ffc-pay-etl-framework 0.0.1
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/LICENSE.md +24 -0
- package/README.md +55 -0
- package/dist/cjs/destinations/consoleDestination.js +21 -0
- package/dist/cjs/destinations/csvFileDestination.js +48 -0
- package/dist/cjs/destinations/index.js +11 -0
- package/dist/cjs/destinations/postgresDestination.js +67 -0
- package/dist/cjs/destinations/sqlFileDestination.js +64 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/lib/index.js +46 -0
- package/dist/cjs/lib/rowMetaData.js +23 -0
- package/dist/cjs/loaders/csvloader.js +31 -0
- package/dist/cjs/loaders/index.js +4 -0
- package/dist/cjs/transformers/fakerTransformer.js +39 -0
- package/dist/cjs/transformers/index.js +6 -0
- package/dist/cjs/transformers/toUpperCaseTransformer.js +24 -0
- package/dist/cjs/types/destinations/consoleDestination.d.ts +11 -0
- package/dist/cjs/types/destinations/consoleDestination.d.ts.map +1 -0
- package/dist/cjs/types/destinations/csvFileDestination.d.ts +17 -0
- package/dist/cjs/types/destinations/csvFileDestination.d.ts.map +1 -0
- package/dist/cjs/types/destinations/index.d.ts +7 -0
- package/dist/cjs/types/destinations/index.d.ts.map +1 -0
- package/dist/cjs/types/destinations/postgresDestination.d.ts +23 -0
- package/dist/cjs/types/destinations/postgresDestination.d.ts.map +1 -0
- package/dist/cjs/types/destinations/sqlFileDestination.d.ts +24 -0
- package/dist/cjs/types/destinations/sqlFileDestination.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +7 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/lib/index.d.ts +25 -0
- package/dist/cjs/types/lib/index.d.ts.map +1 -0
- package/dist/cjs/types/lib/rowMetaData.d.ts +3 -0
- package/dist/cjs/types/lib/rowMetaData.d.ts.map +1 -0
- package/dist/cjs/types/loaders/csvloader.d.ts +11 -0
- package/dist/cjs/types/loaders/csvloader.d.ts.map +1 -0
- package/dist/cjs/types/loaders/index.d.ts +3 -0
- package/dist/cjs/types/loaders/index.d.ts.map +1 -0
- package/dist/cjs/types/transformers/fakerTransformer.d.ts +37 -0
- package/dist/cjs/types/transformers/fakerTransformer.d.ts.map +1 -0
- package/dist/cjs/types/transformers/index.d.ts +4 -0
- package/dist/cjs/types/transformers/index.d.ts.map +1 -0
- package/dist/cjs/types/transformers/toUpperCaseTransformer.d.ts +23 -0
- package/dist/cjs/types/transformers/toUpperCaseTransformer.d.ts.map +1 -0
- package/dist/cjs/types/validators/index.d.ts +5 -0
- package/dist/cjs/types/validators/index.d.ts.map +1 -0
- package/dist/cjs/types/validators/multiToolValidator.d.ts +23 -0
- package/dist/cjs/types/validators/multiToolValidator.d.ts.map +1 -0
- package/dist/cjs/types/validators/requiredValidator.d.ts +13 -0
- package/dist/cjs/types/validators/requiredValidator.d.ts.map +1 -0
- package/dist/cjs/types/validators/uniqueValidator.d.ts +29 -0
- package/dist/cjs/types/validators/uniqueValidator.d.ts.map +1 -0
- package/dist/cjs/validators/index.js +8 -0
- package/dist/cjs/validators/multiToolValidator.js +48 -0
- package/dist/cjs/validators/requiredValidator.js +33 -0
- package/dist/cjs/validators/uniqueValidator.js +40 -0
- package/dist/esm/destinations/consoleDestination.js +22 -0
- package/dist/esm/destinations/csvFileDestination.js +49 -0
- package/dist/esm/destinations/index.js +12 -0
- package/dist/esm/destinations/postgresDestination.js +68 -0
- package/dist/esm/destinations/sqlFileDestination.js +65 -0
- package/dist/esm/index.mjs +13 -0
- package/dist/esm/lib/index.js +47 -0
- package/dist/esm/lib/rowMetaData.js +24 -0
- package/dist/esm/loaders/csvloader.js +32 -0
- package/dist/esm/loaders/index.js +5 -0
- package/dist/esm/transformers/fakerTransformer.js +40 -0
- package/dist/esm/transformers/index.js +7 -0
- package/dist/esm/transformers/toUpperCaseTransformer.js +25 -0
- package/dist/esm/types/destinations/consoleDestination.d.ts +11 -0
- package/dist/esm/types/destinations/consoleDestination.d.ts.map +1 -0
- package/dist/esm/types/destinations/csvFileDestination.d.ts +17 -0
- package/dist/esm/types/destinations/csvFileDestination.d.ts.map +1 -0
- package/dist/esm/types/destinations/index.d.ts +7 -0
- package/dist/esm/types/destinations/index.d.ts.map +1 -0
- package/dist/esm/types/destinations/postgresDestination.d.ts +23 -0
- package/dist/esm/types/destinations/postgresDestination.d.ts.map +1 -0
- package/dist/esm/types/destinations/sqlFileDestination.d.ts +24 -0
- package/dist/esm/types/destinations/sqlFileDestination.d.ts.map +1 -0
- package/dist/esm/types/index.d.ts +7 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/lib/index.d.ts +25 -0
- package/dist/esm/types/lib/index.d.ts.map +1 -0
- package/dist/esm/types/lib/rowMetaData.d.ts +3 -0
- package/dist/esm/types/lib/rowMetaData.d.ts.map +1 -0
- package/dist/esm/types/loaders/csvloader.d.ts +11 -0
- package/dist/esm/types/loaders/csvloader.d.ts.map +1 -0
- package/dist/esm/types/loaders/index.d.ts +3 -0
- package/dist/esm/types/loaders/index.d.ts.map +1 -0
- package/dist/esm/types/transformers/fakerTransformer.d.ts +37 -0
- package/dist/esm/types/transformers/fakerTransformer.d.ts.map +1 -0
- package/dist/esm/types/transformers/index.d.ts +4 -0
- package/dist/esm/types/transformers/index.d.ts.map +1 -0
- package/dist/esm/types/transformers/toUpperCaseTransformer.d.ts +23 -0
- package/dist/esm/types/transformers/toUpperCaseTransformer.d.ts.map +1 -0
- package/dist/esm/types/validators/index.d.ts +5 -0
- package/dist/esm/types/validators/index.d.ts.map +1 -0
- package/dist/esm/types/validators/multiToolValidator.d.ts +23 -0
- package/dist/esm/types/validators/multiToolValidator.d.ts.map +1 -0
- package/dist/esm/types/validators/requiredValidator.d.ts +13 -0
- package/dist/esm/types/validators/requiredValidator.d.ts.map +1 -0
- package/dist/esm/types/validators/uniqueValidator.d.ts +29 -0
- package/dist/esm/types/validators/uniqueValidator.d.ts.map +1 -0
- package/dist/esm/validators/index.js +9 -0
- package/dist/esm/validators/multiToolValidator.js +49 -0
- package/dist/esm/validators/requiredValidator.js +34 -0
- package/dist/esm/validators/uniqueValidator.js +41 -0
- package/package.json +56 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Defra - Copyright (c) 2024
|
|
2
|
+
|
|
3
|
+
This software consists of voluntary contributions made by many individuals.
|
|
4
|
+
For exact contribution history, see the revision history
|
|
5
|
+
available at https://github.com/DEFRA/ffc-pay-etl-framework
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
## 🚀 Features
|
|
2
|
+
- 💾 CSV Source and Destination
|
|
3
|
+
- 👮 Validators
|
|
4
|
+
- 🤖 Transformers
|
|
5
|
+
- 🚨 Error Checking
|
|
6
|
+
- 🐘 Write directly to Postgres
|
|
7
|
+
- 👨⚕️ Intellisense
|
|
8
|
+
|
|
9
|
+
## 📦 Install
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save-dev ffc-pay-etl-framework
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 🪄 Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// ESM
|
|
18
|
+
import { Etl, Loaders, Validators, Transformers, Destinations } from "ffc-pay-etl-framework"
|
|
19
|
+
|
|
20
|
+
// CJS
|
|
21
|
+
const { Etl, Loaders, Validators, Transformers, Destinations } = require("ffc-pay-etl-framework")
|
|
22
|
+
|
|
23
|
+
let csvFile = `${process.cwd()}/test/fixtures/SoilType.csv`
|
|
24
|
+
|
|
25
|
+
const etl = new Etl.Etl()
|
|
26
|
+
|
|
27
|
+
etl
|
|
28
|
+
.loader(Loaders.CSVLoader({path: csvFile, columns: columns}))
|
|
29
|
+
.transform(Transformers.FakerTransformer({
|
|
30
|
+
columns: [{
|
|
31
|
+
name: "Dist Name",
|
|
32
|
+
faker: "location.city"
|
|
33
|
+
}]
|
|
34
|
+
}))
|
|
35
|
+
.destination(Destinations.CSVFileDestination({
|
|
36
|
+
fileName: "SoilType_Output.csv",
|
|
37
|
+
headers: true,
|
|
38
|
+
includeErrors: false,
|
|
39
|
+
quotationMarks: true
|
|
40
|
+
}))
|
|
41
|
+
.pump()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 📢 Shout outs
|
|
45
|
+
|
|
46
|
+
[Faker JS](https://fakerjs.dev/guide/)
|
|
47
|
+
|
|
48
|
+
[Validator](https://github.com/validatorjs/validator.js)
|
|
49
|
+
|
|
50
|
+
[Kaggle](https://www.kaggle.com/datasets/anushkahedaoo/farming-factors)
|
|
51
|
+
|
|
52
|
+
## ✨ Contributing
|
|
53
|
+
|
|
54
|
+
Please make sure to read the [Contributing Guide](https://github.com/DEFRA/ffc-pay-etl-framework/blob/next/CONTRIBUTING.md) before making a pull request.
|
|
55
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { Writable } = require("node:stream");
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} options
|
|
5
|
+
* @param {String} options.includeErrors
|
|
6
|
+
* @returns Writable
|
|
7
|
+
*/
|
|
8
|
+
function ConsoleDestination(options) {
|
|
9
|
+
const includeErrors = options.includeErrors;
|
|
10
|
+
return new Writable({
|
|
11
|
+
objectMode: true,
|
|
12
|
+
write(chunk, _, callback) {
|
|
13
|
+
if (chunk.errors.length === 0 || includeErrors)
|
|
14
|
+
console.log(chunk);
|
|
15
|
+
callback();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
module.exports = {
|
|
20
|
+
ConsoleDestination
|
|
21
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { Writable } = require("node:stream");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {String} options.fileName
|
|
7
|
+
* @param {Boolean} options.headers
|
|
8
|
+
* @param {Boolean} options.includeErrors
|
|
9
|
+
* @param {Boolean} options.quotationMarks
|
|
10
|
+
* @returns Writable
|
|
11
|
+
*/
|
|
12
|
+
function CSVFileDestination(options) {
|
|
13
|
+
const fileName = options.fileName;
|
|
14
|
+
const headers = options.headers;
|
|
15
|
+
const includeErrors = options.includeErrors;
|
|
16
|
+
const quotationMarks = options.quotationMarks;
|
|
17
|
+
let fileHandle;
|
|
18
|
+
fs.open(fileName, 'w+', ((error, fd) => {
|
|
19
|
+
fileHandle = fd;
|
|
20
|
+
}));
|
|
21
|
+
let headersWritten = false;
|
|
22
|
+
return new Writable({
|
|
23
|
+
objectMode: true,
|
|
24
|
+
write(chunk, _, callback) {
|
|
25
|
+
if (!headersWritten && headers) {
|
|
26
|
+
if (quotationMarks) {
|
|
27
|
+
fs.writeFileSync(fileHandle, `${chunk._columns.map(c => `"${c}"`).join(",")}\n`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
fs.writeFileSync(fileHandle, `${chunk._columns.join(",")}\n`);
|
|
31
|
+
}
|
|
32
|
+
headersWritten = true;
|
|
33
|
+
}
|
|
34
|
+
if (chunk.errors.length === 0 || includeErrors) {
|
|
35
|
+
if (quotationMarks) {
|
|
36
|
+
fs.writeFileSync(fileHandle, `${chunk.map(c => `"${c}"`).join(",")}\n`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
fs.writeFileSync(fileHandle, `${chunk.map(c => `"${c}"`).join(",")}\n`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
callback();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
module.exports = {
|
|
47
|
+
CSVFileDestination
|
|
48
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { ConsoleDestination } = require("./consoleDestination");
|
|
2
|
+
const { SQLFileDestination, SQL_MODE } = require("./sqlFileDestination");
|
|
3
|
+
const { CSVFileDestination } = require("./csvFileDestination");
|
|
4
|
+
const { PostgresDestination } = require("./postgresDestination");
|
|
5
|
+
module.exports = {
|
|
6
|
+
ConsoleDestination,
|
|
7
|
+
SQLFileDestination,
|
|
8
|
+
SQL_MODE,
|
|
9
|
+
CSVFileDestination,
|
|
10
|
+
PostgresDestination
|
|
11
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { Transform } = require("node:stream");
|
|
2
|
+
const { Sequelize } = require('sequelize');
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {Object} options.table
|
|
7
|
+
* @param {Object} options.username
|
|
8
|
+
* @param {Object} options.password
|
|
9
|
+
* @param {Object} options.database
|
|
10
|
+
* @param {Object} options.host
|
|
11
|
+
* @param {Object} options.mapping
|
|
12
|
+
* @param {Object} options.includeErrors
|
|
13
|
+
* @returns Transform
|
|
14
|
+
*/
|
|
15
|
+
function PostgresDestination(options) {
|
|
16
|
+
const table = options.table;
|
|
17
|
+
const username = options.username;
|
|
18
|
+
const password = options.password;
|
|
19
|
+
const database = options.database;
|
|
20
|
+
const host = options.host;
|
|
21
|
+
const mapping = options.mapping;
|
|
22
|
+
const includeErrors = options.includeErrors;
|
|
23
|
+
const sequelize = new Sequelize(database, username, password, {
|
|
24
|
+
host: host,
|
|
25
|
+
dialect: 'postgres',
|
|
26
|
+
logging: false
|
|
27
|
+
});
|
|
28
|
+
sequelize.authenticate();
|
|
29
|
+
function getMappingForColumn(column) {
|
|
30
|
+
const [map] = mapping.filter(m => m.column === column);
|
|
31
|
+
return map;
|
|
32
|
+
}
|
|
33
|
+
function writeInsertStatement(chunk) {
|
|
34
|
+
let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
|
|
35
|
+
let mapping = getMappingForColumn(column);
|
|
36
|
+
return mapping ? mapping.targetColumn : column;
|
|
37
|
+
})
|
|
38
|
+
.join(",")}) VALUES (${chunk._columns.map((column, index) => {
|
|
39
|
+
let mapping = getMappingForColumn(column);
|
|
40
|
+
if (mapping.targetType === "varchar" || mapping.targetType === "char")
|
|
41
|
+
return `'${chunk[index]}'`;
|
|
42
|
+
return chunk[index];
|
|
43
|
+
})})`;
|
|
44
|
+
return statement;
|
|
45
|
+
}
|
|
46
|
+
return new Transform({
|
|
47
|
+
objectMode: true,
|
|
48
|
+
transform(chunk, _, callback) {
|
|
49
|
+
let insertStatement;
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
if (chunk.errors.length === 0 | options.includeErrors) {
|
|
52
|
+
insertStatement = writeInsertStatement(chunk);
|
|
53
|
+
sequelize.query(insertStatement)
|
|
54
|
+
.then(result => {
|
|
55
|
+
chunk._result = result;
|
|
56
|
+
callback(null, chunk);
|
|
57
|
+
}).catch(error => {
|
|
58
|
+
chunk.errors.push(error);
|
|
59
|
+
callback(null, chunk);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
module.exports = {
|
|
66
|
+
PostgresDestination
|
|
67
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { Writable } = require("node:stream");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
/**
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
6
|
+
const SQL_MODE = {
|
|
7
|
+
"INSERT_MODE": 1,
|
|
8
|
+
"UPDATE_MODE": 2
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} options
|
|
13
|
+
* @param {String} options.fileName
|
|
14
|
+
* @param {SQL_MODE} options.mode
|
|
15
|
+
* @param {String} options.table
|
|
16
|
+
* @param {Array} options.mapping
|
|
17
|
+
* @param {Boolean} options.includeErrors
|
|
18
|
+
* @returns Transform
|
|
19
|
+
*/
|
|
20
|
+
function SQLFileDestination(options) {
|
|
21
|
+
const fileName = options.fileName;
|
|
22
|
+
const sqlMode = options.mode;
|
|
23
|
+
const table = options.table;
|
|
24
|
+
const mapping = options.mapping;
|
|
25
|
+
const includeErrors = options.includeErrors;
|
|
26
|
+
function writeInsertStatement(chunk) {
|
|
27
|
+
let statement = `INSERT INTO ${table} (${mapping.map(m => m.targetColumn)
|
|
28
|
+
.join(",")}) VALUES (${mapping.map((m) => {
|
|
29
|
+
const srcColumnIndex = chunk._columns.indexOf(m.column);
|
|
30
|
+
if (m.targetType === "string")
|
|
31
|
+
return `'${chunk[srcColumnIndex]}'`;
|
|
32
|
+
return chunk[srcColumnIndex];
|
|
33
|
+
})});\n`;
|
|
34
|
+
fs.writeFileSync(fileName, statement, {
|
|
35
|
+
encoding: "utf8",
|
|
36
|
+
flag: "a+"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function writeUpdateStatement(chunk) {
|
|
40
|
+
}
|
|
41
|
+
return new Writable({
|
|
42
|
+
objectMode: true,
|
|
43
|
+
write(chunk, _, callback) {
|
|
44
|
+
if (chunk.errors.length === 0)
|
|
45
|
+
if (sqlMode === SQL_MODE.INSERT_MODE) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
if (chunk.errors.length === 0 | includeErrors) {
|
|
48
|
+
writeInsertStatement(chunk);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (sqlMode === SQL_MODE.UPDATE_MODE) {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
if (chunk.errors.length === 0 | includeErrors) {
|
|
54
|
+
writeUpdateStatement(chunk);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
callback();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
module.exports = {
|
|
62
|
+
SQLFileDestination,
|
|
63
|
+
SQL_MODE
|
|
64
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const Validators = require("./validators");
|
|
2
|
+
const Transformers = require("./transformers");
|
|
3
|
+
const Loaders = require("./loaders");
|
|
4
|
+
const Destinations = require("./destinations");
|
|
5
|
+
const Etl = require("./lib");
|
|
6
|
+
module.exports = {
|
|
7
|
+
Etl,
|
|
8
|
+
Validators,
|
|
9
|
+
Transformers,
|
|
10
|
+
Loaders,
|
|
11
|
+
Destinations,
|
|
12
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const { RowMetaData } = require("./rowMetaData");
|
|
3
|
+
const { compose } = require("node:stream");
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} Etl
|
|
6
|
+
* @function loader
|
|
7
|
+
* @function pump
|
|
8
|
+
* @function validator
|
|
9
|
+
* @function destination
|
|
10
|
+
* @function transform
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @returns Etl
|
|
15
|
+
*/
|
|
16
|
+
function Etl() {
|
|
17
|
+
let self = this;
|
|
18
|
+
self.validatorList = [];
|
|
19
|
+
self.transformationList = [];
|
|
20
|
+
self.destinationList = [];
|
|
21
|
+
this.loader = (loader) => {
|
|
22
|
+
self.loader = loader;
|
|
23
|
+
return self;
|
|
24
|
+
};
|
|
25
|
+
this.pump = () => {
|
|
26
|
+
this.loader
|
|
27
|
+
.pump(this.loader)
|
|
28
|
+
.pipe(compose(RowMetaData, ...self.validatorList, ...self.transformationList, ...self.destinationList));
|
|
29
|
+
};
|
|
30
|
+
this.validator = (validator) => {
|
|
31
|
+
self.validatorList.push(validator);
|
|
32
|
+
return self;
|
|
33
|
+
};
|
|
34
|
+
this.destination = (destination) => {
|
|
35
|
+
self.destinationList.push(destination);
|
|
36
|
+
return self;
|
|
37
|
+
};
|
|
38
|
+
this.transform = (transform) => {
|
|
39
|
+
self.transformationList.push(transform);
|
|
40
|
+
return self;
|
|
41
|
+
};
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
module.exports = {
|
|
45
|
+
Etl
|
|
46
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const { Transform } = require("stream");
|
|
3
|
+
const util = require("util");
|
|
4
|
+
function RowMetaData(options) {
|
|
5
|
+
return new Transform({
|
|
6
|
+
readableObjectMode: true,
|
|
7
|
+
writableObjectMode: true,
|
|
8
|
+
decodeStrings: false,
|
|
9
|
+
construct(callback) {
|
|
10
|
+
this.rowId = 0;
|
|
11
|
+
callback();
|
|
12
|
+
},
|
|
13
|
+
transform(chunk, _, callback) {
|
|
14
|
+
chunk['_rowId'] = this.rowId;
|
|
15
|
+
chunk['errors'] = [];
|
|
16
|
+
this.rowId += 1;
|
|
17
|
+
callback(null, chunk);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
module.exports = {
|
|
22
|
+
RowMetaData
|
|
23
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const { Transform } = require("stream");
|
|
4
|
+
const { parse } = require("csv-parse");
|
|
5
|
+
const { stdout } = require("process");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @param {String} options.path
|
|
10
|
+
* @returns StreamReader
|
|
11
|
+
*/
|
|
12
|
+
function CSVLoader(options) {
|
|
13
|
+
let csvLoader = fs.createReadStream(options.path);
|
|
14
|
+
csvLoader._columns = options.columns;
|
|
15
|
+
csvLoader.pump = (csvLoader) => {
|
|
16
|
+
return csvLoader
|
|
17
|
+
.pipe(parse({ delimiter: ",", from_line: 2 }))
|
|
18
|
+
.pipe(new Transform({
|
|
19
|
+
readableObjectMode: true,
|
|
20
|
+
writableObjectMode: true,
|
|
21
|
+
transform(chunk, _, callback) {
|
|
22
|
+
chunk["_columns"] = options.columns;
|
|
23
|
+
callback(null, chunk);
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
return csvLoader;
|
|
28
|
+
}
|
|
29
|
+
module.exports = {
|
|
30
|
+
CSVLoader
|
|
31
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { Transform } = require("node:stream");
|
|
2
|
+
const { faker } = require("@faker-js/faker");
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {Array} options.columns {
|
|
7
|
+
* columns: [
|
|
8
|
+
* {
|
|
9
|
+
* name: "column-name",
|
|
10
|
+
* faker: "company.name"
|
|
11
|
+
* }
|
|
12
|
+
* ]
|
|
13
|
+
* }
|
|
14
|
+
* @returns StreamReader
|
|
15
|
+
*/
|
|
16
|
+
function FakerTransformer(options) {
|
|
17
|
+
let self = this;
|
|
18
|
+
self.columns = options.columns;
|
|
19
|
+
function getFaker(fakerType) {
|
|
20
|
+
return fakerType.split('.').reduce((a, b) => {
|
|
21
|
+
return Object.keys(a).length === 0 ? faker[b] : a[b];
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
return new Transform({
|
|
25
|
+
readableObjectMode: true,
|
|
26
|
+
writableObjectMode: true,
|
|
27
|
+
transform(chunk, _, callback) {
|
|
28
|
+
const { _columns } = chunk;
|
|
29
|
+
self.columns.forEach(column => {
|
|
30
|
+
const colIndex = _columns.indexOf(column.name);
|
|
31
|
+
chunk[colIndex] = getFaker(column.faker)();
|
|
32
|
+
});
|
|
33
|
+
callback(null, chunk);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
module.exports = {
|
|
38
|
+
FakerTransformer
|
|
39
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { Transform } = require("node:stream");
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} options
|
|
5
|
+
* @param {String} options.column
|
|
6
|
+
* @returns Writable
|
|
7
|
+
*/
|
|
8
|
+
function ToUpperCaseTransformer(options) {
|
|
9
|
+
let self = this;
|
|
10
|
+
self.column = options.column;
|
|
11
|
+
return new Transform({
|
|
12
|
+
readableObjectMode: true,
|
|
13
|
+
writableObjectMode: true,
|
|
14
|
+
transform(chunk, _, callback) {
|
|
15
|
+
const { _columns } = chunk;
|
|
16
|
+
const colIndex = _columns.indexOf(self.column);
|
|
17
|
+
chunk[colIndex] = chunk[colIndex].toUpperCase();
|
|
18
|
+
callback(null, chunk);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
module.exports = {
|
|
23
|
+
ToUpperCaseTransformer
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Object} options
|
|
4
|
+
* @param {String} options.includeErrors
|
|
5
|
+
* @returns Writable
|
|
6
|
+
*/
|
|
7
|
+
export function ConsoleDestination(options: {
|
|
8
|
+
includeErrors: string;
|
|
9
|
+
}): Writable;
|
|
10
|
+
import { Writable } from "stream";
|
|
11
|
+
//# sourceMappingURL=consoleDestination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/consoleDestination.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,4CAHG;IAAwB,aAAa;CACrC,YAYF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Object} options
|
|
4
|
+
* @param {String} options.fileName
|
|
5
|
+
* @param {Boolean} options.headers
|
|
6
|
+
* @param {Boolean} options.includeErrors
|
|
7
|
+
* @param {Boolean} options.quotationMarks
|
|
8
|
+
* @returns Writable
|
|
9
|
+
*/
|
|
10
|
+
export function CSVFileDestination(options: {
|
|
11
|
+
fileName: string;
|
|
12
|
+
headers: boolean;
|
|
13
|
+
includeErrors: boolean;
|
|
14
|
+
quotationMarks: boolean;
|
|
15
|
+
}): Writable;
|
|
16
|
+
import { Writable } from "stream";
|
|
17
|
+
//# sourceMappingURL=csvFileDestination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csvFileDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/csvFileDestination.js"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,4CANG;IAAwB,QAAQ;IACP,OAAO;IACP,aAAa;IACb,cAAc;CACvC,YAkCF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConsoleDestination } from "./consoleDestination";
|
|
2
|
+
import { SQLFileDestination } from "./sqlFileDestination";
|
|
3
|
+
import { SQL_MODE } from "./sqlFileDestination";
|
|
4
|
+
import { CSVFileDestination } from "./csvFileDestination";
|
|
5
|
+
import { PostgresDestination } from "./postgresDestination";
|
|
6
|
+
export { ConsoleDestination, SQLFileDestination, SQL_MODE, CSVFileDestination, PostgresDestination };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/destinations/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Object} options
|
|
4
|
+
* @param {Object} options.table
|
|
5
|
+
* @param {Object} options.username
|
|
6
|
+
* @param {Object} options.password
|
|
7
|
+
* @param {Object} options.database
|
|
8
|
+
* @param {Object} options.host
|
|
9
|
+
* @param {Object} options.mapping
|
|
10
|
+
* @param {Object} options.includeErrors
|
|
11
|
+
* @returns Transform
|
|
12
|
+
*/
|
|
13
|
+
export function PostgresDestination(options: {
|
|
14
|
+
table: any;
|
|
15
|
+
username: any;
|
|
16
|
+
password: any;
|
|
17
|
+
database: any;
|
|
18
|
+
host: any;
|
|
19
|
+
mapping: any;
|
|
20
|
+
includeErrors: any;
|
|
21
|
+
}): Transform;
|
|
22
|
+
import { Transform } from "stream";
|
|
23
|
+
//# sourceMappingURL=postgresDestination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,6CATG;IAAwB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,OAAO;IACP,aAAa;CACrC,aAuDF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Object} options
|
|
4
|
+
* @param {String} options.fileName
|
|
5
|
+
* @param {SQL_MODE} options.mode
|
|
6
|
+
* @param {String} options.table
|
|
7
|
+
* @param {Array} options.mapping
|
|
8
|
+
* @param {Boolean} options.includeErrors
|
|
9
|
+
* @returns Transform
|
|
10
|
+
*/
|
|
11
|
+
export function SQLFileDestination(options: {
|
|
12
|
+
fileName: string;
|
|
13
|
+
mode: SQL_MODE;
|
|
14
|
+
table: string;
|
|
15
|
+
mapping: any[];
|
|
16
|
+
includeErrors: boolean;
|
|
17
|
+
}): Writable;
|
|
18
|
+
export type SQL_MODE = number;
|
|
19
|
+
export namespace SQL_MODE {
|
|
20
|
+
let INSERT_MODE: number;
|
|
21
|
+
let UPDATE_MODE: number;
|
|
22
|
+
}
|
|
23
|
+
import { Writable } from "stream";
|
|
24
|
+
//# sourceMappingURL=sqlFileDestination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlFileDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/sqlFileDestination.js"],"names":[],"mappings":"AAWA;;;;;;;;;GASG;AACH,4CAPG;IAAwB,QAAQ;IACN,IAAI,EAAtB,QAAQ;IACQ,KAAK;IACN,OAAO;IACL,aAAa;CACtC,YA4CF;uBA3DS,MAAM"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Etl = require("./lib");
|
|
2
|
+
import Validators = require("./validators");
|
|
3
|
+
import Transformers = require("./transformers");
|
|
4
|
+
import Loaders = require("./loaders");
|
|
5
|
+
import Destinations = require("./destinations");
|
|
6
|
+
export { Etl, Validators, Transformers, Loaders, Destinations };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Etl = any;
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} Etl
|
|
4
|
+
* @function loader
|
|
5
|
+
* @function pump
|
|
6
|
+
* @function validator
|
|
7
|
+
* @function destination
|
|
8
|
+
* @function transform
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @returns Etl
|
|
13
|
+
*/
|
|
14
|
+
export function Etl(): void;
|
|
15
|
+
export class Etl {
|
|
16
|
+
validatorList: any[];
|
|
17
|
+
transformationList: any[];
|
|
18
|
+
destinationList: any[];
|
|
19
|
+
loader: (loader: any) => this;
|
|
20
|
+
pump: () => void;
|
|
21
|
+
validator: (validator: any) => this;
|
|
22
|
+
destination: (destination: any) => this;
|
|
23
|
+
transform: (transform: any) => this;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";AAIA;;;;;;;GAOG;AAEH;;;GAGG;AACH,4BAwCC;;IAtCG,qBAAuB;IACvB,0BAA4B;IAC5B,uBAAyB;IAEzB,8BAGC;IAED,iBAWC;IAED,oCAGC;IAED,wCAGC;IAED,oCAGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowMetaData.d.ts","sourceRoot":"","sources":["../../../../src/lib/rowMetaData.js"],"names":[],"mappings":"AAIA,qDAgBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csvloader.d.ts","sourceRoot":"","sources":["../../../../src/loaders/csvloader.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,mCAHG;IAAwB,IAAI;CAC5B,iBAmBF"}
|