@nicia-ai/typegraph 0.25.0 → 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 +167 -71
  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 +119 -27
  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-LVCSL6A3.js → chunk-3W6AIFT2.js} +11 -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-7W3KAMVQ.cjs → chunk-4TJI44WP.cjs} +94 -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-OJ6IQVZG.js → chunk-DDVA4QBA.js} +177 -37
  32. package/dist/chunk-DDVA4QBA.js.map +1 -0
  33. package/dist/{chunk-7CDXX3QZ.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-FPCOUJSL.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-WI5VRP3X.js → chunk-RF5EUQWS.js} +371 -47
  48. package/dist/chunk-RF5EUQWS.js.map +1 -0
  49. package/dist/{chunk-ZEMNF3QK.cjs → chunk-RVT2N4RF.cjs} +209 -69
  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-O2P3KAUT.cjs → chunk-TVUARC7S.cjs} +445 -110
  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-B2jjLjpR.d.cts → ddl-9kw8UADK.d.ts} +697 -29
  64. package/dist/{ddl-DpaeAKPp.d.ts → ddl-Cw82BPM4.d.cts} +697 -29
  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-BpjBW1JK.d.cts → manager-Aqzmztkb.d.cts} +11 -3
  88. package/dist/{manager-BKaPQbns.d.ts → manager-C3LxzPcX.d.ts} +11 -3
  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-Myo8e3Lr.d.cts → sqlite-BvSEbybu.d.cts} +320 -1
  100. package/dist/{sqlite-CU3j6rc7.d.ts → sqlite-GKvcDPVn.d.ts} +320 -1
  101. package/dist/{store-BAGuOHDh.d.cts → store-CiS_AGNH.d.ts} +112 -4
  102. package/dist/{store-De98Lod4.d.ts → store-DbQLsSor.d.cts} +112 -4
  103. package/dist/{types-CYga3lZp.d.cts → types-CF7nDH3q.d.cts} +2 -2
  104. package/dist/{types-BLmJq4wI.d.ts → types-Cars4JZ1.d.ts} +2 -2
  105. package/dist/{types--0EslBx5.d.cts → types-DZPBXZOK.d.cts} +275 -8
  106. package/dist/{types-BNWYZ-0-.d.ts → types-Dzkr0Eqi.d.ts} +275 -8
  107. package/dist/{where-m1uWsdua.d.cts → where-BmtjfWuS.d.cts} +2 -2
  108. package/dist/{where-CluR73rs.d.ts → where-kk1Zz2En.d.ts} +2 -2
  109. package/package.json +3 -1
  110. package/dist/chunk-7CDXX3QZ.cjs.map +0 -1
  111. package/dist/chunk-7W3KAMVQ.cjs.map +0 -1
  112. package/dist/chunk-D2GO3RBL.cjs +0 -12
  113. package/dist/chunk-DOTEN2FG.js.map +0 -1
  114. package/dist/chunk-FPCOUJSL.js.map +0 -1
  115. package/dist/chunk-JTI5WT4P.cjs.map +0 -1
  116. package/dist/chunk-LVCSL6A3.js.map +0 -1
  117. package/dist/chunk-O2P3KAUT.cjs.map +0 -1
  118. package/dist/chunk-OJ6IQVZG.js.map +0 -1
  119. package/dist/chunk-W5MTHMTE.cjs.map +0 -1
  120. package/dist/chunk-WI5VRP3X.js.map +0 -1
  121. package/dist/chunk-YZZBDCLV.js.map +0 -1
  122. package/dist/chunk-ZEMNF3QK.cjs.map +0 -1
@@ -1,10 +1,17 @@
1
- import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders, tsvectorStrategy, fts5Strategy, quotedTableName, quotedColumn, edgeColumnList, sqlNull, nodeColumnList } from './chunk-YZZBDCLV.js';
2
- import { MAX_PG_IDENTIFIER_LENGTH } from './chunk-EJCDOA37.js';
3
- import { DatabaseOperationError, MigrationError, SchemaContentConflictError, UniquenessError, StaleVersionError } from './chunk-DOTEN2FG.js';
4
- import { sql, getTableName } from 'drizzle-orm';
5
- import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1 } from 'drizzle-orm/pg-core';
6
- import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, uniqueIndex as uniqueIndex$1, blob, getTableConfig } from 'drizzle-orm/sqlite-core';
1
+ import { isMissingTableError, sortedReplacer } from './chunk-5H3BAMTB.js';
2
+ import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders, tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER, quotedTableName, quotedColumn, edgeColumnList, sqlNull, nodeColumnList } from './chunk-ZTREJOGB.js';
3
+ import { MAX_PG_IDENTIFIER_LENGTH, sha256Hex } from './chunk-EJCDOA37.js';
4
+ import { DatabaseOperationError, ConfigurationError, MigrationError, SchemaContentConflictError, UniquenessError, StoreNotInitializedError, StaleVersionError } from './chunk-U5ROKVRF.js';
5
+ import { sql, is, getTableName } from 'drizzle-orm';
6
+ import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
7
+ import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, uniqueIndex as uniqueIndex$1, blob, getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
7
8
 
