@inflatable-cookie/longhorn 0.6.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.
Files changed (133) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -7
  3. package/src/agent-control/generated/protocol.ts +228 -0
  4. package/src/agent-control/index.ts +1 -5
  5. package/src/agent-control/selection.ts +10 -8
  6. package/src/agent-control/shim.ts +149 -77
  7. package/src/bridge/generated/fields.ts +1 -1
  8. package/src/bridge/generated/protocol.ts +55 -4
  9. package/src/bridge/generated/variant-fields.ts +1 -1
  10. package/src/bridge/job.ts +49 -2
  11. package/src/bridge/runtime/connection.ts +11 -14
  12. package/src/bridge/stream/connection.ts +14 -23
  13. package/src/bridge/stream/tracker.ts +5 -0
  14. package/src/bridge/supervision.ts +102 -80
  15. package/src/bridge/validation/base.ts +7 -27
  16. package/src/bridge/validation/negotiation.ts +1 -6
  17. package/src/bridge/validation/operations.ts +2 -14
  18. package/src/commands/client.ts +16 -2
  19. package/src/commands/controller.ts +96 -58
  20. package/src/commands/generated/fields.ts +4 -4
  21. package/src/commands/generated/protocol.ts +24 -1
  22. package/src/commands/generated/variant-fields.ts +1 -1
  23. package/src/commands/keyboard.ts +4 -13
  24. package/src/commands/physical-code.ts +11 -0
  25. package/src/commands/ports.ts +2 -1
  26. package/src/commands/projectors.ts +52 -29
  27. package/src/commands/validation.ts +408 -188
  28. package/src/config/client.ts +3 -3
  29. package/src/config/generated/base.ts +22 -6
  30. package/src/config/generated/fields.ts +2 -1
  31. package/src/config/generated/label-template.ts +1 -1
  32. package/src/config/generated/labels.ts +1 -1
  33. package/src/config/generated/protocol.ts +1 -1
  34. package/src/config/generated/restore.ts +35 -12
  35. package/src/config/generated/variant-fields.ts +1 -1
  36. package/src/config/validation/commands.ts +11 -13
  37. package/src/config/validation/outcomes.ts +147 -46
  38. package/src/config/validation/primitives.ts +11 -39
  39. package/src/config/validation/projection.ts +44 -44
  40. package/src/core/connection.ts +124 -29
  41. package/src/core/controller-lifecycle.ts +144 -0
  42. package/src/core/generated/identifiers.ts +4 -0
  43. package/src/core/identifiers.ts +40 -0
  44. package/src/core/index.ts +10 -1
  45. package/src/core/json-value.ts +58 -0
  46. package/src/core/listeners.ts +35 -0
  47. package/src/core/record.ts +76 -0
  48. package/src/core/transport.ts +10 -1
  49. package/src/core/wire-copy.ts +1 -0
  50. package/src/history/client.ts +11 -7
  51. package/src/history/controller.ts +72 -74
  52. package/src/history/generated/fields.ts +2 -1
  53. package/src/history/generated/protocol.ts +8 -5
  54. package/src/history/generated/variant-fields.ts +1 -1
  55. package/src/history/ports.ts +7 -2
  56. package/src/history/validation.ts +15 -37
  57. package/src/history-tree/client.ts +15 -13
  58. package/src/history-tree/controller.ts +131 -90
  59. package/src/history-tree/generated/fields.ts +3 -1
  60. package/src/history-tree/generated/protocol.ts +43 -7
  61. package/src/history-tree/generated/variant-fields.ts +7 -1
  62. package/src/history-tree/ports.ts +9 -4
  63. package/src/history-tree/validation.ts +44 -35
  64. package/src/layout/generated/protocol.ts +2 -1
  65. package/src/layout/generated/variant-fields.ts +47 -0
  66. package/src/layout/index.ts +1 -1
  67. package/src/layout/ratio.ts +9 -2
  68. package/src/layout/validation.ts +88 -13
  69. package/src/licence/client.ts +11 -7
  70. package/src/licence/controller.ts +64 -43
  71. package/src/licence/generated/fields.ts +2 -1
  72. package/src/licence/generated/protocol.ts +8 -4
  73. package/src/licence/generated/variant-fields.ts +1 -1
  74. package/src/licence/key.ts +2 -6
  75. package/src/licence/ports.ts +7 -2
  76. package/src/licence/validation.ts +27 -20
  77. package/src/native-content/client.ts +32 -1
  78. package/src/native-content/generated/fields.ts +4 -4
  79. package/src/native-content/generated/protocol.ts +16 -5
  80. package/src/native-content/generated/variant-fields.ts +1 -1
  81. package/src/native-content/ports.ts +2 -1
  82. package/src/native-content/validation/base.ts +16 -46
  83. package/src/native-content/validation/messages.ts +3 -0
  84. package/src/notifications/client.ts +17 -39
  85. package/src/notifications/controller.ts +266 -165
  86. package/src/notifications/generated/fields.ts +2 -1
  87. package/src/notifications/generated/labels.ts +1 -1
  88. package/src/notifications/generated/protocol.ts +5 -1
  89. package/src/notifications/generated/variant-fields.ts +1 -1
  90. package/src/notifications/ports.ts +2 -1
  91. package/src/notifications/tone.ts +1 -1
  92. package/src/notifications/validation.ts +41 -51
  93. package/src/operation/bridge.ts +79 -19
  94. package/src/operation/client.ts +17 -45
  95. package/src/operation/controller.ts +38 -59
  96. package/src/operation/generated/fields.ts +2 -1
  97. package/src/operation/generated/labels.ts +1 -1
  98. package/src/operation/generated/protocol.ts +5 -1
  99. package/src/operation/generated/variant-fields.ts +1 -1
  100. package/src/operation/ports.ts +2 -1
  101. package/src/operation/validation.ts +48 -50
  102. package/src/settings/connection.ts +10 -14
  103. package/src/settings/generated/fields.ts +2 -1
  104. package/src/settings/generated/protocol.ts +5 -1
  105. package/src/settings/generated/variant-fields.ts +1 -1
  106. package/src/settings/validation/authority.ts +2 -2
  107. package/src/settings/validation/command.ts +5 -4
  108. package/src/settings/validation/primitives.ts +32 -67
  109. package/src/settings/validation/registry.ts +13 -11
  110. package/src/surface-transfer/generated/fields.ts +1 -1
  111. package/src/surface-transfer/generated/protocol.ts +3 -3
  112. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  113. package/src/surface-transfer/validation.ts +76 -53
  114. package/src/surfaces/client.ts +26 -38
  115. package/src/surfaces/generated/fields.ts +1 -1
  116. package/src/surfaces/generated/protocol.ts +1 -1
  117. package/src/surfaces/generated/variant-fields.ts +1 -1
  118. package/src/surfaces/validation.ts +198 -61
  119. package/src/transfer/connection.ts +25 -39
  120. package/src/transfer/generated/fields.ts +2 -1
  121. package/src/transfer/generated/protocol.ts +9 -1
  122. package/src/transfer/generated/variant-fields.ts +1 -1
  123. package/src/transfer/index.ts +8 -1
  124. package/src/transfer/payload.ts +12 -9
  125. package/src/transfer/validation.ts +146 -60
  126. package/src/update/client.ts +43 -16
  127. package/src/update/controller.ts +187 -104
  128. package/src/update/generated/fields.ts +2 -1
  129. package/src/update/generated/protocol.ts +19 -7
  130. package/src/update/generated/variant-fields.ts +3 -2
  131. package/src/update/ports.ts +11 -7
  132. package/src/update/serialized.ts +8 -6
  133. package/src/update/validation.ts +18 -28
@@ -1,3 +1,4 @@
1
+ import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
1
2
  import { ForkHistoryClient } from "./client.ts";
2
3
  import {
3
4
  FORK_HISTORY_PROTOCOL_VERSION,
@@ -10,14 +11,14 @@ import type {
10
11
  ForkContinuationPageSnapshot,
11
12
  ForkEntryRecord,
12
13
  ForkPruneResult,
13
- ForkRemovalReceiptProjection,
14
+ ForkDeleteResult,
14
15
  ForkNavigationResult,
15
16
  ForkNavigationTargetProjection,
16
17
  ForkPathPageSnapshot,
17
18
  ForkPathTargetProjection,
18
19
  ForkSnapshot,
19
20
  } from "./generated/protocol.ts";
20
- import type { ForkHistoryPort, ForkHistoryUnlisten } from "./ports.ts";
21
+ import type { ForkHistoryPort } from "./ports.ts";
21
22
 
22
23
  export type ForkHistoryControllerStatus =
23
24
  | { readonly kind: "idle" }
@@ -42,12 +43,10 @@ export class ForkHistoryController {
42
43
  #path: ForkPathPageSnapshot | undefined;
43
44
  #branches: ForkBranchPageSnapshot | undefined;
44
45
  #pathTarget: ForkPathTargetProjection = { kind: "default" };
45
- #started = false;
46
- #lifecycle = 0;
46
+ readonly #lifecycle = new ControllerLifecycle();
47
47
  #load = 0;
48
48
  #navigation = 0;
49
49
  #pending = false;
50
- #unlisten: Array<ForkHistoryUnlisten> = [];
51
50
 
52
51
  constructor(options: ForkHistoryControllerOptions) {
53
52
  this.#client = new ForkHistoryClient(options.port);
@@ -56,7 +55,7 @@ export class ForkHistoryController {
56
55
  this.#continuationPageSize = pageSize(options.continuationPageSize ?? 50);
57
56
  }
58
57
  get status() {
59
- return this.#status;
58
+ return this.#lifecycle.eventFailure ?? this.#status;
60
59
  }
61
60
  get snapshot() {
62
61
  return this.#snapshot;
@@ -84,44 +83,48 @@ export class ForkHistoryController {
84
83
  return () => this.#observers.delete(observer);
85
84
  }
86
85
 
87
- async start(): Promise<void> {
88
- if (this.#started) {
89
- return;
90
- }
91
- this.#started = true;
92
- const lifecycle = ++this.#lifecycle;
93
- this.#setStatus({ kind: "loading" });
94
- try {
95
- const unlisten = await this.#client.listen((event) => this.#changed(event));
96
- if (!this.#started || lifecycle !== this.#lifecycle) {
97
- await unlisten();
98
- return;
99
- }
100
- this.#unlisten.push(unlisten);
101
- await this.refresh();
102
- } catch (error) {
103
- if (this.#started && lifecycle === this.#lifecycle) {
104
- this.#setStatus({ kind: "failed", error });
105
- }
106
- }
86
+ start(): Promise<void> {
87
+ return this.#lifecycle.start({
88
+ loading: () => this.#setStatus({ kind: "loading" }),
89
+ connect: async ({ isCurrent, own, reportFailure }) => {
90
+ const unlisten = await this.#client.listen((event) => {
91
+ if (isCurrent()) {
92
+ this.#changed(event);
93
+ }
94
+ }, reportFailure);
95
+ await own(unlisten);
96
+ if (isCurrent()) {
97
+ await this.refresh();
98
+ }
99
+ },
100
+ failed: (error) => this.#setStatus({ kind: "failed", error }),
101
+ });
107
102
  }
108
103
 
109
- async stop(): Promise<void> {
110
- this.#started = false;
111
- this.#lifecycle += 1;
112
- this.#load += 1;
113
- this.#navigation += 1;
114
- await Promise.allSettled(this.#unlisten.splice(0).map((dispose) => dispose()));
115
- this.#snapshot = undefined;
116
- this.#path = undefined;
117
- this.#branches = undefined;
118
- this.#pathTarget = { kind: "default" };
119
- this.#pending = false;
120
- this.#setStatus({ kind: "idle" });
104
+ /** Replaces the current subscription, including after a reported failure. */
105
+ restart(): Promise<void> {
106
+ return this.#lifecycle.restart(
107
+ this.status,
108
+ () => this.stop(),
109
+ () => this.start(),
110
+ );
111
+ }
112
+
113
+ stop(): Promise<void> {
114
+ return this.#lifecycle.stop(() => {
115
+ this.#load += 1;
116
+ this.#navigation += 1;
117
+ this.#snapshot = undefined;
118
+ this.#path = undefined;
119
+ this.#branches = undefined;
120
+ this.#pathTarget = { kind: "default" };
121
+ this.#pending = false;
122
+ this.#setStatus({ kind: "idle" });
123
+ });
121
124
  }
122
125
 
123
126
  async refresh(): Promise<void> {
124
- if (!this.#started) {
127
+ if (!this.#lifecycle.active) {
125
128
  return;
126
129
  }
127
130
  const load = ++this.#load;
@@ -144,7 +147,7 @@ export class ForkHistoryController {
144
147
  if (branches !== undefined && !same(snapshot, branches)) {
145
148
  continue;
146
149
  }
147
- if (this.#started && load === this.#load) {
150
+ if (this.#lifecycle.active && load === this.#load) {
148
151
  this.#install(snapshot, path, branches);
149
152
  this.#setStatus({ kind: "ready" });
150
153
  }
@@ -152,18 +155,16 @@ export class ForkHistoryController {
152
155
  }
153
156
  throw new ForkHistoryProjectionGapError();
154
157
  } catch (error) {
155
- if (this.#started && load === this.#load) {
158
+ if (this.#lifecycle.active && load === this.#load) {
156
159
  this.#setStatus({ kind: "failed", error });
157
160
  }
158
161
  }
159
162
  }
160
163
 
161
164
  async loadBranches(offset = 0): Promise<ForkBranchPageSnapshot> {
162
- const snapshot = this.#required();
163
- const value = await this.#client.branches(this.#branchCommand(snapshot, offset));
164
- if (!same(snapshot, value)) {
165
- throw new ForkHistoryProjectionGapError();
166
- }
165
+ const value = await this.#loadCurrent((snapshot) =>
166
+ this.#client.branches(this.#branchCommand(snapshot, offset)),
167
+ );
167
168
  this.#branches = value;
168
169
  this.#notify();
169
170
  return value;
@@ -179,40 +180,34 @@ export class ForkHistoryController {
179
180
  * Not cached and not refreshed. A consumer asks when the operator opens an
180
181
  * entry, and the revision check below tells them if it went stale meanwhile.
181
182
  */
182
- async loadContinuations(
183
+ loadContinuations(
183
184
  anchorEntryId: string | null,
184
185
  offset = 0,
185
186
  ): Promise<ForkContinuationPageSnapshot> {
186
- const snapshot = this.#required();
187
- const value = await this.#client.continuations({
188
- protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
189
- authorityEpoch: snapshot.authorityEpoch,
190
- historyId: snapshot.summary.historyId,
191
- expectedRevision: snapshot.summary.revision,
192
- anchorEntryId,
193
- offset,
194
- limit: this.#continuationPageSize,
195
- });
196
- if (!same(snapshot, value)) {
197
- throw new ForkHistoryProjectionGapError();
198
- }
199
- return value;
187
+ return this.#loadCurrent((snapshot) =>
188
+ this.#client.continuations({
189
+ protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
190
+ authorityEpoch: snapshot.authorityEpoch,
191
+ historyId: snapshot.summary.historyId,
192
+ expectedRevision: snapshot.summary.revision,
193
+ anchorEntryId,
194
+ offset,
195
+ limit: this.#continuationPageSize,
196
+ }),
197
+ );
200
198
  }
201
199
 
202
200
  /**
203
201
  * The flat run beginning at one entry. The same snapshot type as the main
204
202
  * path, so a renderer draws a nested fork with the component it already has.
205
203
  */
206
- async loadContinuationRun(fromEntryId: string, offset = 0): Promise<ForkPathPageSnapshot> {
207
- const snapshot = this.#required();
208
- const value = await this.#client.path({
209
- ...this.#pathCommand(snapshot, { kind: "continuation", fromEntryId }),
210
- offset,
211
- });
212
- if (!same(snapshot, value)) {
213
- throw new ForkHistoryProjectionGapError();
214
- }
215
- return value;
204
+ loadContinuationRun(fromEntryId: string, offset = 0): Promise<ForkPathPageSnapshot> {
205
+ return this.#loadCurrent((snapshot) =>
206
+ this.#client.path({
207
+ ...this.#pathCommand(snapshot, { kind: "continuation", fromEntryId }),
208
+ offset,
209
+ }),
210
+ );
216
211
  }
217
212
 
218
213
  /**
@@ -223,11 +218,11 @@ export class ForkHistoryController {
223
218
  *
224
219
  * It refuses four things rather than working around them: the entry the
225
220
  * operator stands on or above, the active line, a pinned branch, and an
226
- * entry that does not exist. A refusal arrives as a rejected promise.
221
+ * entry that does not exist. A refusal is returned as a typed result.
227
222
  */
228
- async deleteContinuation(entryId: string): Promise<ForkRemovalReceiptProjection> {
223
+ async deleteContinuation(entryId: string): Promise<ForkDeleteResult> {
229
224
  const snapshot = this.#required();
230
- const receipt = await this.#client.deleteContinuation({
225
+ const result = await this.#client.deleteContinuation({
231
226
  protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
232
227
  authorityEpoch: snapshot.authorityEpoch,
233
228
  historyId: snapshot.summary.historyId,
@@ -236,8 +231,10 @@ export class ForkHistoryController {
236
231
  });
237
232
  // Every page the consumer holds may name entries that no longer exist, so
238
233
  // this refresh is not optional and is not left to the changed event.
239
- await this.refresh();
240
- return receipt;
234
+ if (result.status === "deleted" || result.rejection.refreshRequired) {
235
+ await this.refresh();
236
+ }
237
+ return result;
241
238
  }
