@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,37 +1,30 @@
1
+ import { isRecord } from "../../core/record.ts";
1
2
  import { BRIDGE_FIELDS } from "../generated/fields.ts";
2
3
  import {
3
4
  BRIDGE_MAXIMUM_DEDUPLICATION_ENTRIES,
4
5
  BRIDGE_MAXIMUM_FAILURE_MESSAGE_BYTES,
5
- BRIDGE_MAXIMUM_OPAQUE_ID_BYTES,
6
6
  BRIDGE_FAILURE_PHASES,
7
7
  BRIDGE_RETRY_CLASSES,
8
- type BridgeCancellationRequest,
9
- type BridgeCommandEnvelope,
10
- type BridgeCommandReply,
11
- type BridgeDeduplicationSupport,
12
- type BridgeFailure,
13
- type BridgeQueryEnvelope,
14
- type BridgeQueryReply,
15
- type BridgeRequestContext,
16
8
  } from "../generated/protocol.ts";
17
- import {
18
- type BridgeCodec,
19
- incompatible,
20
- integer,
21
- nullable,
22
- oneOf,
23
- opaqueId,
24
- record,
25
- } from "./base.ts";
9
+ import type {
10
+ BridgeCancellationRequest,
11
+ BridgeCommandEnvelope,
12
+ BridgeCommandReply,
13
+ BridgeDeduplicationSupport,
14
+ BridgeFailure,
15
+ BridgeQueryEnvelope,
16
+ BridgeQueryReply,
17
+ BridgeRequestContext,
18
+ } from "../generated/protocol.ts";
19
+ import { domainId, incompatible, integer, nullable, oneOf, opaqueId, record } from "./base.ts";
20
+ import type { BridgeCodec } from "./base.ts";
26
21
 
27
- export function parseBridgeRequestContext(
28
- value: unknown,
29
- ): BridgeRequestContext {
22
+ export function parseBridgeRequestContext(value: unknown): BridgeRequestContext {
30
23
  const source = record(value, BRIDGE_FIELDS.BridgeRequestContext);
31
24
  return {
32
25
  requestId: opaqueId(source.requestId),
33
26
  sessionId: opaqueId(source.sessionId),
34
- domainId: parseDomainId(source.domainId),
27
+ domainId: domainId(source.domainId),
35
28
  };
36
29
  }
37
30
 
@@ -60,9 +53,7 @@ export function parseBridgeCommandEnvelope<P>(
60
53
  };
61
54
  }
62
55
 
