MCPcopy Create free account
hub / github.com/Effect-TS/effect / walk

Function walk

packages/effect/src/JsonSchema.ts:315–371  ·  view source on GitHub ↗
(node: unknown, isRoot: boolean)

Source from the content-addressed store, hash-verified

313 }
314
315 function walk(node: unknown, isRoot: boolean): unknown {
316 if (Array.isArray(node)) return node.map(walkNested)
317 if (!Predicate.isObject(node)) return node
318
319 const out: Record<string, unknown> = {}
320
321 let prefixItems: unknown = undefined
322 let additionalItems: unknown = undefined
323
324 for (const k of Object.keys(node)) {
325 const v = node[k]
326
327 if (k === "$ref") {
328 out.$ref = typeof v === "string" ? v.replace(RE_DEFINITIONS, "#/$defs") : v
329 continue
330 }
331 if (DRAFT_07_COPY_KEYWORDS.has(k)) {
332 out[k] = v
333 continue
334 }
335 if (rewriteSubschemaKeyword(out, k, v, walkNested, DRAFT_07_SINGLE_SUBSCHEMA_KEYWORDS)) continue
336
337 switch (k) {
338 case "definitions": {
339 const mapped = mapObject(v, walkNested)
340 if (isRoot) {
341 definitions = mapped as Definitions | undefined
342 } else {
343 out.definitions = mapped ?? v
344 }
345 break
346 }
347
348 case "items":
349 prefixItems = v
350 break
351 case "additionalItems":
352 additionalItems = v
353 break
354
355 default:
356 break
357 }
358 }
359
360 // Draft-07 tuples -> 2020-12 tuples
361 if (prefixItems !== undefined) {
362 if (Array.isArray(prefixItems)) {
363 out.prefixItems = prefixItems.map(walkNested)
364 if (additionalItems !== undefined) out.items = walkNested(additionalItems)
365 } else {
366 out.items = walkNested(prefixItems)
367 }
368 }
369
370 return out
371 }
372

Callers 4

fromSchemaDraft07Function · 0.70
walkNestedFunction · 0.70
toSchemaDraft04Function · 0.70
transformSchemaFunction · 0.70

Calls 8

rewriteSubschemaKeywordFunction · 0.85
mapObjectFunction · 0.85
walkNestedFunction · 0.85
convertExclusiveBoundFunction · 0.85
transformFunction · 0.70
mapMethod · 0.45
replaceMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected