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

Function deferDefinition

ark/type/deferred.ts:1537–1573  ·  view source on GitHub ↗
(
	def: unknown,
	$: InternalScope
)

Source from the content-addressed store, hash-verified

1535}
1536
1537export const deferDefinition = (
1538 def: unknown,
1539 $: InternalScope
1540): BaseRoot | undefined => {
1541 if (!canDefer($)) return
1542 if (deferred.has(def as object)) return def as BaseRoot
1543 if (typeof def === "string") {
1544 const facts = scanLeaf(def)
1545 // a string could be what another route has reached once nodes exist, and
1546 // it's few and cached, so it's parsed from then on
1547 return (
1548 !facts || facts.defaults ? undefined
1549 : lastCreated ? ($.nodesByKey.get(facts.key) as never)
1550 : defer(facts, $, () => $.parseDef(def))
1551 )
1552 }
1553 if (def instanceof RegExp) {
1554 const facts = regexFacts(def)
1555 return facts && defer(facts, $, () => $.parseDef(def))
1556 }
1557 if (typeof def !== "object" || !def || !isPlainObject(def)) return
1558 const facts: Facts = {
1559 key: "",
1560 domains: objectBits,
1561 pure: true,
1562 literal: true
1563 }
1564 let literal: Dict | undefined
1565 try {
1566 literal = walkLiteral(def as Dict, facts)
1567 } catch {
1568 return
1569 }
1570 if (!literal) return
1571 const copy = literal
1572 return defer(facts, $, () => $.parseDef(copy))
1573}

Callers 5

constructorMethod · 0.90
keywords.tsFile · 0.90
deferUnionFunction · 0.85
deferred.tsFile · 0.85
deferUnitsFunction · 0.85

Calls 8

canDeferFunction · 0.85
scanLeafFunction · 0.85
deferFunction · 0.85
regexFactsFunction · 0.85
isPlainObjectFunction · 0.85
walkLiteralFunction · 0.85
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected