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

Function toStableSerializable

packages/electric-db-collection/src/electric.ts:332–358  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

330}
331
332function toStableSerializable(value: unknown): unknown {
333 if (value == null) {
334 return value
335 }
336
337 if (Array.isArray(value)) {
338 return value.map((entry) => toStableSerializable(entry))
339 }
340
341 if (value instanceof Date) {
342 return value.toISOString()
343 }
344
345 if (typeof value === `object`) {
346 const record = value as Record<string, unknown>
347 const stableRecord: Record<string, unknown> = {}
348 const keys = Object.keys(record).sort((left, right) =>
349 left < right ? -1 : left > right ? 1 : 0,
350 )
351 for (const key of keys) {
352 stableRecord[key] = toStableSerializable(record[key])
353 }
354 return stableRecord
355 }
356
357 return value
358}
359
360function getStableShapeIdentity(shapeOptions: {
361 url: string

Callers 1

getStableShapeIdentityFunction · 0.70

Calls 2

mapMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected