poad 2.50.0 → 2.52.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 +13 -2
- package/package.json +1 -1
- package/project/cli.js +8 -0
- package/project/logs.js +2 -0
- package/project/seed/index.js +17 -0
- package/project/seed/load.js +50 -0
- package/project/seed/ls.js +27 -0
- package/project/seed/mode.js +14 -0
- package/project/seed/push.js +103 -0
- package/project/seed/rm.js +14 -0
- package/test/fronts.test.js +173 -0
- package/test/seed.test.js +133 -0
- package/utils/fronts.js +213 -0
- package/utils/logline.js +2 -2
- package/utils/report.js +12 -0
- package/utils/seed/apply.js +124 -0
- package/utils/seed/convert.js +673 -0
- package/utils/seed/pack.js +179 -0
- package/utils/seed/run.js +193 -0
- package/utils/tomlfile.js +3 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Paquets du magasin de seeds : contenu COPY d'une table -> gzip -> chiffré.
|
|
2
|
+
//
|
|
3
|
+
// Empreinte : sha256 du contenu COPY en clair (identité de l'objet, partagée
|
|
4
|
+
// entre branches et versions identiques d'un même projet).
|
|
5
|
+
//
|
|
6
|
+
// Chiffrement « PSD1 » (AES-256-GCM par blocs, clé de données propre à
|
|
7
|
+
// l'objet, donnée par poad.io) :
|
|
8
|
+
// "PSD1" | bloc* avec bloc = nonce(12) | longueur(u32 BE) | chiffré | étiquette(16)
|
|
9
|
+
// données associées de chaque bloc : "PSD1" | index(u32 BE) | dernier(u8)
|
|
10
|
+
// Un bloc retiré, déplacé ou ajouté après le dernier est détecté ; un fichier
|
|
11
|
+
// coupé aussi (le dernier bloc manque).
|
|
12
|
+
'use strict';
|
|
13
|
+
const crypto = require('crypto');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const zlib = require('zlib');
|
|
17
|
+
const { Transform } = require('stream');
|
|
18
|
+
|
|
19
|
+
const MAGIC = Buffer.from('PSD1');
|
|
20
|
+
const CHUNK = 1024 * 1024;
|
|
21
|
+
|
|
22
|
+
/** Contenu COPY d'une table, écrit compressé dans un fichier, empreinte en route */
|
|
23
|
+
class TableSink {
|
|
24
|
+
constructor(file) {
|
|
25
|
+
this.file = file;
|
|
26
|
+
this.hash = crypto.createHash('sha256');
|
|
27
|
+
this.plainBytes = 0;
|
|
28
|
+
this.rows = 0;
|
|
29
|
+
this.pending = [];
|
|
30
|
+
this.pendingBytes = 0;
|
|
31
|
+
this.gzip = zlib.createGzip({ level: 6 });
|
|
32
|
+
this.out = fs.createWriteStream(file);
|
|
33
|
+
this.gzip.pipe(this.out);
|
|
34
|
+
this.done = new Promise((resolve, reject) => {
|
|
35
|
+
this.out.on('finish', resolve);
|
|
36
|
+
this.out.on('error', reject);
|
|
37
|
+
this.gzip.on('error', reject);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
row(line) {
|
|
42
|
+
const b = line + '\n';
|
|
43
|
+
this.pending.push(b);
|
|
44
|
+
this.pendingBytes += b.length;
|
|
45
|
+
this.rows++;
|
|
46
|
+
if (this.pendingBytes >= 256 * 1024) this.flushSync();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
flushSync() {
|
|
50
|
+
if (!this.pending.length) return true;
|
|
51
|
+
const buf = Buffer.from(this.pending.join(''), 'utf8');
|
|
52
|
+
this.pending = [];
|
|
53
|
+
this.pendingBytes = 0;
|
|
54
|
+
this.hash.update(buf);
|
|
55
|
+
this.plainBytes += buf.length;
|
|
56
|
+
return this.gzip.write(buf);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Attend que la compression ait absorbé ce qui a été écrit */
|
|
60
|
+
async drain() {
|
|
61
|
+
if (!this.flushSync()) await new Promise((r) => this.gzip.once('drain', r));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async close() {
|
|
65
|
+
this.flushSync();
|
|
66
|
+
this.gzip.end();
|
|
67
|
+
await this.done;
|
|
68
|
+
return { sha256: this.hash.digest('hex'), plainBytes: this.plainBytes, rows: this.rows, file: this.file, gzBytes: fs.statSync(this.file).size };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const aad = (index, last) => {
|
|
73
|
+
const b = Buffer.alloc(9);
|
|
74
|
+
MAGIC.copy(b, 0);
|
|
75
|
+
b.writeUInt32BE(index, 4);
|
|
76
|
+
b.writeUInt8(last ? 1 : 0, 8);
|
|
77
|
+
return b;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Chiffre un fichier (le gzip d'une table) vers out ; renvoie la taille écrite */
|
|
81
|
+
async function encryptFile(src, out, key) {
|
|
82
|
+
if (key.length !== 32) throw new Error('data key must be 32 bytes');
|
|
83
|
+
const size = fs.statSync(src).size;
|
|
84
|
+
const fd = fs.openSync(src, 'r');
|
|
85
|
+
const w = fs.createWriteStream(out);
|
|
86
|
+
const write = (b) => (w.write(b) ? null : new Promise((r) => w.once('drain', r)));
|
|
87
|
+
try {
|
|
88
|
+
await write(MAGIC);
|
|
89
|
+
const count = Math.max(1, Math.ceil(size / CHUNK));
|
|
90
|
+
const buf = Buffer.alloc(CHUNK);
|
|
91
|
+
for (let index = 0; index < count; index++) {
|
|
92
|
+
const n = fs.readSync(fd, buf, 0, CHUNK, index * CHUNK);
|
|
93
|
+
const nonce = crypto.randomBytes(12);
|
|
94
|
+
const c = crypto.createCipheriv('aes-256-gcm', key, nonce);
|
|
95
|
+
c.setAAD(aad(index, index === count - 1));
|
|
96
|
+
const ct = Buffer.concat([c.update(buf.subarray(0, n)), c.final()]);
|
|
97
|
+
const len = Buffer.alloc(4);
|
|
98
|
+
len.writeUInt32BE(ct.length);
|
|
99
|
+
const p = write(Buffer.concat([nonce, len, ct, c.getAuthTag()]));
|
|
100
|
+
if (p) await p;
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
fs.closeSync(fd);
|
|
104
|
+
await new Promise((resolve, reject) => w.end((e) => (e ? reject(e) : resolve())));
|
|
105
|
+
}
|
|
106
|
+
return fs.statSync(out).size;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Flux de déchiffrement PSD1 (sortie : le gzip en clair) */
|
|
110
|
+
function decryptStream(key) {
|
|
111
|
+
let buf = Buffer.alloc(0);
|
|
112
|
+
let magic = false;
|
|
113
|
+
let index = 0;
|
|
114
|
+
/** Taille du bloc en tête de buf s'il est complet, sinon 0 */
|
|
115
|
+
const complete = () => {
|
|
116
|
+
if (buf.length < 16) return 0;
|
|
117
|
+
const len = buf.readUInt32BE(12);
|
|
118
|
+
if (len > CHUNK + 16) throw new Error('corrupted seed object (block too large)');
|
|
119
|
+
return buf.length >= 32 + len ? 32 + len : 0;
|
|
120
|
+
};
|
|
121
|
+
const open = (total, last) => {
|
|
122
|
+
const nonce = buf.subarray(0, 12);
|
|
123
|
+
const ct = buf.subarray(16, total - 16);
|
|
124
|
+
const tag = buf.subarray(total - 16, total);
|
|
125
|
+
const d = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
126
|
+
d.setAAD(aad(index, last));
|
|
127
|
+
d.setAuthTag(tag);
|
|
128
|
+
let plain;
|
|
129
|
+
try {
|
|
130
|
+
plain = Buffer.concat([d.update(ct), d.final()]);
|
|
131
|
+
} catch {
|
|
132
|
+
throw new Error(last ? 'seed object is truncated or was altered' : 'seed object was altered (authentication failed)');
|
|
133
|
+
}
|
|
134
|
+
buf = buf.subarray(total);
|
|
135
|
+
index++;
|
|
136
|
+
return plain;
|
|
137
|
+
};
|
|
138
|
+
const header = () => {
|
|
139
|
+
if (magic || buf.length < 4) return;
|
|
140
|
+
if (!buf.subarray(0, 4).equals(MAGIC)) throw new Error('not a poad seed object (bad header)');
|
|
141
|
+
buf = buf.subarray(4);
|
|
142
|
+
magic = true;
|
|
143
|
+
};
|
|
144
|
+
// Un bloc n'est déchiffré « non dernier » que si d'autres octets le suivent ; le dernier l'est à la fin du flux
|
|
145
|
+
return new Transform({
|
|
146
|
+
transform(chunk, _enc, cb) {
|
|
147
|
+
buf = buf.length ? Buffer.concat([buf, chunk]) : chunk;
|
|
148
|
+
try {
|
|
149
|
+
header();
|
|
150
|
+
if (magic) {
|
|
151
|
+
for (let total = complete(); total && buf.length > total; total = complete()) this.push(open(total, false));
|
|
152
|
+
}
|
|
153
|
+
cb();
|
|
154
|
+
} catch (e) {
|
|
155
|
+
cb(e);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
flush(cb) {
|
|
159
|
+
try {
|
|
160
|
+
header();
|
|
161
|
+
const total = magic ? complete() : 0;
|
|
162
|
+
if (!total || buf.length !== total) throw new Error('seed object is truncated (no final block)');
|
|
163
|
+
this.push(open(total, true));
|
|
164
|
+
cb();
|
|
165
|
+
} catch (e) {
|
|
166
|
+
cb(e);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Fichier temporaire d'un envoi */
|
|
173
|
+
function tmpDir() {
|
|
174
|
+
const base = path.join(require('os').homedir(), '.poad', 'cache', 'seeds', 'tmp');
|
|
175
|
+
fs.mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
176
|
+
return fs.mkdtempSync(path.join(base, 'push-'));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = { TableSink, encryptFile, decryptStream, tmpDir, MAGIC, CHUNK };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// poad seed : conversion d'un fichier, envoi au magasin de poad.io (URL
|
|
2
|
+
// signées), chargement (hébergé : par poad.io ; local : dans l'engine Docker).
|
|
3
|
+
'use strict';
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const zlib = require('zlib');
|
|
7
|
+
const { pipeline } = require('stream/promises');
|
|
8
|
+
const { spawn } = require('child_process');
|
|
9
|
+
const api = require('../cloud/api');
|
|
10
|
+
const { SqlSource, CsvSource, parseTarget } = require('./convert');
|
|
11
|
+
const { TableSink, encryptFile, decryptStream, tmpDir } = require('./pack');
|
|
12
|
+
const A = require('./apply');
|
|
13
|
+
|
|
14
|
+
const fmt = (n) => (n >= 1024 ** 3 ? `${(n / 1024 ** 3).toFixed(2)} GB` : n >= 1024 ** 2 ? `${(n / 1024 ** 2).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} KB`);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fichier -> une entrée par table : { target, columns, rows, sha256, plainBytes, file (gzip) }.
|
|
18
|
+
* format : sql | csv (sinon d'après l'extension) ; table : obligatoire en CSV (sinon le nom du fichier).
|
|
19
|
+
*/
|
|
20
|
+
async function convertFile(file, { format, table, dir, onProgress } = {}) {
|
|
21
|
+
const ext = path.extname(file).toLowerCase();
|
|
22
|
+
const kind = format || (ext === '.csv' || ext === '.tsv' ? 'csv' : ext === '.sql' ? 'sql' : null);
|
|
23
|
+
if (!kind) throw api.usageError(`${path.basename(file)}: unknown format (.sql or .csv), or pass --format sql|csv`);
|
|
24
|
+
const sinks = new Map();
|
|
25
|
+
const columns = new Map();
|
|
26
|
+
const onRow = (target, cols, line) => {
|
|
27
|
+
let s = sinks.get(target);
|
|
28
|
+
if (!s) {
|
|
29
|
+
s = new TableSink(path.join(dir, `${sinks.size}.copy.gz`));
|
|
30
|
+
sinks.set(target, s);
|
|
31
|
+
columns.set(target, cols);
|
|
32
|
+
} else {
|
|
33
|
+
const prev = columns.get(target);
|
|
34
|
+
if (JSON.stringify(prev) !== JSON.stringify(cols)) {
|
|
35
|
+
throw api.usageError(`${target}: rows with different column lists in the same file (split the file, or give every INSERT the same columns)`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
s.row(line);
|
|
39
|
+
};
|
|
40
|
+
let source;
|
|
41
|
+
if (kind === 'csv') {
|
|
42
|
+
const target = table ? parseTarget(table) : parseTarget(path.basename(file, path.extname(file)));
|
|
43
|
+
if (!target) throw api.usageError('CSV: give the target table with --table schema.table');
|
|
44
|
+
source = new CsvSource({ target, onRow });
|
|
45
|
+
} else source = new SqlSource({ onRow });
|
|
46
|
+
const total = fs.statSync(file).size;
|
|
47
|
+
let read = 0;
|
|
48
|
+
const rs = fs.createReadStream(file, { encoding: 'utf8', highWaterMark: 1 << 20 });
|
|
49
|
+
for await (const chunk of rs) {
|
|
50
|
+
source.push(chunk);
|
|
51
|
+
read = rs.bytesRead;
|
|
52
|
+
for (const s of sinks.values()) await s.drain();
|
|
53
|
+
onProgress && onProgress(read, total);
|
|
54
|
+
}
|
|
55
|
+
source.end();
|
|
56
|
+
const tables = [];
|
|
57
|
+
for (const [target, s] of sinks) {
|
|
58
|
+
const r = await s.close();
|
|
59
|
+
tables.push({ target, columns: columns.get(target), rows: r.rows, sha256: r.sha256, plainBytes: r.plainBytes, file: r.file });
|
|
60
|
+
}
|
|
61
|
+
// Une seule table en SQL et --table donné : il la renomme
|
|
62
|
+
if (kind === 'sql' && table) {
|
|
63
|
+
const t = parseTarget(table);
|
|
64
|
+
if (!t) throw api.usageError(`--table: "${table}" is not schema.table`);
|
|
65
|
+
if (tables.length !== 1) throw api.usageError(`--table renames a single table; the file has ${tables.length}: ${tables.map((x) => x.target).join(', ')}`);
|
|
66
|
+
tables[0].target = t;
|
|
67
|
+
}
|
|
68
|
+
return { tables, skipped: source.skipped || {}, mutations: source.mutations || 0 };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Envoie une table convertie ; renvoie la réponse de commit */
|
|
72
|
+
async function pushTable(id, t, { mode, source, onProgress }) {
|
|
73
|
+
const key = (k) => Buffer.from(k, 'base64');
|
|
74
|
+
const enc = `${t.file}.psd`;
|
|
75
|
+
// Taille chiffrée connue avant la clé : même découpage, taille déterministe
|
|
76
|
+
const gz = fs.statSync(t.file).size;
|
|
77
|
+
const blocks = Math.max(1, Math.ceil(gz / (1024 * 1024)));
|
|
78
|
+
const stored = 4 + gz + blocks * 32;
|
|
79
|
+
const prep = await api.call('POST', `v1/projects/${api.enc(id)}/seeds/upload`, {
|
|
80
|
+
body: { target: t.target, sha256: t.sha256, plain_bytes: t.plainBytes, stored_bytes: stored },
|
|
81
|
+
what: `seed ${t.target}`,
|
|
82
|
+
});
|
|
83
|
+
let commit = { target: t.target, sha256: t.sha256, mode, rows: t.rows, columns: t.columns, source };
|
|
84
|
+
if (!prep.exists) {
|
|
85
|
+
const written = await encryptFile(t.file, enc, key(prep.key));
|
|
86
|
+
if (written !== stored) throw new api.CloudError(`internal: encrypted size ${written} differs from ${stored}`);
|
|
87
|
+
if (prep.upload.kind === 'single') {
|
|
88
|
+
await putWithRetry(prep.upload.url, fs.readFileSync(enc));
|
|
89
|
+
onProgress && onProgress(stored, stored);
|
|
90
|
+
} else {
|
|
91
|
+
const { part_size: size, urls, upload_id: uploadId } = prep.upload;
|
|
92
|
+
const parts = [];
|
|
93
|
+
const fd = fs.openSync(enc, 'r');
|
|
94
|
+
try {
|
|
95
|
+
for (let i = 0; i < urls.length; i++) {
|
|
96
|
+
const len = Math.min(size, stored - i * size);
|
|
97
|
+
const buf = Buffer.alloc(len);
|
|
98
|
+
fs.readSync(fd, buf, 0, len, i * size);
|
|
99
|
+
const etag = await putWithRetry(urls[i], buf);
|
|
100
|
+
parts.push({ n: i + 1, etag });
|
|
101
|
+
onProgress && onProgress(Math.min(stored, (i + 1) * size), stored);
|
|
102
|
+
}
|
|
103
|
+
} finally {
|
|
104
|
+
fs.closeSync(fd);
|
|
105
|
+
}
|
|
106
|
+
commit = { ...commit, upload_id: uploadId, parts };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const r = await api.call('POST', `v1/projects/${api.enc(id)}/seeds/commit`, { body: commit, what: `seed ${t.target}`, timeout: 120000 });
|
|
110
|
+
return { ...r, uploaded: !prep.exists, stored };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function putWithRetry(url, buf, tries = 3) {
|
|
114
|
+
let last;
|
|
115
|
+
for (let i = 0; i < tries; i++) {
|
|
116
|
+
try {
|
|
117
|
+
const res = await fetch(url, { method: 'PUT', body: buf, headers: { 'content-type': 'application/octet-stream' }, signal: AbortSignal.timeout(15 * 60 * 1000) });
|
|
118
|
+
if (res.ok) return res.headers.get('etag') || '';
|
|
119
|
+
last = new Error(`storage refused the upload (HTTP ${res.status})`);
|
|
120
|
+
if (res.status < 500) break;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
last = e;
|
|
123
|
+
}
|
|
124
|
+
await new Promise((r) => setTimeout(r, 1000 * (i + 1)));
|
|
125
|
+
}
|
|
126
|
+
throw new api.CloudError(`Upload failed: ${last && last.message}`, { code: 'seed_upload_failed' });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Attend la fin d'un chargement hébergé ; onStep à chaque changement */
|
|
130
|
+
async function waitLoad(id, loadId, { onStep, interval = 2000, timeout = 60 * 60 * 1000 } = {}) {
|
|
131
|
+
const until = Date.now() + timeout;
|
|
132
|
+
let seen = '';
|
|
133
|
+
for (;;) {
|
|
134
|
+
const l = await api.call('GET', `v1/projects/${api.enc(id)}/seeds/loads/${api.enc(loadId)}`, { what: 'seed load' });
|
|
135
|
+
const sig = JSON.stringify(l.steps.map((s) => s.status));
|
|
136
|
+
if (sig !== seen) {
|
|
137
|
+
seen = sig;
|
|
138
|
+
onStep && onStep(l);
|
|
139
|
+
}
|
|
140
|
+
if (l.status !== 'running') return l;
|
|
141
|
+
if (Date.now() > until) throw new api.CloudError('Still loading after an hour: "poad seed ls" shows the progress.', { code: 'timeout' });
|
|
142
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** psql dans l'engine local (Docker), script sur l'entrée standard */
|
|
147
|
+
function localPsql(container, extra = [], database = 'postgres') {
|
|
148
|
+
return spawn('docker', ['exec', '-i', container, 'psql', '-X', '-q', '-v', 'VERBOSITY=verbose', '-U', 'postgres', '-h', '/var/run/postgresql', '-d', database, ...extra], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Charge un seed (téléchargé de poad.io) dans l'engine local ; { written, deleted } */
|
|
152
|
+
async function loadLocal(container, d, { database } = {}) {
|
|
153
|
+
const res = await fetch(d.url, { signal: AbortSignal.timeout(60 * 60 * 1000) });
|
|
154
|
+
if (!res.ok) throw new api.CloudError(`${d.target}: download refused (HTTP ${res.status})`, { code: 'seed_download_failed' });
|
|
155
|
+
const { Readable } = require('stream');
|
|
156
|
+
const c = localPsql(container, [], database);
|
|
157
|
+
let out = '';
|
|
158
|
+
c.stdout.on('data', (x) => (out = (out + x).slice(-20000)));
|
|
159
|
+
c.stderr.on('data', (x) => (out = (out + x).slice(-20000)));
|
|
160
|
+
const closed = new Promise((r) => c.on('close', r));
|
|
161
|
+
c.stdin.on('error', () => {});
|
|
162
|
+
c.stdin.write(A.head(d.target, d.columns));
|
|
163
|
+
// psql peut s'arrêter avant la fin (ON_ERROR_STOP) : c'est alors son message qui compte, pas l'écriture coupée
|
|
164
|
+
let streamErr = null;
|
|
165
|
+
await pipeline(Readable.fromWeb(res.body), decryptStream(Buffer.from(d.key, 'base64')), zlib.createGunzip(), c.stdin, { end: false })
|
|
166
|
+
.then(() => c.stdin.end(A.tail(d.target, d.columns)))
|
|
167
|
+
.catch((e) => {
|
|
168
|
+
streamErr = e;
|
|
169
|
+
c.stdin.destroy();
|
|
170
|
+
});
|
|
171
|
+
const code = await closed;
|
|
172
|
+
if (code === 0 && streamErr) throw new api.CloudError(`${d.target}: ${streamErr.message}`, { code: 'seed_load_failed' });
|
|
173
|
+
if (code !== 0) {
|
|
174
|
+
const lines = out.split('\n');
|
|
175
|
+
const e = (lines.find((l) => /ERROR:/.test(l)) || lines.filter(Boolean).pop() || `psql ${code}`).replace(/^psql:[^E]*/, '').replace(/^ERROR:\s+([0-9A-Z]{5}:\s+)?/, '');
|
|
176
|
+
const detail = lines.find((l) => /^DETAIL:/.test(l));
|
|
177
|
+
throw new api.CloudError(`${d.target}: ${e}${detail ? ` — ${detail.replace(/^DETAIL:\s+/, '')}` : ''}`, { code: 'seed_load_failed' });
|
|
178
|
+
}
|
|
179
|
+
return A.parseNotice(out) || { written: null, deleted: null };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Dépendances entre tables de l'engine local (ordre de chargement) */
|
|
183
|
+
function localEdges(container) {
|
|
184
|
+
return new Promise((resolve) => {
|
|
185
|
+
const c = localPsql(container, ['-tA', '-c', A.FK_SQL]);
|
|
186
|
+
let out = '';
|
|
187
|
+
c.stdout.on('data', (x) => (out += x));
|
|
188
|
+
c.on('close', (code) => resolve(code === 0 ? out.split('\n').filter(Boolean) : []));
|
|
189
|
+
c.stdin.end();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
module.exports = { convertFile, pushTable, waitLoad, loadLocal, localEdges, fmt, tmpDir };
|
package/utils/tomlfile.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Modifications ciblées d'un fichier TOML simple (config.toml, secrets.toml) :
|
|
2
2
|
// le texte est modifié ligne à ligne, les commentaires et l'ordre restent.
|
|
3
|
-
// Valeurs : chaîne, nombre, booléen
|
|
3
|
+
// Valeurs : chaîne, nombre, booléen, tableau de ces valeurs (sur une ligne) ;
|
|
4
|
+
// null retire la clé. Section imbriquée : son nom pointé (« fronts.k3x9q2m7a1bc »).
|
|
4
5
|
const fs = require('fs');
|
|
5
6
|
|
|
6
|
-
const format = (v) => (typeof v === 'string' ? JSON.stringify(v) : String(v));
|
|
7
|
+
const format = (v) => (Array.isArray(v) ? `[${v.map(format).join(', ')}]` : typeof v === 'string' ? JSON.stringify(v) : String(v));
|
|
7
8
|
|
|
8
9
|
/** Bornes [début, fin) des lignes de la section (début = ligne d'en-tête), ou null */
|
|
9
10
|
function sectionRange(lines, section) {
|