@dyrected/core 2.5.53 → 2.5.55

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 (405) hide show
  1. package/package.json +1 -1
  2. package/dist/__tests__/admin-auth.test.d.ts +0 -2
  3. package/dist/__tests__/admin-auth.test.d.ts.map +0 -1
  4. package/dist/__tests__/admin-auth.test.js +0 -440
  5. package/dist/__tests__/admin-auth.test.js.map +0 -1
  6. package/dist/__tests__/app.test.d.ts +0 -2
  7. package/dist/__tests__/app.test.d.ts.map +0 -1
  8. package/dist/__tests__/app.test.js +0 -27
  9. package/dist/__tests__/app.test.js.map +0 -1
  10. package/dist/__tests__/config.test.d.ts +0 -2
  11. package/dist/__tests__/config.test.d.ts.map +0 -1
  12. package/dist/__tests__/config.test.js +0 -91
  13. package/dist/__tests__/config.test.js.map +0 -1
  14. package/dist/__tests__/deleteMany.test.d.ts +0 -2
  15. package/dist/__tests__/deleteMany.test.d.ts.map +0 -1
  16. package/dist/__tests__/deleteMany.test.js +0 -75
  17. package/dist/__tests__/deleteMany.test.js.map +0 -1
  18. package/dist/__tests__/depth.test.d.ts +0 -2
  19. package/dist/__tests__/depth.test.d.ts.map +0 -1
  20. package/dist/__tests__/depth.test.js +0 -81
  21. package/dist/__tests__/depth.test.js.map +0 -1
  22. package/dist/__tests__/dynamic-options.test.d.ts +0 -2
  23. package/dist/__tests__/dynamic-options.test.d.ts.map +0 -1
  24. package/dist/__tests__/dynamic-options.test.js +0 -132
  25. package/dist/__tests__/dynamic-options.test.js.map +0 -1
  26. package/dist/__tests__/email.service.test.d.ts +0 -2
  27. package/dist/__tests__/email.service.test.d.ts.map +0 -1
  28. package/dist/__tests__/email.service.test.js +0 -46
  29. package/dist/__tests__/email.service.test.js.map +0 -1
  30. package/dist/__tests__/field-inference.test-types.d.ts +0 -24
  31. package/dist/__tests__/field-inference.test-types.d.ts.map +0 -1
  32. package/dist/__tests__/field-inference.test-types.js +0 -87
  33. package/dist/__tests__/field-inference.test-types.js.map +0 -1
  34. package/dist/__tests__/fixtures/editorial-workflow.d.ts +0 -9
  35. package/dist/__tests__/fixtures/editorial-workflow.d.ts.map +0 -1
  36. package/dist/__tests__/fixtures/editorial-workflow.js +0 -12
  37. package/dist/__tests__/fixtures/editorial-workflow.js.map +0 -1
  38. package/dist/__tests__/hooks.test.d.ts +0 -2
  39. package/dist/__tests__/hooks.test.d.ts.map +0 -1
  40. package/dist/__tests__/hooks.test.js +0 -320
  41. package/dist/__tests__/hooks.test.js.map +0 -1
  42. package/dist/__tests__/mocks.d.ts +0 -74
  43. package/dist/__tests__/mocks.d.ts.map +0 -1
  44. package/dist/__tests__/mocks.js +0 -159
  45. package/dist/__tests__/mocks.js.map +0 -1
  46. package/dist/__tests__/openapi.test.d.ts +0 -2
  47. package/dist/__tests__/openapi.test.d.ts.map +0 -1
  48. package/dist/__tests__/openapi.test.js +0 -95
  49. package/dist/__tests__/openapi.test.js.map +0 -1
  50. package/dist/__tests__/parse-sort.test.d.ts +0 -2
  51. package/dist/__tests__/parse-sort.test.d.ts.map +0 -1
  52. package/dist/__tests__/parse-sort.test.js +0 -24
  53. package/dist/__tests__/parse-sort.test.js.map +0 -1
  54. package/dist/__tests__/preferences.test.d.ts +0 -2
  55. package/dist/__tests__/preferences.test.d.ts.map +0 -1
  56. package/dist/__tests__/preferences.test.js +0 -168
  57. package/dist/__tests__/preferences.test.js.map +0 -1
  58. package/dist/__tests__/router.test.d.ts +0 -2
  59. package/dist/__tests__/router.test.d.ts.map +0 -1
  60. package/dist/__tests__/router.test.js +0 -52
  61. package/dist/__tests__/router.test.js.map +0 -1
  62. package/dist/__tests__/where.test.d.ts +0 -2
  63. package/dist/__tests__/where.test.d.ts.map +0 -1
  64. package/dist/__tests__/where.test.js +0 -105
  65. package/dist/__tests__/where.test.js.map +0 -1
  66. package/dist/__tests__/workflow.test.d.ts +0 -2
  67. package/dist/__tests__/workflow.test.d.ts.map +0 -1
  68. package/dist/__tests__/workflow.test.js +0 -497
  69. package/dist/__tests__/workflow.test.js.map +0 -1
  70. package/dist/app-B2tg7Djj.d.cts +0 -1575
  71. package/dist/app-B2tg7Djj.d.ts +0 -1575
  72. package/dist/app-BElen1tP.d.cts +0 -1690
  73. package/dist/app-BElen1tP.d.ts +0 -1690
  74. package/dist/app-BOrsS7Tz.d.cts +0 -1771
  75. package/dist/app-BOrsS7Tz.d.ts +0 -1771
  76. package/dist/app-Bh4_Opv0.d.cts +0 -1522
  77. package/dist/app-Bh4_Opv0.d.ts +0 -1522
  78. package/dist/app-BibuoHQG.d.cts +0 -1764
  79. package/dist/app-BibuoHQG.d.ts +0 -1764
  80. package/dist/app-Bv9gaDAN.d.cts +0 -561
  81. package/dist/app-Bv9gaDAN.d.ts +0 -561
  82. package/dist/app-BvG3bRc8.d.cts +0 -419
  83. package/dist/app-BvG3bRc8.d.ts +0 -419
  84. package/dist/app-C-HgyliB.d.cts +0 -1694
  85. package/dist/app-C-HgyliB.d.ts +0 -1694
  86. package/dist/app-C3B9N1KR.d.cts +0 -1522
  87. package/dist/app-C3B9N1KR.d.ts +0 -1522
  88. package/dist/app-Cc2mG3zi.d.cts +0 -373
  89. package/dist/app-Cc2mG3zi.d.ts +0 -373
  90. package/dist/app-Ctfmo2Re.d.cts +0 -1692
  91. package/dist/app-Ctfmo2Re.d.ts +0 -1692
  92. package/dist/app-D0ffogDd.d.cts +0 -1690
  93. package/dist/app-D0ffogDd.d.ts +0 -1690
  94. package/dist/app-D2uR47gK.d.cts +0 -1690
  95. package/dist/app-D2uR47gK.d.ts +0 -1690
  96. package/dist/app-DDJJa0ep.d.cts +0 -1621
  97. package/dist/app-DDJJa0ep.d.ts +0 -1621
  98. package/dist/app-DO1s9YW1.d.cts +0 -1621
  99. package/dist/app-DO1s9YW1.d.ts +0 -1621
  100. package/dist/app-DTP3-9PJ.d.cts +0 -561
  101. package/dist/app-DTP3-9PJ.d.ts +0 -561
  102. package/dist/app-DZt5nslu.d.cts +0 -374
  103. package/dist/app-DZt5nslu.d.ts +0 -377
  104. package/dist/app-DbKDGYTI.d.cts +0 -566
  105. package/dist/app-DbKDGYTI.d.ts +0 -566
  106. package/dist/app-Dk3SzV1a.d.cts +0 -374
  107. package/dist/app-Dk3SzV1a.d.ts +0 -374
  108. package/dist/app-DnX9mNsh.d.cts +0 -374
  109. package/dist/app-DnX9mNsh.d.ts +0 -374
  110. package/dist/app-DqRO-CMi.d.cts +0 -1457
  111. package/dist/app-DqRO-CMi.d.ts +0 -1457
  112. package/dist/app-DvaFpOtj.d.cts +0 -398
  113. package/dist/app-DvaFpOtj.d.ts +0 -398
  114. package/dist/app-FGzip4XM.d.cts +0 -1563
  115. package/dist/app-FGzip4XM.d.ts +0 -1563
  116. package/dist/app-KApbf4XL.d.cts +0 -362
  117. package/dist/app-KApbf4XL.d.ts +0 -362
  118. package/dist/app-T0alZAE0.d.cts +0 -383
  119. package/dist/app-T0alZAE0.d.ts +0 -383
  120. package/dist/app-aW2FMuYM.d.cts +0 -1759
  121. package/dist/app-aW2FMuYM.d.ts +0 -1759
  122. package/dist/app-config-2vF6W56z.d.cts +0 -1335
  123. package/dist/app-config-2vF6W56z.d.ts +0 -1335
  124. package/dist/app-config-3XBnu9Xz.d.cts +0 -1379
  125. package/dist/app-config-3XBnu9Xz.d.ts +0 -1379
  126. package/dist/app-config-BLMX-9MN.d.cts +0 -1045
  127. package/dist/app-config-BLMX-9MN.d.ts +0 -1045
  128. package/dist/app-config-CaEQH0Kb.d.cts +0 -1383
  129. package/dist/app-config-CaEQH0Kb.d.ts +0 -1383
  130. package/dist/app-config-DLK6bCaP.d.cts +0 -1390
  131. package/dist/app-config-DLK6bCaP.d.ts +0 -1390
  132. package/dist/app-config-oOarB6Fw.d.cts +0 -1411
  133. package/dist/app-config-oOarB6Fw.d.ts +0 -1411
  134. package/dist/app-oQt5-9MU.d.cts +0 -1560
  135. package/dist/app-oQt5-9MU.d.ts +0 -1560
  136. package/dist/app-rZj1VFer.d.cts +0 -1621
  137. package/dist/app-rZj1VFer.d.ts +0 -1621
  138. package/dist/app-wo82JRHl.d.cts +0 -445
  139. package/dist/app-wo82JRHl.d.ts +0 -445
  140. package/dist/app.d.ts +0 -21
  141. package/dist/app.d.ts.map +0 -1
  142. package/dist/app.js +0 -56
  143. package/dist/app.js.map +0 -1
  144. package/dist/auth/jexl.d.ts +0 -10
  145. package/dist/auth/jexl.d.ts.map +0 -1
  146. package/dist/auth/jexl.js +0 -22
  147. package/dist/auth/jexl.js.map +0 -1
  148. package/dist/auth/password.d.ts +0 -10
  149. package/dist/auth/password.d.ts.map +0 -1
  150. package/dist/auth/password.js +0 -28
  151. package/dist/auth/password.js.map +0 -1
  152. package/dist/auth/token.d.ts +0 -22
  153. package/dist/auth/token.d.ts.map +0 -1
  154. package/dist/auth/token.js +0 -40
  155. package/dist/auth/token.js.map +0 -1
  156. package/dist/chunk-22JTWD74.js +0 -1784
  157. package/dist/chunk-23URSKPI.js +0 -2371
  158. package/dist/chunk-2JMA3M5S.js +0 -2475
  159. package/dist/chunk-3FZEUK36.js +0 -2470
  160. package/dist/chunk-3VUH2MNW.js +0 -1903
  161. package/dist/chunk-44O2LDPT.js +0 -1513
  162. package/dist/chunk-45JDQDA2.js +0 -1899
  163. package/dist/chunk-4C4L6SD2.js +0 -1524
  164. package/dist/chunk-4EDMZAM5.js +0 -2692
  165. package/dist/chunk-52T4RCFU.js +0 -1972
  166. package/dist/chunk-6ZXEGKT6.js +0 -619
  167. package/dist/chunk-7GGHK75W.js +0 -1835
  168. package/dist/chunk-ALNQINX7.js +0 -2496
  169. package/dist/chunk-B6KDKYXB.js +0 -2502
  170. package/dist/chunk-BEONZV6M.js +0 -1951
  171. package/dist/chunk-C4GEQ5RP.js +0 -1993
  172. package/dist/chunk-CQDVPMEU.js +0 -613
  173. package/dist/chunk-DOJHZ7XN.js +0 -2394
  174. package/dist/chunk-EH7G3LLL.js +0 -2065
  175. package/dist/chunk-EXXOPW3I.js +0 -2483
  176. package/dist/chunk-F4ZC6TXR.js +0 -2065
  177. package/dist/chunk-FCXE5CVC.js +0 -1528
  178. package/dist/chunk-FDQYPPG3.js +0 -2698
  179. package/dist/chunk-FURYJ254.mjs +0 -33
  180. package/dist/chunk-G2QQLBHW.js +0 -24
  181. package/dist/chunk-GM4WW6IE.js +0 -66
  182. package/dist/chunk-GZODLJ3C.js +0 -1861
  183. package/dist/chunk-IIY3E7Q7.js +0 -1996
  184. package/dist/chunk-JJN4J5NS.js +0 -2069
  185. package/dist/chunk-MRUHCNDM.js +0 -1940
  186. package/dist/chunk-NKDX67AW.js +0 -2698
  187. package/dist/chunk-NYUB4AHZ.js +0 -1951
  188. package/dist/chunk-OD4SLW7H.js +0 -1930
  189. package/dist/chunk-OE5MH3NB.js +0 -2070
  190. package/dist/chunk-PH36WQYS.js +0 -1875
  191. package/dist/chunk-PKNFV7KE.js +0 -2469
  192. package/dist/chunk-SUGK7UYL.js +0 -311
  193. package/dist/chunk-TIJHR54M.js +0 -1879
  194. package/dist/chunk-TUUHGLB5.js +0 -2609
  195. package/dist/chunk-UBTRANFX.js +0 -2476
  196. package/dist/chunk-VJWUG2XK.js +0 -1951
  197. package/dist/chunk-W6KURRMW.js +0 -2471
  198. package/dist/chunk-Y4AYI52W.js +0 -631
  199. package/dist/chunk-YDOBB7MY.js +0 -1457
  200. package/dist/chunk-YNJ3YC4N.js +0 -2483
  201. package/dist/chunk-ZFAOBRHT.js +0 -2709
  202. package/dist/controllers/admin-auth.controller.d.ts +0 -68
  203. package/dist/controllers/admin-auth.controller.d.ts.map +0 -1
  204. package/dist/controllers/admin-auth.controller.js +0 -414
  205. package/dist/controllers/admin-auth.controller.js.map +0 -1
  206. package/dist/controllers/auth.controller.d.ts +0 -125
  207. package/dist/controllers/auth.controller.d.ts.map +0 -1
  208. package/dist/controllers/auth.controller.js +0 -323
  209. package/dist/controllers/auth.controller.js.map +0 -1
  210. package/dist/controllers/collection.controller.d.ts +0 -157
  211. package/dist/controllers/collection.controller.d.ts.map +0 -1
  212. package/dist/controllers/collection.controller.js +0 -779
  213. package/dist/controllers/collection.controller.js.map +0 -1
  214. package/dist/controllers/global.controller.d.ts +0 -17
  215. package/dist/controllers/global.controller.d.ts.map +0 -1
  216. package/dist/controllers/global.controller.js +0 -132
  217. package/dist/controllers/global.controller.js.map +0 -1
  218. package/dist/controllers/media.controller.d.ts +0 -38
  219. package/dist/controllers/media.controller.d.ts.map +0 -1
  220. package/dist/controllers/media.controller.js +0 -162
  221. package/dist/controllers/media.controller.js.map +0 -1
  222. package/dist/controllers/preview.controller.d.ts +0 -37
  223. package/dist/controllers/preview.controller.d.ts.map +0 -1
  224. package/dist/controllers/preview.controller.js +0 -48
  225. package/dist/controllers/preview.controller.js.map +0 -1
  226. package/dist/index-BKYugiYp.d.cts +0 -1988
  227. package/dist/index-BKYugiYp.d.ts +0 -1988
  228. package/dist/index-BSWCiAen.d.cts +0 -1983
  229. package/dist/index-BSWCiAen.d.ts +0 -1983
  230. package/dist/index-BfLDb3b0.d.cts +0 -1467
  231. package/dist/index-BfLDb3b0.d.ts +0 -1467
  232. package/dist/index-Bi4sX_eC.d.cts +0 -1491
  233. package/dist/index-Bi4sX_eC.d.ts +0 -1491
  234. package/dist/index-Bp7PDOYG.d.cts +0 -1750
  235. package/dist/index-Bp7PDOYG.d.ts +0 -1750
  236. package/dist/index-ByXooLy-.d.cts +0 -1762
  237. package/dist/index-ByXooLy-.d.ts +0 -1762
  238. package/dist/index-C9Vp1DCT.d.cts +0 -1563
  239. package/dist/index-C9Vp1DCT.d.ts +0 -1563
  240. package/dist/index-CFezd8p1.d.cts +0 -1986
  241. package/dist/index-CFezd8p1.d.ts +0 -1986
  242. package/dist/index-CdQwnbfh.d.cts +0 -1889
  243. package/dist/index-CdQwnbfh.d.ts +0 -1889
  244. package/dist/index-D38_E0gf.d.cts +0 -336
  245. package/dist/index-D38_E0gf.d.ts +0 -336
  246. package/dist/index-DR2z1rrf.d.cts +0 -1503
  247. package/dist/index-DR2z1rrf.d.ts +0 -1503
  248. package/dist/index-DTrpTru7.d.cts +0 -1881
  249. package/dist/index-DTrpTru7.d.ts +0 -1881
  250. package/dist/index-DfAmTZXk.d.cts +0 -1749
  251. package/dist/index-DfAmTZXk.d.ts +0 -1749
  252. package/dist/index-DfkPT4NR.d.cts +0 -1584
  253. package/dist/index-DfkPT4NR.d.ts +0 -1584
  254. package/dist/index-DzUlE5Hc.d.cts +0 -1751
  255. package/dist/index-DzUlE5Hc.d.ts +0 -1751
  256. package/dist/index-M_m6dXZV.d.cts +0 -1889
  257. package/dist/index-M_m6dXZV.d.ts +0 -1889
  258. package/dist/index-RylhgOwj.d.cts +0 -340
  259. package/dist/index-RylhgOwj.d.ts +0 -340
  260. package/dist/index-qhLus8ZO.d.cts +0 -1881
  261. package/dist/index-qhLus8ZO.d.ts +0 -1881
  262. package/dist/index-xB1lMg79.d.cts +0 -1456
  263. package/dist/index-xB1lMg79.d.ts +0 -1456
  264. package/dist/index.d.mts +0 -417
  265. package/dist/index.d.ts.map +0 -1
  266. package/dist/index.js.map +0 -1
  267. package/dist/index.mjs +0 -1974
  268. package/dist/middleware/auth.d.ts +0 -18
  269. package/dist/middleware/auth.d.ts.map +0 -1
  270. package/dist/middleware/auth.js +0 -45
  271. package/dist/middleware/auth.js.map +0 -1
  272. package/dist/password-ACI2YUGZ.js +0 -8
  273. package/dist/router.d.ts +0 -8
  274. package/dist/router.d.ts.map +0 -1
  275. package/dist/router.js +0 -625
  276. package/dist/router.js.map +0 -1
  277. package/dist/server.d.ts.map +0 -1
  278. package/dist/server.js.map +0 -1
  279. package/dist/services/audit.service.d.ts +0 -23
  280. package/dist/services/audit.service.d.ts.map +0 -1
  281. package/dist/services/audit.service.js +0 -28
  282. package/dist/services/audit.service.js.map +0 -1
  283. package/dist/services/defaults.service.d.ts +0 -8
  284. package/dist/services/defaults.service.d.ts.map +0 -1
  285. package/dist/services/defaults.service.js +0 -55
  286. package/dist/services/defaults.service.js.map +0 -1
  287. package/dist/services/email-template.d.ts +0 -46
  288. package/dist/services/email-template.d.ts.map +0 -1
  289. package/dist/services/email-template.js +0 -88
  290. package/dist/services/email-template.js.map +0 -1
  291. package/dist/services/email.service.d.ts +0 -33
  292. package/dist/services/email.service.d.ts.map +0 -1
  293. package/dist/services/email.service.js +0 -96
  294. package/dist/services/email.service.js.map +0 -1
  295. package/dist/services/media.service.d.ts +0 -20
  296. package/dist/services/media.service.d.ts.map +0 -1
  297. package/dist/services/media.service.js +0 -49
  298. package/dist/services/media.service.js.map +0 -1
  299. package/dist/services/population.service.d.ts +0 -20
  300. package/dist/services/population.service.d.ts.map +0 -1
  301. package/dist/services/population.service.js +0 -194
  302. package/dist/services/population.service.js.map +0 -1
  303. package/dist/token-7QG5DBME.mjs +0 -10
  304. package/dist/types/access.d.ts +0 -38
  305. package/dist/types/access.d.ts.map +0 -1
  306. package/dist/types/access.js +0 -2
  307. package/dist/types/access.js.map +0 -1
  308. package/dist/types/adapters.d.ts +0 -146
  309. package/dist/types/adapters.d.ts.map +0 -1
  310. package/dist/types/adapters.js +0 -2
  311. package/dist/types/adapters.js.map +0 -1
  312. package/dist/types/admin-auth.d.ts +0 -132
  313. package/dist/types/admin-auth.d.ts.map +0 -1
  314. package/dist/types/admin-auth.js +0 -2
  315. package/dist/types/admin-auth.js.map +0 -1
  316. package/dist/types/admin.d.ts +0 -65
  317. package/dist/types/admin.d.ts.map +0 -1
  318. package/dist/types/admin.js +0 -2
  319. package/dist/types/admin.js.map +0 -1
  320. package/dist/types/app-config.d.ts +0 -143
  321. package/dist/types/app-config.d.ts.map +0 -1
  322. package/dist/types/app-config.js +0 -2
  323. package/dist/types/app-config.js.map +0 -1
  324. package/dist/types/documents.d.ts +0 -65
  325. package/dist/types/documents.d.ts.map +0 -1
  326. package/dist/types/documents.js +0 -2
  327. package/dist/types/documents.js.map +0 -1
  328. package/dist/types/hooks.d.ts +0 -122
  329. package/dist/types/hooks.d.ts.map +0 -1
  330. package/dist/types/hooks.js +0 -2
  331. package/dist/types/hooks.js.map +0 -1
  332. package/dist/types/index.d.ts +0 -13
  333. package/dist/types/index.d.ts.map +0 -1
  334. package/dist/types/index.js +0 -13
  335. package/dist/types/index.js.map +0 -1
  336. package/dist/types/request.d.ts +0 -42
  337. package/dist/types/request.d.ts.map +0 -1
  338. package/dist/types/request.js +0 -2
  339. package/dist/types/request.js.map +0 -1
  340. package/dist/types/schema-config.d.ts +0 -303
  341. package/dist/types/schema-config.d.ts.map +0 -1
  342. package/dist/types/schema-config.js +0 -2
  343. package/dist/types/schema-config.js.map +0 -1
  344. package/dist/types/schema-core.d.ts +0 -294
  345. package/dist/types/schema-core.d.ts.map +0 -1
  346. package/dist/types/schema-core.js +0 -2
  347. package/dist/types/schema-core.js.map +0 -1
  348. package/dist/types/schema-inference.d.ts +0 -73
  349. package/dist/types/schema-inference.d.ts.map +0 -1
  350. package/dist/types/schema-inference.js +0 -2
  351. package/dist/types/schema-inference.js.map +0 -1
  352. package/dist/types/workflows.d.ts +0 -84
  353. package/dist/types/workflows.d.ts.map +0 -1
  354. package/dist/types/workflows.js +0 -7
  355. package/dist/types/workflows.js.map +0 -1
  356. package/dist/utils/admin-auth.d.ts +0 -5
  357. package/dist/utils/admin-auth.d.ts.map +0 -1
  358. package/dist/utils/admin-auth.js +0 -39
  359. package/dist/utils/admin-auth.js.map +0 -1
  360. package/dist/utils/config.d.ts +0 -8
  361. package/dist/utils/config.d.ts.map +0 -1
  362. package/dist/utils/config.js +0 -238
  363. package/dist/utils/config.js.map +0 -1
  364. package/dist/utils/hooks.d.ts +0 -41
  365. package/dist/utils/hooks.d.ts.map +0 -1
  366. package/dist/utils/hooks.js +0 -173
  367. package/dist/utils/hooks.js.map +0 -1
  368. package/dist/utils/openapi.d.ts +0 -6
  369. package/dist/utils/openapi.d.ts.map +0 -1
  370. package/dist/utils/openapi.js +0 -842
  371. package/dist/utils/openapi.js.map +0 -1
  372. package/dist/utils/parse-sort.d.ts +0 -7
  373. package/dist/utils/parse-sort.d.ts.map +0 -1
  374. package/dist/utils/parse-sort.js +0 -23
  375. package/dist/utils/parse-sort.js.map +0 -1
  376. package/dist/utils/parse-where.d.ts +0 -63
  377. package/dist/utils/parse-where.d.ts.map +0 -1
  378. package/dist/utils/parse-where.js +0 -196
  379. package/dist/utils/parse-where.js.map +0 -1
  380. package/dist/utils/readonly-db.d.ts +0 -9
  381. package/dist/utils/readonly-db.d.ts.map +0 -1
  382. package/dist/utils/readonly-db.js +0 -21
  383. package/dist/utils/readonly-db.js.map +0 -1
  384. package/dist/utils/setup-prompt.d.ts +0 -11
  385. package/dist/utils/setup-prompt.d.ts.map +0 -1
  386. package/dist/utils/setup-prompt.js +0 -863
  387. package/dist/utils/setup-prompt.js.map +0 -1
  388. package/dist/utils/swagger.d.ts +0 -11
  389. package/dist/utils/swagger.d.ts.map +0 -1
  390. package/dist/utils/swagger.js +0 -62
  391. package/dist/utils/swagger.js.map +0 -1
  392. package/dist/utils/upload-validation.d.ts +0 -23
  393. package/dist/utils/upload-validation.d.ts.map +0 -1
  394. package/dist/utils/upload-validation.js +0 -44
  395. package/dist/utils/upload-validation.js.map +0 -1
  396. package/dist/utils/where-sanitizer.d.ts +0 -10
  397. package/dist/utils/where-sanitizer.d.ts.map +0 -1
  398. package/dist/utils/where-sanitizer.js +0 -67
  399. package/dist/utils/where-sanitizer.js.map +0 -1
  400. package/dist/where-sanitizer-7Q4JXMX6.js +0 -57
  401. package/dist/where-sanitizer-DQIWTQZW.js +0 -50
  402. package/dist/workflows.d.ts +0 -54
  403. package/dist/workflows.d.ts.map +0 -1
  404. package/dist/workflows.js +0 -282
  405. package/dist/workflows.js.map +0 -1
