Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
29 lines
928 B
Plaintext
29 lines
928 B
Plaintext
export function combineWhereConstraints(constraints, as = 'and') {
|
|
if (constraints.length === 0) {
|
|
return {};
|
|
}
|
|
const reducedConstraints = constraints.reduce((acc, constraint)=>{
|
|
if (constraint && typeof constraint === 'object' && Object.keys(constraint).length > 0) {
|
|
if (as in constraint) {
|
|
// merge the objects under the shared key
|
|
acc[as] = [
|
|
...acc[as],
|
|
...constraint[as]
|
|
];
|
|
} else {
|
|
// the constraint does not share the key
|
|
acc[as]?.push(constraint);
|
|
}
|
|
}
|
|
return acc;
|
|
}, {
|
|
[as]: []
|
|
});
|
|
if (reducedConstraints[as]?.length === 0) {
|
|
// If there are no constraints, return an empty object
|
|
return {};
|
|
}
|
|
return reducedConstraints;
|
|
}
|
|
|
|
//# sourceMappingURL=combineWhereConstraints.js.map |