@stratadb/core 0.6.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/index.d.ts ADDED
@@ -0,0 +1,536 @@
1
+ /**
2
+ * TypeScript definitions for StrataDB Node.js SDK
3
+ */
4
+
5
+ /** JSON-compatible value type */
6
+ export type JsonValue =
7
+ | null
8
+ | boolean
9
+ | number
10
+ | string
11
+ | JsonValue[]
12
+ | { [key: string]: JsonValue };
13
+
14
+ /** Versioned value returned by history operations */
15
+ export interface VersionedValue {
16
+ value: JsonValue;
17
+ version: number;
18
+ timestamp: number;
19
+ }
20
+
21
+ /** JSON list result with pagination cursor */
22
+ export interface JsonListResult {
23
+ keys: string[];
24
+ cursor?: string;
25
+ }
26
+
27
+ /** Vector collection information */
28
+ export interface CollectionInfo {
29
+ name: string;
30
+ dimension: number;
31
+ metric: string;
32
+ count: number;
33
+ indexType: string;
34
+ memoryBytes: number;
35
+ }
36
+
37
+ /** Vector data with metadata */
38
+ export interface VectorData {
39
+ key: string;
40
+ embedding: number[];
41
+ metadata?: JsonValue;
42
+ version: number;
43
+ timestamp: number;
44
+ }
45
+
46
+ /** Vector search result */
47
+ export interface SearchMatch {
48
+ key: string;
49
+ score: number;
50
+ metadata?: JsonValue;
51
+ }
52
+
53
+ /** Fork operation result */
54
+ export interface ForkResult {
55
+ source: string;
56
+ destination: string;
57
+ keysCopied: number;
58
+ }
59
+
60
+ /** Branch diff summary */
61
+ export interface DiffSummary {
62
+ totalAdded: number;
63
+ totalRemoved: number;
64
+ totalModified: number;
65
+ }
66
+
67
+ /** Branch diff result */
68
+ export interface DiffResult {
69
+ branchA: string;
70
+ branchB: string;
71
+ summary: DiffSummary;
72
+ }
73
+
74
+ /** Merge conflict */
75
+ export interface MergeConflict {
76
+ key: string;
77
+ space: string;
78
+ }
79
+
80
+ /** Merge operation result */
81
+ export interface MergeResult {
82
+ keysApplied: number;
83
+ spacesMerged: number;
84
+ conflicts: MergeConflict[];
85
+ }
86
+
87
+ /** Database information */
88
+ export interface DatabaseInfo {
89
+ version: string;
90
+ uptimeSecs: number;
91
+ branchCount: number;
92
+ totalKeys: number;
93
+ }
94
+
95
+ /** Branch metadata with version info */
96
+ export interface BranchInfo {
97
+ id: string;
98
+ status: string;
99
+ createdAt: number;
100
+ updatedAt: number;
101
+ parentId?: string;
102
+ version: number;
103
+ timestamp: number;
104
+ }
105
+
106
+ /** Branch export result */
107
+ export interface BranchExportResult {
108
+ branchId: string;
109
+ path: string;
110
+ entryCount: number;
111
+ bundleSize: number;
112
+ }
113
+
114
+ /** Branch import result */
115
+ export interface BranchImportResult {
116
+ branchId: string;
117
+ transactionsApplied: number;
118
+ keysWritten: number;
119
+ }
120
+
121
+ /** Bundle validation result */
122
+ export interface BundleValidateResult {
123
+ branchId: string;
124
+ formatVersion: number;
125
+ entryCount: number;
126
+ checksumsValid: boolean;
127
+ }
128
+
129
+ /** Vector entry for batch upsert */
130
+ export interface BatchVectorEntry {
131
+ key: string;
132
+ vector: number[];
133
+ metadata?: JsonValue;
134
+ }
135
+
136
+ /**
137
+ * StrataDB database handle.
138
+ *
139
+ * This is the main entry point for interacting with StrataDB from Node.js.
140
+ */
141
+ export class Strata {
142
+ /**
143
+ * Open a database at the given path.
144
+ * @param path - Path to the database directory
145
+ */
146
+ static open(path: string): Strata;
147
+
148
+ /**
149
+ * Create an in-memory database (no persistence).
150
+ */
151
+ static cache(): Strata;
152
+
153
+ // =========================================================================
154
+ // KV Store
155
+ // =========================================================================
156
+
157
+ /**
158
+ * Store a key-value pair.
159
+ * @param key - The key to store
160
+ * @param value - The value to store
161
+ * @returns Version number
162
+ */
163
+ kvPut(key: string, value: JsonValue): number;
164
+
165
+ /**
166
+ * Get a value by key.
167
+ * @param key - The key to retrieve
168
+ * @returns The value, or null if not found
169
+ */
170
+ kvGet(key: string): JsonValue;
171
+
172
+ /**
173
+ * Delete a key.
174
+ * @param key - The key to delete
175
+ * @returns True if the key was deleted
176
+ */
177
+ kvDelete(key: string): boolean;
178
+
179
+ /**
180
+ * List keys with optional prefix filter.
181
+ * @param prefix - Optional prefix to filter keys
182
+ * @returns Array of matching keys
183
+ */
184
+ kvList(prefix?: string): string[];
185
+
186
+ /**
187
+ * Get version history for a key.
188
+ * @param key - The key to get history for
189
+ * @returns Array of versioned values, or null if key not found
190
+ */
191
+ kvHistory(key: string): VersionedValue[] | null;
192
+
193
+ // =========================================================================
194
+ // State Cell
195
+ // =========================================================================
196
+
197
+ /**
198
+ * Set a state cell value.
199
+ * @param cell - The cell name
200
+ * @param value - The value to set
201
+ * @returns Version number
202
+ */
203
+ stateSet(cell: string, value: JsonValue): number;
204
+
205
+ /**
206
+ * Get a state cell value.
207
+ * @param cell - The cell name
208
+ * @returns The value, or null if not found
209
+ */
210
+ stateGet(cell: string): JsonValue;
211
+
212
+ /**
213
+ * Initialize a state cell if it doesn't exist.
214
+ * @param cell - The cell name
215
+ * @param value - The initial value
216
+ * @returns Version number
217
+ */
218
+ stateInit(cell: string, value: JsonValue): number;
219
+
220
+ /**
221
+ * Compare-and-swap update based on version.
222
+ * @param cell - The cell name
223
+ * @param newValue - The new value to set
224
+ * @param expectedVersion - The expected current version
225
+ * @returns New version number if successful, null if CAS failed
226
+ */
227
+ stateCas(cell: string, newValue: JsonValue, expectedVersion?: number): number | null;
228
+
229
+ /**
230
+ * Get version history for a state cell.
231
+ * @param cell - The cell name
232
+ * @returns Array of versioned values, or null if cell not found
233
+ */
234
+ stateHistory(cell: string): VersionedValue[] | null;
235
+
236
+ // =========================================================================
237
+ // Event Log
238
+ // =========================================================================
239
+
240
+ /**
241
+ * Append an event to the log.
242
+ * @param eventType - The type of event
243
+ * @param payload - The event payload
244
+ * @returns Sequence number
245
+ */
246
+ eventAppend(eventType: string, payload: JsonValue): number;
247
+
248
+ /**
249
+ * Get an event by sequence number.
250
+ * @param sequence - The sequence number
251
+ * @returns The event, or null if not found
252
+ */
253
+ eventGet(sequence: number): VersionedValue | null;
254
+
255
+ /**
256
+ * List events by type.
257
+ * @param eventType - The type of events to list
258
+ * @returns Array of events
259
+ */
260
+ eventList(eventType: string): VersionedValue[];
261
+
262
+ /**
263
+ * Get total event count.
264
+ * @returns Number of events
265
+ */
266
+ eventLen(): number;
267
+
268
+ // =========================================================================
269
+ // JSON Store
270
+ // =========================================================================
271
+
272
+ /**
273
+ * Set a value at a JSONPath.
274
+ * @param key - The document key
275
+ * @param path - The JSONPath
276
+ * @param value - The value to set
277
+ * @returns Version number
278
+ */
279
+ jsonSet(key: string, path: string, value: JsonValue): number;
280
+
281
+ /**
282
+ * Get a value at a JSONPath.
283
+ * @param key - The document key
284
+ * @param path - The JSONPath
285
+ * @returns The value, or null if not found
286
+ */
287
+ jsonGet(key: string, path: string): JsonValue;
288
+
289
+ /**
290
+ * Delete a JSON document.
291
+ * @param key - The document key
292
+ * @param path - The JSONPath
293
+ * @returns Version number
294
+ */
295
+ jsonDelete(key: string, path: string): number;
296
+
297
+ /**
298
+ * Get version history for a JSON document.
299
+ * @param key - The document key
300
+ * @returns Array of versioned values, or null if document not found
301
+ */
302
+ jsonHistory(key: string): VersionedValue[] | null;
303
+
304
+ /**
305
+ * List JSON document keys.
306
+ * @param limit - Maximum number of keys to return
307
+ * @param prefix - Optional prefix filter
308
+ * @param cursor - Optional pagination cursor
309
+ * @returns Keys and optional next cursor
310
+ */
311
+ jsonList(limit: number, prefix?: string, cursor?: string): JsonListResult;
312
+
313
+ // =========================================================================
314
+ // Vector Store
315
+ // =========================================================================
316
+
317
+ /**
318
+ * Create a vector collection.
319
+ * @param collection - Collection name
320
+ * @param dimension - Vector dimension
321
+ * @param metric - Distance metric ("cosine", "euclidean", "dot_product")
322
+ * @returns Version number
323
+ */
324
+ vectorCreateCollection(collection: string, dimension: number, metric?: string): number;
325
+
326
+ /**
327
+ * Delete a vector collection.
328
+ * @param collection - Collection name
329
+ * @returns True if the collection was deleted
330
+ */
331
+ vectorDeleteCollection(collection: string): boolean;
332
+
333
+ /**
334
+ * List vector collections.
335
+ * @returns Array of collection information
336
+ */
337
+ vectorListCollections(): CollectionInfo[];
338
+
339
+ /**
340
+ * Insert or update a vector.
341
+ * @param collection - Collection name
342
+ * @param key - Vector key
343
+ * @param vector - Vector data (array of numbers)
344
+ * @param metadata - Optional metadata
345
+ * @returns Version number
346
+ */
347
+ vectorUpsert(collection: string, key: string, vector: number[], metadata?: JsonValue): number;
348
+
349
+ /**
350
+ * Get a vector by key.
351
+ * @param collection - Collection name
352
+ * @param key - Vector key
353
+ * @returns Vector data, or null if not found
354
+ */
355
+ vectorGet(collection: string, key: string): VectorData | null;
356
+
357
+ /**
358
+ * Delete a vector.
359
+ * @param collection - Collection name
360
+ * @param key - Vector key
361
+ * @returns True if the vector was deleted
362
+ */
363
+ vectorDelete(collection: string, key: string): boolean;
364
+
365
+ /**
366
+ * Search for similar vectors.
367
+ * @param collection - Collection name
368
+ * @param query - Query vector
369
+ * @param k - Number of results to return
370
+ * @returns Array of search matches
371
+ */
372
+ vectorSearch(collection: string, query: number[], k: number): SearchMatch[];
373
+
374
+ /**
375
+ * Get statistics for a single collection.
376
+ * @param collection - Collection name
377
+ * @returns Collection information
378
+ */
379
+ vectorCollectionStats(collection: string): CollectionInfo;
380
+
381
+ /**
382
+ * Batch insert/update multiple vectors.
383
+ * @param collection - Collection name
384
+ * @param vectors - Array of vector entries
385
+ * @returns Array of version numbers
386
+ */
387
+ vectorBatchUpsert(collection: string, vectors: BatchVectorEntry[]): number[];
388
+
389
+ // =========================================================================
390
+ // Branch Management
391
+ // =========================================================================
392
+
393
+ /**
394
+ * Get the current branch name.
395
+ */
396
+ currentBranch(): string;
397
+
398
+ /**
399
+ * Switch to a different branch.
400
+ * @param branch - Branch name
401
+ */
402
+ setBranch(branch: string): void;
403
+
404
+ /**
405
+ * Create a new empty branch.
406
+ * @param branch - Branch name
407
+ */
408
+ createBranch(branch: string): void;
409
+
410
+ /**
411
+ * Fork the current branch to a new branch, copying all data.
412
+ * @param destination - Destination branch name
413
+ */
414
+ forkBranch(destination: string): ForkResult;
415
+
416
+ /**
417
+ * List all branches.
418
+ */
419
+ listBranches(): string[];
420
+
421
+ /**
422
+ * Delete a branch.
423
+ * @param branch - Branch name
424
+ */
425
+ deleteBranch(branch: string): void;
426
+
427
+ /**
428
+ * Check if a branch exists.
429
+ * @param name - Branch name
430
+ * @returns True if the branch exists
431
+ */
432
+ branchExists(name: string): boolean;
433
+
434
+ /**
435
+ * Get branch metadata with version info.
436
+ * @param name - Branch name
437
+ * @returns Branch info, or null if not found
438
+ */
439
+ branchGet(name: string): BranchInfo | null;
440
+
441
+ /**
442
+ * Compare two branches.
443
+ * @param branchA - First branch name
444
+ * @param branchB - Second branch name
445
+ */
446
+ diffBranches(branchA: string, branchB: string): DiffResult;
447
+
448
+ /**
449
+ * Merge a branch into the current branch.
450
+ * @param source - Source branch name
451
+ * @param strategy - Merge strategy ("last_writer_wins" or "strict")
452
+ */
453
+ mergeBranches(source: string, strategy?: string): MergeResult;
454
+
455
+ // =========================================================================
456
+ // Space Management
457
+ // =========================================================================
458
+
459
+ /**
460
+ * Get the current space name.
461
+ */
462
+ currentSpace(): string;
463
+
464
+ /**
465
+ * Switch to a different space.
466
+ * @param space - Space name
467
+ */
468
+ setSpace(space: string): void;
469
+
470
+ /**
471
+ * List all spaces in the current branch.
472
+ */
473
+ listSpaces(): string[];
474
+
475
+ /**
476
+ * Delete a space and all its data.
477
+ * @param space - Space name
478
+ */
479
+ deleteSpace(space: string): void;
480
+
481
+ /**
482
+ * Force delete a space even if non-empty.
483
+ * @param space - Space name
484
+ */
485
+ deleteSpaceForce(space: string): void;
486
+
487
+ // =========================================================================
488
+ // Database Operations
489
+ // =========================================================================
490
+
491
+ /**
492
+ * Check database connectivity.
493
+ */
494
+ ping(): string;
495
+
496
+ /**
497
+ * Get database info.
498
+ */
499
+ info(): DatabaseInfo;
500
+
501
+ /**
502
+ * Flush writes to disk.
503
+ */
504
+ flush(): void;
505
+
506
+ /**
507
+ * Trigger compaction.
508
+ */
509
+ compact(): void;
510
+
511
+ // =========================================================================
512
+ // Bundle Operations
513
+ // =========================================================================
514
+
515
+ /**
516
+ * Export a branch to a bundle file.
517
+ * @param branch - Branch name
518
+ * @param path - Output file path
519
+ * @returns Export result with counts
520
+ */
521
+ branchExport(branch: string, path: string): BranchExportResult;
522
+
523
+ /**
524
+ * Import a branch from a bundle file.
525
+ * @param path - Bundle file path
526
+ * @returns Import result with counts
527
+ */
528
+ branchImport(path: string): BranchImportResult;
529
+
530
+ /**
531
+ * Validate a bundle file without importing.
532
+ * @param path - Bundle file path
533
+ * @returns Validation result
534
+ */
535
+ branchValidateBundle(path: string): BundleValidateResult;
536
+ }