@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
@@ -0,0 +1,46 @@
1
+ import { FactoryInjectionToken } from '@navios/di';
2
+ import { z } from 'zod/v4';
3
+ import type { ConfigServiceOptions } from './config.service.mjs';
4
+ import { ConfigService, ConfigServiceOptionsSchema } from './config.service.mjs';
5
+ /**
6
+ * Schema for configuration provider options.
7
+ */
8
+ export declare const ConfigProviderOptions: z.ZodObject<{
9
+ load: z.ZodFunction<z.core.$ZodFunctionArgs, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
10
+ }, z.core.$strip>;
11
+ /**
12
+ * Creates a factory injection token for ConfigService that loads configuration asynchronously.
13
+ *
14
+ * Use this when you need to load configuration from a file, database, or other async source.
15
+ *
16
+ * @param options - Configuration provider options
17
+ * @param options.load - Async function that loads and returns the configuration object
18
+ * @returns A factory injection token for ConfigService
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const MyConfigService = provideConfig({
23
+ * load: async () => {
24
+ * const config = await loadConfigFromFile('config.json')
25
+ * return config
26
+ * },
27
+ * })
28
+ *
29
+ * // Use in module setup
30
+ * container.bind(ConfigServiceToken).toFactory(configProvider)
31
+ * ```
32
+ */
33
+ export declare function provideConfig<ConfigMap extends ConfigServiceOptions>(options: z.input<typeof ConfigProviderOptions>): FactoryInjectionToken<ConfigService<ConfigMap>, typeof ConfigServiceOptionsSchema>;
34
+ /**
35
+ * Pre-configured ConfigService provider that uses environment variables.
36
+ *
37
+ * Provides a ConfigService instance bound to `process.env`.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * // Use environment variables as configuration
42
+ * container.bind(ConfigServiceToken).toValue(EnvConfigProvider)
43
+ * ```
44
+ */
45
+ export declare const EnvConfigProvider: import("@navios/di").BoundInjectionToken<ConfigService<Record<string, string>>, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
46
+ //# sourceMappingURL=config.provider.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.provider.d.mts","sourceRoot":"","sources":["config.provider.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAkB,MAAM,YAAY,CAAA;AAElE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEhE,OAAO,EACL,aAAa,EACb,0BAA0B,EAE3B,MAAM,sBAAsB,CAAA;AAE7B;;GAEG;AACH,eAAO,MAAM,qBAAqB;;iBAEhC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,SAAS,SAAS,oBAAoB,EAClE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAC7C,qBAAqB,CACtB,aAAa,CAAC,SAAS,CAAC,EACxB,OAAO,0BAA0B,CAClC,CAEA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,yHAK5B,CAAA"}
@@ -12,10 +12,35 @@ import {
12
12
  ConfigServiceToken,
13
13
  } from './config.service.mjs'
14
14
 
15
+ /**
16
+ * Schema for configuration provider options.
17
+ */
15
18
  export const ConfigProviderOptions = z.object({
16
19
  load: z.function({ output: ConfigServiceOptionsSchema }),
17
20
  })
18
21
 
22
+ /**
23
+ * Creates a factory injection token for ConfigService that loads configuration asynchronously.
24
+ *
25
+ * Use this when you need to load configuration from a file, database, or other async source.
26
+ *
27
+ * @param options - Configuration provider options
28
+ * @param options.load - Async function that loads and returns the configuration object
29
+ * @returns A factory injection token for ConfigService
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const MyConfigService = provideConfig({
34
+ * load: async () => {
35
+ * const config = await loadConfigFromFile('config.json')
36
+ * return config
37
+ * },
38
+ * })
39
+ *
40
+ * // Use in module setup
41
+ * container.bind(ConfigServiceToken).toFactory(configProvider)
42
+ * ```
43
+ */
19
44
  export function provideConfig<ConfigMap extends ConfigServiceOptions>(
20
45
  options: z.input<typeof ConfigProviderOptions>,
21
46
  ): FactoryInjectionToken<
