| 1202 | // a value transforming may fail: what fails goes to ctx, or without one is |
| 1203 | // returned gathered, as arktype's Transform does for a node with no ctx |
| 1204 | class Written implements WrittenValues { |
| 1205 | declare gathered: TransformErrors | undefined |
| 1206 | declare ctx: any |
| 1207 | declare issues: number | undefined |
| 1208 | |
| 1209 | constructor(ctx?: any) { |
| 1210 | this.ctx = ctx |
| 1211 | this.issues = ctx?.errN |
| 1212 | this.gathered = undefined |
| 1213 | } |
| 1214 | |
| 1215 | gather(errors: TransformErrors, k?: PropertyKey) { |
| 1216 | if (this.ctx) addMorphErrs(this.ctx, errors, k) |
| 1217 | else this.gathered = errors.addTo(this.gathered, k) |
| 1218 | } |
| 1219 | |
| 1220 | failed() { |
| 1221 | return this.gathered ?? this.ctx?.errN > this.issues! |
| 1222 | } |
| 1223 | |
| 1224 | // what a t returns of out where a value failed: with no ctx, what failed |
| 1225 | resolved(data: unknown, out: unknown) { |
| 1226 | return this.gathered ?? (this.ctx?.errN > this.issues! ? data : out) |
| 1227 | } |
| 1228 | |
| 1229 | transformed(t: Transform, value: unknown, k: PropertyKey) { |
| 1230 | let result |
| 1231 | if (t.c) { |
| 1232 | this.ctx.path.push(k) |
| 1233 | result = t(value, this.ctx) |
| 1234 | this.ctx.path.pop() |
| 1235 | } else result = t(value) |
| 1236 | if (result === value || !(result instanceof TransformErrors)) return result |
| 1237 | this.gather(result, k) |
| 1238 | return value |
| 1239 | } |
| 1240 | |
| 1241 | defaulted(write: DefaultWrite, out: any) { |
| 1242 | const written = write(out, this.ctx) |
| 1243 | if (written !== out) this.gather(written as TransformErrors) |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | // a transform's Written: where there's no ctx, one for each depth of those |
| 1248 | // running within one another, so a call allocates none. One with a ctx is new, |
nothing calls this directly
no outgoing calls
no test coverage detected