@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 @@
1
+ {"version":3,"file":"use-guards.decorator-kZ3lNK8v.mjs","names":["EndpointMetadataKey","Symbol","getAllEndpointMetadata","context","metadata","Set","Error","getEndpointMetadata","target","endpointMetadata","Array","from","find","item","classMethod","name","newMetadata","url","successStatusCode","adapterToken","headers","httpMethod","config","guards","customAttributes","Map","add","getAllEndpointMetadata","ControllerMetadataKey","Symbol","getControllerMetadata","target","context","metadata","endpointsMetadata","newMetadata","endpoints","guards","Set","customAttributes","Map","Error","extractControllerMetadata","hasControllerMetadata","ModuleMetadataKey","Symbol","getModuleMetadata","target","context","metadata","newMetadata","controllers","Set","imports","guards","customAttributes","Map","Error","extractModuleMetadata","name","hasModuleMetadata","Injectable","InjectableScope","InjectionToken","getControllerMetadata","Controller","guards","target","context","kind","Error","token","create","metadata","controllerMetadata","guard","Array","from","reverse","add","scope","Request","InjectionToken","EndpointAdapterToken","create","InjectionToken","ExecutionContextInjectionToken","ExecutionContext","create","InjectionToken","HttpAdapterToken","create","InjectionToken","MultipartAdapterToken","create","InjectionToken","Reply","create","InjectionToken","Request","create","InjectionToken","StreamAdapterToken","create","InjectionToken","XmlStreamAdapterToken","create","getEndpointMetadata","EndpointAdapterToken","Endpoint","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","Header","name","value","target","context","kind","Error","metadata","headers","getEndpointMetadata","HttpCode","code","target","context","kind","Error","metadata","successStatusCode","Injectable","InjectableScope","InjectionToken","getModuleMetadata","Module","controllers","imports","guards","target","context","kind","Error","token","create","moduleMetadata","controller","add","importedModule","guard","Array","from","reverse","scope","Singleton","getEndpointMetadata","MultipartAdapterToken","Multipart","endpoint","target","context","Error","kind","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","StreamAdapterToken","Stream","endpoint","target","context","Error","kind","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getControllerMetadata","getEndpointMetadata","UseGuards","guards","target","context","kind","controllerMetadata","guard","reverse","add","endpointMetadata","Error"],"sources":["../src/metadata/handler.metadata.mts","../src/metadata/controller.metadata.mts","../src/metadata/module.metadata.mts","../src/decorators/controller.decorator.mts","../src/tokens/endpoint-adapter.token.mts","../src/tokens/execution-context.token.mts","../src/tokens/http-adapter.token.mts","../src/tokens/multipart-adapter.token.mts","../src/tokens/reply.token.mts","../src/tokens/request.token.mts","../src/tokens/stream-adapter.token.mts","../src/tokens/xml-stream-adapter.token.mts","../src/decorators/endpoint.decorator.mts","../src/decorators/header.decorator.mts","../src/decorators/http-code.decorator.mts","../src/decorators/module.decorator.mts","../src/decorators/multipart.decorator.mts","../src/decorators/stream.decorator.mts","../src/decorators/use-guards.decorator.mts"],"sourcesContent":["import type { HttpMethod } from '@navios/builder'\nimport type { ClassTypeWithInstance, InjectionToken } from '@navios/di'\n\nimport type {\n AbstractHttpHandlerAdapterInterface,\n CanActivate,\n HttpHeader,\n} from '../interfaces/index.mjs'\n\nexport const EndpointMetadataKey = Symbol('EndpointMetadataKey')\n\nexport interface HandlerMetadata<Config = null> {\n classMethod: string\n url: string\n successStatusCode: number\n adapterToken:\n | InjectionToken<AbstractHttpHandlerAdapterInterface, undefined>\n | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface>\n | null\n headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>\n httpMethod: HttpMethod\n config: Config\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getAllEndpointMetadata(\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n): Set<HandlerMetadata<any>> {\n if (context.metadata) {\n const metadata = context.metadata[EndpointMetadataKey] as\n | Set<HandlerMetadata>\n | undefined\n if (metadata) {\n return metadata\n } else {\n context.metadata[EndpointMetadataKey] = new Set<HandlerMetadata<any>>()\n return context.metadata[EndpointMetadataKey] as Set<HandlerMetadata<any>>\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function getEndpointMetadata<Config = any>(\n target: Function,\n context: ClassMethodDecoratorContext,\n): HandlerMetadata<Config> {\n if (context.metadata) {\n const metadata = getAllEndpointMetadata(context)\n if (metadata) {\n const endpointMetadata = Array.from(metadata).find(\n (item) => item.classMethod === target.name,\n )\n if (endpointMetadata) {\n return endpointMetadata\n } else {\n const newMetadata: HandlerMetadata<Config> = {\n classMethod: target.name,\n url: '',\n successStatusCode: 200,\n adapterToken: null,\n headers: {},\n httpMethod: 'GET',\n // @ts-expect-error We are using a generic type here\n config: null,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n metadata.add(newMetadata)\n return newMetadata\n }\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\nimport type { HandlerMetadata } from './handler.metadata.mjs'\n\nimport { getAllEndpointMetadata } from './handler.metadata.mjs'\n\nexport const ControllerMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ControllerMetadata {\n endpoints: Set<HandlerMetadata>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getControllerMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ControllerMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const endpointsMetadata = getAllEndpointMetadata(context)\n const newMetadata: ControllerMetadata = {\n endpoints: endpointsMetadata,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ControllerMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ControllerMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractControllerMetadata(\n target: ClassType,\n): ControllerMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (!metadata) {\n throw new Error(\n '[Navios] Controller metadata not found. Make sure to use @Controller decorator.',\n )\n }\n return metadata\n}\n\nexport function hasControllerMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n return !!metadata\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../index.mjs'\n\nexport const ModuleMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ModuleMetadata {\n controllers: Set<ClassType>\n imports: Set<ClassType>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getModuleMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ModuleMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ModuleMetadataKey] as\n | ModuleMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const newMetadata: ModuleMetadata = {\n controllers: new Set<ClassType>(),\n imports: new Set<ClassType>(),\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ModuleMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ModuleMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractModuleMetadata(target: ClassType): ModuleMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ModuleMetadataKey] as ModuleMetadata | undefined\n if (!metadata) {\n throw new Error(\n `[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`,\n )\n }\n return metadata\n}\n\nexport function hasModuleMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n return !!target[ModuleMetadataKey]\n}\n","import type { ClassType } from '@navios/di'\n\nimport { Injectable, InjectableScope, InjectionToken } from '@navios/di'\n\nimport { getControllerMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios controller.\n */\nexport interface ControllerOptions {\n /**\n * Guards to apply to all endpoints in this controller.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n}\n\n/**\n * Decorator that marks a class as a Navios controller.\n * \n * Controllers handle HTTP requests and define endpoints.\n * They are request-scoped by default, meaning a new instance is created for each request.\n * \n * @param options - Controller configuration options\n * @returns A class decorator\n * \n * @example\n * ```typescript\n * @Controller({ guards: [AuthGuard] })\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // Handle request\n * }\n * }\n * ```\n */\nexport function Controller({ guards }: ControllerOptions = {}) {\n return function (target: ClassType, context: ClassDecoratorContext) {\n if (context.kind !== 'class') {\n throw new Error(\n '[Navios] @Controller decorator can only be used on classes.',\n )\n }\n const token = InjectionToken.create(target)\n if (context.metadata) {\n const controllerMetadata = getControllerMetadata(target, context)\n if (guards) {\n for (const guard of Array.from(guards).reverse()) {\n controllerMetadata.guards.add(guard)\n }\n }\n }\n return Injectable({\n token,\n scope: InjectableScope.Request,\n })(target, context)\n }\n}\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const EndpointAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'EndpointAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractExecutionContext } from '../interfaces/index.mjs'\n\nexport const ExecutionContextInjectionToken = 'ExecutionContextInjectionToken'\n\nexport const ExecutionContext = InjectionToken.create<AbstractExecutionContext>(\n ExecutionContextInjectionToken,\n)\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpAdapterInterface } from '../interfaces/index.mjs'\n\nexport const HttpAdapterToken =\n InjectionToken.create<AbstractHttpAdapterInterface<any, any, any, any>>(\n 'HttpAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const MultipartAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'MultipartAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nexport const Reply = InjectionToken.create<any>('ReplyToken')\n","import { InjectionToken } from '@navios/di'\n\nexport const Request = InjectionToken.create<any>('RequestToken')\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const StreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'StreamAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const XmlStreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'XmlStreamAdapterToken',\n )\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { EndpointAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for an endpoint handler function.\n *\n * This utility type extracts URL parameters, query parameters, and request body\n * from an endpoint declaration and flattens them into a single object.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * querySchema: z.object({ include: z.string().optional() }),\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // request.urlParams.userId is typed as string\n * // request.query.include is typed as string | undefined\n * }\n * ```\n */\nexport type EndpointParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodType\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for an endpoint handler function.\n *\n * This utility type extracts the response schema from an endpoint declaration\n * and returns the appropriate Promise type.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {\n * return { id: '1', name: 'John' } // Type-checked against responseSchema\n * }\n * ```\n */\nexport type EndpointResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as an HTTP endpoint.\n *\n * The endpoint must be defined using @navios/builder's `declareEndpoint` method.\n * This ensures type safety and consistency between client and server.\n *\n * @param endpoint - The endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * import { builder } from '@navios/builder'\n *\n * const api = builder()\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * const { userId } = request.urlParams\n * return { id: userId, name: 'John' }\n * }\n * }\n * ```\n */\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n return (\n target: (\n params: QuerySchema extends ZodType\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n ) => Promise<z.input<ResponseSchema>>,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = EndpointAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type { HttpHeader } from '../interfaces/index.mjs'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP response header for an endpoint.\n * \n * @param name - The header name (e.g., 'Content-Type', 'Cache-Control')\n * @param value - The header value (string, number, or array of strings)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @Header('Cache-Control', 'max-age=3600')\n * async getUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function Header(name: HttpHeader, value: string | number | string[]) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error('[Navios] Header decorator can only be used on methods.')\n }\n const metadata = getEndpointMetadata(target, context)\n\n metadata.headers[name] = value\n\n return target\n }\n}\n","import { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP status code for successful responses.\n * \n * By default, endpoints return 200 OK. Use this decorator to return a different status code.\n * \n * @param code - The HTTP status code to return (e.g., 201, 204, 202)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(createUserEndpoint)\n * @HttpCode(201)\n * async createUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function HttpCode(code: number) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] HttpCode decorator can only be used on methods.',\n )\n }\n const metadata = getEndpointMetadata(target, context)\n metadata.successStatusCode = code\n\n return target\n }\n}\n","import type { ClassType } from '@navios/di'\n\nimport { Injectable, InjectableScope, InjectionToken } from '@navios/di'\n\nimport { getModuleMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios module.\n */\nexport interface ModuleOptions {\n /**\n * Controllers to register in this module.\n * Controllers handle HTTP requests and define endpoints.\n */\n controllers?: ClassType[] | Set<ClassType>\n /**\n * Other modules to import into this module.\n * Imported modules' controllers and services become available.\n */\n imports?: ClassType[] | Set<ClassType>\n /**\n * Guards to apply to all controllers in this module.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n}\n\n/**\n * Decorator that marks a class as a Navios module.\n * \n * Modules are the basic building blocks of a Navios application.\n * They organize controllers, services, and other modules into logical units.\n * \n * @param options - Module configuration options\n * @returns A class decorator\n * \n * @example\n * ```typescript\n * @Module({\n * controllers: [UserController, AuthController],\n * imports: [DatabaseModule],\n * guards: [AuthGuard],\n * })\n * export class AppModule {}\n * ```\n */\nexport function Module(\n { controllers = [], imports = [], guards = [] }: ModuleOptions = {\n controllers: [],\n imports: [],\n guards: [],\n },\n) {\n return (target: ClassType, context: ClassDecoratorContext) => {\n if (context.kind !== 'class') {\n throw new Error('[Navios] @Module decorator can only be used on classes.')\n }\n // Register the module in the service locator\n const token = InjectionToken.create(target)\n const moduleMetadata = getModuleMetadata(target, context)\n for (const controller of controllers) {\n moduleMetadata.controllers.add(controller)\n }\n for (const importedModule of imports) {\n moduleMetadata.imports.add(importedModule)\n }\n for (const guard of Array.from(guards).reverse()) {\n moduleMetadata.guards.add(guard)\n }\n\n return Injectable({\n token,\n scope: InjectableScope.Singleton,\n })(target, context)\n }\n}\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { MultipartAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a multipart endpoint handler function.\n * \n * Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.\n * \n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for a multipart endpoint handler function.\n * \n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as a multipart/form-data endpoint.\n * \n * Use this decorator for endpoints that handle file uploads or form data.\n * The endpoint must be defined using @navios/builder's `declareMultipart` method.\n * \n * @param endpoint - The multipart endpoint declaration from @navios/builder\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * const uploadFileEndpoint = api.declareMultipart({\n * method: 'post',\n * url: '/upload',\n * requestSchema: z.object({ file: z.instanceof(File) }),\n * responseSchema: z.object({ url: z.string() }),\n * })\n * \n * @Controller()\n * export class FileController {\n * @Multipart(uploadFileEndpoint)\n * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {\n * const { file } = request.data\n * // Handle file upload\n * return { url: 'https://example.com/file.jpg' }\n * }\n * }\n * ```\n */\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n return (\n target: (\n params: QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>\n : EndpointFunctionArgs<Url, QuerySchema, undefined>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema>\n : EndpointFunctionArgs<Url, undefined, undefined>,\n ) => Promise<z.input<ResponseSchema>>,\n context: ClassMethodDecoratorContext,\n ) => {\n if (typeof target !== 'function') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on functions.',\n )\n }\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = MultipartAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n BaseStreamConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { ZodObject, ZodType } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { StreamAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a stream endpoint handler function.\n * \n * Similar to `EndpointParams`, but specifically for streaming endpoints.\n * \n * @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder\n */\nexport type StreamParams<\n EndpointDeclaration extends {\n config: BaseStreamConfig<any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Decorator that marks a method as a streaming endpoint.\n * \n * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).\n * The endpoint must be defined using @navios/builder's `declareStream` method.\n * \n * @param endpoint - The stream endpoint declaration from @navios/builder\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * const downloadFileEndpoint = api.declareStream({\n * method: 'get',\n * url: '/files/$fileId',\n * })\n * \n * @Controller()\n * export class FileController {\n * @Stream(downloadFileEndpoint)\n * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {\n * const { fileId } = request.urlParams\n * // Stream file data to reply\n * }\n * }\n * ```\n */\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}) {\n return (\n target: (\n params: QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema>\n : EndpointFunctionArgs<Url, QuerySchema, undefined>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema>\n : EndpointFunctionArgs<Url, undefined, undefined>,\n reply: any,\n ) => Promise<void>,\n context: ClassMethodDecoratorContext,\n ) => {\n if (typeof target !== 'function') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on functions.',\n )\n }\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseStreamConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = StreamAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\n\nimport {\n getControllerMetadata,\n getEndpointMetadata,\n} from '../metadata/index.mjs'\n\n/**\n * Decorator that applies guards to a controller or endpoint.\n * \n * Guards are used for authentication, authorization, and request validation.\n * They implement the `CanActivate` interface and are executed before the endpoint handler.\n * Guards can be applied at the module, controller, or endpoint level.\n * \n * @param guards - Guard classes or injection tokens to apply\n * @returns A class or method decorator\n * \n * @example\n * ```typescript\n * // Apply to a controller\n * @Controller()\n * @UseGuards(AuthGuard, RoleGuard)\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser() { }\n * }\n * \n * // Apply to a specific endpoint\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @UseGuards(AuthGuard)\n * async getUser() { }\n * }\n * ```\n */\nexport function UseGuards(\n ...guards: (\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n )[]\n) {\n return function <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n ): T {\n if (context.kind === 'class') {\n const controllerMetadata = getControllerMetadata(\n target as unknown as ClassType,\n context,\n )\n for (const guard of guards.reverse()) {\n controllerMetadata.guards.add(guard)\n }\n } else if (context.kind === 'method') {\n const endpointMetadata = getEndpointMetadata(target, context)\n for (const guard of guards.reverse()) {\n endpointMetadata.guards.add(guard)\n }\n } else {\n throw new Error(\n '[Navios] @UseGuards decorator can only be used on classes or methods.',\n )\n }\n return target\n }\n}\n"],"mappings":";;;AASA,MAAaA,sBAAsBC,OAAO,sBAAA;AAmB1C,SAAgBC,uBACdC,SAA4D;AAE5D,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWD,QAAQC,SAASJ;AAGlC,MAAII,SACF,QAAOA;OACF;AACLD,WAAQC,SAASJ,uCAAuB,IAAIK,KAAAA;AAC5C,UAAOF,QAAQC,SAASJ;;;AAG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;;;;;;GC5EX,SAAgBe,OAKdC,UAED;AACC,SACEC,QAUAC,YAAAA;AAEA,MAAI,OAAOD,WAAW,WACpB,OAAM,IAAIE,MACR,6DAAA;AAGJ,MAAID,QAAQE,SAAS,SACnB,OAAM,IAAID,MACR,2DAAA;EAGJ,MAAME,SAASL,SAASK;AACxB,MAAIH,QAAQI,UAAU;GACpB,IAAIC,mBAAmBV,oBACrBI,QACAC,QAAAA;AAEF,OAAIK,iBAAiBF,UAAUE,iBAAiBF,OAAOG,IACrD,OAAM,IAAIL,MACR,qBAAqBE,OAAOI,OAAO,GAAGJ,OAAOG,IAAI,wDAAuD;AAI5GD,oBAAiBF,SAASA;AAC1BE,oBAAiBG,eAAeZ;AAChCS,oBAAiBI,cAAcV,OAAOW;AACtCL,oBAAiBM,aAAaR,OAAOI;AACrCF,oBAAiBC,MAAMH,OAAOG;;AAEhC,SAAOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GC/EX,SAAgBe,UACd,GAAGC,QAGA;AAEH,QAAO,SACLC,QACAC,SAA4D;AAE5D,MAAIA,QAAQC,SAAS,SAAS;GAC5B,MAAMC,qBAAqBP,sBACzBI,QACAC,QAAAA;AAEF,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCF,oBAAmBJ,OAAOO,IAAIF,MAAAA;aAEvBH,QAAQC,SAAS,UAAU;GACpC,MAAMK,mBAAmBV,oBAAoBG,QAAQC,QAAAA;AACrD,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCE,kBAAiBR,OAAOO,IAAIF,MAAAA;QAG9B,OAAM,IAAII,MACR,wEAAA;AAGJ,SAAOR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navios/core",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "author": {
5
5
  "name": "Oleksandr Hanzha",
6
6
  "email": "alex@granted.name"
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "peerDependencies": {
15
- "@navios/builder": "^0.3.0",
15
+ "@navios/builder": "^0.5.0",
16
16
  "zod": "^3.25.0 || ^4.0.0"
17
17
  },
18
18
  "typings": "./lib/index.d.mts",
@@ -28,17 +28,37 @@
28
28
  "types": "./lib/index.d.ts",
29
29
  "default": "./lib/index.js"
30
30
  }
31
+ },
32
+ "./testing": {
33
+ "import": {
34
+ "types": "./lib/testing/index.d.mts",
35
+ "default": "./lib/testing/index.mjs"
36
+ },
37
+ "require": {
38
+ "types": "./lib/testing/index.d.ts",
39
+ "default": "./lib/testing/index.js"
40
+ }
41
+ },
42
+ "./legacy-compat": {
43
+ "import": {
44
+ "types": "./lib/legacy-compat/index.d.mts",
45
+ "default": "./lib/legacy-compat/index.mjs"
46
+ },
47
+ "require": {
48
+ "types": "./lib/legacy-compat/index.d.ts",
49
+ "default": "./lib/legacy-compat/index.js"
50
+ }
31
51
  }
