@powerhousedao/shared 6.2.0-dev.1 → 6.2.0-dev.11
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/{common-Dmf4BGPa.d.mts → common-BQ2pvhCr.d.mts} +3 -3
- package/dist/clis/args/{common-Dmf4BGPa.d.mts.map → common-BQ2pvhCr.d.mts.map} +1 -1
- package/dist/clis/args/common.d.mts +1 -1
- package/dist/clis/args/connect.d.mts +6 -0
- package/dist/clis/args/connect.d.mts.map +1 -1
- package/dist/clis/args/connect.mjs +6 -1
- package/dist/clis/args/connect.mjs.map +1 -1
- package/dist/clis/args/index.d.mts +2 -2
- package/dist/clis/args/service-C88bN_g_.d.mts +22 -0
- package/dist/clis/args/service-C88bN_g_.d.mts.map +1 -0
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/vetra.d.mts +3 -0
- package/dist/clis/args/vetra.d.mts.map +1 -1
- package/dist/clis/args/vetra.mjs +5 -0
- package/dist/clis/args/vetra.mjs.map +1 -1
- package/dist/clis/constants.d.mts +0 -85
- package/dist/clis/constants.d.mts.map +1 -1
- package/dist/clis/index.d.mts +9 -89
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +10 -4
- package/dist/clis/index.mjs.map +1 -1
- package/dist/connect/config-loader.d.ts +1 -1
- package/dist/connect/index.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-model/index.d.ts +3 -3
- package/dist/document-model/index.js +319 -19
- package/dist/document-model/index.js.map +1 -1
- package/dist/{index-DalC_-i7.d.ts → index-DLx4nU83.d.ts} +41 -3
- package/dist/index-DLx4nU83.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +4 -3
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +2 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +17 -0
- package/dist/registry/manifest-slim.d.ts.map +1 -0
- package/dist/registry/manifest-slim.js +57 -0
- package/dist/registry/manifest-slim.js.map +1 -0
- package/dist/types-Bo4Rb8Yf.d.ts +2492 -0
- package/dist/types-Bo4Rb8Yf.d.ts.map +1 -0
- package/dist/{types-CVqmv94G.d.ts → types-CgGSyOl6.d.ts} +2 -2
- package/dist/{types-CVqmv94G.d.ts.map → types-CgGSyOl6.d.ts.map} +1 -1
- package/dist/{types-Daq_zHP_.d.ts → types-Lj1TT2LW.d.ts} +1 -2
- package/dist/{types-Daq_zHP_.d.ts.map → types-Lj1TT2LW.d.ts.map} +1 -1
- package/package.json +2 -2
- package/dist/clis/args/service-DbbCQSks.d.mts +0 -106
- package/dist/clis/args/service-DbbCQSks.d.mts.map +0 -1
- package/dist/index-DalC_-i7.d.ts.map +0 -1
- package/dist/types-CC6ib3_2.d.ts +0 -21068
- package/dist/types-CC6ib3_2.d.ts.map +0 -1
|
@@ -24,6 +24,21 @@ var InvalidActionInputZodError = class extends InvalidActionInputError {
|
|
|
24
24
|
this.name = "InvalidActionInputZodError";
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when attempting to downgrade a document version.
|
|
29
|
+
*/
|
|
30
|
+
var DowngradeNotSupportedError = class extends Error {
|
|
31
|
+
documentType;
|
|
32
|
+
fromVersion;
|
|
33
|
+
toVersion;
|
|
34
|
+
constructor(documentType, fromVersion, toVersion) {
|
|
35
|
+
super(`Downgrade not supported for ${documentType}: cannot upgrade from version ${fromVersion} to ${toVersion}`);
|
|
36
|
+
this.name = "DowngradeNotSupportedError";
|
|
37
|
+
this.documentType = documentType;
|
|
38
|
+
this.fromVersion = fromVersion;
|
|
39
|
+
this.toVersion = toVersion;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
27
42
|
var HashMismatchError = class extends Error {
|
|
28
43
|
_scope;
|
|
29
44
|
_document;
|
|
@@ -73,15 +88,6 @@ function DocumentActionSchema() {
|
|
|
73
88
|
UndoActionSchema()
|
|
74
89
|
]);
|
|
75
90
|
}
|
|
76
|
-
function DocumentFileSchema() {
|
|
77
|
-
return z.object({
|
|
78
|
-
__typename: z.literal("DocumentFile").optional(),
|
|
79
|
-
data: z.string(),
|
|
80
|
-
extension: z.string().nullable(),
|
|
81
|
-
fileName: z.string().nullable(),
|
|
82
|
-
mimeType: z.string()
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
91
|
function LoadStateActionSchema() {
|
|
86
92
|
return z.object({
|
|
87
93
|
id: z.string(),
|
|
@@ -616,16 +622,16 @@ const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scop
|
|
|
616
622
|
*
|
|
617
623
|
* @param type - The type of the action.
|
|
618
624
|
* @param input - The input properties of the action.
|
|
619
|
-
* @param
|
|
625
|
+
* @param _attachments - Deprecated and ignored. Retained so action creators
|
|
626
|
+
* generated before the attachment-system removal keep their 5-argument shape.
|
|
620
627
|
* @param validator - The validator to use for the input properties.
|
|
621
628
|
* @param scope - The scope of the action, can either be 'global' or 'local'.
|
|
622
|
-
* @param skip - The number of operations to skip before this new action is applied.
|
|
623
629
|
*
|
|
624
630
|
* @throws Error if the type is empty or not a string.
|
|
625
631
|
*
|
|
626
632
|
* @returns The new action.
|
|
627
633
|
*/
|
|
628
|
-
function createAction(type, input,
|
|
634
|
+
function createAction(type, input, _attachments, validator, scope = "global") {
|
|
629
635
|
if (!type) throw new Error("Empty action type");
|
|
630
636
|
if (typeof type !== "string") throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
|
|
631
637
|
const action = {
|
|
@@ -635,7 +641,6 @@ function createAction(type, input, attachments, validator, scope = "global") {
|
|
|
635
641
|
input,
|
|
636
642
|
scope
|
|
637
643
|
};
|
|
638
|
-
if (attachments) action.attachments = attachments;
|
|
639
644
|
try {
|
|
640
645
|
validator?.().parse(action.input);
|
|
641
646
|
} catch (error) {
|
|
@@ -655,8 +660,7 @@ const actionFromAction = (action) => {
|
|
|
655
660
|
type: action.type,
|
|
656
661
|
input: action.input,
|
|
657
662
|
scope: action.scope,
|
|
658
|
-
context: action.context
|
|
659
|
-
attachments: action.attachments
|
|
663
|
+
context: action.context
|
|
660
664
|
};
|
|
661
665
|
};
|
|
662
666
|
const operationFromAction = (action, index, skip, context) => {
|
|
@@ -3408,6 +3412,284 @@ const documentModelStateReducer = (state, action) => {
|
|
|
3408
3412
|
};
|
|
3409
3413
|
const documentModelReducer = createReducer(documentModelStateReducer);
|
|
3410
3414
|
//#endregion
|
|
3415
|
+
//#region document-model/upgrades.ts
|
|
3416
|
+
function applyInitialState(document, action) {
|
|
3417
|
+
const input = action.input;
|
|
3418
|
+
const newState = input.initialState || input.state;
|
|
3419
|
+
if (newState) {
|
|
3420
|
+
document.state = {
|
|
3421
|
+
...document.state,
|
|
3422
|
+
...newState
|
|
3423
|
+
};
|
|
3424
|
+
document.initialState = document.state;
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
/**
|
|
3428
|
+
* Applies an UPGRADE_DOCUMENT action to a document.
|
|
3429
|
+
* Handles all upgrade scenarios including initial upgrades, no-ops, and multi-step upgrades.
|
|
3430
|
+
*
|
|
3431
|
+
* Behavior based on fromVersion/toVersion:
|
|
3432
|
+
* - fromVersion === toVersion (and fromVersion > 0): No-op - return unchanged document
|
|
3433
|
+
* - fromVersion > toVersion: Throw DowngradeNotSupportedError
|
|
3434
|
+
* - All other cases: Apply upgradePath transitions (if provided), then apply initialState, set version
|
|
3435
|
+
*/
|
|
3436
|
+
function applyUpgradeDocumentAction(document, action, upgradePath) {
|
|
3437
|
+
const fromVersion = action.input.fromVersion;
|
|
3438
|
+
const toVersion = action.input.toVersion;
|
|
3439
|
+
if (fromVersion === toVersion && fromVersion > 0) return document;
|
|
3440
|
+
if (fromVersion > toVersion) throw new DowngradeNotSupportedError(document.header.documentType, fromVersion, toVersion);
|
|
3441
|
+
if (upgradePath) for (const transition of upgradePath) document = transition.upgradeReducer(document, action);
|
|
3442
|
+
applyInitialState(document, action);
|
|
3443
|
+
document.state.document = {
|
|
3444
|
+
...document.state.document,
|
|
3445
|
+
version: toVersion
|
|
3446
|
+
};
|
|
3447
|
+
return document;
|
|
3448
|
+
}
|
|
3449
|
+
/**
|
|
3450
|
+
* Applies a DELETE_DOCUMENT action to a document.
|
|
3451
|
+
* Marks the document as deleted in the document scope state.
|
|
3452
|
+
*/
|
|
3453
|
+
function applyDeleteDocumentAction(document, action) {
|
|
3454
|
+
const deletedAt = action.timestampUtcMs || (/* @__PURE__ */ new Date()).toISOString();
|
|
3455
|
+
document.state = {
|
|
3456
|
+
...document.state,
|
|
3457
|
+
document: {
|
|
3458
|
+
...document.state.document,
|
|
3459
|
+
isDeleted: true,
|
|
3460
|
+
deletedAtUtcIso: deletedAt
|
|
3461
|
+
}
|
|
3462
|
+
};
|
|
3463
|
+
return document;
|
|
3464
|
+
}
|
|
3465
|
+
/**
|
|
3466
|
+
* Computes the ordered list of upgrade transitions needed to move from
|
|
3467
|
+
* fromVersion to toVersion using the provided manifest.
|
|
3468
|
+
* Walks keys v(fromVersion+1)..v(toVersion) and throws a descriptive Error
|
|
3469
|
+
* if the manifest is absent or any step is missing.
|
|
3470
|
+
*/
|
|
3471
|
+
function computeUpgradeTransitions(manifest, fromVersion, toVersion) {
|
|
3472
|
+
if (!manifest) throw new Error(`No upgrade manifest provided for transition from version ${fromVersion} to ${toVersion}`);
|
|
3473
|
+
const transitions = [];
|
|
3474
|
+
const upgrades = manifest.upgrades;
|
|
3475
|
+
for (let v = fromVersion + 1; v <= toVersion; v++) {
|
|
3476
|
+
const key = `v${v}`;
|
|
3477
|
+
const transition = upgrades[key];
|
|
3478
|
+
if (!transition) throw new Error(`Upgrade manifest for "${manifest.documentType}" is missing step "${key}" (from v${fromVersion} to v${toVersion}). Available keys: ${Object.keys(upgrades).join(", ")}`);
|
|
3479
|
+
transitions.push(transition);
|
|
3480
|
+
}
|
|
3481
|
+
return transitions;
|
|
3482
|
+
}
|
|
3483
|
+
//#endregion
|
|
3484
|
+
//#region document-model/versioned-replay.ts
|
|
3485
|
+
const NON_DOMAIN_SCOPES$1 = new Set(["auth", "document"]);
|
|
3486
|
+
function highestReducerVersion(reducers) {
|
|
3487
|
+
const keys = Object.keys(reducers).map(Number);
|
|
3488
|
+
if (keys.length === 0) throw new Error("VersionedReplayConfig.reducers must not be empty");
|
|
3489
|
+
return Math.max(...keys);
|
|
3490
|
+
}
|
|
3491
|
+
/**
|
|
3492
|
+
* Version-aware document replay. Replays a versioned document through per-version
|
|
3493
|
+
* reducers, applying upgrade transitions at segment boundaries.
|
|
3494
|
+
*
|
|
3495
|
+
* Algorithm (D5):
|
|
3496
|
+
* a. Build spine from operations["document"]. Empty spine or no upgrades → legacy fallback.
|
|
3497
|
+
* b. Collect UPGRADE_DOCUMENT ops from the spine.
|
|
3498
|
+
* c. Seed state from the creation upgrade (fromVersion===0). Missing seed with validated
|
|
3499
|
+
* upgrades throws; otherwise falls back to legacy.
|
|
3500
|
+
* d. Identify validated upgrades (fromVersion > 0, version increases). Compute per-scope
|
|
3501
|
+
* boundaries using revision snapshot (preferred) or timestamp fallback.
|
|
3502
|
+
* e. Loop over version segments, replaying each scope's ops through the matching reducer,
|
|
3503
|
+
* then applying the upgrade transition before the next segment.
|
|
3504
|
+
* f. Set header.revision["document"], verify per-scope hashes against state at op-time
|
|
3505
|
+
* (not post-upgrade state) when checkHashes is false, and map timestamps from input.
|
|
3506
|
+
*
|
|
3507
|
+
* operations must include ALL scopes (document scope is NOT stripped).
|
|
3508
|
+
* reuseOperationResultingState is ignored by this function — zip operations never carry
|
|
3509
|
+
* resultingState.
|
|
3510
|
+
*/
|
|
3511
|
+
function replayDocumentVersioned(initialState, operations, config, header, dispatch, options) {
|
|
3512
|
+
const { checkHashes = true, skipIndexValidation } = options || {};
|
|
3513
|
+
const protocolVersion = header.protocolVersions?.["base-reducer"] ?? 1;
|
|
3514
|
+
const spine = (operations["document"] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3515
|
+
const upgrades = spine.filter((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
3516
|
+
const legacyFallback = () => {
|
|
3517
|
+
const domainOps = Object.fromEntries(Object.entries(operations).filter(([s]) => !NON_DOMAIN_SCOPES$1.has(s)));
|
|
3518
|
+
const latestVersion = highestReducerVersion(config.reducers);
|
|
3519
|
+
const reducer = config.reducers[latestVersion];
|
|
3520
|
+
return {
|
|
3521
|
+
...replayDocument(initialState, domainOps, reducer, header, dispatch, {}, options),
|
|
3522
|
+
operations
|
|
3523
|
+
};
|
|
3524
|
+
};
|
|
3525
|
+
if (spine.length === 0 || upgrades.length === 0) return legacyFallback();
|
|
3526
|
+
const seedOp = upgrades[0];
|
|
3527
|
+
if (!seedOp) return legacyFallback();
|
|
3528
|
+
const seedAction = seedOp.action;
|
|
3529
|
+
if (seedAction.input.fromVersion !== 0) return legacyFallback();
|
|
3530
|
+
const seedInput = seedAction.input;
|
|
3531
|
+
const seedState = seedInput.initialState ?? seedInput.state;
|
|
3532
|
+
if (!seedState) {
|
|
3533
|
+
const validatedUpgradeCount = upgrades.filter((op) => {
|
|
3534
|
+
const a = op.action;
|
|
3535
|
+
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
3536
|
+
}).length;
|
|
3537
|
+
if (validatedUpgradeCount > 0) throw new Error(`Cannot reconstruct versioned history: the creation UPGRADE_DOCUMENT operation carries no initialState, but the document has ${validatedUpgradeCount} version-changing upgrade(s) recorded after creation. Pre-migration states cannot be reconstructed without the seeded initialState.`);
|
|
3538
|
+
return legacyFallback();
|
|
3539
|
+
}
|
|
3540
|
+
const startVersion = seedAction.input.toVersion;
|
|
3541
|
+
const validatedUpgrades = upgrades.filter((op) => {
|
|
3542
|
+
const a = op.action;
|
|
3543
|
+
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
3544
|
+
});
|
|
3545
|
+
const domainScopes = Object.keys(operations).filter((s) => !NON_DOMAIN_SCOPES$1.has(s));
|
|
3546
|
+
const scopeOps = {};
|
|
3547
|
+
for (const s of domainScopes) scopeOps[s] = (operations[s] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
3548
|
+
const boundaries = validatedUpgrades.map((upgradeOp) => {
|
|
3549
|
+
const revisionSnapshot = upgradeOp.action.input.revision;
|
|
3550
|
+
const upgradeTimestamp = upgradeOp.timestampUtcMs;
|
|
3551
|
+
const boundary = {};
|
|
3552
|
+
for (const s of domainScopes) {
|
|
3553
|
+
const ops = scopeOps[s] ?? [];
|
|
3554
|
+
if (revisionSnapshot !== void 0) {
|
|
3555
|
+
const rev = revisionSnapshot[s] ?? 0;
|
|
3556
|
+
let b = 0;
|
|
3557
|
+
for (let j = 0; j < ops.length; j++) if ((ops[j]?.index ?? 0) < rev) b = j + 1;
|
|
3558
|
+
boundary[s] = b;
|
|
3559
|
+
} else {
|
|
3560
|
+
let b = ops.length;
|
|
3561
|
+
for (let j = 0; j < ops.length; j++) if ((ops[j]?.timestampUtcMs ?? "") >= upgradeTimestamp) {
|
|
3562
|
+
b = j;
|
|
3563
|
+
break;
|
|
3564
|
+
}
|
|
3565
|
+
boundary[s] = b;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
return boundary;
|
|
3569
|
+
});
|
|
3570
|
+
for (let i = 1; i < boundaries.length; i++) for (const s of domainScopes) {
|
|
3571
|
+
const prev = boundaries[i - 1]?.[s] ?? 0;
|
|
3572
|
+
const curr = boundaries[i]?.[s] ?? 0;
|
|
3573
|
+
if (boundaries[i]) boundaries[i][s] = Math.max(prev, curr);
|
|
3574
|
+
}
|
|
3575
|
+
const allScopes = new Set([
|
|
3576
|
+
...Object.keys(operations),
|
|
3577
|
+
"global",
|
|
3578
|
+
"local"
|
|
3579
|
+
]);
|
|
3580
|
+
const initialOperations = {};
|
|
3581
|
+
for (const s of allScopes) initialOperations[s] = [];
|
|
3582
|
+
let document = {
|
|
3583
|
+
header,
|
|
3584
|
+
state: seedState,
|
|
3585
|
+
initialState: seedState,
|
|
3586
|
+
operations: initialOperations,
|
|
3587
|
+
clipboard: []
|
|
3588
|
+
};
|
|
3589
|
+
let currentVersion = startVersion;
|
|
3590
|
+
const segmentEndHashPerScope = /* @__PURE__ */ new Map();
|
|
3591
|
+
for (let k = 0; k <= validatedUpgrades.length; k++) {
|
|
3592
|
+
const reducer = config.reducers[currentVersion];
|
|
3593
|
+
if (!reducer) {
|
|
3594
|
+
const available = Object.keys(config.reducers).join(", ");
|
|
3595
|
+
throw new Error(`No reducer registered for document version ${currentVersion}. Available versions: ${available}`);
|
|
3596
|
+
}
|
|
3597
|
+
for (const s of domainScopes) {
|
|
3598
|
+
const ops = scopeOps[s] ?? [];
|
|
3599
|
+
const segStart = k === 0 ? 0 : boundaries[k - 1]?.[s] ?? 0;
|
|
3600
|
+
const segEnd = k < validatedUpgrades.length ? boundaries[k]?.[s] ?? ops.length : ops.length;
|
|
3601
|
+
const segOps = ops.slice(segStart, segEnd);
|
|
3602
|
+
for (const op of segOps) {
|
|
3603
|
+
document = reducer(document, op.action, dispatch, {
|
|
3604
|
+
ignoreSkipOperations: true,
|
|
3605
|
+
checkHashes,
|
|
3606
|
+
skipIndexValidation,
|
|
3607
|
+
replayOptions: { operation: op },
|
|
3608
|
+
protocolVersion
|
|
3609
|
+
});
|
|
3610
|
+
segmentEndHashPerScope.set(s, hashDocumentStateForScope(document, s));
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
const prevUpgradeSpineIdx = k === 0 ? -1 : spine.indexOf(validatedUpgrades[k - 1]);
|
|
3614
|
+
const nextUpgradeSpineIdx = k < validatedUpgrades.length ? spine.indexOf(validatedUpgrades[k]) : spine.length;
|
|
3615
|
+
for (let si = prevUpgradeSpineIdx + 1; si < nextUpgradeSpineIdx; si++) {
|
|
3616
|
+
const spineOp = spine[si];
|
|
3617
|
+
if (!spineOp) continue;
|
|
3618
|
+
const spineActionType = spineOp.action.type;
|
|
3619
|
+
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
3620
|
+
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
3621
|
+
else document = reducer(document, spineOp.action, dispatch, {
|
|
3622
|
+
ignoreSkipOperations: true,
|
|
3623
|
+
checkHashes,
|
|
3624
|
+
skipIndexValidation,
|
|
3625
|
+
replayOptions: { operation: spineOp },
|
|
3626
|
+
protocolVersion
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
if (k < validatedUpgrades.length) {
|
|
3630
|
+
const upgradeAction = validatedUpgrades[k].action;
|
|
3631
|
+
const fromVer = upgradeAction.input.fromVersion;
|
|
3632
|
+
const toVer = upgradeAction.input.toVersion;
|
|
3633
|
+
const transitions = computeUpgradeTransitions(config.upgradeManifest, fromVer, toVer);
|
|
3634
|
+
document = applyUpgradeDocumentAction(document, upgradeAction, transitions);
|
|
3635
|
+
currentVersion = toVer;
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
const lastSpineOp = spine.at(-1);
|
|
3639
|
+
if (lastSpineOp !== void 0 && validatedUpgrades.length > 0) document = {
|
|
3640
|
+
...document,
|
|
3641
|
+
header: {
|
|
3642
|
+
...document.header,
|
|
3643
|
+
revision: {
|
|
3644
|
+
...document.header.revision,
|
|
3645
|
+
document: lastSpineOp.index + 1
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
};
|
|
3649
|
+
if (!checkHashes) {
|
|
3650
|
+
const allReplayedOps = domainScopes.flatMap((s) => scopeOps[s] ?? []);
|
|
3651
|
+
for (const scope of Object.keys(document.state)) {
|
|
3652
|
+
const capturedHash = segmentEndHashPerScope.get(scope);
|
|
3653
|
+
const scopeHash = capturedHash !== void 0 ? capturedHash : hashDocumentStateForScope(document, scope);
|
|
3654
|
+
for (let i = allReplayedOps.length - 1; i >= 0; i--) {
|
|
3655
|
+
const operation = allReplayedOps[i];
|
|
3656
|
+
if (!operation || operation.action.scope !== scope) continue;
|
|
3657
|
+
if (operation.hash !== scopeHash) throw new HashMismatchError(scope, document, operation);
|
|
3658
|
+
else break;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
const allResultScopes = new Set([
|
|
3663
|
+
...Object.keys(document.operations),
|
|
3664
|
+
...Object.keys(operations),
|
|
3665
|
+
"global",
|
|
3666
|
+
"local"
|
|
3667
|
+
]);
|
|
3668
|
+
allResultScopes.delete("document");
|
|
3669
|
+
const resultOperations = {};
|
|
3670
|
+
for (const s of allResultScopes) resultOperations[s] = (document.operations[s] ?? []).map((op, index) => ({
|
|
3671
|
+
...op,
|
|
3672
|
+
timestamp: operations[s]?.[index]?.timestampUtcMs ?? op.timestampUtcMs
|
|
3673
|
+
}));
|
|
3674
|
+
const lastModified = header.lastModifiedAtUtcIso ? header.lastModifiedAtUtcIso : Object.values(resultOperations).reduce((acc, curr) => {
|
|
3675
|
+
if (!curr) return acc;
|
|
3676
|
+
const last = curr.at(-1);
|
|
3677
|
+
if (last && last.timestampUtcMs > acc) return last.timestampUtcMs;
|
|
3678
|
+
return acc;
|
|
3679
|
+
}, document.header.lastModifiedAtUtcIso);
|
|
3680
|
+
return {
|
|
3681
|
+
...document,
|
|
3682
|
+
header: {
|
|
3683
|
+
...document.header,
|
|
3684
|
+
lastModifiedAtUtcIso: lastModified
|
|
3685
|
+
},
|
|
3686
|
+
operations: {
|
|
3687
|
+
...operations,
|
|
3688
|
+
...resultOperations
|
|
3689
|
+
}
|
|
3690
|
+
};
|
|
3691
|
+
}
|
|
3692
|
+
//#endregion
|
|
3411
3693
|
//#region document-model/files.ts
|
|
3412
3694
|
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
3413
3695
|
function zipAsync(data) {
|
|
@@ -3494,7 +3776,7 @@ function readEntry(files, name) {
|
|
|
3494
3776
|
if (!entry) throw new Error(`${name} not found in document zip`);
|
|
3495
3777
|
return strFromU8(entry);
|
|
3496
3778
|
}
|
|
3497
|
-
async function
|
|
3779
|
+
async function parseZipData(data) {
|
|
3498
3780
|
const files = await unzipAsync(data);
|
|
3499
3781
|
if (!files["state.json"]) throw new Error("Initial state not found");
|
|
3500
3782
|
const initialState = JSON.parse(readEntry(files, "state.json"));
|
|
@@ -3507,14 +3789,32 @@ async function loadFromZipData(data, reducer, options) {
|
|
|
3507
3789
|
const errorMessages = operationsError.map((err) => err.message);
|
|
3508
3790
|
throw new Error(errorMessages.join("\n"));
|
|
3509
3791
|
}
|
|
3792
|
+
return {
|
|
3793
|
+
initialState,
|
|
3794
|
+
header,
|
|
3795
|
+
clearedOperations
|
|
3796
|
+
};
|
|
3797
|
+
}
|
|
3798
|
+
async function loadFromZipData(data, reducer, options) {
|
|
3799
|
+
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
3510
3800
|
return {
|
|
3511
3801
|
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope))), reducer, header, void 0, {}, options),
|
|
3512
3802
|
operations: clearedOperations
|
|
3513
3803
|
};
|
|
3514
3804
|
}
|
|
3805
|
+
async function loadFromZipDataVersioned(data, config, options) {
|
|
3806
|
+
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
3807
|
+
return {
|
|
3808
|
+
...replayDocumentVersioned(initialState, clearedOperations, config, header, void 0, options),
|
|
3809
|
+
operations: clearedOperations
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3515
3812
|
async function baseLoadFromInput(input, reducer, options) {
|
|
3516
3813
|
return loadFromZipData(await toUint8Array(input), reducer, options);
|
|
3517
3814
|
}
|
|
3815
|
+
async function baseLoadFromInputVersioned(input, config, options) {
|
|
3816
|
+
return loadFromZipDataVersioned(await toUint8Array(input), config, options);
|
|
3817
|
+
}
|
|
3518
3818
|
const documentModelLoadFromInput = (input) => {
|
|
3519
3819
|
return baseLoadFromInput(input, documentModelReducer);
|
|
3520
3820
|
};
|
|
@@ -3530,8 +3830,8 @@ function readFileBrowser(path) {
|
|
|
3530
3830
|
function fetchFileBrowser(url) {
|
|
3531
3831
|
throw FileSystemError;
|
|
3532
3832
|
}
|
|
3533
|
-
const getFileBrowser =
|
|
3534
|
-
return readFileBrowser(file);
|
|
3833
|
+
const getFileBrowser = (file) => {
|
|
3834
|
+
return Promise.resolve().then(() => readFileBrowser(file));
|
|
3535
3835
|
};
|
|
3536
3836
|
//#endregion
|
|
3537
3837
|
//#region document-model/state.ts
|
|
@@ -3633,6 +3933,6 @@ function createState(baseState, globalState, localState) {
|
|
|
3633
3933
|
};
|
|
3634
3934
|
}
|
|
3635
3935
|
//#endregion
|
|
3636
|
-
export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema,
|
|
3936
|
+
export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, DowngradeNotSupportedError, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, 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, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, applyDeleteDocumentAction, applyUpgradeDocumentAction, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseLoadFromInputVersioned, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, computeUpgradeTransitions, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayDocumentVersioned, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
3637
3937
|
|
|
3638
3938
|
//# sourceMappingURL=index.js.map
|