@inflatable-cookie/longhorn 0.1.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/LICENSE +21 -0
- package/README.md +38 -0
- package/package.json +205 -0
- package/src/agent-control/index.ts +20 -0
- package/src/agent-control/inject.ts +4 -0
- package/src/agent-control/shim.ts +722 -0
- package/src/bridge/direct.ts +22 -0
- package/src/bridge/generated/fields.ts +32 -0
- package/src/bridge/generated/protocol.ts +218 -0
- package/src/bridge/generated/variant-fields.ts +10 -0
- package/src/bridge/index.ts +15 -0
- package/src/bridge/job.ts +51 -0
- package/src/bridge/loopback.ts +84 -0
- package/src/bridge/operation.ts +166 -0
- package/src/bridge/router.ts +71 -0
- package/src/bridge/runtime/connection.ts +318 -0
- package/src/bridge/runtime/policy.ts +89 -0
- package/src/bridge/runtime/retry.ts +60 -0
- package/src/bridge/runtime.ts +3 -0
- package/src/bridge/session.ts +67 -0
- package/src/bridge/stream/connection.ts +146 -0
- package/src/bridge/stream/source.ts +61 -0
- package/src/bridge/stream/tracker.ts +109 -0
- package/src/bridge/stream.ts +6 -0
- package/src/bridge/supervision.ts +204 -0
- package/src/bridge/validation/base.ts +164 -0
- package/src/bridge/validation/jobs.ts +105 -0
- package/src/bridge/validation/negotiation.ts +242 -0
- package/src/bridge/validation/operations.ts +213 -0
- package/src/bridge/validation/streams.ts +47 -0
- package/src/bridge/validation.ts +5 -0
- package/src/commands/client.ts +124 -0
- package/src/commands/controller.ts +411 -0
- package/src/commands/generated/fields.ts +43 -0
- package/src/commands/generated/protocol.ts +876 -0
- package/src/commands/generated/variant-fields.ts +88 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/keyboard.ts +361 -0
- package/src/commands/ports.ts +82 -0
- package/src/commands/projectors.ts +306 -0
- package/src/commands/validation.ts +444 -0
- package/src/config/client.ts +215 -0
- package/src/config/generated/base.ts +714 -0
- package/src/config/generated/fields.ts +54 -0
- package/src/config/generated/label-template.ts +14 -0
- package/src/config/generated/labels.ts +30 -0
- package/src/config/generated/protocol.ts +3 -0
- package/src/config/generated/restore.ts +658 -0
- package/src/config/generated/variant-fields.ts +129 -0
- package/src/config/index.ts +12 -0
- package/src/config/names.ts +19 -0
- package/src/config/validation/commands.ts +155 -0
- package/src/config/validation/outcomes.ts +243 -0
- package/src/config/validation/primitives.ts +174 -0
- package/src/config/validation/projection.ts +351 -0
- package/src/config/validation.ts +7 -0
- package/src/core/connection.ts +252 -0
- package/src/core/index.ts +2 -0
- package/src/core/transport.ts +24 -0
- package/src/history/client.ts +65 -0
- package/src/history/controller.ts +385 -0
- package/src/history/direct.ts +21 -0
- package/src/history/generated/fields.ts +18 -0
- package/src/history/generated/protocol.ts +389 -0
- package/src/history/generated/variant-fields.ts +27 -0
- package/src/history/index.ts +13 -0
- package/src/history/ports.ts +31 -0
- package/src/history/serialized.ts +38 -0
- package/src/history/validation.ts +334 -0
- package/src/history-tree/client.ts +16 -0
- package/src/history-tree/controller.ts +199 -0
- package/src/history-tree/direct.ts +3 -0
- package/src/history-tree/generated/fields.ts +26 -0
- package/src/history-tree/generated/protocol.ts +711 -0
- package/src/history-tree/generated/variant-fields.ts +39 -0
- package/src/history-tree/index.ts +13 -0
- package/src/history-tree/ports.ts +43 -0
- package/src/history-tree/serialized.ts +15 -0
- package/src/history-tree/validation.ts +269 -0
- package/src/layout/generated/protocol.ts +289 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/ratio.ts +22 -0
- package/src/layout/validation.ts +110 -0
- package/src/layout/visibility.ts +30 -0
- package/src/licence/client.ts +32 -0
- package/src/licence/controller.ts +301 -0
- package/src/licence/direct.ts +3 -0
- package/src/licence/generated/fields.ts +17 -0
- package/src/licence/generated/key-conformance.json +42 -0
- package/src/licence/generated/protocol.ts +249 -0
- package/src/licence/generated/variant-fields.ts +34 -0
- package/src/licence/index.ts +14 -0
- package/src/licence/key.ts +125 -0
- package/src/licence/ports.ts +39 -0
- package/src/licence/serialized.ts +13 -0
- package/src/licence/validation.ts +226 -0
- package/src/native-content/client.ts +474 -0
- package/src/native-content/direct.ts +16 -0
- package/src/native-content/generated/fields.ts +32 -0
- package/src/native-content/generated/protocol.ts +498 -0
- package/src/native-content/generated/variant-fields.ts +77 -0
- package/src/native-content/index.ts +12 -0
- package/src/native-content/ports.ts +46 -0
- package/src/native-content/serialized.ts +50 -0
- package/src/native-content/validation/base.ts +194 -0
- package/src/native-content/validation/messages.ts +192 -0
- package/src/native-content/validation/state.ts +404 -0
- package/src/native-content/validation.ts +7 -0
- package/src/notifications/client.ts +106 -0
- package/src/notifications/controller.ts +240 -0
- package/src/notifications/direct.ts +12 -0
- package/src/notifications/generated/fields.ts +19 -0
- package/src/notifications/generated/labels.ts +20 -0
- package/src/notifications/generated/protocol.ts +522 -0
- package/src/notifications/generated/variant-fields.ts +37 -0
- package/src/notifications/index.ts +16 -0
- package/src/notifications/ports.ts +22 -0
- package/src/notifications/serialized.ts +27 -0
- package/src/notifications/toast.ts +41 -0
- package/src/notifications/tone.ts +27 -0
- package/src/notifications/validation.ts +246 -0
- package/src/operation/bridge.ts +168 -0
- package/src/operation/client.ts +167 -0
- package/src/operation/controller.ts +321 -0
- package/src/operation/direct.ts +15 -0
- package/src/operation/generated/fields.ts +20 -0
- package/src/operation/generated/labels.ts +15 -0
- package/src/operation/generated/protocol.ts +762 -0
- package/src/operation/generated/variant-fields.ts +60 -0
- package/src/operation/index.ts +14 -0
- package/src/operation/ports.ts +29 -0
- package/src/operation/serialized.ts +39 -0
- package/src/operation/validation.ts +479 -0
- package/src/settings/client.ts +142 -0
- package/src/settings/connection.ts +246 -0
- package/src/settings/generated/fields.ts +34 -0
- package/src/settings/generated/protocol.ts +668 -0
- package/src/settings/generated/variant-fields.ts +26 -0
- package/src/settings/index.ts +12 -0
- package/src/settings/names.ts +8 -0
- package/src/settings/registry.ts +141 -0
- package/src/settings/validation/authority.ts +66 -0
- package/src/settings/validation/command.ts +165 -0
- package/src/settings/validation/error.ts +33 -0
- package/src/settings/validation/primitives.ts +203 -0
- package/src/settings/validation/projection.ts +50 -0
- package/src/settings/validation/registry.ts +170 -0
- package/src/settings/validation.ts +4 -0
- package/src/surface-transfer/client.ts +54 -0
- package/src/surface-transfer/generated/fields.ts +12 -0
- package/src/surface-transfer/generated/protocol.ts +61 -0
- package/src/surface-transfer/generated/variant-fields.ts +30 -0
- package/src/surface-transfer/index.ts +9 -0
- package/src/surface-transfer/validation.ts +209 -0
- package/src/surfaces/client.ts +140 -0
- package/src/surfaces/generated/fields.ts +19 -0
- package/src/surfaces/generated/protocol.ts +217 -0
- package/src/surfaces/generated/variant-fields.ts +42 -0
- package/src/surfaces/index.ts +9 -0
- package/src/surfaces/validation.ts +199 -0
- package/src/transfer/client.ts +133 -0
- package/src/transfer/connection.ts +87 -0
- package/src/transfer/generated/fields.ts +23 -0
- package/src/transfer/generated/protocol.ts +171 -0
- package/src/transfer/generated/variant-fields.ts +45 -0
- package/src/transfer/index.ts +11 -0
- package/src/transfer/payload.ts +71 -0
- package/src/transfer/validation.ts +282 -0
- package/src/update/client.ts +29 -0
- package/src/update/controller.ts +255 -0
- package/src/update/direct.ts +3 -0
- package/src/update/generated/fields.ts +14 -0
- package/src/update/generated/protocol.ts +238 -0
- package/src/update/generated/variant-fields.ts +44 -0
- package/src/update/index.ts +14 -0
- package/src/update/ports.ts +36 -0
- package/src/update/serialized.ts +12 -0
- package/src/update/validation.ts +191 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NativeContentChangedEvent,
|
|
3
|
+
NativeContentConnectRequest,
|
|
4
|
+
NativeContentConnectResult,
|
|
5
|
+
NativeContentContentSizeDecisionRequest,
|
|
6
|
+
NativeContentContentSizeDecisionResult,
|
|
7
|
+
NativeContentDesiredUpdateRequest,
|
|
8
|
+
NativeContentDesiredUpdateResult,
|
|
9
|
+
NativeContentRequestId,
|
|
10
|
+
NativeContentSnapshotRequest,
|
|
11
|
+
NativeContentSnapshotResult,
|
|
12
|
+
} from "./generated/protocol.ts";
|
|
13
|
+
|
|
14
|
+
export type NativeContentUnlisten = () => void | Promise<void>;
|
|
15
|
+
|
|
16
|
+
export interface NativeContentPort {
|
|
17
|
+
connect(request: NativeContentConnectRequest): Promise<unknown>;
|
|
18
|
+
snapshot(request: NativeContentSnapshotRequest): Promise<unknown>;
|
|
19
|
+
updateDesired(request: NativeContentDesiredUpdateRequest): Promise<unknown>;
|
|
20
|
+
decideContentSize(
|
|
21
|
+
request: NativeContentContentSizeDecisionRequest,
|
|
22
|
+
): Promise<unknown>;
|
|
23
|
+
listen?(
|
|
24
|
+
listener: (event: unknown) => void,
|
|
25
|
+
): NativeContentUnlisten | Promise<NativeContentUnlisten>;
|
|
26
|
+
nextRequestId(): NativeContentRequestId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CheckedNativeContentPort {
|
|
30
|
+
connect(
|
|
31
|
+
request: NativeContentConnectRequest,
|
|
32
|
+
): Promise<NativeContentConnectResult>;
|
|
33
|
+
snapshot(
|
|
34
|
+
request: NativeContentSnapshotRequest,
|
|
35
|
+
): Promise<NativeContentSnapshotResult>;
|
|
36
|
+
updateDesired(
|
|
37
|
+
request: NativeContentDesiredUpdateRequest,
|
|
38
|
+
): Promise<NativeContentDesiredUpdateResult>;
|
|
39
|
+
decideContentSize(
|
|
40
|
+
request: NativeContentContentSizeDecisionRequest,
|
|
41
|
+
): Promise<NativeContentContentSizeDecisionResult>;
|
|
42
|
+
listen?(
|
|
43
|
+
listener: (event: NativeContentChangedEvent) => void,
|
|
44
|
+
): Promise<NativeContentUnlisten>;
|
|
45
|
+
nextRequestId(): NativeContentRequestId;
|
|
46
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NativeContentConnectRequest,
|
|
3
|
+
NativeContentContentSizeDecisionRequest,
|
|
4
|
+
NativeContentDesiredUpdateRequest,
|
|
5
|
+
NativeContentSnapshotRequest,
|
|
6
|
+
} from "./generated/protocol.ts";
|
|
7
|
+
import type { NativeContentPort, NativeContentUnlisten } from "./ports.ts";
|
|
8
|
+
|
|
9
|
+
export class SerializedNativeContentPort implements NativeContentPort {
|
|
10
|
+
readonly #inner: NativeContentPort;
|
|
11
|
+
|
|
12
|
+
constructor(inner: NativeContentPort) {
|
|
13
|
+
this.#inner = inner;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async connect(request: NativeContentConnectRequest): Promise<unknown> {
|
|
17
|
+
return clone(await this.#inner.connect(clone(request)));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async snapshot(request: NativeContentSnapshotRequest): Promise<unknown> {
|
|
21
|
+
return clone(await this.#inner.snapshot(clone(request)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async updateDesired(
|
|
25
|
+
request: NativeContentDesiredUpdateRequest,
|
|
26
|
+
): Promise<unknown> {
|
|
27
|
+
return clone(await this.#inner.updateDesired(clone(request)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async decideContentSize(
|
|
31
|
+
request: NativeContentContentSizeDecisionRequest,
|
|
32
|
+
): Promise<unknown> {
|
|
33
|
+
return clone(await this.#inner.decideContentSize(clone(request)));
|
|
34
|
+
}
|
|
35
|
+
|
|
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)));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
nextRequestId(): string {
|
|
44
|
+
return this.#inner.nextRequestId();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function clone<Value>(value: Value): Value {
|
|
49
|
+
return JSON.parse(JSON.stringify(value)) as Value;
|
|
50
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NATIVE_CONTENT_VARIANT_FIELDS,
|
|
3
|
+
NATIVE_CONTENT_VARIANT_FIELDS_DISCRIMINANTS,
|
|
4
|
+
} from "../generated/variant-fields.ts";
|
|
5
|
+
import {
|
|
6
|
+
NATIVE_CONTENT_MAXIMUM_OPAQUE_ID_BYTES,
|
|
7
|
+
NATIVE_CONTENT_PROTOCOL_VERSION,
|
|
8
|
+
} from "../generated/protocol.ts";
|
|
9
|
+
|
|
10
|
+
const FORBIDDEN_KEYS = new Set([
|
|
11
|
+
"payload",
|
|
12
|
+
"url",
|
|
13
|
+
"navigation",
|
|
14
|
+
"plugin",
|
|
15
|
+
"midi",
|
|
16
|
+
"camera",
|
|
17
|
+
"renderer",
|
|
18
|
+
"gpu",
|
|
19
|
+
"raw_handle",
|
|
20
|
+
"tauri_label",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export class NativeContentProtocolValidationError extends Error {
|
|
24
|
+
constructor(readonly path: string, message: string) {
|
|
25
|
+
super(`incompatible native-content protocol at ${path}: ${message}`);
|
|
26
|
+
this.name = "NativeContentProtocolValidationError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function assertNativeContentProtocolVersion(
|
|
31
|
+
value: unknown,
|
|
32
|
+
path = "$.protocol_version",
|
|
33
|
+
): asserts value is typeof NATIVE_CONTENT_PROTOCOL_VERSION {
|
|
34
|
+
if (value !== NATIVE_CONTENT_PROTOCOL_VERSION) {
|
|
35
|
+
fail(path, `expected exact version ${NATIVE_CONTENT_PROTOCOL_VERSION}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function assertProductPayloadFree(value: unknown): void {
|
|
40
|
+
visit(value, "$", new Set());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function exactObject(
|
|
44
|
+
value: unknown,
|
|
45
|
+
path: string,
|
|
46
|
+
keys: readonly string[],
|
|
47
|
+
): Record<string, unknown> {
|
|
48
|
+
const object = record(value, path);
|
|
49
|
+
exactKeys(object, path, keys);
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
|
|
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>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function exactKeys(
|
|
64
|
+
value: Record<string, unknown>,
|
|
65
|
+
path: string,
|
|
66
|
+
keys: readonly string[],
|
|
67
|
+
): 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
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function member<const Value extends string>(
|
|
78
|
+
value: unknown,
|
|
79
|
+
values: readonly Value[],
|
|
80
|
+
path: string,
|
|
81
|
+
): asserts value is Value {
|
|
82
|
+
if (typeof value !== "string" || !values.includes(value as Value)) {
|
|
83
|
+
fail(path, `unknown value ${String(value)}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function text(value: unknown, path: string): asserts value is string {
|
|
88
|
+
if (typeof value !== "string") fail(path, "expected string");
|
|
89
|
+
}
|
|
90
|
+
|
|
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
|
+
) {
|
|
101
|
+
fail(path, "invalid bounded opaque id");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function boolean(
|
|
106
|
+
value: unknown,
|
|
107
|
+
path: string,
|
|
108
|
+
): asserts value is boolean {
|
|
109
|
+
if (typeof value !== "boolean") fail(path, "expected boolean");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function finite(
|
|
113
|
+
value: unknown,
|
|
114
|
+
path: string,
|
|
115
|
+
): asserts value is number {
|
|
116
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
117
|
+
fail(path, "expected finite number");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
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
|
+
) {
|
|
130
|
+
fail(path, "expected non-negative safe integer");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function positive(
|
|
135
|
+
value: unknown,
|
|
136
|
+
path: string,
|
|
137
|
+
): asserts value is number {
|
|
138
|
+
natural(value, path);
|
|
139
|
+
if (value === 0) fail(path, "expected positive safe integer");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function array(value: unknown, path: string): readonly unknown[] {
|
|
143
|
+
if (!Array.isArray(value)) fail(path, "expected array");
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function nullable<T>(
|
|
148
|
+
value: unknown,
|
|
149
|
+
path: string,
|
|
150
|
+
guard: (value: unknown, path: string) => asserts value is T,
|
|
151
|
+
): void {
|
|
152
|
+
if (value !== null) guard(value, path);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function fail(path: string, message: string): never {
|
|
156
|
+
throw new NativeContentProtocolValidationError(path, message);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
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");
|
|
162
|
+
seen.add(value);
|
|
163
|
+
if (Array.isArray(value)) {
|
|
164
|
+
value.forEach((item, index) => visit(item, `${path}[${index}]`, seen));
|
|
165
|
+
} else {
|
|
166
|
+
for (const [key, item] of Object.entries(value)) {
|
|
167
|
+
if (FORBIDDEN_KEYS.has(key)) fail(`${path}.${key}`, "product payload field");
|
|
168
|
+
visit(item, `${path}.${key}`, seen);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
seen.delete(value);
|
|
172
|
+
}
|
|
173
|
+
|
|
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
|
+
export function variantKeys(
|
|
186
|
+
type: string,
|
|
187
|
+
object: Record<string, unknown>,
|
|
188
|
+
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;
|
|
194
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { NATIVE_CONTENT_FIELDS } from "../generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
NATIVE_CONTENT_CONNECT_STATUSES,
|
|
4
|
+
NATIVE_CONTENT_DECISION_STATUSES,
|
|
5
|
+
NATIVE_CONTENT_FAILURE_PHASES,
|
|
6
|
+
NATIVE_CONTENT_REJECTION_CODES,
|
|
7
|
+
NATIVE_CONTENT_RETRY_CLASSES,
|
|
8
|
+
NATIVE_CONTENT_SNAPSHOT_STATUSES,
|
|
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,
|
|
18
|
+
} from "../generated/protocol.ts";
|
|
19
|
+
import {
|
|
20
|
+
assertNativeContentProtocolVersion,
|
|
21
|
+
assertProductPayloadFree,
|
|
22
|
+
exactKeys,
|
|
23
|
+
variantKeys,
|
|
24
|
+
exactObject,
|
|
25
|
+
fail,
|
|
26
|
+
member,
|
|
27
|
+
natural,
|
|
28
|
+
opaqueId,
|
|
29
|
+
positive,
|
|
30
|
+
record,
|
|
31
|
+
text,
|
|
32
|
+
} from "./base.ts";
|
|
33
|
+
import {
|
|
34
|
+
assertValidContentSizeDecision,
|
|
35
|
+
assertValidContentSizeProposal,
|
|
36
|
+
assertValidDesiredUpdate,
|
|
37
|
+
assertValidNativeContentChangedEvent,
|
|
38
|
+
assertValidNativeContentSnapshot,
|
|
39
|
+
desiredReceipt,
|
|
40
|
+
proposalReceipt,
|
|
41
|
+
} from "./state.ts";
|
|
42
|
+
|
|
43
|
+
export function assertValidNativeContentConnectRequest(
|
|
44
|
+
value: unknown,
|
|
45
|
+
): asserts value is NativeContentConnectRequest {
|
|
46
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentConnectRequest);
|
|
47
|
+
requestEnvelope(object);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function assertValidNativeContentSnapshotRequest(
|
|
51
|
+
value: unknown,
|
|
52
|
+
): asserts value is NativeContentSnapshotRequest {
|
|
53
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentSnapshotRequest);
|
|
54
|
+
requestEnvelope(object);
|
|
55
|
+
positive(object.client_epoch, "$.client_epoch");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function assertValidNativeContentDesiredUpdateRequest(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): asserts value is NativeContentDesiredUpdateRequest {
|
|
61
|
+
assertProductPayloadFree(value);
|
|
62
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentDesiredUpdateRequest);
|
|
63
|
+
requestEnvelope(object);
|
|
64
|
+
positive(object.client_epoch, "$.client_epoch");
|
|
65
|
+
natural(object.expected_desired_revision, "$.expected_desired_revision");
|
|
66
|
+
assertValidDesiredUpdate(object.update);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function assertValidNativeContentDecisionRequest(
|
|
70
|
+
value: unknown,
|
|
71
|
+
): asserts value is NativeContentContentSizeDecisionRequest {
|
|
72
|
+
assertProductPayloadFree(value);
|
|
73
|
+
const object = exactObject(value, "$", NATIVE_CONTENT_FIELDS.NativeContentContentSizeDecisionRequest);
|
|
74
|
+
requestEnvelope(object);
|
|
75
|
+
positive(object.client_epoch, "$.client_epoch");
|
|
76
|
+
assertValidContentSizeProposal(object.proposal);
|
|
77
|
+
assertValidContentSizeDecision(object.decision);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function assertValidNativeContentConnectResult(
|
|
81
|
+
value: unknown,
|
|
82
|
+
): asserts value is NativeContentConnectResult {
|
|
83
|
+
assertProductPayloadFree(value);
|
|
84
|
+
const object = record(value, "$");
|
|
85
|
+
member(object.status, NATIVE_CONTENT_CONNECT_STATUSES, "$.status");
|
|
86
|
+
responseCorrelation(object);
|
|
87
|
+
if (object.status === "connected") {
|
|
88
|
+
exactKeys(object, "$", variantKeys("NativeContentConnectResult", object, "$"));
|
|
89
|
+
assertValidNativeContentSnapshot(object.snapshot);
|
|
90
|
+
} else {
|
|
91
|
+
exactKeys(object, "$", variantKeys("NativeContentConnectResult", object, "$"));
|
|
92
|
+
rejection(object.rejection, "$.rejection");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function assertValidNativeContentSnapshotResult(
|
|
97
|
+
value: unknown,
|
|
98
|
+
): asserts value is NativeContentSnapshotResult {
|
|
99
|
+
assertProductPayloadFree(value);
|
|
100
|
+
const object = record(value, "$");
|
|
101
|
+
member(object.status, NATIVE_CONTENT_SNAPSHOT_STATUSES, "$.status");
|
|
102
|
+
responseCorrelation(object);
|
|
103
|
+
if (object.status === "ready") {
|
|
104
|
+
exactKeys(object, "$", variantKeys("NativeContentSnapshotResult", object, "$"));
|
|
105
|
+
assertValidNativeContentSnapshot(object.snapshot);
|
|
106
|
+
} else {
|
|
107
|
+
exactKeys(object, "$", variantKeys("NativeContentSnapshotResult", object, "$"));
|
|
108
|
+
rejection(object.rejection, "$.rejection");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function assertValidNativeContentDesiredUpdateResult(
|
|
113
|
+
value: unknown,
|
|
114
|
+
): asserts value is NativeContentDesiredUpdateResult {
|
|
115
|
+
assertProductPayloadFree(value);
|
|
116
|
+
const object = record(value, "$");
|
|
117
|
+
member(object.status, NATIVE_CONTENT_UPDATE_STATUSES, "$.status");
|
|
118
|
+
responseCorrelation(object);
|
|
119
|
+
if (object.status === "committed") {
|
|
120
|
+
exactKeys(object, "$", [
|
|
121
|
+
"status",
|
|
122
|
+
"request_id",
|
|
123
|
+
"snapshot",
|
|
124
|
+
"receipt",
|
|
125
|
+
"event",
|
|
126
|
+
]);
|
|
127
|
+
assertValidNativeContentSnapshot(object.snapshot);
|
|
128
|
+
desiredReceipt(object.receipt, "$.receipt");
|
|
129
|
+
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
|
+
) {
|
|
136
|
+
fail("$.event.change", "desired update event correlation mismatch");
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
exactKeys(object, "$", variantKeys("NativeContentDesiredUpdateResult", object, "$"));
|
|
140
|
+
rejection(object.rejection, "$.rejection");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function assertValidNativeContentDecisionResult(
|
|
145
|
+
value: unknown,
|
|
146
|
+
): asserts value is NativeContentContentSizeDecisionResult {
|
|
147
|
+
assertProductPayloadFree(value);
|
|
148
|
+
const object = record(value, "$");
|
|
149
|
+
member(object.status, NATIVE_CONTENT_DECISION_STATUSES, "$.status");
|
|
150
|
+
responseCorrelation(object);
|
|
151
|
+
if (object.status === "decided") {
|
|
152
|
+
exactKeys(object, "$", [
|
|
153
|
+
"status",
|
|
154
|
+
"request_id",
|
|
155
|
+
"snapshot",
|
|
156
|
+
"receipt",
|
|
157
|
+
"event",
|
|
158
|
+
]);
|
|
159
|
+
assertValidNativeContentSnapshot(object.snapshot);
|
|
160
|
+
proposalReceipt(object.receipt, "$.receipt");
|
|
161
|
+
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
|
+
) {
|
|
168
|
+
fail("$.event.change", "content-size decision event correlation mismatch");
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
exactKeys(object, "$", variantKeys("NativeContentContentSizeDecisionResult", object, "$"));
|
|
172
|
+
rejection(object.rejection, "$.rejection");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function requestEnvelope(object: Record<string, unknown>): void {
|
|
177
|
+
assertNativeContentProtocolVersion(object.protocol_version);
|
|
178
|
+
opaqueId(object.request_id, "$.request_id");
|
|
179
|
+
opaqueId(object.island_id, "$.island_id");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function responseCorrelation(object: Record<string, unknown>): void {
|
|
183
|
+
opaqueId(object.request_id, "$.request_id");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function rejection(value: unknown, path: string): void {
|
|
187
|
+
const object = exactObject(value, path, NATIVE_CONTENT_FIELDS.NativeContentProtocolRejection);
|
|
188
|
+
member(object.code, NATIVE_CONTENT_REJECTION_CODES, `${path}.code`);
|
|
189
|
+
text(object.message, `${path}.message`);
|
|
190
|
+
member(object.phase, NATIVE_CONTENT_FAILURE_PHASES, `${path}.phase`);
|
|
191
|
+
member(object.retry, NATIVE_CONTENT_RETRY_CLASSES, `${path}.retry`);
|
|
192
|
+
}
|