payload 3.24.0 → 3.25.0-canary.6d6bbd2

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 (82) hide show
  1. package/dist/auth/strategies/jwt.d.ts.map +1 -1
  2. package/dist/auth/strategies/jwt.js +2 -0
  3. package/dist/auth/strategies/jwt.js.map +1 -1
  4. package/dist/bin/index.d.ts.map +1 -1
  5. package/dist/bin/index.js +9 -2
  6. package/dist/bin/index.js.map +1 -1
  7. package/dist/collections/operations/local/count.d.ts +31 -1
  8. package/dist/collections/operations/local/count.d.ts.map +1 -1
  9. package/dist/collections/operations/local/count.js.map +1 -1
  10. package/dist/collections/operations/local/countVersions.d.ts +31 -1
  11. package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
  12. package/dist/collections/operations/local/countVersions.js.map +1 -1
  13. package/dist/collections/operations/local/create.d.ts +66 -1
  14. package/dist/collections/operations/local/create.d.ts.map +1 -1
  15. package/dist/collections/operations/local/create.js.map +1 -1
  16. package/dist/collections/operations/local/delete.d.ts +58 -1
  17. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  18. package/dist/collections/operations/local/delete.js.map +1 -1
  19. package/dist/collections/operations/local/duplicate.d.ts +51 -1
  20. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  21. package/dist/collections/operations/local/duplicate.js.map +1 -1
  22. package/dist/collections/operations/local/find.d.ts +76 -1
  23. package/dist/collections/operations/local/find.d.ts.map +1 -1
  24. package/dist/collections/operations/local/find.js.map +1 -1
  25. package/dist/collections/operations/local/findByID.d.ts +59 -1
  26. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  27. package/dist/collections/operations/local/findByID.js.map +1 -1
  28. package/dist/collections/operations/local/findVersionByID.d.ts +48 -1
  29. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  30. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  31. package/dist/collections/operations/local/findVersions.d.ts +58 -1
  32. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  33. package/dist/collections/operations/local/findVersions.js.map +1 -1
  34. package/dist/collections/operations/local/restoreVersion.d.ts +44 -1
  35. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  36. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  37. package/dist/collections/operations/local/update.d.ts +88 -1
  38. package/dist/collections/operations/local/update.d.ts.map +1 -1
  39. package/dist/collections/operations/local/update.js.map +1 -1
  40. package/dist/fields/config/client.d.ts.map +1 -1
  41. package/dist/fields/config/client.js +8 -4
  42. package/dist/fields/config/client.js.map +1 -1
  43. package/dist/fields/config/types.d.ts +2 -1
  44. package/dist/fields/config/types.d.ts.map +1 -1
  45. package/dist/fields/config/types.js.map +1 -1
  46. package/dist/fields/validations.js +2 -2
  47. package/dist/fields/validations.js.map +1 -1
  48. package/dist/globals/operations/local/countGlobalVersions.d.ts +31 -1
  49. package/dist/globals/operations/local/countGlobalVersions.d.ts.map +1 -1
  50. package/dist/globals/operations/local/countGlobalVersions.js.map +1 -1
  51. package/dist/globals/operations/local/findOne.d.ts +46 -0
  52. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  53. package/dist/globals/operations/local/findOne.js.map +1 -1
  54. package/dist/globals/operations/local/findVersionByID.d.ts +47 -0
  55. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  56. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  57. package/dist/globals/operations/local/findVersions.d.ts +57 -0
  58. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  59. package/dist/globals/operations/local/findVersions.js.map +1 -1
  60. package/dist/globals/operations/local/restoreVersion.d.ts +40 -0
  61. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  62. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  63. package/dist/globals/operations/local/update.d.ts +54 -0
  64. package/dist/globals/operations/local/update.d.ts.map +1 -1
  65. package/dist/globals/operations/local/update.js.map +1 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +4 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/types/constants.d.ts +2 -2
  70. package/dist/types/constants.d.ts.map +1 -1
  71. package/dist/types/constants.js +1 -0
  72. package/dist/types/constants.js.map +1 -1
  73. package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
  74. package/dist/uploads/endpoints/getFile.js +24 -1
  75. package/dist/uploads/endpoints/getFile.js.map +1 -1
  76. package/dist/utilities/checkDocumentLockStatus.js +2 -2
  77. package/dist/utilities/checkDocumentLockStatus.js.map +1 -1
  78. package/dist/utilities/configToJSONSchema.d.ts +1 -1
  79. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  80. package/dist/utilities/configToJSONSchema.js +46 -34
  81. package/dist/utilities/configToJSONSchema.js.map +1 -1
  82. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/validations.ts"],"sourcesContent":["// @ts-strict-ignore\nimport Ajv from 'ajv'\nimport ObjectIdImport from 'bson-objectid'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nimport type { RichTextAdapter } from '../admin/types.js'\nimport type { CollectionSlug } from '../index.js'\nimport type { Where } from '../types/index.js'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n DateField,\n EmailField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RelationshipValue,\n RelationshipValueMany,\n RelationshipValueSingle,\n RichTextField,\n SelectField,\n TextareaField,\n TextField,\n UploadField,\n Validate,\n} from './config/types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport { isValidID } from '../utilities/isValidID.js'\n\nexport type TextFieldValidation = Validate<string, unknown, unknown, TextField>\n\nexport type TextFieldManyValidation = Validate<string[], unknown, unknown, TextField>\n\nexport type TextFieldSingleValidation = Validate<string, unknown, unknown, TextField>\n\nexport const text: TextFieldValidation = (\n value,\n {\n hasMany,\n maxLength: fieldMaxLength,\n maxRows,\n minLength,\n minRows,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (!required) {\n if (!value) {\n return true\n }\n }\n\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') {\n return lengthValidationResult\n }\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n\n const stringsToValidate: string[] = Array.isArray(value) ? value : [value]\n\n for (const stringValue of stringsToValidate) {\n const length = stringValue?.length || 0\n\n if (typeof maxLength === 'number' && length > maxLength) {\n return t('validation:shorterThanMax', { label: t('general:value'), maxLength, stringValue })\n }\n\n if (typeof minLength === 'number' && length < minLength) {\n return t('validation:longerThanMin', { label: t('general:value'), minLength, stringValue })\n }\n }\n\n if (required) {\n if (!(typeof value === 'string' || Array.isArray(value)) || value?.length === 0) {\n return t('validation:required')\n }\n }\n\n return true\n}\n\nexport type PasswordFieldValidation = Validate<string, unknown, unknown, TextField>\n\nexport const password: PasswordFieldValidation = (\n value,\n {\n maxLength: fieldMaxLength,\n minLength = 3,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (value && minLength && value.length < minLength) {\n return t('validation:longerThanMin', { minLength })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type ConfirmPasswordFieldValidation = Validate<\n string,\n unknown,\n { password: string },\n TextField\n>\n\nexport const confirmPassword: ConfirmPasswordFieldValidation = (\n value,\n { req: { t }, required, siblingData },\n) => {\n if (required && !value) {\n return t('validation:required')\n }\n\n if (value && value !== siblingData.password) {\n return t('fields:passwordsDoNotMatch')\n }\n\n return true\n}\n\nexport type EmailFieldValidation = Validate<string, unknown, { username?: string }, EmailField>\n\nexport const email: EmailFieldValidation = (\n value,\n {\n collectionSlug,\n req: {\n payload: { collections, config },\n t,\n },\n required,\n siblingData,\n },\n) => {\n if (collectionSlug) {\n const collection =\n collections?.[collectionSlug]?.config ??\n config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available\n\n if (\n collection.auth.loginWithUsername &&\n !collection.auth.loginWithUsername?.requireUsername &&\n !collection.auth.loginWithUsername?.requireEmail\n ) {\n if (!value && !siblingData?.username) {\n return t('validation:required')\n }\n }\n }\n\n if ((value && !/\\S[^\\s@]*@\\S+\\.\\S+/.test(value)) || (!value && required)) {\n return t('validation:emailAddress')\n }\n\n return true\n}\n\nexport type UsernameFieldValidation = Validate<string, unknown, { email?: string }, TextField>\n\nexport const username: UsernameFieldValidation = (\n value,\n {\n collectionSlug,\n req: {\n payload: { collections, config },\n t,\n },\n required,\n siblingData,\n },\n) => {\n let maxLength: number\n\n if (collectionSlug) {\n const collection =\n collections?.[collectionSlug]?.config ??\n config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available\n\n if (\n collection.auth.loginWithUsername &&\n !collection.auth.loginWithUsername?.requireUsername &&\n !collection.auth.loginWithUsername?.requireEmail\n ) {\n if (!value && !siblingData?.email) {\n return t('validation:required')\n }\n }\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (!value && required) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type TextareaFieldValidation = Validate<string, unknown, unknown, TextareaField>\n\nexport const textarea: TextareaFieldValidation = (\n value,\n {\n maxLength: fieldMaxLength,\n minLength,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (value && minLength && value.length < minLength) {\n return t('validation:longerThanMin', { minLength })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type CodeFieldValidation = Validate<string, unknown, unknown, CodeField>\n\nexport const code: CodeFieldValidation = (value, { req: { t }, required }) => {\n if (required && value === undefined) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type JSONFieldValidation = Validate<\n string,\n unknown,\n unknown,\n { jsonError?: string } & JSONField\n>\n\nexport const json: JSONFieldValidation = async (\n value,\n { jsonError, jsonSchema, req: { t }, required },\n) => {\n const isNotEmpty = (value) => {\n if (value === undefined || value === null) {\n return false\n }\n\n if (Array.isArray(value) && value.length === 0) {\n return false\n }\n\n if (typeof value === 'object' && Object.keys(value).length === 0) {\n return false\n }\n\n return true\n }\n\n const fetchSchema = ({ schema, uri }: Record<string, unknown>) => {\n if (uri && schema) {\n return schema\n }\n // @ts-expect-error\n return fetch(uri)\n .then((response) => {\n if (!response.ok) {\n throw new Error('Network response was not ok')\n }\n return response.json()\n })\n .then((json) => {\n const jsonSchemaSanitizations = {\n id: undefined,\n $id: json.id,\n $schema: 'http://json-schema.org/draft-07/schema#',\n }\n\n return Object.assign(json, jsonSchemaSanitizations)\n })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n if (jsonError !== undefined) {\n return t('validation:invalidInput')\n }\n\n if (jsonSchema && isNotEmpty(value)) {\n try {\n jsonSchema.schema = await fetchSchema(jsonSchema)\n const { schema } = jsonSchema\n // @ts-expect-error\n const ajv = new Ajv()\n\n if (!ajv.validate(schema, value)) {\n return t(ajv.errorsText())\n }\n } catch (error) {\n return t(error.message)\n }\n }\n return true\n}\n\nexport type CheckboxFieldValidation = Validate<boolean, unknown, unknown, CheckboxField>\n\nexport const checkbox: CheckboxFieldValidation = (value, { req: { t }, required }) => {\n if ((value && typeof value !== 'boolean') || (required && typeof value !== 'boolean')) {\n return t('validation:trueOrFalse')\n }\n\n return true\n}\n\nexport type DateFieldValidation = Validate<Date, unknown, unknown, DateField>\n\nexport const date: DateFieldValidation = (\n value,\n { name, req: { t }, required, siblingData, timezone },\n) => {\n const validDate = value && !isNaN(Date.parse(value.toString()))\n\n // We need to also check for the timezone data based on this field's config\n // We cannot do this inside the timezone field validation as it's visually hidden\n const hasRequiredTimezone = timezone && required\n const selectedTimezone: string = siblingData?.[`${name}_tz`]\n // Always resolve to true if the field is not required, as timezone may be optional too then\n const validTimezone = hasRequiredTimezone ? Boolean(selectedTimezone) : true\n\n if (validDate && validTimezone) {\n return true\n }\n\n if (validDate && !validTimezone) {\n return t('validation:timezoneRequired')\n }\n\n if (value) {\n return t('validation:notValidDate', { value })\n }\n\n if (required) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type RichTextFieldValidation = Validate<object, unknown, unknown, RichTextField>\n\nexport const richText: RichTextFieldValidation = async (value, options) => {\n if (!options?.editor) {\n throw new Error('richText field has no editor property.')\n }\n if (typeof options?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = options?.editor\n\n return editor.validate(value, options)\n}\n\nconst validateArrayLength = (\n value,\n options: {\n maxRows?: number\n minRows?: number\n required?: boolean\n t: (key: string, options?: { [key: string]: number | string }) => string\n },\n) => {\n const { maxRows, minRows, required, t } = options\n\n const arrayLength = Array.isArray(value) ? value.length : value || 0\n\n if (!required && arrayLength === 0) {\n return true\n }\n\n if (minRows && arrayLength < minRows) {\n return t('validation:requiresAtLeast', { count: minRows, label: t('general:rows') })\n }\n\n if (maxRows && arrayLength > maxRows) {\n return t('validation:requiresNoMoreThan', { count: maxRows, label: t('general:rows') })\n }\n\n if (required && !arrayLength) {\n return t('validation:requiresAtLeast', { count: 1, label: t('general:row') })\n }\n\n return true\n}\n\nexport type NumberFieldValidation = Validate<number | number[], unknown, unknown, NumberField>\n\nexport type NumberFieldManyValidation = Validate<number[], unknown, unknown, NumberField>\n\nexport type NumberFieldSingleValidation = Validate<number, unknown, unknown, NumberField>\n\nexport const number: NumberFieldValidation = (\n value,\n { hasMany, max, maxRows, min, minRows, req: { t }, required },\n) => {\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') {\n return lengthValidationResult\n }\n }\n\n if (!value && !isNumber(value)) {\n // if no value is present, validate based on required\n if (required) {\n return t('validation:required')\n }\n if (!required) {\n return true\n }\n }\n\n const numbersToValidate: number[] = Array.isArray(value) ? value : [value]\n\n for (const number of numbersToValidate) {\n if (!isNumber(number)) {\n return t('validation:enterNumber')\n }\n\n const numberValue = parseFloat(number as unknown as string)\n\n if (typeof max === 'number' && numberValue > max) {\n return t('validation:greaterThanMax', { label: t('general:value'), max, value })\n }\n\n if (typeof min === 'number' && numberValue < min) {\n return t('validation:lessThanMin', { label: t('general:value'), min, value })\n }\n }\n\n return true\n}\n\nexport type ArrayFieldValidation = Validate<unknown[], unknown, unknown, ArrayField>\n\nexport const array: ArrayFieldValidation = (value, { maxRows, minRows, req: { t }, required }) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nexport type BlocksFieldValidation = Validate<unknown, unknown, unknown, BlocksField>\n\nexport const blocks: BlocksFieldValidation = (\n value,\n { maxRows, minRows, req: { t }, required },\n) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nconst validateFilterOptions: Validate<\n unknown,\n unknown,\n unknown,\n RelationshipField | UploadField\n> = async (\n value,\n { id, blockData, data, filterOptions, relationTo, req, req: { payload, t, user }, siblingData },\n) => {\n if (typeof filterOptions !== 'undefined' && value) {\n const options: {\n [collection: string]: (number | string)[]\n } = {}\n\n const falseCollections: CollectionSlug[] = []\n const collections = !Array.isArray(relationTo) ? [relationTo] : relationTo\n const values = Array.isArray(value) ? value : [value]\n\n for (const collection of collections) {\n try {\n let optionFilter =\n typeof filterOptions === 'function'\n ? await filterOptions({\n id,\n blockData,\n data,\n relationTo: collection,\n req,\n siblingData,\n user,\n })\n : filterOptions\n\n if (optionFilter === true) {\n optionFilter = null\n }\n\n const valueIDs: (number | string)[] = []\n\n values.forEach((val) => {\n if (typeof val === 'object') {\n if (val?.value) {\n valueIDs.push(val.value)\n } else if (ObjectId.isValid(val)) {\n valueIDs.push(new ObjectId(val).toHexString())\n }\n }\n\n if (typeof val === 'string' || typeof val === 'number') {\n valueIDs.push(val)\n }\n })\n\n if (valueIDs.length > 0) {\n const findWhere: Where = {\n and: [{ id: { in: valueIDs } }],\n }\n\n if (optionFilter && optionFilter !== true) {\n findWhere.and.push(optionFilter)\n }\n\n if (optionFilter === false) {\n falseCollections.push(collection)\n }\n\n const result = await payload.find({\n collection,\n depth: 0,\n limit: 0,\n pagination: false,\n req,\n where: findWhere,\n })\n\n options[collection] = result.docs.map((doc) => doc.id)\n } else {\n options[collection] = []\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Error validating filter options for collection ${collection}`,\n })\n options[collection] = []\n }\n }\n\n const invalidRelationships = values.filter((val) => {\n let collection: string\n let requestedID: number | string\n\n if (typeof relationTo === 'string') {\n collection = relationTo\n\n if (typeof val === 'string' || typeof val === 'number') {\n requestedID = val\n }\n\n if (typeof val === 'object' && ObjectId.isValid(val)) {\n requestedID = new ObjectId(val).toHexString()\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collection = val.relationTo\n requestedID = val.value\n }\n\n if (falseCollections.find((slug) => relationTo === slug)) {\n return true\n }\n\n if (!options[collection]) {\n return true\n }\n\n return options[collection].indexOf(requestedID) === -1\n })\n\n if (invalidRelationships.length > 0) {\n return invalidRelationships.reduce((err, invalid, i) => {\n return `${err} ${JSON.stringify(invalid)}${\n invalidRelationships.length === i + 1 ? ',' : ''\n } `\n }, t('validation:invalidSelections')) as string\n }\n\n return true\n }\n\n return true\n}\n\nexport type UploadFieldValidation = Validate<unknown, unknown, unknown, UploadField>\n\nexport type UploadFieldManyValidation = Validate<unknown[], unknown, unknown, UploadField>\n\nexport type UploadFieldSingleValidation = Validate<unknown, unknown, unknown, UploadField>\n\nexport const upload: UploadFieldValidation = async (value, options) => {\n const {\n event,\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if (\n ((!value && typeof value !== 'number') || (Array.isArray(value) && value.length === 0)) &&\n required\n ) {\n return t('validation:required')\n }\n\n if (Array.isArray(value) && value.length > 0) {\n if (minRows && value.length < minRows) {\n return t('validation:lessThanMin', {\n label: t('general:rows'),\n min: minRows,\n value: value.length,\n })\n }\n\n if (maxRows && value.length > maxRows) {\n return t('validation:greaterThanMax', {\n label: t('general:rows'),\n max: maxRows,\n value: value.length,\n })\n }\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const values = Array.isArray(value) ? value : [value]\n\n const invalidRelationships = values.filter((val) => {\n let collectionSlug: string\n let requestedID\n\n if (typeof relationTo === 'string') {\n collectionSlug = relationTo\n\n // custom id\n if (val || typeof val === 'number') {\n requestedID = val\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collectionSlug = val.relationTo\n requestedID = val.value\n }\n\n if (requestedID === null) {\n return false\n }\n\n const idType =\n payload.collections[collectionSlug]?.customIDType || payload?.db?.defaultIDType || 'text'\n\n return !isValidID(requestedID, idType)\n })\n\n if (invalidRelationships.length > 0) {\n return `This relationship field has the following invalid relationships: ${invalidRelationships\n .map((err, invalid) => {\n return `${err} ${JSON.stringify(invalid)}`\n })\n .join(', ')}`\n }\n }\n\n if (event === 'onChange') {\n return true\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport type RelationshipFieldValidation = Validate<\n RelationshipValue,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport type RelationshipFieldManyValidation = Validate<\n RelationshipValueMany,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport type RelationshipFieldSingleValidation = Validate<\n RelationshipValueSingle,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport const relationship: RelationshipFieldValidation = async (value, options) => {\n const {\n event,\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if (\n ((!value && typeof value !== 'number') || (Array.isArray(value) && value.length === 0)) &&\n required\n ) {\n return t('validation:required')\n }\n\n if (Array.isArray(value) && value.length > 0) {\n if (minRows && value.length < minRows) {\n return t('validation:lessThanMin', {\n label: t('general:rows'),\n min: minRows,\n value: value.length,\n })\n }\n\n if (maxRows && value.length > maxRows) {\n return t('validation:greaterThanMax', {\n label: t('general:rows'),\n max: maxRows,\n value: value.length,\n })\n }\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const values = Array.isArray(value) ? value : [value]\n\n const invalidRelationships = values.filter((val) => {\n let collectionSlug: string\n let requestedID\n\n if (typeof relationTo === 'string') {\n collectionSlug = relationTo\n\n // custom id\n if (val || typeof val === 'number') {\n requestedID = val\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collectionSlug = val.relationTo\n requestedID = val.value\n }\n\n if (requestedID === null) {\n return false\n }\n\n const idType =\n payload.collections[collectionSlug]?.customIDType || payload?.db?.defaultIDType || 'text'\n\n return !isValidID(requestedID, idType)\n })\n\n if (invalidRelationships.length > 0) {\n return `This relationship field has the following invalid relationships: ${invalidRelationships\n .map((err, invalid) => {\n return `${err} ${JSON.stringify(invalid)}`\n })\n .join(', ')}`\n }\n }\n\n if (event === 'onChange') {\n return true\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport type SelectFieldValidation = Validate<string | string[], unknown, unknown, SelectField>\n\nexport type SelectFieldManyValidation = Validate<string[], unknown, unknown, SelectField>\n\nexport type SelectFieldSingleValidation = Validate<string, unknown, unknown, SelectField>\n\nexport const select: SelectFieldValidation = (\n value,\n { hasMany, options, req: { t }, required },\n) => {\n if (\n Array.isArray(value) &&\n value.some(\n (input) =>\n !options.some(\n (option) => option === input || (typeof option !== 'string' && option?.value === input),\n ),\n )\n ) {\n return t('validation:invalidSelection')\n }\n\n if (\n typeof value === 'string' &&\n !options.some(\n (option) => option === value || (typeof option !== 'string' && option.value === value),\n )\n ) {\n return t('validation:invalidSelection')\n }\n\n if (\n required &&\n (typeof value === 'undefined' ||\n value === null ||\n (hasMany && Array.isArray(value) && (value as [])?.length === 0))\n ) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type RadioFieldValidation = Validate<unknown, unknown, unknown, RadioField>\n\nexport const radio: RadioFieldValidation = (value, { options, req: { t }, required }) => {\n if (value) {\n const valueMatchesOption = options.some(\n (option) => option === value || (typeof option !== 'string' && option.value === value),\n )\n return valueMatchesOption || t('validation:invalidSelection')\n }\n\n return required ? t('validation:required') : true\n}\n\nexport type PointFieldValidation = Validate<\n [number | string, number | string],\n unknown,\n unknown,\n PointField\n>\n\nexport const point: PointFieldValidation = (value = ['', ''], { req: { t }, required }) => {\n const lng = parseFloat(String(value[0]))\n const lat = parseFloat(String(value[1]))\n if (\n required &&\n ((value[0] && value[1] && typeof lng !== 'number' && typeof lat !== 'number') ||\n Number.isNaN(lng) ||\n Number.isNaN(lat) ||\n (Array.isArray(value) && value.length !== 2))\n ) {\n return t('validation:requiresTwoNumbers')\n }\n\n if ((value[1] && Number.isNaN(lng)) || (value[0] && Number.isNaN(lat))) {\n return t('validation:invalidInput')\n }\n\n return true\n}\n\n/**\n * Built-in field validations used by Payload\n *\n * These can be re-used in custom validations\n */\nexport const validations = {\n array,\n blocks,\n checkbox,\n code,\n confirmPassword,\n date,\n email,\n json,\n number,\n password,\n point,\n radio,\n relationship,\n richText,\n select,\n text,\n textarea,\n upload,\n}\n"],"names":["Ajv","ObjectIdImport","ObjectId","default","isNumber","isValidID","text","value","hasMany","maxLength","fieldMaxLength","maxRows","minLength","minRows","req","payload","config","t","required","lengthValidationResult","validateArrayLength","defaultMaxTextLength","stringsToValidate","Array","isArray","stringValue","length","label","password","confirmPassword","siblingData","email","collectionSlug","collections","collection","find","slug","auth","loginWithUsername","requireUsername","requireEmail","username","test","textarea","code","undefined","json","jsonError","jsonSchema","isNotEmpty","Object","keys","fetchSchema","schema","uri","fetch","then","response","ok","Error","jsonSchemaSanitizations","id","$id","$schema","assign","ajv","validate","errorsText","error","message","checkbox","date","name","timezone","validDate","isNaN","Date","parse","toString","hasRequiredTimezone","selectedTimezone","validTimezone","Boolean","richText","options","editor","arrayLength","count","number","max","min","numbersToValidate","numberValue","parseFloat","array","blocks","validateFilterOptions","blockData","data","filterOptions","relationTo","user","falseCollections","values","optionFilter","valueIDs","forEach","val","push","isValid","toHexString","findWhere","and","in","result","depth","limit","pagination","where","docs","map","doc","err","logger","msg","invalidRelationships","filter","requestedID","indexOf","reduce","invalid","i","JSON","stringify","upload","event","idType","customIDType","db","defaultIDType","join","relationship","select","some","input","option","radio","valueMatchesOption","point","lng","String","lat","Number","validations"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,SAAS,MAAK;AACrB,OAAOC,oBAAoB,gBAAe;AAE1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AA4BF,SAASG,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AAQrD,OAAO,MAAMC,OAA4B,CACvCC,OACA,EACEC,OAAO,EACPC,WAAWC,cAAc,EACzBC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACnBC,CAAC,EACF,EACDC,QAAQ,EACT;IAED,IAAIT;IAEJ,IAAI,CAACS,UAAU;QACb,IAAI,CAACX,OAAO;YACV,OAAO;QACT;IACF;IAEA,IAAIC,YAAY,MAAM;QACpB,MAAMW,yBAAyBC,oBAAoBb,OAAO;YAAEI;YAASE;YAASK;YAAUD;QAAE;QAC1F,IAAI,OAAOE,2BAA2B,UAAU;YAC9C,OAAOA;QACT;IACF;IAEA,IAAI,OAAOH,QAAQK,yBAAyB,UAA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,OAAO,MAAMwI,cAAc;IACzB3D;IACAC;IACAzB;IACA1B;IACAf;IACA0C;IACAxC;IACAe;IACA0C;IACA5D;IACAwH;IACAF;IACAL;IACA1D;IACA2D;IACAxI;IACAqC;IACA2F;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/validations.ts"],"sourcesContent":["// @ts-strict-ignore\nimport Ajv from 'ajv'\nimport ObjectIdImport from 'bson-objectid'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nimport type { RichTextAdapter } from '../admin/types.js'\nimport type { CollectionSlug } from '../index.js'\nimport type { Where } from '../types/index.js'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n DateField,\n EmailField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RelationshipValue,\n RelationshipValueMany,\n RelationshipValueSingle,\n RichTextField,\n SelectField,\n TextareaField,\n TextField,\n UploadField,\n Validate,\n} from './config/types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport { isValidID } from '../utilities/isValidID.js'\n\nexport type TextFieldValidation = Validate<string, unknown, unknown, TextField>\n\nexport type TextFieldManyValidation = Validate<string[], unknown, unknown, TextField>\n\nexport type TextFieldSingleValidation = Validate<string, unknown, unknown, TextField>\n\nexport const text: TextFieldValidation = (\n value,\n {\n hasMany,\n maxLength: fieldMaxLength,\n maxRows,\n minLength,\n minRows,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (!required) {\n if (!value) {\n return true\n }\n }\n\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') {\n return lengthValidationResult\n }\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n\n const stringsToValidate: string[] = Array.isArray(value) ? value : [value]\n\n for (const stringValue of stringsToValidate) {\n const length = stringValue?.length || 0\n\n if (typeof maxLength === 'number' && length > maxLength) {\n return t('validation:shorterThanMax', { label: t('general:value'), maxLength, stringValue })\n }\n\n if (typeof minLength === 'number' && length < minLength) {\n return t('validation:longerThanMin', { label: t('general:value'), minLength, stringValue })\n }\n }\n\n if (required) {\n if (!(typeof value === 'string' || Array.isArray(value)) || value?.length === 0) {\n return t('validation:required')\n }\n }\n\n return true\n}\n\nexport type PasswordFieldValidation = Validate<string, unknown, unknown, TextField>\n\nexport const password: PasswordFieldValidation = (\n value,\n {\n maxLength: fieldMaxLength,\n minLength = 3,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (value && minLength && value.length < minLength) {\n return t('validation:longerThanMin', { minLength })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type ConfirmPasswordFieldValidation = Validate<\n string,\n unknown,\n { password: string },\n TextField\n>\n\nexport const confirmPassword: ConfirmPasswordFieldValidation = (\n value,\n { req: { t }, required, siblingData },\n) => {\n if (required && !value) {\n return t('validation:required')\n }\n\n if (value && value !== siblingData.password) {\n return t('fields:passwordsDoNotMatch')\n }\n\n return true\n}\n\nexport type EmailFieldValidation = Validate<string, unknown, { username?: string }, EmailField>\n\nexport const email: EmailFieldValidation = (\n value,\n {\n collectionSlug,\n req: {\n payload: { collections, config },\n t,\n },\n required,\n siblingData,\n },\n) => {\n if (collectionSlug) {\n const collection =\n collections?.[collectionSlug]?.config ??\n config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available\n\n if (\n collection.auth.loginWithUsername &&\n !collection.auth.loginWithUsername?.requireUsername &&\n !collection.auth.loginWithUsername?.requireEmail\n ) {\n if (!value && !siblingData?.username) {\n return t('validation:required')\n }\n }\n }\n\n if ((value && !/\\S[^\\s@]*@\\S+\\.\\S+/.test(value)) || (!value && required)) {\n return t('validation:emailAddress')\n }\n\n return true\n}\n\nexport type UsernameFieldValidation = Validate<string, unknown, { email?: string }, TextField>\n\nexport const username: UsernameFieldValidation = (\n value,\n {\n collectionSlug,\n req: {\n payload: { collections, config },\n t,\n },\n required,\n siblingData,\n },\n) => {\n let maxLength: number\n\n if (collectionSlug) {\n const collection =\n collections?.[collectionSlug]?.config ??\n config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available\n\n if (\n collection.auth.loginWithUsername &&\n !collection.auth.loginWithUsername?.requireUsername &&\n !collection.auth.loginWithUsername?.requireEmail\n ) {\n if (!value && !siblingData?.email) {\n return t('validation:required')\n }\n }\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (!value && required) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type TextareaFieldValidation = Validate<string, unknown, unknown, TextareaField>\n\nexport const textarea: TextareaFieldValidation = (\n value,\n {\n maxLength: fieldMaxLength,\n minLength,\n req: {\n payload: { config },\n t,\n },\n required,\n },\n) => {\n let maxLength: number\n\n if (typeof config?.defaultMaxTextLength === 'number') {\n maxLength = config.defaultMaxTextLength\n }\n if (typeof fieldMaxLength === 'number') {\n maxLength = fieldMaxLength\n }\n if (value && maxLength && value.length > maxLength) {\n return t('validation:shorterThanMax', { maxLength })\n }\n\n if (value && minLength && value.length < minLength) {\n return t('validation:longerThanMin', { minLength })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type CodeFieldValidation = Validate<string, unknown, unknown, CodeField>\n\nexport const code: CodeFieldValidation = (value, { req: { t }, required }) => {\n if (required && value === undefined) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type JSONFieldValidation = Validate<\n string,\n unknown,\n unknown,\n { jsonError?: string } & JSONField\n>\n\nexport const json: JSONFieldValidation = async (\n value,\n { jsonError, jsonSchema, req: { t }, required },\n) => {\n const isNotEmpty = (value) => {\n if (value === undefined || value === null) {\n return false\n }\n\n if (Array.isArray(value) && value.length === 0) {\n return false\n }\n\n if (typeof value === 'object' && Object.keys(value).length === 0) {\n return false\n }\n\n return true\n }\n\n const fetchSchema = ({ schema, uri }: Record<string, unknown>) => {\n if (uri && schema) {\n return schema\n }\n // @ts-expect-error\n return fetch(uri)\n .then((response) => {\n if (!response.ok) {\n throw new Error('Network response was not ok')\n }\n return response.json()\n })\n .then((json) => {\n const jsonSchemaSanitizations = {\n id: undefined,\n $id: json.id,\n $schema: 'http://json-schema.org/draft-07/schema#',\n }\n\n return Object.assign(json, jsonSchemaSanitizations)\n })\n }\n\n if (required && !value) {\n return t('validation:required')\n }\n\n if (jsonError !== undefined) {\n return t('validation:invalidInput')\n }\n\n if (jsonSchema && isNotEmpty(value)) {\n try {\n jsonSchema.schema = await fetchSchema(jsonSchema)\n const { schema } = jsonSchema\n // @ts-expect-error\n const ajv = new Ajv()\n\n if (!ajv.validate(schema, value)) {\n return ajv.errorsText()\n }\n } catch (error) {\n return error.message\n }\n }\n return true\n}\n\nexport type CheckboxFieldValidation = Validate<boolean, unknown, unknown, CheckboxField>\n\nexport const checkbox: CheckboxFieldValidation = (value, { req: { t }, required }) => {\n if ((value && typeof value !== 'boolean') || (required && typeof value !== 'boolean')) {\n return t('validation:trueOrFalse')\n }\n\n return true\n}\n\nexport type DateFieldValidation = Validate<Date, unknown, unknown, DateField>\n\nexport const date: DateFieldValidation = (\n value,\n { name, req: { t }, required, siblingData, timezone },\n) => {\n const validDate = value && !isNaN(Date.parse(value.toString()))\n\n // We need to also check for the timezone data based on this field's config\n // We cannot do this inside the timezone field validation as it's visually hidden\n const hasRequiredTimezone = timezone && required\n const selectedTimezone: string = siblingData?.[`${name}_tz`]\n // Always resolve to true if the field is not required, as timezone may be optional too then\n const validTimezone = hasRequiredTimezone ? Boolean(selectedTimezone) : true\n\n if (validDate && validTimezone) {\n return true\n }\n\n if (validDate && !validTimezone) {\n return t('validation:timezoneRequired')\n }\n\n if (value) {\n return t('validation:notValidDate', { value })\n }\n\n if (required) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type RichTextFieldValidation = Validate<object, unknown, unknown, RichTextField>\n\nexport const richText: RichTextFieldValidation = async (value, options) => {\n if (!options?.editor) {\n throw new Error('richText field has no editor property.')\n }\n if (typeof options?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = options?.editor\n\n return editor.validate(value, options)\n}\n\nconst validateArrayLength = (\n value,\n options: {\n maxRows?: number\n minRows?: number\n required?: boolean\n t: (key: string, options?: { [key: string]: number | string }) => string\n },\n) => {\n const { maxRows, minRows, required, t } = options\n\n const arrayLength = Array.isArray(value) ? value.length : value || 0\n\n if (!required && arrayLength === 0) {\n return true\n }\n\n if (minRows && arrayLength < minRows) {\n return t('validation:requiresAtLeast', { count: minRows, label: t('general:rows') })\n }\n\n if (maxRows && arrayLength > maxRows) {\n return t('validation:requiresNoMoreThan', { count: maxRows, label: t('general:rows') })\n }\n\n if (required && !arrayLength) {\n return t('validation:requiresAtLeast', { count: 1, label: t('general:row') })\n }\n\n return true\n}\n\nexport type NumberFieldValidation = Validate<number | number[], unknown, unknown, NumberField>\n\nexport type NumberFieldManyValidation = Validate<number[], unknown, unknown, NumberField>\n\nexport type NumberFieldSingleValidation = Validate<number, unknown, unknown, NumberField>\n\nexport const number: NumberFieldValidation = (\n value,\n { hasMany, max, maxRows, min, minRows, req: { t }, required },\n) => {\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') {\n return lengthValidationResult\n }\n }\n\n if (!value && !isNumber(value)) {\n // if no value is present, validate based on required\n if (required) {\n return t('validation:required')\n }\n if (!required) {\n return true\n }\n }\n\n const numbersToValidate: number[] = Array.isArray(value) ? value : [value]\n\n for (const number of numbersToValidate) {\n if (!isNumber(number)) {\n return t('validation:enterNumber')\n }\n\n const numberValue = parseFloat(number as unknown as string)\n\n if (typeof max === 'number' && numberValue > max) {\n return t('validation:greaterThanMax', { label: t('general:value'), max, value })\n }\n\n if (typeof min === 'number' && numberValue < min) {\n return t('validation:lessThanMin', { label: t('general:value'), min, value })\n }\n }\n\n return true\n}\n\nexport type ArrayFieldValidation = Validate<unknown[], unknown, unknown, ArrayField>\n\nexport const array: ArrayFieldValidation = (value, { maxRows, minRows, req: { t }, required }) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nexport type BlocksFieldValidation = Validate<unknown, unknown, unknown, BlocksField>\n\nexport const blocks: BlocksFieldValidation = (\n value,\n { maxRows, minRows, req: { t }, required },\n) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nconst validateFilterOptions: Validate<\n unknown,\n unknown,\n unknown,\n RelationshipField | UploadField\n> = async (\n value,\n { id, blockData, data, filterOptions, relationTo, req, req: { payload, t, user }, siblingData },\n) => {\n if (typeof filterOptions !== 'undefined' && value) {\n const options: {\n [collection: string]: (number | string)[]\n } = {}\n\n const falseCollections: CollectionSlug[] = []\n const collections = !Array.isArray(relationTo) ? [relationTo] : relationTo\n const values = Array.isArray(value) ? value : [value]\n\n for (const collection of collections) {\n try {\n let optionFilter =\n typeof filterOptions === 'function'\n ? await filterOptions({\n id,\n blockData,\n data,\n relationTo: collection,\n req,\n siblingData,\n user,\n })\n : filterOptions\n\n if (optionFilter === true) {\n optionFilter = null\n }\n\n const valueIDs: (number | string)[] = []\n\n values.forEach((val) => {\n if (typeof val === 'object') {\n if (val?.value) {\n valueIDs.push(val.value)\n } else if (ObjectId.isValid(val)) {\n valueIDs.push(new ObjectId(val).toHexString())\n }\n }\n\n if (typeof val === 'string' || typeof val === 'number') {\n valueIDs.push(val)\n }\n })\n\n if (valueIDs.length > 0) {\n const findWhere: Where = {\n and: [{ id: { in: valueIDs } }],\n }\n\n if (optionFilter && optionFilter !== true) {\n findWhere.and.push(optionFilter)\n }\n\n if (optionFilter === false) {\n falseCollections.push(collection)\n }\n\n const result = await payload.find({\n collection,\n depth: 0,\n limit: 0,\n pagination: false,\n req,\n where: findWhere,\n })\n\n options[collection] = result.docs.map((doc) => doc.id)\n } else {\n options[collection] = []\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Error validating filter options for collection ${collection}`,\n })\n options[collection] = []\n }\n }\n\n const invalidRelationships = values.filter((val) => {\n let collection: string\n let requestedID: number | string\n\n if (typeof relationTo === 'string') {\n collection = relationTo\n\n if (typeof val === 'string' || typeof val === 'number') {\n requestedID = val\n }\n\n if (typeof val === 'object' && ObjectId.isValid(val)) {\n requestedID = new ObjectId(val).toHexString()\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collection = val.relationTo\n requestedID = val.value\n }\n\n if (falseCollections.find((slug) => relationTo === slug)) {\n return true\n }\n\n if (!options[collection]) {\n return true\n }\n\n return options[collection].indexOf(requestedID) === -1\n })\n\n if (invalidRelationships.length > 0) {\n return invalidRelationships.reduce((err, invalid, i) => {\n return `${err} ${JSON.stringify(invalid)}${\n invalidRelationships.length === i + 1 ? ',' : ''\n } `\n }, t('validation:invalidSelections')) as string\n }\n\n return true\n }\n\n return true\n}\n\nexport type UploadFieldValidation = Validate<unknown, unknown, unknown, UploadField>\n\nexport type UploadFieldManyValidation = Validate<unknown[], unknown, unknown, UploadField>\n\nexport type UploadFieldSingleValidation = Validate<unknown, unknown, unknown, UploadField>\n\nexport const upload: UploadFieldValidation = async (value, options) => {\n const {\n event,\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if (\n ((!value && typeof value !== 'number') || (Array.isArray(value) && value.length === 0)) &&\n required\n ) {\n return t('validation:required')\n }\n\n if (Array.isArray(value) && value.length > 0) {\n if (minRows && value.length < minRows) {\n return t('validation:lessThanMin', {\n label: t('general:rows'),\n min: minRows,\n value: value.length,\n })\n }\n\n if (maxRows && value.length > maxRows) {\n return t('validation:greaterThanMax', {\n label: t('general:rows'),\n max: maxRows,\n value: value.length,\n })\n }\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const values = Array.isArray(value) ? value : [value]\n\n const invalidRelationships = values.filter((val) => {\n let collectionSlug: string\n let requestedID\n\n if (typeof relationTo === 'string') {\n collectionSlug = relationTo\n\n // custom id\n if (val || typeof val === 'number') {\n requestedID = val\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collectionSlug = val.relationTo\n requestedID = val.value\n }\n\n if (requestedID === null) {\n return false\n }\n\n const idType =\n payload.collections[collectionSlug]?.customIDType || payload?.db?.defaultIDType || 'text'\n\n return !isValidID(requestedID, idType)\n })\n\n if (invalidRelationships.length > 0) {\n return `This relationship field has the following invalid relationships: ${invalidRelationships\n .map((err, invalid) => {\n return `${err} ${JSON.stringify(invalid)}`\n })\n .join(', ')}`\n }\n }\n\n if (event === 'onChange') {\n return true\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport type RelationshipFieldValidation = Validate<\n RelationshipValue,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport type RelationshipFieldManyValidation = Validate<\n RelationshipValueMany,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport type RelationshipFieldSingleValidation = Validate<\n RelationshipValueSingle,\n unknown,\n unknown,\n RelationshipField\n>\n\nexport const relationship: RelationshipFieldValidation = async (value, options) => {\n const {\n event,\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if (\n ((!value && typeof value !== 'number') || (Array.isArray(value) && value.length === 0)) &&\n required\n ) {\n return t('validation:required')\n }\n\n if (Array.isArray(value) && value.length > 0) {\n if (minRows && value.length < minRows) {\n return t('validation:lessThanMin', {\n label: t('general:rows'),\n min: minRows,\n value: value.length,\n })\n }\n\n if (maxRows && value.length > maxRows) {\n return t('validation:greaterThanMax', {\n label: t('general:rows'),\n max: maxRows,\n value: value.length,\n })\n }\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const values = Array.isArray(value) ? value : [value]\n\n const invalidRelationships = values.filter((val) => {\n let collectionSlug: string\n let requestedID\n\n if (typeof relationTo === 'string') {\n collectionSlug = relationTo\n\n // custom id\n if (val || typeof val === 'number') {\n requestedID = val\n }\n }\n\n if (Array.isArray(relationTo) && typeof val === 'object' && val?.relationTo) {\n collectionSlug = val.relationTo\n requestedID = val.value\n }\n\n if (requestedID === null) {\n return false\n }\n\n const idType =\n payload.collections[collectionSlug]?.customIDType || payload?.db?.defaultIDType || 'text'\n\n return !isValidID(requestedID, idType)\n })\n\n if (invalidRelationships.length > 0) {\n return `This relationship field has the following invalid relationships: ${invalidRelationships\n .map((err, invalid) => {\n return `${err} ${JSON.stringify(invalid)}`\n })\n .join(', ')}`\n }\n }\n\n if (event === 'onChange') {\n return true\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport type SelectFieldValidation = Validate<string | string[], unknown, unknown, SelectField>\n\nexport type SelectFieldManyValidation = Validate<string[], unknown, unknown, SelectField>\n\nexport type SelectFieldSingleValidation = Validate<string, unknown, unknown, SelectField>\n\nexport const select: SelectFieldValidation = (\n value,\n { hasMany, options, req: { t }, required },\n) => {\n if (\n Array.isArray(value) &&\n value.some(\n (input) =>\n !options.some(\n (option) => option === input || (typeof option !== 'string' && option?.value === input),\n ),\n )\n ) {\n return t('validation:invalidSelection')\n }\n\n if (\n typeof value === 'string' &&\n !options.some(\n (option) => option === value || (typeof option !== 'string' && option.value === value),\n )\n ) {\n return t('validation:invalidSelection')\n }\n\n if (\n required &&\n (typeof value === 'undefined' ||\n value === null ||\n (hasMany && Array.isArray(value) && (value as [])?.length === 0))\n ) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport type RadioFieldValidation = Validate<unknown, unknown, unknown, RadioField>\n\nexport const radio: RadioFieldValidation = (value, { options, req: { t }, required }) => {\n if (value) {\n const valueMatchesOption = options.some(\n (option) => option === value || (typeof option !== 'string' && option.value === value),\n )\n return valueMatchesOption || t('validation:invalidSelection')\n }\n\n return required ? t('validation:required') : true\n}\n\nexport type PointFieldValidation = Validate<\n [number | string, number | string],\n unknown,\n unknown,\n PointField\n>\n\nexport const point: PointFieldValidation = (value = ['', ''], { req: { t }, required }) => {\n const lng = parseFloat(String(value[0]))\n const lat = parseFloat(String(value[1]))\n if (\n required &&\n ((value[0] && value[1] && typeof lng !== 'number' && typeof lat !== 'number') ||\n Number.isNaN(lng) ||\n Number.isNaN(lat) ||\n (Array.isArray(value) && value.length !== 2))\n ) {\n return t('validation:requiresTwoNumbers')\n }\n\n if ((value[1] && Number.isNaN(lng)) || (value[0] && Number.isNaN(lat))) {\n return t('validation:invalidInput')\n }\n\n return true\n}\n\n/**\n * Built-in field validations used by Payload\n *\n * These can be re-used in custom validations\n */\nexport const validations = {\n array,\n blocks,\n checkbox,\n code,\n confirmPassword,\n date,\n email,\n json,\n number,\n password,\n point,\n radio,\n relationship,\n richText,\n select,\n text,\n textarea,\n upload,\n}\n"],"names":["Ajv","ObjectIdImport","ObjectId","default","isNumber","isValidID","text","value","hasMany","maxLength","fieldMaxLength","maxRows","minLength","minRows","req","payload","config","t","required","lengthValidationResult","validateArrayLength","defaultMaxTextLength","stringsToValidate","Array","isArray","stringValue","length","label","password","confirmPassword","siblingData","email","collectionSlug","collections","collection","find","slug","auth","loginWithUsername","requireUsername","requireEmail","username","test","textarea","code","undefined","json","jsonError","jsonSchema","isNotEmpty","Object","keys","fetchSchema","schema","uri","fetch","then","response","ok","Error","jsonSchemaSanitizations","id","$id","$schema","assign","ajv","validate","errorsText","error","message","checkbox","date","name","timezone","validDate","isNaN","Date","parse","toString","hasRequiredTimezone","selectedTimezone","validTimezone","Boolean","richText","options","editor","arrayLength","count","number","max","min","numbersToValidate","numberValue","parseFloat","array","blocks","validateFilterOptions","blockData","data","filterOptions","relationTo","user","falseCollections","values","optionFilter","valueIDs","forEach","val","push","isValid","toHexString","findWhere","and","in","result","depth","limit","pagination","where","docs","map","doc","err","logger","msg","invalidRelationships","filter","requestedID","indexOf","reduce","invalid","i","JSON","stringify","upload","event","idType","customIDType","db","defaultIDType","join","relationship","select","some","input","option","radio","valueMatchesOption","point","lng","String","lat","Number","validations"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,SAAS,MAAK;AACrB,OAAOC,oBAAoB,gBAAe;AAE1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AA4BF,SAASG,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AAQrD,OAAO,MAAMC,OAA4B,CACvCC,OACA,EACEC,OAAO,EACPC,WAAWC,cAAc,EACzBC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACnBC,CAAC,EACF,EACDC,QAAQ,EACT;IAED,IAAIT;IAEJ,IAAI,CAACS,UAAU;QACb,IAAI,CAACX,OAAO;YACV,OAAO;QACT;IACF;IAEA,IAAIC,YAAY,MAAM;QACpB,MAAMW,yBAAyBC,oBAAoBb,OAAO;YAAEI;YAASE;YAASK;YAAUD;QAAE;QAC1F,IAAI,OAAOE,2BAA2B,UAAU;YAC9C,OAAOA;QACT;IACF;IAEA,IAAI,OAAOH,QAAQK,yBAAyB,UAAU;QACpDZ,YAAYO,OAAOK,oBAAoB;IACzC;IACA,IAAI,OAAOX,mBAAmB,UAAU;QACtCD,YAAYC;IACd;IAEA,MAAMY,oBAA8BC,MAAMC,OAAO,CAACjB,SAASA,QAAQ;QAACA;KAAM;IAE1E,KAAK,MAAMkB,eAAeH,kBAAmB;QAC3C,MAAMI,SAASD,aAAaC,UAAU;QAEtC,IAAI,OAAOjB,cAAc,YAAYiB,SAASjB,WAAW;YACvD,OAAOQ,EAAE,6BAA6B;gBAAEU,OAAOV,EAAE;gBAAkBR;gBAAWgB;YAAY;QAC5F;QA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AAWA,WAAW1I,SAAU,OAAO0I,WAAW,YAAYA,OAAO1I,KAAK,KAAKA;QAElF,OAAO4I,sBAAsBlI,EAAE;IACjC;IAEA,OAAOC,WAAWD,EAAE,yBAAyB;AAC/C,EAAC;AASD,OAAO,MAAMmI,QAA8B,CAAC7I,QAAQ;IAAC;IAAI;CAAG,EAAE,EAAEO,KAAK,EAAEG,CAAC,EAAE,EAAEC,QAAQ,EAAE;IACpF,MAAMmI,MAAMxD,WAAWyD,OAAO/I,KAAK,CAAC,EAAE;IACtC,MAAMgJ,MAAM1D,WAAWyD,OAAO/I,KAAK,CAAC,EAAE;IACtC,IACEW,YACC,CAAA,AAACX,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,IAAI,OAAO8I,QAAQ,YAAY,OAAOE,QAAQ,YAClEC,OAAO7E,KAAK,CAAC0E,QACbG,OAAO7E,KAAK,CAAC4E,QACZhI,MAAMC,OAAO,CAACjB,UAAUA,MAAMmB,MAAM,KAAK,CAAC,GAC7C;QACA,OAAOT,EAAE;IACX;IAEA,IAAI,AAACV,KAAK,CAAC,EAAE,IAAIiJ,OAAO7E,KAAK,CAAC0E,QAAU9I,KAAK,CAAC,EAAE,IAAIiJ,OAAO7E,KAAK,CAAC4E,MAAO;QACtE,OAAOtI,EAAE;IACX;IAEA,OAAO;AACT,EAAC;AAED;;;;CAIC,GACD,OAAO,MAAMwI,cAAc;IACzB3D;IACAC;IACAzB;IACA1B;IACAf;IACA0C;IACAxC;IACAe;IACA0C;IACA5D;IACAwH;IACAF;IACAL;IACA1D;IACA2D;IACAxI;IACAqC;IACA2F;AACF,EAAC"}
