@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,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
- ```