@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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/ast-BVyihVbP.d.cts +564 -0
- package/dist/ast-BVyihVbP.d.ts +564 -0
- package/dist/backend/drizzle/index.cjs +41 -0
- package/dist/backend/drizzle/index.cjs.map +1 -0
- package/dist/backend/drizzle/index.d.cts +12 -0
- package/dist/backend/drizzle/index.d.ts +12 -0
- package/dist/backend/drizzle/index.js +12 -0
- package/dist/backend/drizzle/index.js.map +1 -0
- package/dist/backend/drizzle/postgres.cjs +27 -0
- package/dist/backend/drizzle/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/postgres.d.cts +37 -0
- package/dist/backend/drizzle/postgres.d.ts +37 -0
- package/dist/backend/drizzle/postgres.js +10 -0
- package/dist/backend/drizzle/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/postgres.cjs +40 -0
- package/dist/backend/drizzle/schema/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/schema/postgres.d.cts +2419 -0
- package/dist/backend/drizzle/schema/postgres.d.ts +2419 -0
- package/dist/backend/drizzle/schema/postgres.js +7 -0
- package/dist/backend/drizzle/schema/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.cjs +40 -0
- package/dist/backend/drizzle/schema/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.d.cts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.d.ts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.js +7 -0
- package/dist/backend/drizzle/schema/sqlite.js.map +1 -0
- package/dist/backend/drizzle/sqlite.cjs +27 -0
- package/dist/backend/drizzle/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/sqlite.d.cts +36 -0
- package/dist/backend/drizzle/sqlite.d.ts +36 -0
- package/dist/backend/drizzle/sqlite.js +10 -0
- package/dist/backend/drizzle/sqlite.js.map +1 -0
- package/dist/backend/postgres/index.cjs +53 -0
- package/dist/backend/postgres/index.cjs.map +1 -0
- package/dist/backend/postgres/index.d.cts +12 -0
- package/dist/backend/postgres/index.d.ts +12 -0
- package/dist/backend/postgres/index.js +12 -0
- package/dist/backend/postgres/index.js.map +1 -0
- package/dist/backend/sqlite/index.cjs +117 -0
- package/dist/backend/sqlite/index.cjs.map +1 -0
- package/dist/backend/sqlite/index.d.cts +71 -0
- package/dist/backend/sqlite/index.d.ts +71 -0
- package/dist/backend/sqlite/index.js +78 -0
- package/dist/backend/sqlite/index.js.map +1 -0
- package/dist/chunk-2QHQ2C4P.js +146 -0
- package/dist/chunk-2QHQ2C4P.js.map +1 -0
- package/dist/chunk-3A5TKOEJ.js +306 -0
- package/dist/chunk-3A5TKOEJ.js.map +1 -0
- package/dist/chunk-4PIEL2VO.js +162 -0
- package/dist/chunk-4PIEL2VO.js.map +1 -0
- package/dist/chunk-536PH5FT.js +342 -0
- package/dist/chunk-536PH5FT.js.map +1 -0
- package/dist/chunk-DBFCKELK.cjs +156 -0
- package/dist/chunk-DBFCKELK.cjs.map +1 -0
- package/dist/chunk-DDM2FZRJ.cjs +1143 -0
- package/dist/chunk-DDM2FZRJ.cjs.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-F32HCHYA.cjs +680 -0
- package/dist/chunk-F32HCHYA.cjs.map +1 -0
- package/dist/chunk-IIAT36MI.js +353 -0
- package/dist/chunk-IIAT36MI.js.map +1 -0
- package/dist/chunk-JDAET5LO.js +236 -0
- package/dist/chunk-JDAET5LO.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-JKTO7TW3.js +299 -0
- package/dist/chunk-JKTO7TW3.js.map +1 -0
- package/dist/chunk-K7SQ3SWP.js +497 -0
- package/dist/chunk-K7SQ3SWP.js.map +1 -0
- package/dist/chunk-L642L24T.js +142 -0
- package/dist/chunk-L642L24T.js.map +1 -0
- package/dist/chunk-MFVCSNIY.cjs +308 -0
- package/dist/chunk-MFVCSNIY.cjs.map +1 -0
- package/dist/chunk-MNO33ASC.cjs +240 -0
- package/dist/chunk-MNO33ASC.cjs.map +1 -0
- package/dist/chunk-N4AOJ3VF.cjs +154 -0
- package/dist/chunk-N4AOJ3VF.cjs.map +1 -0
- package/dist/chunk-P5CNM325.cjs +508 -0
- package/dist/chunk-P5CNM325.cjs.map +1 -0
- package/dist/chunk-RYT4H46I.js +646 -0
- package/dist/chunk-RYT4H46I.js.map +1 -0
- package/dist/chunk-SV5H3XM5.cjs +321 -0
- package/dist/chunk-SV5H3XM5.cjs.map +1 -0
- package/dist/chunk-TXHKFLWX.cjs +344 -0
- package/dist/chunk-TXHKFLWX.cjs.map +1 -0
- package/dist/chunk-UJAGXJDG.cjs +170 -0
- package/dist/chunk-UJAGXJDG.cjs.map +1 -0
- package/dist/chunk-VXRVGFCI.js +1128 -0
- package/dist/chunk-VXRVGFCI.js.map +1 -0
- package/dist/chunk-YM5AL65Y.cjs +357 -0
- package/dist/chunk-YM5AL65Y.cjs.map +1 -0
- package/dist/index.cjs +8334 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1365 -0
- package/dist/index.d.ts +1365 -0
- package/dist/index.js +8105 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/index.cjs +67 -0
- package/dist/indexes/index.cjs.map +1 -0
- package/dist/indexes/index.d.cts +62 -0
- package/dist/indexes/index.d.ts +62 -0
- package/dist/indexes/index.js +6 -0
- package/dist/indexes/index.js.map +1 -0
- package/dist/interchange/index.cjs +612 -0
- package/dist/interchange/index.cjs.map +1 -0
- package/dist/interchange/index.d.cts +288 -0
- package/dist/interchange/index.d.ts +288 -0
- package/dist/interchange/index.js +598 -0
- package/dist/interchange/index.js.map +1 -0
- package/dist/profiler/index.cjs +793 -0
- package/dist/profiler/index.cjs.map +1 -0
- package/dist/profiler/index.d.cts +283 -0
- package/dist/profiler/index.d.ts +283 -0
- package/dist/profiler/index.js +785 -0
- package/dist/profiler/index.js.map +1 -0
- package/dist/store-60Lcfi0w.d.ts +2263 -0
- package/dist/store-Bifii8MZ.d.cts +2263 -0
- package/dist/test-helpers-BjyRYJZX.d.ts +22 -0
- package/dist/test-helpers-NoQXhleQ.d.cts +22 -0
- package/dist/types-BRzHlhKC.d.cts +14 -0
- package/dist/types-BRzHlhKC.d.ts +14 -0
- package/dist/types-BrSfFSpW.d.cts +158 -0
- package/dist/types-CX4cLd7M.d.ts +152 -0
- package/dist/types-CjZ7g_7v.d.ts +442 -0
- package/dist/types-DDOSfrih.d.cts +442 -0
- package/dist/types-D_3mEv2y.d.ts +158 -0
- package/dist/types-a5rAxC92.d.cts +152 -0
- package/package.json +201 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1365 @@
|
|
|
1
|
+
import { z, ZodType, ZodError } from 'zod';
|
|
2
|
+
import { N as NodeType, E as EdgeType, c as AggregateExpr, F as FieldRef, C as ComparisonOp, d as AggregateComparisonPredicate } from './ast-BVyihVbP.cjs';
|
|
3
|
+
export { A as AnyEdgeType, e as Cardinality, f as Collation, D as DeleteBehavior, g as EdgeProps, h as EdgeRegistration, i as EdgeTypeWithEndpoints, j as EndpointExistence, G as GraphDefaults, J as JsonPointer, a as JsonPointerFor, k as JsonPointerInput, l as JsonPointerSegment, m as JsonPointerSegments, b as JsonPointerSegmentsFor, M as MAX_JSON_POINTER_DEPTH, n as NodeId, o as NodeProps, p as NodeRegistration, O as OrderSpec, R as ResolveJsonPointer, q as ResolveJsonPointerSegments, S as SortDirection, T as TemporalMode, U as UniqueConstraint, r as UniquenessScope, s as isEdgeType, t as isEdgeTypeWithEndpoints, u as isNodeType, v as joinJsonPointers, w as jsonPointer, x as normalizeJsonPointer, y as parseJsonPointer } from './ast-BVyihVbP.cjs';
|
|
4
|
+
import { I as InferenceType, M as MetaEdge, O as OntologyRelation, G as GraphDef, K as KindRegistry, A as AliasMap, E as EdgeAliasMap, Q as QueryBuilder, T as TraversalBuilder, C as CreateQueryBuilderOptions, a as SerializedNodeDef, b as SerializedEdgeDef, c as SerializedMetaEdge, d as SerializedOntologyRelation, e as SerializedClosures, f as SerializedSchema, g as SchemaHash } from './store-Bifii8MZ.cjs';
|
|
5
|
+
export { h as AllEdgeTypes, i as AllNodeTypes, j as ChangeSeverity, k as ChangeType, l as CreateEdgeInput, m as CreateNodeInput, n as Edge, o as EdgeAccessor, p as EdgeChange, q as EdgeCollection, r as EdgeTypeNames, s as EmbeddingSchema, t as EmbeddingValue, u as ExecutableAggregateQuery, v as ExecutableQuery, F as FieldAccessor, w as GetEdgeType, x as GetNodeType, H as HookContext, J as JsonSchema, y as MetaEdgeProperties, N as Node, z as NodeAccessor, B as NodeAlias, D as NodeChange, L as NodeCollection, P as NodeRef, R as NodeTypeNames, U as OntologyChange, V as OperationHookContext, W as PaginateOptions, X as PaginatedResult, Y as Predicate, Z as PropsAccessor, _ as QueryHookContext, $ as QueryOptions, a0 as SchemaDiff, a1 as SchemaManagerOptions, a2 as SchemaValidationResult, a3 as SelectContext, a4 as SelectableEdge, a5 as SelectableNode, a6 as SerializedOntology, a7 as SerializedUniqueConstraint, S as Store, a8 as StoreConfig, a9 as StoreHooks, aa as StoreOptions, ab as StreamOptions, ac as TransactionContext, ad as TypedEdgeCollection, ae as TypedNodeRef, af as UpdateEdgeInput, ag as UpdateNodeInput, ah as computeSchemaDiff, ai as createStore, aj as createStoreWithSchema, ak as defineGraph, al as embedding, am as ensureSchema, an as exists, ao as fieldRef, ap as getActiveSchema, aq as getEdgeTypeNames, ar as getEmbeddingDimensions, as as getMigrationActions, at as getNodeTypeNames, au as getSchemaChanges, av as inSubquery, aw as initializeSchema, ax as isBackwardsCompatible, ay as isEmbeddingSchema, az as isGraphDef, aA as isMetaEdge, aB as isSchemaInitialized, aC as migrateSchema, aD as notExists, aE as notInSubquery } from './store-Bifii8MZ.cjs';
|
|
6
|
+
export { G as GraphBackend, T as TransactionBackend } from './types-DDOSfrih.cjs';
|
|
7
|
+
export { S as SqlDialect } from './types-BRzHlhKC.cjs';
|
|
8
|
+
import 'drizzle-orm';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options for defining a node type.
|
|
12
|
+
*/
|
|
13
|
+
type DefineNodeOptions<S extends z.ZodObject<z.ZodRawShape>> = Readonly<{
|
|
14
|
+
/** Zod schema for node properties */
|
|
15
|
+
schema: S;
|
|
16
|
+
/** Optional description for documentation */
|
|
17
|
+
description?: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a node type definition.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const Person = defineNode("Person", {
|
|
25
|
+
* schema: z.object({
|
|
26
|
+
* fullName: z.string().min(1),
|
|
27
|
+
* email: z.string().email().optional(),
|
|
28
|
+
* }),
|
|
29
|
+
* description: "A person in the system",
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function defineNode<K extends string, S extends z.ZodObject<z.ZodRawShape>>(name: K, options: DefineNodeOptions<S>): NodeType<K, S>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Options for defining an edge type.
|
|
37
|
+
*/
|
|
38
|
+
type DefineEdgeOptions<S extends z.ZodObject<z.ZodRawShape>, From extends readonly NodeType[] | undefined = undefined, To extends readonly NodeType[] | undefined = undefined> = Readonly<{
|
|
39
|
+
/** Zod schema for edge properties (defaults to empty object) */
|
|
40
|
+
schema?: S;
|
|
41
|
+
/** Optional description for documentation */
|
|
42
|
+
description?: string;
|
|
43
|
+
/** Node types that can be the source of this edge (domain constraint) */
|
|
44
|
+
from?: From;
|
|
45
|
+
/** Node types that can be the target of this edge (range constraint) */
|
|
46
|
+
to?: To;
|
|
47
|
+
}>;
|
|
48
|
+
declare const EMPTY_SCHEMA: z.ZodObject<{}, z.core.$strip>;
|
|
49
|
+
type EmptySchema = typeof EMPTY_SCHEMA;
|
|
50
|
+
/**
|
|
51
|
+
* Creates an edge type definition.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Edge with no properties
|
|
56
|
+
* const hasEpisode = defineEdge("hasEpisode");
|
|
57
|
+
*
|
|
58
|
+
* // Edge with properties
|
|
59
|
+
* const employedAt = defineEdge("employedAt", {
|
|
60
|
+
* schema: z.object({
|
|
61
|
+
* isPrimary: z.boolean().default(true),
|
|
62
|
+
* startedAt: z.date(),
|
|
63
|
+
* }),
|
|
64
|
+
* description: "Employment relationship",
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Edge with domain/range constraints (can be used directly in defineGraph)
|
|
68
|
+
* const worksAt = defineEdge("worksAt", {
|
|
69
|
+
* schema: z.object({ role: z.string() }),
|
|
70
|
+
* from: [Person],
|
|
71
|
+
* to: [Company],
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function defineEdge<K extends string>(name: K): EdgeType<K, EmptySchema>;
|
|
76
|
+
declare function defineEdge<K extends string, S extends z.ZodObject<z.ZodRawShape>, From extends readonly NodeType[], To extends readonly NodeType[]>(name: K, options: DefineEdgeOptions<S, From, To> & {
|
|
77
|
+
from: From;
|
|
78
|
+
to: To;
|
|
79
|
+
}): EdgeType<K, S, From, To>;
|
|
80
|
+
declare function defineEdge<K extends string, S extends z.ZodObject<z.ZodRawShape>>(name: K, options: DefineEdgeOptions<S>): EdgeType<K, S>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Options for creating a meta-edge.
|
|
84
|
+
*/
|
|
85
|
+
type MetaEdgeOptions = Readonly<{
|
|
86
|
+
/** Whether the relationship is transitive (A→B, B→C implies A→C) */
|
|
87
|
+
transitive?: boolean;
|
|
88
|
+
/** Whether the relationship is symmetric (A→B implies B→A) */
|
|
89
|
+
symmetric?: boolean;
|
|
90
|
+
/** Whether the relationship is reflexive (A→A is always true) */
|
|
91
|
+
reflexive?: boolean;
|
|
92
|
+
/** Name of the inverse meta-edge */
|
|
93
|
+
inverse?: string;
|
|
94
|
+
/** How this meta-edge affects queries and validation */
|
|
95
|
+
inference?: InferenceType;
|
|
96
|
+
/** Optional description */
|
|
97
|
+
description?: string;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a custom meta-edge definition.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Custom meta-edge for regulatory relationships
|
|
105
|
+
* const regulatedBy = metaEdge("regulatedBy", {
|
|
106
|
+
* description: "Type X is regulated by authority type Y",
|
|
107
|
+
* transitive: false,
|
|
108
|
+
* symmetric: false,
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function metaEdge<K extends string>(name: K, options?: MetaEdgeOptions): MetaEdge<K>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* External reference type for hybrid overlay patterns.
|
|
116
|
+
*
|
|
117
|
+
* Creates a Zod-compatible schema for referencing entities in external
|
|
118
|
+
* data sources (e.g., existing application tables) from TypeGraph nodes.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Symbol key for storing external table name on the schema.
|
|
123
|
+
* This allows the schema introspector to detect external reference types
|
|
124
|
+
* and extract source information.
|
|
125
|
+
*/
|
|
126
|
+
declare const EXTERNAL_REF_TABLE_KEY: "_externalRefTable";
|
|
127
|
+
/**
|
|
128
|
+
* The shape of an external reference value.
|
|
129
|
+
* Contains the source table identifier and the ID of the referenced record.
|
|
130
|
+
*/
|
|
131
|
+
type ExternalRefValue<T extends string = string> = Readonly<{
|
|
132
|
+
table: T;
|
|
133
|
+
id: string;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* A Zod schema for external references with attached table metadata.
|
|
137
|
+
*/
|
|
138
|
+
type ExternalRefSchema<T extends string = string> = z.ZodType<ExternalRefValue<T>> & Readonly<{
|
|
139
|
+
[EXTERNAL_REF_TABLE_KEY]: T;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a Zod schema for referencing external data sources.
|
|
143
|
+
*
|
|
144
|
+
* Use this when building a hybrid overlay where TypeGraph stores
|
|
145
|
+
* graph relationships and metadata while your existing tables
|
|
146
|
+
* remain the source of truth for entity data.
|
|
147
|
+
*
|
|
148
|
+
* @param table - The identifier for the external table/source (e.g., "users", "documents")
|
|
149
|
+
* @returns A Zod schema that validates external reference objects
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* import { defineNode, externalRef, embedding } from "@nicia-ai/typegraph";
|
|
154
|
+
*
|
|
155
|
+
* // Reference documents from your existing application database
|
|
156
|
+
* const Document = defineNode("Document", {
|
|
157
|
+
* schema: z.object({
|
|
158
|
+
* source: externalRef("documents"),
|
|
159
|
+
* embedding: embedding(1536).optional(),
|
|
160
|
+
* extractedTopics: z.array(z.string()).optional(),
|
|
161
|
+
* }),
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* // Create a node referencing an external document
|
|
165
|
+
* await store.nodes.Document.create({
|
|
166
|
+
* source: { table: "documents", id: "doc_abc123" },
|
|
167
|
+
* embedding: await generateEmbedding(docContent),
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Query and hydrate with external data
|
|
171
|
+
* const results = await store
|
|
172
|
+
* .query()
|
|
173
|
+
* .from("Document", "d")
|
|
174
|
+
* .whereNode("d", (d) => d.embedding.similarTo(query, 10))
|
|
175
|
+
* .select((ctx) => ctx.d.source)
|
|
176
|
+
* .execute();
|
|
177
|
+
*
|
|
178
|
+
* // Fetch full data from your app database
|
|
179
|
+
* const externalIds = results.map((r) => r.id);
|
|
180
|
+
* const fullDocs = await appDb.query.documents.findMany({
|
|
181
|
+
* where: inArray(documents.id, externalIds),
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function externalRef<T extends string>(table: T): ExternalRefSchema<T>;
|
|
186
|
+
/**
|
|
187
|
+
* Checks if a value is an external reference schema.
|
|
188
|
+
*/
|
|
189
|
+
declare function isExternalRefSchema(value: unknown): value is ExternalRefSchema;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the table name from an external reference schema.
|
|
192
|
+
* Returns undefined if the schema is not an external reference schema.
|
|
193
|
+
*/
|
|
194
|
+
declare function getExternalRefTable(schema: z.ZodType): string | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Helper function to create a typed external reference value.
|
|
197
|
+
* Useful when you want to avoid repeating the table name.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const docRef = createExternalRef("documents");
|
|
202
|
+
*
|
|
203
|
+
* await store.nodes.Document.create({
|
|
204
|
+
* source: docRef("doc_123"),
|
|
205
|
+
* embedding: [...],
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare function createExternalRef<T extends string>(table: T): (id: string) => ExternalRefValue<T>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates a subClassOf ontology relation.
|
|
213
|
+
*/
|
|
214
|
+
declare function subClassOf(child: NodeType, parent: NodeType): OntologyRelation;
|
|
215
|
+
/**
|
|
216
|
+
* Creates a broader ontology relation.
|
|
217
|
+
*/
|
|
218
|
+
declare function broader(narrowerConcept: NodeType, broaderConcept: NodeType): OntologyRelation;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a narrower ontology relation.
|
|
221
|
+
*/
|
|
222
|
+
declare function narrower(broaderConcept: NodeType, narrowerConcept: NodeType): OntologyRelation;
|
|
223
|
+
/**
|
|
224
|
+
* Creates a relatedTo ontology relation.
|
|
225
|
+
*/
|
|
226
|
+
declare function relatedTo(conceptA: NodeType, conceptB: NodeType): OntologyRelation;
|
|
227
|
+
/**
|
|
228
|
+
* Creates an equivalentTo ontology relation.
|
|
229
|
+
* Can be used with external IRIs for cross-system mapping.
|
|
230
|
+
*/
|
|
231
|
+
declare function equivalentTo(kindA: NodeType, kindBOrIri: NodeType | string): OntologyRelation;
|
|
232
|
+
/**
|
|
233
|
+
* Creates a sameAs ontology relation.
|
|
234
|
+
*/
|
|
235
|
+
declare function sameAs(kindA: NodeType, kindBOrIri: NodeType | string): OntologyRelation;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a differentFrom ontology relation.
|
|
238
|
+
*/
|
|
239
|
+
declare function differentFrom(kindA: NodeType, kindB: NodeType): OntologyRelation;
|
|
240
|
+
/**
|
|
241
|
+
* Creates a disjointWith ontology relation.
|
|
242
|
+
*/
|
|
243
|
+
declare function disjointWith(kindA: NodeType, kindB: NodeType): OntologyRelation;
|
|
244
|
+
/**
|
|
245
|
+
* Creates a partOf ontology relation.
|
|
246
|
+
*/
|
|
247
|
+
declare function partOf(part: NodeType, whole: NodeType): OntologyRelation;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a hasPart ontology relation.
|
|
250
|
+
*/
|
|
251
|
+
declare function hasPart(whole: NodeType, part: NodeType): OntologyRelation;
|
|
252
|
+
/**
|
|
253
|
+
* Creates an inverseOf ontology relation.
|
|
254
|
+
* Edge A inverseOf edge B means traversing A is equivalent to traversing B backwards.
|
|
255
|
+
*/
|
|
256
|
+
declare function inverseOf(edgeA: EdgeType, edgeB: EdgeType): OntologyRelation;
|
|
257
|
+
/**
|
|
258
|
+
* Creates an implies ontology relation.
|
|
259
|
+
* Edge A implies edge B means if A exists between two nodes, B should also exist.
|
|
260
|
+
*/
|
|
261
|
+
declare function implies(edgeA: EdgeType, edgeB: EdgeType): OntologyRelation;
|
|
262
|
+
/**
|
|
263
|
+
* The core ontology module containing all built-in meta-edges
|
|
264
|
+
* and their relation factory functions.
|
|
265
|
+
*/
|
|
266
|
+
declare const core: {
|
|
267
|
+
readonly subClassOfMetaEdge: Readonly<{
|
|
268
|
+
name: "subClassOf";
|
|
269
|
+
properties: Readonly<{
|
|
270
|
+
transitive: boolean;
|
|
271
|
+
symmetric: boolean;
|
|
272
|
+
reflexive: boolean;
|
|
273
|
+
inverse: string | undefined;
|
|
274
|
+
inference: InferenceType;
|
|
275
|
+
description: string | undefined;
|
|
276
|
+
}>;
|
|
277
|
+
__metaEdge: true;
|
|
278
|
+
}>;
|
|
279
|
+
readonly broaderMetaEdge: Readonly<{
|
|
280
|
+
name: "broader";
|
|
281
|
+
properties: Readonly<{
|
|
282
|
+
transitive: boolean;
|
|
283
|
+
symmetric: boolean;
|
|
284
|
+
reflexive: boolean;
|
|
285
|
+
inverse: string | undefined;
|
|
286
|
+
inference: InferenceType;
|
|
287
|
+
description: string | undefined;
|
|
288
|
+
}>;
|
|
289
|
+
__metaEdge: true;
|
|
290
|
+
}>;
|
|
291
|
+
readonly narrowerMetaEdge: Readonly<{
|
|
292
|
+
name: "narrower";
|
|
293
|
+
properties: Readonly<{
|
|
294
|
+
transitive: boolean;
|
|
295
|
+
symmetric: boolean;
|
|
296
|
+
reflexive: boolean;
|
|
297
|
+
inverse: string | undefined;
|
|
298
|
+
inference: InferenceType;
|
|
299
|
+
description: string | undefined;
|
|
300
|
+
}>;
|
|
301
|
+
__metaEdge: true;
|
|
302
|
+
}>;
|
|
303
|
+
readonly relatedToMetaEdge: Readonly<{
|
|
304
|
+
name: "relatedTo";
|
|
305
|
+
properties: Readonly<{
|
|
306
|
+
transitive: boolean;
|
|
307
|
+
symmetric: boolean;
|
|
308
|
+
reflexive: boolean;
|
|
309
|
+
inverse: string | undefined;
|
|
310
|
+
inference: InferenceType;
|
|
311
|
+
description: string | undefined;
|
|
312
|
+
}>;
|
|
313
|
+
__metaEdge: true;
|
|
314
|
+
}>;
|
|
315
|
+
readonly equivalentToMetaEdge: Readonly<{
|
|
316
|
+
name: "equivalentTo";
|
|
317
|
+
properties: Readonly<{
|
|
318
|
+
transitive: boolean;
|
|
319
|
+
symmetric: boolean;
|
|
320
|
+
reflexive: boolean;
|
|
321
|
+
inverse: string | undefined;
|
|
322
|
+
inference: InferenceType;
|
|
323
|
+
description: string | undefined;
|
|
324
|
+
}>;
|
|
325
|
+
__metaEdge: true;
|
|
326
|
+
}>;
|
|
327
|
+
readonly sameAsMetaEdge: Readonly<{
|
|
328
|
+
name: "sameAs";
|
|
329
|
+
properties: Readonly<{
|
|
330
|
+
transitive: boolean;
|
|
331
|
+
symmetric: boolean;
|
|
332
|
+
reflexive: boolean;
|
|
333
|
+
inverse: string | undefined;
|
|
334
|
+
inference: InferenceType;
|
|
335
|
+
description: string | undefined;
|
|
336
|
+
}>;
|
|
337
|
+
__metaEdge: true;
|
|
338
|
+
}>;
|
|
339
|
+
readonly differentFromMetaEdge: Readonly<{
|
|
340
|
+
name: "differentFrom";
|
|
341
|
+
properties: Readonly<{
|
|
342
|
+
transitive: boolean;
|
|
343
|
+
symmetric: boolean;
|
|
344
|
+
reflexive: boolean;
|
|
345
|
+
inverse: string | undefined;
|
|
346
|
+
inference: InferenceType;
|
|
347
|
+
description: string | undefined;
|
|
348
|
+
}>;
|
|
349
|
+
__metaEdge: true;
|
|
350
|
+
}>;
|
|
351
|
+
readonly disjointWithMetaEdge: Readonly<{
|
|
352
|
+
name: "disjointWith";
|
|
353
|
+
properties: Readonly<{
|
|
354
|
+
transitive: boolean;
|
|
355
|
+
symmetric: boolean;
|
|
356
|
+
reflexive: boolean;
|
|
357
|
+
inverse: string | undefined;
|
|
358
|
+
inference: InferenceType;
|
|
359
|
+
description: string | undefined;
|
|
360
|
+
}>;
|
|
361
|
+
__metaEdge: true;
|
|
362
|
+
}>;
|
|
363
|
+
readonly partOfMetaEdge: Readonly<{
|
|
364
|
+
name: "partOf";
|
|
365
|
+
properties: Readonly<{
|
|
366
|
+
transitive: boolean;
|
|
367
|
+
symmetric: boolean;
|
|
368
|
+
reflexive: boolean;
|
|
369
|
+
inverse: string | undefined;
|
|
370
|
+
inference: InferenceType;
|
|
371
|
+
description: string | undefined;
|
|
372
|
+
}>;
|
|
373
|
+
__metaEdge: true;
|
|
374
|
+
}>;
|
|
375
|
+
readonly hasPartMetaEdge: Readonly<{
|
|
376
|
+
name: "hasPart";
|
|
377
|
+
properties: Readonly<{
|
|
378
|
+
transitive: boolean;
|
|
379
|
+
symmetric: boolean;
|
|
380
|
+
reflexive: boolean;
|
|
381
|
+
inverse: string | undefined;
|
|
382
|
+
inference: InferenceType;
|
|
383
|
+
description: string | undefined;
|
|
384
|
+
}>;
|
|
385
|
+
__metaEdge: true;
|
|
386
|
+
}>;
|
|
387
|
+
readonly inverseOfMetaEdge: Readonly<{
|
|
388
|
+
name: "inverseOf";
|
|
389
|
+
properties: Readonly<{
|
|
390
|
+
transitive: boolean;
|
|
391
|
+
symmetric: boolean;
|
|
392
|
+
reflexive: boolean;
|
|
393
|
+
inverse: string | undefined;
|
|
394
|
+
inference: InferenceType;
|
|
395
|
+
description: string | undefined;
|
|
396
|
+
}>;
|
|
397
|
+
__metaEdge: true;
|
|
398
|
+
}>;
|
|
399
|
+
readonly impliesMetaEdge: Readonly<{
|
|
400
|
+
name: "implies";
|
|
401
|
+
properties: Readonly<{
|
|
402
|
+
transitive: boolean;
|
|
403
|
+
symmetric: boolean;
|
|
404
|
+
reflexive: boolean;
|
|
405
|
+
inverse: string | undefined;
|
|
406
|
+
inference: InferenceType;
|
|
407
|
+
description: string | undefined;
|
|
408
|
+
}>;
|
|
409
|
+
__metaEdge: true;
|
|
410
|
+
}>;
|
|
411
|
+
readonly subClassOf: typeof subClassOf;
|
|
412
|
+
readonly broader: typeof broader;
|
|
413
|
+
readonly narrower: typeof narrower;
|
|
414
|
+
readonly relatedTo: typeof relatedTo;
|
|
415
|
+
readonly equivalentTo: typeof equivalentTo;
|
|
416
|
+
readonly sameAs: typeof sameAs;
|
|
417
|
+
readonly differentFrom: typeof differentFrom;
|
|
418
|
+
readonly disjointWith: typeof disjointWith;
|
|
419
|
+
readonly partOf: typeof partOf;
|
|
420
|
+
readonly hasPart: typeof hasPart;
|
|
421
|
+
readonly inverseOf: typeof inverseOf;
|
|
422
|
+
readonly implies: typeof implies;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* TypeGraph Error Hierarchy
|
|
427
|
+
*
|
|
428
|
+
* All errors extend TypeGraphError with:
|
|
429
|
+
* - `code`: Machine-readable error code for programmatic handling
|
|
430
|
+
* - `category`: Classification for error handling strategies
|
|
431
|
+
* - `suggestion`: Optional recovery guidance for users
|
|
432
|
+
* - `details`: Structured context about the error
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* try {
|
|
437
|
+
* await store.nodes.Person.create({ name: "" });
|
|
438
|
+
* } catch (error) {
|
|
439
|
+
* if (isTypeGraphError(error)) {
|
|
440
|
+
* console.error(error.toUserMessage());
|
|
441
|
+
* if (isUserRecoverable(error)) {
|
|
442
|
+
* // Show to user for correction
|
|
443
|
+
* }
|
|
444
|
+
* }
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
/**
|
|
449
|
+
* Error category for programmatic handling.
|
|
450
|
+
*
|
|
451
|
+
* - `user`: Caused by invalid input or incorrect usage. Recoverable by fixing input.
|
|
452
|
+
* - `constraint`: Business rule or schema constraint violation. Recoverable by changing data.
|
|
453
|
+
* - `system`: Internal error or infrastructure issue. May require investigation or retry.
|
|
454
|
+
*/
|
|
455
|
+
type ErrorCategory = "user" | "constraint" | "system";
|
|
456
|
+
/**
|
|
457
|
+
* Options for TypeGraphError constructor.
|
|
458
|
+
*/
|
|
459
|
+
type TypeGraphErrorOptions = Readonly<{
|
|
460
|
+
/** Structured context about the error */
|
|
461
|
+
details?: Record<string, unknown>;
|
|
462
|
+
/** Error category for handling strategies */
|
|
463
|
+
category: ErrorCategory;
|
|
464
|
+
/** Recovery guidance for users */
|
|
465
|
+
suggestion?: string;
|
|
466
|
+
/** Underlying cause of the error */
|
|
467
|
+
cause?: unknown;
|
|
468
|
+
}>;
|
|
469
|
+
/**
|
|
470
|
+
* Base error class for all TypeGraph errors.
|
|
471
|
+
*
|
|
472
|
+
* Provides structured error information for both programmatic handling
|
|
473
|
+
* and user-friendly messages.
|
|
474
|
+
*/
|
|
475
|
+
declare class TypeGraphError extends Error {
|
|
476
|
+
/** Machine-readable error code (e.g., "VALIDATION_ERROR") */
|
|
477
|
+
readonly code: string;
|
|
478
|
+
/** Error category for handling strategies */
|
|
479
|
+
readonly category: ErrorCategory;
|
|
480
|
+
/** Structured context about the error */
|
|
481
|
+
readonly details: Readonly<Record<string, unknown>>;
|
|
482
|
+
/** Recovery guidance for users */
|
|
483
|
+
readonly suggestion?: string;
|
|
484
|
+
constructor(message: string, code: string, options: TypeGraphErrorOptions);
|
|
485
|
+
/**
|
|
486
|
+
* Returns a user-friendly error message with suggestion if available.
|
|
487
|
+
*/
|
|
488
|
+
toUserMessage(): string;
|
|
489
|
+
/**
|
|
490
|
+
* Returns a detailed string representation for logging.
|
|
491
|
+
*/
|
|
492
|
+
toLogString(): string;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Validation issue from Zod or custom validation.
|
|
496
|
+
*/
|
|
497
|
+
type ValidationIssue = Readonly<{
|
|
498
|
+
/** Path to the invalid field (e.g., "address.city") */
|
|
499
|
+
path: string;
|
|
500
|
+
/** Human-readable error message */
|
|
501
|
+
message: string;
|
|
502
|
+
/** Zod error code if from Zod validation */
|
|
503
|
+
code?: string;
|
|
504
|
+
}>;
|
|
505
|
+
/**
|
|
506
|
+
* Details for ValidationError.
|
|
507
|
+
*/
|
|
508
|
+
type ValidationErrorDetails = Readonly<{
|
|
509
|
+
/** Type of entity being validated */
|
|
510
|
+
entityType?: "node" | "edge";
|
|
511
|
+
/** Kind/type name of the entity */
|
|
512
|
+
kind?: string;
|
|
513
|
+
/** Operation being performed */
|
|
514
|
+
operation?: "create" | "update";
|
|
515
|
+
/** Entity ID if updating */
|
|
516
|
+
id?: string;
|
|
517
|
+
/** Individual validation issues */
|
|
518
|
+
issues: readonly ValidationIssue[];
|
|
519
|
+
}>;
|
|
520
|
+
/**
|
|
521
|
+
* Thrown when schema validation fails during node or edge operations.
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```typescript
|
|
525
|
+
* try {
|
|
526
|
+
* await store.nodes.Person.create({ email: "invalid" });
|
|
527
|
+
* } catch (error) {
|
|
528
|
+
* if (error instanceof ValidationError) {
|
|
529
|
+
* console.log(error.details.issues);
|
|
530
|
+
* // [{ path: "email", message: "Invalid email" }]
|
|
531
|
+
* }
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
declare class ValidationError extends TypeGraphError {
|
|
536
|
+
readonly details: ValidationErrorDetails;
|
|
537
|
+
constructor(message: string, details: ValidationErrorDetails, options?: {
|
|
538
|
+
cause?: unknown;
|
|
539
|
+
suggestion?: string;
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Thrown when a node is not found.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* try {
|
|
548
|
+
* await store.nodes.Person.get("nonexistent-id");
|
|
549
|
+
* } catch (error) {
|
|
550
|
+
* if (error instanceof NodeNotFoundError) {
|
|
551
|
+
* console.log(error.details.kind, error.details.id);
|
|
552
|
+
* }
|
|
553
|
+
* }
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
declare class NodeNotFoundError extends TypeGraphError {
|
|
557
|
+
constructor(kind: string, id: string, options?: {
|
|
558
|
+
cause?: unknown;
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Thrown when an edge is not found.
|
|
563
|
+
*/
|
|
564
|
+
declare class EdgeNotFoundError extends TypeGraphError {
|
|
565
|
+
constructor(kind: string, id: string, options?: {
|
|
566
|
+
cause?: unknown;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Thrown when a kind is not found in the graph registry.
|
|
571
|
+
*/
|
|
572
|
+
declare class KindNotFoundError extends TypeGraphError {
|
|
573
|
+
constructor(kind: string, type: "node" | "edge", options?: {
|
|
574
|
+
cause?: unknown;
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Thrown when edge endpoint node does not exist or is deleted.
|
|
579
|
+
*/
|
|
580
|
+
declare class EndpointNotFoundError extends TypeGraphError {
|
|
581
|
+
constructor(details: Readonly<{
|
|
582
|
+
edgeKind: string;
|
|
583
|
+
endpoint: "from" | "to";
|
|
584
|
+
nodeKind: string;
|
|
585
|
+
nodeId: string;
|
|
586
|
+
}>, options?: {
|
|
587
|
+
cause?: unknown;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Thrown when edge endpoint has wrong node type.
|
|
592
|
+
*/
|
|
593
|
+
declare class EndpointError extends TypeGraphError {
|
|
594
|
+
constructor(details: Readonly<{
|
|
595
|
+
edgeKind: string;
|
|
596
|
+
endpoint: "from" | "to";
|
|
597
|
+
actualKind: string;
|
|
598
|
+
expectedKinds: readonly string[];
|
|
599
|
+
}>, options?: {
|
|
600
|
+
cause?: unknown;
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Thrown when uniqueness constraint is violated.
|
|
605
|
+
*/
|
|
606
|
+
declare class UniquenessError extends TypeGraphError {
|
|
607
|
+
constructor(details: Readonly<{
|
|
608
|
+
constraintName: string;
|
|
609
|
+
kind: string;
|
|
610
|
+
existingId: string;
|
|
611
|
+
newId: string;
|
|
612
|
+
fields: readonly string[];
|
|
613
|
+
}>, options?: {
|
|
614
|
+
cause?: unknown;
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Thrown when cardinality constraint is violated.
|
|
619
|
+
*/
|
|
620
|
+
declare class CardinalityError extends TypeGraphError {
|
|
621
|
+
constructor(details: Readonly<{
|
|
622
|
+
edgeKind: string;
|
|
623
|
+
fromKind: string;
|
|
624
|
+
fromId: string;
|
|
625
|
+
cardinality: string;
|
|
626
|
+
existingCount: number;
|
|
627
|
+
}>, options?: {
|
|
628
|
+
cause?: unknown;
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Thrown when disjointness constraint is violated.
|
|
633
|
+
*
|
|
634
|
+
* Disjoint types cannot share the same ID - a node cannot be both
|
|
635
|
+
* a Person and an Organization if they are declared disjoint.
|
|
636
|
+
*/
|
|
637
|
+
declare class DisjointError extends TypeGraphError {
|
|
638
|
+
constructor(details: Readonly<{
|
|
639
|
+
nodeId: string;
|
|
640
|
+
attemptedKind: string;
|
|
641
|
+
conflictingKind: string;
|
|
642
|
+
}>, options?: {
|
|
643
|
+
cause?: unknown;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Thrown when deletion is blocked due to existing edges (restrict behavior).
|
|
648
|
+
*/
|
|
649
|
+
declare class RestrictedDeleteError extends TypeGraphError {
|
|
650
|
+
constructor(details: Readonly<{
|
|
651
|
+
nodeKind: string;
|
|
652
|
+
nodeId: string;
|
|
653
|
+
edgeCount: number;
|
|
654
|
+
edgeKinds: readonly string[];
|
|
655
|
+
}>, options?: {
|
|
656
|
+
cause?: unknown;
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Thrown when optimistic locking detects a concurrent modification.
|
|
661
|
+
*
|
|
662
|
+
* This occurs when two operations try to update the same entity simultaneously.
|
|
663
|
+
* The operation with the stale version fails.
|
|
664
|
+
*/
|
|
665
|
+
declare class VersionConflictError extends TypeGraphError {
|
|
666
|
+
constructor(details: Readonly<{
|
|
667
|
+
kind: string;
|
|
668
|
+
id: string;
|
|
669
|
+
expectedVersion: number;
|
|
670
|
+
actualVersion: number;
|
|
671
|
+
}>, options?: {
|
|
672
|
+
cause?: unknown;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Thrown when the schema in code doesn't match the schema in the database.
|
|
677
|
+
*/
|
|
678
|
+
declare class SchemaMismatchError extends TypeGraphError {
|
|
679
|
+
constructor(details: Readonly<{
|
|
680
|
+
graphId: string;
|
|
681
|
+
expectedHash: string;
|
|
682
|
+
actualHash: string;
|
|
683
|
+
}>, options?: {
|
|
684
|
+
cause?: unknown;
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Thrown when schema migration fails.
|
|
689
|
+
*/
|
|
690
|
+
declare class MigrationError extends TypeGraphError {
|
|
691
|
+
constructor(message: string, details: Readonly<{
|
|
692
|
+
graphId: string;
|
|
693
|
+
fromVersion: number;
|
|
694
|
+
toVersion: number;
|
|
695
|
+
reason?: string;
|
|
696
|
+
}>, options?: {
|
|
697
|
+
cause?: unknown;
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Thrown when graph configuration is invalid.
|
|
702
|
+
*
|
|
703
|
+
* This includes invalid schema definitions, ontology conflicts,
|
|
704
|
+
* and other configuration issues detected at graph creation time.
|
|
705
|
+
*/
|
|
706
|
+
declare class ConfigurationError extends TypeGraphError {
|
|
707
|
+
constructor(message: string, details?: Record<string, unknown>, options?: {
|
|
708
|
+
cause?: unknown;
|
|
709
|
+
suggestion?: string;
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Thrown when a query predicate cannot be compiled for the target database.
|
|
714
|
+
*/
|
|
715
|
+
declare class UnsupportedPredicateError extends TypeGraphError {
|
|
716
|
+
constructor(message: string, details?: Readonly<Record<string, unknown>>, options?: {
|
|
717
|
+
cause?: unknown;
|
|
718
|
+
suggestion?: string;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Type guard for TypeGraphError.
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* try {
|
|
727
|
+
* await store.nodes.Person.create({});
|
|
728
|
+
* } catch (error) {
|
|
729
|
+
* if (isTypeGraphError(error)) {
|
|
730
|
+
* console.log(error.code, error.category);
|
|
731
|
+
* }
|
|
732
|
+
* }
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
declare function isTypeGraphError(error: unknown): error is TypeGraphError;
|
|
736
|
+
/**
|
|
737
|
+
* Check if error is recoverable by user action (user or constraint error).
|
|
738
|
+
*
|
|
739
|
+
* User-recoverable errors can typically be resolved by:
|
|
740
|
+
* - Fixing invalid input data
|
|
741
|
+
* - Using different IDs or values
|
|
742
|
+
* - Deleting conflicting data first
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* if (isUserRecoverable(error)) {
|
|
747
|
+
* showErrorToUser(error.toUserMessage());
|
|
748
|
+
* } else {
|
|
749
|
+
* logAndAlertOps(error);
|
|
750
|
+
* }
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
declare function isUserRecoverable(error: unknown): boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Check if error indicates a system/infrastructure issue.
|
|
756
|
+
*
|
|
757
|
+
* System errors typically require:
|
|
758
|
+
* - Retry logic (for transient failures)
|
|
759
|
+
* - Investigation (for persistent failures)
|
|
760
|
+
* - Ops team notification
|
|
761
|
+
*/
|
|
762
|
+
declare function isSystemError(error: unknown): boolean;
|
|
763
|
+
/**
|
|
764
|
+
* Check if error is a constraint violation.
|
|
765
|
+
*/
|
|
766
|
+
declare function isConstraintError(error: unknown): boolean;
|
|
767
|
+
/**
|
|
768
|
+
* Extract suggestion from error if available.
|
|
769
|
+
*/
|
|
770
|
+
declare function getErrorSuggestion(error: unknown): string | undefined;
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Contextual Validation Utilities
|
|
774
|
+
*
|
|
775
|
+
* Provides Zod validation wrappers that include full context about
|
|
776
|
+
* which entity (node/edge) and operation (create/update) failed.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* ```typescript
|
|
780
|
+
* const props = validateNodeProps(schema, input, {
|
|
781
|
+
* kind: "Person",
|
|
782
|
+
* operation: "create",
|
|
783
|
+
* });
|
|
784
|
+
* ```
|
|
785
|
+
*/
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Context for validation operations.
|
|
789
|
+
*/
|
|
790
|
+
type ValidationContext = Readonly<{
|
|
791
|
+
/** Type of entity being validated */
|
|
792
|
+
entityType: "node" | "edge";
|
|
793
|
+
/** Kind/type name of the entity */
|
|
794
|
+
kind: string;
|
|
795
|
+
/** Operation being performed */
|
|
796
|
+
operation: "create" | "update";
|
|
797
|
+
/** Entity ID (for updates) */
|
|
798
|
+
id?: string;
|
|
799
|
+
}>;
|
|
800
|
+
/**
|
|
801
|
+
* Validates props with full context for error messages.
|
|
802
|
+
*
|
|
803
|
+
* @param schema - Zod schema to validate against
|
|
804
|
+
* @param props - Properties to validate
|
|
805
|
+
* @param context - Context about the entity and operation
|
|
806
|
+
* @returns Validated and transformed props
|
|
807
|
+
* @throws ValidationError with full context if validation fails
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```typescript
|
|
811
|
+
* const validatedProps = validateProps(personSchema, input, {
|
|
812
|
+
* entityType: "node",
|
|
813
|
+
* kind: "Person",
|
|
814
|
+
* operation: "create",
|
|
815
|
+
* });
|
|
816
|
+
* ```
|
|
817
|
+
*/
|
|
818
|
+
declare function validateProps<T>(schema: ZodType<T>, props: unknown, context: ValidationContext): T;
|
|
819
|
+
/**
|
|
820
|
+
* Validates node props with full context.
|
|
821
|
+
*
|
|
822
|
+
* Convenience wrapper around validateProps for node operations.
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```typescript
|
|
826
|
+
* const props = validateNodeProps(schema, input, {
|
|
827
|
+
* kind: "Person",
|
|
828
|
+
* operation: "create",
|
|
829
|
+
* });
|
|
830
|
+
* ```
|
|
831
|
+
*/
|
|
832
|
+
declare function validateNodeProps<T>(schema: ZodType<T>, props: unknown, context: Readonly<{
|
|
833
|
+
kind: string;
|
|
834
|
+
operation: "create" | "update";
|
|
835
|
+
id?: string;
|
|
836
|
+
}>): T;
|
|
837
|
+
/**
|
|
838
|
+
* Validates edge props with full context.
|
|
839
|
+
*
|
|
840
|
+
* Convenience wrapper around validateProps for edge operations.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```typescript
|
|
844
|
+
* const props = validateEdgeProps(schema, input, {
|
|
845
|
+
* kind: "worksAt",
|
|
846
|
+
* operation: "create",
|
|
847
|
+
* });
|
|
848
|
+
* ```
|
|
849
|
+
*/
|
|
850
|
+
declare function validateEdgeProps<T>(schema: ZodType<T>, props: unknown, context: Readonly<{
|
|
851
|
+
kind: string;
|
|
852
|
+
operation: "create" | "update";
|
|
853
|
+
id?: string;
|
|
854
|
+
}>): T;
|
|
855
|
+
/**
|
|
856
|
+
* Wraps a Zod error with TypeGraph context.
|
|
857
|
+
*
|
|
858
|
+
* Use this when you've already caught a ZodError and want to
|
|
859
|
+
* convert it to a ValidationError with context.
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
* ```typescript
|
|
863
|
+
* try {
|
|
864
|
+
* schema.parse(input);
|
|
865
|
+
* } catch (error) {
|
|
866
|
+
* if (error instanceof ZodError) {
|
|
867
|
+
* throw wrapZodError(error, {
|
|
868
|
+
* entityType: "node",
|
|
869
|
+
* kind: "Person",
|
|
870
|
+
* operation: "create",
|
|
871
|
+
* });
|
|
872
|
+
* }
|
|
873
|
+
* throw error;
|
|
874
|
+
* }
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
declare function wrapZodError(error: ZodError, context: ValidationContext): ValidationError;
|
|
878
|
+
/**
|
|
879
|
+
* Creates a simple ValidationError without Zod context.
|
|
880
|
+
*
|
|
881
|
+
* Use this for custom validation rules that aren't part of a Zod schema.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* if (startDate > endDate) {
|
|
886
|
+
* throw createValidationError(
|
|
887
|
+
* "Start date must be before end date",
|
|
888
|
+
* [{ path: "startDate", message: "Must be before endDate" }],
|
|
889
|
+
* { entityType: "edge", kind: "employment", operation: "create" }
|
|
890
|
+
* );
|
|
891
|
+
* }
|
|
892
|
+
* ```
|
|
893
|
+
*/
|
|
894
|
+
declare function createValidationError(message: string, issues: ValidationIssue[], context?: Partial<ValidationContext>): ValidationError;
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Builder functions for creating KindRegistry from GraphDef.
|
|
898
|
+
*/
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Builds a KindRegistry from a GraphDef.
|
|
902
|
+
*
|
|
903
|
+
* This precomputes all transitive closures for efficient runtime queries.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```typescript
|
|
907
|
+
* const graph = defineGraph({
|
|
908
|
+
* id: "my_graph",
|
|
909
|
+
* nodes: { Person: { type: Person }, Company: { type: Company } },
|
|
910
|
+
* edges: { worksAt: { type: worksAt, from: [Person], to: [Company] } },
|
|
911
|
+
* ontology: [subClassOf(Company, Organization)],
|
|
912
|
+
* });
|
|
913
|
+
*
|
|
914
|
+
* const registry = buildKindRegistry(graph);
|
|
915
|
+
* registry.isSubClassOf("Company", "Organization"); // true
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
declare function buildKindRegistry<G extends GraphDef>(graph: G): KindRegistry;
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Recursive CTE Compilation
|
|
922
|
+
*
|
|
923
|
+
* Compiles variable-length path traversals using WITH RECURSIVE.
|
|
924
|
+
* Handles cycle detection and depth limiting using dialect-specific operations.
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Maximum depth for recursive CTE queries.
|
|
929
|
+
*
|
|
930
|
+
* This limit prevents runaway recursion in variable-length path queries.
|
|
931
|
+
* Even when a user specifies "unlimited" depth (-1), this limit is enforced.
|
|
932
|
+
* The limit of 100 is sufficient for most graph traversal use cases while
|
|
933
|
+
* preventing database resource exhaustion.
|
|
934
|
+
*/
|
|
935
|
+
declare const MAX_RECURSIVE_DEPTH = 100;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Aggregate and HAVING Helper Functions
|
|
939
|
+
*
|
|
940
|
+
* Provides factory functions for creating aggregate expressions (COUNT, SUM, etc.)
|
|
941
|
+
* and HAVING clause predicates for use in GROUP BY queries.
|
|
942
|
+
*/
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Creates a COUNT aggregate expression.
|
|
946
|
+
*
|
|
947
|
+
* @param alias - The node alias to count
|
|
948
|
+
* @param field - Optional field to count (defaults to counting nodes by ID)
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* ```typescript
|
|
952
|
+
* // COUNT all persons
|
|
953
|
+
* count("p")
|
|
954
|
+
*
|
|
955
|
+
* // COUNT persons with email field
|
|
956
|
+
* count("p", "email")
|
|
957
|
+
* ```
|
|
958
|
+
*/
|
|
959
|
+
declare function count(alias: string, field?: string): AggregateExpr;
|
|
960
|
+
/**
|
|
961
|
+
* Creates a COUNT DISTINCT aggregate expression.
|
|
962
|
+
*
|
|
963
|
+
* @param alias - The node alias to count
|
|
964
|
+
* @param field - Optional field to count distinct values of
|
|
965
|
+
*/
|
|
966
|
+
declare function countDistinct(alias: string, field?: string): AggregateExpr;
|
|
967
|
+
/**
|
|
968
|
+
* Creates a SUM aggregate expression.
|
|
969
|
+
*
|
|
970
|
+
* @param alias - The node alias
|
|
971
|
+
* @param field - The numeric field to sum
|
|
972
|
+
*/
|
|
973
|
+
declare function sum(alias: string, field: string): AggregateExpr;
|
|
974
|
+
/**
|
|
975
|
+
* Creates an AVG aggregate expression.
|
|
976
|
+
*
|
|
977
|
+
* @param alias - The node alias
|
|
978
|
+
* @param field - The numeric field to average
|
|
979
|
+
*/
|
|
980
|
+
declare function avg(alias: string, field: string): AggregateExpr;
|
|
981
|
+
/**
|
|
982
|
+
* Creates a MIN aggregate expression.
|
|
983
|
+
*
|
|
984
|
+
* @param alias - The node alias
|
|
985
|
+
* @param field - The field to find minimum of
|
|
986
|
+
*/
|
|
987
|
+
declare function min(alias: string, field: string): AggregateExpr;
|
|
988
|
+
/**
|
|
989
|
+
* Creates a MAX aggregate expression.
|
|
990
|
+
*
|
|
991
|
+
* @param alias - The node alias
|
|
992
|
+
* @param field - The field to find maximum of
|
|
993
|
+
*/
|
|
994
|
+
declare function max(alias: string, field: string): AggregateExpr;
|
|
995
|
+
/**
|
|
996
|
+
* Creates a field reference for use in selectAggregate.
|
|
997
|
+
*
|
|
998
|
+
* @param alias - The node alias
|
|
999
|
+
* @param path - Path to the field. Use "id" for node ID, "kind" for node kind,
|
|
1000
|
+
* or the property name directly (e.g., "title", "year").
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* field("p", "id") // Node ID
|
|
1005
|
+
* field("p", "kind") // Node kind
|
|
1006
|
+
* field("p", "title") // Property field
|
|
1007
|
+
* field("p", "nested", "field") // Nested property
|
|
1008
|
+
* ```
|
|
1009
|
+
*/
|
|
1010
|
+
declare function field(alias: string, ...path: string[]): FieldRef;
|
|
1011
|
+
/**
|
|
1012
|
+
* Creates a HAVING predicate that compares an aggregate to a value.
|
|
1013
|
+
*
|
|
1014
|
+
* @param aggregate - The aggregate expression (count, sum, avg, etc.)
|
|
1015
|
+
* @param op - The comparison operator
|
|
1016
|
+
* @param value - The value to compare against
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```typescript
|
|
1020
|
+
* // HAVING COUNT(*) > 10
|
|
1021
|
+
* having(count("p"), "gt", 10)
|
|
1022
|
+
*
|
|
1023
|
+
* // HAVING AVG(salary) >= 50000
|
|
1024
|
+
* having(avg("p", "salary"), "gte", 50000)
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
declare function having(aggregate: AggregateExpr, op: ComparisonOp, value: number | string | boolean): AggregateComparisonPredicate;
|
|
1028
|
+
/**
|
|
1029
|
+
* Creates a HAVING predicate: aggregate > value
|
|
1030
|
+
*/
|
|
1031
|
+
declare function havingGt(aggregate: AggregateExpr, value: number): AggregateComparisonPredicate;
|
|
1032
|
+
/**
|
|
1033
|
+
* Creates a HAVING predicate: aggregate >= value
|
|
1034
|
+
*/
|
|
1035
|
+
declare function havingGte(aggregate: AggregateExpr, value: number): AggregateComparisonPredicate;
|
|
1036
|
+
/**
|
|
1037
|
+
* Creates a HAVING predicate: aggregate < value
|
|
1038
|
+
*/
|
|
1039
|
+
declare function havingLt(aggregate: AggregateExpr, value: number): AggregateComparisonPredicate;
|
|
1040
|
+
/**
|
|
1041
|
+
* Creates a HAVING predicate: aggregate <= value
|
|
1042
|
+
*/
|
|
1043
|
+
declare function havingLte(aggregate: AggregateExpr, value: number): AggregateComparisonPredicate;
|
|
1044
|
+
/**
|
|
1045
|
+
* Creates a HAVING predicate: aggregate = value
|
|
1046
|
+
*/
|
|
1047
|
+
declare function havingEq(aggregate: AggregateExpr, value: number): AggregateComparisonPredicate;
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* Query Fragment Composition
|
|
1051
|
+
*
|
|
1052
|
+
* Provides types and utilities for creating reusable query fragments
|
|
1053
|
+
* that can be composed together using the pipe() method.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```typescript
|
|
1057
|
+
* // Define a reusable fragment
|
|
1058
|
+
* const activeUsers = createFragment<MyGraph>()((q) =>
|
|
1059
|
+
* q.whereNode("u", ({ status }) => status.eq("active"))
|
|
1060
|
+
* );
|
|
1061
|
+
*
|
|
1062
|
+
* // Use in queries
|
|
1063
|
+
* const results = await query()
|
|
1064
|
+
* .from("User", "u")
|
|
1065
|
+
* .pipe(activeUsers)
|
|
1066
|
+
* .select((ctx) => ctx.u)
|
|
1067
|
+
* .execute();
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* A query fragment that transforms a QueryBuilder.
|
|
1073
|
+
*
|
|
1074
|
+
* Fragments are functions that take a builder and return a modified builder.
|
|
1075
|
+
* They can add predicates, traversals, ordering, and other query operations.
|
|
1076
|
+
*
|
|
1077
|
+
* @typeParam G - The graph definition
|
|
1078
|
+
* @typeParam InAliases - Input alias map (what the fragment requires)
|
|
1079
|
+
* @typeParam OutAliases - Output alias map (what the fragment produces)
|
|
1080
|
+
* @typeParam InEdgeAliases - Input edge alias map
|
|
1081
|
+
* @typeParam OutEdgeAliases - Output edge alias map
|
|
1082
|
+
*/
|
|
1083
|
+
type QueryFragment<G extends GraphDef, InAliases extends AliasMap = AliasMap, OutAliases extends AliasMap = InAliases, InEdgeAliases extends EdgeAliasMap = EdgeAliasMap, OutEdgeAliases extends EdgeAliasMap = InEdgeAliases> = (builder: QueryBuilder<G, InAliases, InEdgeAliases>) => QueryBuilder<G, OutAliases, OutEdgeAliases>;
|
|
1084
|
+
/**
|
|
1085
|
+
* A flexible query fragment that works with any compatible builder.
|
|
1086
|
+
*
|
|
1087
|
+
* Use this when you want a fragment that only requires certain aliases
|
|
1088
|
+
* to exist, but doesn't care about other aliases that may be present.
|
|
1089
|
+
*/
|
|
1090
|
+
type FlexibleQueryFragment<G extends GraphDef, RequiredAliases extends AliasMap = AliasMap, AddedAliases extends AliasMap = AliasMap, RequiredEdgeAliases extends EdgeAliasMap = EdgeAliasMap, AddedEdgeAliases extends EdgeAliasMap = EdgeAliasMap> = <Aliases extends RequiredAliases, EdgeAliases extends RequiredEdgeAliases>(builder: QueryBuilder<G, Aliases, EdgeAliases>) => QueryBuilder<G, Aliases & AddedAliases, EdgeAliases & AddedEdgeAliases>;
|
|
1091
|
+
/**
|
|
1092
|
+
* A traversal fragment that transforms a TraversalBuilder.
|
|
1093
|
+
*
|
|
1094
|
+
* Use this for reusable traversal patterns including edge filtering,
|
|
1095
|
+
* recursive traversals, and path collection.
|
|
1096
|
+
*/
|
|
1097
|
+
type TraversalFragment<G extends GraphDef, EK extends keyof G["edges"] & string, EA extends string, InAliases extends AliasMap = AliasMap, InEdgeAliases extends EdgeAliasMap = EdgeAliasMap> = (builder: TraversalBuilder<G, InAliases, InEdgeAliases, EK, EA, any>) => unknown;
|
|
1098
|
+
declare function createFragment<G extends GraphDef>(): <InAliases extends AliasMap, OutAliases extends AliasMap, InEdgeAliases extends EdgeAliasMap, OutEdgeAliases extends EdgeAliasMap>(fn: (builder: QueryBuilder<G, InAliases, InEdgeAliases>) => QueryBuilder<G, OutAliases, OutEdgeAliases>) => QueryFragment<G, InAliases, OutAliases, InEdgeAliases, OutEdgeAliases>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Combines multiple fragments into a single fragment.
|
|
1101
|
+
*
|
|
1102
|
+
* Fragments are applied in order from left to right.
|
|
1103
|
+
*
|
|
1104
|
+
* @example
|
|
1105
|
+
* ```typescript
|
|
1106
|
+
* const combinedFragment = composeFragments(
|
|
1107
|
+
* activeOnly,
|
|
1108
|
+
* withManager,
|
|
1109
|
+
* recentlyUpdated
|
|
1110
|
+
* );
|
|
1111
|
+
*
|
|
1112
|
+
* query()
|
|
1113
|
+
* .from("User", "u")
|
|
1114
|
+
* .pipe(combinedFragment)
|
|
1115
|
+
* .select(...)
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
declare function composeFragments<G extends GraphDef, A1 extends AliasMap, A2 extends AliasMap, E1 extends EdgeAliasMap, E2 extends EdgeAliasMap>(f1: QueryFragment<G, A1, A2, E1, E2>): QueryFragment<G, A1, A2, E1, E2>;
|
|
1119
|
+
declare function composeFragments<G extends GraphDef, A1 extends AliasMap, A2 extends AliasMap, A3 extends AliasMap, E1 extends EdgeAliasMap, E2 extends EdgeAliasMap, E3 extends EdgeAliasMap>(f1: QueryFragment<G, A1, A2, E1, E2>, f2: QueryFragment<G, A2, A3, E2, E3>): QueryFragment<G, A1, A3, E1, E3>;
|
|
1120
|
+
declare function composeFragments<G extends GraphDef, A1 extends AliasMap, A2 extends AliasMap, A3 extends AliasMap, A4 extends AliasMap, E1 extends EdgeAliasMap, E2 extends EdgeAliasMap, E3 extends EdgeAliasMap, E4 extends EdgeAliasMap>(f1: QueryFragment<G, A1, A2, E1, E2>, f2: QueryFragment<G, A2, A3, E2, E3>, f3: QueryFragment<G, A3, A4, E3, E4>): QueryFragment<G, A1, A4, E1, E4>;
|
|
1121
|
+
declare function composeFragments<G extends GraphDef, A1 extends AliasMap, A2 extends AliasMap, A3 extends AliasMap, A4 extends AliasMap, A5 extends AliasMap, E1 extends EdgeAliasMap, E2 extends EdgeAliasMap, E3 extends EdgeAliasMap, E4 extends EdgeAliasMap, E5 extends EdgeAliasMap>(f1: QueryFragment<G, A1, A2, E1, E2>, f2: QueryFragment<G, A2, A3, E2, E3>, f3: QueryFragment<G, A3, A4, E3, E4>, f4: QueryFragment<G, A4, A5, E4, E5>): QueryFragment<G, A1, A5, E1, E5>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Creates a fragment that adds ordering.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```typescript
|
|
1127
|
+
* const byCreatedAt = orderByFragment<MyGraph, "u">("u", "createdAt", "desc");
|
|
1128
|
+
* ```
|
|
1129
|
+
*/
|
|
1130
|
+
declare function orderByFragment<G extends GraphDef, A extends string>(alias: A, field: string, direction?: "asc" | "desc"): QueryFragment<G, any, any, any, any>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Creates a fragment that adds a limit.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* const first10 = limitFragment<MyGraph>(10);
|
|
1137
|
+
* ```
|
|
1138
|
+
*/
|
|
1139
|
+
declare function limitFragment<G extends GraphDef>(n: number): QueryFragment<G, any, any, any, any>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Creates a fragment that adds an offset.
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```typescript
|
|
1145
|
+
* const skip10 = offsetFragment<MyGraph>(10);
|
|
1146
|
+
* ```
|
|
1147
|
+
*/
|
|
1148
|
+
declare function offsetFragment<G extends GraphDef>(n: number): QueryFragment<G, any, any, any, any>;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Fluent query builder for TypeGraph.
|
|
1152
|
+
*
|
|
1153
|
+
* Provides a type-safe, chainable API for building queries.
|
|
1154
|
+
* Each method returns a new builder instance with expanded type information.
|
|
1155
|
+
*
|
|
1156
|
+
* This module re-exports from the builder submodules and provides the
|
|
1157
|
+
* createQueryBuilder factory function.
|
|
1158
|
+
*/
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Creates a new query builder for a graph.
|
|
1162
|
+
*
|
|
1163
|
+
* @param graphId - The graph identifier
|
|
1164
|
+
* @param registry - The kind registry for ontology lookups
|
|
1165
|
+
* @param options - Optional backend and dialect configuration
|
|
1166
|
+
* @returns A new QueryBuilder instance
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```typescript
|
|
1170
|
+
* // Without execution capability (compile only)
|
|
1171
|
+
* const builder = createQueryBuilder<MyGraph>("my_graph", registry);
|
|
1172
|
+
*
|
|
1173
|
+
* // With execution capability
|
|
1174
|
+
* const builder = createQueryBuilder<MyGraph>("my_graph", registry, {
|
|
1175
|
+
* backend: myBackend,
|
|
1176
|
+
* dialect: "sqlite",
|
|
1177
|
+
* });
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
declare function createQueryBuilder<G extends GraphDef>(graphId: string, registry: KindRegistry, options?: CreateQueryBuilderOptions): QueryBuilder<G>;
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Schema deserializer for loading stored schemas.
|
|
1184
|
+
*
|
|
1185
|
+
* Reconstructs runtime objects from SerializedSchema.
|
|
1186
|
+
* Note: Zod schemas cannot be fully reconstructed from JSON Schema,
|
|
1187
|
+
* so this provides access to the serialized data for introspection.
|
|
1188
|
+
*/
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* A deserialized schema provides read-only access to schema metadata.
|
|
1192
|
+
*
|
|
1193
|
+
* Note: Unlike the original GraphDef, this does not include Zod schemas
|
|
1194
|
+
* since those cannot be reconstructed from JSON Schema. Use this for
|
|
1195
|
+
* introspection and metadata access only.
|
|
1196
|
+
*/
|
|
1197
|
+
type DeserializedSchema = Readonly<{
|
|
1198
|
+
graphId: string;
|
|
1199
|
+
version: number;
|
|
1200
|
+
generatedAt: string;
|
|
1201
|
+
/** Get node definition by name */
|
|
1202
|
+
getNode: (name: string) => SerializedNodeDef | undefined;
|
|
1203
|
+
/** Get all node names */
|
|
1204
|
+
getNodeNames: () => readonly string[];
|
|
1205
|
+
/** Get edge definition by name */
|
|
1206
|
+
getEdge: (name: string) => SerializedEdgeDef | undefined;
|
|
1207
|
+
/** Get all edge names */
|
|
1208
|
+
getEdgeNames: () => readonly string[];
|
|
1209
|
+
/** Get meta-edge definition by name */
|
|
1210
|
+
getMetaEdge: (name: string) => SerializedMetaEdge | undefined;
|
|
1211
|
+
/** Get all meta-edge names */
|
|
1212
|
+
getMetaEdgeNames: () => readonly string[];
|
|
1213
|
+
/** Get all ontology relations */
|
|
1214
|
+
getRelations: () => readonly SerializedOntologyRelation[];
|
|
1215
|
+
/** Get precomputed closures */
|
|
1216
|
+
getClosures: () => SerializedClosures;
|
|
1217
|
+
/** Get graph defaults */
|
|
1218
|
+
getDefaults: () => SerializedSchema["defaults"];
|
|
1219
|
+
/** Get the raw serialized schema */
|
|
1220
|
+
getRaw: () => SerializedSchema;
|
|
1221
|
+
/** Build a KindRegistry from the closures */
|
|
1222
|
+
buildRegistry: () => KindRegistry;
|
|
1223
|
+
}>;
|
|
1224
|
+
/**
|
|
1225
|
+
* Deserializes a SerializedSchema into a DeserializedSchema.
|
|
1226
|
+
*
|
|
1227
|
+
* @param schema - The serialized schema to deserialize
|
|
1228
|
+
* @returns A deserialized schema with accessor methods
|
|
1229
|
+
*/
|
|
1230
|
+
declare function deserializeSchema(schema: SerializedSchema): DeserializedSchema;
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Serializes a GraphDef to a SerializedSchema.
|
|
1234
|
+
*
|
|
1235
|
+
* @param graph - The graph definition to serialize
|
|
1236
|
+
* @param version - The schema version number
|
|
1237
|
+
* @returns The serialized schema
|
|
1238
|
+
*/
|
|
1239
|
+
declare function serializeSchema<G extends GraphDef>(graph: G, version: number): SerializedSchema;
|
|
1240
|
+
/**
|
|
1241
|
+
* A serialized predicate structure (matches UniqueConstraintPredicate from core/types).
|
|
1242
|
+
*/
|
|
1243
|
+
type SerializedPredicate = Readonly<{
|
|
1244
|
+
__type: "unique_predicate";
|
|
1245
|
+
field: string;
|
|
1246
|
+
op: "isNull" | "isNotNull";
|
|
1247
|
+
}>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Field builder returned by the predicate proxy.
|
|
1250
|
+
*/
|
|
1251
|
+
type FieldPredicateBuilder = Readonly<{
|
|
1252
|
+
isNull: () => SerializedPredicate;
|
|
1253
|
+
isNotNull: () => SerializedPredicate;
|
|
1254
|
+
}>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Predicate builder type for where clause serialization.
|
|
1257
|
+
*/
|
|
1258
|
+
type PredicateBuilder = Readonly<Record<string, FieldPredicateBuilder>>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Deserializes a where predicate JSON back to a predicate function.
|
|
1261
|
+
*
|
|
1262
|
+
* This can be used to reconstruct a UniqueConstraint's where clause
|
|
1263
|
+
* from a serialized schema.
|
|
1264
|
+
*
|
|
1265
|
+
* @param serialized - The JSON string from serialization
|
|
1266
|
+
* @returns A where function that returns the predicate structure
|
|
1267
|
+
*/
|
|
1268
|
+
/**
|
|
1269
|
+
* Unique predicate result type.
|
|
1270
|
+
*/
|
|
1271
|
+
type UniquePredicate = Readonly<{
|
|
1272
|
+
__type: "unique_predicate";
|
|
1273
|
+
field: string;
|
|
1274
|
+
op: "isNull" | "isNotNull";
|
|
1275
|
+
}>;
|
|
1276
|
+
declare function deserializeWherePredicate(serialized: string): (builder: PredicateBuilder) => UniquePredicate;
|
|
1277
|
+
/**
|
|
1278
|
+
* Computes a hash of the schema content for change detection.
|
|
1279
|
+
*
|
|
1280
|
+
* Excludes version and generatedAt since those change on every save.
|
|
1281
|
+
*/
|
|
1282
|
+
declare function computeSchemaHash(schema: SerializedSchema): SchemaHash;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Encodes a Date to an ISO 8601 string for storage.
|
|
1286
|
+
*/
|
|
1287
|
+
declare function encodeDate(date: Date): string;
|
|
1288
|
+
/**
|
|
1289
|
+
* Decodes an ISO 8601 string to a Date.
|
|
1290
|
+
* Validates the string format first.
|
|
1291
|
+
*
|
|
1292
|
+
* @throws ValidationError if not a valid ISO datetime
|
|
1293
|
+
*/
|
|
1294
|
+
declare function decodeDate(isoString: string): Date;
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* ID generation utilities.
|
|
1298
|
+
*
|
|
1299
|
+
* Default implementation uses nanoid.
|
|
1300
|
+
* Benefits:
|
|
1301
|
+
* - URL-safe
|
|
1302
|
+
* - Compact (21 characters by default)
|
|
1303
|
+
* - Secure random generation
|
|
1304
|
+
*/
|
|
1305
|
+
/**
|
|
1306
|
+
* Generates a new unique ID.
|
|
1307
|
+
*/
|
|
1308
|
+
declare function generateId(): string;
|
|
1309
|
+
/**
|
|
1310
|
+
* ID generator function type.
|
|
1311
|
+
*/
|
|
1312
|
+
type IdGenerator = () => string;
|
|
1313
|
+
/**
|
|
1314
|
+
* Default ID generator configuration.
|
|
1315
|
+
*/
|
|
1316
|
+
type IdConfig = Readonly<{
|
|
1317
|
+
/** Generator for node IDs */
|
|
1318
|
+
nodeIdGenerator: IdGenerator;
|
|
1319
|
+
/** Generator for edge IDs */
|
|
1320
|
+
edgeIdGenerator: IdGenerator;
|
|
1321
|
+
}>;
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* Result type for error handling without exceptions.
|
|
1325
|
+
* Use at service boundaries and for operations that can fail.
|
|
1326
|
+
*/
|
|
1327
|
+
type Result<T, E = Error> = Readonly<{
|
|
1328
|
+
success: true;
|
|
1329
|
+
data: T;
|
|
1330
|
+
}> | Readonly<{
|
|
1331
|
+
success: false;
|
|
1332
|
+
error: E;
|
|
1333
|
+
}>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Creates a successful result.
|
|
1336
|
+
*/
|
|
1337
|
+
declare function ok<T = undefined>(data?: T): Result<T, never>;
|
|
1338
|
+
/**
|
|
1339
|
+
* Creates a failed result.
|
|
1340
|
+
*/
|
|
1341
|
+
declare function err<E>(error: E): Result<never, E>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Unwraps a result, throwing if it's an error.
|
|
1344
|
+
*/
|
|
1345
|
+
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
1346
|
+
/**
|
|
1347
|
+
* Unwraps a result or returns a default value.
|
|
1348
|
+
*/
|
|
1349
|
+
declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
1350
|
+
/**
|
|
1351
|
+
* Type guard to check if result is successful.
|
|
1352
|
+
*/
|
|
1353
|
+
declare function isOk<T, E>(result: Result<T, E>): result is {
|
|
1354
|
+
success: true;
|
|
1355
|
+
data: T;
|
|
1356
|
+
};
|
|
1357
|
+
/**
|
|
1358
|
+
* Type guard to check if result is an error.
|
|
1359
|
+
*/
|
|
1360
|
+
declare function isErr<T, E>(result: Result<T, E>): result is {
|
|
1361
|
+
success: false;
|
|
1362
|
+
error: E;
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
export { AliasMap, CardinalityError, ConfigurationError, type DefineEdgeOptions, type DefineNodeOptions, type DeserializedSchema, DisjointError, EdgeNotFoundError, EdgeType, EndpointError, EndpointNotFoundError, type ErrorCategory, type ExternalRefSchema, type ExternalRefValue, FieldRef, type FlexibleQueryFragment, GraphDef, type IdConfig, type IdGenerator, InferenceType, KindNotFoundError, KindRegistry, MAX_RECURSIVE_DEPTH, MetaEdge, type MetaEdgeOptions, MigrationError, NodeNotFoundError, NodeType, OntologyRelation, QueryBuilder, type QueryFragment, RestrictedDeleteError, type Result, SchemaHash, SchemaMismatchError, SerializedClosures, SerializedEdgeDef, SerializedMetaEdge, SerializedNodeDef, SerializedOntologyRelation, SerializedSchema, type TraversalFragment, TypeGraphError, type TypeGraphErrorOptions, UniquenessError, UnsupportedPredicateError, type ValidationContext, ValidationError, type ValidationErrorDetails, type ValidationIssue, VersionConflictError, avg, broader, buildKindRegistry, composeFragments, computeSchemaHash, core, count, countDistinct, createExternalRef, createFragment, createQueryBuilder, createValidationError, decodeDate, defineEdge, defineNode, deserializeSchema, deserializeWherePredicate, differentFrom, disjointWith, encodeDate, equivalentTo, err, externalRef, field, generateId, getErrorSuggestion, getExternalRefTable, hasPart, having, havingEq, havingGt, havingGte, havingLt, havingLte, implies, inverseOf, isConstraintError, isErr, isExternalRefSchema, isOk, isSystemError, isTypeGraphError, isUserRecoverable, limitFragment, max, metaEdge, min, narrower, offsetFragment, ok, orderByFragment, partOf, relatedTo, sameAs, serializeSchema, subClassOf, sum, unwrap, unwrapOr, validateEdgeProps, validateNodeProps, validateProps, wrapZodError };
|