(
pair: Pair,
member: string,
data: unknown,
{ isWritten }: { isWritten: boolean },
run: (t: any, data: unknown) => unknown
)
| 788 | const mismatched = Symbol("mismatched") |
| 789 | |
| 790 | const validateBoth = ( |
| 791 | pair: Pair, |
| 792 | member: string, |
| 793 | data: unknown, |
| 794 | { isWritten }: { isWritten: boolean }, |
| 795 | run: (t: any, data: unknown) => unknown |
| 796 | ): unknown => { |
| 797 | const counterparts = new Map<object, unknown>() |
| 798 | const copy = isWritten ? copyOf(data, counterparts) : uncopyable |
| 799 | // e.g. ctx.root, which both sides share where it isn't copied |
| 800 | if (copy === uncopyable && hasDomain(data, "object")) |
| 801 | counterparts.set(data, data) |
| 802 | const current: Validation = { |
| 803 | phase: "record", |
| 804 | skipsApply: false, |
| 805 | calls: [], |
| 806 | replayed: 0, |
| 807 | counterparts, |
| 808 | isCopied: copy !== uncopyable, |
| 809 | mismatch: undefined |
| 810 | } |
| 811 | const outer = validation |
| 812 | validation = current |
| 813 | let arktype: Outcome |
| 814 | let precompiled: Outcome |
| 815 | try { |
| 816 | arktype = inArktype(() => outcomeOf(() => run(pair.original, data))) |
| 817 | current.phase = "replay" |
| 818 | current.skipsApply = pair.contract.errors === "none" && fails(arktype) |
| 819 | precompiled = outcomeOf(() => |
| 820 | run(pair.counterpart, current.isCopied ? copy : data) |
| 821 | ) |
| 822 | } finally { |
| 823 | validation = outer |
| 824 | } |
| 825 | // errors "first" stops at any one issue, before calls arktype makes after it |
| 826 | const stopsEarly = pair.contract.errors === "first" && fails(arktype) |
| 827 | const unreplayed = |
| 828 | current.skipsApply || stopsEarly ? |
| 829 | undefined |
| 830 | : current.calls[current.replayed] |
| 831 | current.mismatch ??= unreplayed && [describeCall(unreplayed), "makes no call"] |
| 832 | const observation = () => |
| 833 | `${member}(${printable(data)})${isWritten ? ", the input as arktype's morphs left it" : ""}` |
| 834 | const reason = |
| 835 | isWritten && !current.isCopied ? |
| 836 | "which its validator received too, since it can't be copied" |
| 837 | : undefined |
| 838 | if (current.mismatch) fail(pair, observation(), ...current.mismatch, reason) |
| 839 | const writesInput = !!pair.contract.mutatesInput |
| 840 | const arktypeObserved = inArktype(() => observe(arktype, { writesInput })) |
| 841 | const precompiledObserved = observe(precompiled, { writesInput }) |
| 842 | // errors "none" fails with one root issue, compared without its data |
| 843 | if (current.skipsApply) { |
| 844 | arktypeObserved.issues = [{ code: "predicate", path: [] }] |
| 845 | const { issues } = precompiledObserved |
| 846 | if (issues) { |
| 847 | precompiledObserved.issues = issues.map(({ code, path }) => ({ |
no test coverage detected