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/dist/backup.d.ts CHANGED
@@ -10,6 +10,8 @@ export interface LiveBackupStatus {
10
10
  checkpointsTaken: number;
11
11
  errorCount: number;
12
12
  lastError?: string;
13
+ /** Last error from liveCheckpointToBucket (initial or manual). Cleared on success. */
14
+ lastCheckpointError?: string;
13
15
  }
14
16
  export interface LiveBackupOptions {
15
17
  /** The only consistency level live backup offers: RPO ≤ 1 second of committed writes. */
@@ -19,6 +21,12 @@ export interface LiveBackupOptions {
19
21
  /** Stable identity for this node in the bucket. Persisted to <dbPath>/.tero-node-id. */
20
22
  nodeId?: string;
21
23
  }
24
+ export interface LiveCheckpointResult {
25
+ uploadedDocs: number;
26
+ tombstonedDocs: number;
27
+ fullUpload: boolean;
28
+ duration: number;
29
+ }
22
30
  export interface RestoreLiveResult {
23
31
  nodeId: string;
24
32
  docsRestored: number;
@@ -34,7 +42,16 @@ export interface CloudStorageConfig {
34
42
  secretAccessKey: string;
35
43
  endpoint?: string;
36
44
  pathPrefix?: string;
45
+ /** Override the derived bucket subprefix (avoids basename collisions). Defaults to "<basename>-<hash>". */
46
+ dbName?: string;
37
47
  }
48
+ /** Injectable logger for BackupManager. Pass your own to route backup logs into
49
+ * your observability stack, or pass console. Default is silent to prevent log noise. */
50
+ export type BackupLogger = {
51
+ info: (...args: any[]) => void;
52
+ warn: (...args: any[]) => void;
53
+ error: (...args: any[]) => void;
54
+ };
38
55
  export interface BackupConfig {
39
56
  interval?: string;
40
57
  retention?: string;
@@ -44,6 +61,9 @@ export interface BackupConfig {
44
61
  compression?: boolean;
45
62
  includeMetadata?: boolean;
46
63
  metadataUse?: 'verification' | 'audit' | 'recovery' | 'none';
64
+ logger?: 'silent' | BackupLogger;
65
+ /** Override bucket subprefix (takes precedence over cloudStorage.dbName). */
66
+ bucketPrefix?: string;
47
67
  }
48
68
  export interface BackupMetadata {
49
69
  timestamp: string;
@@ -65,6 +85,8 @@ export declare class BackupManager {
65
85
  private scheduledBackups;
66
86
  private config;
67
87
  private dbPath;
88
+ /** Injected or default logger (see BackupConfig.logger). */
89
+ private log;
68
90
  constructor(dbPath: string, config: BackupConfig);
69
91
  private initializeCloudStorage;
70
92
  private parseInterval;
@@ -85,6 +107,16 @@ export declare class BackupManager {
85
107
  private uploadToCloud;
86
108
  private uploadDirectoryToCloud;
87
109
  private uploadIndividualFilesToCloud;
110
+ /**
111
+ * Derive a collision-free bucket key prefix for this DB instance.
112
+ * The old `basename(dbPath)` implementation made `/tmp/a/TeroDB` and
113
+ * `/tmp/b/TeroDB` collide on the same prefix (cross-tenant overwrite).
114
+ * We now use `pathPrefix/<safeDbName>` where `safeDbName` is derived from
115
+ * the FULL resolved path when a custom `dbName` isn't supplied.
116
+ * Explicit `cloudStorage.dbName` or `BackupConfig.bucketPrefix` takes
117
+ * precedence for callers who want stable, human-readable prefixes.
118
+ */
119
+ private getDbName;
88
120
  private getCloudKey;
89
121
  performBackup(): Promise<{
90
122
  success: boolean;
@@ -126,22 +158,27 @@ export declare class BackupManager {
126
158
  private liveEngine?;
127
159
  private livePrefix?;
128
160
  private liveCheckpoints;
161
+ /** In-flight checkpoint (shared promise: concurrent callers await the same run). */
162
+ private liveCheckpointPromise?;
163
+ private lastCheckpointError?;
164
+ drainInFlight(): Promise<void>;
129
165
  destroy(): void;
130
166
  private liveCloudPrefix;
131
167
  private uploadBytes;
132
168
  private downloadBytes;
133
169
  private readJsonOrDefault;
134
170
  private listPrefix;
171
+ private listPrefixWithMeta;
172
+ private deleteObject;
135
173
  enableLiveBackup(engine: ACIDStorageEngine, opts: LiveBackupOptions): void;
174
+ /** Initial full checkpoint with bounded retry. Stops on success or disable. */
175
+ private runInitialCheckpoint;
136
176
  disableLiveBackup(): void;
137
177
  getLiveBackupStatus(): LiveBackupStatus;
138
178
  liveCheckpointToBucket(_opts?: {
139
179
  tag?: string;
140
- }): Promise<{
141
- uploadedDocs: number;
142
- fullUpload: boolean;
143
- duration: number;
144
- }>;
180
+ }): Promise<LiveCheckpointResult>;
181
+ private doLiveCheckpoint;
145
182
  restoreLiveToDirectory(targetDir: string, opts?: {
146
183
  nodeId?: string;
147
184
  pointInTime?: number;