@navios/core 1.0.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
* Returns a value stored in decorator metadata under `key`, creating it for
|
|
36
|
+
* this class if it only exists on a parent. Decorator metadata objects
|
|
37
|
+
* inherit from the parent class's, so writing through an inherited value
|
|
38
|
+
* would change the parent.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
function own(metadata, key, create) {
|
|
42
|
+
if (!Object.hasOwn(metadata, key)) metadata[key] = create(metadata[key]);
|
|
43
|
+
return metadata[key];
|
|
44
|
+
}
|
|
45
|
+
/** The metadata of a decorator context, which has to have one. */
|
|
46
|
+
function requireMetadata(context) {
|
|
47
|
+
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.");
|
|
48
|
+
return context.metadata;
|
|
49
|
+
}
|
|
50
|
+
// src/metadata/class-metadata.mts
|
|
51
|
+
const ClassAttributesKey = Symbol.for("navios.core.classAttributes");
|
|
52
|
+
const ClassGuardsKey = Symbol.for("navios.core.classGuards");
|
|
53
|
+
const ClassInterceptorsKey = Symbol.for("navios.core.classInterceptors");
|
|
54
|
+
/** The attributes of a class, inherited ones included, to read and to add to. */
|
|
55
|
+
function classAttributes(context) {
|
|
56
|
+
return own(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited));
|
|
57
|
+
}
|
|
58
|
+
/** The guards of a class, as `classAttributes`. */
|
|
59
|
+
function classGuards(context) {
|
|
60
|
+
return own(requireMetadata(context), ClassGuardsKey, (inherited) => [...inherited ?? []]);
|
|
61
|
+
}
|
|
62
|
+
/** The interceptors of a class, as `classAttributes`. */
|
|
63
|
+
function classInterceptors(context) {
|
|
64
|
+
return own(requireMetadata(context), ClassInterceptorsKey, (inherited) => [...inherited ?? []]);
|
|
65
|
+
}
|
|
66
|
+
/** @internal */
|
|
67
|
+
function unique(list) {
|
|
68
|
+
return Array.from(new Set(list));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Puts `first` in front of `list`, in place, skipping duplicates.
|
|
72
|
+
*/
|
|
73
|
+
function prepend(list, first) {
|
|
74
|
+
if (first) {
|
|
75
|
+
const added = unique([...first]).filter((item) => !list.includes(item));
|
|
76
|
+
list.unshift(...added);
|
|
77
|
+
}
|
|
78
|
+
return list;
|
|
79
|
+
}
|
|
80
|
+
// src/metadata/member-metadata.mts
|
|
81
|
+
/** Where the members of a class are kept in its metadata. */
|
|
82
|
+
const MembersKey = Symbol.for("navios.core.members");
|
|
83
|
+
/**
|
|
84
|
+
* What decorators attached to a member, inherited ones included, to read and to
|
|
85
|
+
* add to.
|
|
86
|
+
*/
|
|
87
|
+
function memberMetadata(context, name) {
|
|
88
|
+
const members = own(requireMetadata(context), MembersKey, (inherited) => {
|
|
89
|
+
const copy = /* @__PURE__ */ new Map();
|
|
90
|
+
if (inherited) for (const [key, value] of inherited) copy.set(key, {
|
|
91
|
+
...value,
|
|
92
|
+
guards: [...value.guards],
|
|
93
|
+
interceptors: [...value.interceptors],
|
|
94
|
+
attributes: new Map(value.attributes),
|
|
95
|
+
entries: new Map(value.entries)
|
|
96
|
+
});
|
|
97
|
+
return copy;
|
|
98
|
+
});
|
|
99
|
+
let member = members.get(name);
|
|
100
|
+
if (!member) {
|
|
101
|
+
member = {
|
|
102
|
+
name,
|
|
103
|
+
guards: [],
|
|
104
|
+
interceptors: [],
|
|
105
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
106
|
+
entries: /* @__PURE__ */ new Map()
|
|
107
|
+
};
|
|
108
|
+
members.set(name, member);
|
|
109
|
+
}
|
|
110
|
+
return member;
|
|
111
|
+
}
|
|
112
|
+
// src/attributes/attribute-value.mts
|
|
113
|
+
/** Sets the values of attributes on a map of them. */
|
|
114
|
+
function applyAttributes(target, attributes) {
|
|
115
|
+
for (const attribute of attributes ?? []) target.set(attribute.token, attribute.value);
|
|
116
|
+
}
|
|
117
|
+
Object.defineProperty(exports, "MembersKey", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return MembersKey;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "applyAttributes", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function() {
|
|
126
|
+
return applyAttributes;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "classAttributes", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return classAttributes;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "classGuards", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function() {
|
|
138
|
+
return classGuards;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "classInterceptors", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return classInterceptors;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "memberMetadata", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return memberMetadata;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "prepend", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function() {
|
|
156
|
+
return prepend;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "requireMetadata", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function() {
|
|
162
|
+
return requireMetadata;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, "unique", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function() {
|
|
168
|
+
return unique;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=attribute-value-CjX9ZkLq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-value-CjX9ZkLq.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/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 * Returns a value stored in decorator metadata under `key`, creating it for\n * this class if it only exists on a parent. Decorator metadata objects\n * inherit from the parent class's, so writing through an inherited value\n * would change the parent.\n * @internal\n */\nexport function own<T>(metadata: DecoratorMetadata, key: symbol, create: (inherited?: T) => T): 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 { own, 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 own(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited))\n}\n\n/** The guards of a class, as `classAttributes`. */\nexport function classGuards(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return own<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 own<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 * 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 const added = unique([...first]).filter((item) => !list.includes(item))\n list.unshift(...added)\n }\n return list\n}\n","import type { ClassType } from '@navios/di'\n\nimport { own, 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 = own<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","/** 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,CA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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;;;AC5DA,SAAgB,gBACd,QACA,YACM;CACN,KAAK,MAAM,aAAa,cAAc,CAAC,GACrC,OAAO,IAAI,UAAU,OAAO,UAAU,KAAK;AAE/C"}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
* Returns a value stored in decorator metadata under `key`, creating it for
|
|
36
|
+
* this class if it only exists on a parent. Decorator metadata objects
|
|
37
|
+
* inherit from the parent class's, so writing through an inherited value
|
|
38
|
+
* would change the parent.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
function own(metadata, key, create) {
|
|
42
|
+
if (!Object.hasOwn(metadata, key)) metadata[key] = create(metadata[key]);
|
|
43
|
+
return metadata[key];
|
|
44
|
+
}
|
|
45
|
+
/** The metadata of a decorator context, which has to have one. */
|
|
46
|
+
function requireMetadata(context) {
|
|
47
|
+
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.");
|
|
48
|
+
return context.metadata;
|
|
49
|
+
}
|
|
50
|
+
// src/metadata/class-metadata.mts
|
|
51
|
+
const ClassAttributesKey = Symbol.for("navios.core.classAttributes");
|
|
52
|
+
const ClassGuardsKey = Symbol.for("navios.core.classGuards");
|
|
53
|
+
const ClassInterceptorsKey = Symbol.for("navios.core.classInterceptors");
|
|
54
|
+
/** The attributes of a class, inherited ones included, to read and to add to. */
|
|
55
|
+
function classAttributes(context) {
|
|
56
|
+
return own(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited));
|
|
57
|
+
}
|
|
58
|
+
/** The guards of a class, as `classAttributes`. */
|
|
59
|
+
function classGuards(context) {
|
|
60
|
+
return own(requireMetadata(context), ClassGuardsKey, (inherited) => [...inherited ?? []]);
|
|
61
|
+
}
|
|
62
|
+
/** The interceptors of a class, as `classAttributes`. */
|
|
63
|
+
function classInterceptors(context) {
|
|
64
|
+
return own(requireMetadata(context), ClassInterceptorsKey, (inherited) => [...inherited ?? []]);
|
|
65
|
+
}
|
|
66
|
+
/** @internal */
|
|
67
|
+
function unique(list) {
|
|
68
|
+
return Array.from(new Set(list));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Puts `first` in front of `list`, in place, skipping duplicates.
|
|
72
|
+
*/
|
|
73
|
+
function prepend(list, first) {
|
|
74
|
+
if (first) {
|
|
75
|
+
const added = unique([...first]).filter((item) => !list.includes(item));
|
|
76
|
+
list.unshift(...added);
|
|
77
|
+
}
|
|
78
|
+
return list;
|
|
79
|
+
}
|
|
80
|
+
// src/metadata/member-metadata.mts
|
|
81
|
+
/** Where the members of a class are kept in its metadata. */
|
|
82
|
+
const MembersKey = Symbol.for("navios.core.members");
|
|
83
|
+
/**
|
|
84
|
+
* What decorators attached to a member, inherited ones included, to read and to
|
|
85
|
+
* add to.
|
|
86
|
+
*/
|
|
87
|
+
function memberMetadata(context, name) {
|
|
88
|
+
const members = own(requireMetadata(context), MembersKey, (inherited) => {
|
|
89
|
+
const copy = /* @__PURE__ */ new Map();
|
|
90
|
+
if (inherited) for (const [key, value] of inherited) copy.set(key, {
|
|
91
|
+
...value,
|
|
92
|
+
guards: [...value.guards],
|
|
93
|
+
interceptors: [...value.interceptors],
|
|
94
|
+
attributes: new Map(value.attributes),
|
|
95
|
+
entries: new Map(value.entries)
|
|
96
|
+
});
|
|
97
|
+
return copy;
|
|
98
|
+
});
|
|
99
|
+
let member = members.get(name);
|
|
100
|
+
if (!member) {
|
|
101
|
+
member = {
|
|
102
|
+
name,
|
|
103
|
+
guards: [],
|
|
104
|
+
interceptors: [],
|
|
105
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
106
|
+
entries: /* @__PURE__ */ new Map()
|
|
107
|
+
};
|
|
108
|
+
members.set(name, member);
|
|
109
|
+
}
|
|
110
|
+
return member;
|
|
111
|
+
}
|
|
112
|
+
// src/attributes/attribute-value.mts
|
|
113
|
+
/** Sets the values of attributes on a map of them. */
|
|
114
|
+
function applyAttributes(target, attributes) {
|
|
115
|
+
for (const attribute of attributes ?? []) target.set(attribute.token, attribute.value);
|
|
116
|
+
}
|
|
117
|
+
export { classGuards as a, unique as c, classAttributes as i, requireMetadata as l, MembersKey as n, classInterceptors as o, memberMetadata as r, prepend as s, applyAttributes as t };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=attribute-value-DMEA255r.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-value-DMEA255r.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/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 * Returns a value stored in decorator metadata under `key`, creating it for\n * this class if it only exists on a parent. Decorator metadata objects\n * inherit from the parent class's, so writing through an inherited value\n * would change the parent.\n * @internal\n */\nexport function own<T>(metadata: DecoratorMetadata, key: symbol, create: (inherited?: T) => T): 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 { own, 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 own(requireMetadata(context), ClassAttributesKey, (inherited) => new Map(inherited))\n}\n\n/** The guards of a class, as `classAttributes`. */\nexport function classGuards(context: { metadata?: DecoratorMetadata }): ClassType[] {\n return own<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 own<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 * 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 const added = unique([...first]).filter((item) => !list.includes(item))\n list.unshift(...added)\n }\n return list\n}\n","import type { ClassType } from '@navios/di'\n\nimport { own, 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 = own<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","/** 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;;;;;;;;;ACGhE,SAAgB,IAAO,UAA6B,KAAa,QAAiC;CAChG,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;;AC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AAI,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;;;AC5DA,SAAgB,gBACd,QACA,YACM;CACN,KAAK,MAAM,aAAa,cAAc,CAAC,GACrC,OAAO,IAAI,UAAU,OAAO,UAAU,KAAK;AAE/C"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { a as classGuards, i as classAttributes, l as requireMetadata, n as MembersKey, o as classInterceptors, s as prepend, t as applyAttributes } from "./attribute-value-DMEA255r.mjs";
|
|
2
|
+
import { r as needsScope, t as ExecutionContextToken } from "./execution-context-token-CrXmTvk2.mjs";
|
|
3
|
+
// src/transports/transport.mts
|
|
4
|
+
/**
|
|
5
|
+
* Defines a transport.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* export const queueTransport = defineTransport({
|
|
9
|
+
* name: 'queue',
|
|
10
|
+
* create(host, options: { url: string }) {
|
|
11
|
+
* return new QueueTransport(host, options)
|
|
12
|
+
* },
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* const app = createApplication(AppModule, {
|
|
16
|
+
* transports: [queueTransport({ url })],
|
|
17
|
+
* })
|
|
18
|
+
* await app.start()
|
|
19
|
+
* app.transport(queueTransport) // the QueueTransport
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* An application can hold several transports of one definition when each has
|
|
23
|
+
* its own name: `queueTransport({ url }, 'orders')`.
|
|
24
|
+
*/
|
|
25
|
+
function defineTransport(definition) {
|
|
26
|
+
const factory = (options, instanceName) => ({
|
|
27
|
+
definition,
|
|
28
|
+
options: options ?? {},
|
|
29
|
+
instanceName: instanceName ?? definition.name
|
|
30
|
+
});
|
|
31
|
+
return Object.assign(factory, { definition });
|
|
32
|
+
}
|
|
33
|
+
// src/metadata/handler-class.mts
|
|
34
|
+
/**
|
|
35
|
+
* What decorators attached to a class of handlers and to its members, together
|
|
36
|
+
* with the options of the class decorator that asks. The lists are live:
|
|
37
|
+
* `@UseGuards` and the like placed above that decorator run after it and are
|
|
38
|
+
* still seen.
|
|
39
|
+
*/
|
|
40
|
+
function describeHandlerClass(context, options = {}) {
|
|
41
|
+
const metadata = requireMetadata(context);
|
|
42
|
+
const attributes = classAttributes(context);
|
|
43
|
+
applyAttributes(attributes, options.attributes);
|
|
44
|
+
return {
|
|
45
|
+
guards: prepend(classGuards(context), options.guards),
|
|
46
|
+
interceptors: prepend(classInterceptors(context), options.interceptors),
|
|
47
|
+
attributes,
|
|
48
|
+
members: metadata[MembersKey] ?? /* @__PURE__ */ new Map()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// src/metadata/handler-chain.mts
|
|
52
|
+
/**
|
|
53
|
+
* An attribute may open the handler to everyone or restrict it, so it is not
|
|
54
|
+
* guessed which of the import paths is meant.
|
|
55
|
+
*/
|
|
56
|
+
function assertUndisputed({ node, owner, member }) {
|
|
57
|
+
for (const [key, paths] of node.disputed) if (!owner.attributes.has(key) && !member.attributes.has(key)) throw new Error(`[Navios] Module ${node.module.name} inherits different values of the attribute ${String(key)}: ${paths}. Set it on the controllers or handlers it is meant for, or on ${node.module.name} itself.`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
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.
|
|
64
|
+
*
|
|
65
|
+
* An interceptor of the application sees every execution, denied ones
|
|
66
|
+
* included, as tracing and logging need. One that is attached to handlers runs
|
|
67
|
+
* only for what their guards let through.
|
|
68
|
+
*
|
|
69
|
+
* Throws when the handler would inherit an attribute that the importers of its
|
|
70
|
+
* module do not agree about.
|
|
71
|
+
*
|
|
72
|
+
* Every transport uses this, so the rule is the same everywhere. `runChain`
|
|
73
|
+
* runs the chain.
|
|
74
|
+
*/
|
|
75
|
+
function handlerChain(input) {
|
|
76
|
+
assertUndisputed(input);
|
|
77
|
+
const { application, node, owner, member } = input;
|
|
78
|
+
const outer = new Set(application);
|
|
79
|
+
const attached = [
|
|
80
|
+
...node.interceptors,
|
|
81
|
+
...owner.interceptors,
|
|
82
|
+
...member.interceptors
|
|
83
|
+
];
|
|
84
|
+
const inner = new Set(attached.filter((interceptor) => !outer.has(interceptor)));
|
|
85
|
+
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)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// src/metadata/run-chain.mts
|
|
97
|
+
async function resolve(container, type, kind, method) {
|
|
98
|
+
const instance = await container.get(type);
|
|
99
|
+
if (typeof instance?.[method] !== "function") throw new Error(`[Navios] ${kind} ${type.name} does not implement ${method}()`);
|
|
100
|
+
return instance;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Resolves the classes of a chain. A transport does this once per handler,
|
|
104
|
+
* while it is set up.
|
|
105
|
+
*/
|
|
106
|
+
async function resolveChain(container, chain) {
|
|
107
|
+
const outer = [];
|
|
108
|
+
const guards = [];
|
|
109
|
+
const inner = [];
|
|
110
|
+
for (const type of chain.outer) outer.push(await resolve(container, type, "Interceptor", "intercept"));
|
|
111
|
+
for (const type of chain.guards) guards.push({
|
|
112
|
+
type,
|
|
113
|
+
guard: await resolve(container, type, "Guard", "canActivate")
|
|
114
|
+
});
|
|
115
|
+
for (const type of chain.inner) inner.push(await resolve(container, type, "Interceptor", "intercept"));
|
|
116
|
+
return {
|
|
117
|
+
outer,
|
|
118
|
+
guards,
|
|
119
|
+
inner
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function intercepted(ctx, interceptors, innermost) {
|
|
123
|
+
let next = async () => innermost();
|
|
124
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
125
|
+
const interceptor = interceptors[i];
|
|
126
|
+
const inner = next;
|
|
127
|
+
next = async () => interceptor.intercept(ctx, inner);
|
|
128
|
+
}
|
|
129
|
+
return next;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Runs a handler with what applies to it: the outer interceptors, the guards
|
|
133
|
+
* one after another, the inner interceptors, the handler. When a guard refuses,
|
|
134
|
+
* nothing further runs and `onDenied` says what becomes of the execution: what
|
|
135
|
+
* it returns is the result, and what it throws is the failure.
|
|
136
|
+
*/
|
|
137
|
+
function runChain(ctx, chain, handler, onDenied) {
|
|
138
|
+
const guarded = async () => {
|
|
139
|
+
for (const { type, guard } of chain.guards) if (await guard.canActivate(ctx) !== true) return onDenied(type);
|
|
140
|
+
return intercepted(ctx, chain.inner, handler)();
|
|
141
|
+
};
|
|
142
|
+
return intercepted(ctx, chain.outer, guarded)();
|
|
143
|
+
}
|
|
144
|
+
// src/execution/basic-execution-context.mts
|
|
145
|
+
/**
|
|
146
|
+
* An `ExecutionContext` for transports that need nothing beyond the neutral
|
|
147
|
+
* contract. The transport creates one per execution and calls `finish()` when
|
|
148
|
+
* the handler is done.
|
|
149
|
+
*/
|
|
150
|
+
var BasicExecutionContext = class {
|
|
151
|
+
kind;
|
|
152
|
+
id;
|
|
153
|
+
handler;
|
|
154
|
+
host;
|
|
155
|
+
givenSignal;
|
|
156
|
+
ownSignal = null;
|
|
157
|
+
slots = null;
|
|
158
|
+
scope = null;
|
|
159
|
+
finishers = null;
|
|
160
|
+
finished = false;
|
|
161
|
+
finishing = null;
|
|
162
|
+
constructor(init) {
|
|
163
|
+
this.kind = init.kind;
|
|
164
|
+
this.id = init.id;
|
|
165
|
+
this.handler = init.handler;
|
|
166
|
+
this.host = init.host;
|
|
167
|
+
this.givenSignal = init.signal;
|
|
168
|
+
}
|
|
169
|
+
/** Not shared between contexts: listeners would outlive their execution. */
|
|
170
|
+
get signal() {
|
|
171
|
+
return this.givenSignal ?? (this.ownSignal ??= new AbortController().signal);
|
|
172
|
+
}
|
|
173
|
+
get(key) {
|
|
174
|
+
const slots = this.slots;
|
|
175
|
+
if (slots === null || !slots.has(key)) throw new Error(`[Navios] Context key ${key.name} is not set. Set it with ctx.set() (usually in a guard), or read it with ctx.find().`);
|
|
176
|
+
return slots.get(key);
|
|
177
|
+
}
|
|
178
|
+
find(key) {
|
|
179
|
+
return this.slots?.get(key);
|
|
180
|
+
}
|
|
181
|
+
set(key, value) {
|
|
182
|
+
(this.slots ??= /* @__PURE__ */ new Map()).set(key, value);
|
|
183
|
+
}
|
|
184
|
+
has(key) {
|
|
185
|
+
return this.slots?.has(key) ?? false;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* What resolves a token for this execution: its DI scope, which is created
|
|
189
|
+
* when something needs it.
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
resolverFor(token) {
|
|
193
|
+
const { container } = this.host;
|
|
194
|
+
if (this.scope === null && !needsScope(container, token)) return container;
|
|
195
|
+
this.host.onScopedUse?.(token);
|
|
196
|
+
if (this.scope === null) {
|
|
197
|
+
if (this.finished) throw new Error("[Navios] Request-scoped services cannot be used: the execution has finished, so nothing would dispose them.");
|
|
198
|
+
this.scope = container.createScope();
|
|
199
|
+
this.scope.addInstance(ExecutionContextToken, this);
|
|
200
|
+
}
|
|
201
|
+
return this.scope;
|
|
202
|
+
}
|
|
203
|
+
onFinish(callback) {
|
|
204
|
+
if (this.finished) {
|
|
205
|
+
this.runFinisher(callback);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
(this.finishers ??= []).push(callback);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Runs the `onFinish` callbacks in reverse order, those they register
|
|
212
|
+
* included, then disposes the DI scope. Runs once, however often it is
|
|
213
|
+
* called; every caller waits for that run.
|
|
214
|
+
*/
|
|
215
|
+
finish() {
|
|
216
|
+
return this.finishing ??= this.runFinishers();
|
|
217
|
+
}
|
|
218
|
+
async runFinishers() {
|
|
219
|
+
let finisher;
|
|
220
|
+
while ((finisher = this.finishers?.pop()) !== void 0) await this.runFinisher(finisher);
|
|
221
|
+
this.finished = true;
|
|
222
|
+
this.ownSignal = null;
|
|
223
|
+
const scope = this.scope;
|
|
224
|
+
this.scope = null;
|
|
225
|
+
if (scope !== null) await scope.dispose();
|
|
226
|
+
}
|
|
227
|
+
/** Runs a callback whose failure must not stop what follows. */
|
|
228
|
+
async runFinisher(callback) {
|
|
229
|
+
try {
|
|
230
|
+
await callback();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
try {
|
|
233
|
+
this.host.logger?.error(`Error in an onFinish callback of ${this.kind} ${this.id}`, error);
|
|
234
|
+
} catch {}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
BasicExecutionContext.prototype.use = function use(token, args) {
|
|
239
|
+
return this.resolverFor(token).getSync(token, args);
|
|
240
|
+
};
|
|
241
|
+
BasicExecutionContext.prototype.resolve = function resolve(token, args) {
|
|
242
|
+
return this.resolverFor(token).get(token, args);
|
|
243
|
+
};
|
|
244
|
+
export { describeHandlerClass as a, handlerChain as i, resolveChain as n, defineTransport as o, runChain as r, BasicExecutionContext as t };
|
|
245
|
+
|
|
246
|
+
//# sourceMappingURL=basic-execution-context-CeGuhMOz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-execution-context-CeGuhMOz.mjs","names":[],"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 { 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' | 'disputed'>\n /** The class that owns the handler. */\n owner: OwnExtras\n /** The handler itself. */\n member: OwnExtras\n}\n\nexport interface HandlerChain {\n guards: ClassType[]\n /** `outer` and `inner`, one after the other. */\n interceptors: ClassType[]\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: the interceptors of the application, then the guards from the module\n * chain, the owning class and the handler, then the interceptors of the same\n * three. A class that appears twice is kept where it first appears.\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. `runChain`\n * runs the chain.\n */\nexport function handlerChain(input: HandlerChainInput): HandlerChain {\n assertUndisputed(input)\n const { application, node, owner, member } = input\n const outer = new Set(application)\n const attached = [...node.interceptors, ...owner.interceptors, ...member.interceptors]\n const inner = new Set(attached.filter((interceptor) => !outer.has(interceptor)))\n return {\n guards: Array.from(new Set([...node.guards, ...owner.guards, ...member.guards])),\n interceptors: [...outer, ...inner],\n outer: Array.from(outer),\n inner: Array.from(inner),\n }\n}\n","import type { ClassType, Container } from '@navios/di'\n\nimport type { ExecutionContext } from '../execution/execution-context.mjs'\nimport type { Guard } from '../guards/guard.mjs'\nimport type { Interceptor } from '../interceptors/interceptor.mjs'\n\nimport type { HandlerChain } from './handler-chain.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. A transport does this once per handler,\n * 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: Pick<HandlerChain, 'outer' | 'guards' | 'inner'>,\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.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","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 /** Defaults to a signal of the context's own that never aborts. */\n signal?: AbortSignal\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 readonly givenSignal: AbortSignal | undefined\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 this.givenSignal = init.signal\n }\n\n /** Not shared between contexts: listeners would outlive their execution. */\n get signal(): AbortSignal {\n return this.givenSignal ?? (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 } = this.host\n if (this.scope === null && !needsScope(container, token)) {\n return container\n }\n this.host.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,WAAW,gBAAgB,OAAO;CACxC,MAAM,aAAa,gBAAgB,OAAO;CAC1C,gBAAgB,YAAY,QAAQ,UAAU;CAC9C,OAAO;EACL,QAAQ,QAAQ,YAAY,OAAO,GAAG,QAAQ,MAAM;EACpD,cAAc,QAAQ,kBAAkB,OAAO,GAAG,QAAQ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