* Describe what fields to be included/excluded * @param f - A field name to be included, an array of field names to be * included, or an Fields object for the inclusion/exclusion
(...f: (Fields<MT> | Extract<keyof MT, string>)[])
| 579 | * included, or an Fields object for the inclusion/exclusion |
| 580 | */ |
| 581 | fields(...f: (Fields<MT> | Extract<keyof MT, string>)[]): this { |
| 582 | if (!this.filter.fields) { |
| 583 | this.filter.fields = {}; |
| 584 | } else if (Array.isArray(this.filter.fields)) { |
| 585 | this.filter.fields = this.filter.fields.reduce( |
| 586 | (prev, current) => ({...prev, [current]: true}), |
| 587 | {}, |
| 588 | ); |
| 589 | } |
| 590 | const fields = this.filter.fields; |
| 591 | for (const field of f) { |
| 592 | if (Array.isArray(field)) { |
| 593 | field.forEach(i => (fields[i] = true)); |
| 594 | } else if (typeof field === 'string') { |
| 595 | fields[field] = true; |
| 596 | } else { |
| 597 | Object.assign(fields, field); |
| 598 | } |
| 599 | } |
| 600 | return this; |
| 601 | } |
| 602 | |
| 603 | private validateOrder(order: string) { |
| 604 | assert(order.match(/^[^\s]+( (ASC|DESC))?$/), 'Invalid order: ' + order); |
no outgoing calls