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

Function updateHasher

packages/db-ivm/src/hashing/hash.ts:154–188  ·  view source on GitHub ↗
(hasher: Hasher, input: unknown)

Source from the content-addressed store, hash-verified

152}
153
154function updateHasher(hasher: Hasher, input: unknown): void {
155 if (input === null) {
156 hasher.update(NULL)
157 return
158 }
159 switch (typeof input) {
160 case `undefined`:
161 hasher.update(UNDEFINED)
162 return
163 case `boolean`:
164 hasher.update(input ? TRUE : FALSE)
165 return
166 case `number`:
167 // Normalize NaNs and -0
168 hasher.update(isNaN(input) ? NaN : input === 0 ? 0 : input)
169 return
170 case `bigint`:
171 case `string`:
172 case `symbol`:
173 hasher.update(input)
174 return
175 case `object`:
176 hasher.update(getCachedHash(input))
177 return
178 case `function`:
179 // Functions are assigned a globally unique ID
180 // and that ID is cached in the weak map
181 hasher.update(cachedReferenceHash(input))
182 return
183 default:
184 console.warn(
185 `Ignored input during hashing because it is of type ${typeof input} which is not supported`,
186 )
187 }
188}
189
190function getCachedHash(input: object): number {
191 let valueHash = hashCache.get(input)

Callers 2

hashFunction · 0.85
hashPlainObjectFunction · 0.85

Calls 3

getCachedHashFunction · 0.85
cachedReferenceHashFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected