@inflatable-cookie/longhorn 0.1.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.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/package.json +205 -0
- package/src/agent-control/index.ts +20 -0
- package/src/agent-control/inject.ts +4 -0
- package/src/agent-control/shim.ts +722 -0
- package/src/bridge/direct.ts +22 -0
- package/src/bridge/generated/fields.ts +32 -0
- package/src/bridge/generated/protocol.ts +218 -0
- package/src/bridge/generated/variant-fields.ts +10 -0
- package/src/bridge/index.ts +15 -0
- package/src/bridge/job.ts +51 -0
- package/src/bridge/loopback.ts +84 -0
- package/src/bridge/operation.ts +166 -0
- package/src/bridge/router.ts +71 -0
- package/src/bridge/runtime/connection.ts +318 -0
- package/src/bridge/runtime/policy.ts +89 -0
- package/src/bridge/runtime/retry.ts +60 -0
- package/src/bridge/runtime.ts +3 -0
- package/src/bridge/session.ts +67 -0
- package/src/bridge/stream/connection.ts +146 -0
- package/src/bridge/stream/source.ts +61 -0
- package/src/bridge/stream/tracker.ts +109 -0
- package/src/bridge/stream.ts +6 -0
- package/src/bridge/supervision.ts +204 -0
- package/src/bridge/validation/base.ts +164 -0
- package/src/bridge/validation/jobs.ts +105 -0
- package/src/bridge/validation/negotiation.ts +242 -0
- package/src/bridge/validation/operations.ts +213 -0
- package/src/bridge/validation/streams.ts +47 -0
- package/src/bridge/validation.ts +5 -0
- package/src/commands/client.ts +124 -0
- package/src/commands/controller.ts +411 -0
- package/src/commands/generated/fields.ts +43 -0
- package/src/commands/generated/protocol.ts +876 -0
- package/src/commands/generated/variant-fields.ts +88 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/keyboard.ts +361 -0
- package/src/commands/ports.ts +82 -0
- package/src/commands/projectors.ts +306 -0
- package/src/commands/validation.ts +444 -0
- package/src/config/client.ts +215 -0
- package/src/config/generated/base.ts +714 -0
- package/src/config/generated/fields.ts +54 -0
- package/src/config/generated/label-template.ts +14 -0
- package/src/config/generated/labels.ts +30 -0
- package/src/config/generated/protocol.ts +3 -0
- package/src/config/generated/restore.ts +658 -0
- package/src/config/generated/variant-fields.ts +129 -0
- package/src/config/index.ts +12 -0
- package/src/config/names.ts +19 -0
- package/src/config/validation/commands.ts +155 -0
- package/src/config/validation/outcomes.ts +243 -0
- package/src/config/validation/primitives.ts +174 -0
- package/src/config/validation/projection.ts +351 -0
- package/src/config/validation.ts +7 -0
- package/src/core/connection.ts +252 -0
- package/src/core/index.ts +2 -0
- package/src/core/transport.ts +24 -0
- package/src/history/client.ts +65 -0
- package/src/history/controller.ts +385 -0
- package/src/history/direct.ts +21 -0
- package/src/history/generated/fields.ts +18 -0
- package/src/history/generated/protocol.ts +389 -0
- package/src/history/generated/variant-fields.ts +27 -0
- package/src/history/index.ts +13 -0
- package/src/history/ports.ts +31 -0
- package/src/history/serialized.ts +38 -0
- package/src/history/validation.ts +334 -0
- package/src/history-tree/client.ts +16 -0
- package/src/history-tree/controller.ts +199 -0
- package/src/history-tree/direct.ts +3 -0
- package/src/history-tree/generated/fields.ts +26 -0
- package/src/history-tree/generated/protocol.ts +711 -0
- package/src/history-tree/generated/variant-fields.ts +39 -0
- package/src/history-tree/index.ts +13 -0
- package/src/history-tree/ports.ts +43 -0
- package/src/history-tree/serialized.ts +15 -0
- package/src/history-tree/validation.ts +269 -0
- package/src/layout/generated/protocol.ts +289 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/ratio.ts +22 -0
- package/src/layout/validation.ts +110 -0
- package/src/layout/visibility.ts +30 -0
- package/src/licence/client.ts +32 -0
- package/src/licence/controller.ts +301 -0
- package/src/licence/direct.ts +3 -0
- package/src/licence/generated/fields.ts +17 -0
- package/src/licence/generated/key-conformance.json +42 -0
- package/src/licence/generated/protocol.ts +249 -0
- package/src/licence/generated/variant-fields.ts +34 -0
- package/src/licence/index.ts +14 -0
- package/src/licence/key.ts +125 -0
- package/src/licence/ports.ts +39 -0
- package/src/licence/serialized.ts +13 -0
- package/src/licence/validation.ts +226 -0
- package/src/native-content/client.ts +474 -0
- package/src/native-content/direct.ts +16 -0
- package/src/native-content/generated/fields.ts +32 -0
- package/src/native-content/generated/protocol.ts +498 -0
- package/src/native-content/generated/variant-fields.ts +77 -0
- package/src/native-content/index.ts +12 -0
- package/src/native-content/ports.ts +46 -0
- package/src/native-content/serialized.ts +50 -0
- package/src/native-content/validation/base.ts +194 -0
- package/src/native-content/validation/messages.ts +192 -0
- package/src/native-content/validation/state.ts +404 -0
- package/src/native-content/validation.ts +7 -0
- package/src/notifications/client.ts +106 -0
- package/src/notifications/controller.ts +240 -0
- package/src/notifications/direct.ts +12 -0
- package/src/notifications/generated/fields.ts +19 -0
- package/src/notifications/generated/labels.ts +20 -0
- package/src/notifications/generated/protocol.ts +522 -0
- package/src/notifications/generated/variant-fields.ts +37 -0
- package/src/notifications/index.ts +16 -0
- package/src/notifications/ports.ts +22 -0
- package/src/notifications/serialized.ts +27 -0
- package/src/notifications/toast.ts +41 -0
- package/src/notifications/tone.ts +27 -0
- package/src/notifications/validation.ts +246 -0
- package/src/operation/bridge.ts +168 -0
- package/src/operation/client.ts +167 -0
- package/src/operation/controller.ts +321 -0
- package/src/operation/direct.ts +15 -0
- package/src/operation/generated/fields.ts +20 -0
- package/src/operation/generated/labels.ts +15 -0
- package/src/operation/generated/protocol.ts +762 -0
- package/src/operation/generated/variant-fields.ts +60 -0
- package/src/operation/index.ts +14 -0
- package/src/operation/ports.ts +29 -0
- package/src/operation/serialized.ts +39 -0
- package/src/operation/validation.ts +479 -0
- package/src/settings/client.ts +142 -0
- package/src/settings/connection.ts +246 -0
- package/src/settings/generated/fields.ts +34 -0
- package/src/settings/generated/protocol.ts +668 -0
- package/src/settings/generated/variant-fields.ts +26 -0
- package/src/settings/index.ts +12 -0
- package/src/settings/names.ts +8 -0
- package/src/settings/registry.ts +141 -0
- package/src/settings/validation/authority.ts +66 -0
- package/src/settings/validation/command.ts +165 -0
- package/src/settings/validation/error.ts +33 -0
- package/src/settings/validation/primitives.ts +203 -0
- package/src/settings/validation/projection.ts +50 -0
- package/src/settings/validation/registry.ts +170 -0
- package/src/settings/validation.ts +4 -0
- package/src/surface-transfer/client.ts +54 -0
- package/src/surface-transfer/generated/fields.ts +12 -0
- package/src/surface-transfer/generated/protocol.ts +61 -0
- package/src/surface-transfer/generated/variant-fields.ts +30 -0
- package/src/surface-transfer/index.ts +9 -0
- package/src/surface-transfer/validation.ts +209 -0
- package/src/surfaces/client.ts +140 -0
- package/src/surfaces/generated/fields.ts +19 -0
- package/src/surfaces/generated/protocol.ts +217 -0
- package/src/surfaces/generated/variant-fields.ts +42 -0
- package/src/surfaces/index.ts +9 -0
- package/src/surfaces/validation.ts +199 -0
- package/src/transfer/client.ts +133 -0
- package/src/transfer/connection.ts +87 -0
- package/src/transfer/generated/fields.ts +23 -0
- package/src/transfer/generated/protocol.ts +171 -0
- package/src/transfer/generated/variant-fields.ts +45 -0
- package/src/transfer/index.ts +11 -0
- package/src/transfer/payload.ts +71 -0
- package/src/transfer/validation.ts +282 -0
- package/src/update/client.ts +29 -0
- package/src/update/controller.ts +255 -0
- package/src/update/direct.ts +3 -0
- package/src/update/generated/fields.ts +14 -0
- package/src/update/generated/protocol.ts +238 -0
- package/src/update/generated/variant-fields.ts +44 -0
- package/src/update/index.ts +14 -0
- package/src/update/ports.ts +36 -0
- package/src/update/serialized.ts +12 -0
- package/src/update/validation.ts +191 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HISTORY_MAXIMUM_OPAQUE_ID_BYTES,
|
|
3
|
+
HISTORY_CHANGED_KINDS,
|
|
4
|
+
HISTORY_ENTRY_POSITIONS,
|
|
5
|
+
HISTORY_PAGE_FLOORS,
|
|
6
|
+
HISTORY_MODES,
|
|
7
|
+
HISTORY_NAVIGATION_DIRECTIONS,
|
|
8
|
+
HISTORY_NAVIGATION_REJECTION_CODES,
|
|
9
|
+
HISTORY_NAVIGATION_STATUSES,
|
|
10
|
+
HISTORY_NAVIGATION_TARGETS,
|
|
11
|
+
HISTORY_PROTOCOL_VERSION,
|
|
12
|
+
type HistoryChangedEvent,
|
|
13
|
+
type HistoryNavigationCommand,
|
|
14
|
+
type HistoryNavigationResult,
|
|
15
|
+
type HistoryPageCommand,
|
|
16
|
+
type HistoryPageSnapshot,
|
|
17
|
+
type HistorySnapshot,
|
|
18
|
+
} from "./generated/protocol.ts";
|
|
19
|
+
import { HISTORY_FIELDS } from "./generated/fields.ts";
|
|
20
|
+
import {
|
|
21
|
+
HISTORY_VARIANT_FIELDS,
|
|
22
|
+
HISTORY_VARIANT_FIELDS_DISCRIMINANTS,
|
|
23
|
+
} from "./generated/variant-fields.ts";
|
|
24
|
+
|
|
25
|
+
export class HistoryProtocolValidationError extends Error {
|
|
26
|
+
constructor(readonly path: string, message: string) {
|
|
27
|
+
super(`${path}: ${message}`);
|
|
28
|
+
this.name = "HistoryProtocolValidationError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function assertValidHistorySnapshot(
|
|
33
|
+
value: unknown,
|
|
34
|
+
): asserts value is HistorySnapshot {
|
|
35
|
+
assertNoPayload(value, "$");
|
|
36
|
+
const record = object(value, "$");
|
|
37
|
+
keys(record, "$", HISTORY_FIELDS.HistorySnapshot);
|
|
38
|
+
protocol(record.protocolVersion, "$.protocolVersion");
|
|
39
|
+
positiveInteger(record.authorityEpoch, "$.authorityEpoch");
|
|
40
|
+
summary(record.summary, "$.summary");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function assertValidHistoryPageCommand(
|
|
44
|
+
value: unknown,
|
|
45
|
+
): asserts value is HistoryPageCommand {
|
|
46
|
+
assertNoPayload(value, "$");
|
|
47
|
+
const record = object(value, "$");
|
|
48
|
+
keys(record, "$", HISTORY_FIELDS.HistoryPageCommand);
|
|
49
|
+
protocol(record.protocolVersion, "$.protocolVersion");
|
|
50
|
+
positiveInteger(record.authorityEpoch, "$.authorityEpoch");
|
|
51
|
+
id(record.historyId, "$.historyId");
|
|
52
|
+
integer(record.expectedRevision, "$.expectedRevision");
|
|
53
|
+
integer(record.offset, "$.offset");
|
|
54
|
+
positiveInteger(record.limit, "$.limit");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function assertValidHistoryPageSnapshot(
|
|
58
|
+
value: unknown,
|
|
59
|
+
): asserts value is HistoryPageSnapshot {
|
|
60
|
+
assertNoPayload(value, "$");
|
|
61
|
+
const record = object(value, "$");
|
|
62
|
+
keys(record, "$", HISTORY_FIELDS.HistoryPageSnapshot);
|
|
63
|
+
protocol(record.protocolVersion, "$.protocolVersion");
|
|
64
|
+
positiveInteger(record.authorityEpoch, "$.authorityEpoch");
|
|
65
|
+
id(record.historyId, "$.historyId");
|
|
66
|
+
integer(record.revision, "$.revision");
|
|
67
|
+
integer(record.offset, "$.offset");
|
|
68
|
+
integer(record.totalEntries, "$.totalEntries");
|
|
69
|
+
boolean(record.truncatedBefore, "$.truncatedBefore");
|
|
70
|
+
boolean(record.truncatedAfter, "$.truncatedAfter");
|
|
71
|
+
baseline(record.retainedBaseline, "$.retainedBaseline");
|
|
72
|
+
floor(record.floor, "$.floor");
|
|
73
|
+
array(record.entries, "$.entries").forEach((entry, index) =>
|
|
74
|
+
entryRecord(entry, `$.entries[${index}]`),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function assertValidHistoryNavigationCommand(
|
|
79
|
+
value: unknown,
|
|
80
|
+
): asserts value is HistoryNavigationCommand {
|
|
81
|
+
assertNoPayload(value, "$");
|
|
82
|
+
const record = object(value, "$");
|
|
83
|
+
keys(record, "$", HISTORY_FIELDS.HistoryNavigationCommand);
|
|
84
|
+
protocol(record.protocolVersion, "$.protocolVersion");
|
|
85
|
+
positiveInteger(record.authorityEpoch, "$.authorityEpoch");
|
|
86
|
+
id(record.historyId, "$.historyId");
|
|
87
|
+
id(record.planId, "$.planId");
|
|
88
|
+
integer(record.expectedRevision, "$.expectedRevision");
|
|
89
|
+
const target = object(record.target, "$.target");
|
|
90
|
+
oneOf(target.kind, "$.target.kind", HISTORY_NAVIGATION_TARGETS);
|
|
91
|
+
keys(target, "$.target", variantKeys("HistoryNavigationTargetProjection", target, "$.target"));
|
|
92
|
+
if (target.kind === "checkout") {
|
|
93
|
+
id(target.entryId, "$.target.entryId");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function assertValidHistoryNavigationResult(
|
|
98
|
+
value: unknown,
|
|
99
|
+
): asserts value is HistoryNavigationResult {
|
|
100
|
+
assertNoPayload(value, "$");
|
|
101
|
+
const record = object(value, "$");
|
|
102
|
+
oneOf(record.status, "$.status", HISTORY_NAVIGATION_STATUSES);
|
|
103
|
+
keys(record, "$", variantKeys("HistoryNavigationResult", record, "$"));
|
|
104
|
+
assertValidHistorySnapshot(record.snapshot);
|
|
105
|
+
if (record.status === "committed") {
|
|
106
|
+
receipt(record.receipt, "$.receipt");
|
|
107
|
+
} else {
|
|
108
|
+
rejection(record.rejection, "$.rejection");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function assertValidHistoryChangedEvent(
|
|
113
|
+
value: unknown,
|
|
114
|
+
): asserts value is HistoryChangedEvent {
|
|
115
|
+
assertNoPayload(value, "$");
|
|
116
|
+
const record = object(value, "$");
|
|
117
|
+
keys(record, "$", HISTORY_FIELDS.HistoryChangedEvent);
|
|
118
|
+
protocol(record.protocolVersion, "$.protocolVersion");
|
|
119
|
+
positiveInteger(record.authorityEpoch, "$.authorityEpoch");
|
|
120
|
+
id(record.historyId, "$.historyId");
|
|
121
|
+
optionalInteger(record.previousRevision, "$.previousRevision");
|
|
122
|
+
integer(record.committedRevision, "$.committedRevision");
|
|
123
|
+
oneOf(record.kind, "$.kind", HISTORY_CHANGED_KINDS);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function summary(value: unknown, path: string): void {
|
|
127
|
+
const record = object(value, path);
|
|
128
|
+
keys(record, path, HISTORY_FIELDS.HistorySummaryProjection);
|
|
129
|
+
id(record.historyId, `${path}.historyId`);
|
|
130
|
+
integer(record.revision, `${path}.revision`);
|
|
131
|
+
oneOf(record.mode, `${path}.mode`, HISTORY_MODES);
|
|
132
|
+
integer(record.undoDepth, `${path}.undoDepth`);
|
|
133
|
+
integer(record.redoDepth, `${path}.redoDepth`);
|
|
134
|
+
optionalId(record.currentEntryId, `${path}.currentEntryId`);
|
|
135
|
+
optionalString(record.nextUndoLabel, `${path}.nextUndoLabel`);
|
|
136
|
+
optionalString(record.nextRedoLabel, `${path}.nextRedoLabel`);
|
|
137
|
+
integer(record.retainedEntryCount, `${path}.retainedEntryCount`);
|
|
138
|
+
integer(record.retainedEncodedWeight, `${path}.retainedEncodedWeight`);
|
|
139
|
+
baseline(record.retainedBaseline, `${path}.retainedBaseline`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function baseline(value: unknown, path: string): void {
|
|
143
|
+
const record = object(value, path);
|
|
144
|
+
keys(record, path, HISTORY_FIELDS.HistoryBaselineProjection);
|
|
145
|
+
integer(record.prunedEntryCount, `${path}.prunedEntryCount`);
|
|
146
|
+
integer(record.prunedEncodedWeight, `${path}.prunedEncodedWeight`);
|
|
147
|
+
optionalId(record.lastPrunedEntryId, `${path}.lastPrunedEntryId`);
|
|
148
|
+
optionalInteger(record.lastPrunedSequence, `${path}.lastPrunedSequence`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function entryRecord(value: unknown, path: string): void {
|
|
152
|
+
const record = object(value, path);
|
|
153
|
+
keys(record, path, HISTORY_FIELDS.HistoryEntryRecord);
|
|
154
|
+
id(record.entryId, `${path}.entryId`);
|
|
155
|
+
string(record.label, `${path}.label`);
|
|
156
|
+
optionalId(record.kindId, `${path}.kindId`);
|
|
157
|
+
optionalId(record.groupId, `${path}.groupId`);
|
|
158
|
+
positiveInteger(record.sequence, `${path}.sequence`);
|
|
159
|
+
integer(record.committedRevision, `${path}.committedRevision`);
|
|
160
|
+
integer(record.encodedWeight, `${path}.encodedWeight`);
|
|
161
|
+
oneOf(record.position, `${path}.position`, HISTORY_ENTRY_POSITIONS);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function receipt(value: unknown, path: string): void {
|
|
165
|
+
const record = object(value, path);
|
|
166
|
+
keys(record, path, HISTORY_FIELDS.HistoryNavigationReceiptProjection);
|
|
167
|
+
id(record.historyId, `${path}.historyId`);
|
|
168
|
+
id(record.planId, `${path}.planId`);
|
|
169
|
+
integer(record.previousRevision, `${path}.previousRevision`);
|
|
170
|
+
integer(record.committedRevision, `${path}.committedRevision`);
|
|
171
|
+
oneOf(record.direction, `${path}.direction`, HISTORY_NAVIGATION_DIRECTIONS);
|
|
172
|
+
array(record.movedEntryIds, `${path}.movedEntryIds`).forEach((entry, index) =>
|
|
173
|
+
id(entry, `${path}.movedEntryIds[${index}]`),
|
|
174
|
+
);
|
|
175
|
+
navigationPosition(record.sourcePosition, `${path}.sourcePosition`);
|
|
176
|
+
navigationPosition(
|
|
177
|
+
record.authoritativePosition,
|
|
178
|
+
`${path}.authoritativePosition`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function navigationPosition(value: unknown, path: string): void {
|
|
183
|
+
const record = object(value, path);
|
|
184
|
+
keys(record, path, HISTORY_FIELDS.HistoryNavigationPositionProjection);
|
|
185
|
+
integer(record.appliedDepth, `${path}.appliedDepth`);
|
|
186
|
+
integer(record.futureDepth, `${path}.futureDepth`);
|
|
187
|
+
optionalId(record.currentEntryId, `${path}.currentEntryId`);
|
|
188
|
+
optionalString(record.nextUndoLabel, `${path}.nextUndoLabel`);
|
|
189
|
+
optionalId(record.nextRedoEntryId, `${path}.nextRedoEntryId`);
|
|
190
|
+
optionalString(record.nextRedoLabel, `${path}.nextRedoLabel`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function rejection(value: unknown, path: string): void {
|
|
194
|
+
const record = object(value, path);
|
|
195
|
+
keys(record, path, HISTORY_FIELDS.HistoryNavigationRejectionProjection);
|
|
196
|
+
oneOf(
|
|
197
|
+
record.code,
|
|
198
|
+
`${path}.code`,
|
|
199
|
+
HISTORY_NAVIGATION_REJECTION_CODES,
|
|
200
|
+
);
|
|
201
|
+
string(record.detail, `${path}.detail`);
|
|
202
|
+
boolean(record.refreshRequired, `${path}.refreshRequired`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function protocol(value: unknown, path: string): void {
|
|
206
|
+
if (value !== HISTORY_PROTOCOL_VERSION) {
|
|
207
|
+
fail(path, `expected exact protocol ${HISTORY_PROTOCOL_VERSION}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
212
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
213
|
+
fail(path, "expected object");
|
|
214
|
+
}
|
|
215
|
+
return value as Record<string, unknown>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function array(value: unknown, path: string): readonly unknown[] {
|
|
219
|
+
if (!Array.isArray(value)) fail(path, "expected array");
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function keys(
|
|
224
|
+
value: Record<string, unknown>,
|
|
225
|
+
path: string,
|
|
226
|
+
allowed: readonly string[],
|
|
227
|
+
): void {
|
|
228
|
+
const allowedSet = new Set(allowed);
|
|
229
|
+
for (const key of Object.keys(value)) {
|
|
230
|
+
if (!allowedSet.has(key)) fail(`${path}.${key}`, "unknown field");
|
|
231
|
+
}
|
|
232
|
+
for (const key of allowed) {
|
|
233
|
+
if (!(key in value)) fail(`${path}.${key}`, "missing field");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function oneOf(
|
|
238
|
+
value: unknown,
|
|
239
|
+
path: string,
|
|
240
|
+
values: readonly string[],
|
|
241
|
+
): void {
|
|
242
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
243
|
+
fail(path, `expected one of ${values.join(", ")}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function id(value: unknown, path: string): void {
|
|
248
|
+
string(value, path);
|
|
249
|
+
if (
|
|
250
|
+
(value as string).length === 0 ||
|
|
251
|
+
(value as string).length > HISTORY_MAXIMUM_OPAQUE_ID_BYTES ||
|
|
252
|
+
!/^[a-z0-9._:-]+$/.test(value as string)
|
|
253
|
+
) {
|
|
254
|
+
fail(path, "expected bounded lowercase opaque id");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function optionalId(value: unknown, path: string): void {
|
|
259
|
+
if (value !== null) id(value, path);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function string(value: unknown, path: string): void {
|
|
263
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
264
|
+
fail(path, "expected nonempty string");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function optionalString(value: unknown, path: string): void {
|
|
269
|
+
if (value !== null) string(value, path);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function integer(value: unknown, path: string): void {
|
|
273
|
+
if (!Number.isSafeInteger(value) || (value as number) < 0) {
|
|
274
|
+
fail(path, "expected nonnegative safe integer");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function positiveInteger(value: unknown, path: string): void {
|
|
279
|
+
integer(value, path);
|
|
280
|
+
if ((value as number) === 0) fail(path, "expected nonzero integer");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function optionalInteger(value: unknown, path: string): void {
|
|
284
|
+
if (value !== null) integer(value, path);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function boolean(value: unknown, path: string): void {
|
|
288
|
+
if (typeof value !== "boolean") fail(path, "expected boolean");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function assertNoPayload(value: unknown, path: string): void {
|
|
292
|
+
if (Array.isArray(value)) {
|
|
293
|
+
value.forEach((entry, index) => assertNoPayload(entry, `${path}[${index}]`));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (typeof value !== "object" || value === null) return;
|
|
297
|
+
for (const [key, child] of Object.entries(value)) {
|
|
298
|
+
if (key === "payload") fail(`${path}.payload`, "product payload is forbidden");
|
|
299
|
+
assertNoPayload(child, `${path}.${key}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function fail(path: string, message: string): never {
|
|
304
|
+
throw new HistoryProtocolValidationError(path, message);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* What sits below the page's oldest entry.
|
|
309
|
+
*
|
|
310
|
+
* `baseline` means retention took everything before it, so the position is
|
|
311
|
+
* where the surviving history begins rather than where the document did. A
|
|
312
|
+
* renderer that draws it as the origin claims data the authority discarded,
|
|
313
|
+
* which is why the two are separate variants and not a flag.
|
|
314
|
+
*/
|
|
315
|
+
function floor(value: unknown, path: string): void {
|
|
316
|
+
const record = object(value, path);
|
|
317
|
+
oneOf(record.kind, `${path}.kind`, HISTORY_PAGE_FLOORS);
|
|
318
|
+
keys(record, path, variantKeys("HistoryPageFloorProjection", record, path));
|
|
319
|
+
if (record.kind === "baseline") integer(record.prunedEntryCount, `${path}.prunedEntryCount`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Allowed keys for one tagged-union variant, from the generated map, with the
|
|
324
|
+
* discriminant's name read from the map too.
|
|
325
|
+
*
|
|
326
|
+
* A missing entry means the generator failed to read the union: every caller
|
|
327
|
+
* checks the discriminant above this call.
|
|
328
|
+
*/
|
|
329
|
+
function variantKeys(type: string, record: Record<string, unknown>, path: string): readonly string[] {
|
|
330
|
+
const discriminant = record[HISTORY_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
331
|
+
const allowed = HISTORY_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
332
|
+
if (allowed === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
333
|
+
return allowed;
|
|
334
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assertForkBranchCommand, assertForkBranchPage, assertForkContinuationCommand, assertForkContinuationPage, assertForkDeleteCommand, assertForkPruneCommand, assertForkPruneResult, assertForkRemovalReceipt, assertForkChangedEvent, assertForkNavigationCommand, assertForkNavigationResult, assertForkPathCommand, assertForkPathPage, assertForkSnapshot } from "./validation.ts";
|
|
2
|
+
import type { ForkBranchPageCommand, ForkBranchPageSnapshot, ForkChangedEvent, ForkContinuationPageCommand, ForkContinuationPageSnapshot, ForkDeleteContinuationCommand, ForkPruneCommand, ForkPruneResult, ForkRemovalReceiptProjection, ForkNavigationCommand, ForkNavigationResult, ForkPathPageCommand, ForkPathPageSnapshot, ForkSnapshot } from "./generated/protocol.ts";
|
|
3
|
+
import type { CheckedForkHistoryPort, ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
|
|
4
|
+
|
|
5
|
+
export class ForkHistoryClient implements CheckedForkHistoryPort {
|
|
6
|
+
constructor(readonly port: ForkHistoryPort) {}
|
|
7
|
+
nextPlanId(): string { return this.port.nextPlanId(); }
|
|
8
|
+
async snapshot(): Promise<ForkSnapshot> { const value = await this.port.snapshot(); assertForkSnapshot(value); return value; }
|
|
9
|
+
async path(command: ForkPathPageCommand): Promise<ForkPathPageSnapshot> { assertForkPathCommand(command); const value = await this.port.path(command); assertForkPathPage(value); return value; }
|
|
10
|
+
async branches(command: ForkBranchPageCommand): Promise<ForkBranchPageSnapshot> { assertForkBranchCommand(command); const value = await this.port.branches(command); assertForkBranchPage(value); return value; }
|
|
11
|
+
async continuations(command: ForkContinuationPageCommand): Promise<ForkContinuationPageSnapshot> { assertForkContinuationCommand(command); const value = await this.port.continuations(command); assertForkContinuationPage(value); return value; }
|
|
12
|
+
async deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkRemovalReceiptProjection> { assertForkDeleteCommand(command); const value = await this.port.deleteContinuation(command); assertForkRemovalReceipt(value); return value; }
|
|
13
|
+
async prune(command: ForkPruneCommand): Promise<ForkPruneResult> { assertForkPruneCommand(command); const value = await this.port.prune(command); assertForkPruneResult(value); return value; }
|
|
14
|
+
async navigate(command: ForkNavigationCommand): Promise<ForkNavigationResult> { assertForkNavigationCommand(command); const value = await this.port.navigate(command); assertForkNavigationResult(value); return value; }
|
|
15
|
+
async listen(listener: (event: ForkChangedEvent) => void): Promise<ForkHistoryUnlisten> { if (this.port.listen === undefined) return () => {}; return this.port.listen((value) => { assertForkChangedEvent(value); listener(value); }); }
|
|
16
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { ForkHistoryClient } from "./client.ts";
|
|
2
|
+
import { FORK_HISTORY_PROTOCOL_VERSION, MAXIMUM_FORK_HISTORY_PAGE_SIZE, type ForkBranchId, type ForkBranchPageSnapshot, type ForkChangedEvent, type ForkContinuationPageSnapshot, type ForkEntryRecord, type ForkPruneResult, type ForkRemovalReceiptProjection, type ForkNavigationResult, type ForkNavigationTargetProjection, type ForkPathPageSnapshot, type ForkPathTargetProjection, type ForkSnapshot } from "./generated/protocol.ts";
|
|
3
|
+
import type { ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
|
|
4
|
+
|
|
5
|
+
export type ForkHistoryControllerStatus = { readonly kind: "idle" } | { readonly kind: "loading" } | { readonly kind: "ready" } | { readonly kind: "failed"; readonly error: unknown };
|
|
6
|
+
export interface ForkHistoryControllerOptions { readonly port: ForkHistoryPort; readonly pathPageSize?: number; readonly branchPageSize?: number; readonly continuationPageSize?: number; }
|
|
7
|
+
|
|
8
|
+
export class ForkHistoryController {
|
|
9
|
+
readonly #client: ForkHistoryClient;
|
|
10
|
+
readonly #observers = new Set<() => void>();
|
|
11
|
+
readonly #pathPageSize: number;
|
|
12
|
+
readonly #branchPageSize: number;
|
|
13
|
+
readonly #continuationPageSize: number;
|
|
14
|
+
#status: ForkHistoryControllerStatus = { kind: "idle" };
|
|
15
|
+
#snapshot?: ForkSnapshot;
|
|
16
|
+
#path?: ForkPathPageSnapshot;
|
|
17
|
+
#branches?: ForkBranchPageSnapshot;
|
|
18
|
+
#pathTarget: ForkPathTargetProjection = { kind: "default" };
|
|
19
|
+
#started = false;
|
|
20
|
+
#lifecycle = 0;
|
|
21
|
+
#load = 0;
|
|
22
|
+
#navigation = 0;
|
|
23
|
+
#pending = false;
|
|
24
|
+
#unlisten: ForkHistoryUnlisten[] = [];
|
|
25
|
+
|
|
26
|
+
constructor(options: ForkHistoryControllerOptions) { this.#client = new ForkHistoryClient(options.port); this.#pathPageSize = pageSize(options.pathPageSize ?? 50); this.#branchPageSize = pageSize(options.branchPageSize ?? 50); this.#continuationPageSize = pageSize(options.continuationPageSize ?? 50); }
|
|
27
|
+
get status() { return this.#status; }
|
|
28
|
+
get snapshot() { return this.#snapshot; }
|
|
29
|
+
get path() { return this.#path; }
|
|
30
|
+
get branches() { return this.#branches; }
|
|
31
|
+
get entries(): readonly ForkEntryRecord[] { return this.#path?.entries ?? []; }
|
|
32
|
+
get navigationPending() { return this.#pending; }
|
|
33
|
+
get canUndo() { return (this.#snapshot?.summary.undoDepth ?? 0) > 0; }
|
|
34
|
+
get canRedo() { return (this.#snapshot?.summary.redoDepth ?? 0) > 0; }
|
|
35
|
+
observe(observer: () => void): () => void { this.#observers.add(observer); return () => this.#observers.delete(observer); }
|
|
36
|
+
|
|
37
|
+
async start(): Promise<void> {
|
|
38
|
+
if (this.#started) return;
|
|
39
|
+
this.#started = true; const lifecycle = ++this.#lifecycle; this.#setStatus({ kind: "loading" });
|
|
40
|
+
try {
|
|
41
|
+
const unlisten = await this.#client.listen((event) => this.#changed(event));
|
|
42
|
+
if (!this.#started || lifecycle !== this.#lifecycle) { await unlisten(); return; }
|
|
43
|
+
this.#unlisten.push(unlisten); await this.refresh();
|
|
44
|
+
} catch (error) { if (this.#started && lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error }); }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async stop(): Promise<void> {
|
|
48
|
+
this.#started = false; this.#lifecycle += 1; this.#load += 1; this.#navigation += 1;
|
|
49
|
+
await Promise.allSettled(this.#unlisten.splice(0).map((dispose) => dispose()));
|
|
50
|
+
this.#snapshot = undefined; this.#path = undefined; this.#branches = undefined; this.#pathTarget = { kind: "default" }; this.#pending = false; this.#setStatus({ kind: "idle" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async refresh(): Promise<void> {
|
|
54
|
+
if (!this.#started) return;
|
|
55
|
+
const load = ++this.#load;
|
|
56
|
+
// The offset a consumer had paged to, so a refresh returns the page they
|
|
57
|
+
// were looking at rather than sending them back to the first one.
|
|
58
|
+
const branchOffset = this.#branches?.offset;
|
|
59
|
+
try {
|
|
60
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
61
|
+
const snapshot = await this.#client.snapshot();
|
|
62
|
+
const path = await this.#client.path(this.#pathCommand(snapshot, this.#pathTarget));
|
|
63
|
+
if (!same(snapshot, path)) continue;
|
|
64
|
+
// Only for a consumer that asked for branches. Loading a page nobody
|
|
65
|
+
// wanted would make every refresh pay for a projection it will not use.
|
|
66
|
+
const branches = branchOffset === undefined
|
|
67
|
+
? undefined
|
|
68
|
+
: await this.#client.branches(this.#branchCommand(snapshot, branchOffset));
|
|
69
|
+
if (branches !== undefined && !same(snapshot, branches)) continue;
|
|
70
|
+
if (this.#started && load === this.#load) { this.#install(snapshot, path, branches); this.#setStatus({ kind: "ready" }); }
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
throw new ForkHistoryProjectionGapError();
|
|
74
|
+
} catch (error) { if (this.#started && load === this.#load) this.#setStatus({ kind: "failed", error }); }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async loadBranches(offset = 0): Promise<ForkBranchPageSnapshot> {
|
|
78
|
+
const snapshot = this.#required();
|
|
79
|
+
const value = await this.#client.branches(this.#branchCommand(snapshot, offset));
|
|
80
|
+
if (!same(snapshot, value)) throw new ForkHistoryProjectionGapError();
|
|
81
|
+
this.#branches = value; this.#notify(); return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The continuations at one entry, or at the root when `anchorEntryId` is
|
|
86
|
+
* null. Every child is returned, the one already on the current page
|
|
87
|
+
* included: a renderer showing entry E inline drops it and shows the rest as
|
|
88
|
+
* that entry's forks, which is why `continuationCount` is one more than the
|
|
89
|
+
* fork badge.
|
|
90
|
+
*
|
|
91
|
+
* Not cached and not refreshed. A consumer asks when the operator opens an
|
|
92
|
+
* entry, and the revision check below tells them if it went stale meanwhile.
|
|
93
|
+
*/
|
|
94
|
+
async loadContinuations(anchorEntryId: string | null, offset = 0): Promise<ForkContinuationPageSnapshot> {
|
|
95
|
+
const snapshot = this.#required();
|
|
96
|
+
const value = await this.#client.continuations({ protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, expectedRevision: snapshot.summary.revision, anchorEntryId, offset, limit: this.#continuationPageSize });
|
|
97
|
+
if (!same(snapshot, value)) throw new ForkHistoryProjectionGapError();
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The flat run beginning at one entry. The same snapshot type as the main
|
|
103
|
+
* path, so a renderer draws a nested fork with the component it already has.
|
|
104
|
+
*/
|
|
105
|
+
async loadContinuationRun(fromEntryId: string, offset = 0): Promise<ForkPathPageSnapshot> {
|
|
106
|
+
const snapshot = this.#required();
|
|
107
|
+
const value = await this.#client.path({ ...this.#pathCommand(snapshot, { kind: "continuation", fromEntryId }), offset });
|
|
108
|
+
if (!same(snapshot, value)) throw new ForkHistoryProjectionGapError();
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Deletes one continuation and everything below it, then refreshes.
|
|
114
|
+
*
|
|
115
|
+
* **Irreversible.** Nothing restores what this removes. Confirm it with the
|
|
116
|
+
* operator before calling; the authority will not ask.
|
|
117
|
+
*
|
|
118
|
+
* It refuses four things rather than working around them: the entry the
|
|
119
|
+
* operator stands on or above, the active line, a pinned branch, and an
|
|
120
|
+
* entry that does not exist. A refusal arrives as a rejected promise.
|
|
121
|
+
*/
|
|
122
|
+
async deleteContinuation(entryId: string): Promise<ForkRemovalReceiptProjection> {
|
|
123
|
+
const snapshot = this.#required();
|
|
124
|
+
const receipt = await this.#client.deleteContinuation({ protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, expectedRevision: snapshot.summary.revision, entryId });
|
|
125
|
+
// Every page the consumer holds may name entries that no longer exist, so
|
|
126
|
+
// this refresh is not optional and is not left to the changed event.
|
|
127
|
+
await this.refresh();
|
|
128
|
+
return receipt;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Prunes the unprotected share to a budget, then refreshes if anything went.
|
|
133
|
+
*
|
|
134
|
+
* The budget bounds what is **not** protected -- not on the current branch
|
|
135
|
+
* and not on a pinned branch. Size it for the transient history to keep; a
|
|
136
|
+
* graph with a large pinned set exceeds it and that is correct.
|
|
137
|
+
*
|
|
138
|
+
* Longhorn owns no scheduler. Call this on record, on a timer, on an
|
|
139
|
+
* operator action, or not at all: those are the app's three triggers and
|
|
140
|
+
* opting out is not calling it. `summary.retainedEntryCount` and
|
|
141
|
+
* `summary.retainedEncodedWeight` are there to decide with.
|
|
142
|
+
*/
|
|
143
|
+
async prune(maximumEntries: number, maximumEncodedWeight: number): Promise<ForkPruneResult> {
|
|
144
|
+
const snapshot = this.#required();
|
|
145
|
+
const result = await this.#client.prune({ protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, expectedRevision: snapshot.summary.revision, maximumEntries, maximumEncodedWeight });
|
|
146
|
+
if (result.status === "pruned") await this.refresh();
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async selectDefaultPath(): Promise<void> { this.#pathTarget = { kind: "default" }; await this.refresh(); }
|
|
151
|
+
async selectBranchPath(branchId: ForkBranchId): Promise<void> { this.#pathTarget = { kind: "branch", branchId }; await this.refresh(); }
|
|
152
|
+
undo(): Promise<ForkNavigationResult> { return this.#navigate({ kind: "undo" }); }
|
|
153
|
+
redo(): Promise<ForkNavigationResult> { return this.#navigate({ kind: "redo" }); }
|
|
154
|
+
checkout(branchId: ForkBranchId, entryId: string): Promise<ForkNavigationResult> { return this.#navigate({ kind: "checkout", branchId, entryId }); }
|
|
155
|
+
/** Move to a branch's root, the position before its first entry. */
|
|
156
|
+
checkoutBranchRoot(branchId: ForkBranchId): Promise<ForkNavigationResult> { return this.#navigate({ kind: "checkoutBranchRoot", branchId }); }
|
|
157
|
+
/**
|
|
158
|
+
* Check out the run beginning at one entry: it becomes the current line,
|
|
159
|
+
* and the previous line becomes a fork at the same entry. No delta of it is
|
|
160
|
+
* applied, and the operator ends up standing at the fork entry whether or
|
|
161
|
+
* not they started there.
|
|
162
|
+
*
|
|
163
|
+
* This commits. Browsing the forks does not — use `loadContinuationRun` to
|
|
164
|
+
* show a fork's entries without choosing it.
|
|
165
|
+
*/
|
|
166
|
+
checkoutContinuation(entryId: string): Promise<ForkNavigationResult> { return this.#navigate({ kind: "checkoutContinuation", entryId }); }
|
|
167
|
+
|
|
168
|
+
async #navigate(target: ForkNavigationTargetProjection): Promise<ForkNavigationResult> {
|
|
169
|
+
const snapshot = this.#required(); const navigation = ++this.#navigation; this.#pending = true; this.#notify();
|
|
170
|
+
try {
|
|
171
|
+
const result = await this.#client.navigate({ protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, planId: this.#client.nextPlanId(), expectedRevision: snapshot.summary.revision, target });
|
|
172
|
+
if (!this.#started || navigation !== this.#navigation) throw new ForkHistoryLateResultError();
|
|
173
|
+
const path = await this.#client.path(this.#pathCommand(result.snapshot, this.#pathTarget));
|
|
174
|
+
if (!this.#started || navigation !== this.#navigation) throw new ForkHistoryLateResultError();
|
|
175
|
+
if (!same(result.snapshot, path)) throw new ForkHistoryProjectionGapError();
|
|
176
|
+
const branchOffset = this.#branches?.offset;
|
|
177
|
+
const branches = branchOffset === undefined
|
|
178
|
+
? undefined
|
|
179
|
+
: await this.#client.branches(this.#branchCommand(result.snapshot, branchOffset));
|
|
180
|
+
if (!this.#started || navigation !== this.#navigation) throw new ForkHistoryLateResultError();
|
|
181
|
+
if (branches !== undefined && !same(result.snapshot, branches)) throw new ForkHistoryProjectionGapError();
|
|
182
|
+
this.#install(result.snapshot, path, branches); this.#setStatus({ kind: "ready" }); return result;
|
|
183
|
+
} finally { if (navigation === this.#navigation) { this.#pending = false; this.#notify(); } }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#pathCommand(snapshot: ForkSnapshot, target: ForkPathTargetProjection) { return { protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, expectedRevision: snapshot.summary.revision, target, offset: 0, limit: this.#pathPageSize } as const; }
|
|
187
|
+
#required(): ForkSnapshot { if (!this.#started || this.#snapshot === undefined) throw new ForkHistoryUnavailableError(); return this.#snapshot; }
|
|
188
|
+
#branchCommand(snapshot: ForkSnapshot, offset: number) { return { protocolVersion: FORK_HISTORY_PROTOCOL_VERSION, authorityEpoch: snapshot.authorityEpoch, historyId: snapshot.summary.historyId, expectedRevision: snapshot.summary.revision, offset, limit: this.#branchPageSize } as const; }
|
|
189
|
+
#install(snapshot: ForkSnapshot, path: ForkPathPageSnapshot, branches?: ForkBranchPageSnapshot): void { const current = this.#snapshot; if (current !== undefined && snapshot.authorityEpoch === current.authorityEpoch && snapshot.summary.historyId === current.summary.historyId && snapshot.summary.revision < current.summary.revision) return; this.#snapshot = snapshot; this.#path = path; if (branches !== undefined) this.#branches = branches; else if (this.#branches !== undefined && !same(snapshot, this.#branches)) this.#branches = undefined; this.#notify(); }
|
|
190
|
+
#changed(event: ForkChangedEvent): void { const snapshot = this.#snapshot; if (!this.#started || snapshot === undefined || event.authorityEpoch !== snapshot.authorityEpoch || event.historyId !== snapshot.summary.historyId || event.committedRevision > snapshot.summary.revision) void this.refresh(); }
|
|
191
|
+
#setStatus(status: ForkHistoryControllerStatus): void { this.#status = status; this.#notify(); }
|
|
192
|
+
#notify(): void { for (const observer of this.#observers) observer(); }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function same(snapshot: ForkSnapshot, page: { authorityEpoch: number; historyId: string; revision: number }): boolean { return snapshot.authorityEpoch === page.authorityEpoch && snapshot.summary.historyId === page.historyId && snapshot.summary.revision === page.revision; }
|
|
196
|
+
function pageSize(value: number): number { if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM_FORK_HISTORY_PAGE_SIZE) throw new RangeError(`fork-history page size must be 1..${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`); return value; }
|
|
197
|
+
export class ForkHistoryUnavailableError extends Error {}
|
|
198
|
+
export class ForkHistoryProjectionGapError extends Error {}
|
|
199
|
+
export class ForkHistoryLateResultError extends Error {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @generated by `effigy generate:history-tree`; do not edit.
|
|
2
|
+
// Allowed field names per protocol type, from the Rust structs.
|
|
3
|
+
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
|
+
// contract 010's Boundary Validation Target.
|
|
5
|
+
|
|
6
|
+
export const HISTORY_TREE_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"ForkSummaryProjection": ["historyId", "revision", "currentBranchId", "currentEntryId", "undoDepth", "redoDepth", "nextUndoLabel", "nextRedoLabel", "retainedEntryCount", "retainedEncodedWeight", "branchCount", "alternatePathCount"],
|
|
8
|
+
"ForkSnapshot": ["protocolVersion", "authorityEpoch", "summary"],
|
|
9
|
+
"ForkEntryRecord": ["entryId", "label", "kindId", "recordedAt", "groupId", "sequence", "committedRevision", "encodedWeight", "position", "continuationCount"],
|
|
10
|
+
"ForkPathPageCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "target", "offset", "limit"],
|
|
11
|
+
"ForkPathPageSnapshot": ["protocolVersion", "authorityEpoch", "historyId", "revision", "branchId", "headEntryId", "offset", "precedingContinuationCount", "floor", "totalEntries", "entries", "truncatedBefore", "truncatedAfter"],
|
|
12
|
+
"ForkBranchRecord": ["branchId", "headEntryId", "divergenceEntryId", "divergenceBranchId", "name", "annotation", "pinned", "current"],
|
|
13
|
+
"ForkBranchPageCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "offset", "limit"],
|
|
14
|
+
"ForkBranchPageSnapshot": ["protocolVersion", "authorityEpoch", "historyId", "revision", "offset", "totalBranches", "branches", "truncatedBefore", "truncatedAfter"],
|
|
15
|
+
"ForkContinuationRecord": ["entryId", "label", "recordedAt", "preferred", "entryCount", "branchId", "branchName"],
|
|
16
|
+
"ForkContinuationPageCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "anchorEntryId", "offset", "limit"],
|
|
17
|
+
"ForkContinuationPageSnapshot": ["protocolVersion", "authorityEpoch", "historyId", "revision", "anchorEntryId", "offset", "totalContinuations", "continuations", "truncatedBefore", "truncatedAfter"],
|
|
18
|
+
"ForkDeleteContinuationCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "entryId"],
|
|
19
|
+
"ForkRemovedEntryRecord": ["entryId", "sequence", "encodedWeight"],
|
|
20
|
+
"ForkRemovalReceiptProjection": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "removedEntries", "removedBranches", "removedCheckpoints", "retainedEntryCount", "retainedEncodedWeight", "unprotectedEntryCount", "unprotectedEncodedWeight"],
|
|
21
|
+
"ForkPruneCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "maximumEntries", "maximumEncodedWeight"],
|
|
22
|
+
"ForkNavigationCommand": ["protocolVersion", "authorityEpoch", "historyId", "planId", "expectedRevision", "target"],
|
|
23
|
+
"ForkNavigationReceiptProjection": ["historyId", "planId", "previousRevision", "committedRevision", "sourceEntryId", "targetEntryId", "targetBranchId", "movedEntryIds"],
|
|
24
|
+
"ForkNavigationRejectionProjection": ["code", "detail", "refreshRequired"],
|
|
25
|
+
"ForkChangedEvent": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "kind"],
|
|
26
|
+
};
|