@tearleads/client-sdk 0.1.252 → 0.1.253
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Tearleads.js +3 -3
- package/Tearleads.js.map +1 -1
- package/client/containerContents/index.d.ts +2 -0
- package/client/containerContents/index.js +4 -9
- package/client/containerContents/index.js.map +1 -1
- package/client/containerContents/storeRuntime.d.ts +17 -0
- package/client/containerContents/storeRuntime.js +31 -0
- package/client/containerContents/storeRuntime.js.map +1 -0
- package/client/deviceFirst/index.d.ts +2 -3
- package/client/deviceFirst/index.js +44 -22
- package/client/deviceFirst/index.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +2 -0
- package/client/runtime/workflowRuntime.js +13 -6
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/sync/syncCoordinator.js +17 -10
- package/data/sync/syncCoordinator.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +3 -9
- package/stores/container-contents/containerContentsStore.js +24 -21
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/containerState/storeScope.js +6 -0
- package/stores/container-contents/containerState/storeScope.js.map +1 -0
- package/stores/container-contents/hydration/backgroundHydration.js +2 -1
- package/stores/container-contents/hydration/backgroundHydration.js.map +1 -1
- package/stores/container-contents/hydration/reconnectRefresh.d.ts +10 -0
- package/stores/container-contents/hydration/reconnectRefresh.js +68 -0
- package/stores/container-contents/hydration/reconnectRefresh.js.map +1 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js +49 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js.map +1 -0
- package/stores/container-contents/hydration/remoteHydrationRefresh.js +4 -1
- package/stores/container-contents/hydration/remoteHydrationRefresh.js.map +1 -1
- package/stores/container-contents/hydration/remoteHydrationRequest.js +79 -10
- package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -1
- package/stores/container-contents/hydration/startupHydration.js +2 -9
- package/stores/container-contents/hydration/startupHydration.js.map +1 -1
- package/stores/container-contents/hydration/treeResetMachine.js +61 -0
- package/stores/container-contents/hydration/treeResetMachine.js.map +1 -0
- package/stores/container-contents/localRefresh.js +28 -12
- package/stores/container-contents/localRefresh.js.map +1 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js +4 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -1
- package/stores/container-contents/remoteWrites/writeGeneration.js +5 -2
- package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -1
- package/stores/container-contents/state.d.ts +3 -7
- package/stores/container-contents/state.js +27 -16
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/syncAgent/index.d.ts +7 -2
- package/stores/container-contents/syncAgent/index.js +77 -49
- package/stores/container-contents/syncAgent/index.js.map +1 -1
- package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +5 -2
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js +6 -3
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/stores/local-projection/localProjectionStore.js +24 -15
- package/stores/local-projection/localProjectionStore.js.map +1 -1
- package/stores/local-projection/registry.js +2 -2
- package/stores/local-projection/registry.js.map +1 -1
- package/workflows/container-contents/container-state/create/createChild.js +3 -15
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +4 -8
- package/workflows/container-contents/containerPersistence.js +22 -12
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/localState.js +3 -0
- package/workflows/container-contents/localState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.d.ts +12 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js +93 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js.map +1 -0
- package/workflows/container-contents/remoteHydration/index.d.ts +3 -11
- package/workflows/container-contents/remoteHydration/index.js +17 -66
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js +3 -2
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -1
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js +57 -5
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +105 -62
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +15 -5
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +13 -0
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/runtime.d.ts +3 -0
- package/workflows/container-contents/runtime.js.map +1 -1
- package/workflows/container-contents/storedContainerState.js +17 -7
- package/workflows/container-contents/storedContainerState.js.map +1 -1
- package/workflows/container-contents/syncLane.d.ts +1 -0
- package/workflows/container-contents/syncLane.js +9 -1
- package/workflows/container-contents/syncLane.js.map +1 -1
- package/workflows/shared/runtimeInput.d.ts +2 -0
- package/workflows/shared/runtimeInput.js.map +1 -1
- package/workflows/container-contents/remoteHydration/completeHydration.js +0 -25
- package/workflows/container-contents/remoteHydration/completeHydration.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containerContentsStore.js","sourceRoot":"","sources":["containerContentsStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;AACxH,OAAO,EAEL,mCAAmC,GACpC,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,aAAa,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C,WAAW,CAAC,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,sBAAsB,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport { getCachedContainerWriterProjection } from \"../../workflows/container-contents/container-state/projectionCache\";\nimport {\n type ContainerContentsPersistence,\n defaultContainerContentsPersistence,\n} from \"../../workflows/container-contents/containerPersistence\";\nimport { persistContainerState } from \"./containerState/containerStatePersistence\";\nimport { createTreeRefreshMethods } from \"./hydration/remoteHydrationRefresh\";\nimport {\n createChildContainer,\n deleteContainer,\n ensureSystemContainer,\n moveContainer,\n renameContainer,\n} from \"./operations\";\nimport { emptyTrash } from \"./operations/emptyTrashOperation\";\nimport {\n prepareContainerGroupRewrap,\n verifyContainerGroupRewrapCurrent,\n} from \"./operations/groupRewrapOperation\";\nimport { purgeContainer } from \"./operations/purgeContainerOperation\";\nimport { chainPurgeAfterScopeMoves } from \"./operations/purgeMoveSettlementOperation\";\nimport { setContainerIcon } from \"./operations/setContainerIconOperation\";\nimport { setContainerPrimaryDocument } from \"./operations/setContainerPrimaryDocumentOperation\";\nimport {\n shareContainerWithGroup,\n shareContainerWithUser,\n} from \"./operations/shareOperations\";\nimport { chainContainerWrite } from \"./remoteWrites/localWriteQueue\";\nimport { chainRemoteContainerTask } from \"./remoteWrites/remoteWriteQueue\";\nimport { captureContainerWriteGeneration } from \"./remoteWrites/writeGeneration\";\nimport {\n createContainerContentsStoreState,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStorePersistence,\n updateContainerContentsStoreRuntime,\n} from \"./state\";\nimport {\n type ContainerContentsStoreRuntime,\n type ContainerContentsStoreSyncAgent,\n createContainerContentsStoreSyncAgent,\n} from \"./syncAgent\";\nimport { oweContainerMetadataRead } from \"./syncAgent/metadataRevalidation\";\nimport { findRootContainerState } from \"./systemContainers/systemContainerLookup\";\nimport type {\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerContentsStoreState,\n} from \"./types\";\n\nconst containerContentsStoresByScope = new WeakMap<\n DomainScope,\n ContainerContentsStoreEntry\n>();\n\ninterface ContainerContentsStoreEntry {\n requestDocumentPriming: () => void;\n store: ContainerContentsStore;\n updateOptions: (options: ContainerContentsStoreOptions) => void;\n}\n\nfunction applyContainerContentsStoreOptions(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n options: ContainerContentsStoreOptions,\n): void {\n if (\"logLabel\" in options) {\n state.logLabel = options.logLabel;\n }\n\n if (\"persistence\" in options) {\n updateContainerContentsStorePersistence(\n state,\n options.persistence ?? defaultContainerContentsPersistence,\n syncAgent,\n );\n }\n}\n\nfunction getCachedContainerWriterProjectionForStore(\n state: ContainerContentsStoreState,\n containerId: string,\n) {\n const containerState = state.containersById.get(containerId);\n return containerState\n ? getCachedContainerWriterProjection(containerState)\n : null;\n}\n\nfunction createContainerContentsStoreSyncHost(\n state: ContainerContentsStoreState,\n): Parameters<typeof createContainerContentsStoreSyncAgent>[0][\"host\"] {\n return {\n persistContainerState: (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) =>\n persistContainerState(state, containerState, {\n patch,\n updateView,\n saveOptions,\n ...mutationOptions,\n }),\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n },\n requestMetadataRevalidation: (request) =>\n oweContainerMetadataRead(state, request),\n updateSnapshot: () => updateContainerContentsSnapshot(state),\n };\n}\n\ntype ContainerWriteMethods = Pick<\n ContainerContentsStore,\n | \"createChild\"\n | \"deleteContainer\"\n | \"emptyTrash\"\n | \"ensureSystemContainer\"\n | \"moveContainer\"\n | \"prepareGroupRewrap\"\n | \"purgeContainer\"\n | \"renameContainer\"\n | \"setContainerIcon\"\n | \"setContainerPrimaryDocument\"\n | \"shareWithGroup\"\n | \"shareWithUser\"\n>;\n\n// The group-rewrap builder verifies any required existing grant before capturing\n// the container KEK, then returns a check/rewrap pair. A verified non-match is\n// distinct from an unavailable preparation so security-critical callers can\n// no-op unrelated groups without failing open for a real grant.\nfunction createPrepareGroupRewrapMethod(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerContentsStore[\"prepareGroupRewrap\"] {\n return async (containerId, groupId, accessLevel, options) => {\n const preparation = await chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n prepareContainerGroupRewrap(\n state,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n );\n return preparation?.status === \"prepared\"\n ? {\n isCurrent: (\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n ) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n verifyContainerGroupRewrapCurrent(\n state,\n containerId,\n groupId,\n accessLevel,\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n isCurrent,\n ),\n containerId,\n ),\n rewrap: () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n {\n ...options,\n knownContainerKeks: preparation.knownContainerKeks,\n // A prepared re-wrap is grant-preserving by definition, so\n // it never mints a grant and never needs the chosen name.\n requireExistingGrant: true,\n },\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n status: \"prepared\" as const,\n }\n : (preparation ?? null);\n };\n}\n\nfunction createContainerSharingMethods(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): Pick<ContainerWriteMethods, \"shareWithUser\" | \"shareWithGroup\"> {\n return {\n shareWithUser: (containerId, userId, accessLevel) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n async (isCurrent) => {\n // Sharing admits the recipient, so a pin observed on first sight is\n // not enough: a verified identity link (or this device's keys) must\n // have established it, or the full-bundle signed roster. The\n // check runs inside the write scope, which must still be current\n // once it returns.\n await state.runtime.requireVerifiedRecipient(userId, accessLevel);\n if (!isCurrent()) return false;\n return shareContainerWithUser(\n state,\n syncAgent,\n containerId,\n userId,\n accessLevel,\n isCurrent,\n );\n },\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n shareWithGroup: (containerId, groupId, accessLevel, options) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n };\n}\n\nfunction createDeleteContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"deleteContainer\"] {\n return (containerId) => {\n const current = captureContainerWriteGeneration(state);\n const remoteDelete = () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n deleteContainer(state, syncAgent, containerId, isCurrent),\n containerId,\n ).then((node) => node !== null);\n if (state.containersById.get(containerId)?.record.documentId)\n return remoteDelete();\n let promoted = false;\n return chainContainerWrite(\n state,\n (isCurrent) => {\n // Promotion can win while this local operation was queued. Hand it to\n // the remote queue after releasing the local chain, before any HTTP I/O.\n promoted = Boolean(\n state.containersById.get(containerId)?.record.documentId,\n );\n return promoted\n ? Promise.resolve(null)\n : deleteContainer(state, syncAgent, containerId, isCurrent);\n },\n [containerId],\n ).then((node) => (promoted && current() ? remoteDelete() : node !== null));\n };\n}\n\nfunction createEnsureSystemContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"ensureSystemContainer\"] {\n return (systemSlot, name, options) => {\n const work = (isCurrent: () => boolean) =>\n ensureSystemContainer(\n state,\n syncAgent,\n systemSlot,\n name,\n options,\n isCurrent,\n );\n const rootId = findRootContainerState(state)?.container.id;\n return options?.deferRemoteBootstrap\n ? chainContainerWrite(state, work, [])\n : chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n work,\n rootId ? { rootId, systemSlot } : undefined,\n );\n };\n}\n\nexport function createContainerWriteMethods(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerWriteMethods {\n return {\n ...createContainerSharingMethods(state, syncAgent),\n createChild: (parentId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n createChildContainer(state, syncAgent, parentId, name, isCurrent),\n [parentId],\n ),\n deleteContainer: createDeleteContainerMethod(state, syncAgent),\n purgeContainer: (containerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n containerId,\n options,\n (isCurrent) =>\n purgeContainer(state, syncAgent, containerId, options, isCurrent),\n ),\n emptyTrash: (trashContainerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n trashContainerId,\n options,\n (isCurrent) =>\n emptyTrash(state, syncAgent, trashContainerId, options, isCurrent),\n ),\n ensureSystemContainer: createEnsureSystemContainerMethod(state, syncAgent),\n moveContainer: (containerId, parentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n moveContainer(state, syncAgent, containerId, parentId, isCurrent),\n [containerId, parentId],\n containerId,\n ),\n prepareGroupRewrap: createPrepareGroupRewrapMethod(state, syncAgent),\n renameContainer: (containerId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n renameContainer(state, syncAgent, containerId, name, isCurrent),\n [containerId],\n ),\n setContainerPrimaryDocument: (containerId, documentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerPrimaryDocument(\n state,\n syncAgent,\n containerId,\n documentId,\n isCurrent,\n ),\n [containerId],\n ),\n setContainerIcon: (containerId, icon) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerIcon(state, syncAgent, containerId, icon, isCurrent),\n [containerId],\n ),\n };\n}\n\nfunction createContainerContentsStoreEntry(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStoreEntry {\n const state = createContainerContentsStoreState(\n initialRuntime,\n options.persistence ?? persistence,\n options.logLabel,\n );\n const syncAgent = createContainerContentsStoreSyncAgent({\n host: createContainerContentsStoreSyncHost(state),\n state,\n });\n const writeMethods = createContainerWriteMethods(state, syncAgent);\n\n return {\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n syncAgent.scheduleSync();\n },\n store: {\n ...writeMethods,\n ...createTreeRefreshMethods(state, syncAgent),\n // Force an on-demand local SQLite re-read (see the interface doc): arm the\n // gate refreshLocalContainerStates otherwise requires, which the runtime\n // auto-arms only on a context transition an on-demand caller cannot rely on.\n refreshLocalContainers: () => {\n state.localContainersNeedRefresh = true;\n return syncAgent.refreshLocalContainers();\n },\n requestSync: () => syncAgent.scheduleSync(),\n getCachedContainerWriterProjection: (containerId) =>\n getCachedContainerWriterProjectionForStore(state, containerId),\n getSnapshot: () => state.snapshot,\n subscribe: (listener) =>\n subscribeToContainerContentsStore(state, listener),\n updateRuntime: (runtime) =>\n updateContainerContentsStoreRuntime(state, runtime, syncAgent),\n },\n updateOptions: (nextOptions) =>\n applyContainerContentsStoreOptions(state, syncAgent, nextOptions),\n };\n}\n\nexport function createContainerContentsStore(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n return createContainerContentsStoreEntry(initialRuntime, persistence, options)\n .store;\n}\n\nexport function getOrCreateContainerContentsStore(\n domainScope: DomainScope,\n runtime: ContainerContentsStoreRuntime,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n const existingEntry = containerContentsStoresByScope.get(domainScope);\n if (existingEntry) {\n existingEntry.updateOptions(options);\n return existingEntry.store;\n }\n\n const nextEntry = createContainerContentsStoreEntry(\n runtime,\n defaultContainerContentsPersistence,\n options,\n );\n containerContentsStoresByScope.set(domainScope, nextEntry);\n return nextEntry.store;\n}\n\n/**\n * Arm the next structural pass's document-priming scan for a domain scope.\n * Priming normally re-arms only on store creation and topology changes, so a\n * caller that just tore down a document's local state uses this to have the\n * still-listed server document re-created without waiting for an app\n * restart. Returns false when the scope has no container-contents store yet;\n * the startup priming pass covers that case.\n */\nexport function requestContainerContentsDocumentPriming(\n domainScope: DomainScope,\n): boolean {\n const entry = containerContentsStoresByScope.get(domainScope);\n if (!entry) {\n return false;\n }\n\n entry.requestDocumentPriming();\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"containerContentsStore.js","sourceRoot":"","sources":["containerContentsStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;AACxH,OAAO,EAEL,mCAAmC,GACpC,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC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GAAG,CAAC,WAAW,CAAC,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,sBAAsB,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport { getCachedContainerWriterProjection } from \"../../workflows/container-contents/container-state/projectionCache\";\nimport {\n type ContainerContentsPersistence,\n defaultContainerContentsPersistence,\n} from \"../../workflows/container-contents/containerPersistence\";\nimport { getOrCreateDomainSyncCoordinator } from \"../../workflows/sync/coordination\";\nimport { persistContainerState } from \"./containerState/containerStatePersistence\";\nimport { createTreeRefreshMethods } from \"./hydration/remoteHydrationRefresh\";\nimport {\n createChildContainer,\n deleteContainer,\n ensureSystemContainer,\n moveContainer,\n renameContainer,\n} from \"./operations\";\nimport { emptyTrash } from \"./operations/emptyTrashOperation\";\nimport {\n prepareContainerGroupRewrap,\n verifyContainerGroupRewrapCurrent,\n} from \"./operations/groupRewrapOperation\";\nimport { purgeContainer } from \"./operations/purgeContainerOperation\";\nimport { chainPurgeAfterScopeMoves } from \"./operations/purgeMoveSettlementOperation\";\nimport { setContainerIcon } from \"./operations/setContainerIconOperation\";\nimport { setContainerPrimaryDocument } from \"./operations/setContainerPrimaryDocumentOperation\";\nimport {\n shareContainerWithGroup,\n shareContainerWithUser,\n} from \"./operations/shareOperations\";\nimport { chainContainerWrite } from \"./remoteWrites/localWriteQueue\";\nimport { chainRemoteContainerTask } from \"./remoteWrites/remoteWriteQueue\";\nimport { captureContainerWriteGeneration } from \"./remoteWrites/writeGeneration\";\nimport {\n createContainerContentsStoreState,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStorePersistence,\n updateContainerContentsStoreRuntime,\n} from \"./state\";\nimport {\n type ContainerContentsStoreRuntime,\n type ContainerContentsStoreSyncAgent,\n type createContainerContentsStoreSyncAgent,\n prepareContainerContentsStoreSyncAgent,\n} from \"./syncAgent\";\nimport { oweContainerMetadataRead } from \"./syncAgent/metadataRevalidation\";\nimport { findRootContainerState } from \"./systemContainers/systemContainerLookup\";\nimport type {\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerContentsStoreState,\n} from \"./types\";\n\nconst containerContentsStoresByScope = new WeakMap<\n DomainScope,\n ContainerContentsStoreEntry\n>();\n\ninterface ContainerContentsStoreEntry {\n registerLane: () => void;\n isDisposed: () => boolean;\n requestDocumentPriming: () => void;\n store: ContainerContentsStore;\n updateOptions: (options: ContainerContentsStoreOptions) => void;\n}\n\nfunction applyContainerContentsStoreOptions(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n options: ContainerContentsStoreOptions,\n): void {\n if (\"logLabel\" in options) {\n state.logLabel = options.logLabel;\n }\n\n if (\"persistence\" in options) {\n updateContainerContentsStorePersistence(\n state,\n options.persistence ?? defaultContainerContentsPersistence,\n syncAgent,\n );\n }\n}\n\nfunction createContainerContentsStoreSyncHost(\n state: ContainerContentsStoreState,\n): Parameters<typeof createContainerContentsStoreSyncAgent>[0][\"host\"] {\n return {\n persistContainerState: (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) =>\n persistContainerState(state, containerState, {\n patch,\n updateView,\n saveOptions,\n ...mutationOptions,\n }),\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n },\n requestMetadataRevalidation: (request) =>\n oweContainerMetadataRead(state, request),\n updateSnapshot: () => updateContainerContentsSnapshot(state),\n };\n}\n\ntype ContainerWriteMethods = Pick<\n ContainerContentsStore,\n | \"createChild\"\n | \"deleteContainer\"\n | \"emptyTrash\"\n | \"ensureSystemContainer\"\n | \"moveContainer\"\n | \"prepareGroupRewrap\"\n | \"purgeContainer\"\n | \"renameContainer\"\n | \"setContainerIcon\"\n | \"setContainerPrimaryDocument\"\n | \"shareWithGroup\"\n | \"shareWithUser\"\n>;\n\n// The group-rewrap builder verifies any required existing grant before capturing\n// the container KEK, then returns a check/rewrap pair. A verified non-match is\n// distinct from an unavailable preparation so security-critical callers can\n// no-op unrelated groups without failing open for a real grant.\nfunction createPrepareGroupRewrapMethod(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerContentsStore[\"prepareGroupRewrap\"] {\n return async (containerId, groupId, accessLevel, options) => {\n const preparation = await chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n prepareContainerGroupRewrap(\n state,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n );\n return preparation?.status === \"prepared\"\n ? {\n isCurrent: (\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n ) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n verifyContainerGroupRewrapCurrent(\n state,\n containerId,\n groupId,\n accessLevel,\n expectedGroupHead,\n expectedContainerId,\n expectedOrganizationId,\n isCurrent,\n ),\n containerId,\n ),\n rewrap: () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n {\n ...options,\n knownContainerKeks: preparation.knownContainerKeks,\n // A prepared re-wrap is grant-preserving by definition, so\n // it never mints a grant and never needs the chosen name.\n requireExistingGrant: true,\n },\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n status: \"prepared\" as const,\n }\n : (preparation ?? null);\n };\n}\n\nfunction createContainerSharingMethods(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): Pick<ContainerWriteMethods, \"shareWithUser\" | \"shareWithGroup\"> {\n return {\n shareWithUser: (containerId, userId, accessLevel) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n async (isCurrent) => {\n // Sharing admits the recipient, so a pin observed on first sight is\n // not enough: a verified identity link (or this device's keys) must\n // have established it, or the full-bundle signed roster. The\n // check runs inside the write scope, which must still be current\n // once it returns.\n await state.runtime.requireVerifiedRecipient(userId, accessLevel);\n if (!isCurrent()) return false;\n return shareContainerWithUser(\n state,\n syncAgent,\n containerId,\n userId,\n accessLevel,\n isCurrent,\n );\n },\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n shareWithGroup: (containerId, groupId, accessLevel, options) =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n false,\n (isCurrent) =>\n shareContainerWithGroup(\n state,\n syncAgent,\n containerId,\n groupId,\n accessLevel,\n options,\n isCurrent,\n ),\n containerId,\n { preserveResultOnLocalWrite: true },\n ),\n };\n}\n\nfunction createDeleteContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"deleteContainer\"] {\n return (containerId) => {\n const current = captureContainerWriteGeneration(state);\n const remoteDelete = () =>\n chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n (isCurrent) =>\n deleteContainer(state, syncAgent, containerId, isCurrent),\n containerId,\n ).then((node) => node !== null);\n if (state.containersById.get(containerId)?.record.documentId)\n return remoteDelete();\n let promoted = false;\n return chainContainerWrite(\n state,\n (isCurrent) => {\n // Promotion can win while this local operation was queued. Hand it to\n // the remote queue after releasing the local chain, before any HTTP I/O.\n promoted = Boolean(\n state.containersById.get(containerId)?.record.documentId,\n );\n return promoted\n ? Promise.resolve(null)\n : deleteContainer(state, syncAgent, containerId, isCurrent);\n },\n [containerId],\n ).then((node) => (promoted && current() ? remoteDelete() : node !== null));\n };\n}\n\nfunction createEnsureSystemContainerMethod(\n state: ContainerContentsStoreState,\n syncAgent: ContainerContentsStoreSyncAgent,\n): ContainerContentsStore[\"ensureSystemContainer\"] {\n return (systemSlot, name, options) => {\n const work = (isCurrent: () => boolean) =>\n ensureSystemContainer(\n state,\n syncAgent,\n systemSlot,\n name,\n options,\n isCurrent,\n );\n const rootId = findRootContainerState(state)?.container.id;\n return options?.deferRemoteBootstrap\n ? chainContainerWrite(state, work, [])\n : chainRemoteContainerTask(\n state,\n syncAgent,\n null,\n work,\n rootId ? { rootId, systemSlot } : undefined,\n );\n };\n}\n\nexport function createContainerWriteMethods(\n state: ContainerContentsStoreState,\n syncAgent: ReturnType<typeof createContainerContentsStoreSyncAgent>,\n): ContainerWriteMethods {\n return {\n ...createContainerSharingMethods(state, syncAgent),\n createChild: (parentId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n createChildContainer(state, syncAgent, parentId, name, isCurrent),\n [parentId],\n ),\n deleteContainer: createDeleteContainerMethod(state, syncAgent),\n purgeContainer: (containerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n containerId,\n options,\n (isCurrent) =>\n purgeContainer(state, syncAgent, containerId, options, isCurrent),\n ),\n emptyTrash: (trashContainerId, options) =>\n chainPurgeAfterScopeMoves(\n state,\n syncAgent,\n trashContainerId,\n options,\n (isCurrent) =>\n emptyTrash(state, syncAgent, trashContainerId, options, isCurrent),\n ),\n ensureSystemContainer: createEnsureSystemContainerMethod(state, syncAgent),\n moveContainer: (containerId, parentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n moveContainer(state, syncAgent, containerId, parentId, isCurrent),\n [containerId, parentId],\n containerId,\n ),\n prepareGroupRewrap: createPrepareGroupRewrapMethod(state, syncAgent),\n renameContainer: (containerId, name) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n renameContainer(state, syncAgent, containerId, name, isCurrent),\n [containerId],\n ),\n setContainerPrimaryDocument: (containerId, documentId) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerPrimaryDocument(\n state,\n syncAgent,\n containerId,\n documentId,\n isCurrent,\n ),\n [containerId],\n ),\n setContainerIcon: (containerId, icon) =>\n chainContainerWrite(\n state,\n (isCurrent) =>\n setContainerIcon(state, syncAgent, containerId, icon, isCurrent),\n [containerId],\n ),\n };\n}\n\nfunction createContainerContentsStoreEntry(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStoreEntry {\n const state = createContainerContentsStoreState(\n initialRuntime,\n options.persistence ?? persistence,\n options.logLabel,\n );\n const { agent: syncAgent, registerLane } =\n prepareContainerContentsStoreSyncAgent({\n host: createContainerContentsStoreSyncHost(state),\n state,\n });\n const coordinator = getOrCreateDomainSyncCoordinator(\n initialRuntime.state.domainScope,\n );\n const writeMethods = createContainerWriteMethods(state, syncAgent);\n\n return {\n registerLane,\n isDisposed: coordinator.isDisposed,\n requestDocumentPriming: () => {\n state.documentStoresNeedPriming = true;\n syncAgent.scheduleSync();\n },\n store: {\n ...writeMethods,\n ...createTreeRefreshMethods(state, syncAgent),\n // Force an on-demand local SQLite re-read (see the interface doc): arm the\n // gate refreshLocalContainerStates otherwise requires, which the runtime\n // auto-arms only on a context transition an on-demand caller cannot rely on.\n refreshLocalContainers: () => {\n state.localContainersNeedRefresh = true;\n return syncAgent.refreshLocalContainers();\n },\n requestSync: () => syncAgent.scheduleSync(),\n getCachedContainerWriterProjection: (containerId) => {\n const container = state.containersById.get(containerId);\n return container ? getCachedContainerWriterProjection(container) : null;\n },\n getSnapshot: () => state.snapshot,\n subscribe: (listener) =>\n subscribeToContainerContentsStore(state, listener),\n updateRuntime: (runtime) =>\n updateContainerContentsStoreRuntime(state, runtime, syncAgent),\n },\n updateOptions: (nextOptions) =>\n applyContainerContentsStoreOptions(state, syncAgent, nextOptions),\n };\n}\n\nexport function createContainerContentsStore(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence = defaultContainerContentsPersistence,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n const entry = createContainerContentsStoreEntry(\n initialRuntime,\n persistence,\n options,\n );\n entry.registerLane();\n if (entry.isDisposed())\n throw new Error(\"Container scope retired during registration\");\n return entry.store;\n}\n\nexport function getOrCreateContainerContentsStore(\n domainScope: DomainScope,\n runtime: ContainerContentsStoreRuntime,\n options: ContainerContentsStoreOptions = {},\n): ContainerContentsStore {\n const existingEntry = containerContentsStoresByScope.get(domainScope);\n if (existingEntry && !existingEntry.isDisposed()) {\n existingEntry.updateOptions(options);\n return existingEntry.store;\n }\n\n const nextEntry = createContainerContentsStoreEntry(\n runtime,\n defaultContainerContentsPersistence,\n options,\n );\n containerContentsStoresByScope.set(domainScope, nextEntry);\n // Registering the lane publishes a snapshot and can synchronously reopen this tree.\n nextEntry.registerLane();\n const current = containerContentsStoresByScope.get(domainScope);\n if (!current || current.isDisposed())\n throw new Error(\"Container scope retired during registration\");\n return current.store;\n}\n\n/** Re-arm priming after a local deletion so the next pass re-creates still-listed documents.\n * A new store already primes its documents on startup. */\nexport function requestContainerContentsDocumentPriming(\n domainScope: DomainScope,\n): boolean {\n const entry = containerContentsStoresByScope.get(domainScope);\n if (!entry) {\n return false;\n }\n\n entry.requestDocumentPriming();\n return true;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeScope.js","sourceRoot":"","sources":["storeScope.ts"],"names":[],"mappings":"AAOA,6EAA6E;AAC7E,MAAM,UAAU,kBAAkB,CAAC,KAA0B;IAC3D,OAAO,CACL,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE;QAC/B,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,KAAK,SAAS,CACpD,CAAC;AACJ,CAAC","sourcesContent":["import type { ContainerContentsStoreWorkflowRuntime } from \"../../../workflows/container-contents/runtime\";\n\nexport interface ContainerStoreScope {\n runtime: Pick<ContainerContentsStoreWorkflowRuntime, \"liveHydrationStatus\">;\n syncLane?: { isDisposed?: () => boolean } | null;\n}\n\n/** The host can retire a store without delivering another runtime update. */\nexport function ownsContainerStore(state: ContainerStoreScope): boolean {\n return (\n !state.syncLane?.isDisposed?.() &&\n state.runtime.liveHydrationStatus?.() !== \"retired\"\n );\n}\n"]}
|
|
@@ -6,7 +6,8 @@ export function observeContainerBackgroundHydration(state, hydration) {
|
|
|
6
6
|
const generation = state.lifecycleGeneration;
|
|
7
7
|
const runtime = state.runtime;
|
|
8
8
|
void hydration.catch(async (error) => {
|
|
9
|
-
if (state.
|
|
9
|
+
if (state.syncLane?.isDisposed?.() ||
|
|
10
|
+
state.lifecycleGeneration !== generation ||
|
|
10
11
|
isDatabaseUnavailableError(error))
|
|
11
12
|
return;
|
|
12
13
|
await reportKeyingVerificationErrorInCauseChain(error, runtime.util.reportSecurityIncident, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundHydration.js","sourceRoot":"","sources":["backgroundHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,yCAAyC,EAAE,MAAM,wCAAwC,CAAC;AACnG,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAG5F,4EAA4E;AAC5E,MAAM,UAAU,mCAAmC,CACjD,KAAsC,EACtC,
|
|
1
|
+
{"version":3,"file":"backgroundHydration.js","sourceRoot":"","sources":["backgroundHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,yCAAyC,EAAE,MAAM,wCAAwC,CAAC;AACnG,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAG5F,4EAA4E;AAC5E,MAAM,UAAU,mCAAmC,CACjD,KAAsC,EACtC,SAA2B;IAE3B,MAAM,UAAU,GAAG,KAAK,CAAC,mBAAmB,CAAC;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,KAAK,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAc,EAAE,EAAE;QAC5C,IACE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE;YAC9B,KAAK,CAAC,mBAAmB,KAAK,UAAU;YACxC,0BAA0B,CAAC,KAAK,CAAC;YAEjC,OAAO;QAET,MAAM,yCAAyC,CAC7C,KAAK,EACL,OAAO,CAAC,IAAI,CAAC,sBAAsB,EACnC;YACE,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,WAAW;YACvB,SAAS,EAAE,gCAAgC;YAC3C,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc;SAC5C,CACF,CAAC;QACF,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,uCAAuC,CAAC;YACxD,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC9C,CAAC;iBAAM,CAAC;gBACN,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;QAC1E,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { errorMessage } from \"../../../data/shared/errorMessage\";\nimport { reportKeyingVerificationErrorInCauseChain } from \"../../../data/shared/securityIncidents\";\nimport { isDatabaseUnavailableError } from \"../../../workflows/container-contents/syncLane\";\nimport type { ContainerContentsStoreSyncState } from \"../syncAgent/syncAgentTypes\";\n\n/** Observe a background refresh without changing the caller's rejection. */\nexport function observeContainerBackgroundHydration(\n state: ContainerContentsStoreSyncState,\n hydration: Promise<unknown>,\n): void {\n const generation = state.lifecycleGeneration;\n const runtime = state.runtime;\n void hydration.catch(async (error: unknown) => {\n if (\n state.syncLane?.isDisposed?.() ||\n state.lifecycleGeneration !== generation ||\n isDatabaseUnavailableError(error)\n )\n return;\n\n await reportKeyingVerificationErrorInCauseChain(\n error,\n runtime.util.reportSecurityIncident,\n {\n objectId: null,\n objectKind: \"container\",\n operation: \"container.hydration.background\",\n organizationId: runtime.auth.organizationId,\n },\n );\n try {\n const message = \"Container background hydration failed\";\n if (runtime.util.logError) {\n await runtime.util.logError(message, error);\n } else {\n await runtime.util.log(`${message}: ${errorMessage(error)}`);\n }\n } catch {\n // A host logger must not turn an observed refusal into a new rejection.\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReconnectCrawl } from "../../../workflows/container-contents/remoteHydration/index.js";
|
|
2
|
+
export declare class ReconnectRefresh {
|
|
3
|
+
private state;
|
|
4
|
+
private timer;
|
|
5
|
+
constructor(acknowledged: boolean);
|
|
6
|
+
reset(type: "acknowledged" | "runtimeChanged" | "disposed"): void;
|
|
7
|
+
runWhenReady(canRun: () => boolean, refresh: (options: {
|
|
8
|
+
reconnect: ReconnectCrawl;
|
|
9
|
+
}) => Promise<boolean>): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ProjectionDependencyUnavailableError } from "../../../data/shared/dependencyUnavailable.js";
|
|
2
|
+
import { transitionReconnectRefresh, } from "./reconnectRefreshMachine.js";
|
|
3
|
+
export class ReconnectRefresh {
|
|
4
|
+
state = { status: "idle" };
|
|
5
|
+
timer;
|
|
6
|
+
constructor(acknowledged) {
|
|
7
|
+
if (acknowledged)
|
|
8
|
+
this.reset("acknowledged");
|
|
9
|
+
}
|
|
10
|
+
reset(type) {
|
|
11
|
+
clearTimeout(this.timer);
|
|
12
|
+
this.timer = undefined;
|
|
13
|
+
this.state = transitionReconnectRefresh(this.state, { type });
|
|
14
|
+
}
|
|
15
|
+
runWhenReady(canRun, refresh) {
|
|
16
|
+
if (this.state.status !== "pending" || !canRun())
|
|
17
|
+
return;
|
|
18
|
+
const crawl = {};
|
|
19
|
+
this.state = transitionReconnectRefresh(this.state, {
|
|
20
|
+
type: "start",
|
|
21
|
+
crawl,
|
|
22
|
+
});
|
|
23
|
+
const isCurrent = () => this.state.status === "crawling" &&
|
|
24
|
+
this.state.crawl === crawl &&
|
|
25
|
+
canRun();
|
|
26
|
+
const finish = (outcome) => {
|
|
27
|
+
const next = transitionReconnectRefresh(this.state, {
|
|
28
|
+
type: "finish",
|
|
29
|
+
crawl,
|
|
30
|
+
outcome,
|
|
31
|
+
});
|
|
32
|
+
if (next === this.state)
|
|
33
|
+
return;
|
|
34
|
+
this.state = next;
|
|
35
|
+
if (next.status !== "backoff")
|
|
36
|
+
return;
|
|
37
|
+
this.timer = setTimeout(() => {
|
|
38
|
+
this.timer = undefined;
|
|
39
|
+
this.state = transitionReconnectRefresh(this.state, {
|
|
40
|
+
type: "retry",
|
|
41
|
+
crawl,
|
|
42
|
+
});
|
|
43
|
+
this.runWhenReady(canRun, refresh);
|
|
44
|
+
}, next.delayMs);
|
|
45
|
+
};
|
|
46
|
+
// A joined or interrupted crawl that never reported coverage owes a retry.
|
|
47
|
+
let outcome = "retry";
|
|
48
|
+
let manualRejection;
|
|
49
|
+
void refresh({
|
|
50
|
+
reconnect: {
|
|
51
|
+
isCurrent,
|
|
52
|
+
record: (value, error) => {
|
|
53
|
+
outcome = value;
|
|
54
|
+
manualRejection = error;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}).then(() => finish(isCurrent() ? outcome : "retry"), (error) => {
|
|
58
|
+
if (!isCurrent())
|
|
59
|
+
return finish("retry");
|
|
60
|
+
if (manualRejection && manualRejection === error)
|
|
61
|
+
return finish(outcome);
|
|
62
|
+
finish(error instanceof ProjectionDependencyUnavailableError
|
|
63
|
+
? "retry"
|
|
64
|
+
: "unexpectedFailure");
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=reconnectRefresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnectRefresh.js","sourceRoot":"","sources":["reconnectRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAC;AAKlG,OAAO,EAGL,0BAA0B,GAC3B,MAAM,2BAA2B,CAAC;AAEnC,MAAM,OAAO,gBAAgB;IACnB,K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CAAC,KAAK,GAAG,SAAS,CAAC;gBACvB,IAAI,CAAC,KAAK,GAAG,0BAA0B,CAAC,IAAI,CAAC,KAAK,EAAE;oBAClD,IAAI,EAAE,OAAO;oBACb,KAAK;iBACN,CAAC,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACrC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC;QACF,2EAA2E;QAC3E,IAAI,OAAO,GAAqB,OAAO,CAAC;QACxC,IAAI,eAAkC,CAAC;QACvC,KAAK,OAAO,CAAC;YACX,SAAS,EAAE;gBACT,SAAS;gBACT,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;oBACvB,OAAO,GAAG,KAAK,CAAC;oBAChB,eAAe,GAAG,KAAK,CAAC;gBAC1B,CAAC;aACF;SACF,CAAC,CAAC,IAAI,CACL,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAC7C,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,CAAC,SAAS,EAAE;gBAAE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;YACzC,IAAI,eAAe,IAAI,eAAe,KAAK,KAAK;gBAC9C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;YACzB,MAAM,CACJ,KAAK,YAAY,oCAAoC;gBACnD,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,mBAAmB,CACxB,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport type {\n HydrationOutcome,\n ReconnectCrawl,\n} from \"../../../workflows/container-contents/remoteHydration\";\nimport {\n type ReconnectOutcome,\n type ReconnectRefreshState,\n transitionReconnectRefresh,\n} from \"./reconnectRefreshMachine\";\n\nexport class ReconnectRefresh {\n private state: ReconnectRefreshState = { status: \"idle\" };\n private timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(acknowledged: boolean) {\n if (acknowledged) this.reset(\"acknowledged\");\n }\n\n reset(type: \"acknowledged\" | \"runtimeChanged\" | \"disposed\"): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.state = transitionReconnectRefresh(this.state, { type });\n }\n\n runWhenReady(\n canRun: () => boolean,\n refresh: (options: { reconnect: ReconnectCrawl }) => Promise<boolean>,\n ): void {\n if (this.state.status !== \"pending\" || !canRun()) return;\n const crawl = {};\n this.state = transitionReconnectRefresh(this.state, {\n type: \"start\",\n crawl,\n });\n const isCurrent = () =>\n this.state.status === \"crawling\" &&\n this.state.crawl === crawl &&\n canRun();\n const finish = (outcome: ReconnectOutcome) => {\n const next = transitionReconnectRefresh(this.state, {\n type: \"finish\",\n crawl,\n outcome,\n });\n if (next === this.state) return;\n this.state = next;\n if (next.status !== \"backoff\") return;\n this.timer = setTimeout(() => {\n this.timer = undefined;\n this.state = transitionReconnectRefresh(this.state, {\n type: \"retry\",\n crawl,\n });\n this.runWhenReady(canRun, refresh);\n }, next.delayMs);\n };\n // A joined or interrupted crawl that never reported coverage owes a retry.\n let outcome: HydrationOutcome = \"retry\";\n let manualRejection: Error | undefined;\n void refresh({\n reconnect: {\n isCurrent,\n record: (value, error) => {\n outcome = value;\n manualRejection = error;\n },\n },\n }).then(\n () => finish(isCurrent() ? outcome : \"retry\"),\n (error: unknown) => {\n if (!isCurrent()) return finish(\"retry\");\n if (manualRejection && manualRejection === error)\n return finish(outcome);\n finish(\n error instanceof ProjectionDependencyUnavailableError\n ? \"retry\"\n : \"unexpectedFailure\",\n );\n },\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const FIRST_ATTEMPT = {
|
|
2
|
+
status: "pending",
|
|
3
|
+
delayMs: 1_000,
|
|
4
|
+
refusals: 0,
|
|
5
|
+
};
|
|
6
|
+
const MAX_RETRY_MS = 60_000;
|
|
7
|
+
const PROOF_REFUSAL_LIMIT = 3;
|
|
8
|
+
function afterCrawl(state, outcome) {
|
|
9
|
+
if (outcome === "complete")
|
|
10
|
+
return { status: "idle" };
|
|
11
|
+
if (outcome === "unexpectedFailure")
|
|
12
|
+
return { status: "deferred" };
|
|
13
|
+
const refusals = outcome === "refused" ? state.refusals + 1 : 0;
|
|
14
|
+
if (refusals >= PROOF_REFUSAL_LIMIT)
|
|
15
|
+
return { status: "deferred" };
|
|
16
|
+
return { ...state, status: "backoff", refusals };
|
|
17
|
+
}
|
|
18
|
+
/** Only the current crawl or its own timer can consume outstanding work. */
|
|
19
|
+
export function transitionReconnectRefresh(state, event) {
|
|
20
|
+
if (state.status === "disposed")
|
|
21
|
+
return state;
|
|
22
|
+
switch (event.type) {
|
|
23
|
+
case "disposed":
|
|
24
|
+
return { status: "disposed" };
|
|
25
|
+
case "runtimeChanged":
|
|
26
|
+
return state.status === "idle" ? state : FIRST_ATTEMPT;
|
|
27
|
+
case "acknowledged":
|
|
28
|
+
return FIRST_ATTEMPT;
|
|
29
|
+
case "start":
|
|
30
|
+
return state.status === "pending"
|
|
31
|
+
? { ...state, status: "crawling", crawl: event.crawl }
|
|
32
|
+
: state;
|
|
33
|
+
case "finish":
|
|
34
|
+
return state.status === "crawling" && state.crawl === event.crawl
|
|
35
|
+
? afterCrawl(state, event.outcome)
|
|
36
|
+
: state;
|
|
37
|
+
case "retry":
|
|
38
|
+
return state.status === "backoff" && state.crawl === event.crawl
|
|
39
|
+
? {
|
|
40
|
+
status: "pending",
|
|
41
|
+
delayMs: Math.min(state.delayMs * 2, MAX_RETRY_MS),
|
|
42
|
+
refusals: state.refusals,
|
|
43
|
+
}
|
|
44
|
+
: state;
|
|
45
|
+
default:
|
|
46
|
+
return event;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=reconnectRefreshMachine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnectRefreshMach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,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;gBACtD,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,QAAQ;YACX,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;gBAC/D,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;gBAClC,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;gBAC9D,CAAC,CAAC;oBACE,MAAM,EAAE,SAAS;oBACjB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,YAAY,CAAC;oBAClD,QAAQ,EAAE,KAAK,CAAC,QAAQ;iBACzB;gBACH,CAAC,CAAC,KAAK,CAAC;QACZ;YACE,OAAO,KAAqB,CAAC;IACjC,CAAC;AACH,CAAC","sourcesContent":["import type { HydrationOutcome } from \"../../../workflows/container-contents/remoteHydration\";\n\ninterface RetryProgress {\n delayMs: number;\n refusals: number;\n}\nconst FIRST_ATTEMPT = {\n status: \"pending\",\n delayMs: 1_000,\n refusals: 0,\n} as const;\nconst MAX_RETRY_MS = 60_000;\nconst PROOF_REFUSAL_LIMIT = 3;\n\ntype ActiveCrawl = RetryProgress & {\n status: \"crawling\" | \"backoff\";\n crawl: object;\n};\nexport type ReconnectRefreshState =\n | { status: \"idle\" | \"deferred\" | \"disposed\" }\n | (RetryProgress & { status: \"pending\" })\n | ActiveCrawl;\n\nexport type ReconnectOutcome = HydrationOutcome | \"unexpectedFailure\";\n\ntype ReconnectRefreshEvent =\n | { type: \"acknowledged\" | \"runtimeChanged\" | \"disposed\" }\n | { type: \"start\"; crawl: object }\n | { type: \"finish\"; crawl: object; outcome: ReconnectOutcome }\n | { type: \"retry\"; crawl: object };\n\nfunction afterCrawl(\n state: ActiveCrawl,\n outcome: ReconnectOutcome,\n): ReconnectRefreshState {\n if (outcome === \"complete\") return { status: \"idle\" };\n if (outcome === \"unexpectedFailure\") return { status: \"deferred\" };\n const refusals = outcome === \"refused\" ? state.refusals + 1 : 0;\n if (refusals >= PROOF_REFUSAL_LIMIT) return { status: \"deferred\" };\n return { ...state, status: \"backoff\", refusals };\n}\n\n/** Only the current crawl or its own timer can consume outstanding work. */\nexport function transitionReconnectRefresh(\n state: ReconnectRefreshState,\n event: ReconnectRefreshEvent,\n): ReconnectRefreshState {\n if (state.status === \"disposed\") return state;\n switch (event.type) {\n case \"disposed\":\n return { status: \"disposed\" };\n case \"runtimeChanged\":\n return state.status === \"idle\" ? state : FIRST_ATTEMPT;\n case \"acknowledged\":\n return FIRST_ATTEMPT;\n case \"start\":\n return state.status === \"pending\"\n ? { ...state, status: \"crawling\", crawl: event.crawl }\n : state;\n case \"finish\":\n return state.status === \"crawling\" && state.crawl === event.crawl\n ? afterCrawl(state, event.outcome)\n : state;\n case \"retry\":\n return state.status === \"backoff\" && state.crawl === event.crawl\n ? {\n status: \"pending\",\n delayMs: Math.min(state.delayMs * 2, MAX_RETRY_MS),\n refusals: state.refusals,\n }\n : state;\n default:\n return event satisfies never;\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ownsContainerStore, } from "../containerState/storeScope.js";
|
|
1
2
|
/**
|
|
2
3
|
* The store's explicit tree refreshes. Each reports whether any container
|
|
3
4
|
* listing request failed or timed out while it ran: it waits on every crawl
|
|
@@ -56,7 +57,8 @@ function queueAllRemoteHydrationParentIds(state) {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
function canRefreshRemoteHydration(state) {
|
|
59
|
-
return (state
|
|
60
|
+
return (ownsContainerStore(state) &&
|
|
61
|
+
state.runtime.infra.dbStatus === "ready" &&
|
|
60
62
|
state.initialized &&
|
|
61
63
|
state.runtime.auth.isAuthenticated &&
|
|
62
64
|
state.runtime.state.online);
|
|
@@ -74,6 +76,7 @@ export function refreshAllRemoteHydration(input) {
|
|
|
74
76
|
// container's updatedAt, so a persisted watermark would hide it forever.
|
|
75
77
|
return requestHydration({
|
|
76
78
|
followDiscoveredParentLanes: true,
|
|
79
|
+
reconnect: input.reconnect,
|
|
77
80
|
onFullyHydrated: input.onFullyHydrated,
|
|
78
81
|
recreateOnFullyHydratedAfterReset: input.recreateOnFullyHydratedAfterReset,
|
|
79
82
|
...(input.resetAllLaneWatermarks ? { resetAllLaneWatermarks: true } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteHydrationRefresh.js","sourceRoot":"","sources":["remoteHydrationRefresh.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAoD,EACpD,SAGC;IAED,MAAM,OAAO,GAAG,KAAK,EACnB,OAA+B,EAC/B,QAAkD,EAChC,EAAE;QACpB,MAAM,cAAc,GAAG,KAAK,CAAC,wBAAwB,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,wBAAwB,KAAK,cAAc,EAAE,CAAC;YACtD,QAAQ,EAAE,oBAAoB,EAAE,EAAE,CAAC;QACrC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IACF,OAAO;QACL,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CACnB,OAAO,CACL,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,EACzD,OAAO,CACR;QACH,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE,CAC3B,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;KAC7D,CAAC;AACJ,CAAC;AA2BD,4EAA4E;AAC5E,wEAAwE;AACx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AC;QACrC,6EAA6E;QAC7E,0EAA0E;QAC1E,8EAA8E;QAC9E,+EAA+E;QAC/E,0EAA0E;QAC1E,6EAA6E;QAC7E,+EAA+E;QAC/E,wDAAwD;QACxD,6EAA6E;QAC7E,+EAA+E;QAC/E,6EAA6E;QAC7E,4CAA4C;QAC5C,MAAM,2BAA2B,GAC/B,kCAAkC,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,gBAAgB,CAAC;YACtB,2BAA2B,EAAE,KAAK;YAClC,SAAS,EAAE,2BAA2B;gBACpC,CAAC,CAAC,CAAC,IAAI,EAAE,2BAA2B,CAAC;gBACrC,CAAC,CAAC,CAAC,IAAI,CAAC;SACX,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,2EAA2E;IAC3E,iFAAiF;IACjF,4EAA4E;IAC5E,gFAAgF;IAChF,6EAA6E;IAC7E,oFAAoF;IACpF,EAAE;IACF,iFAAiF;IACjF,iEAAiE;IACjE,+EAA+E;IAC/E,+EAA+E;IAC/E,kFAAkF;IAClF,gFAAgF;IAChF,6EAA6E;IAC7E,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAC5B,IAAI,GAAG,CAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,CAC3D,CAAC;IACF,OAAO,gBAAgB,CAAC;QACtB,2BAA2B,EAAE,KAAK;QAClC,SAAS,EAAE,WAAW;QACtB,sBAAsB,EAAE,IAAI;KAC7B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import type { ContainerContentsStoreSyncAgent } from \"../syncAgent/syncAgentTypes\";\nimport type {\n ContainerContentsStore,\n ContainerTreeRefreshObserver,\n} from \"../types\";\n\nexport interface RemoteHydrationRefreshOptions {\n followDiscoveredParentLanes?: boolean | undefined;\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n parentIds?: ReadonlyArray<string | null> | undefined;\n resetAllLaneWatermarks?: boolean | undefined;\n resetRootLaneWatermark?: boolean | undefined;\n recreateOnFullyHydratedAfterReset?:\n | (() => () => Promise<void> | void)\n | undefined;\n scheduleSyncAfterHydration?: boolean | undefined;\n scheduleSyncOnHydrationChange?: boolean | undefined;\n}\n\nexport type RemoteHydrationRequester = (\n options: RemoteHydrationRefreshOptions,\n) => Promise<void>;\n\n/**\n * The store's explicit tree refreshes. Each reports whether any container\n * listing request failed or timed out while it ran: it waits on every crawl\n * that lists its lanes, so each of their failures falls inside that window.\n * Another crawl failing meanwhile is reported too, which errs toward calling\n * the tree possibly stale.\n */\nexport function createTreeRefreshMethods(\n state: { readonly containerListingFailures: number },\n syncAgent: Pick<\n ContainerContentsStoreSyncAgent,\n \"refresh\" | \"refreshRootLane\"\n >,\n): Pick<ContainerContentsStore, \"refresh\" | \"refreshRootLane\"> {\n const observe = async (\n refresh: () => Promise<boolean>,\n observer: ContainerTreeRefreshObserver | undefined,\n ): Promise<boolean> => {\n const failuresBefore = state.containerListingFailures;\n const started = await refresh();\n if (state.containerListingFailures !== failuresBefore) {\n observer?.onListingUnavailable?.();\n }\n return started;\n };\n return {\n refresh: (options) =>\n observe(\n () => syncAgent.refresh({ resetAllLaneWatermarks: true }),\n options,\n ),\n refreshRootLane: (options) =>\n observe(() => syncAgent.refreshRootLane(options), options),\n };\n}\n\ninterface RemoteHydrationRefreshState {\n containerParentIdsNeedingHydration: Set<string | null>;\n containersById: ReadonlyMap<string, RefreshRootContainerLike>;\n initialized: boolean;\n remoteHydrationPromise: Promise<void> | null;\n runtime: {\n auth: {\n isAuthenticated: boolean;\n organizationId?: string | null | undefined;\n };\n infra: { dbStatus: string };\n state: { containerId?: string | null | undefined; online: boolean };\n };\n}\n\nexport interface RefreshRootContainerLike {\n container: {\n id: string;\n metadataDocumentId?: string | null | undefined;\n organizationId: string | null;\n parentId: string | null;\n systemSlot?: string | null | undefined;\n };\n}\n\n// Resolve the parent whose child lane the provisioned-system-container poll\n// should list to pull organization-born children (Trash) into the tree.\n//\n// It must NOT trust runtime.state.containerId: after a cold-cache login of an\n// already-registered user, that value is still the pre-auth device-first LOCAL\n// root (organizationId \"\", no remote metadata) — login() never adopts the server\n// root id, and reconcileLocalOnlyRootContainers later deletes the local root out\n// from under it. Listing that dead local root's child lane returns nothing, so\n// the poll never pulls Trash, never satisfies its stop condition, and spins its\n// whole retry budget churning the tree (the sidebar flicker).\n//\n// Prefer instead the reconciled server root already in the tree: the top-level\n// (parentId === null) container in the viewer's own organization that carries\n// remote metadata. Fall back to runtime.state.containerId when no such root is\n// loaded yet — the null discovery lane then surfaces it and hydrateRemoteContainers\n// crawls a freshly-discovered container's child lane within the same pass.\nfunction resolveActiveRootChildLaneParentId(\n state: RemoteHydrationRefreshState,\n): string | null | undefined {\n const organizationId = state.runtime.auth.organizationId ?? null;\n if (organizationId !== null) {\n for (const { container } of state.containersById.values()) {\n if (\n container.parentId === null &&\n !container.systemSlot &&\n container.organizationId === organizationId &&\n (container.metadataDocumentId ?? null) !== null\n ) {\n return container.id;\n }\n }\n }\n\n return state.runtime.state.containerId;\n}\n\nfunction queueAllRemoteHydrationParentIds(state: RemoteHydrationRefreshState) {\n state.containerParentIdsNeedingHydration.add(null);\n for (const containerId of state.containersById.keys()) {\n state.containerParentIdsNeedingHydration.add(containerId);\n }\n}\n\nfunction canRefreshRemoteHydration(\n state: RemoteHydrationRefreshState,\n): boolean {\n return (\n state.runtime.infra.dbStatus === \"ready\" &&\n state.initialized &&\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online\n );\n}\n\nexport function refreshAllRemoteHydration(input: {\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n recreateOnFullyHydratedAfterReset?:\n | (() => () => Promise<void> | void)\n | undefined;\n requestHydration: RemoteHydrationRequester;\n resetAllLaneWatermarks?: boolean | undefined;\n scheduleSyncAfterHydration?: boolean | undefined;\n scheduleSyncOnHydrationChange?: boolean | undefined;\n state: RemoteHydrationRefreshState;\n}): Promise<boolean> {\n const { requestHydration, state } = input;\n if (!canRefreshRemoteHydration(state)) {\n return Promise.resolve(false);\n }\n\n if (state.remoteHydrationPromise) {\n queueAllRemoteHydrationParentIds(state);\n }\n\n // An explicit refresh always re-lists the root discovery lane from the start.\n // A grant that makes a new top-level container reachable does not bump that\n // container's updatedAt, so a persisted watermark would hide it forever.\n return requestHydration({\n followDiscoveredParentLanes: true,\n onFullyHydrated: input.onFullyHydrated,\n recreateOnFullyHydratedAfterReset: input.recreateOnFullyHydratedAfterReset,\n ...(input.resetAllLaneWatermarks ? { resetAllLaneWatermarks: true } : {}),\n resetRootLaneWatermark: true,\n scheduleSyncAfterHydration: input.scheduleSyncAfterHydration ?? true,\n ...(input.scheduleSyncOnHydrationChange === false\n ? { scheduleSyncOnHydrationChange: false }\n : {}),\n }).then(() => true);\n}\n\nexport function refreshRootRemoteHydration(input: {\n includeActiveRootChildLane?: boolean | undefined;\n parentIds?: ReadonlyArray<string | null> | undefined;\n requestHydration: RemoteHydrationRequester;\n state: RemoteHydrationRefreshState;\n}): Promise<boolean> {\n const { requestHydration, state } = input;\n if (!canRefreshRemoteHydration(state)) {\n return Promise.resolve(false);\n }\n\n if (input.includeActiveRootChildLane) {\n // Provisioned-system-container poll: it fires on a ~250ms interval until the\n // org-born slot (Trash) surfaces. List the reconciled server root's child\n // lane directly — resolved from the tree, NOT from runtime.state.containerId,\n // which after a cold-cache login is still the pre-auth device-first local root\n // that Trash does not live under — so Trash is pulled instead of the poll\n // spinning on a dead lane. Crucially do NOT reset the root-lane watermark on\n // this path: an unwatermarked re-list every tick makes hydrateRemoteContainers\n // count every listed container as \"changed\", re-running\n // updateSnapshot()+scheduleSync() on every tick and churning settling nodes'\n // sync badges for the whole poll window — the sidebar \"You\"/Trash flicker. The\n // stored watermark still surfaces Trash (a cold cache lists in full; a later\n // arrival advances the child lane past it).\n const activeRootChildLaneParentId =\n resolveActiveRootChildLaneParentId(state);\n return requestHydration({\n followDiscoveredParentLanes: false,\n parentIds: activeRootChildLaneParentId\n ? [null, activeRootChildLaneParentId]\n : [null],\n }).then(() => true);\n }\n\n // Automatic catch-up and the shared_with_you discovery event only need the\n // top-level lane, but they DO re-list it unwatermarked: a root newly shared with\n // the viewer does not bump the viewer's persisted root-lane watermark, so a\n // watermarked list would hide it forever. hydrateRemoteContainers then crawls a\n // freshly discovered root's child lane within the same pass. (The all-parent\n // traversal stays reserved for explicit user refresh in refreshAllRemoteHydration.)\n //\n // The resync_required handler also passes the affected containers' parent lanes.\n // A deleted nested container's tombstone is only returned by its\n // parent lane (rootDiscoveryVisible=false), never the root lane, so re-listing\n // that parent lane is what applies the tombstone and drops the stale container\n // without falling back to the full crawl. Those parent lanes keep their persisted\n // watermark (a deletion bumps the tombstone's updatedAt, so it still surfaces);\n // only the root lane is unwatermarked, for the newly-shared-root case above.\n const parentLanes = Array.from(\n new Set<string | null>([null, ...(input.parentIds ?? [])]),\n );\n return requestHydration({\n followDiscoveredParentLanes: false,\n parentIds: parentLanes,\n resetRootLaneWatermark: true,\n }).then(() => true);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteHydrationRefresh.js","sourceRoot":"","sources":["remoteHydrationRefresh.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAyBtC;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAoD,EACpD,SAGC;IAED,MAAM,OAAO,GAAG,KAAK,EACnB,OAA+B,EAC/B,QAAkD,EAChC,EAAE;QACpB,MAAM,cAAc,GAAG,KAAK,CAAC,wBAAwB,CAAC;QACtD,MAAM,OAAO,GAAG,MAAM,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,wBAAwB,KAAK,cAAc,EAAE,CAAC;YACtD,QAAQ,EAAE,oBAAoB,EAAE,EAAE,CAAC;QACrC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC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AK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,CAC3D,CAAC;IACF,OAAO,gBAAgB,CAAC;QACtB,2BAA2B,EAAE,KAAK;QAClC,SAAS,EAAE,WAAW;QACtB,sBAAsB,EAAE,IAAI;KAC7B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import type { ReconnectCrawl } from \"../../../workflows/container-contents/remoteHydration\";\nimport {\n type ContainerStoreScope,\n ownsContainerStore,\n} from \"../containerState/storeScope\";\nimport type { ContainerContentsStoreSyncAgent } from \"../syncAgent/syncAgentTypes\";\nimport type {\n ContainerContentsStore,\n ContainerTreeRefreshObserver,\n} from \"../types\";\n\nexport interface RemoteHydrationRefreshOptions {\n followDiscoveredParentLanes?: boolean | undefined;\n reconnect?: ReconnectCrawl | undefined;\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n parentIds?: ReadonlyArray<string | null> | undefined;\n resetAllLaneWatermarks?: boolean | undefined;\n resetRootLaneWatermark?: boolean | undefined;\n recreateOnFullyHydratedAfterReset?:\n | (() => () => Promise<void> | void)\n | undefined;\n scheduleSyncAfterHydration?: boolean | undefined;\n scheduleSyncOnHydrationChange?: boolean | undefined;\n}\n\nexport type RemoteHydrationRequester = (\n options: RemoteHydrationRefreshOptions,\n) => Promise<void>;\n\n/**\n * The store's explicit tree refreshes. Each reports whether any container\n * listing request failed or timed out while it ran: it waits on every crawl\n * that lists its lanes, so each of their failures falls inside that window.\n * Another crawl failing meanwhile is reported too, which errs toward calling\n * the tree possibly stale.\n */\nexport function createTreeRefreshMethods(\n state: { readonly containerListingFailures: number },\n syncAgent: Pick<\n ContainerContentsStoreSyncAgent,\n \"refresh\" | \"refreshRootLane\"\n >,\n): Pick<ContainerContentsStore, \"refresh\" | \"refreshRootLane\"> {\n const observe = async (\n refresh: () => Promise<boolean>,\n observer: ContainerTreeRefreshObserver | undefined,\n ): Promise<boolean> => {\n const failuresBefore = state.containerListingFailures;\n const started = await refresh();\n if (state.containerListingFailures !== failuresBefore) {\n observer?.onListingUnavailable?.();\n }\n return started;\n };\n return {\n refresh: (options) =>\n observe(\n () => syncAgent.refresh({ resetAllLaneWatermarks: true }),\n options,\n ),\n refreshRootLane: (options) =>\n observe(() => syncAgent.refreshRootLane(options), options),\n };\n}\n\ninterface RemoteHydrationRefreshState extends ContainerStoreScope {\n containerParentIdsNeedingHydration: Set<string | null>;\n containersById: ReadonlyMap<string, RefreshRootContainerLike>;\n initialized: boolean;\n remoteHydrationPromise: Promise<void> | null;\n runtime: ContainerStoreScope[\"runtime\"] & {\n auth: {\n isAuthenticated: boolean;\n organizationId?: string | null | undefined;\n };\n infra: { dbStatus: string };\n state: { containerId?: string | null | undefined; online: boolean };\n };\n}\n\nexport interface RefreshRootContainerLike {\n container: {\n id: string;\n metadataDocumentId?: string | null | undefined;\n organizationId: string | null;\n parentId: string | null;\n systemSlot?: string | null | undefined;\n };\n}\n\n// Resolve the parent whose child lane the provisioned-system-container poll\n// should list to pull organization-born children (Trash) into the tree.\n//\n// It must NOT trust runtime.state.containerId: after a cold-cache login of an\n// already-registered user, that value is still the pre-auth device-first LOCAL\n// root (organizationId \"\", no remote metadata) — login() never adopts the server\n// root id, and reconcileLocalOnlyRootContainers later deletes the local root out\n// from under it. Listing that dead local root's child lane returns nothing, so\n// the poll never pulls Trash, never satisfies its stop condition, and spins its\n// whole retry budget churning the tree (the sidebar flicker).\n//\n// Prefer instead the reconciled server root already in the tree: the top-level\n// (parentId === null) container in the viewer's own organization that carries\n// remote metadata. Fall back to runtime.state.containerId when no such root is\n// loaded yet — the null discovery lane then surfaces it and hydrateRemoteContainers\n// crawls a freshly-discovered container's child lane within the same pass.\nfunction resolveActiveRootChildLaneParentId(\n state: RemoteHydrationRefreshState,\n): string | null | undefined {\n const organizationId = state.runtime.auth.organizationId ?? null;\n if (organizationId !== null) {\n for (const { container } of state.containersById.values()) {\n if (\n container.parentId === null &&\n !container.systemSlot &&\n container.organizationId === organizationId &&\n (container.metadataDocumentId ?? null) !== null\n ) {\n return container.id;\n }\n }\n }\n\n return state.runtime.state.containerId;\n}\n\nfunction queueAllRemoteHydrationParentIds(state: RemoteHydrationRefreshState) {\n state.containerParentIdsNeedingHydration.add(null);\n for (const containerId of state.containersById.keys()) {\n state.containerParentIdsNeedingHydration.add(containerId);\n }\n}\n\nfunction canRefreshRemoteHydration(\n state: RemoteHydrationRefreshState,\n): boolean {\n return (\n ownsContainerStore(state) &&\n state.runtime.infra.dbStatus === \"ready\" &&\n state.initialized &&\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online\n );\n}\n\nexport function refreshAllRemoteHydration(input: {\n reconnect?: ReconnectCrawl | undefined;\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n recreateOnFullyHydratedAfterReset?:\n | (() => () => Promise<void> | void)\n | undefined;\n requestHydration: RemoteHydrationRequester;\n resetAllLaneWatermarks?: boolean | undefined;\n scheduleSyncAfterHydration?: boolean | undefined;\n scheduleSyncOnHydrationChange?: boolean | undefined;\n state: RemoteHydrationRefreshState;\n}): Promise<boolean> {\n const { requestHydration, state } = input;\n if (!canRefreshRemoteHydration(state)) {\n return Promise.resolve(false);\n }\n\n if (state.remoteHydrationPromise) {\n queueAllRemoteHydrationParentIds(state);\n }\n\n // An explicit refresh always re-lists the root discovery lane from the start.\n // A grant that makes a new top-level container reachable does not bump that\n // container's updatedAt, so a persisted watermark would hide it forever.\n return requestHydration({\n followDiscoveredParentLanes: true,\n reconnect: input.reconnect,\n onFullyHydrated: input.onFullyHydrated,\n recreateOnFullyHydratedAfterReset: input.recreateOnFullyHydratedAfterReset,\n ...(input.resetAllLaneWatermarks ? { resetAllLaneWatermarks: true } : {}),\n resetRootLaneWatermark: true,\n scheduleSyncAfterHydration: input.scheduleSyncAfterHydration ?? true,\n ...(input.scheduleSyncOnHydrationChange === false\n ? { scheduleSyncOnHydrationChange: false }\n : {}),\n }).then(() => true);\n}\n\nexport function refreshRootRemoteHydration(input: {\n includeActiveRootChildLane?: boolean | undefined;\n parentIds?: ReadonlyArray<string | null> | undefined;\n requestHydration: RemoteHydrationRequester;\n state: RemoteHydrationRefreshState;\n}): Promise<boolean> {\n const { requestHydration, state } = input;\n if (!canRefreshRemoteHydration(state)) {\n return Promise.resolve(false);\n }\n\n if (input.includeActiveRootChildLane) {\n // Provisioned-system-container poll: it fires on a ~250ms interval until the\n // org-born slot (Trash) surfaces. List the reconciled server root's child\n // lane directly — resolved from the tree, NOT from runtime.state.containerId,\n // which after a cold-cache login is still the pre-auth device-first local root\n // that Trash does not live under — so Trash is pulled instead of the poll\n // spinning on a dead lane. Crucially do NOT reset the root-lane watermark on\n // this path: an unwatermarked re-list every tick makes hydrateRemoteContainers\n // count every listed container as \"changed\", re-running\n // updateSnapshot()+scheduleSync() on every tick and churning settling nodes'\n // sync badges for the whole poll window — the sidebar \"You\"/Trash flicker. The\n // stored watermark still surfaces Trash (a cold cache lists in full; a later\n // arrival advances the child lane past it).\n const activeRootChildLaneParentId =\n resolveActiveRootChildLaneParentId(state);\n return requestHydration({\n followDiscoveredParentLanes: false,\n parentIds: activeRootChildLaneParentId\n ? [null, activeRootChildLaneParentId]\n : [null],\n }).then(() => true);\n }\n\n // Automatic catch-up and the shared_with_you discovery event only need the\n // top-level lane, but they DO re-list it unwatermarked: a root newly shared with\n // the viewer does not bump the viewer's persisted root-lane watermark, so a\n // watermarked list would hide it forever. hydrateRemoteContainers then crawls a\n // freshly discovered root's child lane within the same pass. (The all-parent\n // traversal stays reserved for explicit user refresh in refreshAllRemoteHydration.)\n //\n // The resync_required handler also passes the affected containers' parent lanes.\n // A deleted nested container's tombstone is only returned by its\n // parent lane (rootDiscoveryVisible=false), never the root lane, so re-listing\n // that parent lane is what applies the tombstone and drops the stale container\n // without falling back to the full crawl. Those parent lanes keep their persisted\n // watermark (a deletion bumps the tombstone's updatedAt, so it still surfaces);\n // only the root lane is unwatermarked, for the newly-shared-root case above.\n const parentLanes = Array.from(\n new Set<string | null>([null, ...(input.parentIds ?? [])]),\n );\n return requestHydration({\n followDiscoveredParentLanes: false,\n parentIds: parentLanes,\n resetRootLaneWatermark: true,\n }).then(() => true);\n}\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createGenerationGuardedHydrationHost, hydrateRemoteContainers, StaleRemoteHydrationError, } from "../../../workflows/container-contents/remoteHydration/index.js";
|
|
2
2
|
import { isDatabaseUnavailableError } from "../../../workflows/container-contents/syncLane.js";
|
|
3
|
+
import { ownsContainerStore } from "../containerState/storeScope.js";
|
|
3
4
|
import { refreshLocalContainerStates, } from "../localRefresh.js";
|
|
4
5
|
import { IDLE_RECOVERY_HYDRATION, transitionRecoveryHydration, } from "./recoveryHydrationMachine.js";
|
|
6
|
+
import { captureTreeResetOwner, claimTreeReset, queueTreeReset, } from "./treeResetMachine.js";
|
|
5
7
|
function isRequestGenerationCurrent(input) {
|
|
6
|
-
return (input.state
|
|
8
|
+
return (ownsContainerStore(input.state) &&
|
|
9
|
+
input.state.lifecycleGeneration === input.lifecycleGeneration &&
|
|
7
10
|
input.state.structuralGeneration === input.structuralGeneration);
|
|
8
11
|
}
|
|
9
12
|
const recoveryHydrationByState = new WeakMap();
|
|
@@ -27,7 +30,8 @@ function queueRecoveryHydrationRequest(input) {
|
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
32
|
function hasRemoteHydrationPrerequisites(state) {
|
|
30
|
-
return (state.runtime.
|
|
33
|
+
return ((state.runtime.liveHydrationStatus?.() ?? "ready") === "ready" &&
|
|
34
|
+
state.runtime.infra.dbStatus === "ready" &&
|
|
31
35
|
state.runtime.auth.isAuthenticated &&
|
|
32
36
|
state.runtime.state.online);
|
|
33
37
|
}
|
|
@@ -41,11 +45,32 @@ function createResetRecoveryInput(input) {
|
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
function resumeRetainedRecoveryHydration(input) {
|
|
48
|
+
if (!ownsHydrationRequest(input))
|
|
49
|
+
return Promise.resolve();
|
|
44
50
|
queueRecoveryHydrationRequest(input);
|
|
45
51
|
return hasRemoteHydrationPrerequisites(input.state)
|
|
46
52
|
? input.resumeRecoveryWork()
|
|
47
53
|
: Promise.resolve();
|
|
48
54
|
}
|
|
55
|
+
function prepareTreeReset(input) {
|
|
56
|
+
const coverReset = claimTreeReset(input.state, !!input.reconnect || !!input.resetAllLaneWatermarks);
|
|
57
|
+
if (!coverReset)
|
|
58
|
+
return input;
|
|
59
|
+
const onCovered = input.recreateOnFullyHydratedAtStart
|
|
60
|
+
? input.recreateOnFullyHydratedAfterReset?.()
|
|
61
|
+
: input.onFullyHydrated;
|
|
62
|
+
return {
|
|
63
|
+
...input,
|
|
64
|
+
followDiscoveredParentLanes: true,
|
|
65
|
+
resetAllLaneWatermarks: true,
|
|
66
|
+
recreateOnFullyHydratedAtStart: false,
|
|
67
|
+
ownsTreeReset: coverReset.isOwned,
|
|
68
|
+
onFullyHydrated: () => {
|
|
69
|
+
coverReset.cover();
|
|
70
|
+
return onCovered?.();
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
49
74
|
function waitForActiveRemoteHydration(input) {
|
|
50
75
|
const { state } = input;
|
|
51
76
|
const activeHydration = state.remoteHydrationPromise;
|
|
@@ -56,6 +81,16 @@ function waitForActiveRemoteHydration(input) {
|
|
|
56
81
|
const requestStructuralGeneration = state.structuralGeneration;
|
|
57
82
|
const needsCurrentGenerationHydration = state.remoteHydrationGeneration !== state.lifecycleGeneration ||
|
|
58
83
|
state.remoteHydrationStructuralGeneration !== state.structuralGeneration;
|
|
84
|
+
// A restoration owns its sweep callback and its sync scheduling policy.
|
|
85
|
+
// Let it list after prior work settles so its durable claim can complete.
|
|
86
|
+
const needsOwnCrawl = !!(input.onFullyHydrated || input.recreateOnFullyHydratedAfterReset) &&
|
|
87
|
+
!!input.resetAllLaneWatermarks &&
|
|
88
|
+
!!input.followDiscoveredParentLanes;
|
|
89
|
+
if (!needsOwnCrawl &&
|
|
90
|
+
input.resetAllLaneWatermarks &&
|
|
91
|
+
input.followDiscoveredParentLanes) {
|
|
92
|
+
input = { ...input, ownsTreeReset: queueTreeReset(state) };
|
|
93
|
+
}
|
|
59
94
|
const requestQueuedHydration = () => {
|
|
60
95
|
if (!isRequestGenerationCurrent({
|
|
61
96
|
lifecycleGeneration: requestLifecycleGeneration,
|
|
@@ -67,7 +102,8 @@ function waitForActiveRemoteHydration(input) {
|
|
|
67
102
|
// Another request's crawl may have taken over this request's queued
|
|
68
103
|
// lanes. Settle with that crawl rather than at once, so the request never
|
|
69
104
|
// resolves before the listing that covers it.
|
|
70
|
-
return
|
|
105
|
+
return needsOwnCrawl ||
|
|
106
|
+
needsCurrentGenerationHydration ||
|
|
71
107
|
state.containerParentIdsNeedingHydration.size > 0
|
|
72
108
|
? requestContainerContentsRemoteHydration(input)
|
|
73
109
|
: (state.remoteHydrationPromise ?? undefined);
|
|
@@ -94,6 +130,15 @@ function waitForActiveInitialization(input) {
|
|
|
94
130
|
});
|
|
95
131
|
}
|
|
96
132
|
function retryRemoteHydrationAfterReset(input) {
|
|
133
|
+
// The reconnect state machine owns its retry across a reset.
|
|
134
|
+
if (input.reconnect) {
|
|
135
|
+
// A superseded crawl still owes the manual refresh whose reset it consumed.
|
|
136
|
+
// Complete that request under the live store's own generation guard.
|
|
137
|
+
if (!input.ownsTreeReset?.() ||
|
|
138
|
+
input.state.runtime.liveHydrationStatus?.() === "retired")
|
|
139
|
+
return Promise.resolve();
|
|
140
|
+
input = { ...input, reconnect: undefined };
|
|
141
|
+
}
|
|
97
142
|
return resumeRetainedRecoveryHydration(createResetRecoveryInput(input));
|
|
98
143
|
}
|
|
99
144
|
function retainResetRecoveryHydration(input) {
|
|
@@ -172,23 +217,45 @@ function consumeQueuedHydrationScope(state, followDiscoveredParentLanesOption) {
|
|
|
172
217
|
: queuedParentIds,
|
|
173
218
|
};
|
|
174
219
|
}
|
|
220
|
+
function ownsHydrationRequest(input) {
|
|
221
|
+
return (ownsContainerStore(input.state) &&
|
|
222
|
+
input.ownsTreeReset?.() !== false &&
|
|
223
|
+
input.reconnect?.isCurrent() !== false);
|
|
224
|
+
}
|
|
225
|
+
function captureHydrationScope(input) {
|
|
226
|
+
const { state } = input;
|
|
227
|
+
const { lifecycleGeneration, structuralGeneration } = state;
|
|
228
|
+
return () => ownsHydrationRequest(input) &&
|
|
229
|
+
isRequestGenerationCurrent({
|
|
230
|
+
state,
|
|
231
|
+
lifecycleGeneration,
|
|
232
|
+
structuralGeneration,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function bindManualTreeReset(input) {
|
|
236
|
+
if (!input.resetAllLaneWatermarks ||
|
|
237
|
+
input.ownsTreeReset ||
|
|
238
|
+
input.onFullyHydrated ||
|
|
239
|
+
input.recreateOnFullyHydratedAfterReset)
|
|
240
|
+
return input;
|
|
241
|
+
return { ...input, ownsTreeReset: captureTreeResetOwner(input.state) };
|
|
242
|
+
}
|
|
175
243
|
export function requestContainerContentsRemoteHydration(input) {
|
|
176
244
|
const { host, scheduleSync, state } = input;
|
|
245
|
+
input = bindManualTreeReset(input);
|
|
246
|
+
if (!ownsHydrationRequest(input))
|
|
247
|
+
return Promise.resolve();
|
|
177
248
|
queueRequestedParentIds(input);
|
|
178
249
|
const readinessBarrier = waitForRemoteHydrationReadiness(input);
|
|
179
250
|
if (readinessBarrier) {
|
|
180
251
|
return readinessBarrier;
|
|
181
252
|
}
|
|
253
|
+
input = prepareTreeReset(input);
|
|
182
254
|
const { followDiscoveredParentLanes, parentIds } = consumeQueuedHydrationScope(state, input.followDiscoveredParentLanes);
|
|
183
255
|
let appliedRemoteContainerChange = false;
|
|
184
256
|
let retainInterruptedHydration = false;
|
|
185
|
-
const lifecycleGeneration = state
|
|
186
|
-
const
|
|
187
|
-
const isCurrent = () => isRequestGenerationCurrent({
|
|
188
|
-
lifecycleGeneration,
|
|
189
|
-
state,
|
|
190
|
-
structuralGeneration,
|
|
191
|
-
});
|
|
257
|
+
const { lifecycleGeneration, structuralGeneration } = state;
|
|
258
|
+
const isCurrent = captureHydrationScope(input);
|
|
192
259
|
const onFullyHydrated = input.recreateOnFullyHydratedAtStart
|
|
193
260
|
? input.recreateOnFullyHydratedAfterReset?.()
|
|
194
261
|
: input.onFullyHydrated;
|
|
@@ -201,6 +268,7 @@ export function requestContainerContentsRemoteHydration(input) {
|
|
|
201
268
|
state.remoteHydrationStructuralGeneration = structuralGeneration;
|
|
202
269
|
const hydrationPromise = refreshLocalContainerStates({
|
|
203
270
|
host: hydrationHost,
|
|
271
|
+
stillCurrent: input.reconnect?.isCurrent,
|
|
204
272
|
state,
|
|
205
273
|
})
|
|
206
274
|
.then(() => {
|
|
@@ -212,6 +280,7 @@ export function requestContainerContentsRemoteHydration(input) {
|
|
|
212
280
|
host: hydrationHost,
|
|
213
281
|
isCurrent,
|
|
214
282
|
onFullyHydrated,
|
|
283
|
+
reconnect: input.reconnect,
|
|
215
284
|
parentIds,
|
|
216
285
|
resetAllLaneWatermarks: input.resetAllLaneWatermarks,
|
|
217
286
|
resetRootLaneWatermark: input.resetRootLaneWatermark,
|