payload 3.80.0-internal.60d6f94 → 3.80.0-internal.82dcece

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/collections/operations/update.js +1 -1
  2. package/dist/collections/operations/update.js.map +1 -1
  3. package/dist/database/getLocalizedPaths.d.ts.map +1 -1
  4. package/dist/database/getLocalizedPaths.js +2 -1
  5. package/dist/database/getLocalizedPaths.js.map +1 -1
  6. package/dist/database/queryValidation/validateQueryPaths.js +1 -1
  7. package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
  8. package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
  9. package/dist/database/queryValidation/validateSearchParams.js +2 -1
  10. package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
  11. package/dist/exports/shared.d.ts +1 -0
  12. package/dist/exports/shared.d.ts.map +1 -1
  13. package/dist/exports/shared.js +1 -0
  14. package/dist/exports/shared.js.map +1 -1
  15. package/dist/fields/baseFields/slug/index.d.ts +7 -0
  16. package/dist/fields/baseFields/slug/index.d.ts.map +1 -1
  17. package/dist/fields/baseFields/slug/index.js +2 -2
  18. package/dist/fields/baseFields/slug/index.js.map +1 -1
  19. package/dist/fields/validations.js +1 -1
  20. package/dist/fields/validations.js.map +1 -1
  21. package/dist/fields/validations.spec.js +25 -0
  22. package/dist/fields/validations.spec.js.map +1 -1
  23. package/dist/index.bundled.d.ts +7 -0
  24. package/dist/types/constants.d.ts +5 -0
  25. package/dist/types/constants.d.ts.map +1 -1
  26. package/dist/types/constants.js +4 -0
  27. package/dist/types/constants.js.map +1 -1
  28. package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
  29. package/dist/uploads/endpoints/getFile.js +7 -1
  30. package/dist/uploads/endpoints/getFile.js.map +1 -1
  31. package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
  32. package/dist/uploads/endpoints/getFileFromURL.js +67 -28
  33. package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
  34. package/dist/uploads/getExternalFile.d.ts.map +1 -1
  35. package/dist/uploads/getExternalFile.js +3 -0
  36. package/dist/uploads/getExternalFile.js.map +1 -1
  37. package/dist/uploads/safeFetch.d.ts +1 -1
  38. package/dist/uploads/safeFetch.d.ts.map +1 -1
  39. package/dist/uploads/safeFetch.js.map +1 -1
  40. package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
  41. package/dist/utilities/addDataAndFileToRequest.js +7 -1
  42. package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
  43. package/dist/utilities/sanitizeUrl.d.ts +7 -0
  44. package/dist/utilities/sanitizeUrl.d.ts.map +1 -0
  45. package/dist/utilities/sanitizeUrl.js +28 -0
  46. package/dist/utilities/sanitizeUrl.js.map +1 -0
  47. package/package.json +4 -4
@@ -88,7 +88,7 @@ export const updateOperation = async (incomingArgs)=>{
88
88
  sort: incomingSort
89
89
  });
90
90
  let docs;
