@antelopejs/interface-core 0.0.7 → 0.0.9
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.
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +58 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/modules.js +2 -0
- package/dist/modules.js.map +1 -1
- package/dist/proxies.d.ts +13 -0
- package/dist/proxies.js +55 -14
- package/dist/proxies.js.map +1 -1
- package/dist/tests/module-ownership-context.test.d.ts +1 -0
- package/dist/tests/module-ownership-context.test.js +197 -0
- package/dist/tests/module-ownership-context.test.js.map +1 -0
- package/dist/tests/stub-mode.test.js +34 -3
- package/dist/tests/stub-mode.test.js.map +1 -1
- package/docs/2.proxies.md +38 -2
- package/package.json +1 -1
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const MISSING_PROVIDER_CODE = "ERR_NO_PROVIDER";
|
|
2
|
+
export declare const MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
3
|
+
/**
|
|
4
|
+
* Error emitted when a proxy is used without an attached provider in test
|
|
5
|
+
* stub mode.
|
|
6
|
+
*
|
|
7
|
+
* The detection contract is the type and the stable `code` property, not the
|
|
8
|
+
* message text: use `instanceof MissingProviderError` or, across duplicated
|
|
9
|
+
* copies of this package, {@link isMissingProviderError}.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MissingProviderError extends Error {
|
|
12
|
+
readonly code = "ERR_NO_PROVIDER";
|
|
13
|
+
constructor(detail?: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error emitted when work inherited ownership from a destroyed module.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ModuleContextInvalidatedError extends Error {
|
|
19
|
+
readonly code = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
20
|
+
constructor(module: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for {@link MissingProviderError}.
|
|
24
|
+
*
|
|
25
|
+
* Checks the stable `code` property instead of `instanceof`, so detection
|
|
26
|
+
* survives realm boundaries and duplicated copies of this package.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isMissingProviderError(error: unknown): error is MissingProviderError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleContextInvalidatedError = exports.MissingProviderError = exports.MODULE_CONTEXT_INVALIDATED_CODE = exports.MISSING_PROVIDER_CODE = void 0;
|
|
4
|
+
exports.isMissingProviderError = isMissingProviderError;
|
|
5
|
+
exports.MISSING_PROVIDER_CODE = "ERR_NO_PROVIDER";
|
|
6
|
+
exports.MODULE_CONTEXT_INVALIDATED_CODE = "ERR_MODULE_CONTEXT_INVALIDATED";
|
|
7
|
+
const MISSING_PROVIDER_MESSAGE = "Interface function called without implementation in test environment. " +
|
|
8
|
+
"Ensure the required module is loaded in your test config.";
|
|
9
|
+
/**
|
|
10
|
+
* Error emitted when a proxy is used without an attached provider in test
|
|
11
|
+
* stub mode.
|
|
12
|
+
*
|
|
13
|
+
* The detection contract is the type and the stable `code` property, not the
|
|
14
|
+
* message text: use `instanceof MissingProviderError` or, across duplicated
|
|
15
|
+
* copies of this package, {@link isMissingProviderError}.
|
|
16
|
+
*/
|
|
17
|
+
class MissingProviderError extends Error {
|
|
18
|
+
code = exports.MISSING_PROVIDER_CODE;
|
|
19
|
+
constructor(detail) {
|
|
20
|
+
super(detail ?? MISSING_PROVIDER_MESSAGE);
|
|
21
|
+
this.name = "MissingProviderError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MissingProviderError = MissingProviderError;
|
|
25
|
+
/**
|
|
26
|
+
* Error emitted when work inherited ownership from a destroyed module.
|
|
27
|
+
*/
|
|
28
|
+
class ModuleContextInvalidatedError extends Error {
|
|
29
|
+
code = exports.MODULE_CONTEXT_INVALIDATED_CODE;
|
|
30
|
+
constructor(module) {
|
|
31
|
+
super(`Module context has been invalidated: ${module}`);
|
|
32
|
+
this.name = "ModuleContextInvalidatedError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ModuleContextInvalidatedError = ModuleContextInvalidatedError;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the value is an error, including one built in another realm.
|
|
38
|
+
*
|
|
39
|
+
* `instanceof Error` is realm-bound: an error crossing a vm context, worker or
|
|
40
|
+
* iframe boundary carries a different `Error.prototype` and fails it. The brand
|
|
41
|
+
* check holds across realms while still rejecting plain objects; `instanceof`
|
|
42
|
+
* covers the reverse case of an object created from `Error.prototype`.
|
|
43
|
+
*/
|
|
44
|
+
function isError(value) {
|
|
45
|
+
return (Object.prototype.toString.call(value) === "[object Error]" ||
|
|
46
|
+
value instanceof Error);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type guard for {@link MissingProviderError}.
|
|
50
|
+
*
|
|
51
|
+
* Checks the stable `code` property instead of `instanceof`, so detection
|
|
52
|
+
* survives realm boundaries and duplicated copies of this package.
|
|
53
|
+
*/
|
|
54
|
+
function isMissingProviderError(error) {
|
|
55
|
+
return (isError(error) &&
|
|
56
|
+
error.code === exports.MISSING_PROVIDER_CODE);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import type { Class } from "./decorators";
|
|
3
3
|
import { EventProxy, RegisteringProxy } from "./proxies";
|
|
4
|
-
export
|
|
4
|
+
export * from "./errors";
|
|
5
|
+
export { AsyncProxy, EventProxy, GetResponsibleModule, RegisteringProxy, RunWithResponsibleModule, } from "./proxies";
|
|
5
6
|
/**
|
|
6
7
|
* Gets metadata for a target object using the specified metadata class.
|
|
7
8
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegisteringProxy = exports.GetResponsibleModule = exports.EventProxy = exports.AsyncProxy = void 0;
|
|
17
|
+
exports.RunWithResponsibleModule = exports.RegisteringProxy = exports.GetResponsibleModule = exports.EventProxy = exports.AsyncProxy = void 0;
|
|
4
18
|
exports.GetMetadata = GetMetadata;
|
|
5
19
|
exports.InterfaceFunction = InterfaceFunction;
|
|
6
20
|
exports.ImplementInterface = ImplementInterface;
|
|
@@ -10,11 +24,13 @@ require("reflect-metadata");
|
|
|
10
24
|
const internal_1 = require("./internal");
|
|
11
25
|
const logging_1 = require("./logging");
|
|
12
26
|
const proxies_1 = require("./proxies");
|
|
27
|
+
__exportStar(require("./errors"), exports);
|
|
13
28
|
var proxies_2 = require("./proxies");
|
|
14
29
|
Object.defineProperty(exports, "AsyncProxy", { enumerable: true, get: function () { return proxies_2.AsyncProxy; } });
|
|
15
30
|
Object.defineProperty(exports, "EventProxy", { enumerable: true, get: function () { return proxies_2.EventProxy; } });
|
|
16
31
|
Object.defineProperty(exports, "GetResponsibleModule", { enumerable: true, get: function () { return proxies_2.GetResponsibleModule; } });
|
|
17
32
|
Object.defineProperty(exports, "RegisteringProxy", { enumerable: true, get: function () { return proxies_2.RegisteringProxy; } });
|
|
33
|
+
Object.defineProperty(exports, "RunWithResponsibleModule", { enumerable: true, get: function () { return proxies_2.RunWithResponsibleModule; } });
|
|
18
34
|
internal_1.internal.asyncContextReporter = (trace) => {
|
|
19
35
|
const lastSite = trace[trace.length - 1];
|
|
20
36
|
if (lastSite?.getFileName() !== "node:internal/timers") {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,2GAAA,gBAAgB,OAAA;AAChB,mHAAA,wBAAwB,OAAA;AAG1B,mBAAQ,CAAC,oBAAoB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,QAAQ,EAAE,WAAW,EAAE,KAAK,sBAAsB,EAAE,CAAC;QACvD,OAAO;IACT,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK;SACnB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;SACnE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC9B,IAAI,CAAC,UAAU,CAAC,CAAC;IACpB,iBAAO,CAAC,KAAK,CACX,kGAAkG;QAChG,QAAQ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|
|
|
3
3
|
exports.ReloadModule = exports.DestroyModule = exports.StopModule = exports.StartModule = exports.LoadModule = exports.GetModuleInfo = exports.ListModules = exports.Events = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const internal_1 = require("./internal");
|
|
6
|
+
const proxies_1 = require("./proxies");
|
|
6
7
|
/**
|
|
7
8
|
* Contains events related to module lifecycle management.
|
|
8
9
|
*
|
|
@@ -50,6 +51,7 @@ var Events;
|
|
|
50
51
|
})(Events || (exports.Events = Events = {}));
|
|
51
52
|
// Using the Events namespace from modules.ts instead of the lowercase events
|
|
52
53
|
Events.ModuleDestroyed.register((module) => {
|
|
54
|
+
(0, proxies_1.InvalidateResponsibleModule)(module);
|
|
53
55
|
if (internal_1.internal.knownAsync.has(module)) {
|
|
54
56
|
for (const proxy of internal_1.internal.knownAsync.get(module) ?? []) {
|
|
55
57
|
proxy.detach();
|
package/dist/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":";;;AAAA,wBAAkD;AAClD,yCAAsC;
|
|
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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Md,CAAC;AAEN;;;;;;;;GAQG;AACU,QAAA,WAAW,GAAG,IAAA,oBAAiB,GAA4B,CAAC;AAEzE;;;;;;;;GAQG;AACU,QAAA,UAAU,GAAG,IAAA,oBAAiB,GAA4B,CAAC;AAExE;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,IAAA,oBAAiB,GAA4B,CAAC;AAE3E;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,IAAA,oBAAiB,GAA4B,CAAC"}
|
package/dist/proxies.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
type Func<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
2
|
+
/** @internal */
|
|
3
|
+
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
|
+
*/
|
|
14
|
+
export declare function RunWithResponsibleModule<T>(module: string, callback: () => T): T;
|
|
2
15
|
/**
|
|
3
16
|
* Proxy for an asynchronous function.
|
|
4
17
|
*
|
package/dist/proxies.js
CHANGED
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventProxy = exports.RegisteringProxy = exports.AsyncProxy = void 0;
|
|
4
|
+
exports.InvalidateResponsibleModule = InvalidateResponsibleModule;
|
|
5
|
+
exports.RunWithResponsibleModule = RunWithResponsibleModule;
|
|
4
6
|
exports.GetResponsibleModule = GetResponsibleModule;
|
|
7
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
5
9
|
const internal_1 = require("./internal");
|
|
6
10
|
const responsible_module_1 = require("./responsible-module");
|
|
7
|
-
const
|
|
8
|
-
|
|
11
|
+
const responsibleModuleContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
12
|
+
const activeResponsibleModuleTokens = new Map();
|
|
13
|
+
function getResponsibleModuleToken(module) {
|
|
14
|
+
const activeToken = activeResponsibleModuleTokens.get(module);
|
|
15
|
+
if (activeToken) {
|
|
16
|
+
return activeToken;
|
|
17
|
+
}
|
|
18
|
+
const token = Symbol(module);
|
|
19
|
+
activeResponsibleModuleTokens.set(module, token);
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
function assertActiveContext(context) {
|
|
23
|
+
if (activeResponsibleModuleTokens.get(context.module) !== context.token) {
|
|
24
|
+
throw new errors_1.ModuleContextInvalidatedError(context.module);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** @internal */
|
|
28
|
+
function InvalidateResponsibleModule(module) {
|
|
29
|
+
activeResponsibleModuleTokens.delete(module);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Runs work with an explicit responsible module.
|
|
33
|
+
*
|
|
34
|
+
* The module remains available to nested synchronous and asynchronous work.
|
|
35
|
+
* Calls outside this context continue to use stack-based module resolution.
|
|
36
|
+
*
|
|
37
|
+
* @param module Module ID responsible for the work
|
|
38
|
+
* @param callback Work to run in the module context
|
|
39
|
+
* @returns The callback result
|
|
40
|
+
*/
|
|
41
|
+
function RunWithResponsibleModule(module, callback) {
|
|
42
|
+
const inheritedContext = responsibleModuleContext.getStore();
|
|
43
|
+
if (inheritedContext) {
|
|
44
|
+
assertActiveContext(inheritedContext);
|
|
45
|
+
}
|
|
46
|
+
const context = { module, token: getResponsibleModuleToken(module) };
|
|
47
|
+
return responsibleModuleContext.run(context, callback);
|
|
48
|
+
}
|
|
9
49
|
/**
|
|
10
50
|
* Proxy for an asynchronous function.
|
|
11
51
|
*
|
|
@@ -25,12 +65,10 @@ class AsyncProxy {
|
|
|
25
65
|
* @param manualDetach Don't detach automatically when module is unloaded
|
|
26
66
|
*/
|
|
27
67
|
onCall(callback, manualDetach) {
|
|
68
|
+
const caller = manualDetach ? undefined : GetResponsibleModule();
|
|
28
69
|
this.callback = callback;
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
if (caller) {
|
|
32
|
-
internal_1.internal.addAsyncProxy(caller, this);
|
|
33
|
-
}
|
|
70
|
+
if (caller) {
|
|
71
|
+
internal_1.internal.addAsyncProxy(caller, this);
|
|
34
72
|
}
|
|
35
73
|
if (this.queue.length > 0) {
|
|
36
74
|
this.queue.forEach(({ args, resolve, reject }) => {
|
|
@@ -65,7 +103,7 @@ class AsyncProxy {
|
|
|
65
103
|
}
|
|
66
104
|
}
|
|
67
105
|
if (internal_1.internal.testStubMode) {
|
|
68
|
-
return Promise.reject(new
|
|
106
|
+
return Promise.reject(new errors_1.MissingProviderError());
|
|
69
107
|
}
|
|
70
108
|
return new Promise((resolve, reject) => this.queue.push({ args, resolve, reject }));
|
|
71
109
|
}
|
|
@@ -90,12 +128,10 @@ class RegisteringProxy {
|
|
|
90
128
|
* @param manualDetach Don't detach automatically
|
|
91
129
|
*/
|
|
92
130
|
onRegister(callback, manualDetach) {
|
|
131
|
+
const caller = manualDetach ? undefined : GetResponsibleModule();
|
|
93
132
|
this.registerCallback = callback;
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
if (caller) {
|
|
97
|
-
internal_1.internal.addRegisteringProxy(caller, this);
|
|
98
|
-
}
|
|
133
|
+
if (caller) {
|
|
134
|
+
internal_1.internal.addRegisteringProxy(caller, this);
|
|
99
135
|
}
|
|
100
136
|
for (const [id, { args }] of this.registered) {
|
|
101
137
|
try {
|
|
@@ -136,7 +172,7 @@ class RegisteringProxy {
|
|
|
136
172
|
*/
|
|
137
173
|
register(id, ...args) {
|
|
138
174
|
if (!this.registerCallback && internal_1.internal.testStubMode) {
|
|
139
|
-
throw new
|
|
175
|
+
throw new errors_1.MissingProviderError();
|
|
140
176
|
}
|
|
141
177
|
const module = GetResponsibleModule();
|
|
142
178
|
this.registered.set(id, { module, args });
|
|
@@ -249,6 +285,11 @@ function captureCallStack(startFrame = 0) {
|
|
|
249
285
|
* @returns The module ID or undefined if no module is found
|
|
250
286
|
*/
|
|
251
287
|
function GetResponsibleModule(startFrame = 0) {
|
|
288
|
+
const explicitContext = responsibleModuleContext.getStore();
|
|
289
|
+
if (explicitContext) {
|
|
290
|
+
assertActiveContext(explicitContext);
|
|
291
|
+
return explicitContext.module;
|
|
292
|
+
}
|
|
252
293
|
const trace = captureCallStack(startFrame);
|
|
253
294
|
const responsible = (0, responsible_module_1.findResponsibleFile)(trace);
|
|
254
295
|
if (responsible.module) {
|
package/dist/proxies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;AAiCA,kEAEC;AAYD,4DAUC;AAgRD,oDAaC;AAtVD,uDAAqD;AACrD,qCAA+E;AAC/E,yCAAsC;AACtC,6DAA2D;AAS3D,MAAM,wBAAwB,GAC5B,IAAI,oCAAiB,EAA4B,CAAC;AACpD,MAAM,6BAA6B,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEhE,SAAS,yBAAyB,CAAC,MAAc;IAC/C,MAAM,WAAW,GAAG,6BAA6B,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,6BAA6B,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAiC;IAC5D,IAAI,6BAA6B,CAAC,GAAG,CAAC,OAAO,CAAC,M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CAAC,QAAQ,EAAE,CAAC;IAC5D,IAAI,eAAe,EAAE,CAAC;QACpB,mBAAmB,CAAC,eAAe,CAAC,CAAC;QACrC,OAAO,eAAe,CAAC,MAAM,CAAC;IAChC,CAAC;IACD,MAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,IAAA,wCAAmB,EAAC,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,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const internal_1 = require("../internal");
|
|
7
|
+
const modules_1 = require("../modules");
|
|
8
|
+
function runDetached(module, callback) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
(0, __1.RunWithResponsibleModule)(module, () => {
|
|
11
|
+
setImmediate(() => {
|
|
12
|
+
try {
|
|
13
|
+
callback();
|
|
14
|
+
resolve(undefined);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
resolve(error);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
describe("explicit module ownership", () => {
|
|
24
|
+
let testStubMode;
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
testStubMode = internal_1.internal.testStubMode;
|
|
27
|
+
internal_1.internal.knownAsync.clear();
|
|
28
|
+
internal_1.internal.knownRegisters.clear();
|
|
29
|
+
});
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
internal_1.internal.testStubMode = testStubMode;
|
|
32
|
+
});
|
|
33
|
+
it("resolves without capturing a stack", () => {
|
|
34
|
+
const captureStackTrace = Error.captureStackTrace;
|
|
35
|
+
let captures = 0;
|
|
36
|
+
Error.captureStackTrace = (...args) => {
|
|
37
|
+
captures += 1;
|
|
38
|
+
captureStackTrace(...args);
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
(0, chai_1.expect)((0, __1.RunWithResponsibleModule)("module-a", () => (0, __1.GetResponsibleModule)())).to.equal("module-a");
|
|
42
|
+
(0, chai_1.expect)(captures).to.equal(0);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
Error.captureStackTrace = captureStackTrace;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
it("retains stack resolution outside an explicit context", () => {
|
|
49
|
+
const captureStackTrace = Error.captureStackTrace;
|
|
50
|
+
let captures = 0;
|
|
51
|
+
Error.captureStackTrace = (...args) => {
|
|
52
|
+
captures += 1;
|
|
53
|
+
captureStackTrace(...args);
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
(0, __1.GetResponsibleModule)();
|
|
57
|
+
(0, chai_1.expect)(captures).to.equal(1);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
Error.captureStackTrace = captureStackTrace;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
it("restores nested ownership", () => {
|
|
64
|
+
(0, __1.RunWithResponsibleModule)("outer", () => {
|
|
65
|
+
(0, chai_1.expect)((0, __1.GetResponsibleModule)()).to.equal("outer");
|
|
66
|
+
(0, __1.RunWithResponsibleModule)("inner", () => {
|
|
67
|
+
(0, chai_1.expect)((0, __1.GetResponsibleModule)()).to.equal("inner");
|
|
68
|
+
});
|
|
69
|
+
(0, chai_1.expect)((0, __1.GetResponsibleModule)()).to.equal("outer");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("preserves ownership across asynchronous work", async () => {
|
|
73
|
+
await (0, __1.RunWithResponsibleModule)("async-module", async () => {
|
|
74
|
+
await Promise.resolve();
|
|
75
|
+
(0, chai_1.expect)((0, __1.GetResponsibleModule)()).to.equal("async-module");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
it("does not let detached work register after module destruction", async () => {
|
|
79
|
+
const events = new __1.EventProxy();
|
|
80
|
+
let calls = 0;
|
|
81
|
+
const registration = runDetached("detached-module", () => {
|
|
82
|
+
events.register(() => {
|
|
83
|
+
calls += 1;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
modules_1.Events.ModuleDestroyed.emit("detached-module");
|
|
87
|
+
const error = await registration;
|
|
88
|
+
events.emit();
|
|
89
|
+
(0, chai_1.expect)(error).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
90
|
+
(0, chai_1.expect)(calls).to.equal(0);
|
|
91
|
+
});
|
|
92
|
+
it("keeps old work invalid after reloading the same module", async () => {
|
|
93
|
+
const events = new __1.EventProxy();
|
|
94
|
+
const calls = [];
|
|
95
|
+
const oldRegistration = runDetached("reload-module", () => {
|
|
96
|
+
(0, __1.RunWithResponsibleModule)("reload-module", () => {
|
|
97
|
+
events.register(() => calls.push("old"));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
modules_1.Events.ModuleDestroyed.emit("reload-module");
|
|
101
|
+
(0, __1.RunWithResponsibleModule)("reload-module", () => {
|
|
102
|
+
events.register(() => calls.push("new"));
|
|
103
|
+
});
|
|
104
|
+
const oldError = await oldRegistration;
|
|
105
|
+
events.emit("event");
|
|
106
|
+
(0, chai_1.expect)(oldError).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
107
|
+
(0, chai_1.expect)(calls).to.deep.equal(["new"]);
|
|
108
|
+
});
|
|
109
|
+
it("invalidates concurrent work from the destroyed generation", async () => {
|
|
110
|
+
const events = new __1.EventProxy();
|
|
111
|
+
const first = runDetached("concurrent-module", () => events.register(() => undefined));
|
|
112
|
+
const second = runDetached("concurrent-module", () => events.register(() => undefined));
|
|
113
|
+
modules_1.Events.ModuleDestroyed.emit("concurrent-module");
|
|
114
|
+
(0, chai_1.expect)(await first).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
115
|
+
(0, chai_1.expect)(await second).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
116
|
+
});
|
|
117
|
+
it("invalidates only the destroyed nested context", async () => {
|
|
118
|
+
const calls = [];
|
|
119
|
+
const events = new __1.EventProxy();
|
|
120
|
+
let inner;
|
|
121
|
+
const outer = (0, __1.RunWithResponsibleModule)("outer-module", () => {
|
|
122
|
+
inner = runDetached("inner-module", () => events.register(() => calls.push("inner")));
|
|
123
|
+
return runDetached("outer-module", () => events.register(() => calls.push("outer")));
|
|
124
|
+
});
|
|
125
|
+
modules_1.Events.ModuleDestroyed.emit("outer-module");
|
|
126
|
+
(0, chai_1.expect)(await outer).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
127
|
+
(0, chai_1.expect)(await inner).to.equal(undefined);
|
|
128
|
+
events.emit();
|
|
129
|
+
(0, chai_1.expect)(calls).to.deep.equal(["inner"]);
|
|
130
|
+
});
|
|
131
|
+
it("does not let stale providers replace a reloaded provider", async () => {
|
|
132
|
+
const proxy = new __1.AsyncProxy();
|
|
133
|
+
const staleAttachment = runDetached("provider-module", () => proxy.onCall(() => "stale"));
|
|
134
|
+
modules_1.Events.ModuleDestroyed.emit("provider-module");
|
|
135
|
+
(0, __1.RunWithResponsibleModule)("provider-module", () => proxy.onCall(() => "reloaded"));
|
|
136
|
+
(0, chai_1.expect)(await staleAttachment).to.be.instanceOf(__1.ModuleContextInvalidatedError);
|
|
137
|
+
(0, chai_1.expect)(await proxy.call()).to.equal("reloaded");
|
|
138
|
+
});
|
|
139
|
+
it("restores ownership when nested work throws", () => {
|
|
140
|
+
(0, __1.RunWithResponsibleModule)("outer", () => {
|
|
141
|
+
(0, chai_1.expect)(() => (0, __1.RunWithResponsibleModule)("inner", () => {
|
|
142
|
+
throw new Error("boom");
|
|
143
|
+
})).to.throw("boom");
|
|
144
|
+
(0, chai_1.expect)((0, __1.GetResponsibleModule)()).to.equal("outer");
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
it("detaches an async provider during module destruction", async () => {
|
|
148
|
+
const proxy = new __1.AsyncProxy();
|
|
149
|
+
(0, __1.RunWithResponsibleModule)("provider", () => proxy.onCall(() => "ready"));
|
|
150
|
+
(0, chai_1.expect)(await proxy.call()).to.equal("ready");
|
|
151
|
+
modules_1.Events.ModuleDestroyed.emit("provider");
|
|
152
|
+
internal_1.internal.testStubMode = true;
|
|
153
|
+
let rejection;
|
|
154
|
+
try {
|
|
155
|
+
await proxy.call();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
rejection = error;
|
|
159
|
+
}
|
|
160
|
+
(0, chai_1.expect)(rejection).to.be.instanceOf(errors_1.MissingProviderError);
|
|
161
|
+
});
|
|
162
|
+
it("cleans handlers and preserves replay attribution", () => {
|
|
163
|
+
const registrations = new __1.RegisteringProxy();
|
|
164
|
+
const events = new __1.EventProxy();
|
|
165
|
+
const registered = [];
|
|
166
|
+
const unregistered = [];
|
|
167
|
+
let eventCalls = 0;
|
|
168
|
+
(0, __1.RunWithResponsibleModule)("consumer", () => {
|
|
169
|
+
registrations.register("entry");
|
|
170
|
+
events.register(() => {
|
|
171
|
+
eventCalls += 1;
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
(0, __1.RunWithResponsibleModule)("provider", () => {
|
|
175
|
+
registrations.onRegister((id) => registered.push(id));
|
|
176
|
+
registrations.onUnregister((id) => unregistered.push(id));
|
|
177
|
+
});
|
|
178
|
+
(0, chai_1.expect)(registered).to.deep.equal(["entry"]);
|
|
179
|
+
modules_1.Events.ModuleDestroyed.emit("consumer");
|
|
180
|
+
events.emit();
|
|
181
|
+
(0, chai_1.expect)(eventCalls).to.equal(0);
|
|
182
|
+
(0, chai_1.expect)(registered).to.deep.equal(["entry"]);
|
|
183
|
+
(0, chai_1.expect)(unregistered).to.deep.equal(["entry"]);
|
|
184
|
+
});
|
|
185
|
+
it("detaches registering providers during hot reload", () => {
|
|
186
|
+
const proxy = new __1.RegisteringProxy();
|
|
187
|
+
const registrations = [];
|
|
188
|
+
(0, __1.RunWithResponsibleModule)("provider", () => proxy.onRegister(() => undefined));
|
|
189
|
+
modules_1.Events.ModuleDestroyed.emit("provider");
|
|
190
|
+
internal_1.internal.testStubMode = true;
|
|
191
|
+
(0, chai_1.expect)(() => proxy.register("entry")).to.throw();
|
|
192
|
+
(0, __1.RunWithResponsibleModule)("provider", () => proxy.onRegister((id) => registrations.push(id)));
|
|
193
|
+
(0, __1.RunWithResponsibleModule)("consumer", () => proxy.register("reloaded"));
|
|
194
|
+
(0, chai_1.expect)(registrations).to.deep.equal(["reloaded"]);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=module-ownership-context.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-ownership-context.test.js","sourceRoot":"","sources":["../../src/tests/module-ownership-context.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,0BAOY;AACZ,sCAAiD;AACjD,0CAAuC;AACvC,wCAAoC;AAEpC,SAAS,WAAW,CAAC,MAAc,EAAE,QAAoB;IACvD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAA,4BAAwB,EAAC,MAAM,EAAE,GAAG,EAAE;YACpC,YAAY,CAAC,GAAG,EAAE;gBAChB,IAAI,CAAC;oBACH,QAAQ,EAAE,CAAC;oBACX,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,QA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chai_1 = require("chai");
|
|
4
5
|
const __1 = require("..");
|
|
5
6
|
const internal_1 = require("../internal");
|
|
@@ -18,7 +19,8 @@ describe("test stub mode", () => {
|
|
|
18
19
|
catch (error) {
|
|
19
20
|
thrown = error;
|
|
20
21
|
}
|
|
21
|
-
(0, chai_1.expect)(thrown).to.be.instanceOf(
|
|
22
|
+
(0, chai_1.expect)(thrown).to.be.instanceOf(__1.MissingProviderError);
|
|
23
|
+
(0, chai_1.expect)(thrown.code).to.equal(__1.MISSING_PROVIDER_CODE);
|
|
22
24
|
(0, chai_1.expect)(thrown.message).to.include("without implementation");
|
|
23
25
|
});
|
|
24
26
|
it("still queues calls when stub mode is off", () => {
|
|
@@ -35,10 +37,18 @@ describe("test stub mode", () => {
|
|
|
35
37
|
});
|
|
36
38
|
});
|
|
37
39
|
describe("RegisteringProxy", () => {
|
|
38
|
-
it("throws when registering without callback in stub mode", () => {
|
|
40
|
+
it("throws MissingProviderError when registering without callback in stub mode", () => {
|
|
39
41
|
internal_1.internal.testStubMode = true;
|
|
40
42
|
const proxy = new __1.RegisteringProxy();
|
|
41
|
-
|
|
43
|
+
let thrown;
|
|
44
|
+
try {
|
|
45
|
+
proxy.register("id1");
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
thrown = error;
|
|
49
|
+
}
|
|
50
|
+
(0, chai_1.expect)(thrown).to.be.instanceOf(__1.MissingProviderError);
|
|
51
|
+
(0, chai_1.expect)(thrown.code).to.equal(__1.MISSING_PROVIDER_CODE);
|
|
42
52
|
});
|
|
43
53
|
it("still queues registration when stub mode is off", () => {
|
|
44
54
|
const proxy = new __1.RegisteringProxy();
|
|
@@ -53,5 +63,26 @@ describe("test stub mode", () => {
|
|
|
53
63
|
(0, chai_1.expect)(registered).to.deep.equal(["id1"]);
|
|
54
64
|
});
|
|
55
65
|
});
|
|
66
|
+
describe("isMissingProviderError", () => {
|
|
67
|
+
it("accepts a MissingProviderError instance", () => {
|
|
68
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)(new __1.MissingProviderError())).to.equal(true);
|
|
69
|
+
});
|
|
70
|
+
it("accepts an error carrying the code from a duplicated package copy", () => {
|
|
71
|
+
const foreignCopy = Object.assign(new Error("other wording"), {
|
|
72
|
+
code: __1.MISSING_PROVIDER_CODE,
|
|
73
|
+
});
|
|
74
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)(foreignCopy)).to.equal(true);
|
|
75
|
+
});
|
|
76
|
+
it("accepts an error carrying the code from another realm", () => {
|
|
77
|
+
const foreignRealmError = (0, node_vm_1.runInNewContext)("Object.assign(new Error('other realm'), { code })", { code: __1.MISSING_PROVIDER_CODE });
|
|
78
|
+
(0, chai_1.expect)(foreignRealmError instanceof Error).to.equal(false);
|
|
79
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)(foreignRealmError)).to.equal(true);
|
|
80
|
+
});
|
|
81
|
+
it("rejects unrelated errors and non-errors", () => {
|
|
82
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)(new Error("boom"))).to.equal(false);
|
|
83
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)({ code: __1.MISSING_PROVIDER_CODE })).to.equal(false);
|
|
84
|
+
(0, chai_1.expect)((0, __1.isMissingProviderError)(undefined)).to.equal(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
56
87
|
});
|
|
57
88
|
//# sourceMappingURL=stub-mode.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stub-mode.test.js","sourceRoot":"","sources":["../../src/tests/stub-mode.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"stub-mode.test.js","sourceRoot":"","sources":["../../src/tests/stub-mode.test.ts"],"names":[],"mappings":";;AAAA,qCAA0C;AAC1C,+BAA8B;AAC9B,0BAMY;AACZ,0CAAuC;AAEvC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,SAAS,CAAC,GAAG,EAAE;QAC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,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YACjD,IAAA,aAAM,EAAC,IAAA,0BAAsB,EAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAClE,IAAA,aAAM,EAAC,IAAA,0BAAsB,EAAC,EAAE,IAAI,EAAE,yBAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CACtE,KAAK,CACN,CAAC;YACF,IAAA,aAAM,EAAC,IAAA,0BAAsB,EAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/docs/2.proxies.md
CHANGED
|
@@ -41,7 +41,7 @@ proxy.onCall(myHandler, true);
|
|
|
41
41
|
|
|
42
42
|
### `call(...args)`
|
|
43
43
|
|
|
44
|
-
Invokes the attached callback. If no callback is attached, the call returns a `Promise` that resolves once a callback is provided. In test stub mode, unattached calls reject with
|
|
44
|
+
Invokes the attached callback. If no callback is attached, the call returns a `Promise` that resolves once a callback is provided. In test stub mode, unattached calls reject with a [`MissingProviderError`](#missingprovidererror).
|
|
45
45
|
|
|
46
46
|
### `detach()`
|
|
47
47
|
|
|
@@ -175,6 +175,25 @@ ImplementInterface(ItemInterface, {
|
|
|
175
175
|
|
|
176
176
|
`EventProxy` entries in the declaration are skipped during implementation wiring, as they are emitted from the declaring side, not implemented.
|
|
177
177
|
|
|
178
|
+
## `MissingProviderError`
|
|
179
|
+
|
|
180
|
+
In test stub mode, using a proxy that has no provider attached fails with a `MissingProviderError`: `AsyncProxy.call` rejects with it and `RegisteringProxy.register` throws it.
|
|
181
|
+
|
|
182
|
+
This error is the supported way to detect the "no provider" condition. The contract is the type and its stable `code` property (`"ERR_NO_PROVIDER"`, exported as `MISSING_PROVIDER_CODE`) - never the message text, which may change between versions.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { isMissingProviderError, MissingProviderError } from "@antelopejs/interface-core";
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
registry.register("my-entry", data);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (!isMissingProviderError(error)) throw error;
|
|
191
|
+
// Tolerate the missing provider
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Prefer the `isMissingProviderError` guard over `instanceof`: it checks the `code` property, so detection keeps working across realm boundaries and duplicated copies of the package where `instanceof` fails.
|
|
196
|
+
|
|
178
197
|
## `GetInterfaceInstances` and `GetInterfaceInstance`
|
|
179
198
|
|
|
180
199
|
These functions retrieve information about active interface connections for the current module.
|
|
@@ -199,7 +218,24 @@ import { GetResponsibleModule } from "@antelopejs/interface-core";
|
|
|
199
218
|
const moduleId = GetResponsibleModule();
|
|
200
219
|
```
|
|
201
220
|
|
|
202
|
-
> **Warning:** Calling `GetResponsibleModule` from within an async context (such as `setTimeout` or `setInterval`) breaks hot reloading. The system logs an error when this is detected.
|
|
221
|
+
> **Warning:** Calling `GetResponsibleModule` from within an async context (such as `setTimeout` or `setInterval`) without explicit ownership breaks hot reloading. The system logs an error when this is detected.
|
|
222
|
+
|
|
223
|
+
## `RunWithResponsibleModule`
|
|
224
|
+
|
|
225
|
+
`RunWithResponsibleModule` sets the responsible module explicitly for synchronous and asynchronous work. Proxy registrations made in the callback use this module directly instead of capturing and walking a stack. Nested contexts restore their parent when they complete, including when a callback throws.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { RunWithResponsibleModule } from "@antelopejs/interface-core";
|
|
229
|
+
|
|
230
|
+
await RunWithResponsibleModule("my-module", async () => {
|
|
231
|
+
proxy.onCall(myHandler);
|
|
232
|
+
await initializeModule();
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The module loader should wrap known module-owned entry points, including module evaluation and lifecycle hooks. Existing callers need no migration: outside an explicit context, `GetResponsibleModule` retains stack-based resolution as a backward-compatible fallback. Automatic proxy detachment and registration cleanup use the resolved module in both paths.
|
|
237
|
+
|
|
238
|
+
Ownership contexts are scoped to a loaded module generation. `ModuleDestroyed` invalidates that generation before cleanup, so detached asynchronous work cannot add stale providers or handlers afterward. Such work receives a `ModuleContextInvalidatedError`. A later invocation for the same module ID creates a fresh generation without reactivating older contexts.
|
|
203
239
|
|
|
204
240
|
## Next steps
|
|
205
241
|
|