@navios/core 0.5.1 → 0.7.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 (277) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +18 -1
  3. package/docs/README.md +1 -0
  4. package/docs/legacy-compat.md +320 -0
  5. package/docs/testing.md +140 -17
  6. package/lib/index-BFwNx9WQ.d.cts +1951 -0
  7. package/lib/index-BFwNx9WQ.d.cts.map +1 -0
  8. package/lib/index-D657ijFO.d.mts +1951 -0
  9. package/lib/index-D657ijFO.d.mts.map +1 -0
  10. package/lib/index.cjs +157 -0
  11. package/lib/index.d.cts +3 -0
  12. package/lib/index.d.mts +3 -188
  13. package/lib/index.mjs +4 -1439
  14. package/lib/legacy-compat/index.cjs +315 -0
  15. package/lib/legacy-compat/index.cjs.map +1 -0
  16. package/lib/legacy-compat/index.d.cts +219 -0
  17. package/lib/legacy-compat/index.d.cts.map +1 -0
  18. package/lib/legacy-compat/index.d.mts +219 -0
  19. package/lib/legacy-compat/index.d.mts.map +1 -0
  20. package/lib/legacy-compat/index.mjs +308 -0
  21. package/lib/legacy-compat/index.mjs.map +1 -0
  22. package/lib/src-Cb1aTjl0.cjs +5710 -0
  23. package/lib/src-Cb1aTjl0.cjs.map +1 -0
  24. package/lib/src-DzPY5s6d.mjs +5353 -0
  25. package/lib/src-DzPY5s6d.mjs.map +1 -0
  26. package/lib/testing/index.cjs +106 -0
  27. package/lib/testing/index.cjs.map +1 -0
  28. package/lib/testing/index.d.cts +156 -0
  29. package/lib/testing/index.d.cts.map +1 -0
  30. package/lib/testing/index.d.mts +156 -0
  31. package/lib/testing/index.d.mts.map +1 -0
  32. package/lib/testing/index.mjs +100 -0
  33. package/lib/testing/index.mjs.map +1 -0
  34. package/lib/use-guards.decorator-DdvUhB03.cjs +622 -0
  35. package/lib/use-guards.decorator-DdvUhB03.cjs.map +1 -0
  36. package/lib/use-guards.decorator-kZ3lNK8v.mjs +454 -0
  37. package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +1 -0
  38. package/package.json +26 -6
  39. package/project.json +2 -2
  40. package/src/attribute.factory.d.mts +175 -0
  41. package/src/attribute.factory.d.mts.map +1 -0
  42. package/src/attribute.factory.mts +154 -0
  43. package/src/config/config-service.interface.d.mts +39 -0
  44. package/src/config/config-service.interface.d.mts.map +1 -0
  45. package/src/config/config-service.interface.mts +31 -0
  46. package/src/config/config.provider.d.mts +46 -0
  47. package/src/config/config.provider.d.mts.map +1 -0
  48. package/src/config/config.provider.mts +36 -0
  49. package/src/config/config.service.d.mts +108 -0
  50. package/src/config/config.service.d.mts.map +1 -0
  51. package/src/config/config.service.mts +94 -4
  52. package/src/config/index.d.mts +6 -0
  53. package/src/config/index.d.mts.map +1 -0
  54. package/src/config/types.d.mts +13 -0
  55. package/src/config/types.d.mts.map +1 -0
  56. package/src/config/utils/helpers.d.mts +3 -0
  57. package/src/config/utils/helpers.d.mts.map +1 -0
  58. package/src/config/utils/index.d.mts +2 -0
  59. package/src/config/utils/index.d.mts.map +1 -0
  60. package/src/decorators/controller.decorator.d.mts +33 -0
  61. package/src/decorators/controller.decorator.d.mts.map +1 -0
  62. package/src/decorators/controller.decorator.mts +28 -0
  63. package/src/decorators/endpoint.decorator.d.mts +89 -0
  64. package/src/decorators/endpoint.decorator.d.mts.map +1 -0
  65. package/src/decorators/endpoint.decorator.mts +76 -0
  66. package/src/decorators/header.decorator.d.mts +22 -0
  67. package/src/decorators/header.decorator.d.mts.map +1 -0
  68. package/src/decorators/header.decorator.mts +19 -0
  69. package/src/decorators/http-code.decorator.d.mts +22 -0
  70. package/src/decorators/http-code.decorator.d.mts.map +1 -0
  71. package/src/decorators/http-code.decorator.mts +20 -0
  72. package/src/decorators/index.d.mts +9 -0
  73. package/src/decorators/index.d.mts.map +1 -0
  74. package/src/decorators/module.decorator.d.mts +42 -0
  75. package/src/decorators/module.decorator.d.mts.map +1 -0
  76. package/src/decorators/module.decorator.mts +34 -0
  77. package/src/decorators/multipart.decorator.d.mts +54 -0
  78. package/src/decorators/multipart.decorator.d.mts.map +1 -0
  79. package/src/decorators/multipart.decorator.mts +41 -0
  80. package/src/decorators/stream.decorator.d.mts +42 -0
  81. package/src/decorators/stream.decorator.d.mts.map +1 -0
  82. package/src/decorators/stream.decorator.mts +33 -0
  83. package/src/decorators/use-guards.decorator.d.mts +33 -0
  84. package/src/decorators/use-guards.decorator.d.mts.map +1 -0
  85. package/src/decorators/use-guards.decorator.mts +29 -0
  86. package/src/exceptions/bad-request.exception.d.mts +26 -0
  87. package/src/exceptions/bad-request.exception.d.mts.map +1 -0
  88. package/src/exceptions/bad-request.exception.mts +21 -0
  89. package/src/exceptions/conflict.exception.d.mts +29 -0
  90. package/src/exceptions/conflict.exception.d.mts.map +1 -0
  91. package/src/exceptions/conflict.exception.mts +24 -0
  92. package/src/exceptions/forbidden.exception.d.mts +28 -0
  93. package/src/exceptions/forbidden.exception.d.mts.map +1 -0
  94. package/src/exceptions/forbidden.exception.mts +23 -0
  95. package/src/exceptions/http.exception.d.mts +33 -0
  96. package/src/exceptions/http.exception.d.mts.map +1 -0
  97. package/src/exceptions/http.exception.mts +26 -0
  98. package/src/exceptions/index.d.mts +8 -0
  99. package/src/exceptions/index.d.mts.map +1 -0
  100. package/src/exceptions/internal-server-error.exception.d.mts +31 -0
  101. package/src/exceptions/internal-server-error.exception.d.mts.map +1 -0
  102. package/src/exceptions/internal-server-error.exception.mts +26 -0
  103. package/src/exceptions/not-found.exception.d.mts +30 -0
  104. package/src/exceptions/not-found.exception.d.mts.map +1 -0
  105. package/src/exceptions/not-found.exception.mts +23 -0
  106. package/src/exceptions/unauthorized.exception.d.mts +28 -0
  107. package/src/exceptions/unauthorized.exception.d.mts.map +1 -0
  108. package/src/exceptions/unauthorized.exception.mts +23 -0
  109. package/src/factories/endpoint-adapter.factory.d.mts +6 -0
  110. package/src/factories/endpoint-adapter.factory.d.mts.map +1 -0
  111. package/src/factories/http-adapter.factory.d.mts +6 -0
  112. package/src/factories/http-adapter.factory.d.mts.map +1 -0
  113. package/src/factories/index.d.mts +8 -0
  114. package/src/factories/index.d.mts.map +1 -0
  115. package/src/factories/index.mts +1 -0
  116. package/src/factories/multipart-adapter.factory.d.mts +6 -0
  117. package/src/factories/multipart-adapter.factory.d.mts.map +1 -0
  118. package/src/factories/reply.factory.d.mts +6 -0
  119. package/src/factories/reply.factory.d.mts.map +1 -0
  120. package/src/factories/request.factory.d.mts +6 -0
  121. package/src/factories/request.factory.d.mts.map +1 -0
  122. package/src/factories/stream-adapter.factory.d.mts +6 -0
  123. package/src/factories/stream-adapter.factory.d.mts.map +1 -0
  124. package/src/factories/xml-stream-adapter.factory.d.mts +6 -0
  125. package/src/factories/xml-stream-adapter.factory.d.mts.map +1 -0
  126. package/src/factories/xml-stream-adapter.factory.mts +20 -0
  127. package/src/index.d.mts +15 -0
  128. package/src/index.d.mts.map +1 -0
  129. package/src/index.mts +1 -0
  130. package/src/interfaces/abstract-execution-context.inteface.d.mts +44 -0
  131. package/src/interfaces/abstract-execution-context.inteface.d.mts.map +1 -0
  132. package/src/interfaces/abstract-execution-context.inteface.mts +35 -0
  133. package/src/interfaces/abstract-http-adapter.interface.d.mts +15 -0
  134. package/src/interfaces/abstract-http-adapter.interface.d.mts.map +1 -0
  135. package/src/interfaces/abstract-http-cors-options.interface.d.mts +58 -0
  136. package/src/interfaces/abstract-http-cors-options.interface.d.mts.map +1 -0
  137. package/src/interfaces/abstract-http-handler-adapter.interface.d.mts +7 -0
  138. package/src/interfaces/abstract-http-handler-adapter.interface.d.mts.map +1 -0
  139. package/src/interfaces/abstract-http-handler-adapter.interface.mts +2 -2
  140. package/src/interfaces/abstract-http-listen-options.interface.d.mts +5 -0
  141. package/src/interfaces/abstract-http-listen-options.interface.d.mts.map +1 -0
  142. package/src/interfaces/can-activate.d.mts +36 -0
  143. package/src/interfaces/can-activate.d.mts.map +1 -0
  144. package/src/interfaces/can-activate.mts +31 -0
  145. package/src/interfaces/http-header.d.mts +10 -0
  146. package/src/interfaces/http-header.d.mts.map +1 -0
  147. package/src/interfaces/index.d.mts +9 -0
  148. package/src/interfaces/index.d.mts.map +1 -0
  149. package/src/interfaces/navios-module.d.mts +29 -0
  150. package/src/interfaces/navios-module.d.mts.map +1 -0
  151. package/src/interfaces/navios-module.mts +25 -0
  152. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +420 -0
  153. package/src/legacy-compat/__type-tests__/tsconfig.json +15 -0
  154. package/src/legacy-compat/context-compat.d.mts +19 -0
  155. package/src/legacy-compat/context-compat.d.mts.map +1 -0
  156. package/src/legacy-compat/context-compat.mts +93 -0
  157. package/src/legacy-compat/decorators/controller.decorator.d.mts +21 -0
  158. package/src/legacy-compat/decorators/controller.decorator.d.mts.map +1 -0
  159. package/src/legacy-compat/decorators/controller.decorator.mts +31 -0
  160. package/src/legacy-compat/decorators/endpoint.decorator.d.mts +33 -0
  161. package/src/legacy-compat/decorators/endpoint.decorator.d.mts.map +1 -0
  162. package/src/legacy-compat/decorators/endpoint.decorator.mts +99 -0
  163. package/src/legacy-compat/decorators/header.decorator.d.mts +24 -0
  164. package/src/legacy-compat/decorators/header.decorator.d.mts.map +1 -0
  165. package/src/legacy-compat/decorators/header.decorator.mts +42 -0
  166. package/src/legacy-compat/decorators/http-code.decorator.d.mts +22 -0
  167. package/src/legacy-compat/decorators/http-code.decorator.d.mts.map +1 -0
  168. package/src/legacy-compat/decorators/http-code.decorator.mts +38 -0
  169. package/src/legacy-compat/decorators/index.d.mts +9 -0
  170. package/src/legacy-compat/decorators/index.d.mts.map +1 -0
  171. package/src/legacy-compat/decorators/index.mts +9 -0
  172. package/src/legacy-compat/decorators/module.decorator.d.mts +22 -0
  173. package/src/legacy-compat/decorators/module.decorator.d.mts.map +1 -0
  174. package/src/legacy-compat/decorators/module.decorator.mts +37 -0
  175. package/src/legacy-compat/decorators/multipart.decorator.d.mts +34 -0
  176. package/src/legacy-compat/decorators/multipart.decorator.d.mts.map +1 -0
  177. package/src/legacy-compat/decorators/multipart.decorator.mts +93 -0
  178. package/src/legacy-compat/decorators/stream.decorator.d.mts +34 -0
  179. package/src/legacy-compat/decorators/stream.decorator.d.mts.map +1 -0
  180. package/src/legacy-compat/decorators/stream.decorator.mts +76 -0
  181. package/src/legacy-compat/decorators/use-guards.decorator.d.mts +29 -0
  182. package/src/legacy-compat/decorators/use-guards.decorator.d.mts.map +1 -0
  183. package/src/legacy-compat/decorators/use-guards.decorator.mts +80 -0
  184. package/src/legacy-compat/index.d.mts +19 -0
  185. package/src/legacy-compat/index.d.mts.map +1 -0
  186. package/src/legacy-compat/index.mts +40 -0
  187. package/src/logger/console-logger.service.d.mts +196 -0
  188. package/src/logger/console-logger.service.d.mts.map +1 -0
  189. package/src/logger/console-logger.service.mts +15 -2
  190. package/src/logger/index.d.mts +7 -0
  191. package/src/logger/index.d.mts.map +1 -0
  192. package/src/logger/log-levels.d.mts +14 -0
  193. package/src/logger/log-levels.d.mts.map +1 -0
  194. package/src/logger/log-levels.mts +9 -0
  195. package/src/logger/logger-service.interface.d.mts +36 -0
  196. package/src/logger/logger-service.interface.d.mts.map +1 -0
  197. package/src/logger/logger.service.d.mts +57 -0
  198. package/src/logger/logger.service.d.mts.map +1 -0
  199. package/src/logger/logger.service.mts +19 -0
  200. package/src/logger/logger.tokens.d.mts +36 -0
  201. package/src/logger/logger.tokens.d.mts.map +1 -0
  202. package/src/logger/logger.tokens.mts +23 -0
  203. package/src/logger/utils/cli-colors.util.d.mts +10 -0
  204. package/src/logger/utils/cli-colors.util.d.mts.map +1 -0
  205. package/src/logger/utils/filter-log-levelts.util.d.mts +6 -0
  206. package/src/logger/utils/filter-log-levelts.util.d.mts.map +1 -0
  207. package/src/logger/utils/index.d.mts +6 -0
  208. package/src/logger/utils/index.d.mts.map +1 -0
  209. package/src/logger/utils/is-log-level-enabled.d.mts +8 -0
  210. package/src/logger/utils/is-log-level-enabled.d.mts.map +1 -0
  211. package/src/logger/utils/is-log-level.util.d.mts +6 -0
  212. package/src/logger/utils/is-log-level.util.d.mts.map +1 -0
  213. package/src/logger/utils/shared.utils.d.mts +14 -0
  214. package/src/logger/utils/shared.utils.d.mts.map +1 -0
  215. package/src/metadata/controller.metadata.d.mts +13 -0
  216. package/src/metadata/controller.metadata.d.mts.map +1 -0
  217. package/src/metadata/handler.metadata.d.mts +18 -0
  218. package/src/metadata/handler.metadata.d.mts.map +1 -0
  219. package/src/metadata/index.d.mts +4 -0
  220. package/src/metadata/index.d.mts.map +1 -0
  221. package/src/metadata/module.metadata.d.mts +13 -0
  222. package/src/metadata/module.metadata.d.mts.map +1 -0
  223. package/src/navios.application.d.mts +210 -0
  224. package/src/navios.application.d.mts.map +1 -0
  225. package/src/navios.application.mts +176 -2
  226. package/src/navios.environment.d.mts +11 -0
  227. package/src/navios.environment.d.mts.map +1 -0
  228. package/src/navios.factory.d.mts +68 -0
  229. package/src/navios.factory.d.mts.map +1 -0
  230. package/src/navios.factory.mts +59 -1
  231. package/src/services/guard-runner.service.d.mts +10 -0
  232. package/src/services/guard-runner.service.d.mts.map +1 -0
  233. package/src/services/guard-runner.service.mts +12 -11
  234. package/src/services/index.d.mts +3 -0
  235. package/src/services/index.d.mts.map +1 -0
  236. package/src/services/module-loader.service.d.mts +17 -0
  237. package/src/services/module-loader.service.d.mts.map +1 -0
  238. package/src/services/module-loader.service.mts +16 -11
  239. package/src/stores/index.d.mts +2 -0
  240. package/src/stores/index.d.mts.map +1 -0
  241. package/src/stores/index.mts +1 -0
  242. package/src/stores/request-id.store.d.mts +37 -0
  243. package/src/stores/request-id.store.d.mts.map +1 -0
  244. package/src/stores/request-id.store.mts +43 -0
  245. package/src/testing/index.mts +2 -0
  246. package/src/testing/testing-module.mts +231 -0
  247. package/src/tokens/endpoint-adapter.token.d.mts +4 -0
  248. package/src/tokens/endpoint-adapter.token.d.mts.map +1 -0
  249. package/src/tokens/execution-context.token.d.mts +5 -0
  250. package/src/tokens/execution-context.token.d.mts.map +1 -0
  251. package/src/tokens/http-adapter.token.d.mts +4 -0
  252. package/src/tokens/http-adapter.token.d.mts.map +1 -0
  253. package/src/tokens/index.d.mts +9 -0
  254. package/src/tokens/index.d.mts.map +1 -0
  255. package/src/tokens/index.mts +1 -0
  256. package/src/tokens/multipart-adapter.token.d.mts +4 -0
  257. package/src/tokens/multipart-adapter.token.d.mts.map +1 -0
  258. package/src/tokens/reply.token.d.mts +3 -0
  259. package/src/tokens/reply.token.d.mts.map +1 -0
  260. package/src/tokens/request.token.d.mts +3 -0
  261. package/src/tokens/request.token.d.mts.map +1 -0
  262. package/src/tokens/stream-adapter.token.d.mts +4 -0
  263. package/src/tokens/stream-adapter.token.d.mts.map +1 -0
  264. package/src/tokens/xml-stream-adapter.token.d.mts +4 -0
  265. package/src/tokens/xml-stream-adapter.token.d.mts.map +1 -0
  266. package/src/tokens/xml-stream-adapter.token.mts +8 -0
  267. package/tsconfig.lib.json +1 -1
  268. package/tsconfig.spec.json +3 -0
  269. package/tsdown.config.mts +35 -0
  270. package/vitest.config.mts +6 -0
  271. package/lib/_tsup-dts-rollup.d.mts +0 -1352
  272. package/lib/_tsup-dts-rollup.d.ts +0 -1352
  273. package/lib/index.d.ts +0 -188
  274. package/lib/index.js +0 -1519
  275. package/lib/index.js.map +0 -1
  276. package/lib/index.mjs.map +0 -1
  277. package/tsup.config.mts +0 -13
