@nicia-ai/typegraph 0.30.0 → 0.32.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 +39 -0
- package/dist/backend/postgres/index.cjs +19 -18
- package/dist/backend/postgres/index.d.cts +6 -6
- package/dist/backend/postgres/index.d.ts +6 -6
- package/dist/backend/postgres/index.js +9 -8
- package/dist/backend/postgres/pglite.cjs +13 -12
- package/dist/backend/postgres/pglite.cjs.map +1 -1
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +9 -8
- package/dist/backend/postgres/pglite.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +16 -16
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +7 -7
- package/dist/backend/sqlite/libsql.cjs +12 -12
- package/dist/backend/sqlite/libsql.d.cts +3 -3
- package/dist/backend/sqlite/libsql.d.ts +3 -3
- package/dist/backend/sqlite/libsql.js +8 -8
- package/dist/backend/sqlite/local.cjs +13 -13
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +8 -8
- package/dist/{chunk-3JLRHQ67.js → chunk-2BVHPOIG.js} +7 -6
- package/dist/chunk-2BVHPOIG.js.map +1 -0
- package/dist/chunk-2LAT5BIK.cjs +16277 -0
- package/dist/chunk-2LAT5BIK.cjs.map +1 -0
- package/dist/chunk-2YMGNYXY.js +40 -0
- package/dist/chunk-2YMGNYXY.js.map +1 -0
- package/dist/chunk-3EUKJEQ3.js +77 -0
- package/dist/chunk-3EUKJEQ3.js.map +1 -0
- package/dist/{chunk-WFCECD6Q.cjs → chunk-3HQDMOBK.cjs} +73 -68
- package/dist/chunk-3HQDMOBK.cjs.map +1 -0
- package/dist/chunk-3QRBXYT5.cjs +94 -0
- package/dist/chunk-3QRBXYT5.cjs.map +1 -0
- package/dist/chunk-6G35I3VW.cjs +40 -0
- package/dist/chunk-6G35I3VW.cjs.map +1 -0
- package/dist/{chunk-4BXHVEFB.cjs → chunk-6RMLO5O4.cjs} +6 -51
- package/dist/chunk-6RMLO5O4.cjs.map +1 -0
- package/dist/chunk-6ZR4QC3O.cjs +12 -0
- package/dist/{chunk-LUHU4T2F.cjs.map → chunk-6ZR4QC3O.cjs.map} +1 -1
- package/dist/chunk-73KASJGO.cjs +52 -0
- package/dist/chunk-73KASJGO.cjs.map +1 -0
- package/dist/{chunk-IUIJJYPI.js → chunk-7WW3WL6E.js} +6 -5
- package/dist/chunk-7WW3WL6E.js.map +1 -0
- package/dist/chunk-A3W7QG7K.js +45 -0
- package/dist/chunk-A3W7QG7K.js.map +1 -0
- package/dist/chunk-AW4A3P5A.cjs +51 -0
- package/dist/chunk-AW4A3P5A.cjs.map +1 -0
- package/dist/{chunk-AI3RNREM.js → chunk-C4C4Q7A6.js} +94 -496
- package/dist/chunk-C4C4Q7A6.js.map +1 -0
- package/dist/{chunk-4LBO6KIF.cjs → chunk-CAMMC3E4.cjs} +60 -59
- package/dist/chunk-CAMMC3E4.cjs.map +1 -0
- package/dist/{chunk-3IRMLJEK.js → chunk-CEF2QOTO.js} +3 -3
- package/dist/{chunk-3IRMLJEK.js.map → chunk-CEF2QOTO.js.map} +1 -1
- package/dist/{chunk-UESTHN47.cjs → chunk-CFNT3ITG.cjs} +95 -507
- package/dist/chunk-CFNT3ITG.cjs.map +1 -0
- package/dist/chunk-CWFPJ3RC.js +282 -0
- package/dist/chunk-CWFPJ3RC.js.map +1 -0
- package/dist/{chunk-7JGLPAFV.cjs → chunk-EEYV6UOE.cjs} +16 -16
- package/dist/chunk-EEYV6UOE.cjs.map +1 -0
- package/dist/{chunk-FWBVPATK.cjs → chunk-FDN43KXV.cjs} +19 -19
- package/dist/{chunk-FWBVPATK.cjs.map → chunk-FDN43KXV.cjs.map} +1 -1
- package/dist/chunk-HFBRAOF7.js +610 -0
- package/dist/chunk-HFBRAOF7.js.map +1 -0
- package/dist/chunk-HTGDWIDE.cjs +89 -0
- package/dist/chunk-HTGDWIDE.cjs.map +1 -0
- package/dist/{chunk-R4JOBEJU.js → chunk-IJORSAC3.js} +4 -40
- package/dist/chunk-IJORSAC3.js.map +1 -0
- package/dist/{chunk-WEMZM7J7.cjs → chunk-JKRKIEVA.cjs} +5 -41
- package/dist/chunk-JKRKIEVA.cjs.map +1 -0
- package/dist/{chunk-SGPXKJ4A.cjs → chunk-KTIEB7VH.cjs} +26 -16
- package/dist/chunk-KTIEB7VH.cjs.map +1 -0
- package/dist/{chunk-K4N35E7B.cjs → chunk-LAZGHOZW.cjs} +72 -71
- package/dist/chunk-LAZGHOZW.cjs.map +1 -0
- package/dist/{chunk-VFX3LC76.cjs → chunk-LM2IC4ZJ.cjs} +14 -14
- package/dist/{chunk-VFX3LC76.cjs.map → chunk-LM2IC4ZJ.cjs.map} +1 -1
- package/dist/{chunk-K5VREXMZ.js → chunk-NDM5PXEH.js} +7 -6
- package/dist/chunk-NDM5PXEH.js.map +1 -0
- package/dist/chunk-PIHXFF73.js +90 -0
- package/dist/chunk-PIHXFF73.js.map +1 -0
- package/dist/{chunk-FVIGJTS7.js → chunk-PRMKPFN5.js} +4 -74
- package/dist/chunk-PRMKPFN5.js.map +1 -0
- package/dist/chunk-SAJSMR2B.js +35 -0
- package/dist/chunk-SAJSMR2B.js.map +1 -0
- package/dist/chunk-SB65GJNY.cjs +624 -0
- package/dist/chunk-SB65GJNY.cjs.map +1 -0
- package/dist/{chunk-N2OEOGBB.js → chunk-TUA3MEJJ.js} +13 -8
- package/dist/chunk-TUA3MEJJ.js.map +1 -0
- package/dist/{chunk-MAQJYNJR.js → chunk-W4ZX2GCP.js} +14 -16
- package/dist/chunk-W4ZX2GCP.js.map +1 -0
- package/dist/chunk-WNORITK6.js +16231 -0
- package/dist/chunk-WNORITK6.js.map +1 -0
- package/dist/chunk-WWVV44DY.cjs +287 -0
- package/dist/chunk-WWVV44DY.cjs.map +1 -0
- package/dist/{chunk-IX7RE7CG.js → chunk-WYTUF3QO.js} +3 -3
- package/dist/{chunk-IX7RE7CG.js.map → chunk-WYTUF3QO.js.map} +1 -1
- package/dist/{chunk-2QA5EHEN.js → chunk-XKNAK27R.js} +3 -3
- package/dist/{chunk-2QA5EHEN.js.map → chunk-XKNAK27R.js.map} +1 -1
- package/dist/{chunk-633N7DSE.js → chunk-XQFAJVYW.js} +4 -36
- package/dist/chunk-XQFAJVYW.js.map +1 -0
- package/dist/{chunk-ENDUY2CD.js → chunk-YCV72E6L.js} +23 -17
- package/dist/chunk-YCV72E6L.js.map +1 -0
- package/dist/{chunk-26HWIIVS.cjs → chunk-YL4F3CMD.cjs} +63 -62
- package/dist/chunk-YL4F3CMD.cjs.map +1 -0
- package/dist/{chunk-IE6GN7L3.cjs → chunk-YW7GHMF4.cjs} +17 -98
- package/dist/chunk-YW7GHMF4.cjs.map +1 -0
- package/dist/{ddl-EdkIiFVU.d.ts → ddl-C8e8zDAE.d.ts} +3 -3
- package/dist/{ddl-BSFlbGQF.d.cts → ddl-CwyG4HoQ.d.cts} +3 -3
- package/dist/{extension-types-CwHV-Uk4.d.cts → extension-types-D1k0inWU.d.cts} +1 -1
- package/dist/{extension-types-CwHV-Uk4.d.ts → extension-types-D1k0inWU.d.ts} +1 -1
- package/dist/graph-extension/index.cjs +17 -17
- package/dist/graph-extension/index.d.cts +5 -16
- package/dist/graph-extension/index.d.ts +5 -16
- package/dist/graph-extension/index.js +2 -2
- package/dist/graph-merge/index.cjs +3966 -0
- package/dist/graph-merge/index.cjs.map +1 -0
- package/dist/graph-merge/index.d.cts +1191 -0
- package/dist/graph-merge/index.d.ts +1191 -0
- package/dist/graph-merge/index.js +3935 -0
- package/dist/graph-merge/index.js.map +1 -0
- package/dist/{index-DzeIiMO3.d.ts → index-BEK0VtNB.d.ts} +2 -2
- package/dist/{index-Ln_KHTGA.d.cts → index-C8sSTErx.d.cts} +2 -2
- package/dist/index.cjs +291 -15919
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -11
- package/dist/index.d.ts +12 -11
- package/dist/index.js +24 -15791
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +30 -26
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +6 -2
- package/dist/interchange/index.cjs +49 -592
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +9 -9
- package/dist/interchange/index.d.ts +9 -9
- package/dist/interchange/index.js +2 -588
- package/dist/interchange/index.js.map +1 -1
- package/dist/{manager-BbdyNhkv.d.ts → manager-8htmuGr-.d.ts} +3 -3
- package/dist/{manager-wTDgjoXG.d.cts → manager-aVgxbGt-.d.cts} +3 -3
- package/dist/{materialize-indexes-lkawaDor.d.ts → materialize-indexes-CAGhqPHQ.d.ts} +1 -1
- package/dist/{materialize-indexes-oanE3RU0.d.cts → materialize-indexes-DEYkU-wr.d.cts} +1 -1
- package/dist/{postgres-CK2ByP1q.d.cts → postgres-Dhom7iiX.d.ts} +1 -1
- package/dist/{postgres-ymXYC6Rr.d.ts → postgres-jgXmD45C.d.cts} +1 -1
- package/dist/profiler/index.d.cts +7 -7
- package/dist/profiler/index.d.ts +7 -7
- package/dist/result-DWo6mUVz.d.cts +37 -0
- package/dist/result-DWo6mUVz.d.ts +37 -0
- package/dist/schema/index.cjs +30 -29
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +7 -7
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +7 -6
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-R8YGOqVQ.d.ts → sqlite-BfLsCEqO.d.ts} +1 -1
- package/dist/{sqlite-DxH1lrwD.d.cts → sqlite-DcQ_BCUW.d.cts} +1 -1
- package/dist/{store-CNKM334w.d.ts → store-view-lTcb_cnp.d.cts} +694 -366
- package/dist/{store--z1Tmk7U.d.cts → store-view-pBOUrQte.d.ts} +694 -366
- package/dist/{types-D5B6Be5c.d.cts → types-5RQwzWXx.d.cts} +2 -2
- package/dist/{types-CMvxx2kd.d.ts → types-DGDiXAYc.d.ts} +2 -2
- package/dist/{types-BBiDqJCU.d.ts → types-Dk8r09KY.d.ts} +16 -2
- package/dist/{types-dL-clxO3.d.cts → types-Dvmn-eal.d.cts} +16 -2
- package/dist/{where-CAo6wsBZ.d.ts → where-CHZFELX0.d.ts} +2 -2
- package/dist/{where-bJjuOCeV.d.cts → where-Cx_glEEB.d.cts} +2 -2
- package/package.json +7 -2
- package/dist/chunk-26HWIIVS.cjs.map +0 -1
- package/dist/chunk-3JLRHQ67.js.map +0 -1
- package/dist/chunk-4BXHVEFB.cjs.map +0 -1
- package/dist/chunk-4LBO6KIF.cjs.map +0 -1
- package/dist/chunk-633N7DSE.js.map +0 -1
- package/dist/chunk-7JGLPAFV.cjs.map +0 -1
- package/dist/chunk-AI3RNREM.js.map +0 -1
- package/dist/chunk-ENDUY2CD.js.map +0 -1
- package/dist/chunk-FVIGJTS7.js.map +0 -1
- package/dist/chunk-IE6GN7L3.cjs.map +0 -1
- package/dist/chunk-IUIJJYPI.js.map +0 -1
- package/dist/chunk-K4N35E7B.cjs.map +0 -1
- package/dist/chunk-K5VREXMZ.js.map +0 -1
- package/dist/chunk-LUHU4T2F.cjs +0 -12
- package/dist/chunk-MAQJYNJR.js.map +0 -1
- package/dist/chunk-N2OEOGBB.js.map +0 -1
- package/dist/chunk-R4JOBEJU.js.map +0 -1
- package/dist/chunk-SGPXKJ4A.cjs.map +0 -1
- package/dist/chunk-UESTHN47.cjs.map +0 -1
- package/dist/chunk-WEMZM7J7.cjs.map +0 -1
- package/dist/chunk-WFCECD6Q.cjs.map +0 -1
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkEEYV6UOE_cjs = require('./chunk-EEYV6UOE.cjs');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var FORMAT_VERSION = "1.0";
|
|
7
|
+
var ValidityTimestampSchema = zod.z.iso.datetime().refine((value) => chunkEEYV6UOE_cjs.isCanonicalIsoDate(value), {
|
|
8
|
+
message: "Expected canonical UTC ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ); convert with new Date(value).toISOString()."
|
|
9
|
+
});
|
|
10
|
+
var InterchangeNodeSchema = zod.z.object({
|
|
11
|
+
kind: zod.z.string().min(1),
|
|
12
|
+
id: zod.z.string().min(1),
|
|
13
|
+
properties: zod.z.record(zod.z.string(), zod.z.unknown()),
|
|
14
|
+
validFrom: ValidityTimestampSchema.optional(),
|
|
15
|
+
validTo: ValidityTimestampSchema.optional(),
|
|
16
|
+
meta: zod.z.object({
|
|
17
|
+
version: zod.z.number().int().positive().optional(),
|
|
18
|
+
createdAt: zod.z.iso.datetime().optional(),
|
|
19
|
+
updatedAt: zod.z.iso.datetime().optional()
|
|
20
|
+
}).optional()
|
|
21
|
+
});
|
|
22
|
+
var InterchangeEdgeSchema = zod.z.object({
|
|
23
|
+
kind: zod.z.string().min(1),
|
|
24
|
+
id: zod.z.string().min(1),
|
|
25
|
+
from: zod.z.object({
|
|
26
|
+
kind: zod.z.string().min(1),
|
|
27
|
+
id: zod.z.string().min(1)
|
|
28
|
+
}),
|
|
29
|
+
to: zod.z.object({
|
|
30
|
+
kind: zod.z.string().min(1),
|
|
31
|
+
id: zod.z.string().min(1)
|
|
32
|
+
}),
|
|
33
|
+
properties: zod.z.record(zod.z.string(), zod.z.unknown()).default({}),
|
|
34
|
+
validFrom: ValidityTimestampSchema.optional(),
|
|
35
|
+
validTo: ValidityTimestampSchema.optional(),
|
|
36
|
+
meta: zod.z.object({
|
|
37
|
+
createdAt: zod.z.iso.datetime().optional(),
|
|
38
|
+
updatedAt: zod.z.iso.datetime().optional()
|
|
39
|
+
}).optional()
|
|
40
|
+
});
|
|
41
|
+
var ConflictStrategySchema = zod.z.enum(["skip", "update", "error"]);
|
|
42
|
+
var UnknownPropertyStrategySchema = zod.z.enum([
|
|
43
|
+
"error",
|
|
44
|
+
"strip",
|
|
45
|
+
"allow"
|
|
46
|
+
]);
|
|
47
|
+
var ImportOptionsSchema = zod.z.object({
|
|
48
|
+
/** How to handle existing nodes/edges with the same ID */
|
|
49
|
+
onConflict: ConflictStrategySchema,
|
|
50
|
+
/** How to handle properties not in the schema */
|
|
51
|
+
onUnknownProperty: UnknownPropertyStrategySchema.default("error"),
|
|
52
|
+
/** Whether to validate that edge endpoints exist */
|
|
53
|
+
validateReferences: zod.z.boolean().default(true),
|
|
54
|
+
/** Number of items to process in each batch */
|
|
55
|
+
batchSize: zod.z.number().int().positive().default(100)
|
|
56
|
+
});
|
|
57
|
+
var GraphDataSourceSchema = zod.z.discriminatedUnion("type", [
|
|
58
|
+
zod.z.object({
|
|
59
|
+
type: zod.z.literal("typegraph-export"),
|
|
60
|
+
graphId: zod.z.string(),
|
|
61
|
+
schemaVersion: zod.z.number().int().positive()
|
|
62
|
+
}),
|
|
63
|
+
zod.z.object({
|
|
64
|
+
type: zod.z.literal("external"),
|
|
65
|
+
description: zod.z.string().optional()
|
|
66
|
+
})
|
|
67
|
+
]);
|
|
68
|
+
var GraphDataSchema = zod.z.object({
|
|
69
|
+
formatVersion: zod.z.literal(FORMAT_VERSION),
|
|
70
|
+
exportedAt: zod.z.iso.datetime(),
|
|
71
|
+
source: GraphDataSourceSchema,
|
|
72
|
+
nodes: zod.z.array(InterchangeNodeSchema),
|
|
73
|
+
edges: zod.z.array(InterchangeEdgeSchema)
|
|
74
|
+
});
|
|
75
|
+
var ImportErrorSchema = zod.z.object({
|
|
76
|
+
entityType: zod.z.enum(["node", "edge"]),
|
|
77
|
+
kind: zod.z.string(),
|
|
78
|
+
id: zod.z.string(),
|
|
79
|
+
error: zod.z.string()
|
|
80
|
+
});
|
|
81
|
+
var ImportResultSchema = zod.z.object({
|
|
82
|
+
success: zod.z.boolean(),
|
|
83
|
+
nodes: zod.z.object({
|
|
84
|
+
created: zod.z.number().int().nonnegative(),
|
|
85
|
+
updated: zod.z.number().int().nonnegative(),
|
|
86
|
+
skipped: zod.z.number().int().nonnegative()
|
|
87
|
+
}),
|
|
88
|
+
edges: zod.z.object({
|
|
89
|
+
created: zod.z.number().int().nonnegative(),
|
|
90
|
+
updated: zod.z.number().int().nonnegative(),
|
|
91
|
+
skipped: zod.z.number().int().nonnegative()
|
|
92
|
+
}),
|
|
93
|
+
errors: zod.z.array(ImportErrorSchema)
|
|
94
|
+
});
|
|
95
|
+
var ExportOptionsSchema = zod.z.object({
|
|
96
|
+
/** Filter to specific node kinds (undefined = all) */
|
|
97
|
+
nodeKinds: zod.z.array(zod.z.string()).optional(),
|
|
98
|
+
/** Filter to specific edge kinds (undefined = all) */
|
|
99
|
+
edgeKinds: zod.z.array(zod.z.string()).optional(),
|
|
100
|
+
/** Include temporal fields (validFrom, validTo) */
|
|
101
|
+
includeTemporal: zod.z.boolean().default(false),
|
|
102
|
+
/** Include metadata (version, timestamps) */
|
|
103
|
+
includeMeta: zod.z.boolean().default(false),
|
|
104
|
+
/** Include soft-deleted records */
|
|
105
|
+
includeDeleted: zod.z.boolean().default(false)
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// src/interchange/export.ts
|
|
109
|
+
async function exportGraph(store, options) {
|
|
110
|
+
const options_ = {
|
|
111
|
+
nodeKinds: options?.nodeKinds,
|
|
112
|
+
edgeKinds: options?.edgeKinds,
|
|
113
|
+
includeTemporal: options?.includeTemporal ?? false,
|
|
114
|
+
includeMeta: options?.includeMeta ?? false,
|
|
115
|
+
includeDeleted: options?.includeDeleted ?? false
|
|
116
|
+
};
|
|
117
|
+
const graph = store.graph;
|
|
118
|
+
const graphId = store.graphId;
|
|
119
|
+
const backend = store.backend;
|
|
120
|
+
const nodeKindsToExport = options_.nodeKinds ?? chunkEEYV6UOE_cjs.getNodeKinds(graph);
|
|
121
|
+
const edgeKindsToExport = options_.edgeKinds ?? chunkEEYV6UOE_cjs.getEdgeKinds(graph);
|
|
122
|
+
const nodes = [];
|
|
123
|
+
for (const kind of nodeKindsToExport) {
|
|
124
|
+
const kindNodes = await exportNodesOfKind(backend, graphId, kind, options_);
|
|
125
|
+
nodes.push(...kindNodes);
|
|
126
|
+
}
|
|
127
|
+
const edges = [];
|
|
128
|
+
for (const kind of edgeKindsToExport) {
|
|
129
|
+
const kindEdges = await exportEdgesOfKind(backend, graphId, kind, options_);
|
|
130
|
+
edges.push(...kindEdges);
|
|
131
|
+
}
|
|
132
|
+
const schemaVersion = await backend.getActiveSchema(graphId);
|
|
133
|
+
return {
|
|
134
|
+
formatVersion: FORMAT_VERSION,
|
|
135
|
+
exportedAt: chunkEEYV6UOE_cjs.nowIso(),
|
|
136
|
+
source: {
|
|
137
|
+
type: "typegraph-export",
|
|
138
|
+
graphId,
|
|
139
|
+
schemaVersion: schemaVersion?.version ?? 1
|
|
140
|
+
},
|
|
141
|
+
nodes,
|
|
142
|
+
edges
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async function exportNodesOfKind(backend, graphId, kind, options) {
|
|
146
|
+
const rows = await backend.findNodesByKind({
|
|
147
|
+
graphId,
|
|
148
|
+
kind,
|
|
149
|
+
excludeDeleted: !options.includeDeleted
|
|
150
|
+
});
|
|
151
|
+
return rows.map((row) => {
|
|
152
|
+
const node = {
|
|
153
|
+
kind: row.kind,
|
|
154
|
+
id: row.id,
|
|
155
|
+
properties: JSON.parse(row.props)
|
|
156
|
+
};
|
|
157
|
+
if (options.includeTemporal) {
|
|
158
|
+
if (row.valid_from) {
|
|
159
|
+
node.validFrom = row.valid_from;
|
|
160
|
+
}
|
|
161
|
+
if (row.valid_to) {
|
|
162
|
+
node.validTo = row.valid_to;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (options.includeMeta) {
|
|
166
|
+
node.meta = {
|
|
167
|
+
version: row.version,
|
|
168
|
+
createdAt: row.created_at,
|
|
169
|
+
updatedAt: row.updated_at
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return node;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async function exportEdgesOfKind(backend, graphId, kind, options) {
|
|
176
|
+
const rows = await backend.findEdgesByKind({
|
|
177
|
+
graphId,
|
|
178
|
+
kind,
|
|
179
|
+
excludeDeleted: !options.includeDeleted
|
|
180
|
+
});
|
|
181
|
+
return rows.map((row) => {
|
|
182
|
+
const edge = {
|
|
183
|
+
kind: row.kind,
|
|
184
|
+
id: row.id,
|
|
185
|
+
from: {
|
|
186
|
+
kind: row.from_kind,
|
|
187
|
+
id: row.from_id
|
|
188
|
+
},
|
|
189
|
+
to: {
|
|
190
|
+
kind: row.to_kind,
|
|
191
|
+
id: row.to_id
|
|
192
|
+
},
|
|
193
|
+
properties: JSON.parse(row.props)
|
|
194
|
+
};
|
|
195
|
+
if (options.includeTemporal) {
|
|
196
|
+
if (row.valid_from) {
|
|
197
|
+
edge.validFrom = row.valid_from;
|
|
198
|
+
}
|
|
199
|
+
if (row.valid_to) {
|
|
200
|
+
edge.validTo = row.valid_to;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (options.includeMeta) {
|
|
204
|
+
edge.meta = {
|
|
205
|
+
createdAt: row.created_at,
|
|
206
|
+
updatedAt: row.updated_at
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return edge;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/interchange/import.ts
|
|
214
|
+
async function importGraph(store, data, options) {
|
|
215
|
+
const result = {
|
|
216
|
+
success: true,
|
|
217
|
+
nodes: { created: 0, updated: 0, skipped: 0 },
|
|
218
|
+
edges: { created: 0, updated: 0, skipped: 0 },
|
|
219
|
+
errors: []
|
|
220
|
+
};
|
|
221
|
+
const errors = [];
|
|
222
|
+
const graph = store.graph;
|
|
223
|
+
const graphId = store.graphId;
|
|
224
|
+
const backend = store.backend;
|
|
225
|
+
const nodeSchemas = buildNodeSchemaMap(graph);
|
|
226
|
+
const edgeSchemas = buildEdgeSchemaMap(graph);
|
|
227
|
+
const importedNodeIds = /* @__PURE__ */ new Set();
|
|
228
|
+
if (backend.capabilities.transactions) {
|
|
229
|
+
await backend.transaction(async (tx) => {
|
|
230
|
+
await processNodes(
|
|
231
|
+
tx,
|
|
232
|
+
graphId,
|
|
233
|
+
data.nodes,
|
|
234
|
+
nodeSchemas,
|
|
235
|
+
options,
|
|
236
|
+
result,
|
|
237
|
+
errors,
|
|
238
|
+
importedNodeIds
|
|
239
|
+
);
|
|
240
|
+
await processEdges(
|
|
241
|
+
tx,
|
|
242
|
+
graphId,
|
|
243
|
+
data.edges,
|
|
244
|
+
edgeSchemas,
|
|
245
|
+
nodeSchemas,
|
|
246
|
+
options,
|
|
247
|
+
result,
|
|
248
|
+
errors,
|
|
249
|
+
importedNodeIds
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
} else {
|
|
253
|
+
await processNodes(
|
|
254
|
+
backend,
|
|
255
|
+
graphId,
|
|
256
|
+
data.nodes,
|
|
257
|
+
nodeSchemas,
|
|
258
|
+
options,
|
|
259
|
+
result,
|
|
260
|
+
errors,
|
|
261
|
+
importedNodeIds
|
|
262
|
+
);
|
|
263
|
+
await processEdges(
|
|
264
|
+
backend,
|
|
265
|
+
graphId,
|
|
266
|
+
data.edges,
|
|
267
|
+
edgeSchemas,
|
|
268
|
+
nodeSchemas,
|
|
269
|
+
options,
|
|
270
|
+
result,
|
|
271
|
+
errors,
|
|
272
|
+
importedNodeIds
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
...result,
|
|
277
|
+
success: errors.length === 0,
|
|
278
|
+
errors
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function buildNodeSchemaMap(graph) {
|
|
282
|
+
const map = /* @__PURE__ */ new Map();
|
|
283
|
+
for (const kindName of chunkEEYV6UOE_cjs.getNodeKinds(graph)) {
|
|
284
|
+
const registration = graph.nodes[kindName];
|
|
285
|
+
map.set(kindName, {
|
|
286
|
+
registration,
|
|
287
|
+
schema: registration.type.schema
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return map;
|
|
291
|
+
}
|
|
292
|
+
function buildEdgeSchemaMap(graph) {
|
|
293
|
+
const map = /* @__PURE__ */ new Map();
|
|
294
|
+
for (const kindName of chunkEEYV6UOE_cjs.getEdgeKinds(graph)) {
|
|
295
|
+
const registration = graph.edges[kindName];
|
|
296
|
+
map.set(kindName, {
|
|
297
|
+
registration,
|
|
298
|
+
schema: registration.type.schema,
|
|
299
|
+
fromKinds: new Set(registration.from.map((node) => node.kind)),
|
|
300
|
+
toKinds: new Set(registration.to.map((node) => node.kind))
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return map;
|
|
304
|
+
}
|
|
305
|
+
async function processNodes(backend, graphId, nodes, schemas, options, result, errors, importedNodeIds) {
|
|
306
|
+
const batchSize = options.batchSize;
|
|
307
|
+
for (let index = 0; index < nodes.length; index += batchSize) {
|
|
308
|
+
const batch = nodes.slice(index, index + batchSize);
|
|
309
|
+
for (const node of batch) {
|
|
310
|
+
const importResult = await processNode(
|
|
311
|
+
backend,
|
|
312
|
+
graphId,
|
|
313
|
+
node,
|
|
314
|
+
schemas,
|
|
315
|
+
options
|
|
316
|
+
);
|
|
317
|
+
switch (importResult.status) {
|
|
318
|
+
case "created": {
|
|
319
|
+
result.nodes.created++;
|
|
320
|
+
importedNodeIds.add(makeNodeKey(node.kind, node.id));
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case "updated": {
|
|
324
|
+
result.nodes.updated++;
|
|
325
|
+
importedNodeIds.add(makeNodeKey(node.kind, node.id));
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
case "skipped": {
|
|
329
|
+
result.nodes.skipped++;
|
|
330
|
+
importedNodeIds.add(makeNodeKey(node.kind, node.id));
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case "error": {
|
|
334
|
+
errors.push({
|
|
335
|
+
entityType: "node",
|
|
336
|
+
kind: node.kind,
|
|
337
|
+
id: node.id,
|
|
338
|
+
error: importResult.error
|
|
339
|
+
});
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function validateValidityWindow(entity) {
|
|
347
|
+
try {
|
|
348
|
+
chunkEEYV6UOE_cjs.validateOptionalCanonicalIsoDate(entity.validFrom, "validFrom");
|
|
349
|
+
chunkEEYV6UOE_cjs.validateOptionalCanonicalIsoDate(entity.validTo, "validTo");
|
|
350
|
+
return void 0;
|
|
351
|
+
} catch (error) {
|
|
352
|
+
return error instanceof Error ? error.message : String(error);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function processNode(backend, graphId, node, schemas, options) {
|
|
356
|
+
const schemaEntry = schemas.get(node.kind);
|
|
357
|
+
if (!schemaEntry) {
|
|
358
|
+
return { status: "error", error: `Unknown node kind: ${node.kind}` };
|
|
359
|
+
}
|
|
360
|
+
const propsResult = validateProperties(
|
|
361
|
+
node.properties,
|
|
362
|
+
schemaEntry.schema,
|
|
363
|
+
options.onUnknownProperty
|
|
364
|
+
);
|
|
365
|
+
if (!propsResult.success) {
|
|
366
|
+
return { status: "error", error: propsResult.error };
|
|
367
|
+
}
|
|
368
|
+
const validityError = validateValidityWindow(node);
|
|
369
|
+
if (validityError !== void 0) {
|
|
370
|
+
return { status: "error", error: validityError };
|
|
371
|
+
}
|
|
372
|
+
const existing = await backend.getNode(graphId, node.kind, node.id);
|
|
373
|
+
if (existing) {
|
|
374
|
+
switch (options.onConflict) {
|
|
375
|
+
case "skip": {
|
|
376
|
+
return { status: "skipped" };
|
|
377
|
+
}
|
|
378
|
+
case "error": {
|
|
379
|
+
return {
|
|
380
|
+
status: "error",
|
|
381
|
+
error: `Node already exists: ${node.kind}:${node.id}`
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
case "update": {
|
|
385
|
+
await backend.updateNode({
|
|
386
|
+
graphId,
|
|
387
|
+
kind: node.kind,
|
|
388
|
+
id: node.id,
|
|
389
|
+
props: propsResult.data,
|
|
390
|
+
incrementVersion: true,
|
|
391
|
+
...node.validTo !== void 0 && { validTo: node.validTo }
|
|
392
|
+
});
|
|
393
|
+
return { status: "updated" };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
await backend.insertNode({
|
|
398
|
+
graphId,
|
|
399
|
+
kind: node.kind,
|
|
400
|
+
id: node.id,
|
|
401
|
+
props: propsResult.data,
|
|
402
|
+
...node.validFrom !== void 0 && { validFrom: node.validFrom },
|
|
403
|
+
...node.validTo !== void 0 && { validTo: node.validTo }
|
|
404
|
+
});
|
|
405
|
+
return { status: "created" };
|
|
406
|
+
}
|
|
407
|
+
async function processEdges(backend, graphId, edges, edgeSchemas, nodeSchemas, options, result, errors, importedNodeIds) {
|
|
408
|
+
const batchSize = options.batchSize;
|
|
409
|
+
for (let index = 0; index < edges.length; index += batchSize) {
|
|
410
|
+
const batch = edges.slice(index, index + batchSize);
|
|
411
|
+
for (const edge of batch) {
|
|
412
|
+
const importResult = await processEdge(
|
|
413
|
+
backend,
|
|
414
|
+
graphId,
|
|
415
|
+
edge,
|
|
416
|
+
edgeSchemas,
|
|
417
|
+
nodeSchemas,
|
|
418
|
+
options,
|
|
419
|
+
importedNodeIds
|
|
420
|
+
);
|
|
421
|
+
switch (importResult.status) {
|
|
422
|
+
case "created": {
|
|
423
|
+
result.edges.created++;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
case "updated": {
|
|
427
|
+
result.edges.updated++;
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case "skipped": {
|
|
431
|
+
result.edges.skipped++;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
case "error": {
|
|
435
|
+
errors.push({
|
|
436
|
+
entityType: "edge",
|
|
437
|
+
kind: edge.kind,
|
|
438
|
+
id: edge.id,
|
|
439
|
+
error: importResult.error
|
|
440
|
+
});
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async function processEdge(backend, graphId, edge, edgeSchemas, nodeSchemas, options, importedNodeIds) {
|
|
448
|
+
const schemaEntry = edgeSchemas.get(edge.kind);
|
|
449
|
+
if (!schemaEntry) {
|
|
450
|
+
return { status: "error", error: `Unknown edge kind: ${edge.kind}` };
|
|
451
|
+
}
|
|
452
|
+
if (!nodeSchemas.has(edge.from.kind)) {
|
|
453
|
+
return {
|
|
454
|
+
status: "error",
|
|
455
|
+
error: `Unknown from node kind: ${edge.from.kind}`
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
if (!nodeSchemas.has(edge.to.kind)) {
|
|
459
|
+
return { status: "error", error: `Unknown to node kind: ${edge.to.kind}` };
|
|
460
|
+
}
|
|
461
|
+
if (!schemaEntry.fromKinds.has(edge.from.kind)) {
|
|
462
|
+
return {
|
|
463
|
+
status: "error",
|
|
464
|
+
error: `Edge ${edge.kind} does not allow from kind: ${edge.from.kind}`
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (!schemaEntry.toKinds.has(edge.to.kind)) {
|
|
468
|
+
return {
|
|
469
|
+
status: "error",
|
|
470
|
+
error: `Edge ${edge.kind} does not allow to kind: ${edge.to.kind}`
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
if (options.validateReferences) {
|
|
474
|
+
const fromKey = makeNodeKey(edge.from.kind, edge.from.id);
|
|
475
|
+
const toKey = makeNodeKey(edge.to.kind, edge.to.id);
|
|
476
|
+
if (!importedNodeIds.has(fromKey)) {
|
|
477
|
+
const fromExists = await backend.getNode(
|
|
478
|
+
graphId,
|
|
479
|
+
edge.from.kind,
|
|
480
|
+
edge.from.id
|
|
481
|
+
);
|
|
482
|
+
if (!fromExists) {
|
|
483
|
+
return {
|
|
484
|
+
status: "error",
|
|
485
|
+
error: `From node not found: ${edge.from.kind}:${edge.from.id}`
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (!importedNodeIds.has(toKey)) {
|
|
490
|
+
const toExists = await backend.getNode(graphId, edge.to.kind, edge.to.id);
|
|
491
|
+
if (!toExists) {
|
|
492
|
+
return {
|
|
493
|
+
status: "error",
|
|
494
|
+
error: `To node not found: ${edge.to.kind}:${edge.to.id}`
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const propsResult = validateProperties(
|
|
500
|
+
edge.properties,
|
|
501
|
+
schemaEntry.schema,
|
|
502
|
+
options.onUnknownProperty
|
|
503
|
+
);
|
|
504
|
+
if (!propsResult.success) {
|
|
505
|
+
return { status: "error", error: propsResult.error };
|
|
506
|
+
}
|
|
507
|
+
const validityError = validateValidityWindow(edge);
|
|
508
|
+
if (validityError !== void 0) {
|
|
509
|
+
return { status: "error", error: validityError };
|
|
510
|
+
}
|
|
511
|
+
const existing = await backend.getEdge(graphId, edge.id);
|
|
512
|
+
if (existing) {
|
|
513
|
+
switch (options.onConflict) {
|
|
514
|
+
case "skip": {
|
|
515
|
+
return { status: "skipped" };
|
|
516
|
+
}
|
|
517
|
+
case "error": {
|
|
518
|
+
return { status: "error", error: `Edge already exists: ${edge.id}` };
|
|
519
|
+
}
|
|
520
|
+
case "update": {
|
|
521
|
+
await backend.updateEdge({
|
|
522
|
+
graphId,
|
|
523
|
+
id: edge.id,
|
|
524
|
+
props: propsResult.data,
|
|
525
|
+
...edge.validTo !== void 0 && { validTo: edge.validTo }
|
|
526
|
+
});
|
|
527
|
+
return { status: "updated" };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
await backend.insertEdge({
|
|
532
|
+
graphId,
|
|
533
|
+
id: edge.id,
|
|
534
|
+
kind: edge.kind,
|
|
535
|
+
fromKind: edge.from.kind,
|
|
536
|
+
fromId: edge.from.id,
|
|
537
|
+
toKind: edge.to.kind,
|
|
538
|
+
toId: edge.to.id,
|
|
539
|
+
props: propsResult.data,
|
|
540
|
+
...edge.validFrom !== void 0 && { validFrom: edge.validFrom },
|
|
541
|
+
...edge.validTo !== void 0 && { validTo: edge.validTo }
|
|
542
|
+
});
|
|
543
|
+
return { status: "created" };
|
|
544
|
+
}
|
|
545
|
+
function validateProperties(properties, schema, unknownStrategy) {
|
|
546
|
+
try {
|
|
547
|
+
const knownKeys = new Set(Object.keys(schema.shape));
|
|
548
|
+
const unknownKeys = Object.keys(properties).filter(
|
|
549
|
+
(key) => !knownKeys.has(key)
|
|
550
|
+
);
|
|
551
|
+
if (unknownKeys.length > 0) {
|
|
552
|
+
switch (unknownStrategy) {
|
|
553
|
+
case "error": {
|
|
554
|
+
return {
|
|
555
|
+
success: false,
|
|
556
|
+
error: `Unknown properties: ${unknownKeys.join(", ")}`
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
case "strip": {
|
|
560
|
+
const stripped = {};
|
|
561
|
+
for (const key of knownKeys) {
|
|
562
|
+
if (key in properties) {
|
|
563
|
+
stripped[key] = properties[key];
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const result2 = schema.safeParse(stripped);
|
|
567
|
+
if (!result2.success) {
|
|
568
|
+
return {
|
|
569
|
+
success: false,
|
|
570
|
+
error: formatZodError(result2.error)
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
success: true,
|
|
575
|
+
data: result2.data
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
case "allow": {
|
|
579
|
+
const result2 = schema.safeParse(properties);
|
|
580
|
+
if (!result2.success) {
|
|
581
|
+
return {
|
|
582
|
+
success: false,
|
|
583
|
+
error: formatZodError(result2.error)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
return { success: true, data: properties };
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const result = schema.safeParse(properties);
|
|
591
|
+
if (!result.success) {
|
|
592
|
+
return { success: false, error: formatZodError(result.error) };
|
|
593
|
+
}
|
|
594
|
+
return { success: true, data: result.data };
|
|
595
|
+
} catch (error) {
|
|
596
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
597
|
+
return { success: false, error: `Validation error: ${message}` };
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function formatZodError(error) {
|
|
601
|
+
return error.issues.map((issue) => {
|
|
602
|
+
const path = issue.path.join(".");
|
|
603
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
604
|
+
}).join("; ");
|
|
605
|
+
}
|
|
606
|
+
function makeNodeKey(kind, id) {
|
|
607
|
+
return `${kind}:${id}`;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
exports.ConflictStrategySchema = ConflictStrategySchema;
|
|
611
|
+
exports.ExportOptionsSchema = ExportOptionsSchema;
|
|
612
|
+
exports.FORMAT_VERSION = FORMAT_VERSION;
|
|
613
|
+
exports.GraphDataSchema = GraphDataSchema;
|
|
614
|
+
exports.GraphDataSourceSchema = GraphDataSourceSchema;
|
|
615
|
+
exports.ImportErrorSchema = ImportErrorSchema;
|
|
616
|
+
exports.ImportOptionsSchema = ImportOptionsSchema;
|
|
617
|
+
exports.ImportResultSchema = ImportResultSchema;
|
|
618
|
+
exports.InterchangeEdgeSchema = InterchangeEdgeSchema;
|
|
619
|
+
exports.InterchangeNodeSchema = InterchangeNodeSchema;
|
|
620
|
+
exports.UnknownPropertyStrategySchema = UnknownPropertyStrategySchema;
|
|
621
|
+
exports.exportGraph = exportGraph;
|
|
622
|
+
exports.importGraph = importGraph;
|
|
623
|
+
//# sourceMappingURL=chunk-SB65GJNY.cjs.map
|
|
624
|
+
//# sourceMappingURL=chunk-SB65GJNY.cjs.map
|