payload 4.0.0-internal.5f0cd13 → 4.0.0-internal.63f8536

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 (541) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +11 -0
  3. package/dist/admin/RichText.d.ts +2 -2
  4. package/dist/admin/RichText.d.ts.map +1 -1
  5. package/dist/admin/RichText.js.map +1 -1
  6. package/dist/admin/adapters/devReload.d.ts +9 -0
  7. package/dist/admin/adapters/devReload.d.ts.map +1 -0
  8. package/dist/admin/adapters/devReload.js +6 -0
  9. package/dist/admin/adapters/devReload.js.map +1 -0
  10. package/dist/admin/adapters/index.d.ts +3 -0
  11. package/dist/admin/adapters/index.d.ts.map +1 -1
  12. package/dist/admin/adapters/index.js.map +1 -1
  13. package/dist/admin/adapters/render.d.ts +16 -0
  14. package/dist/admin/adapters/render.d.ts.map +1 -0
  15. package/dist/admin/adapters/render.js +7 -0
  16. package/dist/admin/adapters/render.js.map +1 -0
  17. package/dist/admin/adapters/views.d.ts +36 -0
  18. package/dist/admin/adapters/views.d.ts.map +1 -0
  19. package/dist/admin/adapters/views.js +7 -0
  20. package/dist/admin/adapters/views.js.map +1 -0
  21. package/dist/admin/fields/Row.d.ts +2 -2
  22. package/dist/admin/fields/Row.d.ts.map +1 -1
  23. package/dist/admin/fields/Row.js.map +1 -1
  24. package/dist/admin/forms/Description.d.ts +2 -2
  25. package/dist/admin/forms/Description.d.ts.map +1 -1
  26. package/dist/admin/forms/Description.js.map +1 -1
  27. package/dist/admin/forms/Field.d.ts +10 -5
  28. package/dist/admin/forms/Field.d.ts.map +1 -1
  29. package/dist/admin/forms/Field.js.map +1 -1
  30. package/dist/admin/functions/index.d.ts +10 -1
  31. package/dist/admin/functions/index.d.ts.map +1 -1
  32. package/dist/admin/functions/index.js.map +1 -1
  33. package/dist/admin/types.d.ts +3 -2
  34. package/dist/admin/types.d.ts.map +1 -1
  35. package/dist/admin/types.js.map +1 -1
  36. package/dist/admin/views/dashboard.d.ts +7 -0
  37. package/dist/admin/views/dashboard.d.ts.map +1 -1
  38. package/dist/admin/views/dashboard.js.map +1 -1
  39. package/dist/admin/views/document.d.ts +5 -3
  40. package/dist/admin/views/document.d.ts.map +1 -1
  41. package/dist/admin/views/document.js.map +1 -1
  42. package/dist/admin/views/list.d.ts +5 -0
  43. package/dist/admin/views/list.d.ts.map +1 -1
  44. package/dist/admin/views/list.js.map +1 -1
  45. package/dist/auth/baseFields/apiKey.d.ts +10 -2
  46. package/dist/auth/baseFields/apiKey.d.ts.map +1 -1
  47. package/dist/auth/baseFields/apiKey.js +35 -24
  48. package/dist/auth/baseFields/apiKey.js.map +1 -1
  49. package/dist/auth/defaultAccess.d.ts +1 -1
  50. package/dist/auth/defaultAccess.d.ts.map +1 -1
  51. package/dist/auth/defaultAccess.js +1 -1
  52. package/dist/auth/defaultAccess.js.map +1 -1
  53. package/dist/auth/defaultUser.d.ts.map +1 -1
  54. package/dist/auth/defaultUser.js +2 -1
  55. package/dist/auth/defaultUser.js.map +1 -1
  56. package/dist/auth/getAuthFields.js +2 -2
  57. package/dist/auth/getAuthFields.js.map +1 -1
  58. package/dist/auth/operations/auth.d.ts +2 -2
  59. package/dist/auth/operations/auth.d.ts.map +1 -1
  60. package/dist/auth/operations/auth.js.map +1 -1
  61. package/dist/auth/operations/login.d.ts +2 -1
  62. package/dist/auth/operations/login.d.ts.map +1 -1
  63. package/dist/auth/operations/login.js.map +1 -1
  64. package/dist/auth/operations/me.js.map +1 -1
  65. package/dist/auth/operations/refresh.d.ts.map +1 -1
  66. package/dist/auth/operations/refresh.js +9 -3
  67. package/dist/auth/operations/refresh.js.map +1 -1
  68. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  69. package/dist/auth/operations/resetPassword.js.map +1 -1
  70. package/dist/auth/sendVerificationEmail.d.ts +2 -2
  71. package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
  72. package/dist/auth/sendVerificationEmail.js +1 -1
  73. package/dist/auth/sendVerificationEmail.js.map +1 -1
  74. package/dist/auth/sessions.d.ts +4 -5
  75. package/dist/auth/sessions.d.ts.map +1 -1
  76. package/dist/auth/sessions.js +5 -3
  77. package/dist/auth/sessions.js.map +1 -1
  78. package/dist/auth/strategies/apiKey.js.map +1 -1
  79. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts +2 -2
  80. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
  81. package/dist/auth/strategies/local/incrementLoginAttempts.js +1 -1
  82. package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
  83. package/dist/auth/types.d.ts +28 -21
  84. package/dist/auth/types.d.ts.map +1 -1
  85. package/dist/auth/types.js.map +1 -1
  86. package/dist/bin/build.d.ts +25 -0
  87. package/dist/bin/build.d.ts.map +1 -0
  88. package/dist/bin/build.js +80 -0
  89. package/dist/bin/build.js.map +1 -0
  90. package/dist/bin/build.spec.js +170 -0
  91. package/dist/bin/build.spec.js.map +1 -0
  92. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  93. package/dist/bin/generateImportMap/index.js +8 -5
  94. package/dist/bin/generateImportMap/index.js.map +1 -1
  95. package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
  96. package/dist/bin/generateImportMap/iterateCollections.js +11 -0
  97. package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
  98. package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
  99. package/dist/bin/generateImportMap/iterateConfig.js +12 -0
  100. package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
  101. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +5 -1
  102. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
  103. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +32 -18
  104. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
  105. package/dist/bin/generateTypes.d.ts +3 -2
  106. package/dist/bin/generateTypes.d.ts.map +1 -1
  107. package/dist/bin/generateTypes.js +4 -0
  108. package/dist/bin/generateTypes.js.map +1 -1
  109. package/dist/bin/index.d.ts.map +1 -1
  110. package/dist/bin/index.js +9 -0
  111. package/dist/bin/index.js.map +1 -1
  112. package/dist/bin/loadEnv.d.ts +3 -1
  113. package/dist/bin/loadEnv.d.ts.map +1 -1
  114. package/dist/bin/loadEnv.js +40 -10
  115. package/dist/bin/loadEnv.js.map +1 -1
  116. package/dist/collections/config/client.d.ts +1 -1
  117. package/dist/collections/config/client.d.ts.map +1 -1
  118. package/dist/collections/config/client.js +1 -0
  119. package/dist/collections/config/client.js.map +1 -1
  120. package/dist/collections/config/defaults.d.ts +0 -4
  121. package/dist/collections/config/defaults.d.ts.map +1 -1
  122. package/dist/collections/config/defaults.js +2 -17
  123. package/dist/collections/config/defaults.js.map +1 -1
  124. package/dist/collections/config/defaults.spec.js +47 -0
  125. package/dist/collections/config/defaults.spec.js.map +1 -0
  126. package/dist/collections/config/sanitize.d.ts.map +1 -1
  127. package/dist/collections/config/sanitize.js +1 -11
  128. package/dist/collections/config/sanitize.js.map +1 -1
  129. package/dist/collections/config/types.d.ts +11 -7
  130. package/dist/collections/config/types.d.ts.map +1 -1
  131. package/dist/collections/config/types.js.map +1 -1
  132. package/dist/collections/endpoints/create.d.ts.map +1 -1
  133. package/dist/collections/endpoints/create.js +0 -2
  134. package/dist/collections/endpoints/create.js.map +1 -1
  135. package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
  136. package/dist/collections/endpoints/updateByID.js +1 -2
  137. package/dist/collections/endpoints/updateByID.js.map +1 -1
  138. package/dist/collections/operations/count.d.ts.map +1 -1
  139. package/dist/collections/operations/count.js +1 -0
  140. package/dist/collections/operations/count.js.map +1 -1
  141. package/dist/collections/operations/create.d.ts +0 -1
  142. package/dist/collections/operations/create.d.ts.map +1 -1
  143. package/dist/collections/operations/create.js +15 -6
  144. package/dist/collections/operations/create.js.map +1 -1
  145. package/dist/collections/operations/delete.d.ts.map +1 -1
  146. package/dist/collections/operations/delete.js +3 -0
  147. package/dist/collections/operations/delete.js.map +1 -1
  148. package/dist/collections/operations/findDistinct.d.ts.map +1 -1
  149. package/dist/collections/operations/findDistinct.js +1 -0
  150. package/dist/collections/operations/findDistinct.js.map +1 -1
  151. package/dist/collections/operations/local/count.d.ts +3 -3
  152. package/dist/collections/operations/local/count.d.ts.map +1 -1
  153. package/dist/collections/operations/local/count.js.map +1 -1
  154. package/dist/collections/operations/local/countVersions.d.ts +3 -3
  155. package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
  156. package/dist/collections/operations/local/countVersions.js.map +1 -1
  157. package/dist/collections/operations/local/create.d.ts +3 -3
  158. package/dist/collections/operations/local/create.d.ts.map +1 -1
  159. package/dist/collections/operations/local/create.js.map +1 -1
  160. package/dist/collections/operations/local/delete.d.ts +3 -3
  161. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  162. package/dist/collections/operations/local/delete.js.map +1 -1
  163. package/dist/collections/operations/local/duplicate.d.ts +3 -3
  164. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  165. package/dist/collections/operations/local/duplicate.js.map +1 -1
  166. package/dist/collections/operations/local/find.d.ts +3 -3
  167. package/dist/collections/operations/local/find.d.ts.map +1 -1
  168. package/dist/collections/operations/local/find.js.map +1 -1
  169. package/dist/collections/operations/local/findByID.d.ts +3 -3
  170. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  171. package/dist/collections/operations/local/findByID.js.map +1 -1
  172. package/dist/collections/operations/local/findDistinct.d.ts +2 -2
  173. package/dist/collections/operations/local/findDistinct.d.ts.map +1 -1
  174. package/dist/collections/operations/local/findDistinct.js.map +1 -1
  175. package/dist/collections/operations/local/findVersionByID.d.ts +3 -3
  176. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  177. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  178. package/dist/collections/operations/local/findVersions.d.ts +3 -3
  179. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  180. package/dist/collections/operations/local/findVersions.js.map +1 -1
  181. package/dist/collections/operations/local/restoreVersion.d.ts +3 -3
  182. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  183. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  184. package/dist/collections/operations/local/update.d.ts +7 -11
  185. package/dist/collections/operations/local/update.d.ts.map +1 -1
  186. package/dist/collections/operations/local/update.js +1 -2
  187. package/dist/collections/operations/local/update.js.map +1 -1
  188. package/dist/collections/operations/update.d.ts +0 -1
  189. package/dist/collections/operations/update.d.ts.map +1 -1
  190. package/dist/collections/operations/update.js +8 -4
  191. package/dist/collections/operations/update.js.map +1 -1
  192. package/dist/collections/operations/updateByID.d.ts +0 -1
  193. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  194. package/dist/collections/operations/updateByID.js +1 -5
  195. package/dist/collections/operations/updateByID.js.map +1 -1
  196. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts +9 -0
  197. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts.map +1 -0
  198. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js +170 -0
  199. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js.map +1 -0
  200. package/dist/collections/operations/utilities/types.d.ts +0 -9
  201. package/dist/collections/operations/utilities/types.d.ts.map +1 -1
  202. package/dist/collections/operations/utilities/types.js.map +1 -1
  203. package/dist/collections/operations/utilities/update.d.ts +1 -2
  204. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  205. package/dist/collections/operations/utilities/update.js +64 -65
  206. package/dist/collections/operations/utilities/update.js.map +1 -1
  207. package/dist/config/client.d.ts +2 -2
  208. package/dist/config/client.d.ts.map +1 -1
  209. package/dist/config/client.js.map +1 -1
  210. package/dist/config/defaults.d.ts +0 -4
  211. package/dist/config/defaults.d.ts.map +1 -1
  212. package/dist/config/defaults.js +0 -78
  213. package/dist/config/defaults.js.map +1 -1
  214. package/dist/config/definePlugin.d.ts +10 -10
  215. package/dist/config/definePlugin.d.ts.map +1 -1
  216. package/dist/config/definePlugin.js +7 -11
  217. package/dist/config/definePlugin.js.map +1 -1
  218. package/dist/config/orderable/index.d.ts.map +1 -1
  219. package/dist/config/orderable/index.js +23 -0
  220. package/dist/config/orderable/index.js.map +1 -1
  221. package/dist/config/sanitize.d.ts.map +1 -1
  222. package/dist/config/sanitize.js +137 -13
  223. package/dist/config/sanitize.js.map +1 -1
  224. package/dist/config/types.d.ts +57 -19
  225. package/dist/config/types.d.ts.map +1 -1
  226. package/dist/config/types.js +2 -0
  227. package/dist/config/types.js.map +1 -1
  228. package/dist/database/getLocalizedPaths.d.ts.map +1 -1
  229. package/dist/database/getLocalizedPaths.js +1 -1
  230. package/dist/database/getLocalizedPaths.js.map +1 -1
  231. package/dist/database/migrations/migrationsCollection.d.ts.map +1 -1
  232. package/dist/database/migrations/migrationsCollection.js +2 -1
  233. package/dist/database/migrations/migrationsCollection.js.map +1 -1
  234. package/dist/errors/ValidationError.d.ts +1 -0
  235. package/dist/errors/ValidationError.d.ts.map +1 -1
  236. package/dist/errors/ValidationError.js.map +1 -1
  237. package/dist/exports/internal.d.ts +1 -0
  238. package/dist/exports/internal.d.ts.map +1 -1
  239. package/dist/exports/internal.js +1 -0
  240. package/dist/exports/internal.js.map +1 -1
  241. package/dist/exports/migrations.d.ts +5 -13
  242. package/dist/exports/migrations.d.ts.map +1 -1
  243. package/dist/exports/migrations.js +5 -13
  244. package/dist/exports/migrations.js.map +1 -1
  245. package/dist/exports/shared.d.ts +23 -2
  246. package/dist/exports/shared.d.ts.map +1 -1
  247. package/dist/exports/shared.js +22 -1
  248. package/dist/exports/shared.js.map +1 -1
  249. package/dist/fields/baseFields/slug/countVersions.d.ts.map +1 -1
  250. package/dist/fields/baseFields/slug/countVersions.js +6 -8
  251. package/dist/fields/baseFields/slug/countVersions.js.map +1 -1
  252. package/dist/fields/baseFields/slug/generateSlug.d.ts +14 -7
  253. package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
  254. package/dist/fields/baseFields/slug/generateSlug.js +53 -73
  255. package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
  256. package/dist/fields/baseFields/slug/types.d.ts +14 -0
  257. package/dist/fields/baseFields/slug/types.d.ts.map +1 -0
  258. package/dist/fields/baseFields/slug/types.js +6 -0
  259. package/dist/fields/baseFields/slug/types.js.map +1 -0
  260. package/dist/fields/config/client.d.ts +3 -3
  261. package/dist/fields/config/client.d.ts.map +1 -1
  262. package/dist/fields/config/client.js +13 -13
  263. package/dist/fields/config/client.js.map +1 -1
  264. package/dist/fields/config/sanitize.d.ts.map +1 -1
  265. package/dist/fields/config/sanitize.js +40 -4
  266. package/dist/fields/config/sanitize.js.map +1 -1
  267. package/dist/fields/config/types.d.ts +49 -28
  268. package/dist/fields/config/types.d.ts.map +1 -1
  269. package/dist/fields/config/types.js.map +1 -1
  270. package/dist/fields/hooks/afterChange/promise.js +1 -1
  271. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  272. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  273. package/dist/fields/hooks/afterRead/promise.js +13 -3
  274. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  275. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  276. package/dist/fields/hooks/beforeChange/promise.js +3 -3
  277. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  278. package/dist/fields/hooks/beforeDuplicate/promise.js +2 -2
  279. package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
  280. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  281. package/dist/fields/hooks/beforeValidate/promise.js +11 -2
  282. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  283. package/dist/fields/setDefaultBeforeDuplicate.js +1 -0
  284. package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
  285. package/dist/fields/sortableFieldTypes.d.ts.map +1 -1
  286. package/dist/fields/sortableFieldTypes.js +1 -0
  287. package/dist/fields/sortableFieldTypes.js.map +1 -1
  288. package/dist/fields/validations.d.ts +4 -1
  289. package/dist/fields/validations.d.ts.map +1 -1
  290. package/dist/fields/validations.js +12 -4
  291. package/dist/fields/validations.js.map +1 -1
  292. package/dist/globals/config/sanitize.d.ts.map +1 -1
  293. package/dist/globals/config/sanitize.js +2 -6
  294. package/dist/globals/config/sanitize.js.map +1 -1
  295. package/dist/globals/config/sanitize.spec.js +43 -0
  296. package/dist/globals/config/sanitize.spec.js.map +1 -0
  297. package/dist/globals/endpoints/update.d.ts.map +1 -1
  298. package/dist/globals/endpoints/update.js +0 -2
  299. package/dist/globals/endpoints/update.js.map +1 -1
  300. package/dist/globals/operations/local/countVersions.d.ts +3 -3
  301. package/dist/globals/operations/local/countVersions.d.ts.map +1 -1
  302. package/dist/globals/operations/local/countVersions.js.map +1 -1
  303. package/dist/globals/operations/local/findOne.d.ts +3 -3
  304. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  305. package/dist/globals/operations/local/findOne.js.map +1 -1
  306. package/dist/globals/operations/local/findVersionByID.d.ts +3 -3
  307. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  308. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  309. package/dist/globals/operations/local/findVersions.d.ts +3 -3
  310. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  311. package/dist/globals/operations/local/findVersions.js.map +1 -1
  312. package/dist/globals/operations/local/restoreVersion.d.ts +3 -3
  313. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  314. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  315. package/dist/globals/operations/local/update.d.ts +7 -9
  316. package/dist/globals/operations/local/update.d.ts.map +1 -1
  317. package/dist/globals/operations/local/update.js +1 -2
  318. package/dist/globals/operations/local/update.js.map +1 -1
  319. package/dist/globals/operations/update.d.ts +0 -1
  320. package/dist/globals/operations/update.d.ts.map +1 -1
  321. package/dist/globals/operations/update.js +52 -58
  322. package/dist/globals/operations/update.js.map +1 -1
  323. package/dist/index.bundled.d.ts +595 -368
  324. package/dist/index.d.ts +71 -26
  325. package/dist/index.d.ts.map +1 -1
  326. package/dist/index.js +54 -37
  327. package/dist/index.js.map +1 -1
  328. package/dist/kv/adapters/DatabaseKVAdapter.d.ts.map +1 -1
  329. package/dist/kv/adapters/DatabaseKVAdapter.js +1 -0
  330. package/dist/kv/adapters/DatabaseKVAdapter.js.map +1 -1
  331. package/dist/locked-documents/config.d.ts.map +1 -1
  332. package/dist/locked-documents/config.js +2 -1
  333. package/dist/locked-documents/config.js.map +1 -1
  334. package/dist/preferences/config.d.ts.map +1 -1
  335. package/dist/preferences/config.js +2 -1
  336. package/dist/preferences/config.js.map +1 -1
  337. package/dist/preferences/keys.d.ts +4 -0
  338. package/dist/preferences/keys.d.ts.map +1 -1
  339. package/dist/preferences/keys.js +4 -1
  340. package/dist/preferences/keys.js.map +1 -1
  341. package/dist/preferences/types.d.ts +15 -0
  342. package/dist/preferences/types.d.ts.map +1 -1
  343. package/dist/preferences/types.js +3 -1
  344. package/dist/preferences/types.js.map +1 -1
  345. package/dist/query-presets/config.d.ts.map +1 -1
  346. package/dist/query-presets/config.js +75 -35
  347. package/dist/query-presets/config.js.map +1 -1
  348. package/dist/query-presets/constraints.d.ts.map +1 -1
  349. package/dist/query-presets/constraints.js +2 -1
  350. package/dist/query-presets/constraints.js.map +1 -1
  351. package/dist/queues/config/collection.d.ts.map +1 -1
  352. package/dist/queues/config/collection.js +2 -1
  353. package/dist/queues/config/collection.js.map +1 -1
  354. package/dist/queues/config/generateJobsJSONSchemas.js +2 -2
  355. package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
  356. package/dist/queues/config/global.d.ts.map +1 -1
  357. package/dist/queues/config/global.js +2 -1
  358. package/dist/queues/config/global.js.map +1 -1
  359. package/dist/types/index.d.ts +8 -3
  360. package/dist/types/index.d.ts.map +1 -1
  361. package/dist/types/index.js.map +1 -1
  362. package/dist/uploads/generateFileData.d.ts +2 -1
  363. package/dist/uploads/generateFileData.d.ts.map +1 -1
  364. package/dist/uploads/generateFileData.js +5 -2
  365. package/dist/uploads/generateFileData.js.map +1 -1
  366. package/dist/uploads/matchMimeType.d.ts +8 -0
  367. package/dist/uploads/matchMimeType.d.ts.map +1 -0
  368. package/dist/uploads/matchMimeType.js +19 -0
  369. package/dist/uploads/matchMimeType.js.map +1 -0
  370. package/dist/uploads/matchMimeType.spec.js +66 -0
  371. package/dist/uploads/matchMimeType.spec.js.map +1 -0
  372. package/dist/uploads/safeFetch.d.ts.map +1 -1
  373. package/dist/uploads/safeFetch.js +11 -5
  374. package/dist/uploads/safeFetch.js.map +1 -1
  375. package/dist/uploads/types.d.ts +21 -0
  376. package/dist/uploads/types.d.ts.map +1 -1
  377. package/dist/uploads/types.js.map +1 -1
  378. package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
  379. package/dist/utilities/addDataAndFileToRequest.js +6 -0
  380. package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
  381. package/dist/utilities/appendDateTimezoneSelectFields.js +2 -2
  382. package/dist/utilities/appendDateTimezoneSelectFields.js.map +1 -1
  383. package/dist/utilities/configToJSONSchema.d.ts +36 -2
  384. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  385. package/dist/utilities/configToJSONSchema.js +204 -84
  386. package/dist/utilities/configToJSONSchema.js.map +1 -1
  387. package/dist/utilities/configToJSONSchema.spec.js +534 -29
  388. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  389. package/dist/utilities/createLocalReq.d.ts +2 -2
  390. package/dist/utilities/createLocalReq.d.ts.map +1 -1
  391. package/dist/utilities/createLocalReq.js.map +1 -1
  392. package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
  393. package/dist/utilities/createPayloadRequest.js +1 -0
  394. package/dist/utilities/createPayloadRequest.js.map +1 -1
  395. package/dist/utilities/deepCopyObject.d.ts.map +1 -1
  396. package/dist/utilities/deepCopyObject.js +8 -0
  397. package/dist/utilities/deepCopyObject.js.map +1 -1
  398. package/dist/utilities/dependencies/dependencyChecker.js +1 -1
  399. package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
  400. package/dist/utilities/dependencies/getDependencies.d.ts.map +1 -1
  401. package/dist/utilities/dependencies/getDependencies.js +5 -5
  402. package/dist/utilities/dependencies/getDependencies.js.map +1 -1
  403. package/dist/utilities/dynamicImport.js +1 -1
  404. package/dist/utilities/dynamicImport.js.map +1 -1
  405. package/dist/utilities/filterDataToSelectedLocales.d.ts.map +1 -1
  406. package/dist/utilities/filterDataToSelectedLocales.js +5 -12
  407. package/dist/utilities/filterDataToSelectedLocales.js.map +1 -1
  408. package/dist/utilities/filterDataToSelectedLocales.spec.js +1 -2
  409. package/dist/utilities/filterDataToSelectedLocales.spec.js.map +1 -1
  410. package/dist/utilities/flattenAllFields.d.ts.map +1 -1
  411. package/dist/utilities/flattenAllFields.js +7 -22
  412. package/dist/utilities/flattenAllFields.js.map +1 -1
  413. package/dist/utilities/formatErrors.d.ts.map +1 -1
  414. package/dist/utilities/formatErrors.js +3 -1
  415. package/dist/utilities/formatErrors.js.map +1 -1
  416. package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
  417. package/dist/utilities/getEntityPermissions/getEntityPermissions.js +2 -0
  418. package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
  419. package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts +7 -1
  420. package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts.map +1 -1
  421. package/dist/utilities/getEntityPermissions/populateFieldPermissions.js +24 -7
  422. package/dist/utilities/getEntityPermissions/populateFieldPermissions.js.map +1 -1
  423. package/dist/utilities/getFieldByPath.d.ts.map +1 -1
  424. package/dist/utilities/getFieldByPath.js +1 -1
  425. package/dist/utilities/getFieldByPath.js.map +1 -1
  426. package/dist/utilities/getRequestLanguage.d.ts +2 -2
  427. package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
  428. package/dist/utilities/getRequestLanguage.js.map +1 -1
  429. package/dist/utilities/getVersionsConfig.js.map +1 -1
  430. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  431. package/dist/utilities/handleEndpoints.js +7 -3
  432. package/dist/utilities/handleEndpoints.js.map +1 -1
  433. package/dist/utilities/isURLAllowed.d.ts.map +1 -1
  434. package/dist/utilities/isURLAllowed.js +9 -3
  435. package/dist/utilities/isURLAllowed.js.map +1 -1
  436. package/dist/utilities/isURLAllowed.spec.js +78 -0
  437. package/dist/utilities/isURLAllowed.spec.js.map +1 -0
  438. package/dist/utilities/mergeLocalizedData.d.ts +14 -4
  439. package/dist/utilities/mergeLocalizedData.d.ts.map +1 -1
  440. package/dist/utilities/mergeLocalizedData.js +54 -46
  441. package/dist/utilities/mergeLocalizedData.js.map +1 -1
  442. package/dist/utilities/mergeLocalizedData.spec.js +23 -23
  443. package/dist/utilities/mergeLocalizedData.spec.js.map +1 -1
  444. package/dist/utilities/parseParams/index.d.ts +2 -5
  445. package/dist/utilities/parseParams/index.d.ts.map +1 -1
  446. package/dist/utilities/parseParams/index.js.map +1 -1
  447. package/dist/utilities/parseParams/index.spec.js +0 -9
  448. package/dist/utilities/parseParams/index.spec.js.map +1 -1
  449. package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
  450. package/dist/utilities/telemetry/events/adminInit.js +2 -3
  451. package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
  452. package/dist/utilities/telemetry/events/serverInit.d.ts.map +1 -1
  453. package/dist/utilities/telemetry/events/serverInit.js +2 -3
  454. package/dist/utilities/telemetry/events/serverInit.js.map +1 -1
  455. package/dist/utilities/telemetry/index.d.ts +14 -3
  456. package/dist/utilities/telemetry/index.d.ts.map +1 -1
  457. package/dist/utilities/telemetry/index.js +6 -1
  458. package/dist/utilities/telemetry/index.js.map +1 -1
  459. package/dist/utilities/telemetry/index.spec.js +43 -0
  460. package/dist/utilities/telemetry/index.spec.js.map +1 -0
  461. package/dist/utilities/transformColumnPreferences.js +4 -2
  462. package/dist/utilities/transformColumnPreferences.js.map +1 -1
  463. package/dist/utilities/traverseFields.d.ts.map +1 -1
  464. package/dist/utilities/traverseFields.js +2 -4
  465. package/dist/utilities/traverseFields.js.map +1 -1
  466. package/dist/utilities/traverseForLocalizedFields.d.ts.map +1 -1
  467. package/dist/utilities/traverseForLocalizedFields.js +3 -0
  468. package/dist/utilities/traverseForLocalizedFields.js.map +1 -1
  469. package/dist/versions/baseFields.d.ts +1 -2
  470. package/dist/versions/baseFields.d.ts.map +1 -1
  471. package/dist/versions/baseFields.js +0 -13
  472. package/dist/versions/baseFields.js.map +1 -1
  473. package/dist/versions/buildCollectionFields.d.ts.map +1 -1
  474. package/dist/versions/buildCollectionFields.js +0 -2
  475. package/dist/versions/buildCollectionFields.js.map +1 -1
  476. package/dist/versions/buildGlobalFields.d.ts.map +1 -1
  477. package/dist/versions/buildGlobalFields.js +0 -2
  478. package/dist/versions/buildGlobalFields.js.map +1 -1
  479. package/dist/versions/buildSingleLocalePublishData.d.ts +32 -0
  480. package/dist/versions/buildSingleLocalePublishData.d.ts.map +1 -0
  481. package/dist/versions/buildSingleLocalePublishData.js +37 -0
  482. package/dist/versions/buildSingleLocalePublishData.js.map +1 -0
  483. package/dist/versions/saveVersion.d.ts +0 -2
  484. package/dist/versions/saveVersion.d.ts.map +1 -1
  485. package/dist/versions/saveVersion.js +12 -17
  486. package/dist/versions/saveVersion.js.map +1 -1
  487. package/dist/versions/schedule/job.d.ts.map +1 -1
  488. package/dist/versions/schedule/job.js +6 -10
  489. package/dist/versions/schedule/job.js.map +1 -1
  490. package/dist/versions/types.d.ts +2 -15
  491. package/dist/versions/types.d.ts.map +1 -1
  492. package/dist/versions/types.js.map +1 -1
  493. package/package.json +9 -6
  494. package/dist/database/migrations/templates/localizeStatus.d.ts +0 -10
  495. package/dist/database/migrations/templates/localizeStatus.d.ts.map +0 -1
  496. package/dist/database/migrations/templates/localizeStatus.js +0 -54
  497. package/dist/database/migrations/templates/localizeStatus.js.map +0 -1
  498. package/dist/fields/baseFields/slug/index.d.ts +0 -89
  499. package/dist/fields/baseFields/slug/index.d.ts.map +0 -1
  500. package/dist/fields/baseFields/slug/index.js +0 -81
  501. package/dist/fields/baseFields/slug/index.js.map +0 -1
  502. package/dist/versions/migrations/localizeStatus/index.d.ts +0 -12
  503. package/dist/versions/migrations/localizeStatus/index.d.ts.map +0 -1
  504. package/dist/versions/migrations/localizeStatus/index.js +0 -33
  505. package/dist/versions/migrations/localizeStatus/index.js.map +0 -1
  506. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +0 -9
  507. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +0 -1
  508. package/dist/versions/migrations/localizeStatus/mongo/down.js +0 -112
  509. package/dist/versions/migrations/localizeStatus/mongo/down.js.map +0 -1
  510. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +0 -8
  511. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +0 -1
  512. package/dist/versions/migrations/localizeStatus/mongo/index.js +0 -8
  513. package/dist/versions/migrations/localizeStatus/mongo/index.js.map +0 -1
  514. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +0 -9
  515. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +0 -1
  516. package/dist/versions/migrations/localizeStatus/mongo/up.js +0 -220
  517. package/dist/versions/migrations/localizeStatus/mongo/up.js.map +0 -1
  518. package/dist/versions/migrations/localizeStatus/sql/down.d.ts +0 -11
  519. package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +0 -1
  520. package/dist/versions/migrations/localizeStatus/sql/down.js +0 -213
  521. package/dist/versions/migrations/localizeStatus/sql/down.js.map +0 -1
  522. package/dist/versions/migrations/localizeStatus/sql/index.d.ts +0 -8
  523. package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +0 -1
  524. package/dist/versions/migrations/localizeStatus/sql/index.js +0 -8
  525. package/dist/versions/migrations/localizeStatus/sql/index.js.map +0 -1
  526. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +0 -13
  527. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +0 -1
  528. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +0 -51
  529. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +0 -1
  530. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +0 -13
  531. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +0 -1
  532. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +0 -54
  533. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +0 -1
  534. package/dist/versions/migrations/localizeStatus/sql/up.d.ts +0 -11
  535. package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +0 -1
  536. package/dist/versions/migrations/localizeStatus/sql/up.js +0 -277
  537. package/dist/versions/migrations/localizeStatus/sql/up.js.map +0 -1
  538. package/dist/versions/saveSnapshot.d.ts +0 -18
  539. package/dist/versions/saveSnapshot.d.ts.map +0 -1
  540. package/dist/versions/saveSnapshot.js +0 -38
  541. package/dist/versions/saveSnapshot.js.map +0 -1
