@antelopejs/interface-core 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/errors.d.ts +12 -0
  2. package/dist/errors.js +21 -1
  3. package/dist/errors.js.map +1 -1
  4. package/dist/index.d.ts +7 -9
  5. package/dist/index.js +91 -25
  6. package/dist/index.js.map +1 -1
  7. package/dist/internal.d.ts +87 -12
  8. package/dist/internal.js +108 -21
  9. package/dist/internal.js.map +1 -1
  10. package/dist/modules.d.ts +6 -0
  11. package/dist/modules.js +67 -28
  12. package/dist/modules.js.map +1 -1
  13. package/dist/proxies.d.ts +64 -129
  14. package/dist/proxies.js +372 -220
  15. package/dist/proxies.js.map +1 -1
  16. package/dist/runtime.js +2 -2
  17. package/dist/runtime.js.map +1 -1
  18. package/dist/tests/generation-cleanup.test.d.ts +1 -0
  19. package/dist/tests/generation-cleanup.test.js +116 -0
  20. package/dist/tests/generation-cleanup.test.js.map +1 -0
  21. package/dist/tests/implement-interface-validation.test.d.ts +1 -0
  22. package/dist/tests/implement-interface-validation.test.js +45 -0
  23. package/dist/tests/implement-interface-validation.test.js.map +1 -0
  24. package/dist/tests/interface-connections.test.d.ts +1 -0
  25. package/dist/tests/interface-connections.test.js +36 -0
  26. package/dist/tests/interface-connections.test.js.map +1 -0
  27. package/dist/tests/module-ownership-context.test.js +18 -0
  28. package/dist/tests/module-ownership-context.test.js.map +1 -1
  29. package/dist/tests/provider-context.test.d.ts +1 -0
  30. package/dist/tests/provider-context.test.js +117 -0
  31. package/dist/tests/provider-context.test.js.map +1 -0
  32. package/dist/tests/provider-routing.test.d.ts +1 -0
  33. package/dist/tests/provider-routing.test.js +78 -0
  34. package/dist/tests/provider-routing.test.js.map +1 -0
  35. package/dist/tests/queue-and-cleanup.test.d.ts +1 -0
  36. package/dist/tests/queue-and-cleanup.test.js +73 -0
  37. package/dist/tests/queue-and-cleanup.test.js.map +1 -0
  38. package/dist/tests/registering-proxy-replay.test.js +9 -0
  39. package/dist/tests/registering-proxy-replay.test.js.map +1 -1
  40. package/dist/tests/runtime-protocol.test.d.ts +1 -0
  41. package/dist/tests/runtime-protocol.test.js +49 -0
  42. package/dist/tests/runtime-protocol.test.js.map +1 -0
  43. package/dist/tests/runtime.test.js +18 -2
  44. package/dist/tests/runtime.test.js.map +1 -1
  45. package/docs/2.proxies.md +18 -1
  46. package/docs/5.modules.md +22 -0
  47. package/package.json +3 -2
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,6 @@
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";
2
4
  export declare const MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
3
5
  /**
4
6
  * Error emitted when a proxy is used without an attached provider in test
@@ -12,6 +14,16 @@ export declare class MissingProviderError extends Error {
12
14
  readonly code = "ERR_NO_PROVIDER";
13
15
  constructor(detail?: string);
14
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
+ }
15
27
  /**
16
28
  * Error emitted when work inherited ownership from a destroyed module.
17
29
  */
package/dist/errors.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModuleContextInvalidatedError = exports.MissingProviderError = exports.MODULE_CONTEXT_INVALIDATED_CODE = 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";
6
8
  exports.MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
7
9
  const MISSING_PROVIDER_MESSAGE = "Interface function called without implementation in test environment. " +
8
10
  "Ensure the required module is loaded in your test config.";
@@ -22,6 +24,24 @@ class MissingProviderError extends Error {
22
24
  }
23
25
  }
