@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
@@ -0,0 +1,95 @@
1
+ const require_attribute_value = require("./attribute-value-CjX9ZkLq.cjs");
2
+ // src/modules/module-metadata.mts
3
+ const ModuleMetadataKey = Symbol.for("navios.core.module");
4
+ const ownOptions = /* @__PURE__ */ new Set([
5
+ "imports",
6
+ "guards",
7
+ "interceptors",
8
+ "providers",
9
+ "attributes"
10
+ ]);
11
+ function defineModuleMetadata(target, context, options) {
12
+ if (hasModuleMetadata(target)) throw new Error(`[Navios] ${target.name} is already a module. One @Module takes all of its options.`);
13
+ const entries = /* @__PURE__ */ new Map();
14
+ for (const [name, value] of Object.entries(options)) if (!ownOptions.has(name) && value !== void 0) entries.set(name, value);
15
+ const imports = require_attribute_value.unique([...options.imports ?? []]);
16
+ assertImportsDefined(target, imports);
17
+ const providers = [...options.providers ?? []];
18
+ assertProviders(target.name, providers);
19
+ const base = Object.getPrototypeOf(target)[ModuleMetadataKey];
20
+ const module = {
21
+ imports,
22
+ guards: require_attribute_value.prepend(require_attribute_value.prepend(require_attribute_value.classGuards(context), base?.guards), options.guards),
23
+ interceptors: require_attribute_value.prepend(require_attribute_value.prepend(require_attribute_value.classInterceptors(context), base?.interceptors), options.interceptors),
24
+ providers,
25
+ attributes: require_attribute_value.classAttributes(context),
26
+ entries
27
+ };
28
+ for (const [key, value] of base?.attributes ?? []) if (!module.attributes.has(key)) module.attributes.set(key, value);
29
+ Object.defineProperty(target, ModuleMetadataKey, {
30
+ value: module,
31
+ configurable: true,
32
+ enumerable: false
33
+ });
34
+ return module;
35
+ }
36
+ /**
37
+ * An import that is `undefined` is what an import cycle between files leaves
38
+ * behind: the importing file ran before the imported one defined its class.
39
+ * @internal
40
+ */
41
+ function assertImportsDefined(target, imports) {
42
+ const index = imports.findIndex((imported) => imported === void 0 || imported === null);
43
+ if (index !== -1) throw new Error(`[Navios] Module ${target.name} imports ${String(imports[index])} at index ${index} of its imports. This usually means the files of the two modules import each other, so the imported module was not defined yet when ${target.name} was. Break the import cycle.`);
44
+ }
45
+ /**
46
+ * Where there are no types, a class is easily listed for itself.
47
+ * @internal
48
+ */
49
+ function assertProviders(owner, providers) {
50
+ for (const provider of providers) {
51
+ if (typeof provider === "object" && provider !== null && "token" in provider) continue;
52
+ const listed = typeof provider === "function" ? provider.name : typeof provider === "object" && provider !== null ? "an object" : String(provider);
53
+ throw new Error(`[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use provide(token, ...); an @Injectable class needs no entry.`);
54
+ }
55
+ }
56
+ function getModuleMetadata(target) {
57
+ const metadata = Object.hasOwn(target, ModuleMetadataKey) ? target[ModuleMetadataKey] : void 0;
58
+ if (!metadata) throw new Error(`[Navios] ${target.name} is not a module. Make sure it is decorated with @Module.`);
59
+ return metadata;
60
+ }
61
+ function hasModuleMetadata(target) {
62
+ return Object.hasOwn(target, ModuleMetadataKey);
63
+ }
64
+ Object.defineProperty(exports, "assertImportsDefined", {
65
+ enumerable: true,
66
+ get: function() {
67
+ return assertImportsDefined;
68
+ }
69
+ });
70
+ Object.defineProperty(exports, "assertProviders", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return assertProviders;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "defineModuleMetadata", {
77
+ enumerable: true,
78
+ get: function() {
79
+ return defineModuleMetadata;
80
+ }
81
+ });
82
+ Object.defineProperty(exports, "getModuleMetadata", {
83
+ enumerable: true,
84
+ get: function() {
85
+ return getModuleMetadata;
86
+ }
87
+ });
88
+ Object.defineProperty(exports, "hasModuleMetadata", {
89
+ enumerable: true,
90
+ get: function() {
91
+ return hasModuleMetadata;
92
+ }
93
+ });
94
+
95
+ //# sourceMappingURL=module-metadata-C8S92seK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-metadata-C8S92seK.cjs","names":["unique","prepend","classGuards","classInterceptors","classAttributes"],"sources":["../src/modules/module-metadata.mts"],"sourcesContent":["import type { ClassType, Provider } from '@navios/di'\n\nimport {\n classAttributes,\n classGuards,\n classInterceptors,\n prepend,\n unique,\n} from '../metadata/class-metadata.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport interface ModuleMetadata {\n imports: ClassType[]\n guards: ClassType[]\n interceptors: ClassType[]\n providers: Provider[]\n attributes: Map<symbol, unknown>\n /**\n * Every option the module system itself does not use, by option name, as\n * written. A transport reads its own from here.\n */\n entries: Map<string, unknown>\n}\n\nconst ModuleMetadataKey = Symbol.for('navios.core.module')\n\nconst ownOptions = new Set(['imports', 'guards', 'interceptors', 'providers', 'attributes'])\n\nexport function defineModuleMetadata(\n target: ClassType,\n context: { metadata?: DecoratorMetadata },\n options: ModuleOptions,\n): ModuleMetadata {\n if (hasModuleMetadata(target)) {\n throw new Error(\n `[Navios] ${target.name} is already a module. One @Module takes all of its options.`,\n )\n }\n const entries = new Map<string, unknown>()\n for (const [name, value] of Object.entries(options)) {\n if (!ownOptions.has(name) && value !== undefined) {\n entries.set(name, value)\n }\n }\n const imports = unique([...(options.imports ?? [])])\n assertImportsDefined(target, imports)\n const providers = [...(options.providers ?? [])]\n assertProviders(target.name, providers)\n // Decorator metadata inherits by itself between two decorated classes. This\n // covers a class or a base class that was registered without decorators.\n const base = Object.getPrototypeOf(target)[ModuleMetadataKey] as ModuleMetadata | undefined\n const module: ModuleMetadata = {\n imports,\n guards: prepend(prepend(classGuards(context), base?.guards), options.guards),\n interceptors: prepend(\n prepend(classInterceptors(context), base?.interceptors),\n options.interceptors,\n ),\n providers,\n attributes: classAttributes(context),\n entries,\n }\n for (const [key, value] of base?.attributes ?? []) {\n if (!module.attributes.has(key)) {\n module.attributes.set(key, value)\n }\n }\n Object.defineProperty(target, ModuleMetadataKey, {\n value: module,\n configurable: true,\n enumerable: false,\n })\n return module\n}\n\n/**\n * An import that is `undefined` is what an import cycle between files leaves\n * behind: the importing file ran before the imported one defined its class.\n * @internal\n */\nexport function assertImportsDefined(target: ClassType, imports: readonly unknown[]): void {\n const index = imports.findIndex((imported) => imported === undefined || imported === null)\n if (index !== -1) {\n throw new Error(\n `[Navios] Module ${target.name} imports ${String(imports[index])} at index ${index} of ` +\n `its imports. This usually means the files of the two modules import each other, so the ` +\n `imported module was not defined yet when ${target.name} was. Break the import cycle.`,\n )\n }\n}\n\n/**\n * Where there are no types, a class is easily listed for itself.\n * @internal\n */\nexport function assertProviders(owner: string, providers: readonly unknown[]): void {\n for (const provider of providers) {\n if (typeof provider === 'object' && provider !== null && 'token' in provider) {\n continue\n }\n const listed =\n typeof provider === 'function'\n ? provider.name\n : typeof provider === 'object' && provider !== null\n ? 'an object'\n : String(provider)\n throw new Error(\n `[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use ` +\n `provide(token, ...); an @Injectable class needs no entry.`,\n )\n }\n}\n\nexport function getModuleMetadata(target: ClassType): ModuleMetadata {\n const metadata = Object.hasOwn(target, ModuleMetadataKey)\n ? ((target as any)[ModuleMetadataKey] as ModuleMetadata)\n : undefined\n if (!metadata) {\n throw new Error(\n `[Navios] ${target.name} is not a module. Make sure it is decorated with @Module.`,\n )\n }\n return metadata\n}\n\nexport function hasModuleMetadata(target: ClassType): boolean {\n return Object.hasOwn(target, ModuleMetadataKey)\n}\n"],"mappings":";;AA6BA,MAAM,oBAAoB,OAAO,IAAI,oBAAoB;A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F,IAAI,UAAU,IACZ,MAAM,IAAI,MACR,mBAAmB,OAAO,KAAK,WAAW,OAAO,QAAQ,MAAM,EAAE,YAAY,MAAM,sIAErC,OAAO,KAAK,8BAC5D;AAEJ;;;;;AAMA,SAAgB,gBAAgB,OAAe,WAAqC;CAClF,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI,OAAO,aAAa,YAAY,aAAa,QAAQ,WAAW,UAClE;EAEF,MAAM,SACJ,OAAO,aAAa,aAChB,SAAS,OACT,OAAO,aAAa,YAAY,aAAa,OAC3C,cACA,OAAO,QAAQ;EACvB,MAAM,IAAI,MACR,YAAY,MAAM,SAAS,OAAO,sGAEpC;CACF;AACF;AAEA,SAAgB,kBAAkB,QAAmC;CACnE,MAAM,WAAW,OAAO,OAAO,QAAQ,iBAAiB,IAClD,OAAe,qBACjB,KAAA;CACJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,YAAY,OAAO,KAAK,0DAC1B;CAEF,OAAO;AACT;AAEA,SAAgB,kBAAkB,QAA4B;CAC5D,OAAO,OAAO,OAAO,QAAQ,iBAAiB;AAChD"}
@@ -0,0 +1,66 @@
1
+ import { a as classGuards, c as unique, i as classAttributes, o as classInterceptors, s as prepend } from "./attribute-value-DMEA255r.mjs";
2
+ // src/modules/module-metadata.mts
3
+ const ModuleMetadataKey = Symbol.for("navios.core.module");
4
+ const ownOptions = /* @__PURE__ */ new Set([
5
+ "imports",
6
+ "guards",
7
+ "interceptors",
8
+ "providers",
9
+ "attributes"
10
+ ]);
11
+ function defineModuleMetadata(target, context, options) {
12
+ if (hasModuleMetadata(target)) throw new Error(`[Navios] ${target.name} is already a module. One @Module takes all of its options.`);
13
+ const entries = /* @__PURE__ */ new Map();
14
+ for (const [name, value] of Object.entries(options)) if (!ownOptions.has(name) && value !== void 0) entries.set(name, value);
15
+ const imports = unique([...options.imports ?? []]);
16
+ assertImportsDefined(target, imports);
17
+ const providers = [...options.providers ?? []];
18
+ assertProviders(target.name, providers);
19
+ const base = Object.getPrototypeOf(target)[ModuleMetadataKey];
20
+ const module = {
21
+ imports,
22
+ guards: prepend(prepend(classGuards(context), base?.guards), options.guards),
23
+ interceptors: prepend(prepend(classInterceptors(context), base?.interceptors), options.interceptors),
24
+ providers,
25
+ attributes: classAttributes(context),
26
+ entries
27
+ };
28
+ for (const [key, value] of base?.attributes ?? []) if (!module.attributes.has(key)) module.attributes.set(key, value);
29
+ Object.defineProperty(target, ModuleMetadataKey, {
30
+ value: module,
31
+ configurable: true,
32
+ enumerable: false
33
+ });
34
+ return module;
35
+ }
36
+ /**
37
+ * An import that is `undefined` is what an import cycle between files leaves
38
+ * behind: the importing file ran before the imported one defined its class.
39
+ * @internal
40
+ */
41
+ function assertImportsDefined(target, imports) {
42
+ const index = imports.findIndex((imported) => imported === void 0 || imported === null);
43
+ if (index !== -1) throw new Error(`[Navios] Module ${target.name} imports ${String(imports[index])} at index ${index} of its imports. This usually means the files of the two modules import each other, so the imported module was not defined yet when ${target.name} was. Break the import cycle.`);
44
+ }
45
+ /**
46
+ * Where there are no types, a class is easily listed for itself.
47
+ * @internal
48
+ */
49
+ function assertProviders(owner, providers) {
50
+ for (const provider of providers) {
51
+ if (typeof provider === "object" && provider !== null && "token" in provider) continue;
52
+ const listed = typeof provider === "function" ? provider.name : typeof provider === "object" && provider !== null ? "an object" : String(provider);
53
+ throw new Error(`[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use provide(token, ...); an @Injectable class needs no entry.`);
54
+ }
55
+ }
56
+ function getModuleMetadata(target) {
57
+ const metadata = Object.hasOwn(target, ModuleMetadataKey) ? target[ModuleMetadataKey] : void 0;
58
+ if (!metadata) throw new Error(`[Navios] ${target.name} is not a module. Make sure it is decorated with @Module.`);
59
+ return metadata;
60
+ }
61
+ function hasModuleMetadata(target) {
62
+ return Object.hasOwn(target, ModuleMetadataKey);
63
+ }
64
+ export { hasModuleMetadata as a, getModuleMetadata as i, assertProviders as n, defineModuleMetadata as r, assertImportsDefined as t };
65
+
66
+ //# sourceMappingURL=module-metadata-k3RTt20x.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-metadata-k3RTt20x.mjs","names":[],"sources":["../src/modules/module-metadata.mts"],"sourcesContent":["import type { ClassType, Provider } from '@navios/di'\n\nimport {\n classAttributes,\n classGuards,\n classInterceptors,\n prepend,\n unique,\n} from '../metadata/class-metadata.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport interface ModuleMetadata {\n imports: ClassType[]\n guards: ClassType[]\n interceptors: ClassType[]\n providers: Provider[]\n attributes: Map<symbol, unknown>\n /**\n * Every option the module system itself does not use, by option name, as\n * written. A transport reads its own from here.\n */\n entries: Map<string, unknown>\n}\n\nconst ModuleMetadataKey = Symbol.for('navios.core.module')\n\nconst ownOptions = new Set(['imports', 'guards', 'interceptors', 'providers', 'attributes'])\n\nexport function defineModuleMetadata(\n target: ClassType,\n context: { metadata?: DecoratorMetadata },\n options: ModuleOptions,\n): ModuleMetadata {\n if (hasModuleMetadata(target)) {\n throw new Error(\n `[Navios] ${target.name} is already a module. One @Module takes all of its options.`,\n )\n }\n const entries = new Map<string, unknown>()\n for (const [name, value] of Object.entries(options)) {\n if (!ownOptions.has(name) && value !== undefined) {\n entries.set(name, value)\n }\n }\n const imports = unique([...(options.imports ?? [])])\n assertImportsDefined(target, imports)\n const providers = [...(options.providers ?? [])]\n assertProviders(target.name, providers)\n // Decorator metadata inherits by itself between two decorated classes. This\n // covers a class or a base class that was registered without decorators.\n const base = Object.getPrototypeOf(target)[ModuleMetadataKey] as ModuleMetadata | undefined\n const module: ModuleMetadata = {\n imports,\n guards: prepend(prepend(classGuards(context), base?.guards), options.guards),\n interceptors: prepend(\n prepend(classInterceptors(context), base?.interceptors),\n options.interceptors,\n ),\n providers,\n attributes: classAttributes(context),\n entries,\n }\n for (const [key, value] of base?.attributes ?? []) {\n if (!module.attributes.has(key)) {\n module.attributes.set(key, value)\n }\n }\n Object.defineProperty(target, ModuleMetadataKey, {\n value: module,\n configurable: true,\n enumerable: false,\n })\n return module\n}\n\n/**\n * An import that is `undefined` is what an import cycle between files leaves\n * behind: the importing file ran before the imported one defined its class.\n * @internal\n */\nexport function assertImportsDefined(target: ClassType, imports: readonly unknown[]): void {\n const index = imports.findIndex((imported) => imported === undefined || imported === null)\n if (index !== -1) {\n throw new Error(\n `[Navios] Module ${target.name} imports ${String(imports[index])} at index ${index} of ` +\n `its imports. This usually means the files of the two modules import each other, so the ` +\n `imported module was not defined yet when ${target.name} was. Break the import cycle.`,\n )\n }\n}\n\n/**\n * Where there are no types, a class is easily listed for itself.\n * @internal\n */\nexport function assertProviders(owner: string, providers: readonly unknown[]): void {\n for (const provider of providers) {\n if (typeof provider === 'object' && provider !== null && 'token' in provider) {\n continue\n }\n const listed =\n typeof provider === 'function'\n ? provider.name\n : typeof provider === 'object' && provider !== null\n ? 'an object'\n : String(provider)\n throw new Error(\n `[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use ` +\n `provide(token, ...); an @Injectable class needs no entry.`,\n )\n }\n}\n\nexport function getModuleMetadata(target: ClassType): ModuleMetadata {\n const metadata = Object.hasOwn(target, ModuleMetadataKey)\n ? ((target as any)[ModuleMetadataKey] as ModuleMetadata)\n : undefined\n if (!metadata) {\n throw new Error(\n `[Navios] ${target.name} is not a module. Make sure it is decorated with @Module.`,\n )\n }\n return metadata\n}\n\nexport function hasModuleMetadata(target: ClassType): boolean {\n return Object.hasOwn(target, ModuleMetadataKey)\n}\n"],"mappings":";;AA6BA,MAAM,oBAAoB,OAAO,IAAI,oBAAoB;AAEzD,MAAM,6BAAa,IAAI,IAAI;CAAC;CAAW;CAAU;CAAgB;CAAa;AAAY,CAAC;AAE3F,SAAgB,qBACd,QACA,SACA,SACgB;CAChB,IAAI,kBAAkB,MAAM,GAC1B,MAAM,IAAI,MACR,YAAY,OAAO,KAAK,4DAC1B;CAEF,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F,MAAM,SACJ,OAAO,aAAa,aAChB,SAAS,OACT,OAAO,aAAa,YAAY,aAAa,OAC3C,cACA,OAAO,QAAQ;EACvB,MAAM,IAAI,MACR,YAAY,MAAM,SAAS,OAAO,sGAEpC;CACF;AACF;AAEA,SAAgB,kBAAkB,QAAmC;CACnE,MAAM,WAAW,OAAO,OAAO,QAAQ,iBAAiB,IAClD,OAAe,qBACjB,KAAA;CACJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,YAAY,OAAO,KAAK,0DAC1B;CAEF,OAAO;AACT;AAEA,SAAgB,kBAAkB,QAA4B;CAC5D,OAAO,OAAO,OAAO,QAAQ,iBAAiB;AAChD"}
@@ -0,0 +1,51 @@
1
+ import { ClassType, Provider } from "@navios/di";
2
+ import { n as ExecutionContext } from "./execution-context-BPD3FeFb.mjs";
3
+ /**
4
+ * Wraps a handler. `Ctx` is the context of the transport the interceptor is
5
+ * written for and `Result` what that transport's handlers produce; the
6
+ * defaults work on every transport.
7
+ */
8
+ interface Interceptor<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {
9
+ intercept(ctx: Ctx, next: () => Promise<Result>): Result | Promise<Result>;
10
+ }
11
+ /** A class that interceptors are made of. */
12
+ type InterceptorClass = new (...args: any[]) => Interceptor<any, any>;
13
+ /** An attribute value as returned by calling an attribute. */
14
+ type AttributeValue = {
15
+ readonly token: symbol;
16
+ readonly value: unknown;
17
+ };
18
+ /**
19
+ * Decides whether a handler may run. `Ctx` is the context of the transport
20
+ * the guard is written for; the default works on every transport.
21
+ */
22
+ interface Guard<Ctx extends ExecutionContext = ExecutionContext> {
23
+ canActivate(ctx: Ctx): boolean | Promise<boolean>;
24
+ }
25
+ /** A class that guards are made of. */
26
+ type GuardClass = new (...args: any[]) => Guard<any>;
27
+ /**
28
+ * What `@Module` accepts in every application. A transport adds its own
29
+ * options on top; `@Module` keeps an option it does not know as written, for
30
+ * the transport that reads it, and an option that no transport of the running
31
+ * application reads is ignored. One module can therefore serve several
32
+ * transports.
33
+ */
34
+ interface ModuleOptions {
35
+ imports?: ClassType[];
36
+ /** Providers for the whole application (modules do not encapsulate them). */
37
+ providers?: Provider[];
38
+ /** Guards for every handler of this module and of the modules it imports. */
39
+ guards?: GuardClass[];
40
+ /** Interceptors around the same handlers, the first one outermost. */
41
+ interceptors?: InterceptorClass[];
42
+ /**
43
+ * Attribute values for every handler of this module and of the modules it
44
+ * imports: `[Public()]`. A handler whose module is imported by several others
45
+ * has to get one value from all of them, unless it, its class or the module
46
+ * sets its own.
47
+ */
48
+ attributes?: AttributeValue[];
49
+ }
50
+ export { Interceptor as a, AttributeValue as i, Guard as n, InterceptorClass as o, GuardClass as r, ModuleOptions as t };
51
+ //# sourceMappingURL=module-options-Dmse0gii.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-options-Dmse0gii.d.mts","names":[],"sources":["../src/interceptors/interceptor.mts","../src/attributes/attribute-value.mts","../src/guards/guard.mts","../src/modules/module-options.mts"],"mappings":";;;;;;;UAOiB,YAAY,YAAY,mBAAmB,kBAAkB;EAC5E,UAAU,KAAK,KAAK,YAAY,QAAQ,UAAU,SAAS,QAAQ;;;KAMzD,2BAA2B,gBAAgB;;KCb3C;WAA4B;WAAwB;;;;;;UCK/C,MAAM,YAAY,mBAAmB;EACpD,YAAY,KAAK,gBAAgB;;;KAMvB,qBAAqB,gBAAgB;;;;;;;;UCAhC;EACf,UAAU;;EAEV,YAAY;;EAEZ,SAAS;;EAET,eAAe;;;;;;;EAOf,aAAa"}
@@ -0,0 +1,51 @@
1
+ import { ClassType, Provider } from "@navios/di";
2
+ import { n as ExecutionContext } from "./execution-context-BTJdHhbf.cjs";
3
+ /**
4
+ * Wraps a handler. `Ctx` is the context of the transport the interceptor is
5
+ * written for and `Result` what that transport's handlers produce; the
6
+ * defaults work on every transport.
7
+ */
8
+ interface Interceptor<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {
9
+ intercept(ctx: Ctx, next: () => Promise<Result>): Result | Promise<Result>;
10
+ }
11
+ /** A class that interceptors are made of. */
12
+ type InterceptorClass = new (...args: any[]) => Interceptor<any, any>;
13
+ /** An attribute value as returned by calling an attribute. */
14
+ type AttributeValue = {
15
+ readonly token: symbol;
16
+ readonly value: unknown;
17
+ };
18
+ /**
19
+ * Decides whether a handler may run. `Ctx` is the context of the transport
20
+ * the guard is written for; the default works on every transport.
21
+ */
22
+ interface Guard<Ctx extends ExecutionContext = ExecutionContext> {
23
+ canActivate(ctx: Ctx): boolean | Promise<boolean>;
24
+ }
25
+ /** A class that guards are made of. */
26
+ type GuardClass = new (...args: any[]) => Guard<any>;
27
+ /**
28
+ * What `@Module` accepts in every application. A transport adds its own
29
+ * options on top; `@Module` keeps an option it does not know as written, for
30
+ * the transport that reads it, and an option that no transport of the running
31
+ * application reads is ignored. One module can therefore serve several
32
+ * transports.
33
+ */
34
+ interface ModuleOptions {
35
+ imports?: ClassType[];
36
+ /** Providers for the whole application (modules do not encapsulate them). */
37
+ providers?: Provider[];
38
+ /** Guards for every handler of this module and of the modules it imports. */
39
+ guards?: GuardClass[];
40
+ /** Interceptors around the same handlers, the first one outermost. */
41
+ interceptors?: InterceptorClass[];
42
+ /**
43
+ * Attribute values for every handler of this module and of the modules it
44
+ * imports: `[Public()]`. A handler whose module is imported by several others
45
+ * has to get one value from all of them, unless it, its class or the module
46
+ * sets its own.
47
+ */
48
+ attributes?: AttributeValue[];
49
+ }
50
+ export { Interceptor as a, AttributeValue as i, Guard as n, InterceptorClass as o, GuardClass as r, ModuleOptions as t };
51
+ //# sourceMappingURL=module-options-IuDO-p8u.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-options-IuDO-p8u.d.cts","names":[],"sources":["../src/interceptors/interceptor.mts","../src/attributes/attribute-value.mts","../src/guards/guard.mts","../src/modules/module-options.mts"],"mappings":";;;;;;;UAOiB,YAAY,YAAY,mBAAmB,kBAAkB;EAC5E,UAAU,KAAK,KAAK,YAAY,QAAQ,UAAU,SAAS,QAAQ;;;KAMzD,2BAA2B,gBAAgB;;KCb3C;WAA4B;WAAwB;;;;;;UCK/C,MAAM,YAAY,mBAAmB;EACpD,YAAY,KAAK,gBAAgB;;;KAMvB,qBAAqB,gBAAgB;;;;;;;;UCAhC;EACf,UAAU;;EAEV,YAAY;;EAEZ,SAAS;;EAET,eAAe;;;;;;;EAOf,aAAa"}