@wiscale/velesdb-sdk 1.1.1 → 1.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/dist/index.d.mts +257 -1
- package/dist/index.d.ts +257 -1
- package/dist/index.js +406 -5
- package/dist/index.mjs +406 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -104,6 +104,117 @@ interface SearchResult {
|
|
|
104
104
|
/** Vector data (if includeVectors is true) */
|
|
105
105
|
vector?: number[];
|
|
106
106
|
}
|
|
107
|
+
/** Graph edge representing a relationship between nodes */
|
|
108
|
+
interface GraphEdge {
|
|
109
|
+
/** Unique edge ID */
|
|
110
|
+
id: number;
|
|
111
|
+
/** Source node ID */
|
|
112
|
+
source: number;
|
|
113
|
+
/** Target node ID */
|
|
114
|
+
target: number;
|
|
115
|
+
/** Edge label (relationship type, e.g., "KNOWS", "FOLLOWS") */
|
|
116
|
+
label: string;
|
|
117
|
+
/** Edge properties */
|
|
118
|
+
properties?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
/** Request to add an edge to the graph */
|
|
121
|
+
interface AddEdgeRequest {
|
|
122
|
+
/** Unique edge ID */
|
|
123
|
+
id: number;
|
|
124
|
+
/** Source node ID */
|
|
125
|
+
source: number;
|
|
126
|
+
/** Target node ID */
|
|
127
|
+
target: number;
|
|
128
|
+
/** Edge label (relationship type) */
|
|
129
|
+
label: string;
|
|
130
|
+
/** Edge properties (optional) */
|
|
131
|
+
properties?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** Response containing edges */
|
|
134
|
+
interface EdgesResponse {
|
|
135
|
+
/** List of edges */
|
|
136
|
+
edges: GraphEdge[];
|
|
137
|
+
/** Total count of edges returned */
|
|
138
|
+
count: number;
|
|
139
|
+
}
|
|
140
|
+
/** Options for querying edges */
|
|
141
|
+
interface GetEdgesOptions {
|
|
142
|
+
/** Filter by edge label */
|
|
143
|
+
label?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Request for graph traversal (EPIC-016 US-050) */
|
|
146
|
+
interface TraverseRequest {
|
|
147
|
+
/** Source node ID to start traversal from */
|
|
148
|
+
source: number;
|
|
149
|
+
/** Traversal strategy: 'bfs' or 'dfs' */
|
|
150
|
+
strategy?: 'bfs' | 'dfs';
|
|
151
|
+
/** Maximum traversal depth */
|
|
152
|
+
maxDepth?: number;
|
|
153
|
+
/** Maximum number of results to return */
|
|
154
|
+
limit?: number;
|
|
155
|
+
/** Optional cursor for pagination */
|
|
156
|
+
cursor?: string;
|
|
157
|
+
/** Filter by relationship types (empty = all types) */
|
|
158
|
+
relTypes?: string[];
|
|
159
|
+
}
|
|
160
|
+
/** A single traversal result item */
|
|
161
|
+
interface TraversalResultItem {
|
|
162
|
+
/** Target node ID reached */
|
|
163
|
+
targetId: number;
|
|
164
|
+
/** Depth of traversal (number of hops from source) */
|
|
165
|
+
depth: number;
|
|
166
|
+
/** Path taken (list of edge IDs) */
|
|
167
|
+
path: number[];
|
|
168
|
+
}
|
|
169
|
+
/** Statistics from traversal operation */
|
|
170
|
+
interface TraversalStats {
|
|
171
|
+
/** Number of nodes visited */
|
|
172
|
+
visited: number;
|
|
173
|
+
/** Maximum depth reached */
|
|
174
|
+
depthReached: number;
|
|
175
|
+
}
|
|
176
|
+
/** Response from graph traversal */
|
|
177
|
+
interface TraverseResponse {
|
|
178
|
+
/** List of traversal results */
|
|
179
|
+
results: TraversalResultItem[];
|
|
180
|
+
/** Cursor for next page (if applicable) */
|
|
181
|
+
nextCursor?: string;
|
|
182
|
+
/** Whether more results are available */
|
|
183
|
+
hasMore: boolean;
|
|
184
|
+
/** Traversal statistics */
|
|
185
|
+
stats: TraversalStats;
|
|
186
|
+
}
|
|
187
|
+
/** Response for node degree query */
|
|
188
|
+
interface DegreeResponse {
|
|
189
|
+
/** Number of incoming edges */
|
|
190
|
+
inDegree: number;
|
|
191
|
+
/** Number of outgoing edges */
|
|
192
|
+
outDegree: number;
|
|
193
|
+
}
|
|
194
|
+
/** Index type for property indexes */
|
|
195
|
+
type IndexType = 'hash' | 'range';
|
|
196
|
+
/** Index information */
|
|
197
|
+
interface IndexInfo {
|
|
198
|
+
/** Node label (e.g., "Person") */
|
|
199
|
+
label: string;
|
|
200
|
+
/** Property name (e.g., "email") */
|
|
201
|
+
property: string;
|
|
202
|
+
/** Index type: 'hash' for O(1) equality, 'range' for O(log n) range queries */
|
|
203
|
+
indexType: IndexType;
|
|
204
|
+
/** Number of unique values indexed (for hash indexes) */
|
|
205
|
+
cardinality: number;
|
|
206
|
+
/** Memory usage in bytes */
|
|
207
|
+
memoryBytes: number;
|
|
208
|
+
}
|
|
209
|
+
/** Options for creating an index */
|
|
210
|
+
interface CreateIndexOptions {
|
|
211
|
+
/** Node label to index */
|
|
212
|
+
label: string;
|
|
213
|
+
/** Property name to index */
|
|
214
|
+
property: string;
|
|
215
|
+
/** Index type: 'hash' (default) or 'range' */
|
|
216
|
+
indexType?: IndexType;
|
|
217
|
+
}
|
|
107
218
|
/** Backend interface that all backends must implement */
|
|
108
219
|
interface IVelesDBBackend {
|
|
109
220
|
/** Initialize the backend */
|
|
@@ -155,6 +266,22 @@ interface IVelesDBBackend {
|
|
|
155
266
|
flush(collection: string): Promise<void>;
|
|
156
267
|
/** Close/cleanup the backend */
|
|
157
268
|
close(): Promise<void>;
|
|
269
|
+
/** Create a property index for O(1) equality lookups */
|
|
270
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
271
|
+
/** List all indexes on a collection */
|
|
272
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
273
|
+
/** Check if an index exists */
|
|
274
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
275
|
+
/** Drop an index */
|
|
276
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
277
|
+
/** Add an edge to the collection's knowledge graph */
|
|
278
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
279
|
+
/** Get edges from the collection's knowledge graph */
|
|
280
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
281
|
+
/** Traverse the graph using BFS or DFS from a source node */
|
|
282
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
283
|
+
/** Get the in-degree and out-degree of a node */
|
|
284
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
158
285
|
}
|
|
159
286
|
/** Error types */
|
|
160
287
|
declare class VelesDBError extends Error {
|
|
@@ -391,6 +518,117 @@ declare class VelesDB {
|
|
|
391
518
|
* Get the current backend type
|
|
392
519
|
*/
|
|
393
520
|
get backendType(): string;
|
|
521
|
+
/**
|
|
522
|
+
* Create a property index for O(1) equality lookups or O(log n) range queries
|
|
523
|
+
*
|
|
524
|
+
* @param collection - Collection name
|
|
525
|
+
* @param options - Index configuration (label, property, indexType)
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```typescript
|
|
529
|
+
* // Create hash index for fast email lookups
|
|
530
|
+
* await db.createIndex('users', { label: 'Person', property: 'email' });
|
|
531
|
+
*
|
|
532
|
+
* // Create range index for timestamp queries
|
|
533
|
+
* await db.createIndex('events', { label: 'Event', property: 'timestamp', indexType: 'range' });
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
537
|
+
/**
|
|
538
|
+
* List all indexes on a collection
|
|
539
|
+
*
|
|
540
|
+
* @param collection - Collection name
|
|
541
|
+
* @returns Array of index information
|
|
542
|
+
*/
|
|
543
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
544
|
+
/**
|
|
545
|
+
* Check if an index exists
|
|
546
|
+
*
|
|
547
|
+
* @param collection - Collection name
|
|
548
|
+
* @param label - Node label
|
|
549
|
+
* @param property - Property name
|
|
550
|
+
* @returns true if index exists
|
|
551
|
+
*/
|
|
552
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
553
|
+
/**
|
|
554
|
+
* Drop an index
|
|
555
|
+
*
|
|
556
|
+
* @param collection - Collection name
|
|
557
|
+
* @param label - Node label
|
|
558
|
+
* @param property - Property name
|
|
559
|
+
* @returns true if index was dropped, false if it didn't exist
|
|
560
|
+
*/
|
|
561
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
562
|
+
/**
|
|
563
|
+
* Add an edge to the collection's knowledge graph
|
|
564
|
+
*
|
|
565
|
+
* @param collection - Collection name
|
|
566
|
+
* @param edge - Edge to add (id, source, target, label, properties)
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* await db.addEdge('social', {
|
|
571
|
+
* id: 1,
|
|
572
|
+
* source: 100,
|
|
573
|
+
* target: 200,
|
|
574
|
+
* label: 'FOLLOWS',
|
|
575
|
+
* properties: { since: '2024-01-01' }
|
|
576
|
+
* });
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
580
|
+
/**
|
|
581
|
+
* Get edges from the collection's knowledge graph
|
|
582
|
+
*
|
|
583
|
+
* @param collection - Collection name
|
|
584
|
+
* @param options - Query options (filter by label)
|
|
585
|
+
* @returns Array of edges
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```typescript
|
|
589
|
+
* // Get all edges with label "FOLLOWS"
|
|
590
|
+
* const edges = await db.getEdges('social', { label: 'FOLLOWS' });
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Traverse the graph using BFS or DFS from a source node
|
|
596
|
+
*
|
|
597
|
+
* @param collection - Collection name
|
|
598
|
+
* @param request - Traversal request options
|
|
599
|
+
* @returns Traversal response with results and stats
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* // BFS traversal from node 100
|
|
604
|
+
* const result = await db.traverseGraph('social', {
|
|
605
|
+
* source: 100,
|
|
606
|
+
* strategy: 'bfs',
|
|
607
|
+
* maxDepth: 3,
|
|
608
|
+
* limit: 100,
|
|
609
|
+
* relTypes: ['FOLLOWS', 'KNOWS']
|
|
610
|
+
* });
|
|
611
|
+
*
|
|
612
|
+
* for (const node of result.results) {
|
|
613
|
+
* console.log(`Reached node ${node.targetId} at depth ${node.depth}`);
|
|
614
|
+
* }
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
618
|
+
/**
|
|
619
|
+
* Get the in-degree and out-degree of a node
|
|
620
|
+
*
|
|
621
|
+
* @param collection - Collection name
|
|
622
|
+
* @param nodeId - Node ID
|
|
623
|
+
* @returns Degree response with inDegree and outDegree
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const degree = await db.getNodeDegree('social', 100);
|
|
628
|
+
* console.log(`In: ${degree.inDegree}, Out: ${degree.outDegree}`);
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
394
632
|
}
|
|
395
633
|
|
|
396
634
|
/**
|
|
@@ -441,6 +679,14 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
441
679
|
flush(collectionName: string): Promise<void>;
|
|
442
680
|
close(): Promise<void>;
|
|
443
681
|
private toNumericId;
|
|
682
|
+
createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
|
|
683
|
+
listIndexes(_collection: string): Promise<IndexInfo[]>;
|
|
684
|
+
hasIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
685
|
+
dropIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
686
|
+
addEdge(_collection: string, _edge: AddEdgeRequest): Promise<void>;
|
|
687
|
+
getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
688
|
+
traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
|
|
689
|
+
getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
|
|
444
690
|
}
|
|
445
691
|
|
|
446
692
|
/**
|
|
@@ -463,6 +709,8 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
463
709
|
init(): Promise<void>;
|
|
464
710
|
isInitialized(): boolean;
|
|
465
711
|
private ensureInitialized;
|
|
712
|
+
private mapStatusToErrorCode;
|
|
713
|
+
private extractErrorPayload;
|
|
466
714
|
private request;
|
|
467
715
|
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
|
468
716
|
deleteCollection(name: string): Promise<void>;
|
|
@@ -492,6 +740,14 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
492
740
|
isEmpty(collection: string): Promise<boolean>;
|
|
493
741
|
flush(collection: string): Promise<void>;
|
|
494
742
|
close(): Promise<void>;
|
|
743
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
744
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
745
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
746
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
747
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
748
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
749
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
750
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
495
751
|
}
|
|
496
752
|
|
|
497
|
-
export { type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type DistanceMetric, type FusionStrategy, type IVelesDBBackend, type MultiQuerySearchOptions, NotFoundError, RestBackend, type SearchOptions, type SearchResult, type StorageMode, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, WasmBackend };
|
|
753
|
+
export { type AddEdgeRequest, type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type CreateIndexOptions, type DegreeResponse, type DistanceMetric, type EdgesResponse, type FusionStrategy, type GetEdgesOptions, type GraphEdge, type IVelesDBBackend, type IndexInfo, type IndexType, type MultiQuerySearchOptions, NotFoundError, RestBackend, type SearchOptions, type SearchResult, type StorageMode, type TraversalResultItem, type TraversalStats, type TraverseRequest, type TraverseResponse, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, WasmBackend };
|
package/dist/index.d.ts
CHANGED
|
@@ -104,6 +104,117 @@ interface SearchResult {
|
|
|
104
104
|
/** Vector data (if includeVectors is true) */
|
|
105
105
|
vector?: number[];
|
|
106
106
|
}
|
|
107
|
+
/** Graph edge representing a relationship between nodes */
|
|
108
|
+
interface GraphEdge {
|
|
109
|
+
/** Unique edge ID */
|
|
110
|
+
id: number;
|
|
111
|
+
/** Source node ID */
|
|
112
|
+
source: number;
|
|
113
|
+
/** Target node ID */
|
|
114
|
+
target: number;
|
|
115
|
+
/** Edge label (relationship type, e.g., "KNOWS", "FOLLOWS") */
|
|
116
|
+
label: string;
|
|
117
|
+
/** Edge properties */
|
|
118
|
+
properties?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
/** Request to add an edge to the graph */
|
|
121
|
+
interface AddEdgeRequest {
|
|
122
|
+
/** Unique edge ID */
|
|
123
|
+
id: number;
|
|
124
|
+
/** Source node ID */
|
|
125
|
+
source: number;
|
|
126
|
+
/** Target node ID */
|
|
127
|
+
target: number;
|
|
128
|
+
/** Edge label (relationship type) */
|
|
129
|
+
label: string;
|
|
130
|
+
/** Edge properties (optional) */
|
|
131
|
+
properties?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** Response containing edges */
|
|
134
|
+
interface EdgesResponse {
|
|
135
|
+
/** List of edges */
|
|
136
|
+
edges: GraphEdge[];
|
|
137
|
+
/** Total count of edges returned */
|
|
138
|
+
count: number;
|
|
139
|
+
}
|
|
140
|
+
/** Options for querying edges */
|
|
141
|
+
interface GetEdgesOptions {
|
|
142
|
+
/** Filter by edge label */
|
|
143
|
+
label?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Request for graph traversal (EPIC-016 US-050) */
|
|
146
|
+
interface TraverseRequest {
|
|
147
|
+
/** Source node ID to start traversal from */
|
|
148
|
+
source: number;
|
|
149
|
+
/** Traversal strategy: 'bfs' or 'dfs' */
|
|
150
|
+
strategy?: 'bfs' | 'dfs';
|
|
151
|
+
/** Maximum traversal depth */
|
|
152
|
+
maxDepth?: number;
|
|
153
|
+
/** Maximum number of results to return */
|
|
154
|
+
limit?: number;
|
|
155
|
+
/** Optional cursor for pagination */
|
|
156
|
+
cursor?: string;
|
|
157
|
+
/** Filter by relationship types (empty = all types) */
|
|
158
|
+
relTypes?: string[];
|
|
159
|
+
}
|
|
160
|
+
/** A single traversal result item */
|
|
161
|
+
interface TraversalResultItem {
|
|
162
|
+
/** Target node ID reached */
|
|
163
|
+
targetId: number;
|
|
164
|
+
/** Depth of traversal (number of hops from source) */
|
|
165
|
+
depth: number;
|
|
166
|
+
/** Path taken (list of edge IDs) */
|
|
167
|
+
path: number[];
|
|
168
|
+
}
|
|
169
|
+
/** Statistics from traversal operation */
|
|
170
|
+
interface TraversalStats {
|
|
171
|
+
/** Number of nodes visited */
|
|
172
|
+
visited: number;
|
|
173
|
+
/** Maximum depth reached */
|
|
174
|
+
depthReached: number;
|
|
175
|
+
}
|
|
176
|
+
/** Response from graph traversal */
|
|
177
|
+
interface TraverseResponse {
|
|
178
|
+
/** List of traversal results */
|
|
179
|
+
results: TraversalResultItem[];
|
|
180
|
+
/** Cursor for next page (if applicable) */
|
|
181
|
+
nextCursor?: string;
|
|
182
|
+
/** Whether more results are available */
|
|
183
|
+
hasMore: boolean;
|
|
184
|
+
/** Traversal statistics */
|
|
185
|
+
stats: TraversalStats;
|
|
186
|
+
}
|
|
187
|
+
/** Response for node degree query */
|
|
188
|
+
interface DegreeResponse {
|
|
189
|
+
/** Number of incoming edges */
|
|
190
|
+
inDegree: number;
|
|
191
|
+
/** Number of outgoing edges */
|
|
192
|
+
outDegree: number;
|
|
193
|
+
}
|
|
194
|
+
/** Index type for property indexes */
|
|
195
|
+
type IndexType = 'hash' | 'range';
|
|
196
|
+
/** Index information */
|
|
197
|
+
interface IndexInfo {
|
|
198
|
+
/** Node label (e.g., "Person") */
|
|
199
|
+
label: string;
|
|
200
|
+
/** Property name (e.g., "email") */
|
|
201
|
+
property: string;
|
|
202
|
+
/** Index type: 'hash' for O(1) equality, 'range' for O(log n) range queries */
|
|
203
|
+
indexType: IndexType;
|
|
204
|
+
/** Number of unique values indexed (for hash indexes) */
|
|
205
|
+
cardinality: number;
|
|
206
|
+
/** Memory usage in bytes */
|
|
207
|
+
memoryBytes: number;
|
|
208
|
+
}
|
|
209
|
+
/** Options for creating an index */
|
|
210
|
+
interface CreateIndexOptions {
|
|
211
|
+
/** Node label to index */
|
|
212
|
+
label: string;
|
|
213
|
+
/** Property name to index */
|
|
214
|
+
property: string;
|
|
215
|
+
/** Index type: 'hash' (default) or 'range' */
|
|
216
|
+
indexType?: IndexType;
|
|
217
|
+
}
|
|
107
218
|
/** Backend interface that all backends must implement */
|
|
108
219
|
interface IVelesDBBackend {
|
|
109
220
|
/** Initialize the backend */
|
|
@@ -155,6 +266,22 @@ interface IVelesDBBackend {
|
|
|
155
266
|
flush(collection: string): Promise<void>;
|
|
156
267
|
/** Close/cleanup the backend */
|
|
157
268
|
close(): Promise<void>;
|
|
269
|
+
/** Create a property index for O(1) equality lookups */
|
|
270
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
271
|
+
/** List all indexes on a collection */
|
|
272
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
273
|
+
/** Check if an index exists */
|
|
274
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
275
|
+
/** Drop an index */
|
|
276
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
277
|
+
/** Add an edge to the collection's knowledge graph */
|
|
278
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
279
|
+
/** Get edges from the collection's knowledge graph */
|
|
280
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
281
|
+
/** Traverse the graph using BFS or DFS from a source node */
|
|
282
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
283
|
+
/** Get the in-degree and out-degree of a node */
|
|
284
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
158
285
|
}
|
|
159
286
|
/** Error types */
|
|
160
287
|
declare class VelesDBError extends Error {
|
|
@@ -391,6 +518,117 @@ declare class VelesDB {
|
|
|
391
518
|
* Get the current backend type
|
|
392
519
|
*/
|
|
393
520
|
get backendType(): string;
|
|
521
|
+
/**
|
|
522
|
+
* Create a property index for O(1) equality lookups or O(log n) range queries
|
|
523
|
+
*
|
|
524
|
+
* @param collection - Collection name
|
|
525
|
+
* @param options - Index configuration (label, property, indexType)
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```typescript
|
|
529
|
+
* // Create hash index for fast email lookups
|
|
530
|
+
* await db.createIndex('users', { label: 'Person', property: 'email' });
|
|
531
|
+
*
|
|
532
|
+
* // Create range index for timestamp queries
|
|
533
|
+
* await db.createIndex('events', { label: 'Event', property: 'timestamp', indexType: 'range' });
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
537
|
+
/**
|
|
538
|
+
* List all indexes on a collection
|
|
539
|
+
*
|
|
540
|
+
* @param collection - Collection name
|
|
541
|
+
* @returns Array of index information
|
|
542
|
+
*/
|
|
543
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
544
|
+
/**
|
|
545
|
+
* Check if an index exists
|
|
546
|
+
*
|
|
547
|
+
* @param collection - Collection name
|
|
548
|
+
* @param label - Node label
|
|
549
|
+
* @param property - Property name
|
|
550
|
+
* @returns true if index exists
|
|
551
|
+
*/
|
|
552
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
553
|
+
/**
|
|
554
|
+
* Drop an index
|
|
555
|
+
*
|
|
556
|
+
* @param collection - Collection name
|
|
557
|
+
* @param label - Node label
|
|
558
|
+
* @param property - Property name
|
|
559
|
+
* @returns true if index was dropped, false if it didn't exist
|
|
560
|
+
*/
|
|
561
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
562
|
+
/**
|
|
563
|
+
* Add an edge to the collection's knowledge graph
|
|
564
|
+
*
|
|
565
|
+
* @param collection - Collection name
|
|
566
|
+
* @param edge - Edge to add (id, source, target, label, properties)
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* await db.addEdge('social', {
|
|
571
|
+
* id: 1,
|
|
572
|
+
* source: 100,
|
|
573
|
+
* target: 200,
|
|
574
|
+
* label: 'FOLLOWS',
|
|
575
|
+
* properties: { since: '2024-01-01' }
|
|
576
|
+
* });
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
580
|
+
/**
|
|
581
|
+
* Get edges from the collection's knowledge graph
|
|
582
|
+
*
|
|
583
|
+
* @param collection - Collection name
|
|
584
|
+
* @param options - Query options (filter by label)
|
|
585
|
+
* @returns Array of edges
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```typescript
|
|
589
|
+
* // Get all edges with label "FOLLOWS"
|
|
590
|
+
* const edges = await db.getEdges('social', { label: 'FOLLOWS' });
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Traverse the graph using BFS or DFS from a source node
|
|
596
|
+
*
|
|
597
|
+
* @param collection - Collection name
|
|
598
|
+
* @param request - Traversal request options
|
|
599
|
+
* @returns Traversal response with results and stats
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* // BFS traversal from node 100
|
|
604
|
+
* const result = await db.traverseGraph('social', {
|
|
605
|
+
* source: 100,
|
|
606
|
+
* strategy: 'bfs',
|
|
607
|
+
* maxDepth: 3,
|
|
608
|
+
* limit: 100,
|
|
609
|
+
* relTypes: ['FOLLOWS', 'KNOWS']
|
|
610
|
+
* });
|
|
611
|
+
*
|
|
612
|
+
* for (const node of result.results) {
|
|
613
|
+
* console.log(`Reached node ${node.targetId} at depth ${node.depth}`);
|
|
614
|
+
* }
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
618
|
+
/**
|
|
619
|
+
* Get the in-degree and out-degree of a node
|
|
620
|
+
*
|
|
621
|
+
* @param collection - Collection name
|
|
622
|
+
* @param nodeId - Node ID
|
|
623
|
+
* @returns Degree response with inDegree and outDegree
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const degree = await db.getNodeDegree('social', 100);
|
|
628
|
+
* console.log(`In: ${degree.inDegree}, Out: ${degree.outDegree}`);
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
394
632
|
}
|
|
395
633
|
|
|
396
634
|
/**
|
|
@@ -441,6 +679,14 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
441
679
|
flush(collectionName: string): Promise<void>;
|
|
442
680
|
close(): Promise<void>;
|
|
443
681
|
private toNumericId;
|
|
682
|
+
createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
|
|
683
|
+
listIndexes(_collection: string): Promise<IndexInfo[]>;
|
|
684
|
+
hasIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
685
|
+
dropIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
686
|
+
addEdge(_collection: string, _edge: AddEdgeRequest): Promise<void>;
|
|
687
|
+
getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
688
|
+
traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
|
|
689
|
+
getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
|
|
444
690
|
}
|
|
445
691
|
|
|
446
692
|
/**
|
|
@@ -463,6 +709,8 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
463
709
|
init(): Promise<void>;
|
|
464
710
|
isInitialized(): boolean;
|
|
465
711
|
private ensureInitialized;
|
|
712
|
+
private mapStatusToErrorCode;
|
|
713
|
+
private extractErrorPayload;
|
|
466
714
|
private request;
|
|
467
715
|
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
|
468
716
|
deleteCollection(name: string): Promise<void>;
|
|
@@ -492,6 +740,14 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
492
740
|
isEmpty(collection: string): Promise<boolean>;
|
|
493
741
|
flush(collection: string): Promise<void>;
|
|
494
742
|
close(): Promise<void>;
|
|
743
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
744
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
745
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
746
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
747
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
748
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
749
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
750
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
495
751
|
}
|
|
496
752
|
|
|
497
|
-
export { type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type DistanceMetric, type FusionStrategy, type IVelesDBBackend, type MultiQuerySearchOptions, NotFoundError, RestBackend, type SearchOptions, type SearchResult, type StorageMode, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, WasmBackend };
|
|
753
|
+
export { type AddEdgeRequest, type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type CreateIndexOptions, type DegreeResponse, type DistanceMetric, type EdgesResponse, type FusionStrategy, type GetEdgesOptions, type GraphEdge, type IVelesDBBackend, type IndexInfo, type IndexType, type MultiQuerySearchOptions, NotFoundError, RestBackend, type SearchOptions, type SearchResult, type StorageMode, type TraversalResultItem, type TraversalStats, type TraverseRequest, type TraverseResponse, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, WasmBackend };
|