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

Method enrichChangeMessage

packages/db/src/collection/state.ts:310–333  ·  view source on GitHub ↗

* Creates a change message with virtual properties. * Uses the "add-if-missing" pattern so that pass-through from upstream * collections works correctly.

(
    change: ChangeMessage<TOutput, TKey>,
  )

Source from the content-addressed store, hash-verified

308 * collections works correctly.
309 */
310 public enrichChangeMessage(
311 change: ChangeMessage<TOutput, TKey>,
312 ): ChangeMessage<WithVirtualProps<TOutput, TKey>, TKey> {
313 const { __virtualProps } = change as InternalChangeMessage<TOutput, TKey>
314 const enrichedValue = __virtualProps?.value
315 ? this.enrichWithVirtualPropsSnapshot(change.value, __virtualProps.value)
316 : this.enrichWithVirtualProps(change.value, change.key)
317 const enrichedPreviousValue = change.previousValue
318 ? __virtualProps?.previousValue
319 ? this.enrichWithVirtualPropsSnapshot(
320 change.previousValue,
321 __virtualProps.previousValue,
322 )
323 : this.enrichWithVirtualProps(change.previousValue, change.key)
324 : undefined
325
326 return {
327 key: change.key,
328 type: change.type,
329 value: enrichedValue,
330 previousValue: enrichedPreviousValue,
331 metadata: change.metadata,
332 } as ChangeMessage<WithVirtualProps<TOutput, TKey>, TKey>
333 }
334
335 /**
336 * Get the current value for a key enriched with virtual properties.

Callers 1

Calls 2

Tested by

no test coverage detected