@antelopejs/interface-core 0.0.9 → 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.
Files changed (36) 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 +5 -5
  5. package/dist/index.js +91 -25
  6. package/dist/index.js.map +1 -1
  7. package/dist/internal.d.ts +68 -12
  8. package/dist/internal.js +93 -21
  9. package/dist/internal.js.map +1 -1
  10. package/dist/modules.d.ts +6 -0
  11. package/dist/modules.js +58 -27
  12. package/dist/modules.js.map +1 -1
  13. package/dist/proxies.d.ts +55 -129
  14. package/dist/proxies.js +287 -215
  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/implement-interface-validation.test.d.ts +1 -0
  19. package/dist/tests/implement-interface-validation.test.js +45 -0
  20. package/dist/tests/implement-interface-validation.test.js.map +1 -0
  21. package/dist/tests/module-ownership-context.test.js +18 -0
  22. package/dist/tests/module-ownership-context.test.js.map +1 -1
  23. package/dist/tests/provider-routing.test.d.ts +1 -0
  24. package/dist/tests/provider-routing.test.js +78 -0
  25. package/dist/tests/provider-routing.test.js.map +1 -0
  26. package/dist/tests/queue-and-cleanup.test.d.ts +1 -0
  27. package/dist/tests/queue-and-cleanup.test.js +73 -0
  28. package/dist/tests/queue-and-cleanup.test.js.map +1 -0
  29. package/dist/tests/registering-proxy-replay.test.js +9 -0
  30. package/dist/tests/registering-proxy-replay.test.js.map +1 -1
  31. package/dist/tests/runtime-protocol.test.d.ts +1 -0
  32. package/dist/tests/runtime-protocol.test.js +45 -0
  33. package/dist/tests/runtime-protocol.test.js.map +1 -0
  34. package/dist/tests/runtime.test.js +18 -2
  35. package/dist/tests/runtime.test.js.map +1 -1
  36. package/package.json +1 -1
package/dist/modules.js CHANGED
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReloadModule = exports.DestroyModule = exports.StopModule = exports.StartModule = exports.LoadModule = exports.GetModuleInfo = exports.ListModules = exports.Events = void 0;
4
+ exports.RunWithModuleContext = RunWithModuleContext;
5
+ exports.GetModuleContext = GetModuleContext;
4
6
  const _1 = require(".");
5
7
  const internal_1 = require("./internal");
6
- const proxies_1 = require("./proxies");
8
+ /** Runs work with module ownership and an optional provider route across awaits. */
9
+ function RunWithModuleContext(context, callback) {
10
+ return (0, internal_1.runWithModuleContext)(context, callback);
11
+ }
12
+ /** Returns the active module execution context, if one exists. */
13
+ function GetModuleContext() {
14
+ return (0, internal_1.getModuleContext)();
15
+ }
7
16
  /**
8
17
  * Contains events related to module lifecycle management.
9
18
  *
@@ -20,7 +29,7 @@ var Events;
20
29
  *
21
30
  * @param module Module ID
22
31
  */
23
- Events.ModuleConstructed = new _1.EventProxy();
32
+ Events.ModuleConstructed = new _1.EventProxy("modules.ModuleConstructed");
24
33
  /**
25
34
  * Event triggers when a module is started.
26
35
  *
@@ -29,7 +38,7 @@ var Events;
29
38
  *
30
39
  * @param module Module ID
31
40
  */
32
- Events.ModuleStarted = new _1.EventProxy();
41
+ Events.ModuleStarted = new _1.EventProxy("modules.ModuleStarted");
33
42
  /**
34
43
  * Event triggers when a module is stopped.
35
44
  *
@@ -38,7 +47,7 @@ var Events;
38
47
  *
39
48
  * @param module Module ID
40
49
  */
41
- Events.ModuleStopped = new _1.EventProxy();
50
+ Events.ModuleStopped = new _1.EventProxy("modules.ModuleStopped");
42
51
  /**
43
52
  * Event triggers when a module is destroyed.
44
53
  *
@@ -47,30 +56,52 @@ var Events;
47
56
  *
48
57
  * @param module Module ID
49
58
  */