9
+ var regconfig = customType({
10
+ dataType: () => "regconfig"
11
+ });
12
+ var tsvector = customType({
13
+ dataType: () => "tsvector"
14
+ });
8
15
  var vector = customType({
9
16
  dataType(config) {
10
17
  return config?.dimensions ? `vector(${config.dimensions})` : "vector";
@@ -33,6 +40,7 @@ var DEFAULT_TABLE_NAMES = {
33
40
  embeddings: "typegraph_node_embeddings",
34
41
  fulltext: "typegraph_node_fulltext",
35
42
  indexMaterializations: "typegraph_index_materializations",
43
+ contributionMaterializations: "typegraph_contribution_materializations",
36
44
  kindRemovals: "typegraph_kind_removals",
37
45
  reconciliationMarkers: "typegraph_reconciliation_markers"
38
46
  };
@@ -241,6 +249,43 @@ function createPostgresTables(names = {}, options = {}) {
241
249
  },
242
250
  (t) => [primaryKey({ columns: [t.graphId] })]
243
251
  );
252
+ const contributionMaterializations = pgTable(
253
+ n.contributionMaterializations,
254
+ {
255
+ graphId: text("graph_id").notNull(),
256
+ logicalName: text("logical_name").notNull(),
257
+ owner: text("owner").notNull(),
258
+ tableName: text("table_name").notNull(),
259
+ signature: text("signature").notNull(),
260
+ materializedAt: timestamp("materialized_at", { withTimezone: true }),
261
+ lastAttemptedAt: timestamp("last_attempted_at", {
262
+ withTimezone: true
263
+ }).notNull(),
264
+ lastError: text("last_error")
265
+ },
266
+ (t) => [
267
+ primaryKey({
268
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
269
+ })
270
+ ]
271
+ );
272
+ const fulltext2 = pgTable(
273
+ n.fulltext,
274
+ {
275
+ graphId: text("graph_id").notNull(),
276
+ nodeKind: text("node_kind").notNull(),
277
+ nodeId: text("node_id").notNull(),
278
+ content: text("content").notNull(),
279
+ language: regconfig("language").notNull(),
280
+ tsv: tsvector("tsv").generatedAlwaysAs(sql`to_tsvector("language", "content")`).notNull(),
281
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
282
+ },
283
+ (t) => [
284
+ primaryKey({ columns: [t.graphId, t.nodeKind, t.nodeId] }),
285
+ index(`${n.fulltext}_tsv_idx`).using("gin", t.tsv),
286
+ index(`${n.fulltext}_kind_idx`).on(t.graphId, t.nodeKind)
287
+ ]
288
+ );
244
289
  return {
245
290
  nodes: nodes3,
246
291
  edges: edges3,
@@ -248,22 +293,22 @@ function createPostgresTables(names = {}, options = {}) {
248
293
  schemaVersions: schemaVersions3,
249
294
  embeddings: embeddings3,
250
295
  indexMaterializations,
296
+ contributionMaterializations,
251
297
  kindRemovals,
252
298
  reconciliationMarkers,
253
- /**
254
- * The fulltext storage table is owned by the active `FulltextStrategy`,
255
- * not Drizzle. Shapes vary across strategies — the default `tsvectorStrategy`
256
- * uses a `regconfig` language column, a GENERATED STORED `tsv` column,
257
- * and a GIN index; alternate strategies (ParadeDB, pg_trgm, pgroonga)
258
- * pick their own column types and index methods. DDL is emitted as
259
- * raw SQL via `strategy.generateDdl()`; reads and writes are composed
260
- * from the strategy's fragment helpers.
261
- */
299
+ fulltext: fulltext2,
262
300
  fulltextTableName: n.fulltext
263
301
  };
264
302
  }
265
303
  var tables = createPostgresTables();
266
- var { nodes, edges, uniques, schemaVersions, embeddings } = tables;
304
+ var {
305
+ nodes,
306
+ edges,
307
+ uniques,
308
+ schemaVersions,
309
+ embeddings,
310
+ fulltext
311
+ } = tables;
267
312
  var DEFAULT_TABLE_NAMES2 = {
268
313
  nodes: "typegraph_nodes",
269
314
  edges: "typegraph_edges",
@@ -272,6 +317,7 @@ var DEFAULT_TABLE_NAMES2 = {
272
317
  embeddings: "typegraph_node_embeddings",
273
318
  fulltext: "typegraph_node_fulltext",
274
319
  indexMaterializations: "typegraph_index_materializations",
320
+ contributionMaterializations: "typegraph_contribution_materializations",
275
321
  kindRemovals: "typegraph_kind_removals",
276
322
  reconciliationMarkers: "typegraph_reconciliation_markers"
277
323
  };
@@ -480,6 +526,24 @@ function createSqliteTables(names = {}, options = {}) {
480
526
  },
481
527
  (t) => [primaryKey$1({ columns: [t.graphId] })]
482
528
  );
529
+ const contributionMaterializations = sqliteTable(
530
+ n.contributionMaterializations,
531
+ {
532
+ graphId: text$1("graph_id").notNull(),
533
+ logicalName: text$1("logical_name").notNull(),
534
+ owner: text$1("owner").notNull(),
535
+ tableName: text$1("table_name").notNull(),
536
+ signature: text$1("signature").notNull(),
537
+ materializedAt: text$1("materialized_at"),
538
+ lastAttemptedAt: text$1("last_attempted_at").notNull(),
539
+ lastError: text$1("last_error")
540
+ },
541
+ (t) => [
542
+ primaryKey$1({
543
+ columns: [t.graphId, t.logicalName, t.owner, t.tableName]
544
+ })
545
+ ]
546
+ );
483
547
  return {
484
548
  nodes: nodes3,
485
549
  edges: edges3,
@@ -487,6 +551,7 @@ function createSqliteTables(names = {}, options = {}) {
487
551
  schemaVersions: schemaVersions3,
488
552
  embeddings: embeddings3,
489
553
  indexMaterializations,
554
+ contributionMaterializations,
490
555
  kindRemovals,
491
556
  reconciliationMarkers,
492
557
  /**
@@ -554,9 +619,9 @@ function renderIndexColumn(col) {
554
619
  if (col && typeof col === "object" && "name" in col) {
555
620
  return `"${col.name}"`;
556
621
  }
557
- const sql14 = tryInlineSql(col);
558
- if (sql14 !== void 0) {
559
- return sql14;
622
+ const sql15 = tryInlineSql(col);
623
+ if (sql15 !== void 0) {
624
+ return sql15;
560
625
  }
561
626
  return "unknown";
562
627
  }
@@ -627,21 +692,35 @@ function generateSqliteCreateIndexSQL(table) {
627
692
  return statements;
628
693
  }
629
694
  function isSqliteTable(value) {
630
- return typeof value === "object" && value !== null && // Drizzle tables are always objects; strings are our escape hatch.
631
- typeof value !== "string";
695
+ return is(value, SQLiteTable);
632
696
  }
633
- function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
634
- const statements = [];
635
- for (const table of Object.values(tables3)) {
697
+ function runtimeStrategyContributions(fulltextStrategy, fulltextTableName) {
698
+ return fulltextStrategy.ownedTables(fulltextTableName).filter((contribution) => contribution.runtimeEnsure);
699
+ }
700
+ function sqliteContributions(tables3 = tables2, fulltextStrategy = fts5Strategy) {
701
+ const contributions = [];
702
+ for (const [key, table] of Object.entries(tables3)) {
636
703
  if (!isSqliteTable(table)) continue;
637
- statements.push(generateSqliteCreateTableSQL(table));
704
+ contributions.push({
705
+ logicalName: key,
706
+ owner: BASE_CONTRIBUTION_OWNER,
707
+ tableName: getTableConfig(table).name,
708
+ createDdl: [
709
+ generateSqliteCreateTableSQL(table),
710
+ ...generateSqliteCreateIndexSQL(table)
711
+ ],
712
+ runtimeEnsure: false
713
+ });
638
714
  }
639
- for (const table of Object.values(tables3)) {
640
- if (!isSqliteTable(table)) continue;
641
- statements.push(...generateSqliteCreateIndexSQL(table));
715
+ for (const declared of fulltextStrategy.ownedTables(
716
+ tables3.fulltextTableName
717
+ )) {
718
+ contributions.push(declared);
642
719
  }
643
- statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
644
- return statements;
720
+ return contributions;
721
+ }
722
+ function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
723
+ return sqliteContributions(tables3, fulltextStrategy).flatMap((contribution) => [...contribution.createDdl]);
645
724
  }
646
725
  function generateSqliteMigrationSQL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
647
726
  return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
@@ -726,20 +805,33 @@ function generatePgCreateIndexSQL(table) {
726
805
  return statements;
727
806
  }
728
807
  function isPgTable(value) {
729
- return typeof value === "object" && value !== null && typeof value !== "string";
808
+ return is(value, PgTable);
730
809
  }
731
- function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
732
- const statements = [];
733
- for (const table of Object.values(tables3)) {
810
+ function postgresContributions(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
811
+ const contributions = [];
812
+ for (const [key, table] of Object.entries(tables3)) {
734
813
  if (!isPgTable(table)) continue;
735
- statements.push(generatePgCreateTableSQL(table));
814
+ if (table === tables3.fulltext) continue;
815
+ contributions.push({
816
+ logicalName: key,
817
+ owner: BASE_CONTRIBUTION_OWNER,
818
+ tableName: getTableConfig$1(table).name,
819
+ createDdl: [
820
+ generatePgCreateTableSQL(table),
821
+ ...generatePgCreateIndexSQL(table)
822
+ ],
823
+ runtimeEnsure: false
824
+ });
736
825
  }
737
- for (const table of Object.values(tables3)) {
738
- if (!isPgTable(table)) continue;
739
- statements.push(...generatePgCreateIndexSQL(table));
826
+ for (const declared of fulltextStrategy.ownedTables(
827
+ tables3.fulltextTableName
828
+ )) {
829
+ contributions.push(declared);
740
830
  }
741
- statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
742
- return statements;
831
+ return contributions;
832
+ }
833
+ function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
834
+ return postgresContributions(tables3, fulltextStrategy).flatMap((contribution) => [...contribution.createDdl]);
743
835
  }
744
836
  function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
745
837
  const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
@@ -794,6 +886,16 @@ function formatPostgresTimestamp(value) {
794
886
  }
795
887
  return void 0;
796
888
  }
889
+ function coerceNumericScore(value) {
890
+ if (typeof value === "number") return value;
891
+ const parsed = Number.parseFloat(value);
892
+ if (Number.isNaN(parsed)) {
893
+ throw new TypeError(
894
+ `Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`
895
+ );
896
+ }
897
+ return parsed;
898
+ }
797
899
  function normalizeJsonColumn(value) {
798
900
  return typeof value === "string" ? value : JSON.stringify(value ?? {});
799
901
  }
@@ -878,6 +980,222 @@ function createSchemaVersionRowMapper(config) {
878
980
  };
879
981
  };
880
982
  }
983
+ var SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = {
984
+ decode: (value) => typeof value === "string" ? value : void 0,
985
+ encode: (value) => value
986
+ };
987
+ var POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS = {
988
+ decode: formatPostgresTimestamp,
989
+ encode: (value) => new Date(value)
990
+ };
991
+ function mapContributionMaterializationRow(row, decode) {
992
+ const lastAttemptedAt = decode(row.lastAttemptedAt);
993
+ if (lastAttemptedAt === void 0) {
994
+ throw new Error(
995
+ `contribution materialization row missing required last_attempted_at: ${row.graphId}/${row.logicalName}`
996
+ );
997
+ }
998
+ return {
999
+ graphId: row.graphId,
1000
+ logicalName: row.logicalName,
1001
+ owner: row.owner,
1002
+ tableName: row.tableName,
1003
+ signature: row.signature,
1004
+ materializedAt: decode(row.materializedAt),
1005
+ lastAttemptedAt,
1006
+ lastError: row.lastError ?? void 0
1007
+ };
1008
+ }
1009
+ function buildContributionInsertValues(params, encode) {
1010
+ return {
1011
+ graphId: params.graphId,
1012
+ logicalName: params.logicalName,
1013
+ owner: params.owner,
1014
+ tableName: params.tableName,
1015
+ signature: params.signature,
1016
+ materializedAt: params.materializedAt === void 0 ? void 0 : encode(params.materializedAt),
1017
+ lastAttemptedAt: encode(params.attemptedAt),
1018
+ lastError: params.error
1019
+ };
1020
+ }
1021
+ function buildContributionOnConflictSet(materializedAtColumn, paramsMaterializedAt) {
1022
+ const materializedAtSet = paramsMaterializedAt === void 0 ? sql`COALESCE(excluded.${sql.identifier("materialized_at")}, ${materializedAtColumn})` : sql`excluded.${sql.identifier("materialized_at")}`;
1023
+ return {
1024
+ signature: sql`excluded.${sql.identifier("signature")}`,
1025
+ materializedAt: materializedAtSet,
1026
+ lastAttemptedAt: sql`excluded.${sql.identifier("last_attempted_at")}`,
1027
+ lastError: sql`excluded.${sql.identifier("last_error")}`
1028
+ };
1029
+ }
1030
+ async function computeContributionSignature(dialect, identity, createDdl) {
1031
+ const hashable = {
1032
+ dialect,
1033
+ owner: identity.owner,
1034
+ logicalName: identity.logicalName,
1035
+ tableName: identity.tableName,
1036
+ createDdl
1037
+ };
1038
+ return sha256Hex(JSON.stringify(hashable, sortedReplacer), 16);
1039
+ }
1040
+ function evaluateContributionState(row, signature) {
1041
+ if (row === void 0) return "missing";
1042
+ if (row.lastError !== void 0) return "failed";
1043
+ if (row.signature !== signature) return "stale";
1044
+ if (row.materializedAt === void 0) return "missing";
1045
+ return "initialized";
1046
+ }
1047
+ function identityOf(graphId, contribution) {
1048
+ return {
1049
+ graphId,
1050
+ logicalName: contribution.logicalName,
1051
+ owner: contribution.owner,
1052
+ tableName: contribution.tableName
1053
+ };
1054
+ }
1055
+ function gateFulltextMethods(source, assert) {
1056
+ const gated = {};
1057
+ if (source.upsertFulltext) {
1058
+ const raw = source.upsertFulltext;
1059
+ gated.upsertFulltext = async (params) => {
1060
+ await assert(params.graphId);
1061
+ await raw(params);
1062
+ };
1063
+ }
1064
+ if (source.deleteFulltext) {
1065
+ const raw = source.deleteFulltext;
1066
+ gated.deleteFulltext = async (params) => {
1067
+ await assert(params.graphId);
1068
+ await raw(params);
1069
+ };
1070
+ }
1071
+ if (source.upsertFulltextBatch) {
1072
+ const raw = source.upsertFulltextBatch;
1073
+ gated.upsertFulltextBatch = async (params) => {
1074
+ if (params.rows.length === 0) return;
1075
+ await assert(params.graphId);
1076
+ await raw(params);
1077
+ };
1078
+ }
1079
+ if (source.deleteFulltextBatch) {
1080
+ const raw = source.deleteFulltextBatch;
1081
+ gated.deleteFulltextBatch = async (params) => {
1082
+ if (params.nodeIds.length === 0) return;
1083
+ await assert(params.graphId);
1084
+ await raw(params);
1085
+ };
1086
+ }
1087
+ if (source.fulltextSearch) {
1088
+ const raw = source.fulltextSearch;
1089
+ gated.fulltextSearch = async (params) => {
1090
+ await assert(params.graphId);
1091
+ return raw(params);
1092
+ };
1093
+ }
1094
+ const rawHardDelete = source.hardDeleteNode;
1095
+ gated.hardDeleteNode = async (params) => {
1096
+ await assert(params.graphId);
1097
+ await rawHardDelete(params);
1098
+ };
1099
+ return gated;
1100
+ }
1101
+ function gateFulltext(tx, assert) {
1102
+ return { ...tx, ...gateFulltextMethods(tx, assert) };
1103
+ }
1104
+ function createContributionMaterializer(deps) {
1105
+ const { dialect, fulltextStrategy, fulltextTableName } = deps;
1106
+ const initializedGraphIds = /* @__PURE__ */ new Set();
1107
+ function runtimeContributions() {
1108
+ return runtimeStrategyContributions(fulltextStrategy, fulltextTableName);
1109
+ }
1110
+ async function materializeOne(graphId, contribution) {
1111
+ const signature = await computeContributionSignature(
1112
+ dialect,
1113
+ contribution,
1114
+ contribution.createDdl
1115
+ );
1116
+ const identity = identityOf(graphId, contribution);
1117
+ const existing = await deps.getMarker(identity);
1118
+ if (evaluateContributionState(existing, signature) === "initialized") {
1119
+ return;
1120
+ }
1121
+ const priorSuccess = existing?.materializedAt !== void 0;
1122
+ if (priorSuccess && existing.signature !== signature) {
1123
+ const error = new Error(
1124
+ `Contribution "${contribution.logicalName}" (owner "${contribution.owner}", table "${contribution.tableName}") was already materialized with a different signature. The recorded physical shape is stale relative to the current strategy/DDL \u2014 migrate or drop the table and retry, or restore the original strategy.`
1125
+ );
1126
+ await deps.recordMarker({
1127
+ ...identity,
1128
+ signature,
1129
+ attemptedAt: nowIso(),
1130
+ materializedAt: void 0,
1131
+ error: error.message
1132
+ });
1133
+ throw error;
1134
+ }
1135
+ const attemptedAt = nowIso();
1136
+ try {
1137
+ for (const statement of contribution.createDdl) {
1138
+ await deps.execDdl(statement);
1139
+ }
1140
+ } catch (error) {
1141
+ await deps.recordMarker({
1142
+ ...identity,
1143
+ signature,
1144
+ attemptedAt,
1145
+ materializedAt: void 0,
1146
+ error: error instanceof Error ? error.message : String(error)
1147
+ });
1148
+ throw error;
1149
+ }
1150
+ await deps.recordMarker({
1151
+ ...identity,
1152
+ signature,
1153
+ attemptedAt,
1154
+ materializedAt: attemptedAt,
1155
+ error: void 0
1156
+ });
1157
+ }
1158
+ async function ensureRuntimeContributions(graphId) {
1159
+ if (initializedGraphIds.has(graphId)) return;
1160
+ const contributions = runtimeContributions();
1161
+ if (contributions.length > 0) {
1162
+ await deps.ensureMarkerTable();
1163
+ for (const contribution of contributions) {
1164
+ await materializeOne(graphId, contribution);
1165
+ }
1166
+ }
1167
+ initializedGraphIds.add(graphId);
1168
+ }
1169
+ async function assertInitialized(graphId) {
1170
+ if (initializedGraphIds.has(graphId)) return;
1171
+ for (const contribution of runtimeContributions()) {
1172
+ const signature = await computeContributionSignature(
1173
+ dialect,
1174
+ contribution,
1175
+ contribution.createDdl
1176
+ );
1177
+ const identity = identityOf(graphId, contribution);
1178
+ let existing;
1179
+ try {
1180
+ existing = await deps.getMarker(identity);
1181
+ } catch (error) {
1182
+ if (!isMissingTableError(error)) throw error;
1183
+ throw new StoreNotInitializedError(graphId, "missing", {
1184
+ cause: error,
1185
+ details: { logicalName: contribution.logicalName }
1186
+ });
1187
+ }
1188
+ const state = evaluateContributionState(existing, signature);
1189
+ if (state !== "initialized") {
1190
+ throw new StoreNotInitializedError(graphId, state, {
1191
+ details: { logicalName: contribution.logicalName }
1192
+ });
1193
+ }
1194
+ }
1195
+ initializedGraphIds.add(graphId);
1196
+ }
1197
+ return { ensureRuntimeContributions, assertInitialized };
1198
+ }
881
1199
  var SQLITE_INDEX_MAT_TIMESTAMPS = {
882
1200
  decode: (value) => typeof value === "string" ? value : void 0,
883
1201
  encode: (value) => value
@@ -977,8 +1295,14 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
977
1295
  lastError: sql`excluded.${sql.identifier("last_error")}`
978
1296
  };
979
1297
  }
980
-
981
- // src/backend/drizzle/operation-backend-core.ts
1298
+ function assertAdoptedDialect(externalTx, brand, backend) {
1299
+ if (is(externalTx, brand)) return;
1300
+ const label = backend === "postgres" ? "Postgres" : "SQLite";
1301
+ throw new ConfigurationError(
1302
+ `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.`,
1303
+ { backend, capability: "adoptTransaction" }
1304
+ );
1305
+ }
982
1306
  function chunkArray(values, size) {
983
1307
  if (values.length <= size) {
984
1308
  return [values];
@@ -1351,9 +1675,9 @@ function createCommonOperationBackend(options) {
1351
1675
  };
1352
1676
  }
1353
1677
  function buildClearGraph(tables3, graphId) {
1354
- const fulltext = quotedTableName(tables3.fulltextTableName);
1678
+ const fulltext2 = quotedTableName(tables3.fulltextTableName);
1355
1679
  return [
1356
- sql`DELETE FROM ${fulltext} WHERE "graph_id" = ${graphId}`,
1680
+ sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}`,
1357
1681
  sql`DELETE FROM ${tables3.embeddings} WHERE ${tables3.embeddings.graphId} = ${graphId}`,
1358
1682
  sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
1359
1683
  sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
@@ -2649,6 +2973,6 @@ function compileQueryWithDialect(db, query, backendName) {
2649
2973
  return compiler.sqlToQuery(query);
2650
2974
  }
2651
2975
 
2652
- export { POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, POSTGRES_ROW_MAPPER_CONFIG, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, SQLITE_ROW_MAPPER_CONFIG, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildMaterializationInsertValues, buildMaterializationOnConflictSet, compileQueryWithDialect, createCommonOperationBackend, createEdgeRowMapper, createNodeRowMapper, createPostgresOperationStrategy, createPostgresTables, createPostgresVectorIndex, createSchemaVersionRowMapper, createSqliteOperationStrategy, createSqliteTables, createSqliteVectorIndex, createUniqueRowMapper, dropPostgresVectorIndex, dropSqliteVectorIndex, edges, edges2, embeddings, embeddings2, formatPostgresTimestamp, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, getOrCreateLru, mapKindRemovalRow, mapMaterializationRow, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
2653
- //# sourceMappingURL=chunk-WI5VRP3X.js.map
2654
- //# sourceMappingURL=chunk-WI5VRP3X.js.map
2976
+ export { POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, POSTGRES_ROW_MAPPER_CONFIG, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, SQLITE_ROW_MAPPER_CONFIG, assertAdoptedDialect, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildMaterializationInsertValues, buildMaterializationOnConflictSet, coerceNumericScore, compileQueryWithDialect, createCommonOperationBackend, createContributionMaterializer, createEdgeRowMapper, createNodeRowMapper, createPostgresOperationStrategy, createPostgresTables, createPostgresVectorIndex, createSchemaVersionRowMapper, createSqliteOperationStrategy, createSqliteTables, createSqliteVectorIndex, createUniqueRowMapper, dropPostgresVectorIndex, dropSqliteVectorIndex, edges, edges2, embeddings, embeddings2, formatPostgresTimestamp, fulltext, gateFulltext, gateFulltextMethods, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, getOrCreateLru, mapContributionMaterializationRow, mapKindRemovalRow, mapMaterializationRow, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
2977
+ //# sourceMappingURL=chunk-RF5EUQWS.js.map
2978
+ //# sourceMappingURL=chunk-RF5EUQWS.js.map