@nicia-ai/typegraph 0.31.0 → 0.33.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 (188) hide show
  1. package/README.md +31 -0
  2. package/dist/backend/postgres/index.cjs +31 -18
  3. package/dist/backend/postgres/index.d.cts +6 -6
  4. package/dist/backend/postgres/index.d.ts +6 -6
  5. package/dist/backend/postgres/index.js +9 -8
  6. package/dist/backend/postgres/pglite.cjs +13 -12
  7. package/dist/backend/postgres/pglite.cjs.map +1 -1
  8. package/dist/backend/postgres/pglite.d.cts +3 -3
  9. package/dist/backend/postgres/pglite.d.ts +3 -3
  10. package/dist/backend/postgres/pglite.js +9 -8
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +29 -16
  13. package/dist/backend/sqlite/index.d.cts +7 -7
  14. package/dist/backend/sqlite/index.d.ts +7 -7
  15. package/dist/backend/sqlite/index.js +8 -7
  16. package/dist/backend/sqlite/libsql.cjs +13 -12
  17. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  18. package/dist/backend/sqlite/libsql.d.cts +3 -3
  19. package/dist/backend/sqlite/libsql.d.ts +3 -3
  20. package/dist/backend/sqlite/libsql.js +9 -8
  21. package/dist/backend/sqlite/libsql.js.map +1 -1
  22. package/dist/backend/sqlite/local.cjs +14 -13
  23. package/dist/backend/sqlite/local.cjs.map +1 -1
  24. package/dist/backend/sqlite/local.d.cts +3 -3
  25. package/dist/backend/sqlite/local.d.ts +3 -3
  26. package/dist/backend/sqlite/local.js +9 -8
  27. package/dist/backend/sqlite/local.js.map +1 -1
  28. package/dist/{chunk-SFFJ2IKN.cjs → chunk-3642VBVC.cjs} +70 -68
  29. package/dist/chunk-3642VBVC.cjs.map +1 -0
  30. package/dist/chunk-3E7SNSIA.cjs +55 -0
  31. package/dist/chunk-3E7SNSIA.cjs.map +1 -0
  32. package/dist/{chunk-6RMLO5O4.cjs → chunk-3IR2GEMJ.cjs} +8 -7
  33. package/dist/chunk-3IR2GEMJ.cjs.map +1 -0
  34. package/dist/{chunk-6SA7UIQJ.cjs → chunk-3QRBXYT5.cjs} +6 -6
  35. package/dist/{chunk-6SA7UIQJ.cjs.map → chunk-3QRBXYT5.cjs.map} +1 -1
  36. package/dist/{chunk-54JVNOAQ.cjs → chunk-4RBAJVEC.cjs} +128 -6
  37. package/dist/chunk-4RBAJVEC.cjs.map +1 -0
  38. package/dist/{chunk-IJORSAC3.js → chunk-6NRFUHMS.js} +4 -3
  39. package/dist/chunk-6NRFUHMS.js.map +1 -0
  40. package/dist/{chunk-FLOI7QOT.cjs → chunk-BF3ZDEUE.cjs} +104 -72
  41. package/dist/chunk-BF3ZDEUE.cjs.map +1 -0
  42. package/dist/{chunk-2HZGWCB4.js → chunk-C4C4Q7A6.js} +3 -3
  43. package/dist/chunk-C4C4Q7A6.js.map +1 -0
  44. package/dist/{chunk-O4VUR6SI.js → chunk-CEF2QOTO.js} +3 -3
  45. package/dist/{chunk-O4VUR6SI.js.map → chunk-CEF2QOTO.js.map} +1 -1
  46. package/dist/{chunk-V4IQYOQ4.cjs → chunk-CFNT3ITG.cjs} +3 -3
  47. package/dist/chunk-CFNT3ITG.cjs.map +1 -0
  48. package/dist/{chunk-LJLMDDCW.js → chunk-CWFPJ3RC.js} +3 -3
  49. package/dist/{chunk-LJLMDDCW.js.map → chunk-CWFPJ3RC.js.map} +1 -1
  50. package/dist/{chunk-RZ4DH4E7.cjs → chunk-D3EWZ67S.cjs} +3348 -2030
  51. package/dist/chunk-D3EWZ67S.cjs.map +1 -0
  52. package/dist/{chunk-GKFWM3DS.js → chunk-DJYRRDHA.js} +124 -5
  53. package/dist/chunk-DJYRRDHA.js.map +1 -0
  54. package/dist/{chunk-YQGLVWB2.cjs → chunk-EF3Z645U.cjs} +2 -52
  55. package/dist/chunk-EF3Z645U.cjs.map +1 -0
  56. package/dist/{chunk-ASYQDPPU.cjs → chunk-FDN43KXV.cjs} +19 -19
  57. package/dist/{chunk-ASYQDPPU.cjs.map → chunk-FDN43KXV.cjs.map} +1 -1
  58. package/dist/chunk-GYVBEZAO.js +120 -0
  59. package/dist/chunk-GYVBEZAO.js.map +1 -0
  60. package/dist/chunk-I4W7MKVG.cjs +1526 -0
  61. package/dist/chunk-I4W7MKVG.cjs.map +1 -0
  62. package/dist/{chunk-MXE2U3EX.js → chunk-IZ4PCL47.js} +3 -52
  63. package/dist/chunk-IZ4PCL47.js.map +1 -0
  64. package/dist/{chunk-4A4GUZTQ.js → chunk-JHOBXD7O.js} +10 -8
  65. package/dist/chunk-JHOBXD7O.js.map +1 -0
  66. package/dist/{chunk-CIINW6PS.cjs → chunk-KY5SDVA7.cjs} +676 -635
  67. package/dist/chunk-KY5SDVA7.cjs.map +1 -0
  68. package/dist/{chunk-N2MBPTAF.cjs → chunk-LM2IC4ZJ.cjs} +14 -14
  69. package/dist/{chunk-N2MBPTAF.cjs.map → chunk-LM2IC4ZJ.cjs.map} +1 -1
  70. package/dist/{chunk-7JGLPAFV.cjs → chunk-MBLXCV2Y.cjs} +16 -16
  71. package/dist/chunk-MBLXCV2Y.cjs.map +1 -0
  72. package/dist/{chunk-5DTPBFX5.cjs → chunk-NG5N7R45.cjs} +28 -28
  73. package/dist/{chunk-5DTPBFX5.cjs.map → chunk-NG5N7R45.cjs.map} +1 -1
  74. package/dist/chunk-OIE2UPVG.cjs +126 -0
  75. package/dist/chunk-OIE2UPVG.cjs.map +1 -0
  76. package/dist/{chunk-STP7QVUB.js → chunk-OS6KS3HV.js} +43 -11
  77. package/dist/chunk-OS6KS3HV.js.map +1 -0
  78. package/dist/{chunk-2ZY4K43M.js → chunk-PIHXFF73.js} +3 -3
  79. package/dist/{chunk-2ZY4K43M.js.map → chunk-PIHXFF73.js.map} +1 -1
  80. package/dist/{chunk-ATTXBMAX.js → chunk-PRMKPFN5.js} +3 -3
  81. package/dist/{chunk-ATTXBMAX.js.map → chunk-PRMKPFN5.js.map} +1 -1
  82. package/dist/chunk-PYD3UCDU.js +1480 -0
  83. package/dist/chunk-PYD3UCDU.js.map +1 -0
  84. package/dist/{chunk-MAQJYNJR.js → chunk-QBYTJSAY.js} +14 -16
  85. package/dist/chunk-QBYTJSAY.js.map +1 -0
  86. package/dist/{chunk-THX25XW6.js → chunk-SPT5JMME.js} +27 -7
  87. package/dist/chunk-SPT5JMME.js.map +1 -0
  88. package/dist/{chunk-3JBJEYWE.cjs → chunk-SST7XDY6.cjs} +32 -12
  89. package/dist/chunk-SST7XDY6.cjs.map +1 -0
  90. package/dist/{chunk-VZX2KSY3.js → chunk-UPDMJEW6.js} +608 -563
  91. package/dist/chunk-UPDMJEW6.js.map +1 -0
  92. package/dist/{chunk-UIFEEPME.js → chunk-WLP6TKFB.js} +3141 -1823
  93. package/dist/chunk-WLP6TKFB.js.map +1 -0
  94. package/dist/{chunk-VMEWZU2N.cjs → chunk-WWVV44DY.cjs} +11 -11
  95. package/dist/{chunk-VMEWZU2N.cjs.map → chunk-WWVV44DY.cjs.map} +1 -1
  96. package/dist/{chunk-UJ4V3YUQ.js → chunk-XKNAK27R.js} +3 -3
  97. package/dist/{chunk-UJ4V3YUQ.js.map → chunk-XKNAK27R.js.map} +1 -1
  98. package/dist/chunk-XLUNB2TZ.js +53 -0
  99. package/dist/chunk-XLUNB2TZ.js.map +1 -0
  100. package/dist/{chunk-XKJQQQVR.js → chunk-XVUJY72M.js} +6 -6
  101. package/dist/{chunk-XKJQQQVR.js.map → chunk-XVUJY72M.js.map} +1 -1
  102. package/dist/{chunk-5CN7B4CZ.cjs → chunk-YW7GHMF4.cjs} +17 -17
  103. package/dist/{chunk-5CN7B4CZ.cjs.map → chunk-YW7GHMF4.cjs.map} +1 -1
  104. package/dist/{ddl-BJcPrB4L.d.ts → ddl-CVnHJcar.d.ts} +3 -3
  105. package/dist/{ddl-CPZ7mB7X.d.cts → ddl-Dxt_fBHr.d.cts} +3 -3
  106. package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
  107. package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
  108. package/dist/graph-extension/index.d.cts +4 -4
  109. package/dist/graph-extension/index.d.ts +4 -4
  110. package/dist/graph-merge/index.cjs +200 -55
  111. package/dist/graph-merge/index.cjs.map +1 -1
  112. package/dist/graph-merge/index.d.cts +6 -6
  113. package/dist/graph-merge/index.d.ts +6 -6
  114. package/dist/graph-merge/index.js +185 -40
  115. package/dist/graph-merge/index.js.map +1 -1
  116. package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
  117. package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
  118. package/dist/index.cjs +145 -116
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.cts +25 -55
  121. package/dist/index.d.ts +25 -55
  122. package/dist/index.js +19 -17
  123. package/dist/index.js.map +1 -1
  124. package/dist/indexes/index.cjs +15 -14
  125. package/dist/indexes/index.d.cts +5 -5
  126. package/dist/indexes/index.d.ts +5 -5
  127. package/dist/indexes/index.js +6 -5
  128. package/dist/interchange/index.cjs +15 -15
  129. package/dist/interchange/index.d.cts +9 -9
  130. package/dist/interchange/index.d.ts +9 -9
  131. package/dist/interchange/index.js +2 -2
  132. package/dist/{manager-Np7VVSlE.d.cts → manager-BYl_zyZR.d.cts} +2 -2
  133. package/dist/{manager-By-WEd8M.d.ts → manager-C0_r0ALf.d.ts} +2 -2
  134. package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
  135. package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
  136. package/dist/{postgres-4J2tmauh.d.cts → postgres-MzBPkYzq.d.ts} +2651 -596
  137. package/dist/{postgres-BdIb7tS_.d.ts → postgres-_9psmVGm.d.cts} +2651 -596
  138. package/dist/profiler/index.cjs +4 -3
  139. package/dist/profiler/index.cjs.map +1 -1
  140. package/dist/profiler/index.d.cts +7 -7
  141. package/dist/profiler/index.d.ts +7 -7
  142. package/dist/profiler/index.js +2 -1
  143. package/dist/profiler/index.js.map +1 -1
  144. package/dist/schema/index.cjs +30 -29
  145. package/dist/schema/index.cjs.map +1 -1
  146. package/dist/schema/index.d.cts +7 -7
  147. package/dist/schema/index.d.ts +7 -7
  148. package/dist/schema/index.js +7 -6
  149. package/dist/schema/index.js.map +1 -1
  150. package/dist/{sqlite-aM_PAz-O.d.ts → sqlite-BfksSb45.d.cts} +2726 -455
  151. package/dist/{sqlite-Gatk_iw_.d.cts → sqlite-gm44dShb.d.ts} +2726 -455
  152. package/dist/{store-DuCbdqsh.d.cts → store-view-9jQ2rPum.d.cts} +1101 -465
  153. package/dist/{store-MloRPwb9.d.ts → store-view-FfE5_7eo.d.ts} +1101 -465
  154. package/dist/{types-DoByHGyU.d.cts → types-B6mhrcLv.d.cts} +2 -2
  155. package/dist/{types-C1CYxWrL.d.cts → types-C_UnQOQp.d.cts} +154 -23
  156. package/dist/{types-K3vpaJAL.d.ts → types-CdWxK-nD.d.ts} +2 -2
  157. package/dist/{types-BKQljXom.d.ts → types-DGylBhWo.d.ts} +154 -23
  158. package/dist/{where-DydZjGOb.d.cts → where-Bpp2ul_z.d.cts} +2 -2
  159. package/dist/{where-Dt49bvo6.d.ts → where-BsEXraKW.d.ts} +2 -2
  160. package/package.json +2 -2
  161. package/dist/chunk-2HZGWCB4.js.map +0 -1
  162. package/dist/chunk-3JBJEYWE.cjs.map +0 -1
  163. package/dist/chunk-4A4GUZTQ.js.map +0 -1
  164. package/dist/chunk-54JVNOAQ.cjs.map +0 -1
  165. package/dist/chunk-6G35I3VW.cjs +0 -40
  166. package/dist/chunk-6G35I3VW.cjs.map +0 -1
  167. package/dist/chunk-6RMLO5O4.cjs.map +0 -1
  168. package/dist/chunk-7JGLPAFV.cjs.map +0 -1
  169. package/dist/chunk-CIINW6PS.cjs.map +0 -1
  170. package/dist/chunk-FLOI7QOT.cjs.map +0 -1
  171. package/dist/chunk-GKFWM3DS.js.map +0 -1
  172. package/dist/chunk-IJORSAC3.js.map +0 -1
  173. package/dist/chunk-M6OC455F.js +0 -65
  174. package/dist/chunk-M6OC455F.js.map +0 -1
  175. package/dist/chunk-MAQJYNJR.js.map +0 -1
  176. package/dist/chunk-MXE2U3EX.js.map +0 -1
  177. package/dist/chunk-RP7YITHX.cjs +0 -70
  178. package/dist/chunk-RP7YITHX.cjs.map +0 -1
  179. package/dist/chunk-RZ4DH4E7.cjs.map +0 -1
  180. package/dist/chunk-SAJSMR2B.js +0 -35
  181. package/dist/chunk-SAJSMR2B.js.map +0 -1
  182. package/dist/chunk-SFFJ2IKN.cjs.map +0 -1
  183. package/dist/chunk-STP7QVUB.js.map +0 -1
  184. package/dist/chunk-THX25XW6.js.map +0 -1
  185. package/dist/chunk-UIFEEPME.js.map +0 -1
  186. package/dist/chunk-V4IQYOQ4.cjs.map +0 -1
  187. package/dist/chunk-VZX2KSY3.js.map +0 -1
  188. package/dist/chunk-YQGLVWB2.cjs.map +0 -1
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunk54JVNOAQ_cjs = require('./chunk-54JVNOAQ.cjs');
4
- var chunkVMEWZU2N_cjs = require('./chunk-VMEWZU2N.cjs');
5
- var chunkRP7YITHX_cjs = require('./chunk-RP7YITHX.cjs');
6
- var chunkV4IQYOQ4_cjs = require('./chunk-V4IQYOQ4.cjs');
3
+ var chunk4RBAJVEC_cjs = require('./chunk-4RBAJVEC.cjs');
4
+ var chunkWWVV44DY_cjs = require('./chunk-WWVV44DY.cjs');
5
+ var chunkI4W7MKVG_cjs = require('./chunk-I4W7MKVG.cjs');
6
+ var chunkOIE2UPVG_cjs = require('./chunk-OIE2UPVG.cjs');
7
+ var chunkCFNT3ITG_cjs = require('./chunk-CFNT3ITG.cjs');
7
8
  var chunk73KASJGO_cjs = require('./chunk-73KASJGO.cjs');
