payload 3.0.0-beta.104 → 3.0.0-beta.106

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 (60) hide show
  1. package/dist/admin/forms/Description.d.ts +1 -1
  2. package/dist/admin/forms/Description.d.ts.map +1 -1
  3. package/dist/admin/forms/Description.js.map +1 -1
  4. package/dist/admin/forms/Error.d.ts +1 -1
  5. package/dist/admin/forms/Error.d.ts.map +1 -1
  6. package/dist/admin/forms/Error.js.map +1 -1
  7. package/dist/admin/forms/Label.d.ts +3 -3
  8. package/dist/admin/forms/Label.d.ts.map +1 -1
  9. package/dist/admin/forms/Label.js.map +1 -1
  10. package/dist/collections/operations/duplicate.d.ts.map +1 -1
  11. package/dist/collections/operations/duplicate.js +10 -2
  12. package/dist/collections/operations/duplicate.js.map +1 -1
  13. package/dist/fields/baseFields/baseIDField.d.ts.map +1 -1
  14. package/dist/fields/baseFields/baseIDField.js +5 -0
  15. package/dist/fields/baseFields/baseIDField.js.map +1 -1
  16. package/dist/fields/config/sanitize.d.ts.map +1 -1
  17. package/dist/fields/config/sanitize.js +0 -19
  18. package/dist/fields/config/sanitize.js.map +1 -1
  19. package/dist/fields/hooks/afterChange/promise.js +4 -4
  20. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  21. package/dist/fields/hooks/beforeChange/index.d.ts +1 -3
  22. package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
  23. package/dist/fields/hooks/beforeChange/index.js +1 -3
  24. package/dist/fields/hooks/beforeChange/index.js.map +1 -1
  25. package/dist/fields/hooks/beforeChange/promise.d.ts +1 -2
  26. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  27. package/dist/fields/hooks/beforeChange/promise.js +2 -18
  28. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  29. package/dist/fields/hooks/beforeChange/traverseFields.d.ts +1 -2
  30. package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
  31. package/dist/fields/hooks/beforeChange/traverseFields.js +1 -2
  32. package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
  33. package/dist/fields/hooks/beforeDuplicate/index.d.ts +19 -0
  34. package/dist/fields/hooks/beforeDuplicate/index.d.ts.map +1 -0
  35. package/dist/fields/hooks/beforeDuplicate/index.js +25 -0
  36. package/dist/fields/hooks/beforeDuplicate/index.js.map +1 -0
  37. package/dist/fields/hooks/beforeDuplicate/promise.d.ts +18 -0
  38. package/dist/fields/hooks/beforeDuplicate/promise.d.ts.map +1 -0
  39. package/dist/fields/hooks/beforeDuplicate/promise.js +299 -0
  40. package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -0
  41. package/dist/fields/hooks/beforeDuplicate/runHook.d.ts +3 -0
  42. package/dist/fields/hooks/beforeDuplicate/runHook.d.ts.map +1 -0
  43. package/dist/fields/hooks/beforeDuplicate/runHook.js +6 -0
  44. package/dist/fields/hooks/beforeDuplicate/runHook.js.map +1 -0
  45. package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts +18 -0
  46. package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts.map +1 -0
  47. package/dist/fields/hooks/beforeDuplicate/traverseFields.js +21 -0
  48. package/dist/fields/hooks/beforeDuplicate/traverseFields.js.map +1 -0
  49. package/dist/types/index.d.ts +1 -0
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/dist/types/index.js.map +1 -1
  52. package/package.json +6 -6
  53. package/dist/fields/baseFields/baseBeforeDuplicateArrays.d.ts +0 -6
  54. package/dist/fields/baseFields/baseBeforeDuplicateArrays.d.ts.map +0 -1
  55. package/dist/fields/baseFields/baseBeforeDuplicateArrays.js +0 -15
  56. package/dist/fields/baseFields/baseBeforeDuplicateArrays.js.map +0 -1
  57. package/dist/fields/hooks/beforeChange/beforeDuplicate.d.ts +0 -3
  58. package/dist/fields/hooks/beforeChange/beforeDuplicate.d.ts.map +0 -1
  59. package/dist/fields/hooks/beforeChange/beforeDuplicate.js +0 -6
  60. package/dist/fields/hooks/beforeChange/beforeDuplicate.js.map +0 -1
@@ -14,7 +14,7 @@ export type GenericDescriptionProps = {
14
14
  readonly marginPlacement?: 'bottom' | 'top';
15
15
  };
16
16
  export type FieldDescriptionServerProps<TFieldServer extends Field = Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
17
- clientField?: TFieldClient;
17
+ clientField: TFieldClient;
18
18
  readonly field: TFieldServer;
19
19
  } & GenericDescriptionProps & Partial<ServerProps>;
20
20
  export type FieldDescriptionClientProps<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
@@ -1 +1 @@
1
- {"version":3,"file":"Description.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Description.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAA;AAE/C,MAAM,MAAM,+BAA+B,CACzC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAA;AAElE,MAAM,MAAM,+BAA+B,CACzC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,2BAA2B,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA;AAEhF,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;AAE/D,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,iBAAiB,CAAA;AAEjE,MAAM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C5E,KAAK,CAAC,aAAa,CAAC,2BAA2B,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA;AAEhF,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;AAE/D,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,iBAAiB,CAAA;AAEjE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAA;IACtC,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAA;IACxC,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CAC5C,CAAA;AAED,MAAM,MAAM,2BAA2B,CACrC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,WAAW,EAAE,YAAY,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAC7B,GAAG,uBAAuB,GACzB,OAAO,CAAC,WAAW,CAAC,CAAA;AAEtB,MAAM,MAAM,2BAA2B,CACrC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,uBAAuB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Description.ts"],"sourcesContent":["import type { LabelFunction, ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type DescriptionFunction = LabelFunction\n\nexport type FieldDescriptionClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionClientProps<TFieldClient>>\n\nexport type FieldDescriptionServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionServerProps<TFieldServer, TFieldClient>>\n\nexport type StaticDescription = Record<string, string> | string\n\nexport type Description = DescriptionFunction | StaticDescription\n\nexport type GenericDescriptionProps = {\n readonly className?: string\n readonly Description?: MappedComponent\n readonly description?: StaticDescription\n readonly marginPlacement?: 'bottom' | 'top'\n}\n\nexport type FieldDescriptionServerProps<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField?: TFieldClient\n readonly field: TFieldServer\n} & GenericDescriptionProps &\n Partial<ServerProps>\n\nexport type FieldDescriptionClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericDescriptionProps\n"],"names":[],"mappings":"AAoCA,WAI2B"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Description.ts"],"sourcesContent":["import type { LabelFunction, ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type DescriptionFunction = LabelFunction\n\nexport type FieldDescriptionClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionClientProps<TFieldClient>>\n\nexport type FieldDescriptionServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionServerProps<TFieldServer, TFieldClient>>\n\nexport type StaticDescription = Record<string, string> | string\n\nexport type Description = DescriptionFunction | StaticDescription\n\nexport type GenericDescriptionProps = {\n readonly className?: string\n readonly Description?: MappedComponent\n readonly description?: StaticDescription\n readonly marginPlacement?: 'bottom' | 'top'\n}\n\nexport type FieldDescriptionServerProps<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericDescriptionProps &\n Partial<ServerProps>\n\nexport type FieldDescriptionClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericDescriptionProps\n"],"names":[],"mappings":"AAoCA,WAI2B"}
@@ -13,7 +13,7 @@ export type FieldErrorClientProps<TFieldClient extends ClientFieldWithOptionalTy
13
13
  field: TFieldClient;
14
14
  } & GenericErrorProps;
15
15
  export type FieldErrorServerProps<TFieldServer extends Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
16
- clientField?: TFieldClient;
16
+ clientField: TFieldClient;
17
17
  readonly field: TFieldServer;
18
18
  } & GenericErrorProps & Partial<ServerProps>;
19
19
  export type FieldErrorClientComponent<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldErrorClientProps<TFieldClient>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IACjD,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAA;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAA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,CAAA;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,iBAAiB,CAAA;AAErB,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,KAAK,EAC1B,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,WAAW,EAAE,YAAY,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAC7B,GAAG,iBAAiB,GACnB,OAAO,CAAC,WAAW,CAAC,CAAA;AAEtB,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAA;AAE5D,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Error.ts"],"sourcesContent":["import type { ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericErrorProps = {\n readonly alignCaret?: 'center' | 'left' | 'right'\n readonly CustomError?: MappedComponent\n readonly message?: string\n readonly path?: string\n readonly showError?: boolean\n}\n\nexport type FieldErrorClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericErrorProps\n\nexport type FieldErrorServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField?: TFieldClient\n readonly field: TFieldServer\n} & GenericErrorProps &\n Partial<ServerProps>\n\nexport type FieldErrorClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorClientProps<TFieldClient>>\n\nexport type FieldErrorServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAgCA,WAG0E"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Error.ts"],"sourcesContent":["import type { ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericErrorProps = {\n readonly alignCaret?: 'center' | 'left' | 'right'\n readonly CustomError?: MappedComponent\n readonly message?: string\n readonly path?: string\n readonly showError?: boolean\n}\n\nexport type FieldErrorClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericErrorProps\n\nexport type FieldErrorServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericErrorProps &\n Partial<ServerProps>\n\nexport type FieldErrorClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorClientProps<TFieldClient>>\n\nexport type FieldErrorServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAgCA,WAG0E"}
@@ -1,5 +1,5 @@
1
1
  import type { ServerProps, StaticLabel } from '../../config/types.js';
2
- import type { ClientField, Field } from '../../fields/config/types.js';
2
+ import type { Field } from '../../fields/config/types.js';
3
3
  import type { MappedComponent } from '../types.js';
4
4
  import type { ClientFieldWithOptionalType } from './Field.js';
5
5
  export type GenericLabelProps = {
@@ -14,10 +14,10 @@ export type FieldLabelClientProps<TFieldClient extends ClientFieldWithOptionalTy
14
14
  field: TFieldClient;
15
15
  } & GenericLabelProps;
16
16
  export type FieldLabelServerProps<TFieldServer extends Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
17
- clientField?: TFieldClient;
17
+ clientField: TFieldClient;
18
18
  readonly field: TFieldServer;
19
19
  } & GenericLabelProps & Partial<ServerProps>;
20
- export type SanitizedLabelProps<TFieldClient extends ClientField> = Omit<FieldLabelClientProps<TFieldClient>, 'label' | 'required'>;
20
+ export type SanitizedLabelProps<TFieldClient extends ClientFieldWithOptionalType> = Omit<FieldLabelClientProps<TFieldClient>, 'label' | 'required'>;
21
21
  export type FieldLabelClientComponent<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldLabelClientProps<TFieldClient>>;
22
22
  export type FieldLabelServerComponent<TFieldServer extends Field = Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>;
23
23
  //# sourceMappingURL=Label.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,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AK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Label.ts"],"sourcesContent":["import type { ServerProps, StaticLabel } from '../../config/types.js'\nimport type { ClientField, Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericLabelProps = {\n readonly as?: 'label' | 'span'\n readonly htmlFor?: string\n readonly Label?: MappedComponent\n readonly label?: StaticLabel\n readonly required?: boolean\n readonly unstyled?: boolean\n}\n\nexport type FieldLabelClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericLabelProps\n\nexport type FieldLabelServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField?: TFieldClient\n readonly field: TFieldServer\n} & GenericLabelProps &\n Partial<ServerProps>\n\nexport type SanitizedLabelProps<TFieldClient extends ClientField> = Omit<\n FieldLabelClientProps<TFieldClient>,\n 'label' | 'required'\n>\n\nexport type FieldLabelClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelClientProps<TFieldClient>>\n\nexport type FieldLabelServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAsCA,WAG0E"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Label.ts"],"sourcesContent":["import type { ServerProps, StaticLabel } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { MappedComponent } from '../types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericLabelProps = {\n readonly as?: 'label' | 'span'\n readonly htmlFor?: string\n readonly Label?: MappedComponent\n readonly label?: StaticLabel\n readonly required?: boolean\n readonly unstyled?: boolean\n}\n\nexport type FieldLabelClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericLabelProps\n\nexport type FieldLabelServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericLabelProps &\n Partial<ServerProps>\n\nexport type SanitizedLabelProps<TFieldClient extends ClientFieldWithOptionalType> = Omit<\n FieldLabelClientProps<TFieldClient>,\n 'label' | 'required'\n>\n\nexport type FieldLabelClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelClientProps<TFieldClient>>\n\nexport type FieldLabelServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAsCA,WAG0E"}
@@ -1 +1 @@
1
- {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAiB5E,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,KAAK,SAAS,cAAc,gBACrD,SAAS,KACtB,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CA+SvC,CAAA"}
1
+ {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAkB5E,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,KAAK,SAAS,cAAc,gBACrD,SAAS,KACtB,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAuTvC,CAAA"}
@@ -6,6 +6,7 @@ import { APIError, Forbidden, NotFound } from '../../errors/index.js';
6
6
  import { afterChange } from '../../fields/hooks/afterChange/index.js';
7
7
  import { afterRead } from '../../fields/hooks/afterRead/index.js';
8
8
  import { beforeChange } from '../../fields/hooks/beforeChange/index.js';
9
+ import { beforeDuplicate } from '../../fields/hooks/beforeDuplicate/index.js';
9
10
  import { beforeValidate } from '../../fields/hooks/beforeValidate/index.js';
10
11
  import { commitTransaction } from '../../utilities/commitTransaction.js';
11
12
  import { initTransaction } from '../../utilities/initTransaction.js';
@@ -57,7 +58,7 @@ export const duplicateOperation = async (incomingArgs)=>{
57
58
  }
58
59
  }, accessResults)
59
60
  };
60
- const docWithLocales = await getLatestCollectionVersion({
61
+ let docWithLocales = await getLatestCollectionVersion({
61
62
  id,
62
63
  config: collectionConfig,
63
64
  payload,
@@ -73,6 +74,14 @@ export const duplicateOperation = async (incomingArgs)=>{
73
74
  // remove the createdAt timestamp and id to rely on the db to set the default it
74
75
  delete docWithLocales.createdAt;
75
76
  delete docWithLocales.id;
77
+ docWithLocales = await beforeDuplicate({
78
+ id,
79
+ collection: collectionConfig,
80
+ context: req.context,
81
+ doc: docWithLocales,
82
+ overrideAccess,
83
+ req
84
+ });
76
85
  // for version enabled collections, override the current status with draft, unless draft is explicitly set to false
77
86
  if (shouldSaveDraft) {
78
87
  docWithLocales._status = 'draft';
@@ -153,7 +162,6 @@ export const duplicateOperation = async (incomingArgs)=>{
153
162
  data,
154
163
  doc: originalDoc,
155
164
  docWithLocales,
156
- duplicate: true,
157
165
  global: null,
158
166
  operation,
159
167
  req,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const duplicateOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments,\n): Promise<DataFromCollectionSlug<TSlug>> => {\n let args = incomingArgs\n const operation = 'create'\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation,\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n draft: draftArg = true,\n overrideAccess,\n req: { fallbackLocale, locale: localeArg, payload },\n req,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to duplicate.', httpStatus.BAD_REQUEST)\n }\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Read Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.read)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale: req.locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and id to rely on the db to set the default it\n delete docWithLocales.createdAt\n delete docWithLocales.id\n\n // for version enabled collections, override the current status with draft, unless draft is explicitly set to false\n if (shouldSaveDraft) {\n docWithLocales._status = 'draft'\n }\n\n let result\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale: req.locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n // /////////////////////////////////////\n // Create Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data: originalDoc, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n let data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data: originalDoc,\n doc: originalDoc,\n duplicate: true,\n global: null,\n operation,\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n result = await beforeChange({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n docWithLocales,\n duplicate: true,\n global: null,\n operation,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // set req.locale back to the original locale\n req.locale = localeArg\n\n // /////////////////////////////////////\n // Create / Update\n // /////////////////////////////////////\n\n const versionDoc = await payload.db.create({\n collection: collectionConfig.slug,\n data: result,\n req,\n })\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id: versionDoc.id,\n collection: collectionConfig,\n docWithLocales: {\n ...versionDoc,\n createdAt: result.createdAt,\n },\n draft: shouldSaveDraft,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: versionDoc,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale: localeArg,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data: versionDoc,\n doc: result,\n global: null,\n operation,\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation,\n previousDoc: {},\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","duplicateOperation","incomingArgs","args","operation","shouldCommit","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","Promise","resolve","id","collectionConfig","depth","draft","draftArg","overrideAccess","fallbackLocale","locale","localeArg","payload","showHiddenFields","BAD_REQUEST","shouldSaveDraft","Boolean","versions","drafts","accessResults","access","read","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","createdAt","_status","result","originalDoc","doc","global","data","create","duplicate","skipValidation","validate","versionDoc","db","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAOpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,QAAQ,aAAY;AAYhD,OAAO,MAAMC,qBAAqB,OAChCC;IAEA,IAAIC,OAAOD;IACX,MAAME,YAAY;IAElB,IAAI;QACF,MAAMC,eAAe,MAAMT,gBAAgBO,KAAKG,GAAG;QAEnD,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMH,KAAKI,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WA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,WAAWC;YAC9D,MAAMD;YAENkC,SACE,AAAC,MAAMjC,KAAK;gBACVN,YAAYW;gBACZJ,SAASR,IAAIQ,OAAO;gBACpBkC,KAAKF;gBACLxC;YACF,MAAOwC;QACX,GAAG/B,QAAQC,OAAO;QAElB,wCAAwC;QACxC,uBAAuB;QACvB,wCAAwC;QAExC8B,SAAS,MAAMvD,YAAY;YACzBgB,YAAYW;YACZJ,SAASR,IAAIQ,OAAO;YACpBoC,MAAMK;YACNP,KAAKF;YACLG,QAAQ;YACR7C;YACAqD,aAAa,CAAC;YACdnD;QACF;QAEA,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,MAAMY,iBAAiBT,KAAK,CAAClB,WAAW,CAACoB,MAAM,CAAC,OAAOC,WAAWC;YAChE,MAAMD;YAENkC,SACE,AAAC,MAAMjC,KAAK;gBACVN,YAAYW;gBACZJ,SAASR,IAAIQ,OAAO;gBACpBkC,KAAKF;gBACL1C;gBACAqD,aAAa,CAAC;gBACdnD;YACF,MAAOwC;QACX,GAAG/B,QAAQC,OAAO;QAElB,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC8B,SAAS,MAAM9C,oBAAoB;YACjCG;YACAI,YAAYW;YACZd;YACA0C;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIzC,cAAc;YAChB,MAAMV,kBAAkBW;QAC1B;QAEA,OAAOwC;IACT,EAAE,OAAOY,OAAgB;QACvB,MAAM7D,gBAAgBM,KAAKG,GAAG;QAC9B,MAAMoD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeDuplicate } from '../../fields/hooks/beforeDuplicate/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const duplicateOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments,\n): Promise<DataFromCollectionSlug<TSlug>> => {\n let args = incomingArgs\n const operation = 'create'\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation,\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n draft: draftArg = true,\n overrideAccess,\n req: { fallbackLocale, locale: localeArg, payload },\n req,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to duplicate.', httpStatus.BAD_REQUEST)\n }\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Read Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.read)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale: req.locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n let docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and id to rely on the db to set the default it\n delete docWithLocales.createdAt\n delete docWithLocales.id\n\n docWithLocales = await beforeDuplicate({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: docWithLocales,\n overrideAccess,\n req,\n })\n\n // for version enabled collections, override the current status with draft, unless draft is explicitly set to false\n if (shouldSaveDraft) {\n docWithLocales._status = 'draft'\n }\n\n let result\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale: req.locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n // /////////////////////////////////////\n // Create Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data: originalDoc, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n let data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data: originalDoc,\n doc: originalDoc,\n duplicate: true,\n global: null,\n operation,\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n result = await beforeChange({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n docWithLocales,\n global: null,\n operation,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // set req.locale back to the original locale\n req.locale = localeArg\n\n // /////////////////////////////////////\n // Create / Update\n // /////////////////////////////////////\n\n const versionDoc = await payload.db.create({\n collection: collectionConfig.slug,\n data: result,\n req,\n })\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id: versionDoc.id,\n collection: collectionConfig,\n docWithLocales: {\n ...versionDoc,\n createdAt: result.createdAt,\n },\n draft: shouldSaveDraft,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: versionDoc,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale: localeArg,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data: versionDoc,\n doc: result,\n global: null,\n operation,\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation,\n previousDoc: {},\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeDuplicate","beforeValidate","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","duplicateOperation","incomingArgs","args","operation","shouldCommit","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","Promise","resolve","id","collectionConfig","depth","draft","draftArg","overrideAccess","fallbackLocale","locale","localeArg","payload","showHiddenFields","BAD_REQUEST","shouldSaveDraft","Boolean","versions","drafts","accessResults","access","read","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","createdAt","doc","_status","result","originalDoc","global","data","create","duplicate","skipValidation","validate","versionDoc","db","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAOpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,eAAe,QAAQ,8CAA6C;AAC7E,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AC;gBACdnD;YACF,MAAOyC;QACX,GAAGhC,QAAQC,OAAO;QAElB,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC+B,SAAS,MAAM/C,oBAAoB;YACjCG;YACAI,YAAYW;YACZd;YACA2C;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAI1C,cAAc;YAChB,MAAMV,kBAAkBW;QAC1B;QAEA,OAAOyC;IACT,EAAE,OAAOW,OAAgB;QACvB,MAAM7D,gBAAgBM,KAAKG,GAAG;QAC9B,MAAMoD;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"baseIDField.d.ts","sourceRoot":"","sources":["../../../src/fields/baseFields/baseIDField.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,eAAO,MAAM,WAAW,EAAE,SAsBzB,CAAA"}
1
+ {"version":3,"file":"baseIDField.d.ts","sourceRoot":"","sources":["../../../src/fields/baseFields/baseIDField.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,eAAO,MAAM,WAAW,EAAE,SA2BzB,CAAA"}
@@ -18,6 +18,11 @@ export const baseIDField = {
18
18
  }
19
19
  return value;
20
20
  }
21
+ ],
22
+ beforeDuplicate: [
23
+ ()=>{
24
+ return new ObjectId().toHexString();
25
+ }
21
26
  ]
22
27
  },
23
28
  label: 'ID'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/baseFields/baseIDField.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { TextField } from '../config/types.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nexport const baseIDField: TextField = {\n name: 'id',\n type: 'text',\n admin: {\n hidden: true,\n },\n defaultValue: () => new ObjectId().toHexString(),\n hooks: {\n beforeChange: [\n ({ operation, value }) => {\n // If creating new doc, need to disregard any\n // ids that have been passed in because they will cause\n // primary key unique conflicts in relational DBs\n if (!value || (operation === 'create' && value)) {\n return new ObjectId().toHexString()\n }\n\n return value\n },\n ],\n },\n label: 'ID',\n}\n"],"names":["ObjectIdImport","ObjectId","default","baseIDField","name","type","admin","hidden","defaultValue","toHexString","hooks","beforeChange","operation","value","label"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAI1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AAEF,OAAO,MAAMG,cAAyB;IACpCC,MAAM;IACNC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,cAAc,IAAM,IAAIP,WAAWQ,WAAW;IAC9CC,OAAO;QACLC,cAAc;YACZ,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;gBACnB,6CAA6C;gBAC7C,uDAAuD;gBACvD,iDAAiD;gBACjD,IAAI,CAACA,SAAUD,cAAc,YAAYC,OAAQ;oBAC/C,OAAO,IAAIZ,WAAWQ,WAAW;gBACnC;gBAEA,OAAOI;YACT;SACD;IACH;IACAC,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/baseFields/baseIDField.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { TextField } from '../config/types.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nexport const baseIDField: TextField = {\n name: 'id',\n type: 'text',\n admin: {\n hidden: true,\n },\n defaultValue: () => new ObjectId().toHexString(),\n hooks: {\n beforeChange: [\n ({ operation, value }) => {\n // If creating new doc, need to disregard any\n // ids that have been passed in because they will cause\n // primary key unique conflicts in relational DBs\n if (!value || (operation === 'create' && value)) {\n return new ObjectId().toHexString()\n }\n\n return value\n },\n ],\n beforeDuplicate: [\n () => {\n return new ObjectId().toHexString()\n },\n ],\n },\n label: 'ID',\n}\n"],"names":["ObjectIdImport","ObjectId","default","baseIDField","name","type","admin","hidden","defaultValue","toHexString","hooks","beforeChange","operation","value","beforeDuplicate","label"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAI1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AAEF,OAAO,MAAMG,cAAyB;IACpCC,MAAM;IACNC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,cAAc,IAAM,IAAIP,WAAWQ,WAAW;IAC9CC,OAAO;QACLC,cAAc;YACZ,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;gBACnB,6CAA6C;gBAC7C,uDAAuD;gBACvD,iDAAiD;gBACjD,IAAI,CAACA,SAAUD,cAAc,YAAYC,OAAQ;oBAC/C,OAAO,IAAIZ,WAAWQ,WAAW;gBACnC;gBAEA,OAAOI;YACT;SACD;QACDC,iBAAiB;YACf;gBACE,OAAO,IAAIb,WAAWQ,WAAW;YACnC;SACD;IACH;IACAM,OAAO;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAiBvC,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IAEzC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChF;;;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,oKASxB,IAAI,KAAG,OAAO,CAAC,KAAK,EAAE,CA4OxB,CAAA"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAgBvC,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IAEzC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChF;;;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,oKASxB,IAAI,KAAG,OAAO,CAAC,KAAK,EAAE,CA0NxB,CAAA"}
@@ -2,7 +2,6 @@ import { deepMergeSimple } from '@payloadcms/translations/utilities';
2
2
  import { DuplicateFieldName, InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
3
3
  import { MissingEditorProp } from '../../errors/MissingEditorProp.js';
4
4
  import { formatLabels, toWords } from '../../utilities/formatLabels.js';
5
- import { baseBeforeDuplicateArrays } from '../baseFields/baseBeforeDuplicateArrays.js';
6
5
  import { baseBlockFields } from '../baseFields/baseBlockFields.js';
7
6
  import { baseIDField } from '../baseFields/baseIDField.js';
8
7
  import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
@@ -61,15 +60,6 @@ export const sanitizeFields = async ({ collectionConfig, config, existingFieldNa
61
60
  }
62
61
  if (field.type === 'array' && field.fields) {
63
62
  field.fields.push(baseIDField);
64
- if (field.localized) {
65
- if (!field.hooks) {
66
- field.hooks = {};
67
- }
68
- if (!field.hooks.beforeDuplicate) {
69
- field.hooks.beforeDuplicate = [];
70
- }
71
- field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays);
72
- }
73
63
  }
74
64
  if ((field.type === 'blocks' || field.type === 'array') && field.label) {
75
65
  field.labels = field.labels || formatLabels(field.name);
@@ -144,15 +134,6 @@ export const sanitizeFields = async ({ collectionConfig, config, existingFieldNa
144
134
  }
145
135
  }
146
136
  if (field.type === 'blocks' && field.blocks) {
147
- if (field.localized) {
148
- if (!field.hooks) {
149
- field.hooks = {};
150
- }
151
- if (!field.hooks.beforeDuplicate) {
152
- field.hooks.beforeDuplicate = [];
153
- }
154
- field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays);
155
- }
156
137
  for (const block of field.blocks){
157
138
  if (block._sanitized === true) {
158
139
  continue;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBeforeDuplicateArrays } from '../baseFields/baseBeforeDuplicateArrays.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n if (field.localized) {\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.hooks.beforeDuplicate) {\n field.hooks.beforeDuplicate = []\n }\n field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays)\n }\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n if (field.localized) {\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.hooks.beforeDuplicate) {\n field.hooks.beforeDuplicate = []\n }\n field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays)\n }\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","MissingEditorProp","formatLabels","toWords","baseBeforeDuplicateArrays","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","localized","hooks","beforeDuplicate","labels","has","add","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,yBAAyB,QAAQ,6CAA4C;AACtF,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,OAAOC,iBAAiB,oBAAmB;AAC3C,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AA2BzD,OAAO,MAAMC,iBAAi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UAAU,GAAG;QACrB;QAEAR,MAAM,CAACK,EAAE,GAAGE;IACd;IAEA,OAAOP;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","MissingEditorProp","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AA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C,oBAAoBL,iBAAiBc,SAAS,IAAIR,QAAQD;gBAC1DE,QAAQO,MAAMP,MAAM;gBACpBC,mBAAmBA,qBAAqBM,MAAM0B,SAAS;gBACvD/B;gBACAC;gBACAC;YACF;QACF;QAEA,IAAIG,MAAME,IAAI,KAAK,QAAQ;YACzB,IAAK,IAAI+C,IAAI,GAAGA,IAAIjD,MAAMkD,IAAI,CAACnD,MAAM,EAAEkD,IAAK;gBAC1C,MAAME,MAAMnD,MAAMkD,IAAI,CAACD,EAAE;gBACzB,IAAI9D,WAAWgE,QAAQ,OAAOA,IAAI9C,KAAK,KAAK,aAAa;oBACvD8C,IAAI9C,KAAK,GAAGxB,QAAQsE,IAAIhD,IAAI;gBAC9B;gBAEAgD,IAAI1D,MAAM,GAAG,MAAML,eAAe;oBAChCE;oBACAC,oBAAoBJ,WAAWgE,OAAO,IAAI3D,QAAQD;oBAClDE,QAAQ0D,IAAI1D,MAAM;oBAClBC,mBAAmBA,qBAAsBP,WAAWgE,QAAQA,IAAIzB,SAAS;oBACzE/B;oBACAC;oBACAC;gBACF;gBACAG,MAAMkD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,gBAAgBnD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAR,MAAM,CAACK,EAAE,GAAGE;IACd;IAEA,OAAOP;AACT,EAAC"}
@@ -83,9 +83,9 @@ export const promise = async ({ collection, context, data, doc, field, global, o
83
83
  req,
84
84
  schemaPath: fieldSchemaPath,
85
85
  siblingData: siblingData?.[field.name]?.[i] || {},
86
- siblingDoc: {
86
+ siblingDoc: row ? {
87
87
  ...row
88
- } || {}
88
+ } : {}
89
89
  }));
90
90
  });
91
91
  await Promise.all(promises);
@@ -117,9 +117,9 @@ export const promise = async ({ collection, context, data, doc, field, global, o
117
117
  req,
118
118
  schemaPath: fieldSchemaPath,
119
119
  siblingData: siblingData?.[field.name]?.[i] || {},
120
- siblingDoc: {
120
+ siblingDoc: row ? {
121
121
  ...row
122
- } || {}
122
+ } : {}
123
123
  }));
124
124
  }
125
125
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterChange/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n field: Field | TabAsField\n global: null | SanitizedGlobalConfig\n operation: 'create' | 'update'\n /**\n * The parent's path\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n previousDoc: JsonObject\n previousSiblingDoc: JsonObject\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n}\n\n// This function is responsible for the following actions, in order:\n// - Execute field hooks\n\nexport const promise = async ({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n parentPath,\n parentSchemaPath,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (field.hooks?.afterChange) {\n await field.hooks.afterChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n }\n\n // Traverse subfields\n switch (field.type) {\n case 'group': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: previousDoc[field.name] as JsonObject,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: (siblingData?.[field.name] as JsonObject) || {},\n siblingDoc: siblingDoc[field.name] as JsonObject,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as JsonObject),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: ({ ...(row as JsonObject) } as JsonObject) || {},\n }),\n )\n })\n await Promise.all(promises)\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n if (block) {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: block.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as JsonObject),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: ({ ...(row as JsonObject) } as JsonObject) || {},\n }),\n )\n }\n })\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabPreviousSiblingDoc = siblingDoc\n\n if (tabHasName(field)) {\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabPreviousSiblingDoc = previousDoc[field.name] as JsonObject\n }\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: tabPreviousSiblingDoc,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\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\n if (editor?.hooks?.afterChange?.length) {\n await editor.hooks.afterChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getFieldPaths","traverseFields","promise","collection","context","data","doc","field","global","operation","parentPath","parentSchemaPath","previousDoc","previousSiblingDoc","req","siblingData","siblingDoc","path","fieldPath","schemaPath","fieldSchemaPath","hooks","afterChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousValue","name","value","undefined","Promise","resolve","type","fields","rows","Array","isArray","promises","forEach","row","i","push","all","block","blocks","find","blockType","slug","tabSiblingData","tabSiblingDoc","tabPreviousSiblingDoc","tabs","map","tab","editor","Error","length"],"mappings":"AAMA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,cAAc,QAAQ,sBAAqB;AAyBpD,oEAAoE;AACpE,wBAAwB;AAExB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,WAAW,EACXC,kBAAkB,EAClBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACL;IACL,MAAM,EAAEC,MAAMC,SAAS,EAAEC,YAAYC,eAAe,EAAE,GAAGpB,cAAc;QACrEO;QACAG;QACAC;IACF;IAEA,IAAIb,iBAAiBS,QAAQ;QAC3B,gBAAgB;QAChB,IAAIA,MAAMc,KAAK,EAAEC,aAAa;YAC5B,MAAMf,MAAMc,KAAK,CAACC,WAAW,CAACC,MAAM,CAAC,OAAOC,WAAWC;gBACrD,MAAMD;gBAEN,MAAME,cAAc,MAAMD,YAAY;oBACpCtB;oBACAC;oBACAC;oBACAE;oBACAC;oBACAC;oBACAkB,aAAarB;oBACbW,MAAMC;oBACNN;oBACAC;oBACAe,eAAehB,WAAW,CAACL,MAAMsB,IAAI,CAAC;oBACtCf;oBACAK,YAA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ACNN;4BACAC;4BACAe,eAAehB,WAAW,CAACL,MAAMsB,IAAI,CAAC;4BACtCf;4BACAK,YAAYC;4BACZL;4BACAe,OAAOd,UAAU,CAACT,MAAMsB,IAAI,CAAC;wBAC/B;wBAEA,IAAIH,gBAAgBK,WAAW;4BAC7Bf,UAAU,CAACT,MAAMsB,IAAI,CAAC,GAAGH;wBAC3B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterChange/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n field: Field | TabAsField\n global: null | SanitizedGlobalConfig\n operation: 'create' | 'update'\n /**\n * The parent's path\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n previousDoc: JsonObject\n previousSiblingDoc: JsonObject\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n}\n\n// This function is responsible for the following actions, in order:\n// - Execute field hooks\n\nexport const promise = async ({\n collection,\n context,\n data,\n doc,\n field,\n global,\n operation,\n parentPath,\n parentSchemaPath,\n previousDoc,\n previousSiblingDoc,\n req,\n siblingData,\n siblingDoc,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (field.hooks?.afterChange) {\n await field.hooks.afterChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n }\n\n // Traverse subfields\n switch (field.type) {\n case 'group': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: previousDoc[field.name] as JsonObject,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: (siblingData?.[field.name] as JsonObject) || {},\n siblingDoc: siblingDoc[field.name] as JsonObject,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as JsonObject),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: row ? { ...row } : {},\n }),\n )\n })\n await Promise.all(promises)\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n if (block) {\n promises.push(\n traverseFields({\n collection,\n context,\n data,\n doc,\n fields: block.fields,\n global,\n operation,\n path: [...fieldPath, i],\n previousDoc,\n previousSiblingDoc: previousDoc?.[field.name]?.[i] || ({} as JsonObject),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: row ? { ...row } : {},\n }),\n )\n }\n })\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabPreviousSiblingDoc = siblingDoc\n\n if (tabHasName(field)) {\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabPreviousSiblingDoc = previousDoc[field.name] as JsonObject\n }\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.fields,\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: tabPreviousSiblingDoc,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n operation,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc: { ...previousSiblingDoc },\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData || {},\n siblingDoc: { ...siblingDoc },\n })\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\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\n if (editor?.hooks?.afterChange?.length) {\n await editor.hooks.afterChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousDoc,\n previousSiblingDoc,\n previousValue: previousDoc[field.name],\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getFieldPaths","traverseFields","promise","collection","context","data","doc","field","global","operation","parentPath","parentSchemaPath","previousDoc","previousSiblingDoc","req","siblingData","siblingDoc","path","fieldPath","schemaPath","fieldSchemaPath","hooks","afterChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousValue","name","value","undefined","Promise","resolve","type","fields","rows","Array","isArray","promises","forEach","row","i","push","all","block","blocks","find","blockType","slug","tabSiblingData","tabSiblingDoc","tabPreviousSiblingDoc","tabs","map","tab","editor","Error","length"],"mappings":"AAMA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,cAAc,QAAQ,sBAAqB;AAyBpD,oEAAoE;AACpE,wBAAwB;AAExB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,WAAW,EACXC,kBAAkB,EAClBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACL;IACL,MAAM,EAAEC,MAAMC,SAAS,EAAEC,YAAYC,eAAe,EAAE,GAAGpB,cAAc;QACrEO;QACAG;QACAC;IACF;IAEA,IAAIb,iBAAiBS,QAAQ;QAC3B,gBAAgB;QAChB,IAAIA,MAAMc,KAAK,EAAEC,aAAa;YAC5B,MAAMf,MAAMc,KAAK,CAACC,WAAW,CAACC,MAAM,C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OC,aAAaoC,QAAQ;oBACtC,MAAMF,OAAOnC,KAAK,CAACC,WAAW,CAACC,MAAM,CAAC,OAAOC,WAAWC;wBACtD,MAAMD;wBAEN,MAAME,cAAc,MAAMD,YAAY;4BACpCtB;4BACAC;4BACAC;4BACAE;4BACAC;4BACAC;4BACAkB,aAAarB;4BACbW,MAAMC;4BACNN;4BACAC;4BACAe,eAAehB,WAAW,CAACL,MAAMsB,IAAI,CAAC;4BACtCf;4BACAK,YAAYC;4BACZL;4BACAe,OAAOd,UAAU,CAACT,MAAMsB,IAAI,CAAC;wBAC/B;wBAEA,IAAIH,gBAAgBK,WAAW;4BAC7Bf,UAAU,CAACT,MAAMsB,IAAI,CAAC,GAAGH;wBAC3B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
@@ -7,7 +7,6 @@ type Args<T extends JsonObject> = {
7
7
  data: T;
8
8
  doc: T;
9
9
  docWithLocales: JsonObject;
10
- duplicate?: boolean;
11
10
  global: null | SanitizedGlobalConfig;
12
11
  id?: number | string;
13
12
  operation: Operation;
@@ -20,9 +19,8 @@ type Args<T extends JsonObject> = {
20
19
  * - Execute field hooks
21
20
  * - Validate data
22
21
  * - Transform data for storage
23
- * - beforeDuplicate hooks (if duplicate)
24
22
  * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
25
23
  */
26
- export declare const beforeChange: <T extends JsonObject>({ id, collection, context, data: incomingData, doc, docWithLocales, duplicate, global, operation, req, skipValidation, }: Args<T>) => Promise<T>;
24
+ export declare const beforeChange: <T extends JsonObject>({ id, collection, context, data: incomingData, doc, docWithLocales, global, operation, req, skipValidation, }: Args<T>) => Promise<T>;
27
25
  export {};
28
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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;IACP,GAAG,EAAE,CAAC,CAAA;IACN,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,SAAS,UAAU,iHAWpD,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CA4CrB,CAAA"}
@@ -7,9 +7,8 @@ import { traverseFields } from './traverseFields.js';
7
7
  * - Execute field hooks
8
8
  * - Validate data
9
9
  * - Transform data for storage
10
- * - beforeDuplicate hooks (if duplicate)
11
10
  * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
12
- */ export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales, duplicate = false, global, operation, req, skipValidation })=>{
11
+ */ export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales, global, operation, req, skipValidation })=>{
13
12
  const data = deepCopyObjectSimple(incomingData);
14
13
  const mergeLocaleActions = [];
15
14
  const errors = [];
@@ -20,7 +19,6 @@ import { traverseFields } from './traverseFields.js';
20
19
  data,
21
20
  doc,
22
21
  docWithLocales,
23
- duplicate,
24
22
  errors,
25
23
  fields: collection?.fields || global?.fields,
26
24
  global,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: T\n doc: T\n docWithLocales: JsonObject\n duplicate?: boolean\n global: null | SanitizedGlobalConfig\n id?: number | string\n operation: Operation\n req: PayloadRequest\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - beforeDuplicate hooks (if duplicate)\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const beforeChange = async <T extends JsonObject>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n duplicate = false,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObjectSimple(incomingData)\n const mergeLocaleActions = []\n const errors: { field: string; message: string }[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(\n {\n id,\n collection: collection?.slug,\n errors,\n global: global?.slug,\n },\n req.t,\n )\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObjectSimple","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","duplicate","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","slug","t","reduce","priorAction","action","Promise","resolve"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAgBpD;;;;;;;;CAQC,GACD,OAAO,MAAMC,eAAe,OAA6B,EACvDC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,YAAY,KAAK,EACjBC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMR,OAAON,qBAAqBO;IAClC,MAAMQ,qBAAqB,EAAE;IAC7B,MAAMC,SAA+C,EAAE;IAEvD,MAAMf,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAC;QACAM;QACAC,QAAQb,YAAYa,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAad;QACbe,YAAYb;QACZc,uBAAuBb;QACvBK;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIxB,gBACR;YACEI;YACAC,YAAYA,YAAYoB;YACxBR;YACAL,QAAQA,QAAQa;QAClB,GACAX,IAAIY,CAAC;IAET;IAEA,MAAMV,mBAAmBW,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOxB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: T\n doc: T\n docWithLocales: JsonObject\n global: null | SanitizedGlobalConfig\n id?: number | string\n operation: Operation\n req: PayloadRequest\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const beforeChange = async <T extends JsonObject>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObjectSimple(incomingData)\n const mergeLocaleActions = []\n const errors: { field: string; message: string }[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(\n {\n id,\n collection: collection?.slug,\n errors,\n global: global?.slug,\n },\n req.t,\n )\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObjectSimple","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","slug","t","reduce","priorAction","action","Promise","resolve"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAepD;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAe,OAA6B,EACvDC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMP,OAAON,qBAAqBO;IAClC,MAAMO,qBAAqB,EAAE;IAC7B,MAAMC,SAA+C,EAAE;IAEvD,MAAMd,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAM;QACAC,QAAQZ,YAAYY,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAab;QACbc,YAAYZ;QACZa,uBAAuBZ;QACvBI;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIvB,gBACR;YACEI;YACAC,YAAYA,YAAYmB;YACxBR;YACAL,QAAQA,QAAQa;QAClB,GACAX,IAAIY,CAAC;IAET;IAEA,MAAMV,mBAAmBW,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOvB;AACT,EAAC"}