tero 0.0.9 → 0.0.12
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/LICENSE +21 -0
- package/README.md +19 -17
- package/dist/acid-engine.d.ts +32 -16
- package/dist/acid-engine.js +259 -80
- package/dist/backup.d.ts +42 -5
- package/dist/backup.js +451 -104
- package/dist/index.d.ts +64 -29
- package/dist/index.js +556 -176
- package/dist/recovery.d.ts +3 -2
- package/dist/recovery.js +103 -28
- package/package.json +37 -22
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SynchronousMode } from "./acid-engine.js";
|
|
2
2
|
import { DocumentSchema, ValidationResult } from "./schema.js";
|
|
3
|
-
import { BackupConfig, BackupMetadata, CloudStorageConfig, BucketBackupResult, LiveBackupOptions, LiveBackupStatus } from "./backup.js";
|
|
3
|
+
import { BackupConfig, BackupMetadata, CloudStorageConfig, BucketBackupResult, LiveBackupOptions, LiveBackupStatus, LiveCheckpointResult, RestoreLiveResult, BackupLogger } from "./backup.js";
|
|
4
4
|
import { RecoveryConfig, RecoveryResult, FileRecoveryInfo } from "./recovery.js";
|
|
5
5
|
interface TeroConfig {
|
|
6
6
|
directory?: string;
|
|
@@ -26,10 +26,11 @@ interface TeroConfig {
|
|
|
26
26
|
/** v2: per-second live WAL shipping to the bucket. RPO ≤ 1s of committed writes. */
|
|
27
27
|
liveBackup?: LiveBackupOptions;
|
|
28
28
|
/**
|
|
29
|
-
* Acquire an exclusive
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* Acquire an exclusive lock on the data directory (lock-file based:
|
|
30
|
+
* openSync 'wx' exclusive-create on <dir>/.lock with PID + stale-lock
|
|
31
|
+
* reclamation — no native modules). Two Node processes writing the same
|
|
32
|
+
* directory without this flag will corrupt each other's data. Recommended
|
|
33
|
+
* true in production; default false for backwards compatibility.
|
|
33
34
|
*/
|
|
34
35
|
fileLock?: boolean;
|
|
35
36
|
}
|
|
@@ -59,17 +60,37 @@ export declare class Transaction {
|
|
|
59
60
|
private db;
|
|
60
61
|
private startTime;
|
|
61
62
|
private opCount;
|
|
63
|
+
/** Real operation log backing getState() — the old implementation fabricated
|
|
64
|
+
* fake keys ('op_0', 'op_1', …) and labeled every operation 'write',
|
|
65
|
+
* including deletes. One array push per op: O(1), off the engine hot path. */
|
|
66
|
+
private operationsLog;
|
|
62
67
|
private destroyed;
|
|
68
|
+
private committed;
|
|
69
|
+
private rolledBack;
|
|
63
70
|
private timeoutTimer?;
|
|
64
71
|
constructor(id: string, db: Tero, options?: TransactionOptions);
|
|
65
72
|
getId(): string;
|
|
66
73
|
isActive(): boolean;
|
|
67
74
|
isRolledBack(): boolean;
|
|
75
|
+
isCommitted(): boolean;
|
|
68
76
|
private _checkActive;
|
|
69
77
|
create(key: string, initialData?: any): Promise<void>;
|
|
70
78
|
update(key: string, data: any): Promise<void>;
|
|
71
79
|
delete(key: string): Promise<void>;
|
|
72
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Read document within this transaction.
|
|
82
|
+
* @param options.lock - 'shared' (default) or 'exclusive' (SELECT FOR UPDATE)
|
|
83
|
+
*/
|
|
84
|
+
get(key: string, options?: {
|
|
85
|
+
lock?: 'shared' | 'exclusive';
|
|
86
|
+
}): Promise<any>;
|
|
87
|
+
/**
|
|
88
|
+
* Alias for get() with explicit locking semantics.
|
|
89
|
+
* @param options.lock - 'shared' (default) or 'exclusive' (SELECT FOR UPDATE)
|
|
90
|
+
*/
|
|
91
|
+
read(key: string, options?: {
|
|
92
|
+
lock?: 'shared' | 'exclusive';
|
|
93
|
+
}): Promise<any>;
|
|
73
94
|
getState(): {
|
|
74
95
|
status: string;
|
|
75
96
|
operations: Array<{
|
|
@@ -79,7 +100,9 @@ export declare class Transaction {
|
|
|
79
100
|
startTime: number;
|
|
80
101
|
};
|
|
81
102
|
getOperationCount(): number;
|
|
82
|
-
|
|
103
|
+
commit(): Promise<void>;
|
|
104
|
+
abort(): Promise<void>;
|
|
105
|
+
rollback(): Promise<void>;
|
|
83
106
|
destroy(): void;
|
|
84
107
|
}
|
|
85
108
|
export declare class Tero {
|
|
@@ -102,7 +125,7 @@ export declare class Tero {
|
|
|
102
125
|
*/
|
|
103
126
|
private knownKeys;
|
|
104
127
|
private readonly KNOWN_KEYS_MAX;
|
|
105
|
-
/**
|
|
128
|
+
/** Exclusive lock fd on <dir>/.lock (lock-file based; see acquireFileLock). */
|
|
106
129
|
private lockFd?;
|
|
107
130
|
/**
|
|
108
131
|
* Construct an embedded Tero instance synchronously.
|
|
@@ -130,6 +153,7 @@ export declare class Tero {
|
|
|
130
153
|
timeout?: number;
|
|
131
154
|
}): Promise<RecoveryResult>;
|
|
132
155
|
private initializeDirectories;
|
|
156
|
+
private static readonly MAX_KEY_LENGTH;
|
|
133
157
|
private validateKey;
|
|
134
158
|
/**
|
|
135
159
|
* Tracks which keys each active transaction has touched (cache entries tagged
|
|
@@ -147,7 +171,9 @@ export declare class Tero {
|
|
|
147
171
|
schemaName?: string;
|
|
148
172
|
strict?: boolean;
|
|
149
173
|
}): Promise<ValidationResult | void>;
|
|
150
|
-
read(transactionId: string | Transaction, key: string
|
|
174
|
+
read(transactionId: string | Transaction, key: string, options?: {
|
|
175
|
+
lock?: 'shared' | 'exclusive';
|
|
176
|
+
}): Promise<any>;
|
|
151
177
|
commit(transactionId: string | Transaction): Promise<void>;
|
|
152
178
|
rollback(transactionId: string | Transaction): Promise<void>;
|
|
153
179
|
commitTransaction(transactionId: string | Transaction): Promise<void>;
|
|
@@ -169,8 +195,10 @@ export declare class Tero {
|
|
|
169
195
|
strict?: boolean;
|
|
170
196
|
}): Promise<ValidationResult | void>;
|
|
171
197
|
/**
|
|
172
|
-
* Read a document. Returns the document data on success, or `
|
|
173
|
-
* document is absent
|
|
198
|
+
* Read a document. Returns the document data on success, or `null` if the
|
|
199
|
+
* document is absent (use `=== null` to check). For backwards-compat, `false`
|
|
200
|
+
* is still treated as "not found" by callers, but new code should check for null.
|
|
201
|
+
* Throws for genuine errors (invalid key, corrupt file).
|
|
174
202
|
*
|
|
175
203
|
* Fast path (3 tiers, zero-syscall on hit):
|
|
176
204
|
* 1. LRU cache (committed entries) — pure memory, 900k+ ops/s
|
|
@@ -180,10 +208,15 @@ export declare class Tero {
|
|
|
180
208
|
*
|
|
181
209
|
* NO transaction is created, NO WAL I/O, NO lock acquired.
|
|
182
210
|
*/
|
|
183
|
-
get(key: string): Promise<any>;
|
|
211
|
+
get(key: string): Promise<any | null>;
|
|
184
212
|
/**
|
|
185
213
|
* Map a document key to its partitioned path on disk (2-level hash-prefix).
|
|
186
|
-
*
|
|
214
|
+
* Delegates to the ENGINE'S partitionedPath() — the single authoritative
|
|
215
|
+
* implementation. The previous local FNV-1a re-implementation produced the
|
|
216
|
+
* same paths only by convention; if the two ever drifted, get() would read a
|
|
217
|
+
* different file than the engine writes (silent data loss). The engine's
|
|
218
|
+
* hash computes a 64-bit value (2 imul/char vs 1) but this runs only on
|
|
219
|
+
* cache-miss reads, which are syscall-dominated — measured impact: none.
|
|
187
220
|
*/
|
|
188
221
|
private keyToPath;
|
|
189
222
|
remove(key: string): Promise<void>;
|
|
@@ -283,20 +316,20 @@ export declare class Tero {
|
|
|
283
316
|
disableLiveBackup(): void;
|
|
284
317
|
/** Current live-backup health and counters. */
|
|
285
318
|
getLiveBackupStatus(): LiveBackupStatus;
|
|
286
|
-
/** Take
|
|
319
|
+
/** Take a checkpoint: FULL on the first call after enable (also taken
|
|
320
|
+
* automatically), INCREMENTAL (only dirty docs) on subsequent calls. */
|
|
287
321
|
liveCheckpointToBucket(opts?: {
|
|
288
322
|
tag?: string;
|
|
289
|
-
}): Promise<
|
|
290
|
-
uploadedDocs: number;
|
|
291
|
-
fullUpload: boolean;
|
|
292
|
-
duration: number;
|
|
293
|
-
}>;
|
|
323
|
+
}): Promise<LiveCheckpointResult>;
|
|
294
324
|
/** Restore a fresh Tero instance from a live backup in the bucket. */
|
|
295
325
|
static restoreFromLiveBackup(opts: {
|
|
296
326
|
directory: string;
|
|
297
327
|
cloudStorage: CloudStorageConfig;
|
|
298
328
|
nodeId?: string;
|
|
299
329
|
pointInTime?: number;
|
|
330
|
+
/** Name of the ORIGINAL database directory in the bucket, if restoring to a
|
|
331
|
+
* new directory name (disaster-recovery / staging restores). Defaults to `directory`. */
|
|
332
|
+
sourceDirectory?: string;
|
|
300
333
|
}): Promise<Tero>;
|
|
301
334
|
configureDataRecovery(config: RecoveryConfig): void;
|
|
302
335
|
recoverFromCloud(key: string): Promise<boolean>;
|
|
@@ -318,9 +351,9 @@ export declare class Tero {
|
|
|
318
351
|
recoverFromArchive(archiveName?: string): Promise<RecoveryResult>;
|
|
319
352
|
/**
|
|
320
353
|
* Read a key locally; if absent locally, transparently recover it from the client's
|
|
321
|
-
* bucket and cache the result. Returns the data, or `
|
|
322
|
-
* doesn't exist on either side
|
|
323
|
-
* don't silently mistake them for "not in cloud".
|
|
354
|
+
* bucket and cache the result. Returns the data, or `null` if the key genuinely
|
|
355
|
+
* doesn't exist on either side (returns `false` for backwards compat — both mean "not found").
|
|
356
|
+
* Throws for real (auth/network) errors so callers don't silently mistake them for "not in cloud".
|
|
324
357
|
*
|
|
325
358
|
* Options:
|
|
326
359
|
* - fallbackToCloud: boolean (default true) — set false to skip cloud fetch
|
|
@@ -329,7 +362,7 @@ export declare class Tero {
|
|
|
329
362
|
getWithRecovery(key: string, options?: {
|
|
330
363
|
fallbackToCloud?: boolean;
|
|
331
364
|
mode?: 'missing' | 'all';
|
|
332
|
-
}): Promise<any>;
|
|
365
|
+
}): Promise<any | null>;
|
|
333
366
|
/**
|
|
334
367
|
* Probe local + cloud availability for a key without modifying local state.
|
|
335
368
|
* Returns { local, cloud, canRecover }:
|
|
@@ -357,14 +390,16 @@ export declare class Tero {
|
|
|
357
390
|
}>;
|
|
358
391
|
clearCache(): void;
|
|
359
392
|
/**
|
|
360
|
-
* Acquire an exclusive
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
393
|
+
* Acquire an exclusive lock on the data directory via a `.lock` file
|
|
394
|
+
* (openSync 'wx' exclusive-create — no native modules, cross-platform).
|
|
395
|
+
* The holder's PID is written to the file; if acquisition fails and the
|
|
396
|
+
* recorded PID is no longer alive, the stale lock from a crashed process
|
|
397
|
+
* is reclaimed automatically.
|
|
365
398
|
*/
|
|
366
399
|
private acquireFileLock;
|
|
367
400
|
private releaseFileLock;
|
|
401
|
+
destroyAsync(): Promise<void>;
|
|
402
|
+
close(): Promise<void>;
|
|
368
403
|
destroy(): void;
|
|
369
404
|
/**
|
|
370
405
|
* Generates a unique identifier with a custom prefix.
|
|
@@ -395,4 +430,4 @@ export declare class Tero {
|
|
|
395
430
|
*/
|
|
396
431
|
getNewId(prefix: string): string;
|
|
397
432
|
}
|
|
398
|
-
export { DocumentSchema, ValidationResult, BackupConfig, BackupMetadata, BucketBackupResult, CloudStorageConfig, RecoveryConfig, RecoveryResult, FileRecoveryInfo, HydrateConfig };
|
|
433
|
+
export { DocumentSchema, ValidationResult, BackupConfig, BackupMetadata, BucketBackupResult, CloudStorageConfig, RecoveryConfig, RecoveryResult, FileRecoveryInfo, HydrateConfig, TeroConfig, LiveBackupOptions, LiveBackupStatus, LiveCheckpointResult, RestoreLiveResult, BackupLogger };
|