@navios/core 1.1.0 → 2.0.0-alpha.1
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 +85 -13
- package/README.md +69 -220
- package/lib/async-context-BAdt7bno.d.mts +239 -0
- package/lib/async-context-BAdt7bno.d.mts.map +1 -0
- package/lib/async-context-RsWmy2Hi.d.cts +239 -0
- package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
- package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
- package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
- package/lib/attribute-value-BNiJjxl1.mjs +225 -0
- package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
- package/lib/attribute-value-Cux5HhOL.cjs +314 -0
- package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
- package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
- package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
- package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
- package/lib/execution-context-BVSmLkYp.d.cts +71 -0
- package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
- package/lib/execution-context-C5F9rojO.d.mts +71 -0
- package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
- package/lib/execution-context-token--cKS4cJv.cjs +270 -0
- package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
- package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
- package/lib/index.cjs +1672 -4426
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +842 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +842 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1559 -4221
- 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-Bz83ZnJ5.cjs +173 -0
- package/lib/module-Bz83ZnJ5.cjs.map +1 -0
- package/lib/module-options-CSqQUSTm.d.mts +51 -0
- package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
- package/lib/module-options-DSRBri4J.d.cts +51 -0
- package/lib/module-options-DSRBri4J.d.cts.map +1 -0
- package/lib/module-zPXwR2qp.mjs +138 -0
- package/lib/module-zPXwR2qp.mjs.map +1 -0
- package/lib/settled-within-B6gpu2XW.cjs +32 -0
- package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
- package/lib/settled-within-Bc2pj8WB.mjs +21 -0
- package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
- package/lib/testing/index.cjs +74 -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 +72 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +36 -0
- package/lib/transport.d.cts +254 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +254 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +6 -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-3LcTrbxz.d.mts +0 -3804
- package/lib/index-3LcTrbxz.d.mts.map +0 -1
- package/lib/index-B14SekVb.d.cts +0 -3804
- package/lib/index-B14SekVb.d.cts.map +0 -1
- package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
- package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
- package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
- package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
- package/lib/tokens-BEuBMGGX.cjs +0 -193
- package/lib/tokens-BEuBMGGX.cjs.map +0 -1
- package/lib/tokens-COyNGV1I.mjs +0 -97
- package/lib/tokens-COyNGV1I.mjs.map +0 -1
- package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
- package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
- package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
- package/lib/use-guards.decorator-DhumFTk3.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 -14
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin-context.mts +0 -104
- package/src/interfaces/plugin-stage.mts +0 -62
- package/src/interfaces/plugin.interface.mts +0 -119
- package/src/interfaces/staged-plugin.interface.mts +0 -209
- 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 -79
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -116
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -678
- 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 -255
- 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/define-plugin.mts +0 -251
- package/src/utils/index.mts +0 -2
- 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,81 +0,0 @@
|
|
|
1
|
-
import type { ClassType, InjectableScope } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Injectable, InjectionToken, Registry } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { getControllerMetadata } from '../metadata/index.mjs'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options for configuring a Navios controller.
|
|
9
|
-
*/
|
|
10
|
-
export interface ControllerOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Guards to apply to all endpoints in this controller.
|
|
13
|
-
* Guards are executed in reverse order (last guard first).
|
|
14
|
-
*/
|
|
15
|
-
guards?: ClassType[] | Set<ClassType>
|
|
16
|
-
/**
|
|
17
|
-
* Registry to use for the controller.
|
|
18
|
-
* Registry is used to store the controller and its endpoints.
|
|
19
|
-
*/
|
|
20
|
-
registry?: Registry
|
|
21
|
-
/**
|
|
22
|
-
* Priority to use for the controller.
|
|
23
|
-
* Priority is used to sort the controller in the registry.
|
|
24
|
-
*/
|
|
25
|
-
priority?: number
|
|
26
|
-
/**
|
|
27
|
-
* Scope to use for the controller.
|
|
28
|
-
* Scope is used to determine the scope of the controller.
|
|
29
|
-
*/
|
|
30
|
-
scope?: InjectableScope
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Decorator that marks a class as a Navios controller.
|
|
35
|
-
*
|
|
36
|
-
* Controllers handle HTTP requests and define endpoints.
|
|
37
|
-
* They are request-scoped by default, meaning a new instance is created for each request.
|
|
38
|
-
*
|
|
39
|
-
* @param options - Controller configuration options
|
|
40
|
-
* @returns A class decorator
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* @Controller({ guards: [AuthGuard] })
|
|
45
|
-
* export class UserController {
|
|
46
|
-
* @Endpoint(getUserEndpoint)
|
|
47
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
48
|
-
* // Handle request
|
|
49
|
-
* }
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function Controller({
|
|
54
|
-
guards,
|
|
55
|
-
registry,
|
|
56
|
-
priority,
|
|
57
|
-
scope,
|
|
58
|
-
}: ControllerOptions = {}) {
|
|
59
|
-
return function (target: ClassType, context: ClassDecoratorContext) {
|
|
60
|
-
if (context.kind !== 'class') {
|
|
61
|
-
throw new Error(
|
|
62
|
-
'[Navios] @Controller decorator can only be used on classes.',
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
const token = InjectionToken.create(target)
|
|
66
|
-
if (context.metadata) {
|
|
67
|
-
const controllerMetadata = getControllerMetadata(target, context)
|
|
68
|
-
if (guards) {
|
|
69
|
-
for (const guard of Array.from(guards).reverse()) {
|
|
70
|
-
controllerMetadata.guards.add(guard)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return Injectable({
|
|
75
|
-
token,
|
|
76
|
-
registry,
|
|
77
|
-
priority,
|
|
78
|
-
scope,
|
|
79
|
-
})(target, context)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EndpointHandler,
|
|
3
|
-
EndpointOptions,
|
|
4
|
-
RequestArgs,
|
|
5
|
-
} from '@navios/builder'
|
|
6
|
-
import type { z } from 'zod/v4'
|
|
7
|
-
|
|
8
|
-
import { ZodDiscriminatedUnion } from 'zod/v4'
|
|
9
|
-
|
|
10
|
-
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
11
|
-
import { EndpointAdapterToken } from '../tokens/index.mjs'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Extracts the typed parameters for an endpoint handler function.
|
|
15
|
-
*
|
|
16
|
-
* This utility type extracts URL parameters, query parameters, and request body
|
|
17
|
-
* from an endpoint declaration and flattens them into a single object.
|
|
18
|
-
*
|
|
19
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
24
|
-
* method: 'get',
|
|
25
|
-
* url: '/users/$userId',
|
|
26
|
-
* querySchema: z.object({ include: z.string().optional() }),
|
|
27
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* @Endpoint(getUserEndpoint)
|
|
31
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
32
|
-
* // request.urlParams.userId is typed as string
|
|
33
|
-
* // request.query.include is typed as string | undefined
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export type EndpointParams<
|
|
38
|
-
EndpointDeclaration extends EndpointHandler<Config, false>,
|
|
39
|
-
Config extends EndpointOptions = EndpointDeclaration['config'],
|
|
40
|
-
> = RequestArgs<
|
|
41
|
-
Config['url'],
|
|
42
|
-
Config['querySchema'],
|
|
43
|
-
Config['requestSchema'],
|
|
44
|
-
Config['urlParamsSchema'],
|
|
45
|
-
true
|
|
46
|
-
>
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extracts the typed return value for an endpoint handler function.
|
|
50
|
-
*
|
|
51
|
-
* This utility type extracts the response schema from an endpoint declaration
|
|
52
|
-
* and returns the appropriate Promise type.
|
|
53
|
-
*
|
|
54
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
59
|
-
* method: 'get',
|
|
60
|
-
* url: '/users/$userId',
|
|
61
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
62
|
-
* })
|
|
63
|
-
*
|
|
64
|
-
* @Endpoint(getUserEndpoint)
|
|
65
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
|
|
66
|
-
* return { id: '1', name: 'John' } // Type-checked against responseSchema
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export type EndpointResult<
|
|
71
|
-
EndpointDeclaration extends {
|
|
72
|
-
config: EndpointOptions
|
|
73
|
-
},
|
|
74
|
-
> =
|
|
75
|
-
EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
|
|
76
|
-
infer Options
|
|
77
|
-
>
|
|
78
|
-
? Promise<z.input<Options[number]>>
|
|
79
|
-
: Promise<z.input<EndpointDeclaration['config']['responseSchema']>>
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Decorator that marks a method as an HTTP endpoint.
|
|
83
|
-
*
|
|
84
|
-
* The endpoint must be defined using @navios/builder's `declareEndpoint` method.
|
|
85
|
-
* This ensures type safety and consistency between client and server.
|
|
86
|
-
*
|
|
87
|
-
* @param endpoint - The endpoint declaration from @navios/builder
|
|
88
|
-
* @returns A method decorator
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* import { builder } from '@navios/builder'
|
|
93
|
-
*
|
|
94
|
-
* const api = builder()
|
|
95
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
96
|
-
* method: 'get',
|
|
97
|
-
* url: '/users/$userId',
|
|
98
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
99
|
-
* })
|
|
100
|
-
*
|
|
101
|
-
* @Controller()
|
|
102
|
-
* export class UserController {
|
|
103
|
-
* @Endpoint(getUserEndpoint)
|
|
104
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
105
|
-
* const { userId } = request.urlParams
|
|
106
|
-
* return { id: userId, name: 'John' }
|
|
107
|
-
* }
|
|
108
|
-
* }
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export function Endpoint<const Config extends EndpointOptions>(
|
|
112
|
-
endpoint: EndpointHandler<Config, false>,
|
|
113
|
-
): (
|
|
114
|
-
target: (
|
|
115
|
-
params: RequestArgs<
|
|
116
|
-
Config['url'],
|
|
117
|
-
Config['querySchema'],
|
|
118
|
-
Config['requestSchema'],
|
|
119
|
-
Config['urlParamsSchema'],
|
|
120
|
-
true
|
|
121
|
-
>,
|
|
122
|
-
) =>
|
|
123
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
124
|
-
| z.input<Config['responseSchema']>,
|
|
125
|
-
context: ClassMethodDecoratorContext,
|
|
126
|
-
) => void
|
|
127
|
-
export function Endpoint<const Config extends EndpointOptions>(
|
|
128
|
-
endpoint: EndpointHandler<Config, false>,
|
|
129
|
-
): (
|
|
130
|
-
target: () =>
|
|
131
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
132
|
-
| z.input<Config['responseSchema']>,
|
|
133
|
-
context: ClassMethodDecoratorContext,
|
|
134
|
-
) => void
|
|
135
|
-
export function Endpoint<const Config extends EndpointOptions>(
|
|
136
|
-
endpoint: EndpointHandler<Config, false>,
|
|
137
|
-
) {
|
|
138
|
-
type Params = RequestArgs<
|
|
139
|
-
Config['url'],
|
|
140
|
-
Config['querySchema'],
|
|
141
|
-
Config['requestSchema'],
|
|
142
|
-
Config['urlParamsSchema'],
|
|
143
|
-
true
|
|
144
|
-
>
|
|
145
|
-
|
|
146
|
-
type Handler =
|
|
147
|
-
| ((
|
|
148
|
-
params: Params,
|
|
149
|
-
) =>
|
|
150
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
151
|
-
| z.input<Config['responseSchema']>)
|
|
152
|
-
| (() =>
|
|
153
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
154
|
-
| z.input<Config['responseSchema']>)
|
|
155
|
-
|
|
156
|
-
return (target: Handler, context: ClassMethodDecoratorContext) => {
|
|
157
|
-
if (context.kind !== 'method') {
|
|
158
|
-
throw new Error(
|
|
159
|
-
'[Navios] Endpoint decorator can only be used on methods.',
|
|
160
|
-
)
|
|
161
|
-
}
|
|
162
|
-
const config = endpoint.config
|
|
163
|
-
if (context.metadata) {
|
|
164
|
-
let endpointMetadata = getEndpointMetadata<EndpointOptions>(
|
|
165
|
-
target,
|
|
166
|
-
context,
|
|
167
|
-
)
|
|
168
|
-
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
169
|
-
throw new Error(
|
|
170
|
-
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
|
|
171
|
-
)
|
|
172
|
-
}
|
|
173
|
-
endpointMetadata.config = config
|
|
174
|
-
endpointMetadata.adapterToken = EndpointAdapterToken
|
|
175
|
-
endpointMetadata.classMethod = target.name
|
|
176
|
-
endpointMetadata.httpMethod = config.method
|
|
177
|
-
endpointMetadata.url = config.url
|
|
178
|
-
}
|
|
179
|
-
return target
|
|
180
|
-
}
|
|
181
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { HttpHeader } from '../interfaces/index.mjs'
|
|
2
|
-
|
|
3
|
-
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Decorator that sets a custom HTTP response header for an endpoint.
|
|
7
|
-
*
|
|
8
|
-
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
9
|
-
* @param value - The header value (string, number, or array of strings)
|
|
10
|
-
* @returns A method decorator
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller()
|
|
15
|
-
* export class UserController {
|
|
16
|
-
* @Endpoint(getUserEndpoint)
|
|
17
|
-
* @Header('Cache-Control', 'max-age=3600')
|
|
18
|
-
* async getUser() {
|
|
19
|
-
* return { id: '1', name: 'John' }
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function Header(name: HttpHeader, value: string | number | string[]) {
|
|
25
|
-
return <T extends Function>(
|
|
26
|
-
target: T,
|
|
27
|
-
context: ClassMethodDecoratorContext,
|
|
28
|
-
) => {
|
|
29
|
-
if (context.kind !== 'method') {
|
|
30
|
-
throw new Error('[Navios] Header decorator can only be used on methods.')
|
|
31
|
-
}
|
|
32
|
-
const metadata = getEndpointMetadata(target, context)
|
|
33
|
-
|
|
34
|
-
metadata.headers[name] = value
|
|
35
|
-
|
|
36
|
-
return target
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Decorator that sets a custom HTTP status code for successful responses.
|
|
5
|
-
*
|
|
6
|
-
* By default, endpoints return 200 OK. Use this decorator to return a different status code.
|
|
7
|
-
*
|
|
8
|
-
* @param code - The HTTP status code to return (e.g., 201, 204, 202)
|
|
9
|
-
* @returns A method decorator
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @Controller()
|
|
14
|
-
* export class UserController {
|
|
15
|
-
* @Endpoint(createUserEndpoint)
|
|
16
|
-
* @HttpCode(201)
|
|
17
|
-
* async createUser() {
|
|
18
|
-
* return { id: '1', name: 'John' }
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function HttpCode(code: number) {
|
|
24
|
-
return <T extends Function>(
|
|
25
|
-
target: T,
|
|
26
|
-
context: ClassMethodDecoratorContext,
|
|
27
|
-
) => {
|
|
28
|
-
if (context.kind !== 'method') {
|
|
29
|
-
throw new Error(
|
|
30
|
-
'[Navios] HttpCode decorator can only be used on methods.',
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
const metadata = getEndpointMetadata(target, context)
|
|
34
|
-
metadata.successStatusCode = code
|
|
35
|
-
|
|
36
|
-
return target
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/decorators/index.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './controller.decorator.mjs'
|
|
2
|
-
export * from './endpoint.decorator.mjs'
|
|
3
|
-
export * from './header.decorator.mjs'
|
|
4
|
-
export * from './http-code.decorator.mjs'
|
|
5
|
-
export * from './module.decorator.mjs'
|
|
6
|
-
export * from './multipart.decorator.mjs'
|
|
7
|
-
export * from './stream.decorator.mjs'
|
|
8
|
-
export * from './use-guards.decorator.mjs'
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ClassType, Registry } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Injectable, InjectableScope, InjectionToken } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { getModuleMetadata } from '../metadata/index.mjs'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options for configuring a Navios module.
|
|
9
|
-
*/
|
|
10
|
-
export interface ModuleOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Controllers to register in this module.
|
|
13
|
-
* Controllers handle HTTP requests and define endpoints.
|
|
14
|
-
*/
|
|
15
|
-
controllers?: ClassType[] | Set<ClassType>
|
|
16
|
-
/**
|
|
17
|
-
* Other modules to import into this module.
|
|
18
|
-
* Imported modules' controllers and services become available.
|
|
19
|
-
*/
|
|
20
|
-
imports?: ClassType[] | Set<ClassType>
|
|
21
|
-
/**
|
|
22
|
-
* Guards to apply to all controllers in this module.
|
|
23
|
-
* Guards are executed in reverse order (last guard first).
|
|
24
|
-
*/
|
|
25
|
-
guards?: ClassType[] | Set<ClassType>
|
|
26
|
-
/**
|
|
27
|
-
* Service override classes to import for side effects.
|
|
28
|
-
* These classes are imported to ensure their @Injectable decorators execute,
|
|
29
|
-
* allowing them to register with the DI system. Overrides should use the same
|
|
30
|
-
* InjectionToken as the original service with a higher priority.
|
|
31
|
-
*/
|
|
32
|
-
overrides?: ClassType[] | Set<ClassType>
|
|
33
|
-
/**
|
|
34
|
-
* Priority to use for the module.
|
|
35
|
-
* Priority is used to sort the module in the registry.
|
|
36
|
-
*/
|
|
37
|
-
priority?: number
|
|
38
|
-
/**
|
|
39
|
-
* Registry to use for the module.
|
|
40
|
-
* Registry is used to store the module and its controllers.
|
|
41
|
-
*/
|
|
42
|
-
registry?: Registry
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Decorator that marks a class as a Navios module.
|
|
47
|
-
*
|
|
48
|
-
* Modules are the basic building blocks of a Navios application.
|
|
49
|
-
* They organize controllers, services, and other modules into logical units.
|
|
50
|
-
*
|
|
51
|
-
* @param options - Module configuration options
|
|
52
|
-
* @returns A class decorator
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* @Module({
|
|
57
|
-
* controllers: [UserController, AuthController],
|
|
58
|
-
* imports: [DatabaseModule],
|
|
59
|
-
* guards: [AuthGuard],
|
|
60
|
-
* })
|
|
61
|
-
* export class AppModule {}
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export function Module(
|
|
65
|
-
{
|
|
66
|
-
controllers = [],
|
|
67
|
-
imports = [],
|
|
68
|
-
guards = [],
|
|
69
|
-
overrides = [],
|
|
70
|
-
priority,
|
|
71
|
-
registry,
|
|
72
|
-
}: ModuleOptions = {
|
|
73
|
-
controllers: [],
|
|
74
|
-
imports: [],
|
|
75
|
-
guards: [],
|
|
76
|
-
overrides: [],
|
|
77
|
-
},
|
|
78
|
-
) {
|
|
79
|
-
return (target: ClassType, context: ClassDecoratorContext) => {
|
|
80
|
-
if (context.kind !== 'class') {
|
|
81
|
-
throw new Error('[Navios] @Module decorator can only be used on classes.')
|
|
82
|
-
}
|
|
83
|
-
// Register the module in the service locator
|
|
84
|
-
const token = InjectionToken.create(target)
|
|
85
|
-
const moduleMetadata = getModuleMetadata(target, context)
|
|
86
|
-
for (const controller of controllers) {
|
|
87
|
-
moduleMetadata.controllers.add(controller)
|
|
88
|
-
}
|
|
89
|
-
for (const importedModule of imports) {
|
|
90
|
-
moduleMetadata.imports.add(importedModule)
|
|
91
|
-
}
|
|
92
|
-
for (const guard of Array.from(guards).reverse()) {
|
|
93
|
-
moduleMetadata.guards.add(guard)
|
|
94
|
-
}
|
|
95
|
-
for (const override of overrides) {
|
|
96
|
-
moduleMetadata.overrides.add(override)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return Injectable({
|
|
100
|
-
token,
|
|
101
|
-
scope: InjectableScope.Singleton,
|
|
102
|
-
priority,
|
|
103
|
-
registry,
|
|
104
|
-
})(target, context)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import type { EndpointOptions, RequestArgs } from '@navios/builder'
|
|
2
|
-
import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
3
|
-
|
|
4
|
-
import { ZodDiscriminatedUnion } from 'zod/v4'
|
|
5
|
-
|
|
6
|
-
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
7
|
-
import { MultipartAdapterToken } from '../tokens/index.mjs'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Extracts the typed parameters for a multipart endpoint handler function.
|
|
11
|
-
*
|
|
12
|
-
* Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.
|
|
13
|
-
*
|
|
14
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
15
|
-
*/
|
|
16
|
-
export type MultipartParams<
|
|
17
|
-
EndpointDeclaration extends {
|
|
18
|
-
config: EndpointOptions
|
|
19
|
-
},
|
|
20
|
-
Url extends string = EndpointDeclaration['config']['url'],
|
|
21
|
-
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
22
|
-
> = QuerySchema extends ZodObject
|
|
23
|
-
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
24
|
-
? RequestArgs<
|
|
25
|
-
Url,
|
|
26
|
-
QuerySchema,
|
|
27
|
-
EndpointDeclaration['config']['requestSchema'],
|
|
28
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
29
|
-
true
|
|
30
|
-
>
|
|
31
|
-
: RequestArgs<
|
|
32
|
-
Url,
|
|
33
|
-
QuerySchema,
|
|
34
|
-
undefined,
|
|
35
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
36
|
-
true
|
|
37
|
-
>
|
|
38
|
-
: EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
39
|
-
? RequestArgs<
|
|
40
|
-
Url,
|
|
41
|
-
undefined,
|
|
42
|
-
EndpointDeclaration['config']['requestSchema'],
|
|
43
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
44
|
-
true
|
|
45
|
-
>
|
|
46
|
-
: RequestArgs<
|
|
47
|
-
Url,
|
|
48
|
-
undefined,
|
|
49
|
-
undefined,
|
|
50
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
51
|
-
true
|
|
52
|
-
>
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Extracts the typed return value for a multipart endpoint handler function.
|
|
56
|
-
*
|
|
57
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
58
|
-
*/
|
|
59
|
-
export type MultipartResult<
|
|
60
|
-
EndpointDeclaration extends {
|
|
61
|
-
config: EndpointOptions
|
|
62
|
-
},
|
|
63
|
-
> =
|
|
64
|
-
EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
|
|
65
|
-
infer Options
|
|
66
|
-
>
|
|
67
|
-
? Promise<z.input<Options[number]>>
|
|
68
|
-
: Promise<z.input<EndpointDeclaration['config']['responseSchema']>>
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
72
|
-
*
|
|
73
|
-
* Use this decorator for endpoints that handle file uploads or form data.
|
|
74
|
-
* The endpoint must be defined using @navios/builder's `declareMultipart` method.
|
|
75
|
-
*
|
|
76
|
-
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
77
|
-
* @returns A method decorator
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* const uploadFileEndpoint = api.declareMultipart({
|
|
82
|
-
* method: 'post',
|
|
83
|
-
* url: '/upload',
|
|
84
|
-
* requestSchema: z.object({ file: z.instanceof(File) }),
|
|
85
|
-
* responseSchema: z.object({ url: z.string() }),
|
|
86
|
-
* })
|
|
87
|
-
*
|
|
88
|
-
* @Controller()
|
|
89
|
-
* export class FileController {
|
|
90
|
-
* @Multipart(uploadFileEndpoint)
|
|
91
|
-
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
|
|
92
|
-
* const { file } = request.data
|
|
93
|
-
* // Handle file upload
|
|
94
|
-
* return { url: 'https://example.com/file.jpg' }
|
|
95
|
-
* }
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
100
|
-
config: Config
|
|
101
|
-
}): (
|
|
102
|
-
target: (
|
|
103
|
-
params: RequestArgs<
|
|
104
|
-
Config['url'],
|
|
105
|
-
Config['querySchema'],
|
|
106
|
-
Config['requestSchema'],
|
|
107
|
-
Config['urlParamsSchema'],
|
|
108
|
-
true
|
|
109
|
-
>,
|
|
110
|
-
) =>
|
|
111
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
112
|
-
| z.input<Config['responseSchema']>,
|
|
113
|
-
context: ClassMethodDecoratorContext,
|
|
114
|
-
) => void
|
|
115
|
-
export function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
116
|
-
config: Config
|
|
117
|
-
}): (
|
|
118
|
-
target: () =>
|
|
119
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
120
|
-
| z.input<Config['responseSchema']>,
|
|
121
|
-
context: ClassMethodDecoratorContext,
|
|
122
|
-
) => void
|
|
123
|
-
export function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
124
|
-
config: Config
|
|
125
|
-
}) {
|
|
126
|
-
type Params = RequestArgs<
|
|
127
|
-
Config['url'],
|
|
128
|
-
Config['querySchema'],
|
|
129
|
-
Config['requestSchema'],
|
|
130
|
-
Config['urlParamsSchema'],
|
|
131
|
-
true
|
|
132
|
-
>
|
|
133
|
-
|
|
134
|
-
type Handler =
|
|
135
|
-
| ((
|
|
136
|
-
params: Params,
|
|
137
|
-
) =>
|
|
138
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
139
|
-
| z.input<Config['responseSchema']>)
|
|
140
|
-
| (() =>
|
|
141
|
-
| Promise<z.input<Config['responseSchema']>>
|
|
142
|
-
| z.input<Config['responseSchema']>)
|
|
143
|
-
|
|
144
|
-
return (target: Handler, context: ClassMethodDecoratorContext) => {
|
|
145
|
-
if (context.kind !== 'method') {
|
|
146
|
-
throw new Error(
|
|
147
|
-
'[Navios] Endpoint decorator can only be used on methods.',
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
const config = endpoint.config
|
|
151
|
-
if (context.metadata) {
|
|
152
|
-
let endpointMetadata = getEndpointMetadata<EndpointOptions>(
|
|
153
|
-
target,
|
|
154
|
-
context,
|
|
155
|
-
)
|
|
156
|
-
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
endpointMetadata.config = config
|
|
162
|
-
endpointMetadata.adapterToken = MultipartAdapterToken
|
|
163
|
-
endpointMetadata.classMethod = target.name
|
|
164
|
-
endpointMetadata.httpMethod = config.method
|
|
165
|
-
endpointMetadata.url = config.url
|
|
166
|
-
}
|
|
167
|
-
return target
|
|
168
|
-
}
|
|
169
|
-
}
|