@@ -1,1751 +0,0 @@
1
- /**
2
- * Minimum HTTP request context passed to every server-side hook and resolver.
3
- *
4
- * The full Web Standard `Request` is available as `raw` when you need it, but
5
- * most hooks only need `query` (URL search parameters).
6
- */
7
- interface HookRequestContext {
8
- /** Parsed URL query-string parameters, e.g. `{ page: '2', search: 'hello' }`. */
9
- query: Record<string, string>;
10
- /** Incoming HTTP headers, lowercased. */
11
- headers: Record<string, string>;
12
- /** The raw Web Standard `Request` object. Useful for streaming or advanced header inspection. */
13
- raw?: Request;
14
- }
15
- /**
16
- * Base shape of an authenticated user as decoded from the JWT.
17
- *
18
- * The actual shape will include every field on your auth collection — this
19
- * interface only guarantees the properties that Dyrected always stamps on the
20
- * token. Extend it in your own codebase for stronger typing:
21
- *
22
- * @example
23
- * declare module '@dyrected/core' {
24
- * interface AuthenticatedUser {
25
- * role: 'admin' | 'editor'
26
- * organizationId: string
27
- * }
28
- * }
29
- */
30
- interface AuthenticatedUser {
31
- /** The user's document ID in the database. */
32
- sub: string;
33
- /** The user's email address. */
34
- email?: string;
35
- /** Slug of the collection this user was authenticated against. */
36
- collection: string;
37
- /** Array of role strings, if your auth collection has a `roles` field. */
38
- roles?: string[];
39
- /** Any additional fields from the auth collection document. */
40
- [key: string]: unknown;
41
- }
42
- /**
43
- * Every field type supported by Dyrected.
44
- *
45
- * - Text group: `text`, `textarea`, `richText`, `email`, `url`, `icon`
46
- * - Number/Bool: `number`, `boolean`
47
- * - Date: `date`, `datetime`, `time`
48
- * - Selection: `select`, `multiSelect`, `radio`
49
- * - Relationship: `relationship`, `join`
50
- * - Structural: `array`, `object`, `blocks`, `json`
51
- * - Layout: `row`
52
- * - Media: `image`
53
- */
54
- type FieldType = "text" | "textarea" | "richText" | "number" | "boolean" | "date" | "datetime" | "time" | "select" | "multiSelect" | "radio" | "relationship" | "array" | "object" | "json" | "blocks" | "image" | "email" | "url" | "icon" | "join" | "row";
55
- /**
56
- * Arguments passed to a server-side dynamic options resolver.
57
- *
58
- * All properties are optional so simple resolvers that fetch from an external
59
- * API without needing any context (`async () => fetch(...)`) still compile
60
- * without errors.
61
- */
62
- interface DynamicOptionsResolverArgs {
63
- /**
64
- * The configured database adapter. Use it to query any collection.
65
- *
66
- * @example
67
- * options: async ({ db }) => {
68
- * const result = await db.find({ collection: 'categories' })
69
- * return result.docs.map(c => ({ label: c.name, value: c.id }))
70
- * }
71
- */
72
- db?: DatabaseAdapter;
73
- /**
74
- * The authenticated user making the request, or `undefined` for
75
- * unauthenticated requests. Use it to filter options per user.
76
- *
77
- * @example
78
- * options: async ({ user, db }) => {
79
- * if (!user) return []
80
- * const teams = await db.find({ collection: 'teams', where: { owner: { equals: user.sub } } })
81
- * return teams.docs.map(t => ({ label: t.name, value: t.id }))
82
- * }
83
- */
84
- user?: AuthenticatedUser;
85
- /**
86
- * HTTP request context. Sibling field values selected in the Admin UI are
87
- * forwarded as query parameters and accessible via `req.query`.
88
- *
89
- * @example
90
- * // Cascading dropdown: the Admin UI appends ?country=ca
91
- * options: async ({ req }) => {
92
- * const country = req.query.country ?? 'us'
93
- * const regions = await fetch(`/api/regions?country=${country}`)
94
- * return regions.json()
95
- * }
96
- */
97
- req: HookRequestContext;
98
- }
99
- /** A function that returns option items for a `select`, `multiSelect`, or `radio` field. */
100
- type DynamicOptionsResolver = (args: DynamicOptionsResolverArgs) => Promise<DynamicOptionItem[]> | DynamicOptionItem[];
101
- /**
102
- * Config-object form for a dynamic options resolver. Use this when you also
103
- * want server-side caching via `cacheTTL`.
104
- *
105
- * @example
106
- * options: {
107
- * resolve: async () => fetchCountriesFromApi(),
108
- * cacheTTL: 300, // cache for 5 minutes
109
- * }
110
- */
111
- interface DynamicOptionsConfig {
112
- /** The resolver function. Receives the same args as a bare function resolver. */
113
- resolve: DynamicOptionsResolver;
114
- /**
115
- * Time-to-live in **seconds** for caching the resolver result on the server.
116
- *
117
- * Useful for resolvers that call rate-limited external APIs. When set, the
118
- * result is reused for all identical requests within the TTL window.
119
- *
120
- * Not applied when the resolver uses query parameters (`req.query`), since
121
- * parameterised results are request-specific.
122
- */
123
- cacheTTL?: number;
124
- }
125
- /** A single option item — either a plain string or a label/value pair. */
126
- type DynamicOptionItem = string | {
127
- label: string;
128
- value: unknown;
129
- };
130
- /**
131
- * A single block type for use inside a `blocks` field.
132
- *
133
- * Each block has its own field schema. At runtime, every block item in the
134
- * array carries a `blockType` property that matches the block's `slug`.
135
- *
136
- * @example
137
- * const HeroBlock: Block = {
138
- * slug: 'hero',
139
- * labels: { singular: 'Hero', plural: 'Heroes' },
140
- * fields: [
141
- * { name: 'heading', type: 'text', required: true },
142
- * { name: 'image', type: 'relationship', relationTo: 'media' },
143
- * ],
144
- * }
145
- */
146
- interface Block {
147
- /** Unique identifier for this block type. Stored as `blockType` on each item. */
148
- slug: string;
149
- /** Human-readable labels shown in the Admin UI block picker. */
150
- labels?: {
151
- singular: string;
152
- plural: string;
153
- };
154
- /** Fields that make up this block's data shape. */
155
- fields: Field[];
156
- }
157
- /**
158
- * A hook that runs **before a field value is saved** to the database.
159
- *
160
- * Return the transformed value to persist. Return `undefined` to leave the
161
- * value unchanged (same as returning the original `value`).
162
- *
163
- * Field `beforeChange` hooks run recursively inside `array`, `object`, and
164
- * `blocks` fields — every nested item is processed automatically.
165
- *
166
- * @template TValue The TypeScript type of this field's value.
167
- * @template TDoc The document shape of the parent collection/global.
168
- *
169
- * @example
170
- * // Normalise email to lowercase
171
- * const normaliseEmail: FieldBeforeChangeHook<string> = ({ value }) =>
172
- * value?.toLowerCase().trim()
173
- *
174
- * @example
175
- * // Hash a password with bcrypt
176
- * const hashPassword: FieldBeforeChangeHook<string> = async ({ value }) =>
177
- * value ? bcrypt.hash(value, 10) : value
178
- */
179
- type FieldBeforeChangeHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: {
180
- /** The current value of this field (after any previous hooks in the chain). */
181
- value: TValue;
182
- /** The full document as it existed before this update. `undefined` on create. */
183
- originalDoc?: TDoc;
184
- /** The full incoming data payload being written. */
185
- data: Partial<TDoc>;
186
- /** The authenticated user, or `undefined` for unauthenticated requests. */
187
- user?: AuthenticatedUser;
188
- /**
189
- * Database adapter for cross-collection reads. Write operations (create,
190
- * update, delete) will throw — use `afterChange`/`afterDelete` for writes.
191
- */
192
- db: ReadonlyDatabaseAdapter;
193
- }) => TValue | undefined | Promise<TValue | undefined>;
194
- /**
195
- * A hook that runs **after a field value is read** from the database, before
196
- * the response is sent to the client.
197
- *
198
- * Return the transformed value to return to the client. Use this for masking,
199
- * formatting, or adding computed properties.
200
- *
201
- * @template TValue The TypeScript type of this field's value.
202
- * @template TDoc The document shape of the parent collection/global.
203
- *
204
- * @example
205
- * // Mask sensitive value for non-admins
206
- * const maskForPublic: FieldAfterReadHook<string> = ({ value, user }) =>
207
- * user?.role === 'admin' ? value : '••••••••'
208
- */
209
- type FieldAfterReadHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: {
210
- /** The raw field value as stored in the database. */
211
- value: TValue;
212
- /** The full document being returned (with defaults applied). */
213
- doc: TDoc;
214
- /** The authenticated user, or `undefined` for unauthenticated requests. */
215
- user?: AuthenticatedUser;
216
- /**
217
- * Database adapter for cross-collection reads. Write operations (create,
218
- * update, delete) will throw — use `afterChange`/`afterDelete` for writes.
219
- */
220
- db: ReadonlyDatabaseAdapter;
221
- }) => TValue | undefined | Promise<TValue | undefined>;
222
- /**
223
- * @deprecated Use {@link FieldBeforeChangeHook} or {@link FieldAfterReadHook} instead.
224
- * This alias remains for backwards compatibility.
225
- */
226
- type FieldHook<TDoc extends object = Record<string, unknown>, TValue = unknown> = FieldBeforeChangeHook<TValue, TDoc>;
227
- /**
228
- * Runs before Dyrected queries the database for a list or single-document fetch.
229
- *
230
- * Return a new `where` query object to override or extend the current filter.
231
- * Return `undefined` (or nothing) to leave the query unchanged.
232
- *
233
- * @example
234
- * // Scope all reads to the current user's own documents
235
- * const scopeToUser: CollectionBeforeReadHook = ({ user, query }) => ({
236
- * ...query,
237
- * owner: { equals: user?.sub },
238
- * })
239
- */
240
- type CollectionBeforeReadHook = (args: {
241
- /** The HTTP request context. */
242
- req: HookRequestContext;
243
- /** The current `where` query filter. Modify and return to override. */
244
- query?: Record<string, unknown>;
245
- /** The authenticated user, or `undefined` for unauthenticated requests. */
246
- user?: AuthenticatedUser;
247
- /**
248
- * Database adapter for cross-collection reads. Write operations (create,
249
- * update, delete) will throw — use `afterChange`/`afterDelete` for writes.
250
- */
251
- db: ReadonlyDatabaseAdapter;
252
- }) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
253
- /**
254
- * Runs after a document (or list of documents) is fetched from the database,
255
- * before the response is sent to the client.
256
- *
257
- * Return a modified document to send instead. Useful for adding computed
258
- * virtual fields or transforming the shape of the response.
259
- *
260
- * @template TDoc The shape of the collection's document.
261
- *
262
- * @example
263
- * // Add a computed fullName field
264
- * const addFullName: CollectionAfterReadHook<User> = ({ doc }) => ({
265
- * ...doc,
266
- * fullName: `${doc.firstName} ${doc.lastName}`.trim(),
267
- * })
268
- */
269
- type CollectionAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
270
- /** The document as fetched from the database (with defaults applied). */
271
- doc: TDoc;
272
- /** The HTTP request context. */
273
- req: HookRequestContext;
274
- /** The authenticated user, or `undefined` for unauthenticated requests. */
275
- user?: AuthenticatedUser;
276
- /**
277
- * Database adapter for cross-collection reads. Write operations (create,
278
- * update, delete) will throw — use `afterChange`/`afterDelete` for writes.
279
- */
280
- db: ReadonlyDatabaseAdapter;
281
- }) => TDoc | Promise<TDoc>;
282
- /**
283
- * Runs **before** a document is created or updated in the database.
284
- *
285
- * Return a modified data object to write instead of the original. This is the
286
- * right place for data transformation, normalisation, slug generation, and
287
- * validation (throw to abort the write).
288
- *
289
- * @template TDoc The shape of the collection's document.
290
- *
291
- * @example
292
- * // Auto-generate a slug on create
293
- * const generateSlug: CollectionBeforeChangeHook<Post> = ({ data, operation }) => {
294
- * if (operation === 'create' || data.title !== undefined) {
295
- * return { ...data, slug: slugify(data.title ?? '') }
296
- * }
297
- * return data
298
- * }
299
- *
300
- * @example
301
- * // Abort the write with a validation error
302
- * const validateStock: CollectionBeforeChangeHook<Product> = ({ data }) => {
303
- * if ((data.stock ?? 0) < 0) throw new Error('Stock cannot be negative.')
304
- * return data
305
- * }
306
- */
307
- type CollectionBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
308
- /** The incoming data payload being written. */
309
- data: Partial<TDoc>;
310
- /**
311
- * The existing document before this update. Only present on `'update'`
312
- * operations; `undefined` on `'create'`.
313
- */
314
- doc?: TDoc;
315
- /** The HTTP request context. */
316
- req: HookRequestContext;
317
- /** The authenticated user, or `undefined` for unauthenticated requests. */
318
- user?: AuthenticatedUser;
319
- /** Whether this is a new document or an update to an existing one. */
320
- operation: "create" | "update";
321
- /**
322
- * Database adapter for cross-collection reads. Write operations (create,
323
- * update, delete) will throw — use `afterChange`/`afterDelete` for writes.
324
- */
325
- db: ReadonlyDatabaseAdapter;
326
- }) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
327
- /**
328
- * Runs **after** a document is created or updated in the database.
329
- *
330
- * **Isolation**: errors thrown inside this hook are caught by the framework,
331
- * logged to the console, and then discarded. The HTTP response returns the
332
- * saved document as if nothing went wrong — because from the database's
333
- * perspective, nothing did. This means a transient email failure or webhook
334
- * timeout will never turn a successful write into a 500 for the caller.
335
- *
336
- * The return value is ignored — this hook is for side-effects only (emails,
337
- * webhooks, cache revalidation, search index updates, etc.).
338
- *
339
- * **Awaiting vs fire-and-forget**: `await`ing inside this hook is fine for
340
- * fast, reliable calls. For slow or unreliable external services prefer
341
- * fire-and-forget with your own `.catch()` so the response doesn't block:
342
- *
343
- * ```ts
344
- * // ✓ fast & reliable — safe to await
345
- * afterChange: [async ({ doc }) => {
346
- * await revalidatePath(`/posts/${doc.slug}`)
347
- * }]
348
- *
349
- * // ✓ slow or unreliable — fire-and-forget
350
- * afterChange: [({ doc }) => {
351
- * sendEmail({ to: doc.email, ... }).catch(console.error)
352
- * }]
353
- * ```
354
- *
355
- * @template TDoc The shape of the collection's document.
356
- *
357
- * @example
358
- * // Send a webhook after every save
359
- * const sendWebhook: CollectionAfterChangeHook<Post> = async ({ doc, operation }) => {
360
- * await fetch('https://hooks.example.com/content', {
361
- * method: 'POST',
362
- * body: JSON.stringify({ event: operation, doc }),
363
- * })
364
- * }
365
- *
366
- * @example
367
- * // Only act when a specific field changed
368
- * const onStatusChange: CollectionAfterChangeHook<Post> = async ({ doc, previousDoc, operation }) => {
369
- * if (operation === 'update' && doc.status !== previousDoc?.status) {
370
- * await notifySubscribers(doc)
371
- * }
372
- * }
373
- */
374
- type CollectionAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
375
- /** The document as it was written to the database. */
376
- doc: TDoc;
377
- /**
378
- * Snapshot of the document before the write. Only present on `'update'`
379
- * operations; `undefined` on `'create'`.
380
- */
381
- previousDoc?: TDoc;
382
- /** The HTTP request context. */
383
- req: HookRequestContext;
384
- /** The authenticated user, or `undefined` for unauthenticated requests. */
385
- user?: AuthenticatedUser;
386
- /** Whether this was a new document or an update. */
387
- operation: "create" | "update";
388
- /**
389
- * Database adapter with full read/write access. The DB write for this
390
- * operation has already committed — safe for side-effect writes.
391
- */
392
- db: DatabaseAdapter;
393
- }) => void | Promise<void>;
394
- /**
395
- * Runs **before** a document is deleted from the database.
396
- *
397
- * Throw an error to cancel the deletion — the document will not be removed
398
- * and the API will return a `500` with your error message.
399
- *
400
- * @template TDoc The shape of the collection's document.
401
- *
402
- * @example
403
- * // Prevent deletion when other documents reference this one
404
- * const guardReferences: CollectionBeforeDeleteHook<Category> = async ({ id, doc }) => {
405
- * const refs = await db.find({ collection: 'posts', where: { category: { equals: id } } })
406
- * if (refs.total > 0) throw new Error(`${refs.total} post(s) still reference this category.`)
407
- * }
408
- */
409
- type CollectionBeforeDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
410
- /** The ID of the document about to be deleted. */
411
- id: string;
412
- /** The full document about to be deleted. */
413
- doc: TDoc;
414
- /** The HTTP request context. */
415
- req: HookRequestContext;
416
- /** The authenticated user, or `undefined` for unauthenticated requests. */
417
- user?: AuthenticatedUser;
418
- /**
419
- * Database adapter for cross-collection reads. Write operations (create,
420
- * update, delete) will throw — use `afterDelete` for post-deletion writes.
421
- */
422
- db: ReadonlyDatabaseAdapter;
423
- }) => void | Promise<void>;
424
- /**
425
- * Runs **after** a document has been deleted from the database.
426
- *
427
- * **Isolation**: same as {@link CollectionAfterChangeHook} — errors are caught,
428
- * logged, and discarded. The deletion is already committed; a hook failure will
429
- * never cause the deleted ID to appear in the `failed` list of a bulk delete or
430
- * turn a successful single delete into a 500.
431
- *
432
- * Use for cleanup side-effects — removing related media, invalidating caches,
433
- * notifying downstream services, etc.
434
- *
435
- * @template TDoc The shape of the collection's document.
436
- */
437
- type CollectionAfterDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
438
- /** The ID of the deleted document. */
439
- id: string;
440
- /** The document as it was just before deletion. */
441
- doc: TDoc;
442
- /** The HTTP request context. */
443
- req: HookRequestContext;
444
- /** The authenticated user, or `undefined` for unauthenticated requests. */
445
- user?: AuthenticatedUser;
446
- /**
447
- * Database adapter with full read/write access. The deletion has already
448
- * committed — safe for cascade deletes or cleanup writes.
449
- */
450
- db: DatabaseAdapter;
451
- }) => void | Promise<void>;
452
- /** @see {@link CollectionBeforeReadHook} */
453
- type GlobalBeforeReadHook = CollectionBeforeReadHook;
454
- /**
455
- * Runs after the global document is fetched, before the response is sent.
456
- * @see {@link CollectionAfterReadHook}
457
- */
458
- type GlobalAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
459
- doc: TDoc;
460
- req: HookRequestContext;
461
- user?: AuthenticatedUser;
462
- /**
463
- * Database adapter for cross-collection reads. Write operations (create,
464
- * update, delete) will throw — use `afterChange` for writes.
465
- */
466
- db: ReadonlyDatabaseAdapter;
467
- }) => TDoc | Promise<TDoc>;
468
- /**
469
- * Runs before the global document is updated.
470
- * Operation is always `'update'` (globals cannot be created or deleted).
471
- * @see {@link CollectionBeforeChangeHook}
472
- */
473
- type GlobalBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
474
- data: Partial<TDoc>;
475
- doc?: TDoc;
476
- req: HookRequestContext;
477
- user?: AuthenticatedUser;
478
- operation: "update";
479
- /**
480
- * Database adapter for cross-collection reads. Write operations (create,
481
- * update, delete) will throw — use `afterChange` for writes.
482
- */
483
- db: ReadonlyDatabaseAdapter;
484
- }) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
485
- /**
486
- * Runs after the global document is updated. Side-effects only.
487
- *
488
- * **Isolation**: errors are caught, logged, and discarded — same behaviour as
489
- * {@link CollectionAfterChangeHook}. The update is already committed.
490
- *
491
- * @see {@link CollectionAfterChangeHook}
492
- */
493
- type GlobalAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
494
- doc: TDoc;
495
- previousDoc?: TDoc;
496
- req: HookRequestContext;
497
- user?: AuthenticatedUser;
498
- operation: "update";
499
- /**
500
- * Database adapter with full read/write access. The DB write for this
501
- * operation has already committed — safe for side-effect writes.
502
- */
503
- db: DatabaseAdapter;
504
- }) => void | Promise<void>;
505
- /**
506
- * @deprecated Use the specific hook types instead:
507
- * {@link CollectionBeforeChangeHook}, {@link CollectionAfterReadHook}, etc.
508
- *
509
- * This broad type remains for backwards compatibility with the internal hook runner.
510
- */
511
- type HookFunction<TDoc extends object = Record<string, unknown>> = (args: {
512
- data?: Partial<TDoc>;
513
- doc?: TDoc;
514
- user?: AuthenticatedUser;
515
- req?: HookRequestContext;
516
- operation?: "create" | "update" | "delete";
517
- db?: DatabaseAdapter;
518
- [key: string]: unknown;
519
- }) => unknown | Promise<unknown>;
520
- /**
521
- * A function that determines whether the current user can perform an operation.
522
- *
523
- * Return `true` to allow, `false` to deny.
524
- * Return a `where`-style object to allow access only to matching documents
525
- * (useful for multi-tenant setups where users can only see their own data).
526
- *
527
- * Can also be expressed as a Jexl expression **string** for simple role checks
528
- * that need to be serialised (e.g. stored in the database or sent to the Admin UI).
529
- *
530
- * @template TDoc The shape of the collection's document.
531
- *
532
- * @example
533
- * // Simple role check
534
- * access: {
535
- * delete: ({ user }) => user?.roles?.includes('admin') ?? false,
536
- * }
537
- *
538
- * @example
539
- * // Row-level: users can only read their own documents
540
- * access: {
541
- * read: ({ user }) => ({ owner: { equals: user?.sub } }),
542
- * }
543
- *
544
- * @example
545
- * // Jexl string — evaluated server-side
546
- * access: {
547
- * update: "user.roles contains 'editor'",
548
- * }
549
- */
550
- type AccessFunction<TDoc extends object = Record<string, unknown>> = (args: {
551
- user: AuthenticatedUser | undefined;
552
- doc?: TDoc;
553
- data?: Partial<TDoc>;
554
- req: HookRequestContext;
555
- }) => boolean | Record<string, unknown> | Promise<boolean | Record<string, unknown>>;
556
- /**
557
- * Shared base properties present on every field type.
558
- * The exported `Field` union type extends this with a typed `hooks` block.
559
- */
560
- interface FieldBase {
561
- /**
562
- * The database column / JSON key for this field.
563
- * Use camelCase. Omit for layout-only fields (`row`, `join`).
564
- */
565
- name?: string;
566
- /**
567
- * Human-readable label shown next to the field in the Admin UI.
568
- * Defaults to a title-cased version of `name` if omitted.
569
- */
570
- label?: string;
571
- /**
572
- * If `true`, the field must have a non-empty value.
573
- * Enforced on both client (Admin UI) and server (API).
574
- */
575
- required?: boolean;
576
- /**
577
- * If `true`, the database adapter enforces a unique constraint for this
578
- * field across the collection.
579
- */
580
- unique?: boolean;
581
- /**
582
- * The initial value written to new documents when no value is provided.
583
- * The type should match the field type.
584
- */
585
- defaultValue?: unknown;
586
- /**
587
- * Available choices for `select`, `multiSelect`, and `radio` fields.
588
- *
589
- * Three forms are accepted:
590
- *
591
- * **1. Static array** — fixed list known at build time:
592
- * ```ts
593
- * options: [{ label: 'Draft', value: 'draft' }, { label: 'Published', value: 'published' }]
594
- * ```
595
- *
596
- * **2. Server-side resolver** — runs on the server (never in the browser).
597
- * Use for DB queries, secret API keys, or user-filtered lists.
598
- * The Admin UI fetches results from `GET /api/dyrected/options/:slug/:field`.
599
- * ```ts
600
- * options: async ({ db, user }) => {
601
- * const cats = await db.find({ collection: 'categories' })
602
- * return cats.docs.map(c => ({ label: c.name, value: c.id }))
603
- * }
604
- * ```
605
- *
606
- * **3. With caching** (`{ resolve, cacheTTL }`) — same as above but the
607
- * result is cached on the server for `cacheTTL` seconds:
608
- * ```ts
609
- * options: { resolve: async () => fetchFromSlowApi(), cacheTTL: 300 }
610
- * ```
611
- *
612
- * For **instant client-side cascading dropdowns** driven by another field's
613
- * value, use `admin.hooks.options` instead (no network round-trip).
614
- */
615
- options?: string[] | {
616
- label: string;
617
- value: unknown;
618
- }[] | DynamicOptionsResolver | DynamicOptionsConfig;
619
- /** For `relationship` fields — the slug of the collection to link to. */
620
- relationTo?: string;
621
- /**
622
- * For `relationship` and `image` fields — if `true`, stores an array of
623
- * IDs instead of a single ID.
624
- */
625
- hasMany?: boolean;
626
- /** Sub-fields for `array` and `object` field types. */
627
- fields?: Field[];
628
- /** Block type definitions for `blocks` fields. */
629
- blocks?: Block[];
630
- /**
631
- * For `join` fields — the slug of the target collection to show linked
632
- * documents from. Paired with `on`.
633
- */
634
- collection?: string;
635
- /**
636
- * For `join` fields — the name of the `relationship` field on the target
637
- * collection that points back to this collection.
638
- */
639
- on?: string;
640
- /**
641
- * For `join` fields — maximum number of related documents to return.
642
- * Defaults to 10. Set to 0 to return all.
643
- */
644
- limit?: number;
645
- /**
646
- * Field-level read/update access control.
647
- *
648
- * - `read`: if it returns `false`, the field is stripped from API responses.
649
- * - `update`: if it returns `false`, incoming values for this field are silently ignored.
650
- */
651
- access?: {
652
- read?: AccessFunction | string;
653
- update?: AccessFunction | string;
654
- };
655
- /**
656
- * Admin UI options for this field. None of these properties affect the API
657
- * or the database — they are purely presentational.
658
- */
659
- admin?: {
660
- /** Placeholder text shown when the input is empty. */
661
- placeholder?: string;
662
- /** String key referencing a custom React component to render this input field. */
663
- component?: string;
664
- /** Help text rendered below the field in the Admin UI. */
665
- description?: string;
666
- /**
667
- * If `true`, the field is hidden from the Admin form entirely.
668
- * Its value is preserved in the database and still returned by the API.
669
- */
670
- hidden?: boolean;
671
- /**
672
- * If `false`, this field cannot be used in list filters and will be stripped from incoming `where` queries.
673
- * Defaults to `true` for supported field types.
674
- */
675
- filterable?: boolean;
676
- /**
677
- * If `true`, the field is rendered as non-editable in the Admin UI.
678
- * The value is still included in form submissions.
679
- */
680
- readOnly?: boolean;
681
- /**
682
- * A function (or Jexl expression string) evaluated reactively as the
683
- * editor types. Return `true` to show the field, `false` to hide it.
684
- *
685
- * Receives the current form values as `data` and sibling-level values
686
- * as `siblingData`.
687
- *
688
- * @example
689
- * // Only show the discount field when a coupon code is entered
690
- * condition: (data) => !!data.couponCode
691
- */
692
- condition?: ((data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean) | string;
693
- /**
694
- * Presentation style for fields with multiple built-in admin renderers.
695
- * - `select`: use `radio` for 2–5 options, otherwise defaults to `select`
696
- * - `boolean`: use `checkbox` (default) or `switch`
697
- */
698
- layout?: "checkbox" | "switch" | "radio" | "select" | string;
699
- /**
700
- * For `select` fields with `layout: 'radio'` — orientation of the radio buttons.
701
- * @default 'vertical'
702
- */
703
- direction?: "horizontal" | "vertical";
704
- /**
705
- * Assigns this field to a named tab in the Admin form.
706
- * When any field in the collection has a `tab`, the form switches to a
707
- * tabbed layout. Fields without a `tab` are grouped under "General".
708
- */
709
- tab?: string;
710
- /**
711
- * CSS width of this field when it is a child of a `row` field.
712
- * Accepts any CSS length value, e.g. `'50%'`, `'200px'`, `'1fr'`.
713
- */
714
- width?: string;
715
- /**
716
- * Client-side Admin UI hooks for this field.
717
- *
718
- * These run **in the browser** every time any sibling field value changes.
719
- * They are completely separate from the server-side `hooks` property.
720
- *
721
- * `onChange` is typed per-field via the discriminated `Field` union —
722
- * see `FieldAdminHooks<TValue>` below.
723
- */
724
- hooks?: {
725
- /**
726
- * For `select`, `multiSelect`, and `radio` fields only.
727
- *
728
- * Computes the **available choices** for this field based on other
729
- * field values — instant, zero-latency cascading dropdowns.
730
- *
731
- * Runs in the browser every time any sibling field changes. When the
732
- * returned list changes, the field's current value is automatically
733
- * cleared if it is no longer a valid choice.
734
- *
735
- * Use the top-level `options` resolver (server-side) when:
736
- * - Your option list requires a DB query or a secret API key
737
- * - You want server-side caching (`cacheTTL`)
738
- *
739
- * @example
740
- * // Country → State/Province cascading dropdown
741
- * options: ({ siblingData }) => {
742
- * if (siblingData.country === 'us') {
743
- * return [{ label: 'California', value: 'CA' }, { label: 'New York', value: 'NY' }]
744
- * }
745
- * return []
746
- * }
747
- */
748
- options?: (args: {
749
- /** Current values of all fields at the same nesting level. */
750
- siblingData: Record<string, unknown>;
751
- /** Current values of the entire form. */
752
- data: Record<string, unknown>;
753
- }) => Array<string | {
754
- label: string;
755
- value: unknown;
756
- }> | Promise<Array<string | {
757
- label: string;
758
- value: unknown;
759
- }>>;
760
- };
761
- };
762
- /**
763
- * For database migrations: if set, data stored under this key in the database
764
- * will be migrated to the current field `name` on next schema sync.
765
- */
766
- renameTo?: string;
767
- /**
768
- * For SQL adapters: if `true`, this field is extracted to a real column
769
- * instead of being stored inside a JSON blob. Improves query performance
770
- * for frequently-filtered fields.
771
- */
772
- promoted?: boolean;
773
- }
774
- /**
775
- * Typed hooks block for a field whose stored value is `TValue`.
776
- *
777
- * The return type of the callbacks is kept as `unknown` here so that TypeScript
778
- * can narrow the contextual type from the discriminated `Field` union without
779
- * bidirectional inference conflicts. Use the explicit `FieldBeforeChangeHook<T>`
780
- * and `FieldAfterReadHook<T>` types when you need checked return types.
781
- */
782
- type FieldHooks<TValue> = {
783
- /**
784
- * Field-level lifecycle hooks.
785
- *
786
- * - `beforeChange` — transform or validate the value before it is saved.
787
- * `value` is typed to the field's own value type (e.g. `string` for
788
- * `text`, `number` for `number`, `boolean` for `boolean`).
789
- * - `afterRead` — transform the value after it is read, before the API response.
790
- *
791
- * Both hook types run **recursively** inside `array`, `object`, and `blocks` fields.
792
- *
793
- * @example
794
- * hooks: {
795
- * beforeChange: [({ value }) => value.trim()], // value: string ✓
796
- * afterRead: [({ value, user }) => user?.role === 'admin' ? value : '****'],
797
- * }
798
- */
799
- hooks?: {
800
- beforeChange?: Array<(args: {
801
- value: TValue;
802
- originalDoc?: Record<string, unknown>;
803
- data: Record<string, unknown>;
804
- user?: AuthenticatedUser;
805
- }) => unknown>;
806
- afterRead?: Array<(args: {
807
- value: TValue;
808
- doc: Record<string, unknown>;
809
- user?: AuthenticatedUser;
810
- }) => unknown>;
811
- };
812
- };
813
- /**
814
- * Typed client-side admin hook block for a field whose value type is `TValue`.
815
- *
816
- * Intersected into each discriminated `Field` union member so that
817
- * `admin.hooks.onChange` receives a `value` typed to the field's own type.
818
- * The return type is `unknown` for the same reason as `FieldHooks` — to
819
- * prevent bidirectional inference from conflicting with union discrimination.
820
- */
821
- type FieldAdminHooks<TValue> = {
822
- admin?: {
823
- hooks?: {
824
- /**
825
- * Derives or computes this field's **value** from other field values in
826
- * real time — without any network request.
827
- *
828
- * Return a new value to update this field. Return `undefined` to leave
829
- * it unchanged.
830
- *
831
- * Use `setValue` for imperative updates inside async callbacks.
832
- *
833
- * ⚠️ Never return an options array here — use `admin.hooks.options` for that.
834
- *
835
- * @example
836
- * // Auto-generate a URL slug from the title field
837
- * onChange: ({ value, siblingData }) => {
838
- * const base = (siblingData.title ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-');
839
- * return base.includes(value) ? base : value;
840
- * }
841
- */
842
- onChange?: (args: {
843
- /** The current value of this field — typed to match the field's `type`. */
844
- value: TValue;
845
- /** Current values of all fields at the same nesting level. */
846
- siblingData: Record<string, unknown>;
847
- /** Current values of the entire form. */
848
- data: Record<string, unknown>;
849
- /** Imperative setter — use inside async callbacks when you can't return a value. */
850
- setValue: (value: unknown) => void;
851
- }) => unknown;
852
- };
853
- };
854
- };
855
- /**
856
- * Defines a single field on a collection or global.
857
- *
858
- * ## Typed `value` in hook callbacks
859
- *
860
- * Three hook callbacks automatically receive a `value` typed to the field's
861
- * own value type — no manual annotations needed:
862
- *
863
- * | Hook | When it runs |
864
- * |------|-------------|
865
- * | `hooks.beforeChange` | Server — before the value is written to the DB |
866
- * | `hooks.afterRead` | Server — after the value is read, before the API response |
867
- * | `admin.hooks.onChange` | Browser — whenever a sibling field changes in the Admin UI |
868
- *
869
- * Type mapping by `type` property:
870
- * - `text / textarea / email / url / icon / date / select / radio` → `string`
871
- * - `number` → `number`
872
- * - `boolean` → `boolean`
873
- * - `multiSelect` → `string[]`
874
- * - `relationship / image` → `string | string[]`
875
- * - `richText / json` → `Record<string, unknown>`
876
- * - `object / array / blocks` → `unknown`
877
- *
878
- * ```ts
879
- * {
880
- * name: 'slug', type: 'text',
881
- * hooks: {
882
- * beforeChange: [({ value }) => value.toLowerCase()], // value: string ✓
883
- * afterRead: [({ value }) => value.trim()], // value: string ✓
884
- * },
885
- * admin: {
886
- * hooks: {
887
- * onChange: ({ value, siblingData }) => // value: string ✓
888
- * (siblingData.title as string ?? '').toLowerCase().replace(/\s+/g, '-'),
889
- * },
890
- * },
891
- * }
892
- * ```
893
- *
894
- * **Important**: write `type` as a plain string literal — do **not** use `as const`.
895
- * TypeScript's `const` generic inference already preserves literal types, and
896
- * adding `as const` to the discriminant property prevents the contextual type
897
- * from flowing into the hook callbacks.
898
- *
899
- * ```ts
900
- * // ✓ correct
901
- * { name: 'slug', type: 'text', hooks: { beforeChange: [({ value }) => value.toLowerCase()] } }
902
- *
903
- * // ✗ breaks value typing
904
- * { name: 'slug', type: 'text' as const, hooks: { beforeChange: [({ value }) => value.toLowerCase()] } }
905
- * ```
906
- */
907
- type Field = FieldBase & (({
908
- type: 'text' | 'textarea' | 'email' | 'url' | 'icon' | 'date' | 'datetime' | 'select' | 'radio';
909
- } & FieldHooks<string> & FieldAdminHooks<string>) | ({
910
- type: 'number';
911
- } & FieldHooks<number> & FieldAdminHooks<number>) | ({
912
- type: 'boolean';
913
- } & FieldHooks<boolean> & FieldAdminHooks<boolean>) | ({
914
- type: 'multiSelect';
915
- } & FieldHooks<string[]> & FieldAdminHooks<string[]>) | ({
916
- type: 'relationship' | 'image';
917
- } & FieldHooks<string | string[]> & FieldAdminHooks<string | string[]>) | ({
918
- type: 'richText' | 'json';
919
- } & FieldHooks<Record<string, unknown>> & FieldAdminHooks<Record<string, unknown>>) | ({
920
- type: 'object' | 'array' | 'blocks' | 'join' | 'row';
921
- } & FieldHooks<unknown> & FieldAdminHooks<unknown>));
922
- /**
923
- * Defines a Dyrected collection — a named set of documents with a shared schema.
924
- *
925
- * Pass your document's TypeScript type as the generic parameter `TDoc` to get
926
- * fully typed hooks and access functions:
927
- *
928
- * ```ts
929
- * interface Post {
930
- * id: string
931
- * title: string
932
- * slug: string
933
- * status: 'draft' | 'published'
934
- * publishedAt?: string
935
- * }
936
- *
937
- * export const Posts = defineCollection<Post>({
938
- * slug: 'posts',
939
- * hooks: {
940
- * beforeChange: [({ data, operation }) => {
941
- * // `data` is typed as Partial<Post>
942
- * if (operation === 'create') return { ...data, status: 'draft' }
943
- * return data
944
- * }],
945
- * afterChange: [({ doc, previousDoc }) => {
946
- * // `doc` and `previousDoc` are typed as Post
947
- * if (doc.status !== previousDoc?.status) notifySubscribers(doc)
948
- * }],
949
- * },
950
- * fields: [...],
951
- * })
952
- * ```
953
- *
954
- * @template TDoc The TypeScript shape of a document in this collection.
955
- * Defaults to `Record<string, unknown>` for untyped usage.
956
- */
957
- interface CollectionConfig<TDoc extends object = Record<string, unknown>> {
958
- /**
959
- * Unique identifier for this collection.
960
- * Used as the URL segment (`/api/collections/:slug`) and the database table/collection name.
961
- * Use kebab-case, e.g. `'blog-posts'`.
962
- */
963
- slug: string;
964
- /**
965
- * Restricts this collection to a specific site in a multi-tenant deployment.
966
- * When set, only requests bearing a matching `X-Site-Id` header can access it.
967
- */
968
- siteId?: string;
969
- /**
970
- * If `true`, this collection is shared across all sites in a multi-tenant
971
- * deployment and accessible regardless of the `X-Site-Id` header.
972
- */
973
- shared?: boolean;
974
- /** Human-readable names for documents in this collection, shown in the Admin UI. */
975
- labels?: {
976
- singular: string;
977
- plural: string;
978
- };
979
- /**
980
- * If `true`, this collection is an **auth collection** — it gains
981
- * `POST /api/collections/:slug/login` and `POST /api/collections/:slug/logout`
982
- * endpoints, and documents are expected to have a `password` field.
983
- */
984
- auth?: boolean;
985
- /**
986
- * If `true` (or a config object), this collection supports **file uploads**.
987
- * Documents gain file-related fields (`url`, `filename`, `mimeType`, etc.)
988
- * and the create endpoint accepts `multipart/form-data`.
989
- */
990
- upload?: boolean | UploadConfig;
991
- /** Field definitions that make up the document schema for this collection. */
992
- fields: Field[];
993
- /**
994
- * If `true`, Dyrected automatically adds `createdAt` and `updatedAt`
995
- * timestamp fields to every document. Defaults to `true`.
996
- */
997
- timestamps?: boolean;
998
- /**
999
- * Initial documents to seed into this collection the first time it is
1000
- * fetched and found to be empty (e.g. for demo data or defaults).
1001
- */
1002
- initialData?: Partial<TDoc>[];
1003
- /**
1004
- * If `true`, every create, update, and delete operation on this collection
1005
- * is logged to the `__audit` collection with before/after snapshots and the
1006
- * acting user's identity.
1007
- */
1008
- audit?: boolean;
1009
- /**
1010
- * Collection-level access control.
1011
- *
1012
- * Each key is an operation; the value is a function (or Jexl string) that
1013
- * returns `true` to allow or `false` to deny. Returning a `where`-style
1014
- * object grants access only to matching documents.
1015
- *
1016
- * @example
1017
- * access: {
1018
- * read: () => true, // public read
1019
- * create: ({ user }) => !!user, // logged-in users only
1020
- * update: ({ user }) => user?.roles?.includes('editor') ?? false,
1021
- * delete: ({ user }) => user?.roles?.includes('admin') ?? false,
1022
- * }
1023
- */
1024
- access?: {
1025
- read?: AccessFunction<TDoc> | string;
1026
- create?: AccessFunction<TDoc> | string;
1027
- update?: AccessFunction<TDoc> | string;
1028
- delete?: AccessFunction<TDoc> | string;
1029
- };
1030
- /**
1031
- * Collection-level lifecycle hooks.
1032
- *
1033
- * Hooks run in the order they appear in the array. The return value of each
1034
- * hook is passed as the input to the next. Throwing inside any hook aborts
1035
- * the operation and returns a `500` error.
1036
- *
1037
- * See the [Hooks reference](/docs/concepts/hooks) for the full lifecycle diagram.
1038
- */
1039
- hooks?: {
1040
- /**
1041
- * Runs before the database is queried. Return a modified `where` object
1042
- * to override the query filter.
1043
- */
1044
- beforeRead?: CollectionBeforeReadHook[];
1045
- /**
1046
- * Runs after documents are fetched. Return a modified doc to change what
1047
- * the client receives. Runs on every document in a list response.
1048
- */
1049
- afterRead?: CollectionAfterReadHook<TDoc>[];
1050
- /**
1051
- * Runs before create or update. Return modified data to change what is
1052
- * written to the database. Throw to abort the write entirely.
1053
- */
1054
- beforeChange?: CollectionBeforeChangeHook<TDoc>[];
1055
- /**
1056
- * Runs after create or update is committed. For side-effects only —
1057
- * webhooks, cache busting, notifications. Return value is ignored.
1058
- *
1059
- * Errors are **isolated**: caught, logged, and discarded so a failing
1060
- * side-effect never turns a successful write into an HTTP 500.
1061
- * See {@link CollectionAfterChangeHook} for the await-vs-fire-and-forget guidance.
1062
- */
1063
- afterChange?: CollectionAfterChangeHook<TDoc>[];
1064
- /**
1065
- * Runs before a document is deleted. Throw to cancel the deletion.
1066
- */
1067
- beforeDelete?: CollectionBeforeDeleteHook<TDoc>[];
1068
- /**
1069
- * Runs after a document has been deleted. For cleanup side-effects only.
1070
- *
1071
- * Errors are **isolated**: caught, logged, and discarded — the deletion is
1072
- * already committed and will not be undone.
1073
- */
1074
- afterDelete?: CollectionAfterDeleteHook<TDoc>[];
1075
- };
1076
- /** Admin UI configuration for this collection. */
1077
- admin?: {
1078
- /**
1079
- * The field name used as the document's display title in the Admin list
1080
- * view and breadcrumbs. Defaults to `'title'` if the field exists.
1081
- */
1082
- useAsTitle?: string;
1083
- /**
1084
- * Field names to show as columns in the Admin list view.
1085
- * Defaults to a sensible set of the first few non-structural fields.
1086
- */
1087
- defaultColumns?: string[];
1088
- /**
1089
- * Groups this collection under a named section in the Admin sidebar.
1090
- * Collections with the same `group` are visually grouped together.
1091
- */
1092
- group?: string;
1093
- /** If `true`, this collection is not shown in the Admin UI sidebar. */
1094
- hidden?: boolean;
1095
- /** If `false`, disables the filter UI entirely for this collection. Defaults to `true`. */
1096
- filterable?: boolean;
1097
- /**
1098
- * URL to open in the Live Preview pane when editing a document.
1099
- * Pass a function to derive the URL from the document's fields.
1100
- *
1101
- * @example
1102
- * previewUrl: (doc) => `https://mysite.com/blog/${doc.slug}`
1103
- */
1104
- previewUrl?: string | ((doc: TDoc, opts: {
1105
- locale?: string;
1106
- }) => string | null);
1107
- /**
1108
- * How the Live Preview pane communicates with the frontend.
1109
- * - `'postMessage'` (default) — sends a `postMessage` with the current doc data.
1110
- * - `'token'` — passes a short-lived preview token as a query parameter.
1111
- */
1112
- previewMode?: "postMessage" | "token";
1113
- /**
1114
- * Frontend URL pattern for this collection, used by `url` fields to
1115
- * resolve internal links. Use `{fieldName}` placeholders.
1116
- *
1117
- * @example
1118
- * urlPattern: '/blog/{slug}' // → /blog/my-post
1119
- * urlPattern: '/{slug}' // → /about
1120
- */
1121
- urlPattern?: string;
1122
- };
1123
- }
1124
- /**
1125
- * Upload configuration for collections that store files.
1126
- * Set `upload: true` on the collection to use all defaults, or pass this
1127
- * object to customise allowed types, size limits, and image processing.
1128
- */
1129
- interface UploadConfig {
1130
- /**
1131
- * Allowed MIME types. Requests with other MIME types are rejected with `400`.
1132
- * @example ['image/jpeg', 'image/png', 'image/webp', 'application/pdf']
1133
- */
1134
- allowedMimeTypes?: string[];
1135
- /**
1136
- * Maximum file size in **bytes**.
1137
- * @example 10 * 1024 * 1024 // 10 MB
1138
- */
1139
- maxFileSize?: number;
1140
- /**
1141
- * Local filesystem path where files are stored.
1142
- * Only used by the `LocalStorage` adapter.
1143
- */
1144
- staticDir?: string;
1145
- /**
1146
- * Public URL prefix prepended to filenames when generating download URLs.
1147
- * Only used by the `LocalStorage` adapter.
1148
- * @example '/uploads'
1149
- */
1150
- staticURL?: string;
1151
- /**
1152
- * The `imageSizes` entry name to use as the thumbnail in the Admin media grid.
1153
- * @example 'thumbnail'
1154
- */
1155
- adminThumbnail?: string;
1156
- /**
1157
- * Additional image sizes to generate when an image is uploaded.
1158
- * Requires an `ImageService` to be configured (e.g. `@dyrected/image-sharp`).
1159
- *
1160
- * @example
1161
- * imageSizes: [
1162
- * { name: 'thumbnail', width: 300, height: 300, fit: 'cover' },
1163
- * { name: 'card', width: 800 },
1164
- * ]
1165
- */
1166
- imageSizes?: {
1167
- /** Identifier used to access this size, e.g. `doc.sizes.thumbnail`. */
1168
- name: string;
1169
- /** Target width in pixels. */
1170
- width?: number;
1171
- /** Target height in pixels. */
1172
- height?: number;
1173
- /** sharp crop strategy (`'entropy'`, `'attention'`, etc.). */
1174
- crop?: string;
1175
- /**
1176
- * sharp fit strategy.
1177
- * @see https://sharp.pixelplumbing.com/api-resize#parameters
1178
- */
1179
- fit?: string;
1180
- /**
1181
- * If `true`, images smaller than the target size are not upscaled.
1182
- * @default true
1183
- */
1184
- withoutEnlargement?: boolean;
1185
- /** Additional sharp format options forwarded to the output pipeline. */
1186
- formatOptions?: Record<string, unknown>;
1187
- }[];
1188
- }
1189
- /**
1190
- * Defines a Dyrected global — a singleton document without pagination or IDs.
1191
- *
1192
- * Globals are ideal for site-wide settings, feature flags, or any data where
1193
- * there is always exactly one record (e.g. `site-settings`, `navigation`, `theme`).
1194
- *
1195
- * Pass your document's TypeScript type as the generic parameter `TDoc` to get
1196
- * fully typed hooks:
1197
- *
1198
- * ```ts
1199
- * interface SiteSettings {
1200
- * siteName: string
1201
- * tagline: string
1202
- * maintenanceMode: boolean
1203
- * }
1204
- *
1205
- * export const Settings = defineGlobal<SiteSettings>({
1206
- * slug: 'site-settings',
1207
- * hooks: {
1208
- * afterChange: [({ doc }) => {
1209
- * // `doc` is typed as SiteSettings
1210
- * if (doc.maintenanceMode) alertOnCall()
1211
- * }],
1212
- * },
1213
- * fields: [...],
1214
- * })
1215
- * ```
1216
- *
1217
- * @template TDoc The TypeScript shape of this global's document.
1218
- */
1219
- interface GlobalConfig<TDoc extends object = Record<string, unknown>> {
1220
- /**
1221
- * Unique identifier for this global.
1222
- * Used as the URL segment (`/api/globals/:slug`) and the storage key.
1223
- */
1224
- slug: string;
1225
- /** Restricts this global to a specific site in a multi-tenant deployment. */
1226
- siteId?: string;
1227
- /**
1228
- * If `true`, this global is shared across all sites in a multi-tenant
1229
- * deployment.
1230
- */
1231
- shared?: boolean;
1232
- /** Human-readable label shown in the Admin UI sidebar. */
1233
- label?: string;
1234
- /** Field definitions for this global's document schema. */
1235
- fields: Field[];
1236
- /** Access control for reading and updating this global. */
1237
- access?: {
1238
- read?: AccessFunction<TDoc>;
1239
- update?: AccessFunction<TDoc>;
1240
- };
1241
- /**
1242
- * Global-level lifecycle hooks.
1243
- * Globals support `beforeRead`, `afterRead`, `beforeChange`, and `afterChange`.
1244
- * There are no delete hooks since globals cannot be deleted.
1245
- */
1246
- hooks?: {
1247
- beforeRead?: GlobalBeforeReadHook[];
1248
- afterRead?: GlobalAfterReadHook<TDoc>[];
1249
- beforeChange?: GlobalBeforeChangeHook<TDoc>[];
1250
- afterChange?: GlobalAfterChangeHook<TDoc>[];
1251
- };
1252
- /** Admin UI configuration for this global. */
1253
- admin?: {
1254
- /** Groups this global under a named section in the Admin sidebar. */
1255
- group?: string;
1256
- /** If `true`, this global is not shown in the Admin UI sidebar. */
1257
- hidden?: boolean;
1258
- };
1259
- /**
1260
- * Initial data to seed this global with the first time it is fetched and
1261
- * found to be empty.
1262
- */
1263
- initialData?: Partial<TDoc>;
1264
- }
1265
- /**
1266
- * The minimum shape of every document returned by the database layer.
1267
- *
1268
- * All documents have an `id` field assigned by the adapter. Additional fields
1269
- * are stored as `unknown` until you narrow them with your own interface.
1270
- *
1271
- * Use this as the base when declaring your collection document types:
1272
- * ```ts
1273
- * interface Post extends BaseDocument {
1274
- * title: string
1275
- * slug: string
1276
- * }
1277
- * ```
1278
- */
1279
- interface BaseDocument {
1280
- /** The document's unique identifier, assigned by the database adapter. */
1281
- id: string;
1282
- [key: string]: any;
1283
- }
1284
- /**
1285
- * The envelope returned by collection list endpoints (`GET /api/collections/:slug`).
1286
- *
1287
- * @template T The document type.
1288
- */
1289
- interface PaginatedResult<T = Record<string, any>> {
1290
- /** The documents on the current page. */
1291
- docs: T[];
1292
- /** Total number of documents matching the query (across all pages). */
1293
- total: number;
1294
- /** Maximum number of documents per page as requested. */
1295
- limit: number;
1296
- /** The current page number (1-indexed). */
1297
- page: number;
1298
- /** Total number of pages given the current `limit`. */
1299
- totalPages: number;
1300
- /** Whether a next page exists. */
1301
- hasNextPage: boolean;
1302
- /** Whether a previous page exists. */
1303
- hasPrevPage: boolean;
1304
- }
1305
- /**
1306
- * The interface every database adapter must implement.
1307
- *
1308
- * Dyrected ships adapters for PostgreSQL, MySQL, SQLite, and MongoDB.
1309
- * Implement this interface to connect any other database.
1310
- */
1311
- interface DatabaseAdapter {
1312
- /** Find a paginated list of documents in a collection. */
1313
- find(args: {
1314
- collection: string;
1315
- where?: Record<string, unknown>;
1316
- limit?: number;
1317
- page?: number;
1318
- sort?: string;
1319
- }): Promise<PaginatedResult>;
1320
- /** Find a single document by its ID. Returns `null` if not found. */
1321
- findOne(args: {
1322
- collection: string;
1323
- id: string;
1324
- }): Promise<BaseDocument | null>;
1325
- /** Insert a new document and return it with its generated `id`. */
1326
- create(args: {
1327
- collection: string;
1328
- data: Record<string, unknown>;
1329
- }): Promise<BaseDocument>;
1330
- /** Update a document by ID and return the updated document. */
1331
- update(args: {
1332
- collection: string;
1333
- id: string;
1334
- data: Record<string, unknown>;
1335
- }): Promise<BaseDocument>;
1336
- /** Delete a document by ID. Return value is intentionally untyped — callers do not use it. */
1337
- delete(args: {
1338
- collection: string;
1339
- id: string;
1340
- }): Promise<unknown>;
1341
- /** Fetch the singleton document for a global. Returns `null` if not yet initialised. */
1342
- getGlobal(args: {
1343
- slug: string;
1344
- }): Promise<Record<string, unknown> | null>;
1345
- /** Create or replace the singleton document for a global. */
1346
- updateGlobal(args: {
1347
- slug: string;
1348
- data: Record<string, unknown>;
1349
- }): Promise<Record<string, unknown>>;
1350
- /**
1351
- * Sync the database schema with the current collection and global configs.
1352
- * Called on startup to create tables/collections that don't exist yet.
1353
- * Not all adapters implement this (e.g. MongoDB is schema-less).
1354
- */
1355
- sync?(collections: CollectionConfig[], globals: GlobalConfig[]): Promise<void>;
1356
- /**
1357
- * Execute a raw SQL query or database command.
1358
- * Optional — not all adapters support raw access.
1359
- */
1360
- execute?(query: string, params?: unknown[]): Promise<unknown>;
1361
- }
1362
- /**
1363
- * Read-only view of the database adapter. Exposes only `find`, `findOne`,
1364
- * and `getGlobal` — no write operations.
1365
- *
1366
- * Passed to `beforeChange`, `beforeDelete`, `beforeRead`, `afterRead`,
1367
- * and field-level hooks. Write operations are available in `afterChange`
1368
- * and `afterDelete` hooks where the full {@link DatabaseAdapter} is provided.
1369
- */
1370
- type ReadonlyDatabaseAdapter = Pick<DatabaseAdapter, 'find' | 'findOne' | 'getGlobal'>;
1371
- /**
1372
- * Metadata returned after a file is uploaded and stored.
1373
- * Stored on the document in upload collections.
1374
- */
1375
- interface FileData {
1376
- filename: string;
1377
- filesize?: number;
1378
- mimeType: string;
1379
- /** Public URL of the stored file. */
1380
- url: string;
1381
- width?: number;
1382
- height?: number;
1383
- focalPoint?: {
1384
- x: number;
1385
- y: number;
1386
- };
1387
- /** Base64-encoded BlurHash string for progressive image loading. */
1388
- blurhash?: string;
1389
- /** `'upload'` for server-stored files; `'external'` for provider-managed files. */
1390
- type?: "upload" | "external";
1391
- provider?: string;
1392
- provider_metadata?: unknown;
1393
- [key: string]: unknown;
1394
- }
1395
- /**
1396
- * The interface every storage adapter must implement.
1397
- *
1398
- * Dyrected ships adapters for local disk, S3, Cloudflare R2, Cloudinary, and
1399
- * Backblaze B2. Implement this interface to use any other storage provider.
1400
- */
1401
- interface StorageAdapter {
1402
- /**
1403
- * Upload a file and return its metadata (URL, dimensions, etc.).
1404
- * The `prefix` is a path prefix used for multi-tenant setups.
1405
- */
1406
- upload(args: {
1407
- filename: string;
1408
- buffer: Uint8Array;
1409
- mimeType: string;
1410
- prefix?: string;
1411
- }): Promise<FileData>;
1412
- /** Delete a file by its stored filename. */
1413
- delete(args: {
1414
- filename: string;
1415
- }): Promise<void>;
1416
- /** Return the public URL for a stored file. */
1417
- getURL(args: {
1418
- filename: string;
1419
- }): string;
1420
- /**
1421
- * Retrieve the file's raw bytes and MIME type for serving via the API.
1422
- * Only needed by adapters that serve files through the Dyrected API
1423
- * (e.g. `LocalStorage`). Cloud adapters return `null` here and rely on
1424
- * direct CDN URLs instead.
1425
- */
1426
- resolve?(args: {
1427
- filename: string;
1428
- }): Promise<{
1429
- buffer: Uint8Array;
1430
- mimeType: string;
1431
- } | null>;
1432
- }
1433
- /**
1434
- * Processes uploaded images — generates metadata (dimensions, BlurHash) and
1435
- * produces resized variants defined in `UploadConfig.imageSizes`.
1436
- *
1437
- * @example
1438
- * import { SharpImageService } from '@dyrected/image-sharp'
1439
- * defineConfig({ image: new SharpImageService(), ... })
1440
- */
1441
- interface ImageService {
1442
- process(args: {
1443
- buffer: Uint8Array;
1444
- mimeType: string;
1445
- config?: CollectionConfig["upload"];
1446
- focalPoint?: {
1447
- x: number;
1448
- y: number;
1449
- };
1450
- }): Promise<{
1451
- metadata: {
1452
- width?: number;
1453
- height?: number;
1454
- /** Base64-encoded BlurHash for progressive loading. */
1455
- blurhash?: string;
1456
- };
1457
- /** Generated image sizes keyed by their `name`. */
1458
- sizes?: Record<string, {
1459
- buffer: Uint8Array;
1460
- width: number;
1461
- height: number;
1462
- filename: string;
1463
- }>;
1464
- }>;
1465
- }
1466
- /**
1467
- * Branding and metadata options for the Dyrected Admin UI.
1468
- *
1469
- * @example
1470
- * admin: {
1471
- * branding: {
1472
- * logo: '/logo.svg',
1473
- * primaryColor: '#6366f1',
1474
- * },
1475
- * meta: {
1476
- * titleSuffix: '- My App',
1477
- * },
1478
- * }
1479
- */
1480
- interface AdminConfig {
1481
- branding?: {
1482
- /** Full logo image shown in the expanded sidebar. URL or imported image asset. */
1483
- logo?: string;
1484
- /** Compact logo mark used in the collapsed sidebar state. */
1485
- logoMark?: string;
1486
- /** Text alternative or addition to the logo image. */
1487
- logoText?: string;
1488
- /**
1489
- * Primary accent colour as any CSS colour value.
1490
- * @example '#6366f1'
1491
- * @example 'hsl(240 50% 60%)'
1492
- */
1493
- primaryColor?: string;
1494
- /** Browser tab favicon URL. */
1495
- favicon?: string;
1496
- /** Font family for body and UI text. Must be loaded separately. */
1497
- fontSans?: string;
1498
- /** Font family for headings. Must be loaded separately. */
1499
- fontSerif?: string;
1500
- };
1501
- meta?: {
1502
- /**
1503
- * String appended to every Admin page's `<title>`.
1504
- * @default '- Dyrected'
1505
- */
1506
- titleSuffix?: string;
1507
- };
1508
- }
1509
- /**
1510
- * Collapses intersection types into a flat object type for readable IDE tooltips.
1511
- *
1512
- * @example
1513
- * type T = Prettify<{ a: string } & { b: number }>
1514
- * // → { a: string; b: number }
1515
- */
1516
- type Prettify<T> = {
1517
- [K in keyof T]: T[K];
1518
- };
1519
- /** Maps a field's runtime type tag to its TypeScript value type. @internal */
1520
- type FieldValueType<F extends Field> = F['type'] extends 'text' | 'textarea' | 'email' | 'url' | 'icon' | 'date' | 'select' | 'radio' ? string : F['type'] extends 'number' ? number : F['type'] extends 'boolean' ? boolean : F['type'] extends 'multiSelect' ? string[] : F['type'] extends 'relationship' ? F extends {
1521
- hasMany: true;
1522
- } ? string[] : string : F['type'] extends 'image' ? string : F['type'] extends 'richText' | 'json' ? Record<string, unknown> : F['type'] extends 'object' ? F extends {
1523
- fields: infer SF extends readonly Field[];
1524
- } ? Prettify<InferDocShape<SF>> : Record<string, unknown> : F['type'] extends 'array' ? F extends {
1525
- fields: infer SF extends readonly Field[];
1526
- } ? Array<Prettify<InferDocShape<SF>>> : unknown[] : F['type'] extends 'blocks' ? F extends {
1527
- blocks: infer B extends readonly Block[];
1528
- } ? Array<InferBlocksUnion<B>> : Array<{
1529
- blockType: string;
1530
- } & Record<string, unknown>> : unknown;
1531
- /** Build a discriminated-union type covering all possible block shapes. @internal */
1532
- type InferBlocksUnion<Blocks extends readonly Block[]> = Blocks extends readonly [infer B extends Block, ...infer Rest extends readonly Block[]] ? B['fields'] extends readonly Field[] ? ({
1533
- blockType: B['slug'];
1534
- } & Prettify<InferDocShape<B['fields']>>) | InferBlocksUnion<Rest> : ({
1535
- blockType: B['slug'];
1536
- } & Record<string, unknown>) | InferBlocksUnion<Rest> : never;
1537
- /** Converts one field definition to its corresponding document key/value pair. @internal */
1538
- type InferFieldEntry<F extends Field> = F extends {
1539
- type: 'row';
1540
- fields: infer SF extends readonly Field[];
1541
- } ? InferDocShape<SF> : F extends {
1542
- type: 'join';
1543
- } ? Record<never, never> : F extends {
1544
- name: infer N extends string;
1545
- required: true;
1546
- } ? {
1547
- [K in N]: FieldValueType<F>;
1548
- } : F extends {
1549
- name: infer N extends string;
1550
- } ? {
1551
- [K in N]?: FieldValueType<F>;
1552
- } : Record<never, never>;
1553
- /**
1554
- * Infer a document shape from a literal fields tuple.
1555
- *
1556
- * This is used automatically by {@link defineCollection} and {@link defineGlobal}
1557
- * when no explicit `TDoc` type argument is provided — TypeScript derives the
1558
- * document type straight from the `fields` array you write inline.
1559
- *
1560
- * For collections, the inferred type is wrapped with `{ id: string }` (the
1561
- * database adapter always stamps an `id` on created documents). Globals don't
1562
- * get an `id`.
1563
- *
1564
- * @example
1565
- * const fields = [
1566
- * { name: 'title', type: 'text', required: true },
1567
- * { name: 'published', type: 'boolean' },
1568
- * ] as const satisfies Field[];
1569
- *
1570
- * type Doc = InferDocShape<typeof fields>;
1571
- * // → { title: string; published?: boolean }
1572
- */
1573
- type InferDocShape<Fields extends readonly Field[]> = Fields extends readonly [] ? Record<never, never> : Fields extends readonly [infer Head extends Field, ...infer Tail extends readonly Field[]] ? InferFieldEntry<Head> & InferDocShape<Tail> : Record<string, unknown>;
1574
- /**
1575
- * Audit fields automatically injected into every collection document at runtime.
1576
- * They are always present in API responses but hidden in the Admin UI by default.
1577
- */
1578
- type SystemDocFields = {
1579
- createdAt?: string;
1580
- updatedAt?: string;
1581
- /** ID of the user who created the document. */
1582
- createdBy?: string;
1583
- /** ID of the user who last updated the document. */
1584
- updatedBy?: string;
1585
- };
1586
- /**
1587
- * Fields automatically injected into collections with `auth: true`.
1588
- * `password` is part of the schema but is stripped from API read responses.
1589
- */
1590
- type AuthDocFields = {
1591
- email: string;
1592
- password?: string;
1593
- roles?: string;
1594
- };
1595
- /**
1596
- * Fields automatically added to upload/media collection documents.
1597
- * These mirror the `FileData` interface returned by storage adapters.
1598
- */
1599
- type UploadDocFields = {
1600
- filename: string;
1601
- filesize?: number;
1602
- mimeType: string;
1603
- /** Public URL of the stored file. */
1604
- url: string;
1605
- width?: number;
1606
- height?: number;
1607
- focalPoint?: {
1608
- x: number;
1609
- y: number;
1610
- };
1611
- /** Base64 BlurHash for progressive image loading. */
1612
- blurhash?: string;
1613
- sizes?: Record<string, {
1614
- filename?: string;
1615
- url?: string;
1616
- width?: number;
1617
- height?: number;
1618
- }>;
1619
- };
1620
- /**
1621
- * The root configuration object passed to `createDyrectedApp`.
1622
- *
1623
- * This is the single source of truth for your entire Dyrected instance —
1624
- * collections, globals, database adapter, storage, email, and more.
1625
- *
1626
- * @example
1627
- * import { defineConfig } from '@dyrected/core'
1628
- * import { SQLiteAdapter } from '@dyrected/db-sqlite'
1629
- *
1630
- * export default defineConfig({
1631
- * db: new SQLiteAdapter({ filename: './db.sqlite' }),
1632
- * collections: [Posts, Users],
1633
- * globals: [SiteSettings],
1634
- * })
1635
- */
1636
- interface DyrectedConfig {
1637
- /** Collection definitions. Each collection maps to a database table/collection. */
1638
- collections: CollectionConfig<any>[];
1639
- /** Global (singleton) definitions. Each global maps to a single document. */
1640
- globals: GlobalConfig<any>[];
1641
- /**
1642
- * The database adapter. Required for all data operations.
1643
- * @see {@link DatabaseAdapter}
1644
- */
1645
- db?: DatabaseAdapter;
1646
- /**
1647
- * The storage adapter for file uploads.
1648
- * Required when any collection has `upload: true`.
1649
- * @see {@link StorageAdapter}
1650
- */
1651
- storage?: StorageAdapter;
1652
- /**
1653
- * The image processing service. Required when any upload collection
1654
- * defines `imageSizes`.
1655
- * @see {@link ImageService}
1656
- */
1657
- image?: ImageService;
1658
- /** Admin UI branding and metadata. */
1659
- admin?: AdminConfig;
1660
- /**
1661
- * Email transport configuration. Required for welcome emails, password
1662
- * resets, and invite links.
1663
- *
1664
- * @example
1665
- * email: {
1666
- * from: 'no-reply@myapp.com',
1667
- * send: async ({ to, subject, html }) => {
1668
- * await resend.emails.send({ from, to, subject, html })
1669
- * },
1670
- * }
1671
- */
1672
- email?: {
1673
- /** The `From` address for all outbound emails. */
1674
- from: string;
1675
- /** The send function. Wire in any email provider (Resend, SendGrid, SES, etc.). */
1676
- send: (args: {
1677
- to: string;
1678
- subject: string;
1679
- html: string;
1680
- }) => Promise<void>;
1681
- /** Override the default email templates. */
1682
- templates?: {
1683
- welcome?: (args: {
1684
- email: string;
1685
- }) => {
1686
- subject?: string;
1687
- html: string;
1688
- };
1689
- invite?: (args: {
1690
- token: string;
1691
- invitedByEmail?: string;
1692
- }) => {
1693
- subject?: string;
1694
- html: string;
1695
- };
1696
- resetPassword?: (args: {
1697
- token: string;
1698
- url?: string;
1699
- }) => {
1700
- subject?: string;
1701
- html: string;
1702
- };
1703
- passwordChanged?: (args: {
1704
- email: string;
1705
- }) => {
1706
- subject?: string;
1707
- html: string;
1708
- };
1709
- };
1710
- };
1711
- /**
1712
- * Redis connection URL. Required for distributed caching of dynamic option
1713
- * resolvers and other server-side caches in multi-instance deployments.
1714
- *
1715
- * @example
1716
- * redis: { url: process.env.REDIS_URL }
1717
- */
1718
- redis?: {
1719
- url: string;
1720
- };
1721
- /**
1722
- * Cross-Origin Resource Sharing (CORS) configuration.
1723
- * List all origins that are allowed to call the Dyrected API.
1724
- *
1725
- * @example
1726
- * cors: { origins: ['https://myapp.com', 'https://www.myapp.com'] }
1727
- */
1728
- cors?: {
1729
- origins: string[];
1730
- };
1731
- /**
1732
- * Callback to dynamically fetch additional collections and globals for a
1733
- * given site ID at request time. Used in multi-tenant deployments where each
1734
- * site has its own schema stored in the database.
1735
- *
1736
- * @param siteId The `X-Site-Id` header value from the incoming request.
1737
- * @returns Extra collections and globals to merge into the config for this request.
1738
- *
1739
- * @example
1740
- * onSchemaFetch: async (siteId) => {
1741
- * const site = await db.findOne({ collection: 'sites', id: siteId })
1742
- * return buildSchemaFromSiteConfig(site)
1743
- * }
1744
- */
1745
- onSchemaFetch?: (siteId: string) => Promise<{
1746
- collections?: CollectionConfig<any>[];
1747
- globals?: GlobalConfig<any>[];
1748
- }>;
1749
- }
1750
-
1751
- export type { AuthDocFields as A, BaseDocument as B, CollectionConfig as C, DyrectedConfig as D, PaginatedResult as E, Field as F, GlobalConfig as G, HookFunction as H, InferDocShape as I, StorageAdapter as J, UploadConfig as K, Prettify as P, ReadonlyDatabaseAdapter as R, SystemDocFields as S, UploadDocFields as U, AccessFunction as a, AdminConfig as b, AuthenticatedUser as c, Block as d, CollectionAfterChangeHook as e, CollectionAfterDeleteHook as f, CollectionAfterReadHook as g, CollectionBeforeChangeHook as h, CollectionBeforeDeleteHook as i, CollectionBeforeReadHook as j, DatabaseAdapter as k, DynamicOptionItem as l, DynamicOptionsConfig as m, DynamicOptionsResolver as n, DynamicOptionsResolverArgs as o, FieldAfterReadHook as p, FieldBeforeChangeHook as q, FieldHook as r, FieldType as s, FileData as t, GlobalAfterChangeHook as u, GlobalAfterReadHook as v, GlobalBeforeChangeHook as w, GlobalBeforeReadHook as x, HookRequestContext as y, ImageService as z };