MCPcopy Create free account
hub / github.com/TanStack/db / wrappedOnUpdate

Function wrappedOnUpdate

packages/db/src/local-storage.ts:473–505  ·  view source on GitHub ↗
(params: UpdateMutationFnParams<any>)

Source from the content-addressed store, hash-verified

471 }
472
473 const wrappedOnUpdate = async (params: UpdateMutationFnParams<any>) => {
474 // Validate that all values in the transaction can be JSON serialized
475 params.transaction.mutations.forEach((mutation) => {
476 validateJsonSerializable(parser, mutation.modified, `update`)
477 })
478
479 // Call the user handler BEFORE persisting changes (if provided)
480 let handlerResult: any = {}
481 if (config.onUpdate) {
482 handlerResult = (await config.onUpdate(params)) ?? {}
483 }
484
485 // Always persist to storage
486 // Use lastKnownData (in-memory cache) instead of reading from storage
487 // Update items with new version keys
488 params.transaction.mutations.forEach((mutation) => {
489 // Use the engine's pre-computed key for consistency
490 const storedItem: StoredItem<any> = {
491 versionKey: generateUuid(),
492 data: mutation.modified,
493 }
494 lastKnownData.set(mutation.key, storedItem)
495 })
496
497 // Save to storage
498 saveToStorage(lastKnownData)
499
500 // Confirm mutations through sync interface (moves from optimistic to synced state)
501 // without reloading from storage
502 sync.confirmOperationsSync(params.transaction.mutations)
503
504 return handlerResult
505 }
506
507 const wrappedOnDelete = async (params: DeleteMutationFnParams<any>) => {
508 // Call the user handler BEFORE persisting changes (if provided)

Callers

nothing calls this directly

Calls 5

validateJsonSerializableFunction · 0.85
generateUuidFunction · 0.85
saveToStorageFunction · 0.85
forEachMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected