poad 2.56.0 → 2.57.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/package.json +1 -1
- package/test/reference-store.test.js +38 -25
- package/utils/cloud/bundle.js +10 -2
package/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Grosses tables de référence : lecture JSON Lines, .gitignore, archive de deploy
|
|
2
|
+
const { describe, test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert');
|
|
2
4
|
const fs = require('fs');
|
|
3
5
|
const os = require('os');
|
|
4
6
|
const path = require('path');
|
|
@@ -8,16 +10,19 @@ const bundle = require('../utils/cloud/bundle');
|
|
|
8
10
|
|
|
9
11
|
describe('JSON Lines (format de poad/reference)', () => {
|
|
10
12
|
test('valeurs : null, texte, nombre, booléen, GeoJSON, tableau PostgreSQL, JSON', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
assert.strictEqual(jsonlValue(null), null);
|
|
14
|
+
assert.strictEqual(jsonlValue('a'), 'a');
|
|
15
|
+
assert.strictEqual(jsonlValue(1.5), '1.5');
|
|
16
|
+
assert.strictEqual(jsonlValue(true), 'true');
|
|
17
|
+
assert.strictEqual(jsonlValue({ type: 'Point', coordinates: [1, 2] }), 'SRID=4326;POINT(1 2)');
|
|
18
|
+
assert.strictEqual(
|
|
19
|
+
jsonlValue({ type: 'MultiPolygon', crs: { type: 'name', properties: { name: 'EPSG:2154' } }, coordinates: [[[[0, 0], [1, 0], [1, 1], [0, 0]]]] }),
|
|
20
|
+
'SRID=2154;MULTIPOLYGON(((0 0, 1 0, 1 1, 0 0)))',
|
|
21
|
+
);
|
|
22
|
+
assert.strictEqual(jsonlValue({ type: 'Feature', a: 1 }), '{"type":"Feature","a":1}');
|
|
23
|
+
assert.strictEqual(jsonlValue(['a', 'b"c', null]), '{"a","b\\"c",NULL}');
|
|
24
|
+
assert.strictEqual(jsonlValue([[1, 2], [3, 4]]), '{{"1","2"},{"3","4"}}');
|
|
25
|
+
assert.strictEqual(jsonlValue([{ a: 1 }]), '[{"a":1}]');
|
|
21
26
|
});
|
|
22
27
|
test('lignes coupées entre deux morceaux, colonnes de la première ligne', () => {
|
|
23
28
|
const rows = [];
|
|
@@ -25,13 +30,13 @@ describe('JSON Lines (format de poad/reference)', () => {
|
|
|
25
30
|
s.push('{"id":1,"nom":"Bourg"}\n{"id":2,');
|
|
26
31
|
s.push('"nom":null}\n{"id":3}');
|
|
27
32
|
s.end();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
assert.deepStrictEqual(rows.map((r) => r[2]), [['1', 'Bourg'], ['2', null], ['3', null]]);
|
|
34
|
+
assert.deepStrictEqual(rows[0][1], ['id', 'nom']);
|
|
35
|
+
assert.deepStrictEqual(rows.map((r) => r[2].map(copyEscape).join('\t')), ['1\tBourg', '2\t\\N', '3\t\\N']);
|
|
31
36
|
});
|
|
32
37
|
test('une colonne absente de la première ligne est refusée, avec sa ligne', () => {
|
|
33
38
|
const s = new JsonlSource({ target: 'public.t', onRow: () => {} });
|
|
34
|
-
|
|
39
|
+
assert.throws(() => s.push('{"id":1}\n{"id":2,"x":3}\n'), /column "x".*line 2/);
|
|
35
40
|
});
|
|
36
41
|
});
|
|
37
42
|
|
|
@@ -46,26 +51,34 @@ describe('grosses références : hors de git et de l’archive de deploy', () =>
|
|
|
46
51
|
};
|
|
47
52
|
test('repérées au-delà du seuil, .gitignore écrit (même texte que le service meta), puis retiré', () => {
|
|
48
53
|
const dir = project();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(large).toEqual([]);
|
|
54
|
+
assert.deepStrictEqual(store.largeFiles(dir, 5).map((f) => f.target), ['public.commune', 'public.petite']);
|
|
55
|
+
assert.deepStrictEqual(store.largeFiles(dir), []);
|
|
52
56
|
fs.truncateSync(path.join(dir, 'reference', 'public.commune.jsonl'), store.LARGE + 1);
|
|
53
57
|
const big = store.largeFiles(dir);
|
|
54
|
-
|
|
58
|
+
assert.deepStrictEqual(big.map((f) => f.rel), ['reference/public.commune.jsonl']);
|
|
55
59
|
store.ensureGitignore(dir, big);
|
|
56
|
-
|
|
60
|
+
assert.strictEqual(
|
|
61
|
+
fs.readFileSync(path.join(dir, 'reference', '.gitignore'), 'utf8'),
|
|
57
62
|
'# Écrit par poad : tables de référence trop lourdes pour git (plus de 20 Mo).\n# Elles restent sur ce poste ; poad deploy les envoie au magasin de références de poad.io.\n/public.commune.jsonl\n',
|
|
58
63
|
);
|
|
59
64
|
store.ensureGitignore(dir, []);
|
|
60
|
-
|
|
65
|
+
assert.strictEqual(fs.existsSync(path.join(dir, 'reference', '.gitignore')), false);
|
|
61
66
|
});
|
|
62
|
-
test('l’archive de deploy les laisse de côté au lieu d’échouer', () => {
|
|
67
|
+
test('l’archive de deploy les laisse de côté au lieu d’échouer, mais garde leur marquage', () => {
|
|
63
68
|
const dir = project();
|
|
64
69
|
fs.truncateSync(path.join(dir, 'reference', 'public.commune.jsonl'), store.LARGE + 1);
|
|
65
|
-
|
|
70
|
+
assert.throws(() => bundle.build(dir), /public\.commune\.jsonl is larger than 20 MB/);
|
|
66
71
|
const b = bundle.build(dir, { exclude: ['reference/public.commune.jsonl'] });
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
const paths = b.files.map((f) => f.path);
|
|
73
|
+
assert.ok(paths.includes('reference/public.petite.jsonl'));
|
|
74
|
+
assert.ok(!paths.includes('reference/public.commune.jsonl'));
|
|
75
|
+
assert.deepStrictEqual(
|
|
76
|
+
b.skipped.find((s) => s.path === 'reference/public.commune.jsonl'),
|
|
77
|
+
{ path: 'reference/public.commune.jsonl', reason: 'large reference table: sent to the reference store' },
|
|
78
|
+
);
|
|
79
|
+
// Le marquage voyage : un témoin léger, pour que l'engine déployé la sache référence
|
|
80
|
+
const witness = b.files.find((f) => f.path === 'reference/public.commune.store');
|
|
81
|
+
assert.ok(witness && witness.size < 100);
|
|
82
|
+
assert.deepStrictEqual(paths, [...paths].sort());
|
|
70
83
|
});
|
|
71
84
|
});
|
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 auth storage functions flows api reference variables types
|
|
4
|
+
// dossiers migrations queries auth storage functions flows api reference 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', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', 'variables', 'types'];
|
|
22
|
+
const DIRS = ['migrations', 'queries', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', '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']);
|
|
@@ -204,6 +204,13 @@ function build(poadDir, { limits = LIMITS, exclude = [] } = {}) {
|
|
|
204
204
|
for (const rel of rels.sort()) {
|
|
205
205
|
if (left.has(rel)) {
|
|
206
206
|
skipped.push({ path: rel, reason: 'large reference table: sent to the reference store' });
|
|
207
|
+
// Le marquage voyage quand même : l'engine déployé sait que la table est une référence,
|
|
208
|
+
// dont le contenu vient du magasin (jamais d'une synchronisation depuis un fichier)
|
|
209
|
+
if (/^reference\/[^/]+\.jsonl$/.test(rel)) {
|
|
210
|
+
const data = Buffer.from(JSON.stringify({ store: true, bytes: fs.statSync(path.join(poadDir, ...rel.split('/'))).size }) + '\n');
|
|
211
|
+
total += data.length;
|
|
212
|
+
files.push({ path: rel.replace(/\.jsonl$/, '.store'), data, mode: 0o644 });
|
|
213
|
+
}
|
|
207
214
|
continue;
|
|
208
215
|
}
|
|
209
216
|
const abs = path.join(poadDir, ...rel.split('/'));
|
|
@@ -225,6 +232,7 @@ function build(poadDir, { limits = LIMITS, exclude = [] } = {}) {
|
|
|
225
232
|
if (total > limits.maxBytes) throw new BundleError(`the poad/ folder to send is larger than ${limits.maxBytes} bytes`);
|
|
226
233
|
files.push({ path: rel, data, mode: st.mode & 0o111 ? 0o755 : 0o644 });
|
|
227
234
|
}
|
|
235
|
+
files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
228
236
|
const tgz = zlib.gzipSync(tar(files), { level: 9 });
|
|
229
237
|
return { tgz, files: files.map((f) => ({ path: f.path, size: f.data.length })), skipped, bytes: total };
|
|
230
238
|
}
|