@liorandb/core 1.0.18 → 1.0.19
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 +36 -13
- package/dist/index.js +347 -109
- package/package.json +1 -1
- package/src/core/checkpoint.ts +111 -0
- package/src/core/compaction.ts +79 -32
- package/src/core/database.ts +78 -58
- package/src/core/wal.ts +213 -0
package/dist/index.d.ts
CHANGED
|
@@ -71,21 +71,43 @@ declare class Collection<T = any> {
|
|
|
71
71
|
countDocuments(filter?: any): Promise<number | boolean | T | T[] | null>;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
type WALRecord = {
|
|
75
|
+
lsn: number;
|
|
76
|
+
tx: number;
|
|
77
|
+
type: "op";
|
|
78
|
+
payload: any;
|
|
79
|
+
} | {
|
|
80
|
+
lsn: number;
|
|
81
|
+
tx: number;
|
|
82
|
+
type: "commit";
|
|
83
|
+
} | {
|
|
84
|
+
lsn: number;
|
|
85
|
+
tx: number;
|
|
86
|
+
type: "applied";
|
|
87
|
+
};
|
|
88
|
+
declare class WALManager {
|
|
89
|
+
private walDir;
|
|
90
|
+
private currentGen;
|
|
91
|
+
private lsn;
|
|
92
|
+
private fd;
|
|
93
|
+
constructor(baseDir: string);
|
|
94
|
+
private walPath;
|
|
95
|
+
private detectLastGeneration;
|
|
96
|
+
private open;
|
|
97
|
+
private rotate;
|
|
98
|
+
append(record: Omit<WALRecord, "lsn">): Promise<number>;
|
|
99
|
+
replay(fromLSN: number, apply: (r: WALRecord) => Promise<void>): Promise<void>;
|
|
100
|
+
cleanup(beforeGen: number): Promise<void>;
|
|
101
|
+
getCurrentLSN(): number;
|
|
102
|
+
getCurrentGen(): number;
|
|
103
|
+
}
|
|
104
|
+
|
|
74
105
|
type TXOp = {
|
|
75
106
|
tx: number;
|
|
76
107
|
col: string;
|
|
77
108
|
op: string;
|
|
78
109
|
args: any[];
|
|
79
110
|
};
|
|
80
|
-
type TXCommit = {
|
|
81
|
-
tx: number;
|
|
82
|
-
commit: true;
|
|
83
|
-
};
|
|
84
|
-
type TXApplied = {
|
|
85
|
-
tx: number;
|
|
86
|
-
applied: true;
|
|
87
|
-
};
|
|
88
|
-
type WALEntry = TXOp | TXCommit | TXApplied;
|
|
89
111
|
declare class DBTransactionContext {
|
|
90
112
|
private db;
|
|
91
113
|
readonly txId: number;
|
|
@@ -99,27 +121,28 @@ declare class LioranDB {
|
|
|
99
121
|
dbName: string;
|
|
100
122
|
manager: LioranManager;
|
|
101
123
|
collections: Map<string, Collection>;
|
|
102
|
-
private walPath;
|
|
103
124
|
private metaPath;
|
|
104
125
|
private meta;
|
|
105
126
|
private migrator;
|
|
106
127
|
private static TX_SEQ;
|
|
128
|
+
wal: WALManager;
|
|
129
|
+
private checkpoint;
|
|
107
130
|
constructor(basePath: string, dbName: string, manager: LioranManager);
|
|
131
|
+
private initialize;
|
|
132
|
+
private recoverFromWAL;
|
|
108
133
|
private loadMeta;
|
|
109
134
|
private saveMeta;
|
|
110
135
|
getSchemaVersion(): string;
|
|
111
136
|
setSchemaVersion(v: string): void;
|
|
112
137
|
migrate(from: string, to: string, fn: (db: LioranDB) => Promise<void>): void;
|
|
113
138
|
applyMigrations(targetVersion: string): Promise<void>;
|
|
114
|
-
writeWAL(entries: WALEntry[]): Promise<void>;
|
|
115
|
-
clearWAL(): Promise<void>;
|
|
116
|
-
private recoverFromWAL;
|
|
117
139
|
applyTransaction(ops: TXOp[]): Promise<void>;
|
|
118
140
|
collection<T = any>(name: string, schema?: ZodSchema<T>, schemaVersion?: number): Collection<T>;
|
|
119
141
|
createIndex(collection: string, field: string, options?: IndexOptions): Promise<void>;
|
|
120
142
|
compactCollection(name: string): Promise<void>;
|
|
121
143
|
compactAll(): Promise<void>;
|
|
122
144
|
transaction<T>(fn: (tx: DBTransactionContext) => Promise<T>): Promise<T>;
|
|
145
|
+
postCommitMaintenance(): Promise<void>;
|
|
123
146
|
close(): Promise<void>;
|
|
124
147
|
}
|
|
125
148
|
|