@powerhousedao/shared 6.2.3-dev.9 → 6.2.3
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/analytics/index.d.ts +4 -4
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics/index.js +25 -24
- package/dist/analytics/index.js.map +1 -1
- package/dist/clis/args/{access-token-To5LaIfL.mjs → access-token-3Hqv_U8I.mjs} +2 -2
- package/dist/clis/args/{access-token-To5LaIfL.mjs.map → access-token-3Hqv_U8I.mjs.map} +1 -1
- package/dist/clis/args/access-token-C5sKsH2O.d.mts +16 -0
- package/dist/clis/args/access-token-C5sKsH2O.d.mts.map +1 -0
- package/dist/clis/args/access-token.d.mts +3 -2
- package/dist/clis/args/access-token.mjs +1 -1
- package/dist/clis/args/{common-CcYbXrBx.mjs → common-BXabdhiO.mjs} +30 -7
- package/dist/clis/args/common-BXabdhiO.mjs.map +1 -0
- package/dist/clis/args/common-Bnm859xU.d.mts +186 -0
- package/dist/clis/args/common-Bnm859xU.d.mts.map +1 -0
- package/dist/clis/args/common.d.mts +3 -2
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/{connect-BVVvCmL9.mjs → connect-BG3HkYBk.mjs} +8 -3
- package/dist/clis/args/connect-BG3HkYBk.mjs.map +1 -0
- package/dist/clis/args/connect-DjeiqXus.d.mts +450 -0
- package/dist/clis/args/connect-DjeiqXus.d.mts.map +1 -0
- package/dist/clis/args/connect.d.mts +3 -2
- package/dist/clis/args/connect.mjs +1 -1
- package/dist/clis/args/{generate-CA916Fvj.mjs → generate-BOItUNvP.mjs} +40 -2
- package/dist/clis/args/generate-BOItUNvP.mjs.map +1 -0
- package/dist/clis/args/generate-BPBBLeUD.d.mts +103 -0
- package/dist/clis/args/generate-BPBBLeUD.d.mts.map +1 -0
- package/dist/clis/args/generate.d.mts +3 -2
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-Bqbgbalu.mjs → help-DS1NlcJQ.mjs} +15 -15
- package/dist/clis/args/{help-Bqbgbalu.mjs.map → help-DS1NlcJQ.mjs.map} +1 -1
- package/dist/clis/args/help-DVPTARGn.d.mts +190 -0
- package/dist/clis/args/help-DVPTARGn.d.mts.map +1 -0
- package/dist/clis/args/help.d.mts +3 -2
- package/dist/clis/args/help.mjs +1 -1
- package/dist/clis/args/index.d.mts +20 -19
- package/dist/clis/args/index.mjs +18 -18
- package/dist/clis/args/init-CFeTq4Cq.d.mts +52 -0
- package/dist/clis/args/init-CFeTq4Cq.d.mts.map +1 -0
- package/dist/clis/args/{init-rz9Ei7nq.mjs → init-Dvb42Y87.mjs} +2 -2
- package/dist/clis/args/{init-rz9Ei7nq.mjs.map → init-Dvb42Y87.mjs.map} +1 -1
- package/dist/clis/args/init.d.mts +3 -2
- package/dist/clis/args/init.mjs +1 -1
- package/dist/clis/args/inspect-BjRmtB86.d.mts +13 -0
- package/dist/clis/args/inspect-BjRmtB86.d.mts.map +1 -0
- package/dist/clis/args/{inspect-tckH8mSw.mjs → inspect-UNQgtuR0.mjs} +2 -2
- package/dist/clis/args/{inspect-tckH8mSw.mjs.map → inspect-UNQgtuR0.mjs.map} +1 -1
- package/dist/clis/args/inspect.d.mts +3 -2
- package/dist/clis/args/inspect.mjs +1 -1
- package/dist/clis/args/install-B0tMyUMw.d.mts +37 -0
- package/dist/clis/args/install-B0tMyUMw.d.mts.map +1 -0
- package/dist/clis/args/{install-Sz2DlCHh.mjs → install-F-27kF6m.mjs} +2 -2
- package/dist/clis/args/{install-Sz2DlCHh.mjs.map → install-F-27kF6m.mjs.map} +1 -1
- package/dist/clis/args/install.d.mts +3 -2
- package/dist/clis/args/install.mjs +1 -1
- package/dist/clis/args/{list-DM2d6f1m.mjs → list-Bkfn8Yuo.mjs} +2 -2
- package/dist/clis/args/{list-DM2d6f1m.mjs.map → list-Bkfn8Yuo.mjs.map} +1 -1
- package/dist/clis/args/list-DrbxA7JJ.d.mts +10 -0
- package/dist/clis/args/list-DrbxA7JJ.d.mts.map +1 -0
- package/dist/clis/args/list.d.mts +3 -2
- package/dist/clis/args/list.mjs +1 -1
- package/dist/clis/args/{login-DiKT5Jfu.mjs → login-CIFkQExi.mjs} +2 -2
- package/dist/clis/args/{login-DiKT5Jfu.mjs.map → login-CIFkQExi.mjs.map} +1 -1
- package/dist/clis/args/login-CXRJXg71.d.mts +25 -0
- package/dist/clis/args/login-CXRJXg71.d.mts.map +1 -0
- package/dist/clis/args/login.d.mts +3 -2
- package/dist/clis/args/login.mjs +1 -1
- package/dist/clis/args/{magic-string.es-h_0HDQBQ.mjs → magic-string.es-BWtG0AyA.mjs} +33 -27
- package/dist/clis/args/magic-string.es-BWtG0AyA.mjs.map +1 -0
- package/dist/clis/args/migrate-DkCQRL2D.d.mts +19 -0
- package/dist/clis/args/migrate-DkCQRL2D.d.mts.map +1 -0
- package/dist/clis/args/{migrate-CG_gWc4k.mjs → migrate-DwJGhc2d.mjs} +2 -2
- package/dist/clis/args/{migrate-CG_gWc4k.mjs.map → migrate-DwJGhc2d.mjs.map} +1 -1
- package/dist/clis/args/migrate.d.mts +3 -2
- package/dist/clis/args/migrate.mjs +1 -1
- package/dist/clis/args/publish-CeW4bOrl.d.mts +16 -0
- package/dist/clis/args/publish-CeW4bOrl.d.mts.map +1 -0
- package/dist/clis/args/{publish-DDZYsUfV.mjs → publish-DHqlGWmL.mjs} +2 -2
- package/dist/clis/args/{publish-DDZYsUfV.mjs.map → publish-DHqlGWmL.mjs.map} +1 -1
- package/dist/clis/args/publish.d.mts +3 -2
- package/dist/clis/args/publish.mjs +1 -1
- package/dist/clis/args/{registry-C_OVFQmI.mjs → registry-DIwES3l2.mjs} +2 -2
- package/dist/clis/args/{registry-C_OVFQmI.mjs.map → registry-DIwES3l2.mjs.map} +1 -1
- package/dist/clis/args/registry-DNH8xuaE.d.mts +17 -0
- package/dist/clis/args/registry-DNH8xuaE.d.mts.map +1 -0
- package/dist/clis/args/registry.d.mts +3 -2
- package/dist/clis/args/registry.mjs +1 -1
- package/dist/clis/args/service-BBx5GDTc.d.mts +27 -0
- package/dist/clis/args/service-BBx5GDTc.d.mts.map +1 -0
- package/dist/clis/args/{service-CHOOr0Gg.mjs → service-Cpjlyeu5.mjs} +2 -2
- package/dist/clis/args/{service-CHOOr0Gg.mjs.map → service-Cpjlyeu5.mjs.map} +1 -1
- package/dist/clis/args/service.d.mts +3 -2
- package/dist/clis/args/service.mjs +1 -1
- package/dist/clis/args/{switchboard-Dsp7nosi.mjs → switchboard-CCaAtU56.mjs} +2 -2
- package/dist/clis/args/{switchboard-Dsp7nosi.mjs.map → switchboard-CCaAtU56.mjs.map} +1 -1
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts +70 -0
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts.map +1 -0
- package/dist/clis/args/switchboard.d.mts +3 -2
- package/dist/clis/args/switchboard.mjs +1 -1
- package/dist/clis/args/{uninstall-CTwTX0u_.mjs → uninstall-3U0B8g5c.mjs} +2 -2
- package/dist/clis/args/{uninstall-CTwTX0u_.mjs.map → uninstall-3U0B8g5c.mjs.map} +1 -1
- package/dist/clis/args/uninstall-CDx7lwxn.d.mts +28 -0
- package/dist/clis/args/uninstall-CDx7lwxn.d.mts.map +1 -0
- package/dist/clis/args/uninstall.d.mts +3 -2
- package/dist/clis/args/uninstall.mjs +1 -1
- package/dist/clis/args/unpublish-CEDsk6uv.d.mts +22 -0
- package/dist/clis/args/unpublish-CEDsk6uv.d.mts.map +1 -0
- package/dist/clis/args/{unpublish-BPMkGEg5.mjs → unpublish-s9zUh6Gw.mjs} +2 -2
- package/dist/clis/args/{unpublish-BPMkGEg5.mjs.map → unpublish-s9zUh6Gw.mjs.map} +1 -1
- package/dist/clis/args/unpublish.d.mts +3 -2
- package/dist/clis/args/unpublish.mjs +1 -1
- package/dist/clis/args/{vetra-b4KUu1Ax.mjs → vetra-BUNlAAPp.mjs} +2 -2
- package/dist/clis/args/{vetra-b4KUu1Ax.mjs.map → vetra-BUNlAAPp.mjs.map} +1 -1
- package/dist/clis/args/vetra-DkDaWFPi.d.mts +111 -0
- package/dist/clis/args/vetra-DkDaWFPi.d.mts.map +1 -0
- package/dist/clis/args/vetra-ports.test.d.mts +2 -1
- package/dist/clis/args/vetra-ports.test.mjs +285 -180
- package/dist/clis/args/vetra-ports.test.mjs.map +1 -1
- package/dist/clis/args/vetra.d.mts +3 -2
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/build-config-CmdMi_wu.mjs +230 -0
- package/dist/clis/build-config-CmdMi_wu.mjs.map +1 -0
- package/dist/clis/build-config.d.mts +44 -10614
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/build-config.mjs +2 -93
- package/dist/clis/build-pieces.d.mts +100 -0
- package/dist/clis/build-pieces.d.mts.map +1 -0
- package/dist/clis/build-pieces.mjs +371 -0
- package/dist/clis/build-pieces.mjs.map +1 -0
- package/dist/clis/command-names.d.mts +2 -2
- package/dist/clis/command-names.d.mts.map +1 -1
- package/dist/clis/command-names.mjs.map +1 -1
- package/dist/clis/constants.d.mts +3 -475
- package/dist/clis/constants.mjs +17 -8
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index-6CZwrmQi.d.mts +11154 -0
- package/dist/clis/index-6CZwrmQi.d.mts.map +1 -0
- package/dist/clis/index.d.mts +1368 -1221
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +209 -65
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/project-env.d.mts +4 -4
- package/dist/clis/project-env.d.mts.map +1 -1
- package/dist/clis/project-env.mjs.map +1 -1
- package/dist/clis/project-ports.d.mts +5 -5
- package/dist/clis/project-ports.d.mts.map +1 -1
- package/dist/clis/project-ports.mjs +1 -1
- package/dist/clis/project-ports.mjs.map +1 -1
- package/dist/clis/services/telemetry.d.mts +7 -7
- package/dist/clis/services/telemetry.d.mts.map +1 -1
- package/dist/clis/services/telemetry.mjs.map +1 -1
- package/dist/clis/types-nzer4WIr.d.mts +541 -0
- package/dist/clis/types-nzer4WIr.d.mts.map +1 -0
- package/dist/clis/utils.d.mts +4 -4
- package/dist/clis/utils.d.mts.map +1 -1
- package/dist/clis/utils.mjs.map +1 -1
- package/dist/{config-loader-B845Hidf.js → config-loader-C6dZB_iX.js} +28 -8
- package/dist/config-loader-C6dZB_iX.js.map +1 -0
- package/dist/connect/config-loader.d.ts +14 -8
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/config-loader.js +2 -2
- package/dist/connect/index.d.ts +190 -56
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +303 -30
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/json-adapter.d.ts +3 -4
- package/dist/connect/json-adapter.d.ts.map +1 -1
- package/dist/connect/json-adapter.js.map +1 -1
- package/dist/{constants-BP_gjn8g.d.ts → constants-DO4IYxuR.d.ts} +2 -1
- package/dist/constants-DO4IYxuR.d.ts.map +1 -0
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js.map +1 -1
- package/dist/document-drive/index.d.ts +104 -101
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-drive/index.js +39 -19
- package/dist/document-drive/index.js.map +1 -1
- package/dist/document-model/index.d.ts +5 -4
- package/dist/document-model/index.js +605 -228
- package/dist/document-model/index.js.map +1 -1
- package/dist/document-model/mock.d.ts +2 -3
- package/dist/document-model/mock.d.ts.map +1 -1
- package/dist/document-model/mock.js +2 -1
- package/dist/document-model/mock.js.map +1 -1
- package/dist/document-model/utils.d.ts +3 -2
- package/dist/document-model/utils.js +1 -1
- package/dist/index-5gwOhPG5.d.ts +36 -0
- package/dist/index-5gwOhPG5.d.ts.map +1 -0
- package/dist/{index-DP3QgHTq.d.ts → index-D6833Siv.d.ts} +131 -28
- package/dist/index-D6833Siv.d.ts.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js.map +1 -1
- package/dist/processors/index.d.ts +3 -2
- package/dist/processors/index.js +5 -1
- package/dist/processors/index.js.map +1 -1
- package/dist/registry/index.d.ts +15 -15
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +14 -5
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +4 -3
- package/dist/registry/manifest-slim.d.ts.map +1 -1
- package/dist/registry/manifest-slim.js +22 -2
- package/dist/registry/manifest-slim.js.map +1 -1
- package/dist/registry/updates.d.ts +3 -3
- package/dist/registry/updates.d.ts.map +1 -1
- package/dist/registry/updates.js.map +1 -1
- package/dist/registry/urls.d.ts +2 -2
- package/dist/registry/urls.d.ts.map +1 -1
- package/dist/registry/urls.js.map +1 -1
- package/dist/{types-C1in4fl3.d.ts → types-Bsp8VL2y.d.ts} +2 -2
- package/dist/types-Bsp8VL2y.d.ts.map +1 -0
- package/dist/{types-DDpRvBK_.d.ts → types-CI3ren9F.d.ts} +23 -35
- package/dist/types-CI3ren9F.d.ts.map +1 -0
- package/dist/{types-BIoOWpOT.d.ts → types-CmeoQg_J.d.ts} +602 -437
- package/dist/types-CmeoQg_J.d.ts.map +1 -0
- package/dist/{utils-DP122OSS.d.ts → utils-BrKxCmKx.d.ts} +2 -2
- package/dist/utils-BrKxCmKx.d.ts.map +1 -0
- package/dist/{utils-aaTmfxFW.js → utils-CSF716ux.js} +10 -3
- package/dist/utils-CSF716ux.js.map +1 -0
- package/package.json +10 -5
- package/dist/clis/args/access-token--9H57y8J.d.mts +0 -18
- package/dist/clis/args/access-token--9H57y8J.d.mts.map +0 -1
- package/dist/clis/args/common-CcYbXrBx.mjs.map +0 -1
- package/dist/clis/args/common-Dsf1vpHV.d.mts +0 -183
- package/dist/clis/args/common-Dsf1vpHV.d.mts.map +0 -1
- package/dist/clis/args/connect-BVVvCmL9.mjs.map +0 -1
- package/dist/clis/args/connect-DetTnI8g.d.mts +0 -443
- package/dist/clis/args/connect-DetTnI8g.d.mts.map +0 -1
- package/dist/clis/args/generate-CA916Fvj.mjs.map +0 -1
- package/dist/clis/args/generate-DnV-bfXt.d.mts +0 -87
- package/dist/clis/args/generate-DnV-bfXt.d.mts.map +0 -1
- package/dist/clis/args/help-CjAsudUn.d.mts +0 -193
- package/dist/clis/args/help-CjAsudUn.d.mts.map +0 -1
- package/dist/clis/args/init-CUXyfquF.d.mts +0 -55
- package/dist/clis/args/init-CUXyfquF.d.mts.map +0 -1
- package/dist/clis/args/inspect-DtZeoA5c.d.mts +0 -15
- package/dist/clis/args/inspect-DtZeoA5c.d.mts.map +0 -1
- package/dist/clis/args/install-CkP8zcHb.d.mts +0 -40
- package/dist/clis/args/install-CkP8zcHb.d.mts.map +0 -1
- package/dist/clis/args/list-BGf8s_gj.d.mts +0 -12
- package/dist/clis/args/list-BGf8s_gj.d.mts.map +0 -1
- package/dist/clis/args/login-DNsHwvqk.d.mts +0 -27
- package/dist/clis/args/login-DNsHwvqk.d.mts.map +0 -1
- package/dist/clis/args/magic-string.es-h_0HDQBQ.mjs.map +0 -1
- package/dist/clis/args/migrate-sixkWhxm.d.mts +0 -21
- package/dist/clis/args/migrate-sixkWhxm.d.mts.map +0 -1
- package/dist/clis/args/publish-Dqe5DUst.d.mts +0 -18
- package/dist/clis/args/publish-Dqe5DUst.d.mts.map +0 -1
- package/dist/clis/args/registry-C_RfTsKB.d.mts +0 -19
- package/dist/clis/args/registry-C_RfTsKB.d.mts.map +0 -1
- package/dist/clis/args/service-DhIkf8-O.d.mts +0 -22
- package/dist/clis/args/service-DhIkf8-O.d.mts.map +0 -1
- package/dist/clis/args/switchboard-BlPaq2at.d.mts +0 -72
- package/dist/clis/args/switchboard-BlPaq2at.d.mts.map +0 -1
- package/dist/clis/args/uninstall-BpA3YYbw.d.mts +0 -31
- package/dist/clis/args/uninstall-BpA3YYbw.d.mts.map +0 -1
- package/dist/clis/args/unpublish-CvwaIimG.d.mts +0 -24
- package/dist/clis/args/unpublish-CvwaIimG.d.mts.map +0 -1
- package/dist/clis/args/vetra-DLQ6lhLl.d.mts +0 -113
- package/dist/clis/args/vetra-DLQ6lhLl.d.mts.map +0 -1
- package/dist/clis/build-config.mjs.map +0 -1
- package/dist/clis/constants.d.mts.map +0 -1
- package/dist/config-loader-B845Hidf.js.map +0 -1
- package/dist/constants-BP_gjn8g.d.ts.map +0 -1
- package/dist/index-C_iVZe7f.d.ts +0 -7
- package/dist/index-C_iVZe7f.d.ts.map +0 -1
- package/dist/index-DP3QgHTq.d.ts.map +0 -1
- package/dist/types-BIoOWpOT.d.ts.map +0 -1
- package/dist/types-C1in4fl3.d.ts.map +0 -1
- package/dist/types-DDpRvBK_.d.ts.map +0 -1
- package/dist/utils-DP122OSS.d.ts.map +0 -1
- package/dist/utils-aaTmfxFW.js.map +0 -1
|
@@ -1,9 +1,176 @@
|
|
|
1
|
-
import { a as base58Decode, c as buildOperationSignatureParams, d as hex2ab, i as ab2hex, l as
|
|
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
2
|
import { ZodError, z } from "zod";
|
|
3
3
|
import { stringify } from "safe-stable-stringify";
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4
5
|
import { strFromU8, strToU8, unzip, zip } from "fflate";
|
|
5
|
-
import { castDraft, create, unsafe } from "mutative";
|
|
6
|
+
import { castDraft, create, isDraft, original, unsafe } from "mutative";
|
|
6
7
|
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
|
|
7
174
|
//#region document-model/signatures.ts
|
|
8
175
|
/**
|
|
9
176
|
* What separates a signature's params when it travels as one string.
|
|
@@ -198,7 +365,7 @@ var GrantNotFoundError = class extends Error {
|
|
|
198
365
|
}
|
|
199
366
|
};
|
|
200
367
|
/**
|
|
201
|
-
* Thrown when a disallowed action (UNDO, REDO
|
|
368
|
+
* Thrown when a disallowed action (UNDO, REDO) targets the auth scope.
|
|
202
369
|
*/
|
|
203
370
|
var AuthActionNotAllowedError = class extends Error {
|
|
204
371
|
actionType;
|
|
@@ -257,8 +424,6 @@ var UnsupportedDocumentModelVersionError = class extends Error {
|
|
|
257
424
|
//#region document-model/schemas.ts
|
|
258
425
|
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
259
426
|
const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
|
|
260
|
-
const Load_StateSchema = z.enum(["LOAD_STATE"]);
|
|
261
|
-
const PruneSchema = z.enum(["PRUNE"]);
|
|
262
427
|
const RedoSchema = z.enum(["REDO"]);
|
|
263
428
|
const Set_NameSchema = z.enum(["SET_NAME"]);
|
|
264
429
|
const Set_PreferredEditorSchema = z.enum(["SET_PREFERRED_EDITOR"]);
|
|
@@ -268,50 +433,12 @@ function OperationScopeSchema() {
|
|
|
268
433
|
}
|
|
269
434
|
function DocumentActionSchema() {
|
|
270
435
|
return z.union([
|
|
271
|
-
LoadStateActionSchema(),
|
|
272
|
-
PruneActionSchema(),
|
|
273
436
|
RedoActionSchema(),
|
|
274
437
|
SetNameActionSchema(),
|
|
275
438
|
SetPreferredEditorActionSchema(),
|
|
276
439
|
UndoActionSchema()
|
|
277
440
|
]);
|
|
278
441
|
}
|
|
279
|
-
function LoadStateActionSchema() {
|
|
280
|
-
return z.object({
|
|
281
|
-
id: z.string(),
|
|
282
|
-
timestampUtcMs: z.string(),
|
|
283
|
-
input: z.lazy(() => LoadStateActionInputSchema()),
|
|
284
|
-
type: Load_StateSchema,
|
|
285
|
-
scope: OperationScopeSchema()
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
function LoadStateActionInputSchema() {
|
|
289
|
-
return z.object({
|
|
290
|
-
operations: z.number(),
|
|
291
|
-
state: z.lazy(() => LoadStateActionStateInputSchema())
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
function LoadStateActionStateInputSchema() {
|
|
295
|
-
return z.object({
|
|
296
|
-
data: z.unknown().nullish(),
|
|
297
|
-
name: z.string()
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
function PruneActionSchema() {
|
|
301
|
-
return z.object({
|
|
302
|
-
id: z.string(),
|
|
303
|
-
timestampUtcMs: z.string(),
|
|
304
|
-
input: z.lazy(() => PruneActionInputSchema()),
|
|
305
|
-
type: PruneSchema,
|
|
306
|
-
scope: OperationScopeSchema()
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
function PruneActionInputSchema() {
|
|
310
|
-
return z.object({
|
|
311
|
-
end: z.number().nullish(),
|
|
312
|
-
start: z.number().nullish()
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
442
|
function RedoActionInputSchema() {
|
|
316
443
|
return z.object({ count: z.number() });
|
|
317
444
|
}
|
|
@@ -729,6 +856,13 @@ const PowerhouseModuleSchema = z.object({
|
|
|
729
856
|
documentTypes: z.array(z.string()).optional()
|
|
730
857
|
});
|
|
731
858
|
const PowerhouseModulesSchema = z.array(PowerhouseModuleSchema).optional();
|
|
859
|
+
const PieceModuleSchema = PowerhouseModuleSchema.extend({
|
|
860
|
+
version: z.string().optional(),
|
|
861
|
+
description: z.string().optional(),
|
|
862
|
+
bundle: z.string().optional(),
|
|
863
|
+
descriptor: z.string().optional()
|
|
864
|
+
});
|
|
865
|
+
const PieceModulesSchema = z.array(PieceModuleSchema).optional();
|
|
732
866
|
const PublisherSchema = z.object({
|
|
733
867
|
name: z.string().optional(),
|
|
734
868
|
url: z.string().optional()
|
|
@@ -739,7 +873,7 @@ const ConfigEntrySchema = z.object({
|
|
|
739
873
|
type: ConfigEntryTypeSchema,
|
|
740
874
|
description: z.string().optional(),
|
|
741
875
|
required: z.boolean().optional(),
|
|
742
|
-
default: z.
|
|
876
|
+
default: z.string().optional()
|
|
743
877
|
});
|
|
744
878
|
const PwaUrlPatternSchema = z.union([z.string(), z.strictObject({
|
|
745
879
|
source: z.string(),
|
|
@@ -835,7 +969,7 @@ const ManifestSchema = z.object({
|
|
|
835
969
|
editors: PowerhouseModulesSchema,
|
|
836
970
|
processors: PowerhouseModulesSchema,
|
|
837
971
|
subgraphs: PowerhouseModulesSchema,
|
|
838
|
-
pieces:
|
|
972
|
+
pieces: PieceModulesSchema,
|
|
839
973
|
config: z.array(ConfigEntrySchema).optional(),
|
|
840
974
|
pwa: PwaConfigSchema.optional()
|
|
841
975
|
});
|
|
@@ -855,35 +989,6 @@ const undo = (count = 1, scope = "global") => createAction("UNDO", { count }, vo
|
|
|
855
989
|
* @category Actions
|
|
856
990
|
*/
|
|
857
991
|
const redo = (count = 1, scope = "global") => createAction("REDO", { count }, void 0, RedoActionInputSchema, scope);
|
|
858
|
-
/**
|
|
859
|
-
* Joins multiple operations into a single {@link loadState | LOAD_STATE} operation.
|
|
860
|
-
*
|
|
861
|
-
* @remarks
|
|
862
|
-
* Useful to keep operations history smaller. Operations to prune are selected by index,
|
|
863
|
-
* similar to the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | slice} method in Arrays.
|
|
864
|
-
*
|
|
865
|
-
* @param start - Index of the first operation to prune
|
|
866
|
-
* @param end - Index of the last operation to prune
|
|
867
|
-
* @category Actions
|
|
868
|
-
*/
|
|
869
|
-
const prune = (start, end, scope = "global") => createAction("PRUNE", {
|
|
870
|
-
start,
|
|
871
|
-
end
|
|
872
|
-
}, void 0, PruneActionInputSchema, scope);
|
|
873
|
-
/**
|
|
874
|
-
* Replaces the state of the document.
|
|
875
|
-
*
|
|
876
|
-
* @remarks
|
|
877
|
-
* This action shouldn't be used directly. It is dispatched by the {@link prune} action.
|
|
878
|
-
*
|
|
879
|
-
* @param state - State to be set in the document.
|
|
880
|
-
* @param operations - Number of operations that were removed from the previous state.
|
|
881
|
-
* @category Actions
|
|
882
|
-
*/
|
|
883
|
-
const loadState = (state, operations) => createAction("LOAD_STATE", {
|
|
884
|
-
state,
|
|
885
|
-
operations
|
|
886
|
-
}, void 0, LoadStateActionInputSchema);
|
|
887
992
|
const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scope);
|
|
888
993
|
/**
|
|
889
994
|
* Helper function to be used by action creators.
|
|
@@ -981,6 +1086,7 @@ async function buildOperationSignature(context, signMethod) {
|
|
|
981
1086
|
const signature = await signMethod(buildOperationSignatureMessage(params));
|
|
982
1087
|
return [...params, `0x${ab2hex(signature)}`];
|
|
983
1088
|
}
|
|
1089
|
+
/** @deprecated Emits a legacy SHA-1 tuple; sign through `ISigner.signAction`. */
|
|
984
1090
|
async function buildSignedAction(action, reducer, document, signer, signHandler) {
|
|
985
1091
|
const scopeOperations = reducer(document, action, void 0, { reuseOperationResultingState: true }).operations[action.scope];
|
|
986
1092
|
if (!scopeOperations) throw new Error(`No operations found for scope: ${action.scope}`);
|
|
@@ -993,8 +1099,10 @@ async function buildSignedAction(action, reducer, document, signer, signHandler)
|
|
|
993
1099
|
action,
|
|
994
1100
|
previousStateHash
|
|
995
1101
|
}, signHandler);
|
|
996
|
-
|
|
1102
|
+
const actionContext = { signer: actionSigner(signer.user, signer.app, [...signer.signatures, signature]) };
|
|
1103
|
+
return operationWithContext(operation, actionContext);
|
|
997
1104
|
}
|
|
1105
|
+
/** @deprecated Use `verifyActionSignature` from `@powerhousedao/reactor`. */
|
|
998
1106
|
async function verifyOperationSignature(signature, signer, verifyHandler) {
|
|
999
1107
|
const publicKey = signer.app.key;
|
|
1000
1108
|
const params = signature.slice(0, 4);
|
|
@@ -1069,8 +1177,6 @@ const baseActions = {
|
|
|
1069
1177
|
setPreferredEditor,
|
|
1070
1178
|
undo,
|
|
1071
1179
|
redo,
|
|
1072
|
-
prune,
|
|
1073
|
-
loadState,
|
|
1074
1180
|
noop
|
|
1075
1181
|
};
|
|
1076
1182
|
const documentModelActions = {
|
|
@@ -1188,7 +1294,7 @@ var AuthAdministrationMissingError = class extends Error {
|
|
|
1188
1294
|
this.name = "AuthAdministrationMissingError";
|
|
1189
1295
|
}
|
|
1190
1296
|
};
|
|
1191
|
-
const GRANT_KEYS = new Set([
|
|
1297
|
+
const GRANT_KEYS = /* @__PURE__ */ new Set([
|
|
1192
1298
|
"id",
|
|
1193
1299
|
"description",
|
|
1194
1300
|
"effect",
|
|
@@ -1196,13 +1302,13 @@ const GRANT_KEYS = new Set([
|
|
|
1196
1302
|
"capability",
|
|
1197
1303
|
"where"
|
|
1198
1304
|
]);
|
|
1199
|
-
const PRINCIPAL_KINDS = new Set([
|
|
1305
|
+
const PRINCIPAL_KINDS = /* @__PURE__ */ new Set([
|
|
1200
1306
|
"anyone",
|
|
1201
1307
|
"address",
|
|
1202
1308
|
"group",
|
|
1203
1309
|
"match"
|
|
1204
1310
|
]);
|
|
1205
|
-
const COMPARISON_CONDITION_KINDS = new Set([
|
|
1311
|
+
const COMPARISON_CONDITION_KINDS = /* @__PURE__ */ new Set([
|
|
1206
1312
|
"eq",
|
|
1207
1313
|
"ne",
|
|
1208
1314
|
"lt",
|
|
@@ -2531,12 +2637,12 @@ function assertAuthPreservedOnDuplicate(documentId, source, duplicated) {
|
|
|
2531
2637
|
* The auth scope a state snapshot may install, given the policy already there.
|
|
2532
2638
|
*
|
|
2533
2639
|
* `applyAuthAction` is the validated door onto `state.auth`, but a whole-state
|
|
2534
|
-
* snapshot (UPGRADE_DOCUMENT's `initialState
|
|
2535
|
-
*
|
|
2536
|
-
*
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
*
|
|
2640
|
+
* snapshot (UPGRADE_DOCUMENT's `initialState`) replaces the scope wholesale and
|
|
2641
|
+
* is authorized as a `document`-scope write. Without this, a subject holding
|
|
2642
|
+
* `execute` on `document` and no auth grant at all can install a policy of its
|
|
2643
|
+
* choosing, name itself `creator` (which exempts the policy from the retention
|
|
2644
|
+
* rule for good), or wipe an existing policy by carrying the default
|
|
2645
|
+
* uninitialized one.
|
|
2540
2646
|
*
|
|
2541
2647
|
* Three cases:
|
|
2542
2648
|
*
|
|
@@ -2563,13 +2669,9 @@ function resolveSnapshotAuth(documentId, documentType, current, incoming) {
|
|
|
2563
2669
|
assertValidInitialGrants(incoming.grants, documentType, incoming.creator);
|
|
2564
2670
|
return incoming;
|
|
2565
2671
|
}
|
|
2566
|
-
/** UNDO
|
|
2672
|
+
/** UNDO and REDO are rejected on the auth scope. */
|
|
2567
2673
|
function assertAuthScopeActionAllowed(action) {
|
|
2568
|
-
if (action.scope === "auth" && [
|
|
2569
|
-
"UNDO",
|
|
2570
|
-
"REDO",
|
|
2571
|
-
"PRUNE"
|
|
2572
|
-
].includes(action.type)) throw new AuthActionNotAllowedError(action.type);
|
|
2674
|
+
if (action.scope === "auth" && ["UNDO", "REDO"].includes(action.type)) throw new AuthActionNotAllowedError(action.type);
|
|
2573
2675
|
}
|
|
2574
2676
|
/**
|
|
2575
2677
|
* Evaluates the auth policy for a single request and reports why it refused.
|
|
@@ -2675,6 +2777,63 @@ function assertIsDocumentModelDocument(document) {
|
|
|
2675
2777
|
DocumentModelSchema.parse(document);
|
|
2676
2778
|
}
|
|
2677
2779
|
//#endregion
|
|
2780
|
+
//#region document-model/signature-policy.ts
|
|
2781
|
+
/** The `protocolVersions` key that fixes a document's signature requirement. */
|
|
2782
|
+
const SIGNATURE_PROTOCOL = "signature";
|
|
2783
|
+
/** `protocolVersions.signature` of a document that requires v2 tuples. */
|
|
2784
|
+
const SIGNATURE_PROTOCOL_V2 = 2;
|
|
2785
|
+
/** What a new document is created as unless the caller or host says otherwise. */
|
|
2786
|
+
const DEFAULT_SIGNATURE_POLICY = "v2-required";
|
|
2787
|
+
function isSignaturePolicy(value) {
|
|
2788
|
+
return value === "legacy" || value === "v2-required";
|
|
2789
|
+
}
|
|
2790
|
+
const DERIVED_ID = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
2791
|
+
/** Read from a header, a CREATE_DOCUMENT input or a bare map. */
|
|
2792
|
+
function signaturePolicyOf(source) {
|
|
2793
|
+
const version = (source && "protocolVersions" in source ? source.protocolVersions : source)?.[SIGNATURE_PROTOCOL];
|
|
2794
|
+
return typeof version === "number" && version >= 2 ? "v2-required" : "legacy";
|
|
2795
|
+
}
|
|
2796
|
+
/** `protocolVersions` for a new v2-required document. */
|
|
2797
|
+
function v2RequiredProtocolVersions(base = {}) {
|
|
2798
|
+
return {
|
|
2799
|
+
"base-reducer": 2,
|
|
2800
|
+
...base,
|
|
2801
|
+
[SIGNATURE_PROTOCOL]: 2
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
/**
|
|
2805
|
+
* The policy a create call asks for: `signaturePolicy`, else the `signature`
|
|
2806
|
+
* key of its `protocolVersions`, else `fallback`, the host's default.
|
|
2807
|
+
*/
|
|
2808
|
+
function requestedSignaturePolicy(request, fallback) {
|
|
2809
|
+
if (request?.signaturePolicy) return request.signaturePolicy;
|
|
2810
|
+
if (request?.protocolVersions?.["signature"] !== void 0) return signaturePolicyOf(request.protocolVersions);
|
|
2811
|
+
return fallback;
|
|
2812
|
+
}
|
|
2813
|
+
/** `protocolVersions` for a new document under `policy`, over `base`. */
|
|
2814
|
+
function protocolVersionsFor(policy, base = {}) {
|
|
2815
|
+
if (policy === "v2-required") return v2RequiredProtocolVersions(base);
|
|
2816
|
+
const { [SIGNATURE_PROTOCOL]: _signature, ...rest } = base;
|
|
2817
|
+
return {
|
|
2818
|
+
"base-reducer": 2,
|
|
2819
|
+
...rest
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
/** `base64url(sha256(canonicalJson(params)))`, unpadded. */
|
|
2823
|
+
function deriveDocumentId(params) {
|
|
2824
|
+
const preimage = canonicalJson({
|
|
2825
|
+
documentType: params.documentType,
|
|
2826
|
+
createdAtUtcIso: params.createdAtUtcIso,
|
|
2827
|
+
nonce: params.nonce,
|
|
2828
|
+
protocolVersions: params.protocolVersions
|
|
2829
|
+
}, "document id");
|
|
2830
|
+
return bytesToBase64Url(sha256(new TextEncoder().encode(preimage)));
|
|
2831
|
+
}
|
|
2832
|
+
/** Whether `id` has the shape `deriveDocumentId` produces. */
|
|
2833
|
+
function isDerivedDocumentId(id) {
|
|
2834
|
+
return DERIVED_ID.test(id);
|
|
2835
|
+
}
|
|
2836
|
+
//#endregion
|
|
2678
2837
|
//#region document-model/header.ts
|
|
2679
2838
|
/**
|
|
2680
2839
|
* Generates a deterministic payload from signing parameters
|
|
@@ -2694,11 +2853,11 @@ async function createVerificationSigner(pubKey) {
|
|
|
2694
2853
|
}, true, ["verify"]);
|
|
2695
2854
|
return {
|
|
2696
2855
|
publicKey: cryptoKey,
|
|
2697
|
-
|
|
2698
|
-
|
|
2856
|
+
sign(_data) {
|
|
2857
|
+
return Promise.reject(/* @__PURE__ */ new Error("verification-only signer cannot sign data"));
|
|
2699
2858
|
},
|
|
2700
|
-
|
|
2701
|
-
|
|
2859
|
+
signAction(_action, _target, _abortSignal) {
|
|
2860
|
+
return Promise.reject(/* @__PURE__ */ new Error("verification-only signer cannot sign actions"));
|
|
2702
2861
|
},
|
|
2703
2862
|
async verify(data, signature) {
|
|
2704
2863
|
let isValid;
|
|
@@ -2768,26 +2927,68 @@ const validateHeader = async (header) => {
|
|
|
2768
2927
|
* Creates a header that has yet to be signed. This header is not valid, but
|
|
2769
2928
|
* can be input into {@link createSignedHeader} to create a signed header.
|
|
2770
2929
|
*
|
|
2930
|
+
* With `protocolVersions` requiring v2 signatures the header takes a random
|
|
2931
|
+
* nonce and the id {@link deriveDocumentId} gives, so `id` must be omitted.
|
|
2932
|
+
*
|
|
2771
2933
|
* @returns An unsigned header for a document.
|
|
2772
2934
|
*/
|
|
2773
|
-
const createPresignedHeader = (id
|
|
2774
|
-
|
|
2775
|
-
|
|
2935
|
+
const createPresignedHeader = (id, documentType = "", protocolVersions) => {
|
|
2936
|
+
const createdAtUtcIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
2937
|
+
const header = {
|
|
2938
|
+
id: id ?? generateId(),
|
|
2776
2939
|
sig: {
|
|
2777
2940
|
publicKey: {},
|
|
2778
2941
|
nonce: ""
|
|
2779
2942
|
},
|
|
2780
2943
|
documentType,
|
|
2781
|
-
createdAtUtcIso
|
|
2944
|
+
createdAtUtcIso,
|
|
2782
2945
|
slug: "",
|
|
2783
2946
|
name: "",
|
|
2784
2947
|
branch: "main",
|
|
2785
2948
|
revision: { document: 0 },
|
|
2786
|
-
lastModifiedAtUtcIso:
|
|
2949
|
+
lastModifiedAtUtcIso: createdAtUtcIso,
|
|
2787
2950
|
meta: {}
|
|
2788
2951
|
};
|
|
2952
|
+
if (protocolVersions === void 0) return header;
|
|
2953
|
+
header.protocolVersions = { ...protocolVersions };
|
|
2954
|
+
if (signaturePolicyOf(header) === "legacy") return header;
|
|
2955
|
+
if (id !== void 0) throw new Error(`A v2-required document's id is derived from its header; cannot use ${id}`);
|
|
2956
|
+
header.sig.nonce = generateId();
|
|
2957
|
+
header.id = deriveDocumentId({
|
|
2958
|
+
documentType,
|
|
2959
|
+
createdAtUtcIso,
|
|
2960
|
+
nonce: header.sig.nonce,
|
|
2961
|
+
protocolVersions: header.protocolVersions
|
|
2962
|
+
});
|
|
2963
|
+
return header;
|
|
2789
2964
|
};
|
|
2790
2965
|
/**
|
|
2966
|
+
* A header for a copy of a document headed `source`. A copy is v2-required
|
|
2967
|
+
* when its source is or when `policy` asks for it, and then takes a derived id;
|
|
2968
|
+
* otherwise it takes `id`. It keeps the source's other protocol versions.
|
|
2969
|
+
*/
|
|
2970
|
+
function createCopyHeader(source, id, policy = DEFAULT_SIGNATURE_POLICY) {
|
|
2971
|
+
const base = source.protocolVersions ?? {};
|
|
2972
|
+
if (signaturePolicyOf(source) === "v2-required" || policy === "v2-required") return createPresignedHeader(void 0, source.documentType, protocolVersionsFor("v2-required", base));
|
|
2973
|
+
const header = createPresignedHeader(id, source.documentType);
|
|
2974
|
+
if (source.protocolVersions) header.protocolVersions = { ...source.protocolVersions };
|
|
2975
|
+
return header;
|
|
2976
|
+
}
|
|
2977
|
+
/** Whether a v2-required `header` carries the id its params derive. */
|
|
2978
|
+
function hasDerivedDocumentId(header) {
|
|
2979
|
+
if (signaturePolicyOf(header) === "legacy" || !header.protocolVersions) return false;
|
|
2980
|
+
try {
|
|
2981
|
+
return deriveDocumentId({
|
|
2982
|
+
documentType: header.documentType,
|
|
2983
|
+
createdAtUtcIso: header.createdAtUtcIso,
|
|
2984
|
+
nonce: header.sig.nonce,
|
|
2985
|
+
protocolVersions: header.protocolVersions
|
|
2986
|
+
}) === header.id;
|
|
2987
|
+
} catch {
|
|
2988
|
+
return false;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2791
2992
|
* Creates a new, signed header for a document. This will replace the id of the
|
|
2792
2993
|
* document.
|
|
2793
2994
|
*
|
|
@@ -2830,7 +3031,8 @@ const createSignedHeader = async (unsignedHeader, documentType, signer) => {
|
|
|
2830
3031
|
* some are not. See the PHDocumentHeader type for more information.
|
|
2831
3032
|
*/
|
|
2832
3033
|
const createSignedHeaderForSigner = async (documentType, signer) => {
|
|
2833
|
-
|
|
3034
|
+
const unsignedHeader = createPresignedHeader();
|
|
3035
|
+
return await createSignedHeader(unsignedHeader, documentType, signer);
|
|
2834
3036
|
};
|
|
2835
3037
|
//#endregion
|
|
2836
3038
|
//#region document-model/documents.ts
|
|
@@ -2848,9 +3050,7 @@ function isDocumentAction(action) {
|
|
|
2848
3050
|
"SET_NAME",
|
|
2849
3051
|
"SET_PREFERRED_EDITOR",
|
|
2850
3052
|
"UNDO",
|
|
2851
|
-
"REDO"
|
|
2852
|
-
"PRUNE",
|
|
2853
|
-
"LOAD_STATE"
|
|
3053
|
+
"REDO"
|
|
2854
3054
|
].includes(action.type);
|
|
2855
3055
|
}
|
|
2856
3056
|
/**
|
|
@@ -2906,12 +3106,16 @@ function createDocumentScopeOperations(header, state) {
|
|
|
2906
3106
|
}
|
|
2907
3107
|
/**
|
|
2908
3108
|
* Creates a new document. When `documentType` is given the header is stamped
|
|
2909
|
-
* with it and the document-scope operations are seeded.
|
|
3109
|
+
* with it and the document-scope operations are seeded. Without
|
|
3110
|
+
* `protocolVersions` the document is v2-required and takes a derived id; with
|
|
3111
|
+
* them it is v2-required only if they say so (see {@link protocolVersionsFor}).
|
|
2910
3112
|
*/
|
|
2911
|
-
function baseCreateDocument(createState, initialState, documentType = "") {
|
|
3113
|
+
function baseCreateDocument(createState, initialState, documentType = "", protocolVersions) {
|
|
2912
3114
|
const state = createState(initialState);
|
|
2913
|
-
const header = createPresignedHeader(
|
|
2914
|
-
|
|
3115
|
+
const header = createPresignedHeader(void 0, documentType, protocolVersions === void 0 ? protocolVersionsFor("v2-required") : {
|
|
3116
|
+
"base-reducer": 2,
|
|
3117
|
+
...protocolVersions
|
|
3118
|
+
});
|
|
2915
3119
|
return {
|
|
2916
3120
|
header,
|
|
2917
3121
|
state,
|
|
@@ -2927,8 +3131,39 @@ function baseCreateDocument(createState, initialState, documentType = "") {
|
|
|
2927
3131
|
clipboard: []
|
|
2928
3132
|
};
|
|
2929
3133
|
}
|
|
3134
|
+
/**
|
|
3135
|
+
* `document`, not yet created, under a fresh header for `policy`. A legacy
|
|
3136
|
+
* header takes `id` when given; a v2-required one ignores `id` and derives its
|
|
3137
|
+
* own, so a caller that needs a fixed id must ask for legacy.
|
|
3138
|
+
* `protocolVersions` are merged over the document's. Name, slug, branch and
|
|
3139
|
+
* meta carry over. A document already under `policy` is returned as is unless
|
|
3140
|
+
* a legacy `id` or `protocolVersions` are given.
|
|
3141
|
+
*/
|
|
3142
|
+
function withSignaturePolicy(document, policy, options = {}) {
|
|
3143
|
+
const id = policy === "legacy" ? options.id : void 0;
|
|
3144
|
+
if (id === void 0 && options.protocolVersions === void 0 && signaturePolicyOf(document.header) === policy) return document;
|
|
3145
|
+
const source = document.header;
|
|
3146
|
+
const header = createPresignedHeader(id, source.documentType, protocolVersionsFor(policy, {
|
|
3147
|
+
...source.protocolVersions,
|
|
3148
|
+
...options.protocolVersions
|
|
3149
|
+
}));
|
|
3150
|
+
header.name = source.name;
|
|
3151
|
+
header.slug = source.slug;
|
|
3152
|
+
header.branch = source.branch;
|
|
3153
|
+
header.meta = source.meta;
|
|
3154
|
+
const operations = document.operations.document ? {
|
|
3155
|
+
...document.operations,
|
|
3156
|
+
document: createDocumentScopeOperations(header, document.state)
|
|
3157
|
+
} : document.operations;
|
|
3158
|
+
return {
|
|
3159
|
+
...document,
|
|
3160
|
+
header,
|
|
3161
|
+
operations
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
2930
3164
|
function hashDocumentStateForScope(document, scope = "global") {
|
|
2931
|
-
|
|
3165
|
+
const stateString = stringify(document.state[scope] || "");
|
|
3166
|
+
return hashBrowser(stateString);
|
|
2932
3167
|
}
|
|
2933
3168
|
function readOnly(value) {
|
|
2934
3169
|
return Object.freeze(value);
|
|
@@ -3059,7 +3294,7 @@ function replayDocument(initialState, operations, reducer, header, dispatch, ski
|
|
|
3059
3294
|
const backfilledInitialState = backfillAuthState(initialState);
|
|
3060
3295
|
let documentState = backfilledInitialState;
|
|
3061
3296
|
const operationsToReplay = [];
|
|
3062
|
-
const allScopes = new Set([
|
|
3297
|
+
const allScopes = /* @__PURE__ */ new Set([
|
|
3063
3298
|
...Object.keys(operations),
|
|
3064
3299
|
"global",
|
|
3065
3300
|
"local"
|
|
@@ -3117,7 +3352,7 @@ function replayDocument(initialState, operations, reducer, header, dispatch, ski
|
|
|
3117
3352
|
if (operation.hash !== hashDocumentStateForScope(result, scope)) throw new HashMismatchError(scope, result, operation);
|
|
3118
3353
|
else break;
|
|
3119
3354
|
}
|
|
3120
|
-
const allResultScopes = new Set([
|
|
3355
|
+
const allResultScopes = /* @__PURE__ */ new Set([
|
|
3121
3356
|
...Object.keys(result.operations),
|
|
3122
3357
|
...Object.keys(operations),
|
|
3123
3358
|
"global",
|
|
@@ -3180,8 +3415,8 @@ function checkCleanedOperationsIntegrity(sortedOperations) {
|
|
|
3180
3415
|
index: nextOperation.index,
|
|
3181
3416
|
skip: nextOperation.skip
|
|
3182
3417
|
},
|
|
3183
|
-
issue:
|
|
3184
|
-
category: nextIndex > currentIndex + 1 ?
|
|
3418
|
+
issue: "UNEXPECTED_INDEX",
|
|
3419
|
+
category: nextIndex > currentIndex + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
|
|
3185
3420
|
message: `Expected index ${currentIndex + 1} with skip 0 or equivalent, got index ${nextOperation.index} with skip ${nextOperation.skip}`
|
|
3186
3421
|
});
|
|
3187
3422
|
currentIndex = nextOperation.index;
|
|
@@ -3291,12 +3526,14 @@ function attachBranch(trunk, newBranch) {
|
|
|
3291
3526
|
nextTrunkOperation = trunkCopy.shift();
|
|
3292
3527
|
}
|
|
3293
3528
|
if (!nextTrunkOperation) enteredBranch = true;
|
|
3294
|
-
else if (!enteredBranch)
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3529
|
+
else if (!enteredBranch) {
|
|
3530
|
+
if (operationsAreEqual(nextTrunkOperation, newOperationCandidate)) {
|
|
3531
|
+
newOperations.shift();
|
|
3532
|
+
result.push(nextTrunkOperation);
|
|
3533
|
+
} else {
|
|
3534
|
+
trunkCopy.unshift(nextTrunkOperation);
|
|
3535
|
+
enteredBranch = true;
|
|
3536
|
+
}
|
|
3300
3537
|
}
|
|
3301
3538
|
if (enteredBranch) {
|
|
3302
3539
|
let nextAppend = newOperations.shift();
|
|
@@ -3327,13 +3564,14 @@ function split(sortedTargetOperations, sortedMergeOperations) {
|
|
|
3327
3564
|
for (let i = 0; i < maxLength; i++) {
|
|
3328
3565
|
const targetOperation = sortedTargetOperations[i];
|
|
3329
3566
|
const mergeOperation = sortedMergeOperations[i];
|
|
3330
|
-
if (targetOperation && mergeOperation)
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3567
|
+
if (targetOperation && mergeOperation) {
|
|
3568
|
+
if (!splitHappened && operationsAreEqual(targetOperation, mergeOperation)) commonOperations.push(targetOperation);
|
|
3569
|
+
else {
|
|
3570
|
+
splitHappened = true;
|
|
3571
|
+
targetDiffOperations.push(targetOperation);
|
|
3572
|
+
mergeDiffOperations.push(mergeOperation);
|
|
3573
|
+
}
|
|
3574
|
+
} else if (targetOperation) targetDiffOperations.push(targetOperation);
|
|
3337
3575
|
else if (mergeOperation) mergeDiffOperations.push(mergeOperation);
|
|
3338
3576
|
}
|
|
3339
3577
|
return [
|
|
@@ -3385,14 +3623,14 @@ function prepareOperations(operationsHistory, newOperations) {
|
|
|
3385
3623
|
const sortedOperationsHistory = sortOperations(operationsHistory);
|
|
3386
3624
|
const sortedOperations = sortOperations(newOperations);
|
|
3387
3625
|
const integrityErrors = checkCleanedOperationsIntegrity([...sortedOperationsHistory, ...sortedOperations]);
|
|
3388
|
-
const firstMissingIndexOperation = [...integrityErrors.filter((integrityIssue) => integrityIssue.category ===
|
|
3626
|
+
const firstMissingIndexOperation = [...integrityErrors.filter((integrityIssue) => integrityIssue.category === "MISSING_INDEX")].sort((a, b) => b.operation.index - a.operation.index).pop()?.operation;
|
|
3389
3627
|
for (const newOperation of sortedOperations) {
|
|
3390
3628
|
if (firstMissingIndexOperation && newOperation.index >= firstMissingIndexOperation.index) {
|
|
3391
3629
|
result.invalidOperations.push(newOperation);
|
|
3392
3630
|
continue;
|
|
3393
3631
|
}
|
|
3394
3632
|
if (integrityErrors.some((integrityError) => {
|
|
3395
|
-
return integrityError.operation.index === newOperation.index && integrityError.operation.skip === newOperation.skip && integrityError.category ===
|
|
3633
|
+
return integrityError.operation.index === newOperation.index && integrityError.operation.skip === newOperation.skip && integrityError.category === "DUPLICATED_INDEX";
|
|
3396
3634
|
})) {
|
|
3397
3635
|
result.duplicatedOperations.push(newOperation);
|
|
3398
3636
|
continue;
|
|
@@ -3621,18 +3859,6 @@ function redoOperation(document, action, skip) {
|
|
|
3621
3859
|
});
|
|
3622
3860
|
});
|
|
3623
3861
|
}
|
|
3624
|
-
function loadStateOperation(document, action) {
|
|
3625
|
-
const loaded = backfillAuthState(action.state.data);
|
|
3626
|
-
loaded.auth = resolveSnapshotAuth(document.header.id, document.header.documentType, backfillAuthState({ ...document.state }).auth, loaded.auth);
|
|
3627
|
-
return {
|
|
3628
|
-
...document,
|
|
3629
|
-
header: {
|
|
3630
|
-
...document.header,
|
|
3631
|
-
name: action.state.name
|
|
3632
|
-
},
|
|
3633
|
-
state: loaded
|
|
3634
|
-
};
|
|
3635
|
-
}
|
|
3636
3862
|
/**
|
|
3637
3863
|
* Reads an operation's outcome. A denial takes precedence over a reducer
|
|
3638
3864
|
* error, since a denied operation never reaches its reducer.
|
|
@@ -3665,15 +3891,12 @@ function replayOperations(initialState, clearedOperations, stateReducer, header,
|
|
|
3665
3891
|
* @returns The updated document state.
|
|
3666
3892
|
*/
|
|
3667
3893
|
function updateOperationsForAction(document, action, reuseLastOperationIndex, skip, context) {
|
|
3668
|
-
if ([
|
|
3669
|
-
"UNDO",
|
|
3670
|
-
"REDO",
|
|
3671
|
-
"PRUNE"
|
|
3672
|
-
].includes(action.type)) return document;
|
|
3894
|
+
if (["UNDO", "REDO"].includes(action.type)) return document;
|
|
3673
3895
|
const scope = action.scope;
|
|
3674
3896
|
const existing = document.operations[scope];
|
|
3675
3897
|
const lastOperationIndex = existing?.at(-1)?.index ?? -1;
|
|
3676
|
-
const
|
|
3898
|
+
const index = reuseLastOperationIndex ? lastOperationIndex : lastOperationIndex + 1;
|
|
3899
|
+
const newOperation = operationFromAction(action, index, skip, context);
|
|
3677
3900
|
const operations = [...existing ?? [], newOperation];
|
|
3678
3901
|
return {
|
|
3679
3902
|
...document,
|
|
@@ -3717,20 +3940,17 @@ function updateDocument(document, action, reuseLastOperationIndex, skip, context
|
|
|
3717
3940
|
return newDocument;
|
|
3718
3941
|
}
|
|
3719
3942
|
/**
|
|
3720
|
-
* The base document reducer function
|
|
3943
|
+
* The base document reducer function.
|
|
3721
3944
|
*
|
|
3722
3945
|
* @param state The current state of the document.
|
|
3723
3946
|
* @param action The action being applied to the document.
|
|
3724
|
-
* @param wrappedReducer The custom reducer function being wrapped by the base reducer.
|
|
3725
3947
|
* @returns The updated document state.
|
|
3726
3948
|
*/
|
|
3727
|
-
function _baseReducer(document, action
|
|
3949
|
+
function _baseReducer(document, action) {
|
|
3728
3950
|
const parsedAction = DocumentActionSchema().parse(action);
|
|
3729
3951
|
switch (parsedAction.type) {
|
|
3730
3952
|
case "SET_NAME": return setNameOperation(document, parsedAction.input);
|
|
3731
3953
|
case "SET_PREFERRED_EDITOR": return setPreferredEditorOperation(document, parsedAction.input);
|
|
3732
|
-
case "PRUNE": return pruneOperation(document, parsedAction.input, wrappedReducer);
|
|
3733
|
-
case "LOAD_STATE": return loadStateOperation(document, parsedAction.input);
|
|
3734
3954
|
default: return document;
|
|
3735
3955
|
}
|
|
3736
3956
|
}
|
|
@@ -3808,7 +4028,7 @@ function processUndoOperation(document, scope, customReducer, reuseOperationResu
|
|
|
3808
4028
|
}
|
|
3809
4029
|
/**
|
|
3810
4030
|
* Base document reducer that wraps a custom document reducer and handles
|
|
3811
|
-
* document-level actions such as undo, redo,
|
|
4031
|
+
* document-level actions such as undo, redo, and set name.
|
|
3812
4032
|
*
|
|
3813
4033
|
* @template TGlobalState - The type of the state of the custom reducer.
|
|
3814
4034
|
* @template TAction - The type of the actions of the custom reducer.
|
|
@@ -3836,7 +4056,7 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
3836
4056
|
...newDocument,
|
|
3837
4057
|
clipboard: []
|
|
3838
4058
|
};
|
|
3839
|
-
if (isDocumentAction(_action)) newDocument = _baseReducer(newDocument, _action
|
|
4059
|
+
if (isDocumentAction(_action)) newDocument = _baseReducer(newDocument, _action);
|
|
3840
4060
|
const operationContext = {
|
|
3841
4061
|
documentId: document.header.id,
|
|
3842
4062
|
scope: _action.scope,
|
|
@@ -3899,11 +4119,7 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
3899
4119
|
}
|
|
3900
4120
|
}
|
|
3901
4121
|
});
|
|
3902
|
-
if ([
|
|
3903
|
-
"UNDO",
|
|
3904
|
-
"REDO",
|
|
3905
|
-
"PRUNE"
|
|
3906
|
-
].includes(_action.type)) return newDocument;
|
|
4122
|
+
if (["UNDO", "REDO"].includes(_action.type)) return newDocument;
|
|
3907
4123
|
const scope = _action.scope || "global";
|
|
3908
4124
|
const replayHash = options.replayOptions?.operation.hash;
|
|
3909
4125
|
const hash = replayHash ? replayHash : hashDocumentStateForScope(newDocument, scope);
|
|
@@ -3923,7 +4139,6 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
|
3923
4139
|
* - `SET_NAME`
|
|
3924
4140
|
* - `UNDO`
|
|
3925
4141
|
* - `REDO`
|
|
3926
|
-
* - `PRUNE`
|
|
3927
4142
|
*
|
|
3928
4143
|
* It also updates the document-related attributes on every operation.
|
|
3929
4144
|
*
|
|
@@ -3938,46 +4153,6 @@ function createReducer(stateReducer, documentReducer = baseReducer) {
|
|
|
3938
4153
|
};
|
|
3939
4154
|
return reducer;
|
|
3940
4155
|
}
|
|
3941
|
-
function pruneOperation(document, input, wrappedReducer) {
|
|
3942
|
-
const operations = document.operations.global;
|
|
3943
|
-
if (!operations) throw new Error("No global operations found");
|
|
3944
|
-
let { start, end } = input;
|
|
3945
|
-
start = start || 0;
|
|
3946
|
-
end = end || operations.length;
|
|
3947
|
-
const actionsToPrune = operations.slice(start, end);
|
|
3948
|
-
const actionsToKeepStart = operations.slice(0, start);
|
|
3949
|
-
const actionsToKeepEnd = operations.slice(end);
|
|
3950
|
-
const newDocument = replayOperations(document.initialState, {
|
|
3951
|
-
...document.operations,
|
|
3952
|
-
global: actionsToKeepStart.concat(actionsToPrune)
|
|
3953
|
-
}, wrappedReducer, document.header);
|
|
3954
|
-
const newState = newDocument.state;
|
|
3955
|
-
const name = newDocument.header.name;
|
|
3956
|
-
const loadStateIndex = actionsToKeepStart.length;
|
|
3957
|
-
const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestampUtcMs : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestampUtcMs : (/* @__PURE__ */ new Date()).toISOString();
|
|
3958
|
-
const action = loadState({
|
|
3959
|
-
name,
|
|
3960
|
-
...newState
|
|
3961
|
-
}, actionsToPrune.length);
|
|
3962
|
-
return replayOperations(document.initialState, {
|
|
3963
|
-
...document.operations,
|
|
3964
|
-
global: [
|
|
3965
|
-
...actionsToKeepStart,
|
|
3966
|
-
{
|
|
3967
|
-
skip: 0,
|
|
3968
|
-
...action,
|
|
3969
|
-
action,
|
|
3970
|
-
timestampUtcMs: loadStateTimestamp,
|
|
3971
|
-
index: loadStateIndex,
|
|
3972
|
-
hash: hashDocumentStateForScope({ state: newState }, "global")
|
|
3973
|
-
},
|
|
3974
|
-
...actionsToKeepEnd.map((action, index) => ({
|
|
3975
|
-
...action,
|
|
3976
|
-
index: loadStateIndex + index + 1
|
|
3977
|
-
}))
|
|
3978
|
-
]
|
|
3979
|
-
}, wrappedReducer, document.header);
|
|
3980
|
-
}
|
|
3981
4156
|
//#endregion
|
|
3982
4157
|
//#region document-model/validation.ts
|
|
3983
4158
|
/**
|
|
@@ -3987,8 +4162,6 @@ function pruneOperation(document, input, wrappedReducer) {
|
|
|
3987
4162
|
const RESERVED_OPERATION_NAMES = [
|
|
3988
4163
|
"UNDO",
|
|
3989
4164
|
"REDO",
|
|
3990
|
-
"PRUNE",
|
|
3991
|
-
"LOAD_STATE",
|
|
3992
4165
|
"SET_NAME",
|
|
3993
4166
|
"SET_PREFERRED_EDITOR",
|
|
3994
4167
|
"NOOP"
|
|
@@ -4227,6 +4400,15 @@ function orderBy(items, order) {
|
|
|
4227
4400
|
return (rank.get(a.item.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.item.id) ?? Number.MAX_SAFE_INTEGER) || a.index - b.index;
|
|
4228
4401
|
}).map(({ item }) => item);
|
|
4229
4402
|
}
|
|
4403
|
+
/**
|
|
4404
|
+
* The untouched base of a mutative draft, or the value itself when it is not a
|
|
4405
|
+
* draft. Build replacement lists from it and freeze them before assigning, as
|
|
4406
|
+
* the drive node reducer does, so finalize skips the walk over the assigned
|
|
4407
|
+
* list. Read before writing: the base does not see this action's mutations.
|
|
4408
|
+
*/
|
|
4409
|
+
function readBase(value) {
|
|
4410
|
+
return isDraft(value) ? original(value) : value;
|
|
4411
|
+
}
|
|
4230
4412
|
const documentModelHeaderReducer = {
|
|
4231
4413
|
setModelNameOperation(state, action) {
|
|
4232
4414
|
state.name = action.input.name;
|
|
@@ -4276,7 +4458,8 @@ const documentModelModuleReducer = {
|
|
|
4276
4458
|
deleteModuleOperation(state, action) {
|
|
4277
4459
|
findModuleOrThrow(state, action.input.id);
|
|
4278
4460
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
4279
|
-
|
|
4461
|
+
const modules = readBase(latestSpec).modules.filter((m) => m.id != action.input.id);
|
|
4462
|
+
latestSpec.modules = Object.freeze(modules);
|
|
4280
4463
|
},
|
|
4281
4464
|
reorderModulesOperation(state, action) {
|
|
4282
4465
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
@@ -4394,14 +4577,20 @@ const documentModelOperationReducer = {
|
|
|
4394
4577
|
const matches = latestSpec.modules.flatMap((mod) => mod.operations.filter((op) => op.id === action.input.operationId));
|
|
4395
4578
|
if (matches.length === 0) throw new Error(`Operation "${action.input.operationId}" not found in the latest specification`);
|
|
4396
4579
|
if (matches.length > 1) throw new Error(`Operation "${action.input.operationId}" is duplicated in the latest specification`);
|
|
4397
|
-
const moved = matches[0];
|
|
4398
|
-
for (const mod of latestSpec.modules)
|
|
4399
|
-
|
|
4580
|
+
const moved = readBase(matches[0]);
|
|
4581
|
+
for (const mod of latestSpec.modules) {
|
|
4582
|
+
const operations = readBase(mod).operations.filter((op) => op.id !== action.input.operationId);
|
|
4583
|
+
if (mod === targetModule) operations.push(moved);
|
|
4584
|
+
mod.operations = Object.freeze(operations);
|
|
4585
|
+
}
|
|
4400
4586
|
},
|
|
4401
4587
|
deleteOperationOperation(state, action) {
|
|
4402
4588
|
findOperationOrThrow(state, action.input.id);
|
|
4403
4589
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
4404
|
-
for (const mod of latestSpec.modules)
|
|
4590
|
+
for (const mod of latestSpec.modules) {
|
|
4591
|
+
const operations = readBase(mod).operations.filter((operation) => operation.id != action.input.id);
|
|
4592
|
+
mod.operations = Object.freeze(operations);
|
|
4593
|
+
}
|
|
4405
4594
|
},
|
|
4406
4595
|
reorderModuleOperationsOperation(state, action) {
|
|
4407
4596
|
const targetModule = findModuleOrThrow(state, action.input.moduleId);
|
|
@@ -4439,7 +4628,8 @@ const documentModelStateSchemaReducer = {
|
|
|
4439
4628
|
if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
|
|
4440
4629
|
const scopeState = latestSpec.state[action.input.scope];
|
|
4441
4630
|
if (!scopeState.examples.some((e) => e.id == action.input.id)) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
|
|
4442
|
-
|
|
4631
|
+
const examples = readBase(scopeState).examples.filter((e) => e.id != action.input.id);
|
|
4632
|
+
scopeState.examples = Object.freeze(examples);
|
|
4443
4633
|
},
|
|
4444
4634
|
reorderStateExamplesOperation(state, action) {
|
|
4445
4635
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
@@ -4709,7 +4899,11 @@ function applyUpgradeDocumentAction(document, action, upgradePath) {
|
|
|
4709
4899
|
const toVersion = action.input.toVersion;
|
|
4710
4900
|
if (fromVersion === toVersion && fromVersion > 0) return document;
|
|
4711
4901
|
if (fromVersion > toVersion) throw new DowngradeNotSupportedError(document.header.documentType, fromVersion, toVersion);
|
|
4712
|
-
if (upgradePath)
|
|
4902
|
+
if (upgradePath) {
|
|
4903
|
+
const protocolVersions = document.header.protocolVersions;
|
|
4904
|
+
for (const transition of upgradePath) document = transition.upgradeReducer(document, action);
|
|
4905
|
+
document = withProtocolVersions(document, protocolVersions);
|
|
4906
|
+
}
|
|
4713
4907
|
applyInitialState(document, action);
|
|
4714
4908
|
document.state.document = {
|
|
4715
4909
|
...document.state.document,
|
|
@@ -4717,6 +4911,16 @@ function applyUpgradeDocumentAction(document, action, upgradePath) {
|
|
|
4717
4911
|
};
|
|
4718
4912
|
return document;
|
|
4719
4913
|
}
|
|
4914
|
+
/** CREATE_DOCUMENT fixes `protocolVersions`; this puts them back after a reducer. */
|
|
4915
|
+
function withProtocolVersions(document, protocolVersions) {
|
|
4916
|
+
const header = { ...document.header };
|
|
4917
|
+
if (protocolVersions === void 0) delete header.protocolVersions;
|
|
4918
|
+
else header.protocolVersions = { ...protocolVersions };
|
|
4919
|
+
return {
|
|
4920
|
+
...document,
|
|
4921
|
+
header
|
|
4922
|
+
};
|
|
4923
|
+
}
|
|
4720
4924
|
/**
|
|
4721
4925
|
* Applies a DELETE_DOCUMENT action to a document.
|
|
4722
4926
|
* Marks the document as deleted in the document scope state.
|
|
@@ -4842,7 +5046,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
4842
5046
|
const curr = boundaries[i]?.[s] ?? 0;
|
|
4843
5047
|
if (boundaries[i]) boundaries[i][s] = Math.max(prev, curr);
|
|
4844
5048
|
}
|
|
4845
|
-
const allScopes = new Set([
|
|
5049
|
+
const allScopes = /* @__PURE__ */ new Set([
|
|
4846
5050
|
...Object.keys(operations),
|
|
4847
5051
|
"global",
|
|
4848
5052
|
"local"
|
|
@@ -4929,7 +5133,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
|
|
|
4929
5133
|
}
|
|
4930
5134
|
}
|
|
4931
5135
|
}
|
|
4932
|
-
const allResultScopes = new Set([
|
|
5136
|
+
const allResultScopes = /* @__PURE__ */ new Set([
|
|
4933
5137
|
...Object.keys(document.operations),
|
|
4934
5138
|
...Object.keys(operations),
|
|
4935
5139
|
"global",
|
|
@@ -5013,22 +5217,22 @@ async function createZip(document) {
|
|
|
5013
5217
|
*/
|
|
5014
5218
|
async function createMinimalZip(data) {
|
|
5015
5219
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5016
|
-
const header = {
|
|
5017
|
-
id: data.documentId,
|
|
5018
|
-
sig: {
|
|
5019
|
-
publicKey: {},
|
|
5020
|
-
nonce: ""
|
|
5021
|
-
},
|
|
5022
|
-
documentType: data.documentType,
|
|
5023
|
-
createdAtUtcIso: now,
|
|
5024
|
-
slug: data.name,
|
|
5025
|
-
name: data.name,
|
|
5026
|
-
branch: data.branch,
|
|
5027
|
-
revision: {},
|
|
5028
|
-
lastModifiedAtUtcIso: now
|
|
5029
|
-
};
|
|
5030
5220
|
return zipAsync({
|
|
5031
|
-
"header.json": jsonEntry(
|
|
5221
|
+
"header.json": jsonEntry({
|
|
5222
|
+
id: data.documentId,
|
|
5223
|
+
sig: {
|
|
5224
|
+
publicKey: {},
|
|
5225
|
+
nonce: ""
|
|
5226
|
+
},
|
|
5227
|
+
documentType: data.documentType,
|
|
5228
|
+
createdAtUtcIso: now,
|
|
5229
|
+
slug: data.name,
|
|
5230
|
+
name: data.name,
|
|
5231
|
+
branch: data.branch,
|
|
5232
|
+
revision: {},
|
|
5233
|
+
lastModifiedAtUtcIso: now,
|
|
5234
|
+
...data.protocolVersions && { protocolVersions: data.protocolVersions }
|
|
5235
|
+
}),
|
|
5032
5236
|
"state.json": jsonEntry(data.state),
|
|
5033
5237
|
"current-state.json": jsonEntry(data.state),
|
|
5034
5238
|
"operations.json": jsonEntry({})
|
|
@@ -5052,7 +5256,10 @@ async function parseZipData(data) {
|
|
|
5052
5256
|
if (!files["header.json"]) throw new Error("Document header not found - file format may be outdated");
|
|
5053
5257
|
const header = JSON.parse(readEntry(files, "header.json"));
|
|
5054
5258
|
if (!files["operations.json"]) throw new Error("Operations history not found");
|
|
5055
|
-
const
|
|
5259
|
+
const operations = JSON.parse(readEntry(files, "operations.json"));
|
|
5260
|
+
const clearedOperations = garbageCollectDocumentOperations(operations);
|
|
5261
|
+
pinProtocolVersionsToCreate(header, operations);
|
|
5262
|
+
backfillBaseReducerVersion(header);
|
|
5056
5263
|
const operationsError = validateOperations(clearedOperations);
|
|
5057
5264
|
if (operationsError.length) {
|
|
5058
5265
|
const errorMessages = operationsError.map((err) => err.message);
|
|
@@ -5064,6 +5271,25 @@ async function parseZipData(data) {
|
|
|
5064
5271
|
clearedOperations
|
|
5065
5272
|
};
|
|
5066
5273
|
}
|
|
5274
|
+
/** header.json is a snapshot; the stored CREATE_DOCUMENT input wins. */
|
|
5275
|
+
function pinProtocolVersionsToCreate(header, operations) {
|
|
5276
|
+
const create = operations.document?.find((operation) => operation.action.type === "CREATE_DOCUMENT");
|
|
5277
|
+
if (!create) return;
|
|
5278
|
+
const input = create.action.input;
|
|
5279
|
+
if (input?.protocolVersions) header.protocolVersions = { ...input.protocolVersions };
|
|
5280
|
+
else if (header.protocolVersions) {
|
|
5281
|
+
const { [SIGNATURE_PROTOCOL]: _dropped, ...rest } = header.protocolVersions;
|
|
5282
|
+
header.protocolVersions = rest;
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
/** A zip with no recorded base-reducer version predates it: replay as v1. */
|
|
5286
|
+
function backfillBaseReducerVersion(header) {
|
|
5287
|
+
if (typeof header.protocolVersions?.["base-reducer"] === "number") return;
|
|
5288
|
+
header.protocolVersions = {
|
|
5289
|
+
...header.protocolVersions,
|
|
5290
|
+
"base-reducer": 1
|
|
5291
|
+
};
|
|
5292
|
+
}
|
|
5067
5293
|
async function loadFromZipData(data, reducer, options) {
|
|
5068
5294
|
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
5069
5295
|
return {
|
|
@@ -5139,6 +5365,157 @@ const getFileBrowser = (file) => {
|
|
|
5139
5365
|
return Promise.resolve().then(() => readFileBrowser(file));
|
|
5140
5366
|
};
|
|
5141
5367
|
//#endregion
|
|
5142
|
-
|
|
5368
|
+
//#region document-model/peer-agreement.ts
|
|
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 };
|
|
5143
5520
|
|
|
5144
5521
|
//# sourceMappingURL=index.js.map
|