payload 3.0.0-beta.55 → 3.0.0-beta.57

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 (422) hide show
  1. package/dist/admin/RichText.d.ts +3 -3
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/views/types.d.ts +2 -2
  5. package/dist/admin/views/types.d.ts.map +1 -1
  6. package/dist/admin/views/types.js.map +1 -1
  7. package/dist/auth/baseFields/auth.d.ts.map +1 -1
  8. package/dist/auth/baseFields/auth.js +0 -14
  9. package/dist/auth/baseFields/auth.js.map +1 -1
  10. package/dist/auth/baseFields/loginField.d.ts +4 -0
  11. package/dist/auth/baseFields/loginField.d.ts.map +1 -0
  12. package/dist/auth/baseFields/loginField.js +35 -0
  13. package/dist/auth/baseFields/loginField.js.map +1 -0
  14. package/dist/auth/defaultAccess.d.ts +2 -2
  15. package/dist/auth/defaultAccess.d.ts.map +1 -1
  16. package/dist/auth/defaultAccess.js.map +1 -1
  17. package/dist/auth/executeAccess.d.ts +2 -2
  18. package/dist/auth/executeAccess.d.ts.map +1 -1
  19. package/dist/auth/executeAccess.js.map +1 -1
  20. package/dist/auth/executeAuthStrategies.d.ts +2 -3
  21. package/dist/auth/executeAuthStrategies.d.ts.map +1 -1
  22. package/dist/auth/executeAuthStrategies.js +6 -4
  23. package/dist/auth/executeAuthStrategies.js.map +1 -1
  24. package/dist/auth/getAccessResults.d.ts +2 -2
  25. package/dist/auth/getAccessResults.d.ts.map +1 -1
  26. package/dist/auth/getAccessResults.js.map +1 -1
  27. package/dist/auth/getFieldsToSign.d.ts +2 -2
  28. package/dist/auth/getFieldsToSign.d.ts.map +1 -1
  29. package/dist/auth/getFieldsToSign.js.map +1 -1
  30. package/dist/auth/operations/access.d.ts +2 -2
  31. package/dist/auth/operations/access.d.ts.map +1 -1
  32. package/dist/auth/operations/access.js.map +1 -1
  33. package/dist/auth/operations/auth.d.ts +3 -2
  34. package/dist/auth/operations/auth.d.ts.map +1 -1
  35. package/dist/auth/operations/auth.js +3 -1
  36. package/dist/auth/operations/auth.js.map +1 -1
  37. package/dist/auth/operations/forgotPassword.d.ts +7 -7
  38. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  39. package/dist/auth/operations/forgotPassword.js +11 -6
  40. package/dist/auth/operations/forgotPassword.js.map +1 -1
  41. package/dist/auth/operations/init.d.ts +2 -2
  42. package/dist/auth/operations/init.d.ts.map +1 -1
  43. package/dist/auth/operations/init.js.map +1 -1
  44. package/dist/auth/operations/local/auth.js.map +1 -1
  45. package/dist/auth/operations/local/forgotPassword.d.ts +2 -2
  46. package/dist/auth/operations/local/forgotPassword.d.ts.map +1 -1
  47. package/dist/auth/operations/local/forgotPassword.js.map +1 -1
  48. package/dist/auth/operations/local/login.d.ts +4 -7
  49. package/dist/auth/operations/local/login.d.ts.map +1 -1
  50. package/dist/auth/operations/local/login.js.map +1 -1
  51. package/dist/auth/operations/local/resetPassword.d.ts +2 -2
  52. package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
  53. package/dist/auth/operations/local/resetPassword.js.map +1 -1
  54. package/dist/auth/operations/local/unlock.d.ts +2 -2
  55. package/dist/auth/operations/local/unlock.d.ts.map +1 -1
  56. package/dist/auth/operations/local/unlock.js.map +1 -1
  57. package/dist/auth/operations/local/verifyEmail.d.ts +2 -2
  58. package/dist/auth/operations/local/verifyEmail.d.ts.map +1 -1
  59. package/dist/auth/operations/local/verifyEmail.js.map +1 -1
  60. package/dist/auth/operations/login.d.ts +6 -9
  61. package/dist/auth/operations/login.d.ts.map +1 -1
  62. package/dist/auth/operations/login.js +41 -17
  63. package/dist/auth/operations/login.js.map +1 -1
  64. package/dist/auth/operations/logout.d.ts +2 -2
  65. package/dist/auth/operations/logout.d.ts.map +1 -1
  66. package/dist/auth/operations/logout.js.map +1 -1
  67. package/dist/auth/operations/me.d.ts +3 -3
  68. package/dist/auth/operations/me.d.ts.map +1 -1
  69. package/dist/auth/operations/me.js +25 -10
  70. package/dist/auth/operations/me.js.map +1 -1
  71. package/dist/auth/operations/refresh.d.ts +3 -3
  72. package/dist/auth/operations/refresh.d.ts.map +1 -1
  73. package/dist/auth/operations/refresh.js +35 -18
  74. package/dist/auth/operations/refresh.js.map +1 -1
  75. package/dist/auth/operations/registerFirstUser.d.ts +4 -7
  76. package/dist/auth/operations/registerFirstUser.d.ts.map +1 -1
  77. package/dist/auth/operations/registerFirstUser.js.map +1 -1
  78. package/dist/auth/operations/resetPassword.d.ts +2 -2
  79. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  80. package/dist/auth/operations/resetPassword.js +1 -0
  81. package/dist/auth/operations/resetPassword.js.map +1 -1
  82. package/dist/auth/operations/unlock.d.ts +2 -2
  83. package/dist/auth/operations/unlock.d.ts.map +1 -1
  84. package/dist/auth/operations/unlock.js.map +1 -1
  85. package/dist/auth/operations/verifyEmail.d.ts +2 -2
  86. package/dist/auth/operations/verifyEmail.d.ts.map +1 -1
  87. package/dist/auth/operations/verifyEmail.js.map +1 -1
  88. package/dist/auth/sendVerificationEmail.d.ts +2 -2
  89. package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
  90. package/dist/auth/sendVerificationEmail.js.map +1 -1
  91. package/dist/auth/strategies/apiKey.d.ts.map +1 -1
  92. package/dist/auth/strategies/apiKey.js +9 -3
  93. package/dist/auth/strategies/apiKey.js.map +1 -1
  94. package/dist/auth/strategies/jwt.d.ts.map +1 -1
  95. package/dist/auth/strategies/jwt.js +9 -3
  96. package/dist/auth/strategies/jwt.js.map +1 -1
  97. package/dist/auth/strategies/local/generatePasswordSaltHash.d.ts +3 -1
  98. package/dist/auth/strategies/local/generatePasswordSaltHash.d.ts.map +1 -1
  99. package/dist/auth/strategies/local/generatePasswordSaltHash.js +10 -7
  100. package/dist/auth/strategies/local/generatePasswordSaltHash.js.map +1 -1
  101. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts +2 -2
  102. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
  103. package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
  104. package/dist/auth/strategies/local/register.d.ts +2 -2
  105. package/dist/auth/strategies/local/register.d.ts.map +1 -1
  106. package/dist/auth/strategies/local/register.js +19 -7
  107. package/dist/auth/strategies/local/register.js.map +1 -1
  108. package/dist/auth/strategies/local/resetLoginAttempts.d.ts +2 -2
  109. package/dist/auth/strategies/local/resetLoginAttempts.d.ts.map +1 -1
  110. package/dist/auth/strategies/local/resetLoginAttempts.js.map +1 -1
  111. package/dist/auth/types.d.ts +21 -15
  112. package/dist/auth/types.d.ts.map +1 -1
  113. package/dist/auth/types.js.map +1 -1
  114. package/dist/collections/config/client.d.ts +7 -5
  115. package/dist/collections/config/client.d.ts.map +1 -1
  116. package/dist/collections/config/defaults.d.ts +8 -5
  117. package/dist/collections/config/defaults.d.ts.map +1 -1
  118. package/dist/collections/config/defaults.js +4 -1
  119. package/dist/collections/config/defaults.js.map +1 -1
  120. package/dist/collections/config/sanitize.d.ts.map +1 -1
  121. package/dist/collections/config/sanitize.js +3 -0
  122. package/dist/collections/config/sanitize.js.map +1 -1
  123. package/dist/collections/config/schema.d.ts.map +1 -1
  124. package/dist/collections/config/schema.js +8 -5
  125. package/dist/collections/config/schema.js.map +1 -1
  126. package/dist/collections/config/types.d.ts +50 -20
  127. package/dist/collections/config/types.d.ts.map +1 -1
  128. package/dist/collections/config/types.js.map +1 -1
  129. package/dist/collections/dataloader.d.ts.map +1 -1
  130. package/dist/collections/dataloader.js +1 -1
  131. package/dist/collections/dataloader.js.map +1 -1
  132. package/dist/collections/operations/count.d.ts +2 -2
  133. package/dist/collections/operations/count.d.ts.map +1 -1
  134. package/dist/collections/operations/count.js.map +1 -1
  135. package/dist/collections/operations/create.d.ts +2 -2
  136. package/dist/collections/operations/create.d.ts.map +1 -1
  137. package/dist/collections/operations/create.js.map +1 -1
  138. package/dist/collections/operations/delete.d.ts +2 -2
  139. package/dist/collections/operations/delete.d.ts.map +1 -1
  140. package/dist/collections/operations/delete.js.map +1 -1
  141. package/dist/collections/operations/deleteByID.d.ts +2 -2
  142. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  143. package/dist/collections/operations/deleteByID.js.map +1 -1
  144. package/dist/collections/operations/docAccess.d.ts +2 -2
  145. package/dist/collections/operations/docAccess.d.ts.map +1 -1
  146. package/dist/collections/operations/docAccess.js.map +1 -1
  147. package/dist/collections/operations/duplicate.d.ts +2 -2
  148. package/dist/collections/operations/duplicate.d.ts.map +1 -1
  149. package/dist/collections/operations/duplicate.js.map +1 -1
  150. package/dist/collections/operations/find.d.ts +2 -2
  151. package/dist/collections/operations/find.d.ts.map +1 -1
  152. package/dist/collections/operations/find.js.map +1 -1
  153. package/dist/collections/operations/findByID.d.ts +2 -2
  154. package/dist/collections/operations/findByID.d.ts.map +1 -1
  155. package/dist/collections/operations/findByID.js.map +1 -1
  156. package/dist/collections/operations/findVersionByID.d.ts +2 -2
  157. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  158. package/dist/collections/operations/findVersionByID.js.map +1 -1
  159. package/dist/collections/operations/findVersions.d.ts +2 -2
  160. package/dist/collections/operations/findVersions.d.ts.map +1 -1
  161. package/dist/collections/operations/findVersions.js.map +1 -1
  162. package/dist/collections/operations/local/count.d.ts +2 -2
  163. package/dist/collections/operations/local/count.d.ts.map +1 -1
  164. package/dist/collections/operations/local/count.js.map +1 -1
  165. package/dist/collections/operations/local/create.d.ts +2 -2
  166. package/dist/collections/operations/local/create.d.ts.map +1 -1
  167. package/dist/collections/operations/local/create.js.map +1 -1
  168. package/dist/collections/operations/local/delete.d.ts +2 -2
  169. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  170. package/dist/collections/operations/local/delete.js.map +1 -1
  171. package/dist/collections/operations/local/duplicate.d.ts +2 -2
  172. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  173. package/dist/collections/operations/local/duplicate.js.map +1 -1
  174. package/dist/collections/operations/local/find.d.ts +2 -2
  175. package/dist/collections/operations/local/find.d.ts.map +1 -1
  176. package/dist/collections/operations/local/find.js.map +1 -1
  177. package/dist/collections/operations/local/findByID.d.ts +2 -2
  178. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  179. package/dist/collections/operations/local/findByID.js.map +1 -1
  180. package/dist/collections/operations/local/findVersionByID.d.ts +2 -2
  181. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  182. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  183. package/dist/collections/operations/local/findVersions.d.ts +2 -2
  184. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  185. package/dist/collections/operations/local/findVersions.js.map +1 -1
  186. package/dist/collections/operations/local/restoreVersion.d.ts +2 -2
  187. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  188. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  189. package/dist/collections/operations/local/update.d.ts +2 -2
  190. package/dist/collections/operations/local/update.d.ts.map +1 -1
  191. package/dist/collections/operations/local/update.js.map +1 -1
  192. package/dist/collections/operations/restoreVersion.d.ts +2 -2
  193. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  194. package/dist/collections/operations/restoreVersion.js.map +1 -1
  195. package/dist/collections/operations/update.d.ts +2 -2
  196. package/dist/collections/operations/update.d.ts.map +1 -1
  197. package/dist/collections/operations/update.js.map +1 -1
  198. package/dist/collections/operations/updateByID.d.ts +2 -2
  199. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  200. package/dist/collections/operations/updateByID.js +1 -0
  201. package/dist/collections/operations/updateByID.js.map +1 -1
  202. package/dist/collections/operations/utils.d.ts +2 -2
  203. package/dist/collections/operations/utils.d.ts.map +1 -1
  204. package/dist/collections/operations/utils.js.map +1 -1
  205. package/dist/config/schema.d.ts.map +1 -1
  206. package/dist/config/schema.js +4 -2
  207. package/dist/config/schema.js.map +1 -1
  208. package/dist/config/types.d.ts +14 -4
  209. package/dist/config/types.d.ts.map +1 -1
  210. package/dist/config/types.js.map +1 -1
  211. package/dist/database/migrations/migrate.js.map +1 -1
  212. package/dist/database/migrations/migrateDown.js.map +1 -1
  213. package/dist/database/migrations/migrateRefresh.js.map +1 -1
  214. package/dist/database/migrations/migrateReset.js.map +1 -1
  215. package/dist/database/queryValidation/validateQueryPaths.d.ts +2 -2
  216. package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
  217. package/dist/database/queryValidation/validateQueryPaths.js +3 -3
  218. package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
  219. package/dist/database/queryValidation/validateSearchParams.d.ts +2 -2
  220. package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
  221. package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
  222. package/dist/database/types.d.ts +20 -20
  223. package/dist/database/types.d.ts.map +1 -1
  224. package/dist/database/types.js.map +1 -1
  225. package/dist/errors/APIError.d.ts.map +1 -1
  226. package/dist/errors/APIError.js +4 -1
  227. package/dist/errors/APIError.js.map +1 -1
  228. package/dist/errors/AuthenticationError.d.ts +1 -1
  229. package/dist/errors/AuthenticationError.d.ts.map +1 -1
  230. package/dist/errors/AuthenticationError.js +2 -2
  231. package/dist/errors/AuthenticationError.js.map +1 -1
  232. package/dist/errors/ValidationError.d.ts +13 -5
  233. package/dist/errors/ValidationError.d.ts.map +1 -1
  234. package/dist/errors/ValidationError.js +3 -3
  235. package/dist/errors/ValidationError.js.map +1 -1
  236. package/dist/fields/config/client.d.ts +84 -2
  237. package/dist/fields/config/client.d.ts.map +1 -1
  238. package/dist/fields/config/client.js +2 -1
  239. package/dist/fields/config/client.js.map +1 -1
  240. package/dist/fields/config/schema.d.ts.map +1 -1
  241. package/dist/fields/config/schema.js +1 -0
  242. package/dist/fields/config/schema.js.map +1 -1
  243. package/dist/fields/config/types.d.ts +19 -7
  244. package/dist/fields/config/types.d.ts.map +1 -1
  245. package/dist/fields/config/types.js.map +1 -1
  246. package/dist/fields/getDefaultValue.d.ts +2 -2
  247. package/dist/fields/getDefaultValue.d.ts.map +1 -1
  248. package/dist/fields/getDefaultValue.js.map +1 -1
  249. package/dist/fields/hooks/afterChange/index.d.ts +2 -2
  250. package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
  251. package/dist/fields/hooks/afterChange/index.js.map +1 -1
  252. package/dist/fields/hooks/afterChange/promise.d.ts +2 -2
  253. package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
  254. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  255. package/dist/fields/hooks/afterChange/traverseFields.d.ts +2 -2
  256. package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
  257. package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
  258. package/dist/fields/hooks/afterRead/index.d.ts +2 -2
  259. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
  260. package/dist/fields/hooks/afterRead/index.js.map +1 -1
  261. package/dist/fields/hooks/afterRead/promise.d.ts +2 -2
  262. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  263. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  264. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts +2 -2
  265. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
  266. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
  267. package/dist/fields/hooks/afterRead/traverseFields.d.ts +2 -2
  268. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
  269. package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
  270. package/dist/fields/hooks/beforeChange/index.d.ts +2 -2
  271. package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
  272. package/dist/fields/hooks/beforeChange/index.js +5 -1
  273. package/dist/fields/hooks/beforeChange/index.js.map +1 -1
  274. package/dist/fields/hooks/beforeChange/promise.d.ts +2 -2
  275. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  276. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  277. package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -2
  278. package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
  279. package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
  280. package/dist/fields/hooks/beforeValidate/index.d.ts +2 -2
  281. package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
  282. package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
  283. package/dist/fields/hooks/beforeValidate/promise.d.ts +2 -2
  284. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  285. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  286. package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +2 -2
  287. package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
  288. package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
  289. package/dist/fields/validations.d.ts +5 -1
  290. package/dist/fields/validations.d.ts.map +1 -1
  291. package/dist/globals/config/types.d.ts +7 -7
  292. package/dist/globals/config/types.d.ts.map +1 -1
  293. package/dist/globals/config/types.js.map +1 -1
  294. package/dist/globals/operations/docAccess.d.ts +2 -2
  295. package/dist/globals/operations/docAccess.d.ts.map +1 -1
  296. package/dist/globals/operations/docAccess.js.map +1 -1
  297. package/dist/globals/operations/findOne.d.ts +2 -2
  298. package/dist/globals/operations/findOne.d.ts.map +1 -1
  299. package/dist/globals/operations/findOne.js.map +1 -1
  300. package/dist/globals/operations/findVersionByID.d.ts +2 -2
  301. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  302. package/dist/globals/operations/findVersionByID.js.map +1 -1
  303. package/dist/globals/operations/findVersions.d.ts +2 -2
  304. package/dist/globals/operations/findVersions.d.ts.map +1 -1
  305. package/dist/globals/operations/findVersions.js.map +1 -1
  306. package/dist/globals/operations/local/findOne.d.ts +2 -2
  307. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  308. package/dist/globals/operations/local/findOne.js.map +1 -1
  309. package/dist/globals/operations/local/findVersionByID.d.ts +2 -2
  310. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  311. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  312. package/dist/globals/operations/local/findVersions.d.ts +2 -2
  313. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  314. package/dist/globals/operations/local/findVersions.js.map +1 -1
  315. package/dist/globals/operations/local/restoreVersion.d.ts +2 -2
  316. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  317. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  318. package/dist/globals/operations/local/update.d.ts +2 -2
  319. package/dist/globals/operations/local/update.d.ts.map +1 -1
  320. package/dist/globals/operations/local/update.js.map +1 -1
  321. package/dist/globals/operations/restoreVersion.d.ts +2 -2
  322. package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
  323. package/dist/globals/operations/restoreVersion.js.map +1 -1
  324. package/dist/globals/operations/update.d.ts +2 -2
  325. package/dist/globals/operations/update.d.ts.map +1 -1
  326. package/dist/globals/operations/update.js.map +1 -1
  327. package/dist/index.d.ts +21 -1
  328. package/dist/index.d.ts.map +1 -1
  329. package/dist/index.js +2 -0
  330. package/dist/index.js.map +1 -1
  331. package/dist/preferences/deleteUserPreferences.d.ts +2 -2
  332. package/dist/preferences/deleteUserPreferences.d.ts.map +1 -1
  333. package/dist/preferences/deleteUserPreferences.js.map +1 -1
  334. package/dist/preferences/requestHandlers/delete.js.map +1 -1
  335. package/dist/preferences/requestHandlers/findOne.js.map +1 -1
  336. package/dist/preferences/requestHandlers/update.js.map +1 -1
  337. package/dist/preferences/types.d.ts +3 -3
  338. package/dist/preferences/types.d.ts.map +1 -1
  339. package/dist/preferences/types.js.map +1 -1
  340. package/dist/types/index.d.ts +16 -5
  341. package/dist/types/index.d.ts.map +1 -1
  342. package/dist/types/index.js.map +1 -1
  343. package/dist/uploads/deleteAssociatedFiles.d.ts +2 -2
  344. package/dist/uploads/deleteAssociatedFiles.d.ts.map +1 -1
  345. package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
  346. package/dist/uploads/docWithFilenameExists.d.ts +2 -2
  347. package/dist/uploads/docWithFilenameExists.d.ts.map +1 -1
  348. package/dist/uploads/docWithFilenameExists.js.map +1 -1
  349. package/dist/uploads/generateFileData.d.ts +2 -2
  350. package/dist/uploads/generateFileData.d.ts.map +1 -1
  351. package/dist/uploads/generateFileData.js.map +1 -1
  352. package/dist/uploads/getExternalFile.d.ts +2 -2
  353. package/dist/uploads/getExternalFile.d.ts.map +1 -1
  354. package/dist/uploads/getExternalFile.js.map +1 -1
  355. package/dist/uploads/getFileByPath.d.ts +2 -2
  356. package/dist/uploads/getFileByPath.d.ts.map +1 -1
  357. package/dist/uploads/getFileByPath.js.map +1 -1
  358. package/dist/uploads/getImageSize.d.ts +2 -2
  359. package/dist/uploads/getImageSize.d.ts.map +1 -1
  360. package/dist/uploads/getImageSize.js.map +1 -1
  361. package/dist/uploads/getSafeFilename.d.ts +2 -2
  362. package/dist/uploads/getSafeFilename.d.ts.map +1 -1
  363. package/dist/uploads/getSafeFilename.js.map +1 -1
  364. package/dist/uploads/imageResizer.d.ts +3 -3
  365. package/dist/uploads/imageResizer.d.ts.map +1 -1
  366. package/dist/uploads/imageResizer.js.map +1 -1
  367. package/dist/uploads/types.d.ts +2 -2
  368. package/dist/uploads/types.d.ts.map +1 -1
  369. package/dist/uploads/types.js.map +1 -1
  370. package/dist/uploads/unlinkTempFiles.d.ts +2 -2
  371. package/dist/uploads/unlinkTempFiles.d.ts.map +1 -1
  372. package/dist/uploads/unlinkTempFiles.js.map +1 -1
  373. package/dist/uploads/uploadFiles.d.ts +2 -2
  374. package/dist/uploads/uploadFiles.d.ts.map +1 -1
  375. package/dist/uploads/uploadFiles.js.map +1 -1
  376. package/dist/utilities/commitTransaction.d.ts +2 -2
  377. package/dist/utilities/commitTransaction.d.ts.map +1 -1
  378. package/dist/utilities/commitTransaction.js.map +1 -1
  379. package/dist/utilities/configToJSONSchema.d.ts +1 -0
  380. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  381. package/dist/utilities/configToJSONSchema.js +104 -4
  382. package/dist/utilities/configToJSONSchema.js.map +1 -1
  383. package/dist/utilities/configToJSONSchema.spec.js +58 -0
  384. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  385. package/dist/utilities/createLocalReq.d.ts +3 -3
  386. package/dist/utilities/createLocalReq.d.ts.map +1 -1
  387. package/dist/utilities/createLocalReq.js.map +1 -1
  388. package/dist/utilities/getEntityPolicies.d.ts +2 -2
  389. package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
  390. package/dist/utilities/getEntityPolicies.js.map +1 -1
  391. package/dist/utilities/initTransaction.d.ts +2 -2
  392. package/dist/utilities/initTransaction.d.ts.map +1 -1
  393. package/dist/utilities/initTransaction.js.map +1 -1
  394. package/dist/utilities/isEntityHidden.d.ts +2 -2
  395. package/dist/utilities/isEntityHidden.d.ts.map +1 -1
  396. package/dist/utilities/isEntityHidden.js.map +1 -1
  397. package/dist/utilities/killTransaction.d.ts +2 -2
  398. package/dist/utilities/killTransaction.d.ts.map +1 -1
  399. package/dist/utilities/killTransaction.js.map +1 -1
  400. package/dist/utilities/logger.js.map +1 -1
  401. package/dist/utilities/telemetry/events/adminInit.d.ts +2 -2
  402. package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
  403. package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
  404. package/dist/versions/deleteCollectionVersions.d.ts +2 -2
  405. package/dist/versions/deleteCollectionVersions.d.ts.map +1 -1
  406. package/dist/versions/deleteCollectionVersions.js.map +1 -1
  407. package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts +2 -2
  408. package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
  409. package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
  410. package/dist/versions/enforceMaxVersions.d.ts +2 -2
  411. package/dist/versions/enforceMaxVersions.d.ts.map +1 -1
  412. package/dist/versions/enforceMaxVersions.js.map +1 -1
  413. package/dist/versions/getLatestCollectionVersion.d.ts +2 -2
  414. package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
  415. package/dist/versions/getLatestCollectionVersion.js.map +1 -1
  416. package/dist/versions/getLatestGlobalVersion.d.ts +2 -2
  417. package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
  418. package/dist/versions/getLatestGlobalVersion.js.map +1 -1
  419. package/dist/versions/saveVersion.d.ts +2 -2
  420. package/dist/versions/saveVersion.d.ts.map +1 -1
  421. package/dist/versions/saveVersion.js.map +1 -1
  422. package/package.json +2 -2