package/CHANGELOG.md ADDED
@@ -0,0 +1,93 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.7.0] - 2025-12-18
9
+
10
+ ### Added
11
+
12
+ - **Testing Module**: New `TestingModule` class and `createTestingModule` function for easier testing setup with dependency overrides
13
+ - **Config Service**: New `ConfigService` for managing application configuration with type-safe access
14
+ - **Logger System**: Comprehensive logging system with multiple log levels (error, warn, log, debug, verbose, fatal) and customizable output
15
+ - **Attribute Factory**: `AttributeFactory` for creating custom metadata decorators that can be applied to modules, controllers, and endpoints
16
+ - **Exception Classes**: Complete set of HTTP exception classes:
17
+ - `HttpException` (base class)
18
+ - `BadRequestException`
19
+ - `UnauthorizedException`
20
+ - `ForbiddenException`
21
+ - `NotFoundException`
22
+ - `ConflictException`
23
+ - `InternalServerErrorException`
24
+ - **Decorators**: Full set of decorators for building Navios applications:
25
+ - `@Module()` - Define application modules
26
+ - `@Controller()` - Define request controllers
27
+ - `@Endpoint()` - Define HTTP endpoints with type-safe request/response schemas
28
+ - `@Multipart()` - Define multipart/form-data endpoints for file uploads
29
+ - `@Stream()` - Define streaming endpoints
30
+ - `@UseGuards()` - Apply guards to controllers or endpoints
31
+ - `@Header()` - Set custom response headers
32
+ - `@HttpCode()` - Set custom HTTP status codes
33
+ - **Legacy-Compatible Decorators**: Complete set of decorators compatible with TypeScript experimental decorators, available from `@navios/core/legacy-compat`:
34
+ - All standard decorators (`@Module`, `@Controller`, `@Endpoint`, `@Multipart`, `@Stream`, `@UseGuards`, `@Header`, `@HttpCode`) with legacy decorator API support
35
+ - Seamless conversion from experimental decorator format to Stage 3 format internally
36
+ - Full type safety and feature parity with standard decorators
37
+ - **Core Application APIs**:
38
+ - `NaviosFactory.create()` - Factory method for creating Navios applications
39
+ - `NaviosApplication` - Main application class with methods for:
40
+ - `init()` - Initialize the application
41
+ - `listen()` - Start the HTTP server
42
+ - `setGlobalPrefix()` - Set a global URL prefix
43
+ - `enableCors()` - Enable CORS support
44
+ - `enableMultipart()` - Enable multipart/form-data support
45
+ - `getServer()` - Get the underlying HTTP server instance
46
+ - `getContainer()` - Get the dependency injection container
47
+ - `dispose()` / `close()` - Clean up resources
48
+ - **Guards System**: `CanActivate` interface for implementing request guards (authentication, authorization, etc.)
49
+ - **Type Utilities**: Type-safe utilities for endpoint parameters and results:
50
+ - `EndpointParams<T>` - Extract typed parameters from endpoint definitions
51
+ - `EndpointResult<T>` - Extract typed return values from endpoint definitions
52
+ - `MultipartParams<T>` - Extract typed parameters for multipart endpoints
53
+ - `StreamParams<T>` - Extract typed parameters for stream endpoints
54
+ - **Dependency Injection**: Full integration with `@navios/di` for dependency injection
55
+ - **Adapter Support**: Adapter-based architecture supporting multiple HTTP server implementations (Fastify, Bun)
56
+
57
+ ### Features
58
+
59
+ - **Type Safety**: Full TypeScript support with type inference for endpoints, requests, and responses
60
+ - **Zod Integration**: Built-in support for Zod schema validation for request/response validation
61
+ - **Modular Architecture**: Organize code into modules with clear boundaries and dependency management
62
+ - **Extensible**: Custom attributes system for adding metadata to modules, controllers, and endpoints
63
+ - **Testing Support**: Comprehensive testing utilities for unit and integration tests
64
+
65
+ ### Documentation
66
+
67
+ - Complete README with getting started guide
68
+ - Comprehensive documentation in `/docs` covering:
69
+ - Quick Start Guide
70
+ - Application Setup and Configuration
71
+ - Modules, Controllers, and Endpoints
72
+ - Services and Dependency Injection
73
+ - Guards and Exception Handling
74
+ - Attributes System
75
+ - HTTP Server Adapters
76
+ - Testing Guide
77
+
78
+ ### Dependencies
79
+
80
+ - `@navios/di` - Dependency injection container
81
+ - `@navios/builder` (peer dependency) - Type-safe API definitions
82
+ - `zod` (peer dependency) - Schema validation
83
+
84
+ ---
85
+
86
+ ## [Unreleased]
87
+
88
+ ### Planned
89
+
90
+ - Additional adapter implementations
91
+ - Enhanced middleware support
92
+ - WebSocket support
93
+ - Performance optimizations
package/README.md CHANGED
@@ -84,6 +84,21 @@ The choice of adapter depends on your deployment environment and performance req
84
84
  - **Guard**: A guard is a class that is used to validate incoming requests and ensure that they meet certain criteria. Guards can be used to validate request parameters, headers, and body. They can also be used to check authentication and authorization.
