@nicia-ai/typegraph 0.28.1 → 0.30.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 (178) hide show
  1. package/dist/backend/postgres/index.cjs +24 -762
  2. package/dist/backend/postgres/index.cjs.map +1 -1
  3. package/dist/backend/postgres/index.d.cts +24 -5
  4. package/dist/backend/postgres/index.d.ts +24 -5
  5. package/dist/backend/postgres/index.js +11 -753
  6. package/dist/backend/postgres/index.js.map +1 -1
  7. package/dist/backend/postgres/pglite.cjs +52 -0
  8. package/dist/backend/postgres/pglite.cjs.map +1 -0
  9. package/dist/backend/postgres/pglite.d.cts +116 -0
  10. package/dist/backend/postgres/pglite.d.ts +116 -0
  11. package/dist/backend/postgres/pglite.js +50 -0
  12. package/dist/backend/postgres/pglite.js.map +1 -0
  13. package/dist/backend/sqlite/index.cjs +23 -27
  14. package/dist/backend/sqlite/index.d.cts +22 -15
  15. package/dist/backend/sqlite/index.d.ts +22 -15
  16. package/dist/backend/sqlite/index.js +10 -10
  17. package/dist/backend/sqlite/libsql.cjs +18 -14
  18. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  19. package/dist/backend/sqlite/libsql.d.cts +3 -3
  20. package/dist/backend/sqlite/libsql.d.ts +3 -3
  21. package/dist/backend/sqlite/libsql.js +17 -13
  22. package/dist/backend/sqlite/libsql.js.map +1 -1
  23. package/dist/backend/sqlite/local.cjs +19 -17
  24. package/dist/backend/sqlite/local.cjs.map +1 -1
  25. package/dist/backend/sqlite/local.d.cts +9 -3
  26. package/dist/backend/sqlite/local.d.ts +9 -3
  27. package/dist/backend/sqlite/local.js +17 -15
  28. package/dist/backend/sqlite/local.js.map +1 -1
  29. package/dist/chunk-26HWIIVS.cjs +740 -0
  30. package/dist/chunk-26HWIIVS.cjs.map +1 -0
  31. package/dist/chunk-2QA5EHEN.js +181 -0
  32. package/dist/chunk-2QA5EHEN.js.map +1 -0
  33. package/dist/chunk-3IRMLJEK.js +206 -0
  34. package/dist/chunk-3IRMLJEK.js.map +1 -0
  35. package/dist/{chunk-5MTOKWDA.js → chunk-3JLRHQ67.js} +9 -9
  36. package/dist/{chunk-5MTOKWDA.js.map → chunk-3JLRHQ67.js.map} +1 -1
  37. package/dist/{chunk-WVQXAFP3.js → chunk-454I6GDF.js} +46 -5
  38. package/dist/chunk-454I6GDF.js.map +1 -0
  39. package/dist/{chunk-CTHNVU6K.cjs → chunk-4BXHVEFB.cjs} +16 -16
  40. package/dist/{chunk-CTHNVU6K.cjs.map → chunk-4BXHVEFB.cjs.map} +1 -1
  41. package/dist/{chunk-NMOE2ZEU.cjs → chunk-4LBO6KIF.cjs} +139 -128
  42. package/dist/chunk-4LBO6KIF.cjs.map +1 -0
  43. package/dist/chunk-633N7DSE.js +258 -0
  44. package/dist/chunk-633N7DSE.js.map +1 -0
  45. package/dist/{chunk-WFUN6DCM.cjs → chunk-7JGLPAFV.cjs} +11 -11
  46. package/dist/chunk-7JGLPAFV.cjs.map +1 -0
  47. package/dist/{chunk-ZTREJOGB.js → chunk-AI3RNREM.js} +140 -69
  48. package/dist/chunk-AI3RNREM.js.map +1 -0
  49. package/dist/{chunk-TSGBRPNE.js → chunk-ENDUY2CD.js} +46 -46
  50. package/dist/chunk-ENDUY2CD.js.map +1 -0
  51. package/dist/{chunk-7V335GHG.cjs → chunk-FLRCVI2G.cjs} +12 -2
  52. package/dist/chunk-FLRCVI2G.cjs.map +1 -0
  53. package/dist/chunk-FVIGJTS7.js +305 -0
  54. package/dist/chunk-FVIGJTS7.js.map +1 -0
  55. package/dist/chunk-FWBVPATK.cjs +208 -0
  56. package/dist/chunk-FWBVPATK.cjs.map +1 -0
  57. package/dist/chunk-IE6GN7L3.cjs +319 -0
  58. package/dist/chunk-IE6GN7L3.cjs.map +1 -0
  59. package/dist/{chunk-PGU2XKMA.js → chunk-IUIJJYPI.js} +117 -106
  60. package/dist/chunk-IUIJJYPI.js.map +1 -0
  61. package/dist/{chunk-E5ROA3MN.js → chunk-IX7RE7CG.js} +3 -3
  62. package/dist/{chunk-E5ROA3MN.js.map → chunk-IX7RE7CG.js.map} +1 -1
  63. package/dist/{chunk-YEDQLNVE.cjs → chunk-JIEJCTDS.cjs} +30 -2
  64. package/dist/chunk-JIEJCTDS.cjs.map +1 -0
  65. package/dist/{chunk-WZH2MKHW.cjs → chunk-K4N35E7B.cjs} +101 -101
  66. package/dist/{chunk-WZH2MKHW.cjs.map → chunk-K4N35E7B.cjs.map} +1 -1
  67. package/dist/{chunk-NZ5PMBTG.js → chunk-K5P5OZXS.js} +12 -3
  68. package/dist/chunk-K5P5OZXS.js.map +1 -0
  69. package/dist/chunk-K5VREXMZ.js +738 -0
  70. package/dist/chunk-K5VREXMZ.js.map +1 -0
  71. package/dist/chunk-LUHU4T2F.cjs +12 -0
  72. package/dist/{chunk-4FJVSF3K.cjs.map → chunk-LUHU4T2F.cjs.map} +1 -1
  73. package/dist/{chunk-O57GYGYK.js → chunk-M6OC455F.js} +32 -18
  74. package/dist/chunk-M6OC455F.js.map +1 -0
  75. package/dist/{chunk-OYLF3IC7.js → chunk-MAQJYNJR.js} +4 -4
  76. package/dist/chunk-MAQJYNJR.js.map +1 -0
  77. package/dist/{chunk-OOS2RKRH.js → chunk-MXE2U3EX.js} +4 -4
  78. package/dist/{chunk-OOS2RKRH.js.map → chunk-MXE2U3EX.js.map} +1 -1
  79. package/dist/{chunk-TKM2WDT4.js → chunk-N2OEOGBB.js} +386 -1093
  80. package/dist/chunk-N2OEOGBB.js.map +1 -0
  81. package/dist/{chunk-EJCDOA37.js → chunk-R4JOBEJU.js} +5 -5
  82. package/dist/{chunk-EJCDOA37.js.map → chunk-R4JOBEJU.js.map} +1 -1
  83. package/dist/{chunk-FFHW2JEK.cjs → chunk-RP7YITHX.cjs} +32 -17
  84. package/dist/chunk-RP7YITHX.cjs.map +1 -0
  85. package/dist/{chunk-PYJOBZR3.cjs → chunk-SGPXKJ4A.cjs} +60 -60
  86. package/dist/chunk-SGPXKJ4A.cjs.map +1 -0
  87. package/dist/{chunk-U5ROKVRF.js → chunk-TQOYM4LN.js} +29 -3
  88. package/dist/chunk-TQOYM4LN.js.map +1 -0
  89. package/dist/{chunk-PN37HVAV.cjs → chunk-UESTHN47.cjs} +153 -71
  90. package/dist/chunk-UESTHN47.cjs.map +1 -0
  91. package/dist/chunk-VFX3LC76.cjs +183 -0
  92. package/dist/chunk-VFX3LC76.cjs.map +1 -0
  93. package/dist/chunk-WEMZM7J7.cjs +270 -0
  94. package/dist/chunk-WEMZM7J7.cjs.map +1 -0
  95. package/dist/{chunk-NYQFPGYP.cjs → chunk-WFCECD6Q.cjs} +423 -1139
  96. package/dist/chunk-WFCECD6Q.cjs.map +1 -0
  97. package/dist/{chunk-EK6RJ373.cjs → chunk-YQGLVWB2.cjs} +7 -7
  98. package/dist/{chunk-EK6RJ373.cjs.map → chunk-YQGLVWB2.cjs.map} +1 -1
  99. package/dist/{chunk-X3244EKP.cjs → chunk-ZFWNO3GE.cjs} +48 -4
  100. package/dist/chunk-ZFWNO3GE.cjs.map +1 -0
  101. package/dist/ddl-BSFlbGQF.d.cts +38 -0
  102. package/dist/ddl-EdkIiFVU.d.ts +38 -0
  103. package/dist/{extension-types-B78CZfA5.d.cts → extension-types-CwHV-Uk4.d.cts} +4 -4
  104. package/dist/{extension-types-B78CZfA5.d.ts → extension-types-CwHV-Uk4.d.ts} +4 -4
  105. package/dist/graph-extension/index.cjs +19 -19
  106. package/dist/graph-extension/index.d.cts +4 -4
  107. package/dist/graph-extension/index.d.ts +4 -4
  108. package/dist/graph-extension/index.js +4 -4
  109. package/dist/{index-CWdBFWbI.d.ts → index-DzeIiMO3.d.ts} +30 -3
  110. package/dist/{index-Bilw0pYm.d.cts → index-Ln_KHTGA.d.cts} +30 -3
  111. package/dist/index.cjs +1542 -1011
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.cts +142 -12
  114. package/dist/index.d.ts +142 -12
  115. package/dist/index.js +1138 -643
  116. package/dist/index.js.map +1 -1
  117. package/dist/indexes/index.cjs +19 -19
  118. package/dist/indexes/index.d.cts +9 -9
  119. package/dist/indexes/index.d.ts +9 -9
  120. package/dist/indexes/index.js +5 -5
  121. package/dist/interchange/index.cjs +8 -14
  122. package/dist/interchange/index.cjs.map +1 -1
  123. package/dist/interchange/index.d.cts +5 -16
  124. package/dist/interchange/index.d.ts +5 -16
  125. package/dist/interchange/index.js +3 -9
  126. package/dist/interchange/index.js.map +1 -1
  127. package/dist/{manager-ehLTTNq0.d.ts → manager-BbdyNhkv.d.ts} +2 -2
  128. package/dist/{manager-c1MGaVVR.d.cts → manager-wTDgjoXG.d.cts} +2 -2
  129. package/dist/{materialize-indexes-DFavFQah.d.ts → materialize-indexes-lkawaDor.d.ts} +1 -1
  130. package/dist/{materialize-indexes-BQfaAZKA.d.cts → materialize-indexes-oanE3RU0.d.cts} +1 -1
  131. package/dist/{ddl-0Ooc2dpL.d.ts → postgres-CK2ByP1q.d.cts} +2 -471
  132. package/dist/{ddl-Dza3kDrI.d.cts → postgres-ymXYC6Rr.d.ts} +2 -471
  133. package/dist/profiler/index.cjs +10 -10
  134. package/dist/profiler/index.d.cts +7 -7
  135. package/dist/profiler/index.d.ts +7 -7
  136. package/dist/profiler/index.js +3 -3
  137. package/dist/schema/index.cjs +33 -33
  138. package/dist/schema/index.d.cts +7 -7
  139. package/dist/schema/index.d.ts +7 -7
  140. package/dist/schema/index.js +10 -10
  141. package/dist/{sqlite-BxZUPbyD.d.ts → sqlite-DxH1lrwD.d.cts} +2 -468
  142. package/dist/{sqlite-mvpXjEeB.d.cts → sqlite-R8YGOqVQ.d.ts} +2 -468
  143. package/dist/{store-Ufc1Eoey.d.ts → store--z1Tmk7U.d.cts} +124 -5
  144. package/dist/{store-D7YEMg2v.d.cts → store-CNKM334w.d.ts} +124 -5
  145. package/dist/{types-CMQymcwk.d.cts → types-BBiDqJCU.d.ts} +252 -46
  146. package/dist/{types-B-sJJ4GQ.d.ts → types-CMvxx2kd.d.ts} +2 -2
  147. package/dist/{types-CmUA9sal.d.cts → types-D5B6Be5c.d.cts} +2 -2
  148. package/dist/{types-CQ7xXJMP.d.ts → types-dL-clxO3.d.cts} +252 -46
  149. package/dist/{where-CtrLu1Zf.d.ts → where-CAo6wsBZ.d.ts} +2 -2
  150. package/dist/{where-5zf15aFZ.d.cts → where-bJjuOCeV.d.cts} +2 -2
  151. package/package.json +20 -5
  152. package/dist/chunk-3EUKJEQ3.js +0 -77
  153. package/dist/chunk-3EUKJEQ3.js.map +0 -1
  154. package/dist/chunk-4FJVSF3K.cjs +0 -12
  155. package/dist/chunk-7V335GHG.cjs.map +0 -1
  156. package/dist/chunk-FFHW2JEK.cjs.map +0 -1
  157. package/dist/chunk-HTGDWIDE.cjs +0 -89
  158. package/dist/chunk-HTGDWIDE.cjs.map +0 -1
  159. package/dist/chunk-LYRUNG6E.cjs +0 -52
  160. package/dist/chunk-LYRUNG6E.cjs.map +0 -1
  161. package/dist/chunk-NMOE2ZEU.cjs.map +0 -1
  162. package/dist/chunk-NYQFPGYP.cjs.map +0 -1
  163. package/dist/chunk-NZ5PMBTG.js.map +0 -1
  164. package/dist/chunk-O57GYGYK.js.map +0 -1
  165. package/dist/chunk-OYLF3IC7.js.map +0 -1
  166. package/dist/chunk-PCHTTG42.js +0 -47
  167. package/dist/chunk-PCHTTG42.js.map +0 -1
  168. package/dist/chunk-PGU2XKMA.js.map +0 -1
  169. package/dist/chunk-PN37HVAV.cjs.map +0 -1
  170. package/dist/chunk-PYJOBZR3.cjs.map +0 -1
  171. package/dist/chunk-TKM2WDT4.js.map +0 -1
  172. package/dist/chunk-TSGBRPNE.js.map +0 -1
  173. package/dist/chunk-U5ROKVRF.js.map +0 -1
  174. package/dist/chunk-WFUN6DCM.cjs.map +0 -1
  175. package/dist/chunk-WVQXAFP3.js.map +0 -1
  176. package/dist/chunk-X3244EKP.cjs.map +0 -1
  177. package/dist/chunk-YEDQLNVE.cjs.map +0 -1
  178. package/dist/chunk-ZTREJOGB.js.map +0 -1
