@inflatable-cookie/longhorn 0.4.3 → 0.6.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.
- package/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +77 -105
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../../core/record.ts";
|
|
1
2
|
import {
|
|
2
3
|
NATIVE_CONTENT_VARIANT_FIELDS,
|
|
3
4
|
NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS,
|
|
@@ -21,7 +22,10 @@ const FORBIDDEN_KEYS = new Set([
|
|
|
21
22
|
]);
|
|
22
23
|
|
|
23
24
|
export class NativeContentProtocolValidationError extends Error {
|
|
24
|
-
constructor(
|
|
25
|
+
constructor(
|
|
26
|
+
readonly path: string,
|
|
27
|
+
message: string,
|
|
28
|
+
) {
|
|
25
29
|
super(`incompatible native-content protocol at ${path}: ${message}`);
|
|
26
30
|
this.name = "NativeContentProtocolValidationError";
|
|
27
31
|
}
|
|
@@ -43,55 +47,55 @@ export function assertProductPayloadFree(value: unknown): void {
|
|
|
43
47
|
export function exactObject(
|
|
44
48
|
value: unknown,
|
|
45
49
|
path: string,
|
|
46
|
-
keys:
|
|
50
|
+
keys: ReadonlyArray<string>,
|
|
47
51
|
): Record<string, unknown> {
|
|
48
52
|
const object = record(value, path);
|
|
49
53
|
exactKeys(object, path, keys);
|
|
50
54
|
return object;
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
export function record(
|
|
54
|
-
value
|
|
55
|
-
path: string,
|
|
56
|
-
): Record<string, unknown> {
|
|
57
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
57
|
+
export function record(value: unknown, path: string): Record<string, unknown> {
|
|
58
|
+
if (!isRecord(value)) {
|
|
58
59
|
fail(path, "expected object");
|
|
59
60
|
}
|
|
60
|
-
return value
|
|
61
|
+
return value;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export function exactKeys(
|
|
64
65
|
value: Record<string, unknown>,
|
|
65
66
|
path: string,
|
|
66
|
-
keys:
|
|
67
|
+
keys: ReadonlyArray<string>,
|
|
67
68
|
): void {
|
|
68
69
|
const expected = new Set(keys);
|
|
69
70
|
for (const key of Object.keys(value)) {
|
|
70
|
-
if (!expected.has(key))
|
|
71
|
+
if (!expected.has(key)) {
|
|
72
|
+
fail(`${path}.${key}`, "unknown field");
|
|
73
|
+
}
|
|
71
74
|
}
|
|
72
75
|
for (const key of keys) {
|
|
73
|
-
if (!(key in value))
|
|
76
|
+
if (!(key in value)) {
|
|
77
|
+
fail(`${path}.${key}`, "missing field");
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
export function member<const Value extends string>(
|
|
78
83
|
value: unknown,
|
|
79
|
-
values:
|
|
84
|
+
values: ReadonlyArray<Value>,
|
|
80
85
|
path: string,
|
|
81
86
|
): asserts value is Value {
|
|
82
|
-
if (typeof value !== "string" || !values.
|
|
87
|
+
if (typeof value !== "string" || !values.some((candidate) => candidate === value)) {
|
|
83
88
|
fail(path, `unknown value ${String(value)}`);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
export function text(value: unknown, path: string): asserts value is string {
|
|
88
|
-
if (typeof value !== "string")
|
|
93
|
+
if (typeof value !== "string") {
|
|
94
|
+
fail(path, "expected string");
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
export function opaqueId(
|
|
92
|
-
value: unknown,
|
|
93
|
-
path: string,
|
|
94
|
-
): asserts value is string {
|
|
98
|
+
export function opaqueId(value: unknown, path: string): asserts value is string {
|
|
95
99
|
text(value, path);
|
|
96
100
|
if (
|
|
97
101
|
value.length === 0 ||
|
|
@@ -102,45 +106,35 @@ export function opaqueId(
|
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
export function boolean(
|
|
106
|
-
value
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (typeof value !== "boolean") fail(path, "expected boolean");
|
|
109
|
+
export function boolean(value: unknown, path: string): asserts value is boolean {
|
|
110
|
+
if (typeof value !== "boolean") {
|
|
111
|
+
fail(path, "expected boolean");
|
|
112
|
+
}
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
export function finite(
|
|
113
|
-
value: unknown,
|
|
114
|
-
path: string,
|
|
115
|
-
): asserts value is number {
|
|
115
|
+
export function finite(value: unknown, path: string): asserts value is number {
|
|
116
116
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
117
117
|
fail(path, "expected finite number");
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function natural(
|
|
122
|
-
value
|
|
123
|
-
path: string,
|
|
124
|
-
): asserts value is number {
|
|
125
|
-
if (
|
|
126
|
-
typeof value !== "number" ||
|
|
127
|
-
!Number.isSafeInteger(value) ||
|
|
128
|
-
value < 0
|
|
129
|
-
) {
|
|
121
|
+
export function natural(value: unknown, path: string): asserts value is number {
|
|
122
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
130
123
|
fail(path, "expected non-negative safe integer");
|
|
131
124
|
}
|
|
132
125
|
}
|
|
133
126
|
|
|
134
|
-
export function positive(
|
|
135
|
-
value: unknown,
|
|
136
|
-
path: string,
|
|
137
|
-
): asserts value is number {
|
|
127
|
+
export function positive(value: unknown, path: string): asserts value is number {
|
|
138
128
|
natural(value, path);
|
|
139
|
-
if (value === 0)
|
|
129
|
+
if (value === 0) {
|
|
130
|
+
fail(path, "expected positive safe integer");
|
|
131
|
+
}
|
|
140
132
|
}
|
|
141
133
|
|
|
142
|
-
export function array(value: unknown, path: string):
|
|
143
|
-
if (!Array.isArray(value))
|
|
134
|
+
export function array(value: unknown, path: string): ReadonlyArray<unknown> {
|
|
135
|
+
if (!Array.isArray(value)) {
|
|
136
|
+
fail(path, "expected array");
|
|
137
|
+
}
|
|
144
138
|
return value;
|
|
145
139
|
}
|
|
146
140
|
|
|
@@ -149,7 +143,9 @@ export function nullable<T>(
|
|
|
149
143
|
path: string,
|
|
150
144
|
guard: (value: unknown, path: string) => asserts value is T,
|
|
151
145
|
): void {
|
|
152
|
-
if (value !== null)
|
|
146
|
+
if (value !== null) {
|
|
147
|
+
guard(value, path);
|
|
148
|
+
}
|
|
153
149
|
}
|
|
154
150
|
|
|
155
151
|
export function fail(path: string, message: string): never {
|
|
@@ -157,14 +153,20 @@ export function fail(path: string, message: string): never {
|
|
|
157
153
|
}
|
|
158
154
|
|
|
159
155
|
function visit(value: unknown, path: string, seen: Set<object>): void {
|
|
160
|
-
if (typeof value !== "object" || value === null)
|
|
161
|
-
|
|
156
|
+
if (typeof value !== "object" || value === null) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (seen.has(value)) {
|
|
160
|
+
fail(path, "cyclic value");
|
|
161
|
+
}
|
|
162
162
|
seen.add(value);
|
|
163
163
|
if (Array.isArray(value)) {
|
|
164
164
|
value.forEach((item, index) => visit(item, `${path}[${index}]`, seen));
|
|
165
165
|
} else {
|
|
166
166
|
for (const [key, item] of Object.entries(value)) {
|
|
167
|
-
if (FORBIDDEN_KEYS.has(key))
|
|
167
|
+
if (FORBIDDEN_KEYS.has(key)) {
|
|
168
|
+
fail(`${path}.${key}`, "product payload field");
|
|
169
|
+
}
|
|
168
170
|
visit(item, `${path}.${key}`, seen);
|
|
169
171
|
}
|
|
170
172
|
}
|
|
@@ -186,9 +188,14 @@ export function variantKeys(
|
|
|
186
188
|
type: string,
|
|
187
189
|
object: Record<string, unknown>,
|
|
188
190
|
path: string,
|
|
189
|
-
):
|
|
191
|
+
): ReadonlyArray<string> {
|
|
190
192
|
const discriminant = object[NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
191
|
-
const keys =
|
|
192
|
-
|
|
193
|
+
const keys =
|
|
194
|
+
typeof discriminant === "string"
|
|
195
|
+
? NATIVE_CONTENT_VARIANT_FIELDS[type]?.[discriminant]
|
|
196
|
+
: undefined;
|
|
197
|
+
if (keys === undefined) {
|
|
198
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
199
|
+
}
|
|
193
200
|
return keys;
|
|
194
201
|
}
|
|
@@ -7,14 +7,16 @@ import {
|
|
|
7
7
|
NATIVE_CONTENT_RETRY_CLASSES,
|
|
8
8
|
NATIVE_CONTENT_SNAPSHOT_STATUSES,
|
|
9
9
|
NATIVE_CONTENT_UPDATE_STATUSES,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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,
|
|
@@ -70,7 +72,11 @@ export function assertValidNativeContentDecisionRequest(
|
|
|
70
72
|
value: unknown,
|
|
71
73
|
): asserts value is NativeContentContentSizeDecisionRequest {
|
|
72
74
|
assertProductPayloadFree(value);
|
|
73
|
-
const object = exactObject(
|
|
75
|
+
const object = exactObject(
|
|
76
|
+
value,
|
|
77
|
+
"$",
|
|
78
|
+
NATIVE_CONTENT_FIELDS.NativeContentContentSizeDecisionRequest,
|
|
79
|
+
);
|
|
74
80
|
requestEnvelope(object);
|
|
75
81
|
positive(object.client_epoch, "$.client_epoch");
|
|
76
82
|
assertValidContentSizeProposal(object.proposal);
|
|
@@ -117,22 +123,12 @@ export function assertValidNativeContentDesiredUpdateResult(
|
|
|
117
123
|
member(object.status, NATIVE_CONTENT_UPDATE_STATUSES, "$.status");
|
|
118
124
|
responseCorrelation(object);
|
|
119
125
|
if (object.status === "committed") {
|
|
120
|
-
exactKeys(object, "$", [
|
|
121
|
-
"status",
|
|
122
|
-
"request_id",
|
|
123
|
-
"snapshot",
|
|
124
|
-
"receipt",
|
|
125
|
-
"event",
|
|
126
|
-
]);
|
|
126
|
+
exactKeys(object, "$", ["status", "request_id", "snapshot", "receipt", "event"]);
|
|
127
127
|
assertValidNativeContentSnapshot(object.snapshot);
|
|
128
128
|
desiredReceipt(object.receipt, "$.receipt");
|
|
129
129
|
assertValidNativeContentChangedEvent(object.event);
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
change.kind !== "desired_updated" ||
|
|
134
|
-
change.request_id !== object.request_id
|
|
135
|
-
) {
|
|
130
|
+
const change = object.event.change;
|
|
131
|
+
if (change.kind !== "desired_updated" || change.request_id !== object.request_id) {
|
|
136
132
|
fail("$.event.change", "desired update event correlation mismatch");
|
|
137
133
|
}
|
|
138
134
|
} else {
|
|
@@ -149,22 +145,12 @@ export function assertValidNativeContentDecisionResult(
|
|
|
149
145
|
member(object.status, NATIVE_CONTENT_DECISION_STATUSES, "$.status");
|
|
150
146
|
responseCorrelation(object);
|
|
151
147
|
if (object.status === "decided") {
|
|
152
|
-
exactKeys(object, "$", [
|
|
153
|
-
"status",
|
|
154
|
-
"request_id",
|
|
155
|
-
"snapshot",
|
|
156
|
-
"receipt",
|
|
157
|
-
"event",
|
|
158
|
-
]);
|
|
148
|
+
exactKeys(object, "$", ["status", "request_id", "snapshot", "receipt", "event"]);
|
|
159
149
|
assertValidNativeContentSnapshot(object.snapshot);
|
|
160
150
|
proposalReceipt(object.receipt, "$.receipt");
|
|
161
151
|
assertValidNativeContentChangedEvent(object.event);
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
if (
|
|
165
|
-
change.kind !== "content_size_decided" ||
|
|
166
|
-
change.request_id !== object.request_id
|
|
167
|
-
) {
|
|
152
|
+
const change = object.event.change;
|
|
153
|
+
if (change.kind !== "content_size_decided" || change.request_id !== object.request_id) {
|
|
168
154
|
fail("$.event.change", "content-size decision event correlation mismatch");
|
|
169
155
|
}
|
|
170
156
|
} 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
):
|
|
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)
|
|
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(
|
|
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):
|
|
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)
|
|
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 (
|
|
379
|
+
if (object.width < 0 || object.height < 0) {
|
|
382
380
|
fail(path, "contains negative extent");
|
|
383
381
|
}
|
|
384
382
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { CheckedSnapshotConnection
|
|
1
|
+
import { CheckedSnapshotConnection } 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,
|
|
@@ -6,31 +10,37 @@ import {
|
|
|
6
10
|
assertValidNotificationMutationResult,
|
|
7
11
|
assertValidNotificationSnapshotResponse,
|
|
8
12
|
} from "./validation.ts";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type NotificationSnapshotResponse,
|
|
13
|
+
import { NOTIFICATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
14
|
+
import type {
|
|
15
|
+
NotificationMutationCommand,
|
|
16
|
+
NotificationMutationResult,
|
|
17
|
+
NotificationSnapshot,
|
|
18
|
+
NotificationSnapshotResponse,
|
|
16
19
|
} from "./generated/protocol.ts";
|
|
17
20
|
import type { NotificationPort } from "./ports.ts";
|
|
18
21
|
|
|
19
22
|
export interface NotificationSubscription {
|
|
20
23
|
readonly ready: Promise<void>;
|
|
21
24
|
current(): NotificationSnapshot | undefined;
|
|
22
|
-
failures():
|
|
25
|
+
failures(): ReadonlyArray<ConnectionFailure>;
|
|
23
26
|
dispose(): Promise<void>;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export class NotificationClient {
|
|
27
30
|
constructor(readonly port: NotificationPort) {}
|
|
28
31
|
|
|
29
|
-
nextRequestId(): string {
|
|
32
|
+
nextRequestId(): string {
|
|
33
|
+
return this.port.nextRequestId();
|
|
34
|
+
}
|
|
30
35
|
|
|
31
36
|
async snapshot(offset = 0, limit = 100): Promise<NotificationSnapshotResponse> {
|
|
32
37
|
const requestId = this.port.nextRequestId();
|
|
33
|
-
const value = await this.port.snapshot({
|
|
38
|
+
const value = await this.port.snapshot({
|
|
39
|
+
protocolVersion: NOTIFICATION_PROTOCOL_VERSION,
|
|
40
|
+
requestId,
|
|
41
|
+
offset,
|
|
42
|
+
limit,
|
|
43
|
+
});
|
|
34
44
|
assertValidNotificationSnapshotResponse(value);
|
|
35
45
|
assertCorrelation(value.requestId, requestId);
|
|
36
46
|
return value;
|
|
@@ -44,14 +54,23 @@ export class NotificationClient {
|
|
|
44
54
|
return value;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
subscribe(
|
|
57
|
+
subscribe(
|
|
58
|
+
listener: (snapshot: NotificationSnapshot) => void,
|
|
59
|
+
onFailure?: ConnectionFailureReporter,
|
|
60
|
+
limit = 100,
|
|
61
|
+
): NotificationSubscription {
|
|
48
62
|
return new CheckedNotificationSubscription(this, this.port, listener, onFailure, limit);
|
|
49
63
|
}
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
export class NotificationResponseCorrelationError extends Error {
|
|
53
|
-
constructor(
|
|
54
|
-
|
|
67
|
+
constructor(
|
|
68
|
+
readonly expectedRequestId: string,
|
|
69
|
+
readonly receivedRequestId: string,
|
|
70
|
+
) {
|
|
71
|
+
super(
|
|
72
|
+
`notification response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`,
|
|
73
|
+
);
|
|
55
74
|
this.name = "NotificationResponseCorrelationError";
|
|
56
75
|
}
|
|
57
76
|
}
|
|
@@ -60,9 +79,15 @@ class CheckedNotificationSubscription implements NotificationSubscription {
|
|
|
60
79
|
readonly ready: Promise<void>;
|
|
61
80
|
readonly connection: CheckedSnapshotConnection<NotificationSnapshot>;
|
|
62
81
|
|
|
63
|
-
constructor(
|
|
82
|
+
constructor(
|
|
83
|
+
client: NotificationClient,
|
|
84
|
+
port: NotificationPort,
|
|
85
|
+
listener: (snapshot: NotificationSnapshot) => void,
|
|
86
|
+
onFailure: ConnectionFailureReporter | undefined,
|
|
87
|
+
limit: number,
|
|
88
|
+
) {
|
|
64
89
|
this.connection = new CheckedSnapshotConnection({
|
|
65
|
-
listen: async (receive) => port.listen === undefined ? () => {} : port.listen(receive),
|
|
90
|
+
listen: async (receive) => (port.listen === undefined ? () => {} : port.listen(receive)),
|
|
66
91
|
loadSnapshot: async () => (await client.snapshot(0, limit)).snapshot,
|
|
67
92
|
validateSnapshot: parseSnapshot,
|
|
68
93
|
handleEvent: notificationEventAction,
|
|
@@ -73,34 +98,65 @@ class CheckedNotificationSubscription implements NotificationSubscription {
|
|
|
73
98
|
this.ready = this.connection.ready.then(() => undefined);
|
|
74
99
|
}
|
|
75
100
|
|
|
76
|
-
current(): NotificationSnapshot | undefined {
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
current(): NotificationSnapshot | undefined {
|
|
102
|
+
return this.connection.current();
|
|
103
|
+
}
|
|
104
|
+
failures(): ReadonlyArray<ConnectionFailure> {
|
|
105
|
+
return this.connection.failures();
|
|
106
|
+
}
|
|
107
|
+
dispose(): Promise<void> {
|
|
108
|
+
return this.connection.dispose();
|
|
109
|
+
}
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
function parseSnapshot(value: unknown): NotificationSnapshot {
|
|
82
113
|
const response = { requestId: "request:validation", snapshot: value };
|
|
83
114
|
assertValidNotificationSnapshotResponse(response);
|
|
84
|
-
return
|
|
115
|
+
return response.snapshot;
|
|
85
116
|
}
|
|
86
117
|
|
|
87
|
-
export function notificationEventAction(
|
|
118
|
+
export function notificationEventAction(
|
|
119
|
+
value: unknown,
|
|
120
|
+
current: NotificationSnapshot | undefined,
|
|
121
|
+
): { kind: "ignore" } | { kind: "refresh" } {
|
|
88
122
|
assertValidNotificationChangedEvent(value);
|
|
89
|
-
const event = value
|
|
90
|
-
if (current === undefined)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (event.authority.
|
|
123
|
+
const event = value;
|
|
124
|
+
if (current === undefined) {
|
|
125
|
+
return { kind: "refresh" };
|
|
126
|
+
}
|
|
127
|
+
if (event.authority.authorityId !== current.authority.authorityId) {
|
|
128
|
+
return { kind: "ignore" };
|
|
129
|
+
}
|
|
130
|
+
if (event.authority.authorityEpoch < current.authority.authorityEpoch) {
|
|
131
|
+
return { kind: "ignore" };
|
|
132
|
+
}
|
|
133
|
+
if (
|
|
134
|
+
event.authority.authorityEpoch === current.authority.authorityEpoch &&
|
|
135
|
+
event.committedLedgerRevision <= current.ledgerRevision
|
|
136
|
+
) {
|
|
137
|
+
return { kind: "ignore" };
|
|
138
|
+
}
|
|
94
139
|
return { kind: "refresh" };
|
|
95
140
|
}
|
|
96
141
|
|
|
97
|
-
export function isNewerNotificationSnapshot(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
142
|
+
export function isNewerNotificationSnapshot(
|
|
143
|
+
candidate: NotificationSnapshot,
|
|
144
|
+
current: NotificationSnapshot | undefined,
|
|
145
|
+
): boolean {
|
|
146
|
+
if (current === undefined) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (candidate.authority.authorityId !== current.authority.authorityId) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) {
|
|
153
|
+
return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
|
|
154
|
+
}
|
|
101
155
|
return candidate.ledgerRevision > current.ledgerRevision;
|
|
102
156
|
}
|
|
103
157
|
|
|
104
158
|
function assertCorrelation(received: string, expected: string): void {
|
|
105
|
-
if (received !== expected)
|
|
159
|
+
if (received !== expected) {
|
|
160
|
+
throw new NotificationResponseCorrelationError(expected, received);
|
|
161
|
+
}
|
|
106
162
|
}
|