@tearleads/client-sdk 0.1.252 → 0.1.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Tearleads.js +3 -3
- package/Tearleads.js.map +1 -1
- package/client/containerContents/documentDiscovery.js +0 -2
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/client/containerContents/index.d.ts +2 -0
- package/client/containerContents/index.js +4 -9
- package/client/containerContents/index.js.map +1 -1
- package/client/containerContents/storeRuntime.d.ts +17 -0
- package/client/containerContents/storeRuntime.js +31 -0
- package/client/containerContents/storeRuntime.js.map +1 -0
- package/client/deviceFirst/index.d.ts +2 -3
- package/client/deviceFirst/index.js +44 -22
- package/client/deviceFirst/index.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +2 -0
- package/client/runtime/workflowRuntime.js +13 -6
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +7 -10
- package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
- package/data/persistence/container-contents/containerDeletionPersistence.js +5 -1
- package/data/persistence/container-contents/containerDeletionPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerHydrationPersistence.js +1 -1
- package/data/persistence/container-contents/containerHydrationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js +11 -4
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerRemovalMetadata.js +47 -0
- package/data/persistence/container-contents/containerRemovalMetadata.js.map +1 -0
- package/data/persistence/container-contents/containerRemovalPlacements.js +22 -0
- package/data/persistence/container-contents/containerRemovalPlacements.js.map +1 -0
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.d.ts +2 -1
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.js +10 -2
- package/data/persistence/container-contents/containerSyncWatermarkPersistence.js.map +1 -1
- package/data/persistence/documents/documentDiscoveryCandidate.d.ts +1 -0
- package/data/persistence/documents/documentDiscoveryCandidate.js +3 -1
- package/data/persistence/documents/documentDiscoveryCandidate.js.map +1 -1
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.d.ts +1 -1
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js +16 -4
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js.map +1 -1
- package/data/sqlite/migrations/localSchemaMigrations.js +11 -0
- package/data/sqlite/migrations/localSchemaMigrations.js.map +1 -1
- package/data/sqlite/schema/containerSyncWatermarkSchema.js +6 -3
- package/data/sqlite/schema/containerSyncWatermarkSchema.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +17 -0
- package/data/sync/syncCoordinator.js +17 -10
- package/data/sync/syncCoordinator.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +1 -0
- package/internal/api-client/client/apiClientContext.d.ts +1 -0
- package/internal/api-client/client/containerReads.d.ts +1 -0
- package/internal/api-client/requestInternals.js +14 -6
- package/internal/api-client/requestInternals.js.map +1 -1
- package/internal/validators/operation/containerReads.d.ts +29 -2
- package/internal/validators/operation/containerReads.js +2 -1
- package/internal/validators/operation/containerReads.js.map +1 -1
- package/internal/validators/request/containerDocumentLanes.d.ts +7 -0
- package/internal/validators/request/containerDocumentLanes.js +6 -0
- package/internal/validators/request/containerDocumentLanes.js.map +1 -1
- package/internal/validators/response/container.d.ts +8 -0
- package/internal/validators/response/container.js +1 -0
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/containerParentLanes.d.ts +2 -0
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +3 -9
- package/stores/container-contents/containerContentsStore.js +24 -21
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/containerState/storeScope.js +6 -0
- package/stores/container-contents/containerState/storeScope.js.map +1 -0
- package/stores/container-contents/hydration/backgroundHydration.js +2 -1
- package/stores/container-contents/hydration/backgroundHydration.js.map +1 -1
- package/stores/container-contents/hydration/reconnectRefresh.d.ts +10 -0
- package/stores/container-contents/hydration/reconnectRefresh.js +68 -0
- package/stores/container-contents/hydration/reconnectRefresh.js.map +1 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js +49 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js.map +1 -0
- package/stores/container-contents/hydration/remoteHydrationRefresh.js +4 -1
- package/stores/container-contents/hydration/remoteHydrationRefresh.js.map +1 -1
- package/stores/container-contents/hydration/remoteHydrationRequest.js +79 -10
- package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -1
- package/stores/container-contents/hydration/startupHydration.js +2 -9
- package/stores/container-contents/hydration/startupHydration.js.map +1 -1
- package/stores/container-contents/hydration/treeResetMachine.js +61 -0
- package/stores/container-contents/hydration/treeResetMachine.js.map +1 -0
- package/stores/container-contents/localRefresh.js +28 -12
- package/stores/container-contents/localRefresh.js.map +1 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js +4 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -1
- package/stores/container-contents/remoteWrites/writeGeneration.js +5 -2
- package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -1
- package/stores/container-contents/state.d.ts +3 -7
- package/stores/container-contents/state.js +27 -16
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/syncAgent/index.d.ts +7 -2
- package/stores/container-contents/syncAgent/index.js +77 -49
- package/stores/container-contents/syncAgent/index.js.map +1 -1
- package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +5 -2
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js +6 -3
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/stores/local-projection/localProjectionStore.js +24 -15
- package/stores/local-projection/localProjectionStore.js.map +1 -1
- package/stores/local-projection/registry.js +2 -2
- package/stores/local-projection/registry.js.map +1 -1
- package/workflows/container-contents/container-state/create/createChild.js +3 -15
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +4 -8
- package/workflows/container-contents/containerPersistence.js +22 -12
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/containerDocumentListing.js +52 -4
- package/workflows/container-contents/documentDiscovery/containerDocumentListing.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js +4 -2
- package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js +17 -12
- package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryTypes.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/publicationWatermark.js +15 -0
- package/workflows/container-contents/documentDiscovery/publicationWatermark.js.map +1 -0
- package/workflows/container-contents/localState.js +3 -0
- package/workflows/container-contents/localState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.d.ts +12 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js +93 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js.map +1 -0
- package/workflows/container-contents/remoteHydration/index.d.ts +3 -11
- package/workflows/container-contents/remoteHydration/index.js +17 -66
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js +3 -2
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/restorationReceipt.js +25 -0
- package/workflows/container-contents/remoteHydration/lanes/restorationReceipt.js.map +1 -0
- package/workflows/container-contents/remoteHydration/lanes/tombstoneAccess.js +107 -0
- package/workflows/container-contents/remoteHydration/lanes/tombstoneAccess.js.map +1 -0
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js +57 -5
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +129 -84
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +32 -10
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js +67 -24
- package/workflows/container-contents/remoteHydration/tombstoneApplication.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +16 -1
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/remoteReset/remoteResetCursorScope.js +3 -3
- package/workflows/container-contents/remoteReset/remoteResetCursorScope.js.map +1 -1
- package/workflows/container-contents/runtime.d.ts +3 -0
- package/workflows/container-contents/runtime.js.map +1 -1
- package/workflows/container-contents/storedContainerState.js +17 -7
- package/workflows/container-contents/storedContainerState.js.map +1 -1
- package/workflows/container-contents/syncLane.d.ts +1 -0
- package/workflows/container-contents/syncLane.js +9 -1
- package/workflows/container-contents/syncLane.js.map +1 -1
- package/workflows/container-contents/syncPause/discoveryGuard.js +6 -2
- package/workflows/container-contents/syncPause/discoveryGuard.js.map +1 -1
- package/workflows/container-contents/tombstones/documentTombstoneGate.js +6 -3
- package/workflows/container-contents/tombstones/documentTombstoneGate.js.map +1 -1
- package/workflows/shared/runtimeInput.d.ts +2 -0
- package/workflows/shared/runtimeInput.js.map +1 -1
- package/workflows/container-contents/remoteHydration/completeHydration.js +0 -25
- package/workflows/container-contents/remoteHydration/completeHydration.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerIngestion.js","sourceRoot":"","sources":["remoteContainerIngestion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACL,6BAA6B,GAG9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,wCAAwC,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,EA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B,EAAE,CAAC;QAC3B,CAAC;QACD,qBAAqB,EAAE,GAAG,EAAE,CAC1B,iCAAiC,CAAC;YAChC,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CACpB,GAAG,iCAAiC,CAAC,KAAK,CAAC,wCAAwC,YAAY,CAAC,KAAK,CAAC,EAAE,CACzG,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CACpB,GAAG,iCAAiC,CAAC,KAAK,CAAC,kDAAkD,YAAY,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;YACJ,CAAC;YACD,eAAe,EAAE,KAAK,IAAI,EAAE;gBAC1B,MAAM,wCAAwC,CAAC,KAAK,CAAC,CAAC;YACxD,CAAC;YACD,eAAe;SAChB,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n createRemoteContainerIngestor,\n type RemoteContainer,\n type RemoteContainerHydrationHost,\n} from \"../../../workflows/container-contents/remoteHydration\";\nimport { resumeContainerContentsRecoveryHydration } from \"../hydration/remoteHydrationRequest\";\nimport { getContainerContentsStoreLogLabel } from \"../logLabel\";\nimport type { ContainerContentsStoreSyncState } from \"../syncAgent/syncAgentTypes\";\n\ninterface RemoteContainerIngestionController {\n ingest: (remoteContainer: RemoteContainer) => Promise<void>;\n resumeInterruptedWork: () => Promise<void>;\n}\n\nexport async function resumeRemoteContainerRecoveryWork(input: {\n onIngestionError: (error: unknown) => void;\n onHydrationError: (error: unknown) => void;\n resumeHydration: () => Promise<void>;\n resumeIngestion: () => Promise<void>;\n}): Promise<void> {\n try {\n await input.resumeIngestion();\n } catch (error) {\n input.onIngestionError(error);\n return;\n }\n try {\n await input.resumeHydration();\n } catch (error) {\n input.onHydrationError(error);\n }\n}\n\nexport function createRemoteContainerIngestionController(input: {\n host: RemoteContainerHydrationHost;\n scheduleSync: () => void;\n state: ContainerContentsStoreSyncState;\n}): RemoteContainerIngestionController {\n const { host, scheduleSync, state } = input;\n const remoteContainerIngestor = createRemoteContainerIngestor({\n getSerializationBarrier: () => state.initializePromise,\n host,\n state,\n });\n const scheduleAfterIngestion = () => {\n if (\n state.runtime.infra.dbStatus === \"ready\" &&\n state.documentStoresNeedPriming\n ) {\n scheduleSync();\n }\n };\n const resumeIngestion = async () => {\n const hadPendingIngestion = remoteContainerIngestor.hasPending();\n await remoteContainerIngestor.resume();\n if (hadPendingIngestion) {\n scheduleAfterIngestion();\n }\n };\n\n return {\n ingest: async (remoteContainer) => {\n await remoteContainerIngestor(remoteContainer);\n scheduleAfterIngestion();\n },\n resumeInterruptedWork: () =>\n resumeRemoteContainerRecoveryWork({\n onHydrationError: (error) => {\n state.runtime.util.log(\n `${getContainerContentsStoreLogLabel(state)}: failed to resume remote hydration: ${errorMessage(error)}`,\n );\n },\n onIngestionError: (error) => {\n state.runtime.util.log(\n `${getContainerContentsStoreLogLabel(state)}: failed to resume remote container ingestion: ${errorMessage(error)}`,\n );\n },\n resumeHydration: async () => {\n await resumeContainerContentsRecoveryHydration(state);\n },\n resumeIngestion,\n }),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteContainerIngestion.js","sourceRoot":"","sources":["remoteContainerIngestion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACL,6BAA6B,GAG9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,wCAAwC,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAQhE,MAAM,CAAC,KAAK,UAAU,iCAAiC,CAAC,KAKvD;IACC,IAAI,CAAC;QACH,MAAM,KAAK,CAAC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,qBAAqB,EAAE,GAAG,EAAE,CAC1B,iCAAiC,CAAC;YAChC,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CACpB,GAAG,iCAAiC,CAAC,KAAK,CAAC,wCAAwC,YAAY,CAAC,KAAK,CAAC,EAAE,CACzG,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CACpB,GAAG,iCAAiC,CAAC,KAAK,CAAC,kDAAkD,YAAY,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;YACJ,CAAC;YACD,eAAe,EAAE,KAAK,IAAI,EAAE;gBAC1B,MAAM,wCAAwC,CAAC,KAAK,CAAC,CAAC;YACxD,CAAC;YACD,eAAe;SAChB,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n createRemoteContainerIngestor,\n type RemoteContainer,\n type RemoteContainerHydrationHost,\n} from \"../../../workflows/container-contents/remoteHydration\";\nimport { ownsContainerStore } from \"../containerState/storeScope\";\nimport { resumeContainerContentsRecoveryHydration } from \"../hydration/remoteHydrationRequest\";\nimport { getContainerContentsStoreLogLabel } from \"../logLabel\";\nimport type { ContainerContentsStoreSyncState } from \"../syncAgent/syncAgentTypes\";\n\ninterface RemoteContainerIngestionController {\n ingest: (remoteContainer: RemoteContainer) => Promise<void>;\n resumeInterruptedWork: () => Promise<void>;\n}\n\nexport async function resumeRemoteContainerRecoveryWork(input: {\n onIngestionError: (error: unknown) => void;\n onHydrationError: (error: unknown) => void;\n resumeHydration: () => Promise<void>;\n resumeIngestion: () => Promise<void>;\n}): Promise<void> {\n try {\n await input.resumeIngestion();\n } catch (error) {\n input.onIngestionError(error);\n return;\n }\n try {\n await input.resumeHydration();\n } catch (error) {\n input.onHydrationError(error);\n }\n}\n\nexport function createRemoteContainerIngestionController(input: {\n host: RemoteContainerHydrationHost;\n scheduleSync: () => void;\n state: ContainerContentsStoreSyncState;\n}): RemoteContainerIngestionController {\n const { host, scheduleSync, state } = input;\n const remoteContainerIngestor = createRemoteContainerIngestor({\n ownsScope: () => ownsContainerStore(state),\n getSerializationBarrier: () => state.initializePromise,\n host,\n state,\n });\n const scheduleAfterIngestion = () => {\n if (\n ownsContainerStore(state) &&\n state.runtime.infra.dbStatus === \"ready\" &&\n state.documentStoresNeedPriming\n ) {\n scheduleSync();\n }\n };\n const resumeIngestion = async () => {\n const hadPendingIngestion = remoteContainerIngestor.hasPending();\n await remoteContainerIngestor.resume();\n if (hadPendingIngestion) {\n scheduleAfterIngestion();\n }\n };\n\n return {\n ingest: async (remoteContainer) => {\n await remoteContainerIngestor(remoteContainer);\n scheduleAfterIngestion();\n },\n resumeInterruptedWork: () =>\n resumeRemoteContainerRecoveryWork({\n onHydrationError: (error) => {\n state.runtime.util.log(\n `${getContainerContentsStoreLogLabel(state)}: failed to resume remote hydration: ${errorMessage(error)}`,\n );\n },\n onIngestionError: (error) => {\n state.runtime.util.log(\n `${getContainerContentsStoreLogLabel(state)}: failed to resume remote container ingestion: ${errorMessage(error)}`,\n );\n },\n resumeHydration: async () => {\n await resumeContainerContentsRecoveryHydration(state);\n },\n resumeIngestion,\n }),\n };\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ownsContainerStore } from "../containerState/storeScope.js";
|
|
1
2
|
export function didContainerWriteRuntimeChange(previousRuntime, currentRuntime) {
|
|
2
|
-
return (previousRuntime.
|
|
3
|
+
return (previousRuntime.scopeGeneration !== currentRuntime.scopeGeneration ||
|
|
4
|
+
previousRuntime.adoptRootContainer !== currentRuntime.adoptRootContainer ||
|
|
3
5
|
previousRuntime.apiClient !== currentRuntime.apiClient ||
|
|
4
6
|
previousRuntime.auth.defaultOrganizationId !==
|
|
5
7
|
currentRuntime.auth.defaultOrganizationId ||
|
|
@@ -29,7 +31,8 @@ export function captureContainerWriteGeneration(state) {
|
|
|
29
31
|
const persistence = state.persistence;
|
|
30
32
|
const runtime = state.runtime;
|
|
31
33
|
const writeGeneration = state.writeGeneration;
|
|
32
|
-
return () => state
|
|
34
|
+
return () => ownsContainerStore(state) &&
|
|
35
|
+
state.lifecycleGeneration === lifecycleGeneration &&
|
|
33
36
|
state.persistence === persistence &&
|
|
34
37
|
state.writeGeneration === writeGeneration &&
|
|
35
38
|
!didContainerWriteRuntimeChange(runtime, state.runtime);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeGeneration.js","sourceRoot":"","sources":["writeGeneration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"writeGeneration.js","sourceRoot":"","sources":["writeGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAMlE,MAAM,UAAU,8BAA8B,CAC5C,eAA8C,EAC9C,cAA6C;IAE7C,OAAO,CACL,eAAe,CAAC,eAAe,KAAK,cAAc,CAAC,eAAe;QAClE,eAAe,CAAC,kBAAkB,KAAK,cAAc,CAAC,kBAAkB;QACxE,eAAe,CAAC,SAAS,KAAK,cAAc,CAAC,SAAS;QACtD,eAAe,CAAC,IAAI,CAAC,qBAAqB;YACxC,cAAc,CAAC,IAAI,CAAC,qBAAqB;QAC3C,eAAe,CAAC,IAAI,CAAC,eAAe;YAClC,cAAc,CAAC,IAAI,CAAC,eAAe;QACrC,eAAe,CAAC,IAAI,CAAC,cAAc;YACjC,cAAc,CAAC,IAAI,CAAC,cAAc;QACpC,eAAe,CAAC,IAAI,CAAC,MAAM,KAAK,cAAc,CAAC,IAAI,CAAC,MAAM;QAC1D,eAAe,CAAC,MAAM,CAAC,oBAAoB;YACzC,cAAc,CAAC,MAAM,CAAC,oBAAoB;QAC5C,eAAe,CAAC,MAAM,CAAC,kBAAkB;YACvC,cAAc,CAAC,MAAM,CAAC,kBAAkB;QAC1C,eAAe,CAAC,MAAM,CAAC,cAAc;YACnC,cAAc,CAAC,MAAM,CAAC,cAAc;QACtC,eAAe,CAAC,KAAK,CAAC,SAAS,KAAK,cAAc,CAAC,KAAK,CAAC,SAAS;QAClE,eAAe,CAAC,KAAK,CAAC,QAAQ,KAAK,cAAc,CAAC,KAAK,CAAC,QAAQ;QAChE,eAAe,CAAC,KAAK,CAAC,kBAAkB;YACtC,cAAc,CAAC,KAAK,CAAC,kBAAkB;QACzC,eAAe,CAAC,KAAK,CAAC,OAAO,KAAK,cAAc,CAAC,KAAK,CAAC,OAAO;QAC9D,eAAe,CAAC,0BAA0B;YACxC,cAAc,CAAC,0BAA0B;QAC3C,eAAe,CAAC,KAAK,CAAC,WAAW,KAAK,cAAc,CAAC,KAAK,CAAC,WAAW;QACtE,eAAe,CAAC,KAAK,CAAC,WAAW,KAAK,cAAc,CAAC,KAAK,CAAC,WAAW,CACvE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,KAAkC;IAElC,MAAM,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC;IACtD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACtC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,MAAM,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;IAC9C,OAAO,GAAG,EAAE,CACV,kBAAkB,CAAC,KAAK,CAAC;QACzB,KAAK,CAAC,mBAAmB,KAAK,mBAAmB;QACjD,KAAK,CAAC,WAAW,KAAK,WAAW;QACjC,KAAK,CAAC,eAAe,KAAK,eAAe;QACzC,CAAC,8BAA8B,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { ownsContainerStore } from \"../containerState/storeScope\";\nimport type { ContainerContentsStoreRuntime } from \"../syncAgent/syncAgentTypes\";\nimport type { ContainerContentsStoreState } from \"../types\";\n\nexport type ContainerWriteGuard = () => boolean;\n\nexport function didContainerWriteRuntimeChange(\n previousRuntime: ContainerContentsStoreRuntime,\n currentRuntime: ContainerContentsStoreRuntime,\n): boolean {\n return (\n previousRuntime.scopeGeneration !== currentRuntime.scopeGeneration ||\n previousRuntime.adoptRootContainer !== currentRuntime.adoptRootContainer ||\n previousRuntime.apiClient !== currentRuntime.apiClient ||\n previousRuntime.auth.defaultOrganizationId !==\n currentRuntime.auth.defaultOrganizationId ||\n previousRuntime.auth.isAuthenticated !==\n currentRuntime.auth.isAuthenticated ||\n previousRuntime.auth.organizationId !==\n currentRuntime.auth.organizationId ||\n previousRuntime.auth.userId !== currentRuntime.auth.userId ||\n previousRuntime.crypto.encapsulationKeyPair !==\n currentRuntime.crypto.encapsulationKeyPair ||\n previousRuntime.crypto.signingFingerprint !==\n currentRuntime.crypto.signingFingerprint ||\n previousRuntime.crypto.signingKeyPair !==\n currentRuntime.crypto.signingKeyPair ||\n previousRuntime.infra.blobStore !== currentRuntime.infra.blobStore ||\n previousRuntime.infra.dbStatus !== currentRuntime.infra.dbStatus ||\n previousRuntime.infra.documentProjectors !==\n currentRuntime.infra.documentProjectors ||\n previousRuntime.infra.execSql !== currentRuntime.infra.execSql ||\n previousRuntime.resolveTrustedUserIdentity !==\n currentRuntime.resolveTrustedUserIdentity ||\n previousRuntime.state.containerId !== currentRuntime.state.containerId ||\n previousRuntime.state.domainScope !== currentRuntime.state.domainScope\n );\n}\n\nexport function captureContainerWriteGeneration(\n state: ContainerContentsStoreState,\n): ContainerWriteGuard {\n const lifecycleGeneration = state.lifecycleGeneration;\n const persistence = state.persistence;\n const runtime = state.runtime;\n const writeGeneration = state.writeGeneration;\n return () =>\n ownsContainerStore(state) &&\n state.lifecycleGeneration === lifecycleGeneration &&\n state.persistence === persistence &&\n state.writeGeneration === writeGeneration &&\n !didContainerWriteRuntimeChange(runtime, state.runtime);\n}\n"]}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { ContainerContentsPersistence } from "../../workflows/container-contents/containerPersistence.js";
|
|
2
|
-
import type { ContainerContentsStoreRuntime, ContainerContentsStoreSyncAgent } from "./syncAgent/syncAgentTypes.js";
|
|
2
|
+
import type { ContainerContentsStoreRuntime, ContainerContentsStoreSyncAgent, ContainerContentsStoreSyncState } from "./syncAgent/syncAgentTypes.js";
|
|
3
3
|
import type { ContainerContentsStoreState } from "./types.js";
|
|
4
4
|
export declare function createContainerContentsStoreState(initialRuntime: ContainerContentsStoreRuntime, persistence: ContainerContentsPersistence, logLabel?: string | undefined): ContainerContentsStoreState;
|
|
5
5
|
export declare function updateContainerContentsSnapshot(state: ContainerContentsStoreState): void;
|
|
6
6
|
export declare function subscribeToContainerContentsStore(state: ContainerContentsStoreState, listener: () => void): () => boolean;
|
|
7
7
|
export declare function updateContainerContentsStoreRuntime(state: ContainerContentsStoreState, nextRuntime: ContainerContentsStoreRuntime, syncAgent: ContainerContentsStoreSyncAgent): void;
|
|
8
|
-
export declare function
|
|
9
|
-
|
|
10
|
-
snapshot: {
|
|
11
|
-
ready: boolean;
|
|
12
|
-
};
|
|
13
|
-
}, refresh: () => Promise<boolean>): void;
|
|
8
|
+
export declare function retireContainerStore(state: ContainerContentsStoreSyncState): void;
|
|
9
|
+
export declare function consumePendingContainerContentsReconnectRefresh(state: ContainerContentsStoreSyncState, refresh: ContainerContentsStoreSyncAgent["refresh"]): void;
|
|
14
10
|
export declare function updateContainerContentsStorePersistence(state: ContainerContentsStoreState, nextPersistence: ContainerContentsPersistence, syncAgent: ContainerContentsStoreSyncAgent): void;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createContainerContentsProjectionUserKeyResolver, didContainerContentsProjectionKeyRuntimeChange, } from "../../workflows/container-contents/projectionKeys.js";
|
|
2
2
|
import { didRegainSyncPrerequisites } from "../../workflows/container-contents/syncLane.js";
|
|
3
3
|
import { ContainerStateMap } from "./containerState/containerStateMap.js";
|
|
4
|
+
import { observeContainerBackgroundHydration } from "./hydration/backgroundHydration.js";
|
|
5
|
+
import { ReconnectRefresh } from "./hydration/reconnectRefresh.js";
|
|
4
6
|
import { didContainerWriteRuntimeChange } from "./remoteWrites/writeGeneration.js";
|
|
5
7
|
import { getSnapshotNodes } from "./utils.js";
|
|
6
8
|
function areSyncStatesEqual(left, right) {
|
|
@@ -44,8 +46,12 @@ function didStructuralRuntimeChange(previousRuntime, nextRuntime) {
|
|
|
44
46
|
previousRuntime.util.isRemoteSyncBlocked !==
|
|
45
47
|
nextRuntime.util.isRemoteSyncBlocked);
|
|
46
48
|
}
|
|
49
|
+
// Request correlation is scoped to the store instance. A reopened tree can
|
|
50
|
+
// issue an identical listing while the retired tree is waiting on the API.
|
|
51
|
+
let storeSequence = 0;
|
|
47
52
|
export function createContainerContentsStoreState(initialRuntime, persistence, logLabel) {
|
|
48
53
|
return {
|
|
54
|
+
parentLaneRequestPrefix: `s${++storeSequence}`,
|
|
49
55
|
containerListingFailures: 0,
|
|
50
56
|
containersById: new ContainerStateMap(),
|
|
51
57
|
containerParentIdsNeedingHydration: new Set(),
|
|
@@ -72,7 +78,7 @@ export function createContainerContentsStoreState(initialRuntime, persistence, l
|
|
|
72
78
|
remoteHydrationStructuralGeneration: null,
|
|
73
79
|
// A store opened after the socket's interest was acknowledged missed that
|
|
74
80
|
// acknowledgement's re-list, which is how hints lost earlier are recovered.
|
|
75
|
-
|
|
81
|
+
reconnectRefresh: new ReconnectRefresh((initialRuntime.state.serverEventsConnectionGeneration ?? 0) > 0),
|
|
76
82
|
resolveProjectionUserKey: createContainerContentsProjectionUserKeyResolver(initialRuntime),
|
|
77
83
|
rootLaneHydrated: false,
|
|
78
84
|
runtime: initialRuntime,
|
|
@@ -150,6 +156,7 @@ export function updateContainerContentsStoreRuntime(state, nextRuntime, syncAgen
|
|
|
150
156
|
const serverEventsConnectionChanged = previousRuntime.state.serverEventsConnectionGeneration !==
|
|
151
157
|
nextRuntime.state.serverEventsConnectionGeneration;
|
|
152
158
|
if (runtimeReplaced) {
|
|
159
|
+
state.reconnectRefresh.reset("runtimeChanged");
|
|
153
160
|
state.structuralGeneration += 1;
|
|
154
161
|
state.localContainersNeedRefresh = true;
|
|
155
162
|
}
|
|
@@ -161,7 +168,7 @@ export function updateContainerContentsStoreRuntime(state, nextRuntime, syncAgen
|
|
|
161
168
|
}
|
|
162
169
|
state.runtime = nextRuntime;
|
|
163
170
|
if (serverEventsConnectionChanged) {
|
|
164
|
-
state.
|
|
171
|
+
state.reconnectRefresh.reset("acknowledged");
|
|
165
172
|
}
|
|
166
173
|
if (nextRuntime.infra.dbStatus !== "ready") {
|
|
167
174
|
if (hasContainerContentsLoadState(state)) {
|
|
@@ -178,12 +185,8 @@ export function updateContainerContentsStoreRuntime(state, nextRuntime, syncAgen
|
|
|
178
185
|
syncAgent.handleRemoteEvents();
|
|
179
186
|
return;
|
|
180
187
|
}
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
// tree stays valid. Reconcile it in place instead of resetting — resetting
|
|
184
|
-
// here is what blanked Explorer and forced a re-read on first open after
|
|
185
|
-
// register. Identity/storage changes are handled by scope rotation and the
|
|
186
|
-
// dbStatus-loss branch above.
|
|
188
|
+
// The signing fingerprint owns the locally loaded tree. When this scope
|
|
189
|
+
// gains authentication, keep the tree available while reconciling it.
|
|
187
190
|
if (state.snapshot.ready &&
|
|
188
191
|
(contextChanged || didRegainSyncPrerequisites(previousRuntime, nextRuntime))) {
|
|
189
192
|
state.localContainersNeedRefresh = true;
|
|
@@ -209,21 +212,29 @@ export function updateContainerContentsStoreRuntime(state, nextRuntime, syncAgen
|
|
|
209
212
|
syncAgent.scheduleRemoteHydration();
|
|
210
213
|
}
|
|
211
214
|
}
|
|
215
|
+
export function retireContainerStore(state) {
|
|
216
|
+
state.lifecycleGeneration++;
|
|
217
|
+
state.reconnectRefresh.reset("disposed");
|
|
218
|
+
}
|
|
212
219
|
export function consumePendingContainerContentsReconnectRefresh(state, refresh) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
state.
|
|
220
|
+
state.reconnectRefresh.runWhenReady(() => state.snapshot.ready &&
|
|
221
|
+
state.initialized &&
|
|
222
|
+
state.runtime.infra.dbStatus === "ready" &&
|
|
223
|
+
state.runtime.auth.isAuthenticated &&
|
|
224
|
+
state.runtime.state.online &&
|
|
225
|
+
(state.runtime.liveHydrationStatus?.() ?? "ready") === "ready" &&
|
|
226
|
+
state.runtime.isAcknowledgementCurrent?.() !== false &&
|
|
227
|
+
!state.syncLane?.isDisposed?.(), (options) => {
|
|
228
|
+
const hydration = refresh(options);
|
|
229
|
+
observeContainerBackgroundHydration(state, hydration);
|
|
230
|
+
return hydration;
|
|
221
231
|
});
|
|
222
232
|
}
|
|
223
233
|
export function updateContainerContentsStorePersistence(state, nextPersistence, syncAgent) {
|
|
224
234
|
if (state.persistence === nextPersistence) {
|
|
225
235
|
return;
|
|
226
236
|
}
|
|
237
|
+
state.reconnectRefresh.reset("runtimeChanged");
|
|
227
238
|
state.persistence = nextPersistence;
|
|
228
239
|
state.structuralGeneration += 1;
|
|
229
240
|
state.writeGeneration += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gDAAgD,EAChD,8CAA8C,GAC/C,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAUhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,SAAS,kBAAkB,CACzB,IAAgC,EAChC,KAAiC;IAEjC,OAAO,CACL,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;QAClC,IAAI,CAAC,sBAAsB,KAAK,KAAK,CAAC,sBAAsB;QAC5D,IAAI,CAAC,sBAAsB,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,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,6BAA6B;QAAE,OAAO;IAC1E,KAAK,CAAC,6BAA6B,GAAG,KAAK,CAAC;IAC5C,KAAK,OAAO,EAAE,CAAC,IAAI,CACjB,CAAC,SAAS,EAAE,EAAE;QACZ,IAAI,CAAC,SAAS;YAAE,KAAK,CAAC,6BAA6B,GAAG,IAAI,CAAC;IAC7D,CAAC,EACD,GAAG,EAAE;QACH,KAAK,CAAC,6BAA6B,GAAG,IAAI,CAAC;IAC7C,CAAC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,KAAkC,EAClC,eAA6C,EAC7C,SAA0C;IAE1C,IAAI,KAAK,CAAC,WAAW,KAAK,eAAe,EAAE,CAAC;QAC1C,OAAO;IACT,CAAC;IACD,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC;IACpC,KAAK,CAAC,oBAAoB,IAAI,CAAC,CAAC;IAChC,KAAK,CAAC,eAAe,IAAI,CAAC,CAAC;IAC3B,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACnC,SAAS,CAAC,iBAAiB,EAAE,CAAC;AAChC,CAAC","sourcesContent":["import type { ContainerContentsPersistence } from \"../../workflows/container-contents/containerPersistence\";\nimport {\n createContainerContentsProjectionUserKeyResolver,\n didContainerContentsProjectionKeyRuntimeChange,\n} from \"../../workflows/container-contents/projectionKeys\";\nimport { didRegainSyncPrerequisites } from \"../../workflows/container-contents/syncLane\";\nimport { ContainerStateMap } from \"./containerState/containerStateMap\";\nimport { didContainerWriteRuntimeChange } from \"./remoteWrites/writeGeneration\";\nimport type {\n ContainerContentsStoreRuntime,\n ContainerContentsStoreSyncAgent,\n} from \"./syncAgent/syncAgentTypes\";\nimport type {\n ContainerContentsSnapshot,\n ContainerContentsStoreState,\n ContainerNode,\n} from \"./types\";\nimport { getSnapshotNodes } from \"./utils\";\n\nfunction areSyncStatesEqual(\n left: ContainerNode[\"syncState\"],\n right: ContainerNode[\"syncState\"],\n): boolean {\n return (\n left.lastError === right.lastError &&\n left.pendingAttachmentBytes === right.pendingAttachmentBytes &&\n left.pendingAttachmentCount === right.pendingAttachmentCount &&\n left.pendingUpdateCount === right.pendingUpdateCount &&\n left.status === right.status\n );\n}\n\nfunction areSnapshotNodesEqual(\n left: ReadonlyArray<ContainerNode>,\n right: ReadonlyArray<ContainerNode>,\n): boolean {\n if (left.length !== right.length) {\n return false;\n }\n\n return left.every((leftNode, index) => {\n const rightNode = right[index];\n return (\n rightNode !== undefined &&\n leftNode.createdAt === rightNode.createdAt &&\n leftNode.effectiveAccessLevel === rightNode.effectiveAccessLevel &&\n leftNode.id === rightNode.id &&\n leftNode.icon === rightNode.icon &&\n leftNode.kind === rightNode.kind &&\n leftNode.metadataDocumentId === rightNode.metadataDocumentId &&\n leftNode.metadataReady === rightNode.metadataReady &&\n leftNode.name === rightNode.name &&\n leftNode.organizationId === rightNode.organizationId &&\n leftNode.parentId === rightNode.parentId &&\n leftNode.primaryDocumentId === rightNode.primaryDocumentId &&\n areSyncStatesEqual(leftNode.syncState, rightNode.syncState) &&\n leftNode.systemSlot === rightNode.systemSlot &&\n leftNode.updatedAt === rightNode.updatedAt\n );\n });\n}\n\nfunction didStructuralRuntimeChange(\n previousRuntime: ContainerContentsStoreRuntime,\n nextRuntime: ContainerContentsStoreRuntime,\n): boolean {\n // Structural sync also depends on connectivity and event delivery. Local\n // writes use only the identity and storage checks shared below.\n return (\n didContainerWriteRuntimeChange(previousRuntime, nextRuntime) ||\n previousRuntime.state.online !== nextRuntime.state.online ||\n previousRuntime.state.peerScope !== nextRuntime.state.peerScope ||\n previousRuntime.state.serverEventsConnectionGeneration !==\n nextRuntime.state.serverEventsConnectionGeneration ||\n previousRuntime.util.isRemoteSyncBlocked !==\n nextRuntime.util.isRemoteSyncBlocked\n );\n}\n\nexport function createContainerContentsStoreState(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence,\n logLabel?: string | undefined,\n): ContainerContentsStoreState {\n return {\n containerListingFailures: 0,\n containersById: new ContainerStateMap(),\n containerParentIdsNeedingHydration: new Set(),\n documentStoresNeedPriming: true,\n initializeGeneration: null,\n initializePromise: null,\n initialized: false,\n localContainerRefreshPromise: null,\n localContainerRefreshGeneration: null,\n localContainerRefreshStructuralGeneration: null,\n localContainersNeedRefresh: false,\n lifecycleGeneration: 0,\n lastEventCount: 0,\n listeners: new Set(),\n locallyAcceptedMetadataUpdateIds: new Set(),\n logLabel,\n metadataDocumentIdsNeedingSync: new Set(),\n metadataSyncSignalSeqById: new Map(),\n owedMetadataReadsRestored: false,\n persistence,\n plannedMetadataDocumentIds: new Set(),\n remoteHydrationPromise: null,\n remoteHydrationGeneration: null,\n remoteHydrationStructuralGeneration: null,\n // A store opened after the socket's interest was acknowledged missed that\n // acknowledgement's re-list, which is how hints lost earlier are recovered.\n remoteReconnectRefreshPending:\n (initialRuntime.state.serverEventsConnectionGeneration ?? 0) > 0,\n resolveProjectionUserKey:\n createContainerContentsProjectionUserKeyResolver(initialRuntime),\n rootLaneHydrated: false,\n runtime: initialRuntime,\n snapshot: {\n nodes: [],\n ready: false,\n },\n syncLane: null,\n structuralGeneration: 0,\n writeGeneration: 0,\n writeChain: Promise.resolve<ContainerNode | null>(null),\n };\n}\n\nfunction emitContainerContentsStore(state: ContainerContentsStoreState) {\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction setContainerContentsSnapshot(\n state: ContainerContentsStoreState,\n next: ContainerContentsSnapshot,\n) {\n if (\n next.ready === state.snapshot.ready &&\n areSnapshotNodesEqual(next.nodes, state.snapshot.nodes)\n ) {\n return;\n }\n\n state.snapshot = next;\n emitContainerContentsStore(state);\n}\n\nexport function updateContainerContentsSnapshot(\n state: ContainerContentsStoreState,\n) {\n setContainerContentsSnapshot(state, {\n nodes: getSnapshotNodes(state.containersById),\n ready: true,\n });\n}\n\nfunction resetContainerContentsStore(state: ContainerContentsStoreState) {\n state.lifecycleGeneration += 1;\n state.containersById = new ContainerStateMap();\n state.containerParentIdsNeedingHydration = new Set();\n state.documentStoresNeedPriming = true;\n state.initialized = false;\n state.localContainersNeedRefresh = false;\n // Runtime events are snapshots, not a destructive queue. A replacement\n // executor or persistence adapter has not observed any of them, even when\n // their effects were already applied to the previous database. Replay the\n // snapshot after replacement initialization rebuilds metadata identities.\n state.lastEventCount = 0;\n // Accepted-echo suppression state must not survive a reset: after a\n // database loss the tree rehydrates from remote, and a retained id would\n // suppress the next matching remote update signal. Mirrors\n // clearDocumentStoreState in the document store lane.\n state.locallyAcceptedMetadataUpdateIds = new Set();\n state.metadataDocumentIdsNeedingSync = new Set();\n state.metadataSyncSignalSeqById = new Map();\n state.owedMetadataReadsRestored = false;\n state.plannedMetadataDocumentIds = new Set();\n state.rootLaneHydrated = false;\n state.writeChain = Promise.resolve<ContainerNode | null>(null);\n setContainerContentsSnapshot(state, {\n nodes: [],\n ready: false,\n });\n}\n\nexport function subscribeToContainerContentsStore(\n state: ContainerContentsStoreState,\n listener: () => void,\n) {\n state.listeners.add(listener);\n return () => state.listeners.delete(listener);\n}\n\nfunction hasContainerContentsLoadState(\n state: ContainerContentsStoreState,\n): boolean {\n return Boolean(\n state.snapshot.ready || state.initialized || state.initializePromise,\n );\n}\n\nexport function updateContainerContentsStoreRuntime(\n state: ContainerContentsStoreState,\n nextRuntime: ContainerContentsStoreRuntime,\n syncAgent: ContainerContentsStoreSyncAgent,\n) {\n const previousRuntime = state.runtime;\n const runtimeReplaced = didStructuralRuntimeChange(\n previousRuntime,\n nextRuntime,\n );\n if (didContainerWriteRuntimeChange(previousRuntime, nextRuntime)) {\n state.writeGeneration += 1;\n }\n const executorReplaced =\n previousRuntime.infra.execSql !== nextRuntime.infra.execSql;\n const serverEventsConnectionChanged =\n previousRuntime.state.serverEventsConnectionGeneration !==\n nextRuntime.state.serverEventsConnectionGeneration;\n if (runtimeReplaced) {\n state.structuralGeneration += 1;\n state.localContainersNeedRefresh = true;\n }\n const contextChanged =\n previousRuntime.auth.organizationId !== nextRuntime.auth.organizationId ||\n previousRuntime.state.containerId !== nextRuntime.state.containerId;\n if (\n didContainerContentsProjectionKeyRuntimeChange(previousRuntime, nextRuntime)\n ) {\n state.resolveProjectionUserKey =\n createContainerContentsProjectionUserKeyResolver(nextRuntime);\n }\n state.runtime = nextRuntime;\n if (serverEventsConnectionChanged) {\n state.remoteReconnectRefreshPending = true;\n }\n\n if (nextRuntime.infra.dbStatus !== \"ready\") {\n if (hasContainerContentsLoadState(state)) {\n resetContainerContentsStore(state);\n }\n return;\n }\n\n if (executorReplaced) {\n // The in-memory tree and lane markers belong to the previous executor.\n // Rebuild them from the replacement database before any remote sync can\n // observe or persist the old database's state.\n resetContainerContentsStore(state);\n syncAgent.ensureInitialized();\n syncAgent.handleRemoteEvents();\n return;\n }\n\n // Gaining authentication within a domain scope does not change identity\n // (the scope is keyed on the signing fingerprint), so the locally-loaded\n // tree stays valid. Reconcile it in place instead of resetting — resetting\n // here is what blanked Explorer and forced a re-read on first open after\n // register. Identity/storage changes are handled by scope rotation and the\n // dbStatus-loss branch above.\n if (\n state.snapshot.ready &&\n (contextChanged || didRegainSyncPrerequisites(previousRuntime, nextRuntime))\n ) {\n state.localContainersNeedRefresh = true;\n state.documentStoresNeedPriming = true;\n void syncAgent.refreshLocalContainers();\n // The refresh alone does not run the sync lane; schedule it so newly\n // eligible documents (e.g. this organization's orphans) prime now.\n syncAgent.scheduleSync();\n }\n\n syncAgent.ensureInitialized();\n\n syncAgent.handleRemoteEvents();\n\n if (runtimeReplaced) {\n void syncAgent.refreshLocalContainers();\n syncAgent.scheduleSync();\n }\n\n consumePendingContainerContentsReconnectRefresh(state, syncAgent.refresh);\n\n if (\n state.snapshot.ready &&\n didRegainSyncPrerequisites(previousRuntime, nextRuntime)\n ) {\n // A pass blocked by missing prerequisites consumes its lane request before\n // returning early. Re-arm it directly when they return even if hydration\n // finds no remote delta; this also primes unopened document stores.\n syncAgent.scheduleSync();\n syncAgent.scheduleRemoteHydration();\n }\n}\n\nexport function consumePendingContainerContentsReconnectRefresh(\n state: {\n remoteReconnectRefreshPending: boolean;\n snapshot: { ready: boolean };\n },\n refresh: () => Promise<boolean>,\n): void {\n if (!state.snapshot.ready || !state.remoteReconnectRefreshPending) return;\n state.remoteReconnectRefreshPending = false;\n void refresh().then(\n (refreshed) => {\n if (!refreshed) state.remoteReconnectRefreshPending = true;\n },\n () => {\n state.remoteReconnectRefreshPending = true;\n },\n );\n}\n\nexport function updateContainerContentsStorePersistence(\n state: ContainerContentsStoreState,\n nextPersistence: ContainerContentsPersistence,\n syncAgent: ContainerContentsStoreSyncAgent,\n): void {\n if (state.persistence === nextPersistence) {\n return;\n }\n state.persistence = nextPersistence;\n state.structuralGeneration += 1;\n state.writeGeneration += 1;\n // Persistence replacement changes the authoritative local data source even\n // when the SQLite executor itself is stable. Clear storage-backed state and\n // let initialization load the replacement before scheduling remote work.\n resetContainerContentsStore(state);\n syncAgent.ensureInitialized();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gDAAgD,EAChD,8CAA8C,GAC/C,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAWhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,SAAS,kBAAkB,CACzB,IAAgC,EAChC,KAAiC;IAEjC,OAAO,CACL,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;QAClC,IAAI,C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KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC/C,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC;IACpC,KAAK,CAAC,oBAAoB,IAAI,CAAC,CAAC;IAChC,KAAK,CAAC,eAAe,IAAI,CAAC,CAAC;IAC3B,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACnC,SAAS,CAAC,iBAAiB,EAAE,CAAC;AAChC,CAAC","sourcesContent":["import type { ContainerContentsPersistence } from \"../../workflows/container-contents/containerPersistence\";\nimport {\n createContainerContentsProjectionUserKeyResolver,\n didContainerContentsProjectionKeyRuntimeChange,\n} from \"../../workflows/container-contents/projectionKeys\";\nimport { didRegainSyncPrerequisites } from \"../../workflows/container-contents/syncLane\";\nimport { ContainerStateMap } from \"./containerState/containerStateMap\";\nimport { observeContainerBackgroundHydration } from \"./hydration/backgroundHydration\";\nimport { ReconnectRefresh } from \"./hydration/reconnectRefresh\";\nimport { didContainerWriteRuntimeChange } from \"./remoteWrites/writeGeneration\";\nimport type {\n ContainerContentsStoreRuntime,\n ContainerContentsStoreSyncAgent,\n ContainerContentsStoreSyncState,\n} from \"./syncAgent/syncAgentTypes\";\nimport type {\n ContainerContentsSnapshot,\n ContainerContentsStoreState,\n ContainerNode,\n} from \"./types\";\nimport { getSnapshotNodes } from \"./utils\";\n\nfunction areSyncStatesEqual(\n left: ContainerNode[\"syncState\"],\n right: ContainerNode[\"syncState\"],\n): boolean {\n return (\n left.lastError === right.lastError &&\n left.pendingAttachmentBytes === right.pendingAttachmentBytes &&\n left.pendingAttachmentCount === right.pendingAttachmentCount &&\n left.pendingUpdateCount === right.pendingUpdateCount &&\n left.status === right.status\n );\n}\n\nfunction areSnapshotNodesEqual(\n left: ReadonlyArray<ContainerNode>,\n right: ReadonlyArray<ContainerNode>,\n): boolean {\n if (left.length !== right.length) {\n return false;\n }\n\n return left.every((leftNode, index) => {\n const rightNode = right[index];\n return (\n rightNode !== undefined &&\n leftNode.createdAt === rightNode.createdAt &&\n leftNode.effectiveAccessLevel === rightNode.effectiveAccessLevel &&\n leftNode.id === rightNode.id &&\n leftNode.icon === rightNode.icon &&\n leftNode.kind === rightNode.kind &&\n leftNode.metadataDocumentId === rightNode.metadataDocumentId &&\n leftNode.metadataReady === rightNode.metadataReady &&\n leftNode.name === rightNode.name &&\n leftNode.organizationId === rightNode.organizationId &&\n leftNode.parentId === rightNode.parentId &&\n leftNode.primaryDocumentId === rightNode.primaryDocumentId &&\n areSyncStatesEqual(leftNode.syncState, rightNode.syncState) &&\n leftNode.systemSlot === rightNode.systemSlot &&\n leftNode.updatedAt === rightNode.updatedAt\n );\n });\n}\n\nfunction didStructuralRuntimeChange(\n previousRuntime: ContainerContentsStoreRuntime,\n nextRuntime: ContainerContentsStoreRuntime,\n): boolean {\n // Structural sync also depends on connectivity and event delivery. Local\n // writes use only the identity and storage checks shared below.\n return (\n didContainerWriteRuntimeChange(previousRuntime, nextRuntime) ||\n previousRuntime.state.online !== nextRuntime.state.online ||\n previousRuntime.state.peerScope !== nextRuntime.state.peerScope ||\n previousRuntime.state.serverEventsConnectionGeneration !==\n nextRuntime.state.serverEventsConnectionGeneration ||\n previousRuntime.util.isRemoteSyncBlocked !==\n nextRuntime.util.isRemoteSyncBlocked\n );\n}\n\n// Request correlation is scoped to the store instance. A reopened tree can\n// issue an identical listing while the retired tree is waiting on the API.\nlet storeSequence = 0;\n\nexport function createContainerContentsStoreState(\n initialRuntime: ContainerContentsStoreRuntime,\n persistence: ContainerContentsPersistence,\n logLabel?: string | undefined,\n): ContainerContentsStoreState {\n return {\n parentLaneRequestPrefix: `s${++storeSequence}`,\n containerListingFailures: 0,\n containersById: new ContainerStateMap(),\n containerParentIdsNeedingHydration: new Set(),\n documentStoresNeedPriming: true,\n initializeGeneration: null,\n initializePromise: null,\n initialized: false,\n localContainerRefreshPromise: null,\n localContainerRefreshGeneration: null,\n localContainerRefreshStructuralGeneration: null,\n localContainersNeedRefresh: false,\n lifecycleGeneration: 0,\n lastEventCount: 0,\n listeners: new Set(),\n locallyAcceptedMetadataUpdateIds: new Set(),\n logLabel,\n metadataDocumentIdsNeedingSync: new Set(),\n metadataSyncSignalSeqById: new Map(),\n owedMetadataReadsRestored: false,\n persistence,\n plannedMetadataDocumentIds: new Set(),\n remoteHydrationPromise: null,\n remoteHydrationGeneration: null,\n remoteHydrationStructuralGeneration: null,\n // A store opened after the socket's interest was acknowledged missed that\n // acknowledgement's re-list, which is how hints lost earlier are recovered.\n reconnectRefresh: new ReconnectRefresh(\n (initialRuntime.state.serverEventsConnectionGeneration ?? 0) > 0,\n ),\n resolveProjectionUserKey:\n createContainerContentsProjectionUserKeyResolver(initialRuntime),\n rootLaneHydrated: false,\n runtime: initialRuntime,\n snapshot: {\n nodes: [],\n ready: false,\n },\n syncLane: null,\n structuralGeneration: 0,\n writeGeneration: 0,\n writeChain: Promise.resolve<ContainerNode | null>(null),\n };\n}\n\nfunction emitContainerContentsStore(state: ContainerContentsStoreState) {\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction setContainerContentsSnapshot(\n state: ContainerContentsStoreState,\n next: ContainerContentsSnapshot,\n) {\n if (\n next.ready === state.snapshot.ready &&\n areSnapshotNodesEqual(next.nodes, state.snapshot.nodes)\n ) {\n return;\n }\n\n state.snapshot = next;\n emitContainerContentsStore(state);\n}\n\nexport function updateContainerContentsSnapshot(\n state: ContainerContentsStoreState,\n) {\n setContainerContentsSnapshot(state, {\n nodes: getSnapshotNodes(state.containersById),\n ready: true,\n });\n}\n\nfunction resetContainerContentsStore(state: ContainerContentsStoreState) {\n state.lifecycleGeneration += 1;\n state.containersById = new ContainerStateMap();\n state.containerParentIdsNeedingHydration = new Set();\n state.documentStoresNeedPriming = true;\n state.initialized = false;\n state.localContainersNeedRefresh = false;\n // Runtime events are snapshots, not a destructive queue. A replacement\n // executor or persistence adapter has not observed any of them, even when\n // their effects were already applied to the previous database. Replay the\n // snapshot after replacement initialization rebuilds metadata identities.\n state.lastEventCount = 0;\n // Accepted-echo suppression state must not survive a reset: after a\n // database loss the tree rehydrates from remote, and a retained id would\n // suppress the next matching remote update signal. Mirrors\n // clearDocumentStoreState in the document store lane.\n state.locallyAcceptedMetadataUpdateIds = new Set();\n state.metadataDocumentIdsNeedingSync = new Set();\n state.metadataSyncSignalSeqById = new Map();\n state.owedMetadataReadsRestored = false;\n state.plannedMetadataDocumentIds = new Set();\n state.rootLaneHydrated = false;\n state.writeChain = Promise.resolve<ContainerNode | null>(null);\n setContainerContentsSnapshot(state, {\n nodes: [],\n ready: false,\n });\n}\n\nexport function subscribeToContainerContentsStore(\n state: ContainerContentsStoreState,\n listener: () => void,\n) {\n state.listeners.add(listener);\n return () => state.listeners.delete(listener);\n}\n\nfunction hasContainerContentsLoadState(\n state: ContainerContentsStoreState,\n): boolean {\n return Boolean(\n state.snapshot.ready || state.initialized || state.initializePromise,\n );\n}\n\nexport function updateContainerContentsStoreRuntime(\n state: ContainerContentsStoreState,\n nextRuntime: ContainerContentsStoreRuntime,\n syncAgent: ContainerContentsStoreSyncAgent,\n) {\n const previousRuntime = state.runtime;\n const runtimeReplaced = didStructuralRuntimeChange(\n previousRuntime,\n nextRuntime,\n );\n if (didContainerWriteRuntimeChange(previousRuntime, nextRuntime)) {\n state.writeGeneration += 1;\n }\n const executorReplaced =\n previousRuntime.infra.execSql !== nextRuntime.infra.execSql;\n const serverEventsConnectionChanged =\n previousRuntime.state.serverEventsConnectionGeneration !==\n nextRuntime.state.serverEventsConnectionGeneration;\n if (runtimeReplaced) {\n state.reconnectRefresh.reset(\"runtimeChanged\");\n state.structuralGeneration += 1;\n state.localContainersNeedRefresh = true;\n }\n const contextChanged =\n previousRuntime.auth.organizationId !== nextRuntime.auth.organizationId ||\n previousRuntime.state.containerId !== nextRuntime.state.containerId;\n if (\n didContainerContentsProjectionKeyRuntimeChange(previousRuntime, nextRuntime)\n ) {\n state.resolveProjectionUserKey =\n createContainerContentsProjectionUserKeyResolver(nextRuntime);\n }\n state.runtime = nextRuntime;\n if (serverEventsConnectionChanged) {\n state.reconnectRefresh.reset(\"acknowledged\");\n }\n\n if (nextRuntime.infra.dbStatus !== \"ready\") {\n if (hasContainerContentsLoadState(state)) {\n resetContainerContentsStore(state);\n }\n return;\n }\n\n if (executorReplaced) {\n // The in-memory tree and lane markers belong to the previous executor.\n // Rebuild them from the replacement database before any remote sync can\n // observe or persist the old database's state.\n resetContainerContentsStore(state);\n syncAgent.ensureInitialized();\n syncAgent.handleRemoteEvents();\n return;\n }\n\n // The signing fingerprint owns the locally loaded tree. When this scope\n // gains authentication, keep the tree available while reconciling it.\n if (\n state.snapshot.ready &&\n (contextChanged || didRegainSyncPrerequisites(previousRuntime, nextRuntime))\n ) {\n state.localContainersNeedRefresh = true;\n state.documentStoresNeedPriming = true;\n void syncAgent.refreshLocalContainers();\n // The refresh alone does not run the sync lane; schedule it so newly\n // eligible documents (e.g. this organization's orphans) prime now.\n syncAgent.scheduleSync();\n }\n\n syncAgent.ensureInitialized();\n\n syncAgent.handleRemoteEvents();\n\n if (runtimeReplaced) {\n void syncAgent.refreshLocalContainers();\n syncAgent.scheduleSync();\n }\n\n consumePendingContainerContentsReconnectRefresh(state, syncAgent.refresh);\n\n if (\n state.snapshot.ready &&\n didRegainSyncPrerequisites(previousRuntime, nextRuntime)\n ) {\n // A pass blocked by missing prerequisites consumes its lane request before\n // returning early. Re-arm it directly when they return even if hydration\n // finds no remote delta; this also primes unopened document stores.\n syncAgent.scheduleSync();\n syncAgent.scheduleRemoteHydration();\n }\n}\n\nexport function retireContainerStore(\n state: ContainerContentsStoreSyncState,\n): void {\n state.lifecycleGeneration++;\n state.reconnectRefresh.reset(\"disposed\");\n}\n\nexport function consumePendingContainerContentsReconnectRefresh(\n state: ContainerContentsStoreSyncState,\n refresh: ContainerContentsStoreSyncAgent[\"refresh\"],\n): void {\n state.reconnectRefresh.runWhenReady(\n () =>\n state.snapshot.ready &&\n state.initialized &&\n state.runtime.infra.dbStatus === \"ready\" &&\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online &&\n (state.runtime.liveHydrationStatus?.() ?? \"ready\") === \"ready\" &&\n state.runtime.isAcknowledgementCurrent?.() !== false &&\n !state.syncLane?.isDisposed?.(),\n (options) => {\n const hydration = refresh(options);\n observeContainerBackgroundHydration(state, hydration);\n return hydration;\n },\n );\n}\n\nexport function updateContainerContentsStorePersistence(\n state: ContainerContentsStoreState,\n nextPersistence: ContainerContentsPersistence,\n syncAgent: ContainerContentsStoreSyncAgent,\n): void {\n if (state.persistence === nextPersistence) {\n return;\n }\n state.reconnectRefresh.reset(\"runtimeChanged\");\n state.persistence = nextPersistence;\n state.structuralGeneration += 1;\n state.writeGeneration += 1;\n // Persistence replacement changes the authoritative local data source even\n // when the SQLite executor itself is stable. Clear storage-backed state and\n // let initialization load the replacement before scheduling remote work.\n resetContainerContentsStore(state);\n syncAgent.ensureInitialized();\n}\n"]}
|
|
@@ -2,7 +2,12 @@ import type { RemoteContainerHydrationHost } from "../../../workflows/container-
|
|
|
2
2
|
import type { ContainerContentsStoreSyncAgent, ContainerContentsStoreSyncState } from "./syncAgentTypes.js";
|
|
3
3
|
export type { ContainerState } from "../../../workflows/container-contents/remoteHydration/index.js";
|
|
4
4
|
export type { ContainerContentsStoreRuntime, ContainerContentsStoreSyncAgent, ContainerContentsStoreSyncState, RefreshRootLaneOptions, } from "./syncAgentTypes.js";
|
|
5
|
-
|
|
5
|
+
interface AgentInput {
|
|
6
6
|
host: RemoteContainerHydrationHost;
|
|
7
7
|
state: ContainerContentsStoreSyncState;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export declare function prepareContainerContentsStoreSyncAgent(input: AgentInput): {
|
|
10
|
+
agent: ContainerContentsStoreSyncAgent;
|
|
11
|
+
registerLane: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function createContainerContentsStoreSyncAgent(input: AgentInput): ContainerContentsStoreSyncAgent;
|
|
@@ -2,20 +2,32 @@ import { loadLocalContainerStates } from "../../../workflows/container-contents/
|
|
|
2
2
|
import { isDatabaseUnavailableError, registerContainerContentsSyncLane, } from "../../../workflows/container-contents/syncLane.js";
|
|
3
3
|
import { loadOrganizationSyncPausesBeforeSync } from "../../../workflows/sync/coordination.js";
|
|
4
4
|
import { createRestoredAccessReconciler } from "../accessRestorationSweep.js";
|
|
5
|
+
import { ownsContainerStore } from "../containerState/storeScope.js";
|
|
5
6
|
import { primeStoreDocumentSubtree } from "../documentWork/documentRecovery.js";
|
|
6
7
|
import { observeContainerBackgroundHydration } from "../hydration/backgroundHydration.js";
|
|
7
8
|
import { refreshAllRemoteHydration, refreshRootRemoteHydration, } from "../hydration/remoteHydrationRefresh.js";
|
|
8
9
|
import { requestContainerContentsRemoteHydration } from "../hydration/remoteHydrationRequest.js";
|
|
9
|
-
import { hasStartupContainerSyncWork,
|
|
10
|
+
import { hasStartupContainerSyncWork, inspectStartupHydration, } from "../hydration/startupHydration.js";
|
|
10
11
|
import { refreshLocalContainerStates } from "../localRefresh.js";
|
|
11
12
|
import { getContainerContentsStoreLogLabel } from "../logLabel.js";
|
|
12
13
|
import { createRemoteContainerIngestionController } from "../remoteEvents/remoteContainerIngestion.js";
|
|
13
14
|
import { handleContainerContentsRemoteEvents } from "../remoteEvents/remoteEventSync.js";
|
|
14
|
-
import { consumePendingContainerContentsReconnectRefresh } from "../state.js";
|
|
15
|
+
import { consumePendingContainerContentsReconnectRefresh, retireContainerStore, } from "../state.js";
|
|
15
16
|
import { runContainerContentsStoreSyncIteration } from "./syncLaneIteration.js";
|
|
16
17
|
function requestContainerContentsStoreSync(state) {
|
|
17
18
|
state.syncLane?.requestSync();
|
|
18
19
|
}
|
|
20
|
+
function publishInitialContainers(state, startup) {
|
|
21
|
+
for (const [id, row] of startup.containersById) {
|
|
22
|
+
state.containersById.set(id, row);
|
|
23
|
+
}
|
|
24
|
+
state.initialized = true;
|
|
25
|
+
state.rootLaneHydrated = startup.rootLaneHydrated;
|
|
26
|
+
for (const id of startup.containerParentIdsNeedingHydration) {
|
|
27
|
+
state.containerParentIdsNeedingHydration.add(id);
|
|
28
|
+
}
|
|
29
|
+
return startup.containerParentIdsNeedingHydration.size > 0;
|
|
30
|
+
}
|
|
19
31
|
async function initializeContainerContentsStore(input) {
|
|
20
32
|
const { handleRemoteEvents, host, isCurrent, resumeRecoveryWork, scheduleSync, state, } = input;
|
|
21
33
|
const persistence = state.persistence;
|
|
@@ -29,35 +41,41 @@ async function initializeContainerContentsStore(input) {
|
|
|
29
41
|
log: loadRuntime.util.log,
|
|
30
42
|
});
|
|
31
43
|
const localContainerStates = await loadLocalContainerStates({
|
|
44
|
+
isCurrent,
|
|
32
45
|
persistence,
|
|
33
46
|
runtime: loadRuntime,
|
|
34
47
|
});
|
|
35
48
|
if (!isCurrent()) {
|
|
36
49
|
return;
|
|
37
50
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
// Keep the local tree and marker reads private until this initialization
|
|
52
|
+
// can publish them together. Another organization can take over between reads.
|
|
53
|
+
const startup = {
|
|
54
|
+
runtime: state.runtime,
|
|
55
|
+
containersById: new Map(localContainerStates.map((row) => [row.container.id, row])),
|
|
56
|
+
containerParentIdsNeedingHydration: new Set(),
|
|
57
|
+
rootLaneHydrated: state.rootLaneHydrated,
|
|
58
|
+
};
|
|
59
|
+
const shouldScheduleStaleRootRecovery = await inspectStartupHydration({
|
|
43
60
|
isCurrent,
|
|
44
|
-
|
|
45
|
-
host,
|
|
46
|
-
resumeRecoveryWork,
|
|
47
|
-
scheduleSync,
|
|
48
|
-
state,
|
|
49
|
-
}),
|
|
50
|
-
state,
|
|
61
|
+
state: startup,
|
|
51
62
|
});
|
|
52
|
-
if (!isCurrent())
|
|
63
|
+
if (!isCurrent())
|
|
53
64
|
return;
|
|
54
|
-
}
|
|
55
65
|
const runtime = state.runtime;
|
|
56
66
|
const hasPendingRestorationSweep = typeof runtime.auth.userId === "string" &&
|
|
57
67
|
(await persistence.listDormantMetadataSweepRequests(loadRuntime.infra.execSql, runtime.auth.userId)).length > 0;
|
|
58
68
|
if (!isCurrent()) {
|
|
59
69
|
return;
|
|
60
70
|
}
|
|
71
|
+
if (publishInitialContainers(state, startup)) {
|
|
72
|
+
observeContainerBackgroundHydration(state, requestContainerContentsRemoteHydration({
|
|
73
|
+
host,
|
|
74
|
+
resumeRecoveryWork,
|
|
75
|
+
scheduleSync,
|
|
76
|
+
state,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
61
79
|
host.updateSnapshot();
|
|
62
80
|
handleRemoteEvents();
|
|
63
81
|
runtime.util.log(`${getContainerContentsStoreLogLabel(state)}: loaded ${state.containersById.size} container(s)`);
|
|
@@ -105,16 +123,24 @@ function ensureContainerContentsStoreInitialized(input) {
|
|
|
105
123
|
if (state.initialized || state.runtime.infra.dbStatus !== "ready") {
|
|
106
124
|
return;
|
|
107
125
|
}
|
|
108
|
-
if (state.initializePromise) {
|
|
126
|
+
if (!ownsContainerStore(state) || state.initializePromise) {
|
|
109
127
|
return;
|
|
110
128
|
}
|
|
111
129
|
if (waitForStaleLocalRefreshBeforeInitialization(input)) {
|
|
112
130
|
return;
|
|
113
131
|
}
|
|
114
132
|
const lifecycleGeneration = state.lifecycleGeneration;
|
|
133
|
+
// A first login adopts device-local rows on this executor. A later owner must reload them.
|
|
134
|
+
const startedAnonymous = !state.runtime.auth.isAuthenticated;
|
|
135
|
+
const writeGeneration = state.writeGeneration;
|
|
115
136
|
const persistence = state.persistence;
|
|
116
137
|
const execSql = state.runtime.infra.execSql;
|
|
117
|
-
const isCurrent = () => state
|
|
138
|
+
const isCurrent = () => ownsContainerStore(state) &&
|
|
139
|
+
(state.writeGeneration === writeGeneration ||
|
|
140
|
+
(startedAnonymous &&
|
|
141
|
+
state.runtime.auth.isAuthenticated &&
|
|
142
|
+
state.writeGeneration === writeGeneration + 1)) &&
|
|
143
|
+
state.lifecycleGeneration === lifecycleGeneration &&
|
|
118
144
|
state.persistence === persistence &&
|
|
119
145
|
state.runtime.infra.execSql === execSql;
|
|
120
146
|
state.initializeGeneration = lifecycleGeneration;
|
|
@@ -142,6 +168,8 @@ function ensureContainerContentsStoreInitialized(input) {
|
|
|
142
168
|
consumePendingContainerContentsReconnectRefresh(state, input.refreshAfterReconnect);
|
|
143
169
|
}
|
|
144
170
|
else if (state.runtime.infra.dbStatus === "ready") {
|
|
171
|
+
if (!state.snapshot.ready)
|
|
172
|
+
state.initialized = false;
|
|
145
173
|
ensureContainerContentsStoreInitialized(input);
|
|
146
174
|
}
|
|
147
175
|
});
|
|
@@ -163,7 +191,7 @@ function createHydrationRequester(input) {
|
|
|
163
191
|
resetAllLaneWatermarks: options.resetAllLaneWatermarks,
|
|
164
192
|
});
|
|
165
193
|
}
|
|
166
|
-
export function
|
|
194
|
+
export function prepareContainerContentsStoreSyncAgent(input) {
|
|
167
195
|
const { host, state } = input;
|
|
168
196
|
const scheduleSync = () => requestContainerContentsStoreSync(state);
|
|
169
197
|
const remoteContainerIngestion = createRemoteContainerIngestionController({
|
|
@@ -172,23 +200,14 @@ export function createContainerContentsStoreSyncAgent(input) {
|
|
|
172
200
|
state,
|
|
173
201
|
});
|
|
174
202
|
const resumeRecoveryWork = remoteContainerIngestion.resumeInterruptedWork;
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
scheduleSync,
|
|
179
|
-
state,
|
|
180
|
-
});
|
|
181
|
-
const requestRefreshHydration = (options) => requestContainerContentsRemoteHydration({
|
|
182
|
-
...options,
|
|
183
|
-
host,
|
|
184
|
-
resumeRecoveryWork,
|
|
185
|
-
scheduleSync,
|
|
186
|
-
state,
|
|
187
|
-
});
|
|
203
|
+
const hydrationInput = { host, resumeRecoveryWork, scheduleSync, state };
|
|
204
|
+
const requestHydration = createHydrationRequester(hydrationInput);
|
|
205
|
+
const requestRefreshHydration = (options) => requestContainerContentsRemoteHydration({ ...hydrationInput, ...options });
|
|
188
206
|
const scheduleHydration = (options) => observeContainerBackgroundHydration(state, requestHydration(options));
|
|
189
207
|
const refresh = (options) => refreshAllRemoteHydration({
|
|
190
208
|
// Explicit user refresh must rediscover children hidden by unsigned hints.
|
|
191
209
|
resetAllLaneWatermarks: options?.resetAllLaneWatermarks,
|
|
210
|
+
reconnect: options?.reconnect,
|
|
192
211
|
requestHydration: requestRefreshHydration,
|
|
193
212
|
state,
|
|
194
213
|
});
|
|
@@ -201,23 +220,26 @@ export function createContainerContentsStoreSyncAgent(input) {
|
|
|
201
220
|
requestHydration: requestRefreshHydration,
|
|
202
221
|
state,
|
|
203
222
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
policyOperation
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
const registerLane = () => {
|
|
224
|
+
state.syncLane = registerContainerContentsSyncLane({
|
|
225
|
+
onDispose: () => retireContainerStore(state),
|
|
226
|
+
domainScope: state.runtime.state.domainScope,
|
|
227
|
+
logError: (message, error) => logSyncLaneFailure(state, message, error),
|
|
228
|
+
run: (policyOperation) => runContainerContentsStoreSyncIteration({
|
|
229
|
+
host,
|
|
230
|
+
policyOperation,
|
|
231
|
+
reconcileRestoredAccess,
|
|
232
|
+
requestRemoteReconciliation: (parentContainerId) => {
|
|
233
|
+
scheduleHydration({
|
|
234
|
+
followDiscoveredParentLanes: false,
|
|
235
|
+
parentIds: [parentContainerId],
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
state,
|
|
239
|
+
}),
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
const agent = {
|
|
221
243
|
ensureInitialized: () => {
|
|
222
244
|
ensureContainerContentsStoreInitialized({
|
|
223
245
|
handleRemoteEvents,
|
|
@@ -244,5 +266,11 @@ export function createContainerContentsStoreSyncAgent(input) {
|
|
|
244
266
|
scheduleRemoteHydration: scheduleHydration,
|
|
245
267
|
scheduleSync,
|
|
246
268
|
};
|
|
269
|
+
return { agent, registerLane };
|
|
270
|
+
}
|
|
271
|
+
export function createContainerContentsStoreSyncAgent(input) {
|
|
272
|
+
const prepared = prepareContainerContentsStoreSyncAgent(input);
|
|
273
|
+
prepared.registerLane();
|
|
274
|
+
return prepared.agent;
|
|
247
275
|
}
|
|
248
276
|
//# sourceMappingURL=index.js.map
|