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

Function entryAtUndeclaredKey

ark/sets/roots/union.ts:2802–2838  ·  view source on GitHub ↗
(
	node: BaseRoot,
	entry: DisjointEntry,
	depth: number,
	check: UndeclaredKeyCheck
)

Source from the content-addressed store, hash-verified

2800// follows an entry's path through the props a node declares to the first key it
2801// doesn't, where check decides
2802const entryAtUndeclaredKey = (
2803 node: BaseRoot,
2804 entry: DisjointEntry,
2805 depth: number,
2806 check: UndeclaredKeyCheck
2807): boolean => {
2808 if (depth >= entry.path.length) return false
2809 if (node.is("alias")) {
2810 return isResolutionFinal() ?
2811 entryAtUndeclaredKey(node.resolution, entry, depth, check)
2812 : false
2813 }
2814 if (node.is("union"))
2815 return node.branches.some(b => entryAtUndeclaredKey(b, entry, depth, check))
2816 if (!node.is("intersection") || !node.structure) return false
2817 const key = entry.path[depth]
2818 if (typeof key === "number") {
2819 const sequence = node.structure.sequence
2820 if (!sequence) return false
2821 if (!sequence.postfix) {
2822 const element =
2823 key < sequence.leading.length ?
2824 sequence.tuple[key].node
2825 : sequence.variadic
2826 return element ?
2827 entryAtUndeclaredKey(element, entry, depth + 1, check)
2828 : false
2829 }
2830 return sequence.tuple.some(el =>
2831 entryAtUndeclaredKey(el.node, entry, depth + 1, check)
2832 )
2833 }
2834 const prop = node.structure.byKey[key]
2835 return prop ?
2836 entryAtUndeclaredKey(prop.value, entry, depth + 1, check)
2837 : check(node.structure, entry, depth, key)
2838}
2839
2840export const writeIndiscriminableMorphMessage = (
2841 lDescription: string,

Callers 2

leavesKeyOverlapAtFunction · 0.85

Calls 3

isResolutionFinalFunction · 0.90
isMethod · 0.80
checkFunction · 0.50

Tested by

no test coverage detected