@@ -170,7 +170,7 @@ export function fieldsToJSONSchema(/**
170
170
  }
171
171
  case 'json':
172
172
  {
173
- fieldSchema = {
173
+ fieldSchema = field.jsonSchema?.schema || {
174
174
  type: [
175
175
  'object',
176
176
  'array',
@@ -472,6 +472,13 @@ export function fieldsToJSONSchema(/**
472
472
  break;
473
473
  }
474
474
  }
475
+ if ('typescriptSchema' in field && field?.typescriptSchema?.length) {
476
+ for (const schema of field.typescriptSchema){
477
+ fieldSchema = schema({
478
+ jsonSchema: fieldSchema
479
+ });
480
+ }
481
+ }
475
482
  if (fieldSchema && fieldAffectsData(field)) {
476
483
  fieldSchemas.set(field.name, fieldSchema);
477
484
  }
@@ -525,6 +532,80 @@ export function entityToJSONSchema(config, incomingEntity, interfaceNameDefiniti
525
532
  ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config)
526
533
  };
527
534
  }
535
+ function generateOperationJSONSchema(config, operation) {
536
+ const usernameLogin = config.auth?.loginWithUsername;
537
+ const fieldType = {
538
+ type: 'string'
539
+ };
540
+ let properties = {};
541
+ switch(operation){
542
+ case 'login':
543
+ {
544
+ properties = {
545
+ password: fieldType,
546
+ [usernameLogin ? 'username' : 'email']: fieldType
547
+ };
548
+ break;
549
+ }
550
+ case 'forgotPassword':
551
+ {
552
+ properties = {
553
+ [usernameLogin ? 'username' : 'email']: fieldType
554
+ };
555
+ break;
556
+ }
557
+ case 'registerFirstUser':
558
+ {
559
+ properties = {
560
+ email: fieldType,
561
+ password: fieldType
562
+ };
563
+ if (usernameLogin) properties.username = fieldType;
564
+ break;
565
+ }
566
+ }
567
+ return {
568
+ additionalProperties: false,
569
+ properties,
570
+ required: Object.keys(properties)
571
+ };
572
+ }
573
+ export function authCollectionToOperationsJSONSchema(config) {
574
+ const properties = {
575
+ forgotPassword: {
576
+ ...generateOperationJSONSchema(config, 'forgotPassword')
577
+ },
578
+ login: {
579
+ ...generateOperationJSONSchema(config, 'login')
580
+ },
581
+ registerFirstUser: {
582
+ ...generateOperationJSONSchema(config, 'registerFirstUser')
583
+ }
584
+ };
585
+ return {
586
+ type: 'object',
587
+ additionalProperties: false,
588
+ properties,
589
+ required: Object.keys(properties),
590
+ title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`
591
+ };
592
+ }
593
+ function generateAuthOperationSchemas(collections) {
594
+ const properties = collections.reduce((acc, collection)=>{
595
+ if (collection.auth) {
596
+ acc[collection.slug] = {
597
+ $ref: `#/definitions/auth/${collection.slug}`
598
+ };
599
+ }
600
+ return acc;
601
+ }, {});
602
+ return {
603
+ type: 'object',
604
+ additionalProperties: false,
605
+ properties,
606
+ required: Object.keys(properties)
607
+ };
608
+ }
528
609
  /**
529
610
  * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.
530
611
  */ export function configToJSONSchema(config, defaultIDType) {
@@ -539,15 +620,25 @@ export function entityToJSONSchema(config, incomingEntity, interfaceNameDefiniti
539
620
  acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType);
540
621
  return acc;
541
622
  }, {});
