@navios/core 1.0.0 → 2.0.0-alpha.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 +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,357 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { g as hasModuleMetadata, h as getModuleMetadata } from "../tokens-4J9sredA.mjs";
|
|
1
|
+
import "../attribute-value-DMEA255r.mjs";
|
|
3
2
|
import { Factory, Injectable, createClassContext, createClassContext as createClassContext$1, createMethodContext, createMethodContext as createMethodContext$1 } from "@navios/di/legacy-compat";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* @Module({
|
|
17
|
-
* controllers: [UserController, AuthController],
|
|
18
|
-
* imports: [DatabaseModule],
|
|
19
|
-
* guards: [AuthGuard],
|
|
20
|
-
* })
|
|
21
|
-
* export class AppModule {}
|
|
22
|
-
* ```
|
|
23
|
-
*/ function Module(options = {
|
|
24
|
-
controllers: [],
|
|
25
|
-
imports: [],
|
|
26
|
-
guards: []
|
|
27
|
-
}) {
|
|
28
|
-
return function(target) {
|
|
29
|
-
const context = createClassContext$1(target);
|
|
30
|
-
return Module$1(options)(target, context);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/legacy-compat/decorators/controller.decorator.mts
|
|
36
|
-
/**
|
|
37
|
-
* Legacy-compatible Controller decorator.
|
|
38
|
-
*
|
|
39
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
40
|
-
*
|
|
41
|
-
* @param options - Controller configuration options
|
|
42
|
-
* @returns A class decorator compatible with legacy decorator API
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* @Controller({ guards: [AuthGuard] })
|
|
47
|
-
* export class UserController {
|
|
48
|
-
* @Endpoint(getUserEndpoint)
|
|
49
|
-
* async getUser() { }
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
*/ function Controller(options = {}) {
|
|
53
|
-
return function(target) {
|
|
54
|
-
const context = createClassContext$1(target);
|
|
55
|
-
return Controller$1(options)(target, context);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/legacy-compat/decorators/endpoint.decorator.mts
|
|
61
|
-
/**
|
|
62
|
-
* Legacy-compatible Endpoint decorator.
|
|
63
|
-
*
|
|
64
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
65
|
-
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
66
|
-
*
|
|
67
|
-
* @param endpoint - The endpoint declaration from @navios/builder
|
|
68
|
-
* @returns A method decorator compatible with legacy decorator API
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* @Controller()
|
|
73
|
-
* export class UserController {
|
|
74
|
-
* @Endpoint(getUserEndpoint)
|
|
75
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
|
|
76
|
-
* return { id: '1', name: 'John' }
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*/ function Endpoint(endpoint) {
|
|
81
|
-
return function(target, propertyKey, descriptor) {
|
|
82
|
-
if (!descriptor) throw new Error("[Navios] @Endpoint decorator requires a method descriptor. Make sure experimentalDecorators is enabled.");
|
|
83
|
-
const typedDescriptor = descriptor;
|
|
84
|
-
const context = createMethodContext$1(target, propertyKey, typedDescriptor);
|
|
85
|
-
const result = Endpoint$1(endpoint)(typedDescriptor.value, context);
|
|
86
|
-
if (result !== typedDescriptor.value) typedDescriptor.value = result;
|
|
87
|
-
return typedDescriptor;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/legacy-compat/decorators/use-guards.decorator.mts
|
|
93
|
-
/**
|
|
94
|
-
* Legacy-compatible UseGuards decorator.
|
|
95
|
-
*
|
|
96
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
97
|
-
* Can be applied to classes or methods.
|
|
98
|
-
*
|
|
99
|
-
* @param guards - Guard classes or injection tokens to apply
|
|
100
|
-
* @returns A class or method decorator compatible with legacy decorator API
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* // Apply to a controller
|
|
105
|
-
* @Controller()
|
|
106
|
-
* @UseGuards(AuthGuard, RoleGuard)
|
|
107
|
-
* export class UserController { }
|
|
108
|
-
*
|
|
109
|
-
* // Apply to a specific endpoint
|
|
110
|
-
* @Controller()
|
|
111
|
-
* export class UserController {
|
|
112
|
-
* @Endpoint(getUserEndpoint)
|
|
113
|
-
* @UseGuards(AuthGuard)
|
|
114
|
-
* async getUser() { }
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*/ function UseGuards(...guards) {
|
|
118
|
-
function decoratorImpl(target, propertyKey, descriptor) {
|
|
119
|
-
if (propertyKey !== void 0 && descriptor !== void 0) {
|
|
3
|
+
import { a as AttributeFactory$1, i as UseGuards$1, r as UseInterceptors$1, t as Module$1 } from "../module-Bha7GER_.mjs";
|
|
4
|
+
// src/legacy-compat/legacy-decorator.mts
|
|
5
|
+
/**
|
|
6
|
+
* Turns a standard decorator into one that accepts the legacy call shapes:
|
|
7
|
+
* `(constructor)`, `(prototype, key, descriptor)` and `(prototype, key)`.
|
|
8
|
+
*/
|
|
9
|
+
function legacy(decorator) {
|
|
10
|
+
return (target, propertyKey, descriptor) => {
|
|
11
|
+
if (propertyKey === void 0) return decorator(target, createClassContext$1(target)) ?? target;
|
|
12
|
+
if (descriptor && typeof descriptor.value === "function") {
|
|
120
13
|
const context = createMethodContext$1(target, propertyKey, descriptor);
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
14
|
+
const replaced = decorator(descriptor.value, context);
|
|
15
|
+
if (replaced && replaced !== descriptor.value) descriptor.value = replaced;
|
|
123
16
|
return descriptor;
|
|
124
|
-
} else {
|
|
125
|
-
const context = createClassContext$1(target);
|
|
126
|
-
return UseGuards$1(...guards)(target, context);
|
|
127
17
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/legacy-compat/decorators/header.decorator.mts
|
|
134
|
-
/**
|
|
135
|
-
* Legacy-compatible Header decorator.
|
|
136
|
-
*
|
|
137
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
138
|
-
*
|
|
139
|
-
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
140
|
-
* @param value - The header value (string, number, or array of strings)
|
|
141
|
-
* @returns A method decorator compatible with legacy decorator API
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* @Controller()
|
|
146
|
-
* export class UserController {
|
|
147
|
-
* @Endpoint(getUserEndpoint)
|
|
148
|
-
* @Header('Cache-Control', 'max-age=3600')
|
|
149
|
-
* async getUser() {
|
|
150
|
-
* return { id: '1', name: 'John' }
|
|
151
|
-
* }
|
|
152
|
-
* }
|
|
153
|
-
* ```
|
|
154
|
-
*/ function Header(name, value) {
|
|
155
|
-
return function(target, propertyKey, descriptor) {
|
|
156
|
-
const context = createMethodContext$1(target, propertyKey, descriptor);
|
|
157
|
-
const result = Header$1(name, value)(descriptor.value, context);
|
|
158
|
-
if (result !== descriptor.value) descriptor.value = result;
|
|
159
|
-
return descriptor;
|
|
18
|
+
decorator(void 0, {
|
|
19
|
+
...createMethodContext$1(target, propertyKey, descriptor ?? {}),
|
|
20
|
+
kind: "field"
|
|
21
|
+
});
|
|
160
22
|
};
|
|
161
23
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
* @returns A method decorator compatible with legacy decorator API
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* @Controller()
|
|
176
|
-
* export class UserController {
|
|
177
|
-
* @Endpoint(createUserEndpoint)
|
|
178
|
-
* @HttpCode(201)
|
|
179
|
-
* async createUser() {
|
|
180
|
-
* return { id: '1', name: 'John' }
|
|
181
|
-
* }
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*/ function HttpCode(code) {
|
|
185
|
-
return function(target, propertyKey, descriptor) {
|
|
186
|
-
const context = createMethodContext$1(target, propertyKey, descriptor);
|
|
187
|
-
const result = HttpCode$1(code)(descriptor.value, context);
|
|
188
|
-
if (result !== descriptor.value) descriptor.value = result;
|
|
189
|
-
return descriptor;
|
|
24
|
+
// src/legacy-compat/attribute-factory.mts
|
|
25
|
+
function createAttribute(token, schema) {
|
|
26
|
+
const standard = schema ? AttributeFactory$1.createAttribute(token, schema) : AttributeFactory$1.createAttribute(token);
|
|
27
|
+
const attribute = (value) => {
|
|
28
|
+
const application = standard(value);
|
|
29
|
+
return Object.assign(legacy(application), {
|
|
30
|
+
token: application.token,
|
|
31
|
+
value: application.value
|
|
32
|
+
});
|
|
190
33
|
};
|
|
34
|
+
return Object.assign(attribute, schema ? {
|
|
35
|
+
token,
|
|
36
|
+
schema
|
|
37
|
+
} : { token });
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `AttributeFactory` whose attributes are legacy decorators. Reading
|
|
41
|
+
* (`get`, `getAll`, `has`) is the same as the standard one.
|
|
42
|
+
*/
|
|
43
|
+
const AttributeFactory = {
|
|
44
|
+
createAttribute,
|
|
45
|
+
get: AttributeFactory$1.get,
|
|
46
|
+
getAll: AttributeFactory$1.getAll,
|
|
47
|
+
has: AttributeFactory$1.has
|
|
48
|
+
};
|
|
49
|
+
// src/legacy-compat/module.mts
|
|
50
|
+
function Module(options = {}) {
|
|
51
|
+
return legacy(Module$1(options));
|
|
191
52
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Legacy-compatible Multipart decorator.
|
|
197
|
-
*
|
|
198
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
199
|
-
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
200
|
-
*
|
|
201
|
-
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
202
|
-
* @returns A method decorator compatible with legacy decorator API
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* @Controller()
|
|
207
|
-
* export class FileController {
|
|
208
|
-
* @Multipart(uploadFileEndpoint)
|
|
209
|
-
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): MultipartResult<typeof uploadFileEndpoint> {
|
|
210
|
-
* const { file } = request.data
|
|
211
|
-
* return { url: 'https://example.com/file.jpg' }
|
|
212
|
-
* }
|
|
213
|
-
* }
|
|
214
|
-
* ```
|
|
215
|
-
*/ function Multipart(endpoint) {
|
|
216
|
-
return function(target, propertyKey, descriptor) {
|
|
217
|
-
if (!descriptor) throw new Error("[Navios] @Multipart decorator requires a method descriptor. Make sure experimentalDecorators is enabled.");
|
|
218
|
-
const context = createMethodContext$1(target, propertyKey, descriptor);
|
|
219
|
-
const result = Multipart$1(endpoint)(descriptor.value, context);
|
|
220
|
-
if (result !== descriptor.value) descriptor.value = result;
|
|
221
|
-
return descriptor;
|
|
222
|
-
};
|
|
53
|
+
// src/legacy-compat/use-guards.mts
|
|
54
|
+
function UseGuards(...guards) {
|
|
55
|
+
return legacy(UseGuards$1(...guards));
|
|
223
56
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Legacy-compatible Stream decorator.
|
|
229
|
-
*
|
|
230
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
231
|
-
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
232
|
-
*
|
|
233
|
-
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
234
|
-
* @returns A method decorator compatible with legacy decorator API
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```typescript
|
|
238
|
-
* @Controller()
|
|
239
|
-
* export class FileController {
|
|
240
|
-
* @Stream(downloadFileEndpoint)
|
|
241
|
-
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
242
|
-
* const { fileId } = request.urlParams
|
|
243
|
-
* // Stream file data to reply
|
|
244
|
-
* }
|
|
245
|
-
* }
|
|
246
|
-
* ```
|
|
247
|
-
*/ function Stream(endpoint) {
|
|
248
|
-
return function(target, propertyKey, descriptor) {
|
|
249
|
-
if (!descriptor || !descriptor.value) throw new Error("[Navios] @Stream decorator requires a method descriptor. Make sure experimentalDecorators is enabled.");
|
|
250
|
-
const typedDescriptor = descriptor;
|
|
251
|
-
const context = createMethodContext$1(target, propertyKey, typedDescriptor);
|
|
252
|
-
const result = Stream$1(endpoint)(typedDescriptor.value, context);
|
|
253
|
-
if (result && result !== typedDescriptor.value) typedDescriptor.value = result;
|
|
254
|
-
return typedDescriptor;
|
|
255
|
-
};
|
|
57
|
+
// src/legacy-compat/use-interceptors.mts
|
|
58
|
+
function UseInterceptors(...interceptors) {
|
|
59
|
+
return legacy(UseInterceptors$1(...interceptors));
|
|
256
60
|
}
|
|
61
|
+
export { AttributeFactory, Factory, Injectable, Module, UseGuards, UseInterceptors, createClassContext, createMethodContext, legacy };
|
|
257
62
|
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region src/legacy-compat/attribute.factory.mts
|
|
260
|
-
/**
|
|
261
|
-
* Legacy-compatible factory for creating custom attribute decorators.
|
|
262
|
-
*
|
|
263
|
-
* Works with TypeScript experimental decorators (legacy API).
|
|
264
|
-
*
|
|
265
|
-
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
266
|
-
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* // Create a simple boolean attribute
|
|
271
|
-
* const Public = LegacyAttributeFactory.createAttribute(Symbol.for('Public'))
|
|
272
|
-
*
|
|
273
|
-
* // Use it as a decorator
|
|
274
|
-
* @Controller()
|
|
275
|
-
* @Public()
|
|
276
|
-
* export class PublicController { }
|
|
277
|
-
*
|
|
278
|
-
* // Check if attribute exists
|
|
279
|
-
* if (LegacyAttributeFactory.has(Public, controllerMetadata)) {
|
|
280
|
-
* // Skip authentication
|
|
281
|
-
* }
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* // Create an attribute with a validated value
|
|
287
|
-
* const RateLimit = LegacyAttributeFactory.createAttribute(
|
|
288
|
-
* Symbol.for('RateLimit'),
|
|
289
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
290
|
-
* )
|
|
291
|
-
*
|
|
292
|
-
* // Use it with a value
|
|
293
|
-
* @Endpoint(apiEndpoint)
|
|
294
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
295
|
-
* async handler() { }
|
|
296
|
-
*
|
|
297
|
-
* // Get the value
|
|
298
|
-
* const limit = LegacyAttributeFactory.get(RateLimit, endpointMetadata)
|
|
299
|
-
* // limit is typed as { requests: number, window: number } | null
|
|
300
|
-
* ```
|
|
301
|
-
*/ var LegacyAttributeFactory = class {
|
|
302
|
-
static createAttribute(token, schema) {
|
|
303
|
-
const res = (value) => {
|
|
304
|
-
function decorator(target, propertyKey, descriptor) {
|
|
305
|
-
if (propertyKey !== void 0 && descriptor !== void 0) {
|
|
306
|
-
const context = createMethodContext$1(target, propertyKey, descriptor);
|
|
307
|
-
const metadata = getEndpointMetadata(descriptor.value, context);
|
|
308
|
-
if (schema) {
|
|
309
|
-
const validatedValue = schema.safeParse(value);
|
|
310
|
-
if (!validatedValue.success) throw new Error(`[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`);
|
|
311
|
-
metadata.customAttributes.set(token, validatedValue.data);
|
|
312
|
-
} else metadata.customAttributes.set(token, true);
|
|
313
|
-
return descriptor;
|
|
314
|
-
} else {
|
|
315
|
-
const isController = hasControllerMetadata(target);
|
|
316
|
-
const isModule = hasModuleMetadata(target);
|
|
317
|
-
const isManaged = hasManagedMetadata(target);
|
|
318
|
-
if (!isController && !isModule && !isManaged) throw new Error("[Navios] Attribute can only be applied to classes with @Controller, @Module, or other Navios-managed decorators");
|
|
319
|
-
const context = createClassContext$1(target);
|
|
320
|
-
const metadata = isController ? getControllerMetadata(target, context) : isModule ? getModuleMetadata(target, context) : isManaged ? getManagedMetadata(target) : null;
|
|
321
|
-
if (!metadata) throw new Error("[Navios] Could not determine metadata for attribute target");
|
|
322
|
-
if (schema) {
|
|
323
|
-
const validatedValue = schema.safeParse(value);
|
|
324
|
-
if (!validatedValue.success) throw new Error(`[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`);
|
|
325
|
-
metadata.customAttributes.set(token, validatedValue.data);
|
|
326
|
-
} else metadata.customAttributes.set(token, true);
|
|
327
|
-
return target;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return decorator;
|
|
331
|
-
};
|
|
332
|
-
res.token = token;
|
|
333
|
-
if (schema) res.schema = schema;
|
|
334
|
-
return res;
|
|
335
|
-
}
|
|
336
|
-
static get(attribute, target) {
|
|
337
|
-
return target.customAttributes.get(attribute.token) ?? null;
|
|
338
|
-
}
|
|
339
|
-
static getAll(attribute, target) {
|
|
340
|
-
const values = Array.from(target.customAttributes.entries()).filter(([key]) => key === attribute.token).map(([, value]) => value);
|
|
341
|
-
return values.length > 0 ? values : null;
|
|
342
|
-
}
|
|
343
|
-
static getLast(attribute, target) {
|
|
344
|
-
for (let i = target.length - 1; i >= 0; i--) {
|
|
345
|
-
const value = target[i].customAttributes.get(attribute.token);
|
|
346
|
-
if (value) return value;
|
|
347
|
-
}
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
static has(attribute, target) {
|
|
351
|
-
return target.customAttributes.has(attribute.token);
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
//#endregion
|
|
356
|
-
export { LegacyAttributeFactory as AttributeFactory, LegacyAttributeFactory, Controller, Endpoint, Factory, Header, HttpCode, Injectable, Module, Multipart, Stream, UseGuards, createClassContext, createMethodContext };
|
|
357
63
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["createClassContext","Module","OriginalModule","options","controllers","imports","guards","target","context","originalDecorator","createClassContext","Controller","OriginalController","options","target","context","originalDecorator","createMethodContext","Endpoint","OriginalEndpoint","endpoint","target","propertyKey","descriptor","Error","typedDescriptor","context","originalDecorator","result","value","createClassContext","createMethodContext","UseGuards","OriginalUseGuards","guards","decoratorImpl","target","propertyKey","descriptor","undefined","context","originalDecorator","result","value","createMethodContext","Header","OriginalHeader","name","value","target","propertyKey","descriptor","context","originalDecorator","result","createMethodContext","HttpCode","OriginalHttpCode","code","target","propertyKey","descriptor","context","originalDecorator","result","value","createMethodContext","Multipart","OriginalMultipart","endpoint","target","propertyKey","descriptor","Error","context","originalDecorator","result","value","createMethodContext","Stream","OriginalStream","endpoint","target","propertyKey","descriptor","value","Error","typedDescriptor","context","originalDecorator","result","createClassContext","createMethodContext","getControllerMetadata","getEndpointMetadata","getModuleMetadata","hasControllerMetadata","hasModuleMetadata","getManagedMetadata","hasManagedMetadata","LegacyAttributeFactory","createAttribute","token","schema","res","value","decorator","target","propertyKey","descriptor","isMethodDecorator","undefined","context","metadata","validatedValue","safeParse","success","Error","toString","error","customAttributes","set","data","isController","isModule","isManaged","get","attribute","getAll","values","Array","from","entries","filter","key","map","length","getLast","i","has","AttributeFactory"],"sources":["../../src/legacy-compat/decorators/module.decorator.mts","../../src/legacy-compat/decorators/controller.decorator.mts","../../src/legacy-compat/decorators/endpoint.decorator.mts","../../src/legacy-compat/decorators/use-guards.decorator.mts","../../src/legacy-compat/decorators/header.decorator.mts","../../src/legacy-compat/decorators/http-code.decorator.mts","../../src/legacy-compat/decorators/multipart.decorator.mts","../../src/legacy-compat/decorators/stream.decorator.mts","../../src/legacy-compat/attribute.factory.mts"],"sourcesContent":["import type { ClassType } from '@navios/di'\nimport { createClassContext } from '@navios/di/legacy-compat'\n\nimport { Module as OriginalModule, type ModuleOptions } from '../../decorators/module.decorator.mjs'\n\n/**\n * Legacy-compatible Module decorator.\n * \n * Works with TypeScript experimental decorators (legacy API).\n * \n * @param options - Module configuration options\n * @returns A class decorator compatible with legacy decorator API\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 options: ModuleOptions = {\n controllers: [],\n imports: [],\n guards: [],\n },\n) {\n return function (target: ClassType) {\n const context = createClassContext(target)\n const originalDecorator = OriginalModule(options)\n return originalDecorator(target, context)\n }\n}\n\n","import type { ClassType } from '@navios/di'\nimport { createClassContext } from '@navios/di/legacy-compat'\n\nimport type { ControllerOptions } from '../../decorators/controller.decorator.mjs'\n\nimport { Controller as OriginalController } from '../../decorators/controller.decorator.mjs'\n\n/**\n * Legacy-compatible Controller decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n *\n * @param options - Controller configuration options\n * @returns A class decorator compatible with legacy decorator API\n *\n * @example\n * ```typescript\n * @Controller({ guards: [AuthGuard] })\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser() { }\n * }\n * ```\n */\nexport function Controller(options: ControllerOptions = {}) {\n return function (target: ClassType) {\n const context = createClassContext(target)\n const originalDecorator = OriginalController(options)\n return originalDecorator(target, context)\n }\n}\n","import type {\n EndpointHandler,\n EndpointOptions,\n RequestArgs,\n} from '@navios/builder'\nimport { createMethodContext } from '@navios/di/legacy-compat'\nimport type { z } from 'zod/v4'\n\nimport { Endpoint as OriginalEndpoint } from '../../decorators/endpoint.decorator.mjs'\n\n/**\n * Type helper to constrain a PropertyDescriptor's value to match an endpoint signature.\n * Note: In legacy decorators, type constraints are checked when the decorator is applied,\n * but may not be preserved perfectly when decorators are stacked.\n */\ntype EndpointMethodDescriptor<Config extends EndpointOptions> =\n TypedPropertyDescriptor<\n (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) => Promise<z.input<Config['responseSchema']>>\n >\n\n/**\n * Legacy-compatible Endpoint decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n * Provides type safety by ensuring method signatures match the endpoint configuration.\n *\n * @param endpoint - The endpoint declaration from @navios/builder\n * @returns A method decorator compatible with legacy decorator API\n *\n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function Endpoint<const Config extends EndpointOptions>(\n endpoint: EndpointHandler<Config, false>,\n) {\n return function (\n target: any,\n propertyKey: string | symbol,\n descriptor: EndpointMethodDescriptor<Config>,\n ): PropertyDescriptor | void {\n if (!descriptor) {\n throw new Error(\n '[Navios] @Endpoint decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',\n )\n }\n // Type check the descriptor value matches expected signature\n const typedDescriptor = descriptor as EndpointMethodDescriptor<Config>\n const context = createMethodContext(target, propertyKey, typedDescriptor)\n const originalDecorator = OriginalEndpoint(endpoint)\n // @ts-expect-error - we don't need to type the value\n const result = originalDecorator(typedDescriptor.value, context)\n if (result !== typedDescriptor.value) {\n typedDescriptor.value = result as any\n }\n return typedDescriptor\n }\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\nimport { createClassContext, createMethodContext } from '@navios/di/legacy-compat'\n\nimport type { CanActivate } from '../../interfaces/index.mjs'\n\nimport { UseGuards as OriginalUseGuards } from '../../decorators/use-guards.decorator.mjs'\n\n/**\n * Legacy-compatible UseGuards decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n * Can be applied to classes or methods.\n *\n * @param guards - Guard classes or injection tokens to apply\n * @returns A class or method decorator compatible with legacy decorator API\n *\n * @example\n * ```typescript\n * // Apply to a controller\n * @Controller()\n * @UseGuards(AuthGuard, RoleGuard)\n * export class UserController { }\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 // Create the decorator function\n // Note: TypeScript's legacy decorator system has strict type checking for decorators\n // We use a flexible implementation that works for both class and method decorators\n function decoratorImpl(\n target: ClassType | Function,\n propertyKey?: string | symbol,\n descriptor?: PropertyDescriptor,\n ): any {\n // Determine if this is a class or method decorator\n if (propertyKey !== undefined && descriptor !== undefined) {\n // Method decorator\n const context = createMethodContext(\n target as Function,\n propertyKey,\n descriptor,\n )\n const originalDecorator = OriginalUseGuards(...guards)\n const result = originalDecorator(descriptor.value, context)\n if (result !== descriptor.value) {\n descriptor.value = result\n }\n return descriptor\n } else {\n // Class decorator\n const context = createClassContext(target as ClassType)\n const originalDecorator = OriginalUseGuards(...guards)\n return originalDecorator(target as ClassType, context)\n }\n }\n\n // Return with 'any' type to work around TypeScript's strict decorator checking\n // TypeScript's legacy decorator system cannot properly type-check decorators\n // that work as both class and method decorators. The runtime behavior is correct.\n // When used as a class decorator, it returns the class (preserving type at runtime)\n // When used as a method decorator, it returns the PropertyDescriptor\n // @ts-ignore - TypeScript limitation with dual-purpose legacy decorators\n return decoratorImpl as any\n}\n","import { createMethodContext } from '@navios/di/legacy-compat'\n\nimport type { HttpHeader } from '../../interfaces/index.mjs'\n\nimport { Header as OriginalHeader } from '../../decorators/header.decorator.mjs'\n\n/**\n * Legacy-compatible Header decorator.\n * \n * Works with TypeScript experimental decorators (legacy API).\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 compatible with legacy decorator API\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 function <T extends object>(\n target: T,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor,\n ) {\n const context = createMethodContext(target, propertyKey, descriptor)\n const originalDecorator = OriginalHeader(name, value)\n const result = originalDecorator(descriptor.value, context)\n if (result !== descriptor.value) {\n descriptor.value = result\n }\n return descriptor\n }\n}\n\n","import { createMethodContext } from '@navios/di/legacy-compat'\n\nimport { HttpCode as OriginalHttpCode } from '../../decorators/http-code.decorator.mjs'\n\n/**\n * Legacy-compatible HttpCode decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n *\n * @param code - The HTTP status code to return (e.g., 201, 204, 202)\n * @returns A method decorator compatible with legacy decorator API\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 function <T extends object>(\n target: T,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor,\n ) {\n const context = createMethodContext(target, propertyKey, descriptor)\n const originalDecorator = OriginalHttpCode(code)\n const result = originalDecorator(descriptor.value, context)\n if (result !== descriptor.value) {\n descriptor.value = result\n }\n return descriptor\n }\n}\n","import type {\n EndpointHandler,\n EndpointOptions,\n RequestArgs,\n} from '@navios/builder'\nimport { createMethodContext } from '@navios/di/legacy-compat'\nimport type { z } from 'zod/v4'\n\nimport { Multipart as OriginalMultipart } from '../../decorators/multipart.decorator.mjs'\n\n/**\n * Type helper to constrain a PropertyDescriptor's value to match a multipart endpoint signature.\n * Note: In legacy decorators, type constraints are checked when the decorator is applied,\n * but may not be preserved perfectly when decorators are stacked.\n */\ntype MultipartMethodDescriptor<Config extends EndpointOptions> =\n TypedPropertyDescriptor<\n (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) => Promise<z.input<Config['responseSchema']>>\n >\n\n/**\n * Legacy-compatible Multipart decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n * Provides type safety by ensuring method signatures match the endpoint configuration.\n *\n * @param endpoint - The multipart endpoint declaration from @navios/builder\n * @returns A method decorator compatible with legacy decorator API\n *\n * @example\n * ```typescript\n * @Controller()\n * export class FileController {\n * @Multipart(uploadFileEndpoint)\n * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): MultipartResult<typeof uploadFileEndpoint> {\n * const { file } = request.data\n * return { url: 'https://example.com/file.jpg' }\n * }\n * }\n * ```\n */\nexport function Multipart<const Config extends EndpointOptions>(\n endpoint: EndpointHandler<Config, false>,\n) {\n return function <T extends object>(\n target: T,\n propertyKey: string | symbol,\n descriptor: MultipartMethodDescriptor<Config>,\n ): PropertyDescriptor | void {\n if (!descriptor) {\n throw new Error(\n '[Navios] @Multipart decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',\n )\n }\n const context = createMethodContext(target, propertyKey, descriptor)\n const originalDecorator = OriginalMultipart(endpoint)\n // @ts-expect-error - we don't need to type the value\n const result = originalDecorator(descriptor.value, context)\n if (result !== descriptor.value) {\n descriptor.value = result as any\n }\n return descriptor\n }\n}\n","import type {\n BaseEndpointOptions,\n RequestArgs,\n StreamHandler,\n} from '@navios/builder'\nimport { createMethodContext } from '@navios/di/legacy-compat'\n\nimport { Stream as OriginalStream } from '../../decorators/stream.decorator.mjs'\n\n/**\n * Type helper to constrain a PropertyDescriptor's value to match a stream endpoint signature.\n * Supports both with and without reply parameter (Bun doesn't use reply parameter).\n * Note: In legacy decorators, type constraints are checked when the decorator is applied,\n * but may not be preserved perfectly when decorators are stacked.\n */\ntype StreamMethodDescriptor<Config extends BaseEndpointOptions> =\n | TypedPropertyDescriptor<\n (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n reply: any,\n ) => any\n >\n | TypedPropertyDescriptor<\n (\n params: RequestArgs<\n Config['url'],\n Config['querySchema'],\n Config['requestSchema'],\n Config['urlParamsSchema'],\n true\n >,\n ) => any\n >\n\n/**\n * Legacy-compatible Stream decorator.\n *\n * Works with TypeScript experimental decorators (legacy API).\n * Provides type safety by ensuring method signatures match the endpoint configuration.\n *\n * @param endpoint - The stream endpoint declaration from @navios/builder\n * @returns A method decorator compatible with legacy decorator API\n *\n * @example\n * ```typescript\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<const Config extends BaseEndpointOptions>(\n endpoint: StreamHandler<Config, false>,\n) {\n return function (\n target: any,\n propertyKey: string | symbol,\n descriptor: StreamMethodDescriptor<Config>,\n ): PropertyDescriptor | void {\n if (!descriptor || !descriptor.value) {\n throw new Error(\n '[Navios] @Stream decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',\n )\n }\n // Type check the descriptor value matches expected signature\n const typedDescriptor = descriptor as StreamMethodDescriptor<Config>\n const context = createMethodContext(target, propertyKey, typedDescriptor)\n const originalDecorator = OriginalStream(endpoint)\n // Stage3 decorator returns void in type signature but actually returns the function\n // We know value is defined because we checked above\n const result = originalDecorator(typedDescriptor.value!, context) as\n | typeof typedDescriptor.value\n | void\n if (result && result !== typedDescriptor.value) {\n typedDescriptor.value = result as any\n }\n return typedDescriptor\n }\n}\n","import type { ClassType } from '@navios/di'\nimport { createClassContext, createMethodContext } from '@navios/di/legacy-compat'\nimport type { z, ZodType } from 'zod/v4'\n\nimport type {\n ControllerMetadata,\n HandlerMetadata,\n ModuleMetadata,\n} from '../metadata/index.mjs'\n\nimport {\n getControllerMetadata,\n getEndpointMetadata,\n getModuleMetadata,\n hasControllerMetadata,\n hasModuleMetadata,\n} from '../metadata/index.mjs'\nimport {\n getManagedMetadata,\n hasManagedMetadata,\n} from '../metadata/navios-managed.metadata.mjs'\n\n/**\n * Type for a legacy class/method attribute decorator without a value.\n *\n * Attributes are custom metadata decorators that can be applied to modules,\n * controllers, and endpoints.\n */\nexport type LegacyClassAttribute = {\n (): ClassDecorator & MethodDecorator\n token: symbol\n}\n\n/**\n * Type for a legacy class/method attribute decorator with a validated value.\n *\n * @typeParam S - The Zod schema type for validation\n */\nexport type LegacyClassSchemaAttribute<S extends ZodType> = {\n (value: z.input<S>): ClassDecorator & MethodDecorator\n token: symbol\n schema: ZodType\n}\n\n/**\n * Legacy-compatible factory for creating custom attribute decorators.\n *\n * Works with TypeScript experimental decorators (legacy API).\n *\n * Attributes allow you to add custom metadata to modules, controllers, and endpoints.\n * This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.\n *\n * @example\n * ```typescript\n * // Create a simple boolean attribute\n * const Public = LegacyAttributeFactory.createAttribute(Symbol.for('Public'))\n *\n * // Use it as a decorator\n * @Controller()\n * @Public()\n * export class PublicController { }\n *\n * // Check if attribute exists\n * if (LegacyAttributeFactory.has(Public, controllerMetadata)) {\n * // Skip authentication\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Create an attribute with a validated value\n * const RateLimit = LegacyAttributeFactory.createAttribute(\n * Symbol.for('RateLimit'),\n * z.object({ requests: z.number(), window: z.number() })\n * )\n *\n * // Use it with a value\n * @Endpoint(apiEndpoint)\n * @RateLimit({ requests: 100, window: 60000 })\n * async handler() { }\n *\n * // Get the value\n * const limit = LegacyAttributeFactory.get(RateLimit, endpointMetadata)\n * // limit is typed as { requests: number, window: number } | null\n * ```\n */\nexport class LegacyAttributeFactory {\n /**\n * Creates a simple attribute decorator without a value.\n *\n * @param token - A unique symbol to identify this attribute\n * @returns A decorator function that can be applied to classes or methods\n *\n * @example\n * ```typescript\n * const Public = LegacyAttributeFactory.createAttribute(Symbol.for('Public'))\n *\n * @Public()\n * @Controller()\n * export class PublicController { }\n * ```\n */\n static createAttribute(token: symbol): LegacyClassAttribute\n /**\n * Creates an attribute decorator with a validated value.\n *\n * @param token - A unique symbol to identify this attribute\n * @param schema - A Zod schema to validate the attribute value\n * @returns A decorator function that accepts a value and can be applied to classes or methods\n *\n * @example\n * ```typescript\n * const RateLimit = LegacyAttributeFactory.createAttribute(\n * Symbol.for('RateLimit'),\n * z.object({ requests: z.number(), window: z.number() })\n * )\n *\n * @RateLimit({ requests: 100, window: 60000 })\n * @Endpoint(apiEndpoint)\n * async handler() { }\n * ```\n */\n static createAttribute<T extends ZodType>(\n token: symbol,\n schema: T,\n ): LegacyClassSchemaAttribute<T>\n\n static createAttribute(token: symbol, schema?: ZodType) {\n const res = (value?: unknown) => {\n // Return a decorator that can handle both class and method targets\n function decorator(target: any): any\n function decorator(\n target: any,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor,\n ): PropertyDescriptor\n function decorator(\n target: any,\n propertyKey?: string | symbol,\n descriptor?: PropertyDescriptor,\n ): any {\n const isMethodDecorator =\n propertyKey !== undefined && descriptor !== undefined\n\n if (isMethodDecorator) {\n // Method decorator - apply to endpoint\n const context = createMethodContext(target, propertyKey, descriptor)\n const metadata = getEndpointMetadata(descriptor.value, context)\n\n if (schema) {\n const validatedValue = schema.safeParse(value)\n if (!validatedValue.success) {\n throw new Error(\n `[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`,\n )\n }\n metadata.customAttributes.set(token, validatedValue.data)\n } else {\n metadata.customAttributes.set(token, true)\n }\n return descriptor\n } else {\n // Class decorator\n const isController = hasControllerMetadata(target as ClassType)\n const isModule = hasModuleMetadata(target as ClassType)\n const isManaged = hasManagedMetadata(target as ClassType)\n\n if (!isController && !isModule && !isManaged) {\n throw new Error(\n '[Navios] Attribute can only be applied to classes with @Controller, @Module, or other Navios-managed decorators',\n )\n }\n\n const context = createClassContext(target)\n const metadata = isController\n ? getControllerMetadata(target, context)\n : isModule\n ? getModuleMetadata(target, context)\n : isManaged\n ? getManagedMetadata(target)!\n : null\n\n if (!metadata) {\n throw new Error(\n '[Navios] Could not determine metadata for attribute target',\n )\n }\n\n if (schema) {\n const validatedValue = schema.safeParse(value)\n if (!validatedValue.success) {\n throw new Error(\n `[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`,\n )\n }\n metadata.customAttributes.set(token, validatedValue.data)\n } else {\n metadata.customAttributes.set(token, true)\n }\n return target\n }\n }\n return decorator\n }\n res.token = token\n if (schema) {\n res.schema = schema\n }\n return res\n }\n\n /**\n * Gets the value of an attribute from metadata.\n *\n * Returns `null` if the attribute is not present.\n * For simple attributes (without values), returns `true` if present.\n *\n * @param attribute - The attribute decorator\n * @param target - The metadata object (module, controller, or handler)\n * @returns The attribute value, `true` for simple attributes, or `null` if not found\n *\n * @example\n * ```typescript\n * const isPublic = LegacyAttributeFactory.get(Public, controllerMetadata)\n * // isPublic is true | null\n *\n * const rateLimit = LegacyAttributeFactory.get(RateLimit, endpointMetadata)\n * // rateLimit is { requests: number, window: number } | null\n * ```\n */\n static get(\n attribute: LegacyClassAttribute,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): true | null\n static get<T extends ZodType>(\n attribute: LegacyClassSchemaAttribute<T>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): z.output<T> | null\n static get(\n attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ) {\n return target.customAttributes.get(attribute.token) ?? null\n }\n\n /**\n * Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).\n *\n * Returns `null` if the attribute is not present.\n *\n * @param attribute - The attribute decorator\n * @param target - The metadata object (module, controller, or handler)\n * @returns An array of attribute values, or `null` if not found\n *\n * @example\n * ```typescript\n * const tags = LegacyAttributeFactory.getAll(Tag, endpointMetadata)\n * // tags is string[] | null\n * ```\n */\n static getAll(\n attribute: LegacyClassAttribute,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): Array<true> | null\n static getAll<T extends ZodType>(\n attribute: LegacyClassSchemaAttribute<T>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): Array<z.output<T>> | null\n static getAll(\n attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ) {\n const values = Array.from(target.customAttributes.entries())\n .filter(([key]) => key === attribute.token)\n .map(([, value]) => value)\n return values.length > 0 ? values : null\n }\n\n /**\n * Gets the last value of an attribute from an array of metadata objects.\n *\n * Searches from the end of the array backwards, useful for finding the most\n * specific attribute value (e.g., endpoint-level overrides module-level).\n *\n * @param attribute - The attribute decorator\n * @param target - An array of metadata objects (typically [module, controller, handler])\n * @returns The last attribute value found, or `null` if not found\n *\n * @example\n * ```typescript\n * // Check attribute hierarchy: endpoint -> controller -> module\n * const rateLimit = LegacyAttributeFactory.getLast(RateLimit, [\n * moduleMetadata,\n * controllerMetadata,\n * endpointMetadata\n * ])\n * ```\n */\n static getLast(\n attribute: LegacyClassAttribute,\n target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],\n ): true | null\n static getLast<T extends ZodType>(\n attribute: LegacyClassSchemaAttribute<T>,\n target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],\n ): z.output<T> | null\n static getLast(\n attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,\n target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],\n ) {\n for (let i = target.length - 1; i >= 0; i--) {\n const value = target[i].customAttributes.get(attribute.token)\n if (value) {\n return value\n }\n }\n return null\n }\n\n /**\n * Checks if an attribute is present on the metadata object.\n *\n * @param attribute - The attribute decorator\n * @param target - The metadata object (module, controller, or handler)\n * @returns `true` if the attribute is present, `false` otherwise\n *\n * @example\n * ```typescript\n * if (LegacyAttributeFactory.has(Public, controllerMetadata)) {\n * // Skip authentication\n * }\n * ```\n */\n static has(\n attribute: LegacyClassAttribute,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): boolean\n static has<T extends ZodType>(\n attribute: LegacyClassSchemaAttribute<T>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ): boolean\n static has(\n attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,\n target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,\n ) {\n return target.customAttributes.has(attribute.token)\n }\n}\n\n// Re-export as AttributeFactory for convenience\nexport { LegacyAttributeFactory as AttributeFactory }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;GAuBA,SAAgBC,OACdE,UAAyB;CACvBC,aAAa,EAAE;CACfC,SAAS,EAAE;CACXC,QAAQ,EAAE;CACX,EAAA;AAED,QAAO,SAAUC,QAAiB;EAChC,MAAMC,UAAUR,qBAAmBO,OAAAA;AAEnC,SAD0BL,SAAeC,QAAAA,CAChBI,QAAQC,QAAAA;;;;;;;;;;;;;;;;;;;;;;GCTrC,SAAgBG,WAAWE,UAA6B,EAAE,EAAA;AACxD,QAAO,SAAUC,QAAiB;EAChC,MAAMC,UAAUL,qBAAmBI,OAAAA;AAEnC,SAD0BF,aAAmBC,QAAAA,CACpBC,QAAQC,QAAAA;;;;;;;;;;;;;;;;;;;;;;;;;GCoBrC,SAAgBG,SACdE,UAAwC;AAExC,QAAO,SACLC,QACAC,aACAC,YAA4C;AAE5C,MAAI,CAACA,WACH,OAAM,IAAIC,MACR,0GAAA;EAIJ,MAAMC,kBAAkBF;EACxB,MAAMG,UAAUT,sBAAoBI,QAAQC,aAAaG,gBAAAA;EAGzD,MAAMG,SAFoBT,WAAiBC,SAAAA,CAEVK,gBAAgBI,OAAOH,QAAAA;AACxD,MAAIE,WAAWH,gBAAgBI,MAC7BJ,iBAAgBI,QAAQD;AAE1B,SAAOH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GClCX,SAAgBO,UACd,GAAGE,QAGA;CAKH,SAASC,cACPC,QACAC,aACAC,YAA+B;AAG/B,MAAID,gBAAgBE,UAAaD,eAAeC,QAAW;GAEzD,MAAMC,UAAUT,sBACdK,QACAC,aACAC,WAAAA;GAGF,MAAMI,SADoBT,YAAAA,GAAqBC,OAAAA,CACdI,WAAWK,OAAOH,QAAAA;AACnD,OAAIE,WAAWJ,WAAWK,MACxBL,YAAWK,QAAQD;AAErB,UAAOJ;SACF;GAEL,MAAME,UAAUV,qBAAmBM,OAAAA;AAEnC,UAD0BH,YAAAA,GAAqBC,OAAAA,CACtBE,QAAqBI,QAAAA;;;AAUlD,QAAOL;;;;;;;;;;;;;;;;;;;;;;;;;GCnDT,SAAgBU,OAAOE,MAAkBC,OAAiC;AACxE,QAAO,SACLC,QACAC,aACAC,YAA8B;EAE9B,MAAMC,UAAUR,sBAAoBK,QAAQC,aAAaC,WAAAA;EAEzD,MAAMG,SADoBR,SAAeC,MAAMC,MAAAA,CACdG,WAAWH,OAAOI,QAAAA;AACnD,MAAIE,WAAWH,WAAWH,MACxBG,YAAWH,QAAQM;AAErB,SAAOH;;;;;;;;;;;;;;;;;;;;;;;;;GCfX,SAAgBK,SAASE,MAAY;AACnC,QAAO,SACLC,QACAC,aACAC,YAA8B;EAE9B,MAAMC,UAAUP,sBAAoBI,QAAQC,aAAaC,WAAAA;EAEzD,MAAMG,SADoBP,WAAiBC,KAAAA,CACVG,WAAWI,OAAOH,QAAAA;AACnD,MAAIE,WAAWH,WAAWI,MACxBJ,YAAWI,QAAQD;AAErB,SAAOH;;;;;;;;;;;;;;;;;;;;;;;;;;GCaX,SAAgBM,UACdE,UAAwC;AAExC,QAAO,SACLC,QACAC,aACAC,YAA6C;AAE7C,MAAI,CAACA,WACH,OAAM,IAAIC,MACR,2GAAA;EAGJ,MAAMC,UAAUR,sBAAoBI,QAAQC,aAAaC,WAAAA;EAGzD,MAAMI,SAFoBR,YAAkBC,SAAAA,CAEXG,WAAWK,OAAOH,QAAAA;AACnD,MAAIE,WAAWJ,WAAWK,MACxBL,YAAWK,QAAQD;AAErB,SAAOJ;;;;;;;;;;;;;;;;;;;;;;;;;;GCRX,SAAgBO,OACdE,UAAsC;AAEtC,QAAO,SACLC,QACAC,aACAC,YAA0C;AAE1C,MAAI,CAACA,cAAc,CAACA,WAAWC,MAC7B,OAAM,IAAIC,MACR,wGAAA;EAIJ,MAAMC,kBAAkBH;EACxB,MAAMI,UAAUV,sBAAoBI,QAAQC,aAAaI,gBAAAA;EAIzD,MAAMG,SAHoBV,SAAeC,SAAAA,CAGRM,gBAAgBF,OAAQG,QAAAA;AAGzD,MAAIE,UAAUA,WAAWH,gBAAgBF,MACvCE,iBAAgBF,QAAQK;AAE1B,SAAOH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GCAX,IAAaa,yBAAb,MAAaA;CAyCX,OAAOC,gBAAgBC,OAAeC,QAAkB;EACtD,MAAMC,OAAOC,UAAAA;GAQX,SAASC,UACPC,QACAC,aACAC,YAA+B;AAK/B,QAFED,gBAAgBG,UAAaF,eAAeE,QAEvB;KAErB,MAAMC,UAAUpB,sBAAoBe,QAAQC,aAAaC,WAAAA;KACzD,MAAMI,WAAWnB,oBAAoBe,WAAWJ,OAAOO,QAAAA;AAEvD,SAAIT,QAAQ;MACV,MAAMW,iBAAiBX,OAAOY,UAAUV,MAAAA;AACxC,UAAI,CAACS,eAAeE,QAClB,OAAM,IAAIC,MACR,wCAAwCf,MAAMgB,UAAQ,CAAG,IAAIJ,eAAeK,QAAO;AAGvFN,eAASO,iBAAiBC,IAAInB,OAAOY,eAAeQ,KAAI;WAExDT,UAASO,iBAAiBC,IAAInB,OAAO,KAAA;AAEvC,YAAOO;WACF;KAEL,MAAMc,eAAe3B,sBAAsBW,OAAAA;KAC3C,MAAMiB,WAAW3B,kBAAkBU,OAAAA;KACnC,MAAMkB,YAAY1B,mBAAmBQ,OAAAA;AAErC,SAAI,CAACgB,gBAAgB,CAACC,YAAY,CAACC,UACjC,OAAM,IAAIR,MACR,kHAAA;KAIJ,MAAML,UAAUrB,qBAAmBgB,OAAAA;KACnC,MAAMM,WAAWU,eACb9B,sBAAsBc,QAAQK,QAAAA,GAC9BY,WACE7B,kBAAkBY,QAAQK,QAAAA,GAC1Ba,YACE3B,mBAAmBS,OAAAA,GACnB;AAER,SAAI,CAACM,SACH,OAAM,IAAII,MACR,6DAAA;AAIJ,SAAId,QAAQ;MACV,MAAMW,iBAAiBX,OAAOY,UAAUV,MAAAA;AACxC,UAAI,CAACS,eAAeE,QAClB,OAAM,IAAIC,MACR,wCAAwCf,MAAMgB,UAAQ,CAAG,IAAIJ,eAAeK,QAAO;AAGvFN,eAASO,iBAAiBC,IAAInB,OAAOY,eAAeQ,KAAI;WAExDT,UAASO,iBAAiBC,IAAInB,OAAO,KAAA;AAEvC,YAAOK;;;AAGX,UAAOD;;AAETF,MAAIF,QAAQA;AACZ,MAAIC,OACFC,KAAID,SAASA;AAEf,SAAOC;;CA8BT,OAAOsB,IACLC,WACApB,QACA;AACA,SAAOA,OAAOa,iBAAiBM,IAAIC,UAAUzB,MAAK,IAAK;;CA0BzD,OAAO0B,OACLD,WACApB,QACA;EACA,MAAMsB,SAASC,MAAMC,KAAKxB,OAAOa,iBAAiBY,SAAO,CAAA,CACtDC,QAAQ,CAACC,SAASA,QAAQP,UAAUzB,MAAK,CACzCiC,KAAK,GAAG9B,WAAWA,MAAAA;AACtB,SAAOwB,OAAOO,SAAS,IAAIP,SAAS;;CA+BtC,OAAOQ,QACLV,WACApB,QACA;AACA,OAAK,IAAI+B,IAAI/B,OAAO6B,SAAS,GAAGE,KAAK,GAAGA,KAAK;GAC3C,MAAMjC,QAAQE,OAAO+B,GAAGlB,iBAAiBM,IAAIC,UAAUzB,MAAK;AAC5D,OAAIG,MACF,QAAOA;;AAGX,SAAO;;CAyBT,OAAOkC,IACLZ,WACApB,QACA;AACA,SAAOA,OAAOa,iBAAiBmB,IAAIZ,UAAUzB,MAAK"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["createClassContext","createMethodContext","StandardAttributeFactory","StandardModule","StandardUseGuards","StandardUseInterceptors"],"sources":["../../src/legacy-compat/legacy-decorator.mts","../../src/legacy-compat/attribute-factory.mts","../../src/legacy-compat/module.mts","../../src/legacy-compat/use-guards.mts","../../src/legacy-compat/use-interceptors.mts"],"sourcesContent":["import { createClassContext, createMethodContext } from '@navios/di/legacy-compat'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type StandardDecorator = (target: any, context: any) => any\n\n/** A decorator that accepts every legacy call shape. */\nexport type LegacyAnyDecorator = (\n target: any,\n propertyKey?: string | symbol,\n descriptor?: PropertyDescriptor,\n) => any\n\n/**\n * Turns a standard decorator into one that accepts the legacy call shapes:\n * `(constructor)`, `(prototype, key, descriptor)` and `(prototype, key)`.\n */\nexport function legacy(decorator: StandardDecorator) {\n return (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any => {\n if (propertyKey === undefined) {\n return decorator(target, createClassContext(target)) ?? target\n }\n if (descriptor && typeof descriptor.value === 'function') {\n const context = createMethodContext(target, propertyKey, descriptor)\n const replaced = decorator(descriptor.value, context)\n if (replaced && replaced !== descriptor.value) {\n descriptor.value = replaced\n }\n return descriptor\n }\n const context = createMethodContext(target, propertyKey, descriptor ?? {})\n decorator(undefined, { ...context, kind: 'field' })\n return undefined\n }\n}\n","import type { InferInput, StandardSchemaV1 } from '@navios/di'\n\nimport { AttributeFactory as StandardAttributeFactory } from '../attributes/attribute-factory.mjs'\n\nimport type { AttributeApplication } from '../attributes/attribute-factory.mjs'\n\nimport { legacy } from './legacy-decorator.mjs'\n\nimport type { LegacyAnyDecorator } from './legacy-decorator.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * An attribute application usable as a legacy decorator and in\n * `handler(endpoint, { attributes: [...] }, fn)`.\n */\nexport type LegacyAttributeApplication = LegacyAnyDecorator &\n Pick<AttributeApplication, 'token' | 'value'>\n\nexport interface LegacyClassAttribute {\n (): LegacyAttributeApplication\n readonly token: symbol\n}\n\nexport interface LegacyClassSchemaAttribute<Schema extends StandardSchemaV1> {\n (value: InferInput<Schema>): LegacyAttributeApplication\n readonly token: symbol\n readonly schema: Schema\n}\n\nfunction createAttribute(token: symbol): LegacyClassAttribute\nfunction createAttribute<Schema extends StandardSchemaV1>(\n token: symbol,\n schema: Schema,\n): LegacyClassSchemaAttribute<Schema>\nfunction createAttribute(token: symbol, schema?: StandardSchemaV1): any {\n const standard: any = schema\n ? StandardAttributeFactory.createAttribute(token, schema)\n : StandardAttributeFactory.createAttribute(token)\n const attribute = (value?: unknown) => {\n const application: AttributeApplication = standard(value)\n return Object.assign(legacy(application), {\n token: application.token,\n value: application.value,\n })\n }\n return Object.assign(attribute, schema ? { token, schema } : { token })\n}\n\n/**\n * `AttributeFactory` whose attributes are legacy decorators. Reading\n * (`get`, `getAll`, `has`) is the same as the standard one.\n */\nexport const AttributeFactory = {\n createAttribute,\n get: StandardAttributeFactory.get,\n getAll: StandardAttributeFactory.getAll,\n has: StandardAttributeFactory.has,\n}\n","import type { ClassType } from '@navios/di'\n\nimport { Module as StandardModule } from '../modules/module.mjs'\n\nimport type { ModuleOptions } from '../modules/module-options.mjs'\n\nimport { legacy } from './legacy-decorator.mjs'\n\nexport function Module(options: ModuleOptions = {}) {\n return legacy(StandardModule(options)) as <T extends ClassType>(target: T) => T\n}\n","import { UseGuards as StandardUseGuards } from '../guards/use-guards.mjs'\n\nimport type { GuardClass } from '../guards/guard.mjs'\n\nimport { legacy } from './legacy-decorator.mjs'\n\nimport type { LegacyAnyDecorator } from './legacy-decorator.mjs'\n\nexport function UseGuards(...guards: GuardClass[]): LegacyAnyDecorator {\n return legacy(StandardUseGuards(...guards))\n}\n","import { UseInterceptors as StandardUseInterceptors } from '../interceptors/use-interceptors.mjs'\n\nimport type { InterceptorClass } from '../interceptors/interceptor.mjs'\n\nimport { legacy } from './legacy-decorator.mjs'\n\nimport type { LegacyAnyDecorator } from './legacy-decorator.mjs'\n\nexport function UseInterceptors(...interceptors: InterceptorClass[]): LegacyAnyDecorator {\n return legacy(StandardUseInterceptors(...interceptors))\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,OAAO,WAA8B;CACnD,QAAQ,QAAa,aAA+B,eAAyC;EAC3F,IAAI,gBAAgB,KAAA,GAClB,OAAO,UAAU,QAAQA,qBAAmB,MAAM,CAAC,KAAK;EAE1D,IAAI,cAAc,OAAO,WAAW,UAAU,YAAY;GACxD,MAAM,UAAUC,sBAAoB,QAAQ,aAAa,UAAU;GACnE,MAAM,WAAW,UAAU,WAAW,OAAO,OAAO;GACpD,IAAI,YAAY,aAAa,WAAW,OACtC,WAAW,QAAQ;GAErB,OAAO;EACT;EAEA,UAAU,KAAA,GAAW;GAAE,GADPA,sBAAoB,QAAQ,aAAa,cAAc,CAAC,CACxC;GAAG,MAAM;EAAQ,CAAC;CAEpD;AACF;;ACCA,SAAS,gBAAgB,OAAe,QAAgC;CACtE,MAAM,WAAgB,SAClBC,mBAAyB,gBAAgB,OAAO,MAAM,IACtDA,mBAAyB,gBAAgB,KAAK;CAClD,MAAM,aAAa,UAAoB;EACrC,MAAM,cAAoC,SAAS,KAAK;EACxD,OAAO,OAAO,OAAO,OAAO,WAAW,GAAG;GACxC,OAAO,YAAY;GACnB,OAAO,YAAY;EACrB,CAAC;CACH;CACA,OAAO,OAAO,OAAO,WAAW,SAAS;EAAE;EAAO;CAAO,IAAI,EAAE,MAAM,CAAC;AACxE;;;;;AAMA,MAAa,mBAAmB;CAC9B;CACA,KAAKA,mBAAyB;CAC9B,QAAQA,mBAAyB;CACjC,KAAKA,mBAAyB;AAChC;;AClDA,SAAgB,OAAO,UAAyB,CAAC,GAAG;CAClD,OAAO,OAAOC,SAAe,OAAO,CAAC;AACvC;;ACFA,SAAgB,UAAU,GAAG,QAA0C;CACrE,OAAO,OAAOC,YAAkB,GAAG,MAAM,CAAC;AAC5C;;ACFA,SAAgB,gBAAgB,GAAG,cAAsD;CACvF,OAAO,OAAOC,kBAAwB,GAAG,YAAY,CAAC;AACxD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { a as classGuards, i as classAttributes, o as classInterceptors, r as memberMetadata, t as applyAttributes } from "./attribute-value-DMEA255r.mjs";
|
|
2
|
+
import { r as defineModuleMetadata } from "./module-metadata-k3RTt20x.mjs";
|
|
3
|
+
import { InjectableScope, registerInjectable } from "@navios/di";
|
|
4
|
+
// src/attributes/attribute-factory.mts
|
|
5
|
+
function apply(token, value) {
|
|
6
|
+
const decorator = (target, context) => {
|
|
7
|
+
if (context.kind === "class") classAttributes(context).set(token, value);
|
|
8
|
+
else if (context.kind === "method" || context.kind === "field") {
|
|
9
|
+
if (typeof context.name !== "string") throw new Error("[Navios] Attributes cannot be applied to symbol-named members");
|
|
10
|
+
memberMetadata(context, context.name).attributes.set(token, value);
|
|
11
|
+
} else throw new Error("[Navios] Attributes can only be applied to classes, methods and fields");
|
|
12
|
+
return context.kind === "field" ? void 0 : target;
|
|
13
|
+
};
|
|
14
|
+
return Object.assign(decorator, {
|
|
15
|
+
token,
|
|
16
|
+
value
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function layers(source) {
|
|
20
|
+
const attributes = source.attributes;
|
|
21
|
+
if (attributes instanceof Map) return [attributes];
|
|
22
|
+
const route = attributes;
|
|
23
|
+
return [
|
|
24
|
+
route.handler,
|
|
25
|
+
route.controller,
|
|
26
|
+
route.module
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates and reads attributes: typed metadata attached to modules,
|
|
31
|
+
* controllers and handlers.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
35
|
+
* export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))
|
|
36
|
+
*
|
|
37
|
+
* if (AttributeFactory.has(Public, ctx.handler)) return true
|
|
38
|
+
* const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
var AttributeFactory = class {
|
|
42
|
+
static createAttribute(token, schema) {
|
|
43
|
+
const attribute = (value) => {
|
|
44
|
+
if (!schema) return apply(token, true);
|
|
45
|
+
const result = schema["~standard"].validate(value);
|
|
46
|
+
if (result instanceof Promise) {
|
|
47
|
+
result.catch(() => {});
|
|
48
|
+
throw new Error(`[Navios] Attribute ${token.toString()} must use a schema that validates synchronously`);
|
|
49
|
+
}
|
|
50
|
+
if (result.issues) throw new Error(`[Navios] Invalid value for attribute ${token.toString()}: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
51
|
+
return apply(token, result.value);
|
|
52
|
+
};
|
|
53
|
+
return Object.assign(attribute, schema ? {
|
|
54
|
+
token,
|
|
55
|
+
schema
|
|
56
|
+
} : { token });
|
|
57
|
+
}
|
|
58
|
+
static get(attribute, source) {
|
|
59
|
+
for (const layer of layers(source)) if (layer.has(attribute.token)) return layer.get(attribute.token);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
static getAll(attribute, source) {
|
|
63
|
+
const values = [];
|
|
64
|
+
for (const layer of layers(source)) if (layer.has(attribute.token)) values.push(layer.get(attribute.token));
|
|
65
|
+
return values;
|
|
66
|
+
}
|
|
67
|
+
static has(attribute, source) {
|
|
68
|
+
return layers(source).some((layer) => layer.has(attribute.token));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// src/metadata/attach-classes.mts
|
|
72
|
+
/**
|
|
73
|
+
* The decorator behind `@UseGuards` and `@UseInterceptors`: adds classes to
|
|
74
|
+
* the list of a class or of one of its members.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function attachClasses(kind, classes, name) {
|
|
78
|
+
return (target, context) => {
|
|
79
|
+
if (context.kind === "class") {
|
|
80
|
+
const list = kind === "guards" ? classGuards(context) : classInterceptors(context);
|
|
81
|
+
for (const cls of classes) if (!list.includes(cls)) list.push(cls);
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
if (context.kind !== "method" && context.kind !== "field") throw new Error(`[Navios] @${name} can only be used on classes, methods and fields.`);
|
|
85
|
+
if (typeof context.name !== "string") throw new Error(`[Navios] @${name} cannot be used on symbol-named members.`);
|
|
86
|
+
const list = memberMetadata(context, context.name)[kind];
|
|
87
|
+
for (const cls of classes) if (!list.includes(cls)) list.push(cls);
|
|
88
|
+
return context.kind === "field" ? void 0 : target;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// src/guards/use-guards.mts
|
|
92
|
+
/**
|
|
93
|
+
* Adds guards to a module, a controller or a handler. Guards run in the
|
|
94
|
+
* order module, controller, handler, and within one level in the order given.
|
|
95
|
+
*
|
|
96
|
+
* On a class, place it above `@Controller` / `@Module`.
|
|
97
|
+
*/
|
|
98
|
+
function UseGuards(...guards) {
|
|
99
|
+
return attachClasses("guards", guards, "UseGuards");
|
|
100
|
+
}
|
|
101
|
+
// src/interceptors/use-interceptors.mts
|
|
102
|
+
/**
|
|
103
|
+
* Adds interceptors to a module, a controller or a handler. The first one
|
|
104
|
+
* given is the outermost. They run for what the guards let through, unlike the
|
|
105
|
+
* interceptors of the application.
|
|
106
|
+
*
|
|
107
|
+
* On a class, place it above `@Controller` / `@Module`.
|
|
108
|
+
*/
|
|
109
|
+
function UseInterceptors(...interceptors) {
|
|
110
|
+
return attachClasses("interceptors", interceptors, "UseInterceptors");
|
|
111
|
+
}
|
|
112
|
+
// src/modules/module.mts
|
|
113
|
+
/**
|
|
114
|
+
* Marks a class as a module: a group of handlers with shared guards,
|
|
115
|
+
* interceptors and attributes.
|
|
116
|
+
*/
|
|
117
|
+
function Module(options = {}) {
|
|
118
|
+
return (target, context) => {
|
|
119
|
+
if (context.kind !== "class") throw new Error("[Navios] @Module can only be used on classes.");
|
|
120
|
+
applyAttributes(defineModuleMetadata(target, context, options).attributes, options.attributes);
|
|
121
|
+
registerInjectable(target, { scope: InjectableScope.Singleton });
|
|
122
|
+
return target;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Registers a class as a module without decorator syntax.
|
|
127
|
+
*/
|
|
128
|
+
function registerModule(target, options = {}) {
|
|
129
|
+
applyAttributes(defineModuleMetadata(target, { metadata: {} }, options).attributes, options.attributes);
|
|
130
|
+
registerInjectable(target, { scope: InjectableScope.Singleton });
|
|
131
|
+
return target;
|
|
132
|
+
}
|
|
133
|
+
export { AttributeFactory as a, UseGuards as i, registerModule as n, UseInterceptors as r, Module as t };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=module-Bha7GER_.mjs.map
|