@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,9 +1,10 @@
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
 
8
9
  var regconfig = customType({
9
10
  dataType: () => "regconfig"
@@ -39,6 +40,7 @@ var DEFAULT_TABLE_NAMES = {
39
40
  embeddings: "typegraph_node_embeddings",
40
41
  fulltext: "typegraph_node_fulltext",
41
42
  indexMaterializations: "typegraph_index_materializations",
43
+ contributionMaterializations: "typegraph_contribution_materializations",
42
44
  kindRemovals: "typegraph_kind_removals",
43
45
  reconciliationMarkers: "typegraph_reconciliation_markers"
44
46
  };
@@ -247,6 +249,26 @@ function createPostgresTables(names = {}, options = {}) {
247
249
  },
248
250
  (t) => [primaryKey({ columns: [t.graphId] })]
249
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
+ );
250
272
  const fulltext2 = pgTable(
251
273
  n.fulltext,
252
274
  {
@@ -271,6 +293,7 @@ function createPostgresTables(names = {}, options = {}) {
271
293
  schemaVersions: schemaVersions3,
272
294
  embeddings: embeddings3,
273
295
  indexMaterializations,
296
+ contributionMaterializations,
274
297
  kindRemovals,
275
298
  reconciliationMarkers,
276
299
  fulltext: fulltext2,
@@ -294,6 +317,7 @@ var DEFAULT_TABLE_NAMES2 = {
294
317
  embeddings: "typegraph_node_embeddings",
295
318
  fulltext: "typegraph_node_fulltext",
296
319
  indexMaterializations: "typegraph_index_materializations",
320
+ contributionMaterializations: "typegraph_contribution_materializations",
297
321
  kindRemovals: "typegraph_kind_removals",
298
322
  reconciliationMarkers: "typegraph_reconciliation_markers"
299
323
  };
@@ -502,6 +526,24 @@ function createSqliteTables(names = {}, options = {}) {
502
526
  },
503
527
  (t) => [primaryKey$1({ columns: [t.graphId] })]
504
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
+ );
505
547
  return {
506
548
  nodes: nodes3,
507
549
  edges: edges3,
@@ -509,6 +551,7 @@ function createSqliteTables(names = {}, options = {}) {
509
551
  schemaVersions: schemaVersions3,
510
552
  embeddings: embeddings3,
511
553
  indexMaterializations,
554
+ contributionMaterializations,
512
555
  kindRemovals,
513
556
  reconciliationMarkers,
514
557
  /**
@@ -576,9 +619,9 @@ function renderIndexColumn(col) {
576
619
  if (col && typeof col === "object" && "name" in col) {
577
620
  return `"${col.name}"`;
578
621
  }
579
- const sql14 = tryInlineSql(col);
580
- if (sql14 !== void 0) {
581
- return sql14;
622
+ const sql15 = tryInlineSql(col);
623
+ if (sql15 !== void 0) {
624
+ return sql15;
582
625
  }
583
626
  return "unknown";
584
627
  }
@@ -649,21 +692,35 @@ function generateSqliteCreateIndexSQL(table) {
649
692
  return statements;
650
693
  }
651
694
  function isSqliteTable(value) {
652
- return typeof value === "object" && value !== null && // Drizzle tables are always objects; strings are our escape hatch.
653
- typeof value !== "string";
695
+ return is(value, SQLiteTable);
654
696
  }
655
- function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
656
- const statements = [];
657
- 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)) {
658
703
  if (!isSqliteTable(table)) continue;
659
- 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
+ });
660
714
  }
661
- for (const table of Object.values(tables3)) {
662
- if (!isSqliteTable(table)) continue;
663
- statements.push(...generateSqliteCreateIndexSQL(table));
715
+ for (const declared of fulltextStrategy.ownedTables(
716
+ tables3.fulltextTableName
717
+ )) {
718
+ contributions.push(declared);
664
719
  }
665
- statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
666
- return statements;
720
+ return contributions;
721
+ }
722
+ function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
723
+ return sqliteContributions(tables3, fulltextStrategy).flatMap((contribution) => [...contribution.createDdl]);
667
724
  }
668
725
  function generateSqliteMigrationSQL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
669
726
  return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
@@ -748,22 +805,33 @@ function generatePgCreateIndexSQL(table) {
748
805
  return statements;
749
806
  }
750
807
  function isPgTable(value) {
751
- return typeof value === "object" && value !== null && typeof value !== "string";
808
+ return is(value, PgTable);
752
809
  }
753
- function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
754
- const statements = [];
755
- 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)) {
756
813
  if (!isPgTable(table)) continue;
757
814
  if (table === tables3.fulltext) continue;
758
- statements.push(generatePgCreateTableSQL(table));
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
+ });
759
825
  }
760
- for (const table of Object.values(tables3)) {
761
- if (!isPgTable(table)) continue;
762
- if (table === tables3.fulltext) continue;
763
- statements.push(...generatePgCreateIndexSQL(table));
826
+ for (const declared of fulltextStrategy.ownedTables(
827
+ tables3.fulltextTableName
828
+ )) {
829
+ contributions.push(declared);
764
830
  }
765
- statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
766
- return statements;
831
+ return contributions;
832
+ }
833
+ function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
834
+ return postgresContributions(tables3, fulltextStrategy).flatMap((contribution) => [...contribution.createDdl]);
767
835
  }
768
836
  function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
769
837
  const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
@@ -818,6 +886,16 @@ function formatPostgresTimestamp(value) {
818
886
  }
819
887
  return void 0;
820
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
+ }
821
899
  function normalizeJsonColumn(value) {
822
900
  return typeof value === "string" ? value : JSON.stringify(value ?? {});
823
901
  }
@@ -902,6 +980,222 @@ function createSchemaVersionRowMapper(config) {
902
980
  };
903
981
  };
904
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
+ }
905
1199
  var SQLITE_INDEX_MAT_TIMESTAMPS = {
906
1200
  decode: (value) => typeof value === "string" ? value : void 0,
907
1201
  encode: (value) => value
@@ -1001,8 +1295,14 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
1001
1295
  lastError: sql`excluded.${sql.identifier("last_error")}`
1002
1296
  };
1003
1297
  }
1004
-
1005
- // 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
+ }
1006
1306
  function chunkArray(values, size) {
1007
1307
  if (values.length <= size) {
1008
1308
  return [values];
@@ -2673,6 +2973,6 @@ function compileQueryWithDialect(db, query, backendName) {
2673
2973
  return compiler.sqlToQuery(query);
2674
2974
  }
2675
2975
 
2676
- 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, fulltext, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, getOrCreateLru, mapKindRemovalRow, mapMaterializationRow, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
2677
- //# sourceMappingURL=chunk-PSKUWVCB.js.map
2678
- //# sourceMappingURL=chunk-PSKUWVCB.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