@tearleads/client-sdk 0.1.234 → 0.1.236
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/containerContents/documentDiscovery.js +1 -1
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/client/organizations/index.js +1 -1
- package/client/organizations/index.js.map +1 -1
- package/client/organizations/organizationMemberships.d.ts +6 -5
- package/client/organizations/organizationMemberships.js +12 -69
- package/client/organizations/organizationMemberships.js.map +1 -1
- package/client/runtime/workflowRuntime.js +5 -1
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +0 -45
- package/data/sqlite/schema/organizationSyncPauseSchema.js +6 -17
- package/data/sqlite/schema/organizationSyncPauseSchema.js.map +1 -1
- package/data/sync/organizationSyncPauseReadMachine.js +29 -0
- package/data/sync/organizationSyncPauseReadMachine.js.map +1 -0
- package/data/sync/organizationSyncPauses.d.ts +23 -34
- package/data/sync/organizationSyncPauses.js +49 -57
- package/data/sync/organizationSyncPauses.js.map +1 -1
- package/internal/validators/operation/organizationMemberships.d.ts +3 -21
- package/internal/validators/operation/organizationMemberships.js +2 -3
- package/internal/validators/operation/organizationMemberships.js.map +1 -1
- package/internal/validators/response/organizationMembership.d.ts +3 -3
- package/internal/validators/response/organizationMembership.js +3 -3
- package/internal/validators/response/organizationMembership.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +1 -1
- package/stores/container-contents/containerContentsStore.js +0 -2
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/syncAgent/index.js +6 -0
- package/stores/container-contents/syncAgent/index.js.map +1 -1
- package/stores/container-contents/types.d.ts +0 -6
- package/stores/container-contents/types.js.map +1 -1
- package/stores/documents/documentStore/index.js +3 -4
- package/stores/documents/documentStore/index.js.map +1 -1
- package/stores/documents/documentStore/initialization/index.js +7 -7
- package/stores/documents/documentStore/initialization/index.js.map +1 -1
- package/stores/documents/documentStore/sync/index.js +2 -5
- package/stores/documents/documentStore/sync/index.js.map +1 -1
- package/stores/documents/documentStore/sync/syncRequest.js +9 -2
- package/stores/documents/documentStore/sync/syncRequest.js.map +1 -1
- package/stores/documents/registry.d.ts +1 -34
- package/stores/documents/registry.js +4 -78
- package/stores/documents/registry.js.map +1 -1
- package/workflows/container-contents/container-state/create/createIntentRefusal.js +23 -0
- package/workflows/container-contents/container-state/create/createIntentRefusal.js.map +1 -0
- package/workflows/container-contents/container-state/create/createIntentSync.js +3 -8
- package/workflows/container-contents/container-state/create/createIntentSync.js.map +1 -1
- package/workflows/container-contents/container-state/move/moveIntentRefusal.js +23 -0
- package/workflows/container-contents/container-state/move/moveIntentRefusal.js.map +1 -0
- package/workflows/container-contents/container-state/move/moveIntentSync.js +3 -9
- package/workflows/container-contents/container-state/move/moveIntentSync.js.map +1 -1
- package/workflows/container-contents/documentMove/documentMoveBillingPause.js +19 -0
- package/workflows/container-contents/documentMove/documentMoveBillingPause.js.map +1 -0
- package/workflows/container-contents/documentMove/documentMoveIntentSync.js +12 -0
- package/workflows/container-contents/documentMove/documentMoveIntentSync.js.map +1 -1
- package/workflows/container-contents/metadata/metadataRemoteSync.js +1 -0
- package/workflows/container-contents/metadata/metadataRemoteSync.js.map +1 -1
- package/workflows/container-contents/remoteHydration/index.js +1 -1
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/organizationSyncPauseFilter.js +2 -4
- package/workflows/container-contents/remoteHydration/remoteContainers/organizationSyncPauseFilter.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +3 -3
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/syncPause/discoveryGuard.js +7 -6
- package/workflows/container-contents/syncPause/discoveryGuard.js.map +1 -1
- package/workflows/documents/remote/remoteDocumentCollaborators.d.ts +6 -2
- package/workflows/documents/remote/remoteDocumentCollaborators.js.map +1 -1
- package/workflows/documents/sync/index.js +8 -0
- package/workflows/documents/sync/index.js.map +1 -1
- package/workflows/documents/sync/readOnlySync.js +6 -0
- package/workflows/documents/sync/readOnlySync.js.map +1 -1
- package/workflows/documents/sync/remoteDocumentSyncPass.d.ts +7 -1
- package/workflows/documents/sync/remoteDocumentSyncPass.js.map +1 -1
- package/workflows/documents/sync/syncAttemptPlanning.js +24 -8
- package/workflows/documents/sync/syncAttemptPlanning.js.map +1 -1
- package/workflows/documents/syncFailures/index.js +6 -3
- package/workflows/documents/syncFailures/index.js.map +1 -1
- package/workflows/documents/syncFailures/syncAbandon.js +21 -0
- package/workflows/documents/syncFailures/syncAbandon.js.map +1 -1
- package/workflows/organizations/index.d.ts +1 -1
- package/workflows/organizations/index.js +1 -1
- package/workflows/organizations/index.js.map +1 -1
- package/workflows/organizations/memberships/organizationMemberships.d.ts +10 -35
- package/workflows/organizations/memberships/organizationMemberships.js +27 -44
- package/workflows/organizations/memberships/organizationMemberships.js.map +1 -1
- package/workflows/shared/runtimeInput.d.ts +11 -1
- package/workflows/shared/runtimeInput.js.map +1 -1
- package/workflows/sync/coordination.d.ts +1 -1
- package/workflows/sync/coordination.js +1 -1
- package/workflows/sync/coordination.js.map +1 -1
- package/workflows/sync/index.d.ts +1 -1
- package/workflows/sync/index.js +1 -1
- package/workflows/sync/index.js.map +1 -1
- package/data/persistence/container-contents/exclusiveDocumentPlacements.js +0 -61
- package/data/persistence/container-contents/exclusiveDocumentPlacements.js.map +0 -1
- package/stores/container-contents/operations/forgetOrganizationContentOperation.js +0 -76
- package/stores/container-contents/operations/forgetOrganizationContentOperation.js.map +0 -1
- package/stores/documents/removedDocumentStore.js +0 -40
- package/stores/documents/removedDocumentStore.js.map +0 -1
- package/workflows/container-contents/syncPause/documentRemoval.js +0 -165
- package/workflows/container-contents/syncPause/documentRemoval.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncAbandon.js","sourceRoot":"","sources":["sync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wB,CAC5C,KAAyB,EACzB,KAAY;IAEZ,MAAM,OAAO,GAA8B;QACzC,IAAI,EAAE,iCAAiC;QACvC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,IAAI;KACb,CAAC;IACF,MAAM,KAAK,CAAC,uBAAuB,EAAE,CAAC,OAAO,CAAC,CAAC;IAC/C,KAAK,CAAC,eAAe,EAAE,CACrB,mEAAmE,CACpE,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ContainerKekRepairInaccessibleError } from \"../../../data/documents/shared/containerKek/containerKekCurrency\";\nimport type { DocumentSyncSubmitFailure } from \"../../../data/documents/shared/sync/syncSubmitFailure\";\nimport type { RemoteDocumentSyncPass } from \"../sync/remoteDocumentSyncPass\";\nimport { traceAncestorRepairAbandoned } from \"../sync/syncTrace\";\nimport { DocumentAncestorRepairAbandonedError } from \"./syncRepairAbandon\";\n\n/** The ways a sync pass gives up without failing: writes stay queued. */\ntype AbandonedSyncInput = Pick<\n RemoteDocumentSyncPass,\n \"documentId\" | \"onSyncAbandoned\" | \"onSyncTrace\" | \"onTerminalSubmitFailure\"\n>;\n\nexport function abandonBlockedSync(input: AbandonedSyncInput): null {\n input.onSyncTrace?.(`document sync blocked document=${input.documentId}`);\n input.onSyncAbandoned?.(\"blocked\");\n return null;\n}\n\nexport function abandonAncestorRepair(\n input: AbandonedSyncInput,\n error: DocumentAncestorRepairAbandonedError,\n): null {\n // Trace as well as abandon: the store's onSyncAbandoned only parks the\n // document, and this path may already have issued server-side rekeys, so\n // abandoning untraced would leave a retrying loop with no way to see it.\n traceAncestorRepairAbandoned(input.onSyncTrace, {\n documentId: input.documentId,\n reason: error.reason,\n });\n input.onSyncAbandoned?.(error.reason);\n return null;\n}\n\n/**\n * The stale ancestor is one this writer can neither re-key nor be given the\n * key for, and one refetch has already confirmed nobody repaired it yet. The\n * writes stay queued; the durable row tells the write queue why, and the\n * dependent-path hint that follows the repair re-arms the pass.\n */\nexport async function abandonInaccessibleAncestorRepair(\n input: AbandonedSyncInput,\n error: ContainerKekRepairInaccessibleError,\n): Promise<null> {\n await input.onTerminalSubmitFailure?.({\n code: \"document_ancestor_repair_inaccessible\",\n message: error.message,\n ok: false,\n report: () => undefined,\n status: null,\n });\n return abandonAncestorRepair(\n input,\n new DocumentAncestorRepairAbandonedError(\"inaccessible\"),\n );\n}\n\nexport function abandonAfterRetryableConflicts(\n input: AbandonedSyncInput,\n): null {\n input.onSyncAbandoned?.(\"every sync attempt hit a retryable conflict\");\n return null;\n}\n\nexport async function abandonOversizedSyncPlan(\n input: AbandonedSyncInput,\n error: Error,\n): Promise<null> {\n const failure: DocumentSyncSubmitFailure = {\n code: \"document_sync_request_too_large\",\n message: error.message,\n ok: false,\n report: () => undefined,\n status: null,\n };\n await input.onTerminalSubmitFailure?.(failure);\n input.onSyncAbandoned?.(\n \"a queued update cannot fit within the document sync request limit\",\n );\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"syncAbandon.js","sourceRoot":"","sources":["syncAbandon.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAQ3E;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,KAGC;IAED,OAAO,CACL,KAAK,CAAC,gBAAgB,KAAK,SAAS,IAAI,KAAK,CAAC,oBAAoB,KAAK,IAAI,CAC5E,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAOC,EACD,cAAsB;IAEtB,OAAO,CACL,KAAK,CAAC,WAAW,KAAK,KAAK;QAC3B,CAAC,cAAc,CAAC,KAAK,CAAC;QACtB,KAAK,CAAC,MAAM,KAAK,SAAS;QAC1B,CAAC,KAAK,CAAC,mBAAmB,EAAE,CA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IAAI,EAAE,iCAAiC;QACvC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,IAAI;KACb,CAAC;IACF,MAAM,KAAK,CAAC,uBAAuB,EAAE,CAAC,OAAO,CAAC,CAAC;IAC/C,KAAK,CAAC,eAAe,EAAE,CACrB,mEAAmE,CACpE,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ContainerKekRepairInaccessibleError } from \"../../../data/documents/shared/containerKek/containerKekCurrency\";\nimport type { DocumentSyncSubmitFailure } from \"../../../data/documents/shared/sync/syncSubmitFailure\";\nimport type { RemoteDocumentSyncPass } from \"../sync/remoteDocumentSyncPass\";\nimport { traceAncestorRepairAbandoned } from \"../sync/syncTrace\";\nimport { DocumentAncestorRepairAbandonedError } from \"./syncRepairAbandon\";\n\n/** The ways a sync pass gives up without failing: writes stay queued. */\ntype AbandonedSyncInput = Pick<\n RemoteDocumentSyncPass,\n \"documentId\" | \"onSyncAbandoned\" | \"onSyncTrace\" | \"onTerminalSubmitFailure\"\n>;\n\n/**\n * Whether the pass finishes a pull that already fetched a page: it resumes\n * from a cursor, or restarts after its cursor expired.\n */\nexport function isPullUnderWay(\n input: Pick<\n RemoteDocumentSyncPass,\n \"pullContinuation\" | \"pullRecoveryRequired\"\n >,\n): boolean {\n return (\n input.pullContinuation !== undefined || input.pullRecoveryRequired === true\n );\n}\n\n/**\n * Whether a held organization stops this read-only pass. Only the start of a\n * routine pull of a document the device has already pulled is held. A first\n * pull still runs, so a document the device has listed can still be opened;\n * a pull that has fetched a page runs to its end, first pull or not, even\n * when an expired cursor makes it start over, so no document is left half\n * pulled; and so does an explicit read of raw history.\n */\nexport function isRoutinePullHeld(\n input: Pick<\n RemoteDocumentSyncPass,\n | \"historyMode\"\n | \"isRemoteSyncBlocked\"\n | \"minLsn\"\n | \"pullContinuation\"\n | \"pullRecoveryRequired\"\n >,\n organizationId: string,\n): boolean {\n return (\n input.historyMode !== \"raw\" &&\n !isPullUnderWay(input) &&\n input.minLsn !== undefined &&\n (input.isRemoteSyncBlocked?.(organizationId, \"pull\") ?? false)\n );\n}\n\nexport function abandonBlockedSync(input: AbandonedSyncInput): null {\n input.onSyncTrace?.(`document sync blocked document=${input.documentId}`);\n input.onSyncAbandoned?.(\"blocked\");\n return null;\n}\n\nexport function abandonAncestorRepair(\n input: AbandonedSyncInput,\n error: DocumentAncestorRepairAbandonedError,\n): null {\n // Trace as well as abandon: the store's onSyncAbandoned only parks the\n // document, and this path may already have issued server-side rekeys, so\n // abandoning untraced would leave a retrying loop with no way to see it.\n traceAncestorRepairAbandoned(input.onSyncTrace, {\n documentId: input.documentId,\n reason: error.reason,\n });\n input.onSyncAbandoned?.(error.reason);\n return null;\n}\n\n/**\n * The stale ancestor is one this writer can neither re-key nor be given the\n * key for, and one refetch has already confirmed nobody repaired it yet. The\n * writes stay queued; the durable row tells the write queue why, and the\n * dependent-path hint that follows the repair re-arms the pass.\n */\nexport async function abandonInaccessibleAncestorRepair(\n input: AbandonedSyncInput,\n error: ContainerKekRepairInaccessibleError,\n): Promise<null> {\n await input.onTerminalSubmitFailure?.({\n code: \"document_ancestor_repair_inaccessible\",\n message: error.message,\n ok: false,\n report: () => undefined,\n status: null,\n });\n return abandonAncestorRepair(\n input,\n new DocumentAncestorRepairAbandonedError(\"inaccessible\"),\n );\n}\n\nexport function abandonAfterRetryableConflicts(\n input: AbandonedSyncInput,\n): null {\n input.onSyncAbandoned?.(\"every sync attempt hit a retryable conflict\");\n return null;\n}\n\nexport async function abandonOversizedSyncPlan(\n input: AbandonedSyncInput,\n error: Error,\n): Promise<null> {\n const failure: DocumentSyncSubmitFailure = {\n code: \"document_sync_request_too_large\",\n message: error.message,\n ok: false,\n report: () => undefined,\n status: null,\n };\n await input.onTerminalSubmitFailure?.(failure);\n input.onSyncAbandoned?.(\n \"a queued update cannot fit within the document sync request limit\",\n );\n return null;\n}\n"]}
|
|
@@ -9,7 +9,7 @@ export { GroupShareNameMismatchError, shareRemoteContainerWithGroup, } from "./g
|
|
|
9
9
|
export { deleteOrganizationGroup } from "./groups/deleteOrganizationGroup.js";
|
|
10
10
|
export { type OrganizationLeaveRequestResult, setOrganizationLeaveRequested, } from "./memberships/leaveRequest.js";
|
|
11
11
|
export { withVerifiedDirectoryUser, withVerifiedLeaveRequests, withVerifiedUserLeaveRequest, } from "./memberships/leaveRequestVerification.js";
|
|
12
|
-
export {
|
|
12
|
+
export { type OrganizationContentHost, type OrganizationMembership, type OrganizationMembershipApi, type OrganizationSyncPauseResult, refreshOrganizationMemberships, setOrganizationSyncPaused, } from "./memberships/organizationMemberships.js";
|
|
13
13
|
export { buildOrganizationProfileDocumentPatch, createInitializedOrganizationProfileDocument, DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME, getOrganizationProfileDocumentLocalId, ORGANIZATION_PROFILE_DOCUMENT_KIND, readOrganizationProfileName, } from "./organizationProfile.js";
|
|
14
14
|
export { abandonJournaledPrincipalMutation, discardUnreadableJournaledPrincipalMutation, readJournaledPrincipalMutation, } from "./principalMutations/principalMutationJournalManagement.js";
|
|
15
15
|
export { type PrincipalMutationJournalContext, PrincipalMutationOutcomeUnknownError, recoverJournaledPrincipalMutation, submitJournaledPrincipalMutation, } from "./principalMutations/principalMutationJournalSession.js";
|
|
@@ -8,7 +8,7 @@ export { GroupShareNameMismatchError, shareRemoteContainerWithGroup, } from "./g
|
|
|
8
8
|
export { deleteOrganizationGroup } from "./groups/deleteOrganizationGroup.js";
|
|
9
9
|
export { setOrganizationLeaveRequested, } from "./memberships/leaveRequest.js";
|
|
10
10
|
export { withVerifiedDirectoryUser, withVerifiedLeaveRequests, withVerifiedUserLeaveRequest, } from "./memberships/leaveRequestVerification.js";
|
|
11
|
-
export {
|
|
11
|
+
export { refreshOrganizationMemberships, setOrganizationSyncPaused, } from "./memberships/organizationMemberships.js";
|
|
12
12
|
export { buildOrganizationProfileDocumentPatch, createInitializedOrganizationProfileDocument, DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME, getOrganizationProfileDocumentLocalId, ORGANIZATION_PROFILE_DOCUMENT_KIND, readOrganizationProfileName, } from "./organizationProfile.js";
|
|
13
13
|
export { abandonJournaledPrincipalMutation, discardUnreadableJournaledPrincipalMutation, readJournaledPrincipalMutation, } from "./principalMutations/principalMutationJournalManagement.js";
|
|
14
14
|
export { PrincipalMutationOutcomeUnknownError, recoverJournaledPrincipalMutation, submitJournaledPrincipalMutation, } from "./principalMutations/principalMutationJournalSession.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0CAA0C,GAC3C,MAAM,wEAAwE,CAAC;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAK3G,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,8BAA8B,EAC9B,mCAAmC,EACnC,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,EACvB,8BAA8B,EAC9B,oCAAoC,EACpC,yBAAyB,EAOzB,8BAA8B,EAG9B,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAEL,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,wCAAwC,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","s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EAC9B,oCAAoC,EACpC,uBAAuB,EACvB,2BAA2B,EAC3B,yCAAyC,GAC1C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mCAAmC,EAwBnC,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,8BAA8B,EAG9B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GAIvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,kCAAkC,EAClC,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,uCAAuC,EACvC,iCAAiC,EAEjC,uCAAuC,GACxC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,+BAA+B,EAC/B,sCAAsC,EACtC,6CAA6C,EAC7C,kDAAkD,EAClD,+BAA+B,EAC/B,oCAAoC,EACpC,0CAA0C,EAC1C,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC","sourcesContent":["export {\n type OrganizationReadModelInvalidationListener,\n subscribeOrganizationReadModelInvalidation,\n} from \"../../data/persistence/organizations/organizationReadModelInvalidation\";\nexport { PendingPrincipalMutationError } from \"../../data/persistence/principalMutationJournalPersistence\";\nexport type {\n AuthoredPrincipalMutation,\n PrincipalMutationJournalScope,\n} from \"../../data/principals/principalMutationJournal\";\nexport { UnreadablePrincipalMutationError } from \"../../data/principals/principalMutationJournalRecord\";\nexport {\n cancelStripeSubscription,\n changeStripePlan,\n checkNativePurchaseEligibility,\n claimNativeOrganizationSubscription,\n createStripeCheckout,\n createStripeCheckoutSession,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n loadStripeCheckoutOptions,\n type OrganizationBilling,\n type OrganizationBillingHistory,\n type OrganizationBillingHistoryEntry,\n type OrganizationBillingManagementUrl,\n type OrganizationBillingView,\n type OrganizationNativePurchaseEligibility,\n resolveOrganizationBillingView,\n type StripeCheckoutIntent,\n type StripeCheckoutOptions,\n startOrganizationTrial,\n} from \"./billing\";\nexport { revokeOrganizationContainerGrant } from \"./containerGrantRevocation\";\nexport { GroupMembershipNameMismatchError } from \"./groupNames/groupMembershipName\";\nexport {\n GroupShareNameMismatchError,\n shareRemoteContainerWithGroup,\n} from \"./groupShare\";\nexport { deleteOrganizationGroup } from \"./groups/deleteOrganizationGroup\";\nexport {\n type OrganizationLeaveRequestResult,\n setOrganizationLeaveRequested,\n} from \"./memberships/leaveRequest\";\nexport {\n withVerifiedDirectoryUser,\n withVerifiedLeaveRequests,\n withVerifiedUserLeaveRequest,\n} from \"./memberships/leaveRequestVerification\";\nexport {\n type OrganizationContentHost,\n type OrganizationMembership,\n type OrganizationMembershipApi,\n type OrganizationSyncPauseResult,\n refreshOrganizationMemberships,\n setOrganizationSyncPaused,\n} from \"./memberships/organizationMemberships\";\nexport {\n buildOrganizationProfileDocumentPatch,\n createInitializedOrganizationProfileDocument,\n DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME,\n getOrganizationProfileDocumentLocalId,\n ORGANIZATION_PROFILE_DOCUMENT_KIND,\n readOrganizationProfileName,\n} from \"./organizationProfile\";\nexport {\n abandonJournaledPrincipalMutation,\n discardUnreadableJournaledPrincipalMutation,\n readJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalManagement\";\nexport {\n type PrincipalMutationJournalContext,\n PrincipalMutationOutcomeUnknownError,\n recoverJournaledPrincipalMutation,\n submitJournaledPrincipalMutation,\n} from \"./principalMutations/principalMutationJournalSession\";\nexport type { PrincipalMutationResponse } from \"./principalMutations/principalOperationReceipt\";\nexport {\n type AcknowledgedPrincipalCurrentInput,\n type AcknowledgedPrincipalCurrentRetirement,\n retainAcknowledgedPrincipalCurrents,\n} from \"./principalMutations/retainAcknowledgedPrincipalCurrents\";\nexport {\n addOrganizationGroupUser,\n buildInitialGroupPolicyRequest,\n buildInitialMemberGroupPolicyRequest,\n createOrganizationGroup,\n removeOrganizationGroupUser,\n rotateOrganizationGroupForAccessSetShrink,\n} from \"./principalPolicy\";\nexport {\n buildOrganizationGroupPolicyHistory,\n type OrganizationContainerGrant,\n type OrganizationContainerGrants,\n type OrganizationDirectory,\n type OrganizationDirectoryAndGroups,\n type OrganizationDirectoryUser,\n type OrganizationGroupContainer,\n type OrganizationGroupContainers,\n type OrganizationGroupDetails,\n type OrganizationGroupMember,\n type OrganizationGroupMembers,\n type OrganizationGroupPolicyHistory,\n type OrganizationGroupPolicyHistoryEntry,\n type OrganizationGroupSummary,\n type OrganizationPolicyGrantChange,\n type OrganizationPolicyGroupChange,\n type OrganizationPolicyHistory,\n type OrganizationPolicyHistoryEntry,\n type OrganizationPrincipalMemberChange,\n type OrganizationPrincipalMemberChangeType,\n type OrganizationPrincipalPolicyHistory,\n type OrganizationPrincipalPolicyHistoryEntry,\n type OrganizationProfile,\n type OrganizationUserDetail,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n} from \"./readModel\";\nexport {\n loadLocalOrganizationDataUsage,\n type OrganizationDataUsage,\n type ReconcileOrganizationDataUsageInput,\n reconcileOrganizationDataUsage,\n} from \"./readModel/dataUsageReadModel\";\nexport {\n measureOrganizationDeviceDataUsage,\n ORGANIZATION_DOCUMENT_USAGE_CATEGORIES,\n type OrganizationDeviceDataUsage,\n type OrganizationDeviceDocumentUsageCategoryBreakdown,\n type OrganizationDocumentUsageCategory,\n} from \"./readModel/deviceDataUsage\";\nexport {\n type LocalOrganizationSummary,\n listLocalOrganizations,\n} from \"./readModel/listLocalOrganizations\";\nexport {\n loadLocalOrganizationContainerGrants,\n loadLocalOrganizationGroupContainers,\n loadLocalOrganizationGroupPolicyHistory,\n loadLocalOrganizationPolicyHistory,\n loadLocalOrganizationPolicyReference,\n loadLocalOrganizationUserDetail,\n} from \"./readModel/localReadModelDetails\";\nexport {\n loadLocalOrganizationDirectoryAndGroups,\n loadLocalOrganizationGroupMembers,\n type ReconcileOrganizationDirectoryAndGroupsInput,\n reconcileOrganizationDirectoryAndGroups,\n} from \"./readModel/readModelProjection\";\nexport {\n buildRosterProfileDocumentPatch,\n createInitializedRosterProfileDocument,\n deriveOrganizationMetadataContainerSystemSlot,\n deriveOrganizationRosterProfileContainerSystemSlot,\n getRosterProfileDocumentLocalId,\n ORGANIZATION_METADATA_CONTAINER_NAME,\n ORGANIZATION_ROSTER_PROFILE_CONTAINER_NAME,\n ROSTER_PROFILE_DOCUMENT_KIND,\n} from \"./rosterProfileContainer\";\n"]}
|
|
@@ -3,7 +3,6 @@ import type { UpdateOrganizationMembershipRequest } from "../../../internal/vali
|
|
|
3
3
|
import type { OrganizationMembershipResponse, OrganizationMembershipsResponse } from "../../../internal/validators/response/index.js";
|
|
4
4
|
import type { DomainScope } from "../../../data/shared/domainScope.js";
|
|
5
5
|
import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
|
|
6
|
-
import { type OrganizationSyncPauses } from "../../sync/coordination.js";
|
|
7
6
|
/** One organization the user belongs to, with their own choices for it. */
|
|
8
7
|
export type OrganizationMembership = OrganizationMembershipResponse;
|
|
9
8
|
export interface OrganizationMembershipApi {
|
|
@@ -11,27 +10,15 @@ export interface OrganizationMembershipApi {
|
|
|
11
10
|
updateOrganizationMembership(organizationId: string, input: UpdateOrganizationMembershipRequest): Promise<RequestResult<OrganizationMembershipResponse>>;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
* What applying a pause needs from the device's
|
|
15
|
-
* composition root to the
|
|
13
|
+
* What applying a pause or a resume needs from the device's sync. Wired by
|
|
14
|
+
* the composition root to the document reconciler and the sync lanes.
|
|
16
15
|
*/
|
|
17
16
|
export interface OrganizationContentHost {
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* an open store.
|
|
18
|
+
* Re-lists the whole tree and re-drives every sync lane, so a resumed
|
|
19
|
+
* organization fetches what it missed and sends the writes it held.
|
|
22
20
|
*/
|
|
23
|
-
|
|
24
|
-
/** Whether any local write for the organization has not uploaded yet. */
|
|
25
|
-
hasUnsyncedOrganizationWrites(organizationId: string): Promise<boolean>;
|
|
26
|
-
/** Asks every sync lane to upload now and waits briefly for them to idle. */
|
|
27
|
-
flushWrites(): Promise<void>;
|
|
28
|
-
/** Re-lists the whole tree so resumed organizations download again. */
|
|
29
|
-
refetchContent(): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Runs `retry` each time the scope's sync lanes go idle until it resolves
|
|
32
|
-
* true. A later call replaces the pending retry.
|
|
33
|
-
*/
|
|
34
|
-
retryWhenWritesSettle(retry: () => Promise<boolean>): void;
|
|
21
|
+
resumeSync(): Promise<void>;
|
|
35
22
|
}
|
|
36
23
|
interface OrganizationMembershipInput {
|
|
37
24
|
readonly apiClient: OrganizationMembershipApi;
|
|
@@ -48,34 +35,22 @@ interface OrganizationMembershipInput {
|
|
|
48
35
|
export type OrganizationSyncPauseResult = {
|
|
49
36
|
readonly status: "updated";
|
|
50
37
|
readonly membership: OrganizationMembership;
|
|
51
|
-
} | {
|
|
52
|
-
readonly status: "unsynced-writes";
|
|
53
38
|
} | {
|
|
54
39
|
readonly status: "failed";
|
|
55
40
|
readonly httpStatus: number | null;
|
|
56
41
|
readonly message: string;
|
|
57
42
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Removes the content of every paused organization that has nothing left to
|
|
60
|
-
* upload. An organization with pending or queued writes keeps syncing those
|
|
61
|
-
* out and is retried once the sync lanes go idle, so pausing never discards
|
|
62
|
-
* unsynced work and a removal does not wait for the next membership read.
|
|
63
|
-
*/
|
|
64
|
-
export declare function forgetPausedOrganizationContent(input: {
|
|
65
|
-
readonly host: OrganizationContentHost;
|
|
66
|
-
readonly pauses: OrganizationSyncPauses;
|
|
67
|
-
}): Promise<void>;
|
|
68
43
|
/**
|
|
69
44
|
* Reads the user's memberships and applies their pause choices, including
|
|
70
|
-
* ones made on another device: paused
|
|
71
|
-
* resumed
|
|
45
|
+
* ones made on another device: a paused organization's sync is held here, and
|
|
46
|
+
* a resumed one catches up. Returns null when the list is unavailable, in
|
|
72
47
|
* which case the persisted pauses stay in force.
|
|
73
48
|
*/
|
|
74
49
|
export declare function refreshOrganizationMemberships(input: OrganizationMembershipInput): Promise<OrganizationMembership[] | null>;
|
|
75
50
|
/**
|
|
76
|
-
* Pauses or resumes one organization
|
|
77
|
-
*
|
|
78
|
-
*
|
|
51
|
+
* Pauses or resumes one organization. Pausing holds its sync in both
|
|
52
|
+
* directions and keeps everything on the device: writes made meanwhile stay
|
|
53
|
+
* queued and send on resume, so nothing has to upload first.
|
|
79
54
|
*/
|
|
80
55
|
export declare function setOrganizationSyncPaused(input: OrganizationMembershipInput & {
|
|
81
56
|
readonly organizationId: string;
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import { getOrCreateOrganizationSyncPauses, } from "../../sync/coordination.js";
|
|
2
|
-
async function forgetEveryPausedOrganization(input) {
|
|
3
|
-
let complete = true;
|
|
4
|
-
for (const organizationId of [...input.pauses.pausedOrganizationIds()]) {
|
|
5
|
-
if (!(await input.host.forgetOrganizationContent(organizationId))) {
|
|
6
|
-
complete = false;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return complete;
|
|
10
|
-
}
|
|
11
2
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
3
|
+
* The pauses a membership list puts in force on this device. A pause follows
|
|
4
|
+
* the user to every device, except on their personal organization: a device
|
|
5
|
+
* holds that one only when it was paused from this device, because a new
|
|
6
|
+
* device needs it to start. Resuming always applies everywhere.
|
|
16
7
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
function pausesInForce(memberships, heldHere) {
|
|
9
|
+
return memberships.flatMap((membership) => membership.syncPaused &&
|
|
10
|
+
(!membership.isPersonalOrganizationOwner ||
|
|
11
|
+
heldHere.has(membership.organizationId))
|
|
12
|
+
? [membership.organizationId]
|
|
13
|
+
: []);
|
|
21
14
|
}
|
|
22
15
|
/**
|
|
23
16
|
* Reads the user's memberships and applies their pause choices, including
|
|
24
|
-
* ones made on another device: paused
|
|
25
|
-
* resumed
|
|
17
|
+
* ones made on another device: a paused organization's sync is held here, and
|
|
18
|
+
* a resumed one catches up. Returns null when the list is unavailable, in
|
|
26
19
|
* which case the persisted pauses stay in force.
|
|
27
20
|
*/
|
|
28
21
|
export async function refreshOrganizationMemberships(input) {
|
|
@@ -33,16 +26,16 @@ async function applyMembershipList(input, pauses) {
|
|
|
33
26
|
const response = await input.apiClient.listOrganizationMemberships();
|
|
34
27
|
if (!response || !input.isCurrent())
|
|
35
28
|
return null;
|
|
36
|
-
|
|
37
|
-
await
|
|
29
|
+
await pauses.load(input.execSql);
|
|
30
|
+
const change = await pauses.replace(input.execSql, pausesInForce(response.memberships, pauses.pausedOrganizationIds()));
|
|
38
31
|
if (change.resumed.length > 0)
|
|
39
|
-
await input.host.
|
|
32
|
+
await input.host.resumeSync();
|
|
40
33
|
return [...response.memberships];
|
|
41
34
|
}
|
|
42
35
|
/**
|
|
43
|
-
* Pauses or resumes one organization
|
|
44
|
-
*
|
|
45
|
-
*
|
|
36
|
+
* Pauses or resumes one organization. Pausing holds its sync in both
|
|
37
|
+
* directions and keeps everything on the device: writes made meanwhile stay
|
|
38
|
+
* queued and send on resume, so nothing has to upload first.
|
|
46
39
|
*/
|
|
47
40
|
export async function setOrganizationSyncPaused(input) {
|
|
48
41
|
const pauses = getOrCreateOrganizationSyncPauses(input.domainScope);
|
|
@@ -50,23 +43,15 @@ export async function setOrganizationSyncPaused(input) {
|
|
|
50
43
|
}
|
|
51
44
|
async function applySyncPauseChoice(input, pauses) {
|
|
52
45
|
const { host, organizationId, paused } = input;
|
|
53
|
-
const scopeEnded = {
|
|
54
|
-
httpStatus: null,
|
|
55
|
-
message: "The session changed before sync could be changed.",
|
|
56
|
-
status: "failed",
|
|
57
|
-
};
|
|
58
46
|
// Queued behind other membership work, the session may have switched
|
|
59
47
|
// identity; the shared API client would then act for the new identity.
|
|
60
|
-
if (!input.isCurrent())
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
48
|
+
if (!input.isCurrent()) {
|
|
49
|
+
return {
|
|
50
|
+
httpStatus: null,
|
|
51
|
+
message: "The session changed before sync could be changed.",
|
|
52
|
+
status: "failed",
|
|
53
|
+
};
|
|
67
54
|
}
|
|
68
|
-
if (!input.isCurrent())
|
|
69
|
-
return scopeEnded;
|
|
70
55
|
const result = await input.apiClient.updateOrganizationMembership(organizationId, { syncPaused: paused });
|
|
71
56
|
if (!result.ok) {
|
|
72
57
|
return {
|
|
@@ -85,11 +70,9 @@ async function applySyncPauseChoice(input, pauses) {
|
|
|
85
70
|
next.add(organizationId);
|
|
86
71
|
else
|
|
87
72
|
next.delete(organizationId);
|
|
88
|
-
await pauses.replace(input.execSql, next);
|
|
89
|
-
if (
|
|
90
|
-
await
|
|
91
|
-
else
|
|
92
|
-
await host.refetchContent();
|
|
73
|
+
const change = await pauses.replace(input.execSql, next);
|
|
74
|
+
if (change.resumed.length > 0)
|
|
75
|
+
await host.resumeSync();
|
|
93
76
|
return { membership: result.data, status: "updated" };
|
|
94
77
|
}
|
|
95
78
|
//# sourceMappingURL=organizationMemberships.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationMemberships.js","sourceRoot":"","sources":["organizationMemberships.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,iCAAiC,GAElC,MAAM,yBAAyB,CAAC;AA2DjC,KAAK,UAAU,6BAA6B,CAAC,KAG5C;IACC,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,KAAK,MAAM,cAAc,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC,EAAE,CAAC;QACvE,IAAI,CAAC,C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AE,EAAE,CAAC;QACf,OAAO;YACL,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,QAAQ;SACjB,CAAC;IACJ,CAAC;IACD,yEAAyE;IACzE,gCAAgC;IAChC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;QAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9E,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACrD,IAAI,MAAM;QAAE,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;;QAChC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACjC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,MAAM;QAAE,MAAM,+BAA+B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;;QAC/D,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IACjC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { UpdateOrganizationMembershipRequest } from \"@tearleads/validators/request\";\nimport type {\n OrganizationMembershipResponse,\n OrganizationMembershipsResponse,\n} from \"@tearleads/validators/response\";\nimport type { DomainScope } from \"../../../data/shared/domainScope\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n getOrCreateOrganizationSyncPauses,\n type OrganizationSyncPauses,\n} from \"../../sync/coordination\";\n\n/** One organization the user belongs to, with their own choices for it. */\nexport type OrganizationMembership = OrganizationMembershipResponse;\n\nexport interface OrganizationMembershipApi {\n listOrganizationMemberships(): Promise<OrganizationMembershipsResponse | null>;\n updateOrganizationMembership(\n organizationId: string,\n input: UpdateOrganizationMembershipRequest,\n ): Promise<RequestResult<OrganizationMembershipResponse>>;\n}\n\n/**\n * What applying a pause needs from the device's content. Wired by the\n * composition root to the container tree and the document sync lanes.\n */\nexport interface OrganizationContentHost {\n /**\n * Removes an organization's content, keeping its metadata root. Refuses,\n * returning false, while any of its writes is unsynced or still queued in\n * an open store.\n */\n forgetOrganizationContent(organizationId: string): Promise<boolean>;\n /** Whether any local write for the organization has not uploaded yet. */\n hasUnsyncedOrganizationWrites(organizationId: string): Promise<boolean>;\n /** Asks every sync lane to upload now and waits briefly for them to idle. */\n flushWrites(): Promise<void>;\n /** Re-lists the whole tree so resumed organizations download again. */\n refetchContent(): Promise<void>;\n /**\n * Runs `retry` each time the scope's sync lanes go idle until it resolves\n * true. A later call replaces the pending retry.\n */\n retryWhenWritesSettle(retry: () => Promise<boolean>): void;\n}\n\ninterface OrganizationMembershipInput {\n readonly apiClient: OrganizationMembershipApi;\n readonly domainScope: DomainScope;\n readonly execSql: ExecSql;\n readonly host: OrganizationContentHost;\n /**\n * Whether the session still uses `domainScope`. A membership list or pause\n * that completes after an identity switch must not touch the new identity's\n * device state.\n */\n readonly isCurrent: () => boolean;\n}\n\nexport type OrganizationSyncPauseResult =\n | { readonly status: \"updated\"; readonly membership: OrganizationMembership }\n | { readonly status: \"unsynced-writes\" }\n | {\n readonly status: \"failed\";\n readonly httpStatus: number | null;\n readonly message: string;\n };\n\nasync function forgetEveryPausedOrganization(input: {\n readonly host: OrganizationContentHost;\n readonly pauses: OrganizationSyncPauses;\n}): Promise<boolean> {\n let complete = true;\n for (const organizationId of [...input.pauses.pausedOrganizationIds()]) {\n if (!(await input.host.forgetOrganizationContent(organizationId))) {\n complete = false;\n }\n }\n return complete;\n}\n\n/**\n * Removes the content of every paused organization that has nothing left to\n * upload. An organization with pending or queued writes keeps syncing those\n * out and is retried once the sync lanes go idle, so pausing never discards\n * unsynced work and a removal does not wait for the next membership read.\n */\nexport async function forgetPausedOrganizationContent(input: {\n readonly host: OrganizationContentHost;\n readonly pauses: OrganizationSyncPauses;\n}): Promise<void> {\n if (await forgetEveryPausedOrganization(input)) return;\n input.host.retryWhenWritesSettle(() =>\n input.pauses.runExclusive(() => forgetEveryPausedOrganization(input)),\n );\n}\n\n/**\n * Reads the user's memberships and applies their pause choices, including\n * ones made on another device: paused organizations leave this device, and\n * resumed ones download again. Returns null when the list is unavailable, in\n * which case the persisted pauses stay in force.\n */\nexport async function refreshOrganizationMemberships(\n input: OrganizationMembershipInput,\n): Promise<OrganizationMembership[] | null> {\n const pauses = getOrCreateOrganizationSyncPauses(input.domainScope);\n return pauses.runExclusive(() => applyMembershipList(input, pauses));\n}\n\nasync function applyMembershipList(\n input: OrganizationMembershipInput,\n pauses: OrganizationSyncPauses,\n): Promise<OrganizationMembership[] | null> {\n const response = await input.apiClient.listOrganizationMemberships();\n if (!response || !input.isCurrent()) return null;\n const change = await pauses.replace(\n input.execSql,\n response.memberships.flatMap((membership) =>\n membership.syncPaused ? [membership.organizationId] : [],\n ),\n );\n await forgetPausedOrganizationContent({ host: input.host, pauses });\n if (change.resumed.length > 0) await input.host.refetchContent();\n return [...response.memberships];\n}\n\n/**\n * Pauses or resumes one organization for every device of this user. Pausing\n * first uploads this device's pending writes and is refused while any remain,\n * so the local copy it removes holds nothing the server lacks.\n */\nexport async function setOrganizationSyncPaused(\n input: OrganizationMembershipInput & {\n readonly organizationId: string;\n readonly paused: boolean;\n },\n): Promise<OrganizationSyncPauseResult> {\n const pauses = getOrCreateOrganizationSyncPauses(input.domainScope);\n return pauses.runExclusive(() => applySyncPauseChoice(input, pauses));\n}\n\nasync function applySyncPauseChoice(\n input: OrganizationMembershipInput & {\n readonly organizationId: string;\n readonly paused: boolean;\n },\n pauses: OrganizationSyncPauses,\n): Promise<OrganizationSyncPauseResult> {\n const { host, organizationId, paused } = input;\n const scopeEnded = {\n httpStatus: null,\n message: \"The session changed before sync could be changed.\",\n status: \"failed\",\n } as const;\n // Queued behind other membership work, the session may have switched\n // identity; the shared API client would then act for the new identity.\n if (!input.isCurrent()) return scopeEnded;\n if (paused) {\n await host.flushWrites();\n if (await host.hasUnsyncedOrganizationWrites(organizationId)) {\n return { status: \"unsynced-writes\" };\n }\n }\n if (!input.isCurrent()) return scopeEnded;\n const result = await input.apiClient.updateOrganizationMembership(\n organizationId,\n { syncPaused: paused },\n );\n if (!result.ok) {\n return {\n httpStatus: result.status,\n message: result.message,\n status: \"failed\",\n };\n }\n // The choice is recorded; a scope that ended meanwhile applies it on its\n // next membership read instead.\n if (!input.isCurrent()) return { membership: result.data, status: \"updated\" };\n await pauses.load(input.execSql);\n const next = new Set(pauses.pausedOrganizationIds());\n if (paused) next.add(organizationId);\n else next.delete(organizationId);\n await pauses.replace(input.execSql, next);\n if (paused) await forgetPausedOrganizationContent({ host, pauses });\n else await host.refetchContent();\n return { membership: result.data, status: \"updated\" };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organizationMemberships.js","sourceRoot":"","sources":["organizationMemberships.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,iCAAiC,GAElC,MAAM,yBAAyB,CAAC;AA8CjC;;;;;GAKG;AACH,SAAS,aAAa,CACpB,WAA8C,EAC9C,QAA6B;IAE7B,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CACxC,UAAU,CAAC,UAAU;QACrB,CAAC,CAAC,UAAU,CAAC,2BAA2B;YACtC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC;QAC7B,CAAC,CAAC,EAAE,CACP,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,KAAkC;IAElC,MAAM,MAAM,GAAG,iCAAiC,CAAC,KAAK,CAAC,WAA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AAI;YAChB,OAAO,EAAE,mDAAmD;YAC5D,MAAM,EAAE,QAAQ;SACjB,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,4BAA4B,CAC/D,cAAc,EACd,EAAE,UAAU,EAAE,MAAM,EAAE,CACvB,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,OAAO;YACL,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,QAAQ;SACjB,CAAC;IACJ,CAAC;IACD,yEAAyE;IACzE,gCAAgC;IAChC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;QAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC9E,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACrD,IAAI,MAAM;QAAE,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;;QAChC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IACvD,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { UpdateOrganizationMembershipRequest } from \"@tearleads/validators/request\";\nimport type {\n OrganizationMembershipResponse,\n OrganizationMembershipsResponse,\n} from \"@tearleads/validators/response\";\nimport type { DomainScope } from \"../../../data/shared/domainScope\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n getOrCreateOrganizationSyncPauses,\n type OrganizationSyncPauses,\n} from \"../../sync/coordination\";\n\n/** One organization the user belongs to, with their own choices for it. */\nexport type OrganizationMembership = OrganizationMembershipResponse;\n\nexport interface OrganizationMembershipApi {\n listOrganizationMemberships(): Promise<OrganizationMembershipsResponse | null>;\n updateOrganizationMembership(\n organizationId: string,\n input: UpdateOrganizationMembershipRequest,\n ): Promise<RequestResult<OrganizationMembershipResponse>>;\n}\n\n/**\n * What applying a pause or a resume needs from the device's sync. Wired by\n * the composition root to the document reconciler and the sync lanes.\n */\nexport interface OrganizationContentHost {\n /**\n * Re-lists the whole tree and re-drives every sync lane, so a resumed\n * organization fetches what it missed and sends the writes it held.\n */\n resumeSync(): Promise<void>;\n}\n\ninterface OrganizationMembershipInput {\n readonly apiClient: OrganizationMembershipApi;\n readonly domainScope: DomainScope;\n readonly execSql: ExecSql;\n readonly host: OrganizationContentHost;\n /**\n * Whether the session still uses `domainScope`. A membership list or pause\n * that completes after an identity switch must not touch the new identity's\n * device state.\n */\n readonly isCurrent: () => boolean;\n}\n\nexport type OrganizationSyncPauseResult =\n | { readonly status: \"updated\"; readonly membership: OrganizationMembership }\n | {\n readonly status: \"failed\";\n readonly httpStatus: number | null;\n readonly message: string;\n };\n\n/**\n * The pauses a membership list puts in force on this device. A pause follows\n * the user to every device, except on their personal organization: a device\n * holds that one only when it was paused from this device, because a new\n * device needs it to start. Resuming always applies everywhere.\n */\nfunction pausesInForce(\n memberships: readonly OrganizationMembership[],\n heldHere: ReadonlySet<string>,\n): string[] {\n return memberships.flatMap((membership) =>\n membership.syncPaused &&\n (!membership.isPersonalOrganizationOwner ||\n heldHere.has(membership.organizationId))\n ? [membership.organizationId]\n : [],\n );\n}\n\n/**\n * Reads the user's memberships and applies their pause choices, including\n * ones made on another device: a paused organization's sync is held here, and\n * a resumed one catches up. Returns null when the list is unavailable, in\n * which case the persisted pauses stay in force.\n */\nexport async function refreshOrganizationMemberships(\n input: OrganizationMembershipInput,\n): Promise<OrganizationMembership[] | null> {\n const pauses = getOrCreateOrganizationSyncPauses(input.domainScope);\n return pauses.runExclusive(() => applyMembershipList(input, pauses));\n}\n\nasync function applyMembershipList(\n input: OrganizationMembershipInput,\n pauses: OrganizationSyncPauses,\n): Promise<OrganizationMembership[] | null> {\n const response = await input.apiClient.listOrganizationMemberships();\n if (!response || !input.isCurrent()) return null;\n await pauses.load(input.execSql);\n const change = await pauses.replace(\n input.execSql,\n pausesInForce(response.memberships, pauses.pausedOrganizationIds()),\n );\n if (change.resumed.length > 0) await input.host.resumeSync();\n return [...response.memberships];\n}\n\n/**\n * Pauses or resumes one organization. Pausing holds its sync in both\n * directions and keeps everything on the device: writes made meanwhile stay\n * queued and send on resume, so nothing has to upload first.\n */\nexport async function setOrganizationSyncPaused(\n input: OrganizationMembershipInput & {\n readonly organizationId: string;\n readonly paused: boolean;\n },\n): Promise<OrganizationSyncPauseResult> {\n const pauses = getOrCreateOrganizationSyncPauses(input.domainScope);\n return pauses.runExclusive(() => applySyncPauseChoice(input, pauses));\n}\n\nasync function applySyncPauseChoice(\n input: OrganizationMembershipInput & {\n readonly organizationId: string;\n readonly paused: boolean;\n },\n pauses: OrganizationSyncPauses,\n): Promise<OrganizationSyncPauseResult> {\n const { host, organizationId, paused } = input;\n // Queued behind other membership work, the session may have switched\n // identity; the shared API client would then act for the new identity.\n if (!input.isCurrent()) {\n return {\n httpStatus: null,\n message: \"The session changed before sync could be changed.\",\n status: \"failed\",\n };\n }\n const result = await input.apiClient.updateOrganizationMembership(\n organizationId,\n { syncPaused: paused },\n );\n if (!result.ok) {\n return {\n httpStatus: result.status,\n message: result.message,\n status: \"failed\",\n };\n }\n // The choice is recorded; a scope that ended meanwhile applies it on its\n // next membership read instead.\n if (!input.isCurrent()) return { membership: result.data, status: \"updated\" };\n await pauses.load(input.execSql);\n const next = new Set(pauses.pausedOrganizationIds());\n if (paused) next.add(organizationId);\n else next.delete(organizationId);\n const change = await pauses.replace(input.execSql, next);\n if (change.resumed.length > 0) await host.resumeSync();\n return { membership: result.data, status: \"updated\" };\n}\n"]}
|
|
@@ -54,8 +54,18 @@ export interface WorkflowRuntimeInfraInput {
|
|
|
54
54
|
readonly documentProjectors: DocumentProjectorRegistry;
|
|
55
55
|
readonly execSql: ExecSql;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Which half of an organization's sync a caller is about to run: `push` sends
|
|
59
|
+
* local writes, `pull` fetches updates to a document the device already holds.
|
|
60
|
+
*/
|
|
61
|
+
export type RemoteSyncDirection = "push" | "pull";
|
|
57
62
|
export interface WorkflowRuntimeUtilInput {
|
|
58
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Whether the organization's remote sync is held in `direction`, `push`
|
|
65
|
+
* unless given. A billing block holds only pushes; a sync pause the user
|
|
66
|
+
* chose holds both. Held writes stay queued.
|
|
67
|
+
*/
|
|
68
|
+
readonly isRemoteSyncBlocked?: ((organizationId: string, direction?: RemoteSyncDirection) => boolean) | undefined;
|
|
59
69
|
readonly log: (message: string) => void;
|
|
60
70
|
readonly logError: (message: string | Error, cause?: unknown) => void;
|
|
61
71
|
readonly reportSecurityIncident: SecurityIncidentReporter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeInput.js","sourceRoot":"","sources":["runtimeInput.ts"],"names":[],"mappings":"","sourcesContent":["import type { EncapsulationKeyPair, SigningKeyPair } from \"@tearleads/crypto\";\nimport type { BlobStore } from \"../../data/blobs/blobContracts\";\nimport type { DocumentProjectorRegistry } from \"../../data/documents/documentKinds\";\nimport type { DomainScope } from \"../../data/shared/domainScope\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\n\nexport type WorkflowRuntimeDatabaseStatus =\n | \"idle\"\n | \"ready\"\n | \"error\"\n | \"terminated\";\n\nexport interface WorkflowRuntimeAuthInput {\n /** Server-backed personal organization; independent of organizationId. */\n readonly defaultOrganizationId?: string | null;\n /** Session root identity, independent of a document/pane target. */\n readonly rootContainerId?: string | null | undefined;\n readonly isAuthenticated: boolean;\n /** Platform-operator flag from the server; the API enforces root access. */\n readonly isRoot?: boolean | undefined;\n readonly organizationId: string | null;\n readonly userId: string | null;\n}\n\nexport interface WorkflowRuntimeCryptoInput {\n readonly encapsulationKeyPair: EncapsulationKeyPair | null;\n readonly signingFingerprint: string | null;\n readonly signingKeyPair: SigningKeyPair | null;\n}\n\nexport interface WorkflowRuntimeStateInput {\n readonly containerId: string | null;\n readonly domainScope: DomainScope;\n readonly events: ReadonlyArray<unknown>;\n readonly online: boolean;\n /**\n * Increments after each acknowledged server-events interest declaration.\n * Unlike a boolean connection edge, this survives coalesced runtime\n * notifications and document stores retained while their host provider is\n * unmounted.\n */\n readonly serverEventsConnectionGeneration?: number | undefined;\n /**\n * The server-events connect attempt whose interest acknowledgement is\n * outstanding. A document opened meanwhile defers its startup probe to the\n * reconnect probe that acknowledgement arms; when the attempt ends without\n * one, the deferred probe runs.\n */\n readonly serverEventsPendingConnectAttempt?: number | undefined;\n /**\n * Per-pane CRDT peer-seed discriminator (e.g. the pane's local identity\n * namespace). Documents in distinct panes must derive distinct Loro peer ids;\n * absent/`null` means single-pane (bare scope). The document runtime factory\n * always populates it; other runtimes and test fixtures may omit it.\n */\n readonly peerScope?: string | null;\n}\n\nexport interface WorkflowRuntimeInfraInput {\n readonly blobStore: BlobStore;\n readonly dbStatus: WorkflowRuntimeDatabaseStatus;\n readonly documentProjectors: DocumentProjectorRegistry;\n readonly execSql: ExecSql;\n}\n\nexport interface WorkflowRuntimeUtilInput {\n readonly isRemoteSyncBlocked?:\n | ((organizationId: string) => boolean)\n | undefined;\n readonly log: (message: string) => void;\n readonly logError: (message: string | Error, cause?: unknown) => void;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n}\n\nexport interface WorkflowRuntimeGroups {\n readonly auth: WorkflowRuntimeAuthInput;\n readonly crypto: WorkflowRuntimeCryptoInput;\n readonly infra: WorkflowRuntimeInfraInput;\n readonly state: WorkflowRuntimeStateInput;\n readonly util: WorkflowRuntimeUtilInput;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtimeInput.js","sourceRoot":"","sources":["runtimeInput.ts"],"names":[],"mappings":"","sourcesContent":["import type { EncapsulationKeyPair, SigningKeyPair } from \"@tearleads/crypto\";\nimport type { BlobStore } from \"../../data/blobs/blobContracts\";\nimport type { DocumentProjectorRegistry } from \"../../data/documents/documentKinds\";\nimport type { DomainScope } from \"../../data/shared/domainScope\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\n\nexport type WorkflowRuntimeDatabaseStatus =\n | \"idle\"\n | \"ready\"\n | \"error\"\n | \"terminated\";\n\nexport interface WorkflowRuntimeAuthInput {\n /** Server-backed personal organization; independent of organizationId. */\n readonly defaultOrganizationId?: string | null;\n /** Session root identity, independent of a document/pane target. */\n readonly rootContainerId?: string | null | undefined;\n readonly isAuthenticated: boolean;\n /** Platform-operator flag from the server; the API enforces root access. */\n readonly isRoot?: boolean | undefined;\n readonly organizationId: string | null;\n readonly userId: string | null;\n}\n\nexport interface WorkflowRuntimeCryptoInput {\n readonly encapsulationKeyPair: EncapsulationKeyPair | null;\n readonly signingFingerprint: string | null;\n readonly signingKeyPair: SigningKeyPair | null;\n}\n\nexport interface WorkflowRuntimeStateInput {\n readonly containerId: string | null;\n readonly domainScope: DomainScope;\n readonly events: ReadonlyArray<unknown>;\n readonly online: boolean;\n /**\n * Increments after each acknowledged server-events interest declaration.\n * Unlike a boolean connection edge, this survives coalesced runtime\n * notifications and document stores retained while their host provider is\n * unmounted.\n */\n readonly serverEventsConnectionGeneration?: number | undefined;\n /**\n * The server-events connect attempt whose interest acknowledgement is\n * outstanding. A document opened meanwhile defers its startup probe to the\n * reconnect probe that acknowledgement arms; when the attempt ends without\n * one, the deferred probe runs.\n */\n readonly serverEventsPendingConnectAttempt?: number | undefined;\n /**\n * Per-pane CRDT peer-seed discriminator (e.g. the pane's local identity\n * namespace). Documents in distinct panes must derive distinct Loro peer ids;\n * absent/`null` means single-pane (bare scope). The document runtime factory\n * always populates it; other runtimes and test fixtures may omit it.\n */\n readonly peerScope?: string | null;\n}\n\nexport interface WorkflowRuntimeInfraInput {\n readonly blobStore: BlobStore;\n readonly dbStatus: WorkflowRuntimeDatabaseStatus;\n readonly documentProjectors: DocumentProjectorRegistry;\n readonly execSql: ExecSql;\n}\n\n/**\n * Which half of an organization's sync a caller is about to run: `push` sends\n * local writes, `pull` fetches updates to a document the device already holds.\n */\nexport type RemoteSyncDirection = \"push\" | \"pull\";\n\nexport interface WorkflowRuntimeUtilInput {\n /**\n * Whether the organization's remote sync is held in `direction`, `push`\n * unless given. A billing block holds only pushes; a sync pause the user\n * chose holds both. Held writes stay queued.\n */\n readonly isRemoteSyncBlocked?:\n | ((organizationId: string, direction?: RemoteSyncDirection) => boolean)\n | undefined;\n readonly log: (message: string) => void;\n readonly logError: (message: string | Error, cause?: unknown) => void;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n}\n\nexport interface WorkflowRuntimeGroups {\n readonly auth: WorkflowRuntimeAuthInput;\n readonly crypto: WorkflowRuntimeCryptoInput;\n readonly infra: WorkflowRuntimeInfraInput;\n readonly state: WorkflowRuntimeStateInput;\n readonly util: WorkflowRuntimeUtilInput;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createDomainScope, type DomainScope, } from "../../data/shared/domainScope.js";
|
|
2
2
|
export { getRuntimePeerSeed } from "../../data/sync/crdtPeerSeed.js";
|
|
3
|
-
export { getOrCreateOrganizationSyncPauses,
|
|
3
|
+
export { getOrCreateOrganizationSyncPauses, loadOrganizationSyncPausesBeforeSync, type OrganizationSyncPauseChange, type OrganizationSyncPauseSubject, type OrganizationSyncPauses, } from "../../data/sync/organizationSyncPauses.js";
|
|
4
4
|
export { markOriginatedDocuments } from "../../data/sync/originatedDocuments.js";
|
|
5
5
|
export type { DomainSyncCoordinator, DomainSyncSnapshot, SyncIdleOptions, SyncLane, SyncLaneConfig, SyncLaneLastAction, SyncLanePhase, SyncLaneProgress, SyncLaneSnapshot, SyncLaneStatus, UploadSyncLane, UploadSyncLaneOptions, } from "../../data/sync/syncCoordinator.js";
|
|
6
6
|
export { beginDomainSyncUploadLane, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, hasDomainSyncCoordinatorPendingWork, requestAllDomainSyncLanes, subscribeToDomainSyncCoordinator, waitForDomainSyncCoordinatorToSettle, } from "../../data/sync/syncCoordinator.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createDomainScope, } from "../../data/shared/domainScope.js";
|
|
2
2
|
export { getRuntimePeerSeed } from "../../data/sync/crdtPeerSeed.js";
|
|
3
|
-
export { getOrCreateOrganizationSyncPauses,
|
|
3
|
+
export { getOrCreateOrganizationSyncPauses, loadOrganizationSyncPausesBeforeSync, } from "../../data/sync/organizationSyncPauses.js";
|
|
4
4
|
export { markOriginatedDocuments } from "../../data/sync/originatedDocuments.js";
|
|
5
5
|
export { beginDomainSyncUploadLane, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, hasDomainSyncCoordinatorPendingWork, requestAllDomainSyncLanes, subscribeToDomainSyncCoordinator, waitForDomainSyncCoordinatorToSettle, } from "../../data/sync/syncCoordinator.js";
|
|
6
6
|
//# sourceMappingURL=coordination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordination.js","sourceRoot":"","sources":["coordination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,iCAAiC,EACjC,
|
|
1
|
+
{"version":3,"file":"coordination.js","sourceRoot":"","sources":["coordination.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,iCAAiC,EACjC,oCAAoC,GAIrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAe9E,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,gCAAgC,EAChC,mCAAmC,EACnC,yBAAyB,EACzB,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,iCAAiC,CAAC","sourcesContent":["export {\n createDomainScope,\n type DomainScope,\n} from \"../../data/shared/domainScope\";\nexport { getRuntimePeerSeed } from \"../../data/sync/crdtPeerSeed\";\nexport {\n getOrCreateOrganizationSyncPauses,\n loadOrganizationSyncPausesBeforeSync,\n type OrganizationSyncPauseChange,\n type OrganizationSyncPauseSubject,\n type OrganizationSyncPauses,\n} from \"../../data/sync/organizationSyncPauses\";\nexport { markOriginatedDocuments } from \"../../data/sync/originatedDocuments\";\nexport type {\n DomainSyncCoordinator,\n DomainSyncSnapshot,\n SyncIdleOptions,\n SyncLane,\n SyncLaneConfig,\n SyncLaneLastAction,\n SyncLanePhase,\n SyncLaneProgress,\n SyncLaneSnapshot,\n SyncLaneStatus,\n UploadSyncLane,\n UploadSyncLaneOptions,\n} from \"../../data/sync/syncCoordinator\";\nexport {\n beginDomainSyncUploadLane,\n getDomainSyncCoordinatorSnapshot,\n getOrCreateDomainSyncCoordinator,\n hasDomainSyncCoordinatorPendingWork,\n requestAllDomainSyncLanes,\n subscribeToDomainSyncCoordinator,\n waitForDomainSyncCoordinatorToSettle,\n} from \"../../data/sync/syncCoordinator\";\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { beginDomainSyncUploadLane, createDomainScope, type DomainScope, type DomainSyncCoordinator, type DomainSyncSnapshot, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, getOrCreateOrganizationSyncPauses, getRuntimePeerSeed, hasDomainSyncCoordinatorPendingWork,
|
|
1
|
+
export { beginDomainSyncUploadLane, createDomainScope, type DomainScope, type DomainSyncCoordinator, type DomainSyncSnapshot, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, getOrCreateOrganizationSyncPauses, getRuntimePeerSeed, hasDomainSyncCoordinatorPendingWork, markOriginatedDocuments, type OrganizationSyncPauseChange, type OrganizationSyncPauseSubject, type OrganizationSyncPauses, requestAllDomainSyncLanes, type SyncIdleOptions, type SyncLane, type SyncLaneConfig, type SyncLaneLastAction, type SyncLanePhase, type SyncLaneProgress, type SyncLaneSnapshot, type SyncLaneStatus, subscribeToDomainSyncCoordinator, type UploadSyncLane, type UploadSyncLaneOptions, waitForDomainSyncCoordinatorToSettle, } from "./coordination.js";
|
|
2
2
|
export { type ClearRemoteSyncStateResult, clearRemoteSyncState, type RemoteResetInput, type RemoteResetReplacement, } from "./remoteReset.js";
|
package/workflows/sync/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { beginDomainSyncUploadLane, createDomainScope, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, getOrCreateOrganizationSyncPauses, getRuntimePeerSeed, hasDomainSyncCoordinatorPendingWork,
|
|
1
|
+
export { beginDomainSyncUploadLane, createDomainScope, getDomainSyncCoordinatorSnapshot, getOrCreateDomainSyncCoordinator, getOrCreateOrganizationSyncPauses, getRuntimePeerSeed, hasDomainSyncCoordinatorPendingWork, markOriginatedDocuments, requestAllDomainSyncLanes, subscribeToDomainSyncCoordinator, waitForDomainSyncCoordinatorToSettle, } from "./coordination.js";
|
|
2
2
|
export { clearRemoteSyncState, } from "./remoteReset.js";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAIjB,gCAAgC,EAChC,gCAAgC,EAChC,iCAAiC,EACjC,kBAAkB,EAClB,mCAAmC,EACnC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAIjB,gCAAgC,EAChC,gCAAgC,EAChC,iCAAiC,EACjC,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,EAIvB,yBAAyB,EASzB,gCAAgC,EAGhC,oCAAoC,GACrC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,oBAAoB,GAGrB,MAAM,eAAe,CAAC","sourcesContent":["export {\n beginDomainSyncUploadLane,\n createDomainScope,\n type DomainScope,\n type DomainSyncCoordinator,\n type DomainSyncSnapshot,\n getDomainSyncCoordinatorSnapshot,\n getOrCreateDomainSyncCoordinator,\n getOrCreateOrganizationSyncPauses,\n getRuntimePeerSeed,\n hasDomainSyncCoordinatorPendingWork,\n markOriginatedDocuments,\n type OrganizationSyncPauseChange,\n type OrganizationSyncPauseSubject,\n type OrganizationSyncPauses,\n requestAllDomainSyncLanes,\n type SyncIdleOptions,\n type SyncLane,\n type SyncLaneConfig,\n type SyncLaneLastAction,\n type SyncLanePhase,\n type SyncLaneProgress,\n type SyncLaneSnapshot,\n type SyncLaneStatus,\n subscribeToDomainSyncCoordinator,\n type UploadSyncLane,\n type UploadSyncLaneOptions,\n waitForDomainSyncCoordinatorToSettle,\n} from \"./coordination\";\nexport {\n type ClearRemoteSyncStateResult,\n clearRemoteSyncState,\n type RemoteResetInput,\n type RemoteResetReplacement,\n} from \"./remoteReset\";\n"]}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { and, eq, inArray } from "drizzle-orm";
|
|
2
|
-
import { DOCUMENTS_APP_KIND } from "../../documents/documentConstants.js";
|
|
3
|
-
import { documentContainerProjection } from "../../sqlite/schema/documentProjectionSchema.js";
|
|
4
|
-
import { documents } from "../../sqlite/schema/documentRecordSchema.js";
|
|
5
|
-
import { SQLITE_BOUND_VARIABLE_BUDGET } from "../../sqlite/sqliteBindBudget.js";
|
|
6
|
-
import { getClientSQLitePersistenceRuntime } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
7
|
-
// Leave room for the fixed binds each statement adds beside its id list.
|
|
8
|
-
const ID_BATCH_SIZE = SQLITE_BOUND_VARIABLE_BUDGET - 8;
|
|
9
|
-
function batches(values) {
|
|
10
|
-
const result = [];
|
|
11
|
-
for (let index = 0; index < values.length; index += ID_BATCH_SIZE) {
|
|
12
|
-
result.push(values.slice(index, index + ID_BATCH_SIZE));
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Local ids of the documents whose every placement is one of `containerIds`.
|
|
18
|
-
* A document also placed in a container outside the set stays: removing these
|
|
19
|
-
* containers must not take a document another folder still shows.
|
|
20
|
-
*/
|
|
21
|
-
export async function listDocumentLocalIdsPlacedOnlyIn(execSql, containerIds) {
|
|
22
|
-
const targets = new Set(containerIds);
|
|
23
|
-
if (targets.size === 0)
|
|
24
|
-
return [];
|
|
25
|
-
const { db } = getClientSQLitePersistenceRuntime(execSql);
|
|
26
|
-
const placedDocumentIds = new Set();
|
|
27
|
-
for (const batch of batches([...targets])) {
|
|
28
|
-
const rows = await db
|
|
29
|
-
.select({ documentId: documentContainerProjection.documentId })
|
|
30
|
-
.from(documentContainerProjection)
|
|
31
|
-
.where(inArray(documentContainerProjection.containerId, batch));
|
|
32
|
-
for (const row of rows)
|
|
33
|
-
placedDocumentIds.add(row.documentId);
|
|
34
|
-
}
|
|
35
|
-
const exclusiveDocumentIds = new Set(placedDocumentIds);
|
|
36
|
-
for (const batch of batches([...placedDocumentIds])) {
|
|
37
|
-
const rows = await db
|
|
38
|
-
.select({
|
|
39
|
-
containerId: documentContainerProjection.containerId,
|
|
40
|
-
documentId: documentContainerProjection.documentId,
|
|
41
|
-
})
|
|
42
|
-
.from(documentContainerProjection)
|
|
43
|
-
.where(inArray(documentContainerProjection.documentId, batch));
|
|
44
|
-
for (const row of rows) {
|
|
45
|
-
if (!targets.has(row.containerId)) {
|
|
46
|
-
exclusiveDocumentIds.delete(row.documentId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const localIds = [];
|
|
51
|
-
for (const batch of batches([...exclusiveDocumentIds])) {
|
|
52
|
-
const rows = await db
|
|
53
|
-
.select({ localId: documents.localId })
|
|
54
|
-
.from(documents)
|
|
55
|
-
.where(and(eq(documents.appKind, DOCUMENTS_APP_KIND), inArray(documents.documentId, batch)));
|
|
56
|
-
for (const row of rows)
|
|
57
|
-
localIds.push(row.localId);
|
|
58
|
-
}
|
|
59
|
-
return localIds.sort();
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=exclusiveDocumentPlacements.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exclusiveDocumentPlacements.js","sourceRoot":"","sources":["exclusiveDocumentPlacements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,iCAAiC,EAAE,MAAM,uCAAuC,CAAC;AAG1F,yEAAyE;AACzE,MAAM,aAAa,GAAG,4BAA4B,GAAG,CAAC,CAAC;AAEvD,SAAS,OAAO,CAAI,MAAoB;IACtC,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI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AC;aACjC,KAAK,CAAC,OAAO,CAAC,2BAA2B,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;QACjE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBAClC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,GAAG,MAAM,EAAE;aAClB,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC;aACtC,IAAI,CAAC,SAAS,CAAC;aACf,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAC,EACzC,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,CACrC,CACF,CAAC;QACJ,KAAK,MAAM,GAAG,IAAI,IAAI;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import { and, eq, inArray } from \"drizzle-orm\";\nimport { DOCUMENTS_APP_KIND } from \"../../documents/documentConstants\";\nimport { documentContainerProjection } from \"../../sqlite/schema/documentProjectionSchema\";\nimport { documents } from \"../../sqlite/schema/documentRecordSchema\";\nimport { SQLITE_BOUND_VARIABLE_BUDGET } from \"../../sqlite/sqliteBindBudget\";\nimport { getClientSQLitePersistenceRuntime } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\n\n// Leave room for the fixed binds each statement adds beside its id list.\nconst ID_BATCH_SIZE = SQLITE_BOUND_VARIABLE_BUDGET - 8;\n\nfunction batches<T>(values: readonly T[]): T[][] {\n const result: T[][] = [];\n for (let index = 0; index < values.length; index += ID_BATCH_SIZE) {\n result.push(values.slice(index, index + ID_BATCH_SIZE));\n }\n return result;\n}\n\n/**\n * Local ids of the documents whose every placement is one of `containerIds`.\n * A document also placed in a container outside the set stays: removing these\n * containers must not take a document another folder still shows.\n */\nexport async function listDocumentLocalIdsPlacedOnlyIn(\n execSql: ExecSql,\n containerIds: readonly string[],\n): Promise<string[]> {\n const targets = new Set(containerIds);\n if (targets.size === 0) return [];\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const placedDocumentIds = new Set<string>();\n for (const batch of batches([...targets])) {\n const rows = await db\n .select({ documentId: documentContainerProjection.documentId })\n .from(documentContainerProjection)\n .where(inArray(documentContainerProjection.containerId, batch));\n for (const row of rows) placedDocumentIds.add(row.documentId);\n }\n\n const exclusiveDocumentIds = new Set(placedDocumentIds);\n for (const batch of batches([...placedDocumentIds])) {\n const rows = await db\n .select({\n containerId: documentContainerProjection.containerId,\n documentId: documentContainerProjection.documentId,\n })\n .from(documentContainerProjection)\n .where(inArray(documentContainerProjection.documentId, batch));\n for (const row of rows) {\n if (!targets.has(row.containerId)) {\n exclusiveDocumentIds.delete(row.documentId);\n }\n }\n }\n\n const localIds: string[] = [];\n for (const batch of batches([...exclusiveDocumentIds])) {\n const rows = await db\n .select({ localId: documents.localId })\n .from(documents)\n .where(\n and(\n eq(documents.appKind, DOCUMENTS_APP_KIND),\n inArray(documents.documentId, batch),\n ),\n );\n for (const row of rows) localIds.push(row.localId);\n }\n return localIds.sort();\n}\n"]}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { removeOrganizationContentUnlessPending } from "../../../workflows/container-contents/syncPause/documentRemoval.js";
|
|
2
|
-
import { reclaimDocumentOrphanBlobs } from "../../../workflows/documents/index.js";
|
|
3
|
-
import { getOrCreateOrganizationSyncPauses, isRetainedWhileSyncPaused, } from "../../../workflows/sync/coordination.js";
|
|
4
|
-
import { emitPersistedDocumentDeletion, hasQueuedDocumentStoreWrites, restoreDocumentStore, retireDocumentStore, } from "../../documents/registry.js";
|
|
5
|
-
import { updateContainerContentsSnapshot } from "../state.js";
|
|
6
|
-
/** The local containers forgetting an organization's content removes. */
|
|
7
|
-
function listForgettableOrganizationContainerIds(state, organizationId) {
|
|
8
|
-
return [...state.containersById.values()].flatMap(({ container }) => container.organizationId === organizationId &&
|
|
9
|
-
!isRetainedWhileSyncPaused(container)
|
|
10
|
-
? [container.id]
|
|
11
|
-
: []);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Removes one organization's content from this device after its sync was
|
|
15
|
-
* paused: every container except its retained metadata root, and every
|
|
16
|
-
* document placed only in those containers. Nothing changes on the server, so
|
|
17
|
-
* resuming downloads it again.
|
|
18
|
-
*
|
|
19
|
-
* Unsynced work is never removed: the removal refuses while any pending write
|
|
20
|
-
* touches the organization, checked under the same lock as the deletions, and
|
|
21
|
-
* while an open store holds edits for any of its documents that have not
|
|
22
|
-
* reached SQLite. It also refuses the session's active organization, whose
|
|
23
|
-
* root the session still writes to. Returns whether nothing is left to retry.
|
|
24
|
-
*/
|
|
25
|
-
async function forgetOrganizationContent(state, organizationId, isCurrent) {
|
|
26
|
-
if (state.runtime.infra.dbStatus !== "ready" || !state.snapshot.ready) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
if (state.runtime.auth.organizationId === organizationId)
|
|
30
|
-
return false;
|
|
31
|
-
const containerIds = listForgettableOrganizationContainerIds(state, organizationId);
|
|
32
|
-
const { documentProjectors, execSql } = state.runtime.infra;
|
|
33
|
-
const { domainScope } = state.runtime.state;
|
|
34
|
-
// Switching into the organization mid-removal stops it before any deletion.
|
|
35
|
-
const stillCurrent = () => isCurrent() && state.runtime.auth.organizationId !== organizationId;
|
|
36
|
-
await state.persistence.ensureSchema(execSql);
|
|
37
|
-
const pauses = getOrCreateOrganizationSyncPauses(domainScope);
|
|
38
|
-
const removal = await removeOrganizationContentUnlessPending({
|
|
39
|
-
containerIds,
|
|
40
|
-
deleteContainers: (lockedExecSql, removals) => state.persistence.deleteContainers(lockedExecSql, removals, {
|
|
41
|
-
stillCurrent,
|
|
42
|
-
}),
|
|
43
|
-
documentProjectors,
|
|
44
|
-
execSql,
|
|
45
|
-
hasQueuedWrites: (localId) => hasQueuedDocumentStoreWrites(domainScope, localId),
|
|
46
|
-
organizationId,
|
|
47
|
-
restoreDocument: (localId) => restoreDocumentStore(domainScope, localId),
|
|
48
|
-
retireDocument: (localId) => retireDocumentStore(domainScope, localId, () => pauses.isOrganizationPaused(organizationId)),
|
|
49
|
-
stillCurrent,
|
|
50
|
-
});
|
|
51
|
-
for (const localId of removal.deletedLocalIds) {
|
|
52
|
-
emitPersistedDocumentDeletion(domainScope, localId);
|
|
53
|
-
}
|
|
54
|
-
if (removal.deletedLocalIds.length > 0) {
|
|
55
|
-
void reclaimDocumentOrphanBlobs(state.runtime);
|
|
56
|
-
}
|
|
57
|
-
for (const containerId of removal.deletedContainerIds) {
|
|
58
|
-
state.containersById.delete(containerId);
|
|
59
|
-
}
|
|
60
|
-
if (removal.deletedContainerIds.length > 0 && state.initialized) {
|
|
61
|
-
updateContainerContentsSnapshot(state);
|
|
62
|
-
}
|
|
63
|
-
return removal.status === "removed";
|
|
64
|
-
}
|
|
65
|
-
/** Runs `forgetOrganizationContent` in the store's container write chain. */
|
|
66
|
-
export function createForgetOrganizationContentMethod(state, chainContainerWrite) {
|
|
67
|
-
return async (organizationId) => {
|
|
68
|
-
let forgotten = false;
|
|
69
|
-
await chainContainerWrite(state, async (isCurrent) => {
|
|
70
|
-
forgotten = await forgetOrganizationContent(state, organizationId, isCurrent);
|
|
71
|
-
return null;
|
|
72
|
-
}, listForgettableOrganizationContainerIds(state, organizationId));
|
|
73
|
-
return forgotten;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=forgetOrganizationContentOperation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forgetOrganizationContentOperation.js","sourceRoot":"","sources":["forgetOrganizationContentOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,MAAM,iEAAiE,CAAC;AACzH,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACL,iCAAiC,EACjC,yBAAyB,GAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAG3D,yEAAyE;AACzE,SAAS,uCAAuC,CAC9C,KAA0D,EAC1D,cAAsB;IAEtB,OAAO,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAClE,SAAS,CAAC,cAAc,KAAK,cAAc;QAC3C,CAAC,yBAAyB,CAAC,SAAS,CAAC;QACnC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;QAChB,CAAC,CAAC,EAAE,CACP,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,yBAAyB,CACtC,KAAkC,EAClC,cAAsB,EACtB,SAA8B;IAE9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,KAAK,cAAc;QAAE,OAAO,KAAK,CAAC;IACvE,MAAM,YAAY,GAAG,uCAAuC,CAC1D,KAAK,EACL,cAAc,CACf,CAAC;IACF,MAAM,EAA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C,OAAO,CAAC,CAAC;IACjD,CAAC;IACD,KAAK,MAAM,WAAW,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;QACtD,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,OAAO,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;QAChE,+BAA+B,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;AACtC,CAAC;AAQD,6EAA6E;AAC7E,MAAM,UAAU,qCAAqC,CACnD,KAAkC,EAClC,mBAAwC;IAExC,OAAO,KAAK,EAAE,cAAc,EAAE,EAAE;QAC9B,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,MAAM,mBAAmB,CACvB,KAAK,EACL,KAAK,EAAE,SAAS,EAAE,EAAE;YAClB,SAAS,GAAG,MAAM,yBAAyB,CACzC,KAAK,EACL,cAAc,EACd,SAAS,CACV,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC,EACD,uCAAuC,CAAC,KAAK,EAAE,cAAc,CAAC,CAC/D,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { removeOrganizationContentUnlessPending } from \"../../../workflows/container-contents/syncPause/documentRemoval\";\nimport { reclaimDocumentOrphanBlobs } from \"../../../workflows/documents\";\nimport {\n getOrCreateOrganizationSyncPauses,\n isRetainedWhileSyncPaused,\n} from \"../../../workflows/sync/coordination\";\nimport {\n emitPersistedDocumentDeletion,\n hasQueuedDocumentStoreWrites,\n restoreDocumentStore,\n retireDocumentStore,\n} from \"../../documents/registry\";\nimport type { ContainerWriteGuard } from \"../remoteWrites/writeGeneration\";\nimport { updateContainerContentsSnapshot } from \"../state\";\nimport type { ContainerContentsStoreState } from \"../types\";\n\n/** The local containers forgetting an organization's content removes. */\nfunction listForgettableOrganizationContainerIds(\n state: Pick<ContainerContentsStoreState, \"containersById\">,\n organizationId: string,\n): string[] {\n return [...state.containersById.values()].flatMap(({ container }) =>\n container.organizationId === organizationId &&\n !isRetainedWhileSyncPaused(container)\n ? [container.id]\n : [],\n );\n}\n\n/**\n * Removes one organization's content from this device after its sync was\n * paused: every container except its retained metadata root, and every\n * document placed only in those containers. Nothing changes on the server, so\n * resuming downloads it again.\n *\n * Unsynced work is never removed: the removal refuses while any pending write\n * touches the organization, checked under the same lock as the deletions, and\n * while an open store holds edits for any of its documents that have not\n * reached SQLite. It also refuses the session's active organization, whose\n * root the session still writes to. Returns whether nothing is left to retry.\n */\nasync function forgetOrganizationContent(\n state: ContainerContentsStoreState,\n organizationId: string,\n isCurrent: ContainerWriteGuard,\n): Promise<boolean> {\n if (state.runtime.infra.dbStatus !== \"ready\" || !state.snapshot.ready) {\n return false;\n }\n if (state.runtime.auth.organizationId === organizationId) return false;\n const containerIds = listForgettableOrganizationContainerIds(\n state,\n organizationId,\n );\n const { documentProjectors, execSql } = state.runtime.infra;\n const { domainScope } = state.runtime.state;\n // Switching into the organization mid-removal stops it before any deletion.\n const stillCurrent = () =>\n isCurrent() && state.runtime.auth.organizationId !== organizationId;\n await state.persistence.ensureSchema(execSql);\n const pauses = getOrCreateOrganizationSyncPauses(domainScope);\n const removal = await removeOrganizationContentUnlessPending({\n containerIds,\n deleteContainers: (lockedExecSql, removals) =>\n state.persistence.deleteContainers(lockedExecSql, removals, {\n stillCurrent,\n }),\n documentProjectors,\n execSql,\n hasQueuedWrites: (localId) =>\n hasQueuedDocumentStoreWrites(domainScope, localId),\n organizationId,\n restoreDocument: (localId) => restoreDocumentStore(domainScope, localId),\n retireDocument: (localId) =>\n retireDocumentStore(domainScope, localId, () =>\n pauses.isOrganizationPaused(organizationId),\n ),\n stillCurrent,\n });\n for (const localId of removal.deletedLocalIds) {\n emitPersistedDocumentDeletion(domainScope, localId);\n }\n if (removal.deletedLocalIds.length > 0) {\n void reclaimDocumentOrphanBlobs(state.runtime);\n }\n for (const containerId of removal.deletedContainerIds) {\n state.containersById.delete(containerId);\n }\n if (removal.deletedContainerIds.length > 0 && state.initialized) {\n updateContainerContentsSnapshot(state);\n }\n return removal.status === \"removed\";\n}\n\ntype ContainerWriteChain = (\n state: ContainerContentsStoreState,\n work: (isCurrent: () => boolean) => ContainerContentsStoreState[\"writeChain\"],\n changedIds: readonly string[],\n) => ContainerContentsStoreState[\"writeChain\"];\n\n/** Runs `forgetOrganizationContent` in the store's container write chain. */\nexport function createForgetOrganizationContentMethod(\n state: ContainerContentsStoreState,\n chainContainerWrite: ContainerWriteChain,\n): (organizationId: string) => Promise<boolean> {\n return async (organizationId) => {\n let forgotten = false;\n await chainContainerWrite(\n state,\n async (isCurrent) => {\n forgotten = await forgetOrganizationContent(\n state,\n organizationId,\n isCurrent,\n );\n return null;\n },\n listForgettableOrganizationContainerIds(state, organizationId),\n );\n return forgotten;\n };\n}\n"]}
|