50
- Events.ModuleDestroyed = new _1.EventProxy();
59
+ Events.ModuleDestroyed = new _1.EventProxy("modules.ModuleDestroyed");
51
60
  })(Events || (exports.Events = Events = {}));
52
- // Using the Events namespace from modules.ts instead of the lowercase events
53
- Events.ModuleDestroyed.register((module) => {
54
- (0, proxies_1.InvalidateResponsibleModule)(module);
55
- if (internal_1.internal.knownAsync.has(module)) {
56
- for (const proxy of internal_1.internal.knownAsync.get(module) ?? []) {
57
- proxy.detach();
61
+ function runCleanup(cleanup, module, operation) {
62
+ try {
63
+ if ("cleanup" in cleanup) {
64
+ cleanup.cleanup();
58
65
  }
59
- internal_1.internal.knownAsync.delete(module);
60
- }
61
- if (internal_1.internal.knownRegisters.has(module)) {
62
- for (const proxy of internal_1.internal.knownRegisters.get(module) ?? []) {
63
- proxy.detach();
66
+ else {
67
+ cleanup.detach();
64
68
  }
65
- internal_1.internal.knownRegisters.delete(module);
66
69
  }
67
- for (const [, proxies] of internal_1.internal.knownRegisters) {
68
- for (const proxy of proxies) {
70
+ catch (error) {
71
+ internal_1.internal.runtimeErrorReporter?.(error, { operation, module });
72
+ }
73
+ }
74
+ Events.ModuleDestroyed.register((module) => {
75
+ (0, internal_1.invalidateModuleContext)(module);
76
+ for (const cleanup of internal_1.internal.knownAsync.get(module) ?? []) {
77
+ runCleanup(cleanup, module, "detach-async-provider");
78
+ }
79
+ internal_1.internal.knownAsync.delete(module);
80
+ for (const cleanup of internal_1.internal.knownRegisters.get(module) ?? []) {
81
+ runCleanup(cleanup, module, "detach-registering-provider");
82
+ }
83
+ internal_1.internal.knownRegisters.delete(module);
84
+ for (const proxy of internal_1.internal.registeringProxies) {
85
+ try {
69
86
  proxy.unregisterModule(module);
70
87
  }
88
+ catch (error) {
89
+ internal_1.internal.runtimeErrorReporter?.(error, {
90
+ operation: "unregister-module",
91
+ module,
92
+ });
93
+ }
71
94
  }
72
95
  for (const proxy of internal_1.internal.knownEvents) {
73
- proxy.unregisterModule(module);
96
+ try {
97
+ proxy.unregisterModule(module);
98
+ }
99
+ catch (error) {
100
+ internal_1.internal.runtimeErrorReporter?.(error, {
101
+ operation: "unregister-event-module",
102
+ module,
103
+ });
104
+ }
74
105
  }
75
106
  });
76
107
  /**
@@ -81,7 +112,7 @@ Events.ModuleDestroyed.register((module) => {
81
112
  *
82
113
  * @returns Array of module IDs
83
114
  */
84
- exports.ListModules = (0, _1.InterfaceFunction)();
115
+ exports.ListModules = (0, _1.InterfaceFunction)("modules.ListModules");
85
116
  /**
86
117
  * Retrieve the configuration and status information of a loaded module.
87
118
  *
@@ -91,7 +122,7 @@ exports.ListModules = (0, _1.InterfaceFunction)();
91
122
  * @param module The module ID to get information for
92
123
  * @returns Complete module information object
93
124
  */
94
- exports.GetModuleInfo = (0, _1.InterfaceFunction)();
125
+ exports.GetModuleInfo = (0, _1.InterfaceFunction)("modules.GetModuleInfo");
95
126
  /**
96
127
  * Load a new module with the given ID and configuration.
97
128
  *
@@ -102,7 +133,7 @@ exports.GetModuleInfo = (0, _1.InterfaceFunction)();
102
133
  * @param configuration Module configuration including source information
103
134
  * @param autostart Whether to automatically start the module after loading (default: false)
104
135
  */
105
- exports.LoadModule = (0, _1.InterfaceFunction)();
136
+ exports.LoadModule = (0, _1.InterfaceFunction)("modules.LoadModule");
106
137
  /**
107
138
  * Start a loaded but inactive module.
108
139
  *
@@ -112,7 +143,7 @@ exports.LoadModule = (0, _1.InterfaceFunction)();
112
143
  * @param module The module ID to start
113
144
  * @throws Error if the module is not loaded or cannot be started
114
145
  */
115
- exports.StartModule = (0, _1.InterfaceFunction)();
146
+ exports.StartModule = (0, _1.InterfaceFunction)("modules.StartModule");
116
147
  /**
117
148
  * Stop an active module.
118
149
  *
@@ -122,7 +153,7 @@ exports.StartModule = (0, _1.InterfaceFunction)();
122
153
  * @param module The module ID to stop
123
154
  * @throws Error if the module is not loaded or cannot be stopped
124
155
  */
125
- exports.StopModule = (0, _1.InterfaceFunction)();
156
+ exports.StopModule = (0, _1.InterfaceFunction)("modules.StopModule");
126
157
  /**
127
158
  * Destroy a stopped module.
128
159
  *
@@ -132,7 +163,7 @@ exports.StopModule = (0, _1.InterfaceFunction)();
132
163
  * @param module The module ID to destroy
133
164
  * @throws Error if the module is active or not loaded
134
165
  */
135
- exports.DestroyModule = (0, _1.InterfaceFunction)();
166
+ exports.DestroyModule = (0, _1.InterfaceFunction)("modules.DestroyModule");
136
167
  /**
137
168
  * Unload a module and retrigger its source mechanism.
138
169
  *
@@ -143,5 +174,5 @@ exports.DestroyModule = (0, _1.InterfaceFunction)();
143
174
  * @param module The module ID to reload
144
175
  * @throws Error if the module cannot be reloaded
145
176
  */
146
- exports.ReloadModule = (0, _1.InterfaceFunction)();
177
+ exports.ReloadModule = (0, _1.InterfaceFunction)("modules.ReloadModule");
147
178
  //# sourceMappingURL=modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":";;;AAAA,wBAAkD;AAClD,yCAAsC;AACtC,uCAAwD;AAExD;;;;;GAKG;AACH,IAAiB,MAAM,CAwCtB;AAxCD,WAAiB,MAAM;IACrB;;;;;;;OAOG;IACU,wBAAiB,GAAG,IAAI,aAAU,EAA4B,CAAC;IAE5E;;;;;;;OAOG;IACU,oBAAa,GAAG,IAAI,aAAU,EAA4B,CAAC;IAExE;;;;;;;OAOG;IACU,oBAAa,GAAG,IAAI,aAAU,EAA4B,CAAC;IAExE;;;;;;;OAOG;IACU,sBAAe,GAAG,IAAI,aAAU,EAA4B,CAAC;AAC5E,CAAC,EAxCgB,MAAM,sBAAN,MAAM,QAwCtB;AAED,6EAA6E;AAC7E,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE;IACzC,IAAA,qCAA2B,EAAC,MAAM,CAAC,CAAC;IACpC,IAAI,mBAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,KAAK,MAAM,KAAK,IAAI,mBAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1D,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,CAAC;QACD,mBAAQ,CAAC,UAAU,CAAC,MAAM,CAAC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oBAAiB,EAC5C,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;GASG;AACU,QAAA,UAAU,GACrB,IAAA,oBAAiB,EAMf,oBAAoB,CAAC,CAAC;AAE1B;;;;;;;;GAQG;AACU,QAAA,WAAW,GAAG,IAAA,oBAAiB,EAC1C,qBAAqB,CACtB,CAAC;AAEF;;;;;;;;GAQG;AACU,QAAA,UAAU,GACrB,IAAA,oBAAiB,EAA2B,oBAAoB,CAAC,CAAC;AAEpE;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,IAAA,oBAAiB,EAC5C,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,IAAA,oBAAiB,EAC3C,sBAAsB,CACvB,CAAC"}
package/dist/proxies.d.ts CHANGED
@@ -1,148 +1,74 @@
1
+ import { type ProxyBrand } from "./internal";
1
2
  type Func<A extends any[] = any[], R = any> = (...args: A) => R;
3
+ type RegisterFunction = (id: any, ...args: any[]) => void;
4
+ type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
5
+ type RArgs<T> = T extends (id: any, ...args: infer P) => void ? P : never;
6
+ type ProxyKind = ProxyBrand["kind"];
7
+ declare const PROXY_BRAND: unique symbol;
8
+ export interface AttachmentLease {
9
+ generation: number;
10
+ owner: string;
11
+ provider: string;
12
+ }
13
+ /** Returns whether a value implements this runtime's stable proxy protocol. */
14
+ export declare function IsInterfaceProxy(value: unknown, kind?: ProxyKind): boolean;
15
+ /** Returns the stable identity used to bind a proxy to a provider route. */
16
+ export declare function GetInterfaceProxyIdentity(value: unknown): string | undefined;
2
17
  /** @internal */
3
18
  export declare function InvalidateResponsibleModule(module: string): void;
4
- /**
5
- * Runs work with an explicit responsible module.
6
- *
7
- * The module remains available to nested synchronous and asynchronous work.
8
- * Calls outside this context continue to use stack-based module resolution.
9
- *
10
- * @param module Module ID responsible for the work
11
- * @param callback Work to run in the module context
12
- * @returns The callback result
13
- */
19
+ /** Runs work with explicit module ownership across asynchronous boundaries. */
14
20
  export declare function RunWithResponsibleModule<T>(module: string, callback: () => T): T;
15
- /**
16
- * Proxy for an asynchronous function.
17
- *
18
- * Queues up calls while unattached, automatically unattaches when the source module is unloaded.
19
- * Provides a mechanism for delayed execution and module-aware function binding.
20
- */
21
+ /** Proxy for an asynchronous interface function. */
21
22
  export declare class AsyncProxy<T extends Func = Func, R = Awaited<ReturnType<T>>> {
22
- private callback?;
23
- private queue;
24
- /**
25
- * Attaches a callback to the proxy
26
- *
27
- * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
28
- * When attached, any queued calls will be executed immediately.
29
- *
30
- * @param callback Function to attach
31
- * @param manualDetach Don't detach automatically when module is unloaded
32
- */
33
- onCall(callback: T, manualDetach?: boolean): void;
34
- /**
35
- * Manually detach the callback on this proxy.
36
- */
37
- detach(): void;
38
- /**
39
- * Call the function attached to this proxy.
40
- *
41
- * If a callback has not been attached yet, the call is queued up for later.
42
- */
23
+ readonly [PROXY_BRAND]: ProxyBrand;
24
+ private readonly state;
25
+ constructor(identity?: string);
26
+ /** Attaches a provider callback and replays compatible queued calls. */
27
+ onCall(callback: T, manualDetach?: boolean): AttachmentLease;
28
+ /** Detaches one leased provider, or every provider when called without a lease. */
29
+ detach(lease?: AttachmentLease): void;
30
+ /** Calls the provider selected by the current module execution context. */
43
31
  call(...args: Parameters<T>): Promise<R>;
32
+ private invoke;
33
+ private replayQueue;
44
34
  }
45
- type RegisterFunction = (id: any, ...args: any[]) => void;
46
- type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
47
- type RArgs<T> = T extends (id: any, ...args: infer P) => void ? P : never;
48
- /**
49
- * Proxy for a pair of register/unregister functions.
50
- *
51
- * Manages registration of handlers and ensures proper cleanup when modules are unloaded.
52
- * This allows for module-aware event registration with automatic cleanup.
53
- */
35
+ /** Proxy for provider-aware register and unregister handlers. */
54
36
  export declare class RegisteringProxy<T extends RegisterFunction = RegisterFunction> {
55
- private registerCallback?;
56
- private unregisterCallback?;
57
- private registered;
58
- /**
59
- * Attaches a register callback to the proxy
60
- *
61
- * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
62
- *
63
- * @param callback Function to attach as the register callback
64
- * @param manualDetach Don't detach automatically
65
- */
66
- onRegister(callback: T, manualDetach?: boolean): void;
67
- /**
68
- * Attaches an unregister callback to the proxy
69
- *
70
- * Detached at the same time as the register callback.
71
- *
72
- * @param callback Function to attach as the unregister callback
73
- */
74
- onUnregister(callback: (id: RID<T>) => void): void;
75
- /**
76
- * Manually detach the callbacks on this proxy.
77
- */
78
- detach(): void;
79
- /**
80
- * Call the register callback attached to this proxy.
81
- *
82
- * If a callback has not been attached yet, the call is queued up for later.
83
- *
84
- * @param id Unique identifier used to unregister
85
- * @param args Extra arguments
86
- */
37
+ readonly [PROXY_BRAND]: ProxyBrand;
38
+ private readonly state;
39
+ constructor(identity?: string);
40
+ /** Attaches a register callback. */
41
+ onRegister(callback: T, manualDetach?: boolean): AttachmentLease;
42
+ /** Attaches an unregister callback to the current provider route. */
43
+ onUnregister(callback: (id: RID<T>) => void): AttachmentLease;
44
+ /** Atomically attaches both registration handlers. */
45
+ onHandlers(register: T, unregister: (id: RID<T>) => void, manualDetach?: boolean): AttachmentLease;
46
+ /** Detaches one leased provider, or every provider when called without a lease. */
47
+ detach(lease?: AttachmentLease): void;
48
+ /** Registers an entry with the selected provider or queues it for bootstrap. */
87
49
  register(id: RID<T>, ...args: RArgs<T>): void;
88
- /**
89
- * Call the unregister callback attached to this proxy.
90
- *
91
- * @param id Unique identifier to unregister
92
- */
50
+ /** Unregisters an entry from the provider that accepted it. */
93
51
  unregister(id: RID<T>): void;
94
- /**
95
- * Unregister all entries created by the given module
96
- * @internal
97
- *
98
- * @param mod Module ID
99
- */
100
- unregisterModule(mod: string): void;
52
+ /** Unregisters every entry owned by a destroyed module. */
53
+ unregisterModule(module: string): void;
54
+ private attachHandlers;
55
+ private replayRegistrations;
101
56
  }
102
57
  type EventFunction = (...args: any[]) => void;
103
- /**
104
- * Event handler list that automatically removes handlers from unloaded modules.
105
- *
106
- * Provides a module-aware event system that cleans up event handlers when modules are unloaded,
107
- * preventing memory leaks and ensuring proper modularity.
108
- */
58
+ /** Module-aware event handler collection. */
109
59
  export declare class EventProxy<T extends EventFunction = EventFunction> {
110
- private registered;
111
- constructor();
112
- /**
113
- * Call all the event handlers with the specified arguments.
114
- *
115
- * @param args Arguments
116
- */
60
+ readonly [PROXY_BRAND]: ProxyBrand;
61
+ private readonly state;
62
+ constructor(identity?: string);
63
+ /** Emits to every handler, reporting failures without aborting later handlers. */
117
64
  emit(...args: Parameters<T>): void;
118
- /**
119
- * Register a new handler for this event.
120
- *
121
- * @param func Handler
122
- */
65
+ /** Registers a handler once. */
123
66
  register(func: T): void;
124
- /**
125
- * Unregister a handler on this event.
126
- *
127
- * @param fn The handler that was passed to {@link register}
128
- */
67
+ /** Unregisters a handler. */
129
68
  unregister(fn: T): void;
130
- /**
131
- * Unregister all handlers created by the given module.
132
- * @internal
133
- *
134
- * @param mod Module ID
135
- */
136
- unregisterModule(mod: string): void;
69
+ /** Unregisters handlers owned by a destroyed module. */
70
+ unregisterModule(module: string): void;
137
71
  }
138
- /**
139
- * Gets the responsible module for the current execution context.
140
- *
141
- * Determines which module is responsible for the current code execution by analyzing the call stack.
142
- * This is used for automatic proxy detachment and event handler cleanup.
143
- *
144
- * @param startFrame The starting frame in the stack trace to analyze
145
- * @returns The module ID or undefined if no module is found
146
- */
72
+ /** Gets the responsible module from explicit async context or the call stack. */
147
73
  export declare function GetResponsibleModule(startFrame?: number): string | undefined;
148
74
  export {};