32
52
  },
33
53
  "devDependencies": {
34
- "@navios/builder": "^0.3.0",
54
+ "@navios/builder": "^0.5.0",
35
55
  "@types/supertest": "^6.0.3",
36
56
  "supertest": "^7.1.4",
37
- "tsx": "^4.20.6",
57
+ "tsx": "^4.21.0",
38
58
  "typescript": "^5.9.3",
39
- "zod": "^4.1.12"
59
+ "zod": "^4.1.13"
40
60
  },
41
61
  "dependencies": {
42
- "@navios/di": "^0.5.0"
62
+ "@navios/di": "^0.6.0"
43
63
  }
44
64
  }
package/project.json CHANGED
@@ -38,11 +38,11 @@
38
38
  },
39
39
  "build": {
40
40
  "executor": "nx:run-commands",
41
- "inputs": ["projectSources", "{projectRoot}/tsup.config.mts"],
41
+ "inputs": ["projectSources", "{projectRoot}/tsdown.config.mts"],
42
42
  "outputs": ["{projectRoot}/lib"],
43
43
  "dependsOn": ["check", "test:ci", "lint"],
44
44
  "options": {
45
- "command": "tsup",
45
+ "command": "tsdown",
46
46
  "cwd": "packages/core"
47
47
  }
48
48
  },
