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

Function enrichRowWithVirtualProps

packages/db/src/virtual-props.ts:201–222  ·  view source on GitHub ↗
(
  row: T,
  key: TKey,
  collectionId: string,
  computeSynced: () => boolean,
  computeOrigin: () => VirtualOrigin,
)

Source from the content-addressed store, hash-verified

199 * @internal
200 */
201export function enrichRowWithVirtualProps<
202 T extends object,
203 TKey extends string | number,
204>(
205 row: T,
206 key: TKey,
207 collectionId: string,
208 computeSynced: () => boolean,
209 computeOrigin: () => VirtualOrigin,
210): WithVirtualProps<T, TKey> {
211 // Use nullish coalescing to preserve existing virtual properties (pass-through)
212 // This is the "add-if-missing" pattern described in the RFC
213 const existingRow = row as Partial<VirtualRowProps<TKey>>
214
215 return {
216 ...row,
217 $synced: existingRow.$synced ?? computeSynced(),
218 $origin: existingRow.$origin ?? computeOrigin(),
219 $key: existingRow.$key ?? key,
220 $collectionId: existingRow.$collectionId ?? collectionId,
221 } as WithVirtualProps<T, TKey>
222}
223
224/**
225 * Computes aggregate virtual properties for a group of rows.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected