@tearleads/client-sdk 0.1.217 → 0.1.218
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/containerContents/documentDiscovery.js +6 -4
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/client/containerContents/index.js +3 -4
- package/client/containerContents/index.js.map +1 -1
- package/client/deviceFirst/index.js +2 -2
- package/client/deviceFirst/index.js.map +1 -1
- package/client/documents/index.js +2 -2
- package/client/documents/index.js.map +1 -1
- package/client/organizations/organizationGroupHistory.js +1 -2
- package/client/organizations/organizationGroupHistory.js.map +1 -1
- package/client/organizations/organizationGroupNameHydration.js +1 -2
- package/client/organizations/organizationGroupNameHydration.js.map +1 -1
- package/client/organizations/organizationHistory.js +2 -4
- package/client/organizations/organizationHistory.js.map +1 -1
- package/client/organizations/principalContainerMutations.js +1 -2
- package/client/organizations/principalContainerMutations.js.map +1 -1
- package/client/organizations/principalMutations.js +1 -2
- package/client/organizations/principalMutations.js.map +1 -1
- package/client/organizations/rosterAdmissionEvidence.js +1 -2
- package/client/organizations/rosterAdmissionEvidence.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +3 -2
- package/client/runtime/workflowRuntime.js +13 -3
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/stores/documents/documentStore/attachments/attachmentHydration.js +3 -2
- package/stores/documents/documentStore/attachments/attachmentHydration.js.map +1 -1
- package/stores/documents/documentStore/rotation/index.js +1 -2
- package/stores/documents/documentStore/rotation/index.js.map +1 -1
- package/stores/documents/documentStore/rotation/rotationSettlement.js +1 -1
- package/stores/documents/documentStore/rotation/rotationSettlement.js.map +1 -1
- package/stores/documents/documentStore/state.js.map +1 -1
- package/stores/documents/documentStore/sync/carriedFirstUpdate.js.map +1 -1
- package/stores/documents/documentStore/sync/index.js.map +1 -1
- package/stores/documents/documentStore/sync/syncAttachments.js +3 -2
- package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -1
- package/stores/documents/documentStore/sync/syncDetachedAttachments.js +3 -2
- package/stores/documents/documentStore/sync/syncDetachedAttachments.js.map +1 -1
- package/stores/documents/documentStore/sync/syncRequest.js +3 -2
- package/stores/documents/documentStore/sync/syncRequest.js.map +1 -1
- package/stores/documents/documentStore/sync/syncRevalidation.js.map +1 -1
- package/stores/documents/documentStore/sync/syncSeededCreate.js.map +1 -1
- package/stores/documents/documentStore/sync/syncShared.js +3 -2
- package/stores/documents/documentStore/sync/syncShared.js.map +1 -1
- package/workflows/container-contents/container-state/create/createAdoption.js +1 -2
- package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -1
- package/workflows/container-contents/container-state/create/createWithMetadata.js +1 -2
- package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -1
- package/workflows/container-contents/container-state/create/createWithMetadataPlan.js +1 -2
- package/workflows/container-contents/container-state/create/createWithMetadataPlan.js.map +1 -1
- package/workflows/container-contents/container-state/move/moveIntentSync.js +1 -2
- package/workflows/container-contents/container-state/move/moveIntentSync.js.map +1 -1
- package/workflows/container-contents/container-state/purge/purgeTreeScope.js +1 -2
- package/workflows/container-contents/container-state/purge/purgeTreeScope.js.map +1 -1
- package/workflows/container-contents/container-state/remote.js +3 -4
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/container-contents/container-state/share/groupGrantVerification.js +1 -2
- package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -1
- package/workflows/container-contents/container-state/share/index.js +2 -3
- package/workflows/container-contents/container-state/share/index.js.map +1 -1
- package/workflows/container-contents/container-state/types.js.map +1 -1
- package/workflows/container-contents/documentLinks/documentLinksMove.js +4 -2
- package/workflows/container-contents/documentLinks/documentLinksMove.js.map +1 -1
- package/workflows/container-contents/documentLinks/index.js +3 -2
- package/workflows/container-contents/documentLinks/index.js.map +1 -1
- package/workflows/container-contents/index.d.ts +1 -1
- package/workflows/container-contents/index.js +1 -1
- package/workflows/container-contents/index.js.map +1 -1
- package/workflows/container-contents/metadata/index.d.ts +1 -1
- package/workflows/container-contents/metadata/index.js.map +1 -1
- package/workflows/container-contents/metadata/metadataRemoteSync.d.ts +3 -3
- package/workflows/container-contents/metadata/metadataRemoteSync.js +3 -2
- package/workflows/container-contents/metadata/metadataRemoteSync.js.map +1 -1
- package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js +1 -2
- package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -1
- package/workflows/container-contents/remoteHydration/index.js +1 -2
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +4 -2
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +1 -1
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/runtime.d.ts +13 -2
- package/workflows/container-contents/runtime.js +33 -21
- package/workflows/container-contents/runtime.js.map +1 -1
- package/workflows/container-contents/syncLane.d.ts +1 -1
- package/workflows/container-contents/syncLane.js.map +1 -1
- package/workflows/container-contents/tombstones/documentPurge.d.ts +2 -3
- package/workflows/container-contents/tombstones/documentPurge.js +1 -2
- package/workflows/container-contents/tombstones/documentPurge.js.map +1 -1
- package/workflows/container-contents/tombstones/documentTombstoneEvidence.js +3 -2
- package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -1
- package/workflows/documents/index.d.ts +1 -1
- package/workflows/documents/index.js +1 -1
- package/workflows/documents/index.js.map +1 -1
- package/workflows/documents/runtime.d.ts +12 -1
- package/workflows/documents/runtime.js +24 -16
- package/workflows/documents/runtime.js.map +1 -1
- package/workflows/documents/sync/syncLane.d.ts +1 -1
- package/workflows/documents/sync/syncLane.js.map +1 -1
- package/workflows/organizations/currentOrganizationAuthority.d.ts +1 -2
- package/workflows/organizations/currentOrganizationAuthority.js.map +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataRuntime.d.ts +5 -4
- package/workflows/organizations/groupMetadata/groupMetadataRuntime.js +2 -4
- package/workflows/organizations/groupMetadata/groupMetadataRuntime.js.map +1 -1
- package/workflows/organizations/groupMetadata/runtimeGroupMetadataAuthority.js +1 -2
- package/workflows/organizations/groupMetadata/runtimeGroupMetadataAuthority.js.map +1 -1
- package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -1
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.d.ts +1 -2
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js +2 -2
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js.map +1 -1
- package/workflows/organizations/groupShare/runtimeCurrentGroupShare.js +4 -8
- package/workflows/organizations/groupShare/runtimeCurrentGroupShare.js.map +1 -1
- package/workflows/organizations/memberships/leaveRequestMembersEvidence.js +2 -3
- package/workflows/organizations/memberships/leaveRequestMembersEvidence.js.map +1 -1
- package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js.map +1 -1
- package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js +2 -2
- package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js.map +1 -1
- package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js +2 -2
- package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js.map +1 -1
- package/workflows/principals/index.d.ts +1 -0
- package/workflows/principals/index.js.map +1 -1
- package/workflows/principals/principalPolicyService.d.ts +64 -0
- package/workflows/principals/principalPolicyService.js +117 -0
- package/workflows/principals/principalPolicyService.js.map +1 -0
- package/workflows/principals/runtimePolicyRecovery.d.ts +13 -10
- package/workflows/principals/runtimePolicyRecovery.js +9 -17
- package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
- package/workflows/principals/runtimeProjectionPolicyRecovery.js +7 -8
- package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -1
- package/data/principals/principalHistoryRuntime.js +0 -12
- package/data/principals/principalHistoryRuntime.js.map +0 -1
- package/workflows/organizations/principalMutations/currentPrincipalMutationLease.d.ts +0 -16
- package/workflows/organizations/principalMutations/currentPrincipalMutationLease.js +0 -39
- package/workflows/organizations/principalMutations/currentPrincipalMutationLease.js.map +0 -1
- package/workflows/principals/runtimePolicyWarmer.d.ts +0 -26
- package/workflows/principals/runtimePolicyWarmer.js +0 -48
- package/workflows/principals/runtimePolicyWarmer.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPrincipalPolicyOperation,
|
|
1
|
+
import { createPrincipalPolicyOperation, } from "../../../principals/principalPolicyService.js";
|
|
2
2
|
import { prefetchDestinationProjections } from "../destination/destinationPrefetch.js";
|
|
3
3
|
import { cachedDestinationRole } from "../destination/destinationRoleCache.js";
|
|
4
4
|
import { markContainerParentLaneFetched } from "../lanes/laneFetchMarkers.js";
|
|
@@ -26,7 +26,9 @@ async function applyRemoteContainerPage(input) {
|
|
|
26
26
|
let hydratedCount = 0;
|
|
27
27
|
let pageCompleted = true;
|
|
28
28
|
await cacheRemoteContainerPrincipalPolicies({
|
|
29
|
-
cacheReferencedPrincipalPolicies:
|
|
29
|
+
cacheReferencedPrincipalPolicies: state.runtime.principalPolicies.createWarmer({
|
|
30
|
+
operation: input.policyOperation,
|
|
31
|
+
}),
|
|
30
32
|
remoteContainers: items,
|
|
31
33
|
stillCurrent: input.isCurrent,
|
|
32
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerPageHydration.js","sourceRoot":"","sources":["remoteContainerPageHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,kCAAkC,GAEnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,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AC1B,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 createRuntimePrincipalPolicyWarmer,\n type PrincipalPolicyOperation,\n} from \"../../../principals/runtimePolicyWarmer\";\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: createRuntimePrincipalPolicyWarmer(\n state.runtime,\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 off the device. Skipping them\n // here, after tombstones saw the full page, still lets the lane complete\n // 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,8BAA8B,GAE/B,MAAM,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AQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAAC;YACjD,kBAAkB;YAClB,YAAY;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 off the device. Skipping them\n // here, after tombstones saw the full page, still lets the lane complete\n // 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"]}
|
|
@@ -39,7 +39,7 @@ interface RemoteContainerHydrationApi extends Partial<PrincipalPolicyHistoryRead
|
|
|
39
39
|
getContainerWriterProjection(containerId: string, listing?: WriterProjectionListing): Promise<ContainerWriterProjectionResponse | null>;
|
|
40
40
|
listContainerParentLanes(input: ListContainerParentLanesRequest): Promise<ListContainerParentLanesResponse | null>;
|
|
41
41
|
}
|
|
42
|
-
interface RemoteContainerHydrationRuntime extends Pick<ContainerContentsWorkflowRuntime, "auth" | "adoptRootContainer" | "crypto" | "infra" | "resolveTrustedUserIdentity" | "state" | "util"> {
|
|
42
|
+
interface RemoteContainerHydrationRuntime extends Pick<ContainerContentsWorkflowRuntime, "auth" | "adoptRootContainer" | "crypto" | "infra" | "principalPolicies" | "resolveTrustedUserIdentity" | "state" | "util"> {
|
|
43
43
|
apiClient: RemoteContainerHydrationApi;
|
|
44
44
|
}
|
|
45
45
|
export interface RemoteContainerHydrationState {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RequestResult,\n WriterProjectionListing,\n} from \"@tearleads/api-client\";\nimport type { ContainerReplacementAuthorizationsResponse } from \"@tearleads/validators/operation\";\nimport type { ListContainerParentLanesRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerSummary,\n ContainerWriterProjectionResponse,\n DocumentWriterProjectionResponse,\n ListContainerParentLanesResponse,\n ListContainersResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type { CurrentPrincipalPolicyReader } from \"../../principals/currentPrincipalPolicyReader\";\nimport type { PrincipalPolicyHistoryReader } from \"../../principals/principalPolicyHistoryReader\";\nimport type {\n ContainerContentsPersistence,\n ContainerDocumentRecord,\n ContainerHydrationTombstone,\n ContainerRecord,\n createContainerParentSyncLane,\n} from \"../containerPersistence\";\nimport type { ContainerMetadataPatch } from \"../metadata\";\nimport type { createContainerMetadataDocument } from \"../metadata/containerMetadataDocument\";\nimport type { ContainerContentsWorkflowRuntime } from \"../runtime\";\n\nexport type ListedRemoteContainerPageItem =\n ListContainersResponse[\"items\"][number];\nexport type ContainerChildIndex = Map<string, Set<string>>;\nexport type QueueContainerParentLane = (parentId: string | null) => void;\nexport type RemoteContainerIngestQueue = Map<string, RemoteContainer>;\nexport type SaveContainerOptions = Parameters<\n ContainerContentsPersistence[\"saveContainer\"]\n>[3];\n\nexport type ContainerMetadataDocumentState = Awaited<\n ReturnType<typeof createContainerMetadataDocument>\n>;\nexport type RemoteContainer = Pick<\n ContainerSummary,\n | \"createdAt\"\n | \"effectiveAccessLevel\"\n | \"systemSlot\"\n | \"id\"\n | \"metadataAccessEpoch\"\n | \"metadataAccessStateHash\"\n | \"metadataDocumentId\"\n | \"metadataReferencedPrincipals\"\n | \"organizationId\"\n | \"parentId\"\n | \"updatedAt\"\n>;\n\nexport interface ContainerState {\n containerWriterProjection?:\n | ContainerWriterProjectionResponse\n | null\n | undefined;\n /**\n * Bumped whenever a realtime hint or a pull drops this container's cached writer\n * projections (container and metadata document alike); an operation that\n * fetched or carried a projection installs it only if this is unchanged\n * since it started, so a pre-hint answer never lands after the hint.\n */\n writerProjectionGeneration?: number | undefined;\n metadataReferencedPrincipals?:\n | readonly ReferencedPrincipalStateResponse[]\n | undefined;\n container: ContainerRecord;\n doc: ContainerMetadataDocumentState;\n metadataWriterProjection?:\n | DocumentWriterProjectionResponse\n | null\n | undefined;\n /** Durable pull progress mirrored from the metadata document record. */\n pullContinuation?: ContainerDocumentRecord[\"pullContinuation\"] | undefined;\n record: ContainerDocumentRecord;\n}\n\ninterface RemoteContainerHydrationApi\n extends Partial<PrincipalPolicyHistoryReader>,\n CurrentPrincipalPolicyReader {\n getContainerReplacementAuthorizationsResult(\n containerId: string,\n replacesOrganizationId: string,\n ): Promise<RequestResult<ContainerReplacementAuthorizationsResponse>>;\n evictContainerWriterProjection(containerId: string): void;\n evictWriterProjectionsCiting(containerIds: readonly string[]): void;\n getContainerWriterProjection(\n containerId: string,\n listing?: WriterProjectionListing,\n ): Promise<ContainerWriterProjectionResponse | null>;\n listContainerParentLanes(\n input: ListContainerParentLanesRequest,\n ): Promise<ListContainerParentLanesResponse | null>;\n}\n\ninterface RemoteContainerHydrationRuntime\n extends Pick<\n ContainerContentsWorkflowRuntime,\n | \"auth\"\n | \"adoptRootContainer\"\n | \"crypto\"\n | \"infra\"\n | \"resolveTrustedUserIdentity\"\n | \"state\"\n | \"util\"\n > {\n apiClient: RemoteContainerHydrationApi;\n}\n\nexport interface RemoteContainerHydrationState {\n /**\n * Container listing requests that failed or timed out, in a current crawl.\n * An explicit refresh compares it across its wait to tell whether a listing\n * fell short while it ran.\n */\n containerListingFailures?: number | undefined;\n containersById: Map<string, ContainerState>;\n lifecycleGeneration?: number | undefined;\n persistence: ContainerContentsPersistence;\n rootLaneHydrated?: boolean | undefined;\n runtime: RemoteContainerHydrationRuntime;\n structuralGeneration?: number | undefined;\n}\n\nexport type PersistContainerStateResult =\n | { status: \"identity-superseded\"; record: ContainerDocumentRecord }\n | { status: \"missing\" }\n | {\n status: \"persisted\";\n record: ContainerDocumentRecord;\n createIntentSettled?: true | undefined;\n moveIntentSettled?: true | undefined;\n }\n | { status: \"stale-generation\" };\n\nexport interface RemoteContainerHydrationHost {\n persistContainerState: (\n containerState: ContainerState,\n patch?: Partial<ContainerMetadataPatch>,\n updateView?: boolean,\n saveOptions?: SaveContainerOptions,\n mutationOptions?: {\n /** Queued metadata rows the server committed, settled in this write. */\n acceptedPendingUpdateIds?: readonly string[] | undefined;\n clearSyncFailure?: boolean | undefined;\n expectedStateWhenMissing?: ContainerState | undefined;\n isCurrent?: (() => boolean) | undefined;\n createIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"createIntentSettlement\"];\n moveIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"moveIntentSettlement\"];\n preserveDurableStructureWhenPending?: boolean | undefined;\n },\n ) => Promise<PersistContainerStateResult>;\n requestDocumentPriming?: (() => void) | undefined;\n updateSnapshot: () => void;\n}\n\nexport interface ContainerParentHydrationLane {\n parentId: string | null;\n watermark?: ListContainersResponse[\"nextWatermark\"];\n}\n\nexport interface ExpectedContainerState {\n container: ContainerRecord;\n fingerprint: string;\n}\n\nexport interface FetchedContainerParentLanePage {\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: ReadonlyMap<string, ContainerHydrationTombstone>;\n lane: ContainerParentHydrationLane;\n response: ListContainersResponse;\n syncLane: ReturnType<typeof createContainerParentSyncLane>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RequestResult,\n WriterProjectionListing,\n} from \"@tearleads/api-client\";\nimport type { ContainerReplacementAuthorizationsResponse } from \"@tearleads/validators/operation\";\nimport type { ListContainerParentLanesRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerSummary,\n ContainerWriterProjectionResponse,\n DocumentWriterProjectionResponse,\n ListContainerParentLanesResponse,\n ListContainersResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type { CurrentPrincipalPolicyReader } from \"../../principals/currentPrincipalPolicyReader\";\nimport type { PrincipalPolicyHistoryReader } from \"../../principals/principalPolicyHistoryReader\";\nimport type {\n ContainerContentsPersistence,\n ContainerDocumentRecord,\n ContainerHydrationTombstone,\n ContainerRecord,\n createContainerParentSyncLane,\n} from \"../containerPersistence\";\nimport type { ContainerMetadataPatch } from \"../metadata\";\nimport type { createContainerMetadataDocument } from \"../metadata/containerMetadataDocument\";\nimport type { ContainerContentsWorkflowRuntime } from \"../runtime\";\n\nexport type ListedRemoteContainerPageItem =\n ListContainersResponse[\"items\"][number];\nexport type ContainerChildIndex = Map<string, Set<string>>;\nexport type QueueContainerParentLane = (parentId: string | null) => void;\nexport type RemoteContainerIngestQueue = Map<string, RemoteContainer>;\nexport type SaveContainerOptions = Parameters<\n ContainerContentsPersistence[\"saveContainer\"]\n>[3];\n\nexport type ContainerMetadataDocumentState = Awaited<\n ReturnType<typeof createContainerMetadataDocument>\n>;\nexport type RemoteContainer = Pick<\n ContainerSummary,\n | \"createdAt\"\n | \"effectiveAccessLevel\"\n | \"systemSlot\"\n | \"id\"\n | \"metadataAccessEpoch\"\n | \"metadataAccessStateHash\"\n | \"metadataDocumentId\"\n | \"metadataReferencedPrincipals\"\n | \"organizationId\"\n | \"parentId\"\n | \"updatedAt\"\n>;\n\nexport interface ContainerState {\n containerWriterProjection?:\n | ContainerWriterProjectionResponse\n | null\n | undefined;\n /**\n * Bumped whenever a realtime hint or a pull drops this container's cached writer\n * projections (container and metadata document alike); an operation that\n * fetched or carried a projection installs it only if this is unchanged\n * since it started, so a pre-hint answer never lands after the hint.\n */\n writerProjectionGeneration?: number | undefined;\n metadataReferencedPrincipals?:\n | readonly ReferencedPrincipalStateResponse[]\n | undefined;\n container: ContainerRecord;\n doc: ContainerMetadataDocumentState;\n metadataWriterProjection?:\n | DocumentWriterProjectionResponse\n | null\n | undefined;\n /** Durable pull progress mirrored from the metadata document record. */\n pullContinuation?: ContainerDocumentRecord[\"pullContinuation\"] | undefined;\n record: ContainerDocumentRecord;\n}\n\ninterface RemoteContainerHydrationApi\n extends Partial<PrincipalPolicyHistoryReader>,\n CurrentPrincipalPolicyReader {\n getContainerReplacementAuthorizationsResult(\n containerId: string,\n replacesOrganizationId: string,\n ): Promise<RequestResult<ContainerReplacementAuthorizationsResponse>>;\n evictContainerWriterProjection(containerId: string): void;\n evictWriterProjectionsCiting(containerIds: readonly string[]): void;\n getContainerWriterProjection(\n containerId: string,\n listing?: WriterProjectionListing,\n ): Promise<ContainerWriterProjectionResponse | null>;\n listContainerParentLanes(\n input: ListContainerParentLanesRequest,\n ): Promise<ListContainerParentLanesResponse | null>;\n}\n\ninterface RemoteContainerHydrationRuntime\n extends Pick<\n ContainerContentsWorkflowRuntime,\n | \"auth\"\n | \"adoptRootContainer\"\n | \"crypto\"\n | \"infra\"\n | \"principalPolicies\"\n | \"resolveTrustedUserIdentity\"\n | \"state\"\n | \"util\"\n > {\n apiClient: RemoteContainerHydrationApi;\n}\n\nexport interface RemoteContainerHydrationState {\n /**\n * Container listing requests that failed or timed out, in a current crawl.\n * An explicit refresh compares it across its wait to tell whether a listing\n * fell short while it ran.\n */\n containerListingFailures?: number | undefined;\n containersById: Map<string, ContainerState>;\n lifecycleGeneration?: number | undefined;\n persistence: ContainerContentsPersistence;\n rootLaneHydrated?: boolean | undefined;\n runtime: RemoteContainerHydrationRuntime;\n structuralGeneration?: number | undefined;\n}\n\nexport type PersistContainerStateResult =\n | { status: \"identity-superseded\"; record: ContainerDocumentRecord }\n | { status: \"missing\" }\n | {\n status: \"persisted\";\n record: ContainerDocumentRecord;\n createIntentSettled?: true | undefined;\n moveIntentSettled?: true | undefined;\n }\n | { status: \"stale-generation\" };\n\nexport interface RemoteContainerHydrationHost {\n persistContainerState: (\n containerState: ContainerState,\n patch?: Partial<ContainerMetadataPatch>,\n updateView?: boolean,\n saveOptions?: SaveContainerOptions,\n mutationOptions?: {\n /** Queued metadata rows the server committed, settled in this write. */\n acceptedPendingUpdateIds?: readonly string[] | undefined;\n clearSyncFailure?: boolean | undefined;\n expectedStateWhenMissing?: ContainerState | undefined;\n isCurrent?: (() => boolean) | undefined;\n createIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"createIntentSettlement\"];\n moveIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"moveIntentSettlement\"];\n preserveDurableStructureWhenPending?: boolean | undefined;\n },\n ) => Promise<PersistContainerStateResult>;\n requestDocumentPriming?: (() => void) | undefined;\n updateSnapshot: () => void;\n}\n\nexport interface ContainerParentHydrationLane {\n parentId: string | null;\n watermark?: ListContainersResponse[\"nextWatermark\"];\n}\n\nexport interface ExpectedContainerState {\n container: ContainerRecord;\n fingerprint: string;\n}\n\nexport interface FetchedContainerParentLanePage {\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: ReadonlyMap<string, ContainerHydrationTombstone>;\n lane: ContainerParentHydrationLane;\n response: ListContainersResponse;\n syncLane: ReturnType<typeof createContainerParentSyncLane>;\n}\n"]}
|
|
@@ -4,7 +4,8 @@ import { type DocumentProjectorRegistryInput } from "../../data/documents/docume
|
|
|
4
4
|
import type { PrincipalHistoryProtectionLease } from "../../data/principals/principalHistoryProtection.js";
|
|
5
5
|
import type { ExecSql } from "../../data/sqlite/sqlSchema.js";
|
|
6
6
|
import { type TrustedUserIdentityResolver } from "../../data/trustedUserIdentity/index.js";
|
|
7
|
-
import { createDocumentsWorkflowRuntime, type DocumentsWorkflowRuntime } from "../documents/index.js";
|
|
7
|
+
import { type createDocumentsWorkflowRuntime, type DocumentsWorkflowRuntime } from "../documents/index.js";
|
|
8
|
+
import { PrincipalPolicyService } from "../principals/principalPolicyService.js";
|
|
8
9
|
import type { WorkflowRuntimeAuthInput, WorkflowRuntimeCryptoInput, WorkflowRuntimeInfraInput, WorkflowRuntimeStateInput, WorkflowRuntimeUtilInput } from "../shared/runtimeInput.js";
|
|
9
10
|
type DocumentsWorkflowRuntimeInput = Parameters<typeof createDocumentsWorkflowRuntime>[0];
|
|
10
11
|
type ContainerContentsWorkflowApi = ApiClient & DocumentsWorkflowRuntimeInput["apiClient"];
|
|
@@ -46,13 +47,21 @@ export interface ContainerContentsWorkflowRuntimeInputGroups {
|
|
|
46
47
|
readonly util: ContainerContentsWorkflowRuntimeUtil;
|
|
47
48
|
}
|
|
48
49
|
export interface ContainerContentsWorkflowRuntimeInput extends ContainerContentsWorkflowRuntimeInputGroups {
|
|
49
|
-
/** Private host custody,
|
|
50
|
+
/** Private host custody, held by the runtime's policy service and shared with derived document runtimes. */
|
|
50
51
|
readonly withPrincipalHistoryProtection?: PrincipalHistoryProtectionLease | undefined;
|
|
51
52
|
readonly apiClient: ContainerContentsWorkflowApi;
|
|
52
53
|
readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
|
|
53
54
|
}
|
|
55
|
+
/** A runtime snapshot whose producer already bound its policy service, such as `workflowInput()`. */
|
|
56
|
+
export interface ContainerContentsWorkflowRuntimeSnapshot extends ContainerContentsWorkflowRuntimeInputGroups {
|
|
57
|
+
readonly apiClient: ContainerContentsWorkflowApi;
|
|
58
|
+
readonly principalPolicies: PrincipalPolicyService;
|
|
59
|
+
readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
|
|
60
|
+
}
|
|
54
61
|
export interface ContainerContentsWorkflowRuntime extends ContainerContentsWorkflowRuntimeGroups, Pick<ContainerContentsWorkflowRuntimeInput, "apiClient"> {
|
|
55
62
|
readonly adoptRootContainer?: ContainerContentsRootAdopter | undefined;
|
|
63
|
+
/** Bound to this snapshot's API client, executor, and history custody. */
|
|
64
|
+
readonly principalPolicies: PrincipalPolicyService;
|
|
56
65
|
readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
|
|
57
66
|
}
|
|
58
67
|
/**
|
|
@@ -75,6 +84,8 @@ export interface ContainerContentsWorkflowSqlRuntime {
|
|
|
75
84
|
}
|
|
76
85
|
export declare function createContainerContentsDocumentsRuntime(runtime: ContainerContentsWorkflowRuntime, containerId: string | null): DocumentsWorkflowRuntime;
|
|
77
86
|
export declare function createContainerContentsWorkflowRuntime(input: ContainerContentsWorkflowRuntimeInput): ContainerContentsWorkflowRuntime;
|
|
87
|
+
export declare function createContainerContentsWorkflowRuntimeFromSnapshot(snapshot: ContainerContentsWorkflowRuntimeSnapshot): ContainerContentsWorkflowRuntime;
|
|
78
88
|
/** Internal store runtime with the session-root adoption capability wired. */
|
|
79
89
|
export declare function createContainerContentsStoreWorkflowRuntime(input: ContainerContentsWorkflowRuntimeInput, adoptRootContainer: ContainerContentsRootAdopter, requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard): ContainerContentsStoreWorkflowRuntime;
|
|
90
|
+
export declare function createContainerContentsStoreWorkflowRuntimeFromSnapshot(snapshot: ContainerContentsWorkflowRuntimeSnapshot, adoptRootContainer: ContainerContentsRootAdopter, requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard): ContainerContentsStoreWorkflowRuntime;
|
|
80
91
|
export {};
|
|
@@ -1,47 +1,59 @@
|
|
|
1
1
|
import { resolveDocumentProjectorRegistry, } from "../../data/documents/documentKinds.js";
|
|
2
|
-
import { inheritPrincipalHistoryProtection } from "../../data/principals/principalHistoryRuntime.js";
|
|
3
2
|
import { requireTrustedUserIdentityResolver, } from "../../data/trustedUserIdentity/index.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { createDocumentsWorkflowRuntimeFromSnapshot, } from "../documents/index.js";
|
|
4
|
+
import { PrincipalPolicyService } from "../principals/principalPolicyService.js";
|
|
5
|
+
function documentsRuntimeSnapshot(runtime, containerId) {
|
|
6
|
+
return {
|
|
7
7
|
apiClient: runtime.apiClient,
|
|
8
8
|
auth: runtime.auth,
|
|
9
9
|
crypto: runtime.crypto,
|
|
10
10
|
infra: runtime.infra,
|
|
11
|
+
principalPolicies: runtime.principalPolicies,
|
|
11
12
|
resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,
|
|
12
13
|
state: { ...runtime.state, containerId },
|
|
13
14
|
util: runtime.util,
|
|
14
|
-
}
|
|
15
|
+
};
|
|
15
16
|
}
|
|
16
17
|
export function createContainerContentsDocumentsRuntime(runtime, containerId) {
|
|
17
|
-
return
|
|
18
|
+
return createDocumentsWorkflowRuntimeFromSnapshot(documentsRuntimeSnapshot(runtime, containerId));
|
|
19
|
+
}
|
|
20
|
+
/** Standalone hosts supply their own lease; the view never carries it. */
|
|
21
|
+
function standaloneSnapshot(input) {
|
|
22
|
+
return { ...input, principalPolicies: new PrincipalPolicyService(input) };
|
|
18
23
|
}
|
|
19
|
-
function createContainerContentsWorkflowRuntimeWithRootAdopter(
|
|
20
|
-
const documentProjectors = resolveDocumentProjectorRegistry(
|
|
24
|
+
function createContainerContentsWorkflowRuntimeWithRootAdopter(snapshot, adoptRootContainer) {
|
|
25
|
+
const documentProjectors = resolveDocumentProjectorRegistry(snapshot.infra.documentProjectors);
|
|
21
26
|
const infra = {
|
|
22
|
-
...
|
|
27
|
+
...snapshot.infra,
|
|
23
28
|
documentProjectors,
|
|
24
29
|
};
|
|
25
|
-
return
|
|
30
|
+
return {
|
|
26
31
|
...(adoptRootContainer ? { adoptRootContainer } : {}),
|
|
27
|
-
apiClient:
|
|
28
|
-
auth:
|
|
29
|
-
crypto:
|
|
32
|
+
apiClient: snapshot.apiClient,
|
|
33
|
+
auth: snapshot.auth,
|
|
34
|
+
crypto: snapshot.crypto,
|
|
30
35
|
infra,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
principalPolicies: snapshot.principalPolicies,
|
|
37
|
+
resolveTrustedUserIdentity: requireTrustedUserIdentityResolver(snapshot.resolveTrustedUserIdentity),
|
|
38
|
+
state: snapshot.state,
|
|
39
|
+
util: snapshot.util,
|
|
40
|
+
};
|
|
35
41
|
}
|
|
36
42
|
export function createContainerContentsWorkflowRuntime(input) {
|
|
37
|
-
return createContainerContentsWorkflowRuntimeWithRootAdopter(input);
|
|
43
|
+
return createContainerContentsWorkflowRuntimeWithRootAdopter(standaloneSnapshot(input));
|
|
44
|
+
}
|
|
45
|
+
export function createContainerContentsWorkflowRuntimeFromSnapshot(snapshot) {
|
|
46
|
+
return createContainerContentsWorkflowRuntimeWithRootAdopter(snapshot);
|
|
38
47
|
}
|
|
39
48
|
/** Internal store runtime with the session-root adoption capability wired. */
|
|
40
49
|
export function createContainerContentsStoreWorkflowRuntime(input, adoptRootContainer, requireVerifiedRecipient) {
|
|
41
|
-
return
|
|
42
|
-
|
|
50
|
+
return createContainerContentsStoreWorkflowRuntimeFromSnapshot(standaloneSnapshot(input), adoptRootContainer, requireVerifiedRecipient);
|
|
51
|
+
}
|
|
52
|
+
export function createContainerContentsStoreWorkflowRuntimeFromSnapshot(snapshot, adoptRootContainer, requireVerifiedRecipient) {
|
|
53
|
+
return {
|
|
54
|
+
...createContainerContentsWorkflowRuntimeWithRootAdopter(snapshot, adoptRootContainer),
|
|
43
55
|
adoptRootContainer,
|
|
44
56
|
requireVerifiedRecipient,
|
|
45
|
-
}
|
|
57
|
+
};
|
|
46
58
|
}
|
|
47
59
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,gCAAgC,GACjC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,+CAA+C,CAAC;AAElG,OAAO,EACL,kCAAkC,GAEnC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,8BAA8B,GAE/B,MAAM,cAAc,CAAC;AAgHtB,SAAS,qBAAqB,CAC5B,OAAyC,EACzC,WAA0B;IAE1B,OAAO,iCAAiC,CAAC,OAAO,EAAE;QAChD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;QAC9D,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE;QACxC,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,OAAyC,EACzC,WAA0B;IAE1B,OAAO,8BAA8B,CACnC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,CAC5C,CAAC;AACJ,CAAC;AAED,SAAS,qDAAqD,CAC5D,KAA4C,EAC5C,kBAA6D;IAE7D,MAAM,kBAAkB,GAAG,gCAAgC,CACzD,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAC/B,CAAC;IACF,MAAM,KAAK,GAAG;QACZ,GAAG,KAAK,CAAC,KAAK;QACd,kBAAkB;KACnB,CAAC;IAEF,OAAO,iCAAiC,CAAC,KAAK,EAAE;QAC9C,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK;QACL,0BAA0B,EAAE,kCAAkC,CAC5D,KAAK,CAAC,0BAA0B,CACjC;QACD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,KAA4C;IAE5C,OAAO,qDAAqD,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,2CAA2C,CACzD,KAA4C,EAC5C,kBAAgD,EAChD,wBAAiE;IAEjE,OAAO,iCAAiC,CAAC,KAAK,EAAE;QAC9C,GAAG,qDAAqD,CACtD,KAAK,EACL,kBAAkB,CACnB;QACD,kBAAkB;QAClB,wBAAwB;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { ContainerAccessLevel } from \"@tearleads/crypto\";\nimport {\n type DocumentProjectorRegistryInput,\n resolveDocumentProjectorRegistry,\n} from \"../../data/documents/documentKinds\";\nimport type { PrincipalHistoryProtectionLease } from \"../../data/principals/principalHistoryProtection\";\nimport { inheritPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport {\n requireTrustedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n} from \"../../data/trustedUserIdentity\";\nimport {\n createDocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntime,\n} from \"../documents\";\nimport type {\n WorkflowRuntimeAuthInput,\n WorkflowRuntimeCryptoInput,\n WorkflowRuntimeInfraInput,\n WorkflowRuntimeStateInput,\n WorkflowRuntimeUtilInput,\n} from \"../shared/runtimeInput\";\n\ntype DocumentsWorkflowRuntimeInput = Parameters<\n typeof createDocumentsWorkflowRuntime\n>[0];\n\ntype ContainerContentsWorkflowApi = ApiClient &\n DocumentsWorkflowRuntimeInput[\"apiClient\"];\n\nexport interface ContainerContentsWorkflowRuntimeAuth\n extends WorkflowRuntimeAuthInput {}\n\nexport interface ContainerContentsWorkflowRuntimeCrypto\n extends WorkflowRuntimeCryptoInput {}\n\nexport interface ContainerContentsWorkflowRuntimeInfra\n extends Omit<WorkflowRuntimeInfraInput, \"dbStatus\"> {\n readonly dbStatus: string;\n}\n\ninterface ContainerContentsWorkflowRuntimeInputInfra\n extends Omit<ContainerContentsWorkflowRuntimeInfra, \"documentProjectors\"> {\n readonly documentProjectors: DocumentProjectorRegistryInput;\n}\n\nexport interface ContainerContentsWorkflowRuntimeState\n extends WorkflowRuntimeStateInput {}\n\nexport interface ContainerContentsWorkflowRuntimeUtil\n extends Omit<WorkflowRuntimeUtilInput, \"logError\"> {\n // Store recovery is best-effort, so hosts may retain the causal error without\n // making structured error logging mandatory for general workflow runtimes.\n readonly logError?: WorkflowRuntimeUtilInput[\"logError\"] | undefined;\n}\n\nexport interface ContainerContentsRootAdoptionInput {\n readonly domainScope: ContainerContentsWorkflowRuntimeState[\"domainScope\"];\n readonly expectedContainerId: string;\n readonly nextContainerId: string;\n readonly organizationId: string;\n readonly userId: string;\n}\n\nexport type ContainerContentsRootAdopter = (\n input: ContainerContentsRootAdoptionInput,\n) => boolean | \"already-adopted\";\n\nexport interface ContainerContentsWorkflowRuntimeGroups {\n readonly auth: ContainerContentsWorkflowRuntimeAuth;\n readonly crypto: ContainerContentsWorkflowRuntimeCrypto;\n readonly infra: ContainerContentsWorkflowRuntimeInfra;\n readonly state: ContainerContentsWorkflowRuntimeState;\n readonly util: ContainerContentsWorkflowRuntimeUtil;\n}\n\nexport interface ContainerContentsWorkflowRuntimeInputGroups {\n readonly auth: ContainerContentsWorkflowRuntimeAuth;\n readonly crypto: ContainerContentsWorkflowRuntimeCrypto;\n readonly infra: ContainerContentsWorkflowRuntimeInputInfra;\n readonly state: ContainerContentsWorkflowRuntimeState;\n readonly util: ContainerContentsWorkflowRuntimeUtil;\n}\n\nexport interface ContainerContentsWorkflowRuntimeInput\n extends ContainerContentsWorkflowRuntimeInputGroups {\n /** Private host custody, inherited by container and derived document runtimes. */\n readonly withPrincipalHistoryProtection?:\n | PrincipalHistoryProtectionLease\n | undefined;\n readonly apiClient: ContainerContentsWorkflowApi;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\nexport interface ContainerContentsWorkflowRuntime\n extends ContainerContentsWorkflowRuntimeGroups,\n Pick<ContainerContentsWorkflowRuntimeInput, \"apiClient\"> {\n readonly adoptRootContainer?: ContainerContentsRootAdopter | undefined;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/**\n * Refuses a share recipient whose identity no verified identity link (or this\n * device's own keys) established. Sharing admits a user; a read share, which\n * grants no signing authority, may also rest on roster vouching.\n */\nexport type ContainerContentsVerifiedRecipientGuard = (\n userId: string,\n accessLevel: ContainerAccessLevel,\n) => Promise<void>;\n\nexport interface ContainerContentsStoreWorkflowRuntime\n extends ContainerContentsWorkflowRuntime {\n readonly adoptRootContainer: ContainerContentsRootAdopter;\n readonly requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard;\n}\n\nexport interface ContainerContentsWorkflowSqlRuntime {\n readonly auth?: {\n readonly organizationId?: string | null | undefined;\n };\n readonly infra: {\n readonly execSql: ExecSql;\n };\n}\n\nfunction documentsRuntimeInput(\n runtime: ContainerContentsWorkflowRuntime,\n containerId: string | null,\n): DocumentsWorkflowRuntimeInput {\n return inheritPrincipalHistoryProtection(runtime, {\n apiClient: runtime.apiClient,\n auth: runtime.auth,\n crypto: runtime.crypto,\n infra: runtime.infra,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n state: { ...runtime.state, containerId },\n util: runtime.util,\n });\n}\n\nexport function createContainerContentsDocumentsRuntime(\n runtime: ContainerContentsWorkflowRuntime,\n containerId: string | null,\n): DocumentsWorkflowRuntime {\n return createDocumentsWorkflowRuntime(\n documentsRuntimeInput(runtime, containerId),\n );\n}\n\nfunction createContainerContentsWorkflowRuntimeWithRootAdopter(\n input: ContainerContentsWorkflowRuntimeInput,\n adoptRootContainer?: ContainerContentsRootAdopter | undefined,\n): ContainerContentsWorkflowRuntime {\n const documentProjectors = resolveDocumentProjectorRegistry(\n input.infra.documentProjectors,\n );\n const infra = {\n ...input.infra,\n documentProjectors,\n };\n\n return inheritPrincipalHistoryProtection(input, {\n ...(adoptRootContainer ? { adoptRootContainer } : {}),\n apiClient: input.apiClient,\n auth: input.auth,\n crypto: input.crypto,\n infra,\n resolveTrustedUserIdentity: requireTrustedUserIdentityResolver(\n input.resolveTrustedUserIdentity,\n ),\n state: input.state,\n util: input.util,\n });\n}\n\nexport function createContainerContentsWorkflowRuntime(\n input: ContainerContentsWorkflowRuntimeInput,\n): ContainerContentsWorkflowRuntime {\n return createContainerContentsWorkflowRuntimeWithRootAdopter(input);\n}\n\n/** Internal store runtime with the session-root adoption capability wired. */\nexport function createContainerContentsStoreWorkflowRuntime(\n input: ContainerContentsWorkflowRuntimeInput,\n adoptRootContainer: ContainerContentsRootAdopter,\n requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard,\n): ContainerContentsStoreWorkflowRuntime {\n return inheritPrincipalHistoryProtection(input, {\n ...createContainerContentsWorkflowRuntimeWithRootAdopter(\n input,\n adoptRootContainer,\n ),\n adoptRootContainer,\n requireVerifiedRecipient,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["runt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BAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,KAAK;QACL,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;QAC7C,0BAA0B,EAAE,kCAAkC,CAC5D,QAAQ,CAAC,0BAA0B,CACpC;QACD,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;KACpB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,KAA4C;IAE5C,OAAO,qDAAqD,CAC1D,kBAAkB,CAAC,KAAK,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kDAAkD,CAChE,QAAkD;IAElD,OAAO,qDAAqD,CAAC,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,2CAA2C,CACzD,KAA4C,EAC5C,kBAAgD,EAChD,wBAAiE;IAEjE,OAAO,uDAAuD,CAC5D,kBAAkB,CAAC,KAAK,CAAC,EACzB,kBAAkB,EAClB,wBAAwB,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uDAAuD,CACrE,QAAkD,EAClD,kBAAgD,EAChD,wBAAiE;IAEjE,OAAO;QACL,GAAG,qDAAqD,CACtD,QAAQ,EACR,kBAAkB,CACnB;QACD,kBAAkB;QAClB,wBAAwB;KACzB,CAAC;AACJ,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { ContainerAccessLevel } from \"@tearleads/crypto\";\nimport {\n type DocumentProjectorRegistryInput,\n resolveDocumentProjectorRegistry,\n} from \"../../data/documents/documentKinds\";\nimport type { PrincipalHistoryProtectionLease } from \"../../data/principals/principalHistoryProtection\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport {\n requireTrustedUserIdentityResolver,\n type TrustedUserIdentityResolver,\n} from \"../../data/trustedUserIdentity\";\nimport {\n type createDocumentsWorkflowRuntime,\n createDocumentsWorkflowRuntimeFromSnapshot,\n type DocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntimeSnapshot,\n} from \"../documents\";\nimport { PrincipalPolicyService } from \"../principals/principalPolicyService\";\nimport type {\n WorkflowRuntimeAuthInput,\n WorkflowRuntimeCryptoInput,\n WorkflowRuntimeInfraInput,\n WorkflowRuntimeStateInput,\n WorkflowRuntimeUtilInput,\n} from \"../shared/runtimeInput\";\n\ntype DocumentsWorkflowRuntimeInput = Parameters<\n typeof createDocumentsWorkflowRuntime\n>[0];\n\ntype ContainerContentsWorkflowApi = ApiClient &\n DocumentsWorkflowRuntimeInput[\"apiClient\"];\n\nexport interface ContainerContentsWorkflowRuntimeAuth\n extends WorkflowRuntimeAuthInput {}\n\nexport interface ContainerContentsWorkflowRuntimeCrypto\n extends WorkflowRuntimeCryptoInput {}\n\nexport interface ContainerContentsWorkflowRuntimeInfra\n extends Omit<WorkflowRuntimeInfraInput, \"dbStatus\"> {\n readonly dbStatus: string;\n}\n\ninterface ContainerContentsWorkflowRuntimeInputInfra\n extends Omit<ContainerContentsWorkflowRuntimeInfra, \"documentProjectors\"> {\n readonly documentProjectors: DocumentProjectorRegistryInput;\n}\n\nexport interface ContainerContentsWorkflowRuntimeState\n extends WorkflowRuntimeStateInput {}\n\nexport interface ContainerContentsWorkflowRuntimeUtil\n extends Omit<WorkflowRuntimeUtilInput, \"logError\"> {\n // Store recovery is best-effort, so hosts may retain the causal error without\n // making structured error logging mandatory for general workflow runtimes.\n readonly logError?: WorkflowRuntimeUtilInput[\"logError\"] | undefined;\n}\n\nexport interface ContainerContentsRootAdoptionInput {\n readonly domainScope: ContainerContentsWorkflowRuntimeState[\"domainScope\"];\n readonly expectedContainerId: string;\n readonly nextContainerId: string;\n readonly organizationId: string;\n readonly userId: string;\n}\n\nexport type ContainerContentsRootAdopter = (\n input: ContainerContentsRootAdoptionInput,\n) => boolean | \"already-adopted\";\n\nexport interface ContainerContentsWorkflowRuntimeGroups {\n readonly auth: ContainerContentsWorkflowRuntimeAuth;\n readonly crypto: ContainerContentsWorkflowRuntimeCrypto;\n readonly infra: ContainerContentsWorkflowRuntimeInfra;\n readonly state: ContainerContentsWorkflowRuntimeState;\n readonly util: ContainerContentsWorkflowRuntimeUtil;\n}\n\nexport interface ContainerContentsWorkflowRuntimeInputGroups {\n readonly auth: ContainerContentsWorkflowRuntimeAuth;\n readonly crypto: ContainerContentsWorkflowRuntimeCrypto;\n readonly infra: ContainerContentsWorkflowRuntimeInputInfra;\n readonly state: ContainerContentsWorkflowRuntimeState;\n readonly util: ContainerContentsWorkflowRuntimeUtil;\n}\n\nexport interface ContainerContentsWorkflowRuntimeInput\n extends ContainerContentsWorkflowRuntimeInputGroups {\n /** Private host custody, held by the runtime's policy service and shared with derived document runtimes. */\n readonly withPrincipalHistoryProtection?:\n | PrincipalHistoryProtectionLease\n | undefined;\n readonly apiClient: ContainerContentsWorkflowApi;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** A runtime snapshot whose producer already bound its policy service, such as `workflowInput()`. */\nexport interface ContainerContentsWorkflowRuntimeSnapshot\n extends ContainerContentsWorkflowRuntimeInputGroups {\n readonly apiClient: ContainerContentsWorkflowApi;\n readonly principalPolicies: PrincipalPolicyService;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\nexport interface ContainerContentsWorkflowRuntime\n extends ContainerContentsWorkflowRuntimeGroups,\n Pick<ContainerContentsWorkflowRuntimeInput, \"apiClient\"> {\n readonly adoptRootContainer?: ContainerContentsRootAdopter | undefined;\n /** Bound to this snapshot's API client, executor, and history custody. */\n readonly principalPolicies: PrincipalPolicyService;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/**\n * Refuses a share recipient whose identity no verified identity link (or this\n * device's own keys) established. Sharing admits a user; a read share, which\n * grants no signing authority, may also rest on roster vouching.\n */\nexport type ContainerContentsVerifiedRecipientGuard = (\n userId: string,\n accessLevel: ContainerAccessLevel,\n) => Promise<void>;\n\nexport interface ContainerContentsStoreWorkflowRuntime\n extends ContainerContentsWorkflowRuntime {\n readonly adoptRootContainer: ContainerContentsRootAdopter;\n readonly requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard;\n}\n\nexport interface ContainerContentsWorkflowSqlRuntime {\n readonly auth?: {\n readonly organizationId?: string | null | undefined;\n };\n readonly infra: {\n readonly execSql: ExecSql;\n };\n}\n\nfunction documentsRuntimeSnapshot(\n runtime: ContainerContentsWorkflowRuntime,\n containerId: string | null,\n): DocumentsWorkflowRuntimeSnapshot {\n return {\n apiClient: runtime.apiClient,\n auth: runtime.auth,\n crypto: runtime.crypto,\n infra: runtime.infra,\n principalPolicies: runtime.principalPolicies,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n state: { ...runtime.state, containerId },\n util: runtime.util,\n };\n}\n\nexport function createContainerContentsDocumentsRuntime(\n runtime: ContainerContentsWorkflowRuntime,\n containerId: string | null,\n): DocumentsWorkflowRuntime {\n return createDocumentsWorkflowRuntimeFromSnapshot(\n documentsRuntimeSnapshot(runtime, containerId),\n );\n}\n\n/** Standalone hosts supply their own lease; the view never carries it. */\nfunction standaloneSnapshot(\n input: ContainerContentsWorkflowRuntimeInput,\n): ContainerContentsWorkflowRuntimeSnapshot {\n return { ...input, principalPolicies: new PrincipalPolicyService(input) };\n}\n\nfunction createContainerContentsWorkflowRuntimeWithRootAdopter(\n snapshot: ContainerContentsWorkflowRuntimeSnapshot,\n adoptRootContainer?: ContainerContentsRootAdopter | undefined,\n): ContainerContentsWorkflowRuntime {\n const documentProjectors = resolveDocumentProjectorRegistry(\n snapshot.infra.documentProjectors,\n );\n const infra = {\n ...snapshot.infra,\n documentProjectors,\n };\n\n return {\n ...(adoptRootContainer ? { adoptRootContainer } : {}),\n apiClient: snapshot.apiClient,\n auth: snapshot.auth,\n crypto: snapshot.crypto,\n infra,\n principalPolicies: snapshot.principalPolicies,\n resolveTrustedUserIdentity: requireTrustedUserIdentityResolver(\n snapshot.resolveTrustedUserIdentity,\n ),\n state: snapshot.state,\n util: snapshot.util,\n };\n}\n\nexport function createContainerContentsWorkflowRuntime(\n input: ContainerContentsWorkflowRuntimeInput,\n): ContainerContentsWorkflowRuntime {\n return createContainerContentsWorkflowRuntimeWithRootAdopter(\n standaloneSnapshot(input),\n );\n}\n\nexport function createContainerContentsWorkflowRuntimeFromSnapshot(\n snapshot: ContainerContentsWorkflowRuntimeSnapshot,\n): ContainerContentsWorkflowRuntime {\n return createContainerContentsWorkflowRuntimeWithRootAdopter(snapshot);\n}\n\n/** Internal store runtime with the session-root adoption capability wired. */\nexport function createContainerContentsStoreWorkflowRuntime(\n input: ContainerContentsWorkflowRuntimeInput,\n adoptRootContainer: ContainerContentsRootAdopter,\n requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard,\n): ContainerContentsStoreWorkflowRuntime {\n return createContainerContentsStoreWorkflowRuntimeFromSnapshot(\n standaloneSnapshot(input),\n adoptRootContainer,\n requireVerifiedRecipient,\n );\n}\n\nexport function createContainerContentsStoreWorkflowRuntimeFromSnapshot(\n snapshot: ContainerContentsWorkflowRuntimeSnapshot,\n adoptRootContainer: ContainerContentsRootAdopter,\n requireVerifiedRecipient: ContainerContentsVerifiedRecipientGuard,\n): ContainerContentsStoreWorkflowRuntime {\n return {\n ...createContainerContentsWorkflowRuntimeWithRootAdopter(\n snapshot,\n adoptRootContainer,\n ),\n adoptRootContainer,\n requireVerifiedRecipient,\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DomainScope } from "../../data/shared/domainScope.js";
|
|
2
2
|
import { type SyncLane } from "../../data/sync/syncCoordinator.js";
|
|
3
|
-
import type { PrincipalPolicyOperation } from "../principals/
|
|
3
|
+
import type { PrincipalPolicyOperation } from "../principals/principalPolicyService.js";
|
|
4
4
|
export { sequenceUnchanged } from "../../data/sync/sequence.js";
|
|
5
5
|
export { didRegainSyncPrerequisites, isDatabaseUnavailableError, } from "../../data/sync/syncCoordinator.js";
|
|
6
6
|
export type ContainerContentsSyncLane = SyncLane;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncLane.js","sourceRoot":"","sources":["syncLane.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,4EAA4E;AAC5E,+EAA+E;AAC/E,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AAGzC,MAAM,CAAC,MAAM,gCAAgC,GAAG,oBAAoB,CAAC;AAErE,MAAM,UAAU,iCAAiC,CAAC,KASjD;IACC,OAAO,gCAAgC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,YAAY,CACrE,gCAAgC,EAChC;QACE,KAAK,EAAE,oBAAoB;QAC3B,KAAK,EAAE,YAAY;QACnB,qEAAqE;QACrE,sEAAsE;QACtE,yEAAyE;QACzE,mDAAmD;QACnD,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE,CAC/B,KAAK,CAAC,QAAQ,EAAE,CAAC,sCAAsC,EAAE,KAAK,CAAC;QACjE,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,iBAAiB,EAAE,0BAA0B;KAC9C,CACF,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,6BAA6B,CAAC,WAAwB;IACpE,OAAO,CACL,gCAAgC,CAAC,WAAW,CAAC;SAC1C,WAAW,EAAE;SACb,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,gCAAgC,CAAC;QACtE,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport {\n getOrCreateDomainSyncCoordinator,\n isDatabaseUnavailableError,\n type SyncLane,\n} from \"../../data/sync/syncCoordinator\";\nimport type { PrincipalPolicyOperation } from \"../principals/
|
|
1
|
+
{"version":3,"file":"syncLane.js","sourceRoot":"","sources":["syncLane.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,4EAA4E;AAC5E,+EAA+E;AAC/E,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AAGzC,MAAM,CAAC,MAAM,gCAAgC,GAAG,oBAAoB,CAAC;AAErE,MAAM,UAAU,iCAAiC,CAAC,KASjD;IACC,OAAO,gCAAgC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,YAAY,CACrE,gCAAgC,EAChC;QACE,KAAK,EAAE,oBAAoB;QAC3B,KAAK,EAAE,YAAY;QACnB,qEAAqE;QACrE,sEAAsE;QACtE,yEAAyE;QACzE,mDAAmD;QACnD,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE,CAC/B,KAAK,CAAC,QAAQ,EAAE,CAAC,sCAAsC,EAAE,KAAK,CAAC;QACjE,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,iBAAiB,EAAE,0BAA0B;KAC9C,CACF,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,6BAA6B,CAAC,WAAwB;IACpE,OAAO,CACL,gCAAgC,CAAC,WAAW,CAAC;SAC1C,WAAW,EAAE;SACb,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,gCAAgC,CAAC;QACtE,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport {\n getOrCreateDomainSyncCoordinator,\n isDatabaseUnavailableError,\n type SyncLane,\n} from \"../../data/sync/syncCoordinator\";\nimport type { PrincipalPolicyOperation } from \"../principals/principalPolicyService\";\n\nexport { sequenceUnchanged } from \"../../data/sync/sequence\";\n// Facade re-exports: container-contents stores must reach these shared sync\n// helpers through this workflow boundary, not by importing data/sync directly.\nexport {\n didRegainSyncPrerequisites,\n isDatabaseUnavailableError,\n} from \"../../data/sync/syncCoordinator\";\n\nexport type ContainerContentsSyncLane = SyncLane;\nexport const CONTAINER_CONTENTS_SYNC_LANE_KEY = \"container-contents\";\n\nexport function registerContainerContentsSyncLane(input: {\n readonly domainScope: DomainScope;\n /** Host diagnostics sink; bare runtimes do not structure errors. */\n readonly logError?: ((message: string, error: unknown) => void) | undefined;\n /**\n * Receives the coordinator drain's pass token, which is the principal-policy\n * operation of every metadata sync this run performs.\n */\n readonly run: (policyOperation: PrincipalPolicyOperation) => Promise<void>;\n}): ContainerContentsSyncLane {\n return getOrCreateDomainSyncCoordinator(input.domainScope).registerLane(\n CONTAINER_CONTENTS_SYNC_LANE_KEY,\n {\n label: \"Container contents\",\n phase: \"structural\",\n // Fixed literal: no container or identity id may reach a report. The\n // mapped stack identifies which lane body threw. Returning the host's\n // result hands a rejection to the lane reporter's wrapper; discarding it\n // would surface as an unhandled rejection instead.\n reportUnexpectedError: (error) =>\n input.logError?.(\"Container contents: sync lane failed\", error),\n run: input.run,\n shouldIgnoreError: isDatabaseUnavailableError,\n },\n );\n}\n\n/** The lane's run counters, for work that waits on a pass it requested. */\nexport function readContainerContentsSyncLane(domainScope: DomainScope) {\n return (\n getOrCreateDomainSyncCoordinator(domainScope)\n .getSnapshot()\n .lanes.find((lane) => lane.key === CONTAINER_CONTENTS_SYNC_LANE_KEY) ??\n null\n );\n}\n"]}
|
|
@@ -4,14 +4,13 @@ import type { ProjectionUserKeyResolver } from "../../../data/keyingProjectionVe
|
|
|
4
4
|
import { type DocumentsPersistence, deletePersistedDocument, type RemoteDocumentServiceApi } from "../../documents/index.js";
|
|
5
5
|
import type { SubtreePurgeRoot } from "../../documents/purge/subtreePurgeScope.js";
|
|
6
6
|
import type { ContainerContentsWorkflowRuntime } from "../runtime.js";
|
|
7
|
-
type ContainerDocumentPurgeApi = RemoteDocumentServiceApi & Pick<ContainerContentsWorkflowRuntime["apiClient"], "getPrincipalPolicyPages" | "getProjectionPolicyHistoryPages">;
|
|
8
7
|
type DocumentPurgeResult = DocumentPurgeResponse | {
|
|
9
8
|
readonly documentId: string;
|
|
10
9
|
readonly purgedAt: string;
|
|
11
10
|
readonly reclaimedBlobStorageKeys: readonly string[];
|
|
12
11
|
} | null;
|
|
13
|
-
interface ContainerDocumentPurgeRuntime extends Pick<ContainerContentsWorkflowRuntime, "auth" | "crypto" | "infra" | "resolveTrustedUserIdentity" | "state" | "util"> {
|
|
14
|
-
apiClient:
|
|
12
|
+
interface ContainerDocumentPurgeRuntime extends Pick<ContainerContentsWorkflowRuntime, "auth" | "crypto" | "infra" | "principalPolicies" | "resolveTrustedUserIdentity" | "state" | "util"> {
|
|
13
|
+
apiClient: RemoteDocumentServiceApi;
|
|
15
14
|
}
|
|
16
15
|
interface PurgeRemoteContainerDocumentInput {
|
|
17
16
|
beforeSubmit?: (() => Promise<boolean>) | undefined;
|
|
@@ -3,7 +3,6 @@ import { rethrowProjectionVerificationCancelled } from "../../../data/keyingProj
|
|
|
3
3
|
import { errorMessage } from "../../../data/shared/errorMessage.js";
|
|
4
4
|
import { defaultDocumentsPersistence, deletePersistedDocument, RemoteDocumentService, reclaimDocumentOrphanBlobs, resolveDocumentCreateAuthor, } from "../../documents/index.js";
|
|
5
5
|
import { ensureDocumentClientProjectionTables } from "../../documents/persistence.js";
|
|
6
|
-
import { createRuntimePrincipalPolicyWarmer } from "../../principals/runtimePolicyWarmer.js";
|
|
7
6
|
async function deleteAbsentDocumentState(input) {
|
|
8
7
|
return input.persistence.deleteDocumentSideRowsIfAbsent(input.runtime.infra.execSql, input.noteId, input.documentId, async (transactionExecSql) => {
|
|
9
8
|
await input.runtime.infra.documentProjectors.deleteStoredDocumentClientProjection({
|
|
@@ -71,7 +70,7 @@ export async function purgeRemoteContainerDocument(input) {
|
|
|
71
70
|
});
|
|
72
71
|
},
|
|
73
72
|
resolveProjectionUserKey: input.resolveProjectionUserKey,
|
|
74
|
-
warmReferencedPrincipalPolicies:
|
|
73
|
+
warmReferencedPrincipalPolicies: runtime.principalPolicies.createWarmer(),
|
|
75
74
|
});
|
|
76
75
|
if (!response) {
|
|
77
76
|
runtime.util.log(`Container contents: failed to purge note ${noteId} (document ${documentId})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentPurge.js","sourceRoot":"","sources":["documentPurge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAAE,sCAAsC,EAAE,MAAM,kDAAkD,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAEL,2BAA2B,EAC3B,uBAAuB,EACvB,qBAAqB,EAErB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oCAAoC,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AA0C1F,KAAK,UAAU,yBAAyB,CAAC,KASxC;IACC,OAAO,KAAK,CAAC,WAAW,CAAC,8BAA8B,CACrD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAC3B,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,EAChB,KAAK,EAAE,kBAAkB,EAAE,EAAE;QAC3B,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,oCAAoC,CAC/E;YACE,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,OAAO,EAAE,kBAAkB;YAC3B,OAAO,EAAE,KAAK,CAAC,MAAM;SACtB,CACF,CAAC;QACF,MAAM,KAAK,CAAC,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K,CAAC,mBAAmB,CAAC,EAC3D,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,GAAG,CACd,yDAAyD,MAAM,wCAAwC,CACxG,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC;YAC5C,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,kBAAkB;YACpD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,cAAc;YACd,OAAO,EAAE,MAAM;YACf,WAAW;SACZ,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,GAAG,CACd,yDAAyD,MAAM,+BAA+B,CAC/F,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,0BAA0B,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,8CAA8C,MAAM,EAAE,CAAC,CAAC;QACzE,OAAO;YACL,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAClC,wBAAwB,EAAE,EAAE;SAC7B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,GAAG,CACd,uDAAuD,MAAM,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CACxF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { DocumentPurgeResponse } from \"@tearleads/validators/response\";\nimport type { StoredDocumentKind } from \"../../../data/documents/documentKinds\";\nimport type { ProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification\";\nimport { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport { rethrowProjectionVerificationCancelled } from \"../../../data/keyingProjectionVerification/types\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n type DocumentsPersistence,\n defaultDocumentsPersistence,\n deletePersistedDocument,\n RemoteDocumentService,\n type RemoteDocumentServiceApi,\n reclaimDocumentOrphanBlobs,\n resolveDocumentCreateAuthor,\n} from \"../../documents\";\nimport { ensureDocumentClientProjectionTables } from \"../../documents/persistence\";\nimport type { SubtreePurgeRoot } from \"../../documents/purge/subtreePurgeScope\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../principals/runtimePolicyWarmer\";\nimport type { ContainerContentsWorkflowRuntime } from \"../runtime\";\n\ntype ContainerDocumentPurgeApi = RemoteDocumentServiceApi &\n Pick<\n ContainerContentsWorkflowRuntime[\"apiClient\"],\n \"getPrincipalPolicyPages\" | \"getProjectionPolicyHistoryPages\"\n >;\ntype DocumentPurgeResult =\n | DocumentPurgeResponse\n | {\n readonly documentId: string;\n readonly purgedAt: string;\n readonly reclaimedBlobStorageKeys: readonly string[];\n }\n | null;\n\ninterface ContainerDocumentPurgeRuntime\n extends Pick<\n ContainerContentsWorkflowRuntime,\n | \"auth\"\n | \"crypto\"\n | \"infra\"\n | \"resolveTrustedUserIdentity\"\n | \"state\"\n | \"util\"\n > {\n apiClient: ContainerDocumentPurgeApi;\n}\n\ninterface PurgeRemoteContainerDocumentInput {\n beforeSubmit?: (() => Promise<boolean>) | undefined;\n documentId: string;\n expectedSubtreeRoot?: SubtreePurgeRoot | undefined;\n stillCurrent?: (() => boolean) | undefined;\n documentKind: StoredDocumentKind;\n noteId: string;\n persistence?: DocumentsPersistence | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerDocumentPurgeRuntime;\n}\n\nasync function deleteAbsentDocumentState(input: {\n readonly commitPurgeProof: (\n transactionExecSql: ContainerDocumentPurgeRuntime[\"infra\"][\"execSql\"],\n ) => Promise<void>;\n readonly documentId: string;\n readonly documentKind: StoredDocumentKind;\n readonly noteId: string;\n readonly persistence: DocumentsPersistence;\n readonly runtime: ContainerDocumentPurgeRuntime;\n}): Promise<boolean> {\n return input.persistence.deleteDocumentSideRowsIfAbsent(\n input.runtime.infra.execSql,\n input.noteId,\n input.documentId,\n async (transactionExecSql) => {\n await input.runtime.infra.documentProjectors.deleteStoredDocumentClientProjection(\n {\n documentKind: input.documentKind,\n execSql: transactionExecSql,\n localId: input.noteId,\n },\n );\n await input.commitPurgeProof(transactionExecSql);\n },\n );\n}\n\nasync function commitVerifiedDocumentPurge(input: {\n readonly commitPurgeProof: (\n transactionExecSql: ContainerDocumentPurgeRuntime[\"infra\"][\"execSql\"],\n ) => Promise<void>;\n readonly documentId: string;\n readonly documentKind: StoredDocumentKind;\n readonly noteId: string;\n readonly persistence: DocumentsPersistence;\n readonly runtime: ContainerDocumentPurgeRuntime;\n}): Promise<boolean> {\n await input.persistence.ensureSchema(input.runtime.infra.execSql);\n await ensureDocumentClientProjectionTables({\n documentProjectors: input.runtime.infra.documentProjectors,\n execSql: input.runtime.infra.execSql,\n });\n const expectedRecord = await input.persistence.loadDocument(\n input.runtime.infra.execSql,\n input.noteId,\n );\n if (expectedRecord && expectedRecord.documentId !== input.documentId) {\n throw new Error(\n \"Local document identity changed while its remote purge was committing\",\n );\n }\n const deleted = expectedRecord\n ? await deletePersistedDocument({\n beforeDeleteInTransaction: input.commitPurgeProof,\n documentProjectors: input.runtime.infra.documentProjectors,\n execSql: input.runtime.infra.execSql,\n expectedRecord,\n localId: input.noteId,\n persistence: input.persistence,\n })\n : await deleteAbsentDocumentState(input);\n if (!deleted) {\n throw new Error(\n \"Local document state changed while its remote purge was committing\",\n );\n }\n return true;\n}\n\nexport async function purgeRemoteContainerDocument(\n input: PurgeRemoteContainerDocumentInput,\n): Promise<DocumentPurgeResult> {\n const { documentId, noteId, runtime } = input;\n const persistence = input.persistence ?? defaultDocumentsPersistence;\n try {\n const author = resolveDocumentCreateAuthor(runtime);\n if (!author) {\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} because the local signing context is unavailable`,\n );\n return null;\n }\n let deleted = false;\n const remoteDocuments = new RemoteDocumentService({\n api: runtime.apiClient,\n encapsulationSecretKey:\n runtime.crypto.encapsulationKeyPair?.secretKey ?? null,\n execSql: runtime.infra.execSql,\n });\n const response = await remoteDocuments.purgeRemoteDocument({\n beforeSubmit: input.beforeSubmit,\n author,\n documentId,\n expectedSubtreeRoot: input.expectedSubtreeRoot,\n stillCurrent: input.stillCurrent,\n onVerifiedPurge: async ({ commitPurgeProof }) => {\n deleted = await commitVerifiedDocumentPurge({\n commitPurgeProof,\n documentId,\n documentKind: input.documentKind,\n noteId,\n persistence,\n runtime,\n });\n },\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n warmReferencedPrincipalPolicies:\n createRuntimePrincipalPolicyWarmer(runtime),\n });\n if (!response) {\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} (document ${documentId})`,\n );\n return null;\n }\n if (deleted) {\n void reclaimDocumentOrphanBlobs(runtime, persistence);\n }\n runtime.util.log(\n `Container contents: purged note ${noteId} (document ${documentId})`,\n );\n return response;\n } catch (error) {\n // A cancelled verification is neither a failure nor a completed purge; the\n // caller that owns the generation decides what to do with it.\n rethrowProjectionVerificationCancelled(error);\n await reportAndRethrowKeyingVerificationError(\n error,\n runtime.util.reportSecurityIncident,\n {\n objectId: documentId,\n objectKind: \"document\",\n operation: \"document.purge\",\n },\n );\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} (document ${documentId}): ${errorMessage(error)}`,\n );\n return null;\n }\n}\n\ninterface ContainerDocumentLocalPurgeRuntime\n extends Pick<ContainerContentsWorkflowRuntime, \"infra\" | \"util\"> {}\n\nexport async function purgeLocalContainerDocument(input: {\n beforeDeleteInTransaction?: Parameters<\n typeof deletePersistedDocument\n >[0][\"beforeDeleteInTransaction\"];\n noteId: string;\n expectedContainerId?: string | null | undefined;\n persistence?: DocumentsPersistence | undefined;\n runtime: ContainerDocumentLocalPurgeRuntime;\n}): Promise<DocumentPurgeResult> {\n const { noteId, runtime } = input;\n const persistence = input.persistence ?? defaultDocumentsPersistence;\n try {\n await persistence.ensureSchema(runtime.infra.execSql);\n const expectedRecord = await persistence.loadDocument(\n runtime.infra.execSql,\n noteId,\n );\n if (\n !expectedRecord ||\n expectedRecord.documentId !== null ||\n (input.expectedContainerId !== undefined &&\n expectedRecord.containerId !== input.expectedContainerId)\n ) {\n runtime.util.log(\n `Container contents: local-only purge refused for note ${noteId} because it is absent or remote-backed`,\n );\n return null;\n }\n const deleted = await deletePersistedDocument({\n beforeDeleteInTransaction: input.beforeDeleteInTransaction,\n documentProjectors: runtime.infra.documentProjectors,\n execSql: runtime.infra.execSql,\n expectedRecord,\n localId: noteId,\n persistence,\n });\n if (!deleted) {\n runtime.util.log(\n `Container contents: local-only purge refused for note ${noteId} because its identity changed`,\n );\n return null;\n }\n if (deleted) {\n void reclaimDocumentOrphanBlobs(runtime, persistence);\n }\n runtime.util.log(`Container contents: purged local-only note ${noteId}`);\n return {\n documentId: noteId,\n purgedAt: new Date().toISOString(),\n reclaimedBlobStorageKeys: [],\n };\n } catch (error) {\n runtime.util.log(\n `Container contents: failed to purge local-only note ${noteId}: ${errorMessage(error)}`,\n );\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentPurge.js","sourceRoot":"","sources":["documentPurge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAAE,sCAAsC,EAAE,MAAM,kDAAkD,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAEL,2BAA2B,EAC3B,uBAAuB,EACvB,qBAAqB,EAErB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oCAAoC,EAAE,MAAM,6BAA6B,CAAC;AAwCnF,KAAK,UAAU,yBAAyB,CAAC,KASxC;IACC,OAAO,KAAK,CA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ACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,GAAG,CACd,uDAAuD,MAAM,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CACxF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { DocumentPurgeResponse } from \"@tearleads/validators/response\";\nimport type { StoredDocumentKind } from \"../../../data/documents/documentKinds\";\nimport type { ProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification\";\nimport { reportAndRethrowKeyingVerificationError } from \"../../../data/keyingProjectionVerification/error\";\nimport { rethrowProjectionVerificationCancelled } from \"../../../data/keyingProjectionVerification/types\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n type DocumentsPersistence,\n defaultDocumentsPersistence,\n deletePersistedDocument,\n RemoteDocumentService,\n type RemoteDocumentServiceApi,\n reclaimDocumentOrphanBlobs,\n resolveDocumentCreateAuthor,\n} from \"../../documents\";\nimport { ensureDocumentClientProjectionTables } from \"../../documents/persistence\";\nimport type { SubtreePurgeRoot } from \"../../documents/purge/subtreePurgeScope\";\n\nimport type { ContainerContentsWorkflowRuntime } from \"../runtime\";\n\ntype DocumentPurgeResult =\n | DocumentPurgeResponse\n | {\n readonly documentId: string;\n readonly purgedAt: string;\n readonly reclaimedBlobStorageKeys: readonly string[];\n }\n | null;\n\ninterface ContainerDocumentPurgeRuntime\n extends Pick<\n ContainerContentsWorkflowRuntime,\n | \"auth\"\n | \"crypto\"\n | \"infra\"\n | \"principalPolicies\"\n | \"resolveTrustedUserIdentity\"\n | \"state\"\n | \"util\"\n > {\n apiClient: RemoteDocumentServiceApi;\n}\n\ninterface PurgeRemoteContainerDocumentInput {\n beforeSubmit?: (() => Promise<boolean>) | undefined;\n documentId: string;\n expectedSubtreeRoot?: SubtreePurgeRoot | undefined;\n stillCurrent?: (() => boolean) | undefined;\n documentKind: StoredDocumentKind;\n noteId: string;\n persistence?: DocumentsPersistence | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerDocumentPurgeRuntime;\n}\n\nasync function deleteAbsentDocumentState(input: {\n readonly commitPurgeProof: (\n transactionExecSql: ContainerDocumentPurgeRuntime[\"infra\"][\"execSql\"],\n ) => Promise<void>;\n readonly documentId: string;\n readonly documentKind: StoredDocumentKind;\n readonly noteId: string;\n readonly persistence: DocumentsPersistence;\n readonly runtime: ContainerDocumentPurgeRuntime;\n}): Promise<boolean> {\n return input.persistence.deleteDocumentSideRowsIfAbsent(\n input.runtime.infra.execSql,\n input.noteId,\n input.documentId,\n async (transactionExecSql) => {\n await input.runtime.infra.documentProjectors.deleteStoredDocumentClientProjection(\n {\n documentKind: input.documentKind,\n execSql: transactionExecSql,\n localId: input.noteId,\n },\n );\n await input.commitPurgeProof(transactionExecSql);\n },\n );\n}\n\nasync function commitVerifiedDocumentPurge(input: {\n readonly commitPurgeProof: (\n transactionExecSql: ContainerDocumentPurgeRuntime[\"infra\"][\"execSql\"],\n ) => Promise<void>;\n readonly documentId: string;\n readonly documentKind: StoredDocumentKind;\n readonly noteId: string;\n readonly persistence: DocumentsPersistence;\n readonly runtime: ContainerDocumentPurgeRuntime;\n}): Promise<boolean> {\n await input.persistence.ensureSchema(input.runtime.infra.execSql);\n await ensureDocumentClientProjectionTables({\n documentProjectors: input.runtime.infra.documentProjectors,\n execSql: input.runtime.infra.execSql,\n });\n const expectedRecord = await input.persistence.loadDocument(\n input.runtime.infra.execSql,\n input.noteId,\n );\n if (expectedRecord && expectedRecord.documentId !== input.documentId) {\n throw new Error(\n \"Local document identity changed while its remote purge was committing\",\n );\n }\n const deleted = expectedRecord\n ? await deletePersistedDocument({\n beforeDeleteInTransaction: input.commitPurgeProof,\n documentProjectors: input.runtime.infra.documentProjectors,\n execSql: input.runtime.infra.execSql,\n expectedRecord,\n localId: input.noteId,\n persistence: input.persistence,\n })\n : await deleteAbsentDocumentState(input);\n if (!deleted) {\n throw new Error(\n \"Local document state changed while its remote purge was committing\",\n );\n }\n return true;\n}\n\nexport async function purgeRemoteContainerDocument(\n input: PurgeRemoteContainerDocumentInput,\n): Promise<DocumentPurgeResult> {\n const { documentId, noteId, runtime } = input;\n const persistence = input.persistence ?? defaultDocumentsPersistence;\n try {\n const author = resolveDocumentCreateAuthor(runtime);\n if (!author) {\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} because the local signing context is unavailable`,\n );\n return null;\n }\n let deleted = false;\n const remoteDocuments = new RemoteDocumentService({\n api: runtime.apiClient,\n encapsulationSecretKey:\n runtime.crypto.encapsulationKeyPair?.secretKey ?? null,\n execSql: runtime.infra.execSql,\n });\n const response = await remoteDocuments.purgeRemoteDocument({\n beforeSubmit: input.beforeSubmit,\n author,\n documentId,\n expectedSubtreeRoot: input.expectedSubtreeRoot,\n stillCurrent: input.stillCurrent,\n onVerifiedPurge: async ({ commitPurgeProof }) => {\n deleted = await commitVerifiedDocumentPurge({\n commitPurgeProof,\n documentId,\n documentKind: input.documentKind,\n noteId,\n persistence,\n runtime,\n });\n },\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n warmReferencedPrincipalPolicies: runtime.principalPolicies.createWarmer(),\n });\n if (!response) {\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} (document ${documentId})`,\n );\n return null;\n }\n if (deleted) {\n void reclaimDocumentOrphanBlobs(runtime, persistence);\n }\n runtime.util.log(\n `Container contents: purged note ${noteId} (document ${documentId})`,\n );\n return response;\n } catch (error) {\n // A cancelled verification is neither a failure nor a completed purge; the\n // caller that owns the generation decides what to do with it.\n rethrowProjectionVerificationCancelled(error);\n await reportAndRethrowKeyingVerificationError(\n error,\n runtime.util.reportSecurityIncident,\n {\n objectId: documentId,\n objectKind: \"document\",\n operation: \"document.purge\",\n },\n );\n runtime.util.log(\n `Container contents: failed to purge note ${noteId} (document ${documentId}): ${errorMessage(error)}`,\n );\n return null;\n }\n}\n\ninterface ContainerDocumentLocalPurgeRuntime\n extends Pick<ContainerContentsWorkflowRuntime, \"infra\" | \"util\"> {}\n\nexport async function purgeLocalContainerDocument(input: {\n beforeDeleteInTransaction?: Parameters<\n typeof deletePersistedDocument\n >[0][\"beforeDeleteInTransaction\"];\n noteId: string;\n expectedContainerId?: string | null | undefined;\n persistence?: DocumentsPersistence | undefined;\n runtime: ContainerDocumentLocalPurgeRuntime;\n}): Promise<DocumentPurgeResult> {\n const { noteId, runtime } = input;\n const persistence = input.persistence ?? defaultDocumentsPersistence;\n try {\n await persistence.ensureSchema(runtime.infra.execSql);\n const expectedRecord = await persistence.loadDocument(\n runtime.infra.execSql,\n noteId,\n );\n if (\n !expectedRecord ||\n expectedRecord.documentId !== null ||\n (input.expectedContainerId !== undefined &&\n expectedRecord.containerId !== input.expectedContainerId)\n ) {\n runtime.util.log(\n `Container contents: local-only purge refused for note ${noteId} because it is absent or remote-backed`,\n );\n return null;\n }\n const deleted = await deletePersistedDocument({\n beforeDeleteInTransaction: input.beforeDeleteInTransaction,\n documentProjectors: runtime.infra.documentProjectors,\n execSql: runtime.infra.execSql,\n expectedRecord,\n localId: noteId,\n persistence,\n });\n if (!deleted) {\n runtime.util.log(\n `Container contents: local-only purge refused for note ${noteId} because its identity changed`,\n );\n return null;\n }\n if (deleted) {\n void reclaimDocumentOrphanBlobs(runtime, persistence);\n }\n runtime.util.log(`Container contents: purged local-only note ${noteId}`);\n return {\n documentId: noteId,\n purgedAt: new Date().toISOString(),\n reclaimedBlobStorageKeys: [],\n };\n } catch (error) {\n runtime.util.log(\n `Container contents: failed to purge local-only note ${noteId}: ${errorMessage(error)}`,\n );\n return null;\n }\n}\n"]}
|
|
@@ -5,7 +5,6 @@ import { ProjectionDependencyUnavailableError } from "../../../data/keyingProjec
|
|
|
5
5
|
import { reportKeyingVerificationErrorInCauseChain } from "../../../data/keyingProjectionVerification/error.js";
|
|
6
6
|
import { createProjectionUserKeyResolver } from "../../../data/keyingProjectionVerification/userKeyResolver.js";
|
|
7
7
|
import { KeyingCheckpointRepository } from "../../../data/persistence/keyingCheckpoints/keyingCheckpointRepository.js";
|
|
8
|
-
import { createRuntimePrincipalPolicyWarmer, } from "../../principals/runtimePolicyWarmer.js";
|
|
9
8
|
import { documentHeadMatchesOrganization } from "../documentDiscovery/documentHeadScope.js";
|
|
10
9
|
export const HEAD_LINK_SET_LOAD_CONCURRENCY = 4;
|
|
11
10
|
/**
|
|
@@ -33,7 +32,9 @@ async function verifiedHeadLinkSet(runtime, deps, documentId, projection, policy
|
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
resolveProjectionUserKey: createProjectionUserKeyResolver(runtime),
|
|
36
|
-
warmReferencedPrincipalPolicies:
|
|
35
|
+
warmReferencedPrincipalPolicies: runtime.principalPolicies.createWarmer({
|
|
36
|
+
operation: policyOperation,
|
|
37
|
+
}),
|
|
37
38
|
});
|
|
38
39
|
if (!verified.value) {
|
|
39
40
|
throw new Error("Tombstone evidence lacks a verified document head");
|