payload 3.0.0-beta.67 → 3.0.0-beta.68

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 (223) hide show
  1. package/dist/admin/RichText.d.ts +4 -4
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/auth/operations/resetPassword.js +1 -1
  5. package/dist/auth/operations/resetPassword.js.map +1 -1
  6. package/dist/auth/strategies/jwt.d.ts.map +1 -1
  7. package/dist/auth/strategies/jwt.js +29 -0
  8. package/dist/auth/strategies/jwt.js.map +1 -1
  9. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
  10. package/dist/auth/strategies/local/incrementLoginAttempts.js +1 -1
  11. package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
  12. package/dist/auth/strategies/local/register.d.ts +2 -2
  13. package/dist/auth/strategies/local/register.d.ts.map +1 -1
  14. package/dist/auth/strategies/local/register.js.map +1 -1
  15. package/dist/bin/generateTypes.js +2 -2
  16. package/dist/bin/generateTypes.js.map +1 -1
  17. package/dist/collections/config/client.d.ts.map +1 -1
  18. package/dist/collections/config/defaults.d.ts +4 -69
  19. package/dist/collections/config/defaults.d.ts.map +1 -1
  20. package/dist/collections/config/defaults.js.map +1 -1
  21. package/dist/collections/config/reservedFieldNames.d.ts +15 -0
  22. package/dist/collections/config/reservedFieldNames.d.ts.map +1 -0
  23. package/dist/collections/config/reservedFieldNames.js +104 -0
  24. package/dist/collections/config/reservedFieldNames.js.map +1 -0
  25. package/dist/collections/config/reservedFieldNames.spec.js +148 -0
  26. package/dist/collections/config/reservedFieldNames.spec.js.map +1 -0
  27. package/dist/collections/config/sanitize.d.ts.map +1 -1
  28. package/dist/collections/config/sanitize.js +13 -9
  29. package/dist/collections/config/sanitize.js.map +1 -1
  30. package/dist/collections/config/types.d.ts +2 -2
  31. package/dist/collections/config/types.d.ts.map +1 -1
  32. package/dist/collections/config/types.js.map +1 -1
  33. package/dist/collections/dataloader.d.ts.map +1 -1
  34. package/dist/collections/dataloader.js.map +1 -1
  35. package/dist/collections/operations/create.d.ts.map +1 -1
  36. package/dist/collections/operations/create.js.map +1 -1
  37. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  38. package/dist/collections/operations/deleteByID.js.map +1 -1
  39. package/dist/collections/operations/duplicate.js.map +1 -1
  40. package/dist/collections/operations/update.js.map +1 -1
  41. package/dist/collections/operations/updateByID.js.map +1 -1
  42. package/dist/config/client.d.ts.map +1 -1
  43. package/dist/config/client.js +26 -26
  44. package/dist/config/client.js.map +1 -1
  45. package/dist/config/sanitize.d.ts.map +1 -1
  46. package/dist/config/sanitize.js +4 -7
  47. package/dist/config/sanitize.js.map +1 -1
  48. package/dist/config/types.d.ts +3 -4
  49. package/dist/config/types.d.ts.map +1 -1
  50. package/dist/config/types.js.map +1 -1
  51. package/dist/errors/APIError.d.ts +1 -0
  52. package/dist/errors/APIError.d.ts.map +1 -1
  53. package/dist/errors/APIError.js +3 -0
  54. package/dist/errors/APIError.js.map +1 -1
  55. package/dist/errors/ValidationError.d.ts +1 -0
  56. package/dist/errors/ValidationError.d.ts.map +1 -1
  57. package/dist/errors/ValidationError.js +3 -0
  58. package/dist/errors/ValidationError.js.map +1 -1
  59. package/dist/errors/index.d.ts +2 -2
  60. package/dist/errors/index.d.ts.map +1 -1
  61. package/dist/errors/index.js +2 -2
  62. package/dist/errors/index.js.map +1 -1
  63. package/dist/exports/shared.d.ts +3 -2
  64. package/dist/exports/shared.d.ts.map +1 -1
  65. package/dist/exports/shared.js +3 -2
  66. package/dist/exports/shared.js.map +1 -1
  67. package/dist/fields/config/sanitize.d.ts +3 -2
  68. package/dist/fields/config/sanitize.d.ts.map +1 -1
  69. package/dist/fields/config/sanitize.js +8 -16
  70. package/dist/fields/config/sanitize.js.map +1 -1
  71. package/dist/fields/config/sanitize.spec.js +1 -17
  72. package/dist/fields/config/sanitize.spec.js.map +1 -1
  73. package/dist/fields/getDefaultValue.d.ts +5 -5
  74. package/dist/fields/getDefaultValue.d.ts.map +1 -1
  75. package/dist/fields/getDefaultValue.js +4 -6
  76. package/dist/fields/getDefaultValue.js.map +1 -1
  77. package/dist/fields/hooks/afterChange/index.d.ts +6 -6
  78. package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
  79. package/dist/fields/hooks/afterChange/index.js +2 -2
  80. package/dist/fields/hooks/afterChange/index.js.map +1 -1
  81. package/dist/fields/hooks/afterChange/promise.d.ts +7 -7
  82. package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
  83. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  84. package/dist/fields/hooks/afterChange/traverseFields.d.ts +7 -7
  85. package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
  86. package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
  87. package/dist/fields/hooks/afterRead/index.d.ts +4 -4
  88. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
  89. package/dist/fields/hooks/afterRead/index.js +2 -2
  90. package/dist/fields/hooks/afterRead/index.js.map +1 -1
  91. package/dist/fields/hooks/afterRead/promise.d.ts +3 -3
  92. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  93. package/dist/fields/hooks/afterRead/promise.js +2 -2
  94. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  95. package/dist/fields/hooks/afterRead/traverseFields.d.ts +3 -3
  96. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
  97. package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
  98. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts +2 -1
  99. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts.map +1 -1
  100. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js.map +1 -1
  101. package/dist/fields/hooks/beforeChange/getExistingRowDoc.d.ts +2 -1
  102. package/dist/fields/hooks/beforeChange/getExistingRowDoc.d.ts.map +1 -1
  103. package/dist/fields/hooks/beforeChange/getExistingRowDoc.js.map +1 -1
  104. package/dist/fields/hooks/beforeChange/index.d.ts +6 -6
  105. package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
  106. package/dist/fields/hooks/beforeChange/index.js +2 -2
  107. package/dist/fields/hooks/beforeChange/index.js.map +1 -1
  108. package/dist/fields/hooks/beforeChange/promise.d.ts +7 -7
  109. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  110. package/dist/fields/hooks/beforeChange/promise.js +3 -7
  111. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  112. package/dist/fields/hooks/beforeChange/traverseFields.d.ts +7 -7
  113. package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
  114. package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
  115. package/dist/fields/hooks/beforeValidate/index.d.ts +5 -5
  116. package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
  117. package/dist/fields/hooks/beforeValidate/index.js +2 -2
  118. package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
  119. package/dist/fields/hooks/beforeValidate/promise.d.ts +3 -3
  120. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  121. package/dist/fields/hooks/beforeValidate/promise.js +2 -2
  122. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  123. package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +3 -3
  124. package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
  125. package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
  126. package/dist/fields/mergeBaseFields.d.ts.map +1 -1
  127. package/dist/fields/mergeBaseFields.js +2 -2
  128. package/dist/fields/mergeBaseFields.js.map +1 -1
  129. package/dist/globals/operations/findOne.d.ts.map +1 -1
  130. package/dist/globals/operations/findOne.js.map +1 -1
  131. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  132. package/dist/globals/operations/findVersionByID.js +2 -1
  133. package/dist/globals/operations/findVersionByID.js.map +1 -1
  134. package/dist/globals/operations/findVersions.js.map +1 -1
  135. package/dist/globals/operations/update.d.ts.map +1 -1
  136. package/dist/globals/operations/update.js +2 -1
  137. package/dist/globals/operations/update.js.map +1 -1
  138. package/dist/index.d.ts +11 -10
  139. package/dist/index.d.ts.map +1 -1
  140. package/dist/index.js +8 -12
  141. package/dist/index.js.map +1 -1
  142. package/dist/types/index.d.ts +8 -2
  143. package/dist/types/index.d.ts.map +1 -1
  144. package/dist/types/index.js.map +1 -1
  145. package/dist/uploads/imageResizer.d.ts.map +1 -1
  146. package/dist/uploads/imageResizer.js +16 -18
  147. package/dist/uploads/imageResizer.js.map +1 -1
  148. package/dist/utilities/deepCopyObject.d.ts +18 -1
  149. package/dist/utilities/deepCopyObject.d.ts.map +1 -1
  150. package/dist/utilities/deepCopyObject.js +147 -16
  151. package/dist/utilities/deepCopyObject.js.map +1 -1
  152. package/dist/utilities/deepMerge.d.ts +18 -1
  153. package/dist/utilities/deepMerge.d.ts.map +1 -1
  154. package/dist/utilities/deepMerge.js +38 -13
  155. package/dist/utilities/deepMerge.js.map +1 -1
  156. package/dist/utilities/isPlainObject.d.ts +1 -1
  157. package/dist/utilities/isPlainObject.d.ts.map +1 -1
  158. package/dist/utilities/isPlainObject.js +4 -18
  159. package/dist/utilities/isPlainObject.js.map +1 -1
  160. package/dist/utilities/logger.d.ts +5 -7
  161. package/dist/utilities/logger.d.ts.map +1 -1
  162. package/dist/utilities/logger.js +4 -7
  163. package/dist/utilities/logger.js.map +1 -1
  164. package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
  165. package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
  166. package/dist/versions/baseFields.d.ts.map +1 -1
  167. package/dist/versions/baseFields.js +1 -0
  168. package/dist/versions/baseFields.js.map +1 -1
  169. package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
  170. package/dist/versions/drafts/replaceWithDraftIfAvailable.js +2 -1
  171. package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
  172. package/dist/versions/saveVersion.d.ts.map +1 -1
  173. package/dist/versions/saveVersion.js +2 -2
  174. package/dist/versions/saveVersion.js.map +1 -1
  175. package/package.json +5 -7
  176. package/dist/collections/config/schema.d.ts +0 -4
  177. package/dist/collections/config/schema.d.ts.map +0 -1
  178. package/dist/collections/config/schema.js +0 -191
  179. package/dist/collections/config/schema.js.map +0 -1
  180. package/dist/config/schema.d.ts +0 -5
  181. package/dist/config/schema.d.ts.map +0 -1
  182. package/dist/config/schema.js +0 -179
  183. package/dist/config/schema.js.map +0 -1
  184. package/dist/config/shared/adminViewSchema.d.ts +0 -3
  185. package/dist/config/shared/adminViewSchema.d.ts.map +0 -1
  186. package/dist/config/shared/adminViewSchema.js +0 -11
  187. package/dist/config/shared/adminViewSchema.js.map +0 -1
  188. package/dist/config/shared/componentSchema.d.ts +0 -16
  189. package/dist/config/shared/componentSchema.d.ts.map +0 -1
  190. package/dist/config/shared/componentSchema.js +0 -27
  191. package/dist/config/shared/componentSchema.js.map +0 -1
  192. package/dist/config/shared/openGraphSchema.d.ts +0 -3
  193. package/dist/config/shared/openGraphSchema.d.ts.map +0 -1
  194. package/dist/config/shared/openGraphSchema.js +0 -16
  195. package/dist/config/shared/openGraphSchema.js.map +0 -1
  196. package/dist/config/validate.d.ts +0 -4
  197. package/dist/config/validate.d.ts.map +0 -1
  198. package/dist/config/validate.js +0 -89
  199. package/dist/config/validate.js.map +0 -1
  200. package/dist/fields/config/schema.d.ts +0 -29
  201. package/dist/fields/config/schema.d.ts.map +0 -1
  202. package/dist/fields/config/schema.js +0 -508
  203. package/dist/fields/config/schema.js.map +0 -1
  204. package/dist/globals/config/schema.d.ts +0 -4
  205. package/dist/globals/config/schema.d.ts.map +0 -1
  206. package/dist/globals/config/schema.js +0 -79
  207. package/dist/globals/config/schema.js.map +0 -1
  208. package/dist/utilities/combineMerge.d.ts +0 -2
  209. package/dist/utilities/combineMerge.d.ts.map +0 -1
  210. package/dist/utilities/combineMerge.js +0 -16
  211. package/dist/utilities/combineMerge.js.map +0 -1
  212. package/dist/utilities/convertData.d.ts +0 -5
  213. package/dist/utilities/convertData.d.ts.map +0 -1
  214. package/dist/utilities/convertData.js +0 -16
  215. package/dist/utilities/convertData.js.map +0 -1
  216. package/dist/utilities/getCSSVariable.d.ts +0 -3
  217. package/dist/utilities/getCSSVariable.d.ts.map +0 -1
  218. package/dist/utilities/getCSSVariable.js +0 -3
  219. package/dist/utilities/getCSSVariable.js.map +0 -1
  220. package/dist/utilities/overwriteMerge.d.ts +0 -3
  221. package/dist/utilities/overwriteMerge.d.ts.map +0 -1
  222. package/dist/utilities/overwriteMerge.js +0 -4
  223. package/dist/utilities/overwriteMerge.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/exports/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,wBAAwB,GACzB,MAAM,2BAA2B,CAAA;AAElC,cAAc,0BAA0B,CAAA;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,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A;AAE/C,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EACL,SAAS,EACT,2BAA2B,EAC3B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,GACjC,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAE3C,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAEpF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA"}
@@ -5,8 +5,8 @@ export * from '../fields/validations.js';
5
5
  export { validOperators } from '../types/constants.js';
6
6
  export { formatFilesize } from '../uploads/formatFilesize.js';
7
7
  export { isImage } from '../uploads/isImage.js';
8
- export { deepCopyObject } from '../utilities/deepCopyObject.js';
9
- export { deepMerge } from '../utilities/deepMerge.js';
8
+ export { deepCopyObject, deepCopyObjectComplex, deepCopyObjectSimple } from '../utilities/deepCopyObject.js';
9
+ export { deepMerge, deepMergeWithCombinedArrays, deepMergeWithReactComponents, deepMergeWithSourceArrays } from '../utilities/deepMerge.js';
10
10
  export { fieldSchemaToJSON } from '../utilities/fieldSchemaToJSON.js';
11
11
  export { getDataByPath } from '../utilities/getDataByPath.js';
12
12
  export { getSiblingData } from '../utilities/getSiblingData.js';
@@ -19,5 +19,6 @@ export { default as toKebabCase } from '../utilities/toKebabCase.js';
19
19
  export { wait } from '../utilities/wait.js';
20
20
  export { default as wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js';
21
21
  export { versionDefaults } from '../versions/defaults.js';
22
+ export { deepMergeSimple } from '@payloadcms/translations/utilities';
22
23
 
23
24
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/shared.ts"],"sourcesContent":["export { defaults as collectionDefaults } from '../collections/config/defaults.js'\nexport { serverProps } from '../config/types.js'\nexport {\n fieldAffectsData,\n fieldHasMaxDepth,\n fieldHasSubFields,\n fieldIsArrayType,\n fieldIsBlockType,\n fieldIsGroupType,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldSupportsMany,\n optionIsObject,\n optionIsValue,\n optionsAreObjects,\n tabHasName,\n valueIsValueWithRelation,\n} from '../fields/config/types.js'\n\nexport * from '../fields/validations.js'\n\nexport { validOperators } from '../types/constants.js'\nexport { formatFilesize } from '../uploads/formatFilesize.js'\n\nexport { isImage } from '../uploads/isImage.js'\n\nexport { deepCopyObject } from '../utilities/deepCopyObject.js'\n\nexport { deepMerge } from '../utilities/deepMerge.js'\n\nexport { fieldSchemaToJSON } from '../utilities/fieldSchemaToJSON.js'\n\nexport { getDataByPath } from '../utilities/getDataByPath.js'\n\nexport { getSiblingData } from '../utilities/getSiblingData.js'\n\nexport { getUniqueListBy } from '../utilities/getUniqueListBy.js'\n\nexport { isNumber } from '../utilities/isNumber.js'\n\nexport {\n isReactClientComponent,\n isReactComponentOrFunction,\n isReactServerComponentOrFunction,\n} from '../utilities/isReactComponent.js'\n\nexport { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js'\n\nexport { setsAreEqual } from '../utilities/setsAreEqual.js'\n\nexport { default as toKebabCase } from '../utilities/toKebabCase.js'\n\nexport { wait } from '../utilities/wait.js'\n\nexport { default as wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js'\n\nexport { versionDefaults } from '../versions/defaults.js'\n"],"names":["defaults","collectionDefaults","serverProps","fieldAffectsData","fieldHasMaxDepth","fieldHasSubFields","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","fieldIsLocalized","fieldIsPresentationalOnly","fieldSupportsMany","optionIsObject","optionIsValue","optionsAreObjects","tabHasName","valueIsValueWithRelation","validOperators","formatFilesize","isImage","deepCopyObject","deepMerge","fieldSchemaToJSON","getDataByPath","getSiblingData","getUniqueListBy","isNumber","isReactClientComponent","isReactComponentOrFunction","isReactServerComponentOrFunction","reduceFieldsToValues","setsAreEqual","default","toKebabCase","wait","wordBoundariesRegex","versionDefaults"],"mappings":"AAAA,SAASA,YAAYC,kBAAkB,QAAQ,oCAAmC;AAClF,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,iBAAiB,EACjBC,gBAAgB,EAChBC,gBAAgB,EAChBC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,UAAU,EACVC,wBAAwB,QACnB,4BAA2B;AAElC,cAAc,2BAA0B;AAExC,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,cAAc,QAAQ,+BAA8B;AAE7D,SAASC,OAAO,QAAQ,wBAAuB;AAE/C,SAASC,cAAc,QAAQ,iCAAgC;AAE/D,SAASC,SAAS,QAAQ,4BAA2B;AAErD,SAASC,iBAAiB,QAAQ,oCAAmC;AAErE,SAASC,aAAa,QAAQ,gCAA+B;AAE7D,SAASC,cAAc,QAAQ,iCAAgC;AAE/D,SAASC,eAAe,QAAQ,kCAAiC;AAEjE,SAASC,QAAQ,QAAQ,2BAA0B;AAEnD,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,gCAAgC,QAC3B,mCAAkC;AAEzC,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,SAASC,YAAY,QAAQ,+BAA8B;AAE3D,SAASC,WAAWC,WAAW,QAAQ,8BAA6B;AAEpE,SAASC,IAAI,QAAQ,uBAAsB;AAE3C,SAASF,WAAWG,mBAAmB,QAAQ,sCAAqC;AAEpF,SAASC,eAAe,QAAQ,0BAAyB"}
1
+ {"version":3,"sources":["../../src/exports/shared.ts"],"sourcesContent":["export { defaults as collectionDefaults } from '../collections/config/defaults.js'\nexport { serverProps } from '../config/types.js'\nexport {\n fieldAffectsData,\n fieldHasMaxDepth,\n fieldHasSubFields,\n fieldIsArrayType,\n fieldIsBlockType,\n fieldIsGroupType,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldSupportsMany,\n optionIsObject,\n optionIsValue,\n optionsAreObjects,\n tabHasName,\n valueIsValueWithRelation,\n} from '../fields/config/types.js'\n\nexport * from '../fields/validations.js'\n\nexport { validOperators } from '../types/constants.js'\nexport { formatFilesize } from '../uploads/formatFilesize.js'\n\nexport { isImage } from '../uploads/isImage.js'\n\nexport {\n deepCopyObject,\n deepCopyObjectComplex,\n deepCopyObjectSimple,\n} from '../utilities/deepCopyObject.js'\n\nexport {\n deepMerge,\n deepMergeWithCombinedArrays,\n deepMergeWithReactComponents,\n deepMergeWithSourceArrays,\n} from '../utilities/deepMerge.js'\nexport { fieldSchemaToJSON } from '../utilities/fieldSchemaToJSON.js'\n\nexport { getDataByPath } from '../utilities/getDataByPath.js'\n\nexport { getSiblingData } from '../utilities/getSiblingData.js'\n\nexport { getUniqueListBy } from '../utilities/getUniqueListBy.js'\n\nexport { isNumber } from '../utilities/isNumber.js'\n\nexport {\n isReactClientComponent,\n isReactComponentOrFunction,\n isReactServerComponentOrFunction,\n} from '../utilities/isReactComponent.js'\n\nexport { reduceFieldsToValues } from '../utilities/reduceFieldsToValues.js'\n\nexport { setsAreEqual } from '../utilities/setsAreEqual.js'\n\nexport { default as toKebabCase } from '../utilities/toKebabCase.js'\n\nexport { wait } from '../utilities/wait.js'\n\nexport { default as wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js'\n\nexport { versionDefaults } from '../versions/defaults.js'\n\nexport { deepMergeSimple } from '@payloadcms/translations/utilities'\n"],"names":["defaults","collectionDefaults","serverProps","fieldAffectsData","fieldHasMaxDepth","fieldHasSubFields","fieldIsArrayType","fieldIsBlockType","fieldIsGroupType","fieldIsLocalized","fieldIsPresentationalOnly","fieldSupportsMany","optionIsObject","optionIsValue","optionsAreObjects","tabHasName","valueIsValueWithRelation","validOperators","formatFilesize","isImage","deepCopyObject","deepCopyObjectComplex","deepCopyObjectSimple","deepMerge","deepMergeWithCombinedArrays","deepMergeWithReactComponents","deepMergeWithSourceArrays","fieldSchemaToJSON","getDataByPath","getSiblingData","getUniqueListBy","isNumber","isReactClientComponent","isReactComponentOrFunction","isReactServerComponentOrFunction","reduceFieldsToValues","setsAreEqual","default","toKebabCase","wait","wordBoundariesRegex","versionDefaults","deepMergeSimple"],"mappings":"AAAA,SAASA,YAAYC,kBAAkB,QAAQ,oCAAmC;AAClF,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,iBAAiB,EACjBC,gBAAgB,EAChBC,gBAAgB,EAChBC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,UAAU,EACVC,wBAAwB,QACnB,4BAA2B;AAElC,cAAc,2BAA0B;AAExC,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,cAAc,QAAQ,+BAA8B;AAE7D,SAASC,OAAO,QAAQ,wBAAuB;AAE/C,SACEC,cAAc,EACdC,qBAAqB,EACrBC,oBAAoB,QACf,iCAAgC;AAEvC,SACEC,SAAS,EACTC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,yBAAyB,QACpB,4BAA2B;AAClC,SAASC,iBAAiB,QAAQ,oCAAmC;AAErE,SAASC,aAAa,QAAQ,gCAA+B;AAE7D,SAASC,cAAc,QAAQ,iCAAgC;AAE/D,SAASC,eAAe,QAAQ,kCAAiC;AAEjE,SAASC,QAAQ,QAAQ,2BAA0B;AAEnD,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,gCAAgC,QAC3B,mCAAkC;AAEzC,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,SAASC,YAAY,QAAQ,+BAA8B;AAE3D,SAASC,WAAWC,WAAW,QAAQ,8BAA6B;AAEpE,SAASC,IAAI,QAAQ,uBAAsB;AAE3C,SAASF,WAAWG,mBAAmB,QAAQ,sCAAqC;AAEpF,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,SAASC,eAAe,QAAQ,qCAAoC"}
@@ -1,6 +1,8 @@
1
+ import type { CollectionConfig } from '../../collections/config/types.js';
1
2
  import type { Config, SanitizedConfig } from '../../config/types.js';
2
3
  import type { Field } from './types.js';
3
4
  type Args = {
5
+ collectionConfig?: CollectionConfig;
4
6
  config: Config;
5
7
  existingFieldNames?: Set<string>;
6
8
  fields: Field[];
@@ -21,7 +23,6 @@ type Args = {
21
23
  */
22
24
  validRelationships: null | string[];
23
25
  };
24
- export declare const reservedFieldNames: string[];
25
- export declare const sanitizeFields: ({ config, existingFieldNames, fields, requireFieldLevelRichTextEditor, richTextSanitizationPromises, validRelationships, }: Args) => Promise<Field[]>;
26
+ export declare const sanitizeFields: ({ collectionConfig, config, existingFieldNames, fields, requireFieldLevelRichTextEditor, richTextSanitizationPromises, validRelationships, }: Args) => Promise<Field[]>;
26
27
  export {};
27
28
  //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,e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;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,iJAQxB,IAAI,KAAG,OAAO,CAAC,KAAK,EAAE,CA2LxB,CAAA"}
@@ -1,19 +1,13 @@
1
+ import { deepMergeSimple } from '@payloadcms/translations/utilities';
1
2
  import { MissingEditorProp } from '../../errors/MissingEditorProp.js';
2
- import { DuplicateFieldName, InvalidFieldName, InvalidFieldRelationship, MissingFieldType, ReservedFieldName } from '../../errors/index.js';
3
- import { deepMerge } from '../../utilities/deepMerge.js';
3
+ import { DuplicateFieldName, InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
4
4
  import { formatLabels, toWords } from '../../utilities/formatLabels.js';
5
5
  import { baseBlockFields } from '../baseFields/baseBlockFields.js';
6
6
  import { baseIDField } from '../baseFields/baseIDField.js';
7
7
  import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
8
8
  import validations from '../validations.js';
9
9
  import { fieldAffectsData, tabHasName } from './types.js';
10
- export const reservedFieldNames = [
11
- '__v',
12
- 'salt',
13
- 'hash',
14
- 'file'
15
- ];
16
- export const sanitizeFields = async ({ config, existingFieldNames = new Set(), fields, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, validRelationships })=>{
10
+ export const sanitizeFields = async ({ collectionConfig, config, existingFieldNames = new Set(), fields, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, validRelationships })=>{
17
11
  if (!fields) return [];
18
12
  for(let i = 0; i < fields.length; i++){
19
13
  const field = fields[i];
@@ -22,10 +16,6 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
22
16
  if (fieldAffectsData(field) && field.name.includes('.')) {
23
17
  throw new InvalidFieldName(field, field.name);
24
18
  }
25
- // assert that field names are not one of reserved names
26
- if (fieldAffectsData(field) && reservedFieldNames.includes(field.name)) {
27
- throw new ReservedFieldName(field, field.name);
28
- }
29
19
  // Auto-label
30
20
  if ('name' in field && field.name && typeof field.label !== 'object' && typeof field.label !== 'string' && typeof field.label !== 'function' && field.label !== false) {
31
21
  field.label = toWords(field.name);
@@ -56,10 +46,12 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
56
46
  }
57
47
  }
58
48
  if (field.type === 'blocks' && field.blocks) {
59
- field.blocks = field.blocks.map((block)=>({
49
+ field.blocks = field.blocks.map((block)=>{
50
+ return {
60
51
  ...block,
61
52
  fields: block.fields.concat(baseBlockFields)
62
- }));
53
+ };
54
+ });
63
55
  }
64
56
  if (field.type === 'array' && field.fields) {
65
57
  field.fields.push(baseIDField);
@@ -114,7 +106,7 @@ export const sanitizeFields = async ({ config, existingFieldNames = new Set(), f
114
106
  });
115
107
  }
116
108
  if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {
117
- config.i18n.translations = deepMerge(config.i18n.translations, field.editor.i18n);
109
+ config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n);
118
110
  }
119
111
  };
120
112
  if (richTextSanitizationPromises) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n ReservedFieldName,\n} from '../../errors/index.js'\nimport { deepMerge } from '../../utilities/deepMerge.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 config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\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 * 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 /**\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 reservedFieldNames = ['__v', 'salt', 'hash', 'file']\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) return []\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if (!field.type) throw new MissingFieldType(field)\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 // assert that field names are not one of reserved names\n if (fieldAffectsData(field) && reservedFieldNames.includes(field.name)) {\n throw new ReservedFieldName(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.type === 'relationship') {\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\n if (field.type === 'blocks' && field.blocks) {\n field.blocks = field.blocks.map((block) => ({\n ...block,\n fields: block.fields.concat(baseBlockFields),\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 (field.localized && !config.localization) delete field.localized\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) field.hooks = {}\n if (!field.access) field.access = {}\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 })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMerge(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 ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\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 requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('blocks' in field && field.blocks) {\n for (let j = 0; j < field.blocks.length; j++) {\n const block = field.blocks[j]\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 requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.blocks[j] = block\n }\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["MissingEditorProp","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","ReservedFieldName","deepMerge","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","reservedFieldNames","sanitizeFields","config","existingFieldNames","Set","fields","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","blocks","map","block","concat","push","labels","has","add","localized","localization","validate","defaultValidate","val","options","hooks","access","admin","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","j","tabs","tab","slug"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,oCAAmC;AACrE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,EAChBC,iB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AC9B;gBAEA4C,IAAIpD,MAAM,GAAG,MAAMJ,eAAe;oBAChCC;oBACAC,oBAAoBJ,WAAW0D,OAAO,IAAIrD,QAAQD;oBAClDE,QAAQoD,IAAIpD,MAAM;oBAClBC;oBACAC;oBACAC;gBACF;gBACAG,MAAM6C,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,YAAY9C,SAASA,MAAMmB,MAAM,EAAE;YACrC,IAAK,IAAIyB,IAAI,GAAGA,IAAI5C,MAAMmB,MAAM,CAACpB,MAAM,EAAE6C,IAAK;gBAC5C,MAAMvB,QAAQrB,MAAMmB,MAAM,CAACyB,EAAE;gBAC7BvB,MAAMG,MAAM,GAAG,CAACH,MAAMG,MAAM,GAAG3C,aAAawC,MAAM0B,IAAI,IAAI1B,MAAMG,MAAM;gBAEtEH,MAAM3B,MAAM,GAAG,MAAMJ,eAAe;oBAClCC;oBACAC,oBAAoB,IAAIC;oBACxBC,QAAQ2B,MAAM3B,MAAM;oBACpBC;oBACAC;oBACAC;gBACF;gBACAG,MAAMmB,MAAM,CAACyB,EAAE,GAAGvB;YACpB;QACF;QAEA3B,MAAM,CAACI,EAAE,GAAGE;IACd;IAEA,OAAON;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 { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.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 /**\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 * 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 /**\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 requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) return []\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if (!field.type) throw new MissingFieldType(field)\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.type === 'relationship') {\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\n if (field.type === 'blocks' && field.blocks) {\n field.blocks = field.blocks.map((block) => {\n return {\n ...block,\n fields: block.fields.concat(baseBlockFields),\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 (field.localized && !config.localization) delete field.localized\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) field.hooks = {}\n if (!field.access) field.access = {}\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 })\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 ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\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 requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('blocks' in field && field.blocks) {\n for (let j = 0; j < field.blocks.length; j++) {\n const block = field.blocks[j]\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 requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.blocks[j] = block\n }\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","MissingEditorProp","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","blocks","map","block","concat","push","labels","has","add","localized","localization","validate","defaultValidate","val","options","hooks","access","admin","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","j","tabs","tab","slug"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SACEC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6C,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,YAAY9C,SAASA,MAAMmB,MAAM,EAAE;YACrC,IAAK,IAAIyB,IAAI,GAAGA,IAAI5C,MAAMmB,MAAM,CAACpB,MAAM,EAAE6C,IAAK;gBAC5C,MAAMvB,QAAQrB,MAAMmB,MAAM,CAACyB,EAAE;gBAC7BvB,MAAMG,MAAM,GAAG,CAACH,MAAMG,MAAM,GAAG3C,aAAawC,MAAM0B,IAAI,IAAI1B,MAAMG,MAAM;gBAEtEH,MAAM3B,MAAM,GAAG,MAAML,eAAe;oBAClCE;oBACAC,oBAAoB,IAAIC;oBACxBC,QAAQ2B,MAAM3B,MAAM;oBACpBC;oBACAC;oBACAC;gBACF;gBACAG,MAAMmB,MAAM,CAACyB,EAAE,GAAGvB;YACpB;QACF;QAEA3B,MAAM,CAACI,EAAE,GAAGE;IACd;IAEA,OAAON;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import { InvalidFieldName, InvalidFieldRelationship, MissingFieldType, ReservedFieldName } from '../../errors/index.js';
1
+ import { InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
2
2
  import { sanitizeFields } from './sanitize.js';
3
3
  describe('sanitizeFields', ()=>{
4
4
  const config = {};
@@ -34,22 +34,6 @@ describe('sanitizeFields', ()=>{
34
34
  });
35
35
  }).rejects.toThrow(InvalidFieldName);
36
36
  });
37
- it('should throw on a reserved field name', async ()=>{
38
- const fields = [
39
- {
40
- name: 'hash',
41
- type: 'text',
42
- label: 'hash'
43
- }
44
- ];
45
- await expect(async ()=>{
46
- await sanitizeFields({
47
- config,
48
- fields,
49
- validRelationships: []
50
- });
51
- }).rejects.toThrow(ReservedFieldName);
52
- });
53
37
  describe('auto-labeling', ()=>{
54
38
  it('should populate label if missing', async ()=>{
55
39
  const fields = [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/sanitize.spec.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n Field,\n NumberField,\n TextField,\n} from './types.js'\n\nimport {\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n ReservedFieldName,\n} from '../../errors/index.js'\nimport { sanitizeFields } from './sanitize.js'\n\ndescribe('sanitizeFields', () => {\n const config = {} as Config\n it('should throw on missing type field', async () => {\n const fields: Field[] = [\n // @ts-expect-error\n {\n name: 'Some Collection',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n }).rejects.toThrow(MissingFieldType)\n })\n it('should throw on invalid field name', async () => {\n const fields: Field[] = [\n {\n name: 'some.collection',\n type: 'text',\n label: 'some.collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n }).rejects.toThrow(InvalidFieldName)\n })\n\n it('should throw on a reserved field name', async () => {\n const fields: Field[] = [\n {\n name: 'hash',\n type: 'text',\n label: 'hash',\n },\n ]\n await expect(async () => {\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n }).rejects.toThrow(ReservedFieldName)\n })\n\n describe('auto-labeling', () => {\n it('should populate label if missing', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual('Some Field')\n expect(sanitizedField.type).toStrictEqual('text')\n })\n it('should allow auto-label override', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n label: 'Do not label',\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual('Do not label')\n expect(sanitizedField.type).toStrictEqual('text')\n })\n\n describe('opt-out', () => {\n it('should allow label opt-out', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n label: false,\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('text')\n })\n\n it('should allow label opt-out for arrays', async () => {\n const arrayField: ArrayField = {\n name: 'items',\n type: 'array',\n fields: [\n {\n name: 'itemName',\n type: 'text',\n },\n ],\n label: false,\n }\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields: [arrayField],\n validRelationships: [],\n })\n )[0] as ArrayField\n expect(sanitizedField.name).toStrictEqual('items')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('array')\n expect(sanitizedField.labels).toBeUndefined()\n })\n it('should allow label opt-out for blocks', async () => {\n const fields: Field[] = [\n {\n name: 'noLabelBlock',\n type: 'blocks',\n blocks: [\n {\n slug: 'number',\n fields: [\n {\n name: 'testNumber',\n type: 'number',\n },\n ],\n },\n ],\n label: false,\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as BlockField\n expect(sanitizedField.name).toStrictEqual('noLabelBlock')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('blocks')\n expect(sanitizedField.labels).toBeUndefined()\n })\n })\n\n it('should label arrays with plural and singular', async () => {\n const fields: Field[] = [\n {\n name: 'items',\n type: 'array',\n fields: [\n {\n name: 'itemName',\n type: 'text',\n },\n ],\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as ArrayField\n expect(sanitizedField.name).toStrictEqual('items')\n expect(sanitizedField.label).toStrictEqual('Items')\n expect(sanitizedField.type).toStrictEqual('array')\n expect(sanitizedField.labels).toMatchObject({ plural: 'Items', singular: 'Item' })\n })\n\n it('should label blocks with plural and singular', async () => {\n const fields: Field[] = [\n {\n name: 'specialBlock',\n type: 'blocks',\n blocks: [\n {\n slug: 'number',\n fields: [{ name: 'testNumber', type: 'number' }],\n },\n ],\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as BlockField\n expect(sanitizedField.name).toStrictEqual('specialBlock')\n expect(sanitizedField.label).toStrictEqual('Special Block')\n expect(sanitizedField.type).toStrictEqual('blocks')\n expect(sanitizedField.labels).toMatchObject({\n plural: 'Special Blocks',\n singular: 'Special Block',\n })\n expect((sanitizedField.blocks[0].fields[0] as NumberField).label).toStrictEqual('Test Number')\n })\n })\n\n describe('relationships', () => {\n it('should not throw on valid relationship', async () => {\n const validRelationships = ['some-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should not throw on valid relationship - multiple', async () => {\n const validRelationships = ['some-collection', 'another-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: ['some-collection', 'another-collection'],\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should not throw on valid relationship inside blocks', async () => {\n const validRelationships = ['some-collection']\n const relationshipBlock: Block = {\n slug: 'relationshipBlock',\n fields: [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'some-collection',\n },\n ],\n }\n const fields: Field[] = [\n {\n name: 'layout',\n type: 'blocks',\n blocks: [relationshipBlock],\n label: 'Layout Blocks',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should throw on invalid relationship', async () => {\n const validRelationships = ['some-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'not-valid',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should throw on invalid relationship - multiple', async () => {\n const validRelationships = ['some-collection', 'another-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: ['some-collection', 'not-valid'],\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should throw on invalid relationship inside blocks', async () => {\n const validRelationships = ['some-collection']\n const relationshipBlock: Block = {\n slug: 'relationshipBlock',\n fields: [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'not-valid',\n },\n ],\n }\n const fields: Field[] = [\n {\n name: 'layout',\n type: 'blocks',\n blocks: [relationshipBlock],\n label: 'Layout Blocks',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should defaultValue of checkbox to false if required and undefined', async () => {\n const fields: Field[] = [\n {\n name: 'My Checkbox',\n type: 'checkbox',\n required: true,\n },\n ]\n\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as CheckboxField\n expect(sanitizedField.defaultValue).toStrictEqual(false)\n })\n\n it('should return empty field array if no fields', async () => {\n const sanitizedFields = await sanitizeFields({\n config,\n fields: [],\n validRelationships: [],\n })\n expect(sanitizedFields).toStrictEqual([])\n })\n })\n})\n"],"names":["InvalidFieldName","InvalidFieldRelationship","MissingFieldType","ReservedFieldName","sanitizeFields","describe","config","it","fields","name","label","expect","validRelationships","rejects","toThrow","type","sanitizedField","toStrictEqual","arrayField","labels","toBeUndefined","blocks","slug","toMatchObject","plural","singular","relationTo","not","relationshipBlock","required","defaultValue","sanitizedFields"],"mappings":"AAWA,SACEA,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,EAChBC,iB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,eAAe;gBACnBE;gBACAE;gBACAI,oBAAoB,EAAE;YACxB,EAAC,CACF,CAAC,EAAE;YACJD,OAAOK,eAAec,YAAY,EAAEb,aAAa,CAAC;QACpD;QAEAV,GAAG,gDAAgD;YACjD,MAAMwB,kBAAkB,MAAM3B,eAAe;gBAC3CE;gBACAE,QAAQ,EAAE;gBACVI,oBAAoB,EAAE;YACxB;YACAD,OAAOoB,iBAAiBd,aAAa,CAAC,EAAE;QAC1C;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/fields/config/sanitize.spec.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n Field,\n NumberField,\n TextField,\n} from './types.js'\n\nimport { InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js'\nimport { sanitizeFields } from './sanitize.js'\n\ndescribe('sanitizeFields', () => {\n const config = {} as Config\n it('should throw on missing type field', async () => {\n const fields: Field[] = [\n // @ts-expect-error\n {\n name: 'Some Collection',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n }).rejects.toThrow(MissingFieldType)\n })\n it('should throw on invalid field name', async () => {\n const fields: Field[] = [\n {\n name: 'some.collection',\n type: 'text',\n label: 'some.collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n }).rejects.toThrow(InvalidFieldName)\n })\n\n describe('auto-labeling', () => {\n it('should populate label if missing', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual('Some Field')\n expect(sanitizedField.type).toStrictEqual('text')\n })\n it('should allow auto-label override', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n label: 'Do not label',\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual('Do not label')\n expect(sanitizedField.type).toStrictEqual('text')\n })\n\n describe('opt-out', () => {\n it('should allow label opt-out', async () => {\n const fields: Field[] = [\n {\n name: 'someField',\n type: 'text',\n label: false,\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as TextField\n expect(sanitizedField.name).toStrictEqual('someField')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('text')\n })\n\n it('should allow label opt-out for arrays', async () => {\n const arrayField: ArrayField = {\n name: 'items',\n type: 'array',\n fields: [\n {\n name: 'itemName',\n type: 'text',\n },\n ],\n label: false,\n }\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields: [arrayField],\n validRelationships: [],\n })\n )[0] as ArrayField\n expect(sanitizedField.name).toStrictEqual('items')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('array')\n expect(sanitizedField.labels).toBeUndefined()\n })\n it('should allow label opt-out for blocks', async () => {\n const fields: Field[] = [\n {\n name: 'noLabelBlock',\n type: 'blocks',\n blocks: [\n {\n slug: 'number',\n fields: [\n {\n name: 'testNumber',\n type: 'number',\n },\n ],\n },\n ],\n label: false,\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as BlockField\n expect(sanitizedField.name).toStrictEqual('noLabelBlock')\n expect(sanitizedField.label).toStrictEqual(false)\n expect(sanitizedField.type).toStrictEqual('blocks')\n expect(sanitizedField.labels).toBeUndefined()\n })\n })\n\n it('should label arrays with plural and singular', async () => {\n const fields: Field[] = [\n {\n name: 'items',\n type: 'array',\n fields: [\n {\n name: 'itemName',\n type: 'text',\n },\n ],\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as ArrayField\n expect(sanitizedField.name).toStrictEqual('items')\n expect(sanitizedField.label).toStrictEqual('Items')\n expect(sanitizedField.type).toStrictEqual('array')\n expect(sanitizedField.labels).toMatchObject({ plural: 'Items', singular: 'Item' })\n })\n\n it('should label blocks with plural and singular', async () => {\n const fields: Field[] = [\n {\n name: 'specialBlock',\n type: 'blocks',\n blocks: [\n {\n slug: 'number',\n fields: [{ name: 'testNumber', type: 'number' }],\n },\n ],\n },\n ]\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as BlockField\n expect(sanitizedField.name).toStrictEqual('specialBlock')\n expect(sanitizedField.label).toStrictEqual('Special Block')\n expect(sanitizedField.type).toStrictEqual('blocks')\n expect(sanitizedField.labels).toMatchObject({\n plural: 'Special Blocks',\n singular: 'Special Block',\n })\n expect((sanitizedField.blocks[0].fields[0] as NumberField).label).toStrictEqual('Test Number')\n })\n })\n\n describe('relationships', () => {\n it('should not throw on valid relationship', async () => {\n const validRelationships = ['some-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should not throw on valid relationship - multiple', async () => {\n const validRelationships = ['some-collection', 'another-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: ['some-collection', 'another-collection'],\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should not throw on valid relationship inside blocks', async () => {\n const validRelationships = ['some-collection']\n const relationshipBlock: Block = {\n slug: 'relationshipBlock',\n fields: [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'some-collection',\n },\n ],\n }\n const fields: Field[] = [\n {\n name: 'layout',\n type: 'blocks',\n blocks: [relationshipBlock],\n label: 'Layout Blocks',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).not.toThrow()\n })\n\n it('should throw on invalid relationship', async () => {\n const validRelationships = ['some-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'not-valid',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should throw on invalid relationship - multiple', async () => {\n const validRelationships = ['some-collection', 'another-collection']\n const fields: Field[] = [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: ['some-collection', 'not-valid'],\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should throw on invalid relationship inside blocks', async () => {\n const validRelationships = ['some-collection']\n const relationshipBlock: Block = {\n slug: 'relationshipBlock',\n fields: [\n {\n name: 'My Relationship',\n type: 'relationship',\n label: 'my-relationship',\n relationTo: 'not-valid',\n },\n ],\n }\n const fields: Field[] = [\n {\n name: 'layout',\n type: 'blocks',\n blocks: [relationshipBlock],\n label: 'Layout Blocks',\n },\n ]\n await expect(async () => {\n await sanitizeFields({ config, fields, validRelationships })\n }).rejects.toThrow(InvalidFieldRelationship)\n })\n\n it('should defaultValue of checkbox to false if required and undefined', async () => {\n const fields: Field[] = [\n {\n name: 'My Checkbox',\n type: 'checkbox',\n required: true,\n },\n ]\n\n const sanitizedField = (\n await sanitizeFields({\n config,\n fields,\n validRelationships: [],\n })\n )[0] as CheckboxField\n expect(sanitizedField.defaultValue).toStrictEqual(false)\n })\n\n it('should return empty field array if no fields', async () => {\n const sanitizedFields = await sanitizeFields({\n config,\n fields: [],\n validRelationships: [],\n })\n expect(sanitizedFields).toStrictEqual([])\n })\n })\n})\n"],"names":["InvalidFieldName","InvalidFieldRelationship","MissingFieldType","sanitizeFields","describe","config","it","fields","name","label","expect","validRelationships","rejects","toThrow","type","sanitizedField","toStrictEqual","arrayField","labels","toBeUndefined","blocks","slug","toMatchObject","plural","singular","relationTo","not","relationshipBlock","required","defaultValue","sanitizedFields"],"mappings":"AAWA,SAASA,gBAAgB,EAAEC,wBAAwB,EAAEC,gBAAgB,QAAQ,wBAAuB;AACpG,SAASC,cAAc,QAAQ,gBAAe;AAE9CC,SAAS,kBAAkB;IACzB,MAAMC,SAAS,CAAC;IAChBC,GAAG,sCAAsC;QACvC,MAAMC,SAAkB;YACtB,mBAAmB;YACnB;gBACEC,MAAM;gBACNC,OAAO;YACT;SACD;QACD,MAAMC,OAAO;YACX,MAAMP,eAAe;gBACnBE;gBACAE;gBACAI,oBAAoB,EAAE;YACxB;QACF,GAAGC,OAAO,CAACC,OAAO,CAACX;IACrB;IACAI,GAAG,sCAAsC;QACvC,MAAMC,SAAkB;YACtB;gBACEC,MAAM;gBACNM,MAAM;gBACNL,OAAO;YACT;SACD;QACD,MAAMC,OAAO;YACX,MAAMP,eAAe;gBACnBE;gBACAE;gBACAI,oBAAoB,EAAE;YACxB;QACF,GAAGC,OAAO,CAACC,OAAO,CAACb;IACrB;IAEAI,SAAS,iBAAiB;QACxBE,GAAG,oCAAoC;YACrC,MAAMC,SAAkB;gBACtB;oBACEC,MAAM;oBACNM,MAAM;gBACR;aACD;YACD,MAAMC,iBAAiB,AACrB,CAAA,MAAMZ,eAAe;gBACnBE;gBACAE;gBACAI,oBAAoB,EAAE;YACxB,EAAC,CACF,CAAC,EAAE;YACJD,OAAOK,eAAeP,IAAI,EAAEQ,aAAa,CAAC;YAC1CN,OAAOK,eAAeN,KAAK,EAAEO,aAAa,CAAC;YAC3CN,OAAOK,eAAeD,IAAI,EAAEE,aAAa,CAAC;QAC5C;QACAV,GAAG,oCAAoC;YACrC,MAAMC,SAAkB;gBACtB;oBACEC,MAAM;oBACNM,MAAM;oBACNL,OAAO;gBACT;aACD;YACD,MAAMM,iBAAiB,AACrB,CAAA,MAAMZ,eAAe;gBACnBE;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EAAC,CACF,CAAC,EAAE;YACJD,OAAOK,eAAec,YAAY,EAAEb,aAAa,CAAC;QACpD;QAEAV,GAAG,gDAAgD;YACjD,MAAMwB,kBAAkB,MAAM3B,eAAe;gBAC3CE;gBACAE,QAAQ,EAAE;gBACVI,oBAAoB,EAAE;YACxB;YACAD,OAAOoB,iBAAiBd,aAAa,CAAC,EAAE;QAC1C;IACF;AACF"}
@@ -1,10 +1,10 @@
1
- import type { PayloadRequest } from '../types/index.js';
1
+ import type { JsonValue, PayloadRequest } from '../types/index.js';
2
2
  type Args = {
3
- defaultValue: unknown;
3
+ defaultValue: ((args: any) => JsonValue) | any;
4
4
  locale: string | undefined;
5
5
  user: PayloadRequest['user'];
6
- value?: unknown;
6
+ value?: JsonValue;
7
7
  };
8
- declare const getValueWithDefault: ({ defaultValue, locale, user, value }: Args) => unknown;
9
- export default getValueWithDefault;
8
+ export declare const getDefaultValue: ({ defaultValue, locale, user, value, }: Args) => Promise<JsonValue>;
9
+ export {};
10
10
  //# sourceMappingURL=getDefaultValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultValue.d.ts","sourceRoot":"","sources":["../../src/fields/getDefaultValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIvD,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,OAAO,CAAA;IACrB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,QAAA,MAAM,mBAAmB,0CAA2C,IAAI,KAAG,OAc1E,CAAA;AAGD,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"getDefaultValue.d.ts","sourceRoot":"","sources":["../../src/fields/getDefaultValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIlE,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,SAAS,CAAC,GAAG,GAAG,CAAA;IAC9C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,eAAe,2CAKzB,IAAI,KAAG,OAAO,CAAC,SAAS,CAc1B,CAAA"}
@@ -1,20 +1,18 @@
1
- import { deepCopyObject } from '../utilities/deepCopyObject.js';
2
- const getValueWithDefault = ({ defaultValue, locale, user, value })=>{
1
+ import { deepCopyObjectSimple } from '../utilities/deepCopyObject.js';
2
+ export const getDefaultValue = async ({ defaultValue, locale, user, value })=>{
3
3
  if (typeof value !== 'undefined') {
4
4
  return value;
5
5
  }
6
6
  if (defaultValue && typeof defaultValue === 'function') {
7
- return defaultValue({
7
+ return await defaultValue({
8
8
  locale,
9
9
  user
10
10
  });
11
11
  }
12
12
  if (typeof defaultValue === 'object') {
13
- return deepCopyObject(defaultValue);
13
+ return deepCopyObjectSimple(defaultValue);
14
14
  }
15
15
  return defaultValue;
16
16
  };
17
- // eslint-disable-next-line no-restricted-exports
18
- export default getValueWithDefault;
19
17
 
20
18
  //# sourceMappingURL=getDefaultValue.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/getDefaultValue.ts"],"sourcesContent":["import type { PayloadRequest } from '../types/index.js'\n\nimport { deepCopyObject } from '../utilities/deepCopyObject.js'\n\ntype Args = {\n defaultValue: unknown\n locale: string | undefined\n user: PayloadRequest['user']\n value?: unknown\n}\n\nconst getValueWithDefault = ({ defaultValue, locale, user, value }: Args): unknown => {\n if (typeof value !== 'undefined') {\n return value\n }\n\n if (defaultValue && typeof defaultValue === 'function') {\n return defaultValue({ locale, user })\n }\n\n if (typeof defaultValue === 'object') {\n return deepCopyObject(defaultValue)\n }\n\n return defaultValue\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default getValueWithDefault\n"],"names":["deepCopyObject","getValueWithDefault","defaultValue","locale","user","value"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iCAAgC;AAS/D,MAAMC,sBAAsB,CAAC,EAAEC,YAAY,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAQ;IACtE,IAAI,OAAOA,UAAU,aAAa;QAChC,OAAOA;IACT;IAEA,IAAIH,gBAAgB,OAAOA,iBAAiB,YAAY;QACtD,OAAOA,aAAa;YAAEC;YAAQC;QAAK;IACrC;IAEA,IAAI,OAAOF,iBAAiB,UAAU;QACpC,OAAOF,eAAeE;IACxB;IAEA,OAAOA;AACT;AAEA,iDAAiD;AACjD,eAAeD,oBAAmB"}
1
+ {"version":3,"sources":["../../src/fields/getDefaultValue.ts"],"sourcesContent":["import type { JsonValue, PayloadRequest } from '../types/index.js'\n\nimport { deepCopyObjectSimple } from '../utilities/deepCopyObject.js'\n\ntype Args = {\n defaultValue: ((args: any) => JsonValue) | any\n locale: string | undefined\n user: PayloadRequest['user']\n value?: JsonValue\n}\n\nexport const getDefaultValue = async ({\n defaultValue,\n locale,\n user,\n value,\n}: Args): Promise<JsonValue> => {\n if (typeof value !== 'undefined') {\n return value\n }\n\n if (defaultValue && typeof defaultValue === 'function') {\n return await defaultValue({ locale, user })\n }\n\n if (typeof defaultValue === 'object') {\n return deepCopyObjectSimple(defaultValue)\n }\n\n return defaultValue\n}\n"],"names":["deepCopyObjectSimple","getDefaultValue","defaultValue","locale","user","value"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,iCAAgC;AASrE,OAAO,MAAMC,kBAAkB,OAAO,EACpCC,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,KAAK,EACA;IACL,IAAI,OAAOA,UAAU,aAAa;QAChC,OAAOA;IACT;IAEA,IAAIH,gBAAgB,OAAOA,iBAAiB,YAAY;QACtD,OAAO,MAAMA,aAAa;YAAEC;YAAQC;QAAK;IAC3C;IAEA,IAAI,OAAOF,iBAAiB,UAAU;QACpC,OAAOF,qBAAqBE;IAC9B;IAEA,OAAOA;AACT,EAAC"}
@@ -1,26 +1,26 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
2
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
- import type { PayloadRequest, RequestContext } from '../../../types/index.js';
4
- type Args<T> = {
3
+ import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js';
4
+ type Args<T extends JsonObject> = {
5
5
  collection: SanitizedCollectionConfig | null;
6
6
  context: RequestContext;
7
7
  /**
8
8
  * The data before hooks
9
9
  */
10
- data: Record<string, unknown> | T;
10
+ data: T;
11
11
  /**
12
12
  * The data after hooks
13
13
  */
14
- doc: Record<string, unknown> | T;
14
+ doc: T;
15
15
  global: SanitizedGlobalConfig | null;
16
16
  operation: 'create' | 'update';
17
- previousDoc: Record<string, unknown> | T;
17
+ previousDoc: T;
18
18
  req: PayloadRequest;
19
19
  };
20
20
  /**
21
21
  * This function is responsible for the following actions, in order:
22
22
  * - Execute field hooks
23
23
  */
24
- export declare const afterChange: <T extends Record<string, unknown>>({ collection, context, data, doc: incomingDoc, global, operation, previousDoc, req, }: Args<T>) => Promise<T>;
24
+ export declare const afterChange: <T extends JsonObject>({ collection, context, data, doc: incomingDoc, global, operation, previousDoc, req, }: Args<T>) => Promise<T>;
25
25
  export {};
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAK7E,KAAK,IAAI,CAAC,CAAC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GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,SAAS,UAAU,yFASnD,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAqBrB,CAAA"}
@@ -1,10 +1,10 @@
1
- import { deepCopyObject } from '../../../utilities/deepCopyObject.js';
1
+ import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js';
2
2
  import { traverseFields } from './traverseFields.js';
3
3
  /**
4
4
  * This function is responsible for the following actions, in order:
5
5
  * - Execute field hooks
6
6
  */ export const afterChange = async ({ collection, context, data, doc: incomingDoc, global, operation, previousDoc, req })=>{
7
- const doc = deepCopyObject(incomingDoc);
7
+ const doc = deepCopyObjectSimple(incomingDoc);
8
8
  await traverseFields({
9
9
  collection,
10
10
  context,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { PayloadRequest, RequestContext } from '../../../types/index.js'\n\nimport { deepCopyObject } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T> = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n /**\n * The data before hooks\n */\n data: Record<string, unknown> | T\n /**\n * The data after hooks\n */\n doc: Record<string, unknown> | T\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: Record<string, unknown> | T\n req: PayloadRequest\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Execute field hooks\n */\nexport const afterChange = async <T extends Record<string, unknown>>({\n collection,\n context,\n data,\n doc: incomingDoc,\n global,\n operation,\n previousDoc,\n req,\n}: Args<T>): Promise<T> => {\n const doc = deepCopyObject(incomingDoc)\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: collection?.fields || global?.fields,\n global,\n operation,\n path: [],\n previousDoc,\n previousSiblingDoc: previousDoc,\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n })\n\n return doc\n}\n"],"names":["deepCopyObject","traverseFields","afterChange","collection","context","data","doc","incomingDoc","global","operation","previousDoc","req","fields","path","previousSiblingDoc","schemaPath","siblingData","siblingDoc"],"mappings":"AAIA,SAASA,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD;;;CAGC,GACD,OAAO,MAAMC,cAAc,OAA0C,EACnEC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,KAAKC,WAAW,EAChBC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,GAAG,EACK;IACR,MAAML,MAAMN,eAAeO;IAE3B,MAAMN,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAM,QAAQT,YAAYS,UAAUJ,QAAQI;QACtCJ;QACAC;QACAI,MAAM,EAAE;QACRH;QACAI,oBAAoBJ;QACpBC;QACAI,YAAY,EAAE;QACdC,aAAaX;QACbY,YAAYX;IACd;IAEA,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: SanitizedCollectionConfig | null\n context: RequestContext\n /**\n * The data before hooks\n */\n data: T\n /**\n * The data after hooks\n */\n doc: T\n global: SanitizedGlobalConfig | null\n operation: 'create' | 'update'\n previousDoc: T\n req: PayloadRequest\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Execute field hooks\n */\nexport const afterChange = async <T extends JsonObject>({\n collection,\n context,\n data,\n doc: incomingDoc,\n global,\n operation,\n previousDoc,\n req,\n}: Args<T>): Promise<T> => {\n const doc = deepCopyObjectSimple(incomingDoc)\n\n await traverseFields({\n collection,\n context,\n data,\n doc,\n fields: collection?.fields || global?.fields,\n global,\n operation,\n path: [],\n previousDoc,\n previousSiblingDoc: previousDoc,\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n })\n\n return doc\n}\n"],"names":["deepCopyObjectSimple","traverseFields","afterChange","collection","context","data","doc","incomingDoc","global","operation","previousDoc","req","fields","path","previousSiblingDoc","schemaPath","siblingData","siblingDoc"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD;;;CAGC,GACD,OAAO,MAAMC,cAAc,OAA6B,EACtDC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,KAAKC,WAAW,EAChBC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,GAAG,EACK;IACR,MAAML,MAAMN,qBAAqBO;IAEjC,MAAMN,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAM,QAAQT,YAAYS,UAAUJ,QAAQI;QACtCJ;QACAC;QACAI,MAAM,EAAE;QACRH;QACAI,oBAAoBJ;QACpBC;QACAI,YAAY,EAAE;QACdC,aAAaX;QACbY,YAAYX;IACd;IAEA,OAAOA;AACT,EAAC"}
@@ -1,12 +1,12 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
2
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
- import type { PayloadRequest, RequestContext } from '../../../types/index.js';
3
+ import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js';
4
4
  import type { Field, TabAsField } from '../../config/types.js';
5
5
  type Args = {
6
6
  collection: SanitizedCollectionConfig | null;
7
7
  context: RequestContext;
8
- data: Record<string, unknown>;
9
- doc: Record<string, unknown>;
8
+ data: JsonObject;
9
+ doc: JsonObject;
10
10
  field: Field | TabAsField;
11
11
  global: SanitizedGlobalConfig | null;
12
12
  operation: 'create' | 'update';
@@ -18,11 +18,11 @@ type Args = {
18
18
  * The parent's schemaPath (path without indexes).
19
19
  */
20
20
  parentSchemaPath: string[];
21
- previousDoc: Record<string, unknown>;
22
- previousSiblingDoc: Record<string, unknown>;
21
+ previousDoc: JsonObject;
22
+ previousSiblingDoc: JsonObject;
23
23
  req: PayloadRequest;
24
- siblingData: Record<string, unknown>;
25
- siblingDoc: Record<string, unknown>;
24
+ siblingData: JsonObject;
25
+ siblingDoc: JsonObject;
26
26
  };
27
27
  export declare const promise: ({ collection, context, data, doc, field, global, operation, parentPath, parentSchemaPath, previousDoc, previousSiblingDoc, req, siblingData, siblingDoc, }: Args) => Promise<void>;
28
28
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAO9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,GAAG,IAAI,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAA;IACpC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,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E,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAKD,eAAO,MAAM,OAAO,+JAejB,IAAI,KAAG,OAAO,CAAC,IAAI,CAqPrB,CAAA"}
@@ -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 { 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: SanitizedCollectionConfig | null\n context: RequestContext\n data: Record<string, unknown>\n doc: Record<string, unknown>\n field: Field | TabAsField\n global: SanitizedGlobalConfig | null\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: Record<string, unknown>\n previousSiblingDoc: Record<string, unknown>\n req: PayloadRequest\n siblingData: Record<string, unknown>\n siblingDoc: Record<string, unknown>\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 Record<string, unknown>,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: (siblingData?.[field.name] as Record<string, unknown>) || {},\n siblingDoc: siblingDoc[field.name] as Record<string, unknown>,\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 Record<string, unknown>),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...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((blockType) => blockType.slug === row.blockType)\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:\n previousDoc?.[field.name]?.[i] || ({} as Record<string, unknown>),\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData?.[field.name]?.[i] || {},\n siblingDoc: { ...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 Record<string, unknown>\n tabSiblingDoc = siblingDoc[field.name] as Record<string, unknown>\n tabPreviousSiblingDoc = previousDoc[field.name] as Record<string, unknown>\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;oBAC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,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"}
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: SanitizedCollectionConfig | null\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n field: Field | TabAsField\n global: SanitizedGlobalConfig | null\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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