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

Class ReadIssues

ark/schema/shared/issuesLean.ts:41–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40// in place of issues.ts, written for size, whose tiers it's chosen from as issues.ts's are
41class ReadIssues implements FailureContext {
42 /** @internal each issue in the order it was added */
43 _: ArkIssue[] = []
44 /** @internal the path a fused traversal is at */
45 _p: PropertyKey[] = []
46
47 /**
48 * The number of issues.
49 */
50 get count(): number {
51 return this._.length
52 }
53
54 /**
55 * Each issue, its message written when they are first read.
56 */
57 get issues(): readonly WrittenIssue[] {
58 return readsIssues ? serializableIssues(this._) : (this._ as WrittenIssue[])
59 }
60
61 /** @internal takes neither a key nor a site, as issues.ts's */
62 _e(
63 data: unknown,
64 code: ArkErrorCode,
65 expected?: string,
66 message?: string,
67 text?: SiteContext["text"]
68 ): true | undefined {
69 this._.push({ code, path: this._p.slice(), data, expected, message })
70 if (callsSiteText) text?.(this._[this._.length - 1])
71 // only errors stopping at the first issue stop at this one
72 return undefined
73 }
74
75 /** @internal */
76 _k(
77 apply: CompactApply,
78 data: unknown,
79 key: PropertyKey,
80 ...missing: MissingText
81 ): boolean | undefined {
82 this._p.push(key)
83 const stops =
84 missing.length && !(key in (data as object)) ?
85 this._e(data, "required", ...missing)
86 : !apply((data as Keyed)[key], this)
87 this._p.pop()
88 return stops
89 }
90}
91
92// as issues.ts's failsKey, failsSite, failsKeySite and missingTextOf
93export const failsKey = (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected