MCPcopy
hub / github.com/flightcontrolhq/superjson / walker

Function walker

src/plainer.ts:188–293  ·  view source on GitHub ↗
(
  object: any,
  identities: Map<any, any[][]>,
  superJson: SuperJSON,
  dedupe: boolean,
  path: any[] = [],
  objectsInThisPath: any[] = [],
  seenObjects = new Map<unknown, Result>()
)

Source from the content-addressed store, hash-verified

186}
187
188export const walker = (
189 object: any,
190 identities: Map<any, any[][]>,
191 superJson: SuperJSON,
192 dedupe: boolean,
193 path: any[] = [],
194 objectsInThisPath: any[] = [],
195 seenObjects = new Map<unknown, Result>()
196): Result => {
197 const primitive = isPrimitive(object);
198
199 if (!primitive) {
200 addIdentity(object, path, identities);
201
202 const seen = seenObjects.get(object);
203 if (seen) {
204 // short-circuit result if we've seen this object before
205 return dedupe
206 ? {
207 transformedValue: null,
208 }
209 : seen;
210 }
211 }
212
213 if (!isDeep(object, superJson)) {
214 const transformed = transformValue(object, superJson);
215
216 const result: Result = transformed
217 ? {
218 transformedValue: transformed.value,
219 annotations: [transformed.type],
220 }
221 : {
222 transformedValue: object,
223 };
224 if (!primitive) {
225 seenObjects.set(object, result);
226 }
227 return result;
228 }
229
230 if (includes(objectsInThisPath, object)) {
231 // prevent circular references
232 return {
233 transformedValue: null,
234 };
235 }
236
237 const transformationResult = transformValue(object, superJson);
238 const transformed = transformationResult?.value ?? object;
239
240 const transformedValue: any = isArray(transformed) ? [] : {};
241 const innerAnnotations: Record<string, Tree<TypeAnnotation>> = {};
242
243 forEach(transformed, (value, index) => {
244 if (
245 index === '__proto__' ||

Callers 3

serializeMethod · 0.85
traverseFunction · 0.85
plainer.spec.tsFile · 0.85

Calls 11

isPrimitiveFunction · 0.85
addIdentityFunction · 0.85
isDeepFunction · 0.85
transformValueFunction · 0.85
includesFunction · 0.85
isArrayFunction · 0.85
forEachFunction · 0.85
escapeKeyFunction · 0.85
isPlainObjectFunction · 0.85
isEmptyObjectFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…