(options: ProcessWhereOptions<T>)
| 244 | } |
| 245 | |
| 246 | static processWhere<T extends object>(options: ProcessWhereOptions<T>): FilterQuery<T> { |
| 247 | // eslint-disable-next-line prefer-const |
| 248 | let { where, entityName, metadata, platform, aliased = true, convertCustomTypes = true, root = true } = options; |
| 249 | const meta = metadata.find<T>(entityName); |
| 250 | |
| 251 | // inline PK-only objects in M:N queries, so we don't join the target entity when not needed |
| 252 | if (meta && root) { |
| 253 | QueryHelper.liftGroupOperators(where as Dictionary, meta, metadata); |
| 254 | QueryHelper.inlinePrimaryKeyObjects(where as Dictionary, meta, metadata); |
| 255 | } |
| 256 | |
| 257 | if (meta && root) { |
| 258 | QueryHelper.convertCompositeEntityRefs(where as Dictionary, meta); |
| 259 | } |
| 260 | |
| 261 | if (platform.getConfig().get('ignoreUndefinedInQuery') && where && typeof where === 'object') { |
| 262 | Utils.dropUndefinedProperties(where); |
| 263 | } |
| 264 | |
| 265 | where = QueryHelper.processParams(where) ?? {}; |
| 266 | |
| 267 | /* v8 ignore next */ |
| 268 | if (!root && Utils.isPrimaryKey<T>(where)) { |
| 269 | return where; |
| 270 | } |
| 271 | |
| 272 | if (meta && Utils.isPrimaryKey(where, meta.compositePK)) { |
| 273 | where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where } as FilterQuery<T>; |
| 274 | } |
| 275 | |
| 276 | if (Array.isArray(where) && root) { |
| 277 | const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName); |
| 278 | let cond = { [rootPrimaryKey]: { $in: where } } as FilterQuery<T>; |
| 279 | |
| 280 | // @ts-ignore |
| 281 | // detect tuple comparison, use `$or` in case the number of constituents don't match |
| 282 | if ( |
| 283 | meta && |
| 284 | !where.every( |
| 285 | c => |
| 286 | Utils.isPrimaryKey(c as unknown) || |
| 287 | (Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))), |
| 288 | ) |
| 289 | ) { |
| 290 | cond = { $or: where } as FilterQuery<T>; |
| 291 | } |
| 292 | |
| 293 | return QueryHelper.processWhere({ ...options, where: cond, root: false }); |
| 294 | } |
| 295 | |
| 296 | if (!Utils.isPlainObject(where)) { |
| 297 | return where; |
| 298 | } |
| 299 | |
| 300 | return Utils.getObjectQueryKeys(where).reduce((o, key) => { |
| 301 | let value = where[key as keyof typeof where] as unknown as FilterQuery<T>; |
| 302 | const customExpression = Raw.isKnownFragmentSymbol(key); |
| 303 |
no test coverage detected