@navios/core 1.1.0 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +53 -11
  2. package/README.md +67 -220
  3. package/lib/async-context-6pdlnNLA.d.mts +237 -0
  4. package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
  5. package/lib/async-context-Dqk7pE-D.d.cts +237 -0
  6. package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
  7. package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
  8. package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
  9. package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
  10. package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
  11. package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
  12. package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
  13. package/lib/attribute-value-DMEA255r.mjs +119 -0
  14. package/lib/attribute-value-DMEA255r.mjs.map +1 -0
  15. package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
  16. package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
  17. package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
  18. package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
  19. package/lib/execution-context-BPD3FeFb.d.mts +71 -0
  20. package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
  21. package/lib/execution-context-BTJdHhbf.d.cts +71 -0
  22. package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
  23. package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
  24. package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
  25. package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
  26. package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
  27. package/lib/index.cjs +1687 -4424
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +838 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +838 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1573 -4219
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bha7GER_.mjs +135 -0
  44. package/lib/module-Bha7GER_.mjs.map +1 -0
  45. package/lib/module-DZewk_2r.cjs +164 -0
  46. package/lib/module-DZewk_2r.cjs.map +1 -0
  47. package/lib/module-graph-DCP9MHG0.cjs +147 -0
  48. package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
  49. package/lib/module-graph-xvVEykFM.mjs +142 -0
  50. package/lib/module-graph-xvVEykFM.mjs.map +1 -0
  51. package/lib/module-metadata-C8S92seK.cjs +95 -0
  52. package/lib/module-metadata-C8S92seK.cjs.map +1 -0
  53. package/lib/module-metadata-k3RTt20x.mjs +66 -0
  54. package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
  55. package/lib/module-options-Dmse0gii.d.mts +51 -0
  56. package/lib/module-options-Dmse0gii.d.mts.map +1 -0
  57. package/lib/module-options-IuDO-p8u.d.cts +51 -0
  58. package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
  59. package/lib/testing/index.cjs +96 -414
  60. package/lib/testing/index.cjs.map +1 -1
  61. package/lib/testing/index.d.cts +25 -385
  62. package/lib/testing/index.d.cts.map +1 -1
  63. package/lib/testing/index.d.mts +24 -385
  64. package/lib/testing/index.d.mts.map +1 -1
  65. package/lib/testing/index.mjs +94 -408
  66. package/lib/testing/index.mjs.map +1 -1
  67. package/lib/transport.cjs +25 -0
  68. package/lib/transport.d.cts +190 -0
  69. package/lib/transport.d.cts.map +1 -0
  70. package/lib/transport.d.mts +190 -0
  71. package/lib/transport.d.mts.map +1 -0
  72. package/lib/transport.mjs +7 -0
  73. package/package.json +37 -17
  74. package/docs/README.md +0 -316
  75. package/docs/adapters.md +0 -308
  76. package/docs/application-setup.md +0 -524
  77. package/docs/attributes.md +0 -689
  78. package/docs/controllers.md +0 -373
  79. package/docs/endpoints.md +0 -444
  80. package/docs/exceptions.md +0 -352
  81. package/docs/guards.md +0 -550
  82. package/docs/legacy-compat.md +0 -356
  83. package/docs/modules.md +0 -377
  84. package/docs/quick-start.md +0 -290
  85. package/docs/services.md +0 -427
  86. package/docs/testing.md +0 -827
  87. package/lib/index-3LcTrbxz.d.mts +0 -3804
  88. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  89. package/lib/index-B14SekVb.d.cts +0 -3804
  90. package/lib/index-B14SekVb.d.cts.map +0 -1
  91. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  92. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  93. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  94. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  95. package/lib/tokens-BEuBMGGX.cjs +0 -193
  96. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  97. package/lib/tokens-COyNGV1I.mjs +0 -97
  98. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  99. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  100. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  101. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  102. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  103. package/project.json +0 -66
  104. package/src/__tests__/attribute.factory.spec.mts +0 -300
  105. package/src/__tests__/config.service.spec.mts +0 -43
  106. package/src/__tests__/console-logger.service.spec.mts +0 -312
  107. package/src/__tests__/controller-resolver.spec.mts +0 -229
  108. package/src/__tests__/controller.spec.mts +0 -58
  109. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  110. package/src/__tests__/logger.service.spec.mts +0 -147
  111. package/src/__tests__/responders.spec.mts +0 -340
  112. package/src/__tests__/testing-module.spec.mts +0 -459
  113. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  114. package/src/attribute.factory.mts +0 -325
  115. package/src/config/config-service.interface.mts +0 -47
  116. package/src/config/config.provider.mts +0 -69
  117. package/src/config/config.service.mts +0 -176
  118. package/src/config/index.mts +0 -5
  119. package/src/config/types.mts +0 -58
  120. package/src/config/utils/helpers.mts +0 -23
  121. package/src/config/utils/index.mts +0 -1
  122. package/src/decorators/controller.decorator.mts +0 -81
  123. package/src/decorators/endpoint.decorator.mts +0 -181
  124. package/src/decorators/header.decorator.mts +0 -38
  125. package/src/decorators/http-code.decorator.mts +0 -38
  126. package/src/decorators/index.mts +0 -8
  127. package/src/decorators/module.decorator.mts +0 -106
  128. package/src/decorators/multipart.decorator.mts +0 -169
  129. package/src/decorators/stream.decorator.mts +0 -155
  130. package/src/decorators/use-guards.decorator.mts +0 -73
  131. package/src/exceptions/bad-request.exception.mts +0 -28
  132. package/src/exceptions/conflict.exception.mts +0 -31
  133. package/src/exceptions/forbidden.exception.mts +0 -30
  134. package/src/exceptions/http.exception.mts +0 -33
  135. package/src/exceptions/index.mts +0 -7
  136. package/src/exceptions/internal-server-error.exception.mts +0 -33
  137. package/src/exceptions/not-found.exception.mts +0 -33
  138. package/src/exceptions/unauthorized.exception.mts +0 -30
  139. package/src/factories/adapter.factory.mts +0 -20
  140. package/src/factories/endpoint-adapter.factory.mts +0 -21
  141. package/src/factories/http-adapter.factory.mts +0 -20
  142. package/src/factories/index.mts +0 -8
  143. package/src/factories/multipart-adapter.factory.mts +0 -21
  144. package/src/factories/reply.factory.mts +0 -21
  145. package/src/factories/request.factory.mts +0 -21
  146. package/src/factories/stream-adapter.factory.mts +0 -20
  147. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  148. package/src/index.mts +0 -16
  149. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  150. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  151. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  152. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  153. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  154. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  155. package/src/interfaces/adapter-environment.interface.mts +0 -74
  156. package/src/interfaces/can-activate.mts +0 -38
  157. package/src/interfaces/http-header.mts +0 -18
  158. package/src/interfaces/index.mts +0 -14
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin-context.mts +0 -104
  161. package/src/interfaces/plugin-stage.mts +0 -62
  162. package/src/interfaces/plugin.interface.mts +0 -119
  163. package/src/interfaces/staged-plugin.interface.mts +0 -209
  164. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  165. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  166. package/src/legacy-compat/attribute.factory.mts +0 -351
  167. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  168. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  169. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  170. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  171. package/src/legacy-compat/decorators/index.mts +0 -11
  172. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  173. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  174. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  175. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  176. package/src/legacy-compat/index.mts +0 -57
  177. package/src/logger/README.md +0 -3
  178. package/src/logger/console-logger.service.mts +0 -714
  179. package/src/logger/index.mts +0 -6
  180. package/src/logger/log-levels.mts +0 -21
  181. package/src/logger/logger-service.interface.mts +0 -42
  182. package/src/logger/logger.service.mts +0 -113
  183. package/src/logger/logger.tokens.mts +0 -44
  184. package/src/logger/utils/cli-colors.util.mts +0 -17
  185. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  186. package/src/logger/utils/index.mts +0 -5
  187. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  188. package/src/logger/utils/is-log-level.util.mts +0 -10
  189. package/src/logger/utils/shared.utils.mts +0 -51
  190. package/src/metadata/controller.metadata.mts +0 -79
  191. package/src/metadata/handler.metadata.mts +0 -80
  192. package/src/metadata/index.mts +0 -4
  193. package/src/metadata/module.metadata.mts +0 -116
  194. package/src/metadata/navios-managed.metadata.mts +0 -42
  195. package/src/navios.application.mts +0 -678
  196. package/src/navios.environment.mts +0 -42
  197. package/src/navios.factory.mts +0 -158
  198. package/src/responders/enums/framework-error.enum.mts +0 -38
  199. package/src/responders/enums/index.mts +0 -1
  200. package/src/responders/index.mts +0 -4
  201. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  202. package/src/responders/interfaces/error-response.interface.mts +0 -22
  203. package/src/responders/interfaces/index.mts +0 -3
  204. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  205. package/src/responders/services/error-response-producer.service.mts +0 -143
  206. package/src/responders/services/forbidden-responder.service.mts +0 -77
  207. package/src/responders/services/index.mts +0 -5
  208. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  209. package/src/responders/services/not-found-responder.service.mts +0 -76
  210. package/src/responders/services/validation-error-responder.service.mts +0 -78
  211. package/src/responders/tokens/index.mts +0 -1
  212. package/src/responders/tokens/responder.tokens.mts +0 -84
  213. package/src/services/abstract-handler-adapter.service.mts +0 -366
  214. package/src/services/guard-runner.service.mts +0 -152
  215. package/src/services/index.mts +0 -4
  216. package/src/services/instance-resolver.service.mts +0 -177
  217. package/src/services/module-loader.service.mts +0 -255
  218. package/src/stores/index.mts +0 -1
  219. package/src/stores/request-id.store.mts +0 -85
  220. package/src/testing/index.mts +0 -3
  221. package/src/testing/testing-module.mts +0 -393
  222. package/src/testing/unit-testing-module.mts +0 -298
  223. package/src/tokens/adapter.token.mts +0 -6
  224. package/src/tokens/endpoint-adapter.token.mts +0 -8
  225. package/src/tokens/execution-context.token.mts +0 -9
  226. package/src/tokens/http-adapter.token.mts +0 -8
  227. package/src/tokens/index.mts +0 -10
  228. package/src/tokens/multipart-adapter.token.mts +0 -8
  229. package/src/tokens/navios-options.token.mts +0 -6
  230. package/src/tokens/reply.token.mts +0 -3
  231. package/src/tokens/request.token.mts +0 -3
  232. package/src/tokens/stream-adapter.token.mts +0 -8
  233. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  234. package/src/utils/adapter-supports.util.mts +0 -47
  235. package/src/utils/define-plugin.mts +0 -251
  236. package/src/utils/index.mts +0 -2
  237. package/tsconfig.json +0 -21
  238. package/tsconfig.lib.json +0 -8
  239. package/tsconfig.spec.json +0 -15
  240. package/tsdown.config.mts +0 -35
  241. package/vitest.config.mts +0 -15
