Skip to content

Commit

Permalink
chore: fix typescript issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Jan 3, 2022
1 parent bc6638d commit 1fa3a63
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint-config-oclif": "^4.0.0",
"eslint-config-oclif-typescript": "^1.0.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
"typescript": "4.4.4"
},
"engines": {
"node": ">=8.0.0"
Expand Down
33 changes: 18 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { spawn } from "child_process";
const faker = require("faker");
const fs = require("fs");
const path = require("path");
const readline = require('readline');
const readline = require("readline");
import { Input } from "@oclif/parser";

function dieAndLog(message: string, error: any) {
console.error(message);
Expand All @@ -27,7 +28,7 @@ class PgAnonymizer extends Command {
},
];

static flags = {
static flags: flags.Input<any> = {
version: flags.version({ char: "v" }),
help: flags.help({ char: "h" }),
list: flags.string({
Expand All @@ -51,13 +52,14 @@ class PgAnonymizer extends Command {
}),
pgDumpOutputMemory: flags.string({
char: "m",
description: "Obsolete, not needed any more: max memory used to get output from pg_dump in MB",
description:
"Obsolete, not needed any more: max memory used to get output from pg_dump in MB",
default: "0",
}),
};

async run() {
const { args, flags } = this.parse(PgAnonymizer);
const { args, flags } = this.parse(<Input<any>>PgAnonymizer);

if (flags.fakerLocale) {
faker.locale = flags.fakerLocale;
Expand All @@ -68,18 +70,18 @@ class PgAnonymizer extends Command {
: null;

console.log("Launching pg_dump");
const pg = spawn('pg_dump', [args.database]);
pg.on('exit', function(code) {
const pg = spawn("pg_dump", [args.database]);
pg.on("exit", function (code) {
if (code != 0) {
dieAndLog("pg_dump command failed with exit code", code);
}
});
pg.stderr.on('data', function(data) {
pg.stderr.on("data", function (data) {
dieAndLog("pg_dump command error:", data);
});
pg.stdout.setEncoding('utf8');
pg.stdout.setEncoding("utf8");

const list = flags.list.split(",").map((l) => {
const list = flags.list.split(",").map((l: string) => {
return {
col: l.replace(/:(?:.*)$/, "").toLowerCase(),
replacement: l.includes(":") ? l.replace(/^(?:.*):/, "") : null,
Expand All @@ -96,7 +98,7 @@ class PgAnonymizer extends Command {

const inputLineResults = readline.createInterface({
input: pg.stdout,
crlfDelay: Infinity
crlfDelay: Infinity,
}) as any as Iterable<String>;

for await (let line of inputLineResults) {
Expand All @@ -112,8 +114,9 @@ class PgAnonymizer extends Command {
.map((e) => e.toLowerCase());

indices = cols.reduce((acc: Number[], value, key) => {
if (list.find((l) => l.col === value)) acc.push(key)
else if (list.find((l) => l.col === table + '.' + value)) acc.push(key);
if (list.find((l: any) => l.col === value)) acc.push(key);
else if (list.find((l: any) => l.col === table + "." + value))
acc.push(key);
return acc;
}, []);

Expand All @@ -129,11 +132,11 @@ class PgAnonymizer extends Command {
.map((v, k) => {
if (indices.includes(k)) {
let replacement = list.find(
(l) => l.col === cols[k]
(l: any) => l.col === cols[k]
)?.replacement;
if (!replacement) {
replacement = list.find(
(l) => l.col === table + '.' + cols[k]
(l: any) => l.col === table + "." + cols[k]
)?.replacement;
}
if (replacement) {
Expand All @@ -146,7 +149,7 @@ class PgAnonymizer extends Command {
}
if (replacement.startsWith("extension.")) {
const functionPath = replacement.split(".");
return functionPath.reduce((acc, key) => {
return functionPath.reduce((acc: any, key: any) => {
if (acc[key]) {
return acc[key];
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2434,10 +2434,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.5.4:
version "4.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8"
integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==
typescript@4.4.4:
version "4.4.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==

universalify@^0.1.0:
version "0.1.2"
Expand Down

0 comments on commit 1fa3a63

Please sign in to comment.