MCPcopy Create free account
hub / github.com/Miosa-osa/BusinessOS / mergeOperations

Method mergeOperations

desktop/src/main/sync/queue.ts:74–100  ·  view source on GitHub ↗

* Merge two operations on the same record

(
    existing: SyncOperation,
    incoming: SyncOperation
  )

Source from the content-addressed store, hash-verified

72 * Merge two operations on the same record
73 */
74 private mergeOperations(
75 existing: SyncOperation,
76 incoming: SyncOperation
77 ): SyncOperation | null {
78 // Create + Delete = null (cancel out)
79 if (existing === 'create' && incoming === 'delete') {
80 return null;
81 }
82
83 // Create + Update = Create (with new payload)
84 if (existing === 'create' && incoming === 'update') {
85 return 'create';
86 }
87
88 // Update + Delete = Delete
89 if (existing === 'update' && incoming === 'delete') {
90 return 'delete';
91 }
92
93 // Update + Update = Update (with new payload)
94 if (existing === 'update' && incoming === 'update') {
95 return 'update';
96 }
97
98 // For all other cases, use the incoming operation
99 return incoming;
100 }
101
102 /**
103 * Get all pending items in the queue

Callers 1

enqueueMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected