payload 3.0.0-beta.20 → 3.0.0-beta.21

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 (63) hide show
  1. package/dist/admin/RichText.d.ts +3 -0
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/types.d.ts +1 -1
  5. package/dist/admin/types.d.ts.map +1 -1
  6. package/dist/admin/types.js.map +1 -1
  7. package/dist/auth/getAccessResults.js +1 -1
  8. package/dist/auth/getAccessResults.js.map +1 -1
  9. package/dist/bin/loader/index.d.ts.map +1 -1
  10. package/dist/bin/loader/index.js +2 -1
  11. package/dist/bin/loader/index.js.map +1 -1
  12. package/dist/bin/loader/resolveOriginalPath.d.ts +10 -0
  13. package/dist/bin/loader/resolveOriginalPath.d.ts.map +1 -0
  14. package/dist/bin/loader/resolveOriginalPath.js +32 -0
  15. package/dist/bin/loader/resolveOriginalPath.js.map +1 -0
  16. package/dist/collections/config/sanitize.d.ts +2 -2
  17. package/dist/collections/config/sanitize.d.ts.map +1 -1
  18. package/dist/collections/config/sanitize.js +6 -2
  19. package/dist/collections/config/sanitize.js.map +1 -1
  20. package/dist/config/build.d.ts.map +1 -1
  21. package/dist/config/build.js +3 -4
  22. package/dist/config/build.js.map +1 -1
  23. package/dist/config/sanitize.d.ts +1 -1
  24. package/dist/config/sanitize.d.ts.map +1 -1
  25. package/dist/config/sanitize.js +20 -5
  26. package/dist/config/sanitize.js.map +1 -1
  27. package/dist/config/types.d.ts +5 -2
  28. package/dist/config/types.d.ts.map +1 -1
  29. package/dist/config/types.js.map +1 -1
  30. package/dist/exports/i18n.d.ts +2 -0
  31. package/dist/exports/i18n.d.ts.map +1 -0
  32. package/dist/exports/i18n.js +3 -0
  33. package/dist/exports/i18n.js.map +1 -0
  34. package/dist/fields/config/client.d.ts +1 -1
  35. package/dist/fields/config/sanitize.d.ts +7 -2
  36. package/dist/fields/config/sanitize.d.ts.map +1 -1
  37. package/dist/fields/config/sanitize.js +55 -44
  38. package/dist/fields/config/sanitize.js.map +1 -1
  39. package/dist/fields/config/sanitize.spec.js +76 -85
  40. package/dist/fields/config/sanitize.spec.js.map +1 -1
  41. package/dist/fields/config/types.d.ts +4 -3
  42. package/dist/fields/config/types.d.ts.map +1 -1
  43. package/dist/fields/config/types.js.map +1 -1
  44. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  45. package/dist/fields/hooks/afterRead/promise.js +3 -0
  46. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  47. package/dist/fields/validations.d.ts.map +1 -1
  48. package/dist/fields/validations.js +3 -0
  49. package/dist/fields/validations.js.map +1 -1
  50. package/dist/globals/config/sanitize.d.ts +2 -3
  51. package/dist/globals/config/sanitize.d.ts.map +1 -1
  52. package/dist/globals/config/sanitize.js +36 -35
  53. package/dist/globals/config/sanitize.js.map +1 -1
  54. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  55. package/dist/utilities/configToJSONSchema.js +3 -0
  56. package/dist/utilities/configToJSONSchema.js.map +1 -1
  57. package/dist/utilities/configToJSONSchema.spec.js +2 -2
  58. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  59. package/dist/utilities/createLocalReq.js +1 -1
  60. package/dist/utilities/createLocalReq.js.map +1 -1
  61. package/dist/utilities/importWithoutClientFiles.js +1 -1
  62. package/dist/utilities/importWithoutClientFiles.js.map +1 -1
  63. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-use-before-define */\nimport type { EditorProps } from '@monaco-editor/react'\nimport type { CSSProperties } from 'react'\n\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport monacoeditor from 'monaco-editor' // IMPORTANT - DO NOT REMOVE: This is required for pnpm's default isolated mode to work - even though the import is not used. This is due to a typescript bug: https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189. (tsbugisolatedmode)\nimport type React from 'react'\n\nimport type {\n ConditionalDateProps,\n Description,\n ErrorProps,\n LabelProps,\n RichTextAdapter,\n RowLabel,\n} from '../../admin/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../../collections/config/types.js'\nimport type { CustomComponent, LabelFunction } from '../../config/types.js'\nimport type { DBIdentifierName } from '../../database/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { Operation, PayloadRequestWithData, RequestContext, Where } from '../../types/index.js'\nimport type { ClientFieldConfig } from './client.js'\n\nexport type FieldHookArgs<T extends TypeWithID = any, P = any, S = any> = {\n /** The collection which the field belongs to. If the field belongs to a global, this will be null. */\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n /** The data passed to update the document within create and update operations, and the full document itself in the afterRead hook. */\n data?: Partial<T>\n /** The field which the hook is running against. */\n field: FieldAffectingData\n /** Boolean to denote if this hook is running against finding one, or finding many within the afterRead hook. */\n findMany?: boolean\n /** The global which the field belongs to. If the field belongs to a collection, this will be null. */\n global: SanitizedGlobalConfig | null\n /** A string relating to which operation the field type is currently executing within. Useful within beforeValidate, beforeChange, and afterChange hooks to differentiate between create and update operations. */\n operation?: 'create' | 'delete' | 'read' | 'update'\n /** The full original document in `update` operations. In the `afterChange` hook, this is the resulting document of the operation. */\n originalDoc?: T\n overrideAccess?: boolean\n /** The document before changes were applied, only in `afterChange` hooks. */\n previousDoc?: T\n /** The sibling data of the document before changes being applied, only in `beforeChange` and `afterChange` hook. */\n previousSiblingDoc?: T\n /** The previous value of the field, before changes, only in `beforeChange`, `afterChange` and `beforeValidate` hooks. */\n previousValue?: P\n /** The Express request object. It is mocked for Local API operations. */\n req: PayloadRequestWithData\n /** The sibling data passed to a field that the hook is running against. */\n siblingData: Partial<S>\n /** The value of the field. */\n value?: P\n}\n\nexport type FieldHook<T extends TypeWithID = any, P = any, S = any> = (\n args: FieldHookArgs<T, P, S>,\n) => P | Promise<P>\n\nexport type FieldAccess<T extends TypeWithID = any, P = any, U = any> = (args: {\n /**\n * The incoming data used to `create` or `update` the document with. `data` is undefined during the `read` operation.\n */\n data?: Partial<T>\n /**\n * The original data of the document before the `update` is applied. `doc` is undefined during the `create` operation.\n */\n doc?: T\n /**\n * The `id` of the current document being read or updated. `id` is undefined during the `create` operation.\n */\n id?: number | string\n /** The `payload` object to interface with the payload API */\n req: PayloadRequestWithData<U>\n /**\n * Immediately adjacent data to this field. For example, if this is a `group` field, then `siblingData` will be the other fields within the group.\n */\n siblingData?: Partial<P>\n}) => Promise<boolean> | boolean\n\nexport type Condition<T extends TypeWithID = any, P = any> = (\n data: Partial<T>,\n siblingData: Partial<P>,\n { user }: { user: PayloadRequestWithData['user'] },\n) => boolean\n\nexport type FilterOptionsProps<T = any> = {\n /**\n * An object containing the full collection or global document currently being edited.\n */\n data: T\n /**\n * The `id` of the current document being edited. `id` is undefined during the `create` operation.\n */\n id: number | string\n /**\n * The collection `slug` to filter against, limited to this field's `relationTo` property.\n */\n relationTo: string\n /**\n * An object containing document data that is scoped to only fields within the same parent of this field.\n */\n siblingData: unknown\n /**\n * An object containing the currently authenticated user.\n */\n user: Partial<PayloadRequestWithData['user']>\n}\n\nexport type FilterOptions<T = any> =\n | ((options: FilterOptionsProps<T>) => Promise<Where | boolean> | Where | boolean)\n | Where\n | null\n\ntype Admin = {\n className?: string\n components?: {\n Cell?: CustomComponent\n Field?: CustomComponent\n Filter?: React.ComponentType<any>\n }\n /**\n * You can programmatically show / hide fields based on what other fields are doing.\n * This is also run on the server, to determine if the field should be validated.\n */\n condition?: Condition\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n description?: Description\n disableBulkEdit?: boolean\n disabled?: boolean\n hidden?: boolean\n position?: 'sidebar'\n readOnly?: boolean\n style?: CSSProperties\n width?: string\n}\n\nexport type Labels = {\n plural: LabelFunction | Record<string, string> | string\n singular: LabelFunction | Record<string, string> | string\n}\n\nexport type BaseValidateOptions<TData, TSiblingData> = {\n data: Partial<TData>\n id?: number | string\n operation?: Operation\n preferences: DocumentPreferences\n req: PayloadRequestWithData\n siblingData: Partial<TSiblingData>\n}\n\nexport type ValidateOptions<TData, TSiblingData, TFieldConfig extends object> = BaseValidateOptions<\n TData,\n TSiblingData\n> &\n TFieldConfig\n\nexport type Validate<\n TValue = any,\n TData = any,\n TSiblingData = any,\n TFieldConfig extends object = object,\n> = (\n value: TValue,\n options: ValidateOptions<TData, TSiblingData, TFieldConfig>,\n) => Promise<string | true> | string | true\n\nexport type ClientValidate = Omit<Validate, 'req'>\n\nexport type OptionObject = {\n label: LabelFunction | Record<string, string> | string\n value: string\n}\n\nexport type Option = OptionObject | string\n\nexport interface FieldBase {\n access?: {\n create?: FieldAccess\n read?: FieldAccess\n update?: FieldAccess\n }\n admin?: Admin\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n defaultValue?: any\n hidden?: boolean\n hooks?: {\n afterChange?: FieldHook[]\n afterRead?: FieldHook[]\n beforeChange?: FieldHook[]\n /**\n * Runs before a document is duplicated to prevent errors in unique fields or return null to use defaultValue.\n */\n beforeDuplicate?: FieldHook[]\n beforeValidate?: FieldHook[]\n }\n index?: boolean\n label?: LabelFunction | Record<string, string> | false | string\n localized?: boolean\n name: string\n required?: boolean\n saveToJWT?: boolean | string\n unique?: boolean\n validate?: Validate\n}\n\nexport type NumberField = FieldBase & {\n admin?: Admin & {\n /** Set this property to a string that will be used for browser autocomplete. */\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n /** Set this property to define a placeholder string for the field. */\n placeholder?: Record<string, string> | string\n /** Set a value for the number field to increment / decrement using browser controls. */\n step?: number\n }\n /** Maximum value accepted. Used in the default `validation` function. */\n max?: number\n /** Minimum value accepted. Used in the default `validation` function. */\n min?: number\n type: 'number'\n} & (\n | {\n /** Makes this field an ordered array of numbers instead of just a single number. */\n hasMany: true\n /** Maximum number of numbers in the numbers array, if `hasMany` is set to true. */\n maxRows?: number\n /** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */\n minRows?: number\n }\n | {\n /** Makes this field an ordered array of numbers instead of just a single number. */\n hasMany?: false | undefined\n /** Maximum number of numbers in the numbers array, if `hasMany` is set to true. */\n maxRows?: undefined\n /** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */\n minRows?: undefined\n }\n )\n\nexport type TextField = FieldBase & {\n admin?: Admin & {\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n rtl?: boolean\n }\n maxLength?: number\n minLength?: number\n type: 'text'\n} & (\n | {\n /** Makes this field an ordered array of strings instead of just a single string. */\n hasMany: true\n /** Maximum number of strings in the strings array, if `hasMany` is set to true. */\n maxRows?: number\n /** Minimum number of strings in the strings array, if `hasMany` is set to true. */\n minRows?: number\n }\n | {\n /** Makes this field an ordered array of strings instead of just a single string. */\n hasMany?: false | undefined\n /** Maximum number of strings in the strings array, if `hasMany` is set to true. */\n maxRows?: undefined\n /** Minimum number of strings in the strings array, if `hasMany` is set to true. */\n minRows?: undefined\n }\n )\n\nexport type EmailField = FieldBase & {\n admin?: Admin & {\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n }\n type: 'email'\n}\n\nexport type TextareaField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n rows?: number\n rtl?: boolean\n }\n maxLength?: number\n minLength?: number\n type: 'textarea'\n}\n\nexport type CheckboxField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n }\n type: 'checkbox'\n}\n\nexport type DateField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n date?: ConditionalDateProps\n placeholder?: Record<string, string> | string\n }\n type: 'date'\n}\n\nexport type GroupField = Omit<FieldBase, 'required' | 'validation'> & {\n admin?: Admin & {\n hideGutter?: boolean\n }\n fields: Field[]\n /** Customize generated GraphQL and Typescript schema names.\n * By default it is bound to the collection.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n type: 'group'\n}\n\nexport type RowAdmin = Omit<Admin, 'description'>\n\nexport type RowField = Omit<FieldBase, 'admin' | 'label' | 'name'> & {\n admin?: RowAdmin\n fields: Field[]\n type: 'row'\n}\n\nexport type CollapsibleField = Omit<FieldBase, 'label' | 'name'> & {\n admin?: Admin & {\n initCollapsed?: boolean\n }\n fields: Field[]\n label: RowLabel\n type: 'collapsible'\n}\n\nexport type TabsAdmin = Omit<Admin, 'description'>\n\ntype TabBase = Omit<FieldBase, 'required' | 'validation'> & {\n description?: Description\n fields: Field[]\n interfaceName?: string\n saveToJWT?: boolean | string\n}\n\nexport type NamedTab = TabBase & {\n /** Customize generated GraphQL and Typescript schema names.\n * The slug is used by default.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n}\n\nexport type UnnamedTab = Omit<TabBase, 'name'> & {\n interfaceName?: never\n /**\n * Can be either:\n * - A string, which will be used as the tab's label.\n * - An object, where the key is the language code and the value is the label.\n */\n label:\n | {\n [selectedLanguage: string]: string\n }\n | LabelFunction\n | string\n localized?: never\n}\n\nexport type Tab = NamedTab | UnnamedTab\n\nexport type TabsField = Omit<FieldBase, 'admin' | 'localized' | 'name' | 'saveToJWT'> & {\n admin?: TabsAdmin\n tabs: Tab[]\n type: 'tabs'\n}\n\nexport type TabAsField = Tab & {\n name?: string\n type: 'tab'\n}\n\nexport type UIField = {\n admin: {\n components?: {\n Cell?: CustomComponent\n Field: CustomComponent\n Filter?: React.ComponentType<any>\n }\n condition?: Condition\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n disableBulkEdit?: boolean\n position?: string\n width?: string\n }\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n label?: Record<string, string> | string\n name: string\n type: 'ui'\n}\n\nexport type UploadField = FieldBase & {\n admin?: {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n }\n filterOptions?: FilterOptions\n maxDepth?: number\n relationTo: string\n type: 'upload'\n}\n\ntype CodeAdmin = Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n editorOptions?: EditorProps['options']\n language?: string\n}\n\nexport type CodeField = Omit<FieldBase, 'admin'> & {\n admin?: CodeAdmin\n maxLength?: number\n minLength?: number\n type: 'code'\n}\n\ntype JSONAdmin = Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n editorOptions?: EditorProps['options']\n}\n\nexport type JSONField = Omit<FieldBase, 'admin'> & {\n admin?: JSONAdmin\n jsonSchema?: Record<string, unknown>\n type: 'json'\n}\n\nexport type SelectField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n isClearable?: boolean\n isSortable?: boolean\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n /**\n * Customize the DB enum name\n */\n enumName?: DBIdentifierName\n hasMany?: boolean\n options: Option[]\n type: 'select'\n}\n\ntype SharedRelationshipProperties = FieldBase & {\n filterOptions?: FilterOptions\n hasMany?: boolean\n maxDepth?: number\n type: 'relationship'\n} & (\n | {\n hasMany: true\n /**\n * @deprecated Use 'maxRows' instead\n */\n max?: number\n maxRows?: number\n /**\n * @deprecated Use 'minRows' instead\n */\n min?: number\n minRows?: number\n }\n | {\n hasMany?: false | undefined\n /**\n * @deprecated Use 'maxRows' instead\n */\n max?: undefined\n maxRows?: undefined\n /**\n * @deprecated Use 'minRows' instead\n */\n min?: undefined\n minRows?: undefined\n }\n )\n\ntype RelationshipAdmin = Admin & {\n allowCreate?: boolean\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n isSortable?: boolean\n}\nexport type PolymorphicRelationshipField = SharedRelationshipProperties & {\n admin?: RelationshipAdmin & {\n sortOptions?: { [collectionSlug: string]: string }\n }\n relationTo: string[]\n}\nexport type SingleRelationshipField = SharedRelationshipProperties & {\n admin?: RelationshipAdmin & {\n sortOptions?: string\n }\n relationTo: string\n}\nexport type RelationshipField = PolymorphicRelationshipField | SingleRelationshipField\n\nexport type ValueWithRelation = {\n relationTo: string\n value: number | string\n}\n\nexport function valueIsValueWithRelation(value: unknown): value is ValueWithRelation {\n return value !== null && typeof value === 'object' && 'relationTo' in value && 'value' in value\n}\n\nexport type RelationshipValue =\n | (number | string)[]\n | ValueWithRelation\n | ValueWithRelation[]\n | (number | string)\n\nexport type RichTextField<\n Value extends object = any,\n AdapterProps = any,\n ExtraProperties = object,\n> = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n }\n editor?: RichTextAdapter<Value, AdapterProps, AdapterProps>\n type: 'richText'\n} & ExtraProperties\n\nexport type RichTextFieldRequiredEditor<\n Value extends object = any,\n AdapterProps = any,\n ExtraProperties = object,\n> = Omit<RichTextField<Value, AdapterProps, ExtraProperties>, 'editor'> & {\n editor: RichTextAdapter<Value, AdapterProps, ExtraProperties>\n}\n\nexport type ArrayField = FieldBase & {\n admin?: Admin & {\n components?: {\n RowLabel?: RowLabel\n } & Admin['components']\n initCollapsed?: boolean\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n fields: Field[]\n /** Customize generated GraphQL and Typescript schema names.\n * By default it is bound to the collection.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n labels?: Labels\n maxRows?: number\n minRows?: number\n type: 'array'\n}\n\nexport type RadioField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n layout?: 'horizontal' | 'vertical'\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n /**\n * Customize the DB enum name\n */\n enumName?: DBIdentifierName\n options: Option[]\n type: 'radio'\n}\n\nexport type Block = {\n admin?: {\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n }\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n fields: Field[]\n /** @deprecated - please migrate to the interfaceName property instead. */\n graphQL?: {\n singularName?: string\n }\n imageAltText?: string\n imageURL?: string\n /** Customize generated GraphQL and Typescript schema names.\n * The slug is used by default.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n labels?: Labels\n slug: string\n}\n\nexport type BlockField = FieldBase & {\n admin?: Admin & {\n initCollapsed?: boolean\n }\n blocks: Block[]\n defaultValue?: unknown\n labels?: Labels\n maxRows?: number\n minRows?: number\n type: 'blocks'\n}\n\nexport type PointField = FieldBase & {\n type: 'point'\n}\n\nexport type Field =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | CollapsibleField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | RowField\n | SelectField\n | TabsField\n | TextField\n | TextareaField\n | UIField\n | UploadField\n\nexport type FieldWithRichTextRequiredEditor =\n | Exclude<Field, RichTextField>\n | RichTextFieldRequiredEditor\n\nexport type FieldAffectingData =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | SelectField\n | TabAsField\n | TextField\n | TextareaField\n | UploadField\n\nexport type NonPresentationalField =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | CollapsibleField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | RowField\n | SelectField\n | TabsField\n | TextField\n | TextareaField\n | UploadField\n\nexport type FieldWithPath = Field & {\n path?: string\n}\n\nexport type FieldWithSubFields = ArrayField | CollapsibleField | GroupField | RowField\n\nexport type FieldPresentationalOnly = UIField\n\nexport type FieldWithMany = RelationshipField | SelectField\n\nexport type FieldWithMaxDepth = RelationshipField | UploadField\n\nexport function fieldHasSubFields(field: ClientFieldConfig | Field): field is FieldWithSubFields {\n return (\n field.type === 'group' ||\n field.type === 'array' ||\n field.type === 'row' ||\n field.type === 'collapsible'\n )\n}\n\nexport function fieldIsArrayType(field: Field): field is ArrayField {\n return field.type === 'array'\n}\n\nexport function fieldIsBlockType(field: Field): field is BlockField {\n return field.type === 'blocks'\n}\n\nexport function fieldIsGroupType(field: Field): field is GroupField {\n return field.type === 'group'\n}\n\nexport function optionIsObject(option: Option): option is OptionObject {\n return typeof option === 'object'\n}\n\nexport function optionsAreObjects(options: Option[]): options is OptionObject[] {\n return Array.isArray(options) && typeof options?.[0] === 'object'\n}\n\nexport function optionIsValue(option: Option): option is string {\n return typeof option === 'string'\n}\n\nexport function fieldSupportsMany(field: Field): field is FieldWithMany {\n return field.type === 'select' || field.type === 'relationship'\n}\n\nexport function fieldHasMaxDepth(field: Field): field is FieldWithMaxDepth {\n return (\n (field.type === 'upload' || field.type === 'relationship') && typeof field.maxDepth === 'number'\n )\n}\n\nexport function fieldIsPresentationalOnly(\n field: ClientFieldConfig | Field | TabAsField,\n): field is UIField {\n return field.type === 'ui'\n}\n\nexport function fieldAffectsData(\n field: ClientFieldConfig | Field | TabAsField,\n): field is FieldAffectingData {\n return 'name' in field && !fieldIsPresentationalOnly(field)\n}\n\nexport function tabHasName(tab: Tab): tab is NamedTab {\n return 'name' in tab\n}\n\nexport function fieldIsLocalized(field: Field | Tab): boolean {\n return 'localized' in field && field.localized\n}\n\nexport type HookName =\n | 'afterChange'\n | 'afterRead'\n | 'beforeChange'\n | 'beforeRead'\n | 'beforeValidate'\n"],"names":["valueIsValueWithRelation","value","fieldHasSubFields","field","type","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","optionIsObject","option","optionsAreObjects","options","Array","isArray","optionIsValue","fieldSupportsMany","fieldHasMaxDepth","maxDepth","fieldIsPresentationalOnly","fieldAffectsData","tabHasName","tab","fieldIsLocalized","localized"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,qDAAqD,GACrD,uCAAuC,GAqjBvC,OAAO,SAASA,yBAAyBC,KAAc;IACrD,OAAOA,UAAU,QAAQ,OAAOA,UAAU,YAAY,gBAAgBA,SAAS,WAAWA;AAC5F;AA0MA,OAAO,SAASC,kBAAkBC,KAAgC;IAChE,OACEA,MAAMC,IAAI,KAAK,WACfD,MAAMC,IAAI,KAAK,WACfD,MAAMC,IAAI,KAAK,SACfD,MAAMC,IAAI,KAAK;AAEnB;AAEA,OAAO,SAASC,iBAAiBF,KAAY;IAC3C,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAEA,OAAO,SAASE,iBAAiBH,KAAY;IAC3C,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAEA,OAAO,SAASG,iBAAiBJ,KAAY;IAC3C,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAEA,OAAO,SAASI,eAAeC,MAAc;IAC3C,OAAO,OAAOA,WAAW;AAC3B;AAEA,OAAO,SAASC,kBAAkBC,OAAiB;IACjD,OAAOC,MAAMC,OAAO,CAACF,YAAY,OAAOA,SAAS,CAAC,EAAE,KAAK;AAC3D;AAEA,OAAO,SAASG,cAAcL,MAAc;IAC1C,OAAO,OAAOA,WAAW;AAC3B;AAEA,OAAO,SAASM,kBAAkBZ,KAAY;IAC5C,OAAOA,MAAMC,IAAI,KAAK,YAAYD,MAAMC,IAAI,KAAK;AACnD;AAEA,OAAO,SAASY,iBAAiBb,KAAY;IAC3C,OACE,AAACA,CAAAA,MAAMC,IAAI,KAAK,YAAYD,MAAMC,IAAI,KAAK,cAAa,KAAM,OAAOD,MAAMc,QAAQ,KAAK;AAE5F;AAEA,OAAO,SAASC,0BACdf,KAA6C;IAE7C,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAEA,OAAO,SAASe,iBACdhB,KAA6C;IAE7C,OAAO,UAAUA,SAAS,CAACe,0BAA0Bf;AACvD;AAEA,OAAO,SAASiB,WAAWC,GAAQ;IACjC,OAAO,UAAUA;AACnB;AAEA,OAAO,SAASC,iBAAiBnB,KAAkB;IACjD,OAAO,eAAeA,SAASA,MAAMoB,SAAS;AAChD"}
