@navios/core 1.1.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 +53 -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 -4424
- 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-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,155 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BaseEndpointOptions,
|
|
3
|
-
RequestArgs,
|
|
4
|
-
StreamHandler,
|
|
5
|
-
} from '@navios/builder'
|
|
6
|
-
import type { ZodObject, ZodType } from 'zod/v4'
|
|
7
|
-
|
|
8
|
-
import { getEndpointMetadata } from '../metadata/index.mjs'
|
|
9
|
-
import { StreamAdapterToken } from '../tokens/index.mjs'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the typed parameters for a stream endpoint handler function.
|
|
13
|
-
*
|
|
14
|
-
* Similar to `EndpointParams`, but specifically for streaming endpoints.
|
|
15
|
-
*
|
|
16
|
-
* @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder
|
|
17
|
-
*/
|
|
18
|
-
export type StreamParams<
|
|
19
|
-
EndpointDeclaration extends StreamHandler<Config, false>,
|
|
20
|
-
Config extends BaseEndpointOptions = EndpointDeclaration['config'],
|
|
21
|
-
Url extends string = EndpointDeclaration['config']['url'],
|
|
22
|
-
QuerySchema = EndpointDeclaration['config']['querySchema'],
|
|
23
|
-
> = QuerySchema extends ZodObject
|
|
24
|
-
? EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
25
|
-
? RequestArgs<
|
|
26
|
-
Url,
|
|
27
|
-
QuerySchema,
|
|
28
|
-
EndpointDeclaration['config']['requestSchema'],
|
|
29
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
30
|
-
true
|
|
31
|
-
>
|
|
32
|
-
: RequestArgs<
|
|
33
|
-
Url,
|
|
34
|
-
QuerySchema,
|
|
35
|
-
undefined,
|
|
36
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
37
|
-
true
|
|
38
|
-
>
|
|
39
|
-
: EndpointDeclaration['config']['requestSchema'] extends ZodType
|
|
40
|
-
? RequestArgs<
|
|
41
|
-
Url,
|
|
42
|
-
undefined,
|
|
43
|
-
EndpointDeclaration['config']['requestSchema'],
|
|
44
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
45
|
-
true
|
|
46
|
-
>
|
|
47
|
-
: RequestArgs<
|
|
48
|
-
Url,
|
|
49
|
-
undefined,
|
|
50
|
-
undefined,
|
|
51
|
-
EndpointDeclaration['config']['urlParamsSchema'],
|
|
52
|
-
true
|
|
53
|
-
>
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Decorator that marks a method as a streaming endpoint.
|
|
57
|
-
*
|
|
58
|
-
* Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
|
|
59
|
-
* The endpoint must be defined using @navios/builder's `declareStream` method.
|
|
60
|
-
*
|
|
61
|
-
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
62
|
-
* @returns A method decorator
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const downloadFileEndpoint = api.declareStream({
|
|
67
|
-
* method: 'get',
|
|
68
|
-
* url: '/files/$fileId',
|
|
69
|
-
* })
|
|
70
|
-
*
|
|
71
|
-
* @Controller()
|
|
72
|
-
* export class FileController {
|
|
73
|
-
* @Stream(downloadFileEndpoint)
|
|
74
|
-
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
75
|
-
* const { fileId } = request.urlParams
|
|
76
|
-
* // Stream file data to reply
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
82
|
-
config: Config
|
|
83
|
-
}): (
|
|
84
|
-
target: (
|
|
85
|
-
params: RequestArgs<
|
|
86
|
-
Config['url'],
|
|
87
|
-
Config['querySchema'],
|
|
88
|
-
Config['requestSchema'],
|
|
89
|
-
Config['urlParamsSchema'],
|
|
90
|
-
true
|
|
91
|
-
>,
|
|
92
|
-
reply: any,
|
|
93
|
-
) => any,
|
|
94
|
-
context: ClassMethodDecoratorContext,
|
|
95
|
-
) => void
|
|
96
|
-
// Bun doesn't support reply parameter
|
|
97
|
-
export function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
98
|
-
config: Config
|
|
99
|
-
}): (
|
|
100
|
-
target: (
|
|
101
|
-
params: RequestArgs<
|
|
102
|
-
Config['url'],
|
|
103
|
-
Config['querySchema'],
|
|
104
|
-
Config['requestSchema'],
|
|
105
|
-
Config['urlParamsSchema'],
|
|
106
|
-
true
|
|
107
|
-
>,
|
|
108
|
-
) => any,
|
|
109
|
-
context: ClassMethodDecoratorContext,
|
|
110
|
-
) => void
|
|
111
|
-
export function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
112
|
-
config: Config
|
|
113
|
-
}): (target: () => any, context: ClassMethodDecoratorContext) => void
|
|
114
|
-
export function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
115
|
-
config: Config
|
|
116
|
-
}) {
|
|
117
|
-
type Params = RequestArgs<
|
|
118
|
-
Config['url'],
|
|
119
|
-
Config['querySchema'],
|
|
120
|
-
Config['requestSchema'],
|
|
121
|
-
Config['urlParamsSchema'],
|
|
122
|
-
true
|
|
123
|
-
>
|
|
124
|
-
|
|
125
|
-
type Handler =
|
|
126
|
-
| ((params: Params, reply: any) => any)
|
|
127
|
-
| ((params: Params) => any)
|
|
128
|
-
| (() => any)
|
|
129
|
-
|
|
130
|
-
return (target: Handler, context: ClassMethodDecoratorContext) => {
|
|
131
|
-
if (context.kind !== 'method') {
|
|
132
|
-
throw new Error(
|
|
133
|
-
'[Navios] Endpoint decorator can only be used on methods.',
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
const config = endpoint.config
|
|
137
|
-
if (context.metadata) {
|
|
138
|
-
let endpointMetadata = getEndpointMetadata<BaseEndpointOptions>(
|
|
139
|
-
target,
|
|
140
|
-
context,
|
|
141
|
-
)
|
|
142
|
-
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
endpointMetadata.config = config
|
|
148
|
-
endpointMetadata.adapterToken = StreamAdapterToken
|
|
149
|
-
endpointMetadata.classMethod = target.name
|
|
150
|
-
endpointMetadata.httpMethod = config.method
|
|
151
|
-
endpointMetadata.url = config.url
|
|
152
|
-
}
|
|
153
|
-
return target
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ClassType,
|
|
3
|
-
ClassTypeWithInstance,
|
|
4
|
-
InjectionToken,
|
|
5
|
-
} from '@navios/di'
|
|
6
|
-
|
|
7
|
-
import type { CanActivate } from '../interfaces/index.mjs'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
getControllerMetadata,
|
|
11
|
-
getEndpointMetadata,
|
|
12
|
-
} from '../metadata/index.mjs'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Decorator that applies guards to a controller or endpoint.
|
|
16
|
-
*
|
|
17
|
-
* Guards are used for authentication, authorization, and request validation.
|
|
18
|
-
* They implement the `CanActivate` interface and are executed before the endpoint handler.
|
|
19
|
-
* Guards can be applied at the module, controller, or endpoint level.
|
|
20
|
-
*
|
|
21
|
-
* @param guards - Guard classes or injection tokens to apply
|
|
22
|
-
* @returns A class or method decorator
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // Apply to a controller
|
|
27
|
-
* @Controller()
|
|
28
|
-
* @UseGuards(AuthGuard, RoleGuard)
|
|
29
|
-
* export class UserController {
|
|
30
|
-
* @Endpoint(getUserEndpoint)
|
|
31
|
-
* async getUser() { }
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* // Apply to a specific endpoint
|
|
35
|
-
* @Controller()
|
|
36
|
-
* export class UserController {
|
|
37
|
-
* @Endpoint(getUserEndpoint)
|
|
38
|
-
* @UseGuards(AuthGuard)
|
|
39
|
-
* async getUser() { }
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function UseGuards(
|
|
44
|
-
...guards: (
|
|
45
|
-
| ClassTypeWithInstance<CanActivate>
|
|
46
|
-
| InjectionToken<CanActivate, undefined>
|
|
47
|
-
)[]
|
|
48
|
-
) {
|
|
49
|
-
return function <T extends Function>(
|
|
50
|
-
target: T,
|
|
51
|
-
context: ClassMethodDecoratorContext | ClassDecoratorContext,
|
|
52
|
-
): T {
|
|
53
|
-
if (context.kind === 'class') {
|
|
54
|
-
const controllerMetadata = getControllerMetadata(
|
|
55
|
-
target as unknown as ClassType,
|
|
56
|
-
context,
|
|
57
|
-
)
|
|
58
|
-
for (const guard of guards.reverse()) {
|
|
59
|
-
controllerMetadata.guards.add(guard)
|
|
60
|
-
}
|
|
61
|
-
} else if (context.kind === 'method') {
|
|
62
|
-
const endpointMetadata = getEndpointMetadata(target, context)
|
|
63
|
-
for (const guard of guards.reverse()) {
|
|
64
|
-
endpointMetadata.guards.add(guard)
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error(
|
|
68
|
-
'[Navios] @UseGuards decorator can only be used on classes or methods.',
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
return target
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 400 Bad Request HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when the client's request is malformed or invalid.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Endpoint(createUserEndpoint)
|
|
11
|
-
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
12
|
-
* if (!request.data.email) {
|
|
13
|
-
* throw new BadRequestException('Email is required')
|
|
14
|
-
* }
|
|
15
|
-
* // ...
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export class BadRequestException extends HttpException {
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new BadRequestException.
|
|
22
|
-
*
|
|
23
|
-
* @param message - Error message or response object
|
|
24
|
-
*/
|
|
25
|
-
constructor(message: string | object) {
|
|
26
|
-
super(400, message)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 409 Conflict HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when the request conflicts with the current state of the resource
|
|
7
|
-
* (e.g., trying to create a resource that already exists).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Endpoint(createUserEndpoint)
|
|
12
|
-
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
13
|
-
* const existing = await this.userService.findByEmail(request.data.email)
|
|
14
|
-
* if (existing) {
|
|
15
|
-
* throw new ConflictException('User with this email already exists')
|
|
16
|
-
* }
|
|
17
|
-
* // ...
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export class ConflictException extends HttpException {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new ConflictException.
|
|
24
|
-
*
|
|
25
|
-
* @param message - Error message or response object
|
|
26
|
-
* @param error - Optional underlying error for logging
|
|
27
|
-
*/
|
|
28
|
-
constructor(message: string | object, error?: Error) {
|
|
29
|
-
super(409, message, error)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 403 Forbidden HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when the client is authenticated but does not have
|
|
7
|
-
* permission to access the requested resource.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Endpoint(deleteUserEndpoint)
|
|
12
|
-
* @UseGuards(AuthGuard, RoleGuard)
|
|
13
|
-
* async deleteUser(request: EndpointParams<typeof deleteUserEndpoint>) {
|
|
14
|
-
* if (!this.userService.hasPermission(request.user, 'delete')) {
|
|
15
|
-
* throw new ForbiddenException('Insufficient permissions')
|
|
16
|
-
* }
|
|
17
|
-
* // ...
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export class ForbiddenException extends HttpException {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new ForbiddenException.
|
|
24
|
-
*
|
|
25
|
-
* @param message - Error message
|
|
26
|
-
*/
|
|
27
|
-
constructor(message: string) {
|
|
28
|
-
super(403, message)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base exception class for all HTTP exceptions in Navios.
|
|
3
|
-
*
|
|
4
|
-
* All HTTP exception classes extend this base class. When thrown from an endpoint handler,
|
|
5
|
-
* Navios will automatically convert it to an appropriate HTTP response with the specified
|
|
6
|
-
* status code and response body.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Endpoint(getUserEndpoint)
|
|
11
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
12
|
-
* const user = await this.userService.findById(request.urlParams.userId)
|
|
13
|
-
* if (!user) {
|
|
14
|
-
* throw new HttpException(404, 'User not found')
|
|
15
|
-
* }
|
|
16
|
-
* return user
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class HttpException {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new HttpException instance.
|
|
23
|
-
*
|
|
24
|
-
* @param statusCode - HTTP status code (e.g., 400, 404, 500)
|
|
25
|
-
* @param response - Response body (string or object)
|
|
26
|
-
* @param error - Optional underlying error for logging/debugging
|
|
27
|
-
*/
|
|
28
|
-
constructor(
|
|
29
|
-
public readonly statusCode: number,
|
|
30
|
-
public readonly response: string | object,
|
|
31
|
-
public readonly error?: Error,
|
|
32
|
-
) {}
|
|
33
|
-
}
|
package/src/exceptions/index.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './http.exception.mjs'
|
|
2
|
-
export * from './bad-request.exception.mjs'
|
|
3
|
-
export * from './forbidden.exception.mjs'
|
|
4
|
-
export * from './internal-server-error.exception.mjs'
|
|
5
|
-
export * from './not-found.exception.mjs'
|
|
6
|
-
export * from './unauthorized.exception.mjs'
|
|
7
|
-
export * from './conflict.exception.mjs'
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 500 Internal Server Error HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when an unexpected error occurs on the server.
|
|
7
|
-
* Generally, you should let unhandled errors bubble up rather than catching
|
|
8
|
-
* and rethrowing as InternalServerErrorException, as Navios will handle them appropriately.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* @Endpoint(processPaymentEndpoint)
|
|
13
|
-
* async processPayment(request: EndpointParams<typeof processPaymentEndpoint>) {
|
|
14
|
-
* try {
|
|
15
|
-
* return await this.paymentService.process(request.data)
|
|
16
|
-
* } catch (error) {
|
|
17
|
-
* this.logger.error('Payment processing failed', error)
|
|
18
|
-
* throw new InternalServerErrorException('Payment processing failed', error)
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export class InternalServerErrorException extends HttpException {
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new InternalServerErrorException.
|
|
26
|
-
*
|
|
27
|
-
* @param message - Error message or response object
|
|
28
|
-
* @param error - Optional underlying error for logging
|
|
29
|
-
*/
|
|
30
|
-
constructor(message: string | object, error?: Error) {
|
|
31
|
-
super(500, message, error)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 404 Not Found HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when the requested resource does not exist.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Endpoint(getUserEndpoint)
|
|
11
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
12
|
-
* const user = await this.userService.findById(request.urlParams.userId)
|
|
13
|
-
* if (!user) {
|
|
14
|
-
* throw new NotFoundException('User not found')
|
|
15
|
-
* }
|
|
16
|
-
* return user
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class NotFoundException extends HttpException {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new NotFoundException.
|
|
23
|
-
*
|
|
24
|
-
* @param response - Error message or response object
|
|
25
|
-
* @param error - Optional underlying error for logging
|
|
26
|
-
*/
|
|
27
|
-
constructor(
|
|
28
|
-
public readonly response: string | object,
|
|
29
|
-
public readonly error?: Error,
|
|
30
|
-
) {
|
|
31
|
-
super(404, response, error)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { HttpException } from './http.exception.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exception that represents a 401 Unauthorized HTTP error.
|
|
5
|
-
*
|
|
6
|
-
* Use this exception when the client is not authenticated or authentication failed.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Endpoint(getUserEndpoint)
|
|
11
|
-
* @UseGuards(AuthGuard)
|
|
12
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
13
|
-
* if (!request.headers.authorization) {
|
|
14
|
-
* throw new UnauthorizedException('Authentication required')
|
|
15
|
-
* }
|
|
16
|
-
* // ...
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class UnauthorizedException extends HttpException {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new UnauthorizedException.
|
|
23
|
-
*
|
|
24
|
-
* @param message - Error message or response object
|
|
25
|
-
* @param error - Optional underlying error for logging
|
|
26
|
-
*/
|
|
27
|
-
constructor(message: string | object, error?: Error) {
|
|
28
|
-
super(401, message, error)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject, InjectionToken } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { AdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: AdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class AdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
create(ctx: FactoryContext) {
|
|
14
|
-
const service = this.environment.getToken(AdapterToken)
|
|
15
|
-
if (!service) {
|
|
16
|
-
throw new Error('AdapterToken service not found in environment')
|
|
17
|
-
}
|
|
18
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { EndpointAdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: EndpointAdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class EndpointAdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
|
|
14
|
-
create(ctx: FactoryContext) {
|
|
15
|
-
const service = this.environment.getToken(EndpointAdapterToken)
|
|
16
|
-
if (!service) {
|
|
17
|
-
throw new Error('EndpointAdapterToken service not found in environment')
|
|
18
|
-
}
|
|
19
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject, InjectionToken } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { HttpAdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: HttpAdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class HttpAdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
create(ctx: FactoryContext) {
|
|
14
|
-
const service = this.environment.getToken(HttpAdapterToken)
|
|
15
|
-
if (!service) {
|
|
16
|
-
throw new Error('HttpAdapterToken service not found in environment')
|
|
17
|
-
}
|
|
18
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/factories/index.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './adapter.factory.mjs'
|
|
2
|
-
export * from './endpoint-adapter.factory.mjs'
|
|
3
|
-
export * from './http-adapter.factory.mjs'
|
|
4
|
-
export * from './multipart-adapter.factory.mjs'
|
|
5
|
-
export * from './request.factory.mjs'
|
|
6
|
-
export * from './reply.factory.mjs'
|
|
7
|
-
export * from './stream-adapter.factory.mjs'
|
|
8
|
-
export * from './xml-stream-adapter.factory.mjs'
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { MultipartAdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: MultipartAdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class MultipartAdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
|
|
14
|
-
create(ctx: FactoryContext) {
|
|
15
|
-
const service = this.environment.getToken(MultipartAdapterToken)
|
|
16
|
-
if (!service) {
|
|
17
|
-
throw new Error('MultipartAdapterToken service not found in environment')
|
|
18
|
-
}
|
|
19
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject, InjectableScope } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { Reply } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: Reply,
|
|
10
|
-
scope: InjectableScope.Request,
|
|
11
|
-
})
|
|
12
|
-
export class ReplyFactory {
|
|
13
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
14
|
-
create(ctx: FactoryContext) {
|
|
15
|
-
const service = this.environment.getToken(Reply)
|
|
16
|
-
if (!service) {
|
|
17
|
-
throw new Error('ReplyToken service not found in environment')
|
|
18
|
-
}
|
|
19
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject, InjectableScope } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { Request } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: Request,
|
|
10
|
-
scope: InjectableScope.Request,
|
|
11
|
-
})
|
|
12
|
-
export class RequestFactory {
|
|
13
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
14
|
-
create(ctx: FactoryContext) {
|
|
15
|
-
const service = this.environment.getToken(Request)
|
|
16
|
-
if (!service) {
|
|
17
|
-
throw new Error('RequestToken service not found in environment')
|
|
18
|
-
}
|
|
19
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { StreamAdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: StreamAdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class StreamAdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
create(ctx: FactoryContext) {
|
|
14
|
-
const service = this.environment.getToken(StreamAdapterToken)
|
|
15
|
-
if (!service) {
|
|
16
|
-
throw new Error('StreamAdapterToken service not found in environment')
|
|
17
|
-
}
|
|
18
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FactoryContext, InjectionToken } from '@navios/di'
|
|
2
|
-
|
|
3
|
-
import { Factory, inject } from '@navios/di'
|
|
4
|
-
|
|
5
|
-
import { NaviosEnvironment } from '../navios.environment.mjs'
|
|
6
|
-
import { XmlStreamAdapterToken } from '../tokens/index.mjs'
|
|
7
|
-
|
|
8
|
-
@Factory({
|
|
9
|
-
token: XmlStreamAdapterToken,
|
|
10
|
-
})
|
|
11
|
-
export class XmlStreamAdapterFactory {
|
|
12
|
-
private readonly environment = inject(NaviosEnvironment)
|
|
13
|
-
create(ctx: FactoryContext) {
|
|
14
|
-
const service = this.environment.getToken(XmlStreamAdapterToken)
|
|
15
|
-
if (!service) {
|
|
16
|
-
throw new Error('XmlStreamAdapterToken service not found in environment')
|
|
17
|
-
}
|
|
18
|
-
return ctx.inject(service as InjectionToken<any, undefined>)
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/index.mts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from '@navios/di'
|
|
2
|
-
export * from './config/index.mjs'
|
|
3
|
-
export * from './decorators/index.mjs'
|
|
4
|
-
export * from './exceptions/index.mjs'
|
|
5
|
-
export * from './interfaces/index.mjs'
|
|
6
|
-
export * from './logger/index.mjs'
|
|
7
|
-
export * from './metadata/index.mjs'
|
|
8
|
-
export * from './responders/index.mjs'
|
|
9
|
-
export * from './services/index.mjs'
|
|
10
|
-
export * from './stores/index.mjs'
|
|
11
|
-
export * from './tokens/index.mjs'
|
|
12
|
-
export * from './utils/index.mjs'
|
|
13
|
-
export * from './attribute.factory.mjs'
|
|
14
|
-
export * from './factories/index.mjs'
|
|
15
|
-
export * from './navios.application.mjs'
|
|
16
|
-
export * from './navios.factory.mjs'
|