542
- return {
623
+ const authOperationDefinitions = [
624
+ ...config.collections
625
+ ].filter(({ auth })=>Boolean(auth)).reduce((acc, authCollection)=>{
626
+ acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection);
627
+ return acc;
628
+ }, {
629
+ auth: {}
630
+ });
631
+ let jsonSchema = {
543
632
  additionalProperties: false,
544
633
  definitions: {
545
634
  ...entityDefinitions,
546
- ...Object.fromEntries(interfaceNameDefinitions)
635
+ ...Object.fromEntries(interfaceNameDefinitions),
636
+ ...authOperationDefinitions
547
637
  },
548
638
  // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type
549
639
  type: 'object',
550
640
  properties: {
641
+ auth: generateAuthOperationSchemas(config.collections),
551
642
  collections: generateEntitySchemas(config.collections || []),
552
643
  globals: generateEntitySchemas(config.globals || []),
553
644
  locale: generateLocaleEntitySchemas(config.localization),
@@ -557,10 +648,19 @@ export function entityToJSONSchema(config, incomingEntity, interfaceNameDefiniti
557
648
  'user',
558
649
  'locale',
559
650
  'collections',
560
- 'globals'
651
+ 'globals',
652
+ 'auth'
561
653
  ],
562
654
  title: 'Config'
563
655
  };
656
+ if (config?.typescript?.schema?.length) {
657
+ for (const schema of config.typescript.schema){
658
+ jsonSchema = schema({
659
+ jsonSchema
660
+ });
661
+ }
662
+ }
663
+ return jsonSchema;
564
664
  }
