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