85
85
  - **Attribute**: An attribute is a decorator that is used to add metadata to a class or method. Attributes can be used in guards, controllers, modules, and endpoints to provide additional information about the class or method.
86
86
 
87
+ ## Legacy-Compatible Decorators
88
+
89
+ Navios provides legacy-compatible decorators for projects that use TypeScript's experimental decorator API. These decorators are available from `@navios/core/legacy-compat` and provide the same functionality as the standard decorators, but with compatibility for projects that cannot use Stage 3 decorators.
90
+
91
+ ```ts
92
+ import { Controller, Endpoint, Module } from '@navios/core/legacy-compat'
93
+
94
+ @Module({
95
+ controllers: [UserController],
96
+ })
97
+ export class AppModule {}
98
+ ```
99
+
100
+ For more information, see the [Legacy-Compatible Decorators documentation](./docs/legacy-compat.md).
101
+
87
102
  ## Getting Started
88
103
 
89
104
  ### Define your API
@@ -91,7 +106,7 @@ The choice of adapter depends on your deployment environment and performance req
91
106
  Define your API in a shared location accessible to both the client and server. This allows you to use the same API definition for both the client and server, ensuring consistency and reducing duplication.
92
107
 
93
108
  ```ts
94
- import { builder } from '@navios/core'
109
+ import { builder } from '@navios/builder'
95
110
 
96
111
  import { z } from 'zod/v4'
97
112
 
@@ -227,7 +242,9 @@ That's it! You have created your first Navios server. You can now run your serve
227
242
  - **[Quick Start Guide](./docs/quick-start.md)** - Get up and running quickly
228
243
  - **[Complete Documentation](./docs/README.md)** - Comprehensive framework documentation
229
244
  - **[Adapter Guide](./docs/adapters.md)** - Detailed adapter information and comparison
245
+ - **[Legacy-Compatible Decorators](./docs/legacy-compat.md)** - Using Navios with TypeScript experimental decorators
230
246
  - **[API Examples](https://github.com/Arilas/navios/tree/main/examples)** - Working code examples
247
+ - **[CHANGELOG](./CHANGELOG.md)** - Version history and release notes
231
248
 
232
249
  ## Related Packages
233
250
 
package/docs/README.md CHANGED
@@ -16,6 +16,7 @@
16
16
  - [Guards](./guards.md) - Authentication, authorization, and request filtering
17
17
  - [Exception Handling](./exceptions.md) - Error handling and HTTP exceptions
18
18
  - [Attribute System](./attributes.md) - Metadata and custom decorators
19
+ - [Legacy-Compatible Decorators](./legacy-compat.md) - Using Navios with TypeScript experimental decorators
19
20
 
20
21
  ### Infrastructure
21
22
 
@@ -0,0 +1,320 @@
1
+ # Legacy-Compatible Decorators
2
+
3
+ Navios provides a legacy-compatible decorator API for projects that cannot use Stage 3 decorators (the standard decorator proposal). These decorators use the TypeScript experimental decorator API and convert the arguments to Stage 3 format internally.
4
+
5
+ ## Overview
6
+
7
+ The legacy-compat decorators are located in `@navios/core/legacy-compat` and provide the same functionality as the standard decorators, but with compatibility for TypeScript's experimental decorator system.
8
+
9
+ ## When to Use Legacy-Compatible Decorators
10
+
11
+ Use legacy-compatible decorators if:
12
+
13
+ - Your project uses TypeScript with `experimentalDecorators` enabled
14
+ - You cannot migrate to Stage 3 decorators due to tooling or compatibility constraints
15
+ - You need to maintain compatibility with older TypeScript versions or build tools
16
+
17
+ ## Installation and Setup
18
+
19
+ No additional installation is required. The legacy-compat decorators are included in `@navios/core`.
20
+
21
+ To use legacy-compatible decorators, import them from the `legacy-compat` subpath:
22
+
23
+ ```typescript
24
+ import { Module, Controller, Endpoint, UseGuards, Header, HttpCode, Multipart, Stream } from '@navios/core/legacy-compat'
25
+ ```
26
+
27
+ ## Available Decorators
28
+
29
+ All standard Navios decorators are available in legacy-compatible form:
30
+
31
+ ### Class Decorators
32
+
33
+ #### `@Module(options?)`
34
+
35
+ Defines an application module. Can be applied to classes.
36
+
37
+ ```typescript
38
+ import { Module } from '@navios/core/legacy-compat'
39
+
40
+ @Module({
41
+ controllers: [UserController, AuthController],
42
+ imports: [DatabaseModule],
43
+ guards: [AuthGuard],
44
+ })
45
+ export class AppModule {}
46
+ ```
47
+
48
+ #### `@Controller(options?)`
49
+
50
+ Defines a request controller. Can be applied to classes.
51
+
52
+ ```typescript
53
+ import { Controller } from '@navios/core/legacy-compat'
54
+
55
+ @Controller({ guards: [AuthGuard] })
56
+ export class UserController {
57
+ // ...
58
+ }
59
+ ```
60
+
61
+ ### Method Decorators
62
+
63
+ #### `@Endpoint(endpoint)`
64
+
65
+ Defines an HTTP endpoint with type-safe request/response schemas. Must be applied to methods.
66
+
67
+ ```typescript
68
+ import { Controller, Endpoint, type EndpointParams, type EndpointResult } from '@navios/core/legacy-compat'
69
+
70
+ @Controller()
71
+ export class UserController {
72
+ @Endpoint(getUserEndpoint)
73
+ async getUser(request: EndpointParams<typeof getUserEndpoint>): Promise<EndpointResult<typeof getUserEndpoint>> {
74
+ const { id } = request
75
+ return { id, name: 'John Doe' }
76
+ }
77
+ }
78
+ ```
79
+
80
+ #### `@Multipart(endpoint)`
81
+
82
+ Defines a multipart/form-data endpoint for file uploads. Must be applied to methods.
83
+
84
+ ```typescript
85
+ import { Controller, Multipart, type MultipartParams, type MultipartResult } from '@navios/core/legacy-compat'
86
+
87
+ @Controller()
88
+ export class FileController {
89
+ @Multipart(uploadFileEndpoint)
90
+ async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): Promise<MultipartResult<typeof uploadFileEndpoint>> {
91
+ const { file } = request.data
92
+ return { url: 'https://example.com/file.jpg' }
93
+ }
94
+ }
95
+ ```
96
+
97
+ #### `@Stream(endpoint)`
98
+
99
+ Defines a streaming endpoint. Must be applied to methods.
100
+
101
+ ```typescript
102
+ import { Controller, Stream, type StreamParams } from '@navios/core/legacy-compat'
103
+
104
+ @Controller()
105
+ export class FileController {
106
+ @Stream(downloadFileEndpoint)
107
+ async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any): Promise<void> {
108
+ const { fileId } = request.urlParams
109
+ // Stream file data to reply
110
+ }
111
+ }
112
+ ```
113
+
114
+ #### `@UseGuards(...guards)`
115
+
116
+ Applies guards to controllers or endpoints. Can be applied to classes or methods.
117
+
118
+ ```typescript
119
+ import { Controller, Endpoint, UseGuards } from '@navios/core/legacy-compat'
120
+
121
+ // Apply to a controller
122
+ @Controller()
123
+ @UseGuards(AuthGuard, RoleGuard)
124
+ export class UserController {
125
+ // All endpoints in this controller will use AuthGuard and RoleGuard
126
+ }
127
+
128
+ // Apply to a specific endpoint
129
+ @Controller()
130
+ export class UserController {
131
+ @Endpoint(getUserEndpoint)
132
+ @UseGuards(AuthGuard)
133
+ async getUser() {
134
+ // Only this endpoint uses AuthGuard
135
+ }
136
+ }
137
+ ```
138
+
139
+ #### `@Header(name, value)`
140
+
141
+ Sets custom response headers. Must be applied to methods.
142
+
143
+ ```typescript
144
+ import { Controller, Endpoint, Header } from '@navios/core/legacy-compat'
145
+
146
+ @Controller()
147
+ export class UserController {
148
+ @Endpoint(getUserEndpoint)
149
+ @Header('Cache-Control', 'max-age=3600')
150
+ async getUser() {
151
+ return { id: '1', name: 'John' }
152
+ }
153
+ }
154
+ ```
155
+
156
+ #### `@HttpCode(code)`
157
+
158
+ Sets a custom HTTP status code for the response. Must be applied to methods.
159
+
160
+ ```typescript
161
+ import { Controller, Endpoint, HttpCode } from '@navios/core/legacy-compat'
162
+
163
+ @Controller()
164
+ export class UserController {
165
+ @Endpoint(createUserEndpoint)
166
+ @HttpCode(201)
167
+ async createUser() {
168
+ return { id: '1', name: 'John' }
169
+ }
170
+ }
171
+ ```
172
+
173
+ ## Type Utilities
174
+
175
+ The legacy-compat module also exports type utilities for working with endpoints:
176
+
177
+ ```typescript
178
+ import type {
179
+ ModuleOptions,
180
+ ControllerOptions,
181
+ EndpointParams,
182
+ EndpointResult,
183
+ MultipartParams,
184
+ MultipartResult,
185
+ StreamParams,
186
+ } from '@navios/core/legacy-compat'
187
+ ```
188
+
189
+ ## Complete Example
190
+
191
+ Here's a complete example using legacy-compatible decorators:
192
+
193
+ ```typescript
194
+ import { builder } from '@navios/builder'
195
+ import { Module, Controller, Endpoint, UseGuards, HttpCode, type EndpointParams, type EndpointResult } from '@navios/core/legacy-compat'
196
+ import { Injectable, syncInject } from '@navios/core'
197
+ import { z } from 'zod/v4'
198
+
199
+ // Define API endpoints
200
+ const api = builder()
201
+
202
+ const getUserEndpoint = api.declareEndpoint({
203
+ method: 'get',
204
+ url: '/users/:id',
205
+ responseSchema: z.object({
206
+ id: z.string(),
207
+ name: z.string(),
208
+ email: z.string().email(),
209
+ }),
210
+ })
211
+
212
+ const createUserEndpoint = api.declareEndpoint({
213
+ method: 'post',
214
+ url: '/users',
215
+ requestSchema: z.object({
216
+ name: z.string(),
217
+ email: z.string().email(),
218
+ }),
219
+ responseSchema: z.object({
220
+ id: z.string(),
221
+ name: z.string(),
222
+ email: z.string().email(),
223
+ }),
224
+ })
225
+
226
+ // Service
227
+ @Injectable()
228
+ export class UserService {
229
+ async findById(id: string) {
230
+ // Implementation
231
+ }
232
+
233
+ async create(data: { name: string; email: string }) {
234
+ // Implementation
235
+ }
236
+ }
237
+
238
+ // Controller
239
+ @Controller()
240
+ @UseGuards(AuthGuard)
241
+ export class UserController {
242
+ userService = syncInject(UserService)
243
+
244
+ @Endpoint(getUserEndpoint)
245
+ async getUser(request: EndpointParams<typeof getUserEndpoint>): Promise<EndpointResult<typeof getUserEndpoint>> {
246
+ const { id } = request.urlParams
247
+ return await this.userService.findById(id)
248
+ }
249
+
250
+ @Endpoint(createUserEndpoint)
251
+ @HttpCode(201)
252
+ async createUser(request: EndpointParams<typeof createUserEndpoint>): Promise<EndpointResult<typeof createUserEndpoint>> {
253
+ const { name, email } = request.body
254
+ return await this.userService.create({ name, email })
255
+ }
256
+ }
257
+
258
+ // Module
259
+ @Module({
260
+ controllers: [UserController],
261
+ })
262
+ export class AppModule {}
263
+ ```
264
+
265
+ ## Migration from Standard Decorators
266
+
267
+ If you're migrating from standard decorators to legacy-compatible decorators:
268
+
269
+ 1. Update your imports to use the `legacy-compat` subpath:
270
+
271
+ ```typescript
272
+ // Before
273
+ import { Module, Controller, Endpoint } from '@navios/core'
274
+
275
+ // After
276
+ import { Module, Controller, Endpoint } from '@navios/core/legacy-compat'
277
+ ```
278
+
279
+ 2. Ensure your `tsconfig.json` has `experimentalDecorators` enabled:
280
+
281
+ ```json
282
+ {
283
+ "compilerOptions": {
284
+ "experimentalDecorators": true
285
+ }
286
+ }
287
+ ```
288
+
289
+ 3. The decorator usage remains the same - no changes to how you apply them.
290
+
291
+ ## Differences from Standard Decorators
292
+
293
+ The legacy-compatible decorators:
294
+
295
+ - Use TypeScript's experimental decorator API instead of Stage 3 decorators
296
+ - Convert decorator arguments internally to work with the standard Navios implementation
297
+ - Provide the same functionality and type safety as standard decorators
298
+ - May have slightly different type inference behavior in some edge cases
299
+
300
+ ## TypeScript Configuration
301
+
302
+ To use legacy-compatible decorators, ensure your `tsconfig.json` includes:
303
+
304
+ ```json
305
+ {
306
+ "compilerOptions": {
307
+ "experimentalDecorators": true,
308
+ "emitDecoratorMetadata": true
309
+ }
310
+ }
311
+ ```
312
+
313
+ The `emitDecoratorMetadata` option is optional but recommended for better runtime behavior with dependency injection.
314
+
315
+ ## Notes
316
+
317
+ - Legacy-compatible decorators are fully compatible with all Navios features including guards, attributes, dependency injection, and adapters
318
+ - You can mix legacy-compatible decorators with standard decorators in the same project, but it's recommended to use one approach consistently
319
+ - The legacy-compat module is maintained alongside the standard decorators and receives the same updates and bug fixes
320
+
package/docs/testing.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Testing Guide
2
2
 
3
- > This guide is for future reference and may be updated over time
4
- >
5
- > Not represent the final state of the testing strategy for Navios
6
-
7
3
  This guide covers testing strategies and best practices for Navios applications, including unit testing, integration testing, and end-to-end testing.
8
4
 
9
5
  ## Testing Philosophy
@@ -22,6 +18,132 @@ Navios promotes a testing-first approach with:
22
18
  npm install --save-dev vitest supertest @navios/builder
23
19
  ```
