@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.
- package/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- 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 +78 -109
- 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 +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
import { CheckedSnapshotConnection,
|
|
1
|
+
import { CheckedSnapshotConnection, CheckedSubscription } 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,
|
|
5
9
|
assertValidNotificationMutationCommand,
|
|
6
10
|
assertValidNotificationMutationResult,
|
|
11
|
+
assertValidNotificationSnapshot,
|
|
7
12
|
assertValidNotificationSnapshotResponse,
|
|
8
13
|
} from "./validation.ts";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type NotificationSnapshotResponse,
|
|
14
|
+
import { NOTIFICATION_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
15
|
+
import type {
|
|
16
|
+
NotificationMutationCommand,
|
|
17
|
+
NotificationMutationResult,
|
|
18
|
+
NotificationSnapshot,
|
|
19
|
+
NotificationSnapshotResponse,
|
|
16
20
|
} from "./generated/protocol.ts";
|
|
17
21
|
import type { NotificationPort } from "./ports.ts";
|
|
18
22
|
|
|
19
23
|
export interface NotificationSubscription {
|
|
20
24
|
readonly ready: Promise<void>;
|
|
21
25
|
current(): NotificationSnapshot | undefined;
|
|
22
|
-
failures():
|
|
26
|
+
failures(): ReadonlyArray<ConnectionFailure>;
|
|
23
27
|
dispose(): Promise<void>;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
export class NotificationClient {
|
|
27
31
|
constructor(readonly port: NotificationPort) {}
|
|
28
32
|
|
|
29
|
-
nextRequestId(): string {
|
|
33
|
+
nextRequestId(): string {
|
|
34
|
+
return this.port.nextRequestId();
|
|
35
|
+
}
|
|
30
36
|
|
|
31
37
|
async snapshot(offset = 0, limit = 100): Promise<NotificationSnapshotResponse> {
|
|
32
38
|
const requestId = this.port.nextRequestId();
|
|
33
|
-
const value = await this.port.snapshot({
|
|
39
|
+
const value = await this.port.snapshot({
|
|
40
|
+
protocolVersion: NOTIFICATION_PROTOCOL_VERSION,
|
|
41
|
+
requestId,
|
|
42
|
+
offset,
|
|
43
|
+
limit,
|
|
44
|
+
});
|
|
34
45
|
assertValidNotificationSnapshotResponse(value);
|
|
35
46
|
assertCorrelation(value.requestId, requestId);
|
|
36
47
|
return value;
|
|
@@ -44,63 +55,86 @@ export class NotificationClient {
|
|
|
44
55
|
return value;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
subscribe(
|
|
48
|
-
|
|
58
|
+
subscribe(
|
|
59
|
+
listener: (snapshot: NotificationSnapshot) => void,
|
|
60
|
+
onFailure?: ConnectionFailureReporter,
|
|
61
|
+
limit = 100,
|
|
62
|
+
): NotificationSubscription {
|
|
63
|
+
const port = this.port;
|
|
64
|
+
return new CheckedSubscription(
|
|
65
|
+
new CheckedSnapshotConnection({
|
|
66
|
+
listen: async (receive) => (port.listen === undefined ? () => {} : port.listen(receive)),
|
|
67
|
+
loadSnapshot: async () => (await this.snapshot(0, limit)).snapshot,
|
|
68
|
+
validateSnapshot: parseSnapshot,
|
|
69
|
+
handleEvent: notificationEventAction,
|
|
70
|
+
isNewer: isNewerNotificationSnapshot,
|
|
71
|
+
onSnapshot: listener,
|
|
72
|
+
onFailure,
|
|
73
|
+
}),
|
|
74
|
+
() => {},
|
|
75
|
+
);
|
|
49
76
|
}
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
export class NotificationResponseCorrelationError extends Error {
|
|
53
|
-
constructor(
|
|
54
|
-
|
|
80
|
+
constructor(
|
|
81
|
+
readonly expectedRequestId: string,
|
|
82
|
+
readonly receivedRequestId: string,
|
|
83
|
+
) {
|
|
84
|
+
super(
|
|
85
|
+
`notification response correlation mismatch: expected ${expectedRequestId}; received ${receivedRequestId}`,
|
|
86
|
+
);
|
|
55
87
|
this.name = "NotificationResponseCorrelationError";
|
|
56
88
|
}
|
|
57
89
|
}
|
|
58
90
|
|
|
59
|
-
class CheckedNotificationSubscription implements NotificationSubscription {
|
|
60
|
-
readonly ready: Promise<void>;
|
|
61
|
-
readonly connection: CheckedSnapshotConnection<NotificationSnapshot>;
|
|
62
|
-
|
|
63
|
-
constructor(client: NotificationClient, port: NotificationPort, listener: (snapshot: NotificationSnapshot) => void, onFailure: ConnectionFailureReporter | undefined, limit: number) {
|
|
64
|
-
this.connection = new CheckedSnapshotConnection({
|
|
65
|
-
listen: async (receive) => port.listen === undefined ? () => {} : port.listen(receive),
|
|
66
|
-
loadSnapshot: async () => (await client.snapshot(0, limit)).snapshot,
|
|
67
|
-
validateSnapshot: parseSnapshot,
|
|
68
|
-
handleEvent: notificationEventAction,
|
|
69
|
-
isNewer: isNewerNotificationSnapshot,
|
|
70
|
-
onSnapshot: listener,
|
|
71
|
-
onFailure,
|
|
72
|
-
});
|
|
73
|
-
this.ready = this.connection.ready.then(() => undefined);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
current(): NotificationSnapshot | undefined { return this.connection.current(); }
|
|
77
|
-
failures(): readonly ConnectionFailure[] { return this.connection.failures(); }
|
|
78
|
-
dispose(): Promise<void> { return this.connection.dispose(); }
|
|
79
|
-
}
|
|
80
|
-
|
|
81
91
|
function parseSnapshot(value: unknown): NotificationSnapshot {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return value as NotificationSnapshot;
|
|
92
|
+
assertValidNotificationSnapshot(value);
|
|
93
|
+
return value;
|
|
85
94
|
}
|
|
86
95
|
|
|
87
|
-
export function notificationEventAction(
|
|
96
|
+
export function notificationEventAction(
|
|
97
|
+
value: unknown,
|
|
98
|
+
current: NotificationSnapshot | undefined,
|
|
99
|
+
): { kind: "ignore" } | { kind: "refresh" } {
|
|
88
100
|
assertValidNotificationChangedEvent(value);
|
|
89
|
-
const event = value
|
|
90
|
-
if (current === undefined)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (event.authority.
|
|
101
|
+
const event = value;
|
|
102
|
+
if (current === undefined) {
|
|
103
|
+
return { kind: "refresh" };
|
|
104
|
+
}
|
|
105
|
+
if (event.authority.authorityId !== current.authority.authorityId) {
|
|
106
|
+
return { kind: "ignore" };
|
|
107
|
+
}
|
|
108
|
+
if (event.authority.authorityEpoch < current.authority.authorityEpoch) {
|
|
109
|
+
return { kind: "ignore" };
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
event.authority.authorityEpoch === current.authority.authorityEpoch &&
|
|
113
|
+
event.committedLedgerRevision <= current.ledgerRevision
|
|
114
|
+
) {
|
|
115
|
+
return { kind: "ignore" };
|
|
116
|
+
}
|
|
94
117
|
return { kind: "refresh" };
|
|
95
118
|
}
|
|
96
119
|
|
|
97
|
-
export function isNewerNotificationSnapshot(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
export function isNewerNotificationSnapshot(
|
|
121
|
+
candidate: NotificationSnapshot,
|
|
122
|
+
current: NotificationSnapshot | undefined,
|
|
123
|
+
): boolean {
|
|
124
|
+
if (current === undefined) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (candidate.authority.authorityId !== current.authority.authorityId) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (candidate.authority.authorityEpoch !== current.authority.authorityEpoch) {
|
|
131
|
+
return candidate.authority.authorityEpoch > current.authority.authorityEpoch;
|
|
132
|
+
}
|
|
101
133
|
return candidate.ledgerRevision > current.ledgerRevision;
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
function assertCorrelation(received: string, expected: string): void {
|
|
105
|
-
if (received !== expected)
|
|
137
|
+
if (received !== expected) {
|
|
138
|
+
throw new NotificationResponseCorrelationError(expected, received);
|
|
139
|
+
}
|
|
106
140
|
}
|