@liorandb/core 1.0.11 → 1.0.13
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/chunk-ST6KMJQJ.js +759 -0
- package/dist/index.d.ts +46 -49
- package/dist/index.js +790 -5
- package/dist/worker/dbWorker.js +11 -13
- package/package.json +2 -2
- package/src/LioranManager.ts +62 -114
- package/src/core/collection.ts +74 -244
- package/src/core/database.ts +103 -86
- package/src/core/transaction.ts +34 -0
- package/src/ipc/client.ts +85 -0
- package/src/ipc/queue.ts +11 -126
- package/src/ipc/server.ts +84 -0
- package/src/ipc/socketPath.ts +10 -0
- package/src/worker/dbWorker.ts +0 -45
package/dist/index.d.ts
CHANGED
|
@@ -8,100 +8,97 @@ declare class Collection<T = any> {
|
|
|
8
8
|
dir: string;
|
|
9
9
|
db: ClassicLevel<string, string>;
|
|
10
10
|
private queue;
|
|
11
|
-
private walPath;
|
|
12
11
|
private schema?;
|
|
13
|
-
private walCounter;
|
|
14
12
|
constructor(dir: string, schema?: ZodSchema<T>);
|
|
15
13
|
setSchema(schema: ZodSchema<T>): void;
|
|
16
14
|
private validate;
|
|
17
|
-
private writeWAL;
|
|
18
|
-
private clearWAL;
|
|
19
|
-
private maybeCheckpoint;
|
|
20
|
-
private recoverFromWAL;
|
|
21
15
|
private _enqueue;
|
|
22
|
-
private _exec;
|
|
23
16
|
close(): Promise<void>;
|
|
17
|
+
_exec(op: string, args: any[]): Promise<any>;
|
|
24
18
|
insertOne(doc: T & {
|
|
25
19
|
_id?: string;
|
|
26
|
-
}): Promise<
|
|
20
|
+
}): Promise<any>;
|
|
27
21
|
insertMany(docs?: (T & {
|
|
28
22
|
_id?: string;
|
|
29
|
-
})[]): Promise<
|
|
30
|
-
find(query?: any): Promise<
|
|
31
|
-
findOne(query?: any): Promise<
|
|
32
|
-
updateOne(filter
|
|
33
|
-
updateMany(filter
|
|
34
|
-
deleteOne(filter
|
|
35
|
-
deleteMany(filter
|
|
36
|
-
countDocuments(filter?: any): Promise<
|
|
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>;
|
|
37
31
|
private _insertOne;
|
|
38
32
|
private _insertMany;
|
|
39
33
|
private _findOne;
|
|
40
34
|
private _updateOne;
|
|
41
|
-
private _deleteOne;
|
|
42
35
|
private _updateMany;
|
|
43
36
|
private _find;
|
|
37
|
+
private _deleteOne;
|
|
44
38
|
private _deleteMany;
|
|
45
39
|
private _countDocuments;
|
|
46
40
|
}
|
|
47
41
|
|
|
42
|
+
type TXOp = {
|
|
43
|
+
tx: number;
|
|
44
|
+
col: string;
|
|
45
|
+
op: string;
|
|
46
|
+
args: any[];
|
|
47
|
+
};
|
|
48
|
+
type TXCommit = {
|
|
49
|
+
tx: number;
|
|
50
|
+
commit: true;
|
|
51
|
+
};
|
|
52
|
+
type TXApplied = {
|
|
53
|
+
tx: number;
|
|
54
|
+
applied: true;
|
|
55
|
+
};
|
|
56
|
+
type WALEntry = TXOp | TXCommit | TXApplied;
|
|
57
|
+
declare class DBTransactionContext {
|
|
58
|
+
private db;
|
|
59
|
+
readonly txId: number;
|
|
60
|
+
private ops;
|
|
61
|
+
constructor(db: LioranDB, txId: number);
|
|
62
|
+
collection(name: string): {};
|
|
63
|
+
commit(): Promise<void>;
|
|
64
|
+
}
|
|
48
65
|
declare class LioranDB {
|
|
49
66
|
basePath: string;
|
|
50
67
|
dbName: string;
|
|
51
68
|
manager: LioranManager;
|
|
52
69
|
collections: Map<string, Collection>;
|
|
70
|
+
private walPath;
|
|
71
|
+
private static TX_SEQ;
|
|
53
72
|
constructor(basePath: string, dbName: string, manager: LioranManager);
|
|
73
|
+
writeWAL(entries: WALEntry[]): Promise<void>;
|
|
74
|
+
clearWAL(): Promise<void>;
|
|
75
|
+
private recoverFromWAL;
|
|
76
|
+
applyTransaction(ops: TXOp[]): Promise<void>;
|
|
54
77
|
collection<T = any>(name: string, schema?: ZodSchema<T>): Collection<T>;
|
|
55
|
-
|
|
56
|
-
deleteCollection(name: string): Promise<boolean>;
|
|
57
|
-
renameCollection(oldName: string, newName: string): Promise<boolean>;
|
|
58
|
-
dropCollection(name: string): Promise<boolean>;
|
|
59
|
-
listCollections(): Promise<string[]>;
|
|
78
|
+
transaction<T>(fn: (tx: DBTransactionContext) => Promise<T>): Promise<T>;
|
|
60
79
|
close(): Promise<void>;
|
|
61
|
-
getStats(): {
|
|
62
|
-
dbName: string;
|
|
63
|
-
basePath: string;
|
|
64
|
-
collections: string[];
|
|
65
|
-
};
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
interface LioranManagerOptions$1 {
|
|
69
83
|
rootPath?: string;
|
|
70
84
|
encryptionKey?: string | Buffer;
|
|
71
|
-
ipc?: boolean;
|
|
72
85
|
}
|
|
73
86
|
declare class LioranManager {
|
|
74
87
|
rootPath: string;
|
|
75
88
|
openDBs: Map<string, LioranDB>;
|
|
76
89
|
private closed;
|
|
77
|
-
private
|
|
90
|
+
private mode;
|
|
91
|
+
private lockFd?;
|
|
92
|
+
private ipcServer?;
|
|
78
93
|
constructor(options?: LioranManagerOptions$1);
|
|
94
|
+
private isProcessAlive;
|
|
95
|
+
private tryAcquireLock;
|
|
79
96
|
db(name: string): Promise<LioranDB>;
|
|
80
|
-
createDatabase(name: string): Promise<LioranDB>;
|
|
81
97
|
openDatabase(name: string): Promise<LioranDB>;
|
|
82
|
-
closeDatabase(name: string): Promise<void>;
|
|
83
|
-
/**
|
|
84
|
-
* Gracefully shuts down everything.
|
|
85
|
-
* - Closes all databases
|
|
86
|
-
* - Terminates IPC worker if running
|
|
87
|
-
*/
|
|
88
98
|
closeAll(): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Alias for closeAll() (clean public API)
|
|
91
|
-
*/
|
|
92
99
|
close(): Promise<void>;
|
|
93
100
|
private _registerShutdownHooks;
|
|
94
101
|
private _assertOpen;
|
|
95
|
-
renameDatabase(oldName: string, newName: string): Promise<boolean>;
|
|
96
|
-
deleteDatabase(name: string): Promise<boolean>;
|
|
97
|
-
dropDatabase(name: string): Promise<boolean>;
|
|
98
|
-
listDatabases(): Promise<string[]>;
|
|
99
|
-
getStats(): {
|
|
100
|
-
rootPath: string;
|
|
101
|
-
openDatabases: string[];
|
|
102
|
-
ipc: boolean;
|
|
103
|
-
closed: boolean;
|
|
104
|
-
};
|
|
105
102
|
}
|
|
106
103
|
|
|
107
104
|
declare function getBaseDBFolder(): string;
|