@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.
Files changed (237) hide show
  1. package/CHANGELOG.md +97 -11
  2. package/README.md +67 -220
  3. package/lib/async-context-6pdlnNLA.d.mts +237 -0
  4. package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
  5. package/lib/async-context-Dqk7pE-D.d.cts +237 -0
  6. package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
  7. package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
  8. package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
  9. package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
  10. package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
  11. package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
  12. package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
  13. package/lib/attribute-value-DMEA255r.mjs +119 -0
  14. package/lib/attribute-value-DMEA255r.mjs.map +1 -0
  15. package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
  16. package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
  17. package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
  18. package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
  19. package/lib/execution-context-BPD3FeFb.d.mts +71 -0
  20. package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
  21. package/lib/execution-context-BTJdHhbf.d.cts +71 -0
  22. package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
  23. package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
  24. package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
  25. package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
  26. package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
  27. package/lib/index.cjs +1687 -4409
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +838 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +838 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1573 -4219
  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-Bha7GER_.mjs +135 -0
  44. package/lib/module-Bha7GER_.mjs.map +1 -0
  45. package/lib/module-DZewk_2r.cjs +164 -0
  46. package/lib/module-DZewk_2r.cjs.map +1 -0
  47. package/lib/module-graph-DCP9MHG0.cjs +147 -0
  48. package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
  49. package/lib/module-graph-xvVEykFM.mjs +142 -0
  50. package/lib/module-graph-xvVEykFM.mjs.map +1 -0
  51. package/lib/module-metadata-C8S92seK.cjs +95 -0
  52. package/lib/module-metadata-C8S92seK.cjs.map +1 -0
  53. package/lib/module-metadata-k3RTt20x.mjs +66 -0
  54. package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
  55. package/lib/module-options-Dmse0gii.d.mts +51 -0
  56. package/lib/module-options-Dmse0gii.d.mts.map +1 -0
  57. package/lib/module-options-IuDO-p8u.d.cts +51 -0
  58. package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
  59. package/lib/testing/index.cjs +96 -414
  60. package/lib/testing/index.cjs.map +1 -1
  61. package/lib/testing/index.d.cts +25 -385
  62. package/lib/testing/index.d.cts.map +1 -1
  63. package/lib/testing/index.d.mts +24 -385
  64. package/lib/testing/index.d.mts.map +1 -1
  65. package/lib/testing/index.mjs +94 -408
  66. package/lib/testing/index.mjs.map +1 -1
  67. package/lib/transport.cjs +25 -0
  68. package/lib/transport.d.cts +190 -0
  69. package/lib/transport.d.cts.map +1 -0
  70. package/lib/transport.d.mts +190 -0
  71. package/lib/transport.d.mts.map +1 -0
  72. package/lib/transport.mjs +7 -0
  73. package/package.json +37 -17
  74. package/docs/README.md +0 -316
  75. package/docs/adapters.md +0 -308
  76. package/docs/application-setup.md +0 -524
  77. package/docs/attributes.md +0 -689
  78. package/docs/controllers.md +0 -373
  79. package/docs/endpoints.md +0 -444
  80. package/docs/exceptions.md +0 -352
  81. package/docs/guards.md +0 -550
  82. package/docs/legacy-compat.md +0 -356
  83. package/docs/modules.md +0 -377
  84. package/docs/quick-start.md +0 -290
  85. package/docs/services.md +0 -427
  86. package/docs/testing.md +0 -827
  87. package/lib/index-C0Sg16Eb.d.cts +0 -3365
  88. package/lib/index-C0Sg16Eb.d.cts.map +0 -1
  89. package/lib/index-DySQ6Dpd.d.mts +0 -3365
  90. package/lib/index-DySQ6Dpd.d.mts.map +0 -1
  91. package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
  92. package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
  93. package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
  94. package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
  95. package/lib/tokens-4J9sredA.mjs +0 -100
  96. package/lib/tokens-4J9sredA.mjs.map +0 -1
  97. package/lib/tokens-CWw9kyeD.cjs +0 -196
  98. package/lib/tokens-CWw9kyeD.cjs.map +0 -1
  99. package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
  100. package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
  101. package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
  102. package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
  103. package/project.json +0 -66
  104. package/src/__tests__/attribute.factory.spec.mts +0 -300
  105. package/src/__tests__/config.service.spec.mts +0 -43
  106. package/src/__tests__/console-logger.service.spec.mts +0 -312
  107. package/src/__tests__/controller-resolver.spec.mts +0 -229
  108. package/src/__tests__/controller.spec.mts +0 -58
  109. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  110. package/src/__tests__/logger.service.spec.mts +0 -147
  111. package/src/__tests__/responders.spec.mts +0 -340
  112. package/src/__tests__/testing-module.spec.mts +0 -459
  113. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  114. package/src/attribute.factory.mts +0 -325
  115. package/src/config/config-service.interface.mts +0 -47
  116. package/src/config/config.provider.mts +0 -69
  117. package/src/config/config.service.mts +0 -176
  118. package/src/config/index.mts +0 -5
  119. package/src/config/types.mts +0 -58
  120. package/src/config/utils/helpers.mts +0 -23
  121. package/src/config/utils/index.mts +0 -1
  122. package/src/decorators/controller.decorator.mts +0 -81
  123. package/src/decorators/endpoint.decorator.mts +0 -181
  124. package/src/decorators/header.decorator.mts +0 -38
  125. package/src/decorators/http-code.decorator.mts +0 -38
  126. package/src/decorators/index.mts +0 -8
  127. package/src/decorators/module.decorator.mts +0 -106
  128. package/src/decorators/multipart.decorator.mts +0 -169
  129. package/src/decorators/stream.decorator.mts +0 -155
  130. package/src/decorators/use-guards.decorator.mts +0 -73
  131. package/src/exceptions/bad-request.exception.mts +0 -28
  132. package/src/exceptions/conflict.exception.mts +0 -31
  133. package/src/exceptions/forbidden.exception.mts +0 -30
  134. package/src/exceptions/http.exception.mts +0 -33
  135. package/src/exceptions/index.mts +0 -7
  136. package/src/exceptions/internal-server-error.exception.mts +0 -33
  137. package/src/exceptions/not-found.exception.mts +0 -33
  138. package/src/exceptions/unauthorized.exception.mts +0 -30
  139. package/src/factories/adapter.factory.mts +0 -20
  140. package/src/factories/endpoint-adapter.factory.mts +0 -21
  141. package/src/factories/http-adapter.factory.mts +0 -20
  142. package/src/factories/index.mts +0 -8
  143. package/src/factories/multipart-adapter.factory.mts +0 -21
  144. package/src/factories/reply.factory.mts +0 -21
  145. package/src/factories/request.factory.mts +0 -21
  146. package/src/factories/stream-adapter.factory.mts +0 -20
  147. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  148. package/src/index.mts +0 -16
  149. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  150. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  151. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  152. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  153. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  154. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  155. package/src/interfaces/adapter-environment.interface.mts +0 -74
  156. package/src/interfaces/can-activate.mts +0 -38
  157. package/src/interfaces/http-header.mts +0 -18
  158. package/src/interfaces/index.mts +0 -11
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin.interface.mts +0 -139
  161. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  162. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  163. package/src/legacy-compat/attribute.factory.mts +0 -351
  164. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  165. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  166. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  167. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  168. package/src/legacy-compat/decorators/index.mts +0 -11
  169. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  170. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  171. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  172. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  173. package/src/legacy-compat/index.mts +0 -57
  174. package/src/logger/README.md +0 -3
  175. package/src/logger/console-logger.service.mts +0 -714
  176. package/src/logger/index.mts +0 -6
  177. package/src/logger/log-levels.mts +0 -21
  178. package/src/logger/logger-service.interface.mts +0 -42
  179. package/src/logger/logger.service.mts +0 -113
  180. package/src/logger/logger.tokens.mts +0 -44
  181. package/src/logger/utils/cli-colors.util.mts +0 -17
  182. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  183. package/src/logger/utils/index.mts +0 -5
  184. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  185. package/src/logger/utils/is-log-level.util.mts +0 -10
  186. package/src/logger/utils/shared.utils.mts +0 -51
  187. package/src/metadata/controller.metadata.mts +0 -72
  188. package/src/metadata/handler.metadata.mts +0 -80
  189. package/src/metadata/index.mts +0 -4
  190. package/src/metadata/module.metadata.mts +0 -108
  191. package/src/metadata/navios-managed.metadata.mts +0 -42
  192. package/src/navios.application.mts +0 -484
  193. package/src/navios.environment.mts +0 -42
  194. package/src/navios.factory.mts +0 -158
  195. package/src/responders/enums/framework-error.enum.mts +0 -38
  196. package/src/responders/enums/index.mts +0 -1
  197. package/src/responders/index.mts +0 -4
  198. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  199. package/src/responders/interfaces/error-response.interface.mts +0 -22
  200. package/src/responders/interfaces/index.mts +0 -3
  201. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  202. package/src/responders/services/error-response-producer.service.mts +0 -143
  203. package/src/responders/services/forbidden-responder.service.mts +0 -77
  204. package/src/responders/services/index.mts +0 -5
  205. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  206. package/src/responders/services/not-found-responder.service.mts +0 -76
  207. package/src/responders/services/validation-error-responder.service.mts +0 -78
  208. package/src/responders/tokens/index.mts +0 -1
  209. package/src/responders/tokens/responder.tokens.mts +0 -84
  210. package/src/services/abstract-handler-adapter.service.mts +0 -366
  211. package/src/services/guard-runner.service.mts +0 -152
  212. package/src/services/index.mts +0 -4
  213. package/src/services/instance-resolver.service.mts +0 -177
  214. package/src/services/module-loader.service.mts +0 -252
  215. package/src/stores/index.mts +0 -1
  216. package/src/stores/request-id.store.mts +0 -85
  217. package/src/testing/index.mts +0 -3
  218. package/src/testing/testing-module.mts +0 -393
  219. package/src/testing/unit-testing-module.mts +0 -298
  220. package/src/tokens/adapter.token.mts +0 -6
  221. package/src/tokens/endpoint-adapter.token.mts +0 -8
  222. package/src/tokens/execution-context.token.mts +0 -9
  223. package/src/tokens/http-adapter.token.mts +0 -8
  224. package/src/tokens/index.mts +0 -10
  225. package/src/tokens/multipart-adapter.token.mts +0 -8
  226. package/src/tokens/navios-options.token.mts +0 -6
  227. package/src/tokens/reply.token.mts +0 -3
  228. package/src/tokens/request.token.mts +0 -3
  229. package/src/tokens/stream-adapter.token.mts +0 -8
  230. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  231. package/src/utils/adapter-supports.util.mts +0 -47
  232. package/src/utils/index.mts +0 -1
  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,524 +0,0 @@
