MCPcopy Create free account
hub / github.com/arktypeio/arktype / constRoot

Function constRoot

ark/sets/fromJsonSchema.ts:1400–1432  ·  view source on GitHub ↗
(
	value: unknown,
	pointer: string,
	depth = 0,
	seen: Set<object> = new Set()
)

Source from the content-addressed store, hash-verified

1398}
1399
1400const constRoot = (
1401 value: unknown,
1402 pointer: string,
1403 depth = 0,
1404 seen: Set<object> = new Set()
1405): BaseRoot => {
1406 const isArr = isArray(value)
1407 if (!isArr && !isJsonSchemaObject(value))
1408 return jsonSchemaRoot({ unit: value })
1409 if (depth >= maxValueDepth)
1410 return throwParseError(writeMaxDepthMessage(pointer, maxValueDepth))
1411 if (seen.has(value))
1412 return throwParseError(writeCircularSchemaMessage(pointer))
1413 seen.add(value)
1414 try {
1415 return isArr ?
1416 jsonSchemaRoot(
1417 value.length === 0 ?
1418 { proto: Array, exactLength: 0 }
1419 : {
1420 proto: Array,
1421 sequence: {
1422 prefix: value.map((v, i) =>
1423 constRoot(v, `${pointer}/${i}`, depth + 1, seen)
1424 )
1425 }
1426 }
1427 )
1428 : constObjectRoot(value, pointer, depth + 1, seen)
1429 } finally {
1430 seen.delete(value)
1431 }
1432}
1433
1434// one predicate per keyword and subschemas, so equal reads relate
1435const predicatesByKey = /* @__PURE__ */ new WeakCache<Predicate>()

Callers 2

fromJsonSchema.tsFile · 0.85
constObjectRootFunction · 0.85

Calls 10

throwParseErrorFunction · 0.90
isJsonSchemaObjectFunction · 0.85
jsonSchemaRootFunction · 0.85
writeMaxDepthMessageFunction · 0.85
constObjectRootFunction · 0.85
mapMethod · 0.65
hasMethod · 0.45
addMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected