@nicia-ai/typegraph 0.39.0 → 0.41.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 (255) hide show
  1. package/dist/backend/drizzle/indexes.cjs +8 -10
  2. package/dist/backend/drizzle/indexes.d.cts +2 -2
  3. package/dist/backend/drizzle/indexes.d.ts +2 -2
  4. package/dist/backend/drizzle/indexes.js +4 -6
  5. package/dist/backend/index.cjs +60 -39
  6. package/dist/backend/index.d.cts +60 -1
  7. package/dist/backend/index.d.ts +60 -1
  8. package/dist/backend/index.js +12 -3
  9. package/dist/backend/postgres/index.cjs +24 -26
  10. package/dist/backend/postgres/index.d.cts +6 -6
  11. package/dist/backend/postgres/index.d.ts +6 -6
  12. package/dist/backend/postgres/index.js +11 -13
  13. package/dist/backend/postgres/pglite-store.cjs +25 -26
  14. package/dist/backend/postgres/pglite-store.cjs.map +1 -1
  15. package/dist/backend/postgres/pglite-store.d.cts +6 -5
  16. package/dist/backend/postgres/pglite-store.d.ts +6 -5
  17. package/dist/backend/postgres/pglite-store.js +21 -22
  18. package/dist/backend/postgres/pglite-store.js.map +1 -1
  19. package/dist/backend/postgres/pglite.cjs +13 -15
  20. package/dist/backend/postgres/pglite.d.cts +3 -3
  21. package/dist/backend/postgres/pglite.d.ts +3 -3
  22. package/dist/backend/postgres/pglite.js +12 -14
  23. package/dist/backend/sqlite/index.cjs +25 -27
  24. package/dist/backend/sqlite/index.d.cts +6 -6
  25. package/dist/backend/sqlite/index.d.ts +6 -6
  26. package/dist/backend/sqlite/index.js +9 -11
  27. package/dist/backend/sqlite/libsql.cjs +15 -17
  28. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  29. package/dist/backend/sqlite/libsql.d.cts +3 -3
  30. package/dist/backend/sqlite/libsql.d.ts +3 -3
  31. package/dist/backend/sqlite/libsql.js +14 -16
  32. package/dist/backend/sqlite/libsql.js.map +1 -1
  33. package/dist/backend/sqlite/local-store.cjs +26 -27
  34. package/dist/backend/sqlite/local-store.cjs.map +1 -1
  35. package/dist/backend/sqlite/local-store.d.cts +6 -5
  36. package/dist/backend/sqlite/local-store.d.ts +6 -5
  37. package/dist/backend/sqlite/local-store.js +22 -23
  38. package/dist/backend/sqlite/local-store.js.map +1 -1
  39. package/dist/backend/sqlite/local.cjs +14 -16
  40. package/dist/backend/sqlite/local.d.cts +3 -3
  41. package/dist/backend/sqlite/local.d.ts +3 -3
  42. package/dist/backend/sqlite/local.js +12 -14
  43. package/dist/{chunk-U4JDJKPD.js → chunk-2I3DNNBU.js} +4 -4
  44. package/dist/{chunk-U4JDJKPD.js.map → chunk-2I3DNNBU.js.map} +1 -1
  45. package/dist/{chunk-NPWACFQJ.cjs → chunk-2J5NMMVR.cjs} +43 -43
  46. package/dist/{chunk-NPWACFQJ.cjs.map → chunk-2J5NMMVR.cjs.map} +1 -1
  47. package/dist/{chunk-3YFDFOYB.cjs → chunk-2X73QTIC.cjs} +12 -13
  48. package/dist/chunk-2X73QTIC.cjs.map +1 -0
  49. package/dist/chunk-3SHAUJRB.js +79 -0
  50. package/dist/chunk-3SHAUJRB.js.map +1 -0
  51. package/dist/{chunk-3SK4SVTW.js → chunk-53BSOG3O.js} +8 -7
  52. package/dist/chunk-53BSOG3O.js.map +1 -0
  53. package/dist/chunk-5J4VNCUD.js +856 -0
  54. package/dist/chunk-5J4VNCUD.js.map +1 -0
  55. package/dist/chunk-5YBDB7UG.cjs +12 -0
  56. package/dist/{chunk-FMNUSGZ4.cjs.map → chunk-5YBDB7UG.cjs.map} +1 -1
  57. package/dist/{chunk-6XDBRDZE.js → chunk-6N7QBIWN.js} +7 -3
  58. package/dist/chunk-6N7QBIWN.js.map +1 -0
  59. package/dist/{chunk-EZH7FNUS.js → chunk-6QP4QXBR.js} +3 -3
  60. package/dist/{chunk-EZH7FNUS.js.map → chunk-6QP4QXBR.js.map} +1 -1
  61. package/dist/{chunk-E6TXEISH.cjs → chunk-7UTUKH4E.cjs} +4 -4
  62. package/dist/{chunk-E6TXEISH.cjs.map → chunk-7UTUKH4E.cjs.map} +1 -1
  63. package/dist/chunk-7WLEQIHA.cjs +605 -0
  64. package/dist/chunk-7WLEQIHA.cjs.map +1 -0
  65. package/dist/{chunk-BQITNFQJ.js → chunk-AQVDAKXH.js} +3 -3
  66. package/dist/{chunk-BQITNFQJ.js.map → chunk-AQVDAKXH.js.map} +1 -1
  67. package/dist/{chunk-X6CNEA32.js → chunk-BUZWMDNL.js} +5 -5
  68. package/dist/{chunk-X6CNEA32.js.map → chunk-BUZWMDNL.js.map} +1 -1
  69. package/dist/{chunk-7M3NACL3.cjs → chunk-CKFBZ4LV.cjs} +4 -4
  70. package/dist/{chunk-7M3NACL3.cjs.map → chunk-CKFBZ4LV.cjs.map} +1 -1
  71. package/dist/{chunk-IFRPHG7O.js → chunk-EFZ4S22A.js} +10 -9
  72. package/dist/chunk-EFZ4S22A.js.map +1 -0
  73. package/dist/chunk-ELA3V6UN.js +601 -0
  74. package/dist/chunk-ELA3V6UN.js.map +1 -0
  75. package/dist/chunk-HAQVISUF.cjs +1098 -0
  76. package/dist/chunk-HAQVISUF.cjs.map +1 -0
  77. package/dist/{chunk-BKAKAVRW.cjs → chunk-HQRZEYYB.cjs} +44 -44
  78. package/dist/{chunk-BKAKAVRW.cjs.map → chunk-HQRZEYYB.cjs.map} +1 -1
  79. package/dist/{chunk-KAFXPB2L.js → chunk-I5CRUPKO.js} +9 -10
  80. package/dist/{chunk-KAFXPB2L.js.map → chunk-I5CRUPKO.js.map} +1 -1
  81. package/dist/{chunk-IFDXG2YJ.js → chunk-JHK6NPFV.js} +217 -305
  82. package/dist/chunk-JHK6NPFV.js.map +1 -0
  83. package/dist/{chunk-VXAFOF6Z.cjs → chunk-JP5EICR6.cjs} +12 -7
  84. package/dist/chunk-JP5EICR6.cjs.map +1 -0
  85. package/dist/chunk-JZYMOHHM.cjs +226 -0
  86. package/dist/chunk-JZYMOHHM.cjs.map +1 -0
  87. package/dist/{chunk-ERZ4QPQX.js → chunk-K6CD6W5J.js} +5 -5
  88. package/dist/{chunk-ERZ4QPQX.js.map → chunk-K6CD6W5J.js.map} +1 -1
  89. package/dist/{chunk-JD2YC62H.cjs → chunk-KHNKYSGP.cjs} +34 -34
  90. package/dist/{chunk-JD2YC62H.cjs.map → chunk-KHNKYSGP.cjs.map} +1 -1
  91. package/dist/{chunk-CWX77JB4.cjs → chunk-KLR77R5A.cjs} +13 -13
  92. package/dist/{chunk-CWX77JB4.cjs.map → chunk-KLR77R5A.cjs.map} +1 -1
  93. package/dist/chunk-KOI7UEI5.js +81 -0
  94. package/dist/chunk-KOI7UEI5.js.map +1 -0
  95. package/dist/{chunk-AOL64O4Z.js → chunk-L3DDZUZP.js} +3 -3
  96. package/dist/{chunk-AOL64O4Z.js.map → chunk-L3DDZUZP.js.map} +1 -1
  97. package/dist/{chunk-PZHC5GCD.js → chunk-L5ET7FYQ.js} +3 -3
  98. package/dist/{chunk-PZHC5GCD.js.map → chunk-L5ET7FYQ.js.map} +1 -1
  99. package/dist/{chunk-B63IFHXR.cjs → chunk-LFFVD5ZR.cjs} +41 -41
  100. package/dist/{chunk-B63IFHXR.cjs.map → chunk-LFFVD5ZR.cjs.map} +1 -1
  101. package/dist/chunk-LL5D5T5W.cjs +157 -0
  102. package/dist/chunk-LL5D5T5W.cjs.map +1 -0
  103. package/dist/{chunk-GUUWKPTK.cjs → chunk-LLE25NRD.cjs} +7 -7
  104. package/dist/{chunk-GUUWKPTK.cjs.map → chunk-LLE25NRD.cjs.map} +1 -1
  105. package/dist/chunk-LLHMAHG4.cjs +886 -0
  106. package/dist/chunk-LLHMAHG4.cjs.map +1 -0
  107. package/dist/{chunk-6SRLCSAV.cjs → chunk-LOKG3KQV.cjs} +962 -875
  108. package/dist/chunk-LOKG3KQV.cjs.map +1 -0
  109. package/dist/{chunk-KIZSHRUI.cjs → chunk-M2RPZS7J.cjs} +10 -10
  110. package/dist/{chunk-KIZSHRUI.cjs.map → chunk-M2RPZS7J.cjs.map} +1 -1
  111. package/dist/chunk-MNURF4RF.cjs +85 -0
  112. package/dist/chunk-MNURF4RF.cjs.map +1 -0
  113. package/dist/{chunk-CBK2IVI2.js → chunk-MQBF3XGY.js} +119 -32
  114. package/dist/chunk-MQBF3XGY.js.map +1 -0
  115. package/dist/chunk-QCKD3RCI.cjs +83 -0
  116. package/dist/chunk-QCKD3RCI.cjs.map +1 -0
  117. package/dist/chunk-QOHTVDHU.js +144 -0
  118. package/dist/chunk-QOHTVDHU.js.map +1 -0
  119. package/dist/{chunk-HTQOBY75.cjs → chunk-QXKVUJLI.cjs} +110 -109
  120. package/dist/chunk-QXKVUJLI.cjs.map +1 -0
  121. package/dist/{chunk-GNPGGLAE.cjs → chunk-QYDUCWD2.cjs} +4 -4
  122. package/dist/{chunk-GNPGGLAE.cjs.map → chunk-QYDUCWD2.cjs.map} +1 -1
  123. package/dist/{chunk-DOKUXLFH.js → chunk-QZYGZVUI.js} +34 -34
  124. package/dist/chunk-QZYGZVUI.js.map +1 -0
  125. package/dist/{chunk-GKQU44SQ.cjs → chunk-SAMJLDGG.cjs} +103 -103
  126. package/dist/{chunk-GKQU44SQ.cjs.map → chunk-SAMJLDGG.cjs.map} +1 -1
  127. package/dist/{chunk-DOVMTPKE.cjs → chunk-SE422RES.cjs} +27 -27
  128. package/dist/{chunk-DOVMTPKE.cjs.map → chunk-SE422RES.cjs.map} +1 -1
  129. package/dist/{chunk-5ELKD2FQ.cjs → chunk-UCHW2MGP.cjs} +330 -431
  130. package/dist/chunk-UCHW2MGP.cjs.map +1 -0
  131. package/dist/{chunk-Y6UA55YS.cjs → chunk-UDS5DZNY.cjs} +495 -1095
  132. package/dist/chunk-UDS5DZNY.cjs.map +1 -0
  133. package/dist/{chunk-SU7VQOJ3.js → chunk-V3S74J44.js} +9 -5
  134. package/dist/chunk-V3S74J44.js.map +1 -0
  135. package/dist/{chunk-VDYA2HMS.js → chunk-VWEFXG73.js} +3 -3
  136. package/dist/{chunk-VDYA2HMS.js.map → chunk-VWEFXG73.js.map} +1 -1
  137. package/dist/{chunk-KXFUQNF2.js → chunk-W66YCXWT.js} +463 -1047
  138. package/dist/chunk-W66YCXWT.js.map +1 -0
  139. package/dist/{chunk-NQBYTLPW.js → chunk-XMEYZYGE.js} +6 -6
  140. package/dist/{chunk-NQBYTLPW.js.map → chunk-XMEYZYGE.js.map} +1 -1
  141. package/dist/{chunk-G3CSQLLT.js → chunk-Y5UC3IXF.js} +461 -6
  142. package/dist/chunk-Y5UC3IXF.js.map +1 -0
  143. package/dist/{chunk-SDHV2MWU.js → chunk-YGX4PMG6.js} +5 -5
  144. package/dist/{chunk-SDHV2MWU.js.map → chunk-YGX4PMG6.js.map} +1 -1
  145. package/dist/{chunk-E2Q7SP2K.cjs → chunk-YIX3BEBR.cjs} +86 -85
  146. package/dist/chunk-YIX3BEBR.cjs.map +1 -0
  147. package/dist/{chunk-X6RDQ5NB.cjs → chunk-YX3H63VV.cjs} +8 -2
  148. package/dist/chunk-YX3H63VV.cjs.map +1 -0
  149. package/dist/chunk-YYLMXERH.js +211 -0
  150. package/dist/chunk-YYLMXERH.js.map +1 -0
  151. package/dist/{chunk-YPUNPG2T.js → chunk-ZE7E46IZ.js} +5 -5
  152. package/dist/{chunk-YPUNPG2T.js.map → chunk-ZE7E46IZ.js.map} +1 -1
  153. package/dist/{chunk-Z2PPIVOO.js → chunk-ZVME6OSV.js} +5 -5
  154. package/dist/{chunk-Z2PPIVOO.js.map → chunk-ZVME6OSV.js.map} +1 -1
  155. package/dist/core/index.cjs +15 -3
  156. package/dist/core/index.d.cts +4 -3
  157. package/dist/core/index.d.ts +4 -3
  158. package/dist/core/index.js +2 -2
  159. package/dist/{ddl-J6sDyABg.d.cts → ddl-BCXFRLWg.d.cts} +3 -3
  160. package/dist/{ddl-Dx3Z0_WC.d.ts → ddl-ByLmGgn9.d.ts} +3 -3
  161. package/dist/{define-graph-DRo9xpYN.d.ts → define-graph-BSviZubs.d.ts} +1 -1
  162. package/dist/{define-graph-CzEvA_8F.d.cts → define-graph-XyJheaFm.d.cts} +1 -1
  163. package/dist/graph-merge/index.cjs +37 -38
  164. package/dist/graph-merge/index.cjs.map +1 -1
  165. package/dist/graph-merge/index.d.cts +6 -5
  166. package/dist/graph-merge/index.d.ts +6 -5
  167. package/dist/graph-merge/index.js +15 -16
  168. package/dist/graph-merge/index.js.map +1 -1
  169. package/dist/index.cjs +146 -117
  170. package/dist/index.cjs.map +1 -1
  171. package/dist/index.d.cts +12 -10
  172. package/dist/index.d.ts +12 -10
  173. package/dist/index.js +23 -22
  174. package/dist/index.js.map +1 -1
  175. package/dist/indexes/index.cjs +12 -14
  176. package/dist/indexes/index.d.cts +5 -5
  177. package/dist/indexes/index.d.ts +5 -5
  178. package/dist/indexes/index.js +5 -7
  179. package/dist/interchange/index.cjs +28 -29
  180. package/dist/interchange/index.cjs.map +1 -1
  181. package/dist/interchange/index.d.cts +6 -5
  182. package/dist/interchange/index.d.ts +6 -5
  183. package/dist/interchange/index.js +9 -10
  184. package/dist/interchange/index.js.map +1 -1
  185. package/dist/{manager-CASfhmzV.d.ts → manager-C7iC5bk_.d.ts} +27 -3
  186. package/dist/{manager-nCEJiYBb.d.cts → manager-Dm6MCYO7.d.cts} +27 -3
  187. package/dist/{postgres-Cl1ZAN1G.d.ts → postgres-Cb6ceh4-.d.ts} +100 -49
  188. package/dist/{postgres-DMgIKQU-.d.cts → postgres-DZxwzCQ8.d.cts} +100 -49
  189. package/dist/profiler/index.d.cts +8 -7
  190. package/dist/profiler/index.d.ts +8 -7
  191. package/dist/provenance/index.cjs +19 -19
  192. package/dist/provenance/index.d.cts +6 -5
  193. package/dist/provenance/index.d.ts +6 -5
  194. package/dist/provenance/index.js +6 -6
  195. package/dist/schema/index.cjs +33 -101
  196. package/dist/schema/index.cjs.map +1 -1
  197. package/dist/schema/index.d.cts +55 -55
  198. package/dist/schema/index.d.ts +55 -55
  199. package/dist/schema/index.js +6 -86
  200. package/dist/schema/index.js.map +1 -1
  201. package/dist/{temporal-DqtOEo_B.d.ts → searchable-Cet4Oztt.d.ts} +3 -58
  202. package/dist/{temporal-BC_NQV5Y.d.cts → searchable-aUaKh3_r.d.cts} +3 -58
  203. package/dist/{sqlite-BDkW39aa.d.cts → sqlite-Cb3Ilj9_.d.ts} +124 -97
  204. package/dist/{sqlite-CYfhvESj.d.ts → sqlite-Dxklpizv.d.cts} +124 -97
  205. package/dist/{store-view-CLIhwMMX.d.ts → store-view-BDjGFjpN.d.ts} +67 -23
  206. package/dist/{store-view-BJd6Vwpt.d.cts → store-view-PCT7vTKH.d.cts} +67 -23
  207. package/dist/temporal-CyFsSPe8.d.ts +73 -0
  208. package/dist/temporal-Dn_JADWY.d.cts +73 -0
  209. package/dist/{types-CUevi_D1.d.ts → types-CFZiEEPh.d.ts} +1 -1
  210. package/dist/{types-COq3-vMC.d.cts → types-CsaG00wS.d.cts} +1 -1
  211. package/dist/{index-Bq7vSPHy.d.ts → types-D-vOo_pM.d.ts} +2 -2
  212. package/dist/{index-CrFL_ENI.d.cts → types-ho4DJJb_.d.cts} +2 -2
  213. package/dist/{where-BdE_cYtx.d.ts → where-DLYaXa4L.d.ts} +1 -1
  214. package/dist/{where-C92TXCzT.d.cts → where-udes1WRA.d.cts} +1 -1
  215. package/package.json +1 -1
  216. package/dist/chunk-3SK4SVTW.js.map +0 -1
  217. package/dist/chunk-3YFDFOYB.cjs.map +0 -1
  218. package/dist/chunk-5ELKD2FQ.cjs.map +0 -1
  219. package/dist/chunk-6SRLCSAV.cjs.map +0 -1
  220. package/dist/chunk-6XDBRDZE.js.map +0 -1
  221. package/dist/chunk-CBK2IVI2.js.map +0 -1
  222. package/dist/chunk-DDCIXXOO.js +0 -9
  223. package/dist/chunk-DDCIXXOO.js.map +0 -1
  224. package/dist/chunk-DDCYVIVV.cjs +0 -44
  225. package/dist/chunk-DDCYVIVV.cjs.map +0 -1
  226. package/dist/chunk-DOKUXLFH.js.map +0 -1
  227. package/dist/chunk-E2Q7SP2K.cjs.map +0 -1
  228. package/dist/chunk-EOJFGECD.cjs +0 -284
  229. package/dist/chunk-EOJFGECD.cjs.map +0 -1
  230. package/dist/chunk-FMNUSGZ4.cjs +0 -12
  231. package/dist/chunk-G3CSQLLT.js.map +0 -1
  232. package/dist/chunk-HTQOBY75.cjs.map +0 -1
  233. package/dist/chunk-I6FX7AAG.js +0 -39
  234. package/dist/chunk-I6FX7AAG.js.map +0 -1
  235. package/dist/chunk-IFDXG2YJ.js.map +0 -1
  236. package/dist/chunk-IFRPHG7O.js.map +0 -1
  237. package/dist/chunk-J6IJARLG.js +0 -94
  238. package/dist/chunk-J6IJARLG.js.map +0 -1
  239. package/dist/chunk-KXFUQNF2.js.map +0 -1
  240. package/dist/chunk-MTNEGGM2.js +0 -273
  241. package/dist/chunk-MTNEGGM2.js.map +0 -1
  242. package/dist/chunk-SU7VQOJ3.js.map +0 -1
  243. package/dist/chunk-SVUKGWSN.cjs +0 -102
  244. package/dist/chunk-SVUKGWSN.cjs.map +0 -1
  245. package/dist/chunk-UH2USOMG.cjs +0 -627
  246. package/dist/chunk-UH2USOMG.cjs.map +0 -1
  247. package/dist/chunk-VXAFOF6Z.cjs.map +0 -1
  248. package/dist/chunk-X6RDQ5NB.cjs.map +0 -1
  249. package/dist/chunk-Y6UA55YS.cjs.map +0 -1
  250. package/dist/chunk-Y7M44XEK.js +0 -462
  251. package/dist/chunk-Y7M44XEK.js.map +0 -1
  252. package/dist/chunk-Z5QHVL5U.cjs +0 -12
  253. package/dist/chunk-Z5QHVL5U.cjs.map +0 -1
  254. package/dist/chunk-ZKZAIX42.cjs +0 -479
  255. package/dist/chunk-ZKZAIX42.cjs.map +0 -1
@@ -0,0 +1,856 @@
1
+ import { buildPostgresSystemIndexBuilders, buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteSystemIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders } from './chunk-ZVME6OSV.js';
2
+ import { assertNoSystemIndexNameCollision } from './chunk-AQVDAKXH.js';
3
+ import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER } from './chunk-Y5UC3IXF.js';
4
+ import { sql, is } from 'drizzle-orm';
5
+ import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, bigint, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
6
+ import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, uniqueIndex as uniqueIndex$1, getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
7
+
8
+ var regconfig = customType({
9
+ dataType: () => "regconfig"
10
+ });
11
+ var tsvector = customType({
12
+ dataType: () => "tsvector"
13
+ });
14
+
15
+ // src/backend/drizzle/schema/postgres.ts
16
+ var DEFAULT_TABLE_NAMES = {
17
+ nodes: "typegraph_nodes",
18
+ edges: "typegraph_edges",
19
+ recordedNodes: "typegraph_recorded_nodes",
20
+ recordedEdges: "typegraph_recorded_edges",
21
+ recordedClock: "typegraph_recorded_clock",
22
+ revisionOrigins: "typegraph_revision_origins",
23
+ uniques: "typegraph_node_uniques",
24
+ schemaVersions: "typegraph_schema_versions",
25
+ fulltext: "typegraph_node_fulltext",
26
+ indexMaterializations: "typegraph_index_materializations",
27
+ contributionMaterializations: "typegraph_contribution_materializations",
28
+ kindRemovals: "typegraph_kind_removals",
29
+ reconciliationMarkers: "typegraph_reconciliation_markers"
30
+ };
31
+ function createPostgresTables(names = {}, options = {}) {
32
+ const n = { ...DEFAULT_TABLE_NAMES, ...names };
33
+ const indexes = options.indexes ?? [];
34
+ assertNoSystemIndexNameCollision(indexes, n);
35
+ const nodes3 = pgTable(
36
+ n.nodes,
37
+ {
38
+ graphId: text("graph_id").notNull(),
39
+ kind: text("kind").notNull(),
40
+ id: text("id").notNull(),
41
+ props: jsonb("props").notNull(),
42
+ version: integer("version").notNull().default(1),
43
+ validFrom: timestamp("valid_from", { withTimezone: true }),
44
+ validTo: timestamp("valid_to", { withTimezone: true }),
45
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
46
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
47
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
48
+ },
49
+ (t) => [
50
+ primaryKey({ columns: [t.graphId, t.kind, t.id] }),
51
+ // System indexes come from SYSTEM_INDEX_DECLARATIONS (single source
52
+ // for both dialects + the runtime materializer).
53
+ ...buildPostgresSystemIndexBuilders("nodes", n.nodes, t),
54
+ ...buildPostgresNodeIndexBuilders(t, indexes)
55
+ ]
56
+ );
57
+ const edges3 = pgTable(
58
+ n.edges,
59
+ {
60
+ graphId: text("graph_id").notNull(),
61
+ id: text("id").notNull(),
62
+ kind: text("kind").notNull(),
63
+ fromKind: text("from_kind").notNull(),
64
+ fromId: text("from_id").notNull(),
65
+ toKind: text("to_kind").notNull(),
66
+ toId: text("to_id").notNull(),
67
+ props: jsonb("props").notNull(),
68
+ validFrom: timestamp("valid_from", { withTimezone: true }),
69
+ validTo: timestamp("valid_to", { withTimezone: true }),
70
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
71
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
72
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
73
+ },
74
+ (t) => [
75
+ primaryKey({ columns: [t.graphId, t.id] }),
76
+ ...buildPostgresSystemIndexBuilders("edges", n.edges, t),
77
+ ...buildPostgresEdgeIndexBuilders(t, indexes)
78
+ ]
79
+ );
80
+ const recordedNodes3 = pgTable(
81
+ n.recordedNodes,
82
+ {
83
+ historyId: text("history_id").notNull(),
84
+ graphId: text("graph_id").notNull(),
85
+ kind: text("kind").notNull(),
86
+ id: text("id").notNull(),
87
+ props: jsonb("props").notNull(),
88
+ version: integer("version").notNull(),
89
+ validFrom: timestamp("valid_from", { withTimezone: true }),
90
+ validTo: timestamp("valid_to", { withTimezone: true }),
91
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
92
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
93
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
94
+ recordedFrom: bigint("recorded_from", { mode: "number" }).notNull(),
95
+ recordedTo: bigint("recorded_to", { mode: "number" }).notNull(),
96
+ op: text("op").notNull(),
97
+ schemaVersion: integer("schema_version"),
98
+ txId: text("tx_id"),
99
+ meta: jsonb("meta")
100
+ },
101
+ (t) => [
102
+ primaryKey({ columns: [t.historyId] }),
103
+ ...buildPostgresSystemIndexBuilders("recordedNodes", n.recordedNodes, t)
104
+ ]
105
+ );
106
+ const recordedEdges3 = pgTable(
107
+ n.recordedEdges,
108
+ {
109
+ historyId: text("history_id").notNull(),
110
+ graphId: text("graph_id").notNull(),
111
+ id: text("id").notNull(),
112
+ kind: text("kind").notNull(),
113
+ fromKind: text("from_kind").notNull(),
114
+ fromId: text("from_id").notNull(),
115
+ toKind: text("to_kind").notNull(),
116
+ toId: text("to_id").notNull(),
117
+ props: jsonb("props").notNull(),
118
+ validFrom: timestamp("valid_from", { withTimezone: true }),
119
+ validTo: timestamp("valid_to", { withTimezone: true }),
120
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
121
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
122
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
123
+ recordedFrom: bigint("recorded_from", { mode: "number" }).notNull(),
124
+ recordedTo: bigint("recorded_to", { mode: "number" }).notNull(),
125
+ op: text("op").notNull(),
126
+ schemaVersion: integer("schema_version"),
127
+ txId: text("tx_id"),
128
+ meta: jsonb("meta")
129
+ },
130
+ (t) => [
131
+ primaryKey({ columns: [t.historyId] }),
132
+ ...buildPostgresSystemIndexBuilders("recordedEdges", n.recordedEdges, t)
133
+ ]
134
+ );
135
+ const recordedClock3 = pgTable(
136
+ n.recordedClock,
137
+ {
138
+ graphId: text("graph_id").notNull(),
139
+ revision: bigint("revision", { mode: "number" }).notNull(),
140
+ recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull()
141
+ },
142
+ (t) => [primaryKey({ columns: [t.graphId] })]
143
+ );
144
+ const revisionOrigins = pgTable(
145
+ n.revisionOrigins,
146
+ {
147
+ graphId: text("graph_id").notNull(),
148
+ origin: text("origin").notNull()
149
+ },
150
+ (t) => [primaryKey({ columns: [t.graphId] })]
151
+ );
152
+ const uniques3 = pgTable(
153
+ n.uniques,
154
+ {
155
+ graphId: text("graph_id").notNull(),
156
+ nodeKind: text("node_kind").notNull(),
157
+ constraintName: text("constraint_name").notNull(),
158
+ key: text("key").notNull(),
159
+ nodeId: text("node_id").notNull(),
160
+ concreteKind: text("concrete_kind").notNull(),
161
+ deletedAt: timestamp("deleted_at", { withTimezone: true })
162
+ },
163
+ (t) => [
164
+ primaryKey({
165
+ columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
166
+ }),
167
+ index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
168
+ ]
169
+ );
170
+ const schemaVersions3 = pgTable(
171
+ n.schemaVersions,
172
+ {
173
+ graphId: text("graph_id").notNull(),
174
+ version: integer("version").notNull(),
175
+ schemaHash: text("schema_hash").notNull(),
176
+ schemaDoc: jsonb("schema_doc").notNull(),
177
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
178
+ isActive: boolean("is_active").notNull().default(false)
179
+ },
180
+ (t) => [
181
+ primaryKey({ columns: [t.graphId, t.version] }),
182
+ index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
183
+ // Partial unique index enforcing the "at most one active version
184
+ // per graph" invariant at the storage layer. Defense in depth
185
+ // against buggy backend implementations or out-of-band writes.
186
+ // Forces the deactivate-then-activate ordering used by
187
+ // `commitSchemaVersion` and `setActiveVersion`.
188
+ uniqueIndex(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = TRUE`)
189
+ ]
190
+ );
191
+ const indexMaterializations = pgTable(
192
+ n.indexMaterializations,
193
+ {
194
+ indexName: text("index_name").notNull(),
195
+ graphId: text("graph_id").notNull(),
196
+ entity: text("entity").notNull(),
197
+ kind: text("kind").notNull(),
198
+ signature: text("signature").notNull(),
199
+ schemaVersion: integer("schema_version").notNull(),
200
+ materializedAt: timestamp("materialized_at", { withTimezone: true }),
201
+ lastAttemptedAt: timestamp("last_attempted_at", {
202
+ withTimezone: true
203
+ }).notNull(),
204
+ lastError: text("last_error"),
205
+ // Cross-caller build claim: while `building_since` is fresh (within
206
+ // the lease), exactly one materializer owns this index's CREATE
207
+ // INDEX CONCURRENTLY. Serializes same-index CIC across processes —
208
+ // two concurrent expression-index CICs deadlock each other (no
209
+ // safe-snapshot exemption). NULL when no build is in flight.
210
+ buildingSince: timestamp("building_since", { withTimezone: true }),
211
+ claimToken: text("claim_token")
212
+ },
213
+ (t) => [primaryKey({ columns: [t.indexName] })]
214
+ );
215
+ const kindRemovals = pgTable(
216
+ n.kindRemovals,
217
+ {
218
+ graphId: text("graph_id").notNull(),
219
+ kindName: text("kind_name").notNull(),
220
+ entity: text("entity").notNull(),
221
+ schemaVersion: integer("schema_version").notNull(),
222
+ removedAt: timestamp("removed_at", { withTimezone: true }),
223
+ lastAttemptedAt: timestamp("last_attempted_at", {
224
+ withTimezone: true
225
+ }).notNull(),
226
+ lastError: text("last_error")
227
+ },
228
+ (t) => [
229
+ primaryKey({
230
+ columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
231
+ })
232
+ ]
233
+ );
234
+ const reconciliationMarkers = pgTable(
235
+ n.reconciliationMarkers,
236
+ {
237
+ graphId: text("graph_id").notNull(),
238
+ reconciledToVersion: integer("reconciled_to_version").notNull()
239
+ },
240
+ (t) => [primaryKey({ columns: [t.graphId] })]
241
+ );
242
+ const contributionMaterializations = pgTable(
243
+ n.contributionMaterializations,
244
+ {
245
+ graphId: text("graph_id").notNull(),
246
+ logicalName: text("logical_name").notNull(),
247
+ owner: text("owner").notNull(),
248
+ tableName: text("table_name").notNull(),
249
+ signature: text("signature").notNull(),
250
+ materializedAt: timestamp("materialized_at", { withTimezone: true }),
251
+ lastAttemptedAt: timestamp("last_attempted_at", {
252
+ withTimezone: true
253
+ }).notNull(),
254
+ lastError: text("last_error")
255
+ },
256
+ (t) => [
257
+ primaryKey({
258
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
259
+ })
260
+ ]
261
+ );
262
+ const fulltext2 = pgTable(
263
+ n.fulltext,
264
+ {
265
+ graphId: text("graph_id").notNull(),
266
+ nodeKind: text("node_kind").notNull(),
267
+ nodeId: text("node_id").notNull(),
268
+ content: text("content").notNull(),
269
+ language: regconfig("language").notNull(),
270
+ tsv: tsvector("tsv").generatedAlwaysAs(sql`to_tsvector("language", "content")`).notNull(),
271
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
272
+ },
273
+ (t) => [
274
+ primaryKey({ columns: [t.graphId, t.nodeKind, t.nodeId] }),
275
+ index(`${n.fulltext}_tsv_idx`).using("gin", t.tsv),
276
+ index(`${n.fulltext}_kind_idx`).on(t.graphId, t.nodeKind)
277
+ ]
278
+ );
279
+ return {
280
+ nodes: nodes3,
281
+ edges: edges3,
282
+ recordedNodes: recordedNodes3,
283
+ recordedEdges: recordedEdges3,
284
+ recordedClock: recordedClock3,
285
+ revisionOrigins,
286
+ uniques: uniques3,
287
+ schemaVersions: schemaVersions3,
288
+ indexMaterializations,
289
+ contributionMaterializations,
290
+ kindRemovals,
291
+ reconciliationMarkers,
292
+ fulltext: fulltext2,
293
+ fulltextTableName: n.fulltext
294
+ };
295
+ }
296
+ var tables = createPostgresTables();
297
+ var {
298
+ nodes,
299
+ edges,
300
+ recordedNodes,
301
+ recordedEdges,
302
+ recordedClock,
303
+ uniques,
304
+ schemaVersions,
305
+ fulltext
306
+ } = tables;
307
+ var LEGACY_EMBEDDINGS_TABLE_NAME = "typegraph_node_embeddings";
308
+ var DEFAULT_TABLE_NAMES2 = {
309
+ nodes: "typegraph_nodes",
310
+ edges: "typegraph_edges",
311
+ recordedNodes: "typegraph_recorded_nodes",
312
+ recordedEdges: "typegraph_recorded_edges",
313
+ recordedClock: "typegraph_recorded_clock",
314
+ revisionOrigins: "typegraph_revision_origins",
315
+ uniques: "typegraph_node_uniques",
316
+ schemaVersions: "typegraph_schema_versions",
317
+ fulltext: "typegraph_node_fulltext",
318
+ indexMaterializations: "typegraph_index_materializations",
319
+ contributionMaterializations: "typegraph_contribution_materializations",
320
+ kindRemovals: "typegraph_kind_removals",
321
+ reconciliationMarkers: "typegraph_reconciliation_markers"
322
+ };
323
+ function createSqliteTables(names = {}, options = {}) {
324
+ const n = { ...DEFAULT_TABLE_NAMES2, ...names };
325
+ const indexes = options.indexes ?? [];
326
+ assertNoSystemIndexNameCollision(indexes, n);
327
+ const nodes3 = sqliteTable(
328
+ n.nodes,
329
+ {
330
+ graphId: text$1("graph_id").notNull(),
331
+ kind: text$1("kind").notNull(),
332
+ id: text$1("id").notNull(),
333
+ props: text$1("props").notNull(),
334
+ version: integer$1("version").notNull().default(1),
335
+ validFrom: text$1("valid_from"),
336
+ validTo: text$1("valid_to"),
337
+ createdAt: text$1("created_at").notNull(),
338
+ updatedAt: text$1("updated_at").notNull(),
339
+ deletedAt: text$1("deleted_at")
340
+ },
341
+ (t) => [
342
+ primaryKey$1({ columns: [t.graphId, t.kind, t.id] }),
343
+ // System indexes come from SYSTEM_INDEX_DECLARATIONS (single source
344
+ // for both dialects + the runtime materializer).
345
+ ...buildSqliteSystemIndexBuilders("nodes", n.nodes, t),
346
+ ...buildSqliteNodeIndexBuilders(t, indexes)
347
+ ]
348
+ );
349
+ const edges3 = sqliteTable(
350
+ n.edges,
351
+ {
352
+ graphId: text$1("graph_id").notNull(),
353
+ id: text$1("id").notNull(),
354
+ kind: text$1("kind").notNull(),
355
+ fromKind: text$1("from_kind").notNull(),
356
+ fromId: text$1("from_id").notNull(),
357
+ toKind: text$1("to_kind").notNull(),
358
+ toId: text$1("to_id").notNull(),
359
+ props: text$1("props").notNull(),
360
+ validFrom: text$1("valid_from"),
361
+ validTo: text$1("valid_to"),
362
+ createdAt: text$1("created_at").notNull(),
363
+ updatedAt: text$1("updated_at").notNull(),
364
+ deletedAt: text$1("deleted_at")
365
+ },
366
+ (t) => [
367
+ primaryKey$1({ columns: [t.graphId, t.id] }),
368
+ ...buildSqliteSystemIndexBuilders("edges", n.edges, t),
369
+ ...buildSqliteEdgeIndexBuilders(t, indexes)
370
+ ]
371
+ );
372
+ const recordedNodes3 = sqliteTable(
373
+ n.recordedNodes,
374
+ {
375
+ historyId: text$1("history_id").notNull(),
376
+ graphId: text$1("graph_id").notNull(),
377
+ kind: text$1("kind").notNull(),
378
+ id: text$1("id").notNull(),
379
+ props: text$1("props").notNull(),
380
+ version: integer$1("version").notNull(),
381
+ validFrom: text$1("valid_from"),
382
+ validTo: text$1("valid_to"),
383
+ createdAt: text$1("created_at").notNull(),
384
+ updatedAt: text$1("updated_at").notNull(),
385
+ deletedAt: text$1("deleted_at"),
386
+ recordedFrom: integer$1("recorded_from").notNull(),
387
+ recordedTo: integer$1("recorded_to").notNull(),
388
+ op: text$1("op").notNull(),
389
+ schemaVersion: integer$1("schema_version"),
390
+ txId: text$1("tx_id"),
391
+ meta: text$1("meta")
392
+ },
393
+ (t) => [
394
+ primaryKey$1({ columns: [t.historyId] }),
395
+ ...buildSqliteSystemIndexBuilders("recordedNodes", n.recordedNodes, t)
396
+ ]
397
+ );
398
+ const recordedEdges3 = sqliteTable(
399
+ n.recordedEdges,
400
+ {
401
+ historyId: text$1("history_id").notNull(),
402
+ graphId: text$1("graph_id").notNull(),
403
+ id: text$1("id").notNull(),
404
+ kind: text$1("kind").notNull(),
405
+ fromKind: text$1("from_kind").notNull(),
406
+ fromId: text$1("from_id").notNull(),
407
+ toKind: text$1("to_kind").notNull(),
408
+ toId: text$1("to_id").notNull(),
409
+ props: text$1("props").notNull(),
410
+ validFrom: text$1("valid_from"),
411
+ validTo: text$1("valid_to"),
412
+ createdAt: text$1("created_at").notNull(),
413
+ updatedAt: text$1("updated_at").notNull(),
414
+ deletedAt: text$1("deleted_at"),
415
+ recordedFrom: integer$1("recorded_from").notNull(),
416
+ recordedTo: integer$1("recorded_to").notNull(),
417
+ op: text$1("op").notNull(),
418
+ schemaVersion: integer$1("schema_version"),
419
+ txId: text$1("tx_id"),
420
+ meta: text$1("meta")
421
+ },
422
+ (t) => [
423
+ primaryKey$1({ columns: [t.historyId] }),
424
+ ...buildSqliteSystemIndexBuilders("recordedEdges", n.recordedEdges, t)
425
+ ]
426
+ );
427
+ const recordedClock3 = sqliteTable(
428
+ n.recordedClock,
429
+ {
430
+ graphId: text$1("graph_id").notNull(),
431
+ revision: integer$1("revision").notNull(),
432
+ recordedAt: text$1("recorded_at").notNull()
433
+ },
434
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
435
+ );
436
+ const revisionOrigins = sqliteTable(
437
+ n.revisionOrigins,
438
+ {
439
+ graphId: text$1("graph_id").notNull(),
440
+ origin: text$1("origin").notNull()
441
+ },
442
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
443
+ );
444
+ const uniques3 = sqliteTable(
445
+ n.uniques,
446
+ {
447
+ graphId: text$1("graph_id").notNull(),
448
+ nodeKind: text$1("node_kind").notNull(),
449
+ constraintName: text$1("constraint_name").notNull(),
450
+ key: text$1("key").notNull(),
451
+ nodeId: text$1("node_id").notNull(),
452
+ concreteKind: text$1("concrete_kind").notNull(),
453
+ deletedAt: text$1("deleted_at")
454
+ },
455
+ (t) => [
456
+ primaryKey$1({
457
+ columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
458
+ }),
459
+ index$1(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
460
+ ]
461
+ );
462
+ const schemaVersions3 = sqliteTable(
463
+ n.schemaVersions,
464
+ {
465
+ graphId: text$1("graph_id").notNull(),
466
+ version: integer$1("version").notNull(),
467
+ schemaHash: text$1("schema_hash").notNull(),
468
+ schemaDoc: text$1("schema_doc").notNull(),
469
+ createdAt: text$1("created_at").notNull(),
470
+ isActive: integer$1("is_active", { mode: "boolean" }).notNull().default(false)
471
+ },
472
+ (t) => [
473
+ primaryKey$1({ columns: [t.graphId, t.version] }),
474
+ index$1(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
475
+ // Partial unique index enforcing the "at most one active version
476
+ // per graph" invariant at the storage layer. Defense in depth
477
+ // against buggy backend implementations or out-of-band writes.
478
+ // Forces the deactivate-then-activate ordering used by
479
+ // `commitSchemaVersion` and `setActiveVersion`.
480
+ uniqueIndex$1(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = 1`)
481
+ ]
482
+ );
483
+ const indexMaterializations = sqliteTable(
484
+ n.indexMaterializations,
485
+ {
486
+ indexName: text$1("index_name").notNull(),
487
+ graphId: text$1("graph_id").notNull(),
488
+ entity: text$1("entity").notNull(),
489
+ kind: text$1("kind").notNull(),
490
+ signature: text$1("signature").notNull(),
491
+ schemaVersion: integer$1("schema_version").notNull(),
492
+ materializedAt: text$1("materialized_at"),
493
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
494
+ lastError: text$1("last_error")
495
+ },
496
+ (t) => [primaryKey$1({ columns: [t.indexName] })]
497
+ );
498
+ const kindRemovals = sqliteTable(
499
+ n.kindRemovals,
500
+ {
501
+ graphId: text$1("graph_id").notNull(),
502
+ kindName: text$1("kind_name").notNull(),
503
+ entity: text$1("entity").notNull(),
504
+ schemaVersion: integer$1("schema_version").notNull(),
505
+ removedAt: text$1("removed_at"),
506
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
507
+ lastError: text$1("last_error")
508
+ },
509
+ (t) => [
510
+ primaryKey$1({
511
+ columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
512
+ })
513
+ ]
514
+ );
515
+ const reconciliationMarkers = sqliteTable(
516
+ n.reconciliationMarkers,
517
+ {
518
+ graphId: text$1("graph_id").notNull(),
519
+ reconciledToVersion: integer$1("reconciled_to_version").notNull()
520
+ },
521
+ (t) => [primaryKey$1({ columns: [t.graphId] })]
522
+ );
523
+ const contributionMaterializations = sqliteTable(
524
+ n.contributionMaterializations,
525
+ {
526
+ graphId: text$1("graph_id").notNull(),
527
+ logicalName: text$1("logical_name").notNull(),
528
+ owner: text$1("owner").notNull(),
529
+ tableName: text$1("table_name").notNull(),
530
+ signature: text$1("signature").notNull(),
531
+ materializedAt: text$1("materialized_at"),
532
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
533
+ lastError: text$1("last_error")
534
+ },
535
+ (t) => [
536
+ primaryKey$1({
537
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
538
+ })
539
+ ]
540
+ );
541
+ return {
542
+ nodes: nodes3,
543
+ edges: edges3,
544
+ recordedNodes: recordedNodes3,
545
+ recordedEdges: recordedEdges3,
546
+ recordedClock: recordedClock3,
547
+ revisionOrigins,
548
+ uniques: uniques3,
549
+ schemaVersions: schemaVersions3,
550
+ indexMaterializations,
551
+ contributionMaterializations,
552
+ kindRemovals,
553
+ reconciliationMarkers,
554
+ /**
555
+ * The fulltext storage is a FTS5 virtual table which Drizzle cannot
556
+ * represent. DDL is emitted as raw SQL and operations query it via
557
+ * `sql.raw()`.
558
+ */
559
+ fulltextTableName: n.fulltext
560
+ };
561
+ }
562
+ var tables2 = createSqliteTables();
563
+ var {
564
+ nodes: nodes2,
565
+ edges: edges2,
566
+ recordedNodes: recordedNodes2,
567
+ recordedEdges: recordedEdges2,
568
+ recordedClock: recordedClock2,
569
+ uniques: uniques2,
570
+ schemaVersions: schemaVersions2
571
+ } = tables2;
572
+ function getSqliteColumnType(column) {
573
+ switch (column.columnType) {
574
+ case "SQLiteText": {
575
+ return "TEXT";
576
+ }
577
+ case "SQLiteInteger": {
578
+ return "INTEGER";
579
+ }
580
+ case "SQLiteReal": {
581
+ return "REAL";
582
+ }
583
+ case "SQLiteBlob": {
584
+ return "BLOB";
585
+ }
586
+ default: {
587
+ return "TEXT";
588
+ }
589
+ }
590
+ }
591
+ function formatDefaultValue(value) {
592
+ if (value === null) return "NULL";
593
+ if (typeof value === "string") return `'${value}'`;
594
+ if (typeof value === "number") return String(value);
595
+ if (typeof value === "boolean") return value ? "1" : "0";
596
+ return JSON.stringify(value);
597
+ }
598
+ function generateSqliteCreateTableSQL(table) {
599
+ const config = getTableConfig(table);
600
+ const columnDefs = [];
601
+ for (const column of config.columns) {
602
+ const parts = [
603
+ `"${column.name}"`,
604
+ getSqliteColumnType(column)
605
+ ];
606
+ if (column.notNull) {
607
+ parts.push("NOT NULL");
608
+ }
609
+ if (column.hasDefault && column.default !== void 0) {
610
+ parts.push(`DEFAULT ${formatDefaultValue(column.default)}`);
611
+ }
612
+ columnDefs.push(parts.join(" "));
613
+ }
614
+ const pk = config.primaryKeys[0];
615
+ if (pk) {
616
+ const pkColumns = pk.columns.map((c) => `"${c.name}"`).join(", ");
617
+ columnDefs.push(`PRIMARY KEY (${pkColumns})`);
618
+ }
619
+ return `CREATE TABLE IF NOT EXISTS "${config.name}" (
620
+ ${columnDefs.join(",\n ")}
621
+ );`;
622
+ }
623
+ function renderIndexColumn(col) {
624
+ if (col && typeof col === "object" && "name" in col) {
625
+ return `"${col.name}"`;
626
+ }
627
+ const sql3 = tryInlineSql(col);
628
+ if (sql3 !== void 0) {
629
+ return sql3;
630
+ }
631
+ return "unknown";
632
+ }
633
+ function tryInlineSql(value) {
634
+ if (value && typeof value === "object" && "getSQL" in value) {
635
+ const maybe = value;
636
+ if (typeof maybe.getSQL === "function") {
637
+ return inlineSql(maybe.getSQL());
638
+ }
639
+ }
640
+ return inlineSql(value);
641
+ }
642
+ function flattenSqlChunk(chunk) {
643
+ if (typeof chunk === "string") {
644
+ return chunk;
645
+ }
646
+ if (typeof chunk === "object" && chunk !== null) {
647
+ if ("name" in chunk && typeof chunk.name === "string") {
648
+ return `"${chunk.name}"`;
649
+ }
650
+ if ("value" in chunk) {
651
+ const value = chunk.value;
652
+ if (typeof value === "string") {
653
+ return value;
654
+ }
655
+ if (Array.isArray(value)) {
656
+ return value.map((part) => flattenSqlChunk(part)).join("");
657
+ }
658
+ }
659
+ if ("queryChunks" in chunk && Array.isArray(chunk.queryChunks)) {
660
+ return chunk.queryChunks.map((part) => flattenSqlChunk(part)).join("");
661
+ }
662
+ if ("getSQL" in chunk) {
663
+ const maybe = chunk;
664
+ if (typeof maybe.getSQL === "function") {
665
+ return flattenSqlChunk(maybe.getSQL());
666
+ }
667
+ }
668
+ }
669
+ throw new Error(`Unable to inline SQL chunk: ${String(chunk)}`);
670
+ }
671
+ function inlineSql(value) {
672
+ try {
673
+ return flattenSqlChunk(value);
674
+ } catch {
675
+ return void 0;
676
+ }
677
+ }
678
+ function inlineSqlOrThrow(value, context) {
679
+ const inlined = inlineSql(value);
680
+ if (inlined === void 0) {
681
+ throw new Error(`Unable to inline SQL for ${context}`);
682
+ }
683
+ return inlined;
684
+ }
685
+ function generateSqliteCreateIndexSQL(table) {
686
+ const config = getTableConfig(table);
687
+ const statements = [];
688
+ for (const index3 of config.indexes) {
689
+ const indexConfig = index3.config;
690
+ const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
691
+ const unique = indexConfig.unique ? "UNIQUE " : "";
692
+ const where = indexConfig.where ? ` WHERE ${inlineSqlOrThrow(indexConfig.where, `SQLite index "${indexConfig.name}" WHERE clause`)}` : "";
693
+ statements.push(
694
+ `CREATE ${unique}INDEX IF NOT EXISTS "${indexConfig.name}" ON "${config.name}" (${columns})${where};`
695
+ );
696
+ }
697
+ return statements;
698
+ }
699
+ function isSqliteTable(value) {
700
+ return is(value, SQLiteTable);
701
+ }
702
+ function runtimeStrategyContributions(fulltextStrategy, fulltextTableName) {
703
+ return fulltextStrategy.ownedTables(fulltextTableName).filter((contribution) => contribution.runtimeEnsure);
704
+ }
705
+ function sqliteContributions(tables3 = tables2, fulltextStrategy = fts5Strategy) {
706
+ const contributions = [];
707
+ for (const [key, table] of Object.entries(tables3)) {
708
+ if (!isSqliteTable(table)) continue;
709
+ contributions.push({
710
+ logicalName: key,
711
+ owner: BASE_CONTRIBUTION_OWNER,
712
+ tableName: getTableConfig(table).name,
713
+ createDdl: [
714
+ generateSqliteCreateTableSQL(table),
715
+ ...generateSqliteCreateIndexSQL(table)
716
+ ],
717
+ runtimeEnsure: false
718
+ });
719
+ }
720
+ for (const declared of fulltextStrategy.ownedTables(
721
+ tables3.fulltextTableName
722
+ )) {
723
+ contributions.push(declared);
724
+ }
725
+ return contributions;
726
+ }
727
+ function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
728
+ return sqliteContributions(tables3, fulltextStrategy).flatMap(
729
+ (contribution) => [...contribution.createDdl]
730
+ );
731
+ }
732
+ function generateSqliteMigrationSQL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
733
+ return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
734
+ }
735
+ function getPgColumnType(column) {
736
+ switch (column.columnType) {
737
+ case "PgText": {
738
+ return "TEXT";
739
+ }
740
+ case "PgInteger": {
741
+ return "INTEGER";
742
+ }
743
+ case "PgBigInt53":
744
+ case "PgBigInt64": {
745
+ return "BIGINT";
746
+ }
747
+ case "PgBoolean": {
748
+ return "BOOLEAN";
749
+ }
750
+ case "PgJsonb": {
751
+ return "JSONB";
752
+ }
753
+ case "PgTimestamp": {
754
+ return column.config?.withTimezone ? "TIMESTAMPTZ" : "TIMESTAMP";
755
+ }
756
+ case "PgReal": {
757
+ return "REAL";
758
+ }
759
+ case "PgDoublePrecision": {
760
+ return "DOUBLE PRECISION";
761
+ }
762
+ case "PgCustomColumn": {
763
+ const dataType = column.getSQLType?.();
764
+ return dataType ?? "TEXT";
765
+ }
766
+ default: {
767
+ return "TEXT";
768
+ }
769
+ }
770
+ }
771
+ function formatPgDefaultValue(value) {
772
+ if (value === null) return "NULL";
773
+ if (typeof value === "string") return `'${value}'`;
774
+ if (typeof value === "number") return String(value);
775
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
776
+ return JSON.stringify(value);
777
+ }
778
+ function generatePgCreateTableSQL(table) {
779
+ const config = getTableConfig$1(table);
780
+ const columnDefs = [];
781
+ for (const column of config.columns) {
782
+ const parts = [`"${column.name}"`, getPgColumnType(column)];
783
+ if (column.notNull) {
784
+ parts.push("NOT NULL");
785
+ }
786
+ if (column.hasDefault && column.default !== void 0) {
787
+ parts.push(`DEFAULT ${formatPgDefaultValue(column.default)}`);
788
+ }
789
+ columnDefs.push(parts.join(" "));
790
+ }
791
+ const pk = config.primaryKeys[0];
792
+ if (pk) {
793
+ const pkColumns = pk.columns.map((c) => `"${c.name}"`).join(", ");
794
+ columnDefs.push(`PRIMARY KEY (${pkColumns})`);
795
+ }
796
+ return `CREATE TABLE IF NOT EXISTS "${config.name}" (
797
+ ${columnDefs.join(",\n ")}
798
+ );`;
799
+ }
800
+ function generatePgCreateIndexSQL(table) {
801
+ const config = getTableConfig$1(table);
802
+ const statements = [];
803
+ for (const index3 of config.indexes) {
804
+ const indexConfig = index3.config;
805
+ const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
806
+ const unique = indexConfig.unique ? "UNIQUE " : "";
807
+ const method = indexConfig.method && indexConfig.method !== "btree" ? ` USING ${indexConfig.method}` : "";
808
+ const where = indexConfig.where ? ` WHERE ${inlineSqlOrThrow(indexConfig.where, `PostgreSQL index "${indexConfig.name}" WHERE clause`)}` : "";
809
+ statements.push(
810
+ `CREATE ${unique}INDEX IF NOT EXISTS "${indexConfig.name}" ON "${config.name}"${method} (${columns})${where};`
811
+ );
812
+ }
813
+ return statements;
814
+ }
815
+ function isPgTable(value) {
816
+ return is(value, PgTable);
817
+ }
818
+ function postgresContributions(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
819
+ const contributions = [];
820
+ for (const [key, table] of Object.entries(tables3)) {
821
+ if (!isPgTable(table)) continue;
822
+ if (table === tables3.fulltext) continue;
823
+ contributions.push({
824
+ logicalName: key,
825
+ owner: BASE_CONTRIBUTION_OWNER,
826
+ tableName: getTableConfig$1(table).name,
827
+ createDdl: [
828
+ generatePgCreateTableSQL(table),
829
+ ...generatePgCreateIndexSQL(table)
830
+ ],
831
+ runtimeEnsure: false
832
+ });
833
+ }
834
+ for (const declared of fulltextStrategy.ownedTables(
835
+ tables3.fulltextTableName
836
+ )) {
837
+ contributions.push(declared);
838
+ }
839
+ return contributions;
840
+ }
841
+ function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
842
+ return postgresContributions(tables3, fulltextStrategy).flatMap(
843
+ (contribution) => [...contribution.createDdl]
844
+ );
845
+ }
846
+ function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
847
+ const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
848
+ const ddlSql = generatePostgresDDL(tables3, fulltextStrategy).join("\n\n");
849
+ return `${extensionSql}
850
+
851
+ ${ddlSql}`;
852
+ }
853
+
854
+ export { LEGACY_EMBEDDINGS_TABLE_NAME, createPostgresTables, createSqliteTables, edges, edges2, fulltext, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, nodes, nodes2, postgresContributions, recordedClock, recordedClock2, recordedEdges, recordedEdges2, recordedNodes, recordedNodes2, runtimeStrategyContributions, schemaVersions, schemaVersions2, sqliteContributions, tables, tables2, uniques, uniques2 };
855
+ //# sourceMappingURL=chunk-5J4VNCUD.js.map
856
+ //# sourceMappingURL=chunk-5J4VNCUD.js.map