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

Class ReadIssues

ark/schema/shared/issues.ts:152–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150
151// what a program's code reads of its errors, as no bundler drops a class's members
152class ReadIssues implements StandardSchemaV1.FailureResult, FailureContext {
153 /** @internal each issue in the order it was added */
154 declare _: ArkIssue[]
155 /** @internal the path a fused traversal is at */
156 declare _p: PropertyKey[]
157
158 // assigned, as a target lowering class fields defines each with a helper
159 constructor() {
160 this._ = []
161 this._p = []
162 }
163
164 /**
165 * The number of issues.
166 */
167 get count(): number {
168 return this._.length
169 }
170
171 /**
172 * Each issue, its message written when they are first read.
173 */
174 get issues(): readonly WrittenIssue[] {
175 return readsIssues ? serializableIssues(this._) : (this._ as WrittenIssue[])
176 }
177
178 /**
179 * @internal fails data at the path it's at. Every bundle holds this, so it
180 * takes neither a key nor a site: a validator whose code fails nothing at
181 * a key would hold what enters one for nothing, which failsKey does
182 * through _k, and a site is a function building it in every bundle
183 */
184 _e(
185 data: unknown,
186 code: ArkErrorCode,
187 expected?: string,
188 message?: string,
189 text?: SiteContext["text"]
190 ): true | undefined {
191 this._.push({ code, path: this._p.slice(), data, expected, message })
192 // called on the issue once it's added, so errors whose build found no
193 // site calling one hold no name for it
194 if (callsSiteText) text?.(this._[this._.length - 1])
195 // only errors stopping at the first issue stop at this one
196 return undefined
197 }
198
199 /** @internal */
200 _k(
201 apply: CompactApply,
202 data: unknown,
203 key: PropertyKey,
204 ...missing: MissingText
205 ): boolean | undefined {
206 this._p.push(key)
207 // a missing key fails with the object missing it
208 const stops =
209 missing.length && !(key in (data as object)) ?

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected