tero 0.1.2 → 0.3.1

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
@@ -44,8 +44,15 @@ interface TeroConfig {
44
44
  * true in production; default false for backwards compatibility.
45
45
  */
46
46
  fileLock?: boolean;
47
+ /**
48
+ * Durable checkpoint cadence (ms). Every interval with new commits, data files are
49
+ * fsynced and a durable CHECKPOINT is logged, so a restart only replays WAL written
50
+ * since then — boot time and memory stay bounded no matter how long the process
51
+ * ran. Default 30000. 0 disables (a checkpoint is still taken on close).
52
+ */
53
+ durableCheckpointIntervalMs?: number;
47
54
  }
48
- type HydrationMode = 'lazy' | 'eager';
55
+ type HydrationMode = 'lazy' | 'eager' | 'off';
49
56
  interface HydrateConfig {
50
57
  cloudStorage: CloudStorageConfig;
51
58
  /**
@@ -96,6 +103,8 @@ export declare class Transaction {
96
103
  getAbortError(): Error | null;
97
104
  private _checkActive;
98
105
  create(key: string, initialData?: any): Promise<void>;
106
+ /** Replace the whole document within this transaction (see Tero.set). */
107
+ set(key: string, data: any): Promise<void>;
99
108
  update(key: string, data: any): Promise<void>;
100
109
  delete(key: string): Promise<void>;
101
110
  /**
@@ -231,6 +240,18 @@ export declare class Tero {
231
240
  private initializeDirectories;
232
241
  private static readonly MAX_KEY_LENGTH;
233
242
  private validateKey;
243
+ /** True when deletes/re-creates must be mirrored to the bucket (lazy/eager hydration). */
244
+ private cloudReconcileEnabled;
245
+ /**
246
+ * Keys known to have a tombstone in the bucket. A commit only issues the cloud
247
+ * tombstone DELETE for keys in this set (or with a local tombstone / pending
248
+ * queue entry) — previously every single commit awaited a DeleteObject.
249
+ * Bounded; on eviction the bucket's newest-wins rule (document vs tombstone
250
+ * LastModified) still keeps a later backup authoritative.
251
+ */
252
+ private knownCloudTombstones;
253
+ /** Fallback when the durable queue file was lost (ENOSPC): rebuild it from local tombstones. */
254
+ private requeueTombstonesFromDisk;
234
255
  private bumpGeneration;
235
256
  private getGeneration;
236
257
  /**
@@ -244,7 +265,14 @@ export declare class Tero {
244
265
  beginTransaction(options?: TransactionOptions): Transaction;
245
266
  private _beginTransaction;
246
267
  private _txId;
247
- write(transactionId: string | Transaction, key: string, data: any): Promise<void>;
268
+ /**
269
+ * Write inside a transaction. Default: deep-merge `data` into the current document.
270
+ * With `{ replace: true }` the document becomes exactly `data` — the only way to
271
+ * remove a field (a merge can add and change fields but never drop one).
272
+ */
273
+ write(transactionId: string | Transaction, key: string, data: any, options?: {
274
+ replace?: boolean;
275
+ }): Promise<void>;
248
276
  read(transactionId: string | Transaction, key: string, options?: {
249
277
  lock?: 'shared' | 'exclusive';
250
278
  }): Promise<any>;
@@ -259,6 +287,12 @@ export declare class Tero {
259
287
  totalRequests: number;
260
288
  };
261
289
  create(key: string, initialData?: any): Promise<boolean>;
290
+ /**
291
+ * Upsert that REPLACES the whole document (creates it if absent). Unlike
292
+ * update(), fields missing from `data` are removed — use this whenever the
293
+ * caller holds the complete document (read-modify-write).
294
+ */
295
+ set(key: string, data: any): Promise<void>;
262
296
  update(key: string, data: any): Promise<void>;
263
297
  /**
264
298
  * Read a document. Returns the document data on success, or `null` if the
@@ -335,12 +369,13 @@ export declare class Tero {
335
369
  batchWrite(operations: Array<{
336
370
  key: string;
337
371
  data: any;
372
+ replace?: boolean;
338
373
  }>): Promise<void>;
339
374
  batchRead(keys: string[]): Promise<{
340
375
  [key: string]: any;
341
376
  }>;
342
377
  transferMoney(fromKey: string, toKey: string, amount: number): Promise<void>;
343
- _writeRaw(transactionId: string, key: string, data: any): Promise<void>;
378
+ _writeRaw(transactionId: string, key: string, data: any, replace?: boolean): Promise<void>;
344
379
  _readRaw(transactionId: string, key: string): Promise<any>;
345
380
  _deleteRaw(transactionId: string, key: string): Promise<void>;
346
381
  _rollbackRaw(transactionId: string): Promise<void>;
@@ -418,7 +453,9 @@ export declare class Tero {
418
453
  * new directory name (disaster-recovery / staging restores). Defaults to `directory`. */
419
454
  sourceDirectory?: string;
420
455
  }): Promise<Tero>;
421
- configureDataRecovery(config: RecoveryConfig): void;
456
+ configureDataRecovery(config: RecoveryConfig & {
457
+ mode?: 'lazy' | 'off';
458
+ }): void;
422
459
  recoverFromCloud(key: string): Promise<boolean>;
423
460
  recoverAllFromCloud(): Promise<RecoveryResult>;
424
461
  /** Recovery info: how many cloud files exist, which are missing locally, which can be pulled. */