@@ -2,16 +2,46 @@ import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../
2
2
  import type { Document, PayloadRequest, Where } from '../../../types/index.js';
3
3
  export type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {
4
4
  /**
5
- * context, which will then be passed to req.context, which can be read by hooks
5
+ * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,
6
+ * which can be read by hooks. Useful if you want to pass additional information to the hooks which
7
+ * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook
8
+ * to determine if it should run or not.
6
9
  */
7
10
  context?: RequestContext;
11
+ /**
12
+ * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
13
+ */
8
14
  depth?: number;
15
+ /**
16
+ * When set to `true`, errors will not be thrown.
17
+ */
9
18
  disableErrors?: boolean;
19
+ /**
20
+ * the Global slug to operate against.
21
+ */
10
22
  global: TSlug;
23
+ /**
24
+ * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.
25
+ */
11
26
  locale?: TypedLocale;
27
+ /**
28
+ * Skip access control.
29
+ * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
30
+ * @default true
31
+ */
12
32
  overrideAccess?: boolean;
33
+ /**
34
+ * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.
35
+ * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.
36
+ */
13
37
  req?: Partial<PayloadRequest>;
38
+ /**
39
+ * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
40
+ */
14
41
  user?: Document;
42
+ /**
43
+ * A filter [query](https://payloadcms.com/docs/queries/overview)
44
+ */
15
45
  where?: Where;
16
46
  };
