-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
55 lines (41 loc) · 1.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// @ts-check
import readline from "node:readline";
import { createReadStream } from "node:fs";
import { ENDORSEMENTS_COLUMNS, ENDORSEMENTS_PATH } from "./lib/constants.js";
const rl = readline.createInterface({
input: createReadStream(ENDORSEMENTS_PATH),
});
let seq = 0;
const newLines = [];
const errors = [];
let hasSeqError = false;
let lastSeq;
for await (const line of rl) {
const columns = line.split(",");
const endorsement = Object.fromEntries(
columns.map((value, index) => [ENDORSEMENTS_COLUMNS[index], value])
);
if (endorsement.owner_id === "owner_id") {
newLines.push(line);
continue;
}
if (!line.trim()) {
errors.push(`Wrong number of columns after seq #${lastSeq}`);
continue;
}
lastSeq = seq;
if (columns.length !== ENDORSEMENTS_COLUMNS.length) {
errors.push(`Wrong number of columns at seq #${endorsement.seq}`);
}
const parts = line.split(",");
newLines.push(`${++seq},` + parts.slice(1).join(","));
if (Number(endorsement.seq) !== seq && !hasSeqError) {
errors.push(`${endorsement.seq} should be ${seq}`);
hasSeqError = true;
}
}
if (errors.length) {
console.log(`Errors in data found:\n\n- ${errors.join("\n- ")}`);
process.exit(1);
}
console.log("ok");