@navios/core 0.7.1 → 0.9.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 +78 -0
- package/lib/{index-DW9EPAE6.d.mts → index-D9MNh6Tx.d.mts} +534 -342
- package/lib/index-D9MNh6Tx.d.mts.map +1 -0
- package/lib/{index-pHp-dIGt.d.cts → index-Db1d3cwD.d.cts} +534 -342
- package/lib/index-Db1d3cwD.d.cts.map +1 -0
- package/lib/index.cjs +12 -3
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +3 -3
- package/lib/legacy-compat/index.cjs +1 -1
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +3 -3
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +3 -3
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +1 -1
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-QnxR5b7c.cjs → src-BRPtJ9fG.cjs} +474 -53
- package/lib/src-BRPtJ9fG.cjs.map +1 -0
- package/lib/{src-DyvCDuKO.mjs → src-Bo23RIo-.mjs} +454 -51
- package/lib/src-Bo23RIo-.mjs.map +1 -0
- package/lib/testing/index.cjs +346 -29
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +299 -63
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +299 -63
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +347 -31
- package/lib/testing/index.mjs.map +1 -1
- package/lib/{use-guards.decorator-B6q_N0sf.cjs → use-guards.decorator-Bs8oDHOi.cjs} +29 -99
- package/lib/use-guards.decorator-Bs8oDHOi.cjs.map +1 -0
- package/lib/{use-guards.decorator-kZ3lNK8v.mjs → use-guards.decorator-CzVXuLkz.mjs} +23 -99
- package/lib/use-guards.decorator-CzVXuLkz.mjs.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/controller-resolver.spec.mts +229 -0
- package/src/__tests__/controller.spec.mts +1 -1
- package/src/__tests__/testing-module.spec.mts +459 -0
- package/src/__tests__/unit-testing-module.spec.mts +424 -0
- package/src/decorators/controller.decorator.mts +29 -7
- package/src/decorators/endpoint.decorator.mts +60 -12
- package/src/decorators/module.decorator.mts +23 -5
- package/src/decorators/multipart.decorator.mts +67 -24
- package/src/decorators/stream.decorator.mts +65 -24
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +31 -1
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +2 -6
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/multipart.decorator.mts +5 -5
- package/src/legacy-compat/decorators/stream.decorator.mts +5 -5
- package/src/logger/logger.service.mts +0 -2
- package/src/navios.application.mts +23 -9
- package/src/navios.environment.mts +3 -1
- package/src/navios.factory.mts +19 -18
- package/src/services/guard-runner.service.mts +46 -9
- package/src/services/index.mts +1 -0
- package/src/services/instance-resolver.service.mts +187 -0
- package/src/services/module-loader.service.mts +3 -2
- package/src/stores/request-id.store.mts +45 -3
- package/src/testing/index.mts +1 -0
- package/src/testing/testing-module.mts +255 -93
- package/src/testing/unit-testing-module.mts +298 -0
- package/src/tokens/index.mts +1 -0
- package/src/tokens/navios-options.token.mts +6 -0
- package/lib/index-DW9EPAE6.d.mts.map +0 -1
- package/lib/index-pHp-dIGt.d.cts.map +0 -1
- package/lib/src-DyvCDuKO.mjs.map +0 -1
- package/lib/src-QnxR5b7c.cjs.map +0 -1
- package/lib/use-guards.decorator-B6q_N0sf.cjs.map +0 -1
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_src = require('./src-
|
|
1
|
+
const require_src = require('./src-BRPtJ9fG.cjs');
|
|
2
2
|
let _navios_di = require("@navios/di");
|
|
3
3
|
|
|
4
4
|
//#region src/metadata/handler.metadata.mts
|
|
@@ -103,13 +103,13 @@ function hasModuleMetadata(target) {
|
|
|
103
103
|
//#region src/decorators/controller.decorator.mts
|
|
104
104
|
/**
|
|
105
105
|
* Decorator that marks a class as a Navios controller.
|
|
106
|
-
*
|
|
106
|
+
*
|
|
107
107
|
* Controllers handle HTTP requests and define endpoints.
|
|
108
108
|
* They are request-scoped by default, meaning a new instance is created for each request.
|
|
109
|
-
*
|
|
109
|
+
*
|
|
110
110
|
* @param options - Controller configuration options
|
|
111
111
|
* @returns A class decorator
|
|
112
|
-
*
|
|
112
|
+
*
|
|
113
113
|
* @example
|
|
114
114
|
* ```typescript
|
|
115
115
|
* @Controller({ guards: [AuthGuard] })
|
|
@@ -120,7 +120,7 @@ function hasModuleMetadata(target) {
|
|
|
120
120
|
* }
|
|
121
121
|
* }
|
|
122
122
|
* ```
|
|
123
|
-
*/ function Controller({ guards } = {}) {
|
|
123
|
+
*/ function Controller({ guards, registry, priority, scope } = {}) {
|
|
124
124
|
return function(target, context) {
|
|
125
125
|
if (context.kind !== "class") throw new Error("[Navios] @Controller decorator can only be used on classes.");
|
|
126
126
|
const token = _navios_di.InjectionToken.create(target);
|
|
@@ -130,7 +130,9 @@ function hasModuleMetadata(target) {
|
|
|
130
130
|
}
|
|
131
131
|
return (0, _navios_di.Injectable)({
|
|
132
132
|
token,
|
|
133
|
-
|
|
133
|
+
registry,
|
|
134
|
+
priority,
|
|
135
|
+
scope
|
|
134
136
|
})(target, context);
|
|
135
137
|
};
|
|
136
138
|
}
|
|
@@ -152,6 +154,10 @@ const HttpAdapterToken = _navios_di.InjectionToken.create("HttpAdapterToken");
|
|
|
152
154
|
//#region src/tokens/multipart-adapter.token.mts
|
|
153
155
|
const MultipartAdapterToken = _navios_di.InjectionToken.create("MultipartAdapterToken");
|
|
154
156
|
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/tokens/navios-options.token.mts
|
|
159
|
+
const NaviosOptionsToken = _navios_di.InjectionToken.create("NaviosOptionsToken");
|
|
160
|
+
|
|
155
161
|
//#endregion
|
|
156
162
|
//#region src/tokens/reply.token.mts
|
|
157
163
|
const Reply = _navios_di.InjectionToken.create("ReplyToken");
|
|
@@ -170,36 +176,7 @@ const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapter
|
|
|
170
176
|
|
|
171
177
|
//#endregion
|
|
172
178
|
//#region src/decorators/endpoint.decorator.mts
|
|
173
|
-
|
|
174
|
-
* Decorator that marks a method as an HTTP endpoint.
|
|
175
|
-
*
|
|
176
|
-
* The endpoint must be defined using @navios/builder's `declareEndpoint` method.
|
|
177
|
-
* This ensures type safety and consistency between client and server.
|
|
178
|
-
*
|
|
179
|
-
* @param endpoint - The endpoint declaration from @navios/builder
|
|
180
|
-
* @returns A method decorator
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```typescript
|
|
184
|
-
* import { builder } from '@navios/builder'
|
|
185
|
-
*
|
|
186
|
-
* const api = builder()
|
|
187
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
188
|
-
* method: 'get',
|
|
189
|
-
* url: '/users/$userId',
|
|
190
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
191
|
-
* })
|
|
192
|
-
*
|
|
193
|
-
* @Controller()
|
|
194
|
-
* export class UserController {
|
|
195
|
-
* @Endpoint(getUserEndpoint)
|
|
196
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
197
|
-
* const { userId } = request.urlParams
|
|
198
|
-
* return { id: userId, name: 'John' }
|
|
199
|
-
* }
|
|
200
|
-
* }
|
|
201
|
-
* ```
|
|
202
|
-
*/ function Endpoint(endpoint) {
|
|
179
|
+
function Endpoint(endpoint) {
|
|
203
180
|
return (target, context) => {
|
|
204
181
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
205
182
|
const config = endpoint.config;
|
|
@@ -279,13 +256,13 @@ const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapter
|
|
|
279
256
|
//#region src/decorators/module.decorator.mts
|
|
280
257
|
/**
|
|
281
258
|
* Decorator that marks a class as a Navios module.
|
|
282
|
-
*
|
|
259
|
+
*
|
|
283
260
|
* Modules are the basic building blocks of a Navios application.
|
|
284
261
|
* They organize controllers, services, and other modules into logical units.
|
|
285
|
-
*
|
|
262
|
+
*
|
|
286
263
|
* @param options - Module configuration options
|
|
287
264
|
* @returns A class decorator
|
|
288
|
-
*
|
|
265
|
+
*
|
|
289
266
|
* @example
|
|
290
267
|
* ```typescript
|
|
291
268
|
* @Module({
|
|
@@ -295,7 +272,7 @@ const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapter
|
|
|
295
272
|
* })
|
|
296
273
|
* export class AppModule {}
|
|
297
274
|
* ```
|
|
298
|
-
*/ function Module({ controllers = [], imports = [], guards = [] } = {
|
|
275
|
+
*/ function Module({ controllers = [], imports = [], guards = [], priority, registry } = {
|
|
299
276
|
controllers: [],
|
|
300
277
|
imports: [],
|
|
301
278
|
guards: []
|
|
@@ -309,44 +286,17 @@ const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapter
|
|
|
309
286
|
for (const guard of Array.from(guards).reverse()) moduleMetadata.guards.add(guard);
|
|
310
287
|
return (0, _navios_di.Injectable)({
|
|
311
288
|
token,
|
|
312
|
-
scope: _navios_di.InjectableScope.Singleton
|
|
289
|
+
scope: _navios_di.InjectableScope.Singleton,
|
|
290
|
+
priority,
|
|
291
|
+
registry
|
|
313
292
|
})(target, context);
|
|
314
293
|
};
|
|
315
294
|
}
|
|
316
295
|
|
|
317
296
|
//#endregion
|
|
318
297
|
//#region src/decorators/multipart.decorator.mts
|
|
319
|
-
|
|
320
|
-
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
321
|
-
*
|
|
322
|
-
* Use this decorator for endpoints that handle file uploads or form data.
|
|
323
|
-
* The endpoint must be defined using @navios/builder's `declareMultipart` method.
|
|
324
|
-
*
|
|
325
|
-
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
326
|
-
* @returns A method decorator
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* ```typescript
|
|
330
|
-
* const uploadFileEndpoint = api.declareMultipart({
|
|
331
|
-
* method: 'post',
|
|
332
|
-
* url: '/upload',
|
|
333
|
-
* requestSchema: z.object({ file: z.instanceof(File) }),
|
|
334
|
-
* responseSchema: z.object({ url: z.string() }),
|
|
335
|
-
* })
|
|
336
|
-
*
|
|
337
|
-
* @Controller()
|
|
338
|
-
* export class FileController {
|
|
339
|
-
* @Multipart(uploadFileEndpoint)
|
|
340
|
-
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
|
|
341
|
-
* const { file } = request.data
|
|
342
|
-
* // Handle file upload
|
|
343
|
-
* return { url: 'https://example.com/file.jpg' }
|
|
344
|
-
* }
|
|
345
|
-
* }
|
|
346
|
-
* ```
|
|
347
|
-
*/ function Multipart(endpoint) {
|
|
298
|
+
function Multipart(endpoint) {
|
|
348
299
|
return (target, context) => {
|
|
349
|
-
if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
|
|
350
300
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
351
301
|
const config = endpoint.config;
|
|
352
302
|
if (context.metadata) {
|
|
@@ -364,34 +314,8 @@ const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapter
|
|
|
364
314
|
|
|
365
315
|
//#endregion
|
|
366
316
|
//#region src/decorators/stream.decorator.mts
|
|
367
|
-
|
|
368
|
-
* Decorator that marks a method as a streaming endpoint.
|
|
369
|
-
*
|
|
370
|
-
* Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
|
|
371
|
-
* The endpoint must be defined using @navios/builder's `declareStream` method.
|
|
372
|
-
*
|
|
373
|
-
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
374
|
-
* @returns A method decorator
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* ```typescript
|
|
378
|
-
* const downloadFileEndpoint = api.declareStream({
|
|
379
|
-
* method: 'get',
|
|
380
|
-
* url: '/files/$fileId',
|
|
381
|
-
* })
|
|
382
|
-
*
|
|
383
|
-
* @Controller()
|
|
384
|
-
* export class FileController {
|
|
385
|
-
* @Stream(downloadFileEndpoint)
|
|
386
|
-
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
387
|
-
* const { fileId } = request.urlParams
|
|
388
|
-
* // Stream file data to reply
|
|
389
|
-
* }
|
|
390
|
-
* }
|
|
391
|
-
* ```
|
|
392
|
-
*/ function Stream(endpoint) {
|
|
317
|
+
function Stream(endpoint) {
|
|
393
318
|
return (target, context) => {
|
|
394
|
-
if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
|
|
395
319
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
396
320
|
const config = endpoint.config;
|
|
397
321
|
if (context.metadata) {
|
|
@@ -535,6 +459,12 @@ Object.defineProperty(exports, 'MultipartAdapterToken', {
|
|
|
535
459
|
return MultipartAdapterToken;
|
|
536
460
|
}
|
|
537
461
|
});
|
|
462
|
+
Object.defineProperty(exports, 'NaviosOptionsToken', {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
get: function () {
|
|
465
|
+
return NaviosOptionsToken;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
538
468
|
Object.defineProperty(exports, 'Reply', {
|
|
539
469
|
enumerable: true,
|
|
540
470
|
get: function () {
|
|
@@ -619,4 +549,4 @@ Object.defineProperty(exports, 'hasModuleMetadata', {
|
|
|
619
549
|
return hasModuleMetadata;
|
|
620
550
|
}
|
|
621
551
|
});
|
|
622
|
-
//# sourceMappingURL=use-guards.decorator-
|
|
552
|
+
//# sourceMappingURL=use-guards.decorator-Bs8oDHOi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-guards.decorator-Bs8oDHOi.cjs","names":["EndpointMetadataKey","Symbol","getAllEndpointMetadata","context","metadata","Set","Error","getEndpointMetadata","target","endpointMetadata","Array","from","find","item","classMethod","name","newMetadata","url","successStatusCode","adapterToken","headers","httpMethod","config","guards","customAttributes","Map","add","getAllEndpointMetadata","ControllerMetadataKey","Symbol","getControllerMetadata","target","context","metadata","endpointsMetadata","newMetadata","endpoints","guards","Set","customAttributes","Map","Error","extractControllerMetadata","hasControllerMetadata","ModuleMetadataKey","Symbol","getModuleMetadata","target","context","metadata","newMetadata","controllers","Set","imports","guards","customAttributes","Map","Error","extractModuleMetadata","name","hasModuleMetadata","Injectable","InjectionToken","getControllerMetadata","Controller","guards","registry","priority","scope","target","context","kind","Error","token","create","metadata","controllerMetadata","guard","Array","from","reverse","add","InjectionToken","EndpointAdapterToken","create","InjectionToken","ExecutionContextInjectionToken","ExecutionContext","create","InjectionToken","HttpAdapterToken","create","InjectionToken","MultipartAdapterToken","create","InjectionToken","NaviosOptionsToken","create","InjectionToken","Reply","create","InjectionToken","Request","create","InjectionToken","StreamAdapterToken","create","InjectionToken","XmlStreamAdapterToken","create","getEndpointMetadata","EndpointAdapterToken","Endpoint","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","Header","name","value","target","context","kind","Error","metadata","headers","getEndpointMetadata","HttpCode","code","target","context","kind","Error","metadata","successStatusCode","Injectable","InjectableScope","InjectionToken","getModuleMetadata","Module","controllers","imports","guards","priority","registry","target","context","kind","Error","token","create","moduleMetadata","controller","add","importedModule","guard","Array","from","reverse","scope","Singleton","getEndpointMetadata","MultipartAdapterToken","Multipart","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","StreamAdapterToken","Stream","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getControllerMetadata","getEndpointMetadata","UseGuards","guards","target","context","kind","controllerMetadata","guard","reverse","add","endpointMetadata","Error"],"sources":["../src/metadata/handler.metadata.mts","../src/metadata/controller.metadata.mts","../src/metadata/module.metadata.mts","../src/decorators/controller.decorator.mts","../src/tokens/endpoint-adapter.token.mts","../src/tokens/execution-context.token.mts","../src/tokens/http-adapter.token.mts","../src/tokens/multipart-adapter.token.mts","../src/tokens/navios-options.token.mts","../src/tokens/reply.token.mts","../src/tokens/request.token.mts","../src/tokens/stream-adapter.token.mts","../src/tokens/xml-stream-adapter.token.mts","../src/decorators/endpoint.decorator.mts","../src/decorators/header.decorator.mts","../src/decorators/http-code.decorator.mts","../src/decorators/module.decorator.mts","../src/decorators/multipart.decorator.mts","../src/decorators/stream.decorator.mts","../src/decorators/use-guards.decorator.mts"],"sourcesContent":["import type { HttpMethod } from '@navios/builder'\nimport type { ClassTypeWithInstance, InjectionToken } from '@navios/di'\n\nimport type {\n AbstractHttpHandlerAdapterInterface,\n CanActivate,\n HttpHeader,\n} from '../interfaces/index.mjs'\n\nexport const EndpointMetadataKey = Symbol('EndpointMetadataKey')\n\nexport interface HandlerMetadata<Config = null> {\n classMethod: string\n url: string\n successStatusCode: number\n adapterToken:\n | InjectionToken<AbstractHttpHandlerAdapterInterface, undefined>\n | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface>\n | null\n headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>\n httpMethod: HttpMethod\n config: Config\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getAllEndpointMetadata(\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n): Set<HandlerMetadata<any>> {\n if (context.metadata) {\n const metadata = context.metadata[EndpointMetadataKey] as\n | Set<HandlerMetadata>\n | undefined\n if (metadata) {\n return metadata\n } else {\n context.metadata[EndpointMetadataKey] = new Set<HandlerMetadata<any>>()\n return context.metadata[EndpointMetadataKey] as Set<HandlerMetadata<any>>\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function getEndpointMetadata<Config = any>(\n target: Function,\n context: ClassMethodDecoratorContext,\n): HandlerMetadata<Config> {\n if (context.metadata) {\n const metadata = getAllEndpointMetadata(context)\n if (metadata) {\n const endpointMetadata = Array.from(metadata).find(\n (item) => item.classMethod === target.name,\n )\n if (endpointMetadata) {\n return endpointMetadata\n } else {\n const newMetadata: HandlerMetadata<Config> = {\n classMethod: target.name,\n url: '',\n successStatusCode: 200,\n adapterToken: null,\n headers: {},\n httpMethod: 'GET',\n // @ts-expect-error We are using a generic type here\n config: null,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n metadata.add(newMetadata)\n return newMetadata\n }\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\nimport type { HandlerMetadata } from './handler.metadata.mjs'\n\nimport { getAllEndpointMetadata } from './handler.metadata.mjs'\n\nexport const ControllerMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ControllerMetadata {\n endpoints: Set<HandlerMetadata>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getControllerMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ControllerMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const endpointsMetadata = getAllEndpointMetadata(context)\n const newMetadata: ControllerMetadata = {\n endpoints: endpointsMetadata,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ControllerMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ControllerMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractControllerMetadata(\n target: ClassType,\n): ControllerMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (!metadata) {\n throw new Error(\n '[Navios] Controller metadata not found. Make sure to use @Controller decorator.',\n )\n }\n return metadata\n}\n\nexport function hasControllerMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n return !!metadata\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../index.mjs'\n\nexport const ModuleMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ModuleMetadata {\n controllers: Set<ClassType>\n imports: Set<ClassType>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getModuleMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ModuleMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ModuleMetadataKey] as\n | ModuleMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const newMetadata: ModuleMetadata = {\n controllers: new Set<ClassType>(),\n imports: new Set<ClassType>(),\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ModuleMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ModuleMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractModuleMetadata(target: ClassType): ModuleMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ModuleMetadataKey] as ModuleMetadata | undefined\n if (!metadata) {\n throw new Error(\n `[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`,\n )\n }\n return metadata\n}\n\nexport function hasModuleMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n return !!target[ModuleMetadataKey]\n}\n","import type { ClassType, InjectableScope } from '@navios/di'\n\nimport { Injectable, InjectionToken, Registry } from '@navios/di'\n\nimport { getControllerMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios controller.\n */\nexport interface ControllerOptions {\n /**\n * Guards to apply to all endpoints in this controller.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n /**\n * Registry to use for the controller.\n * Registry is used to store the controller and its endpoints.\n */\n registry?: Registry\n /**\n * Priority to use for the controller.\n * Priority is used to sort the controller in the registry.\n */\n priority?: number\n /**\n * Scope to use for the controller.\n * Scope is used to determine the scope of the controller.\n */\n scope?: InjectableScope\n}\n\n/**\n * Decorator that marks a class as a Navios controller.\n *\n * Controllers handle HTTP requests and define endpoints.\n * They are request-scoped by default, meaning a new instance is created for each request.\n *\n * @param options - Controller configuration options\n * @returns A class decorator\n *\n * @example\n * ```typescript\n * @Controller({ guards: [AuthGuard] })\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // Handle request\n * }\n * }\n * ```\n */\nexport function Controller({\n guards,\n registry,\n priority,\n scope,\n}: ControllerOptions = {}) {\n return function (target: ClassType, context: ClassDecoratorContext) {\n if (context.kind !== 'class') {\n throw new Error(\n '[Navios] @Controller decorator can only be used on classes.',\n )\n }\n const token = InjectionToken.create(target)\n if (context.metadata) {\n const controllerMetadata = getControllerMetadata(target, context)\n if (guards) {\n for (const guard of Array.from(guards).reverse()) {\n controllerMetadata.guards.add(guard)\n }\n }\n }\n return Injectable({\n token,\n registry,\n priority,\n scope,\n })(target, context)\n }\n}\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const EndpointAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'EndpointAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractExecutionContext } from '../interfaces/index.mjs'\n\nexport const ExecutionContextInjectionToken = 'ExecutionContextInjectionToken'\n\nexport const ExecutionContext = InjectionToken.create<AbstractExecutionContext>(\n ExecutionContextInjectionToken,\n)\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpAdapterInterface } from '../interfaces/index.mjs'\n\nexport const HttpAdapterToken =\n InjectionToken.create<AbstractHttpAdapterInterface<any, any, any, any>>(\n 'HttpAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const MultipartAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'MultipartAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { NaviosApplicationOptions } from '../navios.application.mjs'\n\nexport const NaviosOptionsToken =\n InjectionToken.create<NaviosApplicationOptions>('NaviosOptionsToken')\n","import { InjectionToken } from '@navios/di'\n\nexport const Reply = InjectionToken.create<any>('ReplyToken')\n","import { InjectionToken } from '@navios/di'\n\nexport const Request = InjectionToken.create<any>('RequestToken')\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const StreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'StreamAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const XmlStreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'XmlStreamAdapterToken',\n )\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { EndpointAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for an endpoint handler function.\n *\n * This utility type extracts URL parameters, query parameters, and request body\n * from an endpoint declaration and flattens them into a single object.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * querySchema: z.object({ include: z.string().optional() }),\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // request.urlParams.userId is typed as string\n * // request.query.include is typed as string | undefined\n * }\n * ```\n */\nexport type EndpointParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodType\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for an endpoint handler function.\n *\n * This utility type extracts the response schema from an endpoint declaration\n * and returns the appropriate Promise type.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {\n * return { id: '1', name: 'John' } // Type-checked against responseSchema\n * }\n * ```\n */\nexport type EndpointResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as an HTTP endpoint.\n *\n * The endpoint must be defined using @navios/builder's `declareEndpoint` method.\n * This ensures type safety and consistency between client and server.\n *\n * @param endpoint - The endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * import { builder } from '@navios/builder'\n *\n * const api = builder()\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * const { userId } = request.urlParams\n * return { id: userId, name: 'John' }\n * }\n * }\n * ```\n */\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodType\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: (\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: () => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n type Params = QuerySchema extends ZodType\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n | (() => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = EndpointAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type { HttpHeader } from '../interfaces/index.mjs'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP response header for an endpoint.\n * \n * @param name - The header name (e.g., 'Content-Type', 'Cache-Control')\n * @param value - The header value (string, number, or array of strings)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @Header('Cache-Control', 'max-age=3600')\n * async getUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function Header(name: HttpHeader, value: string | number | string[]) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error('[Navios] Header decorator can only be used on methods.')\n }\n const metadata = getEndpointMetadata(target, context)\n\n metadata.headers[name] = value\n\n return target\n }\n}\n","import { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP status code for successful responses.\n * \n * By default, endpoints return 200 OK. Use this decorator to return a different status code.\n * \n * @param code - The HTTP status code to return (e.g., 201, 204, 202)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(createUserEndpoint)\n * @HttpCode(201)\n * async createUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function HttpCode(code: number) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] HttpCode decorator can only be used on methods.',\n )\n }\n const metadata = getEndpointMetadata(target, context)\n metadata.successStatusCode = code\n\n return target\n }\n}\n","import type { ClassType, Registry } from '@navios/di'\n\nimport { Injectable, InjectableScope, InjectionToken } from '@navios/di'\n\nimport { getModuleMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios module.\n */\nexport interface ModuleOptions {\n /**\n * Controllers to register in this module.\n * Controllers handle HTTP requests and define endpoints.\n */\n controllers?: ClassType[] | Set<ClassType>\n /**\n * Other modules to import into this module.\n * Imported modules' controllers and services become available.\n */\n imports?: ClassType[] | Set<ClassType>\n /**\n * Guards to apply to all controllers in this module.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n /**\n * Priority to use for the module.\n * Priority is used to sort the module in the registry.\n */\n priority?: number\n /**\n * Registry to use for the module.\n * Registry is used to store the module and its controllers.\n */\n registry?: Registry\n}\n\n/**\n * Decorator that marks a class as a Navios module.\n *\n * Modules are the basic building blocks of a Navios application.\n * They organize controllers, services, and other modules into logical units.\n *\n * @param options - Module configuration options\n * @returns A class decorator\n *\n * @example\n * ```typescript\n * @Module({\n * controllers: [UserController, AuthController],\n * imports: [DatabaseModule],\n * guards: [AuthGuard],\n * })\n * export class AppModule {}\n * ```\n */\nexport function Module(\n {\n controllers = [],\n imports = [],\n guards = [],\n priority,\n registry,\n }: ModuleOptions = {\n controllers: [],\n imports: [],\n guards: [],\n },\n) {\n return (target: ClassType, context: ClassDecoratorContext) => {\n if (context.kind !== 'class') {\n throw new Error('[Navios] @Module decorator can only be used on classes.')\n }\n // Register the module in the service locator\n const token = InjectionToken.create(target)\n const moduleMetadata = getModuleMetadata(target, context)\n for (const controller of controllers) {\n moduleMetadata.controllers.add(controller)\n }\n for (const importedModule of imports) {\n moduleMetadata.imports.add(importedModule)\n }\n for (const guard of Array.from(guards).reverse()) {\n moduleMetadata.guards.add(guard)\n }\n\n return Injectable({\n token,\n scope: InjectableScope.Singleton,\n priority,\n registry,\n })(target, context)\n }\n}\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { MultipartAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a multipart endpoint handler function.\n *\n * Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for a multipart endpoint handler function.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as a multipart/form-data endpoint.\n *\n * Use this decorator for endpoints that handle file uploads or form data.\n * The endpoint must be defined using @navios/builder's `declareMultipart` method.\n *\n * @param endpoint - The multipart endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * const uploadFileEndpoint = api.declareMultipart({\n * method: 'post',\n * url: '/upload',\n * requestSchema: z.object({ file: z.instanceof(File) }),\n * responseSchema: z.object({ url: z.string() }),\n * })\n *\n * @Controller()\n * export class FileController {\n * @Multipart(uploadFileEndpoint)\n * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {\n * const { file } = request.data\n * // Handle file upload\n * return { url: 'https://example.com/file.jpg' }\n * }\n * }\n * ```\n */\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: (\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: () => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n type Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n | (() => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = MultipartAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n BaseStreamConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { ZodObject, ZodType } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { StreamAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a stream endpoint handler function.\n *\n * Similar to `EndpointParams`, but specifically for streaming endpoints.\n *\n * @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder\n */\nexport type StreamParams<\n EndpointDeclaration extends {\n config: BaseStreamConfig<any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Decorator that marks a method as a streaming endpoint.\n *\n * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).\n * The endpoint must be defined using @navios/builder's `declareStream` method.\n *\n * @param endpoint - The stream endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * const downloadFileEndpoint = api.declareStream({\n * method: 'get',\n * url: '/files/$fileId',\n * })\n *\n * @Controller()\n * export class FileController {\n * @Stream(downloadFileEndpoint)\n * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {\n * const { fileId } = request.urlParams\n * // Stream file data to reply\n * }\n * }\n * ```\n */\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (\n target: (params: Params, reply: any) => any,\n context: ClassMethodDecoratorContext,\n) => void\n// Bun doesn't support reply parameter\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (\n target: (params: Params) => any,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (target: () => any, context: ClassMethodDecoratorContext) => void\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}) {\n type Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((params: Params, reply: any) => any)\n | ((params: Params) => any)\n | (() => any)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseStreamConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = StreamAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\n\nimport {\n getControllerMetadata,\n getEndpointMetadata,\n} from '../metadata/index.mjs'\n\n/**\n * Decorator that applies guards to a controller or endpoint.\n * \n * Guards are used for authentication, authorization, and request validation.\n * They implement the `CanActivate` interface and are executed before the endpoint handler.\n * Guards can be applied at the module, controller, or endpoint level.\n * \n * @param guards - Guard classes or injection tokens to apply\n * @returns A class or method decorator\n * \n * @example\n * ```typescript\n * // Apply to a controller\n * @Controller()\n * @UseGuards(AuthGuard, RoleGuard)\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser() { }\n * }\n * \n * // Apply to a specific endpoint\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @UseGuards(AuthGuard)\n * async getUser() { }\n * }\n * ```\n */\nexport function UseGuards(\n ...guards: (\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n )[]\n) {\n return function <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n ): T {\n if (context.kind === 'class') {\n const controllerMetadata = getControllerMetadata(\n target as unknown as ClassType,\n context,\n )\n for (const guard of guards.reverse()) {\n controllerMetadata.guards.add(guard)\n }\n } else if (context.kind === 'method') {\n const endpointMetadata = getEndpointMetadata(target, context)\n for (const guard of guards.reverse()) {\n endpointMetadata.guards.add(guard)\n }\n } else {\n throw new Error(\n '[Navios] @UseGuards decorator can only be used on classes or methods.',\n )\n }\n return target\n }\n}\n"],"mappings":";;;;AASA,MAAaA,sBAAsBC,OAAO,sBAAA;AAmB1C,SAAgBC,uBACdC,SAA4D;AAE5D,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWD,QAAQC,SAASJ;AAGlC,MAAII,SACF,QAAOA;OACF;AACLD,WAAQC,SAASJ,uCAAuB,IAAIK,KAAAA;AAC5C,UAAOF,QAAQC,SAASJ;;;AAG5B,OAAM,IAAIM,MAAM,8BAAA;;AAGlB,SAAgBC,oBACdC,QACAL,SAAoC;AAEpC,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWF,uBAAuBC,QAAAA;AACxC,MAAIC,UAAU;GACZ,MAAMK,mBAAmBC,MAAMC,KAAKP,SAAAA,CAAUQ,MAC3CC,SAASA,KAAKC,gBAAgBN,OAAOO,KAAI;AAE5C,OA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AAGJ,OAAOG,IAAI,wDAAuD;AAI5GD,oBAAiBF,SAASA;AAC1BE,oBAAiBG,eAAeZ;AAChCS,oBAAiBI,cAAcV,OAAOW;AACtCL,oBAAiBM,aAAaR,OAAOI;AACrCF,oBAAiBC,MAAMH,OAAOG;;AAEhC,SAAOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GCxHX,SAAgBe,UACd,GAAGC,QAGA;AAEH,QAAO,SACLC,QACAC,SAA4D;AAE5D,MAAIA,QAAQC,SAAS,SAAS;GAC5B,MAAMC,qBAAqBP,sBACzBI,QACAC,QAAAA;AAEF,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCF,oBAAmBJ,OAAOO,IAAIF,MAAAA;aAEvBH,QAAQC,SAAS,UAAU;GACpC,MAAMK,mBAAmBV,oBAAoBG,QAAQC,QAAAA;AACrD,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCE,kBAAiBR,OAAOO,IAAIF,MAAAA;QAG9B,OAAM,IAAII,MACR,wEAAA;AAGJ,SAAOR"}
|
|
@@ -102,13 +102,13 @@ function hasModuleMetadata(target) {
|
|
|
102
102
|
//#region src/decorators/controller.decorator.mts
|
|
103
103
|
/**
|
|
104
104
|
* Decorator that marks a class as a Navios controller.
|
|
105
|
-
*
|
|
105
|
+
*
|
|
106
106
|
* Controllers handle HTTP requests and define endpoints.
|
|
107
107
|
* They are request-scoped by default, meaning a new instance is created for each request.
|
|
108
|
-
*
|
|
108
|
+
*
|
|
109
109
|
* @param options - Controller configuration options
|
|
110
110
|
* @returns A class decorator
|
|
111
|
-
*
|
|
111
|
+
*
|
|
112
112
|
* @example
|
|
113
113
|
* ```typescript
|
|
114
114
|
* @Controller({ guards: [AuthGuard] })
|
|
@@ -119,7 +119,7 @@ function hasModuleMetadata(target) {
|
|
|
119
119
|
* }
|
|
120
120
|
* }
|
|
121
121
|
* ```
|
|
122
|
-
*/ function Controller({ guards } = {}) {
|
|
122
|
+
*/ function Controller({ guards, registry, priority, scope } = {}) {
|
|
123
123
|
return function(target, context) {
|
|
124
124
|
if (context.kind !== "class") throw new Error("[Navios] @Controller decorator can only be used on classes.");
|
|
125
125
|
const token = InjectionToken.create(target);
|
|
@@ -129,7 +129,9 @@ function hasModuleMetadata(target) {
|
|
|
129
129
|
}
|
|
130
130
|
return Injectable({
|
|
131
131
|
token,
|
|
132
|
-
|
|
132
|
+
registry,
|
|
133
|
+
priority,
|
|
134
|
+
scope
|
|
133
135
|
})(target, context);
|
|
134
136
|
};
|
|
135
137
|
}
|
|
@@ -151,6 +153,10 @@ const HttpAdapterToken = InjectionToken.create("HttpAdapterToken");
|
|
|
151
153
|
//#region src/tokens/multipart-adapter.token.mts
|
|
152
154
|
const MultipartAdapterToken = InjectionToken.create("MultipartAdapterToken");
|
|
153
155
|
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/tokens/navios-options.token.mts
|
|
158
|
+
const NaviosOptionsToken = InjectionToken.create("NaviosOptionsToken");
|
|
159
|
+
|
|
154
160
|
//#endregion
|
|
155
161
|
//#region src/tokens/reply.token.mts
|
|
156
162
|
const Reply = InjectionToken.create("ReplyToken");
|
|
@@ -169,36 +175,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
169
175
|
|
|
170
176
|
//#endregion
|
|
171
177
|
//#region src/decorators/endpoint.decorator.mts
|
|
172
|
-
|
|
173
|
-
* Decorator that marks a method as an HTTP endpoint.
|
|
174
|
-
*
|
|
175
|
-
* The endpoint must be defined using @navios/builder's `declareEndpoint` method.
|
|
176
|
-
* This ensures type safety and consistency between client and server.
|
|
177
|
-
*
|
|
178
|
-
* @param endpoint - The endpoint declaration from @navios/builder
|
|
179
|
-
* @returns A method decorator
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```typescript
|
|
183
|
-
* import { builder } from '@navios/builder'
|
|
184
|
-
*
|
|
185
|
-
* const api = builder()
|
|
186
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
187
|
-
* method: 'get',
|
|
188
|
-
* url: '/users/$userId',
|
|
189
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
190
|
-
* })
|
|
191
|
-
*
|
|
192
|
-
* @Controller()
|
|
193
|
-
* export class UserController {
|
|
194
|
-
* @Endpoint(getUserEndpoint)
|
|
195
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
196
|
-
* const { userId } = request.urlParams
|
|
197
|
-
* return { id: userId, name: 'John' }
|
|
198
|
-
* }
|
|
199
|
-
* }
|
|
200
|
-
* ```
|
|
201
|
-
*/ function Endpoint(endpoint) {
|
|
178
|
+
function Endpoint(endpoint) {
|
|
202
179
|
return (target, context) => {
|
|
203
180
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
204
181
|
const config = endpoint.config;
|
|
@@ -278,13 +255,13 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
278
255
|
//#region src/decorators/module.decorator.mts
|
|
279
256
|
/**
|
|
280
257
|
* Decorator that marks a class as a Navios module.
|
|
281
|
-
*
|
|
258
|
+
*
|
|
282
259
|
* Modules are the basic building blocks of a Navios application.
|
|
283
260
|
* They organize controllers, services, and other modules into logical units.
|
|
284
|
-
*
|
|
261
|
+
*
|
|
285
262
|
* @param options - Module configuration options
|
|
286
263
|
* @returns A class decorator
|
|
287
|
-
*
|
|
264
|
+
*
|
|
288
265
|
* @example
|
|
289
266
|
* ```typescript
|
|
290
267
|
* @Module({
|
|
@@ -294,7 +271,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
294
271
|
* })
|
|
295
272
|
* export class AppModule {}
|
|
296
273
|
* ```
|
|
297
|
-
*/ function Module({ controllers = [], imports = [], guards = [] } = {
|
|
274
|
+
*/ function Module({ controllers = [], imports = [], guards = [], priority, registry } = {
|
|
298
275
|
controllers: [],
|
|
299
276
|
imports: [],
|
|
300
277
|
guards: []
|
|
@@ -308,44 +285,17 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
308
285
|
for (const guard of Array.from(guards).reverse()) moduleMetadata.guards.add(guard);
|
|
309
286
|
return Injectable({
|
|
310
287
|
token,
|
|
311
|
-
scope: InjectableScope.Singleton
|
|
288
|
+
scope: InjectableScope.Singleton,
|
|
289
|
+
priority,
|
|
290
|
+
registry
|
|
312
291
|
})(target, context);
|
|
313
292
|
};
|
|
314
293
|
}
|
|
315
294
|
|
|
316
295
|
//#endregion
|
|
317
296
|
//#region src/decorators/multipart.decorator.mts
|
|
318
|
-
|
|
319
|
-
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
320
|
-
*
|
|
321
|
-
* Use this decorator for endpoints that handle file uploads or form data.
|
|
322
|
-
* The endpoint must be defined using @navios/builder's `declareMultipart` method.
|
|
323
|
-
*
|
|
324
|
-
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
325
|
-
* @returns A method decorator
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* ```typescript
|
|
329
|
-
* const uploadFileEndpoint = api.declareMultipart({
|
|
330
|
-
* method: 'post',
|
|
331
|
-
* url: '/upload',
|
|
332
|
-
* requestSchema: z.object({ file: z.instanceof(File) }),
|
|
333
|
-
* responseSchema: z.object({ url: z.string() }),
|
|
334
|
-
* })
|
|
335
|
-
*
|
|
336
|
-
* @Controller()
|
|
337
|
-
* export class FileController {
|
|
338
|
-
* @Multipart(uploadFileEndpoint)
|
|
339
|
-
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
|
|
340
|
-
* const { file } = request.data
|
|
341
|
-
* // Handle file upload
|
|
342
|
-
* return { url: 'https://example.com/file.jpg' }
|
|
343
|
-
* }
|
|
344
|
-
* }
|
|
345
|
-
* ```
|
|
346
|
-
*/ function Multipart(endpoint) {
|
|
297
|
+
function Multipart(endpoint) {
|
|
347
298
|
return (target, context) => {
|
|
348
|
-
if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
|
|
349
299
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
350
300
|
const config = endpoint.config;
|
|
351
301
|
if (context.metadata) {
|
|
@@ -363,34 +313,8 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
363
313
|
|
|
364
314
|
//#endregion
|
|
365
315
|
//#region src/decorators/stream.decorator.mts
|
|
366
|
-
|
|
367
|
-
* Decorator that marks a method as a streaming endpoint.
|
|
368
|
-
*
|
|
369
|
-
* Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
|
|
370
|
-
* The endpoint must be defined using @navios/builder's `declareStream` method.
|
|
371
|
-
*
|
|
372
|
-
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
373
|
-
* @returns A method decorator
|
|
374
|
-
*
|
|
375
|
-
* @example
|
|
376
|
-
* ```typescript
|
|
377
|
-
* const downloadFileEndpoint = api.declareStream({
|
|
378
|
-
* method: 'get',
|
|
379
|
-
* url: '/files/$fileId',
|
|
380
|
-
* })
|
|
381
|
-
*
|
|
382
|
-
* @Controller()
|
|
383
|
-
* export class FileController {
|
|
384
|
-
* @Stream(downloadFileEndpoint)
|
|
385
|
-
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
386
|
-
* const { fileId } = request.urlParams
|
|
387
|
-
* // Stream file data to reply
|
|
388
|
-
* }
|
|
389
|
-
* }
|
|
390
|
-
* ```
|
|
391
|
-
*/ function Stream(endpoint) {
|
|
316
|
+
function Stream(endpoint) {
|
|
392
317
|
return (target, context) => {
|
|
393
|
-
if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
|
|
394
318
|
if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
|
|
395
319
|
const config = endpoint.config;
|
|
396
320
|
if (context.metadata) {
|
|
@@ -450,5 +374,5 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
|
|
|
450
374
|
}
|
|
451
375
|
|
|
452
376
|
//#endregion
|
|
453
|
-
export {
|
|
454
|
-
//# sourceMappingURL=use-guards.decorator-
|
|
377
|
+
export { ControllerMetadataKey as C, EndpointMetadataKey as D, hasControllerMetadata as E, getAllEndpointMetadata as O, hasModuleMetadata as S, getControllerMetadata as T, EndpointAdapterToken as _, HttpCode as a, extractModuleMetadata as b, XmlStreamAdapterToken as c, Reply as d, NaviosOptionsToken as f, ExecutionContextInjectionToken as g, ExecutionContext as h, Module as i, getEndpointMetadata as k, StreamAdapterToken as l, HttpAdapterToken as m, Stream as n, Header as o, MultipartAdapterToken as p, Multipart as r, Endpoint as s, UseGuards as t, Request as u, Controller as v, extractControllerMetadata as w, getModuleMetadata as x, ModuleMetadataKey as y };
|
|
378
|
+
//# sourceMappingURL=use-guards.decorator-CzVXuLkz.mjs.map
|