@isoloop/runtime 0.1.0-next.9 → 0.1.1
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/README.md +48 -0
- package/dist/bootstrap.js +47 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -5
- package/dist/testing.d.ts +19 -6
- package/dist/testing.js +8 -0
- package/dist/vanilla-C6wHItsG.d.ts +359 -0
- package/dist/worker.js +47 -24
- package/package.json +12 -4
- package/dist/vanilla-DVmrnAWd.d.ts +0 -233
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @isoloop/runtime
|
|
2
|
+
|
|
3
|
+
The [Isoloop](https://isoloop.dev) runtime inside each worker: write a part of your app as an isolate, with a UI or headless, in plain TypeScript.
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
|
|
7
|
+
- **One way to write an isolate:** `defineIsolate` with a `start(ctx)`, for a widget, a feed, an engine or a request handler.
|
|
8
|
+
- **Plain DOM in a worker:** create elements, listen to input and style your surface, and the host draws it.
|
|
9
|
+
- **The bus:** typed publish and subscribe, straight to the bus worker, with replay after a restart.
|
|
10
|
+
- **The page when you need it:** async calls to measure, focus, scroll, navigate and get a canvas to draw on.
|
|
11
|
+
- **A lifecycle:** shutdown handlers, error reporting, and a hold against suspension.
|
|
12
|
+
- **Unit tests without a worker:** `createTestContext` from `@isoloop/runtime/testing`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @isoloop/runtime
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { defineIsolate } from '@isoloop/runtime';
|
|
24
|
+
import { count } from './topics'; // a topic from your contracts
|
|
25
|
+
|
|
26
|
+
export default defineIsolate<HTMLElement>({
|
|
27
|
+
start(ctx) {
|
|
28
|
+
const label = document.createElement('p');
|
|
29
|
+
label.textContent = 'Waiting for a count';
|
|
30
|
+
ctx.root?.append(label);
|
|
31
|
+
|
|
32
|
+
ctx.bus.subscribe(
|
|
33
|
+
count,
|
|
34
|
+
(record) => {
|
|
35
|
+
label.textContent = `Count: ${record.value}`;
|
|
36
|
+
},
|
|
37
|
+
{ from: 'earliest' },
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Learn more
|
|
44
|
+
|
|
45
|
+
- [Writing isolates](https://isoloop.dev/docs/isolates/)
|
|
46
|
+
- [Testing isolates and contracts](https://isoloop.dev/docs/testing/)
|
|
47
|
+
- [What Isoloop can't hide](https://isoloop.dev/docs/limits/)
|
|
48
|
+
- [API reference](https://isoloop.dev/docs/api/runtime/)
|
package/dist/bootstrap.js
CHANGED
|
@@ -240,8 +240,11 @@ var init_dist = __esmMin((() => {
|
|
|
240
240
|
seq
|
|
241
241
|
};
|
|
242
242
|
BusError = class extends Error {
|
|
243
|
+
/** What went wrong, to branch on: `invalid`, `forbidden`, `timeout`, `bus_unavailable`, … */
|
|
243
244
|
code;
|
|
245
|
+
/** For `invalid`: where the value failed its schema, and why. */
|
|
244
246
|
issues;
|
|
247
|
+
/** @param error The broker's error: its code, message and issues. */
|
|
245
248
|
constructor(error) {
|
|
246
249
|
super(error.message);
|
|
247
250
|
this.name = "BusError";
|
|
@@ -293,7 +296,7 @@ var init_dist = __esmMin((() => {
|
|
|
293
296
|
};
|
|
294
297
|
isInspectToIsolate = envelopeGuard(INSPECT_TO_ISOLATE);
|
|
295
298
|
}));
|
|
296
|
-
// src/busy.ts
|
|
299
|
+
// src/pools/busy.ts
|
|
297
300
|
function createBusy(now = () => performance.now()) {
|
|
298
301
|
let frame = null;
|
|
299
302
|
const spent = /* @__PURE__ */ new Map();
|
|
@@ -606,7 +609,7 @@ var init_busy = __esmMin((() => {
|
|
|
606
609
|
busy = createBusy();
|
|
607
610
|
BUSY = Symbol.for("isoloop.busy");
|
|
608
611
|
}));
|
|
609
|
-
// src/freeze.ts
|
|
612
|
+
// src/pools/freeze.ts
|
|
610
613
|
init_dist();
|
|
611
614
|
init_busy();
|
|
612
615
|
/** Constructors whose `prototype` and statics are frozen, if this engine has them. */
|
|
@@ -769,7 +772,7 @@ function freezeBuiltins() {
|
|
|
769
772
|
Object.freeze(JSON);
|
|
770
773
|
Object.freeze(Reflect);
|
|
771
774
|
}
|
|
772
|
-
// src/inspector.ts
|
|
775
|
+
// src/isolate/inspector.ts
|
|
773
776
|
function createInspectorClient() {
|
|
774
777
|
let port = null;
|
|
775
778
|
let ended = false;
|
|
@@ -950,7 +953,7 @@ var init_inspector = __esmMin((() => {
|
|
|
950
953
|
failure = (r) => r.ok ? void 0 : new BusError(r.error);
|
|
951
954
|
endedError = () => /* @__PURE__ */ new Error("inspector: its port has ended; controls no longer act");
|
|
952
955
|
}));
|
|
953
|
-
// src/bus-client.ts
|
|
956
|
+
// src/bus/bus-client.ts
|
|
954
957
|
function createBusClient(first, o = {}) {
|
|
955
958
|
const limit = o.inboxLimit ?? 1e3;
|
|
956
959
|
const now = o.now ?? (() => performance.now());
|
|
@@ -1241,7 +1244,7 @@ var init_bus_client = __esmMin((() => {
|
|
|
1241
1244
|
};
|
|
1242
1245
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
1243
1246
|
}));
|
|
1244
|
-
// src/host-calls.ts
|
|
1247
|
+
// src/isolate/host-calls.ts
|
|
1245
1248
|
function createHostCalls(opts) {
|
|
1246
1249
|
const timeoutMs = opts.timeoutMs ?? 5e3;
|
|
1247
1250
|
const pending = /* @__PURE__ */ new Map();
|
|
@@ -1315,7 +1318,12 @@ function createHostCalls(opts) {
|
|
|
1315
1318
|
var HostCallError, isRect;
|
|
1316
1319
|
var init_host_calls = __esmMin((() => {
|
|
1317
1320
|
HostCallError = class extends Error {
|
|
1321
|
+
/** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
|
|
1318
1322
|
code;
|
|
1323
|
+
/**
|
|
1324
|
+
* @param code What went wrong.
|
|
1325
|
+
* @param message A sentence for people.
|
|
1326
|
+
*/
|
|
1319
1327
|
constructor(code, message) {
|
|
1320
1328
|
super(message);
|
|
1321
1329
|
this.name = "HostCallError";
|
|
@@ -1329,7 +1337,7 @@ var init_host_calls = __esmMin((() => {
|
|
|
1329
1337
|
"height"
|
|
1330
1338
|
].every((k) => typeof Reflect.get(x, k) === "number");
|
|
1331
1339
|
}));
|
|
1332
|
-
// src/keep-awake.ts
|
|
1340
|
+
// src/isolate/keep-awake.ts
|
|
1333
1341
|
function createKeepAwake(now = () => performance.now()) {
|
|
1334
1342
|
const holds = /* @__PURE__ */ new Map();
|
|
1335
1343
|
let next = 0;
|
|
@@ -1359,7 +1367,7 @@ var ISOLOOP_DOM_FMT;
|
|
|
1359
1367
|
var init_records_qo23ZEsQ = __esmMin((() => {
|
|
1360
1368
|
ISOLOOP_DOM_FMT = "isoloop-dom@1";
|
|
1361
1369
|
}));
|
|
1362
|
-
// ../dom/dist/dom-
|
|
1370
|
+
// ../dom/dist/dom-Bd22osRG.js
|
|
1363
1371
|
function createStyle(el) {
|
|
1364
1372
|
const decls = /* @__PURE__ */ new Map();
|
|
1365
1373
|
const write = () => {
|
|
@@ -1411,7 +1419,7 @@ function createStyle(el) {
|
|
|
1411
1419
|
});
|
|
1412
1420
|
}
|
|
1413
1421
|
/**
|
|
1414
|
-
* `element.dataset
|
|
1422
|
+
* `element.dataset`: camelCase keys over the
|
|
1415
1423
|
* `data-*` attributes, so every write travels as an `attr` record.
|
|
1416
1424
|
*/
|
|
1417
1425
|
function createDataset(el) {
|
|
@@ -1652,7 +1660,7 @@ function toEvent(e) {
|
|
|
1652
1660
|
return ev;
|
|
1653
1661
|
}
|
|
1654
1662
|
var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, MEASURE, ANIMATE, LAYOUT_METHODS, LAYOUT_PROPERTIES, layoutError, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
|
|
1655
|
-
var
|
|
1663
|
+
var init_dom_Bd22osRG = __esmMin((() => {
|
|
1656
1664
|
HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
1657
1665
|
SVG_NS = "http://www.w3.org/2000/svg";
|
|
1658
1666
|
str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
@@ -1809,7 +1817,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
1809
1817
|
/**
|
|
1810
1818
|
* @internal The root this node was rendered under, once it has been. Kept
|
|
1811
1819
|
* after the node leaves the tree, so it can't move to another member's root
|
|
1812
|
-
* in a pool
|
|
1820
|
+
* in a pool.
|
|
1813
1821
|
*/
|
|
1814
1822
|
isoOwner = null;
|
|
1815
1823
|
constructor(doc, id) {
|
|
@@ -2100,7 +2108,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2100
2108
|
/** @internal */ isoStyle = null;
|
|
2101
2109
|
/** @internal */ isoClassList = null;
|
|
2102
2110
|
/** @internal */ isoDataset = null;
|
|
2103
|
-
/** @internal The offsets the last `scroll` event brought
|
|
2111
|
+
/** @internal The offsets the last `scroll` event brought. */
|
|
2104
2112
|
isoScroll = {
|
|
2105
2113
|
top: 0,
|
|
2106
2114
|
left: 0
|
|
@@ -2429,7 +2437,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2429
2437
|
body;
|
|
2430
2438
|
/**
|
|
2431
2439
|
* A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
|
|
2432
|
-
* it. The bridge doesn't render it
|
|
2440
|
+
* it. The bridge doesn't render it.
|
|
2433
2441
|
*/
|
|
2434
2442
|
head;
|
|
2435
2443
|
constructor(core) {
|
|
@@ -2459,7 +2467,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2459
2467
|
return new WDocumentFragment(this, -3);
|
|
2460
2468
|
}
|
|
2461
2469
|
/**
|
|
2462
|
-
* The first element in tree order with this `id
|
|
2470
|
+
* The first element in tree order with this `id`:
|
|
2463
2471
|
* under the render root, then the detached head. Nodes not yet inserted
|
|
2464
2472
|
* aren't in the document, so they aren't found.
|
|
2465
2473
|
*/
|
|
@@ -2480,8 +2488,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2480
2488
|
}
|
|
2481
2489
|
/**
|
|
2482
2490
|
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
2483
|
-
* 19 asks when it hoists a `<title>`.
|
|
2484
|
-
* (ADR 0010), built when a library needs them; anything else throws.
|
|
2491
|
+
* 19 asks when it hoists a `<title>`. Anything else throws.
|
|
2485
2492
|
*/
|
|
2486
2493
|
querySelector(selector) {
|
|
2487
2494
|
const steps = selector.split(">").map((t) => t.trim().toLowerCase());
|
|
@@ -2513,7 +2520,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2513
2520
|
defineHandlers(WDocument.prototype);
|
|
2514
2521
|
isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
|
|
2515
2522
|
}));
|
|
2516
|
-
// ../dom/dist/install-
|
|
2523
|
+
// ../dom/dist/install-0dSawI50.js
|
|
2517
2524
|
/**
|
|
2518
2525
|
* Exposes `dom` as the worker's `document`, `window` and DOM classes, so
|
|
2519
2526
|
* frameworks find them where they look. Only for isolates with a surface; a
|
|
@@ -2538,8 +2545,8 @@ function install(dom, scope) {
|
|
|
2538
2545
|
dom.document.defaultView = scope;
|
|
2539
2546
|
}
|
|
2540
2547
|
var DOM_GLOBALS;
|
|
2541
|
-
var
|
|
2542
|
-
|
|
2548
|
+
var init_install_0dSawI50 = __esmMin((() => {
|
|
2549
|
+
init_dom_Bd22osRG();
|
|
2543
2550
|
DOM_GLOBALS = {
|
|
2544
2551
|
Node: WNode,
|
|
2545
2552
|
Element: WElement,
|
|
@@ -2559,10 +2566,10 @@ var init_install_B_iVdCC4 = __esmMin((() => {
|
|
|
2559
2566
|
// ../dom/dist/worker.js
|
|
2560
2567
|
var init_worker = __esmMin((() => {
|
|
2561
2568
|
init_records_qo23ZEsQ();
|
|
2562
|
-
|
|
2563
|
-
|
|
2569
|
+
init_dom_Bd22osRG();
|
|
2570
|
+
init_install_0dSawI50();
|
|
2564
2571
|
}));
|
|
2565
|
-
// src/render/
|
|
2572
|
+
// src/render/render.ts
|
|
2566
2573
|
function sharedDom(scope) {
|
|
2567
2574
|
if (!shared) {
|
|
2568
2575
|
shared = createDom({
|
|
@@ -2696,8 +2703,8 @@ var init_render = __esmMin((() => {
|
|
|
2696
2703
|
headListeners = /* @__PURE__ */ new Set();
|
|
2697
2704
|
}));
|
|
2698
2705
|
// package.json
|
|
2699
|
-
var version = "0.1.
|
|
2700
|
-
// src/vanilla.ts
|
|
2706
|
+
var version = "0.1.1";
|
|
2707
|
+
// src/isolate/vanilla.ts
|
|
2701
2708
|
var vanilla_exports = /* @__PURE__ */ __exportAll({
|
|
2702
2709
|
REQUIRES: () => REQUIRES,
|
|
2703
2710
|
createVanillaIsolate: () => createVanillaIsolate,
|
|
@@ -2705,7 +2712,23 @@ var vanilla_exports = /* @__PURE__ */ __exportAll({
|
|
|
2705
2712
|
});
|
|
2706
2713
|
/**
|
|
2707
2714
|
* Types an isolate module's default export and stamps it with the version
|
|
2708
|
-
* it was built against.
|
|
2715
|
+
* it was built against.
|
|
2716
|
+
* @param def The isolate: its `start(ctx)`.
|
|
2717
|
+
* @returns The definition, with `requires` set to this build's `major.minor`.
|
|
2718
|
+
* @example
|
|
2719
|
+
* ```ts
|
|
2720
|
+
* import { defineIsolate } from '@isoloop/runtime';
|
|
2721
|
+
* import { count } from './topics';
|
|
2722
|
+
*
|
|
2723
|
+
* export default defineIsolate<HTMLElement>({
|
|
2724
|
+
* start(ctx) {
|
|
2725
|
+
* const button = document.createElement('button');
|
|
2726
|
+
* button.textContent = 'Add one';
|
|
2727
|
+
* button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
|
|
2728
|
+
* ctx.root?.append(button);
|
|
2729
|
+
* },
|
|
2730
|
+
* });
|
|
2731
|
+
* ```
|
|
2709
2732
|
*/
|
|
2710
2733
|
function defineIsolate(def) {
|
|
2711
2734
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as defineIsolate, c as ScrollIntoViewOptionsLike, d as SubscribeOptions, f as IsolateInspector, i as REQUIRES, l as BusClient, n as IsolateDefinition, o as HostApi, r as IsolateRoot, s as HostCallError, t as IsolateContext, u as RequestOptions } from "./vanilla-
|
|
1
|
+
import { a as defineIsolate, c as ScrollIntoViewOptionsLike, d as SubscribeOptions, f as IsolateInspector, i as REQUIRES, l as BusClient, n as IsolateDefinition, o as HostApi, r as IsolateRoot, s as HostCallError, t as IsolateContext, u as RequestOptions } from "./vanilla-C6wHItsG.js";
|
|
2
2
|
import { BusError } from "@isoloop/protocol";
|
|
3
3
|
export { type BusClient, BusError, type HostApi, HostCallError, type IsolateContext, type IsolateDefinition, type IsolateInspector, type IsolateRoot, REQUIRES, type RequestOptions, type ScrollIntoViewOptionsLike, type SubscribeOptions, defineIsolate };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,46 @@
|
|
|
1
1
|
import { BusError, majorMinor } from "@isoloop/protocol";
|
|
2
2
|
import "@isoloop/dom/worker";
|
|
3
|
-
// src/host-calls.ts
|
|
4
|
-
/** A host call that failed, with
|
|
3
|
+
// src/isolate/host-calls.ts
|
|
4
|
+
/** A host call (`ctx.host`) that failed, with an error code to branch on. */
|
|
5
5
|
var HostCallError = class extends Error {
|
|
6
|
+
/** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
|
|
6
7
|
code;
|
|
8
|
+
/**
|
|
9
|
+
* @param code What went wrong.
|
|
10
|
+
* @param message A sentence for people.
|
|
11
|
+
*/
|
|
7
12
|
constructor(code, message) {
|
|
8
13
|
super(message);
|
|
9
14
|
this.name = "HostCallError";
|
|
10
15
|
this.code = code;
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
|
-
// src/vanilla.ts
|
|
18
|
+
// src/isolate/vanilla.ts
|
|
14
19
|
/**
|
|
15
20
|
* This build's stamp: `major.minor` of the package version, inlined when tsdown bundles it.
|
|
16
21
|
*
|
|
17
22
|
* @internal
|
|
18
23
|
*/
|
|
19
|
-
const REQUIRES = majorMinor("0.1.
|
|
24
|
+
const REQUIRES = majorMinor("0.1.1") ?? "0.0";
|
|
20
25
|
/**
|
|
21
26
|
* Types an isolate module's default export and stamps it with the version
|
|
22
|
-
* it was built against.
|
|
27
|
+
* it was built against.
|
|
28
|
+
* @param def The isolate: its `start(ctx)`.
|
|
29
|
+
* @returns The definition, with `requires` set to this build's `major.minor`.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { defineIsolate } from '@isoloop/runtime';
|
|
33
|
+
* import { count } from './topics';
|
|
34
|
+
*
|
|
35
|
+
* export default defineIsolate<HTMLElement>({
|
|
36
|
+
* start(ctx) {
|
|
37
|
+
* const button = document.createElement('button');
|
|
38
|
+
* button.textContent = 'Add one';
|
|
39
|
+
* button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
|
|
40
|
+
* ctx.root?.append(button);
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
23
44
|
*/
|
|
24
45
|
function defineIsolate(def) {
|
|
25
46
|
return {
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { o as HostApi, t as IsolateContext } from "./vanilla-
|
|
1
|
+
import { o as HostApi, t as IsolateContext } from "./vanilla-C6wHItsG.js";
|
|
2
2
|
import { ShutdownReason } from "@isoloop/protocol";
|
|
3
|
+
/** `createTestContext`'s options. */
|
|
3
4
|
export type TestContextOptions = {
|
|
5
|
+
/** `ctx.id`. Default `'test'`. */
|
|
4
6
|
id?: string;
|
|
7
|
+
/** `ctx.config`. Default `null`. */
|
|
5
8
|
config?: unknown;
|
|
6
|
-
/** The render root,
|
|
9
|
+
/** The render root, for example an element on the test page. Default: none, a headless context. */
|
|
7
10
|
root?: object;
|
|
8
|
-
/** Answers `bus.request
|
|
11
|
+
/** Answers `bus.request`. Default: reject with `timeout` after the request's `timeoutMs`. */
|
|
9
12
|
respond?: (topic: string, value: unknown) => unknown;
|
|
10
|
-
/** Answers host calls
|
|
13
|
+
/** Answers host calls. Default: `measure` gives a zero rect, the rest resolve. */
|
|
11
14
|
host?: Partial<HostApi>;
|
|
12
15
|
};
|
|
16
|
+
/** A context to test an isolate with, and the handles to drive it and see what it did. */
|
|
13
17
|
export type TestContext = {
|
|
18
|
+
/** The context to pass to `start(ctx)`, or to render a component with. */
|
|
14
19
|
readonly ctx: IsolateContext;
|
|
15
20
|
/** What `ctx.reportError` got, in order. */
|
|
16
21
|
readonly errors: {
|
|
@@ -19,7 +24,7 @@ export type TestContext = {
|
|
|
19
24
|
}[];
|
|
20
25
|
/** Delivers a record to every subscription on `topic`, in order. */
|
|
21
26
|
emit: (topic: string, value: unknown, key?: string) => void;
|
|
22
|
-
/** Runs `onReset` of every subscription on `topic
|
|
27
|
+
/** Runs `onReset` of every subscription on `topic`, as when a bus restart loses a memory topic. */
|
|
23
28
|
reset: (topic: string) => void;
|
|
24
29
|
/** Every `publish`, in order. */
|
|
25
30
|
readonly published: {
|
|
@@ -32,7 +37,15 @@ export type TestContext = {
|
|
|
32
37
|
topic: string;
|
|
33
38
|
from: string;
|
|
34
39
|
}[];
|
|
35
|
-
/** Runs the `onShutdown` handlers, as the runtime does on `stop`. */
|
|
40
|
+
/** Runs the `onShutdown` handlers, as the runtime does on `stop`. `reason` defaults to `'stop'`. */
|
|
36
41
|
shutdown: (reason?: ShutdownReason) => Promise<void>;
|
|
37
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Makes an `IsolateContext` with no worker, bus or host behind it, for
|
|
45
|
+
* testing an isolate or a component on a page. The test drives the bus
|
|
46
|
+
* (`emit`, `reset`) and sees what the isolate did (`published`,
|
|
47
|
+
* `subscriptions`, `errors`). `ctx.inspector` is `undefined`.
|
|
48
|
+
* @param o The id, config, root, and how requests and host calls are answered.
|
|
49
|
+
* @returns The context and its handles.
|
|
50
|
+
*/
|
|
38
51
|
export declare function createTestContext(o?: TestContextOptions): TestContext;
|
package/dist/testing.js
CHANGED
|
@@ -6,6 +6,14 @@ const ZERO = {
|
|
|
6
6
|
width: 0,
|
|
7
7
|
height: 0
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Makes an `IsolateContext` with no worker, bus or host behind it, for
|
|
11
|
+
* testing an isolate or a component on a page. The test drives the bus
|
|
12
|
+
* (`emit`, `reset`) and sees what the isolate did (`published`,
|
|
13
|
+
* `subscriptions`, `errors`). `ctx.inspector` is `undefined`.
|
|
14
|
+
* @param o The id, config, root, and how requests and host calls are answered.
|
|
15
|
+
* @returns The context and its handles.
|
|
16
|
+
*/
|
|
9
17
|
function createTestContext(o = {}) {
|
|
10
18
|
const subs = /* @__PURE__ */ new Set();
|
|
11
19
|
const published = [];
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { ErrorCode, InspectMessage, InspectRecord, InspectSnapshot, Rect, ShutdownReason, StartPosition, TopicRef, TypedRecord } from "@isoloop/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* The inspection feed and its controls, as an isolate with `inspect: true`
|
|
4
|
+
* sees them: `ctx.inspector`, on a port of its own to the host. It's
|
|
5
|
+
* `undefined` without the grant.
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
type IsolateInspector = {
|
|
9
|
+
/**
|
|
10
|
+
* The feed's state now.
|
|
11
|
+
* @returns Isolates, pools, the bus, and the last 200 events. Once the port
|
|
12
|
+
* has ended, the last snapshot it got, if any.
|
|
13
|
+
*/
|
|
14
|
+
snapshot(): Promise<InspectSnapshot>;
|
|
15
|
+
/**
|
|
16
|
+
* The host's feed messages from now on: events at once, beats and bus
|
|
17
|
+
* metrics about once a second.
|
|
18
|
+
* @param fn Called with each message.
|
|
19
|
+
* @returns The function that stops them.
|
|
20
|
+
*/
|
|
21
|
+
on(fn: (m: InspectMessage) => void): () => void;
|
|
22
|
+
/**
|
|
23
|
+
* The last records of a topic still retained, oldest first, as previews.
|
|
24
|
+
* @param topic The topic's name.
|
|
25
|
+
* @param o `last`: how many, at most 100.
|
|
26
|
+
* @returns The records.
|
|
27
|
+
* @throws Rejects with a `BusError` from the bus.
|
|
28
|
+
*/
|
|
29
|
+
records(topic: string, o: {
|
|
30
|
+
last: number;
|
|
31
|
+
}): Promise<InspectRecord[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Records appended to matching topics, as previews. Not a consumer: it
|
|
34
|
+
* isn't in the bus figures.
|
|
35
|
+
* @param o `topics`: names or patterns. `maxPerSec`: at most this many a
|
|
36
|
+
* second, default 50. `onSkipped`: gets each count of records left out
|
|
37
|
+
* over the cap, at most once a second.
|
|
38
|
+
* @param fn Called with each record.
|
|
39
|
+
* @returns The function that ends it.
|
|
40
|
+
*/
|
|
41
|
+
tap(o: {
|
|
42
|
+
topics: string[];
|
|
43
|
+
maxPerSec?: number;
|
|
44
|
+
onSkipped?: (count: number) => void;
|
|
45
|
+
}, fn: (r: InspectRecord) => void): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Restarts an isolate, as `kernel.restart(id)` does.
|
|
48
|
+
* @param id The isolate's id.
|
|
49
|
+
* @returns Resolves once the restart has started.
|
|
50
|
+
* @throws Rejects for an unknown id, and once the port has ended.
|
|
51
|
+
*/
|
|
52
|
+
restart(id: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Ends an isolate's worker as a crash (`worker_error`), so the supervisor
|
|
55
|
+
* restarts it. For a pooled isolate that ends the pool's worker: every
|
|
56
|
+
* member crashes and restarts, and the feed shows each one.
|
|
57
|
+
* @param id The isolate's id.
|
|
58
|
+
* @returns Resolves once the kill is sent, not when the isolate is back.
|
|
59
|
+
* @throws Rejects for an unknown id, and once the port has ended.
|
|
60
|
+
*/
|
|
61
|
+
kill(id: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Busy-loops an isolate's worker.
|
|
64
|
+
* @param id The isolate's id.
|
|
65
|
+
* @param ms How long, at most 10 000 (10 s).
|
|
66
|
+
* @returns Resolves once the block is sent.
|
|
67
|
+
* @throws Rejects for an unknown id, and once the port has ended.
|
|
68
|
+
*/
|
|
69
|
+
block(id: string, ms: number): Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
/** `bus.request`'s options. @experimental */
|
|
72
|
+
type RequestOptions = {
|
|
73
|
+
/** The request record's key. Default: none. */
|
|
74
|
+
key?: string;
|
|
75
|
+
/** How long to wait for a reply, in ms; the call then rejects with `BusError('timeout')`. Default 30 000 (30 s). */
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
};
|
|
78
|
+
/** `bus.subscribe`'s options. */
|
|
79
|
+
type SubscribeOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* Where to start. Default `latest`. With `group`, it applies only while the
|
|
82
|
+
* group has no committed offset: a group that has committed resumes after
|
|
83
|
+
* it, and a member joining a group that has members takes records from
|
|
84
|
+
* where the group is.
|
|
85
|
+
*/
|
|
86
|
+
from?: StartPosition;
|
|
87
|
+
/** Share the topic with other subscribers of the same group: each record goes to one of them. Default: none. @experimental */
|
|
88
|
+
group?: string;
|
|
89
|
+
/** Commit each record once its handler settles. Default true. @experimental */
|
|
90
|
+
autoCommit?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* A bus restart lost this memory topic. Clear what was built from it;
|
|
93
|
+
* records from the new bus follow. Default: none.
|
|
94
|
+
*/
|
|
95
|
+
onReset?: () => void;
|
|
96
|
+
/**
|
|
97
|
+
* Records in `[from, to]` were dropped by retention before they reached
|
|
98
|
+
* this subscription, for example while the isolate was suspended. Default: none.
|
|
99
|
+
*/
|
|
100
|
+
onGap?: (gap: {
|
|
101
|
+
from: number;
|
|
102
|
+
to: number;
|
|
103
|
+
}) => void;
|
|
104
|
+
};
|
|
105
|
+
/** An isolate's side of the bus: `ctx.bus`, on its own port to the bus worker. */
|
|
106
|
+
interface BusClient {
|
|
107
|
+
/**
|
|
108
|
+
* Appends a record to a topic.
|
|
109
|
+
* @param topic The topic, from the contracts.
|
|
110
|
+
* @param rec The record's `value`, and its `key` if any.
|
|
111
|
+
* @returns Resolves once the broker has appended the record.
|
|
112
|
+
* @throws Rejects with a `BusError`, for example `forbidden` without a
|
|
113
|
+
* publish grant, `invalid` when the value fails the schema, or
|
|
114
|
+
* `bus_unavailable` while 1,000 calls wait for an answer.
|
|
115
|
+
*/
|
|
116
|
+
publish<In>(topic: TopicRef<In, any, any, any>, rec: {
|
|
117
|
+
key?: string;
|
|
118
|
+
value: In;
|
|
119
|
+
}): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Delivers a topic's records to `fn`, one at a time, in order: the next
|
|
122
|
+
* waits until `fn`'s promise settles. One subscription per topic:
|
|
123
|
+
* subscribing again replaces the last one.
|
|
124
|
+
* @param topic The topic, from the contracts.
|
|
125
|
+
* @param fn Called with each record.
|
|
126
|
+
* @param opts Where to start, the group, and the reset and gap handlers.
|
|
127
|
+
* @returns The function that unsubscribes.
|
|
128
|
+
*/
|
|
129
|
+
subscribe<Out>(topic: TopicRef<any, Out, any, any>, fn: (r: TypedRecord<Out>) => void | Promise<void>, opts?: SubscribeOptions): () => void;
|
|
130
|
+
/**
|
|
131
|
+
* Appends a request record to a topic with a `reply` schema and waits for
|
|
132
|
+
* the first valid reply.
|
|
133
|
+
* @param topic A topic with a `reply` schema.
|
|
134
|
+
* @param value The request's value, checked against the topic's schema.
|
|
135
|
+
* @param opts The key and the timeout.
|
|
136
|
+
* @returns The reply's value, checked against the `reply` schema.
|
|
137
|
+
* @throws Rejects with a `BusError`: `timeout` after `timeoutMs` (default
|
|
138
|
+
* 30 s); `dropped` at once when the topic's retention removed the request
|
|
139
|
+
* before the bus delivered it to any subscriber; `not_requestable`,
|
|
140
|
+
* `forbidden`, `invalid` or `reply_invalid` from the broker.
|
|
141
|
+
* @experimental
|
|
142
|
+
*/
|
|
143
|
+
request<In, ROut>(topic: TopicRef<In, any, any, ROut>, value: In, opts?: RequestOptions): Promise<ROut>;
|
|
144
|
+
/**
|
|
145
|
+
* Answers a request record delivered to this isolate.
|
|
146
|
+
* @param record The request, as the subscription delivered it.
|
|
147
|
+
* @param value The answer; the broker checks it against the topic's `reply` schema.
|
|
148
|
+
* @returns Resolves once the broker has the reply.
|
|
149
|
+
* @throws `Error` for a record not delivered to this isolate; rejects with a
|
|
150
|
+
* `BusError` (`reply_invalid`, …) from the broker.
|
|
151
|
+
* @experimental
|
|
152
|
+
*/
|
|
153
|
+
reply(record: TypedRecord<unknown>, value: unknown): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Commits a record by hand, for `autoCommit: false`: that record and every
|
|
156
|
+
* one delivered before it on its subscription count as settled.
|
|
157
|
+
* @param record A record this isolate's subscription delivered.
|
|
158
|
+
* @throws `Error` for a record not delivered to this isolate.
|
|
159
|
+
* @experimental
|
|
160
|
+
*/
|
|
161
|
+
commit(record: TypedRecord<unknown>): void;
|
|
162
|
+
}
|
|
163
|
+
/** A host call (`ctx.host`) that failed, with an error code to branch on. */
|
|
164
|
+
declare class HostCallError extends Error {
|
|
165
|
+
/** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
|
|
166
|
+
readonly code: ErrorCode;
|
|
167
|
+
/**
|
|
168
|
+
* @param code What went wrong.
|
|
169
|
+
* @param message A sentence for people.
|
|
170
|
+
*/
|
|
171
|
+
constructor(code: ErrorCode, message: string);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* What `ctx.host` offers: calls the host runs on the main thread for the
|
|
175
|
+
* isolate. Each runs after the DOM changes made before it, and rejects with a
|
|
176
|
+
* `HostCallError`: `timeout` after 5 s without an answer, `not_found` for a
|
|
177
|
+
* node that isn't rendered, `no_surface` in a headless isolate.
|
|
178
|
+
*/
|
|
179
|
+
type HostApi = {
|
|
180
|
+
/**
|
|
181
|
+
* Asks the host to navigate. `/x` resolves against the host's `basePath`.
|
|
182
|
+
* @param href Where to go: same-origin.
|
|
183
|
+
* @param o `replace` the current history entry rather than push one, and the `state` to set.
|
|
184
|
+
* @returns The host's answer: `true` accepted, `false` refused.
|
|
185
|
+
* @throws `HostCallError` `forbidden` without `grants.navigate`, or
|
|
186
|
+
* `routing_disabled` when the host turned routing off.
|
|
187
|
+
*/
|
|
188
|
+
navigate(href: string, o?: {
|
|
189
|
+
replace?: boolean;
|
|
190
|
+
state?: unknown;
|
|
191
|
+
}): Promise<boolean>;
|
|
192
|
+
/**
|
|
193
|
+
* Measures a rendered node, after pending changes apply.
|
|
194
|
+
* @param node A node this isolate rendered.
|
|
195
|
+
* @returns Its box relative to the surface, in CSS pixels.
|
|
196
|
+
*/
|
|
197
|
+
measure(node: unknown): Promise<Rect>;
|
|
198
|
+
/**
|
|
199
|
+
* Focuses a rendered node on the page.
|
|
200
|
+
* @param node A node this isolate rendered.
|
|
201
|
+
* @returns Resolves once the host has focused it.
|
|
202
|
+
*/
|
|
203
|
+
focus(node: unknown): Promise<void>;
|
|
204
|
+
/**
|
|
205
|
+
* Scrolls the page so a rendered node is in view.
|
|
206
|
+
* @param node A node this isolate rendered.
|
|
207
|
+
* @param opts As the DOM's `scrollIntoView` takes them.
|
|
208
|
+
* @returns Resolves once the host has scrolled.
|
|
209
|
+
*/
|
|
210
|
+
scrollIntoView(node: unknown, opts?: ScrollIntoViewOptionsLike): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Hands a rendered `<canvas>` to the isolate as an `OffscreenCanvas`. Draw
|
|
213
|
+
* on it from the worker. The element then gets `resize` events with its CSS
|
|
214
|
+
* `width` and `height`, the first at once.
|
|
215
|
+
* @param node A `<canvas>` this isolate rendered.
|
|
216
|
+
* @param size Its size in canvas pixels, if given.
|
|
217
|
+
* @returns The canvas, transferred to the worker.
|
|
218
|
+
* @throws `HostCallError` `invalid` for a canvas already handed over (each
|
|
219
|
+
* goes once), `no_surface` in a headless isolate.
|
|
220
|
+
*/
|
|
221
|
+
requestCanvas(node: unknown, size?: {
|
|
222
|
+
width?: number;
|
|
223
|
+
height?: number;
|
|
224
|
+
}): Promise<OffscreenCanvas>;
|
|
225
|
+
};
|
|
226
|
+
/** `scrollIntoView`'s options, typed here since worker code has no DOM types. */
|
|
227
|
+
type ScrollIntoViewOptionsLike = {
|
|
228
|
+
/** Default `'auto'`. */
|
|
229
|
+
behavior?: "auto" | "instant" | "smooth";
|
|
230
|
+
/** Default `'start'`. */
|
|
231
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
232
|
+
/** Default `'nearest'`. */
|
|
233
|
+
inline?: "start" | "center" | "end" | "nearest";
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* What a render root offers, structurally, so DOM-typed isolate code can pass
|
|
237
|
+
* its own nodes. Each member works as the DOM's. Use
|
|
238
|
+
* `defineIsolate<HTMLElement>(…)` to get the DOM's types instead.
|
|
239
|
+
*/
|
|
240
|
+
interface IsolateRoot {
|
|
241
|
+
append(...nodes: (object | string)[]): void;
|
|
242
|
+
replaceChildren(...nodes: (object | string)[]): void;
|
|
243
|
+
appendChild<T extends object>(node: T): T;
|
|
244
|
+
insertBefore<T extends object>(node: T, ref: object | null): T;
|
|
245
|
+
removeChild<T extends object>(node: T): T;
|
|
246
|
+
readonly childNodes: ArrayLike<object>;
|
|
247
|
+
textContent: string | null;
|
|
248
|
+
addEventListener(type: string, fn: (event: never) => void, options?: unknown): void;
|
|
249
|
+
}
|
|
250
|
+
/** An isolate's whole world, as `start(ctx)` gets it. */
|
|
251
|
+
type IsolateContext<Root = IsolateRoot> = {
|
|
252
|
+
/** The isolate's id, from the manifest. */
|
|
253
|
+
readonly id: string;
|
|
254
|
+
/** `manifest.config`, passed through. */
|
|
255
|
+
readonly config: unknown;
|
|
256
|
+
/** The render target inside the surface; `undefined` for a headless isolate. */
|
|
257
|
+
readonly root: Root | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* A container inside `root` for modals, tooltips, toasts and menus that
|
|
260
|
+
* libraries would otherwise render into `document.body`, which reaches no
|
|
261
|
+
* surface. Made on first use, typically from a component while it renders,
|
|
262
|
+
* and added as `root`'s last child once that render has committed;
|
|
263
|
+
* `undefined` for a headless isolate.
|
|
264
|
+
*/
|
|
265
|
+
readonly portalRoot: Root | undefined;
|
|
266
|
+
/** Calls the host runs on the main thread: navigate, measure, focus, scroll, hand over a canvas. */
|
|
267
|
+
readonly host: HostApi;
|
|
268
|
+
/** The bus, on its own port to the bus worker. */
|
|
269
|
+
readonly bus: BusClient;
|
|
270
|
+
/**
|
|
271
|
+
* The inspection feed and its controls, on a port of its own to the host;
|
|
272
|
+
* `undefined` unless the isolate holds `inspect: true`.
|
|
273
|
+
* @experimental
|
|
274
|
+
*/
|
|
275
|
+
readonly inspector: IsolateInspector | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* Adds stylesheets to the surface; a no-op when headless.
|
|
278
|
+
* @param css One stylesheet's text, or several.
|
|
279
|
+
*/
|
|
280
|
+
styles(css: string | readonly string[]): void;
|
|
281
|
+
/**
|
|
282
|
+
* Sets an `<input>`'s, `<textarea>`'s or `<select>`'s value. The host owns
|
|
283
|
+
* a focused input's value, so a plain `input.value = …` waits until the
|
|
284
|
+
* user leaves it; with `force` the host applies it at once and keeps the
|
|
285
|
+
* caret at the end, for example to clear a chat box after sending.
|
|
286
|
+
* @param node The element, as this isolate rendered it.
|
|
287
|
+
* @param value The new value.
|
|
288
|
+
* @param opts `force`: apply it even while the user is in the field. Default false.
|
|
289
|
+
*/
|
|
290
|
+
setValue(node: unknown, value: string, opts?: {
|
|
291
|
+
force?: boolean;
|
|
292
|
+
}): void;
|
|
293
|
+
/**
|
|
294
|
+
* Reports an error as this isolate's own: framework adapters call it for a
|
|
295
|
+
* render error their boundary caught, so in a pool it crashes only this
|
|
296
|
+
* member, not the whole worker.
|
|
297
|
+
* @param error What was thrown.
|
|
298
|
+
* @param opts `fatal`: crash the isolate, which the host restarts as usual.
|
|
299
|
+
* Default true. With false the host emits `isolate:error` and the isolate
|
|
300
|
+
* keeps running.
|
|
301
|
+
*/
|
|
302
|
+
reportError(error: unknown, opts?: {
|
|
303
|
+
fatal?: boolean;
|
|
304
|
+
}): void;
|
|
305
|
+
/**
|
|
306
|
+
* Adds a handler that runs on stop, within the host's grace period (1 s),
|
|
307
|
+
* before the worker goes.
|
|
308
|
+
* @param fn Gets why the isolate is stopping; may return a promise.
|
|
309
|
+
*/
|
|
310
|
+
onShutdown(fn: (reason: ShutdownReason) => void | Promise<void>): void;
|
|
311
|
+
/**
|
|
312
|
+
* Holds the isolate against suspension. Only matters for isolates spawned
|
|
313
|
+
* with `suspend`.
|
|
314
|
+
* @returns The function that releases the hold.
|
|
315
|
+
*/
|
|
316
|
+
keepAwake(): () => void;
|
|
317
|
+
};
|
|
318
|
+
/** An isolate module's default export: what `defineIsolate` returns. */
|
|
319
|
+
type IsolateDefinition<Root = IsolateRoot> = {
|
|
320
|
+
/**
|
|
321
|
+
* Runs once, when the isolate starts in its worker. A `start` that throws,
|
|
322
|
+
* or whose promise rejects, crashes the isolate.
|
|
323
|
+
*/
|
|
324
|
+
start(ctx: IsolateContext<Root>): void | Promise<void>;
|
|
325
|
+
/**
|
|
326
|
+
* The Isoloop `major.minor` it was built against, stamped by
|
|
327
|
+
* `defineIsolate`. The host fails an isolate built for a newer Isoloop, or
|
|
328
|
+
* for one older than it still runs; a definition without one isn't checked.
|
|
329
|
+
*/
|
|
330
|
+
requires?: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* This build's stamp: `major.minor` of the package version, inlined when tsdown bundles it.
|
|
334
|
+
*
|
|
335
|
+
* @internal
|
|
336
|
+
*/
|
|
337
|
+
declare const REQUIRES: string;
|
|
338
|
+
/**
|
|
339
|
+
* Types an isolate module's default export and stamps it with the version
|
|
340
|
+
* it was built against.
|
|
341
|
+
* @param def The isolate: its `start(ctx)`.
|
|
342
|
+
* @returns The definition, with `requires` set to this build's `major.minor`.
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* import { defineIsolate } from '@isoloop/runtime';
|
|
346
|
+
* import { count } from './topics';
|
|
347
|
+
*
|
|
348
|
+
* export default defineIsolate<HTMLElement>({
|
|
349
|
+
* start(ctx) {
|
|
350
|
+
* const button = document.createElement('button');
|
|
351
|
+
* button.textContent = 'Add one';
|
|
352
|
+
* button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
|
|
353
|
+
* ctx.root?.append(button);
|
|
354
|
+
* },
|
|
355
|
+
* });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function defineIsolate<Root = IsolateRoot>(def: IsolateDefinition<Root>): IsolateDefinition<Root>;
|
|
359
|
+
export { defineIsolate as a, ScrollIntoViewOptionsLike as c, SubscribeOptions as d, IsolateInspector as f, REQUIRES as i, BusClient as l, IsolateDefinition as n, HostApi as o, IsolateRoot as r, HostCallError as s, IsolateContext as t, RequestOptions as u };
|
package/dist/worker.js
CHANGED
|
@@ -240,8 +240,11 @@ var init_dist = __esmMin((() => {
|
|
|
240
240
|
seq
|
|
241
241
|
};
|
|
242
242
|
BusError = class extends Error {
|
|
243
|
+
/** What went wrong, to branch on: `invalid`, `forbidden`, `timeout`, `bus_unavailable`, … */
|
|
243
244
|
code;
|
|
245
|
+
/** For `invalid`: where the value failed its schema, and why. */
|
|
244
246
|
issues;
|
|
247
|
+
/** @param error The broker's error: its code, message and issues. */
|
|
245
248
|
constructor(error) {
|
|
246
249
|
super(error.message);
|
|
247
250
|
this.name = "BusError";
|
|
@@ -293,7 +296,7 @@ var init_dist = __esmMin((() => {
|
|
|
293
296
|
};
|
|
294
297
|
isInspectToIsolate = envelopeGuard(INSPECT_TO_ISOLATE);
|
|
295
298
|
}));
|
|
296
|
-
// src/busy.ts
|
|
299
|
+
// src/pools/busy.ts
|
|
297
300
|
function createBusy(now = () => performance.now()) {
|
|
298
301
|
let frame = null;
|
|
299
302
|
const spent = /* @__PURE__ */ new Map();
|
|
@@ -606,7 +609,7 @@ var init_busy = __esmMin((() => {
|
|
|
606
609
|
busy = createBusy();
|
|
607
610
|
BUSY = Symbol.for("isoloop.busy");
|
|
608
611
|
}));
|
|
609
|
-
// src/freeze.ts
|
|
612
|
+
// src/pools/freeze.ts
|
|
610
613
|
/** The protected properties, per prototype, that are left as frozen data. */
|
|
611
614
|
function protectedProperties() {
|
|
612
615
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -750,7 +753,7 @@ var init_freeze = __esmMin((() => {
|
|
|
750
753
|
];
|
|
751
754
|
ITERATOR = Symbol.iterator;
|
|
752
755
|
}));
|
|
753
|
-
// src/inspector.ts
|
|
756
|
+
// src/isolate/inspector.ts
|
|
754
757
|
function createInspectorClient() {
|
|
755
758
|
let port = null;
|
|
756
759
|
let ended = false;
|
|
@@ -932,7 +935,7 @@ var init_inspector = __esmMin((() => {
|
|
|
932
935
|
failure = (r) => r.ok ? void 0 : new BusError(r.error);
|
|
933
936
|
endedError = () => /* @__PURE__ */ new Error("inspector: its port has ended; controls no longer act");
|
|
934
937
|
}));
|
|
935
|
-
// src/bus-client.ts
|
|
938
|
+
// src/bus/bus-client.ts
|
|
936
939
|
function createBusClient(first, o = {}) {
|
|
937
940
|
const limit = o.inboxLimit ?? 1e3;
|
|
938
941
|
const now = o.now ?? (() => performance.now());
|
|
@@ -1223,7 +1226,7 @@ var init_bus_client = __esmMin((() => {
|
|
|
1223
1226
|
};
|
|
1224
1227
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
1225
1228
|
}));
|
|
1226
|
-
// src/host-calls.ts
|
|
1229
|
+
// src/isolate/host-calls.ts
|
|
1227
1230
|
function createHostCalls(opts) {
|
|
1228
1231
|
const timeoutMs = opts.timeoutMs ?? 5e3;
|
|
1229
1232
|
const pending = /* @__PURE__ */ new Map();
|
|
@@ -1297,7 +1300,12 @@ function createHostCalls(opts) {
|
|
|
1297
1300
|
var HostCallError, isRect;
|
|
1298
1301
|
var init_host_calls = __esmMin((() => {
|
|
1299
1302
|
HostCallError = class extends Error {
|
|
1303
|
+
/** What went wrong: `not_found`, `no_surface`, `forbidden`, `invalid`, `timeout`, … */
|
|
1300
1304
|
code;
|
|
1305
|
+
/**
|
|
1306
|
+
* @param code What went wrong.
|
|
1307
|
+
* @param message A sentence for people.
|
|
1308
|
+
*/
|
|
1301
1309
|
constructor(code, message) {
|
|
1302
1310
|
super(message);
|
|
1303
1311
|
this.name = "HostCallError";
|
|
@@ -1311,7 +1319,7 @@ var init_host_calls = __esmMin((() => {
|
|
|
1311
1319
|
"height"
|
|
1312
1320
|
].every((k) => typeof Reflect.get(x, k) === "number");
|
|
1313
1321
|
}));
|
|
1314
|
-
// src/keep-awake.ts
|
|
1322
|
+
// src/isolate/keep-awake.ts
|
|
1315
1323
|
function createKeepAwake(now = () => performance.now()) {
|
|
1316
1324
|
const holds = /* @__PURE__ */ new Map();
|
|
1317
1325
|
let next = 0;
|
|
@@ -1341,7 +1349,7 @@ var ISOLOOP_DOM_FMT;
|
|
|
1341
1349
|
var init_records_qo23ZEsQ = __esmMin((() => {
|
|
1342
1350
|
ISOLOOP_DOM_FMT = "isoloop-dom@1";
|
|
1343
1351
|
}));
|
|
1344
|
-
// ../dom/dist/dom-
|
|
1352
|
+
// ../dom/dist/dom-Bd22osRG.js
|
|
1345
1353
|
function createStyle(el) {
|
|
1346
1354
|
const decls = /* @__PURE__ */ new Map();
|
|
1347
1355
|
const write = () => {
|
|
@@ -1393,7 +1401,7 @@ function createStyle(el) {
|
|
|
1393
1401
|
});
|
|
1394
1402
|
}
|
|
1395
1403
|
/**
|
|
1396
|
-
* `element.dataset
|
|
1404
|
+
* `element.dataset`: camelCase keys over the
|
|
1397
1405
|
* `data-*` attributes, so every write travels as an `attr` record.
|
|
1398
1406
|
*/
|
|
1399
1407
|
function createDataset(el) {
|
|
@@ -1634,7 +1642,7 @@ function toEvent(e) {
|
|
|
1634
1642
|
return ev;
|
|
1635
1643
|
}
|
|
1636
1644
|
var HTML_NS, SVG_NS, str, domError, emit, WEventTarget, WNode, WCharacterData, WText, WComment, kebab, WDOMTokenList, dataAttr, dataKey, WParentNode, WDocumentFragment, WElement, HANDLER_EVENTS, MEASURE, ANIMATE, LAYOUT_METHODS, LAYOUT_PROPERTIES, layoutError, WHTMLElement, WSVGElement, WHTMLIFrameElement, WHTMLInputElement, WHTMLTextAreaElement, WHTMLSelectElement, WHTMLOptionElement, HTML_CLASSES, WDocument, isControl;
|
|
1637
|
-
var
|
|
1645
|
+
var init_dom_Bd22osRG = __esmMin((() => {
|
|
1638
1646
|
HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
1639
1647
|
SVG_NS = "http://www.w3.org/2000/svg";
|
|
1640
1648
|
str = (v) => typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
@@ -1791,7 +1799,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
1791
1799
|
/**
|
|
1792
1800
|
* @internal The root this node was rendered under, once it has been. Kept
|
|
1793
1801
|
* after the node leaves the tree, so it can't move to another member's root
|
|
1794
|
-
* in a pool
|
|
1802
|
+
* in a pool.
|
|
1795
1803
|
*/
|
|
1796
1804
|
isoOwner = null;
|
|
1797
1805
|
constructor(doc, id) {
|
|
@@ -2082,7 +2090,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2082
2090
|
/** @internal */ isoStyle = null;
|
|
2083
2091
|
/** @internal */ isoClassList = null;
|
|
2084
2092
|
/** @internal */ isoDataset = null;
|
|
2085
|
-
/** @internal The offsets the last `scroll` event brought
|
|
2093
|
+
/** @internal The offsets the last `scroll` event brought. */
|
|
2086
2094
|
isoScroll = {
|
|
2087
2095
|
top: 0,
|
|
2088
2096
|
left: 0
|
|
@@ -2411,7 +2419,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2411
2419
|
body;
|
|
2412
2420
|
/**
|
|
2413
2421
|
* A detached head: React 19 hoists `<title>`, `<meta>` and `<link>` into
|
|
2414
|
-
* it. The bridge doesn't render it
|
|
2422
|
+
* it. The bridge doesn't render it.
|
|
2415
2423
|
*/
|
|
2416
2424
|
head;
|
|
2417
2425
|
constructor(core) {
|
|
@@ -2441,7 +2449,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2441
2449
|
return new WDocumentFragment(this, -3);
|
|
2442
2450
|
}
|
|
2443
2451
|
/**
|
|
2444
|
-
* The first element in tree order with this `id
|
|
2452
|
+
* The first element in tree order with this `id`:
|
|
2445
2453
|
* under the render root, then the detached head. Nodes not yet inserted
|
|
2446
2454
|
* aren't in the document, so they aren't found.
|
|
2447
2455
|
*/
|
|
@@ -2462,8 +2470,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2462
2470
|
}
|
|
2463
2471
|
/**
|
|
2464
2472
|
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
2465
|
-
* 19 asks when it hoists a `<title>`.
|
|
2466
|
-
* (ADR 0010), built when a library needs them; anything else throws.
|
|
2473
|
+
* 19 asks when it hoists a `<title>`. Anything else throws.
|
|
2467
2474
|
*/
|
|
2468
2475
|
querySelector(selector) {
|
|
2469
2476
|
const steps = selector.split(">").map((t) => t.trim().toLowerCase());
|
|
@@ -2495,7 +2502,7 @@ var init_dom_N7iz67ez = __esmMin((() => {
|
|
|
2495
2502
|
defineHandlers(WDocument.prototype);
|
|
2496
2503
|
isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
|
|
2497
2504
|
}));
|
|
2498
|
-
// ../dom/dist/install-
|
|
2505
|
+
// ../dom/dist/install-0dSawI50.js
|
|
2499
2506
|
/**
|
|
2500
2507
|
* Exposes `dom` as the worker's `document`, `window` and DOM classes, so
|
|
2501
2508
|
* frameworks find them where they look. Only for isolates with a surface; a
|
|
@@ -2520,8 +2527,8 @@ function install(dom, scope) {
|
|
|
2520
2527
|
dom.document.defaultView = scope;
|
|
2521
2528
|
}
|
|
2522
2529
|
var DOM_GLOBALS;
|
|
2523
|
-
var
|
|
2524
|
-
|
|
2530
|
+
var init_install_0dSawI50 = __esmMin((() => {
|
|
2531
|
+
init_dom_Bd22osRG();
|
|
2525
2532
|
DOM_GLOBALS = {
|
|
2526
2533
|
Node: WNode,
|
|
2527
2534
|
Element: WElement,
|
|
@@ -2541,10 +2548,10 @@ var init_install_B_iVdCC4 = __esmMin((() => {
|
|
|
2541
2548
|
// ../dom/dist/worker.js
|
|
2542
2549
|
var init_worker = __esmMin((() => {
|
|
2543
2550
|
init_records_qo23ZEsQ();
|
|
2544
|
-
|
|
2545
|
-
|
|
2551
|
+
init_dom_Bd22osRG();
|
|
2552
|
+
init_install_0dSawI50();
|
|
2546
2553
|
}));
|
|
2547
|
-
// src/render/
|
|
2554
|
+
// src/render/render.ts
|
|
2548
2555
|
function sharedDom(scope) {
|
|
2549
2556
|
if (!shared) {
|
|
2550
2557
|
shared = createDom({
|
|
@@ -2679,8 +2686,8 @@ var init_render = __esmMin((() => {
|
|
|
2679
2686
|
headListeners = /* @__PURE__ */ new Set();
|
|
2680
2687
|
}));
|
|
2681
2688
|
// package.json
|
|
2682
|
-
var version = "0.1.
|
|
2683
|
-
// src/vanilla.ts
|
|
2689
|
+
var version = "0.1.1";
|
|
2690
|
+
// src/isolate/vanilla.ts
|
|
2684
2691
|
var vanilla_exports = /* @__PURE__ */ __exportAll({
|
|
2685
2692
|
REQUIRES: () => REQUIRES,
|
|
2686
2693
|
createVanillaIsolate: () => createVanillaIsolate,
|
|
@@ -2688,7 +2695,23 @@ var vanilla_exports = /* @__PURE__ */ __exportAll({
|
|
|
2688
2695
|
});
|
|
2689
2696
|
/**
|
|
2690
2697
|
* Types an isolate module's default export and stamps it with the version
|
|
2691
|
-
* it was built against.
|
|
2698
|
+
* it was built against.
|
|
2699
|
+
* @param def The isolate: its `start(ctx)`.
|
|
2700
|
+
* @returns The definition, with `requires` set to this build's `major.minor`.
|
|
2701
|
+
* @example
|
|
2702
|
+
* ```ts
|
|
2703
|
+
* import { defineIsolate } from '@isoloop/runtime';
|
|
2704
|
+
* import { count } from './topics';
|
|
2705
|
+
*
|
|
2706
|
+
* export default defineIsolate<HTMLElement>({
|
|
2707
|
+
* start(ctx) {
|
|
2708
|
+
* const button = document.createElement('button');
|
|
2709
|
+
* button.textContent = 'Add one';
|
|
2710
|
+
* button.addEventListener('click', () => void ctx.bus.publish(count, { value: 1 }));
|
|
2711
|
+
* ctx.root?.append(button);
|
|
2712
|
+
* },
|
|
2713
|
+
* });
|
|
2714
|
+
* ```
|
|
2692
2715
|
*/
|
|
2693
2716
|
function defineIsolate(def) {
|
|
2694
2717
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isoloop/runtime",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The Isoloop runtime: write a part of your app as an isolate in a worker, with a UI or headless, in plain TypeScript.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"isoloop",
|
|
7
|
+
"web-workers",
|
|
8
|
+
"event-loop",
|
|
9
|
+
"isolation",
|
|
10
|
+
"microfrontends"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://isoloop.dev/docs/api/runtime/",
|
|
5
13
|
"license": "MIT",
|
|
6
14
|
"type": "module",
|
|
7
15
|
"sideEffects": [
|
|
@@ -35,8 +43,8 @@
|
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
45
|
"dependencies": {
|
|
38
|
-
"@isoloop/dom": "0.1.
|
|
39
|
-
"@isoloop/protocol": "0.1.
|
|
46
|
+
"@isoloop/dom": "0.1.1",
|
|
47
|
+
"@isoloop/protocol": "0.1.1"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {
|
|
42
50
|
"typescript": "7.0.2"
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { ErrorCode, InspectMessage, InspectRecord, InspectSnapshot, Rect, ShutdownReason, StartPosition, TopicRef, TypedRecord } from "@isoloop/protocol";
|
|
2
|
-
/**
|
|
3
|
-
* The inspection feed and its controls, as an isolate with `inspect: true`
|
|
4
|
-
* sees them (ADR 0020, decision 6). `ctx.inspector` is `undefined` without
|
|
5
|
-
* the grant.
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
type IsolateInspector = {
|
|
9
|
-
/**
|
|
10
|
-
* Isolates, pools, the bus, and the last 200 events. Once the port has
|
|
11
|
-
* ended it resolves with the last snapshot it got, if any.
|
|
12
|
-
*/
|
|
13
|
-
snapshot(): Promise<InspectSnapshot>;
|
|
14
|
-
/**
|
|
15
|
-
* The host's feed messages from now on: events at once, beats and bus
|
|
16
|
-
* metrics about once a second. Returns the function that stops them.
|
|
17
|
-
*/
|
|
18
|
-
on(fn: (m: InspectMessage) => void): () => void;
|
|
19
|
-
/** The last `last` retained records of `topic` (at most 100), oldest first, as previews. */
|
|
20
|
-
records(topic: string, o: {
|
|
21
|
-
last: number;
|
|
22
|
-
}): Promise<InspectRecord[]>;
|
|
23
|
-
/**
|
|
24
|
-
* Records appended to matching topics, at most `maxPerSec` a second
|
|
25
|
-
* (default 50), as previews. Not a consumer: it isn't in the bus figures.
|
|
26
|
-
* `onSkipped` gets each count of records left out over the cap, at most
|
|
27
|
-
* once a second (ADR 0020, decision 6, amended 2026-11-19). Returns the
|
|
28
|
-
* function that ends it.
|
|
29
|
-
*/
|
|
30
|
-
tap(o: {
|
|
31
|
-
topics: string[];
|
|
32
|
-
maxPerSec?: number;
|
|
33
|
-
onSkipped?: (count: number) => void;
|
|
34
|
-
}, fn: (r: InspectRecord) => void): () => void;
|
|
35
|
-
/**
|
|
36
|
-
* Restarts an isolate, as `kernel.restart(id)` does. Like `kill` and
|
|
37
|
-
* `block`, it rejects for an unknown id, and once the port has ended.
|
|
38
|
-
*/
|
|
39
|
-
restart(id: string): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Ends an isolate's worker as a crash (`worker_error`), so the supervisor
|
|
42
|
-
* restarts it. For a pooled isolate that ends the pool's worker: every
|
|
43
|
-
* member crashes and restarts, and the feed shows each one. Resolves once
|
|
44
|
-
* the kill is sent, not when the isolate is back.
|
|
45
|
-
*/
|
|
46
|
-
kill(id: string): Promise<void>;
|
|
47
|
-
/** Busy-loops an isolate's worker for `ms`, at most 10 s. */
|
|
48
|
-
block(id: string, ms: number): Promise<void>;
|
|
49
|
-
};
|
|
50
|
-
/** `request`'s options. @experimental */
|
|
51
|
-
type RequestOptions = {
|
|
52
|
-
/** The request record's key. */
|
|
53
|
-
key?: string;
|
|
54
|
-
/** Default 30 s: the call rejects with `BusError('timeout')` after it. */
|
|
55
|
-
timeoutMs?: number;
|
|
56
|
-
};
|
|
57
|
-
type SubscribeOptions = {
|
|
58
|
-
/**
|
|
59
|
-
* Default `latest`. With `group`, it applies only while the group has no
|
|
60
|
-
* committed offset: a group that has committed resumes after it, and a
|
|
61
|
-
* member joining a group that has members takes records from where the
|
|
62
|
-
* group is (ADR 0016, point 14).
|
|
63
|
-
*/
|
|
64
|
-
from?: StartPosition;
|
|
65
|
-
/** Share the topic with other subscribers of the same group: each record goes to one of them. @experimental */
|
|
66
|
-
group?: string;
|
|
67
|
-
/** Default true: commit each record once its handler settles. @experimental */
|
|
68
|
-
autoCommit?: boolean;
|
|
69
|
-
/**
|
|
70
|
-
* A bus restart lost this memory topic (ADR 0007). Clear what was built
|
|
71
|
-
* from it; records from the new bus follow.
|
|
72
|
-
*/
|
|
73
|
-
onReset?: () => void;
|
|
74
|
-
/**
|
|
75
|
-
* Records in `[from, to]` were dropped by retention before they reached
|
|
76
|
-
* this subscription (design §6.3), e.g. while the isolate was suspended.
|
|
77
|
-
*/
|
|
78
|
-
onGap?: (gap: {
|
|
79
|
-
from: number;
|
|
80
|
-
to: number;
|
|
81
|
-
}) => void;
|
|
82
|
-
};
|
|
83
|
-
interface BusClient {
|
|
84
|
-
/** Resolves once the broker appended the record; rejects with a `BusError`. */
|
|
85
|
-
publish<In>(topic: TopicRef<In, any, any, any>, rec: {
|
|
86
|
-
key?: string;
|
|
87
|
-
value: In;
|
|
88
|
-
}): Promise<void>;
|
|
89
|
-
/** Returns the unsubscribe function. */
|
|
90
|
-
subscribe<Out>(topic: TopicRef<any, Out, any, any>, fn: (r: TypedRecord<Out>) => void | Promise<void>, opts?: SubscribeOptions): () => void;
|
|
91
|
-
/**
|
|
92
|
-
* Topics with a `reply` schema only. Rejects with `timeout` after
|
|
93
|
-
* `timeoutMs` (default 30 s), or with `dropped` at once when the topic's
|
|
94
|
-
* retention removed the request before the bus delivered it to any
|
|
95
|
-
* subscriber.
|
|
96
|
-
* @experimental
|
|
97
|
-
*/
|
|
98
|
-
request<In, ROut>(topic: TopicRef<In, any, any, ROut>, value: In, opts?: RequestOptions): Promise<ROut>;
|
|
99
|
-
/**
|
|
100
|
-
* Answers a request record delivered to this isolate; the broker checks `value` against the topic's `reply` schema.
|
|
101
|
-
* @experimental
|
|
102
|
-
*/
|
|
103
|
-
reply(record: TypedRecord<unknown>, value: unknown): Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Commits a record by hand, for `autoCommit: false`: that record and every
|
|
106
|
-
* one delivered before it on its subscription count as settled.
|
|
107
|
-
* @experimental
|
|
108
|
-
*/
|
|
109
|
-
commit(record: TypedRecord<unknown>): void;
|
|
110
|
-
}
|
|
111
|
-
/** A host call that failed, with the protocol's error code. */
|
|
112
|
-
declare class HostCallError extends Error {
|
|
113
|
-
readonly code: ErrorCode;
|
|
114
|
-
constructor(code: ErrorCode, message: string);
|
|
115
|
-
}
|
|
116
|
-
/** What `ctx.host` offers (design §4.7). */
|
|
117
|
-
type HostApi = {
|
|
118
|
-
/**
|
|
119
|
-
* Asks the host to navigate (ADR 0002). Needs `grants.navigate`, else
|
|
120
|
-
* `forbidden`. `/x` resolves against the host's `basePath`. Resolves with
|
|
121
|
-
* the host's answer: `true` accepted, `false` refused.
|
|
122
|
-
*/
|
|
123
|
-
navigate(href: string, o?: {
|
|
124
|
-
replace?: boolean;
|
|
125
|
-
state?: unknown;
|
|
126
|
-
}): Promise<boolean>;
|
|
127
|
-
/** The node's box relative to the surface, after pending patches apply. */
|
|
128
|
-
measure(node: unknown): Promise<Rect>;
|
|
129
|
-
focus(node: unknown): Promise<void>;
|
|
130
|
-
scrollIntoView(node: unknown, opts?: ScrollIntoViewOptionsLike): Promise<void>;
|
|
131
|
-
/**
|
|
132
|
-
* Hands a rendered `<canvas>` to the isolate as an `OffscreenCanvas`
|
|
133
|
-
* (design §4.7), at `size` in canvas pixels if given. Draw on it from the
|
|
134
|
-
* worker. The element then gets `resize` events with its CSS `width` and
|
|
135
|
-
* `height`, the first at once. Each canvas goes once; a second request
|
|
136
|
-
* rejects with `invalid`, a headless isolate's with `no_surface`.
|
|
137
|
-
*/
|
|
138
|
-
requestCanvas(node: unknown, size?: {
|
|
139
|
-
width?: number;
|
|
140
|
-
height?: number;
|
|
141
|
-
}): Promise<OffscreenCanvas>;
|
|
142
|
-
};
|
|
143
|
-
type ScrollIntoViewOptionsLike = {
|
|
144
|
-
behavior?: "auto" | "instant" | "smooth";
|
|
145
|
-
block?: "start" | "center" | "end" | "nearest";
|
|
146
|
-
inline?: "start" | "center" | "end" | "nearest";
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* What a render root offers, structurally, so DOM-typed isolate code can pass
|
|
150
|
-
* its own nodes. Use `defineIsolate<HTMLElement>(…)` to get the DOM's types.
|
|
151
|
-
*/
|
|
152
|
-
interface IsolateRoot {
|
|
153
|
-
append(...nodes: (object | string)[]): void;
|
|
154
|
-
replaceChildren(...nodes: (object | string)[]): void;
|
|
155
|
-
appendChild<T extends object>(node: T): T;
|
|
156
|
-
insertBefore<T extends object>(node: T, ref: object | null): T;
|
|
157
|
-
removeChild<T extends object>(node: T): T;
|
|
158
|
-
readonly childNodes: ArrayLike<object>;
|
|
159
|
-
textContent: string | null;
|
|
160
|
-
addEventListener(type: string, fn: (event: never) => void, options?: unknown): void;
|
|
161
|
-
}
|
|
162
|
-
type IsolateContext<Root = IsolateRoot> = {
|
|
163
|
-
readonly id: string;
|
|
164
|
-
/** `manifest.config`, passed through. */
|
|
165
|
-
readonly config: unknown;
|
|
166
|
-
/** The render target; `undefined` for a headless isolate (ADR 0008). */
|
|
167
|
-
readonly root: Root | undefined;
|
|
168
|
-
/**
|
|
169
|
-
* A container inside `root` for modals, tooltips, toasts and menus that
|
|
170
|
-
* libraries would otherwise render into `document.body`, which reaches no
|
|
171
|
-
* surface (ADR 0015, decision 11). Made on first use, typically from a
|
|
172
|
-
* component while it renders, and added as `root`'s last child once that
|
|
173
|
-
* render has committed; `undefined` for a headless isolate.
|
|
174
|
-
*/
|
|
175
|
-
readonly portalRoot: Root | undefined;
|
|
176
|
-
readonly host: HostApi;
|
|
177
|
-
/** The log bus, on its own port to the bus worker (design §5). */
|
|
178
|
-
readonly bus: BusClient;
|
|
179
|
-
/**
|
|
180
|
-
* The inspection feed and its controls (ADR 0020, decision 6), on a port of
|
|
181
|
-
* its own to the host; `undefined` unless the isolate holds `inspect: true`.
|
|
182
|
-
* @experimental
|
|
183
|
-
*/
|
|
184
|
-
readonly inspector: IsolateInspector | undefined;
|
|
185
|
-
/** Adds stylesheets to the surface (design §4.8); a no-op when headless. */
|
|
186
|
-
styles(css: string | readonly string[]): void;
|
|
187
|
-
/**
|
|
188
|
-
* Sets an `<input>`'s, `<textarea>`'s or `<select>`'s value. The host owns
|
|
189
|
-
* a focused input's value (design §4.6), so a plain `input.value = …` waits
|
|
190
|
-
* until the user leaves it; with `force` the host applies it at once and
|
|
191
|
-
* keeps the caret at the end, e.g. to clear a chat box after sending.
|
|
192
|
-
*/
|
|
193
|
-
setValue(node: unknown, value: string, opts?: {
|
|
194
|
-
force?: boolean;
|
|
195
|
-
}): void;
|
|
196
|
-
/**
|
|
197
|
-
* Reports an error as this isolate's own: framework adapters call it for a
|
|
198
|
-
* render error their boundary caught, so in a pool it crashes only this
|
|
199
|
-
* member, not the whole worker (ADR 0015, decision 8). `fatal` (the
|
|
200
|
-
* default) crashes the isolate, which the host restarts as usual.
|
|
201
|
-
*/
|
|
202
|
-
reportError(error: unknown, opts?: {
|
|
203
|
-
fatal?: boolean;
|
|
204
|
-
}): void;
|
|
205
|
-
/** Runs on stop, within the host's grace period, before the worker goes. */
|
|
206
|
-
onShutdown(fn: (reason: ShutdownReason) => void | Promise<void>): void;
|
|
207
|
-
/**
|
|
208
|
-
* Holds the isolate against suspension (ADR 0001); call the result to
|
|
209
|
-
* release. Only matters for isolates spawned with `suspend`.
|
|
210
|
-
*/
|
|
211
|
-
keepAwake(): () => void;
|
|
212
|
-
};
|
|
213
|
-
type IsolateDefinition<Root = IsolateRoot> = {
|
|
214
|
-
start(ctx: IsolateContext<Root>): void | Promise<void>;
|
|
215
|
-
/**
|
|
216
|
-
* The Isoloop `major.minor` it was built against, stamped by
|
|
217
|
-
* `defineIsolate` (ADR 0012). The host fails an isolate outside its
|
|
218
|
-
* `[FLOOR, VERSION]`; a definition without one isn't checked.
|
|
219
|
-
*/
|
|
220
|
-
requires?: string;
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* This build's stamp: `major.minor` of the package version, inlined when tsdown bundles it.
|
|
224
|
-
*
|
|
225
|
-
* @internal
|
|
226
|
-
*/
|
|
227
|
-
declare const REQUIRES: string;
|
|
228
|
-
/**
|
|
229
|
-
* Types an isolate module's default export and stamps it with the version
|
|
230
|
-
* it was built against. `Root` defaults to the structural `IsolateRoot`.
|
|
231
|
-
*/
|
|
232
|
-
declare function defineIsolate<Root = IsolateRoot>(def: IsolateDefinition<Root>): IsolateDefinition<Root>;
|
|
233
|
-
export { defineIsolate as a, ScrollIntoViewOptionsLike as c, SubscribeOptions as d, IsolateInspector as f, REQUIRES as i, BusClient as l, IsolateDefinition as n, HostApi as o, IsolateRoot as r, HostCallError as s, IsolateContext as t, RequestOptions as u };
|