@serve.zone/interfaces 32.93.0 → 32.94.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/changelog.md +6 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/gatewayarearows.d.ts +1 -11
- package/dist_ts/data/gatewayarearows.js +2 -14
- package/dist_ts/data/gatewayareas.d.ts +17 -0
- package/dist_ts/data/gatewayareas.js +21 -1
- package/dist_ts/data/gatewayareas.validation.d.ts +0 -6
- package/dist_ts/data/gatewayareas.validation.js +2 -9
- package/dist_ts/data/gatewayconnector.d.ts +62 -4
- package/dist_ts/data/gatewayconnector.js +75 -4
- package/package.json +1 -1
- package/readme.md +19 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/gatewayarearows.ts +6 -14
- package/ts/data/gatewayareas.ts +25 -0
- package/ts/data/gatewayareas.validation.ts +1 -10
- package/ts/data/gatewayconnector.ts +146 -4
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
validateControllerNonNegativeInteger,
|
|
10
10
|
validateControllerStrictJson,
|
|
11
11
|
} from '../private/controllercontract.js';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
hasExactKeys,
|
|
14
|
+
readDataElements,
|
|
15
|
+
readDataProperties,
|
|
16
|
+
readDataProperty,
|
|
17
|
+
readExactDataRecord,
|
|
18
|
+
} from '../private/dataproperties.js';
|
|
13
19
|
import { ipv4PrefixOfMapped, parseCanonicalIpAddress } from '../private/ipaddress.js';
|
|
14
20
|
import type { TCompleteKeyList } from '../private/keylist.js';
|
|
15
21
|
import { networkDigest } from '../private/networkcontract.js';
|
|
@@ -18,6 +24,13 @@ import { isGatewayClientIdText } from '../private/gatewayclientid.js';
|
|
|
18
24
|
import { clusterIngressLimits, validateClusterRouteSourceAllowList } from './clusteringress.js';
|
|
19
25
|
import { validateGatewayRouteDnsResult } from './gateway.js';
|
|
20
26
|
import { type IControllerPeerSet, validateControllerPeerSet } from './controller.js';
|
|
27
|
+
import type { TGatewayAreaListMember } from './gatewayarearows.js';
|
|
28
|
+
import {
|
|
29
|
+
gatewayAreaContentContract,
|
|
30
|
+
gatewayAreaMembers,
|
|
31
|
+
gatewayAreaSingletonMembers,
|
|
32
|
+
isGatewayAreaRowId,
|
|
33
|
+
} from './gatewayareas.js';
|
|
21
34
|
import type { TSha256Digest } from './immutableimage.js';
|
|
22
35
|
import { isLocationName } from './location.js';
|
|
23
36
|
import { isReleaseVersion } from './releaseversion.js';
|
|
@@ -63,6 +76,16 @@ export const gatewayConnectorContract = Object.freeze({
|
|
|
63
76
|
maximumDnsZones: 1024,
|
|
64
77
|
maximumHostnameLength: 253,
|
|
65
78
|
maximumRefusalDetailLength: 1024,
|
|
79
|
+
/**
|
|
80
|
+
* Entries one area refusal names (`IGatewayAreaApplyRefusal.rows`). The report travels in the
|
|
81
|
+
* hello, every status push and every apply answer: at this bound, with row ids and reasons at
|
|
82
|
+
* theirs, five refusing areas add at most about 1.1 MiB, so a status document at every bound of
|
|
83
|
+
* this contract, every free-text member at its widest JSON character, stays below the 2 MiB message
|
|
84
|
+
* cap of the controller's socket server (Cloudly): 1,584,299 bytes (`test.gatewayapplyrefusalrows`).
|
|
85
|
+
*/
|
|
86
|
+
maximumRefusalRows: 256,
|
|
87
|
+
/** Characters of one refused row's reason (`IGatewayAreaApplyRefusedRow.reason`). */
|
|
88
|
+
maximumRefusalRowReasonLength: 64,
|
|
66
89
|
maximumStorageBackendLength: 64,
|
|
67
90
|
maximumStoragePathLength: 4096,
|
|
68
91
|
/** Hostnames per `getGatewayRouteDnsResults` request. */
|
|
@@ -502,6 +525,58 @@ export const isGatewayApplyRefusal = (valueArg: unknown): valueArg is TGatewayAp
|
|
|
502
525
|
(gatewayApplyRefusals as readonly unknown[]).includes(valueArg)
|
|
503
526
|
);
|
|
504
527
|
|
|
528
|
+
/**
|
|
529
|
+
* One row an area refusal names as data (`IGatewayAreaApplyRefusal.rows`, Linus ruling 212): the
|
|
530
|
+
* row's address in the refused table and why the gateway refuses it, never a value of the row.
|
|
531
|
+
*/
|
|
532
|
+
export interface IGatewayAreaApplyRefusedRow {
|
|
533
|
+
/** A list member of the refused area (`gatewayAreaMembers` without `gatewayAreaSingletonMembers`). */
|
|
534
|
+
member: TGatewayAreaListMember;
|
|
535
|
+
/** The row's `id` in that member (`isGatewayAreaRowId`), without an unpaired UTF-16 surrogate. */
|
|
536
|
+
id: string;
|
|
537
|
+
/**
|
|
538
|
+
* Why the gateway refuses the row: one or more words of lowercase ASCII letters joined by single
|
|
539
|
+
* hyphens, at most `gatewayConnectorContract.maximumRefusalRowReasonLength` characters, such as
|
|
540
|
+
* `no-managed-domain`. The words are the gateway's own; this package judges their form only, so a
|
|
541
|
+
* new word needs no release of it, and a reader shows a word it does not know as text. The form
|
|
542
|
+
* excludes digits, dots and every separator but the hyphen, so no address, count or dotted
|
|
543
|
+
* hostname fits, and a gateway never writes a hostname here.
|
|
544
|
+
*/
|
|
545
|
+
reason: string;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Why a gateway refused one area of a desired state it accepted as a whole.
|
|
550
|
+
*
|
|
551
|
+
* `rows` names the rows of the area's table the gateway refuses, as data (Linus ruling 212): 1 to
|
|
552
|
+
* `gatewayConnectorContract.maximumRefusalRows` entries, each `(member, id, reason)` once, in no
|
|
553
|
+
* particular order. A gateway names a row only when it judged that row; a gateway that could not
|
|
554
|
+
* judge names none (Linus ruling 216). When the gateway names no row the key is omitted: every
|
|
555
|
+
* refusal of a gateway built before the member, every refusal that is not about rows, and every
|
|
556
|
+
* refusal of a gateway that could not judge; `rows: undefined` and `rows: []` are refused. It adds
|
|
557
|
+
* to `detail` and replaces nothing: `reason` and `detail` keep their meaning, and the detail still
|
|
558
|
+
* states the findings as text. It is no promise that the table applies without the named rows: the
|
|
559
|
+
* detail can state further causes.
|
|
560
|
+
*
|
|
561
|
+
* Writer rule above the bound (Linus ruling 216): the bound counts entries, so a row with two
|
|
562
|
+
* reasons takes two. A gateway that refuses more entries than the bound names the first
|
|
563
|
+
* `maximumRefusalRows` in a fixed order (member order of `gatewayAreaMembers`, then row order of the
|
|
564
|
+
* pushed table, then reason), and its `detail` starts with the total count. The controller holds
|
|
565
|
+
* what is named and pushes again, so the rest arrives in the next refusal.
|
|
566
|
+
*
|
|
567
|
+
* Reader before writer: the refusal is exact-keys like the area state and the report, so a reader
|
|
568
|
+
* built before `rows` refuses the whole report that carries it (the apply answer, the hello and the
|
|
569
|
+
* status document). The gateway learns no version of its controller and cannot gate the member on
|
|
570
|
+
* it, so the controller moves to a release that reads `rows` before any gateway writes it, and
|
|
571
|
+
* neither side goes back below such a release once a report with rows is stored.
|
|
572
|
+
*/
|
|
573
|
+
export interface IGatewayAreaApplyRefusal {
|
|
574
|
+
reason: TGatewayApplyRefusal;
|
|
575
|
+
/** 1 to `gatewayConnectorContract.maximumRefusalDetailLength` characters. */
|
|
576
|
+
detail: string;
|
|
577
|
+
rows?: IGatewayAreaApplyRefusedRow[];
|
|
578
|
+
}
|
|
579
|
+
|
|
505
580
|
/** Where one area of one gateway stands after the last desired state it received. */
|
|
506
581
|
export interface IGatewayAreaApplyState {
|
|
507
582
|
area: TGatewayConfigArea;
|
|
@@ -517,7 +592,7 @@ export interface IGatewayAreaApplyState {
|
|
|
517
592
|
* owns that no document carried is `applied` with `revision: null`.
|
|
518
593
|
*/
|
|
519
594
|
state: 'applied' | 'rejected' | 'not-attempted';
|
|
520
|
-
refusal:
|
|
595
|
+
refusal: IGatewayAreaApplyRefusal | null;
|
|
521
596
|
}
|
|
522
597
|
|
|
523
598
|
/** What a gateway applied, as `applyDesiredState` answers and the status document carries it. */
|
|
@@ -670,6 +745,14 @@ const desiredStateKeys: TCompleteKeyList<IGatewayDesiredState, typeof desiredSta
|
|
|
670
745
|
const areaApplyStateKeyList = ['area', 'owner', 'digest', 'revision', 'state', 'refusal'] as const;
|
|
671
746
|
const areaApplyStateKeys: TCompleteKeyList<IGatewayAreaApplyState, typeof areaApplyStateKeyList> =
|
|
672
747
|
areaApplyStateKeyList;
|
|
748
|
+
const areaApplyRefusalKeyList = ['reason', 'detail', 'rows'] as const;
|
|
749
|
+
const areaApplyRefusalKeys: TCompleteKeyList<IGatewayAreaApplyRefusal, typeof areaApplyRefusalKeyList> =
|
|
750
|
+
areaApplyRefusalKeyList;
|
|
751
|
+
/** `rows` is optional: a refusal of a gateway built before it carries exactly these. */
|
|
752
|
+
const areaApplyRefusalRequiredKeys = ['reason', 'detail'] as const satisfies readonly (keyof IGatewayAreaApplyRefusal)[];
|
|
753
|
+
const areaApplyRefusedRowKeyList = ['member', 'id', 'reason'] as const;
|
|
754
|
+
const areaApplyRefusedRowKeys: TCompleteKeyList<IGatewayAreaApplyRefusedRow, typeof areaApplyRefusedRowKeyList> =
|
|
755
|
+
areaApplyRefusedRowKeyList;
|
|
673
756
|
const applyReportKeyList = ['epoch', 'appliedRevision', 'areas'] as const;
|
|
674
757
|
const applyReportKeys: TCompleteKeyList<IGatewayApplyReport, typeof applyReportKeyList> = applyReportKeyList;
|
|
675
758
|
const statusDocumentKeyList = [
|
|
@@ -832,6 +915,62 @@ export const validateGatewayDesiredState = (
|
|
|
832
915
|
];
|
|
833
916
|
};
|
|
834
917
|
|
|
918
|
+
const refusedRowReason = /^[a-z]+(?:-[a-z]+)*$/;
|
|
919
|
+
|
|
920
|
+
/** A member of the area's `gatewayAreaMembers` that holds rows, not one value. */
|
|
921
|
+
const isAreaListMember = (areaArg: TGatewayConfigArea, memberArg: unknown): boolean => (
|
|
922
|
+
typeof memberArg === 'string'
|
|
923
|
+
&& (gatewayAreaMembers[areaArg] as readonly string[]).includes(memberArg)
|
|
924
|
+
&& !(gatewayAreaSingletonMembers[areaArg] as readonly string[]).includes(memberArg)
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* The rows one area refusal names (`IGatewayAreaApplyRefusal.rows`): 1 to `maximumRefusalRows`
|
|
929
|
+
* entries of exactly `{ member, id, reason }`, each triple once. The member is judged against the
|
|
930
|
+
* refused area only when that area is one; an unknown area is refused by its own check.
|
|
931
|
+
*/
|
|
932
|
+
const validateRefusedRows = (valueArg: unknown, areaArg: unknown, pathArg: string): string[] => {
|
|
933
|
+
const { maximumRefusalRows, maximumRefusalRowReasonLength } = gatewayConnectorContract;
|
|
934
|
+
const rows = readDataElements(valueArg, maximumRefusalRows);
|
|
935
|
+
if (rows === null || rows.length === 0) {
|
|
936
|
+
return [`${pathArg} must be a dense list of 1 to ${maximumRefusalRows} rows`];
|
|
937
|
+
}
|
|
938
|
+
const errors: string[] = [];
|
|
939
|
+
const named = new Set<string>();
|
|
940
|
+
let repeated = false;
|
|
941
|
+
rows.forEach((rowArg, indexArg) => {
|
|
942
|
+
const path = `${pathArg}[${indexArg}]`;
|
|
943
|
+
const row = readExactDataRecord(rowArg, areaApplyRefusedRowKeys);
|
|
944
|
+
if (row === null) {
|
|
945
|
+
errors.push(`${path} must use its exact schema`);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (isGatewayConfigArea(areaArg) && !isAreaListMember(areaArg, row.member)) {
|
|
949
|
+
errors.push(`${path} member must be a list member of the ${areaArg} area`);
|
|
950
|
+
}
|
|
951
|
+
// A row id of a table meets the table's strict-JSON check, which refuses an unpaired surrogate;
|
|
952
|
+
// the report does not run that check, so the id is held to it here (Linus ruling 216 point 3).
|
|
953
|
+
if (!isGatewayAreaRowId(row.id) || validateControllerStrictJson(row.id, `${path} id`).length > 0) {
|
|
954
|
+
errors.push(`${path} id must be a row id of 1 to ${gatewayAreaContentContract.maximumRowIdLength} characters `
|
|
955
|
+
+ 'without a control character or an unpaired UTF-16 surrogate');
|
|
956
|
+
}
|
|
957
|
+
if (typeof row.reason !== 'string' || row.reason.length > maximumRefusalRowReasonLength
|
|
958
|
+
|| !refusedRowReason.test(row.reason)) {
|
|
959
|
+
errors.push(`${path} reason must be lowercase letter words joined by single hyphens, at most `
|
|
960
|
+
+ `${maximumRefusalRowReasonLength} characters`);
|
|
961
|
+
}
|
|
962
|
+
if (typeof row.member === 'string' && typeof row.id === 'string' && typeof row.reason === 'string') {
|
|
963
|
+
const key = JSON.stringify([row.member, row.id, row.reason]);
|
|
964
|
+
repeated ||= named.has(key);
|
|
965
|
+
named.add(key);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
if (repeated) {
|
|
969
|
+
errors.push(`${pathArg} must name each member, id and reason once`);
|
|
970
|
+
}
|
|
971
|
+
return errors;
|
|
972
|
+
};
|
|
973
|
+
|
|
835
974
|
const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] => {
|
|
836
975
|
const record = readExactDataRecord(valueArg, areaApplyStateKeys);
|
|
837
976
|
if (record === null) {
|
|
@@ -857,8 +996,8 @@ const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] =>
|
|
|
857
996
|
if (record.state === 'applied') {
|
|
858
997
|
errors.push(`${pathArg} refusal must be null for an applied area`);
|
|
859
998
|
}
|
|
860
|
-
const refusal =
|
|
861
|
-
if (refusal === null) {
|
|
999
|
+
const refusal = readDataProperties(record.refusal);
|
|
1000
|
+
if (refusal === null || !hasExactKeys(refusal, areaApplyRefusalRequiredKeys, areaApplyRefusalKeys)) {
|
|
862
1001
|
errors.push(`${pathArg} refusal must be null or use its exact schema`);
|
|
863
1002
|
return errors;
|
|
864
1003
|
}
|
|
@@ -867,6 +1006,9 @@ const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] =>
|
|
|
867
1006
|
}
|
|
868
1007
|
errors.push(...validateBoundedString(refusal.detail, `${pathArg} refusal detail`,
|
|
869
1008
|
gatewayConnectorContract.maximumRefusalDetailLength));
|
|
1009
|
+
if (Object.hasOwn(refusal, 'rows')) {
|
|
1010
|
+
errors.push(...validateRefusedRows(refusal.rows, record.area, `${pathArg} refusal rows`));
|
|
1011
|
+
}
|
|
870
1012
|
return errors;
|
|
871
1013
|
};
|
|
872
1014
|
|