@nicia-ai/typegraph 0.1.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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/ast-BVyihVbP.d.cts +564 -0
  4. package/dist/ast-BVyihVbP.d.ts +564 -0
  5. package/dist/backend/drizzle/index.cjs +41 -0
  6. package/dist/backend/drizzle/index.cjs.map +1 -0
  7. package/dist/backend/drizzle/index.d.cts +12 -0
  8. package/dist/backend/drizzle/index.d.ts +12 -0
  9. package/dist/backend/drizzle/index.js +12 -0
  10. package/dist/backend/drizzle/index.js.map +1 -0
  11. package/dist/backend/drizzle/postgres.cjs +27 -0
  12. package/dist/backend/drizzle/postgres.cjs.map +1 -0
  13. package/dist/backend/drizzle/postgres.d.cts +37 -0
  14. package/dist/backend/drizzle/postgres.d.ts +37 -0
  15. package/dist/backend/drizzle/postgres.js +10 -0
  16. package/dist/backend/drizzle/postgres.js.map +1 -0
  17. package/dist/backend/drizzle/schema/postgres.cjs +40 -0
  18. package/dist/backend/drizzle/schema/postgres.cjs.map +1 -0
  19. package/dist/backend/drizzle/schema/postgres.d.cts +2419 -0
  20. package/dist/backend/drizzle/schema/postgres.d.ts +2419 -0
  21. package/dist/backend/drizzle/schema/postgres.js +7 -0
  22. package/dist/backend/drizzle/schema/postgres.js.map +1 -0
  23. package/dist/backend/drizzle/schema/sqlite.cjs +40 -0
  24. package/dist/backend/drizzle/schema/sqlite.cjs.map +1 -0
  25. package/dist/backend/drizzle/schema/sqlite.d.cts +2647 -0
  26. package/dist/backend/drizzle/schema/sqlite.d.ts +2647 -0
  27. package/dist/backend/drizzle/schema/sqlite.js +7 -0
  28. package/dist/backend/drizzle/schema/sqlite.js.map +1 -0
  29. package/dist/backend/drizzle/sqlite.cjs +27 -0
  30. package/dist/backend/drizzle/sqlite.cjs.map +1 -0
  31. package/dist/backend/drizzle/sqlite.d.cts +36 -0
  32. package/dist/backend/drizzle/sqlite.d.ts +36 -0
  33. package/dist/backend/drizzle/sqlite.js +10 -0
  34. package/dist/backend/drizzle/sqlite.js.map +1 -0
  35. package/dist/backend/postgres/index.cjs +53 -0
  36. package/dist/backend/postgres/index.cjs.map +1 -0
  37. package/dist/backend/postgres/index.d.cts +12 -0
  38. package/dist/backend/postgres/index.d.ts +12 -0
  39. package/dist/backend/postgres/index.js +12 -0
  40. package/dist/backend/postgres/index.js.map +1 -0
  41. package/dist/backend/sqlite/index.cjs +117 -0
  42. package/dist/backend/sqlite/index.cjs.map +1 -0
  43. package/dist/backend/sqlite/index.d.cts +71 -0
  44. package/dist/backend/sqlite/index.d.ts +71 -0
  45. package/dist/backend/sqlite/index.js +78 -0
  46. package/dist/backend/sqlite/index.js.map +1 -0
  47. package/dist/chunk-2QHQ2C4P.js +146 -0
  48. package/dist/chunk-2QHQ2C4P.js.map +1 -0
  49. package/dist/chunk-3A5TKOEJ.js +306 -0
  50. package/dist/chunk-3A5TKOEJ.js.map +1 -0
  51. package/dist/chunk-4PIEL2VO.js +162 -0
  52. package/dist/chunk-4PIEL2VO.js.map +1 -0
  53. package/dist/chunk-536PH5FT.js +342 -0
  54. package/dist/chunk-536PH5FT.js.map +1 -0
  55. package/dist/chunk-DBFCKELK.cjs +156 -0
  56. package/dist/chunk-DBFCKELK.cjs.map +1 -0
  57. package/dist/chunk-DDM2FZRJ.cjs +1143 -0
  58. package/dist/chunk-DDM2FZRJ.cjs.map +1 -0
  59. package/dist/chunk-DGUM43GV.js +10 -0
  60. package/dist/chunk-DGUM43GV.js.map +1 -0
  61. package/dist/chunk-F32HCHYA.cjs +680 -0
  62. package/dist/chunk-F32HCHYA.cjs.map +1 -0
  63. package/dist/chunk-IIAT36MI.js +353 -0
  64. package/dist/chunk-IIAT36MI.js.map +1 -0
  65. package/dist/chunk-JDAET5LO.js +236 -0
  66. package/dist/chunk-JDAET5LO.js.map +1 -0
  67. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  68. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  69. package/dist/chunk-JKTO7TW3.js +299 -0
  70. package/dist/chunk-JKTO7TW3.js.map +1 -0
  71. package/dist/chunk-K7SQ3SWP.js +497 -0
  72. package/dist/chunk-K7SQ3SWP.js.map +1 -0
  73. package/dist/chunk-L642L24T.js +142 -0
  74. package/dist/chunk-L642L24T.js.map +1 -0
  75. package/dist/chunk-MFVCSNIY.cjs +308 -0
  76. package/dist/chunk-MFVCSNIY.cjs.map +1 -0
  77. package/dist/chunk-MNO33ASC.cjs +240 -0
  78. package/dist/chunk-MNO33ASC.cjs.map +1 -0
  79. package/dist/chunk-N4AOJ3VF.cjs +154 -0
  80. package/dist/chunk-N4AOJ3VF.cjs.map +1 -0
  81. package/dist/chunk-P5CNM325.cjs +508 -0
  82. package/dist/chunk-P5CNM325.cjs.map +1 -0
  83. package/dist/chunk-RYT4H46I.js +646 -0
  84. package/dist/chunk-RYT4H46I.js.map +1 -0
  85. package/dist/chunk-SV5H3XM5.cjs +321 -0
  86. package/dist/chunk-SV5H3XM5.cjs.map +1 -0
  87. package/dist/chunk-TXHKFLWX.cjs +344 -0
  88. package/dist/chunk-TXHKFLWX.cjs.map +1 -0
  89. package/dist/chunk-UJAGXJDG.cjs +170 -0
  90. package/dist/chunk-UJAGXJDG.cjs.map +1 -0
  91. package/dist/chunk-VXRVGFCI.js +1128 -0
  92. package/dist/chunk-VXRVGFCI.js.map +1 -0
  93. package/dist/chunk-YM5AL65Y.cjs +357 -0
  94. package/dist/chunk-YM5AL65Y.cjs.map +1 -0
  95. package/dist/index.cjs +8334 -0
  96. package/dist/index.cjs.map +1 -0
  97. package/dist/index.d.cts +1365 -0
  98. package/dist/index.d.ts +1365 -0
  99. package/dist/index.js +8105 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/indexes/index.cjs +67 -0
  102. package/dist/indexes/index.cjs.map +1 -0
  103. package/dist/indexes/index.d.cts +62 -0
  104. package/dist/indexes/index.d.ts +62 -0
  105. package/dist/indexes/index.js +6 -0
  106. package/dist/indexes/index.js.map +1 -0
  107. package/dist/interchange/index.cjs +612 -0
  108. package/dist/interchange/index.cjs.map +1 -0
  109. package/dist/interchange/index.d.cts +288 -0
  110. package/dist/interchange/index.d.ts +288 -0
  111. package/dist/interchange/index.js +598 -0
  112. package/dist/interchange/index.js.map +1 -0
  113. package/dist/profiler/index.cjs +793 -0
  114. package/dist/profiler/index.cjs.map +1 -0
  115. package/dist/profiler/index.d.cts +283 -0
  116. package/dist/profiler/index.d.ts +283 -0
  117. package/dist/profiler/index.js +785 -0
  118. package/dist/profiler/index.js.map +1 -0
  119. package/dist/store-60Lcfi0w.d.ts +2263 -0
  120. package/dist/store-Bifii8MZ.d.cts +2263 -0
  121. package/dist/test-helpers-BjyRYJZX.d.ts +22 -0
  122. package/dist/test-helpers-NoQXhleQ.d.cts +22 -0
  123. package/dist/types-BRzHlhKC.d.cts +14 -0
  124. package/dist/types-BRzHlhKC.d.ts +14 -0
  125. package/dist/types-BrSfFSpW.d.cts +158 -0
  126. package/dist/types-CX4cLd7M.d.ts +152 -0
  127. package/dist/types-CjZ7g_7v.d.ts +442 -0
  128. package/dist/types-DDOSfrih.d.cts +442 -0
  129. package/dist/types-D_3mEv2y.d.ts +158 -0
  130. package/dist/types-a5rAxC92.d.cts +152 -0
  131. package/package.json +201 -0