8
9
  var chunkJIEJCTDS_cjs = require('./chunk-JIEJCTDS.cjs');
9
10
  var drizzleOrm = require('drizzle-orm');
@@ -21,6 +22,9 @@ var tsvector = pgCore.customType({
21
22
  var DEFAULT_TABLE_NAMES = {
22
23
  nodes: "typegraph_nodes",
23
24
  edges: "typegraph_edges",
25
+ recordedNodes: "typegraph_recorded_nodes",
26
+ recordedEdges: "typegraph_recorded_edges",
27
+ recordedClock: "typegraph_recorded_clock",
24
28
  uniques: "typegraph_node_uniques",
25
29
  schemaVersions: "typegraph_schema_versions",
26
30
  fulltext: "typegraph_node_fulltext",
@@ -57,7 +61,7 @@ function createPostgresTables(names = {}, options = {}) {
57
61
  ),
58
62
  pgCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
59
63
  pgCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
60
- ...chunkVMEWZU2N_cjs.buildPostgresNodeIndexBuilders(t, indexes)
64
+ ...chunkWWVV44DY_cjs.buildPostgresNodeIndexBuilders(t, indexes)
61
65
  ]
62
66
  );
63
67
  const edges2 = pgCore.pgTable(
@@ -116,9 +120,114 @@ function createPostgresTables(names = {}, options = {}) {
116
120
  t.fromId,
117
121
  t.validTo
118
122
  ),
119
- ...chunkVMEWZU2N_cjs.buildPostgresEdgeIndexBuilders(t, indexes)
123
+ ...chunkWWVV44DY_cjs.buildPostgresEdgeIndexBuilders(t, indexes)
120
124
  ]
121
125
  );
