@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.
Files changed (167) 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/inject.ts +4 -1
  6. package/src/agent-control/selection.ts +42 -25
  7. package/src/agent-control/shim.ts +428 -198
  8. package/src/bridge/direct.ts +1 -1
  9. package/src/bridge/generated/fields.ts +4 -3
  10. package/src/bridge/generated/protocol.ts +62 -7
  11. package/src/bridge/generated/variant-fields.ts +1 -1
  12. package/src/bridge/job.ts +49 -12
  13. package/src/bridge/loopback.ts +7 -25
  14. package/src/bridge/operation.ts +13 -43
  15. package/src/bridge/router.ts +10 -23
  16. package/src/bridge/runtime/connection.ts +78 -109
  17. package/src/bridge/runtime/policy.ts +8 -28
  18. package/src/bridge/runtime/retry.ts +6 -18
  19. package/src/bridge/session.ts +4 -14
  20. package/src/bridge/stream/connection.ts +24 -55
  21. package/src/bridge/stream/source.ts +2 -6
  22. package/src/bridge/stream/tracker.ts +12 -12
  23. package/src/bridge/supervision.ts +104 -97
  24. package/src/bridge/validation/base.ts +21 -63
  25. package/src/bridge/validation/jobs.ts +11 -25
  26. package/src/bridge/validation/negotiation.ts +28 -43
  27. package/src/bridge/validation/operations.ts +29 -65
  28. package/src/bridge/validation/streams.ts +3 -10
  29. package/src/commands/client.ts +37 -28
  30. package/src/commands/controller.ts +119 -96
  31. package/src/commands/generated/fields.ts +7 -6
  32. package/src/commands/generated/protocol.ts +28 -1
  33. package/src/commands/generated/variant-fields.ts +1 -1
  34. package/src/commands/keyboard.ts +94 -100
  35. package/src/commands/physical-code.ts +11 -0
  36. package/src/commands/ports.ts +8 -13
  37. package/src/commands/projectors.ts +100 -75
  38. package/src/commands/validation.ts +434 -241
  39. package/src/config/client.ts +9 -22
  40. package/src/config/generated/base.ts +22 -6
  41. package/src/config/generated/fields.ts +4 -3
  42. package/src/config/generated/label-template.ts +1 -1
  43. package/src/config/generated/labels.ts +1 -1
  44. package/src/config/generated/protocol.ts +1 -1
  45. package/src/config/generated/restore.ts +35 -12
  46. package/src/config/generated/variant-fields.ts +1 -1
  47. package/src/config/names.ts +6 -12
  48. package/src/config/validation/commands.ts +11 -25
  49. package/src/config/validation/outcomes.ts +163 -70
  50. package/src/config/validation/primitives.ts +35 -80
  51. package/src/config/validation/projection.ts +100 -128
  52. package/src/core/connection.ts +187 -83
  53. package/src/core/controller-lifecycle.ts +144 -0
  54. package/src/core/generated/identifiers.ts +4 -0
  55. package/src/core/identifiers.ts +40 -0
  56. package/src/core/index.ts +10 -1
  57. package/src/core/json-value.ts +58 -0
  58. package/src/core/listeners.ts +35 -0
  59. package/src/core/record.ts +80 -0
  60. package/src/core/transport.ts +9 -11
  61. package/src/core/wire-copy.ts +7 -0
  62. package/src/history/client.ts +11 -13
  63. package/src/history/controller.ts +106 -108
  64. package/src/history/direct.ts +1 -3
  65. package/src/history/generated/fields.ts +4 -3
  66. package/src/history/generated/protocol.ts +8 -5
  67. package/src/history/generated/variant-fields.ts +1 -1
  68. package/src/history/ports.ts +7 -4
  69. package/src/history/serialized.ts +9 -13
  70. package/src/history/validation.ts +69 -75
  71. package/src/history-tree/client.ts +89 -11
  72. package/src/history-tree/controller.ts +380 -96
  73. package/src/history-tree/direct.ts +3 -1
  74. package/src/history-tree/generated/fields.ts +5 -3
  75. package/src/history-tree/generated/protocol.ts +43 -7
  76. package/src/history-tree/generated/variant-fields.ts +7 -1
  77. package/src/history-tree/ports.ts +12 -5
  78. package/src/history-tree/serialized.ts +39 -11
  79. package/src/history-tree/validation.ts +286 -78
  80. package/src/layout/generated/protocol.ts +4 -3
  81. package/src/layout/generated/variant-fields.ts +47 -0
  82. package/src/layout/index.ts +1 -1
  83. package/src/layout/ratio.ts +10 -9
  84. package/src/layout/validation.ts +98 -32
  85. package/src/layout/visibility.ts +1 -2
  86. package/src/licence/client.ts +48 -7
  87. package/src/licence/controller.ts +127 -70
  88. package/src/licence/direct.ts +3 -1
  89. package/src/licence/generated/fields.ts +4 -3
  90. package/src/licence/generated/key-conformance.json +28 -0
  91. package/src/licence/generated/protocol.ts +9 -5
  92. package/src/licence/generated/variant-fields.ts +1 -1
  93. package/src/licence/key.ts +42 -18
  94. package/src/licence/ports.ts +10 -3
  95. package/src/licence/serialized.ts +32 -9
  96. package/src/licence/validation.ts +134 -43
  97. package/src/native-content/client.ts +207 -234
  98. package/src/native-content/generated/fields.ts +6 -6
  99. package/src/native-content/generated/protocol.ts +16 -5
  100. package/src/native-content/generated/variant-fields.ts +1 -1
  101. package/src/native-content/ports.ts +11 -16
  102. package/src/native-content/serialized.ts +12 -19
  103. package/src/native-content/validation/base.ts +57 -80
  104. package/src/native-content/validation/messages.ts +24 -35
  105. package/src/native-content/validation/state.ts +31 -33
  106. package/src/notifications/client.ts +85 -51
  107. package/src/notifications/controller.ts +400 -145
  108. package/src/notifications/direct.ts +3 -1
  109. package/src/notifications/generated/fields.ts +4 -3
  110. package/src/notifications/generated/labels.ts +1 -1
  111. package/src/notifications/generated/protocol.ts +5 -1
  112. package/src/notifications/generated/variant-fields.ts +1 -1
  113. package/src/notifications/ports.ts +9 -4
  114. package/src/notifications/serialized.ts +11 -9
  115. package/src/notifications/tone.ts +1 -1
  116. package/src/notifications/validation.ts +165 -71
  117. package/src/operation/bridge.ts +187 -60
  118. package/src/operation/client.ts +48 -62
  119. package/src/operation/controller.ts +67 -97
  120. package/src/operation/direct.ts +1 -3
  121. package/src/operation/generated/fields.ts +4 -3
  122. package/src/operation/generated/labels.ts +1 -1
  123. package/src/operation/generated/protocol.ts +5 -1
  124. package/src/operation/generated/variant-fields.ts +1 -1
  125. package/src/operation/ports.ts +12 -10
  126. package/src/operation/serialized.ts +8 -9
  127. package/src/operation/validation.ts +189 -104
  128. package/src/settings/client.ts +11 -44
  129. package/src/settings/connection.ts +35 -53
  130. package/src/settings/generated/fields.ts +5 -4
  131. package/src/settings/generated/protocol.ts +14 -5
  132. package/src/settings/generated/variant-fields.ts +1 -1
  133. package/src/settings/names.ts +2 -4
  134. package/src/settings/registry.ts +23 -25
  135. package/src/settings/validation/authority.ts +21 -19
  136. package/src/settings/validation/command.ts +22 -41
  137. package/src/settings/validation/error.ts +2 -8
  138. package/src/settings/validation/primitives.ts +46 -97
  139. package/src/settings/validation/projection.ts +8 -24
  140. package/src/settings/validation/registry.ts +33 -79
  141. package/src/surface-transfer/client.ts +6 -18
  142. package/src/surface-transfer/generated/fields.ts +3 -3
  143. package/src/surface-transfer/generated/protocol.ts +3 -3
  144. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  145. package/src/surface-transfer/validation.ts +91 -86
  146. package/src/surfaces/client.ts +33 -55
  147. package/src/surfaces/generated/fields.ts +3 -3
  148. package/src/surfaces/generated/protocol.ts +1 -1
  149. package/src/surfaces/generated/variant-fields.ts +1 -1
  150. package/src/surfaces/validation.ts +227 -99
  151. package/src/transfer/client.ts +26 -60
  152. package/src/transfer/connection.ts +29 -51
  153. package/src/transfer/generated/fields.ts +7 -6
  154. package/src/transfer/generated/protocol.ts +13 -5
  155. package/src/transfer/generated/variant-fields.ts +1 -1
  156. package/src/transfer/index.ts +8 -1
  157. package/src/transfer/payload.ts +20 -35
  158. package/src/transfer/validation.ts +169 -119
  159. package/src/update/client.ts +86 -9
  160. package/src/update/controller.ts +264 -116
  161. package/src/update/direct.ts +3 -1
  162. package/src/update/generated/fields.ts +5 -4
  163. package/src/update/generated/protocol.ts +25 -9
  164. package/src/update/generated/variant-fields.ts +4 -2
  165. package/src/update/ports.ts +14 -6
  166. package/src/update/serialized.ts +36 -10
  167. package/src/update/validation.ts +118 -48
@@ -1,36 +1,47 @@
1
- import { CheckedSnapshotConnection, type ConnectionFailure, type ConnectionFailureReporter } from "@inflatable-cookie/longhorn/core";
1
+ import { CheckedSnapshotConnection, CheckedSubscription } from "@inflatable-cookie/longhorn/core";
2
+ import type {
3
+ ConnectionFailure,
4
+ ConnectionFailureReporter,
5
+ } from "@inflatable-cookie/longhorn/core";
2
6
 
3
7
  import {
4
8
  assertValidNotificationChangedEvent,
5
9
  assertValidNotificationMutationCommand,
6
10
  assertValidNotificationMutationResult,
11
+ assertValidNotificationSnapshot,
7
12
  assertValidNotificationSnapshotResponse,
8
13
  } from "./validation.ts";
9
- import {
10
- NOTIFICATION_PROTOCOL_VERSION,
11
- type NotificationChangedEvent,
12
- type NotificationMutationCommand,
13
- type NotificationMutationResult,
14
- type NotificationSnapshot,
15
- type NotificationSnapshotResponse,
14
+ import { NOTIFICATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
15
+ import type {
16
+ NotificationMutationCommand,
17
+ NotificationMutationResult,
18
+ NotificationSnapshot,
19
+ NotificationSnapshotResponse,
16
20
  } from "./generated/protocol.ts";
17
21
  import type { NotificationPort } from "./ports.ts";
18
22
 
19
23
  export interface NotificationSubscription {
20
24
  readonly ready: Promise<void>;
21
25
  current(): NotificationSnapshot | undefined;
22
- failures(): readonly ConnectionFailure[];
26
+ failures(): ReadonlyArray<ConnectionFailure>;
23
27
  dispose(): Promise<void>;
24
28
  }
25
29
 
26
30
  export class NotificationClient {
27
31
  constructor(readonly port: NotificationPort) {}
28
32
 
29
- nextRequestId(): string { return this.port.nextRequestId(); }
33
+ nextRequestId(): string {
34
+ return this.port.nextRequestId();
35
+ }
30
36
 
31
37
  async snapshot(offset = 0, limit = 100): Promise<NotificationSnapshotResponse> {
32
38
  const requestId = this.port.nextRequestId();
33
- const value = await this.port.snapshot({ protocolVersion: NOTIFICATION_PROTOCOL_VERSION, requestId, offset, limit });
39
+ const value = await this.port.snapshot({
40
+ protocolVersion: NOTIFICATION_PROTOCOL_VERSION,
41
+ requestId,
42
+ offset,
43
+ limit,
44
+ });
34
45
  assertValidNotificationSnapshotResponse(value);
35
46
  assertCorrelation(value.requestId, requestId);
36
47
  return value;
@@ -44,63 +55,86 @@ export class NotificationClient {
44
55
  return value;
45
56
  }
46
57
 
47
- subscribe(listener: (snapshot: NotificationSnapshot) => void, onFailure?: ConnectionFailureReporter, limit = 100): NotificationSubscription {
48
- return new CheckedNotificationSubscription(this, this.port, listener, onFailure, limit);
58
+ subscribe(
59
+ listener: (snapshot: NotificationSnapshot) => void,
60
+ onFailure?: ConnectionFailureReporter,
61
+ limit = 100,
62
+ ): NotificationSubscription {
63
+ const port = this.port;
64
+ return new CheckedSubscription(
65
+ new CheckedSnapshotConnection({
66
+ listen: async (receive) => (port.listen === undefined ? () => {} : port.listen(receive)),
67
+ loadSnapshot: async () => (await this.snapshot(0, limit)).snapshot,
68
+ validateSnapshot: parseSnapshot,
69
+ handleEvent: notificationEventAction,
70
+ isNewer: isNewerNotificationSnapshot,
71
+ onSnapshot: listener,
72
+ onFailure,
73
+ }),
74
+ () => {},
75
+ );
49
76
  }
50
77
  }
51
78
 
52
79
  export class NotificationResponseCorrelationError extends Error {
53
- constructor(readonly expectedRequestId: string, readonly receivedRequestId: string) {
54
- super(`notification response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`);
80
+ constructor(
81
+ readonly expectedRequestId: string,
82
+ readonly receivedRequestId: string,
83
+ ) {
84
+ super(
85
+ `notification response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`,
86
+ );
55
87
  this.name = "NotificationResponseCorrelationError";
56
88
  }
57
89
  }
58
90
 
59
- class CheckedNotificationSubscription implements NotificationSubscription {
60
- readonly ready: Promise<void>;
61
- readonly connection: CheckedSnapshotConnection<NotificationSnapshot>;
62
-
63
- constructor(client: NotificationClient, port: NotificationPort, listener: (snapshot: NotificationSnapshot) => void, onFailure: ConnectionFailureReporter | undefined, limit: number) {
64
- this.connection = new CheckedSnapshotConnection({
65
- listen: async (receive) => port.listen === undefined ? () => {} : port.listen(receive),
66
- loadSnapshot: async () => (await client.snapshot(0, limit)).snapshot,
67
- validateSnapshot: parseSnapshot,
68
- handleEvent: notificationEventAction,
69
- isNewer: isNewerNotificationSnapshot,
70
- onSnapshot: listener,
71
- onFailure,
72
- });
73
- this.ready = this.connection.ready.then(() => undefined);
74
- }
75
-
76
- current(): NotificationSnapshot | undefined { return this.connection.current(); }
77
- failures(): readonly ConnectionFailure[] { return this.connection.failures(); }
78
- dispose(): Promise<void> { return this.connection.dispose(); }
79
- }
80
-
81
91
  function parseSnapshot(value: unknown): NotificationSnapshot {
82
- const response = { requestId: "request:validation", snapshot: value };
83
- assertValidNotificationSnapshotResponse(response);
84
- return value as NotificationSnapshot;
92
+ assertValidNotificationSnapshot(value);
93
+ return value;
85
94
  }
86
95
 
87
- export function notificationEventAction(value: unknown, current: NotificationSnapshot | undefined): { kind: "ignore" } | { kind: "refresh" } {
96
+ export function notificationEventAction(
97
+ value: unknown,
98
+ current: NotificationSnapshot | undefined,
99
+ ): { kind: "ignore" } | { kind: "refresh" } {
88
100
  assertValidNotificationChangedEvent(value);
89
- const event = value as NotificationChangedEvent;
90
- if (current === undefined) return { kind: "refresh" };
91
- if (event.authority.authorityId !== current.authority.authorityId) return { kind: "ignore" };
92
- if (event.authority.authorityEpoch < current.authority.authorityEpoch) return { kind: "ignore" };
93
- if (event.authority.authorityEpoch === current.authority.authorityEpoch && event.committedLedgerRevision <= current.ledgerRevision) return { kind: "ignore" };
101
+ const event = value;
102
+ if (current === undefined) {
103
+ return { kind: "refresh" };
104
+ }
105
+ if (event.authority.authorityId !== current.authority.authorityId) {
106
+ return { kind: "ignore" };
107
+ }
108
+ if (event.authority.authorityEpoch < current.authority.authorityEpoch) {
109
+ return { kind: "ignore" };
110
+ }
111
+ if (
112
+ event.authority.authorityEpoch === current.authority.authorityEpoch &&
113
+ event.committedLedgerRevision <= current.ledgerRevision
114
+ ) {
115
+ return { kind: "ignore" };
116
+ }
94
117
  return { kind: "refresh" };
95
118
  }
96
119
 
97
- export function isNewerNotificationSnapshot(candidate: NotificationSnapshot, current: NotificationSnapshot | undefined): boolean {
98
- if (current === undefined) return true;
99
- if (candidate.authority.authorityId !== current.authority.authorityId) return false;
100
- if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
120
+ export function isNewerNotificationSnapshot(
121
+ candidate: NotificationSnapshot,
122
+ current: NotificationSnapshot | undefined,
123
+ ): boolean {
124
+ if (current === undefined) {
125
+ return true;
126
+ }
127
+ if (candidate.authority.authorityId !== current.authority.authorityId) {
128
+ return false;
129
+ }
130
+ if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) {
131
+ return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
132
+ }
101
133
  return candidate.ledgerRevision > current.ledgerRevision;
102
134
  }
103
135
 
104
136
  function assertCorrelation(received: string, expected: string): void {
105
- if (received !== expected) throw new NotificationResponseCorrelationError(expected, received);
137
+ if (received !== expected) {
138
+ throw new NotificationResponseCorrelationError(expected, received);
139
+ }
106
140
  }