MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / impose

Method impose

packages/filter/src/query.ts:681–704  ·  view source on GitHub ↗

* Add a Filter or Where constraint object. If it is a filter object, create * an `and` clause for conflicting keys with its where object. For any other * properties, throw an error. If it's not a Filter, coerce it to a filter, * and carry out the same logic. * * @param constraint - a

(constraint: Filter<MT> | Where<MT>)

Source from the content-addressed store, hash-verified

679 * @param constraint - a constraint object to merge with own filter object
680 */
681 impose(constraint: Filter<MT> | Where<MT>): this {
682 if (!this.filter) {
683 // if constraint is a Where, turn into a Filter
684 if (!isFilter(constraint)) {
685 constraint = {where: constraint};
686 }
687 this.filter = (constraint as Filter<MT>) || {};
688 } else {
689 if (isFilter(constraint)) {
690 // throw error if imposed Filter has non-where fields
691 for (const key of Object.keys(constraint)) {
692 if (nonWhereFields.includes(key)) {
693 throw new Error(
694 'merging strategy for selection, pagination, and sorting not implemented',
695 );
696 }
697 }
698 }
699 this.filter.where = isFilter(constraint)
700 ? new WhereBuilder(this.filter.where).impose(constraint.where!).build()
701 : new WhereBuilder(this.filter.where).impose(constraint).build();
702 }
703 return this;
704 }
705
706 /**
707 * Return the filter object

Callers 1

constrainFilterFunction · 0.95

Calls 4

isFilterFunction · 0.85
keysMethod · 0.65
buildMethod · 0.65
imposeMethod · 0.45

Tested by

no test coverage detected