@nicia-ai/typegraph 0.28.0 → 0.29.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.
- package/dist/backend/postgres/index.cjs +23 -761
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +24 -5
- package/dist/backend/postgres/index.d.ts +24 -5
- package/dist/backend/postgres/index.js +10 -752
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/postgres/pglite.cjs +52 -0
- package/dist/backend/postgres/pglite.cjs.map +1 -0
- package/dist/backend/postgres/pglite.d.cts +116 -0
- package/dist/backend/postgres/pglite.d.ts +116 -0
- package/dist/backend/postgres/pglite.js +50 -0
- package/dist/backend/postgres/pglite.js.map +1 -0
- package/dist/backend/sqlite/index.cjs +22 -26
- package/dist/backend/sqlite/index.d.cts +17 -15
- package/dist/backend/sqlite/index.d.ts +17 -15
- package/dist/backend/sqlite/index.js +9 -9
- package/dist/backend/sqlite/libsql.cjs +17 -13
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +3 -3
- package/dist/backend/sqlite/libsql.d.ts +3 -3
- package/dist/backend/sqlite/libsql.js +16 -12
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +17 -16
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +15 -14
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-DFHLG75V.js → chunk-3DTLDGIM.js} +386 -1093
- package/dist/chunk-3DTLDGIM.js.map +1 -0
- package/dist/{chunk-WVQXAFP3.js → chunk-454I6GDF.js} +46 -5
- package/dist/chunk-454I6GDF.js.map +1 -0
- package/dist/chunk-4K6IHUW6.cjs +183 -0
- package/dist/chunk-4K6IHUW6.cjs.map +1 -0
- package/dist/{chunk-ZTREJOGB.js → chunk-7KLVFWXR.js} +113 -68
- package/dist/chunk-7KLVFWXR.js.map +1 -0
- package/dist/{chunk-UKG7XHZ3.js → chunk-A4H6QMV4.js} +110 -102
- package/dist/chunk-A4H6QMV4.js.map +1 -0
- package/dist/{chunk-E5ROA3MN.js → chunk-BMDF2S7S.js} +3 -3
- package/dist/{chunk-E5ROA3MN.js.map → chunk-BMDF2S7S.js.map} +1 -1
- package/dist/{chunk-PN37HVAV.cjs → chunk-C2RWFIYP.cjs} +121 -67
- package/dist/chunk-C2RWFIYP.cjs.map +1 -0
- package/dist/chunk-CUZGBWFT.js +206 -0
- package/dist/chunk-CUZGBWFT.js.map +1 -0
- package/dist/chunk-F2Q76CQ4.cjs +266 -0
- package/dist/chunk-F2Q76CQ4.cjs.map +1 -0
- package/dist/{chunk-YEDQLNVE.cjs → chunk-G6P3OVDY.cjs} +14 -2
- package/dist/chunk-G6P3OVDY.cjs.map +1 -0
- package/dist/chunk-GPUNAJFH.js +181 -0
- package/dist/chunk-GPUNAJFH.js.map +1 -0
- package/dist/chunk-HKN622O4.js +254 -0
- package/dist/chunk-HKN622O4.js.map +1 -0
- package/dist/{chunk-PYJOBZR3.cjs → chunk-HM6XMR3E.cjs} +52 -52
- package/dist/chunk-HM6XMR3E.cjs.map +1 -0
- package/dist/chunk-IE2TPFBT.js +305 -0
- package/dist/chunk-IE2TPFBT.js.map +1 -0
- package/dist/chunk-KGAJ5HFO.cjs +319 -0
- package/dist/chunk-KGAJ5HFO.cjs.map +1 -0
- package/dist/chunk-M6OC455F.js +65 -0
- package/dist/chunk-M6OC455F.js.map +1 -0
- package/dist/{chunk-U5ROKVRF.js → chunk-MB363HT5.js} +14 -3
- package/dist/chunk-MB363HT5.js.map +1 -0
- package/dist/{chunk-X53YKGHR.js → chunk-MRMD7S7E.js} +9 -9
- package/dist/{chunk-X53YKGHR.js.map → chunk-MRMD7S7E.js.map} +1 -1
- package/dist/{chunk-OOS2RKRH.js → chunk-N3VVQDMA.js} +3 -3
- package/dist/{chunk-OOS2RKRH.js.map → chunk-N3VVQDMA.js.map} +1 -1
- package/dist/{chunk-EJCDOA37.js → chunk-OGUH56BB.js} +4 -4
- package/dist/{chunk-EJCDOA37.js.map → chunk-OGUH56BB.js.map} +1 -1
- package/dist/chunk-Q3ZZLU3O.cjs +12 -0
- package/dist/{chunk-4FJVSF3K.cjs.map → chunk-Q3ZZLU3O.cjs.map} +1 -1
- package/dist/chunk-Q5ASTPM4.cjs +208 -0
- package/dist/chunk-Q5ASTPM4.cjs.map +1 -0
- package/dist/{chunk-WFUN6DCM.cjs → chunk-R2LA6MKR.cjs} +11 -11
- package/dist/chunk-R2LA6MKR.cjs.map +1 -0
- package/dist/chunk-RP7YITHX.cjs +70 -0
- package/dist/chunk-RP7YITHX.cjs.map +1 -0
- package/dist/{chunk-33K3ZYFG.cjs → chunk-RU5BBUU2.cjs} +132 -124
- package/dist/chunk-RU5BBUU2.cjs.map +1 -0
- package/dist/{chunk-TSGBRPNE.js → chunk-SFNUHFON.js} +45 -45
- package/dist/chunk-SFNUHFON.js.map +1 -0
- package/dist/chunk-UP4QAJND.cjs +740 -0
- package/dist/chunk-UP4QAJND.cjs.map +1 -0
- package/dist/{chunk-CTHNVU6K.cjs → chunk-UPBXUOW7.cjs} +8 -8
- package/dist/{chunk-CTHNVU6K.cjs.map → chunk-UPBXUOW7.cjs.map} +1 -1
- package/dist/{chunk-EK6RJ373.cjs → chunk-VGU26WIU.cjs} +5 -5
- package/dist/{chunk-EK6RJ373.cjs.map → chunk-VGU26WIU.cjs.map} +1 -1
- package/dist/{chunk-ZGEMI7MJ.cjs → chunk-XTQHSOIC.cjs} +101 -101
- package/dist/{chunk-ZGEMI7MJ.cjs.map → chunk-XTQHSOIC.cjs.map} +1 -1
- package/dist/chunk-Y52UNT66.js +738 -0
- package/dist/chunk-Y52UNT66.js.map +1 -0
- package/dist/{chunk-OYLF3IC7.js → chunk-Z36W5WUM.js} +4 -4
- package/dist/chunk-Z36W5WUM.js.map +1 -0
- package/dist/{chunk-X3244EKP.cjs → chunk-ZFWNO3GE.cjs} +48 -4
- package/dist/chunk-ZFWNO3GE.cjs.map +1 -0
- package/dist/{chunk-2E4VTD2E.cjs → chunk-ZYQEXGYC.cjs} +423 -1139
- package/dist/chunk-ZYQEXGYC.cjs.map +1 -0
- package/dist/ddl-BwH00BB6.d.ts +38 -0
- package/dist/ddl-D3o-RmsV.d.cts +38 -0
- package/dist/{extension-types-B78CZfA5.d.ts → extension-types-CwHV-Uk4.d.cts} +4 -4
- package/dist/{extension-types-B78CZfA5.d.cts → extension-types-CwHV-Uk4.d.ts} +4 -4
- package/dist/graph-extension/index.cjs +18 -18
- package/dist/graph-extension/index.d.cts +4 -4
- package/dist/graph-extension/index.d.ts +4 -4
- package/dist/graph-extension/index.js +3 -3
- package/dist/{index-CWdBFWbI.d.ts → index-CapHwi1a.d.ts} +22 -3
- package/dist/{index-Bilw0pYm.d.cts → index-jPPexxM5.d.cts} +22 -3
- package/dist/index.cjs +1211 -945
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -12
- package/dist/index.d.ts +142 -12
- package/dist/index.js +778 -544
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +18 -18
- package/dist/indexes/index.d.cts +9 -9
- package/dist/indexes/index.d.ts +9 -9
- package/dist/indexes/index.js +4 -4
- package/dist/interchange/index.cjs +8 -14
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +5 -16
- package/dist/interchange/index.d.ts +5 -16
- package/dist/interchange/index.js +3 -9
- package/dist/interchange/index.js.map +1 -1
- package/dist/{manager-ehLTTNq0.d.ts → manager-BUugwCYz.d.ts} +2 -2
- package/dist/{manager-c1MGaVVR.d.cts → manager-DpIpn1HQ.d.cts} +2 -2
- package/dist/{materialize-indexes-DFavFQah.d.ts → materialize-indexes-lkawaDor.d.ts} +1 -1
- package/dist/{materialize-indexes-BQfaAZKA.d.cts → materialize-indexes-oanE3RU0.d.cts} +1 -1
- package/dist/{ddl-0Ooc2dpL.d.ts → postgres-CQL9UIn2.d.cts} +2 -471
- package/dist/{ddl-Dza3kDrI.d.cts → postgres-CcRLaxz0.d.ts} +2 -471
- package/dist/profiler/index.cjs +4 -4
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/profiler/index.js +2 -2
- package/dist/schema/index.cjs +32 -32
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +9 -9
- package/dist/{sqlite-BxZUPbyD.d.ts → sqlite-CZDFUfHS.d.ts} +2 -468
- package/dist/{sqlite-mvpXjEeB.d.cts → sqlite-Rj3xu4It.d.cts} +2 -468
- package/dist/{store-Ufc1Eoey.d.ts → store-B43FpOVX.d.cts} +84 -5
- package/dist/{store-D7YEMg2v.d.cts → store-De0Y33wP.d.ts} +84 -5
- package/dist/{types-B-sJJ4GQ.d.ts → types-B5GSeE3t.d.ts} +2 -2
- package/dist/{types-CmUA9sal.d.cts → types-Bwlp_yvu.d.cts} +2 -2
- package/dist/{types-CMQymcwk.d.cts → types-CmAT-Z47.d.ts} +250 -46
- package/dist/{types-CQ7xXJMP.d.ts → types-DXCSyxac.d.cts} +250 -46
- package/dist/{where-5zf15aFZ.d.cts → where-2dsyYt3d.d.cts} +2 -2
- package/dist/{where-CtrLu1Zf.d.ts → where-CP4qGIHd.d.ts} +2 -2
- package/package.json +20 -5
- package/dist/chunk-2E4VTD2E.cjs.map +0 -1
- package/dist/chunk-33K3ZYFG.cjs.map +0 -1
- package/dist/chunk-3EUKJEQ3.js +0 -77
- package/dist/chunk-3EUKJEQ3.js.map +0 -1
- package/dist/chunk-4FJVSF3K.cjs +0 -12
- package/dist/chunk-5H3BAMTB.js +0 -32
- package/dist/chunk-5H3BAMTB.js.map +0 -1
- package/dist/chunk-DFHLG75V.js.map +0 -1
- package/dist/chunk-HTGDWIDE.cjs +0 -89
- package/dist/chunk-HTGDWIDE.cjs.map +0 -1
- package/dist/chunk-IUIWCFG3.cjs +0 -36
- package/dist/chunk-IUIWCFG3.cjs.map +0 -1
- package/dist/chunk-LYRUNG6E.cjs +0 -52
- package/dist/chunk-LYRUNG6E.cjs.map +0 -1
- package/dist/chunk-OYLF3IC7.js.map +0 -1
- package/dist/chunk-PCHTTG42.js +0 -47
- package/dist/chunk-PCHTTG42.js.map +0 -1
- package/dist/chunk-PN37HVAV.cjs.map +0 -1
- package/dist/chunk-PYJOBZR3.cjs.map +0 -1
- package/dist/chunk-TSGBRPNE.js.map +0 -1
- package/dist/chunk-U5ROKVRF.js.map +0 -1
- package/dist/chunk-UKG7XHZ3.js.map +0 -1
- package/dist/chunk-WFUN6DCM.cjs.map +0 -1
- package/dist/chunk-WVQXAFP3.js.map +0 -1
- package/dist/chunk-X3244EKP.cjs.map +0 -1
- package/dist/chunk-YEDQLNVE.cjs.map +0 -1
- package/dist/chunk-ZTREJOGB.js.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
3
|
+
var chunkF2Q76CQ4_cjs = require('./chunk-F2Q76CQ4.cjs');
|
|
4
|
+
var chunkRP7YITHX_cjs = require('./chunk-RP7YITHX.cjs');
|
|
5
|
+
var chunkC2RWFIYP_cjs = require('./chunk-C2RWFIYP.cjs');
|
|
6
|
+
var chunkUPBXUOW7_cjs = require('./chunk-UPBXUOW7.cjs');
|
|
7
|
+
var chunkG6P3OVDY_cjs = require('./chunk-G6P3OVDY.cjs');
|
|
7
8
|
var drizzleOrm = require('drizzle-orm');
|
|
8
9
|
var pgCore = require('drizzle-orm/pg-core');
|
|
9
10
|
var sqliteCore = require('drizzle-orm/sqlite-core');
|
|
@@ -14,24 +15,6 @@ var regconfig = pgCore.customType({
|
|
|
14
15
|
var tsvector = pgCore.customType({
|
|
15
16
|
dataType: () => "tsvector"
|
|
16
17
|
});
|
|
17
|
-
var vector = pgCore.customType({
|
|
18
|
-
dataType(config) {
|
|
19
|
-
return config?.dimensions ? `vector(${config.dimensions})` : "vector";
|
|
20
|
-
},
|
|
21
|
-
toDriver(value) {
|
|
22
|
-
return `[${value.join(",")}]`;
|
|
23
|
-
},
|
|
24
|
-
fromDriver(value) {
|
|
25
|
-
if (Array.isArray(value)) {
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
const content = value.slice(1, -1);
|
|
29
|
-
if (content === "") {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return content.split(",").map((s) => Number.parseFloat(s.trim()));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
18
|
|
|
36
19
|
// src/backend/drizzle/schema/postgres.ts
|
|
37
20
|
var DEFAULT_TABLE_NAMES = {
|
|
@@ -39,7 +22,6 @@ var DEFAULT_TABLE_NAMES = {
|
|
|
39
22
|
edges: "typegraph_edges",
|
|
40
23
|
uniques: "typegraph_node_uniques",
|
|
41
24
|
schemaVersions: "typegraph_schema_versions",
|
|
42
|
-
embeddings: "typegraph_node_embeddings",
|
|
43
25
|
fulltext: "typegraph_node_fulltext",
|
|
44
26
|
indexMaterializations: "typegraph_index_materializations",
|
|
45
27
|
contributionMaterializations: "typegraph_contribution_materializations",
|
|
@@ -49,7 +31,7 @@ var DEFAULT_TABLE_NAMES = {
|
|
|
49
31
|
function createPostgresTables(names = {}, options = {}) {
|
|
50
32
|
const n = { ...DEFAULT_TABLE_NAMES, ...names };
|
|
51
33
|
const indexes = options.indexes ?? [];
|
|
52
|
-
const
|
|
34
|
+
const nodes2 = pgCore.pgTable(
|
|
53
35
|
n.nodes,
|
|
54
36
|
{
|
|
55
37
|
graphId: pgCore.text("graph_id").notNull(),
|
|
@@ -74,10 +56,10 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
74
56
|
),
|
|
75
57
|
pgCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
|
|
76
58
|
pgCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
|
|
77
|
-
...
|
|
59
|
+
...chunkC2RWFIYP_cjs.buildPostgresNodeIndexBuilders(t, indexes)
|
|
78
60
|
]
|
|
79
61
|
);
|
|
80
|
-
const
|
|
62
|
+
const edges2 = pgCore.pgTable(
|
|
81
63
|
n.edges,
|
|
82
64
|
{
|
|
83
65
|
graphId: pgCore.text("graph_id").notNull(),
|
|
@@ -133,10 +115,10 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
133
115
|
t.fromId,
|
|
134
116
|
t.validTo
|
|
135
117
|
),
|
|
136
|
-
...
|
|
118
|
+
...chunkC2RWFIYP_cjs.buildPostgresEdgeIndexBuilders(t, indexes)
|
|
137
119
|
]
|
|
138
120
|
);
|
|
139
|
-
const
|
|
121
|
+
const uniques2 = pgCore.pgTable(
|
|
140
122
|
n.uniques,
|
|
141
123
|
{
|
|
142
124
|
graphId: pgCore.text("graph_id").notNull(),
|
|
@@ -154,7 +136,7 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
154
136
|
pgCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
|
|
155
137
|
]
|
|
156
138
|
);
|
|
157
|
-
const
|
|
139
|
+
const schemaVersions2 = pgCore.pgTable(
|
|
158
140
|
n.schemaVersions,
|
|
159
141
|
{
|
|
160
142
|
graphId: pgCore.text("graph_id").notNull(),
|
|
@@ -175,38 +157,6 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
175
157
|
pgCore.uniqueIndex(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(drizzleOrm.sql`${t.isActive} = TRUE`)
|
|
176
158
|
]
|
|
177
159
|
);
|
|
178
|
-
const embeddings3 = pgCore.pgTable(
|
|
179
|
-
n.embeddings,
|
|
180
|
-
{
|
|
181
|
-
graphId: pgCore.text("graph_id").notNull(),
|
|
182
|
-
nodeKind: pgCore.text("node_kind").notNull(),
|
|
183
|
-
nodeId: pgCore.text("node_id").notNull(),
|
|
184
|
-
fieldPath: pgCore.text("field_path").notNull(),
|
|
185
|
-
/** Embedding vector stored as native pgvector type */
|
|
186
|
-
embedding: vector("embedding").notNull(),
|
|
187
|
-
/** Number of dimensions (for validation) */
|
|
188
|
-
dimensions: pgCore.integer("dimensions").notNull(),
|
|
189
|
-
createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
|
|
190
|
-
updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull()
|
|
191
|
-
},
|
|
192
|
-
(t) => [
|
|
193
|
-
pgCore.primaryKey({
|
|
194
|
-
columns: [t.graphId, t.nodeKind, t.nodeId, t.fieldPath]
|
|
195
|
-
}),
|
|
196
|
-
// Index for looking up embeddings by node
|
|
197
|
-
pgCore.index(`${n.embeddings}_node_idx`).on(
|
|
198
|
-
t.graphId,
|
|
199
|
-
t.nodeKind,
|
|
200
|
-
t.nodeId
|
|
201
|
-
),
|
|
202
|
-
// Index for filtering by kind and field (used in vector search)
|
|
203
|
-
pgCore.index(`${n.embeddings}_kind_field_idx`).on(
|
|
204
|
-
t.graphId,
|
|
205
|
-
t.nodeKind,
|
|
206
|
-
t.fieldPath
|
|
207
|
-
)
|
|
208
|
-
]
|
|
209
|
-
);
|
|
210
160
|
const indexMaterializations = pgCore.pgTable(
|
|
211
161
|
n.indexMaterializations,
|
|
212
162
|
{
|
|
@@ -289,11 +239,10 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
289
239
|
]
|
|
290
240
|
);
|
|
291
241
|
return {
|
|
292
|
-
nodes:
|
|
293
|
-
edges:
|
|
294
|
-
uniques:
|
|
295
|
-
schemaVersions:
|
|
296
|
-
embeddings: embeddings3,
|
|
242
|
+
nodes: nodes2,
|
|
243
|
+
edges: edges2,
|
|
244
|
+
uniques: uniques2,
|
|
245
|
+
schemaVersions: schemaVersions2,
|
|
297
246
|
indexMaterializations,
|
|
298
247
|
contributionMaterializations,
|
|
299
248
|
kindRemovals,
|
|
@@ -302,270 +251,8 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
302
251
|
fulltextTableName: n.fulltext
|
|
303
252
|
};
|
|
304
253
|
}
|
|
305
|
-
var
|
|
306
|
-
var {
|
|
307
|
-
nodes,
|
|
308
|
-
edges,
|
|
309
|
-
uniques,
|
|
310
|
-
schemaVersions,
|
|
311
|
-
embeddings,
|
|
312
|
-
fulltext
|
|
313
|
-
} = tables;
|
|
314
|
-
var DEFAULT_TABLE_NAMES2 = {
|
|
315
|
-
nodes: "typegraph_nodes",
|
|
316
|
-
edges: "typegraph_edges",
|
|
317
|
-
uniques: "typegraph_node_uniques",
|
|
318
|
-
schemaVersions: "typegraph_schema_versions",
|
|
319
|
-
embeddings: "typegraph_node_embeddings",
|
|
320
|
-
fulltext: "typegraph_node_fulltext",
|
|
321
|
-
indexMaterializations: "typegraph_index_materializations",
|
|
322
|
-
contributionMaterializations: "typegraph_contribution_materializations",
|
|
323
|
-
kindRemovals: "typegraph_kind_removals",
|
|
324
|
-
reconciliationMarkers: "typegraph_reconciliation_markers"
|
|
325
|
-
};
|
|
326
|
-
function createSqliteTables(names = {}, options = {}) {
|
|
327
|
-
const n = { ...DEFAULT_TABLE_NAMES2, ...names };
|
|
328
|
-
const indexes = options.indexes ?? [];
|
|
329
|
-
const nodes3 = sqliteCore.sqliteTable(
|
|
330
|
-
n.nodes,
|
|
331
|
-
{
|
|
332
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
333
|
-
kind: sqliteCore.text("kind").notNull(),
|
|
334
|
-
id: sqliteCore.text("id").notNull(),
|
|
335
|
-
props: sqliteCore.text("props").notNull(),
|
|
336
|
-
version: sqliteCore.integer("version").notNull().default(1),
|
|
337
|
-
validFrom: sqliteCore.text("valid_from"),
|
|
338
|
-
validTo: sqliteCore.text("valid_to"),
|
|
339
|
-
createdAt: sqliteCore.text("created_at").notNull(),
|
|
340
|
-
updatedAt: sqliteCore.text("updated_at").notNull(),
|
|
341
|
-
deletedAt: sqliteCore.text("deleted_at")
|
|
342
|
-
},
|
|
343
|
-
(t) => [
|
|
344
|
-
sqliteCore.primaryKey({ columns: [t.graphId, t.kind, t.id] }),
|
|
345
|
-
sqliteCore.index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
|
|
346
|
-
sqliteCore.index(`${n.nodes}_kind_created_idx`).on(
|
|
347
|
-
t.graphId,
|
|
348
|
-
t.kind,
|
|
349
|
-
t.deletedAt,
|
|
350
|
-
t.createdAt
|
|
351
|
-
),
|
|
352
|
-
sqliteCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
|
|
353
|
-
sqliteCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
|
|
354
|
-
...chunkPN37HVAV_cjs.buildSqliteNodeIndexBuilders(t, indexes)
|
|
355
|
-
]
|
|
356
|
-
);
|
|
357
|
-
const edges3 = sqliteCore.sqliteTable(
|
|
358
|
-
n.edges,
|
|
359
|
-
{
|
|
360
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
361
|
-
id: sqliteCore.text("id").notNull(),
|
|
362
|
-
kind: sqliteCore.text("kind").notNull(),
|
|
363
|
-
fromKind: sqliteCore.text("from_kind").notNull(),
|
|
364
|
-
fromId: sqliteCore.text("from_id").notNull(),
|
|
365
|
-
toKind: sqliteCore.text("to_kind").notNull(),
|
|
366
|
-
toId: sqliteCore.text("to_id").notNull(),
|
|
367
|
-
props: sqliteCore.text("props").notNull(),
|
|
368
|
-
validFrom: sqliteCore.text("valid_from"),
|
|
369
|
-
validTo: sqliteCore.text("valid_to"),
|
|
370
|
-
createdAt: sqliteCore.text("created_at").notNull(),
|
|
371
|
-
updatedAt: sqliteCore.text("updated_at").notNull(),
|
|
372
|
-
deletedAt: sqliteCore.text("deleted_at")
|
|
373
|
-
},
|
|
374
|
-
(t) => [
|
|
375
|
-
sqliteCore.primaryKey({ columns: [t.graphId, t.id] }),
|
|
376
|
-
sqliteCore.index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
|
|
377
|
-
// Directional traversal index (outgoing): supports endpoint lookups
|
|
378
|
-
// and extra filtering by edge kind / target kind.
|
|
379
|
-
sqliteCore.index(`${n.edges}_from_idx`).on(
|
|
380
|
-
t.graphId,
|
|
381
|
-
t.fromKind,
|
|
382
|
-
t.fromId,
|
|
383
|
-
t.kind,
|
|
384
|
-
t.toKind,
|
|
385
|
-
t.deletedAt,
|
|
386
|
-
t.validTo
|
|
387
|
-
),
|
|
388
|
-
// Directional traversal index (incoming): mirrors from_idx for reverse traversals.
|
|
389
|
-
sqliteCore.index(`${n.edges}_to_idx`).on(
|
|
390
|
-
t.graphId,
|
|
391
|
-
t.toKind,
|
|
392
|
-
t.toId,
|
|
393
|
-
t.kind,
|
|
394
|
-
t.fromKind,
|
|
395
|
-
t.deletedAt,
|
|
396
|
-
t.validTo
|
|
397
|
-
),
|
|
398
|
-
sqliteCore.index(`${n.edges}_kind_created_idx`).on(
|
|
399
|
-
t.graphId,
|
|
400
|
-
t.kind,
|
|
401
|
-
t.deletedAt,
|
|
402
|
-
t.createdAt
|
|
403
|
-
),
|
|
404
|
-
sqliteCore.index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
|
|
405
|
-
sqliteCore.index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
|
|
406
|
-
sqliteCore.index(`${n.edges}_cardinality_idx`).on(
|
|
407
|
-
t.graphId,
|
|
408
|
-
t.kind,
|
|
409
|
-
t.fromKind,
|
|
410
|
-
t.fromId,
|
|
411
|
-
t.validTo
|
|
412
|
-
),
|
|
413
|
-
...chunkPN37HVAV_cjs.buildSqliteEdgeIndexBuilders(t, indexes)
|
|
414
|
-
]
|
|
415
|
-
);
|
|
416
|
-
const uniques3 = sqliteCore.sqliteTable(
|
|
417
|
-
n.uniques,
|
|
418
|
-
{
|
|
419
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
420
|
-
nodeKind: sqliteCore.text("node_kind").notNull(),
|
|
421
|
-
constraintName: sqliteCore.text("constraint_name").notNull(),
|
|
422
|
-
key: sqliteCore.text("key").notNull(),
|
|
423
|
-
nodeId: sqliteCore.text("node_id").notNull(),
|
|
424
|
-
concreteKind: sqliteCore.text("concrete_kind").notNull(),
|
|
425
|
-
deletedAt: sqliteCore.text("deleted_at")
|
|
426
|
-
},
|
|
427
|
-
(t) => [
|
|
428
|
-
sqliteCore.primaryKey({
|
|
429
|
-
columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
|
|
430
|
-
}),
|
|
431
|
-
sqliteCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
|
|
432
|
-
]
|
|
433
|
-
);
|
|
434
|
-
const schemaVersions3 = sqliteCore.sqliteTable(
|
|
435
|
-
n.schemaVersions,
|
|
436
|
-
{
|
|
437
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
438
|
-
version: sqliteCore.integer("version").notNull(),
|
|
439
|
-
schemaHash: sqliteCore.text("schema_hash").notNull(),
|
|
440
|
-
schemaDoc: sqliteCore.text("schema_doc").notNull(),
|
|
441
|
-
createdAt: sqliteCore.text("created_at").notNull(),
|
|
442
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(false)
|
|
443
|
-
},
|
|
444
|
-
(t) => [
|
|
445
|
-
sqliteCore.primaryKey({ columns: [t.graphId, t.version] }),
|
|
446
|
-
sqliteCore.index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive),
|
|
447
|
-
// Partial unique index enforcing the "at most one active version
|
|
448
|
-
// per graph" invariant at the storage layer. Defense in depth
|
|
449
|
-
// against buggy backend implementations or out-of-band writes.
|
|
450
|
-
// Forces the deactivate-then-activate ordering used by
|
|
451
|
-
// `commitSchemaVersion` and `setActiveVersion`.
|
|
452
|
-
sqliteCore.uniqueIndex(`${n.schemaVersions}_one_active_per_graph_idx`).on(t.graphId).where(drizzleOrm.sql`${t.isActive} = 1`)
|
|
453
|
-
]
|
|
454
|
-
);
|
|
455
|
-
const embeddings3 = sqliteCore.sqliteTable(
|
|
456
|
-
n.embeddings,
|
|
457
|
-
{
|
|
458
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
459
|
-
nodeKind: sqliteCore.text("node_kind").notNull(),
|
|
460
|
-
nodeId: sqliteCore.text("node_id").notNull(),
|
|
461
|
-
fieldPath: sqliteCore.text("field_path").notNull(),
|
|
462
|
-
/**
|
|
463
|
-
* Embedding vector.
|
|
464
|
-
* Stored as BLOB for sqlite-vec binary format, or JSON text for fallback.
|
|
465
|
-
* For sqlite-vec: use vec_f32() to convert JSON array to binary.
|
|
466
|
-
*/
|
|
467
|
-
embedding: sqliteCore.blob("embedding", { mode: "buffer" }).notNull(),
|
|
468
|
-
/** Number of dimensions (for validation) */
|
|
469
|
-
dimensions: sqliteCore.integer("dimensions").notNull(),
|
|
470
|
-
createdAt: sqliteCore.text("created_at").notNull(),
|
|
471
|
-
updatedAt: sqliteCore.text("updated_at").notNull()
|
|
472
|
-
},
|
|
473
|
-
(t) => [
|
|
474
|
-
sqliteCore.primaryKey({
|
|
475
|
-
columns: [t.graphId, t.nodeKind, t.nodeId, t.fieldPath]
|
|
476
|
-
}),
|
|
477
|
-
// Index for looking up embeddings by node
|
|
478
|
-
sqliteCore.index(`${n.embeddings}_node_idx`).on(
|
|
479
|
-
t.graphId,
|
|
480
|
-
t.nodeKind,
|
|
481
|
-
t.nodeId
|
|
482
|
-
),
|
|
483
|
-
// Index for filtering by kind and field (used in vector search)
|
|
484
|
-
sqliteCore.index(`${n.embeddings}_kind_field_idx`).on(
|
|
485
|
-
t.graphId,
|
|
486
|
-
t.nodeKind,
|
|
487
|
-
t.fieldPath
|
|
488
|
-
)
|
|
489
|
-
]
|
|
490
|
-
);
|
|
491
|
-
const indexMaterializations = sqliteCore.sqliteTable(
|
|
492
|
-
n.indexMaterializations,
|
|
493
|
-
{
|
|
494
|
-
indexName: sqliteCore.text("index_name").notNull(),
|
|
495
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
496
|
-
entity: sqliteCore.text("entity").notNull(),
|
|
497
|
-
kind: sqliteCore.text("kind").notNull(),
|
|
498
|
-
signature: sqliteCore.text("signature").notNull(),
|
|
499
|
-
schemaVersion: sqliteCore.integer("schema_version").notNull(),
|
|
500
|
-
materializedAt: sqliteCore.text("materialized_at"),
|
|
501
|
-
lastAttemptedAt: sqliteCore.text("last_attempted_at").notNull(),
|
|
502
|
-
lastError: sqliteCore.text("last_error")
|
|
503
|
-
},
|
|
504
|
-
(t) => [sqliteCore.primaryKey({ columns: [t.indexName] })]
|
|
505
|
-
);
|
|
506
|
-
const kindRemovals = sqliteCore.sqliteTable(
|
|
507
|
-
n.kindRemovals,
|
|
508
|
-
{
|
|
509
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
510
|
-
kindName: sqliteCore.text("kind_name").notNull(),
|
|
511
|
-
entity: sqliteCore.text("entity").notNull(),
|
|
512
|
-
schemaVersion: sqliteCore.integer("schema_version").notNull(),
|
|
513
|
-
removedAt: sqliteCore.text("removed_at"),
|
|
514
|
-
lastAttemptedAt: sqliteCore.text("last_attempted_at").notNull(),
|
|
515
|
-
lastError: sqliteCore.text("last_error")
|
|
516
|
-
},
|
|
517
|
-
(t) => [
|
|
518
|
-
sqliteCore.primaryKey({
|
|
519
|
-
columns: [t.graphId, t.kindName, t.entity, t.schemaVersion]
|
|
520
|
-
})
|
|
521
|
-
]
|
|
522
|
-
);
|
|
523
|
-
const reconciliationMarkers = sqliteCore.sqliteTable(
|
|
524
|
-
n.reconciliationMarkers,
|
|
525
|
-
{
|
|
526
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
527
|
-
reconciledToVersion: sqliteCore.integer("reconciled_to_version").notNull()
|
|
528
|
-
},
|
|
529
|
-
(t) => [sqliteCore.primaryKey({ columns: [t.graphId] })]
|
|
530
|
-
);
|
|
531
|
-
const contributionMaterializations = sqliteCore.sqliteTable(
|
|
532
|
-
n.contributionMaterializations,
|
|
533
|
-
{
|
|
534
|
-
graphId: sqliteCore.text("graph_id").notNull(),
|
|
535
|
-
logicalName: sqliteCore.text("logical_name").notNull(),
|
|
536
|
-
owner: sqliteCore.text("owner").notNull(),
|
|
537
|
-
tableName: sqliteCore.text("table_name").notNull(),
|
|
538
|
-
signature: sqliteCore.text("signature").notNull(),
|
|
539
|
-
materializedAt: sqliteCore.text("materialized_at"),
|
|
540
|
-
lastAttemptedAt: sqliteCore.text("last_attempted_at").notNull(),
|
|
541
|
-
lastError: sqliteCore.text("last_error")
|
|
542
|
-
},
|
|
543
|
-
(t) => [
|
|
544
|
-
sqliteCore.primaryKey({
|
|
545
|
-
columns: [t.graphId, t.logicalName, t.owner, t.tableName]
|
|
546
|
-
})
|
|
547
|
-
]
|
|
548
|
-
);
|
|
549
|
-
return {
|
|
550
|
-
nodes: nodes3,
|
|
551
|
-
edges: edges3,
|
|
552
|
-
uniques: uniques3,
|
|
553
|
-
schemaVersions: schemaVersions3,
|
|
554
|
-
embeddings: embeddings3,
|
|
555
|
-
indexMaterializations,
|
|
556
|
-
contributionMaterializations,
|
|
557
|
-
kindRemovals,
|
|
558
|
-
reconciliationMarkers,
|
|
559
|
-
/**
|
|
560
|
-
* The fulltext storage is a FTS5 virtual table which Drizzle cannot
|
|
561
|
-
* represent. DDL is emitted as raw SQL and operations query it via
|
|
562
|
-
* `sql.raw()`.
|
|
563
|
-
*/
|
|
564
|
-
fulltextTableName: n.fulltext
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
var tables2 = createSqliteTables();
|
|
568
|
-
var { nodes: nodes2, edges: edges2, uniques: uniques2, schemaVersions: schemaVersions2, embeddings: embeddings2 } = tables2;
|
|
254
|
+
var tables2 = createPostgresTables();
|
|
255
|
+
var { nodes, edges, uniques, schemaVersions, fulltext } = tables2;
|
|
569
256
|
function getSqliteColumnType(column) {
|
|
570
257
|
switch (column.columnType) {
|
|
571
258
|
case "SQLiteText": {
|
|
@@ -621,9 +308,9 @@ function renderIndexColumn(col) {
|
|
|
621
308
|
if (col && typeof col === "object" && "name" in col) {
|
|
622
309
|
return `"${col.name}"`;
|
|
623
310
|
}
|
|
624
|
-
const
|
|
625
|
-
if (
|
|
626
|
-
return
|
|
311
|
+
const sql12 = tryInlineSql(col);
|
|
312
|
+
if (sql12 !== void 0) {
|
|
313
|
+
return sql12;
|
|
627
314
|
}
|
|
628
315
|
return "unknown";
|
|
629
316
|
}
|
|
@@ -682,8 +369,8 @@ function inlineSqlOrThrow(value, context) {
|
|
|
682
369
|
function generateSqliteCreateIndexSQL(table) {
|
|
683
370
|
const config = sqliteCore.getTableConfig(table);
|
|
684
371
|
const statements = [];
|
|
685
|
-
for (const
|
|
686
|
-
const indexConfig =
|
|
372
|
+
for (const index2 of config.indexes) {
|
|
373
|
+
const indexConfig = index2.config;
|
|
687
374
|
const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
|
|
688
375
|
const unique = indexConfig.unique ? "UNIQUE " : "";
|
|
689
376
|
const where = indexConfig.where ? ` WHERE ${inlineSqlOrThrow(indexConfig.where, `SQLite index "${indexConfig.name}" WHERE clause`)}` : "";
|
|
@@ -699,13 +386,13 @@ function isSqliteTable(value) {
|
|
|
699
386
|
function runtimeStrategyContributions(fulltextStrategy, fulltextTableName) {
|
|
700
387
|
return fulltextStrategy.ownedTables(fulltextTableName).filter((contribution) => contribution.runtimeEnsure);
|
|
701
388
|
}
|
|
702
|
-
function sqliteContributions(tables3 =
|
|
389
|
+
function sqliteContributions(tables3 = chunkF2Q76CQ4_cjs.tables, fulltextStrategy = chunkC2RWFIYP_cjs.fts5Strategy) {
|
|
703
390
|
const contributions = [];
|
|
704
391
|
for (const [key, table] of Object.entries(tables3)) {
|
|
705
392
|
if (!isSqliteTable(table)) continue;
|
|
706
393
|
contributions.push({
|
|
707
394
|
logicalName: key,
|
|
708
|
-
owner:
|
|
395
|
+
owner: chunkC2RWFIYP_cjs.BASE_CONTRIBUTION_OWNER,
|
|
709
396
|
tableName: sqliteCore.getTableConfig(table).name,
|
|
710
397
|
createDdl: [
|
|
711
398
|
generateSqliteCreateTableSQL(table),
|
|
@@ -721,10 +408,12 @@ function sqliteContributions(tables3 = tables2, fulltextStrategy = chunkPN37HVAV
|
|
|
721
408
|
}
|
|
722
409
|
return contributions;
|
|
723
410
|
}
|
|
724
|
-
function generateSqliteDDL(tables3 =
|
|
725
|
-
return sqliteContributions(tables3, fulltextStrategy).flatMap(
|
|
411
|
+
function generateSqliteDDL(tables3 = chunkF2Q76CQ4_cjs.tables, fulltextStrategy = chunkC2RWFIYP_cjs.fts5Strategy) {
|
|
412
|
+
return sqliteContributions(tables3, fulltextStrategy).flatMap(
|
|
413
|
+
(contribution) => [...contribution.createDdl]
|
|
414
|
+
);
|
|
726
415
|
}
|
|
727
|
-
function generateSqliteMigrationSQL(tables3 =
|
|
416
|
+
function generateSqliteMigrationSQL(tables3 = chunkF2Q76CQ4_cjs.tables, fulltextStrategy = chunkC2RWFIYP_cjs.fts5Strategy) {
|
|
728
417
|
return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
|
|
729
418
|
}
|
|
730
419
|
function getPgColumnType(column) {
|
|
@@ -770,10 +459,7 @@ function generatePgCreateTableSQL(table) {
|
|
|
770
459
|
const config = pgCore.getTableConfig(table);
|
|
771
460
|
const columnDefs = [];
|
|
772
461
|
for (const column of config.columns) {
|
|
773
|
-
const parts = [
|
|
774
|
-
`"${column.name}"`,
|
|
775
|
-
getPgColumnType(column)
|
|
776
|
-
];
|
|
462
|
+
const parts = [`"${column.name}"`, getPgColumnType(column)];
|
|
777
463
|
if (column.notNull) {
|
|
778
464
|
parts.push("NOT NULL");
|
|
779
465
|
}
|
|
@@ -794,8 +480,8 @@ function generatePgCreateTableSQL(table) {
|
|
|
794
480
|
function generatePgCreateIndexSQL(table) {
|
|
795
481
|
const config = pgCore.getTableConfig(table);
|
|
796
482
|
const statements = [];
|
|
797
|
-
for (const
|
|
798
|
-
const indexConfig =
|
|
483
|
+
for (const index2 of config.indexes) {
|
|
484
|
+
const indexConfig = index2.config;
|
|
799
485
|
const columns = indexConfig.columns.map((c) => renderIndexColumn(c)).join(", ");
|
|
800
486
|
const unique = indexConfig.unique ? "UNIQUE " : "";
|
|
801
487
|
const method = indexConfig.method && indexConfig.method !== "btree" ? ` USING ${indexConfig.method}` : "";
|
|
@@ -809,14 +495,14 @@ function generatePgCreateIndexSQL(table) {
|
|
|
809
495
|
function isPgTable(value) {
|
|
810
496
|
return drizzleOrm.is(value, pgCore.PgTable);
|
|
811
497
|
}
|
|
812
|
-
function postgresContributions(tables3 =
|
|
498
|
+
function postgresContributions(tables3 = tables2, fulltextStrategy = chunkC2RWFIYP_cjs.tsvectorStrategy) {
|
|
813
499
|
const contributions = [];
|
|
814
500
|
for (const [key, table] of Object.entries(tables3)) {
|
|
815
501
|
if (!isPgTable(table)) continue;
|
|
816
502
|
if (table === tables3.fulltext) continue;
|
|
817
503
|
contributions.push({
|
|
818
504
|
logicalName: key,
|
|
819
|
-
owner:
|
|
505
|
+
owner: chunkC2RWFIYP_cjs.BASE_CONTRIBUTION_OWNER,
|
|
820
506
|
tableName: pgCore.getTableConfig(table).name,
|
|
821
507
|
createDdl: [
|
|
822
508
|
generatePgCreateTableSQL(table),
|
|
@@ -832,10 +518,12 @@ function postgresContributions(tables3 = tables, fulltextStrategy = chunkPN37HVA
|
|
|
832
518
|
}
|
|
833
519
|
return contributions;
|
|
834
520
|
}
|
|
835
|
-
function generatePostgresDDL(tables3 =
|
|
836
|
-
return postgresContributions(tables3, fulltextStrategy).flatMap(
|
|
521
|
+
function generatePostgresDDL(tables3 = tables2, fulltextStrategy = chunkC2RWFIYP_cjs.tsvectorStrategy) {
|
|
522
|
+
return postgresContributions(tables3, fulltextStrategy).flatMap(
|
|
523
|
+
(contribution) => [...contribution.createDdl]
|
|
524
|
+
);
|
|
837
525
|
}
|
|
838
|
-
function generatePostgresMigrationSQL(tables3 =
|
|
526
|
+
function generatePostgresMigrationSQL(tables3 = tables2, fulltextStrategy = chunkC2RWFIYP_cjs.tsvectorStrategy) {
|
|
839
527
|
const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
|
|
840
528
|
const ddlSql = generatePostgresDDL(tables3, fulltextStrategy).join("\n\n");
|
|
841
529
|
return `${extensionSql}
|
|
@@ -843,10 +531,87 @@ function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = chunk
|
|
|
843
531
|
${ddlSql}`;
|
|
844
532
|
}
|
|
845
533
|
|
|
534
|
+
// src/backend/drizzle/vector-runtime.ts
|
|
535
|
+
function vectorSlotKey(slot) {
|
|
536
|
+
return JSON.stringify([
|
|
537
|
+
slot.graphId,
|
|
538
|
+
slot.nodeKind,
|
|
539
|
+
slot.fieldPath,
|
|
540
|
+
slot.dimensions,
|
|
541
|
+
slot.metric,
|
|
542
|
+
slot.indexType
|
|
543
|
+
]);
|
|
544
|
+
}
|
|
545
|
+
function createVectorSlotLatch() {
|
|
546
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
547
|
+
return {
|
|
548
|
+
ensure(strategy, slot, execDdl) {
|
|
549
|
+
const key = vectorSlotKey(slot);
|
|
550
|
+
const existing = inFlight.get(key);
|
|
551
|
+
if (existing !== void 0) return existing;
|
|
552
|
+
const run = (async () => {
|
|
553
|
+
for (const contribution of strategy.ownedTables(slot)) {
|
|
554
|
+
for (const statement of contribution.createDdl) {
|
|
555
|
+
await execDdl(statement);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
})();
|
|
559
|
+
const cached = run.catch((error) => {
|
|
560
|
+
inFlight.delete(key);
|
|
561
|
+
throw error;
|
|
562
|
+
});
|
|
563
|
+
inFlight.set(key, cached);
|
|
564
|
+
return cached;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
var VECTOR_SLOT_PLACEHOLDER_DIMENSIONS = 1;
|
|
569
|
+
function vectorSlotFromParams(params) {
|
|
570
|
+
return {
|
|
571
|
+
graphId: params.graphId,
|
|
572
|
+
nodeKind: params.nodeKind,
|
|
573
|
+
fieldPath: params.fieldPath,
|
|
574
|
+
dimensions: params.dimensions,
|
|
575
|
+
metric: params.metric,
|
|
576
|
+
indexType: params.indexType
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function vectorSlotFromCreateIndexParams(params) {
|
|
580
|
+
return {
|
|
581
|
+
...vectorSlotFromParams(params),
|
|
582
|
+
...params.indexParams === void 0 ? {} : { indexParams: params.indexParams }
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function vectorSlotFromDropIndexParams(params) {
|
|
586
|
+
return {
|
|
587
|
+
graphId: params.graphId,
|
|
588
|
+
nodeKind: params.nodeKind,
|
|
589
|
+
fieldPath: params.fieldPath,
|
|
590
|
+
dimensions: VECTOR_SLOT_PLACEHOLDER_DIMENSIONS,
|
|
591
|
+
metric: "cosine",
|
|
592
|
+
indexType: "hnsw"
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function mapVectorWriteError(error, params) {
|
|
596
|
+
const mismatch = chunkRP7YITHX_cjs.parseDimensionMismatch(error);
|
|
597
|
+
if (mismatch === void 0) return error;
|
|
598
|
+
const attempted = mismatch.actual ?? "a different number of";
|
|
599
|
+
return new chunkG6P3OVDY_cjs.EmbeddingDimensionChangedError(
|
|
600
|
+
`Embedding "${params.nodeKind}.${params.fieldPath}" was written with ${attempted} dimensions, but its per-field storage expects ${mismatch.expected}. The field's embedding dimension changed; existing vectors must be recreated and re-embedded.`,
|
|
601
|
+
{
|
|
602
|
+
kind: params.nodeKind,
|
|
603
|
+
fieldPath: params.fieldPath,
|
|
604
|
+
storedDimensions: mismatch.expected,
|
|
605
|
+
...mismatch.actual === void 0 ? {} : { declaredDimensions: mismatch.actual }
|
|
606
|
+
},
|
|
607
|
+
{ cause: error }
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
846
611
|
// src/backend/drizzle/row-mappers.ts
|
|
847
612
|
function requireTimestamp(value, field) {
|
|
848
613
|
if (value === void 0) {
|
|
849
|
-
throw new
|
|
614
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
850
615
|
`Expected non-null ${field} timestamp`,
|
|
851
616
|
{ operation: "select", entity: "row" }
|
|
852
617
|
);
|
|
@@ -855,7 +620,7 @@ function requireTimestamp(value, field) {
|
|
|
855
620
|
}
|
|
856
621
|
function asString(value, field) {
|
|
857
622
|
if (typeof value !== "string") {
|
|
858
|
-
throw new
|
|
623
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
859
624
|
`Expected ${field} to be string, got ${typeof value}`,
|
|
860
625
|
{ operation: "select", entity: "row" }
|
|
861
626
|
);
|
|
@@ -864,7 +629,7 @@ function asString(value, field) {
|
|
|
864
629
|
}
|
|
865
630
|
function asNumber(value, field) {
|
|
866
631
|
if (typeof value !== "number") {
|
|
867
|
-
throw new
|
|
632
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
868
633
|
`Expected ${field} to be number, got ${typeof value}`,
|
|
869
634
|
{ operation: "select", entity: "row" }
|
|
870
635
|
);
|
|
@@ -905,7 +670,7 @@ var SQLITE_ROW_MAPPER_CONFIG = {
|
|
|
905
670
|
formatTimestamp: (value) => {
|
|
906
671
|
if (value === null || value === void 0) return;
|
|
907
672
|
if (typeof value !== "string") {
|
|
908
|
-
throw new
|
|
673
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
909
674
|
`Expected timestamp to be string, got ${typeof value}`,
|
|
910
675
|
{ operation: "select", entity: "row" }
|
|
911
676
|
);
|
|
@@ -914,7 +679,7 @@ var SQLITE_ROW_MAPPER_CONFIG = {
|
|
|
914
679
|
},
|
|
915
680
|
normalizeJson: (value) => {
|
|
916
681
|
if (typeof value !== "string") {
|
|
917
|
-
throw new
|
|
682
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
918
683
|
`Expected JSON column to be string, got ${typeof value}`,
|
|
919
684
|
{ operation: "select", entity: "row" }
|
|
920
685
|
);
|
|
@@ -1037,7 +802,7 @@ async function computeContributionSignature(dialect, identity, createDdl) {
|
|
|
1037
802
|
tableName: identity.tableName,
|
|
1038
803
|
createDdl
|
|
1039
804
|
};
|
|
1040
|
-
return
|
|
805
|
+
return chunkUPBXUOW7_cjs.sha256Hex(JSON.stringify(hashable, chunkRP7YITHX_cjs.sortedReplacer), 16);
|
|
1041
806
|
}
|
|
1042
807
|
function evaluateContributionState(row, signature) {
|
|
1043
808
|
if (row === void 0) return "missing";
|
|
@@ -1171,7 +936,7 @@ function createContributionMaterializer(deps) {
|
|
|
1171
936
|
state: evaluateContributionState(existing, signature)
|
|
1172
937
|
};
|
|
1173
938
|
} catch (error) {
|
|
1174
|
-
if (!
|
|
939
|
+
if (!chunkRP7YITHX_cjs.isMissingTableError(error)) throw error;
|
|
1175
940
|
return { kind: "missing-table", error };
|
|
1176
941
|
}
|
|
1177
942
|
}
|
|
@@ -1200,13 +965,13 @@ function createContributionMaterializer(deps) {
|
|
|
1200
965
|
for (const contribution of runtimeContributions()) {
|
|
1201
966
|
const read = await readContributionState(graphId, contribution);
|
|
1202
967
|
if (read.kind === "missing-table") {
|
|
1203
|
-
throw new
|
|
968
|
+
throw new chunkG6P3OVDY_cjs.StoreNotInitializedError(graphId, "missing", {
|
|
1204
969
|
cause: read.error,
|
|
1205
970
|
details: { logicalName: contribution.logicalName }
|
|
1206
971
|
});
|
|
1207
972
|
}
|
|
1208
973
|
if (read.state !== "initialized") {
|
|
1209
|
-
throw new
|
|
974
|
+
throw new chunkG6P3OVDY_cjs.StoreNotInitializedError(graphId, read.state, {
|
|
1210
975
|
details: { logicalName: contribution.logicalName }
|
|
1211
976
|
});
|
|
1212
977
|
}
|
|
@@ -1317,7 +1082,7 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
|
|
|
1317
1082
|
function assertAdoptedDialect(externalTx, brand, backend) {
|
|
1318
1083
|
if (drizzleOrm.is(externalTx, brand)) return;
|
|
1319
1084
|
const label = backend === "postgres" ? "Postgres" : "SQLite";
|
|
1320
|
-
throw new
|
|
1085
|
+
throw new chunkG6P3OVDY_cjs.ConfigurationError(
|
|
1321
1086
|
`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.`,
|
|
1322
1087
|
{ backend, capability: "adoptTransaction" }
|
|
1323
1088
|
);
|
|
@@ -1327,15 +1092,15 @@ function chunkArray(values, size) {
|
|
|
1327
1092
|
return [values];
|
|
1328
1093
|
}
|
|
1329
1094
|
const chunks = [];
|
|
1330
|
-
for (let
|
|
1331
|
-
chunks.push(values.slice(
|
|
1095
|
+
for (let index2 = 0; index2 < values.length; index2 += size) {
|
|
1096
|
+
chunks.push(values.slice(index2, index2 + size));
|
|
1332
1097
|
}
|
|
1333
1098
|
return chunks;
|
|
1334
1099
|
}
|
|
1335
1100
|
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
1336
1101
|
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
1337
1102
|
if (actualActiveVersion !== expectedVersion) {
|
|
1338
|
-
throw new
|
|
1103
|
+
throw new chunkG6P3OVDY_cjs.StaleVersionError({
|
|
1339
1104
|
graphId,
|
|
1340
1105
|
expected: expectedVersion,
|
|
1341
1106
|
actual: actualActiveVersion
|
|
@@ -1356,7 +1121,7 @@ function createCommonOperationBackend(options) {
|
|
|
1356
1121
|
const timestamp2 = nowIso2();
|
|
1357
1122
|
const query = operationStrategy.buildInsertNode(params, timestamp2);
|
|
1358
1123
|
const row = await execution.execGet(query);
|
|
1359
|
-
if (!row) throw new
|
|
1124
|
+
if (!row) throw new chunkG6P3OVDY_cjs.DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
|
|
1360
1125
|
return rowMappers.toNodeRow(row);
|
|
1361
1126
|
},
|
|
1362
1127
|
async insertNodeNoReturn(params) {
|
|
@@ -1406,7 +1171,7 @@ function createCommonOperationBackend(options) {
|
|
|
1406
1171
|
const timestamp2 = nowIso2();
|
|
1407
1172
|
const query = operationStrategy.buildUpdateNode(params, timestamp2);
|
|
1408
1173
|
const row = await execution.execGet(query);
|
|
1409
|
-
if (!row) throw new
|
|
1174
|
+
if (!row) throw new chunkG6P3OVDY_cjs.DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
|
|
1410
1175
|
return rowMappers.toNodeRow(row);
|
|
1411
1176
|
},
|
|
1412
1177
|
async deleteNode(params) {
|
|
@@ -1416,18 +1181,19 @@ function createCommonOperationBackend(options) {
|
|
|
1416
1181
|
},
|
|
1417
1182
|
// IMPORTANT: This cascade is not atomic. Callers must ensure this runs
|
|
1418
1183
|
// within a transaction to prevent partial deletion on intermediate failure.
|
|
1184
|
+
//
|
|
1185
|
+
// Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
|
|
1186
|
+
// fieldPath)` strategy-owned tables addressable only with the slot
|
|
1187
|
+
// context the graph-agnostic backend lacks. The store's hard-delete
|
|
1188
|
+
// path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
|
|
1189
|
+
// resolves each embedding field and routes a per-field
|
|
1190
|
+
// `backend.deleteEmbedding` through the active vector strategy.
|
|
1419
1191
|
async hardDeleteNode(params) {
|
|
1420
1192
|
const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
|
|
1421
1193
|
params.graphId,
|
|
1422
1194
|
params.id
|
|
1423
1195
|
);
|
|
1424
1196
|
await execution.execRun(deleteUniquesQuery);
|
|
1425
|
-
const deleteEmbeddingsQuery = operationStrategy.buildHardDeleteEmbeddingsByNode(
|
|
1426
|
-
params.graphId,
|
|
1427
|
-
params.kind,
|
|
1428
|
-
params.id
|
|
1429
|
-
);
|
|
1430
|
-
await execution.execRun(deleteEmbeddingsQuery);
|
|
1431
1197
|
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
1432
1198
|
params.graphId,
|
|
1433
1199
|
params.kind,
|
|
@@ -1449,7 +1215,7 @@ function createCommonOperationBackend(options) {
|
|
|
1449
1215
|
const timestamp2 = nowIso2();
|
|
1450
1216
|
const query = operationStrategy.buildInsertEdge(params, timestamp2);
|
|
1451
1217
|
const row = await execution.execGet(query);
|
|
1452
|
-
if (!row) throw new
|
|
1218
|
+
if (!row) throw new chunkG6P3OVDY_cjs.DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
|
|
1453
1219
|
return rowMappers.toEdgeRow(row);
|
|
1454
1220
|
},
|
|
1455
1221
|
async insertEdgeNoReturn(params) {
|
|
@@ -1499,7 +1265,7 @@ function createCommonOperationBackend(options) {
|
|
|
1499
1265
|
const timestamp2 = nowIso2();
|
|
1500
1266
|
const query = operationStrategy.buildUpdateEdge(params, timestamp2);
|
|
1501
1267
|
const row = await execution.execGet(query);
|
|
1502
|
-
if (!row) throw new
|
|
1268
|
+
if (!row) throw new chunkG6P3OVDY_cjs.DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
|
|
1503
1269
|
return rowMappers.toEdgeRow(row);
|
|
1504
1270
|
},
|
|
1505
1271
|
async deleteEdge(params) {
|
|
@@ -1550,7 +1316,7 @@ function createCommonOperationBackend(options) {
|
|
|
1550
1316
|
const query = operationStrategy.buildInsertUnique(params);
|
|
1551
1317
|
const result = await execution.execGet(query);
|
|
1552
1318
|
if (result && result.node_id !== params.nodeId) {
|
|
1553
|
-
throw new
|
|
1319
|
+
throw new chunkG6P3OVDY_cjs.UniquenessError({
|
|
1554
1320
|
constraintName: params.constraintName,
|
|
1555
1321
|
kind: params.nodeKind,
|
|
1556
1322
|
existingId: result.node_id,
|
|
@@ -1600,7 +1366,7 @@ function createCommonOperationBackend(options) {
|
|
|
1600
1366
|
if (existingRaw !== void 0) {
|
|
1601
1367
|
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
1602
1368
|
if (existing.schema_hash !== params.schemaHash) {
|
|
1603
|
-
throw new
|
|
1369
|
+
throw new chunkG6P3OVDY_cjs.SchemaContentConflictError({
|
|
1604
1370
|
graphId: params.graphId,
|
|
1605
1371
|
version: params.version,
|
|
1606
1372
|
existingHash: existing.schema_hash,
|
|
@@ -1648,7 +1414,7 @@ function createCommonOperationBackend(options) {
|
|
|
1648
1414
|
);
|
|
1649
1415
|
const insertedRaw = await execution.execGet(insertQuery);
|
|
1650
1416
|
if (!insertedRaw) {
|
|
1651
|
-
throw new
|
|
1417
|
+
throw new chunkG6P3OVDY_cjs.DatabaseOperationError(
|
|
1652
1418
|
"Insert schema failed: no row returned",
|
|
1653
1419
|
{ operation: "insert", entity: "schema" }
|
|
1654
1420
|
);
|
|
@@ -1669,7 +1435,7 @@ function createCommonOperationBackend(options) {
|
|
|
1669
1435
|
)
|
|
1670
1436
|
);
|
|
1671
1437
|
if (!targetRaw) {
|
|
1672
|
-
throw new
|
|
1438
|
+
throw new chunkG6P3OVDY_cjs.MigrationError(
|
|
1673
1439
|
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
1674
1440
|
{
|
|
1675
1441
|
graphId: params.graphId,
|
|
@@ -1694,10 +1460,9 @@ function createCommonOperationBackend(options) {
|
|
|
1694
1460
|
};
|
|
1695
1461
|
}
|
|
1696
1462
|
function buildClearGraph(tables3, graphId) {
|
|
1697
|
-
const fulltext2 =
|
|
1463
|
+
const fulltext2 = chunkC2RWFIYP_cjs.quotedTableName(tables3.fulltextTableName);
|
|
1698
1464
|
return [
|
|
1699
1465
|
drizzleOrm.sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}`,
|
|
1700
|
-
drizzleOrm.sql`DELETE FROM ${tables3.embeddings} WHERE ${tables3.embeddings.graphId} = ${graphId}`,
|
|
1701
1466
|
drizzleOrm.sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
|
|
1702
1467
|
drizzleOrm.sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
|
|
1703
1468
|
drizzleOrm.sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`,
|
|
@@ -1728,20 +1493,20 @@ function buildTemporalConditions(table, params) {
|
|
|
1728
1493
|
return conditions;
|
|
1729
1494
|
}
|
|
1730
1495
|
function buildFindNodesByKind(tables3, params) {
|
|
1731
|
-
const { nodes:
|
|
1496
|
+
const { nodes: nodes2 } = tables3;
|
|
1732
1497
|
const conditions = [
|
|
1733
|
-
drizzleOrm.sql`${
|
|
1734
|
-
drizzleOrm.sql`${
|
|
1735
|
-
...buildTemporalConditions(
|
|
1498
|
+
drizzleOrm.sql`${nodes2.graphId} = ${params.graphId}`,
|
|
1499
|
+
drizzleOrm.sql`${nodes2.kind} = ${params.kind}`,
|
|
1500
|
+
...buildTemporalConditions(nodes2, params)
|
|
1736
1501
|
];
|
|
1737
1502
|
if (params.orderBy === "id" && params.after !== void 0) {
|
|
1738
|
-
conditions.push(drizzleOrm.sql`${
|
|
1503
|
+
conditions.push(drizzleOrm.sql`${nodes2.id} > ${params.after}`);
|
|
1739
1504
|
}
|
|
1740
1505
|
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1741
|
-
const orderByClause = params.orderBy === "id" ? drizzleOrm.sql`${
|
|
1506
|
+
const orderByClause = params.orderBy === "id" ? drizzleOrm.sql`${nodes2.id} ASC` : drizzleOrm.sql`${nodes2.createdAt} DESC, ${nodes2.id} DESC`;
|
|
1742
1507
|
if (params.limit !== void 0 && params.offset !== void 0) {
|
|
1743
1508
|
return drizzleOrm.sql`
|
|
1744
|
-
SELECT * FROM ${
|
|
1509
|
+
SELECT * FROM ${nodes2}
|
|
1745
1510
|
WHERE ${whereClause}
|
|
1746
1511
|
ORDER BY ${orderByClause}
|
|
1747
1512
|
LIMIT ${params.limit} OFFSET ${params.offset}
|
|
@@ -1749,286 +1514,286 @@ function buildFindNodesByKind(tables3, params) {
|
|
|
1749
1514
|
}
|
|
1750
1515
|
if (params.limit !== void 0) {
|
|
1751
1516
|
return drizzleOrm.sql`
|
|
1752
|
-
SELECT * FROM ${
|
|
1517
|
+
SELECT * FROM ${nodes2}
|
|
1753
1518
|
WHERE ${whereClause}
|
|
1754
1519
|
ORDER BY ${orderByClause}
|
|
1755
1520
|
LIMIT ${params.limit}
|
|
1756
1521
|
`;
|
|
1757
1522
|
}
|
|
1758
1523
|
return drizzleOrm.sql`
|
|
1759
|
-
SELECT * FROM ${
|
|
1524
|
+
SELECT * FROM ${nodes2}
|
|
1760
1525
|
WHERE ${whereClause}
|
|
1761
1526
|
ORDER BY ${orderByClause}
|
|
1762
1527
|
`;
|
|
1763
1528
|
}
|
|
1764
1529
|
function buildCountNodesByKind(tables3, params) {
|
|
1765
|
-
const { nodes:
|
|
1530
|
+
const { nodes: nodes2 } = tables3;
|
|
1766
1531
|
const conditions = [
|
|
1767
|
-
drizzleOrm.sql`${
|
|
1768
|
-
drizzleOrm.sql`${
|
|
1769
|
-
...buildTemporalConditions(
|
|
1532
|
+
drizzleOrm.sql`${nodes2.graphId} = ${params.graphId}`,
|
|
1533
|
+
drizzleOrm.sql`${nodes2.kind} = ${params.kind}`,
|
|
1534
|
+
...buildTemporalConditions(nodes2, params)
|
|
1770
1535
|
];
|
|
1771
1536
|
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1772
1537
|
return drizzleOrm.sql`
|
|
1773
|
-
SELECT COUNT(*) as count FROM ${
|
|
1538
|
+
SELECT COUNT(*) as count FROM ${nodes2}
|
|
1774
1539
|
WHERE ${whereClause}
|
|
1775
1540
|
`;
|
|
1776
1541
|
}
|
|
1777
1542
|
function buildFindEdgesByKind(tables3, params) {
|
|
1778
|
-
const { edges:
|
|
1543
|
+
const { edges: edges2 } = tables3;
|
|
1779
1544
|
const conditions = [
|
|
1780
|
-
drizzleOrm.sql`${
|
|
1781
|
-
drizzleOrm.sql`${
|
|
1782
|
-
...buildTemporalConditions(
|
|
1545
|
+
drizzleOrm.sql`${edges2.graphId} = ${params.graphId}`,
|
|
1546
|
+
drizzleOrm.sql`${edges2.kind} = ${params.kind}`,
|
|
1547
|
+
...buildTemporalConditions(edges2, params)
|
|
1783
1548
|
];
|
|
1784
1549
|
if (params.fromKind !== void 0) {
|
|
1785
|
-
conditions.push(drizzleOrm.sql`${
|
|
1550
|
+
conditions.push(drizzleOrm.sql`${edges2.fromKind} = ${params.fromKind}`);
|
|
1786
1551
|
}
|
|
1787
1552
|
if (params.fromId !== void 0) {
|
|
1788
|
-
conditions.push(drizzleOrm.sql`${
|
|
1553
|
+
conditions.push(drizzleOrm.sql`${edges2.fromId} = ${params.fromId}`);
|
|
1789
1554
|
}
|
|
1790
1555
|
if (params.toKind !== void 0) {
|
|
1791
|
-
conditions.push(drizzleOrm.sql`${
|
|
1556
|
+
conditions.push(drizzleOrm.sql`${edges2.toKind} = ${params.toKind}`);
|
|
1792
1557
|
}
|
|
1793
1558
|
if (params.toId !== void 0) {
|
|
1794
|
-
conditions.push(drizzleOrm.sql`${
|
|
1559
|
+
conditions.push(drizzleOrm.sql`${edges2.toId} = ${params.toId}`);
|
|
1795
1560
|
}
|
|
1796
1561
|
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1797
1562
|
if (params.limit !== void 0 && params.offset !== void 0) {
|
|
1798
1563
|
return drizzleOrm.sql`
|
|
1799
|
-
SELECT * FROM ${
|
|
1564
|
+
SELECT * FROM ${edges2}
|
|
1800
1565
|
WHERE ${whereClause}
|
|
1801
|
-
ORDER BY ${
|
|
1566
|
+
ORDER BY ${edges2.createdAt} DESC
|
|
1802
1567
|
LIMIT ${params.limit} OFFSET ${params.offset}
|
|
1803
1568
|
`;
|
|
1804
1569
|
}
|
|
1805
1570
|
if (params.limit !== void 0) {
|
|
1806
1571
|
return drizzleOrm.sql`
|
|
1807
|
-
SELECT * FROM ${
|
|
1572
|
+
SELECT * FROM ${edges2}
|
|
1808
1573
|
WHERE ${whereClause}
|
|
1809
|
-
ORDER BY ${
|
|
1574
|
+
ORDER BY ${edges2.createdAt} DESC
|
|
1810
1575
|
LIMIT ${params.limit}
|
|
1811
1576
|
`;
|
|
1812
1577
|
}
|
|
1813
1578
|
return drizzleOrm.sql`
|
|
1814
|
-
SELECT * FROM ${
|
|
1579
|
+
SELECT * FROM ${edges2}
|
|
1815
1580
|
WHERE ${whereClause}
|
|
1816
|
-
ORDER BY ${
|
|
1581
|
+
ORDER BY ${edges2.createdAt} DESC
|
|
1817
1582
|
`;
|
|
1818
1583
|
}
|
|
1819
1584
|
function buildCountEdgesByKind(tables3, params) {
|
|
1820
|
-
const { edges:
|
|
1585
|
+
const { edges: edges2 } = tables3;
|
|
1821
1586
|
const conditions = [
|
|
1822
|
-
drizzleOrm.sql`${
|
|
1823
|
-
drizzleOrm.sql`${
|
|
1824
|
-
...buildTemporalConditions(
|
|
1587
|
+
drizzleOrm.sql`${edges2.graphId} = ${params.graphId}`,
|
|
1588
|
+
drizzleOrm.sql`${edges2.kind} = ${params.kind}`,
|
|
1589
|
+
...buildTemporalConditions(edges2, params)
|
|
1825
1590
|
];
|
|
1826
1591
|
if (params.fromKind !== void 0) {
|
|
1827
|
-
conditions.push(drizzleOrm.sql`${
|
|
1592
|
+
conditions.push(drizzleOrm.sql`${edges2.fromKind} = ${params.fromKind}`);
|
|
1828
1593
|
}
|
|
1829
1594
|
if (params.fromId !== void 0) {
|
|
1830
|
-
conditions.push(drizzleOrm.sql`${
|
|
1595
|
+
conditions.push(drizzleOrm.sql`${edges2.fromId} = ${params.fromId}`);
|
|
1831
1596
|
}
|
|
1832
1597
|
if (params.toKind !== void 0) {
|
|
1833
|
-
conditions.push(drizzleOrm.sql`${
|
|
1598
|
+
conditions.push(drizzleOrm.sql`${edges2.toKind} = ${params.toKind}`);
|
|
1834
1599
|
}
|
|
1835
1600
|
if (params.toId !== void 0) {
|
|
1836
|
-
conditions.push(drizzleOrm.sql`${
|
|
1601
|
+
conditions.push(drizzleOrm.sql`${edges2.toId} = ${params.toId}`);
|
|
1837
1602
|
}
|
|
1838
1603
|
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1839
1604
|
return drizzleOrm.sql`
|
|
1840
|
-
SELECT COUNT(*) as count FROM ${
|
|
1605
|
+
SELECT COUNT(*) as count FROM ${edges2}
|
|
1841
1606
|
WHERE ${whereClause}
|
|
1842
1607
|
`;
|
|
1843
1608
|
}
|
|
1844
1609
|
function buildInsertEdge(tables3, params, timestamp2) {
|
|
1845
|
-
const { edges:
|
|
1610
|
+
const { edges: edges2 } = tables3;
|
|
1846
1611
|
const propsJson = JSON.stringify(params.props);
|
|
1847
|
-
const columns =
|
|
1612
|
+
const columns = chunkC2RWFIYP_cjs.edgeColumnList(edges2);
|
|
1848
1613
|
return drizzleOrm.sql`
|
|
1849
|
-
INSERT INTO ${
|
|
1614
|
+
INSERT INTO ${edges2} (${columns})
|
|
1850
1615
|
VALUES (
|
|
1851
1616
|
${params.graphId}, ${params.id}, ${params.kind},
|
|
1852
1617
|
${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
|
|
1853
|
-
${propsJson}, ${
|
|
1618
|
+
${propsJson}, ${chunkC2RWFIYP_cjs.sqlNull(params.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(params.validTo)},
|
|
1854
1619
|
${timestamp2}, ${timestamp2}
|
|
1855
1620
|
)
|
|
1856
1621
|
RETURNING *
|
|
1857
1622
|
`;
|
|
1858
1623
|
}
|
|
1859
1624
|
function buildInsertEdgeNoReturn(tables3, params, timestamp2) {
|
|
1860
|
-
const { edges:
|
|
1625
|
+
const { edges: edges2 } = tables3;
|
|
1861
1626
|
const propsJson = JSON.stringify(params.props);
|
|
1862
|
-
const columns =
|
|
1627
|
+
const columns = chunkC2RWFIYP_cjs.edgeColumnList(edges2);
|
|
1863
1628
|
return drizzleOrm.sql`
|
|
1864
|
-
INSERT INTO ${
|
|
1629
|
+
INSERT INTO ${edges2} (${columns})
|
|
1865
1630
|
VALUES (
|
|
1866
1631
|
${params.graphId}, ${params.id}, ${params.kind},
|
|
1867
1632
|
${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
|
|
1868
|
-
${propsJson}, ${
|
|
1633
|
+
${propsJson}, ${chunkC2RWFIYP_cjs.sqlNull(params.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(params.validTo)},
|
|
1869
1634
|
${timestamp2}, ${timestamp2}
|
|
1870
1635
|
)
|
|
1871
1636
|
`;
|
|
1872
1637
|
}
|
|
1873
1638
|
function buildInsertEdgesBatch(tables3, params, timestamp2) {
|
|
1874
|
-
const { edges:
|
|
1875
|
-
const columns =
|
|
1639
|
+
const { edges: edges2 } = tables3;
|
|
1640
|
+
const columns = chunkC2RWFIYP_cjs.edgeColumnList(edges2);
|
|
1876
1641
|
const values = params.map((edgeParams) => {
|
|
1877
1642
|
const propsJson = JSON.stringify(edgeParams.props);
|
|
1878
|
-
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${
|
|
1643
|
+
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkC2RWFIYP_cjs.sqlNull(edgeParams.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
|
|
1879
1644
|
});
|
|
1880
1645
|
return drizzleOrm.sql`
|
|
1881
|
-
INSERT INTO ${
|
|
1646
|
+
INSERT INTO ${edges2} (${columns})
|
|
1882
1647
|
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1883
1648
|
`;
|
|
1884
1649
|
}
|
|
1885
1650
|
function buildInsertEdgesBatchReturning(tables3, params, timestamp2) {
|
|
1886
|
-
const { edges:
|
|
1887
|
-
const columns =
|
|
1651
|
+
const { edges: edges2 } = tables3;
|
|
1652
|
+
const columns = chunkC2RWFIYP_cjs.edgeColumnList(edges2);
|
|
1888
1653
|
const values = params.map((edgeParams) => {
|
|
1889
1654
|
const propsJson = JSON.stringify(edgeParams.props);
|
|
1890
|
-
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${
|
|
1655
|
+
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${chunkC2RWFIYP_cjs.sqlNull(edgeParams.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(edgeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
|
|
1891
1656
|
});
|
|
1892
1657
|
return drizzleOrm.sql`
|
|
1893
|
-
INSERT INTO ${
|
|
1658
|
+
INSERT INTO ${edges2} (${columns})
|
|
1894
1659
|
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1895
1660
|
RETURNING *
|
|
1896
1661
|
`;
|
|
1897
1662
|
}
|
|
1898
1663
|
function buildGetEdge(tables3, graphId, id) {
|
|
1899
|
-
const { edges:
|
|
1664
|
+
const { edges: edges2 } = tables3;
|
|
1900
1665
|
return drizzleOrm.sql`
|
|
1901
|
-
SELECT * FROM ${
|
|
1902
|
-
WHERE ${
|
|
1903
|
-
AND ${
|
|
1666
|
+
SELECT * FROM ${edges2}
|
|
1667
|
+
WHERE ${edges2.graphId} = ${graphId}
|
|
1668
|
+
AND ${edges2.id} = ${id}
|
|
1904
1669
|
`;
|
|
1905
1670
|
}
|
|
1906
1671
|
function buildGetEdges(tables3, graphId, ids) {
|
|
1907
|
-
const { edges:
|
|
1672
|
+
const { edges: edges2 } = tables3;
|
|
1908
1673
|
const idPlaceholders = drizzleOrm.sql.join(
|
|
1909
1674
|
ids.map((edgeId) => drizzleOrm.sql`${edgeId}`),
|
|
1910
1675
|
drizzleOrm.sql`, `
|
|
1911
1676
|
);
|
|
1912
1677
|
return drizzleOrm.sql`
|
|
1913
|
-
SELECT * FROM ${
|
|
1914
|
-
WHERE ${
|
|
1915
|
-
AND ${
|
|
1678
|
+
SELECT * FROM ${edges2}
|
|
1679
|
+
WHERE ${edges2.graphId} = ${graphId}
|
|
1680
|
+
AND ${edges2.id} IN (${idPlaceholders})
|
|
1916
1681
|
`;
|
|
1917
1682
|
}
|
|
1918
1683
|
function buildUpdateEdge(tables3, params, timestamp2) {
|
|
1919
|
-
const { edges:
|
|
1684
|
+
const { edges: edges2 } = tables3;
|
|
1920
1685
|
const propsJson = JSON.stringify(params.props);
|
|
1921
1686
|
const setParts = [
|
|
1922
|
-
drizzleOrm.sql`${
|
|
1923
|
-
drizzleOrm.sql`${
|
|
1687
|
+
drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(edges2.props)} = ${propsJson}`,
|
|
1688
|
+
drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(edges2.updatedAt)} = ${timestamp2}`
|
|
1924
1689
|
];
|
|
1925
1690
|
if (params.validTo !== void 0) {
|
|
1926
|
-
setParts.push(drizzleOrm.sql`${
|
|
1691
|
+
setParts.push(drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(edges2.validTo)} = ${params.validTo}`);
|
|
1927
1692
|
}
|
|
1928
1693
|
if (params.clearDeleted) {
|
|
1929
|
-
setParts.push(drizzleOrm.sql`${
|
|
1694
|
+
setParts.push(drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(edges2.deletedAt)} = NULL`);
|
|
1930
1695
|
}
|
|
1931
1696
|
const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
|
|
1932
1697
|
if (params.clearDeleted) {
|
|
1933
1698
|
return drizzleOrm.sql`
|
|
1934
|
-
UPDATE ${
|
|
1699
|
+
UPDATE ${edges2}
|
|
1935
1700
|
SET ${setClause}
|
|
1936
|
-
WHERE ${
|
|
1937
|
-
AND ${
|
|
1701
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1702
|
+
AND ${edges2.id} = ${params.id}
|
|
1938
1703
|
RETURNING *
|
|
1939
1704
|
`;
|
|
1940
1705
|
}
|
|
1941
1706
|
return drizzleOrm.sql`
|
|
1942
|
-
UPDATE ${
|
|
1707
|
+
UPDATE ${edges2}
|
|
1943
1708
|
SET ${setClause}
|
|
1944
|
-
WHERE ${
|
|
1945
|
-
AND ${
|
|
1946
|
-
AND ${
|
|
1709
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1710
|
+
AND ${edges2.id} = ${params.id}
|
|
1711
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1947
1712
|
RETURNING *
|
|
1948
1713
|
`;
|
|
1949
1714
|
}
|
|
1950
1715
|
function buildDeleteEdge(tables3, params, timestamp2) {
|
|
1951
|
-
const { edges:
|
|
1716
|
+
const { edges: edges2 } = tables3;
|
|
1952
1717
|
return drizzleOrm.sql`
|
|
1953
|
-
UPDATE ${
|
|
1954
|
-
SET ${
|
|
1955
|
-
WHERE ${
|
|
1956
|
-
AND ${
|
|
1957
|
-
AND ${
|
|
1718
|
+
UPDATE ${edges2}
|
|
1719
|
+
SET ${chunkC2RWFIYP_cjs.quotedColumn(edges2.deletedAt)} = ${timestamp2}
|
|
1720
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1721
|
+
AND ${edges2.id} = ${params.id}
|
|
1722
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1958
1723
|
`;
|
|
1959
1724
|
}
|
|
1960
1725
|
function buildHardDeleteEdge(tables3, params) {
|
|
1961
|
-
const { edges:
|
|
1726
|
+
const { edges: edges2 } = tables3;
|
|
1962
1727
|
return drizzleOrm.sql`
|
|
1963
|
-
DELETE FROM ${
|
|
1964
|
-
WHERE ${
|
|
1965
|
-
AND ${
|
|
1728
|
+
DELETE FROM ${edges2}
|
|
1729
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1730
|
+
AND ${edges2.id} = ${params.id}
|
|
1966
1731
|
`;
|
|
1967
1732
|
}
|
|
1968
1733
|
function buildHardDeleteEdgesByNode(tables3, graphId, nodeKind, nodeId) {
|
|
1969
|
-
const { edges:
|
|
1734
|
+
const { edges: edges2 } = tables3;
|
|
1970
1735
|
return drizzleOrm.sql`
|
|
1971
|
-
DELETE FROM ${
|
|
1972
|
-
WHERE ${
|
|
1736
|
+
DELETE FROM ${edges2}
|
|
1737
|
+
WHERE ${edges2.graphId} = ${graphId}
|
|
1973
1738
|
AND (
|
|
1974
|
-
(${
|
|
1975
|
-
OR (${
|
|
1739
|
+
(${edges2.fromKind} = ${nodeKind} AND ${edges2.fromId} = ${nodeId})
|
|
1740
|
+
OR (${edges2.toKind} = ${nodeKind} AND ${edges2.toId} = ${nodeId})
|
|
1976
1741
|
)
|
|
1977
1742
|
`;
|
|
1978
1743
|
}
|
|
1979
1744
|
function buildCountEdgesFrom(tables3, params) {
|
|
1980
|
-
const { edges:
|
|
1745
|
+
const { edges: edges2 } = tables3;
|
|
1981
1746
|
if (params.activeOnly) {
|
|
1982
1747
|
return drizzleOrm.sql`
|
|
1983
|
-
SELECT COUNT(*) as count FROM ${
|
|
1984
|
-
WHERE ${
|
|
1985
|
-
AND ${
|
|
1986
|
-
AND ${
|
|
1987
|
-
AND ${
|
|
1988
|
-
AND ${
|
|
1989
|
-
AND ${
|
|
1748
|
+
SELECT COUNT(*) as count FROM ${edges2}
|
|
1749
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1750
|
+
AND ${edges2.kind} = ${params.edgeKind}
|
|
1751
|
+
AND ${edges2.fromKind} = ${params.fromKind}
|
|
1752
|
+
AND ${edges2.fromId} = ${params.fromId}
|
|
1753
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1754
|
+
AND ${edges2.validTo} IS NULL
|
|
1990
1755
|
`;
|
|
1991
1756
|
}
|
|
1992
1757
|
return drizzleOrm.sql`
|
|
1993
|
-
SELECT COUNT(*) as count FROM ${
|
|
1994
|
-
WHERE ${
|
|
1995
|
-
AND ${
|
|
1996
|
-
AND ${
|
|
1997
|
-
AND ${
|
|
1998
|
-
AND ${
|
|
1758
|
+
SELECT COUNT(*) as count FROM ${edges2}
|
|
1759
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1760
|
+
AND ${edges2.kind} = ${params.edgeKind}
|
|
1761
|
+
AND ${edges2.fromKind} = ${params.fromKind}
|
|
1762
|
+
AND ${edges2.fromId} = ${params.fromId}
|
|
1763
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1999
1764
|
`;
|
|
2000
1765
|
}
|
|
2001
1766
|
function buildEdgeExistsBetween(tables3, params) {
|
|
2002
|
-
const { edges:
|
|
1767
|
+
const { edges: edges2 } = tables3;
|
|
2003
1768
|
return drizzleOrm.sql`
|
|
2004
|
-
SELECT 1 FROM ${
|
|
2005
|
-
WHERE ${
|
|
2006
|
-
AND ${
|
|
2007
|
-
AND ${
|
|
2008
|
-
AND ${
|
|
2009
|
-
AND ${
|
|
2010
|
-
AND ${
|
|
2011
|
-
AND ${
|
|
1769
|
+
SELECT 1 FROM ${edges2}
|
|
1770
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1771
|
+
AND ${edges2.kind} = ${params.edgeKind}
|
|
1772
|
+
AND ${edges2.fromKind} = ${params.fromKind}
|
|
1773
|
+
AND ${edges2.fromId} = ${params.fromId}
|
|
1774
|
+
AND ${edges2.toKind} = ${params.toKind}
|
|
1775
|
+
AND ${edges2.toId} = ${params.toId}
|
|
1776
|
+
AND ${edges2.deletedAt} IS NULL
|
|
2012
1777
|
LIMIT 1
|
|
2013
1778
|
`;
|
|
2014
1779
|
}
|
|
2015
1780
|
function buildFindEdgesConnectedTo(tables3, params) {
|
|
2016
|
-
const { edges:
|
|
1781
|
+
const { edges: edges2 } = tables3;
|
|
2017
1782
|
return drizzleOrm.sql`
|
|
2018
|
-
SELECT * FROM ${
|
|
2019
|
-
WHERE ${
|
|
2020
|
-
AND ${
|
|
2021
|
-
AND ${
|
|
2022
|
-
AND ${
|
|
1783
|
+
SELECT * FROM ${edges2}
|
|
1784
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1785
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1786
|
+
AND ${edges2.fromKind} = ${params.nodeKind}
|
|
1787
|
+
AND ${edges2.fromId} = ${params.nodeId}
|
|
2023
1788
|
UNION ALL
|
|
2024
|
-
SELECT * FROM ${
|
|
2025
|
-
WHERE ${
|
|
2026
|
-
AND ${
|
|
2027
|
-
AND ${
|
|
2028
|
-
AND ${
|
|
1789
|
+
SELECT * FROM ${edges2}
|
|
1790
|
+
WHERE ${edges2.graphId} = ${params.graphId}
|
|
1791
|
+
AND ${edges2.deletedAt} IS NULL
|
|
1792
|
+
AND ${edges2.toKind} = ${params.nodeKind}
|
|
1793
|
+
AND ${edges2.toId} = ${params.nodeId}
|
|
2029
1794
|
AND NOT (
|
|
2030
|
-
${
|
|
2031
|
-
AND ${
|
|
1795
|
+
${edges2.fromKind} = ${params.nodeKind}
|
|
1796
|
+
AND ${edges2.fromId} = ${params.nodeId}
|
|
2032
1797
|
)
|
|
2033
1798
|
`;
|
|
2034
1799
|
}
|
|
@@ -2038,7 +1803,7 @@ function resolveMode(mode) {
|
|
|
2038
1803
|
function buildFulltextSearch(tableName, params, strategy) {
|
|
2039
1804
|
assertValidSearchParams(params);
|
|
2040
1805
|
const mode = resolveMode(params.mode);
|
|
2041
|
-
const table =
|
|
1806
|
+
const table = chunkC2RWFIYP_cjs.quotedTableName(tableName);
|
|
2042
1807
|
const matchCondition = strategy.matchCondition(
|
|
2043
1808
|
tableName,
|
|
2044
1809
|
params.query,
|
|
@@ -2087,136 +1852,136 @@ function assertValidSearchParams(params) {
|
|
|
2087
1852
|
}
|
|
2088
1853
|
}
|
|
2089
1854
|
function buildInsertNode(tables3, params, timestamp2) {
|
|
2090
|
-
const { nodes:
|
|
1855
|
+
const { nodes: nodes2 } = tables3;
|
|
2091
1856
|
const propsJson = JSON.stringify(params.props);
|
|
2092
|
-
const columns =
|
|
1857
|
+
const columns = chunkC2RWFIYP_cjs.nodeColumnList(nodes2);
|
|
2093
1858
|
return drizzleOrm.sql`
|
|
2094
|
-
INSERT INTO ${
|
|
1859
|
+
INSERT INTO ${nodes2} (${columns})
|
|
2095
1860
|
VALUES (
|
|
2096
1861
|
${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
|
|
2097
|
-
1, ${
|
|
1862
|
+
1, ${chunkC2RWFIYP_cjs.sqlNull(params.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(params.validTo)},
|
|
2098
1863
|
${timestamp2}, ${timestamp2}
|
|
2099
1864
|
)
|
|
2100
1865
|
RETURNING *
|
|
2101
1866
|
`;
|
|
2102
1867
|
}
|
|
2103
1868
|
function buildInsertNodeNoReturn(tables3, params, timestamp2) {
|
|
2104
|
-
const { nodes:
|
|
1869
|
+
const { nodes: nodes2 } = tables3;
|
|
2105
1870
|
const propsJson = JSON.stringify(params.props);
|
|
2106
|
-
const columns =
|
|
1871
|
+
const columns = chunkC2RWFIYP_cjs.nodeColumnList(nodes2);
|
|
2107
1872
|
return drizzleOrm.sql`
|
|
2108
|
-
INSERT INTO ${
|
|
1873
|
+
INSERT INTO ${nodes2} (${columns})
|
|
2109
1874
|
VALUES (
|
|
2110
1875
|
${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
|
|
2111
|
-
1, ${
|
|
1876
|
+
1, ${chunkC2RWFIYP_cjs.sqlNull(params.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(params.validTo)},
|
|
2112
1877
|
${timestamp2}, ${timestamp2}
|
|
2113
1878
|
)
|
|
2114
1879
|
`;
|
|
2115
1880
|
}
|
|
2116
1881
|
function buildInsertNodesBatch(tables3, params, timestamp2) {
|
|
2117
|
-
const { nodes:
|
|
2118
|
-
const columns =
|
|
1882
|
+
const { nodes: nodes2 } = tables3;
|
|
1883
|
+
const columns = chunkC2RWFIYP_cjs.nodeColumnList(nodes2);
|
|
2119
1884
|
const values = params.map((nodeParams) => {
|
|
2120
1885
|
const propsJson = JSON.stringify(nodeParams.props);
|
|
2121
|
-
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${
|
|
1886
|
+
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkC2RWFIYP_cjs.sqlNull(nodeParams.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
|
|
2122
1887
|
});
|
|
2123
1888
|
return drizzleOrm.sql`
|
|
2124
|
-
INSERT INTO ${
|
|
1889
|
+
INSERT INTO ${nodes2} (${columns})
|
|
2125
1890
|
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
2126
1891
|
`;
|
|
2127
1892
|
}
|
|
2128
1893
|
function buildInsertNodesBatchReturning(tables3, params, timestamp2) {
|
|
2129
|
-
const { nodes:
|
|
2130
|
-
const columns =
|
|
1894
|
+
const { nodes: nodes2 } = tables3;
|
|
1895
|
+
const columns = chunkC2RWFIYP_cjs.nodeColumnList(nodes2);
|
|
2131
1896
|
const values = params.map((nodeParams) => {
|
|
2132
1897
|
const propsJson = JSON.stringify(nodeParams.props);
|
|
2133
|
-
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${
|
|
1898
|
+
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${chunkC2RWFIYP_cjs.sqlNull(nodeParams.validFrom)}, ${chunkC2RWFIYP_cjs.sqlNull(nodeParams.validTo)}, ${timestamp2}, ${timestamp2})`;
|
|
2134
1899
|
});
|
|
2135
1900
|
return drizzleOrm.sql`
|
|
2136
|
-
INSERT INTO ${
|
|
1901
|
+
INSERT INTO ${nodes2} (${columns})
|
|
2137
1902
|
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
2138
1903
|
RETURNING *
|
|
2139
1904
|
`;
|
|
2140
1905
|
}
|
|
2141
1906
|
function buildGetNode(tables3, graphId, kind, id) {
|
|
2142
|
-
const { nodes:
|
|
1907
|
+
const { nodes: nodes2 } = tables3;
|
|
2143
1908
|
return drizzleOrm.sql`
|
|
2144
|
-
SELECT * FROM ${
|
|
2145
|
-
WHERE ${
|
|
2146
|
-
AND ${
|
|
2147
|
-
AND ${
|
|
1909
|
+
SELECT * FROM ${nodes2}
|
|
1910
|
+
WHERE ${nodes2.graphId} = ${graphId}
|
|
1911
|
+
AND ${nodes2.kind} = ${kind}
|
|
1912
|
+
AND ${nodes2.id} = ${id}
|
|
2148
1913
|
`;
|
|
2149
1914
|
}
|
|
2150
1915
|
function buildGetNodes(tables3, graphId, kind, ids) {
|
|
2151
|
-
const { nodes:
|
|
1916
|
+
const { nodes: nodes2 } = tables3;
|
|
2152
1917
|
const idPlaceholders = drizzleOrm.sql.join(
|
|
2153
1918
|
ids.map((nodeId) => drizzleOrm.sql`${nodeId}`),
|
|
2154
1919
|
drizzleOrm.sql`, `
|
|
2155
1920
|
);
|
|
2156
1921
|
return drizzleOrm.sql`
|
|
2157
|
-
SELECT * FROM ${
|
|
2158
|
-
WHERE ${
|
|
2159
|
-
AND ${
|
|
2160
|
-
AND ${
|
|
1922
|
+
SELECT * FROM ${nodes2}
|
|
1923
|
+
WHERE ${nodes2.graphId} = ${graphId}
|
|
1924
|
+
AND ${nodes2.kind} = ${kind}
|
|
1925
|
+
AND ${nodes2.id} IN (${idPlaceholders})
|
|
2161
1926
|
`;
|
|
2162
1927
|
}
|
|
2163
1928
|
function buildUpdateNode(tables3, params, timestamp2) {
|
|
2164
|
-
const { nodes:
|
|
1929
|
+
const { nodes: nodes2 } = tables3;
|
|
2165
1930
|
const propsJson = JSON.stringify(params.props);
|
|
2166
1931
|
const setParts = [
|
|
2167
|
-
drizzleOrm.sql`${
|
|
2168
|
-
drizzleOrm.sql`${
|
|
1932
|
+
drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(nodes2.props)} = ${propsJson}`,
|
|
1933
|
+
drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(nodes2.updatedAt)} = ${timestamp2}`
|
|
2169
1934
|
];
|
|
2170
1935
|
if (params.incrementVersion) {
|
|
2171
1936
|
setParts.push(
|
|
2172
|
-
drizzleOrm.sql`${
|
|
1937
|
+
drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(nodes2.version)} = ${chunkC2RWFIYP_cjs.quotedColumn(nodes2.version)} + 1`
|
|
2173
1938
|
);
|
|
2174
1939
|
}
|
|
2175
1940
|
if (params.validTo !== void 0) {
|
|
2176
|
-
setParts.push(drizzleOrm.sql`${
|
|
1941
|
+
setParts.push(drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(nodes2.validTo)} = ${params.validTo}`);
|
|
2177
1942
|
}
|
|
2178
1943
|
if (params.clearDeleted) {
|
|
2179
|
-
setParts.push(drizzleOrm.sql`${
|
|
1944
|
+
setParts.push(drizzleOrm.sql`${chunkC2RWFIYP_cjs.quotedColumn(nodes2.deletedAt)} = NULL`);
|
|
2180
1945
|
}
|
|
2181
1946
|
const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
|
|
2182
1947
|
if (params.clearDeleted) {
|
|
2183
1948
|
return drizzleOrm.sql`
|
|
2184
|
-
UPDATE ${
|
|
1949
|
+
UPDATE ${nodes2}
|
|
2185
1950
|
SET ${setClause}
|
|
2186
|
-
WHERE ${
|
|
2187
|
-
AND ${
|
|
2188
|
-
AND ${
|
|
1951
|
+
WHERE ${nodes2.graphId} = ${params.graphId}
|
|
1952
|
+
AND ${nodes2.kind} = ${params.kind}
|
|
1953
|
+
AND ${nodes2.id} = ${params.id}
|
|
2189
1954
|
RETURNING *
|
|
2190
1955
|
`;
|
|
2191
1956
|
}
|
|
2192
1957
|
return drizzleOrm.sql`
|
|
2193
|
-
UPDATE ${
|
|
1958
|
+
UPDATE ${nodes2}
|
|
2194
1959
|
SET ${setClause}
|
|
2195
|
-
WHERE ${
|
|
2196
|
-
AND ${
|
|
2197
|
-
AND ${
|
|
2198
|
-
AND ${
|
|
1960
|
+
WHERE ${nodes2.graphId} = ${params.graphId}
|
|
1961
|
+
AND ${nodes2.kind} = ${params.kind}
|
|
1962
|
+
AND ${nodes2.id} = ${params.id}
|
|
1963
|
+
AND ${nodes2.deletedAt} IS NULL
|
|
2199
1964
|
RETURNING *
|
|
2200
1965
|
`;
|
|
2201
1966
|
}
|
|
2202
1967
|
function buildDeleteNode(tables3, params, timestamp2) {
|
|
2203
|
-
const { nodes:
|
|
1968
|
+
const { nodes: nodes2 } = tables3;
|
|
2204
1969
|
return drizzleOrm.sql`
|
|
2205
|
-
UPDATE ${
|
|
2206
|
-
SET ${
|
|
2207
|
-
WHERE ${
|
|
2208
|
-
AND ${
|
|
2209
|
-
AND ${
|
|
2210
|
-
AND ${
|
|
1970
|
+
UPDATE ${nodes2}
|
|
1971
|
+
SET ${chunkC2RWFIYP_cjs.quotedColumn(nodes2.deletedAt)} = ${timestamp2}
|
|
1972
|
+
WHERE ${nodes2.graphId} = ${params.graphId}
|
|
1973
|
+
AND ${nodes2.kind} = ${params.kind}
|
|
1974
|
+
AND ${nodes2.id} = ${params.id}
|
|
1975
|
+
AND ${nodes2.deletedAt} IS NULL
|
|
2211
1976
|
`;
|
|
2212
1977
|
}
|
|
2213
1978
|
function buildHardDeleteNode(tables3, params) {
|
|
2214
|
-
const { nodes:
|
|
1979
|
+
const { nodes: nodes2 } = tables3;
|
|
2215
1980
|
return drizzleOrm.sql`
|
|
2216
|
-
DELETE FROM ${
|
|
2217
|
-
WHERE ${
|
|
2218
|
-
AND ${
|
|
2219
|
-
AND ${
|
|
1981
|
+
DELETE FROM ${nodes2}
|
|
1982
|
+
WHERE ${nodes2.graphId} = ${params.graphId}
|
|
1983
|
+
AND ${nodes2.kind} = ${params.kind}
|
|
1984
|
+
AND ${nodes2.id} = ${params.id}
|
|
2220
1985
|
`;
|
|
2221
1986
|
}
|
|
2222
1987
|
function createSchemaDialectStrategy(dialect) {
|
|
@@ -2233,13 +1998,13 @@ var SCHEMA_DIALECT_STRATEGIES = {
|
|
|
2233
1998
|
sqlite: createSchemaDialectStrategy("sqlite")
|
|
2234
1999
|
};
|
|
2235
2000
|
function buildInsertSchema(tables3, params, timestamp2, dialect = "sqlite") {
|
|
2236
|
-
const { schemaVersions:
|
|
2001
|
+
const { schemaVersions: schemaVersions2 } = tables3;
|
|
2237
2002
|
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2238
2003
|
const schemaDocumentJson = JSON.stringify(params.schemaDoc);
|
|
2239
2004
|
const isActiveValue = strategy.booleanLiteral(params.isActive);
|
|
2240
|
-
const columns = drizzleOrm.sql.raw(`"${
|
|
2005
|
+
const columns = drizzleOrm.sql.raw(`"${schemaVersions2.graphId.name}", "${schemaVersions2.version.name}", "${schemaVersions2.schemaHash.name}", "${schemaVersions2.schemaDoc.name}", "${schemaVersions2.createdAt.name}", "${schemaVersions2.isActive.name}"`);
|
|
2241
2006
|
return drizzleOrm.sql`
|
|
2242
|
-
INSERT INTO ${
|
|
2007
|
+
INSERT INTO ${schemaVersions2} (${columns})
|
|
2243
2008
|
VALUES (
|
|
2244
2009
|
${params.graphId}, ${params.version},
|
|
2245
2010
|
${params.schemaHash}, ${schemaDocumentJson},
|
|
@@ -2249,98 +2014,98 @@ function buildInsertSchema(tables3, params, timestamp2, dialect = "sqlite") {
|
|
|
2249
2014
|
`;
|
|
2250
2015
|
}
|
|
2251
2016
|
function buildGetActiveSchema(tables3, graphId, dialect = "sqlite") {
|
|
2252
|
-
const { schemaVersions:
|
|
2017
|
+
const { schemaVersions: schemaVersions2 } = tables3;
|
|
2253
2018
|
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2254
2019
|
return drizzleOrm.sql`
|
|
2255
|
-
SELECT * FROM ${
|
|
2256
|
-
WHERE ${
|
|
2257
|
-
AND ${
|
|
2020
|
+
SELECT * FROM ${schemaVersions2}
|
|
2021
|
+
WHERE ${schemaVersions2.graphId} = ${graphId}
|
|
2022
|
+
AND ${schemaVersions2.isActive} = ${strategy.booleanLiteral(true)}
|
|
2258
2023
|
`;
|
|
2259
2024
|
}
|
|
2260
2025
|
function buildGetSchemaVersion(tables3, graphId, version) {
|
|
2261
|
-
const { schemaVersions:
|
|
2026
|
+
const { schemaVersions: schemaVersions2 } = tables3;
|
|
2262
2027
|
return drizzleOrm.sql`
|
|
2263
|
-
SELECT * FROM ${
|
|
2264
|
-
WHERE ${
|
|
2265
|
-
AND ${
|
|
2028
|
+
SELECT * FROM ${schemaVersions2}
|
|
2029
|
+
WHERE ${schemaVersions2.graphId} = ${graphId}
|
|
2030
|
+
AND ${schemaVersions2.version} = ${version}
|
|
2266
2031
|
`;
|
|
2267
2032
|
}
|
|
2268
2033
|
function buildSetActiveSchema(tables3, graphId, version, dialect = "sqlite") {
|
|
2269
|
-
const { schemaVersions:
|
|
2034
|
+
const { schemaVersions: schemaVersions2 } = tables3;
|
|
2270
2035
|
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2271
2036
|
const deactivateAll = drizzleOrm.sql`
|
|
2272
|
-
UPDATE ${
|
|
2273
|
-
SET ${
|
|
2274
|
-
WHERE ${
|
|
2037
|
+
UPDATE ${schemaVersions2}
|
|
2038
|
+
SET ${chunkC2RWFIYP_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(false)}
|
|
2039
|
+
WHERE ${schemaVersions2.graphId} = ${graphId}
|
|
2275
2040
|
`;
|
|
2276
2041
|
const activateVersion = drizzleOrm.sql`
|
|
2277
|
-
UPDATE ${
|
|
2278
|
-
SET ${
|
|
2279
|
-
WHERE ${
|
|
2280
|
-
AND ${
|
|
2042
|
+
UPDATE ${schemaVersions2}
|
|
2043
|
+
SET ${chunkC2RWFIYP_cjs.quotedColumn(schemaVersions2.isActive)} = ${strategy.booleanLiteral(true)}
|
|
2044
|
+
WHERE ${schemaVersions2.graphId} = ${graphId}
|
|
2045
|
+
AND ${schemaVersions2.version} = ${version}
|
|
2281
2046
|
`;
|
|
2282
2047
|
return { deactivateAll, activateVersion };
|
|
2283
2048
|
}
|
|
2284
2049
|
function buildInsertUniqueSqlite(tables3, params) {
|
|
2285
|
-
const { uniques:
|
|
2286
|
-
const columns = drizzleOrm.sql.raw(`"${
|
|
2287
|
-
const conflictColumns = drizzleOrm.sql.raw(`"${
|
|
2050
|
+
const { uniques: uniques2 } = tables3;
|
|
2051
|
+
const columns = drizzleOrm.sql.raw(`"${uniques2.graphId.name}", "${uniques2.nodeKind.name}", "${uniques2.constraintName.name}", "${uniques2.key.name}", "${uniques2.nodeId.name}", "${uniques2.concreteKind.name}", "${uniques2.deletedAt.name}"`);
|
|
2052
|
+
const conflictColumns = drizzleOrm.sql.raw(`"${uniques2.graphId.name}", "${uniques2.nodeKind.name}", "${uniques2.constraintName.name}", "${uniques2.key.name}"`);
|
|
2288
2053
|
return drizzleOrm.sql`
|
|
2289
|
-
INSERT INTO ${
|
|
2054
|
+
INSERT INTO ${uniques2} (${columns})
|
|
2290
2055
|
VALUES (
|
|
2291
2056
|
${params.graphId}, ${params.nodeKind}, ${params.constraintName},
|
|
2292
2057
|
${params.key}, ${params.nodeId}, ${params.concreteKind}, ${drizzleOrm.sql.raw("NULL")}
|
|
2293
2058
|
)
|
|
2294
2059
|
ON CONFLICT (${conflictColumns})
|
|
2295
2060
|
DO UPDATE SET
|
|
2296
|
-
${
|
|
2297
|
-
WHEN ${
|
|
2298
|
-
WHEN ${
|
|
2299
|
-
ELSE ${
|
|
2061
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} = CASE
|
|
2062
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
|
|
2063
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.nodeId}
|
|
2064
|
+
ELSE ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)}
|
|
2300
2065
|
END,
|
|
2301
|
-
${
|
|
2302
|
-
WHEN ${
|
|
2303
|
-
WHEN ${
|
|
2304
|
-
ELSE ${
|
|
2066
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.concreteKind)} = CASE
|
|
2067
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
|
|
2068
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
|
|
2069
|
+
ELSE ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.concreteKind)}
|
|
2305
2070
|
END,
|
|
2306
|
-
${
|
|
2307
|
-
WHEN ${
|
|
2308
|
-
WHEN ${
|
|
2309
|
-
ELSE ${
|
|
2071
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} = CASE
|
|
2072
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} = ${params.nodeId} THEN NULL
|
|
2073
|
+
WHEN ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} IS NOT NULL THEN NULL
|
|
2074
|
+
ELSE ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)}
|
|
2310
2075
|
END
|
|
2311
|
-
RETURNING ${
|
|
2076
|
+
RETURNING ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} as node_id
|
|
2312
2077
|
`;
|
|
2313
2078
|
}
|
|
2314
2079
|
function buildInsertUniquePostgres(tables3, params) {
|
|
2315
|
-
const { uniques:
|
|
2316
|
-
const columns = drizzleOrm.sql.raw(`"${
|
|
2317
|
-
const conflictColumns = drizzleOrm.sql.raw(`"${
|
|
2318
|
-
const tableName = drizzleOrm.getTableName(
|
|
2080
|
+
const { uniques: uniques2 } = tables3;
|
|
2081
|
+
const columns = drizzleOrm.sql.raw(`"${uniques2.graphId.name}", "${uniques2.nodeKind.name}", "${uniques2.constraintName.name}", "${uniques2.key.name}", "${uniques2.nodeId.name}", "${uniques2.concreteKind.name}", "${uniques2.deletedAt.name}"`);
|
|
2082
|
+
const conflictColumns = drizzleOrm.sql.raw(`"${uniques2.graphId.name}", "${uniques2.nodeKind.name}", "${uniques2.constraintName.name}", "${uniques2.key.name}"`);
|
|
2083
|
+
const tableName = drizzleOrm.getTableName(uniques2);
|
|
2319
2084
|
const existingColumn = (column) => drizzleOrm.sql.raw(`"${tableName}"."${column.name}"`);
|
|
2320
2085
|
return drizzleOrm.sql`
|
|
2321
|
-
INSERT INTO ${
|
|
2086
|
+
INSERT INTO ${uniques2} (${columns})
|
|
2322
2087
|
VALUES (
|
|
2323
2088
|
${params.graphId}, ${params.nodeKind}, ${params.constraintName},
|
|
2324
2089
|
${params.key}, ${params.nodeId}, ${params.concreteKind}, ${drizzleOrm.sql.raw("NULL")}
|
|
2325
2090
|
)
|
|
2326
2091
|
ON CONFLICT (${conflictColumns})
|
|
2327
2092
|
DO UPDATE SET
|
|
2328
|
-
${
|
|
2329
|
-
WHEN ${existingColumn(
|
|
2330
|
-
WHEN ${existingColumn(
|
|
2331
|
-
ELSE ${existingColumn(
|
|
2093
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} = CASE
|
|
2094
|
+
WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
|
|
2095
|
+
WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.nodeId}
|
|
2096
|
+
ELSE ${existingColumn(uniques2.nodeId)}
|
|
2332
2097
|
END,
|
|
2333
|
-
${
|
|
2334
|
-
WHEN ${existingColumn(
|
|
2335
|
-
WHEN ${existingColumn(
|
|
2336
|
-
ELSE ${existingColumn(
|
|
2098
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.concreteKind)} = CASE
|
|
2099
|
+
WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
|
|
2100
|
+
WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
|
|
2101
|
+
ELSE ${existingColumn(uniques2.concreteKind)}
|
|
2337
2102
|
END,
|
|
2338
|
-
${
|
|
2339
|
-
WHEN ${existingColumn(
|
|
2340
|
-
WHEN ${existingColumn(
|
|
2341
|
-
ELSE ${existingColumn(
|
|
2103
|
+
${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} = CASE
|
|
2104
|
+
WHEN ${existingColumn(uniques2.nodeId)} = ${params.nodeId} THEN NULL
|
|
2105
|
+
WHEN ${existingColumn(uniques2.deletedAt)} IS NOT NULL THEN NULL
|
|
2106
|
+
ELSE ${existingColumn(uniques2.deletedAt)}
|
|
2342
2107
|
END
|
|
2343
|
-
RETURNING ${
|
|
2108
|
+
RETURNING ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.nodeId)} as node_id
|
|
2344
2109
|
`;
|
|
2345
2110
|
}
|
|
2346
2111
|
var UNIQUE_INSERT_BUILDERS = {
|
|
@@ -2352,327 +2117,67 @@ function buildInsertUnique(tables3, dialect, params) {
|
|
|
2352
2117
|
return builder(tables3, params);
|
|
2353
2118
|
}
|
|
2354
2119
|
function buildDeleteUnique(tables3, params, timestamp2) {
|
|
2355
|
-
const { uniques:
|
|
2120
|
+
const { uniques: uniques2 } = tables3;
|
|
2356
2121
|
return drizzleOrm.sql`
|
|
2357
|
-
UPDATE ${
|
|
2358
|
-
SET ${
|
|
2359
|
-
WHERE ${
|
|
2360
|
-
AND ${
|
|
2361
|
-
AND ${
|
|
2362
|
-
AND ${
|
|
2363
|
-
AND ${
|
|
2122
|
+
UPDATE ${uniques2}
|
|
2123
|
+
SET ${chunkC2RWFIYP_cjs.quotedColumn(uniques2.deletedAt)} = ${timestamp2}
|
|
2124
|
+
WHERE ${uniques2.graphId} = ${params.graphId}
|
|
2125
|
+
AND ${uniques2.nodeKind} = ${params.nodeKind}
|
|
2126
|
+
AND ${uniques2.constraintName} = ${params.constraintName}
|
|
2127
|
+
AND ${uniques2.key} = ${params.key}
|
|
2128
|
+
AND ${uniques2.deletedAt} IS NULL
|
|
2364
2129
|
`;
|
|
2365
2130
|
}
|
|
2366
2131
|
function buildHardDeleteUniquesByNode(tables3, graphId, nodeId) {
|
|
2367
|
-
const { uniques:
|
|
2132
|
+
const { uniques: uniques2 } = tables3;
|
|
2368
2133
|
return drizzleOrm.sql`
|
|
2369
|
-
DELETE FROM ${
|
|
2370
|
-
WHERE ${
|
|
2371
|
-
AND ${
|
|
2372
|
-
`;
|
|
2373
|
-
}
|
|
2374
|
-
function buildHardDeleteEmbeddingsByNode(tables3, graphId, nodeKind, nodeId) {
|
|
2375
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2376
|
-
return drizzleOrm.sql`
|
|
2377
|
-
DELETE FROM ${embeddings3}
|
|
2378
|
-
WHERE ${embeddings3.graphId} = ${graphId}
|
|
2379
|
-
AND ${embeddings3.nodeKind} = ${nodeKind}
|
|
2380
|
-
AND ${embeddings3.nodeId} = ${nodeId}
|
|
2134
|
+
DELETE FROM ${uniques2}
|
|
2135
|
+
WHERE ${uniques2.graphId} = ${graphId}
|
|
2136
|
+
AND ${uniques2.nodeId} = ${nodeId}
|
|
2381
2137
|
`;
|
|
2382
2138
|
}
|
|
2383
2139
|
function buildCheckUnique(tables3, params) {
|
|
2384
|
-
const { uniques:
|
|
2140
|
+
const { uniques: uniques2 } = tables3;
|
|
2385
2141
|
if (params.includeDeleted) {
|
|
2386
2142
|
return drizzleOrm.sql`
|
|
2387
|
-
SELECT * FROM ${
|
|
2388
|
-
WHERE ${
|
|
2389
|
-
AND ${
|
|
2390
|
-
AND ${
|
|
2391
|
-
AND ${
|
|
2143
|
+
SELECT * FROM ${uniques2}
|
|
2144
|
+
WHERE ${uniques2.graphId} = ${params.graphId}
|
|
2145
|
+
AND ${uniques2.nodeKind} = ${params.nodeKind}
|
|
2146
|
+
AND ${uniques2.constraintName} = ${params.constraintName}
|
|
2147
|
+
AND ${uniques2.key} = ${params.key}
|
|
2392
2148
|
`;
|
|
2393
2149
|
}
|
|
2394
2150
|
return drizzleOrm.sql`
|
|
2395
|
-
SELECT * FROM ${
|
|
2396
|
-
WHERE ${
|
|
2397
|
-
AND ${
|
|
2398
|
-
AND ${
|
|
2399
|
-
AND ${
|
|
2400
|
-
AND ${
|
|
2151
|
+
SELECT * FROM ${uniques2}
|
|
2152
|
+
WHERE ${uniques2.graphId} = ${params.graphId}
|
|
2153
|
+
AND ${uniques2.nodeKind} = ${params.nodeKind}
|
|
2154
|
+
AND ${uniques2.constraintName} = ${params.constraintName}
|
|
2155
|
+
AND ${uniques2.key} = ${params.key}
|
|
2156
|
+
AND ${uniques2.deletedAt} IS NULL
|
|
2401
2157
|
`;
|
|
2402
2158
|
}
|
|
2403
2159
|
function buildCheckUniqueBatch(tables3, params) {
|
|
2404
|
-
const { uniques:
|
|
2160
|
+
const { uniques: uniques2 } = tables3;
|
|
2405
2161
|
const keyPlaceholders = drizzleOrm.sql.join(
|
|
2406
2162
|
params.keys.map((key) => drizzleOrm.sql`${key}`),
|
|
2407
2163
|
drizzleOrm.sql`, `
|
|
2408
2164
|
);
|
|
2409
2165
|
if (params.includeDeleted) {
|
|
2410
2166
|
return drizzleOrm.sql`
|
|
2411
|
-
SELECT * FROM ${
|
|
2412
|
-
WHERE ${
|
|
2413
|
-
AND ${
|
|
2414
|
-
AND ${
|
|
2415
|
-
AND ${
|
|
2167
|
+
SELECT * FROM ${uniques2}
|
|
2168
|
+
WHERE ${uniques2.graphId} = ${params.graphId}
|
|
2169
|
+
AND ${uniques2.nodeKind} = ${params.nodeKind}
|
|
2170
|
+
AND ${uniques2.constraintName} = ${params.constraintName}
|
|
2171
|
+
AND ${uniques2.key} IN (${keyPlaceholders})
|
|
2416
2172
|
`;
|
|
2417
2173
|
}
|
|
2418
2174
|
return drizzleOrm.sql`
|
|
2419
|
-
SELECT * FROM ${
|
|
2420
|
-
WHERE ${
|
|
2421
|
-
AND ${
|
|
2422
|
-
AND ${
|
|
2423
|
-
AND ${
|
|
2424
|
-
AND ${
|
|
2425
|
-
`;
|
|
2426
|
-
}
|
|
2427
|
-
var MAX_HNSW_EF_SEARCH = 1e3;
|
|
2428
|
-
function assertFiniteNumberArray(array, name) {
|
|
2429
|
-
for (const [index3, value] of array.entries()) {
|
|
2430
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
2431
|
-
throw new TypeError(
|
|
2432
|
-
`${name}[${index3}] must be a finite number, got: ${value}`
|
|
2433
|
-
);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
function formatEmbeddingLiteral(embedding) {
|
|
2438
|
-
assertFiniteNumberArray(embedding, "embedding");
|
|
2439
|
-
return `[${embedding.join(",")}]`;
|
|
2440
|
-
}
|
|
2441
|
-
function buildUpsertEmbeddingPostgres(tables3, params, timestamp2) {
|
|
2442
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2443
|
-
const embeddingLiteral = formatEmbeddingLiteral(params.embedding);
|
|
2444
|
-
const columns = drizzleOrm.sql.raw(
|
|
2445
|
-
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}", "${embeddings3.embedding.name}", "${embeddings3.dimensions.name}", "${embeddings3.createdAt.name}", "${embeddings3.updatedAt.name}"`
|
|
2446
|
-
);
|
|
2447
|
-
const conflictColumns = drizzleOrm.sql.raw(
|
|
2448
|
-
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}"`
|
|
2449
|
-
);
|
|
2450
|
-
const column = (target) => drizzleOrm.sql.raw(`"${target.name}"`);
|
|
2451
|
-
return drizzleOrm.sql`
|
|
2452
|
-
INSERT INTO ${embeddings3} (${columns})
|
|
2453
|
-
VALUES (
|
|
2454
|
-
${params.graphId}, ${params.nodeKind}, ${params.nodeId}, ${params.fieldPath},
|
|
2455
|
-
${embeddingLiteral}::vector, ${params.dimensions}, ${timestamp2}, ${timestamp2}
|
|
2456
|
-
)
|
|
2457
|
-
ON CONFLICT (${conflictColumns})
|
|
2458
|
-
DO UPDATE SET
|
|
2459
|
-
${column(embeddings3.embedding)} = ${embeddingLiteral}::vector,
|
|
2460
|
-
${column(embeddings3.dimensions)} = ${params.dimensions},
|
|
2461
|
-
${column(embeddings3.updatedAt)} = ${timestamp2}
|
|
2462
|
-
`;
|
|
2463
|
-
}
|
|
2464
|
-
function buildUpsertEmbeddingSqlite(tables3, params, timestamp2) {
|
|
2465
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2466
|
-
const embeddingJson = JSON.stringify(params.embedding);
|
|
2467
|
-
assertFiniteNumberArray(params.embedding, "embedding");
|
|
2468
|
-
const columns = drizzleOrm.sql.raw(
|
|
2469
|
-
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}", "${embeddings3.embedding.name}", "${embeddings3.dimensions.name}", "${embeddings3.createdAt.name}", "${embeddings3.updatedAt.name}"`
|
|
2470
|
-
);
|
|
2471
|
-
const conflictColumns = drizzleOrm.sql.raw(
|
|
2472
|
-
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}"`
|
|
2473
|
-
);
|
|
2474
|
-
const column = (target) => drizzleOrm.sql.raw(`"${target.name}"`);
|
|
2475
|
-
return drizzleOrm.sql`
|
|
2476
|
-
INSERT INTO ${embeddings3} (${columns})
|
|
2477
|
-
VALUES (
|
|
2478
|
-
${params.graphId}, ${params.nodeKind}, ${params.nodeId}, ${params.fieldPath},
|
|
2479
|
-
vec_f32(${embeddingJson}), ${params.dimensions}, ${timestamp2}, ${timestamp2}
|
|
2480
|
-
)
|
|
2481
|
-
ON CONFLICT (${conflictColumns})
|
|
2482
|
-
DO UPDATE SET
|
|
2483
|
-
${column(embeddings3.embedding)} = vec_f32(${embeddingJson}),
|
|
2484
|
-
${column(embeddings3.dimensions)} = ${params.dimensions},
|
|
2485
|
-
${column(embeddings3.updatedAt)} = ${timestamp2}
|
|
2486
|
-
`;
|
|
2487
|
-
}
|
|
2488
|
-
function buildDeleteEmbedding(tables3, params) {
|
|
2489
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2490
|
-
return drizzleOrm.sql`
|
|
2491
|
-
DELETE FROM ${embeddings3}
|
|
2492
|
-
WHERE ${embeddings3.graphId} = ${params.graphId}
|
|
2493
|
-
AND ${embeddings3.nodeKind} = ${params.nodeKind}
|
|
2494
|
-
AND ${embeddings3.nodeId} = ${params.nodeId}
|
|
2495
|
-
AND ${embeddings3.fieldPath} = ${params.fieldPath}
|
|
2496
|
-
`;
|
|
2497
|
-
}
|
|
2498
|
-
function buildGetEmbedding(tables3, graphId, nodeKind, nodeId, fieldPath) {
|
|
2499
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2500
|
-
return drizzleOrm.sql`
|
|
2501
|
-
SELECT * FROM ${embeddings3}
|
|
2502
|
-
WHERE ${embeddings3.graphId} = ${graphId}
|
|
2503
|
-
AND ${embeddings3.nodeKind} = ${nodeKind}
|
|
2504
|
-
AND ${embeddings3.nodeId} = ${nodeId}
|
|
2505
|
-
AND ${embeddings3.fieldPath} = ${fieldPath}
|
|
2506
|
-
`;
|
|
2507
|
-
}
|
|
2508
|
-
function buildDistanceExpression(embeddingColumn, queryLiteral, metric) {
|
|
2509
|
-
const vectorParameter = drizzleOrm.sql`${queryLiteral}::vector`;
|
|
2510
|
-
switch (metric) {
|
|
2511
|
-
case "cosine": {
|
|
2512
|
-
return drizzleOrm.sql`(${embeddingColumn} <=> ${vectorParameter})`;
|
|
2513
|
-
}
|
|
2514
|
-
case "l2": {
|
|
2515
|
-
return drizzleOrm.sql`(${embeddingColumn} <-> ${vectorParameter})`;
|
|
2516
|
-
}
|
|
2517
|
-
case "inner_product": {
|
|
2518
|
-
return drizzleOrm.sql`(${embeddingColumn} <#> ${vectorParameter})`;
|
|
2519
|
-
}
|
|
2520
|
-
default: {
|
|
2521
|
-
const _exhaustive = metric;
|
|
2522
|
-
throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
function buildVectorSearchScoreExpression(distanceExpression, metric) {
|
|
2527
|
-
switch (metric) {
|
|
2528
|
-
case "cosine": {
|
|
2529
|
-
return drizzleOrm.sql`(1 - (${distanceExpression}))`;
|
|
2530
|
-
}
|
|
2531
|
-
case "l2":
|
|
2532
|
-
case "inner_product": {
|
|
2533
|
-
return distanceExpression;
|
|
2534
|
-
}
|
|
2535
|
-
default: {
|
|
2536
|
-
const _exhaustive = metric;
|
|
2537
|
-
throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
function buildVectorSearchMinScoreCondition(distanceExpression, metric, minScore) {
|
|
2542
|
-
switch (metric) {
|
|
2543
|
-
case "cosine": {
|
|
2544
|
-
const threshold = 1 - minScore;
|
|
2545
|
-
return drizzleOrm.sql`${distanceExpression} <= ${threshold}`;
|
|
2546
|
-
}
|
|
2547
|
-
case "l2": {
|
|
2548
|
-
return drizzleOrm.sql`${distanceExpression} <= ${minScore}`;
|
|
2549
|
-
}
|
|
2550
|
-
case "inner_product": {
|
|
2551
|
-
const negativeThreshold = -minScore;
|
|
2552
|
-
return drizzleOrm.sql`${distanceExpression} <= ${negativeThreshold}`;
|
|
2553
|
-
}
|
|
2554
|
-
default: {
|
|
2555
|
-
const _exhaustive = metric;
|
|
2556
|
-
throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
function assertVectorSearchBounds(params) {
|
|
2561
|
-
if (params.minScore !== void 0 && !Number.isFinite(params.minScore)) {
|
|
2562
|
-
throw new TypeError(
|
|
2563
|
-
`minScore must be a finite number, got: ${params.minScore}`
|
|
2564
|
-
);
|
|
2565
|
-
}
|
|
2566
|
-
if (!Number.isInteger(params.limit) || params.limit <= 0) {
|
|
2567
|
-
throw new Error(`limit must be a positive integer, got: ${params.limit}`);
|
|
2568
|
-
}
|
|
2569
|
-
if (params.efSearch !== void 0 && (!Number.isInteger(params.efSearch) || params.efSearch <= 0)) {
|
|
2570
|
-
throw new Error(
|
|
2571
|
-
`efSearch must be a positive integer, got: ${params.efSearch}`
|
|
2572
|
-
);
|
|
2573
|
-
}
|
|
2574
|
-
}
|
|
2575
|
-
function buildVectorSearchPostgres(tables3, params) {
|
|
2576
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2577
|
-
const queryLiteral = formatEmbeddingLiteral(params.queryEmbedding);
|
|
2578
|
-
assertVectorSearchBounds(params);
|
|
2579
|
-
if (params.efSearch !== void 0 && params.efSearch > MAX_HNSW_EF_SEARCH) {
|
|
2580
|
-
throw new RangeError(
|
|
2581
|
-
`efSearch must be \u2264 ${MAX_HNSW_EF_SEARCH} (pgvector's hnsw.ef_search valid range is 1..${MAX_HNSW_EF_SEARCH}), got: ${params.efSearch}`
|
|
2582
|
-
);
|
|
2583
|
-
}
|
|
2584
|
-
const embeddingColumn = drizzleOrm.sql`${embeddings3.embedding}`;
|
|
2585
|
-
const distanceExpression = buildDistanceExpression(
|
|
2586
|
-
embeddingColumn,
|
|
2587
|
-
queryLiteral,
|
|
2588
|
-
params.metric
|
|
2589
|
-
);
|
|
2590
|
-
const conditions = [
|
|
2591
|
-
drizzleOrm.sql`${embeddings3.graphId} = ${params.graphId}`,
|
|
2592
|
-
drizzleOrm.sql`${embeddings3.nodeKind} = ${params.nodeKind}`,
|
|
2593
|
-
drizzleOrm.sql`${embeddings3.fieldPath} = ${params.fieldPath}`
|
|
2594
|
-
];
|
|
2595
|
-
if (params.minScore !== void 0) {
|
|
2596
|
-
conditions.push(
|
|
2597
|
-
buildVectorSearchMinScoreCondition(
|
|
2598
|
-
distanceExpression,
|
|
2599
|
-
params.metric,
|
|
2600
|
-
params.minScore
|
|
2601
|
-
)
|
|
2602
|
-
);
|
|
2603
|
-
}
|
|
2604
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
2605
|
-
const scoreExpression = buildVectorSearchScoreExpression(
|
|
2606
|
-
distanceExpression,
|
|
2607
|
-
params.metric
|
|
2608
|
-
);
|
|
2609
|
-
return drizzleOrm.sql`
|
|
2610
|
-
SELECT
|
|
2611
|
-
${embeddings3.nodeId} as node_id,
|
|
2612
|
-
${scoreExpression} as score
|
|
2613
|
-
FROM ${embeddings3}
|
|
2614
|
-
WHERE ${whereClause}
|
|
2615
|
-
ORDER BY ${distanceExpression} ASC
|
|
2616
|
-
LIMIT ${params.limit}
|
|
2617
|
-
`;
|
|
2618
|
-
}
|
|
2619
|
-
function buildSqliteDistanceExpression(embeddingColumn, embeddingJson, metric) {
|
|
2620
|
-
switch (metric) {
|
|
2621
|
-
case "cosine": {
|
|
2622
|
-
return drizzleOrm.sql`vec_distance_cosine(${embeddingColumn}, vec_f32(${embeddingJson}))`;
|
|
2623
|
-
}
|
|
2624
|
-
case "l2": {
|
|
2625
|
-
return drizzleOrm.sql`vec_distance_l2(${embeddingColumn}, vec_f32(${embeddingJson}))`;
|
|
2626
|
-
}
|
|
2627
|
-
case "inner_product": {
|
|
2628
|
-
throw new Error(
|
|
2629
|
-
"Inner product distance is not supported by sqlite-vec. Use 'cosine' or 'l2' metrics instead."
|
|
2630
|
-
);
|
|
2631
|
-
}
|
|
2632
|
-
default: {
|
|
2633
|
-
const _exhaustive = metric;
|
|
2634
|
-
throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
function buildVectorSearchSqlite(tables3, params) {
|
|
2639
|
-
const { embeddings: embeddings3 } = tables3;
|
|
2640
|
-
assertFiniteNumberArray(params.queryEmbedding, "queryEmbedding");
|
|
2641
|
-
const embeddingJson = JSON.stringify(params.queryEmbedding);
|
|
2642
|
-
assertVectorSearchBounds(params);
|
|
2643
|
-
const embeddingColumn = drizzleOrm.sql`${embeddings3.embedding}`;
|
|
2644
|
-
const distanceExpression = buildSqliteDistanceExpression(
|
|
2645
|
-
embeddingColumn,
|
|
2646
|
-
embeddingJson,
|
|
2647
|
-
params.metric
|
|
2648
|
-
);
|
|
2649
|
-
const conditions = [
|
|
2650
|
-
drizzleOrm.sql`${embeddings3.graphId} = ${params.graphId}`,
|
|
2651
|
-
drizzleOrm.sql`${embeddings3.nodeKind} = ${params.nodeKind}`,
|
|
2652
|
-
drizzleOrm.sql`${embeddings3.fieldPath} = ${params.fieldPath}`
|
|
2653
|
-
];
|
|
2654
|
-
if (params.minScore !== void 0) {
|
|
2655
|
-
conditions.push(
|
|
2656
|
-
buildVectorSearchMinScoreCondition(
|
|
2657
|
-
distanceExpression,
|
|
2658
|
-
params.metric,
|
|
2659
|
-
params.minScore
|
|
2660
|
-
)
|
|
2661
|
-
);
|
|
2662
|
-
}
|
|
2663
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
2664
|
-
const scoreExpression = buildVectorSearchScoreExpression(
|
|
2665
|
-
distanceExpression,
|
|
2666
|
-
params.metric
|
|
2667
|
-
);
|
|
2668
|
-
return drizzleOrm.sql`
|
|
2669
|
-
SELECT
|
|
2670
|
-
${embeddings3.nodeId} as node_id,
|
|
2671
|
-
${scoreExpression} as score
|
|
2672
|
-
FROM ${embeddings3}
|
|
2673
|
-
WHERE ${whereClause}
|
|
2674
|
-
ORDER BY ${distanceExpression} ASC
|
|
2675
|
-
LIMIT ${params.limit}
|
|
2175
|
+
SELECT * FROM ${uniques2}
|
|
2176
|
+
WHERE ${uniques2.graphId} = ${params.graphId}
|
|
2177
|
+
AND ${uniques2.nodeKind} = ${params.nodeKind}
|
|
2178
|
+
AND ${uniques2.constraintName} = ${params.constraintName}
|
|
2179
|
+
AND ${uniques2.key} IN (${keyPlaceholders})
|
|
2180
|
+
AND ${uniques2.deletedAt} IS NULL
|
|
2676
2181
|
`;
|
|
2677
2182
|
}
|
|
2678
2183
|
|
|
@@ -2715,7 +2220,6 @@ var COMMON_TABLE_OPERATION_BUILDERS = {
|
|
|
2715
2220
|
buildCountEdgesByKind,
|
|
2716
2221
|
buildDeleteUnique,
|
|
2717
2222
|
buildHardDeleteUniquesByNode,
|
|
2718
|
-
buildHardDeleteEmbeddingsByNode,
|
|
2719
2223
|
buildCheckUnique,
|
|
2720
2224
|
buildCheckUniqueBatch,
|
|
2721
2225
|
buildGetSchemaVersion
|
|
@@ -2759,221 +2263,10 @@ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
|
|
|
2759
2263
|
};
|
|
2760
2264
|
}
|
|
2761
2265
|
function createSqliteOperationStrategy(tables3, fulltextStrategy) {
|
|
2762
|
-
|
|
2763
|
-
tables3,
|
|
2764
|
-
"sqlite",
|
|
2765
|
-
fulltextStrategy
|
|
2766
|
-
);
|
|
2767
|
-
return {
|
|
2768
|
-
...common,
|
|
2769
|
-
buildUpsertEmbedding(params, timestamp2) {
|
|
2770
|
-
return buildUpsertEmbeddingSqlite(tables3, params, timestamp2);
|
|
2771
|
-
},
|
|
2772
|
-
buildDeleteEmbedding(params) {
|
|
2773
|
-
return buildDeleteEmbedding(tables3, params);
|
|
2774
|
-
},
|
|
2775
|
-
buildVectorSearch(params) {
|
|
2776
|
-
return buildVectorSearchSqlite(tables3, params);
|
|
2777
|
-
}
|
|
2778
|
-
};
|
|
2266
|
+
return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
|
|
2779
2267
|
}
|
|
2780
2268
|
function createPostgresOperationStrategy(tables3, fulltextStrategy) {
|
|
2781
|
-
|
|
2782
|
-
tables3,
|
|
2783
|
-
"postgres",
|
|
2784
|
-
fulltextStrategy
|
|
2785
|
-
);
|
|
2786
|
-
return {
|
|
2787
|
-
...common,
|
|
2788
|
-
buildUpsertEmbedding(params, timestamp2) {
|
|
2789
|
-
return buildUpsertEmbeddingPostgres(tables3, params, timestamp2);
|
|
2790
|
-
},
|
|
2791
|
-
buildDeleteEmbedding(params) {
|
|
2792
|
-
return buildDeleteEmbedding(tables3, params);
|
|
2793
|
-
},
|
|
2794
|
-
buildGetEmbedding(graphId, nodeKind, nodeId, fieldPath) {
|
|
2795
|
-
return buildGetEmbedding(tables3, graphId, nodeKind, nodeId, fieldPath);
|
|
2796
|
-
},
|
|
2797
|
-
buildVectorSearch(params) {
|
|
2798
|
-
return buildVectorSearchPostgres(tables3, params);
|
|
2799
|
-
}
|
|
2800
|
-
};
|
|
2801
|
-
}
|
|
2802
|
-
function assertPositiveInteger(value, name) {
|
|
2803
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
2804
|
-
throw new Error(`${name} must be a positive integer, got: ${value}`);
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
function assertSafeIdentifier(value, name) {
|
|
2808
|
-
if (!/^[a-z0-9_]+$/i.test(value)) {
|
|
2809
|
-
throw new Error(
|
|
2810
|
-
`${name} must contain only alphanumeric characters and underscores, got: ${value}`
|
|
2811
|
-
);
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
function sanitizeIdentifier(s) {
|
|
2815
|
-
return s.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
|
|
2816
|
-
}
|
|
2817
|
-
function quoteIdentifier(value) {
|
|
2818
|
-
return `"${value.replaceAll('"', '""')}"`;
|
|
2819
|
-
}
|
|
2820
|
-
function shortHash(input) {
|
|
2821
|
-
let h1 = 3735928559;
|
|
2822
|
-
let h2 = 1103547991;
|
|
2823
|
-
for (let index3 = 0; index3 < input.length; index3++) {
|
|
2824
|
-
const ch = input.codePointAt(index3);
|
|
2825
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
2826
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
2827
|
-
}
|
|
2828
|
-
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
2829
|
-
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
2830
|
-
const hi = (h2 >>> 0).toString(16).padStart(8, "0");
|
|
2831
|
-
const lo = (h1 >>> 0).toString(16).padStart(8, "0");
|
|
2832
|
-
return `${hi}${lo}`.slice(0, 8);
|
|
2833
|
-
}
|
|
2834
|
-
function generateVectorIndexName(graphId, nodeKind, fieldPath, metric = "cosine") {
|
|
2835
|
-
const parts = [
|
|
2836
|
-
"idx_emb",
|
|
2837
|
-
sanitizeIdentifier(graphId),
|
|
2838
|
-
sanitizeIdentifier(nodeKind),
|
|
2839
|
-
sanitizeIdentifier(fieldPath),
|
|
2840
|
-
metric
|
|
2841
|
-
];
|
|
2842
|
-
const name = parts.join("_");
|
|
2843
|
-
if (name.length <= chunkCTHNVU6K_cjs.MAX_PG_IDENTIFIER_LENGTH) {
|
|
2844
|
-
return name;
|
|
2845
|
-
}
|
|
2846
|
-
const hash = shortHash(name);
|
|
2847
|
-
const truncated = name.slice(0, chunkCTHNVU6K_cjs.MAX_PG_IDENTIFIER_LENGTH - 1 - hash.length);
|
|
2848
|
-
return `${truncated}_${hash}`;
|
|
2849
|
-
}
|
|
2850
|
-
function getOperatorClass(metric) {
|
|
2851
|
-
switch (metric) {
|
|
2852
|
-
case "cosine": {
|
|
2853
|
-
return "vector_cosine_ops";
|
|
2854
|
-
}
|
|
2855
|
-
case "l2": {
|
|
2856
|
-
return "vector_l2_ops";
|
|
2857
|
-
}
|
|
2858
|
-
case "inner_product": {
|
|
2859
|
-
return "vector_ip_ops";
|
|
2860
|
-
}
|
|
2861
|
-
default: {
|
|
2862
|
-
const _exhaustive = metric;
|
|
2863
|
-
throw new Error("Unsupported vector metric: " + String(_exhaustive));
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
}
|
|
2867
|
-
function escapeSqlString(value) {
|
|
2868
|
-
const tag = `tg${crypto.randomUUID().replaceAll("-", "").slice(0, 8)}`;
|
|
2869
|
-
return `$${tag}$${value}$${tag}$`;
|
|
2870
|
-
}
|
|
2871
|
-
async function createPostgresVectorIndex(db, options) {
|
|
2872
|
-
const {
|
|
2873
|
-
graphId,
|
|
2874
|
-
nodeKind,
|
|
2875
|
-
fieldPath,
|
|
2876
|
-
dimensions,
|
|
2877
|
-
embeddingsTableName = "typegraph_node_embeddings",
|
|
2878
|
-
indexType = "hnsw",
|
|
2879
|
-
metric = "cosine",
|
|
2880
|
-
hnswM = 16,
|
|
2881
|
-
hnswEfConstruction = 64,
|
|
2882
|
-
ivfflatLists = 100
|
|
2883
|
-
} = options;
|
|
2884
|
-
assertPositiveInteger(dimensions, "dimensions");
|
|
2885
|
-
assertPositiveInteger(hnswM, "hnswM");
|
|
2886
|
-
assertPositiveInteger(hnswEfConstruction, "hnswEfConstruction");
|
|
2887
|
-
assertPositiveInteger(ivfflatLists, "ivfflatLists");
|
|
2888
|
-
const indexName = generateVectorIndexName(graphId, nodeKind, fieldPath, metric);
|
|
2889
|
-
const operatorClass = getOperatorClass(metric);
|
|
2890
|
-
const quotedEmbeddingsTableName = quoteIdentifier(embeddingsTableName);
|
|
2891
|
-
assertSafeIdentifier(indexName, "indexName");
|
|
2892
|
-
const safeGraphId = escapeSqlString(graphId);
|
|
2893
|
-
const safeNodeKind = escapeSqlString(nodeKind);
|
|
2894
|
-
const safeFieldPath = escapeSqlString(fieldPath);
|
|
2895
|
-
let indexSql;
|
|
2896
|
-
const concurrentClause = options.concurrent === true ? "CONCURRENTLY " : "";
|
|
2897
|
-
if (indexType === "hnsw") {
|
|
2898
|
-
indexSql = drizzleOrm.sql.raw(`
|
|
2899
|
-
CREATE INDEX ${concurrentClause}IF NOT EXISTS ${indexName}
|
|
2900
|
-
ON ${quotedEmbeddingsTableName}
|
|
2901
|
-
USING hnsw ((embedding::vector(${dimensions})) ${operatorClass})
|
|
2902
|
-
WITH (m = ${hnswM}, ef_construction = ${hnswEfConstruction})
|
|
2903
|
-
WHERE graph_id = ${safeGraphId}
|
|
2904
|
-
AND node_kind = ${safeNodeKind}
|
|
2905
|
-
AND field_path = ${safeFieldPath}
|
|
2906
|
-
`);
|
|
2907
|
-
} else if (indexType === "ivfflat") {
|
|
2908
|
-
indexSql = drizzleOrm.sql.raw(`
|
|
2909
|
-
CREATE INDEX ${concurrentClause}IF NOT EXISTS ${indexName}
|
|
2910
|
-
ON ${quotedEmbeddingsTableName}
|
|
2911
|
-
USING ivfflat ((embedding::vector(${dimensions})) ${operatorClass})
|
|
2912
|
-
WITH (lists = ${ivfflatLists})
|
|
2913
|
-
WHERE graph_id = ${safeGraphId}
|
|
2914
|
-
AND node_kind = ${safeNodeKind}
|
|
2915
|
-
AND field_path = ${safeFieldPath}
|
|
2916
|
-
`);
|
|
2917
|
-
} else {
|
|
2918
|
-
return {
|
|
2919
|
-
indexName,
|
|
2920
|
-
success: true,
|
|
2921
|
-
message: `Index type "${indexType}" not supported, skipping index creation`
|
|
2922
|
-
};
|
|
2923
|
-
}
|
|
2924
|
-
try {
|
|
2925
|
-
await db.execute(indexSql);
|
|
2926
|
-
return {
|
|
2927
|
-
indexName,
|
|
2928
|
-
success: true,
|
|
2929
|
-
message: `Created ${indexType.toUpperCase()} index "${indexName}" for ${nodeKind}.${fieldPath}`
|
|
2930
|
-
};
|
|
2931
|
-
} catch (error) {
|
|
2932
|
-
return {
|
|
2933
|
-
indexName,
|
|
2934
|
-
success: false,
|
|
2935
|
-
message: `Failed to create index: ${error instanceof Error ? error.message : String(error)}`
|
|
2936
|
-
};
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
async function dropPostgresVectorIndex(db, indexName) {
|
|
2940
|
-
assertSafeIdentifier(indexName, "indexName");
|
|
2941
|
-
try {
|
|
2942
|
-
const dropSql = drizzleOrm.sql.raw(`DROP INDEX IF EXISTS ${indexName}`);
|
|
2943
|
-
await db.execute(dropSql);
|
|
2944
|
-
return {
|
|
2945
|
-
indexName,
|
|
2946
|
-
success: true,
|
|
2947
|
-
message: `Dropped index "${indexName}"`
|
|
2948
|
-
};
|
|
2949
|
-
} catch (error) {
|
|
2950
|
-
return {
|
|
2951
|
-
indexName,
|
|
2952
|
-
success: false,
|
|
2953
|
-
message: `Failed to drop index: ${error instanceof Error ? error.message : String(error)}`
|
|
2954
|
-
};
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
function createSqliteVectorIndex(_options) {
|
|
2958
|
-
const indexName = generateVectorIndexName(
|
|
2959
|
-
_options.graphId,
|
|
2960
|
-
_options.nodeKind,
|
|
2961
|
-
_options.fieldPath,
|
|
2962
|
-
_options.metric
|
|
2963
|
-
);
|
|
2964
|
-
return {
|
|
2965
|
-
indexName,
|
|
2966
|
-
success: true,
|
|
2967
|
-
message: "SQLite/sqlite-vec uses optimized internal indexing, no explicit index needed"
|
|
2968
|
-
};
|
|
2969
|
-
}
|
|
2970
|
-
function dropSqliteVectorIndex(graphId, nodeKind, fieldPath, metric = "cosine") {
|
|
2971
|
-
const indexName = generateVectorIndexName(graphId, nodeKind, fieldPath, metric);
|
|
2972
|
-
return {
|
|
2973
|
-
indexName,
|
|
2974
|
-
success: true,
|
|
2975
|
-
message: "SQLite/sqlite-vec does not use explicit indexes"
|
|
2976
|
-
};
|
|
2269
|
+
return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
|
|
2977
2270
|
}
|
|
2978
2271
|
|
|
2979
2272
|
// src/backend/drizzle/execution/lru.ts
|
|
@@ -3026,19 +2319,11 @@ exports.createEdgeRowMapper = createEdgeRowMapper;
|
|
|
3026
2319
|
exports.createNodeRowMapper = createNodeRowMapper;
|
|
3027
2320
|
exports.createPostgresOperationStrategy = createPostgresOperationStrategy;
|
|
3028
2321
|
exports.createPostgresTables = createPostgresTables;
|
|
3029
|
-
exports.createPostgresVectorIndex = createPostgresVectorIndex;
|
|
3030
2322
|
exports.createSchemaVersionRowMapper = createSchemaVersionRowMapper;
|
|
3031
2323
|
exports.createSqliteOperationStrategy = createSqliteOperationStrategy;
|
|
3032
|
-
exports.createSqliteTables = createSqliteTables;
|
|
3033
|
-
exports.createSqliteVectorIndex = createSqliteVectorIndex;
|
|
3034
2324
|
exports.createUniqueRowMapper = createUniqueRowMapper;
|
|
3035
|
-
exports.
|
|
3036
|
-
exports.dropSqliteVectorIndex = dropSqliteVectorIndex;
|
|
2325
|
+
exports.createVectorSlotLatch = createVectorSlotLatch;
|
|
3037
2326
|
exports.edges = edges;
|
|
3038
|
-
exports.edges2 = edges2;
|
|
3039
|
-
exports.embeddings = embeddings;
|
|
3040
|
-
exports.embeddings2 = embeddings2;
|
|
3041
|
-
exports.formatPostgresTimestamp = formatPostgresTimestamp;
|
|
3042
2327
|
exports.fulltext = fulltext;
|
|
3043
2328
|
exports.gateFulltext = gateFulltext;
|
|
3044
2329
|
exports.gateFulltextMethods = gateFulltextMethods;
|
|
@@ -3048,19 +2333,18 @@ exports.generatePostgresMigrationSQL = generatePostgresMigrationSQL;
|
|
|
3048
2333
|
exports.generateSqliteCreateTableSQL = generateSqliteCreateTableSQL;
|
|
3049
2334
|
exports.generateSqliteDDL = generateSqliteDDL;
|
|
3050
2335
|
exports.generateSqliteMigrationSQL = generateSqliteMigrationSQL;
|
|
3051
|
-
exports.generateVectorIndexName = generateVectorIndexName;
|
|
3052
2336
|
exports.getOrCreateLru = getOrCreateLru;
|
|
3053
2337
|
exports.mapContributionMaterializationRow = mapContributionMaterializationRow;
|
|
3054
2338
|
exports.mapKindRemovalRow = mapKindRemovalRow;
|
|
3055
2339
|
exports.mapMaterializationRow = mapMaterializationRow;
|
|
2340
|
+
exports.mapVectorWriteError = mapVectorWriteError;
|
|
3056
2341
|
exports.nodes = nodes;
|
|
3057
|
-
exports.nodes2 = nodes2;
|
|
3058
2342
|
exports.nowIso = nowIso;
|
|
3059
2343
|
exports.schemaVersions = schemaVersions;
|
|
3060
|
-
exports.
|
|
3061
|
-
exports.tables = tables;
|
|
3062
|
-
exports.tables2 = tables2;
|
|
2344
|
+
exports.tables = tables2;
|
|
3063
2345
|
exports.uniques = uniques;
|
|
3064
|
-
exports.
|
|
3065
|
-
|
|
3066
|
-
|
|
2346
|
+
exports.vectorSlotFromCreateIndexParams = vectorSlotFromCreateIndexParams;
|
|
2347
|
+
exports.vectorSlotFromDropIndexParams = vectorSlotFromDropIndexParams;
|
|
2348
|
+
exports.vectorSlotFromParams = vectorSlotFromParams;
|
|
2349
|
+
//# sourceMappingURL=chunk-ZYQEXGYC.cjs.map
|
|
2350
|
+
//# sourceMappingURL=chunk-ZYQEXGYC.cjs.map
|