@tearleads/client-sdk 0.1.251 → 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.d.ts +0 -2
- package/Tearleads.js +17 -28
- 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/organizations/organizationReadModelPresentation.js +7 -4
- package/client/organizations/organizationReadModelPresentation.js.map +1 -1
- package/client/organizations/organizationReadModels.js +6 -5
- package/client/organizations/organizationReadModels.js.map +1 -1
- package/client/organizations/organizationWorkflowRuntime.js +1 -1
- package/client/organizations/organizationWorkflowRuntime.js.map +1 -1
- package/client/runtime/principalMutationApi.d.ts +4 -0
- package/client/runtime/principalMutationApi.js +9 -5
- package/client/runtime/principalMutationApi.js.map +1 -1
- package/client/runtime/runtimeIdentityResolution.js +23 -0
- package/client/runtime/runtimeIdentityResolution.js.map +1 -1
- package/client/runtime/runtimeSubscription.js +68 -0
- package/client/runtime/runtimeSubscription.js.map +1 -0
- package/client/runtime/workflowRuntime.d.ts +3 -1
- package/client/runtime/workflowRuntime.js +31 -81
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/client/session/authenticationMachine.js +47 -0
- package/client/session/authenticationMachine.js.map +1 -0
- package/client/session/index.js +75 -93
- package/client/session/index.js.map +1 -1
- package/client/session/sessionBlobStore.js +39 -0
- package/client/session/sessionBlobStore.js.map +1 -0
- package/client/session/sessionContext.js +11 -0
- package/client/session/sessionContext.js.map +1 -1
- package/client/session/sessionIdentityTrust.d.ts +2 -1
- package/client/session/sessionIdentityTrust.js +8 -4
- package/client/session/sessionIdentityTrust.js.map +1 -1
- package/client/session/sessionLifetime.js +87 -0
- package/client/session/sessionLifetime.js.map +1 -0
- package/client/session/sessionLogin.js +114 -0
- package/client/session/sessionLogin.js.map +1 -0
- package/client/session/sessionOrganizationCreation.js +3 -2
- package/client/session/sessionOrganizationCreation.js.map +1 -1
- package/client/session/sessionPurgeRecovery.js +11 -3
- package/client/session/sessionPurgeRecovery.js.map +1 -1
- package/client/session/sessionTypes.d.ts +6 -2
- package/client/session/sessionTypes.js.map +1 -1
- package/data/blobs/blobContracts.d.ts +4 -3
- package/data/blobs/blobContracts.js.map +1 -1
- package/data/blobs/createBlobStore.js +1 -8
- package/data/blobs/createBlobStore.js.map +1 -1
- package/data/blobs/encryptedBlobStore.js +17 -12
- package/data/blobs/encryptedBlobStore.js.map +1 -1
- package/data/blobs/memoryBlobStore.js +8 -5
- package/data/blobs/memoryBlobStore.js.map +1 -1
- package/data/blobs/opfsBlobFile.js +36 -0
- package/data/blobs/opfsBlobFile.js.map +1 -0
- package/data/blobs/opfsBlobStore.d.ts +1 -1
- package/data/blobs/opfsBlobStore.js +91 -21
- package/data/blobs/opfsBlobStore.js.map +1 -1
- package/data/principals/principalPolicyCoordinator.js +8 -17
- package/data/principals/principalPolicyCoordinator.js.map +1 -1
- package/data/shared/domainScope.d.ts +2 -0
- package/data/shared/domainScope.js +2 -1
- package/data/shared/domainScope.js.map +1 -1
- package/data/shared/keyedQueue.js +15 -0
- package/data/shared/keyedQueue.js.map +1 -0
- package/data/sqlite/migrations/migrateLocalSchema.js +2 -3
- package/data/sqlite/migrations/migrateLocalSchema.js.map +1 -1
- package/data/sqlite/sqlExec.d.ts +6 -0
- package/data/sqlite/sqlExec.js +64 -13
- package/data/sqlite/sqlExec.js.map +1 -1
- package/data/sqlite/sqlitePersistenceRuntime.js +2 -3
- package/data/sqlite/sqlitePersistenceRuntime.js.map +1 -1
- package/data/sync/syncCoordinator.js +17 -10
- package/data/sync/syncCoordinator.js.map +1 -1
- package/data/trustedUserIdentity/service.js +2 -1
- package/data/trustedUserIdentity/service.js.map +1 -1
- package/data/trustedUserIdentity/types.d.ts +1 -1
- package/data/trustedUserIdentity/types.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +4 -1
- package/internal/api-client/apiRequestRuntime.d.ts +6 -3
- package/internal/api-client/apiRequestRuntime.js +86 -101
- package/internal/api-client/apiRequestRuntime.js.map +1 -1
- package/internal/api-client/binaryRequestOperationTransport.js +2 -1
- package/internal/api-client/binaryRequestOperationTransport.js.map +1 -1
- package/internal/api-client/binaryResponseOperationTransport.js +6 -2
- package/internal/api-client/binaryResponseOperationTransport.js.map +1 -1
- package/internal/api-client/client/blobs.d.ts +1 -0
- package/internal/api-client/client/blobs.js +12 -3
- package/internal/api-client/client/blobs.js.map +1 -1
- package/internal/api-client/client/laneListingRequest.js +4 -0
- package/internal/api-client/client/laneListingRequest.js.map +1 -1
- package/internal/api-client/client/session.d.ts +5 -1
- package/internal/api-client/client/session.js +12 -4
- package/internal/api-client/client/session.js.map +1 -1
- package/internal/api-client/client/writerProjections.js +12 -13
- package/internal/api-client/client/writerProjections.js.map +1 -1
- package/internal/api-client/operationResponse.d.ts +1 -1
- package/internal/api-client/operationResponse.js +10 -23
- package/internal/api-client/operationResponse.js.map +1 -1
- package/internal/api-client/operationTransport.js +2 -1
- package/internal/api-client/operationTransport.js.map +1 -1
- package/internal/api-client/principalHistoryRequest.js +25 -20
- package/internal/api-client/principalHistoryRequest.js.map +1 -1
- package/internal/api-client/principalHistoryRequestContext.js +30 -6
- package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
- package/internal/api-client/principalPolicyPages.d.ts +4 -1
- package/internal/api-client/principalPolicyPages.js +4 -2
- package/internal/api-client/principalPolicyPages.js.map +1 -1
- package/internal/api-client/projectionPolicyHistoryPages.d.ts +4 -1
- package/internal/api-client/projectionPolicyHistoryPages.js +4 -2
- package/internal/api-client/projectionPolicyHistoryPages.js.map +1 -1
- package/internal/api-client/routes/blobs/blobDownloadBody.js +65 -0
- package/internal/api-client/routes/blobs/blobDownloadBody.js.map +1 -0
- package/internal/api-client/routes/blobs/get.js +9 -67
- package/internal/api-client/routes/blobs/get.js.map +1 -1
- package/internal/api-client/routes/blobs/multipartUpload.js +1 -1
- package/internal/api-client/routes/blobs/multipartUpload.js.map +1 -1
- package/internal/api-client/sessionRefresh.js +1 -1
- package/internal/api-client/sessionRefresh.js.map +1 -1
- package/internal/api-client/sessionRenewal.d.ts +31 -0
- package/internal/api-client/sessionRenewal.js +91 -6
- package/internal/api-client/sessionRenewal.js.map +1 -1
- package/internal/api-client/sessionRequestInit.js +22 -0
- package/internal/api-client/sessionRequestInit.js.map +1 -0
- package/internal/api-client/sessionResponse.js +39 -0
- package/internal/api-client/sessionResponse.js.map +1 -0
- package/internal/api-client/types.d.ts +1 -0
- package/internal/api-client/types.js.map +1 -1
- package/internal/api-client/webSocketTickets.d.ts +1 -0
- package/internal/api-client/webSocketTickets.js +4 -0
- package/internal/api-client/webSocketTickets.js.map +1 -1
- package/internal/sqlite-worker/client.d.ts +1 -1
- package/internal/sqlite-worker/client.js +6 -1
- package/internal/sqlite-worker/client.js.map +1 -1
- package/internal/sqlite-worker/purgeOpfsDatabase.d.ts +1 -1
- package/internal/sqlite-worker/purgeOpfsDatabase.js +3 -2
- package/internal/sqlite-worker/purgeOpfsDatabase.js.map +1 -1
- package/internal/sqlite-worker/types.d.ts +4 -0
- package/internal/sqlite-worker/types.js.map +1 -1
- package/package.json +1 -1
- package/sqlite/worker.js +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/documents/attachments/blobMutationLock.d.ts +1 -1
- package/workflows/documents/attachments/blobMutationLock.js +2 -2
- package/workflows/documents/attachments/blobMutationLock.js.map +1 -1
- package/workflows/organizations/readModel/readModelProjection.js +2 -0
- package/workflows/organizations/readModel/readModelProjection.js.map +1 -1
- package/workflows/registration/registerIdentity.js +2 -0
- package/workflows/registration/registerIdentity.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,18 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOrCreateDomainSyncCoordinator, isDatabaseUnavailableError, } from "../../data/sync/syncCoordinator.js";
|
|
2
2
|
import { isAutomaticRootCatchupContainerNode, isReconcilableContainerNode, isRemoteBackedContainerNode, } from "../../stores/container-contents/index.js";
|
|
3
3
|
import { openDocumentStore } from "../../stores/documents/index.js";
|
|
4
4
|
import { requestRegisteredDocumentRemoteSync, subscribeToPersistedDocumentDeletions, subscribeToPersistedDocuments, } from "../../stores/documents/registry.js";
|
|
5
5
|
import { getOrCreateLocalProjectionStore, } from "../../stores/local-projection/index.js";
|
|
6
6
|
import { connectReconciliationTriggers, createReconciliationService, systemReconciliationClock, } from "../../sync/reconciliation/index.js";
|
|
7
|
-
import { createContainerContentsDocumentsRuntime,
|
|
7
|
+
import { createContainerContentsDocumentsRuntime, } from "../../workflows/container-contents/index.js";
|
|
8
8
|
import { listAllContainerDocumentIdsFromApi } from "../../workflows/container-contents/documentDiscovery/containerDocumentListing.js";
|
|
9
9
|
import { probeUndiscoveredRemoteDocumentBatch } from "../../workflows/container-contents/documentPriming/documentHydrationProbe.js";
|
|
10
|
+
import { createContainerContentsStoreRuntime as createDeviceFirstWorkflowRuntime, } from "../containerContents/index.js";
|
|
10
11
|
import { discoverContainerDocumentLanesForRuntime } from "../containerContents/documentDiscovery.js";
|
|
11
|
-
import { requireShareRecipient } from "../organizations/recipientAdmission.js";
|
|
12
12
|
import { createReconciledDocumentContentPuller } from "./reconciledDocumentContentPull.js";
|
|
13
13
|
export function createDeviceFirst(runtimeService, containerContents) {
|
|
14
14
|
return new DeviceFirstService(runtimeService, containerContents);
|
|
15
15
|
}
|
|
16
|
+
function stopScopeEntry(entry) {
|
|
17
|
+
entry.coordinator.dispose();
|
|
18
|
+
entry.contents.reconciler.stop();
|
|
19
|
+
entry.disconnectReconciliationTriggers();
|
|
20
|
+
entry.unsubscribePersistedDocumentDeletions();
|
|
21
|
+
entry.unsubscribePersistedDocuments();
|
|
22
|
+
}
|
|
16
23
|
function createInitialDocumentProbeHost(runtimeService, domainScope) {
|
|
17
24
|
return {
|
|
18
25
|
listContainerDocumentIds: (containerId) => {
|
|
@@ -62,14 +69,17 @@ class DeviceFirstService {
|
|
|
62
69
|
// scope's reconciler subscribed and its coordinator pump live; tear them
|
|
63
70
|
// all down. Force-stop each scope's coordinator (which runs the reconciler
|
|
64
71
|
// lane) alongside stopping the service.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
entry.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.entriesByScope.
|
|
72
|
+
const entries = Array.from(this.entriesByScope);
|
|
73
|
+
for (const [, entry] of entries)
|
|
74
|
+
entry.retiring = true;
|
|
75
|
+
for (const [scope, entry] of entries)
|
|
76
|
+
this.retireEntry(scope, entry);
|
|
77
|
+
}
|
|
78
|
+
retireEntry(scope, entry) {
|
|
79
|
+
if (this.entriesByScope.get(scope) !== entry)
|
|
80
|
+
return;
|
|
81
|
+
this.entriesByScope.delete(scope);
|
|
82
|
+
stopScopeEntry(entry);
|
|
73
83
|
}
|
|
74
84
|
workflowRuntime() {
|
|
75
85
|
return createDeviceFirstWorkflowRuntime(this.runtimeService);
|
|
@@ -78,18 +88,29 @@ class DeviceFirstService {
|
|
|
78
88
|
const runtime = this.workflowRuntime();
|
|
79
89
|
const domainScope = runtime.state.domainScope;
|
|
80
90
|
const existing = this.entriesByScope.get(domainScope);
|
|
91
|
+
if (existing && (existing.retiring || existing.coordinator.isDisposed())) {
|
|
92
|
+
this.retireEntry(domainScope, existing);
|
|
93
|
+
return this.getOrCreateEntry(options);
|
|
94
|
+
}
|
|
81
95
|
if (existing) {
|
|
82
96
|
// Do not call updateRuntime here: facade selectors run during React
|
|
83
97
|
// render, and updateRuntime emits synchronously. Hosts drive runtime
|
|
84
98
|
// updates through view.updateRuntime() from an effect instead.
|
|
85
99
|
return existing;
|
|
86
100
|
}
|
|
101
|
+
const coordinator = getOrCreateDomainSyncCoordinator(domainScope);
|
|
87
102
|
const store = getOrCreateLocalProjectionStore({
|
|
88
103
|
domainScope,
|
|
89
104
|
runtime,
|
|
90
105
|
options,
|
|
91
106
|
});
|
|
92
|
-
|
|
107
|
+
// Opening the container store publishes its lane. A subscriber may have
|
|
108
|
+
// finished opening this scope while that notification was in progress.
|
|
109
|
+
if (this.entriesByScope.has(domainScope))
|
|
110
|
+
return this.getOrCreateEntry(options);
|
|
111
|
+
if (coordinator.isDisposed())
|
|
112
|
+
throw new Error("Device-first scope retired during registration");
|
|
113
|
+
const service = createReconciliationService(this.createReconciliationHost(store, domainScope, coordinator));
|
|
93
114
|
const disconnectReconciliationTriggers = connectReconciliationTriggers({
|
|
94
115
|
service,
|
|
95
116
|
store,
|
|
@@ -98,7 +119,6 @@ class DeviceFirstService {
|
|
|
98
119
|
store.removePersistedDocument(localId);
|
|
99
120
|
});
|
|
100
121
|
const unsubscribePersistedDocuments = subscribeToPersistedDocuments(domainScope, (document, change) => store.refreshPersistedDocument(document, change.placementChanged));
|
|
101
|
-
service.start();
|
|
102
122
|
const view = {
|
|
103
123
|
getSnapshot: () => store.getSnapshot(),
|
|
104
124
|
subscribe: (listener) => store.subscribe(listener),
|
|
@@ -106,6 +126,7 @@ class DeviceFirstService {
|
|
|
106
126
|
updateRuntime: (nextRuntime) => store.updateRuntime(nextRuntime),
|
|
107
127
|
};
|
|
108
128
|
const entry = {
|
|
129
|
+
coordinator,
|
|
109
130
|
contents: {
|
|
110
131
|
containerStore: store.getContainerStore(),
|
|
111
132
|
reconciler: service,
|
|
@@ -116,9 +137,15 @@ class DeviceFirstService {
|
|
|
116
137
|
unsubscribePersistedDocuments,
|
|
117
138
|
};
|
|
118
139
|
this.entriesByScope.set(domainScope, entry);
|
|
119
|
-
|
|
140
|
+
service.start();
|
|
141
|
+
const current = this.entriesByScope.get(domainScope);
|
|
142
|
+
if (!current || current.coordinator.isDisposed()) {
|
|
143
|
+
this.retireEntry(domainScope, entry);
|
|
144
|
+
throw new Error("Device-first scope retired during registration");
|
|
145
|
+
}
|
|
146
|
+
return current;
|
|
120
147
|
}
|
|
121
|
-
createReconciliationHost(store, domainScope) {
|
|
148
|
+
createReconciliationHost(store, domainScope, coordinator) {
|
|
122
149
|
const runtimeService = this.runtimeService;
|
|
123
150
|
const containerContents = this.containerContents;
|
|
124
151
|
const requestDocumentContentPull = createReconciledDocumentContentPuller({
|
|
@@ -157,7 +184,7 @@ class DeviceFirstService {
|
|
|
157
184
|
return {
|
|
158
185
|
clock: systemReconciliationClock,
|
|
159
186
|
domainScope,
|
|
160
|
-
registerLane: (key, config) =>
|
|
187
|
+
registerLane: (key, config) => coordinator.registerLane(key, config),
|
|
161
188
|
canDiscoverContainerDocuments,
|
|
162
189
|
getRuntimeStatus: () => {
|
|
163
190
|
const input = runtimeService.workflowInput();
|
|
@@ -210,10 +237,5 @@ function logReconciliationFailure(runtime, message, error) {
|
|
|
210
237
|
const { log, logError } = runtime.util;
|
|
211
238
|
return logError ? logError(message, error) : log(message);
|
|
212
239
|
}
|
|
213
|
-
export
|
|
214
|
-
const input = runtimeService.workflowInput();
|
|
215
|
-
return createContainerContentsStoreWorkflowRuntimeFromSnapshot({ ...input, organizations: runtimeService.containerContentsOrganizations }, runtimeService.adoptRootContainer,
|
|
216
|
-
// Admit against the trust store of the database this runtime writes.
|
|
217
|
-
(userId, accessLevel) => requireShareRecipient(runtimeService, input.infra.execSql, userId, accessLevel));
|
|
218
|
-
}
|
|
240
|
+
export { createDeviceFirstWorkflowRuntime };
|
|
219
241
|
//# sourceMappingURL=index.js.map
|
|
@@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yncCoordinator,\n isDatabaseUnavailableError,\n} from \"../../data/sync/syncCoordinator\";\nimport {\n type ContainerContentsStore,\n type ContainerContentsStoreOptions,\n isAutomaticRootCatchupContainerNode,\n isReconcilableContainerNode,\n isRemoteBackedContainerNode,\n} from \"../../stores/container-contents\";\nimport { openDocumentStore } from \"../../stores/documents\";\nimport {\n requestRegisteredDocumentRemoteSync,\n subscribeToPersistedDocumentDeletions,\n subscribeToPersistedDocuments,\n} from \"../../stores/documents/registry\";\nimport {\n getOrCreateLocalProjectionStore,\n type LocalProjectionStore,\n type LocalProjectionView,\n} from \"../../stores/local-projection\";\nimport {\n connectReconciliationTriggers,\n createReconciliationService,\n type ReconciliationHost,\n type ReconciliationService,\n systemReconciliationClock,\n} from \"../../sync/reconciliation\";\nimport {\n type ContainerContentsStoreWorkflowRuntime,\n createContainerContentsDocumentsRuntime,\n createContainerContentsStoreWorkflowRuntimeFromSnapshot,\n} from \"../../workflows/container-contents\";\nimport { listAllContainerDocumentIdsFromApi } from \"../../workflows/container-contents/documentDiscovery/containerDocumentListing\";\nimport { probeUndiscoveredRemoteDocumentBatch } from \"../../workflows/container-contents/documentPriming/documentHydrationProbe\";\nimport type { ContainerContents } from \"../containerContents\";\nimport { discoverContainerDocumentLanesForRuntime } from \"../containerContents/documentDiscovery\";\nimport { requireShareRecipient } from \"../organizations/recipientAdmission\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { createReconciledDocumentContentPuller } from \"./reconciledDocumentContentPull\";\n\nexport type { LocalProjectionView } from \"../../stores/local-projection\";\n\n/** One domain scope's local read, local-write, and reconciliation handles. */\nexport interface DeviceFirstContainerContents {\n /**\n * Locally durable container tree and mutation store. Ordinary tree writes\n * update this store after local persistence and queue remote convergence in\n * the background; security-sensitive remote operations keep their explicit\n * online requirements.\n */\n readonly containerStore: ContainerContentsStore;\n /** Background remote reconciliation; never awaited for first paint. */\n readonly reconciler: ReconciliationService;\n /** Synchronously readable container/document projection. */\n readonly view: LocalProjectionView;\n}\n\n/**\n * Device-first facade. Opens a shared scope that pairs immediate local reads\n * and locally durable writes with background remote convergence.\n */\nexport interface DeviceFirst {\n /** Open all device-first handles for the current domain scope. */\n open(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstContainerContents;\n /** Stop the current scope's reconciler (if one was created) on teardown. */\n dispose(): void;\n}\n\nexport function createDeviceFirst(\n runtimeService: InternalRuntime,\n containerContents: ContainerContents,\n): DeviceFirst {\n return new DeviceFirstService(runtimeService, containerContents);\n}\n\ninterface DeviceFirstScopeEntry {\n contents: DeviceFirstContainerContents;\n disconnectReconciliationTriggers: () => void;\n unsubscribePersistedDocumentDeletions: () => void;\n unsubscribePersistedDocuments: () => void;\n}\n\nfunction createInitialDocumentProbeHost(\n runtimeService: InternalRuntime,\n domainScope: ReconciliationHost[\"domainScope\"],\n): Pick<\n ReconciliationHost,\n | \"listContainerDocumentIds\"\n | \"probeUndiscoveredDocumentsBatch\"\n | \"reportInitialDocumentProbeComplete\"\n> {\n return {\n listContainerDocumentIds: (containerId) => {\n const runtime = createDeviceFirstWorkflowRuntime(runtimeService);\n return listAllContainerDocumentIdsFromApi({\n apiClient: runtime.apiClient,\n containerId,\n reportErrors: false,\n });\n },\n probeUndiscoveredDocumentsBatch: async (input) => {\n const runtime = createDeviceFirstWorkflowRuntime(runtimeService);\n return probeUndiscoveredRemoteDocumentBatch({\n ...input,\n host: {\n documentWorkflowRuntime: (containerId) =>\n createContainerContentsDocumentsRuntime(runtime, containerId),\n openDocumentStore: (target) =>\n openDocumentStore(\n domainScope,\n target.localId,\n target.runtime,\n target.documentId,\n ),\n },\n runtime,\n });\n },\n reportInitialDocumentProbeComplete: (requestedCount) => {\n runtimeService\n .workflowInput()\n .util.log(\n `Initial document hydration probe requested ${requestedCount} syncs`,\n );\n },\n };\n}\n\nclass DeviceFirstService implements DeviceFirst {\n // A real Map (not WeakMap) so dispose() can iterate every scope seen this\n // session. A running reconciler holds event subscriptions that keep an idle,\n // stale-scope service (and its scope) reachable anyway, so WeakMap bought no\n // GC here; the entries are released explicitly on dispose().\n private readonly entriesByScope = new Map<\n DomainScope,\n DeviceFirstScopeEntry\n >();\n\n constructor(\n private readonly runtimeService: InternalRuntime,\n private readonly containerContents: ContainerContents,\n ) {}\n\n open(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstContainerContents {\n return this.getOrCreateEntry(options).contents;\n }\n\n dispose(): void {\n // Stop every reconciler created this session — not just the current\n // scope's. A scope change (e.g. anonymous -> authenticated) leaves the old\n // scope's reconciler subscribed and its coordinator pump live; tear them\n // all down. Force-stop each scope's coordinator (which runs the reconciler\n // lane) alongside stopping the service.\n for (const [domainScope, entry] of this.entriesByScope) {\n entry.contents.reconciler.stop();\n entry.disconnectReconciliationTriggers();\n entry.unsubscribePersistedDocumentDeletions();\n entry.unsubscribePersistedDocuments();\n disposeDomainSyncCoordinator(domainScope);\n }\n this.entriesByScope.clear();\n }\n\n private workflowRuntime(): ContainerContentsStoreWorkflowRuntime {\n return createDeviceFirstWorkflowRuntime(this.runtimeService);\n }\n\n private getOrCreateEntry(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstScopeEntry {\n const runtime = this.workflowRuntime();\n const domainScope = runtime.state.domainScope;\n const existing = this.entriesByScope.get(domainScope);\n if (existing) {\n // Do not call updateRuntime here: facade selectors run during React\n // render, and updateRuntime emits synchronously. Hosts drive runtime\n // updates through view.updateRuntime() from an effect instead.\n return existing;\n }\n\n const store = getOrCreateLocalProjectionStore({\n domainScope,\n runtime,\n options,\n });\n const service = createReconciliationService(\n this.createReconciliationHost(store, domainScope),\n );\n const disconnectReconciliationTriggers = connectReconciliationTriggers({\n service,\n store,\n });\n const unsubscribePersistedDocumentDeletions =\n subscribeToPersistedDocumentDeletions(domainScope, (localId) => {\n store.removePersistedDocument(localId);\n });\n const unsubscribePersistedDocuments = subscribeToPersistedDocuments(\n domainScope,\n (document, change) =>\n store.refreshPersistedDocument(document, change.placementChanged),\n );\n service.start();\n\n const view: LocalProjectionView = {\n getSnapshot: () => store.getSnapshot(),\n subscribe: (listener) => store.subscribe(listener),\n setActiveContainer: (containerId) =>\n store.setActiveContainer(containerId),\n updateRuntime: (nextRuntime) => store.updateRuntime(nextRuntime),\n };\n\n const entry: DeviceFirstScopeEntry = {\n contents: {\n containerStore: store.getContainerStore(),\n reconciler: service,\n view,\n },\n disconnectReconciliationTriggers,\n unsubscribePersistedDocumentDeletions,\n unsubscribePersistedDocuments,\n };\n this.entriesByScope.set(domainScope, entry);\n return entry;\n }\n\n private createReconciliationHost(\n store: LocalProjectionStore,\n domainScope: ReconciliationHost[\"domainScope\"],\n ): ReconciliationHost {\n const runtimeService = this.runtimeService;\n const containerContents = this.containerContents;\n const requestDocumentContentPull = createReconciledDocumentContentPuller({\n getContainer: (containerId) =>\n store\n .getSnapshot()\n .containers.find((container) => container.id === containerId) ?? null,\n pullDocumentContent: (input) =>\n containerContents.pullDocumentContent(input),\n requestRegisteredDocumentRemoteSync: (localId, documentId) =>\n requestRegisteredDocumentRemoteSync(domainScope, localId, documentId),\n });\n const canDiscoverContainerDocuments = (containerId: string) => {\n const container = store\n .getSnapshot()\n .containers.find((node) => node.id === containerId);\n return container ? isRemoteBackedContainerNode(container) : false;\n };\n const listKnownContainerIds = () => {\n // A local-first id is not listable yet and may still be racing its create\n // request. Once remote-backed, it participates normally; system contents\n // are especially important during rematerialization because this device\n // may not have authored them.\n const homeOrganizationId =\n runtimeService.workflowInput().auth.organizationId;\n return store\n .getSnapshot()\n .containers.flatMap((node) =>\n isReconcilableContainerNode(node, homeOrganizationId)\n ? [node.id]\n : [],\n );\n };\n const listAutomaticRootCatchupContainerIds = () => {\n const homeOrganizationId =\n runtimeService.workflowInput().auth.organizationId;\n return store\n .getSnapshot()\n .containers.flatMap((node) =>\n isAutomaticRootCatchupContainerNode(node, homeOrganizationId)\n ? [node.id]\n : [],\n );\n };\n return {\n clock: systemReconciliationClock,\n domainScope,\n registerLane: (key, config) =>\n getOrCreateDomainSyncCoordinator(domainScope).registerLane(key, config),\n canDiscoverContainerDocuments,\n getRuntimeStatus: () => {\n const input = runtimeService.workflowInput();\n return {\n dbStatus: input.infra.dbStatus,\n isAuthenticated: input.auth.isAuthenticated,\n online: input.state.online,\n };\n },\n listKnownContainerIds,\n // Root discovery can surface directly granted non-root containers, so\n // retain every regular container. Exclude only this identity's own system\n // children; cold/auth backfill and explicit full Refresh cover those.\n listAutomaticRootCatchupContainerIds,\n discoverContainerDocuments: (requests, onOutcome) =>\n discoverContainerDocumentLanesForRuntime({\n onOutcome,\n requests,\n runtimeService,\n }),\n loadContainerDelta: (containerId) =>\n store.loadContainerDelta(containerId),\n applyReconciled: (delta) => store.applyReconciled(delta),\n requestDocumentContentPull,\n ...createInitialDocumentProbeHost(runtimeService, domainScope),\n refreshTree: () =>\n refreshContainerTree((onListingUnavailable) =>\n store.getContainerStore().refresh({ onListingUnavailable }),\n ),\n refreshRootTree: () =>\n refreshContainerTree((onListingUnavailable) =>\n store.getContainerStore().refreshRootLane({ onListingUnavailable }),\n ),\n isIgnorableError: isDatabaseUnavailableError,\n // Resolve the runtime per call: it is rebuilt as the active identity\n // changes, and a reference captured here would report into a dead host.\n logError: (message, error) =>\n logReconciliationFailure(this.workflowRuntime(), message, error),\n };\n }\n}\n\n/**\n * Runs one tree refresh and rejects if any listing request it made failed or\n * timed out: the crawl stopped short, so the tree may be stale even though\n * the refresh itself settled.\n */\nasync function refreshContainerTree(\n refresh: (onListingUnavailable: () => void) => Promise<boolean>,\n): Promise<void> {\n let listingUnavailable = false;\n await refresh(() => {\n listingUnavailable = true;\n });\n if (listingUnavailable) {\n throw new Error(\"Container tree listing was unavailable\");\n }\n}\n\n// Returns the host's result: both callbacks are declared `=> void` but may be\n// async, and the lane reporter only catches a rejection it is handed.\nfunction logReconciliationFailure(\n runtime: ContainerContentsStoreWorkflowRuntime,\n message: string,\n error: unknown,\n): unknown {\n const { log, logError } = runtime.util;\n return logError ? logError(message, error) : log(message);\n}\n\nexport function createDeviceFirstWorkflowRuntime(\n runtimeService: InternalRuntime,\n): ContainerContentsStoreWorkflowRuntime {\n const input = runtimeService.workflowInput();\n return createContainerContentsStoreWorkflowRuntimeFromSnapshot(\n { ...input, organizations: runtimeService.containerContentsOrganizations },\n runtimeService.adoptRootContainer,\n // Admit against the trust store of the database this runtime writes.\n (userId, accessLevel) =>\n requireShareRecipient(\n runtimeService,\n input.infra.execSql,\n userId,\n accessLevel,\n ),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAGL,mCAAmC,EACnC,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,mCAAmC,EACnC,qCAAqC,EACrC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,+BAA+B,GAGhC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAG3B,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,uCAAuC,GACxC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kCAAkC,EAAE,MAAM,+EAA+E,CAAC;AACnI,OAAO,EAAE,oCAAoC,EAAE,MAAM,2EAA2E,CAAC;AACjI,OAAO,EAEL,mCAAmC,IAAI,gCAAgC,GACxE,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wCAAwC,EAAE,MAAM,wCAAwC,CAAC;AAElG,OAAO,EAAE,qCAAqC,EAAE,MAAM,iCAAiC,CAAC;AAgCxF,MAAM,UAAU,iBAAiB,CAC/B,cAA+B,EAC/B,iBAAoC;IAEpC,OAAO,IAAI,kBAAkB,CAAC,cAAc,EAAE,iBAA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AAE,EAAE,CAC5C,KAAK,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAC5D;YACH,eAAe,EAAE,GAAG,EAAE,CACpB,oBAAoB,CAAC,CAAC,oBAAoB,EAAE,EAAE,CAC5C,KAAK,CAAC,iBAAiB,EAAE,CAAC,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAC,CACpE;YACH,gBAAgB,EAAE,0BAA0B;YAC5C,qEAAqE;YACrE,wEAAwE;YACxE,QAAQ,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAC3B,wBAAwB,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC;SACnE,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,KAAK,UAAU,oBAAoB,CACjC,OAA+D;IAE/D,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAC/B,MAAM,OAAO,CAAC,GAAG,EAAE;QACjB,kBAAkB,GAAG,IAAI,CAAC;IAC5B,CAAC,CAAC,CAAC;IACH,IAAI,kBAAkB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,sEAAsE;AACtE,SAAS,wBAAwB,CAC/B,OAA8C,EAC9C,OAAe,EACf,KAAc;IAEd,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACvC,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,OAAO,EAAE,gCAAgC,EAAE,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport {\n type DomainSyncCoordinator,\n getOrCreateDomainSyncCoordinator,\n isDatabaseUnavailableError,\n} from \"../../data/sync/syncCoordinator\";\nimport {\n type ContainerContentsStore,\n type ContainerContentsStoreOptions,\n isAutomaticRootCatchupContainerNode,\n isReconcilableContainerNode,\n isRemoteBackedContainerNode,\n} from \"../../stores/container-contents\";\nimport { openDocumentStore } from \"../../stores/documents\";\nimport {\n requestRegisteredDocumentRemoteSync,\n subscribeToPersistedDocumentDeletions,\n subscribeToPersistedDocuments,\n} from \"../../stores/documents/registry\";\nimport {\n getOrCreateLocalProjectionStore,\n type LocalProjectionStore,\n type LocalProjectionView,\n} from \"../../stores/local-projection\";\nimport {\n connectReconciliationTriggers,\n createReconciliationService,\n type ReconciliationHost,\n type ReconciliationService,\n systemReconciliationClock,\n} from \"../../sync/reconciliation\";\nimport {\n type ContainerContentsStoreWorkflowRuntime,\n createContainerContentsDocumentsRuntime,\n} from \"../../workflows/container-contents\";\nimport { listAllContainerDocumentIdsFromApi } from \"../../workflows/container-contents/documentDiscovery/containerDocumentListing\";\nimport { probeUndiscoveredRemoteDocumentBatch } from \"../../workflows/container-contents/documentPriming/documentHydrationProbe\";\nimport {\n type ContainerContents,\n createContainerContentsStoreRuntime as createDeviceFirstWorkflowRuntime,\n} from \"../containerContents\";\nimport { discoverContainerDocumentLanesForRuntime } from \"../containerContents/documentDiscovery\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { createReconciledDocumentContentPuller } from \"./reconciledDocumentContentPull\";\n\nexport type { LocalProjectionView } from \"../../stores/local-projection\";\n\n/** One domain scope's local read, local-write, and reconciliation handles. */\nexport interface DeviceFirstContainerContents {\n /**\n * Locally durable container tree and mutation store. Ordinary tree writes\n * update this store after local persistence and queue remote convergence in\n * the background; security-sensitive remote operations keep their explicit\n * online requirements.\n */\n readonly containerStore: ContainerContentsStore;\n /** Background remote reconciliation; never awaited for first paint. */\n readonly reconciler: ReconciliationService;\n /** Synchronously readable container/document projection. */\n readonly view: LocalProjectionView;\n}\n\n/**\n * Device-first facade. Opens a shared scope that pairs immediate local reads\n * and locally durable writes with background remote convergence.\n */\nexport interface DeviceFirst {\n /** Open all device-first handles for the current domain scope. */\n open(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstContainerContents;\n /** Stop the current scope's reconciler (if one was created) on teardown. */\n dispose(): void;\n}\n\nexport function createDeviceFirst(\n runtimeService: InternalRuntime,\n containerContents: ContainerContents,\n): DeviceFirst {\n return new DeviceFirstService(runtimeService, containerContents);\n}\n\ninterface DeviceFirstScopeEntry {\n retiring?: boolean;\n coordinator: DomainSyncCoordinator;\n contents: DeviceFirstContainerContents;\n disconnectReconciliationTriggers: () => void;\n unsubscribePersistedDocumentDeletions: () => void;\n unsubscribePersistedDocuments: () => void;\n}\n\nfunction stopScopeEntry(entry: DeviceFirstScopeEntry): void {\n entry.coordinator.dispose();\n entry.contents.reconciler.stop();\n entry.disconnectReconciliationTriggers();\n entry.unsubscribePersistedDocumentDeletions();\n entry.unsubscribePersistedDocuments();\n}\n\nfunction createInitialDocumentProbeHost(\n runtimeService: InternalRuntime,\n domainScope: ReconciliationHost[\"domainScope\"],\n): Pick<\n ReconciliationHost,\n | \"listContainerDocumentIds\"\n | \"probeUndiscoveredDocumentsBatch\"\n | \"reportInitialDocumentProbeComplete\"\n> {\n return {\n listContainerDocumentIds: (containerId) => {\n const runtime = createDeviceFirstWorkflowRuntime(runtimeService);\n return listAllContainerDocumentIdsFromApi({\n apiClient: runtime.apiClient,\n containerId,\n reportErrors: false,\n });\n },\n probeUndiscoveredDocumentsBatch: async (input) => {\n const runtime = createDeviceFirstWorkflowRuntime(runtimeService);\n return probeUndiscoveredRemoteDocumentBatch({\n ...input,\n host: {\n documentWorkflowRuntime: (containerId) =>\n createContainerContentsDocumentsRuntime(runtime, containerId),\n openDocumentStore: (target) =>\n openDocumentStore(\n domainScope,\n target.localId,\n target.runtime,\n target.documentId,\n ),\n },\n runtime,\n });\n },\n reportInitialDocumentProbeComplete: (requestedCount) => {\n runtimeService\n .workflowInput()\n .util.log(\n `Initial document hydration probe requested ${requestedCount} syncs`,\n );\n },\n };\n}\n\nclass DeviceFirstService implements DeviceFirst {\n // A real Map (not WeakMap) so dispose() can iterate every scope seen this\n // session. A running reconciler holds event subscriptions that keep an idle,\n // stale-scope service (and its scope) reachable anyway, so WeakMap bought no\n // GC here; the entries are released explicitly on dispose().\n private readonly entriesByScope = new Map<\n DomainScope,\n DeviceFirstScopeEntry\n >();\n\n constructor(\n private readonly runtimeService: InternalRuntime,\n private readonly containerContents: ContainerContents,\n ) {}\n\n open(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstContainerContents {\n return this.getOrCreateEntry(options).contents;\n }\n\n dispose(): void {\n // Stop every reconciler created this session — not just the current\n // scope's. A scope change (e.g. anonymous -> authenticated) leaves the old\n // scope's reconciler subscribed and its coordinator pump live; tear them\n // all down. Force-stop each scope's coordinator (which runs the reconciler\n // lane) alongside stopping the service.\n const entries = Array.from(this.entriesByScope);\n for (const [, entry] of entries) entry.retiring = true;\n for (const [scope, entry] of entries) this.retireEntry(scope, entry);\n }\n\n private retireEntry(scope: DomainScope, entry: DeviceFirstScopeEntry): void {\n if (this.entriesByScope.get(scope) !== entry) return;\n this.entriesByScope.delete(scope);\n stopScopeEntry(entry);\n }\n\n private workflowRuntime(): ContainerContentsStoreWorkflowRuntime {\n return createDeviceFirstWorkflowRuntime(this.runtimeService);\n }\n\n private getOrCreateEntry(\n options?: ContainerContentsStoreOptions | undefined,\n ): DeviceFirstScopeEntry {\n const runtime = this.workflowRuntime();\n const domainScope = runtime.state.domainScope;\n const existing = this.entriesByScope.get(domainScope);\n if (existing && (existing.retiring || existing.coordinator.isDisposed())) {\n this.retireEntry(domainScope, existing);\n return this.getOrCreateEntry(options);\n }\n if (existing) {\n // Do not call updateRuntime here: facade selectors run during React\n // render, and updateRuntime emits synchronously. Hosts drive runtime\n // updates through view.updateRuntime() from an effect instead.\n return existing;\n }\n\n const coordinator = getOrCreateDomainSyncCoordinator(domainScope);\n const store = getOrCreateLocalProjectionStore({\n domainScope,\n runtime,\n options,\n });\n // Opening the container store publishes its lane. A subscriber may have\n // finished opening this scope while that notification was in progress.\n if (this.entriesByScope.has(domainScope))\n return this.getOrCreateEntry(options);\n if (coordinator.isDisposed())\n throw new Error(\"Device-first scope retired during registration\");\n const service = createReconciliationService(\n this.createReconciliationHost(store, domainScope, coordinator),\n );\n const disconnectReconciliationTriggers = connectReconciliationTriggers({\n service,\n store,\n });\n const unsubscribePersistedDocumentDeletions =\n subscribeToPersistedDocumentDeletions(domainScope, (localId) => {\n store.removePersistedDocument(localId);\n });\n const unsubscribePersistedDocuments = subscribeToPersistedDocuments(\n domainScope,\n (document, change) =>\n store.refreshPersistedDocument(document, change.placementChanged),\n );\n const view: LocalProjectionView = {\n getSnapshot: () => store.getSnapshot(),\n subscribe: (listener) => store.subscribe(listener),\n setActiveContainer: (containerId) =>\n store.setActiveContainer(containerId),\n updateRuntime: (nextRuntime) => store.updateRuntime(nextRuntime),\n };\n\n const entry: DeviceFirstScopeEntry = {\n coordinator,\n contents: {\n containerStore: store.getContainerStore(),\n reconciler: service,\n view,\n },\n disconnectReconciliationTriggers,\n unsubscribePersistedDocumentDeletions,\n unsubscribePersistedDocuments,\n };\n this.entriesByScope.set(domainScope, entry);\n service.start();\n const current = this.entriesByScope.get(domainScope);\n if (!current || current.coordinator.isDisposed()) {\n this.retireEntry(domainScope, entry);\n throw new Error(\"Device-first scope retired during registration\");\n }\n return current;\n }\n\n private createReconciliationHost(\n store: LocalProjectionStore,\n domainScope: ReconciliationHost[\"domainScope\"],\n coordinator: DomainSyncCoordinator,\n ): ReconciliationHost {\n const runtimeService = this.runtimeService;\n const containerContents = this.containerContents;\n const requestDocumentContentPull = createReconciledDocumentContentPuller({\n getContainer: (containerId) =>\n store\n .getSnapshot()\n .containers.find((container) => container.id === containerId) ?? null,\n pullDocumentContent: (input) =>\n containerContents.pullDocumentContent(input),\n requestRegisteredDocumentRemoteSync: (localId, documentId) =>\n requestRegisteredDocumentRemoteSync(domainScope, localId, documentId),\n });\n const canDiscoverContainerDocuments = (containerId: string) => {\n const container = store\n .getSnapshot()\n .containers.find((node) => node.id === containerId);\n return container ? isRemoteBackedContainerNode(container) : false;\n };\n const listKnownContainerIds = () => {\n // A local-first id is not listable yet and may still be racing its create\n // request. Once remote-backed, it participates normally; system contents\n // are especially important during rematerialization because this device\n // may not have authored them.\n const homeOrganizationId =\n runtimeService.workflowInput().auth.organizationId;\n return store\n .getSnapshot()\n .containers.flatMap((node) =>\n isReconcilableContainerNode(node, homeOrganizationId)\n ? [node.id]\n : [],\n );\n };\n const listAutomaticRootCatchupContainerIds = () => {\n const homeOrganizationId =\n runtimeService.workflowInput().auth.organizationId;\n return store\n .getSnapshot()\n .containers.flatMap((node) =>\n isAutomaticRootCatchupContainerNode(node, homeOrganizationId)\n ? [node.id]\n : [],\n );\n };\n return {\n clock: systemReconciliationClock,\n domainScope,\n registerLane: (key, config) => coordinator.registerLane(key, config),\n canDiscoverContainerDocuments,\n getRuntimeStatus: () => {\n const input = runtimeService.workflowInput();\n return {\n dbStatus: input.infra.dbStatus,\n isAuthenticated: input.auth.isAuthenticated,\n online: input.state.online,\n };\n },\n listKnownContainerIds,\n // Root discovery can surface directly granted non-root containers, so\n // retain every regular container. Exclude only this identity's own system\n // children; cold/auth backfill and explicit full Refresh cover those.\n listAutomaticRootCatchupContainerIds,\n discoverContainerDocuments: (requests, onOutcome) =>\n discoverContainerDocumentLanesForRuntime({\n onOutcome,\n requests,\n runtimeService,\n }),\n loadContainerDelta: (containerId) =>\n store.loadContainerDelta(containerId),\n applyReconciled: (delta) => store.applyReconciled(delta),\n requestDocumentContentPull,\n ...createInitialDocumentProbeHost(runtimeService, domainScope),\n refreshTree: () =>\n refreshContainerTree((onListingUnavailable) =>\n store.getContainerStore().refresh({ onListingUnavailable }),\n ),\n refreshRootTree: () =>\n refreshContainerTree((onListingUnavailable) =>\n store.getContainerStore().refreshRootLane({ onListingUnavailable }),\n ),\n isIgnorableError: isDatabaseUnavailableError,\n // Resolve the runtime per call: it is rebuilt as the active identity\n // changes, and a reference captured here would report into a dead host.\n logError: (message, error) =>\n logReconciliationFailure(this.workflowRuntime(), message, error),\n };\n }\n}\n\n/**\n * Runs one tree refresh and rejects if any listing request it made failed or\n * timed out: the crawl stopped short, so the tree may be stale even though\n * the refresh itself settled.\n */\nasync function refreshContainerTree(\n refresh: (onListingUnavailable: () => void) => Promise<boolean>,\n): Promise<void> {\n let listingUnavailable = false;\n await refresh(() => {\n listingUnavailable = true;\n });\n if (listingUnavailable) {\n throw new Error(\"Container tree listing was unavailable\");\n }\n}\n\n// Returns the host's result: both callbacks are declared `=> void` but may be\n// async, and the lane reporter only catches a rejection it is handed.\nfunction logReconciliationFailure(\n runtime: ContainerContentsStoreWorkflowRuntime,\n message: string,\n error: unknown,\n): unknown {\n const { log, logError } = runtime.util;\n return logError ? logError(message, error) : log(message);\n}\n\nexport { createDeviceFirstWorkflowRuntime };\n"]}
|
|
@@ -7,7 +7,7 @@ import { isOrganizationDataRuntimeCurrent, } from "./organizationWorkflowRuntime
|
|
|
7
7
|
/**
|
|
8
8
|
* Run one read-model pass for the scope, then present what it applied: access
|
|
9
9
|
* recovery when the pass restored a server-denied scope, group names, and
|
|
10
|
-
* verified leave requests.
|
|
10
|
+
* verified leave requests. A superseded pass resolves without a result.
|
|
11
11
|
*/
|
|
12
12
|
export function presentOrganizationReadModelPass(runtimeService, active, pass, passIsCurrent = () => true) {
|
|
13
13
|
// Snapshot the server-denied flag before reconciling. A reconcile that
|
|
@@ -26,9 +26,12 @@ export function presentOrganizationReadModelPass(runtimeService, active, pass, p
|
|
|
26
26
|
const domainScope = active.runtime.state.domainScope;
|
|
27
27
|
const stillCurrent = () => isOrganizationDataRuntimeCurrent(runtimeService, active, domainScope) &&
|
|
28
28
|
passIsCurrent();
|
|
29
|
+
const obsolete = () => runtimeService.workflowInput().state.domainScope === domainScope
|
|
30
|
+
? null
|
|
31
|
+
: undefined;
|
|
29
32
|
return pass().then(async (directoryAndGroups) => {
|
|
30
33
|
if (!stillCurrent())
|
|
31
|
-
return
|
|
34
|
+
return obsolete();
|
|
32
35
|
// Feed success restores retry eligibility even if name decryption fails.
|
|
33
36
|
const accessWasRestored = accessWasDenied &&
|
|
34
37
|
directoryAndGroups !== null &&
|
|
@@ -42,10 +45,10 @@ export function presentOrganizationReadModelPass(runtimeService, active, pass, p
|
|
|
42
45
|
userId: active.userId,
|
|
43
46
|
});
|
|
44
47
|
if (!stillCurrent())
|
|
45
|
-
return
|
|
48
|
+
return obsolete();
|
|
46
49
|
const presented = await withVerifiedLeaveRequests(await hydrateOrganizationGroupNamesForRuntime(runtimeService, active, domainScope, directoryAndGroups), leaveRequestVerifier(runtimeService, active.runtime, active));
|
|
47
50
|
// A transition during presentation publishes nothing for the old scope.
|
|
48
|
-
return stillCurrent() ? presented :
|
|
51
|
+
return stillCurrent() ? presented : obsolete();
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
//# sourceMappingURL=organizationReadModelPresentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModelPresentation.js","sourceRoot":"","sources":["organizationReadModelPresentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAE1G,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,+CAA+C,EAAE,MAAM,6EAA6E,CAAC;AAE9I,OAAO,EAAE,uCAAuC,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAEL,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAC9C,cAA+B,EAC/B,MAAqC,EACrC,IAAsE,EACtE,gBAA+B,GAAG,EAAE,CAAC,IAAI;IAEzC,uEAAuE;IACvE,yEAAyE;IACzE,8DAA8D;IAC9D,0EAA0E;IAC1E,qEAAqE;IACrE,yEAAyE;IACzE,2EAA2E;IAC3E,oEAAoE;IACpE,MAAM,eAAe,GAAG,+CAA+C,CACrE;QACE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QACrC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,eAAe,EAAE,MAAM,CAAC,MAAM;KAC/B,EACD,WAAW,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC;IACrD,MAAM,YAAY,GAAG,GAAG,EAAE,CACxB,gCAAgC,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,CAAC;QACrE,aAAa,EAAE,CAAC;IAElB,OAAO,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE;QAC9C,IAAI,CAAC,YAAY,EAAE;YAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"organizationReadModelPresentation.js","sourceRoot":"","sources":["organizationReadModelPresentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAE1G,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,+CAA+C,EAAE,MAAM,6EAA6E,CAAC;AAE9I,OAAO,EAAE,uCAAuC,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAEL,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAC9C,cAA+B,EAC/B,MAAqC,EACrC,IAAsE,EACtE,gBAA+B,GAAG,EAAE,CAAC,IAAI;IAEzC,uEAAuE;IACvE,yEAAyE;IACzE,8DAA8D;IAC9D,0EAA0E;IAC1E,qEAAqE;IACrE,yEAAyE;IACzE,2EAA2E;IAC3E,oEAAoE;IACpE,MAAM,eAAe,GAAG,+CA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C7D,CAAC;QACF,wEAAwE;QACxE,OAAO,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { recoverOrganizationAccess } from \"../../workflows/container-contents/recovery/accessRestoration\";\nimport type { OrganizationDirectoryAndGroups } from \"../../workflows/organizations\";\nimport { withVerifiedLeaveRequests } from \"../../workflows/organizations\";\nimport { wasOrganizationPresentationAccessDeniedByServer } from \"../../workflows/organizations/readModel/organizationPresentationAccessState\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { hydrateOrganizationGroupNamesForRuntime } from \"./organizationGroupNameHydration\";\nimport { leaveRequestVerifier } from \"./organizationLeaveRequestVerifier\";\nimport {\n type ActiveOrganizationDataRuntime,\n isOrganizationDataRuntimeCurrent,\n} from \"./organizationWorkflowRuntime\";\n\n/**\n * Run one read-model pass for the scope, then present what it applied: access\n * recovery when the pass restored a server-denied scope, group names, and\n * verified leave requests. A superseded pass resolves without a result.\n */\nexport function presentOrganizationReadModelPass(\n runtimeService: InternalRuntime,\n active: ActiveOrganizationDataRuntime,\n pass: () => Promise<OrganizationDirectoryAndGroups | null | undefined>,\n passIsCurrent: () => boolean = () => true,\n): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n // Snapshot the server-denied flag before reconciling. A reconcile that\n // flips it back to readable means org access was just restored (e.g. the\n // user was re-added to a group), and any write lanes idled by\n // permission-denied submissions have no self re-arm — regaining access is\n // their retry signal, mirroring how billing recovery re-requests all\n // lanes. Only a genuine server denial counts: a local session reset also\n // marks scopes denied, and re-arming on its first reconcile would race the\n // startup sync passes (e.g. pending-create adoption between panes).\n const accessWasDenied = wasOrganizationPresentationAccessDeniedByServer(\n {\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n requesterUserId: active.userId,\n },\n \"readModel\",\n );\n const domainScope = active.runtime.state.domainScope;\n const stillCurrent = () =>\n isOrganizationDataRuntimeCurrent(runtimeService, active, domainScope) &&\n passIsCurrent();\n\n const obsolete = () =>\n runtimeService.workflowInput().state.domainScope === domainScope\n ? null\n : undefined;\n return pass().then(async (directoryAndGroups) => {\n if (!stillCurrent()) return obsolete();\n // Feed success restores retry eligibility even if name decryption fails.\n const accessWasRestored =\n accessWasDenied &&\n directoryAndGroups !== null &&\n directoryAndGroups !== undefined;\n if (accessWasRestored)\n await recoverOrganizationAccess({\n domainScope,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n stillCurrent,\n userId: active.userId,\n });\n if (!stillCurrent()) return obsolete();\n const presented = await withVerifiedLeaveRequests(\n await hydrateOrganizationGroupNamesForRuntime(\n runtimeService,\n active,\n domainScope,\n directoryAndGroups,\n ),\n leaveRequestVerifier(runtimeService, active.runtime, active),\n );\n // A transition during presentation publishes nothing for the old scope.\n return stillCurrent() ? presented : obsolete();\n });\n}\n"]}
|
|
@@ -75,23 +75,21 @@ class OrganizationReadModelCoordinatorImpl {
|
|
|
75
75
|
if (!active || groupId.length === 0) {
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
|
-
const domainScope = active.runtime.state.domainScope;
|
|
79
78
|
return loadBoundedOrganizationGroupHistory({
|
|
80
79
|
active,
|
|
81
80
|
groupId,
|
|
82
81
|
beforeVersion,
|
|
83
|
-
stillCurrent: () => isOrganizationDataRuntimeCurrent(this.runtimeService, active
|
|
82
|
+
stillCurrent: () => isOrganizationDataRuntimeCurrent(this.runtimeService, active),
|
|
84
83
|
});
|
|
85
84
|
}
|
|
86
85
|
async loadOrganizationPolicyHistory(organizationId, beforeVersion) {
|
|
87
86
|
const active = activeOrganizationDataRuntime(this.runtimeService, organizationId);
|
|
88
87
|
if (!active)
|
|
89
88
|
return null;
|
|
90
|
-
const domainScope = active.runtime.state.domainScope;
|
|
91
89
|
return loadBoundedOrganizationHistory({
|
|
92
90
|
active,
|
|
93
91
|
beforeVersion,
|
|
94
|
-
stillCurrent: () => isOrganizationDataRuntimeCurrent(this.runtimeService, active
|
|
92
|
+
stillCurrent: () => isOrganizationDataRuntimeCurrent(this.runtimeService, active),
|
|
95
93
|
});
|
|
96
94
|
}
|
|
97
95
|
async loadLocalUserDetail(userId, organizationId) {
|
|
@@ -126,6 +124,7 @@ class OrganizationReadModelCoordinatorImpl {
|
|
|
126
124
|
execSql: active.runtime.infra.execSql,
|
|
127
125
|
logError: active.runtime.util.logError,
|
|
128
126
|
organizationId: active.organizationId,
|
|
127
|
+
stillCurrent: () => isOrganizationDataRuntimeCurrent(this.runtimeService, active),
|
|
129
128
|
}));
|
|
130
129
|
}
|
|
131
130
|
/** Run one projection pass for the scope, then present what it applied. */
|
|
@@ -163,7 +162,9 @@ class OrganizationReadModelCoordinatorImpl {
|
|
|
163
162
|
return undefined;
|
|
164
163
|
}
|
|
165
164
|
await this.settleInFlightReconcile(active);
|
|
166
|
-
return this.
|
|
165
|
+
return isOrganizationDataRuntimeCurrent(this.runtimeService, active)
|
|
166
|
+
? this.reconcile(active.organizationId)
|
|
167
|
+
: undefined;
|
|
167
168
|
}
|
|
168
169
|
async applyCommittedReadModel(organizationId, delta) {
|
|
169
170
|
const active = activeOrganizationDataRuntime(this.runtimeService, organizationId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModels.js","sourceRoot":"","sources":["organizationReadModels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,mDAAmD,CAAC;AAGxG,OAAO,EACL,mCAAmC,EACnC,6BAA6B,EAG7B,4BAA4B,EAC5B,mCAAmC,EACnC,oCAAoC,EACpC,uCAAuC,EACvC,oCAAoC,EACpC,iCAAiC,EACjC,+BAA+B,EAE/B,uCAAuC,EACvC,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,6EAA6E,CAAC;AAEzH,OAAO,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AACj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WAAW,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { organizationReadModelCursorPosition } from \"@tearleads/validators/organizationReadModelCursor\";\nimport type { OrganizationReadModelDeltaResponse } from \"@tearleads/validators/response\";\nimport type { DomainScope } from \"../../data/shared/domainScope\";\nimport {\n applyCommittedOrganizationReadModel,\n awaitCommittedReadModelOffers,\n type CommittedReadModelOffer,\n type CommittedReadModelOutcome,\n claimCommittedReadModelOffer,\n loadHeldOrganizationReadModelCursor,\n loadLocalOrganizationContainerGrants,\n loadLocalOrganizationDirectoryAndGroups,\n loadLocalOrganizationGroupContainers,\n loadLocalOrganizationGroupMembers,\n loadLocalOrganizationUserDetail,\n type OrganizationDirectoryAndGroups,\n reconcileOrganizationDirectoryAndGroups,\n withVerifiedLeaveRequests,\n withVerifiedUserLeaveRequest,\n} from \"../../workflows/organizations\";\nimport { organizationAccessScopeKey } from \"../../workflows/organizations/readModel/organizationPresentationAccessState\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { loadBoundedOrganizationGroupHistory } from \"./organizationGroupHistory\";\nimport { loadBoundedOrganizationHistory } from \"./organizationHistory\";\nimport { leaveRequestVerifier } from \"./organizationLeaveRequestVerifier\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModelCoordinator\";\n\nexport type { OrganizationReadModelCoordinator } from \"./organizationReadModelCoordinator\";\n\nimport { presentOrganizationReadModelPass } from \"./organizationReadModelPresentation\";\nimport {\n committedScope,\n type InFlightReadModelPass,\n presentedAppliedCursor,\n scopedMap,\n sessionIsCurrent,\n} from \"./organizationReadModelScopes\";\nimport {\n type ActiveOrganizationDataRuntime,\n activeOrganizationDataRuntime,\n isOrganizationDataRuntimeCurrent,\n} from \"./organizationWorkflowRuntime\";\n\nconst coordinatorsByRuntime = new WeakMap<\n InternalRuntime,\n OrganizationReadModelCoordinator\n>();\n\nclass OrganizationReadModelCoordinatorImpl\n implements OrganizationReadModelCoordinator\n{\n // The pass in flight per requester: a feed read, or a committed delta's\n // local apply, which a feed refresh waits out instead of joining.\n private readonly reconciliationsByScope = new WeakMap<\n DomainScope,\n Map<string, InFlightReadModelPass>\n >();\n // The cursor each requester's last reconcile fully presented: applied,\n // group names hydrated and leave requests verified. A stored cursor whose\n // presentation work failed does not count as applied, so the next hint\n // reconciles and retries that work.\n private readonly presentedCursorsByScope = new WeakMap<\n DomainScope,\n Map<string, string>\n >();\n constructor(private readonly runtimeService: InternalRuntime) {}\n\n private reconciliationMap(active: ActiveOrganizationDataRuntime) {\n return scopedMap(this.reconciliationsByScope, active);\n }\n\n async loadLocal(organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) {\n return null;\n }\n return withVerifiedLeaveRequests(\n await loadLocalOrganizationDirectoryAndGroups({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n }),\n leaveRequestVerifier(this.runtimeService, active.runtime, active),\n );\n }\n\n async loadLocalGrants(organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) {\n return null;\n }\n return loadLocalOrganizationContainerGrants({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n });\n }\n\n async loadLocalGroupContainers(groupId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n return loadLocalOrganizationGroupContainers({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n groupId,\n organizationId: active.organizationId,\n });\n }\n\n async loadLocalGroupMembers(groupId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n return loadLocalOrganizationGroupMembers({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n groupId,\n organizationId: active.organizationId,\n });\n }\n\n async loadGroupPolicyHistory(\n groupId: string,\n organizationId?: string,\n beforeVersion?: number,\n ) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n const domainScope = active.runtime.state.domainScope;\n return loadBoundedOrganizationGroupHistory({\n active,\n groupId,\n beforeVersion,\n stillCurrent: () =>\n isOrganizationDataRuntimeCurrent(\n this.runtimeService,\n active,\n domainScope,\n ),\n });\n }\n\n async loadOrganizationPolicyHistory(\n organizationId?: string,\n beforeVersion?: number,\n ) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) return null;\n const domainScope = active.runtime.state.domainScope;\n return loadBoundedOrganizationHistory({\n active,\n beforeVersion,\n stillCurrent: () =>\n isOrganizationDataRuntimeCurrent(\n this.runtimeService,\n active,\n domainScope,\n ),\n });\n }\n\n async loadLocalUserDetail(userId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || userId.length === 0) {\n return null;\n }\n return withVerifiedUserLeaveRequest(\n await loadLocalOrganizationUserDetail({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n userId,\n }),\n active.organizationId,\n leaveRequestVerifier(this.runtimeService, active.runtime, active),\n );\n }\n\n reconcile(\n organizationId?: string,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active?.runtime.state.online) {\n return Promise.resolve(undefined);\n }\n const inFlight = this.reconciliationMap(active).get(\n organizationAccessScopeKey(active.organizationId, active.userId),\n );\n // A delta's apply reflects its commit, not this request: read after it,\n // for this scope only.\n if (inFlight?.kind === \"delta\") {\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n );\n return inFlight.promise\n .catch(() => null)\n .then(() =>\n stillCurrent() ? this.reconcile(active.organizationId) : null,\n );\n }\n return this.presentReconciliation(active, \"feed\", () =>\n reconcileOrganizationDirectoryAndGroups({\n apiClient: active.runtime.apiClient,\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n logError: active.runtime.util.logError,\n organizationId: active.organizationId,\n }),\n );\n }\n\n /** Run one projection pass for the scope, then present what it applied. */\n private presentReconciliation(\n active: ActiveOrganizationDataRuntime,\n kind: InFlightReadModelPass[\"kind\"],\n pass: () => Promise<OrganizationDirectoryAndGroups | null | undefined>,\n passIsCurrent?: () => boolean,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const byKey = this.reconciliationMap(active);\n const key = organizationAccessScopeKey(\n active.organizationId,\n active.userId,\n );\n const existing = byKey.get(key);\n if (existing) {\n return existing.promise;\n }\n const presentedCursors = scopedMap(this.presentedCursorsByScope, active);\n\n const reconciliation = presentOrganizationReadModelPass(\n this.runtimeService,\n active,\n pass,\n passIsCurrent,\n )\n .then(\n (presented) => {\n if (presented) presentedCursors.set(key, presented.readModelCursor);\n // A delta that did not apply leaves what was presented standing.\n else if (kind === \"feed\") presentedCursors.delete(key);\n return presented;\n },\n (error: unknown) => {\n presentedCursors.delete(key);\n throw error;\n },\n )\n .finally(() => {\n if (byKey.get(key)?.promise === reconciliation) {\n byKey.delete(key);\n }\n });\n byKey.set(key, { kind, promise: reconciliation });\n return reconciliation;\n }\n\n async reconcileAfterMutation(\n organizationId?: string,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active?.runtime.state.online) {\n return undefined;\n }\n await this.settleInFlightReconcile(active);\n return this.reconcile(active.organizationId);\n }\n\n async applyCommittedReadModel(\n organizationId: string,\n delta: OrganizationReadModelDeltaResponse | undefined,\n ): Promise<CommittedReadModelOutcome> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || !delta) return undefined;\n const { sessionGeneration } = this.runtimeService;\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n // A hint's cursor check may have claimed this delta first; share its apply.\n const outcome = await claimCommittedReadModelOffer(\n committedScope(active, sessionGeneration),\n delta,\n (offer) => this.applyClaimedOffer(active, offer, sessionGeneration),\n );\n if (!stillCurrent()) return undefined;\n if (!outcome) return outcome;\n // An apply that finished earlier stands only while nothing replaced it: a\n // later feed pass or purge leaves the caller to read instead. The mutation\n // already committed, so a failed check is only a missed delta.\n const presented = await presentedAppliedCursor(\n active,\n scopedMap(this.presentedCursorsByScope, active),\n ).catch(() => null);\n return stillCurrent() && presented === outcome.readModelCursor\n ? outcome\n : undefined;\n }\n\n private async applyClaimedOffer(\n active: ActiveOrganizationDataRuntime,\n offer: CommittedReadModelOffer,\n sessionGeneration: number,\n ): Promise<CommittedReadModelOutcome> {\n // Distinct offers apply one after another: each waits out every pass in\n // flight, so none joins another's apply and is consumed unapplied.\n const key = organizationAccessScopeKey(\n active.organizationId,\n active.userId,\n );\n while (this.reconciliationMap(active).has(key))\n await this.settleInFlightReconcile(active);\n return this.applyCommittedOffer(active, offer, sessionGeneration);\n }\n\n /**\n * Present an offer while the projection holds its sent cursor and the scope\n * and session are the ones that waited; a failure only forgoes it.\n */\n private applyCommittedOffer(\n active: ActiveOrganizationDataRuntime,\n offer: CommittedReadModelOffer,\n sessionGeneration: number,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n return this.presentReconciliation(\n active,\n \"delta\",\n async () => {\n const held = await loadHeldOrganizationReadModelCursor(\n committedScope(active, sessionGeneration),\n );\n if (held !== offer.heldCursor || !stillCurrent()) return undefined;\n return applyCommittedOrganizationReadModel({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n logError: active.runtime.util.logError,\n organizationId: active.organizationId,\n requestedCursor: offer.heldCursor,\n response: offer.delta,\n stillCurrent,\n });\n },\n stillCurrent,\n ).catch((error: unknown) => {\n active.runtime.util.logError(\n \"Failed to apply a committed organization read-model delta\",\n error,\n );\n return undefined;\n });\n }\n\n sessionGuard(organizationId?: string): () => boolean {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n return active\n ? sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n )\n : () => false;\n }\n\n async reconcileAfterOwnMutation(\n organizationId: string,\n delta: OrganizationReadModelDeltaResponse | undefined,\n startedIn: () => boolean = () => true,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || !startedIn()) return undefined;\n const current = sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n );\n const stillCurrent = () => current() && startedIn();\n const applied = await this.applyCommittedReadModel(organizationId, delta);\n if (applied) return applied;\n // The fallback reads for the session that committed, or not at all.\n await this.settleInFlightReconcile(active);\n return stillCurrent() ? this.reconcile(active.organizationId) : undefined;\n }\n\n async loadAppliedCursor(\n hintPosition?: bigint,\n organizationId?: string,\n ): Promise<string | null> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) return null;\n // The check belongs to the session it started in, before any await.\n const { sessionGeneration } = this.runtimeService;\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n const presentedCursors = scopedMap(this.presentedCursorsByScope, active);\n // A hint the presentation already covers waits for nothing.\n const presented = await presentedAppliedCursor(active, presentedCursors);\n if (!stillCurrent()) return null;\n if (\n hintPosition !== undefined &&\n presented !== null &&\n (organizationReadModelCursorPosition(presented, active.organizationId) ??\n -1n) >= hintPosition\n )\n return presented;\n // Otherwise this scope's own mutations that could be the hint's commit\n // settle first, and the deltas they carried apply, so a hint naming one of\n // those commits needs no read.\n const scope = committedScope(active, sessionGeneration);\n for (const offer of await awaitCommittedReadModelOffers(\n scope,\n hintPosition,\n )) {\n if (!stillCurrent()) return null;\n await claimCommittedReadModelOffer(scope, offer.delta, (claimed) =>\n this.applyClaimedOffer(active, claimed, sessionGeneration),\n );\n }\n await this.settleInFlightReconcile(active);\n const applied = await presentedAppliedCursor(active, presentedCursors);\n // A replacement session's cursor never answers this session's hint.\n return stillCurrent() ? applied : null;\n }\n\n private async settleInFlightReconcile(\n active: ActiveOrganizationDataRuntime,\n ): Promise<void> {\n await this.reconciliationMap(active)\n .get(organizationAccessScopeKey(active.organizationId, active.userId))\n ?.promise.catch(() => null);\n }\n}\n\nexport function createOrganizationReadModelCoordinator(\n runtimeService: InternalRuntime,\n): OrganizationReadModelCoordinator {\n const existing = coordinatorsByRuntime.get(runtimeService);\n if (existing) {\n return existing;\n }\n\n const coordinator = new OrganizationReadModelCoordinatorImpl(runtimeService);\n coordinatorsByRuntime.set(runtimeService, coordinator);\n return coordinator;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organizationReadModels.js","sourceRoot":"","sources":["organizationReadModels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,mDAAmD,CAAC;AAGxG,OAAO,EACL,mCAAmC,EACnC,6BAA6B,EAG7B,4BAA4B,EAC5B,mCAAmC,EACnC,oCAAoC,EACpC,uCAAuC,EACvC,oCAAoC,EACpC,iCAAiC,EACjC,+BAA+B,EAE/B,uCAAuC,EACvC,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,6EAA6E,CAAC;AAEzH,OAAO,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAK1E,OAAO,EAAE,gCAAgC,EAAE,MAAM,qCAAqC,CAAC;AACvF,OAAO,EACL,cAAc,EAEd,sBAAsB,EACtB,SAAS,EACT,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EA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AI,CAAC;YACjC,MAAM,4BAA4B,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CACjE,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAC3D,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACvE,oEAAoE;QACpE,OAAO,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACnC,MAAqC;QAErC,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;aACjC,GAAG,CAAC,0BAA0B,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YACtE,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AAED,MAAM,UAAU,sCAAsC,CACpD,cAA+B;IAE/B,MAAM,QAAQ,GAAG,qBAAqB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC3D,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,oCAAoC,CAAC,cAAc,CAAC,CAAC;IAC7E,qBAAqB,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { organizationReadModelCursorPosition } from \"@tearleads/validators/organizationReadModelCursor\";\nimport type { OrganizationReadModelDeltaResponse } from \"@tearleads/validators/response\";\nimport type { DomainScope } from \"../../data/shared/domainScope\";\nimport {\n applyCommittedOrganizationReadModel,\n awaitCommittedReadModelOffers,\n type CommittedReadModelOffer,\n type CommittedReadModelOutcome,\n claimCommittedReadModelOffer,\n loadHeldOrganizationReadModelCursor,\n loadLocalOrganizationContainerGrants,\n loadLocalOrganizationDirectoryAndGroups,\n loadLocalOrganizationGroupContainers,\n loadLocalOrganizationGroupMembers,\n loadLocalOrganizationUserDetail,\n type OrganizationDirectoryAndGroups,\n reconcileOrganizationDirectoryAndGroups,\n withVerifiedLeaveRequests,\n withVerifiedUserLeaveRequest,\n} from \"../../workflows/organizations\";\nimport { organizationAccessScopeKey } from \"../../workflows/organizations/readModel/organizationPresentationAccessState\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\nimport { loadBoundedOrganizationGroupHistory } from \"./organizationGroupHistory\";\nimport { loadBoundedOrganizationHistory } from \"./organizationHistory\";\nimport { leaveRequestVerifier } from \"./organizationLeaveRequestVerifier\";\nimport type { OrganizationReadModelCoordinator } from \"./organizationReadModelCoordinator\";\n\nexport type { OrganizationReadModelCoordinator } from \"./organizationReadModelCoordinator\";\n\nimport { presentOrganizationReadModelPass } from \"./organizationReadModelPresentation\";\nimport {\n committedScope,\n type InFlightReadModelPass,\n presentedAppliedCursor,\n scopedMap,\n sessionIsCurrent,\n} from \"./organizationReadModelScopes\";\nimport {\n type ActiveOrganizationDataRuntime,\n activeOrganizationDataRuntime,\n isOrganizationDataRuntimeCurrent,\n} from \"./organizationWorkflowRuntime\";\n\nconst coordinatorsByRuntime = new WeakMap<\n InternalRuntime,\n OrganizationReadModelCoordinator\n>();\n\nclass OrganizationReadModelCoordinatorImpl\n implements OrganizationReadModelCoordinator\n{\n // The pass in flight per requester: a feed read, or a committed delta's\n // local apply, which a feed refresh waits out instead of joining.\n private readonly reconciliationsByScope = new WeakMap<\n DomainScope,\n Map<string, InFlightReadModelPass>\n >();\n // The cursor each requester's last reconcile fully presented: applied,\n // group names hydrated and leave requests verified. A stored cursor whose\n // presentation work failed does not count as applied, so the next hint\n // reconciles and retries that work.\n private readonly presentedCursorsByScope = new WeakMap<\n DomainScope,\n Map<string, string>\n >();\n constructor(private readonly runtimeService: InternalRuntime) {}\n\n private reconciliationMap(active: ActiveOrganizationDataRuntime) {\n return scopedMap(this.reconciliationsByScope, active);\n }\n\n async loadLocal(organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) {\n return null;\n }\n return withVerifiedLeaveRequests(\n await loadLocalOrganizationDirectoryAndGroups({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n }),\n leaveRequestVerifier(this.runtimeService, active.runtime, active),\n );\n }\n\n async loadLocalGrants(organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) {\n return null;\n }\n return loadLocalOrganizationContainerGrants({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n });\n }\n\n async loadLocalGroupContainers(groupId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n return loadLocalOrganizationGroupContainers({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n groupId,\n organizationId: active.organizationId,\n });\n }\n\n async loadLocalGroupMembers(groupId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n return loadLocalOrganizationGroupMembers({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n groupId,\n organizationId: active.organizationId,\n });\n }\n\n async loadGroupPolicyHistory(\n groupId: string,\n organizationId?: string,\n beforeVersion?: number,\n ) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || groupId.length === 0) {\n return null;\n }\n return loadBoundedOrganizationGroupHistory({\n active,\n groupId,\n beforeVersion,\n stillCurrent: () =>\n isOrganizationDataRuntimeCurrent(this.runtimeService, active),\n });\n }\n\n async loadOrganizationPolicyHistory(\n organizationId?: string,\n beforeVersion?: number,\n ) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) return null;\n return loadBoundedOrganizationHistory({\n active,\n beforeVersion,\n stillCurrent: () =>\n isOrganizationDataRuntimeCurrent(this.runtimeService, active),\n });\n }\n\n async loadLocalUserDetail(userId: string, organizationId?: string) {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || userId.length === 0) {\n return null;\n }\n return withVerifiedUserLeaveRequest(\n await loadLocalOrganizationUserDetail({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n organizationId: active.organizationId,\n userId,\n }),\n active.organizationId,\n leaveRequestVerifier(this.runtimeService, active.runtime, active),\n );\n }\n\n reconcile(\n organizationId?: string,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active?.runtime.state.online) {\n return Promise.resolve(undefined);\n }\n const inFlight = this.reconciliationMap(active).get(\n organizationAccessScopeKey(active.organizationId, active.userId),\n );\n // A delta's apply reflects its commit, not this request: read after it,\n // for this scope only.\n if (inFlight?.kind === \"delta\") {\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n );\n return inFlight.promise\n .catch(() => null)\n .then(() =>\n stillCurrent() ? this.reconcile(active.organizationId) : null,\n );\n }\n return this.presentReconciliation(active, \"feed\", () =>\n reconcileOrganizationDirectoryAndGroups({\n apiClient: active.runtime.apiClient,\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n logError: active.runtime.util.logError,\n organizationId: active.organizationId,\n stillCurrent: () =>\n isOrganizationDataRuntimeCurrent(this.runtimeService, active),\n }),\n );\n }\n\n /** Run one projection pass for the scope, then present what it applied. */\n private presentReconciliation(\n active: ActiveOrganizationDataRuntime,\n kind: InFlightReadModelPass[\"kind\"],\n pass: () => Promise<OrganizationDirectoryAndGroups | null | undefined>,\n passIsCurrent?: () => boolean,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const byKey = this.reconciliationMap(active);\n const key = organizationAccessScopeKey(\n active.organizationId,\n active.userId,\n );\n const existing = byKey.get(key);\n if (existing) {\n return existing.promise;\n }\n const presentedCursors = scopedMap(this.presentedCursorsByScope, active);\n\n const reconciliation = presentOrganizationReadModelPass(\n this.runtimeService,\n active,\n pass,\n passIsCurrent,\n )\n .then(\n (presented) => {\n if (presented) presentedCursors.set(key, presented.readModelCursor);\n // A delta that did not apply leaves what was presented standing.\n else if (kind === \"feed\") presentedCursors.delete(key);\n return presented;\n },\n (error: unknown) => {\n presentedCursors.delete(key);\n throw error;\n },\n )\n .finally(() => {\n if (byKey.get(key)?.promise === reconciliation) {\n byKey.delete(key);\n }\n });\n byKey.set(key, { kind, promise: reconciliation });\n return reconciliation;\n }\n\n async reconcileAfterMutation(\n organizationId?: string,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active?.runtime.state.online) {\n return undefined;\n }\n await this.settleInFlightReconcile(active);\n return isOrganizationDataRuntimeCurrent(this.runtimeService, active)\n ? this.reconcile(active.organizationId)\n : undefined;\n }\n\n async applyCommittedReadModel(\n organizationId: string,\n delta: OrganizationReadModelDeltaResponse | undefined,\n ): Promise<CommittedReadModelOutcome> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || !delta) return undefined;\n const { sessionGeneration } = this.runtimeService;\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n // A hint's cursor check may have claimed this delta first; share its apply.\n const outcome = await claimCommittedReadModelOffer(\n committedScope(active, sessionGeneration),\n delta,\n (offer) => this.applyClaimedOffer(active, offer, sessionGeneration),\n );\n if (!stillCurrent()) return undefined;\n if (!outcome) return outcome;\n // An apply that finished earlier stands only while nothing replaced it: a\n // later feed pass or purge leaves the caller to read instead. The mutation\n // already committed, so a failed check is only a missed delta.\n const presented = await presentedAppliedCursor(\n active,\n scopedMap(this.presentedCursorsByScope, active),\n ).catch(() => null);\n return stillCurrent() && presented === outcome.readModelCursor\n ? outcome\n : undefined;\n }\n\n private async applyClaimedOffer(\n active: ActiveOrganizationDataRuntime,\n offer: CommittedReadModelOffer,\n sessionGeneration: number,\n ): Promise<CommittedReadModelOutcome> {\n // Distinct offers apply one after another: each waits out every pass in\n // flight, so none joins another's apply and is consumed unapplied.\n const key = organizationAccessScopeKey(\n active.organizationId,\n active.userId,\n );\n while (this.reconciliationMap(active).has(key))\n await this.settleInFlightReconcile(active);\n return this.applyCommittedOffer(active, offer, sessionGeneration);\n }\n\n /**\n * Present an offer while the projection holds its sent cursor and the scope\n * and session are the ones that waited; a failure only forgoes it.\n */\n private applyCommittedOffer(\n active: ActiveOrganizationDataRuntime,\n offer: CommittedReadModelOffer,\n sessionGeneration: number,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n return this.presentReconciliation(\n active,\n \"delta\",\n async () => {\n const held = await loadHeldOrganizationReadModelCursor(\n committedScope(active, sessionGeneration),\n );\n if (held !== offer.heldCursor || !stillCurrent()) return undefined;\n return applyCommittedOrganizationReadModel({\n currentUserId: active.userId,\n execSql: active.runtime.infra.execSql,\n logError: active.runtime.util.logError,\n organizationId: active.organizationId,\n requestedCursor: offer.heldCursor,\n response: offer.delta,\n stillCurrent,\n });\n },\n stillCurrent,\n ).catch((error: unknown) => {\n active.runtime.util.logError(\n \"Failed to apply a committed organization read-model delta\",\n error,\n );\n return undefined;\n });\n }\n\n sessionGuard(organizationId?: string): () => boolean {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n return active\n ? sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n )\n : () => false;\n }\n\n async reconcileAfterOwnMutation(\n organizationId: string,\n delta: OrganizationReadModelDeltaResponse | undefined,\n startedIn: () => boolean = () => true,\n ): Promise<OrganizationDirectoryAndGroups | null | undefined> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active || !startedIn()) return undefined;\n const current = sessionIsCurrent(\n this.runtimeService,\n active,\n this.runtimeService.sessionGeneration,\n );\n const stillCurrent = () => current() && startedIn();\n const applied = await this.applyCommittedReadModel(organizationId, delta);\n if (applied) return applied;\n // The fallback reads for the session that committed, or not at all.\n await this.settleInFlightReconcile(active);\n return stillCurrent() ? this.reconcile(active.organizationId) : undefined;\n }\n\n async loadAppliedCursor(\n hintPosition?: bigint,\n organizationId?: string,\n ): Promise<string | null> {\n const active = activeOrganizationDataRuntime(\n this.runtimeService,\n organizationId,\n );\n if (!active) return null;\n // The check belongs to the session it started in, before any await.\n const { sessionGeneration } = this.runtimeService;\n const stillCurrent = sessionIsCurrent(\n this.runtimeService,\n active,\n sessionGeneration,\n );\n const presentedCursors = scopedMap(this.presentedCursorsByScope, active);\n // A hint the presentation already covers waits for nothing.\n const presented = await presentedAppliedCursor(active, presentedCursors);\n if (!stillCurrent()) return null;\n if (\n hintPosition !== undefined &&\n presented !== null &&\n (organizationReadModelCursorPosition(presented, active.organizationId) ??\n -1n) >= hintPosition\n )\n return presented;\n // Otherwise this scope's own mutations that could be the hint's commit\n // settle first, and the deltas they carried apply, so a hint naming one of\n // those commits needs no read.\n const scope = committedScope(active, sessionGeneration);\n for (const offer of await awaitCommittedReadModelOffers(\n scope,\n hintPosition,\n )) {\n if (!stillCurrent()) return null;\n await claimCommittedReadModelOffer(scope, offer.delta, (claimed) =>\n this.applyClaimedOffer(active, claimed, sessionGeneration),\n );\n }\n await this.settleInFlightReconcile(active);\n const applied = await presentedAppliedCursor(active, presentedCursors);\n // A replacement session's cursor never answers this session's hint.\n return stillCurrent() ? applied : null;\n }\n\n private async settleInFlightReconcile(\n active: ActiveOrganizationDataRuntime,\n ): Promise<void> {\n await this.reconciliationMap(active)\n .get(organizationAccessScopeKey(active.organizationId, active.userId))\n ?.promise.catch(() => null);\n }\n}\n\nexport function createOrganizationReadModelCoordinator(\n runtimeService: InternalRuntime,\n): OrganizationReadModelCoordinator {\n const existing = coordinatorsByRuntime.get(runtimeService);\n if (existing) {\n return existing;\n }\n\n const coordinator = new OrganizationReadModelCoordinatorImpl(runtimeService);\n coordinatorsByRuntime.set(runtimeService, coordinator);\n return coordinator;\n}\n"]}
|
|
@@ -28,7 +28,7 @@ export function activeOrganizationDataRuntime(runtimeService, expectedOrganizati
|
|
|
28
28
|
}
|
|
29
29
|
return { runtime, organizationId, userId };
|
|
30
30
|
}
|
|
31
|
-
export function isOrganizationDataRuntimeCurrent(runtimeService, active, domainScope) {
|
|
31
|
+
export function isOrganizationDataRuntimeCurrent(runtimeService, active, domainScope = active.runtime.state.domainScope) {
|
|
32
32
|
const current = activeOrganizationDataRuntime(runtimeService, active.organizationId);
|
|
33
33
|
return (current?.userId === active.userId &&
|
|
34
34
|
current.runtime.infra.execSql === active.runtime.infra.execSql &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationWorkflowRuntime.js","sourceRoot":"","sources":["organizationWorkflowRuntime.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,2BAA2B,CACzC,OAAqC;IAErC,OAAO,OAAO,CAAC,IAAI,CAAC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,eAAe;QAChE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc;QAC7B,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,cAA+B,EAC/B,QAAiC,EACjC,oBAA6B;IAE7B,MAAM,OAAO,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAC/C,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAClE,MAAM,cAAc,GAClB,oBAAoB,KAAK,SAAS;QAChC,CAAC,CAAC,oBAAoB;QACtB,CAAC,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,MAAM;QACjC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QAC9D,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,KAAK,WAAW,CAClD,CAAC;AACJ,CAAC","sourcesContent":["import type { DomainScope } from \"../../data/shared/domainScope\";\nimport type {\n InternalRuntime,\n InternalWorkflowRuntimeInput,\n} from \"../runtime/workflowRuntime\";\n\ntype OrganizationWorkflow<T> = (input: {\n readonly apiClient: InternalWorkflowRuntimeInput[\"apiClient\"];\n readonly organizationId: string;\n}) => Promise<T>;\n\nexport function authenticatedOrganizationId(\n runtime: InternalWorkflowRuntimeInput,\n): string | null {\n return runtime.auth.organizationId && runtime.auth.isAuthenticated\n ? runtime.auth.organizationId\n : null;\n}\n\nexport function runForOrganization<T>(\n runtimeService: InternalRuntime,\n workflow: OrganizationWorkflow<T>,\n targetOrganizationId?: string,\n): Promise<T | null> {\n const runtime = runtimeService.workflowInput();\n const activeOrganizationId = authenticatedOrganizationId(runtime);\n const organizationId =\n targetOrganizationId === undefined\n ? activeOrganizationId\n : targetOrganizationId;\n if (!activeOrganizationId || !organizationId) {\n return Promise.resolve(null);\n }\n\n return workflow({ apiClient: runtime.apiClient, organizationId });\n}\n\nexport interface ActiveOrganizationDataRuntime {\n readonly runtime: InternalWorkflowRuntimeInput;\n readonly organizationId: string;\n readonly userId: string;\n}\n\nexport function activeOrganizationDataRuntime(\n runtimeService: InternalRuntime,\n expectedOrganizationId?: string,\n): ActiveOrganizationDataRuntime | null {\n const runtime = runtimeService.workflowInput();\n const organizationId = runtime.auth.organizationId;\n const userId = runtime.auth.userId;\n if (\n !runtime.auth.isAuthenticated ||\n !organizationId ||\n !userId ||\n runtime.infra.dbStatus !== \"ready\" ||\n (expectedOrganizationId !== undefined &&\n organizationId !== expectedOrganizationId)\n ) {\n return null;\n }\n\n return { runtime, organizationId, userId };\n}\n\nexport function isOrganizationDataRuntimeCurrent(\n runtimeService: InternalRuntime,\n active: ActiveOrganizationDataRuntime,\n domainScope: DomainScope = active.runtime.state.domainScope,\n): boolean {\n const current = activeOrganizationDataRuntime(\n runtimeService,\n active.organizationId,\n );\n return (\n current?.userId === active.userId &&\n current.runtime.infra.execSql === active.runtime.infra.execSql &&\n current.runtime.state.domainScope === domainScope\n );\n}\n"]}
|
|
@@ -16,6 +16,10 @@ interface PrincipalMutationApiCustodyInput {
|
|
|
16
16
|
readonly api: ApiClient;
|
|
17
17
|
/** Binds a mutation's committed read-model lease to its session. */
|
|
18
18
|
readonly readSessionGeneration?: (() => number) | undefined;
|
|
19
|
+
readonly signIn?: {
|
|
20
|
+
readonly epoch: number;
|
|
21
|
+
guard(): () => void;
|
|
22
|
+
};
|
|
19
23
|
readonly readScope: () => PrincipalMutationRuntimeScope | null;
|
|
20
24
|
readonly principalMutationTimeoutMs?: number | undefined;
|
|
21
25
|
}
|
|
@@ -37,7 +37,8 @@ export function createPrincipalMutationApiCustody(input) {
|
|
|
37
37
|
return {
|
|
38
38
|
bind() {
|
|
39
39
|
const scope = input.readScope();
|
|
40
|
-
|
|
40
|
+
const epoch = input.signIn?.epoch;
|
|
41
|
+
if (cached && epoch === cached.epoch && sameScope(scope, cached.scope))
|
|
41
42
|
return cached.api;
|
|
42
43
|
const context = (organizationId) => mutationContext(input, scope, organizationId);
|
|
43
44
|
const read = async (organizationId) => scope
|
|
@@ -64,13 +65,13 @@ export function createPrincipalMutationApiCustody(input) {
|
|
|
64
65
|
});
|
|
65
66
|
},
|
|
66
67
|
};
|
|
67
|
-
const api = bindMutationMethods(input.api, methods);
|
|
68
|
-
cached = { scope, api };
|
|
68
|
+
const api = bindMutationMethods(input.api, methods, input.signIn?.guard());
|
|
69
|
+
cached = { epoch, scope, api };
|
|
69
70
|
return api;
|
|
70
71
|
},
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
function bindMutationMethods(api, methods) {
|
|
74
|
+
function bindMutationMethods(api, methods, assertCurrent) {
|
|
74
75
|
const boundMethods = new Map();
|
|
75
76
|
const bound = new Proxy(api, {
|
|
76
77
|
get(target, property) {
|
|
@@ -82,7 +83,10 @@ function bindMutationMethods(api, methods) {
|
|
|
82
83
|
const previous = boundMethods.get(property);
|
|
83
84
|
if (previous?.source === value)
|
|
84
85
|
return previous.bound;
|
|
85
|
-
const bound =
|
|
86
|
+
const bound = (...args) => {
|
|
87
|
+
assertCurrent?.();
|
|
88
|
+
return Reflect.apply(value, target, args);
|
|
89
|
+
};
|
|
86
90
|
boundMethods.set(property, { source: value, bound });
|
|
87
91
|
return bound;
|
|
88
92
|
},
|