@@ -1,755 +1,13 @@
1
- import { quoteIdentifier } from '../../chunk-3EUKJEQ3.js';
2
- import { createNodeRowMapper, POSTGRES_ROW_MAPPER_CONFIG, createEdgeRowMapper, createUniqueRowMapper, createSchemaVersionRowMapper, tables, createPostgresOperationStrategy, createContributionMaterializer, gateFulltextMethods, createCommonOperationBackend, nowIso, generatePgCreateTableSQL, mapContributionMaterializationRow, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, buildContributionInsertValues, buildContributionOnConflictSet, assertAdoptedDialect, buildKindRemovalInsertValues, POSTGRES_KIND_REMOVAL_TIMESTAMPS, buildKindRemovalOnConflictSet, mapKindRemovalRow, buildMaterializationInsertValues, POSTGRES_INDEX_MAT_TIMESTAMPS, buildMaterializationOnConflictSet, mapMaterializationRow, generatePostgresDDL, generateVectorIndexName, dropPostgresVectorIndex, coerceNumericScore, createPostgresVectorIndex, gateFulltext, compileQueryWithDialect, formatPostgresTimestamp, getOrCreateLru } from '../../chunk-TKM2WDT4.js';
3
- export { createPostgresTables, edges, embeddings, fulltext, generatePostgresDDL, generatePostgresMigrationSQL, nodes, schemaVersions, tables, uniques } from '../../chunk-TKM2WDT4.js';
4
- import { POSTGRES_CAPABILITIES } from '../../chunk-PCHTTG42.js';
5
- import '../../chunk-O57GYGYK.js';
6
- import { tsvectorStrategy, buildFulltextCapabilities } from '../../chunk-ZTREJOGB.js';
7
- import '../../chunk-EJCDOA37.js';
8
- import '../../chunk-OOS2RKRH.js';
9
- import '../../chunk-WVQXAFP3.js';
10
- import { ConfigurationError } from '../../chunk-U5ROKVRF.js';
11
- import '../../chunk-NZ5PMBTG.js';
12
- import { getTableName, sql, and, eq, isNull, inArray } from 'drizzle-orm';
13
- import { PgDatabase, PgTransaction } from 'drizzle-orm/pg-core';
14
-
15
- // src/backend/drizzle/execution/postgres-execution.ts
16
- function hasFunctionProperty(value, property) {
17
- if (value === void 0 || value === null) {
18
- return false;
19
- }
20
- const candidate = value;
21
- return typeof candidate[property] === "function";
22
- }
23
- function isPgNativeClient(candidate) {
24
- return typeof candidate === "object" && hasFunctionProperty(candidate, "query");
25
- }
26
- function isPostgresJsClient(candidate) {
27
- return typeof candidate === "function" && hasFunctionProperty(candidate, "unsafe") && hasFunctionProperty(candidate, "begin");
28
- }
29
- function isNeonHttpClient(db) {
30
- const candidate = db.$client;
31
- return typeof candidate === "function" && hasFunctionProperty(candidate, "transaction") && !hasFunctionProperty(candidate, "begin");
32
- }
33
- var DEFAULT_POSTGRES_STATEMENT_CACHE_MAX = 256;
34
- var STATEMENT_NAME_CACHE = /* @__PURE__ */ new Map();
35
- var nextStatementId = 0;
36
- function statementNameFor(sqlText, cacheMax) {
37
- return getOrCreateLru(STATEMENT_NAME_CACHE, sqlText, cacheMax, () => {
38
- const name = `tg_${nextStatementId}`;
39
- nextStatementId += 1;
40
- return name;
41
- });
42
- }
43
- function normalizeRow(row) {
44
- if (row === null || typeof row !== "object") return row;
45
- let mutated;
46
- for (const key of Object.keys(row)) {
47
- const value = row[key];
48
- if (value instanceof Date) {
49
- mutated ??= { ...row };
50
- mutated[key] = value.toISOString();
51
- }
52
- }
53
- return mutated ?? row;
54
- }
55
- function normalizeRows(rows) {
56
- let mutated;
57
- for (let index = 0; index < rows.length; index += 1) {
58
- const original = rows[index];
59
- const normalized = normalizeRow(original);
60
- if (normalized !== original) {
61
- mutated ??= [...rows];
62
- mutated[index] = normalized;
63
- }
64
- }
65
- return mutated ?? rows;
66
- }
67
- function wrapNodePgClient(client, cacheMax) {
68
- return {
69
- async query(sqlText, params) {
70
- const result = await client.query({
71
- name: statementNameFor(sqlText, cacheMax),
72
- text: sqlText,
73
- values: params
74
- });
75
- return { rows: normalizeRows(result.rows) };
76
- }
77
- };
78
- }
79
- function wrapNodePgClientUnnamed(client) {
80
- return {
81
- async query(sqlText, params) {
82
- const result = await client.query(sqlText, params);
83
- return { rows: normalizeRows(result.rows) };
84
- }
85
- };
86
- }
87
- function adaptPostgresJsClient(sql2) {
88
- return {
89
- async query(sqlText, params) {
90
- const rows = await sql2.unsafe(sqlText, params);
91
- return { rows };
92
- }
93
- };
94
- }
95
- function resolvePgClient(db, prepareStatements, cacheMax) {
96
- if (isNeonHttpClient(db)) {
97
- return void 0;
98
- }
99
- const client = db.$client;
100
- if (isPgNativeClient(client)) {
101
- return prepareStatements ? wrapNodePgClient(client, cacheMax) : wrapNodePgClientUnnamed(client);
102
- }
103
- if (isPostgresJsClient(client)) {
104
- return adaptPostgresJsClient(client);
105
- }
106
- return void 0;
107
- }
108
- async function executeDrizzleQuery(db, query) {
109
- const result = await db.execute(query);
110
- if (Array.isArray(result)) {
111
- return result;
112
- }
113
- return result.rows;
114
- }
115
- function createPgPreparedStatement(pgClient, sqlText) {
116
- return {
117
- async execute(params) {
118
- const result = await pgClient.query(sqlText, params);
119
- return result.rows;
120
- }
121
- };
122
- }
123
- function createPostgresExecutionAdapter(db, options = {}) {
124
- const prepareStatements = options.prepareStatements ?? true;
125
- const cacheMax = options.preparedStatementCacheMax ?? DEFAULT_POSTGRES_STATEMENT_CACHE_MAX;
126
- const pgClient = resolvePgClient(db, prepareStatements, cacheMax);
127
- function compile(query) {
128
- return compileQueryWithDialect(db, query, "PostgreSQL");
129
- }
130
- if (pgClient === void 0) {
131
- return {
132
- compile,
133
- async execute(query) {
134
- return executeDrizzleQuery(db, query);
135
- }
136
- };
137
- }
138
- const pgQueryClient = pgClient;
139
- async function executeCompiled(compiledQuery) {
140
- const result = await pgQueryClient.query(
141
- compiledQuery.sql,
142
- compiledQuery.params
143
- );
144
- return result.rows;
145
- }
146
- return {
147
- compile,
148
- async execute(query) {
149
- const compiled = compile(query);
150
- return executeCompiled(compiled);
151
- },
152
- executeCompiled,
153
- prepare(sqlText) {
154
- return createPgPreparedStatement(pgQueryClient, sqlText);
155
- }
156
- };
157
- }
158
-
159
- // src/backend/drizzle/postgres.ts
160
- var POSTGRES_MAX_BIND_PARAMETERS = 65535;
161
- var NODE_INSERT_PARAM_COUNT = 9;
162
- var EDGE_INSERT_PARAM_COUNT = 12;
163
- var POSTGRES_NODE_INSERT_BATCH_SIZE = Math.max(
164
- 1,
165
- Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT)
166
- );
167
- var POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(
168
- 1,
169
- Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT)
170
- );
171
- var POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(
172
- 1,
173
- POSTGRES_MAX_BIND_PARAMETERS - 2
174
- );
175
- var POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(
176
- 1,
177
- POSTGRES_MAX_BIND_PARAMETERS - 1
178
- );
179
- var CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT = 3;
180
- var POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(
181
- 1,
182
- POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
183
- );
184
- var toNodeRow = createNodeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
185
- var toEdgeRow = createEdgeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
186
- var toUniqueRow = createUniqueRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
187
- var toSchemaVersionRow = createSchemaVersionRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
188
- function toEmbeddingRow(row) {
189
- let embedding;
190
- if (typeof row.embedding === "string") {
191
- const content = row.embedding.slice(1, -1);
192
- embedding = content === "" ? [] : content.split(",").map((s) => Number.parseFloat(s.trim()));
193
- } else if (Array.isArray(row.embedding)) {
194
- embedding = row.embedding;
195
- } else {
196
- embedding = [];
197
- }
198
- return {
199
- graph_id: row.graph_id,
200
- node_kind: row.node_kind,
201
- node_id: row.node_id,
202
- field_path: row.field_path,
203
- embedding,
204
- dimensions: row.dimensions,
205
- created_at: formatPostgresTimestamp(row.created_at) ?? "",
206
- updated_at: formatPostgresTimestamp(row.updated_at) ?? ""
207
- };
208
- }
209
- function buildPostgresCapabilities(strategy) {
210
- return {
211
- ...POSTGRES_CAPABILITIES,
212
- vector: {
213
- supported: true,
214
- metrics: ["cosine", "l2", "inner_product"],
215
- indexTypes: ["hnsw", "ivfflat", "none"],
216
- maxDimensions: 16e3
217
- // pgvector limit
218
- },
219
- fulltext: buildFulltextCapabilities(strategy)
220
- };
221
- }
222
- function createPostgresBackend(db, options = {}) {
223
- const tables2 = options.tables ?? tables;
224
- const fulltextStrategy = options.fulltext ?? tsvectorStrategy;
225
- const baseCapabilities = buildPostgresCapabilities(fulltextStrategy);
226
- const httpOnlyOverrides = isNeonHttpClient(db) ? { transactions: false } : {};
227
- const capabilities = {
228
- ...baseCapabilities,
229
- ...httpOnlyOverrides,
230
- ...options.capabilities
231
- };
232
- const adapterOptions = {
233
- ...options.prepareStatements === void 0 ? {} : { prepareStatements: options.prepareStatements },
234
- ...options.preparedStatementCacheMax === void 0 ? {} : { preparedStatementCacheMax: options.preparedStatementCacheMax }
235
- };
236
- const executionAdapter = createPostgresExecutionAdapter(db, adapterOptions);
237
- const tableNames = {
238
- nodes: getTableName(tables2.nodes),
239
- edges: getTableName(tables2.edges),
240
- embeddings: getTableName(tables2.embeddings),
241
- fulltext: tables2.fulltextTableName,
242
- uniques: getTableName(tables2.uniques)
243
- };
244
- const analyzeStatement = sql`ANALYZE ${sql.join(
245
- [
246
- tableNames.nodes,
247
- tableNames.edges,
248
- getTableName(tables2.uniques),
249
- tableNames.embeddings,
250
- tableNames.fulltext
251
- ].map((name) => quoteIdentifier(name)),
252
- sql`, `
253
- )}`;
254
- const operationStrategy = createPostgresOperationStrategy(
255
- tables2,
256
- fulltextStrategy
257
- );
258
- const operations = createPostgresOperationBackend({
259
- db,
260
- executionAdapter,
261
- adapterOptions,
262
- operationStrategy,
263
- tableNames,
264
- capabilities,
265
- fulltextStrategy
266
- });
267
- function runSchemaWriteTransaction(graphId, fn) {
268
- if (!capabilities.transactions) {
269
- throw new ConfigurationError(
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.",
271
- {
272
- backend: "postgres",
273
- capability: "transactions",
274
- supportsTransactions: false
275
- }
276
- );
277
- }
278
- return db.transaction(async (tx) => {
279
- await tx.execute(
280
- sql`SELECT pg_advisory_xact_lock(hashtext(${graphId}))`
281
- );
282
- const txBackend = createTransactionBackend({
283
- db: tx,
284
- adapterOptions,
285
- operationStrategy,
286
- tableNames,
287
- capabilities,
288
- fulltextStrategy
289
- });
290
- return fn(txBackend);
291
- });
292
- }
293
- const matTable = tables2.contributionMaterializations;
294
- async function ensureContributionMaterializationsTableImpl() {
295
- await db.execute(sql.raw(generatePgCreateTableSQL(matTable)));
296
- }
297
- async function getContributionMaterializationRow(identity) {
298
- const rows = await db.select().from(matTable).where(
299
- and(
300
- eq(matTable.graphId, identity.graphId),
301
- eq(matTable.logicalName, identity.logicalName),
302
- eq(matTable.owner, identity.owner),
303
- eq(matTable.tableName, identity.tableName)
304
- )
305
- );
306
- const row = rows[0];
307
- if (row === void 0) return void 0;
308
- return mapContributionMaterializationRow(
309
- row,
310
- POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS.decode
311
- );
312
- }
313
- async function recordContributionMaterializationRow(params) {
314
- await db.insert(matTable).values(
315
- buildContributionInsertValues(
316
- params,
317
- 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: buildContributionOnConflictSet(
327
- matTable.materializedAt,
328
- params.materializedAt
329
- )
330
- });
331
- }
332
- const contributionMaterializer = createContributionMaterializer({
333
- dialect: "postgres",
334
- fulltextStrategy,
335
- fulltextTableName: tables2.fulltextTableName,
336
- execDdl: async (statement) => {
337
- await db.execute(sql.raw(statement));
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 gateFulltext(txBackend, contributionMaterializer.assertInitialized);
353
- }
354
- const backend = {
355
- ...operations,
356
- async bootstrapTables() {
357
- const statements = generatePostgresDDL(tables2, fulltextStrategy);
358
- for (const statement of statements) {
359
- await db.execute(sql.raw(statement));
360
- }
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
- ...gateFulltextMethods(
368
- operations,
369
- contributionMaterializer.assertInitialized
370
- ),
371
- async executeDdl(ddl) {
372
- await db.execute(sql.raw(ddl));
373
- },
374
- async ensureIndexMaterializationsTable() {
375
- await db.execute(
376
- sql.raw(generatePgCreateTableSQL(tables2.indexMaterializations))
377
- );
378
- },
379
- async getIndexMaterialization(indexName) {
380
- const t = tables2.indexMaterializations;
381
- const rows = await db.select().from(t).where(eq(t.indexName, indexName));
382
- const row = rows[0];
383
- if (row === void 0) return void 0;
384
- return mapMaterializationRow(row, POSTGRES_INDEX_MAT_TIMESTAMPS.decode);
385
- },
386
- async getIndexMaterializations(statusKeys) {
387
- if (statusKeys.length === 0) return [];
388
- const t = tables2.indexMaterializations;
389
- const rows = await db.select().from(t).where(inArray(t.indexName, [...statusKeys]));
390
- return rows.map(
391
- (row) => mapMaterializationRow(row, POSTGRES_INDEX_MAT_TIMESTAMPS.decode)
392
- );
393
- },
394
- async recordIndexMaterialization(params) {
395
- const t = tables2.indexMaterializations;
396
- await db.insert(t).values(
397
- buildMaterializationInsertValues(
398
- params,
399
- POSTGRES_INDEX_MAT_TIMESTAMPS.encode
400
- )
401
- ).onConflictDoUpdate({
402
- target: t.indexName,
403
- set: buildMaterializationOnConflictSet(
404
- t.materializedAt,
405
- params.materializedAt
406
- )
407
- });
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
- },
421
- async ensureKindRemovalsTable() {
422
- await db.execute(
423
- sql.raw(generatePgCreateTableSQL(tables2.kindRemovals))
424
- );
425
- },
426
- async getPendingKindRemovals(graphId) {
427
- const t = tables2.kindRemovals;
428
- const rows = await db.select().from(t).where(and(eq(t.graphId, graphId), isNull(t.removedAt)));
429
- return rows.map(
430
- (row) => mapKindRemovalRow(row, POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
431
- );
432
- },
433
- async getAllKindRemovals(graphId) {
434
- const t = tables2.kindRemovals;
435
- const rows = await db.select().from(t).where(eq(t.graphId, graphId));
436
- return rows.map(
437
- (row) => mapKindRemovalRow(row, POSTGRES_KIND_REMOVAL_TIMESTAMPS.decode)
438
- );
439
- },
440
- async recordKindRemoval(params) {
441
- const t = tables2.kindRemovals;
442
- await db.insert(t).values(
443
- buildKindRemovalInsertValues(
444
- params,
445
- POSTGRES_KIND_REMOVAL_TIMESTAMPS.encode
446
- )
447
- ).onConflictDoUpdate({
448
- target: [t.graphId, t.kindName, t.entity, t.schemaVersion],
449
- set: buildKindRemovalOnConflictSet(t.removedAt, params.removedAt)
450
- });
451
- },
452
- async ensureReconciliationMarkersTable() {
453
- await db.execute(
454
- sql.raw(generatePgCreateTableSQL(tables2.reconciliationMarkers))
455
- );
456
- },
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);
467
- },
468
- async getReconciliationMarker(graphId) {
469
- const t = tables2.reconciliationMarkers;
470
- const rows = await db.select().from(t).where(eq(t.graphId, graphId));
471
- return rows[0]?.reconciledToVersion;
472
- },
473
- async setReconciliationMarker(graphId, version) {
474
- const t = tables2.reconciliationMarkers;
475
- await db.insert(t).values({ graphId, reconciledToVersion: version }).onConflictDoUpdate({
476
- target: t.graphId,
477
- set: { reconciledToVersion: version }
478
- });
479
- },
480
- async refreshStatistics() {
481
- await db.execute(analyzeStatement);
482
- },
483
- async commitSchemaVersion(params) {
484
- return runSchemaWriteTransaction(
485
- params.graphId,
486
- (target) => target.commitSchemaVersion(params)
487
- );
488
- },
489
- async setActiveVersion(params) {
490
- await runSchemaWriteTransaction(
491
- params.graphId,
492
- (target) => target.setActiveVersion(params)
493
- );
494
- },
495
- async transaction(fn, options2) {
496
- const txConfig = options2?.isolationLevel ? {
497
- isolationLevel: options2.isolationLevel.replace("_", " ")
498
- } : void 0;
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 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
- assertAdoptedDialect(externalTx, PgDatabase, "postgres");
516
- return bindTransactionBackend(externalTx);
517
- },
518
- async close() {
519
- }
520
- };
521
- return backend;
522
- }
523
- function createPostgresOperationBackend(options) {
524
- const {
525
- db,
526
- executionAdapter,
527
- adapterOptions,
528
- operationStrategy,
529
- tableNames,
530
- capabilities,
531
- fulltextStrategy
532
- } = options;
533
- async function execAll(query) {
534
- return executionAdapter.execute(query);
535
- }
536
- async function execGet(query) {
537
- const rows = await executionAdapter.execute(query);
538
- return rows[0];
539
- }
540
- async function execRun(query) {
541
- await executionAdapter.execute(query);
542
- }
543
- let efSearchUnsupportedWarned = false;
544
- function warnEfSearchUnsupported() {
545
- if (efSearchUnsupportedWarned) return;
546
- efSearchUnsupportedWarned = true;
547
- if (typeof console === "undefined" || typeof console.warn !== "function") {
548
- return;
549
- }
550
- console.warn(
551
- "[typegraph] efSearch (hnsw.ef_search override) was ignored: this Postgres backend has transactions disabled (e.g. drizzle-orm/neon-http), and SET LOCAL needs a transaction to scope the override. Use a transactional driver (node-postgres / neon-serverless / postgres-js) to apply efSearch."
552
- );
553
- }
554
- async function runVectorSearch(efSearch, query) {
555
- if (efSearch === void 0) {
556
- return execAll(query);
557
- }
558
- if (!capabilities.transactions) {
559
- warnEfSearchUnsupported();
560
- return execAll(query);
561
- }
562
- const setEfSearch = sql.raw(`SET LOCAL hnsw.ef_search = ${efSearch}`);
563
- if (db instanceof PgTransaction) {
564
- const [setting] = await execAll(
565
- sql`SELECT current_setting('hnsw.ef_search') AS ef_search`
566
- );
567
- await execRun(setEfSearch);
568
- const rows = await execAll(query);
569
- if (setting !== void 0) {
570
- await execRun(
571
- sql`SELECT set_config('hnsw.ef_search', ${setting.ef_search}, true)`
572
- );
573
- }
574
- return rows;
575
- }
576
- return db.transaction(async (tx) => {
577
- const txAdapter = createPostgresExecutionAdapter(tx, adapterOptions);
578
- await txAdapter.execute(setEfSearch);
579
- return txAdapter.execute(query);
580
- });
581
- }
582
- const commonBackend = createCommonOperationBackend({
583
- batchConfig: {
584
- checkUniqueBatchChunkSize: POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE,
585
- edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,
586
- getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,
587
- getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,
588
- nodeInsertBatchSize: POSTGRES_NODE_INSERT_BATCH_SIZE
589
- },
590
- execution: {
591
- execAll,
592
- execGet,
593
- execRun
594
- },
595
- nowIso,
596
- operationStrategy,
597
- rowMappers: {
598
- toEdgeRow,
599
- toNodeRow,
600
- toSchemaVersionRow,
601
- toUniqueRow
602
- }
603
- });
604
- const executeCompiled = executionAdapter.executeCompiled;
605
- const executeRawMethod = executeCompiled === void 0 ? {} : {
606
- async executeRaw(sqlText, params) {
607
- return executeCompiled({ params, sql: sqlText });
608
- }
609
- };
610
- const operationBackend = {
611
- ...commonBackend,
612
- ...executeRawMethod,
613
- capabilities,
614
- fulltextStrategy,
615
- dialect: "postgres",
616
- tableNames,
617
- // === Embedding Operations ===
618
- async upsertEmbedding(params) {
619
- const timestamp = nowIso();
620
- const query = operationStrategy.buildUpsertEmbedding(params, timestamp);
621
- await execRun(query);
622
- },
623
- async deleteEmbedding(params) {
624
- const query = operationStrategy.buildDeleteEmbedding(params);
625
- await execRun(query);
626
- },
627
- async getEmbedding(graphId, nodeKind, nodeId, fieldPath) {
628
- const query = operationStrategy.buildGetEmbedding(
629
- graphId,
630
- nodeKind,
631
- nodeId,
632
- fieldPath
633
- );
634
- const row = await execGet(query);
635
- return row ? toEmbeddingRow(row) : void 0;
636
- },
637
- async vectorSearch(params) {
638
- const query = operationStrategy.buildVectorSearch(params);
639
- const rows = await runVectorSearch(params.efSearch, query);
640
- return rows.map((row) => ({
641
- nodeId: row.node_id,
642
- score: row.score
643
- }));
644
- },
645
- async createVectorIndex(params) {
646
- const indexOptions = {
647
- graphId: params.graphId,
648
- nodeKind: params.nodeKind,
649
- fieldPath: params.fieldPath,
650
- dimensions: params.dimensions,
651
- embeddingsTableName: tableNames.embeddings,
652
- indexType: params.indexType,
653
- metric: params.metric,
654
- ...params.indexParams?.m === void 0 ? {} : { hnswM: params.indexParams.m },
655
- ...params.indexParams?.efConstruction === void 0 ? {} : { hnswEfConstruction: params.indexParams.efConstruction },
656
- ...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists },
657
- ...params.concurrent === true ? { concurrent: true } : {}
658
- };
659
- const result = await createPostgresVectorIndex(db, indexOptions);
660
- if (!result.success) {
661
- throw new Error(
662
- result.message ?? "Failed to create PostgreSQL vector index"
663
- );
664
- }
665
- },
666
- // === Fulltext Operations ===
667
- async upsertFulltext(params) {
668
- const timestamp = nowIso();
669
- const statements = operationStrategy.buildUpsertFulltext(
670
- params,
671
- timestamp
672
- );
673
- for (const stmt of statements) {
674
- await execRun(stmt);
675
- }
676
- },
677
- async deleteFulltext(params) {
678
- const statements = operationStrategy.buildDeleteFulltext(params);
679
- for (const stmt of statements) {
680
- await execRun(stmt);
681
- }
682
- },
683
- async upsertFulltextBatch(params) {
684
- if (params.rows.length === 0) return;
685
- const timestamp = nowIso();
686
- const statements = operationStrategy.buildUpsertFulltextBatch(
687
- params,
688
- timestamp
689
- );
690
- for (const stmt of statements) {
691
- await execRun(stmt);
692
- }
693
- },
694
- async deleteFulltextBatch(params) {
695
- if (params.nodeIds.length === 0) return;
696
- const statements = operationStrategy.buildDeleteFulltextBatch(params);
697
- for (const stmt of statements) {
698
- await execRun(stmt);
699
- }
700
- },
701
- async fulltextSearch(params) {
702
- const query = operationStrategy.buildFulltextSearch(params);
703
- const rows = await execAll(query);
704
- return rows.map((row, index) => ({
705
- nodeId: row.node_id,
706
- score: coerceNumericScore(row.score),
707
- rank: index + 1,
708
- ...row.snippet === null ? {} : { snippet: row.snippet }
709
- }));
710
- },
711
- async dropVectorIndex(params) {
712
- const metrics = capabilities.vector?.metrics ?? ["cosine"];
713
- await Promise.all(
714
- metrics.map(async (metric) => {
715
- const indexName = generateVectorIndexName(
716
- params.graphId,
717
- params.nodeKind,
718
- params.fieldPath,
719
- metric
720
- );
721
- const result = await dropPostgresVectorIndex(db, indexName);
722
- if (!result.success) {
723
- throw new Error(
724
- result.message ?? "Failed to drop PostgreSQL vector index"
725
- );
726
- }
727
- })
728
- );
729
- },
730
- // === Query Execution ===
731
- async execute(query) {
732
- return executionAdapter.execute(query);
733
- },
734
- compileSql(query) {
735
- return executionAdapter.compile(query);
736
- }
737
- };
738
- return operationBackend;
739
- }
740
- function createTransactionBackend(options) {
741
- const txExecutionAdapter = options.executionAdapter ?? createPostgresExecutionAdapter(options.db, options.adapterOptions);
742
- return createPostgresOperationBackend({
743
- db: options.db,
744
- executionAdapter: txExecutionAdapter,
745
- adapterOptions: options.adapterOptions,
746
- operationStrategy: options.operationStrategy,
747
- tableNames: options.tableNames,
748
- capabilities: options.capabilities,
749
- fulltextStrategy: options.fulltextStrategy
750
- });
751
- }
752
-
753
- export { createPostgresBackend };
1
+ export { createPostgresBackend } from '../../chunk-K5VREXMZ.js';
2
+ import '../../chunk-FVIGJTS7.js';
3
+ export { createPostgresTables, edges, fulltext, generatePostgresDDL, generatePostgresMigrationSQL, nodes, schemaVersions, tables, uniques } from '../../chunk-N2OEOGBB.js';
4
+ import '../../chunk-633N7DSE.js';
5
+ import '../../chunk-M6OC455F.js';
6
+ import '../../chunk-AI3RNREM.js';
7
+ import '../../chunk-R4JOBEJU.js';
8
+ import '../../chunk-MXE2U3EX.js';
9
+ import '../../chunk-454I6GDF.js';
10
+ import '../../chunk-TQOYM4LN.js';
11
+ import '../../chunk-K5P5OZXS.js';
754
12
  //# sourceMappingURL=index.js.map
755
13
  //# sourceMappingURL=index.js.map