@@ -1,4151 +0,0 @@
1
- import { a as NaviosOptionsToken, d as AdapterToken, p as extractModuleMetadata } from "./tokens-COyNGV1I.mjs";
2
- import { Container, Injectable, InjectableScope, InjectionToken, getInjectableToken, inject, optional } from "@navios/di";
3
- import z from "zod/v4";
4
- import { inspect } from "util";
5
- import { AsyncLocalStorage } from "node:async_hooks";
6
-
7
- //#region src/logger/utils/cli-colors.util.mts
8
- const isColorAllowed = () => !process.env.NO_COLOR;
9
- const colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
10
- const clc = {
11
- bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
12
- green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
13
- yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
14
- red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
15
- magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
16
- cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
17
- };
18
- const yellow = colorIfAllowed((text) => `\x1B[38;5;3m${text}\x1B[39m`);
19
-
20
- //#endregion
21
- //#region src/logger/log-levels.mts
22
- /**
23
- * Available log levels in order of severity (lowest to highest).
24
- */ const LOG_LEVELS = [
25
- "verbose",
26
- "debug",
27
- "log",
28
- "warn",
29
- "error",
30
- "fatal"
31
- ];
32
-
33
- //#endregion
34
- //#region src/logger/utils/is-log-level.util.mts
35
- /**
36
- * @publicApi
37
- */ function isLogLevel(maybeLogLevel) {
38
- return LOG_LEVELS.includes(maybeLogLevel);
39
- }
40
-
41
- //#endregion
42
- //#region src/logger/utils/filter-log-levelts.util.mts
43
- /**
44
- * @publicApi
45
- */ function filterLogLevels(parseableString = "") {
46
- const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
47
- if (sanitizedString[0] === ">") {
48
- const orEqual = sanitizedString[1] === "=";
49
- const logLevelIndex = LOG_LEVELS.indexOf(sanitizedString.substring(orEqual ? 2 : 1));
50
- if (logLevelIndex === -1) throw new Error(`parse error (unknown log level): ${sanitizedString}`);
51
- return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
52
- } else if (sanitizedString.includes(",")) return sanitizedString.split(",").filter(isLogLevel);
53
- return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
54
- }
55
-
56
- //#endregion
57
- //#region src/logger/utils/is-log-level-enabled.mts
58
- const LOG_LEVEL_VALUES = {
59
- verbose: 0,
60
- debug: 1,
61
- log: 2,
62
- warn: 3,
63
- error: 4,
64
- fatal: 5
65
- };
66
- /**
67
- * Checks if target level is enabled.
68
- * @param targetLevel target level
69
- * @param logLevels array of enabled log levels
70
- */ function isLogLevelEnabled(targetLevel, logLevels) {
71
- if (!logLevels || Array.isArray(logLevels) && logLevels?.length === 0) return false;
72
- if (logLevels.includes(targetLevel)) return true;
73
- const highestLogLevelValue = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)?.[0];
74
- return LOG_LEVEL_VALUES[targetLevel] >= highestLogLevelValue;
75
- }
76
-
77
- //#endregion
78
- //#region src/logger/utils/shared.utils.mts
79
- const isUndefined = (obj) => typeof obj === "undefined";
80
- const isObject = (fn) => !isNil(fn) && typeof fn === "object";
81
- const isPlainObject = (fn) => {
82
- if (!isObject(fn)) return false;
83
- const proto = Object.getPrototypeOf(fn);
84
- if (proto === null) return true;
85
- const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
86
- return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
87
- };
88
- const addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
89
- const normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
90
- const stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
91
- const isFunction = (val) => typeof val === "function";
92
- const isString = (val) => typeof val === "string";
93
- const isNumber = (val) => typeof val === "number";
94
- const isConstructor = (val) => val === "constructor";
95
- const isNil = (val) => isUndefined(val) || val === null;
96
- const isEmpty = (array) => !(array && array.length > 0);
97
- const isSymbol = (val) => typeof val === "symbol";
98
-
99
- //#endregion
100
- //#region src/stores/request-id.store.mts
101
- let requestCounter = 0;
102
- /**
103
- * Generates a simple incremental request ID.
104
- * Much faster than crypto.randomUUID() and sufficient for request tracking.
105
- *
106
- * @returns A unique request ID string (e.g., "req-1", "req-2", ...)
107
- */ function generateRequestId() {
108
- return `req-${++requestCounter}`;
109
- }
110
- /**
111
- * AsyncLocalStorage store for the current request ID.
112
- *
113
- * This allows logging and other services to access the current request ID
114
- * without explicitly passing it through the call stack.
115
- *
116
- * @example
117
- * ```typescript
118
- * import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
119
- *
120
- * // Run code with a request ID in context
121
- * runWithRequestId('req-123', () => {
122
- * // Inside this callback, getRequestId() returns 'req-123'
123
- * logger.log('Processing request') // Will include request ID if logger is configured
124
- * })
125
- *
126
- * // Get current request ID (returns undefined if not in a request context)
127
- * const currentId = getRequestId()
128
- * ```
129
- */ let requestIdStore = null;
130
- function getRequestIdStore() {
131
- if (!requestIdStore) requestIdStore = new AsyncLocalStorage();
132
- return requestIdStore;
133
- }
134
- /**
135
- * Whether request ID propagation is enabled.
136
- * When disabled, runWithRequestId is a pass-through for better performance.
137
- */ let requestIdEnabled = false;
138
- /**
139
- * Enables or disables request ID propagation.
140
- * Called by NaviosFactory based on the enableRequestId option.
141
- *
142
- * @param enabled - Whether to enable request ID propagation
143
- */ function setRequestIdEnabled(enabled) {
144
- requestIdEnabled = enabled;
145
- }
146
- /**
147
- * Runs a function with a request ID in the async local storage context.
148
- * If request ID propagation is disabled, the function is called directly
149
- * without AsyncLocalStorage overhead.
150
- *
151
- * @param requestId - The request ID to set for this context
152
- * @param fn - The function to run within this context
153
- * @returns The return value of the function
154
- */ function runWithRequestId(requestId, fn) {
155
- if (!requestIdEnabled) return fn();
156
- return getRequestIdStore().run(requestId, fn);
157
- }
158
- /**
159
- * Gets the current request ID from the async local storage context.
160
- *
161
- * @returns The current request ID, or undefined if not in a request context
162
- */ function getRequestId() {
163
- if (!requestIdEnabled) return;
164
- return getRequestIdStore().getStore();
165
- }
166
-
167
- //#endregion
168
- //#region src/logger/logger.tokens.mts
169
- /**
170
- * Injection token for the logger output service.
171
- *
172
- * This token is used to provide a custom logger implementation.
173
- * By default, it's bound to ConsoleLogger.
174
- */ const LoggerOutput = InjectionToken.create("LoggerOutput");
175
- /**
176
- * Schema for logger options.
177
- */ const loggerOptionsSchema = z.object({ context: z.string().optional() }).optional();
178
- /**
179
- * Injection token for the Logger service.
180
- *
181
- * Use this token to inject a contextualized logger instance.
182
- *
183
- * @example
184
- * ```typescript
185
- * const logger = inject(Logger, { context: 'MyService' })
186
- * logger.log('Hello world') // Logs with context: [MyService]
187
- * ```
188
- */ const Logger = InjectionToken.create("Logger", loggerOptionsSchema);
189
-
190
- //#endregion
191
- //#region src/logger/console-logger.service.mts
192
- function applyDecs2203RFactory$7() {
193
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
194
- return function addInitializer(initializer) {
195
- assertNotFinished(decoratorFinishedRef, "addInitializer");
196
- assertCallable(initializer, "An initializer");
197
- initializers.push(initializer);
198
- };
199
- }
200
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
201
- var kindStr;
202
- switch (kind) {
203
- case 1:
204
- kindStr = "accessor";
205
- break;
206
- case 2:
207
- kindStr = "method";
208
- break;
209
- case 3:
210
- kindStr = "getter";
211
- break;
212
- case 4:
213
- kindStr = "setter";
214
- break;
215
- default: kindStr = "field";
216
- }
217
- var ctx = {
218
- kind: kindStr,
219
- name: isPrivate ? "#" + name : name,
220
- static: isStatic,
221
- private: isPrivate,
222
- metadata
223
- };
224
- var decoratorFinishedRef = { v: false };
225
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
226
- var get, set;
227
- if (kind === 0) if (isPrivate) {
228
- get = desc.get;
229
- set = desc.set;
230
- } else {
231
- get = function() {
232
- return this[name];
233
- };
234
- set = function(v) {
235
- this[name] = v;
236
- };
237
- }
238
- else if (kind === 2) get = function() {
239
- return desc.value;
240
- };
241
- else {
242
- if (kind === 1 || kind === 3) get = function() {
243
- return desc.get.call(this);
244
- };
245
- if (kind === 1 || kind === 4) set = function(v) {
246
- desc.set.call(this, v);
247
- };
248
- }
249
- ctx.access = get && set ? {
250
- get,
251
- set
252
- } : get ? { get } : { set };
253
- try {
254
- return dec(value, ctx);
255
- } finally {
256
- decoratorFinishedRef.v = true;
257
- }
258
- }
259
- function assertNotFinished(decoratorFinishedRef, fnName) {
260
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
261
- }
262
- function assertCallable(fn, hint) {
263
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
264
- }
265
- function assertValidReturnValue(kind, value) {
266
- var type = typeof value;
267
- if (kind === 1) {
268
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
269
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
270
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
271
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
272
- } else if (type !== "function") {
273
- var hint;
274
- if (kind === 0) hint = "field";
275
- else if (kind === 10) hint = "class";
276
- else hint = "method";
277
- throw new TypeError(hint + " decorators must return a function or void 0");
278
- }
279
- }
280
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
281
- var decs = decInfo[0];
282
- var desc, init, value;
283
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
284
- get: decInfo[3],
285
- set: decInfo[4]
286
- };
287
- else if (kind === 3) desc = { get: decInfo[3] };
288
- else if (kind === 4) desc = { set: decInfo[3] };
289
- else desc = { value: decInfo[3] };
290
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
291
- if (kind === 1) value = {
292
- get: desc.get,
293
- set: desc.set
294
- };
295
- else if (kind === 2) value = desc.value;
296
- else if (kind === 3) value = desc.get;
297
- else if (kind === 4) value = desc.set;
298
- var newValue, get, set;
299
- if (typeof decs === "function") {
300
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
301
- if (newValue !== void 0) {
302
- assertValidReturnValue(kind, newValue);
303
- if (kind === 0) init = newValue;
304
- else if (kind === 1) {
305
- init = newValue.init;
306
- get = newValue.get || value.get;
307
- set = newValue.set || value.set;
308
- value = {
309
- get,
310
- set
311
- };
312
- } else value = newValue;
313
- }
314
- } else for (var i = decs.length - 1; i >= 0; i--) {
315
- var dec = decs[i];
316
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
317
- if (newValue !== void 0) {
318
- assertValidReturnValue(kind, newValue);
319
- var newInit;
320
- if (kind === 0) newInit = newValue;
321
- else if (kind === 1) {
322
- newInit = newValue.init;
323
- get = newValue.get || value.get;
324
- set = newValue.set || value.set;
325
- value = {
326
- get,
327
- set
328
- };
329
- } else value = newValue;
330
- if (newInit !== void 0) if (init === void 0) init = newInit;
331
- else if (typeof init === "function") init = [init, newInit];
332
- else init.push(newInit);
333
- }
334
- }
335
- if (kind === 0 || kind === 1) {
336
- if (init === void 0) init = function(instance, init$1) {
337
- return init$1;
338
- };
339
- else if (typeof init !== "function") {
340
- var ownInitializers = init;
341
- init = function(instance, init$1) {
342
- var value$1 = init$1;
343
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
344
- return value$1;
345
- };
346
- } else {
347
- var originalInitializer = init;
348
- init = function(instance, init$1) {
349
- return originalInitializer.call(instance, init$1);
350
- };
351
- }
352
- ret.push(init);
353
- }
354
- if (kind !== 0) {
355
- if (kind === 1) {
356
- desc.get = value.get;
357
- desc.set = value.set;
358
- } else if (kind === 2) desc.value = value;
359
- else if (kind === 3) desc.get = value;
360
- else if (kind === 4) desc.set = value;
361
- if (isPrivate) if (kind === 1) {
362
- ret.push(function(instance, args) {
363
- return value.get.call(instance, args);
364
- });
365
- ret.push(function(instance, args) {
366
- return value.set.call(instance, args);
367
- });
368
- } else if (kind === 2) ret.push(value);
369
- else ret.push(function(instance, args) {
370
- return value.call(instance, args);
371
- });
372
- else Object.defineProperty(base, name, desc);
373
- }
374
- }
375
- function applyMemberDecs(Class, decInfos, metadata) {
376
- var ret = [];
377
- var protoInitializers;
378
- var staticInitializers;
379
- var existingProtoNonFields = /* @__PURE__ */ new Map();
380
- var existingStaticNonFields = /* @__PURE__ */ new Map();
381
- for (var i = 0; i < decInfos.length; i++) {
382
- var decInfo = decInfos[i];
383
- if (!Array.isArray(decInfo)) continue;
384
- var kind = decInfo[1];
385
- var name = decInfo[2];
386
- var isPrivate = decInfo.length > 3;
387
- var isStatic = kind >= 5;
388
- var base;
389
- var initializers;
390
- if (isStatic) {
391
- base = Class;
392
- kind = kind - 5;
393
- staticInitializers = staticInitializers || [];
394
- initializers = staticInitializers;
395
- } else {
396
- base = Class.prototype;
397
- protoInitializers = protoInitializers || [];
398
- initializers = protoInitializers;
399
- }
400
- if (kind !== 0 && !isPrivate) {
401
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
402
- var existingKind = existingNonFields.get(name) || 0;
403
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
404
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
405
- else existingNonFields.set(name, true);
406
- }
407
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
408
- }
409
- pushInitializers(ret, protoInitializers);
410
- pushInitializers(ret, staticInitializers);
411
- return ret;
412
- }
413
- function pushInitializers(ret, initializers) {
414
- if (initializers) ret.push(function(instance) {
415
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
416
- return instance;
417
- });
418
- }
419
- function applyClassDecs(targetClass, classDecs, metadata) {
420
- if (classDecs.length > 0) {
421
- var initializers = [];
422
- var newClass = targetClass;
423
- var name = targetClass.name;
424
- for (var i = classDecs.length - 1; i >= 0; i--) {
425
- var decoratorFinishedRef = { v: false };
426
- try {
427
- var nextNewClass = classDecs[i](newClass, {
428
- kind: "class",
429
- name,
430
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
431
- metadata
432
- });
433
- } finally {
434
- decoratorFinishedRef.v = true;
435
- }
436
- if (nextNewClass !== void 0) {
437
- assertValidReturnValue(10, nextNewClass);
438
- newClass = nextNewClass;
439
- }
440
- }
441
- return [defineMetadata(newClass, metadata), function() {
442
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
443
- }];
444
- }
445
- }
446
- function defineMetadata(Class, metadata) {
447
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
448
- configurable: true,
449
- enumerable: true,
450
- value: metadata
451
- });
452
- }
453
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
454
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
455
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
456
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
457
- if (!classDecs.length) defineMetadata(targetClass, metadata);
458
- return {
459
- e,
460
- get c() {
461
- return applyClassDecs(targetClass, classDecs, metadata);
462
- }
463
- };
464
- };
465
- }
466
- function _apply_decs_2203_r$7(targetClass, memberDecs, classDecs, parentClass) {
467
- return (_apply_decs_2203_r$7 = applyDecs2203RFactory$7())(targetClass, memberDecs, classDecs, parentClass);
468
- }
469
- function _identity(x) {
470
- return x;
471
- }
472
- var _dec$7, _initClass$7;
473
- const DEFAULT_DEPTH = 5;
474
- const DEFAULT_LOG_LEVELS = [
475
- "log",
476
- "error",
477
- "warn",
478
- "debug",
479
- "verbose",
480
- "fatal"
481
- ];
482
- const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
483
- year: "numeric",
484
- hour: "numeric",
485
- minute: "numeric",
486
- second: "numeric",
487
- day: "2-digit",
488
- month: "2-digit"
489
- });
490
- let _ConsoleLogger;
491
- _dec$7 = Injectable({ token: LoggerOutput });
492
- new class extends _identity {
493
- constructor() {
494
- super(_ConsoleLogger), _initClass$7();
495
- }
496
- static {
497
- class ConsoleLogger {
498
- static {
499
- ({c: [_ConsoleLogger, _initClass$7]} = _apply_decs_2203_r$7(this, [], [_dec$7]));
500
- }
501
- static create(contextOrOptions, options) {
502
- const logger = new ConsoleLogger();
503
- if (contextOrOptions !== void 0) if (typeof contextOrOptions === "string") logger.setup(contextOrOptions, options ?? {});
504
- else logger.setup(contextOrOptions);
505
- else logger.setup();
506
- return logger;
507
- }
508
- /**
509
- * The options of the logger.
510
- */ options = {};
511
- /**
512
- * The context of the logger (can be set manually or automatically inferred).
513
- */ context;
514
- /**
515
- * The original context of the logger (set in the constructor).
516
- */ originalContext;
517
- /**
518
- * The options used for the "inspect" method.
519
- */ inspectOptions = this.getInspectOptions();
520
- /**
521
- * The last timestamp at which the log message was printed.
522
- */ lastTimestampAt;
523
- setup(contextOrOptions, options) {
524
- let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions?.context, contextOrOptions];
525
- opts = opts ?? {};
526
- opts.logLevels ??= DEFAULT_LOG_LEVELS;
527
- opts.colors ??= opts.colors ?? (opts.json ? false : true);
528
- opts.prefix ??= "Navios";
529
- this.options = opts;
530
- this.inspectOptions = this.getInspectOptions();
531
- if (context) {
532
- this.context = context;
533
- this.originalContext = context;
534
- }
535
- }
536
- log(message, ...optionalParams) {
537
- if (!this.isLevelEnabled("log")) return;
538
- const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
539
- this.printMessages(messages, context, "log");
540
- }
541
- error(message, ...optionalParams) {
542
- if (!this.isLevelEnabled("error")) return;
543
- const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
544
- this.printMessages(messages, context, "error", void 0, "stderr", stack);
545
- this.printStackTrace(stack);
546
- }
547
- warn(message, ...optionalParams) {
548
- if (!this.isLevelEnabled("warn")) return;
549
- const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
550
- this.printMessages(messages, context, "warn");
551
- }
552
- debug(message, ...optionalParams) {
553
- if (!this.isLevelEnabled("debug")) return;
554
- const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
555
- this.printMessages(messages, context, "debug");
556
- }
557
- verbose(message, ...optionalParams) {
558
- if (!this.isLevelEnabled("verbose")) return;
559
- const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
560
- this.printMessages(messages, context, "verbose");
561
- }
562
- fatal(message, ...optionalParams) {
563
- if (!this.isLevelEnabled("fatal")) return;
564
- const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
565
- this.printMessages(messages, context, "fatal");
566
- }
567
- /**
568
- * Set log levels
569
- * @param levels log levels
570
- */ setLogLevels(levels) {
571
- if (!this.options) this.options = {};
572
- this.options.logLevels = levels;
573
- }
574
- /**
575
- * Set logger context
576
- * @param context context
577
- */ setContext(context) {
578
- this.context = context;
579
- }
580
- /**
581
- * Resets the logger context to the value that was passed in the constructor.
582
- */ resetContext() {
583
- this.context = this.originalContext;
584
- }
585
- isLevelEnabled(level) {
586
- const logLevels = this.options?.logLevels;
587
- return isLogLevelEnabled(level, logLevels);
588
- }
589
- /**
590
- * Gets the current request ID from the AsyncLocalStorage store.
591
- * Only returns a value if the requestId option is enabled.
592
- */ getCurrentRequestId() {
593
- if (!this.options.requestId) return;
594
- return getRequestId();
595
- }
596
- getTimestamp() {
597
- return dateTimeFormatter.format(Date.now());
598
- }
599
- printMessages(messages, context = "", logLevel = "log", requestId, writeStreamType, errorStack) {
600
- const resolvedRequestId = requestId ?? this.getCurrentRequestId();
601
- messages.forEach((message) => {
602
- if (this.options.json) {
603
- this.printAsJson(message, {
604
- context,
605
- logLevel,
606
- writeStreamType,
607
- errorStack,
608
- requestId: resolvedRequestId
609
- });
610
- return;
611
- }
612
- const pidMessage = this.formatPid(process.pid);
613
- const contextMessage = this.formatContext(context);
614
- const timestampDiff = this.updateAndGetTimestampDiff();
615
- const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
616
- const formattedMessage = this.formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff, resolvedRequestId);
617
- process[writeStreamType ?? "stdout"].write(formattedMessage);
618
- });
619
- }
620
- printAsJson(message, options) {
621
- const logObject = {
622
- level: options.logLevel,
623
- pid: process.pid,
624
- timestamp: Date.now(),
625
- message
626
- };
627
- if (options.context) logObject.context = options.context;
628
- if (options.errorStack) logObject.stack = options.errorStack;
629
- if (this.options.requestId && options.requestId) logObject.requestId = options.requestId;
630
- const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : inspect(logObject, this.inspectOptions);
631
- process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}\n`);
632
- }
633
- formatPid(pid) {
634
- const showPrefix = this.options.showPrefix ?? true;
635
- const showPid = this.options.showPid ?? true;
636
- if (!showPrefix && !showPid) return "";
637
- const prefix = showPrefix ? `[${this.options.prefix}]` : "";
638
- const pidPart = showPid ? `${pid}` : "";
639
- return `${prefix}${showPrefix && showPid ? " " : ""}${pidPart}${showPrefix || showPid ? " - " : ""}`;
640
- }
641
- formatContext(context) {
642
- const showContext = this.options.showContext ?? true;
643
- if (!context || !showContext) return "";
644
- context = `[${context}] `;
645
- return this.options.colors ? yellow(context) : context;
646
- }
647
- formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff, requestId) {
648
- const output = this.stringifyMessage(message, logLevel);
649
- const showLogLevel = this.options.showLogLevel ?? true;
650
- const showTimestamp = this.options.showTimestamp ?? true;
651
- pidMessage = this.colorize(pidMessage, logLevel);
652
- formattedLogLevel = showLogLevel ? this.colorize(formattedLogLevel, logLevel) : "";
653
- const timestamp = showTimestamp ? this.getTimestamp() : "";
654
- const requestIdPart = this.getRequestId(requestId);
655
- const parts = [];
656
- if (pidMessage) parts.push(pidMessage.trimEnd());
657
- if (requestIdPart) parts.push(requestIdPart.trimEnd());
658
- if (timestamp) parts.push(timestamp);
659
- if (formattedLogLevel) parts.push(formattedLogLevel);
660
- if (contextMessage) parts.push(contextMessage.trimEnd());
661
- return `${parts.length > 0 ? parts.join(" ") + " " : ""}${output}${timestampDiff}\n`;
662
- }
663
- getRequestId(requestId) {
664
- if (this.options.requestId && requestId) return `(${this.colorize(requestId, "log")}) `;
665
- return "";
666
- }
667
- stringifyMessage(message, logLevel) {
668
- if (isFunction(message)) {
669
- if (Function.prototype.toString.call(message).startsWith("class ")) return this.stringifyMessage(message.name, logLevel);
670
- return this.stringifyMessage(message(), logLevel);
671
- }
672
- if (typeof message === "string") return this.colorize(message, logLevel);
673
- const outputText = inspect(message, this.inspectOptions);
674
- if (isPlainObject(message)) return `Object(${Object.keys(message).length}) ${outputText}`;
675
- if (Array.isArray(message)) return `Array(${message.length}) ${outputText}`;
676
- return outputText;
677
- }
678
- colorize(message, logLevel) {
679
- if (!this.options.colors || this.options.json) return message;
680
- return this.getColorByLogLevel(logLevel)(message);
681
- }
682
- printStackTrace(stack) {
683
- if (!stack || this.options.json) return;
684
- process.stderr.write(`${stack}\n`);
685
- }
686
- updateAndGetTimestampDiff() {
687
- const showTimeDiff = this.options?.showTimeDiff ?? false;
688
- const result = this.lastTimestampAt && showTimeDiff ? this.formatTimestampDiff(Date.now() - this.lastTimestampAt) : "";
689
- this.lastTimestampAt = Date.now();
690
- return result;
691
- }
692
- formatTimestampDiff(timestampDiff) {
693
- const formattedDiff = ` +${timestampDiff}ms`;
694
- return this.options.colors ? yellow(formattedDiff) : formattedDiff;
695
- }
696
- getInspectOptions() {
697
- let breakLength = this.options.breakLength;
698
- if (typeof breakLength === "undefined") breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
699
- const inspectOptions = {
700
- depth: this.options.depth ?? DEFAULT_DEPTH,
701
- sorted: this.options.sorted,
702
- showHidden: this.options.showHidden,
703
- compact: this.options.compact ?? (this.options.json ? true : false),
704
- colors: this.options.colors,
705
- breakLength
706
- };
707
- if (this.options.maxArrayLength) inspectOptions.maxArrayLength = this.options.maxArrayLength;
708
- if (this.options.maxStringLength) inspectOptions.maxStringLength = this.options.maxStringLength;
709
- return inspectOptions;
710
- }
711
- stringifyReplacer(key, value) {
712
- if (typeof value === "bigint") return value.toString();
713
- if (typeof value === "symbol") return value.toString();
714
- if (value instanceof Map || value instanceof Set || value instanceof Error) return `${inspect(value, this.inspectOptions)}`;
715
- return value;
716
- }
717
- getContextAndMessagesToPrint(args) {
718
- if (args?.length <= 1) return {
719
- messages: args,
720
- context: this.context
721
- };
722
- const lastElement = args[args.length - 1];
723
- if (!isString(lastElement)) return {
724
- messages: args,
725
- context: this.context
726
- };
727
- return {
728
- context: lastElement,
729
- messages: args.slice(0, args.length - 1)
730
- };
731
- }
732
- getContextAndStackAndMessagesToPrint(args) {
733
- if (args.length === 2) return this.isStackFormat(args[1]) ? {
734
- messages: [args[0]],
735
- stack: args[1],
736
- context: this.context
737
- } : {
738
- messages: [args[0]],
739
- context: args[1]
740
- };
741
- const { messages, context } = this.getContextAndMessagesToPrint(args);
742
- if (messages?.length <= 1) return {
743
- messages,
744
- context
745
- };
746
- const lastElement = messages[messages.length - 1];
747
- if (!isString(lastElement) && !isUndefined(lastElement)) return {
748
- messages,
749
- context
750
- };
751
- return {
752
- stack: lastElement,
753
- messages: messages.slice(0, messages.length - 1),
754
- context
755
- };
756
- }
757
- isStackFormat(stack) {
758
- if (!isString(stack) && !isUndefined(stack)) return false;
759
- return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
760
- }
761
- getColorByLogLevel(level) {
762
- switch (level) {
763
- case "debug": return clc.magentaBright;
764
- case "warn": return clc.yellow;
765
- case "error": return clc.red;
766
- case "verbose": return clc.cyanBright;
767
- case "fatal": return clc.bold;
768
- default: return clc.green;
769
- }
770
- }
771
- }
772
- }
773
- }();
774
-
775
- //#endregion
776
- //#region src/logger/logger.service.mts
777
- function applyDecs2203RFactory$6() {
778
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
779
- return function addInitializer(initializer) {
780
- assertNotFinished(decoratorFinishedRef, "addInitializer");
781
- assertCallable(initializer, "An initializer");
782
- initializers.push(initializer);
783
- };
784
- }
785
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
786
- var kindStr;
787
- switch (kind) {
788
- case 1:
789
- kindStr = "accessor";
790
- break;
791
- case 2:
792
- kindStr = "method";
793
- break;
794
- case 3:
795
- kindStr = "getter";
796
- break;
797
- case 4:
798
- kindStr = "setter";
799
- break;
800
- default: kindStr = "field";
801
- }
802
- var ctx = {
803
- kind: kindStr,
804
- name: isPrivate ? "#" + name : name,
805
- static: isStatic,
806
- private: isPrivate,
807
- metadata
808
- };
809
- var decoratorFinishedRef = { v: false };
810
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
811
- var get, set;
812
- if (kind === 0) if (isPrivate) {
813
- get = desc.get;
814
- set = desc.set;
815
- } else {
816
- get = function() {
817
- return this[name];
818
- };
819
- set = function(v) {
820
- this[name] = v;
821
- };
822
- }
823
- else if (kind === 2) get = function() {
824
- return desc.value;
825
- };
826
- else {
827
- if (kind === 1 || kind === 3) get = function() {
828
- return desc.get.call(this);
829
- };
830
- if (kind === 1 || kind === 4) set = function(v) {
831
- desc.set.call(this, v);
832
- };
833
- }
834
- ctx.access = get && set ? {
835
- get,
836
- set
837
- } : get ? { get } : { set };
838
- try {
839
- return dec(value, ctx);
840
- } finally {
841
- decoratorFinishedRef.v = true;
842
- }
843
- }
844
- function assertNotFinished(decoratorFinishedRef, fnName) {
845
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
846
- }
847
- function assertCallable(fn, hint) {
848
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
849
- }
850
- function assertValidReturnValue(kind, value) {
851
- var type = typeof value;
852
- if (kind === 1) {
853
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
854
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
855
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
856
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
857
- } else if (type !== "function") {
858
- var hint;
859
- if (kind === 0) hint = "field";
860
- else if (kind === 10) hint = "class";
861
- else hint = "method";
862
- throw new TypeError(hint + " decorators must return a function or void 0");
863
- }
864
- }
865
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
866
- var decs = decInfo[0];
867
- var desc, init, value;
868
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
869
- get: decInfo[3],
870
- set: decInfo[4]
871
- };
872
- else if (kind === 3) desc = { get: decInfo[3] };
873
- else if (kind === 4) desc = { set: decInfo[3] };
874
- else desc = { value: decInfo[3] };
875
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
876
- if (kind === 1) value = {
877
- get: desc.get,
878
- set: desc.set
879
- };
880
- else if (kind === 2) value = desc.value;
881
- else if (kind === 3) value = desc.get;
882
- else if (kind === 4) value = desc.set;
883
- var newValue, get, set;
884
- if (typeof decs === "function") {
885
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
886
- if (newValue !== void 0) {
887
- assertValidReturnValue(kind, newValue);
888
- if (kind === 0) init = newValue;
889
- else if (kind === 1) {
890
- init = newValue.init;
891
- get = newValue.get || value.get;
892
- set = newValue.set || value.set;
893
- value = {
894
- get,
895
- set
896
- };
897
- } else value = newValue;
898
- }
899
- } else for (var i = decs.length - 1; i >= 0; i--) {
900
- var dec = decs[i];
901
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
902
- if (newValue !== void 0) {
903
- assertValidReturnValue(kind, newValue);
904
- var newInit;
905
- if (kind === 0) newInit = newValue;
906
- else if (kind === 1) {
907
- newInit = newValue.init;
908
- get = newValue.get || value.get;
909
- set = newValue.set || value.set;
910
- value = {
911
- get,
912
- set
913
- };
914
- } else value = newValue;
915
- if (newInit !== void 0) if (init === void 0) init = newInit;
916
- else if (typeof init === "function") init = [init, newInit];
917
- else init.push(newInit);
918
- }
919
- }
920
- if (kind === 0 || kind === 1) {
921
- if (init === void 0) init = function(instance, init$1) {
922
- return init$1;
923
- };
924
- else if (typeof init !== "function") {
925
- var ownInitializers = init;
926
- init = function(instance, init$1) {
927
- var value$1 = init$1;
928
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
929
- return value$1;
930
- };
931
- } else {
932
- var originalInitializer = init;
933
- init = function(instance, init$1) {
934
- return originalInitializer.call(instance, init$1);
935
- };
936
- }
937
- ret.push(init);
938
- }
939
- if (kind !== 0) {
940
- if (kind === 1) {
941
- desc.get = value.get;
942
- desc.set = value.set;
943
- } else if (kind === 2) desc.value = value;
944
- else if (kind === 3) desc.get = value;
945
- else if (kind === 4) desc.set = value;
946
- if (isPrivate) if (kind === 1) {
947
- ret.push(function(instance, args) {
948
- return value.get.call(instance, args);
949
- });
950
- ret.push(function(instance, args) {
951
- return value.set.call(instance, args);
952
- });
953
- } else if (kind === 2) ret.push(value);
954
- else ret.push(function(instance, args) {
955
- return value.call(instance, args);
956
- });
957
- else Object.defineProperty(base, name, desc);
958
- }
959
- }
960
- function applyMemberDecs(Class, decInfos, metadata) {
961
- var ret = [];
962
- var protoInitializers;
963
- var staticInitializers;
964
- var existingProtoNonFields = /* @__PURE__ */ new Map();
965
- var existingStaticNonFields = /* @__PURE__ */ new Map();
966
- for (var i = 0; i < decInfos.length; i++) {
967
- var decInfo = decInfos[i];
968
- if (!Array.isArray(decInfo)) continue;
969
- var kind = decInfo[1];
970
- var name = decInfo[2];
971
- var isPrivate = decInfo.length > 3;
972
- var isStatic = kind >= 5;
973
- var base;
974
- var initializers;
975
- if (isStatic) {
976
- base = Class;
977
- kind = kind - 5;
978
- staticInitializers = staticInitializers || [];
979
- initializers = staticInitializers;
980
- } else {
981
- base = Class.prototype;
982
- protoInitializers = protoInitializers || [];
983
- initializers = protoInitializers;
984
- }
985
- if (kind !== 0 && !isPrivate) {
986
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
987
- var existingKind = existingNonFields.get(name) || 0;
988
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
989
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
990
- else existingNonFields.set(name, true);
991
- }
992
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
993
- }
994
- pushInitializers(ret, protoInitializers);
995
- pushInitializers(ret, staticInitializers);
996
- return ret;
997
- }
998
- function pushInitializers(ret, initializers) {
999
- if (initializers) ret.push(function(instance) {
1000
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1001
- return instance;
1002
- });
1003
- }
1004
- function applyClassDecs(targetClass, classDecs, metadata) {
1005
- if (classDecs.length > 0) {
1006
- var initializers = [];
1007
- var newClass = targetClass;
1008
- var name = targetClass.name;
1009
- for (var i = classDecs.length - 1; i >= 0; i--) {
1010
- var decoratorFinishedRef = { v: false };
1011
- try {
1012
- var nextNewClass = classDecs[i](newClass, {
1013
- kind: "class",
1014
- name,
1015
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1016
- metadata
1017
- });
1018
- } finally {
1019
- decoratorFinishedRef.v = true;
1020
- }
1021
- if (nextNewClass !== void 0) {
1022
- assertValidReturnValue(10, nextNewClass);
1023
- newClass = nextNewClass;
1024
- }
1025
- }
1026
- return [defineMetadata(newClass, metadata), function() {
1027
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1028
- }];
1029
- }
1030
- }
1031
- function defineMetadata(Class, metadata) {
1032
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1033
- configurable: true,
1034
- enumerable: true,
1035
- value: metadata
1036
- });
1037
- }
1038
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1039
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1040
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1041
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
1042
- if (!classDecs.length) defineMetadata(targetClass, metadata);
1043
- return {
1044
- e,
1045
- get c() {
1046
- return applyClassDecs(targetClass, classDecs, metadata);
1047
- }
1048
- };
1049
- };
1050
- }
1051
- function _apply_decs_2203_r$6(targetClass, memberDecs, classDecs, parentClass) {
1052
- return (_apply_decs_2203_r$6 = applyDecs2203RFactory$6())(targetClass, memberDecs, classDecs, parentClass);
1053
- }
1054
- var _dec$6, _initClass$6;
1055
- let _LoggerInstance;
1056
- _dec$6 = Injectable({ token: Logger });
1057
- var LoggerInstance = class {
1058
- static {
1059
- ({c: [_LoggerInstance, _initClass$6]} = _apply_decs_2203_r$6(this, [], [_dec$6]));
1060
- }
1061
- constructor(config = {}) {
1062
- this.context = config.context;
1063
- }
1064
- localInstance = inject(LoggerOutput);
1065
- context;
1066
- error(message, ...optionalParams) {
1067
- optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(this.context) : optionalParams;
1068
- this.localInstance?.error(message, ...optionalParams);
1069
- }
1070
- log(message, ...optionalParams) {
1071
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1072
- this.localInstance?.log(message, ...optionalParams);
1073
- }
1074
- warn(message, ...optionalParams) {
1075
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1076
- this.localInstance?.warn(message, ...optionalParams);
1077
- }
1078
- debug(message, ...optionalParams) {
1079
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1080
- this.localInstance?.debug?.(message, ...optionalParams);
1081
- }
1082
- verbose(message, ...optionalParams) {
1083
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1084
- this.localInstance?.verbose?.(message, ...optionalParams);
1085
- }
1086
- fatal(message, ...optionalParams) {
1087
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1088
- this.localInstance?.fatal?.(message, ...optionalParams);
1089
- }
1090
- static {
1091
- _initClass$6();
1092
- }
1093
- };
1094
-
1095
- //#endregion
1096
- //#region src/exceptions/http.exception.mts
1097
- /**
1098
- * Base exception class for all HTTP exceptions in Navios.
1099
- *
1100
- * All HTTP exception classes extend this base class. When thrown from an endpoint handler,
1101
- * Navios will automatically convert it to an appropriate HTTP response with the specified
1102
- * status code and response body.
1103
- *
1104
- * @example
1105
- * ```typescript
1106
- * @Endpoint(getUserEndpoint)
1107
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
1108
- * const user = await this.userService.findById(request.urlParams.userId)
1109
- * if (!user) {
1110
- * throw new HttpException(404, 'User not found')
1111
- * }
1112
- * return user
1113
- * }
1114
- * ```
1115
- */ var HttpException = class {
1116
- statusCode;
1117
- response;
1118
- error;
1119
- /**
1120
- * Creates a new HttpException instance.
1121
- *
1122
- * @param statusCode - HTTP status code (e.g., 400, 404, 500)
1123
- * @param response - Response body (string or object)
1124
- * @param error - Optional underlying error for logging/debugging
1125
- */ constructor(statusCode, response, error) {
1126
- this.statusCode = statusCode;
1127
- this.response = response;
1128
- this.error = error;
1129
- }
1130
- };
1131
-
1132
- //#endregion
1133
- //#region src/interfaces/plugin-stage.mts
1134
- /**
1135
- * Base stage names (without pre:/post: prefix)
1136
- */
1137
- const PluginStageBase = {
1138
- MODULES_TRAVERSE: "modules-traverse",
1139
- ADAPTER_RESOLVE: "adapter-resolve",
1140
- ADAPTER_SETUP: "adapter-setup",
1141
- MODULES_INIT: "modules-init",
1142
- READY: "ready"
1143
- };
1144
- /**
1145
- * Helper to create pre stage name from base
1146
- */
1147
- const preStage = (base) => `pre:${base}`;
1148
- /**
1149
- * Helper to create post stage name from base
1150
- */
1151
- const postStage = (base) => `post:${base}`;
1152
- /**
1153
- * All stages as constants for direct access
1154
- */
1155
- const PluginStages = {
1156
- PRE_MODULES_TRAVERSE: "pre:modules-traverse",
1157
- POST_MODULES_TRAVERSE: "post:modules-traverse",
1158
- PRE_ADAPTER_RESOLVE: "pre:adapter-resolve",
1159
- POST_ADAPTER_RESOLVE: "post:adapter-resolve",
1160
- PRE_ADAPTER_SETUP: "pre:adapter-setup",
1161
- POST_ADAPTER_SETUP: "post:adapter-setup",
1162
- PRE_MODULES_INIT: "pre:modules-init",
1163
- POST_MODULES_INIT: "post:modules-init",
1164
- PRE_READY: "pre:ready",
1165
- POST_READY: "post:ready"
1166
- };
1167
- /**
1168
- * All stages in execution order
1169
- */
1170
- const PLUGIN_STAGES_ORDER = [
1171
- PluginStages.PRE_MODULES_TRAVERSE,
1172
- PluginStages.POST_MODULES_TRAVERSE,
1173
- PluginStages.PRE_ADAPTER_RESOLVE,
1174
- PluginStages.POST_ADAPTER_RESOLVE,
1175
- PluginStages.PRE_ADAPTER_SETUP,
1176
- PluginStages.POST_ADAPTER_SETUP,
1177
- PluginStages.PRE_MODULES_INIT,
1178
- PluginStages.POST_MODULES_INIT,
1179
- PluginStages.PRE_READY,
1180
- PluginStages.POST_READY
1181
- ];
1182
-
1183
- //#endregion
1184
- //#region src/responders/enums/framework-error.enum.mts
1185
- /**
1186
- * Enumeration of framework-level error types.
1187
- * Used to explicitly specify which error responder should handle an error.
1188
- *
1189
- * @example
1190
- * ```typescript
1191
- * // In adapter error handling
1192
- * if (error instanceof ZodError) {
1193
- * return errorProducer.respond(FrameworkError.ValidationError, error)
1194
- * }
1195
- * return errorProducer.handleUnknown(error)
1196
- * ```
1197
- */ var FrameworkError = /* @__PURE__ */ function(FrameworkError$1) {
1198
- /**
1199
- * Resource not found (HTTP 404).
1200
- * Use when a requested resource does not exist.
1201
- */ FrameworkError$1["NotFound"] = "NotFound";
1202
- /**
1203
- * Forbidden (HTTP 403).
1204
- * Use when access to a resource is denied (e.g., guard rejection).
1205
- */ FrameworkError$1["Forbidden"] = "Forbidden";
1206
- /**
1207
- * Internal server error (HTTP 500).
1208
- * Use for unexpected errors that don't fit other categories.
1209
- */ FrameworkError$1["InternalServerError"] = "InternalServerError";
1210
- /**
1211
- * Validation error (HTTP 400).
1212
- * Use when request data fails validation (e.g., Zod errors).
1213
- */ FrameworkError$1["ValidationError"] = "ValidationError";
1214
- return FrameworkError$1;
1215
- }({});
1216
-
1217
- //#endregion
1218
- //#region src/responders/tokens/responder.tokens.mts
1219
- /**
1220
- * Injection token for the Internal Server Error responder.
1221
- * Default implementation returns HTTP 500 with RFC 7807 Problem Details.
1222
- *
1223
- * @example Override with custom implementation:
1224
- * ```typescript
1225
- * @Injectable({
1226
- * token: InternalServerErrorResponderToken,
1227
- * priority: 0, // Higher than default -10
1228
- * })
1229
- * export class CustomInternalErrorResponder implements ErrorResponder {
1230
- * getResponse(error: unknown, description?: string): ErrorResponse {
1231
- * // Custom implementation
1232
- * }
1233
- * }
1234
- * ```
1235
- */ const InternalServerErrorResponderToken = InjectionToken.create("InternalServerErrorResponder");
1236
- /**
1237
- * Injection token for the Not Found responder.
1238
- * Default implementation returns HTTP 404 with RFC 7807 Problem Details.
1239
- *
1240
- * @example Override with custom implementation:
1241
- * ```typescript
1242
- * @Injectable({
1243
- * token: NotFoundResponderToken,
1244
- * priority: 0, // Higher than default -10
1245
- * })
1246
- * export class CustomNotFoundResponder implements ErrorResponder {
1247
- * getResponse(error: unknown, description?: string): ErrorResponse {
1248
- * // Custom implementation
1249
- * }
1250
- * }
1251
- * ```
1252
- */ const NotFoundResponderToken = InjectionToken.create("NotFoundResponder");
1253
- /**
1254
- * Injection token for the Validation Error responder.
1255
- * Default implementation returns HTTP 400 with RFC 7807 Problem Details
1256
- * and includes validation errors from ZodError.
1257
- *
1258
- * @example Override with custom implementation:
1259
- * ```typescript
1260
- * @Injectable({
1261
- * token: ValidationErrorResponderToken,
1262
- * priority: 0, // Higher than default -10
1263
- * })
1264
- * export class CustomValidationResponder implements ErrorResponder {
1265
- * getResponse(error: unknown, description?: string): ErrorResponse {
1266
- * // Custom implementation
1267
- * }
1268
- * }
1269
- * ```
1270
- */ const ValidationErrorResponderToken = InjectionToken.create("ValidationErrorResponder");
1271
- /**
1272
- * Injection token for the Forbidden responder.
1273
- * Default implementation returns HTTP 403 with RFC 7807 Problem Details.
1274
- *
1275
- * @example Override with custom implementation:
1276
- * ```typescript
1277
- * @Injectable({
1278
- * token: ForbiddenResponderToken,
1279
- * priority: 0, // Higher than default -10
1280
- * })
1281
- * export class CustomForbiddenResponder implements ErrorResponder {
1282
- * getResponse(error: unknown, description?: string): ErrorResponse {
1283
- * // Custom implementation
1284
- * }
1285
- * }
1286
- * ```
1287
- */ const ForbiddenResponderToken = InjectionToken.create("ForbiddenResponder");
1288
-
1289
- //#endregion
1290
- //#region src/responders/services/error-response-producer.service.mts
1291
- function applyDecs2203RFactory$5() {
1292
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1293
- return function addInitializer(initializer) {
1294
- assertNotFinished(decoratorFinishedRef, "addInitializer");
1295
- assertCallable(initializer, "An initializer");
1296
- initializers.push(initializer);
1297
- };
1298
- }
1299
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
1300
- var kindStr;
1301
- switch (kind) {
1302
- case 1:
1303
- kindStr = "accessor";
1304
- break;
1305
- case 2:
1306
- kindStr = "method";
1307
- break;
1308
- case 3:
1309
- kindStr = "getter";
1310
- break;
1311
- case 4:
1312
- kindStr = "setter";
1313
- break;
1314
- default: kindStr = "field";
1315
- }
1316
- var ctx = {
1317
- kind: kindStr,
1318
- name: isPrivate ? "#" + name : name,
1319
- static: isStatic,
1320
- private: isPrivate,
1321
- metadata
1322
- };
1323
- var decoratorFinishedRef = { v: false };
1324
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
1325
- var get, set;
1326
- if (kind === 0) if (isPrivate) {
1327
- get = desc.get;
1328
- set = desc.set;
1329
- } else {
1330
- get = function() {
1331
- return this[name];
1332
- };
1333
- set = function(v) {
1334
- this[name] = v;
1335
- };
1336
- }
1337
- else if (kind === 2) get = function() {
1338
- return desc.value;
1339
- };
1340
- else {
1341
- if (kind === 1 || kind === 3) get = function() {
1342
- return desc.get.call(this);
1343
- };
1344
- if (kind === 1 || kind === 4) set = function(v) {
1345
- desc.set.call(this, v);
1346
- };
1347
- }
1348
- ctx.access = get && set ? {
1349
- get,
1350
- set
1351
- } : get ? { get } : { set };
1352
- try {
1353
- return dec(value, ctx);
1354
- } finally {
1355
- decoratorFinishedRef.v = true;
1356
- }
1357
- }
1358
- function assertNotFinished(decoratorFinishedRef, fnName) {
1359
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
1360
- }
1361
- function assertCallable(fn, hint) {
1362
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
1363
- }
1364
- function assertValidReturnValue(kind, value) {
1365
- var type = typeof value;
1366
- if (kind === 1) {
1367
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
1368
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
1369
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
1370
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
1371
- } else if (type !== "function") {
1372
- var hint;
1373
- if (kind === 0) hint = "field";
1374
- else if (kind === 10) hint = "class";
1375
- else hint = "method";
1376
- throw new TypeError(hint + " decorators must return a function or void 0");
1377
- }
1378
- }
1379
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
1380
- var decs = decInfo[0];
1381
- var desc, init, value;
1382
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
1383
- get: decInfo[3],
1384
- set: decInfo[4]
1385
- };
1386
- else if (kind === 3) desc = { get: decInfo[3] };
1387
- else if (kind === 4) desc = { set: decInfo[3] };
1388
- else desc = { value: decInfo[3] };
1389
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
1390
- if (kind === 1) value = {
1391
- get: desc.get,
1392
- set: desc.set
1393
- };
1394
- else if (kind === 2) value = desc.value;
1395
- else if (kind === 3) value = desc.get;
1396
- else if (kind === 4) value = desc.set;
1397
- var newValue, get, set;
1398
- if (typeof decs === "function") {
1399
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1400
- if (newValue !== void 0) {
1401
- assertValidReturnValue(kind, newValue);
1402
- if (kind === 0) init = newValue;
1403
- else if (kind === 1) {
1404
- init = newValue.init;
1405
- get = newValue.get || value.get;
1406
- set = newValue.set || value.set;
1407
- value = {
1408
- get,
1409
- set
1410
- };
1411
- } else value = newValue;
1412
- }
1413
- } else for (var i = decs.length - 1; i >= 0; i--) {
1414
- var dec = decs[i];
1415
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1416
- if (newValue !== void 0) {
1417
- assertValidReturnValue(kind, newValue);
1418
- var newInit;
1419
- if (kind === 0) newInit = newValue;
1420
- else if (kind === 1) {
1421
- newInit = newValue.init;
1422
- get = newValue.get || value.get;
1423
- set = newValue.set || value.set;
1424
- value = {
1425
- get,
1426
- set
1427
- };
1428
- } else value = newValue;
1429
- if (newInit !== void 0) if (init === void 0) init = newInit;
1430
- else if (typeof init === "function") init = [init, newInit];
1431
- else init.push(newInit);
1432
- }
1433
- }
1434
- if (kind === 0 || kind === 1) {
1435
- if (init === void 0) init = function(instance, init$1) {
1436
- return init$1;
1437
- };
1438
- else if (typeof init !== "function") {
1439
- var ownInitializers = init;
1440
- init = function(instance, init$1) {
1441
- var value$1 = init$1;
1442
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
1443
- return value$1;
1444
- };
1445
- } else {
1446
- var originalInitializer = init;
1447
- init = function(instance, init$1) {
1448
- return originalInitializer.call(instance, init$1);
1449
- };
1450
- }
1451
- ret.push(init);
1452
- }
1453
- if (kind !== 0) {
1454
- if (kind === 1) {
1455
- desc.get = value.get;
1456
- desc.set = value.set;
1457
- } else if (kind === 2) desc.value = value;
1458
- else if (kind === 3) desc.get = value;
1459
- else if (kind === 4) desc.set = value;
1460
- if (isPrivate) if (kind === 1) {
1461
- ret.push(function(instance, args) {
1462
- return value.get.call(instance, args);
1463
- });
1464
- ret.push(function(instance, args) {
1465
- return value.set.call(instance, args);
1466
- });
1467
- } else if (kind === 2) ret.push(value);
1468
- else ret.push(function(instance, args) {
1469
- return value.call(instance, args);
1470
- });
1471
- else Object.defineProperty(base, name, desc);
1472
- }
1473
- }
1474
- function applyMemberDecs(Class, decInfos, metadata) {
1475
- var ret = [];
1476
- var protoInitializers;
1477
- var staticInitializers;
1478
- var existingProtoNonFields = /* @__PURE__ */ new Map();
1479
- var existingStaticNonFields = /* @__PURE__ */ new Map();
1480
- for (var i = 0; i < decInfos.length; i++) {
1481
- var decInfo = decInfos[i];
1482
- if (!Array.isArray(decInfo)) continue;
1483
- var kind = decInfo[1];
1484
- var name = decInfo[2];
1485
- var isPrivate = decInfo.length > 3;
1486
- var isStatic = kind >= 5;
1487
- var base;
1488
- var initializers;
1489
- if (isStatic) {
1490
- base = Class;
1491
- kind = kind - 5;
1492
- staticInitializers = staticInitializers || [];
1493
- initializers = staticInitializers;
1494
- } else {
1495
- base = Class.prototype;
1496
- protoInitializers = protoInitializers || [];
1497
- initializers = protoInitializers;
1498
- }
1499
- if (kind !== 0 && !isPrivate) {
1500
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1501
- var existingKind = existingNonFields.get(name) || 0;
1502
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
1503
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1504
- else existingNonFields.set(name, true);
1505
- }
1506
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1507
- }
1508
- pushInitializers(ret, protoInitializers);
1509
- pushInitializers(ret, staticInitializers);
1510
- return ret;
1511
- }
1512
- function pushInitializers(ret, initializers) {
1513
- if (initializers) ret.push(function(instance) {
1514
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1515
- return instance;
1516
- });
1517
- }
1518
- function applyClassDecs(targetClass, classDecs, metadata) {
1519
- if (classDecs.length > 0) {
1520
- var initializers = [];
1521
- var newClass = targetClass;
1522
- var name = targetClass.name;
1523
- for (var i = classDecs.length - 1; i >= 0; i--) {
1524
- var decoratorFinishedRef = { v: false };
1525
- try {
1526
- var nextNewClass = classDecs[i](newClass, {
1527
- kind: "class",
1528
- name,
1529
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1530
- metadata
1531
- });
1532
- } finally {
1533
- decoratorFinishedRef.v = true;
1534
- }
1535
- if (nextNewClass !== void 0) {
1536
- assertValidReturnValue(10, nextNewClass);
1537
- newClass = nextNewClass;
1538
- }
1539
- }
1540
- return [defineMetadata(newClass, metadata), function() {
1541
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1542
- }];
1543
- }
1544
- }
1545
- function defineMetadata(Class, metadata) {
1546
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1547
- configurable: true,
1548
- enumerable: true,
1549
- value: metadata
1550
- });
1551
- }
1552
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1553
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1554
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1555
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
1556
- if (!classDecs.length) defineMetadata(targetClass, metadata);
1557
- return {
1558
- e,
1559
- get c() {
1560
- return applyClassDecs(targetClass, classDecs, metadata);
1561
- }
1562
- };
1563
- };
1564
- }
1565
- function _apply_decs_2203_r$5(targetClass, memberDecs, classDecs, parentClass) {
1566
- return (_apply_decs_2203_r$5 = applyDecs2203RFactory$5())(targetClass, memberDecs, classDecs, parentClass);
1567
- }
1568
- var _dec$5, _initClass$5;
1569
- let _ErrorResponseProducerService;
1570
- _dec$5 = Injectable();
1571
- var ErrorResponseProducerService = class {
1572
- static {
1573
- ({c: [_ErrorResponseProducerService, _initClass$5]} = _apply_decs_2203_r$5(this, [], [_dec$5]));
1574
- }
1575
- forbiddenResponder = inject(ForbiddenResponderToken);
1576
- internalServerErrorResponder = inject(InternalServerErrorResponderToken);
1577
- notFoundResponder = inject(NotFoundResponderToken);
1578
- validationErrorResponder = inject(ValidationErrorResponderToken);
1579
- /**
1580
- * Produces an error response for a specific framework error type.
1581
- *
1582
- * @param type - The type of framework error (from FrameworkError enum)
1583
- * @param error - The original error that was thrown
1584
- * @param description - Optional custom description to include in the response
1585
- * @returns ErrorResponse with status code, RFC 7807 payload, and headers
1586
- */ respond(type, error, description) {
1587
- switch (type) {
1588
- case FrameworkError.NotFound: return this.notFoundResponder.getResponse(error, description);
1589
- case FrameworkError.Forbidden: return this.forbiddenResponder.getResponse(error, description);
1590
- case FrameworkError.InternalServerError: return this.internalServerErrorResponder.getResponse(error, description);
1591
- case FrameworkError.ValidationError: return this.validationErrorResponder.getResponse(error, description);
1592
- }
1593
- }
1594
- /**
1595
- * Handles unknown errors by producing an Internal Server Error response.
1596
- *
1597
- * Use this as a fallback when the error type is not known or doesn't
1598
- * match any specific framework error type.
1599
- *
1600
- * @param error - The original error that was thrown
1601
- * @param description - Optional custom description to include in the response
1602
- * @returns ErrorResponse with 500 status code
1603
- */ handleUnknown(error, description) {
1604
- return this.internalServerErrorResponder.getResponse(error, description);
1605
- }
1606
- /**
1607
- * Convenience method to produce a Not Found error response.
1608
- *
1609
- * @param error - The original error that was thrown
1610
- * @param description - Optional custom description
1611
- * @returns ErrorResponse with 404 status code
1612
- */ notFound(error, description) {
1613
- return this.notFoundResponder.getResponse(error, description);
1614
- }
1615
- /**
1616
- * Convenience method to produce a Validation Error response.
1617
- *
1618
- * @param error - The original error (typically a ZodError)
1619
- * @param description - Optional custom description
1620
- * @returns ErrorResponse with 400 status code
1621
- */ validationError(error, description) {
1622
- return this.validationErrorResponder.getResponse(error, description);
1623
- }
1624
- /**
1625
- * Convenience method to produce an Internal Server Error response.
1626
- *
1627
- * @param error - The original error
1628
- * @param description - Optional custom description
1629
- * @returns ErrorResponse with 500 status code
1630
- */ internalServerError(error, description) {
1631
- return this.internalServerErrorResponder.getResponse(error, description);
1632
- }
1633
- /**
1634
- * Convenience method to produce a Forbidden error response.
1635
- *
1636
- * @param error - The original error
1637
- * @param description - Optional custom description
1638
- * @returns ErrorResponse with 403 status code
1639
- */ forbidden(error, description) {
1640
- return this.forbiddenResponder.getResponse(error, description);
1641
- }
1642
- static {
1643
- _initClass$5();
1644
- }
1645
- };
1646
-
1647
- //#endregion
1648
- //#region src/services/instance-resolver.service.mts
1649
- function applyDecs2203RFactory$4() {
1650
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1651
- return function addInitializer(initializer) {
1652
- assertNotFinished(decoratorFinishedRef, "addInitializer");
1653
- assertCallable(initializer, "An initializer");
1654
- initializers.push(initializer);
1655
- };
1656
- }
1657
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
1658
- var kindStr;
1659
- switch (kind) {
1660
- case 1:
1661
- kindStr = "accessor";
1662
- break;
1663
- case 2:
1664
- kindStr = "method";
1665
- break;
1666
- case 3:
1667
- kindStr = "getter";
1668
- break;
1669
- case 4:
1670
- kindStr = "setter";
1671
- break;
1672
- default: kindStr = "field";
1673
- }
1674
- var ctx = {
1675
- kind: kindStr,
1676
- name: isPrivate ? "#" + name : name,
1677
- static: isStatic,
1678
- private: isPrivate,
1679
- metadata
1680
- };
1681
- var decoratorFinishedRef = { v: false };
1682
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
1683
- var get, set;
1684
- if (kind === 0) if (isPrivate) {
1685
- get = desc.get;
1686
- set = desc.set;
1687
- } else {
1688
- get = function() {
1689
- return this[name];
1690
- };
1691
- set = function(v) {
1692
- this[name] = v;
1693
- };
1694
- }
1695
- else if (kind === 2) get = function() {
1696
- return desc.value;
1697
- };
1698
- else {
1699
- if (kind === 1 || kind === 3) get = function() {
1700
- return desc.get.call(this);
1701
- };
1702
- if (kind === 1 || kind === 4) set = function(v) {
1703
- desc.set.call(this, v);
1704
- };
1705
- }
1706
- ctx.access = get && set ? {
1707
- get,
1708
- set
1709
- } : get ? { get } : { set };
1710
- try {
1711
- return dec(value, ctx);
1712
- } finally {
1713
- decoratorFinishedRef.v = true;
1714
- }
1715
- }
1716
- function assertNotFinished(decoratorFinishedRef, fnName) {
1717
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
1718
- }
1719
- function assertCallable(fn, hint) {
1720
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
1721
- }
1722
- function assertValidReturnValue(kind, value) {
1723
- var type = typeof value;
1724
- if (kind === 1) {
1725
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
1726
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
1727
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
1728
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
1729
- } else if (type !== "function") {
1730
- var hint;
1731
- if (kind === 0) hint = "field";
1732
- else if (kind === 10) hint = "class";
1733
- else hint = "method";
1734
- throw new TypeError(hint + " decorators must return a function or void 0");
1735
- }
1736
- }
1737
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
1738
- var decs = decInfo[0];
1739
- var desc, init, value;
1740
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
1741
- get: decInfo[3],
1742
- set: decInfo[4]
1743
- };
1744
- else if (kind === 3) desc = { get: decInfo[3] };
1745
- else if (kind === 4) desc = { set: decInfo[3] };
1746
- else desc = { value: decInfo[3] };
1747
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
1748
- if (kind === 1) value = {
1749
- get: desc.get,
1750
- set: desc.set
1751
- };
1752
- else if (kind === 2) value = desc.value;
1753
- else if (kind === 3) value = desc.get;
1754
- else if (kind === 4) value = desc.set;
1755
- var newValue, get, set;
1756
- if (typeof decs === "function") {
1757
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1758
- if (newValue !== void 0) {
1759
- assertValidReturnValue(kind, newValue);
1760
- if (kind === 0) init = newValue;
1761
- else if (kind === 1) {
1762
- init = newValue.init;
1763
- get = newValue.get || value.get;
1764
- set = newValue.set || value.set;
1765
- value = {
1766
- get,
1767
- set
1768
- };
1769
- } else value = newValue;
1770
- }
1771
- } else for (var i = decs.length - 1; i >= 0; i--) {
1772
- var dec = decs[i];
1773
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1774
- if (newValue !== void 0) {
1775
- assertValidReturnValue(kind, newValue);
1776
- var newInit;
1777
- if (kind === 0) newInit = newValue;
1778
- else if (kind === 1) {
1779
- newInit = newValue.init;
1780
- get = newValue.get || value.get;
1781
- set = newValue.set || value.set;
1782
- value = {
1783
- get,
1784
- set
1785
- };
1786
- } else value = newValue;
1787
- if (newInit !== void 0) if (init === void 0) init = newInit;
1788
- else if (typeof init === "function") init = [init, newInit];
1789
- else init.push(newInit);
1790
- }
1791
- }
1792
- if (kind === 0 || kind === 1) {
1793
- if (init === void 0) init = function(instance, init$1) {
1794
- return init$1;
1795
- };
1796
- else if (typeof init !== "function") {
1797
- var ownInitializers = init;
1798
- init = function(instance, init$1) {
1799
- var value$1 = init$1;
1800
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
1801
- return value$1;
1802
- };
1803
- } else {
1804
- var originalInitializer = init;
1805
- init = function(instance, init$1) {
1806
- return originalInitializer.call(instance, init$1);
1807
- };
1808
- }
1809
- ret.push(init);
1810
- }
1811
- if (kind !== 0) {
1812
- if (kind === 1) {
1813
- desc.get = value.get;
1814
- desc.set = value.set;
1815
- } else if (kind === 2) desc.value = value;
1816
- else if (kind === 3) desc.get = value;
1817
- else if (kind === 4) desc.set = value;
1818
- if (isPrivate) if (kind === 1) {
1819
- ret.push(function(instance, args) {
1820
- return value.get.call(instance, args);
1821
- });
1822
- ret.push(function(instance, args) {
1823
- return value.set.call(instance, args);
1824
- });
1825
- } else if (kind === 2) ret.push(value);
1826
- else ret.push(function(instance, args) {
1827
- return value.call(instance, args);
1828
- });
1829
- else Object.defineProperty(base, name, desc);
1830
- }
1831
- }
1832
- function applyMemberDecs(Class, decInfos, metadata) {
1833
- var ret = [];
1834
- var protoInitializers;
1835
- var staticInitializers;
1836
- var existingProtoNonFields = /* @__PURE__ */ new Map();
1837
- var existingStaticNonFields = /* @__PURE__ */ new Map();
1838
- for (var i = 0; i < decInfos.length; i++) {
1839
- var decInfo = decInfos[i];
1840
- if (!Array.isArray(decInfo)) continue;
1841
- var kind = decInfo[1];
1842
- var name = decInfo[2];
1843
- var isPrivate = decInfo.length > 3;
1844
- var isStatic = kind >= 5;
1845
- var base;
1846
- var initializers;
1847
- if (isStatic) {
1848
- base = Class;
1849
- kind = kind - 5;
1850
- staticInitializers = staticInitializers || [];
1851
- initializers = staticInitializers;
1852
- } else {
1853
- base = Class.prototype;
1854
- protoInitializers = protoInitializers || [];
1855
- initializers = protoInitializers;
1856
- }
1857
- if (kind !== 0 && !isPrivate) {
1858
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1859
- var existingKind = existingNonFields.get(name) || 0;
1860
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
1861
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1862
- else existingNonFields.set(name, true);
1863
- }
1864
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1865
- }
1866
- pushInitializers(ret, protoInitializers);
1867
- pushInitializers(ret, staticInitializers);
1868
- return ret;
1869
- }
1870
- function pushInitializers(ret, initializers) {
1871
- if (initializers) ret.push(function(instance) {
1872
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1873
- return instance;
1874
- });
1875
- }
1876
- function applyClassDecs(targetClass, classDecs, metadata) {
1877
- if (classDecs.length > 0) {
1878
- var initializers = [];
1879
- var newClass = targetClass;
1880
- var name = targetClass.name;
1881
- for (var i = classDecs.length - 1; i >= 0; i--) {
1882
- var decoratorFinishedRef = { v: false };
1883
- try {
1884
- var nextNewClass = classDecs[i](newClass, {
1885
- kind: "class",
1886
- name,
1887
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1888
- metadata
1889
- });
1890
- } finally {
1891
- decoratorFinishedRef.v = true;
1892
- }
1893
- if (nextNewClass !== void 0) {
1894
- assertValidReturnValue(10, nextNewClass);
1895
- newClass = nextNewClass;
1896
- }
1897
- }
1898
- return [defineMetadata(newClass, metadata), function() {
1899
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1900
- }];
1901
- }
1902
- }
1903
- function defineMetadata(Class, metadata) {
1904
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1905
- configurable: true,
1906
- enumerable: true,
1907
- value: metadata
1908
- });
1909
- }
1910
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1911
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1912
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1913
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
1914
- if (!classDecs.length) defineMetadata(targetClass, metadata);
1915
- return {
1916
- e,
1917
- get c() {
1918
- return applyClassDecs(targetClass, classDecs, metadata);
1919
- }
1920
- };
1921
- };
1922
- }
1923
- function _apply_decs_2203_r$4(targetClass, memberDecs, classDecs, parentClass) {
1924
- return (_apply_decs_2203_r$4 = applyDecs2203RFactory$4())(targetClass, memberDecs, classDecs, parentClass);
1925
- }
1926
- var _dec$4, _initClass$4;
1927
- let _InstanceResolverService;
1928
- _dec$4 = Injectable();
1929
- var InstanceResolverService = class {
1930
- static {
1931
- ({c: [_InstanceResolverService, _initClass$4]} = _apply_decs_2203_r$4(this, [], [_dec$4]));
1932
- }
1933
- container = inject(Container);
1934
- /**
1935
- * Attempts to resolve a class instance, automatically detecting if it needs
1936
- * request scope based on its dependencies.
1937
- *
1938
- * @param classType - The class to resolve
1939
- * @returns A resolution result containing either a cached instance or resolver function
1940
- */ async resolve(classType) {
1941
- let cachedInstance = null;
1942
- try {
1943
- cachedInstance = await this.container.get(classType);
1944
- } catch {
1945
- const token = getInjectableToken(classType);
1946
- this.container.getRegistry().updateScope(token, InjectableScope.Request);
1947
- }
1948
- return {
1949
- cached: cachedInstance !== null,
1950
- instance: cachedInstance,
1951
- resolve: (scoped) => scoped.get(classType)
1952
- };
1953
- }
1954
- /**
1955
- * Attempts to resolve multiple class instances, automatically detecting if any need
1956
- * request scope based on their dependencies.
1957
- *
1958
- * Returns `cached: true` only if ALL classes can be resolved as singletons.
1959
- * If any class has request-scoped dependencies, returns `cached: false`.
1960
- *
1961
- * @param classTypes - The classes to resolve
1962
- * @returns A resolution result containing either all cached instances or resolver function
1963
- */ async resolveMany(classTypes) {
1964
- if (classTypes.length === 0) return {
1965
- cached: true,
1966
- instances: [],
1967
- classTypes: [],
1968
- resolve: async () => []
1969
- };
1970
- const results = await Promise.all(classTypes.map(async (classType) => {
1971
- try {
1972
- return {
1973
- success: true,
1974
- instance: await this.container.get(classType)
1975
- };
1976
- } catch {
1977
- const token = getInjectableToken(classType);
1978
- this.container.getRegistry().updateScope(token, InjectableScope.Request);
1979
- return {
1980
- success: false,
1981
- instance: null
1982
- };
1983
- }
1984
- }));
1985
- const allCached = results.every((r) => r.success);
1986
- return {
1987
- cached: allCached,
1988
- instances: allCached ? results.map((r) => r.instance) : null,
1989
- classTypes,
1990
- resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
1991
- };
1992
- }
1993
- static {
1994
- _initClass$4();
1995
- }
1996
- };
1997
-
1998
- //#endregion
1999
- //#region src/services/abstract-handler-adapter.service.mts
2000
- const defaultOptions = {
2001
- adapter: [],
2002
- validateResponses: true,
2003
- enableRequestId: false
2004
- };
2005
- /**
2006
- * Abstract base class for HTTP handler adapter services.
2007
- *
2008
- * Provides shared logic for:
2009
- * - Controller resolution (singleton vs request-scoped)
2010
- * - Argument formatting (sync/async detection)
2011
- * - Handler generation with static/dynamic branching
2012
- * - Standardized error handling
2013
- *
2014
- * Adapters implement abstract methods for framework-specific behavior:
2015
- * - Request parsing (query, body, URL params)
2016
- * - Response creation
2017
- * - Schema provision
2018
- *
2019
- * Supports all adapter types:
2020
- * - Endpoint adapters: JSON request/response with validation
2021
- * - Stream adapters: Streaming responses with extra context
2022
- * - Multipart adapters: Form data parsing (extends endpoint)
2023
- *
2024
- * @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
2025
- * @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
2026
- * @typeParam TConfig - Endpoint configuration type
2027
- */ var AbstractHandlerAdapterService = class {
2028
- instanceResolver = inject(_InstanceResolverService);
2029
- options = optional(NaviosOptionsToken) ?? defaultOptions;
2030
- /**
2031
- * Prepares argument getters for parsing request data.
2032
- *
2033
- * Public alias for createArgumentGetters to satisfy interface contracts.
2034
- * Subclasses should override createArgumentGetters instead.
2035
- *
2036
- * @param handlerMetadata - Handler metadata with schemas and configuration
2037
- * @returns Array of getter functions
2038
- */ prepareArguments(handlerMetadata) {
2039
- return this.createArgumentGetters(handlerMetadata);
2040
- }
2041
- /**
2042
- * Checks if the handler has any validation schemas defined.
2043
- *
2044
- * Override in subclasses to add additional schema checks
2045
- * (e.g., response schema validation for endpoint adapters).
2046
- *
2047
- * @param handlerMetadata - Handler metadata with configuration
2048
- * @returns true if handler has schemas
2049
- */ hasSchema(handlerMetadata) {
2050
- const config = handlerMetadata.config;
2051
- return !!config.requestSchema || !!config.querySchema;
2052
- }
2053
- /**
2054
- * Provides schema information for the framework's validation system.
2055
- *
2056
- * Override in subclasses for frameworks that support schema registration
2057
- * (e.g., Fastify). Default returns empty object (suitable for Bun).
2058
- *
2059
- * @param handlerMetadata - Handler metadata with configuration
2060
- * @returns Schema object for framework registration
2061
- */ provideSchema(_handlerMetadata) {
2062
- return {};
2063
- }
2064
- /**
2065
- * Creates a request handler function for the endpoint.
2066
- *
2067
- * This method orchestrates the entire handler creation:
2068
- * 1. Prepares argument getters for request parsing
2069
- * 2. Builds optimized formatArguments function (sync/async)
2070
- * 3. Resolves the controller (singleton vs request-scoped)
2071
- * 4. Creates appropriate handler (static or dynamic)
2072
- *
2073
- * @param controller - Controller class containing the handler method
2074
- * @param handlerMetadata - Handler metadata with configuration
2075
- * @returns Handler result (static or dynamic)
2076
- */ async provideHandler(controller, handlerMetadata) {
2077
- const getters = this.createArgumentGetters(handlerMetadata);
2078
- const formatArguments = this.buildFormatArguments(getters);
2079
- const hasArguments = getters.length > 0;
2080
- const context = {
2081
- methodName: handlerMetadata.classMethod,
2082
- statusCode: handlerMetadata.successStatusCode,
2083
- headers: handlerMetadata.headers,
2084
- handlerMetadata,
2085
- hasArguments
2086
- };
2087
- const resolution = await this.instanceResolver.resolve(controller);
2088
- if (resolution.cached) {
2089
- const cachedController = resolution.instance;
2090
- const boundMethod = cachedController[context.methodName].bind(cachedController);
2091
- return this.createStaticHandler(boundMethod, formatArguments, context);
2092
- }
2093
- return this.createDynamicHandler(resolution, formatArguments, context);
2094
- }
2095
- /**
2096
- * Builds a formatArguments function from argument getters.
2097
- *
2098
- * Automatically detects sync vs async getters and optimizes accordingly:
2099
- * - If all getters are sync: returns sync function (no Promise overhead)
2100
- * - If any getter is async: returns async function with Promise.all
2101
- * - If no getters: returns frozen empty object (zero allocation)
2102
- *
2103
- * This method is public to allow composition-based adapters (like XML adapter)
2104
- * to reuse the optimized formatArguments logic without inheritance.
2105
- *
2106
- * @param getters - Array of argument getter functions
2107
- * @returns Function to format arguments from request
2108
- */ buildFormatArguments(getters) {
2109
- if (getters.length === 0) {
2110
- const emptyArgs = Object.freeze({});
2111
- return () => emptyArgs;
2112
- }
2113
- if (getters.some((g) => g.constructor.name === "AsyncFunction")) return async (request) => {
2114
- const argument = {};
2115
- const promises = [];
2116
- for (const getter of getters) {
2117
- const res = getter(argument, request);
2118
- if (res instanceof Promise) promises.push(res);
2119
- }
2120
- await Promise.all(promises);
2121
- return argument;
2122
- };
2123
- return (request) => {
2124
- const argument = {};
2125
- for (const getter of getters) getter(argument, request);
2126
- return argument;
2127
- };
2128
- }
2129
- /**
2130
- * Checks if the URL pattern contains URL parameters.
2131
- *
2132
- * @param config - Endpoint configuration
2133
- * @returns true if URL contains '$' parameter markers
2134
- */ hasUrlParams(config) {
2135
- return config.url.includes("$");
2136
- }
2137
- /**
2138
- * Wraps handler execution with standardized error handling.
2139
- *
2140
- * Re-throws HttpExceptions as-is for framework error handlers.
2141
- * Other errors are re-thrown for global error handling.
2142
- *
2143
- * @param fn - Handler function to wrap
2144
- * @returns Wrapped function with error handling
2145
- */ wrapWithErrorHandling(fn) {
2146
- return async (...args) => {
2147
- try {
2148
- return await fn(...args);
2149
- } catch (error) {
2150
- if (error && typeof error === "object" && "statusCode" in error) throw error;
2151
- throw error;
2152
- }
2153
- };
2154
- }
2155
- };
2156
-
2157
- //#endregion
2158
- //#region src/services/guard-runner.service.mts
2159
- function applyDecs2203RFactory$3() {
2160
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2161
- return function addInitializer(initializer) {
2162
- assertNotFinished(decoratorFinishedRef, "addInitializer");
2163
- assertCallable(initializer, "An initializer");
2164
- initializers.push(initializer);
2165
- };
2166
- }
2167
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2168
- var kindStr;
2169
- switch (kind) {
2170
- case 1:
2171
- kindStr = "accessor";
2172
- break;
2173
- case 2:
2174
- kindStr = "method";
2175
- break;
2176
- case 3:
2177
- kindStr = "getter";
2178
- break;
2179
- case 4:
2180
- kindStr = "setter";
2181
- break;
2182
- default: kindStr = "field";
2183
- }
2184
- var ctx = {
2185
- kind: kindStr,
2186
- name: isPrivate ? "#" + name : name,
2187
- static: isStatic,
2188
- private: isPrivate,
2189
- metadata
2190
- };
2191
- var decoratorFinishedRef = { v: false };
2192
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2193
- var get, set;
2194
- if (kind === 0) if (isPrivate) {
2195
- get = desc.get;
2196
- set = desc.set;
2197
- } else {
2198
- get = function() {
2199
- return this[name];
2200
- };
2201
- set = function(v) {
2202
- this[name] = v;
2203
- };
2204
- }
2205
- else if (kind === 2) get = function() {
2206
- return desc.value;
2207
- };
2208
- else {
2209
- if (kind === 1 || kind === 3) get = function() {
2210
- return desc.get.call(this);
2211
- };
2212
- if (kind === 1 || kind === 4) set = function(v) {
2213
- desc.set.call(this, v);
2214
- };
2215
- }
2216
- ctx.access = get && set ? {
2217
- get,
2218
- set
2219
- } : get ? { get } : { set };
2220
- try {
2221
- return dec(value, ctx);
2222
- } finally {
2223
- decoratorFinishedRef.v = true;
2224
- }
2225
- }
2226
- function assertNotFinished(decoratorFinishedRef, fnName) {
2227
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2228
- }
2229
- function assertCallable(fn, hint) {
2230
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2231
- }
2232
- function assertValidReturnValue(kind, value) {
2233
- var type = typeof value;
2234
- if (kind === 1) {
2235
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2236
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2237
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2238
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2239
- } else if (type !== "function") {
2240
- var hint;
2241
- if (kind === 0) hint = "field";
2242
- else if (kind === 10) hint = "class";
2243
- else hint = "method";
2244
- throw new TypeError(hint + " decorators must return a function or void 0");
2245
- }
2246
- }
2247
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2248
- var decs = decInfo[0];
2249
- var desc, init, value;
2250
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
2251
- get: decInfo[3],
2252
- set: decInfo[4]
2253
- };
2254
- else if (kind === 3) desc = { get: decInfo[3] };
2255
- else if (kind === 4) desc = { set: decInfo[3] };
2256
- else desc = { value: decInfo[3] };
2257
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2258
- if (kind === 1) value = {
2259
- get: desc.get,
2260
- set: desc.set
2261
- };
2262
- else if (kind === 2) value = desc.value;
2263
- else if (kind === 3) value = desc.get;
2264
- else if (kind === 4) value = desc.set;
2265
- var newValue, get, set;
2266
- if (typeof decs === "function") {
2267
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2268
- if (newValue !== void 0) {
2269
- assertValidReturnValue(kind, newValue);
2270
- if (kind === 0) init = newValue;
2271
- else if (kind === 1) {
2272
- init = newValue.init;
2273
- get = newValue.get || value.get;
2274
- set = newValue.set || value.set;
2275
- value = {
2276
- get,
2277
- set
2278
- };
2279
- } else value = newValue;
2280
- }
2281
- } else for (var i = decs.length - 1; i >= 0; i--) {
2282
- var dec = decs[i];
2283
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2284
- if (newValue !== void 0) {
2285
- assertValidReturnValue(kind, newValue);
2286
- var newInit;
2287
- if (kind === 0) newInit = newValue;
2288
- else if (kind === 1) {
2289
- newInit = newValue.init;
2290
- get = newValue.get || value.get;
2291
- set = newValue.set || value.set;
2292
- value = {
2293
- get,
2294
- set
2295
- };
2296
- } else value = newValue;
2297
- if (newInit !== void 0) if (init === void 0) init = newInit;
2298
- else if (typeof init === "function") init = [init, newInit];
2299
- else init.push(newInit);
2300
- }
2301
- }
2302
- if (kind === 0 || kind === 1) {
2303
- if (init === void 0) init = function(instance, init$1) {
2304
- return init$1;
2305
- };
2306
- else if (typeof init !== "function") {
2307
- var ownInitializers = init;
2308
- init = function(instance, init$1) {
2309
- var value$1 = init$1;
2310
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2311
- return value$1;
2312
- };
2313
- } else {
2314
- var originalInitializer = init;
2315
- init = function(instance, init$1) {
2316
- return originalInitializer.call(instance, init$1);
2317
- };
2318
- }
2319
- ret.push(init);
2320
- }
2321
- if (kind !== 0) {
2322
- if (kind === 1) {
2323
- desc.get = value.get;
2324
- desc.set = value.set;
2325
- } else if (kind === 2) desc.value = value;
2326
- else if (kind === 3) desc.get = value;
2327
- else if (kind === 4) desc.set = value;
2328
- if (isPrivate) if (kind === 1) {
2329
- ret.push(function(instance, args) {
2330
- return value.get.call(instance, args);
2331
- });
2332
- ret.push(function(instance, args) {
2333
- return value.set.call(instance, args);
2334
- });
2335
- } else if (kind === 2) ret.push(value);
2336
- else ret.push(function(instance, args) {
2337
- return value.call(instance, args);
2338
- });
2339
- else Object.defineProperty(base, name, desc);
2340
- }
2341
- }
2342
- function applyMemberDecs(Class, decInfos, metadata) {
2343
- var ret = [];
2344
- var protoInitializers;
2345
- var staticInitializers;
2346
- var existingProtoNonFields = /* @__PURE__ */ new Map();
2347
- var existingStaticNonFields = /* @__PURE__ */ new Map();
2348
- for (var i = 0; i < decInfos.length; i++) {
2349
- var decInfo = decInfos[i];
2350
- if (!Array.isArray(decInfo)) continue;
2351
- var kind = decInfo[1];
2352
- var name = decInfo[2];
2353
- var isPrivate = decInfo.length > 3;
2354
- var isStatic = kind >= 5;
2355
- var base;
2356
- var initializers;
2357
- if (isStatic) {
2358
- base = Class;
2359
- kind = kind - 5;
2360
- staticInitializers = staticInitializers || [];
2361
- initializers = staticInitializers;
2362
- } else {
2363
- base = Class.prototype;
2364
- protoInitializers = protoInitializers || [];
2365
- initializers = protoInitializers;
2366
- }
2367
- if (kind !== 0 && !isPrivate) {
2368
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2369
- var existingKind = existingNonFields.get(name) || 0;
2370
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
2371
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2372
- else existingNonFields.set(name, true);
2373
- }
2374
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2375
- }
2376
- pushInitializers(ret, protoInitializers);
2377
- pushInitializers(ret, staticInitializers);
2378
- return ret;
2379
- }
2380
- function pushInitializers(ret, initializers) {
2381
- if (initializers) ret.push(function(instance) {
2382
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2383
- return instance;
2384
- });
2385
- }
2386
- function applyClassDecs(targetClass, classDecs, metadata) {
2387
- if (classDecs.length > 0) {
2388
- var initializers = [];
2389
- var newClass = targetClass;
2390
- var name = targetClass.name;
2391
- for (var i = classDecs.length - 1; i >= 0; i--) {
2392
- var decoratorFinishedRef = { v: false };
2393
- try {
2394
- var nextNewClass = classDecs[i](newClass, {
2395
- kind: "class",
2396
- name,
2397
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2398
- metadata
2399
- });
2400
- } finally {
2401
- decoratorFinishedRef.v = true;
2402
- }
2403
- if (nextNewClass !== void 0) {
2404
- assertValidReturnValue(10, nextNewClass);
2405
- newClass = nextNewClass;
2406
- }
2407
- }
2408
- return [defineMetadata(newClass, metadata), function() {
2409
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2410
- }];
2411
- }
2412
- }
2413
- function defineMetadata(Class, metadata) {
2414
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2415
- configurable: true,
2416
- enumerable: true,
2417
- value: metadata
2418
- });
2419
- }
2420
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2421
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2422
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2423
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
2424
- if (!classDecs.length) defineMetadata(targetClass, metadata);
2425
- return {
2426
- e,
2427
- get c() {
2428
- return applyClassDecs(targetClass, classDecs, metadata);
2429
- }
2430
- };
2431
- };
2432
- }
2433
- function _apply_decs_2203_r$3(targetClass, memberDecs, classDecs, parentClass) {
2434
- return (_apply_decs_2203_r$3 = applyDecs2203RFactory$3())(targetClass, memberDecs, classDecs, parentClass);
2435
- }
2436
- var _dec$3, _initClass$3;
2437
- let _GuardRunnerService;
2438
- _dec$3 = Injectable();
2439
- var GuardRunnerService = class {
2440
- static {
2441
- ({c: [_GuardRunnerService, _initClass$3]} = _apply_decs_2203_r$3(this, [], [_dec$3]));
2442
- }
2443
- errorProducer = inject(_ErrorResponseProducerService);
2444
- logger = inject(Logger, { context: _GuardRunnerService.name });
2445
- /**
2446
- * Runs guards that need to be resolved from a scoped container.
2447
- * Use this when guards have request-scoped dependencies.
2448
- */ async runGuards(allGuards, executionContext, context) {
2449
- const guardsArray = Array.from(allGuards).reverse();
2450
- const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
2451
- const guardInstance = await context.get(guard);
2452
- if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
2453
- return guardInstance;
2454
- }));
2455
- return this.executeGuards(guardInstances, executionContext);
2456
- }
2457
- /**
2458
- * Runs pre-resolved guard instances.
2459
- * Use this when all guards are singletons and have been pre-resolved at startup.
2460
- */ async runGuardsStatic(guardInstances, executionContext) {
2461
- return this.executeGuards(guardInstances, executionContext);
2462
- }
2463
- /**
2464
- * Shared guard execution logic.
2465
- * Iterates through guard instances and calls canActivate on each.
2466
- */ async executeGuards(guardInstances, executionContext) {
2467
- let canActivate = true;
2468
- for (const guardInstance of guardInstances) try {
2469
- canActivate = await guardInstance.canActivate(executionContext);
2470
- if (!canActivate) break;
2471
- } catch (error) {
2472
- if (error instanceof HttpException) {
2473
- executionContext.getReply().status(error.statusCode).send(error.response);
2474
- return false;
2475
- } else {
2476
- this.logger.error("Error running guard", error);
2477
- const errorResponse = this.errorProducer.respond(FrameworkError.InternalServerError, error);
2478
- executionContext.getReply().status(errorResponse.statusCode).send(errorResponse.payload);
2479
- return false;
2480
- }
2481
- }
2482
- if (!canActivate) {
2483
- const errorResponse = this.errorProducer.respond(FrameworkError.Forbidden, null);
2484
- executionContext.getReply().status(errorResponse.statusCode).send(errorResponse.payload);
2485
- return false;
2486
- }
2487
- return canActivate;
2488
- }
2489
- makeContext(moduleMetadata, controllerMetadata, endpoint) {
2490
- const guards = /* @__PURE__ */ new Set();
2491
- const endpointGuards = endpoint.guards;
2492
- const controllerGuards = controllerMetadata.guards;
2493
- const moduleGuards = moduleMetadata.guards;
2494
- if (endpointGuards.size > 0) for (const guard of endpointGuards) guards.add(guard);
2495
- if (controllerGuards.size > 0) for (const guard of controllerGuards) guards.add(guard);
2496
- if (moduleGuards.size > 0) for (const guard of moduleGuards) guards.add(guard);
2497
- return guards;
2498
- }
2499
- static {
2500
- _initClass$3();
2501
- }
2502
- };
2503
-
2504
- //#endregion
2505
- //#region src/services/module-loader.service.mts
2506
- function applyDecs2203RFactory$2() {
2507
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2508
- return function addInitializer(initializer) {
2509
- assertNotFinished(decoratorFinishedRef, "addInitializer");
2510
- assertCallable(initializer, "An initializer");
2511
- initializers.push(initializer);
2512
- };
2513
- }
2514
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2515
- var kindStr;
2516
- switch (kind) {
2517
- case 1:
2518
- kindStr = "accessor";
2519
- break;
2520
- case 2:
2521
- kindStr = "method";
2522
- break;
2523
- case 3:
2524
- kindStr = "getter";
2525
- break;
2526
- case 4:
2527
- kindStr = "setter";
2528
- break;
2529
- default: kindStr = "field";
2530
- }
2531
- var ctx = {
2532
- kind: kindStr,
2533
- name: isPrivate ? "#" + name : name,
2534
- static: isStatic,
2535
- private: isPrivate,
2536
- metadata
2537
- };
2538
- var decoratorFinishedRef = { v: false };
2539
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2540
- var get, set;
2541
- if (kind === 0) if (isPrivate) {
2542
- get = desc.get;
2543
- set = desc.set;
2544
- } else {
2545
- get = function() {
2546
- return this[name];
2547
- };
2548
- set = function(v) {
2549
- this[name] = v;
2550
- };
2551
- }
2552
- else if (kind === 2) get = function() {
2553
- return desc.value;
2554
- };
2555
- else {
2556
- if (kind === 1 || kind === 3) get = function() {
2557
- return desc.get.call(this);
2558
- };
2559
- if (kind === 1 || kind === 4) set = function(v) {
2560
- desc.set.call(this, v);
2561
- };
2562
- }
2563
- ctx.access = get && set ? {
2564
- get,
2565
- set
2566
- } : get ? { get } : { set };
2567
- try {
2568
- return dec(value, ctx);
2569
- } finally {
2570
- decoratorFinishedRef.v = true;
2571
- }
2572
- }
2573
- function assertNotFinished(decoratorFinishedRef, fnName) {
2574
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2575
- }
2576
- function assertCallable(fn, hint) {
2577
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2578
- }
2579
- function assertValidReturnValue(kind, value) {
2580
- var type = typeof value;
2581
- if (kind === 1) {
2582
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2583
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2584
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2585
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2586
- } else if (type !== "function") {
2587
- var hint;
2588
- if (kind === 0) hint = "field";
2589
- else if (kind === 10) hint = "class";
2590
- else hint = "method";
2591
- throw new TypeError(hint + " decorators must return a function or void 0");
2592
- }
2593
- }
2594
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2595
- var decs = decInfo[0];
2596
- var desc, init, value;
2597
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
2598
- get: decInfo[3],
2599
- set: decInfo[4]
2600
- };
2601
- else if (kind === 3) desc = { get: decInfo[3] };
2602
- else if (kind === 4) desc = { set: decInfo[3] };
2603
- else desc = { value: decInfo[3] };
2604
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2605
- if (kind === 1) value = {
2606
- get: desc.get,
2607
- set: desc.set
2608
- };
2609
- else if (kind === 2) value = desc.value;
2610
- else if (kind === 3) value = desc.get;
2611
- else if (kind === 4) value = desc.set;
2612
- var newValue, get, set;
2613
- if (typeof decs === "function") {
2614
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2615
- if (newValue !== void 0) {
2616
- assertValidReturnValue(kind, newValue);
2617
- if (kind === 0) init = newValue;
2618
- else if (kind === 1) {
2619
- init = newValue.init;
2620
- get = newValue.get || value.get;
2621
- set = newValue.set || value.set;
2622
- value = {
2623
- get,
2624
- set
2625
- };
2626
- } else value = newValue;
2627
- }
2628
- } else for (var i = decs.length - 1; i >= 0; i--) {
2629
- var dec = decs[i];
2630
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2631
- if (newValue !== void 0) {
2632
- assertValidReturnValue(kind, newValue);
2633
- var newInit;
2634
- if (kind === 0) newInit = newValue;
2635
- else if (kind === 1) {
2636
- newInit = newValue.init;
2637
- get = newValue.get || value.get;
2638
- set = newValue.set || value.set;
2639
- value = {
2640
- get,
2641
- set
2642
- };
2643
- } else value = newValue;
2644
- if (newInit !== void 0) if (init === void 0) init = newInit;
2645
- else if (typeof init === "function") init = [init, newInit];
2646
- else init.push(newInit);
2647
- }
2648
- }
2649
- if (kind === 0 || kind === 1) {
2650
- if (init === void 0) init = function(instance, init$1) {
2651
- return init$1;
2652
- };
2653
- else if (typeof init !== "function") {
2654
- var ownInitializers = init;
2655
- init = function(instance, init$1) {
2656
- var value$1 = init$1;
2657
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2658
- return value$1;
2659
- };
2660
- } else {
2661
- var originalInitializer = init;
2662
- init = function(instance, init$1) {
2663
- return originalInitializer.call(instance, init$1);
2664
- };
2665
- }
2666
- ret.push(init);
2667
- }
2668
- if (kind !== 0) {
2669
- if (kind === 1) {
2670
- desc.get = value.get;
2671
- desc.set = value.set;
2672
- } else if (kind === 2) desc.value = value;
2673
- else if (kind === 3) desc.get = value;
2674
- else if (kind === 4) desc.set = value;
2675
- if (isPrivate) if (kind === 1) {
2676
- ret.push(function(instance, args) {
2677
- return value.get.call(instance, args);
2678
- });
2679
- ret.push(function(instance, args) {
2680
- return value.set.call(instance, args);
2681
- });
2682
- } else if (kind === 2) ret.push(value);
2683
- else ret.push(function(instance, args) {
2684
- return value.call(instance, args);
2685
- });
2686
- else Object.defineProperty(base, name, desc);
2687
- }
2688
- }
2689
- function applyMemberDecs(Class, decInfos, metadata) {
2690
- var ret = [];
2691
- var protoInitializers;
2692
- var staticInitializers;
2693
- var existingProtoNonFields = /* @__PURE__ */ new Map();
2694
- var existingStaticNonFields = /* @__PURE__ */ new Map();
2695
- for (var i = 0; i < decInfos.length; i++) {
2696
- var decInfo = decInfos[i];
2697
- if (!Array.isArray(decInfo)) continue;
2698
- var kind = decInfo[1];
2699
- var name = decInfo[2];
2700
- var isPrivate = decInfo.length > 3;
2701
- var isStatic = kind >= 5;
2702
- var base;
2703
- var initializers;
2704
- if (isStatic) {
2705
- base = Class;
2706
- kind = kind - 5;
2707
- staticInitializers = staticInitializers || [];
2708
- initializers = staticInitializers;
2709
- } else {
2710
- base = Class.prototype;
2711
- protoInitializers = protoInitializers || [];
2712
- initializers = protoInitializers;
2713
- }
2714
- if (kind !== 0 && !isPrivate) {
2715
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2716
- var existingKind = existingNonFields.get(name) || 0;
2717
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
2718
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2719
- else existingNonFields.set(name, true);
2720
- }
2721
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2722
- }
2723
- pushInitializers(ret, protoInitializers);
2724
- pushInitializers(ret, staticInitializers);
2725
- return ret;
2726
- }
2727
- function pushInitializers(ret, initializers) {
2728
- if (initializers) ret.push(function(instance) {
2729
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2730
- return instance;
2731
- });
2732
- }
2733
- function applyClassDecs(targetClass, classDecs, metadata) {
2734
- if (classDecs.length > 0) {
2735
- var initializers = [];
2736
- var newClass = targetClass;
2737
- var name = targetClass.name;
2738
- for (var i = classDecs.length - 1; i >= 0; i--) {
2739
- var decoratorFinishedRef = { v: false };
2740
- try {
2741
- var nextNewClass = classDecs[i](newClass, {
2742
- kind: "class",
2743
- name,
2744
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2745
- metadata
2746
- });
2747
- } finally {
2748
- decoratorFinishedRef.v = true;
2749
- }
2750
- if (nextNewClass !== void 0) {
2751
- assertValidReturnValue(10, nextNewClass);
2752
- newClass = nextNewClass;
2753
- }
2754
- }
2755
- return [defineMetadata(newClass, metadata), function() {
2756
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2757
- }];
2758
- }
2759
- }
2760
- function defineMetadata(Class, metadata) {
2761
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2762
- configurable: true,
2763
- enumerable: true,
2764
- value: metadata
2765
- });
2766
- }
2767
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2768
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2769
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2770
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
2771
- if (!classDecs.length) defineMetadata(targetClass, metadata);
2772
- return {
2773
- e,
2774
- get c() {
2775
- return applyClassDecs(targetClass, classDecs, metadata);
2776
- }
2777
- };
2778
- };
2779
- }
2780
- function _apply_decs_2203_r$2(targetClass, memberDecs, classDecs, parentClass) {
2781
- return (_apply_decs_2203_r$2 = applyDecs2203RFactory$2())(targetClass, memberDecs, classDecs, parentClass);
2782
- }
2783
- var _dec$2, _initClass$2;
2784
- let _ModuleLoaderService;
2785
- _dec$2 = Injectable();
2786
- var ModuleLoaderService = class {
2787
- static {
2788
- ({c: [_ModuleLoaderService, _initClass$2]} = _apply_decs_2203_r$2(this, [], [_dec$2]));
2789
- }
2790
- logger = inject(Logger, { context: _ModuleLoaderService.name });
2791
- container = inject(Container);
2792
- modulesMetadata = /* @__PURE__ */ new Map();
2793
- loadedModules = /* @__PURE__ */ new Map();
2794
- initialized = false;
2795
- async loadModules(appModule) {
2796
- if (this.initialized) return;
2797
- await this.traverseModules(appModule);
2798
- this.initialized = true;
2799
- }
2800
- /**
2801
- * Extends the module tree with additional modules or controllers.
2802
- *
2803
- * This method is designed to be called by plugins during registration,
2804
- * which happens after initial module loading but before route registration.
2805
- *
2806
- * @param extensions - Array of module extensions to add
2807
- * @throws Error if not initialized (loadModules must be called first)
2808
- *
2809
- * @example
2810
- * ```typescript
2811
- * // In plugin registration
2812
- * const moduleLoader = await context.container.get(ModuleLoaderService)
2813
- * await moduleLoader.extendModules([{
2814
- * controllers: [OpenApiJsonController, OpenApiYamlController],
2815
- * moduleName: 'OpenApiBunModule',
2816
- * }])
2817
- * ```
2818
- */ async extendModules(extensions) {
2819
- if (!this.initialized) throw new Error("ModuleLoaderService must be initialized before extending. Call loadModules() first.");
2820
- for (const extension of extensions) {
2821
- if (extension.module) {
2822
- await this.traverseModules(extension.module);
2823
- continue;
2824
- }
2825
- if (!extension.controllers) continue;
2826
- if (!extension.moduleName) throw new Error("moduleName is required when providing controllers without a module");
2827
- await this.registerControllers(extension.controllers, extension.moduleName);
2828
- }
2829
- }
2830
- /**
2831
- * Registers controllers under a synthetic module.
2832
- * Used when plugins want to add controllers without a full module class.
2833
- */ async registerControllers(controllers, moduleName) {
2834
- if (this.modulesMetadata.has(moduleName)) {
2835
- const existing = this.modulesMetadata.get(moduleName);
2836
- for (const controller of controllers) existing.controllers.add(controller);
2837
- this.logger.debug(`Extended module ${moduleName} with ${controllers.length} controllers`);
2838
- } else {
2839
- const metadata = {
2840
- name: moduleName,
2841
- controllers: new Set(controllers),
2842
- imports: /* @__PURE__ */ new Set(),
2843
- guards: /* @__PURE__ */ new Set(),
2844
- overrides: /* @__PURE__ */ new Set(),
2845
- customAttributes: /* @__PURE__ */ new Map(),
2846
- customEntries: /* @__PURE__ */ new Map()
2847
- };
2848
- this.modulesMetadata.set(moduleName, metadata);
2849
- this.logger.debug(`Created module ${moduleName} with ${controllers.length} controllers`);
2850
- }
2851
- }
2852
- async traverseModules(module, parentMetadata) {
2853
- const metadata = extractModuleMetadata(module);
2854
- if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
2855
- const moduleName = getInjectableToken(module).id;
2856
- if (this.modulesMetadata.has(moduleName)) return;
2857
- try {
2858
- this.modulesMetadata.set(moduleName, metadata);
2859
- const imports = metadata.imports ?? /* @__PURE__ */ new Set();
2860
- const loadingPromises = Array.from(imports).map(async (importedModule) => this.traverseModules(importedModule, metadata));
2861
- await Promise.all(loadingPromises);
2862
- this.validateOverrides(metadata, moduleName);
2863
- const instance = await this.container.get(module);
2864
- if (instance.onModuleInit) await instance.onModuleInit();
2865
- this.logger.debug(`Module ${moduleName} loaded`);
2866
- this.loadedModules.set(moduleName, instance);
2867
- } catch (error) {
2868
- this.logger.error(`Error loading module ${moduleName}`, error);
2869
- throw error;
2870
- }
2871
- }
2872
- validateOverrides(metadata, moduleName) {
2873
- if (!metadata.overrides || metadata.overrides.size === 0) return;
2874
- const registry = this.container.getRegistry();
2875
- for (const overrideClass of metadata.overrides) try {
2876
- const overrideToken = getInjectableToken(overrideClass);
2877
- const allRegistrations = registry.getAll(overrideToken);
2878
- if (allRegistrations.length === 0) {
2879
- this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is not registered. Make sure it has @Injectable decorator.`);
2880
- continue;
2881
- }
2882
- const highestPriorityRegistration = allRegistrations[0];
2883
- if (highestPriorityRegistration.target !== overrideClass) {
2884
- const overrideRegistration = allRegistrations.find((r) => r.target === overrideClass);
2885
- if (!overrideRegistration) this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is registered but not found in registry for token ${overrideToken.toString()}.`);
2886
- else this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is not active. Current active service: ${highestPriorityRegistration.target.name} (priority: ${highestPriorityRegistration.priority}). Override priority: ${overrideRegistration.priority}. Override needs higher priority to take effect.`);
2887
- } else this.logger.debug(`[Navios] Override ${overrideClass.name} in module ${moduleName} is active (priority: ${highestPriorityRegistration.priority})`);
2888
- } catch (error) {
2889
- this.logger.warn(`[Navios] Failed to validate override ${overrideClass.name} in module ${moduleName}: ${error}`);
2890
- }
2891
- }
2892
- mergeMetadata(metadata, parentMetadata) {
2893
- if (parentMetadata.guards) for (const guard of parentMetadata.guards) metadata.guards.add(guard);
2894
- if (parentMetadata.customAttributes) for (const [key, value] of parentMetadata.customAttributes) {
2895
- if (metadata.customAttributes.has(key)) continue;
2896
- metadata.customAttributes.set(key, value);
2897
- }
2898
- }
2899
- getAllModules() {
2900
- return this.modulesMetadata;
2901
- }
2902
- dispose() {
2903
- this.modulesMetadata.clear();
2904
- this.loadedModules.clear();
2905
- this.initialized = false;
2906
- }
2907
- static {
2908
- _initClass$2();
2909
- }
2910
- };
2911
-
2912
- //#endregion
2913
- //#region src/utils/adapter-supports.util.mts
2914
- /**
2915
- * Type guard to check if adapter implements a specific method.
2916
- * Narrows the adapter type to include the method.
2917
- *
2918
- * @example
2919
- * ```typescript
2920
- * if (adapterSupports(adapter, 'getServer')) {
2921
- * const server = adapter.getServer() // TypeScript knows this exists
2922
- * }
2923
- * ```
2924
- */ function adapterSupports(adapter, method) {
2925
- return adapter !== null && typeof adapter[method] === "function";
2926
- }
2927
- /**
2928
- * Asserts adapter supports a method, throws if not.
2929
- * Narrows type after assertion.
2930
- *
2931
- * @example
2932
- * ```typescript
2933
- * assertAdapterSupports(adapter, 'enableCors')
2934
- * adapter.enableCors(options) // TypeScript knows this exists
2935
- * ```
2936
- */ function assertAdapterSupports(adapter, method) {
2937
- if (!adapterSupports(adapter, method)) throw new Error(`Current adapter does not implement '${method}()'`);
2938
- }
2939
-
2940
- //#endregion
2941
- //#region src/utils/define-plugin.mts
2942
- /**
2943
- * Creates a curried plugin factory for a specific stage.
2944
- * Returns a function that takes config and returns a function that takes options.
2945
- */ function createPluginFactory(stage) {
2946
- return (config) => (options) => ({
2947
- plugin: {
2948
- name: config.name,
2949
- stage,
2950
- register: config.register
2951
- },
2952
- options
2953
- });
2954
- }
2955
- /**
2956
- * Define a plugin that runs before modules are traversed.
2957
- *
2958
- * Context: container only
2959
- *
2960
- * Use this stage for early DI setup before any modules are loaded.
2961
- *
2962
- * @example
2963
- * ```typescript
2964
- * export const defineEarlySetupPlugin = definePreModulesTraversePlugin({
2965
- * name: 'early-setup',
2966
- * register: (context, options: { key: string }) => {
2967
- * context.container.addInstance(SomeToken, options.key)
2968
- * },
2969
- * })
2970
- *
2971
- * // Usage
2972
- * app.usePlugin(defineEarlySetupPlugin({ key: 'value' }))
2973
- * ```
2974
- */ const definePreModulesTraversePlugin = createPluginFactory(PluginStages.PRE_MODULES_TRAVERSE);
2975
- /**
2976
- * Define a plugin that runs after modules are traversed.
2977
- *
2978
- * Context: container + modules + moduleLoader
2979
- *
2980
- * Use this stage to inspect loaded modules or extend the module tree.
2981
- *
2982
- * @example
2983
- * ```typescript
2984
- * export const defineModuleInspectorPlugin = definePostModulesTraversePlugin({
2985
- * name: 'module-inspector',
2986
- * register: (context, options) => {
2987
- * console.log('Loaded modules:', context.modules.size)
2988
- * },
2989
- * })
2990
- * ```
2991
- */ const definePostModulesTraversePlugin = createPluginFactory(PluginStages.POST_MODULES_TRAVERSE);
2992
- /**
2993
- * Define a plugin that runs before adapter is resolved from container.
2994
- *
2995
- * Context: container + modules + moduleLoader (NO adapter yet!)
2996
- *
2997
- * Use this stage to modify registry/bindings before adapter instantiation.
2998
- * This is ideal for instrumentation, service wrapping, or changing DI bindings.
2999
- *
3000
- * @example
3001
- * ```typescript
3002
- * export const defineOtelPlugin = definePreAdapterResolvePlugin({
3003
- * name: 'otel',
3004
- * register: (context, options: OtelOptions) => {
3005
- * const registry = context.container.getRegistry()
3006
- * // Modify registry before adapter is created
3007
- * },
3008
- * })
3009
- *
3010
- * // Usage
3011
- * app.usePlugin(defineOtelPlugin({ serviceName: 'my-app' }))
3012
- * ```
3013
- */ const definePreAdapterResolvePlugin = createPluginFactory(PluginStages.PRE_ADAPTER_RESOLVE);
3014
- /**
3015
- * Define a plugin that runs after adapter is resolved.
3016
- *
3017
- * Context: full (container + modules + moduleLoader + adapter)
3018
- *
3019
- * @example
3020
- * ```typescript
3021
- * export const defineAdapterConfigPlugin = definePostAdapterResolvePlugin<
3022
- * { prefix: string },
3023
- * BunApplicationServiceInterface
3024
- * >()({
3025
- * name: 'adapter-config',
3026
- * register: (context, options) => {
3027
- * context.adapter.setGlobalPrefix(options.prefix)
3028
- * },
3029
- * })
3030
- * ```
3031
- */ function definePostAdapterResolvePlugin() {
3032
- return createPluginFactory(PluginStages.POST_ADAPTER_RESOLVE);
3033
- }
3034
- /**
3035
- * Define a plugin that runs before adapter setup.
3036
- *
3037
- * Context: full
3038
- */ function definePreAdapterSetupPlugin() {
3039
- return createPluginFactory(PluginStages.PRE_ADAPTER_SETUP);
3040
- }
3041
- /**
3042
- * Define a plugin that runs after adapter setup.
3043
- *
3044
- * Context: full
3045
- */ function definePostAdapterSetupPlugin() {
3046
- return createPluginFactory(PluginStages.POST_ADAPTER_SETUP);
3047
- }
3048
- /**
3049
- * Define a plugin that runs before modules init (route registration).
3050
- *
3051
- * Context: full
3052
- */ function definePreModulesInitPlugin() {
3053
- return createPluginFactory(PluginStages.PRE_MODULES_INIT);
3054
- }
3055
- /**
3056
- * Define a plugin that runs after modules init (route registration).
3057
- *
3058
- * Context: full
3059
- *
3060
- * This is the default stage for legacy NaviosPlugin implementations.
3061
- *
3062
- * @example
3063
- * ```typescript
3064
- * export const defineOpenApiPlugin = definePostModulesInitPlugin<
3065
- * BunApplicationServiceInterface
3066
- * >()({
3067
- * name: 'openapi',
3068
- * register: async (context, options: OpenApiOptions) => {
3069
- * // Routes are registered, can generate OpenAPI docs
3070
- * },
3071
- * })
3072
- * ```
3073
- */ function definePostModulesInitPlugin() {
3074
- return createPluginFactory(PluginStages.POST_MODULES_INIT);
3075
- }
3076
- /**
3077
- * Define a plugin that runs before adapter signals ready.
3078
- *
3079
- * Context: full
3080
- */ function definePreReadyPlugin() {
3081
- return createPluginFactory(PluginStages.PRE_READY);
3082
- }
3083
- /**
3084
- * Define a plugin that runs after adapter signals ready.
3085
- *
3086
- * Context: full - this is the final stage, app is fully initialized
3087
- *
3088
- * @example
3089
- * ```typescript
3090
- * export const defineStartupLogPlugin = definePostReadyPlugin()({
3091
- * name: 'startup-log',
3092
- * register: (context) => {
3093
- * console.log('Application fully initialized!')
3094
- * },
3095
- * })
3096
- * ```
3097
- */ function definePostReadyPlugin() {
3098
- return createPluginFactory(PluginStages.POST_READY);
3099
- }
3100
-
3101
- //#endregion
3102
- //#region src/navios.environment.mts
3103
- function applyDecs2203RFactory$1() {
3104
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3105
- return function addInitializer(initializer) {
3106
- assertNotFinished(decoratorFinishedRef, "addInitializer");
3107
- assertCallable(initializer, "An initializer");
3108
- initializers.push(initializer);
3109
- };
3110
- }
3111
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
3112
- var kindStr;
3113
- switch (kind) {
3114
- case 1:
3115
- kindStr = "accessor";
3116
- break;
3117
- case 2:
3118
- kindStr = "method";
3119
- break;
3120
- case 3:
3121
- kindStr = "getter";
3122
- break;
3123
- case 4:
3124
- kindStr = "setter";
3125
- break;
3126
- default: kindStr = "field";
3127
- }
3128
- var ctx = {
3129
- kind: kindStr,
3130
- name: isPrivate ? "#" + name : name,
3131
- static: isStatic,
3132
- private: isPrivate,
3133
- metadata
3134
- };
3135
- var decoratorFinishedRef = { v: false };
3136
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
3137
- var get, set;
3138
- if (kind === 0) if (isPrivate) {
3139
- get = desc.get;
3140
- set = desc.set;
3141
- } else {
3142
- get = function() {
3143
- return this[name];
3144
- };
3145
- set = function(v) {
3146
- this[name] = v;
3147
- };
3148
- }
3149
- else if (kind === 2) get = function() {
3150
- return desc.value;
3151
- };
3152
- else {
3153
- if (kind === 1 || kind === 3) get = function() {
3154
- return desc.get.call(this);
3155
- };
3156
- if (kind === 1 || kind === 4) set = function(v) {
3157
- desc.set.call(this, v);
3158
- };
3159
- }
3160
- ctx.access = get && set ? {
3161
- get,
3162
- set
3163
- } : get ? { get } : { set };
3164
- try {
3165
- return dec(value, ctx);
3166
- } finally {
3167
- decoratorFinishedRef.v = true;
3168
- }
3169
- }
3170
- function assertNotFinished(decoratorFinishedRef, fnName) {
3171
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
3172
- }
3173
- function assertCallable(fn, hint) {
3174
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
3175
- }
3176
- function assertValidReturnValue(kind, value) {
3177
- var type = typeof value;
3178
- if (kind === 1) {
3179
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
3180
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
3181
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
3182
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
3183
- } else if (type !== "function") {
3184
- var hint;
3185
- if (kind === 0) hint = "field";
3186
- else if (kind === 10) hint = "class";
3187
- else hint = "method";
3188
- throw new TypeError(hint + " decorators must return a function or void 0");
3189
- }
3190
- }
3191
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
3192
- var decs = decInfo[0];
3193
- var desc, init, value;
3194
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
3195
- get: decInfo[3],
3196
- set: decInfo[4]
3197
- };
3198
- else if (kind === 3) desc = { get: decInfo[3] };
3199
- else if (kind === 4) desc = { set: decInfo[3] };
3200
- else desc = { value: decInfo[3] };
3201
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
3202
- if (kind === 1) value = {
3203
- get: desc.get,
3204
- set: desc.set
3205
- };
3206
- else if (kind === 2) value = desc.value;
3207
- else if (kind === 3) value = desc.get;
3208
- else if (kind === 4) value = desc.set;
3209
- var newValue, get, set;
3210
- if (typeof decs === "function") {
3211
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3212
- if (newValue !== void 0) {
3213
- assertValidReturnValue(kind, newValue);
3214
- if (kind === 0) init = newValue;
3215
- else if (kind === 1) {
3216
- init = newValue.init;
3217
- get = newValue.get || value.get;
3218
- set = newValue.set || value.set;
3219
- value = {
3220
- get,
3221
- set
3222
- };
3223
- } else value = newValue;
3224
- }
3225
- } else for (var i = decs.length - 1; i >= 0; i--) {
3226
- var dec = decs[i];
3227
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3228
- if (newValue !== void 0) {
3229
- assertValidReturnValue(kind, newValue);
3230
- var newInit;
3231
- if (kind === 0) newInit = newValue;
3232
- else if (kind === 1) {
3233
- newInit = newValue.init;
3234
- get = newValue.get || value.get;
3235
- set = newValue.set || value.set;
3236
- value = {
3237
- get,
3238
- set
3239
- };
3240
- } else value = newValue;
3241
- if (newInit !== void 0) if (init === void 0) init = newInit;
3242
- else if (typeof init === "function") init = [init, newInit];
3243
- else init.push(newInit);
3244
- }
3245
- }
3246
- if (kind === 0 || kind === 1) {
3247
- if (init === void 0) init = function(instance, init$1) {
3248
- return init$1;
3249
- };
3250
- else if (typeof init !== "function") {
3251
- var ownInitializers = init;
3252
- init = function(instance, init$1) {
3253
- var value$1 = init$1;
3254
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
3255
- return value$1;
3256
- };
3257
- } else {
3258
- var originalInitializer = init;
3259
- init = function(instance, init$1) {
3260
- return originalInitializer.call(instance, init$1);
3261
- };
3262
- }
3263
- ret.push(init);
3264
- }
3265
- if (kind !== 0) {
3266
- if (kind === 1) {
3267
- desc.get = value.get;
3268
- desc.set = value.set;
3269
- } else if (kind === 2) desc.value = value;
3270
- else if (kind === 3) desc.get = value;
3271
- else if (kind === 4) desc.set = value;
3272
- if (isPrivate) if (kind === 1) {
3273
- ret.push(function(instance, args) {
3274
- return value.get.call(instance, args);
3275
- });
3276
- ret.push(function(instance, args) {
3277
- return value.set.call(instance, args);
3278
- });
3279
- } else if (kind === 2) ret.push(value);
3280
- else ret.push(function(instance, args) {
3281
- return value.call(instance, args);
3282
- });
3283
- else Object.defineProperty(base, name, desc);
3284
- }
3285
- }
3286
- function applyMemberDecs(Class, decInfos, metadata) {
3287
- var ret = [];
3288
- var protoInitializers;
3289
- var staticInitializers;
3290
- var existingProtoNonFields = /* @__PURE__ */ new Map();
3291
- var existingStaticNonFields = /* @__PURE__ */ new Map();
3292
- for (var i = 0; i < decInfos.length; i++) {
3293
- var decInfo = decInfos[i];
3294
- if (!Array.isArray(decInfo)) continue;
3295
- var kind = decInfo[1];
3296
- var name = decInfo[2];
3297
- var isPrivate = decInfo.length > 3;
3298
- var isStatic = kind >= 5;
3299
- var base;
3300
- var initializers;
3301
- if (isStatic) {
3302
- base = Class;
3303
- kind = kind - 5;
3304
- staticInitializers = staticInitializers || [];
3305
- initializers = staticInitializers;
3306
- } else {
3307
- base = Class.prototype;
3308
- protoInitializers = protoInitializers || [];
3309
- initializers = protoInitializers;
3310
- }
3311
- if (kind !== 0 && !isPrivate) {
3312
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
3313
- var existingKind = existingNonFields.get(name) || 0;
3314
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
3315
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
3316
- else existingNonFields.set(name, true);
3317
- }
3318
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
3319
- }
3320
- pushInitializers(ret, protoInitializers);
3321
- pushInitializers(ret, staticInitializers);
3322
- return ret;
3323
- }
3324
- function pushInitializers(ret, initializers) {
3325
- if (initializers) ret.push(function(instance) {
3326
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
3327
- return instance;
3328
- });
3329
- }
3330
- function applyClassDecs(targetClass, classDecs, metadata) {
3331
- if (classDecs.length > 0) {
3332
- var initializers = [];
3333
- var newClass = targetClass;
3334
- var name = targetClass.name;
3335
- for (var i = classDecs.length - 1; i >= 0; i--) {
3336
- var decoratorFinishedRef = { v: false };
3337
- try {
3338
- var nextNewClass = classDecs[i](newClass, {
3339
- kind: "class",
3340
- name,
3341
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
3342
- metadata
3343
- });
3344
- } finally {
3345
- decoratorFinishedRef.v = true;
3346
- }
3347
- if (nextNewClass !== void 0) {
3348
- assertValidReturnValue(10, nextNewClass);
3349
- newClass = nextNewClass;
3350
- }
3351
- }
3352
- return [defineMetadata(newClass, metadata), function() {
3353
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
3354
- }];
3355
- }
3356
- }
3357
- function defineMetadata(Class, metadata) {
3358
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
3359
- configurable: true,
3360
- enumerable: true,
3361
- value: metadata
3362
- });
3363
- }
3364
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
3365
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
3366
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
3367
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
3368
- if (!classDecs.length) defineMetadata(targetClass, metadata);
3369
- return {
3370
- e,
3371
- get c() {
3372
- return applyClassDecs(targetClass, classDecs, metadata);
3373
- }
3374
- };
3375
- };
3376
- }
3377
- function _apply_decs_2203_r$1(targetClass, memberDecs, classDecs, parentClass) {
3378
- return (_apply_decs_2203_r$1 = applyDecs2203RFactory$1())(targetClass, memberDecs, classDecs, parentClass);
3379
- }
3380
- var _dec$1, _initClass$1;
3381
- let _NaviosEnvironment;
3382
- _dec$1 = Injectable();
3383
- var NaviosEnvironment = class {
3384
- static {
3385
- ({c: [_NaviosEnvironment, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
3386
- }
3387
- adapterConfigured = false;
3388
- tokens = /* @__PURE__ */ new Map();
3389
- setupEnvironment(tokens) {
3390
- const hasAdapterToken = tokens.has(AdapterToken);
3391
- if (hasAdapterToken && this.adapterConfigured) throw new Error("Adapter already configured. Only one adapter per application.");
3392
- for (const [token, value] of tokens) this.tokens.set(token, value);
3393
- if (hasAdapterToken) this.adapterConfigured = true;
3394
- }
3395
- getToken(token) {
3396
- return this.tokens.get(token);
3397
- }
3398
- hasAdapterSetup() {
3399
- return this.adapterConfigured;
3400
- }
3401
- static {
3402
- _initClass$1();
3403
- }
3404
- };
3405
-
3406
- //#endregion
3407
- //#region src/navios.application.mts
3408
- function applyDecs2203RFactory() {
3409
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3410
- return function addInitializer(initializer) {
3411
- assertNotFinished(decoratorFinishedRef, "addInitializer");
3412
- assertCallable(initializer, "An initializer");
3413
- initializers.push(initializer);
3414
- };
3415
- }
3416
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
3417
- var kindStr;
3418
- switch (kind) {
3419
- case 1:
3420
- kindStr = "accessor";
3421
- break;
3422
- case 2:
3423
- kindStr = "method";
3424
- break;
3425
- case 3:
3426
- kindStr = "getter";
3427
- break;
3428
- case 4:
3429
- kindStr = "setter";
3430
- break;
3431
- default: kindStr = "field";
3432
- }
3433
- var ctx = {
3434
- kind: kindStr,
3435
- name: isPrivate ? "#" + name : name,
3436
- static: isStatic,
3437
- private: isPrivate,
3438
- metadata
3439
- };
3440
- var decoratorFinishedRef = { v: false };
3441
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
3442
- var get, set;
3443
- if (kind === 0) if (isPrivate) {
3444
- get = desc.get;
3445
- set = desc.set;
3446
- } else {
3447
- get = function() {
3448
- return this[name];
3449
- };
3450
- set = function(v) {
3451
- this[name] = v;
3452
- };
3453
- }
3454
- else if (kind === 2) get = function() {
3455
- return desc.value;
3456
- };
3457
- else {
3458
- if (kind === 1 || kind === 3) get = function() {
3459
- return desc.get.call(this);
3460
- };
3461
- if (kind === 1 || kind === 4) set = function(v) {
3462
- desc.set.call(this, v);
3463
- };
3464
- }
3465
- ctx.access = get && set ? {
3466
- get,
3467
- set
3468
- } : get ? { get } : { set };
3469
- try {
3470
- return dec(value, ctx);
3471
- } finally {
3472
- decoratorFinishedRef.v = true;
3473
- }
3474
- }
3475
- function assertNotFinished(decoratorFinishedRef, fnName) {
3476
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
3477
- }
3478
- function assertCallable(fn, hint) {
3479
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
3480
- }
3481
- function assertValidReturnValue(kind, value) {
3482
- var type = typeof value;
3483
- if (kind === 1) {
3484
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
3485
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
3486
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
3487
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
3488
- } else if (type !== "function") {
3489
- var hint;
3490
- if (kind === 0) hint = "field";
3491
- else if (kind === 10) hint = "class";
3492
- else hint = "method";
3493
- throw new TypeError(hint + " decorators must return a function or void 0");
3494
- }
3495
- }
3496
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
3497
- var decs = decInfo[0];
3498
- var desc, init, value;
3499
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
3500
- get: decInfo[3],
3501
- set: decInfo[4]
3502
- };
3503
- else if (kind === 3) desc = { get: decInfo[3] };
3504
- else if (kind === 4) desc = { set: decInfo[3] };
3505
- else desc = { value: decInfo[3] };
3506
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
3507
- if (kind === 1) value = {
3508
- get: desc.get,
3509
- set: desc.set
3510
- };
3511
- else if (kind === 2) value = desc.value;
3512
- else if (kind === 3) value = desc.get;
3513
- else if (kind === 4) value = desc.set;
3514
- var newValue, get, set;
3515
- if (typeof decs === "function") {
3516
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3517
- if (newValue !== void 0) {
3518
- assertValidReturnValue(kind, newValue);
3519
- if (kind === 0) init = newValue;
3520
- else if (kind === 1) {
3521
- init = newValue.init;
3522
- get = newValue.get || value.get;
3523
- set = newValue.set || value.set;
3524
- value = {
3525
- get,
3526
- set
3527
- };
3528
- } else value = newValue;
3529
- }
3530
- } else for (var i = decs.length - 1; i >= 0; i--) {
3531
- var dec = decs[i];
3532
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3533
- if (newValue !== void 0) {
3534
- assertValidReturnValue(kind, newValue);
3535
- var newInit;
3536
- if (kind === 0) newInit = newValue;
3537
- else if (kind === 1) {
3538
- newInit = newValue.init;
3539
- get = newValue.get || value.get;
3540
- set = newValue.set || value.set;
3541
- value = {
3542
- get,
3543
- set
3544
- };
3545
- } else value = newValue;
3546
- if (newInit !== void 0) if (init === void 0) init = newInit;
3547
- else if (typeof init === "function") init = [init, newInit];
3548
- else init.push(newInit);
3549
- }
3550
- }
3551
- if (kind === 0 || kind === 1) {
3552
- if (init === void 0) init = function(instance, init$1) {
3553
- return init$1;
3554
- };
3555
- else if (typeof init !== "function") {
3556
- var ownInitializers = init;
3557
- init = function(instance, init$1) {
3558
- var value$1 = init$1;
3559
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
3560
- return value$1;
3561
- };
3562
- } else {
3563
- var originalInitializer = init;
3564
- init = function(instance, init$1) {
3565
- return originalInitializer.call(instance, init$1);
3566
- };
3567
- }
3568
- ret.push(init);
3569
- }
3570
- if (kind !== 0) {
3571
- if (kind === 1) {
3572
- desc.get = value.get;
3573
- desc.set = value.set;
3574
- } else if (kind === 2) desc.value = value;
3575
- else if (kind === 3) desc.get = value;
3576
- else if (kind === 4) desc.set = value;
3577
- if (isPrivate) if (kind === 1) {
3578
- ret.push(function(instance, args) {
3579
- return value.get.call(instance, args);
3580
- });
3581
- ret.push(function(instance, args) {
3582
- return value.set.call(instance, args);
3583
- });
3584
- } else if (kind === 2) ret.push(value);
3585
- else ret.push(function(instance, args) {
3586
- return value.call(instance, args);
3587
- });
3588
- else Object.defineProperty(base, name, desc);
3589
- }
3590
- }
3591
- function applyMemberDecs(Class, decInfos, metadata) {
3592
- var ret = [];
3593
- var protoInitializers;
3594
- var staticInitializers;
3595
- var existingProtoNonFields = /* @__PURE__ */ new Map();
3596
- var existingStaticNonFields = /* @__PURE__ */ new Map();
3597
- for (var i = 0; i < decInfos.length; i++) {
3598
- var decInfo = decInfos[i];
3599
- if (!Array.isArray(decInfo)) continue;
3600
- var kind = decInfo[1];
3601
- var name = decInfo[2];
3602
- var isPrivate = decInfo.length > 3;
3603
- var isStatic = kind >= 5;
3604
- var base;
3605
- var initializers;
3606
- if (isStatic) {
3607
- base = Class;
3608
- kind = kind - 5;
3609
- staticInitializers = staticInitializers || [];
3610
- initializers = staticInitializers;
3611
- } else {
3612
- base = Class.prototype;
3613
- protoInitializers = protoInitializers || [];
3614
- initializers = protoInitializers;
3615
- }
3616
- if (kind !== 0 && !isPrivate) {
3617
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
3618
- var existingKind = existingNonFields.get(name) || 0;
3619
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
3620
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
3621
- else existingNonFields.set(name, true);
3622
- }
3623
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
3624
- }
3625
- pushInitializers(ret, protoInitializers);
3626
- pushInitializers(ret, staticInitializers);
3627
- return ret;
3628
- }
3629
- function pushInitializers(ret, initializers) {
3630
- if (initializers) ret.push(function(instance) {
3631
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
3632
- return instance;
3633
- });
3634
- }
3635
- function applyClassDecs(targetClass, classDecs, metadata) {
3636
- if (classDecs.length > 0) {
3637
- var initializers = [];
3638
- var newClass = targetClass;
3639
- var name = targetClass.name;
3640
- for (var i = classDecs.length - 1; i >= 0; i--) {
3641
- var decoratorFinishedRef = { v: false };
3642
- try {
3643
- var nextNewClass = classDecs[i](newClass, {
3644
- kind: "class",
3645
- name,
3646
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
3647
- metadata
3648
- });
3649
- } finally {
3650
- decoratorFinishedRef.v = true;
3651
- }
3652
- if (nextNewClass !== void 0) {
3653
- assertValidReturnValue(10, nextNewClass);
3654
- newClass = nextNewClass;
3655
- }
3656
- }
3657
- return [defineMetadata(newClass, metadata), function() {
3658
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
3659
- }];
3660
- }
3661
- }
3662
- function defineMetadata(Class, metadata) {
3663
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
3664
- configurable: true,
3665
- enumerable: true,
3666
- value: metadata
3667
- });
3668
- }
3669
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
3670
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
3671
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
3672
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
3673
- if (!classDecs.length) defineMetadata(targetClass, metadata);
3674
- return {
3675
- e,
3676
- get c() {
3677
- return applyClassDecs(targetClass, classDecs, metadata);
3678
- }
3679
- };
3680
- };
3681
- }
3682
- function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
3683
- return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
3684
- }
3685
- var _dec, _initClass;
3686
- let _NaviosApplication;
3687
- _dec = Injectable();
3688
- var NaviosApplication = class {
3689
- static {
3690
- ({c: [_NaviosApplication, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
3691
- }
3692
- environment = inject(_NaviosEnvironment);
3693
- moduleLoader = inject(_ModuleLoaderService);
3694
- adapter = null;
3695
- logger = inject(Logger, { context: _NaviosApplication.name });
3696
- container = inject(Container);
3697
- appModule = null;
3698
- options = { adapter: [] };
3699
- /**
3700
- * Plugin storage organized by stage for efficient execution.
3701
- * Each stage has a Set of plugin definitions.
3702
- */ plugins = new Map(PLUGIN_STAGES_ORDER.map((stage) => [stage, /* @__PURE__ */ new Set()]));
3703
- /**
3704
- * Queue of adapter configuration methods to apply after adapter resolution.
3705
- * Allows calling methods like enableCors() before init().
3706
- */ pendingAdapterCalls = [];
3707
- /**
3708
- * Indicates whether the application has been initialized.
3709
- * Set to `true` after `init()` completes successfully.
3710
- */ isInitialized = false;
3711
- /**
3712
- * Sets up the application with the provided module and options.
3713
- * This is called automatically by NaviosFactory.create().
3714
- *
3715
- * Note: Adapter resolution has been moved to init() to allow
3716
- * plugins to modify the container/registry before adapter instantiation.
3717
- *
3718
- * @param appModule - The root application module
3719
- * @param options - Application configuration options
3720
- * @internal
3721
- */ async setup(appModule, options = { adapter: [] }) {
3722
- this.appModule = appModule;
3723
- this.options = options;
3724
- }
3725
- /**
3726
- * Gets the dependency injection container used by this application.
3727
- *
3728
- * @returns The Container instance
3729
- */ getContainer() {
3730
- return this.container;
3731
- }
3732
- /**
3733
- * Returns the current adapter instance.
3734
- *
3735
- * @returns The adapter instance
3736
- * @throws Error if adapter is not initialized
3737
- */ getAdapter() {
3738
- if (!this.adapter) throw new Error("Adapter not initialized");
3739
- return this.adapter;
3740
- }
3741
- /**
3742
- * Registers one or more plugins for initialization during the application lifecycle.
3743
- *
3744
- * Plugins can target specific stages or use the legacy interface (defaults to post:modules-init).
3745
- * Plugins are executed in stage order, and within a stage in registration order.
3746
- *
3747
- * @param definitions - Single plugin definition or array of definitions
3748
- * @returns this for method chaining
3749
- *
3750
- * @example
3751
- * ```typescript
3752
- * // Single plugin (legacy or staged)
3753
- * app.usePlugin(defineOpenApiPlugin({ info: { title: 'My API', version: '1.0.0' } }))
3754
- *
3755
- * // Multiple plugins in one call
3756
- * app.usePlugin([
3757
- * defineOtelPlugin({ serviceName: 'my-service' }),
3758
- * defineOpenApiPlugin({ info: { title: 'My API', version: '1.0.0' } }),
3759
- * ])
3760
- *
3761
- * // Staged plugin with explicit stage
3762
- * app.usePlugin(definePreAdapterResolvePlugin({
3763
- * name: 'early-setup',
3764
- * register: (ctx) => { ... },
3765
- * })({}))
3766
- * ```
3767
- */ usePlugin(definitions) {
3768
- const definitionsArray = Array.isArray(definitions) ? definitions : [definitions];
3769
- for (const definition of definitionsArray) {
3770
- const stage = this.resolvePluginStage(definition);
3771
- const stageSet = this.plugins.get(stage);
3772
- if (!stageSet) throw new Error(`Unknown plugin stage: ${stage}`);
3773
- stageSet.add(definition);
3774
- this.logger.debug(`Registered plugin "${definition.plugin.name}" for stage: ${stage}`);
3775
- }
3776
- return this;
3777
- }
3778
- /**
3779
- * Resolves the stage for a plugin definition.
3780
- * Staged plugins use their explicit stage, legacy plugins default to post:modules-init.
3781
- */ resolvePluginStage(definition) {
3782
- if ("stage" in definition.plugin) return definition.plugin.stage;
3783
- return PluginStages.POST_MODULES_INIT;
3784
- }
3785
- /**
3786
- * Initializes the application.
3787
- *
3788
- * This method executes the following lifecycle stages:
3789
- * 1. pre:modules-traverse → Load modules → post:modules-traverse
3790
- * 2. pre:adapter-resolve → Resolve adapter → post:adapter-resolve
3791
- * 3. pre:adapter-setup → Setup adapter → post:adapter-setup
3792
- * 4. pre:modules-init → Initialize modules → post:modules-init
3793
- * 5. pre:ready → Ready signal → post:ready
3794
- *
3795
- * Must be called before `listen()`.
3796
- *
3797
- * @throws Error if app module is not set
3798
- *
3799
- * @example
3800
- * ```typescript
3801
- * const app = await NaviosFactory.create(AppModule, {
3802
- * adapter: defineFastifyEnvironment(),
3803
- * })
3804
- * await app.init()
3805
- * await app.listen({ port: 3000 })
3806
- * ```
3807
- */ async init() {
3808
- if (!this.appModule) throw new Error("App module is not set. Call setAppModule() first.");
3809
- await this.wrapStage(PluginStageBase.MODULES_TRAVERSE, () => this.moduleLoader.loadModules(this.appModule));
3810
- if (this.environment.hasAdapterSetup()) {
3811
- await this.wrapStage(PluginStageBase.ADAPTER_RESOLVE, async () => {
3812
- this.adapter = await this.container.get(AdapterToken);
3813
- this.applyPendingAdapterCalls();
3814
- });
3815
- if (this.adapter) await this.wrapStage(PluginStageBase.ADAPTER_SETUP, () => this.adapter.setupAdapter(this.options));
3816
- }
3817
- await this.wrapStage(PluginStageBase.MODULES_INIT, () => this.initModules());
3818
- if (this.adapter) await this.wrapStage(PluginStageBase.READY, () => this.adapter.ready());
3819
- this.isInitialized = true;
3820
- this.logger.debug("Navios application initialized");
3821
- }
3822
- /**
3823
- * Wraps an operation with pre/post plugin stage execution.
3824
- *
3825
- * @param baseName - The base stage name (e.g., 'modules-traverse')
3826
- * @param operation - The operation to execute between pre/post stages
3827
- */ async wrapStage(baseName, operation) {
3828
- await this.executePluginStage(preStage(baseName));
3829
- const result = await operation();
3830
- await this.executePluginStage(postStage(baseName));
3831
- return result;
3832
- }
3833
- /**
3834
- * Executes all plugins registered for a specific stage.
3835
- *
3836
- * @param stage - The lifecycle stage to execute plugins for
3837
- */ async executePluginStage(stage) {
3838
- const stagePlugins = this.plugins.get(stage);
3839
- if (!stagePlugins || stagePlugins.size === 0) return;
3840
- const context = this.buildContextForStage(stage);
3841
- this.logger.debug(`Executing ${stagePlugins.size} plugin(s) for stage: ${stage}`);
3842
- for (const { plugin, options } of stagePlugins) {
3843
- this.logger.debug(`Executing plugin: ${plugin.name} (stage: ${stage})`);
3844
- try {
3845
- await plugin.register(context, options);
3846
- } catch (error) {
3847
- this.logger.error(`Plugin "${plugin.name}" failed at stage "${stage}"`, error);
3848
- throw error;
3849
- }
3850
- }
3851
- }
3852
- /**
3853
- * Builds the appropriate context object for a given stage.
3854
- *
3855
- * @param stage - The lifecycle stage
3856
- * @returns Context object with stage-appropriate properties
3857
- */ buildContextForStage(stage) {
3858
- const baseContext = { container: this.container };
3859
- if (stage === PluginStages.PRE_MODULES_TRAVERSE) return baseContext;
3860
- const modulesContext = {
3861
- ...baseContext,
3862
- modules: this.moduleLoader.getAllModules(),
3863
- moduleLoader: this.moduleLoader
3864
- };
3865
- if (stage === PluginStages.POST_MODULES_TRAVERSE || stage === PluginStages.PRE_ADAPTER_RESOLVE) return modulesContext;
3866
- if (!this.adapter) throw new Error(`Cannot execute stage "${stage}" without adapter`);
3867
- return {
3868
- ...modulesContext,
3869
- adapter: this.adapter
3870
- };
3871
- }
3872
- async initModules() {
3873
- const modules = this.moduleLoader.getAllModules();
3874
- if (this.adapter) await this.adapter.onModulesInit(modules);
3875
- }
3876
- /**
3877
- * Applies any pending adapter configuration calls that were queued
3878
- * before the adapter was resolved.
3879
- */ applyPendingAdapterCalls() {
3880
- if (!this.adapter || this.pendingAdapterCalls.length === 0) return;
3881
- for (const { method, args } of this.pendingAdapterCalls) {
3882
- assertAdapterSupports(this.adapter, method);
3883
- this.adapter[method](...args);
3884
- }
3885
- this.pendingAdapterCalls = [];
3886
- }
3887
- async get(token, args) {
3888
- return this.container.get(token, args);
3889
- }
3890
- /**
3891
- * Configures the adapter with additional options before initialization.
3892
- *
3893
- * This method allows setting adapter-specific configuration options
3894
- * before the adapter is initialized. Must be called before `init()`.
3895
- *
3896
- * @param options - Adapter-specific configuration options
3897
- * @returns this for method chaining
3898
- * @throws Error if called after init() or if adapter doesn't support configure
3899
- *
3900
- * @example
3901
- * ```typescript
3902
- * // With Fastify adapter
3903
- * app.configure({ trustProxy: true, logger: true })
3904
- *
3905
- * // With Bun adapter
3906
- * app.configure({ development: true })
3907
- * ```
3908
- */ configure(options) {
3909
- if (this.isInitialized) throw new Error("configure() must be called before init()");
3910
- if (this.adapter) {
3911
- assertAdapterSupports(this.adapter, "configure");
3912
- this.adapter.configure(options);
3913
- } else this.pendingAdapterCalls.push({
3914
- method: "configure",
3915
- args: [options]
3916
- });
3917
- return this;
3918
- }
3919
- /**
3920
- * Enables CORS (Cross-Origin Resource Sharing) for the application.
3921
- *
3922
- * @param options - CORS configuration options (adapter-specific)
3923
- * @throws Error if adapter doesn't support enableCors
3924
- *
3925
- * @example
3926
- * ```typescript
3927
- * app.enableCors({
3928
- * origin: ['http://localhost:3000', 'https://example.com'],
3929
- * methods: ['GET', 'POST', 'PUT', 'DELETE'],
3930
- * credentials: true,
3931
- * })
3932
- * ```
3933
- */ enableCors(options) {
3934
- if (this.adapter) {
3935
- assertAdapterSupports(this.adapter, "enableCors");
3936
- this.adapter.enableCors(options);
3937
- } else this.pendingAdapterCalls.push({
3938
- method: "enableCors",
3939
- args: [options]
3940
- });
3941
- }
3942
- /**
3943
- * Enables multipart/form-data support for file uploads.
3944
- *
3945
- * @param options - Multipart configuration options (adapter-specific)
3946
- * @throws Error if adapter doesn't support enableMultipart
3947
- *
3948
- * @example
3949
- * ```typescript
3950
- * app.enableMultipart({
3951
- * limits: {
3952
- * fileSize: 1024 * 1024 * 10, // 10MB
3953
- * },
3954
- * })
3955
- * ```
3956
- */ enableMultipart(options) {
3957
- if (this.adapter) {
3958
- assertAdapterSupports(this.adapter, "enableMultipart");
3959
- this.adapter.enableMultipart(options);
3960
- } else this.pendingAdapterCalls.push({
3961
- method: "enableMultipart",
3962
- args: [options]
3963
- });
3964
- }
3965
- /**
3966
- * Sets a global prefix for all routes.
3967
- *
3968
- * @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
3969
- * @throws Error if adapter doesn't support setGlobalPrefix
3970
- *
3971
- * @example
3972
- * ```typescript
3973
- * app.setGlobalPrefix('/api/v1')
3974
- * // All routes will be prefixed with /api/v1
3975
- * ```
3976
- */ setGlobalPrefix(prefix) {
3977
- if (this.adapter) {
3978
- assertAdapterSupports(this.adapter, "setGlobalPrefix");
3979
- this.adapter.setGlobalPrefix(prefix);
3980
- } else this.pendingAdapterCalls.push({
3981
- method: "setGlobalPrefix",
3982
- args: [prefix]
3983
- });
3984
- }
3985
- /**
3986
- * Gets the underlying HTTP server instance.
3987
- *
3988
- * The type of the returned server depends on the adapter used:
3989
- * - Fastify adapter: Returns FastifyInstance
3990
- * - Bun adapter: Returns Bun.Server
3991
- *
3992
- * @returns The HTTP server instance
3993
- * @throws Error if adapter doesn't support getServer
3994
- *
3995
- * @example
3996
- * ```typescript
3997
- * const server = app.getServer()
3998
- * // Use adapter-specific server methods
3999
- * ```
4000
- */ getServer() {
4001
- assertAdapterSupports(this.adapter, "getServer");
4002
- return this.adapter.getServer();
4003
- }
4004
- /**
4005
- * Starts the HTTP server and begins listening for requests.
4006
- *
4007
- * @param options - Listen options (port, host, etc.)
4008
- * @throws Error if adapter doesn't support listen
4009
- *
4010
- * @example
4011
- * ```typescript
4012
- * await app.listen({ port: 3000, host: '0.0.0.0' })
4013
- * ```
4014
- */ async listen(options) {
4015
- assertAdapterSupports(this.adapter, "listen");
4016
- return this.adapter.listen(options);
4017
- }
4018
- /**
4019
- * Disposes of application resources.
4020
- *
4021
- * Cleans up the adapter and module loader.
4022
- * This method is called automatically by `close()`.
4023
- */ async dispose() {
4024
- if (this.adapter) await this.adapter.dispose();
4025
- if (this.moduleLoader) this.moduleLoader.dispose();
4026
- }
4027
- /**
4028
- * Closes the application and cleans up all resources.
4029
- *
4030
- * This is an alias for `dispose()`.
4031
- *
4032
- * @example
4033
- * ```typescript
4034
- * // Graceful shutdown
4035
- * process.on('SIGTERM', async () => {
4036
- * await app.close()
4037
- * process.exit(0)
4038
- * })
4039
- * ```
4040
- */ async close() {
4041
- await this.dispose();
4042
- }
4043
- static {
4044
- _initClass();
4045
- }
4046
- };
4047
-
4048
- //#endregion
4049
- //#region src/navios.factory.mts
4050
- /**
4051
- * Factory class for creating and configuring Navios applications.
4052
- *
4053
- * This is the main entry point for bootstrapping a Navios application.
4054
- * It handles dependency injection container setup, adapter registration,
4055
- * and logger configuration.
4056
- *
4057
- * @example
4058
- * ```typescript
4059
- * import { NaviosFactory } from '@navios/core'
4060
- * import { defineFastifyEnvironment } from '@navios/adapter-fastify'
4061
- *
4062
- * const app = await NaviosFactory.create(AppModule, {
4063
- * adapter: defineFastifyEnvironment(),
4064
- * logger: ['log', 'error', 'warn'],
4065
- * })
4066
- *
4067
- * await app.init()
4068
- * await app.listen({ port: 3000 })
4069
- * ```
4070
- */ var NaviosFactory = class {
4071
- /**
4072
- * Creates a new Navios application instance.
4073
- *
4074
- * This method sets up the dependency injection container, registers the adapter,
4075
- * configures logging, and initializes the application with the provided module.
4076
- *
4077
- * @typeParam Environment - Adapter environment interface for type-safe access
4078
- * to adapter-specific features. When specified, methods like `getServer()`,
4079
- * `enableCors()`, `listen()`, and `configure()` will have proper types.
4080
- *
4081
- * @param appModule - The root application module class decorated with @Module()
4082
- * @param options - Configuration options for the application
4083
- * @param options.adapter - Adapter environment (required for server functionality)
4084
- * @param options.logger - Logger configuration. Can be:
4085
- * - A LoggerService instance for custom logging
4086
- * - An array of LogLevel strings to enable specific log levels
4087
- * - `false` to disable logging
4088
- * @param options.container - Optional custom dependency injection container (useful for testing)
4089
- * @returns A configured NaviosApplication instance ready to be initialized
4090
- *
4091
- * @example
4092
- * ```typescript
4093
- * // Basic setup with Fastify adapter
4094
- * const app = await NaviosFactory.create(AppModule, {
4095
- * adapter: defineFastifyEnvironment(),
4096
- * })
4097
- *
4098
- * // Type-safe setup with Fastify environment
4099
- * import { FastifyEnvironment } from '@navios/adapter-fastify'
4100
- *
4101
- * const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
4102
- * adapter: defineFastifyEnvironment(),
4103
- * })
4104
- * app.configure({ trustProxy: true })
4105
- * const server = app.getServer() // FastifyInstance
4106
- *
4107
- * // With custom logger configuration
4108
- * const app = await NaviosFactory.create(AppModule, {
4109
- * adapter: defineFastifyEnvironment(),
4110
- * logger: ['error', 'warn', 'log'],
4111
- * })
4112
- *
4113
- * // With custom container for testing
4114
- * const container = new Container()
4115
- * const app = await NaviosFactory.create(AppModule, {
4116
- * adapter: defineFastifyEnvironment(),
4117
- * container,
4118
- * })
4119
- * ```
4120
- */ static async create(appModule, options = { adapter: [] }) {
4121
- const container = options.container ?? new Container(options.registry);
4122
- if (options.enableRequestId === true) setRequestIdEnabled(true);
4123
- container.addInstance(NaviosOptionsToken, options);
4124
- await this.registerLoggerConfiguration(container, options);
4125
- const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
4126
- for (const adapter of adapters) await this.registerEnvironment(container, adapter);
4127
- const app = await container.get(_NaviosApplication);
4128
- await app.setup(appModule, options);
4129
- return app;
4130
- }
4131
- static async registerEnvironment(container, environment = {}) {
4132
- const naviosEnvironment = await container.get(_NaviosEnvironment);
4133
- const { tokens } = environment;
4134
- if (tokens) naviosEnvironment.setupEnvironment(tokens);
4135
- }
4136
- static async registerLoggerConfiguration(container, options) {
4137
- const { logger } = options;
4138
- if (Array.isArray(logger) || isNil(logger) || options.enableRequestId) {
4139
- (await container.get(LoggerOutput))?.setup({
4140
- logLevels: Array.isArray(logger) ? logger : void 0,
4141
- requestId: options.enableRequestId ?? false
4142
- });
4143
- return;
4144
- }
4145
- if (logger !== true && !isNil(logger)) container.addInstance(LoggerOutput, logger);
4146
- }
4147
- };
4148
-
4149
- //#endregion
4150
- export { stripEndSlash as $, preStage as A, setRequestIdEnabled as B, NotFoundResponderToken as C, PluginStageBase as D, PLUGIN_STAGES_ORDER as E, LoggerOutput as F, isNil as G, isConstructor as H, loggerOptionsSchema as I, isPlainObject as J, isNumber as K, generateRequestId as L, _LoggerInstance as M, _ConsoleLogger as N, PluginStages as O, Logger as P, normalizePath as Q, getRequestId as R, InternalServerErrorResponderToken as S, FrameworkError as T, isEmpty as U, addLeadingSlash as V, isFunction as W, isSymbol as X, isString as Y, isUndefined as Z, _GuardRunnerService as _, definePostAdapterSetupPlugin as a, yellow as at, _ErrorResponseProducerService as b, definePostReadyPlugin as c, definePreModulesInitPlugin as d, isLogLevelEnabled as et, definePreModulesTraversePlugin as f, _ModuleLoaderService as g, assertAdapterSupports as h, definePostAdapterResolvePlugin as i, clc as it, HttpException as j, postStage as k, definePreAdapterResolvePlugin as l, adapterSupports as m, _NaviosApplication as n, isLogLevel as nt, definePostModulesInitPlugin as o, definePreReadyPlugin as p, isObject as q, _NaviosEnvironment as r, LOG_LEVELS as rt, definePostModulesTraversePlugin as s, NaviosFactory as t, filterLogLevels as tt, definePreAdapterSetupPlugin as u, AbstractHandlerAdapterService as v, ValidationErrorResponderToken as w, ForbiddenResponderToken as x, _InstanceResolverService as y, runWithRequestId as z };
4151
- //# sourceMappingURL=navios.factory-DjUOOVVL.mjs.map