@navios/core 2.0.0-alpha.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 (85) hide show
  1. package/CHANGELOG.md +33 -3
  2. package/README.md +8 -6
  3. package/lib/{async-context-6pdlnNLA.d.mts → async-context-BAdt7bno.d.mts} +11 -9
  4. package/lib/async-context-BAdt7bno.d.mts.map +1 -0
  5. package/lib/{async-context-Dqk7pE-D.d.cts → async-context-RsWmy2Hi.d.cts} +11 -9
  6. package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
  7. package/lib/{attribute-factory-B3VuYnp7.d.cts → attribute-factory-BW1kgBqf.d.mts} +2 -2
  8. package/lib/{attribute-factory-B3VuYnp7.d.cts.map → attribute-factory-BW1kgBqf.d.mts.map} +1 -1
  9. package/lib/{attribute-factory-mKOXoVnV.d.mts → attribute-factory-DqN4x5XM.d.cts} +2 -2
  10. package/lib/{attribute-factory-mKOXoVnV.d.mts.map → attribute-factory-DqN4x5XM.d.cts.map} +1 -1
  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-DSk5MNtc.cjs → basic-execution-context-5uq2DvEA.cjs} +66 -29
  16. package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
  17. package/lib/{basic-execution-context-CeGuhMOz.mjs → basic-execution-context-u1VktGoM.mjs} +61 -30
  18. package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
  19. package/lib/{execution-context-BPD3FeFb.d.mts → execution-context-BVSmLkYp.d.cts} +2 -2
  20. package/lib/{execution-context-BPD3FeFb.d.mts.map → execution-context-BVSmLkYp.d.cts.map} +1 -1
  21. package/lib/{execution-context-BTJdHhbf.d.cts → execution-context-C5F9rojO.d.mts} +2 -2
  22. package/lib/{execution-context-BTJdHhbf.d.cts.map → execution-context-C5F9rojO.d.mts.map} +1 -1
  23. package/lib/{module-graph-DCP9MHG0.cjs → execution-context-token--cKS4cJv.cjs} +135 -12
  24. package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
  25. package/lib/{module-graph-xvVEykFM.mjs → execution-context-token-Cb3M3Ao0.mjs} +93 -12
  26. package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
  27. package/lib/index.cjs +84 -101
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +14 -10
  30. package/lib/index.d.cts.map +1 -1
  31. package/lib/index.d.mts +14 -10
  32. package/lib/index.d.mts.map +1 -1
  33. package/lib/index.mjs +76 -92
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +2 -2
  36. package/lib/legacy-compat/index.d.cts +3 -3
  37. package/lib/legacy-compat/index.d.mts +2 -2
  38. package/lib/legacy-compat/index.mjs +2 -2
  39. package/lib/{module-DZewk_2r.cjs → module-Bz83ZnJ5.cjs} +43 -34
  40. package/lib/module-Bz83ZnJ5.cjs.map +1 -0
  41. package/lib/{module-options-Dmse0gii.d.mts → module-options-CSqQUSTm.d.mts} +2 -2
  42. package/lib/{module-options-Dmse0gii.d.mts.map → module-options-CSqQUSTm.d.mts.map} +1 -1
  43. package/lib/{module-options-IuDO-p8u.d.cts → module-options-DSRBri4J.d.cts} +2 -2
  44. package/lib/{module-options-IuDO-p8u.d.cts.map → module-options-DSRBri4J.d.cts.map} +1 -1
  45. package/lib/{module-Bha7GER_.mjs → module-zPXwR2qp.mjs} +38 -35
  46. package/lib/module-zPXwR2qp.mjs.map +1 -0
  47. package/lib/settled-within-B6gpu2XW.cjs +32 -0
  48. package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
  49. package/lib/settled-within-Bc2pj8WB.mjs +21 -0
  50. package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
  51. package/lib/testing/index.cjs +12 -34
  52. package/lib/testing/index.cjs.map +1 -1
  53. package/lib/testing/index.d.cts +2 -2
  54. package/lib/testing/index.d.cts.map +1 -1
  55. package/lib/testing/index.d.mts +1 -1
  56. package/lib/testing/index.d.mts.map +1 -1
  57. package/lib/testing/index.mjs +12 -34
  58. package/lib/testing/index.mjs.map +1 -1
  59. package/lib/transport.cjs +19 -8
  60. package/lib/transport.d.cts +102 -38
  61. package/lib/transport.d.cts.map +1 -1
  62. package/lib/transport.d.mts +102 -38
  63. package/lib/transport.d.mts.map +1 -1
  64. package/lib/transport.mjs +6 -7
  65. package/package.json +2 -2
  66. package/lib/async-context-6pdlnNLA.d.mts.map +0 -1
  67. package/lib/async-context-Dqk7pE-D.d.cts.map +0 -1
  68. package/lib/attribute-value-CjX9ZkLq.cjs +0 -172
  69. package/lib/attribute-value-CjX9ZkLq.cjs.map +0 -1
  70. package/lib/attribute-value-DMEA255r.mjs +0 -119
  71. package/lib/attribute-value-DMEA255r.mjs.map +0 -1
  72. package/lib/basic-execution-context-CeGuhMOz.mjs.map +0 -1
  73. package/lib/basic-execution-context-DSk5MNtc.cjs.map +0 -1
  74. package/lib/execution-context-token-BXUKB2hf.cjs +0 -112
  75. package/lib/execution-context-token-BXUKB2hf.cjs.map +0 -1
  76. package/lib/execution-context-token-CrXmTvk2.mjs +0 -77
  77. package/lib/execution-context-token-CrXmTvk2.mjs.map +0 -1
  78. package/lib/module-Bha7GER_.mjs.map +0 -1
  79. package/lib/module-DZewk_2r.cjs.map +0 -1
  80. package/lib/module-graph-DCP9MHG0.cjs.map +0 -1
  81. package/lib/module-graph-xvVEykFM.mjs.map +0 -1
  82. package/lib/module-metadata-C8S92seK.cjs +0 -95
  83. package/lib/module-metadata-C8S92seK.cjs.map +0 -1
  84. package/lib/module-metadata-k3RTt20x.mjs +0 -66
  85. package/lib/module-metadata-k3RTt20x.mjs.map +0 -1
@@ -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,QA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;CACvB,MAAM,UAAU,YACd,gBAAgB,OAAO,GACvB,aACC,cAAc;EACb,MAAM,uBAAO,IAAI,IAAmC;EACpD,IAAI,WACF,KAAK,MAAM,CAAC,KAAK,UAAU,WACzB,KAAK,IAAI,KAAK;GACZ,GAAG;GACH,QAAQ,CAAC,GAAG,MAAM,MAAM;GACxB,cAAc,CAAC,GAAG,MAAM,YAAY;GACpC,YAAY,IAAI,IAAI,MAAM,UAAU;GACpC,SAAS,IAAI,IAAI,MAAM,OAAO;EAChC,CAAC;EAGL,OAAO;CACT,CACF;CACA,IAAI,SAAS,QAAQ,IAAI,IAAI;CAC7B,IAAI,CAAC,QAAQ;EACX,SAAS;GAAE;GAAM,QAAQ,CAAC;GAAG,cAAc,CAAC;GAAG,4BAAY,IAAI,IAAI;GAAG,yBAAS,IAAI,IAAI;EAAE;EACzF,QAAQ,IAAI,MAAM,MAAM;CAC1B;CACA,OAAO;AACT;;;;;;;AAeA,SAAgB,uBACd,MACA,SACA,UACqD;CACrD,QAAQ,QAAQ,YAAY;EAC1B,IAAI,QAAQ,SAAS,SAAS;GAC5B,QAAQ,OAAO;GACf,OAAO;EACT;EACA,IAAI,QAAQ,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"}
@@ -1,5 +1,5 @@
1
- const require_attribute_value = require("./attribute-value-CjX9ZkLq.cjs");
2
- const require_execution_context_token = require("./execution-context-token-BXUKB2hf.cjs");
1
+ const require_attribute_value = require("./attribute-value-Cux5HhOL.cjs");
2
+ const require_execution_context_token = require("./execution-context-token--cKS4cJv.cjs");
3
3
  // src/transports/transport.mts
