@asterflow/plugin 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,12 +4,8 @@
4
4
 
5
5
  ![license-info](https://img.shields.io/github/license/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af&logoColor=f9e2af)
6
6
  ![stars-info](https://img.shields.io/github/stars/AsterFlow/AsterFlow?colorA=302D41&colorB=f9e2af&style=for-the-badge)
7
+ ![last-commit](https://img.shields.io/github/last-commit/AsterFlow/AsterFlow?path=packages%2Fresponse&style=for-the-badge&colorA=302D41&colorB=b4befe)
7
8
 
8
- ![last-commit](https://img.shields.io/github/last-commit/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=b4befe)
9
- ![commit-activity](https://img.shields.io/github/commit-activity/y/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=f9e2af)
10
- ![code-size](https://img.shields.io/github/languages/code-size/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
11
-
12
- ![top-language](https://img.shields.io/github/languages/top/AsterFlow/AsterFlow?style=for-the-badge&colorA=302D41&colorB=90dceb)
13
9
  ![bundle-size](https://img.shields.io/bundlejs/size/@asterflow/plugin?style=for-the-badge&colorA=302D41&colorB=3ac97b)
14
10
 
15
11
  </div>
@@ -1,10 +1,5 @@
1
1
  import type { AnyAsterflow, ExtendedAsterflow } from '@asterflow/core';
2
2
  import type { PluginHooks, Resolver } from '../types/plugin';
3
- /**
4
- * A factory for creating plugins that can be configured and attached to AsterFlow.
5
- * Plugins are defined with a series of resolvers (`decorate`, `derive`) and lifecycle
6
- * hooks (`on`) that build up its context and runtime behavior.
7
- */
8
3
  export declare class Plugin<Path extends string, Instance extends AnyAsterflow, Config extends Record<string, any> = {}, Context extends Record<string, any> = {}, Hooks extends PluginHooks<any, Context[], any> = {}, Extension extends Record<string, any> = {}> {
9
4
  readonly name: Path;
10
5
  private readonly resolvers;
@@ -41,13 +36,13 @@ export declare class Plugin<Path extends string, Instance extends AnyAsterflow,
41
36
  * .on('beforeInitialize', (app, context) => { })
42
37
  * .on('beforeInitialize', (app, context) => { });
43
38
  */
44
- on<Event extends keyof PluginHooks<ExtendedAsterflow<Instance>, Context & Config, Extension>, Handler extends NonNullable<PluginHooks<ExtendedAsterflow<Instance>, Context & Config, Extension>[Event]> extends (infer F)[] ? F : never>(event: Event, handler: Handler): Plugin<Path, Instance, Config, Context, Omit<Hooks, Event> & { [K in Event]: [...Hooks extends { [k in Event]: any[]; } ? Hooks[K] : [], Handler]; }, Extension>;
39
+ on<Event extends keyof PluginHooks<ExtendedAsterflow<Instance>, Context & Config, Extension>>(event: Event, handler: NonNullable<PluginHooks<ExtendedAsterflow<Instance>, Context & Config, Extension>[Event]>[number]): Plugin<Path, Instance, Config, Context, Omit<Hooks, Event> & { [K in Event]: [...Hooks extends { [k in Event]: any[]; } ? Hooks[K] : []]; }, Extension>;
45
40
  /**
46
41
  * Defines new properties or methods to be added to the AsterFlow instance.
47
42
  * A função recebe a instância do app e o contexto do plugin, e deve retornar um objeto
48
43
  * com as novas propriedades.
49
44
  */
50
- extends<E extends Record<string, any>>(extensionFn: (app: Instance, context: Context) => E): Plugin<Path, Instance, Config, Context, Hooks, Extension & E>;
45
+ extends<E extends Record<string, any>>(extensionFn: (app: ExtendedAsterflow<Instance>, context: Context) => E): Plugin<Path, ExtendedAsterflow<Instance>, Config, Context, Hooks, Extension & E>;
51
46
  /**
52
47
  * Builds the final context and hooks from the provided configuration.
53
48
  */
@@ -1,10 +1,14 @@
1
+ import type { Runtime } from '@asterflow/adapter';
1
2
  import type { AnyAsterflow, ExtendedAsterflow } from '@asterflow/core';
2
3
  import type { Request } from '@asterflow/request';
3
- import type { Response } from '@asterflow/response';
4
+ import type { AsterResponse } from '@asterflow/response';
4
5
  import type { Plugin } from '../controllers/Plugin';
5
6
  export type AnyPlugin = Plugin<string, any, any, any, any, any>;
6
7
  export type AnyPlugins = Record<string, ResolvedPlugin<AnyPlugin>>;
7
- export type AnyPluginHooks = PluginHooks<any, any>;
8
+ export type AnyPluginHooks = PluginHooks<any, any, any>;
9
+ export type AnyPluginInstance = ResolvedPlugin<AnyPlugin> & {
10
+ hooks: AnyPluginHooks;
11
+ };
8
12
  export type InferPluginExtension<P> = P extends Plugin<any, any, any, any, any, infer Ext> ? Ext : {};
9
13
  export type ResolvedPlugin<P extends AnyPlugin> = P extends Plugin<infer Path, any, any, infer Ctx, any, infer Ext> ? {
10
14
  name: Path;
@@ -17,18 +21,25 @@ export type ResolvedPlugin<P extends AnyPlugin> = P extends Plugin<infer Path, a
17
21
  * Tipo para extrair o objeto de configuração de um plugin.
18
22
  * Ele torna as propriedades com valores padrão opcionais.
19
23
  */
20
- export type ConfigArgument<P extends AnyPlugin> = P extends Plugin<any, any, infer C, any, any> ? Omit<C, keyof P['defaultConfig']> & Partial<Pick<C, keyof P['defaultConfig'] & keyof C>> : never;
24
+ export type InferConfigArgument<P extends AnyPlugin> = P extends Plugin<any, any, infer C, any, any> ? Omit<C, keyof P['defaultConfig']> & Partial<Pick<C, keyof P['defaultConfig'] & keyof C>> : never;
21
25
  /**
22
26
  * Defines the available lifecycle hooks a plugin can register.
23
27
  */
24
28
  export type PluginHooks<Instance extends AnyAsterflow, Context extends Record<string, any>, Extension extends Record<string, any> = {}> = {
25
29
  beforeInitialize?: ((app: ExtendedAsterflow<Instance> & Extension, context: Context) => void | Promise<void>)[];
26
30
  afterInitialize?: ((app: ExtendedAsterflow<Instance> & Extension, context: Context) => void | Promise<void>)[];
27
- onRequest?: ((request: Request<unknown>, response: Response, context: Context) => void | Promise<void>)[];
28
- onResponse?: ((request: Request<unknown>, response: Response, context: Context) => void | Promise<void>)[];
31
+ onRequest?: (({ context, request, response }: {
32
+ request: Request<Runtime>;
33
+ response: AsterResponse;
34
+ context: Context;
35
+ }) => void | Promise<void>)[];
36
+ onResponse?: (({ context, request, response }: {
37
+ request: Request<Runtime>;
38
+ response: AsterResponse;
39
+ context: Context;
40
+ }) => void | Promise<void>)[];
29
41
  };
30
42
  /**
31
43
  * Represents a function that resolves a part of the plugin's context.
32
- * @internal
33
44
  */
34
45
  export type Resolver = (config: any, context: any) => Promise<Record<string, any>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterflow/plugin",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "node": ">=20"
19
19
  },
20
20
  "devDependencies": {
21
- "@asterflow/core": "1.0.6",
22
- "@asterflow/response": "1.0.3",
23
- "@asterflow/request": "1.0.6"
21
+ "@asterflow/core": "1.0.8",
22
+ "@asterflow/response": "1.0.5",
23
+ "@asterflow/request": "1.0.8"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": "^5.8.3"