@liorandb/core 1.0.13 → 1.0.14

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/src/ipc/index.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { dbQueue } from "./queue.js";
2
2
 
3
- type AnyFn = (...args: any[]) => Promise<any>;
4
-
5
3
  /* -------------------------------- COLLECTION PROXY -------------------------------- */
6
4
 
7
5
  class CollectionProxy {
@@ -19,6 +17,17 @@ class CollectionProxy {
19
17
  });
20
18
  }
21
19
 
20
+ private callIndex(method: string, params: any[]): Promise<any> {
21
+ return dbQueue.exec("index", {
22
+ db: this.dbName,
23
+ col: this.collectionName,
24
+ method,
25
+ params
26
+ });
27
+ }
28
+
29
+ /* ------------------------------ CRUD ------------------------------ */
30
+
22
31
  insertOne = (doc: any) => this.call("insertOne", [doc]);
23
32
  insertMany = (docs: any[]) => this.call("insertMany", [docs]);
24
33
  find = (query?: any) => this.call("find", [query]);
@@ -31,6 +40,13 @@ class CollectionProxy {
31
40
  deleteMany = (filter: any) => this.call("deleteMany", [filter]);
32
41
  countDocuments = (filter?: any) =>
33
42
  this.call("countDocuments", [filter]);
43
+
44
+ /* ------------------------------ INDEX ----------------------------- */
45
+
46
+ createIndex = (def: any) => this.callIndex("createIndex", [def]);
47
+ dropIndex = (field: string) => this.callIndex("dropIndex", [field]);
48
+ listIndexes = () => this.callIndex("listIndexes", []);
49
+ rebuildIndexes = () => this.callIndex("rebuildIndexes", []);
34
50
  }
35
51
 
36
52
  /* -------------------------------- DATABASE PROXY -------------------------------- */
@@ -53,4 +69,4 @@ class LioranManagerIPC {
53
69
  }
54
70
 
55
71
  export const manager = new LioranManagerIPC();
56
- export type { CollectionProxy, DBProxy };
72
+ export type { CollectionProxy, DBProxy };
@@ -1,13 +1,63 @@
1
+ /* ----------------------------- MANAGER OPTIONS ----------------------------- */
2
+
1
3
  export interface LioranManagerOptions {
2
4
  rootPath?: string
3
- encryptionKey?: string | Buffer,
5
+ encryptionKey?: string | Buffer
4
6
  ipc?: boolean
5
7
  }
6
8
 
9
+ /* ----------------------------- UPDATE OPTIONS ----------------------------- */
10
+
7
11
  export interface UpdateOptions {
8
12
  upsert?: boolean
9
13
  }
10
14
 
15
+ /* --------------------------------- QUERY --------------------------------- */
16
+
11
17
  export type Query<T = any> = Partial<T> & {
12
18
  [key: string]: any
13
19
  }
20
+
21
+ /* --------------------------------- INDEX --------------------------------- */
22
+
23
+ export type IndexType = "hash" | "btree"
24
+
25
+ export interface IndexDefinition<T = any> {
26
+ field: keyof T | string
27
+ unique?: boolean
28
+ sparse?: boolean
29
+ type?: IndexType
30
+ }
31
+
32
+ export interface IndexMetadata {
33
+ field: string
34
+ unique: boolean
35
+ sparse: boolean
36
+ type: IndexType
37
+ createdAt: number
38
+ }
39
+
40
+ /* ----------------------------- QUERY PLANNER ------------------------------ */
41
+
42
+ export interface QueryExplainPlan {
43
+ indexUsed?: string
44
+ indexType?: IndexType
45
+ scannedDocuments: number
46
+ returnedDocuments: number
47
+ executionTimeMs: number
48
+ }
49
+
50
+ /* ------------------------------ COLLECTION -------------------------------- */
51
+
52
+ export interface CollectionIndexAPI<T = any> {
53
+ createIndex(def: IndexDefinition<T>): Promise<void>
54
+ dropIndex(field: keyof T | string): Promise<void>
55
+ listIndexes(): Promise<IndexMetadata[]>
56
+ rebuildIndexes(): Promise<void>
57
+ }
58
+
59
+ /* ------------------------------- DATABASE --------------------------------- */
60
+
61
+ export interface DatabaseIndexAPI {
62
+ rebuildAllIndexes(): Promise<void>
63
+ }