@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
package/src/layout/validation.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import { checkWireFields, isRecord, unsigned32, wireVariantFields } from "../core/record.ts";
|
|
2
|
+
import {
|
|
3
|
+
LAYOUT_VARIANT_FIELDS,
|
|
4
|
+
LAYOUT_VARIANT_FIELDS_DISCRIMINANTS,
|
|
5
|
+
} from "./generated/variant-fields.ts";
|
|
6
|
+
import { isLayoutRatio } from "./ratio.ts";
|
|
1
7
|
import {
|
|
2
8
|
LAYOUT_MUTATION_COMMAND_KINDS,
|
|
3
9
|
LAYOUT_MUTATION_OUTCOME_KINDS,
|
|
4
10
|
LAYOUT_MUTATION_REJECTION_CODES,
|
|
5
11
|
LAYOUT_PROTOCOL_VERSION,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
} from "./generated/protocol.ts";
|
|
13
|
+
import type {
|
|
14
|
+
LayoutMutationCommand,
|
|
15
|
+
LayoutMutationOutcome,
|
|
16
|
+
LayoutMutationRejectionCode,
|
|
9
17
|
} from "./generated/protocol.ts";
|
|
10
18
|
|
|
11
19
|
export type LayoutProtocolValidationCode =
|
|
@@ -18,8 +26,8 @@ export class LayoutProtocolValidationError extends Error {
|
|
|
18
26
|
readonly code: LayoutProtocolValidationCode;
|
|
19
27
|
readonly received: unknown;
|
|
20
28
|
|
|
21
|
-
constructor(code: LayoutProtocolValidationCode, received: unknown) {
|
|
22
|
-
super(message(code, received));
|
|
29
|
+
constructor(code: LayoutProtocolValidationCode, received: unknown, detail?: string) {
|
|
30
|
+
super(detail ?? message(code, received));
|
|
23
31
|
this.name = "LayoutProtocolValidationError";
|
|
24
32
|
this.code = code;
|
|
25
33
|
this.received = received;
|
|
@@ -30,23 +38,30 @@ export function assertLayoutProtocolVersion(
|
|
|
30
38
|
version: unknown,
|
|
31
39
|
): asserts version is typeof LAYOUT_PROTOCOL_VERSION {
|
|
32
40
|
if (version !== LAYOUT_PROTOCOL_VERSION) {
|
|
33
|
-
throw new LayoutProtocolValidationError(
|
|
34
|
-
"unsupported_protocol_version",
|
|
35
|
-
version,
|
|
36
|
-
);
|
|
41
|
+
throw new LayoutProtocolValidationError("unsupported_protocol_version", version);
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export function assertValidLayoutMutationCommand(
|
|
41
46
|
value: unknown,
|
|
42
47
|
): asserts value is LayoutMutationCommand {
|
|
43
|
-
|
|
48
|
+
validateMutation(
|
|
49
|
+
value,
|
|
50
|
+
LAYOUT_MUTATION_COMMAND_KINDS,
|
|
51
|
+
"LayoutMutationCommand",
|
|
52
|
+
"unknown_command",
|
|
53
|
+
);
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
export function assertValidLayoutMutationOutcome(
|
|
47
57
|
value: unknown,
|
|
48
58
|
): asserts value is LayoutMutationOutcome {
|
|
49
|
-
|
|
59
|
+
validateMutation(
|
|
60
|
+
value,
|
|
61
|
+
LAYOUT_MUTATION_OUTCOME_KINDS,
|
|
62
|
+
"LayoutMutationOutcome",
|
|
63
|
+
"unknown_outcome",
|
|
64
|
+
);
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
export function assertValidLayoutMutationRejectionCode(
|
|
@@ -54,37 +69,88 @@ export function assertValidLayoutMutationRejectionCode(
|
|
|
54
69
|
): asserts value is LayoutMutationRejectionCode {
|
|
55
70
|
if (
|
|
56
71
|
typeof value !== "string" ||
|
|
57
|
-
!LAYOUT_MUTATION_REJECTION_CODES.
|
|
58
|
-
value as (typeof LAYOUT_MUTATION_REJECTION_CODES)[number],
|
|
59
|
-
)
|
|
72
|
+
!LAYOUT_MUTATION_REJECTION_CODES.some((code) => code === value)
|
|
60
73
|
) {
|
|
61
|
-
throw new LayoutProtocolValidationError(
|
|
62
|
-
"unknown_rejection_code",
|
|
63
|
-
value,
|
|
64
|
-
);
|
|
74
|
+
throw new LayoutProtocolValidationError("unknown_rejection_code", value);
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
type MutationFields<Variant> = Variant extends { kind: string }
|
|
79
|
+
? Exclude<keyof Variant, "kind">
|
|
80
|
+
: never;
|
|
81
|
+
|
|
82
|
+
const mutationFields = {
|
|
83
|
+
panel_instance_id: isString,
|
|
84
|
+
panel_definition_id: isString,
|
|
85
|
+
surface_id: isString,
|
|
86
|
+
region_id: isString,
|
|
87
|
+
target_surface_id: isString,
|
|
88
|
+
target_region_id: isString,
|
|
89
|
+
source_surface_id: isString,
|
|
90
|
+
source_region_id: isString,
|
|
91
|
+
sizing_slot_id: isString,
|
|
92
|
+
insertion_index: unsigned32,
|
|
93
|
+
former_index: unsigned32,
|
|
94
|
+
panel_instance_ids: (value) => Array.isArray(value) && isStringList(value),
|
|
95
|
+
ratio: isLayoutRatio,
|
|
96
|
+
previous_ratio: isLayoutRatio,
|
|
97
|
+
committed_ratio: isLayoutRatio,
|
|
98
|
+
previous_active_panel_instance_id: (value) => value === null || isString(value),
|
|
99
|
+
collapsed: isBoolean,
|
|
100
|
+
previous_collapsed: isBoolean,
|
|
101
|
+
committed_collapsed: isBoolean,
|
|
102
|
+
} satisfies Record<
|
|
103
|
+
MutationFields<LayoutMutationCommand | LayoutMutationOutcome>,
|
|
104
|
+
(value: unknown) => boolean
|
|
105
|
+
>;
|
|
106
|
+
|
|
107
|
+
function validateMutation(
|
|
69
108
|
value: unknown,
|
|
70
|
-
known:
|
|
109
|
+
known: ReadonlyArray<string>,
|
|
110
|
+
type: "LayoutMutationCommand" | "LayoutMutationOutcome",
|
|
71
111
|
code: "unknown_command" | "unknown_outcome",
|
|
72
|
-
):
|
|
73
|
-
if (
|
|
74
|
-
typeof value !== "object" ||
|
|
75
|
-
value === null ||
|
|
76
|
-
!("kind" in value) ||
|
|
77
|
-
typeof value.kind !== "string" ||
|
|
78
|
-
!known.includes(value.kind)
|
|
79
|
-
) {
|
|
112
|
+
): void {
|
|
113
|
+
if (!isRecord(value) || typeof value.kind !== "string" || !known.includes(value.kind)) {
|
|
80
114
|
throw new LayoutProtocolValidationError(code, value);
|
|
81
115
|
}
|
|
116
|
+
const keys = wireVariantFields(
|
|
117
|
+
LAYOUT_VARIANT_FIELDS,
|
|
118
|
+
LAYOUT_VARIANT_FIELDS_DISCRIMINANTS,
|
|
119
|
+
type,
|
|
120
|
+
value,
|
|
121
|
+
() => {
|
|
122
|
+
throw new LayoutProtocolValidationError(code, value);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
checkWireFields(value, keys, (issue, field) => {
|
|
126
|
+
const detail = issue === "unknown_field" ? "unknown field" : "missing field";
|
|
127
|
+
throw new LayoutProtocolValidationError(code, value, `${type}.${field}: ${detail}`);
|
|
128
|
+
});
|
|
129
|
+
for (const [field, validate] of Object.entries(mutationFields)) {
|
|
130
|
+
if (keys.includes(field) && !validate(value[field])) {
|
|
131
|
+
throw new LayoutProtocolValidationError(code, value, `${type}.${field}: invalid value`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isString(value: unknown): value is string {
|
|
137
|
+
return typeof value === "string";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function isBoolean(value: unknown): value is boolean {
|
|
141
|
+
return typeof value === "boolean";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isStringList(value: ReadonlyArray<unknown>): boolean {
|
|
145
|
+
for (const item of value) {
|
|
146
|
+
if (!isString(item)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
82
151
|
}
|
|
83
152
|
|
|
84
|
-
function message(
|
|
85
|
-
code: LayoutProtocolValidationCode,
|
|
86
|
-
received: unknown,
|
|
87
|
-
): string {
|
|
153
|
+
function message(code: LayoutProtocolValidationCode, received: unknown): string {
|
|
88
154
|
switch (code) {
|
|
89
155
|
case "unsupported_protocol_version":
|
|
90
156
|
return `unsupported layout protocol version ${String(received)}; expected ${LAYOUT_PROTOCOL_VERSION}`;
|
package/src/layout/visibility.ts
CHANGED
|
@@ -18,8 +18,7 @@ export function projectOrdinaryRegionVisibility(
|
|
|
18
18
|
return {
|
|
19
19
|
region_id: definition.id,
|
|
20
20
|
state:
|
|
21
|
-
state.panel_instance_ids.length > 0 ||
|
|
22
|
-
definition.empty_policy === "keep_visible"
|
|
21
|
+
state.panel_instance_ids.length > 0 || definition.empty_policy === "keep_visible"
|
|
23
22
|
? "visible"
|
|
24
23
|
: "hidden",
|
|
25
24
|
};
|
package/src/licence/client.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { listenChecked } from "../core/connection.ts";
|
|
2
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
1
3
|
import type {
|
|
2
4
|
LicenceActivateCommand,
|
|
3
5
|
LicenceChangedEvent,
|
|
@@ -22,11 +24,50 @@ import {
|
|
|
22
24
|
|
|
23
25
|
export class LicenceClient implements CheckedLicencePort {
|
|
24
26
|
constructor(readonly port: LicencePort) {}
|
|
25
|
-
async snapshot(): Promise<LicenceSnapshot> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async
|
|
31
|
-
|
|
27
|
+
async snapshot(): Promise<LicenceSnapshot> {
|
|
28
|
+
const value = await this.port.snapshot();
|
|
29
|
+
assertLicenceSnapshot(value);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
async activate(command: LicenceActivateCommand): Promise<LicenceOutcomeProjection> {
|
|
33
|
+
assertLicenceActivateCommand(command);
|
|
34
|
+
const value = await this.port.activate(command);
|
|
35
|
+
assertLicenceOutcome(value);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
async deactivate(command: LicenceDeactivateCommand): Promise<LicenceOutcomeProjection> {
|
|
39
|
+
assertLicenceDeactivateCommand(command);
|
|
40
|
+
const value = await this.port.deactivate(command);
|
|
41
|
+
assertLicenceOutcome(value);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
async refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection> {
|
|
45
|
+
assertLicenceRefreshCommand(command);
|
|
46
|
+
const value = await this.port.refresh(command);
|
|
47
|
+
assertLicenceOutcome(value);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
async releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection> {
|
|
51
|
+
assertLicenceReleaseSeatCommand(command);
|
|
52
|
+
const value = await this.port.releaseSeat(command);
|
|
53
|
+
assertLicenceOutcome(value);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
async renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection> {
|
|
57
|
+
assertLicenceRenameSeatCommand(command);
|
|
58
|
+
const value = await this.port.renameSeat(command);
|
|
59
|
+
assertLicenceOutcome(value);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
listen(
|
|
63
|
+
listener: (event: LicenceChangedEvent) => void,
|
|
64
|
+
onFailure?: ConnectionFailureReporter,
|
|
65
|
+
): Promise<LicenceUnlisten> {
|
|
66
|
+
return listenChecked({
|
|
67
|
+
listen: (receive) => this.port.listen?.(receive) ?? (() => {}),
|
|
68
|
+
validate: assertLicenceChangedEvent,
|
|
69
|
+
listener,
|
|
70
|
+
onFailure,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
32
73
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
|
|
1
2
|
import { LicenceClient } from "./client.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { LICENCE_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
4
|
+
import type {
|
|
5
|
+
HeldLicenceProjection,
|
|
6
|
+
LicenceCredentialProjection,
|
|
7
|
+
LicenceOutcomeProjection,
|
|
8
|
+
LicenceRejectionCode,
|
|
9
|
+
LicenceSeatProjection,
|
|
10
|
+
LicenceSnapshot,
|
|
11
|
+
LicenceTrustBasisProjection,
|
|
12
|
+
LicenceUsabilityProjection,
|
|
12
13
|
} from "./generated/protocol.ts";
|
|
13
|
-
import type { LicencePort
|
|
14
|
+
import type { LicencePort } from "./ports.ts";
|
|
14
15
|
|
|
15
16
|
export type LicenceControllerStatus =
|
|
16
17
|
| { readonly kind: "idle" }
|
|
@@ -59,28 +60,43 @@ export class LicenceController {
|
|
|
59
60
|
readonly #observers = new Set<() => void>();
|
|
60
61
|
#status: LicenceControllerStatus = { kind: "idle" };
|
|
61
62
|
#snapshot?: LicenceSnapshot;
|
|
62
|
-
#lastRejection
|
|
63
|
-
#
|
|
64
|
-
#lifecycle = 0;
|
|
63
|
+
#lastRejection: LicenceRejectionCode | undefined;
|
|
64
|
+
readonly #lifecycle = new ControllerLifecycle();
|
|
65
65
|
#commandSequence = 0;
|
|
66
|
+
#refreshRevision = 0;
|
|
66
67
|
#pending = false;
|
|
67
|
-
#unlisten: LicenceUnlisten[] = [];
|
|
68
68
|
|
|
69
69
|
constructor(options: LicenceControllerOptions) {
|
|
70
70
|
this.#client = new LicenceClient(options.port);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
get status(): LicenceControllerStatus {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
get
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
get status(): LicenceControllerStatus {
|
|
74
|
+
return this.#lifecycle.eventFailure ?? this.#status;
|
|
75
|
+
}
|
|
76
|
+
get snapshot(): LicenceSnapshot | undefined {
|
|
77
|
+
return this.#snapshot;
|
|
78
|
+
}
|
|
79
|
+
get licence(): HeldLicenceProjection | undefined {
|
|
80
|
+
return this.#snapshot?.licence ?? undefined;
|
|
81
|
+
}
|
|
82
|
+
get usability(): LicenceUsabilityProjection | undefined {
|
|
83
|
+
return this.licence?.usability;
|
|
84
|
+
}
|
|
85
|
+
get trustBasis(): LicenceTrustBasisProjection | undefined {
|
|
86
|
+
return this.licence?.trustBasis;
|
|
87
|
+
}
|
|
88
|
+
get pending(): boolean {
|
|
89
|
+
return this.#pending;
|
|
90
|
+
}
|
|
79
91
|
/** The latest refusal, cleared as soon as the next command starts. */
|
|
80
|
-
get lastRejection(): LicenceRejectionCode | undefined {
|
|
92
|
+
get lastRejection(): LicenceRejectionCode | undefined {
|
|
93
|
+
return this.#lastRejection;
|
|
94
|
+
}
|
|
81
95
|
|
|
82
96
|
/** Whether a licence is held at all. Absence is not a usability state. */
|
|
83
|
-
get activated(): boolean {
|
|
97
|
+
get activated(): boolean {
|
|
98
|
+
return this.licence !== undefined;
|
|
99
|
+
}
|
|
84
100
|
|
|
85
101
|
/** Whether the software may be used. Grace counts, which is its point. */
|
|
86
102
|
get usable(): boolean {
|
|
@@ -96,11 +112,15 @@ export class LicenceController {
|
|
|
96
112
|
* are not the same message, and conflating them on a perpetual licence reads
|
|
97
113
|
* as the application breaking.
|
|
98
114
|
*/
|
|
99
|
-
get useUntil(): number | undefined {
|
|
100
|
-
|
|
115
|
+
get useUntil(): number | undefined {
|
|
116
|
+
return this.licence?.useUntil ?? undefined;
|
|
117
|
+
}
|
|
118
|
+
get updateUntil(): number | undefined {
|
|
119
|
+
return this.licence?.updateUntil ?? undefined;
|
|
120
|
+
}
|
|
101
121
|
|
|
102
122
|
/** Entitlement ids held, opaque by design. Longhorn enumerates no features. */
|
|
103
|
-
get entitlements():
|
|
123
|
+
get entitlements(): ReadonlyArray<string> {
|
|
104
124
|
return this.licence?.entitlements.map((entitlement) => entitlement.id) ?? [];
|
|
105
125
|
}
|
|
106
126
|
|
|
@@ -111,7 +131,9 @@ export class LicenceController {
|
|
|
111
131
|
|
|
112
132
|
/** The bound on an entitlement, or `undefined` for unlimited or unheld. */
|
|
113
133
|
limit(id: string): number | undefined {
|
|
114
|
-
return
|
|
134
|
+
return (
|
|
135
|
+
this.licence?.entitlements.find((entitlement) => entitlement.id === id)?.atMost ?? undefined
|
|
136
|
+
);
|
|
115
137
|
}
|
|
116
138
|
|
|
117
139
|
/**
|
|
@@ -127,7 +149,9 @@ export class LicenceController {
|
|
|
127
149
|
* to buy something they already own.
|
|
128
150
|
*/
|
|
129
151
|
get attention(): LicenceAttention {
|
|
130
|
-
if (!this.activated)
|
|
152
|
+
if (!this.activated) {
|
|
153
|
+
return "actionable";
|
|
154
|
+
}
|
|
131
155
|
switch (this.usability?.state) {
|
|
132
156
|
case "active":
|
|
133
157
|
case "inGrace":
|
|
@@ -150,42 +174,59 @@ export class LicenceController {
|
|
|
150
174
|
return () => this.#observers.delete(observer);
|
|
151
175
|
}
|
|
152
176
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
177
|
+
start(): Promise<void> {
|
|
178
|
+
return this.#lifecycle.start({
|
|
179
|
+
loading: () => this.#setStatus({ kind: "loading" }),
|
|
180
|
+
connect: async ({ isCurrent, own, reportFailure }) => {
|
|
181
|
+
const unlisten = await this.#client.listen(() => {
|
|
182
|
+
if (isCurrent()) {
|
|
183
|
+
void this.refresh();
|
|
184
|
+
}
|
|
185
|
+
}, reportFailure);
|
|
186
|
+
await own(unlisten);
|
|
187
|
+
if (isCurrent()) {
|
|
188
|
+
await this.refresh();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
failed: (error) => this.#setStatus({ kind: "failed", error }),
|
|
192
|
+
});
|
|
169
193
|
}
|
|
170
194
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.#lifecycle
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
195
|
+
/** Replaces the current subscription, including after a reported failure. */
|
|
196
|
+
restart(): Promise<void> {
|
|
197
|
+
return this.#lifecycle.restart(
|
|
198
|
+
this.status,
|
|
199
|
+
() => this.stop(),
|
|
200
|
+
() => this.start(),
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
stop(): Promise<void> {
|
|
205
|
+
return this.#lifecycle.stop(() => {
|
|
206
|
+
this.#pending = false;
|
|
207
|
+
this.#setStatus({ kind: "idle" });
|
|
208
|
+
});
|
|
178
209
|
}
|
|
179
210
|
|
|
180
211
|
async refresh(): Promise<void> {
|
|
181
|
-
|
|
212
|
+
if (!this.#lifecycle.active) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const lifecycle = this.#lifecycle.revision;
|
|
216
|
+
const revision = ++this.#refreshRevision;
|
|
217
|
+
const isCurrent = () =>
|
|
218
|
+
this.#lifecycle.isCurrent(lifecycle) && revision === this.#refreshRevision;
|
|
182
219
|
try {
|
|
183
220
|
const snapshot = await this.#client.snapshot();
|
|
184
|
-
if (
|
|
221
|
+
if (!isCurrent()) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
185
224
|
this.#snapshot = snapshot;
|
|
186
225
|
this.#setStatus({ kind: "ready" });
|
|
187
226
|
} catch (error) {
|
|
188
|
-
if (
|
|
227
|
+
if (isCurrent()) {
|
|
228
|
+
this.#setStatus({ kind: "failed", error });
|
|
229
|
+
}
|
|
189
230
|
}
|
|
190
231
|
}
|
|
191
232
|
|
|
@@ -195,15 +236,17 @@ export class LicenceController {
|
|
|
195
236
|
* Empty when the authority does not account for seats, which is a different
|
|
196
237
|
* state from a licence with one seat.
|
|
197
238
|
*/
|
|
198
|
-
get seats():
|
|
239
|
+
get seats(): ReadonlyArray<LicenceSeatProjection> {
|
|
240
|
+
return this.licence?.seats ?? [];
|
|
241
|
+
}
|
|
199
242
|
|
|
200
243
|
/** The seats that are not this machine — the ones a release would free. */
|
|
201
|
-
get otherSeats():
|
|
244
|
+
get otherSeats(): ReadonlyArray<LicenceSeatProjection> {
|
|
202
245
|
return this.seats.filter((seat) => !seat.thisMachine);
|
|
203
246
|
}
|
|
204
247
|
|
|
205
248
|
/**
|
|
206
|
-
* Presents a credential
|
|
249
|
+
* Presents a credential for any supported activation route.
|
|
207
250
|
*
|
|
208
251
|
* `label` is what the customer calls this machine in the seat list, asked
|
|
209
252
|
* for at the only moment it can be without inventing a settings screen.
|
|
@@ -271,12 +314,12 @@ export class LicenceController {
|
|
|
271
314
|
}
|
|
272
315
|
|
|
273
316
|
async #command(
|
|
274
|
-
run: (
|
|
275
|
-
client: LicenceClient,
|
|
276
|
-
epoch: number,
|
|
277
|
-
) => Promise<LicenceOutcomeProjection>,
|
|
317
|
+
run: (client: LicenceClient, epoch: number) => Promise<LicenceOutcomeProjection>,
|
|
278
318
|
): Promise<LicenceCommandOutcome> {
|
|
279
|
-
|
|
319
|
+
if (!this.#lifecycle.active) {
|
|
320
|
+
// Nothing is sent and nothing is written: a stopped controller stays idle.
|
|
321
|
+
return { status: "failed", error: new LicenceControllerUnavailableError() };
|
|
322
|
+
}
|
|
280
323
|
this.#lastRejection = undefined;
|
|
281
324
|
const epoch = this.#snapshot?.authorityEpoch;
|
|
282
325
|
if (epoch === undefined) {
|
|
@@ -286,27 +329,31 @@ export class LicenceController {
|
|
|
286
329
|
this.#setStatus({ kind: "failed", error });
|
|
287
330
|
return { status: "failed", error };
|
|
288
331
|
}
|
|
289
|
-
const
|
|
332
|
+
const commandSequence = ++this.#commandSequence;
|
|
333
|
+
const lifecycle = this.#lifecycle.revision;
|
|
290
334
|
this.#pending = true;
|
|
291
335
|
this.#notify();
|
|
292
336
|
try {
|
|
293
337
|
const outcome = await run(this.#client, epoch);
|
|
294
|
-
const result: LicenceCommandOutcome =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
338
|
+
const result: LicenceCommandOutcome =
|
|
339
|
+
outcome.status === "rejected"
|
|
340
|
+
? { status: "rejected", snapshot: outcome.snapshot, code: outcome.code }
|
|
341
|
+
: { status: "committed", snapshot: outcome.snapshot };
|
|
342
|
+
if (lifecycle === this.#lifecycle.revision && commandSequence === this.#commandSequence) {
|
|
343
|
+
this.#refreshRevision += 1;
|
|
298
344
|
this.#snapshot = outcome.snapshot;
|
|
299
345
|
this.#lastRejection = result.status === "rejected" ? result.code : undefined;
|
|
300
346
|
this.#setStatus({ kind: "ready" });
|
|
301
347
|
}
|
|
302
348
|
return result;
|
|
303
349
|
} catch (error) {
|
|
304
|
-
if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
|
|
350
|
+
if (lifecycle === this.#lifecycle.revision && commandSequence === this.#commandSequence) {
|
|
351
|
+
this.#refreshRevision += 1;
|
|
305
352
|
this.#setStatus({ kind: "failed", error });
|
|
306
353
|
}
|
|
307
354
|
return { status: "failed", error };
|
|
308
355
|
} finally {
|
|
309
|
-
if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
|
|
356
|
+
if (lifecycle === this.#lifecycle.revision && commandSequence === this.#commandSequence) {
|
|
310
357
|
this.#pending = false;
|
|
311
358
|
this.#notify();
|
|
312
359
|
}
|
|
@@ -319,6 +366,16 @@ export class LicenceController {
|
|
|
319
366
|
}
|
|
320
367
|
|
|
321
368
|
#notify(): void {
|
|
322
|
-
for (const observer of this.#observers)
|
|
369
|
+
for (const observer of this.#observers) {
|
|
370
|
+
observer();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** A command was issued outside a started lifetime. */
|
|
376
|
+
export class LicenceControllerUnavailableError extends Error {
|
|
377
|
+
constructor() {
|
|
378
|
+
super("licence controller is not started");
|
|
379
|
+
this.name = "LicenceControllerUnavailableError";
|
|
323
380
|
}
|
|
324
381
|
}
|
package/src/licence/direct.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { LicencePort } from "./ports.ts";
|
|
2
2
|
export type DirectLicenceHandlers = LicencePort;
|
|
3
|
-
export function createDirectLicencePort(handlers: DirectLicenceHandlers): LicencePort {
|
|
3
|
+
export function createDirectLicencePort(handlers: DirectLicenceHandlers): LicencePort {
|
|
4
|
+
return handlers;
|
|
5
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per protocol type, from the Rust structs.
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
5
5
|
|
|
6
|
-
export const LICENCE_FIELDS
|
|
6
|
+
export const LICENCE_FIELDS = {
|
|
7
7
|
"LicenceEntitlementProjection": ["id", "atMost"],
|
|
8
8
|
"LicenceSeatProjection": ["machineId", "label", "thisMachine"],
|
|
9
9
|
"HeldLicenceProjection": ["product", "usability", "trustBasis", "entitlements", "useUntil", "updateUntil", "seats"],
|
|
@@ -14,4 +14,5 @@ export const LICENCE_FIELDS: Record<string, readonly string[]> = {
|
|
|
14
14
|
"LicenceReleaseSeatCommand": ["protocolVersion", "authorityEpoch", "machineId"],
|
|
15
15
|
"LicenceRenameSeatCommand": ["protocolVersion", "authorityEpoch", "machineId", "label"],
|
|
16
16
|
"LicenceChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
|
|
17
|
-
|
|
17
|
+
"LicenceHostError": ["code", "message", "retryable"],
|
|
18
|
+
} as const;
|
|
@@ -38,5 +38,33 @@
|
|
|
38
38
|
{
|
|
39
39
|
"input": "ABCDE!2345FGHJK6789X",
|
|
40
40
|
"outcome": "unexpectedSymbol:!"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"input": "*BCDE12345FGHJK6789Z",
|
|
44
|
+
"outcome": "unexpectedSymbol:*"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"input": "ABCDEu2345FGHJK6789Z",
|
|
48
|
+
"outcome": "unexpectedSymbol:u"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"input": "000000000000000000V*",
|
|
52
|
+
"outcome": "ok:00000-00000-00000-000V*"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"input": "0000000000000000020u",
|
|
56
|
+
"outcome": "ok:00000-00000-00000-0020U"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"input": "ſBCDE12345FGHJK67894",
|
|
60
|
+
"outcome": "unexpectedSymbol:ſ"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"input": "
ABCDE-12345-FGHJK-67894
",
|
|
64
|
+
"outcome": "ok:ABCDE-12345-FGHJK-67894"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"input": "ABCDE12345FGHJK67894",
|
|
68
|
+
"outcome": "unexpectedSymbol:"
|
|
41
69
|
}
|
|
42
70
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority. Entitlements are opaque
|
|
3
3
|
// ids: Longhorn answers "entitled?" and enumerates no features.
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ export const LICENCE_TRUST_BASIS_KINDS = ["offlineSignature","remoteAssertion"]
|
|
|
8
8
|
export const LICENCE_CREDENTIAL_KINDS = ["key","accountToken","licenceFile"] as const;
|
|
9
9
|
export const LICENCE_REJECTION_CODES = ["malformed","notRecognised","noSeatsFree","revoked","clockRefused","staleAuthority","seatNotFound","unreachable"] as const;
|
|
10
10
|
export const LICENCE_OUTCOME_STATUSES = ["committed","rejected"] as const;
|
|
11
|
-
export const LICENCE_CHANGED_KINDS = ["activated","deactivated","seatRelabelled","refreshed","usabilityChanged"] as const;
|
|
11
|
+
export const LICENCE_CHANGED_KINDS = ["activated","deactivated","seatReleased","seatRelabelled","refreshed","usabilityChanged"] as const;
|
|
12
12
|
|
|
13
13
|
export type LicenceProtocolVersion = number;
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ until: Timestamp, } | { "state": "useWindowExpired",
|
|
|
24
24
|
*/
|
|
25
25
|
at: Timestamp, } | { "state": "leaseLapsed",
|
|
26
26
|
/**
|
|
27
|
-
* When grace ran out.
|
|
27
|
+
* When grace ran out, or when the unleased remote assertion was checked.
|
|
28
28
|
*/
|
|
29
29
|
at: Timestamp, } | { "state": "clockRefused" };
|
|
30
30
|
|
|
@@ -138,7 +138,7 @@ key: string, } | { "kind": "accountToken",
|
|
|
138
138
|
*/
|
|
139
139
|
token: string, } | { "kind": "licenceFile",
|
|
140
140
|
/**
|
|
141
|
-
* The file's bytes, base64. A `Vec<u8>` would arrive as an array of
|
|
141
|
+
* The file's bytes, padded RFC 4648 standard base64. A `Vec<u8>` would arrive as an array of
|
|
142
142
|
* numbers, which is a poor way to move a file across a boundary.
|
|
143
143
|
*/
|
|
144
144
|
contentsBase64: string, };
|
|
@@ -232,7 +232,7 @@ code: LicenceRejectionCode,
|
|
|
232
232
|
*/
|
|
233
233
|
snapshot: LicenceSnapshot, };
|
|
234
234
|
|
|
235
|
-
export type LicenceChangedKind = "activated" | "deactivated" | "seatRelabelled" | "refreshed" | "usabilityChanged";
|
|
235
|
+
export type LicenceChangedKind = "activated" | "deactivated" | "seatReleased" | "seatRelabelled" | "refreshed" | "usabilityChanged";
|
|
236
236
|
|
|
237
237
|
export type LicenceChangedEvent = {
|
|
238
238
|
/**
|
|
@@ -247,3 +247,7 @@ authorityEpoch: number,
|
|
|
247
247
|
* Coarse invalidation category.
|
|
248
248
|
*/
|
|
249
249
|
kind: LicenceChangedKind, };
|
|
250
|
+
|
|
251
|
+
export type LicenceHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
|
|
252
|
+
|
|
253
|
+
export type LicenceHostError = { "code": LicenceHostErrorCode, "message": string, "retryable": boolean, };
|