@antelopejs/interface-core 0.0.2

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.
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventProxy = exports.RegisteringProxy = exports.AsyncProxy = void 0;
4
+ exports.GetResponsibleModule = GetResponsibleModule;
5
+ const internal_1 = require("./internal");
6
+ const STUB_NOT_IMPLEMENTED = "Interface function called without implementation in test environment. " +
7
+ "Ensure the required module is loaded in your test config.";
8
+ /**
9
+ * Proxy for an asynchronous function.
10
+ *
11
+ * Queues up calls while unattached, automatically unattaches when the source module is unloaded.
12
+ * Provides a mechanism for delayed execution and module-aware function binding.
13
+ */
14
+ class AsyncProxy {
15
+ callback;
16
+ queue = [];
17
+ /**
18
+ * Attaches a callback to the proxy
19
+ *
20
+ * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
21
+ * When attached, any queued calls will be executed immediately.
22
+ *
23
+ * @param callback Function to attach
24
+ * @param manualDetach Don't detach automatically when module is unloaded
25
+ */
26
+ onCall(callback, manualDetach) {
27
+ this.callback = callback;
28
+ if (!manualDetach) {
29
+ const caller = GetResponsibleModule();
30
+ if (caller) {
31
+ internal_1.internal.addAsyncProxy(caller, this);
32
+ }
33
+ }
34
+ if (this.queue.length > 0) {
35
+ this.queue.forEach(({ args, resolve, reject }) => {
36
+ try {
37
+ resolve(callback(...args));
38
+ }
39
+ catch (err) {
40
+ reject(err);
41
+ }
42
+ });
43
+ this.queue.splice(0, this.queue.length);
44
+ }
45
+ }
46
+ /**
47
+ * Manually detach the callback on this proxy.
48
+ */
49
+ detach() {
50
+ this.callback = undefined;
51
+ }
52
+ /**
53
+ * Call the function attached to this proxy.
54
+ *
55
+ * If a callback has not been attached yet, the call is queued up for later.
56
+ */
57
+ call(...args) {
58
+ if (this.callback) {
59
+ return Promise.resolve(this.callback(...args));
60
+ }
61
+ if (internal_1.internal.testStubMode) {
62
+ return Promise.reject(new Error(STUB_NOT_IMPLEMENTED));
63
+ }
64
+ return new Promise((resolve, reject) => this.queue.push({ args, resolve, reject }));
65
+ }
66
+ }
67
+ exports.AsyncProxy = AsyncProxy;
68
+ /**
69
+ * Proxy for a pair of register/unregister functions.
70
+ *
71
+ * Manages registration of handlers and ensures proper cleanup when modules are unloaded.
72
+ * This allows for module-aware event registration with automatic cleanup.
73
+ */
74
+ class RegisteringProxy {
75
+ registerCallback;
76
+ unregisterCallback;
77
+ registered = new Map();
78
+ /**
79
+ * Attaches a register callback to the proxy
80
+ *
81
+ * Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
82
+ *
83
+ * @param callback Function to attach as the register callback
84
+ * @param manualDetach Don't detach automatically
85
+ */
86
+ onRegister(callback, manualDetach) {
87
+ this.registerCallback = callback;
88
+ if (!manualDetach) {
89
+ const caller = GetResponsibleModule();
90
+ if (caller) {
91
+ internal_1.internal.addRegisteringProxy(caller, this);
92
+ }
93
+ }
94
+ for (const [id, { args }] of this.registered) {
95
+ callback(id, ...args);
96
+ }
97
+ }
98
+ /**
99
+ * Attaches an unregister callback to the proxy
100
+ *
101
+ * Detached at the same time as the register callback.
102
+ *
103
+ * @param callback Function to attach as the unregister callback
104
+ */
105
+ onUnregister(callback) {
106
+ this.unregisterCallback = callback;
107
+ }
108
+ /**
109
+ * Manually detach the callbacks on this proxy.
110
+ */
111
+ detach() {
112
+ this.registerCallback = undefined;
113
+ this.unregisterCallback = undefined;
114
+ }
115
+ /**
116
+ * Call the register callback attached to this proxy.
117
+ *
118
+ * If a callback has not been attached yet, the call is queued up for later.
119
+ *
120
+ * @param id Unique identifier used to unregister
121
+ * @param args Extra arguments
122
+ */
123
+ register(id, ...args) {
124
+ if (!this.registerCallback && internal_1.internal.testStubMode) {
125
+ throw new Error(STUB_NOT_IMPLEMENTED);
126
+ }
127
+ const module = GetResponsibleModule();
128
+ this.registered.set(id, { module, args });
129
+ if (this.registerCallback) {
130
+ this.registerCallback(id, ...args);
131
+ }
132
+ }
133
+ /**
134
+ * Call the unregister callback attached to this proxy.
135
+ *
136
+ * @param id Unique identifier to unregister
137
+ */
138
+ unregister(id) {
139
+ if (this.registered.has(id)) {
140
+ if (this.unregisterCallback) {
141
+ this.unregisterCallback(id);
142
+ }
143
+ this.registered.delete(id);
144
+ }
145
+ }
146
+ /**
147
+ * Unregister all entries created by the given module
148
+ * @internal
149
+ *
150
+ * @param mod Module ID
151
+ */
152
+ unregisterModule(mod) {
153
+ for (const [id, { module }] of this.registered) {
154
+ if (module === mod) {
155
+ if (this.unregisterCallback) {
156
+ this.unregisterCallback(id);
157
+ }
158
+ this.registered.delete(id);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ exports.RegisteringProxy = RegisteringProxy;
164
+ /**
165
+ * Event handler list that automatically removes handlers from unloaded modules.
166
+ *
167
+ * Provides a module-aware event system that cleans up event handlers when modules are unloaded,
168
+ * preventing memory leaks and ensuring proper modularity.
169
+ */
170
+ class EventProxy {
171
+ registered = [];
172
+ constructor() {
173
+ internal_1.internal.knownEvents.push(this);
174
+ }
175
+ /**
176
+ * Call all the event handlers with the specified arguments.
177
+ *
178
+ * @param args Arguments
179
+ */
180
+ emit(...args) {
181
+ for (const { func } of this.registered) {
182
+ func(...args);
183
+ }
184
+ }
185
+ /**
186
+ * Register a new handler for this event.
187
+ *
188
+ * @param func Handler
189
+ */
190
+ register(func) {
191
+ if (this.registered.some((existing) => existing.func === func)) {
192
+ return;
193
+ }
194
+ const module = GetResponsibleModule();
195
+ this.registered.push({ module, func });
196
+ }
197
+ /**
198
+ * Unregister a handler on this event.
199
+ *
200
+ * @param fn The handler that was passed to {@link register}
201
+ */
202
+ unregister(fn) {
203
+ this.registered = this.registered.filter(({ func }) => func !== fn);
204
+ }
205
+ /**
206
+ * Unregister all handlers created by the given module.
207
+ * @internal
208
+ *
209
+ * @param mod Module ID
210
+ */
211
+ unregisterModule(mod) {
212
+ this.registered = this.registered.filter(({ module }) => module !== mod);
213
+ }
214
+ }
215
+ exports.EventProxy = EventProxy;
216
+ function captureCallStack(startFrame = 0) {
217
+ const oldHandler = Error.prepareStackTrace;
218
+ const oldLimit = Error.stackTraceLimit;
219
+ Error.stackTraceLimit = Infinity;
220
+ Error.prepareStackTrace = (_, trace) => trace;
221
+ const errObj = {};
222
+ Error.captureStackTrace(errObj, GetResponsibleModule);
223
+ const trace = errObj.stack;
224
+ Error.prepareStackTrace = oldHandler;
225
+ Error.stackTraceLimit = oldLimit;
226
+ return trace.slice(startFrame);
227
+ }
228
+ function findResponsibleFile(trace) {
229
+ let currentFound = "";
230
+ const lastInterface = "";
231
+ let currentBestMatch = 0;
232
+ for (const site of trace) {
233
+ const fileName = site.getFileName();
234
+ if (!fileName ||
235
+ fileName.startsWith("node:internal/") ||
236
+ fileName.match(/[/\\]node_modules[/\\]/)) {
237
+ continue;
238
+ }
239
+ for (const { dir, id } of internal_1.internal.moduleByFolder) {
240
+ if (fileName.startsWith(dir) && dir.length > currentBestMatch) {
241
+ currentFound = id;
242
+ currentBestMatch = dir.length;
243
+ }
244
+ }
245
+ if (currentFound) {
246
+ return { module: currentFound, lastInterface };
247
+ }
248
+ if (!site.getFunctionName() && site.getTypeName()) {
249
+ break;
250
+ }
251
+ }
252
+ return { lastInterface };
253
+ }
254
+ /**
255
+ * Gets the responsible module for the current execution context.
256
+ *
257
+ * Determines which module is responsible for the current code execution by analyzing the call stack.
258
+ * This is used for automatic proxy detachment and event handler cleanup.
259
+ *
260
+ * @param startFrame The starting frame in the stack trace to analyze
261
+ * @returns The module ID or undefined if no module is found
262
+ */
263
+ function GetResponsibleModule(startFrame = 0) {
264
+ const trace = captureCallStack(startFrame);
265
+ const responsible = findResponsibleFile(trace);
266
+ if (responsible.module) {
267
+ return responsible.module;
268
+ }
269
+ internal_1.internal.asyncContextReporter?.(trace);
270
+ return responsible.lastInterface;
271
+ }
272
+ //# sourceMappingURL=proxies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxies.js","s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AAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,UAAU,GAAG,CAAC;IACjD,MAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACvB,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;IACD,mBAAQ,CAAC,oBAAoB,EAAE,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,WAAW,CAAC,aAAa,CAAC;AACnC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const __1 = require("..");
5
+ const internal_1 = require("../internal");
6
+ const modules_1 = require("../modules");
7
+ describe("ModuleDestroyed cleanup", () => {
8
+ beforeEach(() => {
9
+ internal_1.internal.knownAsync.clear();
10
+ internal_1.internal.knownRegisters.clear();
11
+ });
12
+ it("should remove module from knownAsync after destroy", () => {
13
+ const proxy = new __1.AsyncProxy();
14
+ internal_1.internal.addAsyncProxy("testModule", proxy);
15
+ (0, chai_1.expect)(internal_1.internal.knownAsync.has("testModule")).to.equal(true);
16
+ modules_1.Events.ModuleDestroyed.emit("testModule");
17
+ (0, chai_1.expect)(internal_1.internal.knownAsync.has("testModule")).to.equal(false);
18
+ });
19
+ it("should remove module from knownRegisters after destroy", () => {
20
+ const proxy = new __1.RegisteringProxy();
21
+ internal_1.internal.addRegisteringProxy("testModule", proxy);
22
+ (0, chai_1.expect)(internal_1.internal.knownRegisters.has("testModule")).to.equal(true);
23
+ modules_1.Events.ModuleDestroyed.emit("testModule");
24
+ (0, chai_1.expect)(internal_1.internal.knownRegisters.has("testModule")).to.equal(false);
25
+ });
26
+ });
27
+ //# sourceMappingURL=modules.test.js.map
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,mBAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const __1 = require("..");
5
+ const internal_1 = require("../internal");
6
+ describe("test stub mode", () => {
7
+ afterEach(() => {
8
+ internal_1.internal.testStubMode = false;
9
+ });
10
+ describe("AsyncProxy", () => {
11
+ it("rejects with error when called without callback in stub mode", async () => {
12
+ internal_1.internal.testStubMode = true;
13
+ const proxy = new __1.AsyncProxy();
14
+ let thrown;
15
+ try {
16
+ await proxy.call();
17
+ }
18
+ catch (error) {
19
+ thrown = error;
20
+ }
21
+ (0, chai_1.expect)(thrown).to.be.instanceOf(Error);
22
+ (0, chai_1.expect)(thrown.message).to.include("without implementation");
23
+ });
24
+ it("still queues calls when stub mode is off", () => {
25
+ const proxy = new __1.AsyncProxy();
26
+ const promise = proxy.call("arg");
27
+ (0, chai_1.expect)(promise).to.be.instanceOf(Promise);
28
+ });
29
+ it("calls callback normally when attached in stub mode", async () => {
30
+ internal_1.internal.testStubMode = true;
31
+ const proxy = new __1.AsyncProxy();
32
+ proxy.onCall((value) => value.toUpperCase(), true);
33
+ const result = await proxy.call("hello");
34
+ (0, chai_1.expect)(result).to.equal("HELLO");
35
+ });
36
+ });
37
+ describe("RegisteringProxy", () => {
38
+ it("throws when registering without callback in stub mode", () => {
39
+ internal_1.internal.testStubMode = true;
40
+ const proxy = new __1.RegisteringProxy();
41
+ (0, chai_1.expect)(() => proxy.register("id1")).to.throw("without implementation");
42
+ });
43
+ it("still queues registration when stub mode is off", () => {
44
+ const proxy = new __1.RegisteringProxy();
45
+ proxy.register("id1");
46
+ });
47
+ it("registers normally when callback attached in stub mode", () => {
48
+ internal_1.internal.testStubMode = true;
49
+ const proxy = new __1.RegisteringProxy();
50
+ const registered = [];
51
+ proxy.onRegister((id) => registered.push(id), true);
52
+ proxy.register("id1");
53
+ (0, chai_1.expect)(registered).to.deep.equal(["id1"]);
54
+ });
55
+ });
56
+ });
57
+ //# sourceMappingURL=stub-mode.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stub-mode.test.js","sourceRoot":"","sources":["../../src/tests/stub-mode.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,0BAAkD;AAClD,0CAAuC;AAEvC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,SAAS,CAAC,GAAG,EAAE;QACb,mBAAQ,CAAC,YAAY,GAAG,KAAK,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,8DAA8D,EAAE,KAAK,IAAI,EAAE;YAC5E,mBAAQ,CAAC,YAAY,GAAG,IAAI,CAAC;YAC7B,MAAM,KAAK,GAAG,IAAI,cAAU,EAAE,CAAC;YAE/B,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YACrB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;YAED,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACvC,IAAA,aAAM,EAAE,MAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;QACzE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,KAAK,GAAG,IAAI,cAAU,EAAE,CAAC;YAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YA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wB,CAAC;YAC3D,MAAM,UAAU,GAAa,EAAE,CAAC;YAChC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;YAEpD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEtB,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@antelopejs/interface-core",
3
+ "version": "0.0.2",
4
+ "description": "AntelopeJS core interface primitives - proxies, decorators, interface functions, and logging",
5
+ "keywords": [
6
+ "antelopejs",
7
+ "interface",
8
+ "core"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/AntelopeJS/interface-core.git"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "packageManager": "pnpm@10.6.5",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./*": {
27
+ "types": "./dist/*.d.ts",
28
+ "default": "./dist/*.js"
29
+ },
30
+ "./config": {
31
+ "types": "./dist/config.d.ts",
32
+ "default": "./dist/config.js"
33
+ },
34
+ "./logging": {
35
+ "types": "./dist/logging/index.d.ts",
36
+ "default": "./dist/logging/index.js"
37
+ },
38
+ "./logging/*": {
39
+ "types": "./dist/logging/*.d.ts",
40
+ "default": "./dist/logging/*.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "typesVersions": {
45
+ "*": {
46
+ "decorators": [
47
+ "dist/decorators.d.ts"
48
+ ],
49
+ "modules": [
50
+ "dist/modules.d.ts"
51
+ ],
52
+ "proxies": [
53
+ "dist/proxies.d.ts"
54
+ ],
55
+ "internal": [
56
+ "dist/internal.d.ts"
57
+ ],
58
+ "config": [
59
+ "dist/config.d.ts"
60
+ ],
61
+ "logging": [
62
+ "dist/logging/index.d.ts"
63
+ ],
64
+ "logging/*": [
65
+ "dist/logging/*.d.ts"
66
+ ]
67
+ }
68
+ },
69
+ "scripts": {
70
+ "build": "rimraf dist && tsc",
71
+ "format": "biome format --write .",
72
+ "lint:fix": "biome check --write .",
73
+ "lint": "biome check .",
74
+ "prepack": "pnpm run build",
75
+ "release": "pnpm run lint && pnpm run prepack && release-it",
76
+ "test": "pnpm run build && ajs module test ."
77
+ },
78
+ "antelopeJs": {
79
+ "test": "src/antelope.test.ts"
80
+ },
81
+ "dependencies": {
82
+ "reflect-metadata": "^0.2.2"
83
+ },
84
+ "devDependencies": {
85
+ "@biomejs/biome": "2.3.2",
86
+ "@types/chai": "^4.3.20",
87
+ "@types/mocha": "^10.0.10",
88
+ "@types/node": "^22.14.1",
89
+ "chai": "^4.5.0",
90
+ "release-it": "^19.0.2",
91
+ "release-it-changelogen": "^0.1.0",
92
+ "rimraf": "^6.0.1",
93
+ "typescript": "^5.8.3"
94
+ },
95
+ "publishConfig": {
96
+ "access": "public"
97
+ }
98
+ }