@navios/core 1.0.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
// oxlint-disable no-unused-vars
|
|
2
|
-
import { builder } from '@navios/builder'
|
|
3
|
-
|
|
4
|
-
import { describe, expectTypeOf, test } from 'vitest'
|
|
5
|
-
import { z } from 'zod/v4'
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
EndpointParams,
|
|
9
|
-
EndpointResult,
|
|
10
|
-
MultipartParams,
|
|
11
|
-
MultipartResult,
|
|
12
|
-
StreamParams,
|
|
13
|
-
} from '../index.mjs'
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
AttributeFactory,
|
|
17
|
-
Controller,
|
|
18
|
-
Endpoint,
|
|
19
|
-
Header,
|
|
20
|
-
HttpCode,
|
|
21
|
-
Injectable,
|
|
22
|
-
Module,
|
|
23
|
-
Multipart,
|
|
24
|
-
Stream,
|
|
25
|
-
UseGuards,
|
|
26
|
-
} from '../index.mjs'
|
|
27
|
-
|
|
28
|
-
// Create a test API builder
|
|
29
|
-
const api = builder()
|
|
30
|
-
|
|
31
|
-
// Test schemas
|
|
32
|
-
const responseSchema = z.object({
|
|
33
|
-
id: z.string(),
|
|
34
|
-
name: z.string(),
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const querySchema = z.object({
|
|
38
|
-
page: z.number(),
|
|
39
|
-
limit: z.number(),
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const requestSchema = z.object({
|
|
43
|
-
name: z.string(),
|
|
44
|
-
email: z.string(),
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const multipartRequestSchema = z.object({
|
|
48
|
-
file: z.instanceof(File),
|
|
49
|
-
description: z.string(),
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
// Test endpoint declarations
|
|
53
|
-
const getUserEndpoint = api.declareEndpoint({
|
|
54
|
-
method: 'GET',
|
|
55
|
-
url: '/users/$userId',
|
|
56
|
-
querySchema,
|
|
57
|
-
responseSchema,
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const createUserEndpoint = api.declareEndpoint({
|
|
61
|
-
method: 'POST',
|
|
62
|
-
url: '/users',
|
|
63
|
-
requestSchema,
|
|
64
|
-
responseSchema,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
const uploadFileEndpoint = api.declareMultipart({
|
|
68
|
-
method: 'POST',
|
|
69
|
-
url: '/upload',
|
|
70
|
-
requestSchema: multipartRequestSchema,
|
|
71
|
-
responseSchema,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const downloadFileEndpoint = api.declareStream({
|
|
75
|
-
method: 'GET',
|
|
76
|
-
url: '/files/$fileId',
|
|
77
|
-
querySchema,
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
// Mock guard for testing
|
|
81
|
-
class AuthGuard {
|
|
82
|
-
canActivate() {
|
|
83
|
-
return true
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
describe('Legacy Decorators Type Safety', () => {
|
|
88
|
-
describe('Module decorator', () => {
|
|
89
|
-
test('should accept valid module options', () => {
|
|
90
|
-
@Module({
|
|
91
|
-
controllers: [],
|
|
92
|
-
imports: [],
|
|
93
|
-
guards: [],
|
|
94
|
-
})
|
|
95
|
-
class TestModule {}
|
|
96
|
-
|
|
97
|
-
expectTypeOf(TestModule).toBeConstructibleWith()
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
test('should accept controllers in module', () => {
|
|
101
|
-
@Controller()
|
|
102
|
-
class TestController {}
|
|
103
|
-
|
|
104
|
-
@Module({
|
|
105
|
-
controllers: [TestController],
|
|
106
|
-
})
|
|
107
|
-
class TestModule {}
|
|
108
|
-
|
|
109
|
-
expectTypeOf(TestModule).toBeConstructibleWith()
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
describe('Controller decorator', () => {
|
|
114
|
-
test('should accept valid controller options', () => {
|
|
115
|
-
@Controller()
|
|
116
|
-
class TestController {}
|
|
117
|
-
|
|
118
|
-
expectTypeOf(TestController).toBeConstructibleWith()
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test('should accept guards in controller', () => {
|
|
122
|
-
@Controller({
|
|
123
|
-
guards: [AuthGuard],
|
|
124
|
-
})
|
|
125
|
-
class TestController {}
|
|
126
|
-
|
|
127
|
-
expectTypeOf(TestController).toBeConstructibleWith()
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
describe('Endpoint decorator', () => {
|
|
132
|
-
test('should enforce correct parameter type', () => {
|
|
133
|
-
@Controller()
|
|
134
|
-
class UserController {
|
|
135
|
-
@Endpoint(getUserEndpoint)
|
|
136
|
-
async getUser(
|
|
137
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
138
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
139
|
-
// TypeScript should infer:
|
|
140
|
-
// - request.urlParams.userId: string | number
|
|
141
|
-
// - request.params.page: number
|
|
142
|
-
// - request.params.limit: number
|
|
143
|
-
expectTypeOf(request.urlParams.userId).toEqualTypeOf<string>()
|
|
144
|
-
expectTypeOf(request.params.page).toEqualTypeOf<number>()
|
|
145
|
-
expectTypeOf(request.params.limit).toEqualTypeOf<number>()
|
|
146
|
-
return {
|
|
147
|
-
id: request.urlParams.userId.toString(),
|
|
148
|
-
name: 'Test',
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
test('should enforce correct return type', () => {
|
|
157
|
-
@Controller()
|
|
158
|
-
class UserController {
|
|
159
|
-
@Endpoint(getUserEndpoint)
|
|
160
|
-
async getUser(
|
|
161
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
162
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
163
|
-
// Return type should match responseSchema
|
|
164
|
-
return {
|
|
165
|
-
id: '1',
|
|
166
|
-
name: 'John',
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('should reject incorrect parameter type', () => {
|
|
175
|
-
@Controller()
|
|
176
|
-
class UserController {
|
|
177
|
-
// @ts-expect-error - wrong parameter type
|
|
178
|
-
@Endpoint(getUserEndpoint)
|
|
179
|
-
async getUser(request: {
|
|
180
|
-
wrong: string
|
|
181
|
-
}): EndpointResult<typeof getUserEndpoint> {
|
|
182
|
-
return { id: '1', name: 'John' }
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
test('should reject incorrect return type', () => {
|
|
188
|
-
@Controller()
|
|
189
|
-
class UserController {
|
|
190
|
-
@Endpoint(getUserEndpoint)
|
|
191
|
-
async getUser(
|
|
192
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
193
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
194
|
-
// @ts-expect-error - wrong return type
|
|
195
|
-
return { wrong: 'value' }
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
test('should work with POST endpoint with request body', () => {
|
|
201
|
-
@Controller()
|
|
202
|
-
class UserController {
|
|
203
|
-
@Endpoint(createUserEndpoint)
|
|
204
|
-
async createUser(
|
|
205
|
-
request: EndpointParams<typeof createUserEndpoint>,
|
|
206
|
-
): EndpointResult<typeof createUserEndpoint> {
|
|
207
|
-
// TypeScript should infer:
|
|
208
|
-
// - request.data.name: string
|
|
209
|
-
// - request.data.email: string
|
|
210
|
-
expectTypeOf(request.data.name).toEqualTypeOf<string>()
|
|
211
|
-
expectTypeOf(request.data.email).toEqualTypeOf<string>()
|
|
212
|
-
return {
|
|
213
|
-
id: '1',
|
|
214
|
-
name: request.data.name,
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
220
|
-
})
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
describe('Multipart decorator', () => {
|
|
224
|
-
test('should enforce correct parameter type', () => {
|
|
225
|
-
@Controller()
|
|
226
|
-
class FileController {
|
|
227
|
-
@Multipart(uploadFileEndpoint)
|
|
228
|
-
async uploadFile(
|
|
229
|
-
request: MultipartParams<typeof uploadFileEndpoint>,
|
|
230
|
-
): MultipartResult<typeof uploadFileEndpoint> {
|
|
231
|
-
// TypeScript should infer:
|
|
232
|
-
// - request.data.file: File
|
|
233
|
-
// - request.data.description: string
|
|
234
|
-
expectTypeOf(request.data.file).toEqualTypeOf<File>()
|
|
235
|
-
expectTypeOf(request.data.description).toEqualTypeOf<string>()
|
|
236
|
-
return {
|
|
237
|
-
id: '1',
|
|
238
|
-
name: 'uploaded.jpg',
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
expectTypeOf(FileController).toBeConstructibleWith()
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('should reject incorrect parameter type', () => {
|
|
247
|
-
@Controller()
|
|
248
|
-
class FileController {
|
|
249
|
-
// @ts-expect-error - wrong parameter type
|
|
250
|
-
@Multipart(uploadFileEndpoint)
|
|
251
|
-
async uploadFile(request: {
|
|
252
|
-
wrong: string
|
|
253
|
-
}): MultipartResult<typeof uploadFileEndpoint> {
|
|
254
|
-
return { id: '1', name: 'test.jpg' }
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
describe('Stream decorator', () => {
|
|
261
|
-
test('should enforce correct parameter type', () => {
|
|
262
|
-
@Controller()
|
|
263
|
-
class FileController {
|
|
264
|
-
@Stream(downloadFileEndpoint)
|
|
265
|
-
async downloadFile(
|
|
266
|
-
request: StreamParams<typeof downloadFileEndpoint>,
|
|
267
|
-
): Promise<void> {
|
|
268
|
-
// TypeScript should infer:
|
|
269
|
-
// - request.urlParams.fileId: string | number
|
|
270
|
-
// - request.params.page: number
|
|
271
|
-
// - request.params.limit: number
|
|
272
|
-
expectTypeOf(request.urlParams.fileId).toEqualTypeOf<string>()
|
|
273
|
-
expectTypeOf(request.params.page).toEqualTypeOf<number>()
|
|
274
|
-
expectTypeOf(request.params.limit).toEqualTypeOf<number>()
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
expectTypeOf(FileController).toBeConstructibleWith()
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
test('should work without reply parameter (Bun compatibility)', () => {
|
|
282
|
-
@Controller()
|
|
283
|
-
class FileController {
|
|
284
|
-
@Stream(downloadFileEndpoint)
|
|
285
|
-
async downloadFile(
|
|
286
|
-
request: StreamParams<typeof downloadFileEndpoint>,
|
|
287
|
-
): Promise<void> {
|
|
288
|
-
// Stream methods can work without reply parameter (for Bun)
|
|
289
|
-
expectTypeOf(request.urlParams.fileId).toEqualTypeOf<string>()
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
expectTypeOf(FileController).toBeConstructibleWith()
|
|
294
|
-
})
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
describe('UseGuards decorator', () => {
|
|
298
|
-
test('should work on class level', () => {
|
|
299
|
-
@Controller()
|
|
300
|
-
@UseGuards(AuthGuard)
|
|
301
|
-
class ProtectedController {
|
|
302
|
-
@Endpoint(getUserEndpoint)
|
|
303
|
-
async getUser(
|
|
304
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
305
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
306
|
-
return { id: '1', name: 'John' }
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
expectTypeOf(ProtectedController).toBeConstructibleWith()
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
test('should work on method level', () => {
|
|
314
|
-
@Controller()
|
|
315
|
-
class UserController {
|
|
316
|
-
@Endpoint(getUserEndpoint)
|
|
317
|
-
@UseGuards(AuthGuard)
|
|
318
|
-
async getUser(
|
|
319
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
320
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
321
|
-
return { id: '1', name: 'John' }
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
326
|
-
})
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
describe('Header decorator', () => {
|
|
330
|
-
test('should work with string value', () => {
|
|
331
|
-
@Controller()
|
|
332
|
-
class UserController {
|
|
333
|
-
@Endpoint(getUserEndpoint)
|
|
334
|
-
@Header('Cache-Control', 'max-age=3600')
|
|
335
|
-
async getUser(
|
|
336
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
337
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
338
|
-
return { id: '1', name: 'John' }
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
test('should work with number value', () => {
|
|
346
|
-
@Controller()
|
|
347
|
-
class UserController {
|
|
348
|
-
@Endpoint(getUserEndpoint)
|
|
349
|
-
@Header('Content-Length', 100)
|
|
350
|
-
async getUser(
|
|
351
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
352
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
353
|
-
return { id: '1', name: 'John' }
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
358
|
-
})
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
describe('HttpCode decorator', () => {
|
|
362
|
-
test('should accept valid status codes', () => {
|
|
363
|
-
@Controller()
|
|
364
|
-
class UserController {
|
|
365
|
-
@Endpoint(createUserEndpoint)
|
|
366
|
-
@HttpCode(201)
|
|
367
|
-
async createUser(
|
|
368
|
-
request: EndpointParams<typeof createUserEndpoint>,
|
|
369
|
-
): EndpointResult<typeof createUserEndpoint> {
|
|
370
|
-
return { id: '1', name: request.data.name }
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
375
|
-
})
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
describe('Injectable decorator', () => {
|
|
379
|
-
test('should work with services', () => {
|
|
380
|
-
@Injectable()
|
|
381
|
-
class UserService {
|
|
382
|
-
getUser(id: string) {
|
|
383
|
-
return { id, name: 'John' }
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
expectTypeOf(UserService).toBeConstructibleWith()
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
test('should work with controller dependencies', () => {
|
|
391
|
-
@Injectable()
|
|
392
|
-
class UserService {
|
|
393
|
-
getUser(id: string) {
|
|
394
|
-
return { id, name: 'John' }
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
@Controller()
|
|
399
|
-
class UserController {
|
|
400
|
-
constructor(private readonly userService: UserService) {}
|
|
401
|
-
|
|
402
|
-
@Endpoint(getUserEndpoint)
|
|
403
|
-
async getUser(
|
|
404
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
405
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
406
|
-
return this.userService.getUser(request.urlParams.userId.toString())
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
expectTypeOf(UserController).toBeConstructibleWith(
|
|
411
|
-
{} as InstanceType<typeof UserService>,
|
|
412
|
-
)
|
|
413
|
-
})
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
describe('AttributeFactory', () => {
|
|
417
|
-
test('should create simple attribute for controllers', () => {
|
|
418
|
-
const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
419
|
-
|
|
420
|
-
// Note: In legacy decorators, decorators are applied bottom-to-top
|
|
421
|
-
// So @Controller() must be at the bottom to run first
|
|
422
|
-
@Public()
|
|
423
|
-
@Controller()
|
|
424
|
-
class PublicController {
|
|
425
|
-
@Endpoint(getUserEndpoint)
|
|
426
|
-
async getUser(
|
|
427
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
428
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
429
|
-
return { id: '1', name: 'John' }
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
expectTypeOf(PublicController).toBeConstructibleWith()
|
|
434
|
-
expectTypeOf(Public.token).toEqualTypeOf<symbol>()
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
test('should create attribute with schema for endpoints', () => {
|
|
438
|
-
const RateLimit = AttributeFactory.createAttribute(
|
|
439
|
-
Symbol.for('RateLimit'),
|
|
440
|
-
z.object({ requests: z.number(), window: z.number() }),
|
|
441
|
-
)
|
|
442
|
-
|
|
443
|
-
@Controller()
|
|
444
|
-
class RateLimitedController {
|
|
445
|
-
// Note: For method decorators, @Endpoint must be at the bottom
|
|
446
|
-
@RateLimit({ requests: 100, window: 60000 })
|
|
447
|
-
@Endpoint(getUserEndpoint)
|
|
448
|
-
async getUser(
|
|
449
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
450
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
451
|
-
return { id: '1', name: 'John' }
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
expectTypeOf(RateLimitedController).toBeConstructibleWith()
|
|
456
|
-
expectTypeOf(RateLimit.token).toEqualTypeOf<symbol>()
|
|
457
|
-
expectTypeOf(RateLimit.schema).toBeObject()
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
test('should create attribute for modules', () => {
|
|
461
|
-
const ApiVersion = AttributeFactory.createAttribute(
|
|
462
|
-
Symbol.for('ApiVersion'),
|
|
463
|
-
z.string(),
|
|
464
|
-
)
|
|
465
|
-
|
|
466
|
-
@Controller()
|
|
467
|
-
class VersionedController {}
|
|
468
|
-
|
|
469
|
-
// Note: In legacy decorators, @Module must be at the bottom
|
|
470
|
-
@ApiVersion('v2')
|
|
471
|
-
@Module({
|
|
472
|
-
controllers: [VersionedController],
|
|
473
|
-
})
|
|
474
|
-
class VersionedModule {}
|
|
475
|
-
|
|
476
|
-
expectTypeOf(VersionedModule).toBeConstructibleWith()
|
|
477
|
-
})
|
|
478
|
-
})
|
|
479
|
-
|
|
480
|
-
describe('Integration test - full controller', () => {
|
|
481
|
-
test('should work with all decorators together', () => {
|
|
482
|
-
@Controller({
|
|
483
|
-
guards: [AuthGuard],
|
|
484
|
-
})
|
|
485
|
-
@UseGuards(AuthGuard)
|
|
486
|
-
class UserController {
|
|
487
|
-
@Endpoint(getUserEndpoint)
|
|
488
|
-
@UseGuards(AuthGuard)
|
|
489
|
-
@Header('Cache-Control', 'max-age=3600')
|
|
490
|
-
@HttpCode(200)
|
|
491
|
-
async getUser(
|
|
492
|
-
request: EndpointParams<typeof getUserEndpoint>,
|
|
493
|
-
): EndpointResult<typeof getUserEndpoint> {
|
|
494
|
-
return {
|
|
495
|
-
id: request.urlParams.userId.toString(),
|
|
496
|
-
name: 'John',
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
@Endpoint(createUserEndpoint)
|
|
501
|
-
@HttpCode(201)
|
|
502
|
-
async createUser(
|
|
503
|
-
request: EndpointParams<typeof createUserEndpoint>,
|
|
504
|
-
): EndpointResult<typeof createUserEndpoint> {
|
|
505
|
-
return {
|
|
506
|
-
id: '1',
|
|
507
|
-
name: request.data.name,
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
@Module({
|
|
513
|
-
controllers: [UserController],
|
|
514
|
-
})
|
|
515
|
-
class AppModule {}
|
|
516
|
-
|
|
517
|
-
expectTypeOf(UserController).toBeConstructibleWith()
|
|
518
|
-
expectTypeOf(AppModule).toBeConstructibleWith()
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"experimentalDecorators": true,
|
|
5
|
-
"emitDecoratorMetadata": false,
|
|
6
|
-
"outDir": "../../../dist/legacy-compat/__type-tests__"
|
|
7
|
-
},
|
|
8
|
-
"include": ["**/*.spec-d.mts"],
|
|
9
|
-
"exclude": [],
|
|
10
|
-
"references": [
|
|
11
|
-
{
|
|
12
|
-
"path": "../../../tsconfig.lib.json"
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|