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

Function writeSitedAllows

ark/type/standalone/combinators.ts:683–706  ·  view source on GitHub ↗
(structure: StructureNode, refs: string[])

Source from the content-addressed store, hash-verified

681// false where a key's check fails, stopping at the first as a walker does, then
682// where data holds a key it rejects, for...in also reaching inherited keys
683const writeSitedAllows = (structure: StructureNode, refs: string[]): string => {
684 const fails = structure.inOrder
685 .map((prop, i) => {
686 const has = `${JSON.stringify(prop.key)} in data`
687 // keys holding the same check call the same checker
688 const checker =
689 /^runtime\.\w+$/.test(refs[i]) ?
690 refs[i]
691 : `checkers[${refs.indexOf(refs[i])}]`
692 const fail = `!${checker}(data${writeAccess(prop.key as string)})`
693 return (
694 prop.is("optional") ? `(${has} && ${fail})`
695 : failsUndefined(prop.value) ? fail
696 : `(!(${has}) || ${fail})`
697 )
698 })
699 .join(" || ")
700 if (structure.handlesUndeclared !== "reject")
701 return `(data, checkers) => !(${fails})`
702 const declared = structure.inOrder
703 .map(prop => `case ${JSON.stringify(prop.key)}:`)
704 .join(" ")
705 return `(data, checkers) => { if (${fails}) return false; for (const k in data) switch (k) { ${declared} break; default: if (Object.prototype.hasOwnProperty.call(data, k)) return false; } return true; }`
706}
707
708// what a key reads through its checker's transform, where it has one
709const writeHeld = (prop: Prop.Node, i: number, failing: boolean): string => {

Callers 1

writeStructureFunction · 0.85

Calls 5

writeAccessFunction · 0.85
failsUndefinedFunction · 0.85
testMethod · 0.80
isMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected