@tearleads/client-sdk 0.1.252 → 0.1.254
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/Tearleads.js +3 -3
- package/Tearleads.js.map +1 -1
- package/client/containerContents/documentDiscovery.js +0 -2
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/client/containerContents/index.d.ts +2 -0
- package/client/containerContents/index.js +4 -9
- package/client/containerContents/index.js.map +1 -1
- package/client/containerContents/storeRuntime.d.ts +17 -0
- package/client/containerContents/storeRuntime.js +31 -0
- package/client/containerContents/storeRuntime.js.map +1 -0
- package/client/deviceFirst/index.d.ts +2 -3
- package/client/deviceFirst/index.js +44 -22
- package/client/deviceFirst/index.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +2 -0
- package/client/runtime/workflowRuntime.js +13 -6
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +7 -10
- package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
- package/data/persistence/container-contents/containerDeletionPersistence.js +5 -1
- package/data/persistence/container-contents/containerDeletionPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerHydrationPersistence.js +1 -1
- package/data/persistence/container-contents/containerHydrationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js +11 -4
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerRemovalMetadata.js +47 -0
- package/data/persistence/container-contents/containerRemovalMetadata.js.map +1 -0
- package/data/persistence/container-contents/containerRemovalPlacements.js +22 -0
- package/data/persistence/container-contents/containerRemovalPlacements.js.map +1 -0
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.d.ts +2 -1
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.js +10 -2
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.js.map +1 -1
- package/data/persistence/documents/documentDiscoveryCandidate.d.ts +1 -0
- package/data/persistence/documents/documentDiscoveryCandidate.js +3 -1
- package/data/persistence/documents/documentDiscoveryCandidate.js.map +1 -1
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.d.ts +1 -1
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js +16 -4
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js.map +1 -1
- package/data/sqlite/migrations/localSchemaMigrations.js +11 -0
- package/data/sqlite/migrations/localSchemaMigrations.js.map +1 -1
- package/data/sqlite/schema/containerSyncWatermarkSchema.js +6 -3
- package/data/sqlite/schema/containerSyncWatermarkSchema.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +17 -0
- package/data/sync/syncCoordinator.js +17 -10
- package/data/sync/syncCoordinator.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +1 -0
- package/internal/api-client/client/apiClientContext.d.ts +1 -0
- package/internal/api-client/client/containerReads.d.ts +1 -0
- package/internal/api-client/requestInternals.js +14 -6
- package/internal/api-client/requestInternals.js.map +1 -1
- package/internal/validators/operation/containerReads.d.ts +29 -2
- package/internal/validators/operation/containerReads.js +2 -1
- package/internal/validators/operation/containerReads.js.map +1 -1
- package/internal/validators/request/containerDocumentLanes.d.ts +7 -0
- package/internal/validators/request/containerDocumentLanes.js +6 -0
- package/internal/validators/request/containerDocumentLanes.js.map +1 -1
- package/internal/validators/response/container.d.ts +8 -0
- package/internal/validators/response/container.js +1 -0
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/containerParentLanes.d.ts +2 -0
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +3 -9
- package/stores/container-contents/containerContentsStore.js +24 -21
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/containerState/storeScope.js +6 -0
- package/stores/container-contents/containerState/storeScope.js.map +1 -0
- package/stores/container-contents/hydration/backgroundHydration.js +2 -1
- package/stores/container-contents/hydration/backgroundHydration.js.map +1 -1
- package/stores/container-contents/hydration/reconnectRefresh.d.ts +10 -0
- package/stores/container-contents/hydration/reconnectRefresh.js +68 -0
- package/stores/container-contents/hydration/reconnectRefresh.js.map +1 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js +49 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js.map +1 -0
- package/stores/container-contents/hydration/remoteHydrationRefresh.js +4 -1
- package/stores/container-contents/hydration/remoteHydrationRefresh.js.map +1 -1
- package/stores/container-contents/hydration/remoteHydrationRequest.js +79 -10
- package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -1
- package/stores/container-contents/hydration/startupHydration.js +2 -9
- package/stores/container-contents/hydration/startupHydration.js.map +1 -1
- package/stores/container-contents/hydration/treeResetMachine.js +61 -0
- package/stores/container-contents/hydration/treeResetMachine.js.map +1 -0
- package/stores/container-contents/localRefresh.js +28 -12
- package/stores/container-contents/localRefresh.js.map +1 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js +4 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -1
- package/stores/container-contents/remoteWrites/writeGeneration.js +5 -2
- package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -1
- package/stores/container-contents/state.d.ts +3 -7
- package/stores/container-contents/state.js +27 -16
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/syncAgent/index.d.ts +7 -2
- package/stores/container-contents/syncAgent/index.js +77 -49
- package/stores/container-contents/syncAgent/index.js.map +1 -1
- package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +5 -2
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js +6 -3
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/stores/local-projection/localProjectionStore.js +24 -15
- package/stores/local-projection/localProjectionStore.js.map +1 -1
- package/stores/local-projection/registry.js +2 -2
- package/stores/local-projection/registry.js.map +1 -1
- package/workflows/container-contents/container-state/create/createChild.js +3 -15
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +4 -8
- package/workflows/container-contents/containerPersistence.js +22 -12
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/containerDocumentListing.js +52 -4
- package/workflows/container-contents/documentDiscovery/containerDocumentListing.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js +4 -2
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js +17 -12
- package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryTypes.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/publicationWatermark.js +15 -0
- package/workflows/container-contents/documentDiscovery/publicationWatermark.js.map +1 -0
- package/workflows/container-contents/localState.js +3 -0
- package/workflows/container-contents/localState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.d.ts +12 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js +93 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js.map +1 -0
- package/workflows/container-contents/remoteHydration/index.d.ts +3 -11
- package/workflows/container-contents/remoteHydration/index.js +17 -66
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js +3 -2
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/restorationReceipt.js +25 -0
- package/workflows/container-contents/remoteHydration/lanes/restorationReceipt.js.map +1 -0
- package/workflows/container-contents/remoteHydration/lanes/tombstoneAccess.js +107 -0
- package/workflows/container-contents/remoteHydration/lanes/tombstoneAccess.js.map +1 -0
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js +57 -5
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +129 -84
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +32 -10
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js +67 -24
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +16 -1
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/remoteReset/remoteResetCursorScope.js +3 -3
- package/workflows/container-contents/remoteReset/remoteResetCursorScope.js.map +1 -1
- package/workflows/container-contents/runtime.d.ts +3 -0
- package/workflows/container-contents/runtime.js.map +1 -1
- package/workflows/container-contents/storedContainerState.js +17 -7
- package/workflows/container-contents/storedContainerState.js.map +1 -1
- package/workflows/container-contents/syncLane.d.ts +1 -0
- package/workflows/container-contents/syncLane.js +9 -1
- package/workflows/container-contents/syncLane.js.map +1 -1
- package/workflows/container-contents/syncPause/discoveryGuard.js +6 -2
- package/workflows/container-contents/syncPause/discoveryGuard.js.map +1 -1
- package/workflows/container-contents/tombstones/documentTombstoneGate.js +6 -3
- package/workflows/container-contents/tombstones/documentTombstoneGate.js.map +1 -1
- package/workflows/shared/runtimeInput.d.ts +2 -0
- package/workflows/shared/runtimeInput.js.map +1 -1
- package/workflows/container-contents/remoteHydration/completeHydration.js +0 -25
- package/workflows/container-contents/remoteHydration/completeHydration.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerPageHydration.js","sourceRoot":"","sources":["remoteContainerPageHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,GAE/B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO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AY;YACZ,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK;YACL,eAAe;YACf,eAAe;YACf,gBAAgB;YAChB,KAAK;SACN,CAAC,CAAC;QACH,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;QACpC,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC;QAE7B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import {\n createPrincipalPolicyOperation,\n type PrincipalPolicyOperation,\n} from \"../../../principals/principalPolicyService\";\nimport { prefetchDestinationProjections } from \"../destination/destinationPrefetch\";\nimport { cachedDestinationRole } from \"../destination/destinationRoleCache\";\nimport { markContainerParentLaneFetched } from \"../lanes/laneFetchMarkers\";\nimport { fetchContainerParentLaneBatch } from \"../lanes/parentLaneFetch\";\nimport { cacheRemoteContainerPrincipalPolicies } from \"../principalPolicyCache\";\nimport {\n applyContainerTombstones,\n getApplicableRemoteContainerItems,\n} from \"../tombstoneApplication\";\nimport type {\n ContainerChildIndex,\n ContainerParentHydrationLane,\n ExpectedContainerState,\n FetchedContainerParentLanePage,\n ListedRemoteContainerPageItem,\n QueueContainerParentLane,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { containerStateMatchesFingerprint } from \"./containerStateFingerprint\";\nimport { loadPausedContainerFilter } from \"./organizationSyncPauseFilter\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainerState\";\n\nconst CONTAINER_PARENT_HYDRATION_CONCURRENCY = 4;\n\ninterface HydrationProgress {\n changedCount: number;\n complete: boolean;\n shouldStop: boolean;\n}\n// Re-checked inside the commit: a pause from another device can land after\n// the page was filtered, and its cleanup may already have run.\nfunction currentUnlessPaused(\n input: {\n isCurrent?: (() => boolean) | undefined;\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n },\n container: ListedRemoteContainerPageItem,\n): () => boolean {\n return () => input.isCurrent?.() !== false && !input.isPaused(container);\n}\n\n/** The local state still matches the fingerprint the listing was read at. */\nfunction matchesListedState(\n state: RemoteContainerHydrationState,\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>,\n containerId: string,\n): boolean {\n return containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint: expectedContainerStates.get(containerId)?.fingerprint,\n });\n}\n\nasync function applyRemoteContainerPage(input: {\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: FetchedContainerParentLanePage[\"expectedHydrationTombstones\"];\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n /** Live pause check; a pause arriving mid-page stops the commit. */\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n items: ReadonlyArray<ListedRemoteContainerPageItem>;\n /** The hydration pass's token: its pages share one directory discovery. */\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; completed: boolean }> {\n const {\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n items,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let hydratedCount = 0;\n let pageCompleted = true;\n await cacheRemoteContainerPrincipalPolicies({\n cacheReferencedPrincipalPolicies:\n state.runtime.principalPolicies.createWarmer({\n operation: input.policyOperation,\n }),\n remoteContainers: items,\n stillCurrent: input.isCurrent,\n });\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, completed: false };\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: items,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: items,\n state,\n }),\n ]);\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, completed: false };\n }\n const prefetchedProjections = await prefetchDestinationProjections({\n containers: items.filter(\n (item) =>\n !seenContainerIds.has(item.id) &&\n !state.containersById.has(item.id) &&\n !expectedHydrationTombstones.get(item.id) &&\n !cachedDestinationRole(state.runtime.infra.execSql, item),\n ),\n isCurrent: input.isCurrent,\n runtime: state.runtime,\n });\n for (const container of items) {\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, completed: false };\n }\n if (seenContainerIds.has(container.id)) {\n queueParentLane(container.id);\n continue;\n }\n if (!matchesListedState(state, expectedContainerStates, container.id)) {\n pageCompleted = false;\n continue;\n }\n const upserted = await upsertIsolatedRemoteContainerState({\n childIdsByParentId,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host,\n isCurrent: currentUnlessPaused(input, container),\n expectedHydrationTombstone:\n expectedHydrationTombstones.get(container.id) ?? null,\n prefetchedProjection: prefetchedProjections.get(container.id),\n remoteContainer: container,\n state,\n });\n if (!upserted) {\n pageCompleted = false;\n continue;\n }\n seenContainerIds.add(container.id);\n hydratedCount += 1;\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, completed: false };\n }\n queueParentLane(container.id);\n }\n\n return { changedCount: hydratedCount, completed: pageCompleted };\n}\n\nexport function canHydrateRemoteContainers(\n state: RemoteContainerHydrationState,\n): boolean {\n return (\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online &&\n state.runtime.infra.dbStatus === \"ready\"\n );\n}\n\nasync function applyContainerParentLanePage(input: {\n childIdsByParentId: ContainerChildIndex;\n fetchedPage: FetchedContainerParentLanePage;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n policyOperation: PrincipalPolicyOperation;\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPage,\n host,\n queueContinuationLane,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n const {\n expectedContainerStates,\n expectedHydrationTombstones,\n lane,\n response,\n syncLane,\n } = fetchedPage;\n let changedCount = 0;\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const remoteContainerItems = getApplicableRemoteContainerItems(response);\n const tombstoneResult = await applyContainerTombstones({\n childIdsByParentId,\n expectedContainerStates,\n isCurrent: input.isCurrent,\n remoteContainerItems,\n response,\n state,\n });\n if (!tombstoneResult.current) {\n return { changedCount, complete: false, shouldStop: true };\n }\n changedCount += tombstoneResult.changedCount;\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (tombstoneResult.changedCount > 0) {\n // A live tombstone cascade may have orphaned documents (row 3); re-arm\n // document priming so their null-scoped passes run now rather than on\n // the next startup.\n host.requestDocumentPriming?.();\n }\n\n // A paused organization's containers stay as the device last saw them.\n // Skipping them here, after tombstones saw the full page, still lets the\n // lane complete and its watermark advance; their children are never queued.\n const isPaused = await loadPausedContainerFilter(state);\n const appliedPage = await applyRemoteContainerPage({\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n isCurrent: input.isCurrent,\n isPaused,\n items: remoteContainerItems.filter((item) => !isPaused(item)),\n policyOperation: input.policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += appliedPage.changedCount;\n if (!tombstoneResult.completed || !appliedPage.completed) {\n // Keep this page retryable without discarding independent lanes, including\n // children of roots first discovered here. Otherwise the root becomes known\n // but its children are never fetched by subsequent root-only refreshes.\n return { changedCount, complete: false, shouldStop: false };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const didMarkFetched = await markContainerParentLaneFetched({\n isCurrent: input.isCurrent,\n response,\n state,\n syncLane,\n });\n if (!didMarkFetched) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n if (!response.hasMore) {\n return { changedCount, complete: true, shouldStop: false };\n }\n if (!response.nextWatermark) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n queueContinuationLane({\n parentId: lane.parentId,\n watermark: response.nextWatermark,\n });\n return { changedCount, complete: true, shouldStop: false };\n}\n\nfunction takeContainerParentLaneBatch(input: {\n lanes: ContainerParentHydrationLane[];\n state: RemoteContainerHydrationState;\n}): ContainerParentHydrationLane[] {\n const { lanes, state } = input;\n const batch: ContainerParentHydrationLane[] = [];\n\n while (\n lanes.length > 0 &&\n batch.length < CONTAINER_PARENT_HYDRATION_CONCURRENCY\n ) {\n const lane = lanes.shift();\n if (\n lane &&\n (lane.parentId === null || state.containersById.has(lane.parentId))\n ) {\n batch.push(lane);\n }\n }\n\n return batch;\n}\n\nasync function applyContainerParentLaneBatch(input: {\n childIdsByParentId: ContainerChildIndex;\n fetchedPages: ReadonlyArray<FetchedContainerParentLanePage>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPages,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let complete = true;\n\n for (const fetchedPage of fetchedPages) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (\n fetchedPage.lane.parentId !== null &&\n !state.containersById.has(fetchedPage.lane.parentId)\n ) {\n continue;\n }\n\n const result = await applyContainerParentLanePage({\n childIdsByParentId,\n fetchedPage,\n host,\n isCurrent: input.isCurrent,\n policyOperation: input.policyOperation,\n queueContinuationLane: (lane) => lanes.push(lane),\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n complete &&= result.complete;\n\n if (result.shouldStop) {\n return { changedCount, complete: false, shouldStop: true };\n }\n }\n\n return { changedCount, complete, shouldStop: false };\n}\n\nexport async function hydrateContainerParentLanes(input: {\n childIdsByParentId: ContainerChildIndex;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let complete = true;\n // One hydration pass is one policy operation: its pages share a discovery.\n const policyOperation = createPrincipalPolicyOperation();\n\n while (lanes.length > 0) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const batch = takeContainerParentLaneBatch({ lanes, state });\n if (batch.length === 0) {\n continue;\n }\n\n const fetchedPages = await fetchContainerParentLaneBatch({\n batch,\n isCurrent: input.isCurrent,\n state,\n });\n if (!fetchedPages) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const result = await applyContainerParentLaneBatch({\n childIdsByParentId,\n fetchedPages,\n host,\n isCurrent: input.isCurrent,\n lanes,\n policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n complete &&= result.complete;\n\n if (result.shouldStop) {\n return { changedCount, complete: false, shouldStop: true };\n }\n }\n\n return { changedCount, complete, shouldStop: false };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteContainerPageHydration.js","sourceRoot":"","sources":["remoteContainerPageHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8B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AC1B,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;QACD,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;YAClC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAAC;YACjD,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,kBAAkB;YAClB,YAAY;YACZ,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK;YACL,eAAe;YACf,eAAe;YACf,yBAAyB;YACzB,KAAK;SACN,CAAC,CAAC;QACH,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;QACpC,OAAO,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACtD,CAAC","sourcesContent":["import {\n createPrincipalPolicyOperation,\n type PrincipalPolicyOperation,\n} from \"../../../principals/principalPolicyService\";\nimport { changesDiscoveryOrder } from \"../../documentDiscovery/publicationWatermark\";\nimport { prefetchDestinationProjections } from \"../destination/destinationPrefetch\";\nimport { cachedDestinationRole } from \"../destination/destinationRoleCache\";\nimport { markContainerParentLaneFetched } from \"../lanes/laneFetchMarkers\";\nimport { fetchContainerParentLaneBatch } from \"../lanes/parentLaneFetch\";\nimport { warmListedContainerPolicies } from \"../principalPolicyCache\";\nimport {\n applyContainerTombstones,\n getApplicableRemoteContainerItems,\n} from \"../tombstoneApplication\";\nimport type {\n ContainerChildIndex,\n ContainerParentHydrationLane,\n ExpectedContainerState,\n FetchedContainerParentLanePage,\n HydrationOutcome,\n ListedRemoteContainerPageItem,\n QueueContainerParentLane,\n ReconnectPages,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { containerStateMatchesFingerprint } from \"./containerStateFingerprint\";\nimport { loadPausedContainerFilter } from \"./organizationSyncPauseFilter\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainerState\";\n\nconst CONTAINER_PARENT_HYDRATION_CONCURRENCY = 4;\n\ninterface HydrationProgress {\n changedCount: number;\n outcome: HydrationOutcome;\n shouldStop: boolean;\n}\n/** A retryable lane takes precedence over a refused proof elsewhere in the crawl. */\nfunction combineOutcomes(\n a: HydrationOutcome,\n b: HydrationOutcome,\n): HydrationOutcome {\n if (a === \"retry\" || b === \"retry\") return \"retry\";\n if (a === \"refused\" || b === \"refused\") return \"refused\";\n return \"complete\";\n}\n\n// Re-checked inside the commit: a pause from another device can land after\n// the page was filtered, and its cleanup may already have run.\nfunction currentUnlessPaused(\n input: {\n isCurrent?: (() => boolean) | undefined;\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n },\n container: ListedRemoteContainerPageItem,\n): () => boolean {\n return () => input.isCurrent?.() !== false && !input.isPaused(container);\n}\n\n/** The local state still matches the fingerprint the listing was read at. */\nfunction matchesListedState(\n state: RemoteContainerHydrationState,\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>,\n containerId: string,\n): boolean {\n return containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint: expectedContainerStates.get(containerId)?.fingerprint,\n });\n}\n\nasync function applyRemoteContainerPage(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: FetchedContainerParentLanePage[\"expectedHydrationTombstones\"];\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n items: ReadonlyArray<ListedRemoteContainerPageItem>;\n /** The hydration pass's token: its pages share one directory discovery. */\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerObservations: Map<string, string>;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; outcome: HydrationOutcome }> {\n const { seenContainerObservations, state } = input;\n let hydratedCount = 0;\n const { items, outcome: policyOutcome } = await warmListedContainerPolicies(\n input.items,\n state.runtime.principalPolicies.createWarmer({\n operation: input.policyOperation,\n }),\n input.reconnect?.recordManualError,\n input.isCurrent,\n );\n let outcome: HydrationOutcome = policyOutcome;\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, outcome: \"retry\" };\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: items,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: items,\n state,\n }),\n ]);\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, outcome: \"retry\" };\n }\n const prefetchedProjections = await prefetchDestinationProjections({\n containers: items.filter(\n (item) =>\n !seenContainerObservations.has(item.id) &&\n !state.containersById.has(item.id) &&\n !input.expectedHydrationTombstones.get(item.id) &&\n !cachedDestinationRole(state.runtime.infra.execSql, item),\n ),\n isCurrent: input.isCurrent,\n runtime: state.runtime,\n });\n for (const container of items) {\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, outcome: \"retry\" };\n }\n const observation = JSON.stringify(container);\n if (\n seenContainerObservations.get(container.id) === observation &&\n state.containersById.has(container.id)\n ) {\n input.queueParentLane(container.id);\n continue;\n }\n if (\n !matchesListedState(state, input.expectedContainerStates, container.id)\n ) {\n outcome = \"retry\";\n continue;\n }\n let failure: HydrationOutcome = \"retry\";\n const upserted = await upsertIsolatedRemoteContainerState(\n {\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host: input.host,\n isCurrent: currentUnlessPaused(input, container),\n expectedHydrationTombstone:\n input.expectedHydrationTombstones.get(container.id) ?? null,\n prefetchedProjection: prefetchedProjections.get(container.id),\n remoteContainer: container,\n state,\n },\n (outcome) => {\n failure = outcome;\n },\n input.reconnect?.recordManualError,\n );\n if (!upserted) {\n outcome = combineOutcomes(outcome, failure);\n continue;\n }\n seenContainerObservations.set(container.id, observation);\n hydratedCount += 1;\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, outcome: \"retry\" };\n }\n input.queueParentLane(container.id);\n }\n\n return { changedCount: hydratedCount, outcome };\n}\n\nexport function canHydrateRemoteContainers(\n state: RemoteContainerHydrationState,\n): boolean {\n return (\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online &&\n state.runtime.infra.dbStatus === \"ready\"\n );\n}\n\nfunction cursorKey(\n watermark: NonNullable<ContainerParentHydrationLane[\"watermark\"]>,\n): string {\n return JSON.stringify([watermark.updatedAt, watermark.id]);\n}\n\nfunction hasUnusableContinuation({\n lane,\n response,\n}: FetchedContainerParentLanePage): boolean {\n const next = response.nextWatermark;\n if (!next) return response.hasMore;\n // Opaque positions can advance with an older business timestamp.\n // A drained lane may echo its current position, but never an earlier one.\n if (\n next.id === lane.watermark?.id &&\n next.updatedAt === lane.watermark.updatedAt\n )\n return response.hasMore;\n return lane.continuationCursors?.has(cursorKey(next)) === true;\n}\n\nfunction queueNextPage(\n { lane, response }: FetchedContainerParentLanePage,\n skipWatermarkWrite: boolean,\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void,\n): void {\n if (response.hasMore && response.nextWatermark) {\n const continuationCursors = lane.continuationCursors ?? new Set<string>();\n if (lane.watermark) continuationCursors.add(cursorKey(lane.watermark));\n continuationCursors.add(cursorKey(response.nextWatermark));\n queueContinuationLane({\n parentId: lane.parentId,\n watermark: response.nextWatermark,\n skipWatermarkWrite,\n continuationCursors,\n });\n }\n}\n\nasync function checkpointPage(input: {\n reconnect?: ReconnectPages | undefined;\n fetchedPage: FetchedContainerParentLanePage;\n isCurrent?: (() => boolean) | undefined;\n state: RemoteContainerHydrationState;\n}): Promise<boolean> {\n const { lane, response, syncLane } = input.fetchedPage;\n // Only a drained chain can advance a reconnect checkpoint. Otherwise a\n // cycle can alternate the durable cursor between successive attempts.\n if (input.reconnect && response.hasMore) return true;\n const nextWatermark =\n response.nextWatermark ??\n (lane.continuationCursors ? (lane.watermark ?? null) : null);\n return markContainerParentLaneFetched({\n isCurrent: input.isCurrent,\n response: { ...response, nextWatermark },\n state: input.state,\n syncLane,\n });\n}\n\nasync function applyContainerParentLanePage(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n fetchedPage: FetchedContainerParentLanePage;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n policyOperation: PrincipalPolicyOperation;\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void;\n queueParentLane: QueueContainerParentLane;\n seenContainerObservations: Map<string, string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const { childIdsByParentId, fetchedPage, host, state } = input;\n const {\n expectedContainerStates,\n expectedHydrationTombstones,\n lane,\n response,\n } = fetchedPage;\n let changedCount = 0;\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n if (\n changesDiscoveryOrder(\n lane.watermark,\n response.nextWatermark,\n !!lane.continuationCursors,\n )\n )\n return { changedCount, outcome: \"retry\", shouldStop: false };\n const remoteContainerItems = getApplicableRemoteContainerItems(response);\n const isPaused = await loadPausedContainerFilter(state);\n const tombstoneResult = await applyContainerTombstones({\n isPaused,\n parentId: lane.parentId,\n childIdsByParentId,\n expectedContainerStates,\n isCurrent: input.isCurrent,\n remoteContainerItems,\n response,\n state,\n });\n if (!tombstoneResult.current) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n changedCount += tombstoneResult.changedCount;\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (tombstoneResult.changedCount > 0) {\n // Prime documents orphaned by this cascade during the current pass.\n host.requestDocumentPriming?.();\n }\n\n // Paused folders keep their local state while the lane advances.\n const appliedPage = await applyRemoteContainerPage({\n reconnect: input.reconnect,\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n isCurrent: input.isCurrent,\n isPaused,\n items: remoteContainerItems.filter((item) => !isPaused(item)),\n policyOperation: input.policyOperation,\n queueParentLane: input.queueParentLane,\n seenContainerObservations: input.seenContainerObservations,\n state,\n });\n changedCount += appliedPage.changedCount;\n const outcome = tombstoneResult.completed ? appliedPage.outcome : \"retry\";\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n // A bad continuation invalidates the cursor, independently verified rows still apply.\n if (hasUnusableContinuation(fetchedPage))\n return { changedCount, outcome: \"retry\", shouldStop: false };\n // A refused item leaves a gap in this lane. Later pages can still discover\n // independent children, but none may move its durable cursor past the gap.\n if (outcome !== \"complete\" && !input.reconnect)\n return { changedCount, outcome, shouldStop: false };\n const skipWatermarkWrite = lane.skipWatermarkWrite || outcome !== \"complete\";\n if (!skipWatermarkWrite && !(await checkpointPage(input))) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n queueNextPage(fetchedPage, skipWatermarkWrite, input.queueContinuationLane);\n return { changedCount, outcome, shouldStop: false };\n}\n\nfunction takeContainerParentLaneBatch(input: {\n lanes: ContainerParentHydrationLane[];\n state: RemoteContainerHydrationState;\n}): ContainerParentHydrationLane[] {\n const { lanes, state } = input;\n const batch: ContainerParentHydrationLane[] = [];\n\n while (\n lanes.length > 0 &&\n batch.length < CONTAINER_PARENT_HYDRATION_CONCURRENCY\n ) {\n const lane = lanes.shift();\n if (\n lane &&\n (lane.parentId === null || state.containersById.has(lane.parentId))\n ) {\n batch.push(lane);\n }\n }\n\n return batch;\n}\n\nasync function applyContainerParentLaneBatch(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n fetchedPages: ReadonlyArray<FetchedContainerParentLanePage>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerObservations: Map<string, string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPages,\n host,\n lanes,\n queueParentLane,\n seenContainerObservations,\n state,\n } = input;\n let changedCount = 0;\n let outcome: HydrationOutcome = \"complete\";\n\n for (const fetchedPage of fetchedPages) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (\n fetchedPage.lane.parentId !== null &&\n !state.containersById.has(fetchedPage.lane.parentId)\n ) {\n continue;\n }\n\n const result = await applyContainerParentLanePage({\n reconnect: input.reconnect,\n childIdsByParentId,\n fetchedPage,\n host,\n isCurrent: input.isCurrent,\n policyOperation: input.policyOperation,\n queueContinuationLane: (lane) => lanes.push(lane),\n queueParentLane,\n seenContainerObservations,\n state,\n });\n changedCount += result.changedCount;\n outcome = combineOutcomes(outcome, result.outcome);\n\n if (result.shouldStop) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n }\n\n return { changedCount, outcome, shouldStop: false };\n}\n\nexport async function hydrateContainerParentLanes(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n queueParentLane: QueueContainerParentLane;\n seenContainerObservations: Map<string, string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n host,\n lanes,\n queueParentLane,\n seenContainerObservations,\n state,\n } = input;\n let changedCount = 0;\n let outcome: HydrationOutcome = \"complete\";\n // One hydration pass is one policy operation: its pages share a discovery.\n const policyOperation = createPrincipalPolicyOperation();\n\n while (lanes.length > 0) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n const batch = takeContainerParentLaneBatch({ lanes, state });\n if (batch.length === 0) {\n continue;\n }\n\n const fetchedPages = await fetchContainerParentLaneBatch({\n batch,\n laneIdPrefix: input.reconnect?.laneIdPrefix,\n isCurrent: input.isCurrent,\n state,\n });\n if (!fetchedPages) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n const result = await applyContainerParentLaneBatch({\n reconnect: input.reconnect,\n childIdsByParentId,\n fetchedPages,\n host,\n isCurrent: input.isCurrent,\n lanes,\n policyOperation,\n queueParentLane,\n seenContainerObservations,\n state,\n });\n changedCount += result.changedCount;\n outcome = combineOutcomes(outcome, result.outcome);\n\n if (result.shouldStop) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n }\n\n return { changedCount, outcome, shouldStop: false };\n}\n"]}
|
package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { decodeVersionVector, encodeVersionVector, satisfiesVersionVector, } from "../../../../internal/loro/index.js";
|
|
2
2
|
import { isProjectionVerificationCancelledError } from "../../../../data/keyingProjectionVerification/types.js";
|
|
3
3
|
import { heldContainerBinding, listingRepeatsHeldOrdinaryBinding, } from "../../../../data/persistence/container-contents/containerBinding.js";
|
|
4
|
+
import { ProjectionDependencyUnavailableError } from "../../../../data/shared/dependencyUnavailable.js";
|
|
4
5
|
import { isKeyingVerificationError, runWithSecurityIncidentReporting, } from "../../../../data/shared/securityIncidents.js";
|
|
5
6
|
import { invalidateContainerProjectionCaches } from "../../container-state/projectionCache.js";
|
|
6
7
|
import { installContainerMetadataRecord } from "../../metadata/metadataPersistence.js";
|
|
@@ -153,10 +154,14 @@ async function updateExistingRemoteContainerState(input) {
|
|
|
153
154
|
systemSlot: remoteContainer.systemSlot ?? null,
|
|
154
155
|
organizationId: remoteContainer.organizationId,
|
|
155
156
|
...(nextParentId !== undefined ? { parentId: nextParentId } : {}),
|
|
156
|
-
}, false,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
}, false, {
|
|
158
|
+
...remoteContainerHydrationSaveOptions({
|
|
159
|
+
localUpdatedAt,
|
|
160
|
+
remoteContainer,
|
|
161
|
+
}),
|
|
162
|
+
verifiedPlacement: input.verifiedPlacement,
|
|
163
|
+
}, {
|
|
164
|
+
isCurrent: input.isCurrent,
|
|
160
165
|
preserveDurableStructureWhenPending: true,
|
|
161
166
|
});
|
|
162
167
|
if (persistenceResult.status === "missing") {
|
|
@@ -226,17 +231,24 @@ export async function upsertRemoteContainerState(input) {
|
|
|
226
231
|
if (input.isCurrent?.() === false)
|
|
227
232
|
return null;
|
|
228
233
|
invalidateListedProjectionCaches(input);
|
|
234
|
+
const backwardsClock = heldState?.container.serverUpdatedAt != null &&
|
|
235
|
+
heldState.container.serverUpdatedAt > listed.updatedAt;
|
|
229
236
|
const verified = await verifyRemoteContainerDestination({
|
|
230
237
|
...input,
|
|
231
238
|
heldBinding,
|
|
232
239
|
supersededListing,
|
|
233
|
-
refresh: !!input.expectedHydrationTombstone,
|
|
240
|
+
refresh: !!input.expectedHydrationTombstone || backwardsClock,
|
|
234
241
|
onVerifiedCheckpoint: (checkpoint) => {
|
|
235
242
|
expectedPlacementCheckpoint = checkpoint;
|
|
236
243
|
},
|
|
237
244
|
});
|
|
238
245
|
if (!verified || input.isCurrent?.() === false)
|
|
239
246
|
return null;
|
|
247
|
+
// A signed projection from a lagging replica can still repeat our old pin.
|
|
248
|
+
// Retry until it covers the manifest whose listing would be checkpointed.
|
|
249
|
+
if (backwardsClock &&
|
|
250
|
+
expectedPlacementCheckpoint?.manifestHash !== listed.metadataAccessStateHash)
|
|
251
|
+
return null;
|
|
240
252
|
input = { ...input, remoteContainer: verified };
|
|
241
253
|
const existingState = input.state.containersById.get(input.remoteContainer.id);
|
|
242
254
|
const remoteState = await runWithSecurityIncidentReporting(input.state.runtime.util.reportSecurityIncident, {
|
|
@@ -274,21 +286,31 @@ export async function upsertRemoteContainerState(input) {
|
|
|
274
286
|
* was already reported; returning no state leaves the item unapplied without
|
|
275
287
|
* blocking independent folders.
|
|
276
288
|
*/
|
|
277
|
-
export async function upsertIsolatedRemoteContainerState(input) {
|
|
289
|
+
export async function upsertIsolatedRemoteContainerState(input, recordIncompleteItem, recordUnavailable) {
|
|
278
290
|
try {
|
|
279
291
|
return await upsertRemoteContainerState(input);
|
|
280
292
|
}
|
|
281
293
|
catch (error) {
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
294
|
+
if (isKeyingVerificationError(error)) {
|
|
295
|
+
recordIncompleteItem?.("refused");
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
if (isProjectionVerificationCancelledError(error))
|
|
299
|
+
return null;
|
|
300
|
+
if (error instanceof ProjectionDependencyUnavailableError &&
|
|
301
|
+
recordUnavailable) {
|
|
302
|
+
recordUnavailable(error);
|
|
303
|
+
recordIncompleteItem?.("retry");
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
286
307
|
}
|
|
287
308
|
}
|
|
288
309
|
function persistVerifiedRemoteContainer(input) {
|
|
289
310
|
const { existingState, expectedPlacementCheckpoint } = input;
|
|
290
311
|
return existingState
|
|
291
312
|
? updateExistingRemoteContainerState({
|
|
313
|
+
verifiedPlacement: expectedPlacementCheckpoint,
|
|
292
314
|
childIdsByParentId: input.childIdsByParentId,
|
|
293
315
|
containerIdsWithPendingMetadataUpdates: input.containerIdsWithPendingMetadataUpdates,
|
|
294
316
|
containerIdsWithPendingStructuralIntents: input.containerIdsWithPendingStructuralIntents,
|
package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerState.js","sourceRoot":"","sources":["remoteContainerState.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sCAAsC,EAAE,MAAM,qDAAqD,CAAC;AAC7G,OAAO,EACL,oBAAoB,EACpB,iCAAiC,GAClC,MAAM,kEAAkE,CAAC;AAC1E,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAE5F,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EACL,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,EACnC,6CAA6C,GAC9C,MAAM,6BAA6B,CAAC;AAErC,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,2EAA2E;AAC3E,+EAA+E;AAC/E,8CAA8C;AAC9C,qFAAqF;AACrF,4E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C;YAE9C,MAAM,KAAK,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,8BAA8B,CACrC,KAGC;IAED,MAAM,EAAE,aAAa,EAAE,2BAA2B,EAAE,GAAG,KAAK,CAAC;IAC7D,OAAO,aAAa;QAClB,CAAC,CAAC,kCAAkC,CAAC;YACjC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,sCAAsC,EACpC,KAAK,CAAC,sCAAsC;YAC9C,wCAAwC,EACtC,KAAK,CAAC,wCAAwC;YAChD,aAAa;YACb,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACJ,CAAC,CAAC,0BAA0B,CAAC;YACzB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,0BAA0B,EAAE,KAAK,CAAC,0BAA0B,IAAI,IAAI;YACpE,2BAA2B;YAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n decodeVersionVector,\n encodeVersionVector,\n satisfiesVersionVector,\n} from \"@tearleads/loro\";\nimport { isProjectionVerificationCancelledError } from \"../../../../data/keyingProjectionVerification/types\";\nimport {\n heldContainerBinding,\n listingRepeatsHeldOrdinaryBinding,\n} from \"../../../../data/persistence/container-contents/containerBinding\";\nimport {\n isKeyingVerificationError,\n runWithSecurityIncidentReporting,\n} from \"../../../../data/shared/securityIncidents\";\nimport { invalidateContainerProjectionCaches } from \"../../container-state/projectionCache\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport { installContainerMetadataRecord } from \"../../metadata/metadataPersistence\";\nimport { projectionGeneration } from \"../../projectionGeneration\";\nimport type { PrefetchedDestinationProjection } from \"../destination/destinationPrefetch\";\nimport { verifyRemoteContainerDestination } from \"../destination/verifiedDestination\";\nimport { rebindReHomedContainer } from \"../heldContainerRebind\";\nimport {\n moveIndexedContainerChild,\n removeIndexedContainerChild,\n} from \"../lanes/childIndex\";\nimport {\n reconcileLocalOnlyRootContainers,\n reconcileLocalOnlySystemContainers,\n} from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { insertRemoteContainerState } from \"./insertRemoteContainer\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n resolveRemoteContainerHydrationLocalUpdatedAt,\n} from \"./remoteContainerTimestamps\";\n\n// Container ids (restricted to the inbound page) that carry an unsynced local\n// create or move intent. Such a container's parent and local-edit timestamp are\n// owned by its structural-intent lane until that lane reconciles, so inbound\n// hydration must not revert parentId to the server value nor collapse\n// localUpdatedAt — doing so silently undoes a queued move and falsely reads\n// \"synced\". Move intents are read via listUnsyncedMoveIntents so a blocked\n// move — one whose destination parent has not synced yet, the common boot-time\n// case — is protected too. Pending *metadata*\n// updates are handled separately (listRemoteContainerIdsWithPendingMetadataUpdates);\n// structural intents live in the local outbox's container lanes, which that\n// query does not cover.\nexport async function listRemoteContainerIdsWithPendingStructuralIntents(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n if (input.remoteContainers.length === 0) {\n return new Set();\n }\n const remoteContainerIds = new Set(\n input.remoteContainers.map((remoteContainer) => remoteContainer.id),\n );\n\n const execSql = input.state.runtime.infra.execSql;\n const [pendingCreateIntents, unsyncedMoveIntents] = await Promise.all([\n input.state.persistence.listPendingCreateIntents(execSql),\n input.state.persistence.listUnsyncedMoveIntents(execSql),\n ]);\n const containerIdsWithPendingStructuralIntents = new Set<string>();\n for (const intent of pendingCreateIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n for (const intent of unsyncedMoveIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n return containerIdsWithPendingStructuralIntents;\n}\n\nexport async function listRemoteContainerIdsWithPendingMetadataUpdates(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n const containerIds = input.remoteContainers.flatMap((remoteContainer) => {\n const previousLocalUpdatedAt = input.state.containersById.get(\n remoteContainer.id,\n )?.container.localUpdatedAt;\n\n return previousLocalUpdatedAt &&\n previousLocalUpdatedAt.localeCompare(remoteContainer.updatedAt) > 0\n ? [remoteContainer.id]\n : [];\n });\n if (containerIds.length === 0) {\n return new Set();\n }\n\n const execSql = input.state.runtime.infra.execSql;\n return new Set(\n await input.state.persistence.listContainerIdsWithPendingUpdates(\n execSql,\n containerIds,\n ),\n );\n}\n\nfunction removeMissingHydratedContainer(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n existingState: ContainerState;\n host: RemoteContainerHydrationHost;\n previousParentId: string | null;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): void {\n const { existingState, remoteContainer, state } = input;\n if (state.containersById.get(remoteContainer.id) !== existingState) {\n return;\n }\n\n state.containersById.delete(remoteContainer.id);\n if (input.childIdsByParentId) {\n removeIndexedContainerChild(\n input.childIdsByParentId,\n remoteContainer.id,\n input.previousParentId,\n );\n input.childIdsByParentId.delete(remoteContainer.id);\n }\n input.host.updateSnapshot();\n}\n\nfunction createUpdatedRemoteContainerState(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): ContainerState {\n return {\n ...existingState,\n container: applyRemoteContainerTimestamps(\n existingState.container,\n remoteContainer,\n ),\n containerWriterProjection: null,\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n };\n}\n\nfunction installUpdatedRemoteContainerState(\n existingState: ContainerState,\n nextState: ContainerState,\n host: RemoteContainerHydrationHost,\n): void {\n const wasLocalOnly = existingState.container.serverCreatedAt == null;\n existingState.container = nextState.container;\n existingState.containerWriterProjection = nextState.containerWriterProjection;\n existingState.metadataReferencedPrincipals =\n nextState.metadataReferencedPrincipals;\n // The snapshot copied the live generation when it was taken; a hint that\n // landed during the persist leaves the live metadata projection dropped.\n if (projectionGeneration(existingState) === projectionGeneration(nextState))\n existingState.metadataWriterProjection = nextState.metadataWriterProjection;\n installContainerMetadataRecord(existingState, nextState.record);\n // A document pass may have deferred while this root was awaiting proof.\n // The first durable remote acknowledgement makes its pending creates runnable.\n if (wasLocalOnly && existingState.container.serverCreatedAt != null)\n host.requestDocumentPriming?.();\n}\n\n/**\n * A clean metadata document is read only when a hint names it, and a hint sent\n * while this client was offline or not yet subscribed is lost. The listing\n * reports the version vector of every update the server holds for the metadata\n * document; when this client's copy does not cover it, an edit is unread. Owe\n * the read before this hydration advances the lane watermark past the row.\n */\nfunction coversMetadataVersion(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): boolean {\n const listed = remoteContainer.metadataVersionVector;\n try {\n // A document with no stored update is covered by any copy.\n if (decodeVersionVector(listed).toJSON().size === 0) return true;\n return satisfiesVersionVector(\n encodeVersionVector(existingState.doc),\n listed,\n );\n } catch {\n // An unreadable version proves nothing: owe the read, which pulls the\n // truth, and let the rest of the page hydrate.\n return false;\n }\n}\n\nasync function oweMetadataReadIfBehind(\n host: RemoteContainerHydrationHost,\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): Promise<void> {\n if (!coversMetadataVersion(existingState, remoteContainer)) {\n await host.requestMetadataRevalidation?.({\n advertisedVersionVector: remoteContainer.metadataVersionVector,\n documentId: remoteContainer.metadataDocumentId,\n });\n }\n}\n\nasync function updateExistingRemoteContainerState(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n existingState: ContainerState;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<ContainerState | null> {\n const { childIdsByParentId, existingState, host, remoteContainer, state } =\n input;\n const previousParentId = existingState.container.parentId;\n const previousLocalUpdatedAt = existingState.container.localUpdatedAt;\n // A queued, not-yet-synced local move/create owns this container's parent\n // until its intent lane reconciles. Omit the remote parent when the page scan\n // saw one; persistence also rechecks the intent transactionally so a move\n // created after that scan wins. Both paths preserve the durable local clock.\n const hasPendingStructuralIntent =\n input.containerIdsWithPendingStructuralIntents.has(remoteContainer.id);\n const nextParentId = hasPendingStructuralIntent\n ? undefined\n : remoteContainer.parentId;\n const localUpdatedAt = resolveRemoteContainerHydrationLocalUpdatedAt({\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n hasPendingStructuralIntent,\n previousLocalUpdatedAt,\n remoteContainer,\n });\n await oweMetadataReadIfBehind(host, existingState, remoteContainer);\n const nextState = createUpdatedRemoteContainerState(\n existingState,\n remoteContainer,\n );\n const persistenceResult = await host.persistContainerState(\n nextState,\n {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n organizationId: remoteContainer.organizationId,\n ...(nextParentId !== undefined ? { parentId: nextParentId } : {}),\n },\n false,\n remoteContainerHydrationSaveOptions({\n localUpdatedAt,\n remoteContainer,\n }),\n {\n preserveDurableStructureWhenPending: true,\n },\n );\n if (persistenceResult.status === \"missing\") {\n // Hydration persists a detached candidate so an in-flight response cannot\n // mutate mapped state before its guards settle. Retire the exact state this\n // hydration read because store-level reference cleanup cannot see the clone.\n removeMissingHydratedContainer({\n childIdsByParentId,\n existingState,\n host,\n previousParentId,\n remoteContainer,\n state,\n });\n return null;\n }\n if (persistenceResult.status !== \"persisted\") return null;\n const { record: nextRecord } = persistenceResult;\n installContainerMetadataRecord(nextState, nextRecord);\n if (input.isCurrent?.() === false) {\n return existingState;\n }\n nextState.container = {\n ...nextState.container,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n organizationId: remoteContainer.organizationId,\n parentId: nextState.container.parentId,\n };\n\n installUpdatedRemoteContainerState(existingState, nextState, host);\n moveIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n previousParentId,\n existingState.container.parentId,\n );\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: existingState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return existingState;\n}\n\ninterface UpsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone?: ContainerHydrationTombstone | null | undefined;\n isCurrent?: (() => boolean) | undefined;\n prefetchedProjection?: PrefetchedDestinationProjection | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\n/** A pull can observe the same manifest change as a missed realtime hint. */\nfunction invalidateListedProjectionCaches(\n input: UpsertRemoteContainerStateInput,\n) {\n const held = input.state.containersById.get(input.remoteContainer.id);\n if (\n held &&\n (held.record.accessStateHash !==\n input.remoteContainer.metadataAccessStateHash ||\n (held.container.effectiveAccessLevel ?? \"read\") !==\n input.remoteContainer.effectiveAccessLevel)\n ) {\n // Eviction admits no remote state. Drop citations before verification can\n // advance local checkpoints past those cached container/document paths.\n invalidateContainerProjectionCaches(input.state, [\n input.remoteContainer.id,\n ]);\n }\n}\n\nexport async function upsertRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n let expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n const heldState = input.state.containersById.get(input.remoteContainer.id);\n const heldBinding = heldState\n ? heldContainerBinding(heldState)\n : await input.state.persistence.loadHeldContainerBinding(\n input.state.runtime.infra.execSql,\n input.remoteContainer.id,\n );\n const listed = input.remoteContainer;\n // A folder re-homed away from the listed organization never returns there,\n // whatever binding (possibly none, after a reset) the device holds now.\n const supersededListing =\n !listingRepeatsHeldOrdinaryBinding(heldBinding, listed) &&\n (await input.state.persistence.isSupersededContainerBinding(\n input.state.runtime.infra.execSql,\n { containerId: listed.id, organizationId: listed.organizationId },\n ));\n if (input.isCurrent?.() === false) return null;\n invalidateListedProjectionCaches(input);\n const verified = await verifyRemoteContainerDestination({\n ...input,\n heldBinding,\n supersededListing,\n refresh: !!input.expectedHydrationTombstone,\n onVerifiedCheckpoint: (checkpoint) => {\n expectedPlacementCheckpoint = checkpoint;\n },\n });\n if (!verified || input.isCurrent?.() === false) return null;\n input = { ...input, remoteContainer: verified };\n const existingState = input.state.containersById.get(\n input.remoteContainer.id,\n );\n const remoteState = await runWithSecurityIncidentReporting(\n input.state.runtime.util.reportSecurityIncident,\n {\n objectId: verified.id,\n objectKind: \"container\",\n operation: \"container.binding.persist\",\n organizationId: verified.organizationId,\n },\n async () =>\n (await rebindReHomedContainer({\n existingState,\n heldBinding,\n isCurrent: input.isCurrent,\n state: input.state,\n verified,\n }))\n ? persistVerifiedRemoteContainer({\n ...input,\n existingState,\n expectedPlacementCheckpoint,\n })\n : null,\n );\n if (!remoteState) {\n return null;\n }\n await reconcileLocalOnlySystemContainers({\n childIdsByParentId: input.childIdsByParentId,\n isCurrent: input.isCurrent,\n requestDocumentPriming: input.host.requestDocumentPriming,\n remoteSystemState: remoteState,\n state: input.state,\n });\n return remoteState;\n}\n\n/**\n * Upsert one listed folder, isolating a rejected proof or binding. The refusal\n * was already reported; returning no state leaves the item unapplied without\n * blocking independent folders.\n */\nexport async function upsertIsolatedRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n try {\n return await upsertRemoteContainerState(input);\n } catch (error) {\n if (\n !isKeyingVerificationError(error) &&\n !isProjectionVerificationCancelledError(error)\n )\n throw error;\n return null;\n }\n}\n\nfunction persistVerifiedRemoteContainer(\n input: UpsertRemoteContainerStateInput & {\n existingState: ContainerState | undefined;\n expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n },\n): Promise<ContainerState | null> {\n const { existingState, expectedPlacementCheckpoint } = input;\n return existingState\n ? updateExistingRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents:\n input.containerIdsWithPendingStructuralIntents,\n existingState,\n host: input.host,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n })\n : insertRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n host: input.host,\n expectedHydrationTombstone: input.expectedHydrationTombstone ?? null,\n expectedPlacementCheckpoint,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteContainerState.js","sourceRoot":"","sources":["remoteContainerState.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sCAAsC,EAAE,MAAM,qDAAqD,CAAC;AAC7G,OAAO,EACL,oBAAoB,EACpB,iCAAiC,GAClC,MAAM,kEAAkE,CAAC;AAC1E,OAAO,EAAE,oCAAoC,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAE5F,OAAO,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B,EAAE,CAAC,OAAO,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,8BAA8B,CACrC,KAGC;IAED,MAAM,EAAE,aAAa,EAAE,2BAA2B,EAAE,GAAG,KAAK,CAAC;IAC7D,OAAO,aAAa;QAClB,CAAC,CAAC,kCAAkC,CAAC;YACjC,iBAAiB,EAAE,2BAA2B;YAC9C,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,sCAAsC,EACpC,KAAK,CAAC,sCAAsC;YAC9C,wCAAwC,EACtC,KAAK,CAAC,wCAAwC;YAChD,aAAa;YACb,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACJ,CAAC,CAAC,0BAA0B,CAAC;YACzB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,0BAA0B,EAAE,KAAK,CAAC,0BAA0B,IAAI,IAAI;YACpE,2BAA2B;YAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n decodeVersionVector,\n encodeVersionVector,\n satisfiesVersionVector,\n} from \"@tearleads/loro\";\nimport { isProjectionVerificationCancelledError } from \"../../../../data/keyingProjectionVerification/types\";\nimport {\n heldContainerBinding,\n listingRepeatsHeldOrdinaryBinding,\n} from \"../../../../data/persistence/container-contents/containerBinding\";\nimport { ProjectionDependencyUnavailableError } from \"../../../../data/shared/dependencyUnavailable\";\nimport {\n isKeyingVerificationError,\n runWithSecurityIncidentReporting,\n} from \"../../../../data/shared/securityIncidents\";\nimport { invalidateContainerProjectionCaches } from \"../../container-state/projectionCache\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport { installContainerMetadataRecord } from \"../../metadata/metadataPersistence\";\nimport { projectionGeneration } from \"../../projectionGeneration\";\nimport type { PrefetchedDestinationProjection } from \"../destination/destinationPrefetch\";\nimport { verifyRemoteContainerDestination } from \"../destination/verifiedDestination\";\nimport { rebindReHomedContainer } from \"../heldContainerRebind\";\nimport {\n moveIndexedContainerChild,\n removeIndexedContainerChild,\n} from \"../lanes/childIndex\";\nimport {\n reconcileLocalOnlyRootContainers,\n reconcileLocalOnlySystemContainers,\n} from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { insertRemoteContainerState } from \"./insertRemoteContainer\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n resolveRemoteContainerHydrationLocalUpdatedAt,\n} from \"./remoteContainerTimestamps\";\n\n// Container ids (restricted to the inbound page) that carry an unsynced local\n// create or move intent. Such a container's parent and local-edit timestamp are\n// owned by its structural-intent lane until that lane reconciles, so inbound\n// hydration must not revert parentId to the server value nor collapse\n// localUpdatedAt — doing so silently undoes a queued move and falsely reads\n// \"synced\". Move intents are read via listUnsyncedMoveIntents so a blocked\n// move — one whose destination parent has not synced yet, the common boot-time\n// case — is protected too. Pending *metadata*\n// updates are handled separately (listRemoteContainerIdsWithPendingMetadataUpdates);\n// structural intents live in the local outbox's container lanes, which that\n// query does not cover.\nexport async function listRemoteContainerIdsWithPendingStructuralIntents(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n if (input.remoteContainers.length === 0) {\n return new Set();\n }\n const remoteContainerIds = new Set(\n input.remoteContainers.map((remoteContainer) => remoteContainer.id),\n );\n\n const execSql = input.state.runtime.infra.execSql;\n const [pendingCreateIntents, unsyncedMoveIntents] = await Promise.all([\n input.state.persistence.listPendingCreateIntents(execSql),\n input.state.persistence.listUnsyncedMoveIntents(execSql),\n ]);\n const containerIdsWithPendingStructuralIntents = new Set<string>();\n for (const intent of pendingCreateIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n for (const intent of unsyncedMoveIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n return containerIdsWithPendingStructuralIntents;\n}\n\nexport async function listRemoteContainerIdsWithPendingMetadataUpdates(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n const containerIds = input.remoteContainers.flatMap((remoteContainer) => {\n const previousLocalUpdatedAt = input.state.containersById.get(\n remoteContainer.id,\n )?.container.localUpdatedAt;\n\n return previousLocalUpdatedAt &&\n previousLocalUpdatedAt.localeCompare(remoteContainer.updatedAt) > 0\n ? [remoteContainer.id]\n : [];\n });\n if (containerIds.length === 0) {\n return new Set();\n }\n\n const execSql = input.state.runtime.infra.execSql;\n return new Set(\n await input.state.persistence.listContainerIdsWithPendingUpdates(\n execSql,\n containerIds,\n ),\n );\n}\n\nfunction removeMissingHydratedContainer(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n existingState: ContainerState;\n host: RemoteContainerHydrationHost;\n previousParentId: string | null;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): void {\n const { existingState, remoteContainer, state } = input;\n if (state.containersById.get(remoteContainer.id) !== existingState) {\n return;\n }\n\n state.containersById.delete(remoteContainer.id);\n if (input.childIdsByParentId) {\n removeIndexedContainerChild(\n input.childIdsByParentId,\n remoteContainer.id,\n input.previousParentId,\n );\n input.childIdsByParentId.delete(remoteContainer.id);\n }\n input.host.updateSnapshot();\n}\n\nfunction createUpdatedRemoteContainerState(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): ContainerState {\n return {\n ...existingState,\n container: applyRemoteContainerTimestamps(\n existingState.container,\n remoteContainer,\n ),\n containerWriterProjection: null,\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n };\n}\n\nfunction installUpdatedRemoteContainerState(\n existingState: ContainerState,\n nextState: ContainerState,\n host: RemoteContainerHydrationHost,\n): void {\n const wasLocalOnly = existingState.container.serverCreatedAt == null;\n existingState.container = nextState.container;\n existingState.containerWriterProjection = nextState.containerWriterProjection;\n existingState.metadataReferencedPrincipals =\n nextState.metadataReferencedPrincipals;\n // The snapshot copied the live generation when it was taken; a hint that\n // landed during the persist leaves the live metadata projection dropped.\n if (projectionGeneration(existingState) === projectionGeneration(nextState))\n existingState.metadataWriterProjection = nextState.metadataWriterProjection;\n installContainerMetadataRecord(existingState, nextState.record);\n // A document pass may have deferred while this root was awaiting proof.\n // The first durable remote acknowledgement makes its pending creates runnable.\n if (wasLocalOnly && existingState.container.serverCreatedAt != null)\n host.requestDocumentPriming?.();\n}\n\n/**\n * A clean metadata document is read only when a hint names it, and a hint sent\n * while this client was offline or not yet subscribed is lost. The listing\n * reports the version vector of every update the server holds for the metadata\n * document; when this client's copy does not cover it, an edit is unread. Owe\n * the read before this hydration advances the lane watermark past the row.\n */\nfunction coversMetadataVersion(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): boolean {\n const listed = remoteContainer.metadataVersionVector;\n try {\n // A document with no stored update is covered by any copy.\n if (decodeVersionVector(listed).toJSON().size === 0) return true;\n return satisfiesVersionVector(\n encodeVersionVector(existingState.doc),\n listed,\n );\n } catch {\n // An unreadable version proves nothing: owe the read, which pulls the\n // truth, and let the rest of the page hydrate.\n return false;\n }\n}\n\nasync function oweMetadataReadIfBehind(\n host: RemoteContainerHydrationHost,\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): Promise<void> {\n if (!coversMetadataVersion(existingState, remoteContainer)) {\n await host.requestMetadataRevalidation?.({\n advertisedVersionVector: remoteContainer.metadataVersionVector,\n documentId: remoteContainer.metadataDocumentId,\n });\n }\n}\n\nasync function updateExistingRemoteContainerState(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n verifiedPlacement?: AccessManifestCheckpoint | undefined;\n existingState: ContainerState;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<ContainerState | null> {\n const { childIdsByParentId, existingState, host, remoteContainer, state } =\n input;\n const previousParentId = existingState.container.parentId;\n const previousLocalUpdatedAt = existingState.container.localUpdatedAt;\n // A queued, not-yet-synced local move/create owns this container's parent\n // until its intent lane reconciles. Omit the remote parent when the page scan\n // saw one; persistence also rechecks the intent transactionally so a move\n // created after that scan wins. Both paths preserve the durable local clock.\n const hasPendingStructuralIntent =\n input.containerIdsWithPendingStructuralIntents.has(remoteContainer.id);\n const nextParentId = hasPendingStructuralIntent\n ? undefined\n : remoteContainer.parentId;\n const localUpdatedAt = resolveRemoteContainerHydrationLocalUpdatedAt({\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n hasPendingStructuralIntent,\n previousLocalUpdatedAt,\n remoteContainer,\n });\n await oweMetadataReadIfBehind(host, existingState, remoteContainer);\n const nextState = createUpdatedRemoteContainerState(\n existingState,\n remoteContainer,\n );\n const persistenceResult = await host.persistContainerState(\n nextState,\n {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n organizationId: remoteContainer.organizationId,\n ...(nextParentId !== undefined ? { parentId: nextParentId } : {}),\n },\n false,\n {\n ...remoteContainerHydrationSaveOptions({\n localUpdatedAt,\n remoteContainer,\n }),\n verifiedPlacement: input.verifiedPlacement,\n },\n {\n isCurrent: input.isCurrent,\n preserveDurableStructureWhenPending: true,\n },\n );\n if (persistenceResult.status === \"missing\") {\n // Hydration persists a detached candidate so an in-flight response cannot\n // mutate mapped state before its guards settle. Retire the exact state this\n // hydration read because store-level reference cleanup cannot see the clone.\n removeMissingHydratedContainer({\n childIdsByParentId,\n existingState,\n host,\n previousParentId,\n remoteContainer,\n state,\n });\n return null;\n }\n if (persistenceResult.status !== \"persisted\") return null;\n const { record: nextRecord } = persistenceResult;\n installContainerMetadataRecord(nextState, nextRecord);\n if (input.isCurrent?.() === false) {\n return existingState;\n }\n nextState.container = {\n ...nextState.container,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n organizationId: remoteContainer.organizationId,\n parentId: nextState.container.parentId,\n };\n\n installUpdatedRemoteContainerState(existingState, nextState, host);\n moveIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n previousParentId,\n existingState.container.parentId,\n );\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: existingState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return existingState;\n}\n\ninterface UpsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone?: ContainerHydrationTombstone | null | undefined;\n isCurrent?: (() => boolean) | undefined;\n prefetchedProjection?: PrefetchedDestinationProjection | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\n/** A pull can observe the same manifest change as a missed realtime hint. */\nfunction invalidateListedProjectionCaches(\n input: UpsertRemoteContainerStateInput,\n) {\n const held = input.state.containersById.get(input.remoteContainer.id);\n if (\n held &&\n (held.record.accessStateHash !==\n input.remoteContainer.metadataAccessStateHash ||\n (held.container.effectiveAccessLevel ?? \"read\") !==\n input.remoteContainer.effectiveAccessLevel)\n ) {\n // Eviction admits no remote state. Drop citations before verification can\n // advance local checkpoints past those cached container/document paths.\n invalidateContainerProjectionCaches(input.state, [\n input.remoteContainer.id,\n ]);\n }\n}\n\nexport async function upsertRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n let expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n const heldState = input.state.containersById.get(input.remoteContainer.id);\n const heldBinding = heldState\n ? heldContainerBinding(heldState)\n : await input.state.persistence.loadHeldContainerBinding(\n input.state.runtime.infra.execSql,\n input.remoteContainer.id,\n );\n const listed = input.remoteContainer;\n // A folder re-homed away from the listed organization never returns there,\n // whatever binding (possibly none, after a reset) the device holds now.\n const supersededListing =\n !listingRepeatsHeldOrdinaryBinding(heldBinding, listed) &&\n (await input.state.persistence.isSupersededContainerBinding(\n input.state.runtime.infra.execSql,\n { containerId: listed.id, organizationId: listed.organizationId },\n ));\n if (input.isCurrent?.() === false) return null;\n invalidateListedProjectionCaches(input);\n const backwardsClock =\n heldState?.container.serverUpdatedAt != null &&\n heldState.container.serverUpdatedAt > listed.updatedAt;\n const verified = await verifyRemoteContainerDestination({\n ...input,\n heldBinding,\n supersededListing,\n refresh: !!input.expectedHydrationTombstone || backwardsClock,\n onVerifiedCheckpoint: (checkpoint) => {\n expectedPlacementCheckpoint = checkpoint;\n },\n });\n if (!verified || input.isCurrent?.() === false) return null;\n // A signed projection from a lagging replica can still repeat our old pin.\n // Retry until it covers the manifest whose listing would be checkpointed.\n if (\n backwardsClock &&\n expectedPlacementCheckpoint?.manifestHash !== listed.metadataAccessStateHash\n )\n return null;\n input = { ...input, remoteContainer: verified };\n const existingState = input.state.containersById.get(\n input.remoteContainer.id,\n );\n const remoteState = await runWithSecurityIncidentReporting(\n input.state.runtime.util.reportSecurityIncident,\n {\n objectId: verified.id,\n objectKind: \"container\",\n operation: \"container.binding.persist\",\n organizationId: verified.organizationId,\n },\n async () =>\n (await rebindReHomedContainer({\n existingState,\n heldBinding,\n isCurrent: input.isCurrent,\n state: input.state,\n verified,\n }))\n ? persistVerifiedRemoteContainer({\n ...input,\n existingState,\n expectedPlacementCheckpoint,\n })\n : null,\n );\n if (!remoteState) {\n return null;\n }\n await reconcileLocalOnlySystemContainers({\n childIdsByParentId: input.childIdsByParentId,\n isCurrent: input.isCurrent,\n requestDocumentPriming: input.host.requestDocumentPriming,\n remoteSystemState: remoteState,\n state: input.state,\n });\n return remoteState;\n}\n\n/**\n * Upsert one listed folder, isolating a rejected proof or binding. The refusal\n * was already reported; returning no state leaves the item unapplied without\n * blocking independent folders.\n */\nexport async function upsertIsolatedRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n recordIncompleteItem?: (outcome: \"refused\" | \"retry\") => void,\n recordUnavailable?:\n | ((error: ProjectionDependencyUnavailableError) => void)\n | undefined,\n): Promise<ContainerState | null> {\n try {\n return await upsertRemoteContainerState(input);\n } catch (error) {\n if (isKeyingVerificationError(error)) {\n recordIncompleteItem?.(\"refused\");\n return null;\n }\n if (isProjectionVerificationCancelledError(error)) return null;\n if (\n error instanceof ProjectionDependencyUnavailableError &&\n recordUnavailable\n ) {\n recordUnavailable(error);\n recordIncompleteItem?.(\"retry\");\n return null;\n }\n throw error;\n }\n}\n\nfunction persistVerifiedRemoteContainer(\n input: UpsertRemoteContainerStateInput & {\n existingState: ContainerState | undefined;\n expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n },\n): Promise<ContainerState | null> {\n const { existingState, expectedPlacementCheckpoint } = input;\n return existingState\n ? updateExistingRemoteContainerState({\n verifiedPlacement: expectedPlacementCheckpoint,\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents:\n input.containerIdsWithPendingStructuralIntents,\n existingState,\n host: input.host,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n })\n : insertRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n host: input.host,\n expectedHydrationTombstone: input.expectedHydrationTombstone ?? null,\n expectedPlacementCheckpoint,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n });\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isCanonicalSignedAt } from "../../../internal/validators/util/index.js";
|
|
2
2
|
import { removeIndexedContainerChild } from "./lanes/childIndex.js";
|
|
3
|
+
import { pendingFolderRestorations, recordFolderRestoration, } from "./lanes/restorationReceipt.js";
|
|
4
|
+
import { resolveTombstoneCascade } from "./lanes/tombstoneAccess.js";
|
|
3
5
|
import { containerStateMatchesFingerprint } from "./remoteContainers/containerStateFingerprint.js";
|
|
4
|
-
import { collectRemovedContainers } from "./tombstoneReasons.js";
|
|
5
6
|
function latestContainerItemsById(items) {
|
|
6
7
|
const latestItems = new Map();
|
|
7
8
|
for (const item of items) {
|
|
@@ -48,13 +49,15 @@ export function getApplicableRemoteContainerItems(response) {
|
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
async function applyContainerTombstoneCascade(input) {
|
|
51
|
-
const { childIdsByParentId, expectedContainerStates,
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const { childIdsByParentId, expectedContainerStates, state } = input;
|
|
53
|
+
const resolved = await resolveTombstoneCascade(input);
|
|
54
|
+
if (!resolved || input.isCurrent?.() === false)
|
|
55
|
+
return {
|
|
56
|
+
current: input.isCurrent?.() !== false,
|
|
57
|
+
removedCount: 0,
|
|
58
|
+
settled: false,
|
|
59
|
+
};
|
|
60
|
+
const { fenceOnlyContainerIds, absentDeletedContainerIds, removalByContainerId, removedContainerIds, } = resolved.cascade;
|
|
58
61
|
const affectedContainerIds = new Set([
|
|
59
62
|
...removedContainerIds,
|
|
60
63
|
...absentDeletedContainerIds,
|
|
@@ -77,10 +80,21 @@ async function applyContainerTombstoneCascade(input) {
|
|
|
77
80
|
return removal ? [{ containerId, ...removal }] : [];
|
|
78
81
|
}), {
|
|
79
82
|
discoveryOnly: true,
|
|
80
|
-
expectedContainers: Array.from(affectedContainerIds, (containerId) =>
|
|
81
|
-
containerId
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
expectedContainers: Array.from(affectedContainerIds, (containerId) => {
|
|
84
|
+
const metadata = state.containersById.get(containerId)?.record;
|
|
85
|
+
return {
|
|
86
|
+
containerId,
|
|
87
|
+
...(resolved.denied?.has(containerId)
|
|
88
|
+
? {
|
|
89
|
+
confirmedAccessLoss: {
|
|
90
|
+
placementHash: resolved.denied.get(containerId) ?? null,
|
|
91
|
+
expectedMetadata: metadata ? { ...metadata } : null,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
expectedContainer: expectedContainerStates.get(containerId)?.container ?? null,
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
84
98
|
stillCurrent: input.isCurrent,
|
|
85
99
|
});
|
|
86
100
|
if (deletedContainerIds.length !== affectedContainerIds.size) {
|
|
@@ -101,8 +115,36 @@ async function applyContainerTombstoneCascade(input) {
|
|
|
101
115
|
settled: true,
|
|
102
116
|
};
|
|
103
117
|
}
|
|
118
|
+
function preserveOtherRoots(state, liveContainerIds, tombstoneRootIds, rootId) {
|
|
119
|
+
const preservedContainerIds = new Set([
|
|
120
|
+
...liveContainerIds,
|
|
121
|
+
...tombstoneRootIds,
|
|
122
|
+
...Array.from(state.containersById, ([id, state]) => state.container.metadataDocumentId === null ? id : null).filter((id) => id !== null),
|
|
123
|
+
]);
|
|
124
|
+
if (state.containersById.get(rootId)?.container.metadataDocumentId !== null) {
|
|
125
|
+
preservedContainerIds.delete(rootId);
|
|
126
|
+
}
|
|
127
|
+
return preservedContainerIds;
|
|
128
|
+
}
|
|
104
129
|
export async function applyContainerTombstones(input) {
|
|
105
|
-
|
|
130
|
+
// A folder can regain access after one of its cached children moved away.
|
|
131
|
+
// Its live listing keeps the folder and reconciles the previously held tree.
|
|
132
|
+
const restored = await pendingFolderRestorations({
|
|
133
|
+
...input,
|
|
134
|
+
items: input.remoteContainerItems,
|
|
135
|
+
execSql: input.state.runtime.infra.execSql,
|
|
136
|
+
});
|
|
137
|
+
const restoredById = new Map(restored.map((item) => [item.id, item]));
|
|
138
|
+
const tombstones = [
|
|
139
|
+
...getApplicableContainerTombstones(input.response),
|
|
140
|
+
...restored.map((item) => ({
|
|
141
|
+
containerId: item.id,
|
|
142
|
+
parentId: item.parentId,
|
|
143
|
+
depth: item.depth,
|
|
144
|
+
updatedAt: item.updatedAt,
|
|
145
|
+
reason: "access_revoked",
|
|
146
|
+
})),
|
|
147
|
+
];
|
|
106
148
|
if (tombstones.length === 0 || input.isCurrent?.() === false) {
|
|
107
149
|
return {
|
|
108
150
|
changedCount: 0,
|
|
@@ -121,25 +163,26 @@ export async function applyContainerTombstones(input) {
|
|
|
121
163
|
// Apply each root as its own CAS-protected cascade. Other explicit roots
|
|
122
164
|
// stay out of this cascade so their own reason wins and one stale root
|
|
123
165
|
// cannot block independent tombstones or live items on the page.
|
|
124
|
-
const preservedContainerIds =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
...Array.from(input.state.containersById, ([id, state]) => state.container.metadataDocumentId === null ? id : null).filter((id) => id !== null),
|
|
128
|
-
]);
|
|
129
|
-
if (input.state.containersById.get(tombstone.containerId)?.container
|
|
130
|
-
.metadataDocumentId !== null) {
|
|
131
|
-
preservedContainerIds.delete(tombstone.containerId);
|
|
132
|
-
}
|
|
166
|
+
const preservedContainerIds = preserveOtherRoots(input.state, liveContainerIds, tombstoneRootIds, tombstone.containerId);
|
|
167
|
+
const live = restoredById.get(tombstone.containerId);
|
|
168
|
+
const stillCurrent = () => input.isCurrent?.() !== false && !(live && input.isPaused?.(live));
|
|
133
169
|
const result = await applyContainerTombstoneCascade({
|
|
170
|
+
reconcileDescendants: live !== undefined,
|
|
171
|
+
afterParentPage: input.response.nextWatermark
|
|
172
|
+
? { parentId: input.parentId, watermark: input.response.nextWatermark }
|
|
173
|
+
: undefined,
|
|
134
174
|
childIdsByParentId: input.childIdsByParentId,
|
|
135
175
|
expectedContainerStates: input.expectedContainerStates,
|
|
136
|
-
isCurrent:
|
|
176
|
+
isCurrent: stillCurrent,
|
|
137
177
|
preservedContainerIds,
|
|
138
178
|
state: input.state,
|
|
139
179
|
tombstone,
|
|
140
180
|
});
|
|
141
181
|
changedCount += result.removedCount;
|
|
142
|
-
|
|
182
|
+
if (live && input.isPaused?.(live) && input.isCurrent?.() !== false)
|
|
183
|
+
continue;
|
|
184
|
+
const recorded = await recordFolderRestoration(input.state.runtime.infra.execSql, live, result.settled, stillCurrent);
|
|
185
|
+
completed = completed && recorded;
|
|
143
186
|
if (!result.current) {
|
|
144
187
|
return { changedCount, completed: false, current: false };
|
|
145
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tombstoneApplication.js","sourceRoot":"","sources":["tombstoneApplication.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAChG,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAQ9D,SAAS,wBAAwB,CAC/B,KAAmD;IAEnD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyC,CAAC;IACrE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACnD,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC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AAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type {\n ContainerSyncTombstone,\n ListContainersResponse,\n} from \"@tearleads/validators/response\";\nimport { isCanonicalSignedAt } from \"@tearleads/validators/util\";\nimport { removeIndexedContainerChild } from \"./lanes/childIndex\";\nimport { containerStateMatchesFingerprint } from \"./remoteContainers/containerStateFingerprint\";\nimport { collectRemovedContainers } from \"./tombstoneReasons\";\nimport type {\n ContainerChildIndex,\n ExpectedContainerState,\n ListedRemoteContainerPageItem,\n RemoteContainerHydrationState,\n} from \"./types\";\n\nfunction latestContainerItemsById(\n items: ReadonlyArray<ListedRemoteContainerPageItem>,\n): Map<string, ListedRemoteContainerPageItem> {\n const latestItems = new Map<string, ListedRemoteContainerPageItem>();\n for (const item of items) {\n const current = latestItems.get(item.id);\n if (!current || current.updatedAt < item.updatedAt) {\n latestItems.set(item.id, item);\n }\n }\n\n return latestItems;\n}\n\nfunction latestContainerTombstonesById(\n tombstones: ReadonlyArray<ContainerSyncTombstone>,\n): Map<string, ContainerSyncTombstone> {\n const latestTombstones = new Map<string, ContainerSyncTombstone>();\n for (const tombstone of tombstones) {\n if (!isCanonicalSignedAt(tombstone.updatedAt))\n throw new Error(\"Container tombstone timestamp is not canonical\");\n const current = latestTombstones.get(tombstone.containerId);\n if (\n !current ||\n current.updatedAt < tombstone.updatedAt ||\n (current.updatedAt === tombstone.updatedAt &&\n current.reason === \"access_revoked\" &&\n tombstone.reason === \"deleted\")\n ) {\n latestTombstones.set(tombstone.containerId, tombstone);\n }\n }\n\n return latestTombstones;\n}\n\nfunction getApplicableContainerTombstones(\n response: ListContainersResponse,\n): ContainerSyncTombstone[] {\n const latestItems = latestContainerItemsById(response.items);\n return Array.from(\n latestContainerTombstonesById(response.tombstones).values(),\n ).filter((tombstone) => {\n const item = latestItems.get(tombstone.containerId);\n return (\n !item ||\n item.updatedAt < tombstone.updatedAt ||\n (item.updatedAt === tombstone.updatedAt && tombstone.reason === \"deleted\")\n );\n });\n}\n\nexport function getApplicableRemoteContainerItems(\n response: ListContainersResponse,\n): ListedRemoteContainerPageItem[] {\n const latestTombstones = latestContainerTombstonesById(response.tombstones);\n return response.items.filter((item) => {\n const tombstone = latestTombstones.get(item.id);\n return (\n !tombstone ||\n tombstone.updatedAt < item.updatedAt ||\n (tombstone.updatedAt === item.updatedAt &&\n tombstone.reason === \"access_revoked\")\n );\n });\n}\n\nasync function applyContainerTombstoneCascade(input: {\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n isCurrent?: (() => boolean) | undefined;\n preservedContainerIds: ReadonlySet<string>;\n state: RemoteContainerHydrationState;\n tombstone: ContainerSyncTombstone;\n}): Promise<{ current: boolean; removedCount: number; settled: boolean }> {\n const {\n childIdsByParentId,\n expectedContainerStates,\n preservedContainerIds,\n state,\n tombstone,\n } = input;\n const {\n fenceOnlyContainerIds,\n absentDeletedContainerIds,\n removalByContainerId,\n removedContainerIds,\n } = collectRemovedContainers({\n childIdsByParentId,\n containersById: state.containersById,\n preservedContainerIds,\n tombstones: [tombstone],\n });\n const affectedContainerIds = new Set([\n ...removedContainerIds,\n ...absentDeletedContainerIds,\n ...fenceOnlyContainerIds,\n ]);\n for (const containerId of affectedContainerIds) {\n if (\n !containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint:\n expectedContainerStates.get(containerId)?.fingerprint,\n })\n ) {\n return { current: true, removedCount: 0, settled: false };\n }\n }\n\n const deletedContainerIds = await state.persistence.deleteContainers(\n state.runtime.infra.execSql,\n [\n ...removedContainerIds,\n ...absentDeletedContainerIds,\n ...fenceOnlyContainerIds,\n ].flatMap((containerId) => {\n const removal = removalByContainerId.get(containerId);\n return removal ? [{ containerId, ...removal }] : [];\n }),\n {\n discoveryOnly: true,\n expectedContainers: Array.from(affectedContainerIds, (containerId) => ({\n containerId,\n expectedContainer:\n expectedContainerStates.get(containerId)?.container ?? null,\n })),\n stillCurrent: input.isCurrent,\n },\n );\n if (deletedContainerIds.length !== affectedContainerIds.size) {\n return { current: true, removedCount: 0, settled: false };\n }\n if (input.isCurrent?.() === false) {\n return { current: false, removedCount: 0, settled: false };\n }\n for (const containerId of removedContainerIds) {\n const parentId =\n state.containersById.get(containerId)?.container.parentId ?? null;\n removeIndexedContainerChild(childIdsByParentId, containerId, parentId);\n childIdsByParentId.delete(containerId);\n state.containersById.delete(containerId);\n }\n\n return {\n current: true,\n removedCount: removedContainerIds.length,\n settled: true,\n };\n}\n\nexport async function applyContainerTombstones(input: {\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n isCurrent?: (() => boolean) | undefined;\n remoteContainerItems: ReadonlyArray<ListedRemoteContainerPageItem>;\n response: ListContainersResponse;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; completed: boolean; current: boolean }> {\n const tombstones = getApplicableContainerTombstones(input.response);\n if (tombstones.length === 0 || input.isCurrent?.() === false) {\n return {\n changedCount: 0,\n completed: true,\n current: input.isCurrent?.() !== false,\n };\n }\n\n const tombstoneRootIds = new Set(\n tombstones.map((tombstone) => tombstone.containerId),\n );\n const liveContainerIds = input.remoteContainerItems.map((item) => item.id);\n let changedCount = 0;\n let completed = true;\n for (const tombstone of tombstones) {\n if (input.isCurrent?.() === false) {\n return { changedCount, completed: false, current: false };\n }\n // Apply each root as its own CAS-protected cascade. Other explicit roots\n // stay out of this cascade so their own reason wins and one stale root\n // cannot block independent tombstones or live items on the page.\n const preservedContainerIds = new Set([\n ...liveContainerIds,\n ...tombstoneRootIds,\n ...Array.from(input.state.containersById, ([id, state]) =>\n state.container.metadataDocumentId === null ? id : null,\n ).filter((id): id is string => id !== null),\n ]);\n if (\n input.state.containersById.get(tombstone.containerId)?.container\n .metadataDocumentId !== null\n ) {\n preservedContainerIds.delete(tombstone.containerId);\n }\n const result = await applyContainerTombstoneCascade({\n childIdsByParentId: input.childIdsByParentId,\n expectedContainerStates: input.expectedContainerStates,\n isCurrent: input.isCurrent,\n preservedContainerIds,\n state: input.state,\n tombstone,\n });\n changedCount += result.removedCount;\n completed = completed && result.settled;\n if (!result.current) {\n return { changedCount, completed: false, current: false };\n }\n }\n\n return { changedCount, completed, current: true };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tombstoneApplication.js","sourceRoot":"","sources":["tombstoneApplication.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAQhG,SAAS,wBAAwB,CAC/B,KAAmD;IAEnD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyC,CAAC;IACrE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACnD,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,6BAA6B,CACpC,UAAiD;IAEjD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkC,CAAC;IACnE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,mBAAmB,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Q,CAAC,aAAa,EAAE;gBACvE,CAAC,CAAC,SAAS;YACb,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,uBAAuB,EAAE,KAAK,CAAC,uBAAuB;YACtD,SAAS,EAAE,YAAY;YACvB,qBAAqB;YACrB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,SAAS;SACV,CAAC,CAAC;QACH,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;QACpC,IAAI,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK;YACjE,SAAS;QACX,MAAM,QAAQ,GAAG,MAAM,uBAAuB,CAC5C,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EACjC,IAAI,EACJ,MAAM,CAAC,OAAO,EACd,YAAY,CACb,CAAC;QACF,SAAS,GAAG,SAAS,IAAI,QAAQ,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { ListContainerDocumentLanesRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerSyncTombstone,\n ListContainersResponse,\n} from \"@tearleads/validators/response\";\nimport { isCanonicalSignedAt } from \"@tearleads/validators/util\";\nimport { removeIndexedContainerChild } from \"./lanes/childIndex\";\nimport {\n pendingFolderRestorations,\n recordFolderRestoration,\n} from \"./lanes/restorationReceipt\";\nimport { resolveTombstoneCascade } from \"./lanes/tombstoneAccess\";\nimport { containerStateMatchesFingerprint } from \"./remoteContainers/containerStateFingerprint\";\nimport type {\n ContainerChildIndex,\n ExpectedContainerState,\n ListedRemoteContainerPageItem,\n RemoteContainerHydrationState,\n} from \"./types\";\n\nfunction latestContainerItemsById(\n items: ReadonlyArray<ListedRemoteContainerPageItem>,\n): Map<string, ListedRemoteContainerPageItem> {\n const latestItems = new Map<string, ListedRemoteContainerPageItem>();\n for (const item of items) {\n const current = latestItems.get(item.id);\n if (!current || current.updatedAt < item.updatedAt) {\n latestItems.set(item.id, item);\n }\n }\n\n return latestItems;\n}\n\nfunction latestContainerTombstonesById(\n tombstones: ReadonlyArray<ContainerSyncTombstone>,\n): Map<string, ContainerSyncTombstone> {\n const latestTombstones = new Map<string, ContainerSyncTombstone>();\n for (const tombstone of tombstones) {\n if (!isCanonicalSignedAt(tombstone.updatedAt))\n throw new Error(\"Container tombstone timestamp is not canonical\");\n const current = latestTombstones.get(tombstone.containerId);\n if (\n !current ||\n current.updatedAt < tombstone.updatedAt ||\n (current.updatedAt === tombstone.updatedAt &&\n current.reason === \"access_revoked\" &&\n tombstone.reason === \"deleted\")\n ) {\n latestTombstones.set(tombstone.containerId, tombstone);\n }\n }\n\n return latestTombstones;\n}\n\nfunction getApplicableContainerTombstones(\n response: ListContainersResponse,\n): ContainerSyncTombstone[] {\n const latestItems = latestContainerItemsById(response.items);\n return Array.from(\n latestContainerTombstonesById(response.tombstones).values(),\n ).filter((tombstone) => {\n const item = latestItems.get(tombstone.containerId);\n return (\n !item ||\n item.updatedAt < tombstone.updatedAt ||\n (item.updatedAt === tombstone.updatedAt && tombstone.reason === \"deleted\")\n );\n });\n}\n\nexport function getApplicableRemoteContainerItems(\n response: ListContainersResponse,\n): ListedRemoteContainerPageItem[] {\n const latestTombstones = latestContainerTombstonesById(response.tombstones);\n return response.items.filter((item) => {\n const tombstone = latestTombstones.get(item.id);\n return (\n !tombstone ||\n tombstone.updatedAt < item.updatedAt ||\n (tombstone.updatedAt === item.updatedAt &&\n tombstone.reason === \"access_revoked\")\n );\n });\n}\n\nasync function applyContainerTombstoneCascade(input: {\n reconcileDescendants: boolean;\n afterParentPage: ListContainerDocumentLanesRequest[\"afterParentPage\"];\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n isCurrent?: (() => boolean) | undefined;\n preservedContainerIds: ReadonlySet<string>;\n state: RemoteContainerHydrationState;\n tombstone: ContainerSyncTombstone;\n}): Promise<{ current: boolean; removedCount: number; settled: boolean }> {\n const { childIdsByParentId, expectedContainerStates, state } = input;\n const resolved = await resolveTombstoneCascade(input);\n if (!resolved || input.isCurrent?.() === false)\n return {\n current: input.isCurrent?.() !== false,\n removedCount: 0,\n settled: false,\n };\n const {\n fenceOnlyContainerIds,\n absentDeletedContainerIds,\n removalByContainerId,\n removedContainerIds,\n } = resolved.cascade;\n const affectedContainerIds = new Set([\n ...removedContainerIds,\n ...absentDeletedContainerIds,\n ...fenceOnlyContainerIds,\n ]);\n for (const containerId of affectedContainerIds) {\n if (\n !containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint:\n expectedContainerStates.get(containerId)?.fingerprint,\n })\n ) {\n return { current: true, removedCount: 0, settled: false };\n }\n }\n\n const deletedContainerIds = await state.persistence.deleteContainers(\n state.runtime.infra.execSql,\n [\n ...removedContainerIds,\n ...absentDeletedContainerIds,\n ...fenceOnlyContainerIds,\n ].flatMap((containerId) => {\n const removal = removalByContainerId.get(containerId);\n return removal ? [{ containerId, ...removal }] : [];\n }),\n {\n discoveryOnly: true,\n expectedContainers: Array.from(affectedContainerIds, (containerId) => {\n const metadata = state.containersById.get(containerId)?.record;\n return {\n containerId,\n ...(resolved.denied?.has(containerId)\n ? {\n confirmedAccessLoss: {\n placementHash: resolved.denied.get(containerId) ?? null,\n expectedMetadata: metadata ? { ...metadata } : null,\n },\n }\n : {}),\n expectedContainer:\n expectedContainerStates.get(containerId)?.container ?? null,\n };\n }),\n stillCurrent: input.isCurrent,\n },\n );\n if (deletedContainerIds.length !== affectedContainerIds.size) {\n return { current: true, removedCount: 0, settled: false };\n }\n if (input.isCurrent?.() === false) {\n return { current: false, removedCount: 0, settled: false };\n }\n for (const containerId of removedContainerIds) {\n const parentId =\n state.containersById.get(containerId)?.container.parentId ?? null;\n removeIndexedContainerChild(childIdsByParentId, containerId, parentId);\n childIdsByParentId.delete(containerId);\n state.containersById.delete(containerId);\n }\n\n return {\n current: true,\n removedCount: removedContainerIds.length,\n settled: true,\n };\n}\n\nfunction preserveOtherRoots(\n state: RemoteContainerHydrationState,\n liveContainerIds: ReadonlyArray<string>,\n tombstoneRootIds: ReadonlySet<string>,\n rootId: string,\n) {\n const preservedContainerIds = new Set([\n ...liveContainerIds,\n ...tombstoneRootIds,\n ...Array.from(state.containersById, ([id, state]) =>\n state.container.metadataDocumentId === null ? id : null,\n ).filter((id): id is string => id !== null),\n ]);\n if (state.containersById.get(rootId)?.container.metadataDocumentId !== null) {\n preservedContainerIds.delete(rootId);\n }\n return preservedContainerIds;\n}\n\nexport async function applyContainerTombstones(input: {\n parentId: string | null;\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n isCurrent?: (() => boolean) | undefined;\n isPaused?: (item: ListedRemoteContainerPageItem) => boolean;\n remoteContainerItems: ReadonlyArray<ListedRemoteContainerPageItem>;\n response: ListContainersResponse;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; completed: boolean; current: boolean }> {\n // A folder can regain access after one of its cached children moved away.\n // Its live listing keeps the folder and reconciles the previously held tree.\n const restored = await pendingFolderRestorations({\n ...input,\n items: input.remoteContainerItems,\n execSql: input.state.runtime.infra.execSql,\n });\n const restoredById = new Map(restored.map((item) => [item.id, item]));\n const tombstones = [\n ...getApplicableContainerTombstones(input.response),\n ...restored.map((item) => ({\n containerId: item.id,\n parentId: item.parentId,\n depth: item.depth,\n updatedAt: item.updatedAt,\n reason: \"access_revoked\" as const,\n })),\n ];\n if (tombstones.length === 0 || input.isCurrent?.() === false) {\n return {\n changedCount: 0,\n completed: true,\n current: input.isCurrent?.() !== false,\n };\n }\n\n const tombstoneRootIds = new Set(\n tombstones.map((tombstone) => tombstone.containerId),\n );\n const liveContainerIds = input.remoteContainerItems.map((item) => item.id);\n let changedCount = 0;\n let completed = true;\n for (const tombstone of tombstones) {\n if (input.isCurrent?.() === false) {\n return { changedCount, completed: false, current: false };\n }\n // Apply each root as its own CAS-protected cascade. Other explicit roots\n // stay out of this cascade so their own reason wins and one stale root\n // cannot block independent tombstones or live items on the page.\n const preservedContainerIds = preserveOtherRoots(\n input.state,\n liveContainerIds,\n tombstoneRootIds,\n tombstone.containerId,\n );\n const live = restoredById.get(tombstone.containerId);\n const stillCurrent = () =>\n input.isCurrent?.() !== false && !(live && input.isPaused?.(live));\n const result = await applyContainerTombstoneCascade({\n reconcileDescendants: live !== undefined,\n afterParentPage: input.response.nextWatermark\n ? { parentId: input.parentId, watermark: input.response.nextWatermark }\n : undefined,\n childIdsByParentId: input.childIdsByParentId,\n expectedContainerStates: input.expectedContainerStates,\n isCurrent: stillCurrent,\n preservedContainerIds,\n state: input.state,\n tombstone,\n });\n changedCount += result.removedCount;\n if (live && input.isPaused?.(live) && input.isCurrent?.() !== false)\n continue;\n const recorded = await recordFolderRestoration(\n input.state.runtime.infra.execSql,\n live,\n result.settled,\n stillCurrent,\n );\n completed = completed && recorded;\n if (!result.current) {\n return { changedCount, completed: false, current: false };\n }\n }\n\n return { changedCount, completed, current: true };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RequestResult, WriterProjectionListing } from "../../../internal/api-client/index.js";
|
|
1
|
+
import type { ApiClient, RequestResult, WriterProjectionListing } from "../../../internal/api-client/index.js";
|
|
2
2
|
import type { ContainerReplacementAuthorizationsResponse } from "../../../internal/validators/operation/index.js";
|
|
3
3
|
import type { ListContainerParentLanesRequest } from "../../../internal/validators/request/index.js";
|
|
4
4
|
import type { ContainerSummary, ContainerWriterProjectionResponse, DocumentWriterProjectionResponse, ListContainerParentLanesResponse, ListContainersResponse, ReferencedPrincipalStateResponse } from "../../../internal/validators/response/index.js";
|
|
@@ -34,6 +34,7 @@ export interface ContainerState {
|
|
|
34
34
|
}
|
|
35
35
|
interface RemoteContainerHydrationApi extends Partial<PrincipalPolicyHistoryReader>, CurrentPrincipalPolicyReader {
|
|
36
36
|
getContainerReplacementAuthorizationsResult(containerId: string, replacesOrganizationId: string): Promise<RequestResult<ContainerReplacementAuthorizationsResponse>>;
|
|
37
|
+
listContainerDocumentLanes: ApiClient["listContainerDocumentLanes"];
|
|
37
38
|
evictContainerWriterProjection(containerId: string): void;
|
|
38
39
|
evictWriterProjectionsCiting(containerIds: readonly string[]): void;
|
|
39
40
|
getContainerWriterProjection(containerId: string, listing?: WriterProjectionListing): Promise<ContainerWriterProjectionResponse | null>;
|
|
@@ -42,13 +43,24 @@ interface RemoteContainerHydrationApi extends Partial<PrincipalPolicyHistoryRead
|
|
|
42
43
|
interface RemoteContainerHydrationRuntime extends Pick<ContainerContentsWorkflowRuntime, "auth" | "adoptRootContainer" | "crypto" | "infra" | "organizations" | "principalPolicies" | "resolveTrustedUserIdentity" | "state" | "util"> {
|
|
43
44
|
apiClient: RemoteContainerHydrationApi;
|
|
44
45
|
}
|
|
46
|
+
export type HydrationOutcome = "complete" | "refused" | "retry";
|
|
47
|
+
export interface ReconnectPages {
|
|
48
|
+
laneIdPrefix: string;
|
|
49
|
+
recordManualError(error: Error): void;
|
|
50
|
+
}
|
|
51
|
+
export interface ReconnectCrawl {
|
|
52
|
+
isCurrent(): boolean;
|
|
53
|
+
record(outcome: HydrationOutcome, manualRejection?: Error): void;
|
|
54
|
+
}
|
|
45
55
|
export interface RemoteContainerHydrationState {
|
|
56
|
+
readonly parentLaneRequestPrefix?: string;
|
|
46
57
|
/**
|
|
47
58
|
* Container listing requests that failed or timed out, in a current crawl.
|
|
48
59
|
* An explicit refresh compares it across its wait to tell whether a listing
|
|
49
60
|
* fell short while it ran.
|
|
50
61
|
*/
|
|
51
62
|
containerListingFailures?: number | undefined;
|
|
63
|
+
containerParentIdsNeedingHydration?: Set<string | null>;
|
|
52
64
|
containersById: Map<string, ContainerState>;
|
|
53
65
|
lifecycleGeneration?: number | undefined;
|
|
54
66
|
persistence: ContainerContentsPersistence;
|
|
@@ -92,6 +104,9 @@ export interface RemoteContainerHydrationHost {
|
|
|
92
104
|
updateSnapshot: () => void;
|
|
93
105
|
}
|
|
94
106
|
export interface ContainerParentHydrationLane {
|
|
107
|
+
/** An earlier page is incomplete. Continue discovery without persisting a cursor past it. */
|
|
108
|
+
skipWatermarkWrite?: boolean;
|
|
109
|
+
continuationCursors?: Set<string>;
|
|
95
110
|
parentId: string | null;
|
|
96
111
|
watermark?: ListContainersResponse["nextWatermark"];
|
|
97
112
|
}
|