@navios/core 1.0.0 → 2.0.0-alpha.0

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