tero 0.0.9 → 0.0.10

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
@@ -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 OS-level file lock (flock) on the data directory to
30
- * prevent concurrent process access. Two Node.js processes opening the same
31
- * directory without this flag will corrupt each other's data. Set to true
32
- * in production; default false for backwards compatibility.
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,6 +60,10 @@ 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;
63
68
  private timeoutTimer?;
64
69
  constructor(id: string, db: Tero, options?: TransactionOptions);
@@ -102,7 +107,7 @@ export declare class Tero {
102
107
  */
103
108
  private knownKeys;
104
109
  private readonly KNOWN_KEYS_MAX;
105
- /** Optional exclusive file-lock fd on the data directory (flock, via fs-ext). */
110
+ /** Exclusive lock fd on <dir>/.lock (lock-file based; see acquireFileLock). */
106
111
  private lockFd?;
107
112
  /**
108
113
  * Construct an embedded Tero instance synchronously.
@@ -183,7 +188,12 @@ export declare class Tero {
183
188
  get(key: string): Promise<any>;
184
189
  /**
185
190
  * Map a document key to its partitioned path on disk (2-level hash-prefix).
186
- * Matches the layout used by ACIDStorageEngine — same key resolves to same path.
191
+ * Delegates to the ENGINE'S partitionedPath() — the single authoritative
192
+ * implementation. The previous local FNV-1a re-implementation produced the
193
+ * same paths only by convention; if the two ever drifted, get() would read a
194
+ * different file than the engine writes (silent data loss). The engine's
195
+ * hash computes a 64-bit value (2 imul/char vs 1) but this runs only on
196
+ * cache-miss reads, which are syscall-dominated — measured impact: none.
187
197
  */
188
198
  private keyToPath;
189
199
  remove(key: string): Promise<void>;
@@ -283,20 +293,20 @@ export declare class Tero {
283
293
  disableLiveBackup(): void;
284
294
  /** Current live-backup health and counters. */
285
295
  getLiveBackupStatus(): LiveBackupStatus;
286
- /** Take an incremental checkpoint (uploads only dirty docs). First call = full upload. */
296
+ /** Take a checkpoint: FULL on the first call after enable (also taken
297
+ * automatically), INCREMENTAL (only dirty docs) on subsequent calls. */
287
298
  liveCheckpointToBucket(opts?: {
288
299
  tag?: string;
289
- }): Promise<{
290
- uploadedDocs: number;
291
- fullUpload: boolean;
292
- duration: number;
293
- }>;
300
+ }): Promise<LiveCheckpointResult>;
294
301
  /** Restore a fresh Tero instance from a live backup in the bucket. */
295
302
  static restoreFromLiveBackup(opts: {
296
303
  directory: string;
297
304
  cloudStorage: CloudStorageConfig;
298
305
  nodeId?: string;
299
306
  pointInTime?: number;
307
+ /** Name of the ORIGINAL database directory in the bucket, if restoring to a
308
+ * new directory name (disaster-recovery / staging restores). Defaults to `directory`. */
309
+ sourceDirectory?: string;
300
310
  }): Promise<Tero>;
301
311
  configureDataRecovery(config: RecoveryConfig): void;
302
312
  recoverFromCloud(key: string): Promise<boolean>;
@@ -357,11 +367,11 @@ export declare class Tero {
357
367
  }>;
358
368
  clearCache(): void;
359
369
  /**
360
- * Acquire an exclusive OS-level lock on the data directory via a .lock file.
361
- * Uses `openSync(path, 'wx')` — creates the file exclusively, failing if it
362
- * already exists (i.e., another process holds the lock). Cross-platform,
363
- * no native modules required. The fd is held open to maintain the lock;
364
- * destroying the Tero instance closes the fd and deletes the lock file.
370
+ * Acquire an exclusive lock on the data directory via a `.lock` file
371
+ * (openSync 'wx' exclusive-create — no native modules, cross-platform).
372
+ * The holder's PID is written to the file; if acquisition fails and the
373
+ * recorded PID is no longer alive, the stale lock from a crashed process
374
+ * is reclaimed automatically.
365
375
  */
366
376
  private acquireFileLock;
367
377
  private releaseFileLock;
@@ -395,4 +405,4 @@ export declare class Tero {
395
405
  */
396
406
  getNewId(prefix: string): string;
397
407
  }
398
- export { DocumentSchema, ValidationResult, BackupConfig, BackupMetadata, BucketBackupResult, CloudStorageConfig, RecoveryConfig, RecoveryResult, FileRecoveryInfo, HydrateConfig };
408
+ export { DocumentSchema, ValidationResult, BackupConfig, BackupMetadata, BucketBackupResult, CloudStorageConfig, RecoveryConfig, RecoveryResult, FileRecoveryInfo, HydrateConfig, TeroConfig, LiveBackupOptions, LiveBackupStatus, LiveCheckpointResult, RestoreLiveResult, BackupLogger };