@nicia-ai/typegraph 0.25.1 → 0.27.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-4FJVSF3K.cjs +12 -0
  24. package/dist/{chunk-D2GO3RBL.cjs.map → chunk-4FJVSF3K.cjs.map} +1 -1
  25. package/dist/chunk-5H3BAMTB.js +32 -0
  26. package/dist/chunk-5H3BAMTB.js.map +1 -0
  27. package/dist/{chunk-CLEUFN2K.js → chunk-DDVA4QBA.js} +174 -78
  28. package/dist/chunk-DDVA4QBA.js.map +1 -0
  29. package/dist/{chunk-OECDVACY.cjs → chunk-DN4RUDF3.cjs} +2 -2
  30. package/dist/chunk-DN4RUDF3.cjs.map +1 -0
  31. package/dist/{chunk-NHQWXSTS.js → chunk-E5ROA3MN.js} +3 -3
  32. package/dist/{chunk-NHQWXSTS.js.map → chunk-E5ROA3MN.js.map} +1 -1
  33. package/dist/{chunk-CPFR3O7L.js → chunk-ENXJLDRK.js} +2 -2
  34. package/dist/chunk-ENXJLDRK.js.map +1 -0
  35. package/dist/chunk-IUIWCFG3.cjs +36 -0
  36. package/dist/chunk-IUIWCFG3.cjs.map +1 -0
  37. package/dist/{chunk-EG6TJ3I5.js → chunk-OYLF3IC7.js} +3 -3
  38. package/dist/{chunk-EG6TJ3I5.js.map → chunk-OYLF3IC7.js.map} +1 -1
  39. package/dist/{chunk-JTI5WT4P.cjs → chunk-PN37HVAV.cjs} +32 -10
  40. package/dist/chunk-PN37HVAV.cjs.map +1 -0
  41. package/dist/{chunk-RCAJZG67.cjs → chunk-PYJOBZR3.cjs} +10 -10
  42. package/dist/{chunk-RCAJZG67.cjs.map → chunk-PYJOBZR3.cjs.map} +1 -1
  43. package/dist/{chunk-PSKUWVCB.js → chunk-RF5EUQWS.js} +336 -36
  44. package/dist/chunk-RF5EUQWS.js.map +1 -0
  45. package/dist/{chunk-CLGC7AQ2.cjs → chunk-RVT2N4RF.cjs} +206 -110
  46. package/dist/chunk-RVT2N4RF.cjs.map +1 -0
  47. package/dist/{chunk-4BOWVUGQ.js → chunk-TSGBRPNE.js} +3 -3
  48. package/dist/{chunk-4BOWVUGQ.js.map → chunk-TSGBRPNE.js.map} +1 -1
  49. package/dist/{chunk-CQVNGKU7.cjs → chunk-TVUARC7S.cjs} +410 -100
  50. package/dist/chunk-TVUARC7S.cjs.map +1 -0
  51. package/dist/{chunk-DOTEN2FG.js → chunk-U5ROKVRF.js} +26 -3
  52. package/dist/chunk-U5ROKVRF.js.map +1 -0
  53. package/dist/{chunk-E5JZSEGJ.cjs → chunk-WFUN6DCM.cjs} +8 -8
  54. package/dist/{chunk-E5JZSEGJ.cjs.map → chunk-WFUN6DCM.cjs.map} +1 -1
  55. package/dist/{chunk-AAA2CR3P.js → chunk-X53YKGHR.js} +78 -37
  56. package/dist/chunk-X53YKGHR.js.map +1 -0
  57. package/dist/{chunk-W5MTHMTE.cjs → chunk-YEDQLNVE.cjs} +26 -2
  58. package/dist/chunk-YEDQLNVE.cjs.map +1 -0
  59. package/dist/{chunk-QMQYK3IF.cjs → chunk-ZGEMI7MJ.cjs} +163 -122
  60. package/dist/chunk-ZGEMI7MJ.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 +482 -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 +153 -37
  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-CWa9cgwb.d.cts} +36 -9
  88. package/dist/{manager-sZkU2VPC.d.ts → manager-Cfcb2sJL.d.ts} +36 -9
  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 +32 -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-C57kdvAa.d.ts} +155 -5
  102. package/dist/{store-CkCvqRUf.d.cts → store-Ojf0NOKk.d.cts} +155 -5
  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,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkHTGDWIDE_cjs = require('../../chunk-HTGDWIDE.cjs');
4
- var chunkCQVNGKU7_cjs = require('../../chunk-CQVNGKU7.cjs');
5
- var chunkOECDVACY_cjs = require('../../chunk-OECDVACY.cjs');
6
- var chunkJTI5WT4P_cjs = require('../../chunk-JTI5WT4P.cjs');
4
+ var chunkTVUARC7S_cjs = require('../../chunk-TVUARC7S.cjs');
5
+ var chunkDN4RUDF3_cjs = require('../../chunk-DN4RUDF3.cjs');
6
+ require('../../chunk-IUIWCFG3.cjs');
7
+ var chunkPN37HVAV_cjs = require('../../chunk-PN37HVAV.cjs');
7
8
  require('../../chunk-CTHNVU6K.cjs');
8
9
  require('../../chunk-EK6RJ373.cjs');
9
10
  require('../../chunk-X3244EKP.cjs');
10
- var chunkW5MTHMTE_cjs = require('../../chunk-W5MTHMTE.cjs');
11
+ var chunkYEDQLNVE_cjs = require('../../chunk-YEDQLNVE.cjs');
11
12
  require('../../chunk-7V335GHG.cjs');
12
13
  var drizzleOrm = require('drizzle-orm');
14
+ var pgCore = require('drizzle-orm/pg-core');
13
15
 
14
16
  // src/backend/drizzle/execution/postgres-execution.ts
