@powerhousedao/builder-tools 6.0.0-dev.8 → 6.0.0-dev.81

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 (342) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/connect-utils/helpers.d.ts +1 -1
  4. package/dist/connect-utils/helpers.d.ts.map +1 -1
  5. package/dist/connect-utils/index.d.ts +0 -1
  6. package/dist/connect-utils/index.d.ts.map +1 -1
  7. package/dist/connect-utils/types.d.ts +0 -1
  8. package/dist/connect-utils/types.d.ts.map +1 -1
  9. package/dist/connect-utils/vite-config.d.ts.map +1 -1
  10. package/dist/index.d.ts +0 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +111925 -4
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/package.json +20 -114
  15. package/dist/browser.d.ts +0 -2
  16. package/dist/browser.d.ts.map +0 -1
  17. package/dist/browser.js +0 -2
  18. package/dist/browser.js.map +0 -1
  19. package/dist/connect-build/build.d.ts +0 -6
  20. package/dist/connect-build/build.d.ts.map +0 -1
  21. package/dist/connect-build/build.js +0 -54
  22. package/dist/connect-build/build.js.map +0 -1
  23. package/dist/connect-build/constants.d.ts +0 -11
  24. package/dist/connect-build/constants.d.ts.map +0 -1
  25. package/dist/connect-build/constants.js +0 -11
  26. package/dist/connect-build/constants.js.map +0 -1
  27. package/dist/connect-build/helpers.d.ts +0 -37
  28. package/dist/connect-build/helpers.d.ts.map +0 -1
  29. package/dist/connect-build/helpers.js +0 -111
  30. package/dist/connect-build/helpers.js.map +0 -1
  31. package/dist/connect-build/index.d.ts +0 -5
  32. package/dist/connect-build/index.d.ts.map +0 -1
  33. package/dist/connect-build/index.js +0 -4
  34. package/dist/connect-build/index.js.map +0 -1
  35. package/dist/connect-build/preview.d.ts +0 -3
  36. package/dist/connect-build/preview.d.ts.map +0 -1
  37. package/dist/connect-build/preview.js +0 -19
  38. package/dist/connect-build/preview.js.map +0 -1
  39. package/dist/connect-build/types.d.ts +0 -27
  40. package/dist/connect-build/types.d.ts.map +0 -1
  41. package/dist/connect-build/types.js +0 -2
  42. package/dist/connect-build/types.js.map +0 -1
  43. package/dist/connect-studio/index.d.ts +0 -3
  44. package/dist/connect-studio/index.d.ts.map +0 -1
  45. package/dist/connect-studio/index.js +0 -2
  46. package/dist/connect-studio/index.js.map +0 -1
  47. package/dist/connect-studio/server.d.ts +0 -3
  48. package/dist/connect-studio/server.d.ts.map +0 -1
  49. package/dist/connect-studio/server.js +0 -234
  50. package/dist/connect-studio/server.js.map +0 -1
  51. package/dist/connect-studio/studio.d.ts +0 -3
  52. package/dist/connect-studio/studio.d.ts.map +0 -1
  53. package/dist/connect-studio/studio.js +0 -66
  54. package/dist/connect-studio/studio.js.map +0 -1
  55. package/dist/connect-studio/types.d.ts +0 -28
  56. package/dist/connect-studio/types.d.ts.map +0 -1
  57. package/dist/connect-studio/types.js +0 -2
  58. package/dist/connect-studio/types.js.map +0 -1
  59. package/dist/connect-utils/build.js +0 -21
  60. package/dist/connect-utils/build.js.map +0 -1
  61. package/dist/connect-utils/constants.js +0 -5
  62. package/dist/connect-utils/constants.js.map +0 -1
  63. package/dist/connect-utils/env-config.d.ts +0 -844
  64. package/dist/connect-utils/env-config.d.ts.map +0 -1
  65. package/dist/connect-utils/env-config.js +0 -518
  66. package/dist/connect-utils/env-config.js.map +0 -1
  67. package/dist/connect-utils/helpers.js +0 -265
  68. package/dist/connect-utils/helpers.js.map +0 -1
  69. package/dist/connect-utils/index.js +0 -16
  70. package/dist/connect-utils/index.js.map +0 -1
  71. package/dist/connect-utils/preview.js +0 -33
  72. package/dist/connect-utils/preview.js.map +0 -1
  73. package/dist/connect-utils/studio.js +0 -30
  74. package/dist/connect-utils/studio.js.map +0 -1
  75. package/dist/connect-utils/types.js +0 -2
  76. package/dist/connect-utils/types.js.map +0 -1
  77. package/dist/connect-utils/vite-config.js +0 -267
  78. package/dist/connect-utils/vite-config.js.map +0 -1
  79. package/dist/connect-utils/vite-plugins/base.js +0 -130
  80. package/dist/connect-utils/vite-plugins/base.js.map +0 -1
  81. package/dist/connect-utils/vite-plugins/document-models-hmr.js +0 -62
  82. package/dist/connect-utils/vite-plugins/document-models-hmr.js.map +0 -1
  83. package/dist/connect-utils/vite-plugins/editors-hmr.js +0 -61
  84. package/dist/connect-utils/vite-plugins/editors-hmr.js.map +0 -1
  85. package/dist/connect-utils/vite-plugins/external-packages.js +0 -127
  86. package/dist/connect-utils/vite-plugins/external-packages.js.map +0 -1
  87. package/dist/connect-utils/vite-plugins/importmap.js +0 -243
  88. package/dist/connect-utils/vite-plugins/importmap.js.map +0 -1
  89. package/dist/connect-utils/vite-plugins/ph-external-packages.js +0 -88
  90. package/dist/connect-utils/vite-plugins/ph-external-packages.js.map +0 -1
  91. package/dist/connect-utils/vite-plugins/studio.js +0 -33
  92. package/dist/connect-utils/vite-plugins/studio.js.map +0 -1
  93. package/dist/document-model-editor/components/button.d.ts +0 -2
  94. package/dist/document-model-editor/components/button.d.ts.map +0 -1
  95. package/dist/document-model-editor/components/button.js +0 -8
  96. package/dist/document-model-editor/components/button.js.map +0 -1
  97. package/dist/document-model-editor/components/code-editors/constants.d.ts +0 -3
  98. package/dist/document-model-editor/components/code-editors/constants.d.ts.map +0 -1
  99. package/dist/document-model-editor/components/code-editors/constants.js +0 -38
  100. package/dist/document-model-editor/components/code-editors/constants.js.map +0 -1
  101. package/dist/document-model-editor/components/code-editors/factories.d.ts +0 -4
  102. package/dist/document-model-editor/components/code-editors/factories.d.ts.map +0 -1
  103. package/dist/document-model-editor/components/code-editors/factories.js +0 -47
  104. package/dist/document-model-editor/components/code-editors/factories.js.map +0 -1
  105. package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts +0 -10
  106. package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts.map +0 -1
  107. package/dist/document-model-editor/components/code-editors/graphql-editor.js +0 -73
  108. package/dist/document-model-editor/components/code-editors/graphql-editor.js.map +0 -1
  109. package/dist/document-model-editor/components/code-editors/hooks.d.ts +0 -23
  110. package/dist/document-model-editor/components/code-editors/hooks.d.ts.map +0 -1
  111. package/dist/document-model-editor/components/code-editors/hooks.js +0 -59
  112. package/dist/document-model-editor/components/code-editors/hooks.js.map +0 -1
  113. package/dist/document-model-editor/components/code-editors/json-editor.d.ts +0 -8
  114. package/dist/document-model-editor/components/code-editors/json-editor.d.ts.map +0 -1
  115. package/dist/document-model-editor/components/code-editors/json-editor.js +0 -47
  116. package/dist/document-model-editor/components/code-editors/json-editor.js.map +0 -1
  117. package/dist/document-model-editor/components/code-editors/linting.d.ts +0 -6
  118. package/dist/document-model-editor/components/code-editors/linting.d.ts.map +0 -1
  119. package/dist/document-model-editor/components/code-editors/linting.js +0 -59
  120. package/dist/document-model-editor/components/code-editors/linting.js.map +0 -1
  121. package/dist/document-model-editor/components/divider.d.ts +0 -8
  122. package/dist/document-model-editor/components/divider.d.ts.map +0 -1
  123. package/dist/document-model-editor/components/divider.js +0 -22
  124. package/dist/document-model-editor/components/divider.js.map +0 -1
  125. package/dist/document-model-editor/components/errors.d.ts +0 -6
  126. package/dist/document-model-editor/components/errors.d.ts.map +0 -1
  127. package/dist/document-model-editor/components/errors.js +0 -5
  128. package/dist/document-model-editor/components/errors.js.map +0 -1
  129. package/dist/document-model-editor/components/form.d.ts +0 -12
  130. package/dist/document-model-editor/components/form.d.ts.map +0 -1
  131. package/dist/document-model-editor/components/form.js +0 -43
  132. package/dist/document-model-editor/components/form.js.map +0 -1
  133. package/dist/document-model-editor/components/input.d.ts +0 -6
  134. package/dist/document-model-editor/components/input.d.ts.map +0 -1
  135. package/dist/document-model-editor/components/input.js +0 -9
  136. package/dist/document-model-editor/components/input.js.map +0 -1
  137. package/dist/document-model-editor/components/label.d.ts +0 -6
  138. package/dist/document-model-editor/components/label.d.ts.map +0 -1
  139. package/dist/document-model-editor/components/label.js +0 -10
  140. package/dist/document-model-editor/components/label.js.map +0 -1
  141. package/dist/document-model-editor/components/model-metadata-form.d.ts +0 -31
  142. package/dist/document-model-editor/components/model-metadata-form.d.ts.map +0 -1
  143. package/dist/document-model-editor/components/model-metadata-form.js +0 -70
  144. package/dist/document-model-editor/components/model-metadata-form.js.map +0 -1
  145. package/dist/document-model-editor/components/module-form.d.ts +0 -10
  146. package/dist/document-model-editor/components/module-form.d.ts.map +0 -1
  147. package/dist/document-model-editor/components/module-form.js +0 -22
  148. package/dist/document-model-editor/components/module-form.js.map +0 -1
  149. package/dist/document-model-editor/components/module.d.ts +0 -22
  150. package/dist/document-model-editor/components/module.d.ts.map +0 -1
  151. package/dist/document-model-editor/components/module.js +0 -10
  152. package/dist/document-model-editor/components/module.js.map +0 -1
  153. package/dist/document-model-editor/components/modules.d.ts +0 -20
  154. package/dist/document-model-editor/components/modules.d.ts.map +0 -1
  155. package/dist/document-model-editor/components/modules.js +0 -17
  156. package/dist/document-model-editor/components/modules.js.map +0 -1
  157. package/dist/document-model-editor/components/operation-description-form.d.ts +0 -9
  158. package/dist/document-model-editor/components/operation-description-form.d.ts.map +0 -1
  159. package/dist/document-model-editor/components/operation-description-form.js +0 -13
  160. package/dist/document-model-editor/components/operation-description-form.js.map +0 -1
  161. package/dist/document-model-editor/components/operation-error-form.d.ts +0 -13
  162. package/dist/document-model-editor/components/operation-error-form.d.ts.map +0 -1
  163. package/dist/document-model-editor/components/operation-error-form.js +0 -40
  164. package/dist/document-model-editor/components/operation-error-form.js.map +0 -1
  165. package/dist/document-model-editor/components/operation-errors.d.ts +0 -10
  166. package/dist/document-model-editor/components/operation-errors.d.ts.map +0 -1
  167. package/dist/document-model-editor/components/operation-errors.js +0 -17
  168. package/dist/document-model-editor/components/operation-errors.js.map +0 -1
  169. package/dist/document-model-editor/components/operation-form.d.ts +0 -13
  170. package/dist/document-model-editor/components/operation-form.d.ts.map +0 -1
  171. package/dist/document-model-editor/components/operation-form.js +0 -37
  172. package/dist/document-model-editor/components/operation-form.js.map +0 -1
  173. package/dist/document-model-editor/components/operation.d.ts +0 -23
  174. package/dist/document-model-editor/components/operation.d.ts.map +0 -1
  175. package/dist/document-model-editor/components/operation.js +0 -25
  176. package/dist/document-model-editor/components/operation.js.map +0 -1
  177. package/dist/document-model-editor/components/operations.d.ts +0 -18
  178. package/dist/document-model-editor/components/operations.d.ts.map +0 -1
  179. package/dist/document-model-editor/components/operations.js +0 -20
  180. package/dist/document-model-editor/components/operations.js.map +0 -1
  181. package/dist/document-model-editor/components/state-error.d.ts +0 -5
  182. package/dist/document-model-editor/components/state-error.d.ts.map +0 -1
  183. package/dist/document-model-editor/components/state-error.js +0 -21
  184. package/dist/document-model-editor/components/state-error.js.map +0 -1
  185. package/dist/document-model-editor/components/state-schemas.d.ts +0 -15
  186. package/dist/document-model-editor/components/state-schemas.d.ts.map +0 -1
  187. package/dist/document-model-editor/components/state-schemas.js +0 -81
  188. package/dist/document-model-editor/components/state-schemas.js.map +0 -1
  189. package/dist/document-model-editor/components/tabs.d.ts +0 -8
  190. package/dist/document-model-editor/components/tabs.d.ts.map +0 -1
  191. package/dist/document-model-editor/components/tabs.js +0 -13
  192. package/dist/document-model-editor/components/tabs.js.map +0 -1
  193. package/dist/document-model-editor/components/text-area.d.ts +0 -9
  194. package/dist/document-model-editor/components/text-area.d.ts.map +0 -1
  195. package/dist/document-model-editor/components/text-area.js +0 -27
  196. package/dist/document-model-editor/components/text-area.js.map +0 -1
  197. package/dist/document-model-editor/components/text-field.d.ts +0 -21
  198. package/dist/document-model-editor/components/text-field.d.ts.map +0 -1
  199. package/dist/document-model-editor/components/text-field.js +0 -80
  200. package/dist/document-model-editor/components/text-field.js.map +0 -1
  201. package/dist/document-model-editor/config.d.ts +0 -3
  202. package/dist/document-model-editor/config.d.ts.map +0 -1
  203. package/dist/document-model-editor/config.js +0 -4
  204. package/dist/document-model-editor/config.js.map +0 -1
  205. package/dist/document-model-editor/constants/documents.d.ts +0 -13
  206. package/dist/document-model-editor/constants/documents.d.ts.map +0 -1
  207. package/dist/document-model-editor/constants/documents.js +0 -18
  208. package/dist/document-model-editor/constants/documents.js.map +0 -1
  209. package/dist/document-model-editor/constants/graphql-kinds.d.ts +0 -9
  210. package/dist/document-model-editor/constants/graphql-kinds.d.ts.map +0 -1
  211. package/dist/document-model-editor/constants/graphql-kinds.js +0 -13
  212. package/dist/document-model-editor/constants/graphql-kinds.js.map +0 -1
  213. package/dist/document-model-editor/context/form-context.d.ts +0 -11
  214. package/dist/document-model-editor/context/form-context.d.ts.map +0 -1
  215. package/dist/document-model-editor/context/form-context.js +0 -4
  216. package/dist/document-model-editor/context/form-context.js.map +0 -1
  217. package/dist/document-model-editor/context/schema-context.d.ts +0 -18
  218. package/dist/document-model-editor/context/schema-context.d.ts.map +0 -1
  219. package/dist/document-model-editor/context/schema-context.js +0 -129
  220. package/dist/document-model-editor/context/schema-context.js.map +0 -1
  221. package/dist/document-model-editor/document-model-editor.stories.d.ts +0 -8
  222. package/dist/document-model-editor/document-model-editor.stories.d.ts.map +0 -1
  223. package/dist/document-model-editor/document-model-editor.stories.js +0 -267
  224. package/dist/document-model-editor/document-model-editor.stories.js.map +0 -1
  225. package/dist/document-model-editor/editor.d.ts +0 -2
  226. package/dist/document-model-editor/editor.d.ts.map +0 -1
  227. package/dist/document-model-editor/editor.js +0 -217
  228. package/dist/document-model-editor/editor.js.map +0 -1
  229. package/dist/document-model-editor/hooks/index.d.ts +0 -3
  230. package/dist/document-model-editor/hooks/index.d.ts.map +0 -1
  231. package/dist/document-model-editor/hooks/index.js +0 -3
  232. package/dist/document-model-editor/hooks/index.js.map +0 -1
  233. package/dist/document-model-editor/hooks/useDocumentModelDocument.d.ts +0 -5
  234. package/dist/document-model-editor/hooks/useDocumentModelDocument.d.ts.map +0 -1
  235. package/dist/document-model-editor/hooks/useDocumentModelDocument.js +0 -8
  236. package/dist/document-model-editor/hooks/useDocumentModelDocument.js.map +0 -1
  237. package/dist/document-model-editor/hooks/useFormField.d.ts +0 -13
  238. package/dist/document-model-editor/hooks/useFormField.d.ts.map +0 -1
  239. package/dist/document-model-editor/hooks/useFormField.js +0 -22
  240. package/dist/document-model-editor/hooks/useFormField.js.map +0 -1
  241. package/dist/document-model-editor/index.d.ts +0 -2
  242. package/dist/document-model-editor/index.d.ts.map +0 -1
  243. package/dist/document-model-editor/index.js +0 -2
  244. package/dist/document-model-editor/index.js.map +0 -1
  245. package/dist/document-model-editor/module.d.ts +0 -3
  246. package/dist/document-model-editor/module.d.ts.map +0 -1
  247. package/dist/document-model-editor/module.js +0 -10
  248. package/dist/document-model-editor/module.js.map +0 -1
  249. package/dist/document-model-editor/schemas/inputs.d.ts +0 -25
  250. package/dist/document-model-editor/schemas/inputs.d.ts.map +0 -1
  251. package/dist/document-model-editor/schemas/inputs.js +0 -71
  252. package/dist/document-model-editor/schemas/inputs.js.map +0 -1
  253. package/dist/document-model-editor/schemas/utils.d.ts +0 -3
  254. package/dist/document-model-editor/schemas/utils.d.ts.map +0 -1
  255. package/dist/document-model-editor/schemas/utils.js +0 -3
  256. package/dist/document-model-editor/schemas/utils.js.map +0 -1
  257. package/dist/document-model-editor/types/documents.d.ts +0 -26
  258. package/dist/document-model-editor/types/documents.d.ts.map +0 -1
  259. package/dist/document-model-editor/types/documents.js +0 -2
  260. package/dist/document-model-editor/types/documents.js.map +0 -1
  261. package/dist/document-model-editor/types.d.ts +0 -2
  262. package/dist/document-model-editor/types.d.ts.map +0 -1
  263. package/dist/document-model-editor/types.js +0 -2
  264. package/dist/document-model-editor/types.js.map +0 -1
  265. package/dist/document-model-editor/utils/helpers.d.ts +0 -112
  266. package/dist/document-model-editor/utils/helpers.d.ts.map +0 -1
  267. package/dist/document-model-editor/utils/helpers.js +0 -920
  268. package/dist/document-model-editor/utils/helpers.js.map +0 -1
  269. package/dist/document-model-editor/utils/linting.d.ts +0 -7
  270. package/dist/document-model-editor/utils/linting.d.ts.map +0 -1
  271. package/dist/document-model-editor/utils/linting.js +0 -49
  272. package/dist/document-model-editor/utils/linting.js.map +0 -1
  273. package/dist/document-model-editor/utils/style.d.ts +0 -3
  274. package/dist/document-model-editor/utils/style.d.ts.map +0 -1
  275. package/dist/document-model-editor/utils/style.js +0 -6
  276. package/dist/document-model-editor/utils/style.js.map +0 -1
  277. package/dist/editor-utils/components/documentEditor.d.ts +0 -7
  278. package/dist/editor-utils/components/documentEditor.d.ts.map +0 -1
  279. package/dist/editor-utils/components/documentEditor.js +0 -6
  280. package/dist/editor-utils/components/documentEditor.js.map +0 -1
  281. package/dist/editor-utils/components/editorToolbar.d.ts +0 -11
  282. package/dist/editor-utils/components/editorToolbar.d.ts.map +0 -1
  283. package/dist/editor-utils/components/editorToolbar.js +0 -6
  284. package/dist/editor-utils/components/editorToolbar.js.map +0 -1
  285. package/dist/editor-utils/components/editorWorksheet.d.ts +0 -7
  286. package/dist/editor-utils/components/editorWorksheet.d.ts.map +0 -1
  287. package/dist/editor-utils/components/editorWorksheet.js +0 -5
  288. package/dist/editor-utils/components/editorWorksheet.js.map +0 -1
  289. package/dist/editor-utils/components/index.d.ts +0 -9
  290. package/dist/editor-utils/components/index.d.ts.map +0 -1
  291. package/dist/editor-utils/components/index.js +0 -10
  292. package/dist/editor-utils/components/index.js.map +0 -1
  293. package/dist/editor-utils/components/styles.d.ts +0 -40
  294. package/dist/editor-utils/components/styles.d.ts.map +0 -1
  295. package/dist/editor-utils/components/styles.js +0 -79
  296. package/dist/editor-utils/components/styles.js.map +0 -1
  297. package/dist/editor-utils/components/stylesVariant.d.ts +0 -40
  298. package/dist/editor-utils/components/stylesVariant.d.ts.map +0 -1
  299. package/dist/editor-utils/components/stylesVariant.js +0 -89
  300. package/dist/editor-utils/components/stylesVariant.js.map +0 -1
  301. package/dist/editor-utils/components/textInput.d.ts +0 -20
  302. package/dist/editor-utils/components/textInput.d.ts.map +0 -1
  303. package/dist/editor-utils/components/textInput.js +0 -84
  304. package/dist/editor-utils/components/textInput.js.map +0 -1
  305. package/dist/editor-utils/components/textInputVariant.d.ts +0 -21
  306. package/dist/editor-utils/components/textInputVariant.d.ts.map +0 -1
  307. package/dist/editor-utils/components/textInputVariant.js +0 -93
  308. package/dist/editor-utils/components/textInputVariant.js.map +0 -1
  309. package/dist/editor-utils/components/toolbarButton.d.ts +0 -7
  310. package/dist/editor-utils/components/toolbarButton.d.ts.map +0 -1
  311. package/dist/editor-utils/components/toolbarButton.js +0 -9
  312. package/dist/editor-utils/components/toolbarButton.js.map +0 -1
  313. package/dist/editor-utils/hooks/index.d.ts +0 -2
  314. package/dist/editor-utils/hooks/index.d.ts.map +0 -1
  315. package/dist/editor-utils/hooks/index.js +0 -2
  316. package/dist/editor-utils/hooks/index.js.map +0 -1
  317. package/dist/editor-utils/hooks/useEnsInfo.d.ts +0 -15
  318. package/dist/editor-utils/hooks/useEnsInfo.d.ts.map +0 -1
  319. package/dist/editor-utils/hooks/useEnsInfo.js +0 -64
  320. package/dist/editor-utils/hooks/useEnsInfo.js.map +0 -1
  321. package/dist/editor-utils/index.d.ts +0 -5
  322. package/dist/editor-utils/index.d.ts.map +0 -1
  323. package/dist/editor-utils/index.js +0 -5
  324. package/dist/editor-utils/index.js.map +0 -1
  325. package/dist/editor-utils/reducer.d.ts +0 -3
  326. package/dist/editor-utils/reducer.d.ts.map +0 -1
  327. package/dist/editor-utils/reducer.js +0 -25
  328. package/dist/editor-utils/reducer.js.map +0 -1
  329. package/dist/editor-utils/storybook.d.ts +0 -32
  330. package/dist/editor-utils/storybook.d.ts.map +0 -1
  331. package/dist/editor-utils/storybook.js +0 -104
  332. package/dist/editor-utils/storybook.js.map +0 -1
  333. package/dist/index.js.map +0 -1
  334. package/dist/style.css +0 -890
  335. package/dist/test/helpers.test.d.ts +0 -2
  336. package/dist/test/helpers.test.d.ts.map +0 -1
  337. package/dist/test/helpers.test.js +0 -805
  338. package/dist/test/helpers.test.js.map +0 -1
  339. package/dist/test/index.d.ts +0 -2
  340. package/dist/test/index.d.ts.map +0 -1
  341. package/dist/test/index.js +0 -2
  342. package/dist/test/index.js.map +0 -1
