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

Method _traverse

ark/schema/structure/structure.ts:604–707  ·  view source on GitHub ↗
(
		trav: TraversalKind,
		data: object,
		ctx: InternalTraversal,
		transformsKeys = true,
		// whether code compiled to write in place called it
		inPlace = false
	)

Source from the content-addressed store, hash-verified

602 }
603
604 protected _traverse(
605 trav: TraversalKind,
606 data: object,
607 ctx: InternalTraversal,
608 transformsKeys = true,
609 // whether code compiled to write in place called it
610 inPlace = false
611 ): boolean {
612 const errN = ctx?.errN ?? 0
613 const valueOf = (node: BaseRoot): BaseNode =>
614 inPlace ? inPlaceShapeOf(node) : node
615 const props = trav === "Allows" ? this.allowsProps : this.inOrder
616 for (let i = 0; i < props.length; i++) {
617 const prop = props[i]
618 if (trav === "Allows") {
619 if (!prop.tAllows(data, ctx)) return false
620 } else {
621 // a prop's Apply would transform before an index signature checks it
622 if (transformsKeys) prop.tApply(data as never, ctx)
623 else if (prop.key in data) {
624 travKey(
625 prop.key,
626 () =>
627 applyValue(
628 valueOf(prop.value),
629 data[prop.key as never],
630 ctx,
631 false
632 ),
633 ctx
634 )
635 } else if (prop.is("required"))
636 travKey(prop.key, () => ctx.nodeError(prop.errorCtx, data), ctx)
637
638 if (ctx.failFast && ctx.errN > errN) return false
639 }
640 }
641
642 if (this.sequence) {
643 if (trav === "Allows") {
644 if (!this.sequence.tAllows(data as never, ctx)) return false
645 } else {
646 this.sequence.tApply(data as never, ctx)
647 if (ctx.failFast && ctx.errN > errN) return false
648 }
649 }
650
651 if (this.index || this.undeclared === "reject") {
652 const keys = this.index ? ownKeysOf(data) : Object.keys(data)
653 const isArray = Array.isArray(data)
654
655 for (let i = 0; i < keys.length; i++) {
656 const k = keys[i]
657
658 if (this.index) {
659 const pathKey = isArray ? arrayPathKeyOf(k) : k
660 for (const node of this.index) {
661 if (node.allowsKey(k, ctx)) {

Callers 3

tAllowsMethod · 0.95
tApplyMethod · 0.95
applySharedKeysMethod · 0.95

Calls 10

travKeyFunction · 0.90
applyValueFunction · 0.90
arrayPathKeyOfFunction · 0.90
errorFromContextFunction · 0.90
ownKeysOfFunction · 0.85
isMethod · 0.80
valueOfFunction · 0.50
tAllowsMethod · 0.45
tApplyMethod · 0.45
nodeErrorMethod · 0.45

Tested by

no test coverage detected