| 628 | }) |
| 629 | |
| 630 | const declaredKey = (declaration: KeyDeclaration<any, string>, fields: Schema.Struct.Fields): RowKey => { |
| 631 | const names = declaration.fields |
| 632 | const derive = declaration.derive |
| 633 | return { |
| 634 | fields: names, |
| 635 | schema: Schema.Struct(Struct.pick(fields, names) as Schema.Struct.Fields), |
| 636 | fromRow: (row) => Struct.pick(row, names), |
| 637 | toValues: (key) => key as Row, |
| 638 | primaryKey: derive !== undefined |
| 639 | ? (row) => derive(Struct.pick(row, names) as any) |
| 640 | : jsonKey(names.map((name) => [name, fields[name]]), false) |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | // A string single-field key is its own primary key. Otherwise the key is the |
| 645 | // JSON tuple of the fields' JSON encodings, distinct for distinct values of |