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
70 lines
2.8 KiB
Plaintext
70 lines
2.8 KiB
Plaintext
import { QueryError } from '../../errors/QueryError.js';
|
|
import { validOperatorSet } from '../../types/constants.js';
|
|
import { validateSearchParam } from './validateSearchParams.js';
|
|
export async function validateQueryPaths({ collectionConfig, errors = [], globalConfig, overrideAccess, policies = {
|
|
collections: {},
|
|
globals: {}
|
|
}, polymorphicJoin, req, versionFields, where }) {
|
|
const fields = versionFields || (globalConfig || collectionConfig).flattenedFields;
|
|
if (typeof where === 'object') {
|
|
// We need to determine if the whereKey is an AND, OR, or a schema path
|
|
const promises = [];
|
|
for(const path in where){
|
|
const constraint = where[path];
|
|
if ((path === 'and' || path === 'or') && Array.isArray(constraint)) {
|
|
for (const item of constraint){
|
|
if (collectionConfig) {
|
|
promises.push(validateQueryPaths({
|
|
collectionConfig,
|
|
errors,
|
|
overrideAccess,
|
|
policies,
|
|
polymorphicJoin,
|
|
req,
|
|
versionFields,
|
|
where: item
|
|
}));
|
|
} else {
|
|
promises.push(validateQueryPaths({
|
|
errors,
|
|
globalConfig,
|
|
overrideAccess,
|
|
policies,
|
|
polymorphicJoin,
|
|
req,
|
|
versionFields,
|
|
where: item
|
|
}));
|
|
}
|
|
}
|
|
} else if (!Array.isArray(constraint)) {
|
|
for(const operator in constraint){
|
|
const val = constraint[operator];
|
|
if (validOperatorSet.has(operator)) {
|
|
promises.push(validateSearchParam({
|
|
collectionConfig,
|
|
constraint: where,
|
|
errors,
|
|
fields,
|
|
globalConfig,
|
|
operator,
|
|
overrideAccess,
|
|
path,
|
|
policies,
|
|
polymorphicJoin,
|
|
req,
|
|
val,
|
|
versionFields
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await Promise.all(promises);
|
|
if (errors.length > 0) {
|
|
throw new QueryError(errors);
|
|
}
|
|
}
|
|
}
|
|
|
|
//# sourceMappingURL=validateQueryPaths.js.map |