| 1347 | const headReadsCtx = headT?.c |
| 1348 | const pipes = steps.map(step => step.p) |
| 1349 | const t: Transform = (data, ctx) => { |
| 1350 | let result = data |
| 1351 | if (headT) { |
| 1352 | const issues = ctx?.errN |
| 1353 | result = headReadsCtx ? headT(data, ctx) : headT(data) |
| 1354 | if (result instanceof TransformErrors) { |
| 1355 | if (!ctx) return result |
| 1356 | addMorphErrs(ctx, result) |
| 1357 | return data |
| 1358 | } |
| 1359 | if (ctx?.errN > issues) return data |
| 1360 | } |
| 1361 | for (let i = 0; i < steps.length; i++) { |
| 1362 | const step = steps[i] |
| 1363 | const morphed: any = step(result, ctx) |
| 1364 | if ( |
| 1365 | pipes[i] ? |
| 1366 | ctx._errors !== undefined && morphed === ctx._errors |
| 1367 | : morphed instanceof ArkErrors |
| 1368 | ) { |
| 1369 | if (!ctx) return new TransformErrors(morphed, result) |
| 1370 | addErrors(ctx, morphed) |
| 1371 | return data |
| 1372 | } |
| 1373 | result = morphed |
| 1374 | } |
| 1375 | return result |
| 1376 | } |
| 1377 | t.e = applyMorphAt |
| 1378 | if (pipes.includes(1) || headReadsCtx) t.c = 1 |
| 1379 | checker.t = t |