@tearleads/client-sdk 0.1.64 → 0.1.66

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 (646) hide show
  1. package/client/organizations/organizationAccessRestoration.js +1 -1
  2. package/data/containers/shared/mutationAcknowledgement.js +1 -1
  3. package/data/containers/shared/mutationAcknowledgement.js.map +1 -1
  4. package/data/documents/blob/shared/projection.js +3 -3
  5. package/data/documents/blob/shared/projection.js.map +1 -1
  6. package/data/documents/shared/{containerKekCurrency.d.ts → containerKek/containerKekCurrency.d.ts} +1 -1
  7. package/data/documents/shared/{containerKekEntryVerification.js → containerKek/containerKekEntryVerification.js} +1 -1
  8. package/data/documents/shared/{containerKekLogFetch.d.ts → containerKek/containerKekLogFetch.d.ts} +1 -1
  9. package/data/documents/shared/{containerKekLogFetch.js → containerKek/containerKekLogFetch.js} +1 -1
  10. package/data/documents/shared/{containerKekPath.js → containerKek/containerKekPath.js} +3 -3
  11. package/data/documents/shared/containerKek/containerKekPath.js.map +1 -0
  12. package/data/documents/shared/{containerKekPathHistory.d.ts → containerKek/containerKekPathHistory.d.ts} +3 -3
  13. package/data/documents/shared/{containerKekPathHistory.js → containerKek/containerKekPathHistory.js} +4 -4
  14. package/data/documents/shared/containerKek/containerKekPathHistory.js.map +1 -0
  15. package/data/documents/shared/{containerKekPathVerification.d.ts → containerKek/containerKekPathVerification.d.ts} +5 -5
  16. package/data/documents/shared/{containerKekPathVerification.js → containerKek/containerKekPathVerification.js} +2 -2
  17. package/data/documents/shared/containerKek/containerKekPathVerification.js.map +1 -0
  18. package/data/documents/shared/{containerKekWrapping.js → containerKek/containerKekWrapping.js} +3 -3
  19. package/data/documents/shared/containerKek/containerKekWrapping.js.map +1 -0
  20. package/data/documents/shared/{keyringLogWalk.d.ts → containerKek/keyringLogWalk.d.ts} +2 -2
  21. package/data/documents/shared/{keyringLogWalk.js → containerKek/keyringLogWalk.js} +1 -1
  22. package/data/documents/shared/{keyringRebuild.d.ts → containerKek/keyringRebuild.d.ts} +3 -3
  23. package/data/documents/shared/{keyringRebuild.js → containerKek/keyringRebuild.js} +3 -3
  24. package/data/documents/shared/containerKek/keyringRebuild.js.map +1 -0
  25. package/data/documents/shared/crypto.js +2 -2
  26. package/data/documents/shared/crypto.js.map +1 -1
  27. package/data/documents/shared/events.js +1 -1
  28. package/data/documents/shared/{projection.d.ts → projection/index.d.ts} +7 -7
  29. package/data/documents/shared/{projection.js → projection/index.js} +9 -9
  30. package/data/documents/shared/projection/index.js.map +1 -0
  31. package/data/documents/shared/{projectionContentKeys.d.ts → projection/projectionContentKeys.d.ts} +6 -6
  32. package/data/documents/shared/{projectionContentKeys.js → projection/projectionContentKeys.js} +9 -9
  33. package/data/documents/shared/projection/projectionContentKeys.js.map +1 -0
  34. package/data/documents/shared/{projectionTargets.d.ts → projection/projectionTargets.d.ts} +4 -4
  35. package/data/documents/shared/{projectionTargets.js → projection/projectionTargets.js} +3 -3
  36. package/data/documents/shared/projection/projectionTargets.js.map +1 -0
  37. package/data/documents/shared/responses.d.ts +1 -1
  38. package/data/documents/shared/responses.js +1 -1
  39. package/data/documents/shared/responses.js.map +1 -1
  40. package/data/documents/shared/{documentSyncUpdateDecryption.js → sync/documentSyncUpdateDecryption.js} +10 -10
  41. package/data/documents/shared/sync/documentSyncUpdateDecryption.js.map +1 -0
  42. package/data/documents/shared/{documentSyncUpdateIsolation.d.ts → sync/documentSyncUpdateIsolation.d.ts} +3 -3
  43. package/data/documents/shared/{documentSyncUpdateIsolation.js → sync/documentSyncUpdateIsolation.js} +1 -1
  44. package/data/documents/shared/sync/documentSyncUpdateIsolation.js.map +1 -0
  45. package/data/documents/shared/{mutationAcknowledgement.js → sync/mutationAcknowledgement.js} +1 -1
  46. package/data/documents/shared/sync/mutationAcknowledgement.js.map +1 -0
  47. package/data/documents/shared/{pullContinuation.js → sync/pullContinuation.js} +1 -1
  48. package/data/documents/shared/{syncPagination.d.ts → sync/syncPagination.d.ts} +2 -2
  49. package/data/documents/shared/{syncPagination.js → sync/syncPagination.js} +1 -1
  50. package/data/documents/shared/sync/syncPagination.js.map +1 -0
  51. package/data/documents/shared/{syncResponseAuthorization.js → sync/syncResponseAuthorization.js} +3 -3
  52. package/data/documents/shared/sync/syncResponseAuthorization.js.map +1 -0
  53. package/data/documents/shared/{syncResponses.d.ts → sync/syncResponses.d.ts} +2 -2
  54. package/data/documents/shared/{syncResponses.js → sync/syncResponses.js} +6 -6
  55. package/data/documents/shared/sync/syncResponses.js.map +1 -0
  56. package/data/documents/shared/{syncSubmitFailure.d.ts → sync/syncSubmitFailure.d.ts} +1 -1
  57. package/data/documents/shared/types.d.ts +3 -3
  58. package/data/documents/shared/types.js.map +1 -1
  59. package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js +1 -1
  60. package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js.map +1 -1
  61. package/data/keyingProjectionVerification/checkpoints/checkpointContext.d.ts +1 -1
  62. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js +1 -1
  63. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
  64. package/data/keyingProjectionVerification/checkpoints/manifestCheckpointVerification.js +1 -1
  65. package/data/keyingProjectionVerification/checkpoints/manifestCheckpointVerification.js.map +1 -1
  66. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointCurrency.js +4 -4
  67. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointCurrency.js.map +1 -1
  68. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointEnforcement.js +1 -1
  69. package/data/keyingProjectionVerification/documentPurge/documentPurgeCheckpointEnforcement.js.map +1 -1
  70. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCheckpoints.js +1 -1
  71. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCheckpoints.js.map +1 -1
  72. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCurrency.js +1 -1
  73. package/data/keyingProjectionVerification/documentPurge/documentPurgePolicyCurrency.js.map +1 -1
  74. package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js +3 -3
  75. package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js.map +1 -1
  76. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js +4 -4
  77. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map +1 -1
  78. package/data/keyingProjectionVerification/principalPolicy/resolvedPrincipalPolicy.js +2 -2
  79. package/data/keyingProjectionVerification/principalPolicy/resolvedPrincipalPolicy.js.map +1 -1
  80. package/data/persistence/container-contents/containerContentsPersistence.js +3 -3
  81. package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
  82. package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +2 -2
  83. package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
  84. package/data/persistence/container-contents/containerCreateIntentSettlement.js +1 -1
  85. package/data/persistence/container-contents/containerDeletionPersistence.js +2 -2
  86. package/data/persistence/container-contents/containerDocumentReassignment.js +2 -2
  87. package/data/persistence/container-contents/containerDocumentReassignment.js.map +1 -1
  88. package/data/persistence/container-contents/containerHydrationPersistence.js +3 -3
  89. package/data/persistence/container-contents/containerHydrationPersistence.js.map +1 -1
  90. package/data/persistence/container-contents/containerIntentPersistence.js +1 -1
  91. package/data/persistence/container-contents/containerMetadataMutationPersistence.js +5 -5
  92. package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
  93. package/data/persistence/container-contents/containerMetadataPullContinuationPersistence.js +1 -1
  94. package/data/persistence/container-contents/containerMetadataRows.js +3 -3
  95. package/data/persistence/container-contents/containerMetadataRows.js.map +1 -1
  96. package/data/persistence/container-contents/containerMoveAbandonPersistence.js +1 -1
  97. package/data/persistence/container-contents/containerMoveIntentRows.js +1 -1
  98. package/data/persistence/container-contents/containerPendingUpdatePersistence.js +3 -3
  99. package/data/persistence/container-contents/containerPendingUpdatePersistence.js.map +1 -1
  100. package/data/persistence/container-contents/containerRebindPersistence.js +1 -1
  101. package/data/persistence/container-contents/containerReconcilePersistence.js +2 -2
  102. package/data/persistence/container-contents/containerRecoveryPersistence.js +1 -1
  103. package/data/persistence/container-contents/containerRemovalWork.js +3 -3
  104. package/data/persistence/container-contents/containerRemovalWork.js.map +1 -1
  105. package/data/persistence/container-contents/containerStructuralRepair.js +1 -1
  106. package/data/persistence/container-contents/documentLinkRemovalRepair.js +2 -2
  107. package/data/persistence/container-contents/documentLinkRemovalRepair.js.map +1 -1
  108. package/data/persistence/container-contents/documentMoveIntentPersistence.js +2 -2
  109. package/data/persistence/container-contents/documentMoveIntentPersistence.js.map +1 -1
  110. package/data/persistence/container-contents/documentPlacementIntentEnqueue.js +2 -2
  111. package/data/persistence/container-contents/documentPlacementIntentEnqueue.js.map +1 -1
  112. package/data/persistence/container-contents/documentPurgePlacement.js +14 -1
  113. package/data/persistence/container-contents/documentPurgePlacement.js.map +1 -1
  114. package/data/persistence/container-contents/dormantContainerMetadata.js +1 -1
  115. package/data/persistence/container-contents/dormantMetadataSweep.js +1 -1
  116. package/data/persistence/container-contents/pendingContainerCreate.js +1 -1
  117. package/data/persistence/container-contents/supersededContainerBindings.js +1 -1
  118. package/data/persistence/containers/containerPersistence.js +1 -1
  119. package/data/persistence/containers/containerSyncWatermarkPersistence.js +1 -1
  120. package/data/persistence/containers/documentContainerProjectionPersistence.js +1 -1
  121. package/data/persistence/containers/documentPlacement.js +1 -1
  122. package/data/persistence/documents/containerDocumentTombstoneHoldsPersistence.js +1 -1
  123. package/data/persistence/documents/documentDiscoveryEvidencePersistence.js +3 -3
  124. package/data/persistence/documents/documentDiscoveryEvidencePersistence.js.map +1 -1
  125. package/data/persistence/documents/documentDiscoveryReset.js +1 -1
  126. package/data/persistence/documents/documentDiscoveryReset.js.map +1 -1
  127. package/data/persistence/documents/documentsPersistence.js +3 -3
  128. package/data/persistence/documents/documentsPersistence.js.map +1 -1
  129. package/data/persistence/documents/internal/attachmentStagingPersistence.js +1 -1
  130. package/data/persistence/documents/internal/containerDocumentTombstoneHolds.js +1 -1
  131. package/data/persistence/documents/internal/containerDocumentTombstones.js +1 -1
  132. package/data/persistence/documents/internal/createDocumentWithHistoryCheckpoint.js +2 -2
  133. package/data/persistence/documents/internal/createDocumentWithHistoryCheckpoint.js.map +1 -1
  134. package/data/persistence/documents/internal/discardDocument.js +3 -3
  135. package/data/persistence/documents/internal/discardDocument.js.map +1 -1
  136. package/data/persistence/documents/internal/documentDeletionPersistence.js +4 -4
  137. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  138. package/data/persistence/documents/internal/documentMutationPersistence.js +5 -5
  139. package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
  140. package/data/persistence/documents/internal/documentProjectionRows.js +1 -1
  141. package/data/persistence/documents/internal/documentPullContinuationPersistence.js +1 -1
  142. package/data/persistence/documents/internal/documentRows.js +2 -2
  143. package/data/persistence/documents/internal/documentRows.js.map +1 -1
  144. package/data/persistence/documents/internal/documentSummaryQueries.js +1 -1
  145. package/data/persistence/documents/internal/ensureDocumentsSchema.js +2 -2
  146. package/data/persistence/documents/internal/hydratedAttachmentPersistence.js +1 -1
  147. package/data/persistence/documents/internal/orphanSideRows.js +2 -2
  148. package/data/persistence/documents/internal/orphanSideRows.js.map +1 -1
  149. package/data/persistence/documents/internal/pendingCreateAdoption.js +1 -1
  150. package/data/persistence/documents/internal/rowQueryPersistence.js +2 -2
  151. package/data/persistence/documents/internal/syncQueuePersistence.js +3 -3
  152. package/data/persistence/documents/internal/syncQueuePersistence.js.map +1 -1
  153. package/data/persistence/documents/types.d.ts +3 -3
  154. package/data/persistence/documents/types.js.map +1 -1
  155. package/data/persistence/{documentPurgeCheckpointPersistence.d.ts → keyingCheckpoints/documentPurgeCheckpointPersistence.d.ts} +2 -2
  156. package/data/persistence/{documentPurgeCheckpointPersistence.js → keyingCheckpoints/documentPurgeCheckpointPersistence.js} +4 -4
  157. package/data/persistence/keyingCheckpoints/documentPurgeCheckpointPersistence.js.map +1 -0
  158. package/data/persistence/{keyingCheckpointAdvancePersistence.js → keyingCheckpoints/keyingCheckpointAdvancePersistence.js} +9 -9
  159. package/data/persistence/keyingCheckpoints/keyingCheckpointAdvancePersistence.js.map +1 -0
  160. package/data/persistence/{keyingCheckpointEvidence.js → keyingCheckpoints/keyingCheckpointEvidence.js} +1 -1
  161. package/data/persistence/{keyingCheckpointPersistence.js → keyingCheckpoints/keyingCheckpointPersistence.js} +5 -5
  162. package/data/persistence/keyingCheckpoints/keyingCheckpointPersistence.js.map +1 -0
  163. package/data/persistence/{locallyAcknowledgedCheckpointPersistence.d.ts → keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.d.ts} +4 -4
  164. package/data/persistence/{locallyAcknowledgedCheckpointPersistence.js → keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js} +7 -7
  165. package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js.map +1 -0
  166. package/data/persistence/{organizationReplacementCheckpointPersistence.js → keyingCheckpoints/organizationReplacementCheckpointPersistence.js} +6 -6
  167. package/data/persistence/keyingCheckpoints/organizationReplacementCheckpointPersistence.js.map +1 -0
  168. package/data/persistence/{principalAuthorizationCheckpoints.js → keyingCheckpoints/principalAuthorizationCheckpoints.js} +1 -1
  169. package/data/persistence/keyingCheckpoints/principalAuthorizationCheckpoints.js.map +1 -0
  170. package/data/persistence/organizationFounderPersistence.js +2 -2
  171. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  172. package/data/persistence/organizations/organizationAccessRevocationPersistence.js +3 -3
  173. package/data/persistence/organizations/organizationAccessRevocationPersistence.js.map +1 -1
  174. package/data/persistence/organizations/organizationDataUsagePersistence.js +2 -2
  175. package/data/persistence/organizations/organizationDataUsagePersistence.js.map +1 -1
  176. package/data/persistence/organizations/organizationGroupNamePersistence.js +2 -2
  177. package/data/persistence/organizations/organizationGroupNamePersistence.js.map +1 -1
  178. package/data/persistence/organizations/organizationPresentationDenialPersistence.js +2 -2
  179. package/data/persistence/organizations/organizationPresentationDenialPersistence.js.map +1 -1
  180. package/data/persistence/organizations/organizationProfileDocumentPointers.js +2 -2
  181. package/data/persistence/organizations/organizationProfileDocumentPointers.js.map +1 -1
  182. package/data/persistence/organizations/organizationProvisioningAttemptPersistence.js +1 -1
  183. package/data/persistence/organizations/organizationProvisioningAttemptPersistence.js.map +1 -1
  184. package/data/persistence/organizations/organizationReadModelGrantPersistence.js +1 -1
  185. package/data/persistence/organizations/organizationReadModelGrantPersistence.js.map +1 -1
  186. package/data/persistence/organizations/organizationReadModelMemberLoad.js +1 -1
  187. package/data/persistence/organizations/organizationReadModelMemberLoad.js.map +1 -1
  188. package/data/persistence/organizations/organizationReadModelMembershipPersistence.js +1 -1
  189. package/data/persistence/organizations/organizationReadModelMembershipPersistence.js.map +1 -1
  190. package/data/persistence/organizations/organizationReadModelPersistence.js +3 -3
  191. package/data/persistence/organizations/organizationReadModelPersistence.js.map +1 -1
  192. package/data/persistence/organizations/organizationReadModelProjection.js +1 -1
  193. package/data/persistence/organizations/organizationReadModelProjection.js.map +1 -1
  194. package/data/persistence/organizations/organizationReadModelPurge.js +3 -3
  195. package/data/persistence/organizations/organizationReadModelPurge.js.map +1 -1
  196. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +3 -3
  197. package/data/persistence/principalCurrentAcknowledgementPersistence.js +10 -10
  198. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
  199. package/data/persistence/{principalHistoryEvidencePersistence.d.ts → principalHistory/principalHistoryEvidencePersistence.d.ts} +4 -4
  200. package/data/persistence/{principalHistoryEvidencePersistence.js → principalHistory/principalHistoryEvidencePersistence.js} +7 -7
  201. package/data/persistence/principalHistory/principalHistoryEvidencePersistence.js.map +1 -0
  202. package/data/persistence/{principalHistoryIncompleteRetention.js → principalHistory/principalHistoryIncompleteRetention.js} +1 -1
  203. package/data/persistence/principalHistory/principalHistoryIncompleteRetention.js.map +1 -0
  204. package/data/persistence/{principalHistoryNodeRetention.js → principalHistory/principalHistoryNodeRetention.js} +4 -4
  205. package/data/persistence/principalHistory/principalHistoryNodeRetention.js.map +1 -0
  206. package/data/persistence/{principalHistoryPrefixPersistence.d.ts → principalHistory/principalHistoryPrefixPersistence.d.ts} +2 -2
  207. package/data/persistence/{principalHistoryPrefixPersistence.js → principalHistory/principalHistoryPrefixPersistence.js} +6 -6
  208. package/data/persistence/principalHistory/principalHistoryPrefixPersistence.js.map +1 -0
  209. package/data/persistence/{principalHistoryRootOwnership.js → principalHistory/principalHistoryRootOwnership.js} +1 -1
  210. package/data/persistence/principalHistory/principalHistoryRootOwnership.js.map +1 -0
  211. package/data/persistence/{principalHistoryStagePersistence.d.ts → principalHistory/principalHistoryStagePersistence.d.ts} +2 -2
  212. package/data/persistence/{principalHistoryStagePersistence.js → principalHistory/principalHistoryStagePersistence.js} +6 -6
  213. package/data/persistence/principalHistory/principalHistoryStagePersistence.js.map +1 -0
  214. package/data/persistence/{principalHistoryStageRetention.js → principalHistory/principalHistoryStageRetention.js} +2 -2
  215. package/data/persistence/principalHistory/principalHistoryStageRetention.js.map +1 -0
  216. package/data/persistence/{principalHistoryUnpublishedRetention.js → principalHistory/principalHistoryUnpublishedRetention.js} +3 -3
  217. package/data/persistence/principalHistory/principalHistoryUnpublishedRetention.js.map +1 -0
  218. package/data/persistence/{principalGrantRetirementPersistence.d.ts → principalKeys/principalGrantRetirementPersistence.d.ts} +2 -2
  219. package/data/persistence/{principalGrantRetirementPersistence.js → principalKeys/principalGrantRetirementPersistence.js} +2 -2
  220. package/data/persistence/principalKeys/principalGrantRetirementPersistence.js.map +1 -0
  221. package/data/persistence/{principalKeyEnvelopeArchivePersistence.js → principalKeys/principalKeyEnvelopeArchivePersistence.js} +3 -3
  222. package/data/persistence/principalKeys/principalKeyEnvelopeArchivePersistence.js.map +1 -0
  223. package/data/persistence/{principalKeyEnvelopeCandidates.js → principalKeys/principalKeyEnvelopeCandidates.js} +9 -9
  224. package/data/persistence/principalKeys/principalKeyEnvelopeCandidates.js.map +1 -0
  225. package/data/persistence/principalMutationJournalPersistence.d.ts +1 -1
  226. package/data/persistence/principalMutationJournalPersistence.js +1 -1
  227. package/data/persistence/principalMutationJournalPersistence.js.map +1 -1
  228. package/data/persistence/{principalPolicyBundleIntegrity.js → principalPolicy/principalPolicyBundleIntegrity.js} +3 -3
  229. package/data/persistence/principalPolicy/principalPolicyBundleIntegrity.js.map +1 -0
  230. package/data/persistence/{principalPolicyCheckpointSelection.js → principalPolicy/principalPolicyCheckpointSelection.js} +2 -2
  231. package/data/persistence/principalPolicy/principalPolicyCheckpointSelection.js.map +1 -0
  232. package/data/persistence/{principalPolicyOrganizationPersistence.js → principalPolicy/principalPolicyOrganizationPersistence.js} +2 -2
  233. package/data/persistence/principalPolicy/principalPolicyOrganizationPersistence.js.map +1 -0
  234. package/data/persistence/{principalPolicyPersistence.js → principalPolicy/principalPolicyPersistence.js} +5 -5
  235. package/data/persistence/principalPolicy/principalPolicyPersistence.js.map +1 -0
  236. package/data/persistence/{principalPolicyReferenceCheckpoint.js → principalPolicy/principalPolicyReferenceCheckpoint.js} +3 -3
  237. package/data/persistence/principalPolicy/principalPolicyReferenceCheckpoint.js.map +1 -0
  238. package/data/persistence/{principalPolicyReferenceIndexPersistence.js → principalPolicy/principalPolicyReferenceIndexPersistence.js} +4 -4
  239. package/data/persistence/principalPolicy/principalPolicyReferenceIndexPersistence.js.map +1 -0
  240. package/data/persistence/{principalPolicyReferencePersistence.js → principalPolicy/principalPolicyReferencePersistence.js} +5 -5
  241. package/data/persistence/principalPolicy/principalPolicyReferencePersistence.js.map +1 -0
  242. package/data/persistence/{verifiedPrincipalPolicyBundle.js → principalPolicy/verifiedPrincipalPolicyBundle.js} +2 -2
  243. package/data/persistence/principalPolicy/verifiedPrincipalPolicyBundle.js.map +1 -0
  244. package/data/persistence/{verifiedPrincipalPolicyCurrent.js → principalPolicy/verifiedPrincipalPolicyCurrent.js} +2 -2
  245. package/data/persistence/principalPolicy/verifiedPrincipalPolicyCurrent.js.map +1 -0
  246. package/data/persistence/{verifiedPrincipalPolicyRetentionPersistence.js → principalPolicy/verifiedPrincipalPolicyRetentionPersistence.js} +1 -1
  247. package/data/persistence/principalPolicy/verifiedPrincipalPolicyRetentionPersistence.js.map +1 -0
  248. package/data/persistence/securityIncidentPersistence.js +1 -1
  249. package/data/persistence/securityIncidentPersistence.js.map +1 -1
  250. package/data/persistence/trustedUserIdentityPinPersistence.js +1 -1
  251. package/data/persistence/verifiedManifestBundlePersistence.d.ts +1 -1
  252. package/data/persistence/verifiedManifestBundlePersistence.js +4 -4
  253. package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
  254. package/data/principals/organizationGroupRoles.js +2 -2
  255. package/data/principals/organizationGroupRoles.js.map +1 -1
  256. package/data/principals/principalHistoryPrefixProtection.js.map +1 -1
  257. package/data/principals/principalHistoryStageProtection.js.map +1 -1
  258. package/data/principals/principalPolicyCrypto.js +1 -1
  259. package/data/principals/principalPolicyCrypto.js.map +1 -1
  260. package/data/sqlite/{documentHistoryPersistence.d.ts → documentPersistence/documentHistoryPersistence.d.ts} +1 -1
  261. package/data/sqlite/{documentHistoryPersistence.js → documentPersistence/documentHistoryPersistence.js} +5 -5
  262. package/data/sqlite/documentPersistence/documentHistoryPersistence.js.map +1 -0
  263. package/data/sqlite/{documentOrphanBlobReclaims.js → documentPersistence/documentOrphanBlobReclaims.js} +1 -1
  264. package/data/sqlite/documentPersistence/documentOrphanBlobReclaims.js.map +1 -0
  265. package/data/sqlite/{documentPendingUpdatePersistence.d.ts → documentPersistence/documentPendingUpdatePersistence.d.ts} +2 -2
  266. package/data/sqlite/{documentPendingUpdatePersistence.js → documentPersistence/documentPendingUpdatePersistence.js} +2 -2
  267. package/data/sqlite/documentPersistence/documentPendingUpdatePersistence.js.map +1 -0
  268. package/data/sqlite/{documentPersistenceTypes.d.ts → documentPersistence/documentPersistenceTypes.d.ts} +2 -2
  269. package/data/sqlite/documentPersistence/documentPersistenceTypes.js.map +1 -0
  270. package/data/sqlite/{documentRecordPersistence.d.ts → documentPersistence/documentRecordPersistence.d.ts} +1 -1
  271. package/data/sqlite/{documentRecordPersistence.js → documentPersistence/documentRecordPersistence.js} +4 -4
  272. package/data/sqlite/documentPersistence/documentRecordPersistence.js.map +1 -0
  273. package/data/sqlite/{documentSyncFailurePersistence.d.ts → documentPersistence/documentSyncFailurePersistence.d.ts} +2 -2
  274. package/data/sqlite/{documentSyncFailurePersistence.js → documentPersistence/documentSyncFailurePersistence.js} +3 -3
  275. package/data/sqlite/documentPersistence/documentSyncFailurePersistence.js.map +1 -0
  276. package/data/sqlite/{documentPersistence.d.ts → documentPersistence/index.d.ts} +2 -2
  277. package/data/sqlite/{documentPersistence.js → documentPersistence/index.js} +5 -5
  278. package/data/sqlite/documentPersistence/index.js.map +1 -0
  279. package/data/sqlite/{containerSchema.d.ts → schema/containerSchema.d.ts} +1 -1
  280. package/data/sqlite/{containerSchema.js → schema/containerSchema.js} +1 -1
  281. package/data/sqlite/schema/containerSchema.js.map +1 -0
  282. package/data/sqlite/{schema.d.ts → schema/index.d.ts} +1 -1
  283. package/data/sqlite/{schema.js → schema/index.js} +3 -3
  284. package/data/sqlite/schema/index.js.map +1 -0
  285. package/data/sqlite/{organizationDataUsageSchema.js → schema/organizationDataUsageSchema.js} +1 -1
  286. package/data/sqlite/schema/organizationDataUsageSchema.js.map +1 -0
  287. package/data/sqlite/{organizationProvisioningAttemptSchema.js → schema/organizationProvisioningAttemptSchema.js} +1 -1
  288. package/data/sqlite/schema/organizationProvisioningAttemptSchema.js.map +1 -0
  289. package/data/sqlite/{organizationReadModelTableRegistry.d.ts → schema/organizationReadModelTableRegistry.d.ts} +1 -1
  290. package/data/sqlite/{organizationReadModelTableRegistry.js → schema/organizationReadModelTableRegistry.js} +1 -1
  291. package/data/sqlite/schema/organizationReadModelTableRegistry.js.map +1 -0
  292. package/data/sqlite/{principalHistoryEvidenceSchema.d.ts → schema/principalHistoryEvidenceSchema.d.ts} +1 -1
  293. package/data/sqlite/{principalHistoryEvidenceSchema.js → schema/principalHistoryEvidenceSchema.js} +2 -2
  294. package/data/sqlite/schema/principalHistoryEvidenceSchema.js.map +1 -0
  295. package/data/sqlite/{principalHistoryNodeRetentionSchema.js → schema/principalHistoryNodeRetentionSchema.js} +1 -1
  296. package/data/sqlite/schema/principalHistoryNodeRetentionSchema.js.map +1 -0
  297. package/data/sqlite/{principalHistoryRetentionSchema.js → schema/principalHistoryRetentionSchema.js} +1 -1
  298. package/data/sqlite/{principalHistoryRetentionSchema.js.map → schema/principalHistoryRetentionSchema.js.map} +1 -1
  299. package/data/sqlite/{principalHistoryStageSchema.d.ts → schema/principalHistoryStageSchema.d.ts} +1 -1
  300. package/data/sqlite/{principalHistoryStageSchema.js → schema/principalHistoryStageSchema.js} +2 -2
  301. package/data/sqlite/schema/principalHistoryStageSchema.js.map +1 -0
  302. package/data/sqlite/{principalMutationJournalSchema.d.ts → schema/principalMutationJournalSchema.d.ts} +1 -1
  303. package/data/sqlite/{principalMutationJournalSchema.js → schema/principalMutationJournalSchema.js} +1 -1
  304. package/data/sqlite/{principalMutationJournalSchema.js.map → schema/principalMutationJournalSchema.js.map} +1 -1
  305. package/data/sqlite/{principalPolicySchema.js → schema/principalPolicySchema.js} +1 -1
  306. package/data/sqlite/schema/principalPolicySchema.js.map +1 -0
  307. package/data/sqlite/{securityIncidentSchema.d.ts → schema/securityIncidentSchema.d.ts} +1 -1
  308. package/data/sqlite/{securityIncidentSchema.js → schema/securityIncidentSchema.js} +1 -1
  309. package/data/sqlite/schema/securityIncidentSchema.js.map +1 -0
  310. package/data/sqlite/{verifiedManifestBundleSchema.d.ts → schema/verifiedManifestBundleSchema.d.ts} +1 -1
  311. package/data/sqlite/{verifiedManifestBundleSchema.js → schema/verifiedManifestBundleSchema.js} +1 -1
  312. package/data/sqlite/schema/verifiedManifestBundleSchema.js.map +1 -0
  313. package/data/sqlite/sqlitePersistenceRuntime.d.ts +1 -1
  314. package/data/sqlite/sqlitePersistenceRuntime.js +1 -1
  315. package/index.d.ts +1 -1
  316. package/index.js.map +1 -1
  317. package/package.json +1 -1
  318. package/sqlite/index.d.ts +1 -1
  319. package/sqlite/index.js +1 -1
  320. package/stores/container-contents/containerContentsStore.js +3 -2
  321. package/stores/container-contents/containerContentsStore.js.map +1 -1
  322. package/stores/container-contents/index.d.ts +1 -1
  323. package/stores/container-contents/index.js.map +1 -1
  324. package/stores/container-contents/operations/purgeMoveSettlementOperation.js +71 -0
  325. package/stores/container-contents/operations/purgeMoveSettlementOperation.js.map +1 -0
  326. package/stores/documents/documentStore/history/historyRebuild.js +1 -1
  327. package/stores/documents/documentStore/history/historyRebuild.js.map +1 -1
  328. package/stores/documents/documentStore/state.js.map +1 -1
  329. package/stores/documents/documentStore/sync/syncFinalize.js +1 -1
  330. package/stores/documents/documentStore/sync/syncFinalize.js.map +1 -1
  331. package/stores/documents/documentStore/sync/syncUpdateImport.js +1 -1
  332. package/stores/documents/documentStore/sync/syncUpdateImport.js.map +1 -1
  333. package/workflows/blobs/detach.js +1 -1
  334. package/workflows/blobs/hydration/decrypt.js +1 -1
  335. package/workflows/blobs/upload/index.js +1 -1
  336. package/workflows/blobs/verification/retainedAttachmentVerification.js +1 -1
  337. package/workflows/blobs/verification/writerProjection.js +1 -1
  338. package/workflows/container-contents/container-state/create/createWithMetadata.js +2 -2
  339. package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -1
  340. package/workflows/container-contents/container-state/moveIntentSync.js +43 -5
  341. package/workflows/container-contents/container-state/moveIntentSync.js.map +1 -1
  342. package/workflows/container-contents/container-state/purge/purgeMoveSettlement.js +119 -0
  343. package/workflows/container-contents/container-state/purge/purgeMoveSettlement.js.map +1 -0
  344. package/workflows/container-contents/container-state/purge/purgeProgress.d.ts +8 -0
  345. package/workflows/container-contents/container-state/purge/purgeProgress.js.map +1 -1
  346. package/workflows/container-contents/container-state/remote.js +1 -0
  347. package/workflows/container-contents/container-state/remote.js.map +1 -1
  348. package/workflows/container-contents/container-state/share/index.js +1 -1
  349. package/workflows/container-contents/documentLinks/index.js +1 -1
  350. package/workflows/container-contents/documentMove/documentMoveVanishedRefresh.js +1 -1
  351. package/workflows/container-contents/documentPriming/documentHydrationProbe.js +1 -1
  352. package/workflows/container-contents/documentPriming/index.js +1 -1
  353. package/workflows/container-contents/documentQueries/index.js +1 -1
  354. package/workflows/container-contents/documentQueries/sql.js +1 -1
  355. package/workflows/container-contents/info/blobInfo.js +1 -1
  356. package/workflows/container-contents/info/containerInfo.js +1 -1
  357. package/workflows/container-contents/info/documentInfo.js +1 -1
  358. package/workflows/container-contents/metadata/index.js +1 -1
  359. package/workflows/container-contents/metadata/index.js.map +1 -1
  360. package/workflows/container-contents/metadata/metadataEvents.d.ts +1 -1
  361. package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js +2 -2
  362. package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js.map +1 -1
  363. package/workflows/container-contents/metadata/metadataMutationPreparation.js +1 -1
  364. package/workflows/container-contents/metadata/metadataMutationPreparation.js.map +1 -1
  365. package/workflows/container-contents/metadata/metadataPullContinuationInvalidation.js +1 -1
  366. package/workflows/container-contents/metadata/metadataPullContinuationInvalidation.js.map +1 -1
  367. package/workflows/container-contents/metadata/metadataRemoteSync.d.ts +1 -1
  368. package/workflows/container-contents/metadata/metadataSyncErrors.js +1 -1
  369. package/workflows/container-contents/metadata/metadataSyncErrors.js.map +1 -1
  370. package/workflows/container-contents/metadata/metadataSyncSettlement.d.ts +1 -1
  371. package/workflows/container-contents/metadata/metadataSyncSettlement.js.map +1 -1
  372. package/workflows/container-contents/metadata/metadataTypes.d.ts +1 -1
  373. package/workflows/container-contents/metadata/metadataTypes.js.map +1 -1
  374. package/workflows/container-contents/pendingWrites/index.js +2 -2
  375. package/workflows/container-contents/pendingWrites/sources.js +1 -1
  376. package/workflows/container-contents/remoteHydration/destination/replacementBinding.js +1 -1
  377. package/workflows/container-contents/remoteHydration/destination/replacementBinding.js.map +1 -1
  378. package/workflows/container-contents/remoteHydration/reattachMetadata.js.map +1 -1
  379. package/workflows/container-contents/syncLane.d.ts +2 -0
  380. package/workflows/container-contents/syncLane.js +7 -0
  381. package/workflows/container-contents/syncLane.js.map +1 -1
  382. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js +2 -2
  383. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -1
  384. package/workflows/containers/child/create/index.js +2 -2
  385. package/workflows/containers/child/create/index.js.map +1 -1
  386. package/workflows/containers/child/move/index.d.ts +1 -0
  387. package/workflows/containers/child/move/index.js +2 -1
  388. package/workflows/containers/child/move/index.js.map +1 -1
  389. package/workflows/containers/child/move/moveRotation.js +1 -1
  390. package/workflows/containers/child/move/moveRotation.js.map +1 -1
  391. package/workflows/containers/child/move/moveWraps.js +1 -1
  392. package/workflows/containers/child/move/moveWraps.js.map +1 -1
  393. package/workflows/containers/child/mutationSubmit.js +3 -1
  394. package/workflows/containers/child/mutationSubmit.js.map +1 -1
  395. package/workflows/containers/child/recite.js +2 -2
  396. package/workflows/containers/child/recite.js.map +1 -1
  397. package/workflows/containers/child/rotation/rotationContext.js +3 -3
  398. package/workflows/containers/child/rotation/rotationContext.js.map +1 -1
  399. package/workflows/containers/child/share/currentSharePrincipalPolicy.js +1 -1
  400. package/workflows/containers/child/share/currentSharePrincipalPolicy.js.map +1 -1
  401. package/workflows/containers/child/share/index.js +1 -1
  402. package/workflows/containers/child/share/index.js.map +1 -1
  403. package/workflows/containers/child/share/shareAncestorRepair.js +2 -2
  404. package/workflows/containers/child/share/shareAncestorRepair.js.map +1 -1
  405. package/workflows/containers/child/share/shareMaterialization.js +1 -1
  406. package/workflows/containers/child/share/sharePrincipalPolicy.js +5 -5
  407. package/workflows/containers/child/share/sharePrincipalPolicy.js.map +1 -1
  408. package/workflows/containers/index.d.ts +3 -3
  409. package/workflows/containers/index.js +2 -2
  410. package/workflows/containers/index.js.map +1 -1
  411. package/workflows/containers/writeRefusal.js +1 -1
  412. package/workflows/containers/writeRefusal.js.map +1 -1
  413. package/workflows/documents/create/createAdoption.js +1 -1
  414. package/workflows/documents/create/createResponse.js +2 -2
  415. package/workflows/documents/create/createResponse.js.map +1 -1
  416. package/workflows/documents/create/index.js +1 -1
  417. package/workflows/documents/documentMutationCommit.d.ts +1 -1
  418. package/workflows/documents/documentMutationPreparation.d.ts +1 -1
  419. package/workflows/documents/documentMutationPreparation.js +1 -1
  420. package/workflows/documents/documentMutationPreparation.js.map +1 -1
  421. package/workflows/documents/index.d.ts +5 -5
  422. package/workflows/documents/index.js +5 -5
  423. package/workflows/documents/index.js.map +1 -1
  424. package/workflows/documents/linkSet/index.js +2 -2
  425. package/workflows/documents/linkSet/index.js.map +1 -1
  426. package/workflows/documents/linkSet/linkSetAuthority.js +1 -1
  427. package/workflows/documents/linkSet/linkSetBlobRewraps.js +1 -1
  428. package/workflows/documents/linkSet/linkSetProjectionSeed.js +1 -1
  429. package/workflows/documents/linkSet/linkSetRemote.js +1 -1
  430. package/workflows/documents/linkSet/linkSetRemote.js.map +1 -1
  431. package/workflows/documents/purge/index.js +1 -1
  432. package/workflows/documents/sync/index.js +2 -2
  433. package/workflows/documents/sync/index.js.map +1 -1
  434. package/workflows/documents/sync/initialSync.js +1 -1
  435. package/workflows/documents/sync/readOnlyProjectionFailure.js +1 -1
  436. package/workflows/documents/sync/readOnlyProjectionFailure.js.map +1 -1
  437. package/workflows/documents/sync/readOnlySync.d.ts +3 -3
  438. package/workflows/documents/sync/readOnlySync.js +1 -1
  439. package/workflows/documents/sync/readOnlySync.js.map +1 -1
  440. package/workflows/documents/sync/reportDocumentSyncQuarantine.js.map +1 -1
  441. package/workflows/documents/sync/syncAttemptPlanning.js +2 -2
  442. package/workflows/documents/sync/syncAttemptPlanning.js.map +1 -1
  443. package/workflows/documents/sync/syncAttemptState.d.ts +2 -2
  444. package/workflows/documents/sync/syncAttemptState.js.map +1 -1
  445. package/workflows/documents/sync/syncResponseResult.js +2 -2
  446. package/workflows/documents/sync/syncResponseResult.js.map +1 -1
  447. package/workflows/documents/syncFailures/index.js +1 -1
  448. package/workflows/documents/syncFailures/index.js.map +1 -1
  449. package/workflows/documents/syncFailures/syncAbandon.js.map +1 -1
  450. package/workflows/documents/syncFailures/syncFailureClassification.js +1 -1
  451. package/workflows/documents/syncFailures/syncFailureClassification.js.map +1 -1
  452. package/workflows/documents/syncPlan/syncContentKeys.d.ts +1 -1
  453. package/workflows/documents/syncPlan/syncContentKeys.js +3 -3
  454. package/workflows/documents/syncPlan/syncContentKeys.js.map +1 -1
  455. package/workflows/documents/syncPlan/syncPlanMaterial.js +2 -2
  456. package/workflows/documents/syncPlan/syncPlanMaterial.js.map +1 -1
  457. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js +2 -2
  458. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -1
  459. package/workflows/documents/syncRekeys/syncContainerRekeyPreparation.js +1 -1
  460. package/workflows/documents/syncRekeys/syncRecoveryRekey.d.ts +1 -1
  461. package/workflows/documents/syncRekeys/syncRecoveryRekey.js +1 -1
  462. package/workflows/organizations/currentOrganizationAuthority.js +2 -2
  463. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -1
  464. package/workflows/organizations/groupMetadata/groupMetadataAccess.js +1 -1
  465. package/workflows/organizations/groupMetadata/groupMetadataAccess.js.map +1 -1
  466. package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js +1 -1
  467. package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js.map +1 -1
  468. package/workflows/organizations/groupNames/currentOrganizationGroupNames.js +1 -1
  469. package/workflows/organizations/groupNames/currentOrganizationGroupNames.js.map +1 -1
  470. package/workflows/organizations/groupNames/groupNameUniqueness.js +3 -3
  471. package/workflows/organizations/groupNames/groupNameUniqueness.js.map +1 -1
  472. package/workflows/organizations/groupNames/organizationGroupNamePolicies.js +2 -2
  473. package/workflows/organizations/groupNames/organizationGroupNamePolicies.js.map +1 -1
  474. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js +1 -1
  475. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -1
  476. package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js +2 -2
  477. package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js.map +1 -1
  478. package/workflows/organizations/groupPolicy/groupPolicyMutationEvidence.js +1 -1
  479. package/workflows/organizations/groupPolicy/groupPolicyMutationEvidence.js.map +1 -1
  480. package/workflows/organizations/groupPolicy/groupPolicyVerification.js +1 -1
  481. package/workflows/organizations/groupPolicy/groupPolicyVerification.js.map +1 -1
  482. package/workflows/organizations/groups/createCurrentOrganizationGroup.js +1 -1
  483. package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
  484. package/workflows/organizations/groups/deleteOrganizationGroup.js +1 -1
  485. package/workflows/organizations/groups/deleteOrganizationGroup.js.map +1 -1
  486. package/workflows/organizations/groups/organizationGroupDirectory.js +1 -1
  487. package/workflows/organizations/groups/organizationGroupDirectory.js.map +1 -1
  488. package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js +1 -1
  489. package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js.map +1 -1
  490. package/workflows/organizations/provisioning/organizationReplacementVerification.js +1 -1
  491. package/workflows/organizations/provisioning/organizationReplacementVerification.js.map +1 -1
  492. package/workflows/organizations/readModel/listLocalOrganizations.js +1 -1
  493. package/workflows/organizations/readModel/localReadModelDetails.js +1 -1
  494. package/workflows/organizations/readModel/localReadModelDetails.js.map +1 -1
  495. package/workflows/principals/acknowledgements/acknowledgedPrincipalCurrents.js +1 -1
  496. package/workflows/principals/acknowledgements/acknowledgedPrincipalCurrents.js.map +1 -1
  497. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.d.ts +1 -1
  498. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js +1 -1
  499. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js.map +1 -1
  500. package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js +1 -1
  501. package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js.map +1 -1
  502. package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js +2 -2
  503. package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js.map +1 -1
  504. package/workflows/principals/externalAdminPolicy.js +2 -2
  505. package/workflows/principals/externalAdminPolicy.js.map +1 -1
  506. package/workflows/principals/historyRecovery/loadRecoveredPrincipalHistoryPage.js +2 -2
  507. package/workflows/principals/historyRecovery/loadRecoveredPrincipalHistoryPage.js.map +1 -1
  508. package/workflows/principals/historyRecovery/principalHistoryRecoveryPrefix.js +1 -1
  509. package/workflows/principals/historyRecovery/principalHistoryRecoveryPrefix.js.map +1 -1
  510. package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js +1 -1
  511. package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js.map +1 -1
  512. package/workflows/principals/historyRecovery/principalHistoryRecoveryStage.js +1 -1
  513. package/workflows/principals/historyRecovery/principalHistoryRecoveryStage.js.map +1 -1
  514. package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js +3 -3
  515. package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js.map +1 -1
  516. package/workflows/principals/policyCache/index.js +3 -3
  517. package/workflows/principals/policyCache/index.js.map +1 -1
  518. package/workflows/principals/policyCache/principalPolicyCacheAdvance.js +1 -1
  519. package/workflows/principals/policyCache/principalPolicyCacheAdvance.js.map +1 -1
  520. package/workflows/principals/policyCache/principalPolicyOrganizationScope.js +3 -3
  521. package/workflows/principals/policyCache/principalPolicyOrganizationScope.js.map +1 -1
  522. package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js.map +1 -1
  523. package/workflows/principals/publicHistory/publicPrincipalHistoryPage.js +2 -2
  524. package/workflows/principals/publicHistory/publicPrincipalHistoryPage.js.map +1 -1
  525. package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js +3 -3
  526. package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js.map +1 -1
  527. package/workflows/principals/publicHistory/publicPrincipalHistoryTypes.d.ts +2 -2
  528. package/workflows/principals/publicHistory/publicPrincipalHistoryTypes.js.map +1 -1
  529. package/workflows/principals/publicHistory/publicProjectionPrincipal.js +1 -1
  530. package/workflows/principals/publicHistory/publicProjectionPrincipal.js.map +1 -1
  531. package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js +1 -1
  532. package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js.map +1 -1
  533. package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js +1 -1
  534. package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js.map +1 -1
  535. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js +1 -1
  536. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js.map +1 -1
  537. package/workflows/principals/recoveryOperation/principalRecoveryMemoValidity.js +1 -1
  538. package/workflows/principals/recoveryOperation/principalRecoveryMemoValidity.js.map +1 -1
  539. package/workflows/registration/persistRegistrationBootstrap.d.ts +2 -2
  540. package/workflows/registration/persistRegistrationBootstrap.js +2 -2
  541. package/workflows/registration/persistRegistrationBootstrap.js.map +1 -1
  542. package/workflows/registration/provisioningAcknowledgement.js +1 -1
  543. package/workflows/registration/provisioningAcknowledgement.js.map +1 -1
  544. package/workflows/registration/registrationPrincipalPolicyPersistence.js +1 -1
  545. package/workflows/registration/registrationPrincipalPolicyPersistence.js.map +1 -1
  546. package/workflows/sync/remoteReset.js +7 -7
  547. package/workflows/sync/remoteReset.js.map +1 -1
  548. package/workflows/sync/remoteResetAttachments.js +1 -1
  549. package/workflows/sync/remoteResetCursorScope.js +1 -1
  550. package/workflows/sync/remoteResetPlans.js +1 -1
  551. package/workflows/sync/remoteResetPrincipalScope.js +5 -5
  552. package/workflows/sync/remoteResetPrincipalScope.js.map +1 -1
  553. package/workflows/sync/remoteResetScope.js +1 -1
  554. package/data/documents/shared/containerKekPath.js.map +0 -1
  555. package/data/documents/shared/containerKekPathHistory.js.map +0 -1
  556. package/data/documents/shared/containerKekPathVerification.js.map +0 -1
  557. package/data/documents/shared/containerKekWrapping.js.map +0 -1
  558. package/data/documents/shared/documentSyncUpdateDecryption.js.map +0 -1
  559. package/data/documents/shared/documentSyncUpdateIsolation.js.map +0 -1
  560. package/data/documents/shared/keyringRebuild.js.map +0 -1
  561. package/data/documents/shared/mutationAcknowledgement.js.map +0 -1
  562. package/data/documents/shared/projection.js.map +0 -1
  563. package/data/documents/shared/projectionContentKeys.js.map +0 -1
  564. package/data/documents/shared/projectionTargets.js.map +0 -1
  565. package/data/documents/shared/syncPagination.js.map +0 -1
  566. package/data/documents/shared/syncResponseAuthorization.js.map +0 -1
  567. package/data/documents/shared/syncResponses.js.map +0 -1
  568. package/data/persistence/documentPurgeCheckpointPersistence.js.map +0 -1
  569. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +0 -1
  570. package/data/persistence/keyingCheckpointPersistence.js.map +0 -1
  571. package/data/persistence/locallyAcknowledgedCheckpointPersistence.js.map +0 -1
  572. package/data/persistence/organizationReplacementCheckpointPersistence.js.map +0 -1
  573. package/data/persistence/principalAuthorizationCheckpoints.js.map +0 -1
  574. package/data/persistence/principalGrantRetirementPersistence.js.map +0 -1
  575. package/data/persistence/principalHistoryEvidencePersistence.js.map +0 -1
  576. package/data/persistence/principalHistoryIncompleteRetention.js.map +0 -1
  577. package/data/persistence/principalHistoryNodeRetention.js.map +0 -1
  578. package/data/persistence/principalHistoryPrefixPersistence.js.map +0 -1
  579. package/data/persistence/principalHistoryRootOwnership.js.map +0 -1
  580. package/data/persistence/principalHistoryStagePersistence.js.map +0 -1
  581. package/data/persistence/principalHistoryStageRetention.js.map +0 -1
  582. package/data/persistence/principalHistoryUnpublishedRetention.js.map +0 -1
  583. package/data/persistence/principalKeyEnvelopeArchivePersistence.js.map +0 -1
  584. package/data/persistence/principalKeyEnvelopeCandidates.js.map +0 -1
  585. package/data/persistence/principalPolicyBundleIntegrity.js.map +0 -1
  586. package/data/persistence/principalPolicyCheckpointSelection.js.map +0 -1
  587. package/data/persistence/principalPolicyOrganizationPersistence.js.map +0 -1
  588. package/data/persistence/principalPolicyPersistence.js.map +0 -1
  589. package/data/persistence/principalPolicyReferenceCheckpoint.js.map +0 -1
  590. package/data/persistence/principalPolicyReferenceIndexPersistence.js.map +0 -1
  591. package/data/persistence/principalPolicyReferencePersistence.js.map +0 -1
  592. package/data/persistence/verifiedPrincipalPolicyBundle.js.map +0 -1
  593. package/data/persistence/verifiedPrincipalPolicyCurrent.js.map +0 -1
  594. package/data/persistence/verifiedPrincipalPolicyRetentionPersistence.js.map +0 -1
  595. package/data/sqlite/containerSchema.js.map +0 -1
  596. package/data/sqlite/documentHistoryPersistence.js.map +0 -1
  597. package/data/sqlite/documentOrphanBlobReclaims.js.map +0 -1
  598. package/data/sqlite/documentPendingUpdatePersistence.js.map +0 -1
  599. package/data/sqlite/documentPersistence.js.map +0 -1
  600. package/data/sqlite/documentPersistenceTypes.js.map +0 -1
  601. package/data/sqlite/documentRecordPersistence.js.map +0 -1
  602. package/data/sqlite/documentSyncFailurePersistence.js.map +0 -1
  603. package/data/sqlite/organizationDataUsageSchema.js.map +0 -1
  604. package/data/sqlite/organizationProvisioningAttemptSchema.js.map +0 -1
  605. package/data/sqlite/organizationReadModelTableRegistry.js.map +0 -1
  606. package/data/sqlite/principalHistoryEvidenceSchema.js.map +0 -1
  607. package/data/sqlite/principalHistoryNodeRetentionSchema.js.map +0 -1
  608. package/data/sqlite/principalHistoryStageSchema.js.map +0 -1
  609. package/data/sqlite/principalPolicySchema.js.map +0 -1
  610. package/data/sqlite/schema.js.map +0 -1
  611. package/data/sqlite/securityIncidentSchema.js.map +0 -1
  612. package/data/sqlite/verifiedManifestBundleSchema.js.map +0 -1
  613. /package/data/documents/shared/{containerKekCurrency.js → containerKek/containerKekCurrency.js} +0 -0
  614. /package/data/documents/shared/{containerKekCurrency.js.map → containerKek/containerKekCurrency.js.map} +0 -0
  615. /package/data/documents/shared/{containerKekEntryVerification.js.map → containerKek/containerKekEntryVerification.js.map} +0 -0
  616. /package/data/documents/shared/{containerKekLogFetch.js.map → containerKek/containerKekLogFetch.js.map} +0 -0
  617. /package/data/documents/shared/{containerKekPath.d.ts → containerKek/containerKekPath.d.ts} +0 -0
  618. /package/data/documents/shared/{keyringLogWalk.js.map → containerKek/keyringLogWalk.js.map} +0 -0
  619. /package/data/documents/shared/{pullContinuation.d.ts → sync/pullContinuation.d.ts} +0 -0
  620. /package/data/documents/shared/{pullContinuation.js.map → sync/pullContinuation.js.map} +0 -0
  621. /package/data/documents/shared/{syncSubmitFailure.js → sync/syncSubmitFailure.js} +0 -0
  622. /package/data/documents/shared/{syncSubmitFailure.js.map → sync/syncSubmitFailure.js.map} +0 -0
  623. /package/data/persistence/{keyingCheckpointEvidence.js.map → keyingCheckpoints/keyingCheckpointEvidence.js.map} +0 -0
  624. /package/data/persistence/{storedPrincipalPolicyBundle.js → principalPolicy/storedPrincipalPolicyBundle.js} +0 -0
  625. /package/data/persistence/{storedPrincipalPolicyBundle.js.map → principalPolicy/storedPrincipalPolicyBundle.js.map} +0 -0
  626. /package/data/sqlite/{documentPersistenceTypes.js → documentPersistence/documentPersistenceTypes.js} +0 -0
  627. /package/data/sqlite/{containerDocumentTombstoneHoldSchema.d.ts → schema/containerDocumentTombstoneHoldSchema.d.ts} +0 -0
  628. /package/data/sqlite/{containerDocumentTombstoneHoldSchema.js → schema/containerDocumentTombstoneHoldSchema.js} +0 -0
  629. /package/data/sqlite/{containerDocumentTombstoneHoldSchema.js.map → schema/containerDocumentTombstoneHoldSchema.js.map} +0 -0
  630. /package/data/sqlite/{documentAttachmentSchema.d.ts → schema/documentAttachmentSchema.d.ts} +0 -0
  631. /package/data/sqlite/{documentAttachmentSchema.js → schema/documentAttachmentSchema.js} +0 -0
  632. /package/data/sqlite/{documentAttachmentSchema.js.map → schema/documentAttachmentSchema.js.map} +0 -0
  633. /package/data/sqlite/{documentDiscoveryEvidenceSchema.js → schema/documentDiscoveryEvidenceSchema.js} +0 -0
  634. /package/data/sqlite/{documentDiscoveryEvidenceSchema.js.map → schema/documentDiscoveryEvidenceSchema.js.map} +0 -0
  635. /package/data/sqlite/{documentPlacementIntentSchema.js → schema/documentPlacementIntentSchema.js} +0 -0
  636. /package/data/sqlite/{documentPlacementIntentSchema.js.map → schema/documentPlacementIntentSchema.js.map} +0 -0
  637. /package/data/sqlite/{localIntentSchema.d.ts → schema/localIntentSchema.d.ts} +0 -0
  638. /package/data/sqlite/{localIntentSchema.js → schema/localIntentSchema.js} +0 -0
  639. /package/data/sqlite/{localIntentSchema.js.map → schema/localIntentSchema.js.map} +0 -0
  640. /package/data/sqlite/{organizationFounderSchema.js → schema/organizationFounderSchema.js} +0 -0
  641. /package/data/sqlite/{organizationFounderSchema.js.map → schema/organizationFounderSchema.js.map} +0 -0
  642. /package/data/sqlite/{organizationReadModelSchema.js → schema/organizationReadModelSchema.js} +0 -0
  643. /package/data/sqlite/{organizationReadModelSchema.js.map → schema/organizationReadModelSchema.js.map} +0 -0
  644. /package/data/sqlite/{principalGrantRetirementSchema.js → schema/principalGrantRetirementSchema.js} +0 -0
  645. /package/data/sqlite/{principalGrantRetirementSchema.js.map → schema/principalGrantRetirementSchema.js.map} +0 -0
  646. /package/data/sqlite/{principalPolicySchema.d.ts → schema/principalPolicySchema.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { signBlobAttachmentDetachEvent } from "../../data/documents/blob/shared/events.js";
2
2
  import { assertBlobAttachmentDetachResponse } from "../../data/documents/blob/shared/responses.js";
3
- import { authorizingContainerPathRefs } from "../../data/documents/shared/projection.js";
3
+ import { authorizingContainerPathRefs } from "../../data/documents/shared/projection/index.js";
4
4
  import { readCanonicalRecord } from "../../data/keying/canonicalJson.js";
5
5
  import { requireProjectionUserKeyResolver } from "../../data/keyingProjectionVerification/index.js";
6
6
  import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
@@ -4,7 +4,7 @@ import { unwrapBlobContentKey } from "../../../data/documents/blob/shared/projec
4
4
  import { parseBlobEncryptedBytes, readBlobKekTarget, readDocumentManifestIdentity, sortBlobTargets, } from "../../../data/documents/blob/shared/readers.js";
5
5
  import { assertBlobContentKeyBundleTargetHash } from "../../../data/documents/blob/shared/responses.js";
6
6
  import { importContentKeyMaterial } from "../../../data/documents/shared/contentRecordKeys.js";
7
- import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection.js";
7
+ import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection/index.js";
8
8
  import { asWebCryptoBytes, readWriteHeader, uniqueSortedStrings, } from "../../../data/documents/shared/readers.js";
9
9
  import { projectionVerificationOptions } from "../../../data/documents/shared/types.js";
10
10
  import { readCanonicalRecord } from "../../../data/keying/canonicalJson.js";
@@ -4,7 +4,7 @@ import { prepareBlobEncryption } from "../../../data/documents/blob/shared/crypt
4
4
  import { signBlobAttachmentEvent, signBlobAttachmentWriteHeader, } from "../../../data/documents/blob/shared/events.js";
5
5
  import { verifiedBlobWrapTargetsFromDocumentProjection, wrapBlobContentKey, } from "../../../data/documents/blob/shared/projection.js";
6
6
  import { assertBlobAttachmentBindResponse } from "../../../data/documents/blob/shared/responses.js";
7
- import { authorizingContainerPathRefs } from "../../../data/documents/shared/projection.js";
7
+ import { authorizingContainerPathRefs } from "../../../data/documents/shared/projection/index.js";
8
8
  import { uniqueSortedStrings } from "../../../data/documents/shared/readers.js";
9
9
  import { projectionVerificationOptions, } from "../../../data/documents/shared/types.js";
10
10
  import { readCanonicalRecord } from "../../../data/keying/canonicalJson.js";
@@ -1,6 +1,6 @@
1
1
  import { KeyingVerificationError } from "../../../internal/crypto/index.js";
2
2
  import { assertBlobContentKeyBundleTargetHash } from "../../../data/documents/blob/shared/responses.js";
3
- import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection.js";
3
+ import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection/index.js";
4
4
  import { projectionVerificationOptions } from "../../../data/documents/shared/types.js";
5
5
  import { requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification/index.js";
6
6
  import { assertAttachmentBindingVerified } from "./attachmentBindingVerification.js";
@@ -1,5 +1,5 @@
1
1
  import { readDocumentManifestIdentity } from "../../../data/documents/blob/shared/readers.js";
2
- import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection.js";
2
+ import { assertDocumentWriterProjectionConsistent } from "../../../data/documents/shared/projection/index.js";
3
3
  import { projectionVerificationOptions, } from "../../../data/documents/shared/types.js";
4
4
  /**
5
5
  * Shared prologue for blob attachment mutations (upload/detach): resolve the
@@ -1,7 +1,7 @@
1
1
  import { isContainerSystemSlot, } from "../../../../internal/validators/containerSystemSlot.js";
2
2
  import { locallyAcknowledgedContainerMutationHead } from "../../../../data/containers/shared/mutationAcknowledgement.js";
3
- import { assertDocumentWriterProjectionConsistent } from "../../../../data/documents/shared/projection.js";
4
- import { advanceLocallyAcknowledgedAccessManifestHeadsAtomically, locallyAuthoredAccessManifestHead, } from "../../../../data/persistence/locallyAcknowledgedCheckpointPersistence.js";
3
+ import { assertDocumentWriterProjectionConsistent } from "../../../../data/documents/shared/projection/index.js";
4
+ import { advanceLocallyAcknowledgedAccessManifestHeadsAtomically, locallyAuthoredAccessManifestHead, } from "../../../../data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js";
5
5
  import { readContainerMutationMetadataDocumentId, } from "../../../containers/index.js";
6
6
  import { repairContainerCreateFailure } from "../../../containers/child/create/createSubmission.js";
7
7
  import { documentWriterProjectionFromCreateResponse, persistedDocumentCreateStateFromResponse, resolveDocumentCreateAuthor, } from "../../../documents/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"createWithMetadata.js","sourceRoot":"","sources":["createWithMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,GACtB,MAAM,2CAA2C,CAAC;AAMnD,OAAO,EAAE,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kBAAkB;QAClB,eAAe;QACf,gBAAgB;QAChB,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,gBAAgB;QAChB,eAAe;QACf,wBAAwB,EAAE,KAAK,CAAC,wBAAwB;QACxD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ContainerAccessManifestState } from \"@tearleads/crypto\";\nimport {\n type ContainerSystemSlot,\n isContainerSystemSlot,\n} from \"@tearleads/validators/containerSystemSlot\";\nimport type { ContainerCreateWithMetadataDocumentRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { locallyAcknowledgedContainerMutationHead } from \"../../../../data/containers/shared/mutationAcknowledgement\";\nimport type { ContainerMutationSubmitFailure } from \"../../../../data/containers/shared/types\";\nimport { assertDocumentWriterProjectionConsistent } from \"../../../../data/documents/shared/projection\";\nimport type { ProjectionUserKeyResolver } from \"../../../../data/keyingProjectionVerification\";\nimport {\n advanceLocallyAcknowledgedAccessManifestHeadsAtomically,\n locallyAuthoredAccessManifestHead,\n} from \"../../../../data/persistence/locallyAcknowledgedCheckpointPersistence\";\nimport type { ExecSql } from \"../../../../data/sqlite/sqlSchema\";\nimport {\n type buildMaterializedContainerCreatePlan,\n readContainerMutationMetadataDocumentId,\n} from \"../../../containers\";\nimport { repairContainerCreateFailure } from \"../../../containers/child/create/createSubmission\";\nimport {\n type buildMaterializedDocumentCreatePlan,\n documentWriterProjectionFromCreateResponse,\n persistedDocumentCreateStateFromResponse,\n resolveDocumentCreateAuthor,\n} from \"../../../documents\";\nimport { PrincipalPolicyRepairBudget } from \"../../../principals/policyRepairBudget\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../../principals/runtimePolicyWarmer\";\nimport type {\n ContainerWorkflowRuntime,\n CreatedRemoteContainerState,\n} from \"../types\";\nimport { settleTerminalCreateFailure } from \"./createTerminalFailure\";\nimport {\n buildContainerWithMetadataPlans,\n type ContainerWithMetadataPlanInput,\n} from \"./createWithMetadataPlan\";\n\n/**\n * Sentinel for a lost-response retry whose manifest already exists remotely.\n * Callers avoid a duplicate; the next parent hydration settles local state.\n */\nexport const CONTAINER_ALREADY_COMMITTED = Symbol(\"containerAlreadyCommitted\");\nexport type ContainerAlreadyCommitted = typeof CONTAINER_ALREADY_COMMITTED;\n\nasync function submitContainerWithMetadataDocument(input: {\n readonly organizationId: string;\n readonly request: ContainerCreateWithMetadataDocumentRequest;\n readonly runtime: ContainerWorkflowRuntime;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<\n | {\n readonly ok: true;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n }\n | ContainerMutationSubmitFailure\n | null\n> {\n if (input.stillCurrent?.() === false) return null;\n const { apiClient } = input.runtime;\n const result = await apiClient.createContainerWithMetadataDocumentResult(\n input.request,\n {\n expectedPaymentRequiredOrganizationId: input.organizationId,\n reportErrors: false,\n },\n );\n return result.ok ? { ok: true, response: result.data } : result;\n}\n\n/**\n * Seed the metadata document's writer projection from the create response so the\n * first read after the container is created (its own metadata sync, contents\n * hydration) resolves locally instead of a cold `GET writer-projection`. The\n * authorizing path is the child container projection the create was authored\n * against — locally built rather than server-fetched, so unlike the plain\n * document-create path this is gated on the projection's internal consistency;\n * on any mismatch the seed is skipped and the next read falls back to a fetch.\n */\nasync function seedMetadataDocumentWriterProjection(input: {\n readonly runtime: ContainerWorkflowRuntime;\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly execSql?: ExecSql | undefined;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<void> {\n const projection = documentWriterProjectionFromCreateResponse({\n containerProjection: input.childProjection,\n response: input.response.metadataDocument,\n });\n try {\n await assertDocumentWriterProjectionConsistent(projection, {\n execSql: input.execSql,\n stillCurrent: input.stillCurrent,\n trustedLocalProjection: true,\n });\n } catch {\n return;\n }\n if (input.stillCurrent?.() === false) return;\n input.runtime.apiClient.primeDocumentWriterProjection(\n input.response.metadataDocument.id,\n projection,\n );\n}\n\nasync function acknowledgeContainerWithMetadata(input: {\n containerPlan: Parameters<\n typeof locallyAcknowledgedContainerMutationHead\n >[0][\"plan\"];\n execSql: ExecSql;\n metadataDocumentPlan: Parameters<\n typeof persistedDocumentCreateStateFromResponse\n >[0];\n response: ContainerCreateWithMetadataDocumentResponse;\n stillCurrent?: (() => boolean) | undefined;\n}) {\n const persistedState = persistedDocumentCreateStateFromResponse(\n input.metadataDocumentPlan,\n input.response.metadataDocument,\n );\n const containerHead = await locallyAcknowledgedContainerMutationHead({\n plan: input.containerPlan,\n response: input.response.container,\n });\n await advanceLocallyAcknowledgedAccessManifestHeadsAtomically({\n execSql: input.execSql,\n heads: [\n containerHead,\n locallyAuthoredAccessManifestHead(input.metadataDocumentPlan),\n ],\n stillCurrent: input.stillCurrent,\n });\n return persistedState;\n}\n\n/**\n * Prime the new container's writer projection from the create plan the client\n * just authored, so the first write under it (a child folder, a document)\n * resolves locally instead of a cold `GET writer-projection`. Only primed when\n * the locally-built projection matches what the server created — the create\n * response echoes the container id and manifest head — so a mismatch skips the\n * seed and the next write falls back to a fetch (same fail-closed contract as\n * the metadata-document seed). Priming is safe for writes: the server still\n * validates every mutation, so a projection that later goes stale (rekey/share/\n * move evict it) just yields a rejected write that retries with a fresh fetch.\n */\nfunction seedChildContainerWriterProjection(input: {\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly runtime: ContainerWorkflowRuntime;\n}): void {\n const createdManifestHash =\n input.response.container.manifestHead.manifestHash;\n const projectedManifestHash = input.childProjection.path.at(-1)?.manifestHash;\n // Both hashes must be present and equal, or two undefined hashes would compare\n // equal and prime an empty/invalid projection.\n if (\n !createdManifestHash ||\n !projectedManifestHash ||\n input.childProjection.containerId !==\n input.response.container.containerId ||\n projectedManifestHash !== createdManifestHash\n ) {\n return;\n }\n\n input.runtime.apiClient.primeContainerWriterProjection(\n input.response.container.containerId,\n input.childProjection,\n );\n}\n\n/**\n * The persisted slot is the one this client signed into the manifest state.\n * The acknowledgement already refused a response that echoed anything else,\n * so the server's column never chooses which local record becomes Trash.\n */\nfunction signedCreateSystemSlot(\n state: ContainerAccessManifestState,\n): ContainerSystemSlot | null {\n if (state.systemSlot === null) return null;\n if (!isContainerSystemSlot(state.systemSlot)) {\n throw new Error(\"Container create plan signed an invalid system slot\");\n }\n return state.systemSlot;\n}\n\nasync function settleContainerWithMetadataCreate(input: {\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly containerPlan: Awaited<\n ReturnType<typeof buildMaterializedContainerCreatePlan>\n >;\n readonly execSql: ExecSql;\n readonly metadataDocumentPlan: Awaited<\n ReturnType<typeof buildMaterializedDocumentCreatePlan>\n >;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly runtime: ContainerWorkflowRuntime;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<{\n readonly ok: true;\n readonly state: CreatedRemoteContainerState;\n} | null> {\n if (\n input.response.container.containerId !==\n input.containerPlan.plan.containerId\n ) {\n throw new Error(\"Container metadata create response container mismatch\");\n }\n // The acknowledgement echoed the signed parent, which a child always names.\n const parentId = input.containerPlan.plan.state.parentContainerId;\n if (parentId === null) {\n throw new Error(\"A container create must commit under a parent\");\n }\n const metadataDocumentId = readContainerMutationMetadataDocumentId({\n response: input.response.container,\n });\n if (\n metadataDocumentId !== input.containerPlan.plan.metadataDocumentId ||\n input.response.metadataDocument.id !==\n input.metadataDocumentPlan.plan.documentId\n ) {\n throw new Error(\"Container metadata create response document mismatch\");\n }\n const persistedMetadataState = await acknowledgeContainerWithMetadata({\n containerPlan: input.containerPlan.plan,\n execSql: input.execSql,\n metadataDocumentPlan: input.metadataDocumentPlan.plan,\n response: input.response,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n await seedMetadataDocumentWriterProjection({\n childProjection: input.childProjection,\n execSql: input.execSql,\n response: input.response,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n seedChildContainerWriterProjection({\n childProjection: input.childProjection,\n response: input.response,\n runtime: input.runtime,\n });\n return {\n ok: true,\n state: {\n accessManifestHash: input.response.container.manifestHead.manifestHash,\n systemSlot: signedCreateSystemSlot(input.containerPlan.plan.state),\n containerId: input.response.container.containerId,\n createdAt: input.response.container.createdAt,\n metadataDocumentId,\n organizationId: input.response.container.organizationId,\n parentId,\n persistedMetadataState,\n updatedAt: input.response.container.updatedAt,\n },\n };\n}\n\nasync function createRemoteContainerWithMetadataDocumentAttempt(\n input: ContainerWithMetadataPlanInput,\n): Promise<\n | {\n readonly ok: true;\n readonly state: CreatedRemoteContainerState;\n }\n | ContainerMutationSubmitFailure\n | null\n> {\n const execSql = input.runtime.infra.execSql;\n const plans = await buildContainerWithMetadataPlans(input);\n if (!plans) return null;\n const { containerPlan, childProjection, metadataDocumentPlan } = plans;\n const submitted = await submitContainerWithMetadataDocument({\n organizationId: containerPlan.plan.state.organizationId,\n request: {\n systemSlot: input.systemSlot ?? null,\n container: containerPlan.plan.request,\n metadataDocument: metadataDocumentPlan.plan.request,\n },\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!submitted?.ok) {\n return submitted;\n }\n return settleContainerWithMetadataCreate({\n childProjection,\n containerPlan,\n execSql,\n metadataDocumentPlan,\n response: submitted.response,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n}\n\nasync function createContainerWithMetadataWithRepairs(\n input: Parameters<\n typeof createRemoteContainerWithMetadataDocumentAttempt\n >[0] & {\n readonly parentContainerId: string;\n },\n): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n const { apiClient } = input.runtime;\n let parentProjection = input.parentProjection;\n const repairState = {\n didRepairStaleParent: false,\n policyRepairs: new PrincipalPolicyRepairBudget(),\n };\n for (;;) {\n const submitted = await createRemoteContainerWithMetadataDocumentAttempt({\n ...input,\n parentProjection,\n });\n if (!submitted) {\n return null;\n }\n if (submitted.ok) {\n return submitted.state;\n }\n const repair = await repairContainerCreateFailure({\n apiClient,\n failure: submitted,\n parentContainerId: input.parentContainerId,\n parentProjection,\n state: repairState,\n warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(\n input.runtime,\n ),\n stillCurrent: input.stillCurrent,\n });\n if (repair.kind === \"retry\") {\n parentProjection = repair.parentProjection;\n continue;\n }\n if (repair.kind === \"unavailable\") return null;\n return settleTerminalCreateFailure(submitted, input.stillCurrent) ===\n \"committed\"\n ? CONTAINER_ALREADY_COMMITTED\n : null;\n }\n}\n\nexport async function createRemoteContainerWithMetadataDocument(input: {\n systemSlot?: ContainerSystemSlot | null | undefined;\n containerId: string;\n parentContainerId: string;\n parentProjection?: ContainerWriterProjectionResponse | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n const author = resolveDocumentCreateAuthor(input.runtime);\n const { apiClient } = input.runtime;\n const parentSecretKey = input.runtime.crypto.encapsulationKeyPair?.secretKey;\n if (!author || !parentSecretKey) {\n input.runtime.util.log(\n \"Container contents: skipped container create because the writer context is unavailable.\",\n );\n return null;\n }\n\n const parentProjection =\n input.parentProjection ??\n (await apiClient.getContainerWriterProjection(input.parentContainerId));\n if (!parentProjection) {\n return null;\n }\n\n const containerEventId = crypto.randomUUID();\n const containerKey = crypto.getRandomValues(new Uint8Array(32));\n const containerSignedAt = new Date().toISOString();\n const metadataContentKey = crypto.getRandomValues(new Uint8Array(32));\n const metadataEventId = crypto.randomUUID();\n const metadataSignedAt = new Date().toISOString();\n return createContainerWithMetadataWithRepairs({\n author,\n containerEventId,\n containerId: input.containerId,\n containerKey,\n containerSignedAt,\n metadataContentKey,\n metadataEventId,\n metadataSignedAt,\n parentContainerId: input.parentContainerId,\n parentProjection,\n parentSecretKey,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n systemSlot: input.systemSlot,\n });\n}\n"]}
1
+ {"version":3,"file":"createWithMetadata.js","sourceRoot":"","sources":["createWithMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,GACtB,MAAM,2CAA2C,CAAC;AAMnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,4DAA4D,CAAC;AAEtH,OAAO,EAAE,wCAAwC,EAAE,MAAM,8CAA8C,CAAC;AAExG,OAAO,EACL,uDAAuD,EACvD,iCAAiC,GAClC,MAAM,yFAAyF,CAAC;AAEjG,OAAO,EAEL,uCAAuC,GACxC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC;AACjG,OAAO,EAEL,0CAA0C,EAC1C,wCAAwC,EACxC,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAK7F,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,+BAA+B,GAEhC,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAG/E,KAAK,UAAU,mCAAmC,CAAC,KAKlD;IAQC,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC;IACpC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,yCAAyC,CACtE,K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AE,CAAC;IACnD,MAAM,kBAAkB,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAC5C,MAAM,gBAAgB,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,OAAO,sCAAsC,CAAC;QAC5C,MAAM;QACN,gBAAgB;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,YAAY;QACZ,iBAAiB;QACjB,kBAAkB;QAClB,eAAe;QACf,gBAAgB;QAChB,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,gBAAgB;QAChB,eAAe;QACf,wBAAwB,EAAE,KAAK,CAAC,wBAAwB;QACxD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ContainerAccessManifestState } from \"@tearleads/crypto\";\nimport {\n type ContainerSystemSlot,\n isContainerSystemSlot,\n} from \"@tearleads/validators/containerSystemSlot\";\nimport type { ContainerCreateWithMetadataDocumentRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerCreateWithMetadataDocumentResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { locallyAcknowledgedContainerMutationHead } from \"../../../../data/containers/shared/mutationAcknowledgement\";\nimport type { ContainerMutationSubmitFailure } from \"../../../../data/containers/shared/types\";\nimport { assertDocumentWriterProjectionConsistent } from \"../../../../data/documents/shared/projection\";\nimport type { ProjectionUserKeyResolver } from \"../../../../data/keyingProjectionVerification\";\nimport {\n advanceLocallyAcknowledgedAccessManifestHeadsAtomically,\n locallyAuthoredAccessManifestHead,\n} from \"../../../../data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence\";\nimport type { ExecSql } from \"../../../../data/sqlite/sqlSchema\";\nimport {\n type buildMaterializedContainerCreatePlan,\n readContainerMutationMetadataDocumentId,\n} from \"../../../containers\";\nimport { repairContainerCreateFailure } from \"../../../containers/child/create/createSubmission\";\nimport {\n type buildMaterializedDocumentCreatePlan,\n documentWriterProjectionFromCreateResponse,\n persistedDocumentCreateStateFromResponse,\n resolveDocumentCreateAuthor,\n} from \"../../../documents\";\nimport { PrincipalPolicyRepairBudget } from \"../../../principals/policyRepairBudget\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../../principals/runtimePolicyWarmer\";\nimport type {\n ContainerWorkflowRuntime,\n CreatedRemoteContainerState,\n} from \"../types\";\nimport { settleTerminalCreateFailure } from \"./createTerminalFailure\";\nimport {\n buildContainerWithMetadataPlans,\n type ContainerWithMetadataPlanInput,\n} from \"./createWithMetadataPlan\";\n\n/**\n * Sentinel for a lost-response retry whose manifest already exists remotely.\n * Callers avoid a duplicate; the next parent hydration settles local state.\n */\nexport const CONTAINER_ALREADY_COMMITTED = Symbol(\"containerAlreadyCommitted\");\nexport type ContainerAlreadyCommitted = typeof CONTAINER_ALREADY_COMMITTED;\n\nasync function submitContainerWithMetadataDocument(input: {\n readonly organizationId: string;\n readonly request: ContainerCreateWithMetadataDocumentRequest;\n readonly runtime: ContainerWorkflowRuntime;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<\n | {\n readonly ok: true;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n }\n | ContainerMutationSubmitFailure\n | null\n> {\n if (input.stillCurrent?.() === false) return null;\n const { apiClient } = input.runtime;\n const result = await apiClient.createContainerWithMetadataDocumentResult(\n input.request,\n {\n expectedPaymentRequiredOrganizationId: input.organizationId,\n reportErrors: false,\n },\n );\n return result.ok ? { ok: true, response: result.data } : result;\n}\n\n/**\n * Seed the metadata document's writer projection from the create response so the\n * first read after the container is created (its own metadata sync, contents\n * hydration) resolves locally instead of a cold `GET writer-projection`. The\n * authorizing path is the child container projection the create was authored\n * against — locally built rather than server-fetched, so unlike the plain\n * document-create path this is gated on the projection's internal consistency;\n * on any mismatch the seed is skipped and the next read falls back to a fetch.\n */\nasync function seedMetadataDocumentWriterProjection(input: {\n readonly runtime: ContainerWorkflowRuntime;\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly execSql?: ExecSql | undefined;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<void> {\n const projection = documentWriterProjectionFromCreateResponse({\n containerProjection: input.childProjection,\n response: input.response.metadataDocument,\n });\n try {\n await assertDocumentWriterProjectionConsistent(projection, {\n execSql: input.execSql,\n stillCurrent: input.stillCurrent,\n trustedLocalProjection: true,\n });\n } catch {\n return;\n }\n if (input.stillCurrent?.() === false) return;\n input.runtime.apiClient.primeDocumentWriterProjection(\n input.response.metadataDocument.id,\n projection,\n );\n}\n\nasync function acknowledgeContainerWithMetadata(input: {\n containerPlan: Parameters<\n typeof locallyAcknowledgedContainerMutationHead\n >[0][\"plan\"];\n execSql: ExecSql;\n metadataDocumentPlan: Parameters<\n typeof persistedDocumentCreateStateFromResponse\n >[0];\n response: ContainerCreateWithMetadataDocumentResponse;\n stillCurrent?: (() => boolean) | undefined;\n}) {\n const persistedState = persistedDocumentCreateStateFromResponse(\n input.metadataDocumentPlan,\n input.response.metadataDocument,\n );\n const containerHead = await locallyAcknowledgedContainerMutationHead({\n plan: input.containerPlan,\n response: input.response.container,\n });\n await advanceLocallyAcknowledgedAccessManifestHeadsAtomically({\n execSql: input.execSql,\n heads: [\n containerHead,\n locallyAuthoredAccessManifestHead(input.metadataDocumentPlan),\n ],\n stillCurrent: input.stillCurrent,\n });\n return persistedState;\n}\n\n/**\n * Prime the new container's writer projection from the create plan the client\n * just authored, so the first write under it (a child folder, a document)\n * resolves locally instead of a cold `GET writer-projection`. Only primed when\n * the locally-built projection matches what the server created — the create\n * response echoes the container id and manifest head — so a mismatch skips the\n * seed and the next write falls back to a fetch (same fail-closed contract as\n * the metadata-document seed). Priming is safe for writes: the server still\n * validates every mutation, so a projection that later goes stale (rekey/share/\n * move evict it) just yields a rejected write that retries with a fresh fetch.\n */\nfunction seedChildContainerWriterProjection(input: {\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly runtime: ContainerWorkflowRuntime;\n}): void {\n const createdManifestHash =\n input.response.container.manifestHead.manifestHash;\n const projectedManifestHash = input.childProjection.path.at(-1)?.manifestHash;\n // Both hashes must be present and equal, or two undefined hashes would compare\n // equal and prime an empty/invalid projection.\n if (\n !createdManifestHash ||\n !projectedManifestHash ||\n input.childProjection.containerId !==\n input.response.container.containerId ||\n projectedManifestHash !== createdManifestHash\n ) {\n return;\n }\n\n input.runtime.apiClient.primeContainerWriterProjection(\n input.response.container.containerId,\n input.childProjection,\n );\n}\n\n/**\n * The persisted slot is the one this client signed into the manifest state.\n * The acknowledgement already refused a response that echoed anything else,\n * so the server's column never chooses which local record becomes Trash.\n */\nfunction signedCreateSystemSlot(\n state: ContainerAccessManifestState,\n): ContainerSystemSlot | null {\n if (state.systemSlot === null) return null;\n if (!isContainerSystemSlot(state.systemSlot)) {\n throw new Error(\"Container create plan signed an invalid system slot\");\n }\n return state.systemSlot;\n}\n\nasync function settleContainerWithMetadataCreate(input: {\n readonly childProjection: ContainerWriterProjectionResponse;\n readonly containerPlan: Awaited<\n ReturnType<typeof buildMaterializedContainerCreatePlan>\n >;\n readonly execSql: ExecSql;\n readonly metadataDocumentPlan: Awaited<\n ReturnType<typeof buildMaterializedDocumentCreatePlan>\n >;\n readonly response: ContainerCreateWithMetadataDocumentResponse;\n readonly runtime: ContainerWorkflowRuntime;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<{\n readonly ok: true;\n readonly state: CreatedRemoteContainerState;\n} | null> {\n if (\n input.response.container.containerId !==\n input.containerPlan.plan.containerId\n ) {\n throw new Error(\"Container metadata create response container mismatch\");\n }\n // The acknowledgement echoed the signed parent, which a child always names.\n const parentId = input.containerPlan.plan.state.parentContainerId;\n if (parentId === null) {\n throw new Error(\"A container create must commit under a parent\");\n }\n const metadataDocumentId = readContainerMutationMetadataDocumentId({\n response: input.response.container,\n });\n if (\n metadataDocumentId !== input.containerPlan.plan.metadataDocumentId ||\n input.response.metadataDocument.id !==\n input.metadataDocumentPlan.plan.documentId\n ) {\n throw new Error(\"Container metadata create response document mismatch\");\n }\n const persistedMetadataState = await acknowledgeContainerWithMetadata({\n containerPlan: input.containerPlan.plan,\n execSql: input.execSql,\n metadataDocumentPlan: input.metadataDocumentPlan.plan,\n response: input.response,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n await seedMetadataDocumentWriterProjection({\n childProjection: input.childProjection,\n execSql: input.execSql,\n response: input.response,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n seedChildContainerWriterProjection({\n childProjection: input.childProjection,\n response: input.response,\n runtime: input.runtime,\n });\n return {\n ok: true,\n state: {\n accessManifestHash: input.response.container.manifestHead.manifestHash,\n systemSlot: signedCreateSystemSlot(input.containerPlan.plan.state),\n containerId: input.response.container.containerId,\n createdAt: input.response.container.createdAt,\n metadataDocumentId,\n organizationId: input.response.container.organizationId,\n parentId,\n persistedMetadataState,\n updatedAt: input.response.container.updatedAt,\n },\n };\n}\n\nasync function createRemoteContainerWithMetadataDocumentAttempt(\n input: ContainerWithMetadataPlanInput,\n): Promise<\n | {\n readonly ok: true;\n readonly state: CreatedRemoteContainerState;\n }\n | ContainerMutationSubmitFailure\n | null\n> {\n const execSql = input.runtime.infra.execSql;\n const plans = await buildContainerWithMetadataPlans(input);\n if (!plans) return null;\n const { containerPlan, childProjection, metadataDocumentPlan } = plans;\n const submitted = await submitContainerWithMetadataDocument({\n organizationId: containerPlan.plan.state.organizationId,\n request: {\n systemSlot: input.systemSlot ?? null,\n container: containerPlan.plan.request,\n metadataDocument: metadataDocumentPlan.plan.request,\n },\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n if (!submitted?.ok) {\n return submitted;\n }\n return settleContainerWithMetadataCreate({\n childProjection,\n containerPlan,\n execSql,\n metadataDocumentPlan,\n response: submitted.response,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n });\n}\n\nasync function createContainerWithMetadataWithRepairs(\n input: Parameters<\n typeof createRemoteContainerWithMetadataDocumentAttempt\n >[0] & {\n readonly parentContainerId: string;\n },\n): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n const { apiClient } = input.runtime;\n let parentProjection = input.parentProjection;\n const repairState = {\n didRepairStaleParent: false,\n policyRepairs: new PrincipalPolicyRepairBudget(),\n };\n for (;;) {\n const submitted = await createRemoteContainerWithMetadataDocumentAttempt({\n ...input,\n parentProjection,\n });\n if (!submitted) {\n return null;\n }\n if (submitted.ok) {\n return submitted.state;\n }\n const repair = await repairContainerCreateFailure({\n apiClient,\n failure: submitted,\n parentContainerId: input.parentContainerId,\n parentProjection,\n state: repairState,\n warmReferencedPrincipalPolicies: createRuntimePrincipalPolicyWarmer(\n input.runtime,\n ),\n stillCurrent: input.stillCurrent,\n });\n if (repair.kind === \"retry\") {\n parentProjection = repair.parentProjection;\n continue;\n }\n if (repair.kind === \"unavailable\") return null;\n return settleTerminalCreateFailure(submitted, input.stillCurrent) ===\n \"committed\"\n ? CONTAINER_ALREADY_COMMITTED\n : null;\n }\n}\n\nexport async function createRemoteContainerWithMetadataDocument(input: {\n systemSlot?: ContainerSystemSlot | null | undefined;\n containerId: string;\n parentContainerId: string;\n parentProjection?: ContainerWriterProjectionResponse | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n const author = resolveDocumentCreateAuthor(input.runtime);\n const { apiClient } = input.runtime;\n const parentSecretKey = input.runtime.crypto.encapsulationKeyPair?.secretKey;\n if (!author || !parentSecretKey) {\n input.runtime.util.log(\n \"Container contents: skipped container create because the writer context is unavailable.\",\n );\n return null;\n }\n\n const parentProjection =\n input.parentProjection ??\n (await apiClient.getContainerWriterProjection(input.parentContainerId));\n if (!parentProjection) {\n return null;\n }\n\n const containerEventId = crypto.randomUUID();\n const containerKey = crypto.getRandomValues(new Uint8Array(32));\n const containerSignedAt = new Date().toISOString();\n const metadataContentKey = crypto.getRandomValues(new Uint8Array(32));\n const metadataEventId = crypto.randomUUID();\n const metadataSignedAt = new Date().toISOString();\n return createContainerWithMetadataWithRepairs({\n author,\n containerEventId,\n containerId: input.containerId,\n containerKey,\n containerSignedAt,\n metadataContentKey,\n metadataEventId,\n metadataSignedAt,\n parentContainerId: input.parentContainerId,\n parentProjection,\n parentSecretKey,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n runtime: input.runtime,\n stillCurrent: input.stillCurrent,\n systemSlot: input.systemSlot,\n });\n}\n"]}
@@ -8,6 +8,38 @@ import { moveRemoteContainer } from "./remote.js";
8
8
  function currentMoveResult(isCurrent, result) {
9
9
  return isCurrent() ? result : "abandoned";
10
10
  }
11
+ /**
12
+ * The server accepted a move this pass did not settle, so the intent stays
13
+ * queued: a later pass re-posts it and a purge of its subtree waits. Fixed
14
+ * messages only; the error's call site names the path.
15
+ */
16
+ function reportUnsettledAcceptedMove(state, message, error) {
17
+ try {
18
+ const report = state.runtime.util.logError;
19
+ if (report)
20
+ void Promise.resolve(report(message, error)).catch(() => { });
21
+ }
22
+ catch {
23
+ // A host logger must not change the replay result.
24
+ }
25
+ }
26
+ function reportStaleAcceptedMove(state, error) {
27
+ reportUnsettledAcceptedMove(state, "Container contents: a stale sync pass dropped an accepted container move", error);
28
+ }
29
+ function reportFailedAcceptedMove(state, error) {
30
+ if (!(error instanceof Error))
31
+ return;
32
+ reportUnsettledAcceptedMove(state, "Container contents: an accepted container move failed to settle", error);
33
+ }
34
+ /** persistAcceptedMoveIntent already asked to reconcile a stale result. */
35
+ function unpersistedMoveResult(syncInput) {
36
+ if (!syncInput.isCurrent()) {
37
+ reportStaleAcceptedMove(syncInput.state, new Error("Stale pass dropped a persisting container move"));
38
+ return "abandoned";
39
+ }
40
+ reportUnsettledAcceptedMove(syncInput.state, "Container contents: an accepted container move did not persist", new Error("Accepted container move did not persist"));
41
+ return "failed";
42
+ }
11
43
  async function recordPendingMoveIntentError(input) {
12
44
  if (!input.isCurrent()) {
13
45
  return false;
@@ -170,6 +202,7 @@ async function movePendingRemoteContainer(input) {
170
202
  let remoteParentId = intent.parentContainerId;
171
203
  const abandonAppliedMove = () => {
172
204
  if (remoteMoveApplied) {
205
+ reportStaleAcceptedMove(state, new Error("Stale pass dropped an accepted container move"));
173
206
  syncInput.requestRemoteReconciliation(remoteParentId);
174
207
  }
175
208
  return "abandoned";
@@ -177,6 +210,9 @@ async function movePendingRemoteContainer(input) {
177
210
  try {
178
211
  const moved = await moveRemoteContainer({
179
212
  containerId: intent.containerId,
213
+ onStaleAcceptance: () => {
214
+ remoteMoveApplied = true;
215
+ },
180
216
  parentContainerId: intent.parentContainerId,
181
217
  resolveProjectionUserKey: state.resolveProjectionUserKey,
182
218
  runtime: state.runtime,
@@ -184,8 +220,9 @@ async function movePendingRemoteContainer(input) {
184
220
  });
185
221
  if (!moved) {
186
222
  if (!syncInput.isCurrent()) {
187
- syncInput.requestRemoteReconciliation(intent.parentContainerId);
188
- return "abandoned";
223
+ if (!remoteMoveApplied)
224
+ syncInput.requestRemoteReconciliation(intent.parentContainerId);
225
+ return abandonAppliedMove();
189
226
  }
190
227
  await recordPendingMoveIntentError({
191
228
  containerId: intent.containerId,
@@ -209,9 +246,8 @@ async function movePendingRemoteContainer(input) {
209
246
  requestRemoteReconciliation: syncInput.requestRemoteReconciliation,
210
247
  state,
211
248
  });
212
- if (!persisted) {
213
- return currentMoveResult(syncInput.isCurrent, "failed");
214
- }
249
+ if (!persisted)
250
+ return unpersistedMoveResult(syncInput);
215
251
  state.runtime.util.log(`Container contents: synced queued container move ${intent.containerId}`);
216
252
  return "moved";
217
253
  }
@@ -230,6 +266,8 @@ async function movePendingRemoteContainer(input) {
230
266
  if (!syncInput.isCurrent()) {
231
267
  return abandonAppliedMove();
232
268
  }
269
+ if (remoteMoveApplied)
270
+ reportFailedAcceptedMove(state, error);
233
271
  await recordPendingMoveIntentError({
234
272
  containerId: intent.containerId,
235
273
  expectedIntentId: intent.id,
@@ -1 +1 @@
1
- {"version":3,"file":"moveIntentSync.js","sourceRoot":"","sources":["moveIntentSync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qDAAqD,CAAC;AAChG,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,oCAAoC,EACpC,qCAAqC,GACtC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAS/C,SAAS,iBAAiB,CAExB,SAAwB,EAAE,MAAc;IACxC,OAAO,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,4BAA4B,CAAC,KAQ3C;IACC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAClD,MAAM,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,qBAAqB,CAAC,OAAO,EAAE;QAC3D,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;Q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,EAAE,CAAC;YAC3B,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACvB,UAAU,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { ContainerPathTooDeepError } from \"../../../data/containers/shared/containerPathLimits\";\nimport { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../principals/runtimePolicyWarmer\";\nimport {\n createDetachedContainerMetadataState,\n installDetachedContainerMetadataState,\n} from \"../metadata/metadataStateIsolation\";\nimport type { ContainerState, RemoteContainer } from \"../remoteHydration\";\nimport { hasRemoteContainerMetadataState } from \"../remoteHydration/reconciliation\";\nimport { moveRemoteContainer } from \"./remote\";\nimport type {\n ContainerMoveIntentSyncHost,\n ContainerMoveIntentSyncInput,\n ContainerMoveIntentSyncState,\n} from \"./types\";\n\ntype MoveIntentSyncResult = \"abandoned\" | \"blocked\" | \"failed\" | \"moved\";\n\nfunction currentMoveResult<\n Result extends Exclude<MoveIntentSyncResult, \"abandoned\">,\n>(isCurrent: () => boolean, result: Result): \"abandoned\" | Result {\n return isCurrent() ? result : \"abandoned\";\n}\n\nasync function recordPendingMoveIntentError(input: {\n blocked?: boolean | undefined;\n containerId: string;\n expectedIntentId: string;\n expectedUpdatedAt: string;\n isCurrent: () => boolean;\n message: string;\n state: ContainerMoveIntentSyncState;\n}): Promise<boolean> {\n if (!input.isCurrent()) {\n return false;\n }\n const execSql = input.state.runtime.infra.execSql;\n await input.state.persistence.recordMoveIntentError(execSql, {\n blocked: input.blocked,\n containerId: input.containerId,\n expectedIntentId: input.expectedIntentId,\n expectedUpdatedAt: input.expectedUpdatedAt,\n message: input.message,\n stillCurrent: input.isCurrent,\n });\n return input.isCurrent();\n}\n\nasync function resolveMoveIntentLocalUpdatedAt(input: {\n containerId: string;\n isCurrent: () => boolean;\n remoteUpdatedAt: string;\n state: ContainerMoveIntentSyncState;\n}): Promise<string | null> {\n if (!input.isCurrent()) {\n return null;\n }\n const previousLocalUpdatedAt =\n input.state.containersById.get(input.containerId)?.container\n .localUpdatedAt ?? null;\n if (\n !previousLocalUpdatedAt ||\n previousLocalUpdatedAt.localeCompare(input.remoteUpdatedAt) <= 0\n ) {\n return input.remoteUpdatedAt;\n }\n\n const execSql = input.state.runtime.infra.execSql;\n const containersWithPendingMetadataUpdates =\n await input.state.persistence.listContainerIdsWithPendingUpdates(execSql, [\n input.containerId,\n ]);\n if (!input.isCurrent()) {\n return null;\n }\n\n return containersWithPendingMetadataUpdates.includes(input.containerId)\n ? previousLocalUpdatedAt\n : input.remoteUpdatedAt;\n}\n\nexport async function persistAcceptedMoveIntent(input: {\n host: ContainerMoveIntentSyncHost;\n isCurrent: () => boolean;\n intent: ContainerMoveIntentSyncInput[\"intent\"];\n moved: RemoteContainer;\n requestRemoteReconciliation: (parentContainerId: string | null) => void;\n state: ContainerMoveIntentSyncState;\n}): Promise<boolean> {\n const { host, intent, moved, state } = input;\n const abandon = () => {\n input.requestRemoteReconciliation(moved.parentId);\n return false;\n };\n if (!input.isCurrent()) return abandon();\n const containerState = state.containersById.get(intent.containerId);\n if (!containerState) {\n return false;\n }\n\n await createRuntimePrincipalPolicyWarmer(state.runtime)({\n organizationId: moved.organizationId,\n references: moved.metadataReferencedPrincipals,\n stillCurrent: input.isCurrent,\n });\n if (!input.isCurrent()) {\n return abandon();\n }\n const localUpdatedAt = await resolveMoveIntentLocalUpdatedAt({\n containerId: intent.containerId,\n isCurrent: input.isCurrent,\n remoteUpdatedAt: moved.updatedAt,\n state,\n });\n if (!input.isCurrent() || localUpdatedAt === null) {\n return abandon();\n }\n const persistenceCandidate =\n await createDetachedContainerMetadataState(containerState);\n if (!input.isCurrent()) {\n return abandon();\n }\n persistenceCandidate.container = {\n ...persistenceCandidate.container,\n createdAt: moved.createdAt,\n serverCreatedAt: moved.createdAt,\n serverUpdatedAt: moved.updatedAt,\n updatedAt: moved.updatedAt,\n };\n const persistenceResult = await host.persistContainerState(\n persistenceCandidate,\n {\n accessEpoch: moved.metadataAccessEpoch,\n accessStateHash: moved.metadataAccessStateHash,\n documentId: moved.metadataDocumentId,\n metadataDocumentId: moved.metadataDocumentId,\n organizationId: moved.organizationId,\n parentId: moved.parentId,\n systemSlot: moved.systemSlot ?? null,\n },\n false,\n {\n localUpdatedAt,\n serverTimestamps: {\n createdAt: moved.createdAt,\n updatedAt: moved.updatedAt,\n },\n },\n {\n expectedStateWhenMissing: containerState,\n isCurrent: input.isCurrent,\n moveIntentSettlement: {\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n },\n },\n );\n if (!input.isCurrent() || persistenceResult.status !== \"persisted\") {\n return abandon();\n }\n if (persistenceResult.moveIntentSettled !== true) {\n throw new Error(\n \"Container move persistence must settle the intent atomically\",\n );\n }\n if (!input.isCurrent()) return abandon();\n const { record: nextRecord } = persistenceResult;\n installDetachedContainerMetadataState(containerState, persistenceCandidate, {\n candidateRecord: nextRecord,\n preserveConcurrentMetadataEdit: true,\n });\n containerState.container = {\n ...containerState.container,\n metadataDocumentId: moved.metadataDocumentId,\n organizationId: moved.organizationId,\n parentId: moved.parentId,\n };\n return true;\n}\n\n/**\n * A move refused for path length never succeeds; the queue-time check saw only\n * the descendants this device holds. Drop the queued move and restore the\n * previous parent together: the server row never changed, so no listing would\n * ever put the folder back.\n */\nasync function abandonTooDeepMove(\n syncInput: ContainerMoveIntentSyncInput,\n): Promise<MoveIntentSyncResult> {\n const { host, intent, state } = syncInput;\n const previousParentId = intent.previousParentContainerId;\n if (previousParentId === null) {\n throw new Error(\"A queued container move must name its previous parent\");\n }\n const abandoned = await state.persistence.abandonMoveIntentRevision(\n state.runtime.infra.execSql,\n {\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n previousParentContainerId: previousParentId,\n stillCurrent: syncInput.isCurrent,\n },\n );\n if (!syncInput.isCurrent()) return \"abandoned\";\n // A newer local move superseded this revision; it replays on its own.\n if (!abandoned) return \"failed\";\n const containerState = state.containersById.get(intent.containerId);\n if (containerState) {\n containerState.container = {\n ...containerState.container,\n parentId: previousParentId,\n };\n }\n host.updateSnapshot();\n state.runtime.util.log(\n `Container contents: abandoned queued move of ${intent.containerId}; its path would exceed the maximum depth`,\n );\n return \"failed\";\n}\n\nasync function movePendingRemoteContainer(input: {\n parentState: ContainerState;\n syncInput: ContainerMoveIntentSyncInput;\n}): Promise<MoveIntentSyncResult> {\n const { parentState, syncInput } = input;\n const { host, intent, state } = syncInput;\n let remoteMoveApplied = false;\n let remoteParentId: string | null = intent.parentContainerId;\n const abandonAppliedMove = () => {\n if (remoteMoveApplied) {\n syncInput.requestRemoteReconciliation(remoteParentId);\n }\n return \"abandoned\" as const;\n };\n try {\n const moved = await moveRemoteContainer({\n containerId: intent.containerId,\n parentContainerId: intent.parentContainerId,\n resolveProjectionUserKey: state.resolveProjectionUserKey,\n runtime: state.runtime,\n stillCurrent: syncInput.isCurrent,\n });\n if (!moved) {\n if (!syncInput.isCurrent()) {\n syncInput.requestRemoteReconciliation(intent.parentContainerId);\n return \"abandoned\";\n }\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: syncInput.isCurrent,\n message: \"Remote container move was rejected or unavailable\",\n state,\n });\n return currentMoveResult(syncInput.isCurrent, \"failed\");\n }\n remoteMoveApplied = true;\n remoteParentId = moved.parentId;\n if (!syncInput.isCurrent()) return abandonAppliedMove();\n\n const persisted = await persistAcceptedMoveIntent({\n host,\n isCurrent: syncInput.isCurrent,\n intent,\n moved,\n requestRemoteReconciliation: syncInput.requestRemoteReconciliation,\n state,\n });\n if (!persisted) {\n return currentMoveResult(syncInput.isCurrent, \"failed\");\n }\n state.runtime.util.log(\n `Container contents: synced queued container move ${intent.containerId}`,\n );\n return \"moved\";\n } catch (error: unknown) {\n if (!syncInput.isCurrent()) {\n return abandonAppliedMove();\n }\n if (error instanceof ContainerPathTooDeepError)\n return abandonTooDeepMove(syncInput);\n await reportAndRethrowKeyingVerificationError(\n error,\n state.runtime.util.reportSecurityIncident,\n {\n objectId: intent.containerId,\n objectKind: \"container\",\n operation: \"container.move.replay\",\n organizationId: parentState.container.organizationId,\n },\n );\n if (!syncInput.isCurrent()) {\n return abandonAppliedMove();\n }\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: syncInput.isCurrent,\n message: `Failed to sync container move: ${errorMessage(error)}`,\n state,\n });\n return currentMoveResult(syncInput.isCurrent, \"failed\");\n }\n}\n\nasync function trySyncPendingContainerMoveIntent(\n input: ContainerMoveIntentSyncInput,\n): Promise<MoveIntentSyncResult> {\n const { intent, state } = input;\n if (!input.isCurrent()) {\n return \"abandoned\";\n }\n const containerState = state.containersById.get(intent.containerId);\n const parentState = state.containersById.get(intent.parentContainerId);\n\n if (!containerState) {\n await recordPendingMoveIntentError({\n blocked: true,\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move intent references a missing local container\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"failed\");\n }\n if (!parentState) {\n await recordPendingMoveIntentError({\n blocked: true,\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message:\n \"Container move intent references a missing destination parent container\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"failed\");\n }\n if (input.isRemoteSyncBlocked(containerState.container.organizationId)) {\n return \"blocked\";\n }\n if (\n !hasRemoteContainerMetadataState(containerState) ||\n input.isCreatePending(intent.containerId)\n ) {\n // Source not synced yet is TRANSIENT, exactly like the destination case\n // below: the source's own create intent syncs first (createIntentSync runs\n // before moveIntentSync in a pass), but if that create fails on this pass\n // the source still lacks remote metadata here. Keep the intent 'pending'\n // (not 'blocked') so the queue reports a retryable failure rather than a\n // missing-dependency block; either way listUnsyncedMoveIntents replays it\n // once the create lands.\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move source is not synced yet\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"blocked\");\n }\n if (\n !hasRemoteContainerMetadataState(parentState) ||\n input.isCreatePending(intent.parentContainerId)\n ) {\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move destination parent is not synced yet\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"blocked\");\n }\n\n return movePendingRemoteContainer({ parentState, syncInput: input });\n}\n\nexport async function syncPendingContainerMoveIntents(input: {\n host: ContainerMoveIntentSyncHost;\n isCreatePending: (containerId: string) => boolean;\n isCurrent: () => boolean;\n isRemoteSyncBlocked: (organizationId: string) => boolean;\n requestRemoteReconciliation: (parentContainerId: string | null) => void;\n state: ContainerMoveIntentSyncState;\n}): Promise<number> {\n if (!input.isCurrent()) {\n return 0;\n }\n const { host } = input;\n const state = { ...input.state };\n const execSql = state.runtime.infra.execSql;\n const pendingIntents =\n await state.persistence.listUnsyncedMoveIntents(execSql);\n if (!input.isCurrent()) {\n return 0;\n }\n let movedCount = 0;\n\n for (const intent of pendingIntents) {\n if (!input.isCurrent()) {\n return movedCount;\n }\n const result = await trySyncPendingContainerMoveIntent({\n host,\n isCurrent: input.isCurrent,\n isCreatePending: input.isCreatePending,\n isRemoteSyncBlocked: input.isRemoteSyncBlocked,\n intent,\n requestRemoteReconciliation: input.requestRemoteReconciliation,\n state,\n });\n if (result === \"abandoned\") {\n return movedCount;\n }\n\n if (result === \"moved\") {\n movedCount += 1;\n }\n }\n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esContent":["import { ContainerPathTooDeepError } from \"../../../data/containers/shared/containerPathLimits\";\nimport { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../principals/runtimePolicyWarmer\";\nimport {\n createDetachedContainerMetadataState,\n installDetachedContainerMetadataState,\n} from \"../metadata/metadataStateIsolation\";\nimport type { ContainerState, RemoteContainer } from \"../remoteHydration\";\nimport { hasRemoteContainerMetadataState } from \"../remoteHydration/reconciliation\";\nimport { moveRemoteContainer } from \"./remote\";\nimport type {\n ContainerMoveIntentSyncHost,\n ContainerMoveIntentSyncInput,\n ContainerMoveIntentSyncState,\n} from \"./types\";\n\ntype MoveIntentSyncResult = \"abandoned\" | \"blocked\" | \"failed\" | \"moved\";\n\nfunction currentMoveResult<\n Result extends Exclude<MoveIntentSyncResult, \"abandoned\">,\n>(isCurrent: () => boolean, result: Result): \"abandoned\" | Result {\n return isCurrent() ? result : \"abandoned\";\n}\n\n/**\n * The server accepted a move this pass did not settle, so the intent stays\n * queued: a later pass re-posts it and a purge of its subtree waits. Fixed\n * messages only; the error's call site names the path.\n */\nfunction reportUnsettledAcceptedMove(\n state: ContainerMoveIntentSyncState,\n message: string,\n error: Error,\n): void {\n try {\n const report = state.runtime.util.logError;\n if (report) void Promise.resolve(report(message, error)).catch(() => {});\n } catch {\n // A host logger must not change the replay result.\n }\n}\n\nfunction reportStaleAcceptedMove(\n state: ContainerMoveIntentSyncState,\n error: Error,\n): void {\n reportUnsettledAcceptedMove(\n state,\n \"Container contents: a stale sync pass dropped an accepted container move\",\n error,\n );\n}\n\nfunction reportFailedAcceptedMove(\n state: ContainerMoveIntentSyncState,\n error: unknown,\n): void {\n if (!(error instanceof Error)) return;\n reportUnsettledAcceptedMove(\n state,\n \"Container contents: an accepted container move failed to settle\",\n error,\n );\n}\n\n/** persistAcceptedMoveIntent already asked to reconcile a stale result. */\nfunction unpersistedMoveResult(\n syncInput: ContainerMoveIntentSyncInput,\n): MoveIntentSyncResult {\n if (!syncInput.isCurrent()) {\n reportStaleAcceptedMove(\n syncInput.state,\n new Error(\"Stale pass dropped a persisting container move\"),\n );\n return \"abandoned\";\n }\n reportUnsettledAcceptedMove(\n syncInput.state,\n \"Container contents: an accepted container move did not persist\",\n new Error(\"Accepted container move did not persist\"),\n );\n return \"failed\";\n}\n\nasync function recordPendingMoveIntentError(input: {\n blocked?: boolean | undefined;\n containerId: string;\n expectedIntentId: string;\n expectedUpdatedAt: string;\n isCurrent: () => boolean;\n message: string;\n state: ContainerMoveIntentSyncState;\n}): Promise<boolean> {\n if (!input.isCurrent()) {\n return false;\n }\n const execSql = input.state.runtime.infra.execSql;\n await input.state.persistence.recordMoveIntentError(execSql, {\n blocked: input.blocked,\n containerId: input.containerId,\n expectedIntentId: input.expectedIntentId,\n expectedUpdatedAt: input.expectedUpdatedAt,\n message: input.message,\n stillCurrent: input.isCurrent,\n });\n return input.isCurrent();\n}\n\nasync function resolveMoveIntentLocalUpdatedAt(input: {\n containerId: string;\n isCurrent: () => boolean;\n remoteUpdatedAt: string;\n state: ContainerMoveIntentSyncState;\n}): Promise<string | null> {\n if (!input.isCurrent()) {\n return null;\n }\n const previousLocalUpdatedAt =\n input.state.containersById.get(input.containerId)?.container\n .localUpdatedAt ?? null;\n if (\n !previousLocalUpdatedAt ||\n previousLocalUpdatedAt.localeCompare(input.remoteUpdatedAt) <= 0\n ) {\n return input.remoteUpdatedAt;\n }\n\n const execSql = input.state.runtime.infra.execSql;\n const containersWithPendingMetadataUpdates =\n await input.state.persistence.listContainerIdsWithPendingUpdates(execSql, [\n input.containerId,\n ]);\n if (!input.isCurrent()) {\n return null;\n }\n\n return containersWithPendingMetadataUpdates.includes(input.containerId)\n ? previousLocalUpdatedAt\n : input.remoteUpdatedAt;\n}\n\nexport async function persistAcceptedMoveIntent(input: {\n host: ContainerMoveIntentSyncHost;\n isCurrent: () => boolean;\n intent: ContainerMoveIntentSyncInput[\"intent\"];\n moved: RemoteContainer;\n requestRemoteReconciliation: (parentContainerId: string | null) => void;\n state: ContainerMoveIntentSyncState;\n}): Promise<boolean> {\n const { host, intent, moved, state } = input;\n const abandon = () => {\n input.requestRemoteReconciliation(moved.parentId);\n return false;\n };\n if (!input.isCurrent()) return abandon();\n const containerState = state.containersById.get(intent.containerId);\n if (!containerState) {\n return false;\n }\n\n await createRuntimePrincipalPolicyWarmer(state.runtime)({\n organizationId: moved.organizationId,\n references: moved.metadataReferencedPrincipals,\n stillCurrent: input.isCurrent,\n });\n if (!input.isCurrent()) {\n return abandon();\n }\n const localUpdatedAt = await resolveMoveIntentLocalUpdatedAt({\n containerId: intent.containerId,\n isCurrent: input.isCurrent,\n remoteUpdatedAt: moved.updatedAt,\n state,\n });\n if (!input.isCurrent() || localUpdatedAt === null) {\n return abandon();\n }\n const persistenceCandidate =\n await createDetachedContainerMetadataState(containerState);\n if (!input.isCurrent()) {\n return abandon();\n }\n persistenceCandidate.container = {\n ...persistenceCandidate.container,\n createdAt: moved.createdAt,\n serverCreatedAt: moved.createdAt,\n serverUpdatedAt: moved.updatedAt,\n updatedAt: moved.updatedAt,\n };\n const persistenceResult = await host.persistContainerState(\n persistenceCandidate,\n {\n accessEpoch: moved.metadataAccessEpoch,\n accessStateHash: moved.metadataAccessStateHash,\n documentId: moved.metadataDocumentId,\n metadataDocumentId: moved.metadataDocumentId,\n organizationId: moved.organizationId,\n parentId: moved.parentId,\n systemSlot: moved.systemSlot ?? null,\n },\n false,\n {\n localUpdatedAt,\n serverTimestamps: {\n createdAt: moved.createdAt,\n updatedAt: moved.updatedAt,\n },\n },\n {\n expectedStateWhenMissing: containerState,\n isCurrent: input.isCurrent,\n moveIntentSettlement: {\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n },\n },\n );\n if (!input.isCurrent() || persistenceResult.status !== \"persisted\") {\n return abandon();\n }\n if (persistenceResult.moveIntentSettled !== true) {\n throw new Error(\n \"Container move persistence must settle the intent atomically\",\n );\n }\n if (!input.isCurrent()) return abandon();\n const { record: nextRecord } = persistenceResult;\n installDetachedContainerMetadataState(containerState, persistenceCandidate, {\n candidateRecord: nextRecord,\n preserveConcurrentMetadataEdit: true,\n });\n containerState.container = {\n ...containerState.container,\n metadataDocumentId: moved.metadataDocumentId,\n organizationId: moved.organizationId,\n parentId: moved.parentId,\n };\n return true;\n}\n\n/**\n * A move refused for path length never succeeds; the queue-time check saw only\n * the descendants this device holds. Drop the queued move and restore the\n * previous parent together: the server row never changed, so no listing would\n * ever put the folder back.\n */\nasync function abandonTooDeepMove(\n syncInput: ContainerMoveIntentSyncInput,\n): Promise<MoveIntentSyncResult> {\n const { host, intent, state } = syncInput;\n const previousParentId = intent.previousParentContainerId;\n if (previousParentId === null) {\n throw new Error(\"A queued container move must name its previous parent\");\n }\n const abandoned = await state.persistence.abandonMoveIntentRevision(\n state.runtime.infra.execSql,\n {\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n previousParentContainerId: previousParentId,\n stillCurrent: syncInput.isCurrent,\n },\n );\n if (!syncInput.isCurrent()) return \"abandoned\";\n // A newer local move superseded this revision; it replays on its own.\n if (!abandoned) return \"failed\";\n const containerState = state.containersById.get(intent.containerId);\n if (containerState) {\n containerState.container = {\n ...containerState.container,\n parentId: previousParentId,\n };\n }\n host.updateSnapshot();\n state.runtime.util.log(\n `Container contents: abandoned queued move of ${intent.containerId}; its path would exceed the maximum depth`,\n );\n return \"failed\";\n}\n\nasync function movePendingRemoteContainer(input: {\n parentState: ContainerState;\n syncInput: ContainerMoveIntentSyncInput;\n}): Promise<MoveIntentSyncResult> {\n const { parentState, syncInput } = input;\n const { host, intent, state } = syncInput;\n let remoteMoveApplied = false;\n let remoteParentId: string | null = intent.parentContainerId;\n const abandonAppliedMove = () => {\n if (remoteMoveApplied) {\n reportStaleAcceptedMove(\n state,\n new Error(\"Stale pass dropped an accepted container move\"),\n );\n syncInput.requestRemoteReconciliation(remoteParentId);\n }\n return \"abandoned\" as const;\n };\n try {\n const moved = await moveRemoteContainer({\n containerId: intent.containerId,\n onStaleAcceptance: () => {\n remoteMoveApplied = true;\n },\n parentContainerId: intent.parentContainerId,\n resolveProjectionUserKey: state.resolveProjectionUserKey,\n runtime: state.runtime,\n stillCurrent: syncInput.isCurrent,\n });\n if (!moved) {\n if (!syncInput.isCurrent()) {\n if (!remoteMoveApplied)\n syncInput.requestRemoteReconciliation(intent.parentContainerId);\n return abandonAppliedMove();\n }\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: syncInput.isCurrent,\n message: \"Remote container move was rejected or unavailable\",\n state,\n });\n return currentMoveResult(syncInput.isCurrent, \"failed\");\n }\n remoteMoveApplied = true;\n remoteParentId = moved.parentId;\n if (!syncInput.isCurrent()) return abandonAppliedMove();\n\n const persisted = await persistAcceptedMoveIntent({\n host,\n isCurrent: syncInput.isCurrent,\n intent,\n moved,\n requestRemoteReconciliation: syncInput.requestRemoteReconciliation,\n state,\n });\n if (!persisted) return unpersistedMoveResult(syncInput);\n state.runtime.util.log(\n `Container contents: synced queued container move ${intent.containerId}`,\n );\n return \"moved\";\n } catch (error: unknown) {\n if (!syncInput.isCurrent()) {\n return abandonAppliedMove();\n }\n if (error instanceof ContainerPathTooDeepError)\n return abandonTooDeepMove(syncInput);\n await reportAndRethrowKeyingVerificationError(\n error,\n state.runtime.util.reportSecurityIncident,\n {\n objectId: intent.containerId,\n objectKind: \"container\",\n operation: \"container.move.replay\",\n organizationId: parentState.container.organizationId,\n },\n );\n if (!syncInput.isCurrent()) {\n return abandonAppliedMove();\n }\n if (remoteMoveApplied) reportFailedAcceptedMove(state, error);\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: syncInput.isCurrent,\n message: `Failed to sync container move: ${errorMessage(error)}`,\n state,\n });\n return currentMoveResult(syncInput.isCurrent, \"failed\");\n }\n}\n\nasync function trySyncPendingContainerMoveIntent(\n input: ContainerMoveIntentSyncInput,\n): Promise<MoveIntentSyncResult> {\n const { intent, state } = input;\n if (!input.isCurrent()) {\n return \"abandoned\";\n }\n const containerState = state.containersById.get(intent.containerId);\n const parentState = state.containersById.get(intent.parentContainerId);\n\n if (!containerState) {\n await recordPendingMoveIntentError({\n blocked: true,\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move intent references a missing local container\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"failed\");\n }\n if (!parentState) {\n await recordPendingMoveIntentError({\n blocked: true,\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message:\n \"Container move intent references a missing destination parent container\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"failed\");\n }\n if (input.isRemoteSyncBlocked(containerState.container.organizationId)) {\n return \"blocked\";\n }\n if (\n !hasRemoteContainerMetadataState(containerState) ||\n input.isCreatePending(intent.containerId)\n ) {\n // Source not synced yet is TRANSIENT, exactly like the destination case\n // below: the source's own create intent syncs first (createIntentSync runs\n // before moveIntentSync in a pass), but if that create fails on this pass\n // the source still lacks remote metadata here. Keep the intent 'pending'\n // (not 'blocked') so the queue reports a retryable failure rather than a\n // missing-dependency block; either way listUnsyncedMoveIntents replays it\n // once the create lands.\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move source is not synced yet\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"blocked\");\n }\n if (\n !hasRemoteContainerMetadataState(parentState) ||\n input.isCreatePending(intent.parentContainerId)\n ) {\n await recordPendingMoveIntentError({\n containerId: intent.containerId,\n expectedIntentId: intent.id,\n expectedUpdatedAt: intent.updatedAt,\n isCurrent: input.isCurrent,\n message: \"Container move destination parent is not synced yet\",\n state,\n });\n return currentMoveResult(input.isCurrent, \"blocked\");\n }\n\n return movePendingRemoteContainer({ parentState, syncInput: input });\n}\n\nexport async function syncPendingContainerMoveIntents(input: {\n host: ContainerMoveIntentSyncHost;\n isCreatePending: (containerId: string) => boolean;\n isCurrent: () => boolean;\n isRemoteSyncBlocked: (organizationId: string) => boolean;\n requestRemoteReconciliation: (parentContainerId: string | null) => void;\n state: ContainerMoveIntentSyncState;\n}): Promise<number> {\n if (!input.isCurrent()) {\n return 0;\n }\n const { host } = input;\n const state = { ...input.state };\n const execSql = state.runtime.infra.execSql;\n const pendingIntents =\n await state.persistence.listUnsyncedMoveIntents(execSql);\n if (!input.isCurrent()) {\n return 0;\n }\n let movedCount = 0;\n\n for (const intent of pendingIntents) {\n if (!input.isCurrent()) {\n return movedCount;\n }\n const result = await trySyncPendingContainerMoveIntent({\n host,\n isCurrent: input.isCurrent,\n isCreatePending: input.isCreatePending,\n isRemoteSyncBlocked: input.isRemoteSyncBlocked,\n intent,\n requestRemoteReconciliation: input.requestRemoteReconciliation,\n state,\n });\n if (result === \"abandoned\") {\n return movedCount;\n }\n\n if (result === \"moved\") {\n movedCount += 1;\n }\n }\n\n return movedCount;\n}\n"]}
@@ -0,0 +1,119 @@
1
+ import { listDocumentPlacementIntentStates } from "../../../../data/persistence/container-contents/documentPurgePlacement.js";
2
+ import { listDocumentsByContainerIdsOrDocumentIds } from "../../../../data/persistence/documents/documentsPersistence.js";
3
+ import { collectSubtreeLeafFirst } from "./purgeTreeCollection.js";
4
+ // A pass replays pending and blocked moves. A denied placement waits for the
5
+ // next store generation and an unavailable one never replays, so waiting on
6
+ // either would only reach the ceiling.
7
+ const REPLAYED_STATUSES = new Set(["pending", "blocked"]);
8
+ const DEFAULT_TIMING = { pollMs: 200, timeoutMs: 30_000 };
9
+ function delay(ms, signal) {
10
+ return new Promise((resolve) => {
11
+ const timer = setTimeout(done, ms);
12
+ function done() {
13
+ clearTimeout(timer);
14
+ signal?.removeEventListener("abort", done);
15
+ resolve();
16
+ }
17
+ signal?.addEventListener("abort", done, { once: true });
18
+ });
19
+ }
20
+ function createScopeReader(input) {
21
+ const containerIds = new Set(collectSubtreeLeafFirst(input.containersById, input.rootContainerId).map((containerState) => containerState.container.id));
22
+ let documentLocalIds = null;
23
+ // Listing the subtree's documents is the costly read, so it runs only once
24
+ // some document placement is queued anywhere on this device.
25
+ const readDocumentLocalIds = () => {
26
+ documentLocalIds ??= listDocumentsByContainerIdsOrDocumentIds(input.execSql, { containerIds: [...containerIds], documentIds: [] }).then((documents) => new Set(documents.map((document) => document.id)));
27
+ return documentLocalIds;
28
+ };
29
+ return async () => {
30
+ const moves = await input.persistence.listUnsyncedMoveIntents(input.execSql);
31
+ const placements = await listDocumentPlacementIntentStates(input.execSql);
32
+ const scoped = moves.filter((move) => containerIds.has(move.containerId));
33
+ if (placements.length === 0)
34
+ return scoped;
35
+ const localIds = await readDocumentLocalIds();
36
+ return [
37
+ ...scoped,
38
+ ...placements.filter((placement) => localIds.has(placement.localId)),
39
+ ];
40
+ };
41
+ }
42
+ const isParked = (intent) => !REPLAYED_STATUSES.has(intent.syncStatus);
43
+ /** Why a wait that began at `startedAt` must stop, or null to keep polling. */
44
+ function stopReason(input) {
45
+ const { intents, lane, startedAt } = input;
46
+ if (intents.some(isParked))
47
+ return {
48
+ error: new Error("Purge scope move was parked"),
49
+ message: "Container contents: a move in the purge scope was parked",
50
+ };
51
+ if (startedAt !== null &&
52
+ intents.some(({ lastAttemptedAt }) => lastAttemptedAt !== null && lastAttemptedAt >= startedAt))
53
+ return {
54
+ error: new Error("Purge scope move failed to sync"),
55
+ message: "Container contents: a move in the purge scope failed to sync",
56
+ };
57
+ if (startedAt !== null && lane && !lane.running && !lane.requested)
58
+ return {
59
+ error: new Error("Purge scope move stayed queued"),
60
+ message: "Container contents: a sync pass left a purge scope move queued",
61
+ };
62
+ if (Date.now() >= input.deadline)
63
+ return {
64
+ error: new Error("Purge scope move wait timed out"),
65
+ message: "Container contents: purge timed out waiting for a move",
66
+ };
67
+ return null;
68
+ }
69
+ /**
70
+ * The purge scope refuses a subtree whose moves the server has not accepted,
71
+ * so ask for a pass that replays them and wait for its verdict. The scope's
72
+ * own checks still run afterwards; this only gives the moves time to land.
73
+ * It ends unsettled once a pass requested here has tried and left one queued.
74
+ */
75
+ export async function settlePurgeScopeMoves(input) {
76
+ const timing = input.timing ?? DEFAULT_TIMING;
77
+ const cancelled = () => input.signal?.aborted === true || !input.stillCurrent();
78
+ const unsettled = (reason) => {
79
+ input.report(reason.message, reason.error);
80
+ input.onMoveSettlement?.("unsettled");
81
+ return "unsettled";
82
+ };
83
+ const readScope = createScopeReader(input);
84
+ let intents = await readScope();
85
+ if (cancelled())
86
+ return "cancelled";
87
+ if (intents.length === 0)
88
+ return "settled";
89
+ if (intents.some(isParked))
90
+ return unsettled({
91
+ error: new Error("Purge scope holds a parked move"),
92
+ message: "Container contents: purge scope holds a parked move",
93
+ });
94
+ input.onMoveSettlement?.("waiting");
95
+ const runCountAtRequest = input.lane.read()?.runCount ?? 0;
96
+ input.lane.request();
97
+ const deadline = Date.now() + timing.timeoutMs;
98
+ let startedAt = null;
99
+ while (true) {
100
+ await delay(timing.pollMs, input.signal);
101
+ if (cancelled())
102
+ return "cancelled";
103
+ // Read the lane first: a row still queued after a pass it shows finished
104
+ // survived that pass, while one read before could have settled since.
105
+ const lane = input.lane.read();
106
+ intents = await readScope();
107
+ if (cancelled())
108
+ return "cancelled";
109
+ if (intents.length === 0)
110
+ return "settled";
111
+ // Only a pass that starts after the request answers it.
112
+ if (lane && lane.runCount > runCountAtRequest)
113
+ startedAt ??= lane.lastStartedAt;
114
+ const reason = stopReason({ deadline, intents, lane, startedAt });
115
+ if (reason)
116
+ return unsettled(reason);
117
+ }
118
+ }
119
+ //# sourceMappingURL=purgeMoveSettlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purgeM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AAC,QAAQ,GAAG,iBAAiB;YAC3C,SAAS,KAAK,IAAI,CAAC,aAAa,CAAC;QACnC,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAClE,IAAI,MAAM;YAAE,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { listDocumentPlacementIntentStates } from \"../../../../data/persistence/container-contents/documentPurgePlacement\";\nimport { listDocumentsByContainerIdsOrDocumentIds } from \"../../../../data/persistence/documents/documentsPersistence\";\nimport type { ExecSql } from \"../../../../data/sqlite/sqlSchema\";\nimport type { ContainerContentsPersistence } from \"../../containerPersistence\";\nimport type { ContainerState } from \"../../remoteHydration\";\nimport type { PurgeMoveSettlement } from \"./purgeProgress\";\nimport { collectSubtreeLeafFirst } from \"./purgeTreeCollection\";\n\n/** The container-contents lane replays queued container and document moves. */\nexport interface PurgeMoveSyncLane {\n readonly read: () => {\n readonly lastStartedAt: string | null;\n readonly requested: boolean;\n readonly runCount: number;\n readonly running: boolean;\n } | null;\n readonly request: () => void;\n}\n\ninterface ScopedIntent {\n readonly lastAttemptedAt: string | null;\n readonly syncStatus: string;\n}\n\ninterface SettlePurgeScopeMovesInput {\n readonly containersById: ReadonlyMap<string, ContainerState>;\n readonly execSql: ExecSql;\n readonly lane: PurgeMoveSyncLane;\n readonly onMoveSettlement?:\n | ((settlement: PurgeMoveSettlement) => void)\n | undefined;\n readonly persistence: Pick<\n ContainerContentsPersistence,\n \"listUnsyncedMoveIntents\"\n >;\n /** Fixed messages only: the error's call site names the outcome. */\n readonly report: (message: string, error: Error) => void;\n readonly rootContainerId: string;\n readonly signal?: AbortSignal | undefined;\n readonly stillCurrent: () => boolean;\n readonly timing?: { pollMs: number; timeoutMs: number } | undefined;\n}\n\n// A pass replays pending and blocked moves. A denied placement waits for the\n// next store generation and an unavailable one never replays, so waiting on\n// either would only reach the ceiling.\nconst REPLAYED_STATUSES = new Set([\"pending\", \"blocked\"]);\nconst DEFAULT_TIMING = { pollMs: 200, timeoutMs: 30_000 };\n\nfunction delay(ms: number, signal: AbortSignal | undefined): Promise<void> {\n return new Promise((resolve) => {\n const timer = setTimeout(done, ms);\n function done() {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", done);\n resolve();\n }\n signal?.addEventListener(\"abort\", done, { once: true });\n });\n}\n\nfunction createScopeReader(input: SettlePurgeScopeMovesInput) {\n const containerIds = new Set(\n collectSubtreeLeafFirst(input.containersById, input.rootContainerId).map(\n (containerState) => containerState.container.id,\n ),\n );\n let documentLocalIds: Promise<Set<string>> | null = null;\n // Listing the subtree's documents is the costly read, so it runs only once\n // some document placement is queued anywhere on this device.\n const readDocumentLocalIds = () => {\n documentLocalIds ??= listDocumentsByContainerIdsOrDocumentIds(\n input.execSql,\n { containerIds: [...containerIds], documentIds: [] },\n ).then((documents) => new Set(documents.map((document) => document.id)));\n return documentLocalIds;\n };\n return async (): Promise<ScopedIntent[]> => {\n const moves = await input.persistence.listUnsyncedMoveIntents(\n input.execSql,\n );\n const placements = await listDocumentPlacementIntentStates(input.execSql);\n const scoped: ScopedIntent[] = moves.filter((move) =>\n containerIds.has(move.containerId),\n );\n if (placements.length === 0) return scoped;\n const localIds = await readDocumentLocalIds();\n return [\n ...scoped,\n ...placements.filter((placement) => localIds.has(placement.localId)),\n ];\n };\n}\n\ntype LaneRun = ReturnType<PurgeMoveSyncLane[\"read\"]>;\n\nconst isParked = (intent: ScopedIntent) =>\n !REPLAYED_STATUSES.has(intent.syncStatus);\n\n/** Why a wait that began at `startedAt` must stop, or null to keep polling. */\nfunction stopReason(input: {\n deadline: number;\n intents: readonly ScopedIntent[];\n lane: LaneRun;\n startedAt: string | null;\n}): { error: Error; message: string } | null {\n const { intents, lane, startedAt } = input;\n if (intents.some(isParked))\n return {\n error: new Error(\"Purge scope move was parked\"),\n message: \"Container contents: a move in the purge scope was parked\",\n };\n if (\n startedAt !== null &&\n intents.some(\n ({ lastAttemptedAt }) =>\n lastAttemptedAt !== null && lastAttemptedAt >= startedAt,\n )\n )\n return {\n error: new Error(\"Purge scope move failed to sync\"),\n message: \"Container contents: a move in the purge scope failed to sync\",\n };\n if (startedAt !== null && lane && !lane.running && !lane.requested)\n return {\n error: new Error(\"Purge scope move stayed queued\"),\n message: \"Container contents: a sync pass left a purge scope move queued\",\n };\n if (Date.now() >= input.deadline)\n return {\n error: new Error(\"Purge scope move wait timed out\"),\n message: \"Container contents: purge timed out waiting for a move\",\n };\n return null;\n}\n\n/**\n * The purge scope refuses a subtree whose moves the server has not accepted,\n * so ask for a pass that replays them and wait for its verdict. The scope's\n * own checks still run afterwards; this only gives the moves time to land.\n * It ends unsettled once a pass requested here has tried and left one queued.\n */\nexport async function settlePurgeScopeMoves(\n input: SettlePurgeScopeMovesInput,\n): Promise<\"cancelled\" | \"settled\" | \"unsettled\"> {\n const timing = input.timing ?? DEFAULT_TIMING;\n const cancelled = () =>\n input.signal?.aborted === true || !input.stillCurrent();\n const unsettled = (reason: { error: Error; message: string }) => {\n input.report(reason.message, reason.error);\n input.onMoveSettlement?.(\"unsettled\");\n return \"unsettled\" as const;\n };\n const readScope = createScopeReader(input);\n let intents = await readScope();\n if (cancelled()) return \"cancelled\";\n if (intents.length === 0) return \"settled\";\n if (intents.some(isParked))\n return unsettled({\n error: new Error(\"Purge scope holds a parked move\"),\n message: \"Container contents: purge scope holds a parked move\",\n });\n\n input.onMoveSettlement?.(\"waiting\");\n const runCountAtRequest = input.lane.read()?.runCount ?? 0;\n input.lane.request();\n const deadline = Date.now() + timing.timeoutMs;\n let startedAt: string | null = null;\n while (true) {\n await delay(timing.pollMs, input.signal);\n if (cancelled()) return \"cancelled\";\n // Read the lane first: a row still queued after a pass it shows finished\n // survived that pass, while one read before could have settled since.\n const lane = input.lane.read();\n intents = await readScope();\n if (cancelled()) return \"cancelled\";\n if (intents.length === 0) return \"settled\";\n // Only a pass that starts after the request answers it.\n if (lane && lane.runCount > runCountAtRequest)\n startedAt ??= lane.lastStartedAt;\n const reason = stopReason({ deadline, intents, lane, startedAt });\n if (reason) return unsettled(reason);\n }\n}\n"]}
@@ -3,7 +3,15 @@ export interface PurgeProgress {
3
3
  readonly failedCount: number;
4
4
  readonly totalCount: number;
5
5
  }
6
+ /**
7
+ * A purge first waits for moves this device queued inside its scope: until the
8
+ * server holds them, the scope cannot prove what it would destroy. "waiting"
9
+ * reports the wait; "unsettled" means it ended before every move reached the
10
+ * server, and nothing was deleted.
11
+ */
12
+ export type PurgeMoveSettlement = "waiting" | "unsettled";
6
13
  export interface PurgeOptions {
14
+ onMoveSettlement?: ((settlement: PurgeMoveSettlement) => void) | undefined;
7
15
  onProgress?: ((progress: PurgeProgress) => void) | undefined;
8
16
  signal?: AbortSignal | undefined;
9
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"purgeProgress.js","sourceRoot":"","sources":["purgeProgress.ts"],"names":[],"mappings":"","sourcesContent":["// Progress + cancellation contract shared by the recursive purge engine and its\n// store wrappers (\"Delete Forever\" and \"Empty Trash\"). onProgress reports\n// ABSOLUTE counts (not deltas) so a determinate progress bar can render\n// completed/total directly; a fresh object is emitted each tick so a\n// referential-equality state setter never drops an update. signal cancels at the\n// next unit boundary — between whole documents / whole containers, never\n// mid-remote-call — so a cancelled run always stops on a consistent prefix that\n// re-running can safely resume.\nexport interface PurgeProgress {\n readonly completedCount: number;\n readonly failedCount: number;\n readonly totalCount: number;\n}\n\nexport interface PurgeOptions {\n onProgress?: ((progress: PurgeProgress) => void) | undefined;\n signal?: AbortSignal | undefined;\n}\n"]}
1
+ {"version":3,"file":"purgeProgress.js","sourceRoot":"","sources":["purgeProgress.ts"],"names":[],"mappings":"","sourcesContent":["// Progress + cancellation contract shared by the recursive purge engine and its\n// store wrappers (\"Delete Forever\" and \"Empty Trash\"). onProgress reports\n// ABSOLUTE counts (not deltas) so a determinate progress bar can render\n// completed/total directly; a fresh object is emitted each tick so a\n// referential-equality state setter never drops an update. signal cancels at the\n// next unit boundary — between whole documents / whole containers, never\n// mid-remote-call — so a cancelled run always stops on a consistent prefix that\n// re-running can safely resume.\nexport interface PurgeProgress {\n readonly completedCount: number;\n readonly failedCount: number;\n readonly totalCount: number;\n}\n\n/**\n * A purge first waits for moves this device queued inside its scope: until the\n * server holds them, the scope cannot prove what it would destroy. \"waiting\"\n * reports the wait; \"unsettled\" means it ended before every move reached the\n * server, and nothing was deleted.\n */\nexport type PurgeMoveSettlement = \"waiting\" | \"unsettled\";\n\nexport interface PurgeOptions {\n onMoveSettlement?: ((settlement: PurgeMoveSettlement) => void) | undefined;\n onProgress?: ((progress: PurgeProgress) => void) | undefined;\n signal?: AbortSignal | undefined;\n}\n"]}
@@ -116,6 +116,7 @@ export async function moveRemoteContainer(input) {
116
116
  containerId: input.containerId,
117
117
  destinationParentContainerId: input.parentContainerId,
118
118
  execSql,
119
+ onStaleAcceptance: input.onStaleAcceptance,
119
120
  resolveProjectionUserKey: input.resolveProjectionUserKey,
120
121
  stillCurrent: input.stillCurrent,
121
122
  targetSecretKey,