@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/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,60 @@ 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) {
69
- proxy.unregisterModule(module);
70
+ catch (error) {
71
+ internal_1.internal.runtimeErrorReporter?.(error, { operation, module });
72
+ }
73
+ }
74
+ function getDestroyedOwner(module) {
75
+ const context = (0, internal_1.peekModuleContext)();
76
+ if (context?.module !== module) {
77
+ return module;
78
+ }
79
+ return context.owner ?? module;
80
+ }
81
+ Events.ModuleDestroyed.register((module) => {
82
+ const owner = getDestroyedOwner(module);
83
+ (0, internal_1.invalidateModuleContext)(owner);
84
+ for (const cleanup of internal_1.internal.knownAsync.get(owner) ?? []) {
85
+ runCleanup(cleanup, owner, "detach-async-provider");
86
+ }
87
+ internal_1.internal.knownAsync.delete(owner);
88
+ for (const cleanup of internal_1.internal.knownRegisters.get(owner) ?? []) {
89
+ runCleanup(cleanup, owner, "detach-registering-provider");
90
+ }
91
+ internal_1.internal.knownRegisters.delete(owner);
92
+ for (const proxy of internal_1.internal.registeringProxies) {
93
+ try {
94
+ proxy.unregisterOwner(owner);
95
+ }
96
+ catch (error) {
97
+ internal_1.internal.runtimeErrorReporter?.(error, {
98
+ operation: "unregister-module",
99
+ module,
100
+ });
70
101
  }
71
102
  }
72
103
  for (const proxy of internal_1.internal.knownEvents) {
73
- proxy.unregisterModule(module);
104
+ try {
105
+ proxy.unregisterOwner(owner);
106
+ }
107
+ catch (error) {
108
+ internal_1.internal.runtimeErrorReporter?.(error, {
109
+ operation: "unregister-event-module",
110
+ module,
111
+ });
112
+ }
74
113
  }
75
114
  });
76
115
  /**
@@ -81,7 +120,7 @@ Events.ModuleDestroyed.register((module) => {
81
120
  *
82
121
  * @returns Array of module IDs
83
122
  */
84
- exports.ListModules = (0, _1.InterfaceFunction)();
123
+ exports.ListModules = (0, _1.InterfaceFunction)("modules.ListModules");
85
124
  /**
86
125
  * Retrieve the configuration and status information of a loaded module.
87
126
  *
@@ -91,7 +130,7 @@ exports.ListModules = (0, _1.InterfaceFunction)();
91
130
  * @param module The module ID to get information for
92
131
  * @returns Complete module information object
93
132
  */
94
- exports.GetModuleInfo = (0, _1.InterfaceFunction)();
133
+ exports.GetModuleInfo = (0, _1.InterfaceFunction)("modules.GetModuleInfo");
95
134
  /**
96
135
  * Load a new module with the given ID and configuration.
97
136
  *
@@ -102,7 +141,7 @@ exports.GetModuleInfo = (0, _1.InterfaceFunction)();
102
141
  * @param configuration Module configuration including source information
103
142
  * @param autostart Whether to automatically start the module after loading (default: false)
104
143
  */
105
- exports.LoadModule = (0, _1.InterfaceFunction)();
144
+ exports.LoadModule = (0, _1.InterfaceFunction)("modules.LoadModule");
106
145
  /**
107
146
  * Start a loaded but inactive module.
108
147
  *
@@ -112,7 +151,7 @@ exports.LoadModule = (0, _1.InterfaceFunction)();
112
151
  * @param module The module ID to start
113
152
  * @throws Error if the module is not loaded or cannot be started
114
153
  */
115
- exports.StartModule = (0, _1.InterfaceFunction)();
154
+ exports.StartModule = (0, _1.InterfaceFunction)("modules.StartModule");
116
155
  /**
117
156
  * Stop an active module.
118
157
  *
@@ -122,7 +161,7 @@ exports.StartModule = (0, _1.InterfaceFunction)();
122
161
  * @param module The module ID to stop
123
162
  * @throws Error if the module is not loaded or cannot be stopped
124
163
  */
125
- exports.StopModule = (0, _1.InterfaceFunction)();
164
+ exports.StopModule = (0, _1.InterfaceFunction)("modules.StopModule");
126
165
  /**
127
166
  * Destroy a stopped module.
128
167
  *
@@ -132,7 +171,7 @@ exports.StopModule = (0, _1.InterfaceFunction)();
132
171
  * @param module The module ID to destroy
133
172
  * @throws Error if the module is active or not loaded
134
173
  */
135
- exports.DestroyModule = (0, _1.InterfaceFunction)();
174
+ exports.DestroyModule = (0, _1.InterfaceFunction)("modules.DestroyModule");
136
175
  /**
137
176
  * Unload a module and retrigger its source mechanism.
138
177
  *
@@ -143,5 +182,5 @@ exports.DestroyModule = (0, _1.InterfaceFunction)();
143
182
  * @param module The module ID to reload
144
183
  * @throws Error if the module cannot be reloaded
145
184
  */
146
- exports.ReloadModule = (0, _1.InterfaceFunction)();
185
+ exports.ReloadModule = (0, _1.InterfaceFunction)("modules.ReloadModule");
147
186
  //# 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,aAA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AAG,IAAA,oBAAiB,EAC3C,sBAAsB,CACvB,CAAC"}
package/dist/proxies.d.ts CHANGED
@@ -1,148 +1,83 @@
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
+ /** Unregisters every entry owned by a destroyed module generation. */
55
+ unregisterOwner(owner: string): void;
56
+ private unregisterMatching;
57
+ private attachRegister;
58
+ private attachUnregister;
59
+ private trackAttachment;
60
+ private createLease;
61
+ private createAttachment;
62
+ private replayRegistrations;
101
63
  }
102
64
  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
- */
65
+ /** Module-aware event handler collection. */
109
66
  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
- */
67
+ readonly [PROXY_BRAND]: ProxyBrand;
68
+ private readonly state;
69
+ constructor(identity?: string);
70
+ /** Emits to every handler, reporting failures without aborting later handlers. */
117
71
  emit(...args: Parameters<T>): void;
118
- /**
119
- * Register a new handler for this event.
120
- *
121
- * @param func Handler
122
- */
72
+ /** Registers a handler once. */
123
73
  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
- */
74
+ /** Unregisters a handler. */
129
75
  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;
76
+ /** Unregisters handlers owned by a destroyed module. */
77
+ unregisterModule(module: string): void;
78
+ /** Unregisters handlers owned by a destroyed module generation. */
79
+ unregisterOwner(owner: string): void;
137
80
  }
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
- */
81
+ /** Gets the responsible module from explicit async context or the call stack. */
147
82
  export declare function GetResponsibleModule(startFrame?: number): string | undefined;
148
83
  export {};