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

Function writeShape

ark/type/standalone/combinators.ts:1035–1068  ·  view source on GitHub ↗
(
	js: CombinatorCompiler,
	node: IntersectionNode
)

Source from the content-addressed store, hash-verified

1033
1034// an intersection one of the runtime's shapes checks, as one call
1035const writeShape = (
1036 js: CombinatorCompiler,
1037 node: IntersectionNode
1038): string | undefined => {
1039 const { basis, structure, preStruct } = node
1040 if (!basis || node.inner.predicate) return
1041 const checked = writeCheck(js, basis)
1042 if (checked === "runtime.stringCheck" && !structure) {
1043 const rules = rulesOf(preStruct, ["maxLength", "minLength"])
1044 if (rules) return writeCall("stringRange", ...writeRules(rules))
1045 }
1046 if (checked === "runtime.numberCheck" && !structure) {
1047 const rules = rulesOf(preStruct, ["divisor", "max", "min"])
1048 if (rules?.[0] === 1)
1049 return writeCall("integerRange", ...writeRules([rules[2], rules[1]]))
1050 }
1051 if (checked === "runtime.arrayCheck" && structure?.sequence) {
1052 const element = structure.sequence.variadic!
1053 const failing = element.hasAlias || element.hasMorph
1054 const rules =
1055 (!element.tfs || failing) &&
1056 rulesOf(preStruct, ["maxLength", "minLength"], arrayLengthDescriptionOf)
1057 if (rules) {
1058 return element.tfs ?
1059 writeCall(
1060 "failingArrayOf",
1061 readValue(js, element),
1062 ...writeRules(rules),
1063 element.hasAlias ? "1" : undefined
1064 )
1065 : writeCall("arrayOf", readValue(js, element), ...writeRules(rules))
1066 }
1067 }
1068}
1069
1070const readChecker = (js: CombinatorCompiler, node: BaseRoot): string =>
1071 isInlined(node) ? writeCombinator(js, node)!

Callers 1

Calls 5

writeCheckFunction · 0.85
rulesOfFunction · 0.85
writeCallFunction · 0.85
writeRulesFunction · 0.85
readValueFunction · 0.85

Tested by

no test coverage detected