@powerhousedao/shared 6.2.3-dev.33 → 6.2.3-dev.35
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/dist/clis/args/index.d.mts +1 -1
- package/dist/clis/args/{service-BBx5GDTc.d.mts → service-CHjY5epu.d.mts} +3 -3
- package/dist/clis/args/{service-BBx5GDTc.d.mts.map → service-CHjY5epu.d.mts.map} +1 -1
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/build-pieces.d.mts +1 -1
- package/dist/clis/constants.d.mts +1 -1
- package/dist/clis/index.d.mts +3 -2
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +5 -2
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/{types-nzer4WIr.d.mts → types-DM26OWlT.d.mts} +2 -2
- package/dist/clis/{types-nzer4WIr.d.mts.map → types-DM26OWlT.d.mts.map} +1 -1
- package/dist/{config-loader-C6dZB_iX.js → config-loader-CXhzL512.js} +7 -2
- package/dist/{config-loader-C6dZB_iX.js.map → config-loader-CXhzL512.js.map} +1 -1
- package/dist/connect/config-loader.d.ts +2 -1
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/config-loader.js +2 -2
- package/dist/connect/index.d.ts +3 -3
- package/dist/connect/index.js +2 -2
- package/dist/document-drive/index.d.ts +3 -4
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-model/index.d.ts +2 -3
- package/dist/document-model/index.js +7 -322
- package/dist/document-model/index.js.map +1 -1
- package/dist/{index-5gwOhPG5.d.ts → index-DdXp-CVw.d.ts} +2 -2
- package/dist/{index-5gwOhPG5.d.ts.map → index-DdXp-CVw.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.js +58 -3
- package/dist/processors/index.js.map +1 -1
- package/dist/purge-v06m_oGz.js +381 -0
- package/dist/purge-v06m_oGz.js.map +1 -0
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +10 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +2 -2
- package/dist/{types-CI3ren9F.d.ts → types-B11NGQOQ.d.ts} +20 -12
- package/dist/types-B11NGQOQ.d.ts.map +1 -0
- package/dist/{types-CmeoQg_J.d.ts → types-CFbd2nan.d.ts} +1489 -468
- package/dist/types-CFbd2nan.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/index-D6833Siv.d.ts +0 -939
- package/dist/index-D6833Siv.d.ts.map +0 -1
- package/dist/types-CI3ren9F.d.ts.map +0 -1
- package/dist/types-CmeoQg_J.d.ts.map +0 -1
|
@@ -1,176 +1,11 @@
|
|
|
1
1
|
import { a as base58Decode, c as buildOperationSignatureParams, d as hashBrowser, f as hex2ab, i as ab2hex, l as bytesToBase64Url, n as generateId, o as base64UrlToBytes, r as generateMock, s as buildOperationSignatureMessage, t as deriveOperationId, u as getUnixTimestamp } from "../utils-CSF716ux.js";
|
|
2
|
+
import { A as signActionV2, C as DOCUMENT_SCOPE_ACTION_TYPES, D as canonicalJson, E as actionSigningTarget, M as v2TupleProblem, O as hashActionV2, S as CanonicalJsonError, T as actionSignerIdentity, _ as mergePeerCapabilities, a as purgedProtocolVersions, b as selectProtocolVersions, c as PEER_CAPABILITIES, d as holdReason, f as isOlderManifest, g as manifestRevision, h as localSupports, i as purgeMarkerOperation, j as targetDocumentId, k as isV2ActionHash, l as PEER_MANIFEST_FORMAT, m as localPeerManifest, n as isPurgeMarker, o as DOCUMENT_PURGE_PROTOCOL, p as legacySupports, r as purgeDocumentAction, s as MARKER_REFUSAL_FEATURE, t as PURGE_DOCUMENT, u as coversLocal, v as peerSupports, w as actionPreimageV2, x as ACTION_SIGNATURE_V2_PREFIX, y as readPeerManifest } from "../purge-v06m_oGz.js";
|
|
2
3
|
import { ZodError, z } from "zod";
|
|
3
4
|
import { stringify } from "safe-stable-stringify";
|
|
4
5
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
5
6
|
import { strFromU8, strToU8, unzip, zip } from "fflate";
|
|
6
7
|
import { castDraft, create, isDraft, original, unsafe } from "mutative";
|
|
7
8
|
import { constantCase, pascalCase } from "change-case";
|
|
8
|
-
//#region document-model/action-signature.ts
|
|
9
|
-
const ACTION_SIGNATURE_V2_PREFIX = "v2:";
|
|
10
|
-
const V2_HASH = /^v2:[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
11
|
-
const V2_TIMESTAMP = /^[0-9]+$/;
|
|
12
|
-
const V2_SIGNATURE = /^0x[0-9a-f]{128}$/;
|
|
13
|
-
const LONE_SURROGATE = /\p{Cs}/u;
|
|
14
|
-
const PREIMAGE_FIELDS = [
|
|
15
|
-
"version",
|
|
16
|
-
"documentId",
|
|
17
|
-
"branch",
|
|
18
|
-
"scope",
|
|
19
|
-
"type",
|
|
20
|
-
"id",
|
|
21
|
-
"timestampUtcMs",
|
|
22
|
-
"input",
|
|
23
|
-
"signer.user.address",
|
|
24
|
-
"signer.user.networkId",
|
|
25
|
-
"signer.user.chainId",
|
|
26
|
-
"signer.app.key"
|
|
27
|
-
];
|
|
28
|
-
/** A value that would not survive a JSON store round trip unchanged. */
|
|
29
|
-
var CanonicalJsonError = class extends Error {
|
|
30
|
-
constructor(path, detail) {
|
|
31
|
-
super(`Cannot canonicalize ${path}: ${detail}`);
|
|
32
|
-
this.name = "CanonicalJsonError";
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
/** Sorted-key JSON, as the state hash encodes; drops `undefined` properties. */
|
|
36
|
-
function canonicalJson(value, label = "value") {
|
|
37
|
-
assertCanonical(value, label, /* @__PURE__ */ new Set());
|
|
38
|
-
return stringify(value);
|
|
39
|
-
}
|
|
40
|
-
/** Actions the reactor reduces itself, onto the document scope. */
|
|
41
|
-
const DOCUMENT_SCOPE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
42
|
-
"CREATE_DOCUMENT",
|
|
43
|
-
"DELETE_DOCUMENT",
|
|
44
|
-
"UPGRADE_DOCUMENT",
|
|
45
|
-
"ADD_RELATIONSHIP",
|
|
46
|
-
"REMOVE_RELATIONSHIP",
|
|
47
|
-
"UPDATE_RELATIONSHIP"
|
|
48
|
-
]);
|
|
49
|
-
/** Where a document-scope action writes: `sourceId` or `documentId`. */
|
|
50
|
-
function targetDocumentId(action, fallback) {
|
|
51
|
-
const input = action.input;
|
|
52
|
-
if (action.type === "ADD_RELATIONSHIP" || action.type === "REMOVE_RELATIONSHIP" || action.type === "UPDATE_RELATIONSHIP") return typeof input?.sourceId === "string" && input.sourceId.length > 0 ? input.sourceId : fallback;
|
|
53
|
-
return typeof input?.documentId === "string" && input.documentId.length > 0 ? input.documentId : fallback;
|
|
54
|
-
}
|
|
55
|
-
/** The log an action submitted to a job on `documentId` is stored in. */
|
|
56
|
-
function actionSigningTarget(action, documentId, branch) {
|
|
57
|
-
return {
|
|
58
|
-
documentId: DOCUMENT_SCOPE_ACTION_TYPES.has(action.type) ? targetDocumentId(action, documentId) : documentId,
|
|
59
|
-
branch
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/** The identity a signer writes into `context.signer`, and signs over. */
|
|
63
|
-
function actionSignerIdentity(signer) {
|
|
64
|
-
return {
|
|
65
|
-
user: {
|
|
66
|
-
address: signer.user?.address ?? "",
|
|
67
|
-
networkId: signer.user?.networkId ?? "",
|
|
68
|
-
chainId: signer.user?.chainId ?? 0
|
|
69
|
-
},
|
|
70
|
-
app: {
|
|
71
|
-
name: signer.app?.name ?? "",
|
|
72
|
-
key: signer.app?.key ?? ""
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/** The v2 preimage; throws `CanonicalJsonError` on an unsignable action. */
|
|
77
|
-
function actionPreimageV2(action, target, signer) {
|
|
78
|
-
if (!target.documentId) throw new CanonicalJsonError("documentId", "must not be empty");
|
|
79
|
-
if (!target.branch) throw new CanonicalJsonError("branch", "must not be empty");
|
|
80
|
-
if (action.input === void 0) throw new CanonicalJsonError("input", `action ${action.id} (${action.type}) has no input`);
|
|
81
|
-
const fields = [
|
|
82
|
-
"v2",
|
|
83
|
-
target.documentId,
|
|
84
|
-
target.branch,
|
|
85
|
-
action.scope,
|
|
86
|
-
action.type,
|
|
87
|
-
action.id,
|
|
88
|
-
action.timestampUtcMs,
|
|
89
|
-
action.input,
|
|
90
|
-
signer.user.address,
|
|
91
|
-
signer.user.networkId,
|
|
92
|
-
signer.user.chainId,
|
|
93
|
-
signer.app.key
|
|
94
|
-
];
|
|
95
|
-
fields.forEach((field, i) => {
|
|
96
|
-
assertCanonical(field, PREIMAGE_FIELDS[i], /* @__PURE__ */ new Set());
|
|
97
|
-
});
|
|
98
|
-
return stringify(fields);
|
|
99
|
-
}
|
|
100
|
-
/** `"v2:" + base64url(sha256(preimage))`, unpadded. */
|
|
101
|
-
async function hashActionV2(action, target, signer) {
|
|
102
|
-
const preimage = actionPreimageV2(action, target, signer);
|
|
103
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(preimage));
|
|
104
|
-
return "v2:" + bytesToBase64Url$1(new Uint8Array(digest));
|
|
105
|
-
}
|
|
106
|
-
/** Signs `action` as a v2 tuple; the message layout is the legacy one. */
|
|
107
|
-
async function signActionV2(params) {
|
|
108
|
-
const { action, target, signer, sign } = params;
|
|
109
|
-
const previousStateHash = params.previousStateHash ?? "";
|
|
110
|
-
if (previousStateHash.includes(", ")) throw new Error(`Cannot sign action ${action.id}: the previous state hash contains ", "`);
|
|
111
|
-
const tuple = [
|
|
112
|
-
(Date.now() / 1e3).toFixed(0),
|
|
113
|
-
signer.app.key,
|
|
114
|
-
await hashActionV2(action, target, signer),
|
|
115
|
-
previousStateHash
|
|
116
|
-
];
|
|
117
|
-
const signature = await sign(buildOperationSignatureMessage(tuple));
|
|
118
|
-
if (signature.length !== 64) throw new Error(`Cannot sign action ${action.id}: expected a 64-byte P-256 signature, got ${signature.length} bytes`);
|
|
119
|
-
return [...tuple, `0x${bytesToHex(signature)}`];
|
|
120
|
-
}
|
|
121
|
-
/** Element [2] carries the v2 prefix, whether or not it is well formed. */
|
|
122
|
-
function isV2ActionHash(hash) {
|
|
123
|
-
return hash.startsWith("v2:");
|
|
124
|
-
}
|
|
125
|
-
/** The strict shape of a v2 tuple, apart from what its hash covers. */
|
|
126
|
-
function v2TupleProblem(tuple) {
|
|
127
|
-
if (!V2_TIMESTAMP.test(tuple[0])) return "signing time is not decimal seconds";
|
|
128
|
-
if (!V2_HASH.test(tuple[2])) return "hash is not v2: and 43 base64url characters";
|
|
129
|
-
if (!V2_SIGNATURE.test(tuple[4])) return "signature is not 0x and 128 lowercase hex digits";
|
|
130
|
-
}
|
|
131
|
-
function assertCanonical(value, path, ancestors) {
|
|
132
|
-
switch (typeof value) {
|
|
133
|
-
case "string":
|
|
134
|
-
if (LONE_SURROGATE.test(value)) throw new CanonicalJsonError(path, "string holds a lone surrogate");
|
|
135
|
-
return;
|
|
136
|
-
case "boolean": return;
|
|
137
|
-
case "number":
|
|
138
|
-
if (!Number.isFinite(value)) throw new CanonicalJsonError(path, `${value} is not a JSON number`);
|
|
139
|
-
return;
|
|
140
|
-
case "undefined": throw new CanonicalJsonError(path, "undefined is not a JSON value");
|
|
141
|
-
case "bigint": throw new CanonicalJsonError(path, "BigInt is not a JSON value");
|
|
142
|
-
case "function":
|
|
143
|
-
case "symbol": throw new CanonicalJsonError(path, `${typeof value} is not a JSON value`);
|
|
144
|
-
}
|
|
145
|
-
if (value === null) return;
|
|
146
|
-
const object = value;
|
|
147
|
-
if (ancestors.has(object)) throw new CanonicalJsonError(path, "value is circular");
|
|
148
|
-
const toJSON = object.toJSON;
|
|
149
|
-
if (typeof toJSON === "function") {
|
|
150
|
-
assertCanonical(toJSON.call(object), path, new Set(ancestors).add(object));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
ancestors.add(object);
|
|
154
|
-
if (Array.isArray(object)) for (let i = 0; i < object.length; i++) {
|
|
155
|
-
if (!(i in object)) throw new CanonicalJsonError(`${path}[${i}]`, "array is sparse");
|
|
156
|
-
assertCanonical(object[i], `${path}[${i}]`, ancestors);
|
|
157
|
-
}
|
|
158
|
-
else for (const [key, child] of Object.entries(object)) {
|
|
159
|
-
if (LONE_SURROGATE.test(key)) throw new CanonicalJsonError(path, "key holds a lone surrogate");
|
|
160
|
-
if (child === void 0) continue;
|
|
161
|
-
assertCanonical(child, `${path}.${key}`, ancestors);
|
|
162
|
-
}
|
|
163
|
-
ancestors.delete(object);
|
|
164
|
-
}
|
|
165
|
-
function bytesToBase64Url$1(bytes) {
|
|
166
|
-
let binary = "";
|
|
167
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
168
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
169
|
-
}
|
|
170
|
-
function bytesToHex(bytes) {
|
|
171
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
9
|
//#region document-model/signatures.ts
|
|
175
10
|
/**
|
|
176
11
|
* What separates a signature's params when it travels as one string.
|
|
@@ -4164,7 +3999,8 @@ const RESERVED_OPERATION_NAMES = [
|
|
|
4164
3999
|
"REDO",
|
|
4165
4000
|
"SET_NAME",
|
|
4166
4001
|
"SET_PREFERRED_EDITOR",
|
|
4167
|
-
"NOOP"
|
|
4002
|
+
"NOOP",
|
|
4003
|
+
"PURGE_DOCUMENT"
|
|
4168
4004
|
];
|
|
4169
4005
|
/**
|
|
4170
4006
|
* Operation names become the literal action `type` string at runtime and the
|
|
@@ -4922,11 +4758,11 @@ function withProtocolVersions(document, protocolVersions) {
|
|
|
4922
4758
|
};
|
|
4923
4759
|
}
|
|
4924
4760
|
/**
|
|
4925
|
-
* Applies a DELETE_DOCUMENT action to a document.
|
|
4761
|
+
* Applies a DELETE_DOCUMENT action, or a PURGE_DOCUMENT marker, to a document.
|
|
4926
4762
|
* Marks the document as deleted in the document scope state.
|
|
4927
4763
|
*/
|
|
4928
4764
|
function applyDeleteDocumentAction(document, action) {
|
|
4929
|
-
const deletedAt = action.timestampUtcMs || (/* @__PURE__ */ new Date()).toISOString();
|
|
4765
|
+
const deletedAt = isPurgeMarker(action) ? action.input.purgedAtUtcIso : action.timestampUtcMs || (/* @__PURE__ */ new Date()).toISOString();
|
|
4930
4766
|
document.state = {
|
|
4931
4767
|
...document.state,
|
|
4932
4768
|
document: {
|
|
@@ -5091,7 +4927,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
5091
4927
|
const spineActionType = spineOp.action.type;
|
|
5092
4928
|
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
5093
4929
|
if (isDenied(spineOp)) continue;
|
|
5094
|
-
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
4930
|
+
if (spineActionType === "DELETE_DOCUMENT" || spineActionType === "PURGE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
5095
4931
|
else document = reducer(document, spineOp.action, dispatch, {
|
|
5096
4932
|
ignoreSkipOperations: true,
|
|
5097
4933
|
checkHashes,
|
|
@@ -5365,157 +5201,6 @@ const getFileBrowser = (file) => {
|
|
|
5365
5201
|
return Promise.resolve().then(() => readFileBrowser(file));
|
|
5366
5202
|
};
|
|
5367
5203
|
//#endregion
|
|
5368
|
-
|
|
5369
|
-
const PEER_CAPABILITIES = [{
|
|
5370
|
-
kind: "protocol",
|
|
5371
|
-
name: "base-reducer",
|
|
5372
|
-
baseline: [1, 2],
|
|
5373
|
-
supported: () => [1, 2],
|
|
5374
|
-
preferred: () => 2,
|
|
5375
|
-
optional: false
|
|
5376
|
-
}, {
|
|
5377
|
-
kind: "protocol",
|
|
5378
|
-
name: "signature",
|
|
5379
|
-
baseline: [2],
|
|
5380
|
-
supported: () => [2],
|
|
5381
|
-
optional: true
|
|
5382
|
-
}];
|
|
5383
|
-
/** `base` plus `extra`; an extra replaces a base entry of the same name. */
|
|
5384
|
-
function mergePeerCapabilities(base, extra) {
|
|
5385
|
-
const key = (capability) => `${capability.kind}:${capability.name}`;
|
|
5386
|
-
const replaced = new Set(extra.map(key));
|
|
5387
|
-
return [...base.filter((capability) => !replaced.has(key(capability))), ...extra];
|
|
5388
|
-
}
|
|
5389
|
-
const PEER_MANIFEST_FORMAT = 1;
|
|
5390
|
-
function versionSet(values) {
|
|
5391
|
-
return [...new Set(values)].sort((a, b) => a - b);
|
|
5392
|
-
}
|
|
5393
|
-
function supportsFrom(capabilities, values) {
|
|
5394
|
-
const supports = {
|
|
5395
|
-
protocols: {},
|
|
5396
|
-
features: {}
|
|
5397
|
-
};
|
|
5398
|
-
for (const capability of capabilities) {
|
|
5399
|
-
const target = capability.kind === "protocol" ? supports.protocols : supports.features;
|
|
5400
|
-
target[capability.name] = versionSet(values(capability));
|
|
5401
|
-
}
|
|
5402
|
-
return supports;
|
|
5403
|
-
}
|
|
5404
|
-
/** What this reactor supports, for every capability it registers. */
|
|
5405
|
-
function localSupports(capabilities, flags) {
|
|
5406
|
-
return supportsFrom(capabilities, (capability) => capability.supported(flags));
|
|
5407
|
-
}
|
|
5408
|
-
/** What a peer that announces nothing supports. */
|
|
5409
|
-
function legacySupports(capabilities) {
|
|
5410
|
-
return supportsFrom(capabilities, (capability) => capability.baseline);
|
|
5411
|
-
}
|
|
5412
|
-
function manifestRevision(supports, sequence = 0) {
|
|
5413
|
-
const preimage = canonicalJson({
|
|
5414
|
-
protocols: supports.protocols,
|
|
5415
|
-
features: supports.features,
|
|
5416
|
-
sequence
|
|
5417
|
-
}, "peer manifest");
|
|
5418
|
-
return bytesToBase64Url(sha256(new TextEncoder().encode(preimage)));
|
|
5419
|
-
}
|
|
5420
|
-
function localPeerManifest(capabilities, flags, appKey, sequence = 0) {
|
|
5421
|
-
const supports = localSupports(capabilities, flags);
|
|
5422
|
-
return {
|
|
5423
|
-
format: 1,
|
|
5424
|
-
...appKey !== void 0 ? { appKey } : {},
|
|
5425
|
-
sequence,
|
|
5426
|
-
revision: manifestRevision(supports, sequence),
|
|
5427
|
-
protocols: supports.protocols,
|
|
5428
|
-
features: supports.features
|
|
5429
|
-
};
|
|
5430
|
-
}
|
|
5431
|
-
/** A manifest sent before the one already held; silence carries no sequence. */
|
|
5432
|
-
function isOlderManifest(next, held) {
|
|
5433
|
-
return next !== null && held != null && next.sequence < held.sequence;
|
|
5434
|
-
}
|
|
5435
|
-
/** A peer's manifest, or the baselines for a peer that announced none. */
|
|
5436
|
-
function peerSupports(manifest, capabilities) {
|
|
5437
|
-
return manifest ?? legacySupports(capabilities);
|
|
5438
|
-
}
|
|
5439
|
-
function readVersionMap(value) {
|
|
5440
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return;
|
|
5441
|
-
const map = {};
|
|
5442
|
-
for (const [name, versions] of Object.entries(value)) {
|
|
5443
|
-
if (!Array.isArray(versions) || !versions.every((v) => Number.isInteger(v))) return;
|
|
5444
|
-
map[name] = versionSet(versions);
|
|
5445
|
-
}
|
|
5446
|
-
return map;
|
|
5447
|
-
}
|
|
5448
|
-
/**
|
|
5449
|
-
* A manifest as received from a peer, or null when it is not one. Formats only
|
|
5450
|
-
* add fields, so one of an unknown format is read as its two maps.
|
|
5451
|
-
*/
|
|
5452
|
-
function readPeerManifest(value) {
|
|
5453
|
-
if (typeof value !== "object" || value === null) return null;
|
|
5454
|
-
const raw = value;
|
|
5455
|
-
const protocols = readVersionMap(raw.protocols);
|
|
5456
|
-
const features = readVersionMap(raw.features ?? {});
|
|
5457
|
-
if (!protocols || !features) return null;
|
|
5458
|
-
const sequence = Number.isSafeInteger(raw.sequence) ? raw.sequence : 0;
|
|
5459
|
-
return {
|
|
5460
|
-
format: 1,
|
|
5461
|
-
...typeof raw.appKey === "string" ? { appKey: raw.appKey } : {},
|
|
5462
|
-
sequence,
|
|
5463
|
-
revision: typeof raw.revision === "string" ? raw.revision : manifestRevision({
|
|
5464
|
-
protocols,
|
|
5465
|
-
features
|
|
5466
|
-
}, sequence),
|
|
5467
|
-
protocols,
|
|
5468
|
-
features
|
|
5469
|
-
};
|
|
5470
|
-
}
|
|
5471
|
-
/** Only keys this reactor registers are judged; an absent key agrees. */
|
|
5472
|
-
function holdReason(peer, versions, capabilities) {
|
|
5473
|
-
for (const capability of capabilities) {
|
|
5474
|
-
if (capability.kind !== "protocol") continue;
|
|
5475
|
-
const version = versions[capability.name];
|
|
5476
|
-
if (version === void 0) continue;
|
|
5477
|
-
const supported = peer.protocols[capability.name] ?? [];
|
|
5478
|
-
if (!supported.includes(version)) return {
|
|
5479
|
-
protocol: capability.name,
|
|
5480
|
-
version,
|
|
5481
|
-
peerSupports: supported
|
|
5482
|
-
};
|
|
5483
|
-
}
|
|
5484
|
-
}
|
|
5485
|
-
/** Whether a peer runs every version this reactor does, so nothing is held. */
|
|
5486
|
-
function coversLocal(peer, local, capabilities) {
|
|
5487
|
-
for (const capability of capabilities) {
|
|
5488
|
-
if (capability.kind !== "protocol") continue;
|
|
5489
|
-
const theirs = peer.protocols[capability.name] ?? [];
|
|
5490
|
-
if (!(local.protocols[capability.name] ?? []).every((version) => theirs.includes(version))) return false;
|
|
5491
|
-
}
|
|
5492
|
-
return true;
|
|
5493
|
-
}
|
|
5494
|
-
/**
|
|
5495
|
-
* protocolVersions for a new document: per negotiated protocol, the highest
|
|
5496
|
-
* version up to the local preference that every member supports, else the
|
|
5497
|
-
* lowest local one. `requested` wins over what is selected.
|
|
5498
|
-
*/
|
|
5499
|
-
function selectProtocolVersions(input) {
|
|
5500
|
-
const members = [...input.members];
|
|
5501
|
-
const selected = {};
|
|
5502
|
-
for (const capability of input.capabilities) {
|
|
5503
|
-
if (capability.kind !== "protocol" || !capability.preferred) continue;
|
|
5504
|
-
const preferred = capability.preferred(input.flags);
|
|
5505
|
-
const supported = capability.supported(input.flags);
|
|
5506
|
-
let agreed = supported.filter((version) => version <= preferred);
|
|
5507
|
-
for (const member of members) {
|
|
5508
|
-
const theirs = member.protocols[capability.name] ?? [];
|
|
5509
|
-
agreed = agreed.filter((version) => theirs.includes(version));
|
|
5510
|
-
}
|
|
5511
|
-
selected[capability.name] = agreed.length > 0 ? Math.max(...agreed) : Math.min(...supported);
|
|
5512
|
-
}
|
|
5513
|
-
return {
|
|
5514
|
-
...selected,
|
|
5515
|
-
...input.requested
|
|
5516
|
-
};
|
|
5517
|
-
}
|
|
5518
|
-
//#endregion
|
|
5519
|
-
export { ACTION_SIGNATURE_V2_PREFIX, AUTH_ACTION_TYPES, AUTH_DENIED_BY_GRANT_REASON, AUTH_NO_GRANT_REASON, AUTH_VERSION_UNSUPPORTED_REASON, AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthActionNotAllowedError, AuthAdministrationLockoutError, AuthAdministrationMissingError, AuthAlreadyInitializedError, AuthInitializerNotCreatorError, AuthPolicyNotPreservedError, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CanonicalJsonError, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DEFAULT_SIGNATURE_POLICY, DOCUMENT_DELETED_REASON, DOCUMENT_SCOPE_ACTION_TYPES, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, DowngradeNotSupportedError, FileSystemError, GrantNotFoundError, GrantSchema, GroupPrincipalNotAllowedError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, InitializeAuthActionInputSchema, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, InvalidAuthVersionError, InvalidGrantError, MAX_AUTH_GRANTS, MAX_CAPABILITY_OPERATIONS, MAX_CONDITION_DEPTH, MAX_CONDITION_NODES, MAX_SUPPORTED_AUTH_VERSION, ManifestSchema, ModuleSchema, MoveGrantActionInputSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PEER_CAPABILITIES, PEER_MANIFEST_FORMAT, PieceModuleSchema, PieceModulesSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PublisherSchema, PwaConfigSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, RemoveGrantActionInputSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, SIGNATURE_PROTOCOL, SIGNATURE_PROTOCOL_V2, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetGrantActionInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UnsupportedDocumentModelVersionError, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionPreimageV2, actionSigner, actionSignerIdentity, actionSigningTarget, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, appendWithoutApplying, applyAuthAction, applyDeleteDocumentAction, applyInitializeAuthAction, applyMoveGrantAction, applyRemoveGrantAction, applySetGrantAction, applyUpgradeDocumentAction, assertAuthAdministrationRetained, assertAuthPreservedOnDuplicate, assertAuthScopeActionAllowed, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, assertValidGrant, assertValidGrantUpsert, assertValidInitialGrants, attachBranch, backfillAuthState, base58Decode, base64UrlToBytes, baseActions, baseCreateDocument, baseLoadFromInput, baseLoadFromInputVersioned, baseReducer, baseReducerVersion, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, bytesToBase64Url, canonicalJson, checkCleanedOperationsIntegrity, checkOperationsIntegrity, computeUpgradeTransitions, coversLocal, createAction, createAuthState, createBaseState, createCopyHeader, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, decide, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveDocumentId, deriveOperationId, deserializeSignature, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, evaluate, evaluateCondition, evaluateGrantStack, evaluateGrants, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, grantProblem, groupDocumentType, groupMembershipActionTypes, groupOperationsByScope, hasDerivedDocumentId, hashActionV2, hashBrowser, hashDocumentStateForScope, hex2ab, holdReason, initializeAuth, isAuthAction, isDefinedNonNullAny, isDenied, isDerivedDocumentId, isDocumentAction, isDocumentCreator, isDocumentModelDocument, isDocumentModelState, isDocumentZip, isNoopOperation, isOlderManifest, isPlainValue, isReservedOperationName, isSignaturePolicy, isUndo, isUndoRedo, isV2ActionHash, isValidOperationNameFormat, legacySupports, localPeerManifest, localSupports, manifestRevision, mapSkippedOperations, mapSkippedOperationsV2, mentionedGroupIds, merge, mergePeerCapabilities, moveGrant, moveOperation, nextSkipNumber, noop, normalizeDocumentModelVersion, operationExampleCreators, operationFromAction, operationFromOperation, operationOutcome, operationWithContext, operationsAreEqual, parseBulkArchive, parseResultingState, peerSupports, precedes, prepareOperations, processUndoRedo, protocolVersionsFor, readFileBrowser, readOnly, readPeerManifest, redo, redoOperation, referencedGroupIds, releaseNewVersion, removeExistingOperations, removeGrant, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, requestedSignaturePolicy, reshuffleByTimestamp, reshuffleByTimestampAndIndex, resolveSnapshotAuth, selectProtocolVersions, serializeSignature, setAuthorName, setAuthorWebsite, setGrant, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, signActionV2, signaturePolicyOf, skipHeaderOperations, sortMappedOperations, sortOperations, split, targetDocumentId, toTransportAction, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, v2RequiredProtocolVersions, v2TupleProblem, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, withProtocolVersions, withSignaturePolicy, writeFileBrowser, zipEntries };
|
|
5204
|
+
export { ACTION_SIGNATURE_V2_PREFIX, AUTH_ACTION_TYPES, AUTH_DENIED_BY_GRANT_REASON, AUTH_NO_GRANT_REASON, AUTH_VERSION_UNSUPPORTED_REASON, AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthActionNotAllowedError, AuthAdministrationLockoutError, AuthAdministrationMissingError, AuthAlreadyInitializedError, AuthInitializerNotCreatorError, AuthPolicyNotPreservedError, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CanonicalJsonError, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DEFAULT_SIGNATURE_POLICY, DOCUMENT_DELETED_REASON, DOCUMENT_PURGE_PROTOCOL, DOCUMENT_SCOPE_ACTION_TYPES, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, DowngradeNotSupportedError, FileSystemError, GrantNotFoundError, GrantSchema, GroupPrincipalNotAllowedError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, InitializeAuthActionInputSchema, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, InvalidAuthVersionError, InvalidGrantError, MARKER_REFUSAL_FEATURE, MAX_AUTH_GRANTS, MAX_CAPABILITY_OPERATIONS, MAX_CONDITION_DEPTH, MAX_CONDITION_NODES, MAX_SUPPORTED_AUTH_VERSION, ManifestSchema, ModuleSchema, MoveGrantActionInputSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PEER_CAPABILITIES, PEER_MANIFEST_FORMAT, PURGE_DOCUMENT, PieceModuleSchema, PieceModulesSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PublisherSchema, PwaConfigSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, RemoveGrantActionInputSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, SIGNATURE_PROTOCOL, SIGNATURE_PROTOCOL_V2, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetGrantActionInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UnsupportedDocumentModelVersionError, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionPreimageV2, actionSigner, actionSignerIdentity, actionSigningTarget, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, appendWithoutApplying, applyAuthAction, applyDeleteDocumentAction, applyInitializeAuthAction, applyMoveGrantAction, applyRemoveGrantAction, applySetGrantAction, applyUpgradeDocumentAction, assertAuthAdministrationRetained, assertAuthPreservedOnDuplicate, assertAuthScopeActionAllowed, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, assertValidGrant, assertValidGrantUpsert, assertValidInitialGrants, attachBranch, backfillAuthState, base58Decode, base64UrlToBytes, baseActions, baseCreateDocument, baseLoadFromInput, baseLoadFromInputVersioned, baseReducer, baseReducerVersion, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, bytesToBase64Url, canonicalJson, checkCleanedOperationsIntegrity, checkOperationsIntegrity, computeUpgradeTransitions, coversLocal, createAction, createAuthState, createBaseState, createCopyHeader, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, decide, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveDocumentId, deriveOperationId, deserializeSignature, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, evaluate, evaluateCondition, evaluateGrantStack, evaluateGrants, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, grantProblem, groupDocumentType, groupMembershipActionTypes, groupOperationsByScope, hasDerivedDocumentId, hashActionV2, hashBrowser, hashDocumentStateForScope, hex2ab, holdReason, initializeAuth, isAuthAction, isDefinedNonNullAny, isDenied, isDerivedDocumentId, isDocumentAction, isDocumentCreator, isDocumentModelDocument, isDocumentModelState, isDocumentZip, isNoopOperation, isOlderManifest, isPlainValue, isPurgeMarker, isReservedOperationName, isSignaturePolicy, isUndo, isUndoRedo, isV2ActionHash, isValidOperationNameFormat, legacySupports, localPeerManifest, localSupports, manifestRevision, mapSkippedOperations, mapSkippedOperationsV2, mentionedGroupIds, merge, mergePeerCapabilities, moveGrant, moveOperation, nextSkipNumber, noop, normalizeDocumentModelVersion, operationExampleCreators, operationFromAction, operationFromOperation, operationOutcome, operationWithContext, operationsAreEqual, parseBulkArchive, parseResultingState, peerSupports, precedes, prepareOperations, processUndoRedo, protocolVersionsFor, purgeDocumentAction, purgeMarkerOperation, purgedProtocolVersions, readFileBrowser, readOnly, readPeerManifest, redo, redoOperation, referencedGroupIds, releaseNewVersion, removeExistingOperations, removeGrant, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, requestedSignaturePolicy, reshuffleByTimestamp, reshuffleByTimestampAndIndex, resolveSnapshotAuth, selectProtocolVersions, serializeSignature, setAuthorName, setAuthorWebsite, setGrant, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, signActionV2, signaturePolicyOf, skipHeaderOperations, sortMappedOperations, sortOperations, split, targetDocumentId, toTransportAction, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, v2RequiredProtocolVersions, v2TupleProblem, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, withProtocolVersions, withSignaturePolicy, writeFileBrowser, zipEntries };
|
|
5520
5205
|
|
|
5521
5206
|
//# sourceMappingURL=index.js.map
|