{"version":3,"sources":["../../../src/utilities/getEntityPermissions/entityDocExists.ts"],"sourcesContent":["import {\n type AllOperations,\n combineQueries,\n type DefaultDocumentIDType,\n type PayloadRequest,\n type Where,\n} from '../../index.js'\n\n/**\n * Returns whether or not the entity doc exists based on the where query.\n */\nexport async function entityDocExists({\n id,\n slug,\n entityType,\n locale,\n operation,\n req,\n where,\n}: {\n entityType: 'collection' | 'global'\n id?: DefaultDocumentIDType\n locale?: string\n operation?: AllOperations\n req: PayloadRequest\n slug: string\n where: Where\n}): Promise {\n if (entityType === 'global') {\n const global = await req.payload.db.findGlobal({\n slug,\n locale,\n req,\n select: {},\n where,\n })\n\n const hasGlobalDoc = Boolean(global && Object.keys(global).length > 0)\n\n return hasGlobalDoc\n }\n\n if (entityType === 'collection' && id) {\n if (operation === 'readVersions') {\n const count = await req.payload.db.countVersions({\n collection: slug,\n locale,\n req,\n where: combineQueries(where, { parent: { equals: id } }),\n })\n return count.totalDocs > 0\n }\n\n const count = await req.payload.db.count({\n collection: slug,\n locale,\n req,\n where: combineQueries(where, { id: { equals: id } }),\n })\n\n return count.totalDocs > 0\n }\n\n return false\n}\n"],"names":["combineQueries","entityDocExists","id","slug","entityType","locale","operation","req","where","global","payload","db","findGlobal","select","hasGlobalDoc","Boolean","Object","keys","length","count","countVersions","collection","parent","equals","totalDocs"],"mappings":"AAAA,SAEEA,cAAc,QAIT,iBAAgB;AAEvB;;CAEC,GACD,OAAO,eAAeC,gBAAgB,EACpCC,EAAE,EACFC,IAAI,EACJC,UAAU,EACVC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,KAAK,EASN;IACC,IAAIJ,eAAe,UAAU;QAC3B,MAAMK,SAAS,MAAMF,IAAIG,OAAO,CAACC,EAAE,CAACC,UAAU,CAAC;YAC7CT;YACAE;YACAE;YACAM,QAAQ,CAAC;YACTL;QACF;QAEA,MAAMM,eAAeC,QAAQN,UAAUO,OAAOC,IAAI,CAACR,QAAQS,MAAM,GAAG;QAEpE,OAAOJ;IACT;IAEA,IAAIV,eAAe,gBAAgBF,IAAI;QACrC,IAAII,cAAc,gBAAgB;YAChC,MAAMa,QAAQ,MAAMZ,IAAIG,OAAO,CAACC,EAAE,CAACS,aAAa,CAAC;gBAC/CC,YAAYlB;gBACZE;gBACAE;gBACAC,OAAOR,eAAeQ,OAAO;oBAAEc,QAAQ;wBAAEC,QAAQrB;oBAAG;gBAAE;YACxD;YACA,OAAOiB,MAAMK,SAAS,GAAG;QAC3B;QAEA,MAAML,QAAQ,MAAMZ,IAAIG,OAAO,CAACC,EAAE,CAACQ,KAAK,CAAC;YACvCE,YAAYlB;YACZE;YACAE;YACAC,OAAOR,eAAeQ,OAAO;gBAAEN,IAAI;oBAAEqB,QAAQrB;gBAAG;YAAE;QACpD;QAEA,OAAOiB,MAAMK,SAAS,GAAG;IAC3B;IAEA,OAAO;AACT"}