@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.
Files changed (38) hide show
  1. package/dist/errors.d.ts +20 -0
  2. package/dist/errors.js +33 -1
  3. package/dist/errors.js.map +1 -1
  4. package/dist/index.d.ts +5 -5
  5. package/dist/index.js +92 -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 -25
  12. package/dist/modules.js.map +1 -1
  13. package/dist/proxies.d.ts +58 -119
  14. package/dist/proxies.js +298 -184
  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.d.ts +1 -0
  22. package/dist/tests/module-ownership-context.test.js +215 -0
  23. package/dist/tests/module-ownership-context.test.js.map +1 -0
  24. package/dist/tests/provider-routing.test.d.ts +1 -0
  25. package/dist/tests/provider-routing.test.js +78 -0
  26. package/dist/tests/provider-routing.test.js.map +1 -0
  27. package/dist/tests/queue-and-cleanup.test.d.ts +1 -0
  28. package/dist/tests/queue-and-cleanup.test.js +73 -0
  29. package/dist/tests/queue-and-cleanup.test.js.map +1 -0
  30. package/dist/tests/registering-proxy-replay.test.js +9 -0
  31. package/dist/tests/registering-proxy-replay.test.js.map +1 -1
  32. package/dist/tests/runtime-protocol.test.d.ts +1 -0
  33. package/dist/tests/runtime-protocol.test.js +45 -0
  34. package/dist/tests/runtime-protocol.test.js.map +1 -0
  35. package/dist/tests/runtime.test.js +18 -2
  36. package/dist/tests/runtime.test.js.map +1 -1
  37. package/docs/2.proxies.md +18 -1
  38. package/package.json +1 -1
package/dist/modules.js CHANGED
@@ -1,8 +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");
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
+ }
6
16
  /**
7
17
  * Contains events related to module lifecycle management.
8
18
  *
@@ -19,7 +29,7 @@ var Events;
19
29
  *
20
30
  * @param module Module ID
21
31
  */
22
- Events.ModuleConstructed = new _1.EventProxy();
32
+ Events.ModuleConstructed = new _1.EventProxy("modules.ModuleConstructed");
23
33
  /**
24
34
  * Event triggers when a module is started.
25
35
  *
@@ -28,7 +38,7 @@ var Events;
28
38
  *
29
39
  * @param module Module ID
30
40
  */
31
- Events.ModuleStarted = new _1.EventProxy();
41
+ Events.ModuleStarted = new _1.EventProxy("modules.ModuleStarted");
32
42
  /**
33
43
  * Event triggers when a module is stopped.
34
44
  *
@@ -37,7 +47,7 @@ var Events;
37
47
  *
38
48
  * @param module Module ID
39
49
  */
40
- Events.ModuleStopped = new _1.EventProxy();
50
+ Events.ModuleStopped = new _1.EventProxy("modules.ModuleStopped");
41
51
  /**
42
52
  * Event triggers when a module is destroyed.
43
53
  *
@@ -46,29 +56,52 @@ var Events;
46
56
  *
47
57
  * @param module Module ID
48
58
  */
49
- Events.ModuleDestroyed = new _1.EventProxy();
59
+ Events.ModuleDestroyed = new _1.EventProxy("modules.ModuleDestroyed");
50
60
  })(Events || (exports.Events = Events = {}));