565
665
 
566
666
  //# sourceMappingURL=configToJSONSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\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 if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n return {\n additionalProperties: false,\n definitions: { ...entityDefinitions, ...Object.fromEntries(interfaceNameDefinitions) },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n collections: generateEntitySchemas(config.collections || []),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals'],\n title: 'Config',\n }\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","config","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","Map","from","entityToJSONSchema","incomingEntity","defaultIDType","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","configToJSONSchema","entityDefinitions","globals","collections","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAOrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe,OAAO;IAE1B,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIZ,iBAAiBM,UAAUK,kB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EACvBsC,aAAiC;IAEjC,yJAAyJ;IACzJ,MAAMvC,2BAAqD,IAAImC;IAE/D,gLAAgL;IAChL,+CAA+C;IAC/C,MAAMgB,oBAAkD;WACnDlD,OAAOmD,OAAO;WACdnD,OAAOoD,WAAW;KACtB,CAAChF,MAAM,CAAC,CAACC,KAAKkE;QACblE,GAAG,CAACkE,OAAOjE,IAAI,CAAC,GAAG8D,mBAAmBpC,QAAQuC,QAAQxC,0BAA0BuC;QAChF,OAAOjE;IACT,GAAG,CAAC;IAEJ,OAAO;QACLG,sBAAsB;QACtB6E,aAAa;YAAE,GAAGH,iBAAiB;YAAE,GAAGzE,OAAO0B,WAAW,CAACJ,yBAAyB;QAAC;QACrF,wJAAwJ;QACxJzC,MAAM;QACNa,YAAY;YACViF,aAAanF,sBAAsB+B,OAAOoD,WAAW,IAAI,EAAE;YAC3DD,SAASlF,sBAAsB+B,OAAOmD,OAAO,IAAI,EAAE;YACnDpE,QAAQJ,4BAA4BqB,OAAOpB,YAAY;YACvD0E,MAAMpE,0BAA0Bc,OAAOoD,WAAW;QACpD;QACA/F,UAAU;YAAC;YAAQ;YAAU;YAAe;SAAU;QACtDmF,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\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 if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema })\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\nfunction generateOperationJSONSchema(\n config: SanitizedCollectionConfig,\n operation: 'forgotPassword' | 'login' | 'registerFirstUser',\n): JSONSchema4 {\n const usernameLogin = config.auth?.loginWithUsername\n const fieldType: JSONSchema4 = {\n type: 'string',\n }\n\n let properties: JSONSchema4['properties'] = {}\n switch (operation) {\n case 'login': {\n properties = {\n password: fieldType,\n [usernameLogin ? 'username' : 'email']: fieldType,\n }\n break\n }\n case 'forgotPassword': {\n properties = {\n [usernameLogin ? 'username' : 'email']: fieldType,\n }\n break\n }\n case 'registerFirstUser': {\n properties = {\n email: fieldType,\n password: fieldType,\n }\n if (usernameLogin) properties.username = fieldType\n break\n }\n }\n\n return {\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const properties = {\n forgotPassword: {\n ...generateOperationJSONSchema(config, 'forgotPassword'),\n },\n login: {\n ...generateOperationJSONSchema(config, 'login'),\n },\n registerFirstUser: {\n ...generateOperationJSONSchema(config, 'registerFirstUser'),\n },\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n ...entityDefinitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n collections: generateEntitySchemas(config.collections || []),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","config","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","defaultIDType","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateOperationJSONSchema","operation","usernameLogin","loginWithUsername","password","email","username","authCollectionToOperationsJSONSchema","forgotPassword","login","registerFirstUser","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAG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AAM,CACL,CAACC,KAAKiG;QACJjG,IAAIe,IAAI,CAACkF,eAAehG,IAAI,CAAC,GAAGsF,qCAAqCU;QACrE,OAAOjG;IACT,GACA;QAAEe,MAAM,CAAC;IAAE;IAGf,IAAIsB,aAA0B;QAC5BlC,sBAAsB;QACtB+F,aAAa;YACX,GAAGJ,iBAAiB;YACpB,GAAG1F,OAAO0B,WAAW,CAACJ,yBAAyB;YAC/C,GAAGsE,wBAAwB;QAC7B;QACA,wJAAwJ;QACxJ/G,MAAM;QACNa,YAAY;YACViB,MAAM4E,6BAA6BhE,OAAOiE,WAAW;YACrDA,aAAahG,sBAAsB+B,OAAOiE,WAAW,IAAI,EAAE;YAC3DG,SAASnG,sBAAsB+B,OAAOoE,OAAO,IAAI,EAAE;YACnDrF,QAAQJ,4BAA4BqB,OAAOpB,YAAY;YACvD4F,MAAMtF,0BAA0Bc,OAAOiE,WAAW;QACpD;QACA5G,UAAU;YAAC;YAAQ;YAAU;YAAe;YAAW;SAAO;QAC9DuF,OAAO;IACT;IAEA,IAAI5C,QAAQ6C,YAAYlC,QAAQ0B,QAAQ;QACtC,KAAK,MAAM1B,UAAUX,OAAO6C,UAAU,CAAClC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
@@ -159,6 +159,64 @@ describe('configToJSONSchema', ()=>{
159
159
  type: 'object'
160
160
  });
161
161
  });
162
+ it('should handle custom typescript schema and JSON field schema', async ()=>{
163
+ const customSchema = {
164
+ type: 'object',
165
+ properties: {
166
+ id: {
167
+ type: 'number'
168
+ },
169
+ required: [
170
+ 'id'
171
+ ]
172
+ }
173
+ };
174
+ const config = {
175
+ collections: [
176
+ {
177
+ fields: [
178
+ {
179
+ type: 'text',
180
+ name: 'withCustom',
181
+ typescriptSchema: [
182
+ ()=>customSchema
183
+ ]
184
+ },
185
+ {
186
+ type: 'json',
187
+ name: 'jsonWithSchema',
188
+ jsonSchema: {
189
+ uri: 'a://b/foo.json',
190
+ fileMatch: [
191
+ 'a://b/foo.json'
192
+ ],
193
+ schema: customSchema
194
+ }
195
+ }
196
+ ],
197
+ slug: 'test',
198
+ timestamps: false
199
+ }
200
+ ]
201
+ };
202
+ const sanitizedConfig = await sanitizeConfig(config);
203
+ const schema = configToJSONSchema(sanitizedConfig, 'text');
204
+ expect(schema?.definitions?.test).toStrictEqual({
205
+ additionalProperties: false,
206
+ properties: {
207
+ id: {
208
+ type: 'string'
209
+ },
210
+ withCustom: customSchema,
211
+ jsonWithSchema: customSchema
212
+ },
213
+ required: [
214
+ 'id'
215
+ ],
216
+ title: 'Test',
217
+ type: 'object'
218
+ });
219
+ });
162
220
  });
163
221
 
164
222
  //# sourceMappingURL=configToJSONSchema.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n required: true,\n type: 'text',\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n items: {\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n type: 'object',\n },\n type: ['array', 'null'],\n },\n },\n required: ['id'],\n title: 'Test',\n type: 'object',\n })\n })\n\n it('should handle tabs and named tabs with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n label: 'unnamedTab',\n fields: [\n {\n type: 'text',\n name: 'fieldInUnnamedTab',\n },\n ],\n },\n {\n label: 'namedTab',\n name: 'namedTab',\n fields: [\n {\n type: 'text',\n name: 'fieldInNamedTab',\n },\n ],\n },\n {\n label: 'namedTabWithRequired',\n name: 'namedTabWithRequired',\n fields: [\n {\n type: 'text',\n name: 'fieldInNamedTab',\n required: true,\n },\n ],\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n fieldInUnnamedTab: {\n type: ['string', 'null'],\n },\n namedTab: {\n additionalProperties: false,\n type: 'object',\n properties: {\n fieldInNamedTab: {\n type: ['string', 'null'],\n },\n },\n required: [],\n },\n namedTabWithRequired: {\n additionalProperties: false,\n type: 'object',\n properties: {\n fieldInNamedTab: {\n type: 'string',\n },\n },\n required: ['fieldInNamedTab'],\n },\n },\n required: ['id', 'namedTabWithRequired'],\n title: 'Test',\n type: 'object',\n })\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","fields","name","type","required","slug","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title","tabs","label","fieldInUnnamedTab","namedTab","fieldInNamedTab","namedTabWithRequired"],"mappings":"AAEA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNE,UAAU;oCACVD,MAAM;gCACR;6BACD;w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gBACAkB,mBAAmB;oBACjBlB,MAAM;wBAAC;wBAAU;qBAAO;gBAC1B;gBACAmB,UAAU;oBACRT,sBAAsB;oBACtBV,MAAM;oBACNW,YAAY;wBACVS,iBAAiB;4BACfpB,MAAM;gCAAC;gCAAU;6BAAO;wBAC1B;oBACF;oBACAC,UAAU,EAAE;gBACd;gBACAoB,sBAAsB;oBACpBX,sBAAsB;oBACtBV,MAAM;oBACNW,YAAY;wBACVS,iBAAiB;4BACfpB,MAAM;wBACR;oBACF;oBACAC,UAAU;wBAAC;qBAAkB;gBAC/B;YACF;YACAA,UAAU;gBAAC;gBAAM;aAAuB;YACxCc,OAAO;YACPf,MAAM;QACR;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\nimport { JSONSchema4 } from 'json-schema'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n required: true,\n type: 'text',\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n items: {\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n type: 'object',\n },\n type: ['array', 'null'],\n },\n },\n required: ['id'],\n title: 'Test',\n type: 'object',\n })\n })\n\n it('should handle tabs and named tabs with required fields', async () => {\n // @ts-expect-error\n const config: Config = {\n collections: [\n {\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n label: 'unnamedTab',\n fields: [\n {\n type: 'text',\n name: 'fieldInUnnamedTab',\n },\n ],\n },\n {\n label: 'namedTab',\n name: 'namedTab',\n fields: [\n {\n type: 'text',\n name: 'fieldInNamedTab',\n },\n ],\n },\n {\n label: 'namedTabWithRequired',\n name: 'namedTabWithRequired',\n fields: [\n {\n type: 'text',\n name: 'fieldInNamedTab',\n required: true,\n },\n ],\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n fieldInUnnamedTab: {\n type: ['string', 'null'],\n },\n namedTab: {\n additionalProperties: false,\n type: 'object',\n properties: {\n fieldInNamedTab: {\n type: ['string', 'null'],\n },\n },\n required: [],\n },\n namedTabWithRequired: {\n additionalProperties: false,\n type: 'object',\n properties: {\n fieldInNamedTab: {\n type: 'string',\n },\n },\n required: ['fieldInNamedTab'],\n },\n },\n required: ['id', 'namedTabWithRequired'],\n title: 'Test',\n type: 'object',\n })\n })\n\n it('should handle custom typescript schema and JSON field schema', async () => {\n const customSchema: JSONSchema4 = {\n type: 'object',\n properties: {\n id: {\n type: 'number',\n },\n required: ['id'],\n },\n }\n\n const config: Partial<Config> = {\n collections: [\n {\n fields: [\n {\n type: 'text',\n name: 'withCustom',\n typescriptSchema: [() => customSchema],\n },\n {\n type: 'json',\n name: 'jsonWithSchema',\n jsonSchema: {\n uri: 'a://b/foo.json',\n fileMatch: ['a://b/foo.json'],\n schema: customSchema,\n },\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config as Config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n withCustom: customSchema,\n jsonWithSchema: customSchema,\n },\n required: ['id'],\n title: 'Test',\n type: 'object',\n })\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","fields","name","type","required","slug","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title","tabs","label","fieldInUnnamedTab","namedTab","fieldInNamedTab","namedTabWithRequired","customSchema","typescriptSchema","jsonSchema","uri","fileMatch","withCustom","jsonWithSchema"],"mappings":"AAEA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAG5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNE,UAAU;oCACVD,MAAM;gCACR;6BACD;wBACH;qBACD;oBACDE,MAAM;oBACNC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMZ,eAAeI;QAC7C,MAAMS,SAASZ,mBAAmBW,iBAAiB;QAEnDE,OAAOD,QAAQE,aAAaC,MAAMC,aAAa,CAAC;YAC9CC,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFZ,MAAM;gBACR;gBACAa,mBAAmB;oBACjBC,OAAO;wBACLJ,sBAAsB;wBACtBC,YAAY;4BACVC,IAAI;gCACFZ,MAAM;oCAAC;oCAAU;iCAAO;4BAC1B;4BACAa,mBAAmB;gCACjBb,MAAM;4BACR;wBACF;wBACAC,UAAU;4BAAC;yBAAoB;wBAC/BD,MAAM;oBACR;oBACAA,MAAM;wBAAC;wBAAS;qBAAO;gBACzB;YACF;YACAC,UAAU;gBAAC;aAAK;YAChBc,OAAO;YACPf,MAAM;QACR;IACF;IAEAL,GAAG,0DAA0D;QAC3D,mBAAmB;QACnB,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,Q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MAAM;4BACNwB,kBAAkB;gCAAC,IAAMD;6BAAa;wBACxC;wBACA;4BACEtB,MAAM;4BACND,MAAM;4BACNyB,YAAY;gCACVC,KAAK;gCACLC,WAAW;oCAAC;iCAAiB;gCAC7BrB,QAAQiB;4BACV;wBACF;qBACD;oBACDpB,MAAM;oBACNC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMZ,eAAeI;QAC7C,MAAMS,SAASZ,mBAAmBW,iBAAiB;QAEnDE,OAAOD,QAAQE,aAAaC,MAAMC,aAAa,CAAC;YAC9CC,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFZ,MAAM;gBACR;gBACA2B,YAAYL;gBACZM,gBAAgBN;YAClB;YACArB,UAAU;gBAAC;aAAK;YAChBc,OAAO;YACPf,MAAM;QACR;IACF;AACF"}
