MCPcopy Create free account
hub / github.com/clientdb/clientdb / performMutation

Function performMutation

engine/server/mutation.ts:17–47  ·  view source on GitHub ↗
(
  context: SyncRequestContext,
  input: EntityChange
)

Source from the content-addressed store, hash-verified

15}
16
17export async function performMutation(
18 context: SyncRequestContext,
19 input: EntityChange
20): Promise<void> {
21 const { schema, db } = context;
22
23 if (!getIsChangeDataValid(context, input)) {
24 throw new Error("Invalid change data");
25 }
26
27 if (!(await getIsChangeAllowed(context, input))) {
28 throw new Error("Change is not allowed");
29 }
30
31 const idField = getIdKeyForEntity(schema, input.entity);
32
33 switch (input.type) {
34 case "remove": {
35 db.table(input.entity).where(idField, input.id).delete();
36 return;
37 }
38 case "update": {
39 db.table(input.entity).where(idField, input.id).update(input.data);
40 return;
41 }
42 case "create": {
43 db.table(input.entity).insert(input.data);
44 return;
45 }
46 }
47}

Callers 1

createSyncServerFunction · 0.90

Calls 4

getIsChangeDataValidFunction · 0.90
getIsChangeAllowedFunction · 0.90
getIdKeyForEntityFunction · 0.85
updateMethod · 0.65

Tested by

no test coverage detected