@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.
Files changed (616) hide show
  1. package/data/documents/blob/shared/projection.js +1 -1
  2. package/data/documents/blob/shared/projection.js.map +1 -1
  3. package/data/documents/shared/projectionContentKeys.js +1 -1
  4. package/data/documents/shared/projectionContentKeys.js.map +1 -1
  5. package/data/documents/shared/syncResponseAuthorization.js +1 -1
  6. package/data/documents/shared/syncResponseAuthorization.js.map +1 -1
  7. package/data/keyingProjectionVerification/{accessManifestCheckpointEnforcement.js → checkpoints/accessManifestCheckpointEnforcement.js} +2 -2
  8. package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js.map +1 -0
  9. package/data/keyingProjectionVerification/{bundleVerification.js → checkpoints/bundleVerification.js} +5 -5
  10. package/data/keyingProjectionVerification/checkpoints/bundleVerification.js.map +1 -0
  11. package/data/keyingProjectionVerification/{checkpointContext.d.ts → checkpoints/checkpointContext.d.ts} +6 -6
  12. package/data/keyingProjectionVerification/{checkpointContext.js → checkpoints/checkpointContext.js} +6 -6
  13. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -0
  14. package/data/keyingProjectionVerification/{manifestCheckpointVerification.js → checkpoints/manifestCheckpointVerification.js} +2 -2
  15. package/data/keyingProjectionVerification/checkpoints/manifestCheckpointVerification.js.map +1 -0
  16. package/data/keyingProjectionVerification/{containerAncestorCitations.js → container/containerAncestorCitations.js} +4 -4
  17. package/data/keyingProjectionVerification/container/containerAncestorCitations.js.map +1 -0
  18. package/data/keyingProjectionVerification/{containerCreateManifest.js → container/containerCreateManifest.js} +1 -1
  19. package/data/keyingProjectionVerification/{containerDestinationVerification.js → container/containerDestinationVerification.js} +4 -4
  20. package/data/keyingProjectionVerification/container/containerDestinationVerification.js.map +1 -0
  21. package/data/keyingProjectionVerification/{containerManifestVerification.js → container/containerManifestVerification.js} +7 -7
  22. package/data/keyingProjectionVerification/container/containerManifestVerification.js.map +1 -0
  23. package/data/keyingProjectionVerification/{containerPathVerification.js → container/containerPathVerification.js} +2 -2
  24. package/data/keyingProjectionVerification/container/containerPathVerification.js.map +1 -0
  25. package/data/keyingProjectionVerification/{containerProjectionVerification.d.ts → container/containerProjectionVerification.d.ts} +7 -7
  26. package/data/keyingProjectionVerification/{containerProjectionVerification.js → container/containerProjectionVerification.js} +9 -9
  27. package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -0
  28. package/data/keyingProjectionVerification/{documentDependencyPaths.d.ts → document/documentDependencyPaths.d.ts} +1 -1
  29. package/data/keyingProjectionVerification/{documentDependencyPaths.js → document/documentDependencyPaths.js} +3 -3
  30. package/data/keyingProjectionVerification/document/documentDependencyPaths.js.map +1 -0
  31. package/data/keyingProjectionVerification/{documentManifestPolicies.js → document/documentManifestPolicies.js} +2 -2
  32. package/data/keyingProjectionVerification/document/documentManifestPolicies.js.map +1 -0
  33. package/data/keyingProjectionVerification/{documentManifestPredecessor.js → document/documentManifestPredecessor.js} +1 -1
  34. package/data/keyingProjectionVerification/{documentManifestVerification.js → document/documentManifestVerification.js} +5 -5
  35. package/data/keyingProjectionVerification/document/documentManifestVerification.js.map +1 -0
  36. package/data/keyingProjectionVerification/{documentProjectionVerification.d.ts → document/documentProjectionVerification.d.ts} +4 -4
  37. package/data/keyingProjectionVerification/{documentProjectionVerification.js → document/documentProjectionVerification.js} +9 -9
  38. package/data/keyingProjectionVerification/document/documentProjectionVerification.js.map +1 -0
  39. package/data/keyingProjectionVerification/{documentPurgeCheckpointCurrency.js → documentPurge/documentPurgeCheckpointCurrency.js} +12 -12
  40. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointCurrency.js.map +1 -0
  41. package/data/keyingProjectionVerification/{documentPurgeCheckpointEnforcement.js → documentPurge/documentPurgeCheckpointEnforcement.js} +2 -2
  42. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointEnforcement.js.map +1 -0
  43. package/data/keyingProjectionVerification/{documentPurgeDocumentChainVerification.js → documentPurge/documentPurgeDocumentChainVerification.js} +8 -8
  44. package/data/keyingProjectionVerification/documentPurge/documentPurgeDocumentChainVerification.js.map +1 -0
  45. package/data/keyingProjectionVerification/{documentPurgePolicyCheckpoints.js → documentPurge/documentPurgePolicyCheckpoints.js} +2 -2
  46. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCheckpoints.js.map +1 -0
  47. package/data/keyingProjectionVerification/{documentPurgePolicyCurrency.js → documentPurge/documentPurgePolicyCurrency.js} +4 -4
  48. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCurrency.js.map +1 -0
  49. package/data/keyingProjectionVerification/{documentPurgePrincipalEvidence.js → documentPurge/documentPurgePrincipalEvidence.js} +3 -3
  50. package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js.map +1 -0
  51. package/data/keyingProjectionVerification/{documentPurgeProofVerification.d.ts → documentPurge/documentPurgeProofVerification.d.ts} +5 -5
  52. package/data/keyingProjectionVerification/{documentPurgeProofVerification.js → documentPurge/documentPurgeProofVerification.js} +10 -10
  53. package/data/keyingProjectionVerification/documentPurge/documentPurgeProofVerification.js.map +1 -0
  54. package/data/keyingProjectionVerification/index.d.ts +4 -4
  55. package/data/keyingProjectionVerification/index.js +4 -4
  56. package/data/keyingProjectionVerification/index.js.map +1 -1
  57. package/data/keyingProjectionVerification/{mergeProjectionPolicyEvidence.js → principalPolicy/mergeProjectionPolicyEvidence.js} +2 -2
  58. package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -0
  59. package/data/keyingProjectionVerification/{organizationFounderBinding.js → principalPolicy/organizationFounderBinding.js} +3 -3
  60. package/data/keyingProjectionVerification/principalPolicy/organizationFounderBinding.js.map +1 -0
  61. package/data/keyingProjectionVerification/{principalPolicyCache.js → principalPolicy/principalPolicyCache.js} +6 -6
  62. package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js.map +1 -0
  63. package/data/keyingProjectionVerification/{principalPolicyVerification.js → principalPolicy/principalPolicyVerification.js} +12 -12
  64. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map +1 -0
  65. package/data/keyingProjectionVerification/{projectionAuthorizationEvidence.js → principalPolicy/projectionAuthorizationEvidence.js} +3 -3
  66. package/data/keyingProjectionVerification/principalPolicy/projectionAuthorizationEvidence.js.map +1 -0
  67. package/data/keyingProjectionVerification/{projectionPolicyEvidence.js → principalPolicy/projectionPolicyEvidence.js} +3 -3
  68. package/data/keyingProjectionVerification/principalPolicy/projectionPolicyEvidence.js.map +1 -0
  69. package/data/keyingProjectionVerification/{resolvedPrincipalPolicy.js → principalPolicy/resolvedPrincipalPolicy.js} +6 -6
  70. package/data/keyingProjectionVerification/principalPolicy/resolvedPrincipalPolicy.js.map +1 -0
  71. package/package.json +1 -1
  72. package/stores/container-contents/accessRestorationSweep.js +1 -1
  73. package/stores/container-contents/accessRestorationSweep.js.map +1 -1
  74. package/stores/container-contents/containerContentsStore.d.ts +1 -1
  75. package/stores/container-contents/containerContentsStore.js +12 -12
  76. package/stores/container-contents/containerContentsStore.js.map +1 -1
  77. package/stores/container-contents/containerState/containerStateMap.js.map +1 -0
  78. package/stores/container-contents/{containerStatePersistence.js → containerState/containerStatePersistence.js} +2 -2
  79. package/stores/container-contents/containerState/containerStatePersistence.js.map +1 -0
  80. package/stores/container-contents/{missingContainerState.js → containerState/missingContainerState.js} +1 -1
  81. package/stores/container-contents/containerState/missingContainerState.js.map +1 -0
  82. package/stores/container-contents/containerState/missingSyncedContainerState.js.map +1 -0
  83. package/stores/container-contents/{reconcilableContainer.d.ts → containerState/reconcilableContainer.d.ts} +1 -1
  84. package/stores/container-contents/containerState/reconcilableContainer.js.map +1 -0
  85. package/stores/container-contents/{documentRecovery.js → documentWork/documentRecovery.js} +6 -6
  86. package/stores/container-contents/documentWork/documentRecovery.js.map +1 -0
  87. package/stores/container-contents/{documentRotation.js → documentWork/documentRotation.js} +2 -2
  88. package/stores/container-contents/documentWork/documentRotation.js.map +1 -0
  89. package/stores/container-contents/{documentWork.js → documentWork/index.js} +1 -1
  90. package/stores/container-contents/documentWork/index.js.map +1 -0
  91. package/stores/container-contents/{backgroundHydration.js → hydration/backgroundHydration.js} +3 -3
  92. package/stores/container-contents/hydration/backgroundHydration.js.map +1 -0
  93. package/stores/container-contents/{remoteHydrationRequest.js → hydration/remoteHydrationRequest.js} +3 -3
  94. package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -0
  95. package/stores/container-contents/{startupHydration.js → hydration/startupHydration.js} +3 -3
  96. package/stores/container-contents/hydration/startupHydration.js.map +1 -0
  97. package/stores/container-contents/index.d.ts +3 -3
  98. package/stores/container-contents/index.js +2 -2
  99. package/stores/container-contents/index.js.map +1 -1
  100. package/stores/container-contents/localRefresh.js +2 -2
  101. package/stores/container-contents/localRefresh.js.map +1 -1
  102. package/stores/container-contents/{containerPurgeCore.js → operations/containerPurgeCore.js} +4 -4
  103. package/stores/container-contents/operations/containerPurgeCore.js.map +1 -0
  104. package/stores/container-contents/operations/emptyTrashOperation.js.map +1 -0
  105. package/stores/container-contents/{groupRewrapOperation.js → operations/groupRewrapOperation.js} +2 -2
  106. package/stores/container-contents/operations/groupRewrapOperation.js.map +1 -0
  107. package/stores/container-contents/{operations.js → operations/index.js} +18 -18
  108. package/stores/container-contents/operations/index.js.map +1 -0
  109. package/stores/container-contents/operations/purgeContainerOperation.js.map +1 -0
  110. package/stores/container-contents/{reportShareFailure.js → operations/reportShareFailure.js} +4 -4
  111. package/stores/container-contents/operations/reportShareFailure.js.map +1 -0
  112. package/stores/container-contents/{setContainerIconOperation.js → operations/setContainerIconOperation.js} +6 -6
  113. package/stores/container-contents/operations/setContainerIconOperation.js.map +1 -0
  114. package/stores/container-contents/{shareOperations.js → operations/shareOperations.js} +6 -6
  115. package/stores/container-contents/operations/shareOperations.js.map +1 -0
  116. package/stores/container-contents/remoteEvents/remoteBackedContainerState.js.map +1 -0
  117. package/stores/container-contents/{remoteContainerIngestion.js → remoteEvents/remoteContainerIngestion.js} +4 -4
  118. package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -0
  119. package/stores/container-contents/{remoteEventProjectionInvalidation.js → remoteEvents/remoteEventProjectionInvalidation.js} +1 -1
  120. package/stores/container-contents/remoteEvents/remoteEventProjectionInvalidation.js.map +1 -0
  121. package/stores/container-contents/{remoteEventSync.js → remoteEvents/remoteEventSync.js} +4 -4
  122. package/stores/container-contents/remoteEvents/remoteEventSync.js.map +1 -0
  123. package/stores/container-contents/{remoteWriteGuards.js → remoteWrites/remoteWriteGuards.js} +2 -2
  124. package/stores/container-contents/remoteWrites/remoteWriteGuards.js.map +1 -0
  125. package/stores/container-contents/{remoteWriteQueue.js → remoteWrites/remoteWriteQueue.js} +1 -1
  126. package/stores/container-contents/remoteWrites/remoteWriteQueue.js.map +1 -0
  127. package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -0
  128. package/stores/container-contents/state.d.ts +1 -1
  129. package/stores/container-contents/state.js +2 -2
  130. package/stores/container-contents/state.js.map +1 -1
  131. package/stores/container-contents/{syncAgent.d.ts → syncAgent/index.d.ts} +2 -2
  132. package/stores/container-contents/{syncAgent.js → syncAgent/index.js} +14 -14
  133. package/stores/container-contents/syncAgent/index.js.map +1 -0
  134. package/stores/container-contents/{metadataSyncSignal.js → syncAgent/metadataSyncSignal.js} +1 -1
  135. package/stores/container-contents/{metadataSyncSignal.js.map → syncAgent/metadataSyncSignal.js.map} +1 -1
  136. package/stores/container-contents/{syncAgentTypes.d.ts → syncAgent/syncAgentTypes.d.ts} +5 -5
  137. package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -0
  138. package/stores/container-contents/{syncLaneIteration.js → syncAgent/syncLaneIteration.js} +11 -11
  139. package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -0
  140. package/stores/container-contents/{existingSystemContainer.js → systemContainers/existingSystemContainer.js} +4 -4
  141. package/stores/container-contents/systemContainers/existingSystemContainer.js.map +1 -0
  142. package/stores/container-contents/{organizationMetadataSystemContainer.js → systemContainers/organizationMetadataSystemContainer.js} +2 -2
  143. package/stores/container-contents/systemContainers/organizationMetadataSystemContainer.js.map +1 -0
  144. package/stores/container-contents/{systemContainerHydration.js → systemContainers/systemContainerHydration.js} +3 -3
  145. package/stores/container-contents/systemContainers/systemContainerHydration.js.map +1 -0
  146. package/stores/container-contents/{systemContainerIcon.js → systemContainers/systemContainerIcon.js} +5 -5
  147. package/stores/container-contents/systemContainers/systemContainerIcon.js.map +1 -0
  148. package/stores/container-contents/systemContainers/systemContainerLookup.js.map +1 -0
  149. package/stores/container-contents/{systemContainerPostCreate.js → systemContainers/systemContainerPostCreate.js} +2 -2
  150. package/stores/container-contents/systemContainers/systemContainerPostCreate.js.map +1 -0
  151. package/stores/container-contents/{systemContainerPromotion.js → systemContainers/systemContainerPromotion.js} +1 -1
  152. package/stores/container-contents/systemContainers/systemContainerPromotion.js.map +1 -0
  153. package/stores/container-contents/types.d.ts +2 -2
  154. package/stores/container-contents/types.js.map +1 -1
  155. package/stores/documents/documentStore/{attachmentSourceUpload.js → attachmentUpload/attachmentSourceUpload.js} +4 -4
  156. package/stores/documents/documentStore/attachmentUpload/attachmentSourceUpload.js.map +1 -0
  157. package/stores/documents/documentStore/{attachmentStaging.js → attachmentUpload/attachmentStaging.js} +5 -5
  158. package/stores/documents/documentStore/attachmentUpload/attachmentStaging.js.map +1 -0
  159. package/stores/documents/documentStore/{attachmentUploadAttempt.js → attachmentUpload/attachmentUploadAttempt.js} +2 -2
  160. package/stores/documents/documentStore/attachmentUpload/attachmentUploadAttempt.js.map +1 -0
  161. package/stores/documents/documentStore/{attachmentUploadLane.js → attachmentUpload/attachmentUploadLane.js} +1 -1
  162. package/stores/documents/documentStore/attachmentUpload/attachmentUploadLane.js.map +1 -0
  163. package/stores/documents/documentStore/{attachmentUploadResume.js → attachmentUpload/attachmentUploadResume.js} +4 -4
  164. package/stores/documents/documentStore/attachmentUpload/attachmentUploadResume.js.map +1 -0
  165. package/stores/documents/documentStore/{attachmentDetachState.js → attachments/attachmentDetachState.js} +1 -1
  166. package/stores/documents/documentStore/attachments/attachmentDetachState.js.map +1 -0
  167. package/stores/documents/documentStore/{attachmentHydration.js → attachments/attachmentHydration.js} +5 -5
  168. package/stores/documents/documentStore/attachments/attachmentHydration.js.map +1 -0
  169. package/stores/documents/documentStore/{attachmentHydrationCommit.js → attachments/attachmentHydrationCommit.js} +3 -3
  170. package/stores/documents/documentStore/attachments/attachmentHydrationCommit.js.map +1 -0
  171. package/stores/documents/documentStore/{attachmentIntents.js → attachments/attachmentIntents.js} +2 -2
  172. package/stores/documents/documentStore/attachments/attachmentIntents.js.map +1 -0
  173. package/stores/documents/documentStore/{attachmentMutationPersistence.js → attachments/attachmentMutationPersistence.js} +4 -4
  174. package/stores/documents/documentStore/attachments/attachmentMutationPersistence.js.map +1 -0
  175. package/stores/documents/documentStore/attachments/attachmentPersistFollowup.js.map +1 -0
  176. package/stores/documents/documentStore/{attachmentPersistence.js → attachments/attachmentPersistence.js} +4 -4
  177. package/stores/documents/documentStore/attachments/attachmentPersistence.js.map +1 -0
  178. package/stores/documents/documentStore/{attachmentRemoval.js → attachments/attachmentRemoval.js} +11 -11
  179. package/stores/documents/documentStore/attachments/attachmentRemoval.js.map +1 -0
  180. package/stores/documents/documentStore/attachments/attachmentSnapshot.js.map +1 -0
  181. package/stores/documents/documentStore/{attachmentWriteGeneration.js → attachments/attachmentWriteGeneration.js} +2 -2
  182. package/stores/documents/documentStore/attachments/attachmentWriteGeneration.js.map +1 -0
  183. package/stores/documents/documentStore/{attachments.js → attachments/index.js} +11 -11
  184. package/stores/documents/documentStore/attachments/index.js.map +1 -0
  185. package/stores/documents/documentStore/{documentHistoryCompaction.js → history/documentHistoryCompaction.js} +4 -4
  186. package/stores/documents/documentStore/history/documentHistoryCompaction.js.map +1 -0
  187. package/stores/documents/documentStore/{durableDocumentReload.js → history/durableDocumentReload.js} +6 -6
  188. package/stores/documents/documentStore/history/durableDocumentReload.js.map +1 -0
  189. package/stores/documents/documentStore/{historyRebuild.js → history/historyRebuild.js} +6 -6
  190. package/stores/documents/documentStore/history/historyRebuild.js.map +1 -0
  191. package/stores/documents/{documentStore.d.ts → documentStore/index.d.ts} +5 -5
  192. package/stores/documents/{documentStore.js → documentStore/index.js} +18 -18
  193. package/stores/documents/documentStore/index.js.map +1 -0
  194. package/stores/documents/documentStore/{deferredInitialUpdate.js → initialization/deferredInitialUpdate.js} +9 -9
  195. package/stores/documents/documentStore/initialization/deferredInitialUpdate.js.map +1 -0
  196. package/stores/documents/documentStore/{initialization.js → initialization/index.js} +14 -14
  197. package/stores/documents/documentStore/initialization/index.js.map +1 -0
  198. package/stores/documents/documentStore/{initializationAttachments.js → initialization/initializationAttachments.js} +1 -1
  199. package/stores/documents/documentStore/initialization/initializationAttachments.js.map +1 -0
  200. package/stores/documents/documentStore/{initializationHistory.js → initialization/initializationHistory.js} +3 -3
  201. package/stores/documents/documentStore/initialization/initializationHistory.js.map +1 -0
  202. package/stores/documents/documentStore/{initializationRecovery.js → initialization/initializationRecovery.js} +7 -7
  203. package/stores/documents/documentStore/initialization/initializationRecovery.js.map +1 -0
  204. package/stores/documents/documentStore/mutationIdentityRevalidation.js.map +1 -1
  205. package/stores/documents/documentStore/mutations.js +2 -2
  206. package/stores/documents/documentStore/mutations.js.map +1 -1
  207. package/stores/documents/documentStore/pendingUpdateRefusal.js +1 -1
  208. package/stores/documents/documentStore/pendingUpdateRefusal.js.map +1 -1
  209. package/stores/documents/documentStore/persistence.js +3 -3
  210. package/stores/documents/documentStore/persistence.js.map +1 -1
  211. package/stores/documents/documentStore/{rotation.js → rotation/index.js} +14 -14
  212. package/stores/documents/documentStore/rotation/index.js.map +1 -0
  213. package/stores/documents/documentStore/{rotationProvenance.js → rotation/rotationProvenance.js} +2 -2
  214. package/stores/documents/documentStore/rotation/rotationProvenance.js.map +1 -0
  215. package/stores/documents/documentStore/{rotationSettlement.js → rotation/rotationSettlement.js} +9 -9
  216. package/stores/documents/documentStore/rotation/rotationSettlement.js.map +1 -0
  217. package/stores/documents/documentStore/rows.js +2 -2
  218. package/stores/documents/documentStore/rows.js.map +1 -1
  219. package/stores/documents/documentStore/state.js +1 -1
  220. package/stores/documents/documentStore/state.js.map +1 -1
  221. package/stores/documents/documentStore/{sync.js → sync/index.js} +7 -7
  222. package/stores/documents/documentStore/sync/index.js.map +1 -0
  223. package/stores/documents/documentStore/{pullContinuationInvalidation.js → sync/pullContinuationInvalidation.js} +3 -3
  224. package/stores/documents/documentStore/sync/pullContinuationInvalidation.js.map +1 -0
  225. package/stores/documents/documentStore/{remoteRevalidationTelemetry.js → sync/remoteRevalidationTelemetry.js} +1 -1
  226. package/stores/documents/documentStore/sync/remoteRevalidationTelemetry.js.map +1 -0
  227. package/stores/documents/documentStore/sync/remoteWork.js.map +1 -0
  228. package/stores/documents/documentStore/sync/syncAcceptedUpdateIds.js.map +1 -0
  229. package/stores/documents/documentStore/{syncAttachmentSettlement.js → sync/syncAttachmentSettlement.js} +3 -3
  230. package/stores/documents/documentStore/sync/syncAttachmentSettlement.js.map +1 -0
  231. package/stores/documents/documentStore/{syncAttachments.js → sync/syncAttachments.js} +7 -7
  232. package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -0
  233. package/stores/documents/documentStore/{syncDetachedAttachments.js → sync/syncDetachedAttachments.js} +7 -7
  234. package/stores/documents/documentStore/sync/syncDetachedAttachments.js.map +1 -0
  235. package/stores/documents/documentStore/{syncFinalize.js → sync/syncFinalize.js} +9 -9
  236. package/stores/documents/documentStore/sync/syncFinalize.js.map +1 -0
  237. package/stores/documents/documentStore/sync/syncGeneration.js.map +1 -0
  238. package/stores/documents/documentStore/{syncOutgoingCoverage.js → sync/syncOutgoingCoverage.js} +4 -4
  239. package/stores/documents/documentStore/sync/syncOutgoingCoverage.js.map +1 -0
  240. package/stores/documents/documentStore/{syncRemoteSignals.js → sync/syncRemoteSignals.js} +4 -4
  241. package/stores/documents/documentStore/sync/syncRemoteSignals.js.map +1 -0
  242. package/stores/documents/documentStore/{syncRequest.js → sync/syncRequest.js} +8 -8
  243. package/stores/documents/documentStore/sync/syncRequest.js.map +1 -0
  244. package/stores/documents/documentStore/{syncShared.js → sync/syncShared.js} +8 -8
  245. package/stores/documents/documentStore/sync/syncShared.js.map +1 -0
  246. package/stores/documents/documentStore/{syncUpdateImport.js → sync/syncUpdateImport.js} +3 -3
  247. package/stores/documents/documentStore/sync/syncUpdateImport.js.map +1 -0
  248. package/stores/documents/documentStore/{versionCoverage.js → sync/versionCoverage.js} +1 -1
  249. package/stores/documents/index.d.ts +1 -1
  250. package/stores/documents/index.js +1 -1
  251. package/stores/local-projection/localProjectionStore.d.ts +1 -1
  252. package/stores/local-projection/localProjectionStore.js +1 -1
  253. package/stores/local-projection/localProjectionStore.js.map +1 -1
  254. package/stores/local-projection/registry.d.ts +1 -1
  255. package/stores/local-projection/types.d.ts +1 -1
  256. package/workflows/blobs/hydration/decrypt.js +1 -1
  257. package/workflows/blobs/hydration/decrypt.js.map +1 -1
  258. package/workflows/container-contents/container-state/{createAdoption.js → create/createAdoption.js} +6 -6
  259. package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -0
  260. package/workflows/container-contents/container-state/{createChild.js → create/createChild.js} +7 -7
  261. package/workflows/container-contents/container-state/create/createChild.js.map +1 -0
  262. package/workflows/container-contents/container-state/{createIntentDepth.js → create/createIntentDepth.js} +2 -2
  263. package/workflows/container-contents/container-state/create/createIntentDepth.js.map +1 -0
  264. package/workflows/container-contents/container-state/create/createIntentSettlement.js.map +1 -0
  265. package/workflows/container-contents/container-state/{createIntentSync.js → create/createIntentSync.js} +7 -7
  266. package/workflows/container-contents/container-state/create/createIntentSync.js.map +1 -0
  267. package/workflows/container-contents/container-state/{createTerminalFailure.js → create/createTerminalFailure.js} +2 -2
  268. package/workflows/container-contents/container-state/create/createTerminalFailure.js.map +1 -0
  269. package/workflows/container-contents/container-state/{createWithMetadata.js → create/createWithMetadata.js} +9 -9
  270. package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -0
  271. package/workflows/container-contents/container-state/{createWithMetadataPlan.js → create/createWithMetadataPlan.js} +4 -4
  272. package/workflows/container-contents/container-state/create/createWithMetadataPlan.js.map +1 -0
  273. package/workflows/container-contents/container-state/{localPurgeScope.js → purge/localPurgeScope.js} +1 -1
  274. package/workflows/container-contents/container-state/purge/localPurgeScope.js.map +1 -0
  275. package/workflows/container-contents/container-state/{purgeTree.js → purge/purgeTree.js} +5 -5
  276. package/workflows/container-contents/container-state/purge/purgeTree.js.map +1 -0
  277. package/workflows/container-contents/container-state/purge/purgeTreeCollection.js.map +1 -0
  278. package/workflows/container-contents/container-state/{purgeTreeContainerDeletion.js → purge/purgeTreeContainerDeletion.js} +1 -1
  279. package/workflows/container-contents/container-state/purge/purgeTreeContainerDeletion.js.map +1 -0
  280. package/workflows/container-contents/container-state/{purgeTreeScope.js → purge/purgeTreeScope.js} +8 -8
  281. package/workflows/container-contents/container-state/purge/purgeTreeScope.js.map +1 -0
  282. package/workflows/container-contents/container-state/{readLocalPurgeScope.js → purge/readLocalPurgeScope.js} +3 -3
  283. package/workflows/container-contents/container-state/purge/readLocalPurgeScope.js.map +1 -0
  284. package/workflows/container-contents/container-state/remote.js +2 -2
  285. package/workflows/container-contents/container-state/remote.js.map +1 -1
  286. package/workflows/container-contents/container-state/{groupGrantVerification.js → share/groupGrantVerification.js} +8 -8
  287. package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -0
  288. package/workflows/container-contents/container-state/{groupShareEpoch.js → share/groupShareEpoch.js} +2 -2
  289. package/workflows/container-contents/container-state/share/groupShareEpoch.js.map +1 -0
  290. package/workflows/container-contents/container-state/{share.js → share/index.js} +8 -8
  291. package/workflows/container-contents/container-state/share/index.js.map +1 -0
  292. package/workflows/container-contents/container-state/{sharePersistence.js → share/sharePersistence.js} +3 -3
  293. package/workflows/container-contents/container-state/share/sharePersistence.js.map +1 -0
  294. package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js +1 -1
  295. package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js.map +1 -1
  296. package/workflows/container-contents/documentDiscovery/index.js +1 -1
  297. package/workflows/container-contents/documentDiscovery/index.js.map +1 -1
  298. package/workflows/container-contents/metadata/metadataSyncErrors.js +1 -1
  299. package/workflows/container-contents/metadata/metadataSyncErrors.js.map +1 -1
  300. package/workflows/container-contents/remoteHydration/destination/destinationPrefetch.js.map +1 -0
  301. package/workflows/container-contents/remoteHydration/destination/destinationRoleCache.js.map +1 -0
  302. package/workflows/container-contents/remoteHydration/{destinationRootReload.js → destination/destinationRootReload.js} +1 -1
  303. package/workflows/container-contents/remoteHydration/destination/destinationRootReload.js.map +1 -0
  304. package/workflows/container-contents/remoteHydration/{replacementBinding.js → destination/replacementBinding.js} +5 -5
  305. package/workflows/container-contents/remoteHydration/destination/replacementBinding.js.map +1 -0
  306. package/workflows/container-contents/remoteHydration/{verifiedDestination.js → destination/verifiedDestination.js} +9 -9
  307. package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -0
  308. package/workflows/container-contents/remoteHydration/index.js +4 -4
  309. package/workflows/container-contents/remoteHydration/index.js.map +1 -1
  310. package/workflows/container-contents/remoteHydration/lanes/childIndex.js.map +1 -0
  311. package/workflows/container-contents/remoteHydration/{laneFetchMarkers.js → lanes/laneFetchMarkers.js} +1 -1
  312. package/workflows/container-contents/remoteHydration/lanes/laneFetchMarkers.js.map +1 -0
  313. package/workflows/container-contents/remoteHydration/{parentLaneFetch.js → lanes/parentLaneFetch.js} +2 -2
  314. package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -0
  315. package/workflows/container-contents/remoteHydration/lanes/parentLaneQueue.js.map +1 -0
  316. package/workflows/container-contents/remoteHydration/principalPolicyCache.js +1 -1
  317. package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
  318. package/workflows/container-contents/remoteHydration/reconciliation.js +2 -2
  319. package/workflows/container-contents/remoteHydration/reconciliation.js.map +1 -1
  320. package/workflows/container-contents/remoteHydration/remoteContainers/containerStateFingerprint.js.map +1 -0
  321. package/workflows/container-contents/remoteHydration/{insertRemoteContainer.js → remoteContainers/insertRemoteContainer.js} +6 -6
  322. package/workflows/container-contents/remoteHydration/remoteContainers/insertRemoteContainer.js.map +1 -0
  323. package/workflows/container-contents/remoteHydration/{remoteContainerPageHydration.js → remoteContainers/remoteContainerPageHydration.js} +7 -7
  324. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -0
  325. package/workflows/container-contents/remoteHydration/{remoteContainerState.js → remoteContainers/remoteContainerState.js} +9 -9
  326. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -0
  327. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerTimestamps.js.map +1 -0
  328. package/workflows/container-contents/remoteHydration/tombstoneApplication.js +2 -2
  329. package/workflows/container-contents/remoteHydration/tombstoneApplication.js.map +1 -1
  330. package/workflows/containers/child/{createProjection.d.ts → create/createProjection.d.ts} +2 -2
  331. package/workflows/containers/child/{createProjection.js → create/createProjection.js} +2 -2
  332. package/workflows/containers/child/create/createProjection.js.map +1 -0
  333. package/workflows/containers/child/{createSubmission.d.ts → create/createSubmission.d.ts} +7 -7
  334. package/workflows/containers/child/{createSubmission.js → create/createSubmission.js} +2 -2
  335. package/workflows/containers/child/create/createSubmission.js.map +1 -0
  336. package/workflows/containers/child/{create.d.ts → create/index.d.ts} +5 -5
  337. package/workflows/containers/child/{create.js → create/index.js} +15 -15
  338. package/workflows/containers/child/create/index.js.map +1 -0
  339. package/workflows/containers/child/{move.d.ts → move/index.d.ts} +5 -5
  340. package/workflows/containers/child/{move.js → move/index.js} +12 -12
  341. package/workflows/containers/child/move/index.js.map +1 -0
  342. package/workflows/containers/child/{moveArtifacts.js → move/moveArtifacts.js} +3 -3
  343. package/workflows/containers/child/move/moveArtifacts.js.map +1 -0
  344. package/workflows/containers/child/{moveRotation.js → move/moveRotation.js} +3 -3
  345. package/workflows/containers/child/move/moveRotation.js.map +1 -0
  346. package/workflows/containers/child/{moveWraps.js → move/moveWraps.js} +5 -5
  347. package/workflows/containers/child/move/moveWraps.js.map +1 -0
  348. package/workflows/containers/child/mutationSubmit.js +1 -1
  349. package/workflows/containers/child/mutationSubmit.js.map +1 -1
  350. package/workflows/containers/child/{carriedDescendantRekeys.js → rekey/carriedDescendantRekeys.js} +4 -4
  351. package/workflows/containers/child/rekey/carriedDescendantRekeys.js.map +1 -0
  352. package/workflows/containers/child/{rekey.d.ts → rekey/index.d.ts} +6 -6
  353. package/workflows/containers/child/{rekey.js → rekey/index.js} +13 -13
  354. package/workflows/containers/child/rekey/index.js.map +1 -0
  355. package/workflows/containers/child/{keyringOverrideLineage.d.ts → rekey/keyringOverrideLineage.d.ts} +1 -1
  356. package/workflows/containers/child/{keyringOverrideLineage.js → rekey/keyringOverrideLineage.js} +1 -1
  357. package/workflows/containers/child/{rekeyProjection.d.ts → rekey/rekeyProjection.d.ts} +2 -2
  358. package/workflows/containers/child/{rekeyProjection.js → rekey/rekeyProjection.js} +3 -3
  359. package/workflows/containers/child/rekey/rekeyProjection.js.map +1 -0
  360. package/workflows/containers/child/{rekeyRemote.d.ts → rekey/rekeyRemote.d.ts} +6 -6
  361. package/workflows/containers/child/{rekeyRemote.js → rekey/rekeyRemote.js} +2 -2
  362. package/workflows/containers/child/rekey/rekeyRemote.js.map +1 -0
  363. package/workflows/containers/child/revoke.js +5 -5
  364. package/workflows/containers/child/revoke.js.map +1 -1
  365. package/workflows/containers/child/{replacementPrincipalPolicyReferences.js → rotation/replacementPrincipalPolicyReferences.js} +2 -2
  366. package/workflows/containers/child/rotation/replacementPrincipalPolicyReferences.js.map +1 -0
  367. package/workflows/containers/child/{rotationContext.js → rotation/rotationContext.js} +5 -5
  368. package/workflows/containers/child/rotation/rotationContext.js.map +1 -0
  369. package/workflows/containers/child/{rotationPrincipalPolicies.js → rotation/rotationPrincipalPolicies.js} +2 -2
  370. package/workflows/containers/child/rotation/rotationPrincipalPolicies.js.map +1 -0
  371. package/workflows/containers/child/{rotationWraps.js → rotation/rotationWraps.js} +1 -1
  372. package/workflows/containers/child/rotation/rotationWraps.js.map +1 -0
  373. package/workflows/containers/child/{currentShareGrantMutation.js → share/currentShareGrantMutation.js} +6 -6
  374. package/workflows/containers/child/share/currentShareGrantMutation.js.map +1 -0
  375. package/workflows/containers/child/{currentSharePrincipalPolicy.js → share/currentSharePrincipalPolicy.js} +10 -10
  376. package/workflows/containers/child/share/currentSharePrincipalPolicy.js.map +1 -0
  377. package/workflows/containers/child/{share.d.ts → share/index.d.ts} +8 -8
  378. package/workflows/containers/child/{share.js → share/index.js} +10 -10
  379. package/workflows/containers/child/share/index.js.map +1 -0
  380. package/workflows/containers/child/{runtimeCurrentGroupShare.js → share/runtimeCurrentGroupShare.js} +6 -6
  381. package/workflows/containers/child/share/runtimeCurrentGroupShare.js.map +1 -0
  382. package/workflows/containers/child/{shareAncestorRepair.js → share/shareAncestorRepair.js} +4 -4
  383. package/workflows/containers/child/share/shareAncestorRepair.js.map +1 -0
  384. package/workflows/containers/child/{shareMaterialization.d.ts → share/shareMaterialization.d.ts} +5 -5
  385. package/workflows/containers/child/{shareMaterialization.js → share/shareMaterialization.js} +7 -7
  386. package/workflows/containers/child/share/shareMaterialization.js.map +1 -0
  387. package/workflows/containers/child/{sharePlanCore.d.ts → share/sharePlanCore.d.ts} +7 -7
  388. package/workflows/containers/child/{sharePlanCore.js → share/sharePlanCore.js} +6 -6
  389. package/workflows/containers/child/share/sharePlanCore.js.map +1 -0
  390. package/workflows/containers/child/{sharePrincipalPolicy.d.ts → share/sharePrincipalPolicy.d.ts} +9 -9
  391. package/workflows/containers/child/{sharePrincipalPolicy.js → share/sharePrincipalPolicy.js} +13 -13
  392. package/workflows/containers/child/share/sharePrincipalPolicy.js.map +1 -0
  393. package/workflows/containers/child/share/shareProjection.js.map +1 -0
  394. package/workflows/containers/index.d.ts +10 -10
  395. package/workflows/containers/index.js +10 -10
  396. package/workflows/containers/index.js.map +1 -1
  397. package/workflows/documents/linkSet/linkSetAuthority.js +1 -1
  398. package/workflows/documents/linkSet/linkSetAuthority.js.map +1 -1
  399. package/workflows/documents/linkSet/linkSetBlobRewraps.js +1 -1
  400. package/workflows/documents/linkSet/linkSetBlobRewraps.js.map +1 -1
  401. package/workflows/documents/linkSet/linkSetProjectionSeed.js +1 -1
  402. package/workflows/documents/linkSet/linkSetProjectionSeed.js.map +1 -1
  403. package/workflows/documents/purge/index.js +1 -1
  404. package/workflows/documents/purge/index.js.map +1 -1
  405. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js +2 -2
  406. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -1
  407. package/workflows/organizations/rematerialization/precedingPrincipalRematerialization.js +1 -1
  408. package/workflows/organizations/rematerialization/precedingPrincipalRematerialization.js.map +1 -1
  409. package/workflows/organizations/rematerialization/principalContainerRematerialization.js +5 -5
  410. package/workflows/organizations/rematerialization/principalContainerRematerialization.js.map +1 -1
  411. package/workflows/organizations/rematerialization/principalContainerRematerializationPlanning.js +1 -1
  412. package/workflows/organizations/rematerialization/principalContainerRematerializationPlanning.js.map +1 -1
  413. package/workflows/organizations/rematerialization/principalContainerRematerializationTargets.js +1 -1
  414. package/workflows/organizations/rematerialization/principalContainerRematerializationTargets.js.map +1 -1
  415. package/workflows/principals/policyCache/index.js +1 -1
  416. package/workflows/principals/policyCache/index.js.map +1 -1
  417. package/workflows/principals/policyRepair.js +1 -1
  418. package/workflows/principals/policyRepair.js.map +1 -1
  419. package/workflows/registration/organizationProvisioningArtifacts.d.ts +1 -1
  420. package/workflows/registration/provisioningBootstrapBuilders.js +1 -1
  421. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +0 -1
  422. package/data/keyingProjectionVerification/bundleVerification.js.map +0 -1
  423. package/data/keyingProjectionVerification/checkpointContext.js.map +0 -1
  424. package/data/keyingProjectionVerification/containerAncestorCitations.js.map +0 -1
  425. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +0 -1
  426. package/data/keyingProjectionVerification/containerManifestVerification.js.map +0 -1
  427. package/data/keyingProjectionVerification/containerPathVerification.js.map +0 -1
  428. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +0 -1
  429. package/data/keyingProjectionVerification/documentDependencyPaths.js.map +0 -1
  430. package/data/keyingProjectionVerification/documentManifestPolicies.js.map +0 -1
  431. package/data/keyingProjectionVerification/documentManifestVerification.js.map +0 -1
  432. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +0 -1
  433. package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js.map +0 -1
  434. package/data/keyingProjectionVerification/documentPurgeCheckpointEnforcement.js.map +0 -1
  435. package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js.map +0 -1
  436. package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js.map +0 -1
  437. package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js.map +0 -1
  438. package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js.map +0 -1
  439. package/data/keyingProjectionVerification/documentPurgeProofVerification.js.map +0 -1
  440. package/data/keyingProjectionVerification/manifestCheckpointVerification.js.map +0 -1
  441. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +0 -1
  442. package/data/keyingProjectionVerification/organizationFounderBinding.js.map +0 -1
  443. package/data/keyingProjectionVerification/principalPolicyCache.js.map +0 -1
  444. package/data/keyingProjectionVerification/principalPolicyVerification.js.map +0 -1
  445. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +0 -1
  446. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +0 -1
  447. package/data/keyingProjectionVerification/resolvedPrincipalPolicy.js.map +0 -1
  448. package/stores/container-contents/backgroundHydration.js.map +0 -1
  449. package/stores/container-contents/containerPurgeCore.js.map +0 -1
  450. package/stores/container-contents/containerStateMap.js.map +0 -1
  451. package/stores/container-contents/containerStatePersistence.js.map +0 -1
  452. package/stores/container-contents/documentRecovery.js.map +0 -1
  453. package/stores/container-contents/documentRotation.js.map +0 -1
  454. package/stores/container-contents/documentWork.js.map +0 -1
  455. package/stores/container-contents/emptyTrashOperation.js.map +0 -1
  456. package/stores/container-contents/existingSystemContainer.js.map +0 -1
  457. package/stores/container-contents/groupRewrapOperation.js.map +0 -1
  458. package/stores/container-contents/missingContainerState.js.map +0 -1
  459. package/stores/container-contents/missingSyncedContainerState.js.map +0 -1
  460. package/stores/container-contents/operations.js.map +0 -1
  461. package/stores/container-contents/organizationMetadataSystemContainer.js.map +0 -1
  462. package/stores/container-contents/purgeContainerOperation.js.map +0 -1
  463. package/stores/container-contents/reconcilableContainer.js.map +0 -1
  464. package/stores/container-contents/remoteBackedContainerState.js.map +0 -1
  465. package/stores/container-contents/remoteContainerIngestion.js.map +0 -1
  466. package/stores/container-contents/remoteEventProjectionInvalidation.js.map +0 -1
  467. package/stores/container-contents/remoteEventSync.js.map +0 -1
  468. package/stores/container-contents/remoteHydrationRequest.js.map +0 -1
  469. package/stores/container-contents/remoteWriteGuards.js.map +0 -1
  470. package/stores/container-contents/remoteWriteQueue.js.map +0 -1
  471. package/stores/container-contents/reportShareFailure.js.map +0 -1
  472. package/stores/container-contents/setContainerIconOperation.js.map +0 -1
  473. package/stores/container-contents/shareOperations.js.map +0 -1
  474. package/stores/container-contents/startupHydration.js.map +0 -1
  475. package/stores/container-contents/syncAgent.js.map +0 -1
  476. package/stores/container-contents/syncAgentTypes.js.map +0 -1
  477. package/stores/container-contents/syncLaneIteration.js.map +0 -1
  478. package/stores/container-contents/systemContainerHydration.js.map +0 -1
  479. package/stores/container-contents/systemContainerIcon.js.map +0 -1
  480. package/stores/container-contents/systemContainerLookup.js.map +0 -1
  481. package/stores/container-contents/systemContainerPostCreate.js.map +0 -1
  482. package/stores/container-contents/systemContainerPromotion.js.map +0 -1
  483. package/stores/container-contents/writeGeneration.js.map +0 -1
  484. package/stores/documents/documentStore/attachmentDetachState.js.map +0 -1
  485. package/stores/documents/documentStore/attachmentHydration.js.map +0 -1
  486. package/stores/documents/documentStore/attachmentHydrationCommit.js.map +0 -1
  487. package/stores/documents/documentStore/attachmentIntents.js.map +0 -1
  488. package/stores/documents/documentStore/attachmentMutationPersistence.js.map +0 -1
  489. package/stores/documents/documentStore/attachmentPersistFollowup.js.map +0 -1
  490. package/stores/documents/documentStore/attachmentPersistence.js.map +0 -1
  491. package/stores/documents/documentStore/attachmentRemoval.js.map +0 -1
  492. package/stores/documents/documentStore/attachmentSnapshot.js.map +0 -1
  493. package/stores/documents/documentStore/attachmentSourceUpload.js.map +0 -1
  494. package/stores/documents/documentStore/attachmentStaging.js.map +0 -1
  495. package/stores/documents/documentStore/attachmentUploadAttempt.js.map +0 -1
  496. package/stores/documents/documentStore/attachmentUploadLane.js.map +0 -1
  497. package/stores/documents/documentStore/attachmentUploadResume.js.map +0 -1
  498. package/stores/documents/documentStore/attachmentWriteGeneration.js.map +0 -1
  499. package/stores/documents/documentStore/attachments.js.map +0 -1
  500. package/stores/documents/documentStore/deferredInitialUpdate.js.map +0 -1
  501. package/stores/documents/documentStore/documentHistoryCompaction.js.map +0 -1
  502. package/stores/documents/documentStore/durableDocumentReload.js.map +0 -1
  503. package/stores/documents/documentStore/historyRebuild.js.map +0 -1
  504. package/stores/documents/documentStore/initialization.js.map +0 -1
  505. package/stores/documents/documentStore/initializationAttachments.js.map +0 -1
  506. package/stores/documents/documentStore/initializationHistory.js.map +0 -1
  507. package/stores/documents/documentStore/initializationRecovery.js.map +0 -1
  508. package/stores/documents/documentStore/pullContinuationInvalidation.js.map +0 -1
  509. package/stores/documents/documentStore/remoteRevalidationTelemetry.js.map +0 -1
  510. package/stores/documents/documentStore/remoteWork.js.map +0 -1
  511. package/stores/documents/documentStore/rotation.js.map +0 -1
  512. package/stores/documents/documentStore/rotationProvenance.js.map +0 -1
  513. package/stores/documents/documentStore/rotationSettlement.js.map +0 -1
  514. package/stores/documents/documentStore/sync.js.map +0 -1
  515. package/stores/documents/documentStore/syncAcceptedUpdateIds.js.map +0 -1
  516. package/stores/documents/documentStore/syncAttachmentSettlement.js.map +0 -1
  517. package/stores/documents/documentStore/syncAttachments.js.map +0 -1
  518. package/stores/documents/documentStore/syncDetachedAttachments.js.map +0 -1
  519. package/stores/documents/documentStore/syncFinalize.js.map +0 -1
  520. package/stores/documents/documentStore/syncGeneration.js.map +0 -1
  521. package/stores/documents/documentStore/syncOutgoingCoverage.js.map +0 -1
  522. package/stores/documents/documentStore/syncRemoteSignals.js.map +0 -1
  523. package/stores/documents/documentStore/syncRequest.js.map +0 -1
  524. package/stores/documents/documentStore/syncShared.js.map +0 -1
  525. package/stores/documents/documentStore/syncUpdateImport.js.map +0 -1
  526. package/stores/documents/documentStore.js.map +0 -1
  527. package/workflows/container-contents/container-state/createAdoption.js.map +0 -1
  528. package/workflows/container-contents/container-state/createChild.js.map +0 -1
  529. package/workflows/container-contents/container-state/createIntentDepth.js.map +0 -1
  530. package/workflows/container-contents/container-state/createIntentSettlement.js.map +0 -1
  531. package/workflows/container-contents/container-state/createIntentSync.js.map +0 -1
  532. package/workflows/container-contents/container-state/createTerminalFailure.js.map +0 -1
  533. package/workflows/container-contents/container-state/createWithMetadata.js.map +0 -1
  534. package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +0 -1
  535. package/workflows/container-contents/container-state/groupGrantVerification.js.map +0 -1
  536. package/workflows/container-contents/container-state/groupShareEpoch.js.map +0 -1
  537. package/workflows/container-contents/container-state/localPurgeScope.js.map +0 -1
  538. package/workflows/container-contents/container-state/purgeTree.js.map +0 -1
  539. package/workflows/container-contents/container-state/purgeTreeCollection.js.map +0 -1
  540. package/workflows/container-contents/container-state/purgeTreeContainerDeletion.js.map +0 -1
  541. package/workflows/container-contents/container-state/purgeTreeScope.js.map +0 -1
  542. package/workflows/container-contents/container-state/readLocalPurgeScope.js.map +0 -1
  543. package/workflows/container-contents/container-state/share.js.map +0 -1
  544. package/workflows/container-contents/container-state/sharePersistence.js.map +0 -1
  545. package/workflows/container-contents/remoteHydration/childIndex.js.map +0 -1
  546. package/workflows/container-contents/remoteHydration/containerStateFingerprint.js.map +0 -1
  547. package/workflows/container-contents/remoteHydration/destinationPrefetch.js.map +0 -1
  548. package/workflows/container-contents/remoteHydration/destinationRoleCache.js.map +0 -1
  549. package/workflows/container-contents/remoteHydration/destinationRootReload.js.map +0 -1
  550. package/workflows/container-contents/remoteHydration/insertRemoteContainer.js.map +0 -1
  551. package/workflows/container-contents/remoteHydration/laneFetchMarkers.js.map +0 -1
  552. package/workflows/container-contents/remoteHydration/parentLaneFetch.js.map +0 -1
  553. package/workflows/container-contents/remoteHydration/parentLaneQueue.js.map +0 -1
  554. package/workflows/container-contents/remoteHydration/remoteContainerPageHydration.js.map +0 -1
  555. package/workflows/container-contents/remoteHydration/remoteContainerState.js.map +0 -1
  556. package/workflows/container-contents/remoteHydration/remoteContainerTimestamps.js.map +0 -1
  557. package/workflows/container-contents/remoteHydration/replacementBinding.js.map +0 -1
  558. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +0 -1
  559. package/workflows/containers/child/carriedDescendantRekeys.js.map +0 -1
  560. package/workflows/containers/child/create.js.map +0 -1
  561. package/workflows/containers/child/createProjection.js.map +0 -1
  562. package/workflows/containers/child/createSubmission.js.map +0 -1
  563. package/workflows/containers/child/currentShareGrantMutation.js.map +0 -1
  564. package/workflows/containers/child/currentSharePrincipalPolicy.js.map +0 -1
  565. package/workflows/containers/child/move.js.map +0 -1
  566. package/workflows/containers/child/moveArtifacts.js.map +0 -1
  567. package/workflows/containers/child/moveRotation.js.map +0 -1
  568. package/workflows/containers/child/moveWraps.js.map +0 -1
  569. package/workflows/containers/child/rekey.js.map +0 -1
  570. package/workflows/containers/child/rekeyProjection.js.map +0 -1
  571. package/workflows/containers/child/rekeyRemote.js.map +0 -1
  572. package/workflows/containers/child/replacementPrincipalPolicyReferences.js.map +0 -1
  573. package/workflows/containers/child/rotationContext.js.map +0 -1
  574. package/workflows/containers/child/rotationPrincipalPolicies.js.map +0 -1
  575. package/workflows/containers/child/rotationWraps.js.map +0 -1
  576. package/workflows/containers/child/runtimeCurrentGroupShare.js.map +0 -1
  577. package/workflows/containers/child/share.js.map +0 -1
  578. package/workflows/containers/child/shareAncestorRepair.js.map +0 -1
  579. package/workflows/containers/child/shareMaterialization.js.map +0 -1
  580. package/workflows/containers/child/sharePlanCore.js.map +0 -1
  581. package/workflows/containers/child/sharePrincipalPolicy.js.map +0 -1
  582. package/workflows/containers/child/shareProjection.js.map +0 -1
  583. /package/data/keyingProjectionVerification/{containerCreateManifest.js.map → container/containerCreateManifest.js.map} +0 -0
  584. /package/data/keyingProjectionVerification/{documentContainerProjections.js → document/documentContainerProjections.js} +0 -0
  585. /package/data/keyingProjectionVerification/{documentContainerProjections.js.map → document/documentContainerProjections.js.map} +0 -0
  586. /package/data/keyingProjectionVerification/{documentManifestPredecessor.js.map → document/documentManifestPredecessor.js.map} +0 -0
  587. /package/stores/container-contents/{containerStateMap.js → containerState/containerStateMap.js} +0 -0
  588. /package/stores/container-contents/{missingSyncedContainerState.js → containerState/missingSyncedContainerState.js} +0 -0
  589. /package/stores/container-contents/{reconcilableContainer.js → containerState/reconcilableContainer.js} +0 -0
  590. /package/stores/container-contents/{remoteHydrationRefresh.js → hydration/remoteHydrationRefresh.js} +0 -0
  591. /package/stores/container-contents/{remoteHydrationRefresh.js.map → hydration/remoteHydrationRefresh.js.map} +0 -0
  592. /package/stores/container-contents/{emptyTrashOperation.js → operations/emptyTrashOperation.js} +0 -0
  593. /package/stores/container-contents/{purgeContainerOperation.js → operations/purgeContainerOperation.js} +0 -0
  594. /package/stores/container-contents/{remoteBackedContainerState.js → remoteEvents/remoteBackedContainerState.js} +0 -0
  595. /package/stores/container-contents/{writeGeneration.js → remoteWrites/writeGeneration.js} +0 -0
  596. /package/stores/container-contents/{syncAgentTypes.js → syncAgent/syncAgentTypes.js} +0 -0
  597. /package/stores/container-contents/{systemContainerLookup.js → systemContainers/systemContainerLookup.js} +0 -0
  598. /package/stores/documents/documentStore/{attachmentPersistFollowup.js → attachments/attachmentPersistFollowup.js} +0 -0
  599. /package/stores/documents/documentStore/{attachmentSnapshot.js → attachments/attachmentSnapshot.js} +0 -0
  600. /package/stores/documents/documentStore/{remoteWork.js → sync/remoteWork.js} +0 -0
  601. /package/stores/documents/documentStore/{syncAcceptedUpdateIds.js → sync/syncAcceptedUpdateIds.js} +0 -0
  602. /package/stores/documents/documentStore/{syncGeneration.js → sync/syncGeneration.js} +0 -0
  603. /package/stores/documents/documentStore/{versionCoverage.js.map → sync/versionCoverage.js.map} +0 -0
  604. /package/workflows/container-contents/container-state/{createIntentSettlement.js → create/createIntentSettlement.js} +0 -0
  605. /package/workflows/container-contents/container-state/{purgeProgress.d.ts → purge/purgeProgress.d.ts} +0 -0
  606. /package/workflows/container-contents/container-state/{purgeProgress.js → purge/purgeProgress.js} +0 -0
  607. /package/workflows/container-contents/container-state/{purgeProgress.js.map → purge/purgeProgress.js.map} +0 -0
  608. /package/workflows/container-contents/container-state/{purgeTreeCollection.js → purge/purgeTreeCollection.js} +0 -0
  609. /package/workflows/container-contents/remoteHydration/{destinationPrefetch.js → destination/destinationPrefetch.js} +0 -0
  610. /package/workflows/container-contents/remoteHydration/{destinationRoleCache.js → destination/destinationRoleCache.js} +0 -0
  611. /package/workflows/container-contents/remoteHydration/{childIndex.js → lanes/childIndex.js} +0 -0
  612. /package/workflows/container-contents/remoteHydration/{parentLaneQueue.js → lanes/parentLaneQueue.js} +0 -0
  613. /package/workflows/container-contents/remoteHydration/{containerStateFingerprint.js → remoteContainers/containerStateFingerprint.js} +0 -0
  614. /package/workflows/container-contents/remoteHydration/{remoteContainerTimestamps.js → remoteContainers/remoteContainerTimestamps.js} +0 -0
  615. /package/workflows/containers/child/{keyringOverrideLineage.js.map → rekey/keyringOverrideLineage.js.map} +0 -0
  616. /package/workflows/containers/child/{shareProjection.js → share/shareProjection.js} +0 -0
@@ -0,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AAE,OAAO,EAAE,UAAU,EAAE,EAAE;YAChD,IACE,CAAC,oCAAoC,CAAC,KAAK,EAAE,oBAAoB,CAAC;gBAClE,iBAAiB,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO;gBAE7C,OAAO;YACT,sEAAsE;YACtE,yEAAyE;YACzE,kEAAkE;YAClE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,uBAAuB,CACpE,UAAU,EACV,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB,CAAC;YACF,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACrE,IACE,CAAC,oCAAoC,CAAC,KAAK,EAAE,oBAAoB,CAAC;gBAClE,iBAAiB,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO;gBAC7C,QAAQ,CAAC,IAAI,CACX,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,MAAM,KAAK,iBAAiB,CAAC,MAAM;oBAC3C,OAAO,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,CAC3C;gBAED,OAAO;YACT,mEAAmE;YACnE,uEAAuE;YACvE,wEAAwE;YACxE,uEAAuE;YACvE,MAAM,kBAAkB,GAAG,2BAA2B,CAAC,eAAe,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 \"../attachments/attachmentPersistence\";\nimport type { DocumentStoreState } from \"../state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"../sync/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"]}
@@ -11,7 +11,7 @@
11
11
  * the attachment list before an unlink and writes it back after. Both read the
