| 18 | * @internal |
| 19 | */ |
| 20 | export class CriteriaNode<T extends object> implements ICriteriaNode<T> { |
| 21 | payload: any; |
| 22 | prop?: EntityProperty<T>; |
| 23 | index?: number; |
| 24 | |
| 25 | constructor( |
| 26 | protected readonly metadata: MetadataStorage, |
| 27 | readonly entityName: EntityName<T>, |
| 28 | readonly parent?: ICriteriaNode<T>, |
| 29 | readonly key?: EntityKey<T> | RawQueryFragmentSymbol, |
| 30 | readonly validate = true, |
| 31 | readonly strict = false, |
| 32 | ) { |
| 33 | const meta = parent && metadata.find<T>(parent.entityName); |
| 34 | |
| 35 | if (meta && key && !RawQueryFragment.isKnownFragmentSymbol(key)) { |
| 36 | const pks = Utils.splitPrimaryKeys<T>(key); |
| 37 | |
| 38 | if (pks.length > 1) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | for (const k of pks) { |
| 43 | this.prop = meta.props.find( |
| 44 | prop => |
| 45 | prop.name === k || (prop.fieldNames?.length === 1 && prop.fieldNames[0] === k && prop.persist !== false), |
| 46 | ); |
| 47 | const isProp = this.prop || meta.props.find(prop => (prop.fieldNames || []).includes(k)); |
| 48 | |
| 49 | // do not validate if the key is prefixed or type casted (e.g. `k::text`) |
| 50 | if (validate && !isProp && !k.includes('.') && !k.includes('::') && !Utils.isOperator(k)) { |
| 51 | throw new Error(`Trying to query by not existing property ${Utils.className(entityName)}.${k}`); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any { |
| 58 | return this.payload; |
| 59 | } |
| 60 | |
| 61 | unwrap(): any { |
| 62 | return this.payload; |
| 63 | } |
| 64 | |
| 65 | shouldInline(payload: any): boolean { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | shouldRename(payload: any): boolean { |
| 74 | const type = this.prop ? this.prop.kind : null; |
| 75 | // Polymorphic relations have a composite column set (discriminator + FK), but we only |
| 76 | // need tuple-renaming when the payload is itself a tuple (entity ref expanded by |
| 77 | // `convertCompositeEntityRefs`) or an array-valued operator like `$in`. Scalar payloads |
nothing calls this directly
no outgoing calls
no test coverage detected