@nicia-ai/typegraph 0.31.0 → 0.33.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/README.md +31 -0
- package/dist/backend/postgres/index.cjs +31 -18
- package/dist/backend/postgres/index.d.cts +6 -6
- package/dist/backend/postgres/index.d.ts +6 -6
- package/dist/backend/postgres/index.js +9 -8
- package/dist/backend/postgres/pglite.cjs +13 -12
- package/dist/backend/postgres/pglite.cjs.map +1 -1
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +9 -8
- package/dist/backend/postgres/pglite.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +29 -16
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +8 -7
- package/dist/backend/sqlite/libsql.cjs +13 -12
- 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 +9 -8
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +14 -13
- 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 +9 -8
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-SFFJ2IKN.cjs → chunk-3642VBVC.cjs} +70 -68
- package/dist/chunk-3642VBVC.cjs.map +1 -0
- package/dist/chunk-3E7SNSIA.cjs +55 -0
- package/dist/chunk-3E7SNSIA.cjs.map +1 -0
- package/dist/{chunk-6RMLO5O4.cjs → chunk-3IR2GEMJ.cjs} +8 -7
- package/dist/chunk-3IR2GEMJ.cjs.map +1 -0
- package/dist/{chunk-6SA7UIQJ.cjs → chunk-3QRBXYT5.cjs} +6 -6
- package/dist/{chunk-6SA7UIQJ.cjs.map → chunk-3QRBXYT5.cjs.map} +1 -1
- package/dist/{chunk-54JVNOAQ.cjs → chunk-4RBAJVEC.cjs} +128 -6
- package/dist/chunk-4RBAJVEC.cjs.map +1 -0
- package/dist/{chunk-IJORSAC3.js → chunk-6NRFUHMS.js} +4 -3
- package/dist/chunk-6NRFUHMS.js.map +1 -0
- package/dist/{chunk-FLOI7QOT.cjs → chunk-BF3ZDEUE.cjs} +104 -72
- package/dist/chunk-BF3ZDEUE.cjs.map +1 -0
- package/dist/{chunk-2HZGWCB4.js → chunk-C4C4Q7A6.js} +3 -3
- package/dist/chunk-C4C4Q7A6.js.map +1 -0
- package/dist/{chunk-O4VUR6SI.js → chunk-CEF2QOTO.js} +3 -3
- package/dist/{chunk-O4VUR6SI.js.map → chunk-CEF2QOTO.js.map} +1 -1
- package/dist/{chunk-V4IQYOQ4.cjs → chunk-CFNT3ITG.cjs} +3 -3
- package/dist/chunk-CFNT3ITG.cjs.map +1 -0
- package/dist/{chunk-LJLMDDCW.js → chunk-CWFPJ3RC.js} +3 -3
- package/dist/{chunk-LJLMDDCW.js.map → chunk-CWFPJ3RC.js.map} +1 -1
- package/dist/{chunk-RZ4DH4E7.cjs → chunk-D3EWZ67S.cjs} +3348 -2030
- package/dist/chunk-D3EWZ67S.cjs.map +1 -0
- package/dist/{chunk-GKFWM3DS.js → chunk-DJYRRDHA.js} +124 -5
- package/dist/chunk-DJYRRDHA.js.map +1 -0
- package/dist/{chunk-YQGLVWB2.cjs → chunk-EF3Z645U.cjs} +2 -52
- package/dist/chunk-EF3Z645U.cjs.map +1 -0
- package/dist/{chunk-ASYQDPPU.cjs → chunk-FDN43KXV.cjs} +19 -19
- package/dist/{chunk-ASYQDPPU.cjs.map → chunk-FDN43KXV.cjs.map} +1 -1
- package/dist/chunk-GYVBEZAO.js +120 -0
- package/dist/chunk-GYVBEZAO.js.map +1 -0
- package/dist/chunk-I4W7MKVG.cjs +1526 -0
- package/dist/chunk-I4W7MKVG.cjs.map +1 -0
- package/dist/{chunk-MXE2U3EX.js → chunk-IZ4PCL47.js} +3 -52
- package/dist/chunk-IZ4PCL47.js.map +1 -0
- package/dist/{chunk-4A4GUZTQ.js → chunk-JHOBXD7O.js} +10 -8
- package/dist/chunk-JHOBXD7O.js.map +1 -0
- package/dist/{chunk-CIINW6PS.cjs → chunk-KY5SDVA7.cjs} +676 -635
- package/dist/chunk-KY5SDVA7.cjs.map +1 -0
- package/dist/{chunk-N2MBPTAF.cjs → chunk-LM2IC4ZJ.cjs} +14 -14
- package/dist/{chunk-N2MBPTAF.cjs.map → chunk-LM2IC4ZJ.cjs.map} +1 -1
- package/dist/{chunk-7JGLPAFV.cjs → chunk-MBLXCV2Y.cjs} +16 -16
- package/dist/chunk-MBLXCV2Y.cjs.map +1 -0
- package/dist/{chunk-5DTPBFX5.cjs → chunk-NG5N7R45.cjs} +28 -28
- package/dist/{chunk-5DTPBFX5.cjs.map → chunk-NG5N7R45.cjs.map} +1 -1
- package/dist/chunk-OIE2UPVG.cjs +126 -0
- package/dist/chunk-OIE2UPVG.cjs.map +1 -0
- package/dist/{chunk-STP7QVUB.js → chunk-OS6KS3HV.js} +43 -11
- package/dist/chunk-OS6KS3HV.js.map +1 -0
- package/dist/{chunk-2ZY4K43M.js → chunk-PIHXFF73.js} +3 -3
- package/dist/{chunk-2ZY4K43M.js.map → chunk-PIHXFF73.js.map} +1 -1
- package/dist/{chunk-ATTXBMAX.js → chunk-PRMKPFN5.js} +3 -3
- package/dist/{chunk-ATTXBMAX.js.map → chunk-PRMKPFN5.js.map} +1 -1
- package/dist/chunk-PYD3UCDU.js +1480 -0
- package/dist/chunk-PYD3UCDU.js.map +1 -0
- package/dist/{chunk-MAQJYNJR.js → chunk-QBYTJSAY.js} +14 -16
- package/dist/chunk-QBYTJSAY.js.map +1 -0
- package/dist/{chunk-THX25XW6.js → chunk-SPT5JMME.js} +27 -7
- package/dist/chunk-SPT5JMME.js.map +1 -0
- package/dist/{chunk-3JBJEYWE.cjs → chunk-SST7XDY6.cjs} +32 -12
- package/dist/chunk-SST7XDY6.cjs.map +1 -0
- package/dist/{chunk-VZX2KSY3.js → chunk-UPDMJEW6.js} +608 -563
- package/dist/chunk-UPDMJEW6.js.map +1 -0
- package/dist/{chunk-UIFEEPME.js → chunk-WLP6TKFB.js} +3141 -1823
- package/dist/chunk-WLP6TKFB.js.map +1 -0
- package/dist/{chunk-VMEWZU2N.cjs → chunk-WWVV44DY.cjs} +11 -11
- package/dist/{chunk-VMEWZU2N.cjs.map → chunk-WWVV44DY.cjs.map} +1 -1
- package/dist/{chunk-UJ4V3YUQ.js → chunk-XKNAK27R.js} +3 -3
- package/dist/{chunk-UJ4V3YUQ.js.map → chunk-XKNAK27R.js.map} +1 -1
- package/dist/chunk-XLUNB2TZ.js +53 -0
- package/dist/chunk-XLUNB2TZ.js.map +1 -0
- package/dist/{chunk-XKJQQQVR.js → chunk-XVUJY72M.js} +6 -6
- package/dist/{chunk-XKJQQQVR.js.map → chunk-XVUJY72M.js.map} +1 -1
- package/dist/{chunk-5CN7B4CZ.cjs → chunk-YW7GHMF4.cjs} +17 -17
- package/dist/{chunk-5CN7B4CZ.cjs.map → chunk-YW7GHMF4.cjs.map} +1 -1
- package/dist/{ddl-BJcPrB4L.d.ts → ddl-CVnHJcar.d.ts} +3 -3
- package/dist/{ddl-CPZ7mB7X.d.cts → ddl-Dxt_fBHr.d.cts} +3 -3
- package/dist/{extension-types-D1k0inWU.d.cts → extension-types-YGFJPrzK.d.cts} +1 -1
- package/dist/{extension-types-D1k0inWU.d.ts → extension-types-YGFJPrzK.d.ts} +1 -1
- package/dist/graph-extension/index.d.cts +4 -4
- package/dist/graph-extension/index.d.ts +4 -4
- package/dist/graph-merge/index.cjs +200 -55
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +6 -6
- package/dist/graph-merge/index.d.ts +6 -6
- package/dist/graph-merge/index.js +185 -40
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/{index-BEK0VtNB.d.ts → index-DGX6D9j1.d.ts} +2 -2
- package/dist/{index-C8sSTErx.d.cts → index-SEvUHDA6.d.cts} +2 -2
- package/dist/index.cjs +145 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -55
- package/dist/index.d.ts +25 -55
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +15 -14
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +6 -5
- package/dist/interchange/index.cjs +15 -15
- package/dist/interchange/index.d.cts +9 -9
- package/dist/interchange/index.d.ts +9 -9
- package/dist/interchange/index.js +2 -2
- package/dist/{manager-Np7VVSlE.d.cts → manager-BYl_zyZR.d.cts} +2 -2
- package/dist/{manager-By-WEd8M.d.ts → manager-C0_r0ALf.d.ts} +2 -2
- package/dist/{materialize-indexes-CAGhqPHQ.d.ts → materialize-indexes-CAkIYFV-.d.ts} +1 -1
- package/dist/{materialize-indexes-DEYkU-wr.d.cts → materialize-indexes-D20xNluI.d.cts} +1 -1
- package/dist/{postgres-4J2tmauh.d.cts → postgres-MzBPkYzq.d.ts} +2651 -596
- package/dist/{postgres-BdIb7tS_.d.ts → postgres-_9psmVGm.d.cts} +2651 -596
- package/dist/profiler/index.cjs +4 -3
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/profiler/index.js +2 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +30 -29
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +7 -6
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-aM_PAz-O.d.ts → sqlite-BfksSb45.d.cts} +2726 -455
- package/dist/{sqlite-Gatk_iw_.d.cts → sqlite-gm44dShb.d.ts} +2726 -455
- package/dist/{store-DuCbdqsh.d.cts → store-view-9jQ2rPum.d.cts} +1101 -465
- package/dist/{store-MloRPwb9.d.ts → store-view-FfE5_7eo.d.ts} +1101 -465
- package/dist/{types-DoByHGyU.d.cts → types-B6mhrcLv.d.cts} +2 -2
- package/dist/{types-C1CYxWrL.d.cts → types-C_UnQOQp.d.cts} +154 -23
- package/dist/{types-K3vpaJAL.d.ts → types-CdWxK-nD.d.ts} +2 -2
- package/dist/{types-BKQljXom.d.ts → types-DGylBhWo.d.ts} +154 -23
- package/dist/{where-DydZjGOb.d.cts → where-Bpp2ul_z.d.cts} +2 -2
- package/dist/{where-Dt49bvo6.d.ts → where-BsEXraKW.d.ts} +2 -2
- package/package.json +2 -2
- package/dist/chunk-2HZGWCB4.js.map +0 -1
- package/dist/chunk-3JBJEYWE.cjs.map +0 -1
- package/dist/chunk-4A4GUZTQ.js.map +0 -1
- package/dist/chunk-54JVNOAQ.cjs.map +0 -1
- package/dist/chunk-6G35I3VW.cjs +0 -40
- package/dist/chunk-6G35I3VW.cjs.map +0 -1
- package/dist/chunk-6RMLO5O4.cjs.map +0 -1
- package/dist/chunk-7JGLPAFV.cjs.map +0 -1
- package/dist/chunk-CIINW6PS.cjs.map +0 -1
- package/dist/chunk-FLOI7QOT.cjs.map +0 -1
- package/dist/chunk-GKFWM3DS.js.map +0 -1
- package/dist/chunk-IJORSAC3.js.map +0 -1
- package/dist/chunk-M6OC455F.js +0 -65
- package/dist/chunk-M6OC455F.js.map +0 -1
- package/dist/chunk-MAQJYNJR.js.map +0 -1
- package/dist/chunk-MXE2U3EX.js.map +0 -1
- package/dist/chunk-RP7YITHX.cjs +0 -70
- package/dist/chunk-RP7YITHX.cjs.map +0 -1
- package/dist/chunk-RZ4DH4E7.cjs.map +0 -1
- package/dist/chunk-SAJSMR2B.js +0 -35
- package/dist/chunk-SAJSMR2B.js.map +0 -1
- package/dist/chunk-SFFJ2IKN.cjs.map +0 -1
- package/dist/chunk-STP7QVUB.js.map +0 -1
- package/dist/chunk-THX25XW6.js.map +0 -1
- package/dist/chunk-UIFEEPME.js.map +0 -1
- package/dist/chunk-V4IQYOQ4.cjs.map +0 -1
- package/dist/chunk-VZX2KSY3.js.map +0 -1
- package/dist/chunk-YQGLVWB2.cjs.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { tables } from './chunk-
|
|
2
|
-
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { tables } from './chunk-DJYRRDHA.js';
|
|
2
|
+
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-CWFPJ3RC.js';
|
|
3
|
+
import { formatPostgresTimestamp, createBackendOverlay, nowIso, chunk, isPresent, sqlValueList } from './chunk-PYD3UCDU.js';
|
|
4
|
+
import { parseDimensionMismatch, isMissingTableError, sortedReplacer } from './chunk-GYVBEZAO.js';
|
|
5
|
+
import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER, quotedTableName, quotedColumn, edgeColumnList, sqlNull, nodeColumnList } from './chunk-C4C4Q7A6.js';
|
|
5
6
|
import { sha256Hex } from './chunk-2YMGNYXY.js';
|
|
6
|
-
import { EmbeddingDimensionChangedError,
|
|
7
|
+
import { EmbeddingDimensionChangedError, ConfigurationError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, StoreNotInitializedError, StaleVersionError } from './chunk-TQOYM4LN.js';
|
|
7
8
|
import { sql, is, getTableName } from 'drizzle-orm';
|
|
8
9
|
import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
|
|
9
10
|
import { getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
@@ -19,6 +20,9 @@ var tsvector = customType({
|
|
|
19
20
|
var DEFAULT_TABLE_NAMES = {
|
|
20
21
|
nodes: "typegraph_nodes",
|
|
21
22
|
edges: "typegraph_edges",
|
|
23
|
+
recordedNodes: "typegraph_recorded_nodes",
|
|
24
|
+
recordedEdges: "typegraph_recorded_edges",
|
|
25
|
+
recordedClock: "typegraph_recorded_clock",
|
|
22
26
|
uniques: "typegraph_node_uniques",
|
|
23
27
|
schemaVersions: "typegraph_schema_versions",
|
|
24
28
|
fulltext: "typegraph_node_fulltext",
|
|
@@ -117,6 +121,111 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
117
121
|
...buildPostgresEdgeIndexBuilders(t, indexes)
|
|
118
122
|
]
|
|
119
123
|
);
|
|
124
|
+
const recordedNodes2 = pgTable(
|
|
125
|
+
n.recordedNodes,
|
|
126
|
+
{
|
|
127
|
+
historyId: text("history_id").notNull(),
|
|
128
|
+
graphId: text("graph_id").notNull(),
|
|
129
|
+
kind: text("kind").notNull(),
|
|
130
|
+
id: text("id").notNull(),
|
|
131
|
+
props: jsonb("props").notNull(),
|
|
132
|
+
version: integer("version").notNull(),
|
|
133
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
134
|
+
validTo: timestamp("valid_to", { withTimezone: true }),
|
|
135
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
136
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
137
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
138
|
+
recordedFrom: timestamp("recorded_from", { withTimezone: true }).notNull(),
|
|
139
|
+
recordedTo: timestamp("recorded_to", { withTimezone: true }).notNull(),
|
|
140
|
+
op: text("op").notNull(),
|
|
141
|
+
schemaVersion: integer("schema_version"),
|
|
142
|
+
txId: text("tx_id"),
|
|
143
|
+
meta: jsonb("meta")
|
|
144
|
+
},
|
|
145
|
+
(t) => [
|
|
146
|
+
primaryKey({ columns: [t.historyId] }),
|
|
147
|
+
index(`${n.recordedNodes}_entity_idx`).on(
|
|
148
|
+
t.graphId,
|
|
149
|
+
t.kind,
|
|
150
|
+
t.id,
|
|
151
|
+
t.recordedFrom,
|
|
152
|
+
t.recordedTo
|
|
153
|
+
),
|
|
154
|
+
index(`${n.recordedNodes}_open_idx`).on(t.graphId, t.recordedTo),
|
|
155
|
+
index(`${n.recordedNodes}_valid_idx`).on(
|
|
156
|
+
t.graphId,
|
|
157
|
+
t.validFrom,
|
|
158
|
+
t.validTo
|
|
159
|
+
)
|
|
160
|
+
]
|
|
161
|
+
);
|
|
162
|
+
const recordedEdges2 = pgTable(
|
|
163
|
+
n.recordedEdges,
|
|
164
|
+
{
|
|
165
|
+
historyId: text("history_id").notNull(),
|
|
166
|
+
graphId: text("graph_id").notNull(),
|
|
167
|
+
id: text("id").notNull(),
|
|
168
|
+
kind: text("kind").notNull(),
|
|
169
|
+
fromKind: text("from_kind").notNull(),
|
|
170
|
+
fromId: text("from_id").notNull(),
|
|
171
|
+
toKind: text("to_kind").notNull(),
|
|
172
|
+
toId: text("to_id").notNull(),
|
|
173
|
+
props: jsonb("props").notNull(),
|
|
174
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
175
|
+
validTo: timestamp("valid_to", { withTimezone: true }),
|
|
176
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
177
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
178
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
179
|
+
recordedFrom: timestamp("recorded_from", { withTimezone: true }).notNull(),
|
|
180
|
+
recordedTo: timestamp("recorded_to", { withTimezone: true }).notNull(),
|
|
181
|
+
op: text("op").notNull(),
|
|
182
|
+
schemaVersion: integer("schema_version"),
|
|
183
|
+
txId: text("tx_id"),
|
|
184
|
+
meta: jsonb("meta")
|
|
185
|
+
},
|
|
186
|
+
(t) => [
|
|
187
|
+
primaryKey({ columns: [t.historyId] }),
|
|
188
|
+
index(`${n.recordedEdges}_entity_idx`).on(
|
|
189
|
+
t.graphId,
|
|
190
|
+
t.kind,
|
|
191
|
+
t.id,
|
|
192
|
+
t.recordedFrom,
|
|
193
|
+
t.recordedTo
|
|
194
|
+
),
|
|
195
|
+
index(`${n.recordedEdges}_open_idx`).on(t.graphId, t.recordedTo),
|
|
196
|
+
index(`${n.recordedEdges}_from_idx`).on(
|
|
197
|
+
t.graphId,
|
|
198
|
+
t.fromKind,
|
|
199
|
+
t.fromId,
|
|
200
|
+
t.kind,
|
|
201
|
+
t.toKind,
|
|
202
|
+
t.recordedFrom,
|
|
203
|
+
t.recordedTo
|
|
204
|
+
),
|
|
205
|
+
index(`${n.recordedEdges}_to_idx`).on(
|
|
206
|
+
t.graphId,
|
|
207
|
+
t.toKind,
|
|
208
|
+
t.toId,
|
|
209
|
+
t.kind,
|
|
210
|
+
t.fromKind,
|
|
211
|
+
t.recordedFrom,
|
|
212
|
+
t.recordedTo
|
|
213
|
+
),
|
|
214
|
+
index(`${n.recordedEdges}_valid_idx`).on(
|
|
215
|
+
t.graphId,
|
|
216
|
+
t.validFrom,
|
|
217
|
+
t.validTo
|
|
218
|
+
)
|
|
219
|
+
]
|
|
220
|
+
);
|
|
221
|
+
const recordedClock2 = pgTable(
|
|
222
|
+
n.recordedClock,
|
|
223
|
+
{
|
|
224
|
+
graphId: text("graph_id").notNull(),
|
|
225
|
+
recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull()
|
|
226
|
+
},
|
|
227
|
+
(t) => [primaryKey({ columns: [t.graphId] })]
|
|
228
|
+
);
|
|
120
229
|
const uniques2 = pgTable(
|
|
121
230
|
n.uniques,
|
|
122
231
|
{
|
|
@@ -240,6 +349,9 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
240
349
|
return {
|
|
241
350
|
nodes: nodes2,
|
|
242
351
|
edges: edges2,
|
|
352
|
+
recordedNodes: recordedNodes2,
|
|
353
|
+
recordedEdges: recordedEdges2,
|
|
354
|
+
recordedClock: recordedClock2,
|
|
243
355
|
uniques: uniques2,
|
|
244
356
|
schemaVersions: schemaVersions2,
|
|
245
357
|
indexMaterializations,
|
|
@@ -251,7 +363,16 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
251
363
|
};
|
|
252
364
|
}
|
|
253
365
|
var tables2 = createPostgresTables();
|
|
254
|
-
var {
|
|
366
|
+
var {
|
|
367
|
+
nodes,
|
|
368
|
+
edges,
|
|
369
|
+
recordedNodes,
|
|
370
|
+
recordedEdges,
|
|
371
|
+
recordedClock,
|
|
372
|
+
uniques,
|
|
373
|
+
schemaVersions,
|
|
374
|
+
fulltext
|
|
375
|
+
} = tables2;
|
|
255
376
|
function getSqliteColumnType(column) {
|
|
256
377
|
switch (column.columnType) {
|
|
257
378
|
case "SQLiteText": {
|
|
@@ -307,9 +428,9 @@ function renderIndexColumn(col) {
|
|
|
307
428
|
if (col && typeof col === "object" && "name" in col) {
|
|
308
429
|
return `"${col.name}"`;
|
|
309
430
|
}
|
|
310
|
-
const
|
|
311
|
-
if (
|
|
312
|
-
return
|
|
431
|
+
const sql13 = tryInlineSql(col);
|
|
432
|
+
if (sql13 !== void 0) {
|
|
433
|
+
return sql13;
|
|
313
434
|
}
|
|
314
435
|
return "unknown";
|
|
315
436
|
}
|
|
@@ -322,16 +443,16 @@ function tryInlineSql(value) {
|
|
|
322
443
|
}
|
|
323
444
|
return inlineSql(value);
|
|
324
445
|
}
|
|
325
|
-
function flattenSqlChunk(
|
|
326
|
-
if (typeof
|
|
327
|
-
return
|
|
446
|
+
function flattenSqlChunk(chunk2) {
|
|
447
|
+
if (typeof chunk2 === "string") {
|
|
448
|
+
return chunk2;
|
|
328
449
|
}
|
|
329
|
-
if (typeof
|
|
330
|
-
if ("name" in
|
|
331
|
-
return `"${
|
|
450
|
+
if (typeof chunk2 === "object" && chunk2 !== null) {
|
|
451
|
+
if ("name" in chunk2 && typeof chunk2.name === "string") {
|
|
452
|
+
return `"${chunk2.name}"`;
|
|
332
453
|
}
|
|
333
|
-
if ("value" in
|
|
334
|
-
const value =
|
|
454
|
+
if ("value" in chunk2) {
|
|
455
|
+
const value = chunk2.value;
|
|
335
456
|
if (typeof value === "string") {
|
|
336
457
|
return value;
|
|
337
458
|
}
|
|
@@ -339,17 +460,17 @@ function flattenSqlChunk(chunk) {
|
|
|
339
460
|
return value.map((part) => flattenSqlChunk(part)).join("");
|
|
340
461
|
}
|
|
341
462
|
}
|
|
342
|
-
if ("queryChunks" in
|
|
343
|
-
return
|
|
463
|
+
if ("queryChunks" in chunk2 && Array.isArray(chunk2.queryChunks)) {
|
|
464
|
+
return chunk2.queryChunks.map((part) => flattenSqlChunk(part)).join("");
|
|
344
465
|
}
|
|
345
|
-
if ("getSQL" in
|
|
346
|
-
const maybe =
|
|
466
|
+
if ("getSQL" in chunk2) {
|
|
467
|
+
const maybe = chunk2;
|
|
347
468
|
if (typeof maybe.getSQL === "function") {
|
|
348
469
|
return flattenSqlChunk(maybe.getSQL());
|
|
349
470
|
}
|
|
350
471
|
}
|
|
351
472
|
}
|
|
352
|
-
throw new Error(`Unable to inline SQL chunk: ${String(
|
|
473
|
+
throw new Error(`Unable to inline SQL chunk: ${String(chunk2)}`);
|
|
353
474
|
}
|
|
354
475
|
function inlineSql(value) {
|
|
355
476
|
try {
|
|
@@ -606,146 +727,6 @@ function mapVectorWriteError(error, params) {
|
|
|
606
727
|
{ cause: error }
|
|
607
728
|
);
|
|
608
729
|
}
|
|
609
|
-
|
|
610
|
-
// src/backend/drizzle/row-mappers.ts
|
|
611
|
-
function requireTimestamp(value, field) {
|
|
612
|
-
if (value === void 0) {
|
|
613
|
-
throw new DatabaseOperationError(
|
|
614
|
-
`Expected non-null ${field} timestamp`,
|
|
615
|
-
{ operation: "select", entity: "row" }
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
return value;
|
|
619
|
-
}
|
|
620
|
-
function asString(value, field) {
|
|
621
|
-
if (typeof value !== "string") {
|
|
622
|
-
throw new DatabaseOperationError(
|
|
623
|
-
`Expected ${field} to be string, got ${typeof value}`,
|
|
624
|
-
{ operation: "select", entity: "row" }
|
|
625
|
-
);
|
|
626
|
-
}
|
|
627
|
-
return value;
|
|
628
|
-
}
|
|
629
|
-
function asNumber(value, field) {
|
|
630
|
-
if (typeof value !== "number") {
|
|
631
|
-
throw new DatabaseOperationError(
|
|
632
|
-
`Expected ${field} to be number, got ${typeof value}`,
|
|
633
|
-
{ operation: "select", entity: "row" }
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
return value;
|
|
637
|
-
}
|
|
638
|
-
function nowIso() {
|
|
639
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
640
|
-
}
|
|
641
|
-
function nullToUndefined(value) {
|
|
642
|
-
return value ?? void 0;
|
|
643
|
-
}
|
|
644
|
-
function formatPostgresTimestamp(value) {
|
|
645
|
-
if (value === null || value === void 0) return void 0;
|
|
646
|
-
if (value instanceof Date) return value.toISOString();
|
|
647
|
-
if (typeof value === "string") {
|
|
648
|
-
if (value.includes("T")) return value;
|
|
649
|
-
const date = new Date(value);
|
|
650
|
-
if (!Number.isNaN(date.getTime())) return date.toISOString();
|
|
651
|
-
return value;
|
|
652
|
-
}
|
|
653
|
-
return void 0;
|
|
654
|
-
}
|
|
655
|
-
function coerceNumericScore(value) {
|
|
656
|
-
if (typeof value === "number") return value;
|
|
657
|
-
const parsed = Number.parseFloat(value);
|
|
658
|
-
if (Number.isNaN(parsed)) {
|
|
659
|
-
throw new TypeError(
|
|
660
|
-
`Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
return parsed;
|
|
664
|
-
}
|
|
665
|
-
function normalizeJsonColumn(value) {
|
|
666
|
-
return typeof value === "string" ? value : JSON.stringify(value ?? {});
|
|
667
|
-
}
|
|
668
|
-
var SQLITE_ROW_MAPPER_CONFIG = {
|
|
669
|
-
formatTimestamp: (value) => {
|
|
670
|
-
if (value === null || value === void 0) return;
|
|
671
|
-
if (typeof value !== "string") {
|
|
672
|
-
throw new DatabaseOperationError(
|
|
673
|
-
`Expected timestamp to be string, got ${typeof value}`,
|
|
674
|
-
{ operation: "select", entity: "row" }
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
return value;
|
|
678
|
-
},
|
|
679
|
-
normalizeJson: (value) => {
|
|
680
|
-
if (typeof value !== "string") {
|
|
681
|
-
throw new DatabaseOperationError(
|
|
682
|
-
`Expected JSON column to be string, got ${typeof value}`,
|
|
683
|
-
{ operation: "select", entity: "row" }
|
|
684
|
-
);
|
|
685
|
-
}
|
|
686
|
-
return value;
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
var POSTGRES_ROW_MAPPER_CONFIG = {
|
|
690
|
-
formatTimestamp: formatPostgresTimestamp,
|
|
691
|
-
normalizeJson: normalizeJsonColumn
|
|
692
|
-
};
|
|
693
|
-
function createNodeRowMapper(config) {
|
|
694
|
-
return (row) => ({
|
|
695
|
-
graph_id: asString(row.graph_id, "graph_id"),
|
|
696
|
-
kind: asString(row.kind, "kind"),
|
|
697
|
-
id: asString(row.id, "id"),
|
|
698
|
-
props: config.normalizeJson(row.props),
|
|
699
|
-
version: asNumber(row.version, "version"),
|
|
700
|
-
valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
|
|
701
|
-
valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
|
|
702
|
-
created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
|
|
703
|
-
updated_at: requireTimestamp(config.formatTimestamp(row.updated_at), "updated_at"),
|
|
704
|
-
deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
function createEdgeRowMapper(config) {
|
|
708
|
-
return (row) => ({
|
|
709
|
-
graph_id: asString(row.graph_id, "graph_id"),
|
|
710
|
-
id: asString(row.id, "id"),
|
|
711
|
-
kind: asString(row.kind, "kind"),
|
|
712
|
-
from_kind: asString(row.from_kind, "from_kind"),
|
|
713
|
-
from_id: asString(row.from_id, "from_id"),
|
|
714
|
-
to_kind: asString(row.to_kind, "to_kind"),
|
|
715
|
-
to_id: asString(row.to_id, "to_id"),
|
|
716
|
-
props: config.normalizeJson(row.props),
|
|
717
|
-
valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
|
|
718
|
-
valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
|
|
719
|
-
created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
|
|
720
|
-
updated_at: requireTimestamp(config.formatTimestamp(row.updated_at), "updated_at"),
|
|
721
|
-
deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
function createUniqueRowMapper(config) {
|
|
725
|
-
return (row) => ({
|
|
726
|
-
graph_id: asString(row.graph_id, "graph_id"),
|
|
727
|
-
node_kind: asString(row.node_kind, "node_kind"),
|
|
728
|
-
constraint_name: asString(row.constraint_name, "constraint_name"),
|
|
729
|
-
key: asString(row.key, "key"),
|
|
730
|
-
node_id: asString(row.node_id, "node_id"),
|
|
731
|
-
concrete_kind: asString(row.concrete_kind, "concrete_kind"),
|
|
732
|
-
deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
function createSchemaVersionRowMapper(config) {
|
|
736
|
-
return (row) => {
|
|
737
|
-
const isActiveValue = row.is_active;
|
|
738
|
-
const isActive = isActiveValue === true || isActiveValue === 1 || isActiveValue === "1";
|
|
739
|
-
return {
|
|
740
|
-
graph_id: asString(row.graph_id, "graph_id"),
|
|
741
|
-
version: asNumber(row.version, "version"),
|
|
742
|
-
schema_hash: asString(row.schema_hash, "schema_hash"),
|
|
743
|
-
schema_doc: config.normalizeJson(row.schema_doc),
|
|
744
|
-
created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
|
|
745
|
-
is_active: isActive
|
|
746
|
-
};
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
730
|
var SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = {
|
|
750
731
|
decode: (value) => typeof value === "string" ? value : void 0,
|
|
751
732
|
encode: (value) => value
|
|
@@ -821,21 +802,21 @@ function identityOf(graphId, contribution) {
|
|
|
821
802
|
function gateFulltextMethods(source, assert) {
|
|
822
803
|
const gated = {};
|
|
823
804
|
if (source.upsertFulltext) {
|
|
824
|
-
const raw = source.upsertFulltext;
|
|
805
|
+
const raw = source.upsertFulltext.bind(source);
|
|
825
806
|
gated.upsertFulltext = async (params) => {
|
|
826
807
|
await assert(params.graphId);
|
|
827
808
|
await raw(params);
|
|
828
809
|
};
|
|
829
810
|
}
|
|
830
811
|
if (source.deleteFulltext) {
|
|
831
|
-
const raw = source.deleteFulltext;
|
|
812
|
+
const raw = source.deleteFulltext.bind(source);
|
|
832
813
|
gated.deleteFulltext = async (params) => {
|
|
833
814
|
await assert(params.graphId);
|
|
834
815
|
await raw(params);
|
|
835
816
|
};
|
|
836
817
|
}
|
|
837
818
|
if (source.upsertFulltextBatch) {
|
|
838
|
-
const raw = source.upsertFulltextBatch;
|
|
819
|
+
const raw = source.upsertFulltextBatch.bind(source);
|
|
839
820
|
gated.upsertFulltextBatch = async (params) => {
|
|
840
821
|
if (params.rows.length === 0) return;
|
|
841
822
|
await assert(params.graphId);
|
|
@@ -843,7 +824,7 @@ function gateFulltextMethods(source, assert) {
|
|
|
843
824
|
};
|
|
844
825
|
}
|
|
845
826
|
if (source.deleteFulltextBatch) {
|
|
846
|
-
const raw = source.deleteFulltextBatch;
|
|
827
|
+
const raw = source.deleteFulltextBatch.bind(source);
|
|
847
828
|
gated.deleteFulltextBatch = async (params) => {
|
|
848
829
|
if (params.nodeIds.length === 0) return;
|
|
849
830
|
await assert(params.graphId);
|
|
@@ -851,13 +832,13 @@ function gateFulltextMethods(source, assert) {
|
|
|
851
832
|
};
|
|
852
833
|
}
|
|
853
834
|
if (source.fulltextSearch) {
|
|
854
|
-
const raw = source.fulltextSearch;
|
|
835
|
+
const raw = source.fulltextSearch.bind(source);
|
|
855
836
|
gated.fulltextSearch = async (params) => {
|
|
856
837
|
await assert(params.graphId);
|
|
857
838
|
return raw(params);
|
|
858
839
|
};
|
|
859
840
|
}
|
|
860
|
-
const rawHardDelete = source.hardDeleteNode;
|
|
841
|
+
const rawHardDelete = source.hardDeleteNode.bind(source);
|
|
861
842
|
gated.hardDeleteNode = async (params) => {
|
|
862
843
|
await assert(params.graphId);
|
|
863
844
|
await rawHardDelete(params);
|
|
@@ -865,7 +846,10 @@ function gateFulltextMethods(source, assert) {
|
|
|
865
846
|
return gated;
|
|
866
847
|
}
|
|
867
848
|
function gateFulltext(tx, assert) {
|
|
868
|
-
return
|
|
849
|
+
return createBackendOverlay(
|
|
850
|
+
tx,
|
|
851
|
+
gateFulltextMethods(tx, assert)
|
|
852
|
+
);
|
|
869
853
|
}
|
|
870
854
|
function createContributionMaterializer(deps) {
|
|
871
855
|
const { dialect, fulltextStrategy, fulltextTableName } = deps;
|
|
@@ -1078,397 +1062,46 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
|
|
|
1078
1062
|
lastError: sql`excluded.${sql.identifier("last_error")}`
|
|
1079
1063
|
};
|
|
1080
1064
|
}
|
|
1081
|
-
function
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
function chunkArray(values, size) {
|
|
1090
|
-
if (values.length <= size) {
|
|
1091
|
-
return [values];
|
|
1092
|
-
}
|
|
1093
|
-
const chunks = [];
|
|
1094
|
-
for (let index2 = 0; index2 < values.length; index2 += size) {
|
|
1095
|
-
chunks.push(values.slice(index2, index2 + size));
|
|
1096
|
-
}
|
|
1097
|
-
return chunks;
|
|
1098
|
-
}
|
|
1099
|
-
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
1100
|
-
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
1101
|
-
if (actualActiveVersion !== expectedVersion) {
|
|
1102
|
-
throw new StaleVersionError({
|
|
1103
|
-
graphId,
|
|
1104
|
-
expected: expectedVersion,
|
|
1105
|
-
actual: actualActiveVersion
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
function createCommonOperationBackend(options) {
|
|
1110
|
-
const { batchConfig, execution, operationStrategy, rowMappers } = options;
|
|
1111
|
-
const nowIso2 = options.nowIso ?? nowIso;
|
|
1112
|
-
async function readActiveVersion(graphId) {
|
|
1113
|
-
const row = await execution.execGet(
|
|
1114
|
-
operationStrategy.buildGetActiveSchema(graphId)
|
|
1115
|
-
);
|
|
1116
|
-
return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
|
|
1117
|
-
}
|
|
1118
|
-
return {
|
|
1119
|
-
async insertNode(params) {
|
|
1120
|
-
const timestamp2 = nowIso2();
|
|
1121
|
-
const query = operationStrategy.buildInsertNode(params, timestamp2);
|
|
1122
|
-
const row = await execution.execGet(query);
|
|
1123
|
-
if (!row) throw new DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
|
|
1124
|
-
return rowMappers.toNodeRow(row);
|
|
1125
|
-
},
|
|
1126
|
-
async insertNodeNoReturn(params) {
|
|
1127
|
-
const timestamp2 = nowIso2();
|
|
1128
|
-
const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
|
|
1129
|
-
await execution.execRun(query);
|
|
1130
|
-
},
|
|
1131
|
-
async insertNodesBatch(params) {
|
|
1132
|
-
if (params.length === 0) {
|
|
1133
|
-
return;
|
|
1134
|
-
}
|
|
1135
|
-
const timestamp2 = nowIso2();
|
|
1136
|
-
for (const chunk of chunkArray(params, batchConfig.nodeInsertBatchSize)) {
|
|
1137
|
-
const query = operationStrategy.buildInsertNodesBatch(chunk, timestamp2);
|
|
1138
|
-
await execution.execRun(query);
|
|
1139
|
-
}
|
|
1140
|
-
},
|
|
1141
|
-
async insertNodesBatchReturning(params) {
|
|
1142
|
-
if (params.length === 0) {
|
|
1143
|
-
return [];
|
|
1144
|
-
}
|
|
1145
|
-
const timestamp2 = nowIso2();
|
|
1146
|
-
const allRows = [];
|
|
1147
|
-
for (const chunk of chunkArray(params, batchConfig.nodeInsertBatchSize)) {
|
|
1148
|
-
const query = operationStrategy.buildInsertNodesBatchReturning(chunk, timestamp2);
|
|
1149
|
-
const rows = await execution.execAll(query);
|
|
1150
|
-
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
1151
|
-
}
|
|
1152
|
-
return allRows;
|
|
1153
|
-
},
|
|
1154
|
-
async getNode(graphId, kind, id) {
|
|
1155
|
-
const query = operationStrategy.buildGetNode(graphId, kind, id);
|
|
1156
|
-
const row = await execution.execGet(query);
|
|
1157
|
-
return row ? rowMappers.toNodeRow(row) : void 0;
|
|
1065
|
+
function buildClearGraph(tables3, graphId) {
|
|
1066
|
+
const fulltext2 = quotedTableName(tables3.fulltextTableName);
|
|
1067
|
+
return [
|
|
1068
|
+
{ query: sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}` },
|
|
1069
|
+
{
|
|
1070
|
+
query: sql`DELETE FROM ${tables3.recordedEdges} WHERE ${tables3.recordedEdges.graphId} = ${graphId}`,
|
|
1071
|
+
ignoreMissingTable: true,
|
|
1072
|
+
requiredTableName: getTableName(tables3.recordedEdges)
|
|
1158
1073
|
},
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
const query = operationStrategy.buildGetNodes(graphId, kind, chunk);
|
|
1164
|
-
const rows = await execution.execAll(query);
|
|
1165
|
-
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
1166
|
-
}
|
|
1167
|
-
return allRows;
|
|
1074
|
+
{
|
|
1075
|
+
query: sql`DELETE FROM ${tables3.recordedNodes} WHERE ${tables3.recordedNodes.graphId} = ${graphId}`,
|
|
1076
|
+
ignoreMissingTable: true,
|
|
1077
|
+
requiredTableName: getTableName(tables3.recordedNodes)
|
|
1168
1078
|
},
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
if (!row) throw new DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
|
|
1174
|
-
return rowMappers.toNodeRow(row);
|
|
1079
|
+
{
|
|
1080
|
+
query: sql`DELETE FROM ${tables3.recordedClock} WHERE ${tables3.recordedClock.graphId} = ${graphId}`,
|
|
1081
|
+
ignoreMissingTable: true,
|
|
1082
|
+
requiredTableName: getTableName(tables3.recordedClock)
|
|
1175
1083
|
},
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const query = operationStrategy.buildDeleteNode(params, timestamp2);
|
|
1179
|
-
await execution.execRun(query);
|
|
1084
|
+
{
|
|
1085
|
+
query: sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`
|
|
1180
1086
|
},
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
//
|
|
1184
|
-
// Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
|
|
1185
|
-
// fieldPath)` strategy-owned tables addressable only with the slot
|
|
1186
|
-
// context the graph-agnostic backend lacks. The store's hard-delete
|
|
1187
|
-
// path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
|
|
1188
|
-
// resolves each embedding field and routes a per-field
|
|
1189
|
-
// `backend.deleteEmbedding` through the active vector strategy.
|
|
1190
|
-
async hardDeleteNode(params) {
|
|
1191
|
-
const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
|
|
1192
|
-
params.graphId,
|
|
1193
|
-
params.id
|
|
1194
|
-
);
|
|
1195
|
-
await execution.execRun(deleteUniquesQuery);
|
|
1196
|
-
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
1197
|
-
params.graphId,
|
|
1198
|
-
params.kind,
|
|
1199
|
-
params.id
|
|
1200
|
-
);
|
|
1201
|
-
for (const stmt of deleteFulltextStatements) {
|
|
1202
|
-
await execution.execRun(stmt);
|
|
1203
|
-
}
|
|
1204
|
-
const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
|
|
1205
|
-
params.graphId,
|
|
1206
|
-
params.kind,
|
|
1207
|
-
params.id
|
|
1208
|
-
);
|
|
1209
|
-
await execution.execRun(deleteEdgesQuery);
|
|
1210
|
-
const query = operationStrategy.buildHardDeleteNode(params);
|
|
1211
|
-
await execution.execRun(query);
|
|
1087
|
+
{
|
|
1088
|
+
query: sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`
|
|
1212
1089
|
},
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
const query = operationStrategy.buildInsertEdge(params, timestamp2);
|
|
1216
|
-
const row = await execution.execGet(query);
|
|
1217
|
-
if (!row) throw new DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
|
|
1218
|
-
return rowMappers.toEdgeRow(row);
|
|
1090
|
+
{
|
|
1091
|
+
query: sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`
|
|
1219
1092
|
},
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
|
|
1223
|
-
await execution.execRun(query);
|
|
1093
|
+
{
|
|
1094
|
+
query: sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`
|
|
1224
1095
|
},
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
const timestamp2 = nowIso2();
|
|
1230
|
-
for (const chunk of chunkArray(params, batchConfig.edgeInsertBatchSize)) {
|
|
1231
|
-
const query = operationStrategy.buildInsertEdgesBatch(chunk, timestamp2);
|
|
1232
|
-
await execution.execRun(query);
|
|
1233
|
-
}
|
|
1096
|
+
{
|
|
1097
|
+
query: sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`
|
|
1234
1098
|
},
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
return [];
|
|
1238
|
-
}
|
|
1239
|
-
const timestamp2 = nowIso2();
|
|
1240
|
-
const allRows = [];
|
|
1241
|
-
for (const chunk of chunkArray(params, batchConfig.edgeInsertBatchSize)) {
|
|
1242
|
-
const query = operationStrategy.buildInsertEdgesBatchReturning(chunk, timestamp2);
|
|
1243
|
-
const rows = await execution.execAll(query);
|
|
1244
|
-
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
1245
|
-
}
|
|
1246
|
-
return allRows;
|
|
1099
|
+
{
|
|
1100
|
+
query: sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
|
|
1247
1101
|
},
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
const row = await execution.execGet(query);
|
|
1251
|
-
return row ? rowMappers.toEdgeRow(row) : void 0;
|
|
1252
|
-
},
|
|
1253
|
-
async getEdges(graphId, ids) {
|
|
1254
|
-
if (ids.length === 0) return [];
|
|
1255
|
-
const allRows = [];
|
|
1256
|
-
for (const chunk of chunkArray(ids, batchConfig.getEdgesChunkSize)) {
|
|
1257
|
-
const query = operationStrategy.buildGetEdges(graphId, chunk);
|
|
1258
|
-
const rows = await execution.execAll(query);
|
|
1259
|
-
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
1260
|
-
}
|
|
1261
|
-
return allRows;
|
|
1262
|
-
},
|
|
1263
|
-
async updateEdge(params) {
|
|
1264
|
-
const timestamp2 = nowIso2();
|
|
1265
|
-
const query = operationStrategy.buildUpdateEdge(params, timestamp2);
|
|
1266
|
-
const row = await execution.execGet(query);
|
|
1267
|
-
if (!row) throw new DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
|
|
1268
|
-
return rowMappers.toEdgeRow(row);
|
|
1269
|
-
},
|
|
1270
|
-
async deleteEdge(params) {
|
|
1271
|
-
const timestamp2 = nowIso2();
|
|
1272
|
-
const query = operationStrategy.buildDeleteEdge(params, timestamp2);
|
|
1273
|
-
await execution.execRun(query);
|
|
1274
|
-
},
|
|
1275
|
-
async hardDeleteEdge(params) {
|
|
1276
|
-
const query = operationStrategy.buildHardDeleteEdge(params);
|
|
1277
|
-
await execution.execRun(query);
|
|
1278
|
-
},
|
|
1279
|
-
async countEdgesFrom(params) {
|
|
1280
|
-
const query = operationStrategy.buildCountEdgesFrom(params);
|
|
1281
|
-
const row = await execution.execGet(query);
|
|
1282
|
-
return Number(row?.count ?? 0);
|
|
1283
|
-
},
|
|
1284
|
-
async edgeExistsBetween(params) {
|
|
1285
|
-
const query = operationStrategy.buildEdgeExistsBetween(params);
|
|
1286
|
-
const row = await execution.execGet(query);
|
|
1287
|
-
return row !== void 0;
|
|
1288
|
-
},
|
|
1289
|
-
async findEdgesConnectedTo(params) {
|
|
1290
|
-
const query = operationStrategy.buildFindEdgesConnectedTo(params);
|
|
1291
|
-
const rows = await execution.execAll(query);
|
|
1292
|
-
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
1293
|
-
},
|
|
1294
|
-
async findNodesByKind(params) {
|
|
1295
|
-
const query = operationStrategy.buildFindNodesByKind(params);
|
|
1296
|
-
const rows = await execution.execAll(query);
|
|
1297
|
-
return rows.map((row) => rowMappers.toNodeRow(row));
|
|
1298
|
-
},
|
|
1299
|
-
async countNodesByKind(params) {
|
|
1300
|
-
const query = operationStrategy.buildCountNodesByKind(params);
|
|
1301
|
-
const row = await execution.execGet(query);
|
|
1302
|
-
return Number(row?.count ?? 0);
|
|
1303
|
-
},
|
|
1304
|
-
async findEdgesByKind(params) {
|
|
1305
|
-
const query = operationStrategy.buildFindEdgesByKind(params);
|
|
1306
|
-
const rows = await execution.execAll(query);
|
|
1307
|
-
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
1308
|
-
},
|
|
1309
|
-
async countEdgesByKind(params) {
|
|
1310
|
-
const query = operationStrategy.buildCountEdgesByKind(params);
|
|
1311
|
-
const row = await execution.execGet(query);
|
|
1312
|
-
return Number(row?.count ?? 0);
|
|
1313
|
-
},
|
|
1314
|
-
async insertUnique(params) {
|
|
1315
|
-
const query = operationStrategy.buildInsertUnique(params);
|
|
1316
|
-
const result = await execution.execGet(query);
|
|
1317
|
-
if (result && result.node_id !== params.nodeId) {
|
|
1318
|
-
throw new UniquenessError({
|
|
1319
|
-
constraintName: params.constraintName,
|
|
1320
|
-
kind: params.nodeKind,
|
|
1321
|
-
existingId: result.node_id,
|
|
1322
|
-
newId: params.nodeId,
|
|
1323
|
-
fields: []
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
},
|
|
1327
|
-
async deleteUnique(params) {
|
|
1328
|
-
const timestamp2 = nowIso2();
|
|
1329
|
-
const query = operationStrategy.buildDeleteUnique(params, timestamp2);
|
|
1330
|
-
await execution.execRun(query);
|
|
1331
|
-
},
|
|
1332
|
-
async checkUnique(params) {
|
|
1333
|
-
const query = operationStrategy.buildCheckUnique(params);
|
|
1334
|
-
const row = await execution.execGet(query);
|
|
1335
|
-
return row ? rowMappers.toUniqueRow(row) : void 0;
|
|
1336
|
-
},
|
|
1337
|
-
async checkUniqueBatch(params) {
|
|
1338
|
-
if (params.keys.length === 0) return [];
|
|
1339
|
-
const allRows = [];
|
|
1340
|
-
for (const chunk of chunkArray(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
|
|
1341
|
-
const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk });
|
|
1342
|
-
const rows = await execution.execAll(query);
|
|
1343
|
-
allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
|
|
1344
|
-
}
|
|
1345
|
-
return allRows;
|
|
1346
|
-
},
|
|
1347
|
-
async getActiveSchema(graphId) {
|
|
1348
|
-
const query = operationStrategy.buildGetActiveSchema(graphId);
|
|
1349
|
-
const row = await execution.execGet(query);
|
|
1350
|
-
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
1351
|
-
},
|
|
1352
|
-
async getSchemaVersion(graphId, version) {
|
|
1353
|
-
const query = operationStrategy.buildGetSchemaVersion(graphId, version);
|
|
1354
|
-
const row = await execution.execGet(query);
|
|
1355
|
-
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
1356
|
-
},
|
|
1357
|
-
async commitSchemaVersion(params) {
|
|
1358
|
-
const existingRaw = await execution.execGet(
|
|
1359
|
-
operationStrategy.buildGetSchemaVersion(
|
|
1360
|
-
params.graphId,
|
|
1361
|
-
params.version
|
|
1362
|
-
)
|
|
1363
|
-
);
|
|
1364
|
-
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
1365
|
-
if (existingRaw !== void 0) {
|
|
1366
|
-
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
1367
|
-
if (existing.schema_hash !== params.schemaHash) {
|
|
1368
|
-
throw new SchemaContentConflictError({
|
|
1369
|
-
graphId: params.graphId,
|
|
1370
|
-
version: params.version,
|
|
1371
|
-
existingHash: existing.schema_hash,
|
|
1372
|
-
incomingHash: params.schemaHash
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
if (existing.is_active) {
|
|
1376
|
-
return existing;
|
|
1377
|
-
}
|
|
1378
|
-
verifyExpectedActiveVersion(
|
|
1379
|
-
params.graphId,
|
|
1380
|
-
params.expected,
|
|
1381
|
-
actualActiveVersion
|
|
1382
|
-
);
|
|
1383
|
-
const reactivate = operationStrategy.buildSetActiveSchema(
|
|
1384
|
-
params.graphId,
|
|
1385
|
-
params.version
|
|
1386
|
-
);
|
|
1387
|
-
await execution.execRun(reactivate.deactivateAll);
|
|
1388
|
-
await execution.execRun(reactivate.activateVersion);
|
|
1389
|
-
return { ...existing, is_active: true };
|
|
1390
|
-
}
|
|
1391
|
-
verifyExpectedActiveVersion(
|
|
1392
|
-
params.graphId,
|
|
1393
|
-
params.expected,
|
|
1394
|
-
actualActiveVersion
|
|
1395
|
-
);
|
|
1396
|
-
if (params.expected.kind === "active") {
|
|
1397
|
-
const flip = operationStrategy.buildSetActiveSchema(
|
|
1398
|
-
params.graphId,
|
|
1399
|
-
params.version
|
|
1400
|
-
);
|
|
1401
|
-
await execution.execRun(flip.deactivateAll);
|
|
1402
|
-
}
|
|
1403
|
-
const timestamp2 = nowIso2();
|
|
1404
|
-
const insertQuery = operationStrategy.buildInsertSchema(
|
|
1405
|
-
{
|
|
1406
|
-
graphId: params.graphId,
|
|
1407
|
-
version: params.version,
|
|
1408
|
-
schemaHash: params.schemaHash,
|
|
1409
|
-
schemaDoc: params.schemaDoc,
|
|
1410
|
-
isActive: true
|
|
1411
|
-
},
|
|
1412
|
-
timestamp2
|
|
1413
|
-
);
|
|
1414
|
-
const insertedRaw = await execution.execGet(insertQuery);
|
|
1415
|
-
if (!insertedRaw) {
|
|
1416
|
-
throw new DatabaseOperationError(
|
|
1417
|
-
"Insert schema failed: no row returned",
|
|
1418
|
-
{ operation: "insert", entity: "schema" }
|
|
1419
|
-
);
|
|
1420
|
-
}
|
|
1421
|
-
return rowMappers.toSchemaVersionRow(insertedRaw);
|
|
1422
|
-
},
|
|
1423
|
-
async setActiveVersion(params) {
|
|
1424
|
-
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
1425
|
-
verifyExpectedActiveVersion(
|
|
1426
|
-
params.graphId,
|
|
1427
|
-
params.expected,
|
|
1428
|
-
actualActiveVersion
|
|
1429
|
-
);
|
|
1430
|
-
const targetRaw = await execution.execGet(
|
|
1431
|
-
operationStrategy.buildGetSchemaVersion(
|
|
1432
|
-
params.graphId,
|
|
1433
|
-
params.version
|
|
1434
|
-
)
|
|
1435
|
-
);
|
|
1436
|
-
if (!targetRaw) {
|
|
1437
|
-
throw new MigrationError(
|
|
1438
|
-
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
1439
|
-
{
|
|
1440
|
-
graphId: params.graphId,
|
|
1441
|
-
fromVersion: actualActiveVersion,
|
|
1442
|
-
toVersion: params.version
|
|
1443
|
-
}
|
|
1444
|
-
);
|
|
1445
|
-
}
|
|
1446
|
-
const queries = operationStrategy.buildSetActiveSchema(
|
|
1447
|
-
params.graphId,
|
|
1448
|
-
params.version
|
|
1449
|
-
);
|
|
1450
|
-
await execution.execRun(queries.deactivateAll);
|
|
1451
|
-
await execution.execRun(queries.activateVersion);
|
|
1452
|
-
},
|
|
1453
|
-
async clearGraph(graphId) {
|
|
1454
|
-
const statements = operationStrategy.buildClearGraph(graphId);
|
|
1455
|
-
for (const statement of statements) {
|
|
1456
|
-
await execution.execRun(statement);
|
|
1457
|
-
}
|
|
1102
|
+
{
|
|
1103
|
+
query: sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
|
|
1458
1104
|
}
|
|
1459
|
-
};
|
|
1460
|
-
}
|
|
1461
|
-
function buildClearGraph(tables3, graphId) {
|
|
1462
|
-
const fulltext2 = quotedTableName(tables3.fulltextTableName);
|
|
1463
|
-
return [
|
|
1464
|
-
sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}`,
|
|
1465
|
-
sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
|
|
1466
|
-
sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
|
|
1467
|
-
sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`,
|
|
1468
|
-
sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`,
|
|
1469
|
-
sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`,
|
|
1470
|
-
sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`,
|
|
1471
|
-
sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
|
|
1472
1105
|
];
|
|
1473
1106
|
}
|
|
1474
1107
|
function buildTemporalConditions(table, params) {
|
|
@@ -1673,14 +1306,10 @@ function buildGetEdge(tables3, graphId, id) {
|
|
|
1673
1306
|
}
|
|
1674
1307
|
function buildGetEdges(tables3, graphId, ids) {
|
|
1675
1308
|
const { edges: edges2 } = tables3;
|
|
1676
|
-
const idPlaceholders = sql.join(
|
|
1677
|
-
ids.map((edgeId) => sql`${edgeId}`),
|
|
1678
|
-
sql`, `
|
|
1679
|
-
);
|
|
1680
1309
|
return sql`
|
|
1681
1310
|
SELECT * FROM ${edges2}
|
|
1682
1311
|
WHERE ${edges2.graphId} = ${graphId}
|
|
1683
|
-
AND ${edges2.id} IN (${
|
|
1312
|
+
AND ${edges2.id} IN (${sqlValueList(ids)})
|
|
1684
1313
|
`;
|
|
1685
1314
|
}
|
|
1686
1315
|
function buildUpdateEdge(tables3, params, timestamp2) {
|
|
@@ -1917,15 +1546,11 @@ function buildGetNode(tables3, graphId, kind, id) {
|
|
|
1917
1546
|
}
|
|
1918
1547
|
function buildGetNodes(tables3, graphId, kind, ids) {
|
|
1919
1548
|
const { nodes: nodes2 } = tables3;
|
|
1920
|
-
const idPlaceholders = sql.join(
|
|
1921
|
-
ids.map((nodeId) => sql`${nodeId}`),
|
|
1922
|
-
sql`, `
|
|
1923
|
-
);
|
|
1924
1549
|
return sql`
|
|
1925
1550
|
SELECT * FROM ${nodes2}
|
|
1926
1551
|
WHERE ${nodes2.graphId} = ${graphId}
|
|
1927
1552
|
AND ${nodes2.kind} = ${kind}
|
|
1928
|
-
AND ${nodes2.id} IN (${
|
|
1553
|
+
AND ${nodes2.id} IN (${sqlValueList(ids)})
|
|
1929
1554
|
`;
|
|
1930
1555
|
}
|
|
1931
1556
|
function buildUpdateNode(tables3, params, timestamp2) {
|
|
@@ -2260,17 +1885,437 @@ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
|
|
|
2260
1885
|
buildSetActiveSchema(graphId, version) {
|
|
2261
1886
|
return buildSetActiveSchema(tables3, graphId, version, dialect);
|
|
2262
1887
|
},
|
|
1888
|
+
buildTableExists(tableName) {
|
|
1889
|
+
if (dialect === "postgres") {
|
|
1890
|
+
return sql`
|
|
1891
|
+
SELECT c.relname AS table_name
|
|
1892
|
+
FROM pg_catalog.pg_class AS c
|
|
1893
|
+
WHERE c.relname = ${tableName}
|
|
1894
|
+
AND c.relkind IN ('r', 'p', 'v', 'm', 'f')
|
|
1895
|
+
AND pg_catalog.pg_table_is_visible(c.oid)
|
|
1896
|
+
LIMIT 1
|
|
1897
|
+
`;
|
|
1898
|
+
}
|
|
1899
|
+
return sql`SELECT name AS table_name FROM sqlite_master WHERE type IN ('table', 'view') AND name = ${tableName}`;
|
|
1900
|
+
},
|
|
2263
1901
|
buildClearGraph(graphId) {
|
|
2264
1902
|
return buildClearGraph(tables3, graphId);
|
|
2265
1903
|
}
|
|
2266
1904
|
};
|
|
2267
1905
|
}
|
|
1906
|
+
function tableExistsFromRow(row) {
|
|
1907
|
+
if (row === void 0) return false;
|
|
1908
|
+
return Object.values(row).some((value) => isPresent(value));
|
|
1909
|
+
}
|
|
1910
|
+
function createCachedTableExistence(probe, options) {
|
|
1911
|
+
const cacheExisting = options?.cacheExisting !== false;
|
|
1912
|
+
const cacheMissing = options?.cacheMissing === true;
|
|
1913
|
+
const confirmedExisting = /* @__PURE__ */ new Set();
|
|
1914
|
+
const confirmedMissing = /* @__PURE__ */ new Set();
|
|
1915
|
+
return async function tableExists(tableName) {
|
|
1916
|
+
if (confirmedExisting.has(tableName)) return true;
|
|
1917
|
+
if (confirmedMissing.has(tableName)) return false;
|
|
1918
|
+
const exists = tableExistsFromRow(await probe(tableName));
|
|
1919
|
+
if (exists && cacheExisting) {
|
|
1920
|
+
confirmedExisting.add(tableName);
|
|
1921
|
+
}
|
|
1922
|
+
if (!exists && cacheMissing) {
|
|
1923
|
+
confirmedMissing.add(tableName);
|
|
1924
|
+
}
|
|
1925
|
+
return exists;
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
2268
1928
|
function createSqliteOperationStrategy(tables3, fulltextStrategy) {
|
|
2269
1929
|
return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
|
|
2270
1930
|
}
|
|
2271
1931
|
function createPostgresOperationStrategy(tables3, fulltextStrategy) {
|
|
2272
1932
|
return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
|
|
2273
1933
|
}
|
|
1934
|
+
function assertAdoptedDialect(externalTx, brand, backend) {
|
|
1935
|
+
if (is(externalTx, brand)) return;
|
|
1936
|
+
const label = backend === "postgres" ? "Postgres" : "SQLite";
|
|
1937
|
+
throw new ConfigurationError(
|
|
1938
|
+
`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.`,
|
|
1939
|
+
{ backend, capability: "adoptTransaction" }
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
1943
|
+
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
1944
|
+
if (actualActiveVersion !== expectedVersion) {
|
|
1945
|
+
throw new StaleVersionError({
|
|
1946
|
+
graphId,
|
|
1947
|
+
expected: expectedVersion,
|
|
1948
|
+
actual: actualActiveVersion
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function createCommonOperationBackend(options) {
|
|
1953
|
+
const { batchConfig, execution, operationStrategy, rowMappers } = options;
|
|
1954
|
+
const nowIso2 = options.nowIso ?? nowIso;
|
|
1955
|
+
const requiredClearTableExists = createCachedTableExistence(
|
|
1956
|
+
(tableName) => execution.execGet(
|
|
1957
|
+
operationStrategy.buildTableExists(tableName)
|
|
1958
|
+
),
|
|
1959
|
+
options.tableExistenceCache
|
|
1960
|
+
);
|
|
1961
|
+
async function runIgnorableClearStatement(statement) {
|
|
1962
|
+
if (statement.ignoreMissingTable === true && statement.requiredTableName !== void 0 && !await requiredClearTableExists(statement.requiredTableName)) {
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
await execution.execRun(statement.query);
|
|
1966
|
+
}
|
|
1967
|
+
async function readActiveVersion(graphId) {
|
|
1968
|
+
const row = await execution.execGet(
|
|
1969
|
+
operationStrategy.buildGetActiveSchema(graphId)
|
|
1970
|
+
);
|
|
1971
|
+
return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
|
|
1972
|
+
}
|
|
1973
|
+
return {
|
|
1974
|
+
async executeStatement(query) {
|
|
1975
|
+
await execution.execRun(query);
|
|
1976
|
+
},
|
|
1977
|
+
async insertNode(params) {
|
|
1978
|
+
const timestamp2 = nowIso2();
|
|
1979
|
+
const query = operationStrategy.buildInsertNode(params, timestamp2);
|
|
1980
|
+
const row = await execution.execGet(query);
|
|
1981
|
+
if (!row) throw new DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
|
|
1982
|
+
return rowMappers.toNodeRow(row);
|
|
1983
|
+
},
|
|
1984
|
+
async insertNodeNoReturn(params) {
|
|
1985
|
+
const timestamp2 = nowIso2();
|
|
1986
|
+
const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
|
|
1987
|
+
await execution.execRun(query);
|
|
1988
|
+
},
|
|
1989
|
+
async insertNodesBatch(params) {
|
|
1990
|
+
if (params.length === 0) {
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
const timestamp2 = nowIso2();
|
|
1994
|
+
for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
1995
|
+
const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp2);
|
|
1996
|
+
await execution.execRun(query);
|
|
1997
|
+
}
|
|
1998
|
+
},
|
|
1999
|
+
async insertNodesBatchReturning(params) {
|
|
2000
|
+
if (params.length === 0) {
|
|
2001
|
+
return [];
|
|
2002
|
+
}
|
|
2003
|
+
const timestamp2 = nowIso2();
|
|
2004
|
+
const allRows = [];
|
|
2005
|
+
for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
2006
|
+
const query = operationStrategy.buildInsertNodesBatchReturning(chunk2, timestamp2);
|
|
2007
|
+
const rows = await execution.execAll(query);
|
|
2008
|
+
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2009
|
+
}
|
|
2010
|
+
return allRows;
|
|
2011
|
+
},
|
|
2012
|
+
async getNode(graphId, kind, id) {
|
|
2013
|
+
const query = operationStrategy.buildGetNode(graphId, kind, id);
|
|
2014
|
+
const row = await execution.execGet(query);
|
|
2015
|
+
return row ? rowMappers.toNodeRow(row) : void 0;
|
|
2016
|
+
},
|
|
2017
|
+
async getNodes(graphId, kind, ids) {
|
|
2018
|
+
if (ids.length === 0) return [];
|
|
2019
|
+
const allRows = [];
|
|
2020
|
+
for (const chunk2 of chunk(ids, batchConfig.getNodesChunkSize)) {
|
|
2021
|
+
const query = operationStrategy.buildGetNodes(graphId, kind, chunk2);
|
|
2022
|
+
const rows = await execution.execAll(query);
|
|
2023
|
+
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2024
|
+
}
|
|
2025
|
+
return allRows;
|
|
2026
|
+
},
|
|
2027
|
+
async updateNode(params) {
|
|
2028
|
+
const timestamp2 = nowIso2();
|
|
2029
|
+
const query = operationStrategy.buildUpdateNode(params, timestamp2);
|
|
2030
|
+
const row = await execution.execGet(query);
|
|
2031
|
+
if (!row) throw new DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
|
|
2032
|
+
return rowMappers.toNodeRow(row);
|
|
2033
|
+
},
|
|
2034
|
+
async deleteNode(params) {
|
|
2035
|
+
const timestamp2 = nowIso2();
|
|
2036
|
+
const query = operationStrategy.buildDeleteNode(params, timestamp2);
|
|
2037
|
+
await execution.execRun(query);
|
|
2038
|
+
},
|
|
2039
|
+
// IMPORTANT: This cascade is not atomic. Callers must ensure this runs
|
|
2040
|
+
// within a transaction to prevent partial deletion on intermediate failure.
|
|
2041
|
+
//
|
|
2042
|
+
// Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
|
|
2043
|
+
// fieldPath)` strategy-owned tables addressable only with the slot
|
|
2044
|
+
// context the graph-agnostic backend lacks. The store's hard-delete
|
|
2045
|
+
// path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
|
|
2046
|
+
// resolves each embedding field and routes a per-field
|
|
2047
|
+
// `backend.deleteEmbedding` through the active vector strategy.
|
|
2048
|
+
async hardDeleteNode(params) {
|
|
2049
|
+
const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
|
|
2050
|
+
params.graphId,
|
|
2051
|
+
params.id
|
|
2052
|
+
);
|
|
2053
|
+
await execution.execRun(deleteUniquesQuery);
|
|
2054
|
+
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
2055
|
+
params.graphId,
|
|
2056
|
+
params.kind,
|
|
2057
|
+
params.id
|
|
2058
|
+
);
|
|
2059
|
+
for (const stmt of deleteFulltextStatements) {
|
|
2060
|
+
await execution.execRun(stmt);
|
|
2061
|
+
}
|
|
2062
|
+
const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
|
|
2063
|
+
params.graphId,
|
|
2064
|
+
params.kind,
|
|
2065
|
+
params.id
|
|
2066
|
+
);
|
|
2067
|
+
await execution.execRun(deleteEdgesQuery);
|
|
2068
|
+
const query = operationStrategy.buildHardDeleteNode(params);
|
|
2069
|
+
await execution.execRun(query);
|
|
2070
|
+
},
|
|
2071
|
+
async insertEdge(params) {
|
|
2072
|
+
const timestamp2 = nowIso2();
|
|
2073
|
+
const query = operationStrategy.buildInsertEdge(params, timestamp2);
|
|
2074
|
+
const row = await execution.execGet(query);
|
|
2075
|
+
if (!row) throw new DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
|
|
2076
|
+
return rowMappers.toEdgeRow(row);
|
|
2077
|
+
},
|
|
2078
|
+
async insertEdgeNoReturn(params) {
|
|
2079
|
+
const timestamp2 = nowIso2();
|
|
2080
|
+
const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
|
|
2081
|
+
await execution.execRun(query);
|
|
2082
|
+
},
|
|
2083
|
+
async insertEdgesBatch(params) {
|
|
2084
|
+
if (params.length === 0) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
const timestamp2 = nowIso2();
|
|
2088
|
+
for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2089
|
+
const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp2);
|
|
2090
|
+
await execution.execRun(query);
|
|
2091
|
+
}
|
|
2092
|
+
},
|
|
2093
|
+
async insertEdgesBatchReturning(params) {
|
|
2094
|
+
if (params.length === 0) {
|
|
2095
|
+
return [];
|
|
2096
|
+
}
|
|
2097
|
+
const timestamp2 = nowIso2();
|
|
2098
|
+
const allRows = [];
|
|
2099
|
+
for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2100
|
+
const query = operationStrategy.buildInsertEdgesBatchReturning(chunk2, timestamp2);
|
|
2101
|
+
const rows = await execution.execAll(query);
|
|
2102
|
+
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2103
|
+
}
|
|
2104
|
+
return allRows;
|
|
2105
|
+
},
|
|
2106
|
+
async getEdge(graphId, id) {
|
|
2107
|
+
const query = operationStrategy.buildGetEdge(graphId, id);
|
|
2108
|
+
const row = await execution.execGet(query);
|
|
2109
|
+
return row ? rowMappers.toEdgeRow(row) : void 0;
|
|
2110
|
+
},
|
|
2111
|
+
async getEdges(graphId, ids) {
|
|
2112
|
+
if (ids.length === 0) return [];
|
|
2113
|
+
const allRows = [];
|
|
2114
|
+
for (const chunk2 of chunk(ids, batchConfig.getEdgesChunkSize)) {
|
|
2115
|
+
const query = operationStrategy.buildGetEdges(graphId, chunk2);
|
|
2116
|
+
const rows = await execution.execAll(query);
|
|
2117
|
+
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2118
|
+
}
|
|
2119
|
+
return allRows;
|
|
2120
|
+
},
|
|
2121
|
+
async updateEdge(params) {
|
|
2122
|
+
const timestamp2 = nowIso2();
|
|
2123
|
+
const query = operationStrategy.buildUpdateEdge(params, timestamp2);
|
|
2124
|
+
const row = await execution.execGet(query);
|
|
2125
|
+
if (!row) throw new DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
|
|
2126
|
+
return rowMappers.toEdgeRow(row);
|
|
2127
|
+
},
|
|
2128
|
+
async deleteEdge(params) {
|
|
2129
|
+
const timestamp2 = nowIso2();
|
|
2130
|
+
const query = operationStrategy.buildDeleteEdge(params, timestamp2);
|
|
2131
|
+
await execution.execRun(query);
|
|
2132
|
+
},
|
|
2133
|
+
async hardDeleteEdge(params) {
|
|
2134
|
+
const query = operationStrategy.buildHardDeleteEdge(params);
|
|
2135
|
+
await execution.execRun(query);
|
|
2136
|
+
},
|
|
2137
|
+
async countEdgesFrom(params) {
|
|
2138
|
+
const query = operationStrategy.buildCountEdgesFrom(params);
|
|
2139
|
+
const row = await execution.execGet(query);
|
|
2140
|
+
return Number(row?.count ?? 0);
|
|
2141
|
+
},
|
|
2142
|
+
async edgeExistsBetween(params) {
|
|
2143
|
+
const query = operationStrategy.buildEdgeExistsBetween(params);
|
|
2144
|
+
const row = await execution.execGet(query);
|
|
2145
|
+
return row !== void 0;
|
|
2146
|
+
},
|
|
2147
|
+
async findEdgesConnectedTo(params) {
|
|
2148
|
+
const query = operationStrategy.buildFindEdgesConnectedTo(params);
|
|
2149
|
+
const rows = await execution.execAll(query);
|
|
2150
|
+
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2151
|
+
},
|
|
2152
|
+
async findNodesByKind(params) {
|
|
2153
|
+
const query = operationStrategy.buildFindNodesByKind(params);
|
|
2154
|
+
const rows = await execution.execAll(query);
|
|
2155
|
+
return rows.map((row) => rowMappers.toNodeRow(row));
|
|
2156
|
+
},
|
|
2157
|
+
async countNodesByKind(params) {
|
|
2158
|
+
const query = operationStrategy.buildCountNodesByKind(params);
|
|
2159
|
+
const row = await execution.execGet(query);
|
|
2160
|
+
return Number(row?.count ?? 0);
|
|
2161
|
+
},
|
|
2162
|
+
async findEdgesByKind(params) {
|
|
2163
|
+
const query = operationStrategy.buildFindEdgesByKind(params);
|
|
2164
|
+
const rows = await execution.execAll(query);
|
|
2165
|
+
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2166
|
+
},
|
|
2167
|
+
async countEdgesByKind(params) {
|
|
2168
|
+
const query = operationStrategy.buildCountEdgesByKind(params);
|
|
2169
|
+
const row = await execution.execGet(query);
|
|
2170
|
+
return Number(row?.count ?? 0);
|
|
2171
|
+
},
|
|
2172
|
+
async insertUnique(params) {
|
|
2173
|
+
const query = operationStrategy.buildInsertUnique(params);
|
|
2174
|
+
const result = await execution.execGet(query);
|
|
2175
|
+
if (result && result.node_id !== params.nodeId) {
|
|
2176
|
+
throw new UniquenessError({
|
|
2177
|
+
constraintName: params.constraintName,
|
|
2178
|
+
kind: params.nodeKind,
|
|
2179
|
+
existingId: result.node_id,
|
|
2180
|
+
newId: params.nodeId,
|
|
2181
|
+
fields: []
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
},
|
|
2185
|
+
async deleteUnique(params) {
|
|
2186
|
+
const timestamp2 = nowIso2();
|
|
2187
|
+
const query = operationStrategy.buildDeleteUnique(params, timestamp2);
|
|
2188
|
+
await execution.execRun(query);
|
|
2189
|
+
},
|
|
2190
|
+
async checkUnique(params) {
|
|
2191
|
+
const query = operationStrategy.buildCheckUnique(params);
|
|
2192
|
+
const row = await execution.execGet(query);
|
|
2193
|
+
return row ? rowMappers.toUniqueRow(row) : void 0;
|
|
2194
|
+
},
|
|
2195
|
+
async checkUniqueBatch(params) {
|
|
2196
|
+
if (params.keys.length === 0) return [];
|
|
2197
|
+
const allRows = [];
|
|
2198
|
+
for (const chunk2 of chunk(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
|
|
2199
|
+
const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk2 });
|
|
2200
|
+
const rows = await execution.execAll(query);
|
|
2201
|
+
allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
|
|
2202
|
+
}
|
|
2203
|
+
return allRows;
|
|
2204
|
+
},
|
|
2205
|
+
async getActiveSchema(graphId) {
|
|
2206
|
+
const query = operationStrategy.buildGetActiveSchema(graphId);
|
|
2207
|
+
const row = await execution.execGet(query);
|
|
2208
|
+
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
2209
|
+
},
|
|
2210
|
+
async getSchemaVersion(graphId, version) {
|
|
2211
|
+
const query = operationStrategy.buildGetSchemaVersion(graphId, version);
|
|
2212
|
+
const row = await execution.execGet(query);
|
|
2213
|
+
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
2214
|
+
},
|
|
2215
|
+
async commitSchemaVersion(params) {
|
|
2216
|
+
const existingRaw = await execution.execGet(
|
|
2217
|
+
operationStrategy.buildGetSchemaVersion(
|
|
2218
|
+
params.graphId,
|
|
2219
|
+
params.version
|
|
2220
|
+
)
|
|
2221
|
+
);
|
|
2222
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
2223
|
+
if (existingRaw !== void 0) {
|
|
2224
|
+
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
2225
|
+
if (existing.schema_hash !== params.schemaHash) {
|
|
2226
|
+
throw new SchemaContentConflictError({
|
|
2227
|
+
graphId: params.graphId,
|
|
2228
|
+
version: params.version,
|
|
2229
|
+
existingHash: existing.schema_hash,
|
|
2230
|
+
incomingHash: params.schemaHash
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
if (existing.is_active) {
|
|
2234
|
+
return existing;
|
|
2235
|
+
}
|
|
2236
|
+
verifyExpectedActiveVersion(
|
|
2237
|
+
params.graphId,
|
|
2238
|
+
params.expected,
|
|
2239
|
+
actualActiveVersion
|
|
2240
|
+
);
|
|
2241
|
+
const reactivate = operationStrategy.buildSetActiveSchema(
|
|
2242
|
+
params.graphId,
|
|
2243
|
+
params.version
|
|
2244
|
+
);
|
|
2245
|
+
await execution.execRun(reactivate.deactivateAll);
|
|
2246
|
+
await execution.execRun(reactivate.activateVersion);
|
|
2247
|
+
return { ...existing, is_active: true };
|
|
2248
|
+
}
|
|
2249
|
+
verifyExpectedActiveVersion(
|
|
2250
|
+
params.graphId,
|
|
2251
|
+
params.expected,
|
|
2252
|
+
actualActiveVersion
|
|
2253
|
+
);
|
|
2254
|
+
if (params.expected.kind === "active") {
|
|
2255
|
+
const flip = operationStrategy.buildSetActiveSchema(
|
|
2256
|
+
params.graphId,
|
|
2257
|
+
params.version
|
|
2258
|
+
);
|
|
2259
|
+
await execution.execRun(flip.deactivateAll);
|
|
2260
|
+
}
|
|
2261
|
+
const timestamp2 = nowIso2();
|
|
2262
|
+
const insertQuery = operationStrategy.buildInsertSchema(
|
|
2263
|
+
{
|
|
2264
|
+
graphId: params.graphId,
|
|
2265
|
+
version: params.version,
|
|
2266
|
+
schemaHash: params.schemaHash,
|
|
2267
|
+
schemaDoc: params.schemaDoc,
|
|
2268
|
+
isActive: true
|
|
2269
|
+
},
|
|
2270
|
+
timestamp2
|
|
2271
|
+
);
|
|
2272
|
+
const insertedRaw = await execution.execGet(insertQuery);
|
|
2273
|
+
if (!insertedRaw) {
|
|
2274
|
+
throw new DatabaseOperationError(
|
|
2275
|
+
"Insert schema failed: no row returned",
|
|
2276
|
+
{ operation: "insert", entity: "schema" }
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
return rowMappers.toSchemaVersionRow(insertedRaw);
|
|
2280
|
+
},
|
|
2281
|
+
async setActiveVersion(params) {
|
|
2282
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
2283
|
+
verifyExpectedActiveVersion(
|
|
2284
|
+
params.graphId,
|
|
2285
|
+
params.expected,
|
|
2286
|
+
actualActiveVersion
|
|
2287
|
+
);
|
|
2288
|
+
const targetRaw = await execution.execGet(
|
|
2289
|
+
operationStrategy.buildGetSchemaVersion(
|
|
2290
|
+
params.graphId,
|
|
2291
|
+
params.version
|
|
2292
|
+
)
|
|
2293
|
+
);
|
|
2294
|
+
if (!targetRaw) {
|
|
2295
|
+
throw new MigrationError(
|
|
2296
|
+
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
2297
|
+
{
|
|
2298
|
+
graphId: params.graphId,
|
|
2299
|
+
fromVersion: actualActiveVersion,
|
|
2300
|
+
toVersion: params.version
|
|
2301
|
+
}
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
const queries = operationStrategy.buildSetActiveSchema(
|
|
2305
|
+
params.graphId,
|
|
2306
|
+
params.version
|
|
2307
|
+
);
|
|
2308
|
+
await execution.execRun(queries.deactivateAll);
|
|
2309
|
+
await execution.execRun(queries.activateVersion);
|
|
2310
|
+
},
|
|
2311
|
+
async clearGraph(graphId) {
|
|
2312
|
+
const statements = operationStrategy.buildClearGraph(graphId);
|
|
2313
|
+
for (const statement of statements) {
|
|
2314
|
+
await runIgnorableClearStatement(statement);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2274
2319
|
|
|
2275
2320
|
// src/backend/drizzle/execution/lru.ts
|
|
2276
2321
|
function getOrCreateLru(cache, key, cacheMax, create) {
|
|
@@ -2299,6 +2344,6 @@ function compileQueryWithDialect(db, query, backendName) {
|
|
|
2299
2344
|
return compiler.sqlToQuery(query);
|
|
2300
2345
|
}
|
|
2301
2346
|
|
|
2302
|
-
export { POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS,
|
|
2303
|
-
//# sourceMappingURL=chunk-
|
|
2304
|
-
//# sourceMappingURL=chunk-
|
|
2347
|
+
export { POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS, SQLITE_CONTRIBUTION_MAT_TIMESTAMPS, SQLITE_INDEX_MAT_TIMESTAMPS, SQLITE_KIND_REMOVAL_TIMESTAMPS, assertAdoptedDialect, buildContributionInsertValues, buildContributionOnConflictSet, buildKindRemovalInsertValues, buildKindRemovalOnConflictSet, buildMaterializationInsertValues, buildMaterializationOnConflictSet, compileQueryWithDialect, createCachedTableExistence, createCommonOperationBackend, createContributionMaterializer, createPostgresOperationStrategy, createPostgresTables, createSqliteOperationStrategy, createVectorSlotLatch, edges, fulltext, gateFulltext, gateFulltextMethods, generatePgCreateTableSQL, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteCreateTableSQL, generateSqliteDDL, generateSqliteMigrationSQL, getOrCreateLru, mapContributionMaterializationRow, mapKindRemovalRow, mapMaterializationRow, mapVectorWriteError, nodes, recordedClock, recordedEdges, recordedNodes, schemaVersions, tables2 as tables, uniques, vectorSlotFromCreateIndexParams, vectorSlotFromDropIndexParams, vectorSlotFromParams };
|
|
2348
|
+
//# sourceMappingURL=chunk-UPDMJEW6.js.map
|
|
2349
|
+
//# sourceMappingURL=chunk-UPDMJEW6.js.map
|