@kyro-cms/core 0.10.4 → 0.10.6

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 (301) hide show
  1. package/dist/api-handler-graphql.cjs +1 -49
  2. package/dist/api-handler-graphql.js +1 -46
  3. package/dist/api-handler-trpc.cjs +1 -38
  4. package/dist/api-handler-trpc.js +1 -36
  5. package/dist/api-handler.cjs +1 -44
  6. package/dist/api-handler.js +1 -27
  7. package/dist/bootstrap-HIAV5ZFT.cjs +1 -0
  8. package/dist/bootstrap-P7QPQYQP.js +1 -0
  9. package/dist/chunk-2BTRHVT3.cjs +20 -0
  10. package/dist/chunk-2W4FK6CJ.js +122 -0
  11. package/dist/chunk-4ORJMSJU.cjs +1 -0
  12. package/dist/chunk-65G73T7Z.cjs +2 -0
  13. package/dist/chunk-7N6NKCRT.js +1 -0
  14. package/dist/chunk-7WOX27LK.js +259 -0
  15. package/dist/chunk-AE6GXUT7.js +1 -0
  16. package/dist/chunk-AJAZ7D3W.cjs +259 -0
  17. package/dist/chunk-ATLSIYRH.cjs +1 -0
  18. package/dist/chunk-AU6IWTBO.js +2 -0
  19. package/dist/chunk-CDL7ARXT.js +133 -0
  20. package/dist/chunk-CUTFS6N2.cjs +1 -0
  21. package/dist/chunk-CVVW4LXZ.cjs +1 -0
  22. package/dist/chunk-DGJUBN33.js +1 -0
  23. package/dist/chunk-DV4LFLPL.cjs +1 -0
  24. package/dist/chunk-EEWCANFX.js +1 -0
  25. package/dist/chunk-ELICKLFM.cjs +3 -0
  26. package/dist/chunk-EQUQJBPP.cjs +2 -0
  27. package/dist/chunk-ET6NN2V2.cjs +122 -0
  28. package/dist/chunk-F7P36SLX.cjs +74 -0
  29. package/dist/chunk-F7SR5IDT.cjs +1 -0
  30. package/dist/chunk-FO3HLBC7.js +1 -0
  31. package/dist/chunk-FS7GL2BR.js +73 -0
  32. package/dist/chunk-G6A7OSIG.js +2 -0
  33. package/dist/chunk-GFU7AOI3.cjs +1 -0
  34. package/dist/chunk-GYQMNXXW.cjs +114 -0
  35. package/dist/chunk-HLSB2MCK.js +1 -0
  36. package/dist/chunk-HVXO3OFB.cjs +1 -0
  37. package/dist/chunk-IFJJ44OQ.cjs +133 -0
  38. package/dist/chunk-ISWMETHJ.cjs +1 -0
  39. package/dist/chunk-K6WUOU6P.js +1 -0
  40. package/dist/chunk-KDNYHLD2.js +1 -0
  41. package/dist/chunk-KIW36TG7.cjs +86 -0
  42. package/dist/chunk-L6CZYN3L.cjs +20 -0
  43. package/dist/chunk-LRGAPGG3.js +74 -0
  44. package/dist/chunk-LZ6YFYQM.js +20 -0
  45. package/dist/chunk-MIOMMB23.cjs +1 -0
  46. package/dist/chunk-NGBJKZMT.js +90 -0
  47. package/dist/chunk-NRLIGDYF.js +1 -0
  48. package/dist/chunk-NY47CFVP.cjs +1 -0
  49. package/dist/chunk-NZ35PV5R.js +2 -0
  50. package/dist/chunk-OG7CNQGU.js +1 -0
  51. package/dist/chunk-OQD3WG6Z.cjs +1 -0
  52. package/dist/chunk-P7CESLDJ.js +1 -0
  53. package/dist/chunk-PP5S2UBV.js +0 -0
  54. package/dist/chunk-Q3Q7BJVQ.cjs +1 -0
  55. package/dist/chunk-Q4CSLXCO.cjs +90 -0
  56. package/dist/chunk-QRXDCV6K.js +0 -0
  57. package/dist/chunk-R7DVVXXI.cjs +73 -0
  58. package/dist/chunk-RHCWCG3O.js +114 -0
  59. package/dist/chunk-SL3LZQCF.js +1 -0
  60. package/dist/chunk-UBHFUFD4.cjs +1 -0
  61. package/dist/chunk-UBRYJP2G.js +1 -0
  62. package/dist/chunk-UDSJGML2.cjs +2 -0
  63. package/dist/chunk-UHFDH3PG.js +20 -0
  64. package/dist/chunk-UJNSOOYZ.cjs +1 -0
  65. package/dist/chunk-URCLFIME.js +86 -0
  66. package/dist/chunk-UVTS2IWM.js +1 -0
  67. package/dist/chunk-V65NPSR5.cjs +1 -0
  68. package/dist/chunk-WIZ6C5QZ.cjs +1 -0
  69. package/dist/chunk-ZAQOSRP6.js +1 -0
  70. package/dist/chunk-ZELCS7IC.js +3 -0
  71. package/dist/cli/index.cjs +35 -405
  72. package/dist/cli/index.js +35 -402
  73. package/dist/client.cjs +1 -55
  74. package/dist/client.js +1 -6
  75. package/dist/drizzle/index.cjs +1 -50
  76. package/dist/drizzle/index.d.cts +1 -2
  77. package/dist/drizzle/index.d.ts +1 -2
  78. package/dist/drizzle/index.js +1 -9
  79. package/dist/fields/index.cjs +1 -89
  80. package/dist/fields/index.js +1 -4
  81. package/dist/graphql/index.cjs +1 -31
  82. package/dist/graphql/index.d.cts +1 -1
  83. package/dist/graphql/index.d.ts +1 -1
  84. package/dist/graphql/index.js +1 -6
  85. package/dist/{index-jLs0zlft.d.ts → index-DXr33e0x.d.ts} +1 -1
  86. package/dist/{index-DHbywDs-.d.cts → index-DuuUzWBq.d.cts} +1 -1
  87. package/dist/index.cjs +29 -2464
  88. package/dist/index.d.cts +2 -2
  89. package/dist/index.d.ts +2 -2
  90. package/dist/index.js +29 -1929
  91. package/dist/integration.cjs +1 -10
  92. package/dist/integration.js +1 -4
  93. package/dist/media-NSSMOB7N.cjs +1 -0
  94. package/dist/media-RNMCZYPZ.js +1 -0
  95. package/dist/mongo-auth-adapter-JYJ4GBZE.cjs +1 -0
  96. package/dist/mongo-auth-adapter-XI7EPURZ.js +1 -0
  97. package/dist/mongodb/index.cjs +1 -29
  98. package/dist/mongodb/index.d.cts +1 -2
  99. package/dist/mongodb/index.d.ts +1 -2
  100. package/dist/mongodb/index.js +1 -8
  101. package/dist/postgres-auth-adapter-E7OGMDD4.cjs +1 -0
  102. package/dist/postgres-auth-adapter-F4KLOGAG.js +1 -0
  103. package/dist/redis-adapter-AQJVABYT.cjs +1 -0
  104. package/dist/redis-adapter-AUKOV74G.js +1 -0
  105. package/dist/rest/index.cjs +1 -31
  106. package/dist/rest/index.d.cts +1 -1
  107. package/dist/rest/index.d.ts +1 -1
  108. package/dist/rest/index.js +1 -18
  109. package/dist/schema-5XNROI7I.js +1 -0
  110. package/dist/schema-6O4JTJRU.cjs +1 -0
  111. package/dist/sqlite-adapter-5XFLNJDH.js +1 -0
  112. package/dist/sqlite-adapter-W53Q32N5.cjs +1 -0
  113. package/dist/templates/index.cjs +1 -207
  114. package/dist/templates/index.js +1 -6
  115. package/dist/trpc/index.cjs +1 -48
  116. package/dist/trpc/index.js +1 -7
  117. package/dist/ws/index.cjs +1 -25
  118. package/dist/ws/index.js +1 -4
  119. package/package.json +44 -13
  120. package/dist/api-handler-graphql.cjs.map +0 -1
  121. package/dist/api-handler-graphql.js.map +0 -1
  122. package/dist/api-handler-trpc.cjs.map +0 -1
  123. package/dist/api-handler-trpc.js.map +0 -1
  124. package/dist/api-handler.cjs.map +0 -1
  125. package/dist/api-handler.js.map +0 -1
  126. package/dist/bootstrap-FUAPY2OF.cjs +0 -32
  127. package/dist/bootstrap-FUAPY2OF.cjs.map +0 -1
  128. package/dist/bootstrap-OXNVM7FP.js +0 -7
  129. package/dist/bootstrap-OXNVM7FP.js.map +0 -1
  130. package/dist/chunk-2HFJUUFZ.js +0 -250
  131. package/dist/chunk-2HFJUUFZ.js.map +0 -1
  132. package/dist/chunk-3AKCVYDB.js +0 -162
  133. package/dist/chunk-3AKCVYDB.js.map +0 -1
  134. package/dist/chunk-3KTWGODI.cjs +0 -178
  135. package/dist/chunk-3KTWGODI.cjs.map +0 -1
  136. package/dist/chunk-3YELQL7Z.cjs +0 -4
  137. package/dist/chunk-3YELQL7Z.cjs.map +0 -1
  138. package/dist/chunk-4CV4JOE5.js +0 -24
  139. package/dist/chunk-4CV4JOE5.js.map +0 -1
  140. package/dist/chunk-4OCMVGEY.cjs +0 -173
  141. package/dist/chunk-4OCMVGEY.cjs.map +0 -1
  142. package/dist/chunk-4PWRCMTQ.cjs +0 -15
  143. package/dist/chunk-4PWRCMTQ.cjs.map +0 -1
  144. package/dist/chunk-53NYVYVX.js +0 -3243
  145. package/dist/chunk-53NYVYVX.js.map +0 -1
  146. package/dist/chunk-5GFQPHGT.cjs +0 -156
  147. package/dist/chunk-5GFQPHGT.cjs.map +0 -1
  148. package/dist/chunk-5RPRLTTN.js +0 -861
  149. package/dist/chunk-5RPRLTTN.js.map +0 -1
  150. package/dist/chunk-74YSDAWE.cjs +0 -2749
  151. package/dist/chunk-74YSDAWE.cjs.map +0 -1
  152. package/dist/chunk-7OGPN7MP.js +0 -352
  153. package/dist/chunk-7OGPN7MP.js.map +0 -1
  154. package/dist/chunk-7OS7TX2Q.cjs +0 -495
  155. package/dist/chunk-7OS7TX2Q.cjs.map +0 -1
  156. package/dist/chunk-ADLJSJSN.cjs +0 -13
  157. package/dist/chunk-ADLJSJSN.cjs.map +0 -1
  158. package/dist/chunk-B6X3LN25.cjs +0 -6486
  159. package/dist/chunk-B6X3LN25.cjs.map +0 -1
  160. package/dist/chunk-BYBMTIMT.js +0 -419
  161. package/dist/chunk-BYBMTIMT.js.map +0 -1
  162. package/dist/chunk-CF7OL6HR.js +0 -355
  163. package/dist/chunk-CF7OL6HR.js.map +0 -1
  164. package/dist/chunk-CJX74IYK.js +0 -489
  165. package/dist/chunk-CJX74IYK.js.map +0 -1
  166. package/dist/chunk-CKVOU6MX.cjs +0 -52
  167. package/dist/chunk-CKVOU6MX.cjs.map +0 -1
  168. package/dist/chunk-CZLDE2OZ.cjs +0 -28
  169. package/dist/chunk-CZLDE2OZ.cjs.map +0 -1
  170. package/dist/chunk-DPA3KWPY.cjs +0 -205
  171. package/dist/chunk-DPA3KWPY.cjs.map +0 -1
  172. package/dist/chunk-EEJUFDMF.cjs +0 -424
  173. package/dist/chunk-EEJUFDMF.cjs.map +0 -1
  174. package/dist/chunk-FIAMXNTH.js +0 -220
  175. package/dist/chunk-FIAMXNTH.js.map +0 -1
  176. package/dist/chunk-GAOXD3XT.js +0 -175
  177. package/dist/chunk-GAOXD3XT.js.map +0 -1
  178. package/dist/chunk-GTGRLD4Y.js +0 -3
  179. package/dist/chunk-GTGRLD4Y.js.map +0 -1
  180. package/dist/chunk-GUUB5EAG.cjs +0 -223
  181. package/dist/chunk-GUUB5EAG.cjs.map +0 -1
  182. package/dist/chunk-GXFOGU7N.cjs +0 -359
  183. package/dist/chunk-GXFOGU7N.cjs.map +0 -1
  184. package/dist/chunk-GZS4LMR7.js +0 -422
  185. package/dist/chunk-GZS4LMR7.js.map +0 -1
  186. package/dist/chunk-HY6B7B5A.js +0 -150
  187. package/dist/chunk-HY6B7B5A.js.map +0 -1
  188. package/dist/chunk-HZOMOK5Y.js +0 -2728
  189. package/dist/chunk-HZOMOK5Y.js.map +0 -1
  190. package/dist/chunk-IDVRRRAK.cjs +0 -824
  191. package/dist/chunk-IDVRRRAK.cjs.map +0 -1
  192. package/dist/chunk-KC2GDBLS.cjs +0 -84
  193. package/dist/chunk-KC2GDBLS.cjs.map +0 -1
  194. package/dist/chunk-L4EZKIEX.js +0 -185
  195. package/dist/chunk-L4EZKIEX.js.map +0 -1
  196. package/dist/chunk-LNTFRAHF.cjs +0 -473
  197. package/dist/chunk-LNTFRAHF.cjs.map +0 -1
  198. package/dist/chunk-MTIRYI7F.cjs +0 -4
  199. package/dist/chunk-MTIRYI7F.cjs.map +0 -1
  200. package/dist/chunk-N4GN6Q3V.cjs +0 -869
  201. package/dist/chunk-N4GN6Q3V.cjs.map +0 -1
  202. package/dist/chunk-N4H37VN4.cjs +0 -259
  203. package/dist/chunk-N4H37VN4.cjs.map +0 -1
  204. package/dist/chunk-N5QSHUA6.js +0 -1135
  205. package/dist/chunk-N5QSHUA6.js.map +0 -1
  206. package/dist/chunk-NKPKR5BW.cjs +0 -188
  207. package/dist/chunk-NKPKR5BW.cjs.map +0 -1
  208. package/dist/chunk-OIRG6ZRV.cjs +0 -1073
  209. package/dist/chunk-OIRG6ZRV.cjs.map +0 -1
  210. package/dist/chunk-OJ2AM75W.cjs +0 -253
  211. package/dist/chunk-OJ2AM75W.cjs.map +0 -1
  212. package/dist/chunk-OLV7K22H.js +0 -6457
  213. package/dist/chunk-OLV7K22H.js.map +0 -1
  214. package/dist/chunk-OX6GOIPH.js +0 -516
  215. package/dist/chunk-OX6GOIPH.js.map +0 -1
  216. package/dist/chunk-P2YW545G.js +0 -11
  217. package/dist/chunk-P2YW545G.js.map +0 -1
  218. package/dist/chunk-PHJRNPHY.cjs +0 -3291
  219. package/dist/chunk-PHJRNPHY.cjs.map +0 -1
  220. package/dist/chunk-Q72BOAPK.js +0 -817
  221. package/dist/chunk-Q72BOAPK.js.map +0 -1
  222. package/dist/chunk-QU2RFFH4.js +0 -3
  223. package/dist/chunk-QU2RFFH4.js.map +0 -1
  224. package/dist/chunk-RP7VZUEL.js +0 -49
  225. package/dist/chunk-RP7VZUEL.js.map +0 -1
  226. package/dist/chunk-SHTTJMLT.cjs +0 -361
  227. package/dist/chunk-SHTTJMLT.cjs.map +0 -1
  228. package/dist/chunk-SX76DNOO.js +0 -103
  229. package/dist/chunk-SX76DNOO.js.map +0 -1
  230. package/dist/chunk-THBQG64D.cjs +0 -425
  231. package/dist/chunk-THBQG64D.cjs.map +0 -1
  232. package/dist/chunk-TQG7G7YI.cjs +0 -526
  233. package/dist/chunk-TQG7G7YI.cjs.map +0 -1
  234. package/dist/chunk-U3VVLYXG.cjs +0 -189
  235. package/dist/chunk-U3VVLYXG.cjs.map +0 -1
  236. package/dist/chunk-UUDTPZX6.js +0 -193
  237. package/dist/chunk-UUDTPZX6.js.map +0 -1
  238. package/dist/chunk-V5AWATUP.js +0 -1059
  239. package/dist/chunk-V5AWATUP.js.map +0 -1
  240. package/dist/chunk-VAXLFZCV.cjs +0 -110
  241. package/dist/chunk-VAXLFZCV.cjs.map +0 -1
  242. package/dist/chunk-VKREAIBA.cjs +0 -1139
  243. package/dist/chunk-VKREAIBA.cjs.map +0 -1
  244. package/dist/chunk-WDTTHKDS.js +0 -458
  245. package/dist/chunk-WDTTHKDS.js.map +0 -1
  246. package/dist/chunk-WXVB364T.js +0 -218
  247. package/dist/chunk-WXVB364T.js.map +0 -1
  248. package/dist/chunk-X4BPPD6K.js +0 -181
  249. package/dist/chunk-X4BPPD6K.js.map +0 -1
  250. package/dist/chunk-XEB7PH2E.js +0 -81
  251. package/dist/chunk-XEB7PH2E.js.map +0 -1
  252. package/dist/chunk-YT7HXXVN.js +0 -13
  253. package/dist/chunk-YT7HXXVN.js.map +0 -1
  254. package/dist/cli/index.cjs.map +0 -1
  255. package/dist/cli/index.js.map +0 -1
  256. package/dist/client.cjs.map +0 -1
  257. package/dist/client.js.map +0 -1
  258. package/dist/drizzle/index.cjs.map +0 -1
  259. package/dist/drizzle/index.js.map +0 -1
  260. package/dist/fields/index.cjs.map +0 -1
  261. package/dist/fields/index.js.map +0 -1
  262. package/dist/graphql/index.cjs.map +0 -1
  263. package/dist/graphql/index.js.map +0 -1
  264. package/dist/index.cjs.map +0 -1
  265. package/dist/index.js.map +0 -1
  266. package/dist/integration.cjs.map +0 -1
  267. package/dist/integration.js.map +0 -1
  268. package/dist/media-7WDX4BDJ.js +0 -4
  269. package/dist/media-7WDX4BDJ.js.map +0 -1
  270. package/dist/media-TUSLVRQ6.cjs +0 -17
  271. package/dist/media-TUSLVRQ6.cjs.map +0 -1
  272. package/dist/mongo-auth-adapter-GT4S7SCU.cjs +0 -17
  273. package/dist/mongo-auth-adapter-GT4S7SCU.cjs.map +0 -1
  274. package/dist/mongo-auth-adapter-M7VV4LNB.js +0 -4
  275. package/dist/mongo-auth-adapter-M7VV4LNB.js.map +0 -1
  276. package/dist/mongodb/index.cjs.map +0 -1
  277. package/dist/mongodb/index.js.map +0 -1
  278. package/dist/postgres-auth-adapter-AFAPISH7.js +0 -5
  279. package/dist/postgres-auth-adapter-AFAPISH7.js.map +0 -1
  280. package/dist/postgres-auth-adapter-SFDTLONT.cjs +0 -14
  281. package/dist/postgres-auth-adapter-SFDTLONT.cjs.map +0 -1
  282. package/dist/redis-adapter-UQX4EE3B.cjs +0 -13
  283. package/dist/redis-adapter-UQX4EE3B.cjs.map +0 -1
  284. package/dist/redis-adapter-XALOGWY3.js +0 -4
  285. package/dist/redis-adapter-XALOGWY3.js.map +0 -1
  286. package/dist/rest/index.cjs.map +0 -1
  287. package/dist/rest/index.js.map +0 -1
  288. package/dist/schema-6QL3USNB.cjs +0 -67
  289. package/dist/schema-6QL3USNB.cjs.map +0 -1
  290. package/dist/schema-FNNWEAAW.js +0 -6
  291. package/dist/schema-FNNWEAAW.js.map +0 -1
  292. package/dist/sqlite-adapter-AQB5TCGV.cjs +0 -13
  293. package/dist/sqlite-adapter-AQB5TCGV.cjs.map +0 -1
  294. package/dist/sqlite-adapter-N5H6IM2X.js +0 -4
  295. package/dist/sqlite-adapter-N5H6IM2X.js.map +0 -1
  296. package/dist/templates/index.cjs.map +0 -1
  297. package/dist/templates/index.js.map +0 -1
  298. package/dist/trpc/index.cjs.map +0 -1
  299. package/dist/trpc/index.js.map +0 -1
  300. package/dist/ws/index.cjs.map +0 -1
  301. package/dist/ws/index.js.map +0 -1