24
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;
25
45
  /**
26
46
  * Error emitted when work inherited ownership from a destroyed module.
27
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAyDA,wDAOC;AAhEY,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAC1C,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;;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"}
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;A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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,10 @@
1
1
  import "reflect-metadata";
2
2
  import type { Class } from "./decorators";
3
- import { EventProxy, RegisteringProxy } from "./proxies";
3
+ import { type InterfaceConnection } from "./internal";
4
+ import { AsyncProxy, type EventProxy, type RegisteringProxy } from "./proxies";
4
5
  export * from "./errors";
5
- export { AsyncProxy, EventProxy, GetResponsibleModule, RegisteringProxy, RunWithResponsibleModule, } from "./proxies";
6
+ export type { InterfaceConnection } from "./internal";
7
+ export { AsyncProxy, EventProxy, GetInterfaceProxyIdentity, GetResponsibleModule, IsInterfaceProxy, RegisteringProxy, RunWithResponsibleModule, } from "./proxies";
6
8
  /**
7
9
  * Gets metadata for a target object using the specified metadata class.
8
10
  *
@@ -26,12 +28,12 @@ type Func<A extends any[] = any[], R = any> = (...args: A) => R;
26
28
  *
27
29
  * @returns A function that proxies calls to the implementation when available
28
30
  */
29
- export declare function InterfaceFunction<T extends Func = Func, R = Awaited<ReturnType<T>>>(): (...args: Parameters<T>) => Promise<R>;
31
+ export declare function InterfaceFunction<T extends Func = Func, R = Awaited<ReturnType<T>>>(identity?: string): (...args: Parameters<T>) => Promise<R>;
30
32
  type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
31
33
  type InterfaceImplType<T> = T extends RegisteringProxy<infer P> ? {
32
34
  register: P;
33
35
  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;
36
+ } : 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
37
  type InterfaceToImpl<T> = T extends infer P ? {
36
38
  [K in keyof P]?: InterfaceImplType<P[K]>;
37
39
  } : never;
@@ -52,14 +54,10 @@ export declare function ImplementInterface<T extends Record<string, unknown>, T2
52
54
  /**
53
55
  * @deprecated Please use the non-async version of this function.
54
56
  */
