@navios/core 1.1.0 → 2.0.0-alpha.1

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 +85 -13
  2. package/README.md +69 -220
  3. package/lib/async-context-BAdt7bno.d.mts +239 -0
  4. package/lib/async-context-BAdt7bno.d.mts.map +1 -0
  5. package/lib/async-context-RsWmy2Hi.d.cts +239 -0
  6. package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
  7. package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
  8. package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
  9. package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
  10. package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
  11. package/lib/attribute-value-BNiJjxl1.mjs +225 -0
  12. package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
  13. package/lib/attribute-value-Cux5HhOL.cjs +314 -0
  14. package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
  15. package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
  16. package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
  17. package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
  18. package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
  19. package/lib/execution-context-BVSmLkYp.d.cts +71 -0
  20. package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
  21. package/lib/execution-context-C5F9rojO.d.mts +71 -0
  22. package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
  23. package/lib/execution-context-token--cKS4cJv.cjs +270 -0
  24. package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
  25. package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
  26. package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
  27. package/lib/index.cjs +1672 -4426
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +842 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +842 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1559 -4221
  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-Bz83ZnJ5.cjs +173 -0
  44. package/lib/module-Bz83ZnJ5.cjs.map +1 -0
  45. package/lib/module-options-CSqQUSTm.d.mts +51 -0
  46. package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
  47. package/lib/module-options-DSRBri4J.d.cts +51 -0
  48. package/lib/module-options-DSRBri4J.d.cts.map +1 -0
  49. package/lib/module-zPXwR2qp.mjs +138 -0
  50. package/lib/module-zPXwR2qp.mjs.map +1 -0
  51. package/lib/settled-within-B6gpu2XW.cjs +32 -0
  52. package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
  53. package/lib/settled-within-Bc2pj8WB.mjs +21 -0
  54. package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
  55. package/lib/testing/index.cjs +74 -414
  56. package/lib/testing/index.cjs.map +1 -1
  57. package/lib/testing/index.d.cts +25 -385
  58. package/lib/testing/index.d.cts.map +1 -1
  59. package/lib/testing/index.d.mts +24 -385
  60. package/lib/testing/index.d.mts.map +1 -1
  61. package/lib/testing/index.mjs +72 -408
  62. package/lib/testing/index.mjs.map +1 -1
  63. package/lib/transport.cjs +36 -0
  64. package/lib/transport.d.cts +254 -0
  65. package/lib/transport.d.cts.map +1 -0
  66. package/lib/transport.d.mts +254 -0
  67. package/lib/transport.d.mts.map +1 -0
  68. package/lib/transport.mjs +6 -0
  69. package/package.json +37 -17
  70. package/docs/README.md +0 -316
  71. package/docs/adapters.md +0 -308
  72. package/docs/application-setup.md +0 -524
  73. package/docs/attributes.md +0 -689
  74. package/docs/controllers.md +0 -373
  75. package/docs/endpoints.md +0 -444
  76. package/docs/exceptions.md +0 -352
  77. package/docs/guards.md +0 -550
  78. package/docs/legacy-compat.md +0 -356
  79. package/docs/modules.md +0 -377
  80. package/docs/quick-start.md +0 -290
  81. package/docs/services.md +0 -427
  82. package/docs/testing.md +0 -827
  83. package/lib/index-3LcTrbxz.d.mts +0 -3804
  84. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  85. package/lib/index-B14SekVb.d.cts +0 -3804
  86. package/lib/index-B14SekVb.d.cts.map +0 -1
  87. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  88. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  89. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  90. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  91. package/lib/tokens-BEuBMGGX.cjs +0 -193
  92. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  93. package/lib/tokens-COyNGV1I.mjs +0 -97
  94. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  95. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  96. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  97. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  98. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  99. package/project.json +0 -66
  100. package/src/__tests__/attribute.factory.spec.mts +0 -300
  101. package/src/__tests__/config.service.spec.mts +0 -43
  102. package/src/__tests__/console-logger.service.spec.mts +0 -312
  103. package/src/__tests__/controller-resolver.spec.mts +0 -229
  104. package/src/__tests__/controller.spec.mts +0 -58
  105. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  106. package/src/__tests__/logger.service.spec.mts +0 -147
  107. package/src/__tests__/responders.spec.mts +0 -340
  108. package/src/__tests__/testing-module.spec.mts +0 -459
  109. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  110. package/src/attribute.factory.mts +0 -325
  111. package/src/config/config-service.interface.mts +0 -47
  112. package/src/config/config.provider.mts +0 -69
  113. package/src/config/config.service.mts +0 -176
  114. package/src/config/index.mts +0 -5
  115. package/src/config/types.mts +0 -58
  116. package/src/config/utils/helpers.mts +0 -23
  117. package/src/config/utils/index.mts +0 -1
  118. package/src/decorators/controller.decorator.mts +0 -81
  119. package/src/decorators/endpoint.decorator.mts +0 -181
  120. package/src/decorators/header.decorator.mts +0 -38
  121. package/src/decorators/http-code.decorator.mts +0 -38
  122. package/src/decorators/index.mts +0 -8
  123. package/src/decorators/module.decorator.mts +0 -106
  124. package/src/decorators/multipart.decorator.mts +0 -169
  125. package/src/decorators/stream.decorator.mts +0 -155
  126. package/src/decorators/use-guards.decorator.mts +0 -73
  127. package/src/exceptions/bad-request.exception.mts +0 -28
  128. package/src/exceptions/conflict.exception.mts +0 -31
  129. package/src/exceptions/forbidden.exception.mts +0 -30
  130. package/src/exceptions/http.exception.mts +0 -33
  131. package/src/exceptions/index.mts +0 -7
  132. package/src/exceptions/internal-server-error.exception.mts +0 -33
  133. package/src/exceptions/not-found.exception.mts +0 -33
  134. package/src/exceptions/unauthorized.exception.mts +0 -30
  135. package/src/factories/adapter.factory.mts +0 -20
  136. package/src/factories/endpoint-adapter.factory.mts +0 -21
  137. package/src/factories/http-adapter.factory.mts +0 -20
  138. package/src/factories/index.mts +0 -8
  139. package/src/factories/multipart-adapter.factory.mts +0 -21
  140. package/src/factories/reply.factory.mts +0 -21
  141. package/src/factories/request.factory.mts +0 -21
  142. package/src/factories/stream-adapter.factory.mts +0 -20
  143. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  144. package/src/index.mts +0 -16
  145. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  146. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  147. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  148. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  149. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  150. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  151. package/src/interfaces/adapter-environment.interface.mts +0 -74
  152. package/src/interfaces/can-activate.mts +0 -38
  153. package/src/interfaces/http-header.mts +0 -18
  154. package/src/interfaces/index.mts +0 -14
  155. package/src/interfaces/navios-module.mts +0 -28
  156. package/src/interfaces/plugin-context.mts +0 -104
  157. package/src/interfaces/plugin-stage.mts +0 -62
  158. package/src/interfaces/plugin.interface.mts +0 -119
  159. package/src/interfaces/staged-plugin.interface.mts +0 -209
  160. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  161. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  162. package/src/legacy-compat/attribute.factory.mts +0 -351
  163. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  164. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  165. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  166. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  167. package/src/legacy-compat/decorators/index.mts +0 -11
  168. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  169. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  170. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  171. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  172. package/src/legacy-compat/index.mts +0 -57
  173. package/src/logger/README.md +0 -3
  174. package/src/logger/console-logger.service.mts +0 -714
  175. package/src/logger/index.mts +0 -6
  176. package/src/logger/log-levels.mts +0 -21
  177. package/src/logger/logger-service.interface.mts +0 -42
  178. package/src/logger/logger.service.mts +0 -113
  179. package/src/logger/logger.tokens.mts +0 -44
  180. package/src/logger/utils/cli-colors.util.mts +0 -17
  181. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  182. package/src/logger/utils/index.mts +0 -5
  183. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  184. package/src/logger/utils/is-log-level.util.mts +0 -10
  185. package/src/logger/utils/shared.utils.mts +0 -51
  186. package/src/metadata/controller.metadata.mts +0 -79
  187. package/src/metadata/handler.metadata.mts +0 -80
  188. package/src/metadata/index.mts +0 -4
  189. package/src/metadata/module.metadata.mts +0 -116
  190. package/src/metadata/navios-managed.metadata.mts +0 -42
  191. package/src/navios.application.mts +0 -678
  192. package/src/navios.environment.mts +0 -42
  193. package/src/navios.factory.mts +0 -158
  194. package/src/responders/enums/framework-error.enum.mts +0 -38
  195. package/src/responders/enums/index.mts +0 -1
  196. package/src/responders/index.mts +0 -4
  197. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  198. package/src/responders/interfaces/error-response.interface.mts +0 -22
  199. package/src/responders/interfaces/index.mts +0 -3
  200. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  201. package/src/responders/services/error-response-producer.service.mts +0 -143
  202. package/src/responders/services/forbidden-responder.service.mts +0 -77
  203. package/src/responders/services/index.mts +0 -5
  204. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  205. package/src/responders/services/not-found-responder.service.mts +0 -76
  206. package/src/responders/services/validation-error-responder.service.mts +0 -78
  207. package/src/responders/tokens/index.mts +0 -1
  208. package/src/responders/tokens/responder.tokens.mts +0 -84
  209. package/src/services/abstract-handler-adapter.service.mts +0 -366
  210. package/src/services/guard-runner.service.mts +0 -152
  211. package/src/services/index.mts +0 -4
  212. package/src/services/instance-resolver.service.mts +0 -177
  213. package/src/services/module-loader.service.mts +0 -255
  214. package/src/stores/index.mts +0 -1
  215. package/src/stores/request-id.store.mts +0 -85
  216. package/src/testing/index.mts +0 -3
  217. package/src/testing/testing-module.mts +0 -393
  218. package/src/testing/unit-testing-module.mts +0 -298
  219. package/src/tokens/adapter.token.mts +0 -6
  220. package/src/tokens/endpoint-adapter.token.mts +0 -8
  221. package/src/tokens/execution-context.token.mts +0 -9
  222. package/src/tokens/http-adapter.token.mts +0 -8
  223. package/src/tokens/index.mts +0 -10
  224. package/src/tokens/multipart-adapter.token.mts +0 -8
  225. package/src/tokens/navios-options.token.mts +0 -6
  226. package/src/tokens/reply.token.mts +0 -3
  227. package/src/tokens/request.token.mts +0 -3
  228. package/src/tokens/stream-adapter.token.mts +0 -8
  229. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  230. package/src/utils/adapter-supports.util.mts +0 -47
  231. package/src/utils/define-plugin.mts +0 -251
  232. package/src/utils/index.mts +0 -2
  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,225 @@
