houdini 2.0.0-next.2 → 2.0.0-next.23

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 (429) hide show
  1. package/build/adapter/index.d.ts +2 -2
  2. package/build/adapter/index.js +6 -0
  3. package/build/cmd/generate.d.ts +5 -0
  4. package/build/cmd/generate.js +77 -0
  5. package/build/cmd/index.js +32 -0
  6. package/build/cmd/init.js +530 -0
  7. package/build/cmd/pullSchema.js +21 -0
  8. package/build/{vite → lib}/ast.d.ts +1 -1
  9. package/build/lib/ast.js +71 -0
  10. package/build/lib/codegen.d.ts +55 -0
  11. package/build/lib/codegen.js +522 -0
  12. package/build/lib/config.d.ts +219 -177
  13. package/build/lib/config.js +134 -0
  14. package/build/lib/constants.js +10 -0
  15. package/build/lib/database.d.ts +6 -0
  16. package/build/lib/database.js +629 -0
  17. package/build/lib/deepMerge.js +23 -0
  18. package/build/lib/error.d.ts +16 -0
  19. package/build/lib/error.js +115 -0
  20. package/build/lib/fs.d.ts +9 -11
  21. package/build/lib/fs.js +245 -0
  22. package/build/lib/graphql.d.ts +5 -32
  23. package/build/lib/graphql.js +36 -0
  24. package/build/lib/imports.d.ts +29 -14
  25. package/build/lib/imports.js +66 -0
  26. package/build/lib/index.d.ts +16 -24
  27. package/build/lib/index.js +20 -0
  28. package/build/lib/logger.d.ts +12 -0
  29. package/build/lib/logger.js +45 -0
  30. package/build/lib/parse.d.ts +1 -2
  31. package/build/lib/parse.js +30 -0
  32. package/build/lib/path.d.ts +0 -1
  33. package/build/lib/path.js +44 -0
  34. package/build/lib/pipeline.d.ts +1 -1
  35. package/build/lib/pipeline.js +8 -0
  36. package/build/lib/plugins.d.ts +4 -0
  37. package/build/lib/plugins.js +72 -0
  38. package/build/lib/project.d.ts +17 -0
  39. package/build/lib/project.js +183 -0
  40. package/build/lib/schema.d.ts +1 -0
  41. package/build/lib/schema.js +62 -0
  42. package/build/lib/sleep.d.ts +1 -0
  43. package/build/lib/sleep.js +8 -0
  44. package/build/lib/types.d.ts +93 -304
  45. package/build/lib/types.js +37 -0
  46. package/build/lib/walk.d.ts +4 -3
  47. package/build/lib/walk.js +138 -0
  48. package/build/node/index.d.ts +37 -0
  49. package/build/node/index.js +271 -0
  50. package/build/package.json +201 -0
  51. package/build/{lib/router → router}/conventions.d.ts +14 -5
  52. package/build/router/conventions.js +165 -0
  53. package/build/{runtime-esm/router → router}/cookies.d.ts +9 -9
  54. package/build/{runtime-esm/router → router}/cookies.js +22 -22
  55. package/build/{runtime-esm/router → router}/jwt.js +34 -17
  56. package/build/{lib/router → router}/manifest.d.ts +2 -2
  57. package/build/router/manifest.js +279 -0
  58. package/build/{runtime/router → router}/match.d.ts +6 -6
  59. package/build/{runtime-esm/router → router}/match.js +50 -12
  60. package/build/router/server.d.ts +42 -0
  61. package/build/router/server.js +130 -0
  62. package/build/{runtime-esm/router → router}/session.d.ts +1 -0
  63. package/build/{runtime-esm/router → router}/session.js +6 -2
  64. package/build/{runtime-cjs/router → router}/types.d.ts +1 -1
  65. package/build/runtime/cache/gc.d.ts +1 -1
  66. package/build/{runtime-esm → runtime}/cache/gc.js +0 -1
  67. package/build/runtime/cache/index.d.ts +169 -3
  68. package/build/{runtime-esm/cache/cache.js → runtime/cache/index.js} +34 -49
  69. package/build/runtime/cache/lists.d.ts +9 -9
  70. package/build/{runtime-esm → runtime}/cache/lists.js +29 -27
  71. package/build/runtime/cache/staleManager.d.ts +1 -1
  72. package/build/{runtime-esm → runtime}/cache/staleManager.js +2 -27
  73. package/build/runtime/cache/storage.d.ts +1 -1
  74. package/build/{runtime-esm → runtime}/cache/storage.js +6 -8
  75. package/build/runtime/cache/subscription.d.ts +11 -5
  76. package/build/{runtime-esm → runtime}/cache/subscription.js +10 -11
  77. package/build/runtime/{client/index.d.ts → client.d.ts} +15 -22
  78. package/build/runtime/client.js +86 -0
  79. package/build/runtime/config.d.ts +7 -0
  80. package/build/{runtime-esm/lib → runtime}/config.js +6 -19
  81. package/build/runtime/{lib/constants.d.ts → constants.d.ts} +1 -1
  82. package/build/{runtime-esm/lib → runtime}/deepEquals.js +4 -2
  83. package/build/runtime/{client/documentStore.d.ts → documentStore.d.ts} +13 -9
  84. package/build/{runtime-esm/client → runtime}/documentStore.js +31 -68
  85. package/build/{runtime-cjs/lib → runtime}/flatten.d.ts +1 -1
  86. package/build/runtime/index.d.ts +12 -8
  87. package/build/runtime/index.js +30 -0
  88. package/build/{runtime-cjs/lib → runtime}/key.d.ts +1 -1
  89. package/build/{runtime-esm/lib → runtime}/key.js +4 -4
  90. package/build/{runtime-esm/lib → runtime}/log.js +3 -3
  91. package/build/{runtime-cjs/lib → runtime}/pageInfo.d.ts +3 -3
  92. package/build/{runtime-esm/lib → runtime}/pageInfo.js +2 -2
  93. package/build/{runtime-cjs/lib → runtime}/pagination.d.ts +8 -8
  94. package/build/{runtime-esm/lib → runtime}/pagination.js +19 -19
  95. package/build/{runtime-cjs/lib → runtime}/scalars.d.ts +6 -6
  96. package/build/{runtime-esm/lib → runtime}/scalars.js +10 -43
  97. package/build/{runtime-cjs/lib → runtime}/selection.d.ts +1 -1
  98. package/build/{runtime-esm/lib → runtime}/selection.js +2 -2
  99. package/build/runtime/{lib/store.d.ts → store.d.ts} +1 -1
  100. package/build/{runtime-esm/lib → runtime}/store.js +2 -3
  101. package/build/{runtime-cjs/lib → runtime}/types.d.ts +39 -84
  102. package/build/{runtime-esm/lib → runtime}/types.js +8 -22
  103. package/build/test/index.d.ts +6 -25
  104. package/build/test/index.js +329 -0
  105. package/build/vite/hmr.d.ts +23 -5
  106. package/build/vite/hmr.js +231 -0
  107. package/build/vite/houdini.d.ts +4 -10
  108. package/build/vite/houdini.js +127 -0
  109. package/build/vite/index.d.ts +13 -7
  110. package/build/vite/index.js +96 -0
  111. package/build/vite/package.json +1 -0
  112. package/build/vite/schema.d.ts +5 -3
  113. package/build/vite/schema.js +150 -0
  114. package/package.json +115 -36
  115. package/build/adapter-cjs/index.js +0 -33
  116. package/build/adapter-cjs/package.json +0 -1
  117. package/build/adapter-esm/index.js +0 -9
  118. package/build/cmd-cjs/index.js +0 -89277
  119. package/build/cmd-cjs/package.json +0 -1
  120. package/build/cmd-esm/index.js +0 -89281
  121. package/build/codegen/generators/artifacts/fieldKey.d.ts +0 -3
  122. package/build/codegen/generators/artifacts/index.d.ts +0 -17
  123. package/build/codegen/generators/artifacts/indexFile.d.ts +0 -2
  124. package/build/codegen/generators/artifacts/inputs.d.ts +0 -4
  125. package/build/codegen/generators/artifacts/operations.d.ts +0 -11
  126. package/build/codegen/generators/artifacts/selection.d.ts +0 -20
  127. package/build/codegen/generators/artifacts/utils.d.ts +0 -8
  128. package/build/codegen/generators/comments/jsdoc.d.ts +0 -2
  129. package/build/codegen/generators/definitions/enums.d.ts +0 -2
  130. package/build/codegen/generators/definitions/index.d.ts +0 -2
  131. package/build/codegen/generators/index.d.ts +0 -6
  132. package/build/codegen/generators/indexFile/index.d.ts +0 -2
  133. package/build/codegen/generators/persistedQueries/index.d.ts +0 -2
  134. package/build/codegen/generators/runtime/graphqlFunction.d.ts +0 -2
  135. package/build/codegen/generators/runtime/index.d.ts +0 -3
  136. package/build/codegen/generators/runtime/injectPlugins.d.ts +0 -7
  137. package/build/codegen/generators/runtime/pluginIndex.d.ts +0 -5
  138. package/build/codegen/generators/runtime/pluginRuntime.d.ts +0 -15
  139. package/build/codegen/generators/runtime/runtimeConfig.d.ts +0 -7
  140. package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +0 -4
  141. package/build/codegen/generators/typescript/documentTypes.d.ts +0 -2
  142. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +0 -2
  143. package/build/codegen/generators/typescript/index.d.ts +0 -2
  144. package/build/codegen/generators/typescript/inlineType.d.ts +0 -28
  145. package/build/codegen/generators/typescript/loadingState.d.ts +0 -8
  146. package/build/codegen/index.d.ts +0 -8
  147. package/build/codegen/transforms/addFields.d.ts +0 -2
  148. package/build/codegen/transforms/collectDefinitions.d.ts +0 -9
  149. package/build/codegen/transforms/componentFields.d.ts +0 -8
  150. package/build/codegen/transforms/fragmentVariables.d.ts +0 -17
  151. package/build/codegen/transforms/index.d.ts +0 -9
  152. package/build/codegen/transforms/list.d.ts +0 -9
  153. package/build/codegen/transforms/paginate.d.ts +0 -4
  154. package/build/codegen/transforms/runtimeScalars.d.ts +0 -2
  155. package/build/codegen/transforms/schema.d.ts +0 -2
  156. package/build/codegen/transforms/typename.d.ts +0 -2
  157. package/build/codegen/utils/commonjs.d.ts +0 -5
  158. package/build/codegen/utils/flattenSelections.d.ts +0 -11
  159. package/build/codegen/utils/index.d.ts +0 -4
  160. package/build/codegen/utils/moduleExport.d.ts +0 -4
  161. package/build/codegen/utils/murmur.d.ts +0 -9
  162. package/build/codegen/utils/objectIdentificationSelection.d.ts +0 -3
  163. package/build/codegen/utils/stripLoc.d.ts +0 -3
  164. package/build/codegen/validators/componentFields.d.ts +0 -2
  165. package/build/codegen/validators/index.d.ts +0 -5
  166. package/build/codegen/validators/noIDAlias.d.ts +0 -2
  167. package/build/codegen/validators/plugins.d.ts +0 -3
  168. package/build/codegen/validators/typeCheck.d.ts +0 -5
  169. package/build/codegen/validators/uniqueNames.d.ts +0 -2
  170. package/build/codegen-cjs/index.js +0 -74633
  171. package/build/codegen-cjs/package.json +0 -1
  172. package/build/codegen-esm/index.js +0 -74632
  173. package/build/lib/cleanupFiles.d.ts +0 -1
  174. package/build/lib/detectTools.d.ts +0 -16
  175. package/build/lib/introspection.d.ts +0 -3
  176. package/build/lib/plugin.d.ts +0 -2
  177. package/build/lib/router/index.d.ts +0 -9
  178. package/build/lib/router/server.d.ts +0 -7
  179. package/build/lib/router/types.d.ts +0 -23
  180. package/build/lib/typescript.d.ts +0 -20
  181. package/build/lib/watchAndRun.d.ts +0 -61
  182. package/build/lib-cjs/index.js +0 -79731
  183. package/build/lib-cjs/package.json +0 -1
  184. package/build/lib-esm/index.js +0 -79640
  185. package/build/runtime/cache/cache.d.ts +0 -169
  186. package/build/runtime/client/plugins/cache.d.ts +0 -9
  187. package/build/runtime/client/plugins/fetch.d.ts +0 -38
  188. package/build/runtime/client/plugins/fetchParams.d.ts +0 -9
  189. package/build/runtime/client/plugins/fragment.d.ts +0 -2
  190. package/build/runtime/client/plugins/index.d.ts +0 -9
  191. package/build/runtime/client/plugins/injectedPlugins.d.ts +0 -4
  192. package/build/runtime/client/plugins/mutation.d.ts +0 -2
  193. package/build/runtime/client/plugins/optimisticKeys.d.ts +0 -7
  194. package/build/runtime/client/plugins/query.d.ts +0 -2
  195. package/build/runtime/client/plugins/subscription.d.ts +0 -20
  196. package/build/runtime/client/plugins/test.d.ts +0 -15
  197. package/build/runtime/client/plugins/throwOnError.d.ts +0 -8
  198. package/build/runtime/client/utils/documentPlugins.d.ts +0 -3
  199. package/build/runtime/client/utils/index.d.ts +0 -1
  200. package/build/runtime/generated.d.ts +0 -5
  201. package/build/runtime/imports/config.d.ts +0 -3
  202. package/build/runtime/imports/pluginConfig.d.ts +0 -3
  203. package/build/runtime/lib/config.d.ts +0 -216
  204. package/build/runtime/lib/deepEquals.d.ts +0 -1
  205. package/build/runtime/lib/flatten.d.ts +0 -2
  206. package/build/runtime/lib/index.d.ts +0 -10
  207. package/build/runtime/lib/key.d.ts +0 -6
  208. package/build/runtime/lib/log.d.ts +0 -6
  209. package/build/runtime/lib/lru.d.ts +0 -52
  210. package/build/runtime/lib/pageInfo.d.ts +0 -7
  211. package/build/runtime/lib/pagination.d.ts +0 -27
  212. package/build/runtime/lib/scalars.d.ts +0 -14
  213. package/build/runtime/lib/selection.d.ts +0 -2
  214. package/build/runtime/lib/types.d.ts +0 -417
  215. package/build/runtime/public/cache.d.ts +0 -43
  216. package/build/runtime/public/index.d.ts +0 -1
  217. package/build/runtime/public/list.d.ts +0 -18
  218. package/build/runtime/public/record.d.ts +0 -40
  219. package/build/runtime/public/tests/test.d.ts +0 -156
  220. package/build/runtime/public/types.d.ts +0 -62
  221. package/build/runtime/router/cookies.d.ts +0 -41
  222. package/build/runtime/router/jwt.d.ts +0 -117
  223. package/build/runtime/router/server.d.ts +0 -24
  224. package/build/runtime/router/session.d.ts +0 -21
  225. package/build/runtime/router/types.d.ts +0 -26
  226. package/build/runtime-cjs/cache/cache.d.ts +0 -169
  227. package/build/runtime-cjs/cache/cache.js +0 -1077
  228. package/build/runtime-cjs/cache/constants.d.ts +0 -1
  229. package/build/runtime-cjs/cache/constants.js +0 -28
  230. package/build/runtime-cjs/cache/gc.d.ts +0 -10
  231. package/build/runtime-cjs/cache/gc.js +0 -74
  232. package/build/runtime-cjs/cache/index.d.ts +0 -3
  233. package/build/runtime-cjs/cache/index.js +0 -25
  234. package/build/runtime-cjs/cache/lists.d.ts +0 -89
  235. package/build/runtime-cjs/cache/lists.js +0 -467
  236. package/build/runtime-cjs/cache/staleManager.d.ts +0 -31
  237. package/build/runtime-cjs/cache/staleManager.js +0 -123
  238. package/build/runtime-cjs/cache/storage.d.ts +0 -110
  239. package/build/runtime-cjs/cache/storage.js +0 -451
  240. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  241. package/build/runtime-cjs/cache/stuff.js +0 -56
  242. package/build/runtime-cjs/cache/subscription.d.ts +0 -52
  243. package/build/runtime-cjs/cache/subscription.js +0 -349
  244. package/build/runtime-cjs/client/documentStore.d.ts +0 -107
  245. package/build/runtime-cjs/client/documentStore.js +0 -487
  246. package/build/runtime-cjs/client/index.d.ts +0 -50
  247. package/build/runtime-cjs/client/index.js +0 -162
  248. package/build/runtime-cjs/client/plugins/cache.d.ts +0 -9
  249. package/build/runtime-cjs/client/plugins/cache.js +0 -138
  250. package/build/runtime-cjs/client/plugins/fetch.d.ts +0 -38
  251. package/build/runtime-cjs/client/plugins/fetch.js +0 -210
  252. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +0 -9
  253. package/build/runtime-cjs/client/plugins/fetchParams.js +0 -47
  254. package/build/runtime-cjs/client/plugins/fragment.d.ts +0 -2
  255. package/build/runtime-cjs/client/plugins/fragment.js +0 -77
  256. package/build/runtime-cjs/client/plugins/index.d.ts +0 -9
  257. package/build/runtime-cjs/client/plugins/index.js +0 -45
  258. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +0 -4
  259. package/build/runtime-cjs/client/plugins/injectedPlugins.js +0 -25
  260. package/build/runtime-cjs/client/plugins/mutation.d.ts +0 -2
  261. package/build/runtime-cjs/client/plugins/mutation.js +0 -89
  262. package/build/runtime-cjs/client/plugins/optimisticKeys.d.ts +0 -7
  263. package/build/runtime-cjs/client/plugins/optimisticKeys.js +0 -324
  264. package/build/runtime-cjs/client/plugins/query.d.ts +0 -2
  265. package/build/runtime-cjs/client/plugins/query.js +0 -93
  266. package/build/runtime-cjs/client/plugins/subscription.d.ts +0 -20
  267. package/build/runtime-cjs/client/plugins/subscription.js +0 -114
  268. package/build/runtime-cjs/client/plugins/test.d.ts +0 -15
  269. package/build/runtime-cjs/client/plugins/test.js +0 -118
  270. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +0 -8
  271. package/build/runtime-cjs/client/plugins/throwOnError.js +0 -47
  272. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +0 -3
  273. package/build/runtime-cjs/client/utils/documentPlugins.js +0 -57
  274. package/build/runtime-cjs/client/utils/index.d.ts +0 -1
  275. package/build/runtime-cjs/client/utils/index.js +0 -22
  276. package/build/runtime-cjs/generated.d.ts +0 -5
  277. package/build/runtime-cjs/generated.js +0 -16
  278. package/build/runtime-cjs/imports/config.d.ts +0 -3
  279. package/build/runtime-cjs/imports/config.js +0 -24
  280. package/build/runtime-cjs/imports/pluginConfig.d.ts +0 -3
  281. package/build/runtime-cjs/imports/pluginConfig.js +0 -25
  282. package/build/runtime-cjs/index.d.ts +0 -8
  283. package/build/runtime-cjs/index.js +0 -61
  284. package/build/runtime-cjs/lib/config.d.ts +0 -216
  285. package/build/runtime-cjs/lib/config.js +0 -110
  286. package/build/runtime-cjs/lib/constants.d.ts +0 -6
  287. package/build/runtime-cjs/lib/constants.js +0 -38
  288. package/build/runtime-cjs/lib/deepEquals.js +0 -52
  289. package/build/runtime-cjs/lib/flatten.js +0 -41
  290. package/build/runtime-cjs/lib/index.d.ts +0 -10
  291. package/build/runtime-cjs/lib/index.js +0 -40
  292. package/build/runtime-cjs/lib/key.js +0 -41
  293. package/build/runtime-cjs/lib/log.js +0 -72
  294. package/build/runtime-cjs/lib/lru.js +0 -73
  295. package/build/runtime-cjs/lib/pageInfo.js +0 -79
  296. package/build/runtime-cjs/lib/pagination.js +0 -240
  297. package/build/runtime-cjs/lib/scalars.js +0 -147
  298. package/build/runtime-cjs/lib/selection.js +0 -66
  299. package/build/runtime-cjs/lib/store.d.ts +0 -19
  300. package/build/runtime-cjs/lib/store.js +0 -81
  301. package/build/runtime-cjs/lib/types.js +0 -104
  302. package/build/runtime-cjs/package.json +0 -1
  303. package/build/runtime-cjs/public/cache.d.ts +0 -43
  304. package/build/runtime-cjs/public/cache.js +0 -112
  305. package/build/runtime-cjs/public/index.d.ts +0 -1
  306. package/build/runtime-cjs/public/index.js +0 -28
  307. package/build/runtime-cjs/public/list.d.ts +0 -18
  308. package/build/runtime-cjs/public/list.js +0 -151
  309. package/build/runtime-cjs/public/record.d.ts +0 -40
  310. package/build/runtime-cjs/public/record.js +0 -94
  311. package/build/runtime-cjs/public/tests/test.d.ts +0 -156
  312. package/build/runtime-cjs/public/tests/test.js +0 -60
  313. package/build/runtime-cjs/public/types.d.ts +0 -62
  314. package/build/runtime-cjs/public/types.js +0 -16
  315. package/build/runtime-cjs/router/cookies.d.ts +0 -41
  316. package/build/runtime-cjs/router/cookies.js +0 -168
  317. package/build/runtime-cjs/router/jwt.js +0 -168
  318. package/build/runtime-cjs/router/match.d.ts +0 -39
  319. package/build/runtime-cjs/router/match.js +0 -158
  320. package/build/runtime-cjs/router/server.d.ts +0 -24
  321. package/build/runtime-cjs/router/server.js +0 -102
  322. package/build/runtime-cjs/router/session.d.ts +0 -21
  323. package/build/runtime-cjs/router/session.js +0 -95
  324. package/build/runtime-cjs/router/types.js +0 -16
  325. package/build/runtime-esm/cache/cache.d.ts +0 -169
  326. package/build/runtime-esm/cache/constants.d.ts +0 -1
  327. package/build/runtime-esm/cache/gc.d.ts +0 -10
  328. package/build/runtime-esm/cache/index.d.ts +0 -3
  329. package/build/runtime-esm/cache/index.js +0 -5
  330. package/build/runtime-esm/cache/lists.d.ts +0 -89
  331. package/build/runtime-esm/cache/staleManager.d.ts +0 -31
  332. package/build/runtime-esm/cache/storage.d.ts +0 -110
  333. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  334. package/build/runtime-esm/cache/subscription.d.ts +0 -52
  335. package/build/runtime-esm/client/documentStore.d.ts +0 -107
  336. package/build/runtime-esm/client/index.d.ts +0 -50
  337. package/build/runtime-esm/client/index.js +0 -130
  338. package/build/runtime-esm/client/plugins/cache.d.ts +0 -9
  339. package/build/runtime-esm/client/plugins/cache.js +0 -104
  340. package/build/runtime-esm/client/plugins/fetch.d.ts +0 -38
  341. package/build/runtime-esm/client/plugins/fetch.js +0 -184
  342. package/build/runtime-esm/client/plugins/fetchParams.d.ts +0 -9
  343. package/build/runtime-esm/client/plugins/fetchParams.js +0 -23
  344. package/build/runtime-esm/client/plugins/fragment.d.ts +0 -2
  345. package/build/runtime-esm/client/plugins/fragment.js +0 -53
  346. package/build/runtime-esm/client/plugins/index.d.ts +0 -9
  347. package/build/runtime-esm/client/plugins/index.js +0 -12
  348. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +0 -4
  349. package/build/runtime-esm/client/plugins/injectedPlugins.js +0 -5
  350. package/build/runtime-esm/client/plugins/mutation.d.ts +0 -2
  351. package/build/runtime-esm/client/plugins/mutation.js +0 -65
  352. package/build/runtime-esm/client/plugins/optimisticKeys.d.ts +0 -7
  353. package/build/runtime-esm/client/plugins/optimisticKeys.js +0 -290
  354. package/build/runtime-esm/client/plugins/query.d.ts +0 -2
  355. package/build/runtime-esm/client/plugins/query.js +0 -69
  356. package/build/runtime-esm/client/plugins/subscription.d.ts +0 -20
  357. package/build/runtime-esm/client/plugins/subscription.js +0 -90
  358. package/build/runtime-esm/client/plugins/test.d.ts +0 -15
  359. package/build/runtime-esm/client/plugins/test.js +0 -93
  360. package/build/runtime-esm/client/plugins/throwOnError.d.ts +0 -8
  361. package/build/runtime-esm/client/plugins/throwOnError.js +0 -23
  362. package/build/runtime-esm/client/utils/documentPlugins.d.ts +0 -3
  363. package/build/runtime-esm/client/utils/documentPlugins.js +0 -33
  364. package/build/runtime-esm/client/utils/index.d.ts +0 -1
  365. package/build/runtime-esm/client/utils/index.js +0 -1
  366. package/build/runtime-esm/generated.d.ts +0 -5
  367. package/build/runtime-esm/generated.js +0 -0
  368. package/build/runtime-esm/imports/config.d.ts +0 -3
  369. package/build/runtime-esm/imports/config.js +0 -4
  370. package/build/runtime-esm/imports/pluginConfig.d.ts +0 -3
  371. package/build/runtime-esm/imports/pluginConfig.js +0 -5
  372. package/build/runtime-esm/index.d.ts +0 -8
  373. package/build/runtime-esm/index.js +0 -22
  374. package/build/runtime-esm/lib/config.d.ts +0 -216
  375. package/build/runtime-esm/lib/constants.d.ts +0 -6
  376. package/build/runtime-esm/lib/deepEquals.d.ts +0 -1
  377. package/build/runtime-esm/lib/flatten.d.ts +0 -2
  378. package/build/runtime-esm/lib/index.d.ts +0 -10
  379. package/build/runtime-esm/lib/index.js +0 -10
  380. package/build/runtime-esm/lib/key.d.ts +0 -6
  381. package/build/runtime-esm/lib/log.d.ts +0 -6
  382. package/build/runtime-esm/lib/lru.d.ts +0 -52
  383. package/build/runtime-esm/lib/pageInfo.d.ts +0 -7
  384. package/build/runtime-esm/lib/pagination.d.ts +0 -27
  385. package/build/runtime-esm/lib/scalars.d.ts +0 -14
  386. package/build/runtime-esm/lib/selection.d.ts +0 -2
  387. package/build/runtime-esm/lib/store.d.ts +0 -19
  388. package/build/runtime-esm/lib/types.d.ts +0 -417
  389. package/build/runtime-esm/public/cache.d.ts +0 -43
  390. package/build/runtime-esm/public/cache.js +0 -88
  391. package/build/runtime-esm/public/index.d.ts +0 -1
  392. package/build/runtime-esm/public/index.js +0 -4
  393. package/build/runtime-esm/public/list.d.ts +0 -18
  394. package/build/runtime-esm/public/list.js +0 -127
  395. package/build/runtime-esm/public/record.d.ts +0 -40
  396. package/build/runtime-esm/public/record.js +0 -70
  397. package/build/runtime-esm/public/tests/test.d.ts +0 -156
  398. package/build/runtime-esm/public/tests/test.js +0 -36
  399. package/build/runtime-esm/public/types.d.ts +0 -62
  400. package/build/runtime-esm/router/jwt.d.ts +0 -117
  401. package/build/runtime-esm/router/match.d.ts +0 -39
  402. package/build/runtime-esm/router/server.d.ts +0 -24
  403. package/build/runtime-esm/router/server.js +0 -77
  404. package/build/runtime-esm/router/types.d.ts +0 -26
  405. package/build/runtime-esm/router/types.js +0 -0
  406. package/build/test-cjs/index.js +0 -75227
  407. package/build/test-cjs/package.json +0 -1
  408. package/build/test-esm/index.js +0 -75222
  409. package/build/vite/imports.d.ts +0 -40
  410. package/build/vite-cjs/index.js +0 -86263
  411. package/build/vite-cjs/package.json +0 -1
  412. package/build/vite-esm/index.js +0 -86255
  413. /package/build/{adapter-esm → adapter}/package.json +0 -0
  414. /package/build/{cmd-esm → cmd}/package.json +0 -0
  415. /package/build/{codegen-esm → lib}/package.json +0 -0
  416. /package/build/{lib-esm → node}/package.json +0 -0
  417. /package/build/{runtime-cjs/router → router}/jwt.d.ts +0 -0
  418. /package/build/{runtime-esm → router}/package.json +0 -0
  419. /package/build/{runtime-esm/public → router}/types.js +0 -0
  420. /package/build/{runtime-esm → runtime}/cache/constants.js +0 -0
  421. /package/build/{runtime-esm → runtime}/cache/stuff.js +0 -0
  422. /package/build/{runtime-esm/lib → runtime}/constants.js +0 -0
  423. /package/build/{runtime-cjs/lib → runtime}/deepEquals.d.ts +0 -0
  424. /package/build/{runtime-esm/lib → runtime}/flatten.js +0 -0
  425. /package/build/{runtime-cjs/lib → runtime}/log.d.ts +0 -0
  426. /package/build/{runtime-cjs/lib → runtime}/lru.d.ts +0 -0
  427. /package/build/{runtime-esm/lib → runtime}/lru.js +0 -0
  428. /package/build/{test-esm → runtime}/package.json +0 -0
  429. /package/build/{vite-esm → test}/package.json +0 -0
@@ -0,0 +1,71 @@
1
+ import * as recast from "recast";
2
+ const _AST = recast.types.builders;
3
+ function find_insert_index(script) {
4
+ let insert_index = script.body.findIndex((statement) => {
5
+ return statement.type !== "ImportDeclaration";
6
+ });
7
+ if (insert_index === -1) {
8
+ insert_index = script.body.length;
9
+ }
10
+ return insert_index;
11
+ }
12
+ function find_exported_fn(body, name) {
13
+ for (const statement of body) {
14
+ if (statement.type !== "ExportNamedDeclaration") {
15
+ continue;
16
+ }
17
+ const exportDeclaration = statement;
18
+ if (exportDeclaration.declaration?.type === "FunctionDeclaration") {
19
+ const value = exportDeclaration.declaration;
20
+ if (value.id?.name === name) {
21
+ return {
22
+ declaration: exportDeclaration.declaration,
23
+ export: exportDeclaration
24
+ };
25
+ }
26
+ } else if (exportDeclaration.declaration?.type === "VariableDeclaration") {
27
+ const value = exportDeclaration.declaration;
28
+ if (value.declarations.length !== 1 || value.declarations[0].type !== "VariableDeclarator" || value.declarations[0].id.type !== "Identifier" || value.declarations[0].id.name !== name) {
29
+ continue;
30
+ }
31
+ const declaration = value.declarations[0];
32
+ let { init } = declaration;
33
+ if (!init) {
34
+ continue;
35
+ }
36
+ if (init.type === "TSSatisfiesExpression") {
37
+ init = init.expression;
38
+ }
39
+ if (init.type === "CallExpression" && init.arguments[0] && (init.arguments[0].type === "FunctionExpression" || init.arguments[0].type === "ArrowFunctionExpression")) {
40
+ init = init.arguments[0];
41
+ }
42
+ if (init.type === "FunctionExpression" || init.type === "ArrowFunctionExpression") {
43
+ return { declaration: init, export: exportDeclaration };
44
+ }
45
+ if (init.type === "Identifier" || init.type === "CallExpression") {
46
+ return { declaration: init, export: exportDeclaration };
47
+ }
48
+ } else {
49
+ }
50
+ }
51
+ const exported = body.find(
52
+ (expression) => expression.type === "ExportNamedDeclaration" && (expression.declaration?.type === "FunctionDeclaration" && expression.declaration.id?.name === name || expression.declaration?.type === "VariableDeclaration" && expression.declaration.declarations.length === 1 && expression.declaration.declarations[0].type === "Identifier" && expression.declaration.declarations[0].name === name)
53
+ );
54
+ if (!exported) {
55
+ return null;
56
+ }
57
+ return {
58
+ declaration: exported.declaration,
59
+ export: exported
60
+ };
61
+ }
62
+ function find_exported_id(program, name) {
63
+ return program.body.find(
64
+ (statement) => statement.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration" && statement.declaration.declarations.length === 1 && statement.declaration.declarations[0].type === "VariableDeclarator" && statement.declaration.declarations[0].id.type === "Identifier" && statement.declaration.declarations[0].id.name === name
65
+ );
66
+ }
67
+ export {
68
+ find_exported_fn,
69
+ find_exported_id,
70
+ find_insert_index
71
+ };
@@ -0,0 +1,55 @@
1
+ import { type DatabaseSync } from 'node:sqlite';
2
+ import * as conventions from '../router/conventions.js';
3
+ import type { Config } from './config.js';
4
+ import type { ProjectManifest } from './types';
5
+ export type PluginSpec = {
6
+ name: string;
7
+ port: number;
8
+ directory: string;
9
+ hooks: Set<string>;
10
+ order: 'before' | 'after' | 'core';
11
+ };
12
+ export type Adapter = ((args: {
13
+ config: Config;
14
+ conventions: typeof conventions;
15
+ sourceDir: string;
16
+ publicBase: string;
17
+ outDir: string;
18
+ manifest: ProjectManifest;
19
+ adapterPath: string;
20
+ }) => void | Promise<void>) & {
21
+ includePaths?: Record<string, string> | ((args: {
22
+ config: Config;
23
+ }) => Record<string, string>);
24
+ disableServer?: boolean;
25
+ pre?: (args: {
26
+ config: Config;
27
+ conventions: typeof conventions;
28
+ sourceDir: string;
29
+ publicBase: string;
30
+ outDir: string;
31
+ }) => Promise<void> | void;
32
+ };
33
+ export declare function connect_db(config: Config): [DatabaseSync, string];
34
+ export declare function init_db(config: Config, preserve: boolean): Promise<[DatabaseSync, string]>;
35
+ export type CompilerProxy = {
36
+ close: () => Promise<void>;
37
+ trigger_hook: (name: PipelineHook, opts?: {
38
+ parallel_safe?: boolean;
39
+ payload?: {};
40
+ task_id?: string;
41
+ }) => Promise<Record<string, any> | null>;
42
+ database_path: string;
43
+ run_pipeline: (options: RunPipelineOptions) => Promise<Record<PipelineHook, Record<string, any>>>;
44
+ };
45
+ export declare function plugin_db_key(name: string): string;
46
+ export declare function codegen_setup(config: Config, mode: string, db: DatabaseSync, db_file: string): Promise<CompilerProxy>;
47
+ export declare const PIPELINE_HOOKS: readonly ["Config", "AfterLoad", "Schema", "ExtractDocuments", "AfterExtract", "BeforeValidate", "Validate", "AfterValidate", "BeforeGenerate", "GenerateDocuments", "GenerateRuntime", "AfterGenerate"];
48
+ export type PipelineHook = (typeof PIPELINE_HOOKS)[number];
49
+ export type RunPipelineOptions = {
50
+ task_id?: string;
51
+ after?: PipelineHook;
52
+ start?: PipelineHook;
53
+ through?: PipelineHook;
54
+ };
55
+ export declare function run_pipeline(trigger_hook: CompilerProxy['trigger_hook'], options?: RunPipelineOptions): Promise<Record<PipelineHook, Record<string, any>>>;
@@ -0,0 +1,522 @@
1
+ import { spawn } from "node:child_process";
2
+ import path from "node:path";
3
+ import { createInterface } from "node:readline";
4
+ import sqlite from "node:sqlite";
5
+ import { WebSocket } from "ws";
6
+ import * as conventions from "../router/conventions.js";
7
+ import { create_schema, write_config } from "./database.js";
8
+ import { format_hook_error } from "./error.js";
9
+ import * as fs from "./fs.js";
10
+ import { Logger } from "./logger.js";
11
+ import { LogLevel } from "./types.js";
12
+ function connect_db(config) {
13
+ const filepath = conventions.db_path(config);
14
+ const db = new sqlite.DatabaseSync(filepath);
15
+ db.exec("PRAGMA journal_mode = WAL");
16
+ db.exec("PRAGMA synchronous = off");
17
+ db.exec("PRAGMA cache_size = 10000");
18
+ db.exec("PRAGMA temp_store = memory");
19
+ db.exec("PRAGMA busy_timeout = 5000");
20
+ db.exec("PRAGMA foreign_key = ON");
21
+ db.exec("PRAGMA defer_foreign_keys = ON");
22
+ db.exec(create_schema);
23
+ return [db, filepath];
24
+ }
25
+ async function init_db(config, preserve) {
26
+ const db_file = conventions.db_path(config);
27
+ if (!preserve) {
28
+ try {
29
+ await fs.remove(db_file);
30
+ } catch (_e) {
31
+ }
32
+ try {
33
+ await fs.remove(`${db_file}-shm`);
34
+ } catch (_e) {
35
+ }
36
+ try {
37
+ await fs.remove(`${db_file}-wal`);
38
+ } catch (_e) {
39
+ }
40
+ }
41
+ return [connect_db(config)[0], db_file];
42
+ }
43
+ function plugin_db_key(name) {
44
+ if (!name.startsWith("./") && !name.startsWith("../") && !path.isAbsolute(name)) {
45
+ return name;
46
+ }
47
+ return name.replace(/\./g, "_").replace(/\//g, "__");
48
+ }
49
+ async function codegen_setup(config, mode, db, db_file) {
50
+ const logger = new Logger(config.config_file.logLevel ?? LogLevel.Summary);
51
+ await fs.mkdirpSync(conventions.houdini_root(config));
52
+ const rawTransport = config.config_file.pluginTransport ?? "websocket";
53
+ const resolvedTransport = rawTransport.startsWith("env:") ? process.env[rawTransport.slice("env:".length)] ?? "websocket" : rawTransport;
54
+ const useStdio = resolvedTransport === "stdio";
55
+ const plugins = {};
56
+ const plugin_specs = [];
57
+ const spec_results = {};
58
+ const stdioStdin = /* @__PURE__ */ new Map();
59
+ const triggerHookRef = { fn: null };
60
+ const wait_for_plugin_db = (configKey, dbKey) => new Promise((resolve, reject) => {
61
+ const find_plugin = db.prepare("SELECT * FROM plugins WHERE name = ?");
62
+ const interval = setInterval(() => {
63
+ const row = find_plugin.get(dbKey);
64
+ if (row) {
65
+ clearInterval(interval);
66
+ db.prepare("UPDATE plugins set config = ? where name = ?").run(
67
+ JSON.stringify(
68
+ config.plugins.find((p) => p.name === configKey)?.config ?? {}
69
+ ),
70
+ dbKey
71
+ );
72
+ const spec = {
73
+ name: row.name,
74
+ port: row.port,
75
+ hooks: new Set(JSON.parse(row.hooks)),
76
+ order: row.plugin_order,
77
+ directory: config.plugins.find((p) => p.name === configKey)?.directory || ""
78
+ };
79
+ spec_results[configKey] = spec;
80
+ if (row.config_module) {
81
+ import(row.config_module).then((module) => {
82
+ if (module && typeof module.default === "function") {
83
+ config.config_file = module.default(config.config_file);
84
+ }
85
+ resolver(spec);
86
+ });
87
+ } else {
88
+ resolver(spec);
89
+ }
90
+ }
91
+ }, 10);
92
+ const timeout = setTimeout(() => {
93
+ clearInterval(interval);
94
+ reject(new Error(`Timeout waiting for plugin ${configKey} to register`));
95
+ }, 1e4);
96
+ const resolver = (spec) => {
97
+ clearTimeout(timeout);
98
+ resolve(spec);
99
+ };
100
+ });
101
+ const wait_for_plugin_stdio = (name, child) => new Promise((resolve, reject) => {
102
+ const timeout = setTimeout(() => {
103
+ reject(new Error(`Timeout waiting for plugin ${name} to register`));
104
+ }, 1e4);
105
+ const rl = createInterface({ input: child.stdout });
106
+ let registered = false;
107
+ rl.on("line", (line) => {
108
+ try {
109
+ const msg = JSON.parse(line);
110
+ if (!registered) {
111
+ if (msg.type !== "register") {
112
+ clearTimeout(timeout);
113
+ reject(new Error(`Plugin ${name} sent ${msg.type} before registering`));
114
+ return;
115
+ }
116
+ registered = true;
117
+ clearTimeout(timeout);
118
+ const spec = {
119
+ name: msg.name ?? plugin_db_key(name),
120
+ port: msg.port ?? 0,
121
+ hooks: new Set(msg.hooks ?? []),
122
+ order: msg.order,
123
+ directory: config.plugins.find((p) => p.name === name)?.directory || ""
124
+ };
125
+ spec_results[name] = spec;
126
+ db.prepare(
127
+ `INSERT OR IGNORE INTO plugins (name, hooks, port, plugin_order, include_runtime, config_module, client_plugins)
128
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
129
+ ).run(
130
+ spec.name,
131
+ JSON.stringify([...spec.hooks]),
132
+ spec.port,
133
+ spec.order,
134
+ msg.includeRuntime ?? null,
135
+ msg.configModule ?? null,
136
+ msg.clientPlugins ?? null
137
+ );
138
+ db.prepare("UPDATE plugins SET config = ? WHERE name = ?").run(
139
+ JSON.stringify(
140
+ config.plugins.find((p) => p.name === name)?.config ?? {}
141
+ ),
142
+ spec.name
143
+ );
144
+ if (msg.configModule) {
145
+ import(msg.configModule).then((module) => {
146
+ if (module && typeof module.default === "function") {
147
+ config.config_file = module.default(config.config_file);
148
+ }
149
+ resolve(spec);
150
+ }).catch((err) => {
151
+ reject(
152
+ new Error(
153
+ `Failed to load configModule for ${name}: ${err.message}`
154
+ )
155
+ );
156
+ });
157
+ } else {
158
+ resolve(spec);
159
+ }
160
+ return;
161
+ }
162
+ if (msg.type === "response") {
163
+ const pending = pendingRequests.get(msg.id);
164
+ if (!pending)
165
+ return;
166
+ clearTimeout(pending.timeout);
167
+ pendingRequests.delete(msg.id);
168
+ if (msg.error) {
169
+ const errors = Array.isArray(msg.error) ? msg.error : [msg.error];
170
+ errors.forEach((error) => {
171
+ format_hook_error(config.root_dir, error, name, pending.hook);
172
+ });
173
+ pending.reject(new Error(`Failed to call ${name}`));
174
+ } else {
175
+ pending.resolve(msg.result);
176
+ }
177
+ } else if (msg.type === "invoke") {
178
+ if (!triggerHookRef.fn) {
179
+ const reply = `${JSON.stringify({
180
+ id: msg.id,
181
+ type: "invoke_result",
182
+ error: { message: "orchestrator not ready" }
183
+ })}
184
+ `;
185
+ child.stdin?.write(reply);
186
+ return;
187
+ }
188
+ triggerHookRef.fn(msg.hook, {
189
+ parallel_safe: msg.parallel,
190
+ payload: msg.payload,
191
+ task_id: msg.taskId
192
+ }).then((result) => {
193
+ const reply = JSON.stringify({ id: msg.id, type: "invoke_result", result }) + "\n";
194
+ child.stdin?.write(reply);
195
+ }).catch((err) => {
196
+ const reply = `${JSON.stringify({
197
+ id: msg.id,
198
+ type: "invoke_result",
199
+ error: { message: err.message }
200
+ })}
201
+ `;
202
+ child.stdin?.write(reply);
203
+ });
204
+ }
205
+ } catch (err) {
206
+ if (!registered) {
207
+ reject(err instanceof Error ? err : new Error(String(err)));
208
+ }
209
+ }
210
+ });
211
+ rl.on("close", () => {
212
+ if (!registered) {
213
+ clearTimeout(timeout);
214
+ reject(new Error(`Plugin ${name} stdout closed before registering`));
215
+ } else {
216
+ for (const [id, pending] of pendingRequests.entries()) {
217
+ if (pending.plugin !== name)
218
+ continue;
219
+ clearTimeout(pending.timeout);
220
+ pendingRequests.delete(id);
221
+ pending.reject(new Error(`Plugin ${name} closed unexpectedly`));
222
+ }
223
+ }
224
+ });
225
+ });
226
+ db.prepare("DELETE FROM plugins").run();
227
+ logger.time("Start Plugins");
228
+ await Promise.all(
229
+ config.plugins.map(async (plugin) => {
230
+ let executable = plugin.executable;
231
+ const args = ["--database", db_file];
232
+ const jsExtensions = [".js", ".mjs", ".cjs"];
233
+ if (jsExtensions.includes(path.extname(plugin.executable))) {
234
+ executable = "node";
235
+ args.unshift(plugin.executable);
236
+ }
237
+ const dbKey = plugin_db_key(plugin.name);
238
+ args.push("--plugin-key", dbKey);
239
+ if (useStdio) {
240
+ args.push("--transport", "stdio");
241
+ }
242
+ logger.time(`Spawn ${plugin.name}`);
243
+ const child = spawn(executable, args, {
244
+ stdio: useStdio ? ["pipe", "pipe", "inherit"] : ["inherit", "inherit", "inherit"],
245
+ detached: process.platform !== "win32"
246
+ });
247
+ if (useStdio) {
248
+ stdioStdin.set(dbKey, child.stdin);
249
+ child.stdin.on("error", (err) => {
250
+ if (err.code !== "EPIPE") {
251
+ console.error(`[${plugin.name}] stdin error:`, err.message);
252
+ }
253
+ });
254
+ }
255
+ plugins[plugin.name] = {
256
+ process: child,
257
+ ...await (useStdio ? wait_for_plugin_stdio(plugin.name, child) : wait_for_plugin_db(plugin.name, dbKey))
258
+ };
259
+ logger.timeEnd(`Spawn ${plugin.name}`, LogLevel.Verbose);
260
+ })
261
+ );
262
+ for (const plugin of config.plugins) {
263
+ plugin_specs.push(spec_results[plugin.name]);
264
+ }
265
+ logger.timeEnd("Start Plugins", LogLevel.Summary);
266
+ const wsConnections = /* @__PURE__ */ new Map();
267
+ let messageCounter = 0;
268
+ const pendingRequests = /* @__PURE__ */ new Map();
269
+ async function getOrCreateWS(name, port) {
270
+ const existing = wsConnections.get(name);
271
+ if (existing && existing.readyState === WebSocket.OPEN) {
272
+ return existing;
273
+ }
274
+ return new Promise((resolve, reject) => {
275
+ const wsUrl = `ws://localhost:${port}/ws`;
276
+ const ws = new WebSocket(wsUrl);
277
+ ws.on("open", () => {
278
+ wsConnections.set(name, ws);
279
+ return resolve(ws);
280
+ });
281
+ ws.on("message", (data) => {
282
+ try {
283
+ const response = JSON.parse(data.toString());
284
+ const pending = pendingRequests.get(response.id);
285
+ if (!pending)
286
+ return;
287
+ clearTimeout(pending.timeout);
288
+ pendingRequests.delete(response.id);
289
+ switch (response.type) {
290
+ case "error":
291
+ console.error(`! [${name}] ${response.error}`);
292
+ pending.reject(new Error(`${name}: ${response.error}`));
293
+ break;
294
+ case "response":
295
+ if (response.error) {
296
+ const errors = Array.isArray(response.error) ? response.error : [response.error];
297
+ errors.forEach((error) => {
298
+ format_hook_error(config.root_dir, error, name, pending.hook);
299
+ });
300
+ pending.reject(new Error(`Failed to call ${name}`));
301
+ } else {
302
+ pending.resolve(response.result);
303
+ }
304
+ break;
305
+ default:
306
+ console.warn(`[${name}] Unknown message type: ${response.type}`);
307
+ pending.reject(new Error(`Unknown message type: ${response.type}`));
308
+ }
309
+ } catch (err) {
310
+ console.error(`Error processing WebSocket message for ${name}:`, err);
311
+ }
312
+ });
313
+ ws.on("error", (err) => {
314
+ console.error(`WebSocket error for ${name}:`, err);
315
+ wsConnections.delete(name);
316
+ reject(new Error(`WebSocket error for ${name}: ${err}`));
317
+ });
318
+ ws.on("close", () => {
319
+ wsConnections.delete(name);
320
+ });
321
+ });
322
+ }
323
+ const invoke_hook = async (name, hook, payload = {}, task_id) => {
324
+ const plugin = plugin_specs.find((spec) => spec.name === name);
325
+ if (!plugin) {
326
+ throw new Error(`unknown plugin: ${name}`);
327
+ }
328
+ const { port, directory } = plugin;
329
+ const messageId = String(++messageCounter);
330
+ const message = {
331
+ id: messageId,
332
+ type: "request",
333
+ hook,
334
+ payload,
335
+ taskId: task_id,
336
+ pluginDirectory: directory
337
+ };
338
+ if (useStdio) {
339
+ const stdin = stdioStdin.get(name);
340
+ if (!stdin) {
341
+ throw new Error(`No stdio channel for plugin ${name}`);
342
+ }
343
+ return new Promise((resolve, reject) => {
344
+ const timeout = setTimeout(() => {
345
+ pendingRequests.delete(messageId);
346
+ reject(new Error(`Request timeout for ${name}/${hook}`));
347
+ }, 3e4);
348
+ pendingRequests.set(messageId, { resolve, reject, timeout, hook, plugin: name });
349
+ stdin.write(`${JSON.stringify(message)}
350
+ `);
351
+ });
352
+ } else {
353
+ const ws = await getOrCreateWS(name, port);
354
+ return new Promise((resolve, reject) => {
355
+ const timeout = setTimeout(() => {
356
+ pendingRequests.delete(messageId);
357
+ reject(new Error(`WebSocket request timeout for ${name}/${hook}`));
358
+ }, 3e4);
359
+ pendingRequests.set(messageId, { resolve, reject, timeout, hook, plugin: name });
360
+ ws.send(JSON.stringify(message));
361
+ });
362
+ }
363
+ };
364
+ const trigger_hook = async (hook, {
365
+ parallel_safe,
366
+ payload,
367
+ task_id
368
+ } = {}) => {
369
+ const timeName = hook + (task_id ? ` (${task_id})` : "");
370
+ logger.time(timeName);
371
+ const plugins2 = plugin_specs.filter(({ hooks }) => hooks.has(hook));
372
+ const result = {};
373
+ try {
374
+ if (parallel_safe) {
375
+ await Promise.all(
376
+ plugins2.map(async (plugin) => {
377
+ result[plugin.name] = await invoke_hook(plugin.name, hook, payload, task_id);
378
+ })
379
+ );
380
+ } else {
381
+ for (const { name } of plugins2) {
382
+ result[name] = await invoke_hook(name, hook, payload, task_id);
383
+ }
384
+ }
385
+ } finally {
386
+ logger.timeEnd(timeName, task_id ? LogLevel.Verbose : LogLevel.Summary);
387
+ }
388
+ return result;
389
+ };
390
+ triggerHookRef.fn = trigger_hook;
391
+ await write_config(db, config, invoke_hook, plugin_specs, mode, logger);
392
+ await trigger_hook("Config");
393
+ await trigger_hook("AfterLoad");
394
+ await trigger_hook("Schema");
395
+ return {
396
+ database_path: db_file,
397
+ trigger_hook,
398
+ run_pipeline: (options) => run_pipeline(trigger_hook, options),
399
+ close: async () => {
400
+ for (const [name, ws] of wsConnections.entries()) {
401
+ try {
402
+ if (ws.readyState === WebSocket.OPEN) {
403
+ ws.close(1001, "shutdown");
404
+ }
405
+ } catch (err) {
406
+ console.error(`Error closing WebSocket for ${name}:`, err);
407
+ }
408
+ }
409
+ wsConnections.clear();
410
+ for (const [, stdin] of stdioStdin.entries()) {
411
+ try {
412
+ stdin.end();
413
+ } catch {
414
+ }
415
+ }
416
+ stdioStdin.clear();
417
+ for (const [, { timeout, reject }] of pendingRequests.entries()) {
418
+ clearTimeout(timeout);
419
+ reject(new Error("codegen closed"));
420
+ }
421
+ pendingRequests.clear();
422
+ await new Promise((resolve) => setTimeout(resolve, 100));
423
+ try {
424
+ db.close();
425
+ } catch {
426
+ }
427
+ await Promise.all(
428
+ Object.entries(plugins).map(async ([, plugin]) => {
429
+ if (plugin.process.pid) {
430
+ if (process.platform === "win32") {
431
+ try {
432
+ spawn("taskkill", [
433
+ "/pid",
434
+ plugin.process.pid.toString(),
435
+ "/f",
436
+ "/t"
437
+ ]);
438
+ } catch (_err) {
439
+ }
440
+ } else {
441
+ try {
442
+ process.kill(plugin.process.pid, 0);
443
+ process.kill(-plugin.process.pid, "SIGINT");
444
+ } catch {
445
+ }
446
+ }
447
+ }
448
+ })
449
+ );
450
+ }
451
+ };
452
+ }
453
+ const PIPELINE_HOOKS = [
454
+ "Config",
455
+ "AfterLoad",
456
+ "Schema",
457
+ "ExtractDocuments",
458
+ "AfterExtract",
459
+ "BeforeValidate",
460
+ "Validate",
461
+ "AfterValidate",
462
+ "BeforeGenerate",
463
+ "GenerateDocuments",
464
+ "GenerateRuntime",
465
+ "AfterGenerate"
466
+ ];
467
+ async function run_pipeline(trigger_hook, options = {}) {
468
+ const { task_id, after, start, through } = options;
469
+ const results = {};
470
+ let startIndex = 0;
471
+ let endIndex = PIPELINE_HOOKS.length - 1;
472
+ if (after) {
473
+ const afterIndex = PIPELINE_HOOKS.indexOf(after);
474
+ if (afterIndex === -1) {
475
+ throw new Error(`Unknown hook: ${after}`);
476
+ }
477
+ startIndex = afterIndex + 1;
478
+ }
479
+ if (start) {
480
+ const index = PIPELINE_HOOKS.indexOf(start);
481
+ if (index === -1) {
482
+ throw new Error(`Unknown hook: ${after}`);
483
+ }
484
+ startIndex = index;
485
+ }
486
+ if (through) {
487
+ endIndex = PIPELINE_HOOKS.indexOf(through);
488
+ if (endIndex === -1) {
489
+ throw new Error(`Unknown hook: ${through}`);
490
+ }
491
+ }
492
+ if (startIndex > endIndex) {
493
+ return results;
494
+ }
495
+ for (let i = startIndex; i <= endIndex; i++) {
496
+ const hook = PIPELINE_HOOKS[i];
497
+ const opts = { task_id };
498
+ if (hook === "Validate" || hook === "GenerateDocuments") {
499
+ opts.parallel_safe = true;
500
+ }
501
+ if (hook === "GenerateDocuments" && i + 1 <= endIndex && PIPELINE_HOOKS[i + 1] === "GenerateRuntime") {
502
+ const [gdResult, grResult] = await Promise.all([
503
+ trigger_hook("GenerateDocuments", { task_id, parallel_safe: true }),
504
+ trigger_hook("GenerateRuntime", { task_id })
505
+ ]);
506
+ results.GenerateDocuments = gdResult;
507
+ results.GenerateRuntime = grResult;
508
+ i++;
509
+ continue;
510
+ }
511
+ results[hook] = await trigger_hook(hook, opts);
512
+ }
513
+ return results;
514
+ }
515
+ export {
516
+ PIPELINE_HOOKS,
517
+ codegen_setup,
518
+ connect_db,
519
+ init_db,
520
+ plugin_db_key,
521
+ run_pipeline
522
+ };