126
+ const recordedNodes2 = pgCore.pgTable(
127
+ n.recordedNodes,
128
+ {
129
+ historyId: pgCore.text("history_id").notNull(),
130
+ graphId: pgCore.text("graph_id").notNull(),
131
+ kind: pgCore.text("kind").notNull(),
132
+ id: pgCore.text("id").notNull(),
133
+ props: pgCore.jsonb("props").notNull(),
134
+ version: pgCore.integer("version").notNull(),
135
+ validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
136
+ validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
137
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
138
+ updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
139
+ deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true }),
140
+ recordedFrom: pgCore.timestamp("recorded_from", { withTimezone: true }).notNull(),
141
+ recordedTo: pgCore.timestamp("recorded_to", { withTimezone: true }).notNull(),
142
+ op: pgCore.text("op").notNull(),
143
+ schemaVersion: pgCore.integer("schema_version"),
144
+ txId: pgCore.text("tx_id"),
145
+ meta: pgCore.jsonb("meta")
146
+ },
147
+ (t) => [
148
+ pgCore.primaryKey({ columns: [t.historyId] }),
149
+ pgCore.index(`${n.recordedNodes}_entity_idx`).on(
150
+ t.graphId,
151
+ t.kind,
152
+ t.id,
153
+ t.recordedFrom,
154
+ t.recordedTo
155
+ ),
156
+ pgCore.index(`${n.recordedNodes}_open_idx`).on(t.graphId, t.recordedTo),
157
+ pgCore.index(`${n.recordedNodes}_valid_idx`).on(
158
+ t.graphId,
159
+ t.validFrom,
160
+ t.validTo
161
+ )
162
+ ]
163
+ );
164
+ const recordedEdges2 = pgCore.pgTable(
165
+ n.recordedEdges,
166
+ {
167
+ historyId: pgCore.text("history_id").notNull(),
168
+ graphId: pgCore.text("graph_id").notNull(),
169
+ id: pgCore.text("id").notNull(),
170
+ kind: pgCore.text("kind").notNull(),
171
+ fromKind: pgCore.text("from_kind").notNull(),
172
+ fromId: pgCore.text("from_id").notNull(),
173
+ toKind: pgCore.text("to_kind").notNull(),
174
+ toId: pgCore.text("to_id").notNull(),
175
+ props: pgCore.jsonb("props").notNull(),
176
+ validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
177
+ validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
178
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
179
+ updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
180
+ deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true }),
181
+ recordedFrom: pgCore.timestamp("recorded_from", { withTimezone: true }).notNull(),
182
+ recordedTo: pgCore.timestamp("recorded_to", { withTimezone: true }).notNull(),
183
+ op: pgCore.text("op").notNull(),
184
+ schemaVersion: pgCore.integer("schema_version"),
185
+ txId: pgCore.text("tx_id"),
186
+ meta: pgCore.jsonb("meta")
187
+ },
188
+ (t) => [
189
+ pgCore.primaryKey({ columns: [t.historyId] }),
190
+ pgCore.index(`${n.recordedEdges}_entity_idx`).on(
191
+ t.graphId,
192
+ t.kind,
193
+ t.id,
194
+ t.recordedFrom,
195
+ t.recordedTo
196
+ ),
197
+ pgCore.index(`${n.recordedEdges}_open_idx`).on(t.graphId, t.recordedTo),
198
+ pgCore.index(`${n.recordedEdges}_from_idx`).on(
199
+ t.graphId,
200
+ t.fromKind,
201
+ t.fromId,
202
+ t.kind,
203
+ t.toKind,
204
+ t.recordedFrom,
205
+ t.recordedTo
206
+ ),
207
+ pgCore.index(`${n.recordedEdges}_to_idx`).on(
208
+ t.graphId,
209
+ t.toKind,
210
+ t.toId,
211
+ t.kind,
212
+ t.fromKind,
213
+ t.recordedFrom,
214
+ t.recordedTo
215
+ ),
216
+ pgCore.index(`${n.recordedEdges}_valid_idx`).on(
217
+ t.graphId,
218
+ t.validFrom,
219
+ t.validTo
220
+ )
221
+ ]
222
+ );
223
+ const recordedClock2 = pgCore.pgTable(
224
+ n.recordedClock,
225
+ {
226
+ graphId: pgCore.text("graph_id").notNull(),
227
+ recordedAt: pgCore.timestamp("recorded_at", { withTimezone: true }).notNull()
228
+ },
229
+ (t) => [pgCore.primaryKey({ columns: [t.graphId] })]
230
+ );
122
231
  const uniques2 = pgCore.pgTable(
123
232
  n.uniques,
124
233
  {
@@ -242,6 +351,9 @@ function createPostgresTables(names = {}, options = {}) {
242
351
  return {
243
352
  nodes: nodes2,
244
353
  edges: edges2,
354
+ recordedNodes: recordedNodes2,
355
+ recordedEdges: recordedEdges2,
356
+ recordedClock: recordedClock2,
245
357
  uniques: uniques2,
246
358
  schemaVersions: schemaVersions2,
247
359
  indexMaterializations,
@@ -253,7 +365,16 @@ function createPostgresTables(names = {}, options = {}) {
253
365
  };
254
366
  }
255
367
  var tables2 = createPostgresTables();
256
- var { nodes, edges, uniques, schemaVersions, fulltext } = tables2;
368
+ var {
369
+ nodes,
370
+ edges,
371
+ recordedNodes,
372
+ recordedEdges,
373
+ recordedClock,
374
+ uniques,
375
+ schemaVersions,
376
+ fulltext
377
+ } = tables2;
257
378
  function getSqliteColumnType(column) {
258
379
  switch (column.columnType) {
259
380
  case "SQLiteText": {
@@ -309,9 +430,9 @@ function renderIndexColumn(col) {
309
430
  if (col && typeof col === "object" && "name" in col) {
310
431
  return `"${col.name}"`;
311
432
  }
312
- const sql12 = tryInlineSql(col);
313
- if (sql12 !== void 0) {
314
- return sql12;
433
+ const sql13 = tryInlineSql(col);
434
+ if (sql13 !== void 0) {
435
+ return sql13;
315
436
  }
316
437
  return "unknown";
317
438
  }
@@ -324,16 +445,16 @@ function tryInlineSql(value) {
324
445
  }
325
446
  return inlineSql(value);
326
447
  }
327
- function flattenSqlChunk(chunk) {
328
- if (typeof chunk === "string") {
329
- return chunk;
448
+ function flattenSqlChunk(chunk2) {
449
+ if (typeof chunk2 === "string") {
450
+ return chunk2;
330
451
  }
331
- if (typeof chunk === "object" && chunk !== null) {
332
- if ("name" in chunk && typeof chunk.name === "string") {
333
- return `"${chunk.name}"`;
452
+ if (typeof chunk2 === "object" && chunk2 !== null) {
453
+ if ("name" in chunk2 && typeof chunk2.name === "string") {
454
+ return `"${chunk2.name}"`;
334
455
  }
335
- if ("value" in chunk) {
336
- const value = chunk.value;
456
+ if ("value" in chunk2) {
457
+ const value = chunk2.value;
337
458
  if (typeof value === "string") {
338
459
  return value;
339
460
  }
@@ -341,17 +462,17 @@ function flattenSqlChunk(chunk) {
341
462
  return value.map((part) => flattenSqlChunk(part)).join("");
342
463
  }
343
464
  }
344
- if ("queryChunks" in chunk && Array.isArray(chunk.queryChunks)) {
345
- return chunk.queryChunks.map((part) => flattenSqlChunk(part)).join("");
465
+ if ("queryChunks" in chunk2 && Array.isArray(chunk2.queryChunks)) {
466
+ return chunk2.queryChunks.map((part) => flattenSqlChunk(part)).join("");
346
467
  }
347
- if ("getSQL" in chunk) {
348
- const maybe = chunk;
468
+ if ("getSQL" in chunk2) {
469
+ const maybe = chunk2;
349
470
  if (typeof maybe.getSQL === "function") {
350
471
  return flattenSqlChunk(maybe.getSQL());
351
472
  }
352
473
  }
353
474
  }
354
- throw new Error(`Unable to inline SQL chunk: ${String(chunk)}`);
475
+ throw new Error(`Unable to inline SQL chunk: ${String(chunk2)}`);
355
476
  }
356
477
  function inlineSql(value) {
357
478
  try {
@@ -387,13 +508,13 @@ function isSqliteTable(value) {
387
508
  function runtimeStrategyContributions(fulltextStrategy, fulltextTableName) {
388
509
  return fulltextStrategy.ownedTables(fulltextTableName).filter((contribution) => contribution.runtimeEnsure);
389
510
  }
390
- function sqliteContributions(tables3 = chunk54JVNOAQ_cjs.tables, fulltextStrategy = chunkV4IQYOQ4_cjs.fts5Strategy) {
511
+ function sqliteContributions(tables3 = chunk4RBAJVEC_cjs.tables, fulltextStrategy = chunkCFNT3ITG_cjs.fts5Strategy) {
391
512
  const contributions = [];
392
513
  for (const [key, table] of Object.entries(tables3)) {
393
514
  if (!isSqliteTable(table)) continue;
394
515
  contributions.push({
395
516
  logicalName: key,
396
- owner: chunkV4IQYOQ4_cjs.BASE_CONTRIBUTION_OWNER,
517
+ owner: chunkCFNT3ITG_cjs.BASE_CONTRIBUTION_OWNER,
397
518
  tableName: sqliteCore.getTableConfig(table).name,
398
519
  createDdl: [
399
520
  generateSqliteCreateTableSQL(table),
@@ -409,12 +530,12 @@ function sqliteContributions(tables3 = chunk54JVNOAQ_cjs.tables, fulltextStrateg
409
530
  }
410
531
  return contributions;
411
532
  }
412
- function generateSqliteDDL(tables3 = chunk54JVNOAQ_cjs.tables, fulltextStrategy = chunkV4IQYOQ4_cjs.fts5Strategy) {
533
+ function generateSqliteDDL(tables3 = chunk4RBAJVEC_cjs.tables, fulltextStrategy = chunkCFNT3ITG_cjs.fts5Strategy) {
413
534
  return sqliteContributions(tables3, fulltextStrategy).flatMap(
414
535
  (contribution) => [...contribution.createDdl]
415
536
  );
416
537
  }
417
- function generateSqliteMigrationSQL(tables3 = chunk54JVNOAQ_cjs.tables, fulltextStrategy = chunkV4IQYOQ4_cjs.fts5Strategy) {
538
+ function generateSqliteMigrationSQL(tables3 = chunk4RBAJVEC_cjs.tables, fulltextStrategy = chunkCFNT3ITG_cjs.fts5Strategy) {
418
539
  return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
419
540
  }
420
541
  function getPgColumnType(column) {
@@ -496,14 +617,14 @@ function generatePgCreateIndexSQL(table) {
496
617
  function isPgTable(value) {
497
618
  return drizzleOrm.is(value, pgCore.PgTable);
498
619
  }
499
- function postgresContributions(tables3 = tables2, fulltextStrategy = chunkV4IQYOQ4_cjs.tsvectorStrategy) {
620
+ function postgresContributions(tables3 = tables2, fulltextStrategy = chunkCFNT3ITG_cjs.tsvectorStrategy) {
500
621
  const contributions = [];
501
622
  for (const [key, table] of Object.entries(tables3)) {
502
623
  if (!isPgTable(table)) continue;
503
624
  if (table === tables3.fulltext) continue;
504
625
  contributions.push({
505
626
  logicalName: key,
506
- owner: chunkV4IQYOQ4_cjs.BASE_CONTRIBUTION_OWNER,
627
+ owner: chunkCFNT3ITG_cjs.BASE_CONTRIBUTION_OWNER,
507
628
  tableName: pgCore.getTableConfig(table).name,
508
629
  createDdl: [
509
630
  generatePgCreateTableSQL(table),
@@ -519,12 +640,12 @@ function postgresContributions(tables3 = tables2, fulltextStrategy = chunkV4IQYO
519
640
  }
520
641
  return contributions;
521
642
  }
522
- function generatePostgresDDL(tables3 = tables2, fulltextStrategy = chunkV4IQYOQ4_cjs.tsvectorStrategy) {
643
+ function generatePostgresDDL(tables3 = tables2, fulltextStrategy = chunkCFNT3ITG_cjs.tsvectorStrategy) {
523
644
  return postgresContributions(tables3, fulltextStrategy).flatMap(
524
645
  (contribution) => [...contribution.createDdl]
525
646
  );
526
647
  }
527
- function generatePostgresMigrationSQL(tables3 = tables2, fulltextStrategy = chunkV4IQYOQ4_cjs.tsvectorStrategy) {
648
+ function generatePostgresMigrationSQL(tables3 = tables2, fulltextStrategy = chunkCFNT3ITG_cjs.tsvectorStrategy) {
528
649
  const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
529
650
  const ddlSql = generatePostgresDDL(tables3, fulltextStrategy).join("\n\n");
530
651
  return `${extensionSql}
@@ -594,7 +715,7 @@ function vectorSlotFromDropIndexParams(params) {
594
715
  };
595
716
  }
596
717
  function mapVectorWriteError(error, params) {
597
- const mismatch = chunkRP7YITHX_cjs.parseDimensionMismatch(error);
718
+ const mismatch = chunkOIE2UPVG_cjs.parseDimensionMismatch(error);
598
719
  if (mismatch === void 0) return error;
599
720
  const attempted = mismatch.actual ?? "a different number of";
600
721
  return new chunkJIEJCTDS_cjs.EmbeddingDimensionChangedError(
@@ -608,152 +729,12 @@ function mapVectorWriteError(error, params) {
608
729
  { cause: error }
609
730
  );
610
731
  }
611
-
612
- // src/backend/drizzle/row-mappers.ts
613
- function requireTimestamp(value, field) {
614
- if (value === void 0) {
615
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
616
- `Expected non-null ${field} timestamp`,
617
- { operation: "select", entity: "row" }
618
- );
619
- }
620
- return value;
621
- }
622
- function asString(value, field) {
623
- if (typeof value !== "string") {
624
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
625
- `Expected ${field} to be string, got ${typeof value}`,
626
- { operation: "select", entity: "row" }
627
- );
628
- }
629
- return value;
630
- }
631
- function asNumber(value, field) {
632
- if (typeof value !== "number") {
633
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
634
- `Expected ${field} to be number, got ${typeof value}`,
635
- { operation: "select", entity: "row" }
636
- );
637
- }
638
- return value;
639
- }
640
- function nowIso() {
641
- return (/* @__PURE__ */ new Date()).toISOString();
642
- }
643
- function nullToUndefined(value) {
644
- return value ?? void 0;
645
- }
646
- function formatPostgresTimestamp(value) {
647
- if (value === null || value === void 0) return void 0;
648
- if (value instanceof Date) return value.toISOString();
649
- if (typeof value === "string") {
650
- if (value.includes("T")) return value;
651
- const date = new Date(value);
652
- if (!Number.isNaN(date.getTime())) return date.toISOString();
653
- return value;
654
- }
655
- return void 0;
656
- }
657
- function coerceNumericScore(value) {
658
- if (typeof value === "number") return value;
659
- const parsed = Number.parseFloat(value);
660
- if (Number.isNaN(parsed)) {
661
- throw new TypeError(
662
- `Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`
663
- );
664
- }
665
- return parsed;
666
- }
667
- function normalizeJsonColumn(value) {
668
- return typeof value === "string" ? value : JSON.stringify(value ?? {});
669
- }
670
- var SQLITE_ROW_MAPPER_CONFIG = {
671
- formatTimestamp: (value) => {
672
- if (value === null || value === void 0) return;
673
- if (typeof value !== "string") {
674
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
675
- `Expected timestamp to be string, got ${typeof value}`,
676
- { operation: "select", entity: "row" }
677
- );
678
- }
679
- return value;
680
- },
681
- normalizeJson: (value) => {
682
- if (typeof value !== "string") {
683
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
684
- `Expected JSON column to be string, got ${typeof value}`,
685
- { operation: "select", entity: "row" }
686
- );
687
- }
688
- return value;
689
- }
690
- };
691
- var POSTGRES_ROW_MAPPER_CONFIG = {
692
- formatTimestamp: formatPostgresTimestamp,
693
- normalizeJson: normalizeJsonColumn
694
- };
695
- function createNodeRowMapper(config) {
696
- return (row) => ({
697
- graph_id: asString(row.graph_id, "graph_id"),
698
- kind: asString(row.kind, "kind"),
699
- id: asString(row.id, "id"),
700
- props: config.normalizeJson(row.props),
701
- version: asNumber(row.version, "version"),
702
- valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
703
- valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
704
- created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
705
- updated_at: requireTimestamp(config.formatTimestamp(row.updated_at), "updated_at"),
706
- deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
707
- });
708
- }
709
- function createEdgeRowMapper(config) {
710
- return (row) => ({
711
- graph_id: asString(row.graph_id, "graph_id"),
712
- id: asString(row.id, "id"),
713
- kind: asString(row.kind, "kind"),
714
- from_kind: asString(row.from_kind, "from_kind"),
715
- from_id: asString(row.from_id, "from_id"),
716
- to_kind: asString(row.to_kind, "to_kind"),
717
- to_id: asString(row.to_id, "to_id"),
718
- props: config.normalizeJson(row.props),
719
- valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
720
- valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
721
- created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
722
- updated_at: requireTimestamp(config.formatTimestamp(row.updated_at), "updated_at"),
723
- deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
724
- });
725
- }
726
- function createUniqueRowMapper(config) {
727
- return (row) => ({
728
- graph_id: asString(row.graph_id, "graph_id"),
729
- node_kind: asString(row.node_kind, "node_kind"),
730
- constraint_name: asString(row.constraint_name, "constraint_name"),
731
- key: asString(row.key, "key"),
732
- node_id: asString(row.node_id, "node_id"),
733
- concrete_kind: asString(row.concrete_kind, "concrete_kind"),
734
- deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
735
- });
736
- }
737
- function createSchemaVersionRowMapper(config) {
738
- return (row) => {
739
- const isActiveValue = row.is_active;
740
- const isActive = isActiveValue === true || isActiveValue === 1 || isActiveValue === "1";
741
- return {
742
- graph_id: asString(row.graph_id, "graph_id"),
743
- version: asNumber(row.version, "version"),
744
- schema_hash: asString(row.schema_hash, "schema_hash"),
745
- schema_doc: config.normalizeJson(row.schema_doc),
746
- created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
747
- is_active: isActive
748
- };
749
- };
750
- }
751
732
  var SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = {
752
733
  decode: (value) => typeof value === "string" ? value : void 0,
753
734
  encode: (value) => value
754
735
  };
755
736
  var POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS = {
756
- decode: formatPostgresTimestamp,
737
+ decode: chunkI4W7MKVG_cjs.formatPostgresTimestamp,
757
738
  encode: (value) => new Date(value)
758
739
  };
759
740
  function mapContributionMaterializationRow(row, decode) {
@@ -803,7 +784,7 @@ async function computeContributionSignature(dialect, identity, createDdl) {
803
784
  tableName: identity.tableName,
804
785
  createDdl
805
786
  };
806
- return chunk73KASJGO_cjs.sha256Hex(JSON.stringify(hashable, chunkRP7YITHX_cjs.sortedReplacer), 16);
787
+ return chunk73KASJGO_cjs.sha256Hex(JSON.stringify(hashable, chunkOIE2UPVG_cjs.sortedReplacer), 16);
807
788
  }
808
789
  function evaluateContributionState(row, signature) {
809
790
  if (row === void 0) return "missing";
@@ -823,21 +804,21 @@ function identityOf(graphId, contribution) {
823
804
  function gateFulltextMethods(source, assert) {
824
805
  const gated = {};
825
806
  if (source.upsertFulltext) {
826
- const raw = source.upsertFulltext;
807
+ const raw = source.upsertFulltext.bind(source);
827
808
  gated.upsertFulltext = async (params) => {
828
809
  await assert(params.graphId);
829
810
  await raw(params);
830
811
  };
831
812
  }
832
813
  if (source.deleteFulltext) {
833
- const raw = source.deleteFulltext;
814
+ const raw = source.deleteFulltext.bind(source);
834
815
  gated.deleteFulltext = async (params) => {
835
816
  await assert(params.graphId);
836
817
  await raw(params);
837
818
  };
838
819
  }
839
820
  if (source.upsertFulltextBatch) {
840
- const raw = source.upsertFulltextBatch;
821
+ const raw = source.upsertFulltextBatch.bind(source);
841
822
  gated.upsertFulltextBatch = async (params) => {
842
823
  if (params.rows.length === 0) return;
843
824
  await assert(params.graphId);
@@ -845,7 +826,7 @@ function gateFulltextMethods(source, assert) {
845
826
  };
846
827
  }
847
828
  if (source.deleteFulltextBatch) {
848
- const raw = source.deleteFulltextBatch;
829
+ const raw = source.deleteFulltextBatch.bind(source);
849
830
  gated.deleteFulltextBatch = async (params) => {
850
831
  if (params.nodeIds.length === 0) return;
851
832
  await assert(params.graphId);
@@ -853,13 +834,13 @@ function gateFulltextMethods(source, assert) {
853
834
  };
854
835
  }
855
836
  if (source.fulltextSearch) {
856
- const raw = source.fulltextSearch;
837
+ const raw = source.fulltextSearch.bind(source);
857
838
  gated.fulltextSearch = async (params) => {
858
839
  await assert(params.graphId);
859
840
  return raw(params);
860
841
  };
861
842
  }
862
- const rawHardDelete = source.hardDeleteNode;
843
+ const rawHardDelete = source.hardDeleteNode.bind(source);
863
844
  gated.hardDeleteNode = async (params) => {
864
845
  await assert(params.graphId);
865
846
  await rawHardDelete(params);
@@ -867,7 +848,10 @@ function gateFulltextMethods(source, assert) {
867
848
  return gated;
868
849
  }
869
850
  function gateFulltext(tx, assert) {
870
- return { ...tx, ...gateFulltextMethods(tx, assert) };
851
+ return chunkI4W7MKVG_cjs.createBackendOverlay(
852
+ tx,
853
+ gateFulltextMethods(tx, assert)
854
+ );
871
855
  }
872
856
  function createContributionMaterializer(deps) {
873
857
  const { dialect, fulltextStrategy, fulltextTableName } = deps;
@@ -894,13 +878,13 @@ function createContributionMaterializer(deps) {
894
878
  await deps.recordMarker({
895
879
  ...identity,
896
880
  signature,
897
- attemptedAt: nowIso(),
881
+ attemptedAt: chunkI4W7MKVG_cjs.nowIso(),
898
882
  materializedAt: void 0,
899
883
  error: error.message
900
884
  });
901
885
  throw error;
902
886
  }
903
- const attemptedAt = nowIso();
887
+ const attemptedAt = chunkI4W7MKVG_cjs.nowIso();
904
888
  try {
905
889
  for (const statement of contribution.createDdl) {
906
890
  await deps.execDdl(statement);
@@ -937,7 +921,7 @@ function createContributionMaterializer(deps) {
937
921
  state: evaluateContributionState(existing, signature)
938
922
  };
939
923
  } catch (error) {
940
- if (!chunkRP7YITHX_cjs.isMissingTableError(error)) throw error;
924
+ if (!chunkOIE2UPVG_cjs.isMissingTableError(error)) throw error;
941
925
  return { kind: "missing-table", error };
942
926
  }
943
927
  }
@@ -986,7 +970,7 @@ var SQLITE_INDEX_MAT_TIMESTAMPS = {
986
970
  encode: (value) => value
987
971
  };
988
972
  var POSTGRES_INDEX_MAT_TIMESTAMPS = {
989
- decode: formatPostgresTimestamp,
973
+ decode: chunkI4W7MKVG_cjs.formatPostgresTimestamp,
990
974
  encode: (value) => new Date(value)
991
975
  };
992
976
  function mapMaterializationRow(row, decode) {
@@ -1039,7 +1023,7 @@ var SQLITE_KIND_REMOVAL_TIMESTAMPS = {
1039
1023
  encode: (value) => value
1040
1024
  };
1041
1025
  var POSTGRES_KIND_REMOVAL_TIMESTAMPS = {
1042
- decode: formatPostgresTimestamp,
1026
+ decode: chunkI4W7MKVG_cjs.formatPostgresTimestamp,
1043
1027
  encode: (value) => new Date(value)
1044
1028
  };
1045
1029
  function mapKindRemovalRow(row, decode) {
@@ -1080,397 +1064,46 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
1080
1064
  lastError: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_error")}`
1081
1065
  };
1082
1066
  }
1083
- function assertAdoptedDialect(externalTx, brand, backend) {
1084
- if (drizzleOrm.is(externalTx, brand)) return;
1085
- const label = backend === "postgres" ? "Postgres" : "SQLite";
1086
- throw new chunkJIEJCTDS_cjs.ConfigurationError(
1087
- `adoptTransaction received a handle that is not a ${label} Drizzle transaction. Pass the \`tx\` from a ${label} \`db.transaction(...)\` opened on this backend's connection.`,
1088
- { backend, capability: "adoptTransaction" }
1089
- );
1090
- }
1091
- function chunkArray(values, size) {
1092
- if (values.length <= size) {
1093
- return [values];
1094
- }
1095
- const chunks = [];
1096
- for (let index2 = 0; index2 < values.length; index2 += size) {
1097
- chunks.push(values.slice(index2, index2 + size));
1098
- }
1099
- return chunks;
1100
- }
1101
- function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
1102
- const expectedVersion = expected.kind === "active" ? expected.version : 0;
1103
- if (actualActiveVersion !== expectedVersion) {
1104
- throw new chunkJIEJCTDS_cjs.StaleVersionError({
1105
- graphId,
1106
- expected: expectedVersion,
1107
- actual: actualActiveVersion
1108
- });
1109
- }
1110
- }
1111
- function createCommonOperationBackend(options) {
1112
- const { batchConfig, execution, operationStrategy, rowMappers } = options;
1113
- const nowIso2 = options.nowIso ?? nowIso;
1114
- async function readActiveVersion(graphId) {
1115
- const row = await execution.execGet(
1116
- operationStrategy.buildGetActiveSchema(graphId)
1117
- );
1118
- return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
1119
- }
1120
- return {
1121
- async insertNode(params) {
1122
- const timestamp2 = nowIso2();
1123
- const query = operationStrategy.buildInsertNode(params, timestamp2);
1124
- const row = await execution.execGet(query);
1125
- if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
1126
- return rowMappers.toNodeRow(row);
1127
- },
1128
- async insertNodeNoReturn(params) {
1129
- const timestamp2 = nowIso2();
1130
- const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
1131
- await execution.execRun(query);
1132
- },
1133
- async insertNodesBatch(params) {
1134
- if (params.length === 0) {
1135
- return;
1136
- }
1137
- const timestamp2 = nowIso2();
1138
- for (const chunk of chunkArray(params, batchConfig.nodeInsertBatchSize)) {
1139
- const query = operationStrategy.buildInsertNodesBatch(chunk, timestamp2);
1140
- await execution.execRun(query);
1141
- }
1142
- },
1143
- async insertNodesBatchReturning(params) {
1144
- if (params.length === 0) {
1145
- return [];
1146
- }
1147
- const timestamp2 = nowIso2();
1148
- const allRows = [];
1149
- for (const chunk of chunkArray(params, batchConfig.nodeInsertBatchSize)) {
1150
- const query = operationStrategy.buildInsertNodesBatchReturning(chunk, timestamp2);
1151
- const rows = await execution.execAll(query);
1152
- allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
1153
- }
1154
- return allRows;
1155
- },
1156
- async getNode(graphId, kind, id) {
1157
- const query = operationStrategy.buildGetNode(graphId, kind, id);
1158
- const row = await execution.execGet(query);
1159
- return row ? rowMappers.toNodeRow(row) : void 0;
1160
- },
1161
- async getNodes(graphId, kind, ids) {
1162
- if (ids.length === 0) return [];
1163
- const allRows = [];
1164
- for (const chunk of chunkArray(ids, batchConfig.getNodesChunkSize)) {
1165
- const query = operationStrategy.buildGetNodes(graphId, kind, chunk);
1166
- const rows = await execution.execAll(query);
1167
- allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
1168
- }
1169
- return allRows;
1067
+ function buildClearGraph(tables3, graphId) {
1068
+ const fulltext2 = chunkCFNT3ITG_cjs.quotedTableName(tables3.fulltextTableName);
1069
+ return [
1070
+ { query: drizzleOrm.sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}` },
1071
+ {
1072
+ query: drizzleOrm.sql`DELETE FROM ${tables3.recordedEdges} WHERE ${tables3.recordedEdges.graphId} = ${graphId}`,
1073
+ ignoreMissingTable: true,
1074
+ requiredTableName: drizzleOrm.getTableName(tables3.recordedEdges)
1170
1075
  },
1171
- async updateNode(params) {
1172
- const timestamp2 = nowIso2();
1173
- const query = operationStrategy.buildUpdateNode(params, timestamp2);
1174
- const row = await execution.execGet(query);
1175
- if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
1176
- return rowMappers.toNodeRow(row);
1076
+ {
1077
+ query: drizzleOrm.sql`DELETE FROM ${tables3.recordedNodes} WHERE ${tables3.recordedNodes.graphId} = ${graphId}`,
1078
+ ignoreMissingTable: true,
1079
+ requiredTableName: drizzleOrm.getTableName(tables3.recordedNodes)
1177
1080
  },
1178
- async deleteNode(params) {
1179
- const timestamp2 = nowIso2();
1180
- const query = operationStrategy.buildDeleteNode(params, timestamp2);
1181
- await execution.execRun(query);
1081
+ {
1082
+ query: drizzleOrm.sql`DELETE FROM ${tables3.recordedClock} WHERE ${tables3.recordedClock.graphId} = ${graphId}`,
1083
+ ignoreMissingTable: true,
1084
+ requiredTableName: drizzleOrm.getTableName(tables3.recordedClock)
1182
1085
  },
1183
- // IMPORTANT: This cascade is not atomic. Callers must ensure this runs
1184
- // within a transaction to prevent partial deletion on intermediate failure.
1185
- //
1186
- // Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
1187
- // fieldPath)` strategy-owned tables addressable only with the slot
1188
- // context the graph-agnostic backend lacks. The store's hard-delete
1189
- // path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
1190
- // resolves each embedding field and routes a per-field
1191
- // `backend.deleteEmbedding` through the active vector strategy.
1192
- async hardDeleteNode(params) {
1193
- const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
1194
- params.graphId,
1195
- params.id
1196
- );
1197
- await execution.execRun(deleteUniquesQuery);
1198
- const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
1199
- params.graphId,
1200
- params.kind,
1201
- params.id
1202
- );
1203
- for (const stmt of deleteFulltextStatements) {
1204
- await execution.execRun(stmt);
1205
- }
1206
- const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
1207
- params.graphId,
1208
- params.kind,
1209
- params.id
1210
- );
1211
- await execution.execRun(deleteEdgesQuery);
1212
- const query = operationStrategy.buildHardDeleteNode(params);
1213
- await execution.execRun(query);
1086
+ {
1087
+ query: drizzleOrm.sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`
1214
1088
  },
1215
- async insertEdge(params) {
1216
- const timestamp2 = nowIso2();
1217
- const query = operationStrategy.buildInsertEdge(params, timestamp2);
1218
- const row = await execution.execGet(query);
1219
- if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
1220
- return rowMappers.toEdgeRow(row);
1089
+ {
1090
+ query: drizzleOrm.sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`
1221
1091
  },
1222
- async insertEdgeNoReturn(params) {
1223
- const timestamp2 = nowIso2();
1224
- const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
1225
- await execution.execRun(query);
1092
+ {
1093
+ query: drizzleOrm.sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`
1226
1094
  },
1227
- async insertEdgesBatch(params) {
1228
- if (params.length === 0) {
1229
- return;
1230
- }
1231
- const timestamp2 = nowIso2();
1232
- for (const chunk of chunkArray(params, batchConfig.edgeInsertBatchSize)) {
1233
- const query = operationStrategy.buildInsertEdgesBatch(chunk, timestamp2);
1234
- await execution.execRun(query);
1235
- }
1095
+ {
1096
+ query: drizzleOrm.sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`
1236
1097
  },
1237
- async insertEdgesBatchReturning(params) {
1238
- if (params.length === 0) {
1239
- return [];
1240
- }
1241
- const timestamp2 = nowIso2();
1242
- const allRows = [];
1243
- for (const chunk of chunkArray(params, batchConfig.edgeInsertBatchSize)) {
1244
- const query = operationStrategy.buildInsertEdgesBatchReturning(chunk, timestamp2);
1245
- const rows = await execution.execAll(query);
1246
- allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
1247
- }
1248
- return allRows;
1098
+ {
1099
+ query: drizzleOrm.sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`
1249
1100
  },
1250
- async getEdge(graphId, id) {
1251
- const query = operationStrategy.buildGetEdge(graphId, id);
1252
- const row = await execution.execGet(query);
1253
- return row ? rowMappers.toEdgeRow(row) : void 0;
1101
+ {
1102
+ query: drizzleOrm.sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
1254
1103
  },
1255
- async getEdges(graphId, ids) {
1256
- if (ids.length === 0) return [];
1257
- const allRows = [];
1258
- for (const chunk of chunkArray(ids, batchConfig.getEdgesChunkSize)) {
1259
- const query = operationStrategy.buildGetEdges(graphId, chunk);
1260
- const rows = await execution.execAll(query);
1261
- allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
1262
- }
1263
- return allRows;
1264
- },
1265
- async updateEdge(params) {
1266
- const timestamp2 = nowIso2();
1267
- const query = operationStrategy.buildUpdateEdge(params, timestamp2);
1268
- const row = await execution.execGet(query);
1269
- if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
1270
- return rowMappers.toEdgeRow(row);
1271
- },
1272
- async deleteEdge(params) {
1273
- const timestamp2 = nowIso2();
1274
- const query = operationStrategy.buildDeleteEdge(params, timestamp2);
1275
- await execution.execRun(query);
1276
- },
1277
- async hardDeleteEdge(params) {
1278
- const query = operationStrategy.buildHardDeleteEdge(params);
1279
- await execution.execRun(query);
1280
- },
1281
- async countEdgesFrom(params) {
1282
- const query = operationStrategy.buildCountEdgesFrom(params);
1283
- const row = await execution.execGet(query);
1284
- return Number(row?.count ?? 0);
1285
- },
1286
- async edgeExistsBetween(params) {
1287
- const query = operationStrategy.buildEdgeExistsBetween(params);
1288
- const row = await execution.execGet(query);
1289
- return row !== void 0;
1290
- },
1291
- async findEdgesConnectedTo(params) {
1292
- const query = operationStrategy.buildFindEdgesConnectedTo(params);
1293
- const rows = await execution.execAll(query);
1294
- return rows.map((row) => rowMappers.toEdgeRow(row));
1295
- },
1296
- async findNodesByKind(params) {
1297
- const query = operationStrategy.buildFindNodesByKind(params);
1298
- const rows = await execution.execAll(query);
1299
- return rows.map((row) => rowMappers.toNodeRow(row));
1300
- },
1301
- async countNodesByKind(params) {
1302
- const query = operationStrategy.buildCountNodesByKind(params);
1303
- const row = await execution.execGet(query);
1304
- return Number(row?.count ?? 0);
1305
- },
1306
- async findEdgesByKind(params) {
1307
- const query = operationStrategy.buildFindEdgesByKind(params);
1308
- const rows = await execution.execAll(query);
1309
- return rows.map((row) => rowMappers.toEdgeRow(row));
1310
- },
1311
- async countEdgesByKind(params) {
1312
- const query = operationStrategy.buildCountEdgesByKind(params);
1313
- const row = await execution.execGet(query);
1314
- return Number(row?.count ?? 0);
1315
- },
1316
- async insertUnique(params) {
1317
- const query = operationStrategy.buildInsertUnique(params);
1318
- const result = await execution.execGet(query);
1319
- if (result && result.node_id !== params.nodeId) {
1320
- throw new chunkJIEJCTDS_cjs.UniquenessError({
1321
- constraintName: params.constraintName,
1322
- kind: params.nodeKind,
1323
- existingId: result.node_id,
1324
- newId: params.nodeId,
1325
- fields: []
1326
- });
1327
- }
1328
- },
1329
- async deleteUnique(params) {
1330
- const timestamp2 = nowIso2();
1331
- const query = operationStrategy.buildDeleteUnique(params, timestamp2);
1332
- await execution.execRun(query);
1333
- },
1334
- async checkUnique(params) {
1335
- const query = operationStrategy.buildCheckUnique(params);
1336
- const row = await execution.execGet(query);
1337
- return row ? rowMappers.toUniqueRow(row) : void 0;
1338
- },
1339
- async checkUniqueBatch(params) {
1340
- if (params.keys.length === 0) return [];
1341
- const allRows = [];
1342
- for (const chunk of chunkArray(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
1343
- const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk });
1344
- const rows = await execution.execAll(query);
1345
- allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
1346
- }
1347
- return allRows;
1348
- },
1349
- async getActiveSchema(graphId) {
1350
- const query = operationStrategy.buildGetActiveSchema(graphId);
1351
- const row = await execution.execGet(query);
1352
- return row ? rowMappers.toSchemaVersionRow(row) : void 0;
1353
- },
1354
- async getSchemaVersion(graphId, version) {
1355
- const query = operationStrategy.buildGetSchemaVersion(graphId, version);
1356
- const row = await execution.execGet(query);
1357
- return row ? rowMappers.toSchemaVersionRow(row) : void 0;
1358
- },
1359
- async commitSchemaVersion(params) {
1360
- const existingRaw = await execution.execGet(
1361
- operationStrategy.buildGetSchemaVersion(
1362
- params.graphId,
1363
- params.version
1364
- )
1365
- );
1366
- const actualActiveVersion = await readActiveVersion(params.graphId);
1367
- if (existingRaw !== void 0) {
1368
- const existing = rowMappers.toSchemaVersionRow(existingRaw);
1369
- if (existing.schema_hash !== params.schemaHash) {
1370
- throw new chunkJIEJCTDS_cjs.SchemaContentConflictError({
1371
- graphId: params.graphId,
1372
- version: params.version,
1373
- existingHash: existing.schema_hash,
1374
- incomingHash: params.schemaHash
1375
- });
1376
- }
1377
- if (existing.is_active) {
1378
- return existing;
1379
- }
1380
- verifyExpectedActiveVersion(
1381
- params.graphId,
1382
- params.expected,
1383
- actualActiveVersion
1384
- );
1385
- const reactivate = operationStrategy.buildSetActiveSchema(
1386
- params.graphId,
1387
- params.version
1388
- );
1389
- await execution.execRun(reactivate.deactivateAll);
1390
- await execution.execRun(reactivate.activateVersion);
1391
- return { ...existing, is_active: true };
1392
- }
1393
- verifyExpectedActiveVersion(
1394
- params.graphId,
1395
- params.expected,
1396
- actualActiveVersion
1397
- );
1398
- if (params.expected.kind === "active") {
1399
- const flip = operationStrategy.buildSetActiveSchema(
1400
- params.graphId,
1401
- params.version
1402
- );
1403
- await execution.execRun(flip.deactivateAll);
1404
- }
1405
- const timestamp2 = nowIso2();
1406
- const insertQuery = operationStrategy.buildInsertSchema(
1407
- {
1408
- graphId: params.graphId,
1409
- version: params.version,
1410
- schemaHash: params.schemaHash,
1411
- schemaDoc: params.schemaDoc,
1412
- isActive: true
1413
- },
1414
- timestamp2
1415
- );
1416
- const insertedRaw = await execution.execGet(insertQuery);
1417
- if (!insertedRaw) {
1418
- throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
1419
- "Insert schema failed: no row returned",
1420
- { operation: "insert", entity: "schema" }
1421
- );
1422
- }
1423
- return rowMappers.toSchemaVersionRow(insertedRaw);
1424
- },
1425
- async setActiveVersion(params) {
1426
- const actualActiveVersion = await readActiveVersion(params.graphId);
1427
- verifyExpectedActiveVersion(
1428
- params.graphId,
1429
- params.expected,
1430
- actualActiveVersion
1431
- );
1432
- const targetRaw = await execution.execGet(
1433
- operationStrategy.buildGetSchemaVersion(
1434
- params.graphId,
1435
- params.version
1436
- )
1437
- );
1438
- if (!targetRaw) {
1439
- throw new chunkJIEJCTDS_cjs.MigrationError(
1440
- `Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
1441
- {
1442
- graphId: params.graphId,
1443
- fromVersion: actualActiveVersion,
1444
- toVersion: params.version
1445
- }
1446
- );
1447
- }
1448
- const queries = operationStrategy.buildSetActiveSchema(
1449
- params.graphId,
1450
- params.version
1451
- );
1452
- await execution.execRun(queries.deactivateAll);
1453
- await execution.execRun(queries.activateVersion);
1454
- },
1455
- async clearGraph(graphId) {
1456
- const statements = operationStrategy.buildClearGraph(graphId);
1457
- for (const statement of statements) {
1458
- await execution.execRun(statement);
1459
- }
1104
+ {
1105
+ query: drizzleOrm.sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
1460
1106
  }
1461
- };
1462
- }
1463
- function buildClearGraph(tables3, graphId) {
1464
- const fulltext2 = chunkV4IQYOQ4_cjs.quotedTableName(tables3.fulltextTableName);
1465
- return [
1466
- drizzleOrm.sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}`,
1467
- drizzleOrm.sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
1468
- drizzleOrm.sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
1469
- drizzleOrm.sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`,
1470
- drizzleOrm.sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`,
1471
- drizzleOrm.sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`,
1472
- drizzleOrm.sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`,
1473
- drizzleOrm.sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
1474
1107
  ];
1475
1108
  }
1476
1109
  function buildTemporalConditions(table, params) {
@@ -1614,13 +1247,13 @@ function buildCountEdgesByKind(tables3, params) {
1614
1247
  function buildInsertEdge(tables3, params, timestamp2) {
1615
1248
  const { edges: edges2 } = tables3;
1616
1249
  const propsJson = JSON.stringify(params.props);
1617
- const columns = chunkV4IQYOQ4_cjs.edgeColumnList(edges2);
1250
+ const columns = chunkCFNT3ITG_cjs.edgeColumnList(edges2);
1618
1251
  return drizzleOrm.sql`
1619
1252
  INSERT INTO ${edges2} (${columns})
1620
1253
  VALUES (
1621
1254
  ${params.graphId}, ${params.id}, ${params.kind},
1622
1255
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1623
- ${propsJson}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validTo)},
1256
+ ${propsJson}, ${chunkCFNT3ITG_cjs.sqlNull(params.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(params.validTo)},
1624
1257
  ${timestamp2}, ${timestamp2}
1625
1258
  )
1626
1259
  RETURNING *
@@ -1629,23 +1262,23 @@ function buildInsertEdge(tables3, params, timestamp2) {
1629
1262
  function buildInsertEdgeNoReturn(tables3, params, timestamp2) {
1630
1263
  const { edges: edges2 } = tables3;
1631
1264
  const propsJson = JSON.stringify(params.props);
1632
- const columns = chunkV4IQYOQ4_cjs.edgeColumnList(edges2);
1265
+ const columns = chunkCFNT3ITG_cjs.edgeColumnList(edges2);
1633
1266
  return drizzleOrm.sql`
1634
1267
  INSERT INTO ${edges2} (${columns})
1635
1268
  VALUES (
1636
1269
  ${params.graphId}, ${params.id}, ${params.kind},
1637
1270
  ${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
1638
- ${propsJson}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validTo)},
1271
+ ${propsJson}, ${chunkCFNT3ITG_cjs.sqlNull(params.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(params.validTo)},
1639
1272
  ${timestamp2}, ${timestamp2}
1640
1273
  )
1641
1274
  `;
1642
1275
  }
1643
1276
  function buildInsertEdgesBatch(tables3, params, timestamp2) {
1644
1277
  const { edges: edges2 } = tables3;
1645
- const columns = chunkV4IQYOQ4_cjs.edgeColumnList(edges2);
1278
+ const columns = chunkCFNT3ITG_cjs.edgeColumnList(edges2);
1646
1279
  const values = params.map((edgeParams) => {
1647
1280
  const propsJson = JSON.stringify(edgeParams.props);
1648
- return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkV4IQYOQ4_cjs.sqlNull(edgeParams.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1281
+ return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkCFNT3ITG_cjs.sqlNull(edgeParams.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1649
1282
  });
1650
1283
  return drizzleOrm.sql`
1651
1284
  INSERT INTO ${edges2} (${columns})
@@ -1654,10 +1287,10 @@ function buildInsertEdgesBatch(tables3, params, timestamp2) {
1654
1287
  }
1655
1288
  function buildInsertEdgesBatchReturning(tables3, params, timestamp2) {
1656
1289
  const { edges: edges2 } = tables3;
1657
- const columns = chunkV4IQYOQ4_cjs.edgeColumnList(edges2);
1290
+ const columns = chunkCFNT3ITG_cjs.edgeColumnList(edges2);
1658
1291
  const values = params.map((edgeParams) => {
1659
1292
  const propsJson = JSON.stringify(edgeParams.props);
1660
- return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkV4IQYOQ4_cjs.sqlNull(edgeParams.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1293
+ return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkCFNT3ITG_cjs.sqlNull(edgeParams.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1661
1294
  });
1662
1295
  return drizzleOrm.sql`
1663
1296
  INSERT INTO ${edges2} (${columns})
@@ -1675,28 +1308,24 @@ function buildGetEdge(tables3, graphId, id) {
1675
1308
  }
1676
1309
  function buildGetEdges(tables3, graphId, ids) {
1677
1310
  const { edges: edges2 } = tables3;
1678
- const idPlaceholders = drizzleOrm.sql.join(
1679
- ids.map((edgeId) => drizzleOrm.sql`${edgeId}`),
1680
- drizzleOrm.sql`, `
1681
- );
1682
1311
  return drizzleOrm.sql`
1683
1312
  SELECT * FROM ${edges2}
1684
1313
  WHERE ${edges2.graphId} = ${graphId}
1685
- AND ${edges2.id} IN (${idPlaceholders})
1314
+ AND ${edges2.id} IN (${chunkI4W7MKVG_cjs.sqlValueList(ids)})
1686
1315
  `;
1687
1316
  }
1688
1317
  function buildUpdateEdge(tables3, params, timestamp2) {
1689
1318
  const { edges: edges2 } = tables3;
1690
1319
  const propsJson = JSON.stringify(params.props);
1691
1320
  const setParts = [
1692
- drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(edges2.props)} = ${propsJson}`,
1693
- drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(edges2.updatedAt)} = ${timestamp2}`
1321
+ drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(edges2.props)} = ${propsJson}`,
1322
+ drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(edges2.updatedAt)} = ${timestamp2}`
1694
1323
  ];
1695
1324
  if (params.validTo !== void 0) {
1696
- setParts.push(drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(edges2.validTo)} = ${params.validTo}`);
1325
+ setParts.push(drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(edges2.validTo)} = ${params.validTo}`);
1697
1326
  }
1698
1327
  if (params.clearDeleted) {
1699
- setParts.push(drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(edges2.deletedAt)} = NULL`);
1328
+ setParts.push(drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(edges2.deletedAt)} = NULL`);
1700
1329
  }
1701
1330
  const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
1702
1331
  if (params.clearDeleted) {
@@ -1721,7 +1350,7 @@ function buildDeleteEdge(tables3, params, timestamp2) {
1721
1350
  const { edges: edges2 } = tables3;
1722
1351
  return drizzleOrm.sql`
1723
1352
  UPDATE ${edges2}
1724
- SET ${chunkV4IQYOQ4_cjs.quotedColumn(edges2.deletedAt)} = ${timestamp2}
1353
+ SET ${chunkCFNT3ITG_cjs.quotedColumn(edges2.deletedAt)} = ${timestamp2}
1725
1354
  WHERE ${edges2.graphId} = ${params.graphId}
1726
1355
  AND ${edges2.id} = ${params.id}
1727
1356
  AND ${edges2.deletedAt} IS NULL
@@ -1808,7 +1437,7 @@ function resolveMode(mode) {
1808
1437
  function buildFulltextSearch(tableName, params, strategy) {
1809
1438
  assertValidSearchParams(params);
1810
1439
  const mode = resolveMode(params.mode);
1811
- const table = chunkV4IQYOQ4_cjs.quotedTableName(tableName);
1440
+ const table = chunkCFNT3ITG_cjs.quotedTableName(tableName);
1812
1441
  const matchCondition = strategy.matchCondition(
1813
1442
  tableName,
1814
1443
  params.query,
@@ -1859,12 +1488,12 @@ function assertValidSearchParams(params) {
1859
1488
  function buildInsertNode(tables3, params, timestamp2) {
1860
1489
  const { nodes: nodes2 } = tables3;
1861
1490
  const propsJson = JSON.stringify(params.props);
1862
- const columns = chunkV4IQYOQ4_cjs.nodeColumnList(nodes2);
1491
+ const columns = chunkCFNT3ITG_cjs.nodeColumnList(nodes2);
1863
1492
  return drizzleOrm.sql`
1864
1493
  INSERT INTO ${nodes2} (${columns})
1865
1494
  VALUES (
1866
1495
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1867
- 1, ${chunkV4IQYOQ4_cjs.sqlNull(params.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validTo)},
1496
+ 1, ${chunkCFNT3ITG_cjs.sqlNull(params.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(params.validTo)},
1868
1497
  ${timestamp2}, ${timestamp2}
1869
1498
  )
1870
1499
  RETURNING *
@@ -1873,22 +1502,22 @@ function buildInsertNode(tables3, params, timestamp2) {
1873
1502
  function buildInsertNodeNoReturn(tables3, params, timestamp2) {
1874
1503
  const { nodes: nodes2 } = tables3;
1875
1504
  const propsJson = JSON.stringify(params.props);
1876
- const columns = chunkV4IQYOQ4_cjs.nodeColumnList(nodes2);
1505
+ const columns = chunkCFNT3ITG_cjs.nodeColumnList(nodes2);
1877
1506
  return drizzleOrm.sql`
1878
1507
  INSERT INTO ${nodes2} (${columns})
1879
1508
  VALUES (
1880
1509
  ${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
1881
- 1, ${chunkV4IQYOQ4_cjs.sqlNull(params.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(params.validTo)},
1510
+ 1, ${chunkCFNT3ITG_cjs.sqlNull(params.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(params.validTo)},
1882
1511
  ${timestamp2}, ${timestamp2}
1883
1512
  )
1884
1513
  `;
1885
1514
  }
1886
1515
  function buildInsertNodesBatch(tables3, params, timestamp2) {
1887
1516
  const { nodes: nodes2 } = tables3;
1888
- const columns = chunkV4IQYOQ4_cjs.nodeColumnList(nodes2);
1517
+ const columns = chunkCFNT3ITG_cjs.nodeColumnList(nodes2);
1889
1518
  const values = params.map((nodeParams) => {
1890
1519
  const propsJson = JSON.stringify(nodeParams.props);
1891
- return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkV4IQYOQ4_cjs.sqlNull(nodeParams.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1520
+ return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkCFNT3ITG_cjs.sqlNull(nodeParams.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1892
1521
  });
1893
1522
  return drizzleOrm.sql`
1894
1523
  INSERT INTO ${nodes2} (${columns})
@@ -1897,10 +1526,10 @@ function buildInsertNodesBatch(tables3, params, timestamp2) {
1897
1526
  }
1898
1527
  function buildInsertNodesBatchReturning(tables3, params, timestamp2) {
1899
1528
  const { nodes: nodes2 } = tables3;
1900
- const columns = chunkV4IQYOQ4_cjs.nodeColumnList(nodes2);
1529
+ const columns = chunkCFNT3ITG_cjs.nodeColumnList(nodes2);
1901
1530
  const values = params.map((nodeParams) => {
1902
1531
  const propsJson = JSON.stringify(nodeParams.props);
1903
- return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkV4IQYOQ4_cjs.sqlNull(nodeParams.validFrom)}, ${chunkV4IQYOQ4_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1532
+ return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkCFNT3ITG_cjs.sqlNull(nodeParams.validFrom)}, ${chunkCFNT3ITG_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
1904
1533
  });
1905
1534
  return drizzleOrm.sql`
1906
1535
  INSERT INTO ${nodes2} (${columns})
@@ -1919,34 +1548,30 @@ function buildGetNode(tables3, graphId, kind, id) {
1919
1548
  }
1920
1549
  function buildGetNodes(tables3, graphId, kind, ids) {
1921
1550
  const { nodes: nodes2 } = tables3;
1922
- const idPlaceholders = drizzleOrm.sql.join(
1923
- ids.map((nodeId) => drizzleOrm.sql`${nodeId}`),
1924
- drizzleOrm.sql`, `
1925
- );
1926
1551
  return drizzleOrm.sql`
1927
1552
  SELECT * FROM ${nodes2}
1928
1553
  WHERE ${nodes2.graphId} = ${graphId}
1929
1554
  AND ${nodes2.kind} = ${kind}
1930
- AND ${nodes2.id} IN (${idPlaceholders})
1555
+ AND ${nodes2.id} IN (${chunkI4W7MKVG_cjs.sqlValueList(ids)})
1931
1556
  `;
1932
1557
  }
1933
1558
  function buildUpdateNode(tables3, params, timestamp2) {
1934
1559
  const { nodes: nodes2 } = tables3;
1935
1560
  const propsJson = JSON.stringify(params.props);
1936
1561
  const setParts = [
1937
- drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.props)} = ${propsJson}`,
1938
- drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.updatedAt)} = ${timestamp2}`
1562
+ drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(nodes2.props)} = ${propsJson}`,
1563
+ drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(nodes2.updatedAt)} = ${timestamp2}`
1939
1564
  ];
1940
1565
  if (params.incrementVersion) {
1941
1566
  setParts.push(
1942
- drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.version)} = ${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.version)} + 1`
1567
+ drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(nodes2.version)} = ${chunkCFNT3ITG_cjs.quotedColumn(nodes2.version)} + 1`
1943
1568
  );
1944
1569
  }
1945
1570
  if (params.validTo !== void 0) {
1946
- setParts.push(drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.validTo)} = ${params.validTo}`);
1571
+ setParts.push(drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(nodes2.validTo)} = ${params.validTo}`);
1947
1572
  }
1948
1573
  if (params.clearDeleted) {
1949
- setParts.push(drizzleOrm.sql`${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.deletedAt)} = NULL`);
1574
+ setParts.push(drizzleOrm.sql`${chunkCFNT3ITG_cjs.quotedColumn(nodes2.deletedAt)} = NULL`);
1950
1575
  }
1951
1576
  const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
1952
1577
  if (params.clearDeleted) {
@@ -1973,7 +1598,7 @@ function buildDeleteNode(tables3, params, timestamp2) {
1973
1598
  const { nodes: nodes2 } = tables3;
1974
1599
  return drizzleOrm.sql`
1975
1600
  UPDATE ${nodes2}
1976
- SET ${chunkV4IQYOQ4_cjs.quotedColumn(nodes2.deletedAt)} = ${timestamp2}
1601
+ SET ${chunkCFNT3ITG_cjs.quotedColumn(nodes2.deletedAt)} = ${timestamp2}
1977
1602
  WHERE ${nodes2.graphId} = ${params.graphId}
1978
1603
  AND ${nodes2.kind} = ${params.kind}
1979
1604
  AND ${nodes2.id} = ${params.id}
@@ -2040,12 +1665,12 @@ function buildSetActiveSchema(tables3, graphId, version, dialect = "sqlite") {
2040
1665
  const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
2041
1666
  const deactivateAll = drizzleOrm.sql`
2042
1667
  UPDATE ${schemaVersions2}
2043
- SET ${chunkV4IQYOQ4_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(false)}
1668
+ SET ${chunkCFNT3ITG_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(false)}
2044
1669
  WHERE ${schemaVersions2.graphId} = ${graphId}
2045
1670
  `;
2046
1671
  const activateVersion = drizzleOrm.sql`
2047
1672
  UPDATE ${schemaVersions2}
2048
- SET ${chunkV4IQYOQ4_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(true)}
1673
+ SET ${chunkCFNT3ITG_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(true)}
2049
1674
  WHERE ${schemaVersions2.graphId} = ${graphId}
2050
1675
  AND ${schemaVersions2.version} = ${version}
2051
1676
  `;
@@ -2063,22 +1688,22 @@ function buildInsertUniqueSqlite(tables3, params) {
2063
1688
  )
2064
1689
  ON CONFLICT (${conflictColumns})
2065
1690
  DO UPDATE SET
2066
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} = CASE
2067
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
2068
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.nodeId}
2069
- ELSE ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)}
1691
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} = CASE
1692
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
1693
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.nodeId}
1694
+ ELSE ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)}
2070
1695
  END,
2071
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.concreteKind)} = CASE
2072
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
2073
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
2074
- ELSE ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.concreteKind)}
1696
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.concreteKind)} = CASE
1697
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
1698
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
1699
+ ELSE ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.concreteKind)}
2075
1700
  END,
2076
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} = CASE
2077
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN NULL
2078
- WHEN ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN NULL
2079
- ELSE ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)}
1701
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} = CASE
1702
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN NULL
1703
+ WHEN ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN NULL
1704
+ ELSE ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)}
2080
1705
  END
2081
- RETURNING ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} as node_id
1706
+ RETURNING ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} as node_id
2082
1707
  `;
2083
1708
  }
2084
1709
  function buildInsertUniquePostgres(tables3, params) {
@@ -2095,22 +1720,22 @@ function buildInsertUniquePostgres(tables3, params) {
2095
1720
  )
2096
1721
  ON CONFLICT (${conflictColumns})
2097
1722
  DO UPDATE SET
2098
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} = CASE
1723
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} = CASE
2099
1724
  WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
2100
1725
  WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.nodeId}
2101
1726
  ELSE ${existingColumn(uniques2.nodeId)}
2102
1727
  END,
2103
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.concreteKind)} = CASE
1728
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.concreteKind)} = CASE
2104
1729
  WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
2105
1730
  WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
2106
1731
  ELSE ${existingColumn(uniques2.concreteKind)}
2107
1732
  END,
2108
- ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} = CASE
1733
+ ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} = CASE
2109
1734
  WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN NULL
2110
1735
  WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN NULL
2111
1736
  ELSE ${existingColumn(uniques2.deletedAt)}
2112
1737
  END
2113
- RETURNING ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.nodeId)} as node_id
1738
+ RETURNING ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.nodeId)} as node_id
2114
1739
  `;
2115
1740
  }
2116
1741
  var UNIQUE_INSERT_BUILDERS = {
@@ -2125,7 +1750,7 @@ function buildDeleteUnique(tables3, params, timestamp2) {
2125
1750
  const { uniques: uniques2 } = tables3;
2126
1751
  return drizzleOrm.sql`
2127
1752
  UPDATE ${uniques2}
2128
- SET ${chunkV4IQYOQ4_cjs.quotedColumn(uniques2.deletedAt)} = ${timestamp2}
1753
+ SET ${chunkCFNT3ITG_cjs.quotedColumn(uniques2.deletedAt)} = ${timestamp2}
2129
1754
  WHERE ${uniques2.graphId} = ${params.graphId}
2130
1755
  AND ${uniques2.nodeKind} = ${params.nodeKind}
2131
1756
  AND ${uniques2.constraintName} = ${params.constraintName}
@@ -2262,17 +1887,437 @@ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
2262
1887
  buildSetActiveSchema(graphId, version) {
2263
1888
  return buildSetActiveSchema(tables3, graphId, version, dialect);
2264
1889
  },
1890
+ buildTableExists(tableName) {
1891
+ if (dialect === "postgres") {
1892
+ return drizzleOrm.sql`
1893
+ SELECT c.relname AS table_name
1894
+ FROM pg_catalog.pg_class AS c
1895
+ WHERE c.relname = ${tableName}
1896
+ AND c.relkind IN ('r', 'p', 'v', 'm', 'f')
1897
+ AND pg_catalog.pg_table_is_visible(c.oid)
1898
+ LIMIT 1
1899
+ `;
1900
+ }
1901
+ return drizzleOrm.sql`SELECT name AS table_name FROM sqlite_master WHERE type IN ('table', 'view') AND name = ${tableName}`;
1902
+ },
2265
1903
  buildClearGraph(graphId) {
2266
1904
  return buildClearGraph(tables3, graphId);
2267
1905
  }
2268
1906
  };
2269
1907
  }
1908
+ function tableExistsFromRow(row) {
1909
+ if (row === void 0) return false;
1910
+ return Object.values(row).some((value) => chunkI4W7MKVG_cjs.isPresent(value));
1911
+ }
1912
+ function createCachedTableExistence(probe, options) {
1913
+ const cacheExisting = options?.cacheExisting !== false;
1914
+ const cacheMissing = options?.cacheMissing === true;
1915
+ const confirmedExisting = /* @__PURE__ */ new Set();
1916
+ const confirmedMissing = /* @__PURE__ */ new Set();
1917
+ return async function tableExists(tableName) {
1918
+ if (confirmedExisting.has(tableName)) return true;
1919
+ if (confirmedMissing.has(tableName)) return false;
1920
+ const exists = tableExistsFromRow(await probe(tableName));
1921
+ if (exists && cacheExisting) {
1922
+ confirmedExisting.add(tableName);
1923
+ }
1924
+ if (!exists && cacheMissing) {
1925
+ confirmedMissing.add(tableName);
1926
+ }
1927
+ return exists;
1928
+ };
1929
+ }
2270
1930
  function createSqliteOperationStrategy(tables3, fulltextStrategy) {
2271
1931
  return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
2272
1932
  }
2273
1933
  function createPostgresOperationStrategy(tables3, fulltextStrategy) {
2274
1934
  return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
2275
1935
  }
1936
+ function assertAdoptedDialect(externalTx, brand, backend) {
1937
+ if (drizzleOrm.is(externalTx, brand)) return;
1938
+ const label = backend === "postgres" ? "Postgres" : "SQLite";
1939
+ throw new chunkJIEJCTDS_cjs.ConfigurationError(
1940
+ `adoptTransaction received a handle that is not a ${label} Drizzle transaction. Pass the \`tx\` from a ${label} \`db.transaction(...)\` opened on this backend's connection.`,
1941
+ { backend, capability: "adoptTransaction" }
1942
+ );
1943
+ }
1944
+ function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
1945
+ const expectedVersion = expected.kind === "active" ? expected.version : 0;
1946
+ if (actualActiveVersion !== expectedVersion) {
1947
+ throw new chunkJIEJCTDS_cjs.StaleVersionError({
1948
+ graphId,
1949
+ expected: expectedVersion,
1950
+ actual: actualActiveVersion
1951
+ });
1952
+ }
1953
+ }
1954
+ function createCommonOperationBackend(options) {
1955
+ const { batchConfig, execution, operationStrategy, rowMappers } = options;
1956
+ const nowIso2 = options.nowIso ?? chunkI4W7MKVG_cjs.nowIso;
1957
+ const requiredClearTableExists = createCachedTableExistence(
1958
+ (tableName) => execution.execGet(
1959
+ operationStrategy.buildTableExists(tableName)
1960
+ ),
1961
+ options.tableExistenceCache
1962
+ );
1963
+ async function runIgnorableClearStatement(statement) {
1964
+ if (statement.ignoreMissingTable === true && statement.requiredTableName !== void 0 && !await requiredClearTableExists(statement.requiredTableName)) {
1965
+ return;
1966
+ }
1967
+ await execution.execRun(statement.query);
1968
+ }
1969
+ async function readActiveVersion(graphId) {
1970
+ const row = await execution.execGet(
1971
+ operationStrategy.buildGetActiveSchema(graphId)
1972
+ );
1973
+ return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
1974
+ }
1975
+ return {
1976
+ async executeStatement(query) {
1977
+ await execution.execRun(query);
1978
+ },
1979
+ async insertNode(params) {
1980
+ const timestamp2 = nowIso2();
1981
+ const query = operationStrategy.buildInsertNode(params, timestamp2);
1982
+ const row = await execution.execGet(query);
1983
+ if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
1984
+ return rowMappers.toNodeRow(row);
1985
+ },
1986
+ async insertNodeNoReturn(params) {
1987
+ const timestamp2 = nowIso2();
1988
+ const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
1989
+ await execution.execRun(query);
1990
+ },
1991
+ async insertNodesBatch(params) {
1992
+ if (params.length === 0) {
1993
+ return;
1994
+ }
1995
+ const timestamp2 = nowIso2();
1996
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(params, batchConfig.nodeInsertBatchSize)) {
1997
+ const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp2);
1998
+ await execution.execRun(query);
1999
+ }
2000
+ },
2001
+ async insertNodesBatchReturning(params) {
2002
+ if (params.length === 0) {
2003
+ return [];
2004
+ }
2005
+ const timestamp2 = nowIso2();
2006
+ const allRows = [];
2007
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(params, batchConfig.nodeInsertBatchSize)) {
2008
+ const query = operationStrategy.buildInsertNodesBatchReturning(chunk2, timestamp2);
2009
+ const rows = await execution.execAll(query);
2010
+ allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
2011
+ }
2012
+ return allRows;
2013
+ },
2014
+ async getNode(graphId, kind, id) {
2015
+ const query = operationStrategy.buildGetNode(graphId, kind, id);
2016
+ const row = await execution.execGet(query);
2017
+ return row ? rowMappers.toNodeRow(row) : void 0;
2018
+ },
2019
+ async getNodes(graphId, kind, ids) {
2020
+ if (ids.length === 0) return [];
2021
+ const allRows = [];
2022
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(ids, batchConfig.getNodesChunkSize)) {
2023
+ const query = operationStrategy.buildGetNodes(graphId, kind, chunk2);
2024
+ const rows = await execution.execAll(query);
2025
+ allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
2026
+ }
2027
+ return allRows;
2028
+ },
2029
+ async updateNode(params) {
2030
+ const timestamp2 = nowIso2();
2031
+ const query = operationStrategy.buildUpdateNode(params, timestamp2);
2032
+ const row = await execution.execGet(query);
2033
+ if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
2034
+ return rowMappers.toNodeRow(row);
2035
+ },
2036
+ async deleteNode(params) {
2037
+ const timestamp2 = nowIso2();
2038
+ const query = operationStrategy.buildDeleteNode(params, timestamp2);
2039
+ await execution.execRun(query);
2040
+ },
2041
+ // IMPORTANT: This cascade is not atomic. Callers must ensure this runs
2042
+ // within a transaction to prevent partial deletion on intermediate failure.
2043
+ //
2044
+ // Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
2045
+ // fieldPath)` strategy-owned tables addressable only with the slot
2046
+ // context the graph-agnostic backend lacks. The store's hard-delete
2047
+ // path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
2048
+ // resolves each embedding field and routes a per-field
2049
+ // `backend.deleteEmbedding` through the active vector strategy.
2050
+ async hardDeleteNode(params) {
2051
+ const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
2052
+ params.graphId,
2053
+ params.id
2054
+ );
2055
+ await execution.execRun(deleteUniquesQuery);
2056
+ const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
2057
+ params.graphId,
2058
+ params.kind,
2059
+ params.id
2060
+ );
2061
+ for (const stmt of deleteFulltextStatements) {
2062
+ await execution.execRun(stmt);
2063
+ }
2064
+ const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
2065
+ params.graphId,
2066
+ params.kind,
2067
+ params.id
2068
+ );
2069
+ await execution.execRun(deleteEdgesQuery);
2070
+ const query = operationStrategy.buildHardDeleteNode(params);
2071
+ await execution.execRun(query);
2072
+ },
2073
+ async insertEdge(params) {
2074
+ const timestamp2 = nowIso2();
2075
+ const query = operationStrategy.buildInsertEdge(params, timestamp2);
2076
+ const row = await execution.execGet(query);
2077
+ if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
2078
+ return rowMappers.toEdgeRow(row);
2079
+ },
2080
+ async insertEdgeNoReturn(params) {
2081
+ const timestamp2 = nowIso2();
2082
+ const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
2083
+ await execution.execRun(query);
2084
+ },
2085
+ async insertEdgesBatch(params) {
2086
+ if (params.length === 0) {
2087
+ return;
2088
+ }
2089
+ const timestamp2 = nowIso2();
2090
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(params, batchConfig.edgeInsertBatchSize)) {
2091
+ const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp2);
2092
+ await execution.execRun(query);
2093
+ }
2094
+ },
2095
+ async insertEdgesBatchReturning(params) {
2096
+ if (params.length === 0) {
2097
+ return [];
2098
+ }
2099
+ const timestamp2 = nowIso2();
2100
+ const allRows = [];
2101
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(params, batchConfig.edgeInsertBatchSize)) {
2102
+ const query = operationStrategy.buildInsertEdgesBatchReturning(chunk2, timestamp2);
2103
+ const rows = await execution.execAll(query);
2104
+ allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
2105
+ }
2106
+ return allRows;
2107
+ },
2108
+ async getEdge(graphId, id) {
2109
+ const query = operationStrategy.buildGetEdge(graphId, id);
2110
+ const row = await execution.execGet(query);
2111
+ return row ? rowMappers.toEdgeRow(row) : void 0;
2112
+ },
2113
+ async getEdges(graphId, ids) {
2114
+ if (ids.length === 0) return [];
2115
+ const allRows = [];
2116
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(ids, batchConfig.getEdgesChunkSize)) {
2117
+ const query = operationStrategy.buildGetEdges(graphId, chunk2);
2118
+ const rows = await execution.execAll(query);
2119
+ allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
2120
+ }
2121
+ return allRows;
2122
+ },
2123
+ async updateEdge(params) {
2124
+ const timestamp2 = nowIso2();
2125
+ const query = operationStrategy.buildUpdateEdge(params, timestamp2);
2126
+ const row = await execution.execGet(query);
2127
+ if (!row) throw new chunkJIEJCTDS_cjs.DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
2128
+ return rowMappers.toEdgeRow(row);
2129
+ },
2130
+ async deleteEdge(params) {
2131
+ const timestamp2 = nowIso2();
2132
+ const query = operationStrategy.buildDeleteEdge(params, timestamp2);
2133
+ await execution.execRun(query);
2134
+ },
2135
+ async hardDeleteEdge(params) {
2136
+ const query = operationStrategy.buildHardDeleteEdge(params);
2137
+ await execution.execRun(query);
2138
+ },
2139
+ async countEdgesFrom(params) {
2140
+ const query = operationStrategy.buildCountEdgesFrom(params);
2141
+ const row = await execution.execGet(query);
2142
+ return Number(row?.count ?? 0);
2143
+ },
2144
+ async edgeExistsBetween(params) {
2145
+ const query = operationStrategy.buildEdgeExistsBetween(params);
2146
+ const row = await execution.execGet(query);
2147
+ return row !== void 0;
2148
+ },
2149
+ async findEdgesConnectedTo(params) {
2150
+ const query = operationStrategy.buildFindEdgesConnectedTo(params);
2151
+ const rows = await execution.execAll(query);
2152
+ return rows.map((row) => rowMappers.toEdgeRow(row));
2153
+ },
2154
+ async findNodesByKind(params) {
2155
+ const query = operationStrategy.buildFindNodesByKind(params);
2156
+ const rows = await execution.execAll(query);
2157
+ return rows.map((row) => rowMappers.toNodeRow(row));
2158
+ },
2159
+ async countNodesByKind(params) {
2160
+ const query = operationStrategy.buildCountNodesByKind(params);
2161
+ const row = await execution.execGet(query);
2162
+ return Number(row?.count ?? 0);
2163
+ },
2164
+ async findEdgesByKind(params) {
2165
+ const query = operationStrategy.buildFindEdgesByKind(params);
2166
+ const rows = await execution.execAll(query);
2167
+ return rows.map((row) => rowMappers.toEdgeRow(row));
2168
+ },
2169
+ async countEdgesByKind(params) {
2170
+ const query = operationStrategy.buildCountEdgesByKind(params);
2171
+ const row = await execution.execGet(query);
2172
+ return Number(row?.count ?? 0);
2173
+ },
2174
+ async insertUnique(params) {
2175
+ const query = operationStrategy.buildInsertUnique(params);
2176
+ const result = await execution.execGet(query);
2177
+ if (result && result.node_id !== params.nodeId) {
2178
+ throw new chunkJIEJCTDS_cjs.UniquenessError({
2179
+ constraintName: params.constraintName,
2180
+ kind: params.nodeKind,
2181
+ existingId: result.node_id,
2182
+ newId: params.nodeId,
2183
+ fields: []
2184
+ });
2185
+ }
2186
+ },
2187
+ async deleteUnique(params) {
2188
+ const timestamp2 = nowIso2();
2189
+ const query = operationStrategy.buildDeleteUnique(params, timestamp2);
2190
+ await execution.execRun(query);
2191
+ },
2192
+ async checkUnique(params) {
2193
+ const query = operationStrategy.buildCheckUnique(params);
2194
+ const row = await execution.execGet(query);
2195
+ return row ? rowMappers.toUniqueRow(row) : void 0;
2196
+ },
2197
+ async checkUniqueBatch(params) {
2198
+ if (params.keys.length === 0) return [];
2199
+ const allRows = [];
2200
+ for (const chunk2 of chunkI4W7MKVG_cjs.chunk(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
2201
+ const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk2 });
2202
+ const rows = await execution.execAll(query);
2203
+ allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
2204
+ }
2205
+ return allRows;
2206
+ },
2207
+ async getActiveSchema(graphId) {
2208
+ const query = operationStrategy.buildGetActiveSchema(graphId);
2209
+ const row = await execution.execGet(query);
2210
+ return row ? rowMappers.toSchemaVersionRow(row) : void 0;
2211
+ },
2212
+ async getSchemaVersion(graphId, version) {
2213
+ const query = operationStrategy.buildGetSchemaVersion(graphId, version);
2214
+ const row = await execution.execGet(query);
2215
+ return row ? rowMappers.toSchemaVersionRow(row) : void 0;
2216
+ },
2217
+ async commitSchemaVersion(params) {
2218
+ const existingRaw = await execution.execGet(
2219
+ operationStrategy.buildGetSchemaVersion(
2220
+ params.graphId,
2221
+ params.version
2222
+ )
2223
+ );
2224
+ const actualActiveVersion = await readActiveVersion(params.graphId);
2225
+ if (existingRaw !== void 0) {
2226
+ const existing = rowMappers.toSchemaVersionRow(existingRaw);
2227
+ if (existing.schema_hash !== params.schemaHash) {
2228
+ throw new chunkJIEJCTDS_cjs.SchemaContentConflictError({
2229
+ graphId: params.graphId,
2230
+ version: params.version,
2231
+ existingHash: existing.schema_hash,
2232
+ incomingHash: params.schemaHash
2233
+ });
2234
+ }
2235
+ if (existing.is_active) {
2236
+ return existing;
2237
+ }
2238
+ verifyExpectedActiveVersion(
2239
+ params.graphId,
2240
+ params.expected,
2241
+ actualActiveVersion
2242
+ );
2243
+ const reactivate = operationStrategy.buildSetActiveSchema(
2244
+ params.graphId,
2245
+ params.version
2246
+ );
2247
+ await execution.execRun(reactivate.deactivateAll);
2248
+ await execution.execRun(reactivate.activateVersion);
2249
+ return { ...existing, is_active: true };
2250
+ }
2251
+ verifyExpectedActiveVersion(
2252
+ params.graphId,
2253
+ params.expected,
2254
+ actualActiveVersion
2255
+ );
2256
+ if (params.expected.kind === "active") {
2257
+ const flip = operationStrategy.buildSetActiveSchema(
2258
+ params.graphId,
2259
+ params.version
2260
+ );
2261
+ await execution.execRun(flip.deactivateAll);
2262
+ }
2263
+ const timestamp2 = nowIso2();
2264
+ const insertQuery = operationStrategy.buildInsertSchema(
2265
+ {
2266
+ graphId: params.graphId,
2267
+ version: params.version,
2268
+ schemaHash: params.schemaHash,
2269
+ schemaDoc: params.schemaDoc,
2270
+ isActive: true
2271
+ },
2272
+ timestamp2
2273
+ );
2274
+ const insertedRaw = await execution.execGet(insertQuery);
2275
+ if (!insertedRaw) {
2276
+ throw new chunkJIEJCTDS_cjs.DatabaseOperationError(
2277
+ "Insert schema failed: no row returned",
2278
+ { operation: "insert", entity: "schema" }
2279
+ );
2280
+ }
2281
+ return rowMappers.toSchemaVersionRow(insertedRaw);
2282
+ },
2283
+ async setActiveVersion(params) {
2284
+ const actualActiveVersion = await readActiveVersion(params.graphId);
2285
+ verifyExpectedActiveVersion(
2286
+ params.graphId,
2287
+ params.expected,
2288
+ actualActiveVersion
2289
+ );
2290
+ const targetRaw = await execution.execGet(
2291
+ operationStrategy.buildGetSchemaVersion(
2292
+ params.graphId,
2293
+ params.version
2294
+ )
2295
+ );
2296
+ if (!targetRaw) {
2297
+ throw new chunkJIEJCTDS_cjs.MigrationError(
2298
+ `Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
2299
+ {
2300
+ graphId: params.graphId,
2301
+ fromVersion: actualActiveVersion,
2302
+ toVersion: params.version
2303
+ }
2304
+ );
2305
+ }
2306
+ const queries = operationStrategy.buildSetActiveSchema(
2307
+ params.graphId,
2308
+ params.version
2309
+ );
2310
+ await execution.execRun(queries.deactivateAll);
2311
+ await execution.execRun(queries.activateVersion);
2312
+ },
2313
+ async clearGraph(graphId) {
2314
+ const statements = operationStrategy.buildClearGraph(graphId);
2315
+ for (const statement of statements) {
2316
+ await runIgnorableClearStatement(statement);
2317
+ }
2318
+ }
2319
+ };
2320
+ }
2276
2321
 
2277
2322
  // src/backend/drizzle/execution/lru.ts
2278
2323
  function getOrCreateLru(cache, key, cacheMax, create) {
@@ -2304,11 +2349,9 @@ function compileQueryWithDialect(db, query, backendName) {
2304
2349
  exports.POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS = POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS;
2305
2350
  exports.POSTGRES_INDEX_MAT_TIMESTAMPS = POSTGRES_INDEX_MAT_TIMESTAMPS;
2306
2351
  exports.POSTGRES_KIND_REMOVAL_TIMESTAMPS = POSTGRES_KIND_REMOVAL_TIMESTAMPS;
2307
- exports.POSTGRES_ROW_MAPPER_CONFIG = POSTGRES_ROW_MAPPER_CONFIG;
2308
2352
  exports.SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = SQLITE_CONTRIBUTION_MAT_TIMESTAMPS;
2309
2353
  exports.SQLITE_INDEX_MAT_TIMESTAMPS = SQLITE_INDEX_MAT_TIMESTAMPS;
2310
2354
  exports.SQLITE_KIND_REMOVAL_TIMESTAMPS = SQLITE_KIND_REMOVAL_TIMESTAMPS;
2311
- exports.SQLITE_ROW_MAPPER_CONFIG = SQLITE_ROW_MAPPER_CONFIG;
2312
2355
  exports.assertAdoptedDialect = assertAdoptedDialect;
2313
2356
  exports.buildContributionInsertValues = buildContributionInsertValues;
2314
2357
  exports.buildContributionOnConflictSet = buildContributionOnConflictSet;
@@ -2316,17 +2359,13 @@ exports.buildKindRemovalInsertValues = buildKindRemovalInsertValues;
2316
2359
  exports.buildKindRemovalOnConflictSet = buildKindRemovalOnConflictSet;
2317
2360
  exports.buildMaterializationInsertValues = buildMaterializationInsertValues;
2318
2361
  exports.buildMaterializationOnConflictSet = buildMaterializationOnConflictSet;
2319
- exports.coerceNumericScore = coerceNumericScore;
2320
2362
  exports.compileQueryWithDialect = compileQueryWithDialect;
2363
+ exports.createCachedTableExistence = createCachedTableExistence;
2321
2364
  exports.createCommonOperationBackend = createCommonOperationBackend;
2322
2365
  exports.createContributionMaterializer = createContributionMaterializer;
2323
- exports.createEdgeRowMapper = createEdgeRowMapper;
2324
- exports.createNodeRowMapper = createNodeRowMapper;
2325
2366
  exports.createPostgresOperationStrategy = createPostgresOperationStrategy;
2326
2367
  exports.createPostgresTables = createPostgresTables;
2327
- exports.createSchemaVersionRowMapper = createSchemaVersionRowMapper;
2328
2368
  exports.createSqliteOperationStrategy = createSqliteOperationStrategy;
2329
- exports.createUniqueRowMapper = createUniqueRowMapper;
2330
2369
  exports.createVectorSlotLatch = createVectorSlotLatch;
2331
2370
  exports.edges = edges;
2332
2371
  exports.fulltext = fulltext;
@@ -2344,12 +2383,14 @@ exports.mapKindRemovalRow = mapKindRemovalRow;
2344
2383
  exports.mapMaterializationRow = mapMaterializationRow;
2345
2384
  exports.mapVectorWriteError = mapVectorWriteError;
2346
2385
  exports.nodes = nodes;
2347
- exports.nowIso = nowIso;
2386
+ exports.recordedClock = recordedClock;
2387
+ exports.recordedEdges = recordedEdges;
2388
+ exports.recordedNodes = recordedNodes;
2348
2389
  exports.schemaVersions = schemaVersions;
2349
2390
  exports.tables = tables2;
2350
2391
  exports.uniques = uniques;
2351
2392
  exports.vectorSlotFromCreateIndexParams = vectorSlotFromCreateIndexParams;
2352
2393
  exports.vectorSlotFromDropIndexParams = vectorSlotFromDropIndexParams;
2353
2394
  exports.vectorSlotFromParams = vectorSlotFromParams;
2354
- //# sourceMappingURL=chunk-CIINW6PS.cjs.map
2355
- //# sourceMappingURL=chunk-CIINW6PS.cjs.map
2395
+ //# sourceMappingURL=chunk-KY5SDVA7.cjs.map
2396
+ //# sourceMappingURL=chunk-KY5SDVA7.cjs.map