@navios/core 1.0.0 → 1.1.0
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 +44 -0
- package/lib/{index-C0Sg16Eb.d.cts → index-3LcTrbxz.d.mts} +491 -52
- package/lib/index-3LcTrbxz.d.mts.map +1 -0
- package/lib/{index-DySQ6Dpd.d.mts → index-B14SekVb.d.cts} +491 -52
- package/lib/index-B14SekVb.d.cts.map +1 -0
- package/lib/index.cjs +18 -3
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +4 -4
- package/lib/legacy-compat/index.cjs +3 -3
- package/lib/legacy-compat/index.d.cts +1 -1
- package/lib/legacy-compat/index.d.mts +1 -1
- package/lib/legacy-compat/index.mjs +2 -2
- package/lib/{navios.factory-CO5MB_OK.cjs → navios.factory-CUrO_p6K.cjs} +461 -48
- package/lib/navios.factory-CUrO_p6K.cjs.map +1 -0
- package/lib/{navios.factory-D6Y94P9B.mjs → navios.factory-DjUOOVVL.mjs} +372 -49
- package/lib/navios.factory-DjUOOVVL.mjs.map +1 -0
- package/lib/testing/index.cjs +2 -2
- package/lib/testing/index.d.cts +1 -1
- package/lib/testing/index.d.mts +1 -1
- package/lib/testing/index.mjs +2 -2
- package/lib/{tokens-CWw9kyeD.cjs → tokens-BEuBMGGX.cjs} +18 -21
- package/lib/tokens-BEuBMGGX.cjs.map +1 -0
- package/lib/{tokens-4J9sredA.mjs → tokens-COyNGV1I.mjs} +17 -20
- package/lib/tokens-COyNGV1I.mjs.map +1 -0
- package/lib/{use-guards.decorator-BecoQSmE.mjs → use-guards.decorator-DLmRl2CV.mjs} +14 -17
- package/lib/use-guards.decorator-DLmRl2CV.mjs.map +1 -0
- package/lib/{use-guards.decorator-C4ml9XaT.cjs → use-guards.decorator-DhumFTk3.cjs} +15 -18
- package/lib/use-guards.decorator-DhumFTk3.cjs.map +1 -0
- package/package.json +2 -2
- package/src/interfaces/index.mts +3 -0
- package/src/interfaces/plugin-context.mts +104 -0
- package/src/interfaces/plugin-stage.mts +62 -0
- package/src/interfaces/plugin.interface.mts +42 -62
- package/src/interfaces/staged-plugin.interface.mts +209 -0
- package/src/metadata/controller.metadata.mts +29 -22
- package/src/metadata/module.metadata.mts +33 -25
- package/src/navios.application.mts +247 -53
- package/src/services/module-loader.service.mts +11 -8
- package/src/utils/define-plugin.mts +251 -0
- package/src/utils/index.mts +1 -0
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
}
|
|
@@ -12,6 +12,10 @@ import { getAllEndpointMetadata } from './handler.metadata.mjs'
|
|
|
12
12
|
export const ControllerMetadataKey = Symbol('ControllerMetadataKey')
|
|
13
13
|
|
|
14
14
|
export interface ControllerMetadata {
|
|
15
|
+
/**
|
|
16
|
+
* The name of the controller class.
|
|
17
|
+
*/
|
|
18
|
+
name: string
|
|
15
19
|
endpoints: Set<HandlerMetadata>
|
|
16
20
|
guards: Set<
|
|
17
21
|
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
@@ -23,29 +27,32 @@ export function getControllerMetadata(
|
|
|
23
27
|
target: ClassType,
|
|
24
28
|
context: ClassDecoratorContext,
|
|
25
29
|
): ControllerMetadata {
|
|
26
|
-
if (context.metadata) {
|
|
27
|
-
|
|
28
|
-
| ControllerMetadata
|
|
29
|
-
| undefined
|
|
30
|
-
if (metadata) {
|
|
31
|
-
return metadata
|
|
32
|
-
} else {
|
|
33
|
-
const endpointsMetadata = getAllEndpointMetadata(context)
|
|
34
|
-
const newMetadata: ControllerMetadata = {
|
|
35
|
-
endpoints: endpointsMetadata,
|
|
36
|
-
guards: new Set<
|
|
37
|
-
| ClassTypeWithInstance<CanActivate>
|
|
38
|
-
| InjectionToken<CanActivate, undefined>
|
|
39
|
-
>(),
|
|
40
|
-
customAttributes: new Map<string | symbol, any>(),
|
|
41
|
-
}
|
|
42
|
-
context.metadata[ControllerMetadataKey] = newMetadata
|
|
43
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
44
|
-
target[ControllerMetadataKey] = newMetadata
|
|
45
|
-
return newMetadata
|
|
46
|
-
}
|
|
30
|
+
if (!context.metadata) {
|
|
31
|
+
throw new Error('[Navios] Wrong environment.')
|
|
47
32
|
}
|
|
48
|
-
|
|
33
|
+
|
|
34
|
+
const existingMetadata = context.metadata[ControllerMetadataKey] as
|
|
35
|
+
| ControllerMetadata
|
|
36
|
+
| undefined
|
|
37
|
+
|
|
38
|
+
if (existingMetadata) {
|
|
39
|
+
return existingMetadata
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const newMetadata: ControllerMetadata = {
|
|
43
|
+
name: target.name,
|
|
44
|
+
endpoints: getAllEndpointMetadata(context),
|
|
45
|
+
guards: new Set<
|
|
46
|
+
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
47
|
+
>(),
|
|
48
|
+
customAttributes: new Map<string | symbol, any>(),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
context.metadata[ControllerMetadataKey] = newMetadata
|
|
52
|
+
// @ts-expect-error We add a custom metadata key to the target
|
|
53
|
+
target[ControllerMetadataKey] = newMetadata
|
|
54
|
+
|
|
55
|
+
return newMetadata
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
export function extractControllerMetadata(
|
|
@@ -6,9 +6,13 @@ import type {
|
|
|
6
6
|
|
|
7
7
|
import type { CanActivate } from '../index.mjs'
|
|
8
8
|
|
|
9
|
-
export const ModuleMetadataKey = Symbol('
|
|
9
|
+
export const ModuleMetadataKey = Symbol('ModuleMetadataKey')
|
|
10
10
|
|
|
11
11
|
export interface ModuleMetadata {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the module class.
|
|
14
|
+
*/
|
|
15
|
+
name: string
|
|
12
16
|
controllers: Set<ClassType>
|
|
13
17
|
imports: Set<ClassType>
|
|
14
18
|
guards: Set<
|
|
@@ -33,31 +37,35 @@ export function getModuleMetadata(
|
|
|
33
37
|
target: ClassType,
|
|
34
38
|
context: ClassDecoratorContext,
|
|
35
39
|
): ModuleMetadata {
|
|
36
|
-
if (context.metadata) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
guards: new Set<
|
|
47
|
-
| ClassTypeWithInstance<CanActivate>
|
|
48
|
-
| InjectionToken<CanActivate, undefined>
|
|
49
|
-
>(),
|
|
50
|
-
overrides: new Set<ClassType>(),
|
|
51
|
-
customAttributes: new Map<string | symbol, any>(),
|
|
52
|
-
customEntries: new Map<symbol, unknown>(),
|
|
53
|
-
}
|
|
54
|
-
context.metadata[ModuleMetadataKey] = newMetadata
|
|
55
|
-
// @ts-expect-error We add a custom metadata key to the target
|
|
56
|
-
target[ModuleMetadataKey] = newMetadata
|
|
57
|
-
return newMetadata
|
|
58
|
-
}
|
|
40
|
+
if (!context.metadata) {
|
|
41
|
+
throw new Error('[Navios] Wrong environment.')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const existingMetadata = context.metadata[ModuleMetadataKey] as
|
|
45
|
+
| ModuleMetadata
|
|
46
|
+
| undefined
|
|
47
|
+
|
|
48
|
+
if (existingMetadata) {
|
|
49
|
+
return existingMetadata
|
|
59
50
|
}
|
|
60
|
-
|
|
51
|
+
|
|
52
|
+
const newMetadata: ModuleMetadata = {
|
|
53
|
+
name: target.name,
|
|
54
|
+
controllers: new Set<ClassType>(),
|
|
55
|
+
imports: new Set<ClassType>(),
|
|
56
|
+
guards: new Set<
|
|
57
|
+
ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
|
|
58
|
+
>(),
|
|
59
|
+
overrides: new Set<ClassType>(),
|
|
60
|
+
customAttributes: new Map<string | symbol, any>(),
|
|
61
|
+
customEntries: new Map<symbol, unknown>(),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
context.metadata[ModuleMetadataKey] = newMetadata
|
|
65
|
+
// @ts-expect-error We add a custom metadata key to the target
|
|
66
|
+
target[ModuleMetadataKey] = newMetadata
|
|
67
|
+
|
|
68
|
+
return newMetadata
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
export function extractModuleMetadata(target: ClassType): ModuleMetadata {
|