4
4
  /**
5
5
  * Defines a transport.
@@ -58,9 +58,11 @@ function assertUndisputed({ node, owner, member }) {
58
58
  }
59
59
  /**
60
60
  * The guards and interceptors that apply to one handler, in the order they
61
- * run: the interceptors of the application, then the guards from the module
62
- * chain, the owning class and the handler, then the interceptors of the same
63
- * three. A class that appears twice is kept where it first appears.
61
+ * run, and what its contexts tell about it: the interceptors of the
62
+ * application, then the guards from the module chain, the owning class and
63
+ * the handler, then the interceptors of the same three. A class that appears
64
+ * twice is kept where it first appears. `info.guards` are the guards and
65
+ * `info.interceptors` the interceptors, `outer` and then `inner`.
64
66
  *
65
67
  * An interceptor of the application sees every execution, denied ones
66
68
  * included, as tracing and logging need. One that is attached to handlers runs
@@ -69,28 +71,39 @@ function assertUndisputed({ node, owner, member }) {
69
71
  * Throws when the handler would inherit an attribute that the importers of its
70
72
  * module do not agree about.
71
73
  *
72
- * Every transport uses this, so the rule is the same everywhere. `runChain`
73
- * runs the chain.
74
+ * Every transport uses this, so the rule is the same everywhere.
75
+ * `resolveChain` resolves the chain and `runChain` runs it.
74
76
  */
75
77
  function handlerChain(input) {
76
78
  assertUndisputed(input);
77
- const { application, node, owner, member } = input;
78
- const outer = new Set(application);
79
+ const { application, node, controller, owner, handlerName, member } = input;
80
+ const everywhere = new Set(application);
79
81
  const attached = [
80
82
  ...node.interceptors,
81
83
  ...owner.interceptors,
82
84
  ...member.interceptors
83
85
  ];
84
- const inner = new Set(attached.filter((interceptor) => !outer.has(interceptor)));
86
+ const outer = Array.from(everywhere);
87
+ const inner = Array.from(new Set(attached.filter((interceptor) => !everywhere.has(interceptor))));
85
88
  return {
86
- guards: Array.from(/* @__PURE__ */ new Set([
87
- ...node.guards,
88
- ...owner.guards,
89
- ...member.guards
90
- ])),
91
- interceptors: [...outer, ...inner],
92
- outer: Array.from(outer),
93
- inner: Array.from(inner)
89
+ info: {
90
+ module: node.module,
91
+ controller,
92
+ handlerName,
93
+ guards: Array.from(/* @__PURE__ */ new Set([
94
+ ...node.guards,
95
+ ...owner.guards,
96
+ ...member.guards
97
+ ])),
98
+ interceptors: [...outer, ...inner],
99
+ attributes: {
100
+ handler: member.attributes,
101
+ controller: owner.attributes,
102
+ module: node.attributes
103
+ }
104
+ },
105
+ outer,
106
+ inner
94
107
  };
95
108
  }
96
109
  // src/metadata/run-chain.mts
@@ -100,15 +113,15 @@ async function resolve(container, type, kind, method) {
100
113
  return instance;
101
114
  }
102
115
  /**
103
- * Resolves the classes of a chain. A transport does this once per handler,
104
- * while it is set up.
116
+ * Resolves the classes of a chain that `handlerChain` returned. A transport
117
+ * does this once per handler, while it is set up.
105
118
  */
