(data)
| 62 | // project_bidi_schema.mjs) — so recurse through that union's own dispatch |
| 63 | // rather than assuming every resolved ref is a record. |
| 64 | build(data) { |
| 65 | if (objectOnly && (typeof data !== 'object' || data === null || Array.isArray(data))) { |
| 66 | throw new ValidationError(`${name}: expected an object`) |
| 67 | } |
| 68 | const ref = selectVariant(selector, data, (d, key) => Object.hasOwn(d, key)) |
| 69 | if (ref === undefined) { |
| 70 | throw new ValidationError(`${name}: value does not match any known variant`) |
| 71 | } |
| 72 | const variant = resolve(ref) |
| 73 | if (variant.kind === 'union') { |
| 74 | return variant.build(data) |
| 75 | } |
| 76 | return new variant.RecordClass(data) |
| 77 | }, |
| 78 | |
| 79 | // Inbound: resolve which variant `payload` matches. An unresolvable payload is a |
| 80 | // closed-vocabulary miss — always an error, never a warning, since there is no |
no test coverage detected