(fields: ReadonlyArray<readonly [string, Schema.Constraint]>, single: boolean)
| 646 | // `DefaultKeyField`s. A field holds one kind of value, so a raw string never |
| 647 | // meets a tuple from the same field. |
| 648 | const jsonKey = (fields: ReadonlyArray<readonly [string, Schema.Constraint]>, single: boolean) => { |
| 649 | let encoders: ReadonlyArray<readonly [string, (value: unknown) => unknown]> | undefined |
| 650 | return (row: Row): string => { |
| 651 | if (single && typeof row[fields[0][0]] === "string") return row[fields[0][0]] as string |
| 652 | encoders ??= fields.map(([name, field]) => |
| 653 | [name, Schema.encodeUnknownSync(Schema.toCodecJson(field as Schema.Codec<unknown>))] as const |
| 654 | ) |
| 655 | return JSON.stringify(encoders.map(([name, encode]) => encode(row[name]))) |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | // Run the field codec only for present keys, bypassing missing-key defaults. |
| 660 | const patchField = (field: Schema.Constraint): Schema.Constraint => { |
no test coverage detected