@nicia-ai/typegraph 0.25.1 → 0.26.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 (122) hide show
  1. package/dist/backend/postgres/index.cjs +161 -113
  2. package/dist/backend/postgres/index.cjs.map +1 -1
  3. package/dist/backend/postgres/index.d.cts +6 -8
  4. package/dist/backend/postgres/index.d.ts +6 -8
  5. package/dist/backend/postgres/index.js +116 -68
  6. package/dist/backend/postgres/index.js.map +1 -1
  7. package/dist/backend/sqlite/index.cjs +16 -15
  8. package/dist/backend/sqlite/index.d.cts +11 -26
  9. package/dist/backend/sqlite/index.d.ts +11 -26
  10. package/dist/backend/sqlite/index.js +6 -5
  11. package/dist/backend/sqlite/libsql.cjs +9 -8
  12. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  13. package/dist/backend/sqlite/libsql.d.cts +4 -3
  14. package/dist/backend/sqlite/libsql.d.ts +4 -3
  15. package/dist/backend/sqlite/libsql.js +6 -5
  16. package/dist/backend/sqlite/libsql.js.map +1 -1
  17. package/dist/backend/sqlite/local.cjs +11 -10
  18. package/dist/backend/sqlite/local.cjs.map +1 -1
  19. package/dist/backend/sqlite/local.d.cts +4 -3
  20. package/dist/backend/sqlite/local.d.ts +4 -3
  21. package/dist/backend/sqlite/local.js +6 -5
  22. package/dist/backend/sqlite/local.js.map +1 -1
  23. package/dist/{chunk-AAA2CR3P.js → chunk-3W6AIFT2.js} +9 -34
  24. package/dist/chunk-3W6AIFT2.js.map +1 -0
  25. package/dist/chunk-4FJVSF3K.cjs +12 -0
  26. package/dist/{chunk-D2GO3RBL.cjs.map → chunk-4FJVSF3K.cjs.map} +1 -1
  27. package/dist/{chunk-QMQYK3IF.cjs → chunk-4TJI44WP.cjs} +92 -119
  28. package/dist/chunk-4TJI44WP.cjs.map +1 -0
  29. package/dist/chunk-5H3BAMTB.js +32 -0
  30. package/dist/chunk-5H3BAMTB.js.map +1 -0
  31. package/dist/{chunk-CLEUFN2K.js → chunk-DDVA4QBA.js} +174 -78
  32. package/dist/chunk-DDVA4QBA.js.map +1 -0
  33. package/dist/{chunk-OECDVACY.cjs → chunk-DN4RUDF3.cjs} +2 -2
  34. package/dist/chunk-DN4RUDF3.cjs.map +1 -0
  35. package/dist/{chunk-NHQWXSTS.js → chunk-E5ROA3MN.js} +3 -3
  36. package/dist/{chunk-NHQWXSTS.js.map → chunk-E5ROA3MN.js.map} +1 -1
  37. package/dist/{chunk-CPFR3O7L.js → chunk-ENXJLDRK.js} +2 -2
  38. package/dist/chunk-ENXJLDRK.js.map +1 -0
  39. package/dist/chunk-IUIWCFG3.cjs +36 -0
  40. package/dist/chunk-IUIWCFG3.cjs.map +1 -0
  41. package/dist/{chunk-EG6TJ3I5.js → chunk-OYLF3IC7.js} +3 -3
  42. package/dist/{chunk-EG6TJ3I5.js.map → chunk-OYLF3IC7.js.map} +1 -1
  43. package/dist/{chunk-JTI5WT4P.cjs → chunk-PN37HVAV.cjs} +32 -10
  44. package/dist/chunk-PN37HVAV.cjs.map +1 -0
  45. package/dist/{chunk-RCAJZG67.cjs → chunk-PYJOBZR3.cjs} +10 -10
  46. package/dist/{chunk-RCAJZG67.cjs.map → chunk-PYJOBZR3.cjs.map} +1 -1
  47. package/dist/{chunk-PSKUWVCB.js → chunk-RF5EUQWS.js} +336 -36
  48. package/dist/chunk-RF5EUQWS.js.map +1 -0
  49. package/dist/{chunk-CLGC7AQ2.cjs → chunk-RVT2N4RF.cjs} +206 -110
  50. package/dist/chunk-RVT2N4RF.cjs.map +1 -0
  51. package/dist/{chunk-4BOWVUGQ.js → chunk-TSGBRPNE.js} +3 -3
  52. package/dist/{chunk-4BOWVUGQ.js.map → chunk-TSGBRPNE.js.map} +1 -1
  53. package/dist/{chunk-CQVNGKU7.cjs → chunk-TVUARC7S.cjs} +410 -100
  54. package/dist/chunk-TVUARC7S.cjs.map +1 -0
  55. package/dist/{chunk-DOTEN2FG.js → chunk-U5ROKVRF.js} +26 -3
  56. package/dist/chunk-U5ROKVRF.js.map +1 -0
  57. package/dist/{chunk-E5JZSEGJ.cjs → chunk-WFUN6DCM.cjs} +8 -8
  58. package/dist/{chunk-E5JZSEGJ.cjs.map → chunk-WFUN6DCM.cjs.map} +1 -1
  59. package/dist/{chunk-W5MTHMTE.cjs → chunk-YEDQLNVE.cjs} +26 -2
  60. package/dist/chunk-YEDQLNVE.cjs.map +1 -0
  61. package/dist/{chunk-YZZBDCLV.js → chunk-ZTREJOGB.js} +32 -11
  62. package/dist/chunk-ZTREJOGB.js.map +1 -0
  63. package/dist/{ddl-BqMmpNor.d.ts → ddl-9kw8UADK.d.ts} +298 -12
  64. package/dist/{ddl-Bwjh8Hff.d.cts → ddl-Cw82BPM4.d.cts} +298 -12
  65. package/dist/{extension-types-D07e_NTw.d.cts → extension-types-B78CZfA5.d.cts} +1 -1
  66. package/dist/{extension-types-D07e_NTw.d.ts → extension-types-B78CZfA5.d.ts} +1 -1
  67. package/dist/graph-extension/index.cjs +18 -18
  68. package/dist/graph-extension/index.d.cts +4 -4
  69. package/dist/graph-extension/index.d.ts +4 -4
  70. package/dist/graph-extension/index.js +3 -3
  71. package/dist/{index-CT6nvtxL.d.cts → index-Bilw0pYm.d.cts} +34 -3
  72. package/dist/{index-DQheiVQV.d.ts → index-CWdBFWbI.d.ts} +34 -3
  73. package/dist/index.cjs +460 -361
  74. package/dist/index.cjs.map +1 -1
  75. package/dist/index.d.cts +13 -11
  76. package/dist/index.d.ts +13 -11
  77. package/dist/index.js +131 -36
  78. package/dist/index.js.map +1 -1
  79. package/dist/indexes/index.cjs +13 -13
  80. package/dist/indexes/index.d.cts +5 -5
  81. package/dist/indexes/index.d.ts +5 -5
  82. package/dist/indexes/index.js +1 -1
  83. package/dist/interchange/index.cjs +7 -7
  84. package/dist/interchange/index.d.cts +7 -5
  85. package/dist/interchange/index.d.ts +7 -5
  86. package/dist/interchange/index.js +2 -2
  87. package/dist/{manager-Cy3dhwYO.d.cts → manager-Aqzmztkb.d.cts} +11 -8
  88. package/dist/{manager-sZkU2VPC.d.ts → manager-C3LxzPcX.d.ts} +11 -8
  89. package/dist/{materialize-indexes-BB9N5uQl.d.cts → materialize-indexes-BQfaAZKA.d.cts} +1 -1
  90. package/dist/{materialize-indexes-BYpU2RKh.d.ts → materialize-indexes-DFavFQah.d.ts} +1 -1
  91. package/dist/profiler/index.d.cts +9 -7
  92. package/dist/profiler/index.d.ts +9 -7
  93. package/dist/schema/index.cjs +28 -27
  94. package/dist/schema/index.cjs.map +1 -1
  95. package/dist/schema/index.d.cts +9 -7
  96. package/dist/schema/index.d.ts +9 -7
  97. package/dist/schema/index.js +6 -5
  98. package/dist/schema/index.js.map +1 -1
  99. package/dist/{sqlite-h6dta1IJ.d.ts → sqlite-BvSEbybu.d.cts} +320 -1
  100. package/dist/{sqlite-BhFswiAR.d.cts → sqlite-GKvcDPVn.d.ts} +320 -1
  101. package/dist/{store-BS_hehiz.d.ts → store-CiS_AGNH.d.ts} +112 -4
  102. package/dist/{store-CkCvqRUf.d.cts → store-DbQLsSor.d.cts} +112 -4
  103. package/dist/{types-BpgACExN.d.cts → types-CF7nDH3q.d.cts} +2 -2
  104. package/dist/{types-Bz-Pi681.d.ts → types-Cars4JZ1.d.ts} +2 -2
  105. package/dist/{types-DptZHe-l.d.ts → types-DZPBXZOK.d.cts} +272 -14
  106. package/dist/{types-WF5ItKQu.d.cts → types-Dzkr0Eqi.d.ts} +272 -14
  107. package/dist/{where-DZYMiXVq.d.cts → where-BmtjfWuS.d.cts} +2 -2
  108. package/dist/{where-C40InMIp.d.ts → where-kk1Zz2En.d.ts} +2 -2
  109. package/package.json +3 -1
  110. package/dist/chunk-AAA2CR3P.js.map +0 -1
  111. package/dist/chunk-CLEUFN2K.js.map +0 -1
  112. package/dist/chunk-CLGC7AQ2.cjs.map +0 -1
  113. package/dist/chunk-CPFR3O7L.js.map +0 -1
  114. package/dist/chunk-CQVNGKU7.cjs.map +0 -1
  115. package/dist/chunk-D2GO3RBL.cjs +0 -12
  116. package/dist/chunk-DOTEN2FG.js.map +0 -1
  117. package/dist/chunk-JTI5WT4P.cjs.map +0 -1
  118. package/dist/chunk-OECDVACY.cjs.map +0 -1
  119. package/dist/chunk-PSKUWVCB.js.map +0 -1
  120. package/dist/chunk-QMQYK3IF.cjs.map +0 -1
  121. package/dist/chunk-W5MTHMTE.cjs.map +0 -1
  122. package/dist/chunk-YZZBDCLV.js.map +0 -1
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkCQVNGKU7_cjs = require('./chunk-CQVNGKU7.cjs');
4
- var chunkOECDVACY_cjs = require('./chunk-OECDVACY.cjs');
5
- var chunkJTI5WT4P_cjs = require('./chunk-JTI5WT4P.cjs');
6
- var chunkW5MTHMTE_cjs = require('./chunk-W5MTHMTE.cjs');
3
+ var chunkTVUARC7S_cjs = require('./chunk-TVUARC7S.cjs');
4
+ var chunkDN4RUDF3_cjs = require('./chunk-DN4RUDF3.cjs');
5
+ var chunkPN37HVAV_cjs = require('./chunk-PN37HVAV.cjs');
6
+ var chunkYEDQLNVE_cjs = require('./chunk-YEDQLNVE.cjs');
7
7
  var drizzleOrm = require('drizzle-orm');
