@tearleads/client-sdk 0.1.63 → 0.1.64
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/data/documents/blob/shared/projection.js +1 -1
- package/data/documents/blob/shared/projection.js.map +1 -1
- package/data/documents/shared/projectionContentKeys.js +1 -1
- package/data/documents/shared/projectionContentKeys.js.map +1 -1
- package/data/documents/shared/syncResponseAuthorization.js +1 -1
- package/data/documents/shared/syncResponseAuthorization.js.map +1 -1
- package/data/keyingProjectionVerification/{accessManifestCheckpointEnforcement.js → checkpoints/accessManifestCheckpointEnforcement.js} +2 -2
- package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js.map +1 -0
- package/data/keyingProjectionVerification/{bundleVerification.js → checkpoints/bundleVerification.js} +5 -5
- package/data/keyingProjectionVerification/checkpoints/bundleVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{checkpointContext.d.ts → checkpoints/checkpointContext.d.ts} +6 -6
- package/data/keyingProjectionVerification/{checkpointContext.js → checkpoints/checkpointContext.js} +6 -6
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -0
- package/data/keyingProjectionVerification/{manifestCheckpointVerification.js → checkpoints/manifestCheckpointVerification.js} +2 -2
- package/data/keyingProjectionVerification/checkpoints/manifestCheckpointVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{containerAncestorCitations.js → container/containerAncestorCitations.js} +4 -4
- package/data/keyingProjectionVerification/container/containerAncestorCitations.js.map +1 -0
- package/data/keyingProjectionVerification/{containerCreateManifest.js → container/containerCreateManifest.js} +1 -1
- package/data/keyingProjectionVerification/{containerDestinationVerification.js → container/containerDestinationVerification.js} +4 -4
- package/data/keyingProjectionVerification/container/containerDestinationVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{containerManifestVerification.js → container/containerManifestVerification.js} +7 -7
- package/data/keyingProjectionVerification/container/containerManifestVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{containerPathVerification.js → container/containerPathVerification.js} +2 -2
- package/data/keyingProjectionVerification/container/containerPathVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{containerProjectionVerification.d.ts → container/containerProjectionVerification.d.ts} +7 -7
- package/data/keyingProjectionVerification/{containerProjectionVerification.js → container/containerProjectionVerification.js} +9 -9
- package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{documentDependencyPaths.d.ts → document/documentDependencyPaths.d.ts} +1 -1
- package/data/keyingProjectionVerification/{documentDependencyPaths.js → document/documentDependencyPaths.js} +3 -3
- package/data/keyingProjectionVerification/document/documentDependencyPaths.js.map +1 -0
- package/data/keyingProjectionVerification/{documentManifestPolicies.js → document/documentManifestPolicies.js} +2 -2
- package/data/keyingProjectionVerification/document/documentManifestPolicies.js.map +1 -0
- package/data/keyingProjectionVerification/{documentManifestPredecessor.js → document/documentManifestPredecessor.js} +1 -1
- package/data/keyingProjectionVerification/{documentManifestVerification.js → document/documentManifestVerification.js} +5 -5
- package/data/keyingProjectionVerification/document/documentManifestVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{documentProjectionVerification.d.ts → document/documentProjectionVerification.d.ts} +4 -4
- package/data/keyingProjectionVerification/{documentProjectionVerification.js → document/documentProjectionVerification.js} +9 -9
- package/data/keyingProjectionVerification/document/documentProjectionVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgeCheckpointCurrency.js → documentPurge/documentPurgeCheckpointCurrency.js} +12 -12
- package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointCurrency.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgeCheckpointEnforcement.js → documentPurge/documentPurgeCheckpointEnforcement.js} +2 -2
- package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointEnforcement.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgeDocumentChainVerification.js → documentPurge/documentPurgeDocumentChainVerification.js} +8 -8
- package/data/keyingProjectionVerification/documentPurge/documentPurgeDocumentChainVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgePolicyCheckpoints.js → documentPurge/documentPurgePolicyCheckpoints.js} +2 -2
- package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCheckpoints.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgePolicyCurrency.js → documentPurge/documentPurgePolicyCurrency.js} +4 -4
- package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCurrency.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgePrincipalEvidence.js → documentPurge/documentPurgePrincipalEvidence.js} +3 -3
- package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js.map +1 -0
- package/data/keyingProjectionVerification/{documentPurgeProofVerification.d.ts → documentPurge/documentPurgeProofVerification.d.ts} +5 -5
- package/data/keyingProjectionVerification/{documentPurgeProofVerification.js → documentPurge/documentPurgeProofVerification.js} +10 -10
- package/data/keyingProjectionVerification/documentPurge/documentPurgeProofVerification.js.map +1 -0
- package/data/keyingProjectionVerification/index.d.ts +4 -4
- package/data/keyingProjectionVerification/index.js +4 -4
- package/data/keyingProjectionVerification/index.js.map +1 -1
- package/data/keyingProjectionVerification/{mergeProjectionPolicyEvidence.js → principalPolicy/mergeProjectionPolicyEvidence.js} +2 -2
- package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -0
- package/data/keyingProjectionVerification/{organizationFounderBinding.js → principalPolicy/organizationFounderBinding.js} +3 -3
- package/data/keyingProjectionVerification/principalPolicy/organizationFounderBinding.js.map +1 -0
- package/data/keyingProjectionVerification/{principalPolicyCache.js → principalPolicy/principalPolicyCache.js} +6 -6
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js.map +1 -0
- package/data/keyingProjectionVerification/{principalPolicyVerification.js → principalPolicy/principalPolicyVerification.js} +12 -12
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map +1 -0
- package/data/keyingProjectionVerification/{projectionAuthorizationEvidence.js → principalPolicy/projectionAuthorizationEvidence.js} +3 -3
- package/data/keyingProjectionVerification/principalPolicy/projectionAuthorizationEvidence.js.map +1 -0
- package/data/keyingProjectionVerification/{projectionPolicyEvidence.js → principalPolicy/projectionPolicyEvidence.js} +3 -3
- package/data/keyingProjectionVerification/principalPolicy/projectionPolicyEvidence.js.map +1 -0
- package/data/keyingProjectionVerification/{resolvedPrincipalPolicy.js → principalPolicy/resolvedPrincipalPolicy.js} +6 -6
- package/data/keyingProjectionVerification/principalPolicy/resolvedPrincipalPolicy.js.map +1 -0
- package/package.json +1 -1
- package/stores/container-contents/accessRestorationSweep.js +1 -1
- package/stores/container-contents/accessRestorationSweep.js.map +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +1 -1
- package/stores/container-contents/containerContentsStore.js +12 -12
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/containerState/containerStateMap.js.map +1 -0
- package/stores/container-contents/{containerStatePersistence.js → containerState/containerStatePersistence.js} +2 -2
- package/stores/container-contents/containerState/containerStatePersistence.js.map +1 -0
- package/stores/container-contents/{missingContainerState.js → containerState/missingContainerState.js} +1 -1
- package/stores/container-contents/containerState/missingContainerState.js.map +1 -0
- package/stores/container-contents/containerState/missingSyncedContainerState.js.map +1 -0
- package/stores/container-contents/{reconcilableContainer.d.ts → containerState/reconcilableContainer.d.ts} +1 -1
- package/stores/container-contents/containerState/reconcilableContainer.js.map +1 -0
- package/stores/container-contents/{documentRecovery.js → documentWork/documentRecovery.js} +6 -6
- package/stores/container-contents/documentWork/documentRecovery.js.map +1 -0
- package/stores/container-contents/{documentRotation.js → documentWork/documentRotation.js} +2 -2
- package/stores/container-contents/documentWork/documentRotation.js.map +1 -0
- package/stores/container-contents/{documentWork.js → documentWork/index.js} +1 -1
- package/stores/container-contents/documentWork/index.js.map +1 -0
- package/stores/container-contents/{backgroundHydration.js → hydration/backgroundHydration.js} +3 -3
- package/stores/container-contents/hydration/backgroundHydration.js.map +1 -0
- package/stores/container-contents/{remoteHydrationRequest.js → hydration/remoteHydrationRequest.js} +3 -3
- package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -0
- package/stores/container-contents/{startupHydration.js → hydration/startupHydration.js} +3 -3
- package/stores/container-contents/hydration/startupHydration.js.map +1 -0
- package/stores/container-contents/index.d.ts +3 -3
- package/stores/container-contents/index.js +2 -2
- package/stores/container-contents/index.js.map +1 -1
- package/stores/container-contents/localRefresh.js +2 -2
- package/stores/container-contents/localRefresh.js.map +1 -1
- package/stores/container-contents/{containerPurgeCore.js → operations/containerPurgeCore.js} +4 -4
- package/stores/container-contents/operations/containerPurgeCore.js.map +1 -0
- package/stores/container-contents/operations/emptyTrashOperation.js.map +1 -0
- package/stores/container-contents/{groupRewrapOperation.js → operations/groupRewrapOperation.js} +2 -2
- package/stores/container-contents/operations/groupRewrapOperation.js.map +1 -0
- package/stores/container-contents/{operations.js → operations/index.js} +18 -18
- package/stores/container-contents/operations/index.js.map +1 -0
- package/stores/container-contents/operations/purgeContainerOperation.js.map +1 -0
- package/stores/container-contents/{reportShareFailure.js → operations/reportShareFailure.js} +4 -4
- package/stores/container-contents/operations/reportShareFailure.js.map +1 -0
- package/stores/container-contents/{setContainerIconOperation.js → operations/setContainerIconOperation.js} +6 -6
- package/stores/container-contents/operations/setContainerIconOperation.js.map +1 -0
- package/stores/container-contents/{shareOperations.js → operations/shareOperations.js} +6 -6
- package/stores/container-contents/operations/shareOperations.js.map +1 -0
- package/stores/container-contents/remoteEvents/remoteBackedContainerState.js.map +1 -0
- package/stores/container-contents/{remoteContainerIngestion.js → remoteEvents/remoteContainerIngestion.js} +4 -4
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -0
- package/stores/container-contents/{remoteEventProjectionInvalidation.js → remoteEvents/remoteEventProjectionInvalidation.js} +1 -1
- package/stores/container-contents/remoteEvents/remoteEventProjectionInvalidation.js.map +1 -0
- package/stores/container-contents/{remoteEventSync.js → remoteEvents/remoteEventSync.js} +4 -4
- package/stores/container-contents/remoteEvents/remoteEventSync.js.map +1 -0
- package/stores/container-contents/{remoteWriteGuards.js → remoteWrites/remoteWriteGuards.js} +2 -2
- package/stores/container-contents/remoteWrites/remoteWriteGuards.js.map +1 -0
- package/stores/container-contents/{remoteWriteQueue.js → remoteWrites/remoteWriteQueue.js} +1 -1
- package/stores/container-contents/remoteWrites/remoteWriteQueue.js.map +1 -0
- package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -0
- package/stores/container-contents/state.d.ts +1 -1
- package/stores/container-contents/state.js +2 -2
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/{syncAgent.d.ts → syncAgent/index.d.ts} +2 -2
- package/stores/container-contents/{syncAgent.js → syncAgent/index.js} +14 -14
- package/stores/container-contents/syncAgent/index.js.map +1 -0
- package/stores/container-contents/{metadataSyncSignal.js → syncAgent/metadataSyncSignal.js} +1 -1
- package/stores/container-contents/{metadataSyncSignal.js.map → syncAgent/metadataSyncSignal.js.map} +1 -1
- package/stores/container-contents/{syncAgentTypes.d.ts → syncAgent/syncAgentTypes.d.ts} +5 -5
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -0
- package/stores/container-contents/{syncLaneIteration.js → syncAgent/syncLaneIteration.js} +11 -11
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -0
- package/stores/container-contents/{existingSystemContainer.js → systemContainers/existingSystemContainer.js} +4 -4
- package/stores/container-contents/systemContainers/existingSystemContainer.js.map +1 -0
- package/stores/container-contents/{organizationMetadataSystemContainer.js → systemContainers/organizationMetadataSystemContainer.js} +2 -2
- package/stores/container-contents/systemContainers/organizationMetadataSystemContainer.js.map +1 -0
- package/stores/container-contents/{systemContainerHydration.js → systemContainers/systemContainerHydration.js} +3 -3
- package/stores/container-contents/systemContainers/systemContainerHydration.js.map +1 -0
- package/stores/container-contents/{systemContainerIcon.js → systemContainers/systemContainerIcon.js} +5 -5
- package/stores/container-contents/systemContainers/systemContainerIcon.js.map +1 -0
- package/stores/container-contents/systemContainers/systemContainerLookup.js.map +1 -0
- package/stores/container-contents/{systemContainerPostCreate.js → systemContainers/systemContainerPostCreate.js} +2 -2
- package/stores/container-contents/systemContainers/systemContainerPostCreate.js.map +1 -0
- package/stores/container-contents/{systemContainerPromotion.js → systemContainers/systemContainerPromotion.js} +1 -1
- package/stores/container-contents/systemContainers/systemContainerPromotion.js.map +1 -0
- package/stores/container-contents/types.d.ts +2 -2
- package/stores/container-contents/types.js.map +1 -1
- package/stores/documents/documentStore/{attachmentSourceUpload.js → attachmentUpload/attachmentSourceUpload.js} +4 -4
- package/stores/documents/documentStore/attachmentUpload/attachmentSourceUpload.js.map +1 -0
- package/stores/documents/documentStore/{attachmentStaging.js → attachmentUpload/attachmentStaging.js} +5 -5
- package/stores/documents/documentStore/attachmentUpload/attachmentStaging.js.map +1 -0
- package/stores/documents/documentStore/{attachmentUploadAttempt.js → attachmentUpload/attachmentUploadAttempt.js} +2 -2
- package/stores/documents/documentStore/attachmentUpload/attachmentUploadAttempt.js.map +1 -0
- package/stores/documents/documentStore/{attachmentUploadLane.js → attachmentUpload/attachmentUploadLane.js} +1 -1
- package/stores/documents/documentStore/attachmentUpload/attachmentUploadLane.js.map +1 -0
- package/stores/documents/documentStore/{attachmentUploadResume.js → attachmentUpload/attachmentUploadResume.js} +4 -4
- package/stores/documents/documentStore/attachmentUpload/attachmentUploadResume.js.map +1 -0
- package/stores/documents/documentStore/{attachmentDetachState.js → attachments/attachmentDetachState.js} +1 -1
- package/stores/documents/documentStore/attachments/attachmentDetachState.js.map +1 -0
- package/stores/documents/documentStore/{attachmentHydration.js → attachments/attachmentHydration.js} +5 -5
- package/stores/documents/documentStore/attachments/attachmentHydration.js.map +1 -0
- package/stores/documents/documentStore/{attachmentHydrationCommit.js → attachments/attachmentHydrationCommit.js} +3 -3
- package/stores/documents/documentStore/attachments/attachmentHydrationCommit.js.map +1 -0
- package/stores/documents/documentStore/{attachmentIntents.js → attachments/attachmentIntents.js} +2 -2
- package/stores/documents/documentStore/attachments/attachmentIntents.js.map +1 -0
- package/stores/documents/documentStore/{attachmentMutationPersistence.js → attachments/attachmentMutationPersistence.js} +4 -4
- package/stores/documents/documentStore/attachments/attachmentMutationPersistence.js.map +1 -0
- package/stores/documents/documentStore/attachments/attachmentPersistFollowup.js.map +1 -0
- package/stores/documents/documentStore/{attachmentPersistence.js → attachments/attachmentPersistence.js} +4 -4
- package/stores/documents/documentStore/attachments/attachmentPersistence.js.map +1 -0
- package/stores/documents/documentStore/{attachmentRemoval.js → attachments/attachmentRemoval.js} +11 -11
- package/stores/documents/documentStore/attachments/attachmentRemoval.js.map +1 -0
- package/stores/documents/documentStore/attachments/attachmentSnapshot.js.map +1 -0
- package/stores/documents/documentStore/{attachmentWriteGeneration.js → attachments/attachmentWriteGeneration.js} +2 -2
- package/stores/documents/documentStore/attachments/attachmentWriteGeneration.js.map +1 -0
- package/stores/documents/documentStore/{attachments.js → attachments/index.js} +11 -11
- package/stores/documents/documentStore/attachments/index.js.map +1 -0
- package/stores/documents/documentStore/{documentHistoryCompaction.js → history/documentHistoryCompaction.js} +4 -4
- package/stores/documents/documentStore/history/documentHistoryCompaction.js.map +1 -0
- package/stores/documents/documentStore/{durableDocumentReload.js → history/durableDocumentReload.js} +6 -6
- package/stores/documents/documentStore/history/durableDocumentReload.js.map +1 -0
- package/stores/documents/documentStore/{historyRebuild.js → history/historyRebuild.js} +6 -6
- package/stores/documents/documentStore/history/historyRebuild.js.map +1 -0
- package/stores/documents/{documentStore.d.ts → documentStore/index.d.ts} +5 -5
- package/stores/documents/{documentStore.js → documentStore/index.js} +18 -18
- package/stores/documents/documentStore/index.js.map +1 -0
- package/stores/documents/documentStore/{deferredInitialUpdate.js → initialization/deferredInitialUpdate.js} +9 -9
- package/stores/documents/documentStore/initialization/deferredInitialUpdate.js.map +1 -0
- package/stores/documents/documentStore/{initialization.js → initialization/index.js} +14 -14
- package/stores/documents/documentStore/initialization/index.js.map +1 -0
- package/stores/documents/documentStore/{initializationAttachments.js → initialization/initializationAttachments.js} +1 -1
- package/stores/documents/documentStore/initialization/initializationAttachments.js.map +1 -0
- package/stores/documents/documentStore/{initializationHistory.js → initialization/initializationHistory.js} +3 -3
- package/stores/documents/documentStore/initialization/initializationHistory.js.map +1 -0
- package/stores/documents/documentStore/{initializationRecovery.js → initialization/initializationRecovery.js} +7 -7
- package/stores/documents/documentStore/initialization/initializationRecovery.js.map +1 -0
- package/stores/documents/documentStore/mutationIdentityRevalidation.js.map +1 -1
- package/stores/documents/documentStore/mutations.js +2 -2
- package/stores/documents/documentStore/mutations.js.map +1 -1
- package/stores/documents/documentStore/pendingUpdateRefusal.js +1 -1
- package/stores/documents/documentStore/pendingUpdateRefusal.js.map +1 -1
- package/stores/documents/documentStore/persistence.js +3 -3
- package/stores/documents/documentStore/persistence.js.map +1 -1
- package/stores/documents/documentStore/{rotation.js → rotation/index.js} +14 -14
- package/stores/documents/documentStore/rotation/index.js.map +1 -0
- package/stores/documents/documentStore/{rotationProvenance.js → rotation/rotationProvenance.js} +2 -2
- package/stores/documents/documentStore/rotation/rotationProvenance.js.map +1 -0
- package/stores/documents/documentStore/{rotationSettlement.js → rotation/rotationSettlement.js} +9 -9
- package/stores/documents/documentStore/rotation/rotationSettlement.js.map +1 -0
- package/stores/documents/documentStore/rows.js +2 -2
- package/stores/documents/documentStore/rows.js.map +1 -1
- package/stores/documents/documentStore/state.js +1 -1
- package/stores/documents/documentStore/state.js.map +1 -1
- package/stores/documents/documentStore/{sync.js → sync/index.js} +7 -7
- package/stores/documents/documentStore/sync/index.js.map +1 -0
- package/stores/documents/documentStore/{pullContinuationInvalidation.js → sync/pullContinuationInvalidation.js} +3 -3
- package/stores/documents/documentStore/sync/pullContinuationInvalidation.js.map +1 -0
- package/stores/documents/documentStore/{remoteRevalidationTelemetry.js → sync/remoteRevalidationTelemetry.js} +1 -1
- package/stores/documents/documentStore/sync/remoteRevalidationTelemetry.js.map +1 -0
- package/stores/documents/documentStore/sync/remoteWork.js.map +1 -0
- package/stores/documents/documentStore/sync/syncAcceptedUpdateIds.js.map +1 -0
- package/stores/documents/documentStore/{syncAttachmentSettlement.js → sync/syncAttachmentSettlement.js} +3 -3
- package/stores/documents/documentStore/sync/syncAttachmentSettlement.js.map +1 -0
- package/stores/documents/documentStore/{syncAttachments.js → sync/syncAttachments.js} +7 -7
- package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -0
- package/stores/documents/documentStore/{syncDetachedAttachments.js → sync/syncDetachedAttachments.js} +7 -7
- package/stores/documents/documentStore/sync/syncDetachedAttachments.js.map +1 -0
- package/stores/documents/documentStore/{syncFinalize.js → sync/syncFinalize.js} +9 -9
- package/stores/documents/documentStore/sync/syncFinalize.js.map +1 -0
- package/stores/documents/documentStore/sync/syncGeneration.js.map +1 -0
- package/stores/documents/documentStore/{syncOutgoingCoverage.js → sync/syncOutgoingCoverage.js} +4 -4
- package/stores/documents/documentStore/sync/syncOutgoingCoverage.js.map +1 -0
- package/stores/documents/documentStore/{syncRemoteSignals.js → sync/syncRemoteSignals.js} +4 -4
- package/stores/documents/documentStore/sync/syncRemoteSignals.js.map +1 -0
- package/stores/documents/documentStore/{syncRequest.js → sync/syncRequest.js} +8 -8
- package/stores/documents/documentStore/sync/syncRequest.js.map +1 -0
- package/stores/documents/documentStore/{syncShared.js → sync/syncShared.js} +8 -8
- package/stores/documents/documentStore/sync/syncShared.js.map +1 -0
- package/stores/documents/documentStore/{syncUpdateImport.js → sync/syncUpdateImport.js} +3 -3
- package/stores/documents/documentStore/sync/syncUpdateImport.js.map +1 -0
- package/stores/documents/documentStore/{versionCoverage.js → sync/versionCoverage.js} +1 -1
- package/stores/documents/index.d.ts +1 -1
- package/stores/documents/index.js +1 -1
- package/stores/local-projection/localProjectionStore.d.ts +1 -1
- package/stores/local-projection/localProjectionStore.js +1 -1
- package/stores/local-projection/localProjectionStore.js.map +1 -1
- package/stores/local-projection/registry.d.ts +1 -1
- package/stores/local-projection/types.d.ts +1 -1
- package/workflows/blobs/hydration/decrypt.js +1 -1
- package/workflows/blobs/hydration/decrypt.js.map +1 -1
- package/workflows/container-contents/container-state/{createAdoption.js → create/createAdoption.js} +6 -6
- package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -0
- package/workflows/container-contents/container-state/{createChild.js → create/createChild.js} +7 -7
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -0
- package/workflows/container-contents/container-state/{createIntentDepth.js → create/createIntentDepth.js} +2 -2
- package/workflows/container-contents/container-state/create/createIntentDepth.js.map +1 -0
- package/workflows/container-contents/container-state/create/createIntentSettlement.js.map +1 -0
- package/workflows/container-contents/container-state/{createIntentSync.js → create/createIntentSync.js} +7 -7
- package/workflows/container-contents/container-state/create/createIntentSync.js.map +1 -0
- package/workflows/container-contents/container-state/{createTerminalFailure.js → create/createTerminalFailure.js} +2 -2
- package/workflows/container-contents/container-state/create/createTerminalFailure.js.map +1 -0
- package/workflows/container-contents/container-state/{createWithMetadata.js → create/createWithMetadata.js} +9 -9
- package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -0
- package/workflows/container-contents/container-state/{createWithMetadataPlan.js → create/createWithMetadataPlan.js} +4 -4
- package/workflows/container-contents/container-state/create/createWithMetadataPlan.js.map +1 -0
- package/workflows/container-contents/container-state/{localPurgeScope.js → purge/localPurgeScope.js} +1 -1
- package/workflows/container-contents/container-state/purge/localPurgeScope.js.map +1 -0
- package/workflows/container-contents/container-state/{purgeTree.js → purge/purgeTree.js} +5 -5
- package/workflows/container-contents/container-state/purge/purgeTree.js.map +1 -0
- package/workflows/container-contents/container-state/purge/purgeTreeCollection.js.map +1 -0
- package/workflows/container-contents/container-state/{purgeTreeContainerDeletion.js → purge/purgeTreeContainerDeletion.js} +1 -1
- package/workflows/container-contents/container-state/purge/purgeTreeContainerDeletion.js.map +1 -0
- package/workflows/container-contents/container-state/{purgeTreeScope.js → purge/purgeTreeScope.js} +8 -8
- package/workflows/container-contents/container-state/purge/purgeTreeScope.js.map +1 -0
- package/workflows/container-contents/container-state/{readLocalPurgeScope.js → purge/readLocalPurgeScope.js} +3 -3
- package/workflows/container-contents/container-state/purge/readLocalPurgeScope.js.map +1 -0
- package/workflows/container-contents/container-state/remote.js +2 -2
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/container-contents/container-state/{groupGrantVerification.js → share/groupGrantVerification.js} +8 -8
- package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -0
- package/workflows/container-contents/container-state/{groupShareEpoch.js → share/groupShareEpoch.js} +2 -2
- package/workflows/container-contents/container-state/share/groupShareEpoch.js.map +1 -0
- package/workflows/container-contents/container-state/{share.js → share/index.js} +8 -8
- package/workflows/container-contents/container-state/share/index.js.map +1 -0
- package/workflows/container-contents/container-state/{sharePersistence.js → share/sharePersistence.js} +3 -3
- package/workflows/container-contents/container-state/share/sharePersistence.js.map +1 -0
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/index.js +1 -1
- package/workflows/container-contents/documentDiscovery/index.js.map +1 -1
- package/workflows/container-contents/metadata/metadataSyncErrors.js +1 -1
- package/workflows/container-contents/metadata/metadataSyncErrors.js.map +1 -1
- package/workflows/container-contents/remoteHydration/destination/destinationPrefetch.js.map +1 -0
- package/workflows/container-contents/remoteHydration/destination/destinationRoleCache.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{destinationRootReload.js → destination/destinationRootReload.js} +1 -1
- package/workflows/container-contents/remoteHydration/destination/destinationRootReload.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{replacementBinding.js → destination/replacementBinding.js} +5 -5
- package/workflows/container-contents/remoteHydration/destination/replacementBinding.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{verifiedDestination.js → destination/verifiedDestination.js} +9 -9
- package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -0
- package/workflows/container-contents/remoteHydration/index.js +4 -4
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/childIndex.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{laneFetchMarkers.js → lanes/laneFetchMarkers.js} +1 -1
- package/workflows/container-contents/remoteHydration/lanes/laneFetchMarkers.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{parentLaneFetch.js → lanes/parentLaneFetch.js} +2 -2
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -0
- package/workflows/container-contents/remoteHydration/lanes/parentLaneQueue.js.map +1 -0
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js +1 -1
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
- package/workflows/container-contents/remoteHydration/reconciliation.js +2 -2
- package/workflows/container-contents/remoteHydration/reconciliation.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/containerStateFingerprint.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{insertRemoteContainer.js → remoteContainers/insertRemoteContainer.js} +6 -6
- package/workflows/container-contents/remoteHydration/remoteContainers/insertRemoteContainer.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{remoteContainerPageHydration.js → remoteContainers/remoteContainerPageHydration.js} +7 -7
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -0
- package/workflows/container-contents/remoteHydration/{remoteContainerState.js → remoteContainers/remoteContainerState.js} +9 -9
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -0
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerTimestamps.js.map +1 -0
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js +2 -2
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js.map +1 -1
- package/workflows/containers/child/{createProjection.d.ts → create/createProjection.d.ts} +2 -2
- package/workflows/containers/child/{createProjection.js → create/createProjection.js} +2 -2
- package/workflows/containers/child/create/createProjection.js.map +1 -0
- package/workflows/containers/child/{createSubmission.d.ts → create/createSubmission.d.ts} +7 -7
- package/workflows/containers/child/{createSubmission.js → create/createSubmission.js} +2 -2
- package/workflows/containers/child/create/createSubmission.js.map +1 -0
- package/workflows/containers/child/{create.d.ts → create/index.d.ts} +5 -5
- package/workflows/containers/child/{create.js → create/index.js} +15 -15
- package/workflows/containers/child/create/index.js.map +1 -0
- package/workflows/containers/child/{move.d.ts → move/index.d.ts} +5 -5
- package/workflows/containers/child/{move.js → move/index.js} +12 -12
- package/workflows/containers/child/move/index.js.map +1 -0
- package/workflows/containers/child/{moveArtifacts.js → move/moveArtifacts.js} +3 -3
- package/workflows/containers/child/move/moveArtifacts.js.map +1 -0
- package/workflows/containers/child/{moveRotation.js → move/moveRotation.js} +3 -3
- package/workflows/containers/child/move/moveRotation.js.map +1 -0
- package/workflows/containers/child/{moveWraps.js → move/moveWraps.js} +5 -5
- package/workflows/containers/child/move/moveWraps.js.map +1 -0
- package/workflows/containers/child/mutationSubmit.js +1 -1
- package/workflows/containers/child/mutationSubmit.js.map +1 -1
- package/workflows/containers/child/{carriedDescendantRekeys.js → rekey/carriedDescendantRekeys.js} +4 -4
- package/workflows/containers/child/rekey/carriedDescendantRekeys.js.map +1 -0
- package/workflows/containers/child/{rekey.d.ts → rekey/index.d.ts} +6 -6
- package/workflows/containers/child/{rekey.js → rekey/index.js} +13 -13
- package/workflows/containers/child/rekey/index.js.map +1 -0
- package/workflows/containers/child/{keyringOverrideLineage.d.ts → rekey/keyringOverrideLineage.d.ts} +1 -1
- package/workflows/containers/child/{keyringOverrideLineage.js → rekey/keyringOverrideLineage.js} +1 -1
- package/workflows/containers/child/{rekeyProjection.d.ts → rekey/rekeyProjection.d.ts} +2 -2
- package/workflows/containers/child/{rekeyProjection.js → rekey/rekeyProjection.js} +3 -3
- package/workflows/containers/child/rekey/rekeyProjection.js.map +1 -0
- package/workflows/containers/child/{rekeyRemote.d.ts → rekey/rekeyRemote.d.ts} +6 -6
- package/workflows/containers/child/{rekeyRemote.js → rekey/rekeyRemote.js} +2 -2
- package/workflows/containers/child/rekey/rekeyRemote.js.map +1 -0
- package/workflows/containers/child/revoke.js +5 -5
- package/workflows/containers/child/revoke.js.map +1 -1
- package/workflows/containers/child/{replacementPrincipalPolicyReferences.js → rotation/replacementPrincipalPolicyReferences.js} +2 -2
- package/workflows/containers/child/rotation/replacementPrincipalPolicyReferences.js.map +1 -0
- package/workflows/containers/child/{rotationContext.js → rotation/rotationContext.js} +5 -5
- package/workflows/containers/child/rotation/rotationContext.js.map +1 -0
- package/workflows/containers/child/{rotationPrincipalPolicies.js → rotation/rotationPrincipalPolicies.js} +2 -2
- package/workflows/containers/child/rotation/rotationPrincipalPolicies.js.map +1 -0
- package/workflows/containers/child/{rotationWraps.js → rotation/rotationWraps.js} +1 -1
- package/workflows/containers/child/rotation/rotationWraps.js.map +1 -0
- package/workflows/containers/child/{currentShareGrantMutation.js → share/currentShareGrantMutation.js} +6 -6
- package/workflows/containers/child/share/currentShareGrantMutation.js.map +1 -0
- package/workflows/containers/child/{currentSharePrincipalPolicy.js → share/currentSharePrincipalPolicy.js} +10 -10
- package/workflows/containers/child/share/currentSharePrincipalPolicy.js.map +1 -0
- package/workflows/containers/child/{share.d.ts → share/index.d.ts} +8 -8
- package/workflows/containers/child/{share.js → share/index.js} +10 -10
- package/workflows/containers/child/share/index.js.map +1 -0
- package/workflows/containers/child/{runtimeCurrentGroupShare.js → share/runtimeCurrentGroupShare.js} +6 -6
- package/workflows/containers/child/share/runtimeCurrentGroupShare.js.map +1 -0
- package/workflows/containers/child/{shareAncestorRepair.js → share/shareAncestorRepair.js} +4 -4
- package/workflows/containers/child/share/shareAncestorRepair.js.map +1 -0
- package/workflows/containers/child/{shareMaterialization.d.ts → share/shareMaterialization.d.ts} +5 -5
- package/workflows/containers/child/{shareMaterialization.js → share/shareMaterialization.js} +7 -7
- package/workflows/containers/child/share/shareMaterialization.js.map +1 -0
- package/workflows/containers/child/{sharePlanCore.d.ts → share/sharePlanCore.d.ts} +7 -7
- package/workflows/containers/child/{sharePlanCore.js → share/sharePlanCore.js} +6 -6
- package/workflows/containers/child/share/sharePlanCore.js.map +1 -0
- package/workflows/containers/child/{sharePrincipalPolicy.d.ts → share/sharePrincipalPolicy.d.ts} +9 -9
- package/workflows/containers/child/{sharePrincipalPolicy.js → share/sharePrincipalPolicy.js} +13 -13
- package/workflows/containers/child/share/sharePrincipalPolicy.js.map +1 -0
- package/workflows/containers/child/share/shareProjection.js.map +1 -0
- package/workflows/containers/index.d.ts +10 -10
- package/workflows/containers/index.js +10 -10
- package/workflows/containers/index.js.map +1 -1
- package/workflows/documents/linkSet/linkSetAuthority.js +1 -1
- package/workflows/documents/linkSet/linkSetAuthority.js.map +1 -1
- package/workflows/documents/linkSet/linkSetBlobRewraps.js +1 -1
- package/workflows/documents/linkSet/linkSetBlobRewraps.js.map +1 -1
- package/workflows/documents/linkSet/linkSetProjectionSeed.js +1 -1
- package/workflows/documents/linkSet/linkSetProjectionSeed.js.map +1 -1
- package/workflows/documents/purge/index.js +1 -1
- package/workflows/documents/purge/index.js.map +1 -1
- package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js +2 -2
- package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -1
- package/workflows/organizations/rematerialization/precedingPrincipalRematerialization.js +1 -1
- package/workflows/organizations/rematerialization/precedingPrincipalRematerialization.js.map +1 -1
- package/workflows/organizations/rematerialization/principalContainerRematerialization.js +5 -5
- package/workflows/organizations/rematerialization/principalContainerRematerialization.js.map +1 -1
- package/workflows/organizations/rematerialization/principalContainerRematerializationPlanning.js +1 -1
- package/workflows/organizations/rematerialization/principalContainerRematerializationPlanning.js.map +1 -1
- package/workflows/organizations/rematerialization/principalContainerRematerializationTargets.js +1 -1
- package/workflows/organizations/rematerialization/principalContainerRematerializationTargets.js.map +1 -1
- package/workflows/principals/policyCache/index.js +1 -1
- package/workflows/principals/policyCache/index.js.map +1 -1
- package/workflows/principals/policyRepair.js +1 -1
- package/workflows/principals/policyRepair.js.map +1 -1
- package/workflows/registration/organizationProvisioningArtifacts.d.ts +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.js +1 -1
- package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +0 -1
- package/data/keyingProjectionVerification/bundleVerification.js.map +0 -1
- package/data/keyingProjectionVerification/checkpointContext.js.map +0 -1
- package/data/keyingProjectionVerification/containerAncestorCitations.js.map +0 -1
- package/data/keyingProjectionVerification/containerDestinationVerification.js.map +0 -1
- package/data/keyingProjectionVerification/containerManifestVerification.js.map +0 -1
- package/data/keyingProjectionVerification/containerPathVerification.js.map +0 -1
- package/data/keyingProjectionVerification/containerProjectionVerification.js.map +0 -1
- package/data/keyingProjectionVerification/documentDependencyPaths.js.map +0 -1
- package/data/keyingProjectionVerification/documentManifestPolicies.js.map +0 -1
- package/data/keyingProjectionVerification/documentManifestVerification.js.map +0 -1
- package/data/keyingProjectionVerification/documentProjectionVerification.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgeCheckpointEnforcement.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js.map +0 -1
- package/data/keyingProjectionVerification/documentPurgeProofVerification.js.map +0 -1
- package/data/keyingProjectionVerification/manifestCheckpointVerification.js.map +0 -1
- package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +0 -1
- package/data/keyingProjectionVerification/organizationFounderBinding.js.map +0 -1
- package/data/keyingProjectionVerification/principalPolicyCache.js.map +0 -1
- package/data/keyingProjectionVerification/principalPolicyVerification.js.map +0 -1
- package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +0 -1
- package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +0 -1
- package/data/keyingProjectionVerification/resolvedPrincipalPolicy.js.map +0 -1
- package/stores/container-contents/backgroundHydration.js.map +0 -1
- package/stores/container-contents/containerPurgeCore.js.map +0 -1
- package/stores/container-contents/containerStateMap.js.map +0 -1
- package/stores/container-contents/containerStatePersistence.js.map +0 -1
- package/stores/container-contents/documentRecovery.js.map +0 -1
- package/stores/container-contents/documentRotation.js.map +0 -1
- package/stores/container-contents/documentWork.js.map +0 -1
- package/stores/container-contents/emptyTrashOperation.js.map +0 -1
- package/stores/container-contents/existingSystemContainer.js.map +0 -1
- package/stores/container-contents/groupRewrapOperation.js.map +0 -1
- package/stores/container-contents/missingContainerState.js.map +0 -1
- package/stores/container-contents/missingSyncedContainerState.js.map +0 -1
- package/stores/container-contents/operations.js.map +0 -1
- package/stores/container-contents/organizationMetadataSystemContainer.js.map +0 -1
- package/stores/container-contents/purgeContainerOperation.js.map +0 -1
- package/stores/container-contents/reconcilableContainer.js.map +0 -1
- package/stores/container-contents/remoteBackedContainerState.js.map +0 -1
- package/stores/container-contents/remoteContainerIngestion.js.map +0 -1
- package/stores/container-contents/remoteEventProjectionInvalidation.js.map +0 -1
- package/stores/container-contents/remoteEventSync.js.map +0 -1
- package/stores/container-contents/remoteHydrationRequest.js.map +0 -1
- package/stores/container-contents/remoteWriteGuards.js.map +0 -1
- package/stores/container-contents/remoteWriteQueue.js.map +0 -1
- package/stores/container-contents/reportShareFailure.js.map +0 -1
- package/stores/container-contents/setContainerIconOperation.js.map +0 -1
- package/stores/container-contents/shareOperations.js.map +0 -1
- package/stores/container-contents/startupHydration.js.map +0 -1
- package/stores/container-contents/syncAgent.js.map +0 -1
- package/stores/container-contents/syncAgentTypes.js.map +0 -1
- package/stores/container-contents/syncLaneIteration.js.map +0 -1
- package/stores/container-contents/systemContainerHydration.js.map +0 -1
- package/stores/container-contents/systemContainerIcon.js.map +0 -1
- package/stores/container-contents/systemContainerLookup.js.map +0 -1
- package/stores/container-contents/systemContainerPostCreate.js.map +0 -1
- package/stores/container-contents/systemContainerPromotion.js.map +0 -1
- package/stores/container-contents/writeGeneration.js.map +0 -1
- package/stores/documents/documentStore/attachmentDetachState.js.map +0 -1
- package/stores/documents/documentStore/attachmentHydration.js.map +0 -1
- package/stores/documents/documentStore/attachmentHydrationCommit.js.map +0 -1
- package/stores/documents/documentStore/attachmentIntents.js.map +0 -1
- package/stores/documents/documentStore/attachmentMutationPersistence.js.map +0 -1
- package/stores/documents/documentStore/attachmentPersistFollowup.js.map +0 -1
- package/stores/documents/documentStore/attachmentPersistence.js.map +0 -1
- package/stores/documents/documentStore/attachmentRemoval.js.map +0 -1
- package/stores/documents/documentStore/attachmentSnapshot.js.map +0 -1
- package/stores/documents/documentStore/attachmentSourceUpload.js.map +0 -1
- package/stores/documents/documentStore/attachmentStaging.js.map +0 -1
- package/stores/documents/documentStore/attachmentUploadAttempt.js.map +0 -1
- package/stores/documents/documentStore/attachmentUploadLane.js.map +0 -1
- package/stores/documents/documentStore/attachmentUploadResume.js.map +0 -1
- package/stores/documents/documentStore/attachmentWriteGeneration.js.map +0 -1
- package/stores/documents/documentStore/attachments.js.map +0 -1
- package/stores/documents/documentStore/deferredInitialUpdate.js.map +0 -1
- package/stores/documents/documentStore/documentHistoryCompaction.js.map +0 -1
- package/stores/documents/documentStore/durableDocumentReload.js.map +0 -1
- package/stores/documents/documentStore/historyRebuild.js.map +0 -1
- package/stores/documents/documentStore/initialization.js.map +0 -1
- package/stores/documents/documentStore/initializationAttachments.js.map +0 -1
- package/stores/documents/documentStore/initializationHistory.js.map +0 -1
- package/stores/documents/documentStore/initializationRecovery.js.map +0 -1
- package/stores/documents/documentStore/pullContinuationInvalidation.js.map +0 -1
- package/stores/documents/documentStore/remoteRevalidationTelemetry.js.map +0 -1
- package/stores/documents/documentStore/remoteWork.js.map +0 -1
- package/stores/documents/documentStore/rotation.js.map +0 -1
- package/stores/documents/documentStore/rotationProvenance.js.map +0 -1
- package/stores/documents/documentStore/rotationSettlement.js.map +0 -1
- package/stores/documents/documentStore/sync.js.map +0 -1
- package/stores/documents/documentStore/syncAcceptedUpdateIds.js.map +0 -1
- package/stores/documents/documentStore/syncAttachmentSettlement.js.map +0 -1
- package/stores/documents/documentStore/syncAttachments.js.map +0 -1
- package/stores/documents/documentStore/syncDetachedAttachments.js.map +0 -1
- package/stores/documents/documentStore/syncFinalize.js.map +0 -1
- package/stores/documents/documentStore/syncGeneration.js.map +0 -1
- package/stores/documents/documentStore/syncOutgoingCoverage.js.map +0 -1
- package/stores/documents/documentStore/syncRemoteSignals.js.map +0 -1
- package/stores/documents/documentStore/syncRequest.js.map +0 -1
- package/stores/documents/documentStore/syncShared.js.map +0 -1
- package/stores/documents/documentStore/syncUpdateImport.js.map +0 -1
- package/stores/documents/documentStore.js.map +0 -1
- package/workflows/container-contents/container-state/createAdoption.js.map +0 -1
- package/workflows/container-contents/container-state/createChild.js.map +0 -1
- package/workflows/container-contents/container-state/createIntentDepth.js.map +0 -1
- package/workflows/container-contents/container-state/createIntentSettlement.js.map +0 -1
- package/workflows/container-contents/container-state/createIntentSync.js.map +0 -1
- package/workflows/container-contents/container-state/createTerminalFailure.js.map +0 -1
- package/workflows/container-contents/container-state/createWithMetadata.js.map +0 -1
- package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +0 -1
- package/workflows/container-contents/container-state/groupGrantVerification.js.map +0 -1
- package/workflows/container-contents/container-state/groupShareEpoch.js.map +0 -1
- package/workflows/container-contents/container-state/localPurgeScope.js.map +0 -1
- package/workflows/container-contents/container-state/purgeTree.js.map +0 -1
- package/workflows/container-contents/container-state/purgeTreeCollection.js.map +0 -1
- package/workflows/container-contents/container-state/purgeTreeContainerDeletion.js.map +0 -1
- package/workflows/container-contents/container-state/purgeTreeScope.js.map +0 -1
- package/workflows/container-contents/container-state/readLocalPurgeScope.js.map +0 -1
- package/workflows/container-contents/container-state/share.js.map +0 -1
- package/workflows/container-contents/container-state/sharePersistence.js.map +0 -1
- package/workflows/container-contents/remoteHydration/childIndex.js.map +0 -1
- package/workflows/container-contents/remoteHydration/containerStateFingerprint.js.map +0 -1
- package/workflows/container-contents/remoteHydration/destinationPrefetch.js.map +0 -1
- package/workflows/container-contents/remoteHydration/destinationRoleCache.js.map +0 -1
- package/workflows/container-contents/remoteHydration/destinationRootReload.js.map +0 -1
- package/workflows/container-contents/remoteHydration/insertRemoteContainer.js.map +0 -1
- package/workflows/container-contents/remoteHydration/laneFetchMarkers.js.map +0 -1
- package/workflows/container-contents/remoteHydration/parentLaneFetch.js.map +0 -1
- package/workflows/container-contents/remoteHydration/parentLaneQueue.js.map +0 -1
- package/workflows/container-contents/remoteHydration/remoteContainerPageHydration.js.map +0 -1
- package/workflows/container-contents/remoteHydration/remoteContainerState.js.map +0 -1
- package/workflows/container-contents/remoteHydration/remoteContainerTimestamps.js.map +0 -1
- package/workflows/container-contents/remoteHydration/replacementBinding.js.map +0 -1
- package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +0 -1
- package/workflows/containers/child/carriedDescendantRekeys.js.map +0 -1
- package/workflows/containers/child/create.js.map +0 -1
- package/workflows/containers/child/createProjection.js.map +0 -1
- package/workflows/containers/child/createSubmission.js.map +0 -1
- package/workflows/containers/child/currentShareGrantMutation.js.map +0 -1
- package/workflows/containers/child/currentSharePrincipalPolicy.js.map +0 -1
- package/workflows/containers/child/move.js.map +0 -1
- package/workflows/containers/child/moveArtifacts.js.map +0 -1
- package/workflows/containers/child/moveRotation.js.map +0 -1
- package/workflows/containers/child/moveWraps.js.map +0 -1
- package/workflows/containers/child/rekey.js.map +0 -1
- package/workflows/containers/child/rekeyProjection.js.map +0 -1
- package/workflows/containers/child/rekeyRemote.js.map +0 -1
- package/workflows/containers/child/replacementPrincipalPolicyReferences.js.map +0 -1
- package/workflows/containers/child/rotationContext.js.map +0 -1
- package/workflows/containers/child/rotationPrincipalPolicies.js.map +0 -1
- package/workflows/containers/child/rotationWraps.js.map +0 -1
- package/workflows/containers/child/runtimeCurrentGroupShare.js.map +0 -1
- package/workflows/containers/child/share.js.map +0 -1
- package/workflows/containers/child/shareAncestorRepair.js.map +0 -1
- package/workflows/containers/child/shareMaterialization.js.map +0 -1
- package/workflows/containers/child/sharePlanCore.js.map +0 -1
- package/workflows/containers/child/sharePrincipalPolicy.js.map +0 -1
- package/workflows/containers/child/shareProjection.js.map +0 -1
- /package/data/keyingProjectionVerification/{containerCreateManifest.js.map → container/containerCreateManifest.js.map} +0 -0
- /package/data/keyingProjectionVerification/{documentContainerProjections.js → document/documentContainerProjections.js} +0 -0
- /package/data/keyingProjectionVerification/{documentContainerProjections.js.map → document/documentContainerProjections.js.map} +0 -0
- /package/data/keyingProjectionVerification/{documentManifestPredecessor.js.map → document/documentManifestPredecessor.js.map} +0 -0
- /package/stores/container-contents/{containerStateMap.js → containerState/containerStateMap.js} +0 -0
- /package/stores/container-contents/{missingSyncedContainerState.js → containerState/missingSyncedContainerState.js} +0 -0
- /package/stores/container-contents/{reconcilableContainer.js → containerState/reconcilableContainer.js} +0 -0
- /package/stores/container-contents/{remoteHydrationRefresh.js → hydration/remoteHydrationRefresh.js} +0 -0
- /package/stores/container-contents/{remoteHydrationRefresh.js.map → hydration/remoteHydrationRefresh.js.map} +0 -0
- /package/stores/container-contents/{emptyTrashOperation.js → operations/emptyTrashOperation.js} +0 -0
- /package/stores/container-contents/{purgeContainerOperation.js → operations/purgeContainerOperation.js} +0 -0
- /package/stores/container-contents/{remoteBackedContainerState.js → remoteEvents/remoteBackedContainerState.js} +0 -0
- /package/stores/container-contents/{writeGeneration.js → remoteWrites/writeGeneration.js} +0 -0
- /package/stores/container-contents/{syncAgentTypes.js → syncAgent/syncAgentTypes.js} +0 -0
- /package/stores/container-contents/{systemContainerLookup.js → systemContainers/systemContainerLookup.js} +0 -0
- /package/stores/documents/documentStore/{attachmentPersistFollowup.js → attachments/attachmentPersistFollowup.js} +0 -0
- /package/stores/documents/documentStore/{attachmentSnapshot.js → attachments/attachmentSnapshot.js} +0 -0
- /package/stores/documents/documentStore/{remoteWork.js → sync/remoteWork.js} +0 -0
- /package/stores/documents/documentStore/{syncAcceptedUpdateIds.js → sync/syncAcceptedUpdateIds.js} +0 -0
- /package/stores/documents/documentStore/{syncGeneration.js → sync/syncGeneration.js} +0 -0
- /package/stores/documents/documentStore/{versionCoverage.js.map → sync/versionCoverage.js.map} +0 -0
- /package/workflows/container-contents/container-state/{createIntentSettlement.js → create/createIntentSettlement.js} +0 -0
- /package/workflows/container-contents/container-state/{purgeProgress.d.ts → purge/purgeProgress.d.ts} +0 -0
- /package/workflows/container-contents/container-state/{purgeProgress.js → purge/purgeProgress.js} +0 -0
- /package/workflows/container-contents/container-state/{purgeProgress.js.map → purge/purgeProgress.js.map} +0 -0
- /package/workflows/container-contents/container-state/{purgeTreeCollection.js → purge/purgeTreeCollection.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{destinationPrefetch.js → destination/destinationPrefetch.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{destinationRoleCache.js → destination/destinationRoleCache.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{childIndex.js → lanes/childIndex.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{parentLaneQueue.js → lanes/parentLaneQueue.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{containerStateFingerprint.js → remoteContainers/containerStateFingerprint.js} +0 -0
- /package/workflows/container-contents/remoteHydration/{remoteContainerTimestamps.js → remoteContainers/remoteContainerTimestamps.js} +0 -0
- /package/workflows/containers/child/{keyringOverrideLineage.js.map → rekey/keyringOverrideLineage.js.map} +0 -0
- /package/workflows/containers/child/{shareProjection.js → share/shareProjection.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentSourceUpload.js","sourceRoot":"","sources":["attachmentSourceUpload.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAClB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AA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AK,CAAC;YAAE,OAAO,IAAI,CAAC;QACxD,IAAI,KAAK,CAAC,iBAAiB,CAAC,aAAa,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAChD,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,iBAAiB,EACvB,QAAQ,CAAC,MAAM,EACf,KAAK,CAAC,oBAAoB,CAC3B,CAAC;QACF,MAAM,iBAAiB,GACrB,MAAM,CAAC,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;QAC9D,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACxD,IAAI,iBAAiB,KAAK,QAAQ,CAAC,SAAS,EAAE,CAAC;YAC7C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC;QACD,SAAS,GAAG,iBAAiB,CAAC;IAChC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import {\n type BlobSourceSnapshot,\n inspectBlobSource,\n} from \"../../../data/documents/blob/shared/blobSourceSnapshot\";\nimport { DEFAULT_BLOB_CHUNK_SIZE_BYTES } from \"../../../data/documents/blob/shared/crypto\";\nimport { getDocumentAttachments } from \"../../../data/documents/documentContent\";\nimport type { BlobByteSource } from \"../../../workflows/blobs\";\nimport type { PendingAttachmentRecord } from \"../../../workflows/documents\";\nimport { deletePendingAttachment } from \"./attachmentPersistence\";\nimport {\n type AttachmentUploadResume,\n resolveAttachmentUploadResume,\n} from \"./attachmentUploadResume\";\nimport type { DocumentStoreState } from \"./state\";\nimport type { DocumentStoreSyncGeneration } from \"./syncGeneration\";\n\ninterface PendingSourceInput {\n attachmentGeneration: DocumentStoreSyncGeneration;\n pendingAttachment: PendingAttachmentRecord;\n state: DocumentStoreState;\n}\n\nexport function pendingAttachmentMatchesIntent(\n input: PendingSourceInput,\n): boolean {\n return (\n input.state.doc !== null &&\n getDocumentAttachments(input.state.doc).some(\n (item) =>\n item.slotId === input.pendingAttachment.slotId &&\n item.contentSha256 === input.pendingAttachment.contentSha256,\n )\n );\n}\n\nexport async function dropUnavailablePendingAttachment(\n input: PendingSourceInput,\n): Promise<\"dropped\"> {\n const { state, pendingAttachment, attachmentGeneration } = input;\n // Unusable bytes or superseded intent cannot be retried. Delete only this\n // storage identity so a concurrently queued replacement survives.\n state.runtime.util.log(\n `Documents: dropping pending attachment ${pendingAttachment.slotId}; its bytes are unavailable or changed, or its content intent was superseded.`,\n );\n await deletePendingAttachment(\n state,\n pendingAttachment.slotId,\n pendingAttachment.storageKey,\n attachmentGeneration,\n );\n return \"dropped\";\n}\n\nexport async function resolveAttachmentSourceUpload(\n input: PendingSourceInput & {\n source: BlobByteSource;\n },\n): Promise<{\n readonly resume: AttachmentUploadResume;\n readonly snapshot: BlobSourceSnapshot;\n} | null> {\n let chunkSize =\n input.pendingAttachment.upload?.partSize ?? DEFAULT_BLOB_CHUNK_SIZE_BYTES;\n\n for (let attempt = 0; attempt < 3; attempt += 1) {\n const snapshot = await inspectBlobSource(input.source, chunkSize);\n if (!pendingAttachmentMatchesIntent(input)) return null;\n if (input.pendingAttachment.contentSha256 !== snapshot.sha256) {\n return null;\n }\n const resume = await resolveAttachmentUploadResume(\n input.state,\n input.pendingAttachment,\n snapshot.sha256,\n input.attachmentGeneration,\n );\n const resolvedChunkSize =\n resume.multipart?.partSize ?? DEFAULT_BLOB_CHUNK_SIZE_BYTES;\n if (!pendingAttachmentMatchesIntent(input)) return null;\n if (resolvedChunkSize === snapshot.chunkSize) {\n return { resume, snapshot };\n }\n chunkSize = resolvedChunkSize;\n }\n\n throw new Error(\"Blob source changed while preparing its upload identity\");\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentStaging.js","sourceRoot":"","sources":["attachmentStaging.ts"],"names":[],"mappings":"AAAA,OAAO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jE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,2BAA2B,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createBlobByteSource } from \"../../../workflows/blobs\";\nimport {\n type AttachmentStagingRows,\n type LocalAttachmentRecord,\n type PendingAttachmentRecord,\n runSerializedDocumentBlobMutation,\n runSerializedSqlMutation,\n} from \"../../../workflows/documents\";\nimport type { DocumentAttachmentUpload } from \"../types\";\nimport {\n assignLocalAttachmentSlots,\n upsertPendingAttachments,\n} from \"./attachmentPersistence\";\nimport { type DocumentStoreState, setReadySnapshot } from \"./state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\ninterface StagePendingAttachmentsInput {\n files: ReadonlyArray<DocumentAttachmentUpload>;\n generation: DocumentStoreSyncGeneration;\n pendingAttachments: PendingAttachmentRecord[];\n state: DocumentStoreState;\n}\n\nfunction localAttachmentRecords(\n localId: string,\n pendingAttachments: ReadonlyArray<PendingAttachmentRecord>,\n): LocalAttachmentRecord[] {\n return pendingAttachments.map((pendingAttachment) => ({\n blobId: null,\n byteLength: pendingAttachment.byteLength,\n contentSha256: pendingAttachment.contentSha256,\n detachedAt: null,\n localId,\n mimeType: pendingAttachment.mimeType,\n slotId: pendingAttachment.slotId,\n storageKey: pendingAttachment.storageKey,\n }));\n}\n\nasync function deleteStagedAttachmentBytes(input: {\n pendingAttachments: ReadonlyArray<PendingAttachmentRecord>;\n state: DocumentStoreState;\n}) {\n const { state } = input;\n const cleanupResults = await Promise.allSettled(\n input.pendingAttachments.map((attachment) =>\n state.runtime.infra.blobStore.deleteBytes(attachment.storageKey),\n ),\n );\n const failedCleanupCount = cleanupResults.filter(\n (result) => result.status === \"rejected\",\n ).length;\n if (failedCleanupCount > 0) {\n state.runtime.util.log(\n `Documents: failed to roll back ${failedCleanupCount} staged attachment operation${failedCleanupCount === 1 ? \"\" : \"s\"}.`,\n );\n }\n}\n\n/**\n * Roll back staged bytes that no committed row references. Like orphan\n * reclaim, check every held and pending reference under the key's lock: an\n * overlapping reset can leave a committed key referenced only by an upload.\n */\nexport async function deleteUnreferencedStagedAttachmentBytes(input: {\n generation: DocumentStoreSyncGeneration;\n pendingAttachments: ReadonlyArray<PendingAttachmentRecord>;\n state: DocumentStoreState;\n}): Promise<void> {\n const { execSql } = input.generation;\n const { state } = input;\n let failedCleanupCount = 0;\n for (const { storageKey } of input.pendingAttachments) {\n try {\n await runSerializedDocumentBlobMutation(execSql, storageKey, async () => {\n const referenced = await runSerializedSqlMutation(\n execSql,\n (lockedExecSql) =>\n state.persistence.orphanBlobs.isReferenced(\n lockedExecSql,\n storageKey,\n ),\n );\n if (!referenced)\n await state.runtime.infra.blobStore.deleteBytes(storageKey);\n });\n } catch {\n // A failed probe cannot prove that the atomic mutation rolled back, so\n // the bytes stay; a failed delete leaves them for a later sweep.\n failedCleanupCount += 1;\n }\n }\n if (failedCleanupCount > 0)\n state.runtime.util.log(\n `Documents: failed to roll back ${failedCleanupCount} staged attachment operation${failedCleanupCount === 1 ? \"\" : \"s\"}.`,\n );\n}\n\nasync function writePendingAttachmentBytes(\n input: StagePendingAttachmentsInput,\n): Promise<void> {\n for (const [index, pendingAttachment] of input.pendingAttachments.entries()) {\n const sourceFile = input.files[index];\n if (!sourceFile) continue;\n await input.state.runtime.infra.blobStore.writeByteSource(\n pendingAttachment.storageKey,\n createBlobByteSource(sourceFile.bytes),\n );\n }\n}\n\nexport function installPendingAttachmentRows(input: {\n localAttachments: ReadonlyArray<LocalAttachmentRecord>;\n pendingAttachments: ReadonlyArray<PendingAttachmentRecord>;\n state: DocumentStoreState;\n}): void {\n const { localAttachments, pendingAttachments, state } = input;\n assignLocalAttachmentSlots(state, localAttachments);\n upsertPendingAttachments(state, pendingAttachments);\n if (state.doc) {\n setReadySnapshot(\n state,\n state.doc,\n state.snapshot.syncing,\n state.snapshot.text,\n state.snapshot.structuredFields,\n );\n }\n}\n\nexport async function stagePendingAttachments(\n input: StagePendingAttachmentsInput,\n): Promise<AttachmentStagingRows | null> {\n const { pendingAttachments, state } = input;\n const localAttachments = localAttachmentRecords(\n state.localId,\n pendingAttachments,\n );\n\n try {\n await writePendingAttachmentBytes(input);\n\n if (!isDocumentStoreSyncGenerationCurrent(state, input.generation)) {\n await deleteStagedAttachmentBytes({ pendingAttachments, state });\n return null;\n }\n return { localAttachments, pendingAttachments };\n } catch (error) {\n await deleteStagedAttachmentBytes({ pendingAttachments, state });\n throw error;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentUploadAttempt.js","sourceRoot":"","sources":["attachmentUploadAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAAE,gCAAgC,IAAI,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAG/G,MAAM,CAAC,KAAK,UAAU,yCAAyC,CAAC,KAI/D;IAKC,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,qBAAyC,CAAC;IAC9C,IAAI,sBAES,CAAC;IACd,MAAM,eAAe,GAAG,KAAK,EAAE,KAG9B,EAAE,EAAE;QACH,sBAAsB,GAAG,KAAK,CAAC;QAC/B,MAAM,KAAK,CAAC,eAAe,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC,CAAC;IACF,MAAM,eAAe,GAAG;QACtB,GAAG,KAAK,CAAC,eAAe;QACxB,mBAAmB,EAAE,CAAC,cAAsB,EAAE,EAAE;YAC9C,qBAAqB,GAAG,cAAc,CAAC;YACvC,iBAAiB;gBACf,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,m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,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport { uploadPreparedDocumentAttachment as uploadDocumentAttachment } from \"../../../workflows/blobs/upload\";\nimport type { DocumentStoreState } from \"./state\";\n\nexport async function uploadAttachmentWithWriterProjectionRetry(input: {\n baseUploadInput: Parameters<typeof uploadDocumentAttachment>[0];\n state: DocumentStoreState;\n writerProjection: DocumentStoreState[\"writerProjection\"];\n}): Promise<{\n error: unknown;\n remoteSyncBlocked: boolean;\n uploaded: Awaited<ReturnType<typeof uploadDocumentAttachment>>;\n}> {\n let remoteSyncBlocked = false;\n let checkedOrganizationId: string | undefined;\n let resolvedMultipartStage:\n | { readonly partSize: number; readonly stageId: string }\n | undefined;\n const onStageResolved = async (stage: {\n readonly partSize: number;\n readonly stageId: string;\n }) => {\n resolvedMultipartStage = stage;\n await input.baseUploadInput.onStageResolved?.(stage);\n };\n const baseUploadInput = {\n ...input.baseUploadInput,\n isRemoteSyncBlocked: (organizationId: string) => {\n checkedOrganizationId = organizationId;\n remoteSyncBlocked =\n input.state.runtime.util.isRemoteSyncBlocked?.(organizationId) ?? false;\n return remoteSyncBlocked;\n },\n onStageResolved,\n };\n let uploadError: unknown;\n let uploadThrew = false;\n let uploaded = await tryUploadDocumentAttachment({\n documentId: input.state.record?.documentId ?? input.state.localId,\n input: {\n ...baseUploadInput,\n writerProjection: input.writerProjection ?? undefined,\n },\n onError: (error) => {\n uploadThrew = true;\n uploadError = error;\n },\n reportSecurityIncident: input.state.runtime.util.reportSecurityIncident,\n });\n if (!uploaded && checkedOrganizationId !== undefined) {\n // The request itself may have produced the first 402 after the workflow's\n // preflight check. Re-read the same verified manifest org so that response\n // is treated as a billing pause even when there was no cached projection\n // available to trigger the retry path below.\n remoteSyncBlocked ||=\n input.state.runtime.util.isRemoteSyncBlocked?.(checkedOrganizationId) ??\n false;\n }\n if (\n !uploaded &&\n input.writerProjection &&\n !remoteSyncBlocked &&\n !uploadThrew\n ) {\n // A stale cached writer projection may have caused an ambiguous null. Retry\n // once with a fresh projection, but do not immediately replay a concrete\n // thrown failure or an expected billing pause.\n input.state.writerProjection = null;\n // Binding can return null after multipart staging succeeded. Carry that\n // resolved stage into the retry so it is resumed instead of orphaned.\n const retryUploadInput = resolvedMultipartStage\n ? {\n ...baseUploadInput,\n multipart: {\n ...(baseUploadInput.multipart ?? {}),\n partSize: resolvedMultipartStage.partSize,\n resumeStageId: resolvedMultipartStage.stageId,\n },\n }\n : baseUploadInput;\n uploaded = await tryUploadDocumentAttachment({\n documentId: input.state.record?.documentId ?? input.state.localId,\n input: retryUploadInput,\n onError: (error) => {\n uploadError = error;\n },\n reportSecurityIncident: input.state.runtime.util.reportSecurityIncident,\n });\n if (!uploaded && checkedOrganizationId !== undefined) {\n remoteSyncBlocked ||=\n input.state.runtime.util.isRemoteSyncBlocked?.(checkedOrganizationId) ??\n false;\n }\n }\n\n if (remoteSyncBlocked) {\n uploadError = undefined;\n }\n return { error: uploadError, remoteSyncBlocked, uploaded };\n}\n\nasync function tryUploadDocumentAttachment(input: {\n documentId: string;\n input: Parameters<typeof uploadDocumentAttachment>[0];\n onError: (error: unknown) => void;\n reportSecurityIncident: DocumentStoreState[\"runtime\"][\"util\"][\"reportSecurityIncident\"];\n}): ReturnType<typeof uploadDocumentAttachment> {\n try {\n return await uploadDocumentAttachment(input.input);\n } catch (error) {\n await reportAndRethrowKeyingVerificationError(\n error,\n input.reportSecurityIncident,\n {\n objectId: input.documentId,\n objectKind: \"document\",\n operation: \"document.attachment.upload\",\n },\n );\n input.onError(error);\n return null;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentUploadLane.js","sourceRoot":"","sources":["attachmentUploadLane.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AASjC,SAAS,4BAA4B,CAAC,IAA+B;IACnE,OA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,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QACD,aAAa,CAAC,KAAc;YAC1B,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,mBAAmB,CAAC,QAAQ;YAC1B,UAAU,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { DomainScope } from \"../../../data/shared/domainScope\";\nimport type { MultipartUploadProgressListener } from \"../../../workflows/blobs\";\nimport type { PendingAttachmentRecord } from \"../../../workflows/documents\";\nimport {\n beginDomainSyncUploadLane,\n type UploadSyncLane,\n} from \"../../../workflows/sync\";\n\nexport interface AttachmentUploadLaneReporter {\n complete: () => void;\n fail: (error: unknown) => void;\n failIfStarted: (error: unknown) => void;\n onMultipartProgress: MultipartUploadProgressListener;\n}\n\nfunction getAttachmentUploadLaneLabel(name: string | null | undefined): string {\n return name ? `Upload ${name}` : \"Attachment upload\";\n}\n\nfunction getAttachmentUploadFailureTarget(\n pendingAttachment: PendingAttachmentRecord,\n): string {\n return pendingAttachment.name\n ? `${pendingAttachment.name} (slot ${pendingAttachment.slotId})`\n : `slot ${pendingAttachment.slotId}`;\n}\n\nexport function createAttachmentUploadFailedError(\n pendingAttachment: PendingAttachmentRecord,\n cause: unknown,\n): Error {\n const error = new Error(\n `Attachment upload failed for ${getAttachmentUploadFailureTarget(pendingAttachment)}.`,\n );\n if (cause !== undefined) Reflect.set(error, \"cause\", cause);\n\n return error;\n}\n\n/**\n * Surfaces attachment uploads as observational lanes. The persisted blob id is\n * the lane identity: slot ids repeat across documents, while a retry must keep\n * updating the same row. Lane creation stays lazy until progress, failure, or\n * completion so a billing block before any upload work does not add noise.\n */\nexport function createAttachmentUploadLaneReporter(input: {\n blobId: string;\n domainScope: DomainScope;\n pendingAttachment: PendingAttachmentRecord;\n}): AttachmentUploadLaneReporter {\n const { blobId, domainScope, pendingAttachment } = input;\n const laneRef: { current: UploadSyncLane | null } = { current: null };\n\n const ensureLane = (): UploadSyncLane => {\n laneRef.current ??= beginDomainSyncUploadLane(\n domainScope,\n `blob-upload:${blobId}`,\n {\n blobStorageKey: pendingAttachment.storageKey,\n label: getAttachmentUploadLaneLabel(pendingAttachment.name),\n },\n );\n return laneRef.current;\n };\n\n return {\n complete() {\n // Completion must create/re-begin the lane too: a resumed stage can\n // already be complete before it emits any per-part callbacks.\n ensureLane().complete();\n },\n fail(error: unknown) {\n ensureLane().fail(error);\n },\n failIfStarted(error: unknown) {\n laneRef.current?.fail(error);\n },\n onMultipartProgress(progress) {\n ensureLane().reportProgress(progress);\n },\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentUploadResume.js","sourceRoot":"","sources":["attachmentUploadResume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAEL,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAE1B,SAAS,2BAA2B,CAClC,eAAuB;IAEvB,2EAA2E;IAC3E,4EAA4E;IAC5E,6EAA6E;IAC7E,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE;QAC3B,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,eAAe,EAAE,CAAC;QAClB,SAAS,EAAE,aAAa,CAAC,cAAc,EAAE,CAAC;QAC1C,QAAQ,EAAE,IAAI;QACd,eAAe;QACf,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAeD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,KAAyB,EACzB,iBAA0C,EAC1C,eAAuB,E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Ae,CAAC,CAAC;YACxE,MAAM,2BAA2B,CAC/B,KAAK,EACL,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,EAAE,EACpD,oBAAoB,CACrB,CAAC;YACF,IAAI,oCAAoC,CAAC,KAAK,EAAE,oBAAoB,CAAC,EAAE,CAAC;gBACtE,iBAAiB,CAAC,MAAM,GAAG,kBAAkB,CAAC;YAChD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createAesGcmIv } from \"@tearleads/crypto\";\nimport { base64ToBytes, bytesToBase64 } from \"@tearleads/encoding\";\nimport type { MultipartStageResolvedListener } from \"../../../workflows/blobs\";\nimport type {\n PendingAttachmentRecord,\n PendingAttachmentUploadIdentity,\n} from \"../../../workflows/documents\";\nimport { savePendingAttachmentUpload } from \"./attachmentPersistence\";\nimport type { DocumentStoreState } from \"./state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\nfunction createPendingUploadIdentity(\n plaintextSha256: string,\n): PendingAttachmentUploadIdentity {\n // Generated once and persisted before the first upload attempt. The source\n // digest derives an envelope IV from this seed, then each chunk derives its\n // IV. Reusing the material for unchanged bytes makes retries byte-identical.\n return {\n blobId: crypto.randomUUID(),\n contentKey: bytesToBase64(crypto.getRandomValues(new Uint8Array(32))),\n contentKeyEpoch: 1,\n nonceSeed: bytesToBase64(createAesGcmIv()),\n partSize: null,\n plaintextSha256,\n stageId: null,\n };\n}\n\nexport interface AttachmentUploadResume {\n readonly blobId: string;\n readonly contentKey: Uint8Array;\n readonly contentKeyEpoch: number;\n readonly nonceSeed: Uint8Array;\n readonly multipart: { partSize: number; resumeStageId: string } | undefined;\n readonly onStageResolved: MultipartStageResolvedListener;\n readonly onStageUnavailable: (\n stageId: string,\n documentId: string,\n ) => Promise<void>;\n}\n\n/**\n * Resolve and persist stable encryption and multipart inputs across retries.\n *\n * Every persist here is an UPSERT of the pending-attachment row, so each one\n * is generation-gated: a store teardown (reset/discard) deletes that row on\n * purpose, and a stale resume racing it would otherwise re-insert the row it\n * just removed. Skipping the persist only costs retry resumability.\n */\nexport async function resolveAttachmentUploadResume(\n state: DocumentStoreState,\n pendingAttachment: PendingAttachmentRecord,\n plaintextSha256: string,\n attachmentGeneration: DocumentStoreSyncGeneration,\n): Promise<AttachmentUploadResume> {\n let uploadIdentity =\n pendingAttachment.upload?.plaintextSha256 === plaintextSha256\n ? pendingAttachment.upload\n : createPendingUploadIdentity(plaintextSha256);\n if (\n pendingAttachment.upload !== uploadIdentity &&\n isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration)\n ) {\n await savePendingAttachmentUpload(\n state,\n { ...pendingAttachment, upload: uploadIdentity },\n attachmentGeneration,\n );\n if (isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration)) {\n pendingAttachment.upload = uploadIdentity;\n }\n }\n\n const multipart =\n uploadIdentity.stageId !== null && uploadIdentity.partSize !== null\n ? {\n partSize: uploadIdentity.partSize,\n resumeStageId: uploadIdentity.stageId,\n }\n : undefined;\n const onStageResolved: MultipartStageResolvedListener = async ({\n partSize,\n stageId,\n }) => {\n if (\n uploadIdentity.stageId === stageId &&\n uploadIdentity.partSize === partSize\n ) {\n return;\n }\n if (!isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration)) {\n return;\n }\n const nextUploadIdentity = { ...uploadIdentity, partSize, stageId };\n await savePendingAttachmentUpload(\n state,\n { ...pendingAttachment, upload: nextUploadIdentity },\n attachmentGeneration,\n );\n if (isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration)) {\n // Publish only after persistence succeeds: a failed save must leave the\n // next attempt responsible for making this identity durable.\n uploadIdentity = nextUploadIdentity;\n pendingAttachment.upload = nextUploadIdentity;\n }\n };\n\n return {\n blobId: uploadIdentity.blobId,\n contentKey: base64ToBytes(uploadIdentity.contentKey),\n contentKeyEpoch: uploadIdentity.contentKeyEpoch,\n nonceSeed: base64ToBytes(uploadIdentity.nonceSeed),\n multipart,\n onStageResolved,\n onStageUnavailable: async (stageId, documentId) => {\n if (\n !isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration) ||\n pendingAttachment.upload?.stageId !== stageId\n )\n return;\n // Recheck after the ambiguous bind, including an immediate projection\n // retry in this pass. A still-active commit must retain its identity for\n // normal adoption on the next pass; a failed read proves nothing.\n const bindings = await state.runtime.apiClient.listDocumentAttachments(\n documentId,\n { refresh: true },\n );\n if (!bindings) throw new Error(\"Attachment recovery lookup failed.\");\n if (\n !isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration) ||\n pendingAttachment.upload?.stageId !== stageId ||\n bindings.some(\n (binding) =>\n binding.slotId === pendingAttachment.slotId &&\n binding.blobId === uploadIdentity.blobId,\n )\n )\n return;\n // A missing stage may have been consumed by a committed bind whose\n // response was lost and whose slot was subsequently replaced/detached.\n // That blob id is permanently reserved, so a replacement stage must use\n // fresh crypto material and an id persisted before any bytes are sent.\n const nextUploadIdentity = createPendingUploadIdentity(plaintextSha256);\n await savePendingAttachmentUpload(\n state,\n { ...pendingAttachment, upload: nextUploadIdentity },\n attachmentGeneration,\n );\n if (isDocumentStoreSyncGenerationCurrent(state, attachmentGeneration)) {\n pendingAttachment.upload = nextUploadIdentity;\n }\n },\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentWriteGeneration.js","sourceRoot":"","sources":["attachmentWriteGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AAEjF,OAAO,EAEL,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAO1B,MAAM,UAAU,gCAAgC,CAC9C,KAAyB;IAEzB,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC/B,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;QACnC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,KAAyB,EACzB,UAAqC;IAErC,OAAO,CACL,KAAK,CAAC,oBAAoB,KAAK,UAAU,CAAC,oBAAoB;QAC9D,KAAK,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,UAAU,CACnD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oCAAoC,CAClD,KAAyB,EACzB,eAA0C,EAC1C,cAA2C,EAC3C,SAAyC;IAEzC,IACE,kCAAkC,CAAC;QACjC,iBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU;QAC3C,2BAA2B,EAAE,KAAK,CAAC,oBAAoB;QACvD,kBAAkB,EAAE,eAAe,CAAC,UAAU;QAC9C,4BAA4B,EAAE,eAAe,CAAC,oBAAoB;QAClE,SAAS;KACV,CAAC,EACF,CAAC;QACD,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAE5B,OAAO,CACL,SAAS,CAAC,0BAA0B,KAAK,IAAI;QAC7C,SAAS,CAAC,sBAAsB,KAAK,IAAI;QACzC,CAAC,oCAAoC,CAAC,KAAK,EAAE,cAAc,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import { requestDocumentStoreSync } from \"../registry\";\nimport { attachmentPersistNeedsFollowupSync } from \"./attachmentPersistFollowup\";\nimport type { DocumentStoreState, PersistedDocumentRecord } from \"./state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\nexport interface AttachmentWriteGeneration {\n documentId: string | null;\n localWriteGeneration: number;\n}\n\nexport function captureAttachmentWriteGeneration(\n state: DocumentStoreState,\n): AttachmentWriteGeneration | null {\n if (!state.record) return null;\n return {\n documentId: state.record.documentId,\n localWriteGeneration: state.localWriteGeneration,\n };\n}\n\nexport function isAttachmentWriteGenerationCurrent(\n state: DocumentStoreState,\n generation: AttachmentWriteGeneration,\n): boolean {\n return (\n state.localWriteGeneration === generation.localWriteGeneration &&\n state.record?.documentId === generation.documentId\n );\n}\n\nexport function shouldAbortAttachmentPersistFollowup(\n state: DocumentStoreState,\n writeGeneration: AttachmentWriteGeneration,\n syncGeneration: DocumentStoreSyncGeneration,\n persisted: PersistedDocumentRecord | null,\n): boolean {\n if (\n attachmentPersistNeedsFollowupSync({\n currentDocumentId: state.record?.documentId,\n currentLocalWriteGeneration: state.localWriteGeneration,\n expectedDocumentId: writeGeneration.documentId,\n expectedLocalWriteGeneration: writeGeneration.localWriteGeneration,\n persisted,\n })\n ) {\n requestDocumentStoreSync(state);\n }\n if (!persisted) return true;\n\n return (\n persisted.pullContinuationSuperseded === true ||\n persisted.syncIdentitySuperseded === true ||\n !isDocumentStoreSyncGenerationCurrent(state, syncGeneration)\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachments.js","sourceRoot":"","sources":["attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAEjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,gCAAgC,EAChC,kCAAkC,EAClC,oCAAoC,GACrC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MA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AAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO;IACT,CAAC;IAED,MAAM,eAAe,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAChE,IAAI,CAAC,eAAe;QAAE,OAAO;IAC7B,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU;SAChC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;SACtB,IAAI,CAAC,KAAK,IAAI,EAAE,CACf,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAChE;SACA,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxB,+BAA+B,CAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IACL,OAAO,KAAK,CAAC,UAAU,CAAC;AAC1B,CAAC","sourcesContent":["import {\n encodeVersionVector,\n exportFullHistorySnapshot,\n} from \"@tearleads/loro\";\nimport { addDocumentAttachments } from \"../../../data/documents/documentContent\";\nimport type { PendingAttachmentRecord } from \"../../../workflows/documents\";\nimport { requestDocumentStoreSync } from \"../registry\";\nimport type { DocumentAttachmentUpload } from \"../types\";\nimport {\n buildAttachmentIntent,\n buildPendingAttachments,\n} from \"./attachmentIntents\";\nimport {\n persistStagedAttachmentMutation,\n restoreFailedAttachmentMutation,\n} from \"./attachmentMutationPersistence\";\nimport {\n deleteUnreferencedStagedAttachmentBytes,\n installPendingAttachmentRows,\n stagePendingAttachments,\n} from \"./attachmentStaging\";\nimport {\n type AttachmentWriteGeneration,\n captureAttachmentWriteGeneration,\n isAttachmentWriteGenerationCurrent,\n shouldAbortAttachmentPersistFollowup,\n} from \"./attachmentWriteGeneration\";\nimport { settleDeferredInitialUpdate } from \"./deferredInitialUpdate\";\nimport { ensureDocumentStoreReady } from \"./initialization\";\nimport {\n advancePendingBaseVersion,\n pendingDeltaSinceBase,\n} from \"./persistence\";\nimport { reportDocumentStoreWriteFailure } from \"./reportWriteFailure\";\nimport {\n canAttachFiles,\n canWriteDocument,\n type DocumentStoreState,\n} from \"./state\";\nimport { captureDocumentStoreSyncGeneration } from \"./syncGeneration\";\n\n// Fixed literal: a reported message must never carry file names or slot ids.\nexport const ATTACHMENT_FAILURE_MESSAGE =\n \"Documents: attachment mutation failed\";\n\nfunction logAttachedFiles(state: DocumentStoreState, count: number) {\n state.runtime.util.log(\n state.runtime.state.online && state.runtime.auth.isAuthenticated\n ? `Attached ${count} file${count === 1 ? \"\" : \"s\"} to document ${state.localId}.`\n : `Stored ${count} attachment${count === 1 ? \"\" : \"s\"} locally for document ${state.localId}.`,\n );\n}\n\nasync function persistAttachedFiles(\n state: DocumentStoreState,\n files: ReadonlyArray<DocumentAttachmentUpload>,\n writeGeneration: AttachmentWriteGeneration,\n) {\n if (!isAttachmentWriteGenerationCurrent(state, writeGeneration)) return;\n const currentDoc = state.doc;\n\n if (!currentDoc || !canAttachFiles(state)) {\n state.runtime.util.log(\n \"Documents: attachments require a local key package.\",\n );\n return;\n }\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation) {\n return;\n }\n\n const { nextAttachments, nextPendingAttachments } =\n await buildPendingAttachments(state.localId, files);\n if (\n !isAttachmentWriteGenerationCurrent(state, writeGeneration) ||\n state.doc !== currentDoc\n )\n return;\n const rollbackSnapshot = exportFullHistorySnapshot(currentDoc).slice();\n addDocumentAttachments(currentDoc, nextAttachments);\n const attachmentUpdate = pendingDeltaSinceBase(state, currentDoc);\n // Captured at delta time: the enqueued row proves coverage up to exactly\n // this version, so it is the frontier the persist below may publish.\n const coveredVersion = encodeVersionVector(currentDoc);\n\n let staged: Awaited<ReturnType<typeof stagePendingAttachments>>;\n try {\n staged = await stagePendingAttachments({\n files,\n generation,\n pendingAttachments: nextPendingAttachments,\n state,\n });\n } catch (error) {\n await restoreFailedAttachmentMutation({\n generation,\n rollbackSnapshot,\n state,\n });\n throw error;\n }\n if (!staged) {\n await restoreFailedAttachmentMutation({\n generation,\n rollbackSnapshot,\n state,\n });\n return;\n }\n // This persist changes attachments, not prose. setReadySnapshot always\n // re-derives attachments from the doc, but preserve the text/structured\n // fields so an attach that overlaps an in-flight keystroke does not republish\n // a stale doc read over the live optimistic editor value.\n const persisted = await persistStagedAttachmentMutation({\n attachmentUpdate,\n coveredVersion,\n currentDoc,\n generation,\n rollbackSnapshot,\n staged,\n state,\n });\n if (\n shouldAbortAttachmentPersistFollowup(\n state,\n writeGeneration,\n generation,\n persisted,\n )\n ) {\n await deleteUnreferencedStagedAttachmentBytes({\n generation,\n pendingAttachments: staged.pendingAttachments,\n state,\n });\n return;\n }\n installPendingAttachmentRows({ ...staged, state });\n advancePendingBaseVersion(state, currentDoc);\n logAttachedFiles(state, files.length);\n requestDocumentStoreSync(state);\n}\n\nasync function persistSlotAttachmentFile(\n state: DocumentStoreState,\n slotId: string,\n file: DocumentAttachmentUpload,\n writeGeneration: AttachmentWriteGeneration,\n) {\n if (!isAttachmentWriteGenerationCurrent(state, writeGeneration)) return;\n const currentDoc = state.doc;\n\n if (!currentDoc || !canAttachFiles(state)) {\n state.runtime.util.log(\n \"Documents: slot attachments require a local key package.\",\n );\n return;\n }\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation) {\n return;\n }\n\n const replacementAttachment = await buildAttachmentIntent(slotId, file);\n if (\n !isAttachmentWriteGenerationCurrent(state, writeGeneration) ||\n state.doc !== currentDoc\n )\n return;\n const rollbackSnapshot = exportFullHistorySnapshot(currentDoc).slice();\n addDocumentAttachments(currentDoc, [replacementAttachment]);\n const attachmentUpdate = pendingDeltaSinceBase(state, currentDoc);\n const coveredVersion = encodeVersionVector(currentDoc);\n\n const storageKey = `${state.localId}-${slotId}-${crypto.randomUUID()}`;\n const pendingAttachment: PendingAttachmentRecord = {\n byteLength: replacementAttachment.byteLength,\n contentSha256: replacementAttachment.contentSha256,\n localId: state.localId,\n mimeType: replacementAttachment.mimeType,\n name: replacementAttachment.name,\n slotId,\n storageKey,\n };\n let staged: Awaited<ReturnType<typeof stagePendingAttachments>>;\n try {\n staged = await stagePendingAttachments({\n files: [file],\n generation,\n pendingAttachments: [pendingAttachment],\n state,\n });\n } catch (error) {\n await restoreFailedAttachmentMutation({\n generation,\n rollbackSnapshot,\n state,\n });\n throw error;\n }\n if (!staged) {\n await restoreFailedAttachmentMutation({\n generation,\n rollbackSnapshot,\n state,\n });\n return;\n }\n // Preserve the optimistic text/structured fields (see persistAttachedFiles):\n // a slot replacement overlapping a keystroke must not regress the editor.\n const persisted = await persistStagedAttachmentMutation({\n attachmentUpdate,\n coveredVersion,\n currentDoc,\n generation,\n rollbackSnapshot,\n staged,\n state,\n });\n if (\n shouldAbortAttachmentPersistFollowup(\n state,\n writeGeneration,\n generation,\n persisted,\n )\n ) {\n await deleteUnreferencedStagedAttachmentBytes({\n generation,\n pendingAttachments: staged.pendingAttachments,\n state,\n });\n return;\n }\n installPendingAttachmentRows({ ...staged, state });\n advancePendingBaseVersion(state, currentDoc);\n state.runtime.util.log(`Queued attachment ${file.name} for slot ${slotId}.`);\n requestDocumentStoreSync(state);\n}\n\nasync function captureReadyAttachWrite(\n state: DocumentStoreState,\n scheduleSync: () => void,\n callGeneration: AttachmentWriteGeneration | null,\n) {\n let ready: boolean;\n try {\n ready = await ensureDocumentStoreReady(state, scheduleSync);\n } catch (error) {\n reportDocumentStoreWriteFailure(state, ATTACHMENT_FAILURE_MESSAGE, error);\n return null;\n }\n if (!ready || !state.doc || !canWriteDocument(state)) return null;\n // A reset or relink while this call waited owns the replacement document.\n if (\n callGeneration &&\n !isAttachmentWriteGenerationCurrent(state, callGeneration)\n ) {\n return null;\n }\n return captureAttachmentWriteGeneration(state);\n}\n\nasync function attachThenSettle(\n state: DocumentStoreState,\n scheduleSync: () => void,\n files: ReadonlyArray<DocumentAttachmentUpload>,\n callGeneration: AttachmentWriteGeneration | null,\n) {\n const writeGeneration =\n files.length === 0\n ? null\n : await captureReadyAttachWrite(state, scheduleSync, callGeneration);\n try {\n if (writeGeneration) {\n await persistAttachedFiles(state, files, writeGeneration);\n }\n } finally {\n await settleDeferredInitialUpdate(state, writeGeneration);\n }\n}\n\nexport async function attachFilesToDocumentStore(\n state: DocumentStoreState,\n scheduleSync: () => void,\n files: ReadonlyArray<DocumentAttachmentUpload>,\n) {\n // Join the chain before awaiting readiness so settlements keep call order,\n // and settle even when nothing attaches: a deferred birth's sync hold lifts\n // only behind every earlier attach, never while one is still staging. The\n // caller's document is captured now (a cold store captures once ready).\n const callGeneration = captureAttachmentWriteGeneration(state);\n state.writeChain = state.writeChain\n .catch(() => undefined)\n .then(async () =>\n attachThenSettle(state, scheduleSync, files, callGeneration),\n )\n .catch((error: unknown) => {\n reportDocumentStoreWriteFailure(state, ATTACHMENT_FAILURE_MESSAGE, error);\n });\n return state.writeChain;\n}\n\nexport async function replaceAttachmentInDocumentStore(\n state: DocumentStoreState,\n scheduleSync: () => void,\n slotId: string,\n file: DocumentAttachmentUpload,\n) {\n let ready: boolean;\n try {\n ready = await ensureDocumentStoreReady(state, scheduleSync);\n } catch (error) {\n reportDocumentStoreWriteFailure(state, ATTACHMENT_FAILURE_MESSAGE, error);\n return;\n }\n\n if (!ready || !state.doc || !canWriteDocument(state)) {\n return;\n }\n\n const writeGeneration = captureAttachmentWriteGeneration(state);\n if (!writeGeneration) return;\n state.writeChain = state.writeChain\n .catch(() => undefined)\n .then(async () =>\n persistSlotAttachmentFile(state, slotId, file, writeGeneration),\n )\n .catch((error: unknown) => {\n reportDocumentStoreWriteFailure(state, ATTACHMENT_FAILURE_MESSAGE, error);\n });\n return state.writeChain;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deferredInitialUpdate.js","sourceRoot":"","sources":["deferredInitialUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC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AK,CAAC,GAAG,CAAC;IAC7B,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC;IAC7C,IAAI,CAAC,UAAU,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO;IAChD,MAAM,eAAe,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACxD,wEAAwE;IACxE,IAAI,sBAAsB,CAAC,WAAW,EAAE,eAAe,CAAC;QAAE,OAAO;IACjE,MAAM,cAAc,GAAG,kCAAkC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC7E,IAAI,CAAC,cAAc;QAAE,OAAO;IAC5B,MAAM,aAAa,GAAG,yBAAyB,CAC7C,qBAAqB,CAAC,KAAK,EAAE,UAAU,CAAC,CACzC,CAAC;IACF,IAAI,CAAC,aAAa;QAAE,OAAO;IAC3B,MAAM,SAAS,GAAG,MAAM,eAAe,CACrC,KAAK,EACL,UAAU,EACV,EAAE,kBAAkB,EAAE,eAAe,EAAE,EACvC;QACE,aAAa;QACb,gCAAgC,EAAE,IAAI;QACtC,oBAAoB,EAAE,IAAI;KAC3B,EACD,cAAc,CACf,CAAC;IACF,IACE,CAAC,SAAS;QACV,CAAC,oCAAoC,CAAC,KAAK,EAAE,cAAc,CAAC,EAC5D,CAAC;QACD,OAAO;IACT,CAAC;IACD,yBAAyB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { encodeVersionVector, satisfiesVersionVector } from \"@tearleads/loro\";\nimport { createPendingUpdateFields } from \"../../../data/documents/documentSync\";\nimport { requestDocumentStoreSync } from \"../registry\";\nimport {\n type AttachmentWriteGeneration,\n captureAttachmentWriteGeneration,\n isAttachmentWriteGenerationCurrent,\n} from \"./attachmentWriteGeneration\";\nimport { reloadDocumentFromDurableHistory } from \"./durableDocumentReload\";\nimport { ensureDocumentStoreInitialized } from \"./initialization\";\nimport {\n advancePendingBaseVersion,\n pendingDeltaSinceBase,\n persistDocument,\n} from \"./persistence\";\nimport { type DocumentStoreState, resetDocumentStore } from \"./state\";\nimport {\n captureDocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\n/**\n * Runs after the first attach on a store opened with `deferInitialUpdate`.\n * Creation committed the birth without a pending update, leaving the marker at\n * the empty version so that attach's delta would carry it, and scheduled sync\n * passes wait meanwhile (see `canRunScheduledSync`) so none ships the birth on\n * its own. When the attach did not land (staging failed or returned null, its\n * persist was refused, or the store could not attach), enqueue the deferred\n * tail now so the document still syncs, without its attachment. Either way,\n * lift the hold and request the pass it skipped.\n */\nexport async function settleDeferredInitialUpdate(\n state: DocumentStoreState,\n writeGeneration: AttachmentWriteGeneration | null,\n): Promise<void> {\n if (!state.deferInitialUpdate) return;\n // Before initialization finishes no attach has touched a live doc, and a\n // reload here would install one behind initialization's back (or mark a\n // not-yet-created document removed). Lift the hold; initialization then\n // restores the empty marker and schedules the pass that ships the birth.\n if (!state.initialized) {\n state.deferInitialUpdate = false;\n return;\n }\n // A pass exports the live doc, so it must hold only durable content (see\n // restoreDurableLiveDocument) before the hold lifts. When that cannot be\n // shown, even after a transient failure, reinitialize from durable history\n // rather than latch the hold: the reset lifts it and drops the live doc.\n let durable = false;\n try {\n durable = await restoreDurableLiveDocument(state);\n } finally {\n if (!durable && state.deferInitialUpdate && state.doc) {\n resetDocumentStore(state);\n ensureDocumentStoreInitialized(state, () =>\n requestDocumentStoreSync(state),\n );\n } else if (!durable) {\n // No live doc remains to leak (a concurrent removal): just lift it.\n state.deferInitialUpdate = false;\n }\n }\n if (!durable) return;\n state.deferInitialUpdate = false;\n try {\n await enqueueDeferredTail(state, writeGeneration);\n } finally {\n requestDocumentStoreSync(state);\n }\n}\n\nfunction isLiveDocumentDurable(state: DocumentStoreState): boolean {\n return (\n state.doc !== null &&\n state.record !== null &&\n satisfiesVersionVector(\n state.record.snapshotEndVersion,\n encodeVersionVector(state.doc),\n )\n );\n}\n\n/**\n * A failed attach whose rollback reload could not run (its generation went\n * stale mid-stage) leaves the uncommitted slot in the live doc, and that slot\n * must never sync without its staged bytes. Reload durable history under a\n * fresh generation before trusting the live doc.\n */\nasync function restoreDurableLiveDocument(\n state: DocumentStoreState,\n): Promise<boolean> {\n if (isLiveDocumentDurable(state)) return true;\n const generation = captureDocumentStoreSyncGeneration(state, state.doc);\n if (generation) {\n await reloadDocumentFromDurableHistory({\n expectedGeneration: generation,\n preserveQueuedWritesWhenIdentityMatches: true,\n state,\n });\n }\n return isLiveDocumentDurable(state);\n}\n\nasync function enqueueDeferredTail(\n state: DocumentStoreState,\n writeGeneration: AttachmentWriteGeneration | null,\n): Promise<void> {\n // A reset or relink owns the replacement store; its deferred tail stays\n // durable and the next write or sync pass materializes it. With no attach\n // (nothing to attach, or the store was not writable) the live store owns it.\n const generation = writeGeneration ?? captureAttachmentWriteGeneration(state);\n if (!generation || !isAttachmentWriteGenerationCurrent(state, generation)) {\n return;\n }\n const currentDoc = state.doc;\n const baseVersion = state.pendingBaseVersion;\n if (!currentDoc || baseVersion === null) return;\n const documentVersion = encodeVersionVector(currentDoc);\n // Settled: the attach (or an earlier write) already enqueued the birth.\n if (satisfiesVersionVector(baseVersion, documentVersion)) return;\n const syncGeneration = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!syncGeneration) return;\n const pendingUpdate = createPendingUpdateFields(\n pendingDeltaSinceBase(state, currentDoc),\n );\n if (!pendingUpdate) return;\n const persisted = await persistDocument(\n state,\n currentDoc,\n { snapshotEndVersion: documentVersion },\n {\n pendingUpdate,\n preserveSnapshotStructuredFields: true,\n preserveSnapshotText: true,\n },\n syncGeneration,\n );\n if (\n !persisted ||\n !isDocumentStoreSyncGenerationCurrent(state, syncGeneration)\n ) {\n return;\n }\n advancePendingBaseVersion(state, currentDoc);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"documentHistoryCompaction.js","sourceRoot":"","sources":["documentHistoryCompaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EA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Y,EAAE,EAAE,KAAK,KAAK,EAC1B,CAAC;QACD,OAAO;IACT,CAAC;IACD,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,WAAW,CAAC,wBAAwB,CAAC,OAAO,EAAE;QAClD,cAAc,EAAE,qBAAqB,CAAC,WAAW,EAAE,UAAU,CAAC;QAC9D,gBAAgB;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC;QACjC,YAAY,EAAE,GAAG,EAAE,CACjB,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,YAAY,EAAE,EAAE,KAAK,KAAK;KAC3E,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,qBAAqB,CAC5B,WAA0D,EAC1D,QAAuB;IAEvB,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACnC,IAAI,CAAC;YACH,OAAO,4BAA4B,CACjC,QAAQ,EACR,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAChC;gBACC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACZ,CAAC,CAAC,EAAE,CAAC;QACT,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { base64ToBytes, bytesToBase64 } from \"@tearleads/encoding\";\nimport {\n encodeVersionVector,\n exportFullHistorySnapshot,\n updateMatchesDocumentHistory,\n} from \"@tearleads/loro\";\nimport {\n DOCUMENT_HISTORY_COMPACTION_MAX_BYTES,\n DOCUMENT_HISTORY_COMPACTION_MAX_ROWS,\n} from \"../../../workflows/documents\";\nimport type { DocumentState, DocumentStoreState } from \"./state\";\nimport {\n captureDocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\n/**\n * Refresh the durable full-history checkpoint when the tail has grown past\n * the compaction thresholds, or seed the first checkpoint as soon as the\n * document can export full history (a freshly created or rebuilt document is\n * cheap to export; waiting for the threshold would leave restarts without\n * history until then). The snapshot comes from the LIVE document, which has\n * every tail update imported, so clearing the tail loses nothing.\n */\nexport async function maybeCompactDocumentHistory(\n state: DocumentStoreState,\n currentDoc: DocumentState,\n stillCurrent?: (() => boolean) | undefined,\n): Promise<void> {\n const { persistence } = state;\n // Bind this compaction to the store context it started under: a store\n // reset or runtime swap mid-compaction must not let the OLD document's\n // checkpoint overwrite the replacement generation's history (or land in a\n // newly selected database).\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation || stillCurrent?.() === false) {\n return;\n }\n const execSql = state.runtime.infra.execSql;\n const tail = await persistence.readHistoryTailSize(execSql, state.localId);\n if (\n tail.hasCheckpoint &&\n tail.rowCount < DOCUMENT_HISTORY_COMPACTION_MAX_ROWS &&\n tail.byteLength < DOCUMENT_HISTORY_COMPACTION_MAX_BYTES\n ) {\n return;\n }\n\n // Capture the tail BEFORE exporting, then prove coverage per row: another\n // pane can append ops this pane's document has not merged, so blanket\n // deletion would discard the only durable copy. Unproven rows survive for\n // a later compaction by whichever pane holds their ops.\n const tailEntries = await persistence.listHistoryTailEntries(\n execSql,\n state.localId,\n );\n const snapshot = exportFullHistorySnapshot(currentDoc);\n if (\n !isSyncGenerationCurrent(state, generation) ||\n stillCurrent?.() === false\n ) {\n return;\n }\n const endVersionVector = encodeVersionVector(currentDoc);\n await persistence.replaceHistoryCheckpoint(execSql, {\n coveredTailIds: coveredHistoryTailIds(tailEntries, currentDoc),\n endVersionVector,\n localId: state.localId,\n snapshot: bytesToBase64(snapshot),\n stillCurrent: () =>\n isSyncGenerationCurrent(state, generation) && stillCurrent?.() !== false,\n });\n}\n\n/**\n * Tail rows whose exact operations already belong to the checkpoint document.\n * Version-vector dominance is insufficient: a same-frontier fork has the same\n * declared range, and malformed rows must survive so recovery fails closed\n * instead of compaction deleting the evidence before provenance validation.\n */\nfunction coveredHistoryTailIds(\n tailEntries: readonly { id: string; updateData: string }[],\n document: DocumentState,\n): string[] {\n return tailEntries.flatMap((entry) => {\n try {\n return updateMatchesDocumentHistory(\n document,\n base64ToBytes(entry.updateData),\n )\n ? [entry.id]\n : [];\n } catch {\n return [];\n }\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"durableDocumentReload.js","sourceRoot":"","sources":["durableDocumentReload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAEL,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAS1B,MAAM,UAAU,4BAA4B,CAC1C,cAA6B,EAC7B,OAAuB;IAEvB,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,cAAc,CAAC,cAAc,EAAE,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,gCAAgC,CAC9B,cAAc,EACd,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CACvD,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAO5C;IACC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACvD,MAAM,kBAAkB,GACtB,KAAK,CAAC,kBAAkB,KAAK,SAAS;QACpC,CAAC,CAAC,CAAC,KAAK,CA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AE,mBAAmB,CAAC,CAAC;QAClE,IAAI,CAAC,oCAAoC,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,CAAC;YACrE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,4BAA4B,CAAC;YAC3B,aAAa;YACb,uCAAuC,EACrC,KAAK,CAAC,uCAAuC;YAC/C,cAAc;YACd,KAAK;SACN,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { base64ToBytes } from \"@tearleads/encoding\";\nimport { importSnapshot } from \"@tearleads/loro\";\nimport {\n importDocumentHistoryTailUpdates,\n runSerializedSqlMutation,\n} from \"../../../workflows/documents\";\nimport {\n type DocumentState,\n type DocumentStoreState,\n markDocumentStoreRemoved,\n setReadySnapshot,\n} from \"./state\";\nimport { createFreshPeerStoredDocument } from \"./storedDocument\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\n\ntype DurableDocumentRecord = NonNullable<\n Awaited<ReturnType<DocumentStoreState[\"persistence\"][\"loadDocument\"]>>\n>;\ntype DurableHistory = Awaited<\n ReturnType<DocumentStoreState[\"persistence\"][\"loadHistoryRestoreState\"]>\n>;\n\nexport function importDurableDocumentHistory(\n replacementDoc: DocumentState,\n history: DurableHistory,\n): void {\n if (history?.snapshot) {\n importSnapshot(replacementDoc, base64ToBytes(history.snapshot));\n }\n if (history) {\n importDocumentHistoryTailUpdates(\n replacementDoc,\n history.tailUpdates.map((update) => update.updateData),\n );\n }\n}\n\nexport function installDurableDocumentReload(input: {\n durableRecord: DurableDocumentRecord;\n previousDocumentId?: string | null | undefined;\n preserveQueuedWritesWhenIdentityMatches: boolean;\n registerIdentityChange?: boolean | undefined;\n replacementDoc: DocumentState;\n state: DocumentStoreState;\n}): void {\n const { durableRecord, replacementDoc, state } = input;\n const previousDocumentId =\n input.previousDocumentId === undefined\n ? (state.record?.documentId ?? null)\n : input.previousDocumentId;\n const identityChanged = previousDocumentId !== durableRecord.documentId;\n const preserveQueuedWrites =\n input.preserveQueuedWritesWhenIdentityMatches && !identityChanged;\n if (!preserveQueuedWrites) {\n state.localWriteGeneration += 1;\n state.pendingLocalWrites = 0;\n }\n state.record = durableRecord;\n state.pullContinuation = durableRecord.pullContinuation ?? null;\n state.pendingBaseVersion =\n durableRecord.pendingBaseVersion ??\n (durableRecord.snapshotEndVersion.length > 0\n ? durableRecord.snapshotEndVersion\n : null);\n state.doc = replacementDoc;\n state.writerProjection = null;\n if (identityChanged && input.registerIdentityChange !== false) {\n state.effects.registerDocumentIdentity(\n state.runtime.state.domainScope,\n durableRecord.id,\n durableRecord.documentId,\n );\n }\n const preserveOptimisticProjection =\n preserveQueuedWrites && state.pendingLocalWrites > 0;\n setReadySnapshot(\n state,\n replacementDoc,\n state.snapshot.syncing,\n preserveOptimisticProjection ? state.snapshot.text : undefined,\n preserveOptimisticProjection ? state.snapshot.structuredFields : undefined,\n );\n}\n\nexport async function reloadDocumentFromDurableHistory(input: {\n expectedGeneration: DocumentStoreSyncGeneration;\n preserveQueuedWritesWhenIdentityMatches: boolean;\n sameIdentitySnapshot?: Uint8Array | undefined;\n state: DocumentStoreState;\n}): Promise<boolean> {\n const { expectedGeneration, state } = input;\n if (!isDocumentStoreSyncGenerationCurrent(state, expectedGeneration)) {\n return false;\n }\n\n const replacementDoc = await createFreshPeerStoredDocument();\n return runSerializedSqlMutation(\n state.runtime.infra.execSql,\n async (lockedExecSql) => {\n if (!isDocumentStoreSyncGenerationCurrent(state, expectedGeneration)) {\n return false;\n }\n const { document: durableRecord, historyRestoreState } =\n await state.persistence.loadDocumentWithHistoryRestoreState(\n lockedExecSql,\n state.localId,\n );\n if (!durableRecord) {\n markDocumentStoreRemoved(state);\n return false;\n }\n const canRestoreCapturedSnapshot = Boolean(\n input.sameIdentitySnapshot &&\n (state.record?.documentId ?? null) === durableRecord.documentId,\n );\n if (canRestoreCapturedSnapshot && input.sameIdentitySnapshot) {\n importSnapshot(replacementDoc, input.sameIdentitySnapshot);\n }\n // The captured snapshot removes the failed in-memory mutation, but it\n // cannot replace the durable source of truth: another pane may have\n // advanced history and the record frontier while attachment staging was\n // in flight. Merge the latest checkpoint and tail in both paths before\n // installing that record/frontier beside the rebuilt CRDT.\n importDurableDocumentHistory(replacementDoc, historyRestoreState);\n if (!isDocumentStoreSyncGenerationCurrent(state, expectedGeneration)) {\n return false;\n }\n\n installDurableDocumentReload({\n durableRecord,\n preserveQueuedWritesWhenIdentityMatches:\n input.preserveQueuedWritesWhenIdentityMatches,\n replacementDoc,\n state,\n });\n return true;\n },\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"historyRebuild.js","sourceRoot":"","sources":["historyRebuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AAKrF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAEL,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAE/E;;;;;GAKG;AAEH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAS5C;IAIC,4EAA4E;IAC5E,0EAA0E;IAC1E,sEAAsE;IACtE,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxE,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,MAAM,eAAe,CACrC,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,UAAU,EAChB;QACE,GAAG,KAAK,CAAC,MAAM,CAAC,cAAc;QAC9B,aAAa,EACX,K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AAC,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QACnD,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC;IACrC,CAAC;IACD,IAAI,SAAS,CAAC,0BAA0B;QAAE,KAAK,CAAC,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;;QAE5E,+BAA+B,CAC7B,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,MAAM,CAAC,gBAAgB,IAAI,KAAK,CAAC,KAAK,CAAC,gBAAgB,EAC7D,KAAK,CAAC,0BAA0B,CACjC,CAAC;IACJ,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC;IACzD,OAAO;QACL,mBAAmB,EAAE,SAAS,CAAC,0BAA0B;YACvD,CAAC,CAAC,yBAAyB,CAAC,YAAY,CAAC;YACzC,CAAC,CAAC,mBAAmB;QACvB,uBAAuB,EACrB,SAAS,CAAC,0BAA0B,KAAK,IAAI;YAC7C,SAAS,CAAC,sBAAsB,KAAK,IAAI;YACzC,SAAS,CAAC,MAAM,CAAC,gBAAgB,IAAI,IAAI;YACzC,SAAS,CAAC,MAAM,CAAC,gCAAgC,KAAK,IAAI;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import { bytesToBase64 } from \"@tearleads/encoding\";\nimport {\n encodeVersionVector,\n exportFullHistorySnapshot,\n} from \"@tearleads/loro\";\nimport { readPullContinuation } from \"../../../data/documents/shared/syncPagination\";\nimport type {\n DocumentSyncPullContinuation,\n syncRemoteDocument,\n} from \"../../../workflows/documents\";\nimport { persistDocument } from \"./persistence\";\nimport type { DocumentState, DocumentStoreState } from \"./state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\nimport { installDocumentWriterProjection } from \"./writerProjectionGeneration\";\n\n/**\n * Machinery for reconstructing a full-history document from a verified remote\n * pull. Used by the rotation preflight (rotation.ts): it pulls the remote op\n * log, replays it into a fresh document alongside the durable local queue,\n * and installs the rebuilt document — preserving op identity end to end.\n */\n\nexport async function installRebuiltDocument(input: {\n consumedPullContinuation: DocumentSyncPullContinuation | null;\n currentRecord: NonNullable<DocumentStoreState[\"record\"]>;\n generation: DocumentStoreSyncGeneration;\n rebuiltDoc: DocumentState;\n state: DocumentStoreState;\n synced: NonNullable<Awaited<ReturnType<typeof syncRemoteDocument>>>;\n /** `state.writerProjectionGeneration` when the recovery pull started. */\n writerProjectionGeneration: number;\n}): Promise<{\n fullHistorySnapshot: Uint8Array;\n settlementRequiresRetry: boolean;\n}> {\n // The guarded persist makes the recovered history durable BEFORE publishing\n // the newer record. Checkpoint-ahead is the safe crash direction: restore\n // reads the checkpoint and the record catches up on the next persist.\n const fullHistorySnapshot = exportFullHistorySnapshot(input.rebuiltDoc);\n const rebuiltEndVersion = encodeVersionVector(input.rebuiltDoc);\n const persisted = await persistDocument(\n input.state,\n input.rebuiltDoc,\n {\n ...input.synced.persistedState,\n lastCommitLsn:\n input.synced.response.commitLsn ??\n input.currentRecord.lastCommitLsn ??\n null,\n pullContinuation: readPullContinuation(input.synced.response),\n recoveryGeneration: (input.currentRecord.recoveryGeneration ?? 0) + 1,\n // The guarded checkpoint below covers exactly this frontier.\n snapshotEndVersion: rebuiltEndVersion,\n },\n {\n acceptedPendingUpdateIds: input.synced.settledPendingUpdateIds,\n expectedSyncState: {\n pullContinuation: input.consumedPullContinuation,\n record: input.currentRecord,\n },\n historyCheckpoint: {\n coveredTailIds: [],\n endVersionVector: rebuiltEndVersion,\n pruneCoveredLocalState: true,\n snapshot: bytesToBase64(fullHistorySnapshot),\n },\n pendingBaseVersionOverride: rebuiltEndVersion,\n preserveSnapshotStructuredFields: input.state.pendingLocalWrites > 0,\n preserveSnapshotText: input.state.pendingLocalWrites > 0,\n },\n input.generation,\n );\n if (!persisted) {\n if (!isDocumentStoreSyncGenerationCurrent(input.state, input.generation)) {\n throw new Error(\n \"Document changed during rotation recovery; retry key rotation\",\n );\n }\n // The resurrect guard refused: another subsystem deleted this document\n // while the rebuild was in flight, and saveDocumentRecord cleared the\n // zombie store — pendingBaseVersion included. Restoring the rebuilt doc,\n // projection, or the captured base version here would resurrect state\n // over that clearing.\n throw new Error(\n \"Document was deleted while its history rebuild was in flight\",\n );\n }\n if (\n !persisted.pullContinuationSuperseded &&\n !persisted.syncIdentitySuperseded\n ) {\n input.state.pendingBaseVersion = rebuiltEndVersion;\n input.state.doc = input.rebuiltDoc;\n }\n if (persisted.pullContinuationSuperseded) input.state.writerProjection = null;\n else\n installDocumentWriterProjection(\n input.state,\n input.synced.writerProjection ?? input.state.writerProjection,\n input.writerProjectionGeneration,\n );\n const installedDoc = input.state.doc ?? input.rebuiltDoc;\n return {\n fullHistorySnapshot: persisted.pullContinuationSuperseded\n ? exportFullHistorySnapshot(installedDoc)\n : fullHistorySnapshot,\n settlementRequiresRetry:\n persisted.pullContinuationSuperseded === true ||\n persisted.syncIdentitySuperseded === true ||\n persisted.record.pullContinuation != null ||\n persisted.record.pullContinuationRecoveryRequired === true,\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initialization.js","sourceRoot":"","sources":["initialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAEL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,s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ACf,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,yBAAyB,CAC9B,SAAS,CAAC,MAAM,EAChB,SAAS,CAAC,SAAS,EACnB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CACvC,CAAC;AACJ,CAAC","sourcesContent":["import { bytesToBase64 } from \"@tearleads/encoding\";\nimport {\n emptyVersionVector,\n encodeVersionVector,\n exportAllUpdates,\n exportFullHistorySnapshot,\n mergeVersionVectors,\n} from \"@tearleads/loro\";\nimport {\n DEFAULT_DOCUMENT_ACCESS_EPOCH,\n DEFAULT_DOCUMENT_KIND,\n} from \"../../../data/documents/documentConstants\";\nimport {\n initializeStoredDocumentKind,\n readStoredDocumentState,\n} from \"../../../data/documents/documentKinds\";\nimport type { DocumentSummary } from \"../../../data/documents/documentSummary\";\nimport { createPendingUpdateFields } from \"../../../data/documents/documentSync\";\nimport {\n type DocumentRecord,\n isDatabaseUnavailableError,\n loadPersistedDocumentStoreState,\n} from \"../../../workflows/documents\";\nimport type { DocumentStoreRelinkInput } from \"../types\";\nimport { chainIdentityWrite } from \"./identityWriteChain\";\nimport {\n installPersistedAttachments,\n type LoadedDocumentStoreState,\n} from \"./initializationAttachments\";\nimport {\n type RestoredHistoryState,\n restoredRemoteTailCoverage,\n restorePersistedDocumentContent,\n} from \"./initializationHistory\";\nimport {\n healLocalAttachmentDetachState,\n recoverDroppedAttachmentSlots,\n} from \"./initializationRecovery\";\nimport type { DocumentRelinkCommitSideEffect } from \"./internalRelink\";\nimport { runDocumentOrphanMaintenance } from \"./orphanMaintenance\";\nimport {\n advancePendingBaseVersion,\n documentSummaryFromRecord,\n persistDocument,\n saveDocumentRecord,\n} from \"./persistence\";\nimport { logRevalidationScheduled } from \"./remoteRevalidationTelemetry\";\nimport {\n type DocumentState,\n type DocumentStoreState,\n setReadySnapshot,\n} from \"./state\";\nimport { createStoredDocument } from \"./storedDocument\";\nimport {\n allowDocumentStoreRemoteSync,\n captureDocumentStoreSyncGeneration,\n invalidateDocumentStoreRemoteSync,\n isDocumentStoreSyncGenerationCurrent,\n markDocumentStoreRemoteSyncPending,\n} from \"./syncGeneration\";\n\nasync function createInitialDocumentRecord(\n state: DocumentStoreState,\n nextDoc: DocumentState,\n): ReturnType<typeof saveDocumentRecord> {\n initializeStoredDocumentKind(\n nextDoc,\n state.initialDocumentKind,\n state.runtime.infra.documentProjectors,\n );\n if (state.initialText.length > 0) {\n nextDoc.getText(\"text\").update(state.initialText);\n }\n const initialDocumentState = readStoredDocumentState(\n nextDoc,\n state.runtime.infra.documentProjectors,\n );\n const hasInitialContent =\n state.initialText.length > 0 ||\n state.initialDocumentKind !== DEFAULT_DOCUMENT_KIND;\n const initialUpdate = hasInitialContent\n ? createPendingUpdateFields(exportAllUpdates(nextDoc))\n : null;\n // A deferred birth still commits its checkpoint, but leaves the marker at the\n // empty version with nothing queued: the promised attach exports every op\n // since that marker, so one update carries the birth and the attachment.\n const birthDurability = !initialUpdate\n ? {}\n : state.deferInitialUpdate\n ? { pendingBaseVersionOverride: emptyVersionVector() }\n : { pendingUpdate: initialUpdate };\n\n const created: DocumentRecord = {\n id: state.localId,\n containerId: state.runtime.state.containerId ?? null,\n documentId: state.initialDocumentId,\n documentKind: initialDocumentState.documentKind,\n text: initialDocumentState.text,\n title: initialDocumentState.title,\n snapshotEndVersion: encodeVersionVector(nextDoc),\n accessEpoch: DEFAULT_DOCUMENT_ACCESS_EPOCH,\n accessStateHash: null,\n effectiveAccessLevel: \"admin\",\n lastCommitLsn: null,\n contentKeyBundle: null,\n documentKekTargets: null,\n documentManifestBundle: null,\n };\n // The create-only persistence primitive commits the canonical row and birth\n // checkpoint together. A concurrent initializer either wins both or adopts\n // both, so it cannot replace another pane's history or keying state.\n const persisted = await saveDocumentRecord(\n state,\n nextDoc,\n {\n ...created,\n snapshotEndVersion: encodeVersionVector(nextDoc),\n },\n {\n historyCheckpoint: {\n coveredTailIds: [],\n endVersionVector: encodeVersionVector(nextDoc),\n pruneCoveredLocalState: false,\n snapshot: bytesToBase64(exportFullHistorySnapshot(nextDoc)),\n },\n ...birthDurability,\n },\n );\n return persisted;\n}\n\nfunction installPersistedDocumentRecord(\n state: DocumentStoreState,\n record: NonNullable<DocumentStoreState[\"record\"]>,\n): void {\n state.record = record;\n state.pullContinuation = record.pullContinuation ?? null;\n}\n\ninterface RestoredInitialDocumentState {\n activePersistedState: LoadedDocumentStoreState;\n activeRecord: NonNullable<DocumentStoreState[\"record\"]>;\n doc: DocumentState;\n history: RestoredHistoryState | null;\n}\n\nasync function restoreLoadedInitialDocument(input: {\n initializeGeneration: number;\n nextDoc: DocumentState;\n persistedState: LoadedDocumentStoreState;\n state: DocumentStoreState;\n}): Promise<RestoredInitialDocumentState | null> {\n const { initializeGeneration, persistedState, state } = input;\n const record = persistedState.document;\n if (!record) return null;\n const history = await restorePersistedDocumentContent(\n input.nextDoc,\n persistedState.historyRestoreState,\n );\n if (state.localWriteGeneration !== initializeGeneration) return null;\n installPersistedDocumentRecord(state, record);\n return {\n activePersistedState: persistedState,\n activeRecord: record,\n doc: input.nextDoc,\n history,\n };\n}\n\nasync function restoreOrCreateInitialDocument(input: {\n initializeGeneration: number;\n nextDoc: DocumentState;\n persistedState: LoadedDocumentStoreState;\n state: DocumentStoreState;\n}): Promise<RestoredInitialDocumentState | null> {\n const { initializeGeneration, persistedState, state } = input;\n if (persistedState.document) {\n return restoreLoadedInitialDocument(input);\n }\n\n const created = await createInitialDocumentRecord(state, input.nextDoc);\n if (!created || state.localWriteGeneration !== initializeGeneration) {\n return null;\n }\n const activePersistedState = await loadPersistedDocumentStoreState({\n execSql: state.runtime.infra.execSql,\n localId: state.localId,\n persistence: state.persistence,\n });\n if (state.localWriteGeneration !== initializeGeneration) {\n return null;\n }\n if (!activePersistedState.document) {\n throw new Error(\"Document creation completed without a durable record\");\n }\n const replacementDoc = await createStoredDocument(state);\n return restoreLoadedInitialDocument({\n initializeGeneration,\n nextDoc: replacementDoc,\n persistedState: activePersistedState,\n state,\n });\n}\n\nfunction restorePendingBaseVersion(input: {\n activeRecord: NonNullable<DocumentStoreState[\"record\"]>;\n doc: DocumentState;\n history: RestoredHistoryState | null;\n state: DocumentStoreState;\n}): void {\n const { activeRecord, doc, history, state } = input;\n const markerBase =\n activeRecord.pendingBaseVersion ??\n (activeRecord.snapshotEndVersion.length > 0\n ? activeRecord.snapshotEndVersion\n : null);\n if (markerBase === null) {\n advancePendingBaseVersion(state, doc);\n return;\n }\n\n const remoteCoverage = restoredRemoteTailCoverage(history);\n state.pendingBaseVersion =\n remoteCoverage.length > 0\n ? mergeVersionVectors([markerBase, ...remoteCoverage])\n : markerBase;\n}\n\nasync function initializeDocumentStore(\n state: DocumentStoreState,\n scheduleSync: () => void,\n) {\n if (state.runtime.infra.dbStatus !== \"ready\") {\n return;\n }\n\n // A store reset while this fire-and-forget initialization is loading (a\n // runtime swap, or a local-edits discard that re-seeds the persisted rows)\n // must win: assigning the state loaded BEFORE the reset would bring the\n // replaced record and doc back to life. Every reset bumps the local write\n // generation, so a stale capture here aborts before each assignment batch.\n const initializeGeneration = state.localWriteGeneration;\n\n const nextDoc = await createStoredDocument(state);\n const persistedState = await loadPersistedDocumentStoreState({\n execSql: state.runtime.infra.execSql,\n localId: state.localId,\n persistence: state.persistence,\n });\n if (state.localWriteGeneration !== initializeGeneration) {\n return;\n }\n const restored = await restoreOrCreateInitialDocument({\n initializeGeneration,\n nextDoc,\n persistedState,\n state,\n });\n if (!restored) {\n return;\n }\n const activePersistedState = restored.activePersistedState;\n installPersistedAttachments(state, activePersistedState);\n\n state.doc = restored.doc;\n // Restore the durable outgoing-delta marker. Re-seeding it to the restored\n // document's version would move it PAST any device-first `deferRemoteSync`\n // op (persisted into the durable history but deliberately left un-enqueued\n // and behind the marker), permanently dropping that op from sync across a\n // restart. When a marker was persisted, restore it so the next edit still\n // re-derives the deferred delta. Only seed for rows that never persisted\n // one, from the RECORD's persisted frontier rather than the restored\n // document: a crash between the tail append and the queue/marker writes can\n // resurrect ops the outgoing queue never durably received, and seeding from\n // the restored document would classify those as covered and orphan them\n // from sync forever.\n restorePendingBaseVersion({\n activeRecord: restored.activeRecord,\n doc: restored.doc,\n history: restored.history,\n state,\n });\n // Heal attachment slots lost to an interrupted attach write before marking\n // ready, so the recovered slots are in the snapshot the editor first renders\n // and are queued for sync. recoverDroppedAttachmentSlots advances the marker\n // again for whatever it re-derives. Both helpers gate every durable write\n // on this generation (validated inside the writes' serialized mutations),\n // so a reset mid-helper cannot repopulate discarded state.\n const writeGeneration = captureDocumentStoreSyncGeneration(\n state,\n restored.doc,\n );\n if (!writeGeneration) {\n return;\n }\n await recoverDroppedAttachmentSlots(state, restored.doc, writeGeneration);\n if (state.localWriteGeneration !== initializeGeneration) {\n return;\n }\n await healLocalAttachmentDetachState(\n state,\n restored.doc,\n activePersistedState,\n writeGeneration,\n );\n if (state.localWriteGeneration !== initializeGeneration) {\n return;\n }\n state.initialized = true;\n state.initializePromise = null;\n setReadySnapshot(state, restored.doc, false);\n\n if (restored.activeRecord.documentId && state.scheduleStartupRemoteSync) {\n // Websocket invalidations are intentionally session-local. A process can\n // stop before receiving a peer device's update event, and no event survives\n // the restart to distinguish a clean local snapshot from a stale one. Probe\n // each opened remote document once after loading it; unopened documents stay\n // lazy, while body and attachment state for a restored window converges.\n allowDocumentStoreRemoteSync(state);\n markDocumentStoreRemoteSyncPending(state, \"independent\");\n logRevalidationScheduled(state.runtime, \"startup\");\n }\n scheduleSync();\n void runDocumentOrphanMaintenance(state);\n}\n\nexport function ensureDocumentStoreInitialized(\n state: DocumentStoreState,\n scheduleSync: () => void,\n) {\n if (\n state.initialized ||\n state.initializePromise ||\n state.runtime.infra.dbStatus !== \"ready\"\n ) {\n return;\n }\n\n const initializePromise = initializeDocumentStore(state, scheduleSync).catch(\n (error: unknown) => {\n state.initializePromise = null;\n // A caller that deferred the birth for its attach may give up once\n // opening fails; never leave its durable birth holding sync. No attach\n // has reached a live doc yet, so lifting the hold ships nothing unsafe.\n state.deferInitialUpdate = false;\n\n if (isDatabaseUnavailableError(error)) {\n return;\n }\n\n throw error;\n },\n );\n state.initializePromise = initializePromise;\n void initializePromise.catch(() => undefined);\n}\n\nexport async function awaitInitializationForSync(state: DocumentStoreState) {\n if (!state.initializePromise) {\n return true;\n }\n\n try {\n await state.initializePromise;\n return true;\n } catch (error) {\n if (isDatabaseUnavailableError(error)) {\n return false;\n }\n\n throw error;\n }\n}\n\nexport async function ensureDocumentStoreReady(\n state: DocumentStoreState,\n scheduleSync: () => void,\n): Promise<boolean> {\n ensureDocumentStoreInitialized(state, scheduleSync);\n\n if (state.initialized) {\n return true;\n }\n\n if (!state.initializePromise) {\n return false;\n }\n\n return awaitInitializationForSync(state);\n}\n\nexport async function relinkDocumentStore(\n state: DocumentStoreState,\n input: DocumentStoreRelinkInput,\n scheduleSync: () => void,\n commitSideEffect?: DocumentRelinkCommitSideEffect,\n): Promise<DocumentSummary | null> {\n if (\n input.stillCurrent?.() === false ||\n !(await ensureDocumentStoreReady(state, scheduleSync)) ||\n input.stillCurrent?.() === false ||\n !state.doc\n ) {\n return null;\n }\n const currentDoc = state.doc;\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation) return null;\n // Read the record and persist on the identity-write chain so an in-flight\n // eager create cannot interleave: a create that captured a null identity\n // before its network round trip would otherwise write the derived documentId\n // over the one this relink assigns.\n const persisted = await chainIdentityWrite(state, async () => {\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) return null;\n const currentDocumentId = state.record?.documentId ?? null;\n const currentAccessEpoch =\n state.record?.accessEpoch ?? DEFAULT_DOCUMENT_ACCESS_EPOCH;\n const patch: Partial<DocumentRecord> = {\n accessEpoch: Math.max(currentAccessEpoch, input.accessEpoch),\n accessStateHash:\n input.accessStateHash === undefined\n ? (state.record?.accessStateHash ?? null)\n : input.accessStateHash,\n containerId: input.containerId,\n documentId: input.documentId,\n };\n if (input.contentKeyBundle !== undefined) {\n patch.contentKeyBundle = input.contentKeyBundle;\n }\n if (input.documentKekTargets !== undefined) {\n patch.documentKekTargets = input.documentKekTargets;\n }\n if (input.documentManifestBundle !== undefined) {\n patch.documentManifestBundle = input.documentManifestBundle;\n }\n\n // Relink rewrites access/identity metadata, not content. If it lands while\n // the user is mid-edit, re-deriving text/structured fields from the\n // (possibly lagging) doc would republish a stale read over the live\n // optimistic snapshot and drop in-flight keystrokes; preserve the snapshot\n // like the keystroke and sync persists do.\n // A prior chained write may have cleared this store (resurrect-guard\n // refusal): persisting the captured doc against a null record would\n // resurrect the document as a create. The identity check runs inside\n // the chain, after every earlier write settled.\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n return null;\n }\n const result = await persistDocument(\n state,\n currentDoc,\n patch,\n {\n preserveSnapshotStructuredFields: true,\n preserveSnapshotText: true,\n stillCurrent: input.stillCurrent,\n },\n generation,\n commitSideEffect,\n );\n if (result && currentDocumentId !== input.documentId) {\n state.writerProjection = null;\n invalidateDocumentStoreRemoteSync(state);\n }\n return result;\n });\n // A refused persist means the durable row vanished mid-relink (resurrect\n // guard); there is no summary to report.\n if (!persisted) {\n return null;\n }\n if (persisted.updatedAt === undefined) {\n return null;\n }\n return documentSummaryFromRecord(\n persisted.record,\n persisted.updatedAt,\n state.runtime.infra.documentProjectors,\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializationAttachments.js","sourceRoot":"","sources":["initializationAttachments.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAOrE,MAAM,UAAU,2BAA2B,CACzC,KAAyB,EACzB,cAAwC;IAExC,KAAK,CAAC,kBAAkB,GAAG,cAAc,CAAC,kBAAkB,CAAC;IAC7D,KAAK,CAAC,wBAAwB,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC;IAC3C,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC;IACxC,0BAA0B,CAAC,KAAK,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { loadPersistedDocumentStoreState } from \"../../../workflows/documents\";\nimport { assignLocalAttachmentSlots } from \"./attachmentPersistence\";\nimport type { DocumentStoreState } from \"./state\";\n\nexport type LoadedDocumentStoreState = Awaited<\n ReturnType<typeof loadPersistedDocumentStoreState>\n>;\n\nexport function installPersistedAttachments(\n state: DocumentStoreState,\n persistedState: LoadedDocumentStoreState,\n): void {\n state.pendingAttachments = persistedState.pendingAttachments;\n state.attachmentBlobIdBySlotId = {};\n state.attachmentContentSha256BySlotId = {};\n state.attachmentStorageKeyBySlotId = {};\n assignLocalAttachmentSlots(state, persistedState.localAttachments);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializationHistory.js","sourceRoot":"","sources":["initializationHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAEL,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AAOtC,SAAS,8BAA8B,CACrC,OAAsB,EACtB,OAA6B;IAE7B,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,gCAAgC,CAC9B,OAAO,EACP,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CACvD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,OAAsB,EACtB,OAAoC;IAEpC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,8BAA8B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,OAAoC;IAEpC,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5C,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ;YAAE,OAAO,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,OAAO;gBACL,qBAAqB,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;qBACpD,uBAAuB;aAC3B,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { base64ToBytes } from \"@tearleads/encoding\";\nimport { getImportBlobMetadata, importSnapshot } from \"@tearleads/loro\";\nimport {\n type DocumentsPersistence,\n importDocumentHistoryTailUpdates,\n} from \"../../../workflows/documents\";\nimport type { DocumentState } from \"./state\";\n\nexport type RestoredHistoryState = NonNullable<\n Awaited<ReturnType<DocumentsPersistence[\"loadHistoryRestoreState\"]>>\n>;\n\nfunction installRestoredDocumentContent(\n nextDoc: DocumentState,\n history: RestoredHistoryState,\n): void {\n if (history.snapshot.length > 0) {\n importSnapshot(nextDoc, base64ToBytes(history.snapshot));\n }\n importDocumentHistoryTailUpdates(\n nextDoc,\n history.tailUpdates.map((update) => update.updateData),\n );\n}\n\nexport function restorePersistedDocumentContent(\n nextDoc: DocumentState,\n history: RestoredHistoryState | null,\n): RestoredHistoryState | null {\n if (!history) return null;\n installRestoredDocumentContent(nextDoc, history);\n return history;\n}\n\nexport function restoredRemoteTailCoverage(\n history: RestoredHistoryState | null,\n): string[] {\n if (!history) return [];\n return history.tailUpdates.flatMap((update) => {\n if (update.origin !== \"remote\") return [];\n try {\n return [\n getImportBlobMetadata(base64ToBytes(update.updateData))\n .partialEndVersionVector,\n ];\n } catch {\n return [];\n }\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializationRecovery.js","sourceRoot":"","sources":["initializationRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACL,sBAAsB,EAEtB,sBAAsB,GACvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,uCAAuC,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,oCAAoC,EAAE,MAAM,kBAAkB,CAAC;AAExE,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,kFAAkF;AAClF,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,KAAyB,EACzB,GAA8B,EAC9B,eAA4C;IAE5C,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,OAAO;IACT,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAC9B,sBAAsB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC;QAC9C,UAAU,CAAC,MAAM;QACjB,UAAU;KACX,CAAC,CACH,CAAC;IACF,MAAM,SAAS,GAAyB,EAAE,CAAC;IAC3C,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,kBAAkB,EAA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","sourcesContent":["import { encodeVersionVector } from \"@tearleads/loro\";\nimport {\n addDocumentAttachments,\n type DocumentAttachment,\n getDocumentAttachments,\n} from \"../../../data/documents/documentContent\";\nimport type { LocalAttachmentRecord } from \"../../../workflows/documents\";\nimport { reconcileLocalAttachmentDetachState } from \"./attachmentDetachState\";\nimport { saveLocalAttachmentRecord } from \"./attachmentPersistence\";\nimport { rebaseDocumentAfterPendingUpdateRefusal } from \"./pendingUpdateRefusal\";\nimport {\n advancePendingBaseVersion,\n enqueuePendingUpdate,\n pendingDeltaSinceBase,\n persistDocument,\n} from \"./persistence\";\nimport type { DocumentState, DocumentStoreState } from \"./state\";\nimport type { DocumentStoreSyncGeneration } from \"./syncGeneration\";\nimport { isDocumentStoreSyncGenerationCurrent } from \"./syncGeneration\";\n\n// Re-derive any attachment slot that lives in a durable pending-upload row but\n// is missing (or stale) in the loaded snapshot. The attach write path persists\n// the blob bytes + pending-attachment row BEFORE it enqueues the slot's CRDT op\n// and persists the snapshot, so a crash in that window leaves bytes+row durable\n// but the slot gone from the document — the attachment would otherwise silently\n// disappear on restart while its bytes upload to a binding nothing references\n// (and a slot replace would keep stale metadata). Because the pending row still\n// carries the slot's metadata and staging digest, we can rebuild the slot without\n// opening bytes; normal upload reports missing sources. Runs on init only; a\n// no-op when every pending attachment already matches a slot.\nexport async function recoverDroppedAttachmentSlots(\n state: DocumentStoreState,\n doc: DocumentStoreState[\"doc\"],\n writeGeneration: DocumentStoreSyncGeneration,\n): Promise<void> {\n if (!doc || state.pendingAttachments.length === 0) {\n return;\n }\n\n const existingBySlotId = new Map(\n getDocumentAttachments(doc).map((attachment) => [\n attachment.slotId,\n attachment,\n ]),\n );\n const recovered: DocumentAttachment[] = [];\n for (const pending of state.pendingAttachments) {\n const mimeType = pending.mimeType ?? null;\n const existing = existingBySlotId.get(pending.slotId);\n const contentSha256 = pending.contentSha256;\n if (!isDocumentStoreSyncGenerationCurrent(state, writeGeneration)) return;\n if (\n existing &&\n existing.name === pending.name &&\n existing.byteLength === pending.byteLength &&\n existing.mimeType === mimeType &&\n existing.contentSha256 === contentSha256\n ) {\n continue;\n }\n recovered.push({\n contentSha256,\n byteLength: pending.byteLength,\n mimeType,\n name: pending.name,\n slotId: pending.slotId,\n });\n }\n if (recovered.length === 0) {\n return;\n }\n\n addDocumentAttachments(doc, recovered);\n const update = pendingDeltaSinceBase(state, doc);\n // Every durable write is gated on the captured generation — the enqueue\n // validates it INSIDE its serialized mutation, and the persist re-checks\n // via its expectedGeneration overload — so a store reset (e.g. a\n // local-edits discard) racing this recovery cannot see it re-enqueue or\n // re-persist the state the teardown just removed.\n if (update.byteLength > 0) {\n const enqueued = await enqueuePendingUpdate(\n state,\n update,\n undefined,\n writeGeneration,\n );\n if (!enqueued) {\n const rebased = await rebaseDocumentAfterPendingUpdateRefusal(\n state,\n writeGeneration,\n );\n if (rebased) {\n // Initialization captured the losing identity and must restart from\n // the winner, including its attachment rows and detach markers.\n throw new Error(\n \"Document identity changed during attachment recovery; retry initialization\",\n );\n }\n return;\n }\n }\n // Derive the snapshot from the loaded doc (do NOT preserve the snapshot). This\n // runs during init, before the store is ready, so state.snapshot is still the\n // empty initial snapshot — preserving it would publish a ready snapshot with\n // empty text/structured fields (a flash of empty content) over the real loaded\n // content. There is no in-flight user edit to protect here. The doc is\n // private to initialization and the enqueue above dual-wrote its delta, so\n // its version is a durably covered frontier.\n const persisted = await persistDocument(\n state,\n doc,\n { snapshotEndVersion: encodeVersionVector(doc) },\n {},\n writeGeneration,\n );\n if (\n !persisted ||\n persisted.pullContinuationSuperseded ||\n persisted.syncIdentitySuperseded\n ) {\n return;\n }\n advancePendingBaseVersion(state, doc);\n state.runtime.util.log(\n `Documents: recovered ${recovered.length} attachment slot(s) from pending uploads after an interrupted write.`,\n );\n}\n\n/**\n * Realign detach markers with the loaded document.\n *\n * Removing an attachment marks its row detached and then persists the document;\n * a stop between those two writes leaves the halves disagreeing, and neither\n * the sync detach pass (which reads the document) nor the read models (which\n * read the marker) can resolve that on their own. The loaded document is the\n * durable truth, so the marker follows it.\n */\nexport async function healLocalAttachmentDetachState(\n state: DocumentStoreState,\n doc: DocumentState,\n persistedState: { localAttachments: ReadonlyArray<LocalAttachmentRecord> },\n writeGeneration: DocumentStoreSyncGeneration,\n): Promise<void> {\n const healed = reconcileLocalAttachmentDetachState(\n persistedState.localAttachments,\n doc,\n );\n for (const attachment of healed) {\n // The save validates the generation inside its serialized mutation, so a\n // concurrent store reset can never see this heal rewrite rows the\n // teardown just removed.\n await saveLocalAttachmentRecord(state, attachment, doc, writeGeneration);\n }\n if (healed.length > 0) {\n state.runtime.util.log(\n `Documents: realigned ${healed.length} attachment detach marker(s) with the loaded document.`,\n );\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pullContinuationInvalidation.js","sourceRoot":"","sources":["pullContinuationInvalidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kCAAkC,EAClC,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAA2B,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAEL,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAAC,KAK7D;IACC,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACjE,MAAM,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC;IACtC,IACE,CAAC,UAAU;QACX,CAAC,OAAO;QACR,CAAC,oCAAoC,CAAC,KAAK,EAAE,UAAU,CAAC,EACxD,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,wBAAwB,CAAC,UAAU,CAAC,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CAAC;gBAC5C,CAAC,aAAa,CAAC,sBAAsB,IAAI,IAAI,CAAC;YAChD,kCAAkC,CAAC,KAAK,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;QAC3E,IAAI,CAAC,qBAAqB,EAAE;YAAE,OAAO;QACrC,4BAA4B,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAC3D,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,MAAM,EACJ,gBAAgB,EAAE,sBAAsB,EACxC,gCAAgC,EAAE,oBAAoB,EACtD,GAAG,UAAU,EACd,GAAG,KAAK,CAAC,MAAM,IAAI,aAAa,CAAC;QAClC,KAAK,CAAC,MAAM,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,aAAa,EAAE,CAAC;QACnD,KAAK,CAAC,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,IAAI,IAAI,CAAC;QAChE,KAAK,CAAC,kBAAkB;YACtB,aAAa,CAAC,kBAAkB,IAAI,aAAa,CAAC,kBAAkB,CAAC;QACvE,MAAM,4BAA4B,GAAG,KAAK,CAAC,kBAAkB,GAAG,CAAC,CAAC;QAClE,gBAAgB,CACd,KAAK,EACL,OAAO,EACP,KAAK,CAAC,QAAQ,CAAC,OAAO,EACtB,4BAA4B,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC9D,4BAA4B;YAC1B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB;YACjC,CAAC,CAAC,SAAS,CACd,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type DocumentRecord,\n type DocumentSyncPullContinuation,\n documentSyncPullContinuationsEqual,\n runSerializedSqlMutation,\n} from \"../../../workflows/documents\";\nimport { importDurableDocumentHistory } from \"./durableDocumentReload\";\nimport { type DocumentStoreState, setReadySnapshot } from \"./state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\nimport { documentSyncContextMatches } from \"./syncUpdateImport\";\n\nexport async function invalidateDocumentStorePullContinuation(input: {\n continuation: DocumentSyncPullContinuation;\n currentRecord: DocumentRecord;\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}): Promise<void> {\n const { continuation, currentRecord, generation, state } = input;\n const documentId = currentRecord.documentId;\n const liveDoc = generation.currentDoc;\n if (\n !documentId ||\n !liveDoc ||\n !isDocumentStoreSyncGenerationCurrent(state, generation)\n ) {\n return;\n }\n\n await runSerializedSqlMutation(generation.execSql, async (lockedExecSql) => {\n const invalidated = await state.persistence.invalidatePullContinuation(\n lockedExecSql,\n {\n accessEpoch: currentRecord.accessEpoch,\n accessStateHash: currentRecord.accessStateHash ?? null,\n continuation,\n contentKeyBundle: currentRecord.contentKeyBundle ?? null,\n documentId,\n documentKekTargets: currentRecord.documentKekTargets ?? null,\n documentManifestBundle: currentRecord.documentManifestBundle ?? null,\n lastCommitLsn: currentRecord.lastCommitLsn ?? null,\n localId: currentRecord.id,\n },\n );\n if (!invalidated) return;\n const { historyRestoreState, record: durableRecord } = invalidated;\n const canAdoptDurableRecord = () =>\n isDocumentStoreSyncGenerationCurrent(state, generation) &&\n documentSyncContextMatches(state.record, currentRecord, documentId) &&\n durableRecord.id === currentRecord.id &&\n durableRecord.documentId === documentId &&\n durableRecord.accessEpoch === currentRecord.accessEpoch &&\n (durableRecord.accessStateHash ?? null) ===\n (currentRecord.accessStateHash ?? null) &&\n (durableRecord.contentKeyBundle ?? null) ===\n (currentRecord.contentKeyBundle ?? null) &&\n (durableRecord.documentKekTargets ?? null) ===\n (currentRecord.documentKekTargets ?? null) &&\n (durableRecord.documentManifestBundle ?? null) ===\n (currentRecord.documentManifestBundle ?? null) &&\n documentSyncPullContinuationsEqual(state.pullContinuation, continuation);\n if (!canAdoptDurableRecord()) return;\n importDurableDocumentHistory(liveDoc, historyRestoreState);\n if (!canAdoptDurableRecord()) {\n return;\n }\n const {\n pullContinuation: _stalePullContinuation,\n pullContinuationRecoveryRequired: _staleRecoveryMarker,\n ...liveRecord\n } = state.record ?? currentRecord;\n state.record = { ...liveRecord, ...durableRecord };\n state.pullContinuation = durableRecord.pullContinuation ?? null;\n state.pendingBaseVersion =\n durableRecord.pendingBaseVersion ?? durableRecord.snapshotEndVersion;\n const preserveOptimisticProjection = state.pendingLocalWrites > 0;\n setReadySnapshot(\n state,\n liveDoc,\n state.snapshot.syncing,\n preserveOptimisticProjection ? state.snapshot.text : undefined,\n preserveOptimisticProjection\n ? state.snapshot.structuredFields\n : undefined,\n );\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remoteRevalidationTelemetry.js","sourceRoot":"","sources":["remoteRevalidationTelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAIjF,MAAM,UAAU,wBAAwB,CACtC,OAAyB,EACzB,MAA+B;IAE/B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,mDAAmD,MAAM,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAyB,EACzB,GAAkB,EAClB,mBAA2B,EAC3B,SAAkB;IAElB,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CACpB,iEAAiE,mBAAmB,oBAAoB,sBAAsB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAC7I,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAyB,EACzB,SAAkB;IAElB,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import { getDocumentAttachments } from \"../../../data/documents/documentContent\";\nimport type { DocumentsRuntime } from \"../types\";\nimport type { DocumentState, DocumentStoreState } from \"./state\";\n\nexport function logRevalidationScheduled(\n runtime: DocumentsRuntime,\n reason: \"reconnect\" | \"startup\",\n): void {\n runtime.util.log(`Documents: remote revalidation scheduled reason=${reason}`);\n}\n\nexport function logRevalidationApplied(\n state: DocumentStoreState,\n doc: DocumentState,\n incomingUpdateCount: number,\n requested: boolean,\n): void {\n if (!requested) return;\n state.runtime.util.log(\n `Documents: remote revalidation result=applied incomingUpdates=${incomingUpdateCount} attachmentSlots=${getDocumentAttachments(doc).length}`,\n );\n}\n\nexport function logRevalidationUnavailable(\n state: DocumentStoreState,\n requested: boolean,\n): void {\n if (!requested) return;\n state.runtime.util.log(\"Documents: remote revalidation result=unavailable\");\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remoteWork.js","sourceRoot":"","sources":["remoteWork.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sCAAsC,EACtC,sCAAsC,EAEtC,wCAAwC,GACzC,MAAM,kBAAkB,CAAC;AAE1B,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAOlC,CAAC;AAEJ,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC/B;IAArB,YAAqB,QAAuB;QAC1C,KAAK,CAAC,4DAA4D,CAAC,CAAC;QADjD,aAAQ,GAAR,QAAQ,CAAe;QAE1C,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,KAAyB;IAEzB,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,MAAM;QACX,wCAAwC,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;QAClE,CAAC,CAAC,MAAM,CAAC,IAAI;QACb,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB,CACnC,KAAyB,EACzB,IAAsB;IAEtB,MAAM,OAAO,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,gFAAgF;IAChF,MAAM,UAAU,GAAG;QACjB,GAAG,sCAAsC,CAAC,KAAK,CAAC;QAChD,GAAG,sCAAsC,CAAC,KAAK,CAAC;KACjD,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE;SAC3B,IAAI,CAAC,IAAI,CAAC;SACV,OAAO,CAAC,GAAG,EAAE;QACZ,IAAI,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC;YAC5C,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CAAC,CAAC;IACL,MAAM,MAAM,GAAG;QACb,UAAU;QACV,IAAI,EAAE,IAAI,CAAC,IAAI,CACb,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB;KACF,CAAC;IACF,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { DocumentStoreState } from \"./state\";\nimport {\n captureDocumentStoreGenerationIdentity,\n captureDocumentStoreSyncLaneGeneration,\n type DocumentStoreSyncLaneGeneration,\n isDocumentStoreGenerationIdentityCurrent,\n} from \"./syncGeneration\";\n\nconst remoteWorkByState = new WeakMap<\n DocumentStoreState,\n {\n generation: DocumentStoreSyncLaneGeneration &\n ReturnType<typeof captureDocumentStoreGenerationIdentity>;\n tail: Promise<void>;\n }\n>();\n\nexport class DocumentRemoteWorkBusyError extends Error {\n constructor(readonly whenIdle: Promise<void>) {\n super(\"Document remote work is still running; retry the operation\");\n this.name = \"DocumentRemoteWorkBusyError\";\n }\n}\n\nexport function getActiveDocumentRemoteWork(\n state: DocumentStoreState,\n): Promise<void> | null {\n const active = remoteWorkByState.get(state);\n return active &&\n isDocumentStoreGenerationIdentityCurrent(state, active.generation)\n ? active.tail\n : null;\n}\n\n/** A document lane retries instead of waiting on overlapping remote work. */\nexport function runDocumentRemoteWork<T>(\n state: DocumentStoreState,\n task: () => Promise<T>,\n): Promise<T> {\n const pending = getActiveDocumentRemoteWork(state);\n if (pending) {\n return Promise.reject(new DocumentRemoteWorkBusyError(pending));\n }\n // Database/runtime replacement abandons ownership; ordinary local edits do not.\n const generation = {\n ...captureDocumentStoreGenerationIdentity(state),\n ...captureDocumentStoreSyncLaneGeneration(state),\n };\n const work = Promise.resolve()\n .then(task)\n .finally(() => {\n if (remoteWorkByState.get(state) === active) {\n remoteWorkByState.delete(state);\n }\n });\n const active = {\n generation,\n tail: work.then(\n () => undefined,\n () => undefined,\n ),\n };\n remoteWorkByState.set(state, active);\n return work;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rotation.js","sourceRoot":"","sources":["rotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EACL,qCAAqC,EAErC,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kCAAkC,EAAE,MAAM,mDAAmD,CAAC;AACvG,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,GACnC,MAAM,sBAAsB,CA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E,CAAC;QACJ,CAAC;QACD,KAAK,IAAI,OAAO,GAAG,CAAC,GAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,OAAO,MAAM,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YACpE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,uEAAuE;gBACvE,uEAAuE;gBACvE,gEAAgE;gBAChE,IACE,CAAC,CACC,KAAK,YAAY,kCAAkC;oBACnD,KAAK,YAAY,4BAA4B,CAC9C;oBACD,OAAO,IAAI,CAAC;oBACZ,CAAC,oCAAoC,CAAC,KAAK,EAAE,UAAU,CAAC,EACxD,CAAC;oBACD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { encodeVersionVector, versionVectorsEqual } from \"@tearleads/loro\";\nimport {\n createDocumentWriterPublicKeyResolver,\n type DocumentSyncPullContinuation,\n readPullContinuation,\n resolveDocumentCreateAuthor,\n syncRemoteDocument,\n validateDocumentSyncUpdateImports,\n} from \"../../../workflows/documents\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../../workflows/principals/runtimePolicyWarmer\";\nimport { requestDocumentStoreSync } from \"../registry\";\nimport { installRebuiltDocument } from \"./historyRebuild\";\nimport { chainIdentityWrite } from \"./identityWriteChain\";\nimport { listPendingUpdates } from \"./persistence\";\nimport { runDocumentRemoteWork } from \"./remoteWork\";\nimport {\n assertExactDocumentHistory,\n importProvenOrdinaryPendingHistory,\n} from \"./rotationProvenance\";\nimport {\n invalidatePullContinuationBeforeRotation,\n RotationPendingUpdatesChangedError,\n settleOrdinaryDocumentUpdatesBeforeRotation,\n} from \"./rotationSettlement\";\nimport type { DocumentState, DocumentStoreState } from \"./state\";\nimport { createStoredDocument } from \"./storedDocument\";\nimport {\n captureDocumentStoreAttachmentSyncGeneration,\n captureDocumentStoreSyncLaneGeneration,\n type DocumentStoreSyncGeneration,\n type DocumentStoreSyncLaneGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\nimport { deleteUpstreamDeletedDocument } from \"./syncRequest\";\nimport { documentIncomingUpdateIsolationFailureHandler } from \"./syncShared\";\nimport { importSyncedDocumentUpdates } from \"./syncUpdateImport\";\n\nfunction ordinaryRawHistoryUpdates<T extends { checkpointKind?: string }>(\n updates: readonly T[],\n): T[] {\n return updates.filter((update) => update.checkpointKind === undefined);\n}\n\nfunction assertRotationRecoveryPrerequisites(state: DocumentStoreState) {\n if (state.persistence.supportsAtomicRecoveryHistoryPruning !== true) {\n throw new Error(\n \"Rotation raw-history recovery requires an adapter with atomic local-history pruning\",\n );\n }\n const author = resolveDocumentCreateAuthor(state.runtime);\n const encapsulationKeyPair = state.runtime.crypto.encapsulationKeyPair;\n const documentId = state.record?.documentId;\n if (\n !author ||\n !encapsulationKeyPair ||\n !documentId ||\n !state.runtime.auth.isAuthenticated ||\n !state.runtime.state.online\n ) {\n throw new Error(\n \"Rotation requires verified full-history recovery, but remote sync prerequisites are unavailable\",\n );\n }\n return { author, documentId, encapsulationKeyPair };\n}\n\nfunction assertRotationRecoveryGeneration(input: {\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}): void {\n if (!isDocumentStoreSyncGenerationCurrent(input.state, input.generation)) {\n throw new Error(\n \"Document changed during rotation recovery; retry key rotation\",\n );\n }\n}\n\nfunction rotationIncomingUpdateIsolation(input: {\n currentDocument: DocumentState;\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}) {\n return {\n onIncomingUpdateIsolationFailure:\n documentIncomingUpdateIsolationFailureHandler(\n input.state,\n input.generation,\n ),\n validateIncomingUpdates: async (\n result: Pick<\n NonNullable<Awaited<ReturnType<typeof syncRemoteDocument>>>,\n \"decryptedUpdates\" | \"response\"\n >,\n ) => {\n await validateDocumentSyncUpdateImports({\n currentDocument: input.currentDocument,\n decryptedUpdates: result.decryptedUpdates,\n responseUpdates: result.response.updates,\n });\n const decryptedUpdates = ordinaryRawHistoryUpdates(\n result.decryptedUpdates,\n );\n const ordinaryUpdateIds = new Set(\n decryptedUpdates.map((update) => update.id),\n );\n await validateDocumentSyncUpdateImports({\n currentDocument: input.currentDocument,\n decryptedUpdates,\n responseUpdates: result.response.updates.filter((update) =>\n ordinaryUpdateIds.has(update.id),\n ),\n });\n },\n };\n}\n\nasync function pullVerifiedRawHistoryForRotation(input: {\n currentRecord: NonNullable<DocumentStoreState[\"record\"]>;\n generation: DocumentStoreSyncGeneration;\n rebuiltDocument: DocumentState;\n state: DocumentStoreState;\n}) {\n const { author, documentId, encapsulationKeyPair } =\n assertRotationRecoveryPrerequisites(input.state);\n let pullContinuation: DocumentSyncPullContinuation | undefined;\n const seenPullCursors = new Set<string>();\n let planningRecord = input.currentRecord;\n let writerProjection =\n input.state.writerProjection?.documentId === documentId\n ? input.state.writerProjection\n : undefined;\n\n while (true) {\n let abandonReason: string | null = null;\n const synced = await syncRemoteDocument({\n apiClient: input.state.runtime.apiClient,\n author,\n documentId,\n execSql: input.state.runtime.infra.execSql,\n historyMode: \"raw\",\n isRemoteSyncBlocked: input.state.runtime.util.isRemoteSyncBlocked,\n localVersionVector: null,\n minLsn: input.currentRecord.lastCommitLsn ?? undefined,\n onRemoteDocumentDeleted: ({ commitPurgeProof, documentId }) =>\n deleteUpstreamDeletedDocument(\n input.state,\n input.generation,\n input.currentRecord,\n documentId,\n commitPurgeProof,\n ),\n // Recorded, never parked: this pass submits no writes, so it plans no\n // ancestor repair and cannot abandon as `inaccessible`.\n onSyncAbandoned: (reason) => {\n abandonReason = reason;\n },\n ...rotationIncomingUpdateIsolation({\n currentDocument: input.rebuiltDocument,\n generation: input.generation,\n state: input.state,\n }),\n onSyncTrace: (line) => input.state.runtime.util.log(`Documents: ${line}`),\n pendingUpdates: [],\n persistedState: planningRecord,\n pullContinuation,\n resolveProjectionUserKey: input.state.resolveProjectionUserKey,\n resolveWriterPublicKey: createDocumentWriterPublicKeyResolver({\n logPrefix: \"Documents\",\n runtime: input.state.runtime,\n writerKeyLabel: \"writer key\",\n }),\n targetSecretKey: encapsulationKeyPair.secretKey,\n warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(\n input.state.runtime,\n ),\n writerProjection,\n });\n if (!synced) {\n throw new Error(\n `Rotation raw-history recovery could not complete (${abandonReason ?? \"sync did not finish\"}); key rotation was not started`,\n );\n }\n\n assertRotationRecoveryGeneration(input);\n\n importSyncedDocumentUpdates(\n input.rebuiltDocument,\n ordinaryRawHistoryUpdates(synced.decryptedUpdates),\n );\n if (!synced.hasIncompletePull) return synced;\n\n const nextContinuation = readPullContinuation(synced.response);\n if (!nextContinuation) {\n throw new Error(\n \"Rotation raw-history recovery ended before the retained history was complete\",\n );\n }\n if (seenPullCursors.has(nextContinuation.cursor)) {\n throw new Error(\n \"Rotation raw-history recovery encountered a repeated pull cursor\",\n );\n }\n seenPullCursors.add(nextContinuation.cursor);\n pullContinuation = nextContinuation;\n planningRecord = { ...planningRecord, ...synced.persistedState };\n writerProjection = synced.writerProjection;\n }\n}\n\nasync function collectVerifiedRawHistoryForRotation(input: {\n currentRecord: NonNullable<DocumentStoreState[\"record\"]>;\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}) {\n const consumedPullContinuation = input.state.pullContinuation;\n const writerProjectionGeneration = input.state.writerProjectionGeneration;\n const rebuiltDocument = await createStoredDocument(input.state);\n try {\n const synced = await pullVerifiedRawHistoryForRotation({\n ...input,\n rebuiltDocument,\n });\n return {\n consumedPullContinuation,\n currentRecord: input.currentRecord,\n rebuiltDocument,\n synced,\n writerProjectionGeneration,\n };\n } catch (error) {\n rebuiltDocument.free();\n throw error;\n }\n}\n\nclass RotationDocumentChangedError extends Error {}\n\nfunction assertCapturedDocumentCurrent(input: {\n capturedVersion: string;\n currentDocument: DocumentState;\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}): void {\n assertRotationRecoveryGeneration(input);\n if (\n !versionVectorsEqual(\n encodeVersionVector(input.currentDocument),\n input.capturedVersion,\n )\n ) {\n throw new RotationDocumentChangedError(\n \"Document changed during rotation recovery; retry key rotation\",\n );\n }\n}\n\nfunction currentRotationRecoveryRecord(\n state: DocumentStoreState,\n): NonNullable<DocumentStoreState[\"record\"]> {\n if (state.record) return state.record;\n throw new Error(\n \"Document changed during rotation recovery; retry key rotation\",\n );\n}\n\nfunction installRotationRecovery(input: {\n capturedVersion: string;\n collection: Awaited<ReturnType<typeof collectVerifiedRawHistoryForRotation>>;\n currentDoc: DocumentState;\n generation: DocumentStoreSyncGeneration;\n state: DocumentStoreState;\n}) {\n const { capturedVersion, collection, currentDoc, generation, state } = input;\n const installation = state.writeChain\n .catch(() => undefined)\n .then(() =>\n chainIdentityWrite(state, async () => {\n assertCapturedDocumentCurrent({\n capturedVersion,\n currentDocument: currentDoc,\n generation,\n state,\n });\n assertExactDocumentHistory({\n currentDocument: currentDoc,\n rebuiltDocument: collection.rebuiltDocument,\n });\n return installRebuiltDocument({\n consumedPullContinuation: collection.consumedPullContinuation,\n currentRecord: collection.currentRecord,\n generation,\n rebuiltDoc: collection.rebuiltDocument,\n state,\n synced: collection.synced,\n writerProjectionGeneration: collection.writerProjectionGeneration,\n });\n }),\n );\n // Only the checked local install occupies the write queue. Network recovery\n // uses the remote queue, so an outage cannot hold new edits hostage.\n state.writeChain = installation.then(\n () => undefined,\n () => undefined,\n );\n return installation;\n}\n\nasync function recoverFullHistoryForRotation(\n state: DocumentStoreState,\n laneGeneration: DocumentStoreSyncLaneGeneration,\n): Promise<Uint8Array> {\n assertRotationRecoveryPrerequisites(state);\n await invalidatePullContinuationBeforeRotation(state);\n const currentDoc = state.doc;\n const currentRecord = state.record;\n if (!currentDoc || !currentRecord) {\n throw new Error(\n \"Document must finish loading before its content key can rotate\",\n );\n }\n // The teardown guard for the recovery's terminal-failure handler: captured\n // before the pull so a discard (row 21) racing this preflight invalidates\n // it, and the stale handler cannot resurrect a deleted failure row.\n const generation = captureDocumentStoreAttachmentSyncGeneration(\n state,\n currentDoc,\n laneGeneration,\n );\n if (!generation) {\n throw new Error(\n \"Document changed during rotation recovery; retry key rotation\",\n );\n }\n\n const capturedVersion = encodeVersionVector(currentDoc);\n let settlementRequiresRetry = false;\n\n // A raw recovery starts from an empty scratch document, bypasses untrusted\n // rotation-baseline redirects, drains every retained page in memory, and\n // publishes nothing until all response updates have validated. Checkpoints\n // are authenticated and decrypted but are not reconstruction inputs: the\n // original ordinary update stream is the source of truth in this mode.\n let collection = await collectVerifiedRawHistoryForRotation({\n currentRecord,\n generation,\n state,\n });\n\n try {\n assertCapturedDocumentCurrent({\n capturedVersion,\n currentDocument: currentDoc,\n generation,\n state,\n });\n const pendingUpdates = await listPendingUpdates(state);\n assertCapturedDocumentCurrent({\n capturedVersion,\n currentDocument: currentDoc,\n generation,\n state,\n });\n const verifiedOrdinaryVersion = importProvenOrdinaryPendingHistory({\n currentDocument: currentDoc,\n pendingUpdates,\n rebuiltDocument: collection.rebuiltDocument,\n });\n if (pendingUpdates.some((update) => update.sourceVersionVector == null)) {\n // The first raw pass proves the exact ordinary frontier before any local\n // row can be published. Pull raw history again after settlement so the\n // installed snapshot also includes remote work that raced that submit.\n await settleOrdinaryDocumentUpdatesBeforeRotation(\n state,\n verifiedOrdinaryVersion,\n pendingUpdates,\n generation,\n );\n assertCapturedDocumentCurrent({\n capturedVersion,\n currentDocument: currentDoc,\n generation,\n state,\n });\n const definitiveCollection = await collectVerifiedRawHistoryForRotation({\n currentRecord: currentRotationRecoveryRecord(state),\n generation,\n state,\n });\n collection.rebuiltDocument.free();\n collection = definitiveCollection;\n }\n const installed = await installRotationRecovery({\n capturedVersion,\n collection,\n currentDoc,\n generation,\n state,\n });\n settlementRequiresRetry = installed.settlementRequiresRetry;\n if (settlementRequiresRetry) {\n throw new Error(\n \"Rotation raw-history recovery was superseded during its atomic install; retry key rotation\",\n );\n }\n return installed.fullHistorySnapshot;\n } finally {\n if (state.doc !== collection.rebuiltDocument) {\n collection.rebuiltDocument.free();\n }\n if (settlementRequiresRetry) {\n requestDocumentStoreSync(state);\n }\n }\n}\n\n/**\n * Wait for prior local writes and serialize with other remote work. Edits can\n * continue during the pull; the checked install rejects a changed document so\n * a stale recovery cannot replace them. This preflight can then be retried.\n */\nexport function assertDocumentStoreCanRotateContentKey(\n state: DocumentStoreState,\n): Promise<Uint8Array> {\n const laneGeneration = captureDocumentStoreSyncLaneGeneration(state);\n const generation = captureDocumentStoreAttachmentSyncGeneration(\n state,\n state.doc,\n laneGeneration,\n );\n return runDocumentRemoteWork(state, async () => {\n await state.writeChain.catch(() => undefined);\n if (\n !generation ||\n !isDocumentStoreSyncGenerationCurrent(state, generation)\n ) {\n throw new Error(\n \"Document changed before rotation recovery; retry key rotation\",\n );\n }\n for (let attempt = 0; ; attempt += 1) {\n try {\n return await recoverFullHistoryForRotation(state, laneGeneration);\n } catch (error) {\n // Autosaves and conflict re-keying can invalidate the proven frontier.\n // Repeat the complete proof without blocking new local edits; repeated\n // changes remain bounded and leave the durable queue retryable.\n if (\n !(\n error instanceof RotationPendingUpdatesChangedError ||\n error instanceof RotationDocumentChangedError\n ) ||\n attempt >= 2 ||\n !isDocumentStoreSyncGenerationCurrent(state, generation)\n ) {\n throw error;\n }\n }\n }\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rotationProvenance.js","sourceRoot":"","sources":["rotationProvenance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAIzB,SAAS,sBAAsB,CAAC,KAAe;IAC7C,OAAO,IAAI,KAAK,CACd,4FAA4F,EAC5F,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,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e,EAAE,KAAK,CAAC,eAAe;YACtC,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,aAAa,CAAC,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACtE,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,mBAAmB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACzE,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["import { base64ToBytes } from \"@tearleads/encoding\";\nimport {\n encodeVersionVector,\n exportFullHistoryIdentity,\n getImportBlobMetadata,\n importUpdates,\n satisfiesVersionVector,\n updateMatchesDocumentHistory,\n versionVectorsEqual,\n} from \"@tearleads/loro\";\nimport type { PendingUpdateRecord } from \"../../../workflows/documents\";\nimport type { DocumentState } from \"./state\";\n\nfunction unverifiedLocalHistory(cause?: unknown): Error {\n return new Error(\n \"Rotation raw-history recovery found unverified local history; key rotation was not started\",\n cause === undefined ? undefined : { cause },\n );\n}\n\nfunction ordinaryPendingUpdateBytes(input: {\n currentDocument: DocumentState;\n pendingUpdates: readonly PendingUpdateRecord[];\n}): Uint8Array[] {\n return input.pendingUpdates.flatMap((update) => {\n if (update.sourceVersionVector != null) return [];\n const bytes = base64ToBytes(update.updateData);\n const metadata = getImportBlobMetadata(bytes);\n if (\n metadata.mode !== \"update\" ||\n !versionVectorsEqual(\n metadata.partialStartVersionVector,\n update.partialStartVersionVector,\n ) ||\n !versionVectorsEqual(\n metadata.partialEndVersionVector,\n update.partialEndVersionVector,\n ) ||\n !updateMatchesDocumentHistory(input.currentDocument, bytes)\n ) {\n throw new Error(\"Ordinary pending-update provenance is inconsistent\");\n }\n return [bytes];\n });\n}\n\nexport function assertExactDocumentHistory(input: {\n currentDocument: DocumentState;\n rebuiltDocument: DocumentState;\n}): void {\n const currentVersion = encodeVersionVector(input.currentDocument);\n if (\n !satisfiesVersionVector(\n encodeVersionVector(input.rebuiltDocument),\n currentVersion,\n ) ||\n exportFullHistoryIdentity(input.currentDocument) !==\n exportFullHistoryIdentity(input.rebuiltDocument, currentVersion)\n ) {\n throw unverifiedLocalHistory();\n }\n}\n\n/**\n * Prove that the live history is exactly raw remote history plus queued local\n * ordinary deltas. Deterministic operation-log comparison detects checkpoint\n * substitutions that reuse the genuine operations' version-vector identities.\n */\nexport function importProvenOrdinaryPendingHistory(input: {\n currentDocument: DocumentState;\n pendingUpdates: readonly PendingUpdateRecord[];\n rebuiltDocument: DocumentState;\n}): string {\n try {\n const updates = ordinaryPendingUpdateBytes({\n currentDocument: input.currentDocument,\n pendingUpdates: input.pendingUpdates,\n });\n if (updates.length > 0) importUpdates(input.rebuiltDocument, updates);\n assertExactDocumentHistory(input);\n return encodeVersionVector(input.currentDocument);\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"unverified local\")) {\n throw error;\n }\n throw unverifiedLocalHistory(error);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rotationSettlement.js","sourceRoot":"","sources":["rotationSettlement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,uCAAuC,EAAE,MAAM,gCAAgC,CAAC;AAMzF,OAAO,EACL,sCAAsC,EACtC,uCAAuC,EACvC,4CAA4C,GAC7C,MAAM,yBAAyB,CAAC;AACjC,OAAO,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C,gBAAgB,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC,EACzE,CAAC;YACD,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,gBAAgB,KAAK,mBAAmB,CAAC,cAAc,CAAC,EAAE,CAAC;QACjF,IAAI,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;QACJ,CAAC;QACD,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACnC,gBAAgB,GAAG,MAAM,wBAAwB,CAAC;YAChD,UAAU;YACV,cAAc,EAAE,iBAAiB;YACjC,KAAK;YACL,mBAAmB,EAAE,gBAAgB;SACtC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { encodeVersionVector, satisfiesVersionVector } from \"@tearleads/loro\";\nimport type { PendingUpdateRecord } from \"../../../workflows/documents\";\nimport { chainIdentityWrite } from \"./identityWriteChain\";\nimport { listPendingUpdates, persistDocument } from \"./persistence\";\nimport { invalidateDocumentStorePullContinuation } from \"./pullContinuationInvalidation\";\nimport type {\n DocumentState,\n DocumentStoreState,\n DocumentSyncAttempt,\n} from \"./state\";\nimport {\n cleanupPreRegisteredUpdateIdsOnFailure,\n discardUnacceptedPreRegisteredUpdateIds,\n preRegisterMaterializedDocumentSyncUpdateIds,\n} from \"./syncAcceptedUpdateIds\";\nimport {\n captureDocumentStoreSyncGeneration,\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"./syncGeneration\";\nimport { prepareDocumentOutgoingCoverage } from \"./syncOutgoingCoverage\";\nimport { requestRemoteDocumentSync } from \"./syncRequest\";\nimport { extendDocumentVersionCoverage } from \"./versionCoverage\";\n\nexport class RotationPendingUpdatesChangedError extends Error {}\n\nfunction ordinaryPendingUpdates(\n pendingUpdates: readonly PendingUpdateRecord[],\n): PendingUpdateRecord[] {\n return pendingUpdates.filter(\n (pendingUpdate) => pendingUpdate.sourceVersionVector == null,\n );\n}\n\nfunction pendingUpdateSetKey(pendingUpdates: readonly PendingUpdateRecord[]) {\n return pendingUpdates\n .map((pendingUpdate) => pendingUpdate.id)\n .sort()\n .join(\"\\n\");\n}\n\nfunction pendingUpdateMatchesProvenRow(\n pendingUpdate: PendingUpdateRecord,\n provenUpdate: PendingUpdateRecord,\n): boolean {\n return (\n pendingUpdate.id === provenUpdate.id &&\n pendingUpdate.updateData === provenUpdate.updateData &&\n pendingUpdate.partialStartVersionVector ===\n provenUpdate.partialStartVersionVector &&\n pendingUpdate.partialEndVersionVector ===\n provenUpdate.partialEndVersionVector &&\n pendingUpdate.sourceVersionVector === provenUpdate.sourceVersionVector\n );\n}\n\nfunction assertOrdinaryRowsWereProven(input: {\n pendingUpdates: readonly PendingUpdateRecord[];\n provenUpdatesById: ReadonlyMap<string, PendingUpdateRecord>;\n}): void {\n for (const pendingUpdate of ordinaryPendingUpdates(input.pendingUpdates)) {\n const provenUpdate = input.provenUpdatesById.get(pendingUpdate.id);\n if (\n !provenUpdate ||\n !pendingUpdateMatchesProvenRow(pendingUpdate, provenUpdate)\n ) {\n throw new RotationPendingUpdatesChangedError(\n \"Document local updates changed after rotation provenance verification\",\n );\n }\n }\n}\n\nfunction ordinaryPendingUpdatesWithProvenCoverage(input: {\n currentDocument: DocumentState;\n pendingUpdates: PendingUpdateRecord[];\n verifiedBaseVersion: string;\n}): { coverage: string; pendingUpdates: PendingUpdateRecord[] } {\n const ordinaryUpdates = ordinaryPendingUpdates(input.pendingUpdates);\n const documentVersion = encodeVersionVector(input.currentDocument);\n const ordinaryCoverage = extendDocumentVersionCoverage({\n baseVersion: input.verifiedBaseVersion,\n documentVersion,\n spans: ordinaryUpdates,\n });\n if (!satisfiesVersionVector(ordinaryCoverage, documentVersion)) {\n throw new Error(\n \"Document rotation cannot settle uncovered local history because it may be checkpoint-derived\",\n );\n }\n return { coverage: ordinaryCoverage, pendingUpdates: ordinaryUpdates };\n}\n\nexport async function invalidatePullContinuationBeforeRotation(\n state: DocumentStoreState,\n): Promise<void> {\n const continuation = state.pullContinuation;\n if (!continuation) return;\n const currentDoc = state.doc;\n const currentRecord = state.record;\n if (!currentDoc || !currentRecord) {\n throw new Error(\n \"Document changed while its pull continuation was invalidated for key rotation\",\n );\n }\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation) {\n throw new Error(\n \"Document changed while its pull continuation was invalidated for key rotation\",\n );\n }\n await invalidateDocumentStorePullContinuation({\n continuation,\n currentRecord,\n generation,\n state,\n });\n if (\n state.pullContinuation !== null ||\n !isDocumentStoreSyncGenerationCurrent(state, generation)\n ) {\n throw new Error(\n \"Document pull continuation could not be invalidated before key rotation\",\n );\n }\n}\n\nasync function persistStagedSettlement(input: {\n currentDocument: DocumentState;\n generation: DocumentStoreSyncGeneration;\n preparedRecord: NonNullable<DocumentStoreState[\"record\"]>;\n sentUpdateIds: string[];\n state: DocumentStoreState;\n syncAttempt: DocumentSyncAttempt;\n}): Promise<void> {\n const { state, syncAttempt } = input;\n discardUnacceptedPreRegisteredUpdateIds(\n state,\n input.sentUpdateIds,\n syncAttempt.synced.response.acceptedOutgoingUpdateIds,\n );\n const persisted = await persistDocument(\n state,\n input.currentDocument,\n {\n lastCommitLsn:\n syncAttempt.synced.response.commitLsn ??\n input.preparedRecord.lastCommitLsn ??\n null,\n pullContinuation: null,\n },\n {\n acceptedPendingUpdateIds: syncAttempt.synced.settledPendingUpdateIds,\n expectedSyncState: {\n pullContinuation: syncAttempt.consumedPullContinuation,\n record: syncAttempt.requestRecord,\n },\n preserveSnapshotStructuredFields: true,\n preserveSnapshotText: true,\n },\n input.generation,\n );\n if (\n !persisted ||\n persisted.pullContinuationSuperseded ||\n persisted.syncIdentitySuperseded ||\n !isDocumentStoreSyncGenerationCurrent(state, input.generation)\n ) {\n throw new Error(\n \"Document changed while local updates were settling for key rotation\",\n );\n }\n}\n\nfunction settledOrdinaryCoverage(input: {\n currentDocument: DocumentState;\n pendingUpdates: PendingUpdateRecord[];\n settledUpdateIds: readonly string[];\n verifiedBaseVersion: string;\n}): string {\n const settled = new Set(input.settledUpdateIds);\n return extendDocumentVersionCoverage({\n baseVersion: input.verifiedBaseVersion,\n documentVersion: encodeVersionVector(input.currentDocument),\n spans: input.pendingUpdates.filter((update) => settled.has(update.id)),\n });\n}\n\nasync function persistStagedSettlementOnIdentityChain(input: {\n currentDocument: DocumentState;\n generation: DocumentStoreSyncGeneration;\n pendingUpdates: PendingUpdateRecord[];\n preparedRecord: NonNullable<DocumentStoreState[\"record\"]>;\n sentUpdateIds: string[];\n state: DocumentStoreState;\n syncAttempt: DocumentSyncAttempt;\n verifiedBaseVersion: string;\n}): Promise<string> {\n return chainIdentityWrite(input.state, async () => {\n if (!isDocumentStoreSyncGenerationCurrent(input.state, input.generation)) {\n throw new Error(\n \"Document changed while local updates were settling for key rotation\",\n );\n }\n await persistStagedSettlement(input);\n return settledOrdinaryCoverage({\n currentDocument: input.currentDocument,\n pendingUpdates: input.pendingUpdates,\n settledUpdateIds: input.syncAttempt.synced.settledPendingUpdateIds,\n verifiedBaseVersion: input.verifiedBaseVersion,\n });\n });\n}\n\nasync function settleOrdinaryUpdatePass(input: {\n generation: DocumentStoreSyncGeneration;\n pendingUpdates: PendingUpdateRecord[];\n state: DocumentStoreState;\n verifiedBaseVersion: string;\n}): Promise<string> {\n const { state } = input;\n const currentDoc = state.doc;\n const currentRecord = state.record;\n const encapsulationKeyPair = state.runtime.crypto.encapsulationKeyPair;\n if (!currentDoc || !currentRecord || !encapsulationKeyPair) {\n throw new Error(\n \"Document changed while local updates were settling for key rotation\",\n );\n }\n const generation = input.generation;\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n throw new Error(\n \"Document changed while local updates were settling for key rotation\",\n );\n }\n const proven = ordinaryPendingUpdatesWithProvenCoverage({\n currentDocument: currentDoc,\n pendingUpdates: input.pendingUpdates,\n verifiedBaseVersion: input.verifiedBaseVersion,\n });\n const prepared = await prepareDocumentOutgoingCoverage({\n coverageBaseVersion: input.verifiedBaseVersion,\n currentDoc,\n generation,\n pendingUpdates: proven.pendingUpdates,\n state,\n });\n if (!prepared || !isDocumentStoreSyncGenerationCurrent(state, generation)) {\n throw new Error(\n \"Document changed while local updates were settling for key rotation\",\n );\n }\n const preparedPendingUpdates = ordinaryPendingUpdates(\n prepared.pendingUpdates,\n );\n if (preparedPendingUpdates.length === 0) return proven.coverage;\n\n const sentUpdateIds: string[] = [];\n return cleanupPreRegisteredUpdateIdsOnFailure(\n state,\n sentUpdateIds,\n async () => {\n const syncAttempt = await requestRemoteDocumentSync({\n allowRecoveryBaseline: false,\n currentDoc,\n currentRecord: prepared.record,\n encapsulationKeyPair,\n generation,\n onOutgoingUpdatesMaterialized: (updateIds) =>\n preRegisterMaterializedDocumentSyncUpdateIds(\n state,\n sentUpdateIds,\n updateIds,\n ),\n pendingUpdates: preparedPendingUpdates,\n queuedUpdateCount: preparedPendingUpdates.length,\n state,\n unavailableWriterLogMessage:\n \"Documents: rotation could not settle local updates because the writer context is unavailable.\",\n });\n if (\n !syncAttempt ||\n !isDocumentStoreSyncGenerationCurrent(state, generation)\n ) {\n throw new Error(\n \"Document local updates could not be committed before key rotation\",\n );\n }\n\n return persistStagedSettlementOnIdentityChain({\n currentDocument: currentDoc,\n generation,\n pendingUpdates: preparedPendingUpdates,\n preparedRecord: prepared.record,\n sentUpdateIds,\n state,\n syncAttempt,\n verifiedBaseVersion: input.verifiedBaseVersion,\n });\n },\n );\n}\n\n/**\n * Commit only ordinary local rows before rotation. Server-returned updates are\n * authenticated and decrypted by the workflow but deliberately not imported\n * or persisted; the subsequent raw rebuild owns that all-or-nothing install.\n */\nexport async function settleOrdinaryDocumentUpdatesBeforeRotation(\n state: DocumentStoreState,\n verifiedBaseVersion: string,\n provenPendingUpdates: readonly PendingUpdateRecord[],\n generation: DocumentStoreSyncGeneration,\n): Promise<void> {\n const stalledQueueStates = new Set<string>();\n let verifiedCoverage = verifiedBaseVersion;\n const provenUpdatesById = new Map(\n ordinaryPendingUpdates(provenPendingUpdates).map((update) => [\n update.id,\n update,\n ]),\n );\n\n while (true) {\n const currentDoc = state.doc;\n if (!currentDoc) {\n throw new Error(\"Document rotation requires an initialized document\");\n }\n const allPendingUpdates = await listPendingUpdates(state);\n assertOrdinaryRowsWereProven({\n pendingUpdates: allPendingUpdates,\n provenUpdatesById,\n });\n const pendingUpdates = ordinaryPendingUpdates(allPendingUpdates);\n if (\n pendingUpdates.length === 0 &&\n satisfiesVersionVector(verifiedCoverage, encodeVersionVector(currentDoc))\n ) {\n return;\n }\n\n const queueState = `${verifiedCoverage}\\n${pendingUpdateSetKey(pendingUpdates)}`;\n if (stalledQueueStates.has(queueState)) {\n throw new Error(\n \"Document local updates could not be committed before key rotation\",\n );\n }\n stalledQueueStates.add(queueState);\n verifiedCoverage = await settleOrdinaryUpdatePass({\n generation,\n pendingUpdates: allPendingUpdates,\n state,\n verifiedBaseVersion: verifiedCoverage,\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAGL,0BAA0B,EAE1B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,0BAA0B,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAKL,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,sCAAsC,EACtC,6BAA6B,EAC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;YAC1E,yEAAyE;YACzE,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC;QACD,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,kBAAkB,GAAG,qBAAqB,EAAE,CAAC;YACnD,IAAI,CAAC,kBAAkB;gBAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAClD,MAAM,UAAU,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;YACtD,IAAI,UAAU,EAAE,CAAC;gBACf,qEAAqE;gBACrE,uEAAuE;gBACvE,KAAK,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE;oBACxB,IACE,wCAAwC,CAAC,KAAK,EAAE,kBAAkB,CAAC,EACnE,CAAC;wBACD,wBAAwB,CAAC,KAAK,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;YACD,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,CACvC,wCAAwC,CAAC,KAAK,EAAE,kBAAkB,CAAC;gBACjE,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,CAAC;gBACjD,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CACtB,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport {\n type DocumentRecord,\n type DocumentSyncLane,\n isDatabaseUnavailableError,\n type PendingUpdateRecord,\n registerDocumentSyncLane,\n resolveDocumentCreateAuthor,\n} from \"../../../workflows/documents\";\nimport { requestDocumentStoreSync } from \"../registry\";\nimport { awaitInitializationForSync } from \"./initialization\";\nimport { listPendingUpdates } from \"./persistence\";\nimport { logRevalidationUnavailable as logUnavailable } from \"./remoteRevalidationTelemetry\";\nimport {\n getActiveDocumentRemoteWork,\n runDocumentRemoteWork,\n} from \"./remoteWork\";\nimport {\n type DocumentState,\n type DocumentStoreState,\n type DocumentSyncAttempt,\n type EncapsulationKeyPair,\n setDocumentSyncing,\n} from \"./state\";\nimport {\n cleanupPreRegisteredUpdateIdsOnFailure,\n discardPreRegisteredUpdateIds,\n preRegisterMaterializedDocumentSyncUpdateIds,\n} from \"./syncAcceptedUpdateIds\";\nimport { syncPendingAttachments } from \"./syncAttachments\";\nimport { syncDetachedAttachmentBindings } from \"./syncDetachedAttachments\";\nimport { finalizeDocumentSync } from \"./syncFinalize\";\nimport {\n captureDocumentStoreAttachmentSyncGeneration,\n captureDocumentStoreRemoteSyncGeneration,\n captureDocumentStoreSyncGeneration,\n type DocumentStoreSyncGeneration,\n type DocumentStoreSyncLaneGeneration,\n isDocumentStoreRemoteSyncBlocked,\n isDocumentStoreSyncGenerationCurrent,\n isDocumentStoreSyncLaneGenerationCurrent,\n} from \"./syncGeneration\";\nimport { prepareDocumentOutgoingCoverage } from \"./syncOutgoingCoverage\";\nimport { requestRemoteDocumentSync } from \"./syncRequest\";\nimport {\n ensureRemoteDocument,\n isContainerAwaitingRemoteCreate,\n shouldSkipCleanScheduledDocumentSync,\n} from \"./syncShared\";\n\nfunction canRunScheduledSync(state: DocumentStoreState): boolean {\n return (\n // A deferred birth waits for its attach to carry it (see\n // deferredInitialUpdate.ts); a pass now would ship it on its own.\n state.deferInitialUpdate !== true &&\n state.doc !== null &&\n state.snapshot.ready &&\n state.runtime.state.online &&\n state.runtime.auth.isAuthenticated &&\n state.runtime.crypto.encapsulationKeyPair !== null &&\n resolveDocumentCreateAuthor(state.runtime) !== null\n );\n}\n\nasync function requestOutgoingDocumentBatch(input: {\n readonly currentDoc: DocumentState;\n readonly encapsulationKeyPair: EncapsulationKeyPair;\n readonly generation: DocumentStoreSyncGeneration;\n readonly pendingUpdates: PendingUpdateRecord[];\n readonly record: DocumentRecord;\n readonly state: DocumentStoreState;\n}): Promise<{\n sentUpdateIds: string[];\n syncAttempt: DocumentSyncAttempt | null;\n}> {\n const { planningUpdates, queuedUpdateCount } = prepareDocumentStoreSyncQueue(\n input.pendingUpdates,\n );\n const sentUpdateIds: string[] = [];\n const syncAttempt = await cleanupPreRegisteredUpdateIdsOnFailure(\n input.state,\n sentUpdateIds,\n () =>\n requestRemoteDocumentSync({\n currentDoc: input.currentDoc,\n currentRecord: input.record,\n encapsulationKeyPair: input.encapsulationKeyPair,\n generation: input.generation,\n onOutgoingUpdatesMaterialized: (updateIds) =>\n preRegisterMaterializedDocumentSyncUpdateIds(\n input.state,\n sentUpdateIds,\n updateIds,\n ),\n pendingUpdates: planningUpdates,\n queuedUpdateCount,\n state: input.state,\n unavailableWriterLogMessage:\n \"Documents: skipped sync because the writer context is unavailable.\",\n }),\n );\n return { sentUpdateIds, syncAttempt };\n}\n\n/**\n * Keep the full durable queue visible to stale-heal/checkpoint classification.\n * The workflow planner owns the final count and byte bounds, and the exact\n * materialized batch is pre-registered immediately before each submit.\n */\nexport function prepareDocumentStoreSyncQueue(\n pendingUpdates: PendingUpdateRecord[],\n): {\n planningUpdates: PendingUpdateRecord[];\n queuedUpdateCount: number;\n} {\n return {\n planningUpdates: pendingUpdates,\n queuedUpdateCount: pendingUpdates.length,\n };\n}\n\nexport function canSyncDetachedAttachmentBindings(\n record: DocumentRecord,\n pendingUpdateCount: number,\n): boolean {\n return (\n pendingUpdateCount === 0 &&\n (record.pullContinuation ?? null) === null &&\n !record.pullContinuationRecoveryRequired\n );\n}\n\nasync function syncDocumentState(\n state: DocumentStoreState,\n currentDoc: DocumentState,\n nextRecord: DocumentRecord,\n encapsulationKeyPair: EncapsulationKeyPair,\n generation: DocumentStoreSyncGeneration,\n): Promise<DocumentRecord> {\n // Snapshot the remote-update signal sequence before any await. The GET below\n // fetches server state as of its own snapshot; any remote event delivered\n // after this point describes an update that may not be in that response, so\n // finalizeDocumentSync must not clear the signal if this sequence has moved.\n const consumedRemoteUpdateSignalSeq = state.remoteUpdateSignalSeq;\n const wasRemoteProbe = state.remoteUpdatePending;\n let pendingUpdates = await listPendingUpdates(state);\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return state.record ?? nextRecord;\n }\n if (pendingUpdates.length === 0 && isDocumentStoreRemoteSyncBlocked(state)) {\n return nextRecord;\n }\n // Create the remote document even when nothing is queued to send: a note\n // created and never edited enqueues no updates, but its local row is still a\n // pending create the write queue reports — it must flush, not sit. Defer\n // while the container itself still awaits its remote create — with OR\n // without queued edits, since the create cannot succeed before its parent\n // exists and attempting it just records a spurious failure. The structural\n // lane primes this store again as soon as the container create lands.\n if (!nextRecord.documentId) {\n const containerAwaitsCreate = await isContainerAwaitingRemoteCreate(state);\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return state.record ?? nextRecord;\n }\n if (containerAwaitsCreate) return nextRecord;\n }\n let nextRemoteRecord = await ensureRemoteDocument(\n state,\n currentDoc,\n nextRecord,\n encapsulationKeyPair,\n generation,\n );\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return state.record ?? nextRecord;\n }\n if (!nextRemoteRecord?.documentId) return nextRecord;\n\n const preparedCoverage = await prepareDocumentOutgoingCoverage({\n currentDoc,\n generation,\n pendingUpdates,\n state,\n });\n if (!preparedCoverage) {\n requestDocumentStoreSync(state);\n return state.record ?? nextRemoteRecord;\n }\n nextRemoteRecord = preparedCoverage.record;\n pendingUpdates = preparedCoverage.pendingUpdates;\n\n if (\n shouldSkipCleanScheduledDocumentSync({\n currentRecord: nextRemoteRecord,\n pendingUpdates,\n state,\n })\n ) {\n return nextRemoteRecord;\n }\n\n // Pre-register the IDs we are about to send so the author's OWN\n // `document_update_created` echo (fanned back over redis) is classified as\n // self-authored and never re-arms a redundant sync. Registering BEFORE the\n // network await closes the race where the echo lands before\n // finalizeDocumentSync records the accepted IDs — the gap that turned every\n // fast keystroke into an extra self-triggered sync.\n const { sentUpdateIds, syncAttempt } = await requestOutgoingDocumentBatch({\n currentDoc,\n encapsulationKeyPair,\n generation,\n pendingUpdates,\n record: nextRemoteRecord,\n state,\n });\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n discardPreRegisteredUpdateIds(state, sentUpdateIds);\n requestDocumentStoreSync(state);\n return state.record ?? nextRemoteRecord;\n }\n if (!syncAttempt) {\n discardPreRegisteredUpdateIds(state, sentUpdateIds);\n logUnavailable(state, wasRemoteProbe);\n return nextRemoteRecord;\n }\n\n return cleanupPreRegisteredUpdateIdsOnFailure(state, sentUpdateIds, () =>\n finalizeDocumentSync(\n state,\n currentDoc,\n nextRemoteRecord,\n syncAttempt,\n consumedRemoteUpdateSignalSeq,\n generation,\n sentUpdateIds,\n wasRemoteProbe,\n ),\n );\n}\n\nasync function revalidateRemoteDocumentBeforeAttachments(\n state: DocumentStoreState,\n currentDoc: DocumentState,\n nextRecord: DocumentRecord,\n encapsulationKeyPair: EncapsulationKeyPair,\n generation: DocumentStoreSyncGeneration,\n): Promise<{ canSyncAttachments: boolean; nextRecord: DocumentRecord }> {\n if (state.pendingAttachments.length === 0 || !nextRecord.documentId) {\n return { canSyncAttachments: true, nextRecord };\n }\n\n const consumedRemoteUpdateSignalSeq = state.remoteUpdateSignalSeq;\n const wasRemoteProbe = state.remoteUpdatePending;\n const syncAttempt = await requestRemoteDocumentSync({\n state,\n currentDoc,\n currentRecord: nextRecord,\n encapsulationKeyPair,\n generation,\n pendingUpdates: [],\n unavailableWriterLogMessage:\n \"Documents: skipped pre-attachment revalidation because the writer context is unavailable.\",\n });\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return { canSyncAttachments: false, nextRecord };\n }\n if (!syncAttempt) {\n logUnavailable(state, wasRemoteProbe);\n return { canSyncAttachments: false, nextRecord };\n }\n\n const refreshedRecord = await finalizeDocumentSync(\n state,\n currentDoc,\n nextRecord,\n syncAttempt,\n consumedRemoteUpdateSignalSeq,\n generation,\n [],\n wasRemoteProbe,\n );\n return {\n canSyncAttachments:\n !syncAttempt.synced.hasIncompletePull &&\n refreshedRecord.pullContinuation == null &&\n refreshedRecord.pullContinuationRecoveryRequired !== true &&\n isDocumentStoreSyncGenerationCurrent(state, generation),\n nextRecord: refreshedRecord,\n };\n}\n\nasync function runDocumentSyncPass(\n state: DocumentStoreState,\n syncLaneGeneration: DocumentStoreSyncLaneGeneration,\n) {\n const currentDoc = state.doc;\n const encapsulationKeyPair = state.runtime.crypto.encapsulationKeyPair;\n let nextRecord = state.record;\n\n if (!currentDoc || !nextRecord || !encapsulationKeyPair) {\n return;\n }\n\n const generation = captureDocumentStoreRemoteSyncGeneration(\n state,\n currentDoc,\n syncLaneGeneration,\n );\n const attachmentGeneration = captureDocumentStoreAttachmentSyncGeneration(\n state,\n currentDoc,\n syncLaneGeneration,\n );\n if (!generation || !attachmentGeneration) {\n requestDocumentStoreSync(state);\n return;\n }\n\n const revalidation = await revalidateRemoteDocumentBeforeAttachments(\n state,\n currentDoc,\n nextRecord,\n encapsulationKeyPair,\n generation,\n );\n nextRecord = revalidation.nextRecord;\n if (!revalidation.canSyncAttachments) {\n return;\n }\n\n const attachmentResult = await syncPendingAttachments(\n state,\n nextRecord,\n encapsulationKeyPair,\n attachmentGeneration,\n );\n nextRecord = attachmentResult.nextRecord;\n if (state.pendingAttachments.length > 0) {\n return;\n }\n // A settled bind and the content update carrying its digest are two server\n // writes. Push the content in this same pass rather than re-arming a later\n // one, so a device lost between them is the only remaining window: peers\n // otherwise see the old digest against the new binding.\n\n nextRecord = await syncDocumentState(\n state,\n currentDoc,\n nextRecord,\n encapsulationKeyPair,\n generation,\n );\n\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return;\n }\n\n if (!state.doc || !state.record) return;\n\n const pendingUpdates = await listPendingUpdates(state);\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n return;\n }\n if (!canSyncDetachedAttachmentBindings(nextRecord, pendingUpdates.length)) {\n return;\n }\n\n await syncDetachedAttachmentBindings(state, nextRecord, generation);\n if (!isDocumentStoreSyncGenerationCurrent(state, generation)) {\n requestDocumentStoreSync(state);\n }\n}\n\nasync function runScheduledSyncIteration(\n state: DocumentStoreState,\n syncLaneGeneration: DocumentStoreSyncLaneGeneration,\n) {\n if (!(await awaitInitializationForSync(state))) {\n return false;\n }\n if (!isDocumentStoreSyncLaneGenerationCurrent(state, syncLaneGeneration)) {\n return true;\n }\n\n if (!canRunScheduledSync(state)) {\n return true;\n }\n\n try {\n await runDocumentSyncPass(state, syncLaneGeneration);\n return true;\n } catch (error) {\n if (isDatabaseUnavailableError(error)) {\n return false;\n }\n\n await reportAndRethrowKeyingVerificationError(\n error,\n state.runtime.util.reportSecurityIncident,\n {\n objectId: state.record?.documentId ?? state.localId,\n objectKind: \"document\",\n operation: \"document.sync\",\n },\n );\n\n throw error;\n }\n}\n\nasync function runScheduledSyncLoop(\n state: DocumentStoreState,\n syncLaneGeneration: DocumentStoreSyncLaneGeneration,\n) {\n const syncingGeneration = captureDocumentStoreSyncGeneration(\n state,\n state.doc,\n );\n setDocumentSyncing(state, true);\n\n try {\n await runScheduledSyncIteration(state, syncLaneGeneration);\n } finally {\n if (\n syncingGeneration &&\n isDocumentStoreSyncGenerationCurrent(state, syncingGeneration) &&\n isDocumentStoreSyncLaneGenerationCurrent(state, syncLaneGeneration)\n ) {\n setDocumentSyncing(state, false);\n }\n }\n}\n\nexport function registerDocumentStoreSyncLane(\n state: DocumentStoreState,\n getSyncLaneGeneration: () => DocumentStoreSyncLaneGeneration | null,\n): DocumentSyncLane {\n return registerDocumentSyncLane({\n domainScope: state.runtime.state.domainScope,\n localId: state.localId,\n priority: () =>\n state.remoteUpdatePending || state.record?.snapshotEndVersion === \"\"\n ? -1\n : 0,\n logError: (message, error) => {\n // Read the runtime lazily: a store's runtime is replaced in place, and a\n // reference captured here would report into a torn-down host.\n const { log, logError } = state.runtime.util;\n // Return the host's result: both callbacks are declared `=> void` but may\n // be async, and the lane reporter only catches a rejection it is handed.\n return logError ? logError(message, error) : log(message);\n },\n run: () => {\n const syncLaneGeneration = getSyncLaneGeneration();\n if (!syncLaneGeneration) return Promise.resolve();\n const activeWork = getActiveDocumentRemoteWork(state);\n if (activeWork) {\n // Re-arm on settlement, not immediately: immediate re-requests would\n // spin this lane and starve other work while the HTTP request is held.\n void activeWork.then(() => {\n if (\n isDocumentStoreSyncLaneGenerationCurrent(state, syncLaneGeneration)\n ) {\n requestDocumentStoreSync(state);\n }\n });\n return Promise.resolve();\n }\n return runDocumentRemoteWork(state, () =>\n isDocumentStoreSyncLaneGenerationCurrent(state, syncLaneGeneration)\n ? runScheduledSyncLoop(state, syncLaneGeneration)\n : Promise.resolve(),\n );\n },\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncAcceptedUpdateIds.js","sourceRoot":"","sources":["syncAcceptedUpdateIds.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,6BAA6B,CAC3C,KAAyB,EACzB,aAAgC;IAEhC,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,KAAyB,EACzB,cAAsD;IAEtD,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChE,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,KAAK,CAAC,wBAAwB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,4CAA4C,CAC1D,KAAyB,EACzB,mBAA6B,EAC7B,qBAAwC;IAExC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACvD,MAAM,cAAc,GAAG,qBAAqB,CAAC,MAAM,CACjD,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAC/C,CAAC;IACF,mBAAmB,CAAC,IAAI,CACtB,GAAG,oBAAoB,CACrB,KAAK,EACL,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CACrC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,KAAyB,EACzB,aAAgC,EAChC,iBAAoC;IAEpC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC5C,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sCAAsC,CAC1D,KAAyB,EACzB,aAAgC,EAChC,IAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6BAA6B,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { DocumentStoreState } from \"./state\";\n\nexport function discardPreRegisteredUpdateIds(\n state: DocumentStoreState,\n sentUpdateIds: readonly string[],\n): void {\n for (const sentUpdateId of sentUpdateIds) {\n state.locallyAcceptedUpdateIds.delete(sentUpdateId);\n }\n}\n\nfunction preRegisterUpdateIds(\n state: DocumentStoreState,\n pendingUpdates: ReadonlyArray<{ readonly id: string }>,\n): string[] {\n const sentUpdateIds = pendingUpdates.map((update) => update.id);\n for (const sentUpdateId of sentUpdateIds) {\n state.locallyAcceptedUpdateIds.add(sentUpdateId);\n }\n return sentUpdateIds;\n}\n\nexport function preRegisterMaterializedDocumentSyncUpdateIds(\n state: DocumentStoreState,\n registeredUpdateIds: string[],\n materializedUpdateIds: readonly string[],\n): void {\n const alreadyRegistered = new Set(registeredUpdateIds);\n const freshUpdateIds = materializedUpdateIds.filter(\n (updateId) => !alreadyRegistered.has(updateId),\n );\n registeredUpdateIds.push(\n ...preRegisterUpdateIds(\n state,\n freshUpdateIds.map((id) => ({ id })),\n ),\n );\n}\n\nexport function discardUnacceptedPreRegisteredUpdateIds(\n state: DocumentStoreState,\n sentUpdateIds: readonly string[],\n acceptedUpdateIds: readonly string[],\n): void {\n const accepted = new Set(acceptedUpdateIds);\n for (const sentUpdateId of sentUpdateIds) {\n if (!accepted.has(sentUpdateId)) {\n state.locallyAcceptedUpdateIds.delete(sentUpdateId);\n }\n }\n}\n\nexport async function cleanupPreRegisteredUpdateIdsOnFailure<T>(\n state: DocumentStoreState,\n sentUpdateIds: readonly string[],\n task: () => Promise<T>,\n): Promise<T> {\n try {\n return await task();\n } catch (error) {\n discardPreRegisteredUpdateIds(state, sentUpdateIds);\n throw error;\n }\n}\n"]}
|