@nicia-ai/typegraph 0.32.0 → 0.34.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 +51 -0
- package/dist/backend/postgres/index.cjs +36 -19
- package/dist/backend/postgres/index.d.cts +6 -6
- package/dist/backend/postgres/index.d.ts +6 -6
- package/dist/backend/postgres/index.js +14 -9
- package/dist/backend/postgres/pglite.cjs +18 -13
- 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 +14 -9
- package/dist/backend/postgres/pglite.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +34 -17
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +13 -8
- package/dist/backend/sqlite/libsql.cjs +19 -14
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +12 -5
- package/dist/backend/sqlite/libsql.d.ts +12 -5
- package/dist/backend/sqlite/libsql.js +15 -10
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +19 -14
- 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 +14 -9
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/chunk-2EBMPJBO.js +16 -0
- package/dist/chunk-2EBMPJBO.js.map +1 -0
- package/dist/{chunk-CFNT3ITG.cjs → chunk-2JXB3NYJ.cjs} +15 -35
- package/dist/chunk-2JXB3NYJ.cjs.map +1 -0
- package/dist/chunk-2MRAX3UE.js +105 -0
- package/dist/chunk-2MRAX3UE.js.map +1 -0
- package/dist/{chunk-2LAT5BIK.cjs → chunk-3BRVBQQD.cjs} +2328 -3131
- package/dist/chunk-3BRVBQQD.cjs.map +1 -0
- package/dist/chunk-3E7SNSIA.cjs +55 -0
- package/dist/chunk-3E7SNSIA.cjs.map +1 -0
- package/dist/{chunk-FDN43KXV.cjs → chunk-3Z6TW3CT.cjs} +20 -19
- package/dist/chunk-3Z6TW3CT.cjs.map +1 -0
- package/dist/{chunk-IJORSAC3.js → chunk-4DIBPQNJ.js} +6 -4
- package/dist/chunk-4DIBPQNJ.js.map +1 -0
- package/dist/chunk-4S2FXGBJ.js +9 -0
- package/dist/chunk-4S2FXGBJ.js.map +1 -0
- package/dist/chunk-5IQIX7LU.cjs +2070 -0
- package/dist/chunk-5IQIX7LU.cjs.map +1 -0
- package/dist/{chunk-CWFPJ3RC.js → chunk-6GNSY7AV.js} +3 -3
- package/dist/{chunk-CWFPJ3RC.js.map → chunk-6GNSY7AV.js.map} +1 -1
- package/dist/{chunk-LAZGHOZW.cjs → chunk-6HVOHZHS.cjs} +184 -117
- package/dist/chunk-6HVOHZHS.cjs.map +1 -0
- package/dist/chunk-6SCVW4AS.js +20 -0
- package/dist/chunk-6SCVW4AS.js.map +1 -0
- package/dist/chunk-A7SZZFAG.js +2010 -0
- package/dist/chunk-A7SZZFAG.js.map +1 -0
- package/dist/chunk-ACSVZPK7.cjs +21 -0
- package/dist/chunk-ACSVZPK7.cjs.map +1 -0
- package/dist/{chunk-MXE2U3EX.js → chunk-BVTWD66D.js} +4 -115
- package/dist/chunk-BVTWD66D.js.map +1 -0
- package/dist/{chunk-W4ZX2GCP.js → chunk-CHXTTSC6.js} +5 -39
- package/dist/chunk-CHXTTSC6.js.map +1 -0
- package/dist/{chunk-XQFAJVYW.js → chunk-CYX2JTDG.js} +124 -5
- package/dist/chunk-CYX2JTDG.js.map +1 -0
- package/dist/{chunk-PRMKPFN5.js → chunk-DEQFL35G.js} +4 -3
- package/dist/chunk-DEQFL35G.js.map +1 -0
- package/dist/chunk-DI74SMXS.cjs +29 -0
- package/dist/chunk-DI74SMXS.cjs.map +1 -0
- package/dist/{chunk-WWVV44DY.cjs → chunk-G6SOJEDI.cjs} +11 -11
- package/dist/{chunk-WWVV44DY.cjs.map → chunk-G6SOJEDI.cjs.map} +1 -1
- package/dist/{chunk-LM2IC4ZJ.cjs → chunk-GQANNXXT.cjs} +15 -14
- package/dist/chunk-GQANNXXT.cjs.map +1 -0
- package/dist/chunk-GZCNZ7QW.js +24 -0
- package/dist/chunk-GZCNZ7QW.js.map +1 -0
- package/dist/{chunk-KTIEB7VH.cjs → chunk-HK5SATYM.cjs} +35 -58
- package/dist/chunk-HK5SATYM.cjs.map +1 -0
- package/dist/chunk-HMFK4BXR.cjs +12 -0
- package/dist/{chunk-6ZR4QC3O.cjs.map → chunk-HMFK4BXR.cjs.map} +1 -1
- package/dist/chunk-ITE4IXAK.js +25 -0
- package/dist/chunk-ITE4IXAK.js.map +1 -0
- package/dist/chunk-JJRCLAUN.cjs +155 -0
- package/dist/chunk-JJRCLAUN.cjs.map +1 -0
- package/dist/{chunk-ZFWNO3GE.cjs → chunk-JQGIPGVL.cjs} +66 -2
- package/dist/chunk-JQGIPGVL.cjs.map +1 -0
- package/dist/{chunk-2BVHPOIG.js → chunk-K2TGS3EN.js} +105 -38
- package/dist/chunk-K2TGS3EN.js.map +1 -0
- package/dist/chunk-K34OPSJK.js +29 -0
- package/dist/chunk-K34OPSJK.js.map +1 -0
- package/dist/{chunk-YW7GHMF4.cjs → chunk-KGC4LY5T.cjs} +18 -17
- package/dist/chunk-KGC4LY5T.cjs.map +1 -0
- package/dist/{chunk-SB65GJNY.cjs → chunk-KNHYNQQ3.cjs} +111 -72
- package/dist/chunk-KNHYNQQ3.cjs.map +1 -0
- package/dist/{chunk-C4C4Q7A6.js → chunk-KUTNI6SI.js} +6 -21
- package/dist/chunk-KUTNI6SI.js.map +1 -0
- package/dist/{chunk-NDM5PXEH.js → chunk-LANHCOXB.js} +44 -11
- package/dist/chunk-LANHCOXB.js.map +1 -0
- package/dist/chunk-N6WTUSBV.cjs +23 -0
- package/dist/chunk-N6WTUSBV.cjs.map +1 -0
- package/dist/{chunk-73KASJGO.cjs → chunk-NAUA4PW5.cjs} +4 -28
- package/dist/chunk-NAUA4PW5.cjs.map +1 -0
- package/dist/chunk-QV245VMN.js +145 -0
- package/dist/chunk-QV245VMN.js.map +1 -0
- package/dist/{chunk-CEF2QOTO.js → chunk-RBV7YCQD.js} +4 -3
- package/dist/chunk-RBV7YCQD.js.map +1 -0
- package/dist/chunk-RHZWOJVA.cjs +109 -0
- package/dist/chunk-RHZWOJVA.cjs.map +1 -0
- package/dist/{chunk-6RMLO5O4.cjs → chunk-RRKQAKD6.cjs} +13 -11
- package/dist/chunk-RRKQAKD6.cjs.map +1 -0
- package/dist/{chunk-TUA3MEJJ.js → chunk-RY2VIWAM.js} +612 -564
- package/dist/chunk-RY2VIWAM.js.map +1 -0
- package/dist/{chunk-PIHXFF73.js → chunk-SHLY4MCM.js} +3 -3
- package/dist/{chunk-PIHXFF73.js.map → chunk-SHLY4MCM.js.map} +1 -1
- package/dist/{chunk-HFBRAOF7.js → chunk-T2DWPQNE.js} +103 -64
- package/dist/chunk-T2DWPQNE.js.map +1 -0
- package/dist/{chunk-WYTUF3QO.js → chunk-T46GR2VY.js} +3 -3
- package/dist/{chunk-WYTUF3QO.js.map → chunk-T46GR2VY.js.map} +1 -1
- package/dist/{chunk-EEYV6UOE.cjs → chunk-T6SPUYLX.cjs} +5 -43
- package/dist/chunk-T6SPUYLX.cjs.map +1 -0
- package/dist/{chunk-3QRBXYT5.cjs → chunk-TGJE22RM.cjs} +6 -6
- package/dist/{chunk-3QRBXYT5.cjs.map → chunk-TGJE22RM.cjs.map} +1 -1
- package/dist/{chunk-YL4F3CMD.cjs → chunk-TOTPVGOG.cjs} +105 -72
- package/dist/chunk-TOTPVGOG.cjs.map +1 -0
- package/dist/{chunk-3HQDMOBK.cjs → chunk-UJLOZYKT.cjs} +680 -636
- package/dist/chunk-UJLOZYKT.cjs.map +1 -0
- package/dist/chunk-UNNPKQUG.cjs +1390 -0
- package/dist/chunk-UNNPKQUG.cjs.map +1 -0
- package/dist/chunk-UR7W5YQK.js +18 -0
- package/dist/chunk-UR7W5YQK.js.map +1 -0
- package/dist/chunk-V3QNTB7Z.js +1351 -0
- package/dist/chunk-V3QNTB7Z.js.map +1 -0
- package/dist/{chunk-XKNAK27R.js → chunk-VCGO4V26.js} +4 -3
- package/dist/chunk-VCGO4V26.js.map +1 -0
- package/dist/{chunk-YQGLVWB2.cjs → chunk-WL2SG7ZV.cjs} +6 -122
- package/dist/chunk-WL2SG7ZV.cjs.map +1 -0
- package/dist/{chunk-WNORITK6.js → chunk-WLRIWYHQ.js} +2041 -2834
- package/dist/chunk-WLRIWYHQ.js.map +1 -0
- package/dist/{chunk-JKRKIEVA.cjs → chunk-WVC2Q2FD.cjs} +128 -6
- package/dist/chunk-WVC2Q2FD.cjs.map +1 -0
- package/dist/chunk-XLUNB2TZ.js +53 -0
- package/dist/chunk-XLUNB2TZ.js.map +1 -0
- package/dist/chunk-XXVEULWX.js +39 -0
- package/dist/chunk-XXVEULWX.js.map +1 -0
- package/dist/chunk-YAZE7QZR.cjs +32 -0
- package/dist/chunk-YAZE7QZR.cjs.map +1 -0
- package/dist/chunk-YC6PWTHY.cjs +44 -0
- package/dist/chunk-YC6PWTHY.cjs.map +1 -0
- package/dist/chunk-Z5HBYM7U.cjs +11 -0
- package/dist/chunk-Z5HBYM7U.cjs.map +1 -0
- package/dist/{chunk-454I6GDF.js → chunk-Z5XBMDXU.js} +63 -3
- package/dist/chunk-Z5XBMDXU.js.map +1 -0
- package/dist/{chunk-CAMMC3E4.cjs → chunk-ZP5WHI4C.cjs} +109 -81
- package/dist/chunk-ZP5WHI4C.cjs.map +1 -0
- package/dist/{chunk-YCV72E6L.js → chunk-ZURTTSCM.js} +4 -25
- package/dist/chunk-ZURTTSCM.js.map +1 -0
- package/dist/{chunk-7WW3WL6E.js → chunk-ZV5N4DBG.js} +49 -21
- package/dist/chunk-ZV5N4DBG.js.map +1 -0
- package/dist/chunk-ZY4GXIVN.cjs +32 -0
- package/dist/chunk-ZY4GXIVN.cjs.map +1 -0
- package/dist/{ddl-C8e8zDAE.d.ts → ddl-BrmPg61z.d.ts} +3 -3
- package/dist/{ddl-CwyG4HoQ.d.cts → ddl-j1-sH6lE.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.cjs +18 -17
- 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 -2
- package/dist/graph-merge/index.cjs +295 -146
- 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 +173 -24
- 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 +206 -172
- 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 +32 -22
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +28 -25
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +10 -7
- package/dist/interchange/index.cjs +25 -16
- package/dist/interchange/index.d.cts +5 -5
- package/dist/interchange/index.d.ts +5 -5
- package/dist/interchange/index.js +12 -3
- package/dist/{manager-8htmuGr-.d.ts → manager-BZUeN_BU.d.ts} +2 -2
- package/dist/{manager-aVgxbGt-.d.cts → manager-ms9cKdc6.d.cts} +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-Dhom7iiX.d.ts → postgres-BhpxGMC5.d.cts} +2651 -596
- package/dist/{postgres-jgXmD45C.d.cts → postgres-CWHLwNl1.d.ts} +2651 -596
- package/dist/profiler/index.cjs +5 -4
- 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 +3 -2
- package/dist/profiler/index.js.map +1 -1
- package/dist/provenance/index.cjs +591 -0
- package/dist/provenance/index.cjs.map +1 -0
- package/dist/provenance/index.d.cts +73 -0
- package/dist/provenance/index.d.ts +73 -0
- package/dist/provenance/index.js +589 -0
- package/dist/provenance/index.js.map +1 -0
- package/dist/schema/index.cjs +37 -32
- 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 +14 -9
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-DcQ_BCUW.d.cts → sqlite-CGu5SLsw.d.ts} +2726 -455
- package/dist/{sqlite-BfLsCEqO.d.ts → sqlite-XrDxNaa7.d.cts} +2726 -455
- package/dist/{store-view-pBOUrQte.d.ts → store-view-BlgnhEYf.d.ts} +467 -131
- package/dist/{store-view-lTcb_cnp.d.cts → store-view-D09po4H6.d.cts} +467 -131
- package/dist/{types-DGDiXAYc.d.ts → types-B1TbZJYS.d.ts} +2 -2
- package/dist/{types-Dk8r09KY.d.ts → types-D1Sqeyxy.d.ts} +161 -26
- package/dist/{types-5RQwzWXx.d.cts → types-DiE1AO7p.d.cts} +2 -2
- package/dist/{types-Dvmn-eal.d.cts → types-DkNnF-7K.d.cts} +161 -26
- package/dist/{where-Cx_glEEB.d.cts → where-DKjuofPr.d.cts} +2 -2
- package/dist/{where-CHZFELX0.d.ts → where-DrUIIWHb.d.ts} +2 -2
- package/package.json +8 -2
- package/dist/chunk-2BVHPOIG.js.map +0 -1
- package/dist/chunk-2LAT5BIK.cjs.map +0 -1
- package/dist/chunk-2YMGNYXY.js +0 -40
- package/dist/chunk-2YMGNYXY.js.map +0 -1
- package/dist/chunk-3HQDMOBK.cjs.map +0 -1
- package/dist/chunk-454I6GDF.js.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-6ZR4QC3O.cjs +0 -12
- package/dist/chunk-73KASJGO.cjs.map +0 -1
- package/dist/chunk-7WW3WL6E.js.map +0 -1
- package/dist/chunk-C4C4Q7A6.js.map +0 -1
- package/dist/chunk-CAMMC3E4.cjs.map +0 -1
- package/dist/chunk-CEF2QOTO.js.map +0 -1
- package/dist/chunk-CFNT3ITG.cjs.map +0 -1
- package/dist/chunk-EEYV6UOE.cjs.map +0 -1
- package/dist/chunk-FDN43KXV.cjs.map +0 -1
- package/dist/chunk-HFBRAOF7.js.map +0 -1
- package/dist/chunk-IJORSAC3.js.map +0 -1
- package/dist/chunk-JKRKIEVA.cjs.map +0 -1
- package/dist/chunk-KTIEB7VH.cjs.map +0 -1
- package/dist/chunk-LAZGHOZW.cjs.map +0 -1
- package/dist/chunk-LM2IC4ZJ.cjs.map +0 -1
- package/dist/chunk-M6OC455F.js +0 -65
- package/dist/chunk-M6OC455F.js.map +0 -1
- package/dist/chunk-MXE2U3EX.js.map +0 -1
- package/dist/chunk-NDM5PXEH.js.map +0 -1
- package/dist/chunk-PRMKPFN5.js.map +0 -1
- package/dist/chunk-RP7YITHX.cjs +0 -70
- package/dist/chunk-RP7YITHX.cjs.map +0 -1
- package/dist/chunk-SAJSMR2B.js +0 -35
- package/dist/chunk-SAJSMR2B.js.map +0 -1
- package/dist/chunk-SB65GJNY.cjs.map +0 -1
- package/dist/chunk-TUA3MEJJ.js.map +0 -1
- package/dist/chunk-W4ZX2GCP.js.map +0 -1
- package/dist/chunk-WNORITK6.js.map +0 -1
- package/dist/chunk-XKNAK27R.js.map +0 -1
- package/dist/chunk-XQFAJVYW.js.map +0 -1
- package/dist/chunk-YCV72E6L.js.map +0 -1
- package/dist/chunk-YL4F3CMD.cjs.map +0 -1
- package/dist/chunk-YQGLVWB2.cjs.map +0 -1
- package/dist/chunk-YW7GHMF4.cjs.map +0 -1
- package/dist/chunk-ZFWNO3GE.cjs.map +0 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { tables } from './chunk-
|
|
2
|
-
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { tables } from './chunk-CYX2JTDG.js';
|
|
2
|
+
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders } from './chunk-6GNSY7AV.js';
|
|
3
|
+
import { formatPostgresTimestamp, nowIso } from './chunk-QV245VMN.js';
|
|
4
|
+
import { sortedReplacer } from './chunk-UR7W5YQK.js';
|
|
5
|
+
import { tsvectorStrategy, fts5Strategy, BASE_CONTRIBUTION_OWNER } from './chunk-KUTNI6SI.js';
|
|
6
|
+
import { sha256Hex } from './chunk-K34OPSJK.js';
|
|
7
|
+
import { createBackendOverlay, chunk, isPresent, sqlValueList } from './chunk-V3QNTB7Z.js';
|
|
8
|
+
import { parseDimensionMismatch, isMissingTableError } from './chunk-2MRAX3UE.js';
|
|
9
|
+
import { quotedTableName, quotedColumn, edgeColumnList, sqlNull, nodeColumnList } from './chunk-GZCNZ7QW.js';
|
|
10
|
+
import { EmbeddingDimensionChangedError, ConfigurationError, MigrationError, SchemaContentConflictError, DatabaseOperationError, UniquenessError, StoreNotInitializedError, StaleVersionError } from './chunk-TQOYM4LN.js';
|
|
7
11
|
import { sql, is, getTableName } from 'drizzle-orm';
|
|
8
12
|
import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, uniqueIndex, getTableConfig as getTableConfig$1, PgTable } from 'drizzle-orm/pg-core';
|
|
9
13
|
import { getTableConfig, SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
@@ -19,6 +23,9 @@ var tsvector = customType({
|
|
|
19
23
|
var DEFAULT_TABLE_NAMES = {
|
|
20
24
|
nodes: "typegraph_nodes",
|
|
21
25
|
edges: "typegraph_edges",
|
|
26
|
+
recordedNodes: "typegraph_recorded_nodes",
|
|
27
|
+
recordedEdges: "typegraph_recorded_edges",
|
|
28
|
+
recordedClock: "typegraph_recorded_clock",
|
|
22
29
|
uniques: "typegraph_node_uniques",
|
|
23
30
|
schemaVersions: "typegraph_schema_versions",
|
|
24
31
|
fulltext: "typegraph_node_fulltext",
|
|
@@ -117,6 +124,111 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
117
124
|
...buildPostgresEdgeIndexBuilders(t, indexes)
|
|
118
125
|
]
|
|
119
126
|
);
|
|
127
|
+
const recordedNodes2 = pgTable(
|
|
128
|
+
n.recordedNodes,
|
|
129
|
+
{
|
|
130
|
+
historyId: text("history_id").notNull(),
|
|
131
|
+
graphId: text("graph_id").notNull(),
|
|
132
|
+
kind: text("kind").notNull(),
|
|
133
|
+
id: text("id").notNull(),
|
|
134
|
+
props: jsonb("props").notNull(),
|
|
135
|
+
version: integer("version").notNull(),
|
|
136
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
137
|
+
validTo: timestamp("valid_to", { withTimezone: true }),
|
|
138
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
139
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
140
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
141
|
+
recordedFrom: timestamp("recorded_from", { withTimezone: true }).notNull(),
|
|
142
|
+
recordedTo: timestamp("recorded_to", { withTimezone: true }).notNull(),
|
|
143
|
+
op: text("op").notNull(),
|
|
144
|
+
schemaVersion: integer("schema_version"),
|
|
145
|
+
txId: text("tx_id"),
|
|
146
|
+
meta: jsonb("meta")
|
|
147
|
+
},
|
|
148
|
+
(t) => [
|
|
149
|
+
primaryKey({ columns: [t.historyId] }),
|
|
150
|
+
index(`${n.recordedNodes}_entity_idx`).on(
|
|
151
|
+
t.graphId,
|
|
152
|
+
t.kind,
|
|
153
|
+
t.id,
|
|
154
|
+
t.recordedFrom,
|
|
155
|
+
t.recordedTo
|
|
156
|
+
),
|
|
157
|
+
index(`${n.recordedNodes}_open_idx`).on(t.graphId, t.recordedTo),
|
|
158
|
+
index(`${n.recordedNodes}_valid_idx`).on(
|
|
159
|
+
t.graphId,
|
|
160
|
+
t.validFrom,
|
|
161
|
+
t.validTo
|
|
162
|
+
)
|
|
163
|
+
]
|
|
164
|
+
);
|
|
165
|
+
const recordedEdges2 = pgTable(
|
|
166
|
+
n.recordedEdges,
|
|
167
|
+
{
|
|
168
|
+
historyId: text("history_id").notNull(),
|
|
169
|
+
graphId: text("graph_id").notNull(),
|
|
170
|
+
id: text("id").notNull(),
|
|
171
|
+
kind: text("kind").notNull(),
|
|
172
|
+
fromKind: text("from_kind").notNull(),
|
|
173
|
+
fromId: text("from_id").notNull(),
|
|
174
|
+
toKind: text("to_kind").notNull(),
|
|
175
|
+
toId: text("to_id").notNull(),
|
|
176
|
+
props: jsonb("props").notNull(),
|
|
177
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
178
|
+
validTo: timestamp("valid_to", { withTimezone: true }),
|
|
179
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
180
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
181
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true }),
|
|
182
|
+
recordedFrom: timestamp("recorded_from", { withTimezone: true }).notNull(),
|
|
183
|
+
recordedTo: timestamp("recorded_to", { withTimezone: true }).notNull(),
|
|
184
|
+
op: text("op").notNull(),
|
|
185
|
+
schemaVersion: integer("schema_version"),
|
|
186
|
+
txId: text("tx_id"),
|
|
187
|
+
meta: jsonb("meta")
|
|
188
|
+
},
|
|
189
|
+
(t) => [
|
|
190
|
+
primaryKey({ columns: [t.historyId] }),
|
|
191
|
+
index(`${n.recordedEdges}_entity_idx`).on(
|
|
192
|
+
t.graphId,
|
|
193
|
+
t.kind,
|
|
194
|
+
t.id,
|
|
195
|
+
t.recordedFrom,
|
|
196
|
+
t.recordedTo
|
|
197
|
+
),
|
|
198
|
+
index(`${n.recordedEdges}_open_idx`).on(t.graphId, t.recordedTo),
|
|
199
|
+
index(`${n.recordedEdges}_from_idx`).on(
|
|
200
|
+
t.graphId,
|
|
201
|
+
t.fromKind,
|
|
202
|
+
t.fromId,
|
|
203
|
+
t.kind,
|
|
204
|
+
t.toKind,
|
|
205
|
+
t.recordedFrom,
|
|
206
|
+
t.recordedTo
|
|
207
|
+
),
|
|
208
|
+
index(`${n.recordedEdges}_to_idx`).on(
|
|
209
|
+
t.graphId,
|
|
210
|
+
t.toKind,
|
|
211
|
+
t.toId,
|
|
212
|
+
t.kind,
|
|
213
|
+
t.fromKind,
|
|
214
|
+
t.recordedFrom,
|
|
215
|
+
t.recordedTo
|
|
216
|
+
),
|
|
217
|
+
index(`${n.recordedEdges}_valid_idx`).on(
|
|
218
|
+
t.graphId,
|
|
219
|
+
t.validFrom,
|
|
220
|
+
t.validTo
|
|
221
|
+
)
|
|
222
|
+
]
|
|
223
|
+
);
|
|
224
|
+
const recordedClock2 = pgTable(
|
|
225
|
+
n.recordedClock,
|
|
226
|
+
{
|
|
227
|
+
graphId: text("graph_id").notNull(),
|
|
228
|
+
recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull()
|
|
229
|
+
},
|
|
230
|
+
(t) => [primaryKey({ columns: [t.graphId] })]
|
|
231
|
+
);
|
|
120
232
|
const uniques2 = pgTable(
|
|
121
233
|
n.uniques,
|
|
122
234
|
{
|
|
@@ -240,6 +352,9 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
240
352
|
return {
|
|
241
353
|
nodes: nodes2,
|
|
242
354
|
edges: edges2,
|
|
355
|
+
recordedNodes: recordedNodes2,
|
|
356
|
+
recordedEdges: recordedEdges2,
|
|
357
|
+
recordedClock: recordedClock2,
|
|
243
358
|
uniques: uniques2,
|
|
244
359
|
schemaVersions: schemaVersions2,
|
|
245
360
|
indexMaterializations,
|
|
@@ -251,7 +366,16 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
251
366
|
};
|
|
252
367
|
}
|
|
253
368
|
var tables2 = createPostgresTables();
|
|
254
|
-
var {
|
|
369
|
+
var {
|
|
370
|
+
nodes,
|
|
371
|
+
edges,
|
|
372
|
+
recordedNodes,
|
|
373
|
+
recordedEdges,
|
|
374
|
+
recordedClock,
|
|
375
|
+
uniques,
|
|
376
|
+
schemaVersions,
|
|
377
|
+
fulltext
|
|
378
|
+
} = tables2;
|
|
255
379
|
function getSqliteColumnType(column) {
|
|
256
380
|
switch (column.columnType) {
|
|
257
381
|
case "SQLiteText": {
|
|
@@ -307,9 +431,9 @@ function renderIndexColumn(col) {
|
|
|
307
431
|
if (col && typeof col === "object" && "name" in col) {
|
|
308
432
|
return `"${col.name}"`;
|
|
309
433
|
}
|
|
310
|
-
const
|
|
311
|
-
if (
|
|
312
|
-
return
|
|
434
|
+
const sql13 = tryInlineSql(col);
|
|
435
|
+
if (sql13 !== void 0) {
|
|
436
|
+
return sql13;
|
|
313
437
|
}
|
|
314
438
|
return "unknown";
|
|
315
439
|
}
|
|
@@ -322,16 +446,16 @@ function tryInlineSql(value) {
|
|
|
322
446
|
}
|
|
323
447
|
return inlineSql(value);
|
|
324
448
|
}
|
|
325
|
-
function flattenSqlChunk(
|
|
326
|
-
if (typeof
|
|
327
|
-
return
|
|
449
|
+
function flattenSqlChunk(chunk2) {
|
|
450
|
+
if (typeof chunk2 === "string") {
|
|
451
|
+
return chunk2;
|
|
328
452
|
}
|
|
329
|
-
if (typeof
|
|
330
|
-
if ("name" in
|
|
331
|
-
return `"${
|
|
453
|
+
if (typeof chunk2 === "object" && chunk2 !== null) {
|
|
454
|
+
if ("name" in chunk2 && typeof chunk2.name === "string") {
|
|
455
|
+
return `"${chunk2.name}"`;
|
|
332
456
|
}
|
|
333
|
-
if ("value" in
|
|
334
|
-
const value =
|
|
457
|
+
if ("value" in chunk2) {
|
|
458
|
+
const value = chunk2.value;
|
|
335
459
|
if (typeof value === "string") {
|
|
336
460
|
return value;
|
|
337
461
|
}
|
|
@@ -339,17 +463,17 @@ function flattenSqlChunk(chunk) {
|
|
|
339
463
|
return value.map((part) => flattenSqlChunk(part)).join("");
|
|
340
464
|
}
|
|
341
465
|
}
|
|
342
|
-
if ("queryChunks" in
|
|
343
|
-
return
|
|
466
|
+
if ("queryChunks" in chunk2 && Array.isArray(chunk2.queryChunks)) {
|
|
467
|
+
return chunk2.queryChunks.map((part) => flattenSqlChunk(part)).join("");
|
|
344
468
|
}
|
|
345
|
-
if ("getSQL" in
|
|
346
|
-
const maybe =
|
|
469
|
+
if ("getSQL" in chunk2) {
|
|
470
|
+
const maybe = chunk2;
|
|
347
471
|
if (typeof maybe.getSQL === "function") {
|
|
348
472
|
return flattenSqlChunk(maybe.getSQL());
|
|
349
473
|
}
|
|
350
474
|
}
|
|
351
475
|
}
|
|
352
|
-
throw new Error(`Unable to inline SQL chunk: ${String(
|
|
476
|
+
throw new Error(`Unable to inline SQL chunk: ${String(chunk2)}`);
|
|
353
477
|
}
|
|
354
478
|
function inlineSql(value) {
|
|
355
479
|
try {
|
|
@@ -606,146 +730,6 @@ function mapVectorWriteError(error, params) {
|
|
|
606
730
|
{ cause: error }
|
|
607
731
|
);
|
|
608
732
|
}
|
|
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
733
|
var SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = {
|
|
750
734
|
decode: (value) => typeof value === "string" ? value : void 0,
|
|
751
735
|
encode: (value) => value
|
|
@@ -821,21 +805,21 @@ function identityOf(graphId, contribution) {
|
|
|
821
805
|
function gateFulltextMethods(source, assert) {
|
|
822
806
|
const gated = {};
|
|
823
807
|
if (source.upsertFulltext) {
|
|
824
|
-
const raw = source.upsertFulltext;
|
|
808
|
+
const raw = source.upsertFulltext.bind(source);
|
|
825
809
|
gated.upsertFulltext = async (params) => {
|
|
826
810
|
await assert(params.graphId);
|
|
827
811
|
await raw(params);
|
|
828
812
|
};
|
|
829
813
|
}
|
|
830
814
|
if (source.deleteFulltext) {
|
|
831
|
-
const raw = source.deleteFulltext;
|
|
815
|
+
const raw = source.deleteFulltext.bind(source);
|
|
832
816
|
gated.deleteFulltext = async (params) => {
|
|
833
817
|
await assert(params.graphId);
|
|
834
818
|
await raw(params);
|
|
835
819
|
};
|
|
836
820
|
}
|
|
837
821
|
if (source.upsertFulltextBatch) {
|
|
838
|
-
const raw = source.upsertFulltextBatch;
|
|
822
|
+
const raw = source.upsertFulltextBatch.bind(source);
|
|
839
823
|
gated.upsertFulltextBatch = async (params) => {
|
|
840
824
|
if (params.rows.length === 0) return;
|
|
841
825
|
await assert(params.graphId);
|
|
@@ -843,7 +827,7 @@ function gateFulltextMethods(source, assert) {
|
|
|
843
827
|
};
|
|
844
828
|
}
|
|
845
829
|
if (source.deleteFulltextBatch) {
|
|
846
|
-
const raw = source.deleteFulltextBatch;
|
|
830
|
+
const raw = source.deleteFulltextBatch.bind(source);
|
|
847
831
|
gated.deleteFulltextBatch = async (params) => {
|
|
848
832
|
if (params.nodeIds.length === 0) return;
|
|
849
833
|
await assert(params.graphId);
|
|
@@ -851,13 +835,13 @@ function gateFulltextMethods(source, assert) {
|
|
|
851
835
|
};
|
|
852
836
|
}
|
|
853
837
|
if (source.fulltextSearch) {
|
|
854
|
-
const raw = source.fulltextSearch;
|
|
838
|
+
const raw = source.fulltextSearch.bind(source);
|
|
855
839
|
gated.fulltextSearch = async (params) => {
|
|
856
840
|
await assert(params.graphId);
|
|
857
841
|
return raw(params);
|
|
858
842
|
};
|
|
859
843
|
}
|
|
860
|
-
const rawHardDelete = source.hardDeleteNode;
|
|
844
|
+
const rawHardDelete = source.hardDeleteNode.bind(source);
|
|
861
845
|
gated.hardDeleteNode = async (params) => {
|
|
862
846
|
await assert(params.graphId);
|
|
863
847
|
await rawHardDelete(params);
|
|
@@ -865,7 +849,10 @@ function gateFulltextMethods(source, assert) {
|
|
|
865
849
|
return gated;
|
|
866
850
|
}
|
|
867
851
|
function gateFulltext(tx, assert) {
|
|
868
|
-
return
|
|
852
|
+
return createBackendOverlay(
|
|
853
|
+
tx,
|
|
854
|
+
gateFulltextMethods(tx, assert)
|
|
855
|
+
);
|
|
869
856
|
}
|
|
870
857
|
function createContributionMaterializer(deps) {
|
|
871
858
|
const { dialect, fulltextStrategy, fulltextTableName } = deps;
|
|
@@ -1078,397 +1065,46 @@ function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
|
|
|
1078
1065
|
lastError: sql`excluded.${sql.identifier("last_error")}`
|
|
1079
1066
|
};
|
|
1080
1067
|
}
|
|
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;
|
|
1068
|
+
function buildClearGraph(tables3, graphId) {
|
|
1069
|
+
const fulltext2 = quotedTableName(tables3.fulltextTableName);
|
|
1070
|
+
return [
|
|
1071
|
+
{ query: sql`DELETE FROM ${fulltext2} WHERE "graph_id" = ${graphId}` },
|
|
1072
|
+
{
|
|
1073
|
+
query: sql`DELETE FROM ${tables3.recordedEdges} WHERE ${tables3.recordedEdges.graphId} = ${graphId}`,
|
|
1074
|
+
ignoreMissingTable: true,
|
|
1075
|
+
requiredTableName: getTableName(tables3.recordedEdges)
|
|
1158
1076
|
},
|
|
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;
|
|
1077
|
+
{
|
|
1078
|
+
query: sql`DELETE FROM ${tables3.recordedNodes} WHERE ${tables3.recordedNodes.graphId} = ${graphId}`,
|
|
1079
|
+
ignoreMissingTable: true,
|
|
1080
|
+
requiredTableName: getTableName(tables3.recordedNodes)
|
|
1168
1081
|
},
|
|
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);
|
|
1082
|
+
{
|
|
1083
|
+
query: sql`DELETE FROM ${tables3.recordedClock} WHERE ${tables3.recordedClock.graphId} = ${graphId}`,
|
|
1084
|
+
ignoreMissingTable: true,
|
|
1085
|
+
requiredTableName: getTableName(tables3.recordedClock)
|
|
1175
1086
|
},
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const query = operationStrategy.buildDeleteNode(params, timestamp2);
|
|
1179
|
-
await execution.execRun(query);
|
|
1087
|
+
{
|
|
1088
|
+
query: sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`
|
|
1180
1089
|
},
|
|
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);
|
|
1090
|
+
{
|
|
1091
|
+
query: sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`
|
|
1212
1092
|
},
|
|
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);
|
|
1093
|
+
{
|
|
1094
|
+
query: sql`DELETE FROM ${tables3.nodes} WHERE ${tables3.nodes.graphId} = ${graphId}`
|
|
1219
1095
|
},
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
|
|
1223
|
-
await execution.execRun(query);
|
|
1096
|
+
{
|
|
1097
|
+
query: sql`DELETE FROM ${tables3.indexMaterializations} WHERE ${tables3.indexMaterializations.graphId} = ${graphId}`
|
|
1224
1098
|
},
|
|
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
|
-
}
|
|
1099
|
+
{
|
|
1100
|
+
query: sql`DELETE FROM ${tables3.kindRemovals} WHERE ${tables3.kindRemovals.graphId} = ${graphId}`
|
|
1234
1101
|
},
|
|
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;
|
|
1102
|
+
{
|
|
1103
|
+
query: sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
|
|
1247
1104
|
},
|
|
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
|
-
}
|
|
1105
|
+
{
|
|
1106
|
+
query: sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
|
|
1458
1107
|
}
|
|
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
1108
|
];
|
|
1473
1109
|
}
|
|
1474
1110
|
function buildTemporalConditions(table, params) {
|
|
@@ -1673,14 +1309,10 @@ function buildGetEdge(tables3, graphId, id) {
|
|
|
1673
1309
|
}
|
|
1674
1310
|
function buildGetEdges(tables3, graphId, ids) {
|
|
1675
1311
|
const { edges: edges2 } = tables3;
|
|
1676
|
-
const idPlaceholders = sql.join(
|
|
1677
|
-
ids.map((edgeId) => sql`${edgeId}`),
|
|
1678
|
-
sql`, `
|
|
1679
|
-
);
|
|
1680
1312
|
return sql`
|
|
1681
1313
|
SELECT * FROM ${edges2}
|
|
1682
1314
|
WHERE ${edges2.graphId} = ${graphId}
|
|
1683
|
-
AND ${edges2.id} IN (${
|
|
1315
|
+
AND ${edges2.id} IN (${sqlValueList(ids)})
|
|
1684
1316
|
`;
|
|
1685
1317
|
}
|
|
1686
1318
|
function buildUpdateEdge(tables3, params, timestamp2) {
|
|
@@ -1917,15 +1549,11 @@ function buildGetNode(tables3, graphId, kind, id) {
|
|
|
1917
1549
|
}
|
|
1918
1550
|
function buildGetNodes(tables3, graphId, kind, ids) {
|
|
1919
1551
|
const { nodes: nodes2 } = tables3;
|
|
1920
|
-
const idPlaceholders = sql.join(
|
|
1921
|
-
ids.map((nodeId) => sql`${nodeId}`),
|
|
1922
|
-
sql`, `
|
|
1923
|
-
);
|
|
1924
1552
|
return sql`
|
|
1925
1553
|
SELECT * FROM ${nodes2}
|
|
1926
1554
|
WHERE ${nodes2.graphId} = ${graphId}
|
|
1927
1555
|
AND ${nodes2.kind} = ${kind}
|
|
1928
|
-
AND ${nodes2.id} IN (${
|
|
1556
|
+
AND ${nodes2.id} IN (${sqlValueList(ids)})
|
|
1929
1557
|
`;
|
|
1930
1558
|
}
|
|
1931
1559
|
function buildUpdateNode(tables3, params, timestamp2) {
|
|
@@ -2260,17 +1888,437 @@ function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
|
|
|
2260
1888
|
buildSetActiveSchema(graphId, version) {
|
|
2261
1889
|
return buildSetActiveSchema(tables3, graphId, version, dialect);
|
|
2262
1890
|
},
|
|
1891
|
+
buildTableExists(tableName) {
|
|
1892
|
+
if (dialect === "postgres") {
|
|
1893
|
+
return sql`
|
|
1894
|
+
SELECT c.relname AS table_name
|
|
1895
|
+
FROM pg_catalog.pg_class AS c
|
|
1896
|
+
WHERE c.relname = ${tableName}
|
|
1897
|
+
AND c.relkind IN ('r', 'p', 'v', 'm', 'f')
|
|
1898
|
+
AND pg_catalog.pg_table_is_visible(c.oid)
|
|
1899
|
+
LIMIT 1
|
|
1900
|
+
`;
|
|
1901
|
+
}
|
|
1902
|
+
return sql`SELECT name AS table_name FROM sqlite_master WHERE type IN ('table', 'view') AND name = ${tableName}`;
|
|
1903
|
+
},
|
|
2263
1904
|
buildClearGraph(graphId) {
|
|
2264
1905
|
return buildClearGraph(tables3, graphId);
|
|
2265
1906
|
}
|
|
2266
1907
|
};
|
|
2267
1908
|
}
|
|
1909
|
+
function tableExistsFromRow(row) {
|
|
1910
|
+
if (row === void 0) return false;
|
|
1911
|
+
return Object.values(row).some((value) => isPresent(value));
|
|
1912
|
+
}
|
|
1913
|
+
function createCachedTableExistence(probe, options) {
|
|
1914
|
+
const cacheExisting = options?.cacheExisting !== false;
|
|
1915
|
+
const cacheMissing = options?.cacheMissing === true;
|
|
1916
|
+
const confirmedExisting = /* @__PURE__ */ new Set();
|
|
1917
|
+
const confirmedMissing = /* @__PURE__ */ new Set();
|
|
1918
|
+
return async function tableExists(tableName) {
|
|
1919
|
+
if (confirmedExisting.has(tableName)) return true;
|
|
1920
|
+
if (confirmedMissing.has(tableName)) return false;
|
|
1921
|
+
const exists = tableExistsFromRow(await probe(tableName));
|
|
1922
|
+
if (exists && cacheExisting) {
|
|
1923
|
+
confirmedExisting.add(tableName);
|
|
1924
|
+
}
|
|
1925
|
+
if (!exists && cacheMissing) {
|
|
1926
|
+
confirmedMissing.add(tableName);
|
|
1927
|
+
}
|
|
1928
|
+
return exists;
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
2268
1931
|
function createSqliteOperationStrategy(tables3, fulltextStrategy) {
|
|
2269
1932
|
return createCommonOperationStrategy(tables3, "sqlite", fulltextStrategy);
|
|
2270
1933
|
}
|
|
2271
1934
|
function createPostgresOperationStrategy(tables3, fulltextStrategy) {
|
|
2272
1935
|
return createCommonOperationStrategy(tables3, "postgres", fulltextStrategy);
|
|
2273
1936
|
}
|
|
1937
|
+
function assertAdoptedDialect(externalTx, brand, backend) {
|
|
1938
|
+
if (is(externalTx, brand)) return;
|
|
1939
|
+
const label = backend === "postgres" ? "Postgres" : "SQLite";
|
|
1940
|
+
throw new ConfigurationError(
|
|
1941
|
+
`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.`,
|
|
1942
|
+
{ backend, capability: "adoptTransaction" }
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
1945
|
+
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
1946
|
+
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
1947
|
+
if (actualActiveVersion !== expectedVersion) {
|
|
1948
|
+
throw new StaleVersionError({
|
|
1949
|
+
graphId,
|
|
1950
|
+
expected: expectedVersion,
|
|
1951
|
+
actual: actualActiveVersion
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
function createCommonOperationBackend(options) {
|
|
1956
|
+
const { batchConfig, execution, operationStrategy, rowMappers } = options;
|
|
1957
|
+
const nowIso2 = options.nowIso ?? nowIso;
|
|
1958
|
+
const requiredClearTableExists = createCachedTableExistence(
|
|
1959
|
+
(tableName) => execution.execGet(
|
|
1960
|
+
operationStrategy.buildTableExists(tableName)
|
|
1961
|
+
),
|
|
1962
|
+
options.tableExistenceCache
|
|
1963
|
+
);
|
|
1964
|
+
async function runIgnorableClearStatement(statement) {
|
|
1965
|
+
if (statement.ignoreMissingTable === true && statement.requiredTableName !== void 0 && !await requiredClearTableExists(statement.requiredTableName)) {
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
await execution.execRun(statement.query);
|
|
1969
|
+
}
|
|
1970
|
+
async function readActiveVersion(graphId) {
|
|
1971
|
+
const row = await execution.execGet(
|
|
1972
|
+
operationStrategy.buildGetActiveSchema(graphId)
|
|
1973
|
+
);
|
|
1974
|
+
return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
|
|
1975
|
+
}
|
|
1976
|
+
return {
|
|
1977
|
+
async executeStatement(query) {
|
|
1978
|
+
await execution.execRun(query);
|
|
1979
|
+
},
|
|
1980
|
+
async insertNode(params) {
|
|
1981
|
+
const timestamp2 = nowIso2();
|
|
1982
|
+
const query = operationStrategy.buildInsertNode(params, timestamp2);
|
|
1983
|
+
const row = await execution.execGet(query);
|
|
1984
|
+
if (!row) throw new DatabaseOperationError("Insert node failed: no row returned", { operation: "insert", entity: "node" });
|
|
1985
|
+
return rowMappers.toNodeRow(row);
|
|
1986
|
+
},
|
|
1987
|
+
async insertNodeNoReturn(params) {
|
|
1988
|
+
const timestamp2 = nowIso2();
|
|
1989
|
+
const query = operationStrategy.buildInsertNodeNoReturn(params, timestamp2);
|
|
1990
|
+
await execution.execRun(query);
|
|
1991
|
+
},
|
|
1992
|
+
async insertNodesBatch(params) {
|
|
1993
|
+
if (params.length === 0) {
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
const timestamp2 = nowIso2();
|
|
1997
|
+
for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
1998
|
+
const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp2);
|
|
1999
|
+
await execution.execRun(query);
|
|
2000
|
+
}
|
|
2001
|
+
},
|
|
2002
|
+
async insertNodesBatchReturning(params) {
|
|
2003
|
+
if (params.length === 0) {
|
|
2004
|
+
return [];
|
|
2005
|
+
}
|
|
2006
|
+
const timestamp2 = nowIso2();
|
|
2007
|
+
const allRows = [];
|
|
2008
|
+
for (const chunk2 of chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
2009
|
+
const query = operationStrategy.buildInsertNodesBatchReturning(chunk2, timestamp2);
|
|
2010
|
+
const rows = await execution.execAll(query);
|
|
2011
|
+
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2012
|
+
}
|
|
2013
|
+
return allRows;
|
|
2014
|
+
},
|
|
2015
|
+
async getNode(graphId, kind, id) {
|
|
2016
|
+
const query = operationStrategy.buildGetNode(graphId, kind, id);
|
|
2017
|
+
const row = await execution.execGet(query);
|
|
2018
|
+
return row ? rowMappers.toNodeRow(row) : void 0;
|
|
2019
|
+
},
|
|
2020
|
+
async getNodes(graphId, kind, ids) {
|
|
2021
|
+
if (ids.length === 0) return [];
|
|
2022
|
+
const allRows = [];
|
|
2023
|
+
for (const chunk2 of chunk(ids, batchConfig.getNodesChunkSize)) {
|
|
2024
|
+
const query = operationStrategy.buildGetNodes(graphId, kind, chunk2);
|
|
2025
|
+
const rows = await execution.execAll(query);
|
|
2026
|
+
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2027
|
+
}
|
|
2028
|
+
return allRows;
|
|
2029
|
+
},
|
|
2030
|
+
async updateNode(params) {
|
|
2031
|
+
const timestamp2 = nowIso2();
|
|
2032
|
+
const query = operationStrategy.buildUpdateNode(params, timestamp2);
|
|
2033
|
+
const row = await execution.execGet(query);
|
|
2034
|
+
if (!row) throw new DatabaseOperationError("Update node failed: no row returned", { operation: "update", entity: "node" });
|
|
2035
|
+
return rowMappers.toNodeRow(row);
|
|
2036
|
+
},
|
|
2037
|
+
async deleteNode(params) {
|
|
2038
|
+
const timestamp2 = nowIso2();
|
|
2039
|
+
const query = operationStrategy.buildDeleteNode(params, timestamp2);
|
|
2040
|
+
await execution.execRun(query);
|
|
2041
|
+
},
|
|
2042
|
+
// IMPORTANT: This cascade is not atomic. Callers must ensure this runs
|
|
2043
|
+
// within a transaction to prevent partial deletion on intermediate failure.
|
|
2044
|
+
//
|
|
2045
|
+
// Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
|
|
2046
|
+
// fieldPath)` strategy-owned tables addressable only with the slot
|
|
2047
|
+
// context the graph-agnostic backend lacks. The store's hard-delete
|
|
2048
|
+
// path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
|
|
2049
|
+
// resolves each embedding field and routes a per-field
|
|
2050
|
+
// `backend.deleteEmbedding` through the active vector strategy.
|
|
2051
|
+
async hardDeleteNode(params) {
|
|
2052
|
+
const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
|
|
2053
|
+
params.graphId,
|
|
2054
|
+
params.id
|
|
2055
|
+
);
|
|
2056
|
+
await execution.execRun(deleteUniquesQuery);
|
|
2057
|
+
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
2058
|
+
params.graphId,
|
|
2059
|
+
params.kind,
|
|
2060
|
+
params.id
|
|
2061
|
+
);
|
|
2062
|
+
for (const stmt of deleteFulltextStatements) {
|
|
2063
|
+
await execution.execRun(stmt);
|
|
2064
|
+
}
|
|
2065
|
+
const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
|
|
2066
|
+
params.graphId,
|
|
2067
|
+
params.kind,
|
|
2068
|
+
params.id
|
|
2069
|
+
);
|
|
2070
|
+
await execution.execRun(deleteEdgesQuery);
|
|
2071
|
+
const query = operationStrategy.buildHardDeleteNode(params);
|
|
2072
|
+
await execution.execRun(query);
|
|
2073
|
+
},
|
|
2074
|
+
async insertEdge(params) {
|
|
2075
|
+
const timestamp2 = nowIso2();
|
|
2076
|
+
const query = operationStrategy.buildInsertEdge(params, timestamp2);
|
|
2077
|
+
const row = await execution.execGet(query);
|
|
2078
|
+
if (!row) throw new DatabaseOperationError("Insert edge failed: no row returned", { operation: "insert", entity: "edge" });
|
|
2079
|
+
return rowMappers.toEdgeRow(row);
|
|
2080
|
+
},
|
|
2081
|
+
async insertEdgeNoReturn(params) {
|
|
2082
|
+
const timestamp2 = nowIso2();
|
|
2083
|
+
const query = operationStrategy.buildInsertEdgeNoReturn(params, timestamp2);
|
|
2084
|
+
await execution.execRun(query);
|
|
2085
|
+
},
|
|
2086
|
+
async insertEdgesBatch(params) {
|
|
2087
|
+
if (params.length === 0) {
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
const timestamp2 = nowIso2();
|
|
2091
|
+
for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2092
|
+
const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp2);
|
|
2093
|
+
await execution.execRun(query);
|
|
2094
|
+
}
|
|
2095
|
+
},
|
|
2096
|
+
async insertEdgesBatchReturning(params) {
|
|
2097
|
+
if (params.length === 0) {
|
|
2098
|
+
return [];
|
|
2099
|
+
}
|
|
2100
|
+
const timestamp2 = nowIso2();
|
|
2101
|
+
const allRows = [];
|
|
2102
|
+
for (const chunk2 of chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2103
|
+
const query = operationStrategy.buildInsertEdgesBatchReturning(chunk2, timestamp2);
|
|
2104
|
+
const rows = await execution.execAll(query);
|
|
2105
|
+
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2106
|
+
}
|
|
2107
|
+
return allRows;
|
|
2108
|
+
},
|
|
2109
|
+
async getEdge(graphId, id) {
|
|
2110
|
+
const query = operationStrategy.buildGetEdge(graphId, id);
|
|
2111
|
+
const row = await execution.execGet(query);
|
|
2112
|
+
return row ? rowMappers.toEdgeRow(row) : void 0;
|
|
2113
|
+
},
|
|
2114
|
+
async getEdges(graphId, ids) {
|
|
2115
|
+
if (ids.length === 0) return [];
|
|
2116
|
+
const allRows = [];
|
|
2117
|
+
for (const chunk2 of chunk(ids, batchConfig.getEdgesChunkSize)) {
|
|
2118
|
+
const query = operationStrategy.buildGetEdges(graphId, chunk2);
|
|
2119
|
+
const rows = await execution.execAll(query);
|
|
2120
|
+
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2121
|
+
}
|
|
2122
|
+
return allRows;
|
|
2123
|
+
},
|
|
2124
|
+
async updateEdge(params) {
|
|
2125
|
+
const timestamp2 = nowIso2();
|
|
2126
|
+
const query = operationStrategy.buildUpdateEdge(params, timestamp2);
|
|
2127
|
+
const row = await execution.execGet(query);
|
|
2128
|
+
if (!row) throw new DatabaseOperationError("Update edge failed: no row returned", { operation: "update", entity: "edge" });
|
|
2129
|
+
return rowMappers.toEdgeRow(row);
|
|
2130
|
+
},
|
|
2131
|
+
async deleteEdge(params) {
|
|
2132
|
+
const timestamp2 = nowIso2();
|
|
2133
|
+
const query = operationStrategy.buildDeleteEdge(params, timestamp2);
|
|
2134
|
+
await execution.execRun(query);
|
|
2135
|
+
},
|
|
2136
|
+
async hardDeleteEdge(params) {
|
|
2137
|
+
const query = operationStrategy.buildHardDeleteEdge(params);
|
|
2138
|
+
await execution.execRun(query);
|
|
2139
|
+
},
|
|
2140
|
+
async countEdgesFrom(params) {
|
|
2141
|
+
const query = operationStrategy.buildCountEdgesFrom(params);
|
|
2142
|
+
const row = await execution.execGet(query);
|
|
2143
|
+
return Number(row?.count ?? 0);
|
|
2144
|
+
},
|
|
2145
|
+
async edgeExistsBetween(params) {
|
|
2146
|
+
const query = operationStrategy.buildEdgeExistsBetween(params);
|
|
2147
|
+
const row = await execution.execGet(query);
|
|
2148
|
+
return row !== void 0;
|
|
2149
|
+
},
|
|
2150
|
+
async findEdgesConnectedTo(params) {
|
|
2151
|
+
const query = operationStrategy.buildFindEdgesConnectedTo(params);
|
|
2152
|
+
const rows = await execution.execAll(query);
|
|
2153
|
+
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2154
|
+
},
|
|
2155
|
+
async findNodesByKind(params) {
|
|
2156
|
+
const query = operationStrategy.buildFindNodesByKind(params);
|
|
2157
|
+
const rows = await execution.execAll(query);
|
|
2158
|
+
return rows.map((row) => rowMappers.toNodeRow(row));
|
|
2159
|
+
},
|
|
2160
|
+
async countNodesByKind(params) {
|
|
2161
|
+
const query = operationStrategy.buildCountNodesByKind(params);
|
|
2162
|
+
const row = await execution.execGet(query);
|
|
2163
|
+
return Number(row?.count ?? 0);
|
|
2164
|
+
},
|
|
2165
|
+
async findEdgesByKind(params) {
|
|
2166
|
+
const query = operationStrategy.buildFindEdgesByKind(params);
|
|
2167
|
+
const rows = await execution.execAll(query);
|
|
2168
|
+
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2169
|
+
},
|
|
2170
|
+
async countEdgesByKind(params) {
|
|
2171
|
+
const query = operationStrategy.buildCountEdgesByKind(params);
|
|
2172
|
+
const row = await execution.execGet(query);
|
|
2173
|
+
return Number(row?.count ?? 0);
|
|
2174
|
+
},
|
|
2175
|
+
async insertUnique(params) {
|
|
2176
|
+
const query = operationStrategy.buildInsertUnique(params);
|
|
2177
|
+
const result = await execution.execGet(query);
|
|
2178
|
+
if (result && result.node_id !== params.nodeId) {
|
|
2179
|
+
throw new UniquenessError({
|
|
2180
|
+
constraintName: params.constraintName,
|
|
2181
|
+
kind: params.nodeKind,
|
|
2182
|
+
existingId: result.node_id,
|
|
2183
|
+
newId: params.nodeId,
|
|
2184
|
+
fields: []
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
},
|
|
2188
|
+
async deleteUnique(params) {
|
|
2189
|
+
const timestamp2 = nowIso2();
|
|
2190
|
+
const query = operationStrategy.buildDeleteUnique(params, timestamp2);
|
|
2191
|
+
await execution.execRun(query);
|
|
2192
|
+
},
|
|
2193
|
+
async checkUnique(params) {
|
|
2194
|
+
const query = operationStrategy.buildCheckUnique(params);
|
|
2195
|
+
const row = await execution.execGet(query);
|
|
2196
|
+
return row ? rowMappers.toUniqueRow(row) : void 0;
|
|
2197
|
+
},
|
|
2198
|
+
async checkUniqueBatch(params) {
|
|
2199
|
+
if (params.keys.length === 0) return [];
|
|
2200
|
+
const allRows = [];
|
|
2201
|
+
for (const chunk2 of chunk(params.keys, batchConfig.checkUniqueBatchChunkSize)) {
|
|
2202
|
+
const query = operationStrategy.buildCheckUniqueBatch({ ...params, keys: chunk2 });
|
|
2203
|
+
const rows = await execution.execAll(query);
|
|
2204
|
+
allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
|
|
2205
|
+
}
|
|
2206
|
+
return allRows;
|
|
2207
|
+
},
|
|
2208
|
+
async getActiveSchema(graphId) {
|
|
2209
|
+
const query = operationStrategy.buildGetActiveSchema(graphId);
|
|
2210
|
+
const row = await execution.execGet(query);
|
|
2211
|
+
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
2212
|
+
},
|
|
2213
|
+
async getSchemaVersion(graphId, version) {
|
|
2214
|
+
const query = operationStrategy.buildGetSchemaVersion(graphId, version);
|
|
2215
|
+
const row = await execution.execGet(query);
|
|
2216
|
+
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
2217
|
+
},
|
|
2218
|
+
async commitSchemaVersion(params) {
|
|
2219
|
+
const existingRaw = await execution.execGet(
|
|
2220
|
+
operationStrategy.buildGetSchemaVersion(
|
|
2221
|
+
params.graphId,
|
|
2222
|
+
params.version
|
|
2223
|
+
)
|
|
2224
|
+
);
|
|
2225
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
2226
|
+
if (existingRaw !== void 0) {
|
|
2227
|
+
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
2228
|
+
if (existing.schema_hash !== params.schemaHash) {
|
|
2229
|
+
throw new SchemaContentConflictError({
|
|
2230
|
+
graphId: params.graphId,
|
|
2231
|
+
version: params.version,
|
|
2232
|
+
existingHash: existing.schema_hash,
|
|
2233
|
+
incomingHash: params.schemaHash
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
if (existing.is_active) {
|
|
2237
|
+
return existing;
|
|
2238
|
+
}
|
|
2239
|
+
verifyExpectedActiveVersion(
|
|
2240
|
+
params.graphId,
|
|
2241
|
+
params.expected,
|
|
2242
|
+
actualActiveVersion
|
|
2243
|
+
);
|
|
2244
|
+
const reactivate = operationStrategy.buildSetActiveSchema(
|
|
2245
|
+
params.graphId,
|
|
2246
|
+
params.version
|
|
2247
|
+
);
|
|
2248
|
+
await execution.execRun(reactivate.deactivateAll);
|
|
2249
|
+
await execution.execRun(reactivate.activateVersion);
|
|
2250
|
+
return { ...existing, is_active: true };
|
|
2251
|
+
}
|
|
2252
|
+
verifyExpectedActiveVersion(
|
|
2253
|
+
params.graphId,
|
|
2254
|
+
params.expected,
|
|
2255
|
+
actualActiveVersion
|
|
2256
|
+
);
|
|
2257
|
+
if (params.expected.kind === "active") {
|
|
2258
|
+
const flip = operationStrategy.buildSetActiveSchema(
|
|
2259
|
+
params.graphId,
|
|
2260
|
+
params.version
|
|
2261
|
+
);
|
|
2262
|
+
await execution.execRun(flip.deactivateAll);
|
|
2263
|
+
}
|
|
2264
|
+
const timestamp2 = nowIso2();
|
|
2265
|
+
const insertQuery = operationStrategy.buildInsertSchema(
|
|
2266
|
+
{
|
|
2267
|
+
graphId: params.graphId,
|
|
2268
|
+
version: params.version,
|
|
2269
|
+
schemaHash: params.schemaHash,
|
|
2270
|
+
schemaDoc: params.schemaDoc,
|
|
2271
|
+
isActive: true
|
|
2272
|
+
},
|
|
2273
|
+
timestamp2
|
|
2274
|
+
);
|
|
2275
|
+
const insertedRaw = await execution.execGet(insertQuery);
|
|
2276
|
+
if (!insertedRaw) {
|
|
2277
|
+
throw new DatabaseOperationError(
|
|
2278
|
+
"Insert schema failed: no row returned",
|
|
2279
|
+
{ operation: "insert", entity: "schema" }
|
|
2280
|
+
);
|
|
2281
|
+
}
|
|
2282
|
+
return rowMappers.toSchemaVersionRow(insertedRaw);
|
|
2283
|
+
},
|
|
2284
|
+
async setActiveVersion(params) {
|
|
2285
|
+
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
2286
|
+
verifyExpectedActiveVersion(
|
|
2287
|
+
params.graphId,
|
|
2288
|
+
params.expected,
|
|
2289
|
+
actualActiveVersion
|
|
2290
|
+
);
|
|
2291
|
+
const targetRaw = await execution.execGet(
|
|
2292
|
+
operationStrategy.buildGetSchemaVersion(
|
|
2293
|
+
params.graphId,
|
|
2294
|
+
params.version
|
|
2295
|
+
)
|
|
2296
|
+
);
|
|
2297
|
+
if (!targetRaw) {
|
|
2298
|
+
throw new MigrationError(
|
|
2299
|
+
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
2300
|
+
{
|
|
2301
|
+
graphId: params.graphId,
|
|
2302
|
+
fromVersion: actualActiveVersion,
|
|
2303
|
+
toVersion: params.version
|
|
2304
|
+
}
|
|
2305
|
+
);
|
|
2306
|
+
}
|
|
2307
|
+
const queries = operationStrategy.buildSetActiveSchema(
|
|
2308
|
+
params.graphId,
|
|
2309
|
+
params.version
|
|
2310
|
+
);
|
|
2311
|
+
await execution.execRun(queries.deactivateAll);
|
|
2312
|
+
await execution.execRun(queries.activateVersion);
|
|
2313
|
+
},
|
|
2314
|
+
async clearGraph(graphId) {
|
|
2315
|
+
const statements = operationStrategy.buildClearGraph(graphId);
|
|
2316
|
+
for (const statement of statements) {
|
|
2317
|
+
await runIgnorableClearStatement(statement);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2274
2322
|
|
|
2275
2323
|
// src/backend/drizzle/execution/lru.ts
|
|
2276
2324
|
function getOrCreateLru(cache, key, cacheMax, create) {
|
|
@@ -2299,6 +2347,6 @@ function compileQueryWithDialect(db, query, backendName) {
|
|
|
2299
2347
|
return compiler.sqlToQuery(query);
|
|
2300
2348
|
}
|
|
2301
2349
|
|
|
2302
|
-
export { POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, POSTGRES_INDEX_MAT_TIMESTAMPS, POSTGRES_KIND_REMOVAL_TIMESTAMPS,
|
|
2303
|
-
//# sourceMappingURL=chunk-
|
|
2304
|
-
//# sourceMappingURL=chunk-
|
|
2350
|
+
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 };
|
|
2351
|
+
//# sourceMappingURL=chunk-RY2VIWAM.js.map
|
|
2352
|
+
//# sourceMappingURL=chunk-RY2VIWAM.js.map
|