8
+ var sqliteCore = require('drizzle-orm/sqlite-core');
8
9
 
9
10
  var DEFAULT_PREPARED_STATEMENT_CACHE_MAX = 256;
10
11
  function getSessionName(db) {
@@ -20,7 +21,7 @@ function isD1DatabaseBySessionName(db) {
20
21
  }
21
22
  function isDurableObjectBySessionName(db) {
22
23
  const sessionName = getSessionName(db);
23
- return sessionName === "SQLiteDurableObjectSession";
24
+ return sessionName === "SQLiteDOSession" || sessionName === "SQLiteDurableObjectSession";
24
25
  }
25
26
  function isSyncDatabaseBySessionName(db) {
26
27
  const sessionName = getSessionName(db);
@@ -34,6 +35,9 @@ function detectSyncProfile(db, profileHints) {
34
35
  if (sessionName === "BetterSQLiteSession" || sessionName === "BunSQLiteSession") {
35
36
  return true;
36
37
  }
38
+ if (isDurableObjectBySessionName(db)) {
39
+ return true;
40
+ }
37
41
  if (sessionName === "SQLiteD1Session") {
38
42
  return false;
39
43
  }
@@ -48,7 +52,10 @@ function detectTransactionMode(db, profileHints, isSync) {
48
52
  if (profileHints.transactionMode !== void 0) {
49
53
  return profileHints.transactionMode;
50
54
  }
51
- if (isD1DatabaseBySessionName(db) || isDurableObjectBySessionName(db)) {
55
+ if (isDurableObjectBySessionName(db)) {
56
+ return "do-sqlite";
57
+ }
58
+ if (isD1DatabaseBySessionName(db)) {
52
59
  return "none";
53
60
  }
54
61
  if (isSync) return "sql";
@@ -63,7 +70,7 @@ function resolveSqliteClient(db) {
63
70
  return sqliteClient;
64
71
  }
65
72
  function getOrCreatePreparedStatement(cache, sqliteClient, sqlText, cacheMax) {
66
- return chunkCQVNGKU7_cjs.getOrCreateLru(
73
+ return chunkTVUARC7S_cjs.getOrCreateLru(
67
74
  cache,
68
75
  sqlText,
69
76
  cacheMax,
@@ -99,7 +106,7 @@ function createSqliteExecutionAdapter(db, statementCacheMaxOrOptions = {}) {
99
106
  supportsCompiledExecution: sqliteClient !== void 0,
100
107
  transactionMode
101
108
  };
102
- const compile = (query) => chunkCQVNGKU7_cjs.compileQueryWithDialect(db, query, "SQLite");
109
+ const compile = (query) => chunkTVUARC7S_cjs.compileQueryWithDialect(db, query, "SQLite");
103
110
  if (sqliteClient !== void 0) {
104
111
  let executeCompiled2 = function(compiledQuery) {
105
112
  const preparedStatement = getOrCreatePreparedStatement(
@@ -170,10 +177,10 @@ var SQLITE_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(
170
177
  1,
171
178
  SQLITE_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
172
179
  );
173
- var toNodeRow = chunkCQVNGKU7_cjs.createNodeRowMapper(chunkCQVNGKU7_cjs.SQLITE_ROW_MAPPER_CONFIG);
174
- var toEdgeRow = chunkCQVNGKU7_cjs.createEdgeRowMapper(chunkCQVNGKU7_cjs.SQLITE_ROW_MAPPER_CONFIG);
175
- var toUniqueRow = chunkCQVNGKU7_cjs.createUniqueRowMapper(chunkCQVNGKU7_cjs.SQLITE_ROW_MAPPER_CONFIG);
176
- var toSchemaVersionRow = chunkCQVNGKU7_cjs.createSchemaVersionRowMapper(chunkCQVNGKU7_cjs.SQLITE_ROW_MAPPER_CONFIG);
180
+ var toNodeRow = chunkTVUARC7S_cjs.createNodeRowMapper(chunkTVUARC7S_cjs.SQLITE_ROW_MAPPER_CONFIG);
181
+ var toEdgeRow = chunkTVUARC7S_cjs.createEdgeRowMapper(chunkTVUARC7S_cjs.SQLITE_ROW_MAPPER_CONFIG);
182
+ var toUniqueRow = chunkTVUARC7S_cjs.createUniqueRowMapper(chunkTVUARC7S_cjs.SQLITE_ROW_MAPPER_CONFIG);
183
+ var toSchemaVersionRow = chunkTVUARC7S_cjs.createSchemaVersionRowMapper(chunkTVUARC7S_cjs.SQLITE_ROW_MAPPER_CONFIG);
177
184
  var PENDING_FOREVER = new Promise(noop);
178
185
  function pendingForever() {
179
186
  return PENDING_FOREVER;
@@ -191,7 +198,7 @@ function createSerializedExecutionQueue() {
191
198
  disposed = true;
192
199
  },
193
200
  runExclusive(task) {
194
- if (isDisposed()) return Promise.reject(new chunkW5MTHMTE_cjs.BackendDisposedError());
201
+ if (isDisposed()) return Promise.reject(new chunkYEDQLNVE_cjs.BackendDisposedError());
195
202
  const runTask = async () => {
196
203
  if (isDisposed()) return pendingForever();
197
204
  try {
@@ -217,11 +224,18 @@ function runWithSerializedQueue(queue, task) {
217
224
  var SQLITE_VECTOR_METRICS = ["cosine", "l2"];
218
225
  var SQLITE_VECTOR_INDEX_TYPES = ["none"];
219
226
  var SQLITE_VECTOR_MAX_DIMENSIONS = 8e3;
227
+ function throwSqliteTransactionsDisabled(message) {
228
+ throw new chunkYEDQLNVE_cjs.ConfigurationError(message, {
229
+ backend: "sqlite",
230
+ capability: "transactions",
231
+ supportsTransactions: false
232
+ });
233
+ }
220
234
  function buildSqliteCapabilities(options) {
221
- const base = options.transactionMode === "none" ? { ...chunkOECDVACY_cjs.SQLITE_CAPABILITIES, transactions: false } : chunkOECDVACY_cjs.SQLITE_CAPABILITIES;
235
+ const base = options.transactionMode === "none" ? { ...chunkDN4RUDF3_cjs.SQLITE_CAPABILITIES, transactions: false } : chunkDN4RUDF3_cjs.SQLITE_CAPABILITIES;
222
236
  return {
223
237
  ...base,
224
- fulltext: chunkJTI5WT4P_cjs.buildFulltextCapabilities(options.fulltextStrategy),
238
+ fulltext: chunkPN37HVAV_cjs.buildFulltextCapabilities(options.fulltextStrategy),
225
239
  ...options.hasVectorEmbeddings ? {
226
240
  vector: {
227
241
  supported: true,
@@ -258,7 +272,7 @@ function createSqliteOperationBackend(options) {
258
272
  await db.run(query);
259
273
  });
260
274
  }
261
- const commonBackend = chunkCQVNGKU7_cjs.createCommonOperationBackend({
275
+ const commonBackend = chunkTVUARC7S_cjs.createCommonOperationBackend({
262
276
  batchConfig: {
263
277
  checkUniqueBatchChunkSize: SQLITE_CHECK_UNIQUE_BATCH_CHUNK_SIZE,
264
278
  edgeInsertBatchSize: SQLITE_EDGE_INSERT_BATCH_SIZE,
@@ -271,7 +285,7 @@ function createSqliteOperationBackend(options) {
271
285
  execGet,
272
286
  execRun
273
287
  },
274
- nowIso: chunkCQVNGKU7_cjs.nowIso,
288
+ nowIso: chunkTVUARC7S_cjs.nowIso,
275
289
  operationStrategy,
276
290
  rowMappers: {
277
291
  toEdgeRow,
@@ -293,7 +307,7 @@ function createSqliteOperationBackend(options) {
293
307
  async upsertEmbedding(params) {
294
308
  const query = operationStrategy.buildUpsertEmbedding(
295
309
  params,
296
- chunkCQVNGKU7_cjs.nowIso()
310
+ chunkTVUARC7S_cjs.nowIso()
297
311
  );
298
312
  await execRun(query);
299
313
  },
@@ -332,14 +346,14 @@ function createSqliteOperationBackend(options) {
332
346
  ...params.indexParams?.efConstruction === void 0 ? {} : { hnswEfConstruction: params.indexParams.efConstruction },
333
347
  ...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists }
334
348
  };
335
- const result = chunkCQVNGKU7_cjs.createSqliteVectorIndex(indexOptions);
349
+ const result = chunkTVUARC7S_cjs.createSqliteVectorIndex(indexOptions);
336
350
  if (!result.success) {
337
351
  throw new Error(result.message ?? "Failed to create SQLite vector index");
338
352
  }
339
353
  return Promise.resolve();
340
354
  },
341
355
  dropVectorIndex(params) {
342
- const result = chunkCQVNGKU7_cjs.dropSqliteVectorIndex(
356
+ const result = chunkTVUARC7S_cjs.dropSqliteVectorIndex(
343
357
  params.graphId,
344
358
  params.nodeKind,
345
359
  params.fieldPath
@@ -351,7 +365,7 @@ function createSqliteOperationBackend(options) {
351
365
  },
352
366
  // === Fulltext Operations ===
353
367
  async upsertFulltext(params) {
354
- const timestamp = chunkCQVNGKU7_cjs.nowIso();
368
+ const timestamp = chunkTVUARC7S_cjs.nowIso();
355
369
  const statements = operationStrategy.buildUpsertFulltext(
356
370
  params,
357
371
  timestamp
@@ -368,7 +382,7 @@ function createSqliteOperationBackend(options) {
368
382
  },
369
383
  async upsertFulltextBatch(params) {
370
384
  if (params.rows.length === 0) return;
371
- const timestamp = chunkCQVNGKU7_cjs.nowIso();
385
+ const timestamp = chunkTVUARC7S_cjs.nowIso();
372
386
  const statements = operationStrategy.buildUpsertFulltextBatch(
373
387
  params,
374
388
  timestamp
@@ -389,7 +403,7 @@ function createSqliteOperationBackend(options) {
389
403
  const rows = await execAll(query);
390
404
  return rows.map((row, index) => ({
391
405
  nodeId: row.node_id,
392
- score: row.score,
406
+ score: chunkTVUARC7S_cjs.coerceNumericScore(row.score),
393
407
  rank: index + 1,
394
408
  ...row.snippet === null ? {} : { snippet: row.snippet }
395
409
  }));
@@ -408,8 +422,8 @@ function createSqliteOperationBackend(options) {
408
422
  return operationBackend;
409
423
  }
410
424
  function createSqliteBackend(db, options = {}) {
411
- const tables2 = options.tables ?? chunkCQVNGKU7_cjs.tables2;
412
- const fulltextStrategy = options.fulltext ?? chunkJTI5WT4P_cjs.fts5Strategy;
425
+ const tables2 = options.tables ?? chunkTVUARC7S_cjs.tables2;
426
+ const fulltextStrategy = options.fulltext ?? chunkPN37HVAV_cjs.fts5Strategy;
413
427
  const profileHints = options.executionProfile ?? {};
414
428
  const executionAdapter = createSqliteExecutionAdapter(db, { profileHints });
415
429
  const { isSync, transactionMode } = executionAdapter.profile;
@@ -426,7 +440,7 @@ function createSqliteBackend(db, options = {}) {
426
440
  fulltext: tables2.fulltextTableName,
427
441
  uniques: drizzleOrm.getTableName(tables2.uniques)
428
442
  };
429
- const operationStrategy = chunkCQVNGKU7_cjs.createSqliteOperationStrategy(
443
+ const operationStrategy = chunkTVUARC7S_cjs.createSqliteOperationStrategy(
430
444
  tables2,
431
445
  fulltextStrategy
432
446
  );
@@ -441,15 +455,23 @@ function createSqliteBackend(db, options = {}) {
441
455
  hasVectorEmbeddings,
442
456
  ...serializedQueue === void 0 ? {} : { serializedQueue }
443
457
  });
458
+ function runDoSqliteStorageTransaction(run) {
459
+ const storage = db.$client;
460
+ const storageTransaction = storage?.transaction;
461
+ if (typeof storageTransaction !== "function") {
462
+ throwSqliteTransactionsDisabled(
463
+ "transactionMode 'do-sqlite' requires a Drizzle Durable Objects database (drizzle(ctx.storage)) whose `$client` exposes the async storage `transaction(async () => ...)` runner."
464
+ );
465
+ }
466
+ return runWithSerializedQueue(
467
+ serializedQueue,
468
+ async () => storageTransaction.call(storage, run)
469
+ );
470
+ }
444
471
  function runSchemaWriteTransaction(fn) {
445
472
  if (transactionMode === "none") {
446
- throw new chunkW5MTHMTE_cjs.ConfigurationError(
447
- "commitSchemaVersion and setActiveVersion require atomic transactions, but this SQLite backend has transactions disabled. Configure a driver that supports transactions (better-sqlite3, libsql, bun:sqlite) to use schema commits.",
448
- {
449
- backend: "sqlite",
450
- capability: "transactions",
451
- supportsTransactions: false
452
- }
473
+ throwSqliteTransactionsDisabled(
474
+ "commitSchemaVersion and setActiveVersion require atomic transactions, but this SQLite backend has transactions disabled. Configure a driver that supports transactions (better-sqlite3, libsql, bun:sqlite) to use schema commits."
453
475
  );
454
476
  }
455
477
  if (transactionMode === "sql") {
@@ -475,6 +497,20 @@ function createSqliteBackend(db, options = {}) {
475
497
  }
476
498
  });
477
499
  }
500
+ if (transactionMode === "do-sqlite") {
501
+ return runDoSqliteStorageTransaction(async () => {
502
+ const txBackend = createTransactionBackend({
503
+ capabilities,
504
+ db,
505
+ operationStrategy,
506
+ profileHints: { isSync },
507
+ tableNames,
508
+ fulltextStrategy,
509
+ hasVectorEmbeddings
510
+ });
511
+ return fn(txBackend);
512
+ });
513
+ }
478
514
  return runWithSerializedQueue(
479
515
  serializedQueue,
480
516
  async () => db.transaction(async (tx) => {
@@ -491,60 +527,91 @@ function createSqliteBackend(db, options = {}) {
491
527
  }, { behavior: "immediate" })
492
528
  );
493
529
  }
494
- let fulltextEnsured = false;
495
- async function ensureFulltextDdl() {
496
- if (fulltextEnsured) return;
497
- for (const statement of fulltextStrategy.generateDdl(
498
- tables2.fulltextTableName
499
- )) {
530
+ const matTable = tables2.contributionMaterializations;
531
+ async function ensureContributionMaterializationsTableImpl() {
532
+ await db.run(drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generateSqliteCreateTableSQL(matTable)));
533
+ }
534
+ async function getContributionMaterializationRow(identity) {
535
+ const rows = await db.select().from(matTable).where(
536
+ drizzleOrm.and(
537
+ drizzleOrm.eq(matTable.graphId, identity.graphId),
538
+ drizzleOrm.eq(matTable.logicalName, identity.logicalName),
539
+ drizzleOrm.eq(matTable.owner, identity.owner),
540
+ drizzleOrm.eq(matTable.tableName, identity.tableName)
541
+ )
542
+ );
543
+ const row = rows[0];
544
+ if (row === void 0) return void 0;
545
+ return chunkTVUARC7S_cjs.mapContributionMaterializationRow(
546
+ row,
547
+ chunkTVUARC7S_cjs.SQLITE_CONTRIBUTION_MAT_TIMESTAMPS.decode
548
+ );
549
+ }
550
+ async function recordContributionMaterializationRow(params) {
551
+ await db.insert(matTable).values(
552
+ chunkTVUARC7S_cjs.buildContributionInsertValues(
553
+ params,
554
+ chunkTVUARC7S_cjs.SQLITE_CONTRIBUTION_MAT_TIMESTAMPS.encode
555
+ )
556
+ ).onConflictDoUpdate({
557
+ target: [
558
+ matTable.graphId,
559
+ matTable.logicalName,
560
+ matTable.owner,
561
+ matTable.tableName
562
+ ],
563
+ set: chunkTVUARC7S_cjs.buildContributionOnConflictSet(
564
+ matTable.materializedAt,
565
+ params.materializedAt
566
+ )
567
+ });
568
+ }
569
+ const contributionMaterializer = chunkTVUARC7S_cjs.createContributionMaterializer({
570
+ dialect: "sqlite",
571
+ fulltextStrategy,
572
+ fulltextTableName: tables2.fulltextTableName,
573
+ execDdl: async (statement) => {
500
574
  await db.run(drizzleOrm.sql.raw(statement));
501
- }
502
- fulltextEnsured = true;
575
+ },
576
+ ensureMarkerTable: ensureContributionMaterializationsTableImpl,
577
+ getMarker: getContributionMaterializationRow,
578
+ recordMarker: recordContributionMaterializationRow
579
+ });
580
+ function bindTransactionBackend(tx) {
581
+ const txBackend = createTransactionBackend({
582
+ capabilities,
583
+ db: tx,
584
+ operationStrategy,
585
+ profileHints: { isSync },
586
+ tableNames,
587
+ fulltextStrategy,
588
+ hasVectorEmbeddings
589
+ });
590
+ return chunkTVUARC7S_cjs.gateFulltext(txBackend, contributionMaterializer.assertInitialized);
503
591
  }
504
592
  const backend = {
505
593
  ...operations,
506
594
  async bootstrapTables() {
507
- const statements = chunkCQVNGKU7_cjs.generateSqliteDDL(tables2, fulltextStrategy);
595
+ const statements = chunkTVUARC7S_cjs.generateSqliteDDL(tables2, fulltextStrategy);
508
596
  for (const statement of statements) {
509
597
  await db.run(drizzleOrm.sql.raw(statement));
510
598
  }
511
- fulltextEnsured = true;
512
- },
513
- async upsertFulltext(params) {
514
- await ensureFulltextDdl();
515
- await operations.upsertFulltext(params);
516
- },
517
- async deleteFulltext(params) {
518
- await ensureFulltextDdl();
519
- await operations.deleteFulltext(params);
520
- },
521
- async upsertFulltextBatch(params) {
522
- if (params.rows.length === 0) return;
523
- await ensureFulltextDdl();
524
- await operations.upsertFulltextBatch(params);
525
- },
526
- async deleteFulltextBatch(params) {
527
- if (params.nodeIds.length === 0) return;
528
- await ensureFulltextDdl();
529
- await operations.deleteFulltextBatch(params);
530
- },
531
- async fulltextSearch(params) {
532
- await ensureFulltextDdl();
533
- return operations.fulltextSearch(params);
534
- },
535
- // hardDeleteNode is wrapped because the operation-backend-core
536
- // cascade unconditionally deletes from the fulltext table — it
537
- // would fail even on graphs that declare no searchable() fields.
538
- async hardDeleteNode(params) {
539
- await ensureFulltextDdl();
540
- await operations.hardDeleteNode(params);
541
599
  },
600
+ // Every fulltext-touching method asserts the durable marker instead
601
+ // of lazily emitting DDL. Steady state performs zero ensure; an
602
+ // uninitialized database throws `StoreNotInitializedError` rather
603
+ // than self-healing (#135). Shared verbatim with the tx-scoped gate
604
+ // via `gateFulltextMethods`.
605
+ ...chunkTVUARC7S_cjs.gateFulltextMethods(
606
+ operations,
607
+ contributionMaterializer.assertInitialized
608
+ ),
542
609
  async executeDdl(ddl) {
543
610
  await db.run(drizzleOrm.sql.raw(ddl));
544
611
  },
545
612
  async ensureIndexMaterializationsTable() {
546
613
  await db.run(
547
- drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generateSqliteCreateTableSQL(tables2.indexMaterializations))
614
+ drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generateSqliteCreateTableSQL(tables2.indexMaterializations))
548
615
  );
549
616
  },
550
617
  async getIndexMaterialization(indexName) {
@@ -552,67 +619,87 @@ function createSqliteBackend(db, options = {}) {
552
619
  const rows = await db.select().from(t).where(drizzleOrm.eq(t.indexName, indexName));
553
620
  const row = rows[0];
554
621
  if (row === void 0) return void 0;
555
- return chunkCQVNGKU7_cjs.mapMaterializationRow(row, chunkCQVNGKU7_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.decode);
622
+ return chunkTVUARC7S_cjs.mapMaterializationRow(row, chunkTVUARC7S_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.decode);
556
623
  },
557
624
  async getIndexMaterializations(statusKeys) {
558
625
  if (statusKeys.length === 0) return [];
559
626
  const t = tables2.indexMaterializations;
560
627
  const rows = await db.select().from(t).where(drizzleOrm.inArray(t.indexName, [...statusKeys]));
561
628
  return rows.map(
562
- (row) => chunkCQVNGKU7_cjs.mapMaterializationRow(row, chunkCQVNGKU7_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.decode)
629
+ (row) => chunkTVUARC7S_cjs.mapMaterializationRow(row, chunkTVUARC7S_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.decode)
563
630
  );
564
631
  },
565
632
  async recordIndexMaterialization(params) {
566
633
  const t = tables2.indexMaterializations;
567
634
  await db.insert(t).values(
568
- chunkCQVNGKU7_cjs.buildMaterializationInsertValues(
635
+ chunkTVUARC7S_cjs.buildMaterializationInsertValues(
569
636
  params,
570
- chunkCQVNGKU7_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.encode
637
+ chunkTVUARC7S_cjs.SQLITE_INDEX_MAT_TIMESTAMPS.encode
571
638
  )
572
639
  ).onConflictDoUpdate({
573
640
  target: t.indexName,
574
- set: chunkCQVNGKU7_cjs.buildMaterializationOnConflictSet(
641
+ set: chunkTVUARC7S_cjs.buildMaterializationOnConflictSet(
575
642
  t.materializedAt,
576
643
  params.materializedAt
577
644
  )
578
645
  });
579
646
  },
647
+ async ensureContributionMaterializationsTable() {
648
+ await ensureContributionMaterializationsTableImpl();
649
+ },
650
+ async getContributionMaterialization(identity) {
651
+ return getContributionMaterializationRow(identity);
652
+ },
653
+ async recordContributionMaterialization(params) {
654
+ await recordContributionMaterializationRow(params);
655
+ },
656
+ async assertRuntimeContributionsInitialized(graphId) {
657
+ await contributionMaterializer.assertInitialized(graphId);
658
+ },
580
659
  async ensureKindRemovalsTable() {
581
- await db.run(drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generateSqliteCreateTableSQL(tables2.kindRemovals)));
660
+ await db.run(drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generateSqliteCreateTableSQL(tables2.kindRemovals)));
582
661
  },
583
662
  async getPendingKindRemovals(graphId) {
584
663
  const t = tables2.kindRemovals;
585
664
  const rows = await db.select().from(t).where(drizzleOrm.and(drizzleOrm.eq(t.graphId, graphId), drizzleOrm.isNull(t.removedAt)));
586
665
  return rows.map(
587
- (row) => chunkCQVNGKU7_cjs.mapKindRemovalRow(row, chunkCQVNGKU7_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.decode)
666
+ (row) => chunkTVUARC7S_cjs.mapKindRemovalRow(row, chunkTVUARC7S_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.decode)
588
667
  );
589
668
  },
590
669
  async getAllKindRemovals(graphId) {
591
670
  const t = tables2.kindRemovals;
592
671
  const rows = await db.select().from(t).where(drizzleOrm.eq(t.graphId, graphId));
593
672
  return rows.map(
594
- (row) => chunkCQVNGKU7_cjs.mapKindRemovalRow(row, chunkCQVNGKU7_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.decode)
673
+ (row) => chunkTVUARC7S_cjs.mapKindRemovalRow(row, chunkTVUARC7S_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.decode)
595
674
  );
596
675
  },
597
676
  async recordKindRemoval(params) {
598
677
  const t = tables2.kindRemovals;
599
678
  await db.insert(t).values(
600
- chunkCQVNGKU7_cjs.buildKindRemovalInsertValues(
679
+ chunkTVUARC7S_cjs.buildKindRemovalInsertValues(
601
680
  params,
602
- chunkCQVNGKU7_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.encode
681
+ chunkTVUARC7S_cjs.SQLITE_KIND_REMOVAL_TIMESTAMPS.encode
603
682
  )
604
683
  ).onConflictDoUpdate({
605
684
  target: [t.graphId, t.kindName, t.entity, t.schemaVersion],
606
- set: chunkCQVNGKU7_cjs.buildKindRemovalOnConflictSet(t.removedAt, params.removedAt)
685
+ set: chunkTVUARC7S_cjs.buildKindRemovalOnConflictSet(t.removedAt, params.removedAt)
607
686
  });
608
687
  },
609
688
  async ensureReconciliationMarkersTable() {
610
689
  await db.run(
611
- drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generateSqliteCreateTableSQL(tables2.reconciliationMarkers))
690
+ drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generateSqliteCreateTableSQL(tables2.reconciliationMarkers))
612
691
  );
613
692
  },
614
- async ensureFulltextTable() {
615
- await ensureFulltextDdl();
693
+ async ensureRuntimeContributions(graphId) {
694
+ await contributionMaterializer.ensureRuntimeContributions(graphId);
695
+ },
696
+ /**
697
+ * Superseded by `ensureRuntimeContributions(graphId)` (#129).
698
+ * Retained as a thin back-compat wrapper for callers predating
699
+ * #129; #135 routed it through the durable-marker writer.
700
+ */
701
+ async ensureFulltextTable(graphId) {
702
+ await contributionMaterializer.ensureRuntimeContributions(graphId);
616
703
  },
617
704
  async getReconciliationMarker(graphId) {
618
705
  const t = tables2.reconciliationMarkers;
@@ -641,16 +728,10 @@ function createSqliteBackend(db, options = {}) {
641
728
  },
642
729
  async transaction(fn, _options) {
643
730
  if (transactionMode === "none") {
644
- throw new chunkW5MTHMTE_cjs.ConfigurationError(
645
- "This SQLite backend does not support atomic transactions. Operations within a transaction are not rolled back on failure. Use backend.capabilities.transactions to check for transaction support, or use individual operations with manual error handling.",
646
- {
647
- backend: "sqlite",
648
- capability: "transactions",
649
- supportsTransactions: false
650
- }
731
+ throwSqliteTransactionsDisabled(
732
+ "This SQLite backend does not support atomic transactions. Operations within a transaction are not rolled back on failure. Use backend.capabilities.transactions to check for transaction support, or use individual operations with manual error handling."
651
733
  );
652
734
  }
653
- await ensureFulltextDdl();
654
735
  if (transactionMode === "sql") {
655
736
  return runWithSerializedQueue(serializedQueue, async () => {
656
737
  const txBackend = createTransactionBackend({
@@ -665,7 +746,13 @@ function createSqliteBackend(db, options = {}) {
665
746
  });
666
747
  db.run(drizzleOrm.sql`BEGIN`);
667
748
  try {
668
- const result = await fn(txBackend);
749
+ const result = await fn(
750
+ chunkTVUARC7S_cjs.gateFulltext(
751
+ txBackend,
752
+ contributionMaterializer.assertInitialized
753
+ ),
754
+ db
755
+ );
669
756
  db.run(drizzleOrm.sql`COMMIT`);
670
757
  return result;
671
758
  } catch (error) {
@@ -674,21 +761,30 @@ function createSqliteBackend(db, options = {}) {
674
761
  }
675
762
  });
676
763
  }
764
+ if (transactionMode === "do-sqlite") {
765
+ return runDoSqliteStorageTransaction(
766
+ async () => fn(bindTransactionBackend(db), db)
767
+ );
768
+ }
677
769
  return runWithSerializedQueue(
678
770
  serializedQueue,
679
- async () => db.transaction(async (tx) => {
680
- const txBackend = createTransactionBackend({
681
- capabilities,
682
- db: tx,
683
- operationStrategy,
684
- profileHints: { isSync },
685
- tableNames,
686
- fulltextStrategy,
687
- hasVectorEmbeddings
688
- });
689
- return fn(txBackend);
690
- })
771
+ async () => db.transaction(
772
+ async (tx) => fn(bindTransactionBackend(tx), tx)
773
+ )
774
+ );
775
+ },
776
+ adoptTransaction(externalTx) {
777
+ if (transactionMode === "none") {
778
+ throwSqliteTransactionsDisabled(
779
+ "Cross-store atomicity is unavailable on this SQLite backend: transactions are disabled (transactionMode: 'none'). Adopting an external transaction here would let the caller's relational write commit with no way to roll back the graph write. Configure a driver that supports transactions (better-sqlite3, libsql, bun:sqlite)."
780
+ );
781
+ }
782
+ chunkTVUARC7S_cjs.assertAdoptedDialect(
783
+ externalTx,
784
+ sqliteCore.BaseSQLiteDatabase,
785
+ "sqlite"
691
786
  );
787
+ return bindTransactionBackend(externalTx);
692
788
  },
693
789
  close() {
694
790
  serializedQueue?.dispose();
@@ -713,5 +809,5 @@ function createTransactionBackend(options) {
713
809
  }
714
810
 
715
811
  exports.createSqliteBackend = createSqliteBackend;
716
- //# sourceMappingURL=chunk-CLGC7AQ2.cjs.map
717
- //# sourceMappingURL=chunk-CLGC7AQ2.cjs.map
812
+ //# sourceMappingURL=chunk-RVT2N4RF.cjs.map
813
+ //# sourceMappingURL=chunk-RVT2N4RF.cjs.map