55
- export declare function ImplementInterface<T extends Record<string, unknown>, T2 extends InterfaceToImpl<T>>(declaration: T | Promise<T>, implementation: T2 | Promise<T2>): Promise<{
57
+ export declare function ImplementInterface<T extends Record<string, unknown>, T2 extends InterfaceToImpl<T>>(declaration: T | PromiseLike<T>, implementation: T2 | PromiseLike<T2>): Promise<{
56
58
  declaration: Awaited<T>;
57
59
  implementation: T2;
58
60
  }>;
59
- interface InterfaceConnection {
60
- id?: string;
61
- path: string;
62
- }
63
61
  /**
64
62
  * Gets all instances of a specific interface across the system.
65
63
  *
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.RunWithResponsibleModule = 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,7 +28,9 @@ __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; } });
33
35
  Object.defineProperty(exports, "RunWithResponsibleModule", { enumerable: true, get: function () { return proxies_2.RunWithResponsibleModule; } });
34
36
  internal_1.internal.asyncContextReporter = (trace) => {
@@ -84,42 +86,107 @@ function GetMetadata(target, meta, inherit = true) {
84
86
  *
85
87
  * @returns A function that proxies calls to the implementation when available
86
88
  */
87
- function InterfaceFunction() {
88
- const proxy = new proxies_1.AsyncProxy();
89
+ function InterfaceFunction(identity) {
90
+ const proxy = new proxies_1.AsyncProxy(identity);
89
91
  const func = (...args) => proxy.call(...args);
90
92
  func.proxy = proxy;
91
93
  return func;
92
94
  }
93
- function implement(decl, impl) {
94
- for (const key in decl) {
95
- if (key in impl) {
96
- const val = decl[key];
97
- if (val instanceof proxies_1.RegisteringProxy) {
98
- val.onRegister(impl[key].register);
99
- val.onUnregister(impl[key].unregister);
100
- }
101
- else if (typeof val === "function" && val.proxy instanceof proxies_1.AsyncProxy) {
102
- val.proxy.onCall(impl[key]);
103
- }
104
- else if (val instanceof proxies_1.AsyncProxy) {
105
- val.onCall(impl[key]);
106
- }
107
- else if (!(val instanceof proxies_1.EventProxy)) {
108
- implement(val, impl[key]);
109
- }
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}.`);
110
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}.`);
111
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");
112
179
  }
113
180
  function ImplementInterface(declaration, implementation) {
114
- if (declaration instanceof Promise || implementation instanceof Promise) {
181
+ if (isThenable(declaration) || isThenable(implementation)) {
115
182
  return Promise.all([declaration, implementation]).then(([decl, impl]) => {
116
- implement(decl, impl);
183
+ attachImplementation(decl, impl);
117
184
  return { declaration: decl, implementation: impl };
118
185
  });
119
186
  }
120
187
  const decl = declaration;
121
188
  const impl = implementation;
122
- implement(decl, impl);
189
+ attachImplementation(decl, impl);
123
190
  return { declaration: decl, implementation: impl };
124
191
  }
125
192
  /**
@@ -134,8 +201,7 @@ function GetInterfaceInstances(interfaceID) {
134
201
  const module = (0, proxies_1.GetResponsibleModule)();
135
202
  if (!module || !(module in internal_1.internal.interfaceConnections))
136
203
  return [];
137
- const connections = internal_1.internal.interfaceConnections[module];
138
- return connections[interfaceID] ?? [];
204
+ return internal_1.internal.interfaceConnections[module][interfaceID] ?? [];
139
205
  }
140
206
  /**
141
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":";;;;;;;;;;;;;;;;;AA8CA,kCAuBC;AAYD,8CAQC;AAgED,gDAmBC;AAeD,sDAOC;AAWD,oDAUC;AAvND,4BAA0B;AAE1B,yCAAsC;AACtC,uCAAoC;AACpC,uCAKmB;AAEnB,2CAAyB;AACzB,qCAMmB;AALjB,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AACV,+GAAA,oBAAoB,OAAA;AACpB,2GAA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AAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,mBAAQ,CAAC,oBAAoB,CAAC;QAAE,OAAO,EAAE,CAAC;IACrE,OAAO,mBAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;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"}
@@ -1,21 +1,96 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export declare const RUNTIME_PROTOCOL_VERSION = 3;
3
+ export declare const RUNTIME_SYMBOL: unique symbol;
4
+ /** Provider connection metadata visible to an interface consumer. */
1
5
  export interface InterfaceConnection {
6
+ /** Optional connection alias. */
2
7
  id?: string;
8
+ /** Resolved interface package path. */
3
9
  path: string;
10
+ /** Module ID of the provider represented by this connection. */
11
+ provider: string;
12
+ /** Whether this provider is selected for unqualified interface calls. */
13
+ selected: boolean;
4
14
  }
5
- /** @internal */
6
- export declare const internal: {
7
- moduleByFolder: {
15
+ /** Module identity and provider routes propagated through asynchronous work. */
16
+ export interface ModuleExecutionContext {
17
+ /** Stable module ID used by existing lifecycle and attribution APIs. */
18
+ module: string;
19
+ /** Unique lifecycle generation ID. Defaults to the module ID when omitted. */
20
+ owner?: string;
21
+ /** Provider ID used when attaching implementations. */
22
+ provider?: string;
23
+ /** Provider selections keyed by stable interface proxy identity. */
24
+ providerRoutes?: Readonly<Record<string, string>>;
25
+ }
26
+ interface ActiveModuleExecutionContext extends ModuleExecutionContext {
27
+ owner: string;
28
+ ownershipToken: symbol;
29
+ }
30
+ export interface ProxyBrand {
31
+ protocol: number;
32
+ kind: "async" | "registering" | "event";
33
+ identity: string;
34
+ }
35
+ export interface RuntimeProxyState {
36
+ kind: ProxyBrand["kind"];
37
+ value: unknown;
38
+ }
39
+ export interface RuntimeCleanup {
40
+ cleanup(): void;
41
+ unregisterModule?(module: string): void;
42
+ }
43
+ export interface RuntimeErrorDetails {
44
+ operation: string;
45
+ module?: string;
46
+ proxyIdentity?: string;
47
+ registrationId?: unknown;
48
+ }
49
+ export interface InterfaceRuntime {
50
+ protocol: number;
51
+ moduleByFolder: Array<{
8
52
  dir: string;
9
53
  id: string;
10
54
  isImplementor?: boolean;
11
- }[];
55
+ }>;
12
56
  testStubMode: boolean;
13
- knownAsync: Map<string, any[]>;
14
- knownRegisters: Map<string, any[]>;
15
- knownEvents: any[];
57
+ knownAsync: Map<string, Set<RuntimeCleanup | {
58
+ detach(): void;
59
+ }>>;
60
+ knownRegisters: Map<string, Set<RuntimeCleanup | {
61
+ detach(): void;
62
+ }>>;
63
+ registeringProxies: Set<{
64
+ unregisterModule(module: string): void;
65
+ unregisterOwner(owner: string): void;
66
+ }>;
67
+ knownEvents: Set<{
68
+ unregisterModule(module: string): void;
69
+ unregisterOwner(owner: string): void;
70
+ }>;
16
71
  interfaceConnections: Record<string, Record<string, InterfaceConnection[]>>;
17
- asyncContextReporter: ((trace: NodeJS.CallSite[]) => void) | undefined;
18
- replayErrorReporter: ((id: unknown, err: unknown) => void) | undefined;
19
- addAsyncProxy(module: string, proxy: any): void;
20
- addRegisteringProxy(module: string, proxy: any): void;
21
- };
72
+ executionContext: AsyncLocalStorage<ActiveModuleExecutionContext>;
73
+ activeOwnerTokens: Map<string, symbol>;
74
+ proxyStates: Map<string, RuntimeProxyState>;
75
+ nextProxyIdentity: number;
76
+ nextLeaseGeneration: number;
77
+ maxPendingOperations: number;
78
+ asyncContextReporter?: (trace: NodeJS.CallSite[]) => void;
79
+ runtimeErrorReporter?: (error: unknown, details: RuntimeErrorDetails) => void;
80
+ replayErrorReporter?: (id: unknown, error: unknown) => void;
81
+ addAsyncProxy(module: string, proxy: RuntimeCleanup | {
82
+ detach(): void;
83
+ }): void;
84
+ addRegisteringProxy(module: string, proxy: RuntimeCleanup | {
85
+ detach(): void;
86
+ }): void;
87
+ }
88
+ /** @internal */
89
+ export declare const internal: InterfaceRuntime;
90
+ export declare function runWithModuleContext<T>(context: ModuleExecutionContext, callback: () => T): T;
91
+ export declare function captureModuleContext(): ActiveModuleExecutionContext | undefined;
92
+ export declare function runWithCapturedModuleContext<T>(context: ActiveModuleExecutionContext, callback: () => T): T;
93
+ export declare function peekModuleContext(): ModuleExecutionContext | undefined;
94
+ export declare function getModuleContext(): ModuleExecutionContext | undefined;
95
+ export declare function invalidateModuleContext(owner: string): void;
96
+ export {};
package/dist/internal.js CHANGED
@@ -1,27 +1,114 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.internal = void 0;
4
- function addToMapArray(map, key, value) {
5
- if (!map.has(key)) {
6
- map.set(key, []);
3
+ exports.internal = exports.RUNTIME_SYMBOL = exports.RUNTIME_PROTOCOL_VERSION = void 0;
4
+ exports.runWithModuleContext = runWithModuleContext;
5
+ exports.captureModuleContext = captureModuleContext;
6
+ exports.runWithCapturedModuleContext = runWithCapturedModuleContext;
7
+ exports.peekModuleContext = peekModuleContext;
8
+ exports.getModuleContext = getModuleContext;
9
+ exports.invalidateModuleContext = invalidateModuleContext;
10
+ const node_async_hooks_1 = require("node:async_hooks");
11
+ const errors_1 = require("./errors");
12
+ exports.RUNTIME_PROTOCOL_VERSION = 3;
13
+ exports.RUNTIME_SYMBOL = Symbol.for("@antelopejs/interface-core/runtime");
14
+ function addToMapSet(map, key, value) {
15
+ const values = map.get(key) ?? new Set();
16
+ values.add(value);
17
+ map.set(key, values);
18
+ }
19
+ function createRuntime() {
20
+ const runtime = {
21
+ protocol: exports.RUNTIME_PROTOCOL_VERSION,
22
+ moduleByFolder: [],
23
+ testStubMode: false,
24
+ knownAsync: new Map(),
25
+ knownRegisters: new Map(),
26
+ registeringProxies: new Set(),
27
+ knownEvents: new Set(),
28
+ interfaceConnections: Object.create(null),
29
+ executionContext: new node_async_hooks_1.AsyncLocalStorage(),
30
+ activeOwnerTokens: new Map(),
31
+ proxyStates: new Map(),
32
+ nextProxyIdentity: 1,
33
+ nextLeaseGeneration: 1,
34
+ maxPendingOperations: 1_000,
35
+ addAsyncProxy(module, proxy) {
36
+ addToMapSet(runtime.knownAsync, module, proxy);
37
+ },
38
+ addRegisteringProxy(module, proxy) {
39
+ addToMapSet(runtime.knownRegisters, module, proxy);
40
+ },
41
+ };
42
+ return runtime;
43
+ }
44
+ function getRuntime() {
45
+ const globals = globalThis;
46
+ const existing = globals[exports.RUNTIME_SYMBOL];
47
+ if (existing && existing.protocol !== exports.RUNTIME_PROTOCOL_VERSION) {
48
+ throw new Error(`Incompatible @antelopejs/interface-core runtime protocol: expected ${exports.RUNTIME_PROTOCOL_VERSION}, received ${existing.protocol}`);
7
49
  }
8
- map.get(key)?.push(value);
50
+ if (existing) {
51
+ return existing;
52
+ }
53
+ const runtime = createRuntime();
54
+ Object.defineProperty(globals, exports.RUNTIME_SYMBOL, {
55
+ configurable: false,
56
+ enumerable: false,
57
+ writable: false,
58
+ value: runtime,
59
+ });
60
+ return runtime;
9
61
  }
10
62
  /** @internal */
11
- exports.internal = {
12
- moduleByFolder: [],
13
- testStubMode: false,
14
- knownAsync: new Map(),
15
- knownRegisters: new Map(),
16
- knownEvents: [],
17
- interfaceConnections: {},
18
- asyncContextReporter: undefined,
19
- replayErrorReporter: undefined,
20
- addAsyncProxy(module, proxy) {
21
- addToMapArray(exports.internal.knownAsync, module, proxy);
22
- },
23
- addRegisteringProxy(module, proxy) {
24
- addToMapArray(exports.internal.knownRegisters, module, proxy);
25
- },
26
- };
63
+ exports.internal = getRuntime();
64
+ function getOwnerToken(owner) {
65
+ const activeToken = exports.internal.activeOwnerTokens.get(owner);
66
+ if (activeToken) {
67
+ return activeToken;
68
+ }
69
+ const token = Symbol(owner);
70
+ exports.internal.activeOwnerTokens.set(owner, token);
71
+ return token;
72
+ }
73
+ function assertActiveModuleContext(context) {
74
+ if (exports.internal.activeOwnerTokens.get(context.owner) !== context.ownershipToken) {
75
+ throw new errors_1.ModuleContextInvalidatedError(context.module);
76
+ }
77
+ }
78
+ function runWithModuleContext(context, callback) {
79
+ const inheritedContext = exports.internal.executionContext.getStore();
80
+ if (inheritedContext) {
81
+ assertActiveModuleContext(inheritedContext);
82
+ }
83
+ if (!context.module) {
84
+ throw new Error("Module execution context requires a module ID.");
85
+ }
86
+ const owner = context.owner ?? context.module;
87
+ const activeContext = {
88
+ ...context,
89
+ owner,
90
+ ownershipToken: getOwnerToken(owner),
91
+ };
92
+ return exports.internal.executionContext.run(activeContext, callback);
93
+ }
94
+ function captureModuleContext() {
95
+ const context = exports.internal.executionContext.getStore();
96
+ if (context) {
97
+ assertActiveModuleContext(context);
98
+ }
99
+ return context;
100
+ }
101
+ function runWithCapturedModuleContext(context, callback) {
102
+ assertActiveModuleContext(context);
103
+ return exports.internal.executionContext.run(context, callback);
104
+ }
105
+ function peekModuleContext() {
106
+ return exports.internal.executionContext.getStore();
107
+ }
108
+ function getModuleContext() {
109
+ return captureModuleContext();
110
+ }
111
+ function invalidateModuleContext(owner) {
112
+ exports.internal.activeOwnerTokens.delete(owner);
113
+ }
27
114
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;;AAKA,SAAS,aAAa,CAAC,GAA4B,EAAE,GAAW,EAAE,KAAU;IAC1E,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EA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Aa,GAAG;QACpB,GAAG,OAAO;QACV,KAAK;QACL,cAAc,EAAE,aAAa,CAAC,KAAK,CAAC;KACrC,CAAC;IACF,OAAO,gBAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC;AAED,SAAgB,oBAAoB;IAGlC,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,4BAA4B,CAC1C,OAAqC,EACrC,QAAiB;IAEjB,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACnC,OAAO,gBAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,iBAAiB;IAC/B,OAAO,gBAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,oBAAoB,EAAE,CAAC;AAChC,CAAC;AAED,SAAgB,uBAAuB,CAAC,KAAa;IACnD,gBAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3C,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
  *