51
- // Using the Events namespace from modules.ts instead of the lowercase events
52
- Events.ModuleDestroyed.register((module) => {
53
- if (internal_1.internal.knownAsync.has(module)) {
54
- for (const proxy of internal_1.internal.knownAsync.get(module) ?? []) {
55
- proxy.detach();
61
+ function runCleanup(cleanup, module, operation) {
62
+ try {
63
+ if ("cleanup" in cleanup) {
64
+ cleanup.cleanup();
56
65
  }
57
- internal_1.internal.knownAsync.delete(module);
58
- }
59
- if (internal_1.internal.knownRegisters.has(module)) {
60
- for (const proxy of internal_1.internal.knownRegisters.get(module) ?? []) {
61
- proxy.detach();
66
+ else {
67
+ cleanup.detach();
62
68
  }
63
- internal_1.internal.knownRegisters.delete(module);
64
69
  }
65
- for (const [, proxies] of internal_1.internal.knownRegisters) {
66
- 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 {
67
86
  proxy.unregisterModule(module);
68
87
  }
88
+ catch (error) {
89
+ internal_1.internal.runtimeErrorReporter?.(error, {
90
+ operation: "unregister-module",
91
+ module,
92
+ });
93
+ }
69
94
  }
70
95
  for (const proxy of internal_1.internal.knownEvents) {
71
- 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
+ }
72
105
  }
73
106
  });
74
107
  /**
@@ -79,7 +112,7 @@ Events.ModuleDestroyed.register((module) => {
79
112
  *
80
113
  * @returns Array of module IDs
81
114
  */
82
- exports.ListModules = (0, _1.InterfaceFunction)();
115
+ exports.ListModules = (0, _1.InterfaceFunction)("modules.ListModules");
83
116
  /**
84
117
  * Retrieve the configuration and status information of a loaded module.
85
118
  *
@@ -89,7 +122,7 @@ exports.ListModules = (0, _1.InterfaceFunction)();
89
122
  * @param module The module ID to get information for
90
123
  * @returns Complete module information object
91
124
  */
92
- exports.GetModuleInfo = (0, _1.InterfaceFunction)();
125
+ exports.GetModuleInfo = (0, _1.InterfaceFunction)("modules.GetModuleInfo");
93
126
  /**
94
127
  * Load a new module with the given ID and configuration.
95
128
  *
@@ -100,7 +133,7 @@ exports.GetModuleInfo = (0, _1.InterfaceFunction)();
100
133
  * @param configuration Module configuration including source information
101
134
  * @param autostart Whether to automatically start the module after loading (default: false)
102
135
  */
103
- exports.LoadModule = (0, _1.InterfaceFunction)();
136
+ exports.LoadModule = (0, _1.InterfaceFunction)("modules.LoadModule");
104
137
  /**
105
138
  * Start a loaded but inactive module.
106
139
  *
@@ -110,7 +143,7 @@ exports.LoadModule = (0, _1.InterfaceFunction)();
110
143
  * @param module The module ID to start
111
144
  * @throws Error if the module is not loaded or cannot be started
112
145
  */
113
- exports.StartModule = (0, _1.InterfaceFunction)();
146
+ exports.StartModule = (0, _1.InterfaceFunction)("modules.StartModule");
114
147
  /**
115
148
  * Stop an active module.
116
149
  *
@@ -120,7 +153,7 @@ exports.StartModule = (0, _1.InterfaceFunction)();
120
153
  * @param module The module ID to stop
121
154
  * @throws Error if the module is not loaded or cannot be stopped
122
155
  */
123
- exports.StopModule = (0, _1.InterfaceFunction)();
156
+ exports.StopModule = (0, _1.InterfaceFunction)("modules.StopModule");
124
157
  /**
125
158
  * Destroy a stopped module.
126
159
  *
@@ -130,7 +163,7 @@ exports.StopModule = (0, _1.InterfaceFunction)();
130
163
  * @param module The module ID to destroy
131
164
  * @throws Error if the module is active or not loaded
132
165
  */
133
- exports.DestroyModule = (0, _1.InterfaceFunction)();
166
+ exports.DestroyModule = (0, _1.InterfaceFunction)("modules.DestroyModule");
134
167
  /**
135
168
  * Unload a module and retrigger its source mechanism.
136
169
  *
@@ -141,5 +174,5 @@ exports.DestroyModule = (0, _1.InterfaceFunction)();
141
174
  * @param module The module ID to reload
142
175
  * @throws Error if the module cannot be reloaded
143
176
  */
144
- exports.ReloadModule = (0, _1.InterfaceFunction)();
177
+ exports.ReloadModule = (0, _1.InterfaceFunction)("modules.ReloadModule");
145
178
  //# sourceMappingURL=modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":";;;AAAA,wBAAkD;AAClD,yCAAsC;AAEtC;;;;;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,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,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,mBAAQ,CA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ASG;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,135 +1,74 @@
1
+ import { type ProxyBrand } from "./internal";
1
2
  type Func<A extends any[] = any[], R = any> = (...args: A) => R;
2
- /**
3
- * Proxy for an asynchronous function.
4
- *
5
- * Queues up calls while unattached, automatically unattaches when the source module is unloaded.
6
- * Provides a mechanism for delayed execution and module-aware function binding.
7
- */
8
- export declare class AsyncProxy<T extends Func = Func, R = Awaited<ReturnType<T>>> {
9
- private callback?;
10
- private queue;
11
- /**
12
- * Attaches a callback to the proxy
13
- *
14
- * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
15
- * When attached, any queued calls will be executed immediately.
16
- *
17
- * @param callback Function to attach
18
- * @param manualDetach Don't detach automatically when module is unloaded
19
- */
20
- onCall(callback: T, manualDetach?: boolean): void;
21
- /**
22
- * Manually detach the callback on this proxy.
23
- */
24
- detach(): void;
25
- /**
26
- * Call the function attached to this proxy.
27
- *
28
- * If a callback has not been attached yet, the call is queued up for later.
29
- */
30
- call(...args: Parameters<T>): Promise<R>;
31
- }
32
3
  type RegisterFunction = (id: any, ...args: any[]) => void;
33
4
  type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
34
5
  type RArgs<T> = T extends (id: any, ...args: infer P) => void ? P : never;
35
- /**
36
- * Proxy for a pair of register/unregister functions.
37
- *
38
- * Manages registration of handlers and ensures proper cleanup when modules are unloaded.
39
- * This allows for module-aware event registration with automatic cleanup.
40
- */
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;
17
+ /** @internal */
18
+ export declare function InvalidateResponsibleModule(module: string): void;
19
+ /** Runs work with explicit module ownership across asynchronous boundaries. */
20
+ export declare function RunWithResponsibleModule<T>(module: string, callback: () => T): T;
21
+ /** Proxy for an asynchronous interface function. */
22
+ export declare class AsyncProxy<T extends Func = Func, R = Awaited<ReturnType<T>>> {
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. */
31
+ call(...args: Parameters<T>): Promise<R>;
32
+ private invoke;
33
+ private replayQueue;
34
+ }
35
+ /** Proxy for provider-aware register and unregister handlers. */
41
36
  export declare class RegisteringProxy<T extends RegisterFunction = RegisterFunction> {
42
- private registerCallback?;
43
- private unregisterCallback?;
44
- private registered;
45
- /**
46
- * Attaches a register callback to the proxy
47
- *
48
- * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
49
- *
50
- * @param callback Function to attach as the register callback
51
- * @param manualDetach Don't detach automatically
52
- */
53
- onRegister(callback: T, manualDetach?: boolean): void;
54
- /**
55
- * Attaches an unregister callback to the proxy
56
- *
57
- * Detached at the same time as the register callback.
58
- *
59
- * @param callback Function to attach as the unregister callback
60
- */
61
- onUnregister(callback: (id: RID<T>) => void): void;
62
- /**
63
- * Manually detach the callbacks on this proxy.
64
- */
65
- detach(): void;
66
- /**
67
- * Call the register callback attached to this proxy.
68
- *
69
- * If a callback has not been attached yet, the call is queued up for later.
70
- *
71
- * @param id Unique identifier used to unregister
72
- * @param args Extra arguments
73
- */
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. */
74
49
  register(id: RID<T>, ...args: RArgs<T>): void;
75
- /**
76
- * Call the unregister callback attached to this proxy.
77
- *
78
- * @param id Unique identifier to unregister
79
- */
50
+ /** Unregisters an entry from the provider that accepted it. */
80
51
  unregister(id: RID<T>): void;
81
- /**
82
- * Unregister all entries created by the given module
83
- * @internal
84
- *
85
- * @param mod Module ID
86
- */
87
- unregisterModule(mod: string): void;
52
+ /** Unregisters every entry owned by a destroyed module. */
53
+ unregisterModule(module: string): void;
54
+ private attachHandlers;
55
+ private replayRegistrations;
88
56
  }
89
57
  type EventFunction = (...args: any[]) => void;
90
- /**
91
- * Event handler list that automatically removes handlers from unloaded modules.
92
- *
93
- * Provides a module-aware event system that cleans up event handlers when modules are unloaded,
94
- * preventing memory leaks and ensuring proper modularity.
95
- */
58
+ /** Module-aware event handler collection. */
96
59
  export declare class EventProxy<T extends EventFunction = EventFunction> {
97
- private registered;
98
- constructor();
99
- /**
100
- * Call all the event handlers with the specified arguments.
101
- *
102
- * @param args Arguments
103
- */
60
+ readonly [PROXY_BRAND]: ProxyBrand;
61
+ private readonly state;
62
+ constructor(identity?: string);
63
+ /** Emits to every handler, reporting failures without aborting later handlers. */
104
64
  emit(...args: Parameters<T>): void;
105
- /**
106
- * Register a new handler for this event.
107
- *
108
- * @param func Handler
109
- */
65
+ /** Registers a handler once. */
110
66
  register(func: T): void;
111
- /**
112
- * Unregister a handler on this event.
113
- *
114
- * @param fn The handler that was passed to {@link register}
115
- */
67
+ /** Unregisters a handler. */
116
68
  unregister(fn: T): void;
117
- /**
118
- * Unregister all handlers created by the given module.
119
- * @internal
120
- *
121
- * @param mod Module ID
122
- */
123
- unregisterModule(mod: string): void;
69
+ /** Unregisters handlers owned by a destroyed module. */
70
+ unregisterModule(module: string): void;
124
71
  }
125
- /**
126
- * Gets the responsible module for the current execution context.
127
- *
128
- * Determines which module is responsible for the current code execution by analyzing the call stack.
129
- * This is used for automatic proxy detachment and event handler cleanup.
130
- *
131
- * @param startFrame The starting frame in the stack trace to analyze
132
- * @returns The module ID or undefined if no module is found
133
- */
72
+ /** Gets the responsible module from explicit async context or the call stack. */
134
73
  export declare function GetResponsibleModule(startFrame?: number): string | undefined;
135
74
  export {};