@arqlet/engine-client 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,164 @@
1
+ import type {DetailsAnswer, FindAnswer, Graph, Hidden, Intent, NeighbourhoodAnswer, Scene, Snapshot, TraceAnswer} from '@arqlet/contracts';
2
+ import type {DetailTarget, PayloadAnswer, PayloadChange, PeekAnswer, ReadAnswer, RefineRun, Session, SessionResult} from './session.js';
3
+ import type {EngineRequest} from './wasm-client.js';
4
+
5
+ /** Provisional: a view as a value (`bookmark`): the engine's intent, the highlight, the selection, the graph's digest. */
6
+ export interface ViewBookmark {
7
+ version: 1;
8
+ digest: string | null;
9
+ intent: Intent;
10
+ highlight?: ViewHighlight extends infer H ? (H extends unknown ? Omit<H, 'answer'> : never) : never;
11
+ selection?: DetailTarget;
12
+ }
13
+
14
+ /** A bookmark as URL-safe text, and back (throws on text that is not one). */
15
+ export function encodeBookmark(bookmark: ViewBookmark): string;
16
+ export function decodeBookmark(text: string): ViewBookmark;
17
+
18
+ /** Provisional: where keyboard navigation goes (see `navigateScene`). */
19
+ export type NavigationDirection = 'left' | 'right' | 'up' | 'down' | 'parent' | 'child' | 'next' | 'previous' | 'out' | 'in';
20
+
21
+ /** The node of `scene` that `direction` leads to from `from` (without `from`, the first top-level node), or null. */
22
+ export function navigateScene(scene: Scene | null, from: string | null, direction: NavigationDirection): string | null;
23
+
24
+ /** What changed between two scenes, by id. */
25
+ export interface SceneDiff {
26
+ nodes: {added: string[]; removed: string[]; changed: string[]};
27
+ routes: {added: string[]; removed: string[]; changed: string[]};
28
+ }
29
+
30
+ /** Provisional: the highlight a view keeps until it is cleared; asked again after every change. */
31
+ export type ViewHighlight =
32
+ | {kind: 'trace'; from: string; to: string; init?: {mode?: 'shortest' | 'all'; edgeKinds?: string[]}; answer: {ok: true} & TraceAnswer}
33
+ | {
34
+ kind: 'neighbourhood';
35
+ nodeId: string | string[];
36
+ init?: {hops?: number; direction?: 'out' | 'in' | 'both'; edgeKinds?: string[]};
37
+ answer: {ok: true} & NeighbourhoodAnswer;
38
+ };
39
+
40
+ /** Provisional: the state of a view controller (frozen; a new object after every change). */
41
+ export interface ViewState {
42
+ /** The session's snapshot (with a resident session only its state). */
43
+ readonly snapshot: Snapshot | null;
44
+ /** The scene to draw. */
45
+ readonly scene: Scene | null;
46
+ /** What the last step changed in the scene, for animation. */
47
+ readonly diff: SceneDiff | null;
48
+ /** Whether a step is running or queued. */
49
+ readonly busy: boolean;
50
+ /** The last error, cleared by the next successful step. */
51
+ readonly error: string | null;
52
+ readonly highlight: ViewHighlight | null;
53
+ /** The selected node or edge (`select`), or null. */
54
+ readonly selection: DetailTarget | null;
55
+ /** What the engine knows about the selection, asked again after every change; null without a selection. */
56
+ readonly details: (DetailsAnswer & {ok: true}) | null;
57
+ /** The last search (`find`) and its answer, or null. */
58
+ readonly search: {query: string; answer: FindAnswer & {ok: true}} | null;
59
+ /** The last `focus`: the node and the bounds of the box that shows it (null when hidden); `serial` counts requests. */
60
+ readonly focus: {nodeId: string; bounds: {x: number; y: number; width: number; height: number} | null; shownAs: string | null; serial: number} | null;
61
+ /** Provisional (ADR 0023, R1): the content's revision after the last `payload`, or undefined. */
62
+ readonly contentRevision?: number;
63
+ /** The look into a collapsed container (`peek`), or null; cleared by the next change. */
64
+ readonly peek: {nodeId: string; answer: PeekAnswer & {ok: true}} | null;
65
+ /** The refinement under way on the second engine (`refine`), or null; `shown` counts intermediate results applied. */
66
+ readonly refining: {op: string; jobId: string; shown: number} | null;
67
+ /** How the last refinement ended: applied, stale (the view had moved on), cancelled, or an error. */
68
+ readonly refined: {op: string; applied: boolean; stale?: true; cancelled?: true; error?: string; optimization?: unknown} | null;
69
+ /** Refinement results discarded because the view had changed. */
70
+ readonly discarded: number;
71
+ /** What the pointer is over (`hover`), or null. */
72
+ readonly hover: DetailTarget | null;
73
+ /** What the view hides (the last `filter`). */
74
+ readonly hide: Hidden;
75
+ readonly canBack: boolean;
76
+ readonly canForward: boolean;
77
+ /** The names of the steps `back` and `forward` would undo and redo (such as `Open group-1`), or null. */
78
+ readonly backLabel: string | null;
79
+ readonly forwardLabel: string | null;
80
+ /** How many steps changed the scene since the import. */
81
+ readonly steps: number;
82
+ }
83
+
84
+ /** A step's answer: the engine's, or `cancelled` when `cancel()` dropped it before it started. */
85
+ export type ViewResult = SessionResult & {
86
+ cancelled?: boolean;
87
+ /** `back` / `forward` (#148): false when the kept snapshot came back with its geometry, true when the view was laid out again. */
88
+ relaidOut?: boolean;
89
+ };
90
+
91
+ /**
92
+ * Provisional (request 31): a headless view controller over a layout session. `subscribe` and `getState` fit React's
93
+ * `useSyncExternalStore`. Steps run one after the other.
94
+ */
95
+ export interface ViewController {
96
+ getState(): ViewState;
97
+ subscribe(listener: () => void): () => void;
98
+ import(graph: Graph, init?: {limit?: number; options?: Record<string, unknown>}): Promise<ViewResult>;
99
+ open(id: string): Promise<ViewResult>;
100
+ close(id: string): Promise<ViewResult>;
101
+ toggle(id: string): Promise<ViewResult>;
102
+ /** The next `count` (default `page`) children of a `+N more` box, or the first page of a collapsed container; `container` or `rest:<container>`. */
103
+ showRest(container: string, count?: number): Promise<ViewResult>;
104
+ reveal(nodeIds: string[], init?: {partial?: boolean}): Promise<ViewResult>;
105
+ filter(hide?: Hidden): Promise<ViewResult>;
106
+ trace(from: string, to: string, init?: {mode?: 'shortest' | 'all'; edgeKinds?: string[]}): Promise<ReadAnswer<TraceAnswer> & {cancelled?: boolean}>;
107
+ neighbourhood(
108
+ nodeId: string | string[],
109
+ init?: {hops?: number; direction?: 'out' | 'in' | 'both'; edgeKinds?: string[]},
110
+ ): Promise<ReadAnswer<NeighbourhoodAnswer> & {cancelled?: boolean}>;
111
+ /** Opens the groups the highlight passes through. */
112
+ revealHighlight(): Promise<ViewResult>;
113
+ clearHighlight(): void;
114
+ /** Selects a node or an edge (or nothing): `state.details` holds the engine's facts about it, kept up to date. */
115
+ select(target: DetailTarget | null): Promise<ViewResult>;
116
+ /** What the pointer is over (no engine call). */
117
+ hover(target: DetailTarget | null): void;
118
+ /** Finds nodes by label or id, also hidden ones (`state.search` until `clearSearch`). */
119
+ find(query: string, init?: {limit?: number; nodeKinds?: string[]}): Promise<ViewResult>;
120
+ clearSearch(): void;
121
+ /** A look into a collapsed container without opening it (`state.peek`; not a step for `back`). */
122
+ peek(nodeId: string, init?: {limit?: number}): Promise<ViewResult>;
123
+ closePeek(): void;
124
+ /** Provisional (ADR 0023, R1): changes the session's content and refreshes `state.details`; not a step for `back`. */
125
+ payload(change: PayloadChange): Promise<PayloadAnswer | {ok: false; error?: string; cancelled?: boolean}>;
126
+ /** Opens what hides `nodeId` (a step for `back`), selects it, and sets `state.focus` for the host's camera. */
127
+ focus(nodeId: string, options?: {reveal?: boolean; partial?: boolean}): Promise<ViewResult>;
128
+ /**
129
+ * Refines the view on the second engine (`refine`): `{op: 'refine'}` by default, `refineProgressive` or
130
+ * `structuredRefine`; applied only if the view is still the one it started from. Not a step for `back`.
131
+ */
132
+ refine(
133
+ request?: {op?: 'refine' | 'refineProgressive' | 'structuredRefine'; [field: string]: unknown},
134
+ options?: {onApplied?: (snapshot: Snapshot, info: {final: boolean; shown: number}) => void},
135
+ ): Promise<ViewResult>;
136
+ /** Stops the refinement under way; its later results are dropped. */
137
+ cancelRefinement(): void;
138
+ /** Moves the selection the way `direction` says and sets `state.focus` (nothing opened, not a step for `back`). */
139
+ navigate(direction: NavigationDirection): Promise<ViewResult | {ok: false; none: true; collapsed?: boolean}>;
140
+ /** The view as a value to keep or share (`encodeBookmark` for a URL). */
141
+ bookmark(): Promise<{ok: true; bookmark: ViewBookmark} | {ok: false; error?: string; cancelled?: boolean}>;
142
+ /** Opens a bookmark (a step for `back`); another graph's is refused unless `force`. */
143
+ openBookmark(bookmark: ViewBookmark, options?: {force?: boolean}): Promise<ViewResult>;
144
+ back(): Promise<ViewResult>;
145
+ forward(): Promise<ViewResult>;
146
+ /** Any other change of the protocol, remembered for `back` under `label`. */
147
+ apply(
148
+ request: Omit<EngineRequest, 'snapshot' | 'expectedRevision' | 'expectedLayoutVersion'> & {op: string},
149
+ label?: string,
150
+ /** `merge`: a follow-up of the last change, remembered in its entry. */
151
+ options?: {remember?: boolean; merge?: boolean},
152
+ ): Promise<ViewResult>;
153
+ /**
154
+ * Continues from a snapshot the host made; with `forget` the history and the highlight start empty, with `remember` (a
155
+ * label) the change from the previous snapshot is remembered for `back`.
156
+ */
157
+ adopt(snapshot: Snapshot, options?: {forget?: boolean; remember?: string | null}): Promise<ViewResult>;
158
+ /** Drops the steps queued and not started; a step under way finishes. */
159
+ cancel(): void;
160
+ }
161
+
162
+ export function createViewController(session: Session, options?: {page?: number; historyLimit?: number; scenes?: boolean; detailLimit?: number; refine?: RefineRun; publicationInterval?: number; keepGeometry?: boolean}): ViewController;
163
+
164
+ export function sceneDiff(before: Scene | null, after: Scene | null): SceneDiff;