@@ -1,83 +1,5 @@
1
1
  import { defaultAccess } from '../auth/defaultAccess.js';
2
2
  import { databaseKVAdapter } from '../kv/adapters/DatabaseKVAdapter.js';
3
- /**
4
- * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
5
- */ export const defaults = {
6
- admin: {
7
- avatar: 'gravatar',
8
- components: {},
9
- custom: {},
10
- dateFormat: 'MMMM do yyyy, h:mm a',
11
- dependencies: {},
12
- importMap: {
13
- baseDir: `${typeof process?.cwd === 'function' ? process.cwd() : ''}`
14
- },
15
- meta: {
16
- defaultOGImageType: 'dynamic',
17
- robots: 'noindex, nofollow',
18
- titleSuffix: '- Payload'
19
- },
20
- routes: {
21
- account: '/account',
22
- createFirstUser: '/create-first-user',
23
- forgot: '/forgot',
24
- inactivity: '/logout-inactivity',
25
- login: '/login',
26
- logout: '/logout',
27
- reset: '/reset',
28
- unauthorized: '/unauthorized'
29
- },
30
- theme: 'all'
31
- },
32
- auth: {
33
- jwtOrder: [
34
- 'JWT',
35
- 'Bearer',
36
- 'cookie'
37
- ]
38
- },
39
- bin: [],
40
- collections: [],
41
- cookiePrefix: 'payload',
42
- cors: [],
43
- csrf: [],
44
- custom: {},
45
- defaultDepth: 2,
46
- defaultMaxTextLength: 40000,
47
- endpoints: [],
48
- globals: [],
49
- graphQL: {
50
- disablePlaygroundInProduction: true,
51
- maxComplexity: 1000,
52
- schemaOutputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/schema.graphql`
53
- },
54
- hooks: {},
55
- i18n: {},
56
- jobs: {
57
- access: {
58
- cancel: defaultAccess,
59
- queue: defaultAccess,
60
- run: defaultAccess
61
- },
62
- deleteJobOnComplete: true,
63
- depth: 0
64
- },
65
- localization: false,
66
- maxDepth: 10,
67
- routes: {
68
- admin: '/admin',
69
- api: '/api',
70
- graphQL: '/graphql',
71
- graphQLPlayground: '/graphql-playground'
72
- },
73
- serverURL: '',
74
- telemetry: true,
75
- typescript: {
76
- autoGenerate: true,
77
- outputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/payload-types.ts`
78
- },
79
- upload: {}
80
- };
81
3
  export const addDefaultsToConfig = (config)=>{
82
4
  config.admin = {
83
5
  avatar: 'gravatar',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/defaults.ts"],"sourcesContent":["import type { JobsConfig } from '../queues/config/types/index.js'\nimport type { Config } from './types.js'\n\nimport { defaultAccess } from '../auth/defaultAccess.js'\nimport { databaseKVAdapter } from '../kv/adapters/DatabaseKVAdapter.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Omit<Config, 'db' | 'editor' | 'secret'> = {\n admin: {\n avatar: 'gravatar',\n components: {},\n custom: {},\n dateFormat: 'MMMM do yyyy, h:mm a',\n dependencies: {},\n importMap: {\n baseDir: `${typeof process?.cwd === 'function' ? process.cwd() : ''}`,\n },\n meta: {\n defaultOGImageType: 'dynamic',\n robots: 'noindex, nofollow',\n titleSuffix: '- Payload',\n },\n routes: {\n account: '/account',\n createFirstUser: '/create-first-user',\n forgot: '/forgot',\n inactivity: '/logout-inactivity',\n login: '/login',\n logout: '/logout',\n reset: '/reset',\n unauthorized: '/unauthorized',\n },\n theme: 'all',\n },\n auth: {\n jwtOrder: ['JWT', 'Bearer', 'cookie'],\n },\n bin: [],\n collections: [],\n cookiePrefix: 'payload',\n cors: [],\n csrf: [],\n custom: {},\n defaultDepth: 2,\n defaultMaxTextLength: 40000,\n endpoints: [],\n globals: [],\n graphQL: {\n disablePlaygroundInProduction: true,\n maxComplexity: 1000,\n schemaOutputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/schema.graphql`,\n },\n hooks: {},\n i18n: {},\n jobs: {\n access: {\n cancel: defaultAccess,\n queue: defaultAccess,\n run: defaultAccess,\n },\n deleteJobOnComplete: true,\n depth: 0,\n } as JobsConfig,\n\n localization: false,\n maxDepth: 10,\n routes: {\n admin: '/admin',\n api: '/api',\n graphQL: '/graphql',\n graphQLPlayground: '/graphql-playground',\n },\n serverURL: '',\n telemetry: true,\n typescript: {\n autoGenerate: true,\n outputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/payload-types.ts`,\n },\n upload: {},\n}\n\nexport const addDefaultsToConfig = (config: Config): Config => {\n config.admin = {\n avatar: 'gravatar',\n components: {},\n custom: {},\n dateFormat: 'MMMM do yyyy, h:mm a',\n dependencies: {},\n theme: 'all',\n ...(config.admin || {}),\n importMap: {\n baseDir: `${typeof process?.cwd === 'function' ? process.cwd() : ''}`,\n ...(config?.admin?.importMap || {}),\n },\n meta: {\n defaultOGImageType: 'dynamic',\n robots: 'noindex, nofollow',\n titleSuffix: '- Payload',\n ...(config?.admin?.meta || {}),\n },\n routes: {\n account: '/account',\n createFirstUser: '/create-first-user',\n forgot: '/forgot',\n inactivity: '/logout-inactivity',\n login: '/login',\n logout: '/logout',\n reset: '/reset',\n unauthorized: '/unauthorized',\n ...(config?.admin?.routes || {}),\n },\n }\n\n config.bin = config.bin ?? []\n config.collections = config.collections ?? []\n config.cookiePrefix = config.cookiePrefix ?? 'payload'\n config.cors = config.cors ?? []\n config.csrf = config.csrf ?? []\n config.custom = config.custom ?? {}\n config.defaultDepth = config.defaultDepth ?? 2\n config.defaultMaxTextLength = config.defaultMaxTextLength ?? 40000\n config.endpoints = config.endpoints ?? []\n config.globals = config.globals ?? []\n config.graphQL = {\n disableIntrospectionInProduction: true,\n disablePlaygroundInProduction: true,\n maxComplexity: 1000,\n schemaOutputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/schema.graphql`,\n ...(config.graphQL || {}),\n }\n config.hooks = config.hooks ?? {}\n config.i18n = config.i18n ?? {}\n config.jobs = {\n deleteJobOnComplete: true,\n depth: 0,\n ...(config.jobs || {}),\n access: {\n cancel: defaultAccess,\n queue: defaultAccess,\n run: defaultAccess,\n ...(config.jobs?.access || {}),\n },\n } as JobsConfig\n config.localization = config.localization ?? false\n config.maxDepth = config.maxDepth ?? 10\n config.routes = {\n admin: '/admin',\n api: '/api',\n graphQL: '/graphql',\n graphQLPlayground: '/graphql-playground',\n ...(config.routes || {}),\n }\n config.serverURL = config.serverURL ?? ''\n config.telemetry = config.telemetry ?? true\n config.typescript = {\n autoGenerate: true,\n outputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/payload-types.ts`,\n ...(config.typescript || {}),\n }\n config.upload = config.upload ?? {}\n\n config.auth = {\n jwtOrder: ['JWT', 'Bearer', 'cookie'],\n ...(config.auth || {}),\n }\n\n config.kv = config.kv ?? databaseKVAdapter()\n\n if (config.kv?.kvCollection) {\n config.collections.push(config.kv.kvCollection)\n }\n\n return config\n}\n"],"names":["defaultAccess","databaseKVAdapter","defaults","admin","avatar","components","custom","dateFormat","dependencies","importMap","baseDir","process","cwd","meta","defaultOGImageType","robots","titleSuffix","routes","account","createFirstUser","forgot","inactivity","login","logout","reset","unauthorized","theme","auth","jwtOrder","bin","collections","cookiePrefix","cors","csrf","defaultDepth","defaultMaxTextLength","endpoints","globals","graphQL","disablePlaygroundInProduction","maxComplexity","schemaOutputFile","hooks","i18n","jobs","access","cancel","queue","run","deleteJobOnComplete","depth","localization","maxDepth","api","graphQLPlayground","serverURL","telemetry","typescript","autoGenerate","outputFile","upload","addDefaultsToConfig","config","disableIntrospectionInProduction","kv","kvCollection","push"],"mappings":"AAGA,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SAASC,iBAAiB,QAAQ,sCAAqC;AAEvE;;CAEC,GACD,OAAO,MAAMC,WAAqD;IAChEC,OAAO;QACLC,QAAQ;QACRC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,YAAY;QACZC,cAAc,CAAC;QACfC,WAAW;YACTC,SAAS,GAAG,OAAOC,SAASC,QAAQ,aAAaD,QAAQC,GAAG,KAAK,IAAI;QACvE;QACAC,MAAM;YACJC,oBAAoB;YACpBC,QAAQ;YACRC,aAAa;QACf;QACAC,QAAQ;YACNC,SAAS;YACTC,iBAAiB;YACjBC,QAAQ;YACRC,YAAY;YACZC,OAAO;YACPC,QAAQ;YACRC,OAAO;YACPC,cAAc;QAChB;QACAC,OAAO;IACT;IACAC,MAAM;QACJC,UAAU;YAAC;YAAO;YAAU;SAAS;IACvC;IACAC,KAAK,EAAE;IACPC,aAAa,EAAE;IACfC,cAAc;IACdC,MAAM,EAAE;IACRC,MAAM,EAAE;IACR3B,QAAQ,CAAC;IACT4B,cAAc;IACdC,sBAAsB;IACtBC,WAAW,EAAE;IACbC,SAAS,EAAE;IACXC,SAAS;QACPC,+BAA+B;QAC/BC,eAAe;QACfC,kBAAkB,GAAG,OAAO9B,SAASC,QAAQ,aAAaD,QAAQC,GAAG,KAAK,GAAG,eAAe,CAAC;IAC/F;IACA8B,OAAO,CAAC;IACRC,MAAM,CAAC;IACPC,MAAM;QACJC,QAAQ;YACNC,Q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AAc;QACdC,YAAY,GAAG,OAAOhD,SAASC,QAAQ,aAAaD,QAAQC,GAAG,KAAK,GAAG,iBAAiB,CAAC;QACzF,GAAIkD,OAAOL,UAAU,IAAI,CAAC,CAAC;IAC7B;IACAK,OAAOF,MAAM,GAAGE,OAAOF,MAAM,IAAI,CAAC;IAElCE,OAAOnC,IAAI,GAAG;QACZC,UAAU;YAAC;YAAO;YAAU;SAAS;QACrC,GAAIkC,OAAOnC,IAAI,IAAI,CAAC,CAAC;IACvB;IAEAmC,OAAOE,EAAE,GAAGF,OAAOE,EAAE,IAAI/D;IAEzB,IAAI6D,OAAOE,EAAE,EAAEC,cAAc;QAC3BH,OAAOhC,WAAW,CAACoC,IAAI,CAACJ,OAAOE,EAAE,CAACC,YAAY;IAChD;IAEA,OAAOH;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/config/defaults.ts"],"sourcesContent":["import type { JobsConfig } from '../queues/config/types/index.js'\nimport type { Config } from './types.js'\n\nimport { defaultAccess } from '../auth/defaultAccess.js'\nimport { databaseKVAdapter } from '../kv/adapters/DatabaseKVAdapter.js'\n\nexport const addDefaultsToConfig = (config: Config): Config => {\n config.admin = {\n avatar: 'gravatar',\n components: {},\n custom: {},\n dateFormat: 'MMMM do yyyy, h:mm a',\n dependencies: {},\n theme: 'all',\n ...(config.admin || {}),\n importMap: {\n baseDir: `${typeof process?.cwd === 'function' ? process.cwd() : ''}`,\n ...(config?.admin?.importMap || {}),\n },\n meta: {\n defaultOGImageType: 'dynamic',\n robots: 'noindex, nofollow',\n titleSuffix: '- Payload',\n ...(config?.admin?.meta || {}),\n },\n routes: {\n account: '/account',\n createFirstUser: '/create-first-user',\n forgot: '/forgot',\n inactivity: '/logout-inactivity',\n login: '/login',\n logout: '/logout',\n reset: '/reset',\n unauthorized: '/unauthorized',\n ...(config?.admin?.routes || {}),\n },\n }\n\n config.bin = config.bin ?? []\n config.collections = config.collections ?? []\n config.cookiePrefix = config.cookiePrefix ?? 'payload'\n config.cors = config.cors ?? []\n config.csrf = config.csrf ?? []\n config.custom = config.custom ?? {}\n config.defaultDepth = config.defaultDepth ?? 2\n config.defaultMaxTextLength = config.defaultMaxTextLength ?? 40000\n config.endpoints = config.endpoints ?? []\n config.globals = config.globals ?? []\n config.graphQL = {\n disableIntrospectionInProduction: true,\n disablePlaygroundInProduction: true,\n maxComplexity: 1000,\n schemaOutputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/schema.graphql`,\n ...(config.graphQL || {}),\n }\n config.hooks = config.hooks ?? {}\n config.i18n = config.i18n ?? {}\n config.jobs = {\n deleteJobOnComplete: true,\n depth: 0,\n ...(config.jobs || {}),\n access: {\n cancel: defaultAccess,\n queue: defaultAccess,\n run: defaultAccess,\n ...(config.jobs?.access || {}),\n },\n } as JobsConfig\n config.localization = config.localization ?? false\n config.maxDepth = config.maxDepth ?? 10\n config.routes = {\n admin: '/admin',\n api: '/api',\n graphQL: '/graphql',\n graphQLPlayground: '/graphql-playground',\n ...(config.routes || {}),\n }\n config.serverURL = config.serverURL ?? ''\n config.telemetry = config.telemetry ?? true\n config.typescript = {\n autoGenerate: true,\n outputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/payload-types.ts`,\n ...(config.typescript || {}),\n }\n config.upload = config.upload ?? {}\n\n config.auth = {\n jwtOrder: ['JWT', 'Bearer', 'cookie'],\n ...(config.auth || {}),\n }\n\n config.kv = config.kv ?? databaseKVAdapter()\n\n if (config.kv?.kvCollection) {\n config.collections.push(config.kv.kvCollection)\n }\n\n return config\n}\n"],"names":["defaultAccess","databaseKVAdapter","addDefaultsToConfig","config","admin","avatar","components","custom","dateFormat","dependencies","theme","importMap","baseDir","process","cwd","meta","defaultOGImageType","robots","titleSuffix","routes","account","createFirstUser","forgot","inactivity","login","logout","reset","unauthorized","bin","collections","cookiePrefix","cors","csrf","defaultDepth","defaultMaxTextLength","endpoints","globals","graphQL","disableIntrospectionInProduction","disablePlaygroundInProduction","maxComplexity","schemaOutputFile","hooks","i18n","jobs","deleteJobOnComplete","depth","access","cancel","queue","run","localization","maxDepth","api","graphQLPlayground","serverURL","telemetry","typescript","autoGenerate","outputFile","upload","auth","jwtOrder","kv","kvCollection","push"],"mappings":"AAGA,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SAASC,iBAAiB,QAAQ,sCAAqC;AAEvE,OAAO,MAAMC,sBAAsB,CAACC;IAClCA,OAAOC,KAAK,GAAG;QACbC,QAAQ;QACRC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,YAAY;QACZC,cAAc,CAAC;QACfC,OAAO;QACP,GAAIP,OAAOC,KAAK,IAAI,CAAC,CAAC;QACtBO,WAAW;YACTC,SAAS,GAAG,OAAOC,SAASC,QAAQ,aAAaD,QAAQC,GAAG,KAAK,IAAI;YACrE,GAAIX,QAAQC,OAAOO,aAAa,CAAC,CAAC;QACpC;QACAI,MAAM;YACJC,oBAAoB;YACpBC,QAAQ;YACRC,aAAa;YACb,GAAIf,QAAQC,OAAOW,QAAQ,CAAC,CAAC;QAC/B;QACAI,QAAQ;YACNC,SAAS;YACTC,iBAAiB;YACjBC,QAAQ;YACRC,YAAY;YACZC,OAAO;YACPC,QAAQ;YACRC,OAAO;YACPC,cAAc;YACd,GAAIxB,QAAQC,OAAOe,UAAU,CAAC,CAAC;QACjC;IACF;IAEAhB,OAAOyB,GAAG,GAAGzB,OAAOyB,GAAG,IAAI,EAAE;IAC7BzB,OAAO0B,WAAW,GAAG1B,OAAO0B,WAAW,IAAI,EAAE;IAC7C1B,OAAO2B,YAAY,GAAG3B,OAAO2B,YAAY,IAAI;IAC7C3B,OAAO4B,IAAI,GAAG5B,OAAO4B,IAAI,IAAI,EAAE;IAC/B5B,OAAO6B,IAAI,GAAG7B,OAAO6B,IAAI,IAAI,EAAE;IAC/B7B,OAAOI,MAAM,GAAGJ,OAAOI,MAAM,IAAI,CAAC;IAClCJ,OAAO8B,YAAY,GAAG9B,OAAO8B,YAAY,IAAI;IAC7C9B,OAAO+B,oBAAoB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tD,OAAOyD,MAAM,GAAGzD,OAAOyD,MAAM,IAAI,CAAC;IAElCzD,OAAO0D,IAAI,GAAG;QACZC,UAAU;YAAC;YAAO;YAAU;SAAS;QACrC,GAAI3D,OAAO0D,IAAI,IAAI,CAAC,CAAC;IACvB;IAEA1D,OAAO4D,EAAE,GAAG5D,OAAO4D,EAAE,IAAI9D;IAEzB,IAAIE,OAAO4D,EAAE,EAAEC,cAAc;QAC3B7D,OAAO0B,WAAW,CAACoC,IAAI,CAAC9D,OAAO4D,EAAE,CAACC,YAAY;IAChD;IAEA,OAAO7D;AACT,EAAC"}
@@ -3,17 +3,16 @@ import type { Config, Plugin, PluginsMap } from './types.js';
3
3
  * Helper for authoring plugins with order, slug, and typed options.
4
4
  * Eliminates boilerplate and ensures metadata is always set consistently.
5
5
  *
6
- * The `plugin` function receives a single object containing `config`, `plugins`
7
- * (a slug-keyed map of other plugins), and any user-provided options spread in.
6
+ * The `plugin` function receives `config`, `plugins` (a slug-keyed map of other
7
+ * plugins), and the user-provided `options`.
8
8
  *
9
9
  * @experimental
10
10
  *
11
11
  * @example
12
12
  * // With options:
13
- * export const seoPlugin = definePlugin<SEOPluginOptions>({
13
+ * export const seoPlugin = definePlugin<SEOPluginConfig>({
14
14
  * slug: 'plugin-seo',
15
- * order: 10,
16
- * plugin: ({ config, plugins, collections }) => ({ ...config }),
15
+ * plugin: ({ config, options }) => ({ ...config }),
17
16
  * })
18
17
  *
19
18
  * // Without options:
@@ -28,14 +27,15 @@ export declare function definePlugin(descriptor: {
28
27
  config: Config;
29
28
  plugins: PluginsMap;
30
29
  }) => Config | Promise<Config>;
31
- slug?: string;
30
+ slug: string;
32
31
  }): () => Plugin;
33
- export declare function definePlugin<TOptions extends Record<string, unknown>>(descriptor: {
32
+ export declare function definePlugin<TOptions>(descriptor: {
34
33
  order?: number;
35
34
  plugin: (args: {
36
35
  config: Config;
36
+ options: TOptions;
37
37
  plugins: PluginsMap;
38
- } & TOptions) => Config | Promise<Config>;
39
- slug?: string;
40
- }): (options: TOptions) => Plugin;
38
+ }) => Config | Promise<Config>;
39
+ slug: string;
40
+ }): undefined extends TOptions ? (options?: TOptions) => Plugin : (options: TOptions) => Plugin;
41
41
  //# sourceMappingURL=definePlugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"definePlugin.d.ts","sourceRoot":"","sources":["../../src/config/definePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAc5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,UAAU,CAAA;KAAE,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACnF,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,MAAM,MAAM,CAAA;AAChB,wBAAgB,YAAY,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE;IACjF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,UAAU,CAAA;KAAE,GAAG,QAAQ,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9F,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAA"}