24
20
 
21
+ ## Testing Module
22
+
23
+ Navios provides a dedicated testing module that simplifies setting up test environments with mock dependencies.
24
+
25
+ ### Creating a Testing Module
26
+
27
+ The `createTestingModule` function is the main entry point for setting up tests:
28
+
29
+ ```typescript
30
+ import { createTestingModule } from '@navios/core/testing'
31
+
32
+ import { AppModule } from './app.module'
33
+ import { DatabaseService } from './database.service'
34
+
35
+ describe('AppModule', () => {
36
+ it('should create application with mocked dependencies', async () => {
37
+ const mockDatabase = {
38
+ query: vi.fn().mockResolvedValue([]),
39
+ }
40
+
41
+ const testingModule = createTestingModule(AppModule, {
42
+ adapter: [], // No HTTP adapter for unit tests
43
+ })
44
+ .overrideProvider(DatabaseService)
45
+ .useValue(mockDatabase)
46
+
47
+ const app = await testingModule.compile()
48
+
49
+ // App is ready to use with mocked DatabaseService
50
+ expect(app).toBeDefined()
51
+
52
+ await testingModule.close()
53
+ })
54
+ })
55
+ ```
56
+
57
+ ### TestingModule API
58
+
59
+ #### `createTestingModule(appModule, options)`
60
+
61
+ Creates a new testing module builder.
62
+
63
+ ```typescript
64
+ const testingModule = createTestingModule(AppModule, {
65
+ adapter: [], // Required: HTTP adapter configuration
66
+ logger: false, // Optional: Disable logging for tests
67
+ overrides: [ // Optional: Initial overrides
68
+ { token: SomeService, useValue: mockService },
69
+ ],
70
+ })
71
+ ```
72
+
73
+ #### `.overrideProvider(token)`
74
+
75
+ Returns a builder for overriding a provider:
76
+
77
+ ```typescript
78
+ testingModule
79
+ .overrideProvider(DatabaseService)
80
+ .useValue(mockDatabaseService) // Use a mock value
81
+
82
+ testingModule
83
+ .overrideProvider(CacheService)
84
+ .useClass(MockCacheService) // Use a mock class
85
+ ```
86
+
87
+ #### `.compile()`
88
+
89
+ Compiles the testing module and returns the `NaviosApplication`:
90
+
91
+ ```typescript
92
+ const app = await testingModule.compile()
93
+ ```
94
+
95
+ #### `.init()`
96
+
97
+ Compiles and initializes the application (equivalent to calling `compile()` then `app.init()`):
98
+
99
+ ```typescript
100
+ const app = await testingModule.init()
101
+ ```
102
+
103
+ #### `.get(token)`
104
+
105
+ Gets an instance from the container:
106
+
107
+ ```typescript
108
+ const userService = await testingModule.get(UserService)
109
+ ```
110
+
111
+ #### `.getContainer()`
112
+
113
+ Gets the underlying `TestContainer` for direct manipulation:
114
+
115
+ ```typescript
116
+ const container = testingModule.getContainer()
117
+ container.bind(SomeToken).toValue(someValue)
118
+ ```
119
+
120
+ #### `.close()`
121
+
122
+ Disposes the testing module and cleans up resources:
123
+
124
+ ```typescript
125
+ await testingModule.close()
126
+ ```
127
+
128
+ ### Custom Container Support
129
+
130
+ You can also pass a custom container directly to `NaviosFactory.create()`:
131
+
132
+ ```typescript
133
+ import { NaviosFactory } from '@navios/core'
134
+ import { TestContainer } from '@navios/core/testing'
135
+
136
+ const container = new TestContainer()
137
+ container.bind(DatabaseService).toValue(mockDatabase)
138
+
139
+ const app = await NaviosFactory.create(AppModule, {
140
+ adapter: [],
141
+ container, // Use custom container
142
+ })
143
+ ```
144
+
145
+ This is useful when you need more control over the container setup or when integrating with existing test infrastructure.
146
+
25
147
  ## Unit Testing
