@inflatable-cookie/longhorn 0.4.3 → 0.6.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/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- 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 +77 -105
- 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 +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
2
|
+
import {
|
|
3
|
+
HISTORY_TREE_VARIANT_FIELDS,
|
|
4
|
+
HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
5
|
+
} from "./generated/variant-fields.ts";
|
|
2
6
|
import {
|
|
3
7
|
FORK_HISTORY_CHANGED_KINDS,
|
|
4
8
|
FORK_HISTORY_ENTRY_POSITIONS,
|
|
@@ -10,25 +14,30 @@ import {
|
|
|
10
14
|
FORK_HISTORY_PRUNE_STATUSES,
|
|
11
15
|
FORK_HISTORY_PROTOCOL_VERSION,
|
|
12
16
|
MAXIMUM_FORK_HISTORY_PAGE_SIZE,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
} from "./generated/protocol.ts";
|
|
18
|
+
import type {
|
|
19
|
+
ForkBranchPageCommand,
|
|
20
|
+
ForkBranchPageSnapshot,
|
|
21
|
+
ForkContinuationPageCommand,
|
|
22
|
+
ForkContinuationPageSnapshot,
|
|
23
|
+
ForkDeleteContinuationCommand,
|
|
24
|
+
ForkPruneCommand,
|
|
25
|
+
ForkPruneResult,
|
|
26
|
+
ForkRemovalReceiptProjection,
|
|
27
|
+
ForkChangedEvent,
|
|
28
|
+
ForkNavigationCommand,
|
|
29
|
+
ForkNavigationResult,
|
|
30
|
+
ForkPathPageCommand,
|
|
31
|
+
ForkPathPageSnapshot,
|
|
32
|
+
ForkSnapshot,
|
|
27
33
|
} from "./generated/protocol.ts";
|
|
28
34
|
import { HISTORY_TREE_FIELDS } from "./generated/fields.ts";
|
|
29
35
|
|
|
30
36
|
export class ForkHistoryValidationError extends Error {
|
|
31
|
-
constructor(
|
|
37
|
+
constructor(
|
|
38
|
+
readonly path: string,
|
|
39
|
+
message: string,
|
|
40
|
+
) {
|
|
32
41
|
super(`${path}: ${message}`);
|
|
33
42
|
this.name = "ForkHistoryValidationError";
|
|
34
43
|
}
|
|
@@ -46,7 +55,16 @@ export function assertForkSnapshot(value: unknown): asserts value is ForkSnapsho
|
|
|
46
55
|
integer(summary.revision, "$.summary.revision");
|
|
47
56
|
id(summary.currentBranchId, "$.summary.currentBranchId");
|
|
48
57
|
optionalId(summary.currentEntryId, "$.summary.currentEntryId");
|
|
49
|
-
for (const key of [
|
|
58
|
+
for (const key of [
|
|
59
|
+
"undoDepth",
|
|
60
|
+
"redoDepth",
|
|
61
|
+
"retainedEntryCount",
|
|
62
|
+
"retainedEncodedWeight",
|
|
63
|
+
"branchCount",
|
|
64
|
+
"alternatePathCount",
|
|
65
|
+
] as const) {
|
|
66
|
+
integer(summary[key], `$.summary.${key}`);
|
|
67
|
+
}
|
|
50
68
|
optionalString(summary.nextUndoLabel, "$.summary.nextUndoLabel");
|
|
51
69
|
optionalString(summary.nextRedoLabel, "$.summary.nextRedoLabel");
|
|
52
70
|
}
|
|
@@ -56,8 +74,12 @@ export function assertForkPathCommand(value: unknown): asserts value is ForkPath
|
|
|
56
74
|
const target = object(object(value, "$").target, "$.target");
|
|
57
75
|
oneOf(target.kind, "$.target.kind", FORK_HISTORY_PATH_TARGETS);
|
|
58
76
|
exact(target, "$.target", variantFields("ForkPathTargetProjection", target, "$.target"));
|
|
59
|
-
if (target.kind === "branch")
|
|
60
|
-
|
|
77
|
+
if (target.kind === "branch") {
|
|
78
|
+
id(target.branchId, "$.target.branchId");
|
|
79
|
+
}
|
|
80
|
+
if (target.kind === "continuation") {
|
|
81
|
+
id(target.fromEntryId, "$.target.fromEntryId");
|
|
82
|
+
}
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
export function assertForkBranchCommand(value: unknown): asserts value is ForkBranchPageCommand {
|
|
@@ -77,9 +99,13 @@ export function assertForkPathPage(value: unknown): asserts value is ForkPathPag
|
|
|
77
99
|
const floor = object(root.floor, "$.floor");
|
|
78
100
|
oneOf(floor.kind, "$.floor.kind", FORK_HISTORY_PATH_FLOORS);
|
|
79
101
|
exact(floor, "$.floor", variantFields("ForkPathFloorProjection", floor, "$.floor"));
|
|
80
|
-
if (floor.kind === "anchor")
|
|
102
|
+
if (floor.kind === "anchor") {
|
|
103
|
+
id(floor.entryId, "$.floor.entryId");
|
|
104
|
+
}
|
|
81
105
|
integer(root.totalEntries, "$.totalEntries");
|
|
82
|
-
array(root.entries, "$.entries").forEach((entry, index) =>
|
|
106
|
+
array(root.entries, "$.entries").forEach((entry, index) =>
|
|
107
|
+
entryRecord(entry, `$.entries[${index}]`),
|
|
108
|
+
);
|
|
83
109
|
boolean(root.truncatedBefore, "$.truncatedBefore");
|
|
84
110
|
boolean(root.truncatedAfter, "$.truncatedAfter");
|
|
85
111
|
}
|
|
@@ -106,66 +132,220 @@ export function assertForkBranchPage(value: unknown): asserts value is ForkBranc
|
|
|
106
132
|
boolean(root.truncatedAfter, "$.truncatedAfter");
|
|
107
133
|
}
|
|
108
134
|
|
|
109
|
-
export function assertForkNavigationCommand(
|
|
135
|
+
export function assertForkNavigationCommand(
|
|
136
|
+
value: unknown,
|
|
137
|
+
): asserts value is ForkNavigationCommand {
|
|
110
138
|
noPayload(value);
|
|
111
139
|
const root = object(value, "$");
|
|
112
140
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkNavigationCommand);
|
|
113
|
-
protocol(root.protocolVersion, "$.protocolVersion");
|
|
114
|
-
|
|
141
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
142
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
143
|
+
id(root.historyId, "$.historyId");
|
|
144
|
+
id(root.planId, "$.planId");
|
|
145
|
+
integer(root.expectedRevision, "$.expectedRevision");
|
|
146
|
+
const target = object(root.target, "$.target");
|
|
147
|
+
oneOf(target.kind, "$.target.kind", FORK_HISTORY_NAVIGATION_TARGETS);
|
|
115
148
|
exact(target, "$.target", variantFields("ForkNavigationTargetProjection", target, "$.target"));
|
|
116
|
-
if (target.kind === "checkout") {
|
|
117
|
-
|
|
118
|
-
|
|
149
|
+
if (target.kind === "checkout") {
|
|
150
|
+
id(target.branchId, "$.target.branchId");
|
|
151
|
+
id(target.entryId, "$.target.entryId");
|
|
152
|
+
}
|
|
153
|
+
if (target.kind === "checkoutBranchRoot") {
|
|
154
|
+
id(target.branchId, "$.target.branchId");
|
|
155
|
+
}
|
|
156
|
+
if (target.kind === "checkoutContinuation") {
|
|
157
|
+
id(target.entryId, "$.target.entryId");
|
|
158
|
+
}
|
|
119
159
|
}
|
|
120
160
|
|
|
121
161
|
export function assertForkNavigationResult(value: unknown): asserts value is ForkNavigationResult {
|
|
122
162
|
noPayload(value);
|
|
123
|
-
const root = object(value, "$");
|
|
124
|
-
|
|
163
|
+
const root = object(value, "$");
|
|
164
|
+
oneOf(root.status, "$.status", FORK_HISTORY_NAVIGATION_STATUSES);
|
|
165
|
+
exact(
|
|
166
|
+
root,
|
|
167
|
+
"$",
|
|
168
|
+
root.status === "committed"
|
|
169
|
+
? ["status", "snapshot", "receipt"]
|
|
170
|
+
: ["status", "snapshot", "rejection"],
|
|
171
|
+
);
|
|
125
172
|
assertForkSnapshot(root.snapshot);
|
|
126
173
|
if (root.status === "committed") {
|
|
127
174
|
const receipt = object(root.receipt, "$.receipt");
|
|
128
175
|
exact(receipt, "$.receipt", HISTORY_TREE_FIELDS.ForkNavigationReceiptProjection);
|
|
129
|
-
id(receipt.historyId, "$.receipt.historyId");
|
|
176
|
+
id(receipt.historyId, "$.receipt.historyId");
|
|
177
|
+
id(receipt.planId, "$.receipt.planId");
|
|
178
|
+
integer(receipt.previousRevision, "$.receipt.previousRevision");
|
|
179
|
+
integer(receipt.committedRevision, "$.receipt.committedRevision");
|
|
180
|
+
optionalId(receipt.sourceEntryId, "$.receipt.sourceEntryId");
|
|
181
|
+
optionalId(receipt.targetEntryId, "$.receipt.targetEntryId");
|
|
182
|
+
id(receipt.targetBranchId, "$.receipt.targetBranchId");
|
|
183
|
+
array(receipt.movedEntryIds, "$.receipt.movedEntryIds").forEach((entry, index) =>
|
|
184
|
+
id(entry, `$.receipt.movedEntryIds[${index}]`),
|
|
185
|
+
);
|
|
130
186
|
} else {
|
|
131
187
|
const rejection = object(root.rejection, "$.rejection");
|
|
132
|
-
exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
|
|
188
|
+
exact(rejection, "$.rejection", HISTORY_TREE_FIELDS.ForkNavigationRejectionProjection);
|
|
189
|
+
oneOf(rejection.code, "$.rejection.code", FORK_HISTORY_NAVIGATION_REJECTION_CODES);
|
|
190
|
+
string(rejection.detail, "$.rejection.detail");
|
|
191
|
+
boolean(rejection.refreshRequired, "$.rejection.refreshRequired");
|
|
133
192
|
}
|
|
134
193
|
}
|
|
135
194
|
|
|
136
195
|
export function assertForkChangedEvent(value: unknown): asserts value is ForkChangedEvent {
|
|
137
|
-
noPayload(value);
|
|
196
|
+
noPayload(value);
|
|
197
|
+
const root = object(value, "$");
|
|
138
198
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkChangedEvent);
|
|
139
|
-
protocol(root.protocolVersion, "$.protocolVersion");
|
|
140
|
-
|
|
141
|
-
|
|
199
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
200
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
201
|
+
id(root.historyId, "$.historyId");
|
|
202
|
+
if (root.previousRevision !== null) {
|
|
203
|
+
integer(root.previousRevision, "$.previousRevision");
|
|
204
|
+
}
|
|
205
|
+
integer(root.committedRevision, "$.committedRevision");
|
|
206
|
+
oneOf(root.kind, "$.kind", FORK_HISTORY_CHANGED_KINDS);
|
|
142
207
|
}
|
|
143
208
|
|
|
144
|
-
function commandBase(value: unknown, allowed:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
209
|
+
function commandBase(value: unknown, allowed: ReadonlyArray<string>): void {
|
|
210
|
+
noPayload(value);
|
|
211
|
+
const root = object(value, "$");
|
|
212
|
+
exact(root, "$", allowed);
|
|
213
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
214
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
215
|
+
id(root.historyId, "$.historyId");
|
|
216
|
+
integer(root.expectedRevision, "$.expectedRevision");
|
|
217
|
+
integer(root.offset, "$.offset");
|
|
218
|
+
positive(root.limit, "$.limit");
|
|
219
|
+
if (root.limit > MAXIMUM_FORK_HISTORY_PAGE_SIZE) {
|
|
220
|
+
fail("$.limit", `maximum is ${MAXIMUM_FORK_HISTORY_PAGE_SIZE}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function snapshotBase(root: Record<string, unknown>): void {
|
|
224
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
225
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
226
|
+
id(root.historyId, "$.historyId");
|
|
227
|
+
integer(root.revision, "$.revision");
|
|
228
|
+
integer(root.offset, "$.offset");
|
|
229
|
+
}
|
|
230
|
+
function entryRecord(value: unknown, path: string): void {
|
|
231
|
+
const root = object(value, path);
|
|
232
|
+
exact(root, path, HISTORY_TREE_FIELDS.ForkEntryRecord);
|
|
233
|
+
id(root.entryId, `${path}.entryId`);
|
|
234
|
+
string(root.label, `${path}.label`);
|
|
235
|
+
optionalId(root.kindId, `${path}.kindId`);
|
|
236
|
+
optionalId(root.groupId, `${path}.groupId`);
|
|
237
|
+
optionalInteger(root.recordedAt, `${path}.recordedAt`);
|
|
238
|
+
integer(root.continuationCount, `${path}.continuationCount`);
|
|
239
|
+
positive(root.sequence, `${path}.sequence`);
|
|
240
|
+
integer(root.committedRevision, `${path}.committedRevision`);
|
|
241
|
+
integer(root.encodedWeight, `${path}.encodedWeight`);
|
|
242
|
+
oneOf(root.position, `${path}.position`, FORK_HISTORY_ENTRY_POSITIONS);
|
|
243
|
+
}
|
|
244
|
+
function noPayload(value: unknown): void {
|
|
245
|
+
const visit = (candidate: unknown, path: string): void => {
|
|
246
|
+
if (Array.isArray(candidate)) {
|
|
247
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
248
|
+
}
|
|
249
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
250
|
+
for (const [key, child] of Object.entries(candidate)) {
|
|
251
|
+
if (key.toLocaleLowerCase().includes("payload")) {
|
|
252
|
+
fail(`${path}.${key}`, "product payload field is forbidden");
|
|
253
|
+
}
|
|
254
|
+
visit(child, `${path}.${key}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
visit(value, "$");
|
|
259
|
+
}
|
|
260
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
261
|
+
if (!isRecord(value)) {
|
|
262
|
+
fail(path, "expected object");
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
267
|
+
if (!Array.isArray(value)) {
|
|
268
|
+
fail(path, "expected array");
|
|
269
|
+
}
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
function exact(
|
|
273
|
+
value: Record<string, unknown>,
|
|
274
|
+
path: string,
|
|
275
|
+
expected: ReadonlyArray<string>,
|
|
276
|
+
): void {
|
|
277
|
+
const actual = Object.keys(value).sort();
|
|
278
|
+
const wanted = [...expected].sort();
|
|
279
|
+
if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
|
|
280
|
+
fail(path, `unexpected keys: ${actual.join(",")}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function protocol(value: unknown, path: string): void {
|
|
284
|
+
if (value !== FORK_HISTORY_PROTOCOL_VERSION) {
|
|
285
|
+
fail(path, `expected exact protocol ${FORK_HISTORY_PROTOCOL_VERSION}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function integer(value: unknown, path: string): asserts value is number {
|
|
289
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
290
|
+
fail(path, "expected non-negative safe integer");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function positive(value: unknown, path: string): asserts value is number {
|
|
294
|
+
integer(value, path);
|
|
295
|
+
if (value === 0) {
|
|
296
|
+
fail(path, "expected positive integer");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
300
|
+
if (typeof value !== "string") {
|
|
301
|
+
fail(path, "expected string");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function id(value: unknown, path: string): void {
|
|
305
|
+
string(value, path);
|
|
306
|
+
if (value.length === 0) {
|
|
307
|
+
fail(path, "expected non-empty id");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function optionalId(value: unknown, path: string): void {
|
|
311
|
+
if (value !== null) {
|
|
312
|
+
id(value, path);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function optionalString(value: unknown, path: string): void {
|
|
316
|
+
if (value !== null) {
|
|
317
|
+
string(value, path);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function optionalInteger(value: unknown, path: string): void {
|
|
321
|
+
if (value !== null) {
|
|
322
|
+
integer(value, path);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function boolean(value: unknown, path: string): void {
|
|
326
|
+
if (typeof value !== "boolean") {
|
|
327
|
+
fail(path, "expected boolean");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
331
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
332
|
+
fail(path, "unsupported value");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function fail(path: string, message: string): never {
|
|
336
|
+
throw new ForkHistoryValidationError(path, message);
|
|
337
|
+
}
|
|
162
338
|
|
|
163
|
-
export function assertForkContinuationCommand(
|
|
339
|
+
export function assertForkContinuationCommand(
|
|
340
|
+
value: unknown,
|
|
341
|
+
): asserts value is ForkContinuationPageCommand {
|
|
164
342
|
commandBase(value, HISTORY_TREE_FIELDS.ForkContinuationPageCommand);
|
|
165
343
|
optionalId(object(value, "$").anchorEntryId, "$.anchorEntryId");
|
|
166
344
|
}
|
|
167
345
|
|
|
168
|
-
export function assertForkContinuationPage(
|
|
346
|
+
export function assertForkContinuationPage(
|
|
347
|
+
value: unknown,
|
|
348
|
+
): asserts value is ForkContinuationPageSnapshot {
|
|
169
349
|
noPayload(value);
|
|
170
350
|
const root = object(value, "$");
|
|
171
351
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkContinuationPageSnapshot);
|
|
@@ -194,7 +374,9 @@ export function assertForkContinuationPage(value: unknown): asserts value is For
|
|
|
194
374
|
* silently tolerated `offset` and `limit` would accept a caller who thought
|
|
195
375
|
* this was a paged read.
|
|
196
376
|
*/
|
|
197
|
-
export function assertForkDeleteCommand(
|
|
377
|
+
export function assertForkDeleteCommand(
|
|
378
|
+
value: unknown,
|
|
379
|
+
): asserts value is ForkDeleteContinuationCommand {
|
|
198
380
|
noPayload(value);
|
|
199
381
|
const root = object(value, "$");
|
|
200
382
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkDeleteContinuationCommand);
|
|
@@ -205,7 +387,9 @@ export function assertForkDeleteCommand(value: unknown): asserts value is ForkDe
|
|
|
205
387
|
id(root.entryId, "$.entryId");
|
|
206
388
|
}
|
|
207
389
|
|
|
208
|
-
export function assertForkRemovalReceipt(
|
|
390
|
+
export function assertForkRemovalReceipt(
|
|
391
|
+
value: unknown,
|
|
392
|
+
): asserts value is ForkRemovalReceiptProjection {
|
|
209
393
|
noPayload(value);
|
|
210
394
|
const root = object(value, "$");
|
|
211
395
|
exact(root, "$", HISTORY_TREE_FIELDS.ForkRemovalReceiptProjection);
|
|
@@ -222,8 +406,12 @@ export function assertForkRemovalReceipt(value: unknown): asserts value is ForkR
|
|
|
222
406
|
positive(entry.sequence, `${at}.sequence`);
|
|
223
407
|
integer(entry.encodedWeight, `${at}.encodedWeight`);
|
|
224
408
|
});
|
|
225
|
-
array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
|
|
226
|
-
|
|
409
|
+
array(root.removedBranches, "$.removedBranches").forEach((branch, index) =>
|
|
410
|
+
id(branch, `$.removedBranches[${index}]`),
|
|
411
|
+
);
|
|
412
|
+
array(root.removedCheckpoints, "$.removedCheckpoints").forEach((checkpoint, index) =>
|
|
413
|
+
id(checkpoint, `$.removedCheckpoints[${index}]`),
|
|
414
|
+
);
|
|
227
415
|
integer(root.retainedEntryCount, "$.retainedEntryCount");
|
|
228
416
|
integer(root.retainedEncodedWeight, "$.retainedEncodedWeight");
|
|
229
417
|
integer(root.unprotectedEntryCount, "$.unprotectedEntryCount");
|
|
@@ -249,7 +437,9 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
|
|
|
249
437
|
const root = object(value, "$");
|
|
250
438
|
oneOf(root.status, "$.status", FORK_HISTORY_PRUNE_STATUSES);
|
|
251
439
|
exact(root, "$", variantFields("ForkPruneResult", root, "$"));
|
|
252
|
-
if (root.status === "pruned")
|
|
440
|
+
if (root.status === "pruned") {
|
|
441
|
+
assertForkRemovalReceipt(root.receipt);
|
|
442
|
+
}
|
|
253
443
|
}
|
|
254
444
|
|
|
255
445
|
/**
|
|
@@ -261,9 +451,18 @@ export function assertForkPruneResult(value: unknown): asserts value is ForkPrun
|
|
|
261
451
|
* loudly beats defaulting to a key list, which is how `checkoutBranchRoot`
|
|
262
452
|
* shipped rejecting its own `branchId`.
|
|
263
453
|
*/
|
|
264
|
-
function variantFields(
|
|
454
|
+
function variantFields(
|
|
455
|
+
type: string,
|
|
456
|
+
object: Record<string, unknown>,
|
|
457
|
+
path: string,
|
|
458
|
+
): ReadonlyArray<string> {
|
|
265
459
|
const discriminant = object[HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
266
|
-
const fields =
|
|
267
|
-
|
|
460
|
+
const fields =
|
|
461
|
+
typeof discriminant === "string"
|
|
462
|
+
? HISTORY_TREE_VARIANT_FIELDS[type]?.[discriminant]
|
|
463
|
+
: undefined;
|
|
464
|
+
if (fields === undefined) {
|
|
465
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
466
|
+
}
|
|
268
467
|
return fields;
|
|
269
468
|
}
|
|
@@ -26,7 +26,7 @@ export type SurfaceRevision = number;
|
|
|
26
26
|
|
|
27
27
|
export type LayoutRatio = number;
|
|
28
28
|
|
|
29
|
-
export type
|
|
29
|
+
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
30
|
|
|
31
31
|
export type EmptyRegionPolicy = "keep_visible" | "hide_when_empty";
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ export type LayoutSchemaDefinition = { id: LayoutSchemaId, regions: Array<Region
|
|
|
38
38
|
|
|
39
39
|
export type PlacementSelector = { "kind": "region", "id": RegionId } | { "kind": "family", "id": RegionFamilyId };
|
|
40
40
|
|
|
41
|
-
export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "
|
|
41
|
+
export type PanelInstancePolicy = { "kind": "singleton" } | { "kind": "one_per_surface" } | { "kind": "bounded",
|
|
42
42
|
/**
|
|
43
43
|
* Maximum instances in the complete document.
|
|
44
44
|
*/
|
package/src/layout/ratio.ts
CHANGED
|
@@ -3,11 +3,7 @@ import type { LayoutRatio } from "./generated/protocol.ts";
|
|
|
3
3
|
export const LAYOUT_RATIO_ONE_MILLIONTHS = 1_000_000;
|
|
4
4
|
|
|
5
5
|
export function layoutRatioFromMillionths(value: number): LayoutRatio {
|
|
6
|
-
if (
|
|
7
|
-
!Number.isSafeInteger(value) ||
|
|
8
|
-
value < 0 ||
|
|
9
|
-
value > LAYOUT_RATIO_ONE_MILLIONTHS
|
|
10
|
-
) {
|
|
6
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > LAYOUT_RATIO_ONE_MILLIONTHS) {
|
|
11
7
|
throw new RangeError(
|
|
12
8
|
`layout ratio must be an integer from 0 through ${LAYOUT_RATIO_ONE_MILLIONTHS}; received ${String(value)}`,
|
|
13
9
|
);
|
|
@@ -16,7 +12,5 @@ export function layoutRatioFromMillionths(value: number): LayoutRatio {
|
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
export function layoutRatioToUnitInterval(value: LayoutRatio): number {
|
|
19
|
-
return (
|
|
20
|
-
layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS
|
|
21
|
-
);
|
|
15
|
+
return layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS;
|
|
22
16
|
}
|
package/src/layout/validation.ts
CHANGED
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
LAYOUT_MUTATION_OUTCOME_KINDS,
|
|
4
4
|
LAYOUT_MUTATION_REJECTION_CODES,
|
|
5
5
|
LAYOUT_PROTOCOL_VERSION,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
} from "./generated/protocol.ts";
|
|
7
|
+
import type {
|
|
8
|
+
LayoutMutationCommand,
|
|
9
|
+
LayoutMutationOutcome,
|
|
10
|
+
LayoutMutationRejectionCode,
|
|
9
11
|
} from "./generated/protocol.ts";
|
|
10
12
|
|
|
11
13
|
export type LayoutProtocolValidationCode =
|
|
@@ -30,10 +32,7 @@ export function assertLayoutProtocolVersion(
|
|
|
30
32
|
version: unknown,
|
|
31
33
|
): asserts version is typeof LAYOUT_PROTOCOL_VERSION {
|
|
32
34
|
if (version !== LAYOUT_PROTOCOL_VERSION) {
|
|
33
|
-
throw new LayoutProtocolValidationError(
|
|
34
|
-
"unsupported_protocol_version",
|
|
35
|
-
version,
|
|
36
|
-
);
|
|
35
|
+
throw new LayoutProtocolValidationError("unsupported_protocol_version", version);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -54,20 +53,15 @@ export function assertValidLayoutMutationRejectionCode(
|
|
|
54
53
|
): asserts value is LayoutMutationRejectionCode {
|
|
55
54
|
if (
|
|
56
55
|
typeof value !== "string" ||
|
|
57
|
-
!LAYOUT_MUTATION_REJECTION_CODES.
|
|
58
|
-
value as (typeof LAYOUT_MUTATION_REJECTION_CODES)[number],
|
|
59
|
-
)
|
|
56
|
+
!LAYOUT_MUTATION_REJECTION_CODES.some((code) => code === value)
|
|
60
57
|
) {
|
|
61
|
-
throw new LayoutProtocolValidationError(
|
|
62
|
-
"unknown_rejection_code",
|
|
63
|
-
value,
|
|
64
|
-
);
|
|
58
|
+
throw new LayoutProtocolValidationError("unknown_rejection_code", value);
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
function assertKnownKind(
|
|
69
63
|
value: unknown,
|
|
70
|
-
known:
|
|
64
|
+
known: ReadonlyArray<string>,
|
|
71
65
|
code: "unknown_command" | "unknown_outcome",
|
|
72
66
|
): asserts value is Record<"kind", string> {
|
|
73
67
|
if (
|
|
@@ -81,10 +75,7 @@ function assertKnownKind(
|
|
|
81
75
|
}
|
|
82
76
|
}
|
|
83
77
|
|
|
84
|
-
function message(
|
|
85
|
-
code: LayoutProtocolValidationCode,
|
|
86
|
-
received: unknown,
|
|
87
|
-
): string {
|
|
78
|
+
function message(code: LayoutProtocolValidationCode, received: unknown): string {
|
|
88
79
|
switch (code) {
|
|
89
80
|
case "unsupported_protocol_version":
|
|
90
81
|
return `unsupported layout protocol version ${String(received)}; expected ${LAYOUT_PROTOCOL_VERSION}`;
|
package/src/layout/visibility.ts
CHANGED
|
@@ -18,8 +18,7 @@ export function projectOrdinaryRegionVisibility(
|
|
|
18
18
|
return {
|
|
19
19
|
region_id: definition.id,
|
|
20
20
|
state:
|
|
21
|
-
state.panel_instance_ids.length > 0 ||
|
|
22
|
-
definition.empty_policy === "keep_visible"
|
|
21
|
+
state.panel_instance_ids.length > 0 || definition.empty_policy === "keep_visible"
|
|
23
22
|
? "visible"
|
|
24
23
|
: "hidden",
|
|
25
24
|
};
|
package/src/licence/client.ts
CHANGED
|
@@ -22,11 +22,48 @@ import {
|
|
|
22
22
|
|
|
23
23
|
export class LicenceClient implements CheckedLicencePort {
|
|
24
24
|
constructor(readonly port: LicencePort) {}
|
|
25
|
-
async snapshot(): Promise<LicenceSnapshot> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async
|
|
31
|
-
|
|
25
|
+
async snapshot(): Promise<LicenceSnapshot> {
|
|
26
|
+
const value = await this.port.snapshot();
|
|
27
|
+
assertLicenceSnapshot(value);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
async activate(command: LicenceActivateCommand): Promise<LicenceOutcomeProjection> {
|
|
31
|
+
assertLicenceActivateCommand(command);
|
|
32
|
+
const value = await this.port.activate(command);
|
|
33
|
+
assertLicenceOutcome(value);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
async deactivate(command: LicenceDeactivateCommand): Promise<LicenceOutcomeProjection> {
|
|
37
|
+
assertLicenceDeactivateCommand(command);
|
|
38
|
+
const value = await this.port.deactivate(command);
|
|
39
|
+
assertLicenceOutcome(value);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
async refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection> {
|
|
43
|
+
assertLicenceRefreshCommand(command);
|
|
44
|
+
const value = await this.port.refresh(command);
|
|
45
|
+
assertLicenceOutcome(value);
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
async releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection> {
|
|
49
|
+
assertLicenceReleaseSeatCommand(command);
|
|
50
|
+
const value = await this.port.releaseSeat(command);
|
|
51
|
+
assertLicenceOutcome(value);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
async renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection> {
|
|
55
|
+
assertLicenceRenameSeatCommand(command);
|
|
56
|
+
const value = await this.port.renameSeat(command);
|
|
57
|
+
assertLicenceOutcome(value);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
async listen(listener: (event: LicenceChangedEvent) => void): Promise<LicenceUnlisten> {
|
|
61
|
+
if (this.port.listen === undefined) {
|
|
62
|
+
return () => {};
|
|
63
|
+
}
|
|
64
|
+
return this.port.listen((value) => {
|
|
65
|
+
assertLicenceChangedEvent(value);
|
|
66
|
+
listener(value);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
32
69
|
}
|