-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller-api.d.ts
More file actions
130 lines (110 loc) · 3.94 KB
/
Copy pathcontroller-api.d.ts
File metadata and controls
130 lines (110 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type {
AppBootstrapData,
CellIdentifier,
CellStateUpdate,
CompareRequest,
FilmstripRequest,
PersistedSimulationSnapshotV5,
RulesResponse,
SeedComparisonResult,
SeedFilmstripResult,
SimulationSnapshot,
TopologyPreview,
TopologyPreviewRequest,
TopologySpec,
} from "./domain.js";
export interface ConfigTopologySpecPatch {
width?: number;
height?: number;
unsafe_size_override?: boolean;
}
export interface ResetTopologySpec extends TopologySpec {
unsafe_size_override?: boolean;
}
export interface ConfigSyncBody {
topology_spec?: ConfigTopologySpecPatch;
speed?: number;
rule?: string | null;
}
export interface ResetControlBody {
topology_spec: ResetTopologySpec;
speed: number;
rule: string | null;
randomize: boolean;
}
export type CellTargetRequest = CellIdentifier;
export type CellUpdateRequest = CellStateUpdate;
export interface CellUpdatesRequest {
cells: CellUpdateRequest[];
}
export interface ControlCommandMap {
"/api/control/start": undefined;
"/api/control/pause": undefined;
"/api/control/resume": undefined;
"/api/control/step": undefined;
"/api/control/reset": ResetControlBody;
"/api/config": ConfigSyncBody;
}
export type EmptyControlCommandPath = {
[TPath in keyof ControlCommandMap]: ControlCommandMap[TPath] extends undefined ? TPath : never;
}[keyof ControlCommandMap];
export interface FetchRulesFunction {
(): Promise<RulesResponse>;
}
export interface FetchStateFunction {
(): Promise<SimulationSnapshot>;
}
export interface BackendRequestOptions {
signal?: AbortSignal;
}
export interface SimulationBackend {
getState(): Promise<SimulationSnapshot>;
getRules(): Promise<RulesResponse>;
dispose(): void | Promise<void>;
postControl(path: EmptyControlCommandPath): Promise<SimulationSnapshot>;
postControl(path: "/api/control/reset", body: ResetControlBody): Promise<SimulationSnapshot>;
postControl(path: "/api/config", body: ConfigSyncBody): Promise<SimulationSnapshot>;
toggleCell(cell: CellTargetRequest): Promise<SimulationSnapshot>;
setCell(cell: CellTargetRequest, state: number): Promise<SimulationSnapshot>;
setCells(cells: CellUpdateRequest[]): Promise<SimulationSnapshot>;
compareSeed(
request: CompareRequest,
options?: BackendRequestOptions,
): Promise<SeedComparisonResult>;
requestFilmstrip(
request: FilmstripRequest,
options?: BackendRequestOptions,
): Promise<SeedFilmstripResult>;
previewTopology(request: TopologyPreviewRequest): Promise<TopologyPreview>;
}
export interface SimulationStatePersistence {
load(): Promise<PersistedSimulationSnapshotV5 | null>;
save(snapshot: PersistedSimulationSnapshotV5): Promise<void>;
}
export interface PostControlFunction {
(path: EmptyControlCommandPath): Promise<SimulationSnapshot>;
(path: "/api/control/reset", body: ResetControlBody): Promise<SimulationSnapshot>;
(path: "/api/config", body: ConfigSyncBody): Promise<SimulationSnapshot>;
}
export interface CellMutationRequestFunction {
(cell: CellTargetRequest, state?: number): Promise<SimulationSnapshot>;
}
export interface ToggleCellRequestFunction {
(cell: CellTargetRequest): Promise<SimulationSnapshot>;
}
export interface SetCellRequestFunction {
(cell: CellTargetRequest, state: number): Promise<SimulationSnapshot>;
}
export interface SetCellsRequestFunction {
(cells: CellUpdateRequest[]): Promise<SimulationSnapshot>;
}
export interface InitAppOptions {
backend?: SimulationBackend;
bootstrapData?: AppBootstrapData | null;
/** Base session id the wall's live focus pane derives its child session from. */
paneBaseSessionId?: string | null;
/** Factory for the focus pane's independent backend session. */
paneBackendFactory?: (sessionId: string) => SimulationBackend;
/** Maximum concurrent live forks; undefined means unlimited. */
paneForkCapacity?: number;
}