poad 2.61.2 → 2.63.0
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/global/start.js +5 -1
- package/package.json +1 -1
- package/project/cli.js +6 -3
- package/project/source.js +286 -0
- package/project/sources.js +2 -0
- package/project/storage/cp.js +45 -15
- package/project/storage/ls.js +20 -6
- package/project/storage/mv.js +5 -5
- package/project/storage/sync.js +101 -0
- package/test/source.test.js +245 -0
- package/test/storage-sync.test.js +283 -0
- package/test/storage.test.js +233 -4
- package/utils/cloud/bundle.js +2 -2
- package/utils/help-details.js +64 -5
- package/utils/logline.js +2 -2
- package/utils/storage-copy.js +91 -15
- package/utils/storage-sync.js +277 -0
- package/utils/storage.js +94 -3
package/test/storage.test.js
CHANGED
|
@@ -5,6 +5,8 @@ const os = require('os');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const s = require('../utils/storage');
|
|
7
7
|
const c = require('../utils/storage-copy');
|
|
8
|
+
const crypto = require('crypto');
|
|
9
|
+
const md5 = (b) => crypto.createHash('md5').update(b).digest('hex');
|
|
8
10
|
|
|
9
11
|
test('parseRemote: bucket, key, folder', () => {
|
|
10
12
|
assert.deepStrictEqual(s.parseRemote('poad:images/a/b.png'), { bucket: 'images', key: 'a/b.png', dir: false });
|
|
@@ -39,7 +41,8 @@ test('entries: folders first with count and size, then files', () => {
|
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
// Faux Stockage en mémoire, derrière un fetch : les routes que le CLI appelle
|
|
42
|
-
|
|
44
|
+
// folders : le service connaît la vue d'un dossier (storage 0.5+ : { prefix, delimiter: "/" })
|
|
45
|
+
function fakeStorage(initial = {}, { limit = Infinity, folders = false } = {}) {
|
|
43
46
|
const objects = new Map(Object.entries(initial));
|
|
44
47
|
const seen = [];
|
|
45
48
|
const doFetch = async (url, init = {}) => {
|
|
@@ -49,12 +52,30 @@ function fakeStorage(initial = {}) {
|
|
|
49
52
|
const json = (status, body) => new Response(body === undefined ? null : JSON.stringify(body), { status });
|
|
50
53
|
let m;
|
|
51
54
|
if ((m = /^\/object\/list\/([^/]+)$/.exec(route))) {
|
|
52
|
-
const { prefix, limit, offset } = JSON.parse(init.body);
|
|
55
|
+
const { prefix, limit, offset, delimiter } = JSON.parse(init.body);
|
|
56
|
+
if (folders && delimiter === '/') {
|
|
57
|
+
const under = [...objects.keys()].filter((k) => k.startsWith(`${m[1]}/${prefix}`)).sort().map((k) => k.slice(m[1].length + 1));
|
|
58
|
+
const view = new Map();
|
|
59
|
+
const direct = [];
|
|
60
|
+
for (const name of under) {
|
|
61
|
+
const rest = name.slice(prefix.length);
|
|
62
|
+
const cut = rest.indexOf('/');
|
|
63
|
+
if (cut < 0) direct.push(name);
|
|
64
|
+
else {
|
|
65
|
+
const f = view.get(rest.slice(0, cut)) || { name: rest.slice(0, cut), files: 0, size: 0, updated_at: '2026-12-01T10:00:00Z' };
|
|
66
|
+
f.files++;
|
|
67
|
+
f.size += objects.get(`${m[1]}/${name}`).body.length;
|
|
68
|
+
view.set(f.name, f);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const meta = (name) => ({ size: objects.get(`${m[1]}/${name}`).body.length, mimetype: objects.get(`${m[1]}/${name}`).type });
|
|
72
|
+
return json(200, { prefix, folders: [...view.values()], files: direct.slice(offset, offset + limit).map((name) => ({ name, metadata: meta(name), updated_at: '2026-12-01T10:00:00Z' })), total_files: direct.length });
|
|
73
|
+
}
|
|
53
74
|
const rows = [...objects.keys()]
|
|
54
75
|
.filter((k) => k.startsWith(`${m[1]}/${prefix}`))
|
|
55
76
|
.sort()
|
|
56
77
|
.slice(offset, offset + limit)
|
|
57
|
-
.map((k) => ({ name: k.slice(m[1].length + 1), metadata: { size: objects.get(k).body.length, mimetype: objects.get(k).type }, updated_at: '2026-12-01T10:00:00Z' }));
|
|
78
|
+
.map((k) => ({ name: k.slice(m[1].length + 1), metadata: { size: objects.get(k).body.length, mimetype: objects.get(k).type, etag: md5(objects.get(k).body) }, updated_at: '2026-12-01T10:00:00Z' }));
|
|
58
79
|
return json(200, rows);
|
|
59
80
|
}
|
|
60
81
|
if ((m = /^\/object\/([^/]+)$/.exec(route)) && init.method === 'DELETE') {
|
|
@@ -64,9 +85,14 @@ function fakeStorage(initial = {}) {
|
|
|
64
85
|
}
|
|
65
86
|
if ((m = /^\/object\/(.+)$/.exec(route))) {
|
|
66
87
|
if (init.method === 'PUT') {
|
|
88
|
+
seen.push({ put: m[1] });
|
|
89
|
+
// Comme le storage : la taille annoncée, puis la taille reçue
|
|
90
|
+
if (Number(init.headers['content-length']) > limit) return json(413, { statusCode: '413', error: 'EntityTooLarge', message: `taille maximale : ${limit} octets` });
|
|
67
91
|
const chunks = [];
|
|
68
92
|
for await (const ch of init.body) chunks.push(Buffer.from(ch));
|
|
69
|
-
|
|
93
|
+
const body = Buffer.concat(chunks);
|
|
94
|
+
if (body.length > limit) return json(413, { statusCode: '413', error: 'EntityTooLarge', message: `taille maximale : ${limit} octets` });
|
|
95
|
+
objects.set(m[1], { body, type: init.headers['content-type'] });
|
|
70
96
|
return json(201, { name: m[1] });
|
|
71
97
|
}
|
|
72
98
|
const o = objects.get(m[1]);
|
|
@@ -184,3 +210,206 @@ test('client: hosted, anon key for the gateway, storage token renewed before it
|
|
|
184
210
|
test('target: --env or --project goes to poad.io, else the local engine', async () => {
|
|
185
211
|
await assert.rejects(s.target({}, { started: async () => true }), /not in a poad project|service_role|started/);
|
|
186
212
|
});
|
|
213
|
+
|
|
214
|
+
test('concurrency: 1 to 32, default 4, anything else is a usage error', () => {
|
|
215
|
+
assert.strictEqual(s.concurrency(undefined), 4);
|
|
216
|
+
assert.strictEqual(s.concurrency('1'), 1);
|
|
217
|
+
assert.strictEqual(s.concurrency('32'), 32);
|
|
218
|
+
for (const bad of ['0', '33', '-2', '2.5', 'x', ''])
|
|
219
|
+
assert.throws(() => s.concurrency(bad), (e) => e.code === 'usage' && /1 to 32/.test(e.message));
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('each: never more than the concurrency asked at once', async () => {
|
|
223
|
+
let now = 0;
|
|
224
|
+
let max = 0;
|
|
225
|
+
await s.each(Array.from({ length: 20 }, (_, i) => i), async () => {
|
|
226
|
+
max = Math.max(max, ++now);
|
|
227
|
+
await new Promise((r) => setTimeout(r, 2));
|
|
228
|
+
now--;
|
|
229
|
+
}, 7);
|
|
230
|
+
assert.strictEqual(max, 7);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('reason: the size limit of the storage, readable', () => {
|
|
234
|
+
const { CloudError } = require('../utils/cloud/api');
|
|
235
|
+
assert.strictEqual(s.reason(new CloudError('taille maximale : 52428800 octets', { status: 413 })), 'too large: the storage accepts at most 52428800 bytes (50 MB) per file');
|
|
236
|
+
assert.strictEqual(s.reason(new CloudError('HTTP 413', { status: 413 })), 'too large for the storage (HTTP 413)');
|
|
237
|
+
assert.strictEqual(s.reason(new Error('bucket introuvable')), 'bucket introuvable');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('commonDir: one list per destination folder', () => {
|
|
241
|
+
assert.strictEqual(c.commonDir(['a/b/c.png']), 'a/b/c.png');
|
|
242
|
+
assert.strictEqual(c.commonDir(['site/a.html', 'site/css/s.css']), 'site/');
|
|
243
|
+
assert.strictEqual(c.commonDir(['site/a', 'sitemap']), '');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Un dossier du disque : 3 petits fichiers et un trop gros pour le faux Stockage (limite 10 octets)
|
|
247
|
+
function tree() {
|
|
248
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'poad-storage-'));
|
|
249
|
+
fs.mkdirSync(path.join(dir, 'site', 'img'), { recursive: true });
|
|
250
|
+
fs.writeFileSync(path.join(dir, 'site', 'a.txt'), 'A');
|
|
251
|
+
fs.writeFileSync(path.join(dir, 'site', 'b.txt'), 'BB');
|
|
252
|
+
fs.writeFileSync(path.join(dir, 'site', 'img', 'big.bin'), Buffer.alloc(64));
|
|
253
|
+
fs.writeFileSync(path.join(dir, 'site', 'img', 'c.txt'), 'CCC');
|
|
254
|
+
return dir;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
test('run: a failure does not stop the others; failures list path and reason', async () => {
|
|
258
|
+
const f = fakeStorage({}, { limit: 10 });
|
|
259
|
+
const api = s.client({ base: 'http://x', key: 'k', fetch: f.doFetch });
|
|
260
|
+
const dir = tree();
|
|
261
|
+
try {
|
|
262
|
+
const { items } = await c.plan(api, path.join(dir, 'site'), 'poad:web/', { recursive: true });
|
|
263
|
+
const seen = [];
|
|
264
|
+
const r = await c.run(api, items, { concurrency: 2, onError: (it, e) => seen.push([c.label(it.from), e.status]) });
|
|
265
|
+
assert.strictEqual(r.done.length, 3);
|
|
266
|
+
assert.strictEqual(r.errors.length, 1);
|
|
267
|
+
assert.deepStrictEqual(seen, [[path.relative(process.cwd(), path.join(dir, 'site', 'img', 'big.bin')).startsWith('..') ? path.join(dir, 'site', 'img', 'big.bin') : path.relative(process.cwd(), path.join(dir, 'site', 'img', 'big.bin')), 413]]);
|
|
268
|
+
const list = c.failures(r.errors);
|
|
269
|
+
assert.strictEqual(list.length, 1);
|
|
270
|
+
assert.ok(list[0].path.endsWith(path.join('site', 'img', 'big.bin')));
|
|
271
|
+
assert.strictEqual(list[0].to, 'web/site/img/big.bin');
|
|
272
|
+
assert.strictEqual(list[0].reason, 'too large: the storage accepts at most 10 bytes (10 B) per file');
|
|
273
|
+
// La taille connue part dans l'en-tête : refus avant l'envoi du contenu
|
|
274
|
+
assert.ok(!f.objects.has('web/site/img/big.bin'));
|
|
275
|
+
} finally {
|
|
276
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('run again: an identical file at the destination is not copied again (disk → storage, storage → disk, storage → storage)', async () => {
|
|
281
|
+
const f = fakeStorage();
|
|
282
|
+
const api = s.client({ base: 'http://x', key: 'k', fetch: f.doFetch });
|
|
283
|
+
const dir = tree();
|
|
284
|
+
const puts = () => f.seen.filter((x) => x.put).map((x) => x.put).sort();
|
|
285
|
+
try {
|
|
286
|
+
// Disque → Stockage, deux fois : la seconde n'envoie que le fichier changé et le nouveau
|
|
287
|
+
let r = await c.run(api, (await c.plan(api, path.join(dir, 'site'), 'poad:web/', { recursive: true })).items);
|
|
288
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length], [4, 0]);
|
|
289
|
+
f.seen.length = 0;
|
|
290
|
+
fs.writeFileSync(path.join(dir, 'site', 'b.txt'), 'bb'); // même taille, autre contenu
|
|
291
|
+
fs.writeFileSync(path.join(dir, 'site', 'd.txt'), 'D');
|
|
292
|
+
r = await c.run(api, (await c.plan(api, path.join(dir, 'site'), 'poad:web/', { recursive: true })).items);
|
|
293
|
+
assert.deepStrictEqual(puts(), ['web/site/b.txt', 'web/site/d.txt']);
|
|
294
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length, r.bytes], [2, 3, 3]);
|
|
295
|
+
assert.strictEqual(f.objects.get('web/site/b.txt').body.toString(), 'bb');
|
|
296
|
+
|
|
297
|
+
// Stockage → disque, deux fois
|
|
298
|
+
const out = path.join(dir, 'out');
|
|
299
|
+
fs.mkdirSync(out);
|
|
300
|
+
r = await c.run(api, (await c.plan(api, 'poad:web/site', out, { recursive: true })).items);
|
|
301
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length], [5, 0]);
|
|
302
|
+
fs.writeFileSync(path.join(out, 'site', 'a.txt'), 'Z'); // modifié sur le disque : recopié
|
|
303
|
+
r = await c.run(api, (await c.plan(api, 'poad:web/site', out, { recursive: true })).items);
|
|
304
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length], [1, 4]);
|
|
305
|
+
assert.strictEqual(fs.readFileSync(path.join(out, 'site', 'a.txt'), 'utf8'), 'A');
|
|
306
|
+
|
|
307
|
+
// Stockage → Stockage, deux fois
|
|
308
|
+
f.seen.length = 0;
|
|
309
|
+
r = await c.run(api, (await c.plan(api, 'poad:web/site', 'poad:backup/', { recursive: true })).items);
|
|
310
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length], [5, 0]);
|
|
311
|
+
f.seen.length = 0;
|
|
312
|
+
r = await c.run(api, (await c.plan(api, 'poad:web/site', 'poad:backup/', { recursive: true })).items);
|
|
313
|
+
assert.deepStrictEqual([r.done.length, r.unchanged.length, puts().length], [0, 5, 0]);
|
|
314
|
+
|
|
315
|
+
// skipIdentical: false : tout est recopié
|
|
316
|
+
r = await c.run(api, (await c.plan(api, 'poad:web/site', 'poad:backup/', { recursive: true })).items, { skipIdentical: false });
|
|
317
|
+
assert.strictEqual(r.done.length, 5);
|
|
318
|
+
} finally {
|
|
319
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
/** Lance une commande poad storage comme le CLI, sortie et code de sortie capturés */
|
|
324
|
+
async function command(unit, raw, deps) {
|
|
325
|
+
const lines = [];
|
|
326
|
+
const log = console.log;
|
|
327
|
+
const err = console.error;
|
|
328
|
+
const before = process.exitCode;
|
|
329
|
+
process.exitCode = undefined;
|
|
330
|
+
console.log = (...a) => lines.push(a.join(' '));
|
|
331
|
+
console.error = (...a) => lines.push(a.join(' '));
|
|
332
|
+
try {
|
|
333
|
+
await unit({}, raw, deps);
|
|
334
|
+
return { code: process.exitCode || 0, text: lines.join('\n').replace(/\x1b\[[0-9;]*m/g, '') };
|
|
335
|
+
} finally {
|
|
336
|
+
console.log = log;
|
|
337
|
+
console.error = err;
|
|
338
|
+
process.exitCode = before;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
test('poad storage cp -r: the final summary lists the failures, exit code 1; --json has failures', async () => {
|
|
343
|
+
const f = fakeStorage({}, { limit: 10 });
|
|
344
|
+
const deps = { target: async () => ({ base: 'http://x', key: 'k', fetch: f.doFetch }) };
|
|
345
|
+
const cp = require('../project/storage/cp');
|
|
346
|
+
const dir = tree();
|
|
347
|
+
try {
|
|
348
|
+
const src = path.join(dir, 'site');
|
|
349
|
+
const r = await command(cp, ['-r', src, 'poad:web/', '--concurrency', '3'], deps);
|
|
350
|
+
assert.strictEqual(r.code, 1);
|
|
351
|
+
const tail = r.text.split('\n').slice(-2);
|
|
352
|
+
assert.match(tail[0], /1 failure:/);
|
|
353
|
+
assert.match(tail[1], /✖ .*big\.bin: too large: the storage accepts at most 10 bytes/);
|
|
354
|
+
assert.match(r.text, /3 files copied, .*1 failed/);
|
|
355
|
+
assert.ok(!r.text.includes('Bearer') && !r.text.includes(' k '));
|
|
356
|
+
|
|
357
|
+
// Relancée : seul l'échec est retenté, rien n'est recopié
|
|
358
|
+
f.seen.length = 0;
|
|
359
|
+
const again = await command(cp, ['-r', src, 'poad:web/', '--json'], deps);
|
|
360
|
+
assert.strictEqual(again.code, 1);
|
|
361
|
+
const j = JSON.parse(again.text);
|
|
362
|
+
assert.deepStrictEqual(j.copied, []);
|
|
363
|
+
assert.strictEqual(j.unchanged.length, 3);
|
|
364
|
+
assert.strictEqual(j.failures.length, 1);
|
|
365
|
+
assert.deepStrictEqual(Object.keys(j.failures[0]).sort(), ['path', 'reason', 'to']);
|
|
366
|
+
assert.match(j.failures[0].reason, /at most 10 bytes/);
|
|
367
|
+
assert.deepStrictEqual(f.seen.filter((x) => x.put).map((x) => x.put), ['web/site/img/big.bin']);
|
|
368
|
+
|
|
369
|
+
// Sans échec : code 0
|
|
370
|
+
fs.rmSync(path.join(src, 'img', 'big.bin'));
|
|
371
|
+
const ok = await command(cp, ['-r', src, 'poad:web/'], deps);
|
|
372
|
+
assert.strictEqual(ok.code, 0);
|
|
373
|
+
assert.match(ok.text, /0 files copied, 0 B, 3 already identical at the destination/);
|
|
374
|
+
assert.doesNotMatch(ok.text, /failure/);
|
|
375
|
+
|
|
376
|
+
// --concurrency hors bornes : erreur d'usage, rien n'est tenté
|
|
377
|
+
const bad = await command(cp, ['-r', src, 'poad:web/', '--concurrency', '64'], deps);
|
|
378
|
+
assert.strictEqual(bad.code, 2);
|
|
379
|
+
assert.match(bad.text, /1 to 32/);
|
|
380
|
+
} finally {
|
|
381
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test('poad storage mv: a failed copy is listed at the end and left in place, exit code 1', async () => {
|
|
386
|
+
const f = fakeStorage({}, { limit: 3 });
|
|
387
|
+
f.objects.set('img/a.png', f.obj('AAA', 'image/png'));
|
|
388
|
+
f.objects.set('img/big.png', f.obj('BBBBBBB', 'image/png'));
|
|
389
|
+
const deps = { target: async () => ({ base: 'http://x', key: 'k', fetch: f.doFetch }) };
|
|
390
|
+
const r = await command(require('../project/storage/mv'), ['-r', 'img/', 'archive/', '--json'], deps);
|
|
391
|
+
assert.strictEqual(r.code, 1);
|
|
392
|
+
const j = JSON.parse(r.text);
|
|
393
|
+
assert.deepStrictEqual(j.failures.map((x) => x.path), ['img/big.png']);
|
|
394
|
+
assert.ok(f.objects.has('img/big.png') && !f.objects.has('img/a.png'));
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test('client: browse, the folder view of the storage (every folder, direct files in pages) ; null on an older storage', async () => {
|
|
398
|
+
const f = fakeStorage({}, { folders: true });
|
|
399
|
+
// L'exemple de l'utilisateur : a/b/c/d/e à la racine ne donne que le dossier a
|
|
400
|
+
for (const k of ['a/b/c/d/e', 'a/x.txt', 'a/b/y.txt', 'racine.txt']) f.objects.set(`docs/${k}`, f.obj('xy'));
|
|
401
|
+
for (let i = 0; i < 2500; i++) f.objects.set(`docs/gros/f${String(i).padStart(4, '0')}.txt`, f.obj('z'));
|
|
402
|
+
const api = s.client({ base: 'http://x', key: 'k', fetch: f.doFetch });
|
|
403
|
+
const root = await api.browse('docs', '');
|
|
404
|
+
assert.deepStrictEqual(s.viewEntries(root).map((e) => [e.kind, e.name, e.count]), [['folder', 'a', 3], ['folder', 'gros', 2500], ['file', 'racine.txt', undefined]]);
|
|
405
|
+
const a = await api.browse('docs', 'a');
|
|
406
|
+
assert.deepStrictEqual(s.viewEntries(a).map((e) => e.name), ['b', 'x.txt']);
|
|
407
|
+
assert.deepStrictEqual(s.viewEntries(await api.browse('docs', 'a/b/')).map((e) => e.name), ['c', 'y.txt']);
|
|
408
|
+
// 2500 fichiers directs : toutes les pages lues
|
|
409
|
+
const big = await api.browse('docs', 'gros');
|
|
410
|
+
assert.strictEqual(big.files.length, 2500);
|
|
411
|
+
assert.strictEqual(s.viewEntries(big).at(-1).name, 'f2499.txt');
|
|
412
|
+
// Un service plus ancien ignore delimiter et rend une liste : null, l'appelant reprend l'ancienne manière
|
|
413
|
+
const old = fakeStorage({ 'docs/a/x.txt': { body: Buffer.from('x'), type: 'text/plain' } });
|
|
414
|
+
assert.strictEqual(await s.client({ base: 'http://x', key: 'k', fetch: old.doFetch }).browse('docs', 'a'), null);
|
|
415
|
+
});
|
package/utils/cloud/bundle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Archive de déploiement : le dossier poad/ en tar.gz, par liste blanche.
|
|
2
2
|
//
|
|
3
3
|
// Entrent (chemins relatifs à poad/, sans préfixe) :
|
|
4
|
-
// dossiers migrations queries auth storage functions flows api reference variables types
|
|
4
|
+
// dossiers migrations queries auth storage functions flows api reference sources variables types
|
|
5
5
|
// credentials/manifest.json noms, types et usages des credentials, sans valeur
|
|
6
6
|
// (les valeurs restent dans le coffre de chaque engine)
|
|
7
7
|
// fichiers seed.sql, config.toml (sans aucune clé secrète : stripSecrets)
|
|
@@ -19,7 +19,7 @@ const fs = require('fs');
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const zlib = require('zlib');
|
|
21
21
|
|
|
22
|
-
const DIRS = ['migrations', 'queries', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', 'variables', 'types'];
|
|
22
|
+
const DIRS = ['migrations', 'queries', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', 'sources', 'variables', 'types'];
|
|
23
23
|
const FILES = ['seed.sql', 'config.toml'];
|
|
24
24
|
const NEVER = [/^secrets\.toml$/i, /^\.env$/i, /^\.env\..*/i, /^\.DS_Store$/, /^Thumbs\.db$/i, /^desktop\.ini$/i, /~$/, /\.swp$/];
|
|
25
25
|
const SKIP_DIRS = new Set(['node_modules', '.git', 'data', 'backups', '.cache']);
|
package/utils/help-details.js
CHANGED
|
@@ -114,12 +114,14 @@ const sheets = {
|
|
|
114
114
|
['event=<event>', 'an event, e.g. ai_default_model_changed'],
|
|
115
115
|
['table=<table>', 'lines about a table: realtime subscriptions and changes delivered (engine 0.32+), data errors'],
|
|
116
116
|
['channel=<name>', 'a realtime channel (engine 0.32+): joins, leaves, subscriptions, deliveries'],
|
|
117
|
+
['source=<name>', 'a source of poad/sources (engine 0.64+): each synchronisation (received, added, updated, removed) and its failures'],
|
|
117
118
|
['limit=100', 'number of lines, from 1 to 10000'],
|
|
118
119
|
['-f, --follow', 'follow live'],
|
|
119
120
|
['--json', 'one JSON line per entry (for jq)'],
|
|
120
121
|
],
|
|
121
122
|
notes: [
|
|
122
123
|
'Everything combines: poad logs flows run=dafb44e1 step=call level=warn -f',
|
|
124
|
+
'A source and its synchronisations: poad logs source=communes level=warn',
|
|
123
125
|
'A filter without a value (level=, request) or out of range (limit=0) is refused before anything is read, exit code 1. A log store that does not answer (engine starting or stopping, Docker stopped) is said in one sentence; POAD_DEBUG=1 shows the details of an unexpected error.',
|
|
124
126
|
],
|
|
125
127
|
},
|
|
@@ -137,7 +139,7 @@ const sheets = {
|
|
|
137
139
|
],
|
|
138
140
|
},
|
|
139
141
|
storage: {
|
|
140
|
-
usage: ['poad storage ls [bucket[/folder]] [-r]', 'poad storage cp <source> <destination> [-r]', 'poad storage mv <bucket/path> <bucket/path> [-r]', 'poad storage rm <bucket/path…> [-r] [--yes]'],
|
|
142
|
+
usage: ['poad storage ls [bucket[/folder]] [-r]', 'poad storage cp <source> <destination> [-r] [--concurrency <n>]', 'poad storage mv <bucket/path> <bucket/path> [-r] [--concurrency <n>]', 'poad storage rm <bucket/path…> [-r] [--yes]', 'poad storage sync --env <name> [--pull] [--bucket <name>] [--prune] [--dry-run] [--copy-bytes] [--concurrency <n>]'],
|
|
141
143
|
text: [
|
|
142
144
|
'Files of the project storage, local engine (poad start) or poad.io (--env), whatever its backend: engine disk, S3 or 1fichier. A storage path is bucket/path; folders exist through their files ("a/b/c.png"), as in the console. For cp, write a storage path poad:bucket/path so that it is not taken for a file of the disk.',
|
|
143
145
|
],
|
|
@@ -148,21 +150,57 @@ const sheets = {
|
|
|
148
150
|
['cp poad:images/a.png poad:backup/a.png', 'storage → storage'],
|
|
149
151
|
['mv', 'move or rename inside the storage: copy, then delete each source copied (a failed copy leaves its source in place)'],
|
|
150
152
|
['rm', 'delete files; a folder or a whole bucket needs -r and a confirmation (the bucket itself stays)'],
|
|
153
|
+
['sync --env <name>', 'align the storage of a poad.io environment on the local one (see poad help storage sync)'],
|
|
151
154
|
['-r', 'folders, recursively'],
|
|
152
155
|
['--env <name>', 'the storage of a poad.io environment of the linked project (main: production) instead of the local engine'],
|
|
153
156
|
['--project <id>', 'another poad.io project (poad login); with --env for one of its environments'],
|
|
157
|
+
['--concurrency <n>', 'cp, mv, sync: transfers at the same time, 1 to 32 (default 4); more helps with a distant storage, see the notes'],
|
|
154
158
|
['--yes', 'no question (required outside a terminal for rm -r)'],
|
|
155
|
-
['--json', 'the result as JSON'],
|
|
159
|
+
['--json', 'the result as JSON; cp, mv and sync add failures: [{ path, reason }]'],
|
|
156
160
|
],
|
|
157
161
|
notes: [
|
|
158
|
-
'Transfers stream through the CLI
|
|
162
|
+
'Transfers stream through the CLI, 4 at a time (--concurrency <n>, 1 to 32: more helps when each transfer waits on a distant storage; some providers limit the rate themselves, 1fichier for one allows 2 requests per second per account, and more transfers at once then gain little). Local engine: the service_role key of poad/config.toml, never shown. poad.io: a storage token of 15 minutes given to the owner (renewed during long transfers), never the service_role key. A file already at the destination with the same size and MD5 (and type) is left alone, so cp -r run again only sends what is missing or changed; a different one is replaced. A failed file does not stop the others: the final summary lists every failure (path and reason, such as the size limit of the storage) and the command exits with code 1. Every request is logged by the storage service: poad logs storage.',
|
|
159
163
|
'Deleted content leaves the backend a minute later (storage sweeper).',
|
|
160
164
|
],
|
|
161
165
|
},
|
|
162
166
|
'storage ls': { usage: ['poad storage ls [bucket[/folder]] [-r] [--json]'], text: ['Buckets, or the folders then files of a folder (-r: every file under it, full path).'] },
|
|
163
|
-
'storage cp': {
|
|
164
|
-
|
|
167
|
+
'storage cp': {
|
|
168
|
+
usage: ['poad storage cp <source> <destination> [-r] [--concurrency <n>] [--json]'],
|
|
169
|
+
text: [
|
|
170
|
+
'Copy between the disk and the storage, or inside the storage. A storage path is written poad:bucket/path. Example: poad storage cp -r ./site poad:web/',
|
|
171
|
+
'A file already identical at the destination (same size and MD5) is not copied again: run the same command again after an interruption and only what is missing is sent. Failures are listed again at the end (path and reason); any failure: exit code 1. --concurrency <n>: transfers at the same time, 1 to 32 (default 4); some providers limit the rate themselves (1fichier: 2 requests per second per account), more then gains little.',
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
'storage mv': {
|
|
175
|
+
usage: ['poad storage mv <bucket/path> <bucket/path> [-r] [--concurrency <n>] [--json]'],
|
|
176
|
+
text: ['Move or rename inside the storage: copy, then delete each source copied (or already identical at the destination). Failures are listed at the end and left in place; any failure: exit code 1. --concurrency <n>: as for cp.'],
|
|
177
|
+
},
|
|
165
178
|
'storage rm': { usage: ['poad storage rm <bucket/path…> [-r] [--yes] [--json]'], text: ['Delete files; -r for a folder or every file of a bucket, after a confirmation (--yes outside a terminal).'] },
|
|
179
|
+
'storage sync': {
|
|
180
|
+
usage: ['poad storage sync --env <name> [--project <id>] [--pull] [--bucket <name>] [--prune] [--dry-run] [--copy-bytes] [--concurrency <n>] [--yes] [--json]'],
|
|
181
|
+
text: [
|
|
182
|
+
'Align the storage of a poad.io environment on the storage of the local project (engine started), or the other way with --pull: same buckets (created when missing, never deleted), same files. Files are compared by name, size and MD5; an identical file is left alone, so a sync run again (after an interruption or a failure) only does what is missing.',
|
|
183
|
+
'How depends on where each side keeps its files. Either side on its engine disk: the bytes are sent, and the command says so. Both on S3 or 1fichier at the same place (same S3 endpoint, bucket and prefix; same 1fichier folder), between environments of the same project only (your machine and its linked poad.io project, production and a staging environment…): only references are sent (name, size, type, key of the content) and no byte moves; the other storage checks that the request comes from the same project and that each content is really there before recording it. Two different places: the command stops and says so; add --copy-bytes to send the files themselves.',
|
|
184
|
+
'Every project is independent: a storage location is never shared between projects. Two different projects pointing at the same place is a configuration error: the command says so and copies nothing, not even with --copy-bytes.',
|
|
185
|
+
'The place is compared through a fingerprint published by each storage (endpoint, bucket, prefix or folder, never a key), the project through its poad.io identifier (linked with poad link; restart the local engine after linking). Credentials are never copied, read or shown: each side keeps the one set on it.',
|
|
186
|
+
],
|
|
187
|
+
options: [
|
|
188
|
+
['--env <name>', 'the poad.io environment (main: production) of the linked project'],
|
|
189
|
+
['--project <id>', 'another poad.io project (poad login); with --env for one of its environments'],
|
|
190
|
+
['--pull', 'poad.io → local instead of local → poad.io'],
|
|
191
|
+
['--bucket <name>', 'this bucket only'],
|
|
192
|
+
['--prune', 'also delete on the destination the files missing from the source; a file whose content the source still uses under another name (same place) is kept and reported. Buckets are never deleted, not even with --prune: delete a bucket yourself, in the console'],
|
|
193
|
+
['--dry-run, -n', 'show what would be done, change nothing'],
|
|
194
|
+
['--copy-bytes', 'send the bytes even when references would do, or when the two sides store files in different places'],
|
|
195
|
+
['--concurrency <n>', 'byte transfers at the same time, 1 to 32 (default 4). Some providers limit the rate themselves (1fichier: 2 requests per second per account): more transfers at once then gain little'],
|
|
196
|
+
['--yes', 'no question (replacing or deleting files asks first; required outside a terminal)'],
|
|
197
|
+
['--json', 'the plan or the result as JSON (totals: added, updated, unchanged, removed, kept, failed, bytes; failures: [{ path, reason }])'],
|
|
198
|
+
],
|
|
199
|
+
notes: [
|
|
200
|
+
'Same place for two environments of a project: a file deleted on the side that wrote it is gone for the other side too. Each engine only ever removes the contents it wrote itself (orphans, replaced files, folders of deleted buckets), with nothing to turn on, so a sync never makes one environment clean up the other.',
|
|
201
|
+
'A failed file does not stop the others: the final summary lists every failure (path and reason) and the command exits with code 1. References need storage 0.4.0 on both engines (the command says so otherwise); bytes work with any engine. Internal buckets (poad-*) are left out unless named with --bucket. Every request is logged by the storage service of each side: poad logs storage.',
|
|
202
|
+
],
|
|
203
|
+
},
|
|
166
204
|
functions: {
|
|
167
205
|
usage: ['poad functions new <name>', 'poad functions list', 'poad functions types'],
|
|
168
206
|
text: [
|
|
@@ -203,6 +241,26 @@ const sheets = {
|
|
|
203
241
|
],
|
|
204
242
|
notes: ['Their logs: poad logs flow=<name>, poad logs run=<id>'],
|
|
205
243
|
},
|
|
244
|
+
source: {
|
|
245
|
+
usage: ['poad source ls [--json]', 'poad source refresh <name> [--force] [--detach]', 'poad source ls | refresh … --env <name> [--project <id>]'],
|
|
246
|
+
text: [
|
|
247
|
+
'Sources of the project: tables kept up to date from a URL (JSON, GeoJSON, CSV or JSONL), declared in poad/sources/<name>.yaml (engine 0.64.0+). The engine creates the table with a migration of poad/migrations (read-only for the application, readable through the API with api: true) and a generated flow source-<name> that fills it: download, read, deposit, apply (upsert by key, removals under a guard).',
|
|
248
|
+
'With --env or --project, the commands act on the project hosted on poad.io (session of poad login, owner only) instead of the local engine: poad.io gives an access of 15 minutes, never shown. Locally, the service_role key of the project, never shown.',
|
|
249
|
+
],
|
|
250
|
+
options: [
|
|
251
|
+
['ls', 'each source: mode, table, rows, last synchronisation, next one, problems (declaration, table that differs from it, last failure); exit code 1 if a declaration is invalid'],
|
|
252
|
+
['refresh <name>', 'apply the declaration (table, flow), synchronise now and follow the run step by step, then print what changed; exit code 1 if it fails'],
|
|
253
|
+
['--force', 'lift the deletion guard (safety.maxDeletePercent) for this run: the source is right even though many rows go away'],
|
|
254
|
+
['--detach (or --no-wait)', 'print the run id only, without following it'],
|
|
255
|
+
['--json', 'ls: the sources as JSON'],
|
|
256
|
+
['--env <name>', 'an environment of the linked poad.io project (main: production)'],
|
|
257
|
+
['--project <id>', 'a poad.io project other than the one linked to this folder (no project folder needed)'],
|
|
258
|
+
],
|
|
259
|
+
notes: [
|
|
260
|
+
'A run that would remove more rows than safety.maxDeletePercent allows (or empty a table) is refused and changes nothing: check the source, then poad source refresh <name> --force.',
|
|
261
|
+
'Their logs: poad logs source=<name>; the run: poad flows show <run_id>. poad deploy sends poad/sources to poad.io.',
|
|
262
|
+
],
|
|
263
|
+
},
|
|
206
264
|
migrate: {
|
|
207
265
|
usage: ['poad migrate', 'poad migrate --force-reference'],
|
|
208
266
|
text: ['Apply pending migrations of poad/migrations and named queries of poad/queries, then the reference tables of poad/reference (the file is the source of truth).'],
|
|
@@ -232,6 +290,7 @@ const alias = (of, name) => ({
|
|
|
232
290
|
});
|
|
233
291
|
sheets.function = alias('functions', 'function');
|
|
234
292
|
sheets.flow = alias('flows', 'flow');
|
|
293
|
+
sheets.sources = alias('source', 'sources');
|
|
235
294
|
|
|
236
295
|
// --- poad.io (projets hébergés) -------------------------------------------------
|
|
237
296
|
const EXIT_NOTE = 'Exit codes: 0 done, 1 error (poad.io, network), 2 usage (option, folder, link), 3 session (poad login), 4 confirmation missing or refused, 5 deploy failed.';
|
package/utils/logline.js
CHANGED
|
@@ -5,8 +5,8 @@ const LEVELS = ['debug', 'info', 'warn', 'error', 'fatal'];
|
|
|
5
5
|
|
|
6
6
|
// Options de filtre → attribut de la ligne (attrs). Mêmes noms et même sens
|
|
7
7
|
// que les paramètres de /logs/v1 (services/logs/src/api.ts de l'infra).
|
|
8
|
-
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page' };
|
|
9
|
-
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil' };
|
|
8
|
+
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page', source: 'source_name' };
|
|
9
|
+
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil', source: 'communes' };
|
|
10
10
|
// Identifiant d'exécution (UUID) entier, ou son début : 8 caractères au moins
|
|
11
11
|
const RUN_RE = /^[0-9a-f-]{8,36}$/;
|
|
12
12
|
|
package/utils/storage-copy.js
CHANGED
|
@@ -63,16 +63,18 @@ async function plan(api, srcText, dstText, { recursive = false, remoteOnly = fal
|
|
|
63
63
|
const sizeOf = (o) => Number(o.metadata && o.metadata.size) || 0;
|
|
64
64
|
// Le type d'origine (fiche de l'objet), pas celui de la réponse HTTP (qui peut gagner « ; charset=… »)
|
|
65
65
|
const typeOf = (o) => (o.metadata && o.metadata.mimetype) || undefined;
|
|
66
|
+
// MD5 du contenu (etag du Stockage) : sert à reconnaître une copie déjà faite
|
|
67
|
+
const etagOf = (o) => (o.metadata && o.metadata.etag) || undefined;
|
|
66
68
|
|
|
67
69
|
if (!dstRemote) {
|
|
68
70
|
// Stockage → disque
|
|
69
71
|
const dst = path.resolve(String(dstText));
|
|
70
72
|
const isDir = String(dstText).endsWith('/') || String(dstText).endsWith(path.sep) || (fs.existsSync(dst) && fs.statSync(dst).isDirectory());
|
|
71
73
|
if (found.kind === 'file') {
|
|
72
|
-
items.push({ from: { bucket: src.bucket, key: found.objects[0].name }, to: { local: isDir ? path.join(dst, name) : dst }, size: sizeOf(found.objects[0]) });
|
|
74
|
+
items.push({ from: { bucket: src.bucket, key: found.objects[0].name }, to: { local: isDir ? path.join(dst, name) : dst }, size: sizeOf(found.objects[0]), etag: etagOf(found.objects[0]) });
|
|
73
75
|
} else {
|
|
74
76
|
const into = isDir ? path.join(dst, name) : dst;
|
|
75
|
-
for (const o of found.objects) items.push({ from: { bucket: src.bucket, key: o.name }, to: { local: path.join(into, ...relOf(o).split('/')) }, size: sizeOf(o) });
|
|
77
|
+
for (const o of found.objects) items.push({ from: { bucket: src.bucket, key: o.name }, to: { local: path.join(into, ...relOf(o).split('/')) }, size: sizeOf(o), etag: etagOf(o) });
|
|
76
78
|
}
|
|
77
79
|
return { items, kind: found.kind };
|
|
78
80
|
}
|
|
@@ -81,12 +83,12 @@ async function plan(api, srcText, dstText, { recursive = false, remoteOnly = fal
|
|
|
81
83
|
const dst = s.parseRemote(dstText);
|
|
82
84
|
const isDir = dst.dir || (await remoteFolder(api, dst));
|
|
83
85
|
if (found.kind === 'file') {
|
|
84
|
-
items.push({ from: { bucket: src.bucket, key: found.objects[0].name }, to: { bucket: dst.bucket, key: isDir ? s.joinKey(dst.key, name) : dst.key }, size: sizeOf(found.objects[0]), type: typeOf(found.objects[0]) });
|
|
86
|
+
items.push({ from: { bucket: src.bucket, key: found.objects[0].name }, to: { bucket: dst.bucket, key: isDir ? s.joinKey(dst.key, name) : dst.key }, size: sizeOf(found.objects[0]), type: typeOf(found.objects[0]), etag: etagOf(found.objects[0]) });
|
|
85
87
|
} else {
|
|
86
88
|
const into = isDir ? s.joinKey(dst.key, name) : dst.key;
|
|
87
89
|
if (dst.bucket === src.bucket && (into === found.base || (found.base ? into.startsWith(`${found.base}/`) : true)))
|
|
88
90
|
throw usageError(`${s.show(dst.bucket, into)} is inside ${s.show(src.bucket, found.base)}: choose another destination`);
|
|
89
|
-
for (const o of found.objects) items.push({ from: { bucket: src.bucket, key: o.name }, to: { bucket: dst.bucket, key: s.joinKey(into, relOf(o)) }, size: sizeOf(o), type: typeOf(o) });
|
|
91
|
+
for (const o of found.objects) items.push({ from: { bucket: src.bucket, key: o.name }, to: { bucket: dst.bucket, key: s.joinKey(into, relOf(o)) }, size: sizeOf(o), type: typeOf(o), etag: etagOf(o) });
|
|
90
92
|
}
|
|
91
93
|
for (const it of items) {
|
|
92
94
|
if (it.from.bucket === it.to.bucket && it.from.key === it.to.key) throw usageError(`${s.show(it.from.bucket, it.from.key)}: source and destination are the same`);
|
|
@@ -101,10 +103,59 @@ const label = (end) => {
|
|
|
101
103
|
return rel && !rel.startsWith('..') && !path.isAbsolute(rel) ? rel : end.local;
|
|
102
104
|
};
|
|
103
105
|
|
|
106
|
+
/** Plus long préfixe de dossier commun à des clés (« a/b/ »), ou la clé seule. Pure. */
|
|
107
|
+
function commonDir(keys) {
|
|
108
|
+
if (keys.length === 1) return keys[0];
|
|
109
|
+
let p = keys[0];
|
|
110
|
+
for (const k of keys) while (!k.startsWith(p)) p = p.slice(0, -1);
|
|
111
|
+
return p.slice(0, p.lastIndexOf('/') + 1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Ce qui existe déjà à la destination (Stockage) : item.existing = { size, etag, type }.
|
|
116
|
+
* Une seule liste par bucket de destination, sous le dossier commun. Le disque se regarde
|
|
117
|
+
* au moment du transfert.
|
|
118
|
+
*/
|
|
119
|
+
async function lookup(api, items) {
|
|
120
|
+
const byBucket = new Map();
|
|
121
|
+
for (const it of items) if (it.to.bucket !== undefined) byBucket.set(it.to.bucket, [...(byBucket.get(it.to.bucket) || []), it]);
|
|
122
|
+
for (const [bucket, list] of byBucket) {
|
|
123
|
+
const rows = await api.list(bucket, commonDir(list.map((it) => it.to.key)));
|
|
124
|
+
const found = new Map(rows.map((o) => [o.name, o.metadata || {}]));
|
|
125
|
+
for (const it of list) {
|
|
126
|
+
const m = found.get(it.to.key);
|
|
127
|
+
if (m) it.existing = { size: Number(m.size), etag: m.etag || null, type: m.mimetype || null };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return items;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* La destination a-t-elle déjà ce contenu ? Même taille et même MD5 (etag), et dans le
|
|
135
|
+
* Stockage le même type ; sans etag d'un côté : non (la taille seule ne prouve rien).
|
|
136
|
+
*/
|
|
137
|
+
async function identical({ from, to, size, type, etag, existing }) {
|
|
138
|
+
if (to.local !== undefined) {
|
|
139
|
+
if (!etag) return false;
|
|
140
|
+
let st;
|
|
141
|
+
try {
|
|
142
|
+
st = fs.statSync(to.local);
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return st.isFile() && st.size === size && (await s.md5File(to.local)) === etag;
|
|
147
|
+
}
|
|
148
|
+
if (!existing || !existing.etag || existing.size !== size) return false;
|
|
149
|
+
const want = from.local !== undefined ? s.mimeOf(from.local) : type;
|
|
150
|
+
if (want && existing.type && want !== existing.type) return false;
|
|
151
|
+
const have = from.local !== undefined ? await s.md5File(from.local) : etag;
|
|
152
|
+
return Boolean(have) && have === existing.etag;
|
|
153
|
+
}
|
|
154
|
+
|
|
104
155
|
/** Un transfert, en flux ; rend le nombre d'octets */
|
|
105
156
|
async function transfer(api, { from, to, size, type }) {
|
|
106
157
|
if (from.local !== undefined) {
|
|
107
|
-
await api.put(to.bucket, to.key, fs.createReadStream(from.local), { type: s.mimeOf(from.local) });
|
|
158
|
+
await api.put(to.bucket, to.key, fs.createReadStream(from.local), { type: s.mimeOf(from.local), length: size });
|
|
108
159
|
return size;
|
|
109
160
|
}
|
|
110
161
|
const res = await api.get(from.bucket, from.key);
|
|
@@ -125,17 +176,42 @@ async function transfer(api, { from, to, size, type }) {
|
|
|
125
176
|
return size;
|
|
126
177
|
}
|
|
127
178
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Exécute le plan ; rend { done, unchanged, errors: [{ item, error }], bytes }.
|
|
181
|
+
* concurrency : transferts en parallèle (défaut s.PARALLEL)
|
|
182
|
+
* skipIdentical : un fichier déjà identique à la destination n'est pas recopié (défaut)
|
|
183
|
+
* onDone(item), onSkip(item), onError(item, error) : au fil de l'eau
|
|
184
|
+
*/
|
|
185
|
+
async function run(api, items, { onDone, onSkip, onError, concurrency, skipIdentical = true } = {}) {
|
|
130
186
|
const done = [];
|
|
187
|
+
const unchanged = [];
|
|
131
188
|
let bytes = 0;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
189
|
+
if (skipIdentical) await lookup(api, items);
|
|
190
|
+
const errors = await s.each(
|
|
191
|
+
items,
|
|
192
|
+
async (item) => {
|
|
193
|
+
try {
|
|
194
|
+
if (skipIdentical && (await identical(item))) {
|
|
195
|
+
unchanged.push(item);
|
|
196
|
+
if (onSkip) onSkip(item);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const n = await transfer(api, item);
|
|
200
|
+
bytes += n || 0;
|
|
201
|
+
done.push(item);
|
|
202
|
+
if (onDone) onDone(item);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
if (onError) onError(item, e);
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
concurrency,
|
|
209
|
+
);
|
|
210
|
+
return { done, unchanged, errors, bytes };
|
|
139
211
|
}
|
|
140
212
|
|
|
141
|
-
|
|
213
|
+
/** Échecs pour le bilan : [{ path, to, reason }], triés par chemin. Pure. */
|
|
214
|
+
const failures = (errors) =>
|
|
215
|
+
errors.map((e) => ({ path: label(e.item.from), to: label(e.item.to), reason: s.reason(e.error) })).sort((a, b) => a.path.localeCompare(b.path));
|
|
216
|
+
|
|
217
|
+
module.exports = { plan, run, transfer, label, lookup, identical, commonDir, failures };
|