1
+ {"version":3,"file":"definePlugin.d.ts","sourceRoot":"","sources":["../../src/config/definePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAc5D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,UAAU,CAAA;KAAE,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACnF,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,MAAM,MAAM,CAAA;AAChB,wBAAgB,YAAY,CAAC,QAAQ,EAAE,UAAU,EAAE;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QACb,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,QAAQ,CAAA;QACjB,OAAO,EAAE,UAAU,CAAA;KACpB,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,SAAS,SAAS,QAAQ,GAAG,CAAC,OAAO,CAAC,EAAE,QAAQ,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAA"}
@@ -11,19 +11,15 @@ function buildPluginsMap(plugins) {
11
11
  }
12
12
  export function definePlugin(descriptor) {
13
13
  return (options)=>{
14
- const pluginFn = (config)=>{
15
- const plugins = buildPluginsMap(config.plugins);
16
- const args = {
17
- ...options,
14
+ const pluginFn = (config)=>descriptor.plugin({
18
15
  config,
19
- plugins
20
- };
21
- return descriptor.plugin(args);
22
- };
23
- pluginFn.options = options;
24
- if (descriptor.slug !== undefined) {
25
- pluginFn.slug = descriptor.slug;
16
+ options: options,
17
+ plugins: buildPluginsMap(config.plugins)
18
+ });
19
+ if (options !== undefined) {
20
+ pluginFn.options = options;
26
21
  }
22
+ pluginFn.slug = descriptor.slug;
27
23
  if (descriptor.order !== undefined) {
28
24
  pluginFn.order = descriptor.order;
29
25
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/definePlugin.ts"],"sourcesContent":["import type { Config, Plugin, PluginsMap } from './types.js'\n\nfunction buildPluginsMap(plugins: Plugin[] | undefined): PluginsMap {\n const map: Record<string, Plugin | undefined> = {}\n if (plugins) {\n for (const p of plugins) {\n if (p.slug) {\n map[p.slug] = p\n }\n }\n }\n return map as PluginsMap\n}\n\n/**\n * Helper for authoring plugins with order, slug, and typed options.\n * Eliminates boilerplate and ensures metadata is always set consistently.\n *\n * The `plugin` function receives a single object containing `config`, `plugins`\n * (a slug-keyed map of other plugins), and any user-provided options spread in.\n *\n * @experimental\n *\n * @example\n * // With options:\n * export const seoPlugin = definePlugin<SEOPluginOptions>({\n * slug: 'plugin-seo',\n * order: 10,\n * plugin: ({ config, plugins, collections }) => ({ ...config }),\n * })\n *\n * // Without options:\n * export const myPlugin = definePlugin({\n * slug: 'my-plugin',\n * plugin: ({ config }) => ({ ...config }),\n * })\n */\nexport function definePlugin(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap }) => Config | Promise<Config>\n slug?: string\n}): () => Plugin\nexport function definePlugin<TOptions extends Record<string, unknown>>(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap } & TOptions) => Config | Promise<Config>\n slug?: string\n}): (options: TOptions) => Plugin\nexport function definePlugin<TOptions extends Record<string, unknown>>(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap } & TOptions) => Config | Promise<Config>\n slug?: string\n}): (options?: TOptions) => Plugin {\n return (options?: TOptions): Plugin => {\n const pluginFn: Plugin = (config) => {\n const plugins = buildPluginsMap(config.plugins)\n\n const args = {\n ...options,\n config,\n plugins,\n } as { config: Config; plugins: PluginsMap } & TOptions\n\n return descriptor.plugin(args)\n }\n\n pluginFn.options = options as Record<string, unknown>\n\n if (descriptor.slug !== undefined) {\n pluginFn.slug = descriptor.slug\n }\n if (descriptor.order !== undefined) {\n pluginFn.order = descriptor.order\n }\n\n return pluginFn\n }\n}\n"],"names":["buildPluginsMap","plugins","map","p","slug","definePlugin","descriptor","options","pluginFn","config","args","plugin","undefined","order"],"mappings":"AAEA,SAASA,gBAAgBC,OAA6B;IACpD,MAAMC,MAA0C,CAAC;IACjD,IAAID,SAAS;QACX,KAAK,MAAME,KAAKF,QAAS;YACvB,IAAIE,EAAEC,IAAI,EAAE;gBACVF,GAAG,CAACC,EAAEC,IAAI,CAAC,GAAGD;YAChB;QACF;IACF;IACA,OAAOD;AACT;AAmCA,OAAO,SAASG,aAAuDC,UAItE;IACC,OAAO,CAACC;QACN,MAAMC,WAAmB,CAACC;YACxB,MAAMR,UAAUD,gBAAgBS,OAAOR,OAAO;YAE9C,MAAMS,OAAO;gBACX,GAAGH,OAAO;gBACVE;gBACAR;YACF;YAEA,OAAOK,WAAWK,MAAM,CAACD;QAC3B;QAEAF,SAASD,OAAO,GAAGA;QAEnB,IAAID,WAAWF,IAAI,KAAKQ,WAAW;YACjCJ,SAASJ,IAAI,GAAGE,WAAWF,IAAI;QACjC;QACA,IAAIE,WAAWO,KAAK,KAAKD,WAAW;YAClCJ,SAASK,KAAK,GAAGP,WAAWO,KAAK;QACnC;QAEA,OAAOL;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/config/definePlugin.ts"],"sourcesContent":["import type { Config, Plugin, PluginsMap } from './types.js'\n\nfunction buildPluginsMap(plugins: Plugin[] | undefined): PluginsMap {\n const map: Record<string, Plugin | undefined> = {}\n if (plugins) {\n for (const p of plugins) {\n if (p.slug) {\n map[p.slug] = p\n }\n }\n }\n return map as PluginsMap\n}\n\n/**\n * Helper for authoring plugins with order, slug, and typed options.\n * Eliminates boilerplate and ensures metadata is always set consistently.\n *\n * The `plugin` function receives `config`, `plugins` (a slug-keyed map of other\n * plugins), and the user-provided `options`.\n *\n * @experimental\n *\n * @example\n * // With options:\n * export const seoPlugin = definePlugin<SEOPluginConfig>({\n * slug: 'plugin-seo',\n * plugin: ({ config, options }) => ({ ...config }),\n * })\n *\n * // Without options:\n * export const myPlugin = definePlugin({\n * slug: 'my-plugin',\n * plugin: ({ config }) => ({ ...config }),\n * })\n */\nexport function definePlugin(descriptor: {\n order?: number\n plugin: (args: { config: Config; plugins: PluginsMap }) => Config | Promise<Config>\n slug: string\n}): () => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): undefined extends TOptions ? (options?: TOptions) => Plugin : (options: TOptions) => Plugin\nexport function definePlugin<TOptions>(descriptor: {\n order?: number\n plugin: (args: {\n config: Config\n options: TOptions\n plugins: PluginsMap\n }) => Config | Promise<Config>\n slug: string\n}): (options: TOptions) => Plugin {\n return (options?: TOptions): Plugin => {\n const pluginFn: Plugin = (config) =>\n descriptor.plugin({\n config,\n options: options as TOptions,\n plugins: buildPluginsMap(config.plugins),\n })\n\n if (options !== undefined) {\n pluginFn.options = options as Record<string, unknown>\n }\n pluginFn.slug = descriptor.slug\n if (descriptor.order !== undefined) {\n pluginFn.order = descriptor.order\n }\n\n return pluginFn\n }\n}\n"],"names":["buildPluginsMap","plugins","map","p","slug","definePlugin","descriptor","options","pluginFn","config","plugin","undefined","order"],"mappings":"AAEA,SAASA,gBAAgBC,OAA6B;IACpD,MAAMC,MAA0C,CAAC;IACjD,IAAID,SAAS;QACX,KAAK,MAAME,KAAKF,QAAS;YACvB,IAAIE,EAAEC,IAAI,EAAE;gBACVF,GAAG,CAACC,EAAEC,IAAI,CAAC,GAAGD;YAChB;QACF;IACF;IACA,OAAOD;AACT;AAsCA,OAAO,SAASG,aAAuBC,UAQtC;IACC,OAAO,CAACC;QACN,MAAMC,WAAmB,CAACC,SACxBH,WAAWI,MAAM,CAAC;gBAChBD;gBACAF,SAASA;gBACTN,SAASD,gBAAgBS,OAAOR,OAAO;YACzC;QAEF,IAAIM,YAAYI,WAAW;YACzBH,SAASD,OAAO,GAAGA;QACrB;QACAC,SAASJ,IAAI,GAAGE,WAAWF,IAAI;QAC/B,IAAIE,WAAWM,KAAK,KAAKD,WAAW;YAClCH,SAASI,KAAK,GAAGN,WAAWM,KAAK;QACnC;QAEA,OAAOJ;IACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/orderable/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,aAAa,CAAA;AAc5E,eAAO,MAAM,yBAAyB,GACpC,YAAY,gBAAgB,EAC5B,QAAQ,MAAM,EACd,qBAAqB,MAAM,EAAE,EAC7B,6BAA6B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,kBAuF9D,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAA;IAChC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAA;QACV,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,eAAe,EACvB,4BAA4B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,SA4L7D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/orderable/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,aAAa,CAAA;AAgB5E,eAAO,MAAM,yBAAyB,GACpC,YAAY,gBAAgB,EAC5B,QAAQ,MAAM,EACd,qBAAqB,MAAM,EAAE,EAC7B,6BAA6B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,kBAuF9D,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAA;IAChC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAA;QACV,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,eAAe,EACvB,4BAA4B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,SAiN7D,CAAA"}
@@ -4,8 +4,10 @@ import { APIError } from '../../errors/index.js';
4
4
  import { sanitizeField } from '../../fields/config/sanitize.js';