91
- if (hasDraftsEnabled(collectionConfig) && shouldSaveDraft) {
91
+ if (hasDraftsEnabled(collectionConfig) && (shouldSaveDraft || isTrashAttempt)) {
92
92
  const versionsWhere = appendVersionToQueryKey(fullWhere);
93
93
  await validateQueryPaths({
94
94
  collectionConfig: collection.config,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/update.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { APIError } from '../../errors/index.js'\nimport { type CollectionSlug, deepCopyObjectSimple, type FindOptions } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { isErrorPublic } from '../../utilities/isErrorPublic.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js'\nimport { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js'\nimport { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\nimport { updateDocument } from './utilities/update.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n limit?: number\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishAllLocales?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n showHiddenFields?: boolean\n /**\n * Sort the documents, can be a string or an array of strings\n * @example '-createdAt' // Sort DESC by createdAt\n * @example ['group', '-createdAt'] // sort by 2 fields, ASC group and DESC createdAt\n */\n sort?: Sort\n trash?: boolean\n unpublishAllLocales?: boolean\n where: Where\n} & Pick<FindOptions<TSlug, SelectType>, 'select'>\n\nexport const updateOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n if (args.collection.config.disableBulkEdit && !args.overrideAccess) {\n throw new APIError(`Collection ${args.collection.config.slug} has disabled bulk edit`, 403)\n }\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'update',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n limit = 0,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n trash = false,\n unpublishAllLocales,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to update.\", httpStatus.BAD_REQUEST)\n }\n\n const { data: bulkUpdateData } = args\n const shouldSaveDraft = Boolean(draftArg && hasDraftsEnabled(collectionConfig))\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.update)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n let fullWhere = combineQueries(where, accessResult!)\n\n const isTrashAttempt =\n collectionConfig.trash &&\n typeof bulkUpdateData === 'object' &&\n bulkUpdateData !== null &&\n 'deletedAt' in bulkUpdateData &&\n bulkUpdateData.deletedAt != null\n\n // Enforce delete access if performing a soft-delete (trash)\n if (isTrashAttempt && !overrideAccess) {\n // Pass data so access function can check data.deletedAt to know it's a trash attempt\n const deleteAccessResult = await executeAccess(\n { data: bulkUpdateData, req },\n collectionConfig.access.delete,\n )\n fullWhere = combineQueries(fullWhere, deleteAccessResult)\n }\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n const sort = sanitizeSortQuery({\n fields: collection.config.flattenedFields,\n sort: incomingSort,\n })\n\n let docs\n\n if (hasDraftsEnabled(collectionConfig) && shouldSaveDraft) {\n const versionsWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess: overrideAccess!,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n const query = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n limit,\n locale: locale!,\n pagination: false,\n req,\n sort: getQueryDraftsSort({ collectionConfig, sort }),\n where: versionsWhere,\n })\n\n docs = query.docs\n } else {\n const query = await payload.db.find({\n collection: collectionConfig.slug,\n limit,\n locale: locale!,\n pagination: false,\n req,\n sort,\n where: fullWhere,\n })\n\n docs = query.docs\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data: bulkUpdateData,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n const errors: BulkOperationResult<TSlug, TSelect>['errors'] = []\n\n const promises = docs.map(async (docWithLocales) => {\n const { id } = docWithLocales\n\n try {\n // Each document gets its own transaction when singleTransaction is enabled\n let docShouldCommit = false\n if (req.payload.db.bulkOperationsSingleTransaction) {\n docShouldCommit = await initTransaction(req)\n }\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // ///////////////////////////////////////////////\n // Update document, runs all document level hooks\n // ///////////////////////////////////////////////\n let updatedDoc = await updateDocument({\n id,\n autosave,\n collectionConfig,\n config,\n data: deepCopyObjectSimple(data),\n depth: depth!,\n docWithLocales,\n draftArg,\n fallbackLocale: fallbackLocale!,\n filesToUpload,\n locale: locale!,\n overrideAccess: overrideAccess!,\n overrideLock: overrideLock!,\n payload,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req,\n select: select!,\n showHiddenFields: showHiddenFields!,\n unpublishAllLocales,\n })\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n updatedDoc = { ...updatedDoc, collection: collectionConfig.slug }\n }\n\n if (docShouldCommit) {\n await commitTransaction(req)\n }\n\n return updatedDoc\n } catch (error) {\n const isPublic = error instanceof Error ? isErrorPublic(error, config) : false\n\n if (req.payload.db.bulkOperationsSingleTransaction) {\n await killTransaction(req)\n }\n errors.push({\n id,\n isPublic,\n message: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n return null\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // Process sequentially when using single transaction mode to avoid shared state issues\n // Process in parallel when using one transaction for better performance\n let awaitedDocs: (DataFromCollectionSlug<TSlug> | null)[]\n if (req.payload.db.bulkOperationsSingleTransaction) {\n awaitedDocs = []\n for (const promise of promises) {\n awaitedDocs.push(await promise)\n }\n } else {\n awaitedDocs = await Promise.all(promises)\n }\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'update',\n overrideAccess,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","sanitizeWhereQuery","APIError","deepCopyObjectSimple","generateFileData","unlinkTempFiles","appendNonTrashedFilter","commitTransaction","hasDraftsEnabled","initTransaction","isErrorPublic","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSort","buildAfterOperation","buildBeforeOperation","sanitizeSortQuery","updateDocument","updateOperation","incomingArgs","args","collection","config","disableBulkEdit","overrideAccess","slug","shouldCommit","disableTransaction","req","operation","autosave","collectionConfig","depth","draft","draftArg","limit","overrideLock","overwriteExistingFiles","populate","publishAllLocales","publishSpecificLocale","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","incomingSort","trash","unpublishAllLocales","where","BAD_REQUEST","data","bulkUpdateData","shouldSaveDraft","Boolean","accessResult","access","update","fullWhere","isTrashAttempt","deletedAt","deleteAccessResult","delete","enableTrash","fields","flattenedFields","docs","versionsWhere","versionFields","query","db","queryDrafts","pagination","find","files","filesToUpload","throwOnMissingFile","errors","promises","map","docWithLocales","id","docShouldCommit","bulkOperationsSingleTransaction","forceSelect","updatedDoc","auth","error","isPublic","Error","push","message","awaitedDocs","promise","Promise","all","result","filter"],"mappings":"AAEA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAA8BC,oBAAoB,QAA0B,iBAAgB;AAC5F,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,gBAAgB,QAAQ,uCAAsC;AACvE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,mCAAkC;AAChE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S;YACX9B,MAAM0B,YAAYK,MAAM,CAAC3C;YACzBuB;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCmB,SAAS,MAAMpF,oBAAoB;YACjCM;YACAC,YAAYU;YACZF,WAAW;YACXL;YACA,oFAAoF;YACpF0E;QACF;QAEA,IAAIxE,cAAc;YAChB,MAAMrB,kBAAkBuB;QAC1B;QAEA,oFAAoF;QACpF,OAAOsE;IACT,EAAE,OAAOT,OAAgB;QACvB,MAAMhF,gBAAgBW,KAAKQ,GAAG;QAC9B,MAAM6D;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/update.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { APIError } from '../../errors/index.js'\nimport { type CollectionSlug, deepCopyObjectSimple, type FindOptions } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { isErrorPublic } from '../../utilities/isErrorPublic.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js'\nimport { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js'\nimport { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\nimport { updateDocument } from './utilities/update.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n limit?: number\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishAllLocales?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n showHiddenFields?: boolean\n /**\n * Sort the documents, can be a string or an array of strings\n * @example '-createdAt' // Sort DESC by createdAt\n * @example ['group', '-createdAt'] // sort by 2 fields, ASC group and DESC createdAt\n */\n sort?: Sort\n trash?: boolean\n unpublishAllLocales?: boolean\n where: Where\n} & Pick<FindOptions<TSlug, SelectType>, 'select'>\n\nexport const updateOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n if (args.collection.config.disableBulkEdit && !args.overrideAccess) {\n throw new APIError(`Collection ${args.collection.config.slug} has disabled bulk edit`, 403)\n }\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'update',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n limit = 0,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n trash = false,\n unpublishAllLocales,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to update.\", httpStatus.BAD_REQUEST)\n }\n\n const { data: bulkUpdateData } = args\n const shouldSaveDraft = Boolean(draftArg && hasDraftsEnabled(collectionConfig))\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.update)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n let fullWhere = combineQueries(where, accessResult!)\n\n const isTrashAttempt =\n collectionConfig.trash &&\n typeof bulkUpdateData === 'object' &&\n bulkUpdateData !== null &&\n 'deletedAt' in bulkUpdateData &&\n bulkUpdateData.deletedAt != null\n\n // Enforce delete access if performing a soft-delete (trash)\n if (isTrashAttempt && !overrideAccess) {\n // Pass data so access function can check data.deletedAt to know it's a trash attempt\n const deleteAccessResult = await executeAccess(\n { data: bulkUpdateData, req },\n collectionConfig.access.delete,\n )\n fullWhere = combineQueries(fullWhere, deleteAccessResult)\n }\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n const sort = sanitizeSortQuery({\n fields: collection.config.flattenedFields,\n sort: incomingSort,\n })\n\n let docs\n\n if (hasDraftsEnabled(collectionConfig) && (shouldSaveDraft || isTrashAttempt)) {\n const versionsWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess: overrideAccess!,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n const query = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n limit,\n locale: locale!,\n pagination: false,\n req,\n sort: getQueryDraftsSort({ collectionConfig, sort }),\n where: versionsWhere,\n })\n\n docs = query.docs\n } else {\n const query = await payload.db.find({\n collection: collectionConfig.slug,\n limit,\n locale: locale!,\n pagination: false,\n req,\n sort,\n where: fullWhere,\n })\n\n docs = query.docs\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data: bulkUpdateData,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n const errors: BulkOperationResult<TSlug, TSelect>['errors'] = []\n\n const promises = docs.map(async (docWithLocales) => {\n const { id } = docWithLocales\n\n try {\n // Each document gets its own transaction when singleTransaction is enabled\n let docShouldCommit = false\n if (req.payload.db.bulkOperationsSingleTransaction) {\n docShouldCommit = await initTransaction(req)\n }\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // ///////////////////////////////////////////////\n // Update document, runs all document level hooks\n // ///////////////////////////////////////////////\n let updatedDoc = await updateDocument({\n id,\n autosave,\n collectionConfig,\n config,\n data: deepCopyObjectSimple(data),\n depth: depth!,\n docWithLocales,\n draftArg,\n fallbackLocale: fallbackLocale!,\n filesToUpload,\n locale: locale!,\n overrideAccess: overrideAccess!,\n overrideLock: overrideLock!,\n payload,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req,\n select: select!,\n showHiddenFields: showHiddenFields!,\n unpublishAllLocales,\n })\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n updatedDoc = { ...updatedDoc, collection: collectionConfig.slug }\n }\n\n if (docShouldCommit) {\n await commitTransaction(req)\n }\n\n return updatedDoc\n } catch (error) {\n const isPublic = error instanceof Error ? isErrorPublic(error, config) : false\n\n if (req.payload.db.bulkOperationsSingleTransaction) {\n await killTransaction(req)\n }\n errors.push({\n id,\n isPublic,\n message: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n return null\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // Process sequentially when using single transaction mode to avoid shared state issues\n // Process in parallel when using one transaction for better performance\n let awaitedDocs: (DataFromCollectionSlug<TSlug> | null)[]\n if (req.payload.db.bulkOperationsSingleTransaction) {\n awaitedDocs = []\n for (const promise of promises) {\n awaitedDocs.push(await promise)\n }\n } else {\n awaitedDocs = await Promise.all(promises)\n }\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'update',\n overrideAccess,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","sanitizeWhereQuery","APIError","deepCopyObjectSimple","generateFileData","unlinkTempFiles","appendNonTrashedFilter","commitTransaction","hasDraftsEnabled","initTransaction","isErrorPublic","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSort","buildAfterOperation","buildBeforeOperation","sanitizeSortQuery","updateDocument","updateOperation","incomingArgs","args","collection","config","disableBulkEdit","overrideAccess","slug","shouldCommit","disableTransaction","req","operation","autosave","collectionConfig","depth","draft","draftArg","limit","overrideLock","overwriteExistingFiles","populate","publishAllLocales","publishSpecificLocale","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","incomingSort","trash","unpublishAllLocales","where","BAD_REQUEST","data","bulkUpdateData","shouldSaveDraft","Boolean","accessResult","access","update","fullWhere","isTrashAttempt","deletedAt","deleteAccessResult","delete","enableTrash","fields","flattenedFields","docs","versionsWhere","versionFields","query","db","queryDrafts","pagination","find","files","filesToUpload","throwOnMissingFile","errors","promises","map","docWithLocales","id","docShouldCommit","bulkOperationsSingleTransaction","forceSelect","updatedDoc","auth","error","isPublic","Error","push","message","awaitedDocs","promise","Promise","all","result","filter"],"mappings":"AAEA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAA8BC,oBAAoB,QAA0B,iBAAgB;AAC5F,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,gBAAgB,QAAQ,uCAAsC;AACvE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,4BAA4B,QAAQ,0CAAyC;AACtF,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,cAAc,QAAQ,wBAAuB;AA8BtD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAIC,KA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AC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getLocalizedPaths.d.ts","sourceRoot":"","sources":["../../src/database/getLocalizedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAY,KAAK,OAAO,EAAkC,MAAM,aAAa,CAAA;AAEpF,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,cAAsB,EACtB,iBAAiB,EACjB,OAAO,GACR,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,OAAO,EAAE,OAAO,CAAA;CACjB,GAAG,WAAW,EAAE,CA+MhB"}
1
+ {"version":3,"file":"getLocalizedPaths.d.ts","sourceRoot":"","sources":["../../src/database/getLocalizedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAY,KAAK,OAAO,EAAkC,MAAM,aAAa,CAAA;AAGpF,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,cAAsB,EACtB,iBAAiB,EACjB,OAAO,GACR,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,OAAO,EAAE,OAAO,CAAA;CACjB,GAAG,WAAW,EAAE,CA+MhB"}
@@ -1,5 +1,6 @@
1
1
  import { fieldShouldBeLocalized } from '../fields/config/types.js';
2
2
  import { APIError } from '../index.js';
3
+ import { SAFE_FIELD_PATH_REGEX } from '../types/constants.js';
3
4
  export function getLocalizedPaths({ collectionSlug, fields, globalSlug, incomingPath, locale, overrideAccess = false, parentIsLocalized, payload }) {
4
5
  const pathSegments = incomingPath.split('.');
5
6
  const localizationConfig = payload.config.localization;
@@ -156,7 +157,7 @@ export function getLocalizedPaths({ collectionSlug, fields, globalSlug, incoming
156
157
  {
157
158
  const upcomingSegments = pathSegments.slice(i + 1).join('.');
158
159
  pathSegments.forEach((path)=>{
159
- if (!/^\w+(?:\.\w+)*$/.test(path)) {
160
+ if (!SAFE_FIELD_PATH_REGEX.test(path)) {
160
161
  lastIncompletePath.invalid = true;
161
162
  }
162
163
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/database/getLocalizedPaths.ts"],"sourcesContent":["import type { PathToQuery } from './queryValidation/types.js'\n\nimport {\n type Field,\n fieldShouldBeLocalized,\n type FlattenedBlock,\n type FlattenedField,\n} from '../fields/config/types.js'\nimport { APIError, type Payload, type SanitizedCollectionConfig } from '../index.js'\n\nexport function getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n overrideAccess = false,\n parentIsLocalized,\n payload,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n overrideAccess?: boolean\n /**\n * @todo make required in v4.0. Usually, you'd wanna pass this through\n */\n parentIsLocalized?: boolean\n payload: Payload\n}): PathToQuery[] {\n const pathSegments = incomingPath.split('.')\n const localizationConfig = payload.config.localization\n\n let paths: PathToQuery[] = [\n {\n collectionSlug,\n complete: false,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n field: undefined,\n fields,\n globalSlug,\n invalid: false,\n parentIsLocalized: parentIsLocalized!,\n path: '',\n },\n ]\n\n for (let i = 0; i < pathSegments.length; i += 1) {\n const segment = pathSegments[i]\n\n const lastIncompletePath = paths.find(({ complete }) => !complete)\n\n if (lastIncompletePath) {\n const { path } = lastIncompletePath\n let currentPath = path ? `${path}.${segment}` : segment\n\n let fieldsToSearch: FlattenedField[]\n let _parentIsLocalized = parentIsLocalized\n\n let matchedField!: FlattenedField\n\n if (lastIncompletePath?.field?.type === 'blocks') {\n if (segment === 'blockType') {\n matchedField = {\n name: 'blockType',\n type: 'text',\n }\n } else {\n for (const _block of lastIncompletePath.field.blockReferences ??\n lastIncompletePath.field.blocks) {\n let block: FlattenedBlock\n if (typeof _block === 'string') {\n block = payload.blocks[_block]!\n } else {\n block = _block\n }\n\n matchedField = block.flattenedFields.find((field) => field.name === segment)!\n if (matchedField) {\n break\n }\n }\n }\n } else {\n if (lastIncompletePath?.field && 'flattenedFields' in lastIncompletePath.field) {\n fieldsToSearch = lastIncompletePath.field.flattenedFields\n } else {\n fieldsToSearch = lastIncompletePath.fields!\n }\n _parentIsLocalized = parentIsLocalized || lastIncompletePath.field?.localized\n\n matchedField = fieldsToSearch.find((field) => field.name === segment)!\n }\n\n lastIncompletePath.field = matchedField!\n\n if (currentPath === 'globalType' && globalSlug) {\n lastIncompletePath.path = currentPath\n lastIncompletePath.complete = true\n lastIncompletePath.field = {\n name: 'globalType',\n type: 'text',\n }\n\n return paths\n }\n\n if (currentPath === 'relationTo') {\n lastIncompletePath.path = currentPath\n lastIncompletePath.complete = true\n lastIncompletePath.field = {\n name: 'relationTo',\n type: 'select',\n options: Object.keys(payload.collections),\n }\n\n return paths\n }\n\n if (!matchedField && currentPath === 'id' && i === pathSegments.length - 1) {\n lastIncompletePath.path = currentPath\n const idField: Field = {\n name: 'id',\n type: payload.db.defaultIDType as 'text',\n }\n lastIncompletePath.field = idField\n lastIncompletePath.complete = true\n return paths\n }\n\n if (matchedField) {\n if ('hidden' in matchedField && matchedField.hidden && !overrideAccess) {\n lastIncompletePath.invalid = true\n }\n\n const nextSegment = pathSegments[i + 1]!\n const currentFieldIsLocalized = fieldShouldBeLocalized({\n field: matchedField,\n parentIsLocalized: _parentIsLocalized!,\n })\n\n const nextSegmentIsLocale =\n localizationConfig &&\n localizationConfig.localeCodes.includes(nextSegment) &&\n currentFieldIsLocalized\n\n if (nextSegmentIsLocale) {\n // Skip the next iteration, because it's a locale\n i += 1\n currentPath = `${currentPath}.${nextSegment}`\n } else if (localizationConfig && currentFieldIsLocalized) {\n currentPath = `${currentPath}.${locale}`\n }\n\n switch (matchedField.type) {\n case 'join':\n case 'relationship':\n case 'upload': {\n // If this is a polymorphic relation,\n // We only support querying directly (no nested querying)\n if (matchedField.type !== 'join' && typeof matchedField.relationTo !== 'string') {\n lastIncompletePath.path = pathSegments.join('.')\n if (![matchedField.name, 'relationTo', 'value'].includes(pathSegments.at(-1)!)) {\n lastIncompletePath.invalid = true\n } else {\n lastIncompletePath.complete = true\n }\n } else {\n lastIncompletePath.complete = true\n lastIncompletePath.path = currentPath!\n\n const nestedPathToQuery = pathSegments\n .slice(nextSegmentIsLocale ? i + 2 : i + 1)\n .join('.')\n\n if (nestedPathToQuery) {\n let relatedCollection: SanitizedCollectionConfig\n if (matchedField.type === 'join') {\n if (Array.isArray(matchedField.collection)) {\n throw new APIError('Not supported')\n }\n\n relatedCollection = payload.collections[matchedField.collection]!.config\n } else {\n relatedCollection = payload.collections[matchedField.relationTo as string]!.config\n }\n\n const remainingPaths = getLocalizedPaths({\n collectionSlug: relatedCollection.slug,\n fields: relatedCollection.flattenedFields,\n globalSlug,\n incomingPath: nestedPathToQuery,\n locale,\n parentIsLocalized: false,\n payload,\n })\n\n paths = [...paths, ...remainingPaths]\n }\n\n return paths\n }\n\n break\n }\n case 'json':\n case 'richText': {\n const upcomingSegments = pathSegments.slice(i + 1).join('.')\n pathSegments.forEach((path) => {\n if (!/^\\w+(?:\\.\\w+)*$/.test(path)) {\n lastIncompletePath.invalid = true\n }\n })\n lastIncompletePath.complete = true\n lastIncompletePath.path = upcomingSegments\n ? `${currentPath}.${upcomingSegments}`\n : currentPath!\n return paths\n }\n\n default: {\n if (i + 1 === pathSegments.length) {\n lastIncompletePath.complete = true\n }\n lastIncompletePath.path = currentPath!\n }\n }\n } else {\n lastIncompletePath.invalid = true\n lastIncompletePath.path = currentPath!\n return paths\n }\n }\n }\n\n return paths\n}\n"],"names":["fieldShouldBeLocalized","APIError","getLocalizedPaths","collectionSlug","fields","globalSlug","incomingPath","locale","overrideAccess","parentIsLocalized","payload","pathSegments","split","localizationConfig","config","localization","paths","complete","field","undefined","invalid","path","i","length","segment","lastIncompletePath","find","currentPath","fieldsToSearch","_parentIsLocalized","matchedField","type","name","_block","blockReferences","blocks","block","flattenedFields","localized","options","Object","keys","collections","idField","db","defaultIDType","hidden","nextSegment","currentFieldIsLocalized","nextSegmentIsLocale","localeCodes","includes","relationTo","join","at","nestedPathToQuery","slice","relatedCollection","Array","isArray","collection","remainingPaths","slug","upcomingSegments","forEach","test"],"mappings":"AAEA,SAEEA,sBAAsB,QAGjB,4BAA2B;AAClC,SAASC,QAAQ,QAAsD,cAAa;AAEpF,OAAO,SAASC,kBAAkB,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,iBAAiB,KAAK,EACtBC,iBAAiB,EACjBC,OAAO,EAaR;IACC,MAAMC,eAAeL,aAAaM,KAAK,CAAC;IACxC,MAAMC,qBAAqBH,QAAQI,MAAM,CAACC,YAAY;IAEtD,IAAIC,QAAuB;QACzB;YACEb;YACAc,UAAU;YACV,oFAAoF;YACpFC,OAAOC;YACPf;YACAC;YACAe,SAAS;YACTX,mBAAmBA;YACnBY,MAAM;QACR;KACD;IAED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C,IAAI,GAAG+B,IAAI,CAAC;4BACxD1C,aAAaqD,OAAO,CAAC,CAAC3C;gCACpB,IAAI,CAAC,kBAAkB4C,IAAI,CAAC5C,OAAO;oCACjCI,mBAAmBL,OAAO,GAAG;gCAC/B;4BACF;4BACAK,mBAAmBR,QAAQ,GAAG;4BAC9BQ,mBAAmBJ,IAAI,GAAG0C,mBACtB,GAAGpC,YAAY,CAAC,EAAEoC,kBAAkB,GACpCpC;4BACJ,OAAOX;wBACT;oBAEA;wBAAS;4BACP,IAAIM,IAAI,MAAMX,aAAaY,MAAM,EAAE;gCACjCE,mBAAmBR,QAAQ,GAAG;4BAChC;4BACAQ,mBAAmBJ,IAAI,GAAGM;wBAC5B;gBACF;YACF,OAAO;gBACLF,mBAAmBL,OAAO,GAAG;gBAC7BK,mBAAmBJ,IAAI,GAAGM;gBAC1B,OAAOX;YACT;QACF;IACF;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../src/database/getLocalizedPaths.ts"],"sourcesContent":["import type { PathToQuery } from './queryValidation/types.js'\n\nimport {\n type Field,\n fieldShouldBeLocalized,\n type FlattenedBlock,\n type FlattenedField,\n} from '../fields/config/types.js'\nimport { APIError, type Payload, type SanitizedCollectionConfig } from '../index.js'\nimport { SAFE_FIELD_PATH_REGEX } from '../types/constants.js'\n\nexport function getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n overrideAccess = false,\n parentIsLocalized,\n payload,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n overrideAccess?: boolean\n /**\n * @todo make required in v4.0. Usually, you'd wanna pass this through\n */\n parentIsLocalized?: boolean\n payload: Payload\n}): PathToQuery[] {\n const pathSegments = incomingPath.split('.')\n const localizationConfig = payload.config.localization\n\n let paths: PathToQuery[] = [\n {\n collectionSlug,\n complete: false,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n field: undefined,\n fields,\n globalSlug,\n invalid: false,\n parentIsLocalized: parentIsLocalized!,\n path: '',\n },\n ]\n\n for (let i = 0; i < pathSegments.length; i += 1) {\n const segment = pathSegments[i]\n\n const lastIncompletePath = paths.find(({ complete }) => !complete)\n\n if (lastIncompletePath) {\n const { path } = lastIncompletePath\n let currentPath = path ? `${path}.${segment}` : segment\n\n let fieldsToSearch: FlattenedField[]\n let _parentIsLocalized = parentIsLocalized\n\n let matchedField!: FlattenedField\n\n if (lastIncompletePath?.field?.type === 'blocks') {\n if (segment === 'blockType') {\n matchedField = {\n name: 'blockType',\n type: 'text',\n }\n } else {\n for (const _block of lastIncompletePath.field.blockReferences ??\n lastIncompletePath.field.blocks) {\n let block: FlattenedBlock\n if (typeof _block === 'string') {\n block = payload.blocks[_block]!\n } else {\n block = _block\n }\n\n matchedField = block.flattenedFields.find((field) => field.name === segment)!\n if (matchedField) {\n break\n }\n }\n }\n } else {\n if (lastIncompletePath?.field && 'flattenedFields' in lastIncompletePath.field) {\n fieldsToSearch = lastIncompletePath.field.flattenedFields\n } else {\n fieldsToSearch = lastIncompletePath.fields!\n }\n _parentIsLocalized = parentIsLocalized || lastIncompletePath.field?.localized\n\n matchedField = fieldsToSearch.find((field) => field.name === segment)!\n }\n\n lastIncompletePath.field = matchedField!\n\n if (currentPath === 'globalType' && globalSlug) {\n lastIncompletePath.path = currentPath\n lastIncompletePath.complete = true\n lastIncompletePath.field = {\n name: 'globalType',\n type: 'text',\n }\n\n return paths\n }\n\n if (currentPath === 'relationTo') {\n lastIncompletePath.path = currentPath\n lastIncompletePath.complete = true\n lastIncompletePath.field = {\n name: 'relationTo',\n type: 'select',\n options: Object.keys(payload.collections),\n }\n\n return paths\n }\n\n if (!matchedField && currentPath === 'id' && i === pathSegments.length - 1) {\n lastIncompletePath.path = currentPath\n const idField: Field = {\n name: 'id',\n type: payload.db.defaultIDType as 'text',\n }\n lastIncompletePath.field = idField\n lastIncompletePath.complete = true\n return paths\n }\n\n if (matchedField) {\n if ('hidden' in matchedField && matchedField.hidden && !overrideAccess) {\n lastIncompletePath.invalid = true\n }\n\n const nextSegment = pathSegments[i + 1]!\n const currentFieldIsLocalized = fieldShouldBeLocalized({\n field: matchedField,\n parentIsLocalized: _parentIsLocalized!,\n })\n\n const nextSegmentIsLocale =\n localizationConfig &&\n localizationConfig.localeCodes.includes(nextSegment) &&\n currentFieldIsLocalized\n\n if (nextSegmentIsLocale) {\n // Skip the next iteration, because it's a locale\n i += 1\n currentPath = `${currentPath}.${nextSegment}`\n } else if (localizationConfig && currentFieldIsLocalized) {\n currentPath = `${currentPath}.${locale}`\n }\n\n switch (matchedField.type) {\n case 'join':\n case 'relationship':\n case 'upload': {\n // If this is a polymorphic relation,\n // We only support querying directly (no nested querying)\n if (matchedField.type !== 'join' && typeof matchedField.relationTo !== 'string') {\n lastIncompletePath.path = pathSegments.join('.')\n if (![matchedField.name, 'relationTo', 'value'].includes(pathSegments.at(-1)!)) {\n lastIncompletePath.invalid = true\n } else {\n lastIncompletePath.complete = true\n }\n } else {\n lastIncompletePath.complete = true\n lastIncompletePath.path = currentPath!\n\n const nestedPathToQuery = pathSegments\n .slice(nextSegmentIsLocale ? i + 2 : i + 1)\n .join('.')\n\n if (nestedPathToQuery) {\n let relatedCollection: SanitizedCollectionConfig\n if (matchedField.type === 'join') {\n if (Array.isArray(matchedField.collection)) {\n throw new APIError('Not supported')\n }\n\n relatedCollection = payload.collections[matchedField.collection]!.config\n } else {\n relatedCollection = payload.collections[matchedField.relationTo as string]!.config\n }\n\n const remainingPaths = getLocalizedPaths({\n collectionSlug: relatedCollection.slug,\n fields: relatedCollection.flattenedFields,\n globalSlug,\n incomingPath: nestedPathToQuery,\n locale,\n parentIsLocalized: false,\n payload,\n })\n\n paths = [...paths, ...remainingPaths]\n }\n\n return paths\n }\n\n break\n }\n case 'json':\n case 'richText': {\n const upcomingSegments = pathSegments.slice(i + 1).join('.')\n pathSegments.forEach((path) => {\n if (!SAFE_FIELD_PATH_REGEX.test(path)) {\n lastIncompletePath.invalid = true\n }\n })\n lastIncompletePath.complete = true\n lastIncompletePath.path = upcomingSegments\n ? `${currentPath}.${upcomingSegments}`\n : currentPath!\n return paths\n }\n\n default: {\n if (i + 1 === pathSegments.length) {\n lastIncompletePath.complete = true\n }\n lastIncompletePath.path = currentPath!\n }\n }\n } else {\n lastIncompletePath.invalid = true\n lastIncompletePath.path = currentPath!\n return paths\n }\n }\n }\n\n return paths\n}\n"],"names":["fieldShouldBeLocalized","APIError","SAFE_FIELD_PATH_REGEX","getLocalizedPaths","collectionSlug","fields","globalSlug","incomingPath","locale","overrideAccess","parentIsLocalized","payload","pathSegments","split","localizationConfig","config","localization","paths","complete","field","undefined","invalid","path","i","length","segment","lastIncompletePath","find","currentPath","fieldsToSearch","_parentIsLocalized","matchedField","type","name","_block","blockReferences","blocks","block","flattenedFields","localized","options","Object","keys","collections","idField","db","defaultIDType","hidden","nextSegment","currentFieldIsLocalized","nextSegmentIsLocale","localeCodes","includes","relationTo","join","at","nestedPathToQuery","slice","relatedCollection","Array","isArray","collection","remainingPaths","slug","upcomingSegments","forEach","test"],"mappings":"AAEA,SAEEA,sBAAsB,QAGjB,4BAA2B;AAClC,SAASC,QAAQ,QAAsD,cAAa;AACpF,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D,OAAO,SAASC,kBAAkB,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,iBAAiB,KAAK,EACtBC,iBAAiB,EACjBC,OAAO,EAaR;IACC,MAAMC,eAAeL,aAAaM,KAAK,CAAC;IACxC,MAAMC,qBAAqBH,QAAQI,MAAM,CAACC,YAAY;IAEtD,IAAIC,QAAuB;QACzB;YACEb;YACAc,UAAU;YACV,oFAAoF;YACpFC,OAAOC;YACPf;YACAC;YACAe,SAAS;YACTX,mBAAmBA;YACnBY,MAAM;QACR;KACD;IAED,IAAK,IAAIC,IAAI,GAAGA,IAAIX,aAAaY,MAAM,EAAED,KAAK,EAAG;QAC/C,MAAME,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,CAACpB,sBAAsBgE,IAAI,CAAC5C,OAAO;oCACrCI,mBAAmBL,OAAO,GAAG;gCAC/B;4BACF;4BACAK,mBAAmBR,QAAQ,GAAG;4BAC9BQ,mBAAmBJ,IAAI,GAAG0C,mBACtB,GAAGpC,YAAY,CAAC,EAAEoC,kBAAkB,GACpCpC;4BACJ,OAAOX;wBACT;oBAEA;wBAAS;4BACP,IAAIM,IAAI,MAAMX,aAAaY,MAAM,EAAE;gCACjCE,mBAAmBR,QAAQ,GAAG;4BAChC;4BACAQ,mBAAmBJ,IAAI,GAAGM;wBAC5B;gBACF;YACF,OAAO;gBACLF,mBAAmBL,OAAO,GAAG;gBAC7BK,mBAAmBJ,IAAI,GAAGM;gBAC1B,OAAOX;YACT;QACF;IACF;IAEA,OAAOA;AACT"}
@@ -56,7 +56,7 @@ export async function validateQueryPaths({ collectionConfig, errors = [], global
56
56
  val,
57
57
  versionFields
58
58
  }));
59
- } else if (typeof val !== 'object' || val === null) {
59
+ } else {
60
60
  errors.push({
61
61
  path: `${path}.${operator}`
62
62
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/queryValidation/validateQueryPaths.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { Operator, PayloadRequest, Where, WhereField } from '../../types/index.js'\nimport type { EntityPolicies } from './types.js'\n\nimport { QueryError } from '../../errors/QueryError.js'\nimport { validOperatorSet } from '../../types/constants.js'\nimport { validateSearchParam } from './validateSearchParams.js'\n\ntype Args = {\n errors?: { path: string }[]\n overrideAccess: boolean\n // TODO: Rename to permissions or entityPermissions in 4.0\n policies?: EntityPolicies\n polymorphicJoin?: boolean\n req: PayloadRequest\n versionFields?: FlattenedField[]\n where: Where\n} & (\n | {\n collectionConfig: SanitizedCollectionConfig\n globalConfig?: never | undefined\n }\n | {\n collectionConfig?: never | undefined\n globalConfig: SanitizedGlobalConfig\n }\n)\n\nexport async function validateQueryPaths({\n collectionConfig,\n errors = [],\n globalConfig,\n overrideAccess,\n policies = {\n collections: {},\n globals: {},\n },\n polymorphicJoin,\n req,\n versionFields,\n where,\n}: Args): Promise<void> {\n const fields = versionFields || (globalConfig || collectionConfig).flattenedFields\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n const promises: Promise<void>[] = []\n for (const path in where) {\n const constraint = where[path]\n\n if ((path === 'and' || path === 'or') && Array.isArray(constraint)) {\n for (const item of constraint) {\n if (collectionConfig) {\n promises.push(\n validateQueryPaths({\n collectionConfig,\n errors,\n overrideAccess,\n policies,\n polymorphicJoin,\n req,\n versionFields,\n where: item,\n }),\n )\n } else {\n promises.push(\n validateQueryPaths({\n errors,\n globalConfig,\n overrideAccess,\n policies,\n polymorphicJoin,\n req,\n versionFields,\n where: item,\n }),\n )\n }\n }\n } else if (!Array.isArray(constraint)) {\n for (const operator in constraint) {\n const val = constraint[operator as keyof typeof constraint]\n if (validOperatorSet.has(operator as Operator)) {\n promises.push(\n validateSearchParam({\n collectionConfig,\n constraint: where as WhereField,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n path,\n policies,\n polymorphicJoin,\n req,\n val,\n versionFields,\n }),\n )\n } else if (typeof val !== 'object' || val === null) {\n errors.push({ path: `${path}.${operator}` })\n }\n }\n }\n }\n\n await Promise.all(promises)\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n }\n}\n"],"names":["QueryError","validOperatorSet","validateSearchParam","validateQueryPaths","collectionConfig","errors","globalConfig","overrideAccess","policies","collections","globals","polymorphicJoin","req","versionFields","where","fields","flattenedFields","promises","path","constraint","Array","isArray","item","push","operator","val","has","Promise","all","length"],"mappings":"AAMA,SAASA,UAAU,QAAQ,6BAA4B;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,mBAAmB,QAAQ,4BAA2B;AAsB/D,OAAO,eAAeC,mBAAmB,EACvCC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;gBACF;YACF;QACF;QAEA,MAAMG,QAAQC,GAAG,CAACX;QAClB,IAAIZ,OAAOwB,MAAM,GAAG,GAAG;YACrB,MAAM,IAAI7B,WAAWK;QACvB;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/database/queryValidation/validateQueryPaths.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { Operator, PayloadRequest, Where, WhereField } from '../../types/index.js'\nimport type { EntityPolicies } from './types.js'\n\nimport { QueryError } from '../../errors/QueryError.js'\nimport { validOperatorSet } from '../../types/constants.js'\nimport { validateSearchParam } from './validateSearchParams.js'\n\ntype Args = {\n errors?: { path: string }[]\n overrideAccess: boolean\n // TODO: Rename to permissions or entityPermissions in 4.0\n policies?: EntityPolicies\n polymorphicJoin?: boolean\n req: PayloadRequest\n versionFields?: FlattenedField[]\n where: Where\n} & (\n | {\n collectionConfig: SanitizedCollectionConfig\n globalConfig?: never | undefined\n }\n | {\n collectionConfig?: never | undefined\n globalConfig: SanitizedGlobalConfig\n }\n)\n\nexport async function validateQueryPaths({\n collectionConfig,\n errors = [],\n globalConfig,\n overrideAccess,\n policies = {\n collections: {},\n globals: {},\n },\n polymorphicJoin,\n req,\n versionFields,\n where,\n}: Args): Promise<void> {\n const fields = versionFields || (globalConfig || collectionConfig).flattenedFields\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n const promises: Promise<void>[] = []\n for (const path in where) {\n const constraint = where[path]\n\n if ((path === 'and' || path === 'or') && Array.isArray(constraint)) {\n for (const item of constraint) {\n if (collectionConfig) {\n promises.push(\n validateQueryPaths({\n collectionConfig,\n errors,\n overrideAccess,\n policies,\n polymorphicJoin,\n req,\n versionFields,\n where: item,\n }),\n )\n } else {\n promises.push(\n validateQueryPaths({\n errors,\n globalConfig,\n overrideAccess,\n policies,\n polymorphicJoin,\n req,\n versionFields,\n where: item,\n }),\n )\n }\n }\n } else if (!Array.isArray(constraint)) {\n for (const operator in constraint) {\n const val = constraint[operator as keyof typeof constraint]\n if (validOperatorSet.has(operator as Operator)) {\n promises.push(\n validateSearchParam({\n collectionConfig,\n constraint: where as WhereField,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n path,\n policies,\n polymorphicJoin,\n req,\n val,\n versionFields,\n }),\n )\n } else {\n errors.push({ path: `${path}.${operator}` })\n }\n }\n }\n }\n\n await Promise.all(promises)\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n }\n}\n"],"names":["QueryError","validOperatorSet","validateSearchParam","validateQueryPaths","collectionConfig","errors","globalConfig","overrideAccess","policies","collections","globals","polymorphicJoin","req","versionFields","where","fields","flattenedFields","promises","path","constraint","Array","isArray","item","push","operator","val","has","Promise","all","length"],"mappings":"AAMA,SAASA,UAAU,QAAQ,6BAA4B;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,mBAAmB,QAAQ,4BAA2B;AAsB/D,OAAO,eAAeC,mBAAmB,EACvCC,gBAAgB,EAChBC,SAAS,EAAE,EACXC,YAAY,EACZC,cAAc,EACdC,WAAW;IACTC,aAAa,CAAC;IACdC,SAAS,CAAC;AACZ,CAAC,EACDC,eAAe,EACfC,GAAG,EACHC,aAAa,EACbC,KAAK,EACA;IACL,MAAMC,SAASF,iBAAiB,AAACP,CAAAA,gBAAgBF,gBAAe,EAAGY,eAAe;IAElF,IAAI,OAAOF,UAAU,UAAU;QAC7B,uEAAuE;QACvE,MAAMG,WAA4B,EAAE;QACpC,IAAK,MAAMC,QAAQJ,MAAO;YACxB,MAAMK,aAAaL,KAAK,CAACI,KAAK;YAE9B,IAAI,AAACA,CAAAA,SAAS,SAASA,SAAS,IAAG,KAAME,MAAMC,OAAO,CAACF,aAAa;gBAClE,KAAK,MAAMG,QAAQH,WAAY;oBAC7B,IAAIf,kBAAkB;wBACpBa,SAASM,IAAI,CACXpB,mBAAmB;4BACjBC;4BACAC;4BACAE;4BACAC;4BACAG;4BACAC;4BACAC;4BACAC,OAAOQ;wBACT;oBAEJ,OAAO;wBACLL,SAASM,IAAI,CACXpB,mBAAmB;4BACjBE;4BACAC;4BACAC;4BACAC;4BACAG;4BACAC;4BACAC;4BACAC,OAAOQ;wBACT;oBAEJ;gBACF;YACF,OAAO,IAAI,CAACF,MAAMC,OAAO,CAACF,aAAa;gBACrC,IAAK,MAAMK,YAAYL,WAAY;oBACjC,MAAMM,MAAMN,UAAU,CAACK,SAAoC;oBAC3D,IAAIvB,iBAAiByB,GAAG,CAACF,WAAuB;wBAC9CP,SAASM,IAAI,CACXrB,oBAAoB;4BAClBE;4BACAe,YAAYL;4BACZT;4BACAU;4BACAT;4BACAkB;4BACAjB;4BACAW;4BACAV;4BACAG;4BACAC;4BACAa;4BACAZ;wBACF;oBAEJ,OAAO;wBACLR,OAAOkB,IAAI,CAAC;4BAAEL,MAAM,GAAGA,KAAK,CAAC,EAAEM,UAAU;wBAAC;oBAC5C;gBACF;YACF;QACF;QAEA,MAAMG,QAAQC,GAAG,CAACX;QAClB,IAAIZ,OAAOwB,MAAM,GAAG,GAAG;YACrB,MAAM,IAAI7B,WAAWK;QACvB;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateSearchParams.d.ts","sourceRoot":"","sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAQ7D,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IAEZ,QAAQ,EAAE,cAAc,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IACZ,aAAa,CAAC,EAAE,cAAc,EAAE,CAAA;CACjC,CAAA;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,IAAI,EAAE,YAAY,EAClB,QAAQ,EACR,eAAe,EACf,GAAG,EACH,GAAG,EACH,aAAa,GACd,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAoLtB"}
1
+ {"version":3,"file":"validateSearchParams.d.ts","sourceRoot":"","sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAS7D,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IAEZ,QAAQ,EAAE,cAAc,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IACZ,aAAa,CAAC,EAAE,cAAc,EAAE,CAAA;CACjC,CAAA;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,IAAI,EAAE,YAAY,EAClB,QAAQ,EACR,eAAe,EACf,GAAG,EACH,GAAG,EACH,aAAa,GACd,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAoLtB"}
@@ -1,4 +1,5 @@
1
1
  import { fieldAffectsData } from '../../fields/config/types.js';
2
+ import { SAFE_FIELD_PATH_REGEX } from '../../types/constants.js';
2
3
  import { getEntityPermissions } from '../../utilities/getEntityPermissions/getEntityPermissions.js';
3
4
  import { isolateObjectProperty } from '../../utilities/isolateObjectProperty.js';
4
5
  import { getLocalizedPaths } from '../getLocalizedPaths.js';
@@ -50,7 +51,7 @@ import { validateQueryPaths } from './validateQueryPaths.js';
50
51
  }
51
52
  promises.push(...paths.map(async ({ collectionSlug, field, invalid, path }, i)=>{
52
53
  if (invalid) {
53
- if (!polymorphicJoin) {
54
+ if (!polymorphicJoin || !SAFE_FIELD_PATH_REGEX.test(incomingPath)) {
54
55
  errors.push({
55
56
  path
56
57
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { PayloadRequest, WhereField } from '../../types/index.js'\nimport type { EntityPolicies, PathToQuery } from './types.js'\n\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { getEntityPermissions } from '../../utilities/getEntityPermissions/getEntityPermissions.js'\nimport { isolateObjectProperty } from '../../utilities/isolateObjectProperty.js'\nimport { getLocalizedPaths } from '../getLocalizedPaths.js'\nimport { validateQueryPaths } from './validateQueryPaths.js'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n constraint: WhereField\n errors: { path: string }[]\n fields: FlattenedField[]\n globalConfig?: SanitizedGlobalConfig\n operator: string\n overrideAccess: boolean\n parentIsLocalized?: boolean\n path: string\n // TODO: Rename to permissions or entityPermissions in 4.0\n policies: EntityPolicies\n polymorphicJoin?: boolean\n req: PayloadRequest\n val: unknown\n versionFields?: FlattenedField[]\n}\n\n/**\n * Validate the Payload key / value / operator\n */\nexport async function validateSearchParam({\n collectionConfig,\n constraint,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n parentIsLocalized,\n path: incomingPath,\n policies,\n polymorphicJoin,\n req,\n val,\n versionFields,\n}: Args): Promise<void> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath\n if (incomingPath === '_id') {\n sanitizedPath = 'id'\n } else {\n sanitizedPath = incomingPath.replace(/__/g, '.')\n }\n let paths: PathToQuery[] = []\n const { slug } = (collectionConfig || globalConfig)!\n\n const blockReferencesPermissions = {}\n\n if (globalConfig && !policies.globals![slug]) {\n policies.globals![slug] = await getEntityPermissions({\n blockReferencesPermissions,\n entity: globalConfig,\n entityType: 'global',\n fetchData: false,\n operations: ['read'],\n req,\n })\n }\n\n if (sanitizedPath !== 'id') {\n paths = getLocalizedPaths({\n collectionSlug: collectionConfig?.slug,\n fields,\n globalSlug: globalConfig?.slug,\n incomingPath: sanitizedPath,\n locale: req.locale!,\n overrideAccess,\n parentIsLocalized,\n payload: req.payload,\n })\n }\n const promises: Promise<void>[] = []\n\n // Sanitize relation.otherRelation.id to relation.otherRelation\n if (paths.at(-1)?.path === 'id') {\n const previousField = paths.at(-2)?.field\n if (\n previousField &&\n (previousField.type === 'relationship' || previousField.type === 'upload') &&\n typeof previousField.relationTo === 'string'\n ) {\n paths.pop()\n }\n }\n\n promises.push(\n ...paths.map(async ({ collectionSlug, field, invalid, path }, i) => {\n if (invalid) {\n if (!polymorphicJoin) {\n errors.push({ path })\n }\n\n return\n }\n\n // where: { relatedPosts: { equals: 1}} -> { 'relatedPosts.id': { equals: 1}}\n if (field.type === 'join' && path === incomingPath) {\n constraint[`${path}.id` as keyof WhereField] = constraint[path as keyof WhereField]\n delete constraint[path as keyof WhereField]\n }\n\n if ('virtual' in field && field.virtual) {\n if (field.virtual === true) {\n errors.push({ path })\n }\n }\n\n if (polymorphicJoin && path === 'relationTo') {\n return\n }\n\n if (!overrideAccess && fieldAffectsData(field)) {\n if (collectionSlug) {\n if (!policies.collections![collectionSlug]) {\n policies.collections![collectionSlug] = await getEntityPermissions({\n blockReferencesPermissions,\n entity: req.payload.collections[collectionSlug]!.config,\n entityType: 'collection',\n fetchData: false,\n operations: ['read'],\n req: isolateObjectProperty(req, 'transactionID'),\n })\n }\n\n if (\n ['hash', 'salt'].includes(incomingPath) &&\n collectionConfig!.auth &&\n !collectionConfig!.auth?.disableLocalStrategy\n ) {\n errors.push({ path: incomingPath })\n }\n }\n let fieldPath = path\n // remove locale from end of path\n if (path.endsWith(`.${req.locale}`)) {\n fieldPath = path.slice(0, -(req.locale!.length + 1))\n }\n // remove \".value\" from ends of polymorphic relationship paths\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)\n ) {\n fieldPath = fieldPath.replace('.value', '')\n }\n\n const entityType: 'collections' | 'globals' = globalConfig ? 'globals' : 'collections'\n const entitySlug = collectionSlug || globalConfig!.slug\n const segments = fieldPath.split('.')\n\n let fieldAccess: any\n\n if (versionFields) {\n fieldAccess = policies[entityType]![entitySlug]!.fields\n\n if (\n segments[0] === 'parent' ||\n segments[0] === 'version' ||\n segments[0] === 'snapshot' ||\n segments[0] === 'latest'\n ) {\n segments.shift()\n }\n } else {\n fieldAccess = policies[entityType]![entitySlug]!.fields\n }\n\n if (segments.length) {\n segments.forEach((segment) => {\n if (fieldAccess[segment]) {\n if ('fields' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment].fields\n } else {\n fieldAccess = fieldAccess[segment]\n }\n }\n })\n\n if (!fieldAccess?.read?.permission) {\n errors.push({ path: fieldPath })\n }\n }\n }\n\n if (i > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n pathsToQuery.forEach(\n ({ collectionSlug: pathCollectionSlug, path: subPath }, pathToQueryIndex) => {\n // On the \"deepest\" collection,\n // validate query of the relationship\n if (pathToQueryIndex === 0) {\n promises.push(\n validateQueryPaths({\n collectionConfig: req.payload.collections[pathCollectionSlug!]!.config,\n errors,\n globalConfig: undefined,\n overrideAccess,\n policies,\n req,\n where: {\n [subPath]: {\n [operator]: val,\n },\n },\n }),\n )\n }\n },\n )\n }\n }),\n )\n await Promise.all(promises)\n}\n"],"names":["fieldAffectsData","getEntityPermissions","isolateObjectProperty","getLocalizedPaths","validateQueryPaths","validateSearchParam","collectionConfig","constraint","errors","fields","globalConfig","operator","overrideAccess","parentIsLocalized","path","incomingPath","policies","polymorphicJoin","req","val","versionFields","sanitizedPath","replace","paths","slug","blockReferencesPermissions","globals","entity","entityType","fetchData","operations","collectionSlug","globalSlug","locale","payload","promises","at","previousField","field","type","relationTo","pop","push","map","invalid","i","virtual","collections","config","includes","auth","disableLocalStrategy","fieldPath","endsWith","slice","length","Array","isArray","entitySlug","segments","split","fieldAccess","shift","forEach","segment","read","permission","pathsToQuery","reverse","pathCollectionSlug","subPath","pathToQueryIndex","undefined","where","Promise","all"],"mappings":"AAMA,SAASA,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,oBAAoB,QAAQ,+DAA8D;AACnG,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,kBAAkB,QAAQ,0BAAyB;AAoB5D;;CAEC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,gBAAgB,EAChBC,UAAU,EACVC,MAAM,EACNC,MAAM,EACNC,YAAY,EACZC,QAAQ,EACRC,cAAc,EACdC,iBAAiB,EACjBC,MAAMC,YAAY,EAClBC,QAAQ,EACRC,eAAe,EACfC,GAAG,EACHC,GAAG,EACHC,aAAa,EACR;IACL,4DAA4D;IAC5D,IAAIC;IACJ,IAAIN,iBAAiB,OAAO;QAC1BM,gBAAgB;IAClB,OAAO;QACLA,gBAAgBN,aAAaO,OAAO,CAAC,OAAO;IAC9C;IACA,IAAIC,QAAuB,EAAE;IAC7B,MAAM,EAAEC,IAAI,EAAE,GAAIlB,oBAAoBI;IAEtC,MAAMe,6BAA6B,CAAC;IAEpC,IAAIf,gBAAgB,CAACM,SAASU,OAAO,AAAC,CAACF,KAAK,EAAE;QAC5CR,SAASU,OAAO,AAAC,CAACF,KAAK,GAAG,MAAMvB,qBAAqB;YACnDwB;YACAE,QAAQjB;YACRkB,YAAY;YACZC,WAAW;YACXC,YAAY;gBAAC;aAAO;YACpBZ;QACF;IACF;IAEA,IAAIG,kBAAkB,MAAM;QAC1BE,QAAQpB,kBAAkB;YACxB4B,gBAAgBzB,kBAAkBkB;YAClCf;YACAuB,YAAYtB,cAAcc;YAC1BT,cAAcM;YACdY,QAAQf,IAAIe,MAAM;YAClBrB;YACAC;YACAqB,SAAShB,IAAIgB,OAAO;QACtB;IACF;IACA,MAAMC,WAA4B,EAAE;IAEpC,+DAA+D;IAC/D,IAAIZ,MAAMa,EAAE,CAAC,CAAC,IAA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CH,cAAcA,WAAW,CAACG,QAAQ,CAACvD,MAAM;wBAC3C,OAAO;4BACLoD,cAAcA,WAAW,CAACG,QAAQ;wBACpC;oBACF;gBACF;gBAEA,IAAI,CAACH,aAAaI,MAAMC,YAAY;oBAClC1D,OAAOkC,IAAI,CAAC;wBAAE5B,MAAMsC;oBAAU;gBAChC;YACF;QACF;QAEA,IAAIP,IAAI,GAAG;YACT,0CAA0C;YAC1C,6BAA6B;YAC7B,MAAMsB,eAAe5C,MAAM+B,KAAK,CAAC,GAAGc,OAAO;YAE3CD,aAAaJ,OAAO,CAClB,CAAC,EAAEhC,gBAAgBsC,kBAAkB,EAAEvD,MAAMwD,OAAO,EAAE,EAAEC;gBACtD,+BAA+B;gBAC/B,qCAAqC;gBACrC,IAAIA,qBAAqB,GAAG;oBAC1BpC,SAASO,IAAI,CACXtC,mBAAmB;wBACjBE,kBAAkBY,IAAIgB,OAAO,CAACa,WAAW,CAACsB,mBAAoB,CAAErB,MAAM;wBACtExC;wBACAE,cAAc8D;wBACd5D;wBACAI;wBACAE;wBACAuD,OAAO;4BACL,CAACH,QAAQ,EAAE;gCACT,CAAC3D,SAAS,EAAEQ;4BACd;wBACF;oBACF;gBAEJ;YACF;QAEJ;IACF;IAEF,MAAMuD,QAAQC,GAAG,CAACxC;AACpB"}
1
+ {"version":3,"sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { PayloadRequest, WhereField } from '../../types/index.js'\nimport type { EntityPolicies, PathToQuery } from './types.js'\n\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { SAFE_FIELD_PATH_REGEX } from '../../types/constants.js'\nimport { getEntityPermissions } from '../../utilities/getEntityPermissions/getEntityPermissions.js'\nimport { isolateObjectProperty } from '../../utilities/isolateObjectProperty.js'\nimport { getLocalizedPaths } from '../getLocalizedPaths.js'\nimport { validateQueryPaths } from './validateQueryPaths.js'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n constraint: WhereField\n errors: { path: string }[]\n fields: FlattenedField[]\n globalConfig?: SanitizedGlobalConfig\n operator: string\n overrideAccess: boolean\n parentIsLocalized?: boolean\n path: string\n // TODO: Rename to permissions or entityPermissions in 4.0\n policies: EntityPolicies\n polymorphicJoin?: boolean\n req: PayloadRequest\n val: unknown\n versionFields?: FlattenedField[]\n}\n\n/**\n * Validate the Payload key / value / operator\n */\nexport async function validateSearchParam({\n collectionConfig,\n constraint,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n parentIsLocalized,\n path: incomingPath,\n policies,\n polymorphicJoin,\n req,\n val,\n versionFields,\n}: Args): Promise<void> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath\n if (incomingPath === '_id') {\n sanitizedPath = 'id'\n } else {\n sanitizedPath = incomingPath.replace(/__/g, '.')\n }\n let paths: PathToQuery[] = []\n const { slug } = (collectionConfig || globalConfig)!\n\n const blockReferencesPermissions = {}\n\n if (globalConfig && !policies.globals![slug]) {\n policies.globals![slug] = await getEntityPermissions({\n blockReferencesPermissions,\n entity: globalConfig,\n entityType: 'global',\n fetchData: false,\n operations: ['read'],\n req,\n })\n }\n\n if (sanitizedPath !== 'id') {\n paths = getLocalizedPaths({\n collectionSlug: collectionConfig?.slug,\n fields,\n globalSlug: globalConfig?.slug,\n incomingPath: sanitizedPath,\n locale: req.locale!,\n overrideAccess,\n parentIsLocalized,\n payload: req.payload,\n })\n }\n const promises: Promise<void>[] = []\n\n // Sanitize relation.otherRelation.id to relation.otherRelation\n if (paths.at(-1)?.path === 'id') {\n const previousField = paths.at(-2)?.field\n if (\n previousField &&\n (previousField.type === 'relationship' || previousField.type === 'upload') &&\n typeof previousField.relationTo === 'string'\n ) {\n paths.pop()\n }\n }\n\n promises.push(\n ...paths.map(async ({ collectionSlug, field, invalid, path }, i) => {\n if (invalid) {\n if (!polymorphicJoin || !SAFE_FIELD_PATH_REGEX.test(incomingPath)) {\n errors.push({ path })\n }\n\n return\n }\n\n // where: { relatedPosts: { equals: 1}} -> { 'relatedPosts.id': { equals: 1}}\n if (field.type === 'join' && path === incomingPath) {\n constraint[`${path}.id` as keyof WhereField] = constraint[path as keyof WhereField]\n delete constraint[path as keyof WhereField]\n }\n\n if ('virtual' in field && field.virtual) {\n if (field.virtual === true) {\n errors.push({ path })\n }\n }\n\n if (polymorphicJoin && path === 'relationTo') {\n return\n }\n\n if (!overrideAccess && fieldAffectsData(field)) {\n if (collectionSlug) {\n if (!policies.collections![collectionSlug]) {\n policies.collections![collectionSlug] = await getEntityPermissions({\n blockReferencesPermissions,\n entity: req.payload.collections[collectionSlug]!.config,\n entityType: 'collection',\n fetchData: false,\n operations: ['read'],\n req: isolateObjectProperty(req, 'transactionID'),\n })\n }\n\n if (\n ['hash', 'salt'].includes(incomingPath) &&\n collectionConfig!.auth &&\n !collectionConfig!.auth?.disableLocalStrategy\n ) {\n errors.push({ path: incomingPath })\n }\n }\n let fieldPath = path\n // remove locale from end of path\n if (path.endsWith(`.${req.locale}`)) {\n fieldPath = path.slice(0, -(req.locale!.length + 1))\n }\n // remove \".value\" from ends of polymorphic relationship paths\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)\n ) {\n fieldPath = fieldPath.replace('.value', '')\n }\n\n const entityType: 'collections' | 'globals' = globalConfig ? 'globals' : 'collections'\n const entitySlug = collectionSlug || globalConfig!.slug\n const segments = fieldPath.split('.')\n\n let fieldAccess: any\n\n if (versionFields) {\n fieldAccess = policies[entityType]![entitySlug]!.fields\n\n if (\n segments[0] === 'parent' ||\n segments[0] === 'version' ||\n segments[0] === 'snapshot' ||\n segments[0] === 'latest'\n ) {\n segments.shift()\n }\n } else {\n fieldAccess = policies[entityType]![entitySlug]!.fields\n }\n\n if (segments.length) {\n segments.forEach((segment) => {\n if (fieldAccess[segment]) {\n if ('fields' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment].fields\n } else {\n fieldAccess = fieldAccess[segment]\n }\n }\n })\n\n if (!fieldAccess?.read?.permission) {\n errors.push({ path: fieldPath })\n }\n }\n }\n\n if (i > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n pathsToQuery.forEach(\n ({ collectionSlug: pathCollectionSlug, path: subPath }, pathToQueryIndex) => {\n // On the \"deepest\" collection,\n // validate query of the relationship\n if (pathToQueryIndex === 0) {\n promises.push(\n validateQueryPaths({\n collectionConfig: req.payload.collections[pathCollectionSlug!]!.config,\n errors,\n globalConfig: undefined,\n overrideAccess,\n policies,\n req,\n where: {\n [subPath]: {\n [operator]: val,\n },\n },\n }),\n )\n }\n },\n )\n }\n }),\n )\n await Promise.all(promises)\n}\n"],"names":["fieldAffectsData","SAFE_FIELD_PATH_REGEX","getEntityPermissions","isolateObjectProperty","getLocalizedPaths","validateQueryPaths","validateSearchParam","collectionConfig","constraint","errors","fields","globalConfig","operator","overrideAccess","parentIsLocalized","path","incomingPath","policies","polymorphicJoin","req","val","versionFields","sanitizedPath","replace","paths","slug","blockReferencesPermissions","globals","entity","entityType","fetchData","operations","collectionSlug","globalSlug","locale","payload","promises","at","previousField","field","type","relationTo","pop","push","map","invalid","i","test","virtual","collections","config","includes","auth","disableLocalStrategy","fieldPath","endsWith","slice","length","Array","isArray","entitySlug","segments","split","fieldAccess","shift","forEach","segment","read","permission","pathsToQuery","reverse","pathCollectionSlug","subPath","pathToQueryIndex","undefined","where","Promise","all"],"mappings":"AAMA,SAASA,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,qBAAqB,QAAQ,2BAA0B;AAChE,SAASC,oBAAoB,QAAQ,+DAA8D;AACnG,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,kBAAkB,QAAQ,0BAAyB;AAoB5D;;CAEC,GACD,OAAO,eAAeC,oBAAo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C;YAC1C,6BAA6B;YAC7B,MAAMuB,eAAe7C,MAAMgC,KAAK,CAAC,GAAGc,OAAO;YAE3CD,aAAaJ,OAAO,CAClB,CAAC,EAAEjC,gBAAgBuC,kBAAkB,EAAExD,MAAMyD,OAAO,EAAE,EAAEC;gBACtD,+BAA+B;gBAC/B,qCAAqC;gBACrC,IAAIA,qBAAqB,GAAG;oBAC1BrC,SAASO,IAAI,CACXtC,mBAAmB;wBACjBE,kBAAkBY,IAAIgB,OAAO,CAACc,WAAW,CAACsB,mBAAoB,CAAErB,MAAM;wBACtEzC;wBACAE,cAAc+D;wBACd7D;wBACAI;wBACAE;wBACAwD,OAAO;4BACL,CAACH,QAAQ,EAAE;gCACT,CAAC5D,SAAS,EAAEQ;4BACd;wBACF;oBACF;gBAEJ;YACF;QAEJ;IACF;IAEF,MAAMwD,QAAQC,GAAG,CAACzC;AACpB"}
@@ -44,6 +44,7 @@ export { isReactClientComponent, isReactComponentOrFunction, isReactServerCompon
44
44
  export { hoistQueryParamsToAnd, mergeListSearchAndWhere, } from '../utilities/mergeListSearchAndWhere.js';
45
45
  export { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js';
46
46
  export { sanitizeFilename } from '../utilities/sanitizeFilename.js';
47
+ export { sanitizeUrl } from '../utilities/sanitizeUrl.js';
47
48
  export { sanitizeUserDataForEmail } from '../utilities/sanitizeUserDataForEmail.js';
48
49
  export { setsAreEqual } from '../utilities/setsAreEqual.js';
49
50
  export { slugify } from '../utilities/slugify.js';
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/exports/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,GACb,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qBAAq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;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA"}
@@ -42,6 +42,7 @@ export { isReactClientComponent, isReactComponentOrFunction, isReactServerCompon
42
42
  export { hoistQueryParamsToAnd, mergeListSearchAndWhere } from '../utilities/mergeListSearchAndWhere.js';
43
43
  export { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js';
44
44
  export { sanitizeFilename } from '../utilities/sanitizeFilename.js';
45
+ export { sanitizeUrl } from '../utilities/sanitizeUrl.js';
45
46
  export { sanitizeUserDataForEmail } from '../utilities/sanitizeUserDataForEmail.js';
46
47
  export { setsAreEqual } from '../utilities/setsAreEqual.js';
47
48
  export { slugify } from '../utilities/slugify.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/shared.ts"],"sourcesContent":["export {\n generateCookie,\n generateExpiredPayloadCookie,\n generatePayloadCookie,\n getCookieExpiration,\n parseCookies,\n} from '../auth/cookies.js'\n\nexport { getLoginOptions } from '../auth/getLoginOptions.js'\nexport { addSessionToUser, removeExpiredSessions } from '../auth/sessions.js'\nexport { getFromImportMap } from '../bin/generateImportMap/utilities/getFromImportMap.js'\nexport { parsePayloadComponent } from '../bin/generateImportMap/utilities/parsePayloadComponent.js'\nexport { defaults as collectionDefaults } from '../collections/config/defaults.js'\nexport {\n BASE_36_DIGITS,\n generateKeyBetween,\n generateNKeysBetween,\n} from '../config/orderable/fractional-indexing.js'\n\nexport { serverProps } from '../config/types.js'\n\nexport { type Slugify } from '../fields/baseFields/slug/index.js'\n\nexport { defaultTimezones } from '../fields/baseFields/timezone/defaultTimezones.js'\n\nexport {\n fieldAffectsData,\n fieldHasMaxDepth,\n fieldHasSubFields,\n fieldIsArrayType,\n fieldIsBlockType,\n fieldIsGroupType,\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldIsSidebar,\n fieldIsVirtual,\n fieldShouldBeLocalized,\n fieldSupportsMany,\n groupHasName,\n optionIsObject,\n optionIsValue,\n optionsAreObjects,\n tabHasName,\n valueIsValueWithRelation,\n} from '../fields/config/types.js'\n\nexport { getFieldPaths } from '../fields/getFieldPaths.js'\nexport * from '../fields/validations.js'\n\nexport type {\n FolderBreadcrumb,\n FolderDocumentItemKey,\n FolderEnabledColection,\n FolderInterface,\n FolderOrDocument,\n GetFolderDataResult,\n Subfolder,\n} from '../folders/types.js'\n\nexport { buildFolderWhereConstraints } from '../folders/utils/buildFolderWhereConstraints.js'\nexport { formatFolderOrDocumentItem } from '../folders/utils/formatFolderOrDocumentItem.js'\nexport { PREFERENCE_KEYS } from '../preferences/keys.js'\n\nexport { validOperators, validOperatorSet } from '../types/constants.js'\n\nexport { formatFilesize } from '../uploads/formatFilesize.js'\nexport { isImage } from '../uploads/isImage.js'\nexport { appendUploadSelectFields } from '../utilities/appendUploadSelectFields.js'\nexport { applyLocaleFiltering } from '../utilities/applyLocaleFiltering.js'\n\nexport { combineWhereConstraints } from '../utilities/combineWhereConstraints.js'\n\nexport {\n deepCopyObject,\n deepCopyObjectComplex,\n deepCopyObjectSimple,\n deepCopyObjectSimpleWithoutReactComponents,\n} from '../utilities/deepCopyObject.js'\nexport {\n deepMerge,\n deepMergeWithCombinedArrays,\n deepMergeWithReactComponents,\n deepMergeWithSourceArrays,\n} from '../utilities/deepMerge.js'\n\nexport { extractID } from '../utilities/extractID.js'\n\nexport { flattenAllFields } from '../utilities/flattenAllFields.js'\nexport { flattenTopLevelFields } from '../utilities/flattenTopLevelFields.js'\nexport { formatAdminURL } from '../utilities/formatAdminURL.js'\nexport { formatLabels, toWords } from '../utilities/formatLabels.js'\n\nexport { getBestFitFromSizes } from '../utilities/getBestFitFromSizes.js'\nexport { getDataByPath } from '../utilities/getDataByPath.js'\nexport { getFieldPermissions } from '../utilities/getFieldPermissions.js'\nexport { getObjectDotNotation } from '../utilities/getObjectDotNotation.js'\n\nexport { getSafeRedirect } from '../utilities/getSafeRedirect.js'\n\nexport { getSelectMode } from '../utilities/getSelectMode.js'\n\nexport { getSiblingData } from '../utilities/getSiblingData.js'\n\nexport { getUniqueListBy } from '../utilities/getUniqueListBy.js'\n\nexport {\n getAutosaveInterval,\n getVersionsMax,\n hasAutosaveEnabled,\n hasDraftsEnabled,\n hasDraftValidationEnabled,\n hasLocalizeStatusEnabled,\n hasScheduledPublishEnabled,\n} from '../utilities/getVersionsConfig.js'\n\nexport { isNextBuild } from '../utilities/isNextBuild.js'\n\nexport { isNumber } from '../utilities/isNumber.js'\n\nexport { isPlainObject } from '../utilities/isPlainObject.js'\n\nexport {\n isReactClientComponent,\n isReactComponentOrFunction,\n isReactServerComponentOrFunction,\n} from '../utilities/isReactComponent.js'\n\nexport {\n hoistQueryParamsToAnd,\n mergeListSearchAndWhere,\n} from '../utilities/mergeListSearchAndWhere.js'\n\nexport { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js'\n\nexport { sanitizeFilename } from '../utilities/sanitizeFilename.js'\n\nexport { sanitizeUserDataForEmail } from '../utilities/sanitizeUserDataForEmail.js'\n\nexport { setsAreEqual } from '../utilities/setsAreEqual.js'\n\nexport { slugify } from '../utilities/slugify.js'\n\nexport { toKebabCase } from '../utilities/toKebabCase.js'\n\nexport {\n transformColumnsToPreferences,\n transformColumnsToSearchParams,\n} from '../utilities/transformColumnPreferences.js'\n\nexport { transformWhereQuery } from '../utilities/transformWhereQuery.js'\nexport { unflatten } from '../utilities/unflatten.js'\nexport { validateMimeType } from '../utilities/validateMimeType.js'\nexport { validateWhereQuery } from '../utilities/validateWhereQuery.js'\nexport { wait } from '../utilities/wait.js'\nexport { wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js'\nexport { versionDefaults } from '../versions/defaults.js'\n\nexport { deepMergeSimple } from '@payloadcms/translations/utilities'\n"],"names":["generateCookie","generateExpiredPayloadCookie","generatePayloadCookie","getCookieExpiration","parseCookies","getLoginOptions","addSessionToUser","removeExpiredSessions","getFromImportMap","parsePayloadComponent","defaults","collectionDefaults","BASE_36_DIGITS","generateKeyBetween","generateNKeysBetween","serverProps","defaultTimezones","fieldAffectsData","fieldHasMaxDepth","fieldHasSubFields","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","fieldIsHiddenOrDisabled","fieldIsID","fieldIsLocalized","fieldIsPresentationalOnly","fieldIsSidebar","fieldIsVirtual","fieldShouldBeLocalized","fieldSupportsMany","groupHasName","optionIsObject","optionIsValue","optionsAreObjects","tabHasName","valueIsValueWithRelation","getFieldPaths","buildFolderWhereConstraints","formatFolderOrDocumentItem","PREFERENCE_KEYS","validOperators","validOperatorSet","formatFilesize","isImage","appendUploadSelectFields","applyLocaleFiltering","combineWhereConstraints","deepCopyObject","deepCopyObjectComplex","deepCopyObjectSimple","deepCopyObjectSimpleWithoutReactComponents","deepMerge","deepMergeWithCombinedArrays","deepMergeWithReactComponents","deepMergeWithSourceArrays","extractID","flattenAllFields","flattenTopLevelFields","formatAdminURL","formatLabels","toWords","getBestFitFromSizes","getDataByPath","getFieldPermissions","getObjectDotNotation","getSafeRedirect","getSelectMode","getSiblingData","getUniqueListBy","getAutosaveInterval","getVersionsMax","hasAutosaveEnabled","hasDraftsEnabled","hasDraftValidationEnabled","hasLocalizeStatusEnabled","hasScheduledPublishEnabled","isNextBuild","isNumber","isPlainObject","isReactClientComponent","isReactComponentOrFunction","isReactServerComponentOrFunction","hoistQueryParamsToAnd","mergeListSearchAndWhere","reduceFieldsToValues","sanitizeFilename","sanitizeUserDataForEmail","setsAreEqual","slugify","toKebabCase","transformColumnsToPreferences","transformColumnsToSearchParams","transformWhereQuery","unflatten","validateMimeType","validateWhereQuery","wait","wordBoundariesRegex","versionDefaults","deepMergeSimple"],"mappings":"AAAA,SACEA,cAAc,EACdC,4BAA4B,EAC5BC,qBAAqB,EACrBC,mBAAmB,EACnBC,YAAY,QACP,qBAAoB;AAE3B,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,gBAAgB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAC7E,SAASC,gBAAgB,QAAQ,y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
+ {"version":3,"sources":["../../src/exports/shared.ts"],"sourcesContent":["export {\n generateCookie,\n generateExpiredPayloadCookie,\n generatePayloadCookie,\n getCookieExpiration,\n parseCookies,\n} from '../auth/cookies.js'\n\nexport { getLoginOptions } from '../auth/getLoginOptions.js'\nexport { addSessionToUser, removeExpiredSessions } from '../auth/sessions.js'\nexport { getFromImportMap } from '../bin/generateImportMap/utilities/getFromImportMap.js'\nexport { parsePayloadComponent } from '../bin/generateImportMap/utilities/parsePayloadComponent.js'\nexport { defaults as collectionDefaults } from '../collections/config/defaults.js'\nexport {\n BASE_36_DIGITS,\n generateKeyBetween,\n generateNKeysBetween,\n} from '../config/orderable/fractional-indexing.js'\n\nexport { serverProps } from '../config/types.js'\n\nexport { type Slugify } from '../fields/baseFields/slug/index.js'\n\nexport { defaultTimezones } from '../fields/baseFields/timezone/defaultTimezones.js'\n\nexport {\n fieldAffectsData,\n fieldHasMaxDepth,\n fieldHasSubFields,\n fieldIsArrayType,\n fieldIsBlockType,\n fieldIsGroupType,\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldIsSidebar,\n fieldIsVirtual,\n fieldShouldBeLocalized,\n fieldSupportsMany,\n groupHasName,\n optionIsObject,\n optionIsValue,\n optionsAreObjects,\n tabHasName,\n valueIsValueWithRelation,\n} from '../fields/config/types.js'\n\nexport { getFieldPaths } from '../fields/getFieldPaths.js'\nexport * from '../fields/validations.js'\n\nexport type {\n FolderBreadcrumb,\n FolderDocumentItemKey,\n FolderEnabledColection,\n FolderInterface,\n FolderOrDocument,\n GetFolderDataResult,\n Subfolder,\n} from '../folders/types.js'\n\nexport { buildFolderWhereConstraints } from '../folders/utils/buildFolderWhereConstraints.js'\nexport { formatFolderOrDocumentItem } from '../folders/utils/formatFolderOrDocumentItem.js'\nexport { PREFERENCE_KEYS } from '../preferences/keys.js'\n\nexport { validOperators, validOperatorSet } from '../types/constants.js'\n\nexport { formatFilesize } from '../uploads/formatFilesize.js'\nexport { isImage } from '../uploads/isImage.js'\nexport { appendUploadSelectFields } from '../utilities/appendUploadSelectFields.js'\nexport { applyLocaleFiltering } from '../utilities/applyLocaleFiltering.js'\n\nexport { combineWhereConstraints } from '../utilities/combineWhereConstraints.js'\n\nexport {\n deepCopyObject,\n deepCopyObjectComplex,\n deepCopyObjectSimple,\n deepCopyObjectSimpleWithoutReactComponents,\n} from '../utilities/deepCopyObject.js'\nexport {\n deepMerge,\n deepMergeWithCombinedArrays,\n deepMergeWithReactComponents,\n deepMergeWithSourceArrays,\n} from '../utilities/deepMerge.js'\n\nexport { extractID } from '../utilities/extractID.js'\n\nexport { flattenAllFields } from '../utilities/flattenAllFields.js'\nexport { flattenTopLevelFields } from '../utilities/flattenTopLevelFields.js'\nexport { formatAdminURL } from '../utilities/formatAdminURL.js'\nexport { formatLabels, toWords } from '../utilities/formatLabels.js'\n\nexport { getBestFitFromSizes } from '../utilities/getBestFitFromSizes.js'\nexport { getDataByPath } from '../utilities/getDataByPath.js'\nexport { getFieldPermissions } from '../utilities/getFieldPermissions.js'\nexport { getObjectDotNotation } from '../utilities/getObjectDotNotation.js'\n\nexport { getSafeRedirect } from '../utilities/getSafeRedirect.js'\n\nexport { getSelectMode } from '../utilities/getSelectMode.js'\n\nexport { getSiblingData } from '../utilities/getSiblingData.js'\n\nexport { getUniqueListBy } from '../utilities/getUniqueListBy.js'\n\nexport {\n getAutosaveInterval,\n getVersionsMax,\n hasAutosaveEnabled,\n hasDraftsEnabled,\n hasDraftValidationEnabled,\n hasLocalizeStatusEnabled,\n hasScheduledPublishEnabled,\n} from '../utilities/getVersionsConfig.js'\n\nexport { isNextBuild } from '../utilities/isNextBuild.js'\n\nexport { isNumber } from '../utilities/isNumber.js'\n\nexport { isPlainObject } from '../utilities/isPlainObject.js'\n\nexport {\n isReactClientComponent,\n isReactComponentOrFunction,\n isReactServerComponentOrFunction,\n} from '../utilities/isReactComponent.js'\n\nexport {\n hoistQueryParamsToAnd,\n mergeListSearchAndWhere,\n} from '../utilities/mergeListSearchAndWhere.js'\n\nexport { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js'\n\nexport { sanitizeFilename } from '../utilities/sanitizeFilename.js'\n\nexport { sanitizeUrl } from '../utilities/sanitizeUrl.js'\n\nexport { sanitizeUserDataForEmail } from '../utilities/sanitizeUserDataForEmail.js'\n\nexport { setsAreEqual } from '../utilities/setsAreEqual.js'\n\nexport { slugify } from '../utilities/slugify.js'\n\nexport { toKebabCase } from '../utilities/toKebabCase.js'\n\nexport {\n transformColumnsToPreferences,\n transformColumnsToSearchParams,\n} from '../utilities/transformColumnPreferences.js'\n\nexport { transformWhereQuery } from '../utilities/transformWhereQuery.js'\nexport { unflatten } from '../utilities/unflatten.js'\nexport { validateMimeType } from '../utilities/validateMimeType.js'\nexport { validateWhereQuery } from '../utilities/validateWhereQuery.js'\nexport { wait } from '../utilities/wait.js'\nexport { wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js'\nexport { versionDefaults } from '../versions/defaults.js'\n\nexport { deepMergeSimple } from '@payloadcms/translations/utilities'\n"],"names":["generateCookie","generateExpiredPayloadCookie","generatePayloadCookie","getCookieExpiration","parseCookies","getLoginOptions","addSessionToUser","removeExpiredSessions","getFromImportMap","parsePayloadComponent","defaults","collectionDefaults","BASE_36_DIGITS","generateKeyBetween","generateNKeysBetween","serverProps","defaultTimezones","fieldAffectsData","fieldHasMaxDepth","fieldHasSubFields","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","fieldIsHiddenOrDisabled","fieldIsID","fieldIsLocalized","fieldIsPresentationalOnly","fieldIsSidebar","fieldIsVirtual","fieldShouldBeLocalized","fieldSupportsMany","groupHasName","optionIsObject","optionIsValue","optionsAreObjects","tabHasName","valueIsValueWithRelation","getFieldPaths","buildFolderWhereConstraints","formatFolderOrDocumentItem","PREFERENCE_KEYS","validOperators","validOperatorSet","formatFilesize","isImage","appendUploadSelectFields","applyLocaleFiltering","combineWhereConstraints","deepCopyObject","deepCopyObjectComplex","deepCopyObjectSimple","deepCopyObjectSimpleWithoutReactComponents","deepMerge","deepMergeWithCombinedArrays","deepMergeWithReactComponents","deepMergeWithSourceArrays","extractID","flattenAllFields","flattenTopLevelFields","formatAdminURL","formatLabels","toWords","getBestFitFromSizes","getDataByPath","getFieldPermissions","getObjectDotNotation","getSafeRedirect","getSelectMode","getSiblingData","getUniqueListBy","getAutosaveInterval","getVersionsMax","hasAutosaveEnabled","hasDraftsEnabled","hasDraftValidationEnabled","hasLocalizeStatusEnabled","hasScheduledPublishEnabled","isNextBuild","isNumber","isPlainObject","isReactClientComponent","isReactComponentOrFunction","isReactServerComponentOrFunction","hoistQueryParamsToAnd","mergeListSearchAndWhere","reduceFieldsToValues","sanitizeFilename","sanitizeUrl","sanitizeUserDataForEmail","setsAreEqual","slugify","toKebabCase","transformColumnsToPreferences","transformColumnsToSearchParams","transformWhereQuery","unflatten","validateMimeType","validateWhereQuery","wait","wordBoundariesRegex","versionDefaults","deepMergeSimple"],"mappings":"AAAA,SACEA,cAAc,EACdC,4BAA4B,EAC5BC,qBAAqB,EACrBC,mBAAmB,EACnBC,YAAY,QACP,qBAAoB;AAE3B,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,gBAAgB,EAAEC,qBAAqB,QAAQ,sBAAqB;AAC7E,SAASC,gBAAgB,QAAQ,yDAAwD;AACzF,SAASC,qBAAqB,QAAQ,8DAA6D;AACnG,SAASC,YAAYC,kBAAkB,QAAQ,oCAAmC;AAClF,SACEC,cAAc,EACdC,kBAAkB,EAClBC,oBAAoB,QACf,6CAA4C;AAEnD,SAASC,WAAW,QAAQ,qBAAoB;AAIhD,SAASC,gBAAgB,QAAQ,oDAAmD;AAEpF,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,iBAAiB,EACjBC,gBAAgB,EAChBC,gBAAgB,EAChBC,gBAAgB,EAChBC,uBAAuB,EACvBC,SAAS,EACTC,gBAAgB,EAChBC,yBAAyB,EACzBC,cAAc,EACdC,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AyB,EACzBC,wBAAwB,EACxBC,0BAA0B,QACrB,oCAAmC;AAE1C,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,SAASC,QAAQ,QAAQ,2BAA0B;AAEnD,SAASC,aAAa,QAAQ,gCAA+B;AAE7D,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,gCAAgC,QAC3B,mCAAkC;AAEzC,SACEC,qBAAqB,EACrBC,uBAAuB,QAClB,0CAAyC;AAEhD,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,SAASC,gBAAgB,QAAQ,mCAAkC;AAEnE,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,SAASC,wBAAwB,QAAQ,2CAA0C;AAEnF,SAASC,YAAY,QAAQ,+BAA8B;AAE3D,SAASC,OAAO,QAAQ,0BAAyB;AAEjD,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,SACEC,6BAA6B,EAC7BC,8BAA8B,QACzB,6CAA4C;AAEnD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,IAAI,QAAQ,uBAAsB;AAC3C,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,SAASC,eAAe,QAAQ,qCAAoC"}
@@ -13,6 +13,13 @@ export type SlugFieldArgs = {
13
13
  * @default 'generateSlug'
14
14
  */
15
15
  checkboxName?: string;
16
+ /**
17
+ * Disables the unique index on the field.
18
+ * This is useful if instead, you want to add a compound unique index to the collection `indexes` config,
19
+ * for example with the multi tenant plugin, where the slug is only unique per tenant, not globally.
20
+ * @default false
21
+ */
22
+ disableUnique?: boolean;
16
23
  /**
17
24
  * @deprecated use `useAsSlug` instead.
18
25
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/baseFields/slug/index.ts"],"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AC,EAAE,SAAS,CAAC,UAAU,CAAC,CAAA;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,KAAK,QAAQ,CAAA;AAE1D,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;AACvE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GAAG,oBAAoB,CAAA;AAElF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,EAAE,SAuEvB,CAAA"}
@@ -13,7 +13,7 @@ import { generateSlug } from './generateSlug.js';
13
13
  * This is to protect modifying potentially live URLs, breaking links, etc. without explicit intent.
14
14
  *
15
15
  * @experimental This field is experimental and may change or be removed in the future. Use at your own risk.
16
- */ export const slugField = ({ name: slugFieldName = 'slug', checkboxName = 'generateSlug', fieldToUse, localized, overrides, position = 'sidebar', required = true, slugify, useAsSlug: useAsSlugFromArgs = 'title' } = {})=>{
16
+ */ export const slugField = ({ name: slugFieldName = 'slug', checkboxName = 'generateSlug', disableUnique = false, fieldToUse, localized, overrides, position = 'sidebar', required = true, slugify, useAsSlug: useAsSlugFromArgs = 'title' } = {})=>{
17
17
  const useAsSlug = fieldToUse || useAsSlugFromArgs;
18
18
  const baseField = {
19
19
  type: 'row',
@@ -66,7 +66,7 @@ import { generateSlug } from './generateSlug.js';
66
66
  index: true,
67
67
  localized,
68
68
  required,
69
- unique: true
69
+ unique: !disableUnique
70
70
  }
71
71
  ]
72
72
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/baseFields/slug/index.ts"],"sourcesContent":["import type { TextFieldClientProps } from '../../../admin/types.js'\nimport type { TypeWithID } from '../../../collections/config/types.js'\nimport type { FieldAdmin, RowField, TextField } from '../../../fields/config/types.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\nimport { generateSlug } from './generateSlug.js'\n\nexport type Slugify<T extends TypeWithID = any> = (args: {\n data: T\n req: PayloadRequest\n valueToSlugify?: any\n}) => Promise<string | undefined> | string | undefined\n\nexport type SlugFieldArgs = {\n /**\n * Override for the `generateSlug` checkbox field name.\n * @default 'generateSlug'\n */\n checkboxName?: string\n /**\n * @deprecated use `useAsSlug` instead.\n */\n fieldToUse?: string\n /**\n * Enable localization for the slug field.\n */\n localized?: TextField['localized']\n /**\n * Override for the `slug` field name.\n * @default 'slug'\n */\n name?: string\n /**\n * A function used to override the slug field(s) at a granular level.\n * Passes the row field to you to manipulate beyond the exposed options.\n * @example\n * ```ts\n * slugField({\n * overrides: (field) => {\n * field.fields[1].label = 'Custom Slug Label'\n * return field\n * }\n * })\n * ```\n */\n overrides?: (field: RowField) => RowField\n position?: FieldAdmin['position']\n /**\n * Whether or not the `slug` field is required.\n * @default true\n */\n required?: TextField['required']\n /**\n * Provide your own slugify function to override the default.\n */\n slugify?: Slugify\n /**\n * The name of the top-level field to generate the slug from, when applicable.\n * @default 'title'\n */\n useAsSlug?: string\n}\n\nexport type SlugField = (args?: SlugFieldArgs) => RowField\n\nexport type SlugFieldClientPropsOnly = Pick<SlugFieldArgs, 'useAsSlug'>\n/**\n * These are the props that the `SlugField` client component accepts.\n * The `SlugField` server component is responsible for passing down the `slugify` function.\n */\nexport type SlugFieldClientProps = SlugFieldClientPropsOnly & TextFieldClientProps\n\n/**\n * A slug is a unique, indexed, URL-friendly string that identifies a particular document, often used to construct the URL of a webpage.\n * The `slug` field auto-generates its value based on another field, e.g. \"My Title\" → \"my-title\".\n *\n * The slug should continue to be generated through:\n * 1. The `create` operation, unless the user has modified the slug manually\n * 2. The `update` operation, if:\n * a. Autosave is _not_ enabled and there is no slug\n * b. Autosave _is_ enabled, the doc is unpublished, and the user has not modified the slug manually\n *\n * The slug should stabilize after all above criteria have been met, because the URL is typically derived from the slug.\n * This is to protect modifying potentially live URLs, breaking links, etc. without explicit intent.\n *\n * @experimental This field is experimental and may change or be removed in the future. Use at your own risk.\n */\nexport const slugField: SlugField = ({\n name: slugFieldName = 'slug',\n checkboxName = 'generateSlug',\n fieldToUse,\n localized,\n overrides,\n position = 'sidebar',\n required = true,\n slugify,\n useAsSlug: useAsSlugFromArgs = 'title',\n} = {}) => {\n const useAsSlug = fieldToUse || useAsSlugFromArgs\n\n const baseField: RowField = {\n type: 'row',\n admin: {\n position,\n },\n fields: [\n {\n name: checkboxName,\n type: 'checkbox',\n admin: {\n description:\n 'When enabled, the slug will auto-generate from the title field on save and autosave.',\n disableBulkEdit: true,\n disableGroupBy: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n },\n defaultValue: true,\n hooks: {\n beforeChange: [generateSlug({ slugFieldName, slugify, useAsSlug })],\n },\n localized,\n },\n {\n name: slugFieldName,\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n useAsSlug,\n } satisfies SlugFieldClientPropsOnly,\n path: '@payloadcms/next/client#SlugField',\n },\n },\n width: '100%',\n },\n custom: {\n /**\n * This is needed so we can access it from the `slugifyHandler` server function.\n */\n slugify,\n },\n index: true,\n localized,\n required,\n unique: true,\n },\n ],\n }\n\n if (typeof overrides === 'function') {\n return overrides(baseField)\n }\n\n return baseField\n}\n"],"names":["generateSlug","slugField","name","slugFieldName","checkboxName","fieldToUse","localized","overrides","position","required","slugify","useAsSlug","useAsSlugFromArgs","baseField","type","admin","fields","description","disableBulkEdit","disableGroupBy","disableListColumn","disableListFilter","hidden","defaultValue","hooks","beforeChange","components","Field","clientProps","path","width","custom","index","unique"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AAmEhD;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,YAAuB,CAAC,EACnCC,MAAMC,gBAAgB,MAAM,EAC5BC,eAAe,cAAc,EAC7BC,UAAU,EACVC,SAAS,EACTC,SAAS,EACTC,WAAW,SAAS,EACpBC,WAAW,IAAI,EACfC,OAAO,EACPC,WAAWC,oBAAoB,OAAO,EACvC,GAAG,CAAC,CAAC;IACJ,MAAMD,YAAYN,cAAcO;IAEhC,MAAMC,YAAsB;QAC1BC,MAAM;QACNC,OAAO;YACLP;QACF;QACAQ,QAAQ;YACN;gBACEd,MAAME;gBACNU,MAAM;gBACNC,OAAO;oBACLE,aACE;oBACFC,iBAAiB;oBACjBC,gBAAgB;oBAChBC,mBAAmB;oBACnBC,mBAAmB;oBACnBC,QAAQ;gBACV;gBACAC,cAAc;gBACdC,OAAO;oBACLC,cAAc;wBAACzB,aAAa;4BAAEG;4BAAeO;4BAASC;wBAAU;qBAAG;gBACrE;gBACAL;YACF;YACA;gBACEJ,MAAMC;gBACNW,MAAM;gBACNC,OAAO;oBACLW,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXjB;4BACF;4BACAkB,MAAM;wBACR;oBACF;oBACAC,OAAO;gBACT;gBACAC,QAAQ;oBACN;;WAEC,GACDrB;gBACF;gBACAsB,OAAO;gBACP1B;gBACAG;gBACAwB,QAAQ;YACV;SACD;IACH;IAEA,IAAI,OAAO1B,cAAc,YAAY;QACnC,OAAOA,UAAUM;IACnB;IAEA,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/baseFields/slug/index.ts"],"sourcesContent":["import type { TextFieldClientProps } from '../../../admin/types.js'\nimport type { TypeWithID } from '../../../collections/config/types.js'\nimport type { FieldAdmin, RowField, TextField } from '../../../fields/config/types.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\nimport { generateSlug } from './generateSlug.js'\n\nexport type Slugify<T extends TypeWithID = any> = (args: {\n data: T\n req: PayloadRequest\n valueToSlugify?: any\n}) => Promise<string | undefined> | string | undefined\n\nexport type SlugFieldArgs = {\n /**\n * Override for the `generateSlug` checkbox field name.\n * @default 'generateSlug'\n */\n checkboxName?: string\n /**\n * Disables the unique index on the field.\n * This is useful if instead, you want to add a compound unique index to the collection `indexes` config,\n * for example with the multi tenant plugin, where the slug is only unique per tenant, not globally.\n * @default false\n */\n disableUnique?: boolean\n /**\n * @deprecated use `useAsSlug` instead.\n */\n fieldToUse?: string\n /**\n * Enable localization for the slug field.\n */\n localized?: TextField['localized']\n /**\n * Override for the `slug` field name.\n * @default 'slug'\n */\n name?: string\n /**\n * A function used to override the slug field(s) at a granular level.\n * Passes the row field to you to manipulate beyond the exposed options.\n * @example\n * ```ts\n * slugField({\n * overrides: (field) => {\n * field.fields[1].label = 'Custom Slug Label'\n * return field\n * }\n * })\n * ```\n */\n overrides?: (field: RowField) => RowField\n position?: FieldAdmin['position']\n /**\n * Whether or not the `slug` field is required.\n * @default true\n */\n required?: TextField['required']\n /**\n * Provide your own slugify function to override the default.\n */\n slugify?: Slugify\n /**\n * The name of the top-level field to generate the slug from, when applicable.\n * @default 'title'\n */\n useAsSlug?: string\n}\n\nexport type SlugField = (args?: SlugFieldArgs) => RowField\n\nexport type SlugFieldClientPropsOnly = Pick<SlugFieldArgs, 'useAsSlug'>\n/**\n * These are the props that the `SlugField` client component accepts.\n * The `SlugField` server component is responsible for passing down the `slugify` function.\n */\nexport type SlugFieldClientProps = SlugFieldClientPropsOnly & TextFieldClientProps\n\n/**\n * A slug is a unique, indexed, URL-friendly string that identifies a particular document, often used to construct the URL of a webpage.\n * The `slug` field auto-generates its value based on another field, e.g. \"My Title\" → \"my-title\".\n *\n * The slug should continue to be generated through:\n * 1. The `create` operation, unless the user has modified the slug manually\n * 2. The `update` operation, if:\n * a. Autosave is _not_ enabled and there is no slug\n * b. Autosave _is_ enabled, the doc is unpublished, and the user has not modified the slug manually\n *\n * The slug should stabilize after all above criteria have been met, because the URL is typically derived from the slug.\n * This is to protect modifying potentially live URLs, breaking links, etc. without explicit intent.\n *\n * @experimental This field is experimental and may change or be removed in the future. Use at your own risk.\n */\nexport const slugField: SlugField = ({\n name: slugFieldName = 'slug',\n checkboxName = 'generateSlug',\n disableUnique = false,\n fieldToUse,\n localized,\n overrides,\n position = 'sidebar',\n required = true,\n slugify,\n useAsSlug: useAsSlugFromArgs = 'title',\n} = {}) => {\n const useAsSlug = fieldToUse || useAsSlugFromArgs\n\n const baseField: RowField = {\n type: 'row',\n admin: {\n position,\n },\n fields: [\n {\n name: checkboxName,\n type: 'checkbox',\n admin: {\n description:\n 'When enabled, the slug will auto-generate from the title field on save and autosave.',\n disableBulkEdit: true,\n disableGroupBy: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n },\n defaultValue: true,\n hooks: {\n beforeChange: [generateSlug({ slugFieldName, slugify, useAsSlug })],\n },\n localized,\n },\n {\n name: slugFieldName,\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n useAsSlug,\n } satisfies SlugFieldClientPropsOnly,\n path: '@payloadcms/next/client#SlugField',\n },\n },\n width: '100%',\n },\n custom: {\n /**\n * This is needed so we can access it from the `slugifyHandler` server function.\n */\n slugify,\n },\n index: true,\n localized,\n required,\n unique: !disableUnique,\n },\n ],\n }\n\n if (typeof overrides === 'function') {\n return overrides(baseField)\n }\n\n return baseField\n}\n"],"names":["generateSlug","slugField","name","slugFieldName","checkboxName","disableUnique","fieldToUse","localized","overrides","position","required","slugify","useAsSlug","useAsSlugFromArgs","baseField","type","admin","fields","description","disableBulkEdit","disableGroupBy","disableListColumn","disableListFilter","hidden","defaultValue","hooks","beforeChange","components","Field","clientProps","path","width","custom","index","unique"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AA0EhD;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,YAAuB,CAAC,EACnCC,MAAMC,gBAAgB,MAAM,EAC5BC,eAAe,cAAc,EAC7BC,gBAAgB,KAAK,EACrBC,UAAU,EACVC,SAAS,EACTC,SAAS,EACTC,WAAW,SAAS,EACpBC,WAAW,IAAI,EACfC,OAAO,EACPC,WAAWC,oBAAoB,OAAO,EACvC,GAAG,CAAC,CAAC;IACJ,MAAMD,YAAYN,cAAcO;IAEhC,MAAMC,YAAsB;QAC1BC,MAAM;QACNC,OAAO;YACLP;QACF;QACAQ,QAAQ;YACN;gBACEf,MAAME;gBACNW,MAAM;gBACNC,OAAO;oBACLE,aACE;oBACFC,iBAAiB;oBACjBC,gBAAgB;oBAChBC,mBAAmB;oBACnBC,mBAAmB;oBACnBC,QAAQ;gBACV;gBACAC,cAAc;gBACdC,OAAO;oBACLC,cAAc;wBAAC1B,aAAa;4BAAEG;4BAAeQ;4BAASC;wBAAU;qBAAG;gBACrE;gBACAL;YACF;YACA;gBACEL,MAAMC;gBACNY,MAAM;gBACNC,OAAO;oBACLW,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXjB;4BACF;4BACAkB,MAAM;wBACR;oBACF;oBACAC,OAAO;gBACT;gBACAC,QAAQ;oBACN;;WAEC,GACDrB;gBACF;gBACAsB,OAAO;gBACP1B;gBACAG;gBACAwB,QAAQ,CAAC7B;YACX;SACD;IACH;IAEA,IAAI,OAAOG,cAAc,YAAY;QACnC,OAAOA,UAAUM;IACnB;IAEA,OAAOA;AACT,EAAC"}
@@ -48,7 +48,7 @@ export const text = (value, { hasMany, maxLength: fieldMaxLength, maxRows, minLe
48
48
  }
49
49
  }
50
50
  if (required) {
51
- if (!(typeof value === 'string' || Array.isArray(value)) || value?.length === 0) {
51
+ if (!value || (typeof value === 'string' || Array.isArray(value)) && value.length === 0) {
52
52
  return t('validation:required');
53
53
  }
54
54
  }