17
47
  export default function countGlobalVersionsLocal<TSlug extends GlobalSlug>(payload: Payload, options: CountGlobalVersionsOptions<TSlug>): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAM9E,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,UAAU,IAAI;IACjE;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,KAAK,CAAA;IACb,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAGD,wBAA8B,wBAAwB,CAAC,KAAK,SAAS,UAAU,EAC7E,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,CAAC,KAAK,CAAC,GACzC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBhC"}
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAM9E,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,UAAU,IAAI;IACjE;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,MAAM,EAAE,KAAK,CAAA;IACb;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAGD,wBAA8B,wBAAwB,CAAC,KAAK,SAAS,UAAU,EAC7E,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,CAAC,KAAK,CAAC,GACzC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBhC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/globals/operations/local/countGlobalVersions.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countGlobalVersionsOperation } from '../countGlobalVersions.js'\n\nexport type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n depth?: number\n disableErrors?: boolean\n global: TSlug\n locale?: TypedLocale\n overrideAccess?: boolean\n req?: Partial<PayloadRequest>\n user?: Document\n where?: Where\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default async function countGlobalVersionsLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: CountGlobalVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n const { disableErrors, global: globalSlug, overrideAccess = true, where } = options\n\n const global = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n if (!global) {\n throw new APIError(\n `The global with slug ${String(globalSlug)} can't be found. Count Global Versions Operation.`,\n )\n }\n\n return countGlobalVersionsOperation<TSlug>({\n disableErrors,\n global,\n overrideAccess,\n req: await createLocalReq(options, payload),\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countGlobalVersionsOperation","countGlobalVersionsLocal","payload","options","disableErrors","global","globalSlug","overrideAccess","where","globals","config","find","slug","String","req"],"mappings":"AAAA,oBAAoB;AAIpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,4BAA4B,QAAQ,4BAA2B;AAiBxE,iDAAiD;AACjD,eAAe,eAAeC,yBAC5BC,OAAgB,EAChBC,OAA0C;IAE1C,MAAM,EAAEC,aAAa,EAAEC,QAAQC,UAAU,EAAEC,iBAAiB,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAE5E,MAAME,SAASH,QAAQO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASN;IAElE,IAAI,CAACD,QAAQ;QACX,MAAM,IAAIP,SACR,CAAC,qBAAqB,EAAEe,OAAOP,YAAY,iDAAiD,CAAC;IAEjG;IAEA,OAAON,6BAAoC;QACzCI;QACAC;QACAE;QACAO,KAAK,MAAMf,eAAeI,SAASD;QACnCM;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/globals/operations/local/countGlobalVersions.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countGlobalVersionsOperation } from '../countGlobalVersions.js'\n\nexport type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, errors will not be thrown.\n */\n disableErrors?: boolean\n /**\n * the Global slug to operate against.\n */\n global: TSlug\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n /**\n * A filter [query](https://payloadcms.com/docs/queries/overview)\n */\n where?: Where\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default async function countGlobalVersionsLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: CountGlobalVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n const { disableErrors, global: globalSlug, overrideAccess = true, where } = options\n\n const global = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n if (!global) {\n throw new APIError(\n `The global with slug ${String(globalSlug)} can't be found. Count Global Versions Operation.`,\n )\n }\n\n return countGlobalVersionsOperation<TSlug>({\n disableErrors,\n global,\n overrideAccess,\n req: await createLocalReq(options, payload),\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countGlobalVersionsOperation","countGlobalVersionsLocal","payload","options","disableErrors","global","globalSlug","overrideAccess","where","globals","config","find","slug","String","req"],"mappings":"AAAA,oBAAoB;AAIpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,4BAA4B,QAAQ,4BAA2B;AA+CxE,iDAAiD;AACjD,eAAe,eAAeC,yBAC5BC,OAAgB,EAChBC,OAA0C;IAE1C,MAAM,EAAEC,aAAa,EAAEC,QAAQC,UAAU,EAAEC,iBAAiB,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAE5E,MAAME,SAASH,QAAQO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASN;IAElE,IAAI,CAACD,QAAQ;QACX,MAAM,IAAIP,SACR,CAAC,qBAAqB,EAAEe,OAAOP,YAAY,iDAAiD,CAAC;IAEjG;IAEA,OAAON,6BAAoC;QACzCI;QACAC;QACAE;QACAO,KAAK,MAAMf,eAAeI,SAASD;QACnCM;IACF;AACF"}
@@ -2,18 +2,64 @@ import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../
2
2
  import type { Document, PayloadRequest, PopulateType, SelectType, TransformGlobalWithSelect } from '../../../types/index.js';
3
3
  import type { SelectFromGlobalSlug } from '../../config/types.js';
4
4
  export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
5
+ /**
6
+ * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,
7
+ * which can be read by hooks. Useful if you want to pass additional information to the hooks which
8
+ * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook
9
+ * to determine if it should run or not.
10
+ */
5
11
  context?: RequestContext;
12
+ /**
13
+ * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
14
+ */
6
15
  depth?: number;
16
+ /**
17
+ * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)
18
+ */
7
19
  draft?: boolean;
20
+ /**
21
+ * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.
22
+ */
8
23
  fallbackLocale?: false | TypedLocale;
24
+ /**
25
+ * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`
26
+ */
9
27
  includeLockStatus?: boolean;
28
+ /**
29
+ * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.
30
+ */
10
31
  locale?: 'all' | TypedLocale;
32
+ /**
33
+ * Skip access control.
34
+ * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
35
+ * @default true
36
+ */
11
37
  overrideAccess?: boolean;
38
+ /**
39
+ * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.
40
+ */
12
41
  populate?: PopulateType;
42
+ /**
43
+ * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.
44
+ * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.
45
+ */
13
46
  req?: Partial<PayloadRequest>;
47
+ /**
48
+ * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.
49
+ */
14
50
  select?: TSelect;
51
+ /**
52
+ * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.
53
+ * @default false
54
+ */
15
55
  showHiddenFields?: boolean;
56
+ /**
57
+ * the Global slug to operate against.
58
+ */
16
59
  slug: TSlug;
60
+ /**
61
+ * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
62
+ */
17
63
  user?: Document;
18
64
  };
19
65
  export default function findOneLocal<TSlug extends GlobalSlug, TSelect extends SelectFromGlobalSlug<TSlug>>(payload: Payload, options: Options<TSlug, TSelect>): Promise<TransformGlobalWithSelect<TSlug, TSelect>>;
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,yBAAyB,EAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAMjE,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,UAAU,EAAE,OAAO,SAAS,UAAU,IAAI;IAC1E,OAAO,CAAC,EAAE,cAAc,C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AAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IACX;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,wBAA8B,YAAY,CACxC,KAAK,SAAS,UAAU,EACxB,OAAO,SAAS,oBAAoB,CAAC,KAAK,CAAC,EAE3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CA8BpD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/globals/operations/local/findOne.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformGlobalWithSelect,\n} from '../../../types/index.js'\nimport type { SelectFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findOneOperation } from '../findOne.js'\n\nexport type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {\n context?: RequestContext\n depth?: number\n draft?: boolean\n fallbackLocale?: false | TypedLocale\n includeLockStatus?: boolean\n locale?: 'all' | TypedLocale\n overrideAccess?: boolean\n populate?: PopulateType\n req?: Partial<PayloadRequest>\n select?: TSelect\n showHiddenFields?: boolean\n slug: TSlug\n user?: Document\n}\n\nexport default async function findOneLocal<\n TSlug extends GlobalSlug,\n TSelect extends SelectFromGlobalSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<TransformGlobalWithSelect<TSlug, TSelect>> {\n const {\n slug: globalSlug,\n depth,\n draft = false,\n includeLockStatus,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findOneOperation({\n slug: globalSlug as string,\n depth,\n draft,\n globalConfig,\n includeLockStatus,\n overrideAccess,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","findOneOperation","findOneLocal","payload","options","slug","globalSlug","depth","draft","includeLockStatus","overrideAccess","populate","select","showHiddenFields","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AAWpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,gBAAgB,QAAQ,gBAAe;AAkBhD,eAAe,eAAeC,aAI5BC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,MAAMC,UAAU,EAChBC,KAAK,EACLC,QAAQ,KAAK,EACbC,iBAAiB,EACjBC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGT;IAEJ,MAAMU,eAAeX,QAAQY,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOX,IAAI,KAAKC;IAE7E,IAAI,CAACQ,cAAc;QACjB,MAAM,IAAIf,SAAS,CAAC,qBAAqB,EAAEmB,OAAOZ,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,iBAAiB;QACtBI,MAAMC;QACNC;QACAC;QACAM;QACAL;QACAC;QACAC;QACAQ,KAAK,MAAMnB,eAAeI,SAASD;QACnCS;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/globals/operations/local/findOne.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformGlobalWithSelect,\n} from '../../../types/index.js'\nimport type { SelectFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findOneOperation } from '../findOne.js'\n\nexport type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * Whether the document should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * Include info about the lock status to the result with fields: `_isLocked` and `_userEditing`\n */\n includeLockStatus?: boolean\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * the Global slug to operate against.\n */\n slug: TSlug\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}\n\nexport default async function findOneLocal<\n TSlug extends GlobalSlug,\n TSelect extends SelectFromGlobalSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<TransformGlobalWithSelect<TSlug, TSelect>> {\n const {\n slug: globalSlug,\n depth,\n draft = false,\n includeLockStatus,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findOneOperation({\n slug: globalSlug as string,\n depth,\n draft,\n globalConfig,\n includeLockStatus,\n overrideAccess,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","findOneOperation","findOneLocal","payload","options","slug","globalSlug","depth","draft","includeLockStatus","overrideAccess","populate","select","showHiddenFields","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AAWpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,gBAAgB,QAAQ,gBAAe;AAgEhD,eAAe,eAAeC,aAI5BC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,MAAMC,UAAU,EAChBC,KAAK,EACLC,QAAQ,KAAK,EACbC,iBAAiB,EACjBC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGT;IAEJ,MAAMU,eAAeX,QAAQY,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOX,IAAI,KAAKC;IAE7E,IAAI,CAACQ,cAAc;QACjB,MAAM,IAAIf,SAAS,CAAC,qBAAqB,EAAEmB,OAAOZ,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,iBAAiB;QACtBI,MAAMC;QACNC;QACAC;QACAM;QACAL;QACAC;QACAC;QACAQ,KAAK,MAAMnB,eAAeI,SAASD;QACnCS;QACAC;IACF;AACF"}
@@ -3,18 +3,65 @@ import type { Document, PayloadRequest, PopulateType, SelectType } from '../../.
3
3
  import type { TypeWithVersion } from '../../../versions/types.js';
4
4
  import type { DataFromGlobalSlug } from '../../config/types.js';
5
5
  export type Options<TSlug extends GlobalSlug> = {
6
+ /**
7
+ * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,
8
+ * which can be read by hooks. Useful if you want to pass additional information to the hooks which
9
+ * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook
10
+ * to determine if it should run or not.
11
+ */
6
12
  context?: RequestContext;
13
+ /**
14
+ * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
15
+ */
7
16
  depth?: number;
17
+ /**
18
+ * When set to `true`, errors will not be thrown.
19
+ * `null` will be returned instead, if the document on this ID was not found.
20
+ */
8
21
  disableErrors?: boolean;
22
+ /**
23
+ * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.
24
+ */
9
25
  fallbackLocale?: false | TypedLocale;
26
+ /**
27
+ * The ID of the version to find.
28
+ */
10
29
  id: string;
30
+ /**
31
+ * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.
32
+ */
11
33
  locale?: 'all' | TypedLocale;
34
+ /**
35
+ * Skip access control.
36
+ * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
37
+ * @default true
38
+ */
12
39
  overrideAccess?: boolean;
40
+ /**
41
+ * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.
42
+ */
13
43
  populate?: PopulateType;
44
+ /**
45
+ * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.
46
+ * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.
47
+ */
14
48
  req?: Partial<PayloadRequest>;
49
+ /**
50
+ * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.
51
+ */
15
52
  select?: SelectType;
53
+ /**
54
+ * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.
55
+ * @default false
56
+ */
16
57
  showHiddenFields?: boolean;
58
+ /**
59
+ * the Global slug to operate against.
60
+ */
17
61
  slug: TSlug;
62
+ /**
63
+ * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
64
+ */
18
65
  user?: Document;
19
66
  };
20
67
  export default function findVersionByIDLocal<TSlug extends GlobalSlug>(payload: Payload, options: Options<TSlug>): Promise<TypeWithVersion<DataFromGlobalSlug<TSlug>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/findVersionByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAM/D,MAAM,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,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAA;IACX;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AAGD,wBAA8B,oBAAoB,CAAC,KAAK,SAAS,UAAU,EACzE,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GACtB,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CA6BrD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/globals/operations/local/findVersionByID.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\nimport type { TypeWithVersion } from '../../../versions/types.js'\nimport type { DataFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findVersionByIDOperation } from '../findVersionByID.js'\n\nexport type Options<TSlug extends GlobalSlug> = {\n context?: RequestContext\n depth?: number\n disableErrors?: boolean\n fallbackLocale?: false | TypedLocale\n id: string\n locale?: 'all' | TypedLocale\n overrideAccess?: boolean\n populate?: PopulateType\n req?: Partial<PayloadRequest>\n select?: SelectType\n showHiddenFields?: boolean\n slug: TSlug\n user?: Document\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default async function findVersionByIDLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<TypeWithVersion<DataFromGlobalSlug<TSlug>>> {\n const {\n id,\n slug: globalSlug,\n depth,\n disableErrors = false,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findVersionByIDOperation({\n id,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","findVersionByIDOperation","findVersionByIDLocal","payload","options","id","slug","globalSlug","depth","disableErrors","overrideAccess","populate","select","showHiddenFields","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AAMpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,wBAAwB,QAAQ,wBAAuB;AAkBhE,iDAAiD;AACjD,eAAe,eAAeC,qBAC5BC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EACJC,EAAE,EACFC,MAAMC,UAAU,EAChBC,KAAK,EACLC,gBAAgB,KAAK,EACrBC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGT;IAEJ,MAAMU,eAAeX,QAAQY,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOV,IAAI,KAAKC;IAE7E,IAAI,CAACO,cAAc;QACjB,MAAM,IAAIf,SAAS,CAAC,qBAAqB,EAAEmB,OAAOX,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAON,yBAAyB;QAC9BI;QACAG;QACAC;QACAK;QACAJ;QACAC;QACAQ,KAAK,MAAMnB,eAAeI,SAASD;QACnCS;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/globals/operations/local/findVersionByID.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\nimport type { TypeWithVersion } from '../../../versions/types.js'\nimport type { DataFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findVersionByIDOperation } from '../findVersionByID.js'\n\nexport type Options<TSlug extends GlobalSlug> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, errors will not be thrown.\n * `null` will be returned instead, if the document on this ID was not found.\n */\n disableErrors?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The ID of the version to find.\n */\n id: string\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: SelectType\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * the Global slug to operate against.\n */\n slug: TSlug\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default async function findVersionByIDLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<TypeWithVersion<DataFromGlobalSlug<TSlug>>> {\n const {\n id,\n slug: globalSlug,\n depth,\n disableErrors = false,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findVersionByIDOperation({\n id,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","findVersionByIDOperation","findVersionByIDLocal","payload","options","id","slug","globalSlug","depth","disableErrors","overrideAccess","populate","select","showHiddenFields","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AAMpB,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,wBAAwB,QAAQ,wBAAuB;AAiEhE,iDAAiD;AACjD,eAAe,eAAeC,qBAC5BC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EACJC,EAAE,EACFC,MAAMC,UAAU,EAChBC,KAAK,EACLC,gBAAgB,KAAK,EACrBC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGT;IAEJ,MAAMU,eAAeX,QAAQY,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOV,IAAI,KAAKC;IAE7E,IAAI,CAACO,cAAc;QACjB,MAAM,IAAIf,SAAS,CAAC,qBAAqB,EAAEmB,OAAOX,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAON,yBAAyB;QAC9BI;QACAG;QACAC;QACAK;QACAJ;QACAC;QACAQ,KAAK,MAAMnB,eAAeI,SAASD;QACnCS;QACAC;IACF;AACF"}
@@ -4,20 +4,77 @@ import type { Document, PayloadRequest, PopulateType, SelectType, Sort, Where }
4
4
  import type { TypeWithVersion } from '../../../versions/types.js';
5
5
  import type { DataFromGlobalSlug } from '../../config/types.js';
6
6
  export type Options<TSlug extends GlobalSlug> = {
7
+ /**
8
+ * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,
9
+ * which can be read by hooks. Useful if you want to pass additional information to the hooks which
10
+ * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook
11
+ * to determine if it should run or not.
12
+ */
7
13
  context?: RequestContext;
14
+ /**
15
+ * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
16
+ */
8
17
  depth?: number;
18
+ /**
19
+ * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.
20
+ */
9
21
  fallbackLocale?: false | TypedLocale;
22
+ /**
23
+ * The maximum related documents to be returned.
24
+ * Defaults unless `defaultLimit` is specified for the collection config
25
+ * @default 10
26
+ */
10
27
  limit?: number;
28
+ /**
29
+ * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.
30
+ */
11
31
  locale?: 'all' | TypedLocale;
32
+ /**
33
+ * Skip access control.
34
+ * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.
35
+ * @default true
36
+ */
12
37
  overrideAccess?: boolean;
38
+ /**
39
+ * Get a specific page number
40
+ * @default 1
41
+ */
13
42
  page?: number;
43
+ /**
44
+ * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.
45
+ */
14
46
  populate?: PopulateType;
47
+ /**
48
+ * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.
49
+ * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.
50
+ */
15
51
  req?: Partial<PayloadRequest>;
52
+ /**
53
+ * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.
54
+ */
16
55
  select?: SelectType;
56
+ /**
57
+ * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.
58
+ * @default false
59
+ */
17
60
  showHiddenFields?: boolean;
61
+ /**
62
+ * the Global slug to operate against.
63
+ */
18
64
  slug: TSlug;
65
+ /**
66
+ * Sort the documents, can be a string or an array of strings
67
+ * @example '-version.createdAt' // Sort DESC by createdAt
68
+ * @example ['version.group', '-version.createdAt'] // sort by 2 fields, ASC group and DESC createdAt
69
+ */
19
70
  sort?: Sort;
71
+ /**
72
+ * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
73
+ */
20
74
  user?: Document;
75
+ /**
76
+ * A filter [query](https://payloadcms.com/docs/queries/overview)
77
+ */
21
78
  where?: Where;
22
79
  };
23
80
  export default function findVersionsLocal<TSlug extends GlobalSlug>(payload: Payload, options: Options<TSlug>): Promise<PaginatedDocs<TypeWithVersion<DataFromGlobalSlug<TSlug>>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/findVersions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,KAAK,EACN,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAM/D,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,UAAU,IAAI;IAC9C,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAA8B,iBAAiB,CAAC,KAAK,SAAS,UAAU,EACtE,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GACtB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAiCpE"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/findVersions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,O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AC,GACtB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAiCpE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/globals/operations/local/findVersions.ts"],"sourcesContent":["// @ts-strict-ignore\n/* eslint-disable no-restricted-exports */\nimport type { PaginatedDocs } from '../../../database/types.js'\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n Sort,\n Where,\n} from '../../../types/index.js'\nimport type { TypeWithVersion } from '../../../versions/types.js'\nimport type { DataFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findVersionsOperation } from '../findVersions.js'\n\nexport type Options<TSlug extends GlobalSlug> = {\n context?: RequestContext\n depth?: number\n fallbackLocale?: false | TypedLocale\n limit?: number\n locale?: 'all' | TypedLocale\n overrideAccess?: boolean\n page?: number\n populate?: PopulateType\n req?: Partial<PayloadRequest>\n select?: SelectType\n showHiddenFields?: boolean\n slug: TSlug\n sort?: Sort\n user?: Document\n where?: Where\n}\n\nexport default async function findVersionsLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<PaginatedDocs<TypeWithVersion<DataFromGlobalSlug<TSlug>>>> {\n const {\n slug: globalSlug,\n depth,\n limit,\n overrideAccess = true,\n page,\n populate,\n select,\n showHiddenFields,\n sort,\n where,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findVersionsOperation({\n depth,\n globalConfig,\n limit,\n overrideAccess,\n page,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n sort,\n where,\n })\n}\n"],"names":["APIError","createLocalReq","findVersionsOperation","findVersionsLocal","payload","options","slug","globalSlug","depth","limit","overrideAccess","page","populate","select","showHiddenFields","sort","where","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AACpB,wCAAwC,GAcxC,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,qBAAqB,QAAQ,qBAAoB;AAoB1D,eAAe,eAAeC,kBAC5BC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EACJC,MAAMC,UAAU,EAChBC,KAAK,EACLC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACN,GAAGX;IAEJ,MAAMY,eAAeb,QAAQc,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOb,IAAI,KAAKC;IAE7E,IAAI,CAACU,cAAc;QACjB,MAAM,IAAIjB,SAAS,CAAC,qBAAqB,EAAEqB,OAAOd,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,sBAAsB;QAC3BM;QACAS;QACAR;QACAC;QACAC;QACAC;QACAU,KAAK,MAAMrB,eAAeI,SAASD;QACnCS;QACAC;QACAC;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/globals/operations/local/findVersions.ts"],"sourcesContent":["// @ts-strict-ignore\n/* eslint-disable no-restricted-exports */\nimport type { PaginatedDocs } from '../../../database/types.js'\nimport type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n Sort,\n Where,\n} from '../../../types/index.js'\nimport type { TypeWithVersion } from '../../../versions/types.js'\nimport type { DataFromGlobalSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findVersionsOperation } from '../findVersions.js'\n\nexport type Options<TSlug extends GlobalSlug> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The maximum related documents to be returned.\n * Defaults unless `defaultLimit` is specified for the collection config\n * @default 10\n */\n limit?: number\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: 'all' | TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the fron-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Get a specific page number\n * @default 1\n */\n page?: number\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: SelectType\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * the Global slug to operate against.\n */\n slug: TSlug\n /**\n * Sort the documents, can be a string or an array of strings\n * @example '-version.createdAt' // Sort DESC by createdAt\n * @example ['version.group', '-version.createdAt'] // sort by 2 fields, ASC group and DESC createdAt\n */\n sort?: Sort\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n /**\n * A filter [query](https://payloadcms.com/docs/queries/overview)\n */\n where?: Where\n}\n\nexport default async function findVersionsLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<PaginatedDocs<TypeWithVersion<DataFromGlobalSlug<TSlug>>>> {\n const {\n slug: globalSlug,\n depth,\n limit,\n overrideAccess = true,\n page,\n populate,\n select,\n showHiddenFields,\n sort,\n where,\n } = options\n\n const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)\n\n if (!globalConfig) {\n throw new APIError(`The global with slug ${String(globalSlug)} can't be found.`)\n }\n\n return findVersionsOperation({\n depth,\n globalConfig,\n limit,\n overrideAccess,\n page,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n sort,\n where,\n })\n}\n"],"names":["APIError","createLocalReq","findVersionsOperation","findVersionsLocal","payload","options","slug","globalSlug","depth","limit","overrideAccess","page","populate","select","showHiddenFields","sort","where","globalConfig","globals","config","find","String","req"],"mappings":"AAAA,oBAAoB;AACpB,wCAAwC,GAcxC,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,qBAAqB,QAAQ,qBAAoB;AA6E1D,eAAe,eAAeC,kBAC5BC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EACJC,MAAMC,UAAU,EAChBC,KAAK,EACLC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACN,GAAGX;IAEJ,MAAMY,eAAeb,QAAQc,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOb,IAAI,KAAKC;IAE7E,IAAI,CAACU,cAAc;QACjB,MAAM,IAAIjB,SAAS,CAAC,qBAAqB,EAAEqB,OAAOd,YAAY,gBAAgB,CAAC;IACjF;IAEA,OAAOL,sBAAsB;QAC3BM;QACAS;QACAR;QACAC;QACAC;QACAC;QACAU,KAAK,MAAMrB,eAAeI,SAASD;QACnCS;QACAC;QACAC;QACAC;IACF;AACF"}