MCPcopy Index your code
hub / github.com/TanStack/db / stableStringifyCollectionIndexValue

Function stableStringifyCollectionIndexValue

packages/db/src/collection/indexes.ts:131–154  ·  view source on GitHub ↗
(
  value: CollectionIndexSerializableValue,
)

Source from the content-addressed store, hash-verified

129}
130
131function stableStringifyCollectionIndexValue(
132 value: CollectionIndexSerializableValue,
133): string {
134 if (value === null) {
135 return `null`
136 }
137
138 if (Array.isArray(value)) {
139 return `[${value.map(stableStringifyCollectionIndexValue).join(`,`)}]`
140 }
141
142 if (typeof value !== `object`) {
143 return JSON.stringify(value)
144 }
145
146 const sortedKeys = Object.keys(value).sort((left, right) =>
147 compareStringsCodePoint(left, right),
148 )
149 const serializedEntries = sortedKeys.map(
150 (key) =>
151 `${JSON.stringify(key)}:${stableStringifyCollectionIndexValue(value[key]!)}`,
152 )
153 return `{${serializedEntries.join(`,`)}}`
154}
155
156function createCollectionIndexMetadata<TKey extends string | number>(
157 indexId: number,

Callers 2

toSerializableIndexValueFunction · 0.85

Calls 4

compareStringsCodePointFunction · 0.85
joinMethod · 0.45
mapMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected