@nicia-ai/typegraph 0.46.2 → 0.48.0

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 (310) hide show
  1. package/README.md +20 -1
  2. package/dist/backend/drizzle/indexes.cjs +9 -9
  3. package/dist/backend/drizzle/indexes.d.cts +1 -1
  4. package/dist/backend/drizzle/indexes.d.ts +1 -1
  5. package/dist/backend/drizzle/indexes.js +5 -5
  6. package/dist/backend/index.cjs +58 -49
  7. package/dist/backend/index.d.cts +37 -55
  8. package/dist/backend/index.d.ts +37 -55
  9. package/dist/backend/index.js +11 -10
  10. package/dist/backend/postgres/index.cjs +27 -26
  11. package/dist/backend/postgres/index.d.cts +21 -7
  12. package/dist/backend/postgres/index.d.ts +21 -7
  13. package/dist/backend/postgres/index.js +14 -13
  14. package/dist/backend/postgres/pglite-store.cjs +34 -33
  15. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  16. package/dist/backend/postgres/pglite-store.d.cts +8 -8
  17. package/dist/backend/postgres/pglite-store.d.ts +8 -8
  18. package/dist/backend/postgres/pglite-store.js +30 -29
  19. package/dist/backend/postgres/pglite-store.js.map +1 -1
  20. package/dist/backend/postgres/pglite.cjs +16 -15
  21. package/dist/backend/postgres/pglite.d.cts +3 -3
  22. package/dist/backend/postgres/pglite.d.ts +3 -3
  23. package/dist/backend/postgres/pglite.js +15 -14
  24. package/dist/backend/sqlite/index.cjs +24 -23
  25. package/dist/backend/sqlite/index.d.cts +20 -7
  26. package/dist/backend/sqlite/index.d.ts +20 -7
  27. package/dist/backend/sqlite/index.js +12 -11
  28. package/dist/backend/sqlite/libsql.cjs +19 -18
  29. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  30. package/dist/backend/sqlite/libsql.d.cts +3 -3
  31. package/dist/backend/sqlite/libsql.d.ts +3 -3
  32. package/dist/backend/sqlite/libsql.js +14 -13
  33. package/dist/backend/sqlite/libsql.js.map +1 -1
  34. package/dist/backend/sqlite/local-store.cjs +35 -34
  35. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  36. package/dist/backend/sqlite/local-store.d.cts +8 -8
  37. package/dist/backend/sqlite/local-store.d.ts +8 -8
  38. package/dist/backend/sqlite/local-store.js +31 -30
  39. package/dist/backend/sqlite/local-store.js.map +1 -1
  40. package/dist/backend/sqlite/local.cjs +17 -16
  41. package/dist/backend/sqlite/local.d.cts +3 -3
  42. package/dist/backend/sqlite/local.d.ts +3 -3
  43. package/dist/backend/sqlite/local.js +15 -14
  44. package/dist/{chunk-TCT66A7N.cjs → chunk-26YKDNUD.cjs} +10 -10
  45. package/dist/{chunk-TCT66A7N.cjs.map → chunk-26YKDNUD.cjs.map} +1 -1
  46. package/dist/{chunk-E4OSGBCM.cjs → chunk-2HIYYMWY.cjs} +139 -136
  47. package/dist/chunk-2HIYYMWY.cjs.map +1 -0
  48. package/dist/chunk-2QGYQBS2.cjs +161 -0
  49. package/dist/chunk-2QGYQBS2.cjs.map +1 -0
  50. package/dist/{chunk-GWXXHOLU.js → chunk-2SYZXD54.js} +21 -18
  51. package/dist/chunk-2SYZXD54.js.map +1 -0
  52. package/dist/{chunk-KA4L2NZ3.js → chunk-2TYSSBU5.js} +14 -14
  53. package/dist/{chunk-KA4L2NZ3.js.map → chunk-2TYSSBU5.js.map} +1 -1
  54. package/dist/{chunk-QOJ2L2AD.js → chunk-3DMMGT6S.js} +3 -3
  55. package/dist/{chunk-QOJ2L2AD.js.map → chunk-3DMMGT6S.js.map} +1 -1
  56. package/dist/{chunk-F36KZDFX.cjs → chunk-3FPR224C.cjs} +91 -91
  57. package/dist/{chunk-F36KZDFX.cjs.map → chunk-3FPR224C.cjs.map} +1 -1
  58. package/dist/{chunk-32UETY6S.cjs → chunk-3KOY4FH3.cjs} +207 -28
  59. package/dist/chunk-3KOY4FH3.cjs.map +1 -0
  60. package/dist/{chunk-QU7QLJA4.cjs → chunk-3U5ABFDW.cjs} +26 -26
  61. package/dist/{chunk-QU7QLJA4.cjs.map → chunk-3U5ABFDW.cjs.map} +1 -1
  62. package/dist/{chunk-RFDEYLIK.js → chunk-4WMMBDS5.js} +7 -7
  63. package/dist/chunk-4WMMBDS5.js.map +1 -0
  64. package/dist/{chunk-R7EWHKID.js → chunk-5K2BKEBD.js} +19 -145
  65. package/dist/chunk-5K2BKEBD.js.map +1 -0
  66. package/dist/chunk-5PRKMB24.cjs +124 -0
  67. package/dist/chunk-5PRKMB24.cjs.map +1 -0
  68. package/dist/chunk-6LN7FIVU.js +107 -0
  69. package/dist/chunk-6LN7FIVU.js.map +1 -0
  70. package/dist/{chunk-D6GCNNMK.cjs → chunk-6NGW27EO.cjs} +10 -10
  71. package/dist/{chunk-D6GCNNMK.cjs.map → chunk-6NGW27EO.cjs.map} +1 -1
  72. package/dist/{chunk-WHS2Y43J.js → chunk-6SWPJEYN.js} +5 -5
  73. package/dist/{chunk-WHS2Y43J.js.map → chunk-6SWPJEYN.js.map} +1 -1
  74. package/dist/{chunk-7TKNK32B.js → chunk-7SQSZN2J.js} +5 -5
  75. package/dist/{chunk-7TKNK32B.js.map → chunk-7SQSZN2J.js.map} +1 -1
  76. package/dist/{chunk-UTVQPZPN.cjs → chunk-7XUYFFR4.cjs} +20 -20
  77. package/dist/chunk-7XUYFFR4.cjs.map +1 -0
  78. package/dist/{chunk-KXSMF6PL.js → chunk-ACGSAMD3.js} +39 -34
  79. package/dist/chunk-ACGSAMD3.js.map +1 -0
  80. package/dist/{chunk-PYKF7UIL.cjs → chunk-AOSSQDVO.cjs} +13 -13
  81. package/dist/{chunk-PYKF7UIL.cjs.map → chunk-AOSSQDVO.cjs.map} +1 -1
  82. package/dist/{chunk-AT3MLMJV.js → chunk-AX6JGVTZ.js} +91 -20
  83. package/dist/chunk-AX6JGVTZ.js.map +1 -0
  84. package/dist/{chunk-WA64ZSCA.cjs → chunk-BFUOME67.cjs} +11 -11
  85. package/dist/{chunk-WA64ZSCA.cjs.map → chunk-BFUOME67.cjs.map} +1 -1
  86. package/dist/{chunk-YQ4JONWE.js → chunk-BRRP76WO.js} +401 -131
  87. package/dist/chunk-BRRP76WO.js.map +1 -0
  88. package/dist/{chunk-FCIZNUW5.js → chunk-CHAOFCHV.js} +3 -3
  89. package/dist/{chunk-FCIZNUW5.js.map → chunk-CHAOFCHV.js.map} +1 -1
  90. package/dist/chunk-CICO5GXD.cjs +12 -0
  91. package/dist/{chunk-73MWKDFK.cjs.map → chunk-CICO5GXD.cjs.map} +1 -1
  92. package/dist/{chunk-S3G5VLSW.js → chunk-CT3ZKTOF.js} +7 -6
  93. package/dist/chunk-CT3ZKTOF.js.map +1 -0
  94. package/dist/{chunk-SXWLLQ3D.js → chunk-D5R42W5D.js} +4 -4
  95. package/dist/{chunk-SXWLLQ3D.js.map → chunk-D5R42W5D.js.map} +1 -1
  96. package/dist/{chunk-BZZI7B43.cjs → chunk-DO7SAMEK.cjs} +47 -47
  97. package/dist/{chunk-BZZI7B43.cjs.map → chunk-DO7SAMEK.cjs.map} +1 -1
  98. package/dist/chunk-DZAICA5J.js +147 -0
  99. package/dist/chunk-DZAICA5J.js.map +1 -0
  100. package/dist/{chunk-2ZWM2RFH.cjs → chunk-EDN4Y4ZG.cjs} +9 -9
  101. package/dist/{chunk-2ZWM2RFH.cjs.map → chunk-EDN4Y4ZG.cjs.map} +1 -1
  102. package/dist/{chunk-A4R3H7RU.cjs → chunk-EZEEWCFJ.cjs} +264 -361
  103. package/dist/chunk-EZEEWCFJ.cjs.map +1 -0
  104. package/dist/{chunk-BEB4OFZF.cjs → chunk-FA2AFWLP.cjs} +51 -59
  105. package/dist/chunk-FA2AFWLP.cjs.map +1 -0
  106. package/dist/{chunk-ZBVZ7HXD.cjs → chunk-FQPEMEWX.cjs} +12 -12
  107. package/dist/{chunk-ZBVZ7HXD.cjs.map → chunk-FQPEMEWX.cjs.map} +1 -1
  108. package/dist/{chunk-LNIWCQR4.js → chunk-GLHXM7C4.js} +3 -3
  109. package/dist/{chunk-LNIWCQR4.js.map → chunk-GLHXM7C4.js.map} +1 -1
  110. package/dist/{chunk-6BD6ZBKT.cjs → chunk-GYEG3ZLZ.cjs} +10 -10
  111. package/dist/{chunk-6BD6ZBKT.cjs.map → chunk-GYEG3ZLZ.cjs.map} +1 -1
  112. package/dist/{chunk-A7NMUYEL.cjs → chunk-HDL2ARHX.cjs} +27 -27
  113. package/dist/{chunk-A7NMUYEL.cjs.map → chunk-HDL2ARHX.cjs.map} +1 -1
  114. package/dist/{chunk-5ZJOB5YS.js → chunk-HEV35TGT.js} +4 -4
  115. package/dist/{chunk-5ZJOB5YS.js.map → chunk-HEV35TGT.js.map} +1 -1
  116. package/dist/{chunk-LHYSY6SE.js → chunk-I4GAZH5Z.js} +186 -9
  117. package/dist/chunk-I4GAZH5Z.js.map +1 -0
  118. package/dist/{chunk-BQM5P2NO.cjs → chunk-JB6T4GLL.cjs} +260 -223
  119. package/dist/chunk-JB6T4GLL.cjs.map +1 -0
  120. package/dist/{chunk-QPOQX2DI.cjs → chunk-JFRT7S3B.cjs} +1026 -369
  121. package/dist/chunk-JFRT7S3B.cjs.map +1 -0
  122. package/dist/{chunk-JCNTKRAK.js → chunk-JONXFAPO.js} +5 -5
  123. package/dist/{chunk-JCNTKRAK.js.map → chunk-JONXFAPO.js.map} +1 -1
  124. package/dist/{chunk-WEJHA7AD.js → chunk-KF6K7TGH.js} +109 -75
  125. package/dist/chunk-KF6K7TGH.js.map +1 -0
  126. package/dist/{chunk-EDJDDY6H.js → chunk-KKBDXCLQ.js} +4 -4
  127. package/dist/{chunk-EDJDDY6H.js.map → chunk-KKBDXCLQ.js.map} +1 -1
  128. package/dist/{chunk-ZHOAZD7Q.cjs → chunk-L3LQNR34.cjs} +161 -161
  129. package/dist/{chunk-ZHOAZD7Q.cjs.map → chunk-L3LQNR34.cjs.map} +1 -1
  130. package/dist/{chunk-AF3TWL5C.cjs → chunk-LRQKXRXO.cjs} +4 -4
  131. package/dist/{chunk-AF3TWL5C.cjs.map → chunk-LRQKXRXO.cjs.map} +1 -1
  132. package/dist/chunk-MKJ4KXL5.cjs +12 -0
  133. package/dist/{chunk-6LAXM4J2.cjs.map → chunk-MKJ4KXL5.cjs.map} +1 -1
  134. package/dist/{chunk-KCH7WQA5.cjs → chunk-MRDBBHIZ.cjs} +48 -2
  135. package/dist/chunk-MRDBBHIZ.cjs.map +1 -0
  136. package/dist/{chunk-FXNHZFZV.js → chunk-MYKHJI2J.js} +3 -3
  137. package/dist/{chunk-FXNHZFZV.js.map → chunk-MYKHJI2J.js.map} +1 -1
  138. package/dist/{chunk-Z43KWLZF.js → chunk-NACVVDWB.js} +213 -12
  139. package/dist/chunk-NACVVDWB.js.map +1 -0
  140. package/dist/{chunk-72WUT4GG.js → chunk-NVY5CJFP.js} +4 -4
  141. package/dist/{chunk-72WUT4GG.js.map → chunk-NVY5CJFP.js.map} +1 -1
  142. package/dist/{chunk-WYFB7BN3.js → chunk-OD4SSY2U.js} +166 -48
  143. package/dist/chunk-OD4SSY2U.js.map +1 -0
  144. package/dist/{chunk-ZIH42CRX.cjs → chunk-OI2GQ25X.cjs} +7 -7
  145. package/dist/{chunk-ZIH42CRX.cjs.map → chunk-OI2GQ25X.cjs.map} +1 -1
  146. package/dist/{chunk-AU3IJNNP.js → chunk-OMZ37BM2.js} +5 -5
  147. package/dist/{chunk-AU3IJNNP.js.map → chunk-OMZ37BM2.js.map} +1 -1
  148. package/dist/{chunk-C4DYN2SD.cjs → chunk-OORXGFL5.cjs} +48 -48
  149. package/dist/{chunk-C4DYN2SD.cjs.map → chunk-OORXGFL5.cjs.map} +1 -1
  150. package/dist/{chunk-HNYLMPQQ.cjs → chunk-OTUPEF2W.cjs} +149 -78
  151. package/dist/chunk-OTUPEF2W.cjs.map +1 -0
  152. package/dist/{chunk-BRN3RGD2.js → chunk-OVI7IXYX.js} +3 -3
  153. package/dist/{chunk-BRN3RGD2.js.map → chunk-OVI7IXYX.js.map} +1 -1
  154. package/dist/{chunk-WMKEGJG4.js → chunk-P6YLZTRE.js} +3 -3
  155. package/dist/{chunk-WMKEGJG4.js.map → chunk-P6YLZTRE.js.map} +1 -1
  156. package/dist/{chunk-C2ZP5YS6.cjs → chunk-PFBRJBUL.cjs} +278 -160
  157. package/dist/chunk-PFBRJBUL.cjs.map +1 -0
  158. package/dist/{chunk-EJSYWAEV.js → chunk-QTD6HX4O.js} +5 -5
  159. package/dist/{chunk-EJSYWAEV.js.map → chunk-QTD6HX4O.js.map} +1 -1
  160. package/dist/{chunk-JL5UEBWT.cjs → chunk-ROR5ZR6A.cjs} +45 -45
  161. package/dist/{chunk-JL5UEBWT.cjs.map → chunk-ROR5ZR6A.cjs.map} +1 -1
  162. package/dist/{chunk-EDHV4CBU.js → chunk-S5TERQVW.js} +37 -134
  163. package/dist/chunk-S5TERQVW.js.map +1 -0
  164. package/dist/{chunk-FSLTU57P.js → chunk-SDBBMD4N.js} +3 -3
  165. package/dist/{chunk-FSLTU57P.js.map → chunk-SDBBMD4N.js.map} +1 -1
  166. package/dist/{chunk-36LIJXWC.js → chunk-SHFBB23Q.js} +4 -4
  167. package/dist/{chunk-36LIJXWC.js.map → chunk-SHFBB23Q.js.map} +1 -1
  168. package/dist/chunk-SIT26LAZ.cjs +614 -0
  169. package/dist/chunk-SIT26LAZ.cjs.map +1 -0
  170. package/dist/{chunk-C6KE2HSQ.cjs → chunk-SR725PWF.cjs} +1662 -1392
  171. package/dist/chunk-SR725PWF.cjs.map +1 -0
  172. package/dist/{chunk-S7WIRFNS.cjs → chunk-TKZXMWQF.cjs} +13 -12
  173. package/dist/chunk-TKZXMWQF.cjs.map +1 -0
  174. package/dist/{chunk-5PDSCELM.cjs → chunk-TQHGE7UC.cjs} +29 -164
  175. package/dist/chunk-TQHGE7UC.cjs.map +1 -0
  176. package/dist/{chunk-XBHRKLZU.cjs → chunk-TUNPBZY3.cjs} +4 -4
  177. package/dist/{chunk-XBHRKLZU.cjs.map → chunk-TUNPBZY3.cjs.map} +1 -1
  178. package/dist/{chunk-KOAI3KIV.cjs → chunk-TZEGUG6D.cjs} +4 -4
  179. package/dist/{chunk-KOAI3KIV.cjs.map → chunk-TZEGUG6D.cjs.map} +1 -1
  180. package/dist/chunk-UGHG7PGX.js +592 -0
  181. package/dist/chunk-UGHG7PGX.js.map +1 -0
  182. package/dist/{chunk-N3QTGPC7.cjs → chunk-UMGZDVOA.cjs} +303 -101
  183. package/dist/chunk-UMGZDVOA.cjs.map +1 -0
  184. package/dist/{chunk-RHDOAQCT.cjs → chunk-WCCATHMB.cjs} +140 -135
  185. package/dist/chunk-WCCATHMB.cjs.map +1 -0
  186. package/dist/{chunk-DYPRZ53S.cjs → chunk-WODMN3Q2.cjs} +27 -27
  187. package/dist/{chunk-DYPRZ53S.cjs.map → chunk-WODMN3Q2.cjs.map} +1 -1
  188. package/dist/{chunk-OZJCH7ZS.js → chunk-XVWOYKIK.js} +3 -3
  189. package/dist/{chunk-OZJCH7ZS.js.map → chunk-XVWOYKIK.js.map} +1 -1
  190. package/dist/{chunk-IHRDX7K6.js → chunk-YIURNGXI.js} +46 -56
  191. package/dist/chunk-YIURNGXI.js.map +1 -0
  192. package/dist/{chunk-GWUWRZXW.js → chunk-YVF2EM7B.js} +3 -3
  193. package/dist/{chunk-GWUWRZXW.js.map → chunk-YVF2EM7B.js.map} +1 -1
  194. package/dist/{chunk-EAMVXR5B.js → chunk-ZDKTPBGV.js} +4 -4
  195. package/dist/{chunk-EAMVXR5B.js.map → chunk-ZDKTPBGV.js.map} +1 -1
  196. package/dist/{chunk-A2LJG5GM.js → chunk-ZFMCDJGB.js} +803 -148
  197. package/dist/chunk-ZFMCDJGB.js.map +1 -0
  198. package/dist/{chunk-62ZXBMSD.js → chunk-ZLONH2UD.js} +46 -3
  199. package/dist/chunk-ZLONH2UD.js.map +1 -0
  200. package/dist/core/index.cjs +28 -27
  201. package/dist/core/index.d.cts +4 -4
  202. package/dist/core/index.d.ts +4 -4
  203. package/dist/core/index.js +8 -7
  204. package/dist/ddl-BL1NZLMY.d.cts +78 -0
  205. package/dist/ddl-D_oW-EVO.d.ts +78 -0
  206. package/dist/graph-extension/index.cjs +20 -20
  207. package/dist/graph-extension/index.d.cts +4 -4
  208. package/dist/graph-extension/index.d.ts +4 -4
  209. package/dist/graph-extension/index.js +4 -4
  210. package/dist/graph-merge/index.cjs +3418 -706
  211. package/dist/graph-merge/index.cjs.map +1 -1
  212. package/dist/graph-merge/index.d.cts +550 -58
  213. package/dist/graph-merge/index.d.ts +550 -58
  214. package/dist/graph-merge/index.js +3191 -497
  215. package/dist/graph-merge/index.js.map +1 -1
  216. package/dist/{index-Deyu8IXL.d.ts → index-COs_z6nV.d.cts} +47 -3
  217. package/dist/{index-DrRS51Ld.d.cts → index-D7d1u2gr.d.ts} +47 -3
  218. package/dist/index.cjs +233 -216
  219. package/dist/index.cjs.map +1 -1
  220. package/dist/index.d.cts +12 -12
  221. package/dist/index.d.ts +12 -12
  222. package/dist/index.js +35 -34
  223. package/dist/index.js.map +1 -1
  224. package/dist/indexes/index.cjs +13 -13
  225. package/dist/indexes/index.d.cts +4 -4
  226. package/dist/indexes/index.d.ts +4 -4
  227. package/dist/indexes/index.js +6 -6
  228. package/dist/interchange/index.cjs +53 -52
  229. package/dist/interchange/index.cjs.map +1 -1
  230. package/dist/interchange/index.d.cts +17 -13
  231. package/dist/interchange/index.d.ts +17 -13
  232. package/dist/interchange/index.js +17 -16
  233. package/dist/interchange/index.js.map +1 -1
  234. package/dist/{manager-ptr3JLRP.d.cts → manager-CYaff3n3.d.cts} +2 -2
  235. package/dist/{manager-DX983gJ0.d.ts → manager-D9eRT_ns.d.ts} +2 -2
  236. package/dist/{materialize-indexes-CpXoggWU.d.ts → materialize-indexes-DJ3ykH59.d.ts} +1 -1
  237. package/dist/{materialize-indexes-BXz77YqO.d.cts → materialize-indexes-DTtAnvfY.d.cts} +1 -1
  238. package/dist/{postgres-DwgEXSPI.d.cts → postgres-CcL4bAHS.d.ts} +1 -1
  239. package/dist/{postgres-QdOMHTBz.d.ts → postgres-DMj39MEu.d.cts} +1 -1
  240. package/dist/profiler/index.d.cts +9 -9
  241. package/dist/profiler/index.d.ts +9 -9
  242. package/dist/provenance/index.cjs +46 -46
  243. package/dist/provenance/index.cjs.map +1 -1
  244. package/dist/provenance/index.d.cts +7 -7
  245. package/dist/provenance/index.d.ts +7 -7
  246. package/dist/provenance/index.js +13 -13
  247. package/dist/provenance/index.js.map +1 -1
  248. package/dist/repair-validity-windows-BFNZvd_H.d.cts +166 -0
  249. package/dist/repair-validity-windows-DlUSqwCg.d.ts +166 -0
  250. package/dist/schema/index.cjs +45 -44
  251. package/dist/schema/index.d.cts +6 -6
  252. package/dist/schema/index.d.ts +6 -6
  253. package/dist/schema/index.js +18 -17
  254. package/dist/{searchable-BOUuA83f.d.ts → searchable-DHJMh_nj.d.cts} +1 -1
  255. package/dist/{searchable-BrUh0pdc.d.cts → searchable-bpE1bBfc.d.ts} +1 -1
  256. package/dist/{sqlite-BfYcV61E.d.cts → sqlite-D7Oz0SQh.d.ts} +1 -1
  257. package/dist/{sqlite-DK40XVR1.d.ts → sqlite-YppHrNFb.d.cts} +1 -1
  258. package/dist/{store-FTqBpuJD.d.cts → store-JUVvtmR4.d.cts} +228 -92
  259. package/dist/{store-Bo1psfVZ.d.ts → store-UzrGvZOo.d.ts} +228 -92
  260. package/dist/{temporal-DPtn0HOu.d.ts → temporal-5GqpYCk2.d.cts} +1 -1
  261. package/dist/{temporal-CXewwLTB.d.cts → temporal-CbnLzTmM.d.ts} +1 -1
  262. package/dist/{types-Du78EvpN.d.ts → types-BqFZTQmV.d.cts} +60 -9
  263. package/dist/{types-Du78EvpN.d.cts → types-BqFZTQmV.d.ts} +60 -9
  264. package/dist/{types-CeT7xM4M.d.ts → types-Bx74kaTt.d.ts} +1 -1
  265. package/dist/{types-XR1nHERK.d.cts → types-CXAhpW-c.d.cts} +1 -1
  266. package/dist/{where-CJsp-YUf.d.cts → where-DI_Fqz-X.d.cts} +1 -1
  267. package/dist/{where-CMbFiWwp.d.ts → where-O-k2wgYm.d.ts} +1 -1
  268. package/package.json +1 -1
  269. package/dist/chunk-32UETY6S.cjs.map +0 -1
  270. package/dist/chunk-5PDSCELM.cjs.map +0 -1
  271. package/dist/chunk-62ZXBMSD.js.map +0 -1
  272. package/dist/chunk-6LAXM4J2.cjs +0 -12
  273. package/dist/chunk-73MWKDFK.cjs +0 -12
  274. package/dist/chunk-A2LJG5GM.js.map +0 -1
  275. package/dist/chunk-A4R3H7RU.cjs.map +0 -1
  276. package/dist/chunk-ANKOXPCC.cjs +0 -267
  277. package/dist/chunk-ANKOXPCC.cjs.map +0 -1
  278. package/dist/chunk-AT3MLMJV.js.map +0 -1
  279. package/dist/chunk-BEB4OFZF.cjs.map +0 -1
  280. package/dist/chunk-BQM5P2NO.cjs.map +0 -1
  281. package/dist/chunk-C2ZP5YS6.cjs.map +0 -1
  282. package/dist/chunk-C6KE2HSQ.cjs.map +0 -1
  283. package/dist/chunk-DSAWGCMP.js +0 -254
  284. package/dist/chunk-DSAWGCMP.js.map +0 -1
  285. package/dist/chunk-E4OSGBCM.cjs.map +0 -1
  286. package/dist/chunk-EDHV4CBU.js.map +0 -1
  287. package/dist/chunk-FA6Z7B5L.js +0 -244
  288. package/dist/chunk-FA6Z7B5L.js.map +0 -1
  289. package/dist/chunk-GVAMRRZR.cjs +0 -268
  290. package/dist/chunk-GVAMRRZR.cjs.map +0 -1
  291. package/dist/chunk-GWXXHOLU.js.map +0 -1
  292. package/dist/chunk-HNYLMPQQ.cjs.map +0 -1
  293. package/dist/chunk-IHRDX7K6.js.map +0 -1
  294. package/dist/chunk-KCH7WQA5.cjs.map +0 -1
  295. package/dist/chunk-KXSMF6PL.js.map +0 -1
  296. package/dist/chunk-LHYSY6SE.js.map +0 -1
  297. package/dist/chunk-N3QTGPC7.cjs.map +0 -1
  298. package/dist/chunk-QPOQX2DI.cjs.map +0 -1
  299. package/dist/chunk-R7EWHKID.js.map +0 -1
  300. package/dist/chunk-RFDEYLIK.js.map +0 -1
  301. package/dist/chunk-RHDOAQCT.cjs.map +0 -1
  302. package/dist/chunk-S3G5VLSW.js.map +0 -1
  303. package/dist/chunk-S7WIRFNS.cjs.map +0 -1
  304. package/dist/chunk-UTVQPZPN.cjs.map +0 -1
  305. package/dist/chunk-WEJHA7AD.js.map +0 -1
  306. package/dist/chunk-WYFB7BN3.js.map +0 -1
  307. package/dist/chunk-YQ4JONWE.js.map +0 -1
  308. package/dist/chunk-Z43KWLZF.js.map +0 -1
  309. package/dist/ddl-mE07h_EM.d.cts +0 -38
  310. package/dist/ddl-opIn8DfX.d.ts +0 -38
@@ -1,268 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkKCH7WQA5_cjs = require('./chunk-KCH7WQA5.cjs');
4
-
5
- // src/utils/sql-errors.ts
6
- var SQLITE_MISSING_TABLE_PATTERN = "no such table";
7
- var SQLITE_GENERIC_ERROR_CODE = "SQLITE_ERROR";
8
- var SQLITE_NOT_AUTHORIZED_CODE = "SQLITE_AUTH";
9
- var SQLITE_STALE_SNAPSHOT_CODE = "SQLITE_BUSY_SNAPSHOT";
10
- var SQLITE_STALE_SNAPSHOT_EXTENDED_CODE = 517;
11
- var DRIZZLE_QUERY_ERROR_PREFIX = "Failed query:";
12
- var POSTGRES_UNDEFINED_RELATION_PATTERN = /\b(?:relation|table)\s+"[^"]+"\s+does not exist\b/i;
13
- var POSTGRES_UNDEFINED_TABLE_CODE = "42P01";
14
- var POSTGRES_UNIQUE_VIOLATION_CODE = "23505";
15
- var POSTGRES_CONCURRENT_DDL_RACE_SQL_STATES = [
16
- POSTGRES_UNIQUE_VIOLATION_CODE,
17
- "42701"
18
- ];
19
- var POSTGRES_INTERNAL_ERROR_CODE = "XX000";
20
- var POSTGRES_CONCURRENT_TUPLE_UPDATE_MESSAGE = "tuple concurrently updated";
21
- var POSTGRES_TEMPORARY_TABLE_UNAVAILABLE_SQL_STATES = [
22
- "25006",
23
- "42501"
24
- ];
25
- var POSTGRES_READ_WRITE_REFUSED_SQL_STATES = ["0A000", "25006"];
26
- function* errorChain(error) {
27
- const seen = /* @__PURE__ */ new Set();
28
- let current = error;
29
- while (current !== void 0 && current !== null && !seen.has(current)) {
30
- seen.add(current);
31
- yield current;
32
- current = canReadProperty(current) ? Reflect.get(current, "cause") : void 0;
33
- }
34
- }
35
- function canReadProperty(value) {
36
- return typeof value === "object" && value !== null || typeof value === "function";
37
- }
38
- function isPostgresUndefinedTable(link) {
39
- return canReadProperty(link) && Reflect.get(link, "code") === POSTGRES_UNDEFINED_TABLE_CODE;
40
- }
41
- function messageProperty(link) {
42
- if (typeof link === "string") return link;
43
- if (link instanceof Error) return link.message;
44
- const message = canReadProperty(link) ? Reflect.get(link, "message") : void 0;
45
- return typeof message === "string" ? message : void 0;
46
- }
47
- function errorMessage(link) {
48
- return messageProperty(link) ?? String(link);
49
- }
50
- function missingTableMessage(link) {
51
- return typeof link === "string" || link instanceof Error ? messageProperty(link) : void 0;
52
- }
53
- function sqliteErrorCode(link) {
54
- if (!canReadProperty(link)) return void 0;
55
- return Reflect.get(link, "code");
56
- }
57
- function isBareSqliteErrorMarker(link) {
58
- const message = messageProperty(link);
59
- if (message === SQLITE_GENERIC_ERROR_CODE) return true;
60
- if (sqliteErrorCode(link) !== SQLITE_GENERIC_ERROR_CODE) return false;
61
- return message === void 0 || message === SQLITE_GENERIC_ERROR_CODE || message.includes(SQLITE_MISSING_TABLE_PATTERN);
62
- }
63
- function isPostgresUndefinedRelationMessage(link) {
64
- const message = errorMessage(link);
65
- if (message.startsWith(DRIZZLE_QUERY_ERROR_PREFIX)) return false;
66
- return POSTGRES_UNDEFINED_RELATION_PATTERN.test(message);
67
- }
68
- function isInsufficientResourcesError(error) {
69
- for (const link of errorChain(error)) {
70
- if (!canReadProperty(link)) continue;
71
- const code = Reflect.get(link, "code");
72
- if (typeof code === "string" && code.length === 5 && code.startsWith("53"))
73
- return true;
74
- }
75
- return false;
76
- }
77
- function isMissingTableError(error) {
78
- let everyPriorLinkWasError = true;
79
- for (const link of errorChain(error)) {
80
- if (isPostgresUndefinedTable(link)) return true;
81
- if (isPostgresUndefinedRelationMessage(link)) return true;
82
- if (isBareSqliteErrorMarker(link)) return true;
83
- if (everyPriorLinkWasError) {
84
- const message = missingTableMessage(link);
85
- if (message?.includes(SQLITE_MISSING_TABLE_PATTERN) === true) {
86
- return true;
87
- }
88
- }
89
- if (!(link instanceof Error)) everyPriorLinkWasError = false;
90
- }
91
- return false;
92
- }
93
- function isPostgresConcurrentTupleUpdate(link) {
94
- if (!canReadProperty(link)) return false;
95
- if (Reflect.get(link, "code") !== POSTGRES_INTERNAL_ERROR_CODE) return false;
96
- return messageProperty(link)?.includes(
97
- POSTGRES_CONCURRENT_TUPLE_UPDATE_MESSAGE
98
- ) === true;
99
- }
100
- function isPostgresConcurrentDdlRaceError(error) {
101
- for (const link of errorChain(error)) {
102
- if (!canReadProperty(link)) continue;
103
- if (isSqlStateIn(
104
- Reflect.get(link, "code"),
105
- POSTGRES_CONCURRENT_DDL_RACE_SQL_STATES
106
- )) {
107
- return true;
108
- }
109
- if (isPostgresConcurrentTupleUpdate(link)) return true;
110
- }
111
- return false;
112
- }
113
- var POSTGRES_CONSTRAINT_FIELDS = ["constraint", "constraint_name"];
114
- var POSTGRES_RELATION_FIELDS = ["table", "table_name"];
115
- var SQLITE_PRIMARY_KEY_VIOLATION_CODE = "SQLITE_CONSTRAINT_PRIMARYKEY";
116
- var SQLITE_PRIMARY_KEY_VIOLATION_EXTENDED_CODE = 1555;
117
- var SQLITE_EXTENDED_CODE_FIELDS = ["rawCode", "extendedCode"];
118
- function firstStringField(link, fields) {
119
- for (const field of fields) {
120
- const value = Reflect.get(link, field);
121
- if (typeof value === "string") return value;
122
- }
123
- return void 0;
124
- }
125
- function isPostgresPrimaryKeyViolation(link, relation) {
126
- if (Reflect.get(link, "code") !== POSTGRES_UNIQUE_VIOLATION_CODE)
127
- return false;
128
- if (firstStringField(link, POSTGRES_RELATION_FIELDS) !== relation.table) {
129
- return false;
130
- }
131
- const constraint = firstStringField(link, POSTGRES_CONSTRAINT_FIELDS);
132
- return constraint !== void 0 && relation.constraintNames.includes(constraint);
133
- }
134
- function isSqlitePrimaryKeyViolation(link) {
135
- if (Reflect.get(link, "code") === SQLITE_PRIMARY_KEY_VIOLATION_CODE) {
136
- return true;
137
- }
138
- for (const field of SQLITE_EXTENDED_CODE_FIELDS) {
139
- const value = Reflect.get(link, field);
140
- if (typeof value === "number" && value === SQLITE_PRIMARY_KEY_VIOLATION_EXTENDED_CODE) {
141
- return true;
142
- }
143
- }
144
- return false;
145
- }
146
- function isDuplicatePrimaryKeyError(error, relation) {
147
- for (const link of errorChain(error)) {
148
- if (!canReadProperty(link)) continue;
149
- if (isPostgresPrimaryKeyViolation(link, relation)) return true;
150
- if (isSqlitePrimaryKeyViolation(link)) return true;
151
- }
152
- return false;
153
- }
154
- function isSqlStateIn(code, states) {
155
- const known = states;
156
- return typeof code === "string" && known.includes(code);
157
- }
158
- function matchSqlState(error, states) {
159
- for (const link of errorChain(error)) {
160
- if (!canReadProperty(link)) continue;
161
- const code = Reflect.get(link, "code");
162
- if (isSqlStateIn(code, states)) return code;
163
- }
164
- return void 0;
165
- }
166
- function postgresTemporaryTableUnavailableSqlState(error) {
167
- return matchSqlState(error, POSTGRES_TEMPORARY_TABLE_UNAVAILABLE_SQL_STATES);
168
- }
169
- function postgresReadWriteRefusedSqlState(error) {
170
- return matchSqlState(error, POSTGRES_READ_WRITE_REFUSED_SQL_STATES);
171
- }
172
- function isSqliteNotAuthorizedError(error) {
173
- for (const link of errorChain(error)) {
174
- if (sqliteErrorCode(link) === SQLITE_NOT_AUTHORIZED_CODE) return true;
175
- const message = messageProperty(link);
176
- if (message?.includes(SQLITE_NOT_AUTHORIZED_CODE) === true && message.toLowerCase().includes("not authorized")) {
177
- return true;
178
- }
179
- }
180
- return false;
181
- }
182
- function isSqliteStaleSnapshotError(error) {
183
- for (const link of errorChain(error)) {
184
- if (sqliteErrorCode(link) === SQLITE_STALE_SNAPSHOT_CODE) return true;
185
- if (!canReadProperty(link)) continue;
186
- for (const field of SQLITE_EXTENDED_CODE_FIELDS) {
187
- if (Reflect.get(link, field) === SQLITE_STALE_SNAPSHOT_EXTENDED_CODE) {
188
- return true;
189
- }
190
- }
191
- }
192
- return false;
193
- }
194
- function historyMissingRecordedRelationsError(details, cause) {
195
- return new chunkKCH7WQA5_cjs.ConfigurationError(
196
- "history: true requires the recorded-time relations to exist, but a recorded relation is missing.",
197
- details,
198
- {
199
- cause,
200
- suggestion: "Create the recorded-time relations (typegraph_recorded_nodes, typegraph_recorded_edges, typegraph_recorded_clock) \u2014 e.g. re-run the generated migration SQL \u2014 on this database before enabling history capture."
201
- }
202
- );
203
- }
204
- async function withRecordedRelationsPrecondition(promise, details) {
205
- try {
206
- return await promise;
207
- } catch (error) {
208
- if (!isMissingTableError(error)) throw error;
209
- throw historyMissingRecordedRelationsError(
210
- { ...details, code: "RECORDED_RELATIONS_MISSING" },
211
- error
212
- );
213
- }
214
- }
215
- var DIMENSION_MISMATCH_PATTERN = /expected (\d+) dimensions(?:[,\s]+(?:not|got|but got|but)\s*(\d+))?/i;
216
- function parseDimensionMismatch(error) {
217
- for (const link of errorChain(error)) {
218
- const message = errorMessage(link);
219
- const match = DIMENSION_MISMATCH_PATTERN.exec(message);
220
- if (match) {
221
- return {
222
- expected: Number(match[1]),
223
- actual: match[2] === void 0 ? void 0 : Number(match[2])
224
- };
225
- }
226
- }
227
- return void 0;
228
- }
229
-
230
- // src/utils/array.ts
231
- function chunk(items, size) {
232
- if (!Number.isSafeInteger(size) || size < 1) {
233
- throw new RangeError(`chunk size must be a positive integer, got: ${size}`);
234
- }
235
- if (items.length === 0) return [];
236
- if (items.length <= size) return [items];
237
- const chunks = [];
238
- for (let start = 0; start < items.length; start += size) {
239
- chunks.push(items.slice(start, start + size));
240
- }
241
- return chunks;
242
- }
243
- function groupBy(items, keyFor) {
244
- const groups = /* @__PURE__ */ new Map();
245
- for (const item of items) {
246
- const key = keyFor(item);
247
- const group = groups.get(key) ?? [];
248
- group.push(item);
249
- groups.set(key, group);
250
- }
251
- return groups;
252
- }
253
-
254
- exports.chunk = chunk;
255
- exports.errorChain = errorChain;
256
- exports.groupBy = groupBy;
257
- exports.isDuplicatePrimaryKeyError = isDuplicatePrimaryKeyError;
258
- exports.isInsufficientResourcesError = isInsufficientResourcesError;
259
- exports.isMissingTableError = isMissingTableError;
260
- exports.isPostgresConcurrentDdlRaceError = isPostgresConcurrentDdlRaceError;
261
- exports.isSqliteNotAuthorizedError = isSqliteNotAuthorizedError;
262
- exports.isSqliteStaleSnapshotError = isSqliteStaleSnapshotError;
263
- exports.parseDimensionMismatch = parseDimensionMismatch;
264
- exports.postgresReadWriteRefusedSqlState = postgresReadWriteRefusedSqlState;
265
- exports.postgresTemporaryTableUnavailableSqlState = postgresTemporaryTableUnavailableSqlState;
266
- exports.withRecordedRelationsPrecondition = withRecordedRelationsPrecondition;
267
- //# sourceMappingURL=chunk-GVAMRRZR.cjs.map
268
- //# sourceMappingURL=chunk-GVAMRRZR.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/sql-errors.ts","../src/utils/array.ts"],"names":["ConfigurationError"],"mappings":";;;;;AAuBA,IAAM,4BAAA,GAA+B,eAAA;AACrC,IAAM,yBAAA,GAA4B,cAAA;AAClC,IAAM,0BAAA,GAA6B,aAAA;AAiBnC,IAAM,0BAAA,GAA6B,sBAAA;AACnC,IAAM,mCAAA,GAAsC,GAAA;AAC5C,IAAM,0BAAA,GAA6B,eAAA;AACnC,IAAM,mCAAA,GACJ,oDAAA;AASF,IAAM,6BAAA,GAAgC,OAAA;AACtC,IAAM,8BAAA,GAAiC,OAAA;AAevC,IAAM,uCAAA,GAA0C;AAAA,EAC9C,8BAAA;AAAA,EACA;AACF,CAAA;AAcA,IAAM,4BAAA,GAA+B,OAAA;AACrC,IAAM,wCAAA,GAA2C,4BAAA;AAQjD,IAAM,+CAAA,GAAkD;AAAA,EACtD,OAAA;AAAA,EACA;AACF,CAAA;AAUA,IA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CAAM,KAAA,EAAO,KAAA,GAAQ,IAAI,CAAC,CAAA;AAAA,EAC9C;AACA,EAAA,OAAO,MAAA;AACT;AAMO,SAAS,OAAA,CACd,OACA,MAAA,EACa;AACb,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAY;AAC/B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,GAAA,GAAM,OAAO,IAAI,CAAA;AACvB,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,GAAA,CAAI,GAAG,KAAK,EAAC;AAClC,IAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AACf,IAAA,MAAA,CAAO,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA,EACvB;AACA,EAAA,OAAO,MAAA;AACT","file":"chunk-GVAMRRZR.cjs","sourcesContent":["/**\n * Cross-dialect detection of \"this relation does not exist yet\" errors.\n *\n * Shared so the schema bootstrap (`loadActiveSchemaWithBootstrap`) and\n * the durable contribution-materialization gate (#135) agree on what a\n * missing-table failure looks like, and — critically — so neither one\n * swallows a genuine system fault (connection/permission/driver error)\n * as a benign \"not bootstrapped yet\".\n *\n * Detection walks the error's `cause` chain because Drizzle (>= the\n * `DrizzleQueryError` era, drizzle-orm ≥ 0.36) wraps every failure from a\n * query-builder call (`db.select()`, `db.insert()`, …): the wrapper's\n * `.message` becomes the failed query text and the real driver error —\n * which carries both the missing-relation text and the SQLSTATE — is\n * preserved on `.cause`. node-postgres / postgres-js nest the pg error\n * one link deep; better-sqlite3 throws it unwrapped; raw `client.query()`\n * fast paths surface it directly. Walking the chain makes the check\n * wrapper- and driver-agnostic instead of only matching the outermost\n * `.message`, which on Postgres is just the SQL string.\n */\n\nimport { ConfigurationError } from \"../errors\";\n\nconst SQLITE_MISSING_TABLE_PATTERN = \"no such table\";\nconst SQLITE_GENERIC_ERROR_CODE = \"SQLITE_ERROR\";\nconst SQLITE_NOT_AUTHORIZED_CODE = \"SQLITE_AUTH\";\n\n/**\n * SQLite's EXTENDED result code for \"this read transaction cannot become a\n * write transaction\": the connection began a DEFERRED transaction, took a read\n * snapshot, and another connection has committed since. SQLite refuses the\n * upgrade because honoring it would let the writer act on a stale view; the\n * only recovery is `ROLLBACK` and a fresh transaction (SQLite's own rule — the\n * failure is not retryable in place).\n *\n * It is the one code that names the DEFERRED frame itself. A transaction opened\n * `BEGIN IMMEDIATE` holds the writer slot from the start and can never produce\n * it, and plain `SQLITE_BUSY` says something else entirely (\"another writer\n * holds the slot right now\"), so this code alone can be attributed to how the\n * transaction was begun. The numeric spelling is accepted for libSQL, which\n * surfaces only `rawCode`/`extendedCode` over a remote connection.\n */\nconst SQLITE_STALE_SNAPSHOT_CODE = \"SQLITE_BUSY_SNAPSHOT\";\nconst SQLITE_STALE_SNAPSHOT_EXTENDED_CODE = 517;\nconst DRIZZLE_QUERY_ERROR_PREFIX = \"Failed query:\";\nconst POSTGRES_UNDEFINED_RELATION_PATTERN =\n /\\b(?:relation|table)\\s+\"[^\"]+\"\\s+does not exist\\b/i;\n\n/**\n * SQLSTATE for PostgreSQL `undefined_table`. Preferred over the\n * human-readable message: it is locale-independent (the \"... does not\n * exist\" text is translated under a non-English `lc_messages`) and is\n * preserved on the underlying driver error even when Drizzle overwrites\n * `.message` with the query text.\n */\nconst POSTGRES_UNDEFINED_TABLE_CODE = \"42P01\";\nconst POSTGRES_UNIQUE_VIOLATION_CODE = \"23505\";\n\n/**\n * SQLSTATEs a racing IDEMPOTENT DDL statement loses with — the ones that mean\n * \"another session is committing the very thing this statement asks for\", not\n * \"this statement is wrong\".\n *\n * PostgreSQL's `IF NOT EXISTS` is not a concurrency primitive: the existence\n * check cannot see another session's uncommitted catalog rows, so the loser\n * waits for the winner and is then handed the conflict the winner's commit\n * produced — `unique_violation` (23505) from `pg_type`/`pg_class` for a racing\n * CREATE, `duplicate_column` (42701) for a racing `ALTER TABLE ... ADD COLUMN\n * IF NOT EXISTS`. Retrying once after that wait observes the committed object\n * and succeeds; a failure the retry cannot clear stays loud.\n */\nconst POSTGRES_CONCURRENT_DDL_RACE_SQL_STATES = [\n POSTGRES_UNIQUE_VIOLATION_CODE,\n \"42701\",\n] as const;\n\n/**\n * The one concurrent-DDL race PostgreSQL reports with no SQLSTATE of its own:\n * `heap_update` losing a catalog row to a concurrent updater raises\n * `elog(ERROR, \"tuple concurrently updated\")`, which carries the catch-all\n * `internal_error` (XX000).\n *\n * XX000 alone is far too broad to retry on — it covers genuine server faults —\n * so this shape is identified by SQLSTATE AND message together. Matching the\n * message is sound here specifically because `elog` emits it through\n * `errmsg_internal`, which is NOT run through gettext: unlike an `ereport`\n * message, it reads identically under every `lc_messages`.\n */\nconst POSTGRES_INTERNAL_ERROR_CODE = \"XX000\";\nconst POSTGRES_CONCURRENT_TUPLE_UPDATE_MESSAGE = \"tuple concurrently updated\";\n\n/**\n * PostgreSQL failures that mean a temporary table cannot be created here:\n * `read_only_sql_transaction` (a replica or otherwise read-only execution\n * context) and `insufficient_privilege` (a role without the database `TEMP`\n * privilege).\n */\nconst POSTGRES_TEMPORARY_TABLE_UNAVAILABLE_SQL_STATES = [\n \"25006\",\n \"42501\",\n] as const;\n\n/**\n * PostgreSQL failures that mean the read-write transaction hosting temporary\n * tables cannot even start. A standby rejects the read-write access mode in\n * the `BEGIN` itself with `feature_not_supported` (\"cannot set transaction\n * read-write mode during recovery\"), so the failure never reaches a\n * `CREATE TEMP TABLE`; a session pinned read-only by a proxy or by\n * `default_transaction_read_only` reports `read_only_sql_transaction`.\n */\nconst POSTGRES_READ_WRITE_REFUSED_SQL_STATES = [\"0A000\", \"25006\"] as const;\n\nexport type PostgresTemporaryTableUnavailableSqlState =\n (typeof POSTGRES_TEMPORARY_TABLE_UNAVAILABLE_SQL_STATES)[number];\n\nexport type PostgresReadWriteRefusedSqlState =\n (typeof POSTGRES_READ_WRITE_REFUSED_SQL_STATES)[number];\n\n/**\n * Yields an error and each error reachable by following `.cause`,\n * outermost first. `seen` guards the pathological cyclic-cause case so a\n * self-referential chain can't spin forever.\n *\n * The walk intentionally follows `.cause` through *non-`Error`* links, not just\n * `Error` instances: postgres-js surfaces its driver error as a plain object\n * (message + SQLSTATE `code`) on a Drizzle wrapper's `.cause`, so stopping at\n * the first non-`Error` link would miss it (see the postgres-js test). A plain\n * object is classified by its locale-independent SQLSTATE alone\n * ({@link isPostgresUndefinedTable}); the looser SQLite message substring is\n * consulted only for `Error` instances and raw strings\n * ({@link missingTableMessage}), so an unrelated object in a cause chain that\n * merely mentions one of those phrases is not mistaken for a missing table.\n */\nexport function* errorChain(error: unknown): Generator<unknown, void, void> {\n const seen = new Set<unknown>();\n let current: unknown = error;\n while (current !== undefined && current !== null && !seen.has(current)) {\n seen.add(current);\n yield current;\n current =\n canReadProperty(current) ? Reflect.get(current, \"cause\") : undefined;\n }\n}\n\nfunction canReadProperty(value: unknown): value is object {\n return (\n (typeof value === \"object\" && value !== null) || typeof value === \"function\"\n );\n}\n\n/**\n * Whether a single chain link is a PostgreSQL `undefined_table` failure,\n * identified by its SQLSTATE rather than a message substring.\n */\nfunction isPostgresUndefinedTable(link: unknown): boolean {\n return (\n canReadProperty(link) &&\n Reflect.get(link, \"code\") === POSTGRES_UNDEFINED_TABLE_CODE\n );\n}\n\nfunction messageProperty(link: unknown): string | undefined {\n if (typeof link === \"string\") return link;\n if (link instanceof Error) return link.message;\n const message =\n canReadProperty(link) ?\n (Reflect.get(link, \"message\") as unknown)\n : undefined;\n return typeof message === \"string\" ? message : undefined;\n}\n\nfunction errorMessage(link: unknown): string {\n return messageProperty(link) ?? String(link);\n}\n\n/**\n * The message a SQLite missing-table substring match may be tested against — but\n * only for `Error` instances and raw `string` links, never an arbitrary plain\n * object.\n *\n * Generic \"does not exist\" is deliberately not substring-matched: PostgreSQL uses\n * that phrase for undefined columns, functions, types, and relations. PostgreSQL\n * missing tables are classified by SQLSTATE 42P01 when available, or by the\n * narrower driver-message shape `relation/table \"...\" does not exist` when a\n * bring-your-own driver omits SQLSTATE. SQLite does not expose a portable\n * SQLSTATE here, so the narrow \"no such table\" engine message is still accepted.\n */\nfunction missingTableMessage(link: unknown): string | undefined {\n return typeof link === \"string\" || link instanceof Error ?\n messageProperty(link)\n : undefined;\n}\n\nfunction sqliteErrorCode(link: unknown): unknown {\n if (!canReadProperty(link)) return undefined;\n return Reflect.get(link, \"code\");\n}\n\n/**\n * Cloudflare D1 / Durable Objects may surface a missing-table failure as the\n * generic SQLite code with no detail. Accept the bare marker, but do not\n * substring-match detailed `SQLITE_ERROR: ...` failures: those include syntax\n * errors and bind-limit faults that must stay loud.\n */\nfunction isBareSqliteErrorMarker(link: unknown): boolean {\n const message = messageProperty(link);\n if (message === SQLITE_GENERIC_ERROR_CODE) return true;\n if (sqliteErrorCode(link) !== SQLITE_GENERIC_ERROR_CODE) return false;\n return (\n message === undefined ||\n message === SQLITE_GENERIC_ERROR_CODE ||\n message.includes(SQLITE_MISSING_TABLE_PATTERN)\n );\n}\n\nfunction isPostgresUndefinedRelationMessage(link: unknown): boolean {\n const message = errorMessage(link);\n if (message.startsWith(DRIZZLE_QUERY_ERROR_PREFIX)) return false;\n return POSTGRES_UNDEFINED_RELATION_PATTERN.test(message);\n}\n\n/**\n * Whether any link in the cause chain is a PostgreSQL \"insufficient\n * resources\" failure (SQLSTATE class 53: disk_full, out_of_memory,\n * configuration_limit_exceeded, ...). Parallel index builds surface\n * shared-memory exhaustion this way (53100 from dsm_impl_posix on hosts\n * with a small /dev/shm); callers retry such work with parallelism\n * disabled. Identified by the locale-independent 5-character SQLSTATE\n * prefix only — never by message text.\n */\nexport function isInsufficientResourcesError(error: unknown): boolean {\n for (const link of errorChain(error)) {\n if (!canReadProperty(link)) continue;\n const code: unknown = Reflect.get(link, \"code\");\n if (typeof code === \"string\" && code.length === 5 && code.startsWith(\"53\"))\n return true;\n }\n return false;\n}\n\nexport function isMissingTableError(error: unknown): boolean {\n // SQLSTATE 42P01 is locale-independent and structural, so it is honored on\n // *every* link — including a plain driver-error object reached only by walking\n // through a non-`Error` `.cause` (postgres-js).\n //\n // The SQLite message substring is honored only while every prior link in the\n // chain was an `Error` (or the top-level string) — the reach of the\n // pre-broadening walk, which stopped at the first non-`Error` `.cause`.\n let everyPriorLinkWasError = true;\n for (const link of errorChain(error)) {\n if (isPostgresUndefinedTable(link)) return true;\n if (isPostgresUndefinedRelationMessage(link)) return true;\n if (isBareSqliteErrorMarker(link)) return true;\n if (everyPriorLinkWasError) {\n const message = missingTableMessage(link);\n if (message?.includes(SQLITE_MISSING_TABLE_PATTERN) === true) {\n return true;\n }\n }\n if (!(link instanceof Error)) everyPriorLinkWasError = false;\n }\n return false;\n}\n\n/** Whether one chain link is the un-coded `tuple concurrently updated` race. */\nfunction isPostgresConcurrentTupleUpdate(link: unknown): boolean {\n if (!canReadProperty(link)) return false;\n if (Reflect.get(link, \"code\") !== POSTGRES_INTERNAL_ERROR_CODE) return false;\n return (\n messageProperty(link)?.includes(\n POSTGRES_CONCURRENT_TUPLE_UPDATE_MESSAGE,\n ) === true\n );\n}\n\n/**\n * Whether PostgreSQL refused an IDEMPOTENT DDL statement because another\n * session was concurrently committing the same catalog change — the single\n * owner of \"this DDL lost a race and is worth one retry\".\n *\n * Every idempotent-DDL site in the codebase classifies through this one\n * function: the Postgres backend's `executeConcurrentCreateDdl` (bootstrap\n * tables, contribution materialization, identity relations, the index\n * materialization table and its additive columns) and the identity\n * schema-transition retry. A second copy of the predicate would drift the\n * moment one site learned about a new race SQLSTATE — as `ALTER TABLE ... ADD\n * COLUMN IF NOT EXISTS` (42701) did (#445).\n *\n * Callers MUST use it only around DDL that is a no-op when the object already\n * exists. On any other statement 23505/42701 are real defects, and retrying\n * them would hide a duplicate write.\n */\nexport function isPostgresConcurrentDdlRaceError(error: unknown): boolean {\n for (const link of errorChain(error)) {\n if (!canReadProperty(link)) continue;\n if (\n isSqlStateIn(\n Reflect.get(link, \"code\"),\n POSTGRES_CONCURRENT_DDL_RACE_SQL_STATES,\n )\n ) {\n return true;\n }\n if (isPostgresConcurrentTupleUpdate(link)) return true;\n }\n return false;\n}\n\n/**\n * The PostgreSQL error fields naming the violated constraint and its relation.\n * Both spellings are read because the drivers disagree: node-postgres and\n * PGlite expose the protocol fields as `constraint` / `table`, while\n * postgres-js exposes them as `constraint_name` / `table_name`. Reading only\n * one spelling would silently classify nothing on the other driver.\n */\nconst POSTGRES_CONSTRAINT_FIELDS = [\"constraint\", \"constraint_name\"] as const;\nconst POSTGRES_RELATION_FIELDS = [\"table\", \"table_name\"] as const;\n\n/**\n * SQLite's EXTENDED result code for a primary-key duplicate, in both spellings a\n * driver reports it: the symbolic name (better-sqlite3 `code`, and the\n * `SqliteError` the libSQL client nests on its own error's `.cause`) and the\n * numeric value (libSQL `rawCode` / `extendedCode`, the only form a remote\n * connection surfaces).\n *\n * The extended code — not the base `SQLITE_CONSTRAINT` — is what makes the\n * classification possible at all: SQLite distinguishes a PRIMARY KEY duplicate\n * (1555) from any other unique-index duplicate (`SQLITE_CONSTRAINT_UNIQUE`,\n * 2067) in the code itself, so nothing has to read the message, which names the\n * columns rather than the constraint.\n */\nconst SQLITE_PRIMARY_KEY_VIOLATION_CODE = \"SQLITE_CONSTRAINT_PRIMARYKEY\";\nconst SQLITE_PRIMARY_KEY_VIOLATION_EXTENDED_CODE = 1555;\nconst SQLITE_EXTENDED_CODE_FIELDS = [\"rawCode\", \"extendedCode\"] as const;\n\n/**\n * A relation plus the names its PRIMARY KEY constraint can carry — how far a\n * duplicate-key classification is allowed to reach on an engine that reports the\n * violated constraint by name. See {@link isDuplicatePrimaryKeyError}.\n */\nexport type PrimaryKeyRelation = Readonly<{\n table: string;\n constraintNames: readonly string[];\n}>;\n\nfunction firstStringField(\n link: object,\n fields: readonly string[],\n): string | undefined {\n for (const field of fields) {\n const value: unknown = Reflect.get(link, field);\n if (typeof value === \"string\") return value;\n }\n return undefined;\n}\n\n/**\n * Whether PostgreSQL reported this link as a duplicate of `relation`'s PRIMARY\n * KEY: SQLSTATE, relation, and constraint name must all agree on the SAME link\n * (the driver error), so a 23505 raised by an unrelated statement deeper in the\n * chain cannot be attributed to this relation.\n */\nfunction isPostgresPrimaryKeyViolation(\n link: object,\n relation: PrimaryKeyRelation,\n): boolean {\n if (Reflect.get(link, \"code\") !== POSTGRES_UNIQUE_VIOLATION_CODE)\n return false;\n if (firstStringField(link, POSTGRES_RELATION_FIELDS) !== relation.table) {\n return false;\n }\n const constraint = firstStringField(link, POSTGRES_CONSTRAINT_FIELDS);\n return (\n constraint !== undefined && relation.constraintNames.includes(constraint)\n );\n}\n\n/**\n * Whether SQLite reported this link as a PRIMARY KEY duplicate. The relation is\n * not checked because SQLite does not report one — see\n * {@link isDuplicatePrimaryKeyError} for why the call site supplies that scope.\n */\nfunction isSqlitePrimaryKeyViolation(link: object): boolean {\n if (Reflect.get(link, \"code\") === SQLITE_PRIMARY_KEY_VIOLATION_CODE) {\n return true;\n }\n for (const field of SQLITE_EXTENDED_CODE_FIELDS) {\n const value: unknown = Reflect.get(link, field);\n if (\n typeof value === \"number\" &&\n value === SQLITE_PRIMARY_KEY_VIOLATION_EXTENDED_CODE\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether the engine refused a statement because it duplicated a PRIMARY KEY —\n * on PostgreSQL, `relation`'s specifically.\n *\n * Classification is structural: SQLSTATE and SQLite extended result codes, plus\n * the PostgreSQL protocol's own constraint and relation fields. Never message\n * text, which is translated under a non-English `lc_messages`, is overwritten\n * with the query string by Drizzle's wrapper, and on SQLite names the key's\n * COLUMNS rather than the constraint. The `.cause` chain is walked because every\n * driver here nests the real error under at least one wrapper.\n *\n * Narrowing to the primary key is the whole point. A `unique: true` index\n * declaration materializes a UNIQUE INDEX on the same relation, and violating\n * THAT is a declared-uniqueness failure about the row's VALUES, not a duplicate\n * identity. PostgreSQL reports it under the index's own name and SQLite under a\n * different extended code, so it never matches here and keeps surfacing as it\n * did before.\n *\n * `relation` scopes the PostgreSQL arm, which is the one that can see a\n * constraint name. SQLite reports no relation at all, so its scope comes from\n * the CALL SITE instead: callers must invoke this only for a statement that\n * writes exactly one relation — the node or edge insert — where a primary-key\n * duplicate can only be that relation's. Applying it to a multi-relation\n * statement would attribute the wrong table's collision.\n */\nexport function isDuplicatePrimaryKeyError(\n error: unknown,\n relation: PrimaryKeyRelation,\n): boolean {\n for (const link of errorChain(error)) {\n if (!canReadProperty(link)) continue;\n if (isPostgresPrimaryKeyViolation(link, relation)) return true;\n if (isSqlitePrimaryKeyViolation(link)) return true;\n }\n return false;\n}\n\nfunction isSqlStateIn<SqlState extends string>(\n code: unknown,\n states: readonly SqlState[],\n): code is SqlState {\n const known: readonly string[] = states;\n return typeof code === \"string\" && known.includes(code);\n}\n\n/**\n * The first SQLSTATE in the error's cause chain that belongs to `states`. The\n * walk handles both direct driver errors and wrappers such as\n * DrizzleQueryError, which keeps the SQLSTATE-bearing error on `.cause`.\n */\nfunction matchSqlState<SqlState extends string>(\n error: unknown,\n states: readonly SqlState[],\n): SqlState | undefined {\n for (const link of errorChain(error)) {\n if (!canReadProperty(link)) continue;\n const code: unknown = Reflect.get(link, \"code\");\n if (isSqlStateIn(code, states)) return code;\n }\n return undefined;\n}\n\n/**\n * Returns the PostgreSQL SQLSTATE that prevented temporary-table creation.\n *\n * Callers must use this only at a `CREATE TEMP TABLE` execution seam: 42501\n * is otherwise a generic permission failure, and translating it elsewhere\n * would hide a different authorization problem.\n */\nexport function postgresTemporaryTableUnavailableSqlState(\n error: unknown,\n): PostgresTemporaryTableUnavailableSqlState | undefined {\n return matchSqlState(error, POSTGRES_TEMPORARY_TABLE_UNAVAILABLE_SQL_STATES);\n}\n\n/**\n * Returns the PostgreSQL SQLSTATE with which the server refused to open a\n * read-write transaction.\n *\n * Callers must use this only for a failure raised while opening such a\n * transaction — 0A000 is otherwise a generic \"unsupported feature\" report\n * that any statement can raise.\n */\nexport function postgresReadWriteRefusedSqlState(\n error: unknown,\n): PostgresReadWriteRefusedSqlState | undefined {\n return matchSqlState(error, POSTGRES_READ_WRITE_REFUSED_SQL_STATES);\n}\n\n/**\n * Whether SQLite rejected a statement through its authorizer. Cloudflare D1\n * and Durable Objects surface this as `not authorized: SQLITE_AUTH`, usually on\n * a Drizzle wrapper's `.cause`; native drivers may instead expose\n * `code: \"SQLITE_AUTH\"`. Both shapes are structural enough to distinguish from\n * an unrelated permission or connection failure.\n */\nexport function isSqliteNotAuthorizedError(error: unknown): boolean {\n for (const link of errorChain(error)) {\n if (sqliteErrorCode(link) === SQLITE_NOT_AUTHORIZED_CODE) return true;\n const message = messageProperty(link);\n if (\n message?.includes(SQLITE_NOT_AUTHORIZED_CODE) === true &&\n message.toLowerCase().includes(\"not authorized\")\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether SQLite refused a write because the enclosing DEFERRED transaction's\n * read snapshot went stale before it could take the writer slot\n * ({@link SQLITE_STALE_SNAPSHOT_CODE}).\n *\n * Classified structurally — the extended result code in either spelling a\n * driver reports it (better-sqlite3's symbolic `code`, libSQL's numeric\n * `rawCode`/`extendedCode`) — and never by message: SQLite renders this as the\n * bare, indistinguishable \"database is locked\".\n */\nexport function isSqliteStaleSnapshotError(error: unknown): boolean {\n for (const link of errorChain(error)) {\n if (sqliteErrorCode(link) === SQLITE_STALE_SNAPSHOT_CODE) return true;\n if (!canReadProperty(link)) continue;\n for (const field of SQLITE_EXTENDED_CODE_FIELDS) {\n if (Reflect.get(link, field) === SQLITE_STALE_SNAPSHOT_EXTENDED_CODE) {\n return true;\n }\n }\n }\n return false;\n}\n\nfunction historyMissingRecordedRelationsError(\n details: Record<string, unknown>,\n cause: unknown,\n): ConfigurationError {\n return new ConfigurationError(\n \"history: true requires the recorded-time relations to exist, but a recorded relation is missing.\",\n details,\n {\n cause,\n suggestion:\n \"Create the recorded-time relations (typegraph_recorded_nodes, typegraph_recorded_edges, typegraph_recorded_clock) — e.g. re-run the generated migration SQL — on this database before enabling history capture.\",\n },\n );\n}\n\n/**\n * Converts missing recorded-relation failures into the actionable precondition\n * error used by construction-time history checks. Capture paths use this after\n * the live write has already succeeded inside the same transaction; recorded\n * read paths use it when query/schema swapping reaches a recorded table that\n * has not been materialized yet.\n */\nexport async function withRecordedRelationsPrecondition<T>(\n promise: Promise<T>,\n details: Record<string, unknown>,\n): Promise<T> {\n try {\n return await promise;\n } catch (error) {\n if (!isMissingTableError(error)) throw error;\n throw historyMissingRecordedRelationsError(\n { ...details, code: \"RECORDED_RELATIONS_MISSING\" },\n error,\n );\n }\n}\n\n/**\n * Engine \"vector dimension mismatch\" message shapes. pgvector:\n * `expected 384 dimensions, not 512`; libSQL / sqlite-vec surface a similar\n * `expected N … got/not M`. The first capture is the dimension the *stored*\n * column expects; the optional second is the dimension that was *attempted*.\n */\nconst DIMENSION_MISMATCH_PATTERN =\n /expected (\\d+) dimensions(?:[,\\s]+(?:not|got|but got|but)\\s*(\\d+))?/i;\n\n/**\n * Parses an engine vector-dimension-mismatch error into `{ expected, actual }`\n * by walking the `.cause` chain (drivers wrap the real error). `expected` is\n * the stored column's dimension; `actual` (when the message includes it) is the\n * attempted vector's dimension. Returns `undefined` for unrelated errors.\n */\nexport function parseDimensionMismatch(\n error: unknown,\n): { expected: number; actual: number | undefined } | undefined {\n for (const link of errorChain(error)) {\n const message = errorMessage(link);\n const match = DIMENSION_MISMATCH_PATTERN.exec(message);\n if (match) {\n return {\n expected: Number(match[1]),\n actual: match[2] === undefined ? undefined : Number(match[2]),\n };\n }\n }\n return undefined;\n}\n","/**\n * Splits `items` into consecutive chunks of at most `size` elements.\n *\n * An empty input yields no chunks (`[]`), and an input that already fits in a\n * single chunk is returned without copying. Callers rely on the empty-input\n * behavior to skip work entirely rather than issue a statement with an empty\n * `IN ()` list.\n */\nexport function chunk<T>(\n items: readonly T[],\n size: number,\n): readonly (readonly T[])[] {\n // A non-positive, non-finite, or fractional size would make the slice loop\n // fail to advance correctly; fail loud rather than spin or emit empty chunks.\n // All current callers derive size from a positive integer bind-parameter\n // budget, so this only guards against a future regression.\n if (!Number.isSafeInteger(size) || size < 1) {\n throw new RangeError(`chunk size must be a positive integer, got: ${size}`);\n }\n if (items.length === 0) return [];\n if (items.length <= size) return [items];\n const chunks: T[][] = [];\n for (let start = 0; start < items.length; start += size) {\n chunks.push(items.slice(start, start + size));\n }\n return chunks;\n}\n\n/**\n * Groups items by a caller-supplied key while preserving input order within\n * each group.\n */\nexport function groupBy<T, K>(\n items: Iterable<T>,\n keyFor: (item: T) => K,\n): Map<K, T[]> {\n const groups = new Map<K, T[]>();\n for (const item of items) {\n const key = keyFor(item);\n const group = groups.get(key) ?? [];\n group.push(item);\n groups.set(key, group);\n }\n return groups;\n}\n"]}