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
1 line
5.6 KiB
Plaintext
1 line
5.6 KiB
Plaintext
{"version":3,"sources":["../../src/database/sanitizeJoinQuery.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, SanitizedJoin } from '../collections/config/types.js'\nimport type { JoinQuery, PayloadRequest } from '../types/index.js'\n\nimport { executeAccess } from '../auth/executeAccess.js'\nimport { QueryError } from '../errors/QueryError.js'\nimport { combineQueries } from './combineQueries.js'\nimport { validateQueryPaths } from './queryValidation/validateQueryPaths.js'\n\ntype Args = {\n collectionConfig: SanitizedCollectionConfig\n joins?: JoinQuery\n overrideAccess: boolean\n req: PayloadRequest\n}\n\nconst sanitizeJoinFieldQuery = async ({\n collectionSlug,\n errors,\n join,\n joinsQuery,\n overrideAccess,\n promises,\n req,\n}: {\n collectionSlug: string\n errors: { path: string }[]\n join: SanitizedJoin\n joinsQuery: JoinQuery\n overrideAccess: boolean\n promises: Promise<void>[]\n req: PayloadRequest\n}) => {\n const { joinPath } = join\n\n // TODO: fix any's in joinsQuery[joinPath]\n\n if ((joinsQuery as any)[joinPath] === false) {\n return\n }\n\n const joinCollectionConfig = req.payload.collections[collectionSlug]!.config\n\n const accessResult = !overrideAccess\n ? await executeAccess({ disableErrors: true, req }, joinCollectionConfig.access.read)\n : true\n\n if (accessResult === false) {\n ;(joinsQuery as any)[joinPath] = false\n return\n }\n\n if (!(joinsQuery as any)[joinPath]) {\n ;(joinsQuery as any)[joinPath] = {}\n }\n\n const joinQuery = (joinsQuery as any)[joinPath]\n\n if (!joinQuery.where) {\n joinQuery.where = {}\n }\n\n if (join.field.where) {\n joinQuery.where = combineQueries(joinQuery.where, join.field.where)\n }\n\n promises.push(\n validateQueryPaths({\n collectionConfig: joinCollectionConfig,\n errors,\n overrideAccess,\n polymorphicJoin: Array.isArray(join.field.collection),\n req,\n // incoming where input, but we shouldn't validate generated from the access control.\n where: joinQuery.where,\n }),\n )\n\n if (typeof accessResult === 'object') {\n joinQuery.where = combineQueries(joinQuery.where, accessResult)\n }\n}\n\n/**\n * * Validates `where` for each join\n * * Combines the access result for joined collection\n * * Combines the default join's `where`\n */\nexport const sanitizeJoinQuery = async ({\n collectionConfig,\n joins: joinsQuery,\n overrideAccess,\n req,\n}: Args) => {\n if (joinsQuery === false) {\n return false\n }\n\n if (!joinsQuery) {\n joinsQuery = {}\n }\n\n const errors: { path: string }[] = []\n const promises: Promise<void>[] = []\n\n for (const collectionSlug in collectionConfig.joins) {\n for (const join of collectionConfig.joins[collectionSlug]!) {\n await sanitizeJoinFieldQuery({\n collectionSlug,\n errors,\n join,\n joinsQuery,\n overrideAccess,\n promises,\n req,\n })\n }\n }\n\n for (const join of collectionConfig.polymorphicJoins) {\n for (const collectionSlug of join.field.collection) {\n await sanitizeJoinFieldQuery({\n collectionSlug,\n errors,\n join,\n joinsQuery,\n overrideAccess,\n promises,\n req,\n })\n }\n }\n\n await Promise.all(promises)\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return joinsQuery\n}\n"],"names":["executeAccess","QueryError","combineQueries","validateQueryPaths","sanitizeJoinFieldQuery","collectionSlug","errors","join","joinsQuery","overrideAccess","promises","req","joinPath","joinCollectionConfig","payload","collections","config","accessResult","disableErrors","access","read","joinQuery","where","field","push","collectionConfig","polymorphicJoin","Array","isArray","collection","sanitizeJoinQuery","joins","polymorphicJoins","Promise","all","length"],"mappings":"AAGA,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,kBAAkB,QAAQ,0CAAyC;AAS5E,MAAMC,yBAAyB,OA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