npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@asterflow/plugin

v1.0.10

Published

<div align="center">

Readme

@asterflow/plugin

license-info stars-info last-commit

bundle-size

A modular and typed plugin system for extending AsterFlow functionality.

📦 Installation

npm install @asterflow/plugin
# or
bun install @asterflow/plugin

💡 About

@asterflow/plugin provides a robust and typed system for extending AsterFlow's functionality. It allows developers to create modular plugins that can inject context, manipulate configurations, and react to application lifecycle events, ensuring seamless and type-safe integration.

✨ Features

  • Extensible Plugin System: Create modular plugins to add custom functionalities to AsterFlow.
  • Dynamic Context: Inject static values into the plugin's context (decorate) or derive complex properties based on configuration and existing context (derive).
  • Lifecycle Hooks: Register handlers for specific AsterFlow application events (such as beforeInitialize, afterInitialize, onRequest, and onResponse) to extend behavior at different stages.
  • Typed Configuration: Define the plugin's configuration structure and its default values, with automatic type inference.
  • Type Safety: Full TypeScript support to ensure your plugin's context, configuration, and hooks are type-safe.
  • Runtime Optimization: Hooks are efficiently invoked only when the plugin is registered, allowing for performance optimizations.

🚀 Usage

@asterflow/plugin enables the creation of plugins that extend AsterFlow in a modular and type-safe manner. Below are examples of how to create and use plugins.

Creating a Basic Plugin

import { Plugin } from '@asterflow/plugin'

const myPlugin = Plugin.create({ name: 'my-first-plugin' })
  .decorate('appName', 'My AsterFlow Application') // Adds a static value to the plugin's context
  .on('beforeInitialize', (app, context) => {
    console.log(`Initializing ${context.appName}...`)
    // app is the AsterFlow instance
  })
  .on('afterInitialize', (app, context) => {
    console.log(`${context.appName} has been initialized!`)
  })

// This plugin can now be registered with `app.use(myPlugin)`

Using Configuration and Derivation

Plugins can be configured and can derive values based on their configuration or existing context.

import { Plugin } from '@asterflow/plugin'

interface FeaturePluginConfig {
  featureEnabled: boolean;
  featureName: string;
}

const featureTogglePlugin = Plugin.create({ name: 'feature-toggle' })
  .withConfig<FeaturePluginConfig>({
    featureEnabled: true,
    featureName: 'Awesome Feature'
  })
  .derive('statusMessage', (context) => {
    return context.featureEnabled
      ? `${context.featureName} is enabled.`
      : `${context.featureName} is disabled.`
  })
  .on('beforeInitialize', (app, context) => {
    console.log(context.statusMessage) // "Awesome Feature is enabled."
  })

// This plugin can be configured when registered:
// app.use(featureTogglePlugin, { featureEnabled: false })

Lifecycle Hooks

Hooks allow plugins to react to important events in the AsterFlow lifecycle.

import { Plugin } from '@asterflow/plugin'
import { Request } from '@asterflow/request'
import { Response } from '@asterflow/response'

const loggerPlugin = Plugin.create({ name: 'logger-plugin' })
  .on('onRequest', (request, response, context) => {
    // Logs request details
    console.log(`[REQ] ${request.getMethod()} ${request.getPathname()}`)
  })
  .on('onResponse', (request, response, context) => {
    // Logs response details
    console.log(`[RES] ${response.getStatus()} ${request.getPathname()}`)
  })

// Register this plugin for global logging
// app.use(loggerPlugin)

Integrating with AsterFlow

To use the created plugins, you register them with the AsterFlow instance.

import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
import fastify from 'fastify'
// Import your plugins here
// import { myPlugin, featureTogglePlugin, loggerPlugin } from './your-plugins'

const server = fastify()
const app = new AsterFlow({
  driver: adapters.fastify
})

// Example plugin registration
app.use(myPlugin) // No additional configuration
app.use(featureTogglePlugin, { featureEnabled: false }) // With overridden configuration
app.use(loggerPlugin)

app.listen(server, { port: 3000 }, (err) => {
  if (err) {
    console.error(err)
    process.exit(1)
  }
  console.log('AsterFlow server with plugins listening on port 3000!')
})

🔗 Related Packages

📄 License

MIT - See LICENSE for more details.