@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.
Files changed (237) hide show
  1. package/CHANGELOG.md +85 -13
  2. package/README.md +69 -220
  3. package/lib/async-context-BAdt7bno.d.mts +239 -0
  4. package/lib/async-context-BAdt7bno.d.mts.map +1 -0
  5. package/lib/async-context-RsWmy2Hi.d.cts +239 -0
  6. package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
  7. package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
  8. package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
  9. package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
  10. package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
  11. package/lib/attribute-value-BNiJjxl1.mjs +225 -0
  12. package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
  13. package/lib/attribute-value-Cux5HhOL.cjs +314 -0
  14. package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
  15. package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
  16. package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
  17. package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
  18. package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
  19. package/lib/execution-context-BVSmLkYp.d.cts +71 -0
  20. package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
  21. package/lib/execution-context-C5F9rojO.d.mts +71 -0
  22. package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
  23. package/lib/execution-context-token--cKS4cJv.cjs +270 -0
  24. package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
  25. package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
  26. package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
  27. package/lib/index.cjs +1672 -4426
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +842 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +842 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1559 -4221
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bz83ZnJ5.cjs +173 -0
  44. package/lib/module-Bz83ZnJ5.cjs.map +1 -0
  45. package/lib/module-options-CSqQUSTm.d.mts +51 -0
  46. package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
  47. package/lib/module-options-DSRBri4J.d.cts +51 -0
  48. package/lib/module-options-DSRBri4J.d.cts.map +1 -0
  49. package/lib/module-zPXwR2qp.mjs +138 -0
  50. package/lib/module-zPXwR2qp.mjs.map +1 -0
  51. package/lib/settled-within-B6gpu2XW.cjs +32 -0
  52. package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
  53. package/lib/settled-within-Bc2pj8WB.mjs +21 -0
  54. package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
  55. package/lib/testing/index.cjs +74 -414
  56. package/lib/testing/index.cjs.map +1 -1
  57. package/lib/testing/index.d.cts +25 -385
  58. package/lib/testing/index.d.cts.map +1 -1
  59. package/lib/testing/index.d.mts +24 -385
  60. package/lib/testing/index.d.mts.map +1 -1
  61. package/lib/testing/index.mjs +72 -408
  62. package/lib/testing/index.mjs.map +1 -1
  63. package/lib/transport.cjs +36 -0
  64. package/lib/transport.d.cts +254 -0
  65. package/lib/transport.d.cts.map +1 -0
  66. package/lib/transport.d.mts +254 -0
  67. package/lib/transport.d.mts.map +1 -0
  68. package/lib/transport.mjs +6 -0
  69. package/package.json +37 -17
  70. package/docs/README.md +0 -316
  71. package/docs/adapters.md +0 -308
  72. package/docs/application-setup.md +0 -524
  73. package/docs/attributes.md +0 -689
  74. package/docs/controllers.md +0 -373
  75. package/docs/endpoints.md +0 -444
  76. package/docs/exceptions.md +0 -352
  77. package/docs/guards.md +0 -550
  78. package/docs/legacy-compat.md +0 -356
  79. package/docs/modules.md +0 -377
  80. package/docs/quick-start.md +0 -290
  81. package/docs/services.md +0 -427
  82. package/docs/testing.md +0 -827
  83. package/lib/index-3LcTrbxz.d.mts +0 -3804
  84. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  85. package/lib/index-B14SekVb.d.cts +0 -3804
  86. package/lib/index-B14SekVb.d.cts.map +0 -1
  87. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  88. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  89. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  90. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  91. package/lib/tokens-BEuBMGGX.cjs +0 -193
  92. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  93. package/lib/tokens-COyNGV1I.mjs +0 -97
  94. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  95. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  96. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  97. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  98. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  99. package/project.json +0 -66
  100. package/src/__tests__/attribute.factory.spec.mts +0 -300
  101. package/src/__tests__/config.service.spec.mts +0 -43
  102. package/src/__tests__/console-logger.service.spec.mts +0 -312
  103. package/src/__tests__/controller-resolver.spec.mts +0 -229
  104. package/src/__tests__/controller.spec.mts +0 -58
  105. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  106. package/src/__tests__/logger.service.spec.mts +0 -147
  107. package/src/__tests__/responders.spec.mts +0 -340
  108. package/src/__tests__/testing-module.spec.mts +0 -459
  109. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  110. package/src/attribute.factory.mts +0 -325
  111. package/src/config/config-service.interface.mts +0 -47
  112. package/src/config/config.provider.mts +0 -69
  113. package/src/config/config.service.mts +0 -176
  114. package/src/config/index.mts +0 -5
  115. package/src/config/types.mts +0 -58
  116. package/src/config/utils/helpers.mts +0 -23
  117. package/src/config/utils/index.mts +0 -1
  118. package/src/decorators/controller.decorator.mts +0 -81
  119. package/src/decorators/endpoint.decorator.mts +0 -181
  120. package/src/decorators/header.decorator.mts +0 -38
  121. package/src/decorators/http-code.decorator.mts +0 -38
  122. package/src/decorators/index.mts +0 -8
  123. package/src/decorators/module.decorator.mts +0 -106
  124. package/src/decorators/multipart.decorator.mts +0 -169
  125. package/src/decorators/stream.decorator.mts +0 -155
  126. package/src/decorators/use-guards.decorator.mts +0 -73
  127. package/src/exceptions/bad-request.exception.mts +0 -28
  128. package/src/exceptions/conflict.exception.mts +0 -31
  129. package/src/exceptions/forbidden.exception.mts +0 -30
  130. package/src/exceptions/http.exception.mts +0 -33
  131. package/src/exceptions/index.mts +0 -7
  132. package/src/exceptions/internal-server-error.exception.mts +0 -33
  133. package/src/exceptions/not-found.exception.mts +0 -33
  134. package/src/exceptions/unauthorized.exception.mts +0 -30
  135. package/src/factories/adapter.factory.mts +0 -20
  136. package/src/factories/endpoint-adapter.factory.mts +0 -21
  137. package/src/factories/http-adapter.factory.mts +0 -20
  138. package/src/factories/index.mts +0 -8
  139. package/src/factories/multipart-adapter.factory.mts +0 -21
  140. package/src/factories/reply.factory.mts +0 -21
  141. package/src/factories/request.factory.mts +0 -21
  142. package/src/factories/stream-adapter.factory.mts +0 -20
  143. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  144. package/src/index.mts +0 -16
  145. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  146. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  147. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  148. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  149. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  150. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  151. package/src/interfaces/adapter-environment.interface.mts +0 -74
  152. package/src/interfaces/can-activate.mts +0 -38
  153. package/src/interfaces/http-header.mts +0 -18
  154. package/src/interfaces/index.mts +0 -14
  155. package/src/interfaces/navios-module.mts +0 -28
  156. package/src/interfaces/plugin-context.mts +0 -104
  157. package/src/interfaces/plugin-stage.mts +0 -62
  158. package/src/interfaces/plugin.interface.mts +0 -119
  159. package/src/interfaces/staged-plugin.interface.mts +0 -209
  160. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  161. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  162. package/src/legacy-compat/attribute.factory.mts +0 -351
  163. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  164. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  165. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  166. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  167. package/src/legacy-compat/decorators/index.mts +0 -11
  168. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  169. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  170. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  171. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  172. package/src/legacy-compat/index.mts +0 -57
  173. package/src/logger/README.md +0 -3
  174. package/src/logger/console-logger.service.mts +0 -714
  175. package/src/logger/index.mts +0 -6
  176. package/src/logger/log-levels.mts +0 -21
  177. package/src/logger/logger-service.interface.mts +0 -42
  178. package/src/logger/logger.service.mts +0 -113
  179. package/src/logger/logger.tokens.mts +0 -44
  180. package/src/logger/utils/cli-colors.util.mts +0 -17
  181. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  182. package/src/logger/utils/index.mts +0 -5
  183. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  184. package/src/logger/utils/is-log-level.util.mts +0 -10
  185. package/src/logger/utils/shared.utils.mts +0 -51
  186. package/src/metadata/controller.metadata.mts +0 -79
  187. package/src/metadata/handler.metadata.mts +0 -80
  188. package/src/metadata/index.mts +0 -4
  189. package/src/metadata/module.metadata.mts +0 -116
  190. package/src/metadata/navios-managed.metadata.mts +0 -42
  191. package/src/navios.application.mts +0 -678
  192. package/src/navios.environment.mts +0 -42
  193. package/src/navios.factory.mts +0 -158
  194. package/src/responders/enums/framework-error.enum.mts +0 -38
  195. package/src/responders/enums/index.mts +0 -1
  196. package/src/responders/index.mts +0 -4
  197. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  198. package/src/responders/interfaces/error-response.interface.mts +0 -22
  199. package/src/responders/interfaces/index.mts +0 -3
  200. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  201. package/src/responders/services/error-response-producer.service.mts +0 -143
  202. package/src/responders/services/forbidden-responder.service.mts +0 -77
  203. package/src/responders/services/index.mts +0 -5
  204. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  205. package/src/responders/services/not-found-responder.service.mts +0 -76
  206. package/src/responders/services/validation-error-responder.service.mts +0 -78
  207. package/src/responders/tokens/index.mts +0 -1
  208. package/src/responders/tokens/responder.tokens.mts +0 -84
  209. package/src/services/abstract-handler-adapter.service.mts +0 -366
  210. package/src/services/guard-runner.service.mts +0 -152
  211. package/src/services/index.mts +0 -4
  212. package/src/services/instance-resolver.service.mts +0 -177
  213. package/src/services/module-loader.service.mts +0 -255
  214. package/src/stores/index.mts +0 -1
  215. package/src/stores/request-id.store.mts +0 -85
  216. package/src/testing/index.mts +0 -3
  217. package/src/testing/testing-module.mts +0 -393
  218. package/src/testing/unit-testing-module.mts +0 -298
  219. package/src/tokens/adapter.token.mts +0 -6
  220. package/src/tokens/endpoint-adapter.token.mts +0 -8
  221. package/src/tokens/execution-context.token.mts +0 -9
  222. package/src/tokens/http-adapter.token.mts +0 -8
  223. package/src/tokens/index.mts +0 -10
  224. package/src/tokens/multipart-adapter.token.mts +0 -8
  225. package/src/tokens/navios-options.token.mts +0 -6
  226. package/src/tokens/reply.token.mts +0 -3
  227. package/src/tokens/request.token.mts +0 -3
  228. package/src/tokens/stream-adapter.token.mts +0 -8
  229. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  230. package/src/utils/adapter-supports.util.mts +0 -47
  231. package/src/utils/define-plugin.mts +0 -251
  232. package/src/utils/index.mts +0 -2
  233. package/tsconfig.json +0 -21
  234. package/tsconfig.lib.json +0 -8
  235. package/tsconfig.spec.json +0 -15
  236. package/tsdown.config.mts +0 -35
  237. 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
- }