@constructive-io/sdk 0.30.0 → 0.30.1

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 (324) hide show
  1. package/README.md +1 -0
  2. package/agent/orm/input-types.d.ts +96 -8
  3. package/api/orm/index.d.ts +5 -15
  4. package/api/orm/index.js +2 -2
  5. package/api/orm/input-types.d.ts +250 -231
  6. package/api/orm/models/index.d.ts +1 -1
  7. package/api/orm/models/index.js +3 -3
  8. package/api/orm/mutation/index.d.ts +11 -36
  9. package/api/orm/mutation/index.js +6 -30
  10. package/auth/orm/index.d.ts +10 -5
  11. package/auth/orm/input-types.d.ts +54 -45
  12. package/auth/orm/models/principal.d.ts +1 -10
  13. package/auth/orm/models/principal.js +0 -13
  14. package/auth/orm/mutation/index.d.ts +17 -9
  15. package/auth/orm/mutation/index.js +24 -12
  16. package/compute/orm/index.d.ts +76 -17
  17. package/compute/orm/index.js +56 -12
  18. package/compute/orm/input-types.d.ts +5893 -1343
  19. package/compute/orm/input-types.js +17 -3
  20. package/compute/orm/models/dbPreset.d.ts +54 -0
  21. package/compute/orm/models/dbPreset.js +104 -0
  22. package/compute/orm/models/functionGraphCommit.d.ts +2 -2
  23. package/compute/orm/models/functionGraphCommit.js +2 -2
  24. package/compute/orm/models/functionGraphObject.d.ts +2 -2
  25. package/compute/orm/models/functionGraphObject.js +2 -2
  26. package/compute/orm/models/functionGraphRef.d.ts +2 -2
  27. package/compute/orm/models/functionGraphRef.js +2 -2
  28. package/compute/orm/models/index.d.ts +28 -6
  29. package/compute/orm/models/index.js +57 -13
  30. package/compute/orm/models/infraCommit.d.ts +56 -0
  31. package/compute/orm/models/infraCommit.js +107 -0
  32. package/compute/orm/models/infraGetAllRecord.d.ts +30 -0
  33. package/compute/orm/models/infraGetAllRecord.js +59 -0
  34. package/compute/orm/models/infraObject.d.ts +56 -0
  35. package/compute/orm/models/infraObject.js +97 -0
  36. package/compute/orm/models/infraRef.d.ts +56 -0
  37. package/compute/orm/models/infraRef.js +107 -0
  38. package/compute/orm/models/infraStore.d.ts +54 -0
  39. package/compute/orm/models/infraStore.js +104 -0
  40. package/compute/orm/models/integrationProvider.d.ts +54 -0
  41. package/{modules/orm/models/configSecretsModule.js → compute/orm/models/integrationProvider.js} +27 -27
  42. package/compute/orm/models/namespace.d.ts +54 -0
  43. package/compute/orm/models/namespace.js +104 -0
  44. package/compute/orm/models/namespaceEvent.d.ts +56 -0
  45. package/compute/orm/models/{orgFunctionExecutionLog.js → namespaceEvent.js} +27 -27
  46. package/compute/orm/models/platformFunctionApiBinding.d.ts +54 -0
  47. package/compute/orm/models/platformFunctionApiBinding.js +104 -0
  48. package/compute/orm/models/platformFunctionDefinition.d.ts +54 -0
  49. package/compute/orm/models/platformFunctionDefinition.js +104 -0
  50. package/compute/orm/models/platformFunctionDeployment.d.ts +54 -0
  51. package/compute/orm/models/platformFunctionDeployment.js +104 -0
  52. package/compute/orm/models/platformFunctionDeploymentEvent.d.ts +56 -0
  53. package/compute/orm/models/platformFunctionDeploymentEvent.js +107 -0
  54. package/compute/orm/models/platformFunctionExecutionLog.d.ts +56 -0
  55. package/compute/orm/models/platformFunctionExecutionLog.js +107 -0
  56. package/compute/orm/models/platformFunctionInvocation.d.ts +56 -0
  57. package/compute/orm/models/platformFunctionInvocation.js +107 -0
  58. package/compute/orm/models/platformResource.d.ts +54 -0
  59. package/compute/orm/models/{secretDefinition.js → platformResource.js} +27 -27
  60. package/compute/orm/models/platformResourceDefinition.d.ts +54 -0
  61. package/compute/orm/models/platformResourceDefinition.js +104 -0
  62. package/compute/orm/models/platformResourceEvent.d.ts +56 -0
  63. package/compute/orm/models/{orgFunctionInvocation.js → platformResourceEvent.js} +27 -27
  64. package/compute/orm/models/platformResourceStatusCheck.d.ts +54 -0
  65. package/compute/orm/models/platformResourceStatusCheck.js +104 -0
  66. package/compute/orm/models/platformResourcesRequirementsState.d.ts +30 -0
  67. package/compute/orm/models/platformResourcesRequirementsState.js +59 -0
  68. package/compute/orm/models/platformResourcesResolvedRequirement.d.ts +30 -0
  69. package/compute/orm/models/platformResourcesResolvedRequirement.js +59 -0
  70. package/compute/orm/models/resourceDefinition.d.ts +54 -0
  71. package/compute/orm/models/resourceDefinition.js +104 -0
  72. package/compute/orm/models/resourceStatusCheck.d.ts +54 -0
  73. package/compute/orm/models/resourceStatusCheck.js +104 -0
  74. package/compute/orm/models/resourcesRequirementsState.d.ts +30 -0
  75. package/compute/orm/models/resourcesRequirementsState.js +59 -0
  76. package/compute/orm/models/resourcesResolvedRequirement.d.ts +30 -0
  77. package/compute/orm/models/resourcesResolvedRequirement.js +59 -0
  78. package/compute/orm/mutation/index.d.ts +33 -9
  79. package/compute/orm/mutation/index.js +48 -12
  80. package/config/orm/index.d.ts +42 -16
  81. package/config/orm/index.js +8 -2
  82. package/config/orm/input-types.d.ts +595 -154
  83. package/config/orm/models/config.d.ts +54 -0
  84. package/{modules/orm/models/configSecretsOrgModule.js → config/orm/models/config.js} +27 -27
  85. package/config/orm/models/index.d.ts +4 -1
  86. package/config/orm/models/index.js +9 -3
  87. package/config/orm/models/platformInternalSecret.d.ts +36 -0
  88. package/config/orm/models/platformInternalSecret.js +80 -0
  89. package/config/orm/models/platformSecret.d.ts +36 -0
  90. package/config/orm/models/platformSecret.js +80 -0
  91. package/config/orm/models/secret.d.ts +36 -0
  92. package/config/orm/models/secret.js +80 -0
  93. package/config/orm/mutation/index.d.ts +56 -24
  94. package/config/orm/mutation/index.js +78 -30
  95. package/esm/agent/orm/input-types.d.ts +96 -8
  96. package/esm/api/orm/index.d.ts +5 -15
  97. package/esm/api/orm/index.js +2 -2
  98. package/esm/api/orm/input-types.d.ts +250 -231
  99. package/esm/api/orm/models/index.d.ts +1 -1
  100. package/esm/api/orm/models/index.js +1 -1
  101. package/esm/api/orm/mutation/index.d.ts +11 -36
  102. package/esm/api/orm/mutation/index.js +6 -30
  103. package/esm/auth/orm/index.d.ts +10 -5
  104. package/esm/auth/orm/input-types.d.ts +54 -45
  105. package/esm/auth/orm/models/principal.d.ts +1 -10
  106. package/esm/auth/orm/models/principal.js +1 -14
  107. package/esm/auth/orm/mutation/index.d.ts +17 -9
  108. package/esm/auth/orm/mutation/index.js +24 -12
  109. package/esm/compute/orm/index.d.ts +76 -17
  110. package/esm/compute/orm/index.js +56 -12
  111. package/esm/compute/orm/input-types.d.ts +5893 -1343
  112. package/esm/compute/orm/input-types.js +17 -3
  113. package/esm/compute/orm/models/dbPreset.d.ts +54 -0
  114. package/esm/compute/orm/models/dbPreset.js +100 -0
  115. package/esm/compute/orm/models/functionGraphCommit.d.ts +2 -2
  116. package/esm/compute/orm/models/functionGraphCommit.js +2 -2
  117. package/esm/compute/orm/models/functionGraphObject.d.ts +2 -2
  118. package/esm/compute/orm/models/functionGraphObject.js +2 -2
  119. package/esm/compute/orm/models/functionGraphRef.d.ts +2 -2
  120. package/esm/compute/orm/models/functionGraphRef.js +2 -2
  121. package/esm/compute/orm/models/index.d.ts +28 -6
  122. package/esm/compute/orm/models/index.js +28 -6
  123. package/esm/compute/orm/models/infraCommit.d.ts +56 -0
  124. package/esm/compute/orm/models/infraCommit.js +103 -0
  125. package/esm/compute/orm/models/infraGetAllRecord.d.ts +30 -0
  126. package/esm/compute/orm/models/infraGetAllRecord.js +55 -0
  127. package/esm/compute/orm/models/infraObject.d.ts +56 -0
  128. package/esm/compute/orm/models/infraObject.js +93 -0
  129. package/esm/compute/orm/models/infraRef.d.ts +56 -0
  130. package/esm/compute/orm/models/infraRef.js +103 -0
  131. package/esm/compute/orm/models/infraStore.d.ts +54 -0
  132. package/esm/compute/orm/models/infraStore.js +100 -0
  133. package/esm/compute/orm/models/integrationProvider.d.ts +54 -0
  134. package/esm/compute/orm/models/integrationProvider.js +100 -0
  135. package/esm/compute/orm/models/namespace.d.ts +54 -0
  136. package/esm/compute/orm/models/namespace.js +100 -0
  137. package/esm/compute/orm/models/namespaceEvent.d.ts +56 -0
  138. package/esm/compute/orm/models/{orgFunctionExecutionLog.js → namespaceEvent.js} +25 -25
  139. package/esm/compute/orm/models/platformFunctionApiBinding.d.ts +54 -0
  140. package/esm/compute/orm/models/platformFunctionApiBinding.js +100 -0
  141. package/esm/compute/orm/models/platformFunctionDefinition.d.ts +54 -0
  142. package/esm/compute/orm/models/platformFunctionDefinition.js +100 -0
  143. package/esm/compute/orm/models/platformFunctionDeployment.d.ts +54 -0
  144. package/esm/compute/orm/models/platformFunctionDeployment.js +100 -0
  145. package/esm/compute/orm/models/platformFunctionDeploymentEvent.d.ts +56 -0
  146. package/esm/compute/orm/models/platformFunctionDeploymentEvent.js +103 -0
  147. package/esm/compute/orm/models/platformFunctionExecutionLog.d.ts +56 -0
  148. package/esm/compute/orm/models/platformFunctionExecutionLog.js +103 -0
  149. package/esm/compute/orm/models/platformFunctionInvocation.d.ts +56 -0
  150. package/esm/compute/orm/models/platformFunctionInvocation.js +103 -0
  151. package/esm/compute/orm/models/platformResource.d.ts +54 -0
  152. package/esm/compute/orm/models/{secretDefinition.js → platformResource.js} +25 -25
  153. package/esm/compute/orm/models/platformResourceDefinition.d.ts +54 -0
  154. package/esm/compute/orm/models/platformResourceDefinition.js +100 -0
  155. package/esm/compute/orm/models/platformResourceEvent.d.ts +56 -0
  156. package/esm/compute/orm/models/{orgFunctionInvocation.js → platformResourceEvent.js} +25 -25
  157. package/esm/compute/orm/models/platformResourceStatusCheck.d.ts +54 -0
  158. package/esm/compute/orm/models/platformResourceStatusCheck.js +100 -0
  159. package/esm/compute/orm/models/platformResourcesRequirementsState.d.ts +30 -0
  160. package/esm/compute/orm/models/platformResourcesRequirementsState.js +55 -0
  161. package/esm/compute/orm/models/platformResourcesResolvedRequirement.d.ts +30 -0
  162. package/esm/compute/orm/models/platformResourcesResolvedRequirement.js +55 -0
  163. package/esm/compute/orm/models/resourceDefinition.d.ts +54 -0
  164. package/esm/{modules/orm/models/configSecretsOrgModule.js → compute/orm/models/resourceDefinition.js} +25 -25
  165. package/esm/compute/orm/models/resourceStatusCheck.d.ts +54 -0
  166. package/esm/compute/orm/models/resourceStatusCheck.js +100 -0
  167. package/esm/compute/orm/models/resourcesRequirementsState.d.ts +30 -0
  168. package/esm/compute/orm/models/resourcesRequirementsState.js +55 -0
  169. package/esm/compute/orm/models/resourcesResolvedRequirement.d.ts +30 -0
  170. package/esm/compute/orm/models/resourcesResolvedRequirement.js +55 -0
  171. package/esm/compute/orm/mutation/index.d.ts +33 -9
  172. package/esm/compute/orm/mutation/index.js +48 -12
  173. package/esm/config/orm/index.d.ts +42 -16
  174. package/esm/config/orm/index.js +8 -2
  175. package/esm/config/orm/input-types.d.ts +595 -154
  176. package/esm/config/orm/models/config.d.ts +54 -0
  177. package/esm/{modules/orm/models/configSecretsModule.js → config/orm/models/config.js} +25 -25
  178. package/esm/config/orm/models/index.d.ts +4 -1
  179. package/esm/config/orm/models/index.js +4 -1
  180. package/esm/config/orm/models/platformInternalSecret.d.ts +36 -0
  181. package/esm/config/orm/models/platformInternalSecret.js +76 -0
  182. package/esm/config/orm/models/platformSecret.d.ts +36 -0
  183. package/esm/config/orm/models/platformSecret.js +76 -0
  184. package/esm/config/orm/models/secret.d.ts +36 -0
  185. package/esm/config/orm/models/secret.js +76 -0
  186. package/esm/config/orm/mutation/index.d.ts +56 -24
  187. package/esm/config/orm/mutation/index.js +78 -30
  188. package/esm/index.d.ts +1 -0
  189. package/esm/index.js +1 -0
  190. package/esm/infra/index.d.ts +5 -0
  191. package/esm/infra/index.js +5 -0
  192. package/esm/infra/orm/client.d.ts +97 -0
  193. package/esm/infra/orm/client.js +145 -0
  194. package/esm/infra/orm/index.d.ts +74 -0
  195. package/esm/infra/orm/index.js +61 -0
  196. package/esm/infra/orm/input-types.d.ts +1953 -0
  197. package/esm/infra/orm/input-types.js +2 -0
  198. package/esm/infra/orm/models/dbPreset.d.ts +54 -0
  199. package/esm/infra/orm/models/dbPreset.js +100 -0
  200. package/esm/infra/orm/models/index.d.ts +15 -0
  201. package/esm/infra/orm/models/index.js +15 -0
  202. package/esm/infra/orm/models/infraCommit.d.ts +56 -0
  203. package/esm/infra/orm/models/infraCommit.js +103 -0
  204. package/esm/infra/orm/models/infraGetAllRecord.d.ts +30 -0
  205. package/esm/infra/orm/models/infraGetAllRecord.js +55 -0
  206. package/esm/infra/orm/models/infraObject.d.ts +56 -0
  207. package/esm/infra/orm/models/infraObject.js +93 -0
  208. package/esm/infra/orm/models/infraRef.d.ts +56 -0
  209. package/esm/infra/orm/models/infraRef.js +103 -0
  210. package/esm/infra/orm/models/infraStore.d.ts +54 -0
  211. package/esm/infra/orm/models/infraStore.js +100 -0
  212. package/esm/infra/orm/models/namespace.d.ts +54 -0
  213. package/esm/infra/orm/models/namespace.js +100 -0
  214. package/esm/infra/orm/models/namespaceEvent.d.ts +56 -0
  215. package/esm/infra/orm/models/namespaceEvent.js +103 -0
  216. package/esm/infra/orm/models/platformNamespace.d.ts +54 -0
  217. package/esm/{config/orm/models/platformConfigDefinition.js → infra/orm/models/platformNamespace.js} +25 -25
  218. package/esm/infra/orm/models/platformNamespaceEvent.d.ts +56 -0
  219. package/esm/infra/orm/models/platformNamespaceEvent.js +103 -0
  220. package/esm/infra/orm/mutation/index.d.ts +50 -0
  221. package/esm/infra/orm/mutation/index.js +54 -0
  222. package/esm/infra/orm/query-builder.d.ts +110 -0
  223. package/esm/infra/orm/query-builder.js +705 -0
  224. package/esm/infra/orm/realtime.d.ts +142 -0
  225. package/esm/infra/orm/realtime.js +100 -0
  226. package/esm/infra/orm/select-types.d.ts +125 -0
  227. package/esm/infra/orm/select-types.js +1 -0
  228. package/esm/infra/orm/types.d.ts +6 -0
  229. package/esm/infra/orm/types.js +7 -0
  230. package/esm/modules/orm/index.d.ts +48 -38
  231. package/esm/modules/orm/index.js +48 -38
  232. package/esm/modules/orm/input-types.d.ts +5378 -4022
  233. package/esm/modules/orm/input-types.js +1 -0
  234. package/esm/modules/orm/models/dbPool.d.ts +54 -0
  235. package/esm/modules/orm/models/dbPool.js +100 -0
  236. package/esm/modules/orm/models/dbPoolConfig.d.ts +54 -0
  237. package/esm/modules/orm/models/dbPoolConfig.js +100 -0
  238. package/esm/modules/orm/models/dbPresetModule.d.ts +54 -0
  239. package/esm/modules/orm/models/dbPresetModule.js +100 -0
  240. package/esm/modules/orm/models/index.d.ts +24 -19
  241. package/esm/modules/orm/models/index.js +24 -19
  242. package/esm/modules/orm/models/infraConfigModule.d.ts +54 -0
  243. package/esm/modules/orm/models/infraConfigModule.js +100 -0
  244. package/esm/modules/orm/models/infraSecretsModule.d.ts +54 -0
  245. package/esm/modules/orm/models/infraSecretsModule.js +100 -0
  246. package/esm/modules/orm/models/integrationProvidersModule.d.ts +54 -0
  247. package/esm/modules/orm/models/integrationProvidersModule.js +100 -0
  248. package/esm/modules/orm/models/internalSecretsModule.d.ts +54 -0
  249. package/esm/modules/orm/models/internalSecretsModule.js +100 -0
  250. package/index.d.ts +1 -0
  251. package/index.js +2 -1
  252. package/infra/index.d.ts +5 -0
  253. package/infra/index.js +21 -0
  254. package/infra/orm/client.d.ts +97 -0
  255. package/infra/orm/client.js +152 -0
  256. package/infra/orm/index.d.ts +74 -0
  257. package/infra/orm/index.js +83 -0
  258. package/infra/orm/input-types.d.ts +1953 -0
  259. package/infra/orm/input-types.js +5 -0
  260. package/infra/orm/models/dbPreset.d.ts +54 -0
  261. package/infra/orm/models/dbPreset.js +104 -0
  262. package/infra/orm/models/index.d.ts +15 -0
  263. package/infra/orm/models/index.js +28 -0
  264. package/infra/orm/models/infraCommit.d.ts +56 -0
  265. package/infra/orm/models/infraCommit.js +107 -0
  266. package/infra/orm/models/infraGetAllRecord.d.ts +30 -0
  267. package/infra/orm/models/infraGetAllRecord.js +59 -0
  268. package/infra/orm/models/infraObject.d.ts +56 -0
  269. package/infra/orm/models/infraObject.js +97 -0
  270. package/infra/orm/models/infraRef.d.ts +56 -0
  271. package/infra/orm/models/infraRef.js +107 -0
  272. package/infra/orm/models/infraStore.d.ts +54 -0
  273. package/infra/orm/models/infraStore.js +104 -0
  274. package/infra/orm/models/namespace.d.ts +54 -0
  275. package/infra/orm/models/namespace.js +104 -0
  276. package/infra/orm/models/namespaceEvent.d.ts +56 -0
  277. package/infra/orm/models/namespaceEvent.js +107 -0
  278. package/infra/orm/models/platformNamespace.d.ts +54 -0
  279. package/infra/orm/models/platformNamespace.js +104 -0
  280. package/infra/orm/models/platformNamespaceEvent.d.ts +56 -0
  281. package/{config/orm/models/platformConfigDefinition.js → infra/orm/models/platformNamespaceEvent.js} +30 -27
  282. package/infra/orm/mutation/index.d.ts +50 -0
  283. package/infra/orm/mutation/index.js +57 -0
  284. package/infra/orm/query-builder.d.ts +110 -0
  285. package/infra/orm/query-builder.js +757 -0
  286. package/infra/orm/realtime.d.ts +142 -0
  287. package/infra/orm/realtime.js +104 -0
  288. package/infra/orm/select-types.d.ts +125 -0
  289. package/infra/orm/select-types.js +2 -0
  290. package/infra/orm/types.d.ts +6 -0
  291. package/infra/orm/types.js +23 -0
  292. package/modules/orm/index.d.ts +48 -38
  293. package/modules/orm/index.js +48 -38
  294. package/modules/orm/input-types.d.ts +5378 -4022
  295. package/modules/orm/input-types.js +1 -0
  296. package/modules/orm/models/dbPool.d.ts +54 -0
  297. package/modules/orm/models/dbPool.js +104 -0
  298. package/modules/orm/models/dbPoolConfig.d.ts +54 -0
  299. package/modules/orm/models/dbPoolConfig.js +104 -0
  300. package/modules/orm/models/dbPresetModule.d.ts +54 -0
  301. package/modules/orm/models/dbPresetModule.js +104 -0
  302. package/modules/orm/models/index.d.ts +24 -19
  303. package/modules/orm/models/index.js +50 -40
  304. package/modules/orm/models/infraConfigModule.d.ts +54 -0
  305. package/modules/orm/models/infraConfigModule.js +104 -0
  306. package/modules/orm/models/infraSecretsModule.d.ts +54 -0
  307. package/modules/orm/models/infraSecretsModule.js +104 -0
  308. package/modules/orm/models/integrationProvidersModule.d.ts +54 -0
  309. package/modules/orm/models/integrationProvidersModule.js +104 -0
  310. package/modules/orm/models/internalSecretsModule.d.ts +54 -0
  311. package/modules/orm/models/internalSecretsModule.js +104 -0
  312. package/package.json +4 -4
  313. package/compute/orm/models/orgFunctionExecutionLog.d.ts +0 -56
  314. package/compute/orm/models/orgFunctionInvocation.d.ts +0 -56
  315. package/compute/orm/models/secretDefinition.d.ts +0 -54
  316. package/config/orm/models/platformConfigDefinition.d.ts +0 -54
  317. package/esm/compute/orm/models/orgFunctionExecutionLog.d.ts +0 -56
  318. package/esm/compute/orm/models/orgFunctionInvocation.d.ts +0 -56
  319. package/esm/compute/orm/models/secretDefinition.d.ts +0 -54
  320. package/esm/config/orm/models/platformConfigDefinition.d.ts +0 -54
  321. package/esm/modules/orm/models/configSecretsModule.d.ts +0 -54
  322. package/esm/modules/orm/models/configSecretsOrgModule.d.ts +0 -54
  323. package/modules/orm/models/configSecretsModule.d.ts +0 -54
  324. package/modules/orm/models/configSecretsOrgModule.d.ts +0 -54
