@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,14 +1,14 @@
|
|
|
1
1
|
import { LicenceClient } from "./client.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { LICENCE_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
3
|
+
import type {
|
|
4
|
+
HeldLicenceProjection,
|
|
5
|
+
LicenceCredentialProjection,
|
|
6
|
+
LicenceOutcomeProjection,
|
|
7
|
+
LicenceRejectionCode,
|
|
8
|
+
LicenceSeatProjection,
|
|
9
|
+
LicenceSnapshot,
|
|
10
|
+
LicenceTrustBasisProjection,
|
|
11
|
+
LicenceUsabilityProjection,
|
|
12
12
|
} from "./generated/protocol.ts";
|
|
13
13
|
import type { LicencePort, LicenceUnlisten } from "./ports.ts";
|
|
14
14
|
|
|
@@ -59,28 +59,44 @@ export class LicenceController {
|
|
|
59
59
|
readonly #observers = new Set<() => void>();
|
|
60
60
|
#status: LicenceControllerStatus = { kind: "idle" };
|
|
61
61
|
#snapshot?: LicenceSnapshot;
|
|
62
|
-
#lastRejection
|
|
62
|
+
#lastRejection: LicenceRejectionCode | undefined;
|
|
63
63
|
#started = false;
|
|
64
64
|
#lifecycle = 0;
|
|
65
65
|
#commandSequence = 0;
|
|
66
66
|
#pending = false;
|
|
67
|
-
#unlisten: LicenceUnlisten
|
|
67
|
+
#unlisten: Array<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.#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":
|
|
@@ -151,7 +175,9 @@ export class LicenceController {
|
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
async start(): Promise<void> {
|
|
154
|
-
if (this.#started)
|
|
178
|
+
if (this.#started) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
155
181
|
this.#started = true;
|
|
156
182
|
const lifecycle = ++this.#lifecycle;
|
|
157
183
|
this.#setStatus({ kind: "loading" });
|
|
@@ -164,7 +190,9 @@ export class LicenceController {
|
|
|
164
190
|
this.#unlisten.push(unlisten);
|
|
165
191
|
await this.refresh();
|
|
166
192
|
} catch (error) {
|
|
167
|
-
if (this.#started && lifecycle === this.#lifecycle)
|
|
193
|
+
if (this.#started && lifecycle === this.#lifecycle) {
|
|
194
|
+
this.#setStatus({ kind: "failed", error });
|
|
195
|
+
}
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
|
|
@@ -173,7 +201,9 @@ export class LicenceController {
|
|
|
173
201
|
this.#lifecycle += 1;
|
|
174
202
|
const unlisten = this.#unlisten;
|
|
175
203
|
this.#unlisten = [];
|
|
176
|
-
for (const stop of unlisten)
|
|
204
|
+
for (const stop of unlisten) {
|
|
205
|
+
await stop();
|
|
206
|
+
}
|
|
177
207
|
this.#setStatus({ kind: "idle" });
|
|
178
208
|
}
|
|
179
209
|
|
|
@@ -181,11 +211,15 @@ export class LicenceController {
|
|
|
181
211
|
const lifecycle = this.#lifecycle;
|
|
182
212
|
try {
|
|
183
213
|
const snapshot = await this.#client.snapshot();
|
|
184
|
-
if (lifecycle !== this.#lifecycle)
|
|
214
|
+
if (lifecycle !== this.#lifecycle) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
185
217
|
this.#snapshot = snapshot;
|
|
186
218
|
this.#setStatus({ kind: "ready" });
|
|
187
219
|
} catch (error) {
|
|
188
|
-
if (lifecycle === this.#lifecycle)
|
|
220
|
+
if (lifecycle === this.#lifecycle) {
|
|
221
|
+
this.#setStatus({ kind: "failed", error });
|
|
222
|
+
}
|
|
189
223
|
}
|
|
190
224
|
}
|
|
191
225
|
|
|
@@ -195,10 +229,12 @@ export class LicenceController {
|
|
|
195
229
|
* Empty when the authority does not account for seats, which is a different
|
|
196
230
|
* state from a licence with one seat.
|
|
197
231
|
*/
|
|
198
|
-
get seats():
|
|
232
|
+
get seats(): ReadonlyArray<LicenceSeatProjection> {
|
|
233
|
+
return this.licence?.seats ?? [];
|
|
234
|
+
}
|
|
199
235
|
|
|
200
236
|
/** The seats that are not this machine — the ones a release would free. */
|
|
201
|
-
get otherSeats():
|
|
237
|
+
get otherSeats(): ReadonlyArray<LicenceSeatProjection> {
|
|
202
238
|
return this.seats.filter((seat) => !seat.thisMachine);
|
|
203
239
|
}
|
|
204
240
|
|
|
@@ -271,10 +307,7 @@ export class LicenceController {
|
|
|
271
307
|
}
|
|
272
308
|
|
|
273
309
|
async #command(
|
|
274
|
-
run: (
|
|
275
|
-
client: LicenceClient,
|
|
276
|
-
epoch: number,
|
|
277
|
-
) => Promise<LicenceOutcomeProjection>,
|
|
310
|
+
run: (client: LicenceClient, epoch: number) => Promise<LicenceOutcomeProjection>,
|
|
278
311
|
): Promise<LicenceCommandOutcome> {
|
|
279
312
|
const commandSequence = ++this.#commandSequence;
|
|
280
313
|
this.#lastRejection = undefined;
|
|
@@ -291,9 +324,10 @@ export class LicenceController {
|
|
|
291
324
|
this.#notify();
|
|
292
325
|
try {
|
|
293
326
|
const outcome = await run(this.#client, epoch);
|
|
294
|
-
const result: LicenceCommandOutcome =
|
|
295
|
-
|
|
296
|
-
|
|
327
|
+
const result: LicenceCommandOutcome =
|
|
328
|
+
outcome.status === "rejected"
|
|
329
|
+
? { status: "rejected", snapshot: outcome.snapshot, code: outcome.code }
|
|
330
|
+
: { status: "committed", snapshot: outcome.snapshot };
|
|
297
331
|
if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
|
|
298
332
|
this.#snapshot = outcome.snapshot;
|
|
299
333
|
this.#lastRejection = result.status === "rejected" ? result.code : undefined;
|
|
@@ -319,6 +353,8 @@ export class LicenceController {
|
|
|
319
353
|
}
|
|
320
354
|
|
|
321
355
|
#notify(): void {
|
|
322
|
-
for (const observer of this.#observers)
|
|
356
|
+
for (const observer of this.#observers) {
|
|
357
|
+
observer();
|
|
358
|
+
}
|
|
323
359
|
}
|
|
324
360
|
}
|
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
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
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,4 @@ 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
|
+
} 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
|
]
|
|
@@ -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
|
|
package/src/licence/key.ts
CHANGED
|
@@ -68,7 +68,9 @@ export function isProbablyATypo(problem: LicenceKeyProblem): boolean {
|
|
|
68
68
|
*/
|
|
69
69
|
export function parseLicenceKey(input: string): LicenceKeyResult {
|
|
70
70
|
const normalized = normalize(input);
|
|
71
|
-
if (!normalized.ok)
|
|
71
|
+
if (!normalized.ok) {
|
|
72
|
+
return normalized;
|
|
73
|
+
}
|
|
72
74
|
|
|
73
75
|
const value = normalized.value;
|
|
74
76
|
if (value.length < MINIMUM_KEY_SYMBOLS) {
|
|
@@ -87,22 +89,45 @@ export function parseLicenceKey(input: string): LicenceKeyResult {
|
|
|
87
89
|
|
|
88
90
|
/** Renders a normalized key as `XXXXX-XXXXX-…`. */
|
|
89
91
|
export function group(key: string): string {
|
|
90
|
-
const groups: string
|
|
91
|
-
for (let at = 0; at < key.length; at += GROUP)
|
|
92
|
+
const groups: Array<string> = [];
|
|
93
|
+
for (let at = 0; at < key.length; at += GROUP) {
|
|
94
|
+
groups.push(key.slice(at, at + GROUP));
|
|
95
|
+
}
|
|
92
96
|
return groups.join("-");
|
|
93
97
|
}
|
|
94
98
|
|
|
99
|
+
/** Matches Rust's `char::is_whitespace` (Unicode `White_Space`: includes U+0085, excludes U+FEFF). */
|
|
100
|
+
const UNICODE_WHITESPACE = /\p{White_Space}/u;
|
|
101
|
+
|
|
102
|
+
/** Matches Rust's `char::to_ascii_uppercase` so non-ASCII letters like U+017F never fold into ASCII. */
|
|
103
|
+
function toAsciiUpper(character: string): string {
|
|
104
|
+
const code = character.charCodeAt(0);
|
|
105
|
+
if (code >= 0x61 && code <= 0x7a) {
|
|
106
|
+
return String.fromCharCode(code - 0x20);
|
|
107
|
+
}
|
|
108
|
+
return character;
|
|
109
|
+
}
|
|
110
|
+
|
|
95
111
|
function normalize(
|
|
96
112
|
input: string,
|
|
97
|
-
):
|
|
98
|
-
|
|
113
|
+
):
|
|
114
|
+
| { readonly ok: true; readonly value: string }
|
|
115
|
+
| { readonly ok: false; readonly problem: LicenceKeyProblem } {
|
|
116
|
+
const symbols: Array<{ readonly original: string; readonly mapped: string }> = [];
|
|
99
117
|
for (const character of input) {
|
|
100
|
-
if (character === "-" ||
|
|
101
|
-
|
|
118
|
+
if (character === "-" || UNICODE_WHITESPACE.test(character)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const upper = toAsciiUpper(character);
|
|
102
122
|
// The confusions Crockford excluded the symbols to avoid.
|
|
103
123
|
const mapped = upper === "I" || upper === "L" ? "1" : upper === "O" ? "0" : upper;
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
symbols.push({ original: character, mapped });
|
|
125
|
+
}
|
|
126
|
+
let output = "";
|
|
127
|
+
for (const [index, { original, mapped }] of symbols.entries()) {
|
|
128
|
+
const alphabet = index + 1 < symbols.length ? ALPHABET : CHECK_ALPHABET;
|
|
129
|
+
if (mapped.length !== 1 || !alphabet.includes(mapped)) {
|
|
130
|
+
return { ok: false, problem: { kind: "unexpectedSymbol", symbol: original } };
|
|
106
131
|
}
|
|
107
132
|
output += mapped;
|
|
108
133
|
}
|
|
@@ -118,8 +143,11 @@ function normalize(
|
|
|
118
143
|
function checkSymbol(body: string): string {
|
|
119
144
|
let sum = 0;
|
|
120
145
|
for (let index = 0; index < body.length; index += 1) {
|
|
121
|
-
const value = ALPHABET.indexOf(body
|
|
122
|
-
|
|
146
|
+
const value = ALPHABET.indexOf(body.charAt(index));
|
|
147
|
+
if (value === -1) {
|
|
148
|
+
throw new Error(`normalized key body contains unexpected symbol: ${body[index]}`);
|
|
149
|
+
}
|
|
150
|
+
sum += value * (index + 1);
|
|
123
151
|
}
|
|
124
|
-
return CHECK_ALPHABET
|
|
152
|
+
return CHECK_ALPHABET.charAt(sum % 37);
|
|
125
153
|
}
|
package/src/licence/ports.ts
CHANGED
|
@@ -24,7 +24,9 @@ export interface LicencePort {
|
|
|
24
24
|
refresh(command: LicenceRefreshCommand): Promise<unknown>;
|
|
25
25
|
releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown>;
|
|
26
26
|
renameSeat(command: LicenceRenameSeatCommand): Promise<unknown>;
|
|
27
|
-
listen
|
|
27
|
+
listen?:
|
|
28
|
+
| ((listener: (event: unknown) => void) => LicenceUnlisten | Promise<LicenceUnlisten>)
|
|
29
|
+
| undefined;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/** The same seam after validation. */
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
2
|
+
import type {
|
|
3
|
+
LicenceActivateCommand,
|
|
4
|
+
LicenceDeactivateCommand,
|
|
5
|
+
LicenceRefreshCommand,
|
|
6
|
+
LicenceReleaseSeatCommand,
|
|
7
|
+
LicenceRenameSeatCommand,
|
|
8
|
+
} from "./generated/protocol.ts";
|
|
2
9
|
import type { LicencePort, LicenceUnlisten } from "./ports.ts";
|
|
3
10
|
export class SerializedLicencePort implements LicencePort {
|
|
4
11
|
constructor(readonly inner: LicencePort) {}
|
|
5
|
-
async snapshot(): Promise<unknown> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async
|
|
12
|
+
async snapshot(): Promise<unknown> {
|
|
13
|
+
return wireCopy(await this.inner.snapshot());
|
|
14
|
+
}
|
|
15
|
+
async activate(command: LicenceActivateCommand): Promise<unknown> {
|
|
16
|
+
return wireCopy(await this.inner.activate(wireCopy(command)));
|
|
17
|
+
}
|
|
18
|
+
async deactivate(command: LicenceDeactivateCommand): Promise<unknown> {
|
|
19
|
+
return wireCopy(await this.inner.deactivate(wireCopy(command)));
|
|
20
|
+
}
|
|
21
|
+
async refresh(command: LicenceRefreshCommand): Promise<unknown> {
|
|
22
|
+
return wireCopy(await this.inner.refresh(wireCopy(command)));
|
|
23
|
+
}
|
|
24
|
+
async releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown> {
|
|
25
|
+
return wireCopy(await this.inner.releaseSeat(wireCopy(command)));
|
|
26
|
+
}
|
|
27
|
+
async renameSeat(command: LicenceRenameSeatCommand): Promise<unknown> {
|
|
28
|
+
return wireCopy(await this.inner.renameSeat(wireCopy(command)));
|
|
29
|
+
}
|
|
30
|
+
async listen(listener: (event: unknown) => void): Promise<LicenceUnlisten> {
|
|
31
|
+
if (this.inner.listen === undefined) {
|
|
32
|
+
return () => {};
|
|
33
|
+
}
|
|
34
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
35
|
+
}
|
|
12
36
|
}
|
|
13
|
-
function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
|