(
entityName: EntityName<T>,
populate: PopulateOptions<T>[],
fields?: readonly EntityField<T, P>[],
exclude?: string[],
)
| 748 | } |
| 749 | |
| 750 | protected buildFields<T extends object, P extends string = never>( |
| 751 | entityName: EntityName<T>, |
| 752 | populate: PopulateOptions<T>[], |
| 753 | fields?: readonly EntityField<T, P>[], |
| 754 | exclude?: string[], |
| 755 | ): string[] | undefined { |
| 756 | const meta = this.metadata.get(entityName); |
| 757 | const lazyProps = meta.props.filter(prop => prop.lazy && !populate.some(p => this.isPopulated(meta, prop, p))); |
| 758 | const ret: string[] = []; |
| 759 | |
| 760 | if (fields) { |
| 761 | for (let field of fields) { |
| 762 | /* v8 ignore next */ |
| 763 | if (Utils.isPlainObject(field)) { |
| 764 | continue; |
| 765 | } |
| 766 | |
| 767 | if (field.toString().includes('.')) { |
| 768 | field = field.toString().substring(0, field.toString().indexOf('.')) as EntityField<T, P>; |
| 769 | } |
| 770 | |
| 771 | let prop = meta.properties[field as EntityKey<T>]; |
| 772 | |
| 773 | /* v8 ignore next */ |
| 774 | if (prop) { |
| 775 | if (!prop.fieldNames) { |
| 776 | continue; |
| 777 | } |
| 778 | |
| 779 | prop = prop.serializedPrimaryKey ? meta.getPrimaryProps()[0] : prop; |
| 780 | ret.push(prop.fieldNames[0]); |
| 781 | } else if (field === '*') { |
| 782 | const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate)); |
| 783 | ret.push(...Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames))); |
| 784 | } else { |
| 785 | ret.push(field as keyof T & string); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | ret.unshift(...meta.primaryKeys.filter(pk => !fields.includes(pk))); |
| 790 | } else if (!Utils.isEmpty(exclude) || lazyProps.some(p => !p.formula)) { |
| 791 | const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, exclude)); |
| 792 | ret.push(...Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames))); |
| 793 | } |
| 794 | |
| 795 | return ret.length > 0 ? ret : undefined; |
| 796 | } |
| 797 | |
| 798 | private handleVersionProperty<T extends object>( |
| 799 | entityName: EntityName<T>, |
no test coverage detected