@@ -25,6 +50,17 @@ export function provideConfig<ConfigMap extends ConfigServiceOptions>(
25
50
  return InjectionToken.factory(ConfigServiceToken, async () => options.load())
26
51
  }
27
52
 
53
+ /**
54
+ * Pre-configured ConfigService provider that uses environment variables.
55
+ *
56
+ * Provides a ConfigService instance bound to `process.env`.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Use environment variables as configuration
61
+ * container.bind(ConfigServiceToken).toValue(EnvConfigProvider)
62
+ * ```
63
+ */
28
64
  export const EnvConfigProvider = InjectionToken.bound<
29
65
  ConfigService<Record<string, string>>,
30
66
  typeof ConfigServiceOptionsSchema
@@ -0,0 +1,108 @@
1
+ import { InjectionToken } from '@navios/di';
2
+ import { z } from 'zod/v4';
3
+ import type { ConfigServiceInterface as IConfigService } from './config-service.interface.mjs';
4
+ import type { Path, PathValue } from './types.mjs';
5
+ /**
6
+ * Schema for validating configuration service options.
7
+ */
8
+ export declare const ConfigServiceOptionsSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
9
+ /**
10
+ * Type for configuration service options.
11
+ */
12
+ export type ConfigServiceOptions = z.infer<typeof ConfigServiceOptionsSchema>;
13
+ /**
14
+ * Injection token for ConfigService.
15
+ */
16
+ export declare const ConfigServiceToken: InjectionToken<IConfigService<Record<string, unknown>>, z.ZodRecord<z.ZodString, z.ZodUnknown>, true>;
17
+ /**
18
+ * Service for managing application configuration with type-safe access.
19
+ *
20
+ * Provides methods to access configuration values using dot-notation paths
21
+ * with full TypeScript type inference.
22
+ *
23
+ * @typeParam Config - The configuration object type
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * interface AppConfig {
28
+ * database: {
29
+ * host: string
30
+ * port: number
31
+ * }
32
+ * api: {
33
+ * timeout: number
34
+ * }
35
+ * }
36
+ *
37
+ * @Injectable()
38
+ * export class DatabaseService {
39
+ * private config = inject(MyConfigService)
40
+ *
41
+ * connect() {
42
+ * const host = this.config.getOrThrow('database.host')
43
+ * const port = this.config.getOrDefault('database.port', 5432)
44
+ * // host is typed as string, port is typed as number
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export declare class ConfigService<Config extends ConfigServiceOptions = Record<string, unknown>> implements IConfigService<Config> {
50
+ private config;
51
+ private readonly logger;
52
+ /**
53
+ * Creates a new ConfigService instance.
54
+ *
55
+ * @param config - The configuration object
56
+ */
57
+ constructor(config?: Config);
58
+ /**
59
+ * Gets the entire configuration object.
60
+ *
61
+ * @returns The complete configuration object
62
+ */
63
+ getConfig(): Config;
64
+ /**
65
+ * Gets a configuration value by key path.
66
+ *
67
+ * Returns `null` if the key is not found or if any part of the path is invalid.
68
+ *
69
+ * @param key - Dot-separated path to the configuration value (e.g., 'database.host')
70
+ * @returns The configuration value or `null` if not found
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const host = config.get('database.host') // string | null
75
+ * const port = config.get('database.port') // number | null
76
+ * ```
77
+ */
78
+ get<Key extends Path<Config>>(key: Key): PathValue<Config, Key> | null;
79
+ /**
80
+ * Gets a configuration value by key path, or returns a default value if not found.
81
+ *
82
+ * @param key - Dot-separated path to the configuration value
83
+ * @param defaultValue - Default value to return if the key is not found
84
+ * @returns The configuration value or the default value
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const port = config.getOrDefault('database.port', 5432) // number
89
+ * ```
90
+ */
91
+ getOrDefault<Key extends Path<Config>>(key: Key, defaultValue: PathValue<Config, Key>): PathValue<Config, Key>;
92
+ /**
93
+ * Gets a configuration value by key path, or throws an error if not found.
94
+ *
95
+ * @param key - Dot-separated path to the configuration value
96
+ * @param errorMessage - Optional custom error message
97
+ * @returns The configuration value
98
+ * @throws Error if the key is not found
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const host = config.getOrThrow('database.host') // string (throws if not found)
103
+ * const apiKey = config.getOrThrow('api.key', 'API key is required') // string
104
+ * ```
105
+ */
106
+ getOrThrow<Key extends Path<Config>>(key: Key, errorMessage?: string): PathValue<Config, Key>;
107
+ }
108
+ //# sourceMappingURL=config.service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.service.d.mts","sourceRoot":"","sources":["config.service.mts"],"names":[],"mappings":"AACA,OAAO,EAAsB,cAAc,EAAE,MAAM,YAAY,CAAA;AAE/D,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,OAAO,KAAK,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC9F,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,0BAA0B,wCAAoC,CAAA;AAC3E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,kBAAkB,uGAG2B,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAGa,aAAa,CACxB,MAAM,SAAS,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7D,YAAW,cAAc,CAAC,MAAM,CAAC;IAUrB,OAAO,CAAC,MAAM;IAT1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;IAEF;;;;OAIG;gBACiB,MAAM,GAAE,MAAqB;IAEjD;;;;OAIG;IACH,SAAS,IAAI,MAAM;IAInB;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IA0BtE;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EACnC,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,GACnC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;IAKzB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EACjC,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;CAa1B"}
@@ -1,4 +1,4 @@
1
- import { NaviosException } from '@navios/builder'
1
+ import { NaviosError } from '@navios/builder'
2
2
  import { inject, Injectable, InjectionToken } from '@navios/di'
3
3
 
4
4
  import { z } from 'zod/v4'
@@ -8,31 +8,95 @@ import type { Path, PathValue } from './types.mjs'
8
8
 
9
9
  import { Logger } from '../logger/index.mjs'
10
10
 
11
+ /**
12
+ * Schema for validating configuration service options.
13
+ */
11
14
  export const ConfigServiceOptionsSchema = z.record(z.string(), z.unknown())
15
+ /**
16
+ * Type for configuration service options.
17
+ */
12
18
  export type ConfigServiceOptions = z.infer<typeof ConfigServiceOptionsSchema>
13
19
 
20
+ /**
21
+ * Injection token for ConfigService.
22
+ */
14
23
  export const ConfigServiceToken = InjectionToken.create<
15
24
  IConfigService,
16
25
  typeof ConfigServiceOptionsSchema
17
26
  >(Symbol.for('ConfigService'), ConfigServiceOptionsSchema)
18
27
 
28
+ /**
29
+ * Service for managing application configuration with type-safe access.
30
+ *
31
+ * Provides methods to access configuration values using dot-notation paths
32
+ * with full TypeScript type inference.
33
+ *
34
+ * @typeParam Config - The configuration object type
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * interface AppConfig {
39
+ * database: {
40
+ * host: string
41
+ * port: number
42
+ * }
43
+ * api: {
44
+ * timeout: number
45
+ * }
46
+ * }
47
+ *
48
+ * @Injectable()
49
+ * export class DatabaseService {
50
+ * private config = inject(MyConfigService)
51
+ *
52
+ * connect() {
53
+ * const host = this.config.getOrThrow('database.host')
54
+ * const port = this.config.getOrDefault('database.port', 5432)
55
+ * // host is typed as string, port is typed as number
56
+ * }
57
+ * }
58
+ * ```
59
+ */
19
60
  @Injectable({
20
61
  token: ConfigServiceToken,
21
62
  })
22
63
  export class ConfigService<
23
64
  Config extends ConfigServiceOptions = Record<string, unknown>,
24
- > implements IConfigService<Config>
25
- {
65
+ > implements IConfigService<Config> {
26
66
  private readonly logger = inject(Logger, {
27
67
  context: ConfigService.name,
28
68
  })
29
69
 
70
+ /**
71
+ * Creates a new ConfigService instance.
72
+ *
73
+ * @param config - The configuration object
74
+ */
30
75
  constructor(private config: Config = {} as Config) {}
31
76
 
77
+ /**
78
+ * Gets the entire configuration object.
79
+ *
80
+ * @returns The complete configuration object
81
+ */
32
82
  getConfig(): Config {
33
83
  return this.config
34
84
  }
35
85
 
86
+ /**
87
+ * Gets a configuration value by key path.
88
+ *
89
+ * Returns `null` if the key is not found or if any part of the path is invalid.
90
+ *
91
+ * @param key - Dot-separated path to the configuration value (e.g., 'database.host')
92
+ * @returns The configuration value or `null` if not found
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const host = config.get('database.host') // string | null
97
+ * const port = config.get('database.port') // number | null
98
+ * ```
99
+ */
36
100
  get<Key extends Path<Config>>(key: Key): PathValue<Config, Key> | null {
37
101
  try {
38
102
  const parts = String(key).split('.')
@@ -59,6 +123,18 @@ export class ConfigService<
59
123
  }
60
124
  }
61
125
 
126
+ /**
127
+ * Gets a configuration value by key path, or returns a default value if not found.
128
+ *
129
+ * @param key - Dot-separated path to the configuration value
130
+ * @param defaultValue - Default value to return if the key is not found
131
+ * @returns The configuration value or the default value
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const port = config.getOrDefault('database.port', 5432) // number
136
+ * ```
137
+ */
62
138
  getOrDefault<Key extends Path<Config>>(
63
139
  key: Key,
64
140
  defaultValue: PathValue<Config, Key>,
@@ -67,6 +143,20 @@ export class ConfigService<
67
143
  return value !== null ? value : defaultValue
68
144
  }
69
145
 
146
+ /**
147
+ * Gets a configuration value by key path, or throws an error if not found.
148
+ *
149
+ * @param key - Dot-separated path to the configuration value
150
+ * @param errorMessage - Optional custom error message
151
+ * @returns The configuration value
152
+ * @throws Error if the key is not found
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const host = config.getOrThrow('database.host') // string (throws if not found)
157
+ * const apiKey = config.getOrThrow('api.key', 'API key is required') // string
158
+ * ```
159
+ */
70
160
  getOrThrow<Key extends Path<Config>>(
71
161
  key: Key,
72
162
  errorMessage?: string,
@@ -78,7 +168,7 @@ export class ConfigService<
78
168
  errorMessage ||
79
169
  `Configuration value for key "${String(key)}" is not defined`
80
170
  this.logger.error(message)
81
- throw new NaviosException(message)
171
+ throw new NaviosError(message)
82
172
  }
83
173
 
84
174
  return value
@@ -0,0 +1,6 @@
1
+ export * from './utils/index.mjs';
2
+ export * from './config.provider.mjs';
3
+ export * from './config.service.mjs';
4
+ export * from './config-service.interface.mjs';
5
+ export * from './types.mjs';
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,aAAa,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Evaluates to `true` if `T` is `any`. `false` otherwise.
3
+ * (c) https://stackoverflow.com/a/68633327/5290447
4
+ */
5
+ type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
6
+ type ExcludedParts = 'services' | 'mailer' | 'aws' | 'computedTimeRates' | 'aiModelsRates';
7
+ type ExcludedKeys = 'computedTimeRates' | 'aiModelsRates' | 'aiModel';
8
+ export type PathImpl<T, Key extends keyof T> = Key extends string ? Key extends ExcludedKeys ? never : IsAny<T[Key]> extends true ? never : T[Key] extends string ? never : T[Key] extends any[] ? never : T[Key] extends Record<string, any> ? Key extends ExcludedParts ? `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` : `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` | `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` : never : never;
9
+ export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
10
+ export type Path<T> = keyof T extends string ? PathImpl2<T> extends infer P ? P extends string | keyof T ? P : keyof T : keyof T : never;
11
+ export type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends Path<T[Key]> ? PathValue<T[Key], Rest> : never : never : P extends keyof T ? T[P] : never;
12
+
13
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["types.mts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,KAAK,KAAK,CAA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AI,CAAC,CAAC,IAAI,MAAM,CAAC,SAAS,MAAM,GACxC,SAAS,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAC1B,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GACxB,CAAC,GACD,MAAM,CAAC,GACT,MAAM,CAAC,GACT,KAAK,CAAA;AAET,MAAM,MAAM,SAAS,CACnB,CAAC,EACD,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,IACf,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI,MAAM,IAAI,EAAE,GACtC,GAAG,SAAS,MAAM,CAAC,GACjB,IAAI,SAAS,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GACvB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GACvB,KAAK,GACP,KAAK,GACP,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,GACJ,KAAK,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare function envInt(key: keyof NodeJS.ProcessEnv, defaultValue: number): number;
2
+ export declare function envString<DefaultValue extends string | undefined, Ensured = DefaultValue extends string ? true : false>(key: keyof NodeJS.ProcessEnv, defaultValue?: DefaultValue): Ensured extends true ? string : string | undefined;
3
+ //# sourceMappingURL=helpers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["helpers.mts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CACpB,GAAG,EAAE,MAAM,MAAM,CAAC,UAAU,EAC5B,YAAY,EAAE,MAAM,GACnB,MAAM,CAIR;AAED,wBAAgB,SAAS,CACvB,YAAY,SAAS,MAAM,GAAG,SAAS,EACvC,OAAO,GAAG,YAAY,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,EAEpD,GAAG,EAAE,MAAM,MAAM,CAAC,UAAU,EAC5B,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAKpD"}
@@ -0,0 +1,2 @@
1
+ export * from './helpers.mjs';
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -0,0 +1,33 @@
1
+ import type { ClassType } from '@navios/di';
2
+ /**
3
+ * Options for configuring a Navios controller.
4
+ */
5
+ export interface ControllerOptions {
6
+ /**
7
+ * Guards to apply to all endpoints in this controller.
8
+ * Guards are executed in reverse order (last guard first).
9
+ */
10
+ guards?: ClassType[] | Set<ClassType>;
11
+ }
12
+ /**
13
+ * Decorator that marks a class as a Navios controller.
14
+ *
15
+ * Controllers handle HTTP requests and define endpoints.
16
+ * They are request-scoped by default, meaning a new instance is created for each request.
17
+ *
18
+ * @param options - Controller configuration options
19
+ * @returns A class decorator
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * @Controller({ guards: [AuthGuard] })
24
+ * export class UserController {
25
+ * @Endpoint(getUserEndpoint)
26
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
27
+ * // Handle request
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function Controller({ guards }?: ControllerOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
33
+ //# sourceMappingURL=controller.decorator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.decorator.d.mts","sourceRoot":"","sources":["controller.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAM3C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;CACtC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,EAAE,MAAM,EAAE,GAAE,iBAAsB,IAC1C,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAoBnE"}
@@ -4,9 +4,37 @@ import { Injectable, InjectableScope, InjectionToken } from '@navios/di'
4
4
 
5
5
  import { getControllerMetadata } from '../metadata/index.mjs'
6
6
 
7
+ /**
8
+ * Options for configuring a Navios controller.
9
+ */
7
10
  export interface ControllerOptions {
11
+ /**
12
+ * Guards to apply to all endpoints in this controller.
13
+ * Guards are executed in reverse order (last guard first).
14
+ */
8
15
  guards?: ClassType[] | Set<ClassType>
9
16
  }
17
+
18
+ /**
19
+ * Decorator that marks a class as a Navios controller.
20
+ *
21
+ * Controllers handle HTTP requests and define endpoints.
22
+ * They are request-scoped by default, meaning a new instance is created for each request.
23
+ *
24
+ * @param options - Controller configuration options
25
+ * @returns A class decorator
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * @Controller({ guards: [AuthGuard] })
30
+ * export class UserController {
31
+ * @Endpoint(getUserEndpoint)
32
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
33
+ * // Handle request
34
+ * }
35
+ * }
36
+ * ```
37
+ */
10
38
  export function Controller({ guards }: ControllerOptions = {}) {
11
39
  return function (target: ClassType, context: ClassDecoratorContext) {
12
40
  if (context.kind !== 'class') {
@@ -0,0 +1,89 @@
1
+ import type { BaseEndpointConfig, EndpointFunctionArgs, HttpMethod, Util_FlatObject } from '@navios/builder';
2
+ import type { z, ZodType } from 'zod/v4';
3
+ import { ZodDiscriminatedUnion } from 'zod/v4';
4
+ /**
5
+ * Extracts the typed parameters for an endpoint handler function.
6
+ *
7
+ * This utility type extracts URL parameters, query parameters, and request body
8
+ * from an endpoint declaration and flattens them into a single object.
9
+ *
10
+ * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const getUserEndpoint = api.declareEndpoint({
15
+ * method: 'get',
16
+ * url: '/users/$userId',
17
+ * querySchema: z.object({ include: z.string().optional() }),
18
+ * responseSchema: z.object({ id: z.string(), name: z.string() }),
19
+ * })
20
+ *
21
+ * @Endpoint(getUserEndpoint)
22
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
23
+ * // request.urlParams.userId is typed as string
24
+ * // request.query.include is typed as string | undefined
25
+ * }
26
+ * ```
27
+ */
28
+ export type EndpointParams<EndpointDeclaration extends {
29
+ config: BaseEndpointConfig<any, any, any, any, any>;
30
+ }, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodType ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
31
+ /**
32
+ * Extracts the typed return value for an endpoint handler function.
33
+ *
34
+ * This utility type extracts the response schema from an endpoint declaration
35
+ * and returns the appropriate Promise type.
36
+ *
37
+ * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const getUserEndpoint = api.declareEndpoint({
42
+ * method: 'get',
43
+ * url: '/users/$userId',
44
+ * responseSchema: z.object({ id: z.string(), name: z.string() }),
45
+ * })
46
+ *
47
+ * @Endpoint(getUserEndpoint)
48
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
49
+ * return { id: '1', name: 'John' } // Type-checked against responseSchema
50
+ * }
51
+ * ```
52
+ */
53
+ export type EndpointResult<EndpointDeclaration extends {
54
+ config: BaseEndpointConfig<any, any, any, any, any>;
55
+ }> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z.input<Options[number]>> : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>;
56
+ /**
57
+ * Decorator that marks a method as an HTTP endpoint.
58
+ *
59
+ * The endpoint must be defined using @navios/builder's `declareEndpoint` method.
60
+ * This ensures type safety and consistency between client and server.
61
+ *
62
+ * @param endpoint - The endpoint declaration from @navios/builder
63
+ * @returns A method decorator
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { builder } from '@navios/builder'
68
+ *
69
+ * const api = builder()
70
+ * const getUserEndpoint = api.declareEndpoint({
71
+ * method: 'get',
72
+ * url: '/users/$userId',
73
+ * responseSchema: z.object({ id: z.string(), name: z.string() }),
74
+ * })
75
+ *
76
+ * @Controller()
77
+ * export class UserController {
78
+ * @Endpoint(getUserEndpoint)
79
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
80
+ * const { userId } = request.urlParams
81
+ * return { id: userId, name: 'John' }
82
+ * }
83
+ * }
84
+ * ```
85
+ */
86
+ export declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
87
+ config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
88
+ }): (target: (params: QuerySchema extends ZodType ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>) => Promise<z.input<ResponseSchema>>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends ZodType ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>) => Promise<z.input<ResponseSchema>>;
89
+ //# sourceMappingURL=endpoint.decorator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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