@navios/core 1.1.0 → 2.0.0-alpha.1
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/CHANGELOG.md +85 -13
- package/README.md +69 -220
- package/lib/async-context-BAdt7bno.d.mts +239 -0
- package/lib/async-context-BAdt7bno.d.mts.map +1 -0
- package/lib/async-context-RsWmy2Hi.d.cts +239 -0
- package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
- package/lib/attribute-value-BNiJjxl1.mjs +225 -0
- package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
- package/lib/attribute-value-Cux5HhOL.cjs +314 -0
- package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
- package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
- package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
- package/lib/execution-context-BVSmLkYp.d.cts +71 -0
- package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
- package/lib/execution-context-C5F9rojO.d.mts +71 -0
- package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
- package/lib/execution-context-token--cKS4cJv.cjs +270 -0
- package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
- package/lib/index.cjs +1672 -4426
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +842 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +842 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1559 -4221
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bz83ZnJ5.cjs +173 -0
- package/lib/module-Bz83ZnJ5.cjs.map +1 -0
- package/lib/module-options-CSqQUSTm.d.mts +51 -0
- package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
- package/lib/module-options-DSRBri4J.d.cts +51 -0
- package/lib/module-options-DSRBri4J.d.cts.map +1 -0
- package/lib/module-zPXwR2qp.mjs +138 -0
- package/lib/module-zPXwR2qp.mjs.map +1 -0
- package/lib/settled-within-B6gpu2XW.cjs +32 -0
- package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
- package/lib/settled-within-Bc2pj8WB.mjs +21 -0
- package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
- package/lib/testing/index.cjs +74 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +72 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +36 -0
- package/lib/transport.d.cts +254 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +254 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +6 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-3LcTrbxz.d.mts +0 -3804
- package/lib/index-3LcTrbxz.d.mts.map +0 -1
- package/lib/index-B14SekVb.d.cts +0 -3804
- package/lib/index-B14SekVb.d.cts.map +0 -1
- package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
- package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
- package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
- package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
- package/lib/tokens-BEuBMGGX.cjs +0 -193
- package/lib/tokens-BEuBMGGX.cjs.map +0 -1
- package/lib/tokens-COyNGV1I.mjs +0 -97
- package/lib/tokens-COyNGV1I.mjs.map +0 -1
- package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
- package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
- package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
- package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -14
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin-context.mts +0 -104
- package/src/interfaces/plugin-stage.mts +0 -62
- package/src/interfaces/plugin.interface.mts +0 -119
- package/src/interfaces/staged-plugin.interface.mts +0 -209
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -79
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -116
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -678
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -255
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/define-plugin.mts +0 -251
- package/src/utils/index.mts +0 -2
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base stage names (without pre:/post: prefix)
|
|
3
|
-
*/
|
|
4
|
-
export const PluginStageBase = {
|
|
5
|
-
MODULES_TRAVERSE: 'modules-traverse',
|
|
6
|
-
ADAPTER_RESOLVE: 'adapter-resolve',
|
|
7
|
-
ADAPTER_SETUP: 'adapter-setup',
|
|
8
|
-
MODULES_INIT: 'modules-init',
|
|
9
|
-
READY: 'ready',
|
|
10
|
-
} as const
|
|
11
|
-
|
|
12
|
-
export type PluginStageBase =
|
|
13
|
-
(typeof PluginStageBase)[keyof typeof PluginStageBase]
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Full stage names with pre:/post: prefix
|
|
17
|
-
*/
|
|
18
|
-
export type PluginStage = `pre:${PluginStageBase}` | `post:${PluginStageBase}`
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Helper to create pre stage name from base
|
|
22
|
-
*/
|
|
23
|
-
export const preStage = <T extends PluginStageBase>(base: T): `pre:${T}` =>
|
|
24
|
-
`pre:${base}`
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Helper to create post stage name from base
|
|
28
|
-
*/
|
|
29
|
-
export const postStage = <T extends PluginStageBase>(base: T): `post:${T}` =>
|
|
30
|
-
`post:${base}`
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* All stages as constants for direct access
|
|
34
|
-
*/
|
|
35
|
-
export const PluginStages = {
|
|
36
|
-
PRE_MODULES_TRAVERSE: 'pre:modules-traverse',
|
|
37
|
-
POST_MODULES_TRAVERSE: 'post:modules-traverse',
|
|
38
|
-
PRE_ADAPTER_RESOLVE: 'pre:adapter-resolve',
|
|
39
|
-
POST_ADAPTER_RESOLVE: 'post:adapter-resolve',
|
|
40
|
-
PRE_ADAPTER_SETUP: 'pre:adapter-setup',
|
|
41
|
-
POST_ADAPTER_SETUP: 'post:adapter-setup',
|
|
42
|
-
PRE_MODULES_INIT: 'pre:modules-init',
|
|
43
|
-
POST_MODULES_INIT: 'post:modules-init',
|
|
44
|
-
PRE_READY: 'pre:ready',
|
|
45
|
-
POST_READY: 'post:ready',
|
|
46
|
-
} as const satisfies Record<string, PluginStage>
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* All stages in execution order
|
|
50
|
-
*/
|
|
51
|
-
export const PLUGIN_STAGES_ORDER: readonly PluginStage[] = [
|
|
52
|
-
PluginStages.PRE_MODULES_TRAVERSE,
|
|
53
|
-
PluginStages.POST_MODULES_TRAVERSE,
|
|
54
|
-
PluginStages.PRE_ADAPTER_RESOLVE,
|
|
55
|
-
PluginStages.POST_ADAPTER_RESOLVE,
|
|
56
|
-
PluginStages.PRE_ADAPTER_SETUP,
|
|
57
|
-
PluginStages.POST_ADAPTER_SETUP,
|
|
58
|
-
PluginStages.PRE_MODULES_INIT,
|
|
59
|
-
PluginStages.POST_MODULES_INIT,
|
|
60
|
-
PluginStages.PRE_READY,
|
|
61
|
-
PluginStages.POST_READY,
|
|
62
|
-
] as const
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
|
|
2
|
-
import type { FullPluginContext, PluginContext } from './plugin-context.mjs'
|
|
3
|
-
import type { PluginStage } from './plugin-stage.mjs'
|
|
4
|
-
import type { StagedPluginDefinition } from './staged-plugin.interface.mjs'
|
|
5
|
-
|
|
6
|
-
// Re-export context types for backward compatibility
|
|
7
|
-
export type { PluginContext, FullPluginContext }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Base interface for Navios plugins (legacy).
|
|
11
|
-
*
|
|
12
|
-
* @deprecated Use staged plugins with explicit stage property instead.
|
|
13
|
-
* This interface maps to the `post:modules-init` stage.
|
|
14
|
-
* See `StagedPlugin` for the new pattern.
|
|
15
|
-
*
|
|
16
|
-
* Plugins are registered using `app.usePlugin()` and are initialized
|
|
17
|
-
* after all modules are loaded but before the server starts listening.
|
|
18
|
-
*
|
|
19
|
-
* @typeParam TOptions - The type of options the plugin accepts
|
|
20
|
-
* @typeParam TAdapter - The adapter type the plugin requires
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* // Legacy pattern (still works, maps to post:modules-init)
|
|
25
|
-
* const myPlugin: NaviosPlugin<{ enabled: boolean }> = {
|
|
26
|
-
* name: 'my-plugin',
|
|
27
|
-
* register: async (context, options) => {
|
|
28
|
-
* if (options.enabled) {
|
|
29
|
-
* // Register routes, services, etc.
|
|
30
|
-
* }
|
|
31
|
-
* },
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* // New pattern (recommended)
|
|
35
|
-
* import { definePostModulesInitPlugin } from '@navios/core'
|
|
36
|
-
*
|
|
37
|
-
* export const defineMyPlugin = definePostModulesInitPlugin()({
|
|
38
|
-
* name: 'my-plugin',
|
|
39
|
-
* register: async (context, options: { enabled: boolean }) => {
|
|
40
|
-
* // ...
|
|
41
|
-
* },
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export interface NaviosPlugin<
|
|
46
|
-
TOptions = unknown,
|
|
47
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
48
|
-
> {
|
|
49
|
-
/**
|
|
50
|
-
* Plugin name for identification and logging.
|
|
51
|
-
*/
|
|
52
|
-
name: string
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Called after modules are loaded but before the server starts listening.
|
|
56
|
-
*
|
|
57
|
-
* @param context - The plugin context with access to modules and adapter
|
|
58
|
-
* @param options - Plugin-specific configuration options
|
|
59
|
-
* @deprecated Use staged plugins with explicit stage property
|
|
60
|
-
*/
|
|
61
|
-
register(
|
|
62
|
-
context: PluginContext<TAdapter>,
|
|
63
|
-
options: TOptions,
|
|
64
|
-
): Promise<void> | void
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Plugin definition combining a plugin with its options.
|
|
69
|
-
*
|
|
70
|
-
* @deprecated Use `StagedPluginDefinition` for new plugins.
|
|
71
|
-
* This type is kept for backward compatibility with legacy plugins.
|
|
72
|
-
*
|
|
73
|
-
* @typeParam TOptions - The type of options the plugin accepts
|
|
74
|
-
* @typeParam TAdapter - The adapter type the plugin requires
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* // Legacy pattern
|
|
79
|
-
* function defineMyPlugin(options: MyPluginOptions): PluginDefinition<MyPluginOptions> {
|
|
80
|
-
* return {
|
|
81
|
-
* plugin: myPlugin,
|
|
82
|
-
* options,
|
|
83
|
-
* }
|
|
84
|
-
* }
|
|
85
|
-
*
|
|
86
|
-
* // New pattern (recommended)
|
|
87
|
-
* import { definePostModulesInitPlugin } from '@navios/core'
|
|
88
|
-
*
|
|
89
|
-
* export const defineMyPlugin = definePostModulesInitPlugin()({
|
|
90
|
-
* name: 'my-plugin',
|
|
91
|
-
* register: (context, options: MyPluginOptions) => { ... },
|
|
92
|
-
* })
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export interface PluginDefinition<
|
|
96
|
-
TOptions = unknown,
|
|
97
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
98
|
-
> {
|
|
99
|
-
/**
|
|
100
|
-
* The plugin instance.
|
|
101
|
-
*/
|
|
102
|
-
plugin: NaviosPlugin<TOptions, TAdapter>
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Options to pass to the plugin's register function.
|
|
106
|
-
*/
|
|
107
|
-
options: TOptions
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Union of legacy and staged plugin definitions.
|
|
112
|
-
* Used internally by `usePlugin()` to accept both patterns.
|
|
113
|
-
*/
|
|
114
|
-
export type AnyPluginDefinition<
|
|
115
|
-
TOptions = unknown,
|
|
116
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
117
|
-
> =
|
|
118
|
-
| PluginDefinition<TOptions, TAdapter>
|
|
119
|
-
| StagedPluginDefinition<PluginStage, TOptions, TAdapter>
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
|
|
2
|
-
import type {
|
|
3
|
-
ContainerOnlyContext,
|
|
4
|
-
ContextForStage,
|
|
5
|
-
FullPluginContext,
|
|
6
|
-
ModulesLoadedContext,
|
|
7
|
-
} from './plugin-context.mjs'
|
|
8
|
-
import type { PluginStage } from './plugin-stage.mjs'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base interface for staged plugins that target a specific lifecycle stage.
|
|
12
|
-
*
|
|
13
|
-
* @typeParam S - The target stage (e.g., 'pre:adapter-resolve')
|
|
14
|
-
* @typeParam TOptions - Plugin options type
|
|
15
|
-
* @typeParam TAdapter - Adapter type (only relevant for post-adapter stages)
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const myPlugin: StagedPlugin<'pre:adapter-resolve', MyOptions> = {
|
|
20
|
-
* name: 'my-plugin',
|
|
21
|
-
* stage: 'pre:adapter-resolve',
|
|
22
|
-
* register: (context, options) => {
|
|
23
|
-
* // context is typed as ModulesLoadedContext
|
|
24
|
-
* },
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export interface StagedPlugin<
|
|
29
|
-
S extends PluginStage,
|
|
30
|
-
TOptions = unknown,
|
|
31
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
32
|
-
> {
|
|
33
|
-
/**
|
|
34
|
-
* Plugin name for identification and logging.
|
|
35
|
-
*/
|
|
36
|
-
readonly name: string
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The lifecycle stage this plugin targets.
|
|
40
|
-
*/
|
|
41
|
-
readonly stage: S
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Called at the specified stage during application initialization.
|
|
45
|
-
*
|
|
46
|
-
* @param context - Stage-appropriate context
|
|
47
|
-
* @param options - Plugin-specific configuration options
|
|
48
|
-
*/
|
|
49
|
-
register(
|
|
50
|
-
context: ContextForStage<S, TAdapter>,
|
|
51
|
-
options: TOptions,
|
|
52
|
-
): Promise<void> | void
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ============ Convenience Type Aliases for Each Stage ============
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Plugin that runs before module tree traversal.
|
|
59
|
-
* Context: container only
|
|
60
|
-
*/
|
|
61
|
-
export interface PreModulesTraversePlugin<TOptions = unknown>
|
|
62
|
-
extends StagedPlugin<'pre:modules-traverse', TOptions, never> {
|
|
63
|
-
register(context: ContainerOnlyContext, options: TOptions): Promise<void> | void
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Plugin that runs after module tree traversal.
|
|
68
|
-
* Context: container + modules + moduleLoader
|
|
69
|
-
*/
|
|
70
|
-
export interface PostModulesTraversePlugin<TOptions = unknown>
|
|
71
|
-
extends StagedPlugin<'post:modules-traverse', TOptions, never> {
|
|
72
|
-
register(context: ModulesLoadedContext, options: TOptions): Promise<void> | void
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Plugin that runs before adapter is resolved from container.
|
|
77
|
-
* Context: container + modules + moduleLoader (NO adapter yet!)
|
|
78
|
-
*
|
|
79
|
-
* Use this stage to modify registry/bindings before adapter instantiation.
|
|
80
|
-
*/
|
|
81
|
-
export interface PreAdapterResolvePlugin<TOptions = unknown>
|
|
82
|
-
extends StagedPlugin<'pre:adapter-resolve', TOptions, never> {
|
|
83
|
-
register(context: ModulesLoadedContext, options: TOptions): Promise<void> | void
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Plugin that runs after adapter is resolved.
|
|
88
|
-
* Context: full (container + modules + moduleLoader + adapter)
|
|
89
|
-
*/
|
|
90
|
-
export interface PostAdapterResolvePlugin<
|
|
91
|
-
TOptions = unknown,
|
|
92
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
93
|
-
> extends StagedPlugin<'post:adapter-resolve', TOptions, TAdapter> {
|
|
94
|
-
register(
|
|
95
|
-
context: FullPluginContext<TAdapter>,
|
|
96
|
-
options: TOptions,
|
|
97
|
-
): Promise<void> | void
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Plugin that runs before adapter setup.
|
|
102
|
-
* Context: full
|
|
103
|
-
*/
|
|
104
|
-
export interface PreAdapterSetupPlugin<
|
|
105
|
-
TOptions = unknown,
|
|
106
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
107
|
-
> extends StagedPlugin<'pre:adapter-setup', TOptions, TAdapter> {
|
|
108
|
-
register(
|
|
109
|
-
context: FullPluginContext<TAdapter>,
|
|
110
|
-
options: TOptions,
|
|
111
|
-
): Promise<void> | void
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Plugin that runs after adapter setup.
|
|
116
|
-
* Context: full
|
|
117
|
-
*/
|
|
118
|
-
export interface PostAdapterSetupPlugin<
|
|
119
|
-
TOptions = unknown,
|
|
120
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
121
|
-
> extends StagedPlugin<'post:adapter-setup', TOptions, TAdapter> {
|
|
122
|
-
register(
|
|
123
|
-
context: FullPluginContext<TAdapter>,
|
|
124
|
-
options: TOptions,
|
|
125
|
-
): Promise<void> | void
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Plugin that runs before modules init (route registration).
|
|
130
|
-
* Context: full
|
|
131
|
-
*/
|
|
132
|
-
export interface PreModulesInitPlugin<
|
|
133
|
-
TOptions = unknown,
|
|
134
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
135
|
-
> extends StagedPlugin<'pre:modules-init', TOptions, TAdapter> {
|
|
136
|
-
register(
|
|
137
|
-
context: FullPluginContext<TAdapter>,
|
|
138
|
-
options: TOptions,
|
|
139
|
-
): Promise<void> | void
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Plugin that runs after modules init (route registration).
|
|
144
|
-
* Context: full
|
|
145
|
-
*
|
|
146
|
-
* This is the default stage for legacy NaviosPlugin implementations.
|
|
147
|
-
*/
|
|
148
|
-
export interface PostModulesInitPlugin<
|
|
149
|
-
TOptions = unknown,
|
|
150
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
151
|
-
> extends StagedPlugin<'post:modules-init', TOptions, TAdapter> {
|
|
152
|
-
register(
|
|
153
|
-
context: FullPluginContext<TAdapter>,
|
|
154
|
-
options: TOptions,
|
|
155
|
-
): Promise<void> | void
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Plugin that runs before adapter signals ready.
|
|
160
|
-
* Context: full
|
|
161
|
-
*/
|
|
162
|
-
export interface PreReadyPlugin<
|
|
163
|
-
TOptions = unknown,
|
|
164
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
165
|
-
> extends StagedPlugin<'pre:ready', TOptions, TAdapter> {
|
|
166
|
-
register(
|
|
167
|
-
context: FullPluginContext<TAdapter>,
|
|
168
|
-
options: TOptions,
|
|
169
|
-
): Promise<void> | void
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Plugin that runs after adapter signals ready.
|
|
174
|
-
* Context: full - this is the final stage, app is fully initialized
|
|
175
|
-
*/
|
|
176
|
-
export interface PostReadyPlugin<
|
|
177
|
-
TOptions = unknown,
|
|
178
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
179
|
-
> extends StagedPlugin<'post:ready', TOptions, TAdapter> {
|
|
180
|
-
register(
|
|
181
|
-
context: FullPluginContext<TAdapter>,
|
|
182
|
-
options: TOptions,
|
|
183
|
-
): Promise<void> | void
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// ============ Plugin Definition Types ============
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Plugin definition for staged plugins.
|
|
190
|
-
*
|
|
191
|
-
* @typeParam S - The target stage
|
|
192
|
-
* @typeParam TOptions - Plugin options type
|
|
193
|
-
* @typeParam TAdapter - Adapter type
|
|
194
|
-
*/
|
|
195
|
-
export interface StagedPluginDefinition<
|
|
196
|
-
S extends PluginStage = PluginStage,
|
|
197
|
-
TOptions = unknown,
|
|
198
|
-
TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
|
|
199
|
-
> {
|
|
200
|
-
/**
|
|
201
|
-
* The staged plugin instance.
|
|
202
|
-
*/
|
|
203
|
-
plugin: StagedPlugin<S, TOptions, TAdapter>
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Options to pass to the plugin's register function.
|
|
207
|
-
*/
|
|
208
|
-
options: TOptions
|
|
209
|
-
}
|