@antelopejs/interface-core 0.0.8 → 0.0.10
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/dist/errors.d.ts +20 -0
- package/dist/errors.js +33 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +92 -25
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +68 -12
- package/dist/internal.js +93 -21
- package/dist/internal.js.map +1 -1
- package/dist/modules.d.ts +6 -0
- package/dist/modules.js +58 -25
- package/dist/modules.js.map +1 -1
- package/dist/proxies.d.ts +58 -119
- package/dist/proxies.js +298 -184
- package/dist/proxies.js.map +1 -1
- package/dist/runtime.js +2 -2
- package/dist/runtime.js.map +1 -1
- package/dist/tests/implement-interface-validation.test.d.ts +1 -0
- package/dist/tests/implement-interface-validation.test.js +45 -0
- package/dist/tests/implement-interface-validation.test.js.map +1 -0
- package/dist/tests/module-ownership-context.test.d.ts +1 -0
- package/dist/tests/module-ownership-context.test.js +215 -0
- package/dist/tests/module-ownership-context.test.js.map +1 -0
- package/dist/tests/provider-routing.test.d.ts +1 -0
- package/dist/tests/provider-routing.test.js +78 -0
- package/dist/tests/provider-routing.test.js.map +1 -0
- package/dist/tests/queue-and-cleanup.test.d.ts +1 -0
- package/dist/tests/queue-and-cleanup.test.js +73 -0
- package/dist/tests/queue-and-cleanup.test.js.map +1 -0
- package/dist/tests/registering-proxy-replay.test.js +9 -0
- package/dist/tests/registering-proxy-replay.test.js.map +1 -1
- package/dist/tests/runtime-protocol.test.d.ts +1 -0
- package/dist/tests/runtime-protocol.test.js +45 -0
- package/dist/tests/runtime-protocol.test.js.map +1 -0
- package/dist/tests/runtime.test.js +18 -2
- package/dist/tests/runtime.test.js.map +1 -1
- package/docs/2.proxies.md +18 -1
- package/package.json +1 -1
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const MISSING_PROVIDER_CODE = "ERR_NO_PROVIDER";
|
|
2
|
+
export declare const AMBIGUOUS_PROVIDER_CODE = "ERR_AMBIGUOUS_PROVIDER";
|
|
3
|
+
export declare const PROVIDER_QUEUE_FULL_CODE = "ERR_PROVIDER_QUEUE_FULL";
|
|
4
|
+
export declare const MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
2
5
|
/**
|
|
3
6
|
* Error emitted when a proxy is used without an attached provider in test
|
|
4
7
|
* stub mode.
|
|
@@ -11,6 +14,23 @@ export declare class MissingProviderError extends Error {
|
|
|
11
14
|
readonly code = "ERR_NO_PROVIDER";
|
|
12
15
|
constructor(detail?: string);
|
|
13
16
|
}
|
|
17
|
+
/** Error emitted when a call cannot be routed between multiple providers. */
|
|
18
|
+
export declare class AmbiguousProviderError extends Error {
|
|
19
|
+
readonly code = "ERR_AMBIGUOUS_PROVIDER";
|
|
20
|
+
constructor(proxyIdentity: string, providers: string[]);
|
|
21
|
+
}
|
|
22
|
+
/** Error emitted when an unattached proxy's bounded queue is full. */
|
|
23
|
+
export declare class ProviderQueueFullError extends Error {
|
|
24
|
+
readonly code = "ERR_PROVIDER_QUEUE_FULL";
|
|
25
|
+
constructor(proxyIdentity: string, limit: number);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error emitted when work inherited ownership from a destroyed module.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ModuleContextInvalidatedError extends Error {
|
|
31
|
+
readonly code = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
32
|
+
constructor(module: string);
|
|
33
|
+
}
|
|
14
34
|
/**
|
|
15
35
|
* Type guard for {@link MissingProviderError}.
|
|
16
36
|
*
|
package/dist/errors.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingProviderError = exports.MISSING_PROVIDER_CODE = void 0;
|
|
3
|
+
exports.ModuleContextInvalidatedError = exports.ProviderQueueFullError = exports.AmbiguousProviderError = exports.MissingProviderError = exports.MODULE_CONTEXT_INVALIDATED_CODE = exports.PROVIDER_QUEUE_FULL_CODE = exports.AMBIGUOUS_PROVIDER_CODE = exports.MISSING_PROVIDER_CODE = void 0;
|
|
4
4
|
exports.isMissingProviderError = isMissingProviderError;
|
|
5
5
|
exports.MISSING_PROVIDER_CODE = "ERR_NO_PROVIDER";
|
|
6
|
+
exports.AMBIGUOUS_PROVIDER_CODE = "ERR_AMBIGUOUS_PROVIDER";
|
|
7
|
+
exports.PROVIDER_QUEUE_FULL_CODE = "ERR_PROVIDER_QUEUE_FULL";
|
|
8
|
+
exports.MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
6
9
|
const MISSING_PROVIDER_MESSAGE = "Interface function called without implementation in test environment. " +
|
|
7
10
|
"Ensure the required module is loaded in your test config.";
|
|
8
11
|
/**
|
|
@@ -21,6 +24,35 @@ class MissingProviderError extends Error {
|
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
exports.MissingProviderError = MissingProviderError;
|
|
27
|
+
/** Error emitted when a call cannot be routed between multiple providers. */
|
|
28
|
+
class AmbiguousProviderError extends Error {
|
|
29
|
+
code = exports.AMBIGUOUS_PROVIDER_CODE;
|
|
30
|
+
constructor(proxyIdentity, providers) {
|
|
31
|
+
super(`Interface proxy ${proxyIdentity} has multiple providers (${providers.join(", ")}); run the call in a module execution context with an explicit provider route.`);
|
|
32
|
+
this.name = "AmbiguousProviderError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.AmbiguousProviderError = AmbiguousProviderError;
|
|
36
|
+
/** Error emitted when an unattached proxy's bounded queue is full. */
|
|
37
|
+
class ProviderQueueFullError extends Error {
|
|
38
|
+
code = exports.PROVIDER_QUEUE_FULL_CODE;
|
|
39
|
+
constructor(proxyIdentity, limit) {
|
|
40
|
+
super(`Interface proxy ${proxyIdentity} has ${limit} pending operations without a provider.`);
|
|
41
|
+
this.name = "ProviderQueueFullError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ProviderQueueFullError = ProviderQueueFullError;
|
|
45
|
+
/**
|
|
46
|
+
* Error emitted when work inherited ownership from a destroyed module.
|
|
47
|
+
*/
|
|
48
|
+
class ModuleContextInvalidatedError extends Error {
|
|
49
|
+
code = exports.MODULE_CONTEXT_INVALIDATED_CODE;
|
|
50
|
+
constructor(module) {
|
|
51
|
+
super(`Module context has been invalidated: ${module}`);
|
|
52
|
+
this.name = "ModuleContextInvalidatedError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ModuleContextInvalidatedError = ModuleContextInvalidatedError;
|
|
24
56
|
/**
|
|
25
57
|
* Whether the value is an error, including one built in another realm.
|
|
26
58
|
*
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAmFA,wDAOC;AA1FY,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAC1C,QAAA,uBAAuB,GAAG,wBAAwB,CAAC;AACnD,QAAA,wBAAwB,GAAG,yBAAyB,CAAC;AACrD,QAAA,+BAA+B,GAAG,gCAAgC,CAAC;AAEhF,MAAM,wBAAwB,GAC5B,wEAAwE;IACxE,2DAA2D,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAC7B,IAAI,GAAG,6BAAqB,CAAC;IAE7C,YAAmB,MAAe;QAChC,KAAK,CAAC,MAAM,IAAI,wBAAwB,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAPD,oDAOC;AAED,6EAA6E;AAC7E,MAAa,sBAAuB,SAAQ,KAAK;IAC/B,IAAI,GAAG,+BAAuB,CAAC;IAE/C,YAAmB,aAAqB,EAAE,SAAmB;QAC3D,KAAK,CACH,mBAAmB,aAAa,4BAA4B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,gFAAgF,CACjK,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AATD,wDASC;AAED,sEAAsE;AACtE,MAAa,sBAAuB,SAAQ,KAAK;IAC/B,IAAI,GAAG,gCAAwB,CAAC;IAEhD,YAAmB,aAAqB,EAAE,KAAa;QACrD,KAAK,CACH,mBAAmB,aAAa,QAAQ,KAAK,yCAAyC,CACvF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AATD,wDASC;AAED;;GAEG;AACH,MAAa,6BAA8B,SAAQ,KAAK;IACtC,IAAI,GAAG,uCAA+B,CAAC;IAEvD,YAAmB,MAAc;QAC/B,KAAK,CAAC,wCAAwC,MAAM,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC9C,CAAC;CACF;AAPD,sEAOC;AAED;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,gBAAgB;QAC1D,KAAK,YAAY,KAAK,CACvB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,OAAO,CACL,OAAO,CAAC,KAAK,CAAC;QACb,KAA8B,CAAC,IAAI,KAAK,6BAAqB,CAC/D,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import type { Class } from "./decorators";
|
|
3
|
-
import { EventProxy, RegisteringProxy } from "./proxies";
|
|
3
|
+
import { AsyncProxy, type EventProxy, type RegisteringProxy } from "./proxies";
|
|
4
4
|
export * from "./errors";
|
|
5
|
-
export { AsyncProxy, EventProxy, GetResponsibleModule, RegisteringProxy, } from "./proxies";
|
|
5
|
+
export { AsyncProxy, EventProxy, GetInterfaceProxyIdentity, GetResponsibleModule, IsInterfaceProxy, RegisteringProxy, RunWithResponsibleModule, } from "./proxies";
|
|
6
6
|
/**
|
|
7
7
|
* Gets metadata for a target object using the specified metadata class.
|
|
8
8
|
*
|
|
@@ -26,12 +26,12 @@ type Func<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
|
26
26
|
*
|
|
27
27
|
* @returns A function that proxies calls to the implementation when available
|
|
28
28
|
*/
|
|
29
|
-
export declare function InterfaceFunction<T extends Func = Func, R = Awaited<ReturnType<T>>>(): (...args: Parameters<T>) => Promise<R>;
|
|
29
|
+
export declare function InterfaceFunction<T extends Func = Func, R = Awaited<ReturnType<T>>>(identity?: string): (...args: Parameters<T>) => Promise<R>;
|
|
30
30
|
type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
|
|
31
31
|
type InterfaceImplType<T> = T extends RegisteringProxy<infer P> ? {
|
|
32
32
|
register: P;
|
|
33
33
|
unregister: (id: RID<P>) => void;
|
|
34
|
-
} : T extends EventProxy ? never : T extends (...args: infer A) => infer R ? (...args: A) => Awaited<R> | R : T extends Record<string, any> ? InterfaceToImpl<T> : never;
|
|
34
|
+
} : T extends AsyncProxy<infer P> ? P : T extends EventProxy ? never : T extends (...args: infer A) => infer R ? (...args: A) => Awaited<R> | R : T extends Record<string, any> ? InterfaceToImpl<T> : never;
|
|
35
35
|
type InterfaceToImpl<T> = T extends infer P ? {
|
|
36
36
|
[K in keyof P]?: InterfaceImplType<P[K]>;
|
|
37
37
|
} : never;
|
|
@@ -52,7 +52,7 @@ export declare function ImplementInterface<T extends Record<string, unknown>, T2
|
|
|
52
52
|
/**
|
|
53
53
|
* @deprecated Please use the non-async version of this function.
|
|
54
54
|
*/
|
|
55
|
-
export declare function ImplementInterface<T extends Record<string, unknown>, T2 extends InterfaceToImpl<T>>(declaration: T |
|
|
55
|
+
export declare function ImplementInterface<T extends Record<string, unknown>, T2 extends InterfaceToImpl<T>>(declaration: T | PromiseLike<T>, implementation: T2 | PromiseLike<T2>): Promise<{
|
|
56
56
|
declaration: Awaited<T>;
|
|
57
57
|
implementation: T2;
|
|
58
58
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.RegisteringProxy = exports.GetResponsibleModule = exports.EventProxy = exports.AsyncProxy = void 0;
|
|
17
|
+
exports.RunWithResponsibleModule = exports.RegisteringProxy = exports.IsInterfaceProxy = exports.GetResponsibleModule = exports.GetInterfaceProxyIdentity = exports.EventProxy = exports.AsyncProxy = void 0;
|
|
18
18
|
exports.GetMetadata = GetMetadata;
|
|
19
19
|
exports.InterfaceFunction = InterfaceFunction;
|
|
20
20
|
exports.ImplementInterface = ImplementInterface;
|
|
@@ -28,8 +28,11 @@ __exportStar(require("./errors"), exports);
|
|
|
28
28
|
var proxies_2 = require("./proxies");
|
|
29
29
|
Object.defineProperty(exports, "AsyncProxy", { enumerable: true, get: function () { return proxies_2.AsyncProxy; } });
|
|
30
30
|
Object.defineProperty(exports, "EventProxy", { enumerable: true, get: function () { return proxies_2.EventProxy; } });
|
|
31
|
+
Object.defineProperty(exports, "GetInterfaceProxyIdentity", { enumerable: true, get: function () { return proxies_2.GetInterfaceProxyIdentity; } });
|
|
31
32
|
Object.defineProperty(exports, "GetResponsibleModule", { enumerable: true, get: function () { return proxies_2.GetResponsibleModule; } });
|
|
33
|
+
Object.defineProperty(exports, "IsInterfaceProxy", { enumerable: true, get: function () { return proxies_2.IsInterfaceProxy; } });
|
|
32
34
|
Object.defineProperty(exports, "RegisteringProxy", { enumerable: true, get: function () { return proxies_2.RegisteringProxy; } });
|
|
35
|
+
Object.defineProperty(exports, "RunWithResponsibleModule", { enumerable: true, get: function () { return proxies_2.RunWithResponsibleModule; } });
|
|
33
36
|
internal_1.internal.asyncContextReporter = (trace) => {
|
|
34
37
|
const lastSite = trace[trace.length - 1];
|
|
35
38
|
if (lastSite?.getFileName() !== "node:internal/timers") {
|
|
@@ -83,42 +86,107 @@ function GetMetadata(target, meta, inherit = true) {
|
|
|
83
86
|
*
|
|
84
87
|
* @returns A function that proxies calls to the implementation when available
|
|
85
88
|
*/
|
|
86
|
-
function InterfaceFunction() {
|
|
87
|
-
const proxy = new proxies_1.AsyncProxy();
|
|
89
|
+
function InterfaceFunction(identity) {
|
|
90
|
+
const proxy = new proxies_1.AsyncProxy(identity);
|
|
88
91
|
const func = (...args) => proxy.call(...args);
|
|
89
92
|
func.proxy = proxy;
|
|
90
93
|
return func;
|
|
91
94
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
val.onCall(impl[key]);
|
|
105
|
-
}
|
|
106
|
-
else if (!(val instanceof proxies_1.EventProxy)) {
|
|
107
|
-
implement(val, impl[key]);
|
|
108
|
-
}
|
|
95
|
+
function isObject(value) {
|
|
96
|
+
return typeof value === "object" && value !== null;
|
|
97
|
+
}
|
|
98
|
+
function assertAcyclic(value, label) {
|
|
99
|
+
const visited = new WeakSet();
|
|
100
|
+
const active = new WeakSet();
|
|
101
|
+
const visit = (current, path) => {
|
|
102
|
+
if (!isObject(current) || visited.has(current)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (active.has(current)) {
|
|
106
|
+
throw new TypeError(`${label} contains a cycle at ${path}.`);
|
|
109
107
|
}
|
|
108
|
+
active.add(current);
|
|
109
|
+
for (const [key, child] of Object.entries(current)) {
|
|
110
|
+
visit(child, `${path}.${key}`);
|
|
111
|
+
}
|
|
112
|
+
active.delete(current);
|
|
113
|
+
visited.add(current);
|
|
114
|
+
};
|
|
115
|
+
visit(value, label);
|
|
116
|
+
}
|
|
117
|
+
function requireFunction(value, path) {
|
|
118
|
+
if (typeof value !== "function") {
|
|
119
|
+
throw new TypeError(`Missing or malformed interface handler at ${path}.`);
|
|
110
120
|
}
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
function planProxyAttachment(proxy, implementation, path) {
|
|
124
|
+
if ((0, proxies_1.IsInterfaceProxy)(proxy, "event")) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if ((0, proxies_1.IsInterfaceProxy)(proxy, "async")) {
|
|
128
|
+
const callback = requireFunction(implementation, path);
|
|
129
|
+
return {
|
|
130
|
+
attach: () => proxy.onCall(callback),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (!(0, proxies_1.IsInterfaceProxy)(proxy, "registering")) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!isObject(implementation)) {
|
|
137
|
+
throw new TypeError(`Missing or malformed interface handler at ${path}.`);
|
|
138
|
+
}
|
|
139
|
+
const register = requireFunction(implementation.register, `${path}.register`);
|
|
140
|
+
const unregister = requireFunction(implementation.unregister, `${path}.unregister`);
|
|
141
|
+
return {
|
|
142
|
+
attach: () => proxy.onHandlers(register, unregister),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function createAttachmentPlan(declaration, implementation, path = "implementation") {
|
|
146
|
+
const plans = [];
|
|
147
|
+
for (const [key, declared] of Object.entries(declaration)) {
|
|
148
|
+
const implemented = implementation[key];
|
|
149
|
+
const proxy = typeof declared === "function" && "proxy" in declared
|
|
150
|
+
? declared.proxy
|
|
151
|
+
: declared;
|
|
152
|
+
const proxyPlan = planProxyAttachment(proxy, implemented, `${path}.${key}`);
|
|
153
|
+
if (proxyPlan) {
|
|
154
|
+
plans.push(proxyPlan);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (isObject(declared) && !(0, proxies_1.IsInterfaceProxy)(declared)) {
|
|
158
|
+
const nestedImplementation = isObject(implemented) ? implemented : {};
|
|
159
|
+
plans.push(...createAttachmentPlan(declared, nestedImplementation, `${path}.${key}`));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return plans;
|
|
163
|
+
}
|
|
164
|
+
function attachImplementation(declaration, implementation) {
|
|
165
|
+
if (!isObject(declaration) || !isObject(implementation)) {
|
|
166
|
+
throw new TypeError("Interface declaration and implementation must be objects.");
|
|
167
|
+
}
|
|
168
|
+
assertAcyclic(declaration, "declaration");
|
|
169
|
+
assertAcyclic(implementation, "implementation");
|
|
170
|
+
const plans = createAttachmentPlan(declaration, implementation);
|
|
171
|
+
plans.forEach((plan) => {
|
|
172
|
+
plan.attach();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function isThenable(value) {
|
|
176
|
+
return ((typeof value === "object" || typeof value === "function") &&
|
|
177
|
+
value !== null &&
|
|
178
|
+
typeof value.then === "function");
|
|
111
179
|
}
|
|
112
180
|
function ImplementInterface(declaration, implementation) {
|
|
113
|
-
if (declaration
|
|
181
|
+
if (isThenable(declaration) || isThenable(implementation)) {
|
|
114
182
|
return Promise.all([declaration, implementation]).then(([decl, impl]) => {
|
|
115
|
-
|
|
183
|
+
attachImplementation(decl, impl);
|
|
116
184
|
return { declaration: decl, implementation: impl };
|
|
117
185
|
});
|
|
118
186
|
}
|
|
119
187
|
const decl = declaration;
|
|
120
188
|
const impl = implementation;
|
|
121
|
-
|
|
189
|
+
attachImplementation(decl, impl);
|
|
122
190
|
return { declaration: decl, implementation: impl };
|
|
123
191
|
}
|
|
124
192
|
/**
|
|
@@ -133,8 +201,7 @@ function GetInterfaceInstances(interfaceID) {
|
|
|
133
201
|
const module = (0, proxies_1.GetResponsibleModule)();
|
|
134
202
|
if (!module || !(module in internal_1.internal.interfaceConnections))
|
|
135
203
|
return [];
|
|
136
|
-
|
|
137
|
-
return connections[interfaceID] ?? [];
|
|
204
|
+
return internal_1.internal.interfaceConnections[module][interfaceID] ?? [];
|
|
138
205
|
}
|
|
139
206
|
/**
|
|
140
207
|
* Gets a specific instance of an interface by ID.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAiDA,kCAuBC;AAYD,8CAQC;AAoLD,gDAmBC;AAeD,sDAMC;AAWD,oDAUC;AA7UD,4BAA0B;AAE1B,yCAAsC;AACtC,uCAAoC;AACpC,uCAMmB;AAEnB,2CAAyB;AACzB,qCAQmB;AAPjB,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AACV,oHAAA,yBAAyB,OAAA;AACzB,+GAAA,oBAAoB,OAAA;AACpB,2GAAA,gBAAgB,OAAA;AAChB,2GAAA,gBAAgB,OAAA;AAChB,mHAAA,wBAAwB,OAAA;AAG1B,mBAAQ,CAAC,oBAAoB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,QAAQ,EAAE,WAAW,EAAE,KAAK,sBAAsB,EAAE,CAAC;QACvD,OAAO;IACT,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK;SACnB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;SACnE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC9B,IAAI,CAAC,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C;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,WAAmB,EACnB,YAAoB;IAEpB,MAAM,MAAM,GAAG,IAAA,8BAAoB,GAAE,CAAC;IACtC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,mBAAQ,CAAC,oBAAoB,CAAC;QAAE,OAAO;IAClE,MAAM,WAAW,GAAG,mBAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAC1C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,YAAY,CAC/C,CAAC;AACJ,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,21 +1,77 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
export declare const RUNTIME_PROTOCOL_VERSION = 2;
|
|
3
|
+
export declare const RUNTIME_SYMBOL: unique symbol;
|
|
1
4
|
export interface InterfaceConnection {
|
|
2
5
|
id?: string;
|
|
3
6
|
path: string;
|
|
4
7
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
export interface ModuleExecutionContext {
|
|
9
|
+
module: string;
|
|
10
|
+
provider?: string;
|
|
11
|
+
providerRoutes?: Readonly<Record<string, string>>;
|
|
12
|
+
}
|
|
13
|
+
interface ActiveModuleExecutionContext extends ModuleExecutionContext {
|
|
14
|
+
ownershipToken: symbol;
|
|
15
|
+
}
|
|
16
|
+
export interface ProxyBrand {
|
|
17
|
+
protocol: number;
|
|
18
|
+
kind: "async" | "registering" | "event";
|
|
19
|
+
identity: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RuntimeProxyState {
|
|
22
|
+
kind: ProxyBrand["kind"];
|
|
23
|
+
value: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface RuntimeCleanup {
|
|
26
|
+
cleanup(): void;
|
|
27
|
+
unregisterModule?(module: string): void;
|
|
28
|
+
}
|
|
29
|
+
export interface RuntimeErrorDetails {
|
|
30
|
+
operation: string;
|
|
31
|
+
module?: string;
|
|
32
|
+
proxyIdentity?: string;
|
|
33
|
+
registrationId?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface InterfaceRuntime {
|
|
36
|
+
protocol: number;
|
|
37
|
+
moduleByFolder: Array<{
|
|
8
38
|
dir: string;
|
|
9
39
|
id: string;
|
|
10
40
|
isImplementor?: boolean;
|
|
11
|
-
}
|
|
41
|
+
}>;
|
|
12
42
|
testStubMode: boolean;
|
|
13
|
-
knownAsync: Map<string,
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
knownAsync: Map<string, Set<RuntimeCleanup | {
|
|
44
|
+
detach(): void;
|
|
45
|
+
}>>;
|
|
46
|
+
knownRegisters: Map<string, Set<RuntimeCleanup | {
|
|
47
|
+
detach(): void;
|
|
48
|
+
}>>;
|
|
49
|
+
registeringProxies: Set<{
|
|
50
|
+
unregisterModule(module: string): void;
|
|
51
|
+
}>;
|
|
52
|
+
knownEvents: Set<{
|
|
53
|
+
unregisterModule(module: string): void;
|
|
54
|
+
}>;
|
|
16
55
|
interfaceConnections: Record<string, Record<string, InterfaceConnection[]>>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
56
|
+
executionContext: AsyncLocalStorage<ActiveModuleExecutionContext>;
|
|
57
|
+
activeModuleTokens: Map<string, symbol>;
|
|
58
|
+
proxyStates: Map<string, RuntimeProxyState>;
|
|
59
|
+
nextProxyIdentity: number;
|
|
60
|
+
nextLeaseGeneration: number;
|
|
61
|
+
maxPendingOperations: number;
|
|
62
|
+
asyncContextReporter?: (trace: NodeJS.CallSite[]) => void;
|
|
63
|
+
runtimeErrorReporter?: (error: unknown, details: RuntimeErrorDetails) => void;
|
|
64
|
+
replayErrorReporter?: (id: unknown, error: unknown) => void;
|
|
65
|
+
addAsyncProxy(module: string, proxy: RuntimeCleanup | {
|
|
66
|
+
detach(): void;
|
|
67
|
+
}): void;
|
|
68
|
+
addRegisteringProxy(module: string, proxy: RuntimeCleanup | {
|
|
69
|
+
detach(): void;
|
|
70
|
+
}): void;
|
|
71
|
+
}
|
|
72
|
+
/** @internal */
|
|
73
|
+
export declare const internal: InterfaceRuntime;
|
|
74
|
+
export declare function runWithModuleContext<T>(context: ModuleExecutionContext, callback: () => T): T;
|
|
75
|
+
export declare function getModuleContext(): ModuleExecutionContext | undefined;
|
|
76
|
+
export declare function invalidateModuleContext(module: string): void;
|
|
77
|
+
export {};
|
package/dist/internal.js
CHANGED
|
@@ -1,27 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.internal = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.internal = exports.RUNTIME_SYMBOL = exports.RUNTIME_PROTOCOL_VERSION = void 0;
|
|
4
|
+
exports.runWithModuleContext = runWithModuleContext;
|
|
5
|
+
exports.getModuleContext = getModuleContext;
|
|
6
|
+
exports.invalidateModuleContext = invalidateModuleContext;
|
|
7
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
exports.RUNTIME_PROTOCOL_VERSION = 2;
|
|
10
|
+
exports.RUNTIME_SYMBOL = Symbol.for("@antelopejs/interface-core/runtime");
|
|
11
|
+
function addToMapSet(map, key, value) {
|
|
12
|
+
const values = map.get(key) ?? new Set();
|
|
13
|
+
values.add(value);
|
|
14
|
+
map.set(key, values);
|
|
15
|
+
}
|
|
16
|
+
function createRuntime() {
|
|
17
|
+
const runtime = {
|
|
18
|
+
protocol: exports.RUNTIME_PROTOCOL_VERSION,
|
|
19
|
+
moduleByFolder: [],
|
|
20
|
+
testStubMode: false,
|
|
21
|
+
knownAsync: new Map(),
|
|
22
|
+
knownRegisters: new Map(),
|
|
23
|
+
registeringProxies: new Set(),
|
|
24
|
+
knownEvents: new Set(),
|
|
25
|
+
interfaceConnections: Object.create(null),
|
|
26
|
+
executionContext: new node_async_hooks_1.AsyncLocalStorage(),
|
|
27
|
+
activeModuleTokens: new Map(),
|
|
28
|
+
proxyStates: new Map(),
|
|
29
|
+
nextProxyIdentity: 1,
|
|
30
|
+
nextLeaseGeneration: 1,
|
|
31
|
+
maxPendingOperations: 1_000,
|
|
32
|
+
addAsyncProxy(module, proxy) {
|
|
33
|
+
addToMapSet(runtime.knownAsync, module, proxy);
|
|
34
|
+
},
|
|
35
|
+
addRegisteringProxy(module, proxy) {
|
|
36
|
+
addToMapSet(runtime.knownRegisters, module, proxy);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return runtime;
|
|
40
|
+
}
|
|
41
|
+
function getRuntime() {
|
|
42
|
+
const globals = globalThis;
|
|
43
|
+
const existing = globals[exports.RUNTIME_SYMBOL];
|
|
44
|
+
if (existing && existing.protocol !== exports.RUNTIME_PROTOCOL_VERSION) {
|
|
45
|
+
throw new Error(`Incompatible @antelopejs/interface-core runtime protocol: expected ${exports.RUNTIME_PROTOCOL_VERSION}, received ${existing.protocol}`);
|
|
7
46
|
}
|
|
8
|
-
|
|
47
|
+
if (existing) {
|
|
48
|
+
return existing;
|
|
49
|
+
}
|
|
50
|
+
const runtime = createRuntime();
|
|
51
|
+
Object.defineProperty(globals, exports.RUNTIME_SYMBOL, {
|
|
52
|
+
configurable: false,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
writable: false,
|
|
55
|
+
value: runtime,
|
|
56
|
+
});
|
|
57
|
+
return runtime;
|
|
9
58
|
}
|
|
10
59
|
/** @internal */
|
|
11
|
-
exports.internal =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
60
|
+
exports.internal = getRuntime();
|
|
61
|
+
function getModuleToken(module) {
|
|
62
|
+
const activeToken = exports.internal.activeModuleTokens.get(module);
|
|
63
|
+
if (activeToken) {
|
|
64
|
+
return activeToken;
|
|
65
|
+
}
|
|
66
|
+
const token = Symbol(module);
|
|
67
|
+
exports.internal.activeModuleTokens.set(module, token);
|
|
68
|
+
return token;
|
|
69
|
+
}
|
|
70
|
+
function assertActiveModuleContext(context) {
|
|
71
|
+
if (exports.internal.activeModuleTokens.get(context.module) !== context.ownershipToken) {
|
|
72
|
+
throw new errors_1.ModuleContextInvalidatedError(context.module);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function runWithModuleContext(context, callback) {
|
|
76
|
+
const inheritedContext = exports.internal.executionContext.getStore();
|
|
77
|
+
if (inheritedContext) {
|
|
78
|
+
assertActiveModuleContext(inheritedContext);
|
|
79
|
+
}
|
|
80
|
+
if (!context.module) {
|
|
81
|
+
throw new Error("Module execution context requires a module ID.");
|
|
82
|
+
}
|
|
83
|
+
const activeContext = {
|
|
84
|
+
...context,
|
|
85
|
+
ownershipToken: getModuleToken(context.module),
|
|
86
|
+
};
|
|
87
|
+
return exports.internal.executionContext.run(activeContext, callback);
|
|
88
|
+
}
|
|
89
|
+
function getModuleContext() {
|
|
90
|
+
const context = exports.internal.executionContext.getStore();
|
|
91
|
+
if (context) {
|
|
92
|
+
assertActiveModuleContext(context);
|
|
93
|
+
}
|
|
94
|
+
return context;
|
|
95
|
+
}
|
|
96
|
+
function invalidateModuleContext(module) {
|
|
97
|
+
exports.internal.activeModuleTokens.delete(module);
|
|
98
|
+
}
|
|
27
99
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings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AC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED,SAAgB,oBAAoB,CAClC,OAA+B,EAC/B,QAAiB;IAEjB,MAAM,gBAAgB,GAAG,gBAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;IAC9D,IAAI,gBAAgB,EAAE,CAAC;QACrB,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,aAAa,GAAG;QACpB,GAAG,OAAO;QACV,cAAc,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;KAC/C,CAAC;IACF,OAAO,gBAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC;AAED,SAAgB,gBAAgB;IAC9B,MAAM,OAAO,GAAG,gBAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;IACrD,IAAI,OAAO,EAAE,CAAC;QACZ,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,uBAAuB,CAAC,MAAc;IACpD,gBAAQ,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/modules.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { EventProxy } from ".";
|
|
2
|
+
import { type ModuleExecutionContext } from "./internal";
|
|
3
|
+
/** Runs work with module ownership and an optional provider route across awaits. */
|
|
4
|
+
export declare function RunWithModuleContext<T>(context: ModuleExecutionContext, callback: () => T): T;
|
|
5
|
+
/** Returns the active module execution context, if one exists. */
|
|
6
|
+
export declare function GetModuleContext(): ModuleExecutionContext | undefined;
|
|
7
|
+
export type { ModuleExecutionContext } from "./internal";
|
|
2
8
|
/**
|
|
3
9
|
* Contains events related to module lifecycle management.
|
|
4
10
|
*
|