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