106
119
  async function resolveChain(container, chain) {
107
120
  const outer = [];
108
121
  const guards = [];
109
122
  const inner = [];
110
123
  for (const type of chain.outer) outer.push(await resolve(container, type, "Interceptor", "intercept"));
111
- for (const type of chain.guards) guards.push({
124
+ for (const type of chain.info.guards) guards.push({
112
125
  type,
113
126
  guard: await resolve(container, type, "Guard", "canActivate")
114
127
  });
@@ -141,6 +154,22 @@ function runChain(ctx, chain, handler, onDenied) {
141
154
  };
142
155
  return intercepted(ctx, chain.outer, guarded)();
143
156
  }
157
+ /**
158
+ * Runs a handler with what applies to it, as `runChain`, in the async context
159
+ * when the application keeps one, and then finishes its context, whatever the
160
+ * outcome. The context is finished inside the async context, so that
161
+ * `currentContext()` still answers in `onFinish` callbacks.
162
+ */
163
+ function executeChain(host, ctx, chain, handler, onDenied) {
164
+ const execute = async () => {
165
+ try {
166
+ return await runChain(ctx, chain, handler, onDenied);
167
+ } finally {
168
+ await ctx.finish();
169
+ }
170
+ };
171
+ return host.asyncContext ? require_execution_context_token.runInContext(ctx, execute) : execute();
172
+ }
144
173
  // src/execution/basic-execution-context.mts
145
174
  /**
146
175
  * An `ExecutionContext` for transports that need nothing beyond the neutral
@@ -152,7 +181,6 @@ var BasicExecutionContext = class {
152
181
  id;
153
182
  handler;
154
183
  host;
155
- givenSignal;
156
184
  ownSignal = null;
157
185
  slots = null;
158
186
  scope = null;
@@ -164,11 +192,13 @@ var BasicExecutionContext = class {
164
192
  this.id = init.id;
165
193
  this.handler = init.handler;
166
194
  this.host = init.host;
167
- this.givenSignal = init.signal;
168
195
  }
169
- /** Not shared between contexts: listeners would outlive their execution. */
196
+ /**
197
+ * A signal that never aborts. Not shared between contexts: listeners would
198
+ * outlive their execution.
199
+ */
170
200
  get signal() {
171
- return this.givenSignal ?? (this.ownSignal ??= new AbortController().signal);
201
+ return this.ownSignal ??= new AbortController().signal;
172
202
  }
173
203
  get(key) {
174
204
  const slots = this.slots;
@@ -190,9 +220,10 @@ var BasicExecutionContext = class {
190
220
  * @internal
191
221
  */
192
222
  resolverFor(token) {
193
- const { container } = this.host;
194
- if (this.scope === null && !require_execution_context_token.needsScope(container, token)) return container;
195
- this.host.onScopedUse?.(token);
223
+ const { container, onScopedUse } = this.host;
224
+ if (this.scope !== null && onScopedUse === null) return this.scope;
225
+ if (!require_execution_context_token.needsScope(container, token)) return this.scope ?? container;
226
+ onScopedUse?.(token);
196
227
  if (this.scope === null) {
197
228
  if (this.finished) throw new Error("[Navios] Request-scoped services cannot be used: the execution has finished, so nothing would dispose them.");
198
229
  this.scope = container.createScope();
@@ -259,6 +290,12 @@ Object.defineProperty(exports, "describeHandlerClass", {
259
290
  return describeHandlerClass;
260
291
  }
261
292
  });
293
+ Object.defineProperty(exports, "executeChain", {
294
+ enumerable: true,
295
+ get: function() {
296
+ return executeChain;
297
+ }
298
+ });
262
299
  Object.defineProperty(exports, "handlerChain", {
263
300
  enumerable: true,
264
301
  get: function() {
@@ -278,4 +315,4 @@ Object.defineProperty(exports, "runChain", {
278
315
  }
279
316
  });
280
317
 
281
- //# sourceMappingURL=basic-execution-context-DSk5MNtc.cjs.map
318
+ //# sourceMappingURL=basic-execution-context-5uq2DvEA.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-execution-context-5uq2DvEA.cjs","names":["requireMetadata","classAttributes","applyAttributes","prepend","classGuards","classInterceptors","MembersKey","runInContext","needsScope","ExecutionContextToken"],"sources":["../src/transports/transport.mts","../src/metadata/handler-class.mts","../src/metadata/handler-chain.mts","../src/metadata/run-chain.mts","../src/execution/basic-execution-context.mts"],"sourcesContent":["import type { ClassType, Container } from '@navios/di'\n\nimport type { ContextHost } from '../execution/context-host.mjs'\nimport type { OptionsArgument } from '../internal/options-argument.mjs'\nimport type { LoggerService } from '../logger/logger-output.mjs'\nimport type { ModuleNode } from '../modules/module-graph.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * What the application gives a transport when it creates it.\n */\nexport interface TransportHost {\n readonly container: Container\n readonly logger: LoggerService\n /** For the transport's execution contexts. */\n readonly contextHost: ContextHost\n /** Whether the application keeps the current context in an async store. */\n readonly asyncContext: boolean\n /**\n * Interceptors around every handler of the application, outermost first.\n * Complete once `setup()` is called.\n */\n readonly interceptors: readonly ClassType[]\n}\n\n/**\n * One way work reaches the application: an HTTP server, a queue consumer, a\n * command line. The application creates it, hands it the module graph, and\n * starts and stops it together with the others.\n */\nexport interface Transport {\n /**\n * Reads the module graph and prepares the transport's handlers. Must not\n * start accepting work.\n */\n setup(graph: readonly ModuleNode[]): void | Promise<void>\n /** Starts accepting work. Called at most once. */\n start?(): void | Promise<void>\n /**\n * Stops accepting work and waits, up to `timeoutMs`, for what is in flight.\n * One that takes much longer is left behind. When the application fails to\n * initialise or to start it is called for every transport that was created,\n * with no time to wait and possibly before `setup` or `start` ran; it must\n * release what `create` acquired. Called once, and again when `start` settles\n * only after that.\n */\n stop(timeoutMs: number): void | Promise<void>\n}\n\nexport interface TransportDefinition<Options, T extends Transport> {\n /** The kind of transport, and the default name of an instance. */\n name: string\n create(host: TransportHost, options: Options): T | Promise<T>\n}\n\n/**\n * A transport as it is listed in an application's options.\n */\nexport interface TransportInstance<T extends Transport = Transport> {\n readonly definition: TransportDefinition<any, T>\n /** `{}` when the transport was given none. */\n readonly options: unknown\n /** Unique within the application. Defaults to the definition's name. */\n readonly instanceName: string\n}\n\n/**\n * What `defineTransport` returns: called with options it gives the instance\n * to list in an application, and it is the key to look the transport up with.\n */\nexport interface TransportFactory<Options, T extends Transport> {\n (...args: OptionsArgument<Options, [instanceName?: string]>): TransportInstance<T>\n readonly definition: TransportDefinition<Options, T>\n}\n\n/**\n * Defines a transport.\n *\n * ```ts\n * export const queueTransport = defineTransport({\n * name: 'queue',\n * create(host, options: { url: string }) {\n * return new QueueTransport(host, options)\n * },\n * })\n *\n * const app = createApplication(AppModule, {\n * transports: [queueTransport({ url })],\n * })\n * await app.start()\n * app.transport(queueTransport) // the QueueTransport\n * ```\n *\n * An application can hold several transports of one definition when each has\n * its own name: `queueTransport({ url }, 'orders')`.\n */\nexport function defineTransport<Options = void, T extends Transport = Transport>(\n definition: TransportDefinition<Options, T>,\n): TransportFactory<Options, T> {\n const factory = (options?: Options, instanceName?: string): TransportInstance<T> => ({\n definition,\n options: options ?? {},\n instanceName: instanceName ?? definition.name,\n })\n return Object.assign(factory, { definition })\n}\n","import type { ClassType } from '@navios/di'\n\nimport { applyAttributes } from '../attributes/attribute-value.mjs'\n\nimport type { AttributeValue } from '../attributes/attribute-value.mjs'\n\nimport { classAttributes, classGuards, classInterceptors, prepend } from './class-metadata.mjs'\nimport { requireMetadata } from './decorator-metadata.mjs'\nimport { MembersKey } from './member-metadata.mjs'\n\nimport type { DecoratorMetadata } from './decorator-metadata.mjs'\nimport type { HandlerExtras, MethodHandlerMetadata } from './member-metadata.mjs'\n\n/** What a transport's decorator for handler classes may take. */\nexport interface HandlerClassOptions {\n guards?: Iterable<ClassType>\n interceptors?: Iterable<ClassType>\n attributes?: AttributeValue[]\n}\n\n/** A class that owns handlers: what applies to all of them, and its members. */\nexport interface HandlerClassMetadata extends HandlerExtras {\n /** The members decorators were applied to, by name. */\n members: Map<string, MethodHandlerMetadata>\n}\n\n/**\n * What decorators attached to a class of handlers and to its members, together\n * with the options of the class decorator that asks. The lists are live:\n * `@UseGuards` and the like placed above that decorator run after it and are\n * still seen.\n */\nexport function describeHandlerClass(\n context: { metadata?: DecoratorMetadata },\n options: HandlerClassOptions = {},\n): HandlerClassMetadata {\n const metadata = requireMetadata(context)\n const attributes = classAttributes(context)\n applyAttributes(attributes, options.attributes)\n return {\n guards: prepend(classGuards(context), options.guards),\n interceptors: prepend(classInterceptors(context), options.interceptors),\n attributes,\n members: (metadata[MembersKey] as Map<string, MethodHandlerMetadata> | undefined) ?? new Map(),\n }\n}\n","import type { ClassType } from '@navios/di'\n\nimport type { HandlerInfo } from '../execution/execution-context.mjs'\nimport type { ModuleNode } from '../modules/module-graph.mjs'\n\ninterface Extras {\n readonly guards: readonly ClassType[]\n readonly interceptors: readonly ClassType[]\n}\n\ninterface OwnExtras extends Extras {\n readonly attributes: ReadonlyMap<symbol, unknown>\n}\n\nexport interface HandlerChainInput {\n /**\n * Interceptors around every handler of the application or of the transport,\n * outermost first.\n */\n application: readonly ClassType[]\n /** The module the handler belongs to, with what it inherits. */\n node: Extras & Pick<ModuleNode, 'module' | 'attributes' | 'disputed'>\n /** The class that owns the handler. */\n controller: ClassType\n /** What applies to every handler of `controller`. */\n owner: OwnExtras\n /** The name of the handler in its class. */\n handlerName: string\n /** The handler itself. */\n member: OwnExtras\n}\n\nexport interface HandlerChain {\n /** What the contexts of the handler tell about it. */\n info: HandlerInfo\n /** Interceptors around the guards: those of the application. */\n outer: ClassType[]\n /** Interceptors inside the guards: those of the module, the class and the handler. */\n inner: ClassType[]\n}\n\n/**\n * An attribute may open the handler to everyone or restrict it, so it is not\n * guessed which of the import paths is meant.\n */\nfunction assertUndisputed({ node, owner, member }: HandlerChainInput): void {\n for (const [key, paths] of node.disputed) {\n if (!owner.attributes.has(key) && !member.attributes.has(key)) {\n throw new Error(\n `[Navios] Module ${node.module.name} inherits different values of the attribute ` +\n `${String(key)}: ${paths}. Set it on the controllers or handlers it is meant for, or ` +\n `on ${node.module.name} itself.`,\n )\n }\n }\n}\n\n/**\n * The guards and interceptors that apply to one handler, in the order they\n * run, and what its contexts tell about it: the interceptors of the\n * application, then the guards from the module chain, the owning class and\n * the handler, then the interceptors of the same three. A class that appears\n * twice is kept where it first appears. `info.guards` are the guards and\n * `info.interceptors` the interceptors, `outer` and then `inner`.\n *\n * An interceptor of the application sees every execution, denied ones\n * included, as tracing and logging need. One that is attached to handlers runs\n * only for what their guards let through.\n *\n * Throws when the handler would inherit an attribute that the importers of its\n * module do not agree about.\n *\n * Every transport uses this, so the rule is the same everywhere.\n * `resolveChain` resolves the chain and `runChain` runs it.\n */\nexport function handlerChain(input: HandlerChainInput): HandlerChain {\n assertUndisputed(input)\n const { application, node, controller, owner, handlerName, member } = input\n const everywhere = new Set(application)\n const attached = [...node.interceptors, ...owner.interceptors, ...member.interceptors]\n const outer = Array.from(everywhere)\n const inner = Array.from(new Set(attached.filter((interceptor) => !everywhere.has(interceptor))))\n return {\n info: {\n module: node.module,\n controller,\n handlerName,\n guards: Array.from(new Set([...node.guards, ...owner.guards, ...member.guards])),\n interceptors: [...outer, ...inner],\n attributes: {\n handler: member.attributes,\n controller: owner.attributes,\n module: node.attributes,\n },\n },\n outer,\n inner,\n }\n}\n","import type { ClassType, Container } from '@navios/di'\n\nimport { runInContext } from '../execution/async-context.mjs'\n\nimport type { ExecutionContext, HandlerInfo } from '../execution/execution-context.mjs'\nimport type { Guard } from '../guards/guard.mjs'\nimport type { Interceptor } from '../interceptors/interceptor.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/** A handler's chain with its instances, ready to run. */\nexport interface ResolvedChain<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {\n readonly outer: ReadonlyArray<Interceptor<Ctx, Result>>\n readonly guards: ReadonlyArray<{ readonly type: ClassType; readonly guard: Guard<Ctx> }>\n readonly inner: ReadonlyArray<Interceptor<Ctx, Result>>\n}\n\nasync function resolve(\n container: Pick<Container, 'get'>,\n type: ClassType,\n kind: string,\n method: string,\n): Promise<any> {\n const instance = (await container.get(type)) as any\n if (typeof instance?.[method] !== 'function') {\n throw new Error(`[Navios] ${kind} ${type.name} does not implement ${method}()`)\n }\n return instance\n}\n\n/**\n * Resolves the classes of a chain that `handlerChain` returned. A transport\n * does this once per handler, while it is set up.\n */\nexport async function resolveChain<\n Ctx extends ExecutionContext = ExecutionContext,\n Result = unknown,\n>(\n container: Pick<Container, 'get'>,\n chain: {\n readonly info: Pick<HandlerInfo, 'guards'>\n readonly outer: readonly ClassType[]\n readonly inner: readonly ClassType[]\n },\n): Promise<ResolvedChain<Ctx, Result>> {\n const outer: Interceptor<Ctx, Result>[] = []\n const guards: Array<{ type: ClassType; guard: Guard<Ctx> }> = []\n const inner: Interceptor<Ctx, Result>[] = []\n for (const type of chain.outer) {\n outer.push(await resolve(container, type, 'Interceptor', 'intercept'))\n }\n for (const type of chain.info.guards) {\n guards.push({ type, guard: await resolve(container, type, 'Guard', 'canActivate') })\n }\n for (const type of chain.inner) {\n inner.push(await resolve(container, type, 'Interceptor', 'intercept'))\n }\n return { outer, guards, inner }\n}\n\nfunction intercepted<Ctx extends ExecutionContext, Result>(\n ctx: Ctx,\n interceptors: ReadonlyArray<Interceptor<Ctx, Result>>,\n innermost: () => Result | Promise<Result>,\n): () => Promise<Result> {\n let next = async () => innermost()\n for (let i = interceptors.length - 1; i >= 0; i--) {\n const interceptor = interceptors[i]\n const inner = next\n next = async () => interceptor.intercept(ctx, inner)\n }\n return next\n}\n\n/**\n * Runs a handler with what applies to it: the outer interceptors, the guards\n * one after another, the inner interceptors, the handler. When a guard refuses,\n * nothing further runs and `onDenied` says what becomes of the execution: what\n * it returns is the result, and what it throws is the failure.\n */\nexport function runChain<Ctx extends ExecutionContext, Result>(\n ctx: Ctx,\n chain: ResolvedChain<Ctx, Result>,\n handler: () => Result | Promise<Result>,\n onDenied: (guard: ClassType) => Result | Promise<Result>,\n): Promise<Result> {\n const guarded = async (): Promise<Result> => {\n for (const { type, guard } of chain.guards) {\n if ((await guard.canActivate(ctx)) !== true) {\n return onDenied(type)\n }\n }\n return intercepted(ctx, chain.inner, handler)()\n }\n return intercepted(ctx, chain.outer, guarded)()\n}\n\n/**\n * Runs a handler with what applies to it, as `runChain`, in the async context\n * when the application keeps one, and then finishes its context, whatever the\n * outcome. The context is finished inside the async context, so that\n * `currentContext()` still answers in `onFinish` callbacks.\n */\nexport function executeChain<Ctx extends ExecutionContext & { finish(): Promise<void> }, Result>(\n host: { readonly asyncContext: boolean },\n ctx: Ctx,\n chain: ResolvedChain<Ctx, Result>,\n handler: () => Result | Promise<Result>,\n onDenied: (guard: ClassType) => Result | Promise<Result>,\n): Promise<Result> {\n const execute = async (): Promise<Result> => {\n try {\n return await runChain(ctx, chain, handler, onDenied)\n } finally {\n await ctx.finish()\n }\n }\n return host.asyncContext ? runInContext(ctx, execute) : execute()\n}\n","import type { AnyInjectableType, Container, ScopedContainer } from '@navios/di'\n\nimport { needsScope } from './context-host.mjs'\nimport { ExecutionContextToken } from './execution-context-token.mjs'\n\nimport type { ContextHost } from './context-host.mjs'\nimport type { ContextKey, ContextValue } from './context-key.mjs'\nimport type { ExecutionContext, HandlerInfo } from './execution-context.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport interface BasicExecutionContextInit {\n /** The transport kind, for example `'cli'`. */\n kind: string\n id: string\n handler: HandlerInfo\n host: ContextHost\n}\n\n/**\n * An `ExecutionContext` for transports that need nothing beyond the neutral\n * contract. The transport creates one per execution and calls `finish()` when\n * the handler is done.\n */\nexport class BasicExecutionContext implements ExecutionContext {\n readonly kind: string\n readonly id: string\n readonly handler: HandlerInfo\n private readonly host: ContextHost\n private ownSignal: AbortSignal | null = null\n private slots: Map<ContextKey, unknown> | null = null\n private scope: ScopedContainer | null = null\n private finishers: Array<() => void | Promise<void>> | null = null\n private finished = false\n private finishing: Promise<void> | null = null\n\n constructor(init: BasicExecutionContextInit) {\n this.kind = init.kind\n this.id = init.id\n this.handler = init.handler\n this.host = init.host\n }\n\n /**\n * A signal that never aborts. Not shared between contexts: listeners would\n * outlive their execution.\n */\n get signal(): AbortSignal {\n return (this.ownSignal ??= new AbortController().signal)\n }\n\n get<K extends ContextKey>(key: K): ContextValue<K> {\n const slots = this.slots\n if (slots === null || !slots.has(key)) {\n throw new Error(\n `[Navios] Context key ${key.name} is not set. ` +\n `Set it with ctx.set() (usually in a guard), or read it with ctx.find().`,\n )\n }\n return slots.get(key) as ContextValue<K>\n }\n\n find<K extends ContextKey>(key: K): ContextValue<K> | undefined {\n return this.slots?.get(key) as ContextValue<K> | undefined\n }\n\n set<K extends ContextKey>(key: K, value: ContextValue<K>): void {\n ;(this.slots ??= new Map()).set(key, value)\n }\n\n has(key: ContextKey): boolean {\n return this.slots?.has(key) ?? false\n }\n\n /**\n * What resolves a token for this execution: its DI scope, which is created\n * when something needs it.\n * @internal\n */\n resolverFor(token: AnyInjectableType): Container | ScopedContainer {\n const { container, onScopedUse } = this.host\n if (this.scope !== null && onScopedUse === null) {\n return this.scope\n }\n if (!needsScope(container, token)) {\n return this.scope ?? container\n }\n onScopedUse?.(token)\n if (this.scope === null) {\n if (this.finished) {\n throw new Error(\n '[Navios] Request-scoped services cannot be used: the execution has finished, so ' +\n 'nothing would dispose them.',\n )\n }\n this.scope = container.createScope()\n this.scope.addInstance(ExecutionContextToken, this)\n }\n return this.scope\n }\n\n declare use: ScopedContainer['getSync']\n\n declare resolve: ScopedContainer['get']\n\n onFinish(callback: () => void | Promise<void>): void {\n if (this.finished) {\n void this.runFinisher(callback)\n return\n }\n ;(this.finishers ??= []).push(callback)\n }\n\n /**\n * Runs the `onFinish` callbacks in reverse order, those they register\n * included, then disposes the DI scope. Runs once, however often it is\n * called; every caller waits for that run.\n */\n finish(): Promise<void> {\n return (this.finishing ??= this.runFinishers())\n }\n\n private async runFinishers(): Promise<void> {\n let finisher: (() => void | Promise<void>) | undefined\n while ((finisher = this.finishers?.pop()) !== undefined) {\n await this.runFinisher(finisher)\n }\n this.finished = true\n this.ownSignal = null\n const scope = this.scope\n this.scope = null\n if (scope !== null) {\n await scope.dispose()\n }\n }\n\n /** Runs a callback whose failure must not stop what follows. */\n private async runFinisher(callback: () => void | Promise<void>): Promise<void> {\n try {\n await callback()\n } catch (error) {\n // A failing callback must not stop the others, so it is only reported.\n try {\n this.host.logger?.error(`Error in an onFinish callback of ${this.kind} ${this.id}`, error)\n } catch {\n // Nor may a failing logger.\n }\n }\n }\n}\n\nBasicExecutionContext.prototype.use = function use(\n this: BasicExecutionContext,\n token: AnyInjectableType,\n args?: unknown,\n) {\n return (this.resolverFor(token).getSync as any)(token, args)\n} as ScopedContainer['getSync']\n\nBasicExecutionContext.prototype.resolve = function resolve(\n this: BasicExecutionContext,\n token: AnyInjectableType,\n args?: unknown,\n) {\n return (this.resolverFor(token).get as any)(token, args)\n} as ScopedContainer['get']\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,gBACd,YAC8B;CAC9B,MAAM,WAAW,SAAmB,kBAAiD;EACnF;EACA,SAAS,WAAW,CAAC;EACrB,cAAc,gBAAgB,WAAW;CAC3C;CACA,OAAO,OAAO,OAAO,SAAS,EAAE,WAAW,CAAC;AAC9C;;;;;;;;AC1EA,SAAgB,qBACd,SACA,UAA+B,CAAC,GACV;CACtB,MAAM,WAAWA,wBAAAA,gBAAgB,OAAO;CACxC,MAAM,aAAaC,wBAAAA,gBAAgB,OAAO;CAC1CC,wBAAAA,gBAAgB,YAAY,QAAQ,UAAU;CAC9C,OAAO;EACL,QAAQC,wBAAAA,QAAQC,wBAAAA,YAAY,OAAO,GAAG,QAAQ,MAAM;EACpD,cAAcD,wBAAAA,QAAQE,wBAAAA,kBAAkB,OAAO,GAAG,QAAQ,YAAY;EACtE;EACA,SAAU,SAASC,wBAAAA,+BAAkE,IAAI,IAAI;CAC/F;AACF;;;;;;ACAA,SAAS,iBAAiB,EAAE,MAAM,OAAO,UAAmC;CAC1E,KAAK,MAAM,CAAC,KAAK,UAAU,KA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