Files
klz-cables.com/.pnpm-store/v10/files/b0/c9487c39b0f0af5b44fb56b79d27ee74ddd1734246c1a51e5e9672224b1cf300d6a2d30737888e8abb5caa96a417ca3727547afedc62c17fa2292888397839
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

91 lines
2.9 KiB
Plaintext

import { executeAccess } from '../auth/executeAccess.js';
import { QueryError } from '../errors/QueryError.js';
import { combineQueries } from './combineQueries.js';
import { validateQueryPaths } from './queryValidation/validateQueryPaths.js';
const sanitizeJoinFieldQuery = async ({ collectionSlug, errors, join, joinsQuery, overrideAccess, promises, req })=>{
const { joinPath } = join;
// TODO: fix any's in joinsQuery[joinPath]
if (joinsQuery[joinPath] === false) {
return;
}
const joinCollectionConfig = req.payload.collections[collectionSlug].config;
const accessResult = !overrideAccess ? await executeAccess({
disableErrors: true,
req
}, joinCollectionConfig.access.read) : true;
if (accessResult === false) {
;
joinsQuery[joinPath] = false;
return;
}
if (!joinsQuery[joinPath]) {
;
joinsQuery[joinPath] = {};
}
const joinQuery = joinsQuery[joinPath];
if (!joinQuery.where) {
joinQuery.where = {};
}
if (join.field.where) {
joinQuery.where = combineQueries(joinQuery.where, join.field.where);
}
promises.push(validateQueryPaths({
collectionConfig: joinCollectionConfig,
errors,
overrideAccess,
polymorphicJoin: Array.isArray(join.field.collection),
req,
// incoming where input, but we shouldn't validate generated from the access control.
where: joinQuery.where
}));
if (typeof accessResult === 'object') {
joinQuery.where = combineQueries(joinQuery.where, accessResult);
}
};
/**
* * Validates `where` for each join
* * Combines the access result for joined collection
* * Combines the default join's `where`
*/ export const sanitizeJoinQuery = async ({ collectionConfig, joins: joinsQuery, overrideAccess, req })=>{
if (joinsQuery === false) {
return false;
}
if (!joinsQuery) {
joinsQuery = {};
}
const errors = [];
const promises = [];
for(const collectionSlug in collectionConfig.joins){
for (const join of collectionConfig.joins[collectionSlug]){
await sanitizeJoinFieldQuery({
collectionSlug,
errors,
join,
joinsQuery,
overrideAccess,
promises,
req
});
}
}
for (const join of collectionConfig.polymorphicJoins){
for (const collectionSlug of join.field.collection){
await sanitizeJoinFieldQuery({
collectionSlug,
errors,
join,
joinsQuery,
overrideAccess,
promises,
req
});
}
}
await Promise.all(promises);
if (errors.length > 0) {
throw new QueryError(errors);
}
return joinsQuery;
};
//# sourceMappingURL=sanitizeJoinQuery.js.map