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
4.1 KiB
Plaintext
1 line
4.1 KiB
Plaintext
{"version":3,"sources":["../../src/utilities/getRequestEntity.ts"],"sourcesContent":["import type { Collection } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { APIError } from '../errors/APIError.js'\n\nexport const getRequestCollection = (req: PayloadRequest): Collection => {\n const collectionSlug = req.routeParams?.collection\n\n if (typeof collectionSlug !== 'string') {\n throw new APIError(`No collection was specified`, 400)\n }\n\n const collection = req.payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(`Collection with the slug ${collectionSlug} was not found`, 404)\n }\n\n return collection\n}\n\nexport const getRequestCollectionWithID = <T extends boolean>(\n req: PayloadRequest,\n {\n disableSanitize,\n optionalID,\n }: {\n disableSanitize?: T\n optionalID?: boolean\n } = {},\n): {\n collection: Collection\n id: T extends true ? string : number | string\n} => {\n const collection = getRequestCollection(req)\n const id = req.routeParams?.id\n\n if (typeof id !== 'string') {\n if (optionalID) {\n return {\n id: undefined!,\n collection,\n }\n }\n\n throw new APIError(`ID was not specified`, 400)\n }\n\n if (disableSanitize === true) {\n return {\n id,\n collection,\n }\n }\n\n let sanitizedID: number | string = id\n\n // If default db ID type is a number, we should sanitize\n let shouldSanitize = Boolean(req.payload.db.defaultIDType === 'number')\n\n // UNLESS the customIDType for this collection is text.... then we leave it\n if (shouldSanitize && collection.customIDType === 'text') {\n shouldSanitize = false\n }\n\n // If we still should sanitize, parse float\n if (shouldSanitize) {\n sanitizedID = parseFloat(sanitizedID)\n }\n\n return {\n // @ts-expect-error generic return\n id: sanitizedID,\n collection,\n }\n}\n\nexport const getRequestGlobal = (req: PayloadRequest): SanitizedGlobalConfig => {\n const globalSlug = req.routeParams?.global\n\n if (typeof globalSlug !== 'string') {\n throw new APIError(`No global was specified`, 400)\n }\n\n const globalConfig = req.payload.globals.config.find((each) => each.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`Global with the slug ${globalSlug} was not found`, 404)\n }\n\n return globalConfig\n}\n"],"names":["APIError","getRequestCollection","req","collectionSlug","routeParams","collection","payload","collections","getRequestCollectionWithID","disableSanitize","optionalID","id","undefined","sanitizedID","shouldSanitize","Boolean","db","defaultIDType","customIDType","parseFloat","getRequestGlobal","globalSlug","global","globalConfig","globals","config","find","each","slug"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,wBAAuB;AAEhD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,MAAMC,iBAAiBD,IAAIE,WAAW,EAAEC;IAExC,IAAI,OAAOF,mBAAmB,UAAU;QACtC,MAAM,IAAIH,SAAS,CAAC,2BAA2B,CAAC,EAAE;IACpD;IAEA,MAAMK,aAAaH,IAAII,OAAO,CAACC,WAAW,CAACJ,eAAe;IAE1D,IAAI,CAACE,YAAY;QACf,MAAM,IAAIL,SAAS,CAAC,yBAAyB,EAAEG,eAAe,cAAc,CAAC,EAAE;IACjF;IAEA,OAAOE;AACT,EAAC;AAED,OAAO,MAAMG,6BAA6B,CACxCN,KACA,EACEO,eAAe,EACfC,UAAU,EAIX,GAAG,CAAC,CAAC;IAKN,MAAML,aAAaJ,qBAAqBC;IACxC,MAAMS,KAAKT,IAAIE,WAAW,EAAEO;IAE5B,IAAI,OAAOA,OAAO,UAAU;QAC1B,IAAID,YAAY;YACd,OAAO;gBACLC,IAAIC;gBACJP;YACF;QACF;QAEA,MAAM,IAAIL,SAAS,CAAC,oBAAoB,CAAC,EAAE;IAC7C;IAEA,IAAIS,oBAAoB,MAAM;QAC5B,OAAO;YACLE;YACAN;QACF;IACF;IAEA,IA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