26
148
 
27
149
  ### Testing Services
@@ -332,29 +454,31 @@ describe('AuthGuard', () => {
332
454
  ### Testing Module Integration
333
455
 
334
456
  ```typescript
335
- import { NaviosFactory } from '@navios/core'
457
+ import { createTestingModule } from '@navios/core/testing'
458
+ import { defineFastifyEnvironment } from '@navios/adapter-fastify'
336
459
 
337
460
  import { DatabaseService } from './database.service'
338
461
  import { UserModule } from './user.module'
339
462
  import { UserService } from './user.service'
340
463
 
341
464
  describe('UserModule', () => {
342
- let module: TestingModule
465
+ let testingModule: ReturnType<typeof createTestingModule>
343
466
  let userService: UserService
344
467
  let databaseService: DatabaseService
345
468
 
346
469
  beforeAll(async () => {
347
- module = await NaviosFactory.create(UserModule, {
470
+ testingModule = createTestingModule(UserModule, {
348
471
  adapter: defineFastifyEnvironment(),
349
472
  })
350
- await module.init()
351
473
 
352
- userService = module.get<UserService>(UserService)
353
- databaseService = module.get<DatabaseService>(DatabaseService)
474
+ await testingModule.init()
475
+
476
+ userService = await testingModule.get(UserService)
477
+ databaseService = await testingModule.get(DatabaseService)
354
478
  })
355
479
 
356
480
  afterAll(async () => {
357
- await module.close()
481
+ await testingModule.close()
358
482
  })
359
483
 
360
484
  it('should be defined', () => {
@@ -374,28 +498,27 @@ When testing HTTP endpoints, ensure your endpoints are defined using `@navios/bu
374
498
 
375
499
  ```typescript
376
500
  import { defineFastifyEnvironment } from '@navios/adapter-fastify'
377
- import { NaviosFactory } from '@navios/core'
501
+ import { createTestingModule } from '@navios/core/testing'
378
502
 
379
503
  import * as request from 'supertest'
380
504
 
381
505
  import { AppModule } from '../app.module'
382
506
 
383
507
  describe('UserController (e2e)', () => {
384
- let app: any
508
+ let testingModule: ReturnType<typeof createTestingModule>
385
509
  let httpServer: any
386
510
 
387
511
  beforeAll(async () => {
388
- const moduleFixture = await NaviosFactory.create(AppModule, {
512
+ testingModule = createTestingModule(AppModule, {
389
513
  adapter: defineFastifyEnvironment(),
390
514
  })
391
- await moduleFixture.init()
392
515
 
393
- await app.init()
516
+ const app = await testingModule.init()
394
517
  httpServer = app.getServer()
395
518
  })
396
519
 
397
520
  afterAll(async () => {
398
- await app.close()
521
+ await testingModule.close()
399
522
  })
400
523
 
401
524
  describe('/users (GET)', () => {