@liorandb/core 1.0.13 → 1.0.15

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.ts CHANGED
@@ -1,6 +1,26 @@
1
1
  import { ClassicLevel } from 'classic-level';
2
2
  import { ZodSchema } from 'zod';
3
3
 
4
+ interface IndexOptions {
5
+ unique?: boolean;
6
+ }
7
+ declare class Index {
8
+ readonly field: string;
9
+ readonly unique: boolean;
10
+ readonly dir: string;
11
+ readonly db: ClassicLevel<string, string>;
12
+ constructor(baseDir: string, field: string, options?: IndexOptions);
13
+ private normalizeKey;
14
+ private getRaw;
15
+ private setRaw;
16
+ private delRaw;
17
+ insert(doc: any): Promise<void>;
18
+ delete(doc: any): Promise<void>;
19
+ update(oldDoc: any, newDoc: any): Promise<void>;
20
+ find(value: any): Promise<string[]>;
21
+ close(): Promise<void>;
22
+ }
23
+
4
24
  interface UpdateOptions$1 {
5
25
  upsert?: boolean;
6
26
  }
@@ -9,34 +29,36 @@ declare class Collection<T = any> {
9
29
  db: ClassicLevel<string, string>;
10
30
  private queue;
11
31
  private schema?;
32
+ private indexes;
12
33
  constructor(dir: string, schema?: ZodSchema<T>);
34
+ registerIndex(index: Index): void;
35
+ getIndex(field: string): Index | undefined;
13
36
  setSchema(schema: ZodSchema<T>): void;
14
37
  private validate;
15
38
  private _enqueue;
16
39
  close(): Promise<void>;
40
+ compact(): Promise<void>;
17
41
  _exec(op: string, args: any[]): Promise<any>;
18
- insertOne(doc: T & {
19
- _id?: string;
20
- }): Promise<any>;
21
- insertMany(docs?: (T & {
22
- _id?: string;
23
- })[]): Promise<any>;
24
- find(query?: any): Promise<any>;
25
- findOne(query?: any): Promise<any>;
26
- updateOne(filter: any, update: any, options?: UpdateOptions$1): Promise<any>;
27
- updateMany(filter: any, update: any): Promise<any>;
28
- deleteOne(filter: any): Promise<any>;
29
- deleteMany(filter: any): Promise<any>;
30
- countDocuments(filter?: any): Promise<any>;
42
+ private _updateIndexes;
31
43
  private _insertOne;
32
44
  private _insertMany;
45
+ private _getCandidateIds;
46
+ private _find;
33
47
  private _findOne;
48
+ private _countDocuments;
34
49
  private _updateOne;
35
50
  private _updateMany;
36
- private _find;
37
51
  private _deleteOne;
38
52
  private _deleteMany;
39
- private _countDocuments;
53
+ insertOne(doc: any): Promise<any>;
54
+ insertMany(docs: any[]): Promise<any>;
55
+ find(query?: any): Promise<any>;
56
+ findOne(query?: any): Promise<any>;
57
+ updateOne(filter: any, update: any, options?: UpdateOptions$1): Promise<any>;
58
+ updateMany(filter: any, update: any): Promise<any>;
59
+ deleteOne(filter: any): Promise<any>;
60
+ deleteMany(filter: any): Promise<any>;
61
+ countDocuments(filter?: any): Promise<any>;
40
62
  }
41
63
 
42
64
  type TXOp = {
@@ -68,13 +90,26 @@ declare class LioranDB {
68
90
  manager: LioranManager;
69
91
  collections: Map<string, Collection>;
70
92
  private walPath;
93
+ private metaPath;
94
+ private meta;
71
95
  private static TX_SEQ;
72
96
  constructor(basePath: string, dbName: string, manager: LioranManager);
97
+ private loadMeta;
98
+ private saveMeta;
73
99
  writeWAL(entries: WALEntry[]): Promise<void>;
74
100
  clearWAL(): Promise<void>;
75
101
  private recoverFromWAL;
76
102
  applyTransaction(ops: TXOp[]): Promise<void>;
77
103
  collection<T = any>(name: string, schema?: ZodSchema<T>): Collection<T>;
104
+ createIndex(collection: string, field: string, options?: IndexOptions): Promise<void>;
105
+ /**
106
+ * Compact single collection safely (WAL + TX safe)
107
+ */
108
+ compactCollection(name: string): Promise<void>;
109
+ /**
110
+ * Compact entire database safely
111
+ */
112
+ compactAll(): Promise<void>;
78
113
  transaction<T>(fn: (tx: DBTransactionContext) => Promise<T>): Promise<T>;
79
114
  close(): Promise<void>;
80
115
  }
@@ -114,5 +149,35 @@ interface UpdateOptions {
114
149
  type Query<T = any> = Partial<T> & {
115
150
  [key: string]: any;
116
151
  };
152
+ type IndexType = "hash" | "btree";
153
+ interface IndexDefinition<T = any> {
154
+ field: keyof T | string;
155
+ unique?: boolean;
156
+ sparse?: boolean;
157
+ type?: IndexType;
158
+ }
159
+ interface IndexMetadata {
160
+ field: string;
161
+ unique: boolean;
162
+ sparse: boolean;
163
+ type: IndexType;
164
+ createdAt: number;
165
+ }
166
+ interface QueryExplainPlan {
167
+ indexUsed?: string;
168
+ indexType?: IndexType;
169
+ scannedDocuments: number;
170
+ returnedDocuments: number;
171
+ executionTimeMs: number;
172
+ }
173
+ interface CollectionIndexAPI<T = any> {
174
+ createIndex(def: IndexDefinition<T>): Promise<void>;
175
+ dropIndex(field: keyof T | string): Promise<void>;
176
+ listIndexes(): Promise<IndexMetadata[]>;
177
+ rebuildIndexes(): Promise<void>;
178
+ }
179
+ interface DatabaseIndexAPI {
180
+ rebuildAllIndexes(): Promise<void>;
181
+ }
117
182
 
118
- export { LioranDB, LioranManager, type LioranManagerOptions, type Query, type UpdateOptions, getBaseDBFolder };
183
+ export { type CollectionIndexAPI, type DatabaseIndexAPI, type IndexDefinition, type IndexMetadata, type IndexType, LioranDB, LioranManager, type LioranManagerOptions, type Query, type QueryExplainPlan, type UpdateOptions, getBaseDBFolder };