@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,373 +0,0 @@
1
- # Controllers
2
-
3
- Controllers in Navios are classes that handle HTTP requests and define your API endpoints. They are decorated with the `@Controller()` decorator and contain methods decorated with endpoint decorators like `@Endpoint()`.
4
-
5
- ## What is a Controller?
6
-
7
- A controller is a TypeScript class that groups related request handling logic. Each controller method represents an HTTP endpoint and defines how to process incoming requests and generate responses.
8
-
9
- ## Creating a Controller
10
-
11
- ### Basic Controller
12
-
13
- ```typescript
14
- import { Controller } from '@navios/core'
15
-
16
- @Controller()
17
- export class UserController {
18
- // Controller methods go here
19
- }
20
- ```
21
-
22
- ### Controller with Guards
23
-
24
- ```typescript
25
- import { Controller } from '@navios/core'
26
-
27
- import { AuthGuard } from './auth.guard'
28
-
29
- @Controller({
30
- guards: [AuthGuard], // Applied to all endpoints in this controller
31
- })
32
- export class UserController {
33
- // All methods will require authentication
34
- }
35
- ```
36
-
37
- ## Controller Options
38
-
39
- The `@Controller()` decorator accepts the following options:
40
-
41
- ### `guards`
42
-
43
- - **Type**: `ClassType[] | Set<ClassType>`
44
- - **Description**: Array of guard classes that will be applied to all endpoints in this controller
45
- - **Example**:
46
-
47
- ```typescript
48
- @Controller({
49
- guards: [AuthGuard, RoleGuard],
50
- })
51
- export class AdminController {}
52
- ```
53
-
54
- ## Controller Lifecycle
55
-
56
- Controllers in Navios have a specific lifecycle:
57
-
58
- 1. **Registration**: Controllers are registered during module loading
59
- 2. **Instantiation**: Controller instances are created with request scope by default
60
- 3. **Dependency Injection**: Dependencies are injected into the controller
61
- 4. **Endpoint Discovery**: Methods decorated with `@Endpoint()` are discovered
62
- 5. **Guard Application**: Controller and endpoint-level guards are applied
63
- 6. **Request Handling**: Methods are called to handle incoming requests
64
-
65
- ## Controller Scope
66
-
67
- Controllers are registered with **Request Scope** by default, meaning:
68
-
69
- - A new instance is created for each HTTP request
70
- - Dependencies are resolved per request
71
- - State is not shared between requests
72
-
73
- ## Best Practices
74
-
75
- ### 1. Logical Grouping
76
-
77
- Group related endpoints in the same controller:
78
-
79
- ```typescript
80
- @Controller()
81
- export class UserController {
82
- // All user-related endpoints
83
- async getUsers() {
84
- /* ... */
85
- }
86
- async getUserById() {
87
- /* ... */
88
- }
89
- async createUser() {
90
- /* ... */
91
- }
92
- async updateUser() {
93
- /* ... */
94
- }
95
- async deleteUser() {
96
- /* ... */
97
- }
98
- }
99
- ```
100
-
101
- ### 2. Use Guards Appropriately
102
-
103
- Apply guards at the appropriate level:
104
-
105
- ```typescript
106
- // Controller-level guards for all endpoints
107
- @Controller({
108
- guards: [AuthGuard],
109
- })
110
- export class UserController {
111
- // All methods require authentication
112
-
113
- @Endpoint(deleteUserEndpoint)
114
- @UseGuards([RoleGuard]) // Additional endpoint-specific guard
115
- async deleteUser() {
116
- // Requires both authentication and role check
117
- }
118
- }
119
- ```
120
-
121
- ### 3. Keep Controllers Thin
122
-
123
- Controllers should orchestrate business logic, not implement it:
124
-
125
- ```typescript
126
- // api/users.ts
127
- import { builder } from '@navios/builder'
128
-
129
- import { z } from 'zod'
130
-
131
- export const api = builder()
132
-
133
- const UserSchema = z.object({
134
- id: z.string(),
135
- name: z.string(),
136
- email: z.string(),
137
- })
138
-
139
- export const getUserByIdEndpoint = api.declareEndpoint({
140
- method: 'GET',
141
- url: '/users/$id',
142
- responseSchema: UserSchema,
143
- })
144
- ```
145
-
146
- ```typescript
147
- // controllers/user.controller.ts
148
- import { inject } from '@navios/di'
149
-
150
- import { getUserByIdEndpoint } from '../api/users.js'
151
-
152
- @Controller()
153
- export class UserController {
154
- private userService = inject(UserService)
155
-
156
- @Endpoint(getUserByIdEndpoint)
157
- async getUserById(params: EndpointParams<typeof getUserByIdEndpoint>) {
158
- // Delegate business logic to service
159
- return this.userService.findById(params.params.id)
160
- }
161
- }
162
- ```
163
-
164
- ### 4. Use TypeScript Types
165
-
166
- Leverage TypeScript and `@navios/builder` for better type safety:
167
-
168
- ```typescript
169
- // api/users.ts
170
- import { builder } from '@navios/builder'
171
-
172
- import { z } from 'zod'
173
-
174
- export const api = builder()
175
-
176
- const UserResponseSchema = z.object({
177
- id: z.string(),
178
- name: z.string(),
179
- email: z.string().email(),
180
- })
181
-
182
- export const getUserByIdEndpoint = api.declareEndpoint({
183
- method: 'GET',
184
- url: '/users/$id', // $id is automatically typed as string
185
- responseSchema: UserResponseSchema,
186
- })
187
- ```
188
-
189
- ```typescript
190
- // controllers/user.controller.ts
191
- @Controller()
192
- export class UserController {
193
- @Endpoint(getUserByIdEndpoint)
194
- async getUserById(params: EndpointParams<typeof getUserByIdEndpoint>) {
195
- // params is properly typed with full intellisense
196
- // params.params.id is string (from URL parameter)
197
- return { id: params.params.id, name: 'John', email: 'john@example.com' }
198
- }
199
- }
200
- ```
201
-
202
- ## Dependency Injection in Controllers
203
-
204
- Controllers support full dependency injection:
205
-
206
- ```typescript
207
- import { Controller } from '@navios/core'
208
- import { inject } from '@navios/di'
209
-
210
- @Controller()
211
- export class UserController {
212
- // Inject services
213
- private userService = inject(UserService)
214
- private logger = inject(Logger, { context: 'UserController' })
215
-
216
- @Endpoint(createUserEndpoint)
217
- async createUser({ body }: { body: CreateUserDto }) {
218
- this.logger.debug('Creating new user')
219
- return this.userService.create(body)
220
- }
221
- }
222
- ```
223
-
224
- ## Error Handling in Controllers
225
-
226
- Controllers can throw HTTP exceptions that are automatically handled:
227
-
228
- ```typescript
229
- import { BadRequestException, NotFoundException } from '@navios/core'
230
-
231
- @Controller()
232
- export class UserController {
233
- private userService = inject(UserService)
234
-
235
- @Endpoint(getUserByIdEndpoint)
236
- async getUserById({ params }: { params: { id: string } }) {
237
- if (!params.id) {
238
- throw new BadRequestException('User ID is required')
239
- }
240
-
241
- const user = await this.userService.findById(params.id)
242
- if (!user) {
243
- throw new NotFoundException('User not found')
244
- }
245
-
246
- return user
247
- }
248
- }
249
- ```
250
-
251
- ## Controller Metadata
252
-
253
- Each controller decorated with `@Controller()` has associated metadata:
254
-
255
- ```typescript
256
- export interface ControllerMetadata {
257
- guards: Set<ClassType>
258
- attributes: Map<symbol, unknown>
259
- }
260
- ```
261
-
262
- This metadata is used internally by Navios to:
263
-
264
- - Apply guards to all controller endpoints
265
- - Store custom attributes
266
- - Manage controller lifecycle
267
-
268
- ## Advanced Patterns
269
-
270
- ### Resource Controllers
271
-
272
- Create controllers that follow REST conventions using `@navios/builder`:
273
-
274
- ```typescript
275
- // api/users.ts
276
- import { builder } from '@navios/builder'
277
-
278
- import { z } from 'zod'
279
-
280
- export const api = builder()
281
-
282
- const UserSchema = z.object({
283
- id: z.string(),
284
- name: z.string(),
285
- email: z.string(),
286
- })
287
-
288
- const CreateUserSchema = z.object({
289
- name: z.string(),
290
- email: z.string(),
291
- })
292
-
293
- const UpdateUserSchema = CreateUserSchema.partial()
294
-
295
- export const getAllUsersEndpoint = api.declareEndpoint({
296
- method: 'GET',
297
- url: '/users',
298
- responseSchema: z.array(UserSchema),
299
- })
300
-
301
- export const getUserByIdEndpoint = api.declareEndpoint({
302
- method: 'GET',
303
- url: '/users/$id',
304
- responseSchema: UserSchema,
305
- })
306
-
307
- export const createUserEndpoint = api.declareEndpoint({
308
- method: 'POST',
309
- url: '/users',
310
- requestSchema: CreateUserSchema,
311
- responseSchema: UserSchema,
312
- })
313
-
314
- export const updateUserEndpoint = api.declareEndpoint({
315
- method: 'PUT',
316
- url: '/users/$id',
317
- requestSchema: UpdateUserSchema,
318
- responseSchema: UserSchema,
319
- })
320
-
321
- export const deleteUserEndpoint = api.declareEndpoint({
322
- method: 'DELETE',
323
- url: '/users/$id',
324
- responseSchema: z.object({ success: z.boolean() }),
325
- })
326
- ```
327
-
328
- ```typescript
329
- // controllers/user.controller.ts
330
- import type { EndpointParams } from '@navios/core'
331
-
332
- import { Controller, Endpoint } from '@navios/core'
333
- import { inject } from '@navios/di'
334
-
335
- import {
336
- createUserEndpoint,
337
- deleteUserEndpoint,
338
- getAllUsersEndpoint,
339
- getUserByIdEndpoint,
340
- updateUserEndpoint,
341
- } from '../api/users.js'
342
-
343
- @Controller()
344
- export class UserController {
345
- private userService = inject(UserService)
346
-
347
- @Endpoint(getAllUsersEndpoint)
348
- async index(params: EndpointParams<typeof getAllUsersEndpoint>) {
349
- return this.userService.findAll()
350
- }
351
-
352
- @Endpoint(getUserByIdEndpoint)
353
- async show(params: EndpointParams<typeof getUserByIdEndpoint>) {
354
- return this.userService.findById(params.params.id)
355
- }
356
-
357
- @Endpoint(createUserEndpoint)
358
- async create(params: EndpointParams<typeof createUserEndpoint>) {
359
- return this.userService.create(params.data)
360
- }
361
-
362
- @Endpoint(updateUserEndpoint)
363
- async update(params: EndpointParams<typeof updateUserEndpoint>) {
364
- return this.userService.update(params.params.id, params.data)
365
- }
366
-
367
- @Endpoint(deleteUserEndpoint)
368
- async destroy(params: EndpointParams<typeof deleteUserEndpoint>) {
369
- await this.userService.delete(params.params.id)
370
- return { success: true }
371
- }
372
- }
373
- ```