@lifestreamdynamics/vault-cli 1.3.10 → 1.3.11
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/commands/sync.js +9 -5
- package/dist/sync/engine.d.ts +7 -2
- package/dist/sync/engine.js +46 -10
- package/package.json +1 -1
package/dist/commands/sync.js
CHANGED
|
@@ -9,7 +9,7 @@ import { formatUptime } from '../utils/format.js';
|
|
|
9
9
|
import { loadSyncConfigs, createSyncConfig, deleteSyncConfig, getSyncConfig, } from '../sync/config.js';
|
|
10
10
|
import { deleteSyncState, loadSyncState, saveSyncState, hashFileContent, buildRemoteFileState } from '../sync/state.js';
|
|
11
11
|
import { resolveIgnorePatterns } from '../sync/ignore.js';
|
|
12
|
-
import { scanLocalFiles, scanRemoteFiles, executePull, executePush, computePullDiff, computePushDiff, } from '../sync/engine.js';
|
|
12
|
+
import { scanLocalFiles, scanRemoteFiles, executePull, executePush, computePullDiff, computePushDiff, resolveConcurrency, } from '../sync/engine.js';
|
|
13
13
|
import { formatDiff } from '../sync/diff.js';
|
|
14
14
|
import { createWatcher } from '../sync/watcher.js';
|
|
15
15
|
import { createRemotePoller } from '../sync/remote-poller.js';
|
|
@@ -153,7 +153,8 @@ Sync modes:
|
|
|
153
153
|
// sync pull <syncId>
|
|
154
154
|
addGlobalFlags(sync.command('pull')
|
|
155
155
|
.description('Pull remote changes to local directory')
|
|
156
|
-
.argument('<syncId>', 'Sync configuration ID')
|
|
156
|
+
.argument('<syncId>', 'Sync configuration ID')
|
|
157
|
+
.option('--concurrency <n>', 'Max concurrent file transfers (1-16, default 4)', (v) => parseInt(v, 10)))
|
|
157
158
|
.action(async (syncId, _opts) => {
|
|
158
159
|
const flags = resolveFlags(_opts);
|
|
159
160
|
const out = createOutput(flags);
|
|
@@ -211,12 +212,13 @@ Sync modes:
|
|
|
211
212
|
if (flags.verbose) {
|
|
212
213
|
out.status(formatDiff(diff));
|
|
213
214
|
}
|
|
215
|
+
const concurrency = resolveConcurrency(_opts.concurrency);
|
|
214
216
|
out.startSpinner(`Pulling ${totalOps} file(s)...`);
|
|
215
217
|
const result = await executePull(client, config, diff, (progress) => {
|
|
216
218
|
if (progress.phase === 'transferring' && progress.currentFile) {
|
|
217
219
|
out.startSpinner(`[${progress.current}/${progress.total}] ${progress.currentFile}`);
|
|
218
220
|
}
|
|
219
|
-
});
|
|
221
|
+
}, concurrency);
|
|
220
222
|
if (result.errors.length > 0) {
|
|
221
223
|
out.failSpinner(`Pull completed with ${result.errors.length} error(s)`);
|
|
222
224
|
for (const err of result.errors) {
|
|
@@ -241,7 +243,8 @@ Sync modes:
|
|
|
241
243
|
// sync push <syncId>
|
|
242
244
|
addGlobalFlags(sync.command('push')
|
|
243
245
|
.description('Push local changes to remote vault')
|
|
244
|
-
.argument('<syncId>', 'Sync configuration ID')
|
|
246
|
+
.argument('<syncId>', 'Sync configuration ID')
|
|
247
|
+
.option('--concurrency <n>', 'Max concurrent file transfers (1-16, default 4)', (v) => parseInt(v, 10)))
|
|
245
248
|
.action(async (syncId, _opts) => {
|
|
246
249
|
const flags = resolveFlags(_opts);
|
|
247
250
|
const out = createOutput(flags);
|
|
@@ -299,12 +302,13 @@ Sync modes:
|
|
|
299
302
|
if (flags.verbose) {
|
|
300
303
|
out.status(formatDiff(diff));
|
|
301
304
|
}
|
|
305
|
+
const concurrency = resolveConcurrency(_opts.concurrency);
|
|
302
306
|
out.startSpinner(`Pushing ${totalOps} file(s)...`);
|
|
303
307
|
const result = await executePush(client, config, diff, (progress) => {
|
|
304
308
|
if (progress.phase === 'transferring' && progress.currentFile) {
|
|
305
309
|
out.startSpinner(`[${progress.current}/${progress.total}] ${progress.currentFile}`);
|
|
306
310
|
}
|
|
307
|
-
});
|
|
311
|
+
}, concurrency);
|
|
308
312
|
if (result.errors.length > 0) {
|
|
309
313
|
out.failSpinner(`Push completed with ${result.errors.length} error(s)`);
|
|
310
314
|
for (const err of result.errors) {
|
package/dist/sync/engine.d.ts
CHANGED
|
@@ -30,12 +30,17 @@ export declare function scanLocalFiles(localPath: string, ignorePatterns: string
|
|
|
30
30
|
* Returns a map of doc paths -> FileState.
|
|
31
31
|
*/
|
|
32
32
|
export declare function scanRemoteFiles(client: LifestreamVaultClient, vaultId: string, ignorePatterns: string[]): Promise<Record<string, FileState>>;
|
|
33
|
+
/**
|
|
34
|
+
* Validates and clamps a user-supplied concurrency value. Throws on invalid
|
|
35
|
+
* values so the CLI can surface a clear error before kicking off any I/O.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveConcurrency(value: number | undefined): number;
|
|
33
38
|
/**
|
|
34
39
|
* Execute a pull operation: download remote changes to local.
|
|
35
40
|
*/
|
|
36
|
-
export declare function executePull(client: LifestreamVaultClient, config: SyncConfig, diff: SyncDiff, onProgress?: ProgressCallback): Promise<SyncResult>;
|
|
41
|
+
export declare function executePull(client: LifestreamVaultClient, config: SyncConfig, diff: SyncDiff, onProgress?: ProgressCallback, concurrency?: number): Promise<SyncResult>;
|
|
37
42
|
/**
|
|
38
43
|
* Execute a push operation: upload local changes to remote.
|
|
39
44
|
*/
|
|
40
|
-
export declare function executePush(client: LifestreamVaultClient, config: SyncConfig, diff: SyncDiff, onProgress?: ProgressCallback): Promise<SyncResult>;
|
|
45
|
+
export declare function executePush(client: LifestreamVaultClient, config: SyncConfig, diff: SyncDiff, onProgress?: ProgressCallback, concurrency?: number): Promise<SyncResult>;
|
|
41
46
|
export { computePullDiff, computePushDiff, type SyncDiff, type SyncDiffEntry };
|
package/dist/sync/engine.js
CHANGED
|
@@ -54,7 +54,7 @@ export async function scanRemoteFiles(client, vaultId, ignorePatterns) {
|
|
|
54
54
|
if (!shouldIgnore(doc.path, ignorePatterns)) {
|
|
55
55
|
files[doc.path] = {
|
|
56
56
|
path: doc.path,
|
|
57
|
-
hash:
|
|
57
|
+
hash: doc.contentHash,
|
|
58
58
|
mtime: doc.fileModifiedAt,
|
|
59
59
|
size: doc.sizeBytes,
|
|
60
60
|
};
|
|
@@ -71,12 +71,31 @@ function atomicWriteFileSync(targetPath, content, encoding = 'utf-8') {
|
|
|
71
71
|
fs.writeFileSync(tmpFile, content, encoding);
|
|
72
72
|
fs.renameSync(tmpFile, targetPath);
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Default in-flight transfer count. A small number flattens the load1 spike
|
|
76
|
+
* a full-vault `sync pull` causes on the API host without making single
|
|
77
|
+
* transfers measurably slower.
|
|
78
|
+
*/
|
|
79
|
+
const DEFAULT_TRANSFER_CONCURRENCY = 4;
|
|
80
|
+
const MAX_TRANSFER_CONCURRENCY = 16;
|
|
81
|
+
/**
|
|
82
|
+
* Validates and clamps a user-supplied concurrency value. Throws on invalid
|
|
83
|
+
* values so the CLI can surface a clear error before kicking off any I/O.
|
|
84
|
+
*/
|
|
85
|
+
export function resolveConcurrency(value) {
|
|
86
|
+
if (value === undefined)
|
|
87
|
+
return DEFAULT_TRANSFER_CONCURRENCY;
|
|
88
|
+
if (!Number.isInteger(value) || value < 1 || value > MAX_TRANSFER_CONCURRENCY) {
|
|
89
|
+
throw new Error(`--concurrency must be an integer between 1 and ${MAX_TRANSFER_CONCURRENCY} (got ${value})`);
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
74
93
|
/**
|
|
75
94
|
* Shared sync operation executor used by both pull and push.
|
|
76
95
|
* Handles result initialization, state loading, progress callbacks,
|
|
77
96
|
* quota error handling, state saving, and lastSync update.
|
|
78
97
|
*/
|
|
79
|
-
async function executeSyncOperation(config, diff, handlers, onProgress) {
|
|
98
|
+
async function executeSyncOperation(config, diff, handlers, onProgress, concurrency = DEFAULT_TRANSFER_CONCURRENCY) {
|
|
80
99
|
const result = {
|
|
81
100
|
filesUploaded: 0,
|
|
82
101
|
filesDownloaded: 0,
|
|
@@ -87,7 +106,12 @@ async function executeSyncOperation(config, diff, handlers, onProgress) {
|
|
|
87
106
|
const state = loadSyncState(config.id);
|
|
88
107
|
const allOps = [...handlers.transfers, ...handlers.deletes];
|
|
89
108
|
let current = 0;
|
|
90
|
-
|
|
109
|
+
// Once a quota error is hit anywhere in the pool we stop submitting new
|
|
110
|
+
// work but let in-flight transfers drain to keep state consistent.
|
|
111
|
+
let stopSubmitting = false;
|
|
112
|
+
async function runOne(entry) {
|
|
113
|
+
if (stopSubmitting)
|
|
114
|
+
return;
|
|
91
115
|
current++;
|
|
92
116
|
onProgress?.({
|
|
93
117
|
phase: 'transferring',
|
|
@@ -112,13 +136,25 @@ async function executeSyncOperation(config, diff, handlers, onProgress) {
|
|
|
112
136
|
}
|
|
113
137
|
catch (err) {
|
|
114
138
|
const message = err instanceof Error ? err.message : String(err);
|
|
139
|
+
result.errors.push({ path: entry.path, error: message });
|
|
115
140
|
if (isQuotaError(message)) {
|
|
116
|
-
|
|
117
|
-
break; // Stop immediately on quota errors
|
|
141
|
+
stopSubmitting = true;
|
|
118
142
|
}
|
|
119
|
-
result.errors.push({ path: entry.path, error: message });
|
|
120
143
|
}
|
|
121
144
|
}
|
|
145
|
+
// Bounded async pool. Workers race for entries off the queue tail; once
|
|
146
|
+
// the queue is empty (or stopSubmitting is set), each worker exits and
|
|
147
|
+
// Promise.all resolves only after every in-flight transfer has settled.
|
|
148
|
+
const queue = handlers.transfers.slice();
|
|
149
|
+
const poolSize = Math.min(Math.max(1, concurrency), Math.max(1, queue.length));
|
|
150
|
+
await Promise.all(Array.from({ length: poolSize }, async () => {
|
|
151
|
+
while (!stopSubmitting) {
|
|
152
|
+
const entry = queue.shift();
|
|
153
|
+
if (!entry)
|
|
154
|
+
return;
|
|
155
|
+
await runOne(entry);
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
122
158
|
for (const entry of handlers.deletes) {
|
|
123
159
|
current++;
|
|
124
160
|
onProgress?.({
|
|
@@ -154,7 +190,7 @@ async function executeSyncOperation(config, diff, handlers, onProgress) {
|
|
|
154
190
|
/**
|
|
155
191
|
* Execute a pull operation: download remote changes to local.
|
|
156
192
|
*/
|
|
157
|
-
export async function executePull(client, config, diff, onProgress) {
|
|
193
|
+
export async function executePull(client, config, diff, onProgress, concurrency) {
|
|
158
194
|
return executeSyncOperation(config, diff, {
|
|
159
195
|
transfers: diff.downloads,
|
|
160
196
|
deletes: diff.deletes,
|
|
@@ -175,12 +211,12 @@ export async function executePull(client, config, diff, onProgress) {
|
|
|
175
211
|
fs.unlinkSync(localFile);
|
|
176
212
|
}
|
|
177
213
|
},
|
|
178
|
-
}, onProgress);
|
|
214
|
+
}, onProgress, concurrency);
|
|
179
215
|
}
|
|
180
216
|
/**
|
|
181
217
|
* Execute a push operation: upload local changes to remote.
|
|
182
218
|
*/
|
|
183
|
-
export async function executePush(client, config, diff, onProgress) {
|
|
219
|
+
export async function executePush(client, config, diff, onProgress, concurrency) {
|
|
184
220
|
return executeSyncOperation(config, diff, {
|
|
185
221
|
transfers: diff.uploads,
|
|
186
222
|
deletes: diff.deletes,
|
|
@@ -194,7 +230,7 @@ export async function executePush(client, config, diff, onProgress) {
|
|
|
194
230
|
async deleteFile(entry, cfg) {
|
|
195
231
|
await retryWithBackoff(() => client.documents.delete(cfg.vaultId, entry.path));
|
|
196
232
|
},
|
|
197
|
-
}, onProgress);
|
|
233
|
+
}, onProgress, concurrency);
|
|
198
234
|
}
|
|
199
235
|
/**
|
|
200
236
|
* Retry a function with exponential backoff (max 3 retries).
|