@tearleads/client-sdk 0.1.235 → 0.1.237
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/documentRecordSchema.js +7 -0
- package/data/sqlite/schema/documentRecordSchema.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/metadata/metadataRemoteSync.js +1 -0
- package/workflows/container-contents/metadata/metadataRemoteSync.js.map +1 -1
- package/workflows/container-contents/pendingWrites/deferredTails.js +4 -0
- package/workflows/container-contents/pendingWrites/deferredTails.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":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,GAG1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oCAAoC,EACpC,kBAAkB,GACnB,MAAM,0CAA0C,CAAC;AAMlD,OAAO,EAGL,wCAAwC,GACzC,MAAM,oDAAoD,CAAC;AAI5D,OAAO,EAEL,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kCAAkC,EAClC,4BAA4B,EAC5B,wCAAwC,EACxC,4BAA4B,EAE5B,wCAAwC,GAEzC,MAAM,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eAAe,EAAE,CACrB,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n DOCUMENT_SYNC_ERROR_CODES,\n type DocumentSyncResponse,\n type DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport {\n isUpstreamDeletedDocumentSyncFailure,\n submitDocumentSync,\n} from \"../../../data/documents/shared/responses\";\nimport type {\n DocumentSyncApi,\n DocumentSyncPlan,\n MaterializedDocumentSyncPlan,\n} from \"../../../data/documents/shared/sync/documentSyncTypes\";\nimport {\n type DocumentSyncCommitLsnMode,\n type DocumentSyncPullContinuation,\n InvalidDocumentSyncPullContinuationError,\n} from \"../../../data/documents/shared/sync/syncPagination\";\nimport type { DocumentSyncSubmitFailure } from \"../../../data/documents/shared/sync/syncSubmitFailure\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../../data/keyingProjectionVerification\";\nimport type { PendingUpdateRecord } from \"../../../data/persistence/documents/records\";\nimport {\n type DocumentSyncTraceEmitter,\n traceProjectionFailed,\n traceSubmitFailed,\n} from \"../sync/syncTrace\";\nimport {\n canRecoverDocumentUpdateIdConflict,\n canRetryDocumentSyncConflict,\n handleUpstreamDeletedDocumentSyncFailure,\n isCheckpointCoverageConflict,\n type RemoteDocumentDeletionHandler,\n shouldRetrySyncWithFreshWriterProjection,\n type TerminalSubmitFailureHandler,\n} from \"./syncFailureClassification\";\nimport { recoverDocumentSyncPolicyRepair } from \"./syncPolicyRepair\";\n\nconst REMOTE_DOCUMENT_DELETED = Symbol(\"remoteDocumentDeleted\");\n\nexport function assertRawContinuationCanRetry(\n historyMode: \"raw\" | undefined,\n pullContinuation: DocumentSyncPullContinuation | undefined,\n): void {\n if (historyMode === \"raw\" && pullContinuation !== undefined) {\n throw new InvalidDocumentSyncPullContinuationError(\n \"Document raw-history continuation became stale\",\n );\n }\n}\n\ntype DocumentWriterProjectionResolution =\n | DocumentWriterProjectionResponse\n | typeof REMOTE_DOCUMENT_DELETED\n | null;\n\ntype FailedDocumentSyncAction =\n | \"retry\"\n | \"stop\"\n | {\n readonly kind: \"recover_update_id_conflict\";\n readonly recoveryPendingUpdatesById: Map<string, PendingUpdateRecord>;\n }\n | { readonly kind: \"regenerate_queued_checkpoints\" };\n\ntype DocumentSyncAttemptSubmission =\n | {\n readonly kind: \"completed\";\n readonly pullComplete: boolean;\n readonly response: DocumentSyncResponse;\n }\n | FailedDocumentSyncAction\n | \"cancelled\"\n | \"blocked\";\n\nasync function resolveFailedDocumentSyncAction(input: {\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n failure: DocumentSyncSubmitFailure;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n}): Promise<FailedDocumentSyncAction> {\n const action = await classifyFailedDocumentSyncAction(input);\n traceSubmitFailed(input.onSyncTrace, {\n action:\n action === \"retry\" || action === \"stop\"\n ? action\n : action.kind === \"recover_update_id_conflict\"\n ? \"recover-update-ids\"\n : \"regenerate-checkpoints\",\n code: input.failure.code,\n documentId: input.documentId,\n status: input.failure.status,\n });\n return action;\n}\n\nasync function classifyFailedDocumentSyncAction(input: {\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n failure: DocumentSyncSubmitFailure;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n}): Promise<FailedDocumentSyncAction> {\n if (\n await handleUpstreamDeletedDocumentSyncFailure({\n documentId: input.documentId,\n failure: input.failure,\n onRemoteDocumentDeleted: input.onRemoteDocumentDeleted,\n })\n ) {\n return \"stop\";\n }\n\n if (\n canRetryDocumentSyncConflict({\n attempt: input.attempt,\n failure: input.failure,\n maxAttempts: input.maxAttempts,\n })\n ) {\n return \"retry\";\n }\n\n // The write rolled back whole. Its inline repairs would have stranded a\n // level above a directly granted container, and a flat rekey list cannot say\n // what each must carry: the retry commits them standalone instead.\n if (\n input.attempt < input.maxAttempts &&\n input.onInlineRepairRefused &&\n input.failure.code === DOCUMENT_SYNC_ERROR_CODES.descendantRekeysRequired\n ) {\n input.onInlineRepairRefused();\n return \"retry\";\n }\n\n if (\n canRecoverDocumentUpdateIdConflict({\n attempt: input.attempt,\n failure: input.failure,\n maxAttempts: input.maxAttempts,\n pendingUpdateCount: input.pendingUpdates.length,\n })\n ) {\n return {\n kind: \"recover_update_id_conflict\",\n recoveryPendingUpdatesById: new Map(\n input.pendingUpdates.map((update) => [update.id, update]),\n ),\n };\n }\n\n if (\n input.attempt < input.maxAttempts &&\n input.canRegenerateQueuedCheckpoints === true &&\n isCheckpointCoverageConflict(input.failure)\n ) {\n return { kind: \"regenerate_queued_checkpoints\" };\n }\n\n input.failure.report();\n await input.onTerminalSubmitFailure?.(input.failure);\n return \"stop\";\n}\n\nasync function submitDocumentSyncAttempt(input: {\n apiClient: DocumentSyncApi;\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n expectedCommitLsnMode?: DocumentSyncCommitLsnMode | undefined;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n plan: DocumentSyncPlan;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<DocumentSyncAttemptSubmission> {\n if (input.stillCurrent?.() === false) return \"cancelled\";\n const submitted = await submitDocumentSync({\n apiClient: input.apiClient,\n expectedCommitLsnMode: input.expectedCommitLsnMode,\n plan: input.plan,\n });\n if (input.stillCurrent?.() === false) return \"cancelled\";\n if (!submitted) {\n return \"stop\";\n }\n if (submitted.ok) {\n return {\n kind: \"completed\",\n pullComplete: submitted.pullComplete,\n response: submitted.response,\n };\n }\n\n await recoverDocumentSyncPolicyRepair({\n failure: submitted,\n plan: input.plan,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n if (input.stillCurrent?.() === false) return \"cancelled\";\n\n return resolveFailedDocumentSyncAction({\n attempt: input.attempt,\n canRegenerateQueuedCheckpoints: input.canRegenerateQueuedCheckpoints,\n documentId: input.documentId,\n failure: submitted,\n maxAttempts: input.maxAttempts,\n onInlineRepairRefused: input.onInlineRepairRefused,\n onRemoteDocumentDeleted: input.onRemoteDocumentDeleted,\n onSyncTrace: input.onSyncTrace,\n onTerminalSubmitFailure: input.onTerminalSubmitFailure,\n pendingUpdates: input.pendingUpdates,\n });\n}\n\nexport async function submitDocumentSyncAttemptIfAllowed(\n input: Parameters<typeof submitDocumentSyncAttempt>[0] & {\n isRemoteSyncBlocked?: ((organizationId: string) => boolean) | undefined;\n onOutgoingUpdatesMaterialized?:\n | ((updateIds: readonly string[]) => void)\n | undefined;\n failureBlocksQueuedWrites?: boolean | undefined;\n },\n): Promise<DocumentSyncAttemptSubmission> {\n const {\n failureBlocksQueuedWrites,\n isRemoteSyncBlocked,\n onOutgoingUpdatesMaterialized,\n ...submissionInput\n } = input;\n const hasRemoteWrites =\n input.plan.request.outgoingUpdates.length > 0 ||\n (input.plan.request.containerRekeys?.length ?? 0) > 0;\n if (hasRemoteWrites && isRemoteSyncBlocked?.(input.plan.organizationId)) {\n return \"blocked\";\n }\n if (input.stillCurrent?.() === false) return \"cancelled\";\n\n onOutgoingUpdatesMaterialized?.(\n input.plan.request.outgoingUpdates.map(({ id }) => id),\n );\n\n return submitDocumentSyncAttempt({\n ...submissionInput,\n // A read-only pass carries no writes, so a terminal failure describes a\n // pull, not queued local data — recording it would flag the next local\n // edit as failed before it was ever attempted. A cursor continuation and\n // update-id recovery both submit an empty request while durable rows still\n // exist; a terminal 403 there IS what blocks the queued edits.\n onTerminalSubmitFailure:\n hasRemoteWrites || failureBlocksQueuedWrites\n ? submissionInput.onTerminalSubmitFailure\n : undefined,\n });\n}\n\nasync function resolveDocumentSyncWriterProjection(input: {\n apiClient: DocumentSyncApi;\n documentId: string;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n /**\n * Invoked when the projection fetch fails terminally. Write-bearing sync\n * passes persist this: without a writer projection their queued writes can\n * never submit, so the failure (e.g. a 403 after access revocation) is what\n * the write queue should surface.\n */\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n reusableWriterProjection: DocumentWriterProjectionResponse | null;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DocumentWriterProjectionResolution> {\n if (input.stillCurrent?.() === false) return null;\n if (input.reusableWriterProjection) {\n return input.reusableWriterProjection;\n }\n\n const result = await input.apiClient.getDocumentWriterProjectionResult(\n input.documentId,\n { reportErrors: false },\n );\n if (input.stillCurrent?.() === false) return null;\n if (result.ok) {\n return result.data;\n }\n if (isUpstreamDeletedDocumentSyncFailure(result)) {\n return REMOTE_DOCUMENT_DELETED;\n }\n traceProjectionFailed(input.onSyncTrace, {\n code: result.code,\n documentId: input.documentId,\n status: result.status,\n });\n result.report();\n await input.onTerminalFailure?.(result);\n return null;\n}\n\nexport async function retrySyncPlan(input: {\n apiClient: DocumentSyncApi;\n buildWithProjection: (\n projection: DocumentWriterProjectionResponse,\n ) => Promise<MaterializedDocumentSyncPlan>;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n stillCurrent?: (() => boolean) | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}): Promise<\n | readonly [MaterializedDocumentSyncPlan, DocumentWriterProjectionResponse]\n | null\n> {\n try {\n return [\n await input.buildWithProjection(input.writerProjection),\n input.writerProjection,\n ];\n } catch (error) {\n if (\n !input.apiClient.evictDocumentWriterProjection ||\n !shouldRetrySyncWithFreshWriterProjection(error)\n ) {\n throw error;\n }\n }\n if (input.stillCurrent?.() === false) return null;\n\n // Only this document's projection was stale; evict just it so unrelated\n // documents keep their warm cache instead of a global wipe.\n input.apiClient.evictDocumentWriterProjection?.(input.documentId);\n const writerProjection = await resolveDocumentSyncWriterProjection({\n apiClient: input.apiClient,\n documentId: input.documentId,\n onSyncTrace: input.onSyncTrace,\n onTerminalFailure: input.onTerminalFailure,\n reusableWriterProjection: null,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n if (writerProjection === REMOTE_DOCUMENT_DELETED) {\n await input.onRemoteDocumentDeleted?.({ documentId: input.documentId });\n return null;\n }\n if (!writerProjection) {\n return null;\n }\n\n return [await input.buildWithProjection(writerProjection), writerProjection];\n}\n\n/**\n * Resolves the writer projection for one sync attempt, converting the two\n * unrecoverable outcomes into an abandoned (null) result with a named reason\n * so callers that turn a null sync into their own error can surface the real\n * cause.\n */\nexport async function resolveSyncAttemptWriterProjection(input: {\n apiClient: DocumentSyncApi;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncAbandoned?: ((reason: string) => void) | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n reusableWriterProjection: DocumentWriterProjectionResponse | null;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DocumentWriterProjectionResponse | null> {\n const writerProjection = await resolveDocumentSyncWriterProjection(input);\n if (input.stillCurrent?.() === false) return null;\n if (writerProjection === REMOTE_DOCUMENT_DELETED) {\n await input.onRemoteDocumentDeleted?.({ documentId: input.documentId });\n if (input.stillCurrent?.() !== false) {\n input.onSyncAbandoned?.(\"the remote document was deleted\");\n }\n return null;\n }\n if (!writerProjection) {\n input.onSyncAbandoned?.(\n \"the document writer projection could not be fetched\",\n );\n return null;\n }\n return writerProjection;\n}\n\nexport async function refreshSyncAttemptWriterProjection(\n input: Omit<\n Parameters<typeof resolveSyncAttemptWriterProjection>[0],\n \"reusableWriterProjection\"\n > & { unavailableError?: unknown },\n): Promise<DocumentWriterProjectionResponse | null> {\n const { onRemoteDocumentDeleted, unavailableError, ...resolutionInput } =\n input;\n if (input.stillCurrent?.() === false) return null;\n if (input.apiClient.evictDocumentWriterProjection) {\n input.apiClient.evictDocumentWriterProjection(input.documentId);\n } else {\n input.apiClient.clearWriterProjectionCaches?.();\n }\n let remoteDocumentDeleted = false;\n const writerProjection = await resolveSyncAttemptWriterProjection({\n ...resolutionInput,\n onRemoteDocumentDeleted: async (deleted) => {\n remoteDocumentDeleted = true;\n await onRemoteDocumentDeleted?.(deleted);\n },\n reusableWriterProjection: null,\n });\n if (\n !writerProjection &&\n unavailableError !== undefined &&\n !remoteDocumentDeleted &&\n input.stillCurrent?.() !== false\n ) {\n throw unavailableError;\n }\n return writerProjection;\n}\n\nexport async function retrySyncPlanOrAbandon(input: {\n apiClient: DocumentSyncApi;\n buildWithProjection: (\n projection: DocumentWriterProjectionResponse,\n ) => Promise<MaterializedDocumentSyncPlan>;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncAbandoned?: ((reason: string) => void) | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n stillCurrent?: (() => boolean) | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}): Promise<\n | readonly [MaterializedDocumentSyncPlan, DocumentWriterProjectionResponse]\n | null\n> {\n const planned = await retrySyncPlan(input);\n if (!planned && input.stillCurrent?.() !== false) {\n input.onSyncAbandoned?.(\n \"a sync plan could not be built against the current projection\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C;QAChE,GAAG,eAAe;QAClB,uBAAuB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzC,qBAAqB,GAAG,IAAI,CAAC;YAC7B,MAAM,uBAAuB,EAAE,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,wBAAwB,EAAE,IAAI;KAC/B,CAAC,CAAC;IACH,IACE,CAAC,gBAAgB;QACjB,gBAAgB,KAAK,SAAS;QAC9B,CAAC,qBAAqB;QACtB,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK,EAChC,CAAC;QACD,MAAM,gBAAgB,CAAC;IACzB,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAY5C;IAIC,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;QACjD,KAAK,CAAC,eAAe,EAAE,CACrB,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n DOCUMENT_SYNC_ERROR_CODES,\n type DocumentSyncResponse,\n type DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport {\n isUpstreamDeletedDocumentSyncFailure,\n submitDocumentSync,\n} from \"../../../data/documents/shared/responses\";\nimport type {\n DocumentSyncApi,\n DocumentSyncPlan,\n MaterializedDocumentSyncPlan,\n} from \"../../../data/documents/shared/sync/documentSyncTypes\";\nimport {\n type DocumentSyncCommitLsnMode,\n type DocumentSyncPullContinuation,\n InvalidDocumentSyncPullContinuationError,\n} from \"../../../data/documents/shared/sync/syncPagination\";\nimport type { DocumentSyncSubmitFailure } from \"../../../data/documents/shared/sync/syncSubmitFailure\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../../data/keyingProjectionVerification\";\nimport type { PendingUpdateRecord } from \"../../../data/persistence/documents/records\";\nimport type { WorkflowRuntimeUtilInput } from \"../../shared/runtimeInput\";\nimport {\n type DocumentSyncTraceEmitter,\n traceProjectionFailed,\n traceSubmitFailed,\n} from \"../sync/syncTrace\";\nimport { isRoutinePullHeld } from \"./syncAbandon\";\nimport {\n canRecoverDocumentUpdateIdConflict,\n canRetryDocumentSyncConflict,\n handleUpstreamDeletedDocumentSyncFailure,\n isCheckpointCoverageConflict,\n type RemoteDocumentDeletionHandler,\n shouldRetrySyncWithFreshWriterProjection,\n type TerminalSubmitFailureHandler,\n} from \"./syncFailureClassification\";\nimport { recoverDocumentSyncPolicyRepair } from \"./syncPolicyRepair\";\n\nconst REMOTE_DOCUMENT_DELETED = Symbol(\"remoteDocumentDeleted\");\n\nexport function assertRawContinuationCanRetry(\n historyMode: \"raw\" | undefined,\n pullContinuation: DocumentSyncPullContinuation | undefined,\n): void {\n if (historyMode === \"raw\" && pullContinuation !== undefined) {\n throw new InvalidDocumentSyncPullContinuationError(\n \"Document raw-history continuation became stale\",\n );\n }\n}\n\ntype DocumentWriterProjectionResolution =\n | DocumentWriterProjectionResponse\n | typeof REMOTE_DOCUMENT_DELETED\n | null;\n\ntype FailedDocumentSyncAction =\n | \"retry\"\n | \"stop\"\n | {\n readonly kind: \"recover_update_id_conflict\";\n readonly recoveryPendingUpdatesById: Map<string, PendingUpdateRecord>;\n }\n | { readonly kind: \"regenerate_queued_checkpoints\" };\n\ntype DocumentSyncAttemptSubmission =\n | {\n readonly kind: \"completed\";\n readonly pullComplete: boolean;\n readonly response: DocumentSyncResponse;\n }\n | FailedDocumentSyncAction\n | \"cancelled\"\n | \"blocked\";\n\nasync function resolveFailedDocumentSyncAction(input: {\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n failure: DocumentSyncSubmitFailure;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n}): Promise<FailedDocumentSyncAction> {\n const action = await classifyFailedDocumentSyncAction(input);\n traceSubmitFailed(input.onSyncTrace, {\n action:\n action === \"retry\" || action === \"stop\"\n ? action\n : action.kind === \"recover_update_id_conflict\"\n ? \"recover-update-ids\"\n : \"regenerate-checkpoints\",\n code: input.failure.code,\n documentId: input.documentId,\n status: input.failure.status,\n });\n return action;\n}\n\nasync function classifyFailedDocumentSyncAction(input: {\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n failure: DocumentSyncSubmitFailure;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n}): Promise<FailedDocumentSyncAction> {\n if (\n await handleUpstreamDeletedDocumentSyncFailure({\n documentId: input.documentId,\n failure: input.failure,\n onRemoteDocumentDeleted: input.onRemoteDocumentDeleted,\n })\n ) {\n return \"stop\";\n }\n\n if (\n canRetryDocumentSyncConflict({\n attempt: input.attempt,\n failure: input.failure,\n maxAttempts: input.maxAttempts,\n })\n ) {\n return \"retry\";\n }\n\n // The write rolled back whole. Its inline repairs would have stranded a\n // level above a directly granted container, and a flat rekey list cannot say\n // what each must carry: the retry commits them standalone instead.\n if (\n input.attempt < input.maxAttempts &&\n input.onInlineRepairRefused &&\n input.failure.code === DOCUMENT_SYNC_ERROR_CODES.descendantRekeysRequired\n ) {\n input.onInlineRepairRefused();\n return \"retry\";\n }\n\n if (\n canRecoverDocumentUpdateIdConflict({\n attempt: input.attempt,\n failure: input.failure,\n maxAttempts: input.maxAttempts,\n pendingUpdateCount: input.pendingUpdates.length,\n })\n ) {\n return {\n kind: \"recover_update_id_conflict\",\n recoveryPendingUpdatesById: new Map(\n input.pendingUpdates.map((update) => [update.id, update]),\n ),\n };\n }\n\n if (\n input.attempt < input.maxAttempts &&\n input.canRegenerateQueuedCheckpoints === true &&\n isCheckpointCoverageConflict(input.failure)\n ) {\n return { kind: \"regenerate_queued_checkpoints\" };\n }\n\n input.failure.report();\n await input.onTerminalSubmitFailure?.(input.failure);\n return \"stop\";\n}\n\nasync function submitDocumentSyncAttempt(input: {\n apiClient: DocumentSyncApi;\n attempt: number;\n canRegenerateQueuedCheckpoints?: boolean | undefined;\n documentId: string;\n expectedCommitLsnMode?: DocumentSyncCommitLsnMode | undefined;\n maxAttempts: number;\n onInlineRepairRefused?: (() => void) | undefined;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n pendingUpdates: readonly PendingUpdateRecord[];\n plan: DocumentSyncPlan;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<DocumentSyncAttemptSubmission> {\n if (input.stillCurrent?.() === false) return \"cancelled\";\n const submitted = await submitDocumentSync({\n apiClient: input.apiClient,\n expectedCommitLsnMode: input.expectedCommitLsnMode,\n plan: input.plan,\n });\n if (input.stillCurrent?.() === false) return \"cancelled\";\n if (!submitted) {\n return \"stop\";\n }\n if (submitted.ok) {\n return {\n kind: \"completed\",\n pullComplete: submitted.pullComplete,\n response: submitted.response,\n };\n }\n\n await recoverDocumentSyncPolicyRepair({\n failure: submitted,\n plan: input.plan,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n if (input.stillCurrent?.() === false) return \"cancelled\";\n\n return resolveFailedDocumentSyncAction({\n attempt: input.attempt,\n canRegenerateQueuedCheckpoints: input.canRegenerateQueuedCheckpoints,\n documentId: input.documentId,\n failure: submitted,\n maxAttempts: input.maxAttempts,\n onInlineRepairRefused: input.onInlineRepairRefused,\n onRemoteDocumentDeleted: input.onRemoteDocumentDeleted,\n onSyncTrace: input.onSyncTrace,\n onTerminalSubmitFailure: input.onTerminalSubmitFailure,\n pendingUpdates: input.pendingUpdates,\n });\n}\n\nexport async function submitDocumentSyncAttemptIfAllowed(\n input: Parameters<typeof submitDocumentSyncAttempt>[0] & {\n isRemoteSyncBlocked?: WorkflowRuntimeUtilInput[\"isRemoteSyncBlocked\"];\n /** The pass's pull position, which decides whether a pause holds it. */\n pull?: Parameters<typeof isRoutinePullHeld>[0] | undefined;\n onOutgoingUpdatesMaterialized?:\n | ((updateIds: readonly string[]) => void)\n | undefined;\n failureBlocksQueuedWrites?: boolean | undefined;\n },\n): Promise<DocumentSyncAttemptSubmission> {\n const {\n failureBlocksQueuedWrites,\n isRemoteSyncBlocked,\n pull,\n onOutgoingUpdatesMaterialized,\n ...submissionInput\n } = input;\n const hasRemoteWrites =\n input.plan.request.outgoingUpdates.length > 0 ||\n (input.plan.request.containerRekeys?.length ?? 0) > 0;\n const blocked = hasRemoteWrites\n ? isRemoteSyncBlocked?.(input.plan.organizationId)\n : isRoutinePullHeld(\n { ...pull, isRemoteSyncBlocked },\n input.plan.organizationId,\n );\n if (blocked) return \"blocked\";\n if (input.stillCurrent?.() === false) return \"cancelled\";\n\n onOutgoingUpdatesMaterialized?.(\n input.plan.request.outgoingUpdates.map(({ id }) => id),\n );\n\n return submitDocumentSyncAttempt({\n ...submissionInput,\n // A read-only pass carries no writes, so a terminal failure describes a\n // pull, not queued local data — recording it would flag the next local\n // edit as failed before it was ever attempted. A cursor continuation and\n // update-id recovery both submit an empty request while durable rows still\n // exist; a terminal 403 there IS what blocks the queued edits.\n onTerminalSubmitFailure:\n hasRemoteWrites || failureBlocksQueuedWrites\n ? submissionInput.onTerminalSubmitFailure\n : undefined,\n });\n}\n\nasync function resolveDocumentSyncWriterProjection(input: {\n apiClient: DocumentSyncApi;\n documentId: string;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n /**\n * Invoked when the projection fetch fails terminally. Write-bearing sync\n * passes persist this: without a writer projection their queued writes can\n * never submit, so the failure (e.g. a 403 after access revocation) is what\n * the write queue should surface.\n */\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n reusableWriterProjection: DocumentWriterProjectionResponse | null;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DocumentWriterProjectionResolution> {\n if (input.stillCurrent?.() === false) return null;\n if (input.reusableWriterProjection) {\n return input.reusableWriterProjection;\n }\n\n const result = await input.apiClient.getDocumentWriterProjectionResult(\n input.documentId,\n { reportErrors: false },\n );\n if (input.stillCurrent?.() === false) return null;\n if (result.ok) {\n return result.data;\n }\n if (isUpstreamDeletedDocumentSyncFailure(result)) {\n return REMOTE_DOCUMENT_DELETED;\n }\n traceProjectionFailed(input.onSyncTrace, {\n code: result.code,\n documentId: input.documentId,\n status: result.status,\n });\n result.report();\n await input.onTerminalFailure?.(result);\n return null;\n}\n\nexport async function retrySyncPlan(input: {\n apiClient: DocumentSyncApi;\n buildWithProjection: (\n projection: DocumentWriterProjectionResponse,\n ) => Promise<MaterializedDocumentSyncPlan>;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n stillCurrent?: (() => boolean) | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}): Promise<\n | readonly [MaterializedDocumentSyncPlan, DocumentWriterProjectionResponse]\n | null\n> {\n try {\n return [\n await input.buildWithProjection(input.writerProjection),\n input.writerProjection,\n ];\n } catch (error) {\n if (\n !input.apiClient.evictDocumentWriterProjection ||\n !shouldRetrySyncWithFreshWriterProjection(error)\n ) {\n throw error;\n }\n }\n if (input.stillCurrent?.() === false) return null;\n\n // Only this document's projection was stale; evict just it so unrelated\n // documents keep their warm cache instead of a global wipe.\n input.apiClient.evictDocumentWriterProjection?.(input.documentId);\n const writerProjection = await resolveDocumentSyncWriterProjection({\n apiClient: input.apiClient,\n documentId: input.documentId,\n onSyncTrace: input.onSyncTrace,\n onTerminalFailure: input.onTerminalFailure,\n reusableWriterProjection: null,\n stillCurrent: input.stillCurrent,\n });\n if (input.stillCurrent?.() === false) return null;\n if (writerProjection === REMOTE_DOCUMENT_DELETED) {\n await input.onRemoteDocumentDeleted?.({ documentId: input.documentId });\n return null;\n }\n if (!writerProjection) {\n return null;\n }\n\n return [await input.buildWithProjection(writerProjection), writerProjection];\n}\n\n/**\n * Resolves the writer projection for one sync attempt, converting the two\n * unrecoverable outcomes into an abandoned (null) result with a named reason\n * so callers that turn a null sync into their own error can surface the real\n * cause.\n */\nexport async function resolveSyncAttemptWriterProjection(input: {\n apiClient: DocumentSyncApi;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncAbandoned?: ((reason: string) => void) | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n reusableWriterProjection: DocumentWriterProjectionResponse | null;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DocumentWriterProjectionResponse | null> {\n const writerProjection = await resolveDocumentSyncWriterProjection(input);\n if (input.stillCurrent?.() === false) return null;\n if (writerProjection === REMOTE_DOCUMENT_DELETED) {\n await input.onRemoteDocumentDeleted?.({ documentId: input.documentId });\n if (input.stillCurrent?.() !== false) {\n input.onSyncAbandoned?.(\"the remote document was deleted\");\n }\n return null;\n }\n if (!writerProjection) {\n input.onSyncAbandoned?.(\n \"the document writer projection could not be fetched\",\n );\n return null;\n }\n return writerProjection;\n}\n\nexport async function refreshSyncAttemptWriterProjection(\n input: Omit<\n Parameters<typeof resolveSyncAttemptWriterProjection>[0],\n \"reusableWriterProjection\"\n > & { unavailableError?: unknown },\n): Promise<DocumentWriterProjectionResponse | null> {\n const { onRemoteDocumentDeleted, unavailableError, ...resolutionInput } =\n input;\n if (input.stillCurrent?.() === false) return null;\n if (input.apiClient.evictDocumentWriterProjection) {\n input.apiClient.evictDocumentWriterProjection(input.documentId);\n } else {\n input.apiClient.clearWriterProjectionCaches?.();\n }\n let remoteDocumentDeleted = false;\n const writerProjection = await resolveSyncAttemptWriterProjection({\n ...resolutionInput,\n onRemoteDocumentDeleted: async (deleted) => {\n remoteDocumentDeleted = true;\n await onRemoteDocumentDeleted?.(deleted);\n },\n reusableWriterProjection: null,\n });\n if (\n !writerProjection &&\n unavailableError !== undefined &&\n !remoteDocumentDeleted &&\n input.stillCurrent?.() !== false\n ) {\n throw unavailableError;\n }\n return writerProjection;\n}\n\nexport async function retrySyncPlanOrAbandon(input: {\n apiClient: DocumentSyncApi;\n buildWithProjection: (\n projection: DocumentWriterProjectionResponse,\n ) => Promise<MaterializedDocumentSyncPlan>;\n documentId: string;\n onRemoteDocumentDeleted?: RemoteDocumentDeletionHandler | undefined;\n onSyncAbandoned?: ((reason: string) => void) | undefined;\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n onTerminalFailure?: TerminalSubmitFailureHandler | undefined;\n stillCurrent?: (() => boolean) | undefined;\n writerProjection: DocumentWriterProjectionResponse;\n}): Promise<\n | readonly [MaterializedDocumentSyncPlan, DocumentWriterProjectionResponse]\n | null\n> {\n const planned = await retrySyncPlan(input);\n if (!planned && input.stillCurrent?.() !== false) {\n input.onSyncAbandoned?.(\n \"a sync plan could not be built against the current projection\",\n );\n }\n return planned;\n}\n"]}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { traceAncestorRepairAbandoned } from "../sync/syncTrace.js";
|
|
2
2
|
import { DocumentAncestorRepairAbandonedError } from "./syncRepairAbandon.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the pass finishes a pull that already fetched a page: it resumes
|
|
5
|
+
* from a cursor, or restarts after its cursor expired.
|
|
6
|
+
*/
|
|
7
|
+
export function isPullUnderWay(input) {
|
|
8
|
+
return (input.pullContinuation !== undefined || input.pullRecoveryRequired === true);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether a held organization stops this read-only pass. Only the start of a
|
|
12
|
+
* routine pull of a document the device has already pulled is held. A first
|
|
13
|
+
* pull still runs, so a document the device has listed can still be opened;
|
|
14
|
+
* a pull that has fetched a page runs to its end, first pull or not, even
|
|
15
|
+
* when an expired cursor makes it start over, so no document is left half
|
|
16
|
+
* pulled; and so does an explicit read of raw history.
|
|
17
|
+
*/
|
|
18
|
+
export function isRoutinePullHeld(input, organizationId) {
|
|
19
|
+
return (input.historyMode !== "raw" &&
|
|
20
|
+
!isPullUnderWay(input) &&
|
|
21
|
+
input.minLsn !== undefined &&
|
|
22
|
+
(input.isRemoteSyncBlocked?.(organizationId, "pull") ?? false));
|
|
23
|
+
}
|
|
3
24
|
export function abandonBlockedSync(input) {
|
|
4
25
|
input.onSyncTrace?.(`document sync blocked document=${input.documentId}`);
|
|
5
26
|
input.onSyncAbandoned?.("blocked");
|
|
@@ -1 +1 @@
|
|
|
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,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,KAAK,CAAC,WAAW,EAAE,CAAC,kCAAkC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;IAC1E,KAAK,CAAC,eAAe,EAAE,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAyB,EACzB,KAA2C;IAE3C,uEAAuE;IACvE,yEAAyE;IACzE,yEAAyE;IACzE,4BAA4B,CAAC,KAAK,CAAC,WAAW,EAAE;QAC9C,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAC;IACH,KAAK,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,KAAyB,EACzB,KAA0C;IAE1C,MAAM,KAAK,CAAC,uBAAuB,EAAE,CAAC;QACpC,IAAI,EAAE,uCAAuC;QAC7C,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IACH,OAAO,qBAAqB,CAC1B,KAAK,EACL,IAAI,oCAAoC,CAAC,cAAc,CAAC,CACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAyB;IAEzB,KAAK,CAAC,eAAe,EAAE,CAAC,6CAA6C,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,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,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,KAAK,CAAC,WAAW,EAAE,CAAC,kCAAkC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;IAC1E,KAAK,CAAC,eAAe,EAAE,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAyB,EACzB,KAA2C;IAE3C,uEAAuE;IACvE,yEAAyE;IACzE,yEAAyE;IACzE,4BAA4B,CAAC,KAAK,CAAC,WAAW,EAAE;QAC9C,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAC;IACH,KAAK,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,KAAyB,EACzB,KAA0C;IAE1C,MAAM,KAAK,CAAC,uBAAuB,EAAE,CAAC;QACpC,IAAI,EAAE,uCAAuC;QAC7C,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IACH,OAAO,qBAAqB,CAC1B,KAAK,EACL,IAAI,oCAAoC,CAAC,cAAc,CAAC,CACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAyB;IAEzB,KAAK,CAAC,eAAe,EAAE,CAAC,6CAA6C,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,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\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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AAO,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,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;YAClE,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,KAGrD;IACC,IAAI,MAAM,6BAA6B,CAAC,KAAK,CAAC;QAAE,OAAO;IACvD,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CACpC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC,CACtE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,KAAkC;IAElC,MAAM,MAAM,GAAG,iCAAiC,CAAC,KAAK,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,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,WAAW,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,KAAkC,EAClC,MAA8B;IAE9B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,2BAA2B,EAAE,CAAC;IACrE,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CACjC,KAAK,CAAC,OAAO,EACb,aAAa,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,qBAAqB,EAAE,CAAC,CACpE,CAAC;IACF,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AK,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"]}
|