@@ -0,0 +1,175 @@
1
+ import type { z, ZodType } from 'zod/v4';
2
+ import type { ControllerMetadata, HandlerMetadata, ModuleMetadata } from './metadata/index.mjs';
3
+ /**
4
+ * Type for a class attribute decorator without a value.
5
+ *
6
+ * Attributes are custom metadata decorators that can be applied to modules,
7
+ * controllers, and endpoints.
8
+ */
9
+ export type ClassAttribute = (() => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
10
+ token: symbol;
11
+ };
12
+ /**
13
+ * Type for a class attribute decorator with a validated value.
14
+ *
15
+ * @typeParam T - The Zod schema type for validation
16
+ */
17
+ export type ClassSchemaAttribute<T extends ZodType> = ((value: z.input<T>) => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
18
+ token: symbol;
19
+ schema: ZodType;
20
+ };
21
+ /**
22
+ * Factory for creating custom attribute decorators.
23
+ *
24
+ * Attributes allow you to add custom metadata to modules, controllers, and endpoints.
25
+ * This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Create a simple boolean attribute
30
+ * const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
31
+ *
32
+ * // Use it as a decorator
33
+ * @Controller()
34
+ * @Public()
35
+ * export class PublicController { }
36
+ *
37
+ * // Check if attribute exists
38
+ * if (AttributeFactory.has(Public, controllerMetadata)) {
39
+ * // Skip authentication
40
+ * }
41
+ * ```
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Create an attribute with a validated value
46
+ * const RateLimit = AttributeFactory.createAttribute(
47
+ * Symbol.for('RateLimit'),
48
+ * z.object({ requests: z.number(), window: z.number() })
49
+ * )
50
+ *
51
+ * // Use it with a value
52
+ * @Endpoint(apiEndpoint)
53
+ * @RateLimit({ requests: 100, window: 60000 })
54
+ * async handler() { }
55
+ *
56
+ * // Get the value
57
+ * const limit = AttributeFactory.get(RateLimit, endpointMetadata)
58
+ * // limit is typed as { requests: number, window: number } | null
59
+ * ```
60
+ */
61
+ export declare class AttributeFactory {
62
+ /**
63
+ * Creates a simple attribute decorator without a value.
64
+ *
65
+ * @param token - A unique symbol to identify this attribute
66
+ * @returns A decorator function that can be applied to classes or methods
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
71
+ *
72
+ * @Public()
73
+ * @Controller()
74
+ * export class PublicController { }
75
+ * ```
76
+ */
77
+ static createAttribute(token: symbol): ClassAttribute;
78
+ /**
79
+ * Creates an attribute decorator with a validated value.
80
+ *
81
+ * @param token - A unique symbol to identify this attribute
82
+ * @param schema - A Zod schema to validate the attribute value
83
+ * @returns A decorator function that accepts a value and can be applied to classes or methods
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const RateLimit = AttributeFactory.createAttribute(
88
+ * Symbol.for('RateLimit'),
89
+ * z.object({ requests: z.number(), window: z.number() })
90
+ * )
91
+ *
92
+ * @RateLimit({ requests: 100, window: 60000 })
93
+ * @Endpoint(apiEndpoint)
94
+ * async handler() { }
95
+ * ```
96
+ */
97
+ static createAttribute<T extends ZodType>(token: symbol, schema: T): ClassSchemaAttribute<T>;
98
+ /**
99
+ * Gets the value of an attribute from metadata.
100
+ *
101
+ * Returns `null` if the attribute is not present.
102
+ * For simple attributes (without values), returns `true` if present.
103
+ *
104
+ * @param attribute - The attribute decorator
105
+ * @param target - The metadata object (module, controller, or handler)
106
+ * @returns The attribute value, `true` for simple attributes, or `null` if not found
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const isPublic = AttributeFactory.get(Public, controllerMetadata)
111
+ * // isPublic is true | null
112
+ *
113
+ * const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
114
+ * // rateLimit is { requests: number, window: number } | null
115
+ * ```
116
+ */
117
+ static get(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): true | null;
118
+ static get<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): z.output<T> | null;
119
+ /**
120
+ * Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
121
+ *
122
+ * Returns `null` if the attribute is not present.
123
+ *
124
+ * @param attribute - The attribute decorator
125
+ * @param target - The metadata object (module, controller, or handler)
126
+ * @returns An array of attribute values, or `null` if not found
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const tags = AttributeFactory.getAll(Tag, endpointMetadata)
131
+ * // tags is string[] | null
132
+ * ```
133
+ */
134
+ static getAll(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<true> | null;
135
+ static getAll<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<z.output<T>> | null;
136
+ /**
137
+ * Gets the last value of an attribute from an array of metadata objects.
138
+ *
139
+ * Searches from the end of the array backwards, useful for finding the most
140
+ * specific attribute value (e.g., endpoint-level overrides module-level).
141
+ *
142
+ * @param attribute - The attribute decorator
143
+ * @param target - An array of metadata objects (typically [module, controller, handler])
144
+ * @returns The last attribute value found, or `null` if not found
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Check attribute hierarchy: endpoint -> controller -> module
149
+ * const rateLimit = AttributeFactory.getLast(RateLimit, [
150
+ * moduleMetadata,
151
+ * controllerMetadata,
152
+ * endpointMetadata
153
+ * ])
154
+ * ```
155
+ */
156
+ static getLast(attribute: ClassAttribute, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): true | null;
157
+ static getLast<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): z.output<T> | null;
158
+ /**
159
+ * Checks if an attribute is present on the metadata object.
160
+ *
161
+ * @param attribute - The attribute decorator
162
+ * @param target - The metadata object (module, controller, or handler)
163
+ * @returns `true` if the attribute is present, `false` otherwise
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * if (AttributeFactory.has(Public, controllerMetadata)) {
168
+ * // Skip authentication
169
+ * }
170
+ * ```
171
+ */
172
+ static has(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
173
+ static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
174
+ }
175
+ //# sourceMappingURL=attribute.factory.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute.factory.d.mts","sourceRoot":"","sources":["attribute.factory.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAExC,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,sBAAsB,CAAA;AAU7B;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,CAAC,EACpC,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,qBAAqB,GAAG,2BAA2B,KACzD,CAAC,CAAC,GAAG;IACR,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,CACrD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACd,CAAC,CAAC,EACL,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,qBAAqB,GAAG,2BAA2B,KACzD,CAAC,CAAC,GAAG;IACR,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc;IACrD;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,eAAe,CAAC,CAAC,SAAS,OAAO,EACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,GACR,oBAAoB,CA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C,CAAC,GAAG,IAAI;IAcrB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,GAAG,CACR,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,cAAc,GAAG,kBAAkB,GAAG,eAAe,CAAC,GAAG,CAAC,GACjE,OAAO;IACV,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,OAAO,EAC1B,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAClC,MAAM,EAAE,cAAc,GAAG,kBAAkB,GAAG,eAAe,CAAC,GAAG,CAAC,GACjE,OAAO;CAOX"}
@@ -15,12 +15,24 @@ import {
15
15
  hasModuleMetadata,
16
16
  } from './metadata/index.mjs'
