@nicia-ai/typegraph 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/postgres/index.cjs +178 -55
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +6 -7
- package/dist/backend/postgres/index.d.ts +6 -7
- package/dist/backend/postgres/index.js +151 -28
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +19 -17
- package/dist/backend/sqlite/index.d.cts +6 -7
- package/dist/backend/sqlite/index.d.ts +6 -7
- package/dist/backend/sqlite/index.js +9 -7
- package/dist/backend/sqlite/libsql.cjs +12 -10
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +9 -7
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +14 -12
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +9 -7
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/chunk-4BOWVUGQ.js +2029 -0
- package/dist/chunk-4BOWVUGQ.js.map +1 -0
- package/dist/{chunk-RNUNP5JD.cjs → chunk-7CDXX3QZ.cjs} +2 -2
- package/dist/chunk-7CDXX3QZ.cjs.map +1 -0
- package/dist/chunk-7V335GHG.cjs +112 -0
- package/dist/chunk-7V335GHG.cjs.map +1 -0
- package/dist/chunk-7W3KAMVQ.cjs +2678 -0
- package/dist/chunk-7W3KAMVQ.cjs.map +1 -0
- package/dist/chunk-CTHNVU6K.cjs +551 -0
- package/dist/chunk-CTHNVU6K.cjs.map +1 -0
- package/dist/chunk-D2GO3RBL.cjs +12 -0
- package/dist/chunk-D2GO3RBL.cjs.map +1 -0
- package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
- package/dist/chunk-DOTEN2FG.js.map +1 -0
- package/dist/chunk-E5JZSEGJ.cjs +301 -0
- package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
- package/dist/chunk-EG6TJ3I5.js +286 -0
- package/dist/chunk-EG6TJ3I5.js.map +1 -0
- package/dist/chunk-EJCDOA37.js +537 -0
- package/dist/chunk-EJCDOA37.js.map +1 -0
- package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
- package/dist/chunk-EK6RJ373.cjs.map +1 -0
- package/dist/{chunk-7TU5EWQ7.js → chunk-FPCOUJSL.js} +2 -2
- package/dist/chunk-FPCOUJSL.js.map +1 -0
- package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
- package/dist/chunk-JTI5WT4P.cjs.map +1 -0
- package/dist/chunk-LVCSL6A3.js +2626 -0
- package/dist/chunk-LVCSL6A3.js.map +1 -0
- package/dist/chunk-NHQWXSTS.js +10 -0
- package/dist/chunk-NHQWXSTS.js.map +1 -0
- package/dist/chunk-NZ5PMBTG.js +105 -0
- package/dist/chunk-NZ5PMBTG.js.map +1 -0
- package/dist/{chunk-5HVDOPZU.cjs → chunk-O2P3KAUT.cjs} +416 -93
- package/dist/chunk-O2P3KAUT.cjs.map +1 -0
- package/dist/{chunk-GTG5J4UP.js → chunk-OJ6IQVZG.js} +151 -13
- package/dist/chunk-OJ6IQVZG.js.map +1 -0
- package/dist/{chunk-EYELZHKY.js → chunk-OOS2RKRH.js} +5 -140
- package/dist/chunk-OOS2RKRH.js.map +1 -0
- package/dist/chunk-RCAJZG67.cjs +2069 -0
- package/dist/chunk-RCAJZG67.cjs.map +1 -0
- package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
- package/dist/chunk-W5MTHMTE.cjs.map +1 -0
- package/dist/{chunk-EY4LBX3F.js → chunk-WI5VRP3X.js} +337 -26
- package/dist/chunk-WI5VRP3X.js.map +1 -0
- package/dist/chunk-WVQXAFP3.js +79 -0
- package/dist/chunk-WVQXAFP3.js.map +1 -0
- package/dist/chunk-X3244EKP.cjs +84 -0
- package/dist/chunk-X3244EKP.cjs.map +1 -0
- package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
- package/dist/chunk-YZZBDCLV.js.map +1 -0
- package/dist/{chunk-3MDBMCFF.cjs → chunk-ZEMNF3QK.cjs} +171 -33
- package/dist/chunk-ZEMNF3QK.cjs.map +1 -0
- package/dist/{ddl-B_H8JM-E.d.cts → ddl-B2jjLjpR.d.cts} +762 -99
- package/dist/{ddl-1tFIvt9V.d.ts → ddl-DpaeAKPp.d.ts} +762 -99
- package/dist/extension-types-D07e_NTw.d.cts +543 -0
- package/dist/extension-types-D07e_NTw.d.ts +543 -0
- package/dist/graph-extension/index.cjs +71 -0
- package/dist/graph-extension/index.cjs.map +1 -0
- package/dist/graph-extension/index.d.cts +278 -0
- package/dist/graph-extension/index.d.ts +278 -0
- package/dist/graph-extension/index.js +6 -0
- package/dist/graph-extension/index.js.map +1 -0
- package/dist/{index-DXkEXpNz.d.ts → index-CT6nvtxL.d.cts} +114 -5
- package/dist/{index-DXkEXpNz.d.cts → index-DQheiVQV.d.ts} +114 -5
- package/dist/index.cjs +2672 -901
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.js +2248 -598
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +25 -23
- package/dist/indexes/index.d.cts +40 -22
- package/dist/indexes/index.d.ts +40 -22
- package/dist/indexes/index.js +5 -3
- package/dist/interchange/index.cjs +8 -7
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +5 -4
- package/dist/interchange/index.d.ts +5 -4
- package/dist/interchange/index.js +3 -2
- package/dist/interchange/index.js.map +1 -1
- package/dist/{manager-Vkz28eAC.d.cts → manager-BKaPQbns.d.ts} +189 -6
- package/dist/{manager-nIhmttD-.d.ts → manager-BpjBW1JK.d.cts} +189 -6
- package/dist/materialize-indexes-BB9N5uQl.d.cts +68 -0
- package/dist/materialize-indexes-BYpU2RKh.d.ts +68 -0
- package/dist/profiler/index.cjs +10 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +8 -7
- package/dist/profiler/index.d.ts +8 -7
- package/dist/profiler/index.js +3 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +43 -22
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +17 -8
- package/dist/schema/index.d.ts +17 -8
- package/dist/schema/index.js +9 -4
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-D0aceIe0.d.cts → sqlite-CU3j6rc7.d.ts} +837 -120
- package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-Myo8e3Lr.d.cts} +837 -120
- package/dist/{store-CpvwTMxV.d.cts → store-BAGuOHDh.d.cts} +659 -23
- package/dist/{store-U3i2tUch.d.ts → store-De98Lod4.d.ts} +659 -23
- package/dist/types--0EslBx5.d.cts +2123 -0
- package/dist/{types-qYFZ9SqD.d.ts → types-BLmJq4wI.d.ts} +3 -2
- package/dist/types-BNWYZ-0-.d.ts +2123 -0
- package/dist/{types-yH4_p0XB.d.cts → types-CYga3lZp.d.cts} +3 -2
- package/dist/where-CluR73rs.d.ts +11 -0
- package/dist/where-m1uWsdua.d.cts +11 -0
- package/package.json +37 -77
- package/dist/ast-C8S37w1A.d.ts +0 -497
- package/dist/ast-dgLhLOg0.d.cts +0 -497
- package/dist/chunk-3JK66E3I.cjs.map +0 -1
- package/dist/chunk-3MDBMCFF.cjs.map +0 -1
- package/dist/chunk-3PPEHLGK.js +0 -1116
- package/dist/chunk-3PPEHLGK.js.map +0 -1
- package/dist/chunk-5HVDOPZU.cjs.map +0 -1
- package/dist/chunk-753F33CV.js.map +0 -1
- package/dist/chunk-7TU5EWQ7.js.map +0 -1
- package/dist/chunk-EY4LBX3F.js.map +0 -1
- package/dist/chunk-EYELZHKY.js.map +0 -1
- package/dist/chunk-GTG5J4UP.js.map +0 -1
- package/dist/chunk-HRNQ3DVJ.cjs +0 -1417
- package/dist/chunk-HRNQ3DVJ.cjs.map +0 -1
- package/dist/chunk-JYUQA77I.js +0 -1381
- package/dist/chunk-JYUQA77I.js.map +0 -1
- package/dist/chunk-O5PST6TB.cjs.map +0 -1
- package/dist/chunk-PEE4EWXZ.cjs +0 -1131
- package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
- package/dist/chunk-RNUNP5JD.cjs.map +0 -1
- package/dist/chunk-RS5OLGEW.js +0 -135
- package/dist/chunk-RS5OLGEW.js.map +0 -1
- package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
- package/dist/chunk-WFMTAEEN.js.map +0 -1
- package/dist/chunk-WRWVWKQL.cjs +0 -147
- package/dist/chunk-WRWVWKQL.cjs.map +0 -1
- package/dist/types-C-zfYDJB.d.ts +0 -159
- package/dist/types-CQx4iW5Y.d.cts +0 -159
- package/dist/types-Qk2l3IkQ.d.cts +0 -1254
- package/dist/types-Qk2l3IkQ.d.ts +0 -1254
package/dist/indexes/index.cjs
CHANGED
|
@@ -1,66 +1,68 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
3
|
+
var chunkJTI5WT4P_cjs = require('../chunk-JTI5WT4P.cjs');
|
|
4
|
+
var chunkCTHNVU6K_cjs = require('../chunk-CTHNVU6K.cjs');
|
|
5
|
+
require('../chunk-EK6RJ373.cjs');
|
|
6
|
+
require('../chunk-X3244EKP.cjs');
|
|
7
|
+
require('../chunk-7V335GHG.cjs');
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
Object.defineProperty(exports, "andWhere", {
|
|
10
12
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkJTI5WT4P_cjs.andWhere; }
|
|
12
14
|
});
|
|
13
15
|
Object.defineProperty(exports, "buildPostgresEdgeIndexBuilders", {
|
|
14
16
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkJTI5WT4P_cjs.buildPostgresEdgeIndexBuilders; }
|
|
16
18
|
});
|
|
17
19
|
Object.defineProperty(exports, "buildPostgresNodeIndexBuilders", {
|
|
18
20
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkJTI5WT4P_cjs.buildPostgresNodeIndexBuilders; }
|
|
20
22
|
});
|
|
21
23
|
Object.defineProperty(exports, "buildSqliteEdgeIndexBuilders", {
|
|
22
24
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkJTI5WT4P_cjs.buildSqliteEdgeIndexBuilders; }
|
|
24
26
|
});
|
|
25
27
|
Object.defineProperty(exports, "buildSqliteNodeIndexBuilders", {
|
|
26
28
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(exports, "defineEdgeIndex", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () { return chunkPEE4EWXZ_cjs.defineEdgeIndex; }
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "defineNodeIndex", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () { return chunkPEE4EWXZ_cjs.defineNodeIndex; }
|
|
29
|
+
get: function () { return chunkJTI5WT4P_cjs.buildSqliteNodeIndexBuilders; }
|
|
36
30
|
});
|
|
37
31
|
Object.defineProperty(exports, "generateEdgeIndexDDL", {
|
|
38
32
|
enumerable: true,
|
|
39
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkJTI5WT4P_cjs.generateEdgeIndexDDL; }
|
|
40
34
|
});
|
|
41
35
|
Object.defineProperty(exports, "generateIndexDDL", {
|
|
42
36
|
enumerable: true,
|
|
43
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkJTI5WT4P_cjs.generateIndexDDL; }
|
|
44
38
|
});
|
|
45
39
|
Object.defineProperty(exports, "generateNodeIndexDDL", {
|
|
46
40
|
enumerable: true,
|
|
47
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkJTI5WT4P_cjs.generateNodeIndexDDL; }
|
|
48
42
|
});
|
|
49
43
|
Object.defineProperty(exports, "notWhere", {
|
|
50
44
|
enumerable: true,
|
|
51
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkJTI5WT4P_cjs.notWhere; }
|
|
52
46
|
});
|
|
53
47
|
Object.defineProperty(exports, "orWhere", {
|
|
54
48
|
enumerable: true,
|
|
55
|
-
get: function () { return
|
|
49
|
+
get: function () { return chunkJTI5WT4P_cjs.orWhere; }
|
|
56
50
|
});
|
|
57
51
|
Object.defineProperty(exports, "toDeclaredIndex", {
|
|
58
52
|
enumerable: true,
|
|
59
|
-
get: function () { return
|
|
53
|
+
get: function () { return chunkJTI5WT4P_cjs.toDeclaredIndex; }
|
|
60
54
|
});
|
|
61
55
|
Object.defineProperty(exports, "toDeclaredIndexes", {
|
|
62
56
|
enumerable: true,
|
|
63
|
-
get: function () { return
|
|
57
|
+
get: function () { return chunkJTI5WT4P_cjs.toDeclaredIndexes; }
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "defineEdgeIndex", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return chunkCTHNVU6K_cjs.defineEdgeIndex; }
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "defineNodeIndex", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () { return chunkCTHNVU6K_cjs.defineNodeIndex; }
|
|
64
66
|
});
|
|
65
67
|
//# sourceMappingURL=index.cjs.map
|
|
66
68
|
//# sourceMappingURL=index.cjs.map
|
package/dist/indexes/index.d.cts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
import { a as EdgeIndexDeclaration, m as SqlDialect, R as RelationalIndexDeclaration, b as NodeIndexDeclaration, I as IndexDeclaration } from '../types--0EslBx5.cjs';
|
|
2
|
+
export { E as EdgeIndexConfig, n as EdgeIndexDirection, o as EdgeIndexWhereBuilder, p as IndexOrigin, q as IndexScope, c as IndexWhereExpression, r as IndexWhereFieldBuilder, s as IndexWhereInput, N as NodeIndexConfig, t as NodeIndexWhereBuilder, u as SystemColumnName, V as VectorIndexDeclaration, v as VectorIndexImplementation, w as VectorIndexMetric, x as VectorIndexParams } from '../types--0EslBx5.cjs';
|
|
3
|
+
export { a as andWhere, d as defineEdgeIndex, b as defineNodeIndex, n as notWhere, o as orWhere } from '../where-m1uWsdua.cjs';
|
|
4
4
|
import { SQLWrapper } from 'drizzle-orm';
|
|
5
5
|
import { IndexBuilder } from 'drizzle-orm/pg-core';
|
|
6
6
|
import { IndexBuilder as IndexBuilder$1 } from 'drizzle-orm/sqlite-core';
|
|
7
|
-
import { D as DeclaredIndex } from '../types-
|
|
7
|
+
import { D as DeclaredIndex } from '../types-CYga3lZp.cjs';
|
|
8
8
|
import 'zod';
|
|
9
|
-
import '../
|
|
9
|
+
import '../extension-types-D07e_NTw.cjs';
|
|
10
10
|
|
|
11
11
|
type GenerateIndexDdlOptions = Readonly<{
|
|
12
12
|
nodesTableName?: string | undefined;
|
|
13
13
|
edgesTableName?: string | undefined;
|
|
14
14
|
ifNotExists?: boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Emit `CREATE INDEX CONCURRENTLY` (Postgres only). Required for
|
|
17
|
+
* `store.materializeIndexes()` so live tables don't take an
|
|
18
|
+
* `AccessExclusiveLock`. Ignored on SQLite (no equivalent; SQLite is
|
|
19
|
+
* single-writer regardless). When true on Postgres, the resulting
|
|
20
|
+
* statement cannot be executed inside a transaction.
|
|
21
|
+
*/
|
|
22
|
+
concurrent?: boolean | undefined;
|
|
15
23
|
}>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Generate `CREATE INDEX` DDL for a single relational index declaration.
|
|
26
|
+
*
|
|
27
|
+
* Vector index declarations (`entity: "vector"`) are NOT handled here —
|
|
28
|
+
* they go through `backend.createVectorIndex` instead because the DDL
|
|
29
|
+
* is dialect-specific (`USING hnsw (...) WITH (m=..., ef_construction=...)`
|
|
30
|
+
* on Postgres) and operates on the embeddings table, not
|
|
31
|
+
* `typegraph_nodes` / `typegraph_edges`. Callers narrow to the
|
|
32
|
+
* relational subset before calling this function.
|
|
33
|
+
*/
|
|
34
|
+
declare function generateIndexDDL(index: RelationalIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
35
|
+
declare function generateNodeIndexDDL(index: NodeIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
36
|
+
declare function generateEdgeIndexDDL(index: EdgeIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
19
37
|
|
|
20
|
-
declare function
|
|
21
|
-
declare function
|
|
22
|
-
|
|
23
|
-
declare function
|
|
24
|
-
declare function buildPostgresEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder[];
|
|
25
|
-
declare function buildSqliteNodeIndexBuilders(table: NodeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder$1[];
|
|
26
|
-
declare function buildSqliteEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder$1[];
|
|
38
|
+
declare function buildPostgresNodeIndexBuilders(table: NodeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder[];
|
|
39
|
+
declare function buildPostgresEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder[];
|
|
40
|
+
declare function buildSqliteNodeIndexBuilders(table: NodeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder$1[];
|
|
41
|
+
declare function buildSqliteEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder$1[];
|
|
27
42
|
type NodeIndexTable = Readonly<{
|
|
28
43
|
graphId: SQLWrapper;
|
|
29
44
|
kind: SQLWrapper;
|
|
@@ -52,11 +67,14 @@ type EdgeIndexTable = Readonly<{
|
|
|
52
67
|
deletedAt: SQLWrapper;
|
|
53
68
|
}>;
|
|
54
69
|
|
|
55
|
-
declare function toDeclaredIndex(index:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
declare function toDeclaredIndex(index: RelationalIndexDeclaration): DeclaredIndex;
|
|
71
|
+
/**
|
|
72
|
+
* Vector indexes are excluded from the profiler-format conversion —
|
|
73
|
+
* the profiler operates on relational tables (`typegraph_nodes` /
|
|
74
|
+
* `typegraph_edges`) where index hits / misses can be measured against
|
|
75
|
+
* SQL plans. Vector indexes live on the embeddings table with a
|
|
76
|
+
* different access pattern.
|
|
77
|
+
*/
|
|
78
|
+
declare function toDeclaredIndexes(indexes: readonly IndexDeclaration[]): readonly DeclaredIndex[];
|
|
61
79
|
|
|
62
|
-
export {
|
|
80
|
+
export { EdgeIndexDeclaration, type GenerateIndexDdlOptions, IndexDeclaration, NodeIndexDeclaration, RelationalIndexDeclaration, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders, generateEdgeIndexDDL, generateIndexDDL, generateNodeIndexDDL, toDeclaredIndex, toDeclaredIndexes };
|
package/dist/indexes/index.d.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
import { a as EdgeIndexDeclaration, m as SqlDialect, R as RelationalIndexDeclaration, b as NodeIndexDeclaration, I as IndexDeclaration } from '../types-BNWYZ-0-.js';
|
|
2
|
+
export { E as EdgeIndexConfig, n as EdgeIndexDirection, o as EdgeIndexWhereBuilder, p as IndexOrigin, q as IndexScope, c as IndexWhereExpression, r as IndexWhereFieldBuilder, s as IndexWhereInput, N as NodeIndexConfig, t as NodeIndexWhereBuilder, u as SystemColumnName, V as VectorIndexDeclaration, v as VectorIndexImplementation, w as VectorIndexMetric, x as VectorIndexParams } from '../types-BNWYZ-0-.js';
|
|
3
|
+
export { a as andWhere, d as defineEdgeIndex, b as defineNodeIndex, n as notWhere, o as orWhere } from '../where-CluR73rs.js';
|
|
4
4
|
import { SQLWrapper } from 'drizzle-orm';
|
|
5
5
|
import { IndexBuilder } from 'drizzle-orm/pg-core';
|
|
6
6
|
import { IndexBuilder as IndexBuilder$1 } from 'drizzle-orm/sqlite-core';
|
|
7
|
-
import { D as DeclaredIndex } from '../types-
|
|
7
|
+
import { D as DeclaredIndex } from '../types-BLmJq4wI.js';
|
|
8
8
|
import 'zod';
|
|
9
|
-
import '../
|
|
9
|
+
import '../extension-types-D07e_NTw.js';
|
|
10
10
|
|
|
11
11
|
type GenerateIndexDdlOptions = Readonly<{
|
|
12
12
|
nodesTableName?: string | undefined;
|
|
13
13
|
edgesTableName?: string | undefined;
|
|
14
14
|
ifNotExists?: boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Emit `CREATE INDEX CONCURRENTLY` (Postgres only). Required for
|
|
17
|
+
* `store.materializeIndexes()` so live tables don't take an
|
|
18
|
+
* `AccessExclusiveLock`. Ignored on SQLite (no equivalent; SQLite is
|
|
19
|
+
* single-writer regardless). When true on Postgres, the resulting
|
|
20
|
+
* statement cannot be executed inside a transaction.
|
|
21
|
+
*/
|
|
22
|
+
concurrent?: boolean | undefined;
|
|
15
23
|
}>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Generate `CREATE INDEX` DDL for a single relational index declaration.
|
|
26
|
+
*
|
|
27
|
+
* Vector index declarations (`entity: "vector"`) are NOT handled here —
|
|
28
|
+
* they go through `backend.createVectorIndex` instead because the DDL
|
|
29
|
+
* is dialect-specific (`USING hnsw (...) WITH (m=..., ef_construction=...)`
|
|
30
|
+
* on Postgres) and operates on the embeddings table, not
|
|
31
|
+
* `typegraph_nodes` / `typegraph_edges`. Callers narrow to the
|
|
32
|
+
* relational subset before calling this function.
|
|
33
|
+
*/
|
|
34
|
+
declare function generateIndexDDL(index: RelationalIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
35
|
+
declare function generateNodeIndexDDL(index: NodeIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
36
|
+
declare function generateEdgeIndexDDL(index: EdgeIndexDeclaration, dialect: SqlDialect, options?: GenerateIndexDdlOptions): string;
|
|
19
37
|
|
|
20
|
-
declare function
|
|
21
|
-
declare function
|
|
22
|
-
|
|
23
|
-
declare function
|
|
24
|
-
declare function buildPostgresEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder[];
|
|
25
|
-
declare function buildSqliteNodeIndexBuilders(table: NodeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder$1[];
|
|
26
|
-
declare function buildSqliteEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly TypeGraphIndex[]): readonly IndexBuilder$1[];
|
|
38
|
+
declare function buildPostgresNodeIndexBuilders(table: NodeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder[];
|
|
39
|
+
declare function buildPostgresEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder[];
|
|
40
|
+
declare function buildSqliteNodeIndexBuilders(table: NodeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder$1[];
|
|
41
|
+
declare function buildSqliteEdgeIndexBuilders(table: EdgeIndexTable, indexes: readonly IndexDeclaration[]): readonly IndexBuilder$1[];
|
|
27
42
|
type NodeIndexTable = Readonly<{
|
|
28
43
|
graphId: SQLWrapper;
|
|
29
44
|
kind: SQLWrapper;
|
|
@@ -52,11 +67,14 @@ type EdgeIndexTable = Readonly<{
|
|
|
52
67
|
deletedAt: SQLWrapper;
|
|
53
68
|
}>;
|
|
54
69
|
|
|
55
|
-
declare function toDeclaredIndex(index:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
declare function toDeclaredIndex(index: RelationalIndexDeclaration): DeclaredIndex;
|
|
71
|
+
/**
|
|
72
|
+
* Vector indexes are excluded from the profiler-format conversion —
|
|
73
|
+
* the profiler operates on relational tables (`typegraph_nodes` /
|
|
74
|
+
* `typegraph_edges`) where index hits / misses can be measured against
|
|
75
|
+
* SQL plans. Vector indexes live on the embeddings table with a
|
|
76
|
+
* different access pattern.
|
|
77
|
+
*/
|
|
78
|
+
declare function toDeclaredIndexes(indexes: readonly IndexDeclaration[]): readonly DeclaredIndex[];
|
|
61
79
|
|
|
62
|
-
export {
|
|
80
|
+
export { EdgeIndexDeclaration, type GenerateIndexDdlOptions, IndexDeclaration, NodeIndexDeclaration, RelationalIndexDeclaration, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders, generateEdgeIndexDDL, generateIndexDDL, generateNodeIndexDDL, toDeclaredIndex, toDeclaredIndexes };
|
package/dist/indexes/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { andWhere, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders,
|
|
2
|
-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { andWhere, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders, generateEdgeIndexDDL, generateIndexDDL, generateNodeIndexDDL, notWhere, orWhere, toDeclaredIndex, toDeclaredIndexes } from '../chunk-YZZBDCLV.js';
|
|
2
|
+
export { defineEdgeIndex, defineNodeIndex } from '../chunk-EJCDOA37.js';
|
|
3
|
+
import '../chunk-OOS2RKRH.js';
|
|
4
|
+
import '../chunk-WVQXAFP3.js';
|
|
5
|
+
import '../chunk-NZ5PMBTG.js';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var chunkE5JZSEGJ_cjs = require('../chunk-E5JZSEGJ.cjs');
|
|
4
|
+
require('../chunk-X3244EKP.cjs');
|
|
5
|
+
require('../chunk-W5MTHMTE.cjs');
|
|
5
6
|
var zod = require('zod');
|
|
6
7
|
|
|
7
8
|
var FORMAT_VERSION = "1.0";
|
|
@@ -121,8 +122,8 @@ async function exportGraph(store, options) {
|
|
|
121
122
|
const graph = store.graph;
|
|
122
123
|
const graphId = store.graphId;
|
|
123
124
|
const backend = store.backend;
|
|
124
|
-
const nodeKindsToExport = options_.nodeKinds ??
|
|
125
|
-
const edgeKindsToExport = options_.edgeKinds ??
|
|
125
|
+
const nodeKindsToExport = options_.nodeKinds ?? chunkE5JZSEGJ_cjs.getNodeKinds(graph);
|
|
126
|
+
const edgeKindsToExport = options_.edgeKinds ?? chunkE5JZSEGJ_cjs.getEdgeKinds(graph);
|
|
126
127
|
const nodes = [];
|
|
127
128
|
for (const kind of nodeKindsToExport) {
|
|
128
129
|
const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);
|
|
@@ -136,7 +137,7 @@ async function exportGraph(store, options) {
|
|
|
136
137
|
const schemaVersion = await backend.getActiveSchema(graphId);
|
|
137
138
|
return {
|
|
138
139
|
formatVersion: FORMAT_VERSION,
|
|
139
|
-
exportedAt:
|
|
140
|
+
exportedAt: chunkE5JZSEGJ_cjs.nowIso(),
|
|
140
141
|
source: {
|
|
141
142
|
type: "typegraph-export",
|
|
142
143
|
graphId,
|
|
@@ -284,7 +285,7 @@ async function importGraph(store, data, options) {
|
|
|
284
285
|
}
|
|
285
286
|
function buildNodeSchemaMap(graph) {
|
|
286
287
|
const map = /* @__PURE__ */ new Map();
|
|
287
|
-
for (const kindName of
|
|
288
|
+
for (const kindName of chunkE5JZSEGJ_cjs.getNodeKinds(graph)) {
|
|
288
289
|
const registration = graph.nodes[kindName];
|
|
289
290
|
map.set(kindName, {
|
|
290
291
|
registration,
|
|
@@ -295,7 +296,7 @@ function buildNodeSchemaMap(graph) {
|
|
|
295
296
|
}
|
|
296
297
|
function buildEdgeSchemaMap(graph) {
|
|
297
298
|
const map = /* @__PURE__ */ new Map();
|
|
298
|
-
for (const kindName of
|
|
299
|
+
for (const kindName of chunkE5JZSEGJ_cjs.getEdgeKinds(graph)) {
|
|
299
300
|
const registration = graph.edges[kindName];
|
|
300
301
|
map.set(kindName, {
|
|
301
302
|
registration,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/interchange/types.ts","../../src/interchange/export.ts","../../src/interchange/import.ts"],"names":["z","getNodeKinds","getEdgeKinds","nowIso","result"],"mappings":";;;;;;AAmBO,IAAM,cAAA,GAAiB;AAYvB,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,IAAA,EAAMA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACtB,EAAA,EAAIA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACpB,UAAA,EAAYA,MAAE,MAAA,CAAOA,KAAA,CAAE,QAAO,EAAGA,KAAA,CAAE,SAAS,CAAA;AAAA,EAC5C,SAAA,EAAWA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,EACrC,OAAA,EAASA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,EACnC,IAAA,EAAMA,MACH,MAAA,CAAO;AAAA,IACN,OAAA,EAASA,MAAE,MAAA,EAAO,CAAE,KAAI,CAAE,Q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AAA,CACV,GAAA,CAAI,CAAC,KAAA,KAAU;AACd,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAChC,IAAA,OAAO,OAAO,CAAA,EAAG,IAAI,KAAK,KAAA,CAAM,OAAO,KAAK,KAAA,CAAM,OAAA;AAAA,EACpD,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACd;AAMA,SAAS,WAAA,CAAY,MAAc,EAAA,EAAoB;AACrD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA;AACtB","file":"index.cjs","sourcesContent":["/**\n * Graph interchange format types.\n *\n * Defines Zod schemas for importing and exporting graph data.\n * The format is designed to be:\n * - JSON-serializable for API transport\n * - Validated via Zod at runtime\n * - Exportable as JSON Schema for LLM/API documentation\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// Format Version\n// ============================================================\n\n/**\n * Current interchange format version.\n * Increment for breaking changes to the format.\n */\nexport const FORMAT_VERSION = \"1.0\" as const;\n\n// ============================================================\n// Node Interchange\n// ============================================================\n\n/**\n * Interchange format for a node.\n *\n * Properties are stored as a record to allow schema-agnostic transport.\n * Validation against the actual schema happens during import.\n */\nexport const InterchangeNodeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n properties: z.record(z.string(), z.unknown()),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n version: z.number().int().positive().optional(),\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeNode = z.infer<typeof InterchangeNodeSchema>;\n\n// ============================================================\n// Edge Interchange\n// ============================================================\n\n/**\n * Interchange format for an edge.\n *\n * Endpoint references are objects with kind and id, rather than\n * composite strings, for clarity and type safety.\n */\nexport const InterchangeEdgeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n from: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n to: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n properties: z.record(z.string(), z.unknown()).default({}),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeEdge = z.infer<typeof InterchangeEdgeSchema>;\n\n// ============================================================\n// Import Configuration\n// ============================================================\n\n/**\n * Strategy for handling conflicts when a node/edge ID already exists.\n *\n * - `skip`: Keep existing, ignore incoming\n * - `update`: Merge incoming properties into existing\n * - `error`: Throw an error on conflict\n */\nexport const ConflictStrategySchema = z.enum([\"skip\", \"update\", \"error\"]);\nexport type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;\n\n/**\n * Strategy for handling properties not defined in the schema.\n *\n * - `error`: Throw a validation error\n * - `strip`: Remove unknown properties silently\n * - `allow`: Pass through to storage (relies on backend behavior)\n */\nexport const UnknownPropertyStrategySchema = z.enum([\n \"error\",\n \"strip\",\n \"allow\",\n]);\nexport type UnknownPropertyStrategy = z.infer<\n typeof UnknownPropertyStrategySchema\n>;\n\n/**\n * Options for importing graph data.\n */\nexport const ImportOptionsSchema = z.object({\n /** How to handle existing nodes/edges with the same ID */\n onConflict: ConflictStrategySchema,\n /** How to handle properties not in the schema */\n onUnknownProperty: UnknownPropertyStrategySchema.default(\"error\"),\n /** Whether to validate that edge endpoints exist */\n validateReferences: z.boolean().default(true),\n /** Number of items to process in each batch */\n batchSize: z.number().int().positive().default(100),\n});\n\nexport type ImportOptions = z.infer<typeof ImportOptionsSchema>;\n\n// ============================================================\n// Graph Data Source\n// ============================================================\n\n/**\n * Source metadata for graph data.\n *\n * Uses discriminated union to capture different origin types:\n * - `typegraph-cloud`: Extracted by TypeGraph Cloud\n * - `typegraph-export`: Exported from a TypeGraph store\n * - `external`: From a third-party system\n */\nexport const GraphDataSourceSchema = z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"typegraph-cloud\"),\n extractionId: z.string(),\n schemaId: z.string(),\n schemaVersion: z.number().int().positive().optional(),\n }),\n z.object({\n type: z.literal(\"typegraph-export\"),\n graphId: z.string(),\n schemaVersion: z.number().int().positive(),\n }),\n z.object({\n type: z.literal(\"external\"),\n description: z.string().optional(),\n }),\n]);\n\nexport type GraphDataSource = z.infer<typeof GraphDataSourceSchema>;\n\n// ============================================================\n// Graph Data Envelope\n// ============================================================\n\n/**\n * Complete graph data interchange format.\n *\n * The envelope contains metadata about the data source and format version,\n * plus arrays of nodes and edges to import.\n */\nexport const GraphDataSchema = z.object({\n formatVersion: z.literal(FORMAT_VERSION),\n exportedAt: z.iso.datetime(),\n source: GraphDataSourceSchema,\n nodes: z.array(InterchangeNodeSchema),\n edges: z.array(InterchangeEdgeSchema),\n});\n\nexport type GraphData = z.infer<typeof GraphDataSchema>;\n\n// ============================================================\n// Import Result\n// ============================================================\n\n/**\n * An error that occurred during import.\n */\nexport const ImportErrorSchema = z.object({\n entityType: z.enum([\"node\", \"edge\"]),\n kind: z.string(),\n id: z.string(),\n error: z.string(),\n});\n\nexport type ImportError = z.infer<typeof ImportErrorSchema>;\n\n/**\n * Result of an import operation.\n *\n * Contains counts of created/updated/skipped entities and any errors.\n */\nexport const ImportResultSchema = z.object({\n success: z.boolean(),\n nodes: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n edges: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n errors: z.array(ImportErrorSchema),\n});\n\nexport type ImportResult = z.infer<typeof ImportResultSchema>;\n\n// ============================================================\n// Export Options\n// ============================================================\n\n/**\n * Options for exporting graph data.\n */\nexport const ExportOptionsSchema = z.object({\n /** Filter to specific node kinds (undefined = all) */\n nodeKinds: z.array(z.string()).optional(),\n /** Filter to specific edge kinds (undefined = all) */\n edgeKinds: z.array(z.string()).optional(),\n /** Include temporal fields (validFrom, validTo) */\n includeTemporal: z.boolean().default(false),\n /** Include metadata (version, timestamps) */\n includeMeta: z.boolean().default(false),\n /** Include soft-deleted records */\n includeDeleted: z.boolean().default(false),\n});\n\n/** Export options with defaults applied (output type) */\nexport type ExportOptions = z.infer<typeof ExportOptionsSchema>;\n\n/** Export options as accepted by exportGraph (input type with optional defaults) */\nexport type ExportOptionsInput = z.input<typeof ExportOptionsSchema>;\n","/**\n * Graph data export functionality.\n *\n * Exports nodes and edges from a store to the interchange format.\n */\nimport { type GraphBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type Store } from \"../store/store\";\nimport { nowIso } from \"../utils/date\";\nimport {\n type ExportOptionsInput,\n FORMAT_VERSION,\n type GraphData,\n type InterchangeEdge,\n type InterchangeNode,\n} from \"./types\";\n\n// ============================================================\n// Export Function\n// ============================================================\n\n/**\n * Export graph data from a store.\n *\n * @param store - The graph store to export from\n * @param options - Export configuration\n * @returns Graph data in interchange format\n *\n * @example\n * ```typescript\n * const data = await exportGraph(store, {\n * nodeKinds: [\"Person\", \"Organization\"],\n * includeMeta: true,\n * });\n *\n * // Write to file\n * await fs.writeFile(\"backup.json\", JSON.stringify(data, null, 2));\n * ```\n */\nexport async function exportGraph<G extends GraphDef>(\n store: Store<G>,\n options?: ExportOptionsInput,\n): Promise<GraphData> {\n const options_ = {\n nodeKinds: options?.nodeKinds,\n edgeKinds: options?.edgeKinds,\n includeTemporal: options?.includeTemporal ?? false,\n includeMeta: options?.includeMeta ?? false,\n includeDeleted: options?.includeDeleted ?? false,\n };\n\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Determine which kinds to export\n const nodeKindsToExport = options_.nodeKinds ?? getNodeKinds(graph);\n const edgeKindsToExport = options_.edgeKinds ?? getEdgeKinds(graph);\n\n // Export nodes\n const nodes: InterchangeNode[] = [];\n for (const kind of nodeKindsToExport) {\n const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);\n nodes.push(...kindNodes);\n }\n\n // Export edges\n const edges: InterchangeEdge[] = [];\n for (const kind of edgeKindsToExport) {\n const kindEdges = await exportEdgesOfKind(backend, graphId, kind, options_);\n edges.push(...kindEdges);\n }\n\n // Get current schema version\n const schemaVersion = await backend.getActiveSchema(graphId);\n\n return {\n formatVersion: FORMAT_VERSION,\n exportedAt: nowIso(),\n source: {\n type: \"typegraph-export\",\n graphId,\n schemaVersion: schemaVersion?.version ?? 1,\n },\n nodes,\n edges,\n };\n}\n\n// ============================================================\n// Node Export\n// ============================================================\n\ntype ExportOptions_ = Readonly<{\n includeTemporal: boolean;\n includeMeta: boolean;\n includeDeleted: boolean;\n}>;\n\nasync function exportNodesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeNode[]> {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const node: InterchangeNode = {\n kind: row.kind,\n id: row.id,\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (node as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (node as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (node as { meta?: InterchangeNode[\"meta\"] }).meta = {\n version: row.version,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return node;\n });\n}\n\n// ============================================================\n// Edge Export\n// ============================================================\n\nasync function exportEdgesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeEdge[]> {\n const rows = await backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const edge: InterchangeEdge = {\n kind: row.kind,\n id: row.id,\n from: {\n kind: row.from_kind,\n id: row.from_id,\n },\n to: {\n kind: row.to_kind,\n id: row.to_id,\n },\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (edge as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (edge as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (edge as { meta?: InterchangeEdge[\"meta\"] }).meta = {\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return edge;\n });\n}\n","/**\n * Graph data import functionality.\n *\n * Imports nodes and edges from the interchange format into a store,\n * with configurable conflict resolution and validation.\n */\nimport type { z } from \"zod\";\n\nimport { type GraphBackend, type TransactionBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type EdgeRegistration, type NodeRegistration } from \"../core/types\";\nimport { type Store } from \"../store/store\";\nimport {\n type GraphData,\n type ImportError,\n type ImportOptions,\n type ImportResult,\n type InterchangeEdge,\n type InterchangeNode,\n type UnknownPropertyStrategy,\n} from \"./types\";\n\n// ============================================================\n// Import Function\n// ============================================================\n\n/**\n * Import graph data into a store.\n *\n * Nodes are imported first to satisfy edge reference validation.\n * The import runs within a transaction for atomicity when supported.\n *\n * @param store - The graph store to import into\n * @param data - Graph data in interchange format\n * @param options - Import configuration\n * @returns Import statistics and any errors\n *\n * @example\n * ```typescript\n * const result = await importGraph(store, data, {\n * onConflict: \"update\",\n * onUnknownProperty: \"strip\",\n * });\n *\n * console.log(`Created ${result.nodes.created} nodes`);\n * ```\n */\nexport async function importGraph<G extends GraphDef>(\n store: Store<G>,\n data: GraphData,\n options: ImportOptions,\n): Promise<ImportResult> {\n const result: ImportResult = {\n success: true,\n nodes: { created: 0, updated: 0, skipped: 0 },\n edges: { created: 0, updated: 0, skipped: 0 },\n errors: [],\n };\n\n const errors: ImportError[] = [];\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Build lookup maps for schema validation\n const nodeSchemas = buildNodeSchemaMap(graph);\n const edgeSchemas = buildEdgeSchemaMap(graph);\n\n // Track imported node IDs for reference validation\n const importedNodeIds = new Set<string>();\n\n // Process in transaction if supported\n if (backend.capabilities.transactions) {\n await backend.transaction(async (tx) => {\n await processNodes(\n tx,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n tx,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n });\n } else {\n await processNodes(\n backend,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n backend,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n }\n\n return {\n ...result,\n success: errors.length === 0,\n errors,\n };\n}\n\n// ============================================================\n// Schema Maps\n// ============================================================\n\ntype NodeSchemaEntry = Readonly<{\n registration: NodeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n}>;\n\ntype EdgeSchemaEntry = Readonly<{\n registration: EdgeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n fromKinds: ReadonlySet<string>;\n toKinds: ReadonlySet<string>;\n}>;\n\nfunction buildNodeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, NodeSchemaEntry> {\n const map = new Map<string, NodeSchemaEntry>();\n\n for (const kindName of getNodeKinds(graph)) {\n const registration = graph.nodes[kindName] as NodeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n });\n }\n\n return map;\n}\n\nfunction buildEdgeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, EdgeSchemaEntry> {\n const map = new Map<string, EdgeSchemaEntry>();\n\n for (const kindName of getEdgeKinds(graph)) {\n const registration = graph.edges[kindName] as EdgeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n fromKinds: new Set(registration.from.map((node) => node.kind)),\n toKinds: new Set(registration.to.map((node) => node.kind)),\n });\n }\n\n return map;\n}\n\n// ============================================================\n// Node Processing\n// ============================================================\n\nasync function processNodes(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n nodes: readonly InterchangeNode[],\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < nodes.length; index += batchSize) {\n const batch = nodes.slice(index, index + batchSize);\n\n for (const node of batch) {\n const importResult = await processNode(\n backend,\n graphId,\n node,\n schemas,\n options,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.nodes.created++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"updated\": {\n result.nodes.updated++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"skipped\": {\n result.nodes.skipped++;\n // Still track as available for edge references\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"node\",\n kind: node.kind,\n id: node.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\ntype ProcessResult =\n | { status: \"created\" }\n | { status: \"updated\" }\n | { status: \"skipped\" }\n | { status: \"error\"; error: string };\n\nasync function processNode(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n node: InterchangeNode,\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n): Promise<ProcessResult> {\n // Validate kind exists\n const schemaEntry = schemas.get(node.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown node kind: ${node.kind}` };\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n node.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if node already exists\n const existing = await backend.getNode(graphId, node.kind, node.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return {\n status: \"error\",\n error: `Node already exists: ${node.kind}:${node.id}`,\n };\n }\n case \"update\": {\n await backend.updateNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n incrementVersion: true,\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new node\n await backend.insertNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n ...(node.validFrom !== undefined && { validFrom: node.validFrom }),\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Edge Processing\n// ============================================================\n\nasync function processEdges(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edges: readonly InterchangeEdge[],\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < edges.length; index += batchSize) {\n const batch = edges.slice(index, index + batchSize);\n\n for (const edge of batch) {\n const importResult = await processEdge(\n backend,\n graphId,\n edge,\n edgeSchemas,\n nodeSchemas,\n options,\n importedNodeIds,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.edges.created++;\n break;\n }\n case \"updated\": {\n result.edges.updated++;\n break;\n }\n case \"skipped\": {\n result.edges.skipped++;\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"edge\",\n kind: edge.kind,\n id: edge.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\nasync function processEdge(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edge: InterchangeEdge,\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n importedNodeIds: Set<string>,\n): Promise<ProcessResult> {\n // Validate edge kind exists\n const schemaEntry = edgeSchemas.get(edge.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown edge kind: ${edge.kind}` };\n }\n\n // Validate endpoint kinds\n if (!nodeSchemas.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Unknown from node kind: ${edge.from.kind}`,\n };\n }\n if (!nodeSchemas.has(edge.to.kind)) {\n return { status: \"error\", error: `Unknown to node kind: ${edge.to.kind}` };\n }\n\n // Validate endpoint kinds are allowed for this edge type\n if (!schemaEntry.fromKinds.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow from kind: ${edge.from.kind}`,\n };\n }\n if (!schemaEntry.toKinds.has(edge.to.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`,\n };\n }\n\n // Validate references exist (in DB or in import batch)\n if (options.validateReferences) {\n const fromKey = makeNodeKey(edge.from.kind, edge.from.id);\n const toKey = makeNodeKey(edge.to.kind, edge.to.id);\n\n // Check import batch first, then DB\n if (!importedNodeIds.has(fromKey)) {\n const fromExists = await backend.getNode(\n graphId,\n edge.from.kind,\n edge.from.id,\n );\n if (!fromExists) {\n return {\n status: \"error\",\n error: `From node not found: ${edge.from.kind}:${edge.from.id}`,\n };\n }\n }\n\n if (!importedNodeIds.has(toKey)) {\n const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);\n if (!toExists) {\n return {\n status: \"error\",\n error: `To node not found: ${edge.to.kind}:${edge.to.id}`,\n };\n }\n }\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n edge.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if edge already exists\n const existing = await backend.getEdge(graphId, edge.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return { status: \"error\", error: `Edge already exists: ${edge.id}` };\n }\n case \"update\": {\n await backend.updateEdge({\n graphId,\n id: edge.id,\n props: propsResult.data,\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new edge\n await backend.insertEdge({\n graphId,\n id: edge.id,\n kind: edge.kind,\n fromKind: edge.from.kind,\n fromId: edge.from.id,\n toKind: edge.to.kind,\n toId: edge.to.id,\n props: propsResult.data,\n ...(edge.validFrom !== undefined && { validFrom: edge.validFrom }),\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Property Validation\n// ============================================================\n\ntype ValidationResult =\n | { success: true; data: Record<string, unknown> }\n | { success: false; error: string };\n\nfunction validateProperties(\n properties: Record<string, unknown>,\n schema: z.ZodObject<z.ZodRawShape>,\n unknownStrategy: UnknownPropertyStrategy,\n): ValidationResult {\n try {\n // Get the schema's known keys\n const knownKeys = new Set(Object.keys(schema.shape));\n\n // Check for unknown properties\n const unknownKeys = Object.keys(properties).filter(\n (key) => !knownKeys.has(key),\n );\n\n if (unknownKeys.length > 0) {\n switch (unknownStrategy) {\n case \"error\": {\n return {\n success: false,\n error: `Unknown properties: ${unknownKeys.join(\", \")}`,\n };\n }\n case \"strip\": {\n // Remove unknown properties\n const stripped: Record<string, unknown> = {};\n for (const key of knownKeys) {\n if (key in properties) {\n stripped[key] = properties[key];\n }\n }\n // Validate stripped properties\n const result = schema.safeParse(stripped);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n return {\n success: true,\n data: result.data,\n };\n }\n case \"allow\": {\n // Validate but allow extra properties through\n const result = schema.safeParse(properties);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n // Return original properties (including unknown ones)\n return { success: true, data: properties };\n }\n }\n }\n\n // No unknown properties - standard validation\n const result = schema.safeParse(properties);\n if (!result.success) {\n return { success: false, error: formatZodError(result.error) };\n }\n\n return { success: true, data: result.data };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { success: false, error: `Validation error: ${message}` };\n }\n}\n\nfunction formatZodError(error: z.ZodError): string {\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n return path ? `${path}: ${issue.message}` : issue.message;\n })\n .join(\"; \");\n}\n\n// ============================================================\n// Helpers\n// ============================================================\n\nfunction makeNodeKey(kind: string, id: string): string {\n return `${kind}:${id}`;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/interchange/types.ts","../../src/interchange/export.ts","../../src/interchange/import.ts"],"names":["z","getNodeKinds","getEdgeKinds","nowIso","result"],"mappings":";;;;;;;AAmBO,IAAM,cAAA,GAAiB;AAYvB,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,IAAA,EAAMA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACtB,EAAA,EAAIA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACpB,UAAA,EAAYA,MAAE,MAAA,CAAOA,KAAA,CAAE,QAAO,EAAGA,KAAA,CAAE,SAAS,CAAA;AAAA,EAC5C,SAAA,EAAWA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,EACrC,OAAA,EAASA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,EACnC,IAAA,EAAMA,MACH,MAAA,CAAO;AAAA,IACN,OAAA,EAASA,MAAE,MAAA,EAAO,CAAE,KAAI,CAAE,QAAA,GAAW,QAAA,EAAS;AAAA,IAC9C,SAAA,EAAWA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA,EAAS;AAAA,IACrC,SAAA,EAAWA,KAAA,CAAE,GAAA,CAAI,QAAA,GAAW,QAAA;AAAS,GACtC,EACA,QAAA;AACL,CAAC;AAcM,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,IAAA,EAAMA,KAAA,CAAE,MAAA,EAA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c,EAAA,EAAoB;AACrD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA;AACtB","file":"index.cjs","sourcesContent":["/**\n * Graph interchange format types.\n *\n * Defines Zod schemas for importing and exporting graph data.\n * The format is designed to be:\n * - JSON-serializable for API transport\n * - Validated via Zod at runtime\n * - Exportable as JSON Schema for LLM/API documentation\n */\nimport { z } from \"zod\";\n\n// ============================================================\n// Format Version\n// ============================================================\n\n/**\n * Current interchange format version.\n * Increment for breaking changes to the format.\n */\nexport const FORMAT_VERSION = \"1.0\" as const;\n\n// ============================================================\n// Node Interchange\n// ============================================================\n\n/**\n * Interchange format for a node.\n *\n * Properties are stored as a record to allow schema-agnostic transport.\n * Validation against the actual schema happens during import.\n */\nexport const InterchangeNodeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n properties: z.record(z.string(), z.unknown()),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n version: z.number().int().positive().optional(),\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeNode = z.infer<typeof InterchangeNodeSchema>;\n\n// ============================================================\n// Edge Interchange\n// ============================================================\n\n/**\n * Interchange format for an edge.\n *\n * Endpoint references are objects with kind and id, rather than\n * composite strings, for clarity and type safety.\n */\nexport const InterchangeEdgeSchema = z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n from: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n to: z.object({\n kind: z.string().min(1),\n id: z.string().min(1),\n }),\n properties: z.record(z.string(), z.unknown()).default({}),\n validFrom: z.iso.datetime().optional(),\n validTo: z.iso.datetime().optional(),\n meta: z\n .object({\n createdAt: z.iso.datetime().optional(),\n updatedAt: z.iso.datetime().optional(),\n })\n .optional(),\n});\n\nexport type InterchangeEdge = z.infer<typeof InterchangeEdgeSchema>;\n\n// ============================================================\n// Import Configuration\n// ============================================================\n\n/**\n * Strategy for handling conflicts when a node/edge ID already exists.\n *\n * - `skip`: Keep existing, ignore incoming\n * - `update`: Merge incoming properties into existing\n * - `error`: Throw an error on conflict\n */\nexport const ConflictStrategySchema = z.enum([\"skip\", \"update\", \"error\"]);\nexport type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;\n\n/**\n * Strategy for handling properties not defined in the schema.\n *\n * - `error`: Throw a validation error\n * - `strip`: Remove unknown properties silently\n * - `allow`: Pass through to storage (relies on backend behavior)\n */\nexport const UnknownPropertyStrategySchema = z.enum([\n \"error\",\n \"strip\",\n \"allow\",\n]);\nexport type UnknownPropertyStrategy = z.infer<\n typeof UnknownPropertyStrategySchema\n>;\n\n/**\n * Options for importing graph data.\n */\nexport const ImportOptionsSchema = z.object({\n /** How to handle existing nodes/edges with the same ID */\n onConflict: ConflictStrategySchema,\n /** How to handle properties not in the schema */\n onUnknownProperty: UnknownPropertyStrategySchema.default(\"error\"),\n /** Whether to validate that edge endpoints exist */\n validateReferences: z.boolean().default(true),\n /** Number of items to process in each batch */\n batchSize: z.number().int().positive().default(100),\n});\n\nexport type ImportOptions = z.infer<typeof ImportOptionsSchema>;\n\n// ============================================================\n// Graph Data Source\n// ============================================================\n\n/**\n * Source metadata for graph data.\n *\n * Uses discriminated union to capture different origin types:\n * - `typegraph-cloud`: Extracted by TypeGraph Cloud\n * - `typegraph-export`: Exported from a TypeGraph store\n * - `external`: From a third-party system\n */\nexport const GraphDataSourceSchema = z.discriminatedUnion(\"type\", [\n z.object({\n type: z.literal(\"typegraph-cloud\"),\n extractionId: z.string(),\n schemaId: z.string(),\n schemaVersion: z.number().int().positive().optional(),\n }),\n z.object({\n type: z.literal(\"typegraph-export\"),\n graphId: z.string(),\n schemaVersion: z.number().int().positive(),\n }),\n z.object({\n type: z.literal(\"external\"),\n description: z.string().optional(),\n }),\n]);\n\nexport type GraphDataSource = z.infer<typeof GraphDataSourceSchema>;\n\n// ============================================================\n// Graph Data Envelope\n// ============================================================\n\n/**\n * Complete graph data interchange format.\n *\n * The envelope contains metadata about the data source and format version,\n * plus arrays of nodes and edges to import.\n */\nexport const GraphDataSchema = z.object({\n formatVersion: z.literal(FORMAT_VERSION),\n exportedAt: z.iso.datetime(),\n source: GraphDataSourceSchema,\n nodes: z.array(InterchangeNodeSchema),\n edges: z.array(InterchangeEdgeSchema),\n});\n\nexport type GraphData = z.infer<typeof GraphDataSchema>;\n\n// ============================================================\n// Import Result\n// ============================================================\n\n/**\n * An error that occurred during import.\n */\nexport const ImportErrorSchema = z.object({\n entityType: z.enum([\"node\", \"edge\"]),\n kind: z.string(),\n id: z.string(),\n error: z.string(),\n});\n\nexport type ImportError = z.infer<typeof ImportErrorSchema>;\n\n/**\n * Result of an import operation.\n *\n * Contains counts of created/updated/skipped entities and any errors.\n */\nexport const ImportResultSchema = z.object({\n success: z.boolean(),\n nodes: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n edges: z.object({\n created: z.number().int().nonnegative(),\n updated: z.number().int().nonnegative(),\n skipped: z.number().int().nonnegative(),\n }),\n errors: z.array(ImportErrorSchema),\n});\n\nexport type ImportResult = z.infer<typeof ImportResultSchema>;\n\n// ============================================================\n// Export Options\n// ============================================================\n\n/**\n * Options for exporting graph data.\n */\nexport const ExportOptionsSchema = z.object({\n /** Filter to specific node kinds (undefined = all) */\n nodeKinds: z.array(z.string()).optional(),\n /** Filter to specific edge kinds (undefined = all) */\n edgeKinds: z.array(z.string()).optional(),\n /** Include temporal fields (validFrom, validTo) */\n includeTemporal: z.boolean().default(false),\n /** Include metadata (version, timestamps) */\n includeMeta: z.boolean().default(false),\n /** Include soft-deleted records */\n includeDeleted: z.boolean().default(false),\n});\n\n/** Export options with defaults applied (output type) */\nexport type ExportOptions = z.infer<typeof ExportOptionsSchema>;\n\n/** Export options as accepted by exportGraph (input type with optional defaults) */\nexport type ExportOptionsInput = z.input<typeof ExportOptionsSchema>;\n","/**\n * Graph data export functionality.\n *\n * Exports nodes and edges from a store to the interchange format.\n */\nimport { type GraphBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type Store } from \"../store/store\";\nimport { nowIso } from \"../utils/date\";\nimport {\n type ExportOptionsInput,\n FORMAT_VERSION,\n type GraphData,\n type InterchangeEdge,\n type InterchangeNode,\n} from \"./types\";\n\n// ============================================================\n// Export Function\n// ============================================================\n\n/**\n * Export graph data from a store.\n *\n * @param store - The graph store to export from\n * @param options - Export configuration\n * @returns Graph data in interchange format\n *\n * @example\n * ```typescript\n * const data = await exportGraph(store, {\n * nodeKinds: [\"Person\", \"Organization\"],\n * includeMeta: true,\n * });\n *\n * // Write to file\n * await fs.writeFile(\"backup.json\", JSON.stringify(data, null, 2));\n * ```\n */\nexport async function exportGraph<G extends GraphDef>(\n store: Store<G>,\n options?: ExportOptionsInput,\n): Promise<GraphData> {\n const options_ = {\n nodeKinds: options?.nodeKinds,\n edgeKinds: options?.edgeKinds,\n includeTemporal: options?.includeTemporal ?? false,\n includeMeta: options?.includeMeta ?? false,\n includeDeleted: options?.includeDeleted ?? false,\n };\n\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Determine which kinds to export\n const nodeKindsToExport = options_.nodeKinds ?? getNodeKinds(graph);\n const edgeKindsToExport = options_.edgeKinds ?? getEdgeKinds(graph);\n\n // Export nodes\n const nodes: InterchangeNode[] = [];\n for (const kind of nodeKindsToExport) {\n const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);\n nodes.push(...kindNodes);\n }\n\n // Export edges\n const edges: InterchangeEdge[] = [];\n for (const kind of edgeKindsToExport) {\n const kindEdges = await exportEdgesOfKind(backend, graphId, kind, options_);\n edges.push(...kindEdges);\n }\n\n // Get current schema version\n const schemaVersion = await backend.getActiveSchema(graphId);\n\n return {\n formatVersion: FORMAT_VERSION,\n exportedAt: nowIso(),\n source: {\n type: \"typegraph-export\",\n graphId,\n schemaVersion: schemaVersion?.version ?? 1,\n },\n nodes,\n edges,\n };\n}\n\n// ============================================================\n// Node Export\n// ============================================================\n\ntype ExportOptions_ = Readonly<{\n includeTemporal: boolean;\n includeMeta: boolean;\n includeDeleted: boolean;\n}>;\n\nasync function exportNodesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeNode[]> {\n const rows = await backend.findNodesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const node: InterchangeNode = {\n kind: row.kind,\n id: row.id,\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (node as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (node as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (node as { meta?: InterchangeNode[\"meta\"] }).meta = {\n version: row.version,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return node;\n });\n}\n\n// ============================================================\n// Edge Export\n// ============================================================\n\nasync function exportEdgesOfKind(\n backend: GraphBackend,\n graphId: string,\n kind: string,\n options: ExportOptions_,\n): Promise<InterchangeEdge[]> {\n const rows = await backend.findEdgesByKind({\n graphId,\n kind,\n excludeDeleted: !options.includeDeleted,\n });\n\n return rows.map((row) => {\n const edge: InterchangeEdge = {\n kind: row.kind,\n id: row.id,\n from: {\n kind: row.from_kind,\n id: row.from_id,\n },\n to: {\n kind: row.to_kind,\n id: row.to_id,\n },\n properties: JSON.parse(row.props) as Record<string, unknown>,\n };\n\n if (options.includeTemporal) {\n if (row.valid_from) {\n (edge as { validFrom?: string }).validFrom = row.valid_from;\n }\n if (row.valid_to) {\n (edge as { validTo?: string }).validTo = row.valid_to;\n }\n }\n\n if (options.includeMeta) {\n (edge as { meta?: InterchangeEdge[\"meta\"] }).meta = {\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n }\n\n return edge;\n });\n}\n","/**\n * Graph data import functionality.\n *\n * Imports nodes and edges from the interchange format into a store,\n * with configurable conflict resolution and validation.\n */\nimport type { z } from \"zod\";\n\nimport { type GraphBackend, type TransactionBackend } from \"../backend/types\";\nimport {\n getEdgeKinds,\n getNodeKinds,\n type GraphDef,\n} from \"../core/define-graph\";\nimport { type EdgeRegistration, type NodeRegistration } from \"../core/types\";\nimport { type Store } from \"../store/store\";\nimport {\n type GraphData,\n type ImportError,\n type ImportOptions,\n type ImportResult,\n type InterchangeEdge,\n type InterchangeNode,\n type UnknownPropertyStrategy,\n} from \"./types\";\n\n// ============================================================\n// Import Function\n// ============================================================\n\n/**\n * Import graph data into a store.\n *\n * Nodes are imported first to satisfy edge reference validation.\n * The import runs within a transaction for atomicity when supported.\n *\n * @param store - The graph store to import into\n * @param data - Graph data in interchange format\n * @param options - Import configuration\n * @returns Import statistics and any errors\n *\n * @example\n * ```typescript\n * const result = await importGraph(store, data, {\n * onConflict: \"update\",\n * onUnknownProperty: \"strip\",\n * });\n *\n * console.log(`Created ${result.nodes.created} nodes`);\n * ```\n */\nexport async function importGraph<G extends GraphDef>(\n store: Store<G>,\n data: GraphData,\n options: ImportOptions,\n): Promise<ImportResult> {\n const result: ImportResult = {\n success: true,\n nodes: { created: 0, updated: 0, skipped: 0 },\n edges: { created: 0, updated: 0, skipped: 0 },\n errors: [],\n };\n\n const errors: ImportError[] = [];\n const graph = store.graph;\n const graphId = store.graphId;\n const backend = store.backend;\n\n // Build lookup maps for schema validation\n const nodeSchemas = buildNodeSchemaMap(graph);\n const edgeSchemas = buildEdgeSchemaMap(graph);\n\n // Track imported node IDs for reference validation\n const importedNodeIds = new Set<string>();\n\n // Process in transaction if supported\n if (backend.capabilities.transactions) {\n await backend.transaction(async (tx) => {\n await processNodes(\n tx,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n tx,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n });\n } else {\n await processNodes(\n backend,\n graphId,\n data.nodes,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n await processEdges(\n backend,\n graphId,\n data.edges,\n edgeSchemas,\n nodeSchemas,\n options,\n result,\n errors,\n importedNodeIds,\n );\n }\n\n return {\n ...result,\n success: errors.length === 0,\n errors,\n };\n}\n\n// ============================================================\n// Schema Maps\n// ============================================================\n\ntype NodeSchemaEntry = Readonly<{\n registration: NodeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n}>;\n\ntype EdgeSchemaEntry = Readonly<{\n registration: EdgeRegistration;\n schema: z.ZodObject<z.ZodRawShape>;\n fromKinds: ReadonlySet<string>;\n toKinds: ReadonlySet<string>;\n}>;\n\nfunction buildNodeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, NodeSchemaEntry> {\n const map = new Map<string, NodeSchemaEntry>();\n\n for (const kindName of getNodeKinds(graph)) {\n const registration = graph.nodes[kindName] as NodeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n });\n }\n\n return map;\n}\n\nfunction buildEdgeSchemaMap(\n graph: GraphDef,\n): ReadonlyMap<string, EdgeSchemaEntry> {\n const map = new Map<string, EdgeSchemaEntry>();\n\n for (const kindName of getEdgeKinds(graph)) {\n const registration = graph.edges[kindName] as EdgeRegistration;\n map.set(kindName, {\n registration,\n schema: registration.type.schema,\n fromKinds: new Set(registration.from.map((node) => node.kind)),\n toKinds: new Set(registration.to.map((node) => node.kind)),\n });\n }\n\n return map;\n}\n\n// ============================================================\n// Node Processing\n// ============================================================\n\nasync function processNodes(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n nodes: readonly InterchangeNode[],\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < nodes.length; index += batchSize) {\n const batch = nodes.slice(index, index + batchSize);\n\n for (const node of batch) {\n const importResult = await processNode(\n backend,\n graphId,\n node,\n schemas,\n options,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.nodes.created++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"updated\": {\n result.nodes.updated++;\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"skipped\": {\n result.nodes.skipped++;\n // Still track as available for edge references\n importedNodeIds.add(makeNodeKey(node.kind, node.id));\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"node\",\n kind: node.kind,\n id: node.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\ntype ProcessResult =\n | { status: \"created\" }\n | { status: \"updated\" }\n | { status: \"skipped\" }\n | { status: \"error\"; error: string };\n\nasync function processNode(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n node: InterchangeNode,\n schemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n): Promise<ProcessResult> {\n // Validate kind exists\n const schemaEntry = schemas.get(node.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown node kind: ${node.kind}` };\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n node.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if node already exists\n const existing = await backend.getNode(graphId, node.kind, node.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return {\n status: \"error\",\n error: `Node already exists: ${node.kind}:${node.id}`,\n };\n }\n case \"update\": {\n await backend.updateNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n incrementVersion: true,\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new node\n await backend.insertNode({\n graphId,\n kind: node.kind,\n id: node.id,\n props: propsResult.data,\n ...(node.validFrom !== undefined && { validFrom: node.validFrom }),\n ...(node.validTo !== undefined && { validTo: node.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Edge Processing\n// ============================================================\n\nasync function processEdges(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edges: readonly InterchangeEdge[],\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n result: ImportResult,\n errors: ImportError[],\n importedNodeIds: Set<string>,\n): Promise<void> {\n const batchSize = options.batchSize;\n\n for (let index = 0; index < edges.length; index += batchSize) {\n const batch = edges.slice(index, index + batchSize);\n\n for (const edge of batch) {\n const importResult = await processEdge(\n backend,\n graphId,\n edge,\n edgeSchemas,\n nodeSchemas,\n options,\n importedNodeIds,\n );\n\n switch (importResult.status) {\n case \"created\": {\n result.edges.created++;\n break;\n }\n case \"updated\": {\n result.edges.updated++;\n break;\n }\n case \"skipped\": {\n result.edges.skipped++;\n break;\n }\n case \"error\": {\n errors.push({\n entityType: \"edge\",\n kind: edge.kind,\n id: edge.id,\n error: importResult.error,\n });\n break;\n }\n }\n }\n }\n}\n\nasync function processEdge(\n backend: GraphBackend | TransactionBackend,\n graphId: string,\n edge: InterchangeEdge,\n edgeSchemas: ReadonlyMap<string, EdgeSchemaEntry>,\n nodeSchemas: ReadonlyMap<string, NodeSchemaEntry>,\n options: ImportOptions,\n importedNodeIds: Set<string>,\n): Promise<ProcessResult> {\n // Validate edge kind exists\n const schemaEntry = edgeSchemas.get(edge.kind);\n if (!schemaEntry) {\n return { status: \"error\", error: `Unknown edge kind: ${edge.kind}` };\n }\n\n // Validate endpoint kinds\n if (!nodeSchemas.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Unknown from node kind: ${edge.from.kind}`,\n };\n }\n if (!nodeSchemas.has(edge.to.kind)) {\n return { status: \"error\", error: `Unknown to node kind: ${edge.to.kind}` };\n }\n\n // Validate endpoint kinds are allowed for this edge type\n if (!schemaEntry.fromKinds.has(edge.from.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow from kind: ${edge.from.kind}`,\n };\n }\n if (!schemaEntry.toKinds.has(edge.to.kind)) {\n return {\n status: \"error\",\n error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`,\n };\n }\n\n // Validate references exist (in DB or in import batch)\n if (options.validateReferences) {\n const fromKey = makeNodeKey(edge.from.kind, edge.from.id);\n const toKey = makeNodeKey(edge.to.kind, edge.to.id);\n\n // Check import batch first, then DB\n if (!importedNodeIds.has(fromKey)) {\n const fromExists = await backend.getNode(\n graphId,\n edge.from.kind,\n edge.from.id,\n );\n if (!fromExists) {\n return {\n status: \"error\",\n error: `From node not found: ${edge.from.kind}:${edge.from.id}`,\n };\n }\n }\n\n if (!importedNodeIds.has(toKey)) {\n const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);\n if (!toExists) {\n return {\n status: \"error\",\n error: `To node not found: ${edge.to.kind}:${edge.to.id}`,\n };\n }\n }\n }\n\n // Validate and transform properties\n const propsResult = validateProperties(\n edge.properties,\n schemaEntry.schema,\n options.onUnknownProperty,\n );\n\n if (!propsResult.success) {\n return { status: \"error\", error: propsResult.error };\n }\n\n // Check if edge already exists\n const existing = await backend.getEdge(graphId, edge.id);\n\n if (existing) {\n switch (options.onConflict) {\n case \"skip\": {\n return { status: \"skipped\" };\n }\n case \"error\": {\n return { status: \"error\", error: `Edge already exists: ${edge.id}` };\n }\n case \"update\": {\n await backend.updateEdge({\n graphId,\n id: edge.id,\n props: propsResult.data,\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n return { status: \"updated\" };\n }\n }\n }\n\n // Create new edge\n await backend.insertEdge({\n graphId,\n id: edge.id,\n kind: edge.kind,\n fromKind: edge.from.kind,\n fromId: edge.from.id,\n toKind: edge.to.kind,\n toId: edge.to.id,\n props: propsResult.data,\n ...(edge.validFrom !== undefined && { validFrom: edge.validFrom }),\n ...(edge.validTo !== undefined && { validTo: edge.validTo }),\n });\n\n return { status: \"created\" };\n}\n\n// ============================================================\n// Property Validation\n// ============================================================\n\ntype ValidationResult =\n | { success: true; data: Record<string, unknown> }\n | { success: false; error: string };\n\nfunction validateProperties(\n properties: Record<string, unknown>,\n schema: z.ZodObject<z.ZodRawShape>,\n unknownStrategy: UnknownPropertyStrategy,\n): ValidationResult {\n try {\n // Get the schema's known keys\n const knownKeys = new Set(Object.keys(schema.shape));\n\n // Check for unknown properties\n const unknownKeys = Object.keys(properties).filter(\n (key) => !knownKeys.has(key),\n );\n\n if (unknownKeys.length > 0) {\n switch (unknownStrategy) {\n case \"error\": {\n return {\n success: false,\n error: `Unknown properties: ${unknownKeys.join(\", \")}`,\n };\n }\n case \"strip\": {\n // Remove unknown properties\n const stripped: Record<string, unknown> = {};\n for (const key of knownKeys) {\n if (key in properties) {\n stripped[key] = properties[key];\n }\n }\n // Validate stripped properties\n const result = schema.safeParse(stripped);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n return {\n success: true,\n data: result.data,\n };\n }\n case \"allow\": {\n // Validate but allow extra properties through\n const result = schema.safeParse(properties);\n if (!result.success) {\n return {\n success: false,\n error: formatZodError(result.error),\n };\n }\n // Return original properties (including unknown ones)\n return { success: true, data: properties };\n }\n }\n }\n\n // No unknown properties - standard validation\n const result = schema.safeParse(properties);\n if (!result.success) {\n return { success: false, error: formatZodError(result.error) };\n }\n\n return { success: true, data: result.data };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { success: false, error: `Validation error: ${message}` };\n }\n}\n\nfunction formatZodError(error: z.ZodError): string {\n return error.issues\n .map((issue) => {\n const path = issue.path.join(\".\");\n return path ? `${path}: ${issue.message}` : issue.message;\n })\n .join(\"; \");\n}\n\n// ============================================================\n// Helpers\n// ============================================================\n\nfunction makeNodeKey(kind: string, id: string): string {\n return `${kind}:${id}`;\n}\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GraphDef } from '../manager-
|
|
3
|
-
import {
|
|
4
|
-
import '../types-
|
|
2
|
+
import { G as GraphDef } from '../manager-BpjBW1JK.cjs';
|
|
3
|
+
import { S as Store } from '../store-BAGuOHDh.cjs';
|
|
4
|
+
import '../extension-types-D07e_NTw.cjs';
|
|
5
|
+
import '../types--0EslBx5.cjs';
|
|
5
6
|
import 'drizzle-orm';
|
|
6
|
-
import '../
|
|
7
|
+
import '../materialize-indexes-BB9N5uQl.cjs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Graph interchange format types.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GraphDef } from '../manager-
|
|
3
|
-
import {
|
|
4
|
-
import '../types-
|
|
2
|
+
import { G as GraphDef } from '../manager-BKaPQbns.js';
|
|
3
|
+
import { S as Store } from '../store-De98Lod4.js';
|
|
4
|
+
import '../extension-types-D07e_NTw.js';
|
|
5
|
+
import '../types-BNWYZ-0-.js';
|
|
5
6
|
import 'drizzle-orm';
|
|
6
|
-
import '../
|
|
7
|
+
import '../materialize-indexes-BYpU2RKh.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Graph interchange format types.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getNodeKinds, getEdgeKinds, nowIso } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { getNodeKinds, getEdgeKinds, nowIso } from '../chunk-EG6TJ3I5.js';
|
|
2
|
+
import '../chunk-WVQXAFP3.js';
|
|
3
|
+
import '../chunk-DOTEN2FG.js';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
var FORMAT_VERSION = "1.0";
|