@@ -1,13 +1,13 @@
1
1
  import type { User } from '../auth/types.js';
2
2
  import type { Payload, RequestContext } from '../index.js';
3
- import type { PayloadRequestWithData } from '../types/index.js';
3
+ import type { PayloadRequest } from '../types/index.js';
4
4
  type CreateLocalReq = (options: {
5
5
  context?: RequestContext;
6
6
  fallbackLocale?: string;
7
7
  locale?: string;
8
- req?: PayloadRequestWithData;
8
+ req?: PayloadRequest;
9
9
  user?: User;
10
- }, payload: Payload) => Promise<PayloadRequestWithData>;
10
+ }, payload: Payload) => Promise<PayloadRequest>;
11
11
  export declare const createLocalReq: CreateLocalReq;
12
12
  export {};
13
13
  //# sourceMappingURL=createLocalReq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createLocalReq.d.ts","sourceRoot":"","sources":["../../src/utilities/createLocalReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAsD/D,KAAK,cAAc,GAAG,CACpB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,sBAAsB,CAAA;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,sBAAsB,CAAC,CAAA;AACpC,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAA"}
1
+ {"version":3,"file":"createLocalReq.d.ts","sourceRoot":"","sources":["../../src/utilities/createLocalReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAsDvD,KAAK,cAAc,GAAG,CACpB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,cAAc,CAAC,CAAA;AAC5B,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nimport { getDataLoader } from '../collections/dataloader.js'\nimport { getLocalI18n } from '../translations/getLocalI18n.js'\n\nfunction getRequestContext(\n req: PayloadRequestWithData = { context: null } as PayloadRequestWithData,\n context: RequestContext = {},\n): RequestContext {\n if (req.context) {\n if (Object.keys(req.context).length === 0 && req.context.constructor === Object) {\n // if req.context is `{}` avoid unnecessary spread\n return context\n } else {\n return { ...req.context, ...context }\n }\n } else {\n return context\n }\n}\n\nconst attachFakeURLProperties = (req: PayloadRequestWithData) => {\n /**\n * *NOTE*\n * If no URL is provided, the local API was called directly outside\n * the context of a request. Therefore we create a fake URL object.\n * `ts-expect-error` is used below for properties that are 'read-only'\n * since they do not exist yet we can safely ignore the error.\n */\n let urlObject\n\n function getURLObject() {\n if (urlObject) return urlObject\n const urlToUse = req?.url || req.payload.config?.serverURL || 'http://localhost'\n try {\n urlObject = new URL(urlToUse)\n } catch (error) {\n urlObject = new URL('http://localhost')\n }\n\n return urlObject\n }\n\n if (!req.host) req.host = getURLObject().host\n if (!req.protocol) req.protocol = getURLObject().protocol\n if (!req.pathname) req.pathname = getURLObject().pathname\n // @ts-expect-error\n if (!req.searchParams) req.searchParams = getURLObject().searchParams\n // @ts-expect-error\n if (!req.origin) req.origin = getURLObject().origin\n // @ts-expect-error\n if (!req?.url) req.url = getURLObject().href\n}\n\ntype CreateLocalReq = (\n options: {\n context?: RequestContext\n fallbackLocale?: string\n locale?: string\n req?: PayloadRequestWithData\n user?: User\n },\n payload: Payload,\n) => Promise<PayloadRequestWithData>\nexport const createLocalReq: CreateLocalReq = async (\n { context, fallbackLocale, locale: localeArg, req = {} as PayloadRequestWithData, user },\n payload,\n) => {\n if (payload.config?.localization) {\n const locale = localeArg === '*' ? 'all' : localeArg\n const defaultLocale = payload.config.localization.defaultLocale\n req.locale = locale || req?.locale || defaultLocale\n const fallbackLocaleFromConfig = payload.config.localization.locales.find(\n ({ code }) => req.locale === code,\n )?.fallbackLocale\n if (typeof fallbackLocale !== 'undefined') {\n req.fallbackLocale = fallbackLocale\n } else if (typeof req?.fallbackLocale === 'undefined') {\n req.fallbackLocale = fallbackLocaleFromConfig || defaultLocale\n }\n }\n\n const i18n =\n req?.i18n ||\n (await getLocalI18n({ config: payload.config, language: payload.config.i18n.fallbackLanguage }))\n\n // @ts-expect-error\n if (!req.headers) req.headers = new Headers()\n req.context = getRequestContext(req, context)\n req.payloadAPI = req?.payloadAPI || 'local'\n req.payload = payload\n req.i18n = i18n\n req.t = i18n.t\n req.user = user || req?.user || null\n req.payloadDataLoader = req?.payloadDataLoader || getDataLoader(req)\n req.routeParams = req?.routeParams || {}\n req.query = req?.query || {}\n\n attachFakeURLProperties(req)\n\n return req\n}\n"],"names":["getDataLoader","getLocalI18n","getRequestContext","req","context","Object","keys","length","constructor","attachFakeURLProperties","urlObject","getURLObject","urlToUse","url","payload","config","serverURL","URL","error","host","protocol","pathname","searchParams","origin","href","createLocalReq","fallbackLocale","locale","localeArg","user","localization","defaultLocale","fallbackLocaleFromConfig","locales","find","code","i18n","language","fallbackLanguage","headers","Headers","payloadAPI","t","payloadDataLoader","routeParams","query"],"mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,kBACPC,MAA8B;IAAEC,SAAS;AAAK,CAA2B,EACzEA,UAA0B,CAAC,CAAC;IAE5B,IAAID,IAAIC,OAAO,EAAE;QACf,IAAIC,OAAOC,IAAI,CAACH,IAAIC,OAAO,EAAEG,MAAM,KAAK,KAAKJ,IAAIC,OAAO,CAACI,WAAW,KAAKH,QAAQ;YAC/E,kDAAkD;YAClD,OAAOD;QACT,OAAO;YACL,OAAO;gBAAE,GAAGD,IAAIC,OAAO;gBAAE,GAAGA,OAAO;YAAC;QACtC;IACF,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMK,0BAA0B,CAACN;IAC/B;;;;;;GAMC,GACD,IAAIO;IAEJ,SAASC;QACP,IAAID,WAAW,OAAOA;QACtB,MAAME,WAAWT,KAAKU,OAAOV,IAAIW,OAAO,CAACC,MAAM,EAAEC,aAAa;QAC9D,IAAI;YACFN,YAAY,IAAIO,IAAIL;QACtB,EAAE,OAAOM,OAAO;YACdR,YAAY,IAAIO,IAAI;QACtB;QAEA,OAAOP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QAAEsB,UAAUvB,QAAQC,MAAM,CAACqB,IAAI,CAACE,gBAAgB;IAAC;IAE/F,mBAAmB;IACnB,IAAI,CAACnC,IAAIoC,OAAO,EAAEpC,IAAIoC,OAAO,GAAG,IAAIC;IACpCrC,IAAIC,OAAO,GAAGF,kBAAkBC,KAAKC;IACrCD,IAAIsC,UAAU,GAAGtC,KAAKsC,cAAc;IACpCtC,IAAIW,OAAO,GAAGA;IACdX,IAAIiC,IAAI,GAAGA;IACXjC,IAAIuC,CAAC,GAAGN,KAAKM,CAAC;IACdvC,IAAI0B,IAAI,GAAGA,QAAQ1B,KAAK0B,QAAQ;IAChC1B,IAAIwC,iBAAiB,GAAGxC,KAAKwC,qBAAqB3C,cAAcG;IAChEA,IAAIyC,WAAW,GAAGzC,KAAKyC,eAAe,CAAC;IACvCzC,IAAI0C,KAAK,GAAG1C,KAAK0C,SAAS,CAAC;IAE3BpC,wBAAwBN;IAExB,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { getDataLoader } from '../collections/dataloader.js'\nimport { getLocalI18n } from '../translations/getLocalI18n.js'\n\nfunction getRequestContext(\n req: PayloadRequest = { context: null } as PayloadRequest,\n context: RequestContext = {},\n): RequestContext {\n if (req.context) {\n if (Object.keys(req.context).length === 0 && req.context.constructor === Object) {\n // if req.context is `{}` avoid unnecessary spread\n return context\n } else {\n return { ...req.context, ...context }\n }\n } else {\n return context\n }\n}\n\nconst attachFakeURLProperties = (req: PayloadRequest) => {\n /**\n * *NOTE*\n * If no URL is provided, the local API was called directly outside\n * the context of a request. Therefore we create a fake URL object.\n * `ts-expect-error` is used below for properties that are 'read-only'\n * since they do not exist yet we can safely ignore the error.\n */\n let urlObject\n\n function getURLObject() {\n if (urlObject) return urlObject\n const urlToUse = req?.url || req.payload.config?.serverURL || 'http://localhost'\n try {\n urlObject = new URL(urlToUse)\n } catch (error) {\n urlObject = new URL('http://localhost')\n }\n\n return urlObject\n }\n\n if (!req.host) req.host = getURLObject().host\n if (!req.protocol) req.protocol = getURLObject().protocol\n if (!req.pathname) req.pathname = getURLObject().pathname\n // @ts-expect-error\n if (!req.searchParams) req.searchParams = getURLObject().searchParams\n // @ts-expect-error\n if (!req.origin) req.origin = getURLObject().origin\n // @ts-expect-error\n if (!req?.url) req.url = getURLObject().href\n}\n\ntype CreateLocalReq = (\n options: {\n context?: RequestContext\n fallbackLocale?: string\n locale?: string\n req?: PayloadRequest\n user?: User\n },\n payload: Payload,\n) => Promise<PayloadRequest>\nexport const createLocalReq: CreateLocalReq = async (\n { context, fallbackLocale, locale: localeArg, req = {} as PayloadRequest, user },\n payload,\n) => {\n if (payload.config?.localization) {\n const locale = localeArg === '*' ? 'all' : localeArg\n const defaultLocale = payload.config.localization.defaultLocale\n req.locale = locale || req?.locale || defaultLocale\n const fallbackLocaleFromConfig = payload.config.localization.locales.find(\n ({ code }) => req.locale === code,\n )?.fallbackLocale\n if (typeof fallbackLocale !== 'undefined') {\n req.fallbackLocale = fallbackLocale\n } else if (typeof req?.fallbackLocale === 'undefined') {\n req.fallbackLocale = fallbackLocaleFromConfig || defaultLocale\n }\n }\n\n const i18n =\n req?.i18n ||\n (await getLocalI18n({ config: payload.config, language: payload.config.i18n.fallbackLanguage }))\n\n // @ts-expect-error\n if (!req.headers) req.headers = new Headers()\n req.context = getRequestContext(req, context)\n req.payloadAPI = req?.payloadAPI || 'local'\n req.payload = payload\n req.i18n = i18n\n req.t = i18n.t\n req.user = user || req?.user || null\n req.payloadDataLoader = req?.payloadDataLoader || getDataLoader(req)\n req.routeParams = req?.routeParams || {}\n req.query = req?.query || {}\n\n attachFakeURLProperties(req)\n\n return req\n}\n"],"names":["getDataLoader","getLocalI18n","getRequestContext","req","context","Object","keys","length","constructor","attachFakeURLProperties","urlObject","getURLObject","urlToUse","url","payload","config","serverURL","URL","error","host","protocol","pathname","searchParams","origin","href","createLocalReq","fallbackLocale","locale","localeArg","user","localization","defaultLocale","fallbackLocaleFromConfig","locales","find","code","i18n","language","fallbackLanguage","headers","Headers","payloadAPI","t","payloadDataLoader","routeParams","query"],"mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,kBACPC,MAAsB;IAAEC,SAAS;AAAK,CAAmB,EACzDA,UAA0B,CAAC,CAAC;IAE5B,IAAID,IAAIC,OAAO,EAAE;QACf,IAAIC,OAAOC,IAAI,CAACH,IAAIC,OAAO,EAAEG,MAAM,KAAK,KAAKJ,IAAIC,OAAO,CAACI,WAAW,KAAKH,QAAQ;YAC/E,kDAAkD;YAClD,OAAOD;QACT,OAAO;YACL,OAAO;gBAAE,GAAGD,IAAIC,OAAO;gBAAE,GAAGA,OAAO;YAAC;QACtC;IACF,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMK,0BAA0B,CAACN;IAC/B;;;;;;GAMC,GACD,IAAIO;IAEJ,SAASC;QACP,IAAID,WAAW,OAAOA;QACtB,MAAME,WAAWT,KAAKU,OAAOV,IAAIW,OAAO,CAACC,MAAM,EAAEC,aAAa;QAC9D,IAAI;YACFN,YAAY,IAAIO,IAAIL;QACtB,EAAE,OAAOM,OAAO;YACdR,YAAY,IAAIO,IAAI;QACtB;QAEA,OAAOP;IACT;IAEA,IAAI,CAACP,IAAIgB,IAAI,EAAEhB,IAAIgB,IAAI,GAAGR,eAAeQ,IAAI;IAC7C,IAAI,CAAChB,IAAIiB,QAAQ,EAAEjB,IAAIiB,QAAQ,GAAGT,eAAeS,QAAQ;IACzD,IAAI,CAACjB,IAAIkB,QAAQ,EAAElB,IAAIkB,QAAQ,GAAGV,eAAeU,QAAQ;IACzD,mBAAmB;IACnB,IAAI,CAAClB,IAAImB,YAAY,EAAEnB,IAAImB,YAAY,GAAGX,eAAeW,YAAY;IACrE,mBAAmB;IACnB,IAAI,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GAAGA,QAAQ1B,KAAK0B,QAAQ;IAChC1B,IAAIwC,iBAAiB,GAAGxC,KAAKwC,qBAAqB3C,cAAcG;IAChEA,IAAIyC,WAAW,GAAGzC,KAAKyC,eAAe,CAAC;IACvCzC,IAAI0C,KAAK,GAAG1C,KAAK0C,SAAS,CAAC;IAE3BpC,wBAAwBN;IAExB,OAAOA;AACT,EAAC"}
@@ -1,12 +1,12 @@
1
1
  import type { CollectionPermission, GlobalPermission } from '../auth/types.js';
