@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.
- package/CHANGELOG.md +33 -3
- package/README.md +8 -6
- package/lib/{async-context-6pdlnNLA.d.mts → async-context-BAdt7bno.d.mts} +11 -9
- package/lib/async-context-BAdt7bno.d.mts.map +1 -0
- package/lib/{async-context-Dqk7pE-D.d.cts → async-context-RsWmy2Hi.d.cts} +11 -9
- package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
- package/lib/{attribute-factory-B3VuYnp7.d.cts → attribute-factory-BW1kgBqf.d.mts} +2 -2
- package/lib/{attribute-factory-B3VuYnp7.d.cts.map → attribute-factory-BW1kgBqf.d.mts.map} +1 -1
- package/lib/{attribute-factory-mKOXoVnV.d.mts → attribute-factory-DqN4x5XM.d.cts} +2 -2
- package/lib/{attribute-factory-mKOXoVnV.d.mts.map → attribute-factory-DqN4x5XM.d.cts.map} +1 -1
- package/lib/attribute-value-BNiJjxl1.mjs +225 -0
- package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
- package/lib/attribute-value-Cux5HhOL.cjs +314 -0
- package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
- package/lib/{basic-execution-context-DSk5MNtc.cjs → basic-execution-context-5uq2DvEA.cjs} +66 -29
- package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
- package/lib/{basic-execution-context-CeGuhMOz.mjs → basic-execution-context-u1VktGoM.mjs} +61 -30
- package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
- package/lib/{execution-context-BPD3FeFb.d.mts → execution-context-BVSmLkYp.d.cts} +2 -2
- package/lib/{execution-context-BPD3FeFb.d.mts.map → execution-context-BVSmLkYp.d.cts.map} +1 -1
- package/lib/{execution-context-BTJdHhbf.d.cts → execution-context-C5F9rojO.d.mts} +2 -2
- package/lib/{execution-context-BTJdHhbf.d.cts.map → execution-context-C5F9rojO.d.mts.map} +1 -1
- package/lib/{module-graph-DCP9MHG0.cjs → execution-context-token--cKS4cJv.cjs} +135 -12
- package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
- package/lib/{module-graph-xvVEykFM.mjs → execution-context-token-Cb3M3Ao0.mjs} +93 -12
- package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
- package/lib/index.cjs +84 -101
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +14 -10
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +14 -10
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +76 -92
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +2 -2
- package/lib/legacy-compat/index.d.cts +3 -3
- package/lib/legacy-compat/index.d.mts +2 -2
- package/lib/legacy-compat/index.mjs +2 -2
- package/lib/{module-DZewk_2r.cjs → module-Bz83ZnJ5.cjs} +43 -34
- package/lib/module-Bz83ZnJ5.cjs.map +1 -0
- package/lib/{module-options-Dmse0gii.d.mts → module-options-CSqQUSTm.d.mts} +2 -2
- package/lib/{module-options-Dmse0gii.d.mts.map → module-options-CSqQUSTm.d.mts.map} +1 -1
- package/lib/{module-options-IuDO-p8u.d.cts → module-options-DSRBri4J.d.cts} +2 -2
- package/lib/{module-options-IuDO-p8u.d.cts.map → module-options-DSRBri4J.d.cts.map} +1 -1
- package/lib/{module-Bha7GER_.mjs → module-zPXwR2qp.mjs} +38 -35
- package/lib/module-zPXwR2qp.mjs.map +1 -0
- package/lib/settled-within-B6gpu2XW.cjs +32 -0
- package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
- package/lib/settled-within-Bc2pj8WB.mjs +21 -0
- package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
- package/lib/testing/index.cjs +12 -34
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +2 -2
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +1 -1
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +12 -34
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +19 -8
- package/lib/transport.d.cts +102 -38
- package/lib/transport.d.cts.map +1 -1
- package/lib/transport.d.mts +102 -38
- package/lib/transport.d.mts.map +1 -1
- package/lib/transport.mjs +6 -7
- package/package.json +2 -2
- package/lib/async-context-6pdlnNLA.d.mts.map +0 -1
- package/lib/async-context-Dqk7pE-D.d.cts.map +0 -1
- package/lib/attribute-value-CjX9ZkLq.cjs +0 -172
- package/lib/attribute-value-CjX9ZkLq.cjs.map +0 -1
- package/lib/attribute-value-DMEA255r.mjs +0 -119
- package/lib/attribute-value-DMEA255r.mjs.map +0 -1
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +0 -1
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +0 -1
- package/lib/execution-context-token-BXUKB2hf.cjs +0 -112
- package/lib/execution-context-token-BXUKB2hf.cjs.map +0 -1
- package/lib/execution-context-token-CrXmTvk2.mjs +0 -77
- package/lib/execution-context-token-CrXmTvk2.mjs.map +0 -1
- package/lib/module-Bha7GER_.mjs.map +0 -1
- package/lib/module-DZewk_2r.cjs.map +0 -1
- package/lib/module-graph-DCP9MHG0.cjs.map +0 -1
- package/lib/module-graph-xvVEykFM.mjs.map +0 -1
- package/lib/module-metadata-C8S92seK.cjs +0 -95
- package/lib/module-metadata-C8S92seK.cjs.map +0 -1
- package/lib/module-metadata-k3RTt20x.mjs +0 -66
- package/lib/module-metadata-k3RTt20x.mjs.map +0 -1
package/lib/testing/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../attribute-value-
|
|
2
|
-
import {
|
|
1
|
+
import "../attribute-value-BNiJjxl1.mjs";
|
|
2
|
+
import { i as createContextHost, r as moduleClasses, s as enableAsyncContext } from "../execution-context-token-Cb3M3Ao0.mjs";
|
|
3
3
|
import { createClassContext } from "@navios/di/legacy-compat";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as handlerChain, n as executeChain, o as describeHandlerClass, r as resolveChain, s as defineTransport, t as BasicExecutionContext } from "../basic-execution-context-u1VktGoM.mjs";
|
|
5
5
|
// src/testing/fake-transport.mts
|
|
6
6
|
let runs = 0;
|
|
7
7
|
/**
|
|
@@ -36,23 +36,20 @@ const fakeTransport = defineTransport({
|
|
|
36
36
|
setup(graph) {
|
|
37
37
|
log.push(`${kind}:setup`);
|
|
38
38
|
if (options.failSetup) throw new Error(`${kind} setup failed`);
|
|
39
|
-
for (const node of graph) for (const handler of node
|
|
40
|
-
const owner = attachedTo(handler);
|
|
39
|
+
for (const node of graph) for (const handler of moduleClasses(node, entry)) {
|
|
41
40
|
const chain = handlerChain({
|
|
42
41
|
application: host.interceptors,
|
|
43
42
|
node,
|
|
44
|
-
|
|
43
|
+
controller: handler,
|
|
44
|
+
owner: attachedTo(handler),
|
|
45
|
+
handlerName: "run",
|
|
45
46
|
member: {
|
|
46
47
|
guards: [],
|
|
47
48
|
interceptors: [],
|
|
48
49
|
attributes: /* @__PURE__ */ new Map()
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
|
-
found.set(handler,
|
|
52
|
-
node,
|
|
53
|
-
owner,
|
|
54
|
-
chain
|
|
55
|
-
});
|
|
52
|
+
found.set(handler, chain);
|
|
56
53
|
}
|
|
57
54
|
},
|
|
58
55
|
start() {
|
|
@@ -64,35 +61,16 @@ const fakeTransport = defineTransport({
|
|
|
64
61
|
if (options.failStop) throw new Error(`${kind} stop failed`);
|
|
65
62
|
},
|
|
66
63
|
async run(handler) {
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
69
|
-
const { node, owner, chain } = known;
|
|
64
|
+
const chain = found.get(handler);
|
|
65
|
+
if (!chain) throw new Error(`${handler.name} is not a handler of the ${kind} transport`);
|
|
70
66
|
const resolved = await resolveChain(host.container, chain);
|
|
71
67
|
const ctx = new BasicExecutionContext({
|
|
72
68
|
kind,
|
|
73
69
|
id: `${kind}-${++runs}`,
|
|
74
70
|
host: host.contextHost,
|
|
75
|
-
handler:
|
|
76
|
-
module: node.module,
|
|
77
|
-
controller: handler,
|
|
78
|
-
handlerName: "run",
|
|
79
|
-
guards: chain.guards,
|
|
80
|
-
interceptors: chain.interceptors,
|
|
81
|
-
attributes: {
|
|
82
|
-
handler: /* @__PURE__ */ new Map(),
|
|
83
|
-
controller: owner.attributes,
|
|
84
|
-
module: node.attributes
|
|
85
|
-
}
|
|
86
|
-
}
|
|
71
|
+
handler: chain.info
|
|
87
72
|
});
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
return await runChain(ctx, resolved, () => true, () => false);
|
|
91
|
-
} finally {
|
|
92
|
-
await ctx.finish();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return host.asyncContext ? runInContext(ctx, execute) : execute();
|
|
73
|
+
return executeChain(host, ctx, resolved, () => true, () => false);
|
|
96
74
|
}
|
|
97
75
|
};
|
|
98
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/testing/fake-transport.mts"],"sourcesContent":["import { createClassContext } from '@navios/di/legacy-compat'\n\nimport type { ClassType } from '@navios/di'\n\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/testing/fake-transport.mts"],"sourcesContent":["import { createClassContext } from '@navios/di/legacy-compat'\n\nimport type { ClassType } from '@navios/di'\n\nimport { BasicExecutionContext } from '../execution/basic-execution-context.mjs'\nimport { handlerChain } from '../metadata/handler-chain.mjs'\nimport { describeHandlerClass } from '../metadata/handler-class.mjs'\nimport { executeChain, resolveChain } from '../metadata/run-chain.mjs'\nimport { moduleClasses } from '../modules/module-graph.mjs'\nimport { defineTransport } from '../transports/transport.mjs'\n\nimport type { HandlerChain } from '../metadata/handler-chain.mjs'\nimport type { HandlerExtras } from '../metadata/member-metadata.mjs'\nimport type { Transport, TransportHost } from '../transports/transport.mjs'\n\nexport interface FakeTransportOptions {\n /** The `kind` of the contexts this transport creates. */\n kind: string\n /** The `@Module` option this transport reads its handler classes from. */\n entry: string\n /** Receives `<kind>:create`, `:setup`, `:start` and `:stop`. */\n log: string[]\n failSetup?: boolean\n failStart?: boolean\n failStop?: boolean\n}\n\nexport interface FakeTransport extends Transport {\n /** The handler classes found in the graph, in graph order. */\n readonly handlers: ClassType[]\n /**\n * Runs what applies to a handler class, as a transport runs it for a handler\n * that does nothing: the application's interceptors, the guards, the\n * interceptors of the module and the class. Resolves to whether every guard\n * allowed it.\n */\n run(handler: ClassType): Promise<boolean>\n}\n\nlet runs = 0\n\n/**\n * What decorators attached to a class, of either kind, without a decorator of\n * the transport's own having asked for it.\n */\nfunction attachedTo(target: ClassType): HandlerExtras {\n const symbol = (Symbol as { metadata?: symbol }).metadata\n const standard = symbol && (target as unknown as Record<symbol, object | undefined>)[symbol]\n const { metadata } = createClassContext(target)\n const [first, second] = [standard, metadata].map((from) =>\n // Read through an object of its own: reading adds what is missing.\n describeHandlerClass({ metadata: Object.create(from ?? null) }),\n )\n return {\n guards: [...first.guards, ...second.guards],\n interceptors: [...first.interceptors, ...second.interceptors],\n attributes: new Map([...first.attributes, ...second.attributes]),\n }\n}\n\n/**\n * A transport for tests: it records its lifecycle and can run the guards and\n * interceptors of a handler class with a context of its own kind.\n */\nexport const fakeTransport = defineTransport<FakeTransportOptions, FakeTransport>({\n name: 'fake',\n create(host: TransportHost, options) {\n const { kind, entry, log } = options\n const found = new Map<ClassType, HandlerChain>()\n log.push(`${kind}:create`)\n return {\n get handlers() {\n return [...found.keys()]\n },\n setup(graph) {\n log.push(`${kind}:setup`)\n if (options.failSetup) {\n throw new Error(`${kind} setup failed`)\n }\n for (const node of graph) {\n for (const handler of moduleClasses(node, entry)) {\n const chain = handlerChain({\n application: host.interceptors,\n node,\n controller: handler,\n owner: attachedTo(handler),\n handlerName: 'run',\n member: { guards: [], interceptors: [], attributes: new Map() },\n })\n found.set(handler, chain)\n }\n }\n },\n start() {\n log.push(`${kind}:start`)\n if (options.failStart) {\n throw new Error(`${kind} start failed`)\n }\n },\n async stop() {\n log.push(`${kind}:stop`)\n if (options.failStop) {\n throw new Error(`${kind} stop failed`)\n }\n },\n async run(handler) {\n const chain = found.get(handler)\n if (!chain) {\n throw new Error(`${handler.name} is not a handler of the ${kind} transport`)\n }\n const resolved = await resolveChain<BasicExecutionContext, boolean>(host.container, chain)\n const ctx = new BasicExecutionContext({\n kind,\n id: `${kind}-${++runs}`,\n host: host.contextHost,\n handler: chain.info,\n })\n return executeChain(\n host,\n ctx,\n resolved,\n () => true,\n () => false,\n )\n },\n }\n },\n})\n"],"mappings":";;;;;AAuCA,IAAI,OAAO;;;;;AAMX,SAAS,WAAW,QAAkC;CACpD,MAAM,SAAU,OAAiC;CACjD,MAAM,WAAW,UAAW,OAAyD;CACrF,MAAM,EAAE,aAAa,mBAAmB,MAAM;CAC9C,MAAM,CAAC,OAAO,UAAU,CAAC,UAAU,QAAQ,CAAC,CAAC,KAAK,SAEhD,qBAAqB,EAAE,UAAU,OAAO,OAAO,QAAQ,IAAI,EAAE,CAAC,CAChE;CACA,OAAO;EACL,QAAQ,CAAC,GAAG,MAAM,QAAQ,GAAG,OAAO,MAAM;EAC1C,cAAc,CAAC,GAAG,MAAM,cAAc,GAAG,OAAO,YAAY;EAC5D,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,YAAY,GAAG,OAAO,UAAU,CAAC;CACjE;AACF;;;;;AAMA,MAAa,gBAAgB,gBAAqD;CAChF,MAAM;CACN,OAAO,MAAqB,SAAS;EACnC,MAAM,EAAE,MAAM,OAAO,QAAQ;EAC7B,MAAM,wBAAQ,IAAI,IAA6B;EAC/C,IAAI,KAAK,GAAG,KAAK,QAAQ;EACzB,OAAO;GACL,IAAI,WAAW;IACb,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC;GACzB;GACA,MAAM,OAAO;IACX,IAAI,KAAK,GAAG,KAAK,OAAO;IACxB,IAAI,QAAQ,WACV,MAAM,IAAI,MAAM,GAAG,KAAK,cAAc;IAExC,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,WAAW,cAAc,MAAM,KAAK,GAAG;KAChD,MAAM,QAAQ,aAAa;MACzB,aAAa,KAAK;MAClB;MACA,YAAY;MACZ,OAAO,WAAW,OAAO;MACzB,aAAa;MACb,QAAQ;OAAE,QAAQ,CAAC;OAAG,cAAc,CAAC;OAAG,4BAAY,IAAI,IAAI;MAAE;KAChE,CAAC;KACD,MAAM,IAAI,SAAS,KAAK;IAC1B;GAEJ;GACA,QAAQ;IACN,IAAI,KAAK,GAAG,KAAK,OAAO;IACxB,IAAI,QAAQ,WACV,MAAM,IAAI,MAAM,GAAG,KAAK,cAAc;GAE1C;GACA,MAAM,OAAO;IACX,IAAI,KAAK,GAAG,KAAK,MAAM;IACvB,IAAI,QAAQ,UACV,MAAM,IAAI,MAAM,GAAG,KAAK,aAAa;GAEzC;GACA,MAAM,IAAI,SAAS;IACjB,MAAM,QAAQ,MAAM,IAAI,OAAO;IAC/B,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,GAAG,QAAQ,KAAK,2BAA2B,KAAK,WAAW;IAE7E,MAAM,WAAW,MAAM,aAA6C,KAAK,WAAW,KAAK;IACzF,MAAM,MAAM,IAAI,sBAAsB;KACpC;KACA,IAAI,GAAG,KAAK,GAAG,EAAE;KACjB,MAAM,KAAK;KACX,SAAS,MAAM;IACjB,CAAC;IACD,OAAO,aACL,MACA,KACA,gBACM,YACA,KACR;GACF;EACF;CACF;AACF,CAAC"}
|
package/lib/transport.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_attribute_value = require("./attribute-value-
|
|
3
|
-
const require_basic_execution_context = require("./basic-execution-context-
|
|
2
|
+
const require_attribute_value = require("./attribute-value-Cux5HhOL.cjs");
|
|
3
|
+
const require_basic_execution_context = require("./basic-execution-context-5uq2DvEA.cjs");
|
|
4
4
|
let _navios_di_internal = require("@navios/di/internal");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const require_execution_context_token = require("./execution-context-token-BXUKB2hf.cjs");
|
|
5
|
+
const require_settled_within = require("./settled-within-B6gpu2XW.cjs");
|
|
6
|
+
const require_execution_context_token = require("./execution-context-token--cKS4cJv.cjs");
|
|
8
7
|
exports.BasicExecutionContext = require_basic_execution_context.BasicExecutionContext;
|
|
9
|
-
exports.
|
|
8
|
+
exports.MAX_DELAY_MS = require_settled_within.MAX_DELAY_MS;
|
|
9
|
+
exports.buildModuleGraph = require_execution_context_token.buildModuleGraph;
|
|
10
|
+
exports.classMetadata = require_attribute_value.classMetadata;
|
|
10
11
|
Object.defineProperty(exports, "constructedInstances", {
|
|
11
12
|
enumerable: true,
|
|
12
13
|
get: function() {
|
|
@@ -15,11 +16,21 @@ Object.defineProperty(exports, "constructedInstances", {
|
|
|
15
16
|
});
|
|
16
17
|
exports.defineTransport = require_basic_execution_context.defineTransport;
|
|
17
18
|
exports.describeHandlerClass = require_basic_execution_context.describeHandlerClass;
|
|
18
|
-
exports
|
|
19
|
+
Object.defineProperty(exports, "disposeScope", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return _navios_di_internal.disposeScope;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
exports.executeChain = require_basic_execution_context.executeChain;
|
|
26
|
+
exports.getModuleMetadata = require_attribute_value.getModuleMetadata;
|
|
19
27
|
exports.handlerChain = require_basic_execution_context.handlerChain;
|
|
20
|
-
exports.hasModuleMetadata = require_module_metadata.hasModuleMetadata;
|
|
21
28
|
exports.memberMetadata = require_attribute_value.memberMetadata;
|
|
29
|
+
exports.moduleClasses = require_execution_context_token.moduleClasses;
|
|
22
30
|
exports.needsScope = require_execution_context_token.needsScope;
|
|
31
|
+
exports.ownMetadata = require_attribute_value.ownMetadata;
|
|
32
|
+
exports.requireMetadata = require_attribute_value.requireMetadata;
|
|
23
33
|
exports.resolveChain = require_basic_execution_context.resolveChain;
|
|
24
34
|
exports.runChain = require_basic_execution_context.runChain;
|
|
25
35
|
exports.runInContext = require_execution_context_token.runInContext;
|
|
36
|
+
exports.settledWithin = require_settled_within.settledWithin;
|
package/lib/transport.d.cts
CHANGED
|
@@ -5,17 +5,35 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Application code imports from `@navios/core`.
|
|
7
7
|
*/
|
|
8
|
-
import { a as ContextValue, i as ContextKey, n as ExecutionContext, r as HandlerInfo
|
|
9
|
-
import {
|
|
10
|
-
import { ClassType,
|
|
11
|
-
import { constructedInstances } from "@navios/di/internal";
|
|
12
|
-
import { a as Interceptor, i as AttributeValue, n as Guard
|
|
8
|
+
import { a as ContextValue, i as ContextKey, n as ExecutionContext, r as HandlerInfo } from "./execution-context-BVSmLkYp.cjs";
|
|
9
|
+
import { a as TransportDefinition, d as buildModuleGraph, f as moduleClasses, h as needsScope, l as defineTransport, p as ContextHost, r as runInContext, s as TransportHost, u as ModuleNode } from "./async-context-RsWmy2Hi.cjs";
|
|
10
|
+
import { ClassType, Container, Provider, ScopedContainer } from "@navios/di";
|
|
11
|
+
import { constructedInstances, disposeScope } from "@navios/di/internal";
|
|
12
|
+
import { a as Interceptor, i as AttributeValue, n as Guard } from "./module-options-DSRBri4J.cjs";
|
|
13
|
+
/** The longest delay a timer takes; a longer one fires at once. */
|
|
14
|
+
export declare const MAX_DELAY_MS: number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether `work` settles within `ms`, or within `MAX_DELAY_MS` when `ms` is
|
|
17
|
+
* longer. Rejects when it rejects in time; a later rejection is dropped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function settledWithin(work: PromiseLike<unknown>, ms: number): Promise<boolean>;
|
|
13
20
|
/** The `metadata` of a decorator context. */
|
|
14
21
|
type DecoratorMetadata = Record<PropertyKey, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* The value stored in decorator metadata under `key`, created for this class
|
|
24
|
+
* from what a parent class has, if anything. The metadata object of a class
|
|
25
|
+
* inherits from that of its parent, so writing to an inherited value would
|
|
26
|
+
* change the parent.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ownMetadata<T>(metadata: DecoratorMetadata, key: symbol, create: (inherited?: T) => T): T;
|
|
29
|
+
/** The metadata of a decorator context, which has to have one. */
|
|
30
|
+
export declare function requireMetadata(context: {
|
|
31
|
+
metadata?: DecoratorMetadata;
|
|
32
|
+
}): DecoratorMetadata;
|
|
15
33
|
interface ModuleMetadata {
|
|
16
|
-
imports: ClassType
|
|
17
|
-
guards: ClassType
|
|
18
|
-
interceptors: ClassType
|
|
34
|
+
imports: ClassType[];
|
|
35
|
+
guards: ClassType[];
|
|
36
|
+
interceptors: ClassType[];
|
|
19
37
|
providers: Provider[];
|
|
20
38
|
attributes: Map<symbol, unknown>;
|
|
21
39
|
/**
|
|
@@ -24,14 +42,13 @@ interface ModuleMetadata {
|
|
|
24
42
|
*/
|
|
25
43
|
entries: Map<string, unknown>;
|
|
26
44
|
}
|
|
27
|
-
export declare function getModuleMetadata(target: ClassType
|
|
28
|
-
export declare function hasModuleMetadata(target: ClassType$1): boolean;
|
|
45
|
+
export declare function getModuleMetadata(target: ClassType): ModuleMetadata;
|
|
29
46
|
/**
|
|
30
47
|
* What decorators and `handler()` options can attach to a handler.
|
|
31
48
|
*/
|
|
32
49
|
interface HandlerExtras {
|
|
33
|
-
guards: ClassType
|
|
34
|
-
interceptors: ClassType
|
|
50
|
+
guards: ClassType[];
|
|
51
|
+
interceptors: ClassType[];
|
|
35
52
|
attributes: Map<symbol, unknown>;
|
|
36
53
|
}
|
|
37
54
|
/**
|
|
@@ -55,8 +72,8 @@ export declare function memberMetadata(context: {
|
|
|
55
72
|
}, name: string): MethodHandlerMetadata;
|
|
56
73
|
/** What a transport's decorator for handler classes may take. */
|
|
57
74
|
interface HandlerClassOptions {
|
|
58
|
-
guards?: Iterable<ClassType
|
|
59
|
-
interceptors?: Iterable<ClassType
|
|
75
|
+
guards?: Iterable<ClassType>;
|
|
76
|
+
interceptors?: Iterable<ClassType>;
|
|
60
77
|
attributes?: AttributeValue[];
|
|
61
78
|
}
|
|
62
79
|
/** A class that owns handlers: what applies to all of them, and its members. */
|
|
@@ -73,9 +90,36 @@ interface HandlerClassMetadata extends HandlerExtras {
|
|
|
73
90
|
export declare function describeHandlerClass(context: {
|
|
74
91
|
metadata?: DecoratorMetadata;
|
|
75
92
|
}, options?: HandlerClassOptions): HandlerClassMetadata;
|
|
93
|
+
/** What a class decorator stores on the class it decorates. */
|
|
94
|
+
interface ClassMetadata<T> {
|
|
95
|
+
/** Stores `value` on `target`, where it is not enumerable and can be replaced. */
|
|
96
|
+
define(target: ClassType, value: T): void;
|
|
97
|
+
/**
|
|
98
|
+
* What is stored on `target` itself. A subclass does not inherit it: it is
|
|
99
|
+
* not what the decorator makes of a class unless it is decorated itself.
|
|
100
|
+
* Throws when there is none.
|
|
101
|
+
*/
|
|
102
|
+
get(target: ClassType): T;
|
|
103
|
+
/** Whether `get` would find something. */
|
|
104
|
+
has(target: ClassType): boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Metadata that a class decorator stores on classes under `key`. `what` and
|
|
108
|
+
* `decorator` name it when a class has none: `Users is not a controller. Make
|
|
109
|
+
* sure it is decorated with @Controller.`
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* const queueHandlers = classMetadata<HandlerClassMetadata>(
|
|
113
|
+
* Symbol.for('my-transport.handlers'),
|
|
114
|
+
* 'a queue handler',
|
|
115
|
+
* 'QueueHandler',
|
|
116
|
+
* )
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function classMetadata<T>(key: symbol, what: string, decorator: string): ClassMetadata<T>;
|
|
76
120
|
interface Extras {
|
|
77
|
-
readonly guards: readonly ClassType
|
|
78
|
-
readonly interceptors: readonly ClassType
|
|
121
|
+
readonly guards: readonly ClassType[];
|
|
122
|
+
readonly interceptors: readonly ClassType[];
|
|
79
123
|
}
|
|
80
124
|
interface OwnExtras extends Extras {
|
|
81
125
|
readonly attributes: ReadonlyMap<symbol, unknown>;
|
|
@@ -85,28 +129,33 @@ interface HandlerChainInput {
|
|
|
85
129
|
* Interceptors around every handler of the application or of the transport,
|
|
86
130
|
* outermost first.
|
|
87
131
|
*/
|
|
88
|
-
application: readonly ClassType
|
|
132
|
+
application: readonly ClassType[];
|
|
89
133
|
/** The module the handler belongs to, with what it inherits. */
|
|
90
|
-
node: Extras & Pick<ModuleNode, 'module' | 'disputed'>;
|
|
134
|
+
node: Extras & Pick<ModuleNode, 'module' | 'attributes' | 'disputed'>;
|
|
91
135
|
/** The class that owns the handler. */
|
|
136
|
+
controller: ClassType;
|
|
137
|
+
/** What applies to every handler of `controller`. */
|
|
92
138
|
owner: OwnExtras;
|
|
139
|
+
/** The name of the handler in its class. */
|
|
140
|
+
handlerName: string;
|
|
93
141
|
/** The handler itself. */
|
|
94
142
|
member: OwnExtras;
|
|
95
143
|
}
|
|
96
144
|
interface HandlerChain {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
interceptors: ClassType$1[];
|
|
145
|
+
/** What the contexts of the handler tell about it. */
|
|
146
|
+
info: HandlerInfo;
|
|
100
147
|
/** Interceptors around the guards: those of the application. */
|
|
101
|
-
outer: ClassType
|
|
148
|
+
outer: ClassType[];
|
|
102
149
|
/** Interceptors inside the guards: those of the module, the class and the handler. */
|
|
103
|
-
inner: ClassType
|
|
150
|
+
inner: ClassType[];
|
|
104
151
|
}
|
|
105
152
|
/**
|
|
106
153
|
* The guards and interceptors that apply to one handler, in the order they
|
|
107
|
-
* run
|
|
108
|
-
*
|
|
109
|
-
*
|
|
154
|
+
* run, and what its contexts tell about it: the interceptors of the
|
|
155
|
+
* application, then the guards from the module chain, the owning class and
|
|
156
|
+
* the handler, then the interceptors of the same three. A class that appears
|
|
157
|
+
* twice is kept where it first appears. `info.guards` are the guards and
|
|
158
|
+
* `info.interceptors` the interceptors, `outer` and then `inner`.
|
|
110
159
|
*
|
|
111
160
|
* An interceptor of the application sees every execution, denied ones
|
|
112
161
|
* included, as tracing and logging need. One that is attached to handlers runs
|
|
@@ -115,39 +164,52 @@ interface HandlerChain {
|
|
|
115
164
|
* Throws when the handler would inherit an attribute that the importers of its
|
|
116
165
|
* module do not agree about.
|
|
117
166
|
*
|
|
118
|
-
* Every transport uses this, so the rule is the same everywhere.
|
|
119
|
-
*
|
|
167
|
+
* Every transport uses this, so the rule is the same everywhere.
|
|
168
|
+
* `resolveChain` resolves the chain and `runChain` runs it.
|
|
120
169
|
*/
|
|
121
170
|
export declare function handlerChain(input: HandlerChainInput): HandlerChain;
|
|
122
171
|
/** A handler's chain with its instances, ready to run. */
|
|
123
172
|
interface ResolvedChain<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {
|
|
124
173
|
readonly outer: ReadonlyArray<Interceptor<Ctx, Result>>;
|
|
125
174
|
readonly guards: ReadonlyArray<{
|
|
126
|
-
readonly type: ClassType
|
|
175
|
+
readonly type: ClassType;
|
|
127
176
|
readonly guard: Guard<Ctx>;
|
|
128
177
|
}>;
|
|
129
178
|
readonly inner: ReadonlyArray<Interceptor<Ctx, Result>>;
|
|
130
179
|
}
|
|
131
180
|
/**
|
|
132
|
-
* Resolves the classes of a chain. A transport
|
|
133
|
-
* while it is set up.
|
|
181
|
+
* Resolves the classes of a chain that `handlerChain` returned. A transport
|
|
182
|
+
* does this once per handler, while it is set up.
|
|
134
183
|
*/
|
|
135
|
-
export declare function resolveChain<Ctx extends ExecutionContext = ExecutionContext, Result = unknown>(container: Pick<Container, 'get'>, chain:
|
|
184
|
+
export declare function resolveChain<Ctx extends ExecutionContext = ExecutionContext, Result = unknown>(container: Pick<Container, 'get'>, chain: {
|
|
185
|
+
readonly info: Pick<HandlerInfo, 'guards'>;
|
|
186
|
+
readonly outer: readonly ClassType[];
|
|
187
|
+
readonly inner: readonly ClassType[];
|
|
188
|
+
}): Promise<ResolvedChain<Ctx, Result>>;
|
|
136
189
|
/**
|
|
137
190
|
* Runs a handler with what applies to it: the outer interceptors, the guards
|
|
138
191
|
* one after another, the inner interceptors, the handler. When a guard refuses,
|
|
139
192
|
* nothing further runs and `onDenied` says what becomes of the execution: what
|
|
140
193
|
* it returns is the result, and what it throws is the failure.
|
|
141
194
|
*/
|
|
142
|
-
export declare function runChain<Ctx extends ExecutionContext, Result>(ctx: Ctx, chain: ResolvedChain<Ctx, Result>, handler: () => Result | Promise<Result>, onDenied: (guard: ClassType
|
|
195
|
+
export declare function runChain<Ctx extends ExecutionContext, Result>(ctx: Ctx, chain: ResolvedChain<Ctx, Result>, handler: () => Result | Promise<Result>, onDenied: (guard: ClassType) => Result | Promise<Result>): Promise<Result>;
|
|
196
|
+
/**
|
|
197
|
+
* Runs a handler with what applies to it, as `runChain`, in the async context
|
|
198
|
+
* when the application keeps one, and then finishes its context, whatever the
|
|
199
|
+
* outcome. The context is finished inside the async context, so that
|
|
200
|
+
* `currentContext()` still answers in `onFinish` callbacks.
|
|
201
|
+
*/
|
|
202
|
+
export declare function executeChain<Ctx extends ExecutionContext & {
|
|
203
|
+
finish(): Promise<void>;
|
|
204
|
+
}, Result>(host: {
|
|
205
|
+
readonly asyncContext: boolean;
|
|
206
|
+
}, ctx: Ctx, chain: ResolvedChain<Ctx, Result>, handler: () => Result | Promise<Result>, onDenied: (guard: ClassType) => Result | Promise<Result>): Promise<Result>;
|
|
143
207
|
interface BasicExecutionContextInit {
|
|
144
208
|
/** The transport kind, for example `'cli'`. */
|
|
145
209
|
kind: string;
|
|
146
210
|
id: string;
|
|
147
211
|
handler: HandlerInfo;
|
|
148
212
|
host: ContextHost;
|
|
149
|
-
/** Defaults to a signal of the context's own that never aborts. */
|
|
150
|
-
signal?: AbortSignal;
|
|
151
213
|
}
|
|
152
214
|
/**
|
|
153
215
|
* An `ExecutionContext` for transports that need nothing beyond the neutral
|
|
@@ -159,7 +221,6 @@ export declare class BasicExecutionContext implements ExecutionContext {
|
|
|
159
221
|
readonly id: string;
|
|
160
222
|
readonly handler: HandlerInfo;
|
|
161
223
|
private readonly host;
|
|
162
|
-
private readonly givenSignal;
|
|
163
224
|
private ownSignal;
|
|
164
225
|
private slots;
|
|
165
226
|
private scope;
|
|
@@ -167,7 +228,10 @@ export declare class BasicExecutionContext implements ExecutionContext {
|
|
|
167
228
|
private finished;
|
|
168
229
|
private finishing;
|
|
169
230
|
constructor(init: BasicExecutionContextInit);
|
|
170
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* A signal that never aborts. Not shared between contexts: listeners would
|
|
233
|
+
* outlive their execution.
|
|
234
|
+
*/
|
|
171
235
|
get signal(): AbortSignal;
|
|
172
236
|
get<K extends ContextKey>(key: K): ContextValue<K>;
|
|
173
237
|
find<K extends ContextKey>(key: K): ContextValue<K> | undefined;
|
|
@@ -186,5 +250,5 @@ export declare class BasicExecutionContext implements ExecutionContext {
|
|
|
186
250
|
/** Runs a callback whose failure must not stop what follows. */
|
|
187
251
|
private runFinisher;
|
|
188
252
|
}
|
|
189
|
-
export { type
|
|
253
|
+
export { type BasicExecutionContextInit, type ClassMetadata, type ContextHost, type DecoratorMetadata, type HandlerChain, type HandlerChainInput, type HandlerClassMetadata, type HandlerClassOptions, type HandlerExtras, type MethodHandlerMetadata, type ModuleMetadata, type ModuleNode, type ResolvedChain, type TransportDefinition, type TransportHost, buildModuleGraph, constructedInstances, defineTransport, disposeScope, moduleClasses, needsScope, runInContext };
|
|
190
254
|
//# sourceMappingURL=transport.d.cts.map
|
package/lib/transport.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.cts","names":[
|
|
1
|
+
{"version":3,"file":"transport.d.cts","names":[],"sources":["../src/transports/settled-within.mts","../src/metadata/decorator-metadata.mts","../src/modules/module-metadata.mts","../src/metadata/member-metadata.mts","../src/metadata/handler-class.mts","../src/metadata/class-store.mts","../src/metadata/handler-chain.mts","../src/metadata/run-chain.mts","../src/execution/basic-execution-context.mts"],"mappings":";;;;;;;;;;;;;qBACa;;;;;wBAMS,cAAc,MAAM,sBAAsB,aAAa;;KCNjE,oBAAoB,OAAO;;;;;;;wBAQvB,YAAY,GAC1B,UAAU,mBACV,aACA,SAAS,YAAY,MAAM,IAC1B;;wBAQa,gBAAgB;EAAW,WAAW;IAAsB;UCN3D;EACf,SAAS;EACT,QAAQ;EACR,cAAc;EACd,WAAW;EACX,YAAY;;;;;EAKZ,SAAS;;wBAyFK,kBAAkB,QAAQ,YAAY;;;;UCzGrC;EACf,QAAQ;EACR,cAAc;EACd,YAAY;;;;;;UAOG,8BAA8B;EAC7C;;;;;EAKA,SAAS;;;;;;wBAUK,eACd;EAAW,WAAW;GACtB,eACC;;UCxBc;EACf,SAAS,SAAS;EAClB,eAAe,SAAS;EACxB,aAAa;;;UAIE,6BAA6B;;EAE5C,SAAS,YAAY;;;;;;;;wBASP,qBACd;EAAW,WAAW;GACtB,UAAS,sBACR;;UChCc,cAAc;;EAE7B,OAAO,QAAQ,WAAW,OAAO;;;;;;EAMjC,IAAI,QAAQ,YAAY;;EAExB,IAAI,QAAQ;;;;;;;;;;;;;;;wBAgBE,cAAc,GAAG,aAAa,cAAc,oBAAoB,cAAc;UCxBpF;WACC,iBAAiB;WACjB,uBAAuB;;UAGxB,kBAAkB;WACjB,YAAY;;UAGN;;;;;EAKf,sBAAsB;;EAEtB,MAAM,SAAS,KAAK;;EAEpB,YAAY;;EAEZ,OAAO;;EAEP;;EAEA,QAAQ;;UAGO;;EAEf,MAAM;;EAEN,OAAO;;EAEP,OAAO;;;;;;;;;;;;;;;;;;;;wBAqCO,aAAa,OAAO,oBAAoB;;UChEvC,cAAc,YAAY,mBAAmB,kBAAkB;WACrE,OAAO,cAAc,YAAY,KAAK;WACtC,QAAQ;aAAyB,MAAM;aAAoB,OAAO,MAAM;;WACxE,OAAO,cAAc,YAAY,KAAK;;;;;;wBAoB3B,aACpB,YAAY,mBAAmB,kBAC/B,kBAEA,WAAW,KAAK,mBAChB;WACW,MAAM,KAAK;WACX,gBAAgB;WAChB,gBAAgB;IAE1B,QAAQ,cAAc,KAAK;;;;;;;wBAoCd,SAAS,YAAY,kBAAkB,QACrD,KAAK,KACL,OAAO,cAAc,KAAK,SAC1B,eAAe,SAAS,QAAQ,SAChC,WAAW,OAAO,cAAc,SAAS,QAAQ,UAChD,QAAQ;;;;;;;wBAkBK,aAAa,YAAY;EAAqB,UAAU;GAAiB,QACvF;WAAiB;GACjB,KAAK,KACL,OAAO,cAAc,KAAK,SAC1B,eAAe,SAAS,QAAQ,SAChC,WAAW,OAAO,cAAc,SAAS,QAAQ,UAChD,QAAQ;UClGM;;EAEf;EACA;EACA,SAAS;EACT,MAAM;;;;;;;qBAQK,iCAAiC;WACnC;WACA;WACA,SAAS;mBACD;UACT;UACA;UACA;UACA;UACA;UACA;EAER,YAAY,MAAM;;;;;MAWd,UAAU;EAId,IAAI,UAAU,YAAY,KAAK,IAAI,aAAa;EAWhD,KAAK,UAAU,YAAY,KAAK,IAAI,aAAa;EAIjD,IAAI,UAAU,YAAY,KAAK,GAAG,OAAO,aAAa;EAItD,IAAI,KAAK;EA+BD,KAAK;EAEL,SAAS;EAEjB,SAAS,uBAAuB;;;;;;EAahC,UAAU;UAII;;UAeA"}
|