1
- # Application Setup and Configuration
2
-
3
- This guide covers how to set up and configure a Navios application, including application creation, module loading, and server configuration.
4
-
5
- ## Creating a Navios Application
6
-
7
- ### Basic Application Setup
8
-
9
- ```typescript
10
- import { FastifyAdapter } from '@navios/adapter-fastify'
11
- import { NaviosFactory } from '@navios/core'
12
-
13
- import { AppModule } from './app.module'
14
-
15
- async function bootstrap() {
16
- const app = await NaviosFactory.create(AppModule, {
17
- adapter: new FastifyAdapter(),
18
- })
19
-
20
- await app.listen(3000)
21
- console.log('Application is running on http://localhost:3000')
22
- }
23
-
24
- bootstrap()
25
- ```
26
-
27
- ### Application with Multiple Adapters
28
-
29
- ```typescript
30
- import { BunAdapter } from '@navios/adapter-bun'
31
- import { FastifyAdapter } from '@navios/adapter-fastify'
32
- import { NaviosFactory } from '@navios/core'
33
-
34
- async function bootstrap() {
35
- const adapters =
36
- process.env.NODE_ENV === 'production'
37
- ? [new FastifyAdapter()]
38
- : [new BunAdapter(), new FastifyAdapter()]
39
-
40
- const app = await NaviosFactory.create(AppModule, {
41
- adapter: adapters,
42
- })
43
-
44
- await app.listen(3000)
45
- }
46
-
47
- bootstrap()
48
- ```
49
-
50
- ## Application Factory
51
-
52
- The `NaviosFactory` provides methods to create and configure applications:
53
-
54
- ### `NaviosFactory.create()`
55
-
56
- ```typescript
57
- import { NaviosFactory } from '@navios/core'
58
-
59
- const app = await NaviosFactory.create(AppModule, {
60
- adapter: new FastifyAdapter(),
61
- logger: ['error', 'warn', 'log'], // Log levels
62
- // Additional options
63
- })
64
- ```
65
-
66
- ### Factory Options
67
-
68
- ```typescript
69
- interface NaviosApplicationOptions {
70
- adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[]
71
- logger?: LoggerService | LogLevel[] | false
72
- }
73
- ```
74
-
75
- ## Application Module
76
-
77
- The root application module serves as the entry point:
78
-
79
- ```typescript
80
- import { Module } from '@navios/core'
81
-
82
- import { AuthModule } from './auth/auth.module'
83
- import { DatabaseModule } from './database/database.module'
84
- import { UserModule } from './user/user.module'
85
-
86
- @Module({
87
- imports: [DatabaseModule, AuthModule, UserModule],
88
- })
89
- export class AppModule {}
90
- ```
91
-
92
- ## Application Lifecycle
93
-
94
- ### Application Initialization
95
-
96
- ```typescript
97
- async function bootstrap() {
98
- // 1. Create application
99
- const app = await NaviosFactory.create(AppModule, {
100
- adapter: new FastifyAdapter(),
101
- })
102
-
103
- // 2. Configure middleware, CORS, etc.
104
- app.enableCors({
105
- origin: process.env.ALLOWED_ORIGINS?.split(',') || [
106
- 'http://localhost:3000',
107
- ],
108
- })
109
-
110
- app.enableMultipart({
111
- limits: {
112
- fileSize: 10_000_000, // 10MB
113
- },
114
- })
115
-
116
- // 3. Start listening
117
- await app.listen(3000)
118
- }
119
- ```
120
-
121
- ### Graceful Shutdown
122
-
123
- ```typescript
124
- async function bootstrap() {
125
- const app = await NaviosFactory.create(AppModule, {
126
- adapter: new FastifyAdapter(),
127
- })
128
-
129
- await app.listen(3000)
130
-
131
- // Handle graceful shutdown
132
- process.on('SIGTERM', async () => {
133
- console.log('SIGTERM received, shutting down gracefully...')
134
- await app.close()
135
- process.exit(0)
136
- })
137
-
138
- process.on('SIGINT', async () => {
139
- console.log('SIGINT received, shutting down gracefully...')
140
- await app.close()
141
- process.exit(0)
142
- })
143
- }
144
- ```
145
-
146
- ## Environment Configuration
147
-
148
- ### Environment Variables
149
-
150
- ```typescript
151
- // config/environment.ts
152
- export const environment = {
153
- port: parseInt(process.env.PORT || '3000', 10),
154
- nodeEnv: process.env.NODE_ENV || 'development',
155
- database: {
156
- url: process.env.DATABASE_URL || 'postgresql://localhost:5432/navios',
157
- maxConnections: parseInt(process.env.DB_MAX_CONNECTIONS || '10', 10),
158
- },
159
- jwt: {
160
- secret: process.env.JWT_SECRET || 'super-secret',
161
- expiresIn: process.env.JWT_EXPIRES_IN || '1h',
162
- },
163
- cors: {
164
- origin: process.env.CORS_ORIGIN?.split(',') || ['http://localhost:3000'],
165
- },
166
- }
167
- ```
168
-
169
- ### Configuration Service
170
-
171
- ```typescript
172
- import { Injectable } from '@navios/core'
173
-
174
- @Injectable()
175
- export class ConfigService {
176
- private config = new Map()
177
-
178
- constructor() {
179
- this.loadEnvironmentVariables()
180
- }
181
-
182
- get<T>(key: string): T {
183
- return this.config.get(key)
184
- }
185
-
186
- private loadEnvironmentVariables() {
187
- this.config.set('PORT', parseInt(process.env.PORT || '3000', 10))
188
- this.config.set('NODE_ENV', process.env.NODE_ENV || 'development')
189
- this.config.set('DATABASE_URL', process.env.DATABASE_URL)
190
- this.config.set('JWT_SECRET', process.env.JWT_SECRET)
191
- // ... more configuration
192
- }
193
- }
194
-
195
- // Usage in bootstrap
196
- async function bootstrap() {
197
- const app = await NaviosFactory.create(AppModule, {
198
- adapter: new FastifyAdapter(),
199
- })
200
-
201
- const configService = app.getContainer().get(ConfigService)
202
- const port = configService.get<number>('PORT')
203
-
204
- await app.listen(port)
205
- }
206
- ```
207
-
208
- ## CORS Configuration
209
-
210
- Enable Cross-Origin Resource Sharing:
211
-
212
- ```typescript
213
- async function bootstrap() {
214
- const app = await NaviosFactory.create(AppModule, {
215
- adapter: new FastifyAdapter(),
216
- })
217
-
218
- // Basic CORS
219
- app.enableCors()
220
-
221
- // Advanced CORS configuration
222
- app.enableCors({
223
- origin: ['http://localhost:3000', 'https://yourdomain.com'],
224
- methods: ['GET', 'POST', 'PUT', 'DELETE'],
225
- allowedHeaders: ['Content-Type', 'Authorization'],
226
- credentials: true,
227
- })
228
-
229
- await app.listen(3000)
230
- }
231
- ```
232
-
233
- ## Multipart/File Upload Configuration
234
-
235
- Enable file upload support:
236
-
237
- ```typescript
238
- async function bootstrap() {
239
- const app = await NaviosFactory.create(AppModule, {
240
- adapter: new FastifyAdapter(),
241
- })
242
-
243
- app.enableMultipart({
244
- limits: {
245
- fieldNameSize: 100, // Max field name size in bytes
246
- fieldSize: 100, // Max field value size in bytes
247
- fields: 10, // Max number of non-file fields
248
- fileSize: 10_000_000, // Max file size in bytes (10MB)
249
- files: 5, // Max number of file fields
250
- headerPairs: 2000, // Max number of header key=>value pairs
251
- },
252
- })
253
-
254
- await app.listen(3000)
255
- }
256
- ```
257
-
258
- ## Logging Configuration
259
-
260
- ### Custom Logger
261
-
262
- ```typescript
263
- import { LoggerService, LogLevel } from '@navios/core'
264
-
265
- class CustomLogger implements LoggerService {
266
- log(message: string, context?: string) {
267
- console.log(`[${context}] ${message}`)
268
- }
269
-
270
- error(message: string, trace?: string, context?: string) {
271
- console.error(`[${context}] ERROR: ${message}`, trace)
272
- }
273
-
274
- warn(message: string, context?: string) {
275
- console.warn(`[${context}] WARN: ${message}`)
276
- }
277
-
278
- debug(message: string, context?: string) {
279
- if (process.env.DEBUG) {
280
- console.debug(`[${context}] DEBUG: ${message}`)
281
- }
282
- }
283
-
284
- verbose(message: string, context?: string) {
285
- if (process.env.VERBOSE) {
286
- console.log(`[${context}] VERBOSE: ${message}`)
287
- }
288
- }
289
- }
290
-
291
- // Use custom logger
292
- const app = await NaviosFactory.create(AppModule, {
293
- adapter: new FastifyAdapter(),
294
- logger: new CustomLogger(),
295
- })
296
- ```
297
-
298
- ### Log Levels
299
-
300
- ```typescript
301
- const app = await NaviosFactory.create(AppModule, {
302
- adapter: new FastifyAdapter(),
303
- logger: ['error', 'warn', 'log'], // Only these levels will be logged
304
- })
305
-
306
- // Or disable logging
307
- const app = await NaviosFactory.create(AppModule, {
308
- adapter: new FastifyAdapter(),
309
- logger: false,
310
- })
311
- ```
312
-
313
- ## Database Integration
314
-
315
- ### Database Module
316
-
317
- ```typescript
318
- import { Injectable, Module } from '@navios/core'
319
-
320
- import { PrismaClient } from '@prisma/client'
321
-
322
- @Injectable()
323
- export class DatabaseService extends PrismaClient {
324
- constructor() {
325
- super({
326
- datasources: {
327
- db: {
328
- url: process.env.DATABASE_URL,
329
- },
330
- },
331
- })
332
- }
333
-
334
- async onModuleInit() {
335
- await this.$connect()
336
- }
337
-
338
- async onModuleDestroy() {
339
- await this.$disconnect()
340
- }
341
- }
342
-
343
- @Module({
344
- providers: [DatabaseService],
345
- exports: [DatabaseService],
346
- })
347
- export class DatabaseModule {}
348
- ```
349
-
350
- ## Health Checks
351
-
352
- Add health check endpoints using `@navios/builder`:
353
-
354
- ```typescript
355
- // api/health.ts
356
- import { builder } from '@navios/builder'
357
-
358
- import { z } from 'zod'
359
-
360
- export const api = builder()
361
-
362
- export const healthEndpoint = api.declareEndpoint({
363
- method: 'GET',
364
- url: '/health',
365
- responseSchema: z.object({
366
- status: z.string(),
367
- timestamp: z.string(),
368
- uptime: z.number(),
369
- }),
370
- })
371
-
372
- export const readinessEndpoint = api.declareEndpoint({
373
- method: 'GET',
374
- url: '/health/ready',
375
- responseSchema: z.object({
376
- ready: z.boolean(),
377
- checks: z.record(z.string(), z.boolean()),
378
- }),
379
- })
380
- ```
381
-
382
- ```typescript
383
- import type { EndpointParams } from '@navios/core'
384
-
385
- import { Controller, Endpoint } from '@navios/core'
386
-
387
- import { healthEndpoint, readinessEndpoint } from '../api/health.js'
388
-
389
- // controllers/health.controller.ts
390
-
391
- @Controller()
392
- export class HealthController {
393
- @Endpoint(healthEndpoint)
394
- async getHealth(params: EndpointParams<typeof healthEndpoint>) {
395
- return {
396
- status: 'ok',
397
- timestamp: new Date().toISOString(),
398
- uptime: process.uptime(),
399
- }
400
- }
401
-
402
- @Endpoint(readinessEndpoint)
403
- async getReadiness(params: EndpointParams<typeof readinessEndpoint>) {
404
- // Check database connectivity, external services, etc.
405
- try {
406
- await this.databaseService.isConnected()
407
- return { status: 'ready' }
408
- } catch (error) {
409
- throw new InternalServerErrorException('Service not ready')
410
- }
411
- }
412
- }
413
- ```
414
-
415
- ## Production Configuration
416
-
417
- ### Production Bootstrap
418
-
419
- ```typescript
420
- import { defineFastifyEnvironment } from '@navios/adapter-fastify'
421
- import { NaviosFactory } from '@navios/core'
422
-
423
- import { AppModule } from './app.module'
424
-
425
- async function bootstrap() {
426
- const app = await NaviosFactory.create(AppModule, {
427
- adapter: defineFastifyEnvironment({
428
- logger: process.env.NODE_ENV === 'production',
429
- trustProxy: true,
430
- }),
431
- logger:
432
- process.env.NODE_ENV === 'production'
433
- ? ['error', 'warn', 'log']
434
- : ['error', 'warn', 'log', 'debug', 'verbose'],
435
- })
436
-
437
- // Production middleware
438
- if (process.env.NODE_ENV === 'production') {
439
- app.enableCors({
440
- origin: process.env.ALLOWED_ORIGINS?.split(','),
441
- credentials: true,
442
- })
443
- } else {
444
- app.enableCors() // Allow all origins in development
445
- }
446
-
447
- const port = process.env.PORT || 3000
448
- await app.listen({
449
- port: parseInt(port, 10),
450
- host: '0.0.0.0',
451
- })
452
-
453
- console.log(`🚀 Application is running on port ${port}`)
454
- }
455
-
456
- bootstrap().catch((error) => {
457
- console.error('Failed to start application:', error)
458
- process.exit(1)
459
- })
460
- ```
461
-
462
- ### Docker Configuration
463
-
464
- ```dockerfile
465
- FROM node:18-alpine
466
-
467
- WORKDIR /app
468
-
469
- COPY package*.json ./
470
- RUN npm ci --only=production
471
-
472
- COPY . .
473
- RUN npm run build
474
-
475
- EXPOSE 3000
476
-
477
- USER node
478
-
479
- CMD ["node", "dist/main.js"]
480
- ```
481
-
482
- ### Environment Variables for Production
483
-
484
- ```bash
485
- # .env.production
486
- NODE_ENV=production
487
- PORT=3000
488
- DATABASE_URL=postgresql://user:password@db:5432/navios_prod
489
- LOG_LEVEL=error,warn,log
490
- ```
491
-
492
- ## Testing Configuration
493
-
494
- ### Test Application Setup
495
-
496
- ```typescript
497
- import { Test } from '@navios/testing'
498
-
499
- import { AppModule } from '../src/app.module'
500
-
501
- describe('Application', () => {
502
- let app: any
503
-
504
- beforeAll(async () => {
505
- const moduleRef = await Test.createTestingModule({
506
- imports: [AppModule],
507
- })
508
- .overrideProvider(DatabaseService)
509
- .useValue(mockDatabaseService)
510
- .compile()
511
-
512
- app = moduleRef.createNaviosApplication()
513
- await app.init()
514
- })
515
-
516
- afterAll(async () => {
517
- await app.close()
518
- })
519
-
520
- it('should be defined', () => {
521
- expect(app).toBeDefined()
522
- })
523
- })
524
- ```