@navios/core 0.5.1 → 0.7.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 +93 -0
- package/README.md +18 -1
- package/docs/README.md +1 -0
- package/docs/legacy-compat.md +320 -0
- package/docs/testing.md +140 -17
- package/lib/index-BFwNx9WQ.d.cts +1951 -0
- package/lib/index-BFwNx9WQ.d.cts.map +1 -0
- package/lib/index-D657ijFO.d.mts +1951 -0
- package/lib/index-D657ijFO.d.mts.map +1 -0
- package/lib/index.cjs +157 -0
- package/lib/index.d.cts +3 -0
- package/lib/index.d.mts +3 -188
- package/lib/index.mjs +4 -1439
- package/lib/legacy-compat/index.cjs +315 -0
- package/lib/legacy-compat/index.cjs.map +1 -0
- package/lib/legacy-compat/index.d.cts +219 -0
- package/lib/legacy-compat/index.d.cts.map +1 -0
- package/lib/legacy-compat/index.d.mts +219 -0
- package/lib/legacy-compat/index.d.mts.map +1 -0
- package/lib/legacy-compat/index.mjs +308 -0
- package/lib/legacy-compat/index.mjs.map +1 -0
- package/lib/src-Cb1aTjl0.cjs +5710 -0
- package/lib/src-Cb1aTjl0.cjs.map +1 -0
- package/lib/src-DzPY5s6d.mjs +5353 -0
- package/lib/src-DzPY5s6d.mjs.map +1 -0
- package/lib/testing/index.cjs +106 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +156 -0
- package/lib/testing/index.d.cts.map +1 -0
- package/lib/testing/index.d.mts +156 -0
- package/lib/testing/index.d.mts.map +1 -0
- package/lib/testing/index.mjs +100 -0
- package/lib/testing/index.mjs.map +1 -0
- package/lib/use-guards.decorator-DdvUhB03.cjs +622 -0
- package/lib/use-guards.decorator-DdvUhB03.cjs.map +1 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs +454 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +1 -0
- package/package.json +26 -6
- package/project.json +2 -2
- package/src/attribute.factory.d.mts +175 -0
- package/src/attribute.factory.d.mts.map +1 -0
- package/src/attribute.factory.mts +154 -0
- package/src/config/config-service.interface.d.mts +39 -0
- package/src/config/config-service.interface.d.mts.map +1 -0
- package/src/config/config-service.interface.mts +31 -0
- package/src/config/config.provider.d.mts +46 -0
- package/src/config/config.provider.d.mts.map +1 -0
- package/src/config/config.provider.mts +36 -0
- package/src/config/config.service.d.mts +108 -0
- package/src/config/config.service.d.mts.map +1 -0
- package/src/config/config.service.mts +94 -4
- package/src/config/index.d.mts +6 -0
- package/src/config/index.d.mts.map +1 -0
- package/src/config/types.d.mts +13 -0
- package/src/config/types.d.mts.map +1 -0
- package/src/config/utils/helpers.d.mts +3 -0
- package/src/config/utils/helpers.d.mts.map +1 -0
- package/src/config/utils/index.d.mts +2 -0
- package/src/config/utils/index.d.mts.map +1 -0
- package/src/decorators/controller.decorator.d.mts +33 -0
- package/src/decorators/controller.decorator.d.mts.map +1 -0
- package/src/decorators/controller.decorator.mts +28 -0
- package/src/decorators/endpoint.decorator.d.mts +89 -0
- package/src/decorators/endpoint.decorator.d.mts.map +1 -0
- package/src/decorators/endpoint.decorator.mts +76 -0
- package/src/decorators/header.decorator.d.mts +22 -0
- package/src/decorators/header.decorator.d.mts.map +1 -0
- package/src/decorators/header.decorator.mts +19 -0
- package/src/decorators/http-code.decorator.d.mts +22 -0
- package/src/decorators/http-code.decorator.d.mts.map +1 -0
- package/src/decorators/http-code.decorator.mts +20 -0
- package/src/decorators/index.d.mts +9 -0
- package/src/decorators/index.d.mts.map +1 -0
- package/src/decorators/module.decorator.d.mts +42 -0
- package/src/decorators/module.decorator.d.mts.map +1 -0
- package/src/decorators/module.decorator.mts +34 -0
- package/src/decorators/multipart.decorator.d.mts +54 -0
- package/src/decorators/multipart.decorator.d.mts.map +1 -0
- package/src/decorators/multipart.decorator.mts +41 -0
- package/src/decorators/stream.decorator.d.mts +42 -0
- package/src/decorators/stream.decorator.d.mts.map +1 -0
- package/src/decorators/stream.decorator.mts +33 -0
- package/src/decorators/use-guards.decorator.d.mts +33 -0
- package/src/decorators/use-guards.decorator.d.mts.map +1 -0
- package/src/decorators/use-guards.decorator.mts +29 -0
- package/src/exceptions/bad-request.exception.d.mts +26 -0
- package/src/exceptions/bad-request.exception.d.mts.map +1 -0
- package/src/exceptions/bad-request.exception.mts +21 -0
- package/src/exceptions/conflict.exception.d.mts +29 -0
- package/src/exceptions/conflict.exception.d.mts.map +1 -0
- package/src/exceptions/conflict.exception.mts +24 -0
- package/src/exceptions/forbidden.exception.d.mts +28 -0
- package/src/exceptions/forbidden.exception.d.mts.map +1 -0
- package/src/exceptions/forbidden.exception.mts +23 -0
- package/src/exceptions/http.exception.d.mts +33 -0
- package/src/exceptions/http.exception.d.mts.map +1 -0
- package/src/exceptions/http.exception.mts +26 -0
- package/src/exceptions/index.d.mts +8 -0
- package/src/exceptions/index.d.mts.map +1 -0
- package/src/exceptions/internal-server-error.exception.d.mts +31 -0
- package/src/exceptions/internal-server-error.exception.d.mts.map +1 -0
- package/src/exceptions/internal-server-error.exception.mts +26 -0
- package/src/exceptions/not-found.exception.d.mts +30 -0
- package/src/exceptions/not-found.exception.d.mts.map +1 -0
- package/src/exceptions/not-found.exception.mts +23 -0
- package/src/exceptions/unauthorized.exception.d.mts +28 -0
- package/src/exceptions/unauthorized.exception.d.mts.map +1 -0
- package/src/exceptions/unauthorized.exception.mts +23 -0
- package/src/factories/endpoint-adapter.factory.d.mts +6 -0
- package/src/factories/endpoint-adapter.factory.d.mts.map +1 -0
- package/src/factories/http-adapter.factory.d.mts +6 -0
- package/src/factories/http-adapter.factory.d.mts.map +1 -0
- package/src/factories/index.d.mts +8 -0
- package/src/factories/index.d.mts.map +1 -0
- package/src/factories/index.mts +1 -0
- package/src/factories/multipart-adapter.factory.d.mts +6 -0
- package/src/factories/multipart-adapter.factory.d.mts.map +1 -0
- package/src/factories/reply.factory.d.mts +6 -0
- package/src/factories/reply.factory.d.mts.map +1 -0
- package/src/factories/request.factory.d.mts +6 -0
- package/src/factories/request.factory.d.mts.map +1 -0
- package/src/factories/stream-adapter.factory.d.mts +6 -0
- package/src/factories/stream-adapter.factory.d.mts.map +1 -0
- package/src/factories/xml-stream-adapter.factory.d.mts +6 -0
- package/src/factories/xml-stream-adapter.factory.d.mts.map +1 -0
- package/src/factories/xml-stream-adapter.factory.mts +20 -0
- package/src/index.d.mts +15 -0
- package/src/index.d.mts.map +1 -0
- package/src/index.mts +1 -0
- package/src/interfaces/abstract-execution-context.inteface.d.mts +44 -0
- package/src/interfaces/abstract-execution-context.inteface.d.mts.map +1 -0
- package/src/interfaces/abstract-execution-context.inteface.mts +35 -0
- package/src/interfaces/abstract-http-adapter.interface.d.mts +15 -0
- package/src/interfaces/abstract-http-adapter.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-cors-options.interface.d.mts +58 -0
- package/src/interfaces/abstract-http-cors-options.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.d.mts +7 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.d.mts.map +1 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +2 -2
- package/src/interfaces/abstract-http-listen-options.interface.d.mts +5 -0
- package/src/interfaces/abstract-http-listen-options.interface.d.mts.map +1 -0
- package/src/interfaces/can-activate.d.mts +36 -0
- package/src/interfaces/can-activate.d.mts.map +1 -0
- package/src/interfaces/can-activate.mts +31 -0
- package/src/interfaces/http-header.d.mts +10 -0
- package/src/interfaces/http-header.d.mts.map +1 -0
- package/src/interfaces/index.d.mts +9 -0
- package/src/interfaces/index.d.mts.map +1 -0
- package/src/interfaces/navios-module.d.mts +29 -0
- package/src/interfaces/navios-module.d.mts.map +1 -0
- package/src/interfaces/navios-module.mts +25 -0
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +420 -0
- package/src/legacy-compat/__type-tests__/tsconfig.json +15 -0
- package/src/legacy-compat/context-compat.d.mts +19 -0
- package/src/legacy-compat/context-compat.d.mts.map +1 -0
- package/src/legacy-compat/context-compat.mts +93 -0
- package/src/legacy-compat/decorators/controller.decorator.d.mts +21 -0
- package/src/legacy-compat/decorators/controller.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/controller.decorator.mts +31 -0
- package/src/legacy-compat/decorators/endpoint.decorator.d.mts +33 -0
- package/src/legacy-compat/decorators/endpoint.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/endpoint.decorator.mts +99 -0
- package/src/legacy-compat/decorators/header.decorator.d.mts +24 -0
- package/src/legacy-compat/decorators/header.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/header.decorator.mts +42 -0
- package/src/legacy-compat/decorators/http-code.decorator.d.mts +22 -0
- package/src/legacy-compat/decorators/http-code.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/http-code.decorator.mts +38 -0
- package/src/legacy-compat/decorators/index.d.mts +9 -0
- package/src/legacy-compat/decorators/index.d.mts.map +1 -0
- package/src/legacy-compat/decorators/index.mts +9 -0
- package/src/legacy-compat/decorators/module.decorator.d.mts +22 -0
- package/src/legacy-compat/decorators/module.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/module.decorator.mts +37 -0
- package/src/legacy-compat/decorators/multipart.decorator.d.mts +34 -0
- package/src/legacy-compat/decorators/multipart.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/multipart.decorator.mts +93 -0
- package/src/legacy-compat/decorators/stream.decorator.d.mts +34 -0
- package/src/legacy-compat/decorators/stream.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/stream.decorator.mts +76 -0
- package/src/legacy-compat/decorators/use-guards.decorator.d.mts +29 -0
- package/src/legacy-compat/decorators/use-guards.decorator.d.mts.map +1 -0
- package/src/legacy-compat/decorators/use-guards.decorator.mts +80 -0
- package/src/legacy-compat/index.d.mts +19 -0
- package/src/legacy-compat/index.d.mts.map +1 -0
- package/src/legacy-compat/index.mts +40 -0
- package/src/logger/console-logger.service.d.mts +196 -0
- package/src/logger/console-logger.service.d.mts.map +1 -0
- package/src/logger/console-logger.service.mts +15 -2
- package/src/logger/index.d.mts +7 -0
- package/src/logger/index.d.mts.map +1 -0
- package/src/logger/log-levels.d.mts +14 -0
- package/src/logger/log-levels.d.mts.map +1 -0
- package/src/logger/log-levels.mts +9 -0
- package/src/logger/logger-service.interface.d.mts +36 -0
- package/src/logger/logger-service.interface.d.mts.map +1 -0
- package/src/logger/logger.service.d.mts +57 -0
- package/src/logger/logger.service.d.mts.map +1 -0
- package/src/logger/logger.service.mts +19 -0
- package/src/logger/logger.tokens.d.mts +36 -0
- package/src/logger/logger.tokens.d.mts.map +1 -0
- package/src/logger/logger.tokens.mts +23 -0
- package/src/logger/utils/cli-colors.util.d.mts +10 -0
- package/src/logger/utils/cli-colors.util.d.mts.map +1 -0
- package/src/logger/utils/filter-log-levelts.util.d.mts +6 -0
- package/src/logger/utils/filter-log-levelts.util.d.mts.map +1 -0
- package/src/logger/utils/index.d.mts +6 -0
- package/src/logger/utils/index.d.mts.map +1 -0
- package/src/logger/utils/is-log-level-enabled.d.mts +8 -0
- package/src/logger/utils/is-log-level-enabled.d.mts.map +1 -0
- package/src/logger/utils/is-log-level.util.d.mts +6 -0
- package/src/logger/utils/is-log-level.util.d.mts.map +1 -0
- package/src/logger/utils/shared.utils.d.mts +14 -0
- package/src/logger/utils/shared.utils.d.mts.map +1 -0
- package/src/metadata/controller.metadata.d.mts +13 -0
- package/src/metadata/controller.metadata.d.mts.map +1 -0
- package/src/metadata/handler.metadata.d.mts +18 -0
- package/src/metadata/handler.metadata.d.mts.map +1 -0
- package/src/metadata/index.d.mts +4 -0
- package/src/metadata/index.d.mts.map +1 -0
- package/src/metadata/module.metadata.d.mts +13 -0
- package/src/metadata/module.metadata.d.mts.map +1 -0
- package/src/navios.application.d.mts +210 -0
- package/src/navios.application.d.mts.map +1 -0
- package/src/navios.application.mts +176 -2
- package/src/navios.environment.d.mts +11 -0
- package/src/navios.environment.d.mts.map +1 -0
- package/src/navios.factory.d.mts +68 -0
- package/src/navios.factory.d.mts.map +1 -0
- package/src/navios.factory.mts +59 -1
- package/src/services/guard-runner.service.d.mts +10 -0
- package/src/services/guard-runner.service.d.mts.map +1 -0
- package/src/services/guard-runner.service.mts +12 -11
- package/src/services/index.d.mts +3 -0
- package/src/services/index.d.mts.map +1 -0
- package/src/services/module-loader.service.d.mts +17 -0
- package/src/services/module-loader.service.d.mts.map +1 -0
- package/src/services/module-loader.service.mts +16 -11
- package/src/stores/index.d.mts +2 -0
- package/src/stores/index.d.mts.map +1 -0
- package/src/stores/index.mts +1 -0
- package/src/stores/request-id.store.d.mts +37 -0
- package/src/stores/request-id.store.d.mts.map +1 -0
- package/src/stores/request-id.store.mts +43 -0
- package/src/testing/index.mts +2 -0
- package/src/testing/testing-module.mts +231 -0
- package/src/tokens/endpoint-adapter.token.d.mts +4 -0
- package/src/tokens/endpoint-adapter.token.d.mts.map +1 -0
- package/src/tokens/execution-context.token.d.mts +5 -0
- package/src/tokens/execution-context.token.d.mts.map +1 -0
- package/src/tokens/http-adapter.token.d.mts +4 -0
- package/src/tokens/http-adapter.token.d.mts.map +1 -0
- package/src/tokens/index.d.mts +9 -0
- package/src/tokens/index.d.mts.map +1 -0
- package/src/tokens/index.mts +1 -0
- package/src/tokens/multipart-adapter.token.d.mts +4 -0
- package/src/tokens/multipart-adapter.token.d.mts.map +1 -0
- package/src/tokens/reply.token.d.mts +3 -0
- package/src/tokens/reply.token.d.mts.map +1 -0
- package/src/tokens/request.token.d.mts +3 -0
- package/src/tokens/request.token.d.mts.map +1 -0
- package/src/tokens/stream-adapter.token.d.mts +4 -0
- package/src/tokens/stream-adapter.token.d.mts.map +1 -0
- package/src/tokens/xml-stream-adapter.token.d.mts +4 -0
- package/src/tokens/xml-stream-adapter.token.d.mts.map +1 -0
- package/src/tokens/xml-stream-adapter.token.mts +8 -0
- package/tsconfig.lib.json +1 -1
- package/tsconfig.spec.json +3 -0
- package/tsdown.config.mts +35 -0
- package/vitest.config.mts +6 -0
- package/lib/_tsup-dts-rollup.d.mts +0 -1352
- package/lib/_tsup-dts-rollup.d.ts +0 -1352
- package/lib/index.d.ts +0 -188
- package/lib/index.js +0 -1519
- package/lib/index.js.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/tsup.config.mts +0 -13
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseEndpointConfig,
|
|
3
|
+
EndpointFunctionArgs,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
} from '@navios/builder'
|
|
6
|
+
import type { z, ZodType } from 'zod/v4'
|
|
7
|
+
|
|
8
|
+
import { Endpoint as OriginalEndpoint } from '../../decorators/endpoint.decorator.mjs'
|
|
9
|
+
import { createMethodContext } from '../context-compat.mjs'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type helper to constrain a PropertyDescriptor's value to match an endpoint signature.
|
|
13
|
+
* Note: In legacy decorators, type constraints are checked when the decorator is applied,
|
|
14
|
+
* but may not be preserved perfectly when decorators are stacked.
|
|
15
|
+
*/
|
|
16
|
+
type EndpointMethodDescriptor<
|
|
17
|
+
Url extends string,
|
|
18
|
+
QuerySchema,
|
|
19
|
+
RequestSchema,
|
|
20
|
+
ResponseSchema extends ZodType,
|
|
21
|
+
> = TypedPropertyDescriptor<
|
|
22
|
+
(
|
|
23
|
+
params: QuerySchema extends ZodType
|
|
24
|
+
? RequestSchema extends ZodType
|
|
25
|
+
? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>
|
|
26
|
+
: EndpointFunctionArgs<Url, QuerySchema, undefined, true>
|
|
27
|
+
: RequestSchema extends ZodType
|
|
28
|
+
? EndpointFunctionArgs<Url, undefined, RequestSchema, true>
|
|
29
|
+
: EndpointFunctionArgs<Url, undefined, undefined, true>,
|
|
30
|
+
) => Promise<z.input<ResponseSchema>>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Legacy-compatible Endpoint decorator.
|
|
35
|
+
*
|
|
36
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
37
|
+
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
38
|
+
*
|
|
39
|
+
* @param endpoint - The endpoint declaration from @navios/builder
|
|
40
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* @Controller()
|
|
45
|
+
* export class UserController {
|
|
46
|
+
* @Endpoint(getUserEndpoint)
|
|
47
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
|
|
48
|
+
* return { id: '1', name: 'John' }
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function Endpoint<
|
|
54
|
+
Method extends HttpMethod = HttpMethod,
|
|
55
|
+
Url extends string = string,
|
|
56
|
+
QuerySchema = undefined,
|
|
57
|
+
ResponseSchema extends ZodType = ZodType,
|
|
58
|
+
RequestSchema = ZodType,
|
|
59
|
+
>(endpoint: {
|
|
60
|
+
config: BaseEndpointConfig<
|
|
61
|
+
Method,
|
|
62
|
+
Url,
|
|
63
|
+
QuerySchema,
|
|
64
|
+
ResponseSchema,
|
|
65
|
+
RequestSchema
|
|
66
|
+
>
|
|
67
|
+
}) {
|
|
68
|
+
return function (
|
|
69
|
+
target: any,
|
|
70
|
+
propertyKey: string | symbol,
|
|
71
|
+
descriptor: EndpointMethodDescriptor<
|
|
72
|
+
Url,
|
|
73
|
+
QuerySchema,
|
|
74
|
+
RequestSchema,
|
|
75
|
+
ResponseSchema
|
|
76
|
+
>,
|
|
77
|
+
): PropertyDescriptor | void {
|
|
78
|
+
if (!descriptor) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'[Navios] @Endpoint decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
// Type check the descriptor value matches expected signature
|
|
84
|
+
const typedDescriptor = descriptor as EndpointMethodDescriptor<
|
|
85
|
+
Url,
|
|
86
|
+
QuerySchema,
|
|
87
|
+
RequestSchema,
|
|
88
|
+
ResponseSchema
|
|
89
|
+
>
|
|
90
|
+
const context = createMethodContext(target, propertyKey, typedDescriptor)
|
|
91
|
+
const originalDecorator = OriginalEndpoint(endpoint)
|
|
92
|
+
// @ts-expect-error - we don't need to type the value
|
|
93
|
+
const result = originalDecorator(typedDescriptor.value, context)
|
|
94
|
+
if (result !== typedDescriptor.value) {
|
|
95
|
+
typedDescriptor.value = result
|
|
96
|
+
}
|
|
97
|
+
return typedDescriptor
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpHeader } from '../../interfaces/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Legacy-compatible Header decorator.
|
|
4
|
+
*
|
|
5
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
6
|
+
*
|
|
7
|
+
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
8
|
+
* @param value - The header value (string, number, or array of strings)
|
|
9
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Controller()
|
|
14
|
+
* export class UserController {
|
|
15
|
+
* @Endpoint(getUserEndpoint)
|
|
16
|
+
* @Header('Cache-Control', 'max-age=3600')
|
|
17
|
+
* async getUser() {
|
|
18
|
+
* return { id: '1', name: 'John' }
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function Header(name: HttpHeader, value: string | number | string[]): <T extends object>(target: T, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
24
|
+
//# sourceMappingURL=header.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.decorator.d.mts","sourceRoot":"","sources":["header.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAK5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,IACvD,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EACT,aAAa,MAAM,GAAG,MAAM,EAC5B,YAAY,kBAAkB,wBAUjC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { HttpHeader } from '../../interfaces/index.mjs'
|
|
2
|
+
|
|
3
|
+
import { Header as OriginalHeader } from '../../decorators/header.decorator.mjs'
|
|
4
|
+
import { createMethodContext } from '../context-compat.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Legacy-compatible Header decorator.
|
|
8
|
+
*
|
|
9
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
10
|
+
*
|
|
11
|
+
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
12
|
+
* @param value - The header value (string, number, or array of strings)
|
|
13
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @Controller()
|
|
18
|
+
* export class UserController {
|
|
19
|
+
* @Endpoint(getUserEndpoint)
|
|
20
|
+
* @Header('Cache-Control', 'max-age=3600')
|
|
21
|
+
* async getUser() {
|
|
22
|
+
* return { id: '1', name: 'John' }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function Header(name: HttpHeader, value: string | number | string[]) {
|
|
28
|
+
return function <T extends object>(
|
|
29
|
+
target: T,
|
|
30
|
+
propertyKey: string | symbol,
|
|
31
|
+
descriptor: PropertyDescriptor,
|
|
32
|
+
) {
|
|
33
|
+
const context = createMethodContext(target, propertyKey, descriptor)
|
|
34
|
+
const originalDecorator = OriginalHeader(name, value)
|
|
35
|
+
const result = originalDecorator(descriptor.value, context)
|
|
36
|
+
if (result !== descriptor.value) {
|
|
37
|
+
descriptor.value = result
|
|
38
|
+
}
|
|
39
|
+
return descriptor
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy-compatible HttpCode decorator.
|
|
3
|
+
*
|
|
4
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
5
|
+
*
|
|
6
|
+
* @param code - The HTTP status code to return (e.g., 201, 204, 202)
|
|
7
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Controller()
|
|
12
|
+
* export class UserController {
|
|
13
|
+
* @Endpoint(createUserEndpoint)
|
|
14
|
+
* @HttpCode(201)
|
|
15
|
+
* async createUser() {
|
|
16
|
+
* return { id: '1', name: 'John' }
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function HttpCode(code: number): <T extends object>(target: T, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
22
|
+
//# sourceMappingURL=http-code.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-code.decorator.d.mts","sourceRoot":"","sources":["http-code.decorator.mts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,IAClB,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EACT,aAAa,MAAM,GAAG,MAAM,EAC5B,YAAY,kBAAkB,wBAUjC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HttpCode as OriginalHttpCode } from '../../decorators/http-code.decorator.mjs'
|
|
2
|
+
import { createMethodContext } from '../context-compat.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Legacy-compatible HttpCode decorator.
|
|
6
|
+
*
|
|
7
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
8
|
+
*
|
|
9
|
+
* @param code - The HTTP status code to return (e.g., 201, 204, 202)
|
|
10
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Controller()
|
|
15
|
+
* export class UserController {
|
|
16
|
+
* @Endpoint(createUserEndpoint)
|
|
17
|
+
* @HttpCode(201)
|
|
18
|
+
* async createUser() {
|
|
19
|
+
* return { id: '1', name: 'John' }
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function HttpCode(code: number) {
|
|
25
|
+
return function <T extends object>(
|
|
26
|
+
target: T,
|
|
27
|
+
propertyKey: string | symbol,
|
|
28
|
+
descriptor: PropertyDescriptor,
|
|
29
|
+
) {
|
|
30
|
+
const context = createMethodContext(target, propertyKey, descriptor)
|
|
31
|
+
const originalDecorator = OriginalHttpCode(code)
|
|
32
|
+
const result = originalDecorator(descriptor.value, context)
|
|
33
|
+
if (result !== descriptor.value) {
|
|
34
|
+
descriptor.value = result
|
|
35
|
+
}
|
|
36
|
+
return descriptor
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './module.decorator.mjs';
|
|
2
|
+
export * from './controller.decorator.mjs';
|
|
3
|
+
export * from './endpoint.decorator.mjs';
|
|
4
|
+
export * from './use-guards.decorator.mjs';
|
|
5
|
+
export * from './header.decorator.mjs';
|
|
6
|
+
export * from './http-code.decorator.mjs';
|
|
7
|
+
export * from './multipart.decorator.mjs';
|
|
8
|
+
export * from './stream.decorator.mjs';
|
|
9
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './module.decorator.mjs'
|
|
2
|
+
export * from './controller.decorator.mjs'
|
|
3
|
+
export * from './endpoint.decorator.mjs'
|
|
4
|
+
export * from './use-guards.decorator.mjs'
|
|
5
|
+
export * from './header.decorator.mjs'
|
|
6
|
+
export * from './http-code.decorator.mjs'
|
|
7
|
+
export * from './multipart.decorator.mjs'
|
|
8
|
+
export * from './stream.decorator.mjs'
|
|
9
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di';
|
|
2
|
+
import { type ModuleOptions } from '../../decorators/module.decorator.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Legacy-compatible Module decorator.
|
|
5
|
+
*
|
|
6
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
7
|
+
*
|
|
8
|
+
* @param options - Module configuration options
|
|
9
|
+
* @returns A class decorator compatible with legacy decorator API
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Module({
|
|
14
|
+
* controllers: [UserController, AuthController],
|
|
15
|
+
* imports: [DatabaseModule],
|
|
16
|
+
* guards: [AuthGuard],
|
|
17
|
+
* })
|
|
18
|
+
* export class AppModule {}
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function Module(options?: ModuleOptions): (target: ClassType) => ClassType;
|
|
22
|
+
//# sourceMappingURL=module.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.decorator.d.mts","sourceRoot":"","sources":["module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAA;AAGpG;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CACpB,OAAO,GAAE,aAIR,IAEgB,QAAQ,SAAS,eAKnC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di'
|
|
2
|
+
|
|
3
|
+
import { Module as OriginalModule, type ModuleOptions } from '../../decorators/module.decorator.mjs'
|
|
4
|
+
import { createClassContext } from '../context-compat.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Legacy-compatible Module decorator.
|
|
8
|
+
*
|
|
9
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
10
|
+
*
|
|
11
|
+
* @param options - Module configuration options
|
|
12
|
+
* @returns A class decorator compatible with legacy decorator API
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Module({
|
|
17
|
+
* controllers: [UserController, AuthController],
|
|
18
|
+
* imports: [DatabaseModule],
|
|
19
|
+
* guards: [AuthGuard],
|
|
20
|
+
* })
|
|
21
|
+
* export class AppModule {}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function Module(
|
|
25
|
+
options: ModuleOptions = {
|
|
26
|
+
controllers: [],
|
|
27
|
+
imports: [],
|
|
28
|
+
guards: [],
|
|
29
|
+
},
|
|
30
|
+
) {
|
|
31
|
+
return function (target: ClassType) {
|
|
32
|
+
const context = createClassContext(target)
|
|
33
|
+
const originalDecorator = OriginalModule(options)
|
|
34
|
+
return originalDecorator(target, context)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseEndpointConfig, EndpointFunctionArgs, HttpMethod } from '@navios/builder';
|
|
2
|
+
import type { z, ZodObject, ZodType } from 'zod/v4';
|
|
3
|
+
/**
|
|
4
|
+
* Type helper to constrain a PropertyDescriptor's value to match a multipart endpoint signature.
|
|
5
|
+
* Note: In legacy decorators, type constraints are checked when the decorator is applied,
|
|
6
|
+
* but may not be preserved perfectly when decorators are stacked.
|
|
7
|
+
*/
|
|
8
|
+
type MultipartMethodDescriptor<Url extends string, QuerySchema, RequestSchema, ResponseSchema extends ZodType> = TypedPropertyDescriptor<(params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z.input<ResponseSchema>>>;
|
|
9
|
+
/**
|
|
10
|
+
* Legacy-compatible Multipart decorator.
|
|
11
|
+
*
|
|
12
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
13
|
+
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
14
|
+
*
|
|
15
|
+
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
16
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Controller()
|
|
21
|
+
* export class FileController {
|
|
22
|
+
* @Multipart(uploadFileEndpoint)
|
|
23
|
+
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): MultipartResult<typeof uploadFileEndpoint> {
|
|
24
|
+
* const { file } = request.data
|
|
25
|
+
* return { url: 'https://example.com/file.jpg' }
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function Multipart<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
31
|
+
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
32
|
+
}): <T extends object>(target: T, propertyKey: string | symbol, descriptor: MultipartMethodDescriptor<Url, QuerySchema, RequestSchema, ResponseSchema>) => PropertyDescriptor | void;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=multipart.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.decorator.d.mts","sourceRoot":"","sources":["multipart.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAKnD;;;;GAIG;AACH,KAAK,yBAAyB,CAC5B,GAAG,SAAS,MAAM,EAClB,WAAW,EACX,aAAa,EACb,cAAc,SAAS,OAAO,IAC5B,uBAAuB,CACzB,CACE,MAAM,EAAE,WAAW,SAAS,SAAS,GACjC,aAAa,SAAS,OAAO,GAC3B,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,GACrD,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,CAAC,GACnD,aAAa,SAAS,OAAO,GAC3B,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,CAAC,GACnD,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,KAClD,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CACtC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CACvB,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,WAAW,GAAG,SAAS,EACvB,cAAc,SAAS,OAAO,GAAG,OAAO,EACxC,aAAa,GAAG,OAAO,EACvB,QAAQ,EAAE;IACV,MAAM,EAAE,kBAAkB,CACxB,MAAM,EACN,GAAG,EACH,WAAW,EACX,cAAc,EACd,aAAa,CACd,CAAA;CACF,IACkB,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EACT,aAAa,MAAM,GAAG,MAAM,EAC5B,YAAY,yBAAyB,CACnC,GAAG,EACH,WAAW,EACX,aAAa,EACb,cAAc,CACf,KACA,kBAAkB,GAAG,IAAI,CAe7B"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseEndpointConfig,
|
|
3
|
+
EndpointFunctionArgs,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
} from '@navios/builder'
|
|
6
|
+
import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
7
|
+
|
|
8
|
+
import { Multipart as OriginalMultipart } from '../../decorators/multipart.decorator.mjs'
|
|
9
|
+
import { createMethodContext } from '../context-compat.mjs'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type helper to constrain a PropertyDescriptor's value to match a multipart endpoint signature.
|
|
13
|
+
* Note: In legacy decorators, type constraints are checked when the decorator is applied,
|
|
14
|
+
* but may not be preserved perfectly when decorators are stacked.
|
|
15
|
+
*/
|
|
16
|
+
type MultipartMethodDescriptor<
|
|
17
|
+
Url extends string,
|
|
18
|
+
QuerySchema,
|
|
19
|
+
RequestSchema,
|
|
20
|
+
ResponseSchema extends ZodType,
|
|
21
|
+
> = TypedPropertyDescriptor<
|
|
22
|
+
(
|
|
23
|
+
params: QuerySchema extends ZodObject
|
|
24
|
+
? RequestSchema extends ZodType
|
|
25
|
+
? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
|
|
26
|
+
: EndpointFunctionArgs<Url, QuerySchema, undefined>
|
|
27
|
+
: RequestSchema extends ZodType
|
|
28
|
+
? EndpointFunctionArgs<Url, undefined, RequestSchema>
|
|
29
|
+
: EndpointFunctionArgs<Url, undefined, undefined>,
|
|
30
|
+
) => Promise<z.input<ResponseSchema>>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Legacy-compatible Multipart decorator.
|
|
35
|
+
*
|
|
36
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
37
|
+
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
38
|
+
*
|
|
39
|
+
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
40
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* @Controller()
|
|
45
|
+
* export class FileController {
|
|
46
|
+
* @Multipart(uploadFileEndpoint)
|
|
47
|
+
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): MultipartResult<typeof uploadFileEndpoint> {
|
|
48
|
+
* const { file } = request.data
|
|
49
|
+
* return { url: 'https://example.com/file.jpg' }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function Multipart<
|
|
55
|
+
Method extends HttpMethod = HttpMethod,
|
|
56
|
+
Url extends string = string,
|
|
57
|
+
QuerySchema = undefined,
|
|
58
|
+
ResponseSchema extends ZodType = ZodType,
|
|
59
|
+
RequestSchema = ZodType,
|
|
60
|
+
>(endpoint: {
|
|
61
|
+
config: BaseEndpointConfig<
|
|
62
|
+
Method,
|
|
63
|
+
Url,
|
|
64
|
+
QuerySchema,
|
|
65
|
+
ResponseSchema,
|
|
66
|
+
RequestSchema
|
|
67
|
+
>
|
|
68
|
+
}) {
|
|
69
|
+
return function <T extends object>(
|
|
70
|
+
target: T,
|
|
71
|
+
propertyKey: string | symbol,
|
|
72
|
+
descriptor: MultipartMethodDescriptor<
|
|
73
|
+
Url,
|
|
74
|
+
QuerySchema,
|
|
75
|
+
RequestSchema,
|
|
76
|
+
ResponseSchema
|
|
77
|
+
>,
|
|
78
|
+
): PropertyDescriptor | void {
|
|
79
|
+
if (!descriptor) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'[Navios] @Multipart decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
const context = createMethodContext(target, propertyKey, descriptor)
|
|
85
|
+
const originalDecorator = OriginalMultipart(endpoint)
|
|
86
|
+
// @ts-expect-error - we don't need to type the value
|
|
87
|
+
const result = originalDecorator(descriptor.value, context)
|
|
88
|
+
if (result !== descriptor.value) {
|
|
89
|
+
descriptor.value = result
|
|
90
|
+
}
|
|
91
|
+
return descriptor
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseStreamConfig, EndpointFunctionArgs, HttpMethod } from '@navios/builder';
|
|
2
|
+
import type { ZodObject, ZodType } from 'zod/v4';
|
|
3
|
+
/**
|
|
4
|
+
* Type helper to constrain a PropertyDescriptor's value to match a stream endpoint signature.
|
|
5
|
+
* Note: In legacy decorators, type constraints are checked when the decorator is applied,
|
|
6
|
+
* but may not be preserved perfectly when decorators are stacked.
|
|
7
|
+
*/
|
|
8
|
+
type StreamMethodDescriptor<Url extends string, QuerySchema, RequestSchema> = TypedPropertyDescriptor<(params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>, reply: any) => Promise<void>>;
|
|
9
|
+
/**
|
|
10
|
+
* Legacy-compatible Stream decorator.
|
|
11
|
+
*
|
|
12
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
13
|
+
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
14
|
+
*
|
|
15
|
+
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
16
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Controller()
|
|
21
|
+
* export class FileController {
|
|
22
|
+
* @Stream(downloadFileEndpoint)
|
|
23
|
+
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
24
|
+
* const { fileId } = request.urlParams
|
|
25
|
+
* // Stream file data to reply
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function Stream<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, RequestSchema = ZodType>(endpoint: {
|
|
31
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
32
|
+
}): <T extends object>(target: T, propertyKey: string | symbol, descriptor: StreamMethodDescriptor<Url, QuerySchema, RequestSchema>) => StreamMethodDescriptor<Url, QuerySchema, RequestSchema>;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=stream.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.decorator.d.mts","sourceRoot":"","sources":["stream.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,EACX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAKhD;;;;GAIG;AACH,KAAK,sBAAsB,CACzB,GAAG,SAAS,MAAM,EAClB,WAAW,EACX,aAAa,IACX,uBAAuB,CACzB,CACE,MAAM,EAAE,WAAW,SAAS,SAAS,GACjC,aAAa,SAAS,OAAO,GAC3B,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,GACrD,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,CAAC,GACnD,aAAa,SAAS,OAAO,GAC3B,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,CAAC,GACnD,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,EACrD,KAAK,EAAE,GAAG,KACP,OAAO,CAAC,IAAI,CAAC,CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CACpB,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,WAAW,GAAG,SAAS,EACvB,aAAa,GAAG,OAAO,EACvB,QAAQ,EAAE;IACV,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,CAAA;CAClE,IACkB,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EACT,aAAa,MAAM,GAAG,MAAM,EAC5B,YAAY,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,6DAWtE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseStreamConfig,
|
|
3
|
+
EndpointFunctionArgs,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
} from '@navios/builder'
|
|
6
|
+
import type { ZodObject, ZodType } from 'zod/v4'
|
|
7
|
+
|
|
8
|
+
import { Stream as OriginalStream } from '../../decorators/stream.decorator.mjs'
|
|
9
|
+
import { createMethodContext } from '../context-compat.mjs'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type helper to constrain a PropertyDescriptor's value to match a stream endpoint signature.
|
|
13
|
+
* Note: In legacy decorators, type constraints are checked when the decorator is applied,
|
|
14
|
+
* but may not be preserved perfectly when decorators are stacked.
|
|
15
|
+
*/
|
|
16
|
+
type StreamMethodDescriptor<
|
|
17
|
+
Url extends string,
|
|
18
|
+
QuerySchema,
|
|
19
|
+
RequestSchema,
|
|
20
|
+
> = TypedPropertyDescriptor<
|
|
21
|
+
(
|
|
22
|
+
params: QuerySchema extends ZodObject
|
|
23
|
+
? RequestSchema extends ZodType
|
|
24
|
+
? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
|
|
25
|
+
: EndpointFunctionArgs<Url, QuerySchema, undefined>
|
|
26
|
+
: RequestSchema extends ZodType
|
|
27
|
+
? EndpointFunctionArgs<Url, undefined, RequestSchema>
|
|
28
|
+
: EndpointFunctionArgs<Url, undefined, undefined>,
|
|
29
|
+
reply: any,
|
|
30
|
+
) => Promise<void>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Legacy-compatible Stream decorator.
|
|
35
|
+
*
|
|
36
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
37
|
+
* Provides type safety by ensuring method signatures match the endpoint configuration.
|
|
38
|
+
*
|
|
39
|
+
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
40
|
+
* @returns A method decorator compatible with legacy decorator API
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* @Controller()
|
|
45
|
+
* export class FileController {
|
|
46
|
+
* @Stream(downloadFileEndpoint)
|
|
47
|
+
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
48
|
+
* const { fileId } = request.urlParams
|
|
49
|
+
* // Stream file data to reply
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function Stream<
|
|
55
|
+
Method extends HttpMethod = HttpMethod,
|
|
56
|
+
Url extends string = string,
|
|
57
|
+
QuerySchema = undefined,
|
|
58
|
+
RequestSchema = ZodType,
|
|
59
|
+
>(endpoint: {
|
|
60
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>
|
|
61
|
+
}) {
|
|
62
|
+
return function <T extends object>(
|
|
63
|
+
target: T,
|
|
64
|
+
propertyKey: string | symbol,
|
|
65
|
+
descriptor: StreamMethodDescriptor<Url, QuerySchema, RequestSchema>,
|
|
66
|
+
) {
|
|
67
|
+
const context = createMethodContext(target, propertyKey, descriptor)
|
|
68
|
+
const originalDecorator = OriginalStream(endpoint)
|
|
69
|
+
// @ts-expect-error - we don't need to type the value
|
|
70
|
+
const result = originalDecorator(descriptor.value, context)
|
|
71
|
+
if (result !== descriptor.value) {
|
|
72
|
+
descriptor.value = result
|
|
73
|
+
}
|
|
74
|
+
return descriptor
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ClassTypeWithInstance, InjectionToken } from '@navios/di';
|
|
2
|
+
import type { CanActivate } from '../../interfaces/index.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Legacy-compatible UseGuards decorator.
|
|
5
|
+
*
|
|
6
|
+
* Works with TypeScript experimental decorators (legacy API).
|
|
7
|
+
* Can be applied to classes or methods.
|
|
8
|
+
*
|
|
9
|
+
* @param guards - Guard classes or injection tokens to apply
|
|
10
|
+
* @returns A class or method decorator compatible with legacy decorator API
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Apply to a controller
|
|
15
|
+
* @Controller()
|
|
16
|
+
* @UseGuards(AuthGuard, RoleGuard)
|
|
17
|
+
* export class UserController { }
|
|
18
|
+
*
|
|
19
|
+
* // Apply to a specific endpoint
|
|
20
|
+
* @Controller()
|
|
21
|
+
* export class UserController {
|
|
22
|
+
* @Endpoint(getUserEndpoint)
|
|
23
|
+
* @UseGuards(AuthGuard)
|
|
24
|
+
* async getUser() { }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function UseGuards(...guards: (ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>)[]): any;
|
|
29
|
+
//# sourceMappingURL=use-guards.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-guards.decorator.d.mts","sourceRoot":"","sources":["use-guards.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qBAAqB,EACrB,cAAc,EACf,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAK7D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CACvB,GAAG,MAAM,EAAE,CACP,qBAAqB,CAAC,WAAW,CAAC,GAClC,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,CACzC,EAAE,GAsCqB,GAAG,CAC5B"}
|