242
239
 
243
240
  /**
@@ -262,7 +259,10 @@ export class ForkHistoryController {
262
259
  maximumEntries,
263
260
  maximumEncodedWeight,
264
261
  });
265
- if (result.status === "pruned") {
262
+ if (
263
+ result.status === "pruned" ||
264
+ (result.status === "rejected" && result.rejection.refreshRequired)
265
+ ) {
266
266
  await this.refresh();
267
267
  }
268
268
  return result;
@@ -316,11 +316,11 @@ export class ForkHistoryController {
316
316
  expectedRevision: snapshot.summary.revision,
317
317
  target,
318
318
  });
319
- if (!this.#started || navigation !== this.#navigation) {
319
+ if (!this.#lifecycle.active || navigation !== this.#navigation) {
320
320
  throw new ForkHistoryLateResultError();
321
321
  }
322
322
  const path = await this.#client.path(this.#pathCommand(result.snapshot, this.#pathTarget));
323
- if (!this.#started || navigation !== this.#navigation) {
323
+ if (!this.#lifecycle.active || navigation !== this.#navigation) {
324
324
  throw new ForkHistoryLateResultError();
325
325
  }
326
326
  if (!same(result.snapshot, path)) {
@@ -331,7 +331,7 @@ export class ForkHistoryController {
331
331
  branchOffset === undefined
332
332
  ? undefined
333
333
  : await this.#client.branches(this.#branchCommand(result.snapshot, branchOffset));
334
- if (!this.#started || navigation !== this.#navigation) {
334
+ if (!this.#lifecycle.active || navigation !== this.#navigation) {
335
335
  throw new ForkHistoryLateResultError();
336
336
  }
337
337
  if (branches !== undefined && !same(result.snapshot, branches)) {
@@ -340,6 +340,12 @@ export class ForkHistoryController {
340
340
  this.#install(result.snapshot, path, branches);
341
341
  this.#setStatus({ kind: "ready" });
342
342
  return result;
343
+ } catch (error) {
344
+ // A superseded navigation no longer owns the controller's status.
345
+ if (this.#lifecycle.active && navigation === this.#navigation) {
346
+ this.#setStatus({ kind: "failed", error });
347
+ }
348
+ throw error;
343
349
  } finally {
344
350
  if (navigation === this.#navigation) {
345
351
  this.#pending = false;
@@ -348,6 +354,26 @@ export class ForkHistoryController {
348
354
  }
349
355
  }
350
356
 
357
+ /**
358
+ * Loads one page against the held snapshot. The page is returned only while
359
+ * the same lifetime still holds the revision it was read at.
360
+ */
361
+ async #loadCurrent<Page extends ForkPage>(
362
+ load: (snapshot: ForkSnapshot) => Promise<Page>,
363
+ ): Promise<Page> {
364
+ const snapshot = this.#required();
365
+ const lifecycle = this.#lifecycle.revision;
366
+ const page = await load(snapshot);
367
+ if (!this.#lifecycle.isCurrent(lifecycle)) {
368
+ throw new ForkHistoryLateResultError();
369
+ }
370
+ const current = this.#snapshot;
371
+ if (!same(snapshot, page) || current === undefined || !same(current, page)) {
372
+ throw new ForkHistoryProjectionGapError();
373
+ }
374
+ return page;
375
+ }
376
+
351
377
  #pathCommand(snapshot: ForkSnapshot, target: ForkPathTargetProjection) {
352
378
  return {
353
379
  protocolVersion: FORK_HISTORY_PROTOCOL_VERSION,
@@ -360,7 +386,7 @@ export class ForkHistoryController {
360
386
  } as const;
361
387
  }
362
388
  #required(): ForkSnapshot {
363
- if (!this.#started || this.#snapshot === undefined) {
389
+ if (!this.#lifecycle.active || this.#snapshot === undefined) {
364
390
  throw new ForkHistoryUnavailableError();
365
391
  }
366
392
  return this.#snapshot;
@@ -396,12 +422,11 @@ export class ForkHistoryController {
396
422
  } else if (this.#branches !== undefined && !same(snapshot, this.#branches)) {
397
423
  this.#branches = undefined;
398
424
  }
399
- this.#notify();
400
425
  }
