@isoloop/runtime 0.1.0-next.1 → 0.1.0-next.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoloop/runtime",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0-next.11",
4
4
  "description": "Isolate-side runtime that runs inside each worker.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@isoloop/dom": "0.1.0-next.1",
39
- "@isoloop/protocol": "0.1.0-next.1"
38
+ "@isoloop/dom": "0.1.0-next.11",
39
+ "@isoloop/protocol": "0.1.0-next.11"
40
40
  },
41
41
  "devDependencies": {
42
42
  "typescript": "7.0.2"
@@ -1,161 +0,0 @@
1
- import { ErrorCode, Rect, ShutdownReason, StartPosition, TopicRef, TypedRecord } from "@isoloop/protocol";
2
- type SubscribeOptions = {
3
- /**
4
- * Default `latest`. With `group`, it applies only while the group has no
5
- * committed offset: a group that has committed resumes after it, and a
6
- * member joining a group that has members takes records from where the
7
- * group is (ADR 0016, point 14).
8
- */
9
- from?: StartPosition;
10
- /** Share the topic with other subscribers of the same group: each record goes to one of them. */
11
- group?: string;
12
- /** Default true: commit each record once its handler settles. */
13
- autoCommit?: boolean;
14
- /**
15
- * A bus restart lost this memory topic (ADR 0007). Clear what was built
16
- * from it; records from the new bus follow.
17
- */
18
- onReset?: () => void;
19
- /**
20
- * Records in `[from, to]` were dropped by retention before they reached
21
- * this subscription (design §6.3), e.g. while the isolate was suspended.
22
- */
23
- onGap?: (gap: {
24
- from: number;
25
- to: number;
26
- }) => void;
27
- };
28
- interface BusClient {
29
- /** Resolves once the broker appended the record; rejects with a `BusError`. */
30
- publish<In>(topic: TopicRef<In, any, any, any>, rec: {
31
- key?: string;
32
- value: In;
33
- }): Promise<void>;
34
- /** Returns the unsubscribe function. */
35
- subscribe<Out>(topic: TopicRef<any, Out, any, any>, fn: (r: TypedRecord<Out>) => void | Promise<void>, opts?: SubscribeOptions): () => void;
36
- /** Topics with a `reply` schema only. Rejects with `timeout` after `timeoutMs` (default 30 s). */
37
- request<In, ROut>(topic: TopicRef<In, any, any, ROut>, value: In, opts?: {
38
- key?: string;
39
- timeoutMs?: number;
40
- }): Promise<ROut>;
41
- /** Answers a request record delivered to this isolate; the broker checks `value` against the topic's `reply` schema. */
42
- reply(record: TypedRecord<unknown>, value: unknown): Promise<void>;
43
- /**
44
- * Commits a record by hand, for `autoCommit: false`: that record and every
45
- * one delivered before it on its subscription count as settled.
46
- */
47
- commit(record: TypedRecord<unknown>): void;
48
- }
49
- /** A host call that failed, with the protocol's error code. */
50
- declare class HostCallError extends Error {
51
- readonly code: ErrorCode;
52
- constructor(code: ErrorCode, message: string);
53
- }
54
- /** What `ctx.host` offers (design §4.7). */
55
- type HostApi = {
56
- /**
57
- * Asks the host to navigate (ADR 0002). Needs `grants.navigate`, else
58
- * `forbidden`. `/x` resolves against the host's `basePath`. Resolves with
59
- * the host's answer: `true` accepted, `false` refused.
60
- */
61
- navigate(href: string, o?: {
62
- replace?: boolean;
63
- state?: unknown;
64
- }): Promise<boolean>;
65
- /** The node's box relative to the surface, after pending patches apply. */
66
- measure(node: unknown): Promise<Rect>;
67
- focus(node: unknown): Promise<void>;
68
- scrollIntoView(node: unknown, opts?: ScrollIntoViewOptionsLike): Promise<void>;
69
- /**
70
- * Hands a rendered `<canvas>` to the isolate as an `OffscreenCanvas`
71
- * (design §4.7), at `size` in canvas pixels if given. Draw on it from the
72
- * worker. The element then gets `resize` events with its CSS `width` and
73
- * `height`, the first at once. Each canvas goes once; a second request
74
- * rejects with `invalid`, a headless isolate's with `no_surface`.
75
- */
76
- requestCanvas(node: unknown, size?: {
77
- width?: number;
78
- height?: number;
79
- }): Promise<OffscreenCanvas>;
80
- };
81
- type ScrollIntoViewOptionsLike = {
82
- behavior?: "auto" | "instant" | "smooth";
83
- block?: "start" | "center" | "end" | "nearest";
84
- inline?: "start" | "center" | "end" | "nearest";
85
- };
86
- /**
87
- * What a render root offers, structurally, so DOM-typed isolate code can pass
88
- * its own nodes. Use `defineIsolate<HTMLElement>(…)` to get the DOM's types.
89
- */
90
- interface IsolateRoot {
91
- append(...nodes: (object | string)[]): void;
92
- replaceChildren(...nodes: (object | string)[]): void;
93
- appendChild<T extends object>(node: T): T;
94
- insertBefore<T extends object>(node: T, ref: object | null): T;
95
- removeChild<T extends object>(node: T): T;
96
- readonly childNodes: ArrayLike<object>;
97
- textContent: string | null;
98
- addEventListener(type: string, fn: (event: never) => void, options?: unknown): void;
99
- }
100
- type IsolateContext<Root = IsolateRoot> = {
101
- readonly id: string;
102
- /** `manifest.config`, passed through. */
103
- readonly config: unknown;
104
- /** The render target; `undefined` for a headless isolate (ADR 0008). */
105
- readonly root: Root | undefined;
106
- /**
107
- * A container inside `root` for modals, tooltips, toasts and menus that
108
- * libraries would otherwise render into `document.body`, which reaches no
109
- * surface (ADR 0015, decision 11). Made on first use, typically from a
110
- * component while it renders, and added as `root`'s last child once that
111
- * render has committed; `undefined` for a headless isolate.
112
- */
113
- readonly portalRoot: Root | undefined;
114
- readonly host: HostApi;
115
- /** The log bus, on its own port to the bus worker (design §5). */
116
- readonly bus: BusClient;
117
- /** Adds stylesheets to the surface (design §4.8); a no-op when headless. */
118
- styles(css: string | readonly string[]): void;
119
- /**
120
- * Sets an `<input>`'s, `<textarea>`'s or `<select>`'s value. The host owns
121
- * a focused input's value (design §4.6), so a plain `input.value = …` waits
122
- * until the user leaves it; with `force` the host applies it at once and
123
- * keeps the caret at the end, e.g. to clear a chat box after sending.
124
- */
125
- setValue(node: unknown, value: string, opts?: {
126
- force?: boolean;
127
- }): void;
128
- /**
129
- * Reports an error as this isolate's own: framework adapters call it for a
130
- * render error their boundary caught, so in a pool it crashes only this
131
- * member, not the whole worker (ADR 0015, decision 8). `fatal` (the
132
- * default) crashes the isolate, which the host restarts as usual.
133
- */
134
- reportError(error: unknown, opts?: {
135
- fatal?: boolean;
136
- }): void;
137
- /** Runs on stop, within the host's grace period, before the worker goes. */
138
- onShutdown(fn: (reason: ShutdownReason) => void | Promise<void>): void;
139
- /**
140
- * Holds the isolate against suspension (ADR 0001); call the result to
141
- * release. Only matters for isolates spawned with `suspend`.
142
- */
143
- keepAwake(): () => void;
144
- };
145
- type IsolateDefinition<Root = IsolateRoot> = {
146
- start(ctx: IsolateContext<Root>): void | Promise<void>;
147
- /**
148
- * The Isoloop `major.minor` it was built against, stamped by
149
- * `defineIsolate` (ADR 0012). The host fails an isolate outside its
150
- * `[FLOOR, VERSION]`; a definition without one isn't checked.
151
- */
152
- requires?: string;
153
- };
154
- /** This build's stamp: `major.minor` of the package version, inlined when tsdown bundles it. */
155
- declare const REQUIRES: string;
156
- /**
157
- * Types an isolate module's default export and stamps it with the version
158
- * it was built against. `Root` defaults to the structural `IsolateRoot`.
159
- */
160
- declare function defineIsolate<Root = IsolateRoot>(def: IsolateDefinition<Root>): IsolateDefinition<Root>;
161
- export { defineIsolate as a, ScrollIntoViewOptionsLike as c, REQUIRES as i, BusClient as l, IsolateDefinition as n, HostApi as o, IsolateRoot as r, HostCallError as s, IsolateContext as t, SubscribeOptions as u };