@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,3 +1,12 @@
1
+ import { isOpaqueId } from "../../core/identifiers.ts";
2
+ import {
3
+ checkWireFields,
4
+ hasHole,
5
+ readWireRecord,
6
+ signed32,
7
+ unsigned32,
8
+ wireVariantFields,
9
+ } from "../../core/record.ts";
1
10
  import {
2
11
  SETTINGS_VARIANT_FIELDS,
3
12
  SETTINGS_VARIANT_FIELDS_DISCRIMINANTS,
@@ -6,21 +15,10 @@ import { SETTINGS_FIELDS } from "../generated/fields.ts";
6
15
  import {
7
16
  SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
8
17
  SETTINGS_PROTOCOL_VERSION,
9
- type SettingsOpaqueValue,
10
18
  } from "../generated/protocol.ts";
11
- import {
12
- incompatible,
13
- type SettingsProtocolValidationCode,
14
- } from "./error.ts";
15
-
16
- /**
17
- * Kept under its original name so the twenty call sites do not churn, but the
18
- * value is now the Rust `SettingsLimits::HARD_MAXIMUM_OPAQUE_VALUE_BYTES`
19
- * rather than a literal that happened to match it.
20
- */
21
- export const HARD_MAXIMUM_OPAQUE_VALUE_BYTES: number =
22
- SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES;
23
- const OPAQUE_ID = /^[a-z0-9][a-z0-9._:/-]{0,254}$/;
19
+ import type { SettingsOpaqueValue } from "../generated/protocol.ts";
20
+ import { incompatible } from "./error.ts";
21
+ import type { SettingsProtocolValidationCode } from "./error.ts";
24
22
 
25
23
  export function authority(value: unknown): void {
26
24
  const valueRecord = record(value, SETTINGS_FIELDS.SettingsAuthorityExpectation);
@@ -35,12 +33,11 @@ export function optionalOpaque(value: unknown, maximum: number): void {
35
33
  }
36
34
  }
37
35
 
38
- export function opaque(
39
- value: unknown,
40
- maximum: number,
41
- ): asserts value is SettingsOpaqueValue {
36
+ export function opaque(value: unknown, maximum: number): asserts value is SettingsOpaqueValue {
42
37
  const envelope = record(value, SETTINGS_FIELDS.SettingsOpaqueValue);
43
- positive(envelope.codecVersion, "invalid_opaque_value");
38
+ if (!unsigned32(envelope.codecVersion) || envelope.codecVersion === 0) {
39
+ incompatible("invalid_opaque_value", envelope.codecVersion);
40
+ }
44
41
  let encoded: string | undefined;
45
42
  try {
46
43
  encoded = JSON.stringify(envelope);
@@ -51,23 +48,23 @@ export function opaque(
51
48
  incompatible("invalid_opaque_value", value);
52
49
  }
53
50
  const bytes = new TextEncoder().encode(encoded).byteLength;
54
- if (bytes > maximum || bytes > HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
51
+ if (bytes > maximum || bytes > SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
55
52
  incompatible("opaque_value_too_large", bytes);
56
53
  }
57
54
  }
58
55
 
59
- export function definition(value: unknown): void {
60
- const valueRecord = record(value);
56
+ export function definition(value: unknown, allowed: ReadonlyArray<string>): void {
57
+ const valueRecord = record(value, allowed);
61
58
  identity(valueRecord.id);
62
59
  identity(valueRecord.moduleId);
63
60
  }
64
61
 
65
- export function arraysOfIdentities(...values: unknown[]): void {
62
+ export function arraysOfIdentities(...values: Array<unknown>): void {
66
63
  values.forEach((value) => array(value).forEach(identity));
67
64
  }
68
65
 
69
- export function identity(value: unknown): void {
70
- if (typeof value !== "string" || !OPAQUE_ID.test(value)) {
66
+ export function identity(value: unknown): asserts value is string {
67
+ if (!isOpaqueId(value)) {
71
68
  incompatible("invalid_identity", value);
72
69
  }
73
70
  }
@@ -78,7 +75,7 @@ export function protocolVersion(value: unknown): void {
78
75
  }
79
76
  }
80
77
 
81
- export function known(value: unknown, choices: readonly string[]): void {
78
+ export function known(value: unknown, choices: ReadonlyArray<string>): void {
82
79
  if (typeof value !== "string" || !choices.includes(value)) {
83
80
  incompatible("unknown_discriminant", value);
84
81
  }
@@ -100,31 +97,21 @@ export function boolean(value: unknown): void {
100
97
  }
101
98
  }
102
99
 
103
- export function integer(value: unknown): void {
104
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
100
+ export function order(value: unknown): void {
101
+ if (!signed32(value)) {
105
102
  incompatible("invalid_shape", value);
106
103
  }
107
104
  }
108
105
 
109
- export function positive(
110
- value: unknown,
111
- code: SettingsProtocolValidationCode,
112
- ): void {
106
+ export function positive(value: unknown, code: SettingsProtocolValidationCode): void {
113
107
  unsigned(value, code);
114
108
  if (value === 0) {
115
109
  incompatible(code, value);
116
110
  }
117
111
  }
118
112
 
119
- export function unsigned(
120
- value: unknown,
121
- code: SettingsProtocolValidationCode,
122
- ): void {
123
- if (
124
- typeof value !== "number" ||
125
- !Number.isSafeInteger(value) ||
126
- value < 0
127
- ) {
113
+ export function unsigned(value: unknown, code: SettingsProtocolValidationCode): void {
114
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
128
115
  incompatible(code, value);
129
116
  }
130
117
  }
@@ -133,71 +120,33 @@ export function boundedArray(
133
120
  value: unknown,
134
121
  maximum: number,
135
122
  code: SettingsProtocolValidationCode,
136
- ): unknown[] {
137
- const values = array(value);
138
- if (values.length > maximum) {
139
- incompatible(code, values.length);
123
+ ): Array<unknown> {
124
+ // Bounds land before work: an oversized list is refused unread.
125
+ if (Array.isArray(value) && value.length > maximum) {
126
+ incompatible(code, value.length);
140
127
  }
141
- return values;
128
+ return array(value);
142
129
  }
143
130
 
144
- export function array(value: unknown): unknown[] {
145
- if (!Array.isArray(value)) {
131
+ export function array(value: unknown): Array<unknown> {
132
+ if (!Array.isArray(value) || hasHole(value)) {
146
133
  incompatible("invalid_shape", value);
147
134
  }
148
135
  return value;
149
136
  }
150
137
 
151
- /**
152
- * Rejects a non-object, an unknown key, and a missing key.
153
- *
154
- * `allowed` comes from the generated field map, so the keys accepted are the
155
- * Rust struct's and nothing else — contract 010's Boundary Validation Target.
156
- * Called without a list, this keeps shape-only behaviour, which is correct
157
- * for a tagged union and a gap anywhere else.
158
- */
159
- export function record(
160
- value: unknown,
161
- allowed?: readonly string[],
162
- ): Record<string, unknown> {
163
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
164
- incompatible("invalid_shape", value);
165
- }
166
- const result = value as Record<string, unknown>;
167
- if (allowed === undefined) return result;
168
-
169
- const permitted = new Set(allowed);
170
- for (const key of Object.keys(result)) {
171
- if (!permitted.has(key)) {
172
- incompatible("unknown_field", { key, value });
173
- }
174
- }
175
- for (const key of allowed) {
176
- if (!(key in result)) {
177
- incompatible("missing_field", { key, value });
178
- }
179
- }
138
+ export function record(value: unknown, allowed?: ReadonlyArray<string>): Record<string, unknown> {
139
+ const result = readWireRecord(value, () => incompatible("invalid_shape", value));
140
+ checkWireFields(result, allowed, (code, key) => incompatible(code, { key, value }));
180
141
  return result;
181
142
  }
182
143
 
183
- /**
184
- * Allowed keys for one tagged-union variant, from the generated map.
185
- *
186
- * The discriminant's name comes from the map too: this domain tags
187
- * `SettingsDurabilityEvidence` on `kind` and its two results on `status`, and
188
- * a call site that has to name the right one is a per-site chance to name the
189
- * wrong one.
190
- *
191
- * A missing entry means the generator failed to read the union, not that a
192
- * caller sent something odd — every caller checks the discriminant with
193
- * `known()` above this call.
194
- */
195
- export function variantKeys(
196
- type: string,
197
- value: Record<string, unknown>,
198
- ): readonly string[] {
199
- const discriminant = value[SETTINGS_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
200
- const keys = SETTINGS_VARIANT_FIELDS[type]?.[discriminant as string];
201
- if (keys === undefined) incompatible("unknown_field", { type, discriminant });
202
- return keys;
144
+ export function variantKeys(type: string, value: Record<string, unknown>): ReadonlyArray<string> {
145
+ return wireVariantFields(
146
+ SETTINGS_VARIANT_FIELDS,
147
+ SETTINGS_VARIANT_FIELDS_DISCRIMINANTS,
148
+ type,
149
+ value,
150
+ (discriminant) => incompatible("unknown_field", { type, discriminant }),
151
+ );
203
152
  }
@@ -1,37 +1,25 @@
1
1
  import { SETTINGS_FIELDS } from "../generated/fields.ts";
2
- import {
3
- array,
4
- identity,
5
- known,
6
- optionalOpaque,
7
- record,
8
- } from "./primitives.ts";
2
+ import { array, identity, known, optionalOpaque, record } from "./primitives.ts";
9
3
 
10
- export function policy(
4
+ export function hasPolicyOverride(
11
5
  value: unknown,
12
6
  maximum: number,
13
- effects: readonly string[],
14
- ): void {
7
+ effects: ReadonlyArray<string>,
8
+ ): boolean {
15
9
  const valueRecord = record(value, SETTINGS_FIELDS.SettingsPolicyProjection);
16
10
  identity(valueRecord.sourceId);
17
11
  known(valueRecord.effect, effects);
18
12
  optionalOpaque(valueRecord.constraints, maximum);
13
+ return valueRecord.effect === "override";
19
14
  }
20
15
 
21
- export function recovery(
22
- value: unknown,
23
- maximum: number,
24
- codes: readonly string[],
25
- ): void {
16
+ export function recovery(value: unknown, maximum: number, codes: ReadonlyArray<string>): void {
26
17
  const valueRecord = record(value, SETTINGS_FIELDS.SettingsRecoveryState);
27
18
  known(valueRecord.code, codes);
28
19
  optionalOpaque(valueRecord.diagnostic, maximum);
29
20
  }
30
21
 
31
- export function activation(
32
- value: unknown,
33
- states: readonly string[],
34
- ): void {
22
+ export function activation(value: unknown, states: ReadonlyArray<string>): void {
35
23
  array(value).forEach((value) => {
36
24
  const requirement = record(value, SETTINGS_FIELDS.SettingsActivationRequirement);
37
25
  identity(requirement.targetId);
@@ -39,11 +27,7 @@ export function activation(
39
27
  });
40
28
  }
41
29
 
42
- export function rejection(
43
- value: unknown,
44
- maximum: number,
45
- codes: readonly string[],
46
- ): void {
30
+ export function rejection(value: unknown, maximum: number, codes: ReadonlyArray<string>): void {
47
31
  const valueRecord = record(value, SETTINGS_FIELDS.SettingsRejection);
48
32
  known(valueRecord.code, codes);
49
33
  optionalOpaque(valueRecord.diagnostic, maximum);
@@ -1,8 +1,9 @@
1
1
  import { SETTINGS_FIELDS } from "../generated/fields.ts";
2
2
  import {
3
+ SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
3
4
  SETTINGS_MUTATION_TIMINGS,
4
- type SettingsRegistrySnapshot,
5
5
  } from "../generated/protocol.ts";
6
+ import type { SettingsRegistrySnapshot, SettingsLimits } from "../generated/protocol.ts";
6
7
  import { incompatible } from "./error.ts";
7
8
  import {
8
9
  arraysOfIdentities,
@@ -10,14 +11,13 @@ import {
10
11
  boundedArray,
11
12
  definition,
12
13
  identity,
13
- integer,
14
+ order,
14
15
  known,
15
16
  positive,
16
17
  protocolVersion,
17
18
  record,
18
19
  text,
19
20
  unsigned,
20
- HARD_MAXIMUM_OPAQUE_VALUE_BYTES,
21
21
  } from "./primitives.ts";
22
22
 
23
23
  const DIGEST = /^[a-f0-9]{64}$/;
@@ -32,31 +32,11 @@ export function assertValidSettingsRegistrySnapshot(
32
32
  incompatible("invalid_registry", registry.digest);
33
33
  }
34
34
  const limits = settingsLimits(registry.limits);
35
- const modules = boundedArray(
36
- registry.modules,
37
- limits.maximumModules,
38
- "invalid_registry",
39
- );
40
- const sections = boundedArray(
41
- registry.sections,
42
- limits.maximumSections,
43
- "invalid_registry",
44
- );
45
- const pages = boundedArray(
46
- registry.pages,
47
- limits.maximumPages,
48
- "invalid_registry",
49
- );
50
- const renderers = boundedArray(
51
- registry.renderers,
52
- limits.maximumRenderers,
53
- "invalid_registry",
54
- );
55
- const scopes = boundedArray(
56
- registry.scopes,
57
- limits.maximumScopes,
58
- "invalid_registry",
59
- );
35
+ const modules = boundedArray(registry.modules, limits.maximumModules, "invalid_registry");
36
+ const sections = boundedArray(registry.sections, limits.maximumSections, "invalid_registry");
37
+ const pages = boundedArray(registry.pages, limits.maximumPages, "invalid_registry");
38
+ const renderers = boundedArray(registry.renderers, limits.maximumRenderers, "invalid_registry");
39
+ const scopes = boundedArray(registry.scopes, limits.maximumScopes, "invalid_registry");
60
40
  const applyUnits = boundedArray(
61
41
  registry.applyUnits,
62
42
  limits.maximumApplyUnits,
@@ -77,18 +57,18 @@ export function assertValidSettingsRegistrySnapshot(
77
57
  const module = record(value, SETTINGS_FIELDS.SettingsModuleDefinition);
78
58
  identity(module.id);
79
59
  text(module.label, limits.maximumLabelBytes);
80
- integer(module.order);
60
+ order(module.order);
81
61
  });
82
62
  sections.forEach((value) => {
83
63
  const section = record(value, SETTINGS_FIELDS.SettingsSectionDefinition);
84
64
  identity(section.id);
85
65
  identity(section.moduleId);
86
66
  text(section.label, limits.maximumLabelBytes);
87
- integer(section.order);
67
+ order(section.order);
88
68
  });
89
- renderers.forEach(definition);
90
- scopes.forEach(definition);
91
- capabilities.forEach(definition);
69
+ renderers.forEach((value) => definition(value, SETTINGS_FIELDS.SettingsRendererDefinition));
70
+ scopes.forEach((value) => definition(value, SETTINGS_FIELDS.SettingsScopeDefinition));
71
+ capabilities.forEach((value) => definition(value, SETTINGS_FIELDS.SettingsCapabilityDefinition));
92
72
  applyUnits.forEach((value) => {
93
73
  const unit = record(value, SETTINGS_FIELDS.SettingsApplyUnitDefinition);
94
74
  identity(unit.id);
@@ -100,39 +80,26 @@ export function assertValidSettingsRegistrySnapshot(
100
80
  pages.forEach((value) => validatePage(value, limits));
101
81
  }
102
82
 
103
- function validatePage(
104
- value: unknown,
105
- limits: Record<string, number>,
106
- ): void {
83
+ function validatePage(value: unknown, limits: SettingsLimits): void {
107
84
  const page = record(value, SETTINGS_FIELDS.SettingsPageDefinition);
108
85
  identity(page.id);
109
86
  identity(page.moduleId);
110
87
  identity(page.sectionId);
111
88
  identity(page.rendererId);
112
- text(page.label, limits.maximumLabelBytes!);
113
- integer(page.order);
114
- boundedArray(
115
- page.keywords,
116
- limits.maximumKeywordsPerPage!,
117
- "invalid_registry",
118
- ).forEach((keyword) => text(keyword, limits.maximumKeywordBytes!));
119
- boundedArray(
120
- page.anchors,
121
- limits.maximumAnchorsPerPage!,
122
- "invalid_registry",
123
- ).forEach((value) => {
89
+ text(page.label, limits.maximumLabelBytes);
90
+ order(page.order);
91
+ boundedArray(page.keywords, limits.maximumKeywordsPerPage, "invalid_registry").forEach(
92
+ (keyword) => text(keyword, limits.maximumKeywordBytes),
93
+ );
94
+ boundedArray(page.anchors, limits.maximumAnchorsPerPage, "invalid_registry").forEach((value) => {
124
95
  const anchor = record(value, SETTINGS_FIELDS.SettingsAnchorDefinition);
125
96
  identity(anchor.id);
126
97
  if (anchor.label !== null) {
127
- text(anchor.label, limits.maximumLabelBytes!);
98
+ text(anchor.label, limits.maximumLabelBytes);
128
99
  }
129
- integer(anchor.order);
100
+ order(anchor.order);
130
101
  });
131
- arraysOfIdentities(
132
- page.requiredCapabilities,
133
- page.readableScopeIds,
134
- page.writableApplyUnitIds,
135
- );
102
+ arraysOfIdentities(page.requiredCapabilities, page.readableScopeIds, page.writableApplyUnitIds);
136
103
  const features = record(page.features, SETTINGS_FIELDS.SettingsPageFeatures);
137
104
  boolean(features.reset);
138
105
  boolean(features.import);
@@ -141,30 +108,17 @@ function validatePage(
141
108
  boolean(features.confirmation);
142
109
  }
143
110
 
144
- function settingsLimits(value: unknown): Record<string, number> {
111
+ function settingsLimits(value: unknown): SettingsLimits {
145
112
  const limits = record(value, SETTINGS_FIELDS.SettingsLimits);
146
- const names = [
147
- "maximumModules",
148
- "maximumSections",
149
- "maximumPages",
150
- "maximumRenderers",
151
- "maximumScopes",
152
- "maximumApplyUnits",
153
- "maximumCapabilities",
154
- "maximumAnchorsPerPage",
155
- "maximumKeywordsPerPage",
156
- "maximumLabelBytes",
157
- "maximumKeywordBytes",
158
- "maximumOpaqueValueBytes",
159
- ] as const;
160
- for (const name of names) {
161
- positive(limits[name], "invalid_registry");
162
- }
163
- if (
164
- (limits.maximumOpaqueValueBytes as number) >
165
- HARD_MAXIMUM_OPAQUE_VALUE_BYTES
166
- ) {
113
+ assertPositiveLimits(limits);
114
+ if (limits.maximumOpaqueValueBytes > SETTINGS_HARD_MAXIMUM_OPAQUE_VALUE_BYTES) {
167
115
  incompatible("invalid_registry", limits.maximumOpaqueValueBytes);
168
116
  }
169
- return limits as Record<(typeof names)[number], number>;
117
+ return limits;
118
+ }
119
+
120
+ function assertPositiveLimits(limits: Record<string, unknown>): asserts limits is SettingsLimits {
121
+ for (const name of SETTINGS_FIELDS.SettingsLimits) {
122
+ positive(limits[name], "invalid_registry");
123
+ }
170
124
  }
@@ -15,10 +15,8 @@ import {
15
15
  assertValidSurfaceTransferResponse,
16
16
  } from "./validation.ts";
17
17
 
18
- export const TRANSFER_START_SURFACE_COMMAND =
19
- "longhorn_transfer_start_surface";
20
- export const TRANSFER_COMMIT_SURFACE_COMMAND =
21
- "longhorn_transfer_commit_surface";
18
+ export const TRANSFER_START_SURFACE_COMMAND = "longhorn_transfer_start_surface";
19
+ export const TRANSFER_COMMIT_SURFACE_COMMAND = "longhorn_transfer_commit_surface";
22
20
 
23
21
  export class SurfaceTransferClient {
24
22
  readonly #transport: InvokeTransport;
@@ -27,27 +25,17 @@ export class SurfaceTransferClient {
27
25
  this.#transport = transport;
28
26
  }
29
27
 
30
- async start(
31
- request: SurfaceSessionStartRequest,
32
- ): Promise<SurfaceSessionResponse> {
28
+ async start(request: SurfaceSessionStartRequest): Promise<SurfaceSessionResponse> {
33
29
  assertTransferProtocolVersion(request.protocol_version);
34
- const value = await this.#transport.invoke(
35
- TRANSFER_START_SURFACE_COMMAND,
36
- { request },
37
- );
30
+ const value = await this.#transport.invoke(TRANSFER_START_SURFACE_COMMAND, { request });
38
31
  assertValidSurfaceSessionResponse(value);
39
32
  return value;
40
33
  }
41
34
 
42
- async commit(
43
- request: SurfaceTransferCommand,
44
- ): Promise<SurfaceTransferResponse> {
35
+ async commit(request: SurfaceTransferCommand): Promise<SurfaceTransferResponse> {
45
36
  assertTransferProtocolVersion(request.protocol_version);
46
37
  assertValidTransferCommitSelector(request.selector);
47
- const value = await this.#transport.invoke(
48
- TRANSFER_COMMIT_SURFACE_COMMAND,
49
- { request },
50
- );
38
+ const value = await this.#transport.invoke(TRANSFER_COMMIT_SURFACE_COMMAND, { request });
51
39
  assertValidSurfaceTransferResponse(value);
52
40
  return value;
53
41
  }
@@ -1,12 +1,12 @@
1
- // @generated by `effigy generate:surface-transfer`; 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.
5
5
 
6
- export const SURFACE_TRANSFER_FIELDS: Record<string, readonly string[]> = {
6
+ export const SURFACE_TRANSFER_FIELDS = {
7
7
  "SurfaceSessionStartRequest": ["protocol_version", "request_id", "surface_id"],
8
8
  "SurfaceTransferCommand": ["protocol_version", "request_id", "session_id", "selector"],
9
9
  "SurfaceProvisioningCompletion": ["window_id", "host_binding_id", "display_id"],
10
10
  "SurfaceTransferCompletion": ["protocol_version", "request_id", "session_id", "source_host_binding_id", "target_host_binding_id", "previous_revision", "committed_revision", "authoritative_document", "target"],
11
11
  "SurfaceTransferAbort": ["protocol_version", "request_id", "source", "surface_code", "message", "retryable", "session_consumed", "reconciliation_required"],
12
- };
12
+ } as const;
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:surface-transfer`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority.
3
3
 
4
4
  import type { SurfaceDocument, SurfaceId, SurfaceMutationRejectionCode, SurfaceRevision } from "@inflatable-cookie/longhorn/surfaces";
@@ -8,11 +8,11 @@ export const SURFACE_TRANSFER_TARGET_KINDS = ["existing","provisioned"] as const
8
8
  export const SURFACE_TRANSFER_ABORT_DOMAINS = ["transfer","surface_transfer"] as const;
9
9
  export const SURFACE_SESSION_RESPONSE_STATUSES = ["started","aborted"] as const;
10
10
  export const SURFACE_TRANSFER_RESPONSE_STATUSES = ["committed","aborted"] as const;
11
- export const SURFACE_TRANSFER_ERROR_CODES = ["invalid_binding_snapshot","unknown_host_binding","stale_host_binding","surface_load_failed","surface_unavailable","unknown_surface","source_changed","unsupported_source","unsupported_target","cross_document","stale_surface_revision","ineligible_target","target_changed","invalid_insertion_position","empty_display_disabled","no_empty_display_target","ambiguous_empty_display_target","provision_failed","provision_receipt_mismatch","surface_mutation_rejected","publication_failed","host_reconciliation_required","transfer_rejected"] as const;
11
+ export const SURFACE_TRANSFER_ERROR_CODES = ["invalid_binding_snapshot","unknown_host_binding","stale_host_binding","surface_load_failed","surface_unavailable","unknown_surface","source_changed","unsupported_source","unsupported_target","cross_document","stale_surface_revision","ineligible_target","target_changed","invalid_insertion_position","empty_display_disabled","no_empty_display_target","provision_failed","provision_receipt_mismatch","surface_mutation_rejected","publication_failed","host_reconciliation_required","transfer_rejected"] as const;
12
12
 
13
13
  export type DisplayId = string;
14
14
 
15
- export type SurfaceTransferErrorCode = "invalid_binding_snapshot" | "unknown_host_binding" | "stale_host_binding" | "surface_load_failed" | "surface_unavailable" | "unknown_surface" | "source_changed" | "unsupported_source" | "unsupported_target" | "cross_document" | "stale_surface_revision" | "ineligible_target" | "target_changed" | "invalid_insertion_position" | "empty_display_disabled" | "no_empty_display_target" | "ambiguous_empty_display_target" | "provision_failed" | "provision_receipt_mismatch" | "surface_mutation_rejected" | "publication_failed" | "host_reconciliation_required" | "transfer_rejected";
15
+ export type SurfaceTransferErrorCode = "invalid_binding_snapshot" | "unknown_host_binding" | "stale_host_binding" | "surface_load_failed" | "surface_unavailable" | "unknown_surface" | "source_changed" | "unsupported_source" | "unsupported_target" | "cross_document" | "stale_surface_revision" | "ineligible_target" | "target_changed" | "invalid_insertion_position" | "empty_display_disabled" | "no_empty_display_target" | "provision_failed" | "provision_receipt_mismatch" | "surface_mutation_rejected" | "publication_failed" | "host_reconciliation_required" | "transfer_rejected";
16
16
 
17
17
  export type SurfaceSessionStartRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, surface_id: SurfaceId, };
18
18
 
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:surface-transfer`; 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.