MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / applyWrite

Function applyWrite

apps/cloud/src/auth/workos-mirror-store.ts:973–992  ·  view source on GitHub ↗
(writes: Writes, write: WorkOsMirrorWrite)

Source from the content-addressed store, hash-verified

971type Writes = ReturnType<typeof makeWrites>;
972
973const applyWrite = (writes: Writes, write: WorkOsMirrorWrite): Promise<WorkOsMirrorWriteOutcome> =>
974 WorkOsMirrorWrite.$match(write, {
975 UpsertUser: async ({ user }) => ((await writes.upsertUser(user)) ? "applied" : "stale"),
976 UpsertMembership: async ({ membership }) =>
977 (await writes.upsertMembership(membership)) ? "applied" : "stale",
978 UpsertMember: async ({ user, membership }) => {
979 await writes.upsertUser(user);
980 return (await writes.upsertMembership(membership)) ? "applied" : "stale";
981 },
982 DeleteMembership: async ({ membership, deletedAt }) =>
983 (await writes.deleteMembership(membership, deletedAt)) ? "applied" : "absent",
984 DeleteUser: async ({ accountId, deletedAt }) =>
985 (await writes.deleteUser(accountId, deletedAt)) ? "applied" : "absent",
986 RenameOrganization: ({ organizationId, name, updatedAt }) =>
987 writes.renameOrganization(organizationId, name, updatedAt),
988 MarkOrganizationDeleted: async ({ organizationId, name, deletedAt }) =>
989 (await writes.markOrganizationDeleted(organizationId, name, deletedAt))
990 ? "applied"
991 : "absent",
992 });
993
994// Compare-and-set the events cursor. Run inside a transaction this also
995// LOCKS the cursor row until commit: a concurrent run's CAS waits here, then

Callers 1

makeWorkOsMirrorStoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected