@spearwolf/shadow-objects 0.32.0 → 0.34.0
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/CHANGELOG.md +333 -10
- package/README.md +100 -20
- package/bundle.js +5 -54
- package/package.json +7 -3
- package/src/ChangeTrailRefusedError.d.ts +27 -0
- package/src/ChangeTrailRefusedError.d.ts.map +1 -0
- package/src/ChangeTrailRefusedError.js +12 -0
- package/src/ChangeTrailRefusedError.js.map +7 -0
- package/src/EntityUuidInUseError.d.ts +19 -0
- package/src/EntityUuidInUseError.d.ts.map +1 -0
- package/src/EntityUuidInUseError.js +11 -0
- package/src/EntityUuidInUseError.js.map +7 -0
- package/src/WorkerTimeoutError.d.ts +25 -0
- package/src/WorkerTimeoutError.d.ts.map +1 -0
- package/src/WorkerTimeoutError.js +12 -0
- package/src/WorkerTimeoutError.js.map +7 -0
- package/src/bundle.d.ts +1 -1
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +1 -1
- package/src/bundle.js.map +2 -2
- package/src/constants.d.ts +9 -2
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +1 -1
- package/src/constants.js.map +2 -2
- package/src/create-worker.bundle.d.ts +1 -1
- package/src/create-worker.bundle.d.ts.map +1 -1
- package/src/create-worker.bundle.js.map +1 -1
- package/src/create-worker.d.ts +1 -1
- package/src/create-worker.d.ts.map +1 -1
- package/src/create-worker.js.map +1 -1
- package/src/elements/ShaeElement.d.ts +70 -2
- package/src/elements/ShaeElement.d.ts.map +1 -1
- package/src/elements/ShaeElement.js +129 -25
- package/src/elements/ShaeElement.js.map +3 -3
- package/src/elements/ShaeEntElement.d.ts +43 -5
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +399 -170
- package/src/elements/ShaeEntElement.js.map +2 -2
- package/src/elements/ShaeLifecycleElement.d.ts +71 -0
- package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
- package/src/elements/ShaeLifecycleElement.js +83 -0
- package/src/elements/ShaeLifecycleElement.js.map +7 -0
- package/src/elements/ShaePropElement.d.ts +57 -7
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +241 -220
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts +49 -5
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +230 -74
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/elements/constants.d.ts +6 -0
- package/src/elements/constants.d.ts.map +1 -1
- package/src/elements/constants.js +12 -0
- package/src/elements/constants.js.map +2 -2
- package/src/elements/deferredTeardown.d.ts +24 -0
- package/src/elements/deferredTeardown.d.ts.map +1 -0
- package/src/elements/deferredTeardown.js +30 -0
- package/src/elements/deferredTeardown.js.map +7 -0
- package/src/elements/displayContentsRule.d.ts +25 -0
- package/src/elements/displayContentsRule.d.ts.map +1 -0
- package/src/elements/displayContentsRule.js +37 -0
- package/src/elements/displayContentsRule.js.map +7 -0
- package/src/elements/events.d.ts +10 -7
- package/src/elements/events.d.ts.map +1 -1
- package/src/elements/forwardCustomEvents.d.ts +19 -0
- package/src/elements/forwardCustomEvents.d.ts.map +1 -0
- package/src/elements/forwardCustomEvents.js +47 -0
- package/src/elements/forwardCustomEvents.js.map +7 -0
- package/src/elements/hostedSlots.d.ts +36 -0
- package/src/elements/hostedSlots.d.ts.map +1 -0
- package/src/elements/hostedSlots.js +118 -0
- package/src/elements/hostedSlots.js.map +7 -0
- package/src/elements/parentRemoval.d.ts +18 -0
- package/src/elements/parentRemoval.d.ts.map +1 -0
- package/src/elements/parentRemoval.js +60 -0
- package/src/elements/parentRemoval.js.map +7 -0
- package/src/elements/propValueConverters.d.ts +3 -0
- package/src/elements/propValueConverters.d.ts.map +1 -0
- package/src/elements/propValueConverters.js +54 -0
- package/src/elements/propValueConverters.js.map +7 -0
- package/src/elements/requestEntAncestor.d.ts +32 -0
- package/src/elements/requestEntAncestor.d.ts.map +1 -0
- package/src/elements/requestEntAncestor.js +16 -0
- package/src/elements/requestEntAncestor.js.map +7 -0
- package/src/elements.js.map +1 -1
- package/src/in-the-dark/Entity.d.ts +113 -3
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +292 -63
- package/src/in-the-dark/Entity.js.map +3 -3
- package/src/in-the-dark/Kernel.d.ts +81 -17
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +449 -392
- package/src/in-the-dark/Kernel.js.map +3 -3
- package/src/in-the-dark/Registry.d.ts +1 -1
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +99 -26
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObject.d.ts +1 -1
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +3 -2
- package/src/in-the-dark/ShadowObject.js.map +2 -2
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts +126 -0
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js +596 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js +2 -2
- package/src/in-the-dark/SignalsPath.js.map +2 -2
- package/src/in-the-dark/events.js.map +1 -1
- package/src/in-the-dark/importModule.d.ts +7 -0
- package/src/in-the-dark/importModule.d.ts.map +1 -1
- package/src/in-the-dark/importModule.js +8 -5
- package/src/in-the-dark/importModule.js.map +2 -2
- package/src/index.d.ts +7 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -1
- package/src/index.js.map +2 -2
- package/src/shadow-objects.d.ts +2 -0
- package/src/shadow-objects.d.ts.map +1 -1
- package/src/shadow-objects.js +2 -0
- package/src/shadow-objects.js.map +2 -2
- package/src/shadow-objects.worker.js +0 -1
- package/src/shadow-objects.worker.js.map +2 -2
- package/src/shae-ent.js.map +1 -1
- package/src/shae-prop.js +2 -2
- package/src/shae-prop.js.map +2 -2
- package/src/shae-worker.js.map +1 -1
- package/src/types.d.ts +39 -8
- package/src/types.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.d.ts +45 -10
- package/src/utils/ConsoleLogger.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.js +54 -28
- package/src/utils/ConsoleLogger.js.map +2 -2
- package/src/utils/FrameLoop.d.ts +42 -3
- package/src/utils/FrameLoop.d.ts.map +1 -1
- package/src/utils/FrameLoop.js +71 -12
- package/src/utils/FrameLoop.js.map +2 -2
- package/src/utils/MicrotaskCollector.d.ts +45 -0
- package/src/utils/MicrotaskCollector.d.ts.map +1 -0
- package/src/utils/MicrotaskCollector.js +33 -0
- package/src/utils/MicrotaskCollector.js.map +7 -0
- package/src/utils/MicrotaskGate.d.ts +17 -0
- package/src/utils/MicrotaskGate.d.ts.map +1 -0
- package/src/utils/MicrotaskGate.js +20 -0
- package/src/utils/MicrotaskGate.js.map +7 -0
- package/src/utils/array-utils.js.map +1 -1
- package/src/utils/attr-utils.d.ts +6 -0
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +4 -2
- package/src/utils/attr-utils.js.map +2 -2
- package/src/utils/constants.js.map +1 -1
- package/src/utils/generateUUID.d.ts +12 -1
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/generateUUID.js +31 -266
- package/src/utils/generateUUID.js.map +2 -2
- package/src/utils/props-utils.d.ts +3 -2
- package/src/utils/props-utils.d.ts.map +1 -1
- package/src/utils/props-utils.js +13 -24
- package/src/utils/props-utils.js.map +2 -2
- package/src/utils/runGuarded.d.ts +27 -0
- package/src/utils/runGuarded.d.ts.map +1 -0
- package/src/utils/runGuarded.js +11 -0
- package/src/utils/runGuarded.js.map +7 -0
- package/src/utils/toMaybe.d.ts.map +1 -1
- package/src/utils/toMaybe.js.map +1 -1
- package/src/utils/toNamespace.d.ts.map +1 -1
- package/src/utils/toNamespace.js.map +1 -1
- package/src/utils/toUrlString.d.ts +12 -0
- package/src/utils/toUrlString.d.ts.map +1 -1
- package/src/utils/toUrlString.js.map +2 -2
- package/src/utils/waitForMessageOfType.d.ts +16 -1
- package/src/utils/waitForMessageOfType.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.js +28 -3
- package/src/utils/waitForMessageOfType.js.map +2 -2
- package/src/view/ComponentChanges.d.ts +91 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +253 -69
- package/src/view/ComponentChanges.js.map +2 -2
- package/src/view/ComponentContext.d.ts +239 -7
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +648 -115
- package/src/view/ComponentContext.js.map +2 -2
- package/src/view/ComponentMemory.d.ts +3 -3
- package/src/view/ComponentMemory.d.ts.map +1 -1
- package/src/view/ComponentMemory.js +3 -1
- package/src/view/ComponentMemory.js.map +2 -2
- package/src/view/IShadowObjectEnvProxy.d.ts +33 -1
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +2 -2
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +18 -11
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +129 -3
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +290 -60
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +73 -2
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +301 -64
- package/src/view/ShadowEnv.js.map +2 -2
- package/src/view/ViewComponent.d.ts +93 -8
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +148 -28
- package/src/view/ViewComponent.js.map +2 -2
- package/src/view/cloneChangeTrail.js.map +2 -2
- package/src/worker/MessageRouter.d.ts +14 -0
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +80 -18
- package/src/worker/MessageRouter.js.map +2 -2
- package/src/worker/WorkerRuntime.d.ts +22 -1
- package/src/worker/WorkerRuntime.d.ts.map +1 -1
- package/src/worker/WorkerRuntime.js +60 -8
- package/src/worker/WorkerRuntime.js.map +2 -2
package/src/utils/toMaybe.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/toMaybe.ts"],
|
|
4
|
-
"sourcesContent": ["import type {Maybe} from '../types.js';\n\nexport const toMaybe = <T = unknown>(value: T): Maybe<T> => value ?? undefined
|
|
4
|
+
"sourcesContent": ["import type {Maybe} from '../types.js';\n\nexport const toMaybe = <T = unknown>(value: T): Maybe<T> => value ?? undefined;\n"],
|
|
5
5
|
"mappings": "AAEO,MAAM,UAAU,CAAc,UAAuB,SAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toNamespace.d.ts","sourceRoot":"","sources":["../../../src/utils/toNamespace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE/C,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"toNamespace.d.ts","sourceRoot":"","sources":["../../../src/utils/toNamespace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE/C,eAAO,MAAM,WAAW,eAAgB,aAAa,KAAG,aAC6D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/toNamespace.ts"],
|
|
4
|
-
"sourcesContent": ["import {GlobalNS} from '../constants.js';\nimport type {NamespaceType} from '../types.js';\n\nexport const toNamespace = (namespace?: NamespaceType): NamespaceType =>\n typeof namespace === 'string' ? namespace.trim() || GlobalNS : typeof namespace === 'symbol' ? namespace : GlobalNS
|
|
4
|
+
"sourcesContent": ["import {GlobalNS} from '../constants.js';\nimport type {NamespaceType} from '../types.js';\n\nexport const toNamespace = (namespace?: NamespaceType): NamespaceType =>\n typeof namespace === 'string' ? namespace.trim() || GlobalNS : typeof namespace === 'symbol' ? namespace : GlobalNS;\n"],
|
|
5
5
|
"mappings": "AAAA,SAAQ,gBAAe;AAGhB,MAAM,cAAc,CAAC,cAC1B,OAAO,cAAc,WAAW,UAAU,KAAK,KAAK,WAAW,OAAO,cAAc,WAAW,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a module url into the string a dynamic `import()` takes.
|
|
3
|
+
*
|
|
4
|
+
* A `URL` is handed back as its own string. A string is resolved against the base url of
|
|
5
|
+
* the realm -- `globalThis.location.href`, the document on the main thread and the worker
|
|
6
|
+
* script inside a worker -- so an absolute url and a `data:` url come back unchanged,
|
|
7
|
+
* while a relative path becomes absolute against the page or worker that asked for it.
|
|
8
|
+
*
|
|
9
|
+
* The realm therefore has to have a `location`, and every environment this library runs in
|
|
10
|
+
* has one: a document, a dedicated worker, a service worker. A bare Node process has none,
|
|
11
|
+
* and a string handed in there is refused with a `TypeError`.
|
|
12
|
+
*/
|
|
1
13
|
export declare const toUrlString: (url: URL | string) => string;
|
|
2
14
|
//# sourceMappingURL=toUrlString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toUrlString.d.ts","sourceRoot":"","sources":["../../../src/utils/toUrlString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"toUrlString.d.ts","sourceRoot":"","sources":["../../../src/utils/toUrlString.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,GAAG,MAAM,KAAG,MAK/C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/toUrlString.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Turn a module url into the string a dynamic `import()` takes.\n *\n * A `URL` is handed back as its own string. A string is resolved against the base url of\n * the realm -- `globalThis.location.href`, the document on the main thread and the worker\n * script inside a worker -- so an absolute url and a `data:` url come back unchanged,\n * while a relative path becomes absolute against the page or worker that asked for it.\n *\n * The realm therefore has to have a `location`, and every environment this library runs in\n * has one: a document, a dedicated worker, a service worker. A bare Node process has none,\n * and a string handed in there is refused with a `TypeError`.\n */\nexport const toUrlString = (url: URL | string): string => {\n if (typeof url === 'string') {\n url = new URL(url, globalThis.location.href);\n }\n return url.toString();\n};\n"],
|
|
5
|
+
"mappings": "AAYO,MAAM,cAAc,CAAC,QAA8B;AACxD,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,IAAI,IAAI,KAAK,WAAW,SAAS,IAAI;AAAA,EAC7C;AACA,SAAO,IAAI,SAAS;AACtB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import type { WorkerReplyType } from '../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* The largest delay a timer actually keeps. `setTimeout()` truncates its delay into a signed
|
|
4
|
+
* 32-bit field, so a larger number comes back out as some other, shorter one: a millisecond
|
|
5
|
+
* past this bound already fires at once. Whatever it lands on, it is not the wait that was
|
|
6
|
+
* asked for, and nothing says so.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MaxWorkerTimeout = 2147483647;
|
|
9
|
+
export declare const isTimeout: (value: unknown) => value is number;
|
|
1
10
|
/**
|
|
2
11
|
* Wait for a message of a specific type or reject after a timeout.
|
|
12
|
+
*
|
|
13
|
+
* A deadline that runs out rejects with a `WorkerTimeoutError`.
|
|
14
|
+
*
|
|
15
|
+
* A `signal` rejects the promise the moment it is aborted, with the abort reason,
|
|
16
|
+
* so that a caller does not sit out the timeout waiting for a reply that can no
|
|
17
|
+
* longer arrive.
|
|
3
18
|
*/
|
|
4
|
-
export declare const waitForMessageOfType: (worker: Worker, type:
|
|
19
|
+
export declare const waitForMessageOfType: <T = unknown>(worker: Worker, type: WorkerReplyType, timeout?: number, guard?: (data: T) => boolean, signal?: AbortSignal) => Promise<void>;
|
|
5
20
|
//# sourceMappingURL=waitForMessageOfType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForMessageOfType.d.ts","sourceRoot":"","sources":["../../../src/utils/waitForMessageOfType.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"waitForMessageOfType.d.ts","sourceRoot":"","sources":["../../../src/utils/waitForMessageOfType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAIrD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,aAAgB,CAAC;AAE9C,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,KAAK,IAAI,MAC2C,CAAC;AAEhG;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,GAAG,OAAO,UACtC,MAAM,QACR,eAAe,4BAEb,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,WACnB,WAAW,kBA6DlB,CAAC"}
|
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import { WorkerTimeoutError } from "../WorkerTimeoutError.js";
|
|
2
|
+
import { isReadableMessageData } from "../worker/MessageRouter.js";
|
|
3
|
+
const MaxWorkerTimeout = 2147483647;
|
|
4
|
+
const isTimeout = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 && value <= MaxWorkerTimeout;
|
|
5
|
+
const waitForMessageOfType = (worker, type, timeout = 1e3, guard, signal) => new Promise((resolve, reject) => {
|
|
6
|
+
if (timeout !== 0 && timeout !== Infinity && !isTimeout(timeout)) {
|
|
7
|
+
reject(
|
|
8
|
+
new TypeError(
|
|
9
|
+
`cannot wait for a ${type} message: expected a timeout of 1 to ${MaxWorkerTimeout} milliseconds, or 0 or Infinity for no deadline, got ${String(timeout)}`
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (signal?.aborted) {
|
|
15
|
+
reject(signal.reason);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
2
18
|
let timeoutId;
|
|
3
19
|
let listener;
|
|
4
20
|
const cleanup = () => {
|
|
5
21
|
clearTimeout(timeoutId);
|
|
6
22
|
worker.removeEventListener("message", listener);
|
|
23
|
+
signal?.removeEventListener("abort", onAbort);
|
|
7
24
|
};
|
|
25
|
+
function onAbort() {
|
|
26
|
+
cleanup();
|
|
27
|
+
reject(signal.reason);
|
|
28
|
+
}
|
|
8
29
|
if (timeout !== 0 && timeout !== Infinity) {
|
|
9
30
|
timeoutId = setTimeout(() => {
|
|
10
31
|
cleanup();
|
|
11
|
-
reject(new
|
|
32
|
+
reject(new WorkerTimeoutError(type, timeout));
|
|
12
33
|
}, timeout);
|
|
13
34
|
}
|
|
14
35
|
listener = (event) => {
|
|
36
|
+
if (!isReadableMessageData(event.data)) return;
|
|
15
37
|
if (event.data.type === type) {
|
|
16
38
|
try {
|
|
17
39
|
if (!guard || guard(event.data)) {
|
|
@@ -20,13 +42,16 @@ const waitForMessageOfType = (worker, type, timeout = 1e3, guard) => new Promise
|
|
|
20
42
|
}
|
|
21
43
|
} catch (error) {
|
|
22
44
|
cleanup();
|
|
23
|
-
reject(error
|
|
45
|
+
reject(error);
|
|
24
46
|
}
|
|
25
47
|
}
|
|
26
48
|
};
|
|
49
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
27
50
|
worker.addEventListener("message", listener);
|
|
28
51
|
});
|
|
29
52
|
export {
|
|
53
|
+
MaxWorkerTimeout,
|
|
54
|
+
isTimeout,
|
|
30
55
|
waitForMessageOfType
|
|
31
56
|
};
|
|
32
57
|
//# sourceMappingURL=waitForMessageOfType.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/waitForMessageOfType.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Wait for a message of a specific type or reject after a timeout.\n */\nexport const waitForMessageOfType = (worker: Worker
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type {WorkerReplyType} from '../constants.js';\nimport {WorkerTimeoutError} from '../WorkerTimeoutError.js';\nimport {isReadableMessageData} from '../worker/MessageRouter.js';\n\n/**\n * The largest delay a timer actually keeps. `setTimeout()` truncates its delay into a signed\n * 32-bit field, so a larger number comes back out as some other, shorter one: a millisecond\n * past this bound already fires at once. Whatever it lands on, it is not the wait that was\n * asked for, and nothing says so.\n */\nexport const MaxWorkerTimeout = 2_147_483_647;\n\nexport const isTimeout = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0 && value <= MaxWorkerTimeout;\n\n/**\n * Wait for a message of a specific type or reject after a timeout.\n *\n * A deadline that runs out rejects with a `WorkerTimeoutError`.\n *\n * A `signal` rejects the promise the moment it is aborted, with the abort reason,\n * so that a caller does not sit out the timeout waiting for a reply that can no\n * longer arrive.\n */\nexport const waitForMessageOfType = <T = unknown>(\n worker: Worker,\n type: WorkerReplyType,\n timeout = 1000,\n guard?: (data: T) => boolean,\n signal?: AbortSignal,\n) =>\n new Promise<void>((resolve, reject) => {\n if (timeout !== 0 && timeout !== Infinity && !isTimeout(timeout)) {\n reject(\n new TypeError(\n `cannot wait for a ${type} message: expected a timeout of 1 to ${MaxWorkerTimeout} milliseconds, or 0 or Infinity for no deadline, got ${String(timeout)}`,\n ),\n );\n return;\n }\n\n if (signal?.aborted) {\n reject(signal.reason);\n return;\n }\n\n let timeoutId: ReturnType<typeof setTimeout>;\n let listener: (event: MessageEvent) => void;\n\n const cleanup = () => {\n clearTimeout(timeoutId);\n worker.removeEventListener('message', listener);\n signal?.removeEventListener('abort', onAbort);\n };\n\n // a function declaration, so that `cleanup` may reference it above its own definition;\n // it only ever runs when a signal was passed in, since that is the only case where it gets registered below\n function onAbort() {\n cleanup();\n reject(signal!.reason);\n }\n\n if (timeout !== 0 && timeout !== Infinity) {\n timeoutId = setTimeout(() => {\n cleanup();\n reject(new WorkerTimeoutError(type, timeout));\n }, timeout);\n }\n\n listener = (event) => {\n // three readers listen on this channel and answer the same way: a payload that is not\n // an object carries no `type` to route on, and reading through it takes down whoever\n // reads it -- here, into the listener of every request still waiting\n if (!isReadableMessageData(event.data)) return;\n if (event.data.type === type) {\n try {\n if (!guard || guard(event.data)) {\n cleanup();\n resolve();\n }\n } catch (error) {\n cleanup();\n reject(error);\n }\n }\n };\n\n signal?.addEventListener('abort', onAbort, {once: true});\n\n worker.addEventListener('message', listener);\n });\n"],
|
|
5
|
+
"mappings": "AACA,SAAQ,0BAAyB;AACjC,SAAQ,6BAA4B;AAQ7B,MAAM,mBAAmB;AAEzB,MAAM,YAAY,CAAC,UACxB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,KAAK,QAAQ,KAAK,SAAS;AAWxE,MAAM,uBAAuB,CAClC,QACA,MACA,UAAU,KACV,OACA,WAEA,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,MAAI,YAAY,KAAK,YAAY,YAAY,CAAC,UAAU,OAAO,GAAG;AAChE;AAAA,MACE,IAAI;AAAA,QACF,qBAAqB,IAAI,wCAAwC,gBAAgB,wDAAwD,OAAO,OAAO,CAAC;AAAA,MAC1J;AAAA,IACF;AACA;AAAA,EACF;AAEA,MAAI,QAAQ,SAAS;AACnB,WAAO,OAAO,MAAM;AACpB;AAAA,EACF;AAEA,MAAI;AACJ,MAAI;AAEJ,QAAM,UAAU,MAAM;AACpB,iBAAa,SAAS;AACtB,WAAO,oBAAoB,WAAW,QAAQ;AAC9C,YAAQ,oBAAoB,SAAS,OAAO;AAAA,EAC9C;AAIA,WAAS,UAAU;AACjB,YAAQ;AACR,WAAO,OAAQ,MAAM;AAAA,EACvB;AAEA,MAAI,YAAY,KAAK,YAAY,UAAU;AACzC,gBAAY,WAAW,MAAM;AAC3B,cAAQ;AACR,aAAO,IAAI,mBAAmB,MAAM,OAAO,CAAC;AAAA,IAC9C,GAAG,OAAO;AAAA,EACZ;AAEA,aAAW,CAAC,UAAU;AAIpB,QAAI,CAAC,sBAAsB,MAAM,IAAI,EAAG;AACxC,QAAI,MAAM,KAAK,SAAS,MAAM;AAC5B,UAAI;AACF,YAAI,CAAC,SAAS,MAAM,MAAM,IAAI,GAAG;AAC/B,kBAAQ;AACR,kBAAQ;AAAA,QACV;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ;AACR,eAAO,KAAK;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAEA,UAAQ,iBAAiB,SAAS,SAAS,EAAC,MAAM,KAAI,CAAC;AAEvD,SAAO,iBAAiB,WAAW,QAAQ;AAC7C,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,21 +1,100 @@
|
|
|
1
1
|
import { ChangeTrailPhase } from '../constants.js';
|
|
2
2
|
import type { IChangeToken, IComponentChangeType, ICreateEntitiesChange, IDestroyEntitiesChange, IPropertiesChange, ISendEvents, ISetParentChange, IUpdateOrderChange } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The value a property carries in this bookkeeping when it is set without one — the third form
|
|
5
|
+
* of {@link ComponentPropertiesType}, which travels as a one-element `[key]`. `undefined`
|
|
6
|
+
* cannot say it: that is what a removal reads as, and the two have to stay apart all the way
|
|
7
|
+
* to the entry.
|
|
8
|
+
*
|
|
9
|
+
* It never leaves the View Layer. A change trail runs through `structuredClone()` on its way
|
|
10
|
+
* to a worker, and a symbol on that wire is a `DataCloneError` — so every method that builds
|
|
11
|
+
* an entry turns it back into the one-element form, and the one reader outside this class,
|
|
12
|
+
* `ComponentContext.transferPropertiesTo()`, tests for it before it hands a value on.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PropertyWithoutValue: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* Tracks one component's outstanding changes between two change trails as four written ↔
|
|
17
|
+
* pending pairs: `#token`/`#nextToken`, `#parentUuid`/`#nextParentUuid`, `#order`/`#nextOrder`
|
|
18
|
+
* and `#properties`/`#nextProperties`. The `make*` methods read the pending half and leave it
|
|
19
|
+
* where it is: a trail entry is a request, and until the Shadow Environment has applied it the
|
|
20
|
+
* change is still owed. {@link ComponentChanges.commitChange} is what moves the line — it folds
|
|
21
|
+
* one applied entry into the written half and releases exactly the pending values that entry
|
|
22
|
+
* carried, so a value that changed again while the entry was on its way goes out with the next
|
|
23
|
+
* trail instead of being lost.
|
|
24
|
+
*
|
|
25
|
+
* Whether anything is outstanding follows from those pairs rather than from a counter, which is
|
|
26
|
+
* what lets a partly applied trail leave the rest of the component untouched.
|
|
27
|
+
*
|
|
28
|
+
* The create/destroy counts behind {@link ComponentChanges.isCreated} and {@link
|
|
29
|
+
* ComponentChanges.isDestroyed} belong to the uuid, not to a `ViewComponent` instance. They
|
|
30
|
+
* carry the rule `ComponentContext.addComponent` keeps: a uuid names one component of a
|
|
31
|
+
* `ComponentContext` at a time, so a later component takes this bookkeeping over only once
|
|
32
|
+
* its predecessor has counted its own `destroy()`. A count pair that outlives its component
|
|
33
|
+
* therefore describes an entity, and the successor on that uuid continues the same entity
|
|
34
|
+
* rather than starting a second.
|
|
35
|
+
*/
|
|
3
36
|
export declare class ComponentChanges {
|
|
4
37
|
#private;
|
|
5
38
|
get uuid(): string;
|
|
6
39
|
constructor(uuid: string);
|
|
40
|
+
/**
|
|
41
|
+
* Whether this component owes the next change trail anything: a creation, a destruction, or a
|
|
42
|
+
* pending value in one of the four written ↔ pending pairs.
|
|
43
|
+
*/
|
|
7
44
|
hasChanges(): boolean;
|
|
8
45
|
get isNew(): boolean;
|
|
9
46
|
get isCreated(): boolean;
|
|
10
47
|
get isDestroyed(): boolean;
|
|
11
48
|
create(token?: string, parentUuid?: string, order?: number, autoDestructionOnParentRemoval?: boolean): void;
|
|
12
49
|
destroy(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Drop every pending value without writing any of them forward.
|
|
52
|
+
*
|
|
53
|
+
* This is the way out for a component whose bookkeeping is about to be replaced wholesale —
|
|
54
|
+
* `ComponentContext.reCreateChanges` does exactly that. A trail that has gone out is
|
|
55
|
+
* settled with {@link ComponentChanges.commitChange} instead.
|
|
56
|
+
*/
|
|
13
57
|
clear(): void;
|
|
58
|
+
/**
|
|
59
|
+
* The three scalar pairs below all answer the same question the same way: is anything owed once
|
|
60
|
+
* the entry that is on its way out has landed?
|
|
61
|
+
*
|
|
62
|
+
* The written half alone cannot answer it. It is the last *confirmed* value and stays behind
|
|
63
|
+
* until the entry is committed, so a value the caller sets back to it while the entry travels
|
|
64
|
+
* would look like "nothing to do" — and the entry would then be the last word, leaving the
|
|
65
|
+
* Shadow Environment holding a value the view has already moved on from. So the pending half is
|
|
66
|
+
* only released where there is nothing in flight to contradict it; where there is, the new value
|
|
67
|
+
* takes the pending slot and the emitting side decides, against the written half it settles on.
|
|
68
|
+
*/
|
|
14
69
|
changeToken(token: string | undefined): void;
|
|
15
70
|
setParent(parentUuid?: string): void;
|
|
16
71
|
changeOrder(order: number): void;
|
|
17
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @returns `true` if the value differs from the last value this component asked for
|
|
74
|
+
*/
|
|
75
|
+
changeProperty<T = unknown>(key: string, value: T, isEqual?: (a: T, b: T) => boolean): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Mark `key` as set without giving it a value: the next trail carries an entry that names
|
|
78
|
+
* only the key. A later {@link ComponentChanges.changeProperty} replaces it with a value,
|
|
79
|
+
* and {@link ComponentChanges.removeProperty} takes it away like any other property.
|
|
80
|
+
*
|
|
81
|
+
* @returns `true` if this differs from the last value this component asked for
|
|
82
|
+
*/
|
|
83
|
+
setPropertyWithoutValue(key: string): boolean;
|
|
18
84
|
removeProperty(key: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* The properties this component holds at this moment: the ones a change trail has already
|
|
87
|
+
* carried, overlaid with everything that has accrued since.
|
|
88
|
+
*
|
|
89
|
+
* The overlay is what makes the result the current state instead of the state of the last
|
|
90
|
+
* trail — `#properties` is only written forward while a trail is being built
|
|
91
|
+
* ({@link ComponentChanges.makeCreateEntityChange},
|
|
92
|
+
* {@link ComponentChanges.makeChangePropertyChange}). A key whose accrued value is `undefined`
|
|
93
|
+
* and a key queued for change without an accrued value are both removals, and neither appears
|
|
94
|
+
* in the result. A key that is set without a value stands in the result with
|
|
95
|
+
* {@link PropertyWithoutValue}.
|
|
96
|
+
*/
|
|
97
|
+
getProperties(): Map<string, unknown>;
|
|
19
98
|
createEvent(type: string, data: unknown, transferables?: Transferable[]): void;
|
|
20
99
|
transferEventsTo(changes: ComponentChanges): void;
|
|
21
100
|
buildChangeTrail(trail: IComponentChangeType[], trailPhase: ChangeTrailPhase): void;
|
|
@@ -26,5 +105,16 @@ export declare class ComponentChanges {
|
|
|
26
105
|
makeUpdateOrderChange(): IUpdateOrderChange;
|
|
27
106
|
makeChangeToken(): IChangeToken;
|
|
28
107
|
makeChangePropertyChange(): IPropertiesChange;
|
|
108
|
+
/**
|
|
109
|
+
* Fold one trail entry into the written half of this component's bookkeeping: the values the
|
|
110
|
+
* entry carries become the values the next diff is taken against, and the pending half that
|
|
111
|
+
* produced them is released. Called once per entry the Shadow Environment has applied.
|
|
112
|
+
*
|
|
113
|
+
* A pending value is released only while it is still the value the entry carried. Between the
|
|
114
|
+
* build of a trail and its confirmation lies a round trip, and whatever changed in that window
|
|
115
|
+
* is owed to the Shadow Environment — releasing it here would leave the two sides holding
|
|
116
|
+
* different values with nothing left to correct them.
|
|
117
|
+
*/
|
|
118
|
+
commitChange(entry: IComponentChangeType): void;
|
|
29
119
|
}
|
|
30
120
|
//# sourceMappingURL=ComponentChanges.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentChanges.d.ts","sourceRoot":"","sources":["../../../src/view/ComponentChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAiC,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ComponentChanges.d.ts","sourceRoot":"","sources":["../../../src/view/ComponentChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAiC,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAEV,YAAY,EACZ,oBAAoB,EAEpB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,eAAkD,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAgB;;IAG3B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,YAAY,IAAI,EAAE,MAAM,EAEvB;IAMD;;;OAGG;IACH,UAAU,IAAI,OAAO,CAUpB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,WAAW,IAAI,OAAO,CAEzB;IAWD,MAAM,CAAC,KAAK,GAAE,MAAkB,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,EAAE,8BAA8B,UAAQ,QAO/G;IAED,OAAO,SAEN;IAWD;;;;;;OAMG;IACH,KAAK,SAWJ;IAED;;;;;;;;;;OAUG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,QAWpC;IAED,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,QAM5B;IAED,WAAW,CAAC,KAAK,EAAE,MAAM,QAIxB;IAwBD;;OAEG;IACH,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CA+C7F;IAED;;;;;;OAMG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;IAED,cAAc,CAAC,GAAG,EAAE,MAAM,QAgBzB;IAED;;;;;;;;;;;OAWG;IACH,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAapC;IAKD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,YAAY,EAAE,QAKtE;IAED,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,QASzC;IAED,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,gBAAgB,QAoC3E;IAED,UAAU,IAAI,WAAW,CAUxB;IAED,sBAAsB,IAAI,qBAAqB,CA2C9C;IAED,uBAAuB,IAAI,sBAAsB,CAKhD;IAED,mBAAmB,IAAI,gBAAgB,CAYtC;IAED,qBAAqB,IAAI,kBAAkB,CAM1C;IAED,eAAe,IAAI,YAAY,CAM9B;IAED,wBAAwB,IAAI,iBAAiB,CAgB5C;IAaD;;;;;;;;;OASG;IACH,YAAY,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,CA4D9C;CA0CF"}
|