63
- export function parseBridgeCancellationRequest(
64
- value: unknown,
65
- ): BridgeCancellationRequest {
56
+ export function parseBridgeCancellationRequest(value: unknown): BridgeCancellationRequest {
66
57
  const source = record(value, BRIDGE_FIELDS.BridgeCancellationRequest);
67
58
  return {
68
59
  context: parseBridgeRequestContext(source.context),
@@ -71,39 +62,25 @@ export function parseBridgeCancellationRequest(
71
62
  };
72
63
  }
73
64
 
74
- export function parseBridgeFailure<D>(
75
- value: unknown,
76
- details: BridgeCodec<D>,
77
- ): BridgeFailure<D> {
65
+ export function parseBridgeFailure<D>(value: unknown, details: BridgeCodec<D>): BridgeFailure<D> {
78
66
  const source = record(value, BRIDGE_FIELDS.BridgeFailure);
79
67
  if (
80
68
  typeof source.message !== "string" ||
81
69
  source.message.length === 0 ||
82
- new TextEncoder().encode(source.message).length >
83
- BRIDGE_MAXIMUM_FAILURE_MESSAGE_BYTES
70
+ new TextEncoder().encode(source.message).length > BRIDGE_MAXIMUM_FAILURE_MESSAGE_BYTES
84
71
  ) {
85
72
  incompatible("invalid_message", source.message);
86
73
  }
87
74
  return {
88
75
  code: opaqueId(source.code),
89
76
  message: source.message,
90
- retryClass: oneOf(
91
- source.retryClass,
92
- BRIDGE_RETRY_CLASSES,
93
- "unknown_retry_class",
94
- ),
95
- phase: oneOf(
96
- source.phase,
97
- BRIDGE_FAILURE_PHASES,
98
- "unknown_failure_phase",
99
- ),
100
- details: nullable(source.details, details.parse),
77
+ retryClass: oneOf(source.retryClass, BRIDGE_RETRY_CLASSES, "unknown_retry_class"),
78
+ phase: oneOf(source.phase, BRIDGE_FAILURE_PHASES, "unknown_failure_phase"),
79
+ details: nullable(source.details, (payload) => details.parse(payload)),
101
80
  };
102
81
  }
103
82
 
104
- export function parseBridgeDeduplicationSupport(
105
- value: unknown,
106
- ): BridgeDeduplicationSupport {
83
+ export function parseBridgeDeduplicationSupport(value: unknown): BridgeDeduplicationSupport {
107
84
  if (value === "unsupported") {
108
85
  return value;
109
86
  }
@@ -116,7 +93,7 @@ export function parseBridgeDeduplicationSupport(
116
93
  ) {
117
94
  incompatible("unknown_deduplication_support", value);
118
95
  }
119
- const source = value as { finite: unknown };
96
+ const source = value;
120
97
  const capacity = integer(source.finite, 1);
121
98
  if (capacity > BRIDGE_MAXIMUM_DEDUPLICATION_ENTRIES) {
122
99
  incompatible("unknown_deduplication_support", value);
@@ -144,10 +121,7 @@ export function parseBridgeCommandReply<S, D>(
144
121
  const source = record(value, BRIDGE_FIELDS.BridgeCommandReply);
145
122
  return {
146
123
  requestId: opaqueId(source.requestId),
147
- authoritativeRevision: nullable(
148
- source.authoritativeRevision,
149
- integer,
150
- ),
124
+ authoritativeRevision: nullable(source.authoritativeRevision, integer),
151
125
  outcome: parseCommandOutcome(source.outcome, success, details),
152
126
  };
153
127
  }
@@ -187,27 +161,17 @@ function parseCommandOutcome<S, D>(
187
161
 
188
162
  function variant(
189
163
  value: unknown,
190
- keys: readonly string[],
164
+ variants: ReadonlyArray<string>,
191
165
  code: "unknown_query_outcome" | "unknown_command_outcome",
192
166
  ): Record<string, unknown> {
193
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
167
+ if (!isRecord(value)) {
194
168
  incompatible(code, value);
195
169
  }
196
- const source = value as Record<string, unknown>;
170
+ const source = value;
197
171
  const present = Object.keys(source);
198
- if (present.length !== 1 || !keys.includes(present[0]!)) {
172
+ const [key] = present;
173
+ if (present.length !== 1 || key === undefined || !variants.includes(key)) {
199
174
  incompatible(code, value);
200
175
  }
201
176
  return source;
202
177
  }
203
-
204
- function parseDomainId(value: unknown): string {
205
- if (
206
- typeof value !== "string" ||
207
- new TextEncoder().encode(value).length > BRIDGE_MAXIMUM_OPAQUE_ID_BYTES ||
208
- !/^[a-z][a-z0-9_-]*(\.[a-z][a-z0-9_-]*)*$/.test(value)
209
- ) {
210
- incompatible("invalid_domain_id", value);
211
- }
212
- return value;
213
- }
@@ -4,17 +4,10 @@ import type {
4
4
  BridgeSnapshotEnvelope,
5
5
  BridgeStreamCursor,
6
6
  } from "../generated/protocol.ts";
7
- import {
8
- type BridgeCodec,
9
- domainId,
10
- integer,
11
- opaqueId,
12
- record,
13
- } from "./base.ts";
7
+ import { domainId, integer, opaqueId, record } from "./base.ts";
8
+ import type { BridgeCodec } from "./base.ts";
14
9
 
15
- export function parseBridgeStreamCursor(
16
- value: unknown,
17
- ): BridgeStreamCursor {
10
+ export function parseBridgeStreamCursor(value: unknown): BridgeStreamCursor {
18
11
  const source = record(value, BRIDGE_FIELDS.BridgeStreamCursor);
19
12
  return {
20
13
  sessionId: opaqueId(source.sessionId),
@@ -1,3 +1,4 @@
1
+ import { attempt, disposeAll } from "../core/listeners.ts";
1
2
  import {
2
3
  assertValidCommandAvailabilitySnapshot,
3
4
  assertValidCommandCatalogue,
@@ -22,6 +23,7 @@ import type {
22
23
  CommandExecutionIntent,
23
24
  CommandExecutionOutcome,
24
25
  CommandPorts,
26
+ CommandSnapshotPort,
25
27
  CommandUnlisten,
26
28
  } from "./ports.ts";
27
29
 
@@ -54,25 +56,20 @@ export class CommandClient {
54
56
  return { catalogue, keymap, availability };
55
57
  }
56
58
 
57
- async listen(invalidate: () => void): Promise<readonly CommandUnlisten[]> {
59
+ async listen(invalidate: () => void): Promise<ReadonlyArray<CommandUnlisten>> {
58
60
  const results = await Promise.allSettled(
59
- [
60
- this.#ports.catalogue,
61
- this.#ports.keymap,
62
- this.#ports.availability,
63
- ].flatMap((port) =>
64
- port.listen === undefined ? [] : [port.listen(invalidate)],
61
+ [this.#ports.catalogue, this.#ports.keymap, this.#ports.availability].flatMap((port) =>
62
+ registrationOf(port, invalidate),
65
63
  ),
66
64
  );
67
65
  const unlisten = results.flatMap((result) =>
68
66
  result.status === "fulfilled" ? [result.value] : [],
69
67
  );
70
68
  const failure = results.find(
71
- (result): result is PromiseRejectedResult =>
72
- result.status === "rejected",
69
+ (result): result is PromiseRejectedResult => result.status === "rejected",
73
70
  );
74
71
  if (failure !== undefined) {
75
- await Promise.allSettled(unlisten.map((dispose) => dispose()));
72
+ await disposeAll(unlisten);
76
73
  throw failure.reason;
77
74
  }
78
75
  return unlisten;
@@ -82,40 +79,52 @@ export class CommandClient {
82
79
  return this.#ports.executor.execute(intent);
83
80
  }
84
81
 
85
- async preview(
86
- request: CommandKeymapPreview,
87
- ): Promise<CommandKeymapPreviewResult> {
82
+ async preview(request: CommandKeymapPreview): Promise<CommandKeymapPreviewResult> {
88
83
  assertValidCommandKeymapPreview(request);
89
- const preview = this.#ports.keymap.preview;
90
- if (preview === undefined) throw new CommandKeymapReadOnlyError();
91
- const result = await preview(request);
84
+ const keymap = this.#ports.keymap;
85
+ if (keymap.preview === undefined) {
86
+ throw new CommandKeymapReadOnlyError();
87
+ }
88
+ const result = await keymap.preview(request);
92
89
  assertValidCommandKeymapPreviewResult(result);
93
90
  return result;
94
91
  }
95
92
 
96
- async commit(
97
- request: CommandKeymapCommit,
98
- ): Promise<CommandKeymapMutationResult> {
93
+ async commit(request: CommandKeymapCommit): Promise<CommandKeymapMutationResult> {
99
94
  assertValidCommandKeymapCommit(request);
100
- const commit = this.#ports.keymap.commit;
101
- if (commit === undefined) throw new CommandKeymapReadOnlyError();
102
- const result = await commit(request);
95
+ const keymap = this.#ports.keymap;
96
+ if (keymap.commit === undefined) {
97
+ throw new CommandKeymapReadOnlyError();
98
+ }
99
+ const result = await keymap.commit(request);
103
100
  assertValidCommandKeymapMutationResult(result);
104
101
  return result;
105
102
  }
106
103
 
107
- async reset(
108
- request: CommandKeymapReset,
109
- ): Promise<CommandKeymapMutationResult> {
104
+ async reset(request: CommandKeymapReset): Promise<CommandKeymapMutationResult> {
110
105
  assertValidCommandKeymapReset(request);
111
- const reset = this.#ports.keymap.reset;
112
- if (reset === undefined) throw new CommandKeymapReadOnlyError();
113
- const result = await reset(request);
106
+ const keymap = this.#ports.keymap;
107
+ if (keymap.reset === undefined) {
108
+ throw new CommandKeymapReadOnlyError();
109
+ }
110
+ const result = await keymap.reset(request);
114
111
  assertValidCommandKeymapMutationResult(result);
115
112
  return result;
116
113
  }
117
114
  }
118
115
 
116
+ /**
117
+ * Starts one port's listener inside a promise, so its registration joins the
118
+ * settled set whether it returns, resolves or throws synchronously.
119
+ */
120
+ function registrationOf(
121
+ port: CommandSnapshotPort<unknown>,
122
+ invalidate: () => void,
123
+ ): Array<Promise<CommandUnlisten>> {
124
+ const listen = port.listen?.bind(port);
125
+ return listen === undefined ? [] : [attempt(() => listen(invalidate))];
126
+ }
127
+
119
128
  export class CommandKeymapReadOnlyError extends Error {
120
129
  constructor() {
121
130
  super("command keymap mutation is not composed");