@inflatable-cookie/longhorn 0.5.0 → 0.7.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/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +78 -109
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isOpaqueId } from "../core/identifiers.ts";
|
|
2
|
+
import { checkWireFields, readWireRecord, wireVariantFields } from "../core/record.ts";
|
|
3
|
+
import {
|
|
4
|
+
HISTORY_TREE_VARIANT_FIELDS,
|
|
5
|
+
HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
6
|
+
} from "./generated/variant-fields.ts";
|
|
2
7
|
import {
|
|
3
8
|
FORK_HISTORY_CHANGED_KINDS,
|
|
4
9
|
FORK_HISTORY_ENTRY_POSITIONS,
|
|
@@ -8,27 +13,35 @@ import {
|
|
|
8
13
|
FORK_HISTORY_PATH_FLOORS,
|
|
9
14
|
FORK_HISTORY_PATH_TARGETS,
|
|
10
15
|
FORK_HISTORY_PRUNE_STATUSES,
|
|
16
|
+
FORK_HISTORY_DELETE_STATUSES,
|
|
17
|
+
FORK_HISTORY_RETENTION_REJECTION_CODES,
|
|
11
18
|
FORK_HISTORY_PROTOCOL_VERSION,
|
|
12
19
|
MAXIMUM_FORK_HISTORY_PAGE_SIZE,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
} from "./generated/protocol.ts";
|
|
21
|
+
import type {
|
|
22
|
+
ForkBranchPageCommand,
|
|
23
|
+
ForkBranchPageSnapshot,
|
|
24
|
+
ForkContinuationPageCommand,
|
|
25
|
+
ForkContinuationPageSnapshot,
|
|
26
|
+
ForkDeleteContinuationCommand,
|
|
27
|
+
ForkPruneCommand,
|
|
28
|
+
ForkPruneResult,
|
|
29
|
+
ForkDeleteResult,
|
|
30
|
+
ForkRemovalReceiptProjection,
|
|
31
|
+
ForkChangedEvent,
|
|
32
|
+
ForkNavigationCommand,
|
|
33
|
+
ForkNavigationResult,
|
|
34
|
+
ForkPathPageCommand,
|
|
35
|
+
ForkPathPageSnapshot,
|
|
36
|
+
ForkSnapshot,
|
|
27
37
|
} from "./generated/protocol.ts";
|
|
28
38
|
import { HISTORY_TREE_FIELDS } from "./generated/fields.ts";
|
|
29
39
|
|
|
30
40
|
export class ForkHistoryValidationError extends Error {
|
|
31
|
-
constructor(
|
|
41
|
+
constructor(
|
|
42
|
+
readonly path: string,
|
|
43
|
+
message: string,
|
|
44
|
+
) {
|
|
32
45
|
super(`${path}: ${message}`);
|
|
33
46
|
this.name = "ForkHistoryValidationError";
|
|
34
47
|
}
|
|
@@ -46,7 +59,16 @@ export function assertForkSnapshot(value: unknown): asserts value is ForkSnapsho
|
|
|
46
59
|
integer(summary.revision, "$.summary.revision");
|
|
47
60
|
id(summary.currentBranchId, "$.summary.currentBranchId");
|
|
48
61
|
optionalId(summary.currentEntryId, "$.summary.currentEntryId");
|
|
49
|
-
for (const key of [
|
|
62
|
+
for (const key of [
|
|
63
|
+
"undoDepth",
|
|
64
|
+
"redoDepth",
|
|
65
|
+
"retainedEntryCount",
|
|
66
|
+
"retainedEncodedWeight",
|
|
67
|
+
"branchCount",
|
|
68
|
+
"alternatePathCount",
|
|
69
|
+
] as const) {
|
|
70
|
+
integer(summary[key], `$.summary.${key}`);
|
|
71
|
+
}
|
|
50
72
|
optionalString(summary.nextUndoLabel, "$.summary.nextUndoLabel");
|
|
51
73
|
optionalString(summary.nextRedoLabel, "$.summary.nextRedoLabel");
|
|
52
74
|
}
|
|
@@ -56,8 +78,12 @@ export function assertForkPathCommand(value: unknown): asserts value is ForkPath
|
|
|
56
78
|
const target = object(object(value, "$").target, "$.target");
|
|
57
79
|
oneOf(target.kind, "$.target.kind", FORK_HISTORY_PATH_TARGETS);
|
|
58
80
|
exact(target, "$.target", variantFields("ForkPathTargetProjection", target, "$.target"));
|
|
59
|
-
if (target.kind === "branch")
|
|
60
|
-
|
|
81
|
+
if (target.kind === "branch") {
|
|
82
|
+
id(target.branchId, "$.target.branchId");
|
|
83
|
+
}
|
|
84
|
+
if (target.kind === "continuation") {
|
|
85
|
+
id(target.fromEntryId, "$.target.fromEntryId");
|
|
86
|
+
}
|
|
61
87
|
}
|
|
62
88
|
|
|
63
89
|
export function assertForkBranchCommand(value: unknown): asserts value is ForkBranchPageCommand {
|
|
@@ -72,14 +98,17 @@ export function assertForkPathPage(value: unknown): asserts value is ForkPathPag
|
|
|
72
98
|
optionalId(root.branchId, "$.branchId");
|
|
73
99
|
optionalId(root.headEntryId, "$.headEntryId");
|
|
74
100
|
integer(root.precedingContinuationCount, "$.precedingContinuationCount");
|
|
75
|
-
//
|
|
76
|
-
// nested run says `anchor` and means "draw nothing, it is already above".
|
|
101
|
+
// An anchor floor refers to the entry already drawn above a nested run.
|
|
77
102
|
const floor = object(root.floor, "$.floor");
|
|
78
103
|
oneOf(floor.kind, "$.floor.kind", FORK_HISTORY_PATH_FLOORS);
|
|
79
104
|
exact(floor, "$.floor", variantFields("ForkPathFloorProjection", floor, "$.floor"));
|
|
80
|
-
if (floor.kind === "anchor")
|
|
105
|
+
if (floor.kind === "anchor") {
|
|
106
|
+
id(floor.entryId, "$.floor.entryId");
|
|
107
|
+
}
|
|
81
108
|
integer(root.totalEntries, "$.totalEntries");
|
|
82
|
-
array(root.entries, "$.entries").forEach((entry, index) =>
|
|
109
|
+
array(root.entries, "$.entries").forEach((entry, index) =>
|
|
110
|
+
entryRecord(entry, `$.entries[${index}]`),
|
|
111
|
+
);
|
|
83
112
|
boolean(root.truncatedBefore, "$.truncatedBefore");
|
|
84
113
|
boolean(root.truncatedAfter, "$.truncatedAfter");
|
|
85
114
|
}
|
|
@@ -106,66 +135,215 @@ export function assertForkBranchPage(value: unknown): asserts value is ForkBranc
|
|
|
106
135
|
boolean(root.truncatedAfter, "$.truncatedAfter");
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
export function assertForkNavigationCommand(
|
|
138
|
+
export function assertForkNavigationCommand(
|
|
139
|
+
value: unknown,
|
|
140
|
+
): asserts value is ForkNavigationCommand {
|
|
110
141
|
noPayload(value);
|
|
111
142
|
const root = object(value, "$");
|
|
112
143
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkNavigationCommand);
|
|
113
|
-
protocol(root.protocolVersion, "$.protocolVersion");
|
|
114
|
-
|
|
144
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
145
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
146
|
+
id(root.historyId, "$.historyId");
|
|
147
|
+
id(root.planId, "$.planId");
|
|
148
|
+
integer(root.expectedRevision, "$.expectedRevision");
|
|
149
|
+
const target = object(root.target, "$.target");
|
|
150
|
+
oneOf(target.kind, "$.target.kind", FORK_HISTORY_NAVIGATION_TARGETS);
|
|
115
151
|
exact(target, "$.target", variantFields("ForkNavigationTargetProjection", target, "$.target"));
|
|
116
|
-
if (target.kind === "checkout") {
|
|
117
|
-
|
|
118
|
-
|
|
152
|
+
if (target.kind === "checkout") {
|
|
153
|
+
id(target.branchId, "$.target.branchId");
|
|
154
|
+
id(target.entryId, "$.target.entryId");
|
|
155
|
+
}
|
|
156
|
+
if (target.kind === "checkoutBranchRoot") {
|
|
157
|
+
id(target.branchId, "$.target.branchId");
|
|
158
|
+
}
|
|
159
|
+
if (target.kind === "checkoutContinuation") {
|
|
160
|
+
id(target.entryId, "$.target.entryId");
|
|
161
|
+
}
|
|
119
162
|
}
|
|
120
163
|
|
|
121
164
|
export function assertForkNavigationResult(value: unknown): asserts value is ForkNavigationResult {
|
|
122
165
|
noPayload(value);
|
|
123
|
-
const root = object(value, "$");
|
|
124
|
-
|
|
166
|
+
const root = object(value, "$");
|
|
167
|
+
oneOf(root.status, "$.status", FORK_HISTORY_NAVIGATION_STATUSES);
|
|
168
|
+
exact(
|
|
169
|
+
root,
|
|
170
|
+
"$",
|
|
171
|
+
root.status === "committed"
|
|
172
|
+
? ["status", "snapshot", "receipt"]
|
|
173
|
+
: ["status", "snapshot", "rejection"],
|
|
174
|
+
);
|
|
125
175
|
assertForkSnapshot(root.snapshot);
|
|
126
176
|
if (root.status === "committed") {
|
|
127
177
|
const receipt = object(root.receipt, "$.receipt");
|
|
128
178
|
exact(receipt, "$.receipt", HISTORY_TREE_FIELDS.ForkNavigationReceiptProjection);
|
|
129
|
-
id(receipt.historyId, "$.receipt.historyId");
|
|
179
|
+
id(receipt.historyId, "$.receipt.historyId");
|
|
180
|
+
id(receipt.planId, "$.receipt.planId");
|
|
181
|
+
integer(receipt.previousRevision, "$.receipt.previousRevision");
|
|
182
|
+
integer(receipt.committedRevision, "$.receipt.committedRevision");
|
|
183
|
+
optionalId(receipt.sourceEntryId, "$.receipt.sourceEntryId");
|
|
184
|
+
optionalId(receipt.targetEntryId, "$.receipt.targetEntryId");
|
|
185
|
+
id(receipt.targetBranchId, "$.receipt.targetBranchId");
|
|
186
|
+
array(receipt.movedEntryIds, "$.receipt.movedEntryIds").forEach((entry, index) =>
|
|
187
|
+
id(entry, `$.receipt.movedEntryIds[${index}]`),
|
|
188
|
+
);
|
|
130
189
|
} else {
|
|
131
190
|
const rejection = object(root.rejection, "$.rejection");
|
|
132
|
-
exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
|
|
191
|
+
exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
|
|
192
|
+
oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_NAVIGATION_REJECTION_CODES);
|
|
193
|
+
string(rejection.detail, "$.rejection.detail");
|
|
194
|
+
boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
|
|
133
195
|
}
|
|
134
196
|
}
|
|
135
197
|
|
|
136
198
|
export function assertForkChangedEvent(value: unknown): asserts value is ForkChangedEvent {
|
|
137
|
-
noPayload(value);
|
|
199
|
+
noPayload(value);
|
|
200
|
+
const root = object(value, "$");
|
|
138
201
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkChangedEvent);
|
|
139
|
-
protocol(root.protocolVersion, "$.protocolVersion");
|
|
140
|
-
|
|
141
|
-
|
|
202
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
203
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
204
|
+
id(root.historyId, "$.historyId");
|
|
205
|
+
if (root.previousRevision !== null) {
|
|
206
|
+
integer(root.previousRevision, "$.previousRevision");
|
|
207
|
+
}
|
|
208
|
+
integer(root.committedRevision, "$.committedRevision");
|
|
209
|
+
oneOf(root.kind, "$.kind", FORK_HISTORY_CHANGED_KINDS);
|
|
142
210
|
}
|
|
143
211
|
|
|
144
|
-
function commandBase(value: unknown, allowed:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
212
|
+
function commandBase(value: unknown, allowed: ReadonlyArray<string>): void {
|
|
213
|
+
noPayload(value);
|
|
214
|
+
const root = object(value, "$");
|
|
215
|
+
exact(root, "$", allowed);
|
|
216
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
217
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
218
|
+
id(root.historyId, "$.historyId");
|
|
219
|
+
integer(root.expectedRevision, "$.expectedRevision");
|
|
220
|
+
integer(root.offset, "$.offset");
|
|
221
|
+
positive(root.limit, "$.limit");
|
|
222
|
+
if (root.limit > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
|
|
223
|
+
fail("$.limit", `maximum is ${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function snapshotBase(root: Record<string, unknown>): void {
|
|
227
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
228
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
229
|
+
id(root.historyId, "$.historyId");
|
|
230
|
+
integer(root.revision, "$.revision");
|
|
231
|
+
integer(root.offset, "$.offset");
|
|
232
|
+
}
|
|
233
|
+
function entryRecord(value: unknown, path: string): void {
|
|
234
|
+
const root = object(value, path);
|
|
235
|
+
exact(root, path, HISTORY_TREE_FIELDS.ForkEntryRecord);
|
|
236
|
+
id(root.entryId, `${path}.entryId`);
|
|
237
|
+
string(root.label, `${path}.label`);
|
|
238
|
+
optionalId(root.kindId, `${path}.kindId`);
|
|
239
|
+
optionalId(root.groupId, `${path}.groupId`);
|
|
240
|
+
optionalInteger(root.recordedAt, `${path}.recordedAt`);
|
|
241
|
+
integer(root.continuationCount, `${path}.continuationCount`);
|
|
242
|
+
positive(root.sequence, `${path}.sequence`);
|
|
243
|
+
integer(root.committedRevision, `${path}.committedRevision`);
|
|
244
|
+
integer(root.encodedWeight, `${path}.encodedWeight`);
|
|
245
|
+
oneOf(root.position, `${path}.position`, FORK_HISTORY_ENTRY_POSITIONS);
|
|
246
|
+
}
|
|
247
|
+
function noPayload(value: unknown): void {
|
|
248
|
+
const visit = (candidate: unknown, path: string): void => {
|
|
249
|
+
if (Array.isArray(candidate)) {
|
|
250
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
251
|
+
}
|
|
252
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
253
|
+
for (const [key, child] of Object.entries(candidate)) {
|
|
254
|
+
if (key.toLocaleLowerCase().includes("payload")) {
|
|
255
|
+
fail(`${path}.${key}`, "product payload field is forbidden");
|
|
256
|
+
}
|
|
257
|
+
visit(child, `${path}.${key}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
visit(value, "$");
|
|
262
|
+
}
|
|
263
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
264
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
268
|
+
if (!Array.isArray(value)) {
|
|
269
|
+
fail(path, "expected array");
|
|
270
|
+
}
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
function exact(
|
|
274
|
+
value: Record<string, unknown>,
|
|
275
|
+
path: string,
|
|
276
|
+
expected: ReadonlyArray<string>,
|
|
277
|
+
): void {
|
|
278
|
+
checkWireFields(value, expected, () =>
|
|
279
|
+
fail(path, `unexpected keys: ${Object.keys(value).sort().join(",")}`),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
function protocol(value: unknown, path: string): void {
|
|
283
|
+
if (value !== FORK_HISTORY_PROTOCOL_VERSION) {
|
|
284
|
+
fail(path, `expected exact protocol ${FORK_HISTORY_PROTOCOL_VERSION}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function integer(value: unknown, path: string): asserts value is number {
|
|
288
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
289
|
+
fail(path, "expected non-negative safe integer");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function positive(value: unknown, path: string): asserts value is number {
|
|
293
|
+
integer(value, path);
|
|
294
|
+
if (value === 0) {
|
|
295
|
+
fail(path, "expected positive integer");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
299
|
+
if (typeof value !== "string") {
|
|
300
|
+
fail(path, "expected string");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function id(value: unknown, path: string): void {
|
|
304
|
+
if (!isOpaqueId(value)) {
|
|
305
|
+
fail(path, "expected bounded lowercase opaque id");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function optionalId(value: unknown, path: string): void {
|
|
309
|
+
if (value !== null) {
|
|
310
|
+
id(value, path);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function optionalString(value: unknown, path: string): void {
|
|
314
|
+
if (value !== null) {
|
|
315
|
+
string(value, path);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function optionalInteger(value: unknown, path: string): void {
|
|
319
|
+
if (value !== null) {
|
|
320
|
+
integer(value, path);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function boolean(value: unknown, path: string): void {
|
|
324
|
+
if (typeof value !== "boolean") {
|
|
325
|
+
fail(path, "expected boolean");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
329
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
330
|
+
fail(path, "unsupported value");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function fail(path: string, message: string): never {
|
|
334
|
+
throw new ForkHistoryValidationError(path, message);
|
|
335
|
+
}
|
|
162
336
|
|
|
163
|
-
export function assertForkContinuationCommand(
|
|
337
|
+
export function assertForkContinuationCommand(
|
|
338
|
+
value: unknown,
|
|
339
|
+
): asserts value is ForkContinuationPageCommand {
|
|
164
340
|
commandBase(value, HISTORY_TREE_FIELDS.ForkContinuationPageCommand);
|
|
165
341
|
optionalId(object(value, "$").anchorEntryId, "$.anchorEntryId");
|
|
166
342
|
}
|
|
167
343
|
|
|
168
|
-
export function assertForkContinuationPage(
|
|
344
|
+
export function assertForkContinuationPage(
|
|
345
|
+
value: unknown,
|
|
346
|
+
): asserts value is ForkContinuationPageSnapshot {
|
|
169
347
|
noPayload(value);
|
|
170
348
|
const root = object(value, "$");
|
|
171
349
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkContinuationPageSnapshot);
|
|
@@ -194,7 +372,9 @@ export function assertForkContinuationPage(value: unknown): asserts value is For
|
|
|
194
372
|
* silently tolerated `offset` and `limit` would accept a caller who thought
|
|
195
373
|
* this was a paged read.
|
|
196
374
|
*/
|
|
197
|
-
export function assertForkDeleteCommand(
|
|
375
|
+
export function assertForkDeleteCommand(
|
|
376
|
+
value: unknown,
|
|
377
|
+
): asserts value is ForkDeleteContinuationCommand {
|
|
198
378
|
noPayload(value);
|
|
199
379
|
const root = object(value, "$");
|
|
200
380
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkDeleteContinuationCommand);
|
|
@@ -205,7 +385,9 @@ export function assertForkDeleteCommand(value: unknown): asserts value is ForkDe
|
|
|
205
385
|
id(root.entryId, "$.entryId");
|
|
206
386
|
}
|
|
207
387
|
|
|
208
|
-
export function assertForkRemovalReceipt(
|
|
388
|
+
export function assertForkRemovalReceipt(
|
|
389
|
+
value: unknown,
|
|
390
|
+
): asserts value is ForkRemovalReceiptProjection {
|
|
209
391
|
noPayload(value);
|
|
210
392
|
const root = object(value, "$");
|
|
211
393
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkRemovalReceiptProjection);
|
|
@@ -222,8 +404,12 @@ export function assertForkRemovalReceipt(value: unknown): asserts value is ForkR
|
|
|
222
404
|
positive(entry.sequence, `${at}.sequence`);
|
|
223
405
|
integer(entry.encodedWeight, `${at}.encodedWeight`);
|
|
224
406
|
});
|
|
225
|
-
array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
|
|
226
|
-
|
|
407
|
+
array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
|
|
408
|
+
id(branch, `$.removedBranches[${index}]`),
|
|
409
|
+
);
|
|
410
|
+
array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) =>
|
|
411
|
+
id(checkpoint, `$.removedCheckpoints[${index}]`),
|
|
412
|
+
);
|
|
227
413
|
integer(root.retainedEntryCount, "$.retainedEntryCount");
|
|
228
414
|
integer(root.retainedEncodedWeight, "$.retainedEncodedWeight");
|
|
229
415
|
integer(root.unprotectedEntryCount, "$.unprotectedEntryCount");
|
|
@@ -240,8 +426,28 @@ export function assertForkPruneCommand(value: unknown): asserts value is ForkPru
|
|
|
240
426
|
integer(root.expectedRevision, "$.expectedRevision");
|
|
241
427
|
// The budget bounds the unprotected share, and a zero budget is rejected by
|
|
242
428
|
// the authority rather than treated as "remove everything unprotected".
|
|
243
|
-
|
|
244
|
-
|
|
429
|
+
integer(root.maximumEntries, "$.maximumEntries");
|
|
430
|
+
integer(root.maximumEncodedWeight, "$.maximumEncodedWeight");
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function assertRetentionRejection(value: unknown): void {
|
|
434
|
+
const rejection = object(value, "$.rejection");
|
|
435
|
+
exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkRetentionRejectionProjection);
|
|
436
|
+
oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_RETENTION_REJECTION_CODES);
|
|
437
|
+
string(rejection.detail, "$.rejection.detail");
|
|
438
|
+
boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function assertForkDeleteResult(value: unknown): asserts value is ForkDeleteResult {
|
|
442
|
+
noPayload(value);
|
|
443
|
+
const root = object(value, "$");
|
|
444
|
+
oneOf(root.status, "$.status", FORK_HISTORY_DELETE_STATUSES);
|
|
445
|
+
exact(root, "$", variantFields("ForkDeleteResult", root, "$"));
|
|
446
|
+
if (root.status === "deleted") {
|
|
447
|
+
assertForkRemovalReceipt(root.receipt);
|
|
448
|
+
} else {
|
|
449
|
+
assertRetentionRejection(root.rejection);
|
|
450
|
+
}
|
|
245
451
|
}
|
|
246
452
|
|
|
247
453
|
export function assertForkPruneResult(value: unknown): asserts value is ForkPruneResult {
|
|
@@ -249,21 +455,23 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
|
|
|
249
455
|
const root = object(value, "$");
|
|
250
456
|
oneOf(root.status, "$.status", FORK_HISTORY_PRUNE_STATUSES);
|
|
251
457
|
exact(root, "$", variantFields("ForkPruneResult", root, "$"));
|
|
252
|
-
if (root.status === "pruned")
|
|
458
|
+
if (root.status === "pruned") {
|
|
459
|
+
assertForkRemovalReceipt(root.receipt);
|
|
460
|
+
} else if (root.status === "rejected") {
|
|
461
|
+
assertRetentionRejection(root.rejection);
|
|
462
|
+
}
|
|
253
463
|
}
|
|
254
464
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
268
|
-
return fields;
|
|
465
|
+
function variantFields(
|
|
466
|
+
type: string,
|
|
467
|
+
object: Record<string, unknown>,
|
|
468
|
+
path: string,
|
|
469
|
+
): ReadonlyArray<string> {
|
|
470
|
+
return wireVariantFields(
|
|
471
|
+
HISTORY_TREE_VARIANT_FIELDS,
|
|
472
|
+
HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
473
|
+
type,
|
|
474
|
+
object,
|
|
475
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
476
|
+
);
|
|
269
477
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority.
|
|
3
3
|
|
|
4
|
+
export const LAYOUT_RATIO_ONE_MILLIONTHS = 1000000 as const;
|
|
4
5
|
export const LAYOUT_PROTOCOL_VERSION = 1 as const;
|
|
5
6
|
export const LAYOUT_MUTATION_COMMAND_KINDS = ["create_panel","close_panel","activate_panel","reorder_region","move_panel","set_sizing_slot","set_region_collapsed"] as const;
|
|
6
7
|
export const LAYOUT_MUTATION_OUTCOME_KINDS = ["panel_created","panel_closed","panel_activated","region_reordered","panel_moved","sizing_slot_set","region_collapsed_set"] as const;
|
|
@@ -26,7 +27,7 @@ export type SurfaceRevision = number;
|
|
|
26
27
|
|
|
27
28
|
export type LayoutRatio = number;
|
|
28
29
|
|
|
29
|
-
export type
|
|
30
|
+
export type SurfaceLimits = { maximum_schemas: number, maximum_regions_per_schema: number, maximum_sizing_slots_per_schema: number, maximum_panel_definitions: number, maximum_surfaces: number, maximum_windows: number, maximum_host_preferences_per_surface: number, maximum_label_bytes: number, maximum_panel_instances: number, maximum_panel_instances_per_region: number, };
|
|
30
31
|
|
|
31
32
|
export type EmptyRegionPolicy = "keep_visible" | "hide_when_empty";
|
|
32
33
|
|
|
@@ -38,7 +39,7 @@ export type LayoutSchemaDefinition = { id: LayoutSchemaId, regions: Array<Region
|
|
|
38
39
|
|
|
39
40
|
export type PlacementSelector = { "kind": "region", "id": RegionId } | { "kind": "family", "id": RegionFamilyId };
|
|
40
41
|
|
|
41
|
-
export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "
|
|
42
|
+
export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_surface" } | { "kind": "bounded",
|
|
42
43
|
/**
|
|
43
44
|
* Maximum instances in the complete document.
|
|
44
45
|
*/
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
|
+
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
|
+
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
|
+
// each list, because `exact()` compares every key.
|
|
5
|
+
|
|
6
|
+
export const LAYOUT_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"PlacementSelector": {
|
|
8
|
+
"region": ["kind", "id"],
|
|
9
|
+
"family": ["kind", "id"],
|
|
10
|
+
},
|
|
11
|
+
"PanelInstancePolicy": {
|
|
12
|
+
"singleton": ["kind"],
|
|
13
|
+
"one_per_surface": ["kind"],
|
|
14
|
+
"bounded": ["kind", "maximum_per_document", "maximum_per_surface"],
|
|
15
|
+
"multiple": ["kind"],
|
|
16
|
+
},
|
|
17
|
+
"SurfacePresentation": {
|
|
18
|
+
"regional": ["kind"],
|
|
19
|
+
"focused_panel": ["kind", "panel_definition_id"],
|
|
20
|
+
},
|
|
21
|
+
"LayoutMutationCommand": {
|
|
22
|
+
"create_panel": ["kind", "panel_instance_id", "panel_definition_id", "surface_id", "region_id", "insertion_index"],
|
|
23
|
+
"close_panel": ["kind", "panel_instance_id"],
|
|
24
|
+
"activate_panel": ["kind", "panel_instance_id"],
|
|
25
|
+
"reorder_region": ["kind", "surface_id", "region_id", "panel_instance_ids"],
|
|
26
|
+
"move_panel": ["kind", "panel_instance_id", "target_surface_id", "target_region_id", "insertion_index"],
|
|
27
|
+
"set_sizing_slot": ["kind", "surface_id", "sizing_slot_id", "ratio"],
|
|
28
|
+
"set_region_collapsed": ["kind", "surface_id", "region_id", "collapsed"],
|
|
29
|
+
},
|
|
30
|
+
"LayoutMutationOutcome": {
|
|
31
|
+
"panel_created": ["kind", "panel_instance_id", "surface_id", "region_id", "insertion_index"],
|
|
32
|
+
"panel_closed": ["kind", "panel_instance_id", "surface_id", "region_id", "former_index"],
|
|
33
|
+
"panel_activated": ["kind", "panel_instance_id", "surface_id", "region_id", "previous_active_panel_instance_id"],
|
|
34
|
+
"region_reordered": ["kind", "surface_id", "region_id", "panel_instance_ids"],
|
|
35
|
+
"panel_moved": ["kind", "panel_instance_id", "source_surface_id", "source_region_id", "former_index", "target_surface_id", "target_region_id", "insertion_index"],
|
|
36
|
+
"sizing_slot_set": ["kind", "surface_id", "sizing_slot_id", "previous_ratio", "committed_ratio"],
|
|
37
|
+
"region_collapsed_set": ["kind", "surface_id", "region_id", "previous_collapsed", "committed_collapsed"],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const LAYOUT_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
42
|
+
"PlacementSelector": "kind",
|
|
43
|
+
"PanelInstancePolicy": "kind",
|
|
44
|
+
"SurfacePresentation": "kind",
|
|
45
|
+
"LayoutMutationCommand": "kind",
|
|
46
|
+
"LayoutMutationOutcome": "kind",
|
|
47
|
+
};
|
package/src/layout/index.ts
CHANGED
package/src/layout/ratio.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { LAYOUT_RATIO_ONE_MILLIONTHS } from "./generated/protocol.ts";
|
|
1
2
|
import type { LayoutRatio } from "./generated/protocol.ts";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export function isLayoutRatio(value: unknown): value is LayoutRatio {
|
|
5
|
+
return typeof value === "number" && ratioInRange(value);
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
export function layoutRatioFromMillionths(value: number): LayoutRatio {
|
|
6
|
-
if (
|
|
7
|
-
!Number.isSafeInteger(value) ||
|
|
8
|
-
value < 0 ||
|
|
9
|
-
value > LAYOUT_RATIO_ONE_MILLIONTHS
|
|
10
|
-
) {
|
|
9
|
+
if (!ratioInRange(value)) {
|
|
11
10
|
throw new RangeError(
|
|
12
11
|
`layout ratio must be an integer from 0 through ${LAYOUT_RATIO_ONE_MILLIONTHS}; received ${String(value)}`,
|
|
13
12
|
);
|
|
@@ -16,7 +15,9 @@ export function layoutRatioFromMillionths(value: number): LayoutRatio {
|
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function layoutRatioToUnitInterval(value: LayoutRatio): number {
|
|
19
|
-
return (
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
return layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function ratioInRange(value: number): boolean {
|
|
22
|
+
return Number.isSafeInteger(value) && value >= 0 && value <= LAYOUT_RATIO_ONE_MILLIONTHS;
|
|
22
23
|
}
|