5
5
  import { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js';
6
6
  import { commitTransaction } from '../../utilities/commitTransaction.js';
7
+ import { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js';
7
8
  import { initTransaction } from '../../utilities/initTransaction.js';
8
9
  import { killTransaction } from '../../utilities/killTransaction.js';
10
+ import { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js';
9
11
  import { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js';
10
12
  import { getJoinScopeContext } from './utils/getJoinScopeContext.js';
11
13
  import { getJoinScopeWhereFromDocData } from './utils/getJoinScopeWhereFromDocData.js';
@@ -255,8 +257,28 @@ export const addOrderableEndpoint = (config, joinFieldPathsByCollection)=>{
255
257
  // Currently N (= docsToMove.length) is always 1. Maybe in the future we will
256
258
  // allow dragging and reordering multiple documents at once via the UI.
257
259
  const orderValues = newKeyWillBe === 'greater' ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length) : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length);
260
+ const draftsEnabled = hasDraftsEnabled(collection);
258
261
  // Update each document with its new order value
259
262
  for (const [index, id] of docsToMove.entries()){
263
+ let draft;
264
+ if (draftsEnabled) {
265
+ const latestVersion = await getLatestCollectionVersion({
266
+ id,
267
+ config: collection,
268
+ payload: req.payload,
269
+ query: {
270
+ collection: collection.slug,
271
+ req,
272
+ where: {
273
+ id: {
274
+ equals: id
275
+ }
276
+ }
277
+ },
278
+ req
279
+ });
280
+ draft = latestVersion?._status === 'draft';
281
+ }
260
282
  await req.payload.update({
261
283
  id,
262
284
  collection: collection.slug,
@@ -264,6 +286,7 @@ export const addOrderableEndpoint = (config, joinFieldPathsByCollection)=>{
264
286
  [orderableFieldName]: orderValues[index]
265
287
  },
266
288
  depth: 0,
289
+ draft,
267
290
  req
268
291
  });
269
292
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Config } from '../../config/types.js'\nimport type { Field, TextField } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { APIError } from '../../errors/index.js'\nimport { sanitizeField } from '../../fields/config/sanitize.js'\nimport { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\nimport { getJoinScopeContext } from './utils/getJoinScopeContext.js'\nimport { getJoinScopeWhereFromDocData } from './utils/getJoinScopeWhereFromDocData.js'\nimport { resolvePendingTargetKey } from './utils/resolvePendingTargetKey.js'\n\nexport const addOrderableFieldsAndHook = async (\n collection: CollectionConfig,\n config: Config,\n orderableFieldNames: string[],\n joinFieldPathsByCollection?: Map<string, Map<string, string>>,\n) => {\n // 1. Add fields\n for (const orderableFieldName of orderableFieldNames) {\n const orderField: TextField = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disabled: true,\n hidden: true,\n readOnly: true,\n },\n hooks: {\n beforeDuplicate: [\n ({ siblingData }) => {\n delete siblingData[orderableFieldName]\n },\n ],\n },\n index: true,\n }\n\n // Sanitize the field using the standard sanitization logic\n await sanitizeField({\n collectionConfig: collection,\n config,\n existingFieldNames: new Set(),\n field: orderField,\n index: 0,\n isTopLevelField: true,\n joinPath: '',\n parentIndexPath: '',\n parentIsLocalized: false,\n parentSchemaPath: '',\n requireFieldLevelRichTextEditor: false,\n validRelationships: null,\n })\n\n collection.fields.unshift(orderField)\n }\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n const joinScopeWhere = getJoinScopeWhereFromDocData({\n collectionSlug: collection.slug,\n data,\n joinFieldPathsByCollection,\n orderableFieldName,\n originalDoc,\n })\n\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: true,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (\n config: SanitizedConfig,\n joinFieldPathsByCollection: Map<string, Map<string, string>>,\n) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n const { joinScopeWhere, targetDoc } = await getJoinScopeContext({\n collectionSlug: collection.slug,\n joinFieldPathsByCollection,\n orderableFieldName,\n req,\n target,\n })\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n /**\n * If there is no target.key, we can assume the user enabled `orderable`\n * on a collection with existing documents, and that this is the first\n * time they tried to reorder them. Therefore, we perform a one-time\n * migration by setting the key value for all documents. We do this\n * instead of enforcing `required` and `unique` at the database schema\n * level, so that users don't have to run a migration when they enable\n * `orderable` on a collection with existing documents.\n */\n if (!target.key) {\n const { docs } = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 0,\n req,\n select: { [orderableFieldName]: true },\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: false,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n await initTransaction(req)\n // We cannot update all documents in a single operation with `payload.update`,\n // because they would all end up with the same order key (`a0`).\n try {\n for (const doc of docs) {\n await req.payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n // no data needed since the order hooks will handle this\n },\n depth: 0,\n req,\n })\n await commitTransaction(req)\n }\n } catch (e) {\n await killTransaction(req)\n if (e instanceof Error) {\n throw new APIError(e.message, httpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n return new Response(JSON.stringify({ message: 'initial migration', success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n const targetId = target.id\n const targetKey = await resolvePendingTargetKey({\n collectionSlug: collection.slug,\n orderableFieldName,\n req,\n targetDoc,\n targetID: targetId,\n targetKey: target.key,\n })\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n req,\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["status","httpStatus","executeAccess","APIError","sanitizeField","combineWhereConstraints","commitTransaction","initTransaction","killTransaction","generateKeyBetween","generateNKeysBetween","getJoinScopeContext","getJoinScopeWhereFromDocData","resolvePendingTargetKey","addOrderableFieldsAndHook","collection","config","orderableFieldNames","joinFieldPathsByCollection","orderableFieldName","orderField","name","type","admin","disabled","hidden","readOnly","hooks","beforeDuplicate","siblingData","index","collectionConfig","existingFieldNames","Set","field","isTopLevelField","joinPath","parentIndexPath","parentIsLocalized","parentSchemaPath","requireFieldLevelRichTextEditor","validRelationships","fields","unshift","beforeChange","orderBeforeChangeHook","data","originalDoc","req","joinScopeWhere","collectionSlug","slug","lastDoc","payload","find","depth","limit","pagination","select","sort","where","exists","undefined","lastOrderValue","docs","push","addOrderableEndpoint","reorderHandler","body","json","docsToMove","newKeyWillBe","target","Array","isArray","length","Response","JSON","stringify","error","headers","collections","c","targetDoc","access","update","id","key","doc","e","Error","message","INTERNAL_SERVER_ERROR","success","targetId","targetKey","targetID","adjacentDoc","adjacentDocKey","orderValues","entries","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa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AOyF,SAAS,EAAE;QACrBzF,OAAOyF,SAAS,GAAG,EAAE;IACvB;IAEAzF,OAAOyF,SAAS,CAACxC,IAAI,CAACoC;AACxB,EAAC"}
1
+ {"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Config } from '../../config/types.js'\nimport type { Field, TextField } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { APIError } from '../../errors/index.js'\nimport { sanitizeField } from '../../fields/config/sanitize.js'\nimport { combineWhereConstraints } from '../../utilities/combineWhereConstraints.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\nimport { getJoinScopeContext } from './utils/getJoinScopeContext.js'\nimport { getJoinScopeWhereFromDocData } from './utils/getJoinScopeWhereFromDocData.js'\nimport { resolvePendingTargetKey } from './utils/resolvePendingTargetKey.js'\n\nexport const addOrderableFieldsAndHook = async (\n collection: CollectionConfig,\n config: Config,\n orderableFieldNames: string[],\n joinFieldPathsByCollection?: Map<string, Map<string, string>>,\n) => {\n // 1. Add fields\n for (const orderableFieldName of orderableFieldNames) {\n const orderField: TextField = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disabled: true,\n hidden: true,\n readOnly: true,\n },\n hooks: {\n beforeDuplicate: [\n ({ siblingData }) => {\n delete siblingData[orderableFieldName]\n },\n ],\n },\n index: true,\n }\n\n // Sanitize the field using the standard sanitization logic\n await sanitizeField({\n collectionConfig: collection,\n config,\n existingFieldNames: new Set(),\n field: orderField,\n index: 0,\n isTopLevelField: true,\n joinPath: '',\n parentIndexPath: '',\n parentIsLocalized: false,\n parentSchemaPath: '',\n requireFieldLevelRichTextEditor: false,\n validRelationships: null,\n })\n\n collection.fields.unshift(orderField)\n }\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n const joinScopeWhere = getJoinScopeWhereFromDocData({\n collectionSlug: collection.slug,\n data,\n joinFieldPathsByCollection,\n orderableFieldName,\n originalDoc,\n })\n\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: true,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (\n config: SanitizedConfig,\n joinFieldPathsByCollection: Map<string, Map<string, string>>,\n) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n const { joinScopeWhere, targetDoc } = await getJoinScopeContext({\n collectionSlug: collection.slug,\n joinFieldPathsByCollection,\n orderableFieldName,\n req,\n target,\n })\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n /**\n * If there is no target.key, we can assume the user enabled `orderable`\n * on a collection with existing documents, and that this is the first\n * time they tried to reorder them. Therefore, we perform a one-time\n * migration by setting the key value for all documents. We do this\n * instead of enforcing `required` and `unique` at the database schema\n * level, so that users don't have to run a migration when they enable\n * `orderable` on a collection with existing documents.\n */\n if (!target.key) {\n const { docs } = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 0,\n req,\n select: { [orderableFieldName]: true },\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n exists: false,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n await initTransaction(req)\n // We cannot update all documents in a single operation with `payload.update`,\n // because they would all end up with the same order key (`a0`).\n try {\n for (const doc of docs) {\n await req.payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n // no data needed since the order hooks will handle this\n },\n depth: 0,\n req,\n })\n await commitTransaction(req)\n }\n } catch (e) {\n await killTransaction(req)\n if (e instanceof Error) {\n throw new APIError(e.message, httpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n return new Response(JSON.stringify({ message: 'initial migration', success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n const targetId = target.id\n const targetKey = await resolvePendingTargetKey({\n collectionSlug: collection.slug,\n orderableFieldName,\n req,\n targetDoc,\n targetID: targetId,\n targetKey: target.key,\n })\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: combineWhereConstraints([\n {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n joinScopeWhere ?? undefined,\n ]),\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n const draftsEnabled = hasDraftsEnabled(collection)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n let draft: boolean | undefined\n\n if (draftsEnabled) {\n const latestVersion = await getLatestCollectionVersion({\n id,\n config: collection,\n payload: req.payload,\n query: {\n collection: collection.slug,\n req,\n where: { id: { equals: id } },\n },\n req,\n })\n\n draft = latestVersion?._status === 'draft'\n }\n\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n draft,\n req,\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["status","httpStatus","executeAccess","APIError","sanitizeField","combineWhereConstraints","commitTransaction","hasDraftsEnabled","initTransaction","killTransaction","getLatestCollectionVersion","generateKeyBetween","generateNKeysBetween","getJoinScopeContext","getJoinScopeWhereFromDocData","resolvePendingTargetKey","addOrderableFieldsAndHook","collection","config","orderableFieldNames","joinFieldPathsByCollection","orderableFieldName","orderField","name","type","admin","disabled","hidden","readOnly","hooks","beforeDuplicate","siblingData","index","collectionConfig","existingFieldNames","Set","field","isTopLevelField","joinPath","parentIndexPath","parentIsLocalized","parentSchemaPath","requireFieldLevelRichTextEditor","validRelationships","fields","unshift","beforeChange","orderBeforeChangeHook","data","originalDoc","req","joinScopeWhere","collectionSlug","slug","lastDoc","payload","find","depth","limit","pagination","select","sort","where","exists","undefined","lastOrderValue","docs","push","addOrderableEndpoint","reorderHandler","body","json","docsToMove","newKeyWillBe","target","Array","isArray","length","Response","JSON","stringify","error","headers","collections","c","targetDoc","access","update","id","key","doc","e","Error","message","INTERNAL_SERVER_ERROR","success","targetId","targetKey","targetID","adjacentDoc","adjacentDocKey","orderValues","draftsEnabled","entries","draft","latestVersion","query","equals","_status","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAOlD,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,aAAa,QAAQ,kCAAiC;AAC/D,SAASC,uBAAuB,QAAQ,6CAA4C;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BAC1C;gBACAyB,OAAO;gBACP+C;gBACAtD;YACF;QACF;QAEA,OAAO,IAAI4B,SAASC,KAAKC,SAAS,CAAC;YAAEqB;YAAaN,SAAS;QAAK,IAAI;YAClEb,SAAS;gBAAE,gBAAgB;YAAmB;YAC9ClF,QAAQ;QACV;IACF;IAEA,MAAM6G,kBAA4B;QAChCC,SAASzC;QACT0C,QAAQ;QACRC,MAAM;IACR;IAEA,IAAI,CAAC9F,OAAO+F,SAAS,EAAE;QACrB/F,OAAO+F,SAAS,GAAG,EAAE;IACvB;IAEA/F,OAAO+F,SAAS,CAAC9C,IAAI,CAAC0C;AACxB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/config/sanitize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,MAAM,EAGN,eAAe,EAIhB,MAAM,YAAY,CAAA;AA+FnB,eAAO,MAAM,cAAc,GAAU,gBAAgB,MAAM,KAAG,OAAO,CAAC,eAAe,CAgYpF,CAAA"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/config/sanitize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,MAAM,EAIN,eAAe,EAIhB,MAAM,YAAY,CAAA;AAiOnB,eAAO,MAAM,cAAc,GAAU,gBAAgB,MAAM,KAAG,OAAO,CAAC,eAAe,CAsYpF,CAAA"}
@@ -32,19 +32,6 @@ const sanitizeAdminConfig = (configToSanitize)=>{
32
32
  ValidationError: 'info',
33
33
  ...sanitizedConfig.loggingLevels || {}
34
34
  };
35
- (sanitizedConfig.admin.dashboard ??= {
36
- widgets: []
37
- }).widgets.push({
38
- slug: 'collections',
39
- Component: '@payloadcms/ui/rsc#CollectionCards',
40
- minWidth: 'full'
41
- });
42
- sanitizedConfig.admin.dashboard.defaultLayout ??= [
43
- {
44
- widgetSlug: 'collections',
45
- width: 'full'
46
- }
47
- ];
48
35
  // add default user collection if none provided
49
36
  if (!sanitizedConfig?.admin?.user) {
50
37
  const firstCollectionWithAuth = sanitizedConfig.collections.find(({ auth })=>Boolean(auth));
@@ -79,6 +66,138 @@ const sanitizeAdminConfig = (configToSanitize)=>{
79
66
  });
80
67
  return sanitizedConfig;
81
68
  };
69
+ const addDefaultDashboardWidgets = async ({ config, richTextSanitizationPromises, validRelationships })=>{
70
+ const collectionQueryFields = [
71
+ {
72
+ name: 'title',
73
+ type: 'text',
74
+ label: ({ t })=>t('dashboard:widgetTitleLabel')
75
+ },
76
+ {
77
+ name: 'relatedCollection',
78
+ type: 'select',
79
+ label: ({ t })=>t('general:collection'),
80
+ // Only offer collections that are visible in the admin UI. Collections hidden via a function
81
+ // are kept since they may still be visible for some users.
82
+ options: (config.collections ?? []).filter((collection)=>collection.admin?.hidden !== true).map((collection)=>({
83
+ label: collection.labels?.plural || collection.slug,
84
+ value: collection.slug
85
+ })),
86
+ required: true
87
+ },
88
+ {
89
+ name: 'where',
90
+ type: 'json',
91
+ admin: {
92
+ components: {
93
+ Field: '@payloadcms/ui#QueryPresetsWhereField'
94
+ }
95
+ },
96
+ label: ({ t })=>t('general:filters')
97
+ },
98
+ {
99
+ name: 'sortField',
100
+ type: 'text',
101
+ admin: {
102
+ components: {
103
+ Field: '@payloadcms/ui#CollectionQuerySortField'
104
+ }
105
+ },
106
+ label: ({ t })=>t('dashboard:widgetSortFieldLabel')
107
+ },
108
+ {
109
+ name: 'sortDirection',
110
+ type: 'select',
111
+ defaultValue: 'desc',
112
+ label: ({ t })=>t('dashboard:widgetSortDirectionLabel'),
113
+ options: [
114
+ {
115
+ label: ({ t })=>t('general:ascending'),
116
+ value: 'asc'
117
+ },
118
+ {
119
+ label: ({ t })=>t('general:descending'),
120
+ value: 'desc'
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ name: 'limit',
126
+ type: 'number',
127
+ defaultValue: 5,
128
+ label: ({ t })=>t('dashboard:widgetLimitLabel'),
129
+ max: 25,
130
+ min: 1
131
+ }
132
+ ];
133
+ const recentlyViewedFields = [
134
+ {
135
+ name: 'excludedCollections',
136
+ type: 'select',
137
+ admin: {
138
+ components: {
139
+ // Presents an inclusion filter (all collections checked by default) while persisting the
140
+ // inverse as an exclusion list, so collections added later stay visible by default.
141
+ Field: '@payloadcms/ui#RecentlyViewedCollectionsField'
142
+ }
143
+ },
144
+ hasMany: true,
145
+ label: ({ t })=>t('general:collections'),
146
+ // Exclusion list, so an empty value shows every collection and newly added collections are
147
+ // included by default. Hidden collections are never offered as options.
148
+ options: (config.collections ?? []).filter((collection)=>collection.admin?.hidden !== true).map((collection)=>({
149
+ label: collection.labels?.plural || collection.slug,
150
+ value: collection.slug
151
+ }))
152
+ }
153
+ ];
154
+ const adminConfig = config.admin ?? {
155
+ dashboard: {
156
+ widgets: []
157
+ }
158
+ };
159
+ const dashboard = adminConfig.dashboard ??= {
160
+ widgets: []
161
+ };
162
+ dashboard.widgets.push({
163
+ slug: 'collections',
164
+ Component: '@payloadcms/ui/rsc#CollectionCards',
165
+ minWidth: 'full'
166
+ });
167
+ dashboard.widgets.push({
168
+ slug: 'collection-query',
169
+ Component: '@payloadcms/ui/rsc#CollectionQueryWidget',
170
+ fields: await sanitizeFields({
171
+ config: config,
172
+ existingFieldNames: new Set(),
173
+ fields: collectionQueryFields,
174
+ parentIsLocalized: false,
175
+ richTextSanitizationPromises,
176
+ validRelationships
177
+ }),
178
+ minWidth: 'x-small'
179
+ });
180
+ dashboard.widgets.push({
181
+ slug: 'activity',
182
+ Component: '@payloadcms/ui/rsc#RecentlyViewedWidget',
183
+ fields: await sanitizeFields({
184
+ config: config,
185
+ existingFieldNames: new Set(),
186
+ fields: recentlyViewedFields,
187
+ parentIsLocalized: false,
188
+ richTextSanitizationPromises,
189
+ validRelationships
190
+ }),
191
+ label: ({ t })=>t('dashboard:widgetRecentlyViewedTitle'),
192
+ minWidth: 'x-small'
193
+ });
194
+ dashboard.defaultLayout ??= [
195
+ {
196
+ widgetSlug: 'collections',
197
+ width: 'full'
198
+ }
199
+ ];
200
+ };
82
201
  export const sanitizeConfig = async (incomingConfig)=>{
83
202
  const configWithDefaults = addDefaultsToConfig(incomingConfig);
84
203
  const config = sanitizeAdminConfig(configWithDefaults);
@@ -298,6 +417,11 @@ export const sanitizeConfig = async (incomingConfig)=>{
298
417
  if (queryPresetsCollections.length > 0) {
299
418
  configWithDefaults.collections.push(await sanitizeCollection(config, getQueryPresetsConfig(config), richTextSanitizationPromises, validRelationships));
300
419
  }
420
+ await addDefaultDashboardWidgets({
421
+ config,
422
+ richTextSanitizationPromises,
423
+ validRelationships
424
+ });
301
425
  if (config.serverURL !== '') {
302
426
  config.csrf.push(config.serverURL);
303
427
  }