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

Function keyFails

ark/schema/shared/compile.ts:503–538  ·  view source on GitHub ↗
(key: string, value: string, node: BaseNode)

Source from the content-addressed store, hash-verified

501 }
502
503 keyFails(key: string, value: string, node: BaseNode): string | undefined {
504 if (this.trav !== "Apply") {
505 const condition = node.jsCond?.(this, value)
506 if (condition !== undefined) return `!(${condition})`
507 if (
508 (this.loopDepth > 0 && isRefinedPattern(node)) ||
509 (node.allowsCtx && node.checksCtx)
510 )
511 return
512 return `!${this.inv(node, { arg: value })}`
513 }
514 if (node.hasMorph || node.hasAlias) return
515 // a value whose predicates read ctx is checked at its key's path
516 if (node.tfs && node.allowsCtx && node.checksCtx) return
517 // transforming values are checked by Allows first
518 const checksAllowsFirst =
519 node.tfs ||
520 ((this.loopDepth > 0 || (node.is("union") && !node.discriminant)) &&
521 isDecidedByAllows(node))
522 const condition =
523 node.is("union") && !checksAllowsFirst ?
524 undefined
525 : node.jsCond?.(this, value)
526 if (condition !== undefined && !node.is("union"))
527 return `!(${condition}) && ${this.error(node, key)}`
528 const allows =
529 !checksAllowsFirst ? ""
530 : isRefinedPattern(node) ?
531 `${this.ref(rejects)}(${this.traversal(node, "Allows")}, ${value}) && `
532 : condition === undefined ? `!${this.allows(node, value)} && `
533 : `!(${condition}) && `
534 // a refined basis Allows rejected failed its basis or its refinement
535 if (checksAllowsFirst && isRefinedBasis(node))
536 return `${allows}${this.failsEither(node.basis!.jsCond(this, value), this.site(node.preStruct[0]), this.site(node.basis!), "data", key)}`
537 return `${allows}${this.failsIn(`${this.traversal(node, "Apply")}, ${this.data}, ${this.applied(key, value)}`)}`
538 }
539
540 // a cyclic value is applied inline
541 private applyKey(key: string, value: string, node: BaseNode): this {

Callers

nothing calls this directly

Calls 14

isRefinedPatternFunction · 0.85
isDecidedByAllowsFunction · 0.85
isRefinedBasisFunction · 0.85
isMethod · 0.80
traversalMethod · 0.80
allowsMethod · 0.80
failsEitherMethod · 0.80
siteMethod · 0.80
appliedMethod · 0.65
jsCondMethod · 0.45
invMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected