@serve.zone/interfaces 32.76.0 → 32.78.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.
@@ -1,6 +1,6 @@
1
1
  import * as plugins from '../plugins.js';
2
2
  import type { IControllerPeerSet } from '../data/controller.js';
3
- import type { IGateway, IGatewayAdoptionFacts, IGatewayAreaExport, IGatewayApplyReport, IGatewayDesiredState, IGatewayStatusDocument, IRegisterGatewaySessionRequest, TGatewayConfigArea } from '../data/gatewayconnector.js';
3
+ import type { IAdoptGatewayResponse, IGateway, IGatewayAdoptionFacts, IGatewayAreaExport, IGatewayApplyReport, IGatewayDesiredState, IGatewayStatusDocument, IRegisterGatewaySessionRequest, TGatewayConfigArea } from '../data/gatewayconnector.js';
4
4
  import type { ILocationScope } from '../data/location.js';
5
5
  import type { IIdentityCredential } from '../data/user.js';
6
6
  /**
@@ -9,6 +9,10 @@ import type { IIdentityCredential } from '../data/user.js';
9
9
  * answers the gateway's credential once; adopting again with a new code raises the credential
10
10
  * generation and the previous generation stops authenticating. Exclude bodies from logs: the
11
11
  * request carries the code and the answer the bearer.
12
+ *
13
+ * The controller checks the code first (`adoption-code-unknown`, `adoption-code-expired`,
14
+ * `adoption-code-used`) and then the facts' `adoptedAs` against it in the same transaction
15
+ * (`controller-mismatch`, `gateway-mismatch`), refusing with the code left unconsumed.
12
16
  */
13
17
  export interface IReq_Gateway_Cloudly_AdoptGateway extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Gateway_Cloudly_AdoptGateway> {
14
18
  method: 'adoptGateway';
@@ -17,22 +21,8 @@ export interface IReq_Gateway_Cloudly_AdoptGateway extends plugins.typedrequestI
17
21
  /** `data.validateGatewayAdoptionFacts`. */
18
22
  facts: IGatewayAdoptionFacts;
19
23
  };
20
- response: {
21
- gatewayId: string;
22
- /** The gateway stores it and refuses any other controller and any older epoch from then on. */
23
- controller: IControllerPeerSet;
24
- /** Answered once; the gateway authenticates its socket as `userId` with `bearer`. */
25
- credential: {
26
- userId: string;
27
- generation: number;
28
- bearer: string;
29
- };
30
- /**
31
- * The gateway client the controller's existing `requests.gateway` and `requests.mail` calls are
32
- * bound to once they run over the connector socket; `null` when the controller binds none.
33
- */
34
- controllerGatewayClientId: string | null;
35
- };
24
+ /** `data.validateAdoptGatewayResponse`; the gateway checks it before it writes anything. */
25
+ response: IAdoptGatewayResponse;
36
26
  }
37
27
  /**
38
28
  * The hello a gateway sends after `registerCloudlyClientSession` on its socket: the gateway is the
@@ -60,7 +50,14 @@ export interface IReq_Gateway_Cloudly_PushGatewayStatus extends plugins.typedreq
60
50
  }
61
51
  /**
62
52
  * The controller pushes a gateway's whole desired state; the gateway answers what it applied.
53
+ *
63
54
  * A document equal by `(epoch, revision)` to the one applied is answered with the stored report.
55
+ * The gateway refuses a whole document on the request and never stores the refusal in its report:
56
+ * `request-invalid` when `data.validateGatewayDesiredState` fails, `controller-mismatch` for another
57
+ * controller's document, `gateway-mismatch` for another gateway's, `controller-epoch-ahead` for one
58
+ * whose epoch is above the controller epoch the gateway stored, and `desired-state-stale` for an
59
+ * older one, whose text names the applied epoch and revision. An area of an accepted document is
60
+ * refused per area in the report (`data.gatewayApplyRefusals`).
64
61
  */
65
62
  export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Gateway_ApplyDesiredState> {
66
63
  method: 'applyDesiredState';
@@ -75,6 +72,8 @@ export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedreq
75
72
  /**
76
73
  * The controller reads one gateway-owned area table, the first step of taking the area over: it
77
74
  * writes an import revision of it and pushes it back with `takeover.localDigest` set to `digest`.
75
+ * An area the gateway does not take from a controller (`controllerAreas`) is refused
76
+ * `unsupported-area` (`data.gatewayConnectorRefusals`).
78
77
  */
79
78
  export interface IReq_Cloudly_Gateway_ExportGatewayArea extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Cloudly_Gateway_ExportGatewayArea> {
80
79
  method: 'exportGatewayArea';
@@ -2,6 +2,7 @@ import * as plugins from '../plugins.js';
2
2
  import * as secretData from '../data/secret.js';
3
3
  import * as settingsData from '../data/settings.js';
4
4
  import { readDataProperties, hasExactKeys } from '../private/dataproperties.js';
5
+ import { isGatewayClientIdText } from '../private/gatewayclientid.js';
5
6
  const hasJwtIdentity = (valueArg) => {
6
7
  const identity = readDataProperties(valueArg);
7
8
  return identity !== null && typeof identity.jwt === 'string' && identity.jwt.length > 0;
@@ -28,10 +29,7 @@ const validateExpectedGatewayTarget = (urlArg, clientIdArg) => {
28
29
  || url.hash !== '') {
29
30
  errors.push('bootstrap expectedGatewayUrl must be an HTTPS URL without credentials, query or fragment');
30
31
  }
31
- if (typeof clientIdArg !== 'string'
32
- || clientIdArg.length === 0
33
- || clientIdArg.length > settingsData.externalGatewayBootstrapContract.maximumGatewayClientIdLength
34
- || !/^[\x21-\x7e]+$/.test(clientIdArg)) {
32
+ if (!isGatewayClientIdText(clientIdArg)) {
35
33
  errors.push('bootstrap expectedGatewayClientId must be a bounded identifier without whitespace');
36
34
  }
37
35
  return errors;
@@ -89,4 +87,4 @@ export const validateGetExternalGatewayEnrollmentStateRequest = (requestArg) =>
89
87
  }
90
88
  return errors;
91
89
  };
92
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0dGluZ3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9yZXF1ZXN0cy9zZXR0aW5ncy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGVBQWUsQ0FBQztBQUN6QyxPQUFPLEtBQUssVUFBVSxNQUFNLG1CQUFtQixDQUFDO0FBQ2hELE9BQU8sS0FBSyxZQUFZLE1BQU0scUJBQXFCLENBQUM7QUFJcE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SxDQUFDO1FBQ3RDLE1BQU0sQ0FBQyxJQUFJLENBQUMsb0RBQW9ELENBQUMsQ0FBQztJQUNwRSxDQUFDO0lBQ0QsT0FBTyxNQUFNLENBQUM7QUFDaEIsQ0FBQyxDQUFDIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serve.zone/interfaces",
3
- "version": "32.76.0",
3
+ "version": "32.78.0",
4
4
  "private": false,
5
5
  "description": "Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.",
6
6
  "exports": {
package/readme.md CHANGED
@@ -4338,26 +4338,92 @@ A gateway (dcrouter) dials its controller (Cloudly) on the controller's typedsoc
4338
4338
  never dialled once adopted. It authenticates with `registerCloudlyClientSession` as the machine
4339
4339
  identity it received at adoption, then says hello with `registerGatewaySession`; the gateway is the
4340
4340
  one that identity names and is never a request field. The controller records its gateways as
4341
- `data.IGateway`: every gateway stands in a location, and its `connection` is either `legacy` (the
4342
- dcrouter the controller still dials at a URL as a gateway client) or `adopted` (machine user and
4343
- credential generation, no URL).
4341
+ `data.IGateway` (`data.validateGateway`): every gateway stands in a location, carries a name unique
4342
+ among the controller's gateways (`data.isGatewayName`, the location name rule: one lowercase RFC 1123
4343
+ label of 1 to 63 characters) and its `forwardSourcePrefixes` as canonical address prefixes
4344
+ (`192.0.2.10/32`, the rules of `data.validateClusterRouteSourceAllowList`, empty when none). The
4345
+ adoption facts and status documents state plain addresses (`publicIps`, `proxyIps`,
4346
+ `forwardSourceAddresses`), never IPv4-mapped, and a controller writes such an address into the record
4347
+ as its host prefix (`/32`, `/128`). Its
4348
+ `connection` is either `legacy` (the dcrouter the controller still dials at a canonical http(s) URL
4349
+ as a gateway client) or `adopted` (machine user, credential generation and `controllerGatewayClientId`,
4350
+ no URL). A gateway's machine identity has the role `gateway` (`data.IIdentity`, `data.IUser`), so a
4351
+ guard that names roles excludes it by type.
4352
+
4353
+ - Controller gateway: the one gateway the controller's own gateway-client calls are bound to, a
4354
+ `legacy` gateway by its `gatewayClientId` and an `adopted` one by a non-null
4355
+ `controllerGatewayClientId`. A `new` adoption binds `null`; an `existing` re-adoption of a legacy
4356
+ gateway moves its `gatewayClientId` into `controllerGatewayClientId`; a re-adoption of an adopted
4357
+ gateway keeps the binding unchanged, `null` included; no operation changes a non-null binding to
4358
+ another value.
4359
+ - Socket calls, by how a call authenticates: the adopted controller gateway serves on the connector
4360
+ socket every call it serves under gateway-client control auth, which is the `requests.gateway`
4361
+ calls with `identity?`/`apiToken?`, and the `requests.mail` and `requests.webpush` calls with
4362
+ `IMailControlRequestAuth`/`IWebPushControlRequestAuth`; also `reprovisionCertificateDomain` and
4363
+ `getWebPushServiceStatus`, which the controller calls. Off the socket, on HTTP: the credential
4364
+ handover (`provisionGatewayClientCredential`, `finalizeGatewayClientCredential`) and every
4365
+ submission- or app-credential call workloads make (`enqueueMail`, `getMailDeliveryStatus`,
4366
+ `registerServiceMailEndpoint`, `enqueueWebPush`, `cancelWebPush`, `getWebPushDeliveryStatus`). The
4367
+ socket is authenticated as the gateway, so its calls carry no credential: `apiToken` is optional
4368
+ on `syncGatewayClientDnsRecord`, `getGatewayClientCertificate` and
4369
+ `releaseGatewayClientCertificate`, required over HTTP and omitted over the socket. A gateway adopted
4370
+ without a binding refuses them `gateway-client-unbound`.
4371
+ - Refusals: either side refuses a connector request, the controller a legacy gateway setting it no
4372
+ longer owns, and the gateway an HTTP call with a token of its controller-bound gateway client
4373
+ (`controller-gateway-adopted`), with one of `data.gatewayConnectorRefusals` (`data.isGatewayConnectorRefusal`), as
4374
+ a `TypedResponseError` whose `errorData` is `data.IGatewayConnectorRefusalErrorData`
4375
+ (`{ code, retryable: false }`) and whose text carries the detail: `adoption-code-unknown`,
4376
+ `adoption-code-expired`, `adoption-code-used`, `gateway-name-taken`, `gateway-not-found`,
4377
+ `controller-origin-invalid`, `credential-generation-stale`, `registration-sequence-not-advancing`,
4378
+ `controller-mismatch`, `controller-epoch-ahead`, `gateway-session-required`, `status-too-frequent`
4379
+ (send the newest status again after the interval), `controller-gateway-adopted`, `request-invalid`
4380
+ (the text carries the validator's sentences), `desired-state-stale` (the text names the applied
4381
+ epoch and revision), `gateway-mismatch`, `unsupported-area` (an export of an area the gateway does
4382
+ not take) and `gateway-client-unbound`. An unknown location stays `location-not-found`
4383
+ (`data.locationRefusals`).
4384
+ - Revisions: `data.IControllerRevision` is one record of the controller-wide sequence, validated
4385
+ exactly by `data.validateControllerRevision`: the actor's `sub` is `null` exactly for `system`,
4386
+ the bounds of `data.controllerRevisionContract` only ever rise,
4387
+ `changes` holds 1 to `data.controllerRevisionContract.maximumChanges` (1024) changes of strict
4388
+ canonical JSON, each object once, never `null` on both sides.
4344
4389
 
4345
4390
  - Adoption: an administrator makes a one-time code (`createGatewayAdoptionCode`, for a new gateway
4346
4391
  in an existing location or for an existing gateway record) and runs the answered `command` on
4347
4392
  the gateway's host. The gateway redeems it with `adoptGateway` and its `data.IGatewayAdoptionFacts`;
4348
- the controller answers the gateway id, its `data.IControllerPeerSet` and the credential, once.
4349
- Adopting again raises the credential generation. Keep both bodies out of logs.
4393
+ the controller answers the gateway id, its `data.IControllerPeerSet` and the credential, once
4394
+ (`data.IAdoptGatewayResponse`). Adopting again raises the credential generation. Keep both bodies
4395
+ out of logs.
4396
+ - Adopted as: the facts state `adoptedAs`, filled by the gateway from its own connector store: `null`
4397
+ when it was never adopted, otherwise `{ controllerId, gatewayId }` it is adopted as. It is no
4398
+ security control (a gateway can state anything; the code stays the authority) and only keeps two
4399
+ honest stores consistent. Inside the transaction that would consume the code, after the code
4400
+ checks (`adoption-code-unknown`, `-expired`, `-used`), the controller refuses with the code left
4401
+ unconsumed: `controller-mismatch` when `adoptedAs.controllerId` is not this controller,
4402
+ `gateway-mismatch` for a `new` code while `adoptedAs` is set or for an `existing` code naming
4403
+ another gateway than `adoptedAs.gatewayId`; otherwise, `null` included, the adoption proceeds.
4404
+ - Adoption answer: the gateway checks the whole answer with `data.validateAdoptGatewayResponse`
4405
+ before it writes anything: canonical identifiers for `gatewayId` and `credential.userId`,
4406
+ `data.validateControllerPeerSet` for `controller`, a positive counter for `credential.generation`,
4407
+ a `credential.bearer` of 1 to `data.gatewayConnectorContract.maximumBearerBytes` (16384, the
4408
+ Cloudly client-session credential bound) UTF-8 bytes, and `controllerGatewayClientId` `null` or a
4409
+ gateway client id of 1 to 253 visible ASCII characters, exact keys at every level. No refusal
4410
+ carries the bearer.
4350
4411
  - Peers: a gateway stores the peer set (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) and
4351
4412
  refuses any other controller and any older epoch. A takeover and a database restore raise the
4352
4413
  epoch. Later controller contracts extend `data.IControllerPeerSet` and never define a second one.
4353
4414
  - Desired state: the controller pushes the whole `data.IGatewayDesiredState` (`applyDesiredState`):
4354
4415
  `{ gatewayId, controllerId, epoch, revision, areas }`, one whole table per controller-owned area.
4355
4416
  Documents order by `(epoch, revision)` (`data.compareControllerRevisionOrder`): newer applies,
4356
- equal replays the stored report, older is refused `stale`. A gateway validates every table first,
4417
+ equal replays the stored report, older is refused `desired-state-stale`. A document whose epoch is
4418
+ above the controller epoch the gateway stored is refused `controller-epoch-ahead` before anything
4419
+ applies. A refusal of the whole document (`request-invalid`, `controller-mismatch`,
4420
+ `gateway-mismatch`, `controller-epoch-ahead`, `desired-state-stale`) is answered on the request and
4421
+ never stored in a report. A gateway validates every table first,
4357
4422
  skips an area whose digest it already serves, applies the rest in
4358
4423
  `data.gatewayConfigAreaApplyOrder` (`security`, `dns`, `routes`, `mail`, `edges`) and stops at the
4359
4424
  first failure; `data.IGatewayApplyReport.appliedRevision` advances only when the whole document
4360
- applied. Refusals are `data.gatewayApplyRefusals`.
4425
+ applied. Per-area refusals are `data.gatewayApplyRefusals` (`invalid-table`, `unsupported-area`,
4426
+ `local-changed-since-export`, `apply-failed`).
4361
4427
  - Area content is untyped here (`content: unknown`); each area's content type and validator ship in
4362
4428
  the release that moves that area. Its digest is `data.computeGatewayAreaTableDigest(area, content)`,
4363
4429
  `sha256:<hex>` of the strict canonical JSON of the domain `serve.zone/gateway-area-table`, the area
@@ -4379,7 +4445,8 @@ credential generation, no URL).
4379
4445
  `data.gatewayConnectorContract.maximumListeningPortRanges` (1024) per transport; one port may
4380
4446
  appear in both lists. A gateway lowercases its zone names before reporting them in `dnsZones`.
4381
4447
  - Validators name every refusal and never run an accessor: `data.validateControllerPeerSet`,
4382
- `data.validateGatewayAdoptionFacts`, `data.validateRegisterGatewaySessionRequest`,
4448
+ `data.validateControllerRevision`, `data.validateGateway`, `data.validateGatewayAdoptionFacts`,
4449
+ `data.validateAdoptGatewayResponse`, `data.validateRegisterGatewaySessionRequest`,
4383
4450
  `data.validateGatewayDesiredState` (envelope only), `data.validateGatewayApplyReport`,
4384
4451
  `data.validateGatewayStatusDocument` and `data.validateGatewayAreaExport`.
4385
4452
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.76.0',
6
+ version: '32.78.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
package/ts/data/backup.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { TBackupRestoreRefusal } from './backuprestorerefusal.js';
2
2
  import type { ICorestoreDatabaseAllocationReference } from './corestore.js';
3
+ import type { IIdentity } from './user.js';
3
4
 
4
5
  export type TBackupStatus =
5
6
  | 'pending'
@@ -221,7 +222,8 @@ export interface IArchivePruneResult {
221
222
  export interface IIsolatedRestoreActor {
222
223
  userId: string;
223
224
  type: 'human' | 'machine' | 'system';
224
- role?: 'admin' | 'user' | 'api' | 'cluster';
225
+ /** The acting identity's role, so the projection admits every role an identity can hold. */
226
+ role?: IIdentity['role'];
225
227
  }
226
228
 
227
229
  export type TIsolatedRestoreStatus =
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  validateControllerCounter,
3
3
  validateControllerIdentifier,
4
+ validateControllerNonNegativeInteger,
4
5
  validateControllerOrigin,
6
+ validateControllerStrictJson,
5
7
  } from '../private/controllercontract.js';
6
- import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
8
+ import { readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
9
+ import type { TCompleteKeyList } from '../private/keylist.js';
7
10
 
8
11
  /**
9
12
  * The controller as the components that dial it know it: which controller they belong to, which
@@ -41,9 +44,16 @@ export const compareControllerRevisionOrder = (
41
44
  rightArg: Readonly<{ epoch: number; revision: number }>,
42
45
  ): number => Math.sign(leftArg.epoch - rightArg.epoch) || Math.sign(leftArg.revision - rightArg.revision);
43
46
 
47
+ /** The bounds of `validateControllerRevision`; they may only rise, never fall. */
48
+ export const controllerRevisionContract = Object.freeze({
49
+ maximumDisplayNameLength: 256,
50
+ maximumChanges: 1024,
51
+ } as const);
52
+
44
53
  /**
45
54
  * One record of the controller-wide revision sequence, written in the same transaction as the
46
- * change it records. A secret appears in `changes` by its ids and versions only, never by value.
55
+ * change it records (`validateControllerRevision`). A secret appears in `changes` by its ids and
56
+ * versions only, never by value.
47
57
  */
48
58
  export interface IControllerRevision {
49
59
  /** A positive safe integer from the one controller-wide sequence. */
@@ -54,11 +64,19 @@ export interface IControllerRevision {
54
64
  at: number;
55
65
  actor: {
56
66
  kind: 'person' | 'machine' | 'system';
57
- /** The acting identity's subject; `null` for the controller itself (`system`). */
67
+ /**
68
+ * The acting identity's subject, the controller's user id of the person or machine; `null`
69
+ * exactly for the controller itself (`system`).
70
+ */
58
71
  sub: string | null;
72
+ /** 1 to `controllerRevisionContract.maximumDisplayNameLength` characters. */
59
73
  displayName: string;
60
74
  };
61
75
  kind: 'change' | 'adoption' | 'import' | 'revert';
76
+ /**
77
+ * 1 to `controllerRevisionContract.maximumChanges` changes, each object (`objectKind`,
78
+ * `objectId`) at most once.
79
+ */
62
80
  changes: {
63
81
  objectKind: string;
64
82
  objectId: string;
@@ -104,3 +122,97 @@ export const validateControllerPeerSet = (
104
122
  }
105
123
  return errors;
106
124
  };
125
+
126
+ const revisionKeyList = ['revision', 'epoch', 'at', 'actor', 'kind', 'changes'] as const;
127
+ const revisionKeys: TCompleteKeyList<IControllerRevision, typeof revisionKeyList> = revisionKeyList;
128
+ const actorKeyList = ['kind', 'sub', 'displayName'] as const;
129
+ const actorKeys: TCompleteKeyList<IControllerRevision['actor'], typeof actorKeyList> = actorKeyList;
130
+ const changeKeyList = ['objectKind', 'objectId', 'before', 'after'] as const;
131
+ const changeKeys: TCompleteKeyList<IControllerRevision['changes'][number], typeof changeKeyList> = changeKeyList;
132
+ const actorKinds: readonly IControllerRevision['actor']['kind'][] = ['person', 'machine', 'system'];
133
+ const revisionKinds: readonly IControllerRevision['kind'][] = ['change', 'adoption', 'import', 'revert'];
134
+
135
+ const validateRevisionActor = (valueArg: unknown, pathArg: string): string[] => {
136
+ const actor = readExactDataRecord(valueArg, actorKeys);
137
+ if (actor === null) {
138
+ return [`${pathArg} must use its exact schema`];
139
+ }
140
+ const errors: string[] = [];
141
+ if (!actorKinds.some((kindArg) => kindArg === actor.kind)) {
142
+ errors.push(`${pathArg} kind must be one of ${actorKinds.join(', ')}`);
143
+ } else if (actor.kind === 'system') {
144
+ if (actor.sub !== null) {
145
+ errors.push(`${pathArg} sub must be null for the system actor`);
146
+ }
147
+ } else {
148
+ errors.push(...validateControllerIdentifier(actor.sub, `${pathArg} sub`));
149
+ }
150
+ const { maximumDisplayNameLength } = controllerRevisionContract;
151
+ if (typeof actor.displayName !== 'string' || actor.displayName.length === 0
152
+ || actor.displayName.length > maximumDisplayNameLength) {
153
+ errors.push(`${pathArg} displayName must be a string of 1 to ${maximumDisplayNameLength} characters`);
154
+ }
155
+ return errors;
156
+ };
157
+
158
+ const validateRevisionChange = (valueArg: unknown, pathArg: string): string[] => {
159
+ const change = readExactDataRecord(valueArg, changeKeys);
160
+ if (change === null) {
161
+ return [`${pathArg} must use its exact schema`];
162
+ }
163
+ const errors = [
164
+ ...validateControllerIdentifier(change.objectKind, `${pathArg} objectKind`),
165
+ ...validateControllerIdentifier(change.objectId, `${pathArg} objectId`),
166
+ ...validateControllerStrictJson(change.before, `${pathArg} before`),
167
+ ...validateControllerStrictJson(change.after, `${pathArg} after`),
168
+ ];
169
+ if (change.before === null && change.after === null) {
170
+ errors.push(`${pathArg} must state the object before or after the change`);
171
+ }
172
+ return errors;
173
+ };
174
+
175
+ /**
176
+ * Validates one controller revision and names every reason it is refused.
177
+ *
178
+ * The record alone: whether the revision is the next of the controller's sequence, its epoch the
179
+ * controller's current one, and its changes what the transaction wrote, is the controller's to
180
+ * judge against its own store.
181
+ */
182
+ export const validateControllerRevision = (
183
+ valueArg: unknown,
184
+ pathArg = 'controller revision',
185
+ ): string[] => {
186
+ const record = readExactDataRecord(valueArg, revisionKeys);
187
+ if (record === null) {
188
+ return [`${pathArg} must use its exact schema`];
189
+ }
190
+ const errors = [
191
+ ...validateControllerCounter(record.revision, `${pathArg} revision`),
192
+ ...validateControllerCounter(record.epoch, `${pathArg} epoch`),
193
+ ...validateControllerNonNegativeInteger(record.at, `${pathArg} at`),
194
+ ...validateRevisionActor(record.actor, `${pathArg} actor`),
195
+ ];
196
+ if (!revisionKinds.some((kindArg) => kindArg === record.kind)) {
197
+ errors.push(`${pathArg} kind must be one of ${revisionKinds.join(', ')}`);
198
+ }
199
+ const { maximumChanges } = controllerRevisionContract;
200
+ const changes = readDataElements(record.changes, maximumChanges);
201
+ if (changes === null || changes.length === 0) {
202
+ errors.push(`${pathArg} changes must be a dense list of 1 to ${maximumChanges} changes`);
203
+ return errors;
204
+ }
205
+ changes.forEach((changeArg, indexArg) => {
206
+ errors.push(...validateRevisionChange(changeArg, `${pathArg} changes[${indexArg}]`));
207
+ });
208
+ // A change whose object is not stated as two strings is refused by its own validator and left out.
209
+ const objects = changes.flatMap((changeArg) => {
210
+ const objectKind = readDataProperty(changeArg, 'objectKind')?.value;
211
+ const objectId = readDataProperty(changeArg, 'objectId')?.value;
212
+ return typeof objectKind === 'string' && typeof objectId === 'string' ? [`${objectKind}\u0000${objectId}`] : [];
213
+ });
214
+ if (new Set(objects).size !== objects.length) {
215
+ errors.push(`${pathArg} changes must name each object once`);
216
+ }
217
+ return errors;
218
+ };