ponder 0.9.4-debug.1 → 0.9.5-debug.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. package/CHANGELOG.md +2201 -0
  2. package/dist/esm/bin/commands/codegen.js +37 -0
  3. package/dist/esm/bin/commands/codegen.js.map +1 -0
  4. package/dist/esm/bin/commands/dev.js +242 -0
  5. package/dist/esm/bin/commands/dev.js.map +1 -0
  6. package/dist/esm/bin/commands/list.js +103 -0
  7. package/dist/esm/bin/commands/list.js.map +1 -0
  8. package/dist/esm/bin/commands/serve.js +123 -0
  9. package/dist/esm/bin/commands/serve.js.map +1 -0
  10. package/dist/esm/bin/commands/start.js +136 -0
  11. package/dist/esm/bin/commands/start.js.map +1 -0
  12. package/dist/esm/bin/ponder.js +118 -0
  13. package/dist/esm/bin/ponder.js.map +1 -0
  14. package/dist/esm/bin/utils/codegen.js +26 -0
  15. package/dist/esm/bin/utils/codegen.js.map +1 -0
  16. package/dist/esm/bin/utils/exit.js +69 -0
  17. package/dist/esm/bin/utils/exit.js.map +1 -0
  18. package/dist/esm/bin/utils/run.js +247 -0
  19. package/dist/esm/bin/utils/run.js.map +1 -0
  20. package/dist/esm/bin/utils/runServer.js +8 -0
  21. package/dist/esm/bin/utils/runServer.js.map +1 -0
  22. package/dist/esm/build/configAndIndexingFunctions.js +654 -0
  23. package/dist/esm/build/configAndIndexingFunctions.js.map +1 -0
  24. package/dist/esm/build/factory.js +43 -0
  25. package/dist/esm/build/factory.js.map +1 -0
  26. package/dist/esm/build/index.js +431 -0
  27. package/dist/esm/build/index.js.map +1 -0
  28. package/dist/esm/build/plugin.js +43 -0
  29. package/dist/esm/build/plugin.js.map +1 -0
  30. package/dist/esm/build/pre.js +112 -0
  31. package/dist/esm/build/pre.js.map +1 -0
  32. package/dist/esm/build/schema.js +89 -0
  33. package/dist/esm/build/schema.js.map +1 -0
  34. package/dist/esm/build/stacktrace.js +137 -0
  35. package/dist/esm/build/stacktrace.js.map +1 -0
  36. package/dist/esm/client/index.js +124 -0
  37. package/dist/esm/client/index.js.map +1 -0
  38. package/dist/esm/client/validate.js +1151 -0
  39. package/dist/esm/client/validate.js.map +1 -0
  40. package/dist/esm/config/address.js +2 -0
  41. package/dist/esm/config/address.js.map +1 -0
  42. package/dist/esm/config/eventFilter.js +2 -0
  43. package/dist/esm/config/eventFilter.js.map +1 -0
  44. package/dist/esm/config/index.js +2 -0
  45. package/dist/esm/config/index.js.map +1 -0
  46. package/dist/esm/config/networks.js +120 -0
  47. package/dist/esm/config/networks.js.map +1 -0
  48. package/dist/esm/config/utilityTypes.js +2 -0
  49. package/dist/esm/config/utilityTypes.js.map +1 -0
  50. package/dist/esm/database/index.js +914 -0
  51. package/dist/esm/database/index.js.map +1 -0
  52. package/dist/esm/drizzle/bigint.js +36 -0
  53. package/dist/esm/drizzle/bigint.js.map +1 -0
  54. package/dist/esm/drizzle/hex.js +38 -0
  55. package/dist/esm/drizzle/hex.js.map +1 -0
  56. package/dist/esm/drizzle/index.js +43 -0
  57. package/dist/esm/drizzle/index.js.map +1 -0
  58. package/dist/esm/drizzle/kit/index.js +658 -0
  59. package/dist/esm/drizzle/kit/index.js.map +1 -0
  60. package/dist/esm/drizzle/onchain.js +102 -0
  61. package/dist/esm/drizzle/onchain.js.map +1 -0
  62. package/dist/esm/graphql/index.js +704 -0
  63. package/dist/esm/graphql/index.js.map +1 -0
  64. package/dist/esm/graphql/json.js +42 -0
  65. package/dist/esm/graphql/json.js.map +1 -0
  66. package/dist/esm/graphql/middleware.js +80 -0
  67. package/dist/esm/graphql/middleware.js.map +1 -0
  68. package/dist/esm/index.js +9 -0
  69. package/dist/esm/index.js.map +1 -0
  70. package/dist/esm/indexing/addStackTrace.js +54 -0
  71. package/dist/esm/indexing/addStackTrace.js.map +1 -0
  72. package/dist/esm/indexing/index.js +10 -0
  73. package/dist/esm/indexing/index.js.map +1 -0
  74. package/dist/esm/indexing/ponderActions.js +60 -0
  75. package/dist/esm/indexing/ponderActions.js.map +1 -0
  76. package/dist/esm/indexing/service.js +312 -0
  77. package/dist/esm/indexing/service.js.map +1 -0
  78. package/dist/esm/indexing-store/historical.js +591 -0
  79. package/dist/esm/indexing-store/historical.js.map +1 -0
  80. package/dist/esm/indexing-store/index.js +19 -0
  81. package/dist/esm/indexing-store/index.js.map +1 -0
  82. package/dist/esm/indexing-store/metadata.js +46 -0
  83. package/dist/esm/indexing-store/metadata.js.map +1 -0
  84. package/dist/esm/indexing-store/realtime.js +295 -0
  85. package/dist/esm/indexing-store/realtime.js.map +1 -0
  86. package/dist/esm/internal/common.js +2 -0
  87. package/dist/esm/internal/common.js.map +1 -0
  88. package/dist/esm/internal/errors.js +175 -0
  89. package/dist/esm/internal/errors.js.map +1 -0
  90. package/dist/esm/internal/logger.js +96 -0
  91. package/dist/esm/internal/logger.js.map +1 -0
  92. package/dist/esm/internal/metrics.js +569 -0
  93. package/dist/esm/internal/metrics.js.map +1 -0
  94. package/dist/esm/internal/options.js +69 -0
  95. package/dist/esm/internal/options.js.map +1 -0
  96. package/dist/esm/internal/shutdown.js +18 -0
  97. package/dist/esm/internal/shutdown.js.map +1 -0
  98. package/dist/esm/internal/telemetry.js +199 -0
  99. package/dist/esm/internal/telemetry.js.map +1 -0
  100. package/dist/esm/internal/types.js +2 -0
  101. package/dist/esm/internal/types.js.map +1 -0
  102. package/dist/esm/server/error.js +55 -0
  103. package/dist/esm/server/error.js.map +1 -0
  104. package/dist/esm/server/index.js +107 -0
  105. package/dist/esm/server/index.js.map +1 -0
  106. package/dist/esm/sync/abi.js +67 -0
  107. package/dist/esm/sync/abi.js.map +1 -0
  108. package/dist/esm/sync/events.js +607 -0
  109. package/dist/esm/sync/events.js.map +1 -0
  110. package/dist/esm/sync/filter.js +356 -0
  111. package/dist/esm/sync/filter.js.map +1 -0
  112. package/dist/esm/sync/fragments.js +300 -0
  113. package/dist/esm/sync/fragments.js.map +1 -0
  114. package/dist/esm/sync/index.js +1001 -0
  115. package/dist/esm/sync/index.js.map +1 -0
  116. package/dist/esm/sync/transport.js +94 -0
  117. package/dist/esm/sync/transport.js.map +1 -0
  118. package/dist/esm/sync-historical/index.js +590 -0
  119. package/dist/esm/sync-historical/index.js.map +1 -0
  120. package/dist/esm/sync-realtime/bloom.js +75 -0
  121. package/dist/esm/sync-realtime/bloom.js.map +1 -0
  122. package/dist/esm/sync-realtime/index.js +794 -0
  123. package/dist/esm/sync-realtime/index.js.map +1 -0
  124. package/dist/esm/sync-store/encoding.js +157 -0
  125. package/dist/esm/sync-store/encoding.js.map +1 -0
  126. package/dist/esm/sync-store/index.js +727 -0
  127. package/dist/esm/sync-store/index.js.map +1 -0
  128. package/dist/esm/sync-store/migrations.js +1186 -0
  129. package/dist/esm/sync-store/migrations.js.map +1 -0
  130. package/dist/esm/types/db.js +2 -0
  131. package/dist/esm/types/db.js.map +1 -0
  132. package/dist/esm/types/eth.js +2 -0
  133. package/dist/esm/types/eth.js.map +1 -0
  134. package/dist/esm/types/sync.js +2 -0
  135. package/dist/esm/types/sync.js.map +1 -0
  136. package/dist/esm/types/utils.js +2 -0
  137. package/dist/esm/types/utils.js.map +1 -0
  138. package/dist/esm/types/virtual.js +2 -0
  139. package/dist/esm/types/virtual.js.map +1 -0
  140. package/dist/esm/ui/ProgressBar.js +11 -0
  141. package/dist/esm/ui/ProgressBar.js.map +1 -0
  142. package/dist/esm/ui/Table.js +50 -0
  143. package/dist/esm/ui/Table.js.map +1 -0
  144. package/dist/esm/ui/app.js +113 -0
  145. package/dist/esm/ui/app.js.map +1 -0
  146. package/dist/esm/ui/graphiql.html.js +59 -0
  147. package/dist/esm/ui/graphiql.html.js.map +1 -0
  148. package/dist/esm/ui/index.js +21 -0
  149. package/dist/esm/ui/index.js.map +1 -0
  150. package/dist/esm/utils/bigint.js +37 -0
  151. package/dist/esm/utils/bigint.js.map +1 -0
  152. package/dist/esm/utils/chains.js +3 -0
  153. package/dist/esm/utils/chains.js.map +1 -0
  154. package/dist/esm/utils/checkpoint.js +114 -0
  155. package/dist/esm/utils/checkpoint.js.map +1 -0
  156. package/dist/esm/utils/chunk.js +8 -0
  157. package/dist/esm/utils/chunk.js.map +1 -0
  158. package/dist/esm/utils/date.js +27 -0
  159. package/dist/esm/utils/date.js.map +1 -0
  160. package/dist/esm/utils/debug.js +2 -0
  161. package/dist/esm/utils/debug.js.map +1 -0
  162. package/dist/esm/utils/dedupe.js +33 -0
  163. package/dist/esm/utils/dedupe.js.map +1 -0
  164. package/dist/esm/utils/duplicates.js +19 -0
  165. package/dist/esm/utils/duplicates.js.map +1 -0
  166. package/dist/esm/utils/estimate.js +6 -0
  167. package/dist/esm/utils/estimate.js.map +1 -0
  168. package/dist/esm/utils/extend.js +28 -0
  169. package/dist/esm/utils/extend.js.map +1 -0
  170. package/dist/esm/utils/format.js +20 -0
  171. package/dist/esm/utils/format.js.map +1 -0
  172. package/dist/esm/utils/generators.js +77 -0
  173. package/dist/esm/utils/generators.js.map +1 -0
  174. package/dist/esm/utils/hash.js +11 -0
  175. package/dist/esm/utils/hash.js.map +1 -0
  176. package/dist/esm/utils/interval.js +171 -0
  177. package/dist/esm/utils/interval.js.map +1 -0
  178. package/dist/esm/utils/lowercase.js +7 -0
  179. package/dist/esm/utils/lowercase.js.map +1 -0
  180. package/dist/esm/utils/mutex.js +25 -0
  181. package/dist/esm/utils/mutex.js.map +1 -0
  182. package/dist/esm/utils/never.js +4 -0
  183. package/dist/esm/utils/never.js.map +1 -0
  184. package/dist/esm/utils/offset.js +73 -0
  185. package/dist/esm/utils/offset.js.map +1 -0
  186. package/dist/esm/utils/order.js +18 -0
  187. package/dist/esm/utils/order.js.map +1 -0
  188. package/dist/esm/utils/partition.js +37 -0
  189. package/dist/esm/utils/partition.js.map +1 -0
  190. package/dist/esm/utils/pg.js +126 -0
  191. package/dist/esm/utils/pg.js.map +1 -0
  192. package/dist/esm/utils/pglite.js +80 -0
  193. package/dist/esm/utils/pglite.js.map +1 -0
  194. package/dist/esm/utils/port.js +30 -0
  195. package/dist/esm/utils/port.js.map +1 -0
  196. package/dist/esm/utils/print.js +23 -0
  197. package/dist/esm/utils/print.js.map +1 -0
  198. package/dist/esm/utils/promiseWithResolvers.js +13 -0
  199. package/dist/esm/utils/promiseWithResolvers.js.map +1 -0
  200. package/dist/esm/utils/queue.js +145 -0
  201. package/dist/esm/utils/queue.js.map +1 -0
  202. package/dist/esm/utils/range.js +8 -0
  203. package/dist/esm/utils/range.js.map +1 -0
  204. package/dist/esm/utils/requestQueue.js +127 -0
  205. package/dist/esm/utils/requestQueue.js.map +1 -0
  206. package/dist/esm/utils/result.js +10 -0
  207. package/dist/esm/utils/result.js.map +1 -0
  208. package/dist/esm/utils/rpc.js +202 -0
  209. package/dist/esm/utils/rpc.js.map +1 -0
  210. package/dist/esm/utils/serialize.js +23 -0
  211. package/dist/esm/utils/serialize.js.map +1 -0
  212. package/dist/esm/utils/timer.js +17 -0
  213. package/dist/esm/utils/timer.js.map +1 -0
  214. package/dist/esm/utils/wait.js +8 -0
  215. package/dist/esm/utils/wait.js.map +1 -0
  216. package/dist/esm/utils/zipper.js +67 -0
  217. package/dist/esm/utils/zipper.js.map +1 -0
  218. package/dist/types/bin/commands/codegen.d.ts +5 -0
  219. package/dist/types/bin/commands/codegen.d.ts.map +1 -0
  220. package/dist/types/bin/commands/dev.d.ts +5 -0
  221. package/dist/types/bin/commands/dev.d.ts.map +1 -0
  222. package/dist/types/bin/commands/list.d.ts +5 -0
  223. package/dist/types/bin/commands/list.d.ts.map +1 -0
  224. package/dist/types/bin/commands/serve.d.ts +5 -0
  225. package/dist/types/bin/commands/serve.d.ts.map +1 -0
  226. package/dist/types/bin/commands/start.d.ts +5 -0
  227. package/dist/types/bin/commands/start.d.ts.map +1 -0
  228. package/dist/{bin → types/bin}/ponder.d.ts +5 -6
  229. package/dist/types/bin/ponder.d.ts.map +1 -0
  230. package/dist/types/bin/utils/codegen.d.ts +6 -0
  231. package/dist/types/bin/utils/codegen.d.ts.map +1 -0
  232. package/dist/types/bin/utils/exit.d.ts +9 -0
  233. package/dist/types/bin/utils/exit.d.ts.map +1 -0
  234. package/dist/types/bin/utils/run.d.ts +14 -0
  235. package/dist/types/bin/utils/run.d.ts.map +1 -0
  236. package/dist/types/bin/utils/runServer.d.ts +12 -0
  237. package/dist/types/bin/utils/runServer.d.ts.map +1 -0
  238. package/dist/types/build/configAndIndexingFunctions.d.ts +37 -0
  239. package/dist/types/build/configAndIndexingFunctions.d.ts.map +1 -0
  240. package/dist/types/build/factory.d.ts +10 -0
  241. package/dist/types/build/factory.d.ts.map +1 -0
  242. package/dist/types/build/index.d.ts +70 -0
  243. package/dist/types/build/index.d.ts.map +1 -0
  244. package/dist/types/build/plugin.d.ts +4 -0
  245. package/dist/types/build/plugin.d.ts.map +1 -0
  246. package/dist/types/build/pre.d.ts +35 -0
  247. package/dist/types/build/pre.d.ts.map +1 -0
  248. package/dist/types/build/schema.d.ts +18 -0
  249. package/dist/types/build/schema.d.ts.map +1 -0
  250. package/dist/types/build/stacktrace.d.ts +13 -0
  251. package/dist/types/build/stacktrace.d.ts.map +1 -0
  252. package/dist/types/client/index.d.ts +27 -0
  253. package/dist/types/client/index.d.ts.map +1 -0
  254. package/dist/types/client/validate.d.ts +2 -0
  255. package/dist/types/client/validate.d.ts.map +1 -0
  256. package/dist/types/config/address.d.ts +14 -0
  257. package/dist/types/config/address.d.ts.map +1 -0
  258. package/dist/types/config/eventFilter.d.ts +18 -0
  259. package/dist/types/config/eventFilter.d.ts.map +1 -0
  260. package/dist/types/config/index.d.ts +143 -0
  261. package/dist/types/config/index.d.ts.map +1 -0
  262. package/dist/types/config/networks.d.ts +30 -0
  263. package/dist/types/config/networks.d.ts.map +1 -0
  264. package/dist/types/config/utilityTypes.d.ts +43 -0
  265. package/dist/types/config/utilityTypes.d.ts.map +1 -0
  266. package/dist/types/database/index.d.ts +91 -0
  267. package/dist/types/database/index.d.ts.map +1 -0
  268. package/dist/types/drizzle/bigint.d.ts +25 -0
  269. package/dist/types/drizzle/bigint.d.ts.map +1 -0
  270. package/dist/types/drizzle/hex.d.ts +25 -0
  271. package/dist/types/drizzle/hex.d.ts.map +1 -0
  272. package/dist/types/drizzle/index.d.ts +14 -0
  273. package/dist/types/drizzle/index.d.ts.map +1 -0
  274. package/dist/types/drizzle/kit/index.d.ts +49 -0
  275. package/dist/types/drizzle/kit/index.d.ts.map +1 -0
  276. package/dist/{drizzle → types/drizzle}/onchain.d.ts +49 -96
  277. package/dist/types/drizzle/onchain.d.ts.map +1 -0
  278. package/dist/types/graphql/index.d.ts +14 -0
  279. package/dist/types/graphql/index.d.ts.map +1 -0
  280. package/dist/types/graphql/json.d.ts +3 -0
  281. package/dist/types/graphql/json.d.ts.map +1 -0
  282. package/dist/types/graphql/middleware.d.ts +29 -0
  283. package/dist/types/graphql/middleware.d.ts.map +1 -0
  284. package/dist/types/index.d.ts +18 -0
  285. package/dist/types/index.d.ts.map +1 -0
  286. package/dist/types/indexing/addStackTrace.d.ts +3 -0
  287. package/dist/types/indexing/addStackTrace.d.ts.map +1 -0
  288. package/dist/types/indexing/index.d.ts +575 -0
  289. package/dist/types/indexing/index.d.ts.map +1 -0
  290. package/dist/types/indexing/ponderActions.d.ts +47 -0
  291. package/dist/types/indexing/ponderActions.d.ts.map +1 -0
  292. package/dist/types/indexing/service.d.ts +73 -0
  293. package/dist/types/indexing/service.d.ts.map +1 -0
  294. package/dist/types/indexing-store/historical.d.ts +19 -0
  295. package/dist/types/indexing-store/historical.d.ts.map +1 -0
  296. package/dist/types/indexing-store/index.d.ts +10 -0
  297. package/dist/types/indexing-store/index.d.ts.map +1 -0
  298. package/dist/types/indexing-store/metadata.d.ts +10 -0
  299. package/dist/types/indexing-store/metadata.d.ts.map +1 -0
  300. package/dist/types/indexing-store/realtime.d.ts +10 -0
  301. package/dist/types/indexing-store/realtime.d.ts.map +1 -0
  302. package/dist/types/internal/common.d.ts +13 -0
  303. package/dist/types/internal/common.d.ts.map +1 -0
  304. package/dist/types/internal/errors.d.ts +55 -0
  305. package/dist/types/internal/errors.d.ts.map +1 -0
  306. package/dist/types/internal/logger.d.ts +26 -0
  307. package/dist/types/internal/logger.d.ts.map +1 -0
  308. package/dist/types/internal/metrics.d.ts +77 -0
  309. package/dist/types/internal/metrics.d.ts.map +1 -0
  310. package/dist/types/internal/options.d.ts +59 -0
  311. package/dist/types/internal/options.d.ts.map +1 -0
  312. package/dist/types/internal/shutdown.d.ts +8 -0
  313. package/dist/types/internal/shutdown.d.ts.map +1 -0
  314. package/dist/types/internal/telemetry.d.ts +43 -0
  315. package/dist/types/internal/telemetry.d.ts.map +1 -0
  316. package/dist/types/internal/types.d.ts +328 -0
  317. package/dist/types/internal/types.d.ts.map +1 -0
  318. package/dist/types/server/error.d.ts +5 -0
  319. package/dist/types/server/error.d.ts.map +1 -0
  320. package/dist/types/server/index.d.ts +13 -0
  321. package/dist/types/server/index.d.ts.map +1 -0
  322. package/dist/types/sync/abi.d.ts +54 -0
  323. package/dist/types/sync/abi.d.ts.map +1 -0
  324. package/dist/types/sync/events.d.ts +24 -0
  325. package/dist/types/sync/events.d.ts.map +1 -0
  326. package/dist/types/sync/filter.d.ts +71 -0
  327. package/dist/types/sync/filter.d.ts.map +1 -0
  328. package/dist/types/sync/fragments.d.ts +21 -0
  329. package/dist/types/sync/fragments.d.ts.map +1 -0
  330. package/dist/types/sync/index.d.ts +112 -0
  331. package/dist/types/sync/index.d.ts.map +1 -0
  332. package/dist/types/sync/transport.d.ts +8 -0
  333. package/dist/types/sync/transport.d.ts.map +1 -0
  334. package/dist/types/sync-historical/index.d.ts +28 -0
  335. package/dist/types/sync-historical/index.d.ts.map +1 -0
  336. package/dist/types/sync-realtime/bloom.d.ts +19 -0
  337. package/dist/types/sync-realtime/bloom.d.ts.map +1 -0
  338. package/dist/types/sync-realtime/index.d.ts +48 -0
  339. package/dist/types/sync-realtime/index.d.ts.map +1 -0
  340. package/dist/types/sync-store/encoding.d.ts +151 -0
  341. package/dist/types/sync-store/encoding.d.ts.map +1 -0
  342. package/dist/types/sync-store/index.d.ts +104 -0
  343. package/dist/types/sync-store/index.d.ts.map +1 -0
  344. package/dist/types/sync-store/migrations.d.ts +13 -0
  345. package/dist/types/sync-store/migrations.d.ts.map +1 -0
  346. package/dist/types/types/db.d.ts +213 -0
  347. package/dist/types/types/db.d.ts.map +1 -0
  348. package/dist/types/types/eth.d.ts +196 -0
  349. package/dist/types/types/eth.d.ts.map +1 -0
  350. package/dist/types/types/sync.d.ts +15 -0
  351. package/dist/types/types/sync.d.ts.map +1 -0
  352. package/dist/types/types/utils.d.ts +22 -0
  353. package/dist/types/types/utils.d.ts.map +1 -0
  354. package/dist/types/types/virtual.d.ts +95 -0
  355. package/dist/types/types/virtual.d.ts.map +1 -0
  356. package/dist/types/ui/ProgressBar.d.ts +7 -0
  357. package/dist/types/ui/ProgressBar.d.ts.map +1 -0
  358. package/dist/types/ui/Table.d.ts +24 -0
  359. package/dist/types/ui/Table.d.ts.map +1 -0
  360. package/dist/types/ui/app.d.ts +14 -0
  361. package/dist/types/ui/app.d.ts.map +1 -0
  362. package/dist/types/ui/graphiql.html.d.ts +2 -0
  363. package/dist/types/ui/graphiql.html.d.ts.map +1 -0
  364. package/dist/types/ui/index.d.ts +5 -0
  365. package/dist/types/ui/index.d.ts.map +1 -0
  366. package/dist/types/utils/bigint.d.ts +15 -0
  367. package/dist/types/utils/bigint.d.ts.map +1 -0
  368. package/dist/types/utils/chains.d.ts +3 -0
  369. package/dist/types/utils/chains.d.ts.map +1 -0
  370. package/dist/types/utils/checkpoint.d.ts +40 -0
  371. package/dist/types/utils/checkpoint.d.ts.map +1 -0
  372. package/dist/types/utils/chunk.d.ts +2 -0
  373. package/dist/types/utils/chunk.d.ts.map +1 -0
  374. package/dist/types/utils/date.d.ts +7 -0
  375. package/dist/types/utils/date.d.ts.map +1 -0
  376. package/dist/types/utils/debug.d.ts +105 -0
  377. package/dist/types/utils/debug.d.ts.map +1 -0
  378. package/dist/types/utils/dedupe.d.ts +20 -0
  379. package/dist/types/utils/dedupe.d.ts.map +1 -0
  380. package/dist/types/utils/duplicates.d.ts +7 -0
  381. package/dist/types/utils/duplicates.d.ts.map +1 -0
  382. package/dist/types/utils/estimate.d.ts +11 -0
  383. package/dist/types/utils/estimate.d.ts.map +1 -0
  384. package/dist/types/utils/extend.d.ts +13 -0
  385. package/dist/types/utils/extend.d.ts.map +1 -0
  386. package/dist/types/utils/format.d.ts +3 -0
  387. package/dist/types/utils/format.d.ts.map +1 -0
  388. package/dist/types/utils/generators.d.ts +23 -0
  389. package/dist/types/utils/generators.d.ts.map +1 -0
  390. package/dist/types/utils/hash.d.ts +11 -0
  391. package/dist/types/utils/hash.d.ts.map +1 -0
  392. package/dist/types/utils/interval.d.ts +53 -0
  393. package/dist/types/utils/interval.d.ts.map +1 -0
  394. package/dist/types/utils/lowercase.d.ts +5 -0
  395. package/dist/types/utils/lowercase.d.ts.map +1 -0
  396. package/dist/types/utils/mutex.d.ts +8 -0
  397. package/dist/types/utils/mutex.d.ts.map +1 -0
  398. package/dist/types/utils/never.d.ts +2 -0
  399. package/dist/types/utils/never.d.ts.map +1 -0
  400. package/dist/types/utils/offset.d.ts +3 -0
  401. package/dist/types/utils/offset.d.ts.map +1 -0
  402. package/dist/types/utils/order.d.ts +2 -0
  403. package/dist/types/utils/order.d.ts.map +1 -0
  404. package/dist/types/utils/partition.d.ts +22 -0
  405. package/dist/types/utils/partition.d.ts.map +1 -0
  406. package/dist/types/utils/pg.d.ts +5 -0
  407. package/dist/types/utils/pg.d.ts.map +1 -0
  408. package/dist/types/utils/pglite.d.ts +25 -0
  409. package/dist/types/utils/pglite.d.ts.map +1 -0
  410. package/dist/types/utils/port.d.ts +5 -0
  411. package/dist/types/utils/port.d.ts.map +1 -0
  412. package/dist/types/utils/print.d.ts +2 -0
  413. package/dist/types/utils/print.d.ts.map +1 -0
  414. package/dist/types/utils/promiseWithResolvers.d.ts +10 -0
  415. package/dist/types/utils/promiseWithResolvers.d.ts.map +1 -0
  416. package/dist/types/utils/queue.d.ts +33 -0
  417. package/dist/types/utils/queue.d.ts.map +1 -0
  418. package/dist/types/utils/range.d.ts +8 -0
  419. package/dist/types/utils/range.d.ts.map +1 -0
  420. package/dist/types/utils/requestQueue.d.ts +21 -0
  421. package/dist/types/utils/requestQueue.d.ts.map +1 -0
  422. package/dist/types/utils/result.d.ts +17 -0
  423. package/dist/types/utils/result.d.ts.map +1 -0
  424. package/dist/types/utils/rpc.d.ts +57 -0
  425. package/dist/types/utils/rpc.d.ts.map +1 -0
  426. package/dist/types/utils/serialize.d.ts +19 -0
  427. package/dist/types/utils/serialize.d.ts.map +1 -0
  428. package/dist/types/utils/timer.d.ts +11 -0
  429. package/dist/types/utils/timer.d.ts.map +1 -0
  430. package/dist/types/utils/wait.d.ts +6 -0
  431. package/dist/types/utils/wait.d.ts.map +1 -0
  432. package/dist/types/utils/zipper.d.ts +36 -0
  433. package/dist/types/utils/zipper.d.ts.map +1 -0
  434. package/package.json +17 -21
  435. package/src/bin/commands/dev.ts +1 -1
  436. package/src/bin/ponder.ts +1 -1
  437. package/src/bin/utils/run.ts +7 -18
  438. package/src/build/configAndIndexingFunctions.ts +1 -1
  439. package/src/build/factory.ts +1 -1
  440. package/src/build/index.ts +0 -2
  441. package/src/client/index.ts +1 -1
  442. package/src/graphql/index.ts +1 -1
  443. package/src/indexing-store/historical.ts +1 -1
  444. package/src/indexing-store/realtime.ts +1 -1
  445. package/src/internal/telemetry.ts +1 -1
  446. package/src/sync/fragments.ts +1 -1
  447. package/src/sync/index.ts +60 -20
  448. package/src/sync-historical/index.ts +26 -26
  449. package/src/sync-realtime/index.ts +1 -1
  450. package/src/utils/dedupe.ts +40 -0
  451. package/src/utils/generators.ts +1 -1
  452. package/src/utils/mutex.ts +1 -1
  453. package/src/utils/promiseWithResolvers.ts +20 -0
  454. package/src/utils/queue.ts +250 -0
  455. package/src/utils/requestQueue.ts +1 -1
  456. package/dist/bin/ponder.js +0 -11243
  457. package/dist/bin/ponder.js.map +0 -1
  458. package/dist/chunk-6AOFLZJ4.js +0 -1692
  459. package/dist/chunk-6AOFLZJ4.js.map +0 -1
  460. package/dist/chunk-DZFRP3KH.js +0 -70
  461. package/dist/chunk-DZFRP3KH.js.map +0 -1
  462. package/dist/chunk-K2TLRLX3.js +0 -163
  463. package/dist/chunk-K2TLRLX3.js.map +0 -1
  464. package/dist/chunk-MJKRYIBO.js +0 -190
  465. package/dist/chunk-MJKRYIBO.js.map +0 -1
  466. package/dist/db-in86nyw7.d.ts +0 -625
  467. package/dist/drizzle/onchain.js +0 -19
  468. package/dist/drizzle/onchain.js.map +0 -1
  469. package/dist/experimental_unsafe_stores.d.ts +0 -375
  470. package/dist/experimental_unsafe_stores.js +0 -11
  471. package/dist/experimental_unsafe_stores.js.map +0 -1
  472. package/dist/index.d.ts +0 -404
  473. package/dist/index.js +0 -2219
  474. package/dist/index.js.map +0 -1
  475. package/dist/utils-ceNucOJb.d.ts +0 -14
  476. package/src/experimental_unsafe_stores.ts +0 -4
package/dist/index.js DELETED
@@ -1,2219 +0,0 @@
1
- import {
2
- deserialize,
3
- getMetadataStore,
4
- never,
5
- serialize
6
- } from "./chunk-DZFRP3KH.js";
7
- import {
8
- promiseWithResolvers
9
- } from "./chunk-MJKRYIBO.js";
10
- import {
11
- bigint,
12
- hex,
13
- onchainEnum,
14
- onchainTable,
15
- primaryKey
16
- } from "./chunk-K2TLRLX3.js";
17
-
18
- // src/config/index.ts
19
- var createConfig = (config) => config;
20
-
21
- // src/config/address.ts
22
- var factory = (factory2) => factory2;
23
-
24
- // src/index.ts
25
- import {
26
- mergeAbis,
27
- loadBalance,
28
- rateLimit,
29
- replaceBigInts
30
- } from "@ponder/utils";
31
-
32
- // src/client/index.ts
33
- import { pgTable } from "drizzle-orm/pg-core";
34
- import { createMiddleware } from "hono/factory";
35
- import { streamSSE } from "hono/streaming";
36
- import superjson from "superjson";
37
-
38
- // src/client/validate.ts
39
- var getNodeType = (node) => Object.keys(node)[0];
40
- var ALLOW_CACHE = /* @__PURE__ */ new Map();
41
- var validateQuery = async (sql2) => {
42
- const Parser = await import(
43
- /* webpackIgnore: true */
44
- "pg-query-emscripten"
45
- );
46
- const crypto = await import(
47
- /* webpackIgnore: true */
48
- "node:crypto"
49
- );
50
- const hash = crypto.createHash("sha256").update(sql2).digest("hex").slice(0, 10);
51
- if (ALLOW_CACHE.has(hash)) {
52
- const result = ALLOW_CACHE.get(hash);
53
- ALLOW_CACHE.delete(hash);
54
- ALLOW_CACHE.set(hash, result);
55
- if (result)
56
- return;
57
- throw new Error("Invalid query");
58
- } else {
59
- ALLOW_CACHE.set(hash, false);
60
- }
61
- const { parse } = await Parser.default();
62
- const parseResult = parse(sql2);
63
- if (parseResult.error !== null) {
64
- throw new Error(parseResult.error);
65
- }
66
- if (parseResult.parse_tree.stmts.length === 0) {
67
- throw new Error("Invalid query");
68
- }
69
- if (parseResult.parse_tree.stmts.length > 1) {
70
- throw new Error("Multiple statements not supported");
71
- }
72
- const stmt = parseResult.parse_tree.stmts[0];
73
- if (stmt.stmt === void 0) {
74
- throw new Error("Invalid query");
75
- }
76
- const validate = (node) => {
77
- if (ALLOW_LIST.has(getNodeType(node)) === false) {
78
- throw new Error(`${getNodeType(node)} not supported`);
79
- }
80
- ALLOW_LIST.get(getNodeType(node)).validate?.(node[getNodeType(node)]);
81
- for (const child of ALLOW_LIST.get(getNodeType(node)).children(
82
- // @ts-ignore
83
- node[getNodeType(node)]
84
- )) {
85
- validate(child);
86
- }
87
- };
88
- validate(stmt.stmt);
89
- ALLOW_CACHE.set(hash, true);
90
- if (ALLOW_CACHE.size > 1e6) {
91
- const firstKey = ALLOW_CACHE.keys().next().value;
92
- if (firstKey)
93
- ALLOW_CACHE.delete(firstKey);
94
- }
95
- };
96
- var INTEGER_VALIDATOR = {
97
- node: "Integer",
98
- children: () => []
99
- };
100
- var FLOAT_VALIDATOR = {
101
- node: "Float",
102
- children: () => []
103
- };
104
- var BOOLEAN_VALIDATOR = {
105
- node: "Boolean",
106
- children: () => []
107
- };
108
- var STRING_VALIDATOR = {
109
- node: "String",
110
- children: () => []
111
- };
112
- var BIT_STRING_VALIDATOR = {
113
- node: "BitString",
114
- children: () => []
115
- };
116
- var LIST_VALIDATOR = {
117
- node: "List",
118
- children: (node) => [...node.items ?? []]
119
- };
120
- var OID_LIST_VALIDATOR = {
121
- node: "OidList",
122
- children: (node) => [...node.items ?? []]
123
- };
124
- var INT_LIST_VALIDATOR = {
125
- node: "IntList",
126
- children: (node) => [...node.items ?? []]
127
- };
128
- var A_CONST_VALIDATOR = {
129
- node: "A_Const",
130
- children: () => []
131
- };
132
- var ALIAS_VALIDATOR = {
133
- node: "Alias",
134
- children: (node) => [...node.colnames ?? []]
135
- };
136
- var RANGE_VAR_VALIDATOR = {
137
- node: "RangeVar",
138
- children: (node) => [...node.alias ? [{ Alias: node.alias }] : []],
139
- validate: (node) => {
140
- if (node.schemaname) {
141
- throw new Error("Schema name not supported");
142
- }
143
- if (node.relname && SYSTEM_TABLES.has(node.relname)) {
144
- throw new Error("System tables not supported");
145
- }
146
- }
147
- };
148
- var VAR_VALIDATOR = {
149
- node: "Var",
150
- children: (node) => [...node.xpr ? [node.xpr] : []]
151
- };
152
- var PARAM_VALIDATOR = {
153
- node: "Param",
154
- children: (node) => [...node.xpr ? [node.xpr] : []]
155
- };
156
- var AGGREF_VALIDATOR = {
157
- node: "Aggref",
158
- children: (node) => [
159
- ...node.aggargtypes ?? [],
160
- ...node.aggdirectargs ?? [],
161
- ...node.args ?? [],
162
- ...node.aggorder ?? [],
163
- ...node.aggdistinct ?? [],
164
- ...node.aggfilter ? [node.aggfilter] : []
165
- ]
166
- };
167
- var GROUPING_FUNC_VALIDATOR = {
168
- node: "GroupingFunc",
169
- children: (node) => [...node.args ?? [], ...node.refs ?? []]
170
- };
171
- var WINDOW_FUNC_VALIDATOR = {
172
- node: "WindowFunc",
173
- children: (node) => [
174
- ...node.args ?? [],
175
- ...node.aggfilter ? [node.aggfilter] : []
176
- ]
177
- };
178
- var NAMED_ARG_EXPR_VALIDATOR = {
179
- node: "NamedArgExpr",
180
- children: (node) => [
181
- ...node.xpr ? [node.xpr] : [],
182
- ...node.arg ? [node.arg] : []
183
- ]
184
- };
185
- var OP_EXPR_VALIDATOR = {
186
- node: "OpExpr",
187
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
188
- };
189
- var DISTINCT_EXPR_VALIDATOR = {
190
- node: "DistinctExpr",
191
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
192
- };
193
- var NULL_IF_EXPR_VALIDATOR = {
194
- node: "NullIfExpr",
195
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
196
- };
197
- var SCALAR_ARRAY_OP_EXPR_VALIDATOR = {
198
- node: "ScalarArrayOpExpr",
199
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
200
- };
201
- var BOOL_EXPR_VALIDATOR = {
202
- node: "BoolExpr",
203
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
204
- };
205
- var FIELD_SELECT_VALIDATOR = {
206
- node: "FieldSelect",
207
- children: (node) => [
208
- ...node.xpr ? [node.xpr] : [],
209
- ...node.arg ? [node.arg] : []
210
- ]
211
- };
212
- var RELABEL_TYPE_VALIDATOR = {
213
- node: "RelabelType",
214
- children: (node) => [
215
- ...node.xpr ? [node.xpr] : [],
216
- ...node.arg ? [node.arg] : []
217
- ]
218
- };
219
- var ARRAY_COERCE_EXPR_VALIDATOR = {
220
- node: "ArrayCoerceExpr",
221
- children: (node) => [
222
- ...node.xpr ? [node.xpr] : [],
223
- ...node.arg ? [node.arg] : [],
224
- ...node.elemexpr ? [node.elemexpr] : []
225
- ]
226
- };
227
- var CONVERT_ROWTYPE_EXPR_VALIDATOR = {
228
- node: "ConvertRowtypeExpr",
229
- children: (node) => [
230
- ...node.xpr ? [node.xpr] : [],
231
- ...node.arg ? [node.arg] : []
232
- ]
233
- };
234
- var COLLATE_EXPR_VALIDATOR = {
235
- node: "CollateExpr",
236
- children: (node) => [
237
- ...node.xpr ? [node.xpr] : [],
238
- ...node.arg ? [node.arg] : []
239
- ]
240
- };
241
- var CASE_EXPR_VALIDATOR = {
242
- node: "CaseExpr",
243
- children: (node) => [
244
- ...node.xpr ? [node.xpr] : [],
245
- ...node.arg ? [node.arg] : [],
246
- ...node.args ?? [],
247
- ...node.defresult ? [node.defresult] : []
248
- ]
249
- };
250
- var CASE_WHEN_VALIDATOR = {
251
- node: "CaseWhen",
252
- children: (node) => [
253
- ...node.xpr ? [node.xpr] : [],
254
- ...node.expr ? [node.expr] : [],
255
- ...node.result ? [node.result] : []
256
- ]
257
- };
258
- var CASE_TEST_EXPR_VALIDATOR = {
259
- node: "CaseTestExpr",
260
- children: (node) => [...node.xpr ? [node.xpr] : []]
261
- };
262
- var ARRAY_EXPR_VALIDATOR = {
263
- node: "ArrayExpr",
264
- children: (node) => [
265
- ...node.xpr ? [node.xpr] : [],
266
- ...node.elements ?? []
267
- ]
268
- };
269
- var ROW_EXPR_VALIDATOR = {
270
- node: "RowExpr",
271
- children: (node) => [
272
- ...node.xpr ? [node.xpr] : [],
273
- ...node.args ?? [],
274
- ...node.colnames ?? []
275
- ]
276
- };
277
- var ROW_COMPARE_EXPR_VALIDATOR = {
278
- node: "RowCompareExpr",
279
- children: (node) => [
280
- ...node.xpr ? [node.xpr] : [],
281
- ...node.opnos ?? [],
282
- ...node.opfamilies ?? [],
283
- ...node.inputcollids ?? [],
284
- ...node.largs ?? [],
285
- ...node.rargs ?? []
286
- ]
287
- };
288
- var COALESC_EXPR_VALIDATOR = {
289
- node: "CoalesceExpr",
290
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
291
- };
292
- var MIN_MAX_EXPR_VALIDATOR = {
293
- node: "MinMaxExpr",
294
- children: (node) => [...node.xpr ? [node.xpr] : [], ...node.args ?? []]
295
- };
296
- var SQL_VALUE_FUNCTION_VALIDATOR = {
297
- node: "SQLValueFunction",
298
- children: (node) => [...node.xpr ? [node.xpr] : []]
299
- };
300
- var JSON_FORMAT_VALIDATOR = {
301
- node: "JsonFormat",
302
- children: () => []
303
- };
304
- var JSON_RETURNING_VALIDATOR = {
305
- node: "JsonReturning",
306
- children: (node) => [...node.format ? [{ JsonFormat: node.format }] : []]
307
- };
308
- var JSON_VALUE_EXPR_VALIDATOR = {
309
- node: "JsonValueExpr",
310
- children: (node) => [
311
- ...node.raw_expr ? [node.raw_expr] : [],
312
- ...node.formatted_expr ? [node.formatted_expr] : [],
313
- ...node.format ? [{ JsonFormat: node.format }] : []
314
- ]
315
- };
316
- var JSON_CONSTRUCTOR_EXPR_VALIDATOR = {
317
- node: "JsonConstructorExpr",
318
- children: (node) => [
319
- ...node.xpr ? [node.xpr] : [],
320
- ...node.args ?? [],
321
- ...node.func ? [node.func] : [],
322
- ...node.coercion ? [node.coercion] : [],
323
- ...node.returning ? [{ JsonReturning: node.returning }] : []
324
- ]
325
- };
326
- var JSON_IS_PREDICATE_VALIDATOR = {
327
- node: "JsonIsPredicate",
328
- children: (node) => [
329
- ...node.expr ? [node.expr] : [],
330
- ...node.format ? [{ JsonFormat: node.format }] : []
331
- ]
332
- };
333
- var NULL_TEST_VALIDATOR = {
334
- node: "NullTest",
335
- children: (node) => [
336
- ...node.xpr ? [node.xpr] : [],
337
- ...node.arg ? [node.arg] : []
338
- ]
339
- };
340
- var BOOLEAN_TEST_VALIDATOR = {
341
- node: "BooleanTest",
342
- children: (node) => [
343
- ...node.xpr ? [node.xpr] : [],
344
- ...node.arg ? [node.arg] : []
345
- ]
346
- };
347
- var COERCE_TO_DOMAIN_VALIDATOR = {
348
- node: "CoerceToDomain",
349
- children: (node) => [
350
- ...node.xpr ? [node.xpr] : [],
351
- ...node.arg ? [node.arg] : []
352
- ]
353
- };
354
- var COERCE_TO_DOMAIN_VALUE_VALIDATOR = {
355
- node: "CoerceToDomainValue",
356
- children: (node) => [...node.xpr ? [node.xpr] : []]
357
- };
358
- var CURRENT_OF_EXPR_VALIDATOR = {
359
- node: "CurrentOfExpr",
360
- children: (node) => [...node.xpr ? [node.xpr] : []]
361
- };
362
- var NEXT_VALUE_EXPR_VALIDATOR = {
363
- node: "NextValueExpr",
364
- children: (node) => [...node.xpr ? [node.xpr] : []]
365
- };
366
- var INFERENCE_ELEM_VALIDATOR = {
367
- node: "InferenceElem",
368
- children: (node) => [
369
- ...node.xpr ? [node.xpr] : [],
370
- ...node.expr ? [node.expr] : []
371
- ]
372
- };
373
- var TARGET_ENTRY_VALIDATOR = {
374
- node: "TargetEntry",
375
- children: (node) => [
376
- ...node.xpr ? [node.xpr] : [],
377
- ...node.expr ? [node.expr] : []
378
- ]
379
- };
380
- var RANGE_TBL_REF_VALIDATOR = {
381
- node: "RangeTblRef",
382
- children: () => []
383
- };
384
- var JOIN_EXPR_VALIDATOR = {
385
- node: "JoinExpr",
386
- children: (node) => [
387
- ...node.larg ? [node.larg] : [],
388
- ...node.rarg ? [node.rarg] : [],
389
- ...node.usingClause ?? [],
390
- ...node.join_using_alias ? [{ Alias: node.join_using_alias }] : [],
391
- ...node.quals ? [node.quals] : [],
392
- ...node.alias ? [{ Alias: node.alias }] : []
393
- ]
394
- };
395
- var FROM_EXPR_VALIDATOR = {
396
- node: "FromExpr",
397
- children: (node) => [
398
- ...node.fromlist ?? [],
399
- ...node.quals ? [node.quals] : []
400
- ]
401
- };
402
- var ON_CONFLICT_EXPR_VALIDATOR = {
403
- node: "OnConflictExpr",
404
- children: (node) => [
405
- ...node.arbiterElems ?? [],
406
- ...node.arbiterWhere ? [node.arbiterWhere] : [],
407
- ...node.onConflictSet ?? [],
408
- ...node.onConflictWhere ? [node.onConflictWhere] : [],
409
- ...node.exclRelTlist ?? []
410
- ]
411
- };
412
- var TYPE_NAME_VALIDATOR = {
413
- node: "TypeName",
414
- children: (node) => [
415
- ...node.names ?? [],
416
- ...node.typmods ?? [],
417
- ...node.arrayBounds ?? []
418
- ]
419
- };
420
- var COLUMN_REF_VALIDATOR = {
421
- node: "ColumnRef",
422
- children: (node) => [...node.fields ?? []]
423
- };
424
- var PARAM_REF_VALIDATOR = {
425
- node: "ParamRef",
426
- children: () => []
427
- };
428
- var A_EXPR_VALIDATOR = {
429
- node: "A_Expr",
430
- children: (node) => [
431
- ...node.name ?? [],
432
- ...node.lexpr ? [node.lexpr] : [],
433
- ...node.rexpr ? [node.rexpr] : []
434
- ]
435
- };
436
- var TYPE_CAST_VALIDATOR = {
437
- node: "TypeCast",
438
- children: (node) => [
439
- ...node.arg ? [node.arg] : [],
440
- ...node.typeName ? [{ TypeName: node.typeName }] : []
441
- ]
442
- };
443
- var COLLATE_CLAUSE_VALIDATOR = {
444
- node: "CollateClause",
445
- children: (node) => [
446
- ...node.arg ? [node.arg] : [],
447
- ...node.collname ?? []
448
- ]
449
- };
450
- var ALLOWED_FUNCTIONS = /* @__PURE__ */ new Set([
451
- "count",
452
- "sum",
453
- "avg",
454
- "min",
455
- "max",
456
- "lower",
457
- "upper",
458
- "length",
459
- "trim",
460
- "replace",
461
- "substring",
462
- "cast",
463
- "concat",
464
- "now",
465
- "current_timestamp",
466
- "current_date",
467
- "current_time",
468
- "coalesce",
469
- "json_agg",
470
- "json_object",
471
- "json_array",
472
- "json_object_agg",
473
- "json_array_agg"
474
- ]);
475
- var FUNC_CALL_VALIDATOR = {
476
- node: "FuncCall",
477
- children: (node) => [
478
- ...node.funcname ?? [],
479
- ...node.args ?? [],
480
- ...node.agg_order ?? [],
481
- ...node.agg_filter ? [node.agg_filter] : [],
482
- ...node.over ? [{ WindowDef: node.over }] : []
483
- ],
484
- validate: (node) => {
485
- if (node.funcname?.every(
486
- (name) => getNodeType(name) === "String" && // @ts-ignore
487
- ALLOWED_FUNCTIONS.has(name.String.sval)
488
- )) {
489
- return;
490
- }
491
- throw new Error("Function call not supported");
492
- }
493
- };
494
- var A_STAR_VALIDATOR = {
495
- node: "A_Star",
496
- children: () => []
497
- };
498
- var A_INDICES_VALIDATOR = {
499
- node: "A_Indices",
500
- children: (node) => [
501
- ...node.lidx ? [node.lidx] : [],
502
- ...node.uidx ? [node.uidx] : []
503
- ]
504
- };
505
- var A_INDIRECTION_VALIDATOR = {
506
- node: "A_Indirection",
507
- children: (node) => [
508
- ...node.arg ? [node.arg] : [],
509
- ...node.indirection ?? []
510
- ]
511
- };
512
- var A_ARRAY_EXPR_VALIDATOR = {
513
- node: "A_ArrayExpr",
514
- children: (node) => [...node.elements ?? []]
515
- };
516
- var RES_TARGET_VALIDATOR = {
517
- node: "ResTarget",
518
- children: (node) => [
519
- ...node.indirection ?? [],
520
- ...node.val ? [node.val] : []
521
- ]
522
- };
523
- var MULTI_ASSIGN_REF_VALIDATOR = {
524
- node: "MultiAssignRef",
525
- children: (node) => [...node.source ? [node.source] : []]
526
- };
527
- var SORT_BY_VALIDATOR = {
528
- node: "SortBy",
529
- children: (node) => [
530
- ...node.node ? [node.node] : [],
531
- ...node.useOp ?? []
532
- ]
533
- };
534
- var RANGE_SUBSELECT_VALIDATOR = {
535
- node: "RangeSubselect",
536
- children: (node) => [
537
- ...node.subquery ? [node.subquery] : [],
538
- ...node.alias ? [{ Alias: node.alias }] : []
539
- ]
540
- };
541
- var SORT_GROUP_CLAUSE_VALIDATOR = {
542
- node: "SortGroupClause",
543
- children: () => []
544
- };
545
- var GROUPING_SET_VALIDATOR = {
546
- node: "GroupingSet",
547
- children: (node) => [...node.content ?? []]
548
- };
549
- var WITH_CLAUSE_VALIDATOR = {
550
- node: "WithClause",
551
- children: (node) => [...node.ctes ?? []],
552
- validate: (node) => {
553
- if (node.recursive) {
554
- throw new Error("Recursive CTEs not supported");
555
- }
556
- }
557
- };
558
- var COMMON_TABLE_EXPR_VALIDATOR = {
559
- node: "CommonTableExpr",
560
- children: (node) => [
561
- ...node.aliascolnames ?? [],
562
- ...node.ctequery ? [node.ctequery] : [],
563
- ...node.search_clause ? [{ CTESearchClause: node.search_clause }] : [],
564
- ...node.cycle_clause ? [{ CTECycleClause: node.cycle_clause }] : [],
565
- ...node.ctecolnames ?? [],
566
- ...node.ctecoltypes ?? [],
567
- ...node.ctecoltypmods ?? [],
568
- ...node.ctecolcollations ?? []
569
- ],
570
- validate: (node) => {
571
- if (node.ctematerialized === "CTEMaterializeAlways" || node.cterecursive) {
572
- throw new Error("Invalid CTE");
573
- }
574
- }
575
- };
576
- var JSON_OUTPUT_VALIDATOR = {
577
- node: "JsonOutput",
578
- children: (node) => [
579
- ...node.returning ? [{ JsonReturning: node.returning }] : []
580
- ]
581
- };
582
- var JSON_KEY_VALUE_VALIDATOR = {
583
- node: "JsonKeyValue",
584
- children: (node) => [
585
- ...node.key ? [node.key] : [],
586
- ...node.value ? [{ JsonValueExpr: node.value }] : []
587
- ]
588
- };
589
- var JSON_OBJECT_CONSTRUCTOR_VALIDATOR = {
590
- node: "JsonObjectConstructor",
591
- children: (node) => [
592
- ...node.exprs ?? [],
593
- ...node.output ? [{ JsonOutput: node.output }] : []
594
- ]
595
- };
596
- var JSON_ARRAY_CONSTRUCTOR_VALIDATOR = {
597
- node: "JsonArrayConstructor",
598
- children: (node) => [
599
- ...node.exprs ?? [],
600
- ...node.output ? [{ JsonOutput: node.output }] : []
601
- ]
602
- };
603
- var JSON_ARRAY_QUERY_CONSTRUCTOR_VALIDATOR = {
604
- node: "JsonArrayQueryConstructor",
605
- children: (node) => [
606
- ...node.query ? [node.query] : [],
607
- ...node.output ? [{ JsonOutput: node.output }] : [],
608
- ...node.format ? [{ JsonFormat: node.format }] : []
609
- ]
610
- };
611
- var JSON_AGG_CONSTRUCTOR_VALIDATOR = {
612
- node: "JsonAggConstructor",
613
- children: (node) => [
614
- ...node.output ? [{ JsonOutput: node.output }] : [],
615
- ...node.agg_filter ? [node.agg_filter] : [],
616
- ...node.agg_order ?? [],
617
- ...node.over ? [{ WindowDef: node.over }] : []
618
- ]
619
- };
620
- var JSON_OBJECT_AGG_VALIDATOR = {
621
- node: "JsonObjectAgg",
622
- children: (node) => [
623
- ...node.constructor ? [{ JsonAggConstructor: node.constructor }] : [],
624
- ...node.arg ? [{ JsonKeyValue: node.arg }] : []
625
- ]
626
- };
627
- var JSON_ARRAY_AGG_VALIDATOR = {
628
- node: "JsonArrayAgg",
629
- children: (node) => [
630
- ...node.constructor ? [{ JsonAggConstructor: node.constructor }] : [],
631
- ...node.arg ? [{ JsonValueExpr: node.arg }] : []
632
- ]
633
- };
634
- var SELECT_STMT_VALIDATOR = {
635
- node: "SelectStmt",
636
- children: (node) => [
637
- ...node.distinctClause ?? [],
638
- ...node.intoClause ? [{ IntoClause: node.intoClause }] : [],
639
- ...node.targetList ?? [],
640
- ...node.fromClause ?? [],
641
- ...node.whereClause ? [node.whereClause] : [],
642
- ...node.groupClause ?? [],
643
- ...node.havingClause ? [node.havingClause] : [],
644
- ...node.windowClause ?? [],
645
- ...node.valuesLists ?? [],
646
- ...node.sortClause ?? [],
647
- ...node.limitOffset ? [node.limitOffset] : [],
648
- ...node.limitCount ? [node.limitCount] : [],
649
- ...node.lockingClause ?? [],
650
- ...node.withClause ? [{ WithClause: node.withClause }] : [],
651
- ...node.larg ? [{ SelectStmt: node.larg }] : [],
652
- ...node.rarg ? [{ SelectStmt: node.rarg }] : []
653
- ],
654
- validate: (node) => {
655
- if (node.lockingClause) {
656
- throw new Error("Invalid query");
657
- }
658
- }
659
- };
660
- var COMMENT_STMT_VALIDATOR = {
661
- node: "CommentStmt",
662
- children: (node) => [...node.object ? [node.object] : []]
663
- };
664
- var ALLOW_LIST = new Map(
665
- [
666
- INTEGER_VALIDATOR,
667
- FLOAT_VALIDATOR,
668
- BOOLEAN_VALIDATOR,
669
- STRING_VALIDATOR,
670
- BIT_STRING_VALIDATOR,
671
- LIST_VALIDATOR,
672
- OID_LIST_VALIDATOR,
673
- INT_LIST_VALIDATOR,
674
- A_CONST_VALIDATOR,
675
- ALIAS_VALIDATOR,
676
- RANGE_VAR_VALIDATOR,
677
- VAR_VALIDATOR,
678
- PARAM_VALIDATOR,
679
- AGGREF_VALIDATOR,
680
- GROUPING_FUNC_VALIDATOR,
681
- WINDOW_FUNC_VALIDATOR,
682
- NAMED_ARG_EXPR_VALIDATOR,
683
- OP_EXPR_VALIDATOR,
684
- DISTINCT_EXPR_VALIDATOR,
685
- NULL_IF_EXPR_VALIDATOR,
686
- SCALAR_ARRAY_OP_EXPR_VALIDATOR,
687
- BOOL_EXPR_VALIDATOR,
688
- FIELD_SELECT_VALIDATOR,
689
- RELABEL_TYPE_VALIDATOR,
690
- ARRAY_COERCE_EXPR_VALIDATOR,
691
- CONVERT_ROWTYPE_EXPR_VALIDATOR,
692
- COLLATE_EXPR_VALIDATOR,
693
- CASE_EXPR_VALIDATOR,
694
- CASE_WHEN_VALIDATOR,
695
- CASE_TEST_EXPR_VALIDATOR,
696
- ARRAY_EXPR_VALIDATOR,
697
- ROW_EXPR_VALIDATOR,
698
- ROW_COMPARE_EXPR_VALIDATOR,
699
- COALESC_EXPR_VALIDATOR,
700
- MIN_MAX_EXPR_VALIDATOR,
701
- SQL_VALUE_FUNCTION_VALIDATOR,
702
- JSON_FORMAT_VALIDATOR,
703
- JSON_RETURNING_VALIDATOR,
704
- JSON_VALUE_EXPR_VALIDATOR,
705
- JSON_CONSTRUCTOR_EXPR_VALIDATOR,
706
- JSON_IS_PREDICATE_VALIDATOR,
707
- NULL_TEST_VALIDATOR,
708
- BOOLEAN_TEST_VALIDATOR,
709
- COERCE_TO_DOMAIN_VALIDATOR,
710
- COERCE_TO_DOMAIN_VALUE_VALIDATOR,
711
- CURRENT_OF_EXPR_VALIDATOR,
712
- NEXT_VALUE_EXPR_VALIDATOR,
713
- INFERENCE_ELEM_VALIDATOR,
714
- TARGET_ENTRY_VALIDATOR,
715
- RANGE_TBL_REF_VALIDATOR,
716
- JOIN_EXPR_VALIDATOR,
717
- FROM_EXPR_VALIDATOR,
718
- ON_CONFLICT_EXPR_VALIDATOR,
719
- TYPE_NAME_VALIDATOR,
720
- COLUMN_REF_VALIDATOR,
721
- PARAM_REF_VALIDATOR,
722
- A_EXPR_VALIDATOR,
723
- TYPE_CAST_VALIDATOR,
724
- COLLATE_CLAUSE_VALIDATOR,
725
- FUNC_CALL_VALIDATOR,
726
- A_STAR_VALIDATOR,
727
- A_INDICES_VALIDATOR,
728
- A_INDIRECTION_VALIDATOR,
729
- A_ARRAY_EXPR_VALIDATOR,
730
- RES_TARGET_VALIDATOR,
731
- MULTI_ASSIGN_REF_VALIDATOR,
732
- SORT_BY_VALIDATOR,
733
- RANGE_SUBSELECT_VALIDATOR,
734
- SORT_GROUP_CLAUSE_VALIDATOR,
735
- GROUPING_SET_VALIDATOR,
736
- WITH_CLAUSE_VALIDATOR,
737
- COMMON_TABLE_EXPR_VALIDATOR,
738
- JSON_OUTPUT_VALIDATOR,
739
- JSON_KEY_VALUE_VALIDATOR,
740
- JSON_OBJECT_CONSTRUCTOR_VALIDATOR,
741
- JSON_ARRAY_CONSTRUCTOR_VALIDATOR,
742
- JSON_ARRAY_QUERY_CONSTRUCTOR_VALIDATOR,
743
- JSON_AGG_CONSTRUCTOR_VALIDATOR,
744
- JSON_OBJECT_AGG_VALIDATOR,
745
- JSON_ARRAY_AGG_VALIDATOR,
746
- SELECT_STMT_VALIDATOR,
747
- COMMENT_STMT_VALIDATOR
748
- ].map((node) => [node.node, node])
749
- );
750
- var SYSTEM_TABLES = /* @__PURE__ */ new Set([
751
- "pg_statistic",
752
- "pg_type",
753
- "pg_foreign_table",
754
- "pg_proc_oid_index",
755
- "pg_proc_proname_args_nsp_index",
756
- "pg_type_oid_index",
757
- "pg_type_typname_nsp_index",
758
- "pg_attribute_relid_attnam_index",
759
- "pg_attribute_relid_attnum_index",
760
- "pg_class_oid_index",
761
- "pg_class_relname_nsp_index",
762
- "pg_class_tblspc_relfilenode_index",
763
- "pg_attrdef_adrelid_adnum_index",
764
- "pg_attrdef_oid_index",
765
- "pg_constraint_conname_nsp_index",
766
- "pg_constraint_conrelid_contypid_conname_index",
767
- "pg_constraint_contypid_index",
768
- "pg_constraint_oid_index",
769
- "pg_constraint_conparentid_index",
770
- "pg_inherits_relid_seqno_index",
771
- "pg_inherits_parent_index",
772
- "pg_index_indrelid_index",
773
- "pg_index_indexrelid_index",
774
- "pg_operator_oid_index",
775
- "pg_operator_oprname_l_r_n_index",
776
- "pg_opfamily_am_name_nsp_index",
777
- "pg_opfamily_oid_index",
778
- "pg_opclass_am_name_nsp_index",
779
- "pg_opclass_oid_index",
780
- "pg_am_name_index",
781
- "pg_am_oid_index",
782
- "pg_amop_fam_strat_index",
783
- "pg_amop_opr_fam_index",
784
- "pg_amop_oid_index",
785
- "pg_amproc_fam_proc_index",
786
- "pg_amproc_oid_index",
787
- "pg_language_name_index",
788
- "pg_language_oid_index",
789
- "pg_largeobject_metadata_oid_index",
790
- "pg_largeobject_loid_pn_index",
791
- "pg_aggregate_fnoid_index",
792
- "pg_statistic_relid_att_inh_index",
793
- "pg_statistic_ext_oid_index",
794
- "pg_statistic_ext_name_index",
795
- "pg_statistic_ext_relid_index",
796
- "pg_statistic_ext_data_stxoid_inh_index",
797
- "pg_rewrite_oid_index",
798
- "pg_rewrite_rel_rulename_index",
799
- "pg_trigger_tgconstraint_index",
800
- "pg_trigger_tgrelid_tgname_index",
801
- "pg_trigger_oid_index",
802
- "pg_event_trigger_evtname_index",
803
- "pg_event_trigger_oid_index",
804
- "pg_description_o_c_o_index",
805
- "pg_cast_oid_index",
806
- "pg_cast_source_target_index",
807
- "pg_enum_oid_index",
808
- "pg_enum_typid_label_index",
809
- "pg_enum_typid_sortorder_index",
810
- "pg_namespace_nspname_index",
811
- "pg_namespace_oid_index",
812
- "pg_conversion_default_index",
813
- "pg_conversion_name_nsp_index",
814
- "pg_conversion_oid_index",
815
- "pg_depend_depender_index",
816
- "pg_depend_reference_index",
817
- "pg_database_datname_index",
818
- "pg_database_oid_index",
819
- "pg_db_role_setting_databaseid_rol_index",
820
- "pg_tablespace_oid_index",
821
- "pg_tablespace_spcname_index",
822
- "pg_authid_rolname_index",
823
- "pg_authid_oid_index",
824
- "pg_auth_members_oid_index",
825
- "pg_auth_members_role_member_index",
826
- "pg_auth_members_member_role_index",
827
- "pg_auth_members_grantor_index",
828
- "pg_shdepend_depender_index",
829
- "pg_shdepend_reference_index",
830
- "pg_shdescription_o_c_index",
831
- "pg_ts_config_cfgname_index",
832
- "pg_ts_config_oid_index",
833
- "pg_ts_config_map_index",
834
- "pg_ts_dict_dictname_index",
835
- "pg_ts_dict_oid_index",
836
- "pg_ts_parser_prsname_index",
837
- "pg_ts_parser_oid_index",
838
- "pg_ts_template_tmplname_index",
839
- "pg_ts_template_oid_index",
840
- "pg_extension_oid_index",
841
- "pg_extension_name_index",
842
- "pg_foreign_data_wrapper_oid_index",
843
- "pg_foreign_data_wrapper_name_index",
844
- "pg_foreign_server_oid_index",
845
- "pg_foreign_server_name_index",
846
- "pg_user_mapping_oid_index",
847
- "pg_user_mapping_user_server_index",
848
- "pg_foreign_table_relid_index",
849
- "pg_policy_oid_index",
850
- "pg_policy_polrelid_polname_index",
851
- "pg_replication_origin_roiident_index",
852
- "pg_replication_origin_roname_index",
853
- "pg_default_acl_role_nsp_obj_index",
854
- "pg_default_acl_oid_index",
855
- "pg_init_privs_o_c_o_index",
856
- "pg_seclabel_object_index",
857
- "pg_shseclabel_object_index",
858
- "pg_collation_name_enc_nsp_index",
859
- "pg_collation_oid_index",
860
- "pg_parameter_acl_parname_index",
861
- "pg_parameter_acl_oid_index",
862
- "pg_partitioned_table_partrelid_index",
863
- "pg_range_rngtypid_index",
864
- "pg_range_rngmultitypid_index",
865
- "pg_transform_oid_index",
866
- "pg_transform_type_lang_index",
867
- "pg_sequence_seqrelid_index",
868
- "pg_publication_oid_index",
869
- "pg_publication_pubname_index",
870
- "pg_publication_namespace_oid_index",
871
- "pg_publication_namespace_pnnspid_pnpubid_index",
872
- "pg_publication_rel_oid_index",
873
- "pg_publication_rel_prrelid_prpubid_index",
874
- "pg_publication_rel_prpubid_index",
875
- "pg_subscription_oid_index",
876
- "pg_subscription_subname_index",
877
- "pg_subscription_rel_srrelid_srsubid_index",
878
- "pg_authid",
879
- "pg_shadow",
880
- "pg_roles",
881
- "pg_statistic_ext_data",
882
- "pg_hba_file_rules",
883
- "pg_settings",
884
- "pg_file_settings",
885
- "pg_backend_memory_contexts",
886
- "pg_ident_file_mappings",
887
- "pg_config",
888
- "pg_shmem_allocations",
889
- "pg_tables",
890
- "pg_user_mapping",
891
- "pg_replication_origin_status",
892
- "pg_subscription",
893
- "pg_attribute",
894
- "pg_proc",
895
- "pg_class",
896
- "pg_attrdef",
897
- "pg_constraint",
898
- "pg_inherits",
899
- "pg_index",
900
- "pg_operator",
901
- "pg_statio_all_sequences",
902
- "pg_opfamily",
903
- "pg_opclass",
904
- "pg_am",
905
- "pg_amop",
906
- "pg_amproc",
907
- "pg_language",
908
- "pg_largeobject_metadata",
909
- "pg_aggregate",
910
- "pg_statistic_ext",
911
- "pg_rewrite",
912
- "pg_trigger",
913
- "pg_event_trigger",
914
- "pg_description",
915
- "pg_cast",
916
- "pg_enum",
917
- "pg_namespace",
918
- "pg_conversion",
919
- "pg_depend",
920
- "pg_database",
921
- "pg_db_role_setting",
922
- "pg_tablespace",
923
- "pg_auth_members",
924
- "pg_shdepend",
925
- "pg_shdescription",
926
- "pg_ts_config",
927
- "pg_ts_config_map",
928
- "pg_ts_dict",
929
- "pg_ts_parser",
930
- "pg_ts_template",
931
- "pg_extension",
932
- "pg_foreign_data_wrapper",
933
- "pg_foreign_server",
934
- "pg_policy",
935
- "pg_replication_origin",
936
- "pg_default_acl",
937
- "pg_init_privs",
938
- "pg_seclabel",
939
- "pg_shseclabel",
940
- "pg_collation",
941
- "pg_parameter_acl",
942
- "pg_partitioned_table",
943
- "pg_range",
944
- "pg_transform",
945
- "pg_sequence",
946
- "pg_publication",
947
- "pg_publication_namespace",
948
- "pg_publication_rel",
949
- "pg_subscription_rel",
950
- "pg_group",
951
- "pg_user",
952
- "pg_policies",
953
- "pg_rules",
954
- "pg_views",
955
- "pg_matviews",
956
- "pg_indexes",
957
- "pg_sequences",
958
- "pg_stats",
959
- "pg_stats_ext",
960
- "pg_stats_ext_exprs",
961
- "pg_publication_tables",
962
- "pg_locks",
963
- "pg_cursors",
964
- "pg_available_extensions",
965
- "pg_available_extension_versions",
966
- "pg_prepared_xacts",
967
- "pg_prepared_statements",
968
- "pg_seclabels",
969
- "pg_timezone_abbrevs",
970
- "pg_timezone_names",
971
- "pg_stat_all_tables",
972
- "pg_stat_xact_all_tables",
973
- "pg_stat_xact_user_tables",
974
- "pg_stat_sys_tables",
975
- "pg_stat_xact_sys_tables",
976
- "pg_stat_user_tables",
977
- "pg_statio_all_tables",
978
- "pg_statio_sys_tables",
979
- "pg_statio_user_tables",
980
- "pg_stat_all_indexes",
981
- "pg_stat_sys_indexes",
982
- "pg_stat_user_indexes",
983
- "pg_statio_all_indexes",
984
- "pg_statio_sys_indexes",
985
- "pg_statio_user_indexes",
986
- "pg_statio_sys_sequences",
987
- "pg_statio_user_sequences",
988
- "pg_stat_activity",
989
- "pg_stat_replication",
990
- "pg_stat_slru",
991
- "pg_stat_wal_receiver",
992
- "pg_stat_recovery_prefetch",
993
- "pg_stat_subscription",
994
- "pg_stat_ssl",
995
- "pg_stat_gssapi",
996
- "pg_replication_slots",
997
- "pg_stat_replication_slots",
998
- "pg_stat_database",
999
- "pg_stat_database_conflicts",
1000
- "pg_stat_user_functions",
1001
- "pg_stat_xact_user_functions",
1002
- "pg_stat_archiver",
1003
- "pg_stat_bgwriter",
1004
- "pg_stat_io",
1005
- "pg_stat_wal",
1006
- "pg_stat_progress_analyze",
1007
- "pg_stat_progress_vacuum",
1008
- "pg_stat_progress_cluster",
1009
- "pg_stat_progress_create_index",
1010
- "pg_stat_progress_basebackup",
1011
- "pg_stat_progress_copy",
1012
- "pg_user_mappings",
1013
- "pg_stat_subscription_stats",
1014
- "pg_largeobject"
1015
- ]);
1016
-
1017
- // src/client/index.ts
1018
- var status = pgTable("_ponder_status", (t) => ({
1019
- chainId: t.bigint({ mode: "number" }).primaryKey(),
1020
- blockNumber: t.bigint({ mode: "number" }),
1021
- blockTimestamp: t.bigint({ mode: "number" }),
1022
- ready: t.boolean().notNull()
1023
- }));
1024
- var client = ({
1025
- db
1026
- }) => {
1027
- const session = db._.session;
1028
- const driver = globalThis.PONDER_DATABASE.driver;
1029
- let statusResolver = promiseWithResolvers();
1030
- const channel = `${globalThis.PONDER_NAMESPACE_BUILD}_status_channel`;
1031
- if ("instance" in driver) {
1032
- driver.instance.query(`LISTEN "${channel}"`).then(() => {
1033
- driver.instance.onNotification(async () => {
1034
- statusResolver.resolve();
1035
- statusResolver = promiseWithResolvers();
1036
- });
1037
- });
1038
- } else {
1039
- const pool = driver.internal;
1040
- const connectAndListen = async () => {
1041
- driver.listen = await pool.connect();
1042
- await driver.listen.query(`LISTEN "${channel}"`);
1043
- driver.listen.on("error", async () => {
1044
- driver.listen?.release();
1045
- await connectAndListen();
1046
- });
1047
- driver.listen.on("notification", () => {
1048
- statusResolver.resolve();
1049
- statusResolver = promiseWithResolvers();
1050
- });
1051
- };
1052
- connectAndListen();
1053
- }
1054
- return createMiddleware(async (c, next) => {
1055
- if (c.req.path === "/sql/db") {
1056
- const queryString = c.req.query("sql");
1057
- if (queryString === void 0) {
1058
- return c.text('Missing "sql" query parameter', 400);
1059
- }
1060
- const query = superjson.parse(queryString);
1061
- if ("instance" in driver) {
1062
- try {
1063
- await validateQuery(query.sql);
1064
- const result = await session.prepareQuery(query, void 0, void 0, false).execute();
1065
- return c.json(result);
1066
- } catch (error) {
1067
- error.stack = void 0;
1068
- return c.text(error.message, 500);
1069
- }
1070
- } else {
1071
- const client2 = await driver.internal.connect();
1072
- try {
1073
- await validateQuery(query.sql);
1074
- await client2.query("BEGIN READ ONLY");
1075
- const result = await session.prepareQuery(query, void 0, void 0, false).execute();
1076
- return c.json(result);
1077
- } catch (error) {
1078
- error.stack = void 0;
1079
- return c.text(error.message, 500);
1080
- } finally {
1081
- await client2.query("ROLLBACK");
1082
- client2.release();
1083
- }
1084
- }
1085
- }
1086
- if (c.req.path === "/sql/live") {
1087
- c.header("Content-Type", "text/event-stream");
1088
- c.header("Cache-Control", "no-cache");
1089
- c.header("Connection", "keep-alive");
1090
- return streamSSE(c, async (stream) => {
1091
- while (stream.closed === false && stream.aborted === false) {
1092
- try {
1093
- await stream.writeSSE({ data: "" });
1094
- } catch {
1095
- }
1096
- await statusResolver.promise;
1097
- }
1098
- });
1099
- }
1100
- if (c.req.path === "/sql/status") {
1101
- const statusResult = await db.select().from(status);
1102
- return c.json(statusResult);
1103
- }
1104
- return next();
1105
- });
1106
- };
1107
-
1108
- // src/ui/graphiql.html.ts
1109
- var graphiQLHtml = (path) => `<!--
1110
- * Copyright (c) 2021 GraphQL Contributors
1111
- * All rights reserved.
1112
- *
1113
- * This source code is licensed under the license found in the
1114
- * LICENSE file in the root directory of this source tree.
1115
- -->
1116
- <!DOCTYPE html>
1117
- <html lang="en">
1118
- <head>
1119
- <title>Ponder Playground</title>
1120
- <style>
1121
- body {
1122
- height: 100%;
1123
- margin: 0;
1124
- width: 100%;
1125
- overflow: hidden;
1126
- }
1127
- #graphiql {
1128
- height: 100vh;
1129
- }
1130
- *::-webkit-scrollbar {
1131
- height: 0.3rem;
1132
- width: 0.5rem;
1133
- }
1134
- *::-webkit-scrollbar-track {
1135
- -ms-overflow-style: none;
1136
- overflow: -moz-scrollbars-none;
1137
- }
1138
- *::-webkit-scrollbar-thumb {
1139
- -ms-overflow-style: none;
1140
- overflow: -moz-scrollbars-none;
1141
- }
1142
- </style>
1143
- <link rel="stylesheet" href="https://unpkg.com/graphiql@3.7.2/graphiql.min.css" />
1144
- <link rel="stylesheet" href="https://unpkg.com/@graphiql/plugin-explorer@3.2.3/dist/style.css" />
1145
- </head>
1146
- <body>
1147
- <div id="graphiql">Loading...</div>
1148
- <script crossorigin src="https://unpkg.com/react@18.3.1/umd/react.development.js"></script>1
1149
- <script crossorigin src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js"></script>
1150
- <script src="https://unpkg.com/graphiql@3.7.2/graphiql.min.js" crossorigin="anonymous"></script>
1151
- <script src="https://unpkg.com/@graphiql/plugin-explorer@3.2.3/dist/index.umd.js" crossorigin="anonymous"></script>
1152
- <script>
1153
- const fetcher = GraphiQL.createFetcher({ url: "${path}" });
1154
- const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
1155
- const root = ReactDOM.createRoot(document.getElementById("graphiql"));
1156
- root.render(
1157
- React.createElement(GraphiQL, {
1158
- fetcher,
1159
- plugins: [explorerPlugin],
1160
- defaultEditorToolsVisibility: false,
1161
- })
1162
- );
1163
- </script>
1164
- </body>
1165
- </html>`;
1166
-
1167
- // src/graphql/middleware.ts
1168
- import { maxAliasesPlugin } from "@escape.tech/graphql-armor-max-aliases";
1169
- import { maxDepthPlugin } from "@escape.tech/graphql-armor-max-depth";
1170
- import { maxTokensPlugin } from "@escape.tech/graphql-armor-max-tokens";
1171
- import { printSchema } from "graphql";
1172
- import { createYoga } from "graphql-yoga";
1173
- import { createMiddleware as createMiddleware2 } from "hono/factory";
1174
-
1175
- // src/graphql/index.ts
1176
- import DataLoader from "dataloader";
1177
- import {
1178
- Many,
1179
- One,
1180
- and,
1181
- arrayContained,
1182
- arrayContains,
1183
- asc,
1184
- count,
1185
- createTableRelationsHelpers,
1186
- desc,
1187
- eq,
1188
- extractTablesRelationalConfig,
1189
- getTableColumns,
1190
- gt,
1191
- gte,
1192
- inArray,
1193
- is,
1194
- like,
1195
- lt,
1196
- lte,
1197
- ne,
1198
- not,
1199
- notInArray,
1200
- notLike,
1201
- or
1202
- } from "drizzle-orm";
1203
- import {
1204
- PgEnumColumn,
1205
- PgInteger,
1206
- PgSerial,
1207
- isPgEnum
1208
- } from "drizzle-orm/pg-core";
1209
- import {
1210
- GraphQLBoolean,
1211
- GraphQLEnumType,
1212
- GraphQLFloat,
1213
- GraphQLInputObjectType,
1214
- GraphQLInt,
1215
- GraphQLList,
1216
- GraphQLNonNull,
1217
- GraphQLObjectType,
1218
- GraphQLScalarType as GraphQLScalarType2,
1219
- GraphQLSchema,
1220
- GraphQLString
1221
- } from "graphql";
1222
-
1223
- // src/graphql/json.ts
1224
- import {
1225
- GraphQLScalarType,
1226
- Kind,
1227
- print
1228
- } from "graphql";
1229
- var GraphQLJSON = new GraphQLScalarType({
1230
- name: "JSON",
1231
- description: "The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).",
1232
- serialize: (x) => x,
1233
- parseValue: (x) => x,
1234
- parseLiteral: (ast, variables) => {
1235
- if (ast.kind !== Kind.OBJECT) {
1236
- throw new TypeError(
1237
- `JSONObject cannot represent non-object value: ${print(ast)}`
1238
- );
1239
- }
1240
- return parseObject(ast, variables);
1241
- }
1242
- });
1243
- var parseLiteral = (ast, variables) => {
1244
- switch (ast.kind) {
1245
- case Kind.STRING:
1246
- case Kind.BOOLEAN:
1247
- return ast.value;
1248
- case Kind.INT:
1249
- case Kind.FLOAT:
1250
- return Number.parseFloat(ast.value);
1251
- case Kind.OBJECT:
1252
- return parseObject(ast, variables);
1253
- case Kind.LIST:
1254
- return ast.values.map((n) => parseLiteral(n, variables));
1255
- case Kind.NULL:
1256
- return null;
1257
- case Kind.VARIABLE:
1258
- return variables ? variables[ast.name.value] : void 0;
1259
- default:
1260
- throw new TypeError(`JSON cannot represent value: ${print(ast)}`);
1261
- }
1262
- };
1263
- var parseObject = (ast, variables) => {
1264
- const value = /* @__PURE__ */ Object.create(null);
1265
- ast.fields.forEach((field) => {
1266
- value[field.name.value] = parseLiteral(field.value, variables);
1267
- });
1268
- return value;
1269
- };
1270
-
1271
- // src/graphql/index.ts
1272
- var DEFAULT_LIMIT = 50;
1273
- var MAX_LIMIT = 1e3;
1274
- function buildGraphQLSchema({
1275
- schema
1276
- }) {
1277
- const tablesConfig = extractTablesRelationalConfig(
1278
- schema,
1279
- createTableRelationsHelpers
1280
- );
1281
- const tables = Object.values(tablesConfig.tables);
1282
- const enums = Object.entries(schema).filter(
1283
- (el) => isPgEnum(el[1])
1284
- );
1285
- const enumTypes = {};
1286
- for (const [enumTsName, enumObject] of enums) {
1287
- enumTypes[enumObject.enumName] = new GraphQLEnumType({
1288
- name: enumTsName,
1289
- values: enumObject.enumValues.reduce(
1290
- (acc, cur) => ({ ...acc, [cur]: {} }),
1291
- {}
1292
- )
1293
- });
1294
- }
1295
- const entityFilterTypes = {};
1296
- for (const table of tables) {
1297
- const filterType = new GraphQLInputObjectType({
1298
- name: `${table.tsName}Filter`,
1299
- fields: () => {
1300
- const filterFields = {
1301
- // Logical operators
1302
- AND: { type: new GraphQLList(filterType) },
1303
- OR: { type: new GraphQLList(filterType) }
1304
- };
1305
- for (const [columnName, column] of Object.entries(table.columns)) {
1306
- const type = columnToGraphQLCore(column, enumTypes);
1307
- if (type instanceof GraphQLList) {
1308
- const baseType = innerType(type);
1309
- conditionSuffixes.universal.forEach((suffix) => {
1310
- filterFields[`${columnName}${suffix}`] = {
1311
- type: new GraphQLList(baseType)
1312
- };
1313
- });
1314
- conditionSuffixes.plural.forEach((suffix) => {
1315
- filterFields[`${columnName}${suffix}`] = { type: baseType };
1316
- });
1317
- }
1318
- if (type instanceof GraphQLScalarType2 || type instanceof GraphQLEnumType) {
1319
- if (type.name === "JSON")
1320
- continue;
1321
- conditionSuffixes.universal.forEach((suffix) => {
1322
- filterFields[`${columnName}${suffix}`] = {
1323
- type
1324
- };
1325
- });
1326
- conditionSuffixes.singular.forEach((suffix) => {
1327
- filterFields[`${columnName}${suffix}`] = {
1328
- type: new GraphQLList(type)
1329
- };
1330
- });
1331
- if (["String", "ID"].includes(type.name)) {
1332
- conditionSuffixes.string.forEach((suffix) => {
1333
- filterFields[`${columnName}${suffix}`] = {
1334
- type
1335
- };
1336
- });
1337
- }
1338
- if (["Int", "Float", "BigInt"].includes(type.name)) {
1339
- conditionSuffixes.numeric.forEach((suffix) => {
1340
- filterFields[`${columnName}${suffix}`] = {
1341
- type
1342
- };
1343
- });
1344
- }
1345
- }
1346
- }
1347
- return filterFields;
1348
- }
1349
- });
1350
- entityFilterTypes[table.tsName] = filterType;
1351
- }
1352
- const entityTypes = {};
1353
- const entityPageTypes = {};
1354
- for (const table of tables) {
1355
- entityTypes[table.tsName] = new GraphQLObjectType({
1356
- name: table.tsName,
1357
- fields: () => {
1358
- const fieldConfigMap = {};
1359
- for (const [columnName, column] of Object.entries(table.columns)) {
1360
- const type = columnToGraphQLCore(column, enumTypes);
1361
- fieldConfigMap[columnName] = {
1362
- type: column.notNull ? new GraphQLNonNull(type) : type
1363
- };
1364
- }
1365
- const relations2 = Object.entries(table.relations);
1366
- for (const [relationName, relation] of relations2) {
1367
- const referencedTable = tables.find(
1368
- (table2) => table2.dbName === relation.referencedTableName
1369
- );
1370
- if (!referencedTable)
1371
- throw new Error(
1372
- `Internal error: Referenced table "${relation.referencedTableName}" not found`
1373
- );
1374
- const referencedEntityType = entityTypes[referencedTable.tsName];
1375
- const referencedEntityPageType = entityPageTypes[referencedTable.tsName];
1376
- const referencedEntityFilterType = entityFilterTypes[referencedTable.tsName];
1377
- if (referencedEntityType === void 0 || referencedEntityPageType === void 0 || referencedEntityFilterType === void 0)
1378
- throw new Error(
1379
- `Internal error: Referenced entity types not found for table "${referencedTable.tsName}" `
1380
- );
1381
- if (is(relation, One)) {
1382
- const fields = relation.config?.fields ?? [];
1383
- const references = relation.config?.references ?? [];
1384
- if (fields.length !== references.length) {
1385
- throw new Error(
1386
- "Internal error: Fields and references arrays must be the same length"
1387
- );
1388
- }
1389
- fieldConfigMap[relationName] = {
1390
- // Note: There is a `relation.isNullable` field here but it appears
1391
- // to be internal / incorrect. Until we have support for foriegn
1392
- // key constraints, all `one` relations must be nullable.
1393
- type: referencedEntityType,
1394
- resolve: (parent, _args, context) => {
1395
- const loader = context.getDataLoader({
1396
- table: referencedTable
1397
- });
1398
- const rowFragment = {};
1399
- for (let i = 0; i < references.length; i++) {
1400
- const referenceColumn = references[i];
1401
- const fieldColumn = fields[i];
1402
- const fieldColumnTsName = getColumnTsName(fieldColumn);
1403
- const referenceColumnTsName = getColumnTsName(referenceColumn);
1404
- rowFragment[referenceColumnTsName] = parent[fieldColumnTsName];
1405
- }
1406
- const encodedId = encodeRowFragment(rowFragment);
1407
- return loader.load(encodedId);
1408
- }
1409
- };
1410
- } else if (is(relation, Many)) {
1411
- const oneRelation = Object.values(referencedTable.relations).find(
1412
- (relation2) => relation2.relationName === relationName || is(relation2, One) && relation2.referencedTableName === table.dbName
1413
- );
1414
- if (!oneRelation)
1415
- throw new Error(
1416
- `Internal error: Relation "${relationName}" not found in table "${referencedTable.tsName}"`
1417
- );
1418
- const fields = oneRelation.config?.fields ?? [];
1419
- const references = oneRelation.config?.references ?? [];
1420
- fieldConfigMap[relationName] = {
1421
- type: referencedEntityPageType,
1422
- args: {
1423
- where: { type: referencedEntityFilterType },
1424
- orderBy: { type: GraphQLString },
1425
- orderDirection: { type: GraphQLString },
1426
- before: { type: GraphQLString },
1427
- after: { type: GraphQLString },
1428
- limit: { type: GraphQLInt }
1429
- },
1430
- resolve: (parent, args, context, info) => {
1431
- const relationalConditions = [];
1432
- for (let i = 0; i < references.length; i++) {
1433
- const column = fields[i];
1434
- const value = parent[references[i].name];
1435
- relationalConditions.push(eq(column, value));
1436
- }
1437
- const includeTotalCount = selectionIncludesField(
1438
- info,
1439
- "totalCount"
1440
- );
1441
- return executePluralQuery(
1442
- referencedTable,
1443
- context.drizzle,
1444
- args,
1445
- includeTotalCount,
1446
- relationalConditions
1447
- );
1448
- }
1449
- };
1450
- } else {
1451
- throw new Error(
1452
- `Internal error: Relation "${relationName}" is unsupported, expected One or Many`
1453
- );
1454
- }
1455
- }
1456
- return fieldConfigMap;
1457
- }
1458
- });
1459
- entityPageTypes[table.tsName] = new GraphQLObjectType({
1460
- name: `${table.tsName}Page`,
1461
- fields: () => ({
1462
- items: {
1463
- type: new GraphQLNonNull(
1464
- new GraphQLList(new GraphQLNonNull(entityTypes[table.tsName]))
1465
- )
1466
- },
1467
- pageInfo: { type: new GraphQLNonNull(GraphQLPageInfo) },
1468
- totalCount: { type: new GraphQLNonNull(GraphQLInt) }
1469
- })
1470
- });
1471
- }
1472
- const queryFields = {};
1473
- for (const table of tables) {
1474
- const entityType = entityTypes[table.tsName];
1475
- const entityPageType = entityPageTypes[table.tsName];
1476
- const entityFilterType = entityFilterTypes[table.tsName];
1477
- const singularFieldName = table.tsName.charAt(0).toLowerCase() + table.tsName.slice(1);
1478
- const pluralFieldName = `${singularFieldName}s`;
1479
- queryFields[singularFieldName] = {
1480
- type: entityType,
1481
- // Find the primary key columns and GraphQL core types and include them
1482
- // as arguments to the singular query type.
1483
- args: Object.fromEntries(
1484
- table.primaryKey.map((column) => [
1485
- getColumnTsName(column),
1486
- {
1487
- type: new GraphQLNonNull(
1488
- columnToGraphQLCore(column, enumTypes)
1489
- )
1490
- }
1491
- ])
1492
- ),
1493
- resolve: async (_parent, args, context) => {
1494
- const loader = context.getDataLoader({ table });
1495
- const encodedId = encodeRowFragment(args);
1496
- return loader.load(encodedId);
1497
- }
1498
- };
1499
- queryFields[pluralFieldName] = {
1500
- type: new GraphQLNonNull(entityPageType),
1501
- args: {
1502
- where: { type: entityFilterType },
1503
- orderBy: { type: GraphQLString },
1504
- orderDirection: { type: GraphQLString },
1505
- before: { type: GraphQLString },
1506
- after: { type: GraphQLString },
1507
- limit: { type: GraphQLInt }
1508
- },
1509
- resolve: async (_parent, args, context, info) => {
1510
- const includeTotalCount = selectionIncludesField(info, "totalCount");
1511
- return executePluralQuery(
1512
- table,
1513
- context.drizzle,
1514
- args,
1515
- includeTotalCount
1516
- );
1517
- }
1518
- };
1519
- }
1520
- queryFields._meta = {
1521
- type: GraphQLMeta,
1522
- resolve: async (_source, _args, context) => {
1523
- const status2 = await context.metadataStore.getStatus();
1524
- return { status: status2 };
1525
- }
1526
- };
1527
- return new GraphQLSchema({
1528
- // Include these here so they are listed first in the printed schema.
1529
- types: [GraphQLJSON, GraphQLBigInt, GraphQLPageInfo, GraphQLMeta],
1530
- query: new GraphQLObjectType({
1531
- name: "Query",
1532
- fields: queryFields
1533
- })
1534
- });
1535
- }
1536
- var GraphQLPageInfo = new GraphQLObjectType({
1537
- name: "PageInfo",
1538
- fields: {
1539
- hasNextPage: { type: new GraphQLNonNull(GraphQLBoolean) },
1540
- hasPreviousPage: { type: new GraphQLNonNull(GraphQLBoolean) },
1541
- startCursor: { type: GraphQLString },
1542
- endCursor: { type: GraphQLString }
1543
- }
1544
- });
1545
- var GraphQLBigInt = new GraphQLScalarType2({
1546
- name: "BigInt",
1547
- serialize: (value) => String(value),
1548
- parseValue: (value) => BigInt(value),
1549
- parseLiteral: (value) => {
1550
- if (value.kind === "StringValue") {
1551
- return BigInt(value.value);
1552
- } else {
1553
- throw new Error(
1554
- `Invalid value kind provided for field of type BigInt: ${value.kind}. Expected: StringValue`
1555
- );
1556
- }
1557
- }
1558
- });
1559
- var GraphQLMeta = new GraphQLObjectType({
1560
- name: "Meta",
1561
- fields: { status: { type: GraphQLJSON } }
1562
- });
1563
- var columnToGraphQLCore = (column, enumTypes) => {
1564
- if (column.columnType === "PgEvmBigint") {
1565
- return GraphQLBigInt;
1566
- }
1567
- if (column instanceof PgEnumColumn) {
1568
- if (column.enum === void 0) {
1569
- throw new Error(
1570
- `Internal error: Expected enum column "${getColumnTsName(column)}" to have an "enum" property`
1571
- );
1572
- }
1573
- const enumType = enumTypes[column.enum.enumName];
1574
- if (enumType === void 0) {
1575
- throw new Error(
1576
- `Internal error: Expected to find a GraphQL enum named "${column.enum.enumName}"`
1577
- );
1578
- }
1579
- return enumType;
1580
- }
1581
- switch (column.dataType) {
1582
- case "boolean":
1583
- return GraphQLBoolean;
1584
- case "json":
1585
- return GraphQLJSON;
1586
- case "date":
1587
- return GraphQLString;
1588
- case "string":
1589
- return GraphQLString;
1590
- case "bigint":
1591
- return GraphQLString;
1592
- case "number":
1593
- return is(column, PgInteger) || is(column, PgSerial) ? GraphQLInt : GraphQLFloat;
1594
- case "buffer":
1595
- return new GraphQLList(new GraphQLNonNull(GraphQLInt));
1596
- case "array": {
1597
- if (column.columnType === "PgVector") {
1598
- return new GraphQLList(new GraphQLNonNull(GraphQLFloat));
1599
- }
1600
- if (column.columnType === "PgGeometry") {
1601
- return new GraphQLList(new GraphQLNonNull(GraphQLFloat));
1602
- }
1603
- const innerType2 = columnToGraphQLCore(
1604
- column.baseColumn,
1605
- enumTypes
1606
- );
1607
- return new GraphQLList(new GraphQLNonNull(innerType2));
1608
- }
1609
- default:
1610
- throw new Error(`Type ${column.dataType} is not implemented`);
1611
- }
1612
- };
1613
- var innerType = (type) => {
1614
- if (type instanceof GraphQLScalarType2 || type instanceof GraphQLEnumType)
1615
- return type;
1616
- if (type instanceof GraphQLList || type instanceof GraphQLNonNull)
1617
- return innerType(type.ofType);
1618
- throw new Error(`Type ${type.toString()} is not implemented`);
1619
- };
1620
- async function executePluralQuery(table, drizzle, args, includeTotalCount, extraConditions = []) {
1621
- const rawTable = drizzle._.fullSchema[table.tsName];
1622
- const baseQuery = drizzle.query[table.tsName];
1623
- if (rawTable === void 0 || baseQuery === void 0)
1624
- throw new Error(`Internal error: Table "${table.tsName}" not found in RQB`);
1625
- const limit = args.limit ?? DEFAULT_LIMIT;
1626
- if (limit > MAX_LIMIT) {
1627
- throw new Error(`Invalid limit. Got ${limit}, expected <=${MAX_LIMIT}.`);
1628
- }
1629
- const orderBySchema = buildOrderBySchema(table, args);
1630
- const orderBy = orderBySchema.map(([columnName, direction]) => {
1631
- const column = table.columns[columnName];
1632
- if (column === void 0) {
1633
- throw new Error(
1634
- `Unknown column "${columnName}" used in orderBy argument`
1635
- );
1636
- }
1637
- return direction === "asc" ? asc(column) : desc(column);
1638
- });
1639
- const orderByReversed = orderBySchema.map(([columnName, direction]) => {
1640
- const column = table.columns[columnName];
1641
- if (column === void 0) {
1642
- throw new Error(
1643
- `Unknown column "${columnName}" used in orderBy argument`
1644
- );
1645
- }
1646
- return direction === "asc" ? desc(column) : asc(column);
1647
- });
1648
- const whereConditions = buildWhereConditions(args.where, table.columns);
1649
- const after = args.after ?? null;
1650
- const before = args.before ?? null;
1651
- if (after !== null && before !== null) {
1652
- throw new Error("Cannot specify both before and after cursors.");
1653
- }
1654
- let startCursor = null;
1655
- let endCursor = null;
1656
- let hasPreviousPage = false;
1657
- let hasNextPage = false;
1658
- const totalCountPromise = includeTotalCount ? drizzle.select({ count: count() }).from(rawTable).where(and(...whereConditions, ...extraConditions)).then((rows2) => rows2[0]?.count ?? null) : Promise.resolve(null);
1659
- if (after === null && before === null) {
1660
- const [rows2, totalCount2] = await Promise.all([
1661
- baseQuery.findMany({
1662
- where: and(...whereConditions, ...extraConditions),
1663
- orderBy,
1664
- limit: limit + 1
1665
- }),
1666
- totalCountPromise
1667
- ]);
1668
- if (rows2.length === limit + 1) {
1669
- rows2.pop();
1670
- hasNextPage = true;
1671
- }
1672
- startCursor = rows2.length > 0 ? encodeCursor(orderBySchema, rows2[0]) : null;
1673
- endCursor = rows2.length > 0 ? encodeCursor(orderBySchema, rows2[rows2.length - 1]) : null;
1674
- return {
1675
- items: rows2,
1676
- totalCount: totalCount2,
1677
- pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }
1678
- };
1679
- }
1680
- if (after !== null) {
1681
- const cursorObject2 = decodeCursor(after);
1682
- const cursorCondition2 = buildCursorCondition(
1683
- table,
1684
- orderBySchema,
1685
- "after",
1686
- cursorObject2
1687
- );
1688
- const [rows2, totalCount2] = await Promise.all([
1689
- baseQuery.findMany({
1690
- where: and(...whereConditions, cursorCondition2, ...extraConditions),
1691
- orderBy,
1692
- limit: limit + 2
1693
- }),
1694
- totalCountPromise
1695
- ]);
1696
- if (rows2.length === 0) {
1697
- return {
1698
- items: rows2,
1699
- totalCount: totalCount2,
1700
- pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }
1701
- };
1702
- }
1703
- if (encodeCursor(orderBySchema, rows2[0]) === after) {
1704
- rows2.shift();
1705
- hasPreviousPage = true;
1706
- } else {
1707
- rows2.pop();
1708
- }
1709
- if (rows2.length === limit + 1) {
1710
- rows2.pop();
1711
- hasNextPage = true;
1712
- }
1713
- startCursor = rows2.length > 0 ? encodeCursor(orderBySchema, rows2[0]) : null;
1714
- endCursor = rows2.length > 0 ? encodeCursor(orderBySchema, rows2[rows2.length - 1]) : null;
1715
- return {
1716
- items: rows2,
1717
- totalCount: totalCount2,
1718
- pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }
1719
- };
1720
- }
1721
- const cursorObject = decodeCursor(before);
1722
- const cursorCondition = buildCursorCondition(
1723
- table,
1724
- orderBySchema,
1725
- "before",
1726
- cursorObject
1727
- );
1728
- const [rows, totalCount] = await Promise.all([
1729
- baseQuery.findMany({
1730
- where: and(...whereConditions, cursorCondition, ...extraConditions),
1731
- orderBy: orderByReversed,
1732
- limit: limit + 2
1733
- }).then((rows2) => rows2.reverse()),
1734
- totalCountPromise
1735
- ]);
1736
- if (rows.length === 0) {
1737
- return {
1738
- items: rows,
1739
- totalCount,
1740
- pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }
1741
- };
1742
- }
1743
- if (encodeCursor(orderBySchema, rows[rows.length - 1]) === before) {
1744
- rows.pop();
1745
- hasNextPage = true;
1746
- } else {
1747
- rows.shift();
1748
- }
1749
- if (rows.length === limit + 1) {
1750
- rows.shift();
1751
- hasPreviousPage = true;
1752
- }
1753
- startCursor = rows.length > 0 ? encodeCursor(orderBySchema, rows[0]) : null;
1754
- endCursor = rows.length > 0 ? encodeCursor(orderBySchema, rows[rows.length - 1]) : null;
1755
- return {
1756
- items: rows,
1757
- totalCount,
1758
- pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }
1759
- };
1760
- }
1761
- var conditionSuffixes = {
1762
- universal: ["", "_not"],
1763
- singular: ["_in", "_not_in"],
1764
- plural: ["_has", "_not_has"],
1765
- numeric: ["_gt", "_lt", "_gte", "_lte"],
1766
- string: [
1767
- "_contains",
1768
- "_not_contains",
1769
- "_starts_with",
1770
- "_ends_with",
1771
- "_not_starts_with",
1772
- "_not_ends_with"
1773
- ]
1774
- };
1775
- var conditionSuffixesByLengthDesc = Object.values(conditionSuffixes).flat().sort((a, b) => b.length - a.length);
1776
- function buildWhereConditions(where, columns) {
1777
- const conditions = [];
1778
- if (where === void 0)
1779
- return conditions;
1780
- for (const [whereKey, rawValue] of Object.entries(where)) {
1781
- if (whereKey === "AND" || whereKey === "OR") {
1782
- if (!Array.isArray(rawValue)) {
1783
- throw new Error(
1784
- `Invalid query: Expected an array for the ${whereKey} operator. Got: ${rawValue}`
1785
- );
1786
- }
1787
- const nestedConditions = rawValue.flatMap(
1788
- (subWhere) => buildWhereConditions(subWhere, columns)
1789
- );
1790
- if (nestedConditions.length > 0) {
1791
- conditions.push(
1792
- whereKey === "AND" ? and(...nestedConditions) : or(...nestedConditions)
1793
- );
1794
- }
1795
- continue;
1796
- }
1797
- const conditionSuffix = conditionSuffixesByLengthDesc.find(
1798
- (s) => whereKey.endsWith(s)
1799
- );
1800
- if (conditionSuffix === void 0) {
1801
- throw new Error(
1802
- `Invariant violation: Condition suffix not found for where key ${whereKey}`
1803
- );
1804
- }
1805
- const columnName = whereKey.slice(
1806
- 0,
1807
- whereKey.length - conditionSuffix.length
1808
- );
1809
- const column = columns[columnName];
1810
- if (column === void 0) {
1811
- throw new Error(
1812
- `Invalid query: Where clause contains unknown column ${columnName}`
1813
- );
1814
- }
1815
- switch (conditionSuffix) {
1816
- case "":
1817
- if (column.columnType === "PgArray") {
1818
- conditions.push(
1819
- and(
1820
- arrayContains(column, rawValue),
1821
- arrayContained(column, rawValue)
1822
- )
1823
- );
1824
- } else {
1825
- conditions.push(eq(column, rawValue));
1826
- }
1827
- break;
1828
- case "_not":
1829
- if (column.columnType === "PgArray") {
1830
- conditions.push(
1831
- not(
1832
- and(
1833
- arrayContains(column, rawValue),
1834
- arrayContained(column, rawValue)
1835
- )
1836
- )
1837
- );
1838
- } else {
1839
- conditions.push(ne(column, rawValue));
1840
- }
1841
- break;
1842
- case "_in":
1843
- conditions.push(inArray(column, rawValue));
1844
- break;
1845
- case "_not_in":
1846
- conditions.push(notInArray(column, rawValue));
1847
- break;
1848
- case "_has":
1849
- conditions.push(arrayContains(column, [rawValue]));
1850
- break;
1851
- case "_not_has":
1852
- conditions.push(not(arrayContains(column, [rawValue])));
1853
- break;
1854
- case "_gt":
1855
- conditions.push(gt(column, rawValue));
1856
- break;
1857
- case "_lt":
1858
- conditions.push(lt(column, rawValue));
1859
- break;
1860
- case "_gte":
1861
- conditions.push(gte(column, rawValue));
1862
- break;
1863
- case "_lte":
1864
- conditions.push(lte(column, rawValue));
1865
- break;
1866
- case "_contains":
1867
- conditions.push(like(column, `%${rawValue}%`));
1868
- break;
1869
- case "_not_contains":
1870
- conditions.push(notLike(column, `%${rawValue}%`));
1871
- break;
1872
- case "_starts_with":
1873
- conditions.push(like(column, `${rawValue}%`));
1874
- break;
1875
- case "_ends_with":
1876
- conditions.push(like(column, `%${rawValue}`));
1877
- break;
1878
- case "_not_starts_with":
1879
- conditions.push(notLike(column, `${rawValue}%`));
1880
- break;
1881
- case "_not_ends_with":
1882
- conditions.push(notLike(column, `%${rawValue}`));
1883
- break;
1884
- default:
1885
- never(conditionSuffix);
1886
- }
1887
- }
1888
- return conditions;
1889
- }
1890
- function buildOrderBySchema(table, args) {
1891
- const userDirection = args.orderDirection ?? "asc";
1892
- const userColumns = args.orderBy !== void 0 ? [[args.orderBy, userDirection]] : [];
1893
- const pkColumns = table.primaryKey.map((column) => [
1894
- getColumnTsName(column),
1895
- userDirection
1896
- ]);
1897
- const missingPkColumns = pkColumns.filter(
1898
- (pkColumn) => !userColumns.some((userColumn) => userColumn[0] === pkColumn[0])
1899
- );
1900
- return [...userColumns, ...missingPkColumns];
1901
- }
1902
- function encodeCursor(orderBySchema, row) {
1903
- const cursorObject = Object.fromEntries(
1904
- orderBySchema.map(([columnName, _]) => [columnName, row[columnName]])
1905
- );
1906
- return encodeRowFragment(cursorObject);
1907
- }
1908
- function decodeCursor(cursor) {
1909
- return decodeRowFragment(cursor);
1910
- }
1911
- function encodeRowFragment(rowFragment) {
1912
- return Buffer.from(serialize(rowFragment)).toString("base64");
1913
- }
1914
- function decodeRowFragment(encodedRowFragment) {
1915
- return deserialize(Buffer.from(encodedRowFragment, "base64").toString());
1916
- }
1917
- function buildCursorCondition(table, orderBySchema, direction, cursorObject) {
1918
- const cursorColumns = orderBySchema.map(([columnName, orderDirection]) => {
1919
- const column = table.columns[columnName];
1920
- if (column === void 0)
1921
- throw new Error(
1922
- `Unknown column "${columnName}" used in orderBy argument`
1923
- );
1924
- const value = cursorObject[columnName];
1925
- let comparator;
1926
- let comparatorOrEquals;
1927
- if (direction === "after") {
1928
- [comparator, comparatorOrEquals] = orderDirection === "asc" ? [gt, gte] : [lt, lte];
1929
- } else {
1930
- [comparator, comparatorOrEquals] = orderDirection === "asc" ? [lt, lte] : [gt, gte];
1931
- }
1932
- return { column, value, comparator, comparatorOrEquals };
1933
- });
1934
- const buildCondition = (index2) => {
1935
- if (index2 === cursorColumns.length - 1) {
1936
- const { column, value, comparatorOrEquals } = cursorColumns[index2];
1937
- return comparatorOrEquals(column, value);
1938
- }
1939
- const currentColumn = cursorColumns[index2];
1940
- const nextCondition = buildCondition(index2 + 1);
1941
- return or(
1942
- currentColumn.comparator(currentColumn.column, currentColumn.value),
1943
- and(eq(currentColumn.column, currentColumn.value), nextCondition)
1944
- );
1945
- };
1946
- return buildCondition(0);
1947
- }
1948
- function buildDataLoaderCache({
1949
- drizzle
1950
- }) {
1951
- const dataLoaderMap = /* @__PURE__ */ new Map();
1952
- return ({ table }) => {
1953
- const baseQuery = drizzle.query[table.tsName];
1954
- if (baseQuery === void 0)
1955
- throw new Error(
1956
- `Internal error: Unknown table "${table.tsName}" in data loader cache`
1957
- );
1958
- let dataLoader = dataLoaderMap.get(table);
1959
- if (dataLoader === void 0) {
1960
- dataLoader = new DataLoader(
1961
- async (encodedIds) => {
1962
- const decodedRowFragments = encodedIds.map(decodeRowFragment);
1963
- const idConditions = decodedRowFragments.map(
1964
- (decodedRowFragment) => and(...buildWhereConditions(decodedRowFragment, table.columns))
1965
- );
1966
- const rows = await baseQuery.findMany({
1967
- where: or(...idConditions),
1968
- limit: encodedIds.length
1969
- });
1970
- return decodedRowFragments.map((decodedRowFragment) => {
1971
- return rows.find(
1972
- (row) => Object.entries(decodedRowFragment).every(
1973
- ([col, val]) => row[col] === val
1974
- )
1975
- );
1976
- });
1977
- },
1978
- { maxBatchSize: 1e3 }
1979
- );
1980
- dataLoaderMap.set(table, dataLoader);
1981
- }
1982
- return dataLoader;
1983
- };
1984
- }
1985
- function getColumnTsName(column) {
1986
- const tableColumns = getTableColumns(column.table);
1987
- return Object.entries(tableColumns).find(
1988
- ([_, c]) => c.name === column.name
1989
- )[0];
1990
- }
1991
- function selectionIncludesField(info, fieldName) {
1992
- for (const fieldNode of info.fieldNodes) {
1993
- for (const selection of fieldNode.selectionSet?.selections ?? []) {
1994
- if (selection.kind === "Field" && selection.name.value === fieldName) {
1995
- return true;
1996
- }
1997
- }
1998
- }
1999
- return false;
2000
- }
2001
-
2002
- // src/graphql/middleware.ts
2003
- var graphql = ({ db, schema }, {
2004
- maxOperationTokens = 1e3,
2005
- maxOperationDepth = 100,
2006
- maxOperationAliases = 30
2007
- } = {
2008
- // Default limits are from Apollo:
2009
- // https://www.apollographql.com/blog/prevent-graph-misuse-with-operation-size-and-complexity-limit
2010
- maxOperationTokens: 1e3,
2011
- maxOperationDepth: 100,
2012
- maxOperationAliases: 30
2013
- }) => {
2014
- const graphqlSchema = buildGraphQLSchema({ schema });
2015
- generateSchema({ graphqlSchema }).catch(() => {
2016
- });
2017
- const metadataStore = getMetadataStore({
2018
- database: globalThis.PONDER_DATABASE
2019
- });
2020
- const yoga = createYoga({
2021
- graphqlEndpoint: "*",
2022
- // Disable built-in route validation, use Hono routing instead
2023
- schema: graphqlSchema,
2024
- context: () => {
2025
- const getDataLoader = buildDataLoaderCache({ drizzle: db });
2026
- return { drizzle: db, metadataStore, getDataLoader };
2027
- },
2028
- maskedErrors: process.env.NODE_ENV === "production",
2029
- logging: false,
2030
- graphiql: false,
2031
- parserAndValidationCache: false,
2032
- plugins: [
2033
- maxTokensPlugin({ n: maxOperationTokens }),
2034
- maxDepthPlugin({ n: maxOperationDepth, ignoreIntrospection: false }),
2035
- maxAliasesPlugin({ n: maxOperationAliases, allowList: [] })
2036
- ]
2037
- });
2038
- return createMiddleware2(async (c) => {
2039
- if (c.req.method === "GET") {
2040
- return c.html(graphiQLHtml(c.req.path));
2041
- }
2042
- const response = await yoga.handle(c.req.raw);
2043
- response.status = 200;
2044
- response.statusText = "OK";
2045
- return response;
2046
- });
2047
- };
2048
- async function generateSchema({
2049
- graphqlSchema
2050
- }) {
2051
- const fs = await import(
2052
- /* webpackIgnore: true */
2053
- "node:fs"
2054
- );
2055
- const path = await import(
2056
- /* webpackIgnore: true */
2057
- "node:path"
2058
- );
2059
- fs.mkdirSync(path.join(process.cwd(), "generated"), { recursive: true });
2060
- fs.writeFileSync(
2061
- path.join(process.cwd(), "generated", "schema.graphql"),
2062
- printSchema(graphqlSchema),
2063
- "utf-8"
2064
- );
2065
- }
2066
-
2067
- // src/index.ts
2068
- import {
2069
- sql,
2070
- eq as eq2,
2071
- gt as gt2,
2072
- gte as gte2,
2073
- lt as lt2,
2074
- lte as lte2,
2075
- ne as ne2,
2076
- isNull,
2077
- isNotNull,
2078
- inArray as inArray2,
2079
- notInArray as notInArray2,
2080
- exists,
2081
- notExists,
2082
- between,
2083
- notBetween,
2084
- like as like2,
2085
- notLike as notLike2,
2086
- ilike,
2087
- notIlike,
2088
- not as not2,
2089
- asc as asc2,
2090
- desc as desc2,
2091
- and as and2,
2092
- or as or2,
2093
- count as count2,
2094
- countDistinct,
2095
- avg,
2096
- avgDistinct,
2097
- sum,
2098
- sumDistinct,
2099
- max,
2100
- min,
2101
- relations
2102
- } from "drizzle-orm";
2103
- import {
2104
- bigint as bigint2,
2105
- boolean,
2106
- char,
2107
- cidr,
2108
- date,
2109
- doublePrecision,
2110
- inet,
2111
- integer,
2112
- interval,
2113
- json,
2114
- jsonb,
2115
- line,
2116
- macaddr,
2117
- macaddr8,
2118
- numeric,
2119
- point,
2120
- real,
2121
- smallint,
2122
- text,
2123
- time,
2124
- timestamp,
2125
- uuid,
2126
- varchar,
2127
- index,
2128
- uniqueIndex,
2129
- alias,
2130
- foreignKey,
2131
- union,
2132
- unionAll,
2133
- intersect,
2134
- intersectAll,
2135
- except,
2136
- exceptAll
2137
- } from "drizzle-orm/pg-core";
2138
- export {
2139
- alias,
2140
- and2 as and,
2141
- asc2 as asc,
2142
- avg,
2143
- avgDistinct,
2144
- between,
2145
- bigint,
2146
- boolean,
2147
- char,
2148
- cidr,
2149
- client,
2150
- count2 as count,
2151
- countDistinct,
2152
- createConfig,
2153
- date,
2154
- desc2 as desc,
2155
- doublePrecision,
2156
- eq2 as eq,
2157
- except,
2158
- exceptAll,
2159
- exists,
2160
- factory,
2161
- foreignKey,
2162
- graphql,
2163
- gt2 as gt,
2164
- gte2 as gte,
2165
- hex,
2166
- ilike,
2167
- inArray2 as inArray,
2168
- index,
2169
- inet,
2170
- bigint2 as int8,
2171
- integer,
2172
- intersect,
2173
- intersectAll,
2174
- interval,
2175
- isNotNull,
2176
- isNull,
2177
- json,
2178
- jsonb,
2179
- like2 as like,
2180
- line,
2181
- loadBalance,
2182
- lt2 as lt,
2183
- lte2 as lte,
2184
- macaddr,
2185
- macaddr8,
2186
- max,
2187
- mergeAbis,
2188
- min,
2189
- ne2 as ne,
2190
- not2 as not,
2191
- notBetween,
2192
- notExists,
2193
- notIlike,
2194
- notInArray2 as notInArray,
2195
- notLike2 as notLike,
2196
- numeric,
2197
- onchainEnum,
2198
- onchainTable,
2199
- or2 as or,
2200
- point,
2201
- primaryKey,
2202
- rateLimit,
2203
- real,
2204
- relations,
2205
- replaceBigInts,
2206
- smallint,
2207
- sql,
2208
- sum,
2209
- sumDistinct,
2210
- text,
2211
- time,
2212
- timestamp,
2213
- union,
2214
- unionAll,
2215
- uniqueIndex,
2216
- uuid,
2217
- varchar
2218
- };
2219
- //# sourceMappingURL=index.js.map