@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,238 @@
|
|
|
1
|
+
// @generated by `effigy generate:update`; do not edit.
|
|
2
|
+
// Rust serde types are the wire authority. Versions are strings, as
|
|
3
|
+
// `semver::Version` serialises them.
|
|
4
|
+
|
|
5
|
+
export const UPDATE_PROTOCOL_VERSION = 1 as const;
|
|
6
|
+
export const UPDATE_CHANNELS = ["production","beta","nightly"] as const;
|
|
7
|
+
export const UPDATE_OFFER_REASONS = ["staged","belowMinimumVersion","userInitiated"] as const;
|
|
8
|
+
export const UPDATE_INSTALL_MANAGERS = ["macAppStore","homebrewCask","flatpak","snap","appImage","nix","linuxDistribution"] as const;
|
|
9
|
+
export const UPDATE_DEFERRAL_CAUSES = ["userPostponed","workInFlight","installationNotWritable","externallyManaged","installFailed"] as const;
|
|
10
|
+
export const UPDATE_AVAILABILITY_STATES = ["offer","upToDate","aheadOfChannel","withheldByRollout","managedElsewhere"] as const;
|
|
11
|
+
export const UPDATE_PROGRESS_STATES = ["idle","downloading","verifying","readyToInstall","installing"] as const;
|
|
12
|
+
export const UPDATE_INSTALL_AUTHORIZATION_STATUSES = ["approved","deferred"] as const;
|
|
13
|
+
export const UPDATE_REJECTION_CODES = ["staleAuthority","noOffer","unavailable","channelMismatch","unreachable","signatureRejected","notWritable","installFailed"] as const;
|
|
14
|
+
export const UPDATE_OUTCOME_STATUSES = ["committed","rejected"] as const;
|
|
15
|
+
export const UPDATE_CHANGED_KINDS = ["checked","channelSelected","deferred","progressed"] as const;
|
|
16
|
+
|
|
17
|
+
export type UpdateProtocolVersion = number;
|
|
18
|
+
|
|
19
|
+
export type Channel = "production" | "beta" | "nightly";
|
|
20
|
+
|
|
21
|
+
export type OfferReason = "staged" | "belowMinimumVersion" | "userInitiated";
|
|
22
|
+
|
|
23
|
+
export type InstallManager = "macAppStore" | "homebrewCask" | "flatpak" | "snap" | "appImage" | "nix" | "linuxDistribution";
|
|
24
|
+
|
|
25
|
+
export type DeferralCause = { "cause": "userPostponed" } | { "cause": "workInFlight",
|
|
26
|
+
/**
|
|
27
|
+
* What was in flight, for display.
|
|
28
|
+
*/
|
|
29
|
+
detail: string, } | { "cause": "installationNotWritable",
|
|
30
|
+
/**
|
|
31
|
+
* What could not be written, for display.
|
|
32
|
+
*/
|
|
33
|
+
detail: string, } | { "cause": "externallyManaged",
|
|
34
|
+
/**
|
|
35
|
+
* Who owns it, for display.
|
|
36
|
+
*/
|
|
37
|
+
manager: InstallManager,
|
|
38
|
+
/**
|
|
39
|
+
* What the user should run, when the answer is a command.
|
|
40
|
+
*/
|
|
41
|
+
command: string | null, } | { "cause": "installFailed",
|
|
42
|
+
/**
|
|
43
|
+
* What went wrong, for display.
|
|
44
|
+
*/
|
|
45
|
+
detail: string, };
|
|
46
|
+
|
|
47
|
+
export type UpdateAvailabilityProjection = { "state": "offer",
|
|
48
|
+
/**
|
|
49
|
+
* The version offered.
|
|
50
|
+
*/
|
|
51
|
+
version: string,
|
|
52
|
+
/**
|
|
53
|
+
* Why it is offered.
|
|
54
|
+
*/
|
|
55
|
+
reason: OfferReason,
|
|
56
|
+
/**
|
|
57
|
+
* Release notes, when published.
|
|
58
|
+
*/
|
|
59
|
+
notes: string | null, } | { "state": "upToDate" } | { "state": "aheadOfChannel",
|
|
60
|
+
/**
|
|
61
|
+
* What is installed.
|
|
62
|
+
*/
|
|
63
|
+
installed: string,
|
|
64
|
+
/**
|
|
65
|
+
* What the channel currently publishes.
|
|
66
|
+
*/
|
|
67
|
+
channel: string, } | { "state": "withheldByRollout",
|
|
68
|
+
/**
|
|
69
|
+
* The version being staged.
|
|
70
|
+
*/
|
|
71
|
+
version: string, } | { "state": "managedElsewhere",
|
|
72
|
+
/**
|
|
73
|
+
* The version available.
|
|
74
|
+
*/
|
|
75
|
+
version: string,
|
|
76
|
+
/**
|
|
77
|
+
* What manages the install.
|
|
78
|
+
*/
|
|
79
|
+
manager: InstallManager, };
|
|
80
|
+
|
|
81
|
+
export type UpdateDeferralProjection = {
|
|
82
|
+
/**
|
|
83
|
+
* The version that was not installed.
|
|
84
|
+
*/
|
|
85
|
+
version: string,
|
|
86
|
+
/**
|
|
87
|
+
* Why it was not installed.
|
|
88
|
+
*/
|
|
89
|
+
cause: DeferralCause, };
|
|
90
|
+
|
|
91
|
+
export type UpdateProgressProjection = { "state": "idle" } | { "state": "downloading",
|
|
92
|
+
/**
|
|
93
|
+
* How far through, when the source reports a length.
|
|
94
|
+
*
|
|
95
|
+
* Absent rather than zero when it does not. A source with no content
|
|
96
|
+
* length cannot produce a fraction, and a bar that invents one is
|
|
97
|
+
* worse than a bar that says it does not know.
|
|
98
|
+
*/
|
|
99
|
+
fraction: number | null, } | { "state": "verifying" } | { "state": "readyToInstall",
|
|
100
|
+
/**
|
|
101
|
+
* The version waiting.
|
|
102
|
+
*/
|
|
103
|
+
version: string, } | { "state": "installing",
|
|
104
|
+
/**
|
|
105
|
+
* The version being installed.
|
|
106
|
+
*/
|
|
107
|
+
version: string, };
|
|
108
|
+
|
|
109
|
+
export type UpdateSnapshot = {
|
|
110
|
+
/**
|
|
111
|
+
* Exact metadata protocol line.
|
|
112
|
+
*/
|
|
113
|
+
protocolVersion: UpdateProtocolVersion,
|
|
114
|
+
/**
|
|
115
|
+
* Live authority lifetime. A plain count, as the operation and
|
|
116
|
+
* notification domains carry it -- the history epoch type lives in
|
|
117
|
+
* `longhorn-history`, and depending on that domain for one integer would
|
|
118
|
+
* be a worse trade than restating it.
|
|
119
|
+
*/
|
|
120
|
+
authorityEpoch: number,
|
|
121
|
+
/**
|
|
122
|
+
* The channel this install follows.
|
|
123
|
+
*/
|
|
124
|
+
channel: Channel,
|
|
125
|
+
/**
|
|
126
|
+
* The version installed now.
|
|
127
|
+
*/
|
|
128
|
+
installedVersion: string,
|
|
129
|
+
/**
|
|
130
|
+
* The last check's outcome.
|
|
131
|
+
*/
|
|
132
|
+
availability: UpdateAvailabilityProjection,
|
|
133
|
+
/**
|
|
134
|
+
* The standing deferral, when one applies.
|
|
135
|
+
*/
|
|
136
|
+
deferral: UpdateDeferralProjection | null,
|
|
137
|
+
/**
|
|
138
|
+
* What is in flight.
|
|
139
|
+
*/
|
|
140
|
+
progress: UpdateProgressProjection, };
|
|
141
|
+
|
|
142
|
+
export type UpdateCheckCommand = {
|
|
143
|
+
/**
|
|
144
|
+
* Exact metadata protocol line.
|
|
145
|
+
*/
|
|
146
|
+
protocolVersion: UpdateProtocolVersion,
|
|
147
|
+
/**
|
|
148
|
+
* Authority lifetime observed by the caller.
|
|
149
|
+
*/
|
|
150
|
+
authorityEpoch: number, };
|
|
151
|
+
|
|
152
|
+
export type UpdateSelectChannelCommand = {
|
|
153
|
+
/**
|
|
154
|
+
* Exact metadata protocol line.
|
|
155
|
+
*/
|
|
156
|
+
protocolVersion: UpdateProtocolVersion,
|
|
157
|
+
/**
|
|
158
|
+
* Authority lifetime observed by the caller.
|
|
159
|
+
*/
|
|
160
|
+
authorityEpoch: number,
|
|
161
|
+
/**
|
|
162
|
+
* The channel to follow.
|
|
163
|
+
*/
|
|
164
|
+
channel: Channel, };
|
|
165
|
+
|
|
166
|
+
export type UpdateDeferCommand = {
|
|
167
|
+
/**
|
|
168
|
+
* Exact metadata protocol line.
|
|
169
|
+
*/
|
|
170
|
+
protocolVersion: UpdateProtocolVersion,
|
|
171
|
+
/**
|
|
172
|
+
* Authority lifetime observed by the caller.
|
|
173
|
+
*/
|
|
174
|
+
authorityEpoch: number,
|
|
175
|
+
/**
|
|
176
|
+
* The version being declined. Named, because a deferral covers the
|
|
177
|
+
* version it was taken against and nothing later.
|
|
178
|
+
*/
|
|
179
|
+
version: string,
|
|
180
|
+
/**
|
|
181
|
+
* Why.
|
|
182
|
+
*/
|
|
183
|
+
cause: DeferralCause, };
|
|
184
|
+
|
|
185
|
+
export type UpdateInstallCommand = {
|
|
186
|
+
/**
|
|
187
|
+
* Exact metadata protocol line.
|
|
188
|
+
*/
|
|
189
|
+
protocolVersion: UpdateProtocolVersion,
|
|
190
|
+
/**
|
|
191
|
+
* Authority lifetime observed by the caller.
|
|
192
|
+
*/
|
|
193
|
+
authorityEpoch: number,
|
|
194
|
+
/**
|
|
195
|
+
* The version to install.
|
|
196
|
+
*/
|
|
197
|
+
version: string, };
|
|
198
|
+
|
|
199
|
+
export type UpdateInstallAuthorizationProjection = { "status": "approved" } | { "status": "deferred",
|
|
200
|
+
/**
|
|
201
|
+
* What was in flight.
|
|
202
|
+
*/
|
|
203
|
+
cause: DeferralCause, };
|
|
204
|
+
|
|
205
|
+
export type UpdateRejectionCode = "staleAuthority" | "noOffer" | "unavailable" | "channelMismatch" | "unreachable" | "signatureRejected" | "notWritable" | "installFailed";
|
|
206
|
+
|
|
207
|
+
export type UpdateOutcomeProjection = { "status": "committed",
|
|
208
|
+
/**
|
|
209
|
+
* The state the command produced.
|
|
210
|
+
*/
|
|
211
|
+
snapshot: UpdateSnapshot, } | { "status": "rejected",
|
|
212
|
+
/**
|
|
213
|
+
* What a surface should tell the operator.
|
|
214
|
+
*/
|
|
215
|
+
code: UpdateRejectionCode,
|
|
216
|
+
/**
|
|
217
|
+
* The state as it remains.
|
|
218
|
+
*/
|
|
219
|
+
snapshot: UpdateSnapshot, };
|
|
220
|
+
|
|
221
|
+
export type UpdateChangedKind = "checked" | "channelSelected" | "deferred" | "progressed";
|
|
222
|
+
|
|
223
|
+
export type UpdateChangedEvent = {
|
|
224
|
+
/**
|
|
225
|
+
* Exact metadata protocol line.
|
|
226
|
+
*/
|
|
227
|
+
protocolVersion: UpdateProtocolVersion,
|
|
228
|
+
/**
|
|
229
|
+
* Live authority lifetime. A plain count, as the operation and
|
|
230
|
+
* notification domains carry it -- the history epoch type lives in
|
|
231
|
+
* `longhorn-history`, and depending on that domain for one integer would
|
|
232
|
+
* be a worse trade than restating it.
|
|
233
|
+
*/
|
|
234
|
+
authorityEpoch: number,
|
|
235
|
+
/**
|
|
236
|
+
* Coarse invalidation category.
|
|
237
|
+
*/
|
|
238
|
+
kind: UpdateChangedKind, };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @generated by `effigy generate:update`; do not edit.
|
|
2
|
+
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
|
+
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
|
+
// each list, because `exact()` compares every key.
|
|
5
|
+
|
|
6
|
+
export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
|
|
7
|
+
"DeferralCause": {
|
|
8
|
+
"userPostponed": ["cause"],
|
|
9
|
+
"workInFlight": ["cause", "detail"],
|
|
10
|
+
"installationNotWritable": ["cause", "detail"],
|
|
11
|
+
"externallyManaged": ["cause", "manager", "command"],
|
|
12
|
+
"installFailed": ["cause", "detail"],
|
|
13
|
+
},
|
|
14
|
+
"UpdateAvailabilityProjection": {
|
|
15
|
+
"offer": ["state", "version", "reason", "notes"],
|
|
16
|
+
"upToDate": ["state"],
|
|
17
|
+
"aheadOfChannel": ["state", "installed", "channel"],
|
|
18
|
+
"withheldByRollout": ["state", "version"],
|
|
19
|
+
"managedElsewhere": ["state", "version", "manager"],
|
|
20
|
+
},
|
|
21
|
+
"UpdateProgressProjection": {
|
|
22
|
+
"idle": ["state"],
|
|
23
|
+
"downloading": ["state", "fraction"],
|
|
24
|
+
"verifying": ["state"],
|
|
25
|
+
"readyToInstall": ["state", "version"],
|
|
26
|
+
"installing": ["state", "version"],
|
|
27
|
+
},
|
|
28
|
+
"UpdateInstallAuthorizationProjection": {
|
|
29
|
+
"approved": ["status"],
|
|
30
|
+
"deferred": ["status", "cause"],
|
|
31
|
+
},
|
|
32
|
+
"UpdateOutcomeProjection": {
|
|
33
|
+
"committed": ["status", "snapshot"],
|
|
34
|
+
"rejected": ["status", "code", "snapshot"],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const UPDATE_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
|
|
39
|
+
"DeferralCause": "cause",
|
|
40
|
+
"UpdateAvailabilityProjection": "state",
|
|
41
|
+
"UpdateProgressProjection": "state",
|
|
42
|
+
"UpdateInstallAuthorizationProjection": "status",
|
|
43
|
+
"UpdateOutcomeProjection": "status",
|
|
44
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./generated/protocol.ts";
|
|
2
|
+
// The generated field maps are public API. A consumer that mirrors these types
|
|
3
|
+
// structurally -- Poodle does, because it may not depend on Longhorn -- has no
|
|
4
|
+
// compile-time link to them, so a field added here is silent on their side.
|
|
5
|
+
// Whoever sees both can assert their shape against these and fail when it
|
|
6
|
+
// drifts.
|
|
7
|
+
export * from "./generated/fields.ts";
|
|
8
|
+
export * from "./generated/variant-fields.ts";
|
|
9
|
+
export * from "./validation.ts";
|
|
10
|
+
export * from "./ports.ts";
|
|
11
|
+
export * from "./client.ts";
|
|
12
|
+
export * from "./direct.ts";
|
|
13
|
+
export * from "./serialized.ts";
|
|
14
|
+
export * from "./controller.ts";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UpdateChangedEvent,
|
|
3
|
+
UpdateCheckCommand,
|
|
4
|
+
UpdateDeferCommand,
|
|
5
|
+
UpdateInstallCommand,
|
|
6
|
+
UpdateOutcomeProjection,
|
|
7
|
+
UpdateSelectChannelCommand,
|
|
8
|
+
UpdateSnapshot,
|
|
9
|
+
} from "./generated/protocol.ts";
|
|
10
|
+
|
|
11
|
+
export type UpdateUnlisten = () => void | Promise<void>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The raw seam.
|
|
15
|
+
*
|
|
16
|
+
* Every result is `unknown`. What arrives over a transport is untrusted until
|
|
17
|
+
* a validator says otherwise, and `UpdateClient` is what says so.
|
|
18
|
+
*/
|
|
19
|
+
export interface UpdatePort {
|
|
20
|
+
snapshot(): Promise<unknown>;
|
|
21
|
+
check(command: UpdateCheckCommand): Promise<unknown>;
|
|
22
|
+
selectChannel(command: UpdateSelectChannelCommand): Promise<unknown>;
|
|
23
|
+
defer(command: UpdateDeferCommand): Promise<unknown>;
|
|
24
|
+
install(command: UpdateInstallCommand): Promise<unknown>;
|
|
25
|
+
listen?(listener: (event: unknown) => void): UpdateUnlisten | Promise<UpdateUnlisten>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The same seam after validation. */
|
|
29
|
+
export interface CheckedUpdatePort {
|
|
30
|
+
snapshot(): Promise<UpdateSnapshot>;
|
|
31
|
+
check(command: UpdateCheckCommand): Promise<UpdateOutcomeProjection>;
|
|
32
|
+
selectChannel(command: UpdateSelectChannelCommand): Promise<UpdateOutcomeProjection>;
|
|
33
|
+
defer(command: UpdateDeferCommand): Promise<UpdateOutcomeProjection>;
|
|
34
|
+
install(command: UpdateInstallCommand): Promise<UpdateOutcomeProjection>;
|
|
35
|
+
listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UpdateCheckCommand, UpdateDeferCommand, UpdateInstallCommand, UpdateSelectChannelCommand } from "./generated/protocol.ts";
|
|
2
|
+
import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
|
|
3
|
+
export class SerializedUpdatePort implements UpdatePort {
|
|
4
|
+
constructor(readonly inner: UpdatePort) {}
|
|
5
|
+
async snapshot(): Promise<unknown> { return clone(await this.inner.snapshot()); }
|
|
6
|
+
async check(command: UpdateCheckCommand): Promise<unknown> { return clone(await this.inner.check(clone(command))); }
|
|
7
|
+
async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> { return clone(await this.inner.selectChannel(clone(command))); }
|
|
8
|
+
async defer(command: UpdateDeferCommand): Promise<unknown> { return clone(await this.inner.defer(clone(command))); }
|
|
9
|
+
async install(command: UpdateInstallCommand): Promise<unknown> { return clone(await this.inner.install(clone(command))); }
|
|
10
|
+
async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listen === undefined) return () => {}; return this.inner.listen((event) => listener(clone(event))); }
|
|
11
|
+
}
|
|
12
|
+
function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { UPDATE_FIELDS } from "./generated/fields.ts";
|
|
2
|
+
import {
|
|
3
|
+
UPDATE_AVAILABILITY_STATES,
|
|
4
|
+
UPDATE_CHANGED_KINDS,
|
|
5
|
+
UPDATE_CHANNELS,
|
|
6
|
+
UPDATE_DEFERRAL_CAUSES,
|
|
7
|
+
UPDATE_INSTALL_MANAGERS,
|
|
8
|
+
UPDATE_OFFER_REASONS,
|
|
9
|
+
UPDATE_OUTCOME_STATUSES,
|
|
10
|
+
UPDATE_PROGRESS_STATES,
|
|
11
|
+
UPDATE_PROTOCOL_VERSION,
|
|
12
|
+
UPDATE_REJECTION_CODES,
|
|
13
|
+
type UpdateChangedEvent,
|
|
14
|
+
type UpdateCheckCommand,
|
|
15
|
+
type UpdateDeferCommand,
|
|
16
|
+
type UpdateInstallCommand,
|
|
17
|
+
type UpdateOutcomeProjection,
|
|
18
|
+
type UpdateSelectChannelCommand,
|
|
19
|
+
type UpdateSnapshot,
|
|
20
|
+
} from "./generated/protocol.ts";
|
|
21
|
+
import {
|
|
22
|
+
UPDATE_VARIANT_FIELDS,
|
|
23
|
+
UPDATE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
24
|
+
} from "./generated/variant-fields.ts";
|
|
25
|
+
|
|
26
|
+
export class UpdateValidationError extends Error {
|
|
27
|
+
constructor(
|
|
28
|
+
readonly path: string,
|
|
29
|
+
message: string,
|
|
30
|
+
) {
|
|
31
|
+
super(`${path}: ${message}`);
|
|
32
|
+
this.name = "UpdateValidationError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function assertUpdateSnapshot(value: unknown): asserts value is UpdateSnapshot {
|
|
37
|
+
noPayload(value);
|
|
38
|
+
const root = object(value, "$");
|
|
39
|
+
exact(root, "$", UPDATE_FIELDS.UpdateSnapshot);
|
|
40
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
41
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
42
|
+
oneOf(root.channel, "$.channel", UPDATE_CHANNELS);
|
|
43
|
+
version(root.installedVersion, "$.installedVersion");
|
|
44
|
+
availability(root.availability, "$.availability");
|
|
45
|
+
progress(root.progress, "$.progress");
|
|
46
|
+
if (root.deferral !== null) {
|
|
47
|
+
const deferral = object(root.deferral, "$.deferral");
|
|
48
|
+
exact(deferral, "$.deferral", UPDATE_FIELDS.UpdateDeferralProjection);
|
|
49
|
+
version(deferral.version, "$.deferral.version");
|
|
50
|
+
cause(deferral.cause, "$.deferral.cause");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function assertUpdateOutcome(value: unknown): asserts value is UpdateOutcomeProjection {
|
|
55
|
+
noPayload(value);
|
|
56
|
+
const root = object(value, "$");
|
|
57
|
+
oneOf(root.status, "$.status", UPDATE_OUTCOME_STATUSES);
|
|
58
|
+
exact(root, "$", variantFields("UpdateOutcomeProjection", root, "$"));
|
|
59
|
+
if (root.status === "rejected") oneOf(root.code, "$.code", UPDATE_REJECTION_CODES);
|
|
60
|
+
assertUpdateSnapshot(root.snapshot);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function assertUpdateChangedEvent(value: unknown): asserts value is UpdateChangedEvent {
|
|
64
|
+
noPayload(value);
|
|
65
|
+
const root = object(value, "$");
|
|
66
|
+
exact(root, "$", UPDATE_FIELDS.UpdateChangedEvent);
|
|
67
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
68
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
69
|
+
oneOf(root.kind, "$.kind", UPDATE_CHANGED_KINDS);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function assertUpdateCheckCommand(value: unknown): asserts value is UpdateCheckCommand {
|
|
73
|
+
commandBase(value, UPDATE_FIELDS.UpdateCheckCommand);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function assertUpdateSelectChannelCommand(
|
|
77
|
+
value: unknown,
|
|
78
|
+
): asserts value is UpdateSelectChannelCommand {
|
|
79
|
+
commandBase(value, UPDATE_FIELDS.UpdateSelectChannelCommand);
|
|
80
|
+
oneOf(object(value, "$").channel, "$.channel", UPDATE_CHANNELS);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function assertUpdateDeferCommand(value: unknown): asserts value is UpdateDeferCommand {
|
|
84
|
+
commandBase(value, UPDATE_FIELDS.UpdateDeferCommand);
|
|
85
|
+
const root = object(value, "$");
|
|
86
|
+
version(root.version, "$.version");
|
|
87
|
+
cause(root.cause, "$.cause");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function assertUpdateInstallCommand(value: unknown): asserts value is UpdateInstallCommand {
|
|
91
|
+
commandBase(value, UPDATE_FIELDS.UpdateInstallCommand);
|
|
92
|
+
version(object(value, "$").version, "$.version");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function availability(value: unknown, path: string): void {
|
|
96
|
+
const root = object(value, path);
|
|
97
|
+
oneOf(root.state, `${path}.state`, UPDATE_AVAILABILITY_STATES);
|
|
98
|
+
exact(root, path, variantFields("UpdateAvailabilityProjection", root, path));
|
|
99
|
+
if (root.state === "offer") {
|
|
100
|
+
version(root.version, `${path}.version`);
|
|
101
|
+
oneOf(root.reason, `${path}.reason`, UPDATE_OFFER_REASONS);
|
|
102
|
+
optionalString(root.notes, `${path}.notes`);
|
|
103
|
+
}
|
|
104
|
+
// Ahead-of-channel is the one state whose fields a surface must be able to
|
|
105
|
+
// read to say anything useful: "you are on 1.3.0-nightly.4 and production
|
|
106
|
+
// publishes 1.2.9" is the whole message, and Card 154 calls it the single
|
|
107
|
+
// most likely support question the feature generates.
|
|
108
|
+
if (root.state === "aheadOfChannel") {
|
|
109
|
+
version(root.installed, `${path}.installed`);
|
|
110
|
+
version(root.channel, `${path}.channel`);
|
|
111
|
+
}
|
|
112
|
+
if (root.state === "withheldByRollout") version(root.version, `${path}.version`);
|
|
113
|
+
if (root.state === "managedElsewhere") {
|
|
114
|
+
version(root.version, `${path}.version`);
|
|
115
|
+
oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function progress(value: unknown, path: string): void {
|
|
120
|
+
const root = object(value, path);
|
|
121
|
+
oneOf(root.state, `${path}.state`, UPDATE_PROGRESS_STATES);
|
|
122
|
+
exact(root, path, variantFields("UpdateProgressProjection", root, path));
|
|
123
|
+
// Absent rather than zero when the source declares no length. A validator
|
|
124
|
+
// that coerced `null` to 0 here would put back the invented number the
|
|
125
|
+
// protocol went out of its way to avoid.
|
|
126
|
+
if (root.state === "downloading") fraction(root.fraction, `${path}.fraction`);
|
|
127
|
+
if (root.state === "readyToInstall" || root.state === "installing") {
|
|
128
|
+
version(root.version, `${path}.version`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function cause(value: unknown, path: string): void {
|
|
133
|
+
const root = object(value, path);
|
|
134
|
+
oneOf(root.cause, `${path}.cause`, UPDATE_DEFERRAL_CAUSES);
|
|
135
|
+
exact(root, path, variantFields("DeferralCause", root, path));
|
|
136
|
+
if (root.cause === "externallyManaged") {
|
|
137
|
+
oneOf(root.manager, `${path}.manager`, UPDATE_INSTALL_MANAGERS);
|
|
138
|
+
optionalString(root.command, `${path}.command`);
|
|
139
|
+
} else if (root.cause !== "userPostponed") {
|
|
140
|
+
string(root.detail, `${path}.detail`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function commandBase(value: unknown, expected: readonly string[]): void {
|
|
145
|
+
noPayload(value);
|
|
146
|
+
const root = object(value, "$");
|
|
147
|
+
exact(root, "$", expected);
|
|
148
|
+
protocol(root.protocolVersion, "$.protocolVersion");
|
|
149
|
+
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Allowed keys for one variant, from the generated map.
|
|
154
|
+
*
|
|
155
|
+
* A missing entry means the generator failed to read the union, not that a
|
|
156
|
+
* consumer sent something odd — every caller runs `oneOf` over the
|
|
157
|
+
* discriminant first, so an unknown one is already rejected by then.
|
|
158
|
+
*/
|
|
159
|
+
function variantFields(
|
|
160
|
+
type: string,
|
|
161
|
+
value: Record<string, unknown>,
|
|
162
|
+
path: string,
|
|
163
|
+
): readonly string[] {
|
|
164
|
+
const discriminant = value[UPDATE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
165
|
+
const fields = UPDATE_VARIANT_FIELDS[type]?.[discriminant as string];
|
|
166
|
+
if (fields === undefined) fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
167
|
+
return fields;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function noPayload(value: unknown): void {
|
|
171
|
+
const visit = (candidate: unknown, path: string): void => {
|
|
172
|
+
if (Array.isArray(candidate)) return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
173
|
+
if (candidate !== null && typeof candidate === "object")
|
|
174
|
+
for (const [key, child] of Object.entries(candidate)) {
|
|
175
|
+
if (key.toLocaleLowerCase().includes("payload")) fail(`${path}.${key}`, "product payload field is forbidden");
|
|
176
|
+
visit(child, `${path}.${key}`);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
visit(value, "$");
|
|
180
|
+
}
|
|
181
|
+
function object(value: unknown, path: string): Record<string, unknown> { if (value === null || typeof value !== "object" || Array.isArray(value)) fail(path, "expected object"); return value as Record<string, unknown>; }
|
|
182
|
+
function exact(value: Record<string, unknown>, path: string, expected: readonly string[]): void { const actual = Object.keys(value).sort(); const wanted = [...expected].sort(); if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) fail(path, `unexpected keys: ${actual.join(",")}`); }
|
|
183
|
+
function protocol(value: unknown, path: string): void { if (value !== UPDATE_PROTOCOL_VERSION) fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`); }
|
|
184
|
+
function positive(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail(path, "expected positive safe integer"); }
|
|
185
|
+
function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
|
|
186
|
+
function optionalString(value: unknown, path: string): void { if (value !== null) string(value, path); }
|
|
187
|
+
/** Versions are strings on the wire, as `semver::Version` serialises them. */
|
|
188
|
+
function version(value: unknown, path: string): void { string(value, path); if ((value as string).length === 0) fail(path, "expected non-empty version"); }
|
|
189
|
+
function fraction(value: unknown, path: string): void { if (value === null) return; if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) fail(path, "expected a fraction between 0 and 1, or null"); }
|
|
190
|
+
function oneOf(value: unknown, path: string, values: readonly string[]): void { if (typeof value !== "string" || !values.includes(value)) fail(path, "unsupported value"); }
|
|
191
|
+
function fail(path: string, message: string): never { throw new UpdateValidationError(path, message); }
|