@navios/core 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -0
- package/lib/{index-BJjk2X1S.d.mts → index-6S7veHKD.d.mts} +845 -294
- package/lib/index-6S7veHKD.d.mts.map +1 -0
- package/lib/{index-DZ6NU03y.d.cts → index-r0i2txmg.d.cts} +845 -294
- package/lib/index-r0i2txmg.d.cts.map +1 -0
- package/lib/index.cjs +4420 -84
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +4328 -3
- package/lib/index.mjs.map +1 -0
- package/lib/legacy-compat/index.cjs +41 -126
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +4 -60
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +4 -60
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +14 -119
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/navios.factory-BanZIvtR.cjs +4134 -0
- package/lib/navios.factory-BanZIvtR.cjs.map +1 -0
- package/lib/navios.factory-C75yZCoD.mjs +3831 -0
- package/lib/navios.factory-C75yZCoD.mjs.map +1 -0
- package/lib/testing/index.cjs +3 -3
- package/lib/testing/index.cjs.map +1 -1
- 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-4J9sredA.mjs +100 -0
- package/lib/tokens-4J9sredA.mjs.map +1 -0
- package/lib/tokens-BuXXB01L.cjs +196 -0
- package/lib/tokens-BuXXB01L.cjs.map +1 -0
- package/lib/{use-guards.decorator-Be_QUx6b.mjs → use-guards.decorator-BecoQSmE.mjs} +3 -70
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +1 -0
- package/lib/{use-guards.decorator-B6tghdxM.cjs → use-guards.decorator-DgD-kxF5.cjs} +7 -158
- package/lib/use-guards.decorator-DgD-kxF5.cjs.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/attribute.factory.spec.mts +300 -0
- package/src/__tests__/console-logger.service.spec.mts +312 -0
- package/src/__tests__/guard-runner.service.spec.mts +399 -0
- package/src/__tests__/logger.service.spec.mts +147 -0
- package/src/__tests__/responders.spec.mts +6 -5
- package/src/factories/adapter.factory.mts +20 -0
- package/src/factories/endpoint-adapter.factory.mts +1 -1
- package/src/factories/http-adapter.factory.mts +1 -1
- package/src/factories/index.mts +1 -0
- package/src/factories/multipart-adapter.factory.mts +1 -1
- package/src/factories/reply.factory.mts +1 -1
- package/src/factories/request.factory.mts +1 -1
- package/src/factories/stream-adapter.factory.mts +1 -1
- package/src/factories/xml-stream-adapter.factory.mts +1 -1
- package/src/index.mts +1 -0
- package/src/interfaces/abstract-adapter.interface.mts +32 -0
- package/src/interfaces/abstract-http-adapter.interface.mts +27 -20
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +86 -2
- package/src/interfaces/adapter-environment.interface.mts +74 -0
- package/src/interfaces/index.mts +2 -0
- package/src/interfaces/plugin.interface.mts +50 -16
- package/src/legacy-compat/attribute.factory.mts +2 -2
- package/src/legacy-compat/decorators/controller.decorator.mts +1 -1
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/header.decorator.mts +2 -1
- package/src/legacy-compat/decorators/http-code.decorator.mts +2 -1
- package/src/legacy-compat/decorators/index.mts +2 -2
- package/src/legacy-compat/decorators/module.decorator.mts +1 -1
- package/src/legacy-compat/decorators/multipart.decorator.mts +1 -1
- package/src/legacy-compat/decorators/stream.decorator.mts +1 -1
- package/src/legacy-compat/decorators/use-guards.decorator.mts +1 -1
- package/src/legacy-compat/index.mts +10 -5
- package/src/logger/console-logger.service.mts +97 -7
- package/src/metadata/module.metadata.mts +43 -0
- package/src/navios.application.mts +172 -60
- package/src/navios.environment.mts +22 -12
- package/src/navios.factory.mts +31 -10
- package/src/services/abstract-handler-adapter.service.mts +366 -0
- package/src/services/index.mts +1 -0
- package/src/services/module-loader.service.mts +1 -0
- package/src/tokens/adapter.token.mts +6 -0
- package/src/tokens/http-adapter.token.mts +1 -1
- package/src/tokens/index.mts +1 -0
- package/src/utils/adapter-supports.util.mts +47 -0
- package/src/utils/index.mts +1 -0
- package/lib/index-BJjk2X1S.d.mts.map +0 -1
- package/lib/index-DZ6NU03y.d.cts.map +0 -1
- package/lib/src-C46ePe3d.cjs +0 -8022
- package/lib/src-C46ePe3d.cjs.map +0 -1
- package/lib/src-K2k0riYJ.mjs +0 -7587
- package/lib/src-K2k0riYJ.mjs.map +0 -1
- package/lib/use-guards.decorator-B6tghdxM.cjs.map +0 -1
- package/lib/use-guards.decorator-Be_QUx6b.mjs.map +0 -1
- package/src/legacy-compat/context-compat.mts +0 -95
- package/src/legacy-compat/decorators/factory.decorator.mts +0 -37
- package/src/legacy-compat/decorators/injectable.decorator.mts +0 -41
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_navios_factory = require('./navios.factory-BanZIvtR.cjs');
|
|
2
|
+
const require_tokens = require('./tokens-BuXXB01L.cjs');
|
|
2
3
|
let _navios_di = require("@navios/di");
|
|
3
4
|
|
|
4
5
|
//#region src/metadata/handler.metadata.mts
|
|
@@ -69,37 +70,6 @@ function hasControllerMetadata(target) {
|
|
|
69
70
|
return !!target[ControllerMetadataKey];
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/metadata/module.metadata.mts
|
|
74
|
-
const ModuleMetadataKey = Symbol("ControllerMetadataKey");
|
|
75
|
-
function getModuleMetadata(target, context) {
|
|
76
|
-
if (context.metadata) {
|
|
77
|
-
const metadata = context.metadata[ModuleMetadataKey];
|
|
78
|
-
if (metadata) return metadata;
|
|
79
|
-
else {
|
|
80
|
-
const newMetadata = {
|
|
81
|
-
controllers: /* @__PURE__ */ new Set(),
|
|
82
|
-
imports: /* @__PURE__ */ new Set(),
|
|
83
|
-
guards: /* @__PURE__ */ new Set(),
|
|
84
|
-
overrides: /* @__PURE__ */ new Set(),
|
|
85
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
86
|
-
};
|
|
87
|
-
context.metadata[ModuleMetadataKey] = newMetadata;
|
|
88
|
-
target[ModuleMetadataKey] = newMetadata;
|
|
89
|
-
return newMetadata;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
throw new Error("[Navios] Wrong environment.");
|
|
93
|
-
}
|
|
94
|
-
function extractModuleMetadata(target) {
|
|
95
|
-
const metadata = target[ModuleMetadataKey];
|
|
96
|
-
if (!metadata) throw new Error(`[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`);
|
|
97
|
-
return metadata;
|
|
98
|
-
}
|
|
99
|
-
function hasModuleMetadata(target) {
|
|
100
|
-
return !!target[ModuleMetadataKey];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
73
|
//#endregion
|
|
104
74
|
//#region src/metadata/navios-managed.metadata.mts
|
|
105
75
|
/**
|
|
@@ -163,43 +133,6 @@ function hasModuleMetadata(target) {
|
|
|
163
133
|
};
|
|
164
134
|
}
|
|
165
135
|
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/tokens/endpoint-adapter.token.mts
|
|
168
|
-
const EndpointAdapterToken = _navios_di.InjectionToken.create("EndpointAdapterToken");
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/tokens/execution-context.token.mts
|
|
172
|
-
const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
173
|
-
const ExecutionContext = _navios_di.InjectionToken.create(ExecutionContextInjectionToken);
|
|
174
|
-
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region src/tokens/http-adapter.token.mts
|
|
177
|
-
const HttpAdapterToken = _navios_di.InjectionToken.create("HttpAdapterToken");
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/tokens/multipart-adapter.token.mts
|
|
181
|
-
const MultipartAdapterToken = _navios_di.InjectionToken.create("MultipartAdapterToken");
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region src/tokens/navios-options.token.mts
|
|
185
|
-
const NaviosOptionsToken = _navios_di.InjectionToken.create("NaviosOptionsToken");
|
|
186
|
-
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/tokens/reply.token.mts
|
|
189
|
-
const Reply = _navios_di.InjectionToken.create("ReplyToken");
|
|
190
|
-
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/tokens/request.token.mts
|
|
193
|
-
const Request = _navios_di.InjectionToken.create("RequestToken");
|
|
194
|
-
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/tokens/stream-adapter.token.mts
|
|
197
|
-
const StreamAdapterToken = _navios_di.InjectionToken.create("StreamAdapterToken");
|
|
198
|
-
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/tokens/xml-stream-adapter.token.mts
|
|
201
|
-
const XmlStreamAdapterToken = _navios_di.InjectionToken.create("XmlStreamAdapterToken");
|
|
202
|
-
|
|
203
136
|
//#endregion
|
|
204
137
|
//#region src/decorators/endpoint.decorator.mts
|
|
205
138
|
function Endpoint(endpoint) {
|
|
@@ -210,7 +143,7 @@ function Endpoint(endpoint) {
|
|
|
210
143
|
let endpointMetadata = getEndpointMetadata(target, context);
|
|
211
144
|
if (endpointMetadata.config && endpointMetadata.config.url) throw new Error(`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`);
|
|
212
145
|
endpointMetadata.config = config;
|
|
213
|
-
endpointMetadata.adapterToken = EndpointAdapterToken;
|
|
146
|
+
endpointMetadata.adapterToken = require_tokens.EndpointAdapterToken;
|
|
214
147
|
endpointMetadata.classMethod = target.name;
|
|
215
148
|
endpointMetadata.httpMethod = config.method;
|
|
216
149
|
endpointMetadata.url = config.url;
|
|
@@ -307,7 +240,7 @@ function Endpoint(endpoint) {
|
|
|
307
240
|
return (target, context) => {
|
|
308
241
|
if (context.kind !== "class") throw new Error("[Navios] @Module decorator can only be used on classes.");
|
|
309
242
|
const token = _navios_di.InjectionToken.create(target);
|
|
310
|
-
const moduleMetadata = getModuleMetadata(target, context);
|
|
243
|
+
const moduleMetadata = require_tokens.getModuleMetadata(target, context);
|
|
311
244
|
for (const controller of controllers) moduleMetadata.controllers.add(controller);
|
|
312
245
|
for (const importedModule of imports) moduleMetadata.imports.add(importedModule);
|
|
313
246
|
for (const guard of Array.from(guards).reverse()) moduleMetadata.guards.add(guard);
|
|
@@ -331,7 +264,7 @@ function Multipart(endpoint) {
|
|
|
331
264
|
let endpointMetadata = getEndpointMetadata(target, context);
|
|
332
265
|
if (endpointMetadata.config && endpointMetadata.config.url) throw new Error(`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`);
|
|
333
266
|
endpointMetadata.config = config;
|
|
334
|
-
endpointMetadata.adapterToken = MultipartAdapterToken;
|
|
267
|
+
endpointMetadata.adapterToken = require_tokens.MultipartAdapterToken;
|
|
335
268
|
endpointMetadata.classMethod = target.name;
|
|
336
269
|
endpointMetadata.httpMethod = config.method;
|
|
337
270
|
endpointMetadata.url = config.url;
|
|
@@ -350,7 +283,7 @@ function Stream(endpoint) {
|
|
|
350
283
|
let endpointMetadata = getEndpointMetadata(target, context);
|
|
351
284
|
if (endpointMetadata.config && endpointMetadata.config.url) throw new Error(`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`);
|
|
352
285
|
endpointMetadata.config = config;
|
|
353
|
-
endpointMetadata.adapterToken = StreamAdapterToken;
|
|
286
|
+
endpointMetadata.adapterToken = require_tokens.StreamAdapterToken;
|
|
354
287
|
endpointMetadata.classMethod = target.name;
|
|
355
288
|
endpointMetadata.httpMethod = config.method;
|
|
356
289
|
endpointMetadata.url = config.url;
|
|
@@ -421,42 +354,18 @@ Object.defineProperty(exports, 'Endpoint', {
|
|
|
421
354
|
return Endpoint;
|
|
422
355
|
}
|
|
423
356
|
});
|
|
424
|
-
Object.defineProperty(exports, 'EndpointAdapterToken', {
|
|
425
|
-
enumerable: true,
|
|
426
|
-
get: function () {
|
|
427
|
-
return EndpointAdapterToken;
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
357
|
Object.defineProperty(exports, 'EndpointMetadataKey', {
|
|
431
358
|
enumerable: true,
|
|
432
359
|
get: function () {
|
|
433
360
|
return EndpointMetadataKey;
|
|
434
361
|
}
|
|
435
362
|
});
|
|
436
|
-
Object.defineProperty(exports, 'ExecutionContext', {
|
|
437
|
-
enumerable: true,
|
|
438
|
-
get: function () {
|
|
439
|
-
return ExecutionContext;
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
Object.defineProperty(exports, 'ExecutionContextInjectionToken', {
|
|
443
|
-
enumerable: true,
|
|
444
|
-
get: function () {
|
|
445
|
-
return ExecutionContextInjectionToken;
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
363
|
Object.defineProperty(exports, 'Header', {
|
|
449
364
|
enumerable: true,
|
|
450
365
|
get: function () {
|
|
451
366
|
return Header;
|
|
452
367
|
}
|
|
453
368
|
});
|
|
454
|
-
Object.defineProperty(exports, 'HttpAdapterToken', {
|
|
455
|
-
enumerable: true,
|
|
456
|
-
get: function () {
|
|
457
|
-
return HttpAdapterToken;
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
369
|
Object.defineProperty(exports, 'HttpCode', {
|
|
461
370
|
enumerable: true,
|
|
462
371
|
get: function () {
|
|
@@ -469,84 +378,36 @@ Object.defineProperty(exports, 'Module', {
|
|
|
469
378
|
return Module;
|
|
470
379
|
}
|
|
471
380
|
});
|
|
472
|
-
Object.defineProperty(exports, 'ModuleMetadataKey', {
|
|
473
|
-
enumerable: true,
|
|
474
|
-
get: function () {
|
|
475
|
-
return ModuleMetadataKey;
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
381
|
Object.defineProperty(exports, 'Multipart', {
|
|
479
382
|
enumerable: true,
|
|
480
383
|
get: function () {
|
|
481
384
|
return Multipart;
|
|
482
385
|
}
|
|
483
386
|
});
|
|
484
|
-
Object.defineProperty(exports, 'MultipartAdapterToken', {
|
|
485
|
-
enumerable: true,
|
|
486
|
-
get: function () {
|
|
487
|
-
return MultipartAdapterToken;
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
387
|
Object.defineProperty(exports, 'NaviosManagedMetadataKey', {
|
|
491
388
|
enumerable: true,
|
|
492
389
|
get: function () {
|
|
493
390
|
return NaviosManagedMetadataKey;
|
|
494
391
|
}
|
|
495
392
|
});
|
|
496
|
-
Object.defineProperty(exports, 'NaviosOptionsToken', {
|
|
497
|
-
enumerable: true,
|
|
498
|
-
get: function () {
|
|
499
|
-
return NaviosOptionsToken;
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
Object.defineProperty(exports, 'Reply', {
|
|
503
|
-
enumerable: true,
|
|
504
|
-
get: function () {
|
|
505
|
-
return Reply;
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
Object.defineProperty(exports, 'Request', {
|
|
509
|
-
enumerable: true,
|
|
510
|
-
get: function () {
|
|
511
|
-
return Request;
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
393
|
Object.defineProperty(exports, 'Stream', {
|
|
515
394
|
enumerable: true,
|
|
516
395
|
get: function () {
|
|
517
396
|
return Stream;
|
|
518
397
|
}
|
|
519
398
|
});
|
|
520
|
-
Object.defineProperty(exports, 'StreamAdapterToken', {
|
|
521
|
-
enumerable: true,
|
|
522
|
-
get: function () {
|
|
523
|
-
return StreamAdapterToken;
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
399
|
Object.defineProperty(exports, 'UseGuards', {
|
|
527
400
|
enumerable: true,
|
|
528
401
|
get: function () {
|
|
529
402
|
return UseGuards;
|
|
530
403
|
}
|
|
531
404
|
});
|
|
532
|
-
Object.defineProperty(exports, 'XmlStreamAdapterToken', {
|
|
533
|
-
enumerable: true,
|
|
534
|
-
get: function () {
|
|
535
|
-
return XmlStreamAdapterToken;
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
405
|
Object.defineProperty(exports, 'extractControllerMetadata', {
|
|
539
406
|
enumerable: true,
|
|
540
407
|
get: function () {
|
|
541
408
|
return extractControllerMetadata;
|
|
542
409
|
}
|
|
543
410
|
});
|
|
544
|
-
Object.defineProperty(exports, 'extractModuleMetadata', {
|
|
545
|
-
enumerable: true,
|
|
546
|
-
get: function () {
|
|
547
|
-
return extractModuleMetadata;
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
411
|
Object.defineProperty(exports, 'getAllEndpointMetadata', {
|
|
551
412
|
enumerable: true,
|
|
552
413
|
get: function () {
|
|
@@ -571,12 +432,6 @@ Object.defineProperty(exports, 'getManagedMetadata', {
|
|
|
571
432
|
return getManagedMetadata;
|
|
572
433
|
}
|
|
573
434
|
});
|
|
574
|
-
Object.defineProperty(exports, 'getModuleMetadata', {
|
|
575
|
-
enumerable: true,
|
|
576
|
-
get: function () {
|
|
577
|
-
return getModuleMetadata;
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
435
|
Object.defineProperty(exports, 'hasControllerMetadata', {
|
|
581
436
|
enumerable: true,
|
|
582
437
|
get: function () {
|
|
@@ -589,10 +444,4 @@ Object.defineProperty(exports, 'hasManagedMetadata', {
|
|
|
589
444
|
return hasManagedMetadata;
|
|
590
445
|
}
|
|
591
446
|
});
|
|
592
|
-
|
|
593
|
-
enumerable: true,
|
|
594
|
-
get: function () {
|
|
595
|
-
return hasModuleMetadata;
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
//# sourceMappingURL=use-guards.decorator-B6tghdxM.cjs.map
|
|
447
|
+
//# sourceMappingURL=use-guards.decorator-DgD-kxF5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-guards.decorator-DgD-kxF5.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","NaviosManagedMetadataKey","Symbol","getManagedMetadata","target","hasManagedMetadata","Injectable","InjectionToken","getControllerMetadata","Controller","guards","registry","priority","scope","target","context","kind","Error","token","create","metadata","controllerMetadata","guard","Array","from","reverse","add","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","overrides","priority","registry","target","context","kind","Error","token","create","moduleMetadata","controller","add","importedModule","guard","Array","from","reverse","override","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/navios-managed.metadata.mts","../src/decorators/controller.decorator.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 { ClassType } from '@navios/di'\n\n/**\n * Symbol used to identify Navios-managed classes (Controller, Module, MessageController, etc.).\n * This allows AttributeFactory to work with any Navios-managed class type generically.\n */\nexport const NaviosManagedMetadataKey = Symbol('NaviosManagedMetadataKey')\n\n/**\n * Interface for metadata that has custom attributes.\n * Used by Navios-managed classes (Controller, Module, MessageController, etc.).\n */\nexport interface ManagedMetadata {\n customAttributes: Map<string | symbol, any>\n}\n\n/**\n * Gets managed metadata from a class if it exists.\n * This is a generic function that works with any Navios-managed class type.\n *\n * @param target - The class to check\n * @returns The metadata with customAttributes, or null if not managed\n */\nexport function getManagedMetadata(target: ClassType): ManagedMetadata | null {\n // @ts-expect-error - Checking for managed metadata key\n if (target[NaviosManagedMetadataKey]) {\n // @ts-expect-error - Accessing managed metadata\n return target[NaviosManagedMetadataKey] as ManagedMetadata\n }\n return null\n}\n\n/**\n * Checks if a class is Navios-managed (has managed metadata).\n *\n * @param target - The class to check\n * @returns true if the class is Navios-managed\n */\nexport function hasManagedMetadata(target: ClassType): boolean {\n return getManagedMetadata(target) !== null\n}\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 type {\n EndpointHandler,\n EndpointOptions,\n RequestArgs,\n} from '@navios/builder'\nimport type { z } 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 EndpointHandler<Config, false>,\n Config extends EndpointOptions = EndpointDeclaration['config'],\n> = RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n>\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: EndpointOptions\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<const Config extends EndpointOptions>(\n endpoint: EndpointHandler<Config, false>,\n): (\n target: (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<const Config extends EndpointOptions>(\n endpoint: EndpointHandler<Config, false>,\n): (\n target: () =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<const Config extends EndpointOptions>(\n endpoint: EndpointHandler<Config, false>,\n) {\n type Params = RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >\n\n type Handler =\n | ((\n params: Params,\n ) =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>)\n | (() =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['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<EndpointOptions>(\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 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 * Service override classes to import for side effects.\n * These classes are imported to ensure their @Injectable decorators execute,\n * allowing them to register with the DI system. Overrides should use the same\n * InjectionToken as the original service with a higher priority.\n */\n overrides?: 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 overrides = [],\n priority,\n registry,\n }: ModuleOptions = {\n controllers: [],\n imports: [],\n guards: [],\n overrides: [],\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 for (const override of overrides) {\n moduleMetadata.overrides.add(override)\n }\n\n return Injectable({\n token,\n scope: InjectableScope.Singleton,\n priority,\n registry,\n })(target, context)\n }\n}\n","import type { EndpointOptions, RequestArgs } 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: EndpointOptions\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? RequestArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : RequestArgs<\n Url,\n QuerySchema,\n undefined,\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? RequestArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : RequestArgs<\n Url,\n undefined,\n undefined,\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\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: EndpointOptions\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<Config extends EndpointOptions>(endpoint: {\n config: Config\n}): (\n target: (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<Config extends EndpointOptions>(endpoint: {\n config: Config\n}): (\n target: () =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<Config extends EndpointOptions>(endpoint: {\n config: Config\n}) {\n type Params = RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >\n\n type Handler =\n | ((\n params: Params,\n ) =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['responseSchema']>)\n | (() =>\n | Promise<z.input<Config['responseSchema']>>\n | z.input<Config['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<EndpointOptions>(\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 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 BaseEndpointOptions,\n RequestArgs,\n StreamHandler,\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 StreamHandler<Config, false>,\n Config extends BaseEndpointOptions = EndpointDeclaration['config'],\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? RequestArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : RequestArgs<\n Url,\n QuerySchema,\n undefined,\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? RequestArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\n : RequestArgs<\n Url,\n undefined,\n undefined,\n EndpointDeclaration['config']['urlParamsSchema'],\n true\n >\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<Config extends BaseEndpointOptions>(endpoint: {\n config: Config\n}): (\n target: (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n reply: any,\n ) => any,\n context: ClassMethodDecoratorContext,\n) => void\n// Bun doesn't support reply parameter\nexport function Stream<Config extends BaseEndpointOptions>(endpoint: {\n config: Config\n}): (\n target: (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) => any,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Stream<Config extends BaseEndpointOptions>(endpoint: {\n config: Config\n}): (target: () => any, context: ClassMethodDecoratorContext) => void\nexport function Stream<Config extends BaseEndpointOptions>(endpoint: {\n config: Config\n}) {\n type Params = RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >\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<BaseEndpointOptions>(\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 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,OAAIN,iBACF,QAAOA;QACF;IACL,MAAMO,cAAuC;KAC3CF,aAAaN,OAAOO;KACpBE,KAAK;KACLC,mBAAmB;KACnBC,cAAc;KACdC,SAAS,EAAC;KACVC,YAAY;KAEZC,QAAQ;KACRC,wBAAQ,IAAIlB,KAAAA;KAIZmB,kCAAkB,IAAIC,KAAAA;KACxB;AACArB,aAASsB,IAAIV,YAAAA;AACb,WAAOA;;;;AAIb,OAAM,IAAIV,MAAM,8BAAA;;;;;ACnElB,MAAasB,wBAAwBC,OAAO,wBAAA;AAU5C,SAAgBC,sBACdC,QACAC,SAA8B;AAE9B,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWD,QAAQC,SAASL;AAGlC,MAAIK,SACF,QAAOA;OACF;GAEL,MAAME,cAAkC;IACtCC,WAFwBT,uBAAuBK,QAAAA;IAG/CK,wBAAQ,IAAIC,KAAAA;IAIZC,kCAAkB,IAAIC,KAAAA;IACxB;AACAR,WAAQ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AACtCL,oBAAiBM,aAAaR,OAAOI;AACrCF,oBAAiBC,MAAMH,OAAOG;;AAEhC,SAAOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GC9GX,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@navios/builder": "^1.0.0
|
|
15
|
+
"@navios/builder": "^1.0.0",
|
|
16
16
|
"zod": "^3.25.0 || ^4.0.0"
|
|
17
17
|
},
|
|
18
18
|
"typings": "./lib/index.d.mts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@navios/builder": "^1.0.0
|
|
54
|
+
"@navios/builder": "^1.0.0",
|
|
55
55
|
"@types/supertest": "^6.0.3",
|
|
56
56
|
"supertest": "^7.1.4",
|
|
57
57
|
"tsx": "^4.21.0",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"zod": "^4.2.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@navios/di": "^0.
|
|
62
|
+
"@navios/di": "^1.0.0"
|
|
63
63
|
}
|
|
64
64
|
}
|