@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,4 +1,4 @@
1
- // @generated by `effigy generate:native-content`; 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.
@@ -1,3 +1,4 @@
1
+ import type { Unlisten } from "../core/transport.ts";
1
2
  import type {
2
3
  NativeContentChangedEvent,
3
4
  NativeContentConnectRequest,
@@ -11,36 +12,30 @@ import type {
11
12
  NativeContentSnapshotResult,
12
13
  } from "./generated/protocol.ts";
13
14
 
14
- export type NativeContentUnlisten = () => void | Promise<void>;
15
+ export type NativeContentUnlisten = Unlisten;
15
16
 
16
17
  export interface NativeContentPort {
17
18
  connect(request: NativeContentConnectRequest): Promise<unknown>;
18
19
  snapshot(request: NativeContentSnapshotRequest): Promise<unknown>;
19
20
  updateDesired(request: NativeContentDesiredUpdateRequest): Promise<unknown>;
20
- decideContentSize(
21
- request: NativeContentContentSizeDecisionRequest,
22
- ): Promise<unknown>;
23
- listen?(
24
- listener: (event: unknown) => void,
25
- ): NativeContentUnlisten | Promise<NativeContentUnlisten>;
21
+ decideContentSize(request: NativeContentContentSizeDecisionRequest): Promise<unknown>;
22
+ listen?:
23
+ | ((
24
+ listener: (event: unknown) => void,
25
+ ) => NativeContentUnlisten | Promise<NativeContentUnlisten>)
26
+ | undefined;
26
27
  nextRequestId(): NativeContentRequestId;
27
28
  }
28
29
 
29
30
  export interface CheckedNativeContentPort {
30
- connect(
31
- request: NativeContentConnectRequest,
32
- ): Promise<NativeContentConnectResult>;
33
- snapshot(
34
- request: NativeContentSnapshotRequest,
35
- ): Promise<NativeContentSnapshotResult>;
31
+ connect(request: NativeContentConnectRequest): Promise<NativeContentConnectResult>;
32
+ snapshot(request: NativeContentSnapshotRequest): Promise<NativeContentSnapshotResult>;
36
33
  updateDesired(
37
34
  request: NativeContentDesiredUpdateRequest,
38
35
  ): Promise<NativeContentDesiredUpdateResult>;
39
36
  decideContentSize(
40
37
  request: NativeContentContentSizeDecisionRequest,
41
38
  ): Promise<NativeContentContentSizeDecisionResult>;
42
- listen?(
43
- listener: (event: NativeContentChangedEvent) => void,
44
- ): Promise<NativeContentUnlisten>;
39
+ listen?(listener: (event: NativeContentChangedEvent) => void): Promise<NativeContentUnlisten>;
45
40
  nextRequestId(): NativeContentRequestId;
46
41
  }
@@ -1,3 +1,4 @@
1
+ import { wireCopy } from "../core/wire-copy.ts";
1
2
  import type {
2
3
  NativeContentConnectRequest,
3
4
  NativeContentContentSizeDecisionRequest,
@@ -14,37 +15,29 @@ export class SerializedNativeContentPort implements NativeContentPort {
14
15
  }
15
16
 
16
17
  async connect(request: NativeContentConnectRequest): Promise<unknown> {
17
- return clone(await this.#inner.connect(clone(request)));
18
+ return wireCopy(await this.#inner.connect(wireCopy(request)));
18
19
  }
19
20
 
20
21
  async snapshot(request: NativeContentSnapshotRequest): Promise<unknown> {
21
- return clone(await this.#inner.snapshot(clone(request)));
22
+ return wireCopy(await this.#inner.snapshot(wireCopy(request)));
22
23
  }
23
24
 
24
- async updateDesired(
25
- request: NativeContentDesiredUpdateRequest,
26
- ): Promise<unknown> {
27
- return clone(await this.#inner.updateDesired(clone(request)));
25
+ async updateDesired(request: NativeContentDesiredUpdateRequest): Promise<unknown> {
26
+ return wireCopy(await this.#inner.updateDesired(wireCopy(request)));
28
27
  }
29
28
 
30
- async decideContentSize(
31
- request: NativeContentContentSizeDecisionRequest,
32
- ): Promise<unknown> {
33
- return clone(await this.#inner.decideContentSize(clone(request)));
29
+ async decideContentSize(request: NativeContentContentSizeDecisionRequest): Promise<unknown> {
30
+ return wireCopy(await this.#inner.decideContentSize(wireCopy(request)));
34
31
  }
35
32
 
36
- async listen(
37
- listener: (event: unknown) => void,
38
- ): Promise<NativeContentUnlisten> {
39
- if (this.#inner.listen === undefined) return () => {};
40
- return this.#inner.listen((event) => listener(clone(event)));
33
+ async listen(listener: (event: unknown) => void): Promise<NativeContentUnlisten> {
34
+ if (this.#inner.listen === undefined) {
35
+ return () => {};
36
+ }
37
+ return this.#inner.listen((event) => listener(wireCopy(event)));
41
38
  }
42
39
 
43
40
  nextRequestId(): string {
44
41
  return this.#inner.nextRequestId();
45
42
  }
46
43
  }
47
-
48
- function clone<Value>(value: Value): Value {
49
- return JSON.parse(JSON.stringify(value)) as Value;
50
- }
@@ -1,11 +1,10 @@
1
+ import { isOpaqueId } from "../../core/identifiers.ts";
2
+ import { checkWireFields, readWireRecord, wireVariantFields } from "../../core/record.ts";
1
3
  import {
2
4
  NATIVE_CONTENT_VARIANT_FIELDS,
3
5
  NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS,
4
6
  } from "../generated/variant-fields.ts";
5
- import {
6
- NATIVE_CONTENT_MAXIMUM_OPAQUE_ID_BYTES,
7
- NATIVE_CONTENT_PROTOCOL_VERSION,
8
- } from "../generated/protocol.ts";
7
+ import { NATIVE_CONTENT_PROTOCOL_VERSION } from "../generated/protocol.ts";
9
8
 
10
9
  const FORBIDDEN_KEYS = new Set([
11
10
  "payload",
@@ -21,7 +20,10 @@ const FORBIDDEN_KEYS = new Set([
21
20
  ]);
22
21
 
23
22
  export class NativeContentProtocolValidationError extends Error {
24
- constructor(readonly path: string, message: string) {
23
+ constructor(
24
+ readonly path: string,
25
+ message: string,
26
+ ) {
25
27
  super(`incompatible native-content protocol at ${path}: ${message}`);
26
28
  this.name = "NativeContentProtocolValidationError";
27
29
  }
@@ -43,104 +45,79 @@ export function assertProductPayloadFree(value: unknown): void {
43
45
  export function exactObject(
44
46
  value: unknown,
45
47
  path: string,
46
- keys: readonly string[],
48
+ keys: ReadonlyArray<string>,
47
49
  ): Record<string, unknown> {
48
50
  const object = record(value, path);
49
51
  exactKeys(object, path, keys);
50
52
  return object;
51
53
  }
52
54
 
53
- export function record(
54
- value: unknown,
55
- path: string,
56
- ): Record<string, unknown> {
57
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
58
- fail(path, "expected object");
59
- }
60
- return value as Record<string, unknown>;
55
+ export function record(value: unknown, path: string): Record<string, unknown> {
56
+ const result = readWireRecord(value, () => fail(path, "expected object"));
57
+ return result;
61
58
  }
62
59
 
63
60
  export function exactKeys(
64
61
  value: Record<string, unknown>,
65
62
  path: string,
66
- keys: readonly string[],
63
+ keys: ReadonlyArray<string>,
67
64
  ): void {
68
- const expected = new Set(keys);
69
- for (const key of Object.keys(value)) {
70
- if (!expected.has(key)) fail(`${path}.${key}`, "unknown field");
71
- }
72
- for (const key of keys) {
73
- if (!(key in value)) fail(`${path}.${key}`, "missing field");
74
- }
65
+ checkWireFields(value, keys, (code, key) =>
66
+ fail(`${path}.${key}`, code === "unknown_field" ? "unknown field" : "missing field"),
67
+ );
75
68
  }
76
69
 
77
70
  export function member<const Value extends string>(
78
71
  value: unknown,
79
- values: readonly Value[],
72
+ values: ReadonlyArray<Value>,
80
73
  path: string,
81
74
  ): asserts value is Value {
82
- if (typeof value !== "string" || !values.includes(value as Value)) {
75
+ if (typeof value !== "string" || !values.some((candidate) => candidate === value)) {
83
76
  fail(path, `unknown value ${String(value)}`);
84
77
  }
85
78
  }
86
79
 
87
80
  export function text(value: unknown, path: string): asserts value is string {
88
- if (typeof value !== "string") fail(path, "expected string");
81
+ if (typeof value !== "string") {
82
+ fail(path, "expected string");
83
+ }
89
84
  }
90
85
 
91
- export function opaqueId(
92
- value: unknown,
93
- path: string,
94
- ): asserts value is string {
95
- text(value, path);
96
- if (
97
- value.length === 0 ||
98
- value.length > NATIVE_CONTENT_MAXIMUM_OPAQUE_ID_BYTES ||
99
- !/^[a-z0-9._:-]+$/.test(value)
100
- ) {
86
+ export function opaqueId(value: unknown, path: string): asserts value is string {
87
+ if (!isOpaqueId(value)) {
101
88
  fail(path, "invalid bounded opaque id");
102
89
  }
103
90
  }
104
91
 
105
- export function boolean(
106
- value: unknown,
107
- path: string,
108
- ): asserts value is boolean {
109
- if (typeof value !== "boolean") fail(path, "expected boolean");
92
+ export function boolean(value: unknown, path: string): asserts value is boolean {
93
+ if (typeof value !== "boolean") {
94
+ fail(path, "expected boolean");
95
+ }
110
96
  }
111
97
 
112
- export function finite(
113
- value: unknown,
114
- path: string,
115
- ): asserts value is number {
98
+ export function finite(value: unknown, path: string): asserts value is number {
116
99
  if (typeof value !== "number" || !Number.isFinite(value)) {
117
100
  fail(path, "expected finite number");
118
101
  }
119
102
  }
120
103
 
121
- export function natural(
122
- value: unknown,
123
- path: string,
124
- ): asserts value is number {
125
- if (
126
- typeof value !== "number" ||
127
- !Number.isSafeInteger(value) ||
128
- value < 0
129
- ) {
104
+ export function natural(value: unknown, path: string): asserts value is number {
105
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
130
106
  fail(path, "expected non-negative safe integer");
131
107
  }
132
108
  }
133
109
 
134
- export function positive(
135
- value: unknown,
136
- path: string,
137
- ): asserts value is number {
110
+ export function positive(value: unknown, path: string): asserts value is number {
138
111
  natural(value, path);
139
- if (value === 0) fail(path, "expected positive safe integer");
112
+ if (value === 0) {
113
+ fail(path, "expected positive safe integer");
114
+ }
140
115
  }
141
116
 
142
- export function array(value: unknown, path: string): readonly unknown[] {
143
- if (!Array.isArray(value)) fail(path, "expected array");
117
+ export function array(value: unknown, path: string): ReadonlyArray<unknown> {
118
+ if (!Array.isArray(value)) {
119
+ fail(path, "expected array");
120
+ }
144
121
  return value;
145
122
  }
146
123
 
@@ -149,7 +126,9 @@ export function nullable<T>(
149
126
  path: string,
150
127
  guard: (value: unknown, path: string) => asserts value is T,
151
128
  ): void {
152
- if (value !== null) guard(value, path);
129
+ if (value !== null) {
130
+ guard(value, path);
131
+ }
153
132
  }
154
133
 
155
134
  export function fail(path: string, message: string): never {
@@ -157,38 +136,36 @@ export function fail(path: string, message: string): never {
157
136
  }
158
137
 
159
138
  function visit(value: unknown, path: string, seen: Set<object>): void {
160
- if (typeof value !== "object" || value === null) return;
161
- if (seen.has(value)) fail(path, "cyclic value");
139
+ if (typeof value !== "object" || value === null) {
140
+ return;
141
+ }
142
+ if (seen.has(value)) {
143
+ fail(path, "cyclic value");
144
+ }
162
145
  seen.add(value);
163
146
  if (Array.isArray(value)) {
164
147
  value.forEach((item, index) => visit(item, `${path}[${index}]`, seen));
165
148
  } else {
166
149
  for (const [key, item] of Object.entries(value)) {
167
- if (FORBIDDEN_KEYS.has(key)) fail(`${path}.${key}`, "product payload field");
150
+ if (FORBIDDEN_KEYS.has(key)) {
151
+ fail(`${path}.${key}`, "product payload field");
152
+ }
168
153
  visit(item, `${path}.${key}`, seen);
169
154
  }
170
155
  }
171
156
  seen.delete(value);
172
157
  }
173
158
 
174
- /**
175
- * Allowed keys for one tagged-union variant, from the generated map.
176
- *
177
- * The discriminant's *name* comes from the generated map too: this domain
178
- * uses `kind`, `status` and `state`, and a call site that has to name the
179
- * right one is a per-site chance to name the wrong one.
180
- *
181
- * A missing entry means the generator failed to read the union, not that a
182
- * caller sent something odd — every switch checks the discriminant above this
183
- * call. Failing loudly beats a hand-written list, which is what these were.
184
- */
185
159
  export function variantKeys(
186
160
  type: string,
187
161
  object: Record<string, unknown>,
188
162
  path: string,
189
- ): readonly string[] {
190
- const discriminant = object[NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
191
- const keys = NATIVE_CONTENT_VARIANT_FIELDS[type]?.[discriminant as string];
192
- if (keys === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
193
- return keys;
163
+ ): ReadonlyArray<string> {
164
+ return wireVariantFields(
165
+ NATIVE_CONTENT_VARIANT_FIELDS,
166
+ NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS,
167
+ type,
168
+ object,
169
+ (discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
170
+ );
194
171
  }
@@ -7,14 +7,16 @@ import {
7
7
  NATIVE_CONTENT_RETRY_CLASSES,
8
8
  NATIVE_CONTENT_SNAPSHOT_STATUSES,
9
9
  NATIVE_CONTENT_UPDATE_STATUSES,
10
- type NativeContentConnectRequest,
11
- type NativeContentConnectResult,
12
- type NativeContentContentSizeDecisionRequest,
13
- type NativeContentContentSizeDecisionResult,
14
- type NativeContentDesiredUpdateRequest,
15
- type NativeContentDesiredUpdateResult,
16
- type NativeContentSnapshotRequest,
17
- type NativeContentSnapshotResult,
10
+ } from "../generated/protocol.ts";
11
+ import type {
12
+ NativeContentConnectRequest,
13
+ NativeContentConnectResult,
14
+ NativeContentContentSizeDecisionRequest,
15
+ NativeContentContentSizeDecisionResult,
16
+ NativeContentDesiredUpdateRequest,
17
+ NativeContentDesiredUpdateResult,
18
+ NativeContentSnapshotRequest,
19
+ NativeContentSnapshotResult,
18
20
  } from "../generated/protocol.ts";
19
21
  import {
20
22
  assertNativeContentProtocolVersion,
@@ -52,6 +54,7 @@ export function assertValidNativeContentSnapshotRequest(
52
54
  ): asserts value is NativeContentSnapshotRequest {
53
55
  const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentSnapshotRequest);
54
56
  requestEnvelope(object);
57
+ positive(object.authority_epoch, "$.authority_epoch");
55
58
  positive(object.client_epoch, "$.client_epoch");
56
59
  }
57
60
 
@@ -61,6 +64,7 @@ export function assertValidNativeContentDesiredUpdateRequest(
61
64
  assertProductPayloadFree(value);
62
65
  const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentDesiredUpdateRequest);
63
66
  requestEnvelope(object);
67
+ positive(object.authority_epoch, "$.authority_epoch");
64
68
  positive(object.client_epoch, "$.client_epoch");
65
69
  natural(object.expected_desired_revision, "$.expected_desired_revision");
66
70
  assertValidDesiredUpdate(object.update);
@@ -70,8 +74,13 @@ export function assertValidNativeContentDecisionRequest(
70
74
  value: unknown,
71
75
  ): asserts value is NativeContentContentSizeDecisionRequest {
72
76
  assertProductPayloadFree(value);
73
- const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentContentSizeDecisionRequest);
77
+ const object = exactObject(
78
+ value,
79
+ "$",
80
+ NATIVE_CONTENT_FIELDS.NativeContentContentSizeDecisionRequest,
81
+ );
74
82
  requestEnvelope(object);
83
+ positive(object.authority_epoch, "$.authority_epoch");
75
84
  positive(object.client_epoch, "$.client_epoch");
76
85
  assertValidContentSizeProposal(object.proposal);
77
86
  assertValidContentSizeDecision(object.decision);
@@ -117,22 +126,12 @@ export function assertValidNativeContentDesiredUpdateResult(
117
126
  member(object.status, NATIVE_CONTENT_UPDATE_STATUSES, "$.status");
118
127
  responseCorrelation(object);
119
128
  if (object.status === "committed") {
120
- exactKeys(object, "$", [
121
- "status",
122
- "request_id",
123
- "snapshot",
124
- "receipt",
125
- "event",
126
- ]);
129
+ exactKeys(object, "$", ["status", "request_id", "snapshot", "receipt", "event"]);
127
130
  assertValidNativeContentSnapshot(object.snapshot);
128
131
  desiredReceipt(object.receipt, "$.receipt");
129
132
  assertValidNativeContentChangedEvent(object.event);
130
- const event = object.event as Record<string, unknown>;
131
- const change = event.change as Record<string, unknown>;
132
- if (
133
- change.kind !== "desired_updated" ||
134
- change.request_id !== object.request_id
135
- ) {
133
+ const change = object.event.change;
134
+ if (change.kind !== "desired_updated" || change.request_id !== object.request_id) {
136
135
  fail("$.event.change", "desired update event correlation mismatch");
137
136
  }
138
137
  } else {
@@ -149,22 +148,12 @@ export function assertValidNativeContentDecisionResult(
149
148
  member(object.status, NATIVE_CONTENT_DECISION_STATUSES, "$.status");
150
149
  responseCorrelation(object);
151
150
  if (object.status === "decided") {
152
- exactKeys(object, "$", [
153
- "status",
154
- "request_id",
155
- "snapshot",
156
- "receipt",
157
- "event",
158
- ]);
151
+ exactKeys(object, "$", ["status", "request_id", "snapshot", "receipt", "event"]);
159
152
  assertValidNativeContentSnapshot(object.snapshot);
160
153
  proposalReceipt(object.receipt, "$.receipt");
161
154
  assertValidNativeContentChangedEvent(object.event);
162
- const event = object.event as Record<string, unknown>;
163
- const change = event.change as Record<string, unknown>;
164
- if (
165
- change.kind !== "content_size_decided" ||
166
- change.request_id !== object.request_id
167
- ) {
155
+ const change = object.event.change;
156
+ if (change.kind !== "content_size_decided" || change.request_id !== object.request_id) {
168
157
  fail("$.event.change", "content-size decision event correlation mismatch");
169
158
  }
170
159
  } else {
@@ -16,12 +16,14 @@ import {
16
16
  NATIVE_CONTENT_OPERATION_OUTCOME_KINDS,
17
17
  NATIVE_CONTENT_READINESS_STATES,
18
18
  NATIVE_CONTENT_SIZE_DECISION_KINDS,
19
- type ContentSizeDecision,
20
- type ContentSizeProposal,
21
- type DesiredUpdate,
22
- type NativeContentChangedEvent,
23
- type NativeContentCursor,
24
- type NativeContentSnapshot,
19
+ } from "../generated/protocol.ts";
20
+ import type {
21
+ ContentSizeDecision,
22
+ ContentSizeProposal,
23
+ DesiredUpdate,
24
+ NativeContentChangedEvent,
25
+ NativeContentCursor,
26
+ NativeContentSnapshot,
25
27
  } from "../generated/protocol.ts";
26
28
  import {
27
29
  array,
@@ -48,12 +50,10 @@ export function assertValidNativeContentSnapshot(
48
50
  const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentSnapshot);
49
51
  assertNativeContentProtocolVersion(object.protocol_version);
50
52
  cursor(object.cursor, "$.cursor");
51
- desiredState(object.desired, "$.desired");
52
- observedState(object.observed, "$.observed");
53
+ const desired = desiredUpdate(object.desired, "$.desired", true);
54
+ const observed = observedState(object.observed, "$.observed");
53
55
  nullable(object.invalidated_generation, "$.invalidated_generation", positive);
54
- const desired = object.desired as Record<string, unknown>;
55
- const observed = object.observed as Record<string, unknown>;
56
- const valueCursor = object.cursor as Record<string, unknown>;
56
+ const valueCursor = object.cursor;
57
57
  if (
58
58
  desired.island_id !== valueCursor.island_id ||
59
59
  desired.generation !== valueCursor.attach_generation ||
@@ -74,9 +74,7 @@ export function assertValidNativeContentChangedEvent(
74
74
  change(object.change, "$.change");
75
75
  }
76
76
 
77
- export function assertValidDesiredUpdate(
78
- value: unknown,
79
- ): asserts value is DesiredUpdate {
77
+ export function assertValidDesiredUpdate(value: unknown): asserts value is DesiredUpdate {
80
78
  desiredUpdate(value, "$", false);
81
79
  }
82
80
 
@@ -102,20 +100,14 @@ export function cursor(value: unknown, path: string): asserts value is NativeCon
102
100
  natural(object.observed_revision, `${path}.observed_revision`);
103
101
  }
104
102
 
105
- export function proposal(
106
- value: unknown,
107
- path: string,
108
- ): asserts value is ContentSizeProposal {
103
+ export function proposal(value: unknown, path: string): asserts value is ContentSizeProposal {
109
104
  const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ContentSizeProposal);
110
105
  positive(object.generation, `${path}.generation`);
111
106
  natural(object.desired_revision, `${path}.desired_revision`);
112
107
  clientSize(object.size, `${path}.size`);
113
108
  }
114
109
 
115
- export function decision(
116
- value: unknown,
117
- path: string,
118
- ): asserts value is ContentSizeDecision {
110
+ export function decision(value: unknown, path: string): asserts value is ContentSizeDecision {
119
111
  const object = record(value, path);
120
112
  member(object.kind, NATIVE_CONTENT_SIZE_DECISION_KINDS, `${path}.kind`);
121
113
  if (object.kind === "accepted") {
@@ -133,7 +125,7 @@ export function desiredUpdate(
133
125
  value: unknown,
134
126
  path: string,
135
127
  includeIdentity: boolean,
136
- ): void {
128
+ ): Record<string, unknown> {
137
129
  const keys = [
138
130
  "generation",
139
131
  "host_window_id",
@@ -145,7 +137,9 @@ export function desiredUpdate(
145
137
  "focus",
146
138
  "input_routing",
147
139
  ];
148
- if (includeIdentity) keys.unshift("island_id", "kind_id", "capabilities", "revision");
140
+ if (includeIdentity) {
141
+ keys.unshift("island_id", "kind_id", "capabilities", "revision");
142
+ }
149
143
  const object = exactObject(value, path, keys);
150
144
  if (includeIdentity) {
151
145
  opaqueId(object.island_id, `${path}.island_id`);
@@ -162,16 +156,17 @@ export function desiredUpdate(
162
156
  desiredVisibility(object.visibility, `${path}.visibility`);
163
157
  member(object.focus, NATIVE_CONTENT_FOCUS_INTENTS, `${path}.focus`);
164
158
  member(object.input_routing, NATIVE_CONTENT_INPUT_ROUTING_MODES, `${path}.input_routing`);
165
- }
166
-
167
- function desiredState(value: unknown, path: string): void {
168
- desiredUpdate(value, path, true);
159
+ return object;
169
160
  }
170
161
 
171
162
  function capabilities(value: unknown, path: string): void {
172
163
  const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.MechanismCapabilities);
173
164
  member(object.mechanism, NATIVE_CONTENT_MECHANISMS, `${path}.mechanism`);
174
- member(object.active_input_routing, NATIVE_CONTENT_INPUT_ROUTING_MODES, `${path}.active_input_routing`);
165
+ member(
166
+ object.active_input_routing,
167
+ NATIVE_CONTENT_INPUT_ROUTING_MODES,
168
+ `${path}.active_input_routing`,
169
+ );
175
170
  boolean(object.accepts_content_size_requests, `${path}.accepts_content_size_requests`);
176
171
  member(object.detach_policy, NATIVE_CONTENT_DETACH_POLICIES, `${path}.detach_policy`);
177
172
  boolean(object.observes_visibility, `${path}.observes_visibility`);
@@ -189,7 +184,7 @@ function desiredVisibility(value: unknown, path: string): void {
189
184
  }
190
185
  }
191
186
 
192
- function observedState(value: unknown, path: string): void {
187
+ function observedState(value: unknown, path: string): Record<string, unknown> {
193
188
  const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ObservedState);
194
189
  natural(object.revision, `${path}.revision`);
195
190
  positive(object.generation, `${path}.generation`);
@@ -199,8 +194,9 @@ function observedState(value: unknown, path: string): void {
199
194
  member(object.focus, NATIVE_CONTENT_EFFECTIVE_FOCUS_STATES, `${path}.focus`);
200
195
  observedGeometry(object.geometry, `${path}.geometry`);
201
196
  nullable(object.input_routing, `${path}.input_routing`, (candidate, candidatePath) =>
202
- member(candidate, NATIVE_CONTENT_INPUT_ROUTING_MODES, candidatePath)
197
+ member(candidate, NATIVE_CONTENT_INPUT_ROUTING_MODES, candidatePath),
203
198
  );
199
+ return object;
204
200
  }
205
201
 
206
202
  function observedGeometry(value: unknown, path: string): void {
@@ -300,7 +296,9 @@ function applyReceipt(value: unknown, path: string): void {
300
296
  natural(object.observed_revision, `${path}.observed_revision`);
301
297
  positive(object.generation, `${path}.generation`);
302
298
  const steps = array(object.steps, `${path}.steps`);
303
- if (steps.length > 5) fail(`${path}.steps`, "apply receipt exceeds five steps");
299
+ if (steps.length > 5) {
300
+ fail(`${path}.steps`, "apply receipt exceeds five steps");
301
+ }
304
302
  steps.forEach((step, index) => stepReceipt(step, `${path}.steps[${index}]`));
305
303
  }
306
304
 
@@ -378,7 +376,7 @@ function clientSize(value: unknown, path: string): void {
378
376
  const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.ClientSize);
379
377
  finite(object.width, `${path}.width`);
380
378
  finite(object.height, `${path}.height`);
381
- if ((object.width as number) < 0 || (object.height as number) < 0) {
379
+ if (object.width < 0 || object.height < 0) {
382
380
  fail(path, "contains negative extent");
383
381
  }
384
382
  }