@nicia-ai/typegraph 0.24.1 → 0.25.1
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.
- package/dist/backend/postgres/index.cjs +226 -55
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +6 -7
- package/dist/backend/postgres/index.d.ts +6 -7
- package/dist/backend/postgres/index.js +195 -28
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +19 -17
- package/dist/backend/sqlite/index.d.cts +6 -7
- package/dist/backend/sqlite/index.d.ts +6 -7
- package/dist/backend/sqlite/index.js +9 -7
- package/dist/backend/sqlite/libsql.cjs +12 -10
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +9 -7
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +14 -12
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +9 -7
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/chunk-4BOWVUGQ.js +2029 -0
- package/dist/chunk-4BOWVUGQ.js.map +1 -0
- package/dist/chunk-7V335GHG.cjs +112 -0
- package/dist/chunk-7V335GHG.cjs.map +1 -0
- package/dist/chunk-AAA2CR3P.js +2628 -0
- package/dist/chunk-AAA2CR3P.js.map +1 -0
- package/dist/{chunk-QOLTW7OZ.js → chunk-CLEUFN2K.js} +195 -13
- package/dist/chunk-CLEUFN2K.js.map +1 -0
- package/dist/{chunk-OVJ2BE5Q.cjs → chunk-CLGC7AQ2.cjs} +215 -33
- package/dist/chunk-CLGC7AQ2.cjs.map +1 -0
- package/dist/{chunk-GUTQTMOV.js → chunk-CPFR3O7L.js} +2 -2
- package/dist/chunk-CPFR3O7L.js.map +1 -0
- package/dist/{chunk-5HVDOPZU.cjs → chunk-CQVNGKU7.cjs} +452 -104
- package/dist/chunk-CQVNGKU7.cjs.map +1 -0
- package/dist/chunk-CTHNVU6K.cjs +551 -0
- package/dist/chunk-CTHNVU6K.cjs.map +1 -0
- package/dist/chunk-D2GO3RBL.cjs +12 -0
- package/dist/chunk-D2GO3RBL.cjs.map +1 -0
- package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
- package/dist/chunk-DOTEN2FG.js.map +1 -0
- package/dist/chunk-E5JZSEGJ.cjs +301 -0
- package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
- package/dist/chunk-EG6TJ3I5.js +286 -0
- package/dist/chunk-EG6TJ3I5.js.map +1 -0
- package/dist/chunk-EJCDOA37.js +537 -0
- package/dist/chunk-EJCDOA37.js.map +1 -0
- package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
- package/dist/chunk-EK6RJ373.cjs.map +1 -0
- package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
- package/dist/chunk-JTI5WT4P.cjs.map +1 -0
- package/dist/chunk-NHQWXSTS.js +10 -0
- package/dist/chunk-NHQWXSTS.js.map +1 -0
- package/dist/chunk-NZ5PMBTG.js +105 -0
- package/dist/chunk-NZ5PMBTG.js.map +1 -0
- package/dist/{chunk-SUHW2UYL.cjs → chunk-OECDVACY.cjs} +2 -2
- package/dist/chunk-OECDVACY.cjs.map +1 -0
- package/dist/{chunk-EYELZHKY.js → chunk-OOS2RKRH.js} +5 -140
- package/dist/chunk-OOS2RKRH.js.map +1 -0
- package/dist/{chunk-EY4LBX3F.js → chunk-PSKUWVCB.js} +373 -38
- package/dist/chunk-PSKUWVCB.js.map +1 -0
- package/dist/chunk-QMQYK3IF.cjs +2680 -0
- package/dist/chunk-QMQYK3IF.cjs.map +1 -0
- package/dist/chunk-RCAJZG67.cjs +2069 -0
- package/dist/chunk-RCAJZG67.cjs.map +1 -0
- package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
- package/dist/chunk-W5MTHMTE.cjs.map +1 -0
- package/dist/chunk-WVQXAFP3.js +79 -0
- package/dist/chunk-WVQXAFP3.js.map +1 -0
- package/dist/chunk-X3244EKP.cjs +84 -0
- package/dist/chunk-X3244EKP.cjs.map +1 -0
- package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
- package/dist/chunk-YZZBDCLV.js.map +1 -0
- package/dist/{ddl-B_H8JM-E.d.cts → ddl-BqMmpNor.d.ts} +1328 -283
- package/dist/{ddl-1tFIvt9V.d.ts → ddl-Bwjh8Hff.d.cts} +1328 -283
- package/dist/extension-types-D07e_NTw.d.cts +543 -0
- package/dist/extension-types-D07e_NTw.d.ts +543 -0
- package/dist/graph-extension/index.cjs +71 -0
- package/dist/graph-extension/index.cjs.map +1 -0
- package/dist/graph-extension/index.d.cts +278 -0
- package/dist/graph-extension/index.d.ts +278 -0
- package/dist/graph-extension/index.js +6 -0
- package/dist/graph-extension/index.js.map +1 -0
- package/dist/{index-DXkEXpNz.d.ts → index-CT6nvtxL.d.cts} +114 -5
- package/dist/{index-DXkEXpNz.d.cts → index-DQheiVQV.d.ts} +114 -5
- package/dist/index.cjs +2672 -901
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.js +2248 -598
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +25 -23
- package/dist/indexes/index.d.cts +40 -22
- package/dist/indexes/index.d.ts +40 -22
- package/dist/indexes/index.js +5 -3
- package/dist/interchange/index.cjs +8 -7
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +5 -4
- package/dist/interchange/index.d.ts +5 -4
- package/dist/interchange/index.js +3 -2
- package/dist/interchange/index.js.map +1 -1
- package/dist/{manager-Vkz28eAC.d.cts → manager-Cy3dhwYO.d.cts} +194 -6
- package/dist/{manager-nIhmttD-.d.ts → manager-sZkU2VPC.d.ts} +194 -6
- package/dist/materialize-indexes-BB9N5uQl.d.cts +68 -0
- package/dist/materialize-indexes-BYpU2RKh.d.ts +68 -0
- package/dist/profiler/index.cjs +10 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +8 -7
- package/dist/profiler/index.d.ts +8 -7
- package/dist/profiler/index.js +3 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +43 -22
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +17 -8
- package/dist/schema/index.d.ts +17 -8
- package/dist/schema/index.js +9 -4
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-D0aceIe0.d.cts → sqlite-BhFswiAR.d.cts} +837 -120
- package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-h6dta1IJ.d.ts} +837 -120
- package/dist/{store-CpvwTMxV.d.cts → store-BS_hehiz.d.ts} +659 -23
- package/dist/{store-U3i2tUch.d.ts → store-CkCvqRUf.d.cts} +659 -23
- package/dist/{types-yH4_p0XB.d.cts → types-BpgACExN.d.cts} +3 -2
- package/dist/{types-qYFZ9SqD.d.ts → types-Bz-Pi681.d.ts} +3 -2
- package/dist/types-DptZHe-l.d.ts +2132 -0
- package/dist/types-WF5ItKQu.d.cts +2132 -0
- package/dist/where-C40InMIp.d.ts +11 -0
- package/dist/where-DZYMiXVq.d.cts +11 -0
- package/package.json +33 -73
- package/dist/ast-C8S37w1A.d.ts +0 -497
- package/dist/ast-dgLhLOg0.d.cts +0 -497
- package/dist/chunk-3JK66E3I.cjs.map +0 -1
- package/dist/chunk-3PPEHLGK.js +0 -1116
- package/dist/chunk-3PPEHLGK.js.map +0 -1
- package/dist/chunk-5HVDOPZU.cjs.map +0 -1
- package/dist/chunk-753F33CV.js.map +0 -1
- package/dist/chunk-EY4LBX3F.js.map +0 -1
- package/dist/chunk-EYELZHKY.js.map +0 -1
- package/dist/chunk-GFGVREHH.js +0 -1381
- package/dist/chunk-GFGVREHH.js.map +0 -1
- package/dist/chunk-GUTQTMOV.js.map +0 -1
- package/dist/chunk-LBORRUNJ.js +0 -135
- package/dist/chunk-LBORRUNJ.js.map +0 -1
- package/dist/chunk-O5PST6TB.cjs.map +0 -1
- package/dist/chunk-OLROXS2S.cjs +0 -147
- package/dist/chunk-OLROXS2S.cjs.map +0 -1
- package/dist/chunk-OVJ2BE5Q.cjs.map +0 -1
- package/dist/chunk-PAUN562Y.cjs +0 -1417
- package/dist/chunk-PAUN562Y.cjs.map +0 -1
- package/dist/chunk-PEE4EWXZ.cjs +0 -1131
- package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
- package/dist/chunk-QOLTW7OZ.js.map +0 -1
- package/dist/chunk-SUHW2UYL.cjs.map +0 -1
- package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
- package/dist/chunk-WFMTAEEN.js.map +0 -1
- package/dist/types-C-zfYDJB.d.ts +0 -159
- package/dist/types-CQx4iW5Y.d.cts +0 -159
- package/dist/types-Qk2l3IkQ.d.cts +0 -1254
- package/dist/types-Qk2l3IkQ.d.ts +0 -1254
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, getTableConfig as getTableConfig$1 } from 'drizzle-orm/pg-core';
|
|
5
|
-
import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, blob, getTableConfig } from 'drizzle-orm/sqlite-core';
|
|
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';
|
|
6
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';
|
|
7
7
|
|
|
8
|
+
var regconfig = customType({
|
|
9
|
+
dataType: () => "regconfig"
|
|
10
|
+
});
|
|
11
|
+
var tsvector = customType({
|
|
12
|
+
dataType: () => "tsvector"
|
|
13
|
+
});
|
|
8
14
|
var vector = customType({
|
|
9
15
|
dataType(config) {
|
|
10
16
|
return config?.dimensions ? `vector(${config.dimensions})` : "vector";
|
|
@@ -31,7 +37,10 @@ var DEFAULT_TABLE_NAMES = {
|
|
|
31
37
|
uniques: "typegraph_node_uniques",
|
|
32
38
|
schemaVersions: "typegraph_schema_versions",
|
|
33
39
|
embeddings: "typegraph_node_embeddings",
|
|
34
|
-
fulltext: "typegraph_node_fulltext"
|
|
40
|
+
fulltext: "typegraph_node_fulltext",
|
|
41
|
+
indexMaterializations: "typegraph_index_materializations",
|
|
42
|
+
kindRemovals: "typegraph_kind_removals",
|
|
43
|
+
reconciliationMarkers: "typegraph_reconciliation_markers"
|
|
35
44
|
};
|
|
36
45
|
function createPostgresTables(names = {}, options = {}) {
|
|
37
46
|
const n = { ...DEFAULT_TABLE_NAMES, ...names };
|
|
@@ -153,7 +162,13 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
153
162
|
},
|
|
154
163
|
(t) => [
|
|
155
164
|
primaryKey({ columns: [t.graphId, t.version] }),
|
|
156
|
-
index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
|
|
165
|
+
index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
|
|
166
|
+
// Partial unique index enforcing the "at most one active version
|
|
167
|
+
// per graph" invariant at the storage layer. Defense in depth
|
|
168
|
+
// against buggy backend implementations or out-of-band writes.
|
|
169
|
+
// Forces the deactivate-then-activate ordering used by
|
|
170
|
+
// `commitSchemaVersion` and `setActiveVersion`.
|
|
171
|
+
uniqueIndex(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = TRUE`)
|
|
157
172
|
]
|
|
158
173
|
);
|
|
159
174
|
const embeddings3 = pgTable(
|
|
@@ -188,33 +203,99 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
188
203
|
)
|
|
189
204
|
]
|
|
190
205
|
);
|
|
206
|
+
const indexMaterializations = pgTable(
|
|
207
|
+
n.indexMaterializations,
|
|
208
|
+
{
|
|
209
|
+
indexName: text("index_name").notNull(),
|
|
210
|
+
graphId: text("graph_id").notNull(),
|
|
211
|
+
entity: text("entity").notNull(),
|
|
212
|
+
kind: text("kind").notNull(),
|
|
213
|
+
signature: text("signature").notNull(),
|
|
214
|
+
schemaVersion: integer("schema_version").notNull(),
|
|
215
|
+
materializedAt: timestamp("materialized_at", { withTimezone: true }),
|
|
216
|
+
lastAttemptedAt: timestamp("last_attempted_at", {
|
|
217
|
+
withTimezone: true
|
|
218
|
+
}).notNull(),
|
|
219
|
+
lastError: text("last_error")
|
|
220
|
+
},
|
|
221
|
+
(t) => [primaryKey({ columns: [t.indexName] })]
|
|
222
|
+
);
|
|
223
|
+
const kindRemovals = pgTable(
|
|
224
|
+
n.kindRemovals,
|
|
225
|
+
{
|
|
226
|
+
graphId: text("graph_id").notNull(),
|
|
227
|
+
kindName: text("kind_name").notNull(),
|
|
228
|
+
entity: text("entity").notNull(),
|
|
229
|
+
schemaVersion: integer("schema_version").notNull(),
|
|
230
|
+
removedAt: timestamp("removed_at", { withTimezone: true }),
|
|
231
|
+
lastAttemptedAt: timestamp("last_attempted_at", {
|
|
232
|
+
withTimezone: true
|
|
233
|
+
}).notNull(),
|
|
234
|
+
lastError: text("last_error")
|
|
235
|
+
},
|
|
236
|
+
(t) => [
|
|
237
|
+
primaryKey({
|
|
238
|
+
columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
|
|
239
|
+
})
|
|
240
|
+
]
|
|
241
|
+
);
|
|
242
|
+
const reconciliationMarkers = pgTable(
|
|
243
|
+
n.reconciliationMarkers,
|
|
244
|
+
{
|
|
245
|
+
graphId: text("graph_id").notNull(),
|
|
246
|
+
reconciledToVersion: integer("reconciled_to_version").notNull()
|
|
247
|
+
},
|
|
248
|
+
(t) => [primaryKey({ columns: [t.graphId] })]
|
|
249
|
+
);
|
|
250
|
+
const fulltext2 = pgTable(
|
|
251
|
+
n.fulltext,
|
|
252
|
+
{
|
|
253
|
+
graphId: text("graph_id").notNull(),
|
|
254
|
+
nodeKind: text("node_kind").notNull(),
|
|
255
|
+
nodeId: text("node_id").notNull(),
|
|
256
|
+
content: text("content").notNull(),
|
|
257
|
+
language: regconfig("language").notNull(),
|
|
258
|
+
tsv: tsvector("tsv").generatedAlwaysAs(sql`to_tsvector("language", "content")`).notNull(),
|
|
259
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
260
|
+
},
|
|
261
|
+
(t) => [
|
|
262
|
+
primaryKey({ columns: [t.graphId, t.nodeKind, t.nodeId] }),
|
|
263
|
+
index(`${n.fulltext}_tsv_idx`).using("gin", t.tsv),
|
|
264
|
+
index(`${n.fulltext}_kind_idx`).on(t.graphId, t.nodeKind)
|
|
265
|
+
]
|
|
266
|
+
);
|
|
191
267
|
return {
|
|
192
268
|
nodes: nodes3,
|
|
193
269
|
edges: edges3,
|
|
194
270
|
uniques: uniques3,
|
|
195
271
|
schemaVersions: schemaVersions3,
|
|
196
272
|
embeddings: embeddings3,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
* and a GIN index; alternate strategies (ParadeDB, pg_trgm, pgroonga)
|
|
202
|
-
* pick their own column types and index methods. DDL is emitted as
|
|
203
|
-
* raw SQL via `strategy.generateDdl()`; reads and writes are composed
|
|
204
|
-
* from the strategy's fragment helpers.
|
|
205
|
-
*/
|
|
273
|
+
indexMaterializations,
|
|
274
|
+
kindRemovals,
|
|
275
|
+
reconciliationMarkers,
|
|
276
|
+
fulltext: fulltext2,
|
|
206
277
|
fulltextTableName: n.fulltext
|
|
207
278
|
};
|
|
208
279
|
}
|
|
209
280
|
var tables = createPostgresTables();
|
|
210
|
-
var {
|
|
281
|
+
var {
|
|
282
|
+
nodes,
|
|
283
|
+
edges,
|
|
284
|
+
uniques,
|
|
285
|
+
schemaVersions,
|
|
286
|
+
embeddings,
|
|
287
|
+
fulltext
|
|
288
|
+
} = tables;
|
|
211
289
|
var DEFAULT_TABLE_NAMES2 = {
|
|
212
290
|
nodes: "typegraph_nodes",
|
|
213
291
|
edges: "typegraph_edges",
|
|
214
292
|
uniques: "typegraph_node_uniques",
|
|
215
293
|
schemaVersions: "typegraph_schema_versions",
|
|
216
294
|
embeddings: "typegraph_node_embeddings",
|
|
217
|
-
fulltext: "typegraph_node_fulltext"
|
|
295
|
+
fulltext: "typegraph_node_fulltext",
|
|
296
|
+
indexMaterializations: "typegraph_index_materializations",
|
|
297
|
+
kindRemovals: "typegraph_kind_removals",
|
|
298
|
+
reconciliationMarkers: "typegraph_reconciliation_markers"
|
|
218
299
|
};
|
|
219
300
|
function createSqliteTables(names = {}, options = {}) {
|
|
220
301
|
const n = { ...DEFAULT_TABLE_NAMES2, ...names };
|
|
@@ -336,7 +417,13 @@ function createSqliteTables(names = {}, options = {}) {
|
|
|
336
417
|
},
|
|
337
418
|
(t) => [
|
|
338
419
|
primaryKey$1({ columns: [t.graphId, t.version] }),
|
|
339
|
-
index$1(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
|
|
420
|
+
index$1(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
|
|
421
|
+
// Partial unique index enforcing the "at most one active version
|
|
422
|
+
// per graph" invariant at the storage layer. Defense in depth
|
|
423
|
+
// against buggy backend implementations or out-of-band writes.
|
|
424
|
+
// Forces the deactivate-then-activate ordering used by
|
|
425
|
+
// `commitSchemaVersion` and `setActiveVersion`.
|
|
426
|
+
uniqueIndex$1(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(sql`${t.isActive} = 1`)
|
|
340
427
|
]
|
|
341
428
|
);
|
|
342
429
|
const embeddings3 = sqliteTable(
|
|
@@ -375,12 +462,55 @@ function createSqliteTables(names = {}, options = {}) {
|
|
|
375
462
|
)
|
|
376
463
|
]
|
|
377
464
|
);
|
|
465
|
+
const indexMaterializations = sqliteTable(
|
|
466
|
+
n.indexMaterializations,
|
|
467
|
+
{
|
|
468
|
+
indexName: text$1("index_name").notNull(),
|
|
469
|
+
graphId: text$1("graph_id").notNull(),
|
|
470
|
+
entity: text$1("entity").notNull(),
|
|
471
|
+
kind: text$1("kind").notNull(),
|
|
472
|
+
signature: text$1("signature").notNull(),
|
|
473
|
+
schemaVersion: integer$1("schema_version").notNull(),
|
|
474
|
+
materializedAt: text$1("materialized_at"),
|
|
475
|
+
lastAttemptedAt: text$1("last_attempted_at").notNull(),
|
|
476
|
+
lastError: text$1("last_error")
|
|
477
|
+
},
|
|
478
|
+
(t) => [primaryKey$1({ columns: [t.indexName] })]
|
|
479
|
+
);
|
|
480
|
+
const kindRemovals = sqliteTable(
|
|
481
|
+
n.kindRemovals,
|
|
482
|
+
{
|
|
483
|
+
graphId: text$1("graph_id").notNull(),
|
|
484
|
+
kindName: text$1("kind_name").notNull(),
|
|
485
|
+
entity: text$1("entity").notNull(),
|
|
486
|
+
schemaVersion: integer$1("schema_version").notNull(),
|
|
487
|
+
removedAt: text$1("removed_at"),
|
|
488
|
+
lastAttemptedAt: text$1("last_attempted_at").notNull(),
|
|
489
|
+
lastError: text$1("last_error")
|
|
490
|
+
},
|
|
491
|
+
(t) => [
|
|
492
|
+
primaryKey$1({
|
|
493
|
+
columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
|
|
494
|
+
})
|
|
495
|
+
]
|
|
496
|
+
);
|
|
497
|
+
const reconciliationMarkers = sqliteTable(
|
|
498
|
+
n.reconciliationMarkers,
|
|
499
|
+
{
|
|
500
|
+
graphId: text$1("graph_id").notNull(),
|
|
501
|
+
reconciledToVersion: integer$1("reconciled_to_version").notNull()
|
|
502
|
+
},
|
|
503
|
+
(t) => [primaryKey$1({ columns: [t.graphId] })]
|
|
504
|
+
);
|
|
378
505
|
return {
|
|
379
506
|
nodes: nodes3,
|
|
380
507
|
edges: edges3,
|
|
381
508
|
uniques: uniques3,
|
|
382
509
|
schemaVersions: schemaVersions3,
|
|
383
510
|
embeddings: embeddings3,
|
|
511
|
+
indexMaterializations,
|
|
512
|
+
kindRemovals,
|
|
513
|
+
reconciliationMarkers,
|
|
384
514
|
/**
|
|
385
515
|
* The fulltext storage is a FTS5 virtual table which Drizzle cannot
|
|
386
516
|
* represent. DDL is emitted as raw SQL and operations query it via
|
|
@@ -446,9 +576,9 @@ function renderIndexColumn(col) {
|
|
|
446
576
|
if (col && typeof col === "object" && "name" in col) {
|
|
447
577
|
return `"${col.name}"`;
|
|
448
578
|
}
|
|
449
|
-
const
|
|
450
|
-
if (
|
|
451
|
-
return
|
|
579
|
+
const sql14 = tryInlineSql(col);
|
|
580
|
+
if (sql14 !== void 0) {
|
|
581
|
+
return sql14;
|
|
452
582
|
}
|
|
453
583
|
return "unknown";
|
|
454
584
|
}
|
|
@@ -624,10 +754,12 @@ function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrate
|
|
|
624
754
|
const statements = [];
|
|
625
755
|
for (const table of Object.values(tables3)) {
|
|
626
756
|
if (!isPgTable(table)) continue;
|
|
757
|
+
if (table === tables3.fulltext) continue;
|
|
627
758
|
statements.push(generatePgCreateTableSQL(table));
|
|
628
759
|
}
|
|
629
760
|
for (const table of Object.values(tables3)) {
|
|
630
761
|
if (!isPgTable(table)) continue;
|
|
762
|
+
if (table === tables3.fulltext) continue;
|
|
631
763
|
statements.push(...generatePgCreateIndexSQL(table));
|
|
632
764
|
}
|
|
633
765
|
statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
|
|
@@ -770,6 +902,105 @@ function createSchemaVersionRowMapper(config) {
|
|
|
770
902
|
};
|
|
771
903
|
};
|
|
772
904
|
}
|
|
905
|
+
var SQLITE_INDEX_MAT_TIMESTAMPS = {
|
|
906
|
+
decode: (value) => typeof value === "string" ? value : void 0,
|
|
907
|
+
encode: (value) => value
|
|
908
|
+
};
|
|
909
|
+
var POSTGRES_INDEX_MAT_TIMESTAMPS = {
|
|
910
|
+
decode: formatPostgresTimestamp,
|
|
911
|
+
encode: (value) => new Date(value)
|
|
912
|
+
};
|
|
913
|
+
function mapMaterializationRow(row, decode) {
|
|
914
|
+
const lastAttemptedAt = decode(row.lastAttemptedAt);
|
|
915
|
+
if (lastAttemptedAt === void 0) {
|
|
916
|
+
throw new Error(
|
|
917
|
+
`materialization row missing required last_attempted_at: ${row.indexName}`
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
return {
|
|
921
|
+
indexName: row.indexName,
|
|
922
|
+
graphId: row.graphId,
|
|
923
|
+
entity: row.entity,
|
|
924
|
+
kind: row.kind,
|
|
925
|
+
signature: row.signature,
|
|
926
|
+
schemaVersion: row.schemaVersion,
|
|
927
|
+
materializedAt: decode(row.materializedAt),
|
|
928
|
+
lastAttemptedAt,
|
|
929
|
+
lastError: row.lastError ?? void 0
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
function buildMaterializationInsertValues(params, encode) {
|
|
933
|
+
return {
|
|
934
|
+
indexName: params.indexName,
|
|
935
|
+
graphId: params.graphId,
|
|
936
|
+
entity: params.entity,
|
|
937
|
+
kind: params.kind,
|
|
938
|
+
signature: params.signature,
|
|
939
|
+
schemaVersion: params.schemaVersion,
|
|
940
|
+
materializedAt: params.materializedAt === void 0 ? void 0 : encode(params.materializedAt),
|
|
941
|
+
lastAttemptedAt: encode(params.attemptedAt),
|
|
942
|
+
lastError: params.error
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function buildMaterializationOnConflictSet(materializedAtColumn, paramsMaterializedAt) {
|
|
946
|
+
const materializedAtSet = paramsMaterializedAt === void 0 ? sql`COALESCE(excluded.${sql.identifier("materialized_at")}, ${materializedAtColumn})` : sql`excluded.${sql.identifier("materialized_at")}`;
|
|
947
|
+
return {
|
|
948
|
+
graphId: sql`excluded.${sql.identifier("graph_id")}`,
|
|
949
|
+
entity: sql`excluded.${sql.identifier("entity")}`,
|
|
950
|
+
kind: sql`excluded.${sql.identifier("kind")}`,
|
|
951
|
+
signature: sql`excluded.${sql.identifier("signature")}`,
|
|
952
|
+
schemaVersion: sql`excluded.${sql.identifier("schema_version")}`,
|
|
953
|
+
materializedAt: materializedAtSet,
|
|
954
|
+
lastAttemptedAt: sql`excluded.${sql.identifier("last_attempted_at")}`,
|
|
955
|
+
lastError: sql`excluded.${sql.identifier("last_error")}`
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
var SQLITE_KIND_REMOVAL_TIMESTAMPS = {
|
|
959
|
+
decode: (value) => typeof value === "string" ? value : void 0,
|
|
960
|
+
encode: (value) => value
|
|
961
|
+
};
|
|
962
|
+
var POSTGRES_KIND_REMOVAL_TIMESTAMPS = {
|
|
963
|
+
decode: formatPostgresTimestamp,
|
|
964
|
+
encode: (value) => new Date(value)
|
|
965
|
+
};
|
|
966
|
+
function mapKindRemovalRow(row, decode) {
|
|
967
|
+
const lastAttemptedAt = decode(row.lastAttemptedAt);
|
|
968
|
+
if (lastAttemptedAt === void 0) {
|
|
969
|
+
throw new Error(
|
|
970
|
+
`kind removal row missing required last_attempted_at: ${row.kindName}`
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
return {
|
|
974
|
+
graphId: row.graphId,
|
|
975
|
+
kindName: row.kindName,
|
|
976
|
+
entity: row.entity,
|
|
977
|
+
schemaVersion: row.schemaVersion,
|
|
978
|
+
removedAt: decode(row.removedAt),
|
|
979
|
+
lastAttemptedAt,
|
|
980
|
+
lastError: row.lastError ?? void 0
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
function buildKindRemovalInsertValues(params, encode) {
|
|
984
|
+
return {
|
|
985
|
+
graphId: params.graphId,
|
|
986
|
+
kindName: params.kindName,
|
|
987
|
+
entity: params.entity,
|
|
988
|
+
schemaVersion: params.schemaVersion,
|
|
989
|
+
removedAt: params.removedAt === void 0 ? void 0 : encode(params.removedAt),
|
|
990
|
+
lastAttemptedAt: encode(params.attemptedAt),
|
|
991
|
+
lastError: params.error
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
|
|
995
|
+
const removedAtSet = paramsRemovedAt === void 0 ? sql`COALESCE(excluded.${sql.identifier("removed_at")}, ${removedAtColumn})` : sql`excluded.${sql.identifier("removed_at")}`;
|
|
996
|
+
return {
|
|
997
|
+
entity: sql`excluded.${sql.identifier("entity")}`,
|
|
998
|
+
schemaVersion: sql`excluded.${sql.identifier("schema_version")}`,
|
|
999
|
+
removedAt: removedAtSet,
|
|
1000
|
+
lastAttemptedAt: sql`excluded.${sql.identifier("last_attempted_at")}`,
|
|
1001
|
+
lastError: sql`excluded.${sql.identifier("last_error")}`
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
773
1004
|
|
|
774
1005
|
// src/backend/drizzle/operation-backend-core.ts
|
|
775
1006
|
function chunkArray(values, size) {
|
|
@@ -782,9 +1013,25 @@ function chunkArray(values, size) {
|
|
|
782
1013
|
}
|
|
783
1014
|
return chunks;
|
|
784
1015
|
}
|
|
1016
|
+
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
1017
|
+
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
1018
|
+
if (actualActiveVersion !== expectedVersion) {
|
|
1019
|
+
throw new StaleVersionError({
|
|
1020
|
+
graphId,
|
|
1021
|
+
expected: expectedVersion,
|
|
1022
|
+
actual: actualActiveVersion
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
785
1026
|
function createCommonOperationBackend(options) {
|
|
786
1027
|
const { batchConfig, execution, operationStrategy, rowMappers } = options;
|
|
787
1028
|
const nowIso2 = options.nowIso ?? nowIso;
|
|
1029
|
+
async function readActiveVersion(graphId) {
|
|
1030
|
+
const row = await execution.execGet(
|
|
1031
|
+
operationStrategy.buildGetActiveSchema(graphId)
|
|
1032
|
+
);
|
|
1033
|
+
return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
|
|
1034
|
+
}
|
|
788
1035
|
return {
|
|
789
1036
|
async insertNode(params) {
|
|
790
1037
|
const timestamp2 = nowIso2();
|
|
@@ -1018,20 +1265,104 @@ function createCommonOperationBackend(options) {
|
|
|
1018
1265
|
const row = await execution.execGet(query);
|
|
1019
1266
|
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
1020
1267
|
},
|
|
1021
|
-
async insertSchema(params) {
|
|
1022
|
-
const timestamp2 = nowIso2();
|
|
1023
|
-
const query = operationStrategy.buildInsertSchema(params, timestamp2);
|
|
1024
|
-
const row = await execution.execGet(query);
|
|
1025
|
-
if (!row) throw new DatabaseOperationError("Insert schema failed: no row returned", { operation: "insert", entity: "schema" });
|
|
1026
|
-
return rowMappers.toSchemaVersionRow(row);
|
|
1027
|
-
},
|
|
1028
1268
|
async getSchemaVersion(graphId, version) {
|
|
1029
1269
|
const query = operationStrategy.buildGetSchemaVersion(graphId, version);
|
|
1030
1270
|
const row = await execution.execGet(query);
|
|
1031
1271
|
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
1032
1272
|
},
|
|
1033
|
-
async
|
|
1034
|
-
const
|
|
1273
|
+
async commitSchemaVersion(params) {
|
|
1274
|
+
const existingRaw = await execution.execGet(
|
|
1275
|
+
operationStrategy.buildGetSchemaVersion(
|
|
1276
|
+
params.graphId,
|
|
1277
|
+
params.version
|
|
1278
|
+
)
|
|
1279
|
+
);
|
|
1280
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
1281
|
+
if (existingRaw !== void 0) {
|
|
1282
|
+
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
1283
|
+
if (existing.schema_hash !== params.schemaHash) {
|
|
1284
|
+
throw new SchemaContentConflictError({
|
|
1285
|
+
graphId: params.graphId,
|
|
1286
|
+
version: params.version,
|
|
1287
|
+
existingHash: existing.schema_hash,
|
|
1288
|
+
incomingHash: params.schemaHash
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
if (existing.is_active) {
|
|
1292
|
+
return existing;
|
|
1293
|
+
}
|
|
1294
|
+
verifyExpectedActiveVersion(
|
|
1295
|
+
params.graphId,
|
|
1296
|
+
params.expected,
|
|
1297
|
+
actualActiveVersion
|
|
1298
|
+
);
|
|
1299
|
+
const reactivate = operationStrategy.buildSetActiveSchema(
|
|
1300
|
+
params.graphId,
|
|
1301
|
+
params.version
|
|
1302
|
+
);
|
|
1303
|
+
await execution.execRun(reactivate.deactivateAll);
|
|
1304
|
+
await execution.execRun(reactivate.activateVersion);
|
|
1305
|
+
return { ...existing, is_active: true };
|
|
1306
|
+
}
|
|
1307
|
+
verifyExpectedActiveVersion(
|
|
1308
|
+
params.graphId,
|
|
1309
|
+
params.expected,
|
|
1310
|
+
actualActiveVersion
|
|
1311
|
+
);
|
|
1312
|
+
if (params.expected.kind === "active") {
|
|
1313
|
+
const flip = operationStrategy.buildSetActiveSchema(
|
|
1314
|
+
params.graphId,
|
|
1315
|
+
params.version
|
|
1316
|
+
);
|
|
1317
|
+
await execution.execRun(flip.deactivateAll);
|
|
1318
|
+
}
|
|
1319
|
+
const timestamp2 = nowIso2();
|
|
1320
|
+
const insertQuery = operationStrategy.buildInsertSchema(
|
|
1321
|
+
{
|
|
1322
|
+
graphId: params.graphId,
|
|
1323
|
+
version: params.version,
|
|
1324
|
+
schemaHash: params.schemaHash,
|
|
1325
|
+
schemaDoc: params.schemaDoc,
|
|
1326
|
+
isActive: true
|
|
1327
|
+
},
|
|
1328
|
+
timestamp2
|
|
1329
|
+
);
|
|
1330
|
+
const insertedRaw = await execution.execGet(insertQuery);
|
|
1331
|
+
if (!insertedRaw) {
|
|
1332
|
+
throw new DatabaseOperationError(
|
|
1333
|
+
"Insert schema failed: no row returned",
|
|
1334
|
+
{ operation: "insert", entity: "schema" }
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
return rowMappers.toSchemaVersionRow(insertedRaw);
|
|
1338
|
+
},
|
|
1339
|
+
async setActiveVersion(params) {
|
|
1340
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
1341
|
+
verifyExpectedActiveVersion(
|
|
1342
|
+
params.graphId,
|
|
1343
|
+
params.expected,
|
|
1344
|
+
actualActiveVersion
|
|
1345
|
+
);
|
|
1346
|
+
const targetRaw = await execution.execGet(
|
|
1347
|
+
operationStrategy.buildGetSchemaVersion(
|
|
1348
|
+
params.graphId,
|
|
1349
|
+
params.version
|
|
1350
|
+
)
|
|
1351
|
+
);
|
|
1352
|
+
if (!targetRaw) {
|
|
1353
|
+
throw new MigrationError(
|
|
1354
|
+
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
1355
|
+
{
|
|
1356
|
+
graphId: params.graphId,
|
|
1357
|
+
fromVersion: actualActiveVersion,
|
|
1358
|
+
toVersion: params.version
|
|
1359
|
+
}
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
const queries = operationStrategy.buildSetActiveSchema(
|
|
1363
|
+
params.graphId,
|
|
1364
|
+
params.version
|
|
1365
|
+
);
|
|
1035
1366
|
await execution.execRun(queries.deactivateAll);
|
|
1036
1367
|
await execution.execRun(queries.activateVersion);
|
|
1037
1368
|
},
|
|
@@ -1044,13 +1375,16 @@ function createCommonOperationBackend(options) {
|
|
|
1044
1375
|
};
|
|
1045
1376
|
}
|
|
1046
1377
|
function buildClearGraph(tables3, graphId) {
|
|
1047
|
-
const
|
|
1378
|
+
const fulltext2 = quotedTableName(tables3.fulltextTableName);
|
|
1048
1379
|
return [
|
|
1049
|
-
sql`DELETE FROM ${
|
|
1380
|
+
sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}`,
|
|
1050
1381
|
sql`DELETE FROM ${tables3.embeddings} WHERE ${tables3.embeddings.graphId} = ${graphId}`,
|
|
1051
1382
|
sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
|
|
1052
1383
|
sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
|
|
1053
1384
|
sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`,
|
|
1385
|
+
sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`,
|
|
1386
|
+
sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`,
|
|
1387
|
+
sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`,
|
|
1054
1388
|
sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
|
|
1055
1389
|
];
|
|
1056
1390
|
}
|
|
@@ -2229,9 +2563,10 @@ async function createPostgresVectorIndex(db, options) {
|
|
|
2229
2563
|
const safeNodeKind = escapeSqlString(nodeKind);
|
|
2230
2564
|
const safeFieldPath = escapeSqlString(fieldPath);
|
|
2231
2565
|
let indexSql;
|
|
2566
|
+
const concurrentClause = options.concurrent === true ? "CONCURRENTLY " : "";
|
|
2232
2567
|
if (indexType === "hnsw") {
|
|
2233
2568
|
indexSql = sql.raw(`
|
|
2234
|
-
CREATE INDEX IF NOT EXISTS ${indexName}
|
|
2569
|
+
CREATE INDEX ${concurrentClause}IF NOT EXISTS ${indexName}
|
|
2235
2570
|
ON ${quotedEmbeddingsTableName}
|
|
2236
2571
|
USING hnsw ((embedding::vector(${dimensions})) ${operatorClass})
|
|
2237
2572
|
WITH (m = ${hnswM}, ef_construction = ${hnswEfConstruction})
|
|
@@ -2241,7 +2576,7 @@ async function createPostgresVectorIndex(db, options) {
|
|
|
2241
2576
|
`);
|
|
2242
2577
|
} else if (indexType === "ivfflat") {
|
|
2243
2578
|
indexSql = sql.raw(`
|
|
2244
|
-
CREATE INDEX IF NOT EXISTS ${indexName}
|
|
2579
|
+
CREATE INDEX ${concurrentClause}IF NOT EXISTS ${indexName}
|
|
2245
2580
|
ON ${quotedEmbeddingsTableName}
|
|
2246
2581
|
USING ivfflat ((embedding::vector(${dimensions})) ${operatorClass})
|
|
2247
2582
|
WITH (lists = ${ivfflatLists})
|
|
@@ -2338,6 +2673,6 @@ function compileQueryWithDialect(db, query, backendName) {
|
|
|
2338
2673
|
return compiler.sqlToQuery(query);
|
|
2339
2674
|
}
|
|
2340
2675
|
|
|
2341
|
-
export { POSTGRES_ROW_MAPPER_CONFIG, SQLITE_ROW_MAPPER_CONFIG, compileQueryWithDialect, createCommonOperationBackend, createEdgeRowMapper, createNodeRowMapper, createPostgresOperationStrategy, createPostgresTables, createPostgresVectorIndex, createSchemaVersionRowMapper, createSqliteOperationStrategy, createSqliteTables, createSqliteVectorIndex, createUniqueRowMapper, dropPostgresVectorIndex, dropSqliteVectorIndex, edges, edges2, embeddings, embeddings2, formatPostgresTimestamp, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, getOrCreateLru, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
|
|
2342
|
-
//# sourceMappingURL=chunk-
|
|
2343
|
-
//# sourceMappingURL=chunk-
|
|
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
|