@nicia-ai/typegraph 0.32.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 (158) hide show
  1. package/README.md +31 -0
  2. package/dist/backend/postgres/index.cjs +28 -15
  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 +6 -5
  6. package/dist/backend/postgres/pglite.cjs +10 -9
  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 +6 -5
  11. package/dist/backend/postgres/pglite.js.map +1 -1
  12. package/dist/backend/sqlite/index.cjs +27 -14
  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 +6 -5
  16. package/dist/backend/sqlite/libsql.cjs +9 -8
  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 +6 -5
  21. package/dist/backend/sqlite/libsql.js.map +1 -1
  22. package/dist/backend/sqlite/local.cjs +10 -9
  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 +6 -5
  27. package/dist/backend/sqlite/local.js.map +1 -1
  28. package/dist/{chunk-CAMMC3E4.cjs → chunk-3642VBVC.cjs} +65 -63
  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-JKRKIEVA.cjs → chunk-4RBAJVEC.cjs} +125 -3
  35. package/dist/chunk-4RBAJVEC.cjs.map +1 -0
  36. package/dist/{chunk-IJORSAC3.js → chunk-6NRFUHMS.js} +4 -3
  37. package/dist/chunk-6NRFUHMS.js.map +1 -0
  38. package/dist/{chunk-YL4F3CMD.cjs → chunk-BF3ZDEUE.cjs} +96 -64
  39. package/dist/chunk-BF3ZDEUE.cjs.map +1 -0
  40. package/dist/{chunk-2LAT5BIK.cjs → chunk-D3EWZ67S.cjs} +2820 -1947
  41. package/dist/chunk-D3EWZ67S.cjs.map +1 -0
  42. package/dist/{chunk-XQFAJVYW.js → chunk-DJYRRDHA.js} +123 -4
  43. package/dist/chunk-DJYRRDHA.js.map +1 -0
  44. package/dist/{chunk-YQGLVWB2.cjs → chunk-EF3Z645U.cjs} +2 -52
  45. package/dist/chunk-EF3Z645U.cjs.map +1 -0
  46. package/dist/chunk-GYVBEZAO.js +120 -0
  47. package/dist/chunk-GYVBEZAO.js.map +1 -0
  48. package/dist/chunk-I4W7MKVG.cjs +1526 -0
  49. package/dist/chunk-I4W7MKVG.cjs.map +1 -0
  50. package/dist/{chunk-MXE2U3EX.js → chunk-IZ4PCL47.js} +3 -52
  51. package/dist/chunk-IZ4PCL47.js.map +1 -0
  52. package/dist/{chunk-7WW3WL6E.js → chunk-JHOBXD7O.js} +9 -7
  53. package/dist/chunk-JHOBXD7O.js.map +1 -0
  54. package/dist/{chunk-3HQDMOBK.cjs → chunk-KY5SDVA7.cjs} +619 -578
  55. package/dist/chunk-KY5SDVA7.cjs.map +1 -0
  56. package/dist/{chunk-EEYV6UOE.cjs → chunk-MBLXCV2Y.cjs} +2 -2
  57. package/dist/{chunk-EEYV6UOE.cjs.map → chunk-MBLXCV2Y.cjs.map} +1 -1
  58. package/dist/{chunk-LAZGHOZW.cjs → chunk-NG5N7R45.cjs} +28 -28
  59. package/dist/{chunk-LAZGHOZW.cjs.map → chunk-NG5N7R45.cjs.map} +1 -1
  60. package/dist/chunk-OIE2UPVG.cjs +126 -0
  61. package/dist/chunk-OIE2UPVG.cjs.map +1 -0
  62. package/dist/{chunk-NDM5PXEH.js → chunk-OS6KS3HV.js} +41 -9
  63. package/dist/chunk-OS6KS3HV.js.map +1 -0
  64. package/dist/chunk-PYD3UCDU.js +1480 -0
  65. package/dist/chunk-PYD3UCDU.js.map +1 -0
  66. package/dist/{chunk-W4ZX2GCP.js → chunk-QBYTJSAY.js} +2 -2
  67. package/dist/{chunk-W4ZX2GCP.js.map → chunk-QBYTJSAY.js.map} +1 -1
  68. package/dist/{chunk-HFBRAOF7.js → chunk-SPT5JMME.js} +3 -3
  69. package/dist/{chunk-HFBRAOF7.js.map → chunk-SPT5JMME.js.map} +1 -1
  70. package/dist/{chunk-SB65GJNY.cjs → chunk-SST7XDY6.cjs} +11 -11
  71. package/dist/{chunk-SB65GJNY.cjs.map → chunk-SST7XDY6.cjs.map} +1 -1
  72. package/dist/{chunk-TUA3MEJJ.js → chunk-UPDMJEW6.js} +606 -561
  73. package/dist/chunk-UPDMJEW6.js.map +1 -0
  74. package/dist/{chunk-WNORITK6.js → chunk-WLP6TKFB.js} +2691 -1817
  75. package/dist/chunk-WLP6TKFB.js.map +1 -0
  76. package/dist/chunk-XLUNB2TZ.js +53 -0
  77. package/dist/chunk-XLUNB2TZ.js.map +1 -0
  78. package/dist/{chunk-2BVHPOIG.js → chunk-XVUJY72M.js} +6 -6
  79. package/dist/{chunk-2BVHPOIG.js.map → chunk-XVUJY72M.js.map} +1 -1
  80. package/dist/{ddl-C8e8zDAE.d.ts → ddl-CVnHJcar.d.ts} +3 -3
  81. package/dist/{ddl-CwyG4HoQ.d.cts → ddl-Dxt_fBHr.d.cts} +3 -3
  82. package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
  83. package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
  84. package/dist/graph-extension/index.d.cts +4 -4
  85. package/dist/graph-extension/index.d.ts +4 -4
  86. package/dist/graph-merge/index.cjs +24 -23
  87. package/dist/graph-merge/index.cjs.map +1 -1
  88. package/dist/graph-merge/index.d.cts +6 -6
  89. package/dist/graph-merge/index.d.ts +6 -6
  90. package/dist/graph-merge/index.js +9 -8
  91. package/dist/graph-merge/index.js.map +1 -1
  92. package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
  93. package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
  94. package/dist/index.cjs +129 -104
  95. package/dist/index.cjs.map +1 -1
  96. package/dist/index.d.cts +25 -55
  97. package/dist/index.d.ts +25 -55
  98. package/dist/index.js +12 -10
  99. package/dist/index.js.map +1 -1
  100. package/dist/indexes/index.cjs +5 -4
  101. package/dist/indexes/index.d.cts +5 -5
  102. package/dist/indexes/index.d.ts +5 -5
  103. package/dist/indexes/index.js +3 -2
  104. package/dist/interchange/index.cjs +15 -15
  105. package/dist/interchange/index.d.cts +5 -5
  106. package/dist/interchange/index.d.ts +5 -5
  107. package/dist/interchange/index.js +2 -2
  108. package/dist/{manager-aVgxbGt-.d.cts → manager-BYl_zyZR.d.cts} +2 -2
  109. package/dist/{manager-8htmuGr-.d.ts → manager-C0_r0ALf.d.ts} +2 -2
  110. package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
  111. package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
  112. package/dist/{postgres-jgXmD45C.d.cts → postgres-MzBPkYzq.d.ts} +2651 -596
  113. package/dist/{postgres-Dhom7iiX.d.ts → postgres-_9psmVGm.d.cts} +2651 -596
  114. package/dist/profiler/index.cjs +4 -3
  115. package/dist/profiler/index.cjs.map +1 -1
  116. package/dist/profiler/index.d.cts +7 -7
  117. package/dist/profiler/index.d.ts +7 -7
  118. package/dist/profiler/index.js +2 -1
  119. package/dist/profiler/index.js.map +1 -1
  120. package/dist/schema/index.cjs +30 -29
  121. package/dist/schema/index.cjs.map +1 -1
  122. package/dist/schema/index.d.cts +7 -7
  123. package/dist/schema/index.d.ts +7 -7
  124. package/dist/schema/index.js +7 -6
  125. package/dist/schema/index.js.map +1 -1
  126. package/dist/{sqlite-BfLsCEqO.d.ts → sqlite-BfksSb45.d.cts} +2726 -455
  127. package/dist/{sqlite-DcQ_BCUW.d.cts → sqlite-gm44dShb.d.ts} +2726 -455
  128. package/dist/{store-view-pBOUrQte.d.ts → store-view-9jQ2rPum.d.cts} +437 -129
  129. package/dist/{store-view-lTcb_cnp.d.cts → store-view-FfE5_7eo.d.ts} +437 -129
  130. package/dist/{types-5RQwzWXx.d.cts → types-B6mhrcLv.d.cts} +2 -2
  131. package/dist/{types-Dk8r09KY.d.ts → types-C_UnQOQp.d.cts} +154 -23
  132. package/dist/{types-DGDiXAYc.d.ts → types-CdWxK-nD.d.ts} +2 -2
  133. package/dist/{types-Dvmn-eal.d.cts → types-DGylBhWo.d.ts} +154 -23
  134. package/dist/{where-Cx_glEEB.d.cts → where-Bpp2ul_z.d.cts} +2 -2
  135. package/dist/{where-CHZFELX0.d.ts → where-BsEXraKW.d.ts} +2 -2
  136. package/package.json +1 -1
  137. package/dist/chunk-2LAT5BIK.cjs.map +0 -1
  138. package/dist/chunk-3HQDMOBK.cjs.map +0 -1
  139. package/dist/chunk-6G35I3VW.cjs +0 -40
  140. package/dist/chunk-6G35I3VW.cjs.map +0 -1
  141. package/dist/chunk-6RMLO5O4.cjs.map +0 -1
  142. package/dist/chunk-7WW3WL6E.js.map +0 -1
  143. package/dist/chunk-CAMMC3E4.cjs.map +0 -1
  144. package/dist/chunk-IJORSAC3.js.map +0 -1
  145. package/dist/chunk-JKRKIEVA.cjs.map +0 -1
  146. package/dist/chunk-M6OC455F.js +0 -65
  147. package/dist/chunk-M6OC455F.js.map +0 -1
  148. package/dist/chunk-MXE2U3EX.js.map +0 -1
  149. package/dist/chunk-NDM5PXEH.js.map +0 -1
  150. package/dist/chunk-RP7YITHX.cjs +0 -70
  151. package/dist/chunk-RP7YITHX.cjs.map +0 -1
  152. package/dist/chunk-SAJSMR2B.js +0 -35
  153. package/dist/chunk-SAJSMR2B.js.map +0 -1
  154. package/dist/chunk-TUA3MEJJ.js.map +0 -1
  155. package/dist/chunk-WNORITK6.js.map +0 -1
  156. package/dist/chunk-XQFAJVYW.js.map +0 -1
  157. package/dist/chunk-YL4F3CMD.cjs.map +0 -1
  158. package/dist/chunk-YQGLVWB2.cjs.map +0 -1
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkJKRKIEVA_cjs = require('./chunk-JKRKIEVA.cjs');
3
+ var chunk4RBAJVEC_cjs = require('./chunk-4RBAJVEC.cjs');
4
4
  var chunkWWVV44DY_cjs = require('./chunk-WWVV44DY.cjs');
5
- var chunkRP7YITHX_cjs = require('./chunk-RP7YITHX.cjs');
5
+ var chunkI4W7MKVG_cjs = require('./chunk-I4W7MKVG.cjs');
6
+ var chunkOIE2UPVG_cjs = require('./chunk-OIE2UPVG.cjs');
6
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');
@@ -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",
@@ -119,6 +123,111 @@ function createPostgresTables(names = {}, options = {}) {
119
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,7 +508,7 @@ 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 = chunkJKRKIEVA_cjs.tables, fulltextStrategy = chunkCFNT3ITG_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;
@@ -409,12 +530,12 @@ function sqliteContributions(tables3 = chunkJKRKIEVA_cjs.tables, fulltextStrateg
409
530
  }
410
531
  return contributions;
411
532
  }
412
- function generateSqliteDDL(tables3 = chunkJKRKIEVA_cjs.tables, fulltextStrategy = chunkCFNT3ITG_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 = chunkJKRKIEVA_cjs.tables, fulltextStrategy = chunkCFNT3ITG_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) {
@@ -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 = chunkCFNT3ITG_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) {
@@ -1675,14 +1308,10 @@ 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) {
@@ -1919,15 +1548,11 @@ 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) {
@@ -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-3HQDMOBK.cjs.map
2355
- //# sourceMappingURL=chunk-3HQDMOBK.cjs.map
2395
+ //# sourceMappingURL=chunk-KY5SDVA7.cjs.map
2396
+ //# sourceMappingURL=chunk-KY5SDVA7.cjs.map