1
+ // src/internal/single-copy.mts
2
+ /**
3
+ * Warns when a second copy of this package is loaded into the process.
4
+ *
5
+ * Several things only work with one copy: `@Module` options that other
6
+ * packages add by declaration merging, the async store behind
7
+ * `currentContext()`, and `instanceof` checks on context keys. Two copies
8
+ * usually mean two versions were installed, or one package bundled its own.
9
+ */
10
+ const registryKey = Symbol.for("navios.core.copies");
11
+ function registerCopy(url, warn) {
12
+ if (typeof url !== "string") return;
13
+ const location = url.replace(/[?#].*$/, "");
14
+ const holder = globalThis;
15
+ const registry = holder[registryKey] ??= {
16
+ locations: /* @__PURE__ */ new Set(),
17
+ warned: false
18
+ };
19
+ if (registry.locations.has(location)) return;
20
+ registry.locations.add(location);
21
+ if (registry.locations.size > 1 && !registry.warned) {
22
+ registry.warned = true;
23
+ warn(`[Navios] @navios/core is loaded more than once:\n` + [...registry.locations].map((entry) => ` - ${entry}`).join("\n") + "\nModule options, currentContext() and context keys are not shared between copies. Make sure every package resolves the same @navios/core: one version, not bundled into another package, and not loaded with both import and require.");
24
+ }
25
+ }
26
+ // src/internal/this-copy.mts
27
+ /**
28
+ * Registers this copy of the package. Every entry point imports this module,
29
+ * so a copy is noticed whichever entry is loaded, and counted once: the
30
+ * entries of one build share this module.
31
+ */
32
+ registerCopy(import.meta.url, (message) => console.warn(message));
33
+ // src/metadata/decorator-metadata.mts
34
+ /**
35
+ * The value stored in decorator metadata under `key`, created for this class
36
+ * from what a parent class has, if anything. The metadata object of a class
37
+ * inherits from that of its parent, so writing to an inherited value would
38
+ * change the parent.
39
+ */
40
+ function ownMetadata(metadata, key, create) {
41
+ if (!Object.hasOwn(metadata, key)) metadata[key] = create(metadata[key]);
42
+ return metadata[key];
43
+ }
44
+ /** The metadata of a decorator context, which has to have one. */
45
+ function requireMetadata(context) {
46
+ if (!context.metadata) throw new Error("[Navios] Decorator metadata is not available. Use standard decorators, or the @navios/core/legacy-compat entry point with experimentalDecorators.");
47
+ return context.metadata;
48
+ }
49
+ // src/metadata/class-metadata.mts
50
+ const ClassAttributesKey = Symbol.for("navios.core.classAttributes");
51
+ const ClassGuardsKey = Symbol.for("navios.core.classGuards");
52
+ const ClassInterceptorsKey = Symbol.for("navios.core.classInterceptors");
53
+ /** The attributes of a class, inherited ones included, to read and to add to. */
54
+ function classAttributes(context) {
55
+ return ownMetadata(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited));
56
+ }
57
+ /** The guards of a class, as `classAttributes`. */
58
+ function classGuards(context) {
59
+ return ownMetadata(requireMetadata(context), ClassGuardsKey, (inherited) => [...inherited ?? []]);
60
+ }
61
+ /** The interceptors of a class, as `classAttributes`. */
62
+ function classInterceptors(context) {
63
+ return ownMetadata(requireMetadata(context), ClassInterceptorsKey, (inherited) => [...inherited ?? []]);
64
+ }
65
+ /** @internal */
66
+ function unique(list) {
67
+ return Array.from(new Set(list));
68
+ }
69
+ /**
70
+ * Adds to `list`, in place, what it does not include yet, in order.
71
+ * @internal
72
+ */
73
+ function addMissing(list, items) {
74
+ for (const item of items) if (!list.includes(item)) list.push(item);
75
+ return list;
76
+ }
77
+ /**
78
+ * Puts `first` in front of `list`, in place, skipping duplicates.
79
+ */
80
+ function prepend(list, first) {
81
+ if (first) list.unshift(...addMissing([], first).filter((item) => !list.includes(item)));
82
+ return list;
83
+ }
84
+ // src/metadata/class-store.mts
85
+ /**
86
+ * Metadata that a class decorator stores on classes under `key`. `what` and
87
+ * `decorator` name it when a class has none: `Users is not a controller. Make
88
+ * sure it is decorated with @Controller.`
89
+ *
90
+ * ```ts
91
+ * const queueHandlers = classMetadata<HandlerClassMetadata>(
92
+ * Symbol.for('my-transport.handlers'),
93
+ * 'a queue handler',
94
+ * 'QueueHandler',
95
+ * )
96
+ * ```
97
+ */
98
+ function classMetadata(key, what, decorator) {
99
+ const has = (target) => Object.hasOwn(target, key);
100
+ return {
101
+ define(target, value) {
102
+ Object.defineProperty(target, key, {
103
+ value,
104
+ configurable: true,
105
+ enumerable: false
106
+ });
107
+ },
108
+ get(target) {
109
+ if (!has(target)) throw new Error(`[Navios] ${target.name} is not ${what}. Make sure it is decorated with @${decorator}.`);
110
+ return target[key];
111
+ },
112
+ has
113
+ };
114
+ }
115
+ // src/modules/module-metadata.mts
116
+ const ModuleMetadataKey = Symbol.for("navios.core.module");
117
+ const moduleMetadata = classMetadata(ModuleMetadataKey, "a module", "Module");
118
+ const ownOptions = /* @__PURE__ */ new Set([
119
+ "imports",
120
+ "guards",
121
+ "interceptors",
122
+ "providers",
123
+ "attributes"
124
+ ]);
125
+ function defineModuleMetadata(target, context, options) {
126
+ if (moduleMetadata.has(target)) throw new Error(`[Navios] ${target.name} is already a module. One @Module takes all of its options.`);
127
+ const entries = /* @__PURE__ */ new Map();
128
+ for (const [name, value] of Object.entries(options)) if (!ownOptions.has(name) && value !== void 0) entries.set(name, value);
129
+ const imports = unique([...options.imports ?? []]);
130
+ assertImportsDefined(target, imports);
131
+ const providers = [...options.providers ?? []];
132
+ assertProviders(target.name, providers);
133
+ const base = Object.getPrototypeOf(target)[ModuleMetadataKey];
134
+ const module = {
135
+ imports,
136
+ guards: prepend(prepend(classGuards(context), base?.guards), options.guards),
137
+ interceptors: prepend(prepend(classInterceptors(context), base?.interceptors), options.interceptors),
138
+ providers,
139
+ attributes: classAttributes(context),
140
+ entries
141
+ };
142
+ for (const [key, value] of base?.attributes ?? []) if (!module.attributes.has(key)) module.attributes.set(key, value);
143
+ moduleMetadata.define(target, module);
144
+ return module;
145
+ }
146
+ /**
147
+ * An import that is `undefined` is what an import cycle between files leaves
148
+ * behind: the importing file ran before the imported one defined its class.
149
+ */
150
+ function assertImportsDefined(target, imports) {
151
+ const index = imports.findIndex((imported) => imported === void 0 || imported === null);
152
+ 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.`);
153
+ }
154
+ /**
155
+ * Where there are no types, a class is easily listed for itself.
156
+ * @internal
157
+ */
158
+ function assertProviders(owner, providers) {
159
+ for (const provider of providers) {
160
+ if (typeof provider === "object" && provider !== null && "token" in provider) continue;
161
+ const listed = typeof provider === "function" ? provider.name : typeof provider === "object" && provider !== null ? "an object" : String(provider);
162
+ throw new Error(`[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use provide(token, ...); an @Injectable class needs no entry.`);
163
+ }
164
+ }
165
+ function getModuleMetadata(target) {
166
+ return moduleMetadata.get(target);
167
+ }
168
+ // src/metadata/member-metadata.mts
169
+ /** Where the members of a class are kept in its metadata. */
170
+ const MembersKey = Symbol.for("navios.core.members");
171
+ /**
172
+ * What decorators attached to a member, inherited ones included, to read and to
173
+ * add to.
174
+ */
175
+ function memberMetadata(context, name) {
176
+ const members = ownMetadata(requireMetadata(context), MembersKey, (inherited) => {
177
+ const copy = /* @__PURE__ */ new Map();
178
+ if (inherited) for (const [key, value] of inherited) copy.set(key, {
179
+ ...value,
180
+ guards: [...value.guards],
181
+ interceptors: [...value.interceptors],
182
+ attributes: new Map(value.attributes),
183
+ entries: new Map(value.entries)
184
+ });
185
+ return copy;
186
+ });
187
+ let member = members.get(name);
188
+ if (!member) {
189
+ member = {
190
+ name,
191
+ guards: [],
192
+ interceptors: [],
193
+ attributes: /* @__PURE__ */ new Map(),
194
+ entries: /* @__PURE__ */ new Map()
195
+ };
196
+ members.set(name, member);
197
+ }
198
+ return member;
199
+ }
200
+ /**
201
+ * A decorator for classes, methods and fields that adds to what decorators
202
+ * attached to them: `toClass` is given the context of a class, `toMember` the
203
+ * metadata of a member. `name` names the decorator in its errors.
204
+ * @internal
205
+ */
206
+ function classOrMemberDecorator(name, toClass, toMember) {
207
+ return (target, context) => {
208
+ if (context.kind === "class") {
209
+ toClass(context);
210
+ return target;
211
+ }
212
+ if (context.kind !== "method" && context.kind !== "field") throw new Error(`[Navios] ${name} can only be used on classes, methods and fields.`);
213
+ if (typeof context.name !== "string") throw new Error(`[Navios] ${name} cannot be used on symbol-named members.`);
214
+ toMember(memberMetadata(context, context.name));
215
+ return context.kind === "field" ? void 0 : target;
216
+ };
217
+ }
218
+ // src/attributes/attribute-value.mts
219
+ /** Sets the values of attributes on a map of them. */
220
+ function applyAttributes(target, attributes) {
221
+ for (const attribute of attributes ?? []) target.set(attribute.token, attribute.value);
222
+ }
223
+ export { assertProviders as a, classMetadata as c, classGuards as d, classInterceptors as f, requireMetadata as h, memberMetadata as i, addMissing as l, ownMetadata as m, MembersKey as n, defineModuleMetadata as o, prepend as p, classOrMemberDecorator as r, getModuleMetadata as s, applyAttributes as t, classAttributes as u };
224
+
225
+ //# sourceMappingURL=attribute-value-BNiJjxl1.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-value-BNiJjxl1.mjs","names":[],"sources":["../src/internal/single-copy.mts","../src/internal/this-copy.mts","../src/metadata/decorator-metadata.mts","../src/metadata/class-metadata.mts","../src/metadata/class-store.mts","../src/modules/module-metadata.mts","../src/metadata/member-metadata.mts","../src/attributes/attribute-value.mts"],"sourcesContent":["/**\n * Warns when a second copy of this package is loaded into the process.\n *\n * Several things only work with one copy: `@Module` options that other\n * packages add by declaration merging, the async store behind\n * `currentContext()`, and `instanceof` checks on context keys. Two copies\n * usually mean two versions were installed, or one package bundled its own.\n */\nconst registryKey = Symbol.for('navios.core.copies')\n\ninterface Registry {\n locations: Set<string>\n warned: boolean\n}\n\nexport function registerCopy(url: string | undefined, warn: (message: string) => void): void {\n if (typeof url !== 'string') {\n // `import.meta` is empty in a bundle that is not a module.\n return\n }\n // A development server adds a query when it loads a file again.\n const location = url.replace(/[?#].*$/, '')\n const holder = globalThis as { [registryKey]?: Registry }\n const registry = (holder[registryKey] ??= { locations: new Set(), warned: false })\n if (registry.locations.has(location)) {\n // The same file evaluated again: a module reload, not a second copy.\n return\n }\n registry.locations.add(location)\n if (registry.locations.size > 1 && !registry.warned) {\n registry.warned = true\n warn(\n `[Navios] @navios/core is loaded more than once:\\n` +\n [...registry.locations].map((entry) => ` - ${entry}`).join('\\n') +\n `\\nModule options, currentContext() and context keys are not shared between copies. ` +\n `Make sure every package resolves the same @navios/core: one version, not bundled into ` +\n `another package, and not loaded with both import and require.`,\n )\n }\n}\n","/**\n * Registers this copy of the package. Every entry point imports this module,\n * so a copy is noticed whichever entry is loaded, and counted once: the\n * entries of one build share this module.\n */\nimport { registerCopy } from './single-copy.mjs'\n\nregisterCopy(import.meta.url, (message) => console.warn(message))\n","/** The `metadata` of a decorator context. */\nexport type DecoratorMetadata = Record<PropertyKey, unknown>\n\n/**\n * The value stored in decorator metadata under `key`, created for this class\n * from what a parent class has, if anything. The metadata object of a class\n * inherits from that of its parent, so writing to an inherited value would\n * change the parent.\n */\nexport function ownMetadata<T>(\n metadata: DecoratorMetadata,\n key: symbol,\n create: (inherited?: T) => T,\n): T {\n if (!Object.hasOwn(metadata, key)) {\n metadata[key] = create(metadata[key] as T | undefined)\n }\n return metadata[key] as T\n}\n\n/** The metadata of a decorator context, which has to have one. */\nexport function requireMetadata(context: { metadata?: DecoratorMetadata }): DecoratorMetadata {\n if (!context.metadata) {\n throw new Error(\n '[Navios] Decorator metadata is not available. Use standard decorators, or the ' +\n '@navios/core/legacy-compat entry point with experimentalDecorators.',\n )\n }\n return context.metadata\n}\n","import type { ClassType } from '@navios/di'\n\nimport { ownMetadata, requireMetadata } from './decorator-metadata.mjs'\n\nimport type { DecoratorMetadata } from './decorator-metadata.mjs'\n\nconst ClassAttributesKey = Symbol.for('navios.core.classAttributes')\nconst ClassGuardsKey = Symbol.for('navios.core.classGuards')\nconst ClassInterceptorsKey = Symbol.for('navios.core.classInterceptors')\n\n/** The attributes of a class, inherited ones included, to read and to add to. */\nexport function classAttributes(context: { metadata?: DecoratorMetadata }): Map<symbol, unknown> {\n return ownMetadata(\n requireMetadata(context),\n ClassAttributesKey,\n (inherited) => new Map(inherited),\n )\n}\n\n/** The guards of a class, as `classAttributes`. */\nexport function classGuards(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return ownMetadata<ClassType[]>(requireMetadata(context), ClassGuardsKey, (inherited) => [\n ...(inherited ?? []),\n ])\n}\n\n/** The interceptors of a class, as `classAttributes`. */\nexport function classInterceptors(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return ownMetadata<ClassType[]>(requireMetadata(context), ClassInterceptorsKey, (inherited) => [\n ...(inherited ?? []),\n ])\n}\n\n/** @internal */\nexport function unique(list: ClassType[]): ClassType[] {\n return Array.from(new Set(list))\n}\n\n/**\n * Adds to `list`, in place, what it does not include yet, in order.\n * @internal\n */\nexport function addMissing<T>(list: T[], items: Iterable<T>): T[] {\n for (const item of items) {\n if (!list.includes(item)) {\n list.push(item)\n }\n }\n return list\n}\n\n/**\n * Puts `first` in front of `list`, in place, skipping duplicates.\n */\nexport function prepend(list: ClassType[], first: Iterable<ClassType> | undefined): ClassType[] {\n if (first) {\n list.unshift(...addMissing([], first).filter((item) => !list.includes(item)))\n }\n return list\n}\n","import type { ClassType } from '@navios/di'\n\n/** What a class decorator stores on the class it decorates. */\nexport interface ClassMetadata<T> {\n /** Stores `value` on `target`, where it is not enumerable and can be replaced. */\n define(target: ClassType, value: T): void\n /**\n * What is stored on `target` itself. A subclass does not inherit it: it is\n * not what the decorator makes of a class unless it is decorated itself.\n * Throws when there is none.\n */\n get(target: ClassType): T\n /** Whether `get` would find something. */\n has(target: ClassType): boolean\n}\n\n/**\n * Metadata that a class decorator stores on classes under `key`. `what` and\n * `decorator` name it when a class has none: `Users is not a controller. Make\n * sure it is decorated with @Controller.`\n *\n * ```ts\n * const queueHandlers = classMetadata<HandlerClassMetadata>(\n * Symbol.for('my-transport.handlers'),\n * 'a queue handler',\n * 'QueueHandler',\n * )\n * ```\n */\nexport function classMetadata<T>(key: symbol, what: string, decorator: string): ClassMetadata<T> {\n const has = (target: ClassType): boolean => Object.hasOwn(target, key)\n return {\n define(target, value) {\n Object.defineProperty(target, key, { value, configurable: true, enumerable: false })\n },\n get(target) {\n if (!has(target)) {\n throw new Error(\n `[Navios] ${target.name} is not ${what}. Make sure it is decorated with @${decorator}.`,\n )\n }\n return (target as unknown as Record<symbol, T>)[key]\n },\n has,\n }\n}\n","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'\nimport { classMetadata } from '../metadata/class-store.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\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 moduleMetadata = classMetadata<ModuleMetadata>(ModuleMetadataKey, 'a module', '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 (moduleMetadata.has(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 moduleMetadata.define(target, module)\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 */\nfunction 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 return moduleMetadata.get(target)\n}\n","import type { ClassType } from '@navios/di'\n\nimport { ownMetadata, requireMetadata } from './decorator-metadata.mjs'\n\nimport type { DecoratorMetadata } from './decorator-metadata.mjs'\n\n/**\n * What decorators and `handler()` options can attach to a handler.\n */\nexport interface HandlerExtras {\n guards: ClassType[]\n interceptors: ClassType[]\n attributes: Map<symbol, unknown>\n}\n\n/**\n * A class member that is, or may become, a handler: what decorators attached\n * to it.\n */\nexport interface MethodHandlerMetadata extends HandlerExtras {\n name: string\n /**\n * What makes the member a handler of a transport, under that transport's\n * own symbol.\n */\n entries: Map<symbol, unknown>\n}\n\n/** Where the members of a class are kept in its metadata. */\nexport const MembersKey = Symbol.for('navios.core.members')\n\n/**\n * What decorators attached to a member, inherited ones included, to read and to\n * add to.\n */\nexport function memberMetadata(\n context: { metadata?: DecoratorMetadata },\n name: string,\n): MethodHandlerMetadata {\n const members = ownMetadata<Map<string, MethodHandlerMetadata>>(\n requireMetadata(context),\n MembersKey,\n (inherited) => {\n const copy = new Map<string, MethodHandlerMetadata>()\n if (inherited) {\n for (const [key, value] of inherited) {\n copy.set(key, {\n ...value,\n guards: [...value.guards],\n interceptors: [...value.interceptors],\n attributes: new Map(value.attributes),\n entries: new Map(value.entries),\n })\n }\n }\n return copy\n },\n )\n let member = members.get(name)\n if (!member) {\n member = { name, guards: [], interceptors: [], attributes: new Map(), entries: new Map() }\n members.set(name, member)\n }\n return member\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype ClassOrMemberContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * A decorator for classes, methods and fields that adds to what decorators\n * attached to them: `toClass` is given the context of a class, `toMember` the\n * metadata of a member. `name` names the decorator in its errors.\n * @internal\n */\nexport function classOrMemberDecorator(\n name: string,\n toClass: (context: ClassDecoratorContext) => void,\n toMember: (member: MethodHandlerMetadata) => void,\n): (target: any, context: ClassOrMemberContext) => any {\n return (target, context) => {\n if (context.kind === 'class') {\n toClass(context)\n return target\n }\n if (context.kind !== 'method' && context.kind !== 'field') {\n throw new Error(`[Navios] ${name} can only be used on classes, methods and fields.`)\n }\n if (typeof context.name !== 'string') {\n throw new Error(`[Navios] ${name} cannot be used on symbol-named members.`)\n }\n toMember(memberMetadata(context, context.name))\n return context.kind === 'field' ? undefined : target\n }\n}\n","/** An attribute value as returned by calling an attribute. */\nexport type AttributeValue = { readonly token: symbol; readonly value: unknown }\n\n/** Sets the values of attributes on a map of them. */\nexport function applyAttributes(\n target: Map<symbol, unknown>,\n attributes: AttributeValue[] | undefined,\n): void {\n for (const attribute of attributes ?? []) {\n target.set(attribute.token, attribute.value)\n }\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,cAAc,OAAO,IAAI,oBAAoB;AAOnD,SAAgB,aAAa,KAAyB,MAAuC;CAC3F,IAAI,OAAO,QAAQ,UAEjB;CAGF,MAAM,WAAW,IAAI,QAAQ,WAAW,EAAE;CAC1C,MAAM,SAAS;CACf,MAAM,WAAY,OAAO,iBAAiB;EAAE,2BAAW,IAAI,IAAI;EAAG,QAAQ;CAAM;CAChF,IAAI,SAAS,UAAU,IAAI,QAAQ,GAEjC;CAEF,SAAS,UAAU,IAAI,QAAQ;CAC/B,IAAI,SAAS,UAAU,OAAO,KAAK,CAAC,SAAS,QAAQ;EACnD,SAAS,SAAS;EAClB,KACE,sDACE,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,KAAK,UAAU,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,IAChE,wOAGJ;CACF;AACF;;;;;;;AChCA,aAAa,YAAY,MAAM,YAAY,QAAQ,KAAK,OAAO,CAAC;;;;;;;;ACEhE,SAAgB,YACd,UACA,KACA,QACG;CACH,IAAI,CAAC,OAAO,OAAO,UAAU,GAAG,GAC9B,SAAS,OAAO,OAAO,SAAS,IAAqB;CAEvD,OAAO,SAAS;AAClB;;AAGA,SAAgB,gBAAgB,SAA8D;CAC5F,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,MACR,mJAEF;CAEF,OAAO,QAAQ;AACjB;;ACvBA,MAAM,qBAAqB,OAAO,IAAI,6BAA6B;AACnE,MAAM,iBAAiB,OAAO,IAAI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AAQ,SAAS,YAAY,QAAQ,SAAS,SAChD,MAAM,IAAI,MAAM,YAAY,KAAK,kDAAkD;EAErF,IAAI,OAAO,QAAQ,SAAS,UAC1B,MAAM,IAAI,MAAM,YAAY,KAAK,yCAAyC;EAE5E,SAAS,eAAe,SAAS,QAAQ,IAAI,CAAC;EAC9C,OAAO,QAAQ,SAAS,UAAU,KAAA,IAAY;CAChD;AACF;;;AC9FA,SAAgB,gBACd,QACA,YACM;CACN,KAAK,MAAM,aAAa,cAAc,CAAC,GACrC,OAAO,IAAI,UAAU,OAAO,UAAU,KAAK;AAE/C"}
@@ -0,0 +1,314 @@
1
+ // src/internal/single-copy.mts
2
+ /**
3
+ * Warns when a second copy of this package is loaded into the process.
4
+ *
5
+ * Several things only work with one copy: `@Module` options that other
6
+ * packages add by declaration merging, the async store behind
7
+ * `currentContext()`, and `instanceof` checks on context keys. Two copies
8
+ * usually mean two versions were installed, or one package bundled its own.
9
+ */
10
+ const registryKey = Symbol.for("navios.core.copies");
11
+ function registerCopy(url, warn) {
12
+ if (typeof url !== "string") return;
13
+ const location = url.replace(/[?#].*$/, "");
14
+ const holder = globalThis;
15
+ const registry = holder[registryKey] ??= {
16
+ locations: /* @__PURE__ */ new Set(),
17
+ warned: false
18
+ };
19
+ if (registry.locations.has(location)) return;
20
+ registry.locations.add(location);
21
+ if (registry.locations.size > 1 && !registry.warned) {
22
+ registry.warned = true;
23
+ warn(`[Navios] @navios/core is loaded more than once:\n` + [...registry.locations].map((entry) => ` - ${entry}`).join("\n") + "\nModule options, currentContext() and context keys are not shared between copies. Make sure every package resolves the same @navios/core: one version, not bundled into another package, and not loaded with both import and require.");
24
+ }
25
+ }
26
+ // src/internal/this-copy.mts
27
+ /**
28
+ * Registers this copy of the package. Every entry point imports this module,
29
+ * so a copy is noticed whichever entry is loaded, and counted once: the
30
+ * entries of one build share this module.
31
+ */
32
+ registerCopy(require("url").pathToFileURL(__filename).href, (message) => console.warn(message));
33
+ // src/metadata/decorator-metadata.mts
34
+ /**
35
+ * The value stored in decorator metadata under `key`, created for this class
36
+ * from what a parent class has, if anything. The metadata object of a class
37
+ * inherits from that of its parent, so writing to an inherited value would
38
+ * change the parent.
39
+ */
40
+ function ownMetadata(metadata, key, create) {
41
+ if (!Object.hasOwn(metadata, key)) metadata[key] = create(metadata[key]);
42
+ return metadata[key];
43
+ }
44
+ /** The metadata of a decorator context, which has to have one. */
45
+ function requireMetadata(context) {
46
+ if (!context.metadata) throw new Error("[Navios] Decorator metadata is not available. Use standard decorators, or the @navios/core/legacy-compat entry point with experimentalDecorators.");
47
+ return context.metadata;
48
+ }
49
+ // src/metadata/class-metadata.mts
50
+ const ClassAttributesKey = Symbol.for("navios.core.classAttributes");
51
+ const ClassGuardsKey = Symbol.for("navios.core.classGuards");
52
+ const ClassInterceptorsKey = Symbol.for("navios.core.classInterceptors");
53
+ /** The attributes of a class, inherited ones included, to read and to add to. */
54
+ function classAttributes(context) {
55
+ return ownMetadata(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited));
56
+ }
57
+ /** The guards of a class, as `classAttributes`. */
58
+ function classGuards(context) {
59
+ return ownMetadata(requireMetadata(context), ClassGuardsKey, (inherited) => [...inherited ?? []]);
60
+ }
61
+ /** The interceptors of a class, as `classAttributes`. */
62
+ function classInterceptors(context) {
63
+ return ownMetadata(requireMetadata(context), ClassInterceptorsKey, (inherited) => [...inherited ?? []]);
64
+ }
65
+ /** @internal */
66
+ function unique(list) {
67
+ return Array.from(new Set(list));
68
+ }
69
+ /**
70
+ * Adds to `list`, in place, what it does not include yet, in order.
71
+ * @internal
72
+ */
73
+ function addMissing(list, items) {
74
+ for (const item of items) if (!list.includes(item)) list.push(item);
75
+ return list;
76
+ }
77
+ /**
78
+ * Puts `first` in front of `list`, in place, skipping duplicates.
79
+ */
80
+ function prepend(list, first) {
81
+ if (first) list.unshift(...addMissing([], first).filter((item) => !list.includes(item)));
82
+ return list;
83
+ }
84
+ // src/metadata/class-store.mts
85
+ /**
86
+ * Metadata that a class decorator stores on classes under `key`. `what` and
87
+ * `decorator` name it when a class has none: `Users is not a controller. Make
88
+ * sure it is decorated with @Controller.`
89
+ *
90
+ * ```ts
91
+ * const queueHandlers = classMetadata<HandlerClassMetadata>(
92
+ * Symbol.for('my-transport.handlers'),
93
+ * 'a queue handler',
94
+ * 'QueueHandler',
95
+ * )
96
+ * ```
97
+ */
98
+ function classMetadata(key, what, decorator) {
99
+ const has = (target) => Object.hasOwn(target, key);
100
+ return {
101
+ define(target, value) {
102
+ Object.defineProperty(target, key, {
103
+ value,
104
+ configurable: true,
105
+ enumerable: false
106
+ });
107
+ },
108
+ get(target) {
109
+ if (!has(target)) throw new Error(`[Navios] ${target.name} is not ${what}. Make sure it is decorated with @${decorator}.`);
110
+ return target[key];
111
+ },
112
+ has
113
+ };
114
+ }
115
+ // src/modules/module-metadata.mts
116
+ const ModuleMetadataKey = Symbol.for("navios.core.module");
117
+ const moduleMetadata = classMetadata(ModuleMetadataKey, "a module", "Module");
118
+ const ownOptions = /* @__PURE__ */ new Set([
119
+ "imports",
120
+ "guards",
121
+ "interceptors",
122
+ "providers",
123
+ "attributes"
124
+ ]);
125
+ function defineModuleMetadata(target, context, options) {
126
+ if (moduleMetadata.has(target)) throw new Error(`[Navios] ${target.name} is already a module. One @Module takes all of its options.`);
127
+ const entries = /* @__PURE__ */ new Map();
128
+ for (const [name, value] of Object.entries(options)) if (!ownOptions.has(name) && value !== void 0) entries.set(name, value);
129
+ const imports = unique([...options.imports ?? []]);
130
+ assertImportsDefined(target, imports);
131
+ const providers = [...options.providers ?? []];
132
+ assertProviders(target.name, providers);
133
+ const base = Object.getPrototypeOf(target)[ModuleMetadataKey];
134
+ const module = {
135
+ imports,
136
+ guards: prepend(prepend(classGuards(context), base?.guards), options.guards),
137
+ interceptors: prepend(prepend(classInterceptors(context), base?.interceptors), options.interceptors),
138
+ providers,
139
+ attributes: classAttributes(context),
140
+ entries
141
+ };
142
+ for (const [key, value] of base?.attributes ?? []) if (!module.attributes.has(key)) module.attributes.set(key, value);
143
+ moduleMetadata.define(target, module);
144
+ return module;
145
+ }
146
+ /**
147
+ * An import that is `undefined` is what an import cycle between files leaves
148
+ * behind: the importing file ran before the imported one defined its class.
149
+ */
150
+ function assertImportsDefined(target, imports) {
151
+ const index = imports.findIndex((imported) => imported === void 0 || imported === null);
152
+ 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.`);
153
+ }
154
+ /**
155
+ * Where there are no types, a class is easily listed for itself.
156
+ * @internal
157
+ */
158
+ function assertProviders(owner, providers) {
159
+ for (const provider of providers) {
160
+ if (typeof provider === "object" && provider !== null && "token" in provider) continue;
161
+ const listed = typeof provider === "function" ? provider.name : typeof provider === "object" && provider !== null ? "an object" : String(provider);
162
+ throw new Error(`[Navios] ${owner} lists ${listed} in providers, which is not a provider. Use provide(token, ...); an @Injectable class needs no entry.`);
163
+ }
164
+ }
165
+ function getModuleMetadata(target) {
166
+ return moduleMetadata.get(target);
167
+ }
168
+ // src/metadata/member-metadata.mts
169
+ /** Where the members of a class are kept in its metadata. */
170
+ const MembersKey = Symbol.for("navios.core.members");
171
+ /**
172
+ * What decorators attached to a member, inherited ones included, to read and to
173
+ * add to.
174
+ */
175
+ function memberMetadata(context, name) {
176
+ const members = ownMetadata(requireMetadata(context), MembersKey, (inherited) => {
177
+ const copy = /* @__PURE__ */ new Map();
178
+ if (inherited) for (const [key, value] of inherited) copy.set(key, {
179
+ ...value,
180
+ guards: [...value.guards],
181
+ interceptors: [...value.interceptors],
182
+ attributes: new Map(value.attributes),
183
+ entries: new Map(value.entries)
184
+ });
185
+ return copy;
186
+ });
187
+ let member = members.get(name);
188
+ if (!member) {
189
+ member = {
190
+ name,
191
+ guards: [],
192
+ interceptors: [],
193
+ attributes: /* @__PURE__ */ new Map(),
194
+ entries: /* @__PURE__ */ new Map()
195
+ };
196
+ members.set(name, member);
197
+ }
198
+ return member;
199
+ }
200
+ /**
201
+ * A decorator for classes, methods and fields that adds to what decorators
202
+ * attached to them: `toClass` is given the context of a class, `toMember` the
203
+ * metadata of a member. `name` names the decorator in its errors.
204
+ * @internal
205
+ */
206
+ function classOrMemberDecorator(name, toClass, toMember) {
207
+ return (target, context) => {
208
+ if (context.kind === "class") {
209
+ toClass(context);
210
+ return target;
211
+ }
212
+ if (context.kind !== "method" && context.kind !== "field") throw new Error(`[Navios] ${name} can only be used on classes, methods and fields.`);
213
+ if (typeof context.name !== "string") throw new Error(`[Navios] ${name} cannot be used on symbol-named members.`);
214
+ toMember(memberMetadata(context, context.name));
215
+ return context.kind === "field" ? void 0 : target;
216
+ };
217
+ }
218
+ // src/attributes/attribute-value.mts
219
+ /** Sets the values of attributes on a map of them. */
220
+ function applyAttributes(target, attributes) {
221
+ for (const attribute of attributes ?? []) target.set(attribute.token, attribute.value);
222
+ }
223
+ Object.defineProperty(exports, "MembersKey", {
224
+ enumerable: true,
225
+ get: function() {
226
+ return MembersKey;
227
+ }
228
+ });
229
+ Object.defineProperty(exports, "addMissing", {
230
+ enumerable: true,
231
+ get: function() {
232
+ return addMissing;
233
+ }
234
+ });
235
+ Object.defineProperty(exports, "applyAttributes", {
236
+ enumerable: true,
237
+ get: function() {
238
+ return applyAttributes;
239
+ }
240
+ });
241
+ Object.defineProperty(exports, "assertProviders", {
242
+ enumerable: true,
243
+ get: function() {
244
+ return assertProviders;
245
+ }
246
+ });
247
+ Object.defineProperty(exports, "classAttributes", {
248
+ enumerable: true,
249
+ get: function() {
250
+ return classAttributes;
251
+ }
252
+ });
253
+ Object.defineProperty(exports, "classGuards", {
254
+ enumerable: true,
255
+ get: function() {
256
+ return classGuards;
257
+ }
258
+ });
259
+ Object.defineProperty(exports, "classInterceptors", {
260
+ enumerable: true,
261
+ get: function() {
262
+ return classInterceptors;
263
+ }
264
+ });
265
+ Object.defineProperty(exports, "classMetadata", {
266
+ enumerable: true,
267
+ get: function() {
268
+ return classMetadata;
269
+ }
270
+ });
271
+ Object.defineProperty(exports, "classOrMemberDecorator", {
272
+ enumerable: true,
273
+ get: function() {
274
+ return classOrMemberDecorator;
275
+ }
276
+ });
277
+ Object.defineProperty(exports, "defineModuleMetadata", {
278
+ enumerable: true,
279
+ get: function() {
280
+ return defineModuleMetadata;
281
+ }
282
+ });
283
+ Object.defineProperty(exports, "getModuleMetadata", {
284
+ enumerable: true,
285
+ get: function() {
286
+ return getModuleMetadata;
287
+ }
288
+ });
289
+ Object.defineProperty(exports, "memberMetadata", {
290
+ enumerable: true,
291
+ get: function() {
292
+ return memberMetadata;
293
+ }
294
+ });
295
+ Object.defineProperty(exports, "ownMetadata", {
296
+ enumerable: true,
297
+ get: function() {
298
+ return ownMetadata;
299
+ }
300
+ });
301
+ Object.defineProperty(exports, "prepend", {
302
+ enumerable: true,
303
+ get: function() {
304
+ return prepend;
305
+ }
306
+ });
307
+ Object.defineProperty(exports, "requireMetadata", {
308
+ enumerable: true,
309
+ get: function() {
310
+ return requireMetadata;
311
+ }
312
+ });
313
+
314
+ //# sourceMappingURL=attribute-value-Cux5HhOL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-value-Cux5HhOL.cjs","names":[],"sources":["../src/internal/single-copy.mts","../src/internal/this-copy.mts","../src/metadata/decorator-metadata.mts","../src/metadata/class-metadata.mts","../src/metadata/class-store.mts","../src/modules/module-metadata.mts","../src/metadata/member-metadata.mts","../src/attributes/attribute-value.mts"],"sourcesContent":["/**\n * Warns when a second copy of this package is loaded into the process.\n *\n * Several things only work with one copy: `@Module` options that other\n * packages add by declaration merging, the async store behind\n * `currentContext()`, and `instanceof` checks on context keys. Two copies\n * usually mean two versions were installed, or one package bundled its own.\n */\nconst registryKey = Symbol.for('navios.core.copies')\n\ninterface Registry {\n locations: Set<string>\n warned: boolean\n}\n\nexport function registerCopy(url: string | undefined, warn: (message: string) => void): void {\n if (typeof url !== 'string') {\n // `import.meta` is empty in a bundle that is not a module.\n return\n }\n // A development server adds a query when it loads a file again.\n const location = url.replace(/[?#].*$/, '')\n const holder = globalThis as { [registryKey]?: Registry }\n const registry = (holder[registryKey] ??= { locations: new Set(), warned: false })\n if (registry.locations.has(location)) {\n // The same file evaluated again: a module reload, not a second copy.\n return\n }\n registry.locations.add(location)\n if (registry.locations.size > 1 && !registry.warned) {\n registry.warned = true\n warn(\n `[Navios] @navios/core is loaded more than once:\\n` +\n [...registry.locations].map((entry) => ` - ${entry}`).join('\\n') +\n `\\nModule options, currentContext() and context keys are not shared between copies. ` +\n `Make sure every package resolves the same @navios/core: one version, not bundled into ` +\n `another package, and not loaded with both import and require.`,\n )\n }\n}\n","/**\n * Registers this copy of the package. Every entry point imports this module,\n * so a copy is noticed whichever entry is loaded, and counted once: the\n * entries of one build share this module.\n */\nimport { registerCopy } from './single-copy.mjs'\n\nregisterCopy(import.meta.url, (message) => console.warn(message))\n","/** The `metadata` of a decorator context. */\nexport type DecoratorMetadata = Record<PropertyKey, unknown>\n\n/**\n * The value stored in decorator metadata under `key`, created for this class\n * from what a parent class has, if anything. The metadata object of a class\n * inherits from that of its parent, so writing to an inherited value would\n * change the parent.\n */\nexport function ownMetadata<T>(\n metadata: DecoratorMetadata,\n key: symbol,\n create: (inherited?: T) => T,\n): T {\n if (!Object.hasOwn(metadata, key)) {\n metadata[key] = create(metadata[key] as T | undefined)\n }\n return metadata[key] as T\n}\n\n/** The metadata of a decorator context, which has to have one. */\nexport function requireMetadata(context: { metadata?: DecoratorMetadata }): DecoratorMetadata {\n if (!context.metadata) {\n throw new Error(\n '[Navios] Decorator metadata is not available. Use standard decorators, or the ' +\n '@navios/core/legacy-compat entry point with experimentalDecorators.',\n )\n }\n return context.metadata\n}\n","import type { ClassType } from '@navios/di'\n\nimport { ownMetadata, requireMetadata } from './decorator-metadata.mjs'\n\nimport type { DecoratorMetadata } from './decorator-metadata.mjs'\n\nconst ClassAttributesKey = Symbol.for('navios.core.classAttributes')\nconst ClassGuardsKey = Symbol.for('navios.core.classGuards')\nconst ClassInterceptorsKey = Symbol.for('navios.core.classInterceptors')\n\n/** The attributes of a class, inherited ones included, to read and to add to. */\nexport function classAttributes(context: { metadata?: DecoratorMetadata }): Map<symbol, unknown> {\n return ownMetadata(\n requireMetadata(context),\n ClassAttributesKey,\n (inherited) => new Map(inherited),\n )\n}\n\n/** The guards of a class, as `classAttributes`. */\nexport function classGuards(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return ownMetadata<ClassType[]>(requireMetadata(context), ClassGuardsKey, (inherited) => [\n ...(inherited ?? []),\n ])\n}\n\n/** The interceptors of a class, as `classAttributes`. */\nexport function classInterceptors(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return ownMetadata<ClassType[]>(requireMetadata(context), ClassInterceptorsKey, (inherited) => [\n ...(inherited ?? []),\n ])\n}\n\n/** @internal */\nexport function unique(list: ClassType[]): ClassType[] {\n return Array.from(new Set(list))\n}\n\n/**\n * Adds to `list`, in place, what it does not include yet, in order.\n * @internal\n */\nexport function addMissing<T>(list: T[], items: Iterable<T>): T[] {\n for (const item of items) {\n if (!list.includes(item)) {\n list.push(item)\n }\n }\n return list\n}\n\n/**\n * Puts `first` in front of `list`, in place, skipping duplicates.\n */\nexport function prepend(list: ClassType[], first: Iterable<ClassType> | undefined): ClassType[] {\n if (first) {\n list.unshift(...addMissing([], first).filter((item) => !list.includes(item)))\n }\n return list\n}\n","import type { ClassType } from '@navios/di'\n\n/** What a class decorator stores on the class it decorates. */\nexport interface ClassMetadata<T> {\n /** Stores `value` on `target`, where it is not enumerable and can be replaced. */\n define(target: ClassType, value: T): void\n /**\n * What is stored on `target` itself. A subclass does not inherit it: it is\n * not what the decorator makes of a class unless it is decorated itself.\n * Throws when there is none.\n */\n get(target: ClassType): T\n /** Whether `get` would find something. */\n has(target: ClassType): boolean\n}\n\n/**\n * Metadata that a class decorator stores on classes under `key`. `what` and\n * `decorator` name it when a class has none: `Users is not a controller. Make\n * sure it is decorated with @Controller.`\n *\n * ```ts\n * const queueHandlers = classMetadata<HandlerClassMetadata>(\n * Symbol.for('my-transport.handlers'),\n * 'a queue handler',\n * 'QueueHandler',\n * )\n * ```\n */\nexport function classMetadata<T>(key: symbol, what: string, decorator: string): ClassMetadata<T> {\n const has = (target: ClassType): boolean => Object.hasOwn(target, key)\n return {\n define(target, value) {\n Object.defineProperty(target, key, { value, configurable: true, enumerable: false })\n },\n get(target) {\n if (!has(target)) {\n throw new Error(\n `[Navios] ${target.name} is not ${what}. Make sure it is decorated with @${decorator}.`,\n )\n }\n return (target as unknown as Record<symbol, T>)[key]\n },\n has,\n }\n}\n","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'\nimport { classMetadata } from '../metadata/class-store.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\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 moduleMetadata = classMetadata<ModuleMetadata>(ModuleMetadataKey, 'a module', '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 (moduleMetadata.has(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 moduleMetadata.define(target, module)\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 */\nfunction 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 return moduleMetadata.get(target)\n}\n","import type { ClassType } from '@navios/di'\n\nimport { ownMetadata, requireMetadata } from './decorator-metadata.mjs'\n\nimport type { DecoratorMetadata } from './decorator-metadata.mjs'\n\n/**\n * What decorators and `handler()` options can attach to a handler.\n */\nexport interface HandlerExtras {\n guards: ClassType[]\n interceptors: ClassType[]\n attributes: Map<symbol, unknown>\n}\n\n/**\n * A class member that is, or may become, a handler: what decorators attached\n * to it.\n */\nexport interface MethodHandlerMetadata extends HandlerExtras {\n name: string\n /**\n * What makes the member a handler of a transport, under that transport's\n * own symbol.\n */\n entries: Map<symbol, unknown>\n}\n\n/** Where the members of a class are kept in its metadata. */\nexport const MembersKey = Symbol.for('navios.core.members')\n\n/**\n * What decorators attached to a member, inherited ones included, to read and to\n * add to.\n */\nexport function memberMetadata(\n context: { metadata?: DecoratorMetadata },\n name: string,\n): MethodHandlerMetadata {\n const members = ownMetadata<Map<string, MethodHandlerMetadata>>(\n requireMetadata(context),\n MembersKey,\n (inherited) => {\n const copy = new Map<string, MethodHandlerMetadata>()\n if (inherited) {\n for (const [key, value] of inherited) {\n copy.set(key, {\n ...value,\n guards: [...value.guards],\n interceptors: [...value.interceptors],\n attributes: new Map(value.attributes),\n entries: new Map(value.entries),\n })\n }\n }\n return copy\n },\n )\n let member = members.get(name)\n if (!member) {\n member = { name, guards: [], interceptors: [], attributes: new Map(), entries: new Map() }\n members.set(name, member)\n }\n return member\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype ClassOrMemberContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * A decorator for classes, methods and fields that adds to what decorators\n * attached to them: `toClass` is given the context of a class, `toMember` the\n * metadata of a member. `name` names the decorator in its errors.\n * @internal\n */\nexport function classOrMemberDecorator(\n name: string,\n toClass: (context: ClassDecoratorContext) => void,\n toMember: (member: MethodHandlerMetadata) => void,\n): (target: any, context: ClassOrMemberContext) => any {\n return (target, context) => {\n if (context.kind === 'class') {\n toClass(context)\n return target\n }\n if (context.kind !== 'method' && context.kind !== 'field') {\n throw new Error(`[Navios] ${name} can only be used on classes, methods and fields.`)\n }\n if (typeof context.name !== 'string') {\n throw new Error(`[Navios] ${name} cannot be used on symbol-named members.`)\n }\n toMember(memberMetadata(context, context.name))\n return context.kind === 'field' ? undefined : target\n }\n}\n","/** An attribute value as returned by calling an attribute. */\nexport type AttributeValue = { readonly token: symbol; readonly value: unknown }\n\n/** Sets the values of attributes on a map of them. */\nexport function applyAttributes(\n target: Map<symbol, unknown>,\n attributes: AttributeValue[] | undefined,\n): void {\n for (const attribute of attributes ?? []) {\n target.set(attribute.token, attribute.value)\n }\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,cAAc,OAAO,IAAI,oBAAoB;AAOnD,SAAgB,aAAa,KAAyB,MAAuC;CAC3F,IAAI,OAAO,QAAQ,UAEjB;CAGF,MAAM,WAAW,IAAI,QAAQ,WAAW,EAAE;CAC1C,MAAM,SAAS;CACf,MAAM,WAAY,OAAO,iBAAiB;EAAE,2BAAW,IAAI,IAAI;EAAG,QAAQ;CAAM;CAChF,IAAI,SAAS,UAAU,IAAI,QAAQ,GAEjC;CAEF,SAAS,UAAU,IAAI,QAAQ;CAC/B,IAAI,SAAS,UAAU,OAAO,KAAK,CAAC,SAAS,QAAQ;EACnD,SAAS,SAAS;EAClB,KACE,sDACE,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,KAAK,UAAU,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,IAChE,wOAGJ;CACF;AACF;;;;;;;AChCA,aAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,OAA+B,YAAY,QAAQ,KAAK,OAAO,CAAC;;;;;;;;ACEhE,SAAgB,YACd,UACA,KACA,QACG;CACH,IAAI,CAAC,OAAO,OAAO,UAAU,GAAG,GAC9B,SAAS,OAAO,OAAO,SAAS,IAAqB;CAEvD,OAAO,SAAS;AAClB;;AAGA,SAAgB,gBAAgB,SAA8D;CAC5F,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,MACR,mJAEF;CAEF,OAAO,QAAQ;AACjB;;ACvBA,MAAM,qBAAqB,OAAO,IAAI,6BAA6B;AACnE,MAAM,iBAAiB,OAAO,IAAI,yBAAyB;AAC3D,MAAM,uBAAuB,OAAO,IAAI,+BAA+B;;AAG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