@liorandb/core 1.0.18 → 1.1.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/dist/index.d.ts CHANGED
@@ -71,21 +71,45 @@ 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 recoverLSNFromExistingLogs;
97
+ private getSortedWalFiles;
98
+ private open;
99
+ private rotate;
100
+ append(record: Omit<WALRecord, "lsn">): Promise<number>;
101
+ replay(fromLSN: number, apply: (r: WALRecord) => Promise<void>): Promise<void>;
102
+ cleanup(beforeGen: number): Promise<void>;
103
+ getCurrentLSN(): number;
104
+ getCurrentGen(): number;
105
+ }
106
+
74
107
  type TXOp = {
75
108
  tx: number;
76
109
  col: string;
77
110
  op: string;
78
111
  args: any[];
79
112
  };
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
113
  declare class DBTransactionContext {
90
114
  private db;
91
115
  readonly txId: number;
@@ -99,27 +123,29 @@ declare class LioranDB {
99
123
  dbName: string;
100
124
  manager: LioranManager;
101
125
  collections: Map<string, Collection>;
102
- private walPath;
103
126
  private metaPath;
104
127
  private meta;
105
128
  private migrator;
106
129
  private static TX_SEQ;
130
+ wal: WALManager;
131
+ private checkpoint;
107
132
  constructor(basePath: string, dbName: string, manager: LioranManager);
133
+ private initialize;
134
+ private recoverFromWAL;
135
+ advanceCheckpoint(lsn: number): void;
108
136
  private loadMeta;
109
137
  private saveMeta;
110
138
  getSchemaVersion(): string;
111
139
  setSchemaVersion(v: string): void;
112
140
  migrate(from: string, to: string, fn: (db: LioranDB) => Promise<void>): void;
113
141
  applyMigrations(targetVersion: string): Promise<void>;
114
- writeWAL(entries: WALEntry[]): Promise<void>;
115
- clearWAL(): Promise<void>;
116
- private recoverFromWAL;
117
142
  applyTransaction(ops: TXOp[]): Promise<void>;
118
143
  collection<T = any>(name: string, schema?: ZodSchema<T>, schemaVersion?: number): Collection<T>;
119
144
  createIndex(collection: string, field: string, options?: IndexOptions): Promise<void>;
120
145
  compactCollection(name: string): Promise<void>;
121
146
  compactAll(): Promise<void>;
122
147
  transaction<T>(fn: (tx: DBTransactionContext) => Promise<T>): Promise<T>;
148
+ postCommitMaintenance(): Promise<void>;
123
149
  close(): Promise<void>;
124
150
  }
125
151