15
17
  function hasFunctionProperty(value, property) {
@@ -33,7 +35,7 @@ var DEFAULT_POSTGRES_STATEMENT_CACHE_MAX = 256;
33
35
  var STATEMENT_NAME_CACHE = /* @__PURE__ */ new Map();
34
36
  var nextStatementId = 0;
35
37
  function statementNameFor(sqlText, cacheMax) {
36
- return chunkCQVNGKU7_cjs.getOrCreateLru(STATEMENT_NAME_CACHE, sqlText, cacheMax, () => {
38
+ return chunkTVUARC7S_cjs.getOrCreateLru(STATEMENT_NAME_CACHE, sqlText, cacheMax, () => {
37
39
  const name = `tg_${nextStatementId}`;
38
40
  nextStatementId += 1;
39
41
  return name;
@@ -124,7 +126,7 @@ function createPostgresExecutionAdapter(db, options = {}) {
124
126
  const cacheMax = options.preparedStatementCacheMax ?? DEFAULT_POSTGRES_STATEMENT_CACHE_MAX;
125
127
  const pgClient = resolvePgClient(db, prepareStatements, cacheMax);
126
128
  function compile(query) {
127
- return chunkCQVNGKU7_cjs.compileQueryWithDialect(db, query, "PostgreSQL");
129
+ return chunkTVUARC7S_cjs.compileQueryWithDialect(db, query, "PostgreSQL");
128
130
  }
129
131
  if (pgClient === void 0) {
130
132
  return {
@@ -180,10 +182,10 @@ var POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(
180
182
  1,
181
183
  POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
182
184
  );
183
- var toNodeRow = chunkCQVNGKU7_cjs.createNodeRowMapper(chunkCQVNGKU7_cjs.POSTGRES_ROW_MAPPER_CONFIG);
184
- var toEdgeRow = chunkCQVNGKU7_cjs.createEdgeRowMapper(chunkCQVNGKU7_cjs.POSTGRES_ROW_MAPPER_CONFIG);
185
- var toUniqueRow = chunkCQVNGKU7_cjs.createUniqueRowMapper(chunkCQVNGKU7_cjs.POSTGRES_ROW_MAPPER_CONFIG);
186
- var toSchemaVersionRow = chunkCQVNGKU7_cjs.createSchemaVersionRowMapper(chunkCQVNGKU7_cjs.POSTGRES_ROW_MAPPER_CONFIG);
185
+ var toNodeRow = chunkTVUARC7S_cjs.createNodeRowMapper(chunkTVUARC7S_cjs.POSTGRES_ROW_MAPPER_CONFIG);
186
+ var toEdgeRow = chunkTVUARC7S_cjs.createEdgeRowMapper(chunkTVUARC7S_cjs.POSTGRES_ROW_MAPPER_CONFIG);
187
+ var toUniqueRow = chunkTVUARC7S_cjs.createUniqueRowMapper(chunkTVUARC7S_cjs.POSTGRES_ROW_MAPPER_CONFIG);
188
+ var toSchemaVersionRow = chunkTVUARC7S_cjs.createSchemaVersionRowMapper(chunkTVUARC7S_cjs.POSTGRES_ROW_MAPPER_CONFIG);
187
189
  function toEmbeddingRow(row) {
188
190
  let embedding;
189
191
  if (typeof row.embedding === "string") {
@@ -201,23 +203,13 @@ function toEmbeddingRow(row) {
201
203
  field_path: row.field_path,
202
204
  embedding,
203
205
  dimensions: row.dimensions,
204
- created_at: chunkCQVNGKU7_cjs.formatPostgresTimestamp(row.created_at) ?? "",
205
- updated_at: chunkCQVNGKU7_cjs.formatPostgresTimestamp(row.updated_at) ?? ""
206
+ created_at: chunkTVUARC7S_cjs.formatPostgresTimestamp(row.created_at) ?? "",
207
+ updated_at: chunkTVUARC7S_cjs.formatPostgresTimestamp(row.updated_at) ?? ""
206
208
  };
207
209
  }
208
- function coerceNumericScore(value) {
209
- if (typeof value === "number") return value;
210
- const parsed = Number.parseFloat(value);
211
- if (Number.isNaN(parsed)) {
212
- throw new TypeError(
213
- `Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`
214
- );
215
- }
216
- return parsed;
217
- }
218
210
  function buildPostgresCapabilities(strategy) {
219
211
  return {
220
- ...chunkOECDVACY_cjs.POSTGRES_CAPABILITIES,
212
+ ...chunkDN4RUDF3_cjs.POSTGRES_CAPABILITIES,
221
213
  vector: {
222
214
  supported: true,
223
215
  metrics: ["cosine", "l2", "inner_product"],
@@ -225,12 +217,12 @@ function buildPostgresCapabilities(strategy) {
225
217
  maxDimensions: 16e3
226
218
  // pgvector limit
227
219
  },
228
- fulltext: chunkJTI5WT4P_cjs.buildFulltextCapabilities(strategy)
220
+ fulltext: chunkPN37HVAV_cjs.buildFulltextCapabilities(strategy)
229
221
  };
230
222
  }
231
223
  function createPostgresBackend(db, options = {}) {
232
- const tables2 = options.tables ?? chunkCQVNGKU7_cjs.tables;
233
- const fulltextStrategy = options.fulltext ?? chunkJTI5WT4P_cjs.tsvectorStrategy;
224
+ const tables2 = options.tables ?? chunkTVUARC7S_cjs.tables;
225
+ const fulltextStrategy = options.fulltext ?? chunkPN37HVAV_cjs.tsvectorStrategy;
234
226
  const baseCapabilities = buildPostgresCapabilities(fulltextStrategy);
235
227
  const httpOnlyOverrides = isNeonHttpClient(db) ? { transactions: false } : {};
236
228
  const capabilities = {
@@ -260,7 +252,7 @@ function createPostgresBackend(db, options = {}) {
260
252
  ].map((name) => chunkHTGDWIDE_cjs.quoteIdentifier(name)),
261
253
  drizzleOrm.sql`, `
262
254
  )}`;
263
- const operationStrategy = chunkCQVNGKU7_cjs.createPostgresOperationStrategy(
255
+ const operationStrategy = chunkTVUARC7S_cjs.createPostgresOperationStrategy(
264
256
  tables2,
265
257
  fulltextStrategy
266
258
  );
@@ -274,7 +266,7 @@ function createPostgresBackend(db, options = {}) {
274
266
  });
275
267
  function runSchemaWriteTransaction(graphId, fn) {
276
268
  if (!capabilities.transactions) {
277
- throw new chunkW5MTHMTE_cjs.ConfigurationError(
269
+ throw new chunkYEDQLNVE_cjs.ConfigurationError(
278
270
  "commitSchemaVersion and setActiveVersion require atomic transactions, but this Postgres backend does not provide them. The drizzle-orm/neon-http driver communicates over HTTP and cannot hold a session across statements; use drizzle-orm/neon-serverless (websocket) for transactional writes.",
279
271
  {
280
272
  backend: "postgres",
@@ -298,60 +290,90 @@ function createPostgresBackend(db, options = {}) {
298
290
  return fn(txBackend);
299
291
  });
300
292
  }
301
- let fulltextEnsured = false;
302
- async function ensureFulltextDdl() {
303
- if (fulltextEnsured) return;
304
- for (const statement of fulltextStrategy.generateDdl(
305
- tables2.fulltextTableName
306
- )) {
293
+ const matTable = tables2.contributionMaterializations;
294
+ async function ensureContributionMaterializationsTableImpl() {
295
+ await db.execute(drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generatePgCreateTableSQL(matTable)));
296
+ }
297
+ async function getContributionMaterializationRow(identity) {
298
+ const rows = await db.select().from(matTable).where(
299
+ drizzleOrm.and(
300
+ drizzleOrm.eq(matTable.graphId, identity.graphId),
301
+ drizzleOrm.eq(matTable.logicalName, identity.logicalName),
302
+ drizzleOrm.eq(matTable.owner, identity.owner),
303
+ drizzleOrm.eq(matTable.tableName, identity.tableName)
304
+ )
305
+ );
306
+ const row = rows[0];
307
+ if (row === void 0) return void 0;
308
+ return chunkTVUARC7S_cjs.mapContributionMaterializationRow(
309
+ row,
310
+ chunkTVUARC7S_cjs.POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS.decode
311
+ );
312
+ }
313
+ async function recordContributionMaterializationRow(params) {
314
+ await db.insert(matTable).values(
315
+ chunkTVUARC7S_cjs.buildContributionInsertValues(
316
+ params,
317
+ chunkTVUARC7S_cjs.POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS.encode
318
+ )
319
+ ).onConflictDoUpdate({
320
+ target: [
321
+ matTable.graphId,
322
+ matTable.logicalName,
323
+ matTable.owner,
324
+ matTable.tableName
325
+ ],
326
+ set: chunkTVUARC7S_cjs.buildContributionOnConflictSet(
327
+ matTable.materializedAt,
328
+ params.materializedAt
329
+ )
330
+ });
331
+ }
332
+ const contributionMaterializer = chunkTVUARC7S_cjs.createContributionMaterializer({
333
+ dialect: "postgres",
334
+ fulltextStrategy,
335
+ fulltextTableName: tables2.fulltextTableName,
336
+ execDdl: async (statement) => {
307
337
  await db.execute(drizzleOrm.sql.raw(statement));
308
- }
309
- fulltextEnsured = true;
338
+ },
339
+ ensureMarkerTable: ensureContributionMaterializationsTableImpl,
340
+ getMarker: getContributionMaterializationRow,
341
+ recordMarker: recordContributionMaterializationRow
342
+ });
343
+ function bindTransactionBackend(tx) {
344
+ const txBackend = createTransactionBackend({
345
+ db: tx,
346
+ adapterOptions,
347
+ operationStrategy,
348
+ tableNames,
349
+ capabilities,
350
+ fulltextStrategy
351
+ });
352
+ return chunkTVUARC7S_cjs.gateFulltext(txBackend, contributionMaterializer.assertInitialized);
310
353
  }
311
354
  const backend = {
312
355
  ...operations,
313
356
  async bootstrapTables() {
314
- const statements = chunkCQVNGKU7_cjs.generatePostgresDDL(tables2, fulltextStrategy);
357
+ const statements = chunkTVUARC7S_cjs.generatePostgresDDL(tables2, fulltextStrategy);
315
358
  for (const statement of statements) {
316
359
  await db.execute(drizzleOrm.sql.raw(statement));
317
360
  }
318
- fulltextEnsured = true;
319
- },
320
- async upsertFulltext(params) {
321
- await ensureFulltextDdl();
322
- await operations.upsertFulltext(params);
323
- },
324
- async deleteFulltext(params) {
325
- await ensureFulltextDdl();
326
- await operations.deleteFulltext(params);
327
- },
328
- async upsertFulltextBatch(params) {
329
- if (params.rows.length === 0) return;
330
- await ensureFulltextDdl();
331
- await operations.upsertFulltextBatch(params);
332
- },
333
- async deleteFulltextBatch(params) {
334
- if (params.nodeIds.length === 0) return;
335
- await ensureFulltextDdl();
336
- await operations.deleteFulltextBatch(params);
337
- },
338
- async fulltextSearch(params) {
339
- await ensureFulltextDdl();
340
- return operations.fulltextSearch(params);
341
- },
342
- // hardDeleteNode is wrapped because the operation-backend-core
343
- // cascade unconditionally deletes from the fulltext table — it
344
- // would fail even on graphs that declare no searchable() fields.
345
- async hardDeleteNode(params) {
346
- await ensureFulltextDdl();
347
- await operations.hardDeleteNode(params);
348
361
  },
362
+ // Every fulltext-touching method asserts the durable marker instead
363
+ // of lazily emitting DDL. Steady state performs zero ensure; an
364
+ // uninitialized database throws `StoreNotInitializedError` loudly
365
+ // rather than self-healing on a read/write path (#135). Shared
366
+ // verbatim with the tx-scoped gate via `gateFulltextMethods`.
367
+ ...chunkTVUARC7S_cjs.gateFulltextMethods(
368
+ operations,
369
+ contributionMaterializer.assertInitialized
370
+ ),
349
371
  async executeDdl(ddl) {
350
372
  await db.execute(drizzleOrm.sql.raw(ddl));
351
373
  },
352
374
  async ensureIndexMaterializationsTable() {
353
375
  await db.execute(
354
- drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generatePgCreateTableSQL(tables2.indexMaterializations))
376
+ drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generatePgCreateTableSQL(tables2.indexMaterializations))
355
377
  );
356
378
  },
357
379
  async getIndexMaterialization(indexName) {
@@ -359,69 +381,89 @@ function createPostgresBackend(db, options = {}) {
359
381
  const rows = await db.select().from(t).where(drizzleOrm.eq(t.indexName, indexName));
360
382
  const row = rows[0];
361
383
  if (row === void 0) return void 0;
362
- return chunkCQVNGKU7_cjs.mapMaterializationRow(row, chunkCQVNGKU7_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.decode);
384
+ return chunkTVUARC7S_cjs.mapMaterializationRow(row, chunkTVUARC7S_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.decode);
363
385
  },
364
386
  async getIndexMaterializations(statusKeys) {
365
387
  if (statusKeys.length === 0) return [];
366
388
  const t = tables2.indexMaterializations;
367
389
  const rows = await db.select().from(t).where(drizzleOrm.inArray(t.indexName, [...statusKeys]));
368
390
  return rows.map(
369
- (row) => chunkCQVNGKU7_cjs.mapMaterializationRow(row, chunkCQVNGKU7_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.decode)
391
+ (row) => chunkTVUARC7S_cjs.mapMaterializationRow(row, chunkTVUARC7S_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.decode)
370
392
  );
371
393
  },
372
394
  async recordIndexMaterialization(params) {
373
395
  const t = tables2.indexMaterializations;
374
396
  await db.insert(t).values(
375
- chunkCQVNGKU7_cjs.buildMaterializationInsertValues(
397
+ chunkTVUARC7S_cjs.buildMaterializationInsertValues(
376
398
  params,
377
- chunkCQVNGKU7_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.encode
399
+ chunkTVUARC7S_cjs.POSTGRES_INDEX_MAT_TIMESTAMPS.encode
378
400
  )
379
401
  ).onConflictDoUpdate({
380
402
  target: t.indexName,
381
- set: chunkCQVNGKU7_cjs.buildMaterializationOnConflictSet(
403
+ set: chunkTVUARC7S_cjs.buildMaterializationOnConflictSet(
382
404
  t.materializedAt,
383
405
  params.materializedAt
384
406
  )
385
407
  });
386
408
  },
409
+ async ensureContributionMaterializationsTable() {
410
+ await ensureContributionMaterializationsTableImpl();
411
+ },
412
+ async getContributionMaterialization(identity) {
413
+ return getContributionMaterializationRow(identity);
414
+ },
415
+ async recordContributionMaterialization(params) {
416
+ await recordContributionMaterializationRow(params);
417
+ },
418
+ async assertRuntimeContributionsInitialized(graphId) {
419
+ await contributionMaterializer.assertInitialized(graphId);
420
+ },
387
421
  async ensureKindRemovalsTable() {
388
422
  await db.execute(
389
- drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generatePgCreateTableSQL(tables2.kindRemovals))
423
+ drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generatePgCreateTableSQL(tables2.kindRemovals))
390
424
  );
391
425
  },
392
426
  async getPendingKindRemovals(graphId) {
393
427
  const t = tables2.kindRemovals;
394
428
  const rows = await db.select().from(t).where(drizzleOrm.and(drizzleOrm.eq(t.graphId, graphId), drizzleOrm.isNull(t.removedAt)));
395
429
  return rows.map(
396
- (row) => chunkCQVNGKU7_cjs.mapKindRemovalRow(row, chunkCQVNGKU7_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
430
+ (row) => chunkTVUARC7S_cjs.mapKindRemovalRow(row, chunkTVUARC7S_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
397
431
  );
398
432
  },
399
433
  async getAllKindRemovals(graphId) {
400
434
  const t = tables2.kindRemovals;
401
435
  const rows = await db.select().from(t).where(drizzleOrm.eq(t.graphId, graphId));
402
436
  return rows.map(
403
- (row) => chunkCQVNGKU7_cjs.mapKindRemovalRow(row, chunkCQVNGKU7_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
437
+ (row) => chunkTVUARC7S_cjs.mapKindRemovalRow(row, chunkTVUARC7S_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
404
438
  );
405
439
  },
406
440
  async recordKindRemoval(params) {
407
441
  const t = tables2.kindRemovals;
408
442
  await db.insert(t).values(
409
- chunkCQVNGKU7_cjs.buildKindRemovalInsertValues(
443
+ chunkTVUARC7S_cjs.buildKindRemovalInsertValues(
410
444
  params,
411
- chunkCQVNGKU7_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.encode
445
+ chunkTVUARC7S_cjs.POSTGRES_KIND_REMOVAL_TIMESTAMPS.encode
412
446
  )
413
447
  ).onConflictDoUpdate({
414
448
  target: [t.graphId, t.kindName, t.entity, t.schemaVersion],
415
- set: chunkCQVNGKU7_cjs.buildKindRemovalOnConflictSet(t.removedAt, params.removedAt)
449
+ set: chunkTVUARC7S_cjs.buildKindRemovalOnConflictSet(t.removedAt, params.removedAt)
416
450
  });
417
451
  },
418
452
  async ensureReconciliationMarkersTable() {
419
453
  await db.execute(
420
- drizzleOrm.sql.raw(chunkCQVNGKU7_cjs.generatePgCreateTableSQL(tables2.reconciliationMarkers))
454
+ drizzleOrm.sql.raw(chunkTVUARC7S_cjs.generatePgCreateTableSQL(tables2.reconciliationMarkers))
421
455
  );
422
456
  },
423
- async ensureFulltextTable() {
424
- await ensureFulltextDdl();
457
+ async ensureRuntimeContributions(graphId) {
458
+ await contributionMaterializer.ensureRuntimeContributions(graphId);
459
+ },
460
+ /**
461
+ * Superseded by `ensureRuntimeContributions(graphId)` (#129).
462
+ * Retained as a thin back-compat wrapper for callers predating
463
+ * #129; #135 routed it through the durable-marker writer.
464
+ */
465
+ async ensureFulltextTable(graphId) {
466
+ await contributionMaterializer.ensureRuntimeContributions(graphId);
425
467
  },
426
468
  async getReconciliationMarker(graphId) {
427
469
  const t = tables2.reconciliationMarkers;
@@ -451,21 +493,27 @@ function createPostgresBackend(db, options = {}) {
451
493
  );
452
494
  },
453
495
  async transaction(fn, options2) {
454
- await ensureFulltextDdl();
455
496
  const txConfig = options2?.isolationLevel ? {
456
497
  isolationLevel: options2.isolationLevel.replace("_", " ")
457
498
  } : void 0;
458
- return db.transaction(async (tx) => {
459
- const txBackend = createTransactionBackend({
460
- db: tx,
461
- adapterOptions,
462
- operationStrategy,
463
- tableNames,
464
- capabilities,
465
- fulltextStrategy
466
- });
467
- return fn(txBackend);
468
- }, txConfig);
499
+ return db.transaction(
500
+ async (tx) => fn(bindTransactionBackend(tx), tx),
501
+ txConfig
502
+ );
503
+ },
504
+ adoptTransaction(externalTx) {
505
+ if (!capabilities.transactions) {
506
+ throw new chunkYEDQLNVE_cjs.ConfigurationError(
507
+ "Cross-store atomicity is unavailable on this Postgres backend: its driver does not support transactions (drizzle-orm/neon-http, Cloudflare D1). Adopting an external transaction here would let the caller's relational write commit with no way to roll back the graph write. Use a node-postgres or neon-serverless (Pool/WebSocket) connection for cross-store transactions.",
508
+ {
509
+ backend: "postgres",
510
+ capability: "transactions",
511
+ supportsTransactions: false
512
+ }
513
+ );
514
+ }
515
+ chunkTVUARC7S_cjs.assertAdoptedDialect(externalTx, pgCore.PgDatabase, "postgres");
516
+ return bindTransactionBackend(externalTx);
469
517
  },
470
518
  async close() {
471
519
  }
@@ -491,7 +539,7 @@ function createPostgresOperationBackend(options) {
491
539
  async function execRun(query) {
492
540
  await executionAdapter.execute(query);
493
541
  }
494
- const commonBackend = chunkCQVNGKU7_cjs.createCommonOperationBackend({
542
+ const commonBackend = chunkTVUARC7S_cjs.createCommonOperationBackend({
495
543
  batchConfig: {
496
544
  checkUniqueBatchChunkSize: POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE,
497
545
  edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,
@@ -504,7 +552,7 @@ function createPostgresOperationBackend(options) {
504
552
  execGet,
505
553
  execRun
506
554
  },
507
- nowIso: chunkCQVNGKU7_cjs.nowIso,
555
+ nowIso: chunkTVUARC7S_cjs.nowIso,
508
556
  operationStrategy,
509
557
  rowMappers: {
510
558
  toEdgeRow,
@@ -528,7 +576,7 @@ function createPostgresOperationBackend(options) {
528
576
  tableNames,
529
577
  // === Embedding Operations ===
530
578
  async upsertEmbedding(params) {
531
- const timestamp = chunkCQVNGKU7_cjs.nowIso();
579
+ const timestamp = chunkTVUARC7S_cjs.nowIso();
532
580
  const query = operationStrategy.buildUpsertEmbedding(params, timestamp);
533
581
  await execRun(query);
534
582
  },
@@ -568,7 +616,7 @@ function createPostgresOperationBackend(options) {
568
616
  ...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists },
569
617
  ...params.concurrent === true ? { concurrent: true } : {}
570
618
  };
571
- const result = await chunkCQVNGKU7_cjs.createPostgresVectorIndex(db, indexOptions);
619
+ const result = await chunkTVUARC7S_cjs.createPostgresVectorIndex(db, indexOptions);
572
620
  if (!result.success) {
573
621
  throw new Error(
574
622
  result.message ?? "Failed to create PostgreSQL vector index"
@@ -577,7 +625,7 @@ function createPostgresOperationBackend(options) {
577
625
  },
578
626
  // === Fulltext Operations ===
579
627
  async upsertFulltext(params) {
580
- const timestamp = chunkCQVNGKU7_cjs.nowIso();
628
+ const timestamp = chunkTVUARC7S_cjs.nowIso();
581
629
  const statements = operationStrategy.buildUpsertFulltext(
582
630
  params,
583
631
  timestamp
@@ -594,7 +642,7 @@ function createPostgresOperationBackend(options) {
594
642
  },
595
643
  async upsertFulltextBatch(params) {
596
644
  if (params.rows.length === 0) return;
597
- const timestamp = chunkCQVNGKU7_cjs.nowIso();
645
+ const timestamp = chunkTVUARC7S_cjs.nowIso();
598
646
  const statements = operationStrategy.buildUpsertFulltextBatch(
599
647
  params,
600
648
  timestamp
@@ -615,7 +663,7 @@ function createPostgresOperationBackend(options) {
615
663
  const rows = await execAll(query);
616
664
  return rows.map((row, index) => ({
617
665
  nodeId: row.node_id,
618
- score: coerceNumericScore(row.score),
666
+ score: chunkTVUARC7S_cjs.coerceNumericScore(row.score),
619
667
  rank: index + 1,
620
668
  ...row.snippet === null ? {} : { snippet: row.snippet }
621
669
  }));
@@ -624,13 +672,13 @@ function createPostgresOperationBackend(options) {
624
672
  const metrics = capabilities.vector?.metrics ?? ["cosine"];
625
673
  await Promise.all(
626
674
  metrics.map(async (metric) => {
627
- const indexName = chunkCQVNGKU7_cjs.generateVectorIndexName(
675
+ const indexName = chunkTVUARC7S_cjs.generateVectorIndexName(
628
676
  params.graphId,
629
677
  params.nodeKind,
630
678
  params.fieldPath,
631
679
  metric
632
680
  );
633
- const result = await chunkCQVNGKU7_cjs.dropPostgresVectorIndex(db, indexName);
681
+ const result = await chunkTVUARC7S_cjs.dropPostgresVectorIndex(db, indexName);
634
682
  if (!result.success) {
635
683
  throw new Error(
636
684
  result.message ?? "Failed to drop PostgreSQL vector index"
@@ -663,43 +711,43 @@ function createTransactionBackend(options) {
663
711
 
664
712
  Object.defineProperty(exports, "createPostgresTables", {
665
713
  enumerable: true,
666
- get: function () { return chunkCQVNGKU7_cjs.createPostgresTables; }
714
+ get: function () { return chunkTVUARC7S_cjs.createPostgresTables; }
667
715
  });
668
716
  Object.defineProperty(exports, "edges", {
669
717
  enumerable: true,
670
- get: function () { return chunkCQVNGKU7_cjs.edges; }
718
+ get: function () { return chunkTVUARC7S_cjs.edges; }
671
719
  });
672
720
  Object.defineProperty(exports, "embeddings", {
673
721
  enumerable: true,
674
- get: function () { return chunkCQVNGKU7_cjs.embeddings; }
722
+ get: function () { return chunkTVUARC7S_cjs.embeddings; }
675
723
  });
676
724
  Object.defineProperty(exports, "fulltext", {
677
725
  enumerable: true,
678
- get: function () { return chunkCQVNGKU7_cjs.fulltext; }
726
+ get: function () { return chunkTVUARC7S_cjs.fulltext; }
679
727
  });
680
728
  Object.defineProperty(exports, "generatePostgresDDL", {
681
729
  enumerable: true,
682
- get: function () { return chunkCQVNGKU7_cjs.generatePostgresDDL; }
730
+ get: function () { return chunkTVUARC7S_cjs.generatePostgresDDL; }
683
731
  });
684
732
  Object.defineProperty(exports, "generatePostgresMigrationSQL", {
685
733
  enumerable: true,
686
- get: function () { return chunkCQVNGKU7_cjs.generatePostgresMigrationSQL; }
734
+ get: function () { return chunkTVUARC7S_cjs.generatePostgresMigrationSQL; }
687
735
  });
688
736
  Object.defineProperty(exports, "nodes", {
689
737
  enumerable: true,
690
- get: function () { return chunkCQVNGKU7_cjs.nodes; }
738
+ get: function () { return chunkTVUARC7S_cjs.nodes; }
691
739
  });
692
740
  Object.defineProperty(exports, "schemaVersions", {
693
741
  enumerable: true,
694
- get: function () { return chunkCQVNGKU7_cjs.schemaVersions; }
742
+ get: function () { return chunkTVUARC7S_cjs.schemaVersions; }
695
743
  });
696
744
  Object.defineProperty(exports, "tables", {
697
745
  enumerable: true,
698
- get: function () { return chunkCQVNGKU7_cjs.tables; }
746
+ get: function () { return chunkTVUARC7S_cjs.tables; }
699
747
  });
700
748
  Object.defineProperty(exports, "uniques", {
701
749
  enumerable: true,
702
- get: function () { return chunkCQVNGKU7_cjs.uniques; }
750
+ get: function () { return chunkTVUARC7S_cjs.uniques; }
703
751
  });
704
752
  exports.createPostgresBackend = createPostgresBackend;
705
753
  //# sourceMappingURL=index.cjs.map