@nicia-ai/typegraph 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/{ast-BVyihVbP.d.cts → ast-CXFx6bF6.d.ts} +45 -165
- package/dist/{ast-BVyihVbP.d.ts → ast-D-3bOanX.d.cts} +45 -165
- package/dist/backend/drizzle/index.cjs +20 -21
- package/dist/backend/drizzle/index.d.cts +6 -5
- package/dist/backend/drizzle/index.d.ts +6 -5
- package/dist/backend/drizzle/index.js +8 -9
- package/dist/backend/drizzle/postgres.cjs +9 -10
- package/dist/backend/drizzle/postgres.d.cts +9 -11
- package/dist/backend/drizzle/postgres.d.ts +9 -11
- package/dist/backend/drizzle/postgres.js +6 -7
- package/dist/backend/drizzle/schema/postgres.cjs +10 -11
- package/dist/backend/drizzle/schema/postgres.d.cts +6 -5
- package/dist/backend/drizzle/schema/postgres.d.ts +6 -5
- package/dist/backend/drizzle/schema/postgres.js +3 -4
- package/dist/backend/drizzle/schema/sqlite.cjs +10 -11
- package/dist/backend/drizzle/schema/sqlite.d.cts +6 -5
- package/dist/backend/drizzle/schema/sqlite.d.ts +6 -5
- package/dist/backend/drizzle/schema/sqlite.js +3 -4
- package/dist/backend/drizzle/sqlite.cjs +9 -10
- package/dist/backend/drizzle/sqlite.d.cts +17 -18
- package/dist/backend/drizzle/sqlite.d.ts +17 -18
- package/dist/backend/drizzle/sqlite.js +6 -7
- package/dist/backend/postgres/index.cjs +21 -18
- package/dist/backend/postgres/index.d.cts +8 -7
- package/dist/backend/postgres/index.d.ts +8 -7
- package/dist/backend/postgres/index.js +8 -9
- package/dist/backend/sqlite/index.cjs +27 -22
- package/dist/backend/sqlite/index.cjs.map +1 -1
- package/dist/backend/sqlite/index.d.cts +7 -6
- package/dist/backend/sqlite/index.d.ts +7 -6
- package/dist/backend/sqlite/index.js +18 -13
- package/dist/backend/sqlite/index.js.map +1 -1
- package/dist/{chunk-YM5AL65Y.cjs → chunk-2WVFEIHR.cjs} +29 -3
- package/dist/chunk-2WVFEIHR.cjs.map +1 -0
- package/dist/{chunk-4PIEL2VO.js → chunk-3PURVEA4.js} +36 -5
- package/dist/chunk-3PURVEA4.js.map +1 -0
- package/dist/chunk-4HARSV2G.js +1448 -0
- package/dist/chunk-4HARSV2G.js.map +1 -0
- package/dist/{chunk-IIAT36MI.js → chunk-54WJF3DW.js} +29 -3
- package/dist/chunk-54WJF3DW.js.map +1 -0
- package/dist/chunk-CMHFS34N.cjs +390 -0
- package/dist/chunk-CMHFS34N.cjs.map +1 -0
- package/dist/chunk-DD6ONEBN.cjs +1264 -0
- package/dist/chunk-DD6ONEBN.cjs.map +1 -0
- package/dist/chunk-F2BZSEFE.js +388 -0
- package/dist/chunk-F2BZSEFE.js.map +1 -0
- package/dist/{chunk-DDM2FZRJ.cjs → chunk-JQDWEX6V.cjs} +24 -24
- package/dist/{chunk-DDM2FZRJ.cjs.map → chunk-JQDWEX6V.cjs.map} +1 -1
- package/dist/chunk-NP4G4ZKM.js +1228 -0
- package/dist/chunk-NP4G4ZKM.js.map +1 -0
- package/dist/{chunk-UJAGXJDG.cjs → chunk-NU2XNMVI.cjs} +38 -7
- package/dist/chunk-NU2XNMVI.cjs.map +1 -0
- package/dist/{chunk-JKTO7TW3.js → chunk-O5XPCJLF.js} +25 -3
- package/dist/chunk-O5XPCJLF.js.map +1 -0
- package/dist/{chunk-2QHQ2C4P.js → chunk-OGGLFYFA.js} +36 -5
- package/dist/chunk-OGGLFYFA.js.map +1 -0
- package/dist/{chunk-SV5H3XM5.cjs → chunk-OYL2SGBD.cjs} +26 -2
- package/dist/chunk-OYL2SGBD.cjs.map +1 -0
- package/dist/chunk-SFY2PPOY.cjs +1469 -0
- package/dist/chunk-SFY2PPOY.cjs.map +1 -0
- package/dist/{chunk-JDAET5LO.js → chunk-SMLIWLS7.js} +9 -9
- package/dist/chunk-SMLIWLS7.js.map +1 -0
- package/dist/{chunk-VXRVGFCI.js → chunk-U3452TEU.js} +17 -17
- package/dist/{chunk-VXRVGFCI.js.map → chunk-U3452TEU.js.map} +1 -1
- package/dist/{chunk-MNO33ASC.cjs → chunk-UYMT4LO2.cjs} +9 -8
- package/dist/chunk-UYMT4LO2.cjs.map +1 -0
- package/dist/chunk-V7CS2MDB.cjs +289 -0
- package/dist/chunk-V7CS2MDB.cjs.map +1 -0
- package/dist/chunk-WE5BKYNB.js +287 -0
- package/dist/chunk-WE5BKYNB.js.map +1 -0
- package/dist/{chunk-L642L24T.js → chunk-XDTYTNYL.js} +14 -21
- package/dist/chunk-XDTYTNYL.js.map +1 -0
- package/dist/{chunk-N4AOJ3VF.cjs → chunk-XZL6MCZJ.cjs} +38 -7
- package/dist/chunk-XZL6MCZJ.cjs.map +1 -0
- package/dist/{chunk-DBFCKELK.cjs → chunk-ZJHQZZT2.cjs} +18 -27
- package/dist/chunk-ZJHQZZT2.cjs.map +1 -0
- package/dist/index-Dkicw49A.d.cts +373 -0
- package/dist/index-Dkicw49A.d.ts +373 -0
- package/dist/index.cjs +5916 -3371
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -664
- package/dist/index.d.ts +24 -664
- package/dist/index.js +5783 -3220
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +16 -17
- package/dist/indexes/index.d.cts +5 -4
- package/dist/indexes/index.d.ts +5 -4
- package/dist/indexes/index.js +2 -3
- package/dist/interchange/index.cjs +9 -10
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +5 -3
- package/dist/interchange/index.d.ts +5 -3
- package/dist/interchange/index.js +8 -9
- package/dist/interchange/index.js.map +1 -1
- package/dist/manager-Jc5Btay9.d.cts +493 -0
- package/dist/manager-e9LXthrx.d.ts +493 -0
- package/dist/profiler/index.cjs +2 -9
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +9 -161
- package/dist/profiler/index.d.ts +9 -161
- package/dist/profiler/index.js +4 -5
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +145 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +237 -0
- package/dist/schema/index.d.ts +237 -0
- package/dist/schema/index.js +72 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/{store-60Lcfi0w.d.ts → store-DM3Tk3Pw.d.ts} +871 -1314
- package/dist/{store-Bifii8MZ.d.cts → store-nbBybLWP.d.cts} +871 -1314
- package/dist/{test-helpers-BjyRYJZX.d.ts → test-helpers-CIq1Hhj1.d.ts} +5 -1
- package/dist/{test-helpers-NoQXhleQ.d.cts → test-helpers-DPRFVky4.d.cts} +5 -1
- package/dist/{types-D_3mEv2y.d.ts → types-BL1GyVku.d.cts} +2 -2
- package/dist/{types-CjZ7g_7v.d.ts → types-Cdbi4hcx.d.ts} +292 -4
- package/dist/{types-BrSfFSpW.d.cts → types-DCGa53O2.d.ts} +2 -2
- package/dist/{types-DDOSfrih.d.cts → types-DDP0MGBF.d.cts} +292 -4
- package/dist/{types-a5rAxC92.d.cts → types-DHRsi6j9.d.cts} +4 -3
- package/dist/types-DTJEu_-h.d.cts +158 -0
- package/dist/types-DTJEu_-h.d.ts +158 -0
- package/dist/{types-CX4cLd7M.d.ts → types-ZT5mlism.d.ts} +4 -3
- package/package.json +17 -2
- package/dist/chunk-2QHQ2C4P.js.map +0 -1
- package/dist/chunk-3A5TKOEJ.js +0 -306
- package/dist/chunk-3A5TKOEJ.js.map +0 -1
- package/dist/chunk-4PIEL2VO.js.map +0 -1
- package/dist/chunk-536PH5FT.js +0 -342
- package/dist/chunk-536PH5FT.js.map +0 -1
- package/dist/chunk-DBFCKELK.cjs.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -10
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-F32HCHYA.cjs +0 -680
- package/dist/chunk-F32HCHYA.cjs.map +0 -1
- package/dist/chunk-IIAT36MI.js.map +0 -1
- package/dist/chunk-JDAET5LO.js.map +0 -1
- package/dist/chunk-JEQ2X3Z6.cjs +0 -12
- package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
- package/dist/chunk-JKTO7TW3.js.map +0 -1
- package/dist/chunk-L642L24T.js.map +0 -1
- package/dist/chunk-MFVCSNIY.cjs +0 -308
- package/dist/chunk-MFVCSNIY.cjs.map +0 -1
- package/dist/chunk-MNO33ASC.cjs.map +0 -1
- package/dist/chunk-N4AOJ3VF.cjs.map +0 -1
- package/dist/chunk-RYT4H46I.js +0 -646
- package/dist/chunk-RYT4H46I.js.map +0 -1
- package/dist/chunk-SV5H3XM5.cjs.map +0 -1
- package/dist/chunk-TXHKFLWX.cjs +0 -344
- package/dist/chunk-TXHKFLWX.cjs.map +0 -1
- package/dist/chunk-UJAGXJDG.cjs.map +0 -1
- package/dist/chunk-YM5AL65Y.cjs.map +0 -1
|
@@ -1,6 +1,257 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
+
import { N as NodeType, E as EdgeType, U as UniquenessScope, C as Collation, D as DeleteBehavior, d as Cardinality, e as EndpointExistence, T as TemporalMode } from './types-DTJEu_-h.cjs';
|
|
2
3
|
import { S as SqlDialect } from './types-BRzHlhKC.cjs';
|
|
3
4
|
|
|
5
|
+
/** Brand key for MetaEdge */
|
|
6
|
+
declare const META_EDGE_BRAND: "__metaEdge";
|
|
7
|
+
/**
|
|
8
|
+
* How a meta-edge affects queries and validation.
|
|
9
|
+
*/
|
|
10
|
+
type InferenceType = "subsumption" | "hierarchy" | "substitution" | "constraint" | "composition" | "association" | "none";
|
|
11
|
+
/**
|
|
12
|
+
* Properties of a meta-edge.
|
|
13
|
+
*/
|
|
14
|
+
type MetaEdgeProperties = Readonly<{
|
|
15
|
+
transitive: boolean;
|
|
16
|
+
symmetric: boolean;
|
|
17
|
+
reflexive: boolean;
|
|
18
|
+
inverse: string | undefined;
|
|
19
|
+
inference: InferenceType;
|
|
20
|
+
description: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* A meta-edge definition.
|
|
24
|
+
*
|
|
25
|
+
* Meta-edges represent type-level relationships (between kinds),
|
|
26
|
+
* not instance-level relationships (between nodes).
|
|
27
|
+
*/
|
|
28
|
+
type MetaEdge<K extends string = string> = Readonly<{
|
|
29
|
+
[META_EDGE_BRAND]: true;
|
|
30
|
+
name: K;
|
|
31
|
+
properties: MetaEdgeProperties;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* A relation in the ontology (instance of meta-edge between types).
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Podcast subClassOf Media
|
|
39
|
+
* subClassOf(Podcast, Media)
|
|
40
|
+
*
|
|
41
|
+
* // Person equivalentTo schema:Person
|
|
42
|
+
* equivalentTo(Person, "https://schema.org/Person")
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
type OntologyRelation = Readonly<{
|
|
46
|
+
metaEdge: MetaEdge;
|
|
47
|
+
from: NodeType | EdgeType | string;
|
|
48
|
+
to: NodeType | EdgeType | string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a value is a MetaEdge.
|
|
52
|
+
*/
|
|
53
|
+
declare function isMetaEdge(value: unknown): value is MetaEdge;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* SQL Schema Configuration for Query Compilation
|
|
57
|
+
*
|
|
58
|
+
* Provides table and column identifiers that the query compiler uses.
|
|
59
|
+
* This allows the compiler to work with custom table names instead of
|
|
60
|
+
* hard-coded defaults.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Table names for TypeGraph SQL schema.
|
|
65
|
+
*/
|
|
66
|
+
type SqlTableNames = Readonly<{
|
|
67
|
+
/** Nodes table name (default: "typegraph_nodes") */
|
|
68
|
+
nodes: string;
|
|
69
|
+
/** Edges table name (default: "typegraph_edges") */
|
|
70
|
+
edges: string;
|
|
71
|
+
/** Node embeddings table name (default: "typegraph_node_embeddings") */
|
|
72
|
+
embeddings: string;
|
|
73
|
+
}>;
|
|
74
|
+
/**
|
|
75
|
+
* SQL schema configuration for query compilation.
|
|
76
|
+
* Contains table identifiers and utility methods for generating SQL references.
|
|
77
|
+
*/
|
|
78
|
+
type SqlSchema = Readonly<{
|
|
79
|
+
/** Table names */
|
|
80
|
+
tables: SqlTableNames;
|
|
81
|
+
/** Get a SQL reference to the nodes table */
|
|
82
|
+
nodesTable: SQL;
|
|
83
|
+
/** Get a SQL reference to the edges table */
|
|
84
|
+
edgesTable: SQL;
|
|
85
|
+
/** Get a SQL reference to the embeddings table */
|
|
86
|
+
embeddingsTable: SQL;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a SqlSchema configuration from table names.
|
|
90
|
+
*
|
|
91
|
+
* Table names are validated to ensure they are valid SQL identifiers.
|
|
92
|
+
* This prevents SQL injection and ensures compatibility across databases.
|
|
93
|
+
*
|
|
94
|
+
* @param names - Optional custom table names (defaults to standard names)
|
|
95
|
+
* @returns SqlSchema configuration for query compilation
|
|
96
|
+
* @throws Error if any table name is invalid
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Use default table names
|
|
101
|
+
* const schema = createSqlSchema();
|
|
102
|
+
*
|
|
103
|
+
* // Use custom table names
|
|
104
|
+
* const schema = createSqlSchema({
|
|
105
|
+
* nodes: "myapp_nodes",
|
|
106
|
+
* edges: "myapp_edges",
|
|
107
|
+
* embeddings: "myapp_embeddings",
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function createSqlSchema(names?: Partial<SqlTableNames>): SqlSchema;
|
|
112
|
+
/**
|
|
113
|
+
* Default SqlSchema using standard TypeGraph table names.
|
|
114
|
+
*/
|
|
115
|
+
declare const DEFAULT_SQL_SCHEMA: SqlSchema;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Types for serialized schema storage.
|
|
119
|
+
*
|
|
120
|
+
* These types represent the JSON-serializable format used for
|
|
121
|
+
* homoiconic schema storage in the database.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* JSON Schema type (subset used by Zod toJSONSchema).
|
|
126
|
+
*
|
|
127
|
+
* This is a simplified version - the actual JSON Schema has many more properties.
|
|
128
|
+
*/
|
|
129
|
+
type JsonSchema = Readonly<{
|
|
130
|
+
$schema?: string;
|
|
131
|
+
type?: string | readonly string[];
|
|
132
|
+
properties?: Record<string, JsonSchema>;
|
|
133
|
+
required?: readonly string[];
|
|
134
|
+
items?: JsonSchema;
|
|
135
|
+
additionalProperties?: boolean | JsonSchema;
|
|
136
|
+
enum?: readonly unknown[];
|
|
137
|
+
const?: unknown;
|
|
138
|
+
anyOf?: readonly JsonSchema[];
|
|
139
|
+
oneOf?: readonly JsonSchema[];
|
|
140
|
+
allOf?: readonly JsonSchema[];
|
|
141
|
+
not?: JsonSchema;
|
|
142
|
+
description?: string;
|
|
143
|
+
default?: unknown;
|
|
144
|
+
minimum?: number;
|
|
145
|
+
maximum?: number;
|
|
146
|
+
minLength?: number;
|
|
147
|
+
maxLength?: number;
|
|
148
|
+
pattern?: string;
|
|
149
|
+
format?: string;
|
|
150
|
+
[key: string]: unknown;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Serialized representation of a meta-edge.
|
|
154
|
+
*/
|
|
155
|
+
type SerializedMetaEdge = Readonly<{
|
|
156
|
+
name: string;
|
|
157
|
+
transitive: boolean;
|
|
158
|
+
symmetric: boolean;
|
|
159
|
+
reflexive: boolean;
|
|
160
|
+
inverse: string | undefined;
|
|
161
|
+
inference: InferenceType;
|
|
162
|
+
description: string | undefined;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Serialized representation of an ontology relation.
|
|
166
|
+
*/
|
|
167
|
+
type SerializedOntologyRelation = Readonly<{
|
|
168
|
+
metaEdge: string;
|
|
169
|
+
from: string;
|
|
170
|
+
to: string;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Precomputed closures stored in the schema for fast runtime lookup.
|
|
174
|
+
*/
|
|
175
|
+
type SerializedClosures = Readonly<{
|
|
176
|
+
subClassAncestors: Record<string, readonly string[]>;
|
|
177
|
+
subClassDescendants: Record<string, readonly string[]>;
|
|
178
|
+
broaderClosure: Record<string, readonly string[]>;
|
|
179
|
+
narrowerClosure: Record<string, readonly string[]>;
|
|
180
|
+
equivalenceSets: Record<string, readonly string[]>;
|
|
181
|
+
disjointPairs: readonly string[];
|
|
182
|
+
partOfClosure: Record<string, readonly string[]>;
|
|
183
|
+
hasPartClosure: Record<string, readonly string[]>;
|
|
184
|
+
iriToKind: Record<string, string>;
|
|
185
|
+
edgeInverses: Record<string, string>;
|
|
186
|
+
edgeImplicationsClosure: Record<string, readonly string[]>;
|
|
187
|
+
edgeImplyingClosure: Record<string, readonly string[]>;
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Complete serialized ontology section.
|
|
191
|
+
*/
|
|
192
|
+
type SerializedOntology = Readonly<{
|
|
193
|
+
metaEdges: Record<string, SerializedMetaEdge>;
|
|
194
|
+
relations: readonly SerializedOntologyRelation[];
|
|
195
|
+
closures: SerializedClosures;
|
|
196
|
+
}>;
|
|
197
|
+
/**
|
|
198
|
+
* Serialized representation of a uniqueness constraint.
|
|
199
|
+
*/
|
|
200
|
+
type SerializedUniqueConstraint = Readonly<{
|
|
201
|
+
name: string;
|
|
202
|
+
fields: readonly string[];
|
|
203
|
+
where: string | undefined;
|
|
204
|
+
scope: UniquenessScope;
|
|
205
|
+
collation: Collation;
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Serialized representation of a node kind.
|
|
209
|
+
*/
|
|
210
|
+
type SerializedNodeDef = Readonly<{
|
|
211
|
+
kind: string;
|
|
212
|
+
properties: JsonSchema;
|
|
213
|
+
uniqueConstraints: readonly SerializedUniqueConstraint[];
|
|
214
|
+
onDelete: DeleteBehavior;
|
|
215
|
+
description: string | undefined;
|
|
216
|
+
}>;
|
|
217
|
+
/**
|
|
218
|
+
* Serialized representation of an edge kind.
|
|
219
|
+
*/
|
|
220
|
+
type SerializedEdgeDef = Readonly<{
|
|
221
|
+
kind: string;
|
|
222
|
+
fromKinds: readonly string[];
|
|
223
|
+
toKinds: readonly string[];
|
|
224
|
+
properties: JsonSchema;
|
|
225
|
+
cardinality: Cardinality;
|
|
226
|
+
endpointExistence: EndpointExistence;
|
|
227
|
+
description: string | undefined;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Complete serialized schema document.
|
|
231
|
+
*
|
|
232
|
+
* This is the format stored in the schema_doc column of
|
|
233
|
+
* typegraph_schema_versions.
|
|
234
|
+
*/
|
|
235
|
+
type SerializedSchema = Readonly<{
|
|
236
|
+
graphId: string;
|
|
237
|
+
version: number;
|
|
238
|
+
generatedAt: string;
|
|
239
|
+
nodes: Record<string, SerializedNodeDef>;
|
|
240
|
+
edges: Record<string, SerializedEdgeDef>;
|
|
241
|
+
ontology: SerializedOntology;
|
|
242
|
+
defaults: Readonly<{
|
|
243
|
+
onNodeDelete: DeleteBehavior;
|
|
244
|
+
temporalMode: TemporalMode;
|
|
245
|
+
}>;
|
|
246
|
+
}>;
|
|
247
|
+
/**
|
|
248
|
+
* A schema hash for detecting changes.
|
|
249
|
+
*
|
|
250
|
+
* We hash the schema content (excluding version and generatedAt)
|
|
251
|
+
* to detect if the schema has actually changed.
|
|
252
|
+
*/
|
|
253
|
+
type SchemaHash = string;
|
|
254
|
+
|
|
4
255
|
/**
|
|
5
256
|
* Backend interface types for TypeGraph storage.
|
|
6
257
|
*
|
|
@@ -30,7 +281,6 @@ type VectorCapabilities = Readonly<{
|
|
|
30
281
|
maxDimensions: number;
|
|
31
282
|
}>;
|
|
32
283
|
|
|
33
|
-
type Dialect = SqlDialect;
|
|
34
284
|
/**
|
|
35
285
|
* Backend capabilities that vary by dialect.
|
|
36
286
|
*/
|
|
@@ -174,6 +424,7 @@ type UpdateEdgeParams = Readonly<{
|
|
|
174
424
|
id: string;
|
|
175
425
|
props: Record<string, unknown>;
|
|
176
426
|
validTo?: string;
|
|
427
|
+
clearDeleted?: boolean;
|
|
177
428
|
}>;
|
|
178
429
|
/**
|
|
179
430
|
* Parameters for deleting an edge (soft delete).
|
|
@@ -234,6 +485,10 @@ type VectorSearchParams = Readonly<{
|
|
|
234
485
|
*/
|
|
235
486
|
type VectorSearchResult = Readonly<{
|
|
236
487
|
nodeId: string;
|
|
488
|
+
/**
|
|
489
|
+
* Cosine metric returns similarity score (higher is better).
|
|
490
|
+
* L2 and inner_product return raw distance (lower is better).
|
|
491
|
+
*/
|
|
237
492
|
score: number;
|
|
238
493
|
}>;
|
|
239
494
|
/**
|
|
@@ -284,19 +539,29 @@ type TransactionBackend = Omit<GraphBackend, "transaction" | "close">;
|
|
|
284
539
|
*/
|
|
285
540
|
type GraphBackend = Readonly<{
|
|
286
541
|
/** The SQL dialect */
|
|
287
|
-
dialect:
|
|
542
|
+
dialect: SqlDialect;
|
|
288
543
|
/** Backend capabilities */
|
|
289
544
|
capabilities: BackendCapabilities;
|
|
545
|
+
/** Table names used by this backend (for query schema auto-derivation) */
|
|
546
|
+
tableNames?: SqlTableNames | undefined;
|
|
290
547
|
insertNode: (params: InsertNodeParams) => Promise<NodeRow>;
|
|
548
|
+
insertNodeNoReturn?: (params: InsertNodeParams) => Promise<void>;
|
|
549
|
+
insertNodesBatch?: (params: readonly InsertNodeParams[]) => Promise<void>;
|
|
550
|
+
insertNodesBatchReturning?: (params: readonly InsertNodeParams[]) => Promise<readonly NodeRow[]>;
|
|
291
551
|
updateNode: (params: UpdateNodeParams) => Promise<NodeRow>;
|
|
292
552
|
deleteNode: (params: DeleteNodeParams) => Promise<void>;
|
|
293
553
|
hardDeleteNode: (params: HardDeleteNodeParams) => Promise<void>;
|
|
294
554
|
getNode: (graphId: string, kind: string, id: string) => Promise<NodeRow | undefined>;
|
|
555
|
+
getNodes?: (graphId: string, kind: string, ids: readonly string[]) => Promise<readonly NodeRow[]>;
|
|
295
556
|
insertEdge: (params: InsertEdgeParams) => Promise<EdgeRow>;
|
|
557
|
+
insertEdgeNoReturn?: (params: InsertEdgeParams) => Promise<void>;
|
|
558
|
+
insertEdgesBatch?: (params: readonly InsertEdgeParams[]) => Promise<void>;
|
|
559
|
+
insertEdgesBatchReturning?: (params: readonly InsertEdgeParams[]) => Promise<readonly EdgeRow[]>;
|
|
296
560
|
updateEdge: (params: UpdateEdgeParams) => Promise<EdgeRow>;
|
|
297
561
|
deleteEdge: (params: DeleteEdgeParams) => Promise<void>;
|
|
298
562
|
hardDeleteEdge: (params: HardDeleteEdgeParams) => Promise<void>;
|
|
299
563
|
getEdge: (graphId: string, id: string) => Promise<EdgeRow | undefined>;
|
|
564
|
+
getEdges?: (graphId: string, ids: readonly string[]) => Promise<readonly EdgeRow[]>;
|
|
300
565
|
countEdgesFrom: (params: CountEdgesFromParams) => Promise<number>;
|
|
301
566
|
edgeExistsBetween: (params: EdgeExistsBetweenParams) => Promise<boolean>;
|
|
302
567
|
findEdgesConnectedTo: (params: FindEdgesConnectedToParams) => Promise<readonly EdgeRow[]>;
|
|
@@ -318,6 +583,13 @@ type GraphBackend = Readonly<{
|
|
|
318
583
|
createVectorIndex?: (params: CreateVectorIndexParams) => Promise<void>;
|
|
319
584
|
dropVectorIndex?: (params: DropVectorIndexParams) => Promise<void>;
|
|
320
585
|
execute: <T>(query: SQL) => Promise<readonly T[]>;
|
|
586
|
+
/** Execute pre-compiled SQL text with bound parameters. Available on sync SQLite and pg backends. */
|
|
587
|
+
executeRaw?: <T>(sqlText: string, params: readonly unknown[]) => Promise<readonly T[]>;
|
|
588
|
+
/** Compile a Drizzle SQL object to { sql, params } without executing. */
|
|
589
|
+
compileSql?: (query: SQL) => Readonly<{
|
|
590
|
+
sql: string;
|
|
591
|
+
params: readonly unknown[];
|
|
592
|
+
}>;
|
|
321
593
|
transaction: <T>(fn: (tx: TransactionBackend) => Promise<T>, options?: TransactionOptions) => Promise<T>;
|
|
322
594
|
close: () => Promise<void>;
|
|
323
595
|
}>;
|
|
@@ -357,7 +629,7 @@ type InsertSchemaParams = Readonly<{
|
|
|
357
629
|
graphId: string;
|
|
358
630
|
version: number;
|
|
359
631
|
schemaHash: string;
|
|
360
|
-
schemaDoc:
|
|
632
|
+
schemaDoc: SerializedSchema;
|
|
361
633
|
isActive: boolean;
|
|
362
634
|
}>;
|
|
363
635
|
/**
|
|
@@ -400,6 +672,10 @@ type FindNodesByKindParams = Readonly<{
|
|
|
400
672
|
offset?: number;
|
|
401
673
|
/** If true, exclude deleted nodes. Default true. */
|
|
402
674
|
excludeDeleted?: boolean;
|
|
675
|
+
/** Temporal mode for filtering by validity period. */
|
|
676
|
+
temporalMode?: TemporalMode;
|
|
677
|
+
/** Timestamp for "current" and "asOf" temporal modes. */
|
|
678
|
+
asOf?: string;
|
|
403
679
|
}>;
|
|
404
680
|
/**
|
|
405
681
|
* Parameters for counting nodes by kind.
|
|
@@ -409,6 +685,10 @@ type CountNodesByKindParams = Readonly<{
|
|
|
409
685
|
kind: string;
|
|
410
686
|
/** If true, exclude deleted nodes. Default true. */
|
|
411
687
|
excludeDeleted?: boolean;
|
|
688
|
+
/** Temporal mode for filtering by validity period. */
|
|
689
|
+
temporalMode?: TemporalMode;
|
|
690
|
+
/** Timestamp for "current" and "asOf" temporal modes. */
|
|
691
|
+
asOf?: string;
|
|
412
692
|
}>;
|
|
413
693
|
/**
|
|
414
694
|
* Parameters for finding edges by kind.
|
|
@@ -424,6 +704,10 @@ type FindEdgesByKindParams = Readonly<{
|
|
|
424
704
|
offset?: number;
|
|
425
705
|
/** If true, exclude deleted edges. Default true. */
|
|
426
706
|
excludeDeleted?: boolean;
|
|
707
|
+
/** Temporal mode for filtering by validity period. */
|
|
708
|
+
temporalMode?: TemporalMode;
|
|
709
|
+
/** Timestamp for "current" and "asOf" temporal modes. */
|
|
710
|
+
asOf?: string;
|
|
427
711
|
}>;
|
|
428
712
|
/**
|
|
429
713
|
* Parameters for counting edges by kind.
|
|
@@ -437,6 +721,10 @@ type CountEdgesByKindParams = Readonly<{
|
|
|
437
721
|
toId?: string;
|
|
438
722
|
/** If true, exclude deleted edges. Default true. */
|
|
439
723
|
excludeDeleted?: boolean;
|
|
724
|
+
/** Temporal mode for filtering by validity period. */
|
|
725
|
+
temporalMode?: TemporalMode;
|
|
726
|
+
/** Timestamp for "current" and "asOf" temporal modes. */
|
|
727
|
+
asOf?: string;
|
|
440
728
|
}>;
|
|
441
729
|
|
|
442
|
-
export type
|
|
730
|
+
export { DEFAULT_SQL_SCHEMA as D, type GraphBackend as G, type InferenceType as I, type JsonSchema as J, type MetaEdge as M, type OntologyRelation as O, type SerializedNodeDef as S, type TransactionBackend as T, type SerializedEdgeDef as a, type SerializedMetaEdge as b, type SerializedOntologyRelation as c, type SerializedClosures as d, type SerializedSchema as e, type SchemaHash as f, type SerializedOntology as g, type SerializedUniqueConstraint as h, type SchemaVersionRow as i, type MetaEdgeProperties as j, type SqlSchema as k, type SqlTableNames as l, createSqlSchema as m, isMetaEdge as n };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { A as AnyEdgeType, E as EdgeType,
|
|
2
|
+
import { A as AnyEdgeType, E as EdgeType, N as NodeType } from './types-DTJEu_-h.cjs';
|
|
3
|
+
import { J as JsonPointer, V as ValueType, a as JsonPointerFor, b as JsonPointerSegmentsFor } from './ast-D-3bOanX.cjs';
|
|
3
4
|
|
|
4
5
|
type IndexScope =
|
|
5
6
|
/**
|
|
@@ -122,7 +123,7 @@ type EdgeIndexConfig<E extends AnyEdgeType> = Readonly<{
|
|
|
122
123
|
type NodeIndex<N extends NodeType = NodeType> = Readonly<{
|
|
123
124
|
__type: "typegraph_node_index";
|
|
124
125
|
node: N;
|
|
125
|
-
nodeKind: N["
|
|
126
|
+
nodeKind: N["kind"];
|
|
126
127
|
fields: readonly JsonPointer[];
|
|
127
128
|
fieldValueTypes: readonly (ValueType | undefined)[];
|
|
128
129
|
coveringFields: readonly JsonPointer[];
|
|
@@ -135,7 +136,7 @@ type NodeIndex<N extends NodeType = NodeType> = Readonly<{
|
|
|
135
136
|
type EdgeIndex<E extends AnyEdgeType = EdgeType> = Readonly<{
|
|
136
137
|
__type: "typegraph_edge_index";
|
|
137
138
|
edge: E;
|
|
138
|
-
edgeKind: E["
|
|
139
|
+
edgeKind: E["kind"];
|
|
139
140
|
fields: readonly JsonPointer[];
|
|
140
141
|
fieldValueTypes: readonly (ValueType | undefined)[];
|
|
141
142
|
coveringFields: readonly JsonPointer[];
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Brand key for NodeType */
|
|
4
|
+
declare const NODE_TYPE_BRAND: "__nodeType";
|
|
5
|
+
/** Brand key for EdgeType */
|
|
6
|
+
declare const EDGE_TYPE_BRAND: "__edgeType";
|
|
7
|
+
/** Brand symbol for NodeId */
|
|
8
|
+
declare const __nodeId: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* A node type definition.
|
|
11
|
+
*
|
|
12
|
+
* Created via `defineNode()`. Represents a type of node in the graph
|
|
13
|
+
* with an associated Zod schema for properties.
|
|
14
|
+
*/
|
|
15
|
+
type NodeType<K extends string = string, S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = Readonly<{
|
|
16
|
+
[NODE_TYPE_BRAND]: true;
|
|
17
|
+
kind: K;
|
|
18
|
+
schema: S;
|
|
19
|
+
description: string | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Branded node ID type.
|
|
23
|
+
*
|
|
24
|
+
* Prevents mixing IDs from different node types at compile time.
|
|
25
|
+
*/
|
|
26
|
+
type NodeId<N extends NodeType> = string & Readonly<{
|
|
27
|
+
[__nodeId]: N;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Infer the props type from a NodeType.
|
|
31
|
+
*/
|
|
32
|
+
type NodeProps<N extends NodeType> = z.infer<N["schema"]>;
|
|
33
|
+
/**
|
|
34
|
+
* An edge type definition.
|
|
35
|
+
*
|
|
36
|
+
* Created via `defineEdge()`. Represents a type of edge in the graph
|
|
37
|
+
* with an optional Zod schema for properties.
|
|
38
|
+
*
|
|
39
|
+
* Optionally includes `from` and `to` arrays that define the allowed
|
|
40
|
+
* source and target node types (domain and range constraints).
|
|
41
|
+
*/
|
|
42
|
+
type EdgeType<K extends string = string, S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, From extends readonly NodeType[] | undefined = undefined, To extends readonly NodeType[] | undefined = undefined> = Readonly<{
|
|
43
|
+
[EDGE_TYPE_BRAND]: true;
|
|
44
|
+
kind: K;
|
|
45
|
+
schema: S;
|
|
46
|
+
description: string | undefined;
|
|
47
|
+
from: From;
|
|
48
|
+
to: To;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Base edge type for use in constraints - accepts any from/to configuration.
|
|
52
|
+
*/
|
|
53
|
+
type AnyEdgeType = EdgeType<string, z.ZodObject<z.ZodRawShape>, readonly NodeType[] | undefined, readonly NodeType[] | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* An edge type that has both from and to constraints defined.
|
|
56
|
+
* Can be used directly in defineGraph without an EdgeRegistration wrapper.
|
|
57
|
+
*/
|
|
58
|
+
type EdgeTypeWithEndpoints = EdgeType<string, z.ZodObject<z.ZodRawShape>, readonly NodeType[], readonly NodeType[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Infer the props type from an EdgeType.
|
|
61
|
+
*/
|
|
62
|
+
type EdgeProps<E extends AnyEdgeType> = z.infer<E["schema"]>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete behaviors for nodes.
|
|
65
|
+
*/
|
|
66
|
+
type DeleteBehavior = "restrict" | "cascade" | "disconnect";
|
|
67
|
+
/**
|
|
68
|
+
* Edge cardinality constraints.
|
|
69
|
+
*/
|
|
70
|
+
type Cardinality = "many" | "one" | "unique" | "oneActive";
|
|
71
|
+
/**
|
|
72
|
+
* Endpoint existence modes for edge validation.
|
|
73
|
+
*/
|
|
74
|
+
type EndpointExistence = "notDeleted" | "currentlyValid" | "ever";
|
|
75
|
+
/**
|
|
76
|
+
* Temporal query modes.
|
|
77
|
+
*/
|
|
78
|
+
type TemporalMode = "current" | "asOf" | "includeEnded" | "includeTombstones";
|
|
79
|
+
/**
|
|
80
|
+
* Uniqueness constraint scope.
|
|
81
|
+
*/
|
|
82
|
+
type UniquenessScope = "kind" | "kindWithSubClasses";
|
|
83
|
+
/**
|
|
84
|
+
* Collation for uniqueness constraints.
|
|
85
|
+
*/
|
|
86
|
+
type Collation = "binary" | "caseInsensitive";
|
|
87
|
+
/**
|
|
88
|
+
* Uniqueness constraint definition.
|
|
89
|
+
*/
|
|
90
|
+
type UniqueConstraint<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = Readonly<{
|
|
91
|
+
name: string;
|
|
92
|
+
fields: readonly (keyof z.infer<S> & string)[];
|
|
93
|
+
where?: (props: UniqueConstraintPredicateBuilder<S>) => UniqueConstraintPredicate;
|
|
94
|
+
scope: UniquenessScope;
|
|
95
|
+
collation: Collation;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Predicate builder for uniqueness constraint where clause.
|
|
99
|
+
* Uses -? to make all fields required in the builder, even if optional in the schema.
|
|
100
|
+
*/
|
|
101
|
+
type UniqueConstraintPredicateBuilder<S extends z.ZodObject<z.ZodRawShape>> = Readonly<{
|
|
102
|
+
[K in keyof z.infer<S>]-?: UniqueConstraintField;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Field operations for uniqueness constraint predicates.
|
|
106
|
+
*/
|
|
107
|
+
type UniqueConstraintField = Readonly<{
|
|
108
|
+
isNull: () => UniqueConstraintPredicate;
|
|
109
|
+
isNotNull: () => UniqueConstraintPredicate;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* A uniqueness constraint predicate (internal representation).
|
|
113
|
+
*/
|
|
114
|
+
type UniqueConstraintPredicate = Readonly<{
|
|
115
|
+
__type: "unique_predicate";
|
|
116
|
+
field: string;
|
|
117
|
+
op: "isNull" | "isNotNull";
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Node registration in a graph definition.
|
|
121
|
+
*/
|
|
122
|
+
type NodeRegistration<N extends NodeType = NodeType> = Readonly<{
|
|
123
|
+
type: N;
|
|
124
|
+
unique?: readonly UniqueConstraint<N["schema"]>[];
|
|
125
|
+
onDelete?: DeleteBehavior;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Edge registration in a graph definition.
|
|
129
|
+
*/
|
|
130
|
+
type EdgeRegistration<E extends AnyEdgeType = AnyEdgeType, FromTypes extends NodeType = NodeType, ToTypes extends NodeType = NodeType> = Readonly<{
|
|
131
|
+
type: E;
|
|
132
|
+
from: readonly FromTypes[];
|
|
133
|
+
to: readonly ToTypes[];
|
|
134
|
+
cardinality?: Cardinality;
|
|
135
|
+
endpointExistence?: EndpointExistence;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Default settings for a graph.
|
|
139
|
+
*/
|
|
140
|
+
type GraphDefaults = Readonly<{
|
|
141
|
+
onNodeDelete?: DeleteBehavior;
|
|
142
|
+
temporalMode?: TemporalMode;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a value is a NodeType.
|
|
146
|
+
*/
|
|
147
|
+
declare function isNodeType(value: unknown): value is NodeType;
|
|
148
|
+
/**
|
|
149
|
+
* Checks if a value is an EdgeType.
|
|
150
|
+
*/
|
|
151
|
+
declare function isEdgeType(value: unknown): value is AnyEdgeType;
|
|
152
|
+
/**
|
|
153
|
+
* Checks if a value is an EdgeType with both from and to constraints defined.
|
|
154
|
+
* Such edges can be used directly in defineGraph without an EdgeRegistration wrapper.
|
|
155
|
+
*/
|
|
156
|
+
declare function isEdgeTypeWithEndpoints(value: unknown): value is EdgeTypeWithEndpoints;
|
|
157
|
+
|
|
158
|
+
export { type AnyEdgeType as A, type Collation as C, type DeleteBehavior as D, type EdgeType as E, type GraphDefaults as G, type NodeType as N, type TemporalMode as T, type UniquenessScope as U, type NodeRegistration as a, type EdgeRegistration as b, type EdgeTypeWithEndpoints as c, type Cardinality as d, type EndpointExistence as e, type EdgeProps as f, type NodeId as g, type NodeProps as h, type UniqueConstraint as i, isEdgeType as j, isEdgeTypeWithEndpoints as k, isNodeType as l };
|