@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,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sqlContainerContentsPersistence as defaultContainerContentsPersistence, } from "../../data/persistence/container-contents/containerContentsPersistence.js";
|
|
2
2
|
import { containerContentsSyncLane, containerParentSyncLane, } from "../../data/persistence/container-contents/containerSyncWatermarkPersistence.js";
|
|
3
|
-
export { sqlContainerContentsPersistence as defaultContainerContentsPersistence } from "../../data/persistence/container-contents/containerContentsPersistence.js";
|
|
4
3
|
export { ContainerSyncWatermarkRepository, } from "../../data/persistence/container-contents/containerSyncWatermarkPersistence.js";
|
|
5
|
-
export
|
|
6
|
-
const pendingUpdateFields = createPendingUpdateFields(params.update, params.sourceVersionVector);
|
|
7
|
-
if (!pendingUpdateFields) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
return persistence.enqueuePendingUpdate(execSql, {
|
|
11
|
-
containerId: params.containerId,
|
|
12
|
-
...pendingUpdateFields,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
4
|
+
export { defaultContainerContentsPersistence };
|
|
15
5
|
export function createContainerParentSyncLane(parentId) {
|
|
16
6
|
return containerParentSyncLane(parentId);
|
|
17
7
|
}
|
|
18
8
|
export function createContainerContentsSyncLane(containerId) {
|
|
19
9
|
return containerContentsSyncLane(containerId);
|
|
20
10
|
}
|
|
11
|
+
export function resolveAtomicContainerSave(persistence) {
|
|
12
|
+
const saveContainerWithPendingUpdate = persistence.saveContainerWithPendingUpdate;
|
|
13
|
+
if (!saveContainerWithPendingUpdate)
|
|
14
|
+
return null;
|
|
15
|
+
const inheritedSqlAtomicSave = saveContainerWithPendingUpdate ===
|
|
16
|
+
defaultContainerContentsPersistence.saveContainerWithPendingUpdate &&
|
|
17
|
+
(persistence.saveContainer !==
|
|
18
|
+
defaultContainerContentsPersistence.saveContainer ||
|
|
19
|
+
persistence.enqueuePendingUpdate !==
|
|
20
|
+
defaultContainerContentsPersistence.enqueuePendingUpdate);
|
|
21
|
+
return inheritedSqlAtomicSave
|
|
22
|
+
? null
|
|
23
|
+
: saveContainerWithPendingUpdate.bind(persistence);
|
|
24
|
+
}
|
|
25
|
+
export function requireAtomicContainerSave(persistence) {
|
|
26
|
+
const save = resolveAtomicContainerSave(persistence);
|
|
27
|
+
if (!save)
|
|
28
|
+
throw new Error("Container persistence must implement saveContainerWithPendingUpdate to repair pending metadata");
|
|
29
|
+
return save;
|
|
30
|
+
}
|
|
21
31
|
//# sourceMappingURL=containerPersistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"containerPersistence.js","sourceRoot":"","sources":["containerPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"containerPersistence.js","sourceRoot":"","sources":["containerPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,+BAA+B,IAAI,mCAAmC,GACvE,MAAM,wEAAwE,CAAC;AAChF,OAAO,EAEL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,6EAA6E,CAAC;AAcrF,OAAO,EAEL,gCAAgC,GACjC,MAAM,6EAA6E,CAAC;AAErF,OAAO,EAAE,mCAAmC,EAAE,CAAC;AAE/C,MAAM,UAAU,6BAA6B,CAC3C,QAAuB;IAEvB,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,WAAmB;IAEnB,OAAO,yBAAyB,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,WAAyC;IAIzC,MAAM,8BAA8B,GAClC,WAAW,CAAC,8BAA8B,CAAC;IAC7C,IAAI,CAAC,8BAA8B;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,sBAAsB,GAC1B,8BAA8B;QAC5B,mCAAmC,CAAC,8BAA8B;QACpE,CAAC,WAAW,CAAC,aAAa;YACxB,mCAAmC,CAAC,aAAa;YACjD,WAAW,CAAC,oBAAoB;gBAC9B,mCAAmC,CAAC,oBAAoB,CAAC,CAAC;IAChE,OAAO,sBAAsB;QAC3B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,WAAyC;IAEzC,MAAM,IAAI,GAAG,0BAA0B,CAAC,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI;QACP,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {\n type ContainerContentsPersistence,\n sqlContainerContentsPersistence as defaultContainerContentsPersistence,\n} from \"../../data/persistence/container-contents/containerContentsPersistence\";\nimport {\n type ContainerSyncWatermarkLane,\n containerContentsSyncLane,\n containerParentSyncLane,\n} from \"../../data/persistence/container-contents/containerSyncWatermarkPersistence\";\n\nexport type {\n ContainerContentsPersistence,\n ContainerCreateIntentRecord,\n ContainerHydrationTombstone,\n ContainerMetadataRecord,\n ContainerMetadataRecord as ContainerDocumentRecord,\n ContainerMoveIntentRecord,\n LocalRootDescendantReparentInput,\n StoredContainerState,\n} from \"../../data/persistence/container-contents/containerContentsPersistence\";\nexport type { ContainerMetadataRevalidation } from \"../../data/persistence/container-contents/containerMetadataRevalidations\";\nexport type { ContainerRecord } from \"../../data/persistence/container-contents/containerPersistence\";\nexport {\n type ContainerSyncWatermarkLane,\n ContainerSyncWatermarkRepository,\n} from \"../../data/persistence/container-contents/containerSyncWatermarkPersistence\";\nexport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nexport { defaultContainerContentsPersistence };\n\nexport function createContainerParentSyncLane(\n parentId: string | null,\n): ContainerSyncWatermarkLane {\n return containerParentSyncLane(parentId);\n}\n\nexport function createContainerContentsSyncLane(\n containerId: string,\n): ContainerSyncWatermarkLane {\n return containerContentsSyncLane(containerId);\n}\n\nexport function resolveAtomicContainerSave(\n persistence: ContainerContentsPersistence,\n): NonNullable<\n ContainerContentsPersistence[\"saveContainerWithPendingUpdate\"]\n> | null {\n const saveContainerWithPendingUpdate =\n persistence.saveContainerWithPendingUpdate;\n if (!saveContainerWithPendingUpdate) return null;\n const inheritedSqlAtomicSave =\n saveContainerWithPendingUpdate ===\n defaultContainerContentsPersistence.saveContainerWithPendingUpdate &&\n (persistence.saveContainer !==\n defaultContainerContentsPersistence.saveContainer ||\n persistence.enqueuePendingUpdate !==\n defaultContainerContentsPersistence.enqueuePendingUpdate);\n return inheritedSqlAtomicSave\n ? null\n : saveContainerWithPendingUpdate.bind(persistence);\n}\n\nexport function requireAtomicContainerSave(\n persistence: ContainerContentsPersistence,\n) {\n const save = resolveAtomicContainerSave(persistence);\n if (!save)\n throw new Error(\n \"Container persistence must implement saveContainerWithPendingUpdate to repair pending metadata\",\n );\n return save;\n}\n"]}
|
|
@@ -6,8 +6,11 @@ export async function loadLocalContainerStates(input) {
|
|
|
6
6
|
const storedContainers = await persistence.loadContainers(execSql);
|
|
7
7
|
const containerStates = [];
|
|
8
8
|
for (const storedContainer of storedContainers) {
|
|
9
|
+
if (input.isCurrent?.() === false)
|
|
10
|
+
break;
|
|
9
11
|
containerStates.push(await hydrateStoredContainerState({
|
|
10
12
|
execSql,
|
|
13
|
+
isCurrent: input.isCurrent,
|
|
11
14
|
persistence,
|
|
12
15
|
storedContainer,
|
|
13
16
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localState.js","sourceRoot":"","sources":["localState.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAIrE,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,
|
|
1
|
+
{"version":3,"file":"localState.js","sourceRoot":"","sources":["localState.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAIrE,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,KAI9C;IACC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IACtC,MAAM,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAEnE,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE,CAAC;QAC/C,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK;YAAE,MAAM;QACzC,eAAe,CAAC,IAAI,CAClB,MAAM,2BAA2B,CAAC;YAChC,OAAO;YACP,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,WAAW;YACX,eAAe;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import type { ContainerContentsPersistence } from \"./containerPersistence\";\nimport type { ContainerState } from \"./remoteHydration\";\nimport type { ContainerContentsWorkflowSqlRuntime } from \"./runtime\";\nimport { hydrateStoredContainerState } from \"./storedContainerState\";\n\ntype LocalContainerStateRuntime = ContainerContentsWorkflowSqlRuntime;\n\nexport async function loadLocalContainerStates(input: {\n isCurrent?: (() => boolean) | undefined;\n persistence: ContainerContentsPersistence;\n runtime: LocalContainerStateRuntime;\n}): Promise<ReadonlyArray<ContainerState>> {\n const { persistence, runtime } = input;\n const execSql = runtime.infra.execSql;\n await persistence.ensureSchema(execSql);\n const storedContainers = await persistence.loadContainers(execSql);\n\n const containerStates: ContainerState[] = [];\n for (const storedContainer of storedContainers) {\n if (input.isCurrent?.() === false) break;\n containerStates.push(\n await hydrateStoredContainerState({\n execSql,\n isCurrent: input.isCurrent,\n persistence,\n storedContainer,\n }),\n );\n }\n\n return containerStates;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReconnectCrawl, RemoteContainerHydrationHost, RemoteContainerHydrationState } from "./types.js";
|
|
2
|
+
export declare function hydrateRemoteContainers(input: {
|
|
3
|
+
followDiscoveredParentLanes?: boolean | undefined;
|
|
4
|
+
host: RemoteContainerHydrationHost;
|
|
5
|
+
isCurrent?: (() => boolean) | undefined;
|
|
6
|
+
reconnect?: ReconnectCrawl | undefined;
|
|
7
|
+
onFullyHydrated?: (() => Promise<void> | void) | undefined;
|
|
8
|
+
parentIds?: ReadonlyArray<string | null> | undefined;
|
|
9
|
+
resetAllLaneWatermarks?: boolean | undefined;
|
|
10
|
+
resetRootLaneWatermark?: boolean | undefined;
|
|
11
|
+
state: RemoteContainerHydrationState;
|
|
12
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createContainerChildIndex } from "./lanes/childIndex.js";
|
|
2
|
+
import { createContainerParentHydrationQueue } from "./lanes/parentLaneQueue.js";
|
|
3
|
+
import { canHydrateRemoteContainers, hydrateContainerParentLanes, } from "./remoteContainers/remoteContainerPageHydration.js";
|
|
4
|
+
import { describeRemoteContainerHydration } from "./remoteHydrationLog.js";
|
|
5
|
+
async function finishRemoteHydration(input) {
|
|
6
|
+
if (input.isCurrent?.() === false) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (input.changedCount > 0) {
|
|
10
|
+
input.host.updateSnapshot();
|
|
11
|
+
let insertedCount = 0;
|
|
12
|
+
for (const containerId of input.seenContainerIds) {
|
|
13
|
+
if (!input.containerIdsBeforeHydration.has(containerId)) {
|
|
14
|
+
insertedCount++;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
input.state.runtime.util.log(describeRemoteContainerHydration({
|
|
18
|
+
changedCount: input.changedCount,
|
|
19
|
+
insertedCount,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
if (input.complete &&
|
|
23
|
+
input.isCurrent?.() !== false &&
|
|
24
|
+
input.onFullyHydrated) {
|
|
25
|
+
await input.onFullyHydrated();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Distinct correlation IDs prevent an acknowledged crawl joining an older in-flight HTTP listing.
|
|
29
|
+
let reconnectSequence = 0;
|
|
30
|
+
export async function hydrateRemoteContainers(input) {
|
|
31
|
+
const { host, state } = input;
|
|
32
|
+
if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const seenContainerIds = new Set();
|
|
36
|
+
const containerIdsBeforeHydration = new Set(state.containersById.keys());
|
|
37
|
+
const childIdsByParentId = createContainerChildIndex(state.containersById);
|
|
38
|
+
const { lanes, queueParentLane } = createContainerParentHydrationQueue({
|
|
39
|
+
containerIds: state.containersById.keys(),
|
|
40
|
+
parentIds: input.parentIds,
|
|
41
|
+
resetAllLaneWatermarks: input.resetAllLaneWatermarks,
|
|
42
|
+
resetRootLaneWatermark: input.resetRootLaneWatermark,
|
|
43
|
+
});
|
|
44
|
+
// Follow child lanes during an explicit recursive crawl or for containers first
|
|
45
|
+
// discovered in this pass. The latter lets a newly authorized root populate its
|
|
46
|
+
// descendants immediately, while routine ticks keep known subtrees cache-first.
|
|
47
|
+
const queueDiscoveredParentLane = (containerId) => {
|
|
48
|
+
if (input.followDiscoveredParentLanes ||
|
|
49
|
+
(containerId !== null && !containerIdsBeforeHydration.has(containerId))) {
|
|
50
|
+
queueParentLane(containerId);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
let manualError;
|
|
54
|
+
const result = await hydrateContainerParentLanes({
|
|
55
|
+
reconnect: input.reconnect && {
|
|
56
|
+
laneIdPrefix: `r${++reconnectSequence}`,
|
|
57
|
+
recordManualError: (error) => {
|
|
58
|
+
manualError ??= error;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
childIdsByParentId,
|
|
62
|
+
host,
|
|
63
|
+
isCurrent: input.isCurrent,
|
|
64
|
+
lanes,
|
|
65
|
+
queueParentLane: queueDiscoveredParentLane,
|
|
66
|
+
seenContainerIds,
|
|
67
|
+
state,
|
|
68
|
+
});
|
|
69
|
+
const { changedCount } = result;
|
|
70
|
+
await finishRemoteHydration({
|
|
71
|
+
changedCount,
|
|
72
|
+
complete: result.outcome === "complete" &&
|
|
73
|
+
canHydrateRemoteContainers(state) &&
|
|
74
|
+
input.isCurrent?.() !== false,
|
|
75
|
+
containerIdsBeforeHydration,
|
|
76
|
+
host,
|
|
77
|
+
isCurrent: input.isCurrent,
|
|
78
|
+
onFullyHydrated: input.onFullyHydrated,
|
|
79
|
+
seenContainerIds,
|
|
80
|
+
state,
|
|
81
|
+
});
|
|
82
|
+
if (input.reconnect?.isCurrent() && canHydrateRemoteContainers(state)) {
|
|
83
|
+
const manualRejection = input.resetAllLaneWatermarks
|
|
84
|
+
? manualError
|
|
85
|
+
: undefined;
|
|
86
|
+
input.reconnect.record(result.outcome, manualRejection);
|
|
87
|
+
// A manual refresh sharing this crawl observes the error it would receive on its own.
|
|
88
|
+
if (manualRejection)
|
|
89
|
+
throw manualRejection;
|
|
90
|
+
}
|
|
91
|
+
return changedCount;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=hydrateRemoteContainers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrateRemoteContainers.js","sourceRoot":"","sources":["hydrateRemoteContainers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAQxE,KAAK,UAAU,qBAAqB,CAAC,KASpC;IACC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;QAClC,OAAO;IACT,CAAC;IACD,IAAI,KAAK,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,IAAI,aAAa,GAAG,CAAC,CAAC;QACtB,KAAK,MAAM,WAAW,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;YACjD,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACxD,aAAa,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAC1B,gCAAgC,CAAC;YAC/B,YAAY,EAAE,KAAK,CAAC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ndex\";\nimport { createContainerParentHydrationQueue } from \"./lanes/parentLaneQueue\";\nimport {\n canHydrateRemoteContainers,\n hydrateContainerParentLanes,\n} from \"./remoteContainers/remoteContainerPageHydration\";\nimport { describeRemoteContainerHydration } from \"./remoteHydrationLog\";\nimport type {\n QueueContainerParentLane,\n ReconnectCrawl,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"./types\";\n\nasync function finishRemoteHydration(input: {\n changedCount: number;\n complete: boolean;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n seenContainerIds: ReadonlySet<string>;\n containerIdsBeforeHydration: ReadonlySet<string>;\n state: RemoteContainerHydrationState;\n}): Promise<void> {\n if (input.isCurrent?.() === false) {\n return;\n }\n if (input.changedCount > 0) {\n input.host.updateSnapshot();\n let insertedCount = 0;\n for (const containerId of input.seenContainerIds) {\n if (!input.containerIdsBeforeHydration.has(containerId)) {\n insertedCount++;\n }\n }\n input.state.runtime.util.log(\n describeRemoteContainerHydration({\n changedCount: input.changedCount,\n insertedCount,\n }),\n );\n }\n if (\n input.complete &&\n input.isCurrent?.() !== false &&\n input.onFullyHydrated\n ) {\n await input.onFullyHydrated();\n }\n}\n\n// Distinct correlation IDs prevent an acknowledged crawl joining an older in-flight HTTP listing.\nlet reconnectSequence = 0;\n\nexport async function hydrateRemoteContainers(input: {\n followDiscoveredParentLanes?: boolean | undefined;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => 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 state: RemoteContainerHydrationState;\n}): Promise<number> {\n const { host, state } = input;\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return 0;\n }\n\n const seenContainerIds = new Set<string>();\n const containerIdsBeforeHydration = new Set(state.containersById.keys());\n const childIdsByParentId = createContainerChildIndex(state.containersById);\n const { lanes, queueParentLane } = createContainerParentHydrationQueue({\n containerIds: state.containersById.keys(),\n parentIds: input.parentIds,\n resetAllLaneWatermarks: input.resetAllLaneWatermarks,\n resetRootLaneWatermark: input.resetRootLaneWatermark,\n });\n // Follow child lanes during an explicit recursive crawl or for containers first\n // discovered in this pass. The latter lets a newly authorized root populate its\n // descendants immediately, while routine ticks keep known subtrees cache-first.\n const queueDiscoveredParentLane: QueueContainerParentLane = (containerId) => {\n if (\n input.followDiscoveredParentLanes ||\n (containerId !== null && !containerIdsBeforeHydration.has(containerId))\n ) {\n queueParentLane(containerId);\n }\n };\n let manualError: Error | undefined;\n const result = await hydrateContainerParentLanes({\n reconnect: input.reconnect && {\n laneIdPrefix: `r${++reconnectSequence}`,\n recordManualError: (error) => {\n manualError ??= error;\n },\n },\n childIdsByParentId,\n host,\n isCurrent: input.isCurrent,\n lanes,\n queueParentLane: queueDiscoveredParentLane,\n seenContainerIds,\n state,\n });\n const { changedCount } = result;\n await finishRemoteHydration({\n changedCount,\n complete:\n result.outcome === \"complete\" &&\n canHydrateRemoteContainers(state) &&\n input.isCurrent?.() !== false,\n containerIdsBeforeHydration,\n host,\n isCurrent: input.isCurrent,\n onFullyHydrated: input.onFullyHydrated,\n seenContainerIds,\n state,\n });\n if (input.reconnect?.isCurrent() && canHydrateRemoteContainers(state)) {\n const manualRejection = input.resetAllLaneWatermarks\n ? manualError\n : undefined;\n input.reconnect.record(result.outcome, manualRejection);\n // A manual refresh sharing this crawl observes the error it would receive on its own.\n if (manualRejection) throw manualRejection;\n }\n return changedCount;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RemoteContainer, RemoteContainerHydrationHost, RemoteContainerHydrationState } from "./types.js";
|
|
2
|
-
export
|
|
2
|
+
export { hydrateRemoteContainers } from "./hydrateRemoteContainers.js";
|
|
3
|
+
export type { ContainerState, HydrationOutcome, PersistContainerStateResult, ReconnectCrawl, RemoteContainer, RemoteContainerHydrationHost, } from "./types.js";
|
|
3
4
|
export declare class StaleRemoteHydrationError extends Error {
|
|
4
5
|
}
|
|
5
6
|
export declare function createGenerationGuardedHydrationHost(input: {
|
|
@@ -12,17 +13,8 @@ interface RemoteContainerIngestor {
|
|
|
12
13
|
resume: () => Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare function createRemoteContainerIngestor(input: {
|
|
16
|
+
ownsScope?: () => boolean;
|
|
15
17
|
getSerializationBarrier?: (() => Promise<void> | null) | undefined;
|
|
16
18
|
host: RemoteContainerHydrationHost;
|
|
17
19
|
state: RemoteContainerHydrationState;
|
|
18
20
|
}): RemoteContainerIngestor;
|
|
19
|
-
export declare function hydrateRemoteContainers(input: {
|
|
20
|
-
followDiscoveredParentLanes?: boolean | undefined;
|
|
21
|
-
host: RemoteContainerHydrationHost;
|
|
22
|
-
isCurrent?: (() => boolean) | undefined;
|
|
23
|
-
onFullyHydrated?: (() => Promise<void> | void) | undefined;
|
|
24
|
-
parentIds?: ReadonlyArray<string | null> | undefined;
|
|
25
|
-
resetAllLaneWatermarks?: boolean | undefined;
|
|
26
|
-
resetRootLaneWatermark?: boolean | undefined;
|
|
27
|
-
state: RemoteContainerHydrationState;
|
|
28
|
-
}): Promise<number>;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { finishRemoteHydration } from "./completeHydration.js";
|
|
2
|
-
import { createContainerChildIndex } from "./lanes/childIndex.js";
|
|
3
|
-
import { createContainerParentHydrationQueue } from "./lanes/parentLaneQueue.js";
|
|
4
1
|
import { cacheRemoteContainerPrincipalPolicies } from "./principalPolicyCache.js";
|
|
5
2
|
import { loadPausedContainerFilter } from "./remoteContainers/organizationSyncPauseFilter.js";
|
|
6
|
-
import { canHydrateRemoteContainers, hydrateContainerParentLanes, } from "./remoteContainers/remoteContainerPageHydration.js";
|
|
7
3
|
import { listRemoteContainerIdsWithPendingMetadataUpdates, listRemoteContainerIdsWithPendingStructuralIntents, upsertIsolatedRemoteContainerState, } from "./remoteContainers/remoteContainerState.js";
|
|
4
|
+
export { hydrateRemoteContainers } from "./hydrateRemoteContainers.js";
|
|
8
5
|
export class StaleRemoteHydrationError extends Error {
|
|
9
6
|
}
|
|
10
7
|
export function createGenerationGuardedHydrationHost(input) {
|
|
@@ -192,7 +189,18 @@ export function createRemoteContainerIngestor(input) {
|
|
|
192
189
|
const pendingRemoteContainersById = new Map();
|
|
193
190
|
const generationByContainerId = new Map();
|
|
194
191
|
let ingestRemoteContainersPromise = null;
|
|
192
|
+
const settleStale = (generation) => settleStaleRemoteContainerIngestGeneration({
|
|
193
|
+
generation,
|
|
194
|
+
generationByContainerId,
|
|
195
|
+
queue: pendingRemoteContainersById,
|
|
196
|
+
state,
|
|
197
|
+
});
|
|
195
198
|
const runNextGeneration = () => {
|
|
199
|
+
if (input.ownsScope?.() === false) {
|
|
200
|
+
pendingRemoteContainersById.clear();
|
|
201
|
+
generationByContainerId.clear();
|
|
202
|
+
return Promise.resolve();
|
|
203
|
+
}
|
|
196
204
|
if (ingestRemoteContainersPromise) {
|
|
197
205
|
return ingestRemoteContainersPromise.then(runNextGeneration, runNextGeneration);
|
|
198
206
|
}
|
|
@@ -213,7 +221,8 @@ export function createRemoteContainerIngestor(input) {
|
|
|
213
221
|
pendingRemoteContainersById.delete(nextContainerId);
|
|
214
222
|
return runNextGeneration();
|
|
215
223
|
}
|
|
216
|
-
const isCurrent = () =>
|
|
224
|
+
const isCurrent = () => input.ownsScope?.() !== false &&
|
|
225
|
+
isRemoteContainerIngestGenerationCurrent(state, generation);
|
|
217
226
|
const guardedHost = createGenerationGuardedHydrationHost({
|
|
218
227
|
host,
|
|
219
228
|
isCurrent,
|
|
@@ -228,23 +237,12 @@ export function createRemoteContainerIngestor(input) {
|
|
|
228
237
|
state,
|
|
229
238
|
}))
|
|
230
239
|
.then(() => {
|
|
231
|
-
if (!isCurrent())
|
|
232
|
-
|
|
233
|
-
generation,
|
|
234
|
-
generationByContainerId,
|
|
235
|
-
queue: pendingRemoteContainersById,
|
|
236
|
-
state,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
240
|
+
if (!isCurrent())
|
|
241
|
+
settleStale(generation);
|
|
239
242
|
})
|
|
240
243
|
.catch((error) => {
|
|
241
244
|
if (!isCurrent() || error instanceof StaleRemoteHydrationError) {
|
|
242
|
-
|
|
243
|
-
generation,
|
|
244
|
-
generationByContainerId,
|
|
245
|
-
queue: pendingRemoteContainersById,
|
|
246
|
-
state,
|
|
247
|
-
});
|
|
245
|
+
settleStale(generation);
|
|
248
246
|
return;
|
|
249
247
|
}
|
|
250
248
|
throw error;
|
|
@@ -266,51 +264,4 @@ export function createRemoteContainerIngestor(input) {
|
|
|
266
264
|
ingestRemoteContainer.resume = runNextGeneration;
|
|
267
265
|
return ingestRemoteContainer;
|
|
268
266
|
}
|
|
269
|
-
export async function hydrateRemoteContainers(input) {
|
|
270
|
-
const { host, state } = input;
|
|
271
|
-
if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {
|
|
272
|
-
return 0;
|
|
273
|
-
}
|
|
274
|
-
const seenContainerIds = new Set();
|
|
275
|
-
const containerIdsBeforeHydration = new Set(state.containersById.keys());
|
|
276
|
-
const childIdsByParentId = createContainerChildIndex(state.containersById);
|
|
277
|
-
const { lanes, queueParentLane } = createContainerParentHydrationQueue({
|
|
278
|
-
containerIds: state.containersById.keys(),
|
|
279
|
-
parentIds: input.parentIds,
|
|
280
|
-
resetAllLaneWatermarks: input.resetAllLaneWatermarks,
|
|
281
|
-
resetRootLaneWatermark: input.resetRootLaneWatermark,
|
|
282
|
-
});
|
|
283
|
-
// Follow child lanes during an explicit recursive crawl or for containers first
|
|
284
|
-
// discovered in this pass. The latter lets a newly authorized root populate its
|
|
285
|
-
// descendants immediately, while routine ticks keep known subtrees cache-first.
|
|
286
|
-
const queueDiscoveredParentLane = (containerId) => {
|
|
287
|
-
if (input.followDiscoveredParentLanes ||
|
|
288
|
-
(containerId !== null && !containerIdsBeforeHydration.has(containerId))) {
|
|
289
|
-
queueParentLane(containerId);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
const result = await hydrateContainerParentLanes({
|
|
293
|
-
childIdsByParentId,
|
|
294
|
-
host,
|
|
295
|
-
isCurrent: input.isCurrent,
|
|
296
|
-
lanes,
|
|
297
|
-
queueParentLane: queueDiscoveredParentLane,
|
|
298
|
-
seenContainerIds,
|
|
299
|
-
state,
|
|
300
|
-
});
|
|
301
|
-
const { changedCount } = result;
|
|
302
|
-
await finishRemoteHydration({
|
|
303
|
-
changedCount,
|
|
304
|
-
complete: result.complete &&
|
|
305
|
-
canHydrateRemoteContainers(state) &&
|
|
306
|
-
input.isCurrent?.() !== false,
|
|
307
|
-
containerIdsBeforeHydration,
|
|
308
|
-
host,
|
|
309
|
-
isCurrent: input.isCurrent,
|
|
310
|
-
onFullyHydrated: input.onFullyHydrated,
|
|
311
|
-
seenContainerIds,
|
|
312
|
-
state,
|
|
313
|
-
});
|
|
314
|
-
return changedCount;
|
|
315
|
-
}
|
|
316
267
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,gDAAgD,EAChD,kDAAkD,EAClD,kCAAkC,GACnC,MAAM,yCAAyC,CAAC;AAgBjD,MAAM,OAAO,yBAA0B,SAAQ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AE,KAAK,CAAC,SAAS;QAC1B,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;QACpD,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;KACrD,CAAC,CAAC;IACH,gFAAgF;IAChF,gFAAgF;IAChF,gFAAgF;IAChF,MAAM,yBAAyB,GAA6B,CAAC,WAAW,EAAE,EAAE;QAC1E,IACE,KAAK,CAAC,2BAA2B;YACjC,CAAC,WAAW,KAAK,IAAI,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EACvE,CAAC;YACD,eAAe,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,2BAA2B,CAAC;QAC/C,kBAAkB;QAClB,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,KAAK;QACL,eAAe,EAAE,yBAAyB;QAC1C,gBAAgB;QAChB,KAAK;KACN,CAAC,CAAC;IACH,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAChC,MAAM,qBAAqB,CAAC;QAC1B,YAAY;QACZ,QAAQ,EACN,MAAM,CAAC,QAAQ;YACf,0BAA0B,CAAC,KAAK,CAAC;YACjC,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK;QAC/B,2BAA2B;QAC3B,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,gBAAgB;QAChB,KAAK;KACN,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { finishRemoteHydration } from \"./completeHydration\";\nimport { createContainerChildIndex } from \"./lanes/childIndex\";\nimport { createContainerParentHydrationQueue } from \"./lanes/parentLaneQueue\";\nimport { cacheRemoteContainerPrincipalPolicies } from \"./principalPolicyCache\";\nimport { loadPausedContainerFilter } from \"./remoteContainers/organizationSyncPauseFilter\";\nimport {\n canHydrateRemoteContainers,\n hydrateContainerParentLanes,\n} from \"./remoteContainers/remoteContainerPageHydration\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainers/remoteContainerState\";\nimport type {\n QueueContainerParentLane,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n RemoteContainerIngestQueue,\n} from \"./types\";\n\nexport type {\n ContainerState,\n PersistContainerStateResult,\n RemoteContainer,\n RemoteContainerHydrationHost,\n} from \"./types\";\n\nexport class StaleRemoteHydrationError extends Error {}\n\nexport function createGenerationGuardedHydrationHost(input: {\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n}): RemoteContainerHydrationHost {\n const assertCurrent = () => {\n if (!input.isCurrent()) {\n throw new StaleRemoteHydrationError();\n }\n };\n\n return {\n persistContainerState: async (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) => {\n const callerIsCurrent = mutationOptions?.isCurrent;\n const isCurrent = callerIsCurrent\n ? () => input.isCurrent() && callerIsCurrent()\n : input.isCurrent;\n assertCurrent();\n const record = await input.host.persistContainerState(\n containerState,\n patch,\n updateView,\n saveOptions,\n { ...mutationOptions, isCurrent },\n );\n assertCurrent();\n return record;\n },\n ...(input.host.requestDocumentPriming\n ? {\n requestDocumentPriming: () => {\n if (input.isCurrent()) {\n input.host.requestDocumentPriming?.();\n }\n },\n }\n : {}),\n ...(input.host.requestMetadataRevalidation\n ? {\n requestMetadataRevalidation: async (request) => {\n assertCurrent();\n await input.host.requestMetadataRevalidation?.(request);\n assertCurrent();\n },\n }\n : {}),\n updateSnapshot: () => {\n if (input.isCurrent()) {\n input.host.updateSnapshot();\n }\n },\n };\n}\n\ninterface RemoteContainerIngestGeneration {\n readonly lifecycle: number | undefined;\n readonly structural: number | undefined;\n}\ntype RemoteContainerIngestGenerationMap = Map<\n string,\n RemoteContainerIngestGeneration\n>;\n\nfunction remoteContainerIngestGeneration(\n state: RemoteContainerHydrationState,\n): RemoteContainerIngestGeneration {\n return {\n lifecycle: state.lifecycleGeneration,\n structural: state.structuralGeneration,\n };\n}\n\nfunction remoteContainerIngestGenerationsMatch(\n left: RemoteContainerIngestGeneration | undefined,\n right: RemoteContainerIngestGeneration,\n): boolean {\n return (\n left !== undefined &&\n left.lifecycle === right.lifecycle &&\n left.structural === right.structural\n );\n}\n\nfunction isCurrentQueuedRemoteContainer(\n generation: RemoteContainerIngestGeneration,\n generationByContainerId: RemoteContainerIngestGenerationMap,\n queue: RemoteContainerIngestQueue,\n remoteContainer: RemoteContainer,\n): boolean {\n return (\n queue.get(remoteContainer.id) === remoteContainer &&\n remoteContainerIngestGenerationsMatch(\n generationByContainerId.get(remoteContainer.id),\n generation,\n )\n );\n}\n\nasync function upsertQueuedRemoteContainer(input: {\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n queuedRemoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<boolean> {\n const {\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n generation,\n generationByContainerId,\n host,\n queue,\n queuedRemoteContainer,\n state,\n } = input;\n if (\n !input.isCurrent() ||\n !isCurrentQueuedRemoteContainer(\n generation,\n generationByContainerId,\n queue,\n queuedRemoteContainer,\n )\n ) {\n return false;\n }\n\n // A paused organization's container is acknowledged without being applied,\n // including when the pause lands while the commit is in flight.\n const isPaused = await loadPausedContainerFilter(state);\n if (isPaused(queuedRemoteContainer)) return true;\n const tombstones = await state.persistence.loadContainerHydrationTombstones(\n state.runtime.infra.execSql,\n );\n // A refused folder is reported and acknowledged; the batch continues.\n const upserted = await upsertIsolatedRemoteContainerState({\n expectedHydrationTombstone:\n tombstones.find((row) => row.containerId === queuedRemoteContainer.id) ??\n null,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host,\n isCurrent: () => input.isCurrent() && !isPaused(queuedRemoteContainer),\n remoteContainer: queuedRemoteContainer,\n state,\n });\n if (!upserted) {\n return false;\n }\n return true;\n}\n\nfunction acknowledgeRemoteContainerIngestBatch(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n queuedRemoteContainers: ReadonlyArray<RemoteContainer>;\n}): void {\n if (!input.isCurrent()) {\n return;\n }\n for (const queuedRemoteContainer of input.queuedRemoteContainers) {\n if (\n isCurrentQueuedRemoteContainer(\n input.generation,\n input.generationByContainerId,\n input.queue,\n queuedRemoteContainer,\n )\n ) {\n input.queue.delete(queuedRemoteContainer.id);\n input.generationByContainerId.delete(queuedRemoteContainer.id);\n }\n }\n}\n\nasync function drainRemoteContainerIngestQueue(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n state: RemoteContainerHydrationState;\n}) {\n const { generation, generationByContainerId, host, queue, state } = input;\n let shouldUpdateSnapshot = false;\n\n try {\n while (input.isCurrent()) {\n const queuedRemoteContainers = Array.from(queue.values()).filter(\n (remoteContainer) =>\n remoteContainerIngestGenerationsMatch(\n generationByContainerId.get(remoteContainer.id),\n generation,\n ),\n );\n if (queuedRemoteContainers.length === 0) {\n return;\n }\n await cacheRemoteContainerPrincipalPolicies({\n cacheReferencedPrincipalPolicies:\n state.runtime.principalPolicies.createWarmer(),\n remoteContainers: queuedRemoteContainers,\n stillCurrent: input.isCurrent,\n });\n if (!input.isCurrent()) {\n return;\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: queuedRemoteContainers,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: queuedRemoteContainers,\n state,\n }),\n ]);\n if (!input.isCurrent()) {\n return;\n }\n\n for (const queuedRemoteContainer of queuedRemoteContainers) {\n shouldUpdateSnapshot =\n (await upsertQueuedRemoteContainer({\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n generation,\n generationByContainerId,\n host,\n isCurrent: input.isCurrent,\n queue,\n queuedRemoteContainer,\n state,\n })) || shouldUpdateSnapshot;\n }\n acknowledgeRemoteContainerIngestBatch({\n generation,\n generationByContainerId,\n isCurrent: input.isCurrent,\n queue,\n queuedRemoteContainers,\n });\n\n if (shouldUpdateSnapshot) {\n host.updateSnapshot();\n shouldUpdateSnapshot = false;\n }\n }\n } catch (error) {\n if (shouldUpdateSnapshot) {\n host.updateSnapshot();\n }\n throw error;\n }\n}\n\nfunction isRemoteContainerIngestGenerationCurrent(\n state: RemoteContainerHydrationState,\n generation: RemoteContainerIngestGeneration,\n): boolean {\n return remoteContainerIngestGenerationsMatch(\n remoteContainerIngestGeneration(state),\n generation,\n );\n}\n\nfunction settleStaleRemoteContainerIngestGeneration(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n queue: RemoteContainerIngestQueue;\n state: RemoteContainerHydrationState;\n}): void {\n const currentGeneration = remoteContainerIngestGeneration(input.state);\n const shouldReplay =\n currentGeneration.lifecycle !== input.generation.lifecycle &&\n currentGeneration.structural === input.generation.structural;\n for (const [containerId, generation] of input.generationByContainerId) {\n if (!remoteContainerIngestGenerationsMatch(generation, input.generation)) {\n continue;\n }\n if (shouldReplay) {\n input.generationByContainerId.set(containerId, currentGeneration);\n } else {\n input.generationByContainerId.delete(containerId);\n input.queue.delete(containerId);\n }\n }\n}\n\ninterface RemoteContainerIngestor {\n (remoteContainer: RemoteContainer): Promise<void>;\n hasPending: () => boolean;\n resume: () => Promise<void>;\n}\n\nexport function createRemoteContainerIngestor(input: {\n getSerializationBarrier?: (() => Promise<void> | null) | undefined;\n host: RemoteContainerHydrationHost;\n state: RemoteContainerHydrationState;\n}): RemoteContainerIngestor {\n const { host, state } = input;\n const pendingRemoteContainersById: RemoteContainerIngestQueue = new Map();\n const generationByContainerId: RemoteContainerIngestGenerationMap = new Map();\n let ingestRemoteContainersPromise: Promise<void> | null = null;\n\n const runNextGeneration = (): Promise<void> => {\n if (ingestRemoteContainersPromise) {\n return ingestRemoteContainersPromise.then(\n runNextGeneration,\n runNextGeneration,\n );\n }\n if (\n state.runtime.infra.dbStatus !== undefined &&\n state.runtime.infra.dbStatus !== \"ready\"\n ) {\n return Promise.resolve();\n }\n const serializationBarrier = input.getSerializationBarrier?.();\n if (serializationBarrier) {\n return serializationBarrier.then(runNextGeneration);\n }\n const nextContainerId = pendingRemoteContainersById.keys().next().value;\n if (typeof nextContainerId !== \"string\") {\n return Promise.resolve();\n }\n const generation = generationByContainerId.get(nextContainerId);\n if (!generation) {\n pendingRemoteContainersById.delete(nextContainerId);\n return runNextGeneration();\n }\n const isCurrent = () =>\n isRemoteContainerIngestGenerationCurrent(state, generation);\n const guardedHost = createGenerationGuardedHydrationHost({\n host,\n isCurrent,\n });\n const nextPromise = Promise.resolve()\n .then(() =>\n drainRemoteContainerIngestQueue({\n generation,\n generationByContainerId,\n host: guardedHost,\n isCurrent,\n queue: pendingRemoteContainersById,\n state,\n }),\n )\n .then(() => {\n if (!isCurrent()) {\n settleStaleRemoteContainerIngestGeneration({\n generation,\n generationByContainerId,\n queue: pendingRemoteContainersById,\n state,\n });\n }\n })\n .catch((error: unknown) => {\n if (!isCurrent() || error instanceof StaleRemoteHydrationError) {\n settleStaleRemoteContainerIngestGeneration({\n generation,\n generationByContainerId,\n queue: pendingRemoteContainersById,\n state,\n });\n return;\n }\n throw error;\n })\n .finally(() => {\n if (ingestRemoteContainersPromise === nextPromise) {\n ingestRemoteContainersPromise = null;\n }\n });\n ingestRemoteContainersPromise = nextPromise;\n return nextPromise.then(() =>\n pendingRemoteContainersById.size > 0 ? runNextGeneration() : undefined,\n );\n };\n\n const ingestRemoteContainer = (remoteContainer: RemoteContainer) => {\n pendingRemoteContainersById.set(remoteContainer.id, remoteContainer);\n generationByContainerId.set(\n remoteContainer.id,\n remoteContainerIngestGeneration(state),\n );\n return runNextGeneration();\n };\n ingestRemoteContainer.hasPending = () => pendingRemoteContainersById.size > 0;\n ingestRemoteContainer.resume = runNextGeneration;\n return ingestRemoteContainer;\n}\n\nexport async function hydrateRemoteContainers(input: {\n followDiscoveredParentLanes?: boolean | undefined;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n onFullyHydrated?: (() => Promise<void> | void) | undefined;\n parentIds?: ReadonlyArray<string | null> | undefined;\n resetAllLaneWatermarks?: boolean | undefined;\n resetRootLaneWatermark?: boolean | undefined;\n state: RemoteContainerHydrationState;\n}): Promise<number> {\n const { host, state } = input;\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return 0;\n }\n\n const seenContainerIds = new Set<string>();\n const containerIdsBeforeHydration = new Set(state.containersById.keys());\n const childIdsByParentId = createContainerChildIndex(state.containersById);\n const { lanes, queueParentLane } = createContainerParentHydrationQueue({\n containerIds: state.containersById.keys(),\n parentIds: input.parentIds,\n resetAllLaneWatermarks: input.resetAllLaneWatermarks,\n resetRootLaneWatermark: input.resetRootLaneWatermark,\n });\n // Follow child lanes during an explicit recursive crawl or for containers first\n // discovered in this pass. The latter lets a newly authorized root populate its\n // descendants immediately, while routine ticks keep known subtrees cache-first.\n const queueDiscoveredParentLane: QueueContainerParentLane = (containerId) => {\n if (\n input.followDiscoveredParentLanes ||\n (containerId !== null && !containerIdsBeforeHydration.has(containerId))\n ) {\n queueParentLane(containerId);\n }\n };\n const result = await hydrateContainerParentLanes({\n childIdsByParentId,\n host,\n isCurrent: input.isCurrent,\n lanes,\n queueParentLane: queueDiscoveredParentLane,\n seenContainerIds,\n state,\n });\n const { changedCount } = result;\n await finishRemoteHydration({\n changedCount,\n complete:\n result.complete &&\n canHydrateRemoteContainers(state) &&\n input.isCurrent?.() !== false,\n containerIdsBeforeHydration,\n host,\n isCurrent: input.isCurrent,\n onFullyHydrated: input.onFullyHydrated,\n seenContainerIds,\n state,\n });\n return changedCount;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EACL,gDAAgD,EAChD,kDAAkD,EAClD,kCAAkC,GACnC,MAAM,yCAAyC,CAAC;AAQjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAUpE,MAAM,OAAO,yBAA0B,SAAQ,KAAK;CAAG;AAEvD,MAAM,UAAU,oCAAoC,CAAC,KAGpD;IACC,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;YACvB,MAAM,IAAI,yBAAyB,EAAE,CAAC;QACxC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,qBAAqB,EAAE,KAAK,EAC1B,cAAc,EACd,KAAK,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,EAAE;YACF,MAAM,eAAe,GAAG,eAAe,EAAE,SAAS,CAAC;YACnD,MAAM,SAAS,GAAG,eAAe;gBAC/B,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,eAAe,EAAE;gBAC9C,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;YACpB,aAAa,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,qBAAqB,CACnD,cAAc,EACd,KAAK,EACL,UAAU,EACV,WAAW,EACX,EAAE,GAAG,eAAe,EAAE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AC7B,CAAC,CAAC;IACF,qBAAqB,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,2BAA2B,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9E,qBAAqB,CAAC,MAAM,GAAG,iBAAiB,CAAC;IACjD,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import { cacheRemoteContainerPrincipalPolicies } from \"./principalPolicyCache\";\nimport { loadPausedContainerFilter } from \"./remoteContainers/organizationSyncPauseFilter\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainers/remoteContainerState\";\nimport type {\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n RemoteContainerIngestQueue,\n} from \"./types\";\n\nexport { hydrateRemoteContainers } from \"./hydrateRemoteContainers\";\nexport type {\n ContainerState,\n HydrationOutcome,\n PersistContainerStateResult,\n ReconnectCrawl,\n RemoteContainer,\n RemoteContainerHydrationHost,\n} from \"./types\";\n\nexport class StaleRemoteHydrationError extends Error {}\n\nexport function createGenerationGuardedHydrationHost(input: {\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n}): RemoteContainerHydrationHost {\n const assertCurrent = () => {\n if (!input.isCurrent()) {\n throw new StaleRemoteHydrationError();\n }\n };\n\n return {\n persistContainerState: async (\n containerState,\n patch,\n updateView,\n saveOptions,\n mutationOptions,\n ) => {\n const callerIsCurrent = mutationOptions?.isCurrent;\n const isCurrent = callerIsCurrent\n ? () => input.isCurrent() && callerIsCurrent()\n : input.isCurrent;\n assertCurrent();\n const record = await input.host.persistContainerState(\n containerState,\n patch,\n updateView,\n saveOptions,\n { ...mutationOptions, isCurrent },\n );\n assertCurrent();\n return record;\n },\n ...(input.host.requestDocumentPriming\n ? {\n requestDocumentPriming: () => {\n if (input.isCurrent()) {\n input.host.requestDocumentPriming?.();\n }\n },\n }\n : {}),\n ...(input.host.requestMetadataRevalidation\n ? {\n requestMetadataRevalidation: async (request) => {\n assertCurrent();\n await input.host.requestMetadataRevalidation?.(request);\n assertCurrent();\n },\n }\n : {}),\n updateSnapshot: () => {\n if (input.isCurrent()) {\n input.host.updateSnapshot();\n }\n },\n };\n}\n\ninterface RemoteContainerIngestGeneration {\n readonly lifecycle: number | undefined;\n readonly structural: number | undefined;\n}\ntype RemoteContainerIngestGenerationMap = Map<\n string,\n RemoteContainerIngestGeneration\n>;\n\nfunction remoteContainerIngestGeneration(\n state: RemoteContainerHydrationState,\n): RemoteContainerIngestGeneration {\n return {\n lifecycle: state.lifecycleGeneration,\n structural: state.structuralGeneration,\n };\n}\n\nfunction remoteContainerIngestGenerationsMatch(\n left: RemoteContainerIngestGeneration | undefined,\n right: RemoteContainerIngestGeneration,\n): boolean {\n return (\n left !== undefined &&\n left.lifecycle === right.lifecycle &&\n left.structural === right.structural\n );\n}\n\nfunction isCurrentQueuedRemoteContainer(\n generation: RemoteContainerIngestGeneration,\n generationByContainerId: RemoteContainerIngestGenerationMap,\n queue: RemoteContainerIngestQueue,\n remoteContainer: RemoteContainer,\n): boolean {\n return (\n queue.get(remoteContainer.id) === remoteContainer &&\n remoteContainerIngestGenerationsMatch(\n generationByContainerId.get(remoteContainer.id),\n generation,\n )\n );\n}\n\nasync function upsertQueuedRemoteContainer(input: {\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n queuedRemoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<boolean> {\n const {\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n generation,\n generationByContainerId,\n host,\n queue,\n queuedRemoteContainer,\n state,\n } = input;\n if (\n !input.isCurrent() ||\n !isCurrentQueuedRemoteContainer(\n generation,\n generationByContainerId,\n queue,\n queuedRemoteContainer,\n )\n ) {\n return false;\n }\n\n // A paused organization's container is acknowledged without being applied,\n // including when the pause lands while the commit is in flight.\n const isPaused = await loadPausedContainerFilter(state);\n if (isPaused(queuedRemoteContainer)) return true;\n const tombstones = await state.persistence.loadContainerHydrationTombstones(\n state.runtime.infra.execSql,\n );\n // A refused folder is reported and acknowledged; the batch continues.\n const upserted = await upsertIsolatedRemoteContainerState({\n expectedHydrationTombstone:\n tombstones.find((row) => row.containerId === queuedRemoteContainer.id) ??\n null,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host,\n isCurrent: () => input.isCurrent() && !isPaused(queuedRemoteContainer),\n remoteContainer: queuedRemoteContainer,\n state,\n });\n if (!upserted) {\n return false;\n }\n return true;\n}\n\nfunction acknowledgeRemoteContainerIngestBatch(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n queuedRemoteContainers: ReadonlyArray<RemoteContainer>;\n}): void {\n if (!input.isCurrent()) {\n return;\n }\n for (const queuedRemoteContainer of input.queuedRemoteContainers) {\n if (\n isCurrentQueuedRemoteContainer(\n input.generation,\n input.generationByContainerId,\n input.queue,\n queuedRemoteContainer,\n )\n ) {\n input.queue.delete(queuedRemoteContainer.id);\n input.generationByContainerId.delete(queuedRemoteContainer.id);\n }\n }\n}\n\nasync function drainRemoteContainerIngestQueue(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n host: RemoteContainerHydrationHost;\n isCurrent: () => boolean;\n queue: RemoteContainerIngestQueue;\n state: RemoteContainerHydrationState;\n}) {\n const { generation, generationByContainerId, host, queue, state } = input;\n let shouldUpdateSnapshot = false;\n\n try {\n while (input.isCurrent()) {\n const queuedRemoteContainers = Array.from(queue.values()).filter(\n (remoteContainer) =>\n remoteContainerIngestGenerationsMatch(\n generationByContainerId.get(remoteContainer.id),\n generation,\n ),\n );\n if (queuedRemoteContainers.length === 0) {\n return;\n }\n await cacheRemoteContainerPrincipalPolicies({\n cacheReferencedPrincipalPolicies:\n state.runtime.principalPolicies.createWarmer(),\n remoteContainers: queuedRemoteContainers,\n stillCurrent: input.isCurrent,\n });\n if (!input.isCurrent()) {\n return;\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: queuedRemoteContainers,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: queuedRemoteContainers,\n state,\n }),\n ]);\n if (!input.isCurrent()) {\n return;\n }\n\n for (const queuedRemoteContainer of queuedRemoteContainers) {\n shouldUpdateSnapshot =\n (await upsertQueuedRemoteContainer({\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n generation,\n generationByContainerId,\n host,\n isCurrent: input.isCurrent,\n queue,\n queuedRemoteContainer,\n state,\n })) || shouldUpdateSnapshot;\n }\n acknowledgeRemoteContainerIngestBatch({\n generation,\n generationByContainerId,\n isCurrent: input.isCurrent,\n queue,\n queuedRemoteContainers,\n });\n\n if (shouldUpdateSnapshot) {\n host.updateSnapshot();\n shouldUpdateSnapshot = false;\n }\n }\n } catch (error) {\n if (shouldUpdateSnapshot) {\n host.updateSnapshot();\n }\n throw error;\n }\n}\n\nfunction isRemoteContainerIngestGenerationCurrent(\n state: RemoteContainerHydrationState,\n generation: RemoteContainerIngestGeneration,\n): boolean {\n return remoteContainerIngestGenerationsMatch(\n remoteContainerIngestGeneration(state),\n generation,\n );\n}\n\nfunction settleStaleRemoteContainerIngestGeneration(input: {\n generation: RemoteContainerIngestGeneration;\n generationByContainerId: RemoteContainerIngestGenerationMap;\n queue: RemoteContainerIngestQueue;\n state: RemoteContainerHydrationState;\n}): void {\n const currentGeneration = remoteContainerIngestGeneration(input.state);\n const shouldReplay =\n currentGeneration.lifecycle !== input.generation.lifecycle &&\n currentGeneration.structural === input.generation.structural;\n for (const [containerId, generation] of input.generationByContainerId) {\n if (!remoteContainerIngestGenerationsMatch(generation, input.generation)) {\n continue;\n }\n if (shouldReplay) {\n input.generationByContainerId.set(containerId, currentGeneration);\n } else {\n input.generationByContainerId.delete(containerId);\n input.queue.delete(containerId);\n }\n }\n}\n\ninterface RemoteContainerIngestor {\n (remoteContainer: RemoteContainer): Promise<void>;\n hasPending: () => boolean;\n resume: () => Promise<void>;\n}\n\nexport function createRemoteContainerIngestor(input: {\n ownsScope?: () => boolean;\n getSerializationBarrier?: (() => Promise<void> | null) | undefined;\n host: RemoteContainerHydrationHost;\n state: RemoteContainerHydrationState;\n}): RemoteContainerIngestor {\n const { host, state } = input;\n const pendingRemoteContainersById: RemoteContainerIngestQueue = new Map();\n const generationByContainerId: RemoteContainerIngestGenerationMap = new Map();\n let ingestRemoteContainersPromise: Promise<void> | null = null;\n\n const settleStale = (generation: RemoteContainerIngestGeneration) =>\n settleStaleRemoteContainerIngestGeneration({\n generation,\n generationByContainerId,\n queue: pendingRemoteContainersById,\n state,\n });\n\n const runNextGeneration = (): Promise<void> => {\n if (input.ownsScope?.() === false) {\n pendingRemoteContainersById.clear();\n generationByContainerId.clear();\n return Promise.resolve();\n }\n if (ingestRemoteContainersPromise) {\n return ingestRemoteContainersPromise.then(\n runNextGeneration,\n runNextGeneration,\n );\n }\n if (\n state.runtime.infra.dbStatus !== undefined &&\n state.runtime.infra.dbStatus !== \"ready\"\n ) {\n return Promise.resolve();\n }\n const serializationBarrier = input.getSerializationBarrier?.();\n if (serializationBarrier) {\n return serializationBarrier.then(runNextGeneration);\n }\n const nextContainerId = pendingRemoteContainersById.keys().next().value;\n if (typeof nextContainerId !== \"string\") {\n return Promise.resolve();\n }\n const generation = generationByContainerId.get(nextContainerId);\n if (!generation) {\n pendingRemoteContainersById.delete(nextContainerId);\n return runNextGeneration();\n }\n const isCurrent = () =>\n input.ownsScope?.() !== false &&\n isRemoteContainerIngestGenerationCurrent(state, generation);\n const guardedHost = createGenerationGuardedHydrationHost({\n host,\n isCurrent,\n });\n const nextPromise = Promise.resolve()\n .then(() =>\n drainRemoteContainerIngestQueue({\n generation,\n generationByContainerId,\n host: guardedHost,\n isCurrent,\n queue: pendingRemoteContainersById,\n state,\n }),\n )\n .then(() => {\n if (!isCurrent()) settleStale(generation);\n })\n .catch((error: unknown) => {\n if (!isCurrent() || error instanceof StaleRemoteHydrationError) {\n settleStale(generation);\n return;\n }\n throw error;\n })\n .finally(() => {\n if (ingestRemoteContainersPromise === nextPromise) {\n ingestRemoteContainersPromise = null;\n }\n });\n ingestRemoteContainersPromise = nextPromise;\n return nextPromise.then(() =>\n pendingRemoteContainersById.size > 0 ? runNextGeneration() : undefined,\n );\n };\n\n const ingestRemoteContainer = (remoteContainer: RemoteContainer) => {\n pendingRemoteContainersById.set(remoteContainer.id, remoteContainer);\n generationByContainerId.set(\n remoteContainer.id,\n remoteContainerIngestGeneration(state),\n );\n return runNextGeneration();\n };\n ingestRemoteContainer.hasPending = () => pendingRemoteContainersById.size > 0;\n ingestRemoteContainer.resume = runNextGeneration;\n return ingestRemoteContainer;\n}\n"]}
|
|
@@ -8,13 +8,14 @@ async function prepareContainerParentLanePage(input) {
|
|
|
8
8
|
? await new ContainerSyncWatermarkRepository(state.runtime.infra.execSql).loadWatermark(syncLane)
|
|
9
9
|
: lane.watermark;
|
|
10
10
|
return {
|
|
11
|
-
lane,
|
|
11
|
+
lane: { ...lane, watermark },
|
|
12
12
|
request: { laneId, parentId: lane.parentId, watermark },
|
|
13
13
|
syncLane,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export async function fetchContainerParentLaneBatch(input) {
|
|
17
17
|
const { batch, state } = input;
|
|
18
|
+
const prefix = input.laneIdPrefix ?? state.parentLaneRequestPrefix ?? "lane";
|
|
18
19
|
const expectedContainerStates = new Map(Array.from(state.containersById, ([containerId, containerState]) => [
|
|
19
20
|
containerId,
|
|
20
21
|
{
|
|
@@ -24,7 +25,7 @@ export async function fetchContainerParentLaneBatch(input) {
|
|
|
24
25
|
]));
|
|
25
26
|
const preparedPages = await Promise.all(batch.map((lane, index) => prepareContainerParentLanePage({
|
|
26
27
|
lane,
|
|
27
|
-
laneId:
|
|
28
|
+
laneId: `${prefix}-${index}`,
|
|
28
29
|
state,
|
|
29
30
|
})));
|
|
30
31
|
if (input.isCurrent?.() === false) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parentLaneFetch.js","sourceRoot":"","sources":["parentLaneFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mFAAmF,CAAC;AACrI,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAOhG,KAAK,UAAU,8BAA8B,CAAC,KAI7C;IACC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACtC,MAAM,QAAQ,GAAG,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,MAAM,SAAS,GACb,IAAI,CAAC,SAAS,KAAK,SAAS;QAC1B,CAAC,CAAC,MAAM,IAAI,gCAAgC,CACxC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAC5B,CAAC,aAAa,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;IACrB,OAAO;QACL,IAAI;
|
|
1
|
+
{"version":3,"file":"parentLaneFetch.js","sourceRoot":"","sources":["parentLaneFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mFAAmF,CAAC;AACrI,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAOhG,KAAK,UAAU,8BAA8B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CAAC,MAAM,KAAK,aAAa,CAAC,MAAM,EAChD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE;QACxC,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QACD,OAAO;YACL,uBAAuB;YACvB,2BAA2B;YAC3B,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,YAAY,CAAC,QAAQ;SAChC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { ContainerSyncWatermarkRepository } from \"../../../../data/persistence/container-contents/containerSyncWatermarkPersistence\";\nimport { createContainerParentSyncLane } from \"../../containerPersistence\";\nimport { createContainerStateFingerprint } from \"../remoteContainers/containerStateFingerprint\";\nimport type {\n ContainerParentHydrationLane,\n FetchedContainerParentLanePage,\n RemoteContainerHydrationState,\n} from \"../types\";\n\nasync function prepareContainerParentLanePage(input: {\n lane: ContainerParentHydrationLane;\n laneId: string;\n state: RemoteContainerHydrationState;\n}) {\n const { lane, laneId, state } = input;\n const syncLane = createContainerParentSyncLane(lane.parentId);\n const watermark =\n lane.watermark === undefined\n ? await new ContainerSyncWatermarkRepository(\n state.runtime.infra.execSql,\n ).loadWatermark(syncLane)\n : lane.watermark;\n return {\n lane: { ...lane, watermark },\n request: { laneId, parentId: lane.parentId, watermark },\n syncLane,\n };\n}\n\nexport async function fetchContainerParentLaneBatch(input: {\n batch: ReadonlyArray<ContainerParentHydrationLane>;\n laneIdPrefix?: string | undefined;\n isCurrent?: (() => boolean) | undefined;\n state: RemoteContainerHydrationState;\n}): Promise<ReadonlyArray<FetchedContainerParentLanePage> | null> {\n const { batch, state } = input;\n const prefix = input.laneIdPrefix ?? state.parentLaneRequestPrefix ?? \"lane\";\n const expectedContainerStates = new Map(\n Array.from(state.containersById, ([containerId, containerState]) => [\n containerId,\n {\n container: { ...containerState.container },\n fingerprint: createContainerStateFingerprint(containerState),\n },\n ]),\n );\n const preparedPages = await Promise.all(\n batch.map((lane, index) =>\n prepareContainerParentLanePage({\n lane,\n laneId: `${prefix}-${index}`,\n state,\n }),\n ),\n );\n if (input.isCurrent?.() === false) {\n return null;\n }\n const expectedHydrationTombstones = new Map(\n (\n await state.persistence.loadContainerHydrationTombstones(\n state.runtime.infra.execSql,\n )\n ).map((tombstone) => [tombstone.containerId, tombstone]),\n );\n if (input.isCurrent?.() === false) {\n return null;\n }\n const response = await state.runtime.apiClient.listContainerParentLanes({\n lanes: preparedPages.map((page) => page.request),\n });\n if (!response) {\n // A superseded crawl's failure says nothing about the current tree.\n if (input.isCurrent?.() !== false) {\n state.containerListingFailures =\n (state.containerListingFailures ?? 0) + 1;\n }\n return null;\n }\n\n const pagesByLaneId = new Map(\n response.results.map((result) => [result.laneId, result.page]),\n );\n if (\n pagesByLaneId.size !== preparedPages.length ||\n response.results.length !== preparedPages.length\n ) {\n throw new Error(\"Container parent lane batch response mismatch\");\n }\n\n return preparedPages.map((preparedPage) => {\n const page = pagesByLaneId.get(preparedPage.request.laneId);\n if (!page) {\n throw new Error(\"Container parent lane batch response mismatch\");\n }\n return {\n expectedContainerStates,\n expectedHydrationTombstones,\n lane: preparedPage.lane,\n response: page,\n syncLane: preparedPage.syncLane,\n };\n });\n}\n"]}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { referencedPrincipalPolicyKey } from "../../../data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js";
|
|
2
|
+
import { isKeyingVerificationError } from "../../../data/shared/securityIncidents.js";
|
|
3
|
+
async function readPolicyRefusal(warm) {
|
|
4
|
+
try {
|
|
5
|
+
await warm();
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (isKeyingVerificationError(error))
|
|
10
|
+
return error;
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
2
14
|
export async function cacheRemoteContainerPrincipalPolicies(input) {
|
|
3
15
|
const cacheReferencedPrincipalPolicies = input.cacheReferencedPrincipalPolicies;
|
|
4
16
|
if (!cacheReferencedPrincipalPolicies) {
|
|
@@ -17,10 +29,50 @@ export async function cacheRemoteContainerPrincipalPolicies(input) {
|
|
|
17
29
|
}
|
|
18
30
|
referencesByOrganizationId.set(organizationId, organizationReferences);
|
|
19
31
|
}
|
|
20
|
-
await Promise.all([...referencesByOrganizationId].map(([organizationId, referencesByKey]) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
await Promise.all([...referencesByOrganizationId].map(async ([organizationId, referencesByKey]) => {
|
|
33
|
+
const references = [...referencesByKey.values()];
|
|
34
|
+
const warm = (group) => cacheReferencedPrincipalPolicies({
|
|
35
|
+
organizationId,
|
|
36
|
+
references: group,
|
|
37
|
+
stillCurrent: input.stillCurrent,
|
|
38
|
+
});
|
|
39
|
+
if (!input.onRefused)
|
|
40
|
+
return warm(references);
|
|
41
|
+
const batchError = await readPolicyRefusal(() => warm(references));
|
|
42
|
+
if (!batchError)
|
|
43
|
+
return;
|
|
44
|
+
// A failed batch identifies no individual reference. Isolate it
|
|
45
|
+
// without excluding independent containers in the same organization.
|
|
46
|
+
for (const reference of references) {
|
|
47
|
+
if (input.stillCurrent?.() === false)
|
|
48
|
+
return;
|
|
49
|
+
const error = references.length === 1
|
|
50
|
+
? batchError
|
|
51
|
+
: await readPolicyRefusal(() => warm([reference]));
|
|
52
|
+
if (error)
|
|
53
|
+
input.onRefused(organizationId, reference, error);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
export async function warmListedContainerPolicies(items, warmer, recordManualError, stillCurrent) {
|
|
58
|
+
const refused = new Set();
|
|
59
|
+
const key = (organizationId, reference) => JSON.stringify([organizationId, referencedPrincipalPolicyKey(reference)]);
|
|
60
|
+
await cacheRemoteContainerPrincipalPolicies({
|
|
61
|
+
cacheReferencedPrincipalPolicies: warmer,
|
|
62
|
+
remoteContainers: items,
|
|
63
|
+
stillCurrent,
|
|
64
|
+
...(recordManualError && {
|
|
65
|
+
onRefused: (org, ref, error) => {
|
|
66
|
+
recordManualError(error);
|
|
67
|
+
refused.add(key(org, ref));
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
if (!refused.size)
|
|
72
|
+
return { items, outcome: "complete" };
|
|
73
|
+
return {
|
|
74
|
+
outcome: "refused",
|
|
75
|
+
items: items.filter((item) => !item.metadataReferencedPrincipals.some((ref) => refused.has(key(item.organizationId, ref)))),
|
|
76
|
+
};
|
|
25
77
|
}
|
|
26
78
|
//# sourceMappingURL=principalPolicyCache.js.map
|