401
426
  #changed(event: ForkChangedEvent): void {
402
427
  const snapshot = this.#snapshot;
403
428
  if (
404
- !this.#started ||
429
+ !this.#lifecycle.active ||
405
430
  snapshot === undefined ||
406
431
  event.authorityEpoch !== snapshot.authorityEpoch ||
407
432
  event.historyId !== snapshot.summary.historyId ||
@@ -421,10 +446,9 @@ export class ForkHistoryController {
421
446
  }
422
447
  }
423
448
 
424
- function same(
425
- snapshot: ForkSnapshot,
426
- page: { authorityEpoch: number; historyId: string; revision: number },
427
- ): boolean {
449
+ type ForkPage = { authorityEpoch: number; historyId: string; revision: number };
450
+
451
+ function same(snapshot: ForkSnapshot, page: ForkPage): boolean {
428
452
  return (
429
453
  snapshot.authorityEpoch === page.authorityEpoch &&
430
454
  snapshot.summary.historyId === page.historyId &&
@@ -437,6 +461,23 @@ function pageSize(value: number): number {
437
461
  }
438
462
  return value;
439
463
  }
440
- export class ForkHistoryUnavailableError extends Error {}
441
- export class ForkHistoryProjectionGapError extends Error {}
442
- export class ForkHistoryLateResultError extends Error {}
464
+ export class ForkHistoryUnavailableError extends Error {
465
+ constructor(message = "fork-history controller is not ready") {
466
+ super(message);
467
+ this.name = "ForkHistoryUnavailableError";
468
+ }
469
+ }
470
+
471
+ export class ForkHistoryProjectionGapError extends Error {
472
+ constructor(message = "fork-history projections do not share one authority revision") {
473
+ super(message);
474
+ this.name = "ForkHistoryProjectionGapError";
475
+ }
476
+ }
477
+
478
+ export class ForkHistoryLateResultError extends Error {
479
+ constructor(message = "fork-history result arrived after the controller moved on") {
480
+ super(message);
481
+ this.name = "ForkHistoryLateResultError";
482
+ }
483
+ }
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:history-tree`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per protocol type, from the Rust structs.
3
3
  // A `record()` given one of these rejects unknown and missing keys —
4
4
  // contract 010's Boundary Validation Target.
@@ -16,6 +16,7 @@ export const HISTORY_TREE_FIELDS = {
16
16
  "ForkContinuationPageCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "anchorEntryId", "offset", "limit"],
17
17
  "ForkContinuationPageSnapshot": ["protocolVersion", "authorityEpoch", "historyId", "revision", "anchorEntryId", "offset", "totalContinuations", "continuations", "truncatedBefore", "truncatedAfter"],
18
18
  "ForkDeleteContinuationCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "entryId"],
19
+ "ForkRetentionRejectionProjection": ["code", "detail", "refreshRequired"],
19
20
  "ForkRemovedEntryRecord": ["entryId", "sequence", "encodedWeight"],
20
21
  "ForkRemovalReceiptProjection": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "removedEntries", "removedBranches", "removedCheckpoints", "retainedEntryCount", "retainedEncodedWeight", "unprotectedEntryCount", "unprotectedEncodedWeight"],
21
22
  "ForkPruneCommand": ["protocolVersion", "authorityEpoch", "historyId", "expectedRevision", "maximumEntries", "maximumEncodedWeight"],
@@ -23,4 +24,5 @@ export const HISTORY_TREE_FIELDS = {
23
24
  "ForkNavigationReceiptProjection": ["historyId", "planId", "previousRevision", "committedRevision", "sourceEntryId", "targetEntryId", "targetBranchId", "movedEntryIds"],
24
25
  "ForkNavigationRejectionProjection": ["code", "detail", "refreshRequired"],
25
26
  "ForkChangedEvent": ["protocolVersion", "authorityEpoch", "historyId", "previousRevision", "committedRevision", "kind"],
27
+ "ForkHistoryHostError": ["code", "message", "retryable"],
26
28
  } as const;
@@ -1,7 +1,7 @@
1
- // @generated by `effigy generate:history-tree`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are authoritative. Product payloads are intentionally absent.
3
3
 
4
- export const FORK_HISTORY_PROTOCOL_VERSION = 1 as const;
4
+ export const FORK_HISTORY_PROTOCOL_VERSION = 2 as const;
5
5
  export const MAXIMUM_FORK_HISTORY_PAGE_SIZE = 256 as const;
6
6
  export const FORK_HISTORY_ENTRY_POSITIONS = ["past","current","future"] as const;
7
7
  export const FORK_HISTORY_PATH_TARGETS = ["default","branch","continuation"] as const;
@@ -10,7 +10,9 @@ export const FORK_HISTORY_NAVIGATION_TARGETS = ["undo","redo","checkout","checko
10
10
  export const FORK_HISTORY_NAVIGATION_REJECTION_CODES = ["incompatibleProtocol","staleAuthority","foreignHistory","staleRevision","nothingToUndo","nothingToRedo","alreadyAtTarget","unknownTarget","unauthorized","applyFailed","rollbackFailed","invalidRequest"] as const;
11
11
  export const FORK_HISTORY_NAVIGATION_STATUSES = ["committed","rejected"] as const;
12
12
  export const FORK_HISTORY_CHANGED_KINDS = ["record","navigation","branchMetadata","retention","checkpoint","imported","reset"] as const;
13
- export const FORK_HISTORY_PRUNE_STATUSES = ["unchanged","pruned"] as const;
13
+ export const FORK_HISTORY_RETENTION_REJECTION_CODES = ["incompatibleProtocol","staleAuthority","foreignHistory","staleRevision","unknownEntry","currentNodeInSubtree","entryOnCurrentPath","pinnedBranchInSubtree","zeroLimit","limitTooLarge","unauthorized","invalidRequest"] as const;
14
+ export const FORK_HISTORY_DELETE_STATUSES = ["deleted","rejected"] as const;
15
+ export const FORK_HISTORY_PRUNE_STATUSES = ["rejected","unchanged","pruned"] as const;
14
16
 
15
17
  export type HistoryId = string;
16
18
 
@@ -143,13 +145,13 @@ position: ForkProjectionPosition,
143
145
  */
144
146
  continuationCount: number, };
145
147
 
146
- export type ForkPathFloorProjection = { "kind": "origin" } | { "kind": "anchor",
148
+ export type ForkPathFloorProjection = { "kind": "origin", } | { "kind": "anchor",
147
149
  /**
148
150
  * The fork point.
149
151
  */
150
152
  entryId: HistoryEntryId, };
151
153
 
152
- export type ForkPathTargetProjection = { "kind": "default" } | { "kind": "branch",
154
+ export type ForkPathTargetProjection = { "kind": "default", } | { "kind": "branch",
153
155
  /**
154
156
  * Explicit first-class branch selection.
155
157
  */
@@ -470,6 +472,32 @@ expectedRevision: HistoryRevision,
470
472
  */
471
473
  entryId: HistoryEntryId, };
472
474
 
475
+ export type ForkRetentionRejectionCode = "incompatibleProtocol" | "staleAuthority" | "foreignHistory" | "staleRevision" | "unknownEntry" | "currentNodeInSubtree" | "entryOnCurrentPath" | "pinnedBranchInSubtree" | "zeroLimit" | "limitTooLarge" | "unauthorized" | "invalidRequest";
476
+
477
+ export type ForkRetentionRejectionProjection = {
478
+ /**
479
+ * Stable category.
480
+ */
481
+ code: ForkRetentionRejectionCode,
482
+ /**
483
+ * Renderer-safe diagnostic.
484
+ */
485
+ detail: string,
486
+ /**
487
+ * Whether the caller should refresh.
488
+ */
489
+ refreshRequired: boolean, };
490
+
491
+ export type ForkDeleteResult = { "status": "deleted",
492
+ /**
493
+ * Receipt for the committed deletion.
494
+ */
495
+ receipt: ForkRemovalReceiptProjection, } | { "status": "rejected",
496
+ /**
497
+ * Reason for refusal.
498
+ */
499
+ rejection: ForkRetentionRejectionProjection, };
500
+
473
501
  export type ForkRemovedEntryRecord = {
474
502
  /**
475
503
  * Stable identity of the removed entry.
@@ -564,13 +592,17 @@ maximumEntries: number,
564
592
  */
565
593
  maximumEncodedWeight: number, };
566
594
 
567
- export type ForkPruneResult = { "status": "unchanged" } | { "status": "pruned",
595
+ export type ForkPruneResult = { "status": "rejected",
596
+ /**
597
+ * Reason for refusal.
598
+ */
599
+ rejection: ForkRetentionRejectionProjection, } | { "status": "unchanged", } | { "status": "pruned",
568
600
  /**
569
601
  * What it removed, and what is left.
570
602
  */
571
603
  receipt: ForkRemovalReceiptProjection, };
572
604
 
573
- export type ForkNavigationTargetProjection = { "kind": "undo" } | { "kind": "redo" } | { "kind": "checkout",
605
+ export type ForkNavigationTargetProjection = { "kind": "undo", } | { "kind": "redo", } | { "kind": "checkout",
574
606
  /**
575
607
  * Stable target branch.
576
608
  */
@@ -709,3 +741,7 @@ committedRevision: HistoryRevision,
709
741
  * Coarse invalidation category.
710
742
  */
711
743
  kind: ForkChangedKind, };
744
+
745
+ export type ForkHistoryHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
746
+
747
+ export type ForkHistoryHostError = { "code": ForkHistoryHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:history-tree`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per tagged-union variant, from the Rust enums.
3
3
  // Keyed by type, then by discriminant. The discriminant itself is in
4
4
  // each list, because `exact()` compares every key.
@@ -13,7 +13,12 @@ export const HISTORY_TREE_VARIANT_FIELDS: Record<string, Record<string, readonly
13
13
  "branch": ["kind", "branchId"],
14
14
  "continuation": ["kind", "fromEntryId"],
15
15
  },
16
+ "ForkDeleteResult": {
17
+ "deleted": ["status", "receipt"],
18
+ "rejected": ["status", "rejection"],
19
+ },
16
20
  "ForkPruneResult": {
21
+ "rejected": ["status", "rejection"],
17
22
  "unchanged": ["status"],
18
23
  "pruned": ["status", "receipt"],
19
24
  },
@@ -33,6 +38,7 @@ export const HISTORY_TREE_VARIANT_FIELDS: Record<string, Record<string, readonly
33
38
  export const HISTORY_TREE_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
34
39
  "ForkPathFloorProjection": "kind",
35
40
  "ForkPathTargetProjection": "kind",
41
+ "ForkDeleteResult": "status",
36
42
  "ForkPruneResult": "status",
37
43
  "ForkNavigationTargetProjection": "kind",
38
44
  "ForkNavigationResult": "status",
@@ -1,3 +1,5 @@
1
+ import type { ConnectionFailureReporter } from "../core/connection.ts";
2
+ import type { Unlisten } from "../core/transport.ts";
1
3
  import type {
2
4
  ForkBranchPageCommand,
3
5
  ForkBranchPageSnapshot,
@@ -11,12 +13,12 @@ import type {
11
13
  ForkNavigationResult,
12
14
  ForkPathPageCommand,
13
15
  ForkPathPageSnapshot,
14
- ForkRemovalReceiptProjection,
16
+ ForkDeleteResult,
15
17
  ForkSnapshot,
16
18
  HistoryPlanId,
17
19
  } from "./generated/protocol.ts";
18
20
 
19
- export type ForkHistoryUnlisten = () => void | Promise<void>;
21
+ export type ForkHistoryUnlisten = Unlisten;
20
22
 
21
23
  export interface ForkHistoryPort {
22
24
  snapshot(): Promise<unknown>;
@@ -37,9 +39,12 @@ export interface CheckedForkHistoryPort {
37
39
  path(command: ForkPathPageCommand): Promise<ForkPathPageSnapshot>;
38
40
  branches(command: ForkBranchPageCommand): Promise<ForkBranchPageSnapshot>;
39
41
  continuations(command: ForkContinuationPageCommand): Promise<ForkContinuationPageSnapshot>;
40
- deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkRemovalReceiptProjection>;
42
+ deleteContinuation(command: ForkDeleteContinuationCommand): Promise<ForkDeleteResult>;
41
43
  prune(command: ForkPruneCommand): Promise<ForkPruneResult>;
42
44
  navigate(command: ForkNavigationCommand): Promise<ForkNavigationResult>;
43
- listen?(listener: (event: ForkChangedEvent) => void): Promise<ForkHistoryUnlisten>;
45
+ listen?(
46
+ listener: (event: ForkChangedEvent) => void,
47
+ onFailure?: ConnectionFailureReporter,
48
+ ): Promise<ForkHistoryUnlisten>;
44
49
  nextPlanId(): HistoryPlanId;
45
50
  }