@pritzlaff/nano-ui 0.4.0 → 0.5.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/explorer-details.d.ts +44 -0
- package/explorer-nodes.d.ts +9 -0
- package/explorer.d.ts +22 -6
- package/filter/filter.d.ts +40 -0
- package/filter/model.d.ts +25 -0
- package/index.d.ts +17 -2
- package/index.js +1785 -187
- package/index.js.map +39 -15
- package/interfaces.d.ts +127 -1
- package/layout.d.ts +3 -11
- package/observe/bar.d.ts +46 -0
- package/observe/clock-driver.d.ts +16 -0
- package/observe/entry.d.ts +66 -0
- package/observe/fold.d.ts +14 -0
- package/observe/in-flight.d.ts +10 -0
- package/observe/memory-store.d.ts +5 -0
- package/observe/record.d.ts +15 -0
- package/observe/replay.d.ts +56 -0
- package/observe/restart-order.d.ts +3 -0
- package/observe/ring-view.d.ts +86 -0
- package/observe/ring.d.ts +38 -0
- package/observe/shadow.d.ts +18 -0
- package/observe/time-machine.d.ts +55 -0
- package/package.json +3 -3
- package/pods/clock.d.ts +3 -0
- package/pods/debounce.d.ts +4 -1
- package/pods/input.d.ts +3 -0
- package/pods/random.d.ts +5 -0
- package/pods/sim-clock.d.ts +3 -0
- package/views/debounce-model.d.ts +72 -0
- package/views/debounce-parts.d.ts +12 -0
- package/views/debounce.d.ts +36 -0
- package/views/faces.d.ts +0 -13
- package/views/input.d.ts +9 -0
- package/views/view.d.ts +3 -2
package/interfaces.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { Type } from 'typebox';
|
|
7
7
|
export declare const Any: import("@pritzlaff/nano-core").SchemaDef<Type.TUnknown>;
|
|
8
8
|
export declare const Nothing: import("@pritzlaff/nano-core").SchemaDef<Type.TNull>;
|
|
9
|
-
/**
|
|
9
|
+
/** Each returns its input, so its result can be piped: `submit` when the user submits, `change` on every edit. */
|
|
10
10
|
export declare const Input: import("@pritzlaff/nano-core").Interface<{
|
|
11
11
|
submit: {
|
|
12
12
|
readonly kind: "action";
|
|
@@ -17,7 +17,17 @@ export declare const Input: import("@pritzlaff/nano-core").Interface<{
|
|
|
17
17
|
readonly name: "submit";
|
|
18
18
|
readonly coord: string;
|
|
19
19
|
};
|
|
20
|
+
change: {
|
|
21
|
+
readonly kind: "action";
|
|
22
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TUnknown> | undefined;
|
|
23
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TUnknown> | undefined;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
} & {
|
|
26
|
+
readonly name: "change";
|
|
27
|
+
readonly coord: string;
|
|
28
|
+
};
|
|
20
29
|
}>;
|
|
30
|
+
/** A flush publishes the newest value as `flushed` and everything queued since the last flush, oldest first, as `batch`. */
|
|
21
31
|
export declare const Debounce: import("@pritzlaff/nano-core").Interface<{
|
|
22
32
|
push: {
|
|
23
33
|
readonly kind: "action";
|
|
@@ -37,6 +47,15 @@ export declare const Debounce: import("@pritzlaff/nano-core").Interface<{
|
|
|
37
47
|
readonly name: "flushed";
|
|
38
48
|
readonly coord: string;
|
|
39
49
|
};
|
|
50
|
+
batch: {
|
|
51
|
+
readonly kind: "event";
|
|
52
|
+
readonly input?: undefined;
|
|
53
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TArray<Type.TUnknown>> | undefined;
|
|
54
|
+
readonly description?: string;
|
|
55
|
+
} & {
|
|
56
|
+
readonly name: "batch";
|
|
57
|
+
readonly coord: string;
|
|
58
|
+
};
|
|
40
59
|
}>;
|
|
41
60
|
export declare const MapIface: import("@pritzlaff/nano-core").Interface<{
|
|
42
61
|
map: {
|
|
@@ -111,3 +130,110 @@ export declare const HostUI: import("@pritzlaff/nano-core").Interface<{
|
|
|
111
130
|
readonly coord: string;
|
|
112
131
|
};
|
|
113
132
|
}>;
|
|
133
|
+
/** What the host offers a pod to change the deployment: `deploy` adds pods and runtimes (an existing name is
|
|
134
|
+
* `invalid-input`, or with `onConflict: 'overwrite'` replaced), `undeploy` removes runtimes and the pods placed nowhere else. The host's deployment policy decides. */
|
|
135
|
+
export declare const HostDeploy: import("@pritzlaff/nano-core").Interface<{
|
|
136
|
+
deploy: {
|
|
137
|
+
readonly kind: "action";
|
|
138
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TObject<{
|
|
139
|
+
pods: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
140
|
+
runtimes: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
141
|
+
onConflict: Type.TOptional<Type.TUnion<[Type.TLiteral<"error">, Type.TLiteral<"overwrite">]>>;
|
|
142
|
+
}>> | undefined;
|
|
143
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
144
|
+
readonly description?: string;
|
|
145
|
+
} & {
|
|
146
|
+
readonly name: "deploy";
|
|
147
|
+
readonly coord: string;
|
|
148
|
+
};
|
|
149
|
+
undeploy: {
|
|
150
|
+
readonly kind: "action";
|
|
151
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TObject<{
|
|
152
|
+
runtimes: Type.TArray<Type.TString>;
|
|
153
|
+
}>> | undefined;
|
|
154
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
155
|
+
readonly description?: string;
|
|
156
|
+
} & {
|
|
157
|
+
readonly name: "undeploy";
|
|
158
|
+
readonly coord: string;
|
|
159
|
+
};
|
|
160
|
+
}>;
|
|
161
|
+
/** Time and timers: `after` starts a timer and returns its id, `fired` is published when it is due, at the clock's time. */
|
|
162
|
+
export declare const Clock: import("@pritzlaff/nano-core").Interface<{
|
|
163
|
+
now: {
|
|
164
|
+
readonly kind: "action";
|
|
165
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
166
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNumber> | undefined;
|
|
167
|
+
readonly description?: string;
|
|
168
|
+
} & {
|
|
169
|
+
readonly name: "now";
|
|
170
|
+
readonly coord: string;
|
|
171
|
+
};
|
|
172
|
+
after: {
|
|
173
|
+
readonly kind: "action";
|
|
174
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TObject<{
|
|
175
|
+
ms: Type.TInteger;
|
|
176
|
+
tag: Type.TOptional<Type.TString>;
|
|
177
|
+
}>> | undefined;
|
|
178
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TInteger> | undefined;
|
|
179
|
+
readonly description?: string;
|
|
180
|
+
} & {
|
|
181
|
+
readonly name: "after";
|
|
182
|
+
readonly coord: string;
|
|
183
|
+
};
|
|
184
|
+
cancel: {
|
|
185
|
+
readonly kind: "action";
|
|
186
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TInteger> | undefined;
|
|
187
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
188
|
+
readonly description?: string;
|
|
189
|
+
} & {
|
|
190
|
+
readonly name: "cancel";
|
|
191
|
+
readonly coord: string;
|
|
192
|
+
};
|
|
193
|
+
fired: {
|
|
194
|
+
readonly kind: "event";
|
|
195
|
+
readonly input?: undefined;
|
|
196
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TObject<{
|
|
197
|
+
id: Type.TInteger;
|
|
198
|
+
tag: Type.TOptional<Type.TString>;
|
|
199
|
+
at: Type.TNumber;
|
|
200
|
+
}>> | undefined;
|
|
201
|
+
readonly description?: string;
|
|
202
|
+
} & {
|
|
203
|
+
readonly name: "fired";
|
|
204
|
+
readonly coord: string;
|
|
205
|
+
};
|
|
206
|
+
}>;
|
|
207
|
+
/** Moves a simulated clock; `set` may not go back. */
|
|
208
|
+
export declare const ClockControl: import("@pritzlaff/nano-core").Interface<{
|
|
209
|
+
advance: {
|
|
210
|
+
readonly kind: "action";
|
|
211
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TNumber> | undefined;
|
|
212
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
213
|
+
readonly description?: string;
|
|
214
|
+
} & {
|
|
215
|
+
readonly name: "advance";
|
|
216
|
+
readonly coord: string;
|
|
217
|
+
};
|
|
218
|
+
set: {
|
|
219
|
+
readonly kind: "action";
|
|
220
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TNumber> | undefined;
|
|
221
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
222
|
+
readonly description?: string;
|
|
223
|
+
} & {
|
|
224
|
+
readonly name: "set";
|
|
225
|
+
readonly coord: string;
|
|
226
|
+
};
|
|
227
|
+
}>;
|
|
228
|
+
/** A float in [0, 1); pods scale it themselves. */
|
|
229
|
+
export declare const Random: import("@pritzlaff/nano-core").Interface<{
|
|
230
|
+
next: {
|
|
231
|
+
readonly kind: "action";
|
|
232
|
+
readonly input?: import("@pritzlaff/nano-core").SchemaDef<Type.TNull> | undefined;
|
|
233
|
+
readonly output?: import("@pritzlaff/nano-core").SchemaDef<Type.TNumber> | undefined;
|
|
234
|
+
readonly description?: string;
|
|
235
|
+
} & {
|
|
236
|
+
readonly name: "next";
|
|
237
|
+
readonly coord: string;
|
|
238
|
+
};
|
|
239
|
+
}>;
|
package/layout.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The layout convention
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* "layout": {
|
|
6
|
-
* "slots": [{ "id": "a", "runtime": "example.todo.frontend", "pod": "listA" }, { "id": "b", "runtime": "example.todo.frontend", "pod": "listB" }],
|
|
7
|
-
* "geometry": { "a": { "x": 0, "y": 0, "w": 0.5, "h": 1 }, "b": { "x": 0.5, "y": 0, "w": 0.5, "h": 1 } },
|
|
8
|
-
* "workspace": { ...golden-layout's own state }
|
|
9
|
-
* }
|
|
10
|
-
*
|
|
11
|
-
* A slot's key is the pod's instance coordinate; a pod has at most one view (its implementation's, from the provider
|
|
12
|
-
* module's `views`, or the deployment's `views` override). A pod not in `slots` runs unseen.
|
|
2
|
+
* The old layout convention, kept for reading old documents: `AppDeployment.layout` held `slots` (placed pods) and
|
|
3
|
+
* their `geometry`. Pages now live in the Outline (`@pritzlaff/nano-outline`); the workspace migrates a legacy
|
|
4
|
+
* layout into it.
|
|
13
5
|
*/
|
|
14
6
|
/** A placed pod. `id` is the slot's engine-neutral name. */
|
|
15
7
|
export type LayoutSlot = {
|
package/observe/bar.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<nano-time-machine>`: the bar over a time machine — play/pause, step back and forward, a slider over the recording's
|
|
3
|
+
* span, speed, Live and Reset. It says "history too long to rebuild state" once `store` (the recording) no longer
|
|
4
|
+
* holds its clean start, and why `driver` drives no clock. Reset is a `reset` event: the host resets. It sends no message.
|
|
5
|
+
*
|
|
6
|
+
* bar.tm = tm; bar.store = store; bar.driver = clockDriver(app, registry, tm)
|
|
7
|
+
* bar.addEventListener('reset', () => host.reset())
|
|
8
|
+
*/
|
|
9
|
+
import { LitElement } from 'lit';
|
|
10
|
+
import type { MessageStore } from './entry.js';
|
|
11
|
+
import { type TimeMachine } from './time-machine.js';
|
|
12
|
+
export declare class NanoTimeMachine extends LitElement {
|
|
13
|
+
static properties: {
|
|
14
|
+
tm: {
|
|
15
|
+
attribute: boolean;
|
|
16
|
+
};
|
|
17
|
+
store: {
|
|
18
|
+
attribute: boolean;
|
|
19
|
+
};
|
|
20
|
+
driver: {
|
|
21
|
+
attribute: boolean;
|
|
22
|
+
};
|
|
23
|
+
tooLong: {
|
|
24
|
+
state: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
static styles: import("lit").CSSResult;
|
|
28
|
+
tm?: TimeMachine;
|
|
29
|
+
store?: MessageStore;
|
|
30
|
+
driver?: {
|
|
31
|
+
readonly driving: string | null;
|
|
32
|
+
readonly reason?: string;
|
|
33
|
+
};
|
|
34
|
+
tooLong: boolean;
|
|
35
|
+
private off?;
|
|
36
|
+
private clean?;
|
|
37
|
+
constructor();
|
|
38
|
+
connectedCallback(): void;
|
|
39
|
+
disconnectedCallback(): void;
|
|
40
|
+
willUpdate(changed: Map<string, unknown>): void;
|
|
41
|
+
private watch;
|
|
42
|
+
/** Once too long, it stays so until a new store or time machine: entries drop only from the oldest end. */
|
|
43
|
+
private check;
|
|
44
|
+
private act;
|
|
45
|
+
render(): import("lit").TemplateResult<1>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drives the deployment's one simulated clock from the time machine: while it is live, each ticker frame calls the
|
|
3
|
+
* clock's `advance(elapsed real ms × speed)` through the app (so replay sees it as a host input), then waits for quiet.
|
|
4
|
+
*
|
|
5
|
+
* const d = clockDriver(app, registry, tm) // d.driving: the clock pod's name, or null and d.reason
|
|
6
|
+
*/
|
|
7
|
+
import { type Application, type Registry } from '@pritzlaff/nano-core';
|
|
8
|
+
import type { Ticker, TimeMachine } from './time-machine.js';
|
|
9
|
+
export declare function clockDriver(app: Application, registry: Registry, tm: TimeMachine, opts?: {
|
|
10
|
+
maxHz?: number;
|
|
11
|
+
ticker?: Ticker;
|
|
12
|
+
}): {
|
|
13
|
+
readonly driving: string | null;
|
|
14
|
+
readonly reason?: string;
|
|
15
|
+
close(): void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the recorder keeps: entries (an app event, values snapshotted as JSON text), messages (a sent paired with its
|
|
3
|
+
* outcome) and the swappable async store behind them.
|
|
4
|
+
*
|
|
5
|
+
* snap({ n: 10n }) // '{"n":"10n"}'
|
|
6
|
+
* pair(await store.range()) // Message[], in sent order
|
|
7
|
+
*/
|
|
8
|
+
import type { AppDeployment, AppEvent } from '@pritzlaff/nano-core';
|
|
9
|
+
/** A recorded thing: an app event (values snapshotted as JSON text), or the deployment in force from here on (`clean`: its pods held no state). */
|
|
10
|
+
export type Recorded = (Exclude<AppEvent, {
|
|
11
|
+
type: 'sent' | 'delivered';
|
|
12
|
+
}>) | (Omit<Extract<AppEvent, {
|
|
13
|
+
type: 'sent';
|
|
14
|
+
}>, 'input'> & {
|
|
15
|
+
input?: string;
|
|
16
|
+
}) | {
|
|
17
|
+
type: 'delivered';
|
|
18
|
+
id: string;
|
|
19
|
+
ok: boolean;
|
|
20
|
+
result: string;
|
|
21
|
+
ms: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'deployment';
|
|
24
|
+
deployment: AppDeployment;
|
|
25
|
+
clean?: true;
|
|
26
|
+
caller?: string;
|
|
27
|
+
};
|
|
28
|
+
export type Entry = {
|
|
29
|
+
seq: number;
|
|
30
|
+
at: number;
|
|
31
|
+
event: Recorded;
|
|
32
|
+
};
|
|
33
|
+
export declare const CAP = 65536;
|
|
34
|
+
/** Safe JSON text of any value: never throws, cycles, BigInts and functions are marked, capped at CAP. */
|
|
35
|
+
export declare function snap(v: unknown): string;
|
|
36
|
+
export declare const truncated: (text: string) => boolean;
|
|
37
|
+
/** A message: its sent, and its outcome once known. */
|
|
38
|
+
export type Message = {
|
|
39
|
+
seq: number;
|
|
40
|
+
at: number;
|
|
41
|
+
sent: Extract<Recorded, {
|
|
42
|
+
type: 'sent';
|
|
43
|
+
}>;
|
|
44
|
+
outcome?: Extract<Recorded, {
|
|
45
|
+
type: 'delivered';
|
|
46
|
+
}> | Extract<Recorded, {
|
|
47
|
+
type: 'denied';
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
/** Messages in sent order; an outcome without its sent is skipped. */
|
|
51
|
+
export declare function pair(entries: Entry[]): Message[];
|
|
52
|
+
/**
|
|
53
|
+
* Seqs are contiguous (one writer per store assigns them: two tabs on one store is out of scope; a store drops only from
|
|
54
|
+
* the oldest end). After `flush()`, `size`/`oldest`/`range` include every appended entry; `flush()` rejects when
|
|
55
|
+
* buffered writes failed. `range(from, to, limit)` is inclusive and keeps at most `limit`, from the `from` end.
|
|
56
|
+
* `search` matches the entry's JSON text, deployment entries too, and keeps the newest `limit` matches, oldest first.
|
|
57
|
+
*/
|
|
58
|
+
export interface MessageStore {
|
|
59
|
+
append(e: Entry): void;
|
|
60
|
+
flush(): Promise<void>;
|
|
61
|
+
range(from?: number, to?: number, limit?: number): Promise<Entry[]>;
|
|
62
|
+
search(text: string, limit?: number): Promise<Entry[]>;
|
|
63
|
+
oldest(): Promise<number | undefined>;
|
|
64
|
+
size(): Promise<number>;
|
|
65
|
+
clear(): Promise<void>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State at a time t, read from the history alone: fold the paired messages and the deployments, in seq order, up to
|
|
3
|
+
* the last entry with `at ≤ t`. Nothing re-runs. A message counts with its outcome, even one recorded after t.
|
|
4
|
+
*
|
|
5
|
+
* await foldAt(store, t, { initial: 0, step: (n, m) => n + (m.outcome?.type === 'delivered' && m.outcome.ok ? 1 : 0) })
|
|
6
|
+
*/
|
|
7
|
+
import type { AppDeployment } from '@pritzlaff/nano-core';
|
|
8
|
+
import { type Message, type MessageStore } from './entry.js';
|
|
9
|
+
/** `step` gets every message (its outcome, if any, attached); `deployment` each deployment entry, the clean start first. */
|
|
10
|
+
export declare function foldAt<S>(store: MessageStore, t: number, r: {
|
|
11
|
+
initial: S;
|
|
12
|
+
step(s: S, m: Message): S;
|
|
13
|
+
deployment?(s: S, d: AppDeployment): S;
|
|
14
|
+
}): Promise<S>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Application } from '@pritzlaff/nano-core';
|
|
2
|
+
/**
|
|
3
|
+
* Counts `app`'s messages in flight: each `sent` heard until its `delivered` or `denied` (an outcome of a message sent
|
|
4
|
+
* before it listened is ignored: nothing waits on it). `quiet()` resolves once none is, one macrotask later and still
|
|
5
|
+
* none (true), or after `QUIET_MS` from that call (false). `stop()` stops listening.
|
|
6
|
+
*/
|
|
7
|
+
export declare function inFlight(app: Application): {
|
|
8
|
+
quiet: () => Promise<boolean>;
|
|
9
|
+
stop: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Application } from '@pritzlaff/nano-core';
|
|
2
|
+
import { type Entry, type MessageStore } from './entry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Records `app` into `store` from now: first a deployment entry (the app's current deployment, `clean: true` when
|
|
5
|
+
* `opts.clean` says its pods hold no state yet), then every event, snapshotted, with another deployment entry after each
|
|
6
|
+
* `applied`. It listens before reading the store's last seq and holds what arrives meanwhile, so nothing is missed.
|
|
7
|
+
* seq starts after the store's last entry; resolves to `stop` and `listen(fn)`, which hears each entry once appended, in order, and returns its unsubscribe; `at` is `opts.now()` (`Date.now`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function record(app: Application, store: MessageStore, opts?: {
|
|
10
|
+
clean?: boolean;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
stop: () => void;
|
|
14
|
+
listen: (fn: (e: Entry) => void) => () => void;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time machine: reset an app to the recording's clean start and re-send every host input after it at its original
|
|
3
|
+
* pace, then say where the new run differs from the old.
|
|
4
|
+
*
|
|
5
|
+
* const r = await replay(app, store) // success({ sent: 3, failed: 0, …, from: 1, to: 40 })
|
|
6
|
+
* diverge(pair(await store.range(r.from, r.to)), pair(await second.range())) // null: the same messages came out
|
|
7
|
+
*/
|
|
8
|
+
import { type Application, type NanoResult } from '@pritzlaff/nano-core';
|
|
9
|
+
import { type Entry, type Message, type MessageStore } from './entry.js';
|
|
10
|
+
/** The store's oldest entry if it is a clean start (a deployment whose pods held no state), else undefined: what replay and shadowAt need. */
|
|
11
|
+
export declare function cleanStart(store: MessageStore): Promise<(Entry & {
|
|
12
|
+
event: {
|
|
13
|
+
type: 'deployment';
|
|
14
|
+
};
|
|
15
|
+
}) | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* The messages nothing in the app caused: host calls and starts with no cause. Their inputs are snapshots, so a Map, Set, Date or
|
|
18
|
+
* BigInt comes back as its JSON text and an undefined field is gone.
|
|
19
|
+
*/
|
|
20
|
+
export declare const roots: (messages: Message[]) => Message[];
|
|
21
|
+
type Replayed = {
|
|
22
|
+
sent: number;
|
|
23
|
+
failed: number;
|
|
24
|
+
applied: number;
|
|
25
|
+
restarted: number;
|
|
26
|
+
from: number;
|
|
27
|
+
to: number;
|
|
28
|
+
};
|
|
29
|
+
type Opts = {
|
|
30
|
+
to?: number;
|
|
31
|
+
now?: () => number;
|
|
32
|
+
sleep?: (ms: number) => Promise<void>;
|
|
33
|
+
pace?: 'original' | 'fast';
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Rebuilds the app's state as of `to` (default: the newest entry). It starts from the store's oldest entry, which must
|
|
37
|
+
* be a clean start, applies its deployment and restarts every pod, call-edge targets before their callers (calls in flight finish on the old instances). Then
|
|
38
|
+
* every host input recorded after it, up to `to`, happens again at its offset from the start, measured from the reset:
|
|
39
|
+
* each root is re-sent (reads too), each later deployment is applied and each `restarted` pod is restarted. Roots are
|
|
40
|
+
* not awaited one by one: an input waits only for the roots whose outcome was recorded before it, as the host did.
|
|
41
|
+
* Returns the counts and the seq range covered; a re-sent root that fails counts in `failed`.
|
|
42
|
+
* `pace: 'fast'` (for an app on a simulated clock) doesn't keep to the offsets: after the reset, before each input and
|
|
43
|
+
* before it returns, it waits until no message is in flight; an input whose wait for quiet runs out counts in `failed`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function replay(app: Application, store: MessageStore, opts?: Opts): Promise<NanoResult<Replayed>>;
|
|
46
|
+
/**
|
|
47
|
+
* The first message that differs between two runs (kind, from, to, port, input, outcome ok and result; ids, times and
|
|
48
|
+
* causes ignored), or null. Pass the recording's replayed range, `store.range(r.from, r.to)`, not the whole store.
|
|
49
|
+
* The replay also holds what restarted pods sent while building (a recording begun after startup lacks it): compare from the first host input.
|
|
50
|
+
*/
|
|
51
|
+
export declare function diverge(recorded: Message[], replayed: Message[]): {
|
|
52
|
+
index: number;
|
|
53
|
+
recorded?: Message;
|
|
54
|
+
replayed?: Message;
|
|
55
|
+
} | null;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<nano-ring>`: the app as rings (ring.ts): each shown pod as its own view, the time machine's messages in flight as
|
|
3
|
+
* dots between them. With the cursor in the past and still for 200 ms, the views are bound to an app rebuilt to it
|
|
4
|
+
* (`shadowAt` through `create`), inert, and the rings are that app's deployment; at Live, the live app again. A pod with
|
|
5
|
+
* no view (none in `views` or nano-ui's map) is just its label. A dot click seeks to its message. Hidden (its page's
|
|
6
|
+
* route not shown), it renders nothing: no view is mounted, so none starts a lazy pod.
|
|
7
|
+
*
|
|
8
|
+
* ring.app = app; ring.registry = registry; ring.tm = tm; ring.store = store
|
|
9
|
+
* ring.create = d => Application.create(…, { deploymentPolicy: DeploymentPolicies.allowAll() }) // a shadow's own app
|
|
10
|
+
* ring.show = (pod, impl) => impl !== 'nano.ui/clock'
|
|
11
|
+
* ring.views = { 'example.raft/node': 'raft-node' } // implementation → view tag, before nano-ui's own map
|
|
12
|
+
*/
|
|
13
|
+
import { LitElement } from 'lit';
|
|
14
|
+
import type { AppDeployment, Application, NanoResult, Registry } from '@pritzlaff/nano-core';
|
|
15
|
+
import { type ViewMap } from '../views/view.js';
|
|
16
|
+
import type { MessageStore } from './entry.js';
|
|
17
|
+
import type { Frame, TimeMachine } from './time-machine.js';
|
|
18
|
+
export declare class NanoRing extends LitElement {
|
|
19
|
+
static properties: {
|
|
20
|
+
app: {
|
|
21
|
+
attribute: boolean;
|
|
22
|
+
};
|
|
23
|
+
registry: {
|
|
24
|
+
attribute: boolean;
|
|
25
|
+
};
|
|
26
|
+
tm: {
|
|
27
|
+
attribute: boolean;
|
|
28
|
+
};
|
|
29
|
+
store: {
|
|
30
|
+
attribute: boolean;
|
|
31
|
+
};
|
|
32
|
+
create: {
|
|
33
|
+
attribute: boolean;
|
|
34
|
+
};
|
|
35
|
+
show: {
|
|
36
|
+
attribute: boolean;
|
|
37
|
+
};
|
|
38
|
+
views: {
|
|
39
|
+
attribute: boolean;
|
|
40
|
+
};
|
|
41
|
+
frame: {
|
|
42
|
+
state: boolean;
|
|
43
|
+
};
|
|
44
|
+
shadow: {
|
|
45
|
+
state: boolean;
|
|
46
|
+
};
|
|
47
|
+
tooLong: {
|
|
48
|
+
state: boolean;
|
|
49
|
+
};
|
|
50
|
+
failed: {
|
|
51
|
+
state: boolean;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
static styles: import("lit").CSSResult;
|
|
55
|
+
app?: Application;
|
|
56
|
+
registry?: Registry;
|
|
57
|
+
tm?: TimeMachine;
|
|
58
|
+
store?: MessageStore;
|
|
59
|
+
create?: (d: AppDeployment) => Promise<NanoResult<Application>>;
|
|
60
|
+
show?: (pod: string, impl: string) => boolean;
|
|
61
|
+
views?: ViewMap;
|
|
62
|
+
frame?: Frame;
|
|
63
|
+
shadow?: Application;
|
|
64
|
+
tooLong: boolean;
|
|
65
|
+
failed?: string;
|
|
66
|
+
private offs;
|
|
67
|
+
private els;
|
|
68
|
+
private timer?;
|
|
69
|
+
private still?;
|
|
70
|
+
private build;
|
|
71
|
+
private shown;
|
|
72
|
+
private resized;
|
|
73
|
+
constructor();
|
|
74
|
+
connectedCallback(): void;
|
|
75
|
+
disconnectedCallback(): void;
|
|
76
|
+
willUpdate(changed: Map<string, unknown>): void;
|
|
77
|
+
private watch;
|
|
78
|
+
/** Live (or too long): the live app. Past: a rebuild once the cursor has been still for STILL_MS. */
|
|
79
|
+
private sync;
|
|
80
|
+
private toLive;
|
|
81
|
+
private bind;
|
|
82
|
+
private rebuild;
|
|
83
|
+
/** The pod's view element, kept across renders, its target set when it changes; none for a pod with no view. */
|
|
84
|
+
private view;
|
|
85
|
+
render(): import("lit").TemplateResult<1>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Ring's pure parts: each runtime a cluster on an outer ring (one runtime: centred), its own pods around it, the
|
|
3
|
+
* pods placed in several runtimes near the centre; where a message's dot is; and whether the views show the past.
|
|
4
|
+
*
|
|
5
|
+
* const l = ringLayout(app.deployment(), { size: 600 })
|
|
6
|
+
* ringDot(l, app.deployment(), message, 0.5) // halfway from sender to receiver
|
|
7
|
+
*/
|
|
8
|
+
import type { AppDeployment } from '@pritzlaff/nano-core';
|
|
9
|
+
import type { Message } from './entry.js';
|
|
10
|
+
type XY = {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
14
|
+
export type RingLayout = {
|
|
15
|
+
runtimes: {
|
|
16
|
+
id: string;
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
r: number;
|
|
20
|
+
}[];
|
|
21
|
+
/** `runtime` null: shared, placed in two or more runtimes. */
|
|
22
|
+
pods: {
|
|
23
|
+
pod: string;
|
|
24
|
+
runtime: string | null;
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
}[];
|
|
28
|
+
};
|
|
29
|
+
/** `show(pod, implementation)` picks the pods drawn (default: all); every runtime is drawn. A pod placed nowhere is not. */
|
|
30
|
+
export declare function ringLayout(d: AppDeployment, opts: {
|
|
31
|
+
size: number;
|
|
32
|
+
show?: (pod: string, impl: string) => boolean;
|
|
33
|
+
}): RingLayout;
|
|
34
|
+
/** The dot of `m` at `progress` (0..1) from sender to receiver; undefined for the host or a pod not placed. */
|
|
35
|
+
export declare function ringDot(l: RingLayout, d: AppDeployment, m: Message, progress: number): XY | undefined;
|
|
36
|
+
/** What the views show: the live app, the past (an app rebuilt to the cursor) or, the history too long to rebuild, the live app. */
|
|
37
|
+
export declare function ringSource(mode: 'live' | 'paused' | 'playing', atNewest: boolean, rebuildable: boolean): 'live' | 'past' | 'too-long';
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State at a time t, exactly: a private app built from the recording's clean start and replayed to the last entry with
|
|
3
|
+
* `at ≤ t`, at `pace: 'fast'` with no recorder. Every message its last input set off has finished. The caller reads
|
|
4
|
+
* and closes it. It assumes what replay does (see replay.ts): it is exact only for an app whose pods are deterministic
|
|
5
|
+
* given their inputs, e.g. on a simulated clock and a seeded random.
|
|
6
|
+
*
|
|
7
|
+
* const app = await shadowAt(host.history, t, d => Application.create(AppDeployment.assemble(d, registry).value, {}))
|
|
8
|
+
*/
|
|
9
|
+
import type { AppDeployment, Application, NanoResult } from '@pritzlaff/nano-core';
|
|
10
|
+
import type { MessageStore } from './entry.js';
|
|
11
|
+
/**
|
|
12
|
+
* `create` builds an app from a deployment (the host's registry and isolation). The shadow leaves out the pod
|
|
13
|
+
* `opts.host` (default `'ui'`, the host's own) and the host's inputs addressed to it. Refuses with `not-found` when the
|
|
14
|
+
* clean start is gone or no entry is at or before t; a replay that fails closes the app and returns its failure.
|
|
15
|
+
*/
|
|
16
|
+
export declare function shadowAt(store: MessageStore, t: number, create: (d: AppDeployment) => Promise<NanoResult<Application>>, opts?: {
|
|
17
|
+
host?: string;
|
|
18
|
+
}): Promise<NanoResult<Application>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time machine: a cursor (a time, in the recording's `at` ms) over a recording, emitting a frame of what's in flight
|
|
3
|
+
* there on every change. Live follows the newest entry; playing moves at speed × real time, skipping idle gaps; paused
|
|
4
|
+
* stays put while recording goes on.
|
|
5
|
+
*
|
|
6
|
+
* const tm = await timeMachine({ store, listen }) // listen: from record()
|
|
7
|
+
* tm.subscribe(f => draw(f.inFlight)); tm.seek(t); tm.play()
|
|
8
|
+
*/
|
|
9
|
+
import type { Entry, Message, MessageStore } from './entry.js';
|
|
10
|
+
export type Frame = {
|
|
11
|
+
t: number;
|
|
12
|
+
inFlight: {
|
|
13
|
+
message: Message;
|
|
14
|
+
progress: number;
|
|
15
|
+
}[];
|
|
16
|
+
recent: Message[];
|
|
17
|
+
at?: Message;
|
|
18
|
+
};
|
|
19
|
+
/** `frame(fn)` runs `fn` once, at the next frame, and returns its cancel. */
|
|
20
|
+
export type Ticker = {
|
|
21
|
+
now(): number;
|
|
22
|
+
frame(fn: () => void): () => void;
|
|
23
|
+
};
|
|
24
|
+
export interface TimeMachine {
|
|
25
|
+
readonly cursor: number;
|
|
26
|
+
readonly mode: 'live' | 'paused' | 'playing';
|
|
27
|
+
readonly speed: number;
|
|
28
|
+
readonly span: {
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
};
|
|
32
|
+
seek(t: number): void;
|
|
33
|
+
step(dir: 1 | -1): void;
|
|
34
|
+
play(): void;
|
|
35
|
+
pause(): void;
|
|
36
|
+
live(): void;
|
|
37
|
+
setSpeed(s: number): void;
|
|
38
|
+
subscribe(fn: (f: Frame) => void): () => void;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare const SPEEDS: number[];
|
|
42
|
+
/**
|
|
43
|
+
* Catches up with `store.range()` and then hears `listen`, missing nothing. A message's window is
|
|
44
|
+
* `[at, at + travelMs]` (`travelMs` 600) at any speed: speed scales only how fast the cursor moves. Live, while
|
|
45
|
+
* anything is in flight, a frame is emitted each ticker frame with `t = now()`. `recent` keeps the last `recent` (200) messages with `at ≤ t`.
|
|
46
|
+
* Messages are ordered by `at`, ties by seq; a step moves to the next or previous one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function timeMachine(source: {
|
|
49
|
+
store: MessageStore;
|
|
50
|
+
listen: (fn: (e: Entry) => void) => () => void;
|
|
51
|
+
}, opts?: {
|
|
52
|
+
ticker?: Ticker;
|
|
53
|
+
recent?: number;
|
|
54
|
+
travelMs?: number;
|
|
55
|
+
}): Promise<TimeMachine>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pritzlaff/nano-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The nano.ui provider: input, debounce, map and log pods, and the HostUI interface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@pritzlaff/nano-core": "^0.
|
|
24
|
-
"@pritzlaff/nano-elements": "^0.
|
|
23
|
+
"@pritzlaff/nano-core": "^0.5.1",
|
|
24
|
+
"@pritzlaff/nano-elements": "^0.5.1",
|
|
25
25
|
"lit": "^3.0.0",
|
|
26
26
|
"typebox": "^1.4.0"
|
|
27
27
|
},
|
package/pods/clock.d.ts
ADDED
package/pods/debounce.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Implementation } from '@pritzlaff/nano-core';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* `push` returns at once and queues its value. After `quietMs` without a push, or at the latest `maxWaitMs` after the
|
|
4
|
+
* first push of a batch (when set), the queue flushes: the newest value as `flushed`, all of it, oldest first, as `batch`.
|
|
5
|
+
*/
|
|
3
6
|
export declare const debounce: Implementation;
|
package/pods/input.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Implementation } from '@pritzlaff/nano-core';
|
|
2
|
+
/** What its view shows: a line of text, a text area, a number or a checkbox. The pod itself only returns its input. */
|
|
3
|
+
export declare const KINDS: readonly ['text', 'textarea', 'number', 'boolean'];
|
|
4
|
+
export type InputKind = typeof KINDS[number];
|
|
2
5
|
export declare const input: Implementation;
|