@@ -0,0 +1,705 @@
1
+ /**
2
+ * Query Builder - Builds and executes GraphQL operations
3
+ * @generated by @constructive-io/graphql-codegen
4
+ * DO NOT EDIT - changes will be overwritten
5
+ */
6
+ import { parseType, print } from '@constructive-io/graphql-query/runtime';
7
+ import * as t from 'gql-ast';
8
+ import { GraphQLRequestError } from './client';
9
+ export class QueryBuilder {
10
+ config;
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ /**
15
+ * Execute the query and return a discriminated union result
16
+ * Use result.ok to check success, or .unwrap() to throw on error
17
+ */
18
+ async execute() {
19
+ const rawResult = await this.config.client.execute(this.config.document, this.config.variables);
20
+ if (!rawResult.ok) {
21
+ return rawResult;
22
+ }
23
+ if (!this.config.transform) {
24
+ return rawResult;
25
+ }
26
+ return {
27
+ ok: true,
28
+ data: this.config.transform(rawResult.data),
29
+ errors: undefined,
30
+ };
31
+ }
32
+ /**
33
+ * Execute and unwrap the result, throwing GraphQLRequestError on failure
34
+ * @throws {GraphQLRequestError} If the query returns errors
35
+ */
36
+ async unwrap() {
37
+ const result = await this.execute();
38
+ if (!result.ok) {
39
+ throw new GraphQLRequestError(result.errors, result.data);
40
+ }
41
+ return result.data;
42
+ }
43
+ /**
44
+ * Execute and unwrap, returning defaultValue on error instead of throwing
45
+ */
46
+ async unwrapOr(defaultValue) {
47
+ const result = await this.execute();
48
+ if (!result.ok) {
49
+ return defaultValue;
50
+ }
51
+ return result.data;
52
+ }
53
+ /**
54
+ * Execute and unwrap, calling onError callback on failure
55
+ */
56
+ async unwrapOrElse(onError) {
57
+ const result = await this.execute();
58
+ if (!result.ok) {
59
+ return onError(result.errors);
60
+ }
61
+ return result.data;
62
+ }
63
+ toGraphQL() {
64
+ return this.config.document;
65
+ }
66
+ getVariables() {
67
+ return this.config.variables;
68
+ }
69
+ }
70
+ const OP_QUERY = 'query';
71
+ const OP_MUTATION = 'mutation';
72
+ const ENUM_VALUE_KIND = 'EnumValue';
73
+ // ============================================================================
74
+ // Selection Builders
75
+ // ============================================================================
76
+ export function buildSelections(select, connectionFieldsMap, entityType) {
77
+ if (!select) {
78
+ return [];
79
+ }
80
+ const fields = [];
81
+ const entityConnections = entityType ? connectionFieldsMap?.[entityType] : undefined;
82
+ for (const [key, value] of Object.entries(select)) {
83
+ if (value === false || value === undefined) {
84
+ continue;
85
+ }
86
+ if (value === true) {
87
+ fields.push(t.field({ name: key }));
88
+ continue;
89
+ }
90
+ if (typeof value === 'object' && value !== null) {
91
+ const nested = value;
92
+ // Field with arguments (e.g. requestUploadUrl on bucket types)
93
+ if (nested.args && typeof nested.args === 'object') {
94
+ const fieldArgs = Object.entries(nested.args).map(([argName, argValue]) => t.argument({ name: argName, value: buildValueAst(argValue) }));
95
+ const nestedSelect = nested.select;
96
+ if (nestedSelect && typeof nestedSelect === 'object') {
97
+ const subSelections = Object.entries(nestedSelect)
98
+ .filter(([, v]) => v)
99
+ .map(([name]) => t.field({ name }));
100
+ fields.push(t.field({
101
+ name: key,
102
+ args: fieldArgs.length ? fieldArgs : undefined,
103
+ selectionSet: subSelections.length
104
+ ? t.selectionSet({ selections: subSelections })
105
+ : undefined,
106
+ }));
107
+ }
108
+ else {
109
+ fields.push(t.field({
110
+ name: key,
111
+ args: fieldArgs.length ? fieldArgs : undefined,
112
+ }));
113
+ }
114
+ continue;
115
+ }
116
+ if (!nested.select || typeof nested.select !== 'object') {
117
+ throw new Error(`Invalid selection for field "${key}": nested selections must include a "select" object.`);
118
+ }
119
+ const relatedEntityType = entityConnections?.[key];
120
+ const nestedSelections = buildSelections(nested.select, connectionFieldsMap, relatedEntityType);
121
+ const isConnection = nested.connection === true ||
122
+ nested.first !== undefined ||
123
+ nested.filter !== undefined ||
124
+ relatedEntityType !== undefined;
125
+ const args = buildArgs([
126
+ buildOptionalArg('first', nested.first),
127
+ nested.filter
128
+ ? t.argument({
129
+ name: 'filter',
130
+ value: buildValueAst(nested.filter),
131
+ })
132
+ : null,
133
+ buildEnumListArg('orderBy', nested.orderBy),
134
+ ]);
135
+ if (isConnection) {
136
+ fields.push(t.field({
137
+ name: key,
138
+ args,
139
+ selectionSet: t.selectionSet({
140
+ selections: buildConnectionSelections(nestedSelections),
141
+ }),
142
+ }));
143
+ }
144
+ else {
145
+ fields.push(t.field({
146
+ name: key,
147
+ args,
148
+ selectionSet: t.selectionSet({ selections: nestedSelections }),
149
+ }));
150
+ }
151
+ }
152
+ }
153
+ return fields;
154
+ }
155
+ // ============================================================================
156
+ // Document Builders
157
+ // ============================================================================
158
+ export function buildFindManyDocument(operationName, queryField, select, args, filterTypeName, orderByTypeName, connectionFieldsMap) {
159
+ const selections = select
160
+ ? buildSelections(select, connectionFieldsMap, operationName)
161
+ : [t.field({ name: 'id' })];
162
+ const variableDefinitions = [];
163
+ const queryArgs = [];
164
+ const variables = {};
165
+ addVariable({
166
+ varName: 'where',
167
+ typeName: filterTypeName,
168
+ value: args.where,
169
+ }, variableDefinitions, queryArgs, variables);
170
+ addVariable({
171
+ varName: 'orderBy',
172
+ typeName: '[' + orderByTypeName + '!]',
173
+ value: args.orderBy?.length ? args.orderBy : undefined,
174
+ }, variableDefinitions, queryArgs, variables);
175
+ addVariable({ varName: 'first', typeName: 'Int', value: args.first }, variableDefinitions, queryArgs, variables);
176
+ addVariable({ varName: 'last', typeName: 'Int', value: args.last }, variableDefinitions, queryArgs, variables);
177
+ addVariable({ varName: 'after', typeName: 'Cursor', value: args.after }, variableDefinitions, queryArgs, variables);
178
+ addVariable({ varName: 'before', typeName: 'Cursor', value: args.before }, variableDefinitions, queryArgs, variables);
179
+ addVariable({ varName: 'offset', typeName: 'Int', value: args.offset }, variableDefinitions, queryArgs, variables);
180
+ const document = t.document({
181
+ definitions: [
182
+ t.operationDefinition({
183
+ operation: OP_QUERY,
184
+ name: operationName + 'Query',
185
+ variableDefinitions: variableDefinitions.length ? variableDefinitions : undefined,
186
+ selectionSet: t.selectionSet({
187
+ selections: [
188
+ t.field({
189
+ name: queryField,
190
+ args: queryArgs.length ? queryArgs : undefined,
191
+ selectionSet: t.selectionSet({
192
+ selections: buildConnectionSelections(selections),
193
+ }),
194
+ }),
195
+ ],
196
+ }),
197
+ }),
198
+ ],
199
+ });
200
+ return { document: print(document), variables };
201
+ }
202
+ export function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName, orderByTypeName, connectionFieldsMap) {
203
+ const selections = select
204
+ ? buildSelections(select, connectionFieldsMap, operationName)
205
+ : [t.field({ name: 'id' })];
206
+ const variableDefinitions = [];
207
+ const queryArgs = [];
208
+ const variables = {};
209
+ // Always add first: 1 for findFirst
210
+ addVariable({ varName: 'first', typeName: 'Int', value: 1 }, variableDefinitions, queryArgs, variables);
211
+ addVariable({
212
+ varName: 'where',
213
+ typeName: filterTypeName,
214
+ value: args.where,
215
+ }, variableDefinitions, queryArgs, variables);
216
+ addVariable({
217
+ varName: 'orderBy',
218
+ typeName: '[' + orderByTypeName + '!]',
219
+ value: args.orderBy?.length ? args.orderBy : undefined,
220
+ }, variableDefinitions, queryArgs, variables);
221
+ const document = t.document({
222
+ definitions: [
223
+ t.operationDefinition({
224
+ operation: OP_QUERY,
225
+ name: operationName + 'Query',
226
+ variableDefinitions,
227
+ selectionSet: t.selectionSet({
228
+ selections: [
229
+ t.field({
230
+ name: queryField,
231
+ args: queryArgs,
232
+ selectionSet: t.selectionSet({
233
+ selections: [
234
+ t.field({
235
+ name: 'nodes',
236
+ selectionSet: t.selectionSet({ selections }),
237
+ }),
238
+ ],
239
+ }),
240
+ }),
241
+ ],
242
+ }),
243
+ }),
244
+ ],
245
+ });
246
+ return { document: print(document), variables };
247
+ }
248
+ export function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName, connectionFieldsMap) {
249
+ const selections = select
250
+ ? buildSelections(select, connectionFieldsMap, operationName)
251
+ : [t.field({ name: 'id' })];
252
+ return {
253
+ document: buildInputMutationDocument({
254
+ operationName,
255
+ mutationField,
256
+ inputTypeName,
257
+ resultSelections: [
258
+ t.field({
259
+ name: entityField,
260
+ selectionSet: t.selectionSet({ selections }),
261
+ }),
262
+ ],
263
+ }),
264
+ variables: {
265
+ input: {
266
+ [entityField]: data,
267
+ },
268
+ },
269
+ };
270
+ }
271
+ export function buildUpdateDocument(operationName, mutationField, entityField, select, where, data, inputTypeName, patchFieldName, connectionFieldsMap) {
272
+ const selections = select
273
+ ? buildSelections(select, connectionFieldsMap, operationName)
274
+ : [t.field({ name: 'id' })];
275
+ return {
276
+ document: buildInputMutationDocument({
277
+ operationName,
278
+ mutationField,
279
+ inputTypeName,
280
+ resultSelections: [
281
+ t.field({
282
+ name: entityField,
283
+ selectionSet: t.selectionSet({ selections }),
284
+ }),
285
+ ],
286
+ }),
287
+ variables: {
288
+ input: {
289
+ id: where.id,
290
+ [patchFieldName]: data,
291
+ },
292
+ },
293
+ };
294
+ }
295
+ export function buildUpdateByPkDocument(operationName, mutationField, entityField, select, id, data, inputTypeName, idFieldName, patchFieldName, connectionFieldsMap, extraKeys) {
296
+ const selections = select
297
+ ? buildSelections(select, connectionFieldsMap, operationName)
298
+ : [t.field({ name: 'id' })];
299
+ return {
300
+ document: buildInputMutationDocument({
301
+ operationName,
302
+ mutationField,
303
+ inputTypeName,
304
+ resultSelections: [
305
+ t.field({
306
+ name: entityField,
307
+ selectionSet: t.selectionSet({ selections }),
308
+ }),
309
+ ],
310
+ }),
311
+ variables: {
312
+ input: {
313
+ [idFieldName]: id,
314
+ ...extraKeys,
315
+ [patchFieldName]: data,
316
+ },
317
+ },
318
+ };
319
+ }
320
+ export function buildFindOneDocument(operationName, queryField, id, select, idArgName, idTypeName, connectionFieldsMap) {
321
+ const selections = select
322
+ ? buildSelections(select, connectionFieldsMap, operationName)
323
+ : [t.field({ name: 'id' })];
324
+ const variableDefinitions = [
325
+ t.variableDefinition({
326
+ variable: t.variable({ name: idArgName }),
327
+ type: parseType(idTypeName),
328
+ }),
329
+ ];
330
+ const queryArgs = [
331
+ t.argument({
332
+ name: idArgName,
333
+ value: t.variable({ name: idArgName }),
334
+ }),
335
+ ];
336
+ const document = t.document({
337
+ definitions: [
338
+ t.operationDefinition({
339
+ operation: OP_QUERY,
340
+ name: operationName + 'Query',
341
+ variableDefinitions,
342
+ selectionSet: t.selectionSet({
343
+ selections: [
344
+ t.field({
345
+ name: queryField,
346
+ args: queryArgs,
347
+ selectionSet: t.selectionSet({ selections }),
348
+ }),
349
+ ],
350
+ }),
351
+ }),
352
+ ],
353
+ });
354
+ return {
355
+ document: print(document),
356
+ variables: { [idArgName]: id },
357
+ };
358
+ }
359
+ export function buildDeleteDocument(operationName, mutationField, entityField, where, inputTypeName, select, connectionFieldsMap) {
360
+ const entitySelections = select
361
+ ? buildSelections(select, connectionFieldsMap, operationName)
362
+ : [t.field({ name: 'id' })];
363
+ return {
364
+ document: buildInputMutationDocument({
365
+ operationName,
366
+ mutationField,
367
+ inputTypeName,
368
+ resultSelections: [
369
+ t.field({
370
+ name: entityField,
371
+ selectionSet: t.selectionSet({
372
+ selections: entitySelections,
373
+ }),
374
+ }),
375
+ ],
376
+ }),
377
+ variables: {
378
+ input: {
379
+ id: where.id,
380
+ },
381
+ },
382
+ };
383
+ }
384
+ export function buildDeleteByPkDocument(operationName, mutationField, entityField, keys, inputTypeName, select, connectionFieldsMap) {
385
+ const entitySelections = select
386
+ ? buildSelections(select, connectionFieldsMap, operationName)
387
+ : [t.field({ name: 'id' })];
388
+ return {
389
+ document: buildInputMutationDocument({
390
+ operationName,
391
+ mutationField,
392
+ inputTypeName,
393
+ resultSelections: [
394
+ t.field({
395
+ name: entityField,
396
+ selectionSet: t.selectionSet({ selections: entitySelections }),
397
+ }),
398
+ ],
399
+ }),
400
+ variables: {
401
+ input: keys,
402
+ },
403
+ };
404
+ }
405
+ export function buildJunctionRemoveDocument(operationName, mutationField, keys, inputTypeName) {
406
+ return {
407
+ document: buildInputMutationDocument({
408
+ operationName,
409
+ mutationField,
410
+ inputTypeName,
411
+ resultSelections: [t.field({ name: 'clientMutationId' })],
412
+ }),
413
+ variables: {
414
+ input: keys,
415
+ },
416
+ };
417
+ }
418
+ export function buildCustomDocument(operationType, operationName, fieldName, select, args, variableDefinitions, connectionFieldsMap, entityType) {
419
+ let actualSelect = select;
420
+ let isConnection = false;
421
+ if (isCustomSelectionWrapper(select)) {
422
+ actualSelect = select.select;
423
+ isConnection = select.connection === true;
424
+ }
425
+ const selections = actualSelect
426
+ ? buildSelections(actualSelect, connectionFieldsMap, entityType)
427
+ : [];
428
+ const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
429
+ variable: t.variable({ name: definition.name }),
430
+ type: parseType(definition.type),
431
+ }));
432
+ const fieldArgs = variableDefinitions.map((definition) => t.argument({
433
+ name: definition.name,
434
+ value: t.variable({ name: definition.name }),
435
+ }));
436
+ const fieldSelections = isConnection ? buildConnectionSelections(selections) : selections;
437
+ const document = t.document({
438
+ definitions: [
439
+ t.operationDefinition({
440
+ operation: operationType === 'mutation' ? OP_MUTATION : OP_QUERY,
441
+ name: operationName,
442
+ variableDefinitions: variableDefs.length ? variableDefs : undefined,
443
+ selectionSet: t.selectionSet({
444
+ selections: [
445
+ t.field({
446
+ name: fieldName,
447
+ args: fieldArgs.length ? fieldArgs : undefined,
448
+ selectionSet: fieldSelections.length
449
+ ? t.selectionSet({ selections: fieldSelections })
450
+ : undefined,
451
+ }),
452
+ ],
453
+ }),
454
+ }),
455
+ ],
456
+ });
457
+ return {
458
+ document: print(document),
459
+ variables: (args ?? {}),
460
+ };
461
+ }
462
+ function isCustomSelectionWrapper(value) {
463
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
464
+ return false;
465
+ }
466
+ const record = value;
467
+ const keys = Object.keys(record);
468
+ if (!keys.includes('select') || !keys.includes('connection')) {
469
+ return false;
470
+ }
471
+ if (keys.some((key) => key !== 'select' && key !== 'connection')) {
472
+ return false;
473
+ }
474
+ return !!record.select && typeof record.select === 'object' && !Array.isArray(record.select);
475
+ }
476
+ // ============================================================================
477
+ // Helper Functions
478
+ // ============================================================================
479
+ function buildArgs(args) {
480
+ return args.filter((arg) => arg !== null);
481
+ }
482
+ function buildOptionalArg(name, value) {
483
+ if (value === undefined) {
484
+ return null;
485
+ }
486
+ const valueNode = typeof value === 'number' ? t.intValue({ value: value.toString() }) : t.stringValue({ value });
487
+ return t.argument({ name, value: valueNode });
488
+ }
489
+ function buildEnumListArg(name, values) {
490
+ if (!values || values.length === 0) {
491
+ return null;
492
+ }
493
+ return t.argument({
494
+ name,
495
+ value: t.listValue({
496
+ values: values.map((value) => buildEnumValue(value)),
497
+ }),
498
+ });
499
+ }
500
+ function buildEnumValue(value) {
501
+ return {
502
+ kind: ENUM_VALUE_KIND,
503
+ value,
504
+ };
505
+ }
506
+ function buildPageInfoSelections() {
507
+ return [
508
+ t.field({ name: 'hasNextPage' }),
509
+ t.field({ name: 'hasPreviousPage' }),
510
+ t.field({ name: 'startCursor' }),
511
+ t.field({ name: 'endCursor' }),
512
+ ];
513
+ }
514
+ function buildConnectionSelections(nodeSelections) {
515
+ return [
516
+ t.field({
517
+ name: 'nodes',
518
+ selectionSet: t.selectionSet({ selections: nodeSelections }),
519
+ }),
520
+ t.field({ name: 'totalCount' }),
521
+ t.field({
522
+ name: 'pageInfo',
523
+ selectionSet: t.selectionSet({ selections: buildPageInfoSelections() }),
524
+ }),
525
+ ];
526
+ }
527
+ function buildInputMutationDocument(config) {
528
+ const document = t.document({
529
+ definitions: [
530
+ t.operationDefinition({
531
+ operation: OP_MUTATION,
532
+ name: config.operationName + 'Mutation',
533
+ variableDefinitions: [
534
+ t.variableDefinition({
535
+ variable: t.variable({ name: 'input' }),
536
+ type: parseType(config.inputTypeName + '!'),
537
+ }),
538
+ ],
539
+ selectionSet: t.selectionSet({
540
+ selections: [
541
+ t.field({
542
+ name: config.mutationField,
543
+ args: [
544
+ t.argument({
545
+ name: 'input',
546
+ value: t.variable({ name: 'input' }),
547
+ }),
548
+ ],
549
+ selectionSet: t.selectionSet({
550
+ selections: config.resultSelections,
551
+ }),
552
+ }),
553
+ ],
554
+ }),
555
+ }),
556
+ ],
557
+ });
558
+ return print(document);
559
+ }
560
+ function addVariable(spec, definitions, args, variables) {
561
+ if (spec.value === undefined || !spec.typeName)
562
+ return;
563
+ definitions.push(t.variableDefinition({
564
+ variable: t.variable({ name: spec.varName }),
565
+ type: parseType(spec.typeName),
566
+ }));
567
+ args.push(t.argument({
568
+ name: spec.argName ?? spec.varName,
569
+ value: t.variable({ name: spec.varName }),
570
+ }));
571
+ variables[spec.varName] = spec.value;
572
+ }
573
+ function buildValueAst(value) {
574
+ if (value === null) {
575
+ return t.nullValue();
576
+ }
577
+ if (typeof value === 'boolean') {
578
+ return t.booleanValue({ value });
579
+ }
580
+ if (typeof value === 'number') {
581
+ return Number.isInteger(value)
582
+ ? t.intValue({ value: value.toString() })
583
+ : t.floatValue({ value: value.toString() });
584
+ }
585
+ if (typeof value === 'string') {
586
+ return t.stringValue({ value });
587
+ }
588
+ if (Array.isArray(value)) {
589
+ return t.listValue({
590
+ values: value.map((item) => buildValueAst(item)),
591
+ });
592
+ }
593
+ if (typeof value === 'object' && value !== null) {
594
+ const obj = value;
595
+ return t.objectValue({
596
+ fields: Object.entries(obj).map(([key, val]) => t.objectField({
597
+ name: key,
598
+ value: buildValueAst(val),
599
+ })),
600
+ });
601
+ }
602
+ throw new Error('Unsupported value type: ' + typeof value);
603
+ }
604
+ // ============================================================================
605
+ // Bulk Mutation Document Builders
606
+ // ============================================================================
607
+ export function buildBulkInsertDocument(operationName, mutationField, select, data, inputTypeName, onConflict, connectionFieldsMap) {
608
+ const selections = select
609
+ ? buildSelections(select, connectionFieldsMap, operationName)
610
+ : [t.field({ name: 'id' })];
611
+ return {
612
+ document: buildInputMutationDocument({
613
+ operationName,
614
+ mutationField,
615
+ inputTypeName,
616
+ resultSelections: [
617
+ t.field({ name: 'affectedCount' }),
618
+ t.field({
619
+ name: 'returning',
620
+ selectionSet: t.selectionSet({ selections }),
621
+ }),
622
+ ],
623
+ }),
624
+ variables: {
625
+ input: {
626
+ values: data,
627
+ ...(onConflict ? { onConflict } : {}),
628
+ },
629
+ },
630
+ };
631
+ }
632
+ export function buildBulkUpsertDocument(operationName, mutationField, select, data, inputTypeName, onConflict, connectionFieldsMap) {
633
+ const selections = select
634
+ ? buildSelections(select, connectionFieldsMap, operationName)
635
+ : [t.field({ name: 'id' })];
636
+ return {
637
+ document: buildInputMutationDocument({
638
+ operationName,
639
+ mutationField,
640
+ inputTypeName,
641
+ resultSelections: [
642
+ t.field({ name: 'affectedCount' }),
643
+ t.field({
644
+ name: 'returning',
645
+ selectionSet: t.selectionSet({ selections }),
646
+ }),
647
+ ],
648
+ }),
649
+ variables: {
650
+ input: {
651
+ values: data,
652
+ onConflict,
653
+ },
654
+ },
655
+ };
656
+ }
657
+ export function buildBulkUpdateDocument(operationName, mutationField, select, where, data, inputTypeName, connectionFieldsMap) {
658
+ const selections = select
659
+ ? buildSelections(select, connectionFieldsMap, operationName)
660
+ : [t.field({ name: 'id' })];
661
+ return {
662
+ document: buildInputMutationDocument({
663
+ operationName,
664
+ mutationField,
665
+ inputTypeName,
666
+ resultSelections: [
667
+ t.field({ name: 'affectedCount' }),
668
+ t.field({
669
+ name: 'returning',
670
+ selectionSet: t.selectionSet({ selections }),
671
+ }),
672
+ ],
673
+ }),
674
+ variables: {
675
+ input: {
676
+ where,
677
+ patch: data,
678
+ },
679
+ },
680
+ };
681
+ }
682
+ export function buildBulkDeleteDocument(operationName, mutationField, select, where, inputTypeName, connectionFieldsMap) {
683
+ const selections = select
684
+ ? buildSelections(select, connectionFieldsMap, operationName)
685
+ : [t.field({ name: 'id' })];
686
+ return {
687
+ document: buildInputMutationDocument({
688
+ operationName,
689
+ mutationField,
690
+ inputTypeName,
691
+ resultSelections: [
692
+ t.field({ name: 'affectedCount' }),
693
+ t.field({
694
+ name: 'returning',
695
+ selectionSet: t.selectionSet({ selections }),
696
+ }),
697
+ ],
698
+ }),
699
+ variables: {
700
+ input: {
701
+ where,
702
+ },
703
+ },
704
+ };
705
+ }