@@ -0,0 +1,288 @@
1
+ import { z } from 'zod';
2
+ import { G as GraphDef, S as Store } from '../store-60Lcfi0w.js';
3
+ import '../types-CjZ7g_7v.js';
4
+ import 'drizzle-orm';
5
+ import '../types-BRzHlhKC.js';
6
+ import '../ast-BVyihVbP.js';
7
+
8
+ /**
9
+ * Graph interchange format types.
10
+ *
11
+ * Defines Zod schemas for importing and exporting graph data.
12
+ * The format is designed to be:
13
+ * - JSON-serializable for API transport
14
+ * - Validated via Zod at runtime
15
+ * - Exportable as JSON Schema for LLM/API documentation
16
+ */
17
+
18
+ /**
19
+ * Current interchange format version.
20
+ * Increment for breaking changes to the format.
21
+ */
22
+ declare const FORMAT_VERSION: "1.0";
23
+ /**
24
+ * Interchange format for a node.
25
+ *
26
+ * Properties are stored as a record to allow schema-agnostic transport.
27
+ * Validation against the actual schema happens during import.
28
+ */
29
+ declare const InterchangeNodeSchema: z.ZodObject<{
30
+ kind: z.ZodString;
31
+ id: z.ZodString;
32
+ properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
33
+ validFrom: z.ZodOptional<z.ZodISODateTime>;
34
+ validTo: z.ZodOptional<z.ZodISODateTime>;
35
+ meta: z.ZodOptional<z.ZodObject<{
36
+ version: z.ZodOptional<z.ZodNumber>;
37
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
38
+ updatedAt: z.ZodOptional<z.ZodISODateTime>;
39
+ }, z.core.$strip>>;
40
+ }, z.core.$strip>;
41
+ type InterchangeNode = z.infer<typeof InterchangeNodeSchema>;
42
+ /**
43
+ * Interchange format for an edge.
44
+ *
45
+ * Endpoint references are objects with kind and id, rather than
46
+ * composite strings, for clarity and type safety.
47
+ */
48
+ declare const InterchangeEdgeSchema: z.ZodObject<{
49
+ kind: z.ZodString;
50
+ id: z.ZodString;
51
+ from: z.ZodObject<{
52
+ kind: z.ZodString;
53
+ id: z.ZodString;
54
+ }, z.core.$strip>;
55
+ to: z.ZodObject<{
56
+ kind: z.ZodString;
57
+ id: z.ZodString;
58
+ }, z.core.$strip>;
59
+ properties: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
60
+ validFrom: z.ZodOptional<z.ZodISODateTime>;
61
+ validTo: z.ZodOptional<z.ZodISODateTime>;
62
+ meta: z.ZodOptional<z.ZodObject<{
63
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
64
+ updatedAt: z.ZodOptional<z.ZodISODateTime>;
65
+ }, z.core.$strip>>;
66
+ }, z.core.$strip>;
67
+ type InterchangeEdge = z.infer<typeof InterchangeEdgeSchema>;
68
+ /**
69
+ * Strategy for handling conflicts when a node/edge ID already exists.
70
+ *
71
+ * - `skip`: Keep existing, ignore incoming
72
+ * - `update`: Merge incoming properties into existing
73
+ * - `error`: Throw an error on conflict
74
+ */
75
+ declare const ConflictStrategySchema: z.ZodEnum<{
76
+ error: "error";
77
+ skip: "skip";
78
+ update: "update";
79
+ }>;
80
+ type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;
81
+ /**
82
+ * Strategy for handling properties not defined in the schema.
83
+ *
84
+ * - `error`: Throw a validation error
85
+ * - `strip`: Remove unknown properties silently
86
+ * - `allow`: Pass through to storage (relies on backend behavior)
87
+ */
88
+ declare const UnknownPropertyStrategySchema: z.ZodEnum<{
89
+ error: "error";
90
+ strip: "strip";
91
+ allow: "allow";
92
+ }>;
93
+ type UnknownPropertyStrategy = z.infer<typeof UnknownPropertyStrategySchema>;
94
+ /**
95
+ * Options for importing graph data.
96
+ */
97
+ declare const ImportOptionsSchema: z.ZodObject<{
98
+ onConflict: z.ZodEnum<{
99
+ error: "error";
100
+ skip: "skip";
101
+ update: "update";
102
+ }>;
103
+ onUnknownProperty: z.ZodDefault<z.ZodEnum<{
104
+ error: "error";
105
+ strip: "strip";
106
+ allow: "allow";
107
+ }>>;
108
+ validateReferences: z.ZodDefault<z.ZodBoolean>;
109
+ batchSize: z.ZodDefault<z.ZodNumber>;
110
+ }, z.core.$strip>;
111
+ type ImportOptions = z.infer<typeof ImportOptionsSchema>;
112
+ /**
113
+ * Source metadata for graph data.
114
+ *
115
+ * Uses discriminated union to capture different origin types:
116
+ * - `typegraph-cloud`: Extracted by TypeGraph Cloud
117
+ * - `typegraph-export`: Exported from a TypeGraph store
118
+ * - `external`: From a third-party system
119
+ */
120
+ declare const GraphDataSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
121
+ type: z.ZodLiteral<"typegraph-cloud">;
122
+ extractionId: z.ZodString;
123
+ schemaId: z.ZodString;
124
+ schemaVersion: z.ZodOptional<z.ZodNumber>;
125
+ }, z.core.$strip>, z.ZodObject<{
126
+ type: z.ZodLiteral<"typegraph-export">;
127
+ graphId: z.ZodString;
128
+ schemaVersion: z.ZodNumber;
129
+ }, z.core.$strip>, z.ZodObject<{
130
+ type: z.ZodLiteral<"external">;
131
+ description: z.ZodOptional<z.ZodString>;
132
+ }, z.core.$strip>], "type">;
133
+ type GraphDataSource = z.infer<typeof GraphDataSourceSchema>;
134
+ /**
135
+ * Complete graph data interchange format.
136
+ *
137
+ * The envelope contains metadata about the data source and format version,
138
+ * plus arrays of nodes and edges to import.
139
+ */
140
+ declare const GraphDataSchema: z.ZodObject<{
141
+ formatVersion: z.ZodLiteral<"1.0">;
142
+ exportedAt: z.ZodISODateTime;
143
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
144
+ type: z.ZodLiteral<"typegraph-cloud">;
145
+ extractionId: z.ZodString;
146
+ schemaId: z.ZodString;
147
+ schemaVersion: z.ZodOptional<z.ZodNumber>;
148
+ }, z.core.$strip>, z.ZodObject<{
149
+ type: z.ZodLiteral<"typegraph-export">;
150
+ graphId: z.ZodString;
151
+ schemaVersion: z.ZodNumber;
152
+ }, z.core.$strip>, z.ZodObject<{
153
+ type: z.ZodLiteral<"external">;
154
+ description: z.ZodOptional<z.ZodString>;
155
+ }, z.core.$strip>], "type">;
156
+ nodes: z.ZodArray<z.ZodObject<{
157
+ kind: z.ZodString;
158
+ id: z.ZodString;
159
+ properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
160
+ validFrom: z.ZodOptional<z.ZodISODateTime>;
161
+ validTo: z.ZodOptional<z.ZodISODateTime>;
162
+ meta: z.ZodOptional<z.ZodObject<{
163
+ version: z.ZodOptional<z.ZodNumber>;
164
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
165
+ updatedAt: z.ZodOptional<z.ZodISODateTime>;
166
+ }, z.core.$strip>>;
167
+ }, z.core.$strip>>;
168
+ edges: z.ZodArray<z.ZodObject<{
169
+ kind: z.ZodString;
170
+ id: z.ZodString;
171
+ from: z.ZodObject<{
172
+ kind: z.ZodString;
173
+ id: z.ZodString;
174
+ }, z.core.$strip>;
175
+ to: z.ZodObject<{
176
+ kind: z.ZodString;
177
+ id: z.ZodString;
178
+ }, z.core.$strip>;
179
+ properties: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
180
+ validFrom: z.ZodOptional<z.ZodISODateTime>;
181
+ validTo: z.ZodOptional<z.ZodISODateTime>;
182
+ meta: z.ZodOptional<z.ZodObject<{
183
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
184
+ updatedAt: z.ZodOptional<z.ZodISODateTime>;
185
+ }, z.core.$strip>>;
186
+ }, z.core.$strip>>;
187
+ }, z.core.$strip>;
188
+ type GraphData = z.infer<typeof GraphDataSchema>;
189
+ /**
190
+ * An error that occurred during import.
191
+ */
192
+ declare const ImportErrorSchema: z.ZodObject<{
193
+ entityType: z.ZodEnum<{
194
+ node: "node";
195
+ edge: "edge";
196
+ }>;
197
+ kind: z.ZodString;
198
+ id: z.ZodString;
199
+ error: z.ZodString;
200
+ }, z.core.$strip>;
201
+ type ImportError = z.infer<typeof ImportErrorSchema>;
202
+ /**
203
+ * Result of an import operation.
204
+ *
205
+ * Contains counts of created/updated/skipped entities and any errors.
206
+ */
207
+ declare const ImportResultSchema: z.ZodObject<{
208
+ success: z.ZodBoolean;
209
+ nodes: z.ZodObject<{
210
+ created: z.ZodNumber;
211
+ updated: z.ZodNumber;
212
+ skipped: z.ZodNumber;
213
+ }, z.core.$strip>;
214
+ edges: z.ZodObject<{
215
+ created: z.ZodNumber;
216
+ updated: z.ZodNumber;
217
+ skipped: z.ZodNumber;
218
+ }, z.core.$strip>;
219
+ errors: z.ZodArray<z.ZodObject<{
220
+ entityType: z.ZodEnum<{
221
+ node: "node";
222
+ edge: "edge";
223
+ }>;
224
+ kind: z.ZodString;
225
+ id: z.ZodString;
226
+ error: z.ZodString;
227
+ }, z.core.$strip>>;
228
+ }, z.core.$strip>;
229
+ type ImportResult = z.infer<typeof ImportResultSchema>;
230
+ /**
231
+ * Options for exporting graph data.
232
+ */
233
+ declare const ExportOptionsSchema: z.ZodObject<{
234
+ nodeKinds: z.ZodOptional<z.ZodArray<z.ZodString>>;
235
+ edgeKinds: z.ZodOptional<z.ZodArray<z.ZodString>>;
236
+ includeTemporal: z.ZodDefault<z.ZodBoolean>;
237
+ includeMeta: z.ZodDefault<z.ZodBoolean>;
238
+ includeDeleted: z.ZodDefault<z.ZodBoolean>;
239
+ }, z.core.$strip>;
240
+ /** Export options with defaults applied (output type) */
241
+ type ExportOptions = z.infer<typeof ExportOptionsSchema>;
242
+ /** Export options as accepted by exportGraph (input type with optional defaults) */
243
+ type ExportOptionsInput = z.input<typeof ExportOptionsSchema>;
244
+
245
+ /**
246
+ * Export graph data from a store.
247
+ *
248
+ * @param store - The graph store to export from
249
+ * @param options - Export configuration
250
+ * @returns Graph data in interchange format
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const data = await exportGraph(store, {
255
+ * nodeKinds: ["Person", "Organization"],
256
+ * includeMeta: true,
257
+ * });
258
+ *
259
+ * // Write to file
260
+ * await fs.writeFile("backup.json", JSON.stringify(data, null, 2));
261
+ * ```
262
+ */
263
+ declare function exportGraph<G extends GraphDef>(store: Store<G>, options?: ExportOptionsInput): Promise<GraphData>;
264
+
265
+ /**
266
+ * Import graph data into a store.
267
+ *
268
+ * Nodes are imported first to satisfy edge reference validation.
269
+ * The import runs within a transaction for atomicity when supported.
270
+ *
271
+ * @param store - The graph store to import into
272
+ * @param data - Graph data in interchange format
273
+ * @param options - Import configuration
274
+ * @returns Import statistics and any errors
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * const result = await importGraph(store, data, {
279
+ * onConflict: "update",
280
+ * onUnknownProperty: "strip",
281
+ * });
282
+ *
283
+ * console.log(`Created ${result.nodes.created} nodes`);
284
+ * ```
285
+ */
286
+ declare function importGraph<G extends GraphDef>(store: Store<G>, data: GraphData, options: ImportOptions): Promise<ImportResult>;
287
+
288
+ export { type ConflictStrategy, ConflictStrategySchema, type ExportOptions, type ExportOptionsInput, ExportOptionsSchema, FORMAT_VERSION, type GraphData, GraphDataSchema, type GraphDataSource, GraphDataSourceSchema, type ImportError, ImportErrorSchema, type ImportOptions, ImportOptionsSchema, type ImportResult, ImportResultSchema, type InterchangeEdge, InterchangeEdgeSchema, type InterchangeNode, InterchangeNodeSchema, type UnknownPropertyStrategy, UnknownPropertyStrategySchema, exportGraph, importGraph };