2
2
  import type { SanitizedCollectionConfig } from '../collections/config/types.js';
3
3
  import type { SanitizedGlobalConfig } from '../globals/config/types.js';
4
- import type { AllOperations, PayloadRequestWithData } from '../types/index.js';
4
+ import type { AllOperations, PayloadRequest } from '../types/index.js';
5
5
  type Args = {
6
6
  entity: SanitizedCollectionConfig | SanitizedGlobalConfig;
7
7
  id?: number | string;
8
8
  operations: AllOperations[];
9
- req: PayloadRequestWithData;
9
+ req: PayloadRequest;
10
10
  type: 'collection' | 'global';
11
11
  };
12
12
  type ReturnType<T extends Args> = T['type'] extends 'global' ? GlobalPermission : CollectionPermission;
@@ -1 +1 @@
1
- {"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,sBAAsB,EAAS,MAAM,mBAAmB,CAAA;AAI/F,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAA;IACzD,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,sBAAsB,CAAA;IAC3B,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAA;CAC9B,CAAA;AAED,KAAK,UAAU,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GACxD,gBAAgB,GAChB,oBAAoB,CAAA;AAYxB,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA4NvF"}
1
+ {"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAIvF,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAA;IACzD,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAA;CAC9B,CAAA;AAED,KAAK,UAAU,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GACxD,gBAAgB,GAChB,oBAAoB,CAAA;AAYxB,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA4NvF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequestWithData, Where } from '../types/index.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequestWithData\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<TypeWithID & Document> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where: {\n ...where,\n and: [\n ...(where.and || []),\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({ entityPermission, fields, operation, policiesObj }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if (field.name) {\n if (!mutablePolicies[field.name]) mutablePolicies[field.name] = {}\n\n if (field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if (field.fields) {\n if (!mutablePolicies[field.name].fields) mutablePolicies[field.name].fields = {}\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if (field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) mutablePolicies[field.name].blocks = {}\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if (field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","and","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","blocks","block","tabs","tab","reduce","priorOperation","entityAccessPromise","resolve"],"mappings":"AAOA,SAASA,UAAU,QAAQ,4BAA2B;AAwBtD,OAAO,eAAeC,kBAAkCC,IAAO;IAC7D,MAAM,EAAE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AAM;YACrBsB;YACAC,aAAaxB;QACf;IACF,GAAGgC,QAAQY,OAAO;IAElB,OAAO5C;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequest, Where } from '../types/index.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequest\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<TypeWithID & Document> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where: {\n ...where,\n and: [\n ...(where.and || []),\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({ entityPermission, fields, operation, policiesObj }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if (field.name) {\n if (!mutablePolicies[field.name]) mutablePolicies[field.name] = {}\n\n if (field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if (field.fields) {\n if (!mutablePolicies[field.name].fields) mutablePolicies[field.name].fields = {}\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if (field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) mutablePolicies[field.name].blocks = {}\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if (field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","and","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","bl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;gBACpBM,YAAY9B;YACd;QACF;QAEA,MAAM4C;QAEN,MAAMb,qBAAqB;YACzBC,kBAAkB/B,QAAQ,CAACuB,UAAU,CAACM,UAAU;YAChD5B,QAAQR,OAAOQ,MAAM;YACrBsB;YACAC,aAAaxB;QACf;IACF,GAAGgC,QAAQY,OAAO;IAElB,OAAO5C;AACT"}
@@ -1,7 +1,7 @@
1
- import type { PayloadRequestWithData } from '../types/index.js';
1
+ import type { PayloadRequest } from '../types/index.js';
2
2
  /**
3
3
  * Starts a new transaction using the db adapter with a random id and then assigns it to the req.transaction
4
4
  * @returns true if beginning a transaction and false when req already has a transaction to use
5
5
  */