@@ -1,869 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk4OCMVGEY_cjs = require('./chunk-4OCMVGEY.cjs');
4
- var chunkNKPKR5BW_cjs = require('./chunk-NKPKR5BW.cjs');
5
- var graphql = require('graphql');
6
-
7
- var RelationLoader = class {
8
- db;
9
- tenantID;
10
- user;
11
- caches = /* @__PURE__ */ new Map();
12
- pending = /* @__PURE__ */ new Map();
13
- waiting = /* @__PURE__ */ new Map();
14
- flushScheduled = false;
15
- constructor(opts) {
16
- this.db = opts.db;
17
- this.tenantID = opts.tenantID;
18
- this.user = opts.user;
19
- }
20
- getCacheKey(collection) {
21
- return collection;
22
- }
23
- async load(collection, id) {
24
- const key = this.getCacheKey(collection);
25
- let cache = this.caches.get(key);
26
- if (!cache) {
27
- cache = /* @__PURE__ */ new Map();
28
- this.caches.set(key, cache);
29
- }
30
- if (cache.has(id)) {
31
- return cache.get(id);
32
- }
33
- let pendingSet = this.pending.get(key);
34
- if (!pendingSet) {
35
- pendingSet = /* @__PURE__ */ new Set();
36
- this.pending.set(key, pendingSet);
37
- }
38
- pendingSet.add(id);
39
- cache.set(id, void 0);
40
- if (!this.flushScheduled) {
41
- this.flushScheduled = true;
42
- queueMicrotask(() => {
43
- this.flushScheduled = false;
44
- this.flushAll();
45
- });
46
- }
47
- return new Promise((resolve) => {
48
- this.waiting.set(`${key}:${id}`, resolve);
49
- });
50
- }
51
- async flushAll() {
52
- for (const [key, ids] of this.pending) {
53
- if (ids.size === 0) continue;
54
- const cache = this.caches.get(key);
55
- const docs = await this.db.find({
56
- collection: key,
57
- where: { id: { in: Array.from(ids) } },
58
- limit: ids.size,
59
- tenantID: this.tenantID,
60
- draft: !!this.user
61
- });
62
- for (const doc of docs.docs || []) {
63
- if (doc && doc.id) {
64
- cache.set(doc.id, doc);
65
- const resolve = this.waiting.get(`${key}:${doc.id}`);
66
- if (resolve) {
67
- resolve(doc);
68
- this.waiting.delete(`${key}:${doc.id}`);
69
- }
70
- }
71
- }
72
- }
73
- for (const [keyId, resolve] of this.waiting) {
74
- resolve(void 0);
75
- }
76
- this.waiting.clear();
77
- this.pending.clear();
78
- }
79
- resolveOne(collection, id) {
80
- return this.caches.get(this.getCacheKey(collection))?.get(id);
81
- }
82
- };
83
- var GraphQLJSON = new graphql.GraphQLScalarType({
84
- name: "JSON",
85
- description: "Arbitrary JSON value",
86
- serialize(value) {
87
- return value;
88
- },
89
- parseValue(value) {
90
- return value;
91
- },
92
- parseLiteral(ast) {
93
- switch (ast.kind) {
94
- case graphql.Kind.STRING:
95
- return ast.value;
96
- case graphql.Kind.INT:
97
- case graphql.Kind.FLOAT:
98
- return parseFloat(ast.value);
99
- case graphql.Kind.BOOLEAN:
100
- return ast.value;
101
- case graphql.Kind.OBJECT: {
102
- const obj = {};
103
- for (const field of ast.fields) {
104
- obj[field.name.value] = GraphQLJSON.parseLiteral(field.value);
105
- }
106
- return obj;
107
- }
108
- case graphql.Kind.LIST:
109
- return ast.values.map((v) => GraphQLJSON.parseLiteral(v));
110
- case graphql.Kind.NULL:
111
- return null;
112
- default:
113
- return null;
114
- }
115
- }
116
- });
117
- function depthLimit(maxDepth) {
118
- return (validationContext) => {
119
- let depth = 0;
120
- return {
121
- Field() {
122
- depth++;
123
- if (depth > maxDepth) {
124
- validationContext.reportError(
125
- new Error(`Query exceeds max depth of ${maxDepth}`)
126
- );
127
- }
128
- },
129
- leaveField() {
130
- depth--;
131
- }
132
- };
133
- };
134
- }
135
- function toPascal(slug) {
136
- return slug.split(/[-_]/).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
137
- }
138
- function toCamel(slug) {
139
- const p = toPascal(slug);
140
- return p.charAt(0).toLowerCase() + p.slice(1);
141
- }
142
- function toSingular(slug) {
143
- return slug.endsWith("s") && slug.length > 1 ? slug.slice(0, -1) : slug;
144
- }
145
- async function checkGraphQLAccess(collection, operation, context) {
146
- const accessRule = collection.access?.[operation];
147
- if (context.apiKey) {
148
- if (context.apiKey.permissions?.length > 0) {
149
- const resource = collection.slug;
150
- const action = operation === "read" ? "read" : operation === "create" ? "create" : "update";
151
- const permission = `${resource}:${action}`;
152
- if (!chunk4OCMVGEY_cjs.hasApiKeyPermission(context.apiKey.permissions, permission) && !chunk4OCMVGEY_cjs.hasApiKeyPermission(context.apiKey.permissions, `${resource}:admin`)) {
153
- return { allowed: false };
154
- }
155
- return { allowed: true };
156
- }
157
- if (accessRule) {
158
- const result2 = await chunk4OCMVGEY_cjs.evaluateAccess(accessRule, {
159
- req: context.req,
160
- user: context.user,
161
- tenantID: context.tenantID
162
- });
163
- if (typeof result2 === "boolean") {
164
- return { allowed: result2 };
165
- }
166
- return { allowed: true, extraWhere: result2 };
167
- }
168
- return { allowed: true };
169
- }
170
- if (context.user) {
171
- const resource = collection.slug;
172
- const action = operation === "read" ? "read" : operation === "create" ? "create" : operation === "update" ? "update" : "delete";
173
- const permission = `${resource}:${action}`;
174
- const userHasPermission = chunkNKPKR5BW_cjs.hasPermission(
175
- { id: context.user.id, email: context.user.email, role: context.user.role },
176
- permission
177
- );
178
- if (!userHasPermission && !chunkNKPKR5BW_cjs.hasPermission(
179
- { id: context.user.id, email: context.user.email, role: context.user.role },
180
- `${resource}:admin`
181
- )) {
182
- if (!accessRule) {
183
- return { allowed: false };
184
- }
185
- }
186
- }
187
- if (!accessRule) {
188
- if (!context.user) {
189
- return { allowed: false };
190
- }
191
- return { allowed: true };
192
- }
193
- const result = await chunk4OCMVGEY_cjs.evaluateAccess(accessRule, {
194
- req: context.req,
195
- user: context.user,
196
- tenantID: context.tenantID
197
- });
198
- if (typeof result === "boolean") {
199
- return { allowed: result };
200
- }
201
- return { allowed: true, extraWhere: result };
202
- }
203
- async function checkGlobalAccess(global, operation, context) {
204
- const accessRule = global.access?.[operation];
205
- if (context.apiKey) {
206
- if (context.apiKey.permissions?.length > 0) {
207
- const resource = global.slug;
208
- const permission = `${resource}:${operation}`;
209
- if (!chunk4OCMVGEY_cjs.hasApiKeyPermission(context.apiKey.permissions, permission) && !chunk4OCMVGEY_cjs.hasApiKeyPermission(context.apiKey.permissions, `${resource}:admin`) && !chunk4OCMVGEY_cjs.hasApiKeyPermission(context.apiKey.permissions, `${resource}:*`)) {
210
- return { allowed: false };
211
- }
212
- return { allowed: true };
213
- }
214
- if (accessRule) {
215
- const result2 = await chunk4OCMVGEY_cjs.evaluateAccess(accessRule, {
216
- req: context.req,
217
- user: context.user,
218
- tenantID: context.tenantID
219
- });
220
- return { allowed: typeof result2 === "boolean" ? result2 : true };
221
- }
222
- return { allowed: true };
223
- }
224
- if (!accessRule) {
225
- if (!context.user) {
226
- return { allowed: false };
227
- }
228
- const userRole = context.user.role;
229
- if (userRole === "super_admin" || userRole === "admin") {
230
- return { allowed: true };
231
- }
232
- return { allowed: false };
233
- }
234
- const result = await chunk4OCMVGEY_cjs.evaluateAccess(accessRule, {
235
- req: context.req,
236
- user: context.user,
237
- tenantID: context.tenantID
238
- });
239
- if (typeof result === "boolean") {
240
- return { allowed: result };
241
- }
242
- return { allowed: true };
243
- }
244
- function resolveMediaUrl(url, origin) {
245
- if (!url) return null;
246
- if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("blob:") || url.startsWith("data:")) return url;
247
- const base = (process.env.KYRO_BASE_URL || origin || "http://localhost:4321").replace(/\/+$/, "");
248
- return `${base}${url.startsWith("/") ? "" : "/"}${url}`;
249
- }
250
- function processMediaDoc(doc, origin) {
251
- if (!doc) return doc;
252
- if (doc.url) doc.url = resolveMediaUrl(doc.url, origin);
253
- if (doc.thumbnailUrl) doc.thumbnailUrl = resolveMediaUrl(doc.thumbnailUrl, origin);
254
- return doc;
255
- }
256
- function fieldToGraphQLType(field, registry, collectionTypes, isInputType = false) {
257
- switch (field.type) {
258
- case "text":
259
- case "email":
260
- case "password":
261
- case "textarea":
262
- case "color":
263
- case "code":
264
- case "markdown":
265
- case "date":
266
- case "select":
267
- case "radio":
268
- return graphql.GraphQLString;
269
- case "upload": {
270
- const uploadField = field;
271
- if (isInputType) {
272
- return uploadField.hasMany ? new graphql.GraphQLList(graphql.GraphQLString) : graphql.GraphQLString;
273
- }
274
- if (uploadField.relationTo && collectionTypes?.[uploadField.relationTo]) {
275
- const refType = collectionTypes[uploadField.relationTo];
276
- return uploadField.hasMany ? new graphql.GraphQLList(refType) : refType;
277
- }
278
- return GraphQLJSON;
279
- }
280
- case "image": {
281
- if (isInputType) return graphql.GraphQLString;
282
- const imageField = field;
283
- if (imageField.relationTo && collectionTypes?.[imageField.relationTo]) {
284
- return collectionTypes[imageField.relationTo];
285
- }
286
- return GraphQLJSON;
287
- }
288
- case "number":
289
- return field.integer ? graphql.GraphQLInt : graphql.GraphQLFloat;
290
- case "checkbox":
291
- return graphql.GraphQLBoolean;
292
- case "json":
293
- case "richtext":
294
- case "blocks":
295
- case "tabs":
296
- return isInputType ? GraphQLJSON : GraphQLJSON;
297
- case "relationship":
298
- if (typeof field.relationTo === "string") {
299
- if (isInputType) {
300
- return field.hasMany ? new graphql.GraphQLList(graphql.GraphQLString) : graphql.GraphQLString;
301
- }
302
- if (collectionTypes?.[field.relationTo]) {
303
- return field.hasMany ? new graphql.GraphQLList(collectionTypes[field.relationTo]) : collectionTypes[field.relationTo];
304
- }
305
- const relatedCollection = registry.getCollection(field.relationTo);
306
- if (relatedCollection) {
307
- return new graphql.GraphQLObjectType({
308
- name: `${toPascal(field.relationTo)}Ref`,
309
- fields: () => ({
310
- id: { type: graphql.GraphQLString },
311
- ...buildFieldsFromCollection(relatedCollection, registry, collectionTypes)
312
- })
313
- });
314
- }
315
- }
316
- return graphql.GraphQLString;
317
- case "array":
318
- return new graphql.GraphQLList(graphql.GraphQLString);
319
- case "group":
320
- return isInputType ? GraphQLJSON : GraphQLJSON;
321
- default:
322
- return graphql.GraphQLString;
323
- }
324
- }
325
- function buildFieldsFromCollection(config, registry, collectionTypes) {
326
- const fields = {};
327
- for (const field of config.fields) {
328
- if (field.name && field.admin?.hidden !== true) {
329
- const fieldConfig = buildFieldConfig(field, registry, collectionTypes);
330
- if (fieldConfig) {
331
- fields[field.name] = fieldConfig;
332
- }
333
- }
334
- }
335
- return fields;
336
- }
337
- function buildFieldConfig(field, registry, collectionTypes) {
338
- if (!field.name) return null;
339
- const deprecationReason = field.deprecated || void 0;
340
- if (field.type === "upload") {
341
- const gqlType2 = fieldToGraphQLType(field, registry, collectionTypes, false);
342
- const uploadField = field;
343
- return {
344
- type: field.required ? new graphql.GraphQLNonNull(gqlType2) : gqlType2,
345
- description: field.admin?.description || field.label,
346
- deprecationReason,
347
- resolve: async (source, args, ctx) => {
348
- const loader = ctx?.relationLoader;
349
- const value = source?.[uploadField.name];
350
- const origin = ctx?.req?.url ? new URL(ctx.req.url).origin : void 0;
351
- if (!value) return null;
352
- if (uploadField.hasMany) {
353
- const items = Array.isArray(value) ? value : [];
354
- return Promise.all(items.map(async (item) => {
355
- const id2 = typeof item === "string" ? item : item?.id;
356
- if (!id2) return processMediaDoc(item, origin);
357
- if (typeof item === "object" && item?.url) return processMediaDoc(item, origin);
358
- if (loader) {
359
- const cached = loader.resolveOne(uploadField.relationTo, id2);
360
- if (cached) return processMediaDoc(cached, origin);
361
- const loaded = await loader.load(uploadField.relationTo, id2);
362
- if (loaded) return processMediaDoc(loaded, origin);
363
- }
364
- return { id: id2 };
365
- }));
366
- }
367
- const id = typeof value === "string" ? value : value?.id;
368
- if (!id) return processMediaDoc(value, origin);
369
- if (typeof value === "object" && value?.url) return processMediaDoc(value, origin);
370
- if (loader) {
371
- const cached = loader.resolveOne(uploadField.relationTo, id);
372
- if (cached) return processMediaDoc(cached, origin);
373
- const loaded = await loader.load(uploadField.relationTo, id);
374
- if (loaded) return processMediaDoc(loaded, origin);
375
- }
376
- return { id };
377
- }
378
- };
379
- }
380
- if (field.type === "relationship" && !field.hasMany) {
381
- const gqlType2 = fieldToGraphQLType(field, registry, collectionTypes, false);
382
- return {
383
- type: field.required ? new graphql.GraphQLNonNull(gqlType2) : gqlType2,
384
- description: field.admin?.description || field.label,
385
- deprecationReason,
386
- resolve: async (source, args, ctx) => {
387
- const loader = ctx?.relationLoader;
388
- const relField = field;
389
- const id = source?.[relField.name];
390
- if (!id) return null;
391
- if (loader && typeof id === "string") {
392
- const cached = loader.resolveOne(relField.relationTo, id);
393
- if (cached) return cached;
394
- const loaded = await loader.load(relField.relationTo, id);
395
- if (loaded) return loaded;
396
- }
397
- return { id };
398
- }
399
- };
400
- }
401
- if (field.type === "relationship" && field.hasMany) {
402
- const gqlType2 = fieldToGraphQLType(field, registry, collectionTypes, false);
403
- return {
404
- type: gqlType2,
405
- description: field.admin?.description || field.label,
406
- deprecationReason,
407
- resolve: async (source, args, ctx) => {
408
- const loader = ctx?.relationLoader;
409
- const relField = field;
410
- const ids = source?.[relField.name] || [];
411
- if (!ids.length) return [];
412
- if (loader) {
413
- const results = [];
414
- for (const id of ids) {
415
- const cached = loader.resolveOne(relField.relationTo, id);
416
- if (cached) results.push(cached);
417
- else {
418
- const loaded = await loader.load(relField.relationTo, id);
419
- results.push(loaded || { id });
420
- }
421
- }
422
- return results;
423
- }
424
- return ids.map((id) => ({ id }));
425
- }
426
- };
427
- }
428
- const gqlType = fieldToGraphQLType(field, registry, collectionTypes, false);
429
- return {
430
- type: field.required ? new graphql.GraphQLNonNull(gqlType) : gqlType,
431
- description: field.admin?.description || field.label,
432
- deprecationReason
433
- };
434
- }
435
- function buildGraphQLSchema(options) {
436
- const { registry, db, user, req, tenantID, apiKey, settings } = options;
437
- const apiAccess = settings?.access?.apiAccess;
438
- if (apiAccess?.graphqlEnabled === false) {
439
- throw new Error("GraphQL API is disabled");
440
- }
441
- const collections = registry.getCollections();
442
- const globals = registry.getGlobals();
443
- const collectionTypes = {};
444
- const collectionInputTypes = {};
445
- for (const collection of collections) {
446
- collectionTypes[collection.slug] = new graphql.GraphQLObjectType({
447
- name: toPascal(toSingular(collection.slug)),
448
- fields: () => ({
449
- id: { type: graphql.GraphQLString },
450
- ...buildFieldsFromCollection(collection, registry, collectionTypes),
451
- ...collection.timestamps ? {
452
- createdAt: { type: graphql.GraphQLString },
453
- updatedAt: { type: graphql.GraphQLString }
454
- } : {},
455
- ...collection.tenantScoped ? {
456
- tenantID: { type: graphql.GraphQLString }
457
- } : {}
458
- })
459
- });
460
- const inputFields = {};
461
- for (const field of collection.fields) {
462
- if (field.name && field.name !== "id") {
463
- inputFields[field.name] = {
464
- type: fieldToGraphQLType(field, registry, collectionTypes, true)
465
- };
466
- }
467
- }
468
- collectionInputTypes[collection.slug] = new graphql.GraphQLInputObjectType({
469
- name: `${toPascal(toSingular(collection.slug))}Input`,
470
- fields: () => inputFields
471
- });
472
- }
473
- const globalTypes = {};
474
- const globalInputTypes = {};
475
- for (const global of globals) {
476
- globalTypes[global.slug] = new graphql.GraphQLObjectType({
477
- name: `${toPascal(global.slug)}Global`,
478
- fields: () => ({
479
- id: { type: graphql.GraphQLString },
480
- ...buildFieldsFromCollection(
481
- { slug: global.slug, fields: global.fields },
482
- registry,
483
- collectionTypes
484
- )
485
- })
486
- });
487
- globalInputTypes[global.slug] = new graphql.GraphQLInputObjectType({
488
- name: `${toPascal(global.slug)}GlobalInput`,
489
- fields: () => {
490
- const inputFields = {};
491
- for (const field of global.fields) {
492
- if (field.name && field.name !== "id") {
493
- inputFields[field.name] = {
494
- type: fieldToGraphQLType(field, registry, collectionTypes, true)
495
- };
496
- }
497
- }
498
- return inputFields;
499
- }
500
- });
501
- }
502
- const queryFields = {};
503
- for (const collection of collections) {
504
- const type = collectionTypes[collection.slug];
505
- if (!type) continue;
506
- queryFields[toCamel(collection.slug)] = {
507
- type: new graphql.GraphQLObjectType({
508
- name: `${toPascal(toSingular(collection.slug))}FindResult`,
509
- fields: {
510
- docs: { type: new graphql.GraphQLList(type) },
511
- totalDocs: { type: graphql.GraphQLInt },
512
- page: { type: graphql.GraphQLInt },
513
- totalPages: { type: graphql.GraphQLInt },
514
- hasNextPage: { type: graphql.GraphQLBoolean },
515
- hasPrevPage: { type: graphql.GraphQLBoolean }
516
- }
517
- }),
518
- args: {
519
- where: { type: graphql.GraphQLString },
520
- sort: { type: graphql.GraphQLString },
521
- limit: { type: graphql.GraphQLInt },
522
- page: { type: graphql.GraphQLInt },
523
- draft: { type: graphql.GraphQLBoolean }
524
- },
525
- resolve: async (_, args, context) => {
526
- const access = await checkGraphQLAccess(collection, "read", {
527
- user: context.user,
528
- req: context.req,
529
- tenantID: context.tenantID,
530
- apiKey: context.apiKey
531
- });
532
- if (!access.allowed) {
533
- throw new Error("Access denied");
534
- }
535
- if (context.tenantID) {
536
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
537
- }
538
- let where = {};
539
- if (args.where) {
540
- try {
541
- where = JSON.parse(args.where);
542
- } catch {
543
- }
544
- }
545
- if (access.extraWhere) {
546
- where = { ...where, ...access.extraWhere };
547
- }
548
- const isDraft = args.draft ?? !!context.user;
549
- return db.find({
550
- collection: collection.slug,
551
- where,
552
- sort: args.sort,
553
- limit: args.limit || 10,
554
- page: args.page || 1,
555
- tenantID: context.tenantID,
556
- draft: isDraft
557
- });
558
- }
559
- };
560
- queryFields[toCamel(toSingular(collection.slug))] = {
561
- type,
562
- args: {
563
- id: { type: graphql.GraphQLString },
564
- slug: { type: graphql.GraphQLString },
565
- draft: { type: graphql.GraphQLBoolean }
566
- },
567
- resolve: async (_, args, context) => {
568
- if (!args.id && !args.slug) {
569
- throw new Error("Either id or slug is required");
570
- }
571
- const access = await checkGraphQLAccess(collection, "read", {
572
- user: context.user,
573
- req: context.req,
574
- tenantID: context.tenantID,
575
- apiKey: context.apiKey
576
- });
577
- if (!access.allowed) {
578
- throw new Error("Access denied");
579
- }
580
- if (context.tenantID) {
581
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
582
- }
583
- const isDraft = args.draft ?? !!context.user;
584
- if (args.id) {
585
- return db.findByID({
586
- collection: collection.slug,
587
- id: args.id,
588
- tenantID: context.tenantID,
589
- draft: isDraft
590
- });
591
- }
592
- const result = await db.find({
593
- collection: collection.slug,
594
- where: { slug: { equals: args.slug } },
595
- limit: 1,
596
- page: 1,
597
- tenantID: context.tenantID,
598
- draft: isDraft
599
- });
600
- return result.docs?.[0] || null;
601
- }
602
- };
603
- queryFields[`count${toPascal(collection.slug)}`] = {
604
- type: new graphql.GraphQLObjectType({
605
- name: `${toPascal(toSingular(collection.slug))}Count`,
606
- fields: {
607
- totalDocs: { type: graphql.GraphQLInt }
608
- }
609
- }),
610
- args: {
611
- where: { type: graphql.GraphQLString }
612
- },
613
- resolve: async (_, args, context) => {
614
- const access = await checkGraphQLAccess(collection, "read", {
615
- user: context.user,
616
- req: context.req,
617
- tenantID: context.tenantID,
618
- apiKey: context.apiKey
619
- });
620
- if (!access.allowed) {
621
- return { totalDocs: 0 };
622
- }
623
- let where = {};
624
- if (args.where) {
625
- try {
626
- where = JSON.parse(args.where);
627
- } catch {
628
- }
629
- }
630
- const count = await db.count({
631
- collection: collection.slug,
632
- where,
633
- tenantID: context.tenantID
634
- });
635
- return { totalDocs: count };
636
- }
637
- };
638
- }
639
- for (const global of globals) {
640
- const type = globalTypes[global.slug];
641
- if (!type) continue;
642
- queryFields[toCamel(toSingular(global.slug))] = {
643
- type,
644
- resolve: async (_, args, context) => {
645
- const access = await checkGlobalAccess(global, "read", {
646
- user: context.user,
647
- req: context.req,
648
- tenantID: context.tenantID,
649
- apiKey: context.apiKey
650
- });
651
- if (!access.allowed) {
652
- throw new Error("Access denied: cannot read global");
653
- }
654
- if (context.tenantID) {
655
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
656
- }
657
- return db.findOne({
658
- collection: `_globals_${global.slug}`,
659
- where: {},
660
- tenantID: context.tenantID
661
- });
662
- }
663
- };
664
- }
665
- const Query = new graphql.GraphQLObjectType({
666
- name: "Query",
667
- fields: queryFields
668
- });
669
- const mutationFields = {};
670
- for (const collection of collections) {
671
- const type = collectionTypes[collection.slug];
672
- const inputType = collectionInputTypes[collection.slug];
673
- if (!type || !inputType) continue;
674
- mutationFields[`create${toPascal(toSingular(collection.slug))}`] = {
675
- type: new graphql.GraphQLObjectType({
676
- name: `${toPascal(toSingular(collection.slug))}CreateResult`,
677
- fields: {
678
- doc: { type },
679
- message: { type: graphql.GraphQLString }
680
- }
681
- }),
682
- args: {
683
- data: { type: new graphql.GraphQLNonNull(inputType) }
684
- },
685
- resolve: async (_, args, context) => {
686
- const access = await checkGraphQLAccess(collection, "create", {
687
- user: context.user,
688
- req: context.req,
689
- tenantID: context.tenantID,
690
- apiKey: context.apiKey
691
- });
692
- if (!access.allowed) {
693
- throw new Error("Access denied: cannot create");
694
- }
695
- if (context.tenantID) {
696
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
697
- }
698
- const schema = registry.getCreateZodSchema(collection.slug);
699
- const validated = schema.parse(args.data);
700
- const doc = await db.create({
701
- collection: collection.slug,
702
- data: validated,
703
- tenantID: context.tenantID
704
- });
705
- return { doc, message: "Created successfully" };
706
- }
707
- };
708
- mutationFields[`update${toPascal(toSingular(collection.slug))}`] = {
709
- type: new graphql.GraphQLObjectType({
710
- name: `${toPascal(toSingular(collection.slug))}UpdateResult`,
711
- fields: {
712
- doc: { type },
713
- message: { type: graphql.GraphQLString }
714
- }
715
- }),
716
- args: {
717
- id: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
718
- data: { type: new graphql.GraphQLNonNull(inputType) },
719
- baseUpdatedAt: { type: graphql.GraphQLString }
720
- },
721
- resolve: async (_, args, context) => {
722
- const access = await checkGraphQLAccess(collection, "update", {
723
- user: context.user,
724
- req: context.req,
725
- tenantID: context.tenantID,
726
- apiKey: context.apiKey
727
- });
728
- if (!access.allowed) {
729
- throw new Error("Access denied: cannot update");
730
- }
731
- if (context.tenantID) {
732
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
733
- }
734
- if (args.baseUpdatedAt) {
735
- const originalDoc = await db.findByID({
736
- collection: collection.slug,
737
- id: args.id,
738
- tenantID: context.tenantID,
739
- draft: true
740
- });
741
- if (originalDoc && originalDoc.updatedAt && args.baseUpdatedAt !== originalDoc.updatedAt) {
742
- throw new Error(`Revision conflict: document has changed since ${args.baseUpdatedAt}. Current updatedAt: ${originalDoc.updatedAt}`);
743
- }
744
- }
745
- const schema = registry.getUpdateZodSchema(collection.slug);
746
- const validated = schema.parse(args.data);
747
- const doc = await db.update({
748
- collection: collection.slug,
749
- id: args.id,
750
- data: validated,
751
- tenantID: context.tenantID
752
- });
753
- return { doc, message: "Updated successfully" };
754
- }
755
- };
756
- mutationFields[`delete${toPascal(toSingular(collection.slug))}`] = {
757
- type: new graphql.GraphQLObjectType({
758
- name: `${toPascal(toSingular(collection.slug))}DeleteResult`,
759
- fields: {
760
- doc: { type },
761
- message: { type: graphql.GraphQLString }
762
- }
763
- }),
764
- args: {
765
- id: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
766
- },
767
- resolve: async (_, args, context) => {
768
- const access = await checkGraphQLAccess(collection, "delete", {
769
- user: context.user,
770
- req: context.req,
771
- tenantID: context.tenantID,
772
- apiKey: context.apiKey
773
- });
774
- if (!access.allowed) {
775
- throw new Error("Access denied: cannot delete");
776
- }
777
- if (context.tenantID) {
778
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
779
- }
780
- const doc = await db.delete({
781
- collection: collection.slug,
782
- id: args.id,
783
- tenantID: context.tenantID
784
- });
785
- return { doc, message: "Deleted successfully" };
786
- }
787
- };
788
- }
789
- for (const global of globals) {
790
- const inputType = globalInputTypes[global.slug];
791
- if (!inputType) continue;
792
- mutationFields[`update${toPascal(global.slug)}`] = {
793
- type: new graphql.GraphQLObjectType({
794
- name: `${toPascal(global.slug)}UpdateResult`,
795
- fields: {
796
- doc: { type: globalTypes[global.slug] || graphql.GraphQLString },
797
- message: { type: graphql.GraphQLString }
798
- }
799
- }),
800
- args: {
801
- data: { type: new graphql.GraphQLNonNull(inputType) }
802
- },
803
- resolve: async (_, args, context) => {
804
- const access = await checkGlobalAccess(global, "update", {
805
- user: context.user,
806
- req: context.req,
807
- tenantID: context.tenantID,
808
- apiKey: context.apiKey
809
- });
810
- if (!access.allowed) {
811
- throw new Error("Access denied: cannot update global");
812
- }
813
- if (context.tenantID) {
814
- db.setTenantContext({ tenantId: context.tenantID, userId: context.user?.id ?? "", role: context.user?.role, isSuperAdmin: context.user?.role === "super_admin" });
815
- }
816
- const doc = await db.findOne({
817
- collection: `_globals_${global.slug}`,
818
- where: {},
819
- tenantID: context.tenantID
820
- });
821
- let result;
822
- if (doc) {
823
- result = await db.update({
824
- collection: `_globals_${global.slug}`,
825
- id: doc.id,
826
- data: args.data,
827
- tenantID: context.tenantID
828
- });
829
- } else {
830
- result = await db.create({
831
- collection: `_globals_${global.slug}`,
832
- data: args.data,
833
- tenantID: context.tenantID
834
- });
835
- }
836
- return { doc: result, message: "Updated successfully" };
837
- }
838
- };
839
- }
840
- const Mutation = new graphql.GraphQLObjectType({
841
- name: "Mutation",
842
- fields: mutationFields
843
- });
844
- return new graphql.GraphQLSchema({
845
- query: Query,
846
- mutation: Mutation
847
- });
848
- }
849
- function createGraphQLSchema(registry, db, options) {
850
- return buildGraphQLSchema({
851
- registry,
852
- db,
853
- user: options?.user,
854
- req: options?.req,
855
- tenantID: options?.tenantID,
856
- apiKey: options?.apiKey
857
- });
858
- }
859
-
860
- Object.defineProperty(exports, "printSchema", {
861
- enumerable: true,
862
- get: function () { return graphql.printSchema; }
863
- });
864
- exports.RelationLoader = RelationLoader;
865
- exports.buildGraphQLSchema = buildGraphQLSchema;
866
- exports.createGraphQLSchema = createGraphQLSchema;
867
- exports.depthLimit = depthLimit;
868
- //# sourceMappingURL=chunk-N4GN6Q3V.cjs.map
869
- //# sourceMappingURL=chunk-N4GN6Q3V.cjs.map