@nicia-ai/typegraph 0.35.0 → 0.37.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 (234) hide show
  1. package/dist/backend/postgres/index.cjs +24 -24
  2. package/dist/backend/postgres/index.d.cts +6 -6
  3. package/dist/backend/postgres/index.d.ts +6 -6
  4. package/dist/backend/postgres/index.js +11 -11
  5. package/dist/backend/postgres/pglite.cjs +16 -16
  6. package/dist/backend/postgres/pglite.d.cts +3 -3
  7. package/dist/backend/postgres/pglite.d.ts +3 -3
  8. package/dist/backend/postgres/pglite.js +11 -11
  9. package/dist/backend/sqlite/index.cjs +22 -21
  10. package/dist/backend/sqlite/index.d.cts +11 -9
  11. package/dist/backend/sqlite/index.d.ts +11 -9
  12. package/dist/backend/sqlite/index.js +10 -9
  13. package/dist/backend/sqlite/libsql.cjs +15 -14
  14. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  15. package/dist/backend/sqlite/libsql.d.cts +3 -3
  16. package/dist/backend/sqlite/libsql.d.ts +3 -3
  17. package/dist/backend/sqlite/libsql.js +11 -10
  18. package/dist/backend/sqlite/libsql.js.map +1 -1
  19. package/dist/backend/sqlite/local.cjs +30 -23
  20. package/dist/backend/sqlite/local.cjs.map +1 -1
  21. package/dist/backend/sqlite/local.d.cts +3 -3
  22. package/dist/backend/sqlite/local.d.ts +3 -3
  23. package/dist/backend/sqlite/local.js +18 -11
  24. package/dist/backend/sqlite/local.js.map +1 -1
  25. package/dist/{chunk-TCOCYN2P.cjs → chunk-27SSDCEP.cjs} +14 -14
  26. package/dist/{chunk-TCOCYN2P.cjs.map → chunk-27SSDCEP.cjs.map} +1 -1
  27. package/dist/{chunk-5AQIKK56.cjs → chunk-2N6EOBTH.cjs} +16 -16
  28. package/dist/{chunk-5AQIKK56.cjs.map → chunk-2N6EOBTH.cjs.map} +1 -1
  29. package/dist/{chunk-FN35DLCN.cjs → chunk-3C2RYI6L.cjs} +13 -107
  30. package/dist/chunk-3C2RYI6L.cjs.map +1 -0
  31. package/dist/{chunk-4JEZZJ6S.cjs → chunk-3DS7Z4T4.cjs} +39 -39
  32. package/dist/{chunk-4JEZZJ6S.cjs.map → chunk-3DS7Z4T4.cjs.map} +1 -1
  33. package/dist/{chunk-BLZDPRXT.cjs → chunk-3GH67G4Z.cjs} +5 -5
  34. package/dist/{chunk-BLZDPRXT.cjs.map → chunk-3GH67G4Z.cjs.map} +1 -1
  35. package/dist/{chunk-K3PPLHY7.js → chunk-3RWZPJKV.js} +24 -9
  36. package/dist/chunk-3RWZPJKV.js.map +1 -0
  37. package/dist/{chunk-QWEUYILR.js → chunk-3SLPDKHQ.js} +4 -4
  38. package/dist/chunk-3SLPDKHQ.js.map +1 -0
  39. package/dist/{chunk-5A6FNS6N.cjs → chunk-3XXGYU62.cjs} +11 -11
  40. package/dist/{chunk-5A6FNS6N.cjs.map → chunk-3XXGYU62.cjs.map} +1 -1
  41. package/dist/{chunk-JBTOYDMN.js → chunk-44TA22QT.js} +58 -11
  42. package/dist/chunk-44TA22QT.js.map +1 -0
  43. package/dist/{chunk-UES55P7G.js → chunk-552KNYQJ.js} +2652 -409
  44. package/dist/chunk-552KNYQJ.js.map +1 -0
  45. package/dist/{chunk-VPYHY3LJ.cjs → chunk-5KEQ74YU.cjs} +14 -14
  46. package/dist/chunk-5KEQ74YU.cjs.map +1 -0
  47. package/dist/{chunk-Q5TEXCTB.js → chunk-5KPNWT6X.js} +3 -3
  48. package/dist/{chunk-Q5TEXCTB.js.map → chunk-5KPNWT6X.js.map} +1 -1
  49. package/dist/{chunk-MP2JQKSG.js → chunk-5PNMDJ7J.js} +108 -5
  50. package/dist/chunk-5PNMDJ7J.js.map +1 -0
  51. package/dist/{chunk-AW4A3P5A.cjs → chunk-5VQM6VWP.cjs} +2 -2
  52. package/dist/{chunk-AW4A3P5A.cjs.map → chunk-5VQM6VWP.cjs.map} +1 -1
  53. package/dist/{chunk-A3W7QG7K.js → chunk-5WWVZMVX.js} +2 -2
  54. package/dist/{chunk-A3W7QG7K.js.map → chunk-5WWVZMVX.js.map} +1 -1
  55. package/dist/{chunk-FACJJWGF.cjs → chunk-6EEO3OVU.cjs} +7 -7
  56. package/dist/{chunk-FACJJWGF.cjs.map → chunk-6EEO3OVU.cjs.map} +1 -1
  57. package/dist/{chunk-LGEALRC6.cjs → chunk-BVRDGYXQ.cjs} +113 -4
  58. package/dist/chunk-BVRDGYXQ.cjs.map +1 -0
  59. package/dist/{chunk-GSQ6NPH6.cjs → chunk-DEFQM7JU.cjs} +7 -7
  60. package/dist/{chunk-GSQ6NPH6.cjs.map → chunk-DEFQM7JU.cjs.map} +1 -1
  61. package/dist/{chunk-EM3CWPND.cjs → chunk-DIQ3AV5W.cjs} +574 -268
  62. package/dist/chunk-DIQ3AV5W.cjs.map +1 -0
  63. package/dist/{chunk-FPIZFYHE.js → chunk-EXU3RASM.js} +74 -15
  64. package/dist/chunk-EXU3RASM.js.map +1 -0
  65. package/dist/{chunk-H7YNSMA7.cjs → chunk-HAHNRASW.cjs} +20 -2
  66. package/dist/chunk-HAHNRASW.cjs.map +1 -0
  67. package/dist/{chunk-FL472AMI.cjs → chunk-IP3CGGPA.cjs} +8 -8
  68. package/dist/{chunk-FL472AMI.cjs.map → chunk-IP3CGGPA.cjs.map} +1 -1
  69. package/dist/{chunk-4TOD4LBZ.cjs → chunk-IPSVVTWT.cjs} +94 -35
  70. package/dist/chunk-IPSVVTWT.cjs.map +1 -0
  71. package/dist/{chunk-RGP33ZJ5.js → chunk-IXGYRP2P.js} +184 -92
  72. package/dist/chunk-IXGYRP2P.js.map +1 -0
  73. package/dist/{chunk-3TWF3SH4.js → chunk-J4IUSYFF.js} +251 -121
  74. package/dist/chunk-J4IUSYFF.js.map +1 -0
  75. package/dist/{chunk-O7UN7OXA.cjs → chunk-JBNOGRKW.cjs} +318 -188
  76. package/dist/chunk-JBNOGRKW.cjs.map +1 -0
  77. package/dist/{chunk-WDBCBWC4.js → chunk-K3Q3LJY3.js} +520 -221
  78. package/dist/chunk-K3Q3LJY3.js.map +1 -0
  79. package/dist/{chunk-OR5ZA5WP.js → chunk-K5UBVGJN.js} +4 -4
  80. package/dist/{chunk-OR5ZA5WP.js.map → chunk-K5UBVGJN.js.map} +1 -1
  81. package/dist/{chunk-UZV3AZKF.js → chunk-KQJ54OG5.js} +3 -3
  82. package/dist/{chunk-UZV3AZKF.js.map → chunk-KQJ54OG5.js.map} +1 -1
  83. package/dist/{chunk-QOTI55H7.js → chunk-L7HQ2OSI.js} +4 -4
  84. package/dist/{chunk-QOTI55H7.js.map → chunk-L7HQ2OSI.js.map} +1 -1
  85. package/dist/{chunk-55MZDDZV.js → chunk-M6VES7V6.js} +4 -4
  86. package/dist/{chunk-55MZDDZV.js.map → chunk-M6VES7V6.js.map} +1 -1
  87. package/dist/{chunk-J7WFGBJR.cjs → chunk-NBP2WTJW.cjs} +3249 -1006
  88. package/dist/chunk-NBP2WTJW.cjs.map +1 -0
  89. package/dist/{chunk-CK5BVQOW.cjs → chunk-NUIG3BCV.cjs} +100 -85
  90. package/dist/chunk-NUIG3BCV.cjs.map +1 -0
  91. package/dist/{chunk-EMF62TZG.cjs → chunk-NXQFATMF.cjs} +269 -177
  92. package/dist/chunk-NXQFATMF.cjs.map +1 -0
  93. package/dist/{chunk-KBGQIPRQ.js → chunk-PC2UBAUB.js} +20 -3
  94. package/dist/chunk-PC2UBAUB.js.map +1 -0
  95. package/dist/chunk-QARBLBXT.cjs +219 -0
  96. package/dist/chunk-QARBLBXT.cjs.map +1 -0
  97. package/dist/{chunk-6FR2MMS6.js → chunk-QERAIDRJ.js} +45 -4
  98. package/dist/chunk-QERAIDRJ.js.map +1 -0
  99. package/dist/chunk-QSXTWU4U.cjs +12 -0
  100. package/dist/{chunk-GUR2FNB5.cjs.map → chunk-QSXTWU4U.cjs.map} +1 -1
  101. package/dist/{chunk-QNKSQTKQ.js → chunk-RCVLFTCT.js} +49 -19
  102. package/dist/chunk-RCVLFTCT.js.map +1 -0
  103. package/dist/{chunk-VSPCZAXF.js → chunk-RRSNR3TP.js} +3 -3
  104. package/dist/{chunk-VSPCZAXF.js.map → chunk-RRSNR3TP.js.map} +1 -1
  105. package/dist/{chunk-WJT7OU7E.cjs → chunk-TGOMW4MB.cjs} +129 -98
  106. package/dist/chunk-TGOMW4MB.cjs.map +1 -0
  107. package/dist/{chunk-KMI7LYAF.js → chunk-TKT2XHED.js} +8 -8
  108. package/dist/{chunk-KMI7LYAF.js.map → chunk-TKT2XHED.js.map} +1 -1
  109. package/dist/{chunk-RGPG7EOJ.js → chunk-TPF25IG6.js} +3 -3
  110. package/dist/{chunk-RGPG7EOJ.js.map → chunk-TPF25IG6.js.map} +1 -1
  111. package/dist/{chunk-5SEGFTZX.js → chunk-UGZUAYAR.js} +3 -3
  112. package/dist/{chunk-5SEGFTZX.js.map → chunk-UGZUAYAR.js.map} +1 -1
  113. package/dist/{chunk-VHMPG6UL.js → chunk-UXLSNRYL.js} +11 -105
  114. package/dist/chunk-UXLSNRYL.js.map +1 -0
  115. package/dist/{chunk-FRV5Q5IO.js → chunk-UYQMBBWJ.js} +3 -3
  116. package/dist/{chunk-FRV5Q5IO.js.map → chunk-UYQMBBWJ.js.map} +1 -1
  117. package/dist/{chunk-UUT7UN2N.cjs → chunk-VGDDG3XJ.cjs} +7 -7
  118. package/dist/{chunk-UUT7UN2N.cjs.map → chunk-VGDDG3XJ.cjs.map} +1 -1
  119. package/dist/{chunk-CZQ3FO2Q.js → chunk-VKGKDOKR.js} +56 -21
  120. package/dist/chunk-VKGKDOKR.js.map +1 -0
  121. package/dist/{chunk-CTTSDJLY.cjs → chunk-VL2V6PEN.cjs} +11 -11
  122. package/dist/{chunk-CTTSDJLY.cjs.map → chunk-VL2V6PEN.cjs.map} +1 -1
  123. package/dist/{chunk-XOX22WHL.cjs → chunk-WOJMKB3N.cjs} +125 -90
  124. package/dist/chunk-WOJMKB3N.cjs.map +1 -0
  125. package/dist/{chunk-UMDVATGY.cjs → chunk-WWFHO375.cjs} +6 -6
  126. package/dist/{chunk-UMDVATGY.cjs.map → chunk-WWFHO375.cjs.map} +1 -1
  127. package/dist/{chunk-I7ZUZKFD.js → chunk-XGPUQ56G.js} +3 -3
  128. package/dist/{chunk-I7ZUZKFD.js.map → chunk-XGPUQ56G.js.map} +1 -1
  129. package/dist/{chunk-D7ZEOS56.cjs → chunk-XGU7DZDA.cjs} +74 -14
  130. package/dist/chunk-XGU7DZDA.cjs.map +1 -0
  131. package/dist/{chunk-S55OV6PW.cjs → chunk-XPCZADMT.cjs} +54 -11
  132. package/dist/chunk-XPCZADMT.cjs.map +1 -0
  133. package/dist/{chunk-T2WUSPDA.js → chunk-XWV4JT34.js} +3 -3
  134. package/dist/{chunk-T2WUSPDA.js.map → chunk-XWV4JT34.js.map} +1 -1
  135. package/dist/chunk-YTSN73ND.js +212 -0
  136. package/dist/chunk-YTSN73ND.js.map +1 -0
  137. package/dist/{ddl-CZz7a0E8.d.cts → ddl-BD-ZfKeX.d.cts} +3 -3
  138. package/dist/{ddl-C2rZ-Aen.d.ts → ddl-CS0KUVwB.d.ts} +3 -3
  139. package/dist/{extension-types-ixRpJVUp.d.cts → extension-types-BM2ACfYO.d.cts} +6 -1
  140. package/dist/{extension-types-ixRpJVUp.d.ts → extension-types-BM2ACfYO.d.ts} +6 -1
  141. package/dist/{fulltext-strategy-CDkSSYhq.d.cts → fulltext-strategy-C27vXaeB.d.cts} +127 -8
  142. package/dist/{fulltext-strategy-B57yvC5Q.d.ts → fulltext-strategy-DebsMrqg.d.ts} +127 -8
  143. package/dist/graph-extension/index.cjs +19 -19
  144. package/dist/graph-extension/index.d.cts +4 -4
  145. package/dist/graph-extension/index.d.ts +4 -4
  146. package/dist/graph-extension/index.js +4 -4
  147. package/dist/graph-merge/index.cjs +88 -88
  148. package/dist/graph-merge/index.cjs.map +1 -1
  149. package/dist/graph-merge/index.d.cts +6 -6
  150. package/dist/graph-merge/index.d.ts +6 -6
  151. package/dist/graph-merge/index.js +19 -19
  152. package/dist/graph-merge/index.js.map +1 -1
  153. package/dist/{index-Bks_3HHK.d.cts → index-BPM59vsg.d.cts} +119 -7
  154. package/dist/{index-6CSUAq-x.d.ts → index-BeacbPoe.d.ts} +119 -7
  155. package/dist/index.cjs +230 -185
  156. package/dist/index.cjs.map +1 -1
  157. package/dist/index.d.cts +11 -11
  158. package/dist/index.d.ts +11 -11
  159. package/dist/index.js +53 -40
  160. package/dist/index.js.map +1 -1
  161. package/dist/indexes/index.cjs +30 -21
  162. package/dist/indexes/index.d.cts +5 -5
  163. package/dist/indexes/index.d.ts +5 -5
  164. package/dist/indexes/index.js +8 -7
  165. package/dist/interchange/index.cjs +208 -30
  166. package/dist/interchange/index.cjs.map +1 -1
  167. package/dist/interchange/index.d.cts +25 -8
  168. package/dist/interchange/index.d.ts +25 -8
  169. package/dist/interchange/index.js +191 -11
  170. package/dist/interchange/index.js.map +1 -1
  171. package/dist/{manager-DwQi8eV0.d.cts → manager-D00_NXvT.d.ts} +11 -2
  172. package/dist/{manager-ejUCB52T.d.ts → manager-nU1vTJLy.d.cts} +11 -2
  173. package/dist/{materialize-indexes-B4e9360H.d.cts → materialize-indexes-CuR3gAZb.d.cts} +8 -2
  174. package/dist/{materialize-indexes-te9TPMMJ.d.ts → materialize-indexes-zK2J_flP.d.ts} +8 -2
  175. package/dist/{postgres-DQ5R6rzV.d.ts → postgres-IaBA4RgE.d.ts} +1 -1
  176. package/dist/{postgres-CfEqsRMp.d.cts → postgres-YrYmPlaU.d.cts} +1 -1
  177. package/dist/profiler/index.cjs +3 -3
  178. package/dist/profiler/index.d.cts +7 -7
  179. package/dist/profiler/index.d.ts +7 -7
  180. package/dist/profiler/index.js +2 -2
  181. package/dist/provenance/index.cjs +32 -33
  182. package/dist/provenance/index.cjs.map +1 -1
  183. package/dist/provenance/index.d.cts +5 -5
  184. package/dist/provenance/index.d.ts +5 -5
  185. package/dist/provenance/index.js +5 -6
  186. package/dist/provenance/index.js.map +1 -1
  187. package/dist/schema/index.cjs +35 -35
  188. package/dist/schema/index.d.cts +7 -7
  189. package/dist/schema/index.d.ts +7 -7
  190. package/dist/schema/index.js +11 -11
  191. package/dist/{sqlite-DvQndLky.d.ts → sqlite-BUOHPx7p.d.ts} +1 -1
  192. package/dist/{sqlite-D7zBinNR.d.cts → sqlite-Pp8O19WE.d.cts} +1 -1
  193. package/dist/{store-view-CKbHFRnn.d.ts → store-view-ANL6mTph.d.ts} +457 -57
  194. package/dist/{store-view-BSpqvAxK.d.cts → store-view-X96Rd00T.d.cts} +457 -57
  195. package/dist/{types-Bv9DcS_E.d.cts → types-r-Zyq2Hz.d.cts} +2 -2
  196. package/dist/{types-CoxuV7EJ.d.ts → types-wsvuBgPK.d.ts} +2 -2
  197. package/dist/where-CJOpJj3a.d.ts +36 -0
  198. package/dist/where-K3uBP33l.d.cts +36 -0
  199. package/package.json +1 -1
  200. package/dist/chunk-3TWF3SH4.js.map +0 -1
  201. package/dist/chunk-4TOD4LBZ.cjs.map +0 -1
  202. package/dist/chunk-6FR2MMS6.js.map +0 -1
  203. package/dist/chunk-CK5BVQOW.cjs.map +0 -1
  204. package/dist/chunk-CZQ3FO2Q.js.map +0 -1
  205. package/dist/chunk-D7ZEOS56.cjs.map +0 -1
  206. package/dist/chunk-EM3CWPND.cjs.map +0 -1
  207. package/dist/chunk-EMF62TZG.cjs.map +0 -1
  208. package/dist/chunk-EOLERH7Y.cjs +0 -40
  209. package/dist/chunk-EOLERH7Y.cjs.map +0 -1
  210. package/dist/chunk-FN35DLCN.cjs.map +0 -1
  211. package/dist/chunk-FPIZFYHE.js.map +0 -1
  212. package/dist/chunk-GUR2FNB5.cjs +0 -12
  213. package/dist/chunk-H7YNSMA7.cjs.map +0 -1
  214. package/dist/chunk-J7WFGBJR.cjs.map +0 -1
  215. package/dist/chunk-JBTOYDMN.js.map +0 -1
  216. package/dist/chunk-K3PPLHY7.js.map +0 -1
  217. package/dist/chunk-KBGQIPRQ.js.map +0 -1
  218. package/dist/chunk-LGEALRC6.cjs.map +0 -1
  219. package/dist/chunk-MP2JQKSG.js.map +0 -1
  220. package/dist/chunk-O7UN7OXA.cjs.map +0 -1
  221. package/dist/chunk-QNKSQTKQ.js.map +0 -1
  222. package/dist/chunk-QWEUYILR.js.map +0 -1
  223. package/dist/chunk-RGP33ZJ5.js.map +0 -1
  224. package/dist/chunk-S55OV6PW.cjs.map +0 -1
  225. package/dist/chunk-UES55P7G.js.map +0 -1
  226. package/dist/chunk-UT3S4SEN.js +0 -31
  227. package/dist/chunk-UT3S4SEN.js.map +0 -1
  228. package/dist/chunk-VHMPG6UL.js.map +0 -1
  229. package/dist/chunk-VPYHY3LJ.cjs.map +0 -1
  230. package/dist/chunk-WDBCBWC4.js.map +0 -1
  231. package/dist/chunk-WJT7OU7E.cjs.map +0 -1
  232. package/dist/chunk-XOX22WHL.cjs.map +0 -1
  233. package/dist/where-7RKFOsXt.d.ts +0 -11
  234. package/dist/where-DdMIXOtH.d.cts +0 -11
@@ -1,13 +1,14 @@
1
- import { tables } from './chunk-VHMPG6UL.js';
2
- import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-6FR2MMS6.js';
3
- import { formatPostgresTimestamp, coerceNumericScore, nowIso } from './chunk-55MZDDZV.js';
1
+ import { tables } from './chunk-UXLSNRYL.js';
2
+ import { buildPostgresSystemIndexBuilders, buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-QERAIDRJ.js';
3
+ import { formatPostgresTimestamp, coerceNumericScore, nowIso } from './chunk-M6VES7V6.js';
4
4
  import { sortedReplacer } from './chunk-UR7W5YQK.js';
5
+ import { assertNoSystemIndexNameCollision } from './chunk-YTSN73ND.js';
5
6
  import { sha256Hex } from './chunk-W63OVYY4.js';
6
- import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER } from './chunk-FPIZFYHE.js';
7
- import { createBackendOverlay, chunk, isPresent, sqlValueList } from './chunk-JBTOYDMN.js';
8
- import { parseDimensionMismatch, isMissingTableError } from './chunk-I7ZUZKFD.js';
7
+ import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER } from './chunk-EXU3RASM.js';
8
+ import { createBackendOverlay, chunk, asCompiledStatementSql, isPresent, sqlValueList } from './chunk-44TA22QT.js';
9
+ import { parseDimensionMismatch, isMissingTableError } from './chunk-XGPUQ56G.js';
9
10
  import { liveNodeIdsSubquery, quotedTableName, quotedColumn, codePointOrderKey, edgeColumnList, sqlNull, resolveValidFrom, nodeColumnList } from './chunk-OHMP6N2J.js';
10
- import { EmbeddingDimensionChangedError, ConfigurationError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, StoreNotInitializedError, StaleVersionError } from './chunk-MP2JQKSG.js';
11
+ import { EmbeddingDimensionChangedError, ConfigurationError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, TrustedImportError, StaleVersionError, StoreNotInitializedError } from './chunk-5PNMDJ7J.js';
11
12
  import { sql, is, getTableName } from 'drizzle-orm';
12
13
  import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
13
14
  import { getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
@@ -38,6 +39,7 @@ var DEFAULT_TABLE_NAMES = {
38
39
  function createPostgresTables(names = {}, options = {}) {
39
40
  const n = { ...DEFAULT_TABLE_NAMES, ...names };
40
41
  const indexes = options.indexes ?? [];
42
+ assertNoSystemIndexNameCollision(indexes, n);
41
43
  const nodes2 = pgTable(
42
44
  n.nodes,
43
45
  {
@@ -54,15 +56,9 @@ function createPostgresTables(names = {}, options = {}) {
54
56
  },
55
57
  (t) => [
56
58
  primaryKey({ columns: [t.graphId, t.kind, t.id] }),
57
- index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
58
- index(`${n.nodes}_kind_created_idx`).on(
59
- t.graphId,
60
- t.kind,
61
- t.deletedAt,
62
- t.createdAt
63
- ),
64
- index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
65
- index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
59
+ // System indexes come from SYSTEM_INDEX_DECLARATIONS (single source
60
+ // for both dialects + the runtime materializer).
61
+ ...buildPostgresSystemIndexBuilders("nodes", n.nodes, t),
66
62
  ...buildPostgresNodeIndexBuilders(t, indexes)
67
63
  ]
68
64
  );
@@ -85,55 +81,7 @@ function createPostgresTables(names = {}, options = {}) {
85
81
  },
86
82
  (t) => [
87
83
  primaryKey({ columns: [t.graphId, t.id] }),
88
- index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
89
- // Directional traversal index (outgoing): supports endpoint lookups
90
- // and extra filtering by edge kind / target kind. Includes every
91
- // system column the compiled query's soft-delete/temporal-validity
92
- // predicate touches (deleted_at, valid_from, valid_to), trailed by
93
- // to_id — the compiled traversal join reads `n.id = e.to_id` for an
94
- // outgoing traversal (standard-builders.ts), so without to_id here
95
- // the join still fetches the edge's heap row for that one column
96
- // even with the seek/predicate columns covered.
97
- index(`${n.edges}_from_idx`).on(
98
- t.graphId,
99
- t.fromKind,
100
- t.fromId,
101
- t.kind,
102
- t.toKind,
103
- t.deletedAt,
104
- t.validFrom,
105
- t.validTo,
106
- t.toId
107
- ),
108
- // Directional traversal index (incoming): mirrors from_idx for
109
- // reverse traversals, trailed by from_id for the same reason
110
- // (`n.id = e.from_id` for an incoming traversal).
111
- index(`${n.edges}_to_idx`).on(
112
- t.graphId,
113
- t.toKind,
114
- t.toId,
115
- t.kind,
116
- t.fromKind,
117
- t.deletedAt,
118
- t.validFrom,
119
- t.validTo,
120
- t.fromId
121
- ),
122
- index(`${n.edges}_kind_created_idx`).on(
123
- t.graphId,
124
- t.kind,
125
- t.deletedAt,
126
- t.createdAt
127
- ),
128
- index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
129
- index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
130
- index(`${n.edges}_cardinality_idx`).on(
131
- t.graphId,
132
- t.kind,
133
- t.fromKind,
134
- t.fromId,
135
- t.validTo
136
- ),
84
+ ...buildPostgresSystemIndexBuilders("edges", n.edges, t),
137
85
  ...buildPostgresEdgeIndexBuilders(t, indexes)
138
86
  ]
139
87
  );
@@ -160,19 +108,7 @@ function createPostgresTables(names = {}, options = {}) {
160
108
  },
161
109
  (t) => [
162
110
  primaryKey({ columns: [t.historyId] }),
163
- index(`${n.recordedNodes}_entity_idx`).on(
164
- t.graphId,
165
- t.kind,
166
- t.id,
167
- t.recordedFrom,
168
- t.recordedTo
169
- ),
170
- index(`${n.recordedNodes}_open_idx`).on(t.graphId, t.recordedTo),
171
- index(`${n.recordedNodes}_valid_idx`).on(
172
- t.graphId,
173
- t.validFrom,
174
- t.validTo
175
- )
111
+ ...buildPostgresSystemIndexBuilders("recordedNodes", n.recordedNodes, t)
176
112
  ]
177
113
  );
178
114
  const recordedEdges2 = pgTable(
@@ -201,37 +137,7 @@ function createPostgresTables(names = {}, options = {}) {
201
137
  },
202
138
  (t) => [
203
139
  primaryKey({ columns: [t.historyId] }),
204
- index(`${n.recordedEdges}_entity_idx`).on(
205
- t.graphId,
206
- t.kind,
207
- t.id,
208
- t.recordedFrom,
209
- t.recordedTo
210
- ),
211
- index(`${n.recordedEdges}_open_idx`).on(t.graphId, t.recordedTo),
212
- index(`${n.recordedEdges}_from_idx`).on(
213
- t.graphId,
214
- t.fromKind,
215
- t.fromId,
216
- t.kind,
217
- t.toKind,
218
- t.recordedFrom,
219
- t.recordedTo
220
- ),
221
- index(`${n.recordedEdges}_to_idx`).on(
222
- t.graphId,
223
- t.toKind,
224
- t.toId,
225
- t.kind,
226
- t.fromKind,
227
- t.recordedFrom,
228
- t.recordedTo
229
- ),
230
- index(`${n.recordedEdges}_valid_idx`).on(
231
- t.graphId,
232
- t.validFrom,
233
- t.validTo
234
- )
140
+ ...buildPostgresSystemIndexBuilders("recordedEdges", n.recordedEdges, t)
235
141
  ]
236
142
  );
237
143
  const recordedClock2 = pgTable(
@@ -460,9 +366,9 @@ function renderIndexColumn(col) {
460
366
  if (col && typeof col === "object" && "name" in col) {
461
367
  return `"${col.name}"`;
462
368
  }
463
- const sql14 = tryInlineSql(col);
464
- if (sql14 !== void 0) {
465
- return sql14;
369
+ const sql15 = tryInlineSql(col);
370
+ if (sql15 !== void 0) {
371
+ return sql15;
466
372
  }
467
373
  return "unknown";
468
374
  }
@@ -684,39 +590,6 @@ ${ddlSql}`;
684
590
  }
685
591
 
686
592
  // src/backend/drizzle/vector-runtime.ts
687
- function vectorSlotKey(slot) {
688
- return JSON.stringify([
689
- slot.graphId,
690
- slot.nodeKind,
691
- slot.fieldPath,
692
- slot.dimensions,
693
- slot.metric,
694
- slot.indexType
695
- ]);
696
- }
697
- function createVectorSlotLatch() {
698
- const inFlight = /* @__PURE__ */ new Map();
699
- return {
700
- ensure(strategy, slot, execDdl) {
701
- const key = vectorSlotKey(slot);
702
- const existing = inFlight.get(key);
703
- if (existing !== void 0) return existing;
704
- const run = (async () => {
705
- for (const contribution of strategy.ownedTables(slot)) {
706
- for (const statement of contribution.createDdl) {
707
- await execDdl(statement);
708
- }
709
- }
710
- })();
711
- const cached = run.catch((error) => {
712
- inFlight.delete(key);
713
- throw error;
714
- });
715
- inFlight.set(key, cached);
716
- return cached;
717
- }
718
- };
719
- }
720
593
  var VECTOR_SLOT_PLACEHOLDER_DIMENSIONS = 1;
721
594
  var EMBEDDING_UPSERT_PARAM_COUNT = 5;
722
595
  function vectorSlotFromParams(params) {
@@ -807,7 +680,7 @@ function buildContributionOnConflictSet(materializedAtColumn, paramsMaterialized
807
680
  lastError: sql`excluded.${sql.identifier("last_error")}`
808
681
  };
809
682
  }
810
- async function computeContributionSignature(dialect, identity, createDdl) {
683
+ function contributionSignatureInput(dialect, identity, createDdl) {
811
684
  const hashable = {
812
685
  dialect,
813
686
  owner: identity.owner,
@@ -815,7 +688,7 @@ async function computeContributionSignature(dialect, identity, createDdl) {
815
688
  tableName: identity.tableName,
816
689
  createDdl
817
690
  };
818
- return sha256Hex(JSON.stringify(hashable, sortedReplacer), 16);
691
+ return JSON.stringify(hashable, sortedReplacer);
819
692
  }
820
693
  function evaluateContributionState(row, signature) {
821
694
  if (row === void 0) return "missing";
@@ -884,25 +757,64 @@ function gateFulltext(tx, assert) {
884
757
  gateFulltextMethods(tx, assert)
885
758
  );
886
759
  }
760
+ var CONTRIBUTION_KEY_SEPARATOR = String.fromCodePoint(0);
761
+ function contributionKey(graphId, contribution) {
762
+ return [
763
+ graphId,
764
+ contribution.owner,
765
+ contribution.logicalName,
766
+ contribution.tableName
767
+ ].join(CONTRIBUTION_KEY_SEPARATOR);
768
+ }
887
769
  function createContributionMaterializer(deps) {
888
770
  const { dialect, fulltextStrategy, fulltextTableName } = deps;
889
- const initializedGraphIds = /* @__PURE__ */ new Set();
890
- function runtimeContributions() {
891
- return runtimeStrategyContributions(fulltextStrategy, fulltextTableName);
892
- }
893
- async function materializeOne(graphId, contribution) {
894
- const signature = await computeContributionSignature(
771
+ const initializedSignatures = /* @__PURE__ */ new Map();
772
+ const computedSignatures = /* @__PURE__ */ new Map();
773
+ async function resolveContributionSignature(key, contribution) {
774
+ const cached = computedSignatures.get(key);
775
+ const cachedCreateDdl = cached?.createDdl;
776
+ const cachedSignature = cached?.signature;
777
+ if (cachedCreateDdl?.length === contribution.createDdl.length && cachedSignature !== void 0 && contribution.createDdl.every(
778
+ (statement, index2) => cachedCreateDdl[index2] === statement
779
+ )) {
780
+ return cachedSignature;
781
+ }
782
+ const input = contributionSignatureInput(
895
783
  dialect,
896
784
  contribution,
897
785
  contribution.createDdl
898
786
  );
787
+ const entry = {
788
+ createDdl: [...contribution.createDdl],
789
+ signature: sha256Hex(input, 16)
790
+ };
791
+ computedSignatures.set(key, entry);
792
+ try {
793
+ return await entry.signature;
794
+ } catch (error) {
795
+ if (computedSignatures.get(key) === entry) {
796
+ computedSignatures.delete(key);
797
+ }
798
+ throw error;
799
+ }
800
+ }
801
+ function runtimeContributions() {
802
+ return runtimeStrategyContributions(fulltextStrategy, fulltextTableName);
803
+ }
804
+ async function materializeOne(graphId, contribution, signature, existing, options) {
805
+ const force = options?.force === true;
899
806
  const identity = identityOf(graphId, contribution);
900
- const existing = await deps.getMarker(identity);
901
- if (evaluateContributionState(existing, signature) === "initialized") {
902
- return;
807
+ if (!force && evaluateContributionState(existing, signature) === "initialized") {
808
+ return "materialized";
903
809
  }
904
810
  const priorSuccess = existing?.materializedAt !== void 0;
905
- if (priorSuccess && existing.signature !== signature) {
811
+ if (!force && priorSuccess && existing.signature !== signature) {
812
+ if (options?.onDrift === "skip") {
813
+ console.warn(
814
+ `[typegraph] contribution "${contribution.logicalName}" (table "${contribution.tableName}") is provisioned at a different shape than the current declaration \u2014 left untouched. Writes to it will fail until store.reembedVectorField(kind, fieldPath) recreates the storage at the new shape.`
815
+ );
816
+ return "drift-skipped";
817
+ }
906
818
  const error = new Error(
907
819
  `Contribution "${contribution.logicalName}" (owner "${contribution.owner}", table "${contribution.tableName}") was already materialized with a different signature. The recorded physical shape is stale relative to the current strategy/DDL \u2014 migrate or drop the table and retry, or restore the original strategy.`
908
820
  );
@@ -937,64 +849,159 @@ function createContributionMaterializer(deps) {
937
849
  materializedAt: attemptedAt,
938
850
  error: void 0
939
851
  });
852
+ return "materialized";
940
853
  }
941
- async function readContributionState(graphId, contribution) {
942
- const signature = await computeContributionSignature(
943
- dialect,
944
- contribution,
945
- contribution.createDdl
854
+ function indexMarkerRows(graphId, rows) {
855
+ return new Map(
856
+ rows.map((row) => [contributionKey(graphId, row), row])
946
857
  );
947
- const identity = identityOf(graphId, contribution);
858
+ }
859
+ async function readMarkerRows(graphId) {
948
860
  try {
949
- const existing = await deps.getMarker(identity);
950
861
  return {
951
- kind: "state",
952
- state: evaluateContributionState(existing, signature)
862
+ kind: "rows",
863
+ rows: indexMarkerRows(graphId, await deps.getMarkers(graphId))
953
864
  };
954
865
  } catch (error) {
955
866
  if (!isMissingTableError(error)) throw error;
956
867
  return { kind: "missing-table", error };
957
868
  }
958
869
  }
959
- async function allContributionsInitialized(graphId, contributions) {
960
- for (const contribution of contributions) {
961
- const read = await readContributionState(graphId, contribution);
962
- if (read.kind !== "state" || read.state !== "initialized") return false;
963
- }
964
- return true;
965
- }
966
- async function ensureRuntimeContributions(graphId) {
967
- if (initializedGraphIds.has(graphId)) return;
968
- const contributions = runtimeContributions();
969
- if (await allContributionsInitialized(graphId, contributions)) {
970
- initializedGraphIds.add(graphId);
870
+ async function ensureContributions(graphId, contributions, options) {
871
+ const force = options?.force === true;
872
+ const entries = await Promise.all(
873
+ contributions.map(async (contribution) => {
874
+ const key = contributionKey(graphId, contribution);
875
+ return {
876
+ contribution,
877
+ key,
878
+ signature: await resolveContributionSignature(key, contribution)
879
+ };
880
+ })
881
+ );
882
+ const pending = force ? entries : entries.filter(
883
+ (entry) => initializedSignatures.get(entry.key) !== entry.signature
884
+ );
885
+ if (pending.length === 0) return;
886
+ const initialRead = force ? void 0 : await readMarkerRows(graphId);
887
+ if (!force && initialRead?.kind === "rows" && pending.every(
888
+ (entry) => evaluateContributionState(
889
+ initialRead.rows.get(entry.key),
890
+ entry.signature
891
+ ) === "initialized"
892
+ )) {
893
+ for (const entry of pending) {
894
+ initializedSignatures.set(entry.key, entry.signature);
895
+ }
971
896
  return;
972
897
  }
973
898
  await deps.ensureMarkerTable();
974
- for (const contribution of contributions) {
975
- await materializeOne(graphId, contribution);
899
+ const existingRows = indexMarkerRows(
900
+ graphId,
901
+ await deps.getMarkers(graphId)
902
+ );
903
+ for (const entry of pending) {
904
+ const outcome = await materializeOne(
905
+ graphId,
906
+ entry.contribution,
907
+ entry.signature,
908
+ existingRows.get(entry.key),
909
+ {
910
+ force,
911
+ ...options?.onDrift === void 0 ? {} : { onDrift: options.onDrift }
912
+ }
913
+ );
914
+ if (outcome === "materialized") {
915
+ initializedSignatures.set(entry.key, entry.signature);
916
+ }
976
917
  }
977
- initializedGraphIds.add(graphId);
978
918
  }
979
- async function assertInitialized(graphId) {
980
- if (initializedGraphIds.has(graphId)) return;
981
- for (const contribution of runtimeContributions()) {
982
- const read = await readContributionState(graphId, contribution);
983
- if (read.kind === "missing-table") {
984
- throw new StoreNotInitializedError(graphId, "missing", {
985
- cause: read.error,
986
- details: { logicalName: contribution.logicalName }
987
- });
988
- }
989
- if (read.state !== "initialized") {
990
- throw new StoreNotInitializedError(graphId, read.state, {
919
+ async function assertContributions(graphId, contributions) {
920
+ const entries = await Promise.all(
921
+ contributions.map(async (contribution) => {
922
+ const key = contributionKey(graphId, contribution);
923
+ return {
924
+ contribution,
925
+ key,
926
+ signature: await resolveContributionSignature(key, contribution)
927
+ };
928
+ })
929
+ );
930
+ const pending = entries.filter(
931
+ (entry) => initializedSignatures.get(entry.key) !== entry.signature
932
+ );
933
+ if (pending.length === 0) return;
934
+ const read = await readMarkerRows(graphId);
935
+ if (read.kind === "missing-table") {
936
+ const first = pending[0];
937
+ if (first === void 0) return;
938
+ throw new StoreNotInitializedError(graphId, "missing", {
939
+ cause: read.error,
940
+ details: { logicalName: first.contribution.logicalName }
941
+ });
942
+ }
943
+ for (const entry of pending) {
944
+ const { contribution, key, signature } = entry;
945
+ const state = evaluateContributionState(read.rows.get(key), signature);
946
+ if (state !== "initialized") {
947
+ throw new StoreNotInitializedError(graphId, state, {
991
948
  details: { logicalName: contribution.logicalName }
992
949
  });
993
950
  }
951
+ initializedSignatures.set(key, signature);
994
952
  }
995
- initializedGraphIds.add(graphId);
996
953
  }
997
- return { ensureRuntimeContributions, assertInitialized };
954
+ async function ensureRuntimeContributions(graphId) {
955
+ await ensureContributions(graphId, runtimeContributions());
956
+ }
957
+ async function assertInitialized(graphId) {
958
+ await assertContributions(graphId, runtimeContributions());
959
+ }
960
+ async function ensureVectorSlot(slot, options) {
961
+ await ensureVectorSlots([slot], options);
962
+ }
963
+ async function assertVectorSlot(slot) {
964
+ await assertVectorSlots([slot]);
965
+ }
966
+ function groupVectorContributions(slots) {
967
+ const grouped = /* @__PURE__ */ new Map();
968
+ if (deps.vectorStrategy === void 0) return grouped;
969
+ for (const slot of slots) {
970
+ grouped.set(slot.graphId, [
971
+ ...grouped.get(slot.graphId) ?? [],
972
+ ...deps.vectorStrategy.ownedTables(slot)
973
+ ]);
974
+ }
975
+ return grouped;
976
+ }
977
+ async function ensureVectorSlots(slots, options) {
978
+ for (const [graphId, contributions] of groupVectorContributions(slots)) {
979
+ await ensureContributions(graphId, contributions, options);
980
+ }
981
+ }
982
+ async function assertVectorSlots(slots) {
983
+ for (const [graphId, contributions] of groupVectorContributions(slots)) {
984
+ await assertContributions(graphId, contributions);
985
+ }
986
+ }
987
+ async function dropVectorSlot(slot) {
988
+ if (deps.vectorStrategy === void 0) return;
989
+ for (const contribution of deps.vectorStrategy.ownedTables(slot)) {
990
+ await deps.deleteMarker(identityOf(slot.graphId, contribution));
991
+ const key = contributionKey(slot.graphId, contribution);
992
+ initializedSignatures.delete(key);
993
+ computedSignatures.delete(key);
994
+ }
995
+ }
996
+ return {
997
+ ensureRuntimeContributions,
998
+ assertInitialized,
999
+ ensureVectorSlot,
1000
+ ensureVectorSlots,
1001
+ assertVectorSlot,
1002
+ assertVectorSlots,
1003
+ dropVectorSlot
1004
+ };
998
1005
  }
999
1006
  var SQLITE_INDEX_MAT_TIMESTAMPS = {
1000
1007
  decode: (value) => typeof value === "string" ? value : void 0,
@@ -1036,15 +1043,20 @@ function buildMaterializationInsertValues(params, encode) {
1036
1043
  lastError: params.error
1037
1044
  };
1038
1045
  }
1039
- function buildMaterializationOnConflictSet(materializedAtColumn, paramsMaterializedAt) {
1040
- const materializedAtSet = paramsMaterializedAt === void 0 ? sql`COALESCE(excluded.${sql.identifier("materialized_at")}, ${materializedAtColumn})` : sql`excluded.${sql.identifier("materialized_at")}`;
1046
+ function buildMaterializationOnConflictSet(paramsMaterializedAt) {
1047
+ if (paramsMaterializedAt === void 0) {
1048
+ return {
1049
+ lastAttemptedAt: sql`excluded.${sql.identifier("last_attempted_at")}`,
1050
+ lastError: sql`excluded.${sql.identifier("last_error")}`
1051
+ };
1052
+ }
1041
1053
  return {
1042
1054
  graphId: sql`excluded.${sql.identifier("graph_id")}`,
1043
1055
  entity: sql`excluded.${sql.identifier("entity")}`,
1044
1056
  kind: sql`excluded.${sql.identifier("kind")}`,
1045
1057
  signature: sql`excluded.${sql.identifier("signature")}`,
1046
1058
  schemaVersion: sql`excluded.${sql.identifier("schema_version")}`,
1047
- materializedAt: materializedAtSet,
1059
+ materializedAt: sql`excluded.${sql.identifier("materialized_at")}`,
1048
1060
  lastAttemptedAt: sql`excluded.${sql.identifier("last_attempted_at")}`,
1049
1061
  lastError: sql`excluded.${sql.identifier("last_error")}`
1050
1062
  };
@@ -2231,16 +2243,26 @@ function createCommonOperationBackend(options) {
2231
2243
  async executeStatement(query) {
2232
2244
  await execution.execRun(query);
2233
2245
  },
2246
+ async executeTemporaryStatement(query) {
2247
+ await execution.execRun(query);
2248
+ },
2234
2249
  async insertNode(params) {
2235
2250
  const timestamp2 = nowIso2();
2236
2251
  const query = operationStrategy.buildInsertNode(params, timestamp2);
2237
2252
  const row = await execution.execGet(query);
2238
- if (!row) throw new DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
2253
+ if (!row)
2254
+ throw new DatabaseOperationError(
2255
+ "Insert node failed: no row returned",
2256
+ { operation: "insert", entity: "node" }
2257
+ );
2239
2258
  return rowMappers.toNodeRow(row);
2240
2259
  },
2241
2260
  async insertNodeNoReturn(params) {
2242
2261
  const timestamp2 = nowIso2();
2243
- const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
2262
+ const query = operationStrategy.buildInsertNodeNoReturn(
2263
+ params,
2264
+ timestamp2
2265
+ );
2244
2266
  await execution.execRun(query);
2245
2267
  },
2246
2268
  async insertNodesBatch(params) {
@@ -2260,7 +2282,10 @@ function createCommonOperationBackend(options) {
2260
2282
  const timestamp2 = nowIso2();
2261
2283
  const allRows = [];
2262
2284
  for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
2263
- const query = operationStrategy.buildInsertNodesBatchReturning(chunk2, timestamp2);
2285
+ const query = operationStrategy.buildInsertNodesBatchReturning(
2286
+ chunk2,
2287
+ timestamp2
2288
+ );
2264
2289
  const rows = await execution.execAll(query);
2265
2290
  allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
2266
2291
  }
@@ -2285,7 +2310,11 @@ function createCommonOperationBackend(options) {
2285
2310
  const timestamp2 = nowIso2();
2286
2311
  const query = operationStrategy.buildUpdateNode(params, timestamp2);
2287
2312
  const row = await execution.execGet(query);
2288
- if (!row) throw new DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
2313
+ if (!row)
2314
+ throw new DatabaseOperationError(
2315
+ "Update node failed: no row returned",
2316
+ { operation: "update", entity: "node" }
2317
+ );
2289
2318
  return rowMappers.toNodeRow(row);
2290
2319
  },
2291
2320
  async deleteNode(params) {
@@ -2329,12 +2358,19 @@ function createCommonOperationBackend(options) {
2329
2358
  const timestamp2 = nowIso2();
2330
2359
  const query = operationStrategy.buildInsertEdge(params, timestamp2);
2331
2360
  const row = await execution.execGet(query);
2332
- if (!row) throw new DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
2361
+ if (!row)
2362
+ throw new DatabaseOperationError(
2363
+ "Insert edge failed: no row returned",
2364
+ { operation: "insert", entity: "edge" }
2365
+ );
2333
2366
  return rowMappers.toEdgeRow(row);
2334
2367
  },
2335
2368
  async insertEdgeNoReturn(params) {
2336
2369
  const timestamp2 = nowIso2();
2337
- const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
2370
+ const query = operationStrategy.buildInsertEdgeNoReturn(
2371
+ params,
2372
+ timestamp2
2373
+ );
2338
2374
  await execution.execRun(query);
2339
2375
  },
2340
2376
  async insertEdgesBatch(params) {
@@ -2354,7 +2390,10 @@ function createCommonOperationBackend(options) {
2354
2390
  const timestamp2 = nowIso2();
2355
2391
  const allRows = [];
2356
2392
  for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
2357
- const query = operationStrategy.buildInsertEdgesBatchReturning(chunk2, timestamp2);
2393
+ const query = operationStrategy.buildInsertEdgesBatchReturning(
2394
+ chunk2,
2395
+ timestamp2
2396
+ );
2358
2397
  const rows = await execution.execAll(query);
2359
2398
  allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
2360
2399
  }
@@ -2379,7 +2418,11 @@ function createCommonOperationBackend(options) {
2379
2418
  const timestamp2 = nowIso2();
2380
2419
  const query = operationStrategy.buildUpdateEdge(params, timestamp2);
2381
2420
  const row = await execution.execGet(query);
2382
- if (!row) throw new DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
2421
+ if (!row)
2422
+ throw new DatabaseOperationError(
2423
+ "Update edge failed: no row returned",
2424
+ { operation: "update", entity: "edge" }
2425
+ );
2383
2426
  return rowMappers.toEdgeRow(row);
2384
2427
  },
2385
2428
  async deleteEdge(params) {
@@ -2394,7 +2437,10 @@ function createCommonOperationBackend(options) {
2394
2437
  async deleteEdgesBatch(params) {
2395
2438
  if (params.ids.length === 0) return;
2396
2439
  const timestamp2 = nowIso2();
2397
- const softDeleteChunkSize = Math.max(1, batchConfig.getEdgesChunkSize - 1);
2440
+ const softDeleteChunkSize = Math.max(
2441
+ 1,
2442
+ batchConfig.getEdgesChunkSize - 1
2443
+ );
2398
2444
  for (const chunk2 of chunk(params.ids, softDeleteChunkSize)) {
2399
2445
  const query = operationStrategy.buildDeleteEdgesBatch(
2400
2446
  { graphId: params.graphId, ids: chunk2 },
@@ -2405,7 +2451,10 @@ function createCommonOperationBackend(options) {
2405
2451
  },
2406
2452
  async hardDeleteEdgesBatch(params) {
2407
2453
  if (params.ids.length === 0) return;
2408
- for (const chunk2 of chunk(params.ids, batchConfig.getEdgesChunkSize)) {
2454
+ for (const chunk2 of chunk(
2455
+ params.ids,
2456
+ batchConfig.getEdgesChunkSize
2457
+ )) {
2409
2458
  const query = operationStrategy.buildHardDeleteEdgesBatch({
2410
2459
  graphId: params.graphId,
2411
2460
  ids: chunk2
@@ -2521,8 +2570,14 @@ function createCommonOperationBackend(options) {
2521
2570
  async checkUniqueBatch(params) {
2522
2571
  if (params.keys.length === 0) return [];
2523
2572
  const allRows = [];
2524
- for (const chunk2 of chunk(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
2525
- const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk2 });
2573
+ for (const chunk2 of chunk(
2574
+ params.keys,
2575
+ batchConfig.checkUniqueBatchChunkSize
2576
+ )) {
2577
+ const query = operationStrategy.buildCheckUniqueBatch({
2578
+ ...params,
2579
+ keys: chunk2
2580
+ });
2526
2581
  const rows = await execution.execAll(query);
2527
2582
  allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
2528
2583
  }
@@ -2540,10 +2595,7 @@ function createCommonOperationBackend(options) {
2540
2595
  },
2541
2596
  async commitSchemaVersion(params) {
2542
2597
  const existingRaw = await execution.execGet(
2543
- operationStrategy.buildGetSchemaVersion(
2544
- params.graphId,
2545
- params.version
2546
- )
2598
+ operationStrategy.buildGetSchemaVersion(params.graphId, params.version)
2547
2599
  );
2548
2600
  const actualActiveVersion = await readActiveVersion(params.graphId);
2549
2601
  if (existingRaw !== void 0) {
@@ -2612,10 +2664,7 @@ function createCommonOperationBackend(options) {
2612
2664
  actualActiveVersion
2613
2665
  );
2614
2666
  const targetRaw = await execution.execGet(
2615
- operationStrategy.buildGetSchemaVersion(
2616
- params.graphId,
2617
- params.version
2618
- )
2667
+ operationStrategy.buildGetSchemaVersion(params.graphId, params.version)
2619
2668
  );
2620
2669
  if (!targetRaw) {
2621
2670
  throw new MigrationError(
@@ -2642,6 +2691,256 @@ function createCommonOperationBackend(options) {
2642
2691
  }
2643
2692
  };
2644
2693
  }
2694
+ var DATABASE_NULL = null;
2695
+ function quoteSqlIdentifier(identifier) {
2696
+ return `"${identifier.replaceAll('"', '""')}"`;
2697
+ }
2698
+ function requireRawExecution(backend) {
2699
+ if (backend.executeRaw === void 0) {
2700
+ throw new TrustedImportError(
2701
+ "This backend cannot execute the raw statements required by trusted import.",
2702
+ "backend_unsupported"
2703
+ );
2704
+ }
2705
+ return backend.executeRaw;
2706
+ }
2707
+ function requireStatementExecution(backend) {
2708
+ if (backend.executeStatement === void 0) {
2709
+ throw new TrustedImportError(
2710
+ "This backend cannot execute the index lifecycle required by trusted import.",
2711
+ "backend_unsupported"
2712
+ );
2713
+ }
2714
+ return backend.executeStatement;
2715
+ }
2716
+ function rowIndicatesExistingData(row) {
2717
+ if (typeof row !== "object" || row === null) return false;
2718
+ const value = row.has_rows;
2719
+ return value === true || value === 1 || value === "1";
2720
+ }
2721
+ async function assertTrustedImportDatabaseEmpty(backend, tableNames) {
2722
+ const executeRaw = requireRawExecution(backend);
2723
+ const rows = await executeRaw(
2724
+ `SELECT (
2725
+ EXISTS (SELECT 1 FROM ${quoteSqlIdentifier(tableNames.nodes)} LIMIT 1)
2726
+ OR EXISTS (SELECT 1 FROM ${quoteSqlIdentifier(tableNames.edges)} LIMIT 1)
2727
+ ) AS has_rows`,
2728
+ []
2729
+ );
2730
+ if (!rowIndicatesExistingData(rows[0])) return;
2731
+ throw new TrustedImportError(
2732
+ "Trusted import requires globally empty TypeGraph node and edge tables.",
2733
+ "database_not_empty",
2734
+ { tables: [tableNames.nodes, tableNames.edges] },
2735
+ {
2736
+ suggestion: "Run trusted import only against a fresh, dedicated database. Use importGraph or the collection bulk APIs to add data to an existing database."
2737
+ }
2738
+ );
2739
+ }
2740
+ async function lockPostgresTrustedImportTables(backend, tableNames) {
2741
+ const executeStatement = requireStatementExecution(backend);
2742
+ await executeStatement(
2743
+ asCompiledStatementSql(
2744
+ sql.raw(
2745
+ `LOCK TABLE ${quoteSqlIdentifier(tableNames.nodes)}, ${quoteSqlIdentifier(tableNames.edges)} IN ACCESS EXCLUSIVE MODE`
2746
+ )
2747
+ )
2748
+ );
2749
+ }
2750
+ async function suspendSqliteSecondaryIndexes(backend, tableNames) {
2751
+ const executeRaw = requireRawExecution(backend);
2752
+ const executeStatement = requireStatementExecution(backend);
2753
+ const definitions = await executeRaw(
2754
+ `SELECT name AS index_name, sql AS index_definition
2755
+ FROM sqlite_schema
2756
+ WHERE type = 'index'
2757
+ AND tbl_name IN (?, ?)
2758
+ AND sql IS NOT NULL
2759
+ ORDER BY name`,
2760
+ [tableNames.nodes, tableNames.edges]
2761
+ );
2762
+ for (const definition of definitions) {
2763
+ await executeStatement(
2764
+ asCompiledStatementSql(
2765
+ sql.raw(`DROP INDEX ${quoteSqlIdentifier(definition.index_name)}`)
2766
+ )
2767
+ );
2768
+ }
2769
+ return definitions;
2770
+ }
2771
+ async function suspendPostgresSecondaryIndexes(backend, tableNames) {
2772
+ const executeRaw = requireRawExecution(backend);
2773
+ const executeStatement = requireStatementExecution(backend);
2774
+ const definitions = await executeRaw(
2775
+ `SELECT index_class.relname AS index_name,
2776
+ pg_get_indexdef(index_class.oid) AS index_definition
2777
+ FROM pg_class AS table_class
2778
+ JOIN pg_namespace AS namespace
2779
+ ON namespace.oid = table_class.relnamespace
2780
+ JOIN pg_index AS index_metadata
2781
+ ON index_metadata.indrelid = table_class.oid
2782
+ JOIN pg_class AS index_class
2783
+ ON index_class.oid = index_metadata.indexrelid
2784
+ LEFT JOIN pg_constraint AS table_constraint
2785
+ ON table_constraint.conindid = index_class.oid
2786
+ WHERE namespace.nspname = current_schema()
2787
+ AND table_class.relname IN ($1, $2)
2788
+ AND table_constraint.oid IS NULL
2789
+ AND NOT index_metadata.indisprimary
2790
+ ORDER BY index_class.relname`,
2791
+ [tableNames.nodes, tableNames.edges]
2792
+ );
2793
+ for (const definition of definitions) {
2794
+ await executeStatement(
2795
+ asCompiledStatementSql(
2796
+ sql.raw(`DROP INDEX ${quoteSqlIdentifier(definition.index_name)}`)
2797
+ )
2798
+ );
2799
+ }
2800
+ return definitions;
2801
+ }
2802
+ async function restoreSecondaryIndexes(backend, definitions) {
2803
+ const executeStatement = requireStatementExecution(backend);
2804
+ for (const definition of definitions) {
2805
+ await executeStatement(
2806
+ asCompiledStatementSql(sql.raw(definition.index_definition))
2807
+ );
2808
+ }
2809
+ }
2810
+ async function analyzeImportedTables(backend, tableNames) {
2811
+ const executeStatement = requireStatementExecution(backend);
2812
+ await executeStatement(
2813
+ asCompiledStatementSql(
2814
+ sql.raw(`ANALYZE ${quoteSqlIdentifier(tableNames.nodes)}`)
2815
+ )
2816
+ );
2817
+ await executeStatement(
2818
+ asCompiledStatementSql(
2819
+ sql.raw(`ANALYZE ${quoteSqlIdentifier(tableNames.edges)}`)
2820
+ )
2821
+ );
2822
+ }
2823
+ function resolvedValidFrom(validFrom, timestamp2) {
2824
+ return validFrom === void 0 ? timestamp2 : validFrom;
2825
+ }
2826
+ function postgresArray(values) {
2827
+ return `{${values.map(
2828
+ (value) => value === DATABASE_NULL ? "NULL" : `"${value.replaceAll("\\", "\\\\").replaceAll('"', String.raw`\"`)}"`
2829
+ ).join(",")}}`;
2830
+ }
2831
+ function createSqliteTrustedImportSession(executionAdapter, tableNames) {
2832
+ const executePreparedRunBatch = executionAdapter.executePreparedRunBatch;
2833
+ if (executePreparedRunBatch === void 0) {
2834
+ throw new TrustedImportError(
2835
+ "Trusted import requires a synchronous SQLite driver with prepared statement support.",
2836
+ "backend_unsupported"
2837
+ );
2838
+ }
2839
+ const nodeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.nodes)}
2840
+ (graph_id, kind, id, props, version, valid_from, valid_to, created_at, updated_at)
2841
+ VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?)`;
2842
+ const edgeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.edges)}
2843
+ (graph_id, id, kind, from_kind, from_id, to_kind, to_id, props, valid_from, valid_to, created_at, updated_at)
2844
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
2845
+ return {
2846
+ async insertNodes(params) {
2847
+ if (params.length === 0) return;
2848
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
2849
+ await executePreparedRunBatch(
2850
+ nodeSql,
2851
+ params.map((item) => [
2852
+ item.graphId,
2853
+ item.kind,
2854
+ item.id,
2855
+ JSON.stringify(item.props),
2856
+ resolvedValidFrom(item.validFrom, timestamp2),
2857
+ item.validTo ?? DATABASE_NULL,
2858
+ timestamp2,
2859
+ timestamp2
2860
+ ])
2861
+ );
2862
+ },
2863
+ async insertEdges(params) {
2864
+ if (params.length === 0) return;
2865
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
2866
+ await executePreparedRunBatch(
2867
+ edgeSql,
2868
+ params.map((item) => [
2869
+ item.graphId,
2870
+ item.id,
2871
+ item.kind,
2872
+ item.fromKind,
2873
+ item.fromId,
2874
+ item.toKind,
2875
+ item.toId,
2876
+ JSON.stringify(item.props),
2877
+ resolvedValidFrom(item.validFrom, timestamp2),
2878
+ item.validTo ?? DATABASE_NULL,
2879
+ timestamp2,
2880
+ timestamp2
2881
+ ])
2882
+ );
2883
+ }
2884
+ };
2885
+ }
2886
+ function createPostgresTrustedImportSession(backend, tableNames) {
2887
+ const executeRaw = requireRawExecution(backend);
2888
+ const nodeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.nodes)}
2889
+ (graph_id, kind, id, props, version, valid_from, valid_to, created_at, updated_at)
2890
+ SELECT graph_id, kind, id, props::jsonb, 1, valid_from, valid_to, created_at, created_at
2891
+ FROM UNNEST(
2892
+ $1::text[], $2::text[], $3::text[], $4::text[],
2893
+ $5::timestamptz[], $6::timestamptz[], $7::timestamptz[]
2894
+ ) AS imported(graph_id, kind, id, props, valid_from, valid_to, created_at)`;
2895
+ const edgeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.edges)}
2896
+ (graph_id, id, kind, from_kind, from_id, to_kind, to_id, props, valid_from, valid_to, created_at, updated_at)
2897
+ SELECT graph_id, id, kind, from_kind, from_id, to_kind, to_id, props::jsonb,
2898
+ valid_from, valid_to, created_at, created_at
2899
+ FROM UNNEST(
2900
+ $1::text[], $2::text[], $3::text[], $4::text[], $5::text[],
2901
+ $6::text[], $7::text[], $8::text[], $9::timestamptz[],
2902
+ $10::timestamptz[], $11::timestamptz[]
2903
+ ) AS imported(
2904
+ graph_id, id, kind, from_kind, from_id, to_kind, to_id, props,
2905
+ valid_from, valid_to, created_at
2906
+ )`;
2907
+ return {
2908
+ async insertNodes(params) {
2909
+ if (params.length === 0) return;
2910
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
2911
+ await executeRaw(nodeSql, [
2912
+ postgresArray(params.map((item) => item.graphId)),
2913
+ postgresArray(params.map((item) => item.kind)),
2914
+ postgresArray(params.map((item) => item.id)),
2915
+ postgresArray(params.map((item) => JSON.stringify(item.props))),
2916
+ postgresArray(
2917
+ params.map((item) => resolvedValidFrom(item.validFrom, timestamp2))
2918
+ ),
2919
+ postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
2920
+ postgresArray(params.map(() => timestamp2))
2921
+ ]);
2922
+ },
2923
+ async insertEdges(params) {
2924
+ if (params.length === 0) return;
2925
+ const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
2926
+ await executeRaw(edgeSql, [
2927
+ postgresArray(params.map((item) => item.graphId)),
2928
+ postgresArray(params.map((item) => item.id)),
2929
+ postgresArray(params.map((item) => item.kind)),
2930
+ postgresArray(params.map((item) => item.fromKind)),
2931
+ postgresArray(params.map((item) => item.fromId)),
2932
+ postgresArray(params.map((item) => item.toKind)),
2933
+ postgresArray(params.map((item) => item.toId)),
2934
+ postgresArray(params.map((item) => JSON.stringify(item.props))),
2935
+ postgresArray(
2936
+ params.map((item) => resolvedValidFrom(item.validFrom, timestamp2))
2937
+ ),
2938
+ postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
2939
+ postgresArray(params.map(() => timestamp2))
2940
+ ]);
2941
+ }
2942
+ };
2943
+ }
2645
2944
 
2646
2945
  // src/backend/drizzle/execution/lru.ts
2647
2946
  function getOrCreateLru(cache, key, cacheMax, create) {
@@ -2670,6 +2969,6 @@ function compileQueryWithDialect(db, query, backendName) {
2670
2969
  return compiler.sqlToQuery(query);
2671
2970
  }
2672
2971
 
2673
- export { EMBEDDING_UPSERT_PARAM_COUNT, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, assertAdoptedDialect, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildMaterializationInsertValues, buildMaterializationOnConflictSet, compileQueryWithDialect, createCachedTableExistence, createCommonOperationBackend, createContributionMaterializer, createPostgresOperationStrategy, createPostgresTables, createSqliteOperationStrategy, createVectorSlotLatch, edges, fulltext, gateFulltext, gateFulltextMethods, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, getOrCreateLru, hybridCandidatesRef, mapContributionMaterializationRow, mapHybridSearchRow, mapKindRemovalRow, mapMaterializationRow, mapVectorWriteError, nodes, recordedClock, recordedEdges, recordedNodes, schemaVersions, tables2 as tables, uniques, vectorSlotFromCreateIndexParams, vectorSlotFromDropIndexParams, vectorSlotFromParams };
2674
- //# sourceMappingURL=chunk-WDBCBWC4.js.map
2675
- //# sourceMappingURL=chunk-WDBCBWC4.js.map
2972
+ export { EMBEDDING_UPSERT_PARAM_COUNT, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, analyzeImportedTables, assertAdoptedDialect, assertTrustedImportDatabaseEmpty, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildMaterializationInsertValues, buildMaterializationOnConflictSet, compileQueryWithDialect, createCachedTableExistence, createCommonOperationBackend, createContributionMaterializer, createPostgresOperationStrategy, createPostgresTables, createPostgresTrustedImportSession, createSqliteOperationStrategy, createSqliteTrustedImportSession, edges, fulltext, gateFulltext, gateFulltextMethods, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, getOrCreateLru, hybridCandidatesRef, lockPostgresTrustedImportTables, mapContributionMaterializationRow, mapHybridSearchRow, mapKindRemovalRow, mapMaterializationRow, mapVectorWriteError, nodes, recordedClock, recordedEdges, recordedNodes, restoreSecondaryIndexes, schemaVersions, suspendPostgresSecondaryIndexes, suspendSqliteSecondaryIndexes, tables2 as tables, uniques, vectorSlotFromCreateIndexParams, vectorSlotFromDropIndexParams, vectorSlotFromParams };
2973
+ //# sourceMappingURL=chunk-K3Q3LJY3.js.map
2974
+ //# sourceMappingURL=chunk-K3Q3LJY3.js.map