Home / Function/ upsertOperation() — supabase Function Reference

upsertOperation() — supabase Function Reference

Architecture documentation for the upsertOperation() function in queueConflictResolution.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  9b281136_50fc_db48_fd92_e34bfb615e42["upsertOperation()"]
  3722bac8_b656_267a_d2e2_c3ec91d59be4["generateTableChangeKey()"]
  9b281136_50fc_db48_fd92_e34bfb615e42 -->|calls| 3722bac8_b656_267a_d2e2_c3ec91d59be4
  style 9b281136_50fc_db48_fd92_e34bfb615e42 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/grid/utils/queueConflictResolution.ts lines 143–175

export function upsertOperation(
  operations: readonly QueuedOperation[],
  newOperation: NewQueuedOperation
): UpsertResult {
  const operationKey = generateTableChangeKey(newOperation)
  const existingOpIndex = operations.findIndex((op) => op.id === operationKey)

  const queuedOperation: QueuedOperation = {
    ...newOperation,
    id: operationKey,
    timestamp: Date.now(),
  }

  if (existingOpIndex >= 0) {
    const updatedOperations = [...operations]

    // Keep the old value of the operation that is being overwritten
    // When a user edits the same cell multiple times before saving,
    // we need to preserve the original "before edit" value
    const existingOp = operations[existingOpIndex]
    if (
      queuedOperation.type === QueuedOperationType.EDIT_CELL_CONTENT &&
      existingOp.type === QueuedOperationType.EDIT_CELL_CONTENT
    ) {
      queuedOperation.payload.oldValue = existingOp.payload.oldValue
    }

    updatedOperations[existingOpIndex] = queuedOperation
    return { operations: updatedOperations }
  }

  return { operations: [...operations, queuedOperation] }
}

Subdomains

Frequently Asked Questions

What does upsertOperation() do?
upsertOperation() is a function in the supabase codebase.
What does upsertOperation() call?
upsertOperation() calls 1 function(s): generateTableChangeKey.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free