6
- export declare function initTransaction(req: PayloadRequestWithData): Promise<boolean>;
6
+ export declare function initTransaction(req: PayloadRequest): Promise<boolean>;
7
7
  //# sourceMappingURL=initTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/initTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBnF"}
1
+ {"version":3,"file":"initTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/initTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB3E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/initTransaction.ts"],"sourcesContent":["import type { PayloadRequestWithData } from '../types/index.js'\n\n/**\n * Starts a new transaction using the db adapter with a random id and then assigns it to the req.transaction\n * @returns true if beginning a transaction and false when req already has a transaction to use\n */\nexport async function initTransaction(req: PayloadRequestWithData): Promise<boolean> {\n const { payload, transactionID, transactionIDPromise } = req\n if (transactionID) {\n // we already have a transaction, we're not in charge of committing it\n return false\n }\n if (transactionIDPromise) {\n // wait for whoever else is already creating the transaction\n await transactionIDPromise\n return false\n }\n if (typeof payload.db.beginTransaction === 'function') {\n // create a new transaction\n req.transactionIDPromise = payload.db.beginTransaction().then((transactionID) => {\n if (transactionID) {\n req.transactionID = transactionID\n }\n delete req.transactionIDPromise\n })\n await req.transactionIDPromise\n return !!req.transactionID\n }\n return false\n}\n"],"names":["initTransaction","req","payload","transactionID","transactionIDPromise","db","beginTransaction","then"],"mappings":"AAEA;;;CAGC,GACD,OAAO,eAAeA,gBAAgBC,GAA2B;IAC/D,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAEC,oBAAoB,EAAE,GAAGH;IACzD,IAAIE,eAAe;QACjB,sEAAsE;QACtE,OAAO;IACT;IACA,IAAIC,sBAAsB;QACxB,4DAA4D;QAC5D,MAAMA;QACN,OAAO;IACT;IACA,IAAI,OAAOF,QAAQG,EAAE,CAACC,gBAAgB,KAAK,YAAY;QACrD,2BAA2B;QAC3BL,IAAIG,oBAAoB,GAAGF,QAAQG,EAAE,CAACC,gBAAgB,GAAGC,IAAI,CAAC,CAACJ;YAC7D,IAAIA,eAAe;gBACjBF,IAAIE,aAAa,GAAGA;YACtB;YACA,OAAOF,IAAIG,oBAAoB;QACjC;QACA,MAAMH,IAAIG,oBAAoB;QAC9B,OAAO,CAAC,CAACH,IAAIE,aAAa;IAC5B;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/initTransaction.ts"],"sourcesContent":["import type { PayloadRequest } from '../types/index.js'\n\n/**\n * Starts a new transaction using the db adapter with a random id and then assigns it to the req.transaction\n * @returns true if beginning a transaction and false when req already has a transaction to use\n */\nexport async function initTransaction(req: PayloadRequest): Promise<boolean> {\n const { payload, transactionID, transactionIDPromise } = req\n if (transactionID) {\n // we already have a transaction, we're not in charge of committing it\n return false\n }\n if (transactionIDPromise) {\n // wait for whoever else is already creating the transaction\n await transactionIDPromise\n return false\n }\n if (typeof payload.db.beginTransaction === 'function') {\n // create a new transaction\n req.transactionIDPromise = payload.db.beginTransaction().then((transactionID) => {\n if (transactionID) {\n req.transactionID = transactionID\n }\n delete req.transactionIDPromise\n })\n await req.transactionIDPromise\n return !!req.transactionID\n }\n return false\n}\n"],"names":["initTransaction","req","payload","transactionID","transactionIDPromise","db","beginTransaction","then"],"mappings":"AAEA;;;CAGC,GACD,OAAO,eAAeA,gBAAgBC,GAAmB;IACvD,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAEC,oBAAoB,EAAE,GAAGH;IACzD,IAAIE,eAAe;QACjB,sEAAsE;QACtE,OAAO;IACT;IACA,IAAIC,sBAAsB;QACxB,4DAA4D;QAC5D,MAAMA;QACN,OAAO;IACT;IACA,IAAI,OAAOF,QAAQG,EAAE,CAACC,gBAAgB,KAAK,YAAY;QACrD,2BAA2B;QAC3BL,IAAIG,oBAAoB,GAAGF,QAAQG,EAAE,CAACC,gBAAgB,GAAGC,IAAI,CAAC,CAACJ;YAC7D,IAAIA,eAAe;gBACjBF,IAAIE,aAAa,GAAGA;YACtB;YACA,OAAOF,IAAIG,oBAAoB;QACjC;QACA,MAAMH,IAAIG,oBAAoB;QAC9B,OAAO,CAAC,CAACH,IAAIE,aAAa;IAC5B;IACA,OAAO;AACT"}