@tearleads/client-sdk 0.1.211 → 0.1.214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/containerContents/documentDiscovery.js +2 -2
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/client/organizations/organizationReadModels.js +3 -3
- package/client/organizations/organizationReadModels.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistence.js +2 -2
- package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js +2 -2
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataPullContinuationPersistence.js +2 -2
- package/data/persistence/container-contents/containerMetadataPullContinuationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerPendingUpdatePersistence.js +6 -6
- package/data/persistence/container-contents/containerPendingUpdatePersistence.js.map +1 -1
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.d.ts +11 -2
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js +89 -77
- package/data/persistence/documents/documentDiscoveryEvidencePersistence.js.map +1 -1
- package/data/persistence/documents/internal/discardDocument.js +4 -4
- package/data/persistence/documents/internal/discardDocument.js.map +1 -1
- package/data/persistence/documents/internal/discoveredDocumentUpsert.js +3 -3
- package/data/persistence/documents/internal/discoveredDocumentUpsert.js.map +1 -1
- package/data/persistence/documents/internal/documentDeletionPersistence.js +8 -8
- package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
- package/data/persistence/documents/internal/documentMutationPersistence.js +4 -3
- package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
- package/data/persistence/documents/internal/documentPullContinuationPersistence.js +2 -2
- package/data/persistence/documents/internal/documentPullContinuationPersistence.js.map +1 -1
- package/data/persistence/documents/internal/rowQueryPersistence.js +3 -3
- package/data/persistence/documents/internal/rowQueryPersistence.js.map +1 -1
- package/data/persistence/documents/internal/syncQueuePersistence.js +12 -13
- package/data/persistence/documents/internal/syncQueuePersistence.js.map +1 -1
- package/data/persistence/documents/records/documentHistoryPersistence.d.ts +24 -20
- package/data/persistence/documents/records/documentHistoryPersistence.js +59 -90
- package/data/persistence/documents/records/documentHistoryPersistence.js.map +1 -1
- package/data/persistence/documents/records/documentPendingUpdatePersistence.d.ts +10 -25
- package/data/persistence/documents/records/documentPendingUpdatePersistence.js +19 -79
- package/data/persistence/documents/records/documentPendingUpdatePersistence.js.map +1 -1
- package/data/persistence/documents/records/documentQueuedUpdateReplacement.d.ts +4 -14
- package/data/persistence/documents/records/documentQueuedUpdateReplacement.js +27 -42
- package/data/persistence/documents/records/documentQueuedUpdateReplacement.js.map +1 -1
- package/data/persistence/documents/records/documentRecordPersistence.d.ts +5 -8
- package/data/persistence/documents/records/documentRecordPersistence.js +2 -55
- package/data/persistence/documents/records/documentRecordPersistence.js.map +1 -1
- package/data/persistence/documents/records/documentRecordRepository.d.ts +133 -0
- package/data/persistence/documents/records/documentRecordRepository.js +286 -0
- package/data/persistence/documents/records/documentRecordRepository.js.map +1 -0
- package/data/persistence/documents/records/documentSyncFailurePersistence.d.ts +9 -12
- package/data/persistence/documents/records/documentSyncFailurePersistence.js +19 -34
- package/data/persistence/documents/records/documentSyncFailurePersistence.js.map +1 -1
- package/data/persistence/documents/records/index.d.ts +4 -19
- package/data/persistence/documents/records/index.js +5 -29
- package/data/persistence/documents/records/index.js.map +1 -1
- package/data/persistence/organizations/organizationPresentationDenialPersistence.js +0 -43
- package/data/persistence/organizations/organizationPresentationDenialPersistence.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelMemberLoad.d.ts +7 -2
- package/data/persistence/organizations/organizationReadModelMemberLoad.js +22 -27
- package/data/persistence/organizations/organizationReadModelMemberLoad.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelPersistence.js +38 -81
- package/data/persistence/organizations/organizationReadModelPersistence.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelPurge.js +0 -38
- package/data/persistence/organizations/organizationReadModelPurge.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelRepository.js +264 -0
- package/data/persistence/organizations/organizationReadModelRepository.js.map +1 -0
- package/package.json +1 -1
- package/stores/documents/documentStore/sync/attachmentUploadFailure.js +2 -2
- package/stores/documents/documentStore/sync/attachmentUploadFailure.js.map +1 -1
- package/stores/documents/documentStore/sync/syncAttachments.js +2 -2
- package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -1
- package/stores/documents/documentStore/sync/syncShared.js +2 -2
- package/stores/documents/documentStore/sync/syncShared.js.map +1 -1
- package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js.map +1 -1
- package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js +2 -2
- package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js.map +1 -1
- package/workflows/container-contents/pendingWrites/index.js +4 -3
- package/workflows/container-contents/pendingWrites/index.js.map +1 -1
- package/workflows/container-contents/recovery/accessRestoration.js +2 -2
- package/workflows/container-contents/recovery/accessRestoration.js.map +1 -1
- package/workflows/documents/index.d.ts +1 -1
- package/workflows/documents/index.js +1 -1
- package/workflows/documents/index.js.map +1 -1
- package/workflows/documents/syncRekeys/syncRecoveryRekey.js +3 -2
- package/workflows/documents/syncRekeys/syncRecoveryRekey.js.map +1 -1
- package/workflows/organizations/groupNames/currentOrganizationGroupNames.js +6 -2
- package/workflows/organizations/groupNames/currentOrganizationGroupNames.js.map +1 -1
- package/workflows/organizations/index.d.ts +0 -1
- package/workflows/organizations/index.js +0 -1
- package/workflows/organizations/index.js.map +1 -1
- package/workflows/organizations/policyHistory/policyHistoryAccessDenial.js +7 -4
- package/workflows/organizations/policyHistory/policyHistoryAccessDenial.js.map +1 -1
- package/workflows/organizations/readModel/dataUsageReadModel.js +2 -2
- package/workflows/organizations/readModel/dataUsageReadModel.js.map +1 -1
- package/workflows/organizations/readModel/listLocalOrganizations.js +6 -4
- package/workflows/organizations/readModel/listLocalOrganizations.js.map +1 -1
- package/workflows/organizations/readModel/localReadModelDetails.js +8 -9
- package/workflows/organizations/readModel/localReadModelDetails.js.map +1 -1
- package/workflows/organizations/readModel/organizationPresentationAccessState.js +2 -2
- package/workflows/organizations/readModel/organizationPresentationAccessState.js.map +1 -1
- package/workflows/organizations/readModel/readModelProjection.d.ts +1 -1
- package/workflows/organizations/readModel/readModelProjection.js +12 -13
- package/workflows/organizations/readModel/readModelProjection.js.map +1 -1
- package/data/persistence/organizations/organizationAccessRevocationPersistence.js +0 -49
- package/data/persistence/organizations/organizationAccessRevocationPersistence.js.map +0 -1
- package/data/persistence/organizations/organizationGroupNamePersistence.js +0 -33
- package/data/persistence/organizations/organizationGroupNamePersistence.js.map +0 -1
- package/data/persistence/organizations/organizationProfileDocumentPointers.js +0 -32
- package/data/persistence/organizations/organizationProfileDocumentPointers.js.map +0 -1
- package/data/persistence/organizations/organizationReadModelCursorPersistence.d.ts +0 -15
- package/data/persistence/organizations/organizationReadModelCursorPersistence.js +0 -25
- package/data/persistence/organizations/organizationReadModelCursorPersistence.js.map +0 -1
|
@@ -1,48 +1,5 @@
|
|
|
1
1
|
import { and, eq } from "drizzle-orm";
|
|
2
2
|
import { organizationPresentationDenials } from "../../sqlite/schema/organizationReadModelSchema.js";
|
|
3
|
-
import { organizationReadModelTables } from "../../sqlite/schema/organizationReadModelTableRegistry.js";
|
|
4
|
-
import { getClientSQLitePersistenceRuntime, } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
5
|
-
import { ensureSqlTables } from "../../sqlite/sqlTableSchema.js";
|
|
6
|
-
/**
|
|
7
|
-
* Durably record a server denial before the revoked projection rows are
|
|
8
|
-
* purged. The marker is what keeps a failed purge plus an offline restart
|
|
9
|
-
* from serving the revoked projection; it is cleared only when an
|
|
10
|
-
* authoritative reconcile stores fresh server state for the same scope.
|
|
11
|
-
*/
|
|
12
|
-
export async function recordOrganizationPresentationDenials(scope, projections) {
|
|
13
|
-
await ensureSqlTables(scope.execSql, organizationReadModelTables);
|
|
14
|
-
const deniedAt = new Date().toISOString();
|
|
15
|
-
await getClientSQLitePersistenceRuntime(scope.execSql).transaction(async (tx) => {
|
|
16
|
-
for (const projection of new Set(projections)) {
|
|
17
|
-
await tx
|
|
18
|
-
.insert(organizationPresentationDenials)
|
|
19
|
-
.values({
|
|
20
|
-
organizationId: scope.organizationId,
|
|
21
|
-
requesterUserId: scope.requesterUserId,
|
|
22
|
-
projection,
|
|
23
|
-
deniedAt,
|
|
24
|
-
})
|
|
25
|
-
.onConflictDoUpdate({
|
|
26
|
-
target: [
|
|
27
|
-
organizationPresentationDenials.organizationId,
|
|
28
|
-
organizationPresentationDenials.requesterUserId,
|
|
29
|
-
organizationPresentationDenials.projection,
|
|
30
|
-
],
|
|
31
|
-
set: { deniedAt },
|
|
32
|
-
})
|
|
33
|
-
.run();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export async function hasOrganizationPresentationDenial(scope, projection) {
|
|
38
|
-
await ensureSqlTables(scope.execSql, organizationReadModelTables);
|
|
39
|
-
const rows = await getClientSQLitePersistenceRuntime(scope.execSql)
|
|
40
|
-
.db.select({ projection: organizationPresentationDenials.projection })
|
|
41
|
-
.from(organizationPresentationDenials)
|
|
42
|
-
.where(and(eq(organizationPresentationDenials.organizationId, scope.organizationId), eq(organizationPresentationDenials.requesterUserId, scope.requesterUserId), eq(organizationPresentationDenials.projection, projection)))
|
|
43
|
-
.limit(1);
|
|
44
|
-
return rows.length > 0;
|
|
45
|
-
}
|
|
46
3
|
export async function clearOrganizationPresentationDenialInTransaction(input) {
|
|
47
4
|
await input.tx
|
|
48
5
|
.delete(organizationPresentationDenials)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationPresentationDenialPersistence.js","sourceRoot":"","sources":["organizationPresentationDenialPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"organizationPresentationDenialPersistence.js","sourceRoot":"","sources":["organizationPresentationDenialPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iDAAiD,CAAC;AAUlG,MAAM,CAAC,KAAK,UAAU,gDAAgD,CAAC,KAKtE;IACC,MAAM,KAAK,CAAC,EAAE;SACX,MAAM,CAAC,+BAA+B,CAAC;SACvC,KAAK,CACJ,GAAG,CACD,EAAE,CACA,+BAA+B,CAAC,cAAc,EAC9C,KAAK,CAAC,cAAc,CACrB,EACD,EAAE,CACA,+BAA+B,CAAC,eAAe,EAC/C,KAAK,CAAC,eAAe,CACtB,EACD,EAAE,CAAC,+BAA+B,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CACjE,CACF;SACA,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { and, eq } from \"drizzle-orm\";\nimport { organizationPresentationDenials } from \"../../sqlite/schema/organizationReadModelSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\n\nexport type OrganizationPresentationDenialProjection = \"readModel\" | \"usage\";\n\nexport interface OrganizationPresentationDenialScope {\n readonly organizationId: string;\n readonly requesterUserId: string;\n}\n\nexport async function clearOrganizationPresentationDenialInTransaction(input: {\n readonly organizationId: string;\n readonly projection: OrganizationPresentationDenialProjection;\n readonly requesterUserId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationPresentationDenials)\n .where(\n and(\n eq(\n organizationPresentationDenials.organizationId,\n input.organizationId,\n ),\n eq(\n organizationPresentationDenials.requesterUserId,\n input.requesterUserId,\n ),\n eq(organizationPresentationDenials.projection, input.projection),\n ),\n )\n .run();\n}\n"]}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { OrganizationReadModelGroupMemberResponse } from "../../../internal/validators/response/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ClientSQLiteTransactionScope } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
3
3
|
/** Locally projected members of one group, by user and role. */
|
|
4
4
|
export interface OrganizationReadModelGroupMembers {
|
|
5
5
|
readonly groupId: string;
|
|
6
6
|
readonly members: OrganizationReadModelGroupMemberResponse[];
|
|
7
7
|
readonly organizationId: string;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/** One group's members, provided `currentUserId` holds a requester row. */
|
|
10
|
+
export declare function loadRequesterOrganizationReadModelGroupMembersInTransaction(tx: ClientSQLiteTransactionScope, input: {
|
|
11
|
+
readonly currentUserId: string;
|
|
12
|
+
readonly groupId: string;
|
|
13
|
+
readonly organizationId: string;
|
|
14
|
+
}): Promise<OrganizationReadModelGroupMembers | null>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { and, asc, eq } from "drizzle-orm";
|
|
2
2
|
import { organizationReadModelGroupMembers, organizationReadModelGroups, organizationReadModelRequesters, organizationReadModelState, } from "../../sqlite/schema/organizationReadModelSchema.js";
|
|
3
3
|
import { OrganizationReadModelIntegrityError } from "./organizationReadModelProtocol.js";
|
|
4
|
-
import { loadWithOrganizationReadModelIntegrityPurge } from "./organizationReadModelPurge.js";
|
|
5
4
|
function requireOrganizationRole(value) {
|
|
6
5
|
if (value !== "member" && value !== "admin") {
|
|
7
6
|
throw new OrganizationReadModelIntegrityError("Stored organization group member role is invalid");
|
|
@@ -65,33 +64,29 @@ async function loadOrganizationReadModelGroupMembersInTransaction(input) {
|
|
|
65
64
|
members: rows.map((row) => toGroupMember(row, head.stateHash)),
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
groupId: state.memberGroupId,
|
|
89
|
-
stateHash: state.memberGroupStateHash,
|
|
90
|
-
},
|
|
91
|
-
organizationId,
|
|
92
|
-
tx,
|
|
93
|
-
});
|
|
67
|
+
/** One group's members, provided `currentUserId` holds a requester row. */
|
|
68
|
+
export async function loadRequesterOrganizationReadModelGroupMembersInTransaction(tx, input) {
|
|
69
|
+
const { currentUserId, groupId, organizationId } = input;
|
|
70
|
+
const [state] = await tx
|
|
71
|
+
.select({
|
|
72
|
+
memberGroupId: organizationReadModelState.memberGroupId,
|
|
73
|
+
memberGroupStateHash: organizationReadModelState.memberGroupStateHash,
|
|
74
|
+
})
|
|
75
|
+
.from(organizationReadModelState)
|
|
76
|
+
.innerJoin(organizationReadModelRequesters, and(eq(organizationReadModelRequesters.organizationId, organizationReadModelState.organizationId), eq(organizationReadModelRequesters.userId, currentUserId)))
|
|
77
|
+
.where(eq(organizationReadModelState.organizationId, organizationId))
|
|
78
|
+
.limit(1);
|
|
79
|
+
if (!state) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return loadOrganizationReadModelGroupMembersInTransaction({
|
|
83
|
+
groupId,
|
|
84
|
+
memberGroup: {
|
|
85
|
+
groupId: state.memberGroupId,
|
|
86
|
+
stateHash: state.memberGroupStateHash,
|
|
94
87
|
},
|
|
88
|
+
organizationId,
|
|
89
|
+
tx,
|
|
95
90
|
});
|
|
96
91
|
}
|
|
97
92
|
//# sourceMappingURL=organizationReadModelMemberLoad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModelMemberLoad.js","sourceRoot":"","sources":["organizationReadModelMemberLoad.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,iCAAiC,EACjC,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"organizationReadModelMemberLoad.js","sourceRoot":"","sources":["organizationReadModelMemberLoad.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,iCAAiC,EACjC,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAetF,SAAS,uBAAuB,CAAC,KAAa;IAC5C,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QAC5C,MAAM,IAAI,mCAAmC,CAC3C,kDAAkD,CACnD,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CACpB,GAAwB,EACxB,iBAAyB;IAEzB,IAAI,GAAG,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;QACxC,MAAM,IAAI,mCAAmC,CAC3C,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC;KACxC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,KAIjC;IACC,OAAO,KAAK,CAAC,EAAE;SACZ,MAAM,CAAC;QACN,MAAM,EAAE,iCAAiC,CAAC,MAAM;QAChD,IAAI,EAAE,iCAAiC,CAAC,IAAI;QAC5C,SAAS,EAAE,iCAAiC,CAAC,SAAS;KACvD,CAAC;SACD,IAAI,CAAC,iCAAiC,CAAC;SACvC,KAAK,CACJ,GAAG,CACD,EAAE,CACA,iCAAiC,CAAC,cAAc,EAChD,KAAK,CAAC,cAAc,CACrB,EACD,E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AC,CAAC,CAAC;IACZ,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kDAAkD,CAAC;QACxD,OAAO;QACP,WAAW,EAAE;YACX,OAAO,EAAE,KAAK,CAAC,aAAa;YAC5B,SAAS,EAAE,KAAK,CAAC,oBAAoB;SACtC;QACD,cAAc;QACd,EAAE;KACH,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n OrganizationReadModelGroupMemberResponse,\n OrganizationRole,\n} from \"@tearleads/validators/response\";\nimport { and, asc, eq } from \"drizzle-orm\";\nimport {\n organizationReadModelGroupMembers,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { OrganizationReadModelIntegrityError } from \"./organizationReadModelProtocol\";\n\ninterface SelectedGroupMember {\n readonly userId: string;\n readonly role: string;\n readonly stateHash: string;\n}\n\n/** Locally projected members of one group, by user and role. */\nexport interface OrganizationReadModelGroupMembers {\n readonly groupId: string;\n readonly members: OrganizationReadModelGroupMemberResponse[];\n readonly organizationId: string;\n}\n\nfunction requireOrganizationRole(value: string): OrganizationRole {\n if (value !== \"member\" && value !== \"admin\") {\n throw new OrganizationReadModelIntegrityError(\n \"Stored organization group member role is invalid\",\n );\n }\n return value;\n}\n\nfunction toGroupMember(\n row: SelectedGroupMember,\n expectedStateHash: string,\n): OrganizationReadModelGroupMemberResponse {\n if (row.stateHash !== expectedStateHash) {\n throw new OrganizationReadModelIntegrityError(\n \"Stored organization group membership state is inconsistent\",\n );\n }\n return {\n userId: row.userId,\n role: requireOrganizationRole(row.role),\n };\n}\n\nasync function loadMembershipRows(input: {\n readonly groupId: string;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<SelectedGroupMember[]> {\n return input.tx\n .select({\n userId: organizationReadModelGroupMembers.userId,\n role: organizationReadModelGroupMembers.role,\n stateHash: organizationReadModelGroupMembers.stateHash,\n })\n .from(organizationReadModelGroupMembers)\n .where(\n and(\n eq(\n organizationReadModelGroupMembers.organizationId,\n input.organizationId,\n ),\n eq(organizationReadModelGroupMembers.groupId, input.groupId),\n ),\n )\n .orderBy(\n asc(organizationReadModelGroupMembers.sortOrder),\n asc(organizationReadModelGroupMembers.userId),\n );\n}\n\ninterface StoredMembershipHead {\n readonly memberCount: number | null;\n readonly stateHash: string;\n}\n\n/** The reserved Members head lives on the state row; others on catalog rows. */\nasync function loadMembershipHead(input: {\n readonly groupId: string;\n readonly memberGroup: {\n readonly groupId: string;\n readonly stateHash: string;\n };\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<StoredMembershipHead | null> {\n if (input.groupId === input.memberGroup.groupId) {\n return { memberCount: null, stateHash: input.memberGroup.stateHash };\n }\n const [group] = await input.tx\n .select({\n memberCount: organizationReadModelGroups.memberCount,\n membersStateHash: organizationReadModelGroups.membersStateHash,\n stateHash: organizationReadModelGroups.stateHash,\n })\n .from(organizationReadModelGroups)\n .where(\n and(\n eq(organizationReadModelGroups.organizationId, input.organizationId),\n eq(organizationReadModelGroups.groupId, input.groupId),\n ),\n )\n .limit(1);\n if (!group?.membersStateHash) {\n return null;\n }\n if (group.stateHash !== group.membersStateHash) {\n throw new OrganizationReadModelIntegrityError(\n \"Stored organization group membership binding is invalid\",\n );\n }\n return { memberCount: group.memberCount, stateHash: group.membersStateHash };\n}\n\nasync function loadOrganizationReadModelGroupMembersInTransaction(input: {\n readonly groupId: string;\n readonly memberGroup: {\n readonly groupId: string;\n readonly stateHash: string;\n };\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<OrganizationReadModelGroupMembers | null> {\n const head = await loadMembershipHead(input);\n if (!head) {\n return null;\n }\n const rows = await loadMembershipRows(input);\n if (head.memberCount !== null && head.memberCount !== rows.length) {\n throw new OrganizationReadModelIntegrityError(\n \"Stored organization group membership binding is invalid\",\n );\n }\n return {\n organizationId: input.organizationId,\n groupId: input.groupId,\n members: rows.map((row) => toGroupMember(row, head.stateHash)),\n };\n}\n\n/** One group's members, provided `currentUserId` holds a requester row. */\nexport async function loadRequesterOrganizationReadModelGroupMembersInTransaction(\n tx: ClientSQLiteTransactionScope,\n input: {\n readonly currentUserId: string;\n readonly groupId: string;\n readonly organizationId: string;\n },\n): Promise<OrganizationReadModelGroupMembers | null> {\n const { currentUserId, groupId, organizationId } = input;\n const [state] = await tx\n .select({\n memberGroupId: organizationReadModelState.memberGroupId,\n memberGroupStateHash: organizationReadModelState.memberGroupStateHash,\n })\n .from(organizationReadModelState)\n .innerJoin(\n organizationReadModelRequesters,\n and(\n eq(\n organizationReadModelRequesters.organizationId,\n organizationReadModelState.organizationId,\n ),\n eq(organizationReadModelRequesters.userId, currentUserId),\n ),\n )\n .where(eq(organizationReadModelState.organizationId, organizationId))\n .limit(1);\n if (!state) {\n return null;\n }\n return loadOrganizationReadModelGroupMembersInTransaction({\n groupId,\n memberGroup: {\n groupId: state.memberGroupId,\n stateHash: state.memberGroupStateHash,\n },\n organizationId,\n tx,\n });\n}\n"]}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { eq } from "drizzle-orm";
|
|
2
|
-
import { getOrCreatePrincipalPolicyCoordinator } from "../../principals/principalPolicyCoordinator.js";
|
|
3
|
-
import { organizationReadModelTables } from "../../sqlite/schema/index.js";
|
|
4
|
-
import { organizationDataUsageTables } from "../../sqlite/schema/organizationDataUsageSchema.js";
|
|
5
2
|
import { organizationReadModelDirectoryUsers, organizationReadModelGroups, organizationReadModelRequesters, organizationReadModelState, } from "../../sqlite/schema/organizationReadModelSchema.js";
|
|
6
3
|
import { sqliteInsertBatchSize } from "../../sqlite/sqliteBindBudget.js";
|
|
7
|
-
import { getClientSQLitePersistenceRuntime, } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
8
|
-
import { ensureSqlTables } from "../../sqlite/sqlSchema.js";
|
|
9
4
|
import { clearOrganizationPresentationDenialInTransaction } from "./organizationPresentationDenialPersistence.js";
|
|
10
5
|
import { applyOrganizationReadModelGrantsLane } from "./organizationReadModelGrantPersistence.js";
|
|
11
6
|
import { applyGroupMembershipsLane, assertStoredGroupMembershipBindings, OrganizationReadModelBindingError, } from "./organizationReadModelMembershipPersistence.js";
|
|
12
|
-
import {
|
|
13
|
-
import { loadWithOrganizationReadModelIntegrityPurge, pruneInactiveOrganizationRequestersInTransaction, purgeOrganizationReadModelProjectionInTransaction, } from "./organizationReadModelPurge.js";
|
|
14
|
-
import { assertOrganizationReadModelResponse } from "./organizationReadModelResponseAssertions.js";
|
|
7
|
+
import { pruneInactiveOrganizationRequestersInTransaction } from "./organizationReadModelPurge.js";
|
|
15
8
|
const DIRECTORY_INSERT_BATCH_SIZE = sqliteInsertBatchSize(organizationReadModelDirectoryUsers);
|
|
16
9
|
const GROUP_INSERT_BATCH_SIZE = sqliteInsertBatchSize(organizationReadModelGroups);
|
|
17
10
|
/**
|
|
@@ -263,84 +256,48 @@ function requireMemberGroupId(input) {
|
|
|
263
256
|
}
|
|
264
257
|
return memberGroupId;
|
|
265
258
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
tx,
|
|
274
|
-
}),
|
|
259
|
+
/** The transaction body of applying one read-model response. */
|
|
260
|
+
export async function applyOrganizationReadModelResponseInTransaction(tx, input) {
|
|
261
|
+
const current = await loadCurrentState(tx, input.response.organizationId);
|
|
262
|
+
const disposition = resolveApplyDisposition({
|
|
263
|
+
current,
|
|
264
|
+
requestedCursor: input.requestedCursor,
|
|
265
|
+
response: input.response,
|
|
275
266
|
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
267
|
+
if (disposition === "stale") {
|
|
268
|
+
return disposition;
|
|
269
|
+
}
|
|
270
|
+
const now = input.now().toISOString();
|
|
271
|
+
await upsertRequester({
|
|
272
|
+
appliedCursor: input.response.nextCursor,
|
|
279
273
|
currentUserId: input.currentUserId,
|
|
274
|
+
isOrgAdmin: input.response.currentUser.isOrgAdmin,
|
|
275
|
+
now,
|
|
276
|
+
organizationId: input.response.organizationId,
|
|
277
|
+
tx,
|
|
278
|
+
});
|
|
279
|
+
if (disposition === "already-applied") {
|
|
280
|
+
return disposition;
|
|
281
|
+
}
|
|
282
|
+
const memberGroupId = requireMemberGroupId({
|
|
283
|
+
current,
|
|
280
284
|
response: input.response,
|
|
281
285
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const current = await loadCurrentState(tx, input.response.organizationId);
|
|
289
|
-
const disposition = resolveApplyDisposition({
|
|
290
|
-
current,
|
|
291
|
-
requestedCursor: input.requestedCursor,
|
|
292
|
-
response: input.response,
|
|
293
|
-
});
|
|
294
|
-
if (disposition === "stale") {
|
|
295
|
-
return disposition;
|
|
296
|
-
}
|
|
297
|
-
const now = new Date().toISOString();
|
|
298
|
-
await upsertRequester({
|
|
299
|
-
appliedCursor: input.response.nextCursor,
|
|
300
|
-
currentUserId: input.currentUserId,
|
|
301
|
-
isOrgAdmin: input.response.currentUser.isOrgAdmin,
|
|
302
|
-
now,
|
|
303
|
-
organizationId: input.response.organizationId,
|
|
304
|
-
tx,
|
|
305
|
-
});
|
|
306
|
-
if (disposition === "already-applied") {
|
|
307
|
-
return disposition;
|
|
308
|
-
}
|
|
309
|
-
const memberGroupId = requireMemberGroupId({
|
|
310
|
-
current,
|
|
311
|
-
response: input.response,
|
|
312
|
-
});
|
|
313
|
-
const memberGroupStateHash = await applyResponseLanes({
|
|
314
|
-
current,
|
|
315
|
-
currentUserId: input.currentUserId,
|
|
316
|
-
memberGroupId,
|
|
317
|
-
response: input.response,
|
|
318
|
-
tx,
|
|
319
|
-
});
|
|
320
|
-
await upsertOrganizationReadModelState({
|
|
321
|
-
current,
|
|
322
|
-
memberGroupId,
|
|
323
|
-
memberGroupStateHash,
|
|
324
|
-
now,
|
|
325
|
-
response: input.response,
|
|
326
|
-
tx,
|
|
327
|
-
});
|
|
328
|
-
return "applied";
|
|
286
|
+
const memberGroupStateHash = await applyResponseLanes({
|
|
287
|
+
current,
|
|
288
|
+
currentUserId: input.currentUserId,
|
|
289
|
+
memberGroupId,
|
|
290
|
+
response: input.response,
|
|
291
|
+
tx,
|
|
329
292
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
await ensureSqlTables(execSql, organizationReadModelTables);
|
|
338
|
-
await getClientSQLitePersistenceRuntime(execSql).transaction(async (tx) => {
|
|
339
|
-
await purgeOrganizationReadModelProjectionInTransaction({
|
|
340
|
-
onlyRequesterUserId: options.onlyRequesterUserId,
|
|
341
|
-
organizationId,
|
|
342
|
-
tx,
|
|
343
|
-
});
|
|
293
|
+
await upsertOrganizationReadModelState({
|
|
294
|
+
current,
|
|
295
|
+
memberGroupId,
|
|
296
|
+
memberGroupStateHash,
|
|
297
|
+
now,
|
|
298
|
+
response: input.response,
|
|
299
|
+
tx,
|
|
344
300
|
});
|
|
301
|
+
return "applied";
|
|
345
302
|
}
|
|
346
303
|
//# sourceMappingURL=organizationReadModelPersistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModelPersistence.js","sourceRoot":"","sources":["organizationReadModelPersistence.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAC;AACpG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iDAAiD,CAAC;AAC9F,OAAO,EACL,mCAAmC,EACnC,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDA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CAAC","sourcesContent":["import type {\n ListOrganizationGroupsResponse,\n OrganizationGroupCurrentStateResponse,\n OrganizationReadModelDirectoryResponse,\n OrganizationReadModelResponse,\n} from \"@tearleads/validators/response\";\nimport { eq } from \"drizzle-orm\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../principals/principalPolicyCoordinator\";\nimport { organizationReadModelTables } from \"../../sqlite/schema\";\nimport { organizationDataUsageTables } from \"../../sqlite/schema/organizationDataUsageSchema\";\nimport {\n organizationReadModelDirectoryUsers,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport { sqliteInsertBatchSize } from \"../../sqlite/sqliteBindBudget\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport { clearOrganizationPresentationDenialInTransaction } from \"./organizationPresentationDenialPersistence\";\nimport { applyOrganizationReadModelGrantsLane } from \"./organizationReadModelGrantPersistence\";\nimport {\n applyGroupMembershipsLane,\n assertStoredGroupMembershipBindings,\n OrganizationReadModelBindingError,\n} from \"./organizationReadModelMembershipPersistence\";\nimport {\n loadOrganizationReadModelProjectionInTransaction,\n type OrganizationReadModelProjection,\n} from \"./organizationReadModelProjection\";\nimport {\n loadWithOrganizationReadModelIntegrityPurge,\n pruneInactiveOrganizationRequestersInTransaction,\n purgeOrganizationReadModelProjectionInTransaction,\n} from \"./organizationReadModelPurge\";\nimport { assertOrganizationReadModelResponse } from \"./organizationReadModelResponseAssertions\";\n\nexport type { OrganizationReadModelProjection } from \"./organizationReadModelProjection\";\n\nconst DIRECTORY_INSERT_BATCH_SIZE = sqliteInsertBatchSize(\n organizationReadModelDirectoryUsers,\n);\nconst GROUP_INSERT_BATCH_SIZE = sqliteInsertBatchSize(\n organizationReadModelGroups,\n);\n\ntype ApplyOrganizationReadModelResponseResult =\n | \"already-applied\"\n | \"applied\"\n | \"stale\";\n\ninterface CurrentOrganizationReadModelState {\n readonly cursor: string;\n readonly memberGroupId: string;\n readonly memberGroupStateHash: string;\n readonly organizationHead: OrganizationGroupCurrentStateResponse;\n readonly profileDocumentId: string | null;\n}\n\n/**\n * The member's leave request as stored JSON, kept only when it names this\n * organization and member. Its signature is checked when read, against the\n * member's trusted identity rather than the key served beside it.\n */\nfunction storedLeaveRequestJson(\n organizationId: string,\n user: OrganizationReadModelDirectoryResponse[\"users\"][number],\n): string | null {\n const request = user.leaveRequest;\n return request &&\n request.organizationId === organizationId &&\n request.userId === user.userId\n ? JSON.stringify(request)\n : null;\n}\n\nasync function replaceDirectoryLane(input: {\n readonly directory: OrganizationReadModelDirectoryResponse;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelDirectoryUsers)\n .where(\n eq(\n organizationReadModelDirectoryUsers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n\n const rows = input.directory.users.map((user, sortOrder) => ({\n organizationId: input.organizationId,\n userId: user.userId,\n sortOrder,\n signingKeyFingerprint: user.signingKeyFingerprint,\n signingPublicKey: user.signingPublicKey,\n encapsulationPublicKey: user.encapsulationPublicKey,\n encapsulationKeyFingerprint: user.encapsulationKeyFingerprint,\n isPersonalOrganizationOwner: user.isPersonalOrganizationOwner,\n createdAt: user.createdAt,\n status: user.status,\n profileDocumentId: user.profileDocumentId,\n joinedAt: user.joinedAt,\n updatedAt: user.updatedAt,\n disabledAt: user.disabledAt,\n disabledByUserId: user.disabledByUserId,\n leaveRequest: storedLeaveRequestJson(input.organizationId, user),\n }));\n for (\n let index = 0;\n index < rows.length;\n index += DIRECTORY_INSERT_BATCH_SIZE\n ) {\n await input.tx\n .insert(organizationReadModelDirectoryUsers)\n .values(rows.slice(index, index + DIRECTORY_INSERT_BATCH_SIZE))\n .run();\n }\n}\n\nasync function upsertRequester(input: {\n readonly appliedCursor: string;\n readonly currentUserId: string;\n readonly isOrgAdmin: boolean;\n readonly now: string;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n const requesterRow = {\n organizationId: input.organizationId,\n userId: input.currentUserId,\n isOrgAdmin: input.isOrgAdmin,\n appliedCursor: input.appliedCursor,\n updatedAt: input.now,\n };\n await input.tx\n .insert(organizationReadModelRequesters)\n .values(requesterRow)\n .onConflictDoUpdate({\n target: [\n organizationReadModelRequesters.organizationId,\n organizationReadModelRequesters.userId,\n ],\n set: {\n isOrgAdmin: requesterRow.isOrgAdmin,\n appliedCursor: requesterRow.appliedCursor,\n updatedAt: requesterRow.updatedAt,\n },\n })\n .run();\n // Storing an authoritative response proves access: retire the durable\n // denial marker for this scope in the same transaction.\n await clearOrganizationPresentationDenialInTransaction({\n organizationId: input.organizationId,\n projection: \"readModel\",\n requesterUserId: input.currentUserId,\n tx: input.tx,\n });\n}\n\nasync function replaceGroupsLane(input: {\n readonly groups: ListOrganizationGroupsResponse;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n // Hydrated names and delivered membership heads outlive a catalog\n // replacement; the groupMemberships lane rebinds any head that changed.\n const previousGroups = await input.tx\n .select({\n groupId: organizationReadModelGroups.groupId,\n membersStateHash: organizationReadModelGroups.membersStateHash,\n name: organizationReadModelGroups.name,\n })\n .from(organizationReadModelGroups)\n .where(\n eq(organizationReadModelGroups.organizationId, input.organizationId),\n );\n const previousById = new Map(\n previousGroups.map((group) => [group.groupId, group]),\n );\n await input.tx\n .delete(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, input.organizationId))\n .run();\n\n const rows = input.groups.groups.map((group, sortOrder) => ({\n organizationId: input.organizationId,\n groupId: group.groupId,\n sortOrder,\n name: previousById.get(group.groupId)?.name ?? \"\",\n createdAt: group.createdAt,\n isBuiltin: group.isBuiltin,\n stateHash: group.currentState?.stateHash ?? null,\n stateVersion: group.currentState?.version ?? null,\n keyEpoch: group.currentState?.keyEpoch ?? null,\n keyFingerprint: group.currentState?.keyFingerprint ?? null,\n memberCount: group.currentState?.memberCount ?? null,\n membersStateHash: previousById.get(group.groupId)?.membersStateHash ?? null,\n }));\n for (let index = 0; index < rows.length; index += GROUP_INSERT_BATCH_SIZE) {\n await input.tx\n .insert(organizationReadModelGroups)\n .values(rows.slice(index, index + GROUP_INSERT_BATCH_SIZE))\n .run();\n }\n}\n\nasync function loadCurrentState(\n tx: ClientSQLiteTransactionScope,\n organizationId: string,\n): Promise<CurrentOrganizationReadModelState | null> {\n const [current] = await tx\n .select({\n cursor: organizationReadModelState.cursor,\n keyEpoch: organizationReadModelState.organizationKeyEpoch,\n keyFingerprint: organizationReadModelState.organizationKeyFingerprint,\n memberCount: organizationReadModelState.organizationMemberCount,\n memberGroupId: organizationReadModelState.memberGroupId,\n memberGroupStateHash: organizationReadModelState.memberGroupStateHash,\n profileDocumentId: organizationReadModelState.profileDocumentId,\n stateHash: organizationReadModelState.organizationStateHash,\n version: organizationReadModelState.organizationStateVersion,\n })\n .from(organizationReadModelState)\n .where(eq(organizationReadModelState.organizationId, organizationId))\n .limit(1);\n if (!current) {\n return null;\n }\n const { keyEpoch, keyFingerprint, memberCount, stateHash, version, ...rest } =\n current;\n return {\n ...rest,\n organizationHead: {\n keyEpoch,\n keyFingerprint,\n memberCount,\n stateHash,\n version,\n },\n };\n}\n\nfunction resolveApplyDisposition(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n}): ApplyOrganizationReadModelResponseResult | null {\n const currentCursor = input.current?.cursor ?? null;\n if (currentCursor !== input.requestedCursor) {\n return currentCursor === input.response.nextCursor\n ? \"already-applied\"\n : \"stale\";\n }\n if (!input.current && input.response.mode !== \"snapshot\") {\n throw new Error(\"Organization read-model delta requires a local snapshot\");\n }\n return null;\n}\n\ninterface ResponseLanesInput {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly memberGroupId: string;\n readonly response: OrganizationReadModelResponse;\n readonly tx: ClientSQLiteTransactionScope;\n}\n\n/** Apply every carried lane and return the reserved Members head. */\nasync function replaceResponseLanes(\n input: ResponseLanesInput,\n): Promise<string | null> {\n const { organizationId } = input.response;\n const directory = input.response.lanes.directory;\n if (directory) {\n await replaceDirectoryLane({ directory, organizationId, tx: input.tx });\n }\n const groups = input.response.lanes.groups;\n if (groups) {\n await replaceGroupsLane({ groups, organizationId, tx: input.tx });\n }\n const groupMemberships = input.response.lanes.groupMemberships;\n const memberGroupStateHash = groupMemberships\n ? await applyGroupMembershipsLane({\n currentMemberGroupStateHash:\n input.current?.memberGroupStateHash ?? null,\n lane: groupMemberships,\n memberGroupId: input.memberGroupId,\n organizationId,\n replaceAll: input.response.mode === \"snapshot\",\n tx: input.tx,\n })\n : (input.current?.memberGroupStateHash ?? null);\n const grants = input.response.lanes.grants;\n if (grants) {\n await applyOrganizationReadModelGrantsLane({\n lane: grants,\n organizationId,\n tx: input.tx,\n });\n }\n return memberGroupStateHash;\n}\n\nasync function applyResponseLanes(\n input: ResponseLanesInput & { readonly currentUserId: string },\n): Promise<string | null> {\n const memberGroupStateHash = await replaceResponseLanes(input);\n // The directory lane is the authoritative roster, already persisted above:\n // requester rows for users it no longer lists as active fall with it.\n if (input.response.lanes.directory) {\n await pruneInactiveOrganizationRequestersInTransaction({\n organizationId: input.response.organizationId,\n retainUserId: input.currentUserId,\n tx: input.tx,\n });\n }\n if (input.response.lanes.groups || input.response.lanes.groupMemberships) {\n await assertStoredGroupMembershipBindings({\n memberGroupId: input.memberGroupId,\n memberGroupStateHash,\n organizationId: input.response.organizationId,\n tx: input.tx,\n });\n }\n return memberGroupStateHash;\n}\n\n/**\n * Write the cursor with the organization policy head and the reserved Members\n * head in one row, so a failure anywhere in the page rolls them back together.\n */\nasync function upsertOrganizationReadModelState(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly memberGroupId: string;\n readonly memberGroupStateHash: string | null;\n readonly now: string;\n readonly response: OrganizationReadModelResponse;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n const organizationHead =\n input.response.lanes.organizationPolicy?.currentState ??\n input.current?.organizationHead;\n if (!organizationHead || input.memberGroupStateHash === null) {\n throw new OrganizationReadModelBindingError(\n \"Organization read-model policy or Members head is missing\",\n );\n }\n const directoryLane = input.response.lanes.directory;\n const values = {\n cursor: input.response.nextCursor,\n profileDocumentId:\n directoryLane !== undefined\n ? directoryLane.profileDocumentId\n : (input.current?.profileDocumentId ?? null),\n memberGroupId: input.memberGroupId,\n memberGroupStateHash: input.memberGroupStateHash,\n organizationStateHash: organizationHead.stateHash,\n organizationStateVersion: organizationHead.version,\n organizationKeyEpoch: organizationHead.keyEpoch,\n organizationKeyFingerprint: organizationHead.keyFingerprint,\n organizationMemberCount: organizationHead.memberCount,\n updatedAt: input.now,\n };\n await input.tx\n .insert(organizationReadModelState)\n .values({ ...values, organizationId: input.response.organizationId })\n .onConflictDoUpdate({\n target: organizationReadModelState.organizationId,\n set: values,\n })\n .run();\n}\n\nfunction requireMemberGroupId(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly response: OrganizationReadModelResponse;\n}): string {\n const memberGroupId =\n input.response.lanes.groups?.memberGroupId ?? input.current?.memberGroupId;\n if (!memberGroupId) {\n throw new Error(\"Organization read-model member group is missing\");\n }\n return memberGroupId;\n}\n\nexport async function loadOrganizationReadModelProjection(\n execSql: ExecSql,\n organizationId: string,\n currentUserId: string,\n): Promise<OrganizationReadModelProjection | null> {\n return loadWithOrganizationReadModelIntegrityPurge({\n execSql,\n organizationId,\n load: (tx) =>\n loadOrganizationReadModelProjectionInTransaction({\n currentUserId,\n organizationId,\n tx,\n }),\n });\n}\n\nexport async function applyOrganizationReadModelResponse(input: {\n readonly currentUserId: string;\n readonly execSql: ExecSql;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n}): Promise<ApplyOrganizationReadModelResponseResult> {\n assertOrganizationReadModelResponse({\n currentUserId: input.currentUserId,\n response: input.response,\n });\n // The requester prune below also retires pruned users' usage projections.\n await ensureSqlTables(input.execSql, [\n ...organizationReadModelTables,\n ...organizationDataUsageTables,\n ]);\n\n const disposition = await getClientSQLitePersistenceRuntime(\n input.execSql,\n ).transaction(\n async (tx): Promise<ApplyOrganizationReadModelResponseResult> => {\n const current = await loadCurrentState(tx, input.response.organizationId);\n const disposition = resolveApplyDisposition({\n current,\n requestedCursor: input.requestedCursor,\n response: input.response,\n });\n if (disposition === \"stale\") {\n return disposition;\n }\n const now = new Date().toISOString();\n await upsertRequester({\n appliedCursor: input.response.nextCursor,\n currentUserId: input.currentUserId,\n isOrgAdmin: input.response.currentUser.isOrgAdmin,\n now,\n organizationId: input.response.organizationId,\n tx,\n });\n if (disposition === \"already-applied\") {\n return disposition;\n }\n const memberGroupId = requireMemberGroupId({\n current,\n response: input.response,\n });\n const memberGroupStateHash = await applyResponseLanes({\n current,\n currentUserId: input.currentUserId,\n memberGroupId,\n response: input.response,\n tx,\n });\n await upsertOrganizationReadModelState({\n current,\n memberGroupId,\n memberGroupStateHash,\n now,\n response: input.response,\n tx,\n });\n\n return \"applied\";\n },\n );\n // An applied change follows an organization hint or mutation; in-flight\n // operations recover the directory again instead of reusing their memo.\n if (disposition === \"applied\")\n getOrCreatePrincipalPolicyCoordinator(input.execSql).invalidateRecovery(\n input.response.organizationId,\n );\n return disposition;\n}\n\nexport async function purgeOrganizationReadModelProjection(\n execSql: ExecSql,\n organizationId: string,\n options: { readonly onlyRequesterUserId?: string } = {},\n): Promise<void> {\n await ensureSqlTables(execSql, organizationReadModelTables);\n await getClientSQLitePersistenceRuntime(execSql).transaction(async (tx) => {\n await purgeOrganizationReadModelProjectionInTransaction({\n onlyRequesterUserId: options.onlyRequesterUserId,\n organizationId,\n tx,\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organizationReadModelPersistence.js","sourceRoot":"","sources":["organizationReadModelPersistence.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EA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Response,\n OrganizationReadModelDirectoryResponse,\n OrganizationReadModelResponse,\n} from \"@tearleads/validators/response\";\nimport { eq } from \"drizzle-orm\";\nimport {\n organizationReadModelDirectoryUsers,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport { sqliteInsertBatchSize } from \"../../sqlite/sqliteBindBudget\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { clearOrganizationPresentationDenialInTransaction } from \"./organizationPresentationDenialPersistence\";\nimport { applyOrganizationReadModelGrantsLane } from \"./organizationReadModelGrantPersistence\";\nimport {\n applyGroupMembershipsLane,\n assertStoredGroupMembershipBindings,\n OrganizationReadModelBindingError,\n} from \"./organizationReadModelMembershipPersistence\";\nimport { pruneInactiveOrganizationRequestersInTransaction } from \"./organizationReadModelPurge\";\n\nexport type { OrganizationReadModelProjection } from \"./organizationReadModelProjection\";\n\nconst DIRECTORY_INSERT_BATCH_SIZE = sqliteInsertBatchSize(\n organizationReadModelDirectoryUsers,\n);\nconst GROUP_INSERT_BATCH_SIZE = sqliteInsertBatchSize(\n organizationReadModelGroups,\n);\n\nexport type ApplyOrganizationReadModelResponseResult =\n | \"already-applied\"\n | \"applied\"\n | \"stale\";\n\ninterface CurrentOrganizationReadModelState {\n readonly cursor: string;\n readonly memberGroupId: string;\n readonly memberGroupStateHash: string;\n readonly organizationHead: OrganizationGroupCurrentStateResponse;\n readonly profileDocumentId: string | null;\n}\n\n/**\n * The member's leave request as stored JSON, kept only when it names this\n * organization and member. Its signature is checked when read, against the\n * member's trusted identity rather than the key served beside it.\n */\nfunction storedLeaveRequestJson(\n organizationId: string,\n user: OrganizationReadModelDirectoryResponse[\"users\"][number],\n): string | null {\n const request = user.leaveRequest;\n return request &&\n request.organizationId === organizationId &&\n request.userId === user.userId\n ? JSON.stringify(request)\n : null;\n}\n\nasync function replaceDirectoryLane(input: {\n readonly directory: OrganizationReadModelDirectoryResponse;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelDirectoryUsers)\n .where(\n eq(\n organizationReadModelDirectoryUsers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n\n const rows = input.directory.users.map((user, sortOrder) => ({\n organizationId: input.organizationId,\n userId: user.userId,\n sortOrder,\n signingKeyFingerprint: user.signingKeyFingerprint,\n signingPublicKey: user.signingPublicKey,\n encapsulationPublicKey: user.encapsulationPublicKey,\n encapsulationKeyFingerprint: user.encapsulationKeyFingerprint,\n isPersonalOrganizationOwner: user.isPersonalOrganizationOwner,\n createdAt: user.createdAt,\n status: user.status,\n profileDocumentId: user.profileDocumentId,\n joinedAt: user.joinedAt,\n updatedAt: user.updatedAt,\n disabledAt: user.disabledAt,\n disabledByUserId: user.disabledByUserId,\n leaveRequest: storedLeaveRequestJson(input.organizationId, user),\n }));\n for (\n let index = 0;\n index < rows.length;\n index += DIRECTORY_INSERT_BATCH_SIZE\n ) {\n await input.tx\n .insert(organizationReadModelDirectoryUsers)\n .values(rows.slice(index, index + DIRECTORY_INSERT_BATCH_SIZE))\n .run();\n }\n}\n\nasync function upsertRequester(input: {\n readonly appliedCursor: string;\n readonly currentUserId: string;\n readonly isOrgAdmin: boolean;\n readonly now: string;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n const requesterRow = {\n organizationId: input.organizationId,\n userId: input.currentUserId,\n isOrgAdmin: input.isOrgAdmin,\n appliedCursor: input.appliedCursor,\n updatedAt: input.now,\n };\n await input.tx\n .insert(organizationReadModelRequesters)\n .values(requesterRow)\n .onConflictDoUpdate({\n target: [\n organizationReadModelRequesters.organizationId,\n organizationReadModelRequesters.userId,\n ],\n set: {\n isOrgAdmin: requesterRow.isOrgAdmin,\n appliedCursor: requesterRow.appliedCursor,\n updatedAt: requesterRow.updatedAt,\n },\n })\n .run();\n // Storing an authoritative response proves access: retire the durable\n // denial marker for this scope in the same transaction.\n await clearOrganizationPresentationDenialInTransaction({\n organizationId: input.organizationId,\n projection: \"readModel\",\n requesterUserId: input.currentUserId,\n tx: input.tx,\n });\n}\n\nasync function replaceGroupsLane(input: {\n readonly groups: ListOrganizationGroupsResponse;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n // Hydrated names and delivered membership heads outlive a catalog\n // replacement; the groupMemberships lane rebinds any head that changed.\n const previousGroups = await input.tx\n .select({\n groupId: organizationReadModelGroups.groupId,\n membersStateHash: organizationReadModelGroups.membersStateHash,\n name: organizationReadModelGroups.name,\n })\n .from(organizationReadModelGroups)\n .where(\n eq(organizationReadModelGroups.organizationId, input.organizationId),\n );\n const previousById = new Map(\n previousGroups.map((group) => [group.groupId, group]),\n );\n await input.tx\n .delete(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, input.organizationId))\n .run();\n\n const rows = input.groups.groups.map((group, sortOrder) => ({\n organizationId: input.organizationId,\n groupId: group.groupId,\n sortOrder,\n name: previousById.get(group.groupId)?.name ?? \"\",\n createdAt: group.createdAt,\n isBuiltin: group.isBuiltin,\n stateHash: group.currentState?.stateHash ?? null,\n stateVersion: group.currentState?.version ?? null,\n keyEpoch: group.currentState?.keyEpoch ?? null,\n keyFingerprint: group.currentState?.keyFingerprint ?? null,\n memberCount: group.currentState?.memberCount ?? null,\n membersStateHash: previousById.get(group.groupId)?.membersStateHash ?? null,\n }));\n for (let index = 0; index < rows.length; index += GROUP_INSERT_BATCH_SIZE) {\n await input.tx\n .insert(organizationReadModelGroups)\n .values(rows.slice(index, index + GROUP_INSERT_BATCH_SIZE))\n .run();\n }\n}\n\nasync function loadCurrentState(\n tx: ClientSQLiteTransactionScope,\n organizationId: string,\n): Promise<CurrentOrganizationReadModelState | null> {\n const [current] = await tx\n .select({\n cursor: organizationReadModelState.cursor,\n keyEpoch: organizationReadModelState.organizationKeyEpoch,\n keyFingerprint: organizationReadModelState.organizationKeyFingerprint,\n memberCount: organizationReadModelState.organizationMemberCount,\n memberGroupId: organizationReadModelState.memberGroupId,\n memberGroupStateHash: organizationReadModelState.memberGroupStateHash,\n profileDocumentId: organizationReadModelState.profileDocumentId,\n stateHash: organizationReadModelState.organizationStateHash,\n version: organizationReadModelState.organizationStateVersion,\n })\n .from(organizationReadModelState)\n .where(eq(organizationReadModelState.organizationId, organizationId))\n .limit(1);\n if (!current) {\n return null;\n }\n const { keyEpoch, keyFingerprint, memberCount, stateHash, version, ...rest } =\n current;\n return {\n ...rest,\n organizationHead: {\n keyEpoch,\n keyFingerprint,\n memberCount,\n stateHash,\n version,\n },\n };\n}\n\nfunction resolveApplyDisposition(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n}): ApplyOrganizationReadModelResponseResult | null {\n const currentCursor = input.current?.cursor ?? null;\n if (currentCursor !== input.requestedCursor) {\n return currentCursor === input.response.nextCursor\n ? \"already-applied\"\n : \"stale\";\n }\n if (!input.current && input.response.mode !== \"snapshot\") {\n throw new Error(\"Organization read-model delta requires a local snapshot\");\n }\n return null;\n}\n\ninterface ResponseLanesInput {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly memberGroupId: string;\n readonly response: OrganizationReadModelResponse;\n readonly tx: ClientSQLiteTransactionScope;\n}\n\n/** Apply every carried lane and return the reserved Members head. */\nasync function replaceResponseLanes(\n input: ResponseLanesInput,\n): Promise<string | null> {\n const { organizationId } = input.response;\n const directory = input.response.lanes.directory;\n if (directory) {\n await replaceDirectoryLane({ directory, organizationId, tx: input.tx });\n }\n const groups = input.response.lanes.groups;\n if (groups) {\n await replaceGroupsLane({ groups, organizationId, tx: input.tx });\n }\n const groupMemberships = input.response.lanes.groupMemberships;\n const memberGroupStateHash = groupMemberships\n ? await applyGroupMembershipsLane({\n currentMemberGroupStateHash:\n input.current?.memberGroupStateHash ?? null,\n lane: groupMemberships,\n memberGroupId: input.memberGroupId,\n organizationId,\n replaceAll: input.response.mode === \"snapshot\",\n tx: input.tx,\n })\n : (input.current?.memberGroupStateHash ?? null);\n const grants = input.response.lanes.grants;\n if (grants) {\n await applyOrganizationReadModelGrantsLane({\n lane: grants,\n organizationId,\n tx: input.tx,\n });\n }\n return memberGroupStateHash;\n}\n\nasync function applyResponseLanes(\n input: ResponseLanesInput & { readonly currentUserId: string },\n): Promise<string | null> {\n const memberGroupStateHash = await replaceResponseLanes(input);\n // The directory lane is the authoritative roster, already persisted above:\n // requester rows for users it no longer lists as active fall with it.\n if (input.response.lanes.directory) {\n await pruneInactiveOrganizationRequestersInTransaction({\n organizationId: input.response.organizationId,\n retainUserId: input.currentUserId,\n tx: input.tx,\n });\n }\n if (input.response.lanes.groups || input.response.lanes.groupMemberships) {\n await assertStoredGroupMembershipBindings({\n memberGroupId: input.memberGroupId,\n memberGroupStateHash,\n organizationId: input.response.organizationId,\n tx: input.tx,\n });\n }\n return memberGroupStateHash;\n}\n\n/**\n * Write the cursor with the organization policy head and the reserved Members\n * head in one row, so a failure anywhere in the page rolls them back together.\n */\nasync function upsertOrganizationReadModelState(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly memberGroupId: string;\n readonly memberGroupStateHash: string | null;\n readonly now: string;\n readonly response: OrganizationReadModelResponse;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n const organizationHead =\n input.response.lanes.organizationPolicy?.currentState ??\n input.current?.organizationHead;\n if (!organizationHead || input.memberGroupStateHash === null) {\n throw new OrganizationReadModelBindingError(\n \"Organization read-model policy or Members head is missing\",\n );\n }\n const directoryLane = input.response.lanes.directory;\n const values = {\n cursor: input.response.nextCursor,\n profileDocumentId:\n directoryLane !== undefined\n ? directoryLane.profileDocumentId\n : (input.current?.profileDocumentId ?? null),\n memberGroupId: input.memberGroupId,\n memberGroupStateHash: input.memberGroupStateHash,\n organizationStateHash: organizationHead.stateHash,\n organizationStateVersion: organizationHead.version,\n organizationKeyEpoch: organizationHead.keyEpoch,\n organizationKeyFingerprint: organizationHead.keyFingerprint,\n organizationMemberCount: organizationHead.memberCount,\n updatedAt: input.now,\n };\n await input.tx\n .insert(organizationReadModelState)\n .values({ ...values, organizationId: input.response.organizationId })\n .onConflictDoUpdate({\n target: organizationReadModelState.organizationId,\n set: values,\n })\n .run();\n}\n\nfunction requireMemberGroupId(input: {\n readonly current: CurrentOrganizationReadModelState | null;\n readonly response: OrganizationReadModelResponse;\n}): string {\n const memberGroupId =\n input.response.lanes.groups?.memberGroupId ?? input.current?.memberGroupId;\n if (!memberGroupId) {\n throw new Error(\"Organization read-model member group is missing\");\n }\n return memberGroupId;\n}\n\n/** The transaction body of applying one read-model response. */\nexport async function applyOrganizationReadModelResponseInTransaction(\n tx: ClientSQLiteTransactionScope,\n input: {\n readonly currentUserId: string;\n readonly now: () => Date;\n readonly requestedCursor: string | null;\n readonly response: OrganizationReadModelResponse;\n },\n): Promise<ApplyOrganizationReadModelResponseResult> {\n const current = await loadCurrentState(tx, input.response.organizationId);\n const disposition = resolveApplyDisposition({\n current,\n requestedCursor: input.requestedCursor,\n response: input.response,\n });\n if (disposition === \"stale\") {\n return disposition;\n }\n const now = input.now().toISOString();\n await upsertRequester({\n appliedCursor: input.response.nextCursor,\n currentUserId: input.currentUserId,\n isOrgAdmin: input.response.currentUser.isOrgAdmin,\n now,\n organizationId: input.response.organizationId,\n tx,\n });\n if (disposition === \"already-applied\") {\n return disposition;\n }\n const memberGroupId = requireMemberGroupId({\n current,\n response: input.response,\n });\n const memberGroupStateHash = await applyResponseLanes({\n current,\n currentUserId: input.currentUserId,\n memberGroupId,\n response: input.response,\n tx,\n });\n await upsertOrganizationReadModelState({\n current,\n memberGroupId,\n memberGroupStateHash,\n now,\n response: input.response,\n tx,\n });\n\n return \"applied\";\n}\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { and, eq, ne, notExists } from "drizzle-orm";
|
|
2
|
-
import { organizationReadModelTables } from "../../sqlite/schema/index.js";
|
|
3
2
|
import { organizationDataUsageSnapshots } from "../../sqlite/schema/organizationDataUsageSchema.js";
|
|
4
3
|
import { organizationReadModelContainerGrants, organizationReadModelDirectoryUsers, organizationReadModelGroupMembers, organizationReadModelGroups, organizationReadModelRequesters, organizationReadModelState, } from "../../sqlite/schema/organizationReadModelSchema.js";
|
|
5
|
-
import { getClientSQLitePersistenceRuntime, } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
6
|
-
import { ensureSqlTables } from "../../sqlite/sqlSchema.js";
|
|
7
|
-
import { notifyOrganizationReadModelInvalidated } from "./organizationReadModelInvalidation.js";
|
|
8
|
-
import { OrganizationReadModelIntegrityError } from "./organizationReadModelProtocol.js";
|
|
9
4
|
/**
|
|
10
5
|
* Rows for users the persisted directory does not list as active. The
|
|
11
6
|
* exclusion is one anti-join against the directory rows rather than a bound
|
|
@@ -72,37 +67,4 @@ export async function purgeOrganizationReadModelProjectionInTransaction(input) {
|
|
|
72
67
|
.where(eq(organizationReadModelState.organizationId, input.organizationId))
|
|
73
68
|
.run();
|
|
74
69
|
}
|
|
75
|
-
/**
|
|
76
|
-
* The ONE load shell for the durable read-model projection: run `load` in a
|
|
77
|
-
* transaction and, if a stored row fails integrity validation, purge the
|
|
78
|
-
* organization's projection and report null. The projection is a
|
|
79
|
-
* server-refetchable cache, so the next reconcile requests a cursorless
|
|
80
|
-
* snapshot instead of every read and repair pass failing on the same row.
|
|
81
|
-
*/
|
|
82
|
-
export async function loadWithOrganizationReadModelIntegrityPurge(input) {
|
|
83
|
-
await ensureSqlTables(input.execSql, organizationReadModelTables);
|
|
84
|
-
let purgedInvalidRows = false;
|
|
85
|
-
const result = await getClientSQLitePersistenceRuntime(input.execSql).transaction(async (tx) => {
|
|
86
|
-
try {
|
|
87
|
-
return await input.load(tx);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
if (!(error instanceof OrganizationReadModelIntegrityError)) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
await purgeOrganizationReadModelProjectionInTransaction({
|
|
94
|
-
organizationId: input.organizationId,
|
|
95
|
-
tx,
|
|
96
|
-
});
|
|
97
|
-
purgedInvalidRows = true;
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
if (purgedInvalidRows) {
|
|
102
|
-
// Realtime consumers may hold a caught-up lease over rows that no longer
|
|
103
|
-
// exist; the notification lets them drop it and refetch authoritatively.
|
|
104
|
-
notifyOrganizationReadModelInvalidated(input.execSql, input.organizationId);
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
70
|
//# sourceMappingURL=organizationReadModelPurge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationReadModelPurge.js","sourceRoot":"","sources":["organizationReadModelPurge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,EAAE,EAAE,EAAE,EAAE,SAAS,EAAY,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,EACL,oCAAoC,EACpC,mCAAmC,EACnC,iCAAiC,EACjC,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAEL,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,sCAAsC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAEtF;;;;GAIG;AACH,SAAS,iBAAiB,CACxB,KAIC,EACD,oBAA4B,EAC5B,YAAoB;IAEpB,MAAM,SAAS,GAAG,mCAAmC,CAAC;IACtD,OAAO,GAAG,CACR,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC,cAAc,CAAC,EAC9C,EAA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zB,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,mCAAmC,CAAC,EAAE,CAAC;gBAC5D,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,iDAAiD,CAAC;gBACtD,cAAc,EAAE,KAAK,CAAC,cAAc;gBACpC,EAAE;aACH,CAAC,CAAC;YACH,iBAAiB,GAAG,IAAI,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;IACH,IAAI,iBAAiB,EAAE,CAAC;QACtB,yEAAyE;QACzE,yEAAyE;QACzE,sCAAsC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { and, type Column, eq, ne, notExists, type SQL } from \"drizzle-orm\";\nimport { organizationReadModelTables } from \"../../sqlite/schema\";\nimport { organizationDataUsageSnapshots } from \"../../sqlite/schema/organizationDataUsageSchema\";\nimport {\n organizationReadModelContainerGrants,\n organizationReadModelDirectoryUsers,\n organizationReadModelGroupMembers,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport { notifyOrganizationReadModelInvalidated } from \"./organizationReadModelInvalidation\";\nimport { OrganizationReadModelIntegrityError } from \"./organizationReadModelProtocol\";\n\n/**\n * Rows for users the persisted directory does not list as active. The\n * exclusion is one anti-join against the directory rows rather than a bound\n * list, so an organization of any size fits SQLite's bound-variable budget.\n */\nfunction inactiveUserScope(\n input: {\n readonly organizationId: string;\n readonly retainUserId: string;\n readonly tx: ClientSQLiteTransactionScope;\n },\n organizationIdColumn: Column,\n userIdColumn: Column,\n): SQL | undefined {\n const directory = organizationReadModelDirectoryUsers;\n return and(\n eq(organizationIdColumn, input.organizationId),\n ne(userIdColumn, input.retainUserId),\n notExists(\n input.tx\n .select({ userId: directory.userId })\n .from(directory)\n .where(\n and(\n eq(directory.organizationId, input.organizationId),\n eq(directory.userId, userIdColumn),\n eq(directory.status, \"active\"),\n ),\n ),\n ),\n );\n}\n\n/**\n * Retire requester rows — and the requester-scoped usage projections beside\n * them — for users the just-applied authoritative directory no longer lists as\n * active. Without this, a removed member whose identity shares the database\n * keeps presentation access until it personally sees a 403. The applying\n * requester's own rows are never pruned here: the server response that\n * carried this directory already proved that user's access. The caller must\n * have replaced the organization's directory rows earlier in `tx`.\n */\nexport async function pruneInactiveOrganizationRequestersInTransaction(input: {\n readonly organizationId: string;\n readonly retainUserId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelRequesters)\n .where(\n inactiveUserScope(\n input,\n organizationReadModelRequesters.organizationId,\n organizationReadModelRequesters.userId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationDataUsageSnapshots)\n .where(\n inactiveUserScope(\n input,\n organizationDataUsageSnapshots.organizationId,\n organizationDataUsageSnapshots.requesterUserId,\n ),\n )\n .run();\n}\n\n/**\n * Delete the shared projection rows for one organization. By default every\n * requester row falls with them; `onlyRequesterUserId` scopes the requester\n * delete to that user for rebuilds where the shared rows are about to be\n * replaced authoritatively — other local identities keep their rows and read\n * the replacement instead of losing access until their own next reconcile.\n */\nexport async function purgeOrganizationReadModelProjectionInTransaction(input: {\n readonly onlyRequesterUserId?: string | undefined;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelContainerGrants)\n .where(\n eq(\n organizationReadModelContainerGrants.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelGroupMembers)\n .where(\n eq(\n organizationReadModelGroupMembers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelDirectoryUsers)\n .where(\n eq(\n organizationReadModelDirectoryUsers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, input.organizationId))\n .run();\n await input.tx\n .delete(organizationReadModelRequesters)\n .where(\n input.onlyRequesterUserId === undefined\n ? eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n )\n : and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(\n organizationReadModelRequesters.userId,\n input.onlyRequesterUserId,\n ),\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelState)\n .where(eq(organizationReadModelState.organizationId, input.organizationId))\n .run();\n}\n\n/**\n * The ONE load shell for the durable read-model projection: run `load` in a\n * transaction and, if a stored row fails integrity validation, purge the\n * organization's projection and report null. The projection is a\n * server-refetchable cache, so the next reconcile requests a cursorless\n * snapshot instead of every read and repair pass failing on the same row.\n */\nexport async function loadWithOrganizationReadModelIntegrityPurge<T>(input: {\n readonly execSql: ExecSql;\n readonly load: (tx: ClientSQLiteTransactionScope) => Promise<T | null>;\n readonly organizationId: string;\n}): Promise<T | null> {\n await ensureSqlTables(input.execSql, organizationReadModelTables);\n let purgedInvalidRows = false;\n const result = await getClientSQLitePersistenceRuntime(\n input.execSql,\n ).transaction(async (tx) => {\n try {\n return await input.load(tx);\n } catch (error) {\n if (!(error instanceof OrganizationReadModelIntegrityError)) {\n throw error;\n }\n await purgeOrganizationReadModelProjectionInTransaction({\n organizationId: input.organizationId,\n tx,\n });\n purgedInvalidRows = true;\n return null;\n }\n });\n if (purgedInvalidRows) {\n // Realtime consumers may hold a caught-up lease over rows that no longer\n // exist; the notification lets them drop it and refetch authoritatively.\n notifyOrganizationReadModelInvalidated(input.execSql, input.organizationId);\n }\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organizationReadModelPurge.js","sourceRoot":"","sources":["organizationReadModelPurge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,EAAE,EAAE,EAAE,EAAE,SAAS,EAAY,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,EACL,oCAAoC,EACpC,mCAAmC,EACnC,iCAAiC,EACjC,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,iDAAiD,CAAC;AAGzD;;;;GAIG;AACH,SAAS,iBAAiB,CACxB,KAIC,EACD,oBAA4B,EAC5B,YAAoB;IAEpB,MAAM,SAAS,GAAG,mCAAmC,CAAC;IACtD,OAAO,GAAG,CACR,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC,cAAc,CAAC,EAC9C,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,EACpC,SAAS,CACP,KAAK,CAAC,EAAE;SACL,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;SACpC,IAAI,CAAC,SAAS,CAAC;SACf,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,EAClD,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,EAClC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC/B,CACF,CACJ,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gDAAgD,CAAC,KAItE;IACC,MAAM,KAAK,CAAC,EAAE;SACX,MAAM,CAAC,+BAA+B,CAAC;SACvC,KAAK,CACJ,iBAAiB,CACf,KAAK,EACL,+BAA+B,CAAC,cAAc,EAC9C,+BAA+B,CAAC,MAAM,CACvC,CACF;SACA,GAAG,EAAE,CAAC;IAC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A,+BAA+B,CAAC,MAAM,EACtC,KAAK,CAAC,mBAAmB,CAC1B,CACF,CACN;SACA,GAAG,EAAE,CAAC;IACT,MAAM,KAAK,CAAC,EAAE;SACX,MAAM,CAAC,0BAA0B,CAAC;SAClC,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;SAC1E,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { and, type Column, eq, ne, notExists, type SQL } from \"drizzle-orm\";\nimport { organizationDataUsageSnapshots } from \"../../sqlite/schema/organizationDataUsageSchema\";\nimport {\n organizationReadModelContainerGrants,\n organizationReadModelDirectoryUsers,\n organizationReadModelGroupMembers,\n organizationReadModelGroups,\n organizationReadModelRequesters,\n organizationReadModelState,\n} from \"../../sqlite/schema/organizationReadModelSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\n\n/**\n * Rows for users the persisted directory does not list as active. The\n * exclusion is one anti-join against the directory rows rather than a bound\n * list, so an organization of any size fits SQLite's bound-variable budget.\n */\nfunction inactiveUserScope(\n input: {\n readonly organizationId: string;\n readonly retainUserId: string;\n readonly tx: ClientSQLiteTransactionScope;\n },\n organizationIdColumn: Column,\n userIdColumn: Column,\n): SQL | undefined {\n const directory = organizationReadModelDirectoryUsers;\n return and(\n eq(organizationIdColumn, input.organizationId),\n ne(userIdColumn, input.retainUserId),\n notExists(\n input.tx\n .select({ userId: directory.userId })\n .from(directory)\n .where(\n and(\n eq(directory.organizationId, input.organizationId),\n eq(directory.userId, userIdColumn),\n eq(directory.status, \"active\"),\n ),\n ),\n ),\n );\n}\n\n/**\n * Retire requester rows — and the requester-scoped usage projections beside\n * them — for users the just-applied authoritative directory no longer lists as\n * active. Without this, a removed member whose identity shares the database\n * keeps presentation access until it personally sees a 403. The applying\n * requester's own rows are never pruned here: the server response that\n * carried this directory already proved that user's access. The caller must\n * have replaced the organization's directory rows earlier in `tx`.\n */\nexport async function pruneInactiveOrganizationRequestersInTransaction(input: {\n readonly organizationId: string;\n readonly retainUserId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelRequesters)\n .where(\n inactiveUserScope(\n input,\n organizationReadModelRequesters.organizationId,\n organizationReadModelRequesters.userId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationDataUsageSnapshots)\n .where(\n inactiveUserScope(\n input,\n organizationDataUsageSnapshots.organizationId,\n organizationDataUsageSnapshots.requesterUserId,\n ),\n )\n .run();\n}\n\n/**\n * Delete the shared projection rows for one organization. By default every\n * requester row falls with them; `onlyRequesterUserId` scopes the requester\n * delete to that user for rebuilds where the shared rows are about to be\n * replaced authoritatively — other local identities keep their rows and read\n * the replacement instead of losing access until their own next reconcile.\n */\nexport async function purgeOrganizationReadModelProjectionInTransaction(input: {\n readonly onlyRequesterUserId?: string | undefined;\n readonly organizationId: string;\n readonly tx: ClientSQLiteTransactionScope;\n}): Promise<void> {\n await input.tx\n .delete(organizationReadModelContainerGrants)\n .where(\n eq(\n organizationReadModelContainerGrants.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelGroupMembers)\n .where(\n eq(\n organizationReadModelGroupMembers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelDirectoryUsers)\n .where(\n eq(\n organizationReadModelDirectoryUsers.organizationId,\n input.organizationId,\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelGroups)\n .where(eq(organizationReadModelGroups.organizationId, input.organizationId))\n .run();\n await input.tx\n .delete(organizationReadModelRequesters)\n .where(\n input.onlyRequesterUserId === undefined\n ? eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n )\n : and(\n eq(\n organizationReadModelRequesters.organizationId,\n input.organizationId,\n ),\n eq(\n organizationReadModelRequesters.userId,\n input.onlyRequesterUserId,\n ),\n ),\n )\n .run();\n await input.tx\n .delete(organizationReadModelState)\n .where(eq(organizationReadModelState.organizationId, input.organizationId))\n .run();\n}\n"]}
|