@@ -1,920 +0,0 @@
1
- import { getPHCustomScalarByTypeName } from "@powerhousedao/document-engineering/graphql";
2
- import { pascalCase } from "change-case";
3
- import { getVariableValues, GraphQLError, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, isEnumType, isListType, isNonNullType, isObjectType, isScalarType, Kind, parse, print, visit, } from "graphql";
4
- import { buildASTSchema, getOperationAST } from "graphql/utilities";
5
- import { z } from "zod";
6
- import { BOOLEAN_GQL_PRIMITIVE_NAME, FLOAT_GQL_PRIMITIVE_NAME, gqlPrimitiveNodeNamesList, ID_GQL_PRIMITIVE_NAME, INT_GQL_PRIMITIVE_NAME, STRING_GQL_PRIMITIVE_NAME, } from "../constants/graphql-kinds.js";
7
- import { safeParseSdl } from "../context/schema-context.js";
8
- export function makeStateSchemaNameForScope(modelName, scope) {
9
- const modelNamePascalCase = pascalCase(modelName);
10
- const scopePascalCase = pascalCase(scope);
11
- const name = scopePascalCase === "Global"
12
- ? `${modelNamePascalCase}State`
13
- : `${modelNamePascalCase}${scopePascalCase}State`;
14
- return name;
15
- }
16
- export function makeInitialSchemaDoc(modelName, scope) {
17
- const name = makeStateSchemaNameForScope(modelName, scope);
18
- const stateSchemaSdl = `type ${name} {
19
- "Add your ${scope} state fields here"
20
- _placeholder: String
21
- }`;
22
- return stateSchemaSdl;
23
- }
24
- export function makeOperationInitialDoc(name) {
25
- const inputSdl = `input ${pascalCase(name)}Input {
26
- "Add your inputs here"
27
- _placeholder: String
28
- }`;
29
- return inputSdl;
30
- }
31
- export function makeEmptyOperationSchema(operationName) {
32
- const pascalName = pascalCase(operationName);
33
- return `input ${pascalName}Input {\n _empty: Boolean\n}`;
34
- }
35
- export function isEmptyOperationSchema(schema) {
36
- if (!schema)
37
- return false;
38
- // Check if schema only contains _empty: Boolean field
39
- return (/_empty:\s*Boolean/.test(schema) &&
40
- !schema.replace(/_empty:\s*Boolean/, "").match(/\w+:\s*\w+/));
41
- }
42
- export function safeParseJsonRecord(json) {
43
- try {
44
- return JSON.parse(json);
45
- }
46
- catch (error) {
47
- return null;
48
- }
49
- }
50
- export function makeMinimalObjectForStateType(args) {
51
- const { sharedSchemaDocumentNode, stateTypeDefinitionNode, existingValue } = args;
52
- const existingValueObject = safeParseJsonRecord(existingValue);
53
- if (!existingValueObject) {
54
- return existingValue;
55
- }
56
- const stateTypeDefinitionFields = stateTypeDefinitionNode.fields;
57
- if (!stateTypeDefinitionFields?.length) {
58
- return existingValue;
59
- }
60
- // Initialize visitedTypes with the root type to detect self-recursive types
61
- const visitedTypes = new Set([stateTypeDefinitionNode.name.value]);
62
- const minimalObject = makeMinimalValuesForObjectFields({
63
- schemaDocumentNode: sharedSchemaDocumentNode,
64
- fieldDefinitionNodes: stateTypeDefinitionFields,
65
- existingValueObject,
66
- visitedTypes,
67
- });
68
- return JSON.stringify(minimalObject, null, 2);
69
- }
70
- export function makeMinimalValuesForObjectFields(args) {
71
- const { schemaDocumentNode, existingValueObject, fieldDefinitionNodes, visitedTypes, } = args;
72
- const newJson = {};
73
- for (const astNode of fieldDefinitionNodes) {
74
- const fieldName = getASTNodeName(astNode);
75
- if (!fieldName) {
76
- continue;
77
- }
78
- const minimalValue = makeMinimalValueForASTNode({
79
- fieldName,
80
- astNode,
81
- schemaDocumentNode,
82
- existingValueObject,
83
- visitedTypes,
84
- });
85
- newJson[astNode.name.value] = minimalValue;
86
- }
87
- return newJson;
88
- }
89
- function makeMinimalValueForASTNode(args) {
90
- const { fieldName, astNode, schemaDocumentNode, existingValueObject, visitedTypes, } = args;
91
- const existingFieldValue = existingValueObject?.[fieldName];
92
- let node = astNode;
93
- if (isFieldDefinitionNode(astNode)) {
94
- node = getASTNodeTypeNode(node);
95
- }
96
- const isNonNull = isNonNullNode(node);
97
- if (isNonNull) {
98
- node = getASTNodeTypeNode(node);
99
- }
100
- if (isListTypeNode(node)) {
101
- return makeMinimalValueForGqlListNode(node, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes);
102
- }
103
- if (isGqlPrimitiveNode(node)) {
104
- return makeMinimalValueForGQLPrimitiveNode(node, existingFieldValue, isNonNull);
105
- }
106
- const namedTypeDefinitionNode = getNamedTypeDefinitionNode(node, schemaDocumentNode);
107
- if (isEnumTypeDefinitionNode(namedTypeDefinitionNode)) {
108
- return makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull);
109
- }
110
- if (isScalarTypeDefinitionNode(namedTypeDefinitionNode)) {
111
- return makeMinimalValueForGqlScalar(namedTypeDefinitionNode, existingFieldValue, isNonNull);
112
- }
113
- if (isUnionTypeDefinitionNode(namedTypeDefinitionNode)) {
114
- return makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes);
115
- }
116
- if (isObjectTypeDefinitionNode(namedTypeDefinitionNode)) {
117
- return makeMinimalValueForGqlObject(namedTypeDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
118
- }
119
- return existingFieldValue;
120
- }
121
- function isFieldDefinitionNode(astNodeTypeNode) {
122
- if (!astNodeTypeNode)
123
- return false;
124
- return astNodeTypeNode.kind === Kind.FIELD_DEFINITION;
125
- }
126
- function isNonNullNode(astNode) {
127
- if (!astNode)
128
- return false;
129
- return astNode.kind === Kind.NON_NULL_TYPE;
130
- }
131
- export function isGqlPrimitiveNode(astNodeTypeNode) {
132
- if (!astNodeTypeNode)
133
- return false;
134
- const name = getASTNodeName(astNodeTypeNode);
135
- return gqlPrimitiveNodeNamesList.includes(name);
136
- }
137
- function isListTypeNode(astNodeTypeNode) {
138
- if (!astNodeTypeNode)
139
- return false;
140
- return astNodeTypeNode.kind === Kind.LIST_TYPE;
141
- }
142
- function isEnumTypeDefinitionNode(definitionNode) {
143
- if (!definitionNode)
144
- return false;
145
- return definitionNode.kind === Kind.ENUM_TYPE_DEFINITION;
146
- }
147
- function isScalarTypeDefinitionNode(definitionNode) {
148
- if (!definitionNode)
149
- return false;
150
- return definitionNode.kind === Kind.SCALAR_TYPE_DEFINITION;
151
- }
152
- function isUnionTypeDefinitionNode(definitionNode) {
153
- if (!definitionNode)
154
- return false;
155
- return definitionNode.kind === Kind.UNION_TYPE_DEFINITION;
156
- }
157
- function isObjectTypeDefinitionNode(definitionNode) {
158
- if (!definitionNode)
159
- return false;
160
- return definitionNode.kind === Kind.OBJECT_TYPE_DEFINITION;
161
- }
162
- function getASTNodeName(astNode) {
163
- if (!astNode) {
164
- return null;
165
- }
166
- if (!("name" in astNode)) {
167
- return null;
168
- }
169
- if (!astNode.name) {
170
- return null;
171
- }
172
- if (!("value" in astNode.name)) {
173
- return null;
174
- }
175
- return astNode.name.value;
176
- }
177
- function getASTNodeTypeNode(astNode) {
178
- if (!astNode) {
179
- return null;
180
- }
181
- if (!("type" in astNode)) {
182
- return null;
183
- }
184
- return astNode.type;
185
- }
186
- function makeMinimalValueForGQLPrimitiveNode(primitiveTypeNode, existingFieldValue, isNonNull) {
187
- const name = getASTNodeName(primitiveTypeNode);
188
- if (!name) {
189
- return null;
190
- }
191
- switch (name) {
192
- case ID_GQL_PRIMITIVE_NAME: {
193
- if (z.string().safeParse(existingFieldValue).success) {
194
- return existingFieldValue;
195
- }
196
- return isNonNull ? "placeholder-id" : null;
197
- }
198
- case BOOLEAN_GQL_PRIMITIVE_NAME: {
199
- if (z.boolean().safeParse(existingFieldValue).success) {
200
- return existingFieldValue;
201
- }
202
- return isNonNull ? false : null;
203
- }
204
- case INT_GQL_PRIMITIVE_NAME: {
205
- if (z.number().safeParse(existingFieldValue).success) {
206
- return existingFieldValue;
207
- }
208
- return isNonNull ? 0 : null;
209
- }
210
- case FLOAT_GQL_PRIMITIVE_NAME: {
211
- if (z.number().safeParse(existingFieldValue).success) {
212
- return existingFieldValue;
213
- }
214
- return isNonNull ? 0.0 : null;
215
- }
216
- case STRING_GQL_PRIMITIVE_NAME: {
217
- if (z.string().safeParse(existingFieldValue).success) {
218
- return existingFieldValue;
219
- }
220
- return isNonNull ? "" : null;
221
- }
222
- }
223
- return isNonNull ? existingFieldValue : null;
224
- }
225
- function makeMinimalValueForGqlEnum(namedTypeDefinitionNode, existingFieldValue, isNonNull) {
226
- const enumValues = namedTypeDefinitionNode.values?.map((value) => value.name.value) ?? [];
227
- if (typeof existingFieldValue === "string" &&
228
- enumValues.includes(existingFieldValue)) {
229
- return existingFieldValue;
230
- }
231
- if (isNonNull) {
232
- return enumValues[0];
233
- }
234
- return null;
235
- }
236
- function makeMinimalValueForGqlScalar(scalarTypeDefinitionNode, existingFieldValue, isNonNull) {
237
- if (!isNonNull && !existingFieldValue) {
238
- return null;
239
- }
240
- const name = getASTNodeName(scalarTypeDefinitionNode);
241
- if (!name) {
242
- console.error("No name for scalar type definition node", scalarTypeDefinitionNode);
243
- return null;
244
- }
245
- const scalar = getPHCustomScalarByTypeName(name);
246
- if (!scalar) {
247
- return null;
248
- }
249
- const existingValueIsValid = scalar.schema.safeParse(existingFieldValue);
250
- if (existingValueIsValid.success) {
251
- return existingFieldValue;
252
- }
253
- if (!isNonNull) {
254
- return null;
255
- }
256
- const minimalValue = scalar.getDefaultValue?.();
257
- if (minimalValue) {
258
- return minimalValue;
259
- }
260
- return existingFieldValue;
261
- }
262
- function makeMinimalValueForGqlUnion(namedTypeDefinitionNode, existingFieldValue, schemaDocumentNode, existingValueObject, isNonNull, visitedTypes) {
263
- if (!isNonNull && !existingFieldValue) {
264
- return null;
265
- }
266
- const types = namedTypeDefinitionNode.types;
267
- if (!types?.length) {
268
- return null;
269
- }
270
- const firstNamedTypeDefinitionNode = namedTypeDefinitionNode.types?.at(0);
271
- if (!firstNamedTypeDefinitionNode) {
272
- return null;
273
- }
274
- const firstNamedTypeObjectDefinitionNode = getNamedTypeDefinitionNode(firstNamedTypeDefinitionNode, schemaDocumentNode);
275
- if (!isObjectTypeDefinitionNode(firstNamedTypeObjectDefinitionNode)) {
276
- return null;
277
- }
278
- return makeMinimalValueForGqlObject(firstNamedTypeObjectDefinitionNode, schemaDocumentNode, existingValueObject, existingFieldValue, isNonNull, visitedTypes);
279
- }
280
- function makeMinimalValueForGqlListNode(listTypeNode, existingFieldValue, isNonNull, schemaDocumentNode, visitedTypes) {
281
- if (!isNonNull && !Array.isArray(existingFieldValue)) {
282
- return null;
283
- }
284
- if (isNonNull && !Array.isArray(existingFieldValue)) {
285
- return [];
286
- }
287
- // Process each array item recursively
288
- const arrayValue = existingFieldValue;
289
- return arrayValue.map((item, index) => makeMinimalValueForASTNode({
290
- fieldName: String(index),
291
- astNode: listTypeNode.type,
292
- schemaDocumentNode,
293
- existingValueObject: { [index]: item },
294
- visitedTypes,
295
- }));
296
- }
297
- function makeMinimalValueForGqlObject(objectTypeDefinitionNode, schemaDocumentNode, _existingValueObject, existingFieldValue, isNonNull, visitedTypes) {
298
- const typeName = objectTypeDefinitionNode.name.value;
299
- // Check for recursive types to prevent infinite recursion
300
- if (visitedTypes?.has(typeName)) {
301
- return null;
302
- }
303
- if (!isNonNull && !existingFieldValue) {
304
- return null;
305
- }
306
- const fields = objectTypeDefinitionNode.fields;
307
- if (!fields?.length) {
308
- return {};
309
- }
310
- // Track this type to detect cycles
311
- const newVisitedTypes = new Set(visitedTypes);
312
- newVisitedTypes.add(typeName);
313
- // Use existingFieldValue (the actual nested object) instead of existingValueObject (parent)
314
- const nestedExistingValue = existingFieldValue &&
315
- typeof existingFieldValue === "object" &&
316
- !Array.isArray(existingFieldValue)
317
- ? existingFieldValue
318
- : null;
319
- return makeMinimalValuesForObjectFields({
320
- schemaDocumentNode,
321
- existingValueObject: nestedExistingValue,
322
- fieldDefinitionNodes: fields,
323
- visitedTypes: newVisitedTypes,
324
- });
325
- }
326
- function getNamedTypeDefinitionNode(astNodeTypeNode, schemaDocumentNode) {
327
- if (!astNodeTypeNode) {
328
- return null;
329
- }
330
- const name = getASTNodeName(astNodeTypeNode);
331
- if (!name) {
332
- return null;
333
- }
334
- const definitionNode = schemaDocumentNode.definitions.find((def) => "kind" in def && "name" in def && def.name?.value === name);
335
- if (!definitionNode) {
336
- return null;
337
- }
338
- return definitionNode;
339
- }
340
- function removeWhitespace(str) {
341
- return str.replace(/\s+|\\n|\\t/g, "").toLowerCase();
342
- }
343
- export function compareStringsWithoutWhitespace(str1, str2) {
344
- if (str1 === null ||
345
- str2 === null ||
346
- str1 === undefined ||
347
- str2 === undefined)
348
- return false;
349
- return removeWhitespace(str1) === removeWhitespace(str2);
350
- }
351
- export function renameSchemaType(sdl, oldName, newName, scope) {
352
- const typeSuffix = scope === "global" ? "State" : "LocalState";
353
- const oldTypeName = `${pascalCase(oldName)}${typeSuffix}`;
354
- const newTypeName = `${pascalCase(newName)}${typeSuffix}`;
355
- const ast = safeParseSdl(sdl);
356
- if (!ast)
357
- return sdl;
358
- const updatedAst = visit(ast, {
359
- ObjectTypeDefinition: (node) => {
360
- if (node.name.value === oldTypeName) {
361
- return {
362
- ...node,
363
- name: {
364
- ...node.name,
365
- value: newTypeName,
366
- },
367
- };
368
- }
369
- },
370
- });
371
- return print(updatedAst);
372
- }
373
- export function initializeModelSchema(modelName) {
374
- const initialSchemaDoc = makeInitialSchemaDoc(modelName, "global");
375
- return initialSchemaDoc;
376
- }
377
- export function updateModelSchemaNames(params) {
378
- const { oldName, newName, globalStateSchema, localStateSchema, setStateSchema, } = params;
379
- const newSchema = renameSchemaType(globalStateSchema, oldName, newName, "global");
380
- setStateSchema(newSchema, "global");
381
- if (localStateSchema) {
382
- const newLocalStateSchema = renameSchemaType(localStateSchema, oldName, newName, "local");
383
- setStateSchema(newLocalStateSchema, "local");
384
- }
385
- }
386
- export function handleModelNameChange(params) {
387
- const { newName, globalStateSchema, setStateSchema } = params;
388
- const hasExistingSchema = !!globalStateSchema;
389
- if (!hasExistingSchema) {
390
- const initialSchemaDoc = initializeModelSchema(newName);
391
- setStateSchema(initialSchemaDoc, "global");
392
- return;
393
- }
394
- updateModelSchemaNames(params);
395
- }
396
- /**
397
- * Converts an output object type into an equivalent input object type.
398
- * Intended for structural validation of state objects.
399
- */
400
- export function objectTypeToInputType(schema, objectType, options) {
401
- const suffix = options?.nameSuffix ?? "Input";
402
- const cache = options?.cache ?? new Map();
403
- const inputTypeName = `${objectType.name}${suffix}`;
404
- if (cache.has(inputTypeName)) {
405
- return cache.get(inputTypeName);
406
- }
407
- const inputType = new GraphQLInputObjectType({
408
- name: inputTypeName,
409
- fields: () => {
410
- const fields = objectType.getFields();
411
- const inputFields = {};
412
- for (const fieldName in fields) {
413
- const field = fields[fieldName];
414
- if (field.args.length > 0) {
415
- throw new Error(`Cannot convert field "${objectType.name}.${fieldName}" with arguments into input type`);
416
- }
417
- inputFields[fieldName] = {
418
- type: outputTypeToInputType(schema, field.type, suffix, cache),
419
- };
420
- }
421
- return inputFields;
422
- },
423
- });
424
- cache.set(inputTypeName, inputType);
425
- return inputType;
426
- }
427
- function outputTypeToInputType(schema, type, suffix, cache) {
428
- if (isNonNullType(type)) {
429
- return new GraphQLNonNull(outputTypeToInputType(schema, type.ofType, suffix, cache));
430
- }
431
- if (isListType(type)) {
432
- return new GraphQLList(outputTypeToInputType(schema, type.ofType, suffix, cache));
433
- }
434
- if (isScalarType(type) || isEnumType(type)) {
435
- return type;
436
- }
437
- if (isObjectType(type)) {
438
- return objectTypeToInputType(schema, type, {
439
- nameSuffix: suffix,
440
- cache,
441
- });
442
- }
443
- throw new Error(`Unsupported output type: ${type.toString()}`);
444
- }
445
- export function validateStateObject(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateValue) {
446
- let stateObjectJson;
447
- try {
448
- stateObjectJson = JSON.parse(stateValue);
449
- }
450
- catch (error) {
451
- return [new Error("Invalid JSON object", { cause: error })];
452
- }
453
- // 2) Build a quick index of type definitions from the shared schema
454
- const typeDefByName = indexTypeDefinitions(sharedSchemaDocumentNode);
455
- // Ensure the passed node exists in the shared schema (optional but helpful)
456
- const stateTypeName = stateTypeDefinitionNode.name.value;
457
- if (!typeDefByName.has(stateTypeName)) {
458
- return [
459
- new Error(`State type "${stateTypeName}" was not found in sharedSchemaDocumentNode`),
460
- ];
461
- }
462
- // 3) Generate input types needed to validate this state object
463
- const inputSuffix = "Input";
464
- const generatedInputDefs = generateInputTypesForObjectTree(stateTypeName, typeDefByName, inputSuffix);
465
- // 4) Build a schema that includes the generated input types
466
- const augmentedDoc = {
467
- ...sharedSchemaDocumentNode,
468
- definitions: [
469
- ...sharedSchemaDocumentNode.definitions,
470
- ...generatedInputDefs,
471
- ],
472
- };
473
- let schema;
474
- try {
475
- schema = buildASTSchema(augmentedDoc, { assumeValidSDL: false });
476
- }
477
- catch (e) {
478
- return [new Error("Failed to build schema from SDL", { cause: e })];
479
- }
480
- // 5) Validate by coercing variables against the generated input type
481
- const inputTypeName = `${stateTypeName}${inputSuffix}`;
482
- const opDoc = parse(`query($v: ${inputTypeName}!) { __typename }`);
483
- const op = getOperationAST(opDoc);
484
- if (!op) {
485
- return [new Error("Failed to create validation operation AST")];
486
- }
487
- const { errors } = getVariableValues(schema, op.variableDefinitions ?? [], {
488
- v: stateObjectJson,
489
- });
490
- // Detect recursive types first - these take priority over NON_NULL errors
491
- const recursiveTypeErrors = detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName);
492
- // Get the field names that have recursive types
493
- const recursiveFieldNames = new Set(recursiveTypeErrors.map((e) => e.field));
494
- const validationErrors = errors
495
- ? graphQLErrorsToStateValidationErrors(errors).filter((e) => {
496
- // Filter out NON_NULL errors caused by recursive types
497
- if (e instanceof StateValidationError && e.kind === "NON_NULL") {
498
- // Check if this error is in a path that starts with a recursive field
499
- const rootField = e.path[0];
500
- if (typeof rootField === "string" &&
501
- recursiveFieldNames.has(rootField)) {
502
- return false;
503
- }
504
- }
505
- return true;
506
- })
507
- : [];
508
- // Add recursive type errors first (they have priority)
509
- validationErrors.unshift(...recursiveTypeErrors);
510
- const missingOptionalErrors = detectMissingOptionalFields(sharedSchemaDocumentNode, stateTypeDefinitionNode, stateObjectJson);
511
- validationErrors.push(...missingOptionalErrors);
512
- return validationErrors;
513
- }
514
- /**
515
- * Indexes object/input/enum/scalar/interface/union type definition nodes by name.
516
- * Note: only AST definitions that have a "name" field are indexed.
517
- */
518
- function indexTypeDefinitions(doc) {
519
- const map = new Map();
520
- for (const def of doc.definitions) {
521
- if (def.kind === Kind.OBJECT_TYPE_DEFINITION ||
522
- def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
523
- def.kind === Kind.ENUM_TYPE_DEFINITION ||
524
- def.kind === Kind.SCALAR_TYPE_DEFINITION ||
525
- def.kind === Kind.INTERFACE_TYPE_DEFINITION ||
526
- def.kind === Kind.UNION_TYPE_DEFINITION ||
527
- def.kind === Kind.OBJECT_TYPE_EXTENSION ||
528
- def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION ||
529
- def.kind === Kind.ENUM_TYPE_EXTENSION ||
530
- def.kind === Kind.INTERFACE_TYPE_EXTENSION ||
531
- def.kind === Kind.UNION_TYPE_EXTENSION) {
532
- // Extensions also have names; we index them too (but see note below).
533
- // In production, you may want to merge extensions into base definitions.
534
- // For state validation, prefer definitions (not extensions) if both exist.
535
- const name = def.name.value;
536
- if (!map.has(name)) {
537
- map.set(name, def);
538
- }
539
- }
540
- }
541
- return map;
542
- }
543
- /**
544
- * Generates InputObjectTypeDefinitionNode(s) for a root object type and any nested
545
- * object types reachable via fields, converting object references to their *Input equivalents*.
546
- */
547
- function generateInputTypesForObjectTree(rootObjectTypeName, typeDefByName, inputSuffix) {
548
- const generated = new Map();
549
- const visiting = new Set();
550
- const ensureInputForObject = (objectTypeName) => {
551
- const inputName = `${objectTypeName}${inputSuffix}`;
552
- if (generated.has(inputName))
553
- return;
554
- if (visiting.has(objectTypeName)) {
555
- // Recursive reference; we rely on GraphQLInputObjectType lazy field resolution via AST schema build.
556
- // Still, we must avoid infinite loops while generating AST nodes.
557
- return;
558
- }
559
- visiting.add(objectTypeName);
560
- const def = typeDefByName.get(objectTypeName);
561
- if (!def) {
562
- throw new GraphQLError(`Unknown referenced type "${objectTypeName}"`);
563
- }
564
- if (def.kind !== Kind.OBJECT_TYPE_DEFINITION &&
565
- def.kind !== Kind.OBJECT_TYPE_EXTENSION) {
566
- throw new GraphQLError(`Type "${objectTypeName}" is not an object type; cannot generate input from kind "${def.kind}"`);
567
- }
568
- const objDef = def;
569
- // Convert each field type to an input-acceptable TypeNode.
570
- const inputFields = objDef.fields?.map((f) => {
571
- return {
572
- kind: Kind.INPUT_VALUE_DEFINITION,
573
- name: f.name,
574
- description: f.description,
575
- directives: [], // output-field directives don't automatically translate to input fields
576
- type: convertOutputTypeNodeToInputTypeNode(f.type, typeDefByName, inputSuffix, ensureInputForObject),
577
- defaultValue: undefined,
578
- };
579
- }) ?? [];
580
- const inputDef = {
581
- kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
582
- name: { kind: Kind.NAME, value: inputName },
583
- description: objDef.description,
584
- directives: [],
585
- fields: inputFields,
586
- };
587
- generated.set(inputName, inputDef);
588
- visiting.delete(objectTypeName);
589
- };
590
- // Kick off generation for root
591
- ensureInputForObject(rootObjectTypeName);
592
- return Array.from(generated.values());
593
- }
594
- function convertOutputTypeNodeToInputTypeNode(typeNode, typeDefByName, inputSuffix, ensureInputForObject) {
595
- switch (typeNode.kind) {
596
- case Kind.NON_NULL_TYPE:
597
- return {
598
- kind: Kind.NON_NULL_TYPE,
599
- type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject),
600
- };
601
- case Kind.LIST_TYPE:
602
- return {
603
- kind: Kind.LIST_TYPE,
604
- type: convertOutputTypeNodeToInputTypeNode(typeNode.type, typeDefByName, inputSuffix, ensureInputForObject),
605
- };
606
- case Kind.NAMED_TYPE: {
607
- const named = typeNode;
608
- const name = named.name.value;
609
- const def = typeDefByName.get(name);
610
- // If it's an object type, we must reference its generated input twin.
611
- if (def?.kind === Kind.OBJECT_TYPE_DEFINITION ||
612
- def?.kind === Kind.OBJECT_TYPE_EXTENSION) {
613
- ensureInputForObject(name);
614
- return {
615
- kind: Kind.NAMED_TYPE,
616
- name: { kind: Kind.NAME, value: `${name}${inputSuffix}` },
617
- };
618
- }
619
- // Scalars/enums/input objects are valid as-is in input positions.
620
- if (!def ||
621
- def.kind === Kind.SCALAR_TYPE_DEFINITION ||
622
- def.kind === Kind.ENUM_TYPE_DEFINITION ||
623
- def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
624
- def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
625
- return named;
626
- }
627
- // Interfaces/unions are not valid input types.
628
- if (def.kind === Kind.INTERFACE_TYPE_DEFINITION ||
629
- def.kind === Kind.UNION_TYPE_DEFINITION) {
630
- throw new GraphQLError(`Type "${name}" (${def.kind}) cannot be used in an input type`);
631
- }
632
- // Anything else is unexpected.
633
- throw new GraphQLError(`Unsupported named type "${name}" of kind "${def.kind}"`);
634
- }
635
- default:
636
- // Exhaustiveness guard
637
- throw new GraphQLError(`Unsupported TypeNode kind: ${JSON.stringify(typeNode)}`);
638
- }
639
- }
640
- export class StateValidationError extends Error {
641
- payload;
642
- originalMessage;
643
- constructor(payload, originalMessage) {
644
- // Keep Error.message stable but not user-facing; UI should render from payload.
645
- super(payload.kind);
646
- this.name = "StateValidationError";
647
- this.payload = payload;
648
- this.originalMessage = originalMessage;
649
- Object.setPrototypeOf(this, new.target.prototype);
650
- }
651
- get kind() {
652
- return this.payload.kind;
653
- }
654
- get path() {
655
- return this.payload.path;
656
- }
657
- get field() {
658
- return this.payload.field;
659
- }
660
- }
661
- function extractInputPath(message) {
662
- const match = message.match(/at\s+"([^"]+)"/);
663
- if (!match)
664
- return [];
665
- const parts = match[1].split(".").filter(Boolean);
666
- const withoutVar = parts[0] === "v" ? parts.slice(1) : parts;
667
- return withoutVar.map((p) => (/^\d+$/.test(p) ? Number(p) : p));
668
- }
669
- const RE_MISSING_REQUIRED_FIELD = /Field "([^"]+)" of required type "([^"]+)" was not provided\./;
670
- const RE_UNKNOWN_FIELD = /Field "([^"]+)" is not defined by type "([^"]+)"\.(?: Did you mean "([^"]+)"\?)?/;
671
- function extractMissingRequiredField(message) {
672
- const m = message.match(RE_MISSING_REQUIRED_FIELD);
673
- if (!m)
674
- return null;
675
- return { field: m[1], expectedType: m[2] };
676
- }
677
- function extractUnknownField(message) {
678
- const m = message.match(RE_UNKNOWN_FIELD);
679
- if (!m)
680
- return null;
681
- return { field: m[1], typeName: m[2], didYouMean: m[3] };
682
- }
683
- function lastFieldFromPath(path) {
684
- for (let i = path.length - 1; i >= 0; i--) {
685
- if (typeof path[i] === "string")
686
- return path[i];
687
- }
688
- return undefined;
689
- }
690
- function extractExpectedType(message) {
691
- // NON_NULL: Expected non-nullable type "Int!" not to be null.
692
- let m = message.match(/Expected non-nullable type "([^"]+)"/);
693
- if (m?.[1])
694
- return m[1];
695
- // Sometimes: Expected type "X" ...
696
- m = message.match(/Expected type "([^"]+)"/);
697
- if (m?.[1])
698
- return m[1];
699
- // Scalar coercion: "; String cannot represent ..."
700
- m = message.match(/;\s*([_A-Za-z][_0-9A-Za-z]*)\s+cannot represent/i);
701
- if (m?.[1])
702
- return m[1];
703
- return undefined;
704
- }
705
- export function graphQLErrorsToStateValidationErrors(errors) {
706
- const out = [];
707
- for (const e of errors) {
708
- const originalMessage = e.message;
709
- // 1) Missing required field (no `at "v.x"` path usually)
710
- const missing = extractMissingRequiredField(originalMessage);
711
- if (missing) {
712
- out.push(new StateValidationError({
713
- kind: "MISSING",
714
- path: [missing.field],
715
- field: missing.field,
716
- expectedType: missing.expectedType, // if your payload supports it
717
- }, originalMessage));
718
- continue;
719
- }
720
- // 2) Unknown field (extra key)
721
- const unknown = extractUnknownField(originalMessage);
722
- if (unknown) {
723
- out.push(new StateValidationError({
724
- kind: "UNKNOWN_FIELD",
725
- path: [unknown.field],
726
- field: unknown.field,
727
- didYouMean: unknown.didYouMean, // optional
728
- }, originalMessage));
729
- continue;
730
- }
731
- // 3) Usual `at "v.path"` extraction (NON_NULL / TYPE)
732
- const path = extractInputPath(originalMessage);
733
- const field = lastFieldFromPath(path) ?? "value";
734
- const expectedType = extractExpectedType(originalMessage);
735
- if (originalMessage.includes("Expected non-nullable type") &&
736
- originalMessage.includes("not to be null")) {
737
- out.push(new StateValidationError({ kind: "NON_NULL", path, field, expectedType }, originalMessage));
738
- continue;
739
- }
740
- if (originalMessage.includes("cannot represent") ||
741
- originalMessage.includes("Expected type")) {
742
- out.push(new StateValidationError({
743
- kind: "TYPE",
744
- path,
745
- field,
746
- expectedType,
747
- details: originalMessage,
748
- }, originalMessage));
749
- continue;
750
- }
751
- out.push(new StateValidationError({ kind: "TYPE", path, field, details: originalMessage }, originalMessage));
752
- }
753
- return out;
754
- }
755
- /**
756
- * Finds all fields defined in the schema that are missing from the state object.
757
- * Returns information about each missing field including whether it's required.
758
- */
759
- export function findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value, basePath = []) {
760
- let stateObjectJson;
761
- try {
762
- stateObjectJson =
763
- typeof value === "string"
764
- ? JSON.parse(value)
765
- : value;
766
- }
767
- catch {
768
- return [];
769
- }
770
- const typeByName = indexObjectTypes(sharedSchemaDocumentNode);
771
- const missingFields = [];
772
- for (const field of rootTypeNode.fields ?? []) {
773
- const fieldName = field.name.value;
774
- const fieldPath = [...basePath, fieldName];
775
- const isRequired = field.type.kind === Kind.NON_NULL_TYPE;
776
- // Unwrap NonNull to get the underlying type
777
- const underlyingType = isRequired
778
- ? field.type.type
779
- : field.type;
780
- // Check if field is missing from the state object
781
- if (!(fieldName in stateObjectJson)) {
782
- missingFields.push({
783
- fieldName,
784
- path: fieldPath,
785
- isRequired,
786
- type: underlyingType,
787
- });
788
- continue;
789
- }
790
- // If present and object-typed → recurse to check nested missing fields
791
- const namedType = unwrapNamedType(field.type);
792
- const childType = namedType ? typeByName.get(namedType) : undefined;
793
- if (childType &&
794
- typeof stateObjectJson[fieldName] === "object" &&
795
- stateObjectJson[fieldName] !== null &&
796
- !Array.isArray(stateObjectJson[fieldName])) {
797
- const nestedMissing = findMissingFields(sharedSchemaDocumentNode, childType, stateObjectJson[fieldName], fieldPath);
798
- missingFields.push(...nestedMissing);
799
- }
800
- }
801
- return missingFields;
802
- }
803
- /**
804
- * Detects optional fields defined in the schema that are missing from the state object.
805
- * Returns StateValidationError[] for each missing optional field.
806
- */
807
- export function detectMissingOptionalFields(sharedSchemaDocumentNode, rootTypeNode, value) {
808
- const missingFields = findMissingFields(sharedSchemaDocumentNode, rootTypeNode, value);
809
- // Only report optional (not required) fields as MISSING_OPTIONAL errors
810
- // Required fields are already caught by GraphQL validation
811
- return missingFields
812
- .filter((field) => !field.isRequired)
813
- .map((field) => new StateValidationError({
814
- kind: "MISSING_OPTIONAL",
815
- path: field.path,
816
- field: field.fieldName,
817
- expectedType: typeNodeToString(field.type),
818
- }));
819
- }
820
- /**
821
- * Detects fields that have recursive types (types that reference themselves directly or indirectly).
822
- * Returns a RECURSIVE_TYPE error for each field that contains a recursive type.
823
- */
824
- function detectRecursiveTypes(stateTypeDefinitionNode, typeDefByName) {
825
- const errors = [];
826
- for (const field of stateTypeDefinitionNode.fields ?? []) {
827
- const fieldName = field.name.value;
828
- const namedTypeName = getNamedTypeName(field.type);
829
- if (!namedTypeName)
830
- continue;
831
- // Check if this field's type is recursive
832
- if (isRecursiveType(namedTypeName, typeDefByName, new Set())) {
833
- errors.push(new StateValidationError({
834
- kind: "RECURSIVE_TYPE",
835
- path: [fieldName],
836
- field: fieldName,
837
- typeName: namedTypeName,
838
- }));
839
- }
840
- }
841
- return errors;
842
- }
843
- /**
844
- * Gets the named type name from a TypeNode, unwrapping NonNull and List types.
845
- */
846
- function getNamedTypeName(typeNode) {
847
- if (typeNode.kind === Kind.NAMED_TYPE) {
848
- return typeNode.name.value;
849
- }
850
- if (typeNode.kind === Kind.NON_NULL_TYPE ||
851
- typeNode.kind === Kind.LIST_TYPE) {
852
- return getNamedTypeName(typeNode.type);
853
- }
854
- return null;
855
- }
856
- /**
857
- * Checks if a type is recursive (references itself directly or indirectly through required fields).
858
- */
859
- function isRecursiveType(typeName, typeDefByName, visitedTypes) {
860
- if (visitedTypes.has(typeName)) {
861
- return true;
862
- }
863
- const typeDef = typeDefByName.get(typeName);
864
- if (!typeDef || typeDef.kind !== Kind.OBJECT_TYPE_DEFINITION) {
865
- return false;
866
- }
867
- visitedTypes.add(typeName);
868
- for (const field of typeDef.fields ?? []) {
869
- // Only check required fields for recursion (NonNull types)
870
- if (field.type.kind !== Kind.NON_NULL_TYPE)
871
- continue;
872
- const innerType = field.type.type;
873
- let fieldTypeName = null;
874
- if (innerType.kind === Kind.NAMED_TYPE) {
875
- fieldTypeName = innerType.name.value;
876
- }
877
- else if (innerType.kind === Kind.LIST_TYPE) {
878
- // For list types like [Item!]!, get the inner type
879
- fieldTypeName = getNamedTypeName(innerType);
880
- }
881
- if (fieldTypeName &&
882
- isRecursiveType(fieldTypeName, typeDefByName, visitedTypes)) {
883
- return true;
884
- }
885
- }
886
- visitedTypes.delete(typeName);
887
- return false;
888
- }
889
- /**
890
- * Converts a TypeNode to its string representation (e.g., "String", "Int!", "[String]!")
891
- */
892
- function typeNodeToString(typeNode) {
893
- switch (typeNode.kind) {
894
- case Kind.NAMED_TYPE:
895
- return typeNode.name.value;
896
- case Kind.NON_NULL_TYPE:
897
- return `${typeNodeToString(typeNode.type)}!`;
898
- case Kind.LIST_TYPE:
899
- return `[${typeNodeToString(typeNode.type)}]`;
900
- }
901
- }
902
- function indexObjectTypes(doc) {
903
- const map = new Map();
904
- for (const def of doc.definitions) {
905
- if (def.kind === Kind.OBJECT_TYPE_DEFINITION) {
906
- map.set(def.name.value, def);
907
- }
908
- }
909
- return map;
910
- }
911
- function unwrapNamedType(typeNode) {
912
- if (typeNode.kind === Kind.NAMED_TYPE)
913
- return typeNode.name.value;
914
- if (typeNode.kind === Kind.NON_NULL_TYPE)
915
- return unwrapNamedType(typeNode.type);
916
- if (typeNode.kind === Kind.LIST_TYPE)
917
- return unwrapNamedType(typeNode.type);
918
- return undefined;
919
- }
920
- //# sourceMappingURL=helpers.js.map