@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
package/docs/README.md DELETED
@@ -1,316 +0,0 @@
1
- # Navios Documentation
2
-
3
- ## Table of Contents
4
-
5
- ### Getting Started
6
-
7
- - [Quick Start Guide](./quick-start.md) - Get up and running quickly
8
- - [Application Setup and Configuration](./application-setup.md) - Comprehensive setup guide
9
-
10
- ### Core Concepts
11
-
12
- - [Modules](./modules.md) - Application organization and structure
13
- - [Controllers](./controllers.md) - Request handlers and routing
14
- - [Endpoints](./endpoints.md) - HTTP route definitions and configuration
15
- - [Services and Dependency Injection](./services.md) - Business logic and DI system
16
- - [Guards](./guards.md) - Authentication, authorization, and request filtering
17
- - [Exception Handling](./exceptions.md) - Error handling and HTTP exceptions
18
- - [Attribute System](./attributes.md) - Metadata and custom decorators
19
- - [Legacy-Compatible Decorators](./legacy-compat.md) - Using Navios with TypeScript experimental decorators
20
-
21
- ### Infrastructure
22
-
23
- - [HTTP Server Adapters](./adapters.md) - Fastify, Bun, and custom adapters
24
-
25
- ### Advanced Topics
26
-
27
- - [Testing Guide](./testing.md) - Unit, integration, and E2E testing strategies
28
- - Performance Optimization
29
- - Deployment Patterns
30
- - Plugin Development
31
-
32
- ---
33
-
34
- ## Introduction
35
-
36
- Navios is a framework for building Type-Safe HTTP servers with TypeScript. It uses TypeScript and Navios builder to create servers with a well-defined structure, emphasizing type safety, validation, and developer experience.
37
-
38
- The framework is adapter-based, allowing you to choose the underlying HTTP server implementation that best fits your deployment environment and performance requirements.
39
-
40
- > **Important**: Always use `@navios/builder` to define your API endpoints instead of passing configuration objects directly to decorators. This ensures better type safety, maintainability, and access to advanced features like client generation.
41
-
42
- ## Architecture Overview
43
-
44
- Navios follows a modular architecture with the following key components:
45
-
46
- - **Core Framework** (`@navios/core`) - Provides the main framework features
47
- - **Adapters** - HTTP server implementations (Fastify, Bun)
48
- - **Builder** (`@navios/builder`) - Type-safe API definition and client generation
49
- - **Dependency Injection** (`@navios/di`) - Powerful DI container
50
- - **Additional Packages** - JWT, scheduling, React Query integration, and more
51
-
52
- ## HTTP Server Adapters
53
-
54
- Navios requires an HTTP adapter to function as a server. The adapter pattern allows Navios to support different runtimes and frameworks while maintaining a consistent API.
55
-
56
- ### Prerequisites
57
-
58
- **Important**: To use Navios as an HTTP server, you **must** install one of the supported adapters:
59
-
60
- ```bash
61
- # For Fastify adapter (Node.js)
62
- npm install @navios/adapter-fastify
63
-
64
- # OR for Bun adapter (Bun runtime)
65
- npm install @navios/adapter-bun
66
- ```
67
-
68
- ### Fastify Adapter
69
-
70
- The Fastify adapter (`@navios/adapter-fastify`) integrates Navios with the [Fastify](https://www.fastify.io/) web framework.
71
-
72
- #### Features:
73
-
74
- - High performance HTTP server
75
- - Rich ecosystem of plugins
76
- - Full Node.js compatibility
77
- - Built-in request/response validation
78
- - Comprehensive middleware support
79
- - Production-ready with extensive documentation
80
-
81
- #### Usage:
82
-
83
- ```ts
84
- import { defineFastifyEnvironment } from '@navios/adapter-fastify'
85
- import { NaviosFactory } from '@navios/core'
86
-
87
- import { AppModule } from './app.module.js'
88
-
89
- async function bootstrap() {
90
- const app = await NaviosFactory.create(AppModule, {
91
- adapter: defineFastifyEnvironment(),
92
- })
93
-
94
- // Configure CORS
95
- app.enableCors({
96
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
97
- })
98
-
99
- // Enable multipart support for file uploads
100
- app.enableMultipart({})
101
-
102
- await app.init()
103
- await app.listen({ port: 3000, host: '0.0.0.0' })
104
- }
105
-
106
- bootstrap()
107
- ```
108
-
109
- #### Dependencies:
110
-
111
- The Fastify adapter requires `fastify` as a peer dependency:
112
-
113
- ```json
114
- {
115
- "dependencies": {
116
- "@navios/core": "^0.5.0",
117
- "@navios/adapter-fastify": "^0.5.0",
118
- "fastify": "^5.6.0"
119
- }
120
- }
121
- ```
122
-
123
- ### Bun Adapter
124
-
125
- The Bun adapter (`@navios/adapter-bun`) integrates Navios with [Bun's](https://bun.sh/) native HTTP server.
126
-
127
- #### Features:
128
-
129
- - Optimized for Bun runtime performance
130
- - Native HTTP server implementation
131
- - Lightweight with minimal overhead
132
- - Fast startup times
133
- - Efficient memory usage
134
-
135
- #### Usage:
136
-
137
- ```ts
138
- import { defineBunEnvironment } from '@navios/adapter-bun'
139
- import { NaviosFactory } from '@navios/core'
140
-
141
- import { AppModule } from './app.module.js'
142
-
143
- async function bootstrap() {
144
- const app = await NaviosFactory.create(AppModule, {
145
- adapter: defineBunEnvironment(),
146
- })
147
-
148
- // Configure CORS
149
- app.enableCors({
150
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
151
- })
152
-
153
- // Enable multipart support
154
- app.enableMultipart({})
155
-
156
- await app.init()
157
- await app.listen({ port: 3000, host: '0.0.0.0' })
158
- }
159
-
160
- bootstrap()
161
- ```
162
-
163
- #### Dependencies:
164
-
165
- The Bun adapter works with Bun runtime and requires no additional HTTP server dependencies:
166
-
167
- ```json
168
- {
169
- "dependencies": {
170
- "@navios/core": "^0.5.0",
171
- "@navios/adapter-bun": "^0.5.0"
172
- }
173
- }
174
- ```
175
-
176
- ## Adapter Selection Guide
177
-
178
- Choose the appropriate adapter based on your deployment environment and requirements:
179
-
180
- | Adapter | Runtime | Performance | Ecosystem | Use Case |
181
- | ------- | ------- | ----------- | --------- | --------------------------------------------- |
182
- | Fastify | Node.js | High | Rich | Production Node.js apps, need Fastify plugins |
183
- | Bun | Bun | Very High | Growing | Performance-critical apps, Bun runtime |
184
-
185
- ### When to use Fastify Adapter:
186
-
187
- - Deploying to Node.js environments
188
- - Need access to Fastify's extensive plugin ecosystem
189
- - Require compatibility with existing Node.js tooling
190
- - Working with teams familiar with Express/Fastify patterns
191
- - Need mature production support and documentation
192
-
193
- ### When to use Bun Adapter:
194
-
195
- - Running on Bun runtime
196
- - Performance is critical
197
- - Want faster startup times
198
- - Prefer minimal dependencies
199
- - Building new applications without legacy constraints
200
-
201
- ## Error Handling
202
-
203
- Both adapters provide consistent error handling through Navios's exception system. Framework-level errors (validation errors, guard rejections, not found routes, unhandled errors) use **RFC 7807 Problem Details** format for standardized, machine-readable error responses. HttpException responses maintain backward compatibility with the original format.
204
-
205
- ```ts
206
- import { BadRequestException, NotFoundException } from '@navios/core'
207
-
208
- @Controller()
209
- export class UserController {
210
- @Endpoint(getUserEndpoint)
211
- async getUser(request: EndpointParams<typeof getUserEndpoint>) {
212
- const { id } = request
213
-
214
- if (!id) {
215
- throw new BadRequestException('User ID is required')
216
- }
217
-
218
- const user = await this.userService.findById(id)
219
- if (!user) {
220
- throw new NotFoundException('User not found')
221
- }
222
-
223
- return user
224
- }
225
- }
226
- ```
227
-
228
- For more information on error handling, including custom error responders and RFC 7807 Problem Details, see the [Error Handling Guide](../../../apps/docs/docs/server/guides/error-handling.md).
229
-
230
- ## Configuration
231
-
232
- Both adapters support the same Navios configuration options:
233
-
234
- ```ts
235
- const app = await NaviosFactory.create(AppModule, {
236
- adapter: defineFastifyEnvironment(), // or defineBunEnvironment()
237
- logger: ['error', 'warn', 'log'], // Optional: configure logging levels
238
- })
239
-
240
- // Global configuration
241
- app.setGlobalPrefix('/api/v1')
242
- app.enableCors({
243
- origin: ['http://localhost:3000'],
244
- methods: ['GET', 'POST', 'PUT', 'DELETE'],
245
- credentials: true,
246
- })
247
-
248
- // Enable file uploads
249
- app.enableMultipart({
250
- limits: {
251
- fileSize: 1024 * 1024 * 10, // 10MB
252
- },
253
- })
254
- ```
255
-
256
- ## Advanced Usage
257
-
258
- ### Custom Adapter Configuration
259
-
260
- You can pass configuration options to the underlying server:
261
-
262
- ```ts
263
- // Fastify-specific configuration
264
- const app = await NaviosFactory.create(AppModule, {
265
- adapter: defineFastifyEnvironment({
266
- // Fastify instance options can be configured here if needed
267
- }),
268
- })
269
-
270
- // Bun-specific configuration
271
- const app = await NaviosFactory.create(AppModule, {
272
- adapter: defineBunEnvironment({
273
- // Bun server options can be configured here if needed
274
- }),
275
- })
276
- ```
277
-
278
- ### Multiple Adapters
279
-
280
- You can also configure multiple adapters if needed (advanced use case):
281
-
282
- ```ts
283
- const app = await NaviosFactory.create(AppModule, {
284
- adapter: [
285
- defineFastifyEnvironment(),
286
- // Additional adapters...
287
- ],
288
- })
289
- ```
290
-
291
- ## Migration Between Adapters
292
-
293
- Switching between adapters is straightforward and requires minimal code changes:
294
-
295
- 1. Install the new adapter package
296
- 2. Update the import statement
297
- 3. Change the adapter function call
298
- 4. Update any adapter-specific configurations
299
-
300
- ```ts
301
- // From Fastify
302
-
303
- // To Bun
304
- import { defineBunEnvironment } from '@navios/adapter-bun'
305
- import { defineFastifyEnvironment } from '@navios/adapter-fastify'
306
-
307
- const app = await NaviosFactory.create(AppModule, {
308
- adapter: defineFastifyEnvironment(),
309
- })
310
-
311
- const app = await NaviosFactory.create(AppModule, {
312
- adapter: defineBunEnvironment(),
313
- })
314
- ```
315
-
316
- Your controllers, services, and application logic remain unchanged.
package/docs/adapters.md DELETED
@@ -1,308 +0,0 @@
1
- # Navios HTTP Adapters
2
-
3
- This document provides detailed information about Navios HTTP adapters, their implementation, and usage patterns.
4
-
5
- ## Overview
6
-
7
- Navios uses an adapter pattern to provide HTTP server functionality. Adapters are responsible for:
8
-
9
- - Binding HTTP requests and responses to Navios's internal format
10
- - Providing server lifecycle management (start, stop, graceful shutdown)
11
- - Handling server-specific features (middleware, plugins, etc.)
12
- - Abstracting runtime-specific implementations
13
-
14
- ## Adapter Architecture
15
-
16
- Each adapter implements the following core interfaces:
17
-
18
- ### HttpAdapterToken
19
-
20
- Provides the main HTTP server functionality:
21
-
22
- - Server initialization and configuration
23
- - Request/response handling
24
- - Server lifecycle management
25
-
26
- ### EndpointAdapterToken
27
-
28
- Handles endpoint-specific functionality:
29
-
30
- - Route registration
31
- - Request parameter extraction
32
- - Response formatting
33
-
34
- ### StreamAdapterToken
35
-
36
- Manages streaming responses:
37
-
38
- - File streaming
39
- - Server-sent events
40
- - Large response handling
41
-
42
- ### MultipartAdapterToken
43
-
44
- Handles multipart requests:
45
-
46
- - File uploads
47
- - Form data processing
48
- - Binary data handling
49
-
50
- ## Available Adapters
51
-
52
- ### @navios/adapter-fastify
53
-
54
- Built on [Fastify](https://www.fastify.io/), providing a robust HTTP server with excellent performance and a rich ecosystem.
55
-
56
- #### Installation
57
-
58
- ```bash
59
- npm install @navios/adapter-fastify fastify
60
- ```
61
-
62
- #### Basic Usage
63
-
64
- ```ts
65
- import { defineFastifyEnvironment } from '@navios/adapter-fastify'
66
- import { NaviosFactory } from '@navios/core'
67
-
68
- const app = await NaviosFactory.create(AppModule, {
69
- adapter: defineFastifyEnvironment(),
70
- })
71
- ```
72
-
73
- #### Features
74
-
75
- - **High Performance**: Fastify is one of the fastest Node.js web frameworks
76
- - **Schema-based Validation**: Built-in JSON Schema validation
77
- - **Rich Ecosystem**: Extensive plugin system
78
- - **TypeScript Support**: Full TypeScript integration
79
- - **Production Ready**: Battle-tested in production environments
80
-
81
- #### Fastify-specific Features
82
-
83
- ##### Hooks Integration
84
-
85
- The adapter integrates with Fastify's hook system:
86
-
87
- ```ts
88
- // Access to underlying Fastify instance (if needed)
89
- const fastifyInstance = app.getServer()
90
-
91
- // Add Fastify hooks
92
- fastifyInstance.addHook('preHandler', async (request, reply) => {
93
- // Custom pre-handler logic
94
- })
95
- ```
96
-
97
- ##### Plugin System
98
-
99
- You can register Fastify plugins:
100
-
101
- ```ts
102
- import fastifyStatic from '@fastify/static'
103
-
104
- const fastifyInstance = app.getServer()
105
- await fastifyInstance.register(fastifyStatic, {
106
- root: path.join(__dirname, 'public'),
107
- prefix: '/public/',
108
- })
109
- ```
110
-
111
- #### Configuration Options
112
-
113
- ```ts
114
- const app = await NaviosFactory.create(AppModule, {
115
- adapter: defineFastifyEnvironment({
116
- // Fastify server options
117
- trustProxy: true,
118
- }),
119
- })
120
- ```
121
-
122
- ### @navios/adapter-bun
123
-
124
- Built for [Bun](https://bun.sh/) runtime, providing optimal performance and native integration.
125
-
126
- #### Installation
127
-
128
- ```bash
129
- npm install @navios/adapter-bun
130
- ```
131
-
132
- #### Basic Usage
133
-
134
- ```ts
135
- import { defineBunEnvironment } from '@navios/adapter-bun'
136
- import { NaviosFactory } from '@navios/core'
137
-
138
- const app = await NaviosFactory.create(AppModule, {
139
- adapter: defineBunEnvironment(),
140
- })
141
- ```
142
-
143
- #### Features
144
-
145
- - **Native Performance**: Built on Bun's native HTTP server
146
- - **Fast Startup**: Optimized for quick application startup
147
- - **Memory Efficient**: Lower memory footprint
148
- - **Modern Runtime**: Takes advantage of Bun's modern JavaScript features
149
-
150
- #### Bun-specific Features
151
-
152
- #### Configuration Options
153
-
154
- ```ts
155
- const app = await NaviosFactory.create(AppModule, {
156
- adapter: defineBunEnvironment({
157
- // Bun server options
158
- development: process.env.NODE_ENV === 'development',
159
- }),
160
- })
161
- ```
162
-
163
- ## Adapter Comparison
164
-
165
- | Feature | Fastify Adapter | Bun Adapter |
166
- | ------------------ | ---------------------- | ----------- |
167
- | **Runtime** | Node.js | Bun |
168
- | **Performance** | High | Very High |
169
- | **Memory Usage** | Moderate | Low |
170
- | **Startup Time** | Fast | Very Fast |
171
- | **Ecosystem** | Rich (Fastify plugins) | Growing |
172
- | **WebSocket** | Via plugins | Native |
173
- | **File Serving** | Via plugins | Native |
174
- | **Production Use** | Mature | Emerging |
175
- | **Community** | Large | Growing |
176
-
177
- ## Creating Custom Adapters
178
-
179
- To create a custom adapter, implement the required tokens:
180
-
181
- ```ts
182
- import {
183
- EndpointAdapterToken,
184
- HttpAdapterToken,
185
- MultipartAdapterToken,
186
- StreamAdapterToken,
187
- } from '@navios/core'
188
-
189
- export function defineCustomEnvironment() {
190
- const httpTokens = new Map([
191
- [HttpAdapterToken, CustomHttpAdapter],
192
- [EndpointAdapterToken, CustomEndpointAdapter],
193
- [StreamAdapterToken, CustomStreamAdapter],
194
- [MultipartAdapterToken, CustomMultipartAdapter],
195
- ])
196
-
197
- return { httpTokens }
198
- }
199
- ```
200
-
201
- ### HttpAdapter Implementation
202
-
203
- ```ts
204
- import { AbstractHttpAdapter } from '@navios/core'
205
- import { Injectable } from '@navios/di'
206
-
207
- @Injectable()
208
- export class CustomHttpAdapter extends AbstractHttpAdapter {
209
- async init() {
210
- // Initialize your HTTP server
211
- }
212
-
213
- async listen(options: any) {
214
- // Start listening for requests
215
- }
216
-
217
- async close() {
218
- // Graceful shutdown
219
- }
220
-
221
- // Implement other required methods...
222
- }
223
- ```
224
-
225
- ## Best Practices
226
-
227
- ### Adapter Selection
228
-
229
- 1. **Choose based on runtime**: Use Fastify for Node.js, Bun for Bun runtime
230
- 2. **Consider ecosystem needs**: Fastify has more plugins available
231
- 3. **Performance requirements**: Bun offers better raw performance
232
- 4. **Team expertise**: Consider your team's familiarity with the underlying technology
233
-
234
- ### Configuration
235
-
236
- 1. **Environment-specific settings**: Configure adapters differently for dev/prod
237
- 2. **Security**: Enable appropriate security features for production
238
- 3. **Monitoring**: Set up proper logging and metrics collection
239
- 4. **Resource limits**: Configure appropriate timeouts and limits
240
-
241
- ### Error Handling
242
-
243
- 1. **Consistent error responses**: Use Navios exceptions for consistent API responses
244
- 2. **Logging**: Ensure proper error logging across adapters
245
- 3. **Graceful degradation**: Handle adapter-specific errors appropriately
246
-
247
- ### Performance Optimization
248
-
249
- 1. **Connection pooling**: Configure appropriate connection limits
250
- 2. **Caching**: Use adapter-specific caching when available
251
- 3. **Compression**: Enable response compression for better performance
252
- 4. **Static files**: Use efficient static file serving strategies
253
-
254
- ## Troubleshooting
255
-
256
- ### Common Issues
257
-
258
- #### Fastify Adapter
259
-
260
- - **Plugin conflicts**: Ensure Fastify plugins are compatible
261
- - **Schema validation**: Check JSON schema definitions for validation errors
262
- - **Memory leaks**: Monitor for unclosed connections or resources
263
-
264
- #### Bun Adapter
265
-
266
- - **Runtime compatibility**: Ensure code is compatible with Bun runtime
267
- - **Module resolution**: Check import/export statements work with Bun
268
- - **Native features**: Verify Bun-specific features are used correctly
269
-
270
- ### Debugging
271
-
272
- 1. **Enable logging**: Use appropriate log levels for debugging
273
- 2. **Check adapter health**: Monitor adapter-specific metrics
274
- 3. **Validate configuration**: Ensure adapter configuration is correct
275
- 4. **Test isolation**: Test adapters in isolation when troubleshooting
276
-
277
- ## Migration Guide
278
-
279
- ### From Express to Navios
280
-
281
- If migrating from Express, the Fastify adapter provides the most familiar experience:
282
-
283
- ```ts
284
- // Express-style (before)
285
- app.get('/users/:id', (req, res) => {
286
- res.json({ id: req.params.id })
287
- })
288
-
289
- // Navios with Fastify adapter (after)
290
- @Controller()
291
- export class UserController {
292
- @Endpoint(getUserEndpoint)
293
- async getUser(request: EndpointParams<typeof getUserEndpoint>) {
294
- return { id: request.id }
295
- }
296
- }
297
- ```
298
-
299
- ### Between Adapters
300
-
301
- Switching adapters is straightforward:
302
-
303
- 1. Update dependencies
304
- 2. Change the adapter import and function call
305
- 3. Update any adapter-specific configurations
306
- 4. Test thoroughly in your specific environment
307
-
308
- The rest of your application code remains unchanged due to Navios's adapter abstraction.