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

Function assertDescribed

ark/type/standalone/sites.ts:46–82  ·  view source on GitHub ↗
(root: BaseRoot)

Source from the content-addressed store, hash-verified

44
45// a site's text is written from the program's config, so a scope's own isn't, nor a callback's
46export const assertDescribed = (root: BaseRoot): void => {
47 const config = root.$.cfg
48 const raisable = raisableCodesOf(root)
49 let code: ArkErrorCode
50 for (code in errorWritersByCode) {
51 if (raisable !== "any" && !raisable.has(code)) continue
52 for (const k of describingKeys) {
53 const writer = config[code][k]
54 if (writer === $ark.defaultConfig[code][k]) continue
55 const reason =
56 writer !== $ark.cfg![code][k] ? `a scope's configured ${code} ${k}`
57 // a callback raises with code predicate unless it names another
58 : raisable === "any" && code === "predicate" ?
59 `a configured ${code} ${k} that a narrow or morph raises`
60 : (
61 typeof writer === "function" &&
62 k !== "actual" &&
63 unwritableCodes.has(code)
64 ) ?
65 `a configured ${code} ${k} writer, which reads each branch's errors`
66 : undefined
67 if (reason) throwParseError(writeUnprecompilableMessage(reason))
68 }
69 }
70 if (raisable === "any") assertKeepsReportKeys(root)
71 for (const node of writtenSelectedOf(rootUnitsOf(root), isUnion)) {
72 for (const k of describingKeys) {
73 if (k !== "actual" && typeof node.meta[k] === "function") {
74 throwParseError(
75 writeUnprecompilableMessage(
76 `\`${node.expression}\`'s ${k} writer, which reads each branch's errors`
77 )
78 )
79 }
80 }
81 }
82}
83
84// a key a narrow or morph passes its ctx's reject() or error(), which arktype's
85// error keeps, would be on it in development and gone from it in production

Callers 1

attributesOfMethod · 0.90

Calls 7

throwParseErrorFunction · 0.90
writtenSelectedOfFunction · 0.90
rootUnitsOfFunction · 0.90
raisableCodesOfFunction · 0.85
assertKeepsReportKeysFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected