@powerhousedao/powerhouse-vetra-packages 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/browser/assets/{entry-Bzani6_n.js → entry-D6VwthNk.js} +2 -2
- package/dist/browser/assets/{projection-entry-Bpu-8SnI.js → projection-entry-CemvPRT8.js} +2 -2
- package/dist/browser/{connect-ZnLjvmRt.js → connect-BMrgEG7X.js} +4 -4
- package/dist/browser/{connect-ZnLjvmRt.js.map → connect-BMrgEG7X.js.map} +1 -1
- package/dist/browser/{dist-C1nRM9t2.js → dist-B6zWOl4d.js} +44 -30
- package/dist/browser/dist-B6zWOl4d.js.map +1 -0
- package/dist/browser/{dist-DLFI75Zd.js → dist-DPeHVSov.js} +3 -3
- package/dist/browser/dist-DPeHVSov.js.map +1 -0
- package/dist/browser/{document-drive-oqv68jDU.js → document-drive-sTKoi6L4.js} +314 -9
- package/dist/browser/document-drive-sTKoi6L4.js.map +1 -0
- package/dist/browser/document-models/index.js +1 -1
- package/dist/browser/{editor-CoTq6fqT.js → editor-Clp9-uJE.js} +6 -6
- package/dist/browser/{editor-CoTq6fqT.js.map → editor-Clp9-uJE.js.map} +1 -1
- package/dist/browser/{editor-DC3bigBu.js → editor-CzsQw1pE.js} +5 -5
- package/dist/browser/{editor-DC3bigBu.js.map → editor-CzsQw1pE.js.map} +1 -1
- package/dist/browser/editors/document-model-editor/module.js +1 -1
- package/dist/browser/editors/generic-drive-explorer/index.js +4 -4
- package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
- package/dist/browser/{folder-view-DmYBf2pP.js → folder-view-D9jBl4kJ.js} +3 -3
- package/dist/browser/{folder-view-DmYBf2pP.js.map → folder-view-D9jBl4kJ.js.map} +1 -1
- package/dist/browser/{graphql-editor-CiGd_Li7.js → graphql-editor-8bWqxqUN.js} +3 -3
- package/dist/browser/{graphql-editor-CiGd_Li7.js.map → graphql-editor-8bWqxqUN.js.map} +1 -1
- package/dist/browser/index.js +2 -2
- package/dist/browser/{json-editor-sEqd5piI.js → json-editor-DlvyzQQO.js} +3 -3
- package/dist/browser/{json-editor-sEqd5piI.js.map → json-editor-DlvyzQQO.js.map} +1 -1
- package/dist/browser/{state-schemas-DJmzG_M8.js → state-schemas-CVQyYhpH.js} +3 -3
- package/dist/browser/{state-schemas-DJmzG_M8.js.map → state-schemas-CVQyYhpH.js.map} +1 -1
- package/dist/node/{connect-BLC4PXD9.mjs → connect-C8Ur6M5x.mjs} +4 -4
- package/dist/node/{connect-BLC4PXD9.mjs.map → connect-C8Ur6M5x.mjs.map} +1 -1
- package/dist/node/{dist-Bm05eoTg.mjs → dist-D3qXr1ES.mjs} +44 -30
- package/dist/node/dist-D3qXr1ES.mjs.map +1 -0
- package/dist/node/{dist-Cn3iExnV.mjs → dist-vA9scgbK.mjs} +3 -3
- package/dist/node/dist-vA9scgbK.mjs.map +1 -0
- package/dist/node/{document-drive-sM33juXr.mjs → document-drive-DjL9iikf.mjs} +314 -9
- package/dist/node/document-drive-DjL9iikf.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +1 -1
- package/dist/node/{editor-BrS98lEH.mjs → editor-B6gn6QpO.mjs} +5 -5
- package/dist/node/{editor-BrS98lEH.mjs.map → editor-B6gn6QpO.mjs.map} +1 -1
- package/dist/node/{editor-BFBa9nsO.mjs → editor-kdobbTut.mjs} +6 -6
- package/dist/node/{editor-BFBa9nsO.mjs.map → editor-kdobbTut.mjs.map} +1 -1
- package/dist/node/editors/document-model-editor/module.mjs +1 -1
- package/dist/node/editors/generic-drive-explorer/index.mjs +4 -4
- package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
- package/dist/node/{folder-view-DHph3Yuu.mjs → folder-view-C9m-Kbjh.mjs} +3 -3
- package/dist/node/{folder-view-DHph3Yuu.mjs.map → folder-view-C9m-Kbjh.mjs.map} +1 -1
- package/dist/node/{graphql-editor-CPq7oIbf.mjs → graphql-editor-BiK6s8_B.mjs} +3 -3
- package/dist/node/{graphql-editor-CPq7oIbf.mjs.map → graphql-editor-BiK6s8_B.mjs.map} +1 -1
- package/dist/node/index.mjs +2 -2
- package/dist/node/{json-editor-L32CP7TS.mjs → json-editor-rMZOlQFM.mjs} +3 -3
- package/dist/node/{json-editor-L32CP7TS.mjs.map → json-editor-rMZOlQFM.mjs.map} +1 -1
- package/dist/node/{state-schemas-XTTjQZOe.mjs → state-schemas-Dt2-S4R8.mjs} +3 -3
- package/dist/node/{state-schemas-XTTjQZOe.mjs.map → state-schemas-Dt2-S4R8.mjs.map} +1 -1
- package/package.json +6 -6
- package/dist/browser/dist-C1nRM9t2.js.map +0 -1
- package/dist/browser/dist-DLFI75Zd.js.map +0 -1
- package/dist/browser/document-drive-oqv68jDU.js.map +0 -1
- package/dist/node/dist-Bm05eoTg.mjs.map +0 -1
- package/dist/node/dist-Cn3iExnV.mjs.map +0 -1
- package/dist/node/document-drive-sM33juXr.mjs.map +0 -1
|
@@ -2980,6 +2980,21 @@ var InvalidActionInputZodError = class extends InvalidActionInputError {
|
|
|
2980
2980
|
this.name = "InvalidActionInputZodError";
|
|
2981
2981
|
}
|
|
2982
2982
|
};
|
|
2983
|
+
/**
|
|
2984
|
+
* Error thrown when attempting to downgrade a document version.
|
|
2985
|
+
*/
|
|
2986
|
+
var DowngradeNotSupportedError = class extends Error {
|
|
2987
|
+
documentType;
|
|
2988
|
+
fromVersion;
|
|
2989
|
+
toVersion;
|
|
2990
|
+
constructor(documentType, fromVersion, toVersion) {
|
|
2991
|
+
super(`Downgrade not supported for ${documentType}: cannot upgrade from version ${fromVersion} to ${toVersion}`);
|
|
2992
|
+
this.name = "DowngradeNotSupportedError";
|
|
2993
|
+
this.documentType = documentType;
|
|
2994
|
+
this.fromVersion = fromVersion;
|
|
2995
|
+
this.toVersion = toVersion;
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2983
2998
|
var HashMismatchError = class extends Error {
|
|
2984
2999
|
_scope;
|
|
2985
3000
|
_document;
|
|
@@ -3513,16 +3528,16 @@ const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scop
|
|
|
3513
3528
|
*
|
|
3514
3529
|
* @param type - The type of the action.
|
|
3515
3530
|
* @param input - The input properties of the action.
|
|
3516
|
-
* @param
|
|
3531
|
+
* @param _attachments - Deprecated and ignored. Retained so action creators
|
|
3532
|
+
* generated before the attachment-system removal keep their 5-argument shape.
|
|
3517
3533
|
* @param validator - The validator to use for the input properties.
|
|
3518
3534
|
* @param scope - The scope of the action, can either be 'global' or 'local'.
|
|
3519
|
-
* @param skip - The number of operations to skip before this new action is applied.
|
|
3520
3535
|
*
|
|
3521
3536
|
* @throws Error if the type is empty or not a string.
|
|
3522
3537
|
*
|
|
3523
3538
|
* @returns The new action.
|
|
3524
3539
|
*/
|
|
3525
|
-
function createAction(type, input,
|
|
3540
|
+
function createAction(type, input, _attachments, validator, scope = "global") {
|
|
3526
3541
|
if (!type) throw new Error("Empty action type");
|
|
3527
3542
|
if (typeof type !== "string") throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
|
|
3528
3543
|
const action = {
|
|
@@ -3532,7 +3547,6 @@ function createAction(type, input, attachments, validator, scope = "global") {
|
|
|
3532
3547
|
input,
|
|
3533
3548
|
scope
|
|
3534
3549
|
};
|
|
3535
|
-
if (attachments) action.attachments = attachments;
|
|
3536
3550
|
try {
|
|
3537
3551
|
validator?.().parse(action.input);
|
|
3538
3552
|
} catch (error) {
|
|
@@ -3552,8 +3566,7 @@ const actionFromAction = (action) => {
|
|
|
3552
3566
|
type: action.type,
|
|
3553
3567
|
input: action.input,
|
|
3554
3568
|
scope: action.scope,
|
|
3555
|
-
context: action.context
|
|
3556
|
-
attachments: action.attachments
|
|
3569
|
+
context: action.context
|
|
3557
3570
|
};
|
|
3558
3571
|
};
|
|
3559
3572
|
const operationFromAction = (action, index, skip, context) => {
|
|
@@ -5820,6 +5833,280 @@ const documentModelStateReducer = (state, action) => {
|
|
|
5820
5833
|
}
|
|
5821
5834
|
};
|
|
5822
5835
|
const documentModelReducer = createReducer(documentModelStateReducer);
|
|
5836
|
+
function applyInitialState(document, action) {
|
|
5837
|
+
const input = action.input;
|
|
5838
|
+
const newState = input.initialState || input.state;
|
|
5839
|
+
if (newState) {
|
|
5840
|
+
document.state = {
|
|
5841
|
+
...document.state,
|
|
5842
|
+
...newState
|
|
5843
|
+
};
|
|
5844
|
+
document.initialState = document.state;
|
|
5845
|
+
}
|
|
5846
|
+
}
|
|
5847
|
+
/**
|
|
5848
|
+
* Applies an UPGRADE_DOCUMENT action to a document.
|
|
5849
|
+
* Handles all upgrade scenarios including initial upgrades, no-ops, and multi-step upgrades.
|
|
5850
|
+
*
|
|
5851
|
+
* Behavior based on fromVersion/toVersion:
|
|
5852
|
+
* - fromVersion === toVersion (and fromVersion > 0): No-op - return unchanged document
|
|
5853
|
+
* - fromVersion > toVersion: Throw DowngradeNotSupportedError
|
|
5854
|
+
* - All other cases: Apply upgradePath transitions (if provided), then apply initialState, set version
|
|
5855
|
+
*/
|
|
5856
|
+
function applyUpgradeDocumentAction(document, action, upgradePath) {
|
|
5857
|
+
const fromVersion = action.input.fromVersion;
|
|
5858
|
+
const toVersion = action.input.toVersion;
|
|
5859
|
+
if (fromVersion === toVersion && fromVersion > 0) return document;
|
|
5860
|
+
if (fromVersion > toVersion) throw new DowngradeNotSupportedError(document.header.documentType, fromVersion, toVersion);
|
|
5861
|
+
if (upgradePath) for (const transition of upgradePath) document = transition.upgradeReducer(document, action);
|
|
5862
|
+
applyInitialState(document, action);
|
|
5863
|
+
document.state.document = {
|
|
5864
|
+
...document.state.document,
|
|
5865
|
+
version: toVersion
|
|
5866
|
+
};
|
|
5867
|
+
return document;
|
|
5868
|
+
}
|
|
5869
|
+
/**
|
|
5870
|
+
* Applies a DELETE_DOCUMENT action to a document.
|
|
5871
|
+
* Marks the document as deleted in the document scope state.
|
|
5872
|
+
*/
|
|
5873
|
+
function applyDeleteDocumentAction(document, action) {
|
|
5874
|
+
const deletedAt = action.timestampUtcMs || (/* @__PURE__ */ new Date()).toISOString();
|
|
5875
|
+
document.state = {
|
|
5876
|
+
...document.state,
|
|
5877
|
+
document: {
|
|
5878
|
+
...document.state.document,
|
|
5879
|
+
isDeleted: true,
|
|
5880
|
+
deletedAtUtcIso: deletedAt
|
|
5881
|
+
}
|
|
5882
|
+
};
|
|
5883
|
+
return document;
|
|
5884
|
+
}
|
|
5885
|
+
/**
|
|
5886
|
+
* Computes the ordered list of upgrade transitions needed to move from
|
|
5887
|
+
* fromVersion to toVersion using the provided manifest.
|
|
5888
|
+
* Walks keys v(fromVersion+1)..v(toVersion) and throws a descriptive Error
|
|
5889
|
+
* if the manifest is absent or any step is missing.
|
|
5890
|
+
*/
|
|
5891
|
+
function computeUpgradeTransitions(manifest, fromVersion, toVersion) {
|
|
5892
|
+
if (!manifest) throw new Error(`No upgrade manifest provided for transition from version ${fromVersion} to ${toVersion}`);
|
|
5893
|
+
const transitions = [];
|
|
5894
|
+
const upgrades = manifest.upgrades;
|
|
5895
|
+
for (let v = fromVersion + 1; v <= toVersion; v++) {
|
|
5896
|
+
const key = `v${v}`;
|
|
5897
|
+
const transition = upgrades[key];
|
|
5898
|
+
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(", ")}`);
|
|
5899
|
+
transitions.push(transition);
|
|
5900
|
+
}
|
|
5901
|
+
return transitions;
|
|
5902
|
+
}
|
|
5903
|
+
const NON_DOMAIN_SCOPES$1 = new Set(["auth", "document"]);
|
|
5904
|
+
function highestReducerVersion(reducers) {
|
|
5905
|
+
const keys = Object.keys(reducers).map(Number);
|
|
5906
|
+
if (keys.length === 0) throw new Error("VersionedReplayConfig.reducers must not be empty");
|
|
5907
|
+
return Math.max(...keys);
|
|
5908
|
+
}
|
|
5909
|
+
/**
|
|
5910
|
+
* Version-aware document replay. Replays a versioned document through per-version
|
|
5911
|
+
* reducers, applying upgrade transitions at segment boundaries.
|
|
5912
|
+
*
|
|
5913
|
+
* Algorithm (D5):
|
|
5914
|
+
* a. Build spine from operations["document"]. Empty spine or no upgrades → legacy fallback.
|
|
5915
|
+
* b. Collect UPGRADE_DOCUMENT ops from the spine.
|
|
5916
|
+
* c. Seed state from the creation upgrade (fromVersion===0). Missing seed with validated
|
|
5917
|
+
* upgrades throws; otherwise falls back to legacy.
|
|
5918
|
+
* d. Identify validated upgrades (fromVersion > 0, version increases). Compute per-scope
|
|
5919
|
+
* boundaries using revision snapshot (preferred) or timestamp fallback.
|
|
5920
|
+
* e. Loop over version segments, replaying each scope's ops through the matching reducer,
|
|
5921
|
+
* then applying the upgrade transition before the next segment.
|
|
5922
|
+
* f. Set header.revision["document"], verify per-scope hashes against state at op-time
|
|
5923
|
+
* (not post-upgrade state) when checkHashes is false, and map timestamps from input.
|
|
5924
|
+
*
|
|
5925
|
+
* operations must include ALL scopes (document scope is NOT stripped).
|
|
5926
|
+
* reuseOperationResultingState is ignored by this function — zip operations never carry
|
|
5927
|
+
* resultingState.
|
|
5928
|
+
*/
|
|
5929
|
+
function replayDocumentVersioned(initialState, operations, config, header, dispatch, options) {
|
|
5930
|
+
const { checkHashes = true, skipIndexValidation } = options || {};
|
|
5931
|
+
const protocolVersion = header.protocolVersions?.["base-reducer"] ?? 1;
|
|
5932
|
+
const spine = (operations["document"] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
5933
|
+
const upgrades = spine.filter((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
5934
|
+
const legacyFallback = () => {
|
|
5935
|
+
const domainOps = Object.fromEntries(Object.entries(operations).filter(([s]) => !NON_DOMAIN_SCOPES$1.has(s)));
|
|
5936
|
+
const latestVersion = highestReducerVersion(config.reducers);
|
|
5937
|
+
const reducer = config.reducers[latestVersion];
|
|
5938
|
+
return {
|
|
5939
|
+
...replayDocument(initialState, domainOps, reducer, header, dispatch, {}, options),
|
|
5940
|
+
operations
|
|
5941
|
+
};
|
|
5942
|
+
};
|
|
5943
|
+
if (spine.length === 0 || upgrades.length === 0) return legacyFallback();
|
|
5944
|
+
const seedOp = upgrades[0];
|
|
5945
|
+
if (!seedOp) return legacyFallback();
|
|
5946
|
+
const seedAction = seedOp.action;
|
|
5947
|
+
if (seedAction.input.fromVersion !== 0) return legacyFallback();
|
|
5948
|
+
const seedInput = seedAction.input;
|
|
5949
|
+
const seedState = seedInput.initialState ?? seedInput.state;
|
|
5950
|
+
if (!seedState) {
|
|
5951
|
+
const validatedUpgradeCount = upgrades.filter((op) => {
|
|
5952
|
+
const a = op.action;
|
|
5953
|
+
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
5954
|
+
}).length;
|
|
5955
|
+
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.`);
|
|
5956
|
+
return legacyFallback();
|
|
5957
|
+
}
|
|
5958
|
+
const startVersion = seedAction.input.toVersion;
|
|
5959
|
+
const validatedUpgrades = upgrades.filter((op) => {
|
|
5960
|
+
const a = op.action;
|
|
5961
|
+
return a.input.fromVersion > 0 && a.input.fromVersion < a.input.toVersion;
|
|
5962
|
+
});
|
|
5963
|
+
const domainScopes = Object.keys(operations).filter((s) => !NON_DOMAIN_SCOPES$1.has(s));
|
|
5964
|
+
const scopeOps = {};
|
|
5965
|
+
for (const s of domainScopes) scopeOps[s] = (operations[s] ?? []).slice().sort((a, b) => a.index - b.index);
|
|
5966
|
+
const boundaries = validatedUpgrades.map((upgradeOp) => {
|
|
5967
|
+
const revisionSnapshot = upgradeOp.action.input.revision;
|
|
5968
|
+
const upgradeTimestamp = upgradeOp.timestampUtcMs;
|
|
5969
|
+
const boundary = {};
|
|
5970
|
+
for (const s of domainScopes) {
|
|
5971
|
+
const ops = scopeOps[s] ?? [];
|
|
5972
|
+
if (revisionSnapshot !== void 0) {
|
|
5973
|
+
const rev = revisionSnapshot[s] ?? 0;
|
|
5974
|
+
let b = 0;
|
|
5975
|
+
for (let j = 0; j < ops.length; j++) if ((ops[j]?.index ?? 0) < rev) b = j + 1;
|
|
5976
|
+
boundary[s] = b;
|
|
5977
|
+
} else {
|
|
5978
|
+
let b = ops.length;
|
|
5979
|
+
for (let j = 0; j < ops.length; j++) if ((ops[j]?.timestampUtcMs ?? "") >= upgradeTimestamp) {
|
|
5980
|
+
b = j;
|
|
5981
|
+
break;
|
|
5982
|
+
}
|
|
5983
|
+
boundary[s] = b;
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
return boundary;
|
|
5987
|
+
});
|
|
5988
|
+
for (let i = 1; i < boundaries.length; i++) for (const s of domainScopes) {
|
|
5989
|
+
const prev = boundaries[i - 1]?.[s] ?? 0;
|
|
5990
|
+
const curr = boundaries[i]?.[s] ?? 0;
|
|
5991
|
+
if (boundaries[i]) boundaries[i][s] = Math.max(prev, curr);
|
|
5992
|
+
}
|
|
5993
|
+
const allScopes = new Set([
|
|
5994
|
+
...Object.keys(operations),
|
|
5995
|
+
"global",
|
|
5996
|
+
"local"
|
|
5997
|
+
]);
|
|
5998
|
+
const initialOperations = {};
|
|
5999
|
+
for (const s of allScopes) initialOperations[s] = [];
|
|
6000
|
+
let document = {
|
|
6001
|
+
header,
|
|
6002
|
+
state: seedState,
|
|
6003
|
+
initialState: seedState,
|
|
6004
|
+
operations: initialOperations,
|
|
6005
|
+
clipboard: []
|
|
6006
|
+
};
|
|
6007
|
+
let currentVersion = startVersion;
|
|
6008
|
+
const segmentEndHashPerScope = /* @__PURE__ */ new Map();
|
|
6009
|
+
for (let k = 0; k <= validatedUpgrades.length; k++) {
|
|
6010
|
+
const reducer = config.reducers[currentVersion];
|
|
6011
|
+
if (!reducer) {
|
|
6012
|
+
const available = Object.keys(config.reducers).join(", ");
|
|
6013
|
+
throw new Error(`No reducer registered for document version ${currentVersion}. Available versions: ${available}`);
|
|
6014
|
+
}
|
|
6015
|
+
for (const s of domainScopes) {
|
|
6016
|
+
const ops = scopeOps[s] ?? [];
|
|
6017
|
+
const segStart = k === 0 ? 0 : boundaries[k - 1]?.[s] ?? 0;
|
|
6018
|
+
const segEnd = k < validatedUpgrades.length ? boundaries[k]?.[s] ?? ops.length : ops.length;
|
|
6019
|
+
const segOps = ops.slice(segStart, segEnd);
|
|
6020
|
+
for (const op of segOps) {
|
|
6021
|
+
document = reducer(document, op.action, dispatch, {
|
|
6022
|
+
ignoreSkipOperations: true,
|
|
6023
|
+
checkHashes,
|
|
6024
|
+
skipIndexValidation,
|
|
6025
|
+
replayOptions: { operation: op },
|
|
6026
|
+
protocolVersion
|
|
6027
|
+
});
|
|
6028
|
+
segmentEndHashPerScope.set(s, hashDocumentStateForScope(document, s));
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
const prevUpgradeSpineIdx = k === 0 ? -1 : spine.indexOf(validatedUpgrades[k - 1]);
|
|
6032
|
+
const nextUpgradeSpineIdx = k < validatedUpgrades.length ? spine.indexOf(validatedUpgrades[k]) : spine.length;
|
|
6033
|
+
for (let si = prevUpgradeSpineIdx + 1; si < nextUpgradeSpineIdx; si++) {
|
|
6034
|
+
const spineOp = spine[si];
|
|
6035
|
+
if (!spineOp) continue;
|
|
6036
|
+
const spineActionType = spineOp.action.type;
|
|
6037
|
+
if (spineActionType === "CREATE_DOCUMENT" || spineActionType === "UPGRADE_DOCUMENT") continue;
|
|
6038
|
+
if (spineActionType === "DELETE_DOCUMENT") document = applyDeleteDocumentAction(document, spineOp.action);
|
|
6039
|
+
else document = reducer(document, spineOp.action, dispatch, {
|
|
6040
|
+
ignoreSkipOperations: true,
|
|
6041
|
+
checkHashes,
|
|
6042
|
+
skipIndexValidation,
|
|
6043
|
+
replayOptions: { operation: spineOp },
|
|
6044
|
+
protocolVersion
|
|
6045
|
+
});
|
|
6046
|
+
}
|
|
6047
|
+
if (k < validatedUpgrades.length) {
|
|
6048
|
+
const upgradeAction = validatedUpgrades[k].action;
|
|
6049
|
+
const fromVer = upgradeAction.input.fromVersion;
|
|
6050
|
+
const toVer = upgradeAction.input.toVersion;
|
|
6051
|
+
const transitions = computeUpgradeTransitions(config.upgradeManifest, fromVer, toVer);
|
|
6052
|
+
document = applyUpgradeDocumentAction(document, upgradeAction, transitions);
|
|
6053
|
+
currentVersion = toVer;
|
|
6054
|
+
}
|
|
6055
|
+
}
|
|
6056
|
+
const lastSpineOp = spine.at(-1);
|
|
6057
|
+
if (lastSpineOp !== void 0 && validatedUpgrades.length > 0) document = {
|
|
6058
|
+
...document,
|
|
6059
|
+
header: {
|
|
6060
|
+
...document.header,
|
|
6061
|
+
revision: {
|
|
6062
|
+
...document.header.revision,
|
|
6063
|
+
document: lastSpineOp.index + 1
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
};
|
|
6067
|
+
if (!checkHashes) {
|
|
6068
|
+
const allReplayedOps = domainScopes.flatMap((s) => scopeOps[s] ?? []);
|
|
6069
|
+
for (const scope of Object.keys(document.state)) {
|
|
6070
|
+
const capturedHash = segmentEndHashPerScope.get(scope);
|
|
6071
|
+
const scopeHash = capturedHash !== void 0 ? capturedHash : hashDocumentStateForScope(document, scope);
|
|
6072
|
+
for (let i = allReplayedOps.length - 1; i >= 0; i--) {
|
|
6073
|
+
const operation = allReplayedOps[i];
|
|
6074
|
+
if (!operation || operation.action.scope !== scope) continue;
|
|
6075
|
+
if (operation.hash !== scopeHash) throw new HashMismatchError(scope, document, operation);
|
|
6076
|
+
else break;
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
const allResultScopes = new Set([
|
|
6081
|
+
...Object.keys(document.operations),
|
|
6082
|
+
...Object.keys(operations),
|
|
6083
|
+
"global",
|
|
6084
|
+
"local"
|
|
6085
|
+
]);
|
|
6086
|
+
allResultScopes.delete("document");
|
|
6087
|
+
const resultOperations = {};
|
|
6088
|
+
for (const s of allResultScopes) resultOperations[s] = (document.operations[s] ?? []).map((op, index) => ({
|
|
6089
|
+
...op,
|
|
6090
|
+
timestamp: operations[s]?.[index]?.timestampUtcMs ?? op.timestampUtcMs
|
|
6091
|
+
}));
|
|
6092
|
+
const lastModified = header.lastModifiedAtUtcIso ? header.lastModifiedAtUtcIso : Object.values(resultOperations).reduce((acc, curr) => {
|
|
6093
|
+
if (!curr) return acc;
|
|
6094
|
+
const last = curr.at(-1);
|
|
6095
|
+
if (last && last.timestampUtcMs > acc) return last.timestampUtcMs;
|
|
6096
|
+
return acc;
|
|
6097
|
+
}, document.header.lastModifiedAtUtcIso);
|
|
6098
|
+
return {
|
|
6099
|
+
...document,
|
|
6100
|
+
header: {
|
|
6101
|
+
...document.header,
|
|
6102
|
+
lastModifiedAtUtcIso: lastModified
|
|
6103
|
+
},
|
|
6104
|
+
operations: {
|
|
6105
|
+
...operations,
|
|
6106
|
+
...resultOperations
|
|
6107
|
+
}
|
|
6108
|
+
};
|
|
6109
|
+
}
|
|
5823
6110
|
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
5824
6111
|
function zipAsync(data) {
|
|
5825
6112
|
return new Promise((resolve, reject) => {
|
|
@@ -5877,7 +6164,7 @@ function readEntry(files, name) {
|
|
|
5877
6164
|
if (!entry) throw new Error(`${name} not found in document zip`);
|
|
5878
6165
|
return strFromU8(entry);
|
|
5879
6166
|
}
|
|
5880
|
-
async function
|
|
6167
|
+
async function parseZipData(data) {
|
|
5881
6168
|
const files = await unzipAsync(data);
|
|
5882
6169
|
if (!files["state.json"]) throw new Error("Initial state not found");
|
|
5883
6170
|
const initialState = JSON.parse(readEntry(files, "state.json"));
|
|
@@ -5890,14 +6177,32 @@ async function loadFromZipData(data, reducer, options) {
|
|
|
5890
6177
|
const errorMessages = operationsError.map((err) => err.message);
|
|
5891
6178
|
throw new Error(errorMessages.join("\n"));
|
|
5892
6179
|
}
|
|
6180
|
+
return {
|
|
6181
|
+
initialState,
|
|
6182
|
+
header,
|
|
6183
|
+
clearedOperations
|
|
6184
|
+
};
|
|
6185
|
+
}
|
|
6186
|
+
async function loadFromZipData(data, reducer, options) {
|
|
6187
|
+
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
5893
6188
|
return {
|
|
5894
6189
|
...replayDocument(initialState, Object.fromEntries(Object.entries(clearedOperations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope))), reducer, header, void 0, {}, options),
|
|
5895
6190
|
operations: clearedOperations
|
|
5896
6191
|
};
|
|
5897
6192
|
}
|
|
6193
|
+
async function loadFromZipDataVersioned(data, config, options) {
|
|
6194
|
+
const { initialState, header, clearedOperations } = await parseZipData(data);
|
|
6195
|
+
return {
|
|
6196
|
+
...replayDocumentVersioned(initialState, clearedOperations, config, header, void 0, options),
|
|
6197
|
+
operations: clearedOperations
|
|
6198
|
+
};
|
|
6199
|
+
}
|
|
5898
6200
|
async function baseLoadFromInput(input, reducer, options) {
|
|
5899
6201
|
return loadFromZipData(await toUint8Array(input), reducer, options);
|
|
5900
6202
|
}
|
|
6203
|
+
async function baseLoadFromInputVersioned(input, config, options) {
|
|
6204
|
+
return loadFromZipDataVersioned(await toUint8Array(input), config, options);
|
|
6205
|
+
}
|
|
5901
6206
|
const documentModelLoadFromInput = (input) => {
|
|
5902
6207
|
return baseLoadFromInput(input, documentModelReducer);
|
|
5903
6208
|
};
|
|
@@ -7072,6 +7377,6 @@ const driveDocumentModelModule = {
|
|
|
7072
7377
|
}
|
|
7073
7378
|
};
|
|
7074
7379
|
//#endregion
|
|
7075
|
-
export {
|
|
7380
|
+
export { redo as A, setName as B, createZip as C, deleteOperationError as D, deleteOperation as E, setModelDescription as F, setStateSchema as G, setOperationErrorName as H, setModelExtension as I, validateModules as J, undo as K, setModelId as L, setAuthorName as M, setAuthorWebsite as N, documentModelDocumentType as O, setInitialState as P, setModelName as R, createState as S, deleteModule as T, setOperationName as U, setOperationDescription as V, setOperationSchema as W, generateId as X, validateStateSchemaName as Y, baseLoadFromInputVersioned as _, handleTargetNameCollisions as a, createPresignedHeader as b, moveNode as c, logger as d, addModule as f, baseLoadFromInput as g, baseCreateDocument as h, generateNodesCopy as i, replayDocumentVersioned as j, isDocumentAction as k, updateNode as l, addOperationError as m, copyNode as n, isFileNode as o, addOperation as p, validateInitialState as q, driveDocumentModelModule as r, isFolderNode as s, addFolder as t, documentModelDocumentModelModule as u, baseSaveToFileHandle as v, defaultBaseState as w, createReducer as x, buildSignedAction as y, setModuleName as z };
|
|
7076
7381
|
|
|
7077
|
-
//# sourceMappingURL=document-drive-
|
|
7382
|
+
//# sourceMappingURL=document-drive-DjL9iikf.mjs.map
|