17
17
 
18
+ /**
19
+ * Type for a class attribute decorator without a value.
20
+ *
21
+ * Attributes are custom metadata decorators that can be applied to modules,
22
+ * controllers, and endpoints.
23
+ */
18
24
  export type ClassAttribute = (() => <T>(
19
25
  target: T,
20
26
  context: ClassDecoratorContext | ClassMethodDecoratorContext,
21
27
  ) => T) & {
22
28
  token: symbol
23
29
  }
30
+
31
+ /**
32
+ * Type for a class attribute decorator with a validated value.
33
+ *
34
+ * @typeParam T - The Zod schema type for validation
35
+ */
24
36
  export type ClassSchemaAttribute<T extends ZodType> = ((
25
37
  value: z.input<T>,
26
38
  ) => <T>(
@@ -31,8 +43,82 @@ export type ClassSchemaAttribute<T extends ZodType> = ((
31
43
  schema: ZodType
32
44
  }
33
45
 
46
+ /**
47
+ * Factory for creating custom attribute decorators.
48
+ *
49
+ * Attributes allow you to add custom metadata to modules, controllers, and endpoints.
50
+ * This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Create a simple boolean attribute
55
+ * const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
56
+ *
57
+ * // Use it as a decorator
58
+ * @Controller()
59
+ * @Public()
60
+ * export class PublicController { }
61
+ *
62
+ * // Check if attribute exists
63
+ * if (AttributeFactory.has(Public, controllerMetadata)) {
64
+ * // Skip authentication
65
+ * }
66
+ * ```
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Create an attribute with a validated value
71
+ * const RateLimit = AttributeFactory.createAttribute(
72
+ * Symbol.for('RateLimit'),
73
+ * z.object({ requests: z.number(), window: z.number() })
74
+ * )
75
+ *
76
+ * // Use it with a value
77
+ * @Endpoint(apiEndpoint)
78
+ * @RateLimit({ requests: 100, window: 60000 })
79
+ * async handler() { }
80
+ *
81
+ * // Get the value
82
+ * const limit = AttributeFactory.get(RateLimit, endpointMetadata)
83
+ * // limit is typed as { requests: number, window: number } | null
84
+ * ```
85
+ */
34
86
  export class AttributeFactory {
87
+ /**
88
+ * Creates a simple attribute decorator without a value.
89
+ *
90
+ * @param token - A unique symbol to identify this attribute
91
+ * @returns A decorator function that can be applied to classes or methods
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
96
+ *
97
+ * @Public()
98
+ * @Controller()
99
+ * export class PublicController { }
100
+ * ```
101
+ */
35
102
  static createAttribute(token: symbol): ClassAttribute
103
+ /**
104
+ * Creates an attribute decorator with a validated value.
105
+ *
106
+ * @param token - A unique symbol to identify this attribute
107
+ * @param schema - A Zod schema to validate the attribute value
108
+ * @returns A decorator function that accepts a value and can be applied to classes or methods
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const RateLimit = AttributeFactory.createAttribute(
113
+ * Symbol.for('RateLimit'),
114
+ * z.object({ requests: z.number(), window: z.number() })
115
+ * )
116
+ *
117
+ * @RateLimit({ requests: 100, window: 60000 })
118
+ * @Endpoint(apiEndpoint)
119
+ * async handler() { }
120
+ * ```
121
+ */
36
122
  static createAttribute<T extends ZodType>(
37
123
  token: symbol,
38
124
  schema: T,
@@ -84,6 +170,25 @@ export class AttributeFactory {
84
170
  return res
85
171
  }
86
172
 
173
+ /**
174
+ * Gets the value of an attribute from metadata.
175
+ *
176
+ * Returns `null` if the attribute is not present.
177
+ * For simple attributes (without values), returns `true` if present.
178
+ *
179
+ * @param attribute - The attribute decorator
180
+ * @param target - The metadata object (module, controller, or handler)
181
+ * @returns The attribute value, `true` for simple attributes, or `null` if not found
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const isPublic = AttributeFactory.get(Public, controllerMetadata)
186
+ * // isPublic is true | null
187
+ *
188
+ * const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
189
+ * // rateLimit is { requests: number, window: number } | null
190
+ * ```
191
+ */
87
192
  static get(
88
193
  attribute: ClassAttribute,
89
194
  target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
@@ -99,6 +204,21 @@ export class AttributeFactory {
99
204
  return target.customAttributes.get(attribute.token) ?? null
100
205
  }
101
206
 
207
+ /**
208
+ * Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
209
+ *
210
+ * Returns `null` if the attribute is not present.
211
+ *
212
+ * @param attribute - The attribute decorator
213
+ * @param target - The metadata object (module, controller, or handler)
214
+ * @returns An array of attribute values, or `null` if not found
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * const tags = AttributeFactory.getAll(Tag, endpointMetadata)
219
+ * // tags is string[] | null
220
+ * ```
221
+ */
102
222
  static getAll(
103
223
  attribute: ClassAttribute,
104
224
  target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
@@ -117,6 +237,26 @@ export class AttributeFactory {
117
237
  return values.length > 0 ? values : null
118
238
  }
119
239
 
240
+ /**
241
+ * Gets the last value of an attribute from an array of metadata objects.
242
+ *
243
+ * Searches from the end of the array backwards, useful for finding the most
244
+ * specific attribute value (e.g., endpoint-level overrides module-level).
245
+ *
246
+ * @param attribute - The attribute decorator
247
+ * @param target - An array of metadata objects (typically [module, controller, handler])
248
+ * @returns The last attribute value found, or `null` if not found
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * // Check attribute hierarchy: endpoint -> controller -> module
253
+ * const rateLimit = AttributeFactory.getLast(RateLimit, [
254
+ * moduleMetadata,
255
+ * controllerMetadata,
256
+ * endpointMetadata
257
+ * ])
258
+ * ```
259
+ */
120
260
  static getLast(
121
261
  attribute: ClassAttribute,
122
262
  target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
@@ -138,6 +278,20 @@ export class AttributeFactory {
138
278
  return null
139
279
  }
140
280
 
281
+ /**
282
+ * Checks if an attribute is present on the metadata object.
283
+ *
284
+ * @param attribute - The attribute decorator
285
+ * @param target - The metadata object (module, controller, or handler)
286
+ * @returns `true` if the attribute is present, `false` otherwise
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * if (AttributeFactory.has(Public, controllerMetadata)) {
291
+ * // Skip authentication
292
+ * }
293
+ * ```
294
+ */
141
295
  static has(
142
296
  attribute: ClassAttribute,
143
297
  target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
@@ -0,0 +1,39 @@
1
+ import type { Path, PathValue } from './types.mjs';
2
+ /**
3
+ * Interface for configuration service implementations.
4
+ *
5
+ * Provides type-safe access to configuration values with support for nested paths.
6
+ *
7
+ * @typeParam Config - The configuration object type
8
+ */
9
+ export interface ConfigServiceInterface<Config = Record<string, unknown>> {
10
+ /**
11
+ * Gets the entire configuration object.
12
+ */
13
+ getConfig: () => Config;
14
+ /**
15
+ * Gets a configuration value by key path. Returns `null` if not found.
16
+ *
17
+ * @param key - Dot-separated path to the configuration value (e.g., 'database.host')
18
+ * @returns The configuration value or `null` if not found
19
+ */
20
+ get: <Key extends Path<Config>>(key: Key) => PathValue<Config, Key> | null;
21
+ /**
22
+ * Gets a configuration value by key path, or returns a default value if not found.
23
+ *
24
+ * @param key - Dot-separated path to the configuration value
25
+ * @param defaultValue - Default value to return if the key is not found
26
+ * @returns The configuration value or the default value
27
+ */
28
+ getOrDefault: <Key extends Path<Config>>(key: Key, defaultValue: PathValue<Config, Key>) => PathValue<Config, Key>;
29
+ /**
30
+ * Gets a configuration value by key path, or throws an error if not found.
31
+ *
32
+ * @param key - Dot-separated path to the configuration value
33
+ * @param errorMessage - Optional custom error message
34
+ * @returns The configuration value
35
+ * @throws Error if the key is not found
36
+ */
37
+ getOrThrow: <Key extends Path<Config>>(key: Key, errorMessage?: string) => PathValue<Config, Key>;
38
+ }
39
+ //# sourceMappingURL=config-service.interface.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-service.interface.d.mts","sourceRoot":"","sources":["config-service.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAElD;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtE;;OAEG;IACH,SAAS,EAAE,MAAM,MAAM,CAAA;IACvB;;;;;OAKG;IACH,GAAG,EAAE,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAE1E;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EACrC,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,KACjC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE3B;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,EACnC,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,KAClB,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B"}
@@ -1,14 +1,45 @@
1
1
  import type { Path, PathValue } from './types.mjs'
2
2
 
3
+ /**
4
+ * Interface for configuration service implementations.
5
+ *
6
+ * Provides type-safe access to configuration values with support for nested paths.
7
+ *
8
+ * @typeParam Config - The configuration object type
9
+ */
3
10
  export interface ConfigServiceInterface<Config = Record<string, unknown>> {
11
+ /**
12
+ * Gets the entire configuration object.
13
+ */
4
14
  getConfig: () => Config
15
+ /**
16
+ * Gets a configuration value by key path. Returns `null` if not found.
17
+ *
18
+ * @param key - Dot-separated path to the configuration value (e.g., 'database.host')
19
+ * @returns The configuration value or `null` if not found
20
+ */
5
21
  get: <Key extends Path<Config>>(key: Key) => PathValue<Config, Key> | null
6
22
 
23
+ /**
24
+ * Gets a configuration value by key path, or returns a default value if not found.
25
+ *
26
+ * @param key - Dot-separated path to the configuration value
27
+ * @param defaultValue - Default value to return if the key is not found
28
+ * @returns The configuration value or the default value
29
+ */
7
30
  getOrDefault: <Key extends Path<Config>>(
8
31
  key: Key,
9
32
  defaultValue: PathValue<Config, Key>,
10
33
  ) => PathValue<Config, Key>
11
34
 
35
+ /**
36
+ * Gets a configuration value by key path, or throws an error if not found.
37
+ *
38
+ * @param key - Dot-separated path to the configuration value
39
+ * @param errorMessage - Optional custom error message
40
+ * @returns The configuration value
41
+ * @throws Error if the key is not found
42
+ */
12
43
  getOrThrow: <Key extends Path<Config>>(
13
44
  key: Key,
14
45
  errorMessage?: string,