12
12
  * slot list, await, then save — so the slot they save may already be gone.
13
13
  */
14
- import { getDocumentAttachments } from "../../../data/documents/documentContent.js";
14
+ import { getDocumentAttachments } from "../../../../data/documents/documentContent.js";
15
15
  function getLiveSlotIds(doc) {
16
16
  return new Set(getDocumentAttachments(doc).map((attachment) => attachment.slotId));
17
17
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentDetachState.js","sourceRoot":"","sources":["attachmentDetachState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAIpF,SAAS,cAAc,CAAC,GAAkB;IACxC,OAAO,IAAI,GAAG,CACZ,sBAAsB,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CACnE,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAC5C,WAAiD,EACjD,GAAyB;IAEzB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACpC,UAAU,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;QACnE,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,UAAU,EAAE;QAC/B,CAAC,CAAC,UAAU,CACf,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CACjD,WAAiD,EACjD,GAAkB;IAElB,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACxC,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,UAAU,KAAK,CAAC,UAAU,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC;YACpD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,EAAE,GAAG,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Keeps a local attachment row's detach marker consistent with the document.\n *\n * The invariant is one line: a local blob row is marked detached exactly when\n * its slot is no longer in the document. The read models trust that marker to\n * decide whether a blob is still referenced, so anything that writes these rows\n * has to preserve it rather than restate what it believed the slots were.\n *\n * Two writers can otherwise clear a marker they never meant to touch: an upload\n * that settles after the user removed its slot, and a hydration that captured\n * the attachment list before an unlink and writes it back after. Both read the\n * slot list, await, then save — so the slot they save may already be gone.\n */\nimport { getDocumentAttachments } from \"../../../../data/documents/documentContent\";\nimport type { LocalAttachmentRecord } from \"../../../../workflows/documents\";\nimport type { DocumentState } from \"../state\";\n\nfunction getLiveSlotIds(doc: DocumentState): ReadonlySet<string> {\n return new Set(\n getDocumentAttachments(doc).map((attachment) => attachment.slotId),\n );\n}\n\n/**\n * Stamp records being written for slots the document no longer has as detached.\n *\n * The document is read here, at write time, rather than trusted from the\n * caller's earlier snapshot — the Loro document is mutated in place, so this\n * sees any unlink that landed while the caller was awaiting.\n */\nexport function withLocalAttachmentDetachState(\n attachments: ReadonlyArray<LocalAttachmentRecord>,\n doc: DocumentState | null,\n): LocalAttachmentRecord[] {\n if (!doc) {\n return [...attachments];\n }\n\n const detachedAt = new Date().toISOString();\n const liveSlotIds = getLiveSlotIds(doc);\n return attachments.map((attachment) =>\n attachment.detachedAt === null && !liveSlotIds.has(attachment.slotId)\n ? { ...attachment, detachedAt }\n : attachment,\n );\n}\n\n/**\n * Report the loaded rows whose marker disagrees with the loaded document.\n *\n * A write can only be interrupted between marking the row and persisting the\n * document, so a restart can find either half applied. Reconciling against the\n * durable document at load makes the marker mean what it claims again: a slot\n * the document still has is live, and a slot it dropped is detached.\n */\nexport function reconcileLocalAttachmentDetachState(\n attachments: ReadonlyArray<LocalAttachmentRecord>,\n doc: DocumentState,\n): LocalAttachmentRecord[] {\n const detachedAt = new Date().toISOString();\n const liveSlotIds = getLiveSlotIds(doc);\n return attachments.flatMap((attachment) => {\n const slotIsLive = liveSlotIds.has(attachment.slotId);\n if (slotIsLive === (attachment.detachedAt === null)) {\n return [];\n }\n\n return [{ ...attachment, detachedAt: slotIsLive ? null : detachedAt }];\n });\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  /** Hydrate only bytes matching the current document's authenticated attachment intent. */
2
- import { getDocumentAttachments } from "../../../data/documents/documentContent.js";
3
- import { hydrateDocumentAttachmentBlobs } from "../../../workflows/blobs/index.js";
4
- import { createRuntimePrincipalPolicyWarmer } from "../../../workflows/principals/runtimePolicyWarmer.js";
2
+ import { getDocumentAttachments } from "../../../../data/documents/documentContent.js";
3
+ import { hydrateDocumentAttachmentBlobs } from "../../../../workflows/blobs/index.js";
4
+ import { createRuntimePrincipalPolicyWarmer } from "../../../../workflows/principals/runtimePolicyWarmer.js";
5
+ import { runDocumentOrphanMaintenance } from "../orphanMaintenance.js";
6
+ import { isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "../sync/syncGeneration.js";
5
7
  import { commitHydratedAttachment } from "./attachmentHydrationCommit.js";
6
- import { runDocumentOrphanMaintenance } from "./orphanMaintenance.js";
7
- import { isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "./syncGeneration.js";
8
8
  // A remote probe is evidence that bindings may have moved independently of
9
9
  // content. Capture its sequence before I/O so a hint arriving during hydration
10
10
  // survives for the trailing pass. Missing or changed local bytes always retry.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentHydration.js","sourceRoot":"","sources":["attachmentHydration.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAC1G,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAEL,oCAAoC,IAAI,uBAAuB,GAChE,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,MAAM,cAAc,GAAG,IAAI,OAAO,EAG/B,CAAC;AAEJ,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAAyB,EACzB,UAAyB,EACzB,aAAoC,EACpC,kBAAgD;IAEhD,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAC/B,CAAC,kBAAkB,IAAI,uBAAuB,CAAC,KAAK,EAAE,kBAAkB,CAAC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,KAAK,EAAE,KAAK,UAAU;YACrC,CAAC,CAAC,OAAO,CAAC,QAAQ;YAClB,CAAC,CAAC,CAAC,CAAC,CAAC;IACT,OAAO,CACL,CAAC,iBAAiB;QAClB,WAAW,CAAC,KAAK,CACf,CAAC,UAAU,EAAE,EAAE,CACb,KAAK,CAAC,4BAA4B,CAAC,UAAU,CAAC,MAAM,CAAC;YACrD,KAAK,CAAC,+BAA+B,CAAC,UAAU,CAAC,MAAM,CAAC;gBACtD,UAAU,CAAC,aAAa,CAC7B,CACF,CAAC;AACJ,CAAC","sourcesContent":["/** Hydrate only bytes matching the current document's authenticated attachment intent. */\n\nimport { getDocumentAttachments } from \"../../../../data/documents/documentContent\";\nimport { hydrateDocumentAttachmentBlobs } from \"../../../../workflows/blobs\";\nimport type { DocumentRecord } from \"../../../../workflows/documents\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../../../workflows/principals/runtimePolicyWarmer\";\nimport { runDocumentOrphanMaintenance } from \"../orphanMaintenance\";\nimport type { DocumentState, DocumentStoreState } from \"../state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent,\n} from \"../sync/syncGeneration\";\nimport { commitHydratedAttachment } from \"./attachmentHydrationCommit\";\n\n// A remote probe is evidence that bindings may have moved independently of\n// content. Capture its sequence before I/O so a hint arriving during hydration\n// survives for the trailing pass. Missing or changed local bytes always retry.\nconst checkedSignals = new WeakMap<\n DocumentStoreState,\n { documentId: string; document: WeakRef<DocumentState>; sequence: number }\n>();\n\nexport async function hydrateAttachmentBlobs(\n state: DocumentStoreState,\n currentDoc: DocumentState,\n currentRecord: DocumentRecord | null,\n expectedGeneration?: DocumentStoreSyncGeneration,\n) {\n const generationIsCurrent = () =>\n !expectedGeneration || isSyncGenerationCurrent(state, expectedGeneration);\n if (!generationIsCurrent()) return;\n\n const runtime = state.runtime;\n const encapsulationKeyPair = runtime.crypto.encapsulationKeyPair;\n if (\n !encapsulationKeyPair ||\n !runtime.auth.isAuthenticated ||\n !runtime.state.online ||\n !currentRecord?.documentId\n ) {\n return;\n }\n\n const attachments = getDocumentAttachments(currentDoc);\n if (attachments.length === 0) {\n return;\n }\n\n const signalSequence = state.remoteUpdateSignalSeq;\n if (\n bindingsAlreadyChecked(\n state,\n currentDoc,\n currentRecord.documentId,\n attachments,\n signalSequence,\n )\n )\n return;\n\n const expectedStorageKeys = { ...state.attachmentStorageKeyBySlotId };\n let bindingsChecked = false;\n const hydratedBlobs = await hydrateDocumentAttachmentBlobs({\n apiClient: runtime.apiClient,\n onBindingsChecked: () => {\n bindingsChecked = true;\n },\n attachments,\n documentId: currentRecord.documentId,\n execSql: runtime.infra.execSql,\n localBlobIdBySlotId: state.attachmentBlobIdBySlotId,\n localStorageKeyBySlotId: state.attachmentStorageKeyBySlotId,\n log: runtime.util.log,\n rejectedServedBindings: state.rejectedServedAttachmentBindings,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveProjectionUserKey:\n expectedGeneration?.resolveProjectionUserKey ??\n state.resolveProjectionUserKey,\n targetSecretKey: encapsulationKeyPair.secretKey,\n stillCurrent: generationIsCurrent,\n warmReferencedPrincipalPolicies:\n createRuntimePrincipalPolicyWarmer(runtime),\n });\n if (!generationIsCurrent()) return;\n if (!hydratedBlobs) {\n return;\n }\n\n for (const hydratedBlob of hydratedBlobs) {\n await commitHydratedAttachment({\n state,\n currentDoc,\n hydratedBlob,\n generationIsCurrent,\n expectedStorageKey:\n expectedStorageKeys[hydratedBlob.attachment.slotId] ?? null,\n });\n }\n if (\n bindingsChecked &&\n generationIsCurrent() &&\n hydratedBlobs.every(\n (blob) =>\n state.attachmentBlobIdBySlotId[blob.attachment.slotId] ===\n blob.binding.blobId,\n )\n ) {\n checkedSignals.set(state, {\n documentId: currentRecord.documentId,\n document: new WeakRef(currentDoc),\n sequence: signalSequence,\n });\n }\n void runDocumentOrphanMaintenance(state);\n}\n\nfunction bindingsAlreadyChecked(\n state: DocumentStoreState,\n currentDoc: DocumentState,\n documentId: string,\n attachments: ReturnType<typeof getDocumentAttachments>,\n signalSequence: number,\n): boolean {\n const checked = checkedSignals.get(state);\n const needsBindingProbe =\n signalSequence >\n (checked?.documentId === documentId &&\n checked.document.deref() === currentDoc\n ? checked.sequence\n : 0);\n return (\n !needsBindingProbe &&\n attachments.every(\n (attachment) =>\n state.attachmentStorageKeyBySlotId[attachment.slotId] &&\n state.attachmentContentSha256BySlotId[attachment.slotId] ===\n attachment.contentSha256,\n )\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { getDocumentAttachments } from "../../../data/documents/documentContent.js";
2
- import { runSerializedDocumentBlobMutation, } from "../../../workflows/documents/index.js";
3
- import { saveHydratedDocumentAttachment } from "../../../workflows/documents/attachments/attachmentPersistence.js";
1
+ import { getDocumentAttachments } from "../../../../data/documents/documentContent.js";
2
+ import { runSerializedDocumentBlobMutation, } from "../../../../workflows/documents/index.js";
3
+ import { saveHydratedDocumentAttachment } from "../../../../workflows/documents/attachments/attachmentPersistence.js";
4
4
  import { installLocalAttachmentRecords, removeLocalAttachmentSlot, } from "./attachmentPersistence.js";
5
5
  export async function commitHydratedAttachment(input) {
6
6
  const { state, currentDoc, hydratedBlob, expectedStorageKey, generationIsCurrent, } = input;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentHydrationCommit.js","sourceRoot":"","sources":["attachmentHydrationCommit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEpF,OAAO,EAEL,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,8BAA8B,EAAE,MAAM,mEAAmE,CAAC;AAEnH,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AAMjC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,KAW9C;IACC,MAAM,EACJ,KAAK,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,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K,CAAC,WAAW;YAC9B,UAAU;YACV,kBAAkB;YAClB,0BAA0B;YAC1B,YAAY;SACb,CAAC,CAAC;QACH,IAAI,SAAS,IAAI,YAAY,EAAE;YAC7B,6BAA6B,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;aAC5D,IAAI,CAAC,SAAS,IAAI,YAAY,EAAE;YACnC,MAAM,4BAA4B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC5D,CAAC,CACF,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,4BAA4B,CACzC,KAAqD,EACrD,YAA2B;IAE3B,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,oBAAoB,CACvD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAC3B,KAAK,CAAC,OAAO,CACd,CAAC;IACF,IAAI,CAAC,YAAY,EAAE;QAAE,OAAO;IAC5B,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC;IAC9C,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzC,6BAA6B,CAC3B,KAAK,EACL,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,EAC3C,UAAU,CACX,CAAC;AACJ,CAAC","sourcesContent":["import { getDocumentAttachments } from \"../../../../data/documents/documentContent\";\nimport type { hydrateDocumentAttachmentBlobs } from \"../../../../workflows/blobs\";\nimport {\n type LocalAttachmentRecord,\n runSerializedDocumentBlobMutation,\n} from \"../../../../workflows/documents\";\nimport { saveHydratedDocumentAttachment } from \"../../../../workflows/documents/attachments/attachmentPersistence\";\nimport type { DocumentState, DocumentStoreState } from \"../state\";\nimport {\n installLocalAttachmentRecords,\n removeLocalAttachmentSlot,\n} from \"./attachmentPersistence\";\n\ntype HydratedBlob = NonNullable<\n Awaited<ReturnType<typeof hydrateDocumentAttachmentBlobs>>\n>[number];\n\nexport async function commitHydratedAttachment(input: {\n state: DocumentStoreState;\n currentDoc: DocumentState;\n hydratedBlob: Pick<\n HydratedBlob,\n \"attachment\" | \"bytes\" | \"contentSha256\" | \"storageKey\"\n > & {\n binding: Pick<HydratedBlob[\"binding\"], \"blobId\">;\n };\n expectedStorageKey: string | null;\n generationIsCurrent: () => boolean;\n}): Promise<void> {\n const {\n state,\n currentDoc,\n hydratedBlob,\n expectedStorageKey,\n generationIsCurrent,\n } = input;\n const runtime = state.runtime;\n const expectedSnapshotEndVersion = state.record?.snapshotEndVersion ?? null;\n const stillCurrent = () =>\n generationIsCurrent() &&\n state.doc === currentDoc &&\n getDocumentAttachments(currentDoc).some(\n (attachment) =>\n attachment.slotId === hydratedBlob.attachment.slotId &&\n attachment.contentSha256 === hydratedBlob.attachment.contentSha256,\n );\n await runSerializedDocumentBlobMutation(\n runtime.infra.execSql,\n hydratedBlob.storageKey,\n async () => {\n if (!stillCurrent()) return;\n await runtime.infra.blobStore.writeBytes(\n hydratedBlob.storageKey,\n hydratedBlob.bytes,\n );\n const attachment: LocalAttachmentRecord = {\n blobId: hydratedBlob.binding.blobId,\n // The held bytes' own size, not the document intent's: a served\n // binding the intent has not recorded yet may differ in length, and\n // preview gating reads the local record.\n byteLength: hydratedBlob.bytes.byteLength,\n contentSha256: hydratedBlob.contentSha256,\n detachedAt: null,\n localId: state.localId,\n mimeType: hydratedBlob.attachment.mimeType,\n slotId: hydratedBlob.attachment.slotId,\n storageKey: hydratedBlob.storageKey,\n };\n const committed = await saveHydratedDocumentAttachment({\n execSql: runtime.infra.execSql,\n persistence: state.persistence,\n attachment,\n expectedStorageKey,\n expectedSnapshotEndVersion,\n stillCurrent,\n });\n if (committed && stillCurrent())\n installLocalAttachmentRecords(state, [attachment], currentDoc);\n else if (!committed && stillCurrent())\n await refreshRefusedAttachmentSlot(input, stillCurrent);\n },\n );\n}\n\nasync function refreshRefusedAttachmentSlot(\n input: Parameters<typeof commitHydratedAttachment>[0],\n stillCurrent: () => boolean,\n): Promise<void> {\n const { state, currentDoc, hydratedBlob } = input;\n const rows = await state.persistence.listLocalAttachments(\n state.runtime.infra.execSql,\n state.localId,\n );\n if (!stillCurrent()) return;\n const slotId = hydratedBlob.attachment.slotId;\n removeLocalAttachmentSlot(state, slotId);\n installLocalAttachmentRecords(\n state,\n rows.filter((row) => row.slotId === slotId),\n currentDoc,\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { attachmentContentSha256 } from "../../../data/documents/attachmentContentIdentity.js";
2
- import { blobByteSourceInputLength } from "../../../workflows/blobs/index.js";
1
+ import { attachmentContentSha256 } from "../../../../data/documents/attachmentContentIdentity.js";
2
+ import { blobByteSourceInputLength } from "../../../../workflows/blobs/index.js";
3
3
  export async function buildPendingAttachments(localId, files) {
4
4
  const nextPendingAttachments = [];
5
5
  const nextAttachments = [];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentIntents.js","sourceRoot":"","sources":["attachmentIntents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAE/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAe,EACf,KAA8C;IAK9C,MAAM,sBAAsB,GAA8B,EAAE,CAAC;IAC7D,MAAM,eAAe,GAAyB,EAAE,CAAC;IAEjD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC;QAC1C,MAAM,UAAU,GAAG,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,aAAa,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChE,sBAAsB,CAAC,IAAI,CAAC;YAC1B,UAAU;YACV,aAAa;YACb,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM;YACN,UAAU;SACX,CAAC,CAAC;QACH,eAAe,CAAC,IAAI,CAAC;YACnB,aAAa;YACb,UAAU;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAAc,EACd,IAA8B;IAE9B,OAAO;QACL,aAAa,EAAE,MAAM,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC;QACxD,UAAU,EAAE,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC;QACjD,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { attachmentContentSha256 } from \"../../../../data/documents/attachmentContentIdentity\";\nimport type { DocumentAttachment } from \"../../../../data/documents/documentContent\";\nimport { blobByteSourceInputLength } from \"../../../../workflows/blobs\";\nimport type { PendingAttachmentRecord } from \"../../../../workflows/documents\";\nimport type { DocumentAttachmentUpload } from \"../../types\";\n\nexport async function buildPendingAttachments(\n localId: string,\n files: ReadonlyArray<DocumentAttachmentUpload>,\n): Promise<{\n nextAttachments: DocumentAttachment[];\n nextPendingAttachments: PendingAttachmentRecord[];\n}> {\n const nextPendingAttachments: PendingAttachmentRecord[] = [];\n const nextAttachments: DocumentAttachment[] = [];\n\n for (const file of files) {\n const slotId = crypto.randomUUID();\n const storageKey = `${localId}-${slotId}`;\n const byteLength = blobByteSourceInputLength(file.bytes);\n const contentSha256 = await attachmentContentSha256(file.bytes);\n nextPendingAttachments.push({\n byteLength,\n contentSha256,\n localId,\n mimeType: file.mimeType,\n name: file.name,\n slotId,\n storageKey,\n });\n nextAttachments.push({\n contentSha256,\n byteLength,\n mimeType: file.mimeType,\n name: file.name,\n slotId,\n });\n }\n\n return { nextAttachments, nextPendingAttachments };\n}\n\nexport async function buildAttachmentIntent(\n slotId: string,\n file: DocumentAttachmentUpload,\n): Promise<DocumentAttachment> {\n return {\n contentSha256: await attachmentContentSha256(file.bytes),\n byteLength: blobByteSourceInputLength(file.bytes),\n mimeType: file.mimeType,\n name: file.name,\n slotId,\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
- import { createPendingUpdateFields } from "../../../data/documents/documentSync.js";
2
- import { deleteUnreferencedStagedAttachmentBytes, } from "./attachmentStaging.js";
3
- import { reloadDocumentFromDurableHistory } from "./durableDocumentReload.js";
4
- import { persistDocument } from "./persistence.js";
1
+ import { createPendingUpdateFields } from "../../../../data/documents/documentSync.js";
2
+ import { deleteUnreferencedStagedAttachmentBytes, } from "../attachmentUpload/attachmentStaging.js";
3
+ import { reloadDocumentFromDurableHistory } from "../history/durableDocumentReload.js";
4
+ import { persistDocument } from "../persistence.js";
5
5
  export async function restoreFailedAttachmentMutation(input) {
6
6
  await reloadDocumentFromDurableHistory({
7
7
  expectedGeneration: input.generation,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentMutationPersistence.js","sourceRoot":"","sources":["attachmentMutationPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EACL,uCAAuC,GAExC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAIjD,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,KAMrD;IACC,MAAM,gCAAgC,CAAC;QACrC,kBAAkB,EAAE,KAAK,CAAC,UAAU;QACpC,uCAAuC,EAAE,IAAI;QAC7C,oBAAoB,EAAE,KAAK,CAAC,gBAAgB;QAC5C,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,KAUrD;IACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAChC,IAAI,CAAC;QACH,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,KAAK,CAAC,UAAU,EAChB,EAAE,kBAAkB,EAAE,KAAK,CAAC,cAAc,EAAE,EAC5C;YACE,iBAAiB,EAAE,MAAM;YACzB,aAAa,EACX,yBAAyB,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,SAAS;YAChE,gCAAgC,EAAE,IAAI;YACtC,oBAAoB,EAAE,IAAI;SAC3B,EACD,KAAK,CAAC,UAAU,CACjB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,uCAAuC,CAAC;YAC5C,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;YAC7C,KAAK;SACN,CAAC,CAAC;QACH,MAAM,+BAA+B,CAAC;YACpC,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;YACxC,KAAK;SACN,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createPendingUpdateFields } from \"../../../../data/documents/documentSync\";\nimport {\n deleteUnreferencedStagedAttachmentBytes,\n type stagePendingAttachments,\n} from \"../attachmentUpload/attachmentStaging\";\nimport { reloadDocumentFromDurableHistory } from \"../history/durableDocumentReload\";\nimport { persistDocument } from \"../persistence\";\nimport type { DocumentStoreState } from \"../state\";\nimport type { captureDocumentStoreSyncGeneration } from \"../sync/syncGeneration\";\n\nexport async function restoreFailedAttachmentMutation(input: {\n generation: NonNullable<\n ReturnType<typeof captureDocumentStoreSyncGeneration>\n >;\n rollbackSnapshot: Uint8Array;\n state: DocumentStoreState;\n}): Promise<void> {\n await reloadDocumentFromDurableHistory({\n expectedGeneration: input.generation,\n preserveQueuedWritesWhenIdentityMatches: true,\n sameIdentitySnapshot: input.rollbackSnapshot,\n state: input.state,\n });\n}\n\nexport async function persistStagedAttachmentMutation(input: {\n attachmentUpdate: Uint8Array;\n coveredVersion: string;\n currentDoc: NonNullable<DocumentStoreState[\"doc\"]>;\n generation: NonNullable<\n ReturnType<typeof captureDocumentStoreSyncGeneration>\n >;\n rollbackSnapshot: Uint8Array;\n staged: NonNullable<Awaited<ReturnType<typeof stagePendingAttachments>>>;\n state: DocumentStoreState;\n}) {\n const { staged, state } = input;\n try {\n return await persistDocument(\n state,\n input.currentDoc,\n { snapshotEndVersion: input.coveredVersion },\n {\n attachmentStaging: staged,\n pendingUpdate:\n createPendingUpdateFields(input.attachmentUpdate) ?? undefined,\n preserveSnapshotStructuredFields: true,\n preserveSnapshotText: true,\n },\n input.generation,\n );\n } catch (error) {\n await deleteUnreferencedStagedAttachmentBytes({\n generation: input.generation,\n pendingAttachments: staged.pendingAttachments,\n state,\n });\n await restoreFailedAttachmentMutation({\n generation: input.generation,\n rollbackSnapshot: input.rollbackSnapshot,\n state,\n });\n throw error;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentPersistFollowup.js","sourceRoot":"","sources":["attachmentPersistFollowup.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,kCAAkC,CAAC,KAMlD;IACC,IACE,KAAK,CAAC,2BAA2B,KAAK,KAAK,CAAC,4BAA4B;QACxE,KAAK,CAAC,iBAAiB,KAAK,KAAK,CAAC,kBAAkB,EACpD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAClC,OAAO,CACL,KAAK,CAAC,SAAS,CAAC,0BAA0B,KAAK,IAAI;QACnD,KAAK,CAAC,SAAS,CAAC,sBAAsB,KAAK,IAAI,CAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { PersistedDocumentRecord } from \"../state\";\n\n/**\n * A same-identity conflict may still leave newer durable work for the current\n * lane to submit. Identity replacement and local teardown deliberately do not\n * schedule the losing document against the replacement generation.\n */\nexport function attachmentPersistNeedsFollowupSync(input: {\n currentDocumentId: string | null | undefined;\n currentLocalWriteGeneration: number;\n expectedDocumentId: string | null;\n expectedLocalWriteGeneration: number;\n persisted: PersistedDocumentRecord | null;\n}): boolean {\n if (\n input.currentLocalWriteGeneration !== input.expectedLocalWriteGeneration ||\n input.currentDocumentId !== input.expectedDocumentId\n ) {\n return false;\n }\n if (!input.persisted) return true;\n return (\n input.persisted.pullContinuationSuperseded === true &&\n input.persisted.syncIdentitySuperseded !== true\n );\n}\n"]}
@@ -1,8 +1,8 @@
1
- import { deleteLocalDocumentAttachment, deletePendingDocumentAttachment, saveLocalDocumentAttachments, savePendingDocumentAttachment, } from "../../../workflows/documents/index.js";
1
+ import { deleteLocalDocumentAttachment, deletePendingDocumentAttachment, saveLocalDocumentAttachments, savePendingDocumentAttachment, } from "../../../../workflows/documents/index.js";
2
+ import { withGenerationGuardedMutation } from "../persistence.js";
3
+ import { setReadySnapshot, } from "../state.js";
4
+ import { isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "../sync/syncGeneration.js";
2
5
  import { withLocalAttachmentDetachState } from "./attachmentDetachState.js";
3
- import { withGenerationGuardedMutation } from "./persistence.js";
4
- import { setReadySnapshot, } from "./state.js";
5
- import { isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "./syncGeneration.js";
6
6
  export async function deletePendingAttachment(state, slotId, storageKey, expectedGeneration) {
7
7
  // After a REFUSED discard the reset store keeps its rows, and a stale pass
8
8
  // racing that reset must not delete state the refusal deliberately
@@ -0,0 +1 @@
1
+ {"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ACjD,UAAgC;IAEhC,0BAA0B,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAE/C,IAAI,UAAU,IAAI,UAAU,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;QAC3C,gBAAgB,CACd,KAAK,EACL,UAAU,EACV,KAAK,CAAC,QAAQ,CAAC,OAAO,EACtB,KAAK,CAAC,QAAQ,CAAC,IAAI,EACnB,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAChC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAAyB,EACzB,sBAA8D;IAE9D,MAAM,WAAW,GAAG,IAAI,GAAG,CACzB,sBAAsB,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAC5E,CAAC;IACF,KAAK,CAAC,kBAAkB,GAAG;QACzB,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAChC,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAClE;QACD,GAAG,sBAAsB;KAC1B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,KAAyB,EACzB,iBAA0C,EAC1C,kBAAgD;IAEhD,yEAAyE;IACzE,uDAAuD;IACvD,MAAM,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE,CACzE,6BAA6B,CAAC;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,OAAO;QACP,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {\n deleteLocalDocumentAttachment,\n deletePendingDocumentAttachment,\n type LocalAttachmentRecord,\n type PendingAttachmentRecord,\n saveLocalDocumentAttachments,\n savePendingDocumentAttachment,\n} from \"../../../../workflows/documents\";\nimport { withGenerationGuardedMutation } from \"../persistence\";\nimport {\n type DocumentState,\n type DocumentStoreState,\n setReadySnapshot,\n} from \"../state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent,\n} from \"../sync/syncGeneration\";\nimport { withLocalAttachmentDetachState } from \"./attachmentDetachState\";\n\nexport async function deletePendingAttachment(\n state: DocumentStoreState,\n slotId: string,\n storageKey: string,\n expectedGeneration?: DocumentStoreSyncGeneration,\n) {\n // After a REFUSED discard the reset store keeps its rows, and a stale pass\n // racing that reset must not delete state the refusal deliberately\n // preserved.\n await withGenerationGuardedMutation(state, expectedGeneration, (execSql) =>\n deletePendingDocumentAttachment({\n execSql,\n localId: state.localId,\n persistence: state.persistence,\n slotId,\n storageKey,\n }),\n );\n}\n\nexport async function deleteLocalAttachmentRecord(\n state: DocumentStoreState,\n slotId: string,\n storageKey: string,\n currentDoc: DocumentState | null = state.doc,\n) {\n await deleteLocalDocumentAttachment({\n execSql: state.runtime.infra.execSql,\n localId: state.localId,\n persistence: state.persistence,\n slotId,\n storageKey,\n });\n\n if (state.attachmentStorageKeyBySlotId[slotId] === storageKey) {\n removeLocalAttachmentSlot(state, slotId);\n }\n\n if (currentDoc && currentDoc === state.doc) {\n setReadySnapshot(\n state,\n currentDoc,\n state.snapshot.syncing,\n state.snapshot.text,\n state.snapshot.structuredFields,\n );\n }\n}\n\nexport async function saveLocalAttachmentRecord(\n state: DocumentStoreState,\n attachment: LocalAttachmentRecord,\n currentDoc: DocumentState | null = state.doc,\n expectedGeneration?: DocumentStoreSyncGeneration,\n) {\n await saveLocalAttachmentRecords(\n state,\n [attachment],\n currentDoc,\n expectedGeneration,\n );\n}\n\nexport async function saveLocalAttachmentRecords(\n state: DocumentStoreState,\n attachments: ReadonlyArray<LocalAttachmentRecord>,\n currentDoc: DocumentState | null = state.doc,\n expectedGeneration?: DocumentStoreSyncGeneration,\n) {\n if (attachments.length === 0) {\n return;\n }\n\n // These rows are upserts, and a stale writer racing a teardown must never\n // re-insert what the teardown just removed.\n const saved = await withGenerationGuardedMutation(\n state,\n expectedGeneration,\n (execSql) =>\n saveLocalDocumentAttachments({\n attachments: withLocalAttachmentDetachState(attachments, currentDoc),\n execSql,\n persistence: state.persistence,\n }),\n );\n if (\n !saved ||\n (expectedGeneration && !isSyncGenerationCurrent(state, expectedGeneration))\n ) {\n return;\n }\n\n installLocalAttachmentRecords(state, attachments, currentDoc);\n}\n\ntype AttachmentSlot = Pick<\n LocalAttachmentRecord,\n \"slotId\" | \"blobId\" | \"contentSha256\" | \"storageKey\"\n>;\n\n/** Publish the held copy of each record's slot to the store's slot maps. */\nexport function assignLocalAttachmentSlots(\n state: DocumentStoreState,\n attachments: ReadonlyArray<AttachmentSlot>,\n): void {\n const entries = <T>(pick: (attachment: AttachmentSlot) => T) =>\n Object.fromEntries(\n attachments.map((attachment) => [attachment.slotId, pick(attachment)]),\n );\n state.attachmentBlobIdBySlotId = {\n ...state.attachmentBlobIdBySlotId,\n ...entries((attachment) => attachment.blobId),\n };\n state.attachmentContentSha256BySlotId = {\n ...state.attachmentContentSha256BySlotId,\n ...entries((attachment) => attachment.contentSha256),\n };\n state.attachmentStorageKeyBySlotId = {\n ...state.attachmentStorageKeyBySlotId,\n ...entries((attachment) => attachment.storageKey),\n };\n}\n\n/** Forget the held copy of one slot without touching its durable row. */\nexport function removeLocalAttachmentSlot(\n state: DocumentStoreState,\n slotId: string,\n): void {\n const { [slotId]: _blobId, ...blobIds } = state.attachmentBlobIdBySlotId;\n const { [slotId]: _contentSha256, ...contentSha256s } =\n state.attachmentContentSha256BySlotId;\n const { [slotId]: _storageKey, ...storageKeys } =\n state.attachmentStorageKeyBySlotId;\n state.attachmentBlobIdBySlotId = blobIds;\n state.attachmentContentSha256BySlotId = contentSha256s;\n state.attachmentStorageKeyBySlotId = storageKeys;\n}\n\nexport function installLocalAttachmentRecords(\n state: DocumentStoreState,\n attachments: ReadonlyArray<LocalAttachmentRecord>,\n currentDoc: DocumentState | null,\n) {\n assignLocalAttachmentSlots(state, attachments);\n\n if (currentDoc && currentDoc === state.doc) {\n setReadySnapshot(\n state,\n currentDoc,\n state.snapshot.syncing,\n state.snapshot.text,\n state.snapshot.structuredFields,\n );\n }\n}\n\nexport function upsertPendingAttachments(\n state: DocumentStoreState,\n nextPendingAttachments: ReadonlyArray<PendingAttachmentRecord>,\n) {\n const nextSlotIds = new Set(\n nextPendingAttachments.map((pendingAttachment) => pendingAttachment.slotId),\n );\n state.pendingAttachments = [\n ...state.pendingAttachments.filter(\n (pendingAttachment) => !nextSlotIds.has(pendingAttachment.slotId),\n ),\n ...nextPendingAttachments,\n ];\n}\n\n/**\n * Persist a pending attachment's upload-resume identity (blob id, content key,\n * IV, and — once staged — the multipart stage id/part size) so a later attempt\n * reuses it instead of orphaning the stage. The caller publishes the saved\n * identity on the live pending record only after this write succeeds.\n */\nexport async function savePendingAttachmentUpload(\n state: DocumentStoreState,\n pendingAttachment: PendingAttachmentRecord,\n expectedGeneration?: DocumentStoreSyncGeneration,\n): Promise<void> {\n // This row is an upsert, and a stale resume racing a teardown must never\n // re-insert the pending row the teardown just removed.\n await withGenerationGuardedMutation(state, expectedGeneration, (execSql) =>\n savePendingDocumentAttachment({\n attachment: pendingAttachment,\n execSql,\n persistence: state.persistence,\n }),\n );\n}\n"]}
@@ -1,17 +1,17 @@
1
- import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../internal/loro/index.js";
2
- import { getDocumentAttachments, removeDocumentAttachment, } from "../../../data/documents/documentContent.js";
3
- import { createPendingUpdateFields } from "../../../data/documents/documentSync.js";
4
- import { requestDocumentStoreSync } from "../registry.js";
1
+ import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../../internal/loro/index.js";
2
+ import { getDocumentAttachments, removeDocumentAttachment, } from "../../../../data/documents/documentContent.js";
3
+ import { createPendingUpdateFields } from "../../../../data/documents/documentSync.js";
4
+ import { requestDocumentStoreSync } from "../../registry.js";
5
+ import { ensureDocumentStoreReady } from "../initialization/index.js";
6
+ import { runDocumentOrphanMaintenance } from "../orphanMaintenance.js";
7
+ import { advancePendingBaseVersion, pendingDeltaSinceBase, persistDocument, } from "../persistence.js";
8
+ import { reportDocumentStoreWriteFailure } from "../reportWriteFailure.js";
9
+ import { canWriteDocument, setReadySnapshot, } from "../state.js";
10
+ import { captureDocumentStoreSyncGeneration } from "../sync/syncGeneration.js";
5
11
  import { restoreFailedAttachmentMutation } from "./attachmentMutationPersistence.js";
6
12
  import { assignLocalAttachmentSlots, removeLocalAttachmentSlot, } from "./attachmentPersistence.js";
7
- import { ATTACHMENT_FAILURE_MESSAGE } from "./attachments.js";
8
13
  import { captureAttachmentWriteGeneration, isAttachmentWriteGenerationCurrent, shouldAbortAttachmentPersistFollowup, } from "./attachmentWriteGeneration.js";
9
- import { ensureDocumentStoreReady } from "./initialization.js";
10
- import { runDocumentOrphanMaintenance } from "./orphanMaintenance.js";
11
- import { advancePendingBaseVersion, pendingDeltaSinceBase, persistDocument, } from "./persistence.js";
12
- import { reportDocumentStoreWriteFailure } from "./reportWriteFailure.js";
13
- import { canWriteDocument, setReadySnapshot, } from "./state.js";
14
- import { captureDocumentStoreSyncGeneration } from "./syncGeneration.js";
14
+ import { ATTACHMENT_FAILURE_MESSAGE } from "./index.js";
15
15
  function installCommittedAttachmentRemoval(input) {
16
16
  const { slotId, state, storageKey } = input;
17
17
  if (!storageKey)
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentRemoval.js","sourceRoot":"","sources":["attachmentRemoval.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mB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AAc,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 {\n getDocumentAttachments,\n removeDocumentAttachment,\n} from \"../../../../data/documents/documentContent\";\nimport { createPendingUpdateFields } from \"../../../../data/documents/documentSync\";\nimport { requestDocumentStoreSync } from \"../../registry\";\nimport { ensureDocumentStoreReady } from \"../initialization\";\nimport { runDocumentOrphanMaintenance } from \"../orphanMaintenance\";\nimport {\n advancePendingBaseVersion,\n pendingDeltaSinceBase,\n persistDocument,\n} from \"../persistence\";\nimport { reportDocumentStoreWriteFailure } from \"../reportWriteFailure\";\nimport {\n canWriteDocument,\n type DocumentStoreState,\n setReadySnapshot,\n} from \"../state\";\nimport { captureDocumentStoreSyncGeneration } from \"../sync/syncGeneration\";\nimport { restoreFailedAttachmentMutation } from \"./attachmentMutationPersistence\";\nimport {\n assignLocalAttachmentSlots,\n removeLocalAttachmentSlot,\n} from \"./attachmentPersistence\";\nimport {\n type AttachmentWriteGeneration,\n captureAttachmentWriteGeneration,\n isAttachmentWriteGenerationCurrent,\n shouldAbortAttachmentPersistFollowup,\n} from \"./attachmentWriteGeneration\";\nimport { ATTACHMENT_FAILURE_MESSAGE } from \"./index\";\n\nfunction installCommittedAttachmentRemoval(input: {\n currentDoc: NonNullable<DocumentStoreState[\"doc\"]>;\n slotId: string;\n state: DocumentStoreState;\n storageKey: string | undefined;\n syncedAttachment: boolean;\n}): void {\n const { slotId, state, storageKey } = input;\n if (!storageKey) return;\n const pending = state.pendingAttachments.find(\n (attachment) =>\n attachment.slotId === slotId && attachment.storageKey === storageKey,\n );\n if (input.syncedAttachment && pending?.upload) {\n assignLocalAttachmentSlots(state, [\n {\n slotId,\n storageKey,\n blobId: pending.upload.blobId,\n contentSha256: pending.contentSha256,\n },\n ]);\n }\n state.pendingAttachments = state.pendingAttachments.filter(\n (attachment) =>\n attachment.slotId !== slotId || attachment.storageKey !== storageKey,\n );\n // The committed removal queued this key. A reset can leave another document\n // uploading from the same copy; a detached marker keeps it until sync.\n void runDocumentOrphanMaintenance(state);\n if (\n input.syncedAttachment ||\n state.attachmentStorageKeyBySlotId[slotId] !== storageKey\n ) {\n return;\n }\n removeLocalAttachmentSlot(state, slotId);\n setReadySnapshot(\n state,\n input.currentDoc,\n state.snapshot.syncing,\n state.snapshot.text,\n state.snapshot.structuredFields,\n );\n}\n\nasync function persistRemovedAttachment(\n state: DocumentStoreState,\n slotId: string,\n writeGeneration: AttachmentWriteGeneration,\n) {\n if (!isAttachmentWriteGenerationCurrent(state, writeGeneration)) return;\n const currentDoc = state.doc;\n if (!currentDoc) {\n return;\n }\n const generation = captureDocumentStoreSyncGeneration(state, currentDoc);\n if (!generation) {\n return;\n }\n\n const existingAttachment = getDocumentAttachments(currentDoc).find(\n (attachment) => attachment.slotId === slotId,\n );\n if (!existingAttachment) {\n return;\n }\n\n // After a reset, a store opened cold holds the slot only as a pending upload.\n const storageKey =\n state.attachmentStorageKeyBySlotId[slotId] ??\n state.pendingAttachments.find((attachment) => attachment.slotId === slotId)\n ?.storageKey;\n if (\n !isAttachmentWriteGenerationCurrent(state, writeGeneration) ||\n state.doc !== currentDoc\n )\n return;\n const rollbackSnapshot = exportFullHistorySnapshot(currentDoc).slice();\n removeDocumentAttachment(currentDoc, slotId);\n const attachmentUpdate = pendingDeltaSinceBase(state, currentDoc);\n const coveredVersion = encodeVersionVector(currentDoc);\n const pendingUpdate = createPendingUpdateFields(attachmentUpdate);\n const syncedAttachment = Boolean(state.record?.documentId);\n\n // Preserve the optimistic text/structured fields (see persistAttachedFiles):\n // removing an attachment while typing must not regress the editor.\n let persisted: Awaited<ReturnType<typeof persistDocument>>;\n try {\n persisted = await persistDocument(\n state,\n currentDoc,\n { snapshotEndVersion: coveredVersion },\n {\n ...(storageKey\n ? {\n attachmentRemoval: {\n mode: syncedAttachment\n ? (\"detach\" as const)\n : (\"delete\" as const),\n slotId,\n storageKey,\n },\n }\n : {}),\n ...(pendingUpdate ? { pendingUpdate } : {}),\n preserveSnapshotStructuredFields: true,\n preserveSnapshotText: true,\n },\n generation,\n );\n } catch (error) {\n await restoreFailedAttachmentMutation({\n generation,\n rollbackSnapshot,\n state,\n });\n throw error;\n }\n if (\n shouldAbortAttachmentPersistFollowup(\n state,\n writeGeneration,\n generation,\n persisted,\n )\n ) {\n // See persistAttachedFiles: only durable same-identity work re-arms sync.\n return;\n }\n installCommittedAttachmentRemoval({\n currentDoc,\n slotId,\n state,\n storageKey,\n syncedAttachment,\n });\n advancePendingBaseVersion(state, currentDoc);\n state.runtime.util.log(\n `Removed attachment ${existingAttachment.name} from document ${state.localId}.`,\n );\n requestDocumentStoreSync(state);\n}\n\nexport async function removeAttachmentFromDocumentStore(\n state: DocumentStoreState,\n scheduleSync: () => void,\n slotId: string,\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 () => persistRemovedAttachment(state, slotId, writeGeneration))\n .catch((error: unknown) => {\n reportDocumentStoreWriteFailure(state, ATTACHMENT_FAILURE_MESSAGE, error);\n });\n return state.writeChain;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentSnapshot.js","sourceRoot":"","sources":["attachmentSnapshot.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,wBAAwB,CACtC,kBAAoD,EACpD,WAA8C;IAE9C,MAAM,eAAe,GAA2B,EAAE,CAAC;IAEnD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,UAAU,EAAE,CAAC;YACf,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAIrC;IACC,MAAM,YAAY,GAA6C,EAAE,CAAC;IAElE,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;QAC3C,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAChD,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;YAC5C,SAAS;QACX,CAAC;QACD,MAAM,iBAAiB,GAAG,KAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzE,IACE,iBAAiB,KAAK,SAAS;YAC/B,iBAAiB,KAAK,UAAU,CAAC,aAAa,EAC9C,CAAC;YACD,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC;QACtD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import type { DocumentAttachment } from \"../../../../data/documents/documentContent\";\nimport type { DocumentAttachmentStatus } from \"../../types\";\n\nexport function getAttachmentStorageKeys(\n storageKeyBySlotId: Readonly<Record<string, string>>,\n attachments: ReadonlyArray<DocumentAttachment>,\n): Record<string, string> {\n const nextStorageKeys: Record<string, string> = {};\n\n for (const attachment of attachments) {\n const storageKey = storageKeyBySlotId[attachment.slotId];\n if (storageKey) {\n nextStorageKeys[attachment.slotId] = storageKey;\n }\n }\n\n return nextStorageKeys;\n}\n\n/**\n * A slot is `syncing` while its upload is queued. Otherwise it is\n * `intent-mismatch` when the held bytes' digest differs from the digest the\n * document content records: a validly signed served binding the document has\n * not (yet) recorded. The status clears by itself once the content update\n * carrying the digest arrives or a matching binding is hydrated.\n */\nexport function getAttachmentStatuses(input: {\n attachments: ReadonlyArray<DocumentAttachment>;\n contentSha256BySlotId: Readonly<Record<string, string>>;\n pendingSlotIds: ReadonlySet<string>;\n}): Record<string, DocumentAttachmentStatus> {\n const nextStatuses: Record<string, DocumentAttachmentStatus> = {};\n\n for (const attachment of input.attachments) {\n if (input.pendingSlotIds.has(attachment.slotId)) {\n nextStatuses[attachment.slotId] = \"syncing\";\n continue;\n }\n const heldContentSha256 = input.contentSha256BySlotId[attachment.slotId];\n if (\n heldContentSha256 !== undefined &&\n heldContentSha256 !== attachment.contentSha256\n ) {\n nextStatuses[attachment.slotId] = \"intent-mismatch\";\n }\n }\n\n return nextStatuses;\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { requestDocumentStoreSync } from "../registry.js";
1
+ import { requestDocumentStoreSync } from "../../registry.js";
2
+ import { isDocumentStoreSyncGenerationCurrent, } from "../sync/syncGeneration.js";
2
3
  import { attachmentPersistNeedsFollowupSync } from "./attachmentPersistFollowup.js";
3
- import { isDocumentStoreSyncGenerationCurrent, } from "./syncGeneration.js";
4
4
  export function captureAttachmentWriteGeneration(state) {
5
5
  if (!state.record)
6
6
  return null;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentWriteGeneration.js","sourceRoot":"","sources":["attachmentWriteGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAEL,oCAAoC,GACrC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AAOjF,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 type { DocumentStoreState, PersistedDocumentRecord } from \"../state\";\nimport {\n type DocumentStoreSyncGeneration,\n isDocumentStoreSyncGenerationCurrent,\n} from \"../sync/syncGeneration\";\nimport { attachmentPersistNeedsFollowupSync } from \"./attachmentPersistFollowup\";\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,16 +1,16 @@
1
- import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../internal/loro/index.js";
2
- import { addDocumentAttachments } from "../../../data/documents/documentContent.js";
3
- import { requestDocumentStoreSync } from "../registry.js";
1
+ import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../../internal/loro/index.js";
2
+ import { addDocumentAttachments } from "../../../../data/documents/documentContent.js";
3
+ import { requestDocumentStoreSync } from "../../registry.js";
4
+ import { deleteUnreferencedStagedAttachmentBytes, installPendingAttachmentRows, stagePendingAttachments, } from "../attachmentUpload/attachmentStaging.js";
5
+ import { ensureDocumentStoreReady } from "../initialization/index.js";
6
+ import { settleDeferredInitialUpdate } from "../initialization/deferredInitialUpdate.js";
7
+ import { advancePendingBaseVersion, pendingDeltaSinceBase, } from "../persistence.js";
8
+ import { reportDocumentStoreWriteFailure } from "../reportWriteFailure.js";
9
+ import { canAttachFiles, canWriteDocument, } from "../state.js";
10
+ import { captureDocumentStoreSyncGeneration } from "../sync/syncGeneration.js";
4
11
  import { buildAttachmentIntent, buildPendingAttachments, } from "./attachmentIntents.js";
5
12
  import { persistStagedAttachmentMutation, restoreFailedAttachmentMutation, } from "./attachmentMutationPersistence.js";
6
- import { deleteUnreferencedStagedAttachmentBytes, installPendingAttachmentRows, stagePendingAttachments, } from "./attachmentStaging.js";
7
13
  import { captureAttachmentWriteGeneration, isAttachmentWriteGenerationCurrent, shouldAbortAttachmentPersistFollowup, } from "./attachmentWriteGeneration.js";
8
- import { settleDeferredInitialUpdate } from "./deferredInitialUpdate.js";
9
- import { ensureDocumentStoreReady } from "./initialization.js";
10
- import { advancePendingBaseVersion, pendingDeltaSinceBase, } from "./persistence.js";
11
- import { reportDocumentStoreWriteFailure } from "./reportWriteFailure.js";
12
- import { canAttachFiles, canWriteDocument, } from "./state.js";
13
- import { captureDocumentStoreSyncGeneration } from "./syncGeneration.js";
14
14
  // Fixed literal: a reported message must never carry file names or slot ids.
15
15
  export const ATTACHMENT_FAILURE_MESSAGE = "Documents: attachment mutation failed";
16
16
  function logAttachedFiles(state, count) {
@@ -238,4 +238,4 @@ export async function replaceAttachmentInDocumentStore(state, scheduleSync, slot
238
238
  });
239
239
  return state.writeChain;
240
240
  }
241
- //# sourceMappingURL=attachments.js.map
241
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OA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CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+BAA+B,CAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,CAAC,CAAC;QAC1E,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,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 deleteUnreferencedStagedAttachmentBytes,\n installPendingAttachmentRows,\n stagePendingAttachments,\n} from \"../attachmentUpload/attachmentStaging\";\nimport { ensureDocumentStoreReady } from \"../initialization\";\nimport { settleDeferredInitialUpdate } from \"../initialization/deferredInitialUpdate\";\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 \"../sync/syncGeneration\";\nimport {\n buildAttachmentIntent,\n buildPendingAttachments,\n} from \"./attachmentIntents\";\nimport {\n persistStagedAttachmentMutation,\n restoreFailedAttachmentMutation,\n} from \"./attachmentMutationPersistence\";\nimport {\n type AttachmentWriteGeneration,\n captureAttachmentWriteGeneration,\n isAttachmentWriteGenerationCurrent,\n shouldAbortAttachmentPersistFollowup,\n} from \"./attachmentWriteGeneration\";\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,7 +1,7 @@
1
- import { base64ToBytes, bytesToBase64 } from "../../../internal/encoding/index.js";
2
- import { encodeVersionVector, exportFullHistorySnapshot, updateMatchesDocumentHistory, } from "../../../internal/loro/index.js";
3
- import { DOCUMENT_HISTORY_COMPACTION_MAX_BYTES, DOCUMENT_HISTORY_COMPACTION_MAX_ROWS, } from "../../../workflows/documents/index.js";
4
- import { captureDocumentStoreSyncGeneration, isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "./syncGeneration.js";
1
+ import { base64ToBytes, bytesToBase64 } from "../../../../internal/encoding/index.js";
2
+ import { encodeVersionVector, exportFullHistorySnapshot, updateMatchesDocumentHistory, } from "../../../../internal/loro/index.js";
3
+ import { DOCUMENT_HISTORY_COMPACTION_MAX_BYTES, DOCUMENT_HISTORY_COMPACTION_MAX_ROWS, } from "../../../../workflows/documents/index.js";
4
+ import { captureDocumentStoreSyncGeneration, isDocumentStoreSyncGenerationCurrent as isSyncGenerationCurrent, } from "../sync/syncGeneration.js";
5
5
  /**
6
6
  * Refresh the durable full-history checkpoint when the tail has grown past
7
7
  * the compaction thresholds, or seed the first checkpoint as soon as the
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentHistoryCompaction.js","sourceRoot":"","sources":["documentHistoryCompaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qCAAqC,EACrC,oCAAoC,GACrC,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,kCAAkC,EAClC,oCAAoC,IAAI,uBAAuB,GAChE,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,KAAyB,EACzB,UAAyB,EACzB,YAA0C;IAE1C,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK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Y,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 \"../sync/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,9 +1,9 @@
1
- import { base64ToBytes } from "../../../internal/encoding/index.js";
2
- import { importSnapshot } from "../../../internal/loro/index.js";
3
- import { importDocumentHistoryTailUpdates, runSerializedSqlMutation, } from "../../../workflows/documents/index.js";
4
- import { markDocumentStoreRemoved, setReadySnapshot, } from "./state.js";
5
- import { createFreshPeerStoredDocument } from "./storedDocument.js";
6
- import { isDocumentStoreSyncGenerationCurrent, } from "./syncGeneration.js";
1
+ import { base64ToBytes } from "../../../../internal/encoding/index.js";
2
+ import { importSnapshot } from "../../../../internal/loro/index.js";
3
+ import { importDocumentHistoryTailUpdates, runSerializedSqlMutation, } from "../../../../workflows/documents/index.js";
4
+ import { markDocumentStoreRemoved, setReadySnapshot, } from "../state.js";
5
+ import { createFreshPeerStoredDocument } from "../storedDocument.js";
6
+ import { isDocumentStoreSyncGenerationCurrent, } from "../sync/syncGeneration.js";
7
7
  export function importDurableDocumentHistory(replacementDoc, history) {
8
8
  if (history?.snapshot) {
9
9
  importSnapshot(replacementDoc, base64ToBytes(history.snapshot));
@@ -0,0 +1 @@
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,iCAAiC,CAAC;AACzC,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAEL,oCAAoC,GACrC,MAAM,wBAAwB,CAAC;AAShC,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,CACv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,IAAI,0BAA0B,IAAI,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC7D,cAAc,CAAC,cAAc,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC7D,CAAC;QACD,sEAAsE;QACtE,oEAAoE;QACpE,wEAAwE;QACxE,uEAAuE;QACvE,2DAA2D;QAC3D,4BAA4B,CAAC,cAAc,EAAE,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 \"../sync/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,9 +1,9 @@
1
- import { bytesToBase64 } from "../../../internal/encoding/index.js";
2
- import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../internal/loro/index.js";
3
- import { readPullContinuation } from "../../../data/documents/shared/syncPagination.js";
4
- import { persistDocument } from "./persistence.js";
5
- import { isDocumentStoreSyncGenerationCurrent, } from "./syncGeneration.js";
6
- import { installDocumentWriterProjection } from "./writerProjectionGeneration.js";
1
+ import { bytesToBase64 } from "../../../../internal/encoding/index.js";
2
+ import { encodeVersionVector, exportFullHistorySnapshot, } from "../../../../internal/loro/index.js";
3
+ import { readPullContinuation } from "../../../../data/documents/shared/syncPagination.js";
4
+ import { persistDocument } from "../persistence.js";
5
+ import { isDocumentStoreSyncGenerationCurrent, } from "../sync/syncGeneration.js";
6
+ import { installDocumentWriterProjection } from "../writerProjectionGeneration.js";
7
7
  /**
8
8
  * Machinery for reconstructing a full-history document from a verified remote
9
9
  * pull. Used by the rotation preflight (rotation.ts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K,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 \"../sync/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,8 +1,8 @@
1
- import type { StoredDocumentKind } from "../../data/documents/documentKinds.js";
2
- import type { DomainScope } from "../../data/shared/domainScope.js";
3
- import { type DocumentsPersistence } from "../../workflows/documents/index.js";
4
- import type { DocumentStore, DocumentStoreFacade, DocumentStoreOpenOptions, DocumentsRuntime } from "./types.js";
5
- export { discardRegisteredDocumentLocalState, requestDomainDocumentSync, subscribeToPersistedDocuments, } from "./registry.js";
1
+ import type { StoredDocumentKind } from "../../../data/documents/documentKinds.js";
2
+ import type { DomainScope } from "../../../data/shared/domainScope.js";
3
+ import { type DocumentsPersistence } from "../../../workflows/documents/index.js";
4
+ import type { DocumentStore, DocumentStoreFacade, DocumentStoreOpenOptions, DocumentsRuntime } from "../types.js";
5
+ export { discardRegisteredDocumentLocalState, requestDomainDocumentSync, subscribeToPersistedDocuments, } from "../registry.js";
6
6
  export declare function createDocumentStore(localId: string, initialRuntime: DocumentsRuntime, persistence?: DocumentsPersistence, initialDocumentId?: string | null, initialText?: string, initialDocumentKind?: StoredDocumentKind, options?: DocumentStoreOpenOptions): DocumentStoreFacade;
7
7
  export declare function getOrCreateDocumentStore(domainScope: DomainScope, localId: string, runtime: DocumentsRuntime, initialDocumentId?: string | null, initialText?: string, initialDocumentKind?: StoredDocumentKind, options?: DocumentStoreOpenOptions): DocumentStore;
8
8
  export declare function openDocumentStore(domainScope: DomainScope, localId: string, runtime: DocumentsRuntime, initialDocumentId?: string | null, initialText?: string, initialDocumentKind?: StoredDocumentKind, options?: DocumentStoreOpenOptions): DocumentStore;
@@ -1,20 +1,20 @@
1
- import { DEFAULT_DOCUMENT_KIND } from "../../data/documents/documentConstants.js";
2
- import { createDocumentProjectionUserKeyResolver, defaultDocumentsPersistence, didDocumentProjectionKeyRuntimeChange, didRegainSyncPrerequisites, requestDocumentSyncLaneAndWait, } from "../../workflows/documents/index.js";
3
- import { removeAttachmentFromDocumentStore } from "./documentStore/attachmentRemoval.js";
4
- import { attachFilesToDocumentStore, replaceAttachmentInDocumentStore, } from "./documentStore/attachments.js";
5
- import { discardDocumentStoreLocalState } from "./documentStore/discard.js";
6
- import { ensureDocumentStoreInitialized, ensureDocumentStoreReady, relinkDocumentStore, } from "./documentStore/initialization.js";
7
- import { registerInternalDocumentRelink } from "./documentStore/internalRelink.js";
8
- import { setDocumentStructuredFields, setDocumentText, } from "./documentStore/mutations.js";
9
- import { logRevalidationScheduled } from "./documentStore/remoteRevalidationTelemetry.js";
10
- import { assertDocumentStoreCanRotateContentKey } from "./documentStore/rotation.js";
11
- import { addRowToDocumentStore, removeRowFromDocumentStore, updateRowInDocumentStore, } from "./documentStore/rows.js";
12
- import { createDocumentStoreState, refreshAttachabilitySnapshot, resetDocumentStore, subscribeToDocumentStore, } from "./documentStore/state.js";
13
- import { registerDocumentStoreSyncLane } from "./documentStore/sync.js";
14
- import { allowDocumentStoreRemoteSync, captureDocumentStoreRemoteSyncRequestGeneration, captureDocumentStoreSyncLaneGeneration, didDocumentStoreRemoteSyncRequestComplete, hasPendingIndependentDocumentStoreRemoteSync, invalidateDocumentStoreRemoteSync, invalidateDocumentStoreSyncLane, isDocumentStoreRemoteSyncBlocked, isDocumentStoreRemoteSyncRequestGenerationCurrent, markDocumentStoreRemoteSyncPending, registerDocumentStoreRemoteSyncWaiter, } from "./documentStore/syncGeneration.js";
15
- import { handleDocumentRemoteEvents } from "./documentStore/syncRemoteSignals.js";
16
- import { createDocumentStoreFacade, emitPersistedDocument, getOrCreateDocumentStoreRegistry, registerDocumentStore, registerDocumentStoreIdentity, requestDocumentStoreSync, resolveDocumentStoreKey, } from "./registry.js";
17
- export { discardRegisteredDocumentLocalState, requestDomainDocumentSync, subscribeToPersistedDocuments, } from "./registry.js";
1
+ import { DEFAULT_DOCUMENT_KIND } from "../../../data/documents/documentConstants.js";
2
+ import { createDocumentProjectionUserKeyResolver, defaultDocumentsPersistence, didDocumentProjectionKeyRuntimeChange, didRegainSyncPrerequisites, requestDocumentSyncLaneAndWait, } from "../../../workflows/documents/index.js";
3
+ import { createDocumentStoreFacade, emitPersistedDocument, getOrCreateDocumentStoreRegistry, registerDocumentStore, registerDocumentStoreIdentity, requestDocumentStoreSync, resolveDocumentStoreKey, } from "../registry.js";
4
+ import { attachFilesToDocumentStore, replaceAttachmentInDocumentStore, } from "./attachments/index.js";
5
+ import { removeAttachmentFromDocumentStore } from "./attachments/attachmentRemoval.js";
6
+ import { discardDocumentStoreLocalState } from "./discard.js";
7
+ import { ensureDocumentStoreInitialized, ensureDocumentStoreReady, relinkDocumentStore, } from "./initialization/index.js";
8
+ import { registerInternalDocumentRelink } from "./internalRelink.js";
9
+ import { setDocumentStructuredFields, setDocumentText } from "./mutations.js";
10
+ import { assertDocumentStoreCanRotateContentKey } from "./rotation/index.js";
11
+ import { addRowToDocumentStore, removeRowFromDocumentStore, updateRowInDocumentStore, } from "./rows.js";
12
+ import { createDocumentStoreState, refreshAttachabilitySnapshot, resetDocumentStore, subscribeToDocumentStore, } from "./state.js";
13
+ import { registerDocumentStoreSyncLane } from "./sync/index.js";
14
+ import { logRevalidationScheduled } from "./sync/remoteRevalidationTelemetry.js";
15
+ import { allowDocumentStoreRemoteSync, captureDocumentStoreRemoteSyncRequestGeneration, captureDocumentStoreSyncLaneGeneration, didDocumentStoreRemoteSyncRequestComplete, hasPendingIndependentDocumentStoreRemoteSync, invalidateDocumentStoreRemoteSync, invalidateDocumentStoreSyncLane, isDocumentStoreRemoteSyncBlocked, isDocumentStoreRemoteSyncRequestGenerationCurrent, markDocumentStoreRemoteSyncPending, registerDocumentStoreRemoteSyncWaiter, } from "./sync/syncGeneration.js";
16
+ import { handleDocumentRemoteEvents } from "./sync/syncRemoteSignals.js";
17
+ export { discardRegisteredDocumentLocalState, requestDomainDocumentSync, subscribeToPersistedDocuments, } from "../registry.js";
18
18
  function refreshDocumentStoreSyncLane(state, force = false) {
19
19
  if (!force && state.syncLane && !state.syncLane.isDisposed?.()) {
20
20
  return;
@@ -212,4 +212,4 @@ export function openDocumentStore(domainScope, localId, runtime, initialDocument
212
212
  store.updateRuntime(runtime);
213
213
  return store;
214
214
  }
215
- //# sourceMappingURL=documentStore.js.map
215
+ //# sourceMappingURL=index.js.map