1
+ {"version":3,"sources":["../../../src/fields/config/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-use-before-define */\nimport type { EditorProps } from '@monaco-editor/react'\nimport type { CSSProperties } from 'react'\n\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport monacoeditor from 'monaco-editor' // IMPORTANT - DO NOT REMOVE: This is required for pnpm's default isolated mode to work - even though the import is not used. This is due to a typescript bug: https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189. (tsbugisolatedmode)\nimport type React from 'react'\n\nimport type { RichTextAdapter, RichTextAdapterProvider } from '../../admin/RichText.js'\nimport type {\n ConditionalDateProps,\n Description,\n ErrorProps,\n LabelProps,\n RowLabel,\n} from '../../admin/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../../collections/config/types.js'\nimport type { CustomComponent, LabelFunction } from '../../config/types.js'\nimport type { DBIdentifierName } from '../../database/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { Operation, PayloadRequestWithData, RequestContext, Where } from '../../types/index.js'\nimport type { ClientFieldConfig } from './client.js'\n\nexport type FieldHookArgs<T extends TypeWithID = any, P = any, S = any> = {\n /** The collection which the field belongs to. If the field belongs to a global, this will be null. */\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n /** The data passed to update the document within create and update operations, and the full document itself in the afterRead hook. */\n data?: Partial<T>\n /** The field which the hook is running against. */\n field: FieldAffectingData\n /** Boolean to denote if this hook is running against finding one, or finding many within the afterRead hook. */\n findMany?: boolean\n /** The global which the field belongs to. If the field belongs to a collection, this will be null. */\n global: SanitizedGlobalConfig | null\n /** A string relating to which operation the field type is currently executing within. Useful within beforeValidate, beforeChange, and afterChange hooks to differentiate between create and update operations. */\n operation?: 'create' | 'delete' | 'read' | 'update'\n /** The full original document in `update` operations. In the `afterChange` hook, this is the resulting document of the operation. */\n originalDoc?: T\n overrideAccess?: boolean\n /** The document before changes were applied, only in `afterChange` hooks. */\n previousDoc?: T\n /** The sibling data of the document before changes being applied, only in `beforeChange` and `afterChange` hook. */\n previousSiblingDoc?: T\n /** The previous value of the field, before changes, only in `beforeChange`, `afterChange` and `beforeValidate` hooks. */\n previousValue?: P\n /** The Express request object. It is mocked for Local API operations. */\n req: PayloadRequestWithData\n /** The sibling data passed to a field that the hook is running against. */\n siblingData: Partial<S>\n /** The value of the field. */\n value?: P\n}\n\nexport type FieldHook<T extends TypeWithID = any, P = any, S = any> = (\n args: FieldHookArgs<T, P, S>,\n) => P | Promise<P>\n\nexport type FieldAccess<T extends TypeWithID = any, P = any, U = any> = (args: {\n /**\n * The incoming data used to `create` or `update` the document with. `data` is undefined during the `read` operation.\n */\n data?: Partial<T>\n /**\n * The original data of the document before the `update` is applied. `doc` is undefined during the `create` operation.\n */\n doc?: T\n /**\n * The `id` of the current document being read or updated. `id` is undefined during the `create` operation.\n */\n id?: number | string\n /** The `payload` object to interface with the payload API */\n req: PayloadRequestWithData<U>\n /**\n * Immediately adjacent data to this field. For example, if this is a `group` field, then `siblingData` will be the other fields within the group.\n */\n siblingData?: Partial<P>\n}) => Promise<boolean> | boolean\n\nexport type Condition<T extends TypeWithID = any, P = any> = (\n data: Partial<T>,\n siblingData: Partial<P>,\n { user }: { user: PayloadRequestWithData['user'] },\n) => boolean\n\nexport type FilterOptionsProps<T = any> = {\n /**\n * An object containing the full collection or global document currently being edited.\n */\n data: T\n /**\n * The `id` of the current document being edited. `id` is undefined during the `create` operation.\n */\n id: number | string\n /**\n * The collection `slug` to filter against, limited to this field's `relationTo` property.\n */\n relationTo: string\n /**\n * An object containing document data that is scoped to only fields within the same parent of this field.\n */\n siblingData: unknown\n /**\n * An object containing the currently authenticated user.\n */\n user: Partial<PayloadRequestWithData['user']>\n}\n\nexport type FilterOptions<T = any> =\n | ((options: FilterOptionsProps<T>) => Promise<Where | boolean> | Where | boolean)\n | Where\n | null\n\ntype Admin = {\n className?: string\n components?: {\n Cell?: CustomComponent\n Field?: CustomComponent\n Filter?: React.ComponentType<any>\n }\n /**\n * You can programmatically show / hide fields based on what other fields are doing.\n * This is also run on the server, to determine if the field should be validated.\n */\n condition?: Condition\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n description?: Description\n disableBulkEdit?: boolean\n disabled?: boolean\n hidden?: boolean\n position?: 'sidebar'\n readOnly?: boolean\n style?: CSSProperties\n width?: string\n}\n\nexport type Labels = {\n plural: LabelFunction | Record<string, string> | string\n singular: LabelFunction | Record<string, string> | string\n}\n\nexport type BaseValidateOptions<TData, TSiblingData> = {\n data: Partial<TData>\n id?: number | string\n operation?: Operation\n preferences: DocumentPreferences\n req: PayloadRequestWithData\n siblingData: Partial<TSiblingData>\n}\n\nexport type ValidateOptions<TData, TSiblingData, TFieldConfig extends object> = BaseValidateOptions<\n TData,\n TSiblingData\n> &\n TFieldConfig\n\nexport type Validate<\n TValue = any,\n TData = any,\n TSiblingData = any,\n TFieldConfig extends object = object,\n> = (\n value: TValue,\n options: ValidateOptions<TData, TSiblingData, TFieldConfig>,\n) => Promise<string | true> | string | true\n\nexport type ClientValidate = Omit<Validate, 'req'>\n\nexport type OptionObject = {\n label: LabelFunction | Record<string, string> | string\n value: string\n}\n\nexport type Option = OptionObject | string\n\nexport interface FieldBase {\n access?: {\n create?: FieldAccess\n read?: FieldAccess\n update?: FieldAccess\n }\n admin?: Admin\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n defaultValue?: any\n hidden?: boolean\n hooks?: {\n afterChange?: FieldHook[]\n afterRead?: FieldHook[]\n beforeChange?: FieldHook[]\n /**\n * Runs before a document is duplicated to prevent errors in unique fields or return null to use defaultValue.\n */\n beforeDuplicate?: FieldHook[]\n beforeValidate?: FieldHook[]\n }\n index?: boolean\n label?: LabelFunction | Record<string, string> | false | string\n localized?: boolean\n name: string\n required?: boolean\n saveToJWT?: boolean | string\n unique?: boolean\n validate?: Validate\n}\n\nexport type NumberField = FieldBase & {\n admin?: Admin & {\n /** Set this property to a string that will be used for browser autocomplete. */\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n /** Set this property to define a placeholder string for the field. */\n placeholder?: Record<string, string> | string\n /** Set a value for the number field to increment / decrement using browser controls. */\n step?: number\n }\n /** Maximum value accepted. Used in the default `validation` function. */\n max?: number\n /** Minimum value accepted. Used in the default `validation` function. */\n min?: number\n type: 'number'\n} & (\n | {\n /** Makes this field an ordered array of numbers instead of just a single number. */\n hasMany: true\n /** Maximum number of numbers in the numbers array, if `hasMany` is set to true. */\n maxRows?: number\n /** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */\n minRows?: number\n }\n | {\n /** Makes this field an ordered array of numbers instead of just a single number. */\n hasMany?: false | undefined\n /** Maximum number of numbers in the numbers array, if `hasMany` is set to true. */\n maxRows?: undefined\n /** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */\n minRows?: undefined\n }\n )\n\nexport type TextField = FieldBase & {\n admin?: Admin & {\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n rtl?: boolean\n }\n maxLength?: number\n minLength?: number\n type: 'text'\n} & (\n | {\n /** Makes this field an ordered array of strings instead of just a single string. */\n hasMany: true\n /** Maximum number of strings in the strings array, if `hasMany` is set to true. */\n maxRows?: number\n /** Minimum number of strings in the strings array, if `hasMany` is set to true. */\n minRows?: number\n }\n | {\n /** Makes this field an ordered array of strings instead of just a single string. */\n hasMany?: false | undefined\n /** Maximum number of strings in the strings array, if `hasMany` is set to true. */\n maxRows?: undefined\n /** Minimum number of strings in the strings array, if `hasMany` is set to true. */\n minRows?: undefined\n }\n )\n\nexport type EmailField = FieldBase & {\n admin?: Admin & {\n autoComplete?: string\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n }\n type: 'email'\n}\n\nexport type TextareaField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n placeholder?: Record<string, string> | string\n rows?: number\n rtl?: boolean\n }\n maxLength?: number\n minLength?: number\n type: 'textarea'\n}\n\nexport type CheckboxField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n }\n type: 'checkbox'\n}\n\nexport type DateField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n afterInput?: CustomComponent[]\n beforeInput?: CustomComponent[]\n }\n date?: ConditionalDateProps\n placeholder?: Record<string, string> | string\n }\n type: 'date'\n}\n\nexport type GroupField = Omit<FieldBase, 'required' | 'validation'> & {\n admin?: Admin & {\n hideGutter?: boolean\n }\n fields: Field[]\n /** Customize generated GraphQL and Typescript schema names.\n * By default it is bound to the collection.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n type: 'group'\n}\n\nexport type RowAdmin = Omit<Admin, 'description'>\n\nexport type RowField = Omit<FieldBase, 'admin' | 'label' | 'name'> & {\n admin?: RowAdmin\n fields: Field[]\n type: 'row'\n}\n\nexport type CollapsibleField = Omit<FieldBase, 'label' | 'name'> & {\n admin?: Admin & {\n initCollapsed?: boolean\n }\n fields: Field[]\n label: RowLabel\n type: 'collapsible'\n}\n\nexport type TabsAdmin = Omit<Admin, 'description'>\n\ntype TabBase = Omit<FieldBase, 'required' | 'validation'> & {\n description?: Description\n fields: Field[]\n interfaceName?: string\n saveToJWT?: boolean | string\n}\n\nexport type NamedTab = TabBase & {\n /** Customize generated GraphQL and Typescript schema names.\n * The slug is used by default.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n}\n\nexport type UnnamedTab = Omit<TabBase, 'name'> & {\n interfaceName?: never\n /**\n * Can be either:\n * - A string, which will be used as the tab's label.\n * - An object, where the key is the language code and the value is the label.\n */\n label:\n | {\n [selectedLanguage: string]: string\n }\n | LabelFunction\n | string\n localized?: never\n}\n\nexport type Tab = NamedTab | UnnamedTab\n\nexport type TabsField = Omit<FieldBase, 'admin' | 'localized' | 'name' | 'saveToJWT'> & {\n admin?: TabsAdmin\n tabs: Tab[]\n type: 'tabs'\n}\n\nexport type TabAsField = Tab & {\n name?: string\n type: 'tab'\n}\n\nexport type UIField = {\n admin: {\n components?: {\n Cell?: CustomComponent\n Field: CustomComponent\n Filter?: React.ComponentType<any>\n }\n condition?: Condition\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n disableBulkEdit?: boolean\n position?: string\n width?: string\n }\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n label?: Record<string, string> | string\n name: string\n type: 'ui'\n}\n\nexport type UploadField = FieldBase & {\n admin?: {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n }\n filterOptions?: FilterOptions\n maxDepth?: number\n relationTo: string\n type: 'upload'\n}\n\ntype CodeAdmin = Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n editorOptions?: EditorProps['options']\n language?: string\n}\n\nexport type CodeField = Omit<FieldBase, 'admin'> & {\n admin?: CodeAdmin\n maxLength?: number\n minLength?: number\n type: 'code'\n}\n\ntype JSONAdmin = Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n editorOptions?: EditorProps['options']\n}\n\nexport type JSONField = Omit<FieldBase, 'admin'> & {\n admin?: JSONAdmin\n jsonSchema?: Record<string, unknown>\n type: 'json'\n}\n\nexport type SelectField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n isClearable?: boolean\n isSortable?: boolean\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n /**\n * Customize the DB enum name\n */\n enumName?: DBIdentifierName\n hasMany?: boolean\n options: Option[]\n type: 'select'\n}\n\ntype SharedRelationshipProperties = FieldBase & {\n filterOptions?: FilterOptions\n hasMany?: boolean\n maxDepth?: number\n type: 'relationship'\n} & (\n | {\n hasMany: true\n /**\n * @deprecated Use 'maxRows' instead\n */\n max?: number\n maxRows?: number\n /**\n * @deprecated Use 'minRows' instead\n */\n min?: number\n minRows?: number\n }\n | {\n hasMany?: false | undefined\n /**\n * @deprecated Use 'maxRows' instead\n */\n max?: undefined\n maxRows?: undefined\n /**\n * @deprecated Use 'minRows' instead\n */\n min?: undefined\n minRows?: undefined\n }\n )\n\ntype RelationshipAdmin = Admin & {\n allowCreate?: boolean\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n isSortable?: boolean\n}\nexport type PolymorphicRelationshipField = SharedRelationshipProperties & {\n admin?: RelationshipAdmin & {\n sortOptions?: { [collectionSlug: string]: string }\n }\n relationTo: string[]\n}\nexport type SingleRelationshipField = SharedRelationshipProperties & {\n admin?: RelationshipAdmin & {\n sortOptions?: string\n }\n relationTo: string\n}\nexport type RelationshipField = PolymorphicRelationshipField | SingleRelationshipField\n\nexport type ValueWithRelation = {\n relationTo: string\n value: number | string\n}\n\nexport function valueIsValueWithRelation(value: unknown): value is ValueWithRelation {\n return value !== null && typeof value === 'object' && 'relationTo' in value && 'value' in value\n}\n\nexport type RelationshipValue =\n | (number | string)[]\n | ValueWithRelation\n | ValueWithRelation[]\n | (number | string)\n\nexport type RichTextField<\n Value extends object = any,\n AdapterProps = any,\n ExtraProperties = object,\n> = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n }\n editor?:\n | RichTextAdapter<Value, AdapterProps, AdapterProps>\n | RichTextAdapterProvider<Value, AdapterProps, AdapterProps>\n type: 'richText'\n} & ExtraProperties\n\nexport type RichTextFieldRequiredEditor<\n Value extends object = any,\n AdapterProps = any,\n ExtraProperties = object,\n> = Omit<RichTextField<Value, AdapterProps, ExtraProperties>, 'editor'> & {\n editor:\n | RichTextAdapter<Value, AdapterProps, AdapterProps>\n | RichTextAdapterProvider<Value, AdapterProps, AdapterProps>\n}\n\nexport type ArrayField = FieldBase & {\n admin?: Admin & {\n components?: {\n RowLabel?: RowLabel\n } & Admin['components']\n initCollapsed?: boolean\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n fields: Field[]\n /** Customize generated GraphQL and Typescript schema names.\n * By default it is bound to the collection.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n labels?: Labels\n maxRows?: number\n minRows?: number\n type: 'array'\n}\n\nexport type RadioField = FieldBase & {\n admin?: Admin & {\n components?: {\n Error?: CustomComponent<ErrorProps>\n Label?: CustomComponent<LabelProps>\n }\n layout?: 'horizontal' | 'vertical'\n }\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n /**\n * Customize the DB enum name\n */\n enumName?: DBIdentifierName\n options: Option[]\n type: 'radio'\n}\n\nexport type Block = {\n admin?: {\n /** Extension point to add your custom data. Available in server and client. */\n custom?: Record<string, any>\n }\n /** Extension point to add your custom data. Server only. */\n custom?: Record<string, any>\n /**\n * Customize the SQL table name\n */\n dbName?: DBIdentifierName\n fields: Field[]\n /** @deprecated - please migrate to the interfaceName property instead. */\n graphQL?: {\n singularName?: string\n }\n imageAltText?: string\n imageURL?: string\n /** Customize generated GraphQL and Typescript schema names.\n * The slug is used by default.\n *\n * This is useful if you would like to generate a top level type to share amongst collections/fields.\n * **Note**: Top level types can collide, ensure they are unique among collections, arrays, groups, blocks, tabs.\n */\n interfaceName?: string\n labels?: Labels\n slug: string\n}\n\nexport type BlockField = FieldBase & {\n admin?: Admin & {\n initCollapsed?: boolean\n }\n blocks: Block[]\n defaultValue?: unknown\n labels?: Labels\n maxRows?: number\n minRows?: number\n type: 'blocks'\n}\n\nexport type PointField = FieldBase & {\n type: 'point'\n}\n\nexport type Field =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | CollapsibleField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | RowField\n | SelectField\n | TabsField\n | TextField\n | TextareaField\n | UIField\n | UploadField\n\nexport type FieldWithRichTextRequiredEditor =\n | Exclude<Field, RichTextField>\n | RichTextFieldRequiredEditor\n\nexport type FieldAffectingData =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | SelectField\n | TabAsField\n | TextField\n | TextareaField\n | UploadField\n\nexport type NonPresentationalField =\n | ArrayField\n | BlockField\n | CheckboxField\n | CodeField\n | CollapsibleField\n | DateField\n | EmailField\n | GroupField\n | JSONField\n | NumberField\n | PointField\n | RadioField\n | RelationshipField\n | RichTextField\n | RowField\n | SelectField\n | TabsField\n | TextField\n | TextareaField\n | UploadField\n\nexport type FieldWithPath = Field & {\n path?: string\n}\n\nexport type FieldWithSubFields = ArrayField | CollapsibleField | GroupField | RowField\n\nexport type FieldPresentationalOnly = UIField\n\nexport type FieldWithMany = RelationshipField | SelectField\n\nexport type FieldWithMaxDepth = RelationshipField | UploadField\n\nexport function fieldHasSubFields(field: ClientFieldConfig | Field): field is FieldWithSubFields {\n return (\n field.type === 'group' ||\n field.type === 'array' ||\n field.type === 'row' ||\n field.type === 'collapsible'\n )\n}\n\nexport function fieldIsArrayType(field: Field): field is ArrayField {\n return field.type === 'array'\n}\n\nexport function fieldIsBlockType(field: Field): field is BlockField {\n return field.type === 'blocks'\n}\n\nexport function fieldIsGroupType(field: Field): field is GroupField {\n return field.type === 'group'\n}\n\nexport function optionIsObject(option: Option): option is OptionObject {\n return typeof option === 'object'\n}\n\nexport function optionsAreObjects(options: Option[]): options is OptionObject[] {\n return Array.isArray(options) && typeof options?.[0] === 'object'\n}\n\nexport function optionIsValue(option: Option): option is string {\n return typeof option === 'string'\n}\n\nexport function fieldSupportsMany(field: Field): field is FieldWithMany {\n return field.type === 'select' || field.type === 'relationship'\n}\n\nexport function fieldHasMaxDepth(field: Field): field is FieldWithMaxDepth {\n return (\n (field.type === 'upload' || field.type === 'relationship') && typeof field.maxDepth === 'number'\n )\n}\n\nexport function fieldIsPresentationalOnly(\n field: ClientFieldConfig | Field | TabAsField,\n): field is UIField {\n return field.type === 'ui'\n}\n\nexport function fieldAffectsData(\n field: ClientFieldConfig | Field | TabAsField,\n): field is FieldAffectingData {\n return 'name' in field && !fieldIsPresentationalOnly(field)\n}\n\nexport function tabHasName(tab: Tab): tab is NamedTab {\n return 'name' in tab\n}\n\nexport function fieldIsLocalized(field: Field | Tab): boolean {\n return 'localized' in field && field.localized\n}\n\nexport type HookName =\n | 'afterChange'\n | 'afterRead'\n | 'beforeChange'\n | 'beforeRead'\n | 'beforeValidate'\n"],"names":["valueIsValueWithRelation","value","fieldHasSubFields","field","type","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","optionIsObject","option","optionsAreObjects","options","Array","isArray","optionIsValue","fieldSupportsMany","fieldHasMaxDepth","maxDepth","fieldIsPresentationalOnly","fieldAffectsData","tabHasName","tab","fieldIsLocalized","localized"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,qDAAqD,GACrD,uCAAuC,GAqjBvC,OAAO,SAASA,yBAAyBC,KAAc;IACrD,OAAOA,UAAU,QAAQ,OAAOA,UAAU,YAAY,gBAAgBA,SAAS,WAAWA;AAC5F;AA8MA,OAAO,SAASC,kBAAkBC,KAAgC;IAChE,OACEA,MAAMC,IAAI,KAAK,WACfD,MAAMC,IAAI,KAAK,WACfD,MAAMC,IAAI,KAAK,SACfD,MAAMC,IAAI,KAAK;AAEnB;AAEA,OAAO,SAASC,iBAAiBF,KAAY;IAC3C,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAEA,OAAO,SAASE,i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AAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAO9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,GAAG,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IACnC,GAAG,EAAE,sBAAsB,CAAA;IAC3B,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAUD,eAAO,MAAM,OAAO,kPAoBjB,IAAI,KAAG,QAAQ,IAAI,CA6drB,CAAA"}
@@ -66,6 +66,9 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, f
66
66
  }
67
67
  case 'richText':
68
68
  {
69
+ if (typeof field?.editor === 'function') {
70
+ throw new Error('Attempted to access unsanitized rich text editor.');
71
+ }
69
72
  const editor = field?.editor;
70
73
  // This is run here AND in the GraphQL Resolver
71
74
  if (editor?.populationPromises) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { RichTextAdapter } from '../../../admin/types.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport getValueWithDefault from '../../getDefaultValue.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n const editor: RichTextAdapter = field?.editor\n // This is run here AND in the GraphQL Resolver\n if (editor?.populationPromises) {\n editor.populationPromises({\n context,\n currentDepth,\n depth,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n })\n }\n\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n global,\n operation: 'read',\n originalDoc: doc,\n req,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n req,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getValueWithDefault({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') groupDoc = {}\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') tabDoc = {}\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["fieldAffectsData","tabHasName","getValueWithDefault","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","populationPromises","req","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","pointDoc","Array","isArray","coordinates","length","undefined","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","fields","rows","row","values","localeRows","block","blocks","find","blockType","slug","tabDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAOpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,OAAOC,yBAAyB,2BAA0B;AAC1D,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,cAAc,QAAQ,sBAAqB;AA2BpD,oEAAoE;AACpE,uCAAuC;AACvC,0CAA0C;AAC1C,+CAA+C;AAC/C,wBAAwB;AACxB,gCAAgC;AAChC,2BAA2B;AAE3B,OAAO,MAAMC,UAAU,OAAO,EAC5BC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAA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ACAC;oBACAC;oBACAC;oBACAE;oBACA6D,QAAQ9D,MAAMyB,IAAI,CAACmB,GAAG,CAAC,CAACjB,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEH,MAAM;wBAAM,CAAA;oBACvDtB;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;gBACF;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { RichTextAdapter } from '../../../admin/types.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequestWithData, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport getValueWithDefault from '../../getDefaultValue.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n currentDepth: number\n depth: number\n doc: Record<string, unknown>\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: SanitizedGlobalConfig | null\n locale: null | string\n overrideAccess: boolean\n populationPromises: Promise<void>[]\n req: PayloadRequestWithData\n showHiddenFields: boolean\n siblingDoc: Record<string, unknown>\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n // This is run here AND in the GraphQL Resolver\n if (editor?.populationPromises) {\n editor.populationPromises({\n context,\n currentDepth,\n depth,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n })\n }\n\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n global,\n operation: 'read',\n originalDoc: doc,\n req,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n data: doc,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n req,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getValueWithDefault({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') groupDoc = {}\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row) => {\n const block = field.blocks.find((blockType) => blockType.slug === row.blockType)\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as Record<string, unknown>\n if (typeof siblingDoc[field.name] !== 'object') tabDoc = {}\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["fieldAffectsData","tabHasName","getValueWithDefault","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","populationPromises","req","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","Error","pointDoc","Array","isArray","coordinates","length","undefined","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","fields","rows","row","values","localeRows","block","blocks","find","blockType","slug","tabDoc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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F;QAEA,KAAK;YAAO;gBACV,IAAI6D,SAAS/D;gBACb,IAAIrB,WAAWW,QAAQ;oBACrByE,SAAS/D,UAAU,CAACV,MAAMc,IAAI,CAAC;oBAC/B,IAAI,OAAOJ,UAAU,CAACV,MAAMc,IAAI,CAAC,KAAK,UAAU2D,SAAS,CAAC;gBAC5D;gBAEAjF,eAAe;oBACbE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACA8D,QAAQ/D,MAAM+D,MAAM;oBACpB7D;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,YAAY+D;oBACZ9D;oBACAC;gBACF;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACXpB,eAAe;oBACbE;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE;oBACA8D,QAAQ/D,MAAMyB,IAAI,CAACoB,GAAG,CAAC,CAAClB,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEH,MAAM;wBAAM,CAAA;oBACvDtB;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;gBACF;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../src/fields/validations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,SAAS,EACT,aAAa,EACb,WAAW,EACX,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAK1B,eAAO,MAAM,IAAI,EAAE,QAAQ,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAkDzE,CAAA;AAED,eAAO,MAAM,QA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AE,OAAO,EAAE,OAAO,EAAE,UAAU,CAYjE,CAAA;AAED,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAqB5F,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED,wBAkBC"}
@@ -166,6 +166,9 @@ export const date = (value, { req: { t }, required })=>{
166
166
  return true;
167
167
  };
168
168
  export const richText = async (value, options)=>{
169
+ if (typeof options?.editor === 'function') {
170
+ throw new Error('Attempted to access unsanitized rich text editor.');
171
+ }
169
172
  const editor = options?.editor;
170
173
  return editor.validate(value, options);
171
174
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/validations.ts"],"sourcesContent":["import Ajv from 'ajv'\n\nimport type { RichTextAdapter } from '../admin/types.js'\nimport type { Where } from '../types/index.js'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n DateField,\n EmailField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RelationshipValue,\n RichTextField,\n SelectField,\n TextField,\n TextareaField,\n UploadField,\n Validate,\n} from './config/types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport { isValidID } from '../utilities/isValidID.js'\n\nexport const text: Validate<string | string[], unknown, unknown, TextField> = (\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) return true\n }\n\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') return lengthValidationResult\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') maxLength = fieldMaxLength\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('value'), maxLength, stringValue })\n }\n\n if (typeof minLength === 'number' && length < minLength) {\n return t('validation:longerThanMin', { label: t('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 const password: Validate<string, unknown, unknown, TextField> = (\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') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') 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 const email: Validate<string, unknown, unknown, EmailField> = (\n value,\n { req: { t }, required },\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 const textarea: Validate<string, unknown, unknown, TextareaField> = (\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') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') maxLength = fieldMaxLength\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 const code: Validate<string, unknown, unknown, CodeField> = (\n value,\n { req: { t }, required },\n) => {\n if (required && value === undefined) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport const json: Validate<string, unknown, unknown, JSONField & { jsonError?: string }> = 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) return schema\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 const checkbox: Validate<boolean, unknown, unknown, CheckboxField> = (\n value,\n { req: { t }, required },\n) => {\n if ((value && typeof value !== 'boolean') || (required && typeof value !== 'boolean')) {\n return t('validation:trueOrFalse')\n }\n\n return true\n}\n\nexport const date: Validate<Date, unknown, unknown, DateField> = (\n value,\n { req: { t }, required },\n) => {\n if (value && !isNaN(Date.parse(value.toString()))) {\n /* eslint-disable-line */\n return true\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 const richText: Validate<object, unknown, unknown, RichTextField> = async (\n value,\n options,\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) return true\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 const number: Validate<number | number[], unknown, unknown, NumberField> = (\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') return lengthValidationResult\n }\n\n if (!value && !isNumber(value)) {\n // if no value is present, validate based on required\n if (required) return t('validation:required')\n if (!required) return true\n }\n\n const numbersToValidate: number[] = Array.isArray(value) ? value : [value]\n\n for (const number of numbersToValidate) {\n if (!isNumber(number)) return t('validation:enterNumber')\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 const array: Validate<unknown[], unknown, unknown, ArrayField> = (\n value,\n { maxRows, minRows, req: { t }, required },\n) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nexport const blocks: Validate<unknown, unknown, unknown, BlockField> = (\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, 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: string[] = []\n const collections = typeof relationTo === 'string' ? [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 data,\n relationTo: collection,\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' && val?.value) {\n valueIDs.push(val.value)\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) findWhere.and.push(optionFilter)\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\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]) return true\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 const upload: Validate<unknown, unknown, unknown, UploadField> = (\n value: string,\n options,\n) => {\n if (!value && options.required) {\n return options?.req?.t('validation:required')\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const idType =\n options?.req?.payload?.collections[options.relationTo]?.customIDType ||\n options?.req?.payload?.db?.defaultIDType\n\n if (!isValidID(value, idType)) {\n return options.req?.t('validation:validUploadID')\n }\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport const relationship: Validate<\n RelationshipValue,\n unknown,\n unknown,\n RelationshipField\n> = async (value, options) => {\n const {\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if ((!value || (Array.isArray(value) && value.length === 0)) && required) {\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) {\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) return false\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 return validateFilterOptions(value, options)\n}\n\nexport const select: Validate<unknown, unknown, unknown, SelectField> = (\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 const radio: Validate<unknown, unknown, unknown, RadioField> = (\n value,\n { options, req: { t }, required },\n) => {\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 const point: Validate<[number | string, number | string], unknown, unknown, PointField> = (\n value = ['', ''],\n { req: { t }, required },\n) => {\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\nexport default {\n array,\n blocks,\n checkbox,\n code,\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","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","email","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","isNaN","Date","parse","toString","richText","options","editor","arrayLength","count","number","max","min","numbersToValidate","numberValue","parseFloat","array","blocks","validateFilterOptions","data","filterOptions","relationTo","user","siblingData","falseCollections","collections","values","collection","optionFilter","valueIDs","forEach","val","push","findWhere","and","in","result","find","depth","limit","pagination","where","docs","map","doc","err","logger","msg","invalidRelationships","filter","requestedID","slug","indexOf","reduce","invalid","i","JSON","stringify","upload","idType","customIDType","db","defaultIDType","relationship","collectionSlug","join","select","some","input","option","radio","valueMatchesOption","point","lng","String","lat","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAAS,MAAK;AAyBrB,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,OAAO,MAAMC,OAAiE,CAC5EC,OACA,EACEC,OAAO,EACPC,WAAWC,cAAc,EACzBC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACnBC,CAAC,EACF,EACDC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,CAAC,EAAE,IAAIgI,OAAO3E,KAAK,CAACwE,QAAU7H,KAAK,CAAC,EAAE,IAAIgI,OAAO3E,KAAK,CAAC0E,MAAO;QACtE,OAAOrH,EAAE;IACX;IAEA,OAAO;AACT,EAAC;AAED,eAAe;IACb0D;IACAC;IACAlB;IACA1B;IACA2B;IACA9B;IACAK;IACAmC;IACAzC;IACAuG;IACAF;IACAP;IACA1D;IACA6D;IACAvH;IACAyB;IACAsF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/validations.ts"],"sourcesContent":["import Ajv from 'ajv'\n\nimport type { RichTextAdapter } from '../admin/types.js'\nimport type { Where } from '../types/index.js'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n DateField,\n EmailField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RelationshipValue,\n RichTextField,\n SelectField,\n TextField,\n TextareaField,\n UploadField,\n Validate,\n} from './config/types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport { isValidID } from '../utilities/isValidID.js'\n\nexport const text: Validate<string | string[], unknown, unknown, TextField> = (\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) return true\n }\n\n if (hasMany === true) {\n const lengthValidationResult = validateArrayLength(value, { maxRows, minRows, required, t })\n if (typeof lengthValidationResult === 'string') return lengthValidationResult\n }\n\n if (typeof config?.defaultMaxTextLength === 'number') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') maxLength = fieldMaxLength\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('value'), maxLength, stringValue })\n }\n\n if (typeof minLength === 'number' && length < minLength) {\n return t('validation:longerThanMin', { label: t('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 const password: Validate<string, unknown, unknown, TextField> = (\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') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') 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 const email: Validate<string, unknown, unknown, EmailField> = (\n value,\n { req: { t }, required },\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 const textarea: Validate<string, unknown, unknown, TextareaField> = (\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') maxLength = config.defaultMaxTextLength\n if (typeof fieldMaxLength === 'number') maxLength = fieldMaxLength\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 const code: Validate<string, unknown, unknown, CodeField> = (\n value,\n { req: { t }, required },\n) => {\n if (required && value === undefined) {\n return t('validation:required')\n }\n\n return true\n}\n\nexport const json: Validate<string, unknown, unknown, JSONField & { jsonError?: string }> = 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) return schema\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 const checkbox: Validate<boolean, unknown, unknown, CheckboxField> = (\n value,\n { req: { t }, required },\n) => {\n if ((value && typeof value !== 'boolean') || (required && typeof value !== 'boolean')) {\n return t('validation:trueOrFalse')\n }\n\n return true\n}\n\nexport const date: Validate<Date, unknown, unknown, DateField> = (\n value,\n { req: { t }, required },\n) => {\n if (value && !isNaN(Date.parse(value.toString()))) {\n /* eslint-disable-line */\n return true\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 const richText: Validate<object, unknown, unknown, RichTextField> = async (\n value,\n options,\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) return true\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 const number: Validate<number | number[], unknown, unknown, NumberField> = (\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') return lengthValidationResult\n }\n\n if (!value && !isNumber(value)) {\n // if no value is present, validate based on required\n if (required) return t('validation:required')\n if (!required) return true\n }\n\n const numbersToValidate: number[] = Array.isArray(value) ? value : [value]\n\n for (const number of numbersToValidate) {\n if (!isNumber(number)) return t('validation:enterNumber')\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 const array: Validate<unknown[], unknown, unknown, ArrayField> = (\n value,\n { maxRows, minRows, req: { t }, required },\n) => {\n return validateArrayLength(value, { maxRows, minRows, required, t })\n}\n\nexport const blocks: Validate<unknown, unknown, unknown, BlockField> = (\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, 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: string[] = []\n const collections = typeof relationTo === 'string' ? [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 data,\n relationTo: collection,\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' && val?.value) {\n valueIDs.push(val.value)\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) findWhere.and.push(optionFilter)\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\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]) return true\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 const upload: Validate<unknown, unknown, unknown, UploadField> = (\n value: string,\n options,\n) => {\n if (!value && options.required) {\n return options?.req?.t('validation:required')\n }\n\n if (typeof value !== 'undefined' && value !== null) {\n const idType =\n options?.req?.payload?.collections[options.relationTo]?.customIDType ||\n options?.req?.payload?.db?.defaultIDType\n\n if (!isValidID(value, idType)) {\n return options.req?.t('validation:validUploadID')\n }\n }\n\n return validateFilterOptions(value, options)\n}\n\nexport const relationship: Validate<\n RelationshipValue,\n unknown,\n unknown,\n RelationshipField\n> = async (value, options) => {\n const {\n maxRows,\n minRows,\n relationTo,\n req: { payload, t },\n required,\n } = options\n\n if ((!value || (Array.isArray(value) && value.length === 0)) && required) {\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) {\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) return false\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 return validateFilterOptions(value, options)\n}\n\nexport const select: Validate<unknown, unknown, unknown, SelectField> = (\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 const radio: Validate<unknown, unknown, unknown, RadioField> = (\n value,\n { options, req: { t }, required },\n) => {\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 const point: Validate<[number | string, number | string], unknown, unknown, PointField> = (\n value = ['', ''],\n { req: { t }, required },\n) => {\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\nexport default {\n array,\n blocks,\n checkbox,\n code,\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","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","email","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","isNaN","Date","parse","toString","richText","options","editor","arrayLength","count","number","max","min","numbersToValidate","numberValue","parseFloat","array","blocks","validateFilterOptions","data","filterOptions","relationTo","user","siblingData","falseCollections","collections","values","collection","optionFilter","valueIDs","forEach","val","push","findWhere","and","in","result","find","depth","limit","pagination","where","docs","map","doc","err","logger","msg","invalidRelationships","filter","requestedID","slug","indexOf","reduce","invalid","i","JSON","stringify","upload","idType","customIDType","db","defaultIDType","relationship","collectionSlug","join","select","some","input","option","radio","valueMatchesOption","point","lng","String","lat","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAAS,MAAK;AAyBrB,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,OAAO,MAAMC,OAAiE,CAC5EC,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,OAAO;IACrB;IAEA,IAAIC,YAAY,MAAM;QACpB,MAAMW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AAK,CAAC,EAAE,IAAIgI,OAAO3E,KAAK,CAAC0E,MAAO;QACtE,OAAOrH,EAAE;IACX;IAEA,OAAO;AACT,EAAC;AAED,eAAe;IACb0D;IACAC;IACAlB;IACA1B;IACA2B;IACA9B;IACAK;IACAmC;IACAzC;IACAuG;IACAF;IACAP;IACA1D;IACA6D;IACAvH;IACAyB;IACAsF;AACF,EAAC"}
@@ -1,5 +1,4 @@
1
- import type { Config } from '../../config/types.js';
1
+ import type { Config, SanitizedConfig } from '../../config/types.js';
2
2
  import type { SanitizedGlobalConfig } from './types.js';
3
- declare const sanitizeGlobals: (config: Config) => SanitizedGlobalConfig[];
4
- export default sanitizeGlobals;
3
+ export declare const sanitizeGlobals: (config: Config, richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>) => Promise<SanitizedGlobalConfig[]>;
5
4
  //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/globals/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AASvD,QAAA,MAAM,eAAe,WAAY,MAAM,KAAG,qBAAqB,EA8F9D,CAAA;AAED,eAAe,eAAe,CAAA"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/globals/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AASvD,eAAO,MAAM,eAAe,WAClB,MAAM,iCAKiB,MAAM,CAAC,MAAM,EAAE,eAAe,KAAK,QAAQ,IAAI,CAAC,CAAC,KAC/E,QAAQ,qBAAqB,EAAE,CA8FjC,CAAA"}
@@ -4,52 +4,53 @@ import { fieldAffectsData } from '../../fields/config/types.js';
4
4
  import mergeBaseFields from '../../fields/mergeBaseFields.js';
5
5
  import { toWords } from '../../utilities/formatLabels.js';
6
6
  import baseVersionFields from '../../versions/baseFields.js';
7
- const sanitizeGlobals = (config)=>{
7
+ export const sanitizeGlobals = async (config, /**
8
+ * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
9
+ * so that you can sanitize them together, after the config has been sanitized.
10
+ */ richTextSanitizationPromises)=>{
8
11
  const { collections, globals } = config;
9
- const sanitizedGlobals = globals.map((global)=>{
10
- const sanitizedGlobal = {
11
- ...global
12
- };
13
- sanitizedGlobal.label = sanitizedGlobal.label || toWords(sanitizedGlobal.slug);
12
+ for(let i = 0; i < globals.length; i++){
13
+ const global = globals[i];
14
+ global.label = global.label || toWords(global.slug);
14
15
  // /////////////////////////////////
15
16
  // Ensure that collection has required object structure
16
17
  // /////////////////////////////////
17
- sanitizedGlobal.endpoints = sanitizedGlobal.endpoints ?? [];
18
- if (!sanitizedGlobal.hooks) sanitizedGlobal.hooks = {};
19
- if (!sanitizedGlobal.access) sanitizedGlobal.access = {};
20
- if (!sanitizedGlobal.admin) sanitizedGlobal.admin = {};
21
- if (!sanitizedGlobal.access.read) sanitizedGlobal.access.read = defaultAccess;
22
- if (!sanitizedGlobal.access.update) sanitizedGlobal.access.update = defaultAccess;
23
- if (!sanitizedGlobal.hooks.beforeValidate) sanitizedGlobal.hooks.beforeValidate = [];
24
- if (!sanitizedGlobal.hooks.beforeChange) sanitizedGlobal.hooks.beforeChange = [];
25
- if (!sanitizedGlobal.hooks.afterChange) sanitizedGlobal.hooks.afterChange = [];
26
- if (!sanitizedGlobal.hooks.beforeRead) sanitizedGlobal.hooks.beforeRead = [];
27
- if (!sanitizedGlobal.hooks.afterRead) sanitizedGlobal.hooks.afterRead = [];
28
- if (sanitizedGlobal.versions) {
29
- if (sanitizedGlobal.versions === true) sanitizedGlobal.versions = {
18
+ global.endpoints = global.endpoints ?? [];
19
+ if (!global.hooks) global.hooks = {};
20
+ if (!global.access) global.access = {};
21
+ if (!global.admin) global.admin = {};
22
+ if (!global.access.read) global.access.read = defaultAccess;
23
+ if (!global.access.update) global.access.update = defaultAccess;
24
+ if (!global.hooks.beforeValidate) global.hooks.beforeValidate = [];
25
+ if (!global.hooks.beforeChange) global.hooks.beforeChange = [];
26
+ if (!global.hooks.afterChange) global.hooks.afterChange = [];
27
+ if (!global.hooks.beforeRead) global.hooks.beforeRead = [];
28
+ if (!global.hooks.afterRead) global.hooks.afterRead = [];
29
+ if (global.versions) {
30
+ if (global.versions === true) global.versions = {
30
31
  drafts: false
31
32
  };
32
- if (sanitizedGlobal.versions.drafts) {
33
- if (sanitizedGlobal.versions.drafts === true) {
34
- sanitizedGlobal.versions.drafts = {
33
+ if (global.versions.drafts) {
34
+ if (global.versions.drafts === true) {
35
+ global.versions.drafts = {
35
36
  autosave: false
36
37
  };
37
38
  }
38
- if (sanitizedGlobal.versions.drafts.autosave === true) {
39
- sanitizedGlobal.versions.drafts.autosave = {
39
+ if (global.versions.drafts.autosave === true) {
40
+ global.versions.drafts.autosave = {
40
41
  interval: 2000
41
42
  };
42
43
  }
43
- sanitizedGlobal.fields = mergeBaseFields(sanitizedGlobal.fields, baseVersionFields);
44
+ global.fields = mergeBaseFields(global.fields, baseVersionFields);
44
45
  }
45
46
  }
46
- if (!sanitizedGlobal.custom) sanitizedGlobal.custom = {};
47
+ if (!global.custom) global.custom = {};
47
48
  // /////////////////////////////////
48
49
  // Sanitize fields
49
50
  // /////////////////////////////////
50
51
  let hasUpdatedAt = null;
51
52
  let hasCreatedAt = null;
52
- sanitizedGlobal.fields.some((field)=>{
53
+ global.fields.some((field)=>{
53
54
  if (fieldAffectsData(field)) {
54
55
  if (field.name === 'updatedAt') hasUpdatedAt = true;
55
56
  if (field.name === 'createdAt') hasCreatedAt = true;
@@ -57,7 +58,7 @@ const sanitizeGlobals = (config)=>{
57
58
  return hasCreatedAt && hasUpdatedAt;
58
59
  });
59
60
  if (!hasUpdatedAt) {
60
- sanitizedGlobal.fields.push({
61
+ global.fields.push({
61
62
  name: 'updatedAt',
62
63
  type: 'date',
63
64
  admin: {
@@ -68,7 +69,7 @@ const sanitizeGlobals = (config)=>{
68
69
  });
69
70
  }
70
71
  if (!hasCreatedAt) {
71
- sanitizedGlobal.fields.push({
72
+ global.fields.push({
72
73
  name: 'createdAt',
73
74
  type: 'date',
74
75
  admin: {
@@ -79,15 +80,15 @@ const sanitizeGlobals = (config)=>{
79
80
  });
80
81
  }
81
82
  const validRelationships = collections.map((c)=>c.slug) || [];
82
- sanitizedGlobal.fields = sanitizeFields({
83
+ global.fields = await sanitizeFields({
83
84
  config,
84
- fields: sanitizedGlobal.fields,
85
+ fields: global.fields,
86
+ richTextSanitizationPromises,
85
87
  validRelationships
86
88
  });
87
- return sanitizedGlobal;
88
- });
89
- return sanitizedGlobals;
89
+ globals[i] = global;
90
+ }
91
+ return globals;
90
92
  };
91
- export default sanitizeGlobals;
92
93
 
93
94
  //# sourceMappingURL=sanitize.js.map