ffc-pay-etl-framework 1.3.1-alpha.2 → 1.4.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.
Files changed (128) hide show
  1. package/README.md +0 -32
  2. package/package.json +16 -26
  3. package/dist/cjs/database_connections/index.js +0 -6
  4. package/dist/cjs/database_connections/postgresDatabaseConnection.js +0 -55
  5. package/dist/cjs/database_connections/providedConnection.js +0 -29
  6. package/dist/cjs/destinations/consoleDestination.js +0 -37
  7. package/dist/cjs/destinations/csvFileDestination.js +0 -74
  8. package/dist/cjs/destinations/index.js +0 -11
  9. package/dist/cjs/destinations/postgresDestination.js +0 -139
  10. package/dist/cjs/destinations/sqlFileDestination.js +0 -79
  11. package/dist/cjs/index.js +0 -14
  12. package/dist/cjs/lib/index.js +0 -91
  13. package/dist/cjs/lib/rowMetaData.js +0 -23
  14. package/dist/cjs/loaders/csvloader.js +0 -54
  15. package/dist/cjs/loaders/index.js +0 -4
  16. package/dist/cjs/transformers/fakerTransformer.js +0 -46
  17. package/dist/cjs/transformers/index.js +0 -8
  18. package/dist/cjs/transformers/stringReplaceTransformer.js +0 -32
  19. package/dist/cjs/transformers/toUpperCaseTransformer.js +0 -24
  20. package/dist/cjs/types/database_connections/index.d.ts +0 -4
  21. package/dist/cjs/types/database_connections/index.d.ts.map +0 -1
  22. package/dist/cjs/types/database_connections/postgresDatabaseConnection.d.ts +0 -24
  23. package/dist/cjs/types/database_connections/postgresDatabaseConnection.d.ts.map +0 -1
  24. package/dist/cjs/types/database_connections/providedConnection.d.ts +0 -15
  25. package/dist/cjs/types/database_connections/providedConnection.d.ts.map +0 -1
  26. package/dist/cjs/types/destinations/consoleDestination.d.ts +0 -11
  27. package/dist/cjs/types/destinations/consoleDestination.d.ts.map +0 -1
  28. package/dist/cjs/types/destinations/csvFileDestination.d.ts +0 -17
  29. package/dist/cjs/types/destinations/csvFileDestination.d.ts.map +0 -1
  30. package/dist/cjs/types/destinations/index.d.ts +0 -7
  31. package/dist/cjs/types/destinations/index.d.ts.map +0 -1
  32. package/dist/cjs/types/destinations/postgresDestination.d.ts +0 -26
  33. package/dist/cjs/types/destinations/postgresDestination.d.ts.map +0 -1
  34. package/dist/cjs/types/destinations/sqlFileDestination.d.ts +0 -24
  35. package/dist/cjs/types/destinations/sqlFileDestination.d.ts.map +0 -1
  36. package/dist/cjs/types/index.d.ts +0 -8
  37. package/dist/cjs/types/index.d.ts.map +0 -1
  38. package/dist/cjs/types/lib/index.d.ts +0 -31
  39. package/dist/cjs/types/lib/index.d.ts.map +0 -1
  40. package/dist/cjs/types/lib/rowMetaData.d.ts +0 -3
  41. package/dist/cjs/types/lib/rowMetaData.d.ts.map +0 -1
  42. package/dist/cjs/types/loaders/csvloader.d.ts +0 -18
  43. package/dist/cjs/types/loaders/csvloader.d.ts.map +0 -1
  44. package/dist/cjs/types/loaders/index.d.ts +0 -3
  45. package/dist/cjs/types/loaders/index.d.ts.map +0 -1
  46. package/dist/cjs/types/transformers/fakerTransformer.d.ts +0 -41
  47. package/dist/cjs/types/transformers/fakerTransformer.d.ts.map +0 -1
  48. package/dist/cjs/types/transformers/index.d.ts +0 -5
  49. package/dist/cjs/types/transformers/index.d.ts.map +0 -1
  50. package/dist/cjs/types/transformers/stringReplaceTransformer.d.ts +0 -25
  51. package/dist/cjs/types/transformers/stringReplaceTransformer.d.ts.map +0 -1
  52. package/dist/cjs/types/transformers/toUpperCaseTransformer.d.ts +0 -23
  53. package/dist/cjs/types/transformers/toUpperCaseTransformer.d.ts.map +0 -1
  54. package/dist/cjs/types/validators/index.d.ts +0 -5
  55. package/dist/cjs/types/validators/index.d.ts.map +0 -1
  56. package/dist/cjs/types/validators/multiToolValidator.d.ts +0 -23
  57. package/dist/cjs/types/validators/multiToolValidator.d.ts.map +0 -1
  58. package/dist/cjs/types/validators/requiredValidator.d.ts +0 -13
  59. package/dist/cjs/types/validators/requiredValidator.d.ts.map +0 -1
  60. package/dist/cjs/types/validators/uniqueValidator.d.ts +0 -29
  61. package/dist/cjs/types/validators/uniqueValidator.d.ts.map +0 -1
  62. package/dist/cjs/validators/index.js +0 -8
  63. package/dist/cjs/validators/multiToolValidator.js +0 -48
  64. package/dist/cjs/validators/requiredValidator.js +0 -33
  65. package/dist/cjs/validators/uniqueValidator.js +0 -40
  66. package/dist/esm/database_connections/index.js +0 -8
  67. package/dist/esm/database_connections/postgresDatabaseConnection.js +0 -46
  68. package/dist/esm/database_connections/providedConnection.js +0 -20
  69. package/dist/esm/destinations/consoleDestination.js +0 -37
  70. package/dist/esm/destinations/csvFileDestination.js +0 -74
  71. package/dist/esm/destinations/index.js +0 -13
  72. package/dist/esm/destinations/postgresDestination.js +0 -138
  73. package/dist/esm/destinations/sqlFileDestination.js +0 -80
  74. package/dist/esm/index.mjs +0 -16
  75. package/dist/esm/lib/index.js +0 -93
  76. package/dist/esm/lib/rowMetaData.js +0 -25
  77. package/dist/esm/loaders/csvloader.js +0 -55
  78. package/dist/esm/loaders/index.js +0 -6
  79. package/dist/esm/transformers/fakerTransformer.js +0 -48
  80. package/dist/esm/transformers/index.js +0 -10
  81. package/dist/esm/transformers/stringReplaceTransformer.js +0 -34
  82. package/dist/esm/transformers/toUpperCaseTransformer.js +0 -26
  83. package/dist/esm/types/database_connections/index.d.ts +0 -4
  84. package/dist/esm/types/database_connections/index.d.ts.map +0 -1
  85. package/dist/esm/types/database_connections/postgresDatabaseConnection.d.ts +0 -24
  86. package/dist/esm/types/database_connections/postgresDatabaseConnection.d.ts.map +0 -1
  87. package/dist/esm/types/database_connections/providedConnection.d.ts +0 -15
  88. package/dist/esm/types/database_connections/providedConnection.d.ts.map +0 -1
  89. package/dist/esm/types/destinations/consoleDestination.d.ts +0 -11
  90. package/dist/esm/types/destinations/consoleDestination.d.ts.map +0 -1
  91. package/dist/esm/types/destinations/csvFileDestination.d.ts +0 -17
  92. package/dist/esm/types/destinations/csvFileDestination.d.ts.map +0 -1
  93. package/dist/esm/types/destinations/index.d.ts +0 -7
  94. package/dist/esm/types/destinations/index.d.ts.map +0 -1
  95. package/dist/esm/types/destinations/postgresDestination.d.ts +0 -26
  96. package/dist/esm/types/destinations/postgresDestination.d.ts.map +0 -1
  97. package/dist/esm/types/destinations/sqlFileDestination.d.ts +0 -24
  98. package/dist/esm/types/destinations/sqlFileDestination.d.ts.map +0 -1
  99. package/dist/esm/types/index.d.ts +0 -8
  100. package/dist/esm/types/index.d.ts.map +0 -1
  101. package/dist/esm/types/lib/index.d.ts +0 -31
  102. package/dist/esm/types/lib/index.d.ts.map +0 -1
  103. package/dist/esm/types/lib/rowMetaData.d.ts +0 -3
  104. package/dist/esm/types/lib/rowMetaData.d.ts.map +0 -1
  105. package/dist/esm/types/loaders/csvloader.d.ts +0 -18
  106. package/dist/esm/types/loaders/csvloader.d.ts.map +0 -1
  107. package/dist/esm/types/loaders/index.d.ts +0 -3
  108. package/dist/esm/types/loaders/index.d.ts.map +0 -1
  109. package/dist/esm/types/transformers/fakerTransformer.d.ts +0 -41
  110. package/dist/esm/types/transformers/fakerTransformer.d.ts.map +0 -1
  111. package/dist/esm/types/transformers/index.d.ts +0 -5
  112. package/dist/esm/types/transformers/index.d.ts.map +0 -1
  113. package/dist/esm/types/transformers/stringReplaceTransformer.d.ts +0 -25
  114. package/dist/esm/types/transformers/stringReplaceTransformer.d.ts.map +0 -1
  115. package/dist/esm/types/transformers/toUpperCaseTransformer.d.ts +0 -23
  116. package/dist/esm/types/transformers/toUpperCaseTransformer.d.ts.map +0 -1
  117. package/dist/esm/types/validators/index.d.ts +0 -5
  118. package/dist/esm/types/validators/index.d.ts.map +0 -1
  119. package/dist/esm/types/validators/multiToolValidator.d.ts +0 -23
  120. package/dist/esm/types/validators/multiToolValidator.d.ts.map +0 -1
  121. package/dist/esm/types/validators/requiredValidator.d.ts +0 -13
  122. package/dist/esm/types/validators/requiredValidator.d.ts.map +0 -1
  123. package/dist/esm/types/validators/uniqueValidator.d.ts +0 -29
  124. package/dist/esm/types/validators/uniqueValidator.d.ts.map +0 -1
  125. package/dist/esm/validators/index.js +0 -10
  126. package/dist/esm/validators/multiToolValidator.js +0 -50
  127. package/dist/esm/validators/requiredValidator.js +0 -35
  128. package/dist/esm/validators/uniqueValidator.js +0 -42
package/README.md CHANGED
@@ -87,35 +87,3 @@ etl
87
87
  ## ✨ Contributing
88
88
 
89
89
  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.
90
-
91
- ## Contributors ✨
92
-
93
- Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
94
-
95
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
96
- <!-- prettier-ignore-start -->
97
- <!-- markdownlint-disable -->
98
- <table>
99
- <tbody>
100
- <tr>
101
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/suityou01"><img src="https://avatars.githubusercontent.com/u/7422644?v=4?s=100" width="100px;" alt="Charlie Benger-Stevenson"/><br /><sub><b>Charlie Benger-Stevenson</b></sub></a><br /><a href="https://github.com/DEFRA/ffc-pay-etl-framework/commits?author=suityou01" title="Code">💻</a></td>
102
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/GodsonLeigh"><img src="https://avatars.githubusercontent.com/u/139965284?v=4?s=100" width="100px;" alt="Leigh Godson"/><br /><sub><b>Leigh Godson</b></sub></a><br /><a href="https://github.com/DEFRA/ffc-pay-etl-framework/commits?author=GodsonLeigh" title="Code">💻</a></td>
103
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/samplackett"><img src="https://avatars.githubusercontent.com/u/60177449?v=4?s=100" width="100px;" alt="Sam Plackett"/><br /><sub><b>Sam Plackett</b></sub></a><br /><a href="https://github.com/DEFRA/ffc-pay-etl-framework/commits?author=samplackett" title="Code">💻</a></td> </tr>
104
- </tbody>
105
- <tfoot>
106
- <tr>
107
- <td align="center" size="13px" colspan="7">
108
- <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg">
109
- <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
110
- </img>
111
- </td>
112
- </tr>
113
- </tfoot>
114
- </table>
115
-
116
- <!-- markdownlint-restore -->
117
- <!-- prettier-ignore-end -->
118
-
119
- <!-- ALL-CONTRIBUTORS-LIST:END -->
120
-
121
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "ffc-pay-etl-framework",
3
- "version": "1.3.1-alpha.2",
3
+ "version": "1.4.0",
4
4
  "publisher": "Defra",
5
5
  "main": "dist/cjs/index.js",
6
6
  "private": false,
7
7
  "scripts": {
8
8
  "test": "jest",
9
9
  "test:watch": "jest --watchAll",
10
+ "test:lint": "eslint",
11
+ "test:lint:fix": "eslint --fix",
10
12
  "dev": "nodemon src/index.js",
11
13
  "clean": "rm -rf ./dist",
12
- "build": "npm run clean && npm run build:esm && npm run build:cjs",
13
- "build:esm": "tsc -p ./tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs",
14
- "build:cjs": "tsc -p ./tsconfig.cjs.json",
15
- "prepack": "npm run build",
16
14
  "example": "node ./src/examples/sql-return-values.js"
17
15
  },
18
16
  "keywords": [
@@ -21,8 +19,8 @@
21
19
  "author": "Defra",
22
20
  "contributors": [
23
21
  "Charlie Benger-Stevenson charlie.benger-stevenson.external@eviden.com",
24
- "Leigh Godson leigh.godson@eviden.com",
25
- "Sam Plackett samuel.plackett@eviden.com"
22
+ "Leigh Godson leigh.godson@atos.net",
23
+ "Sam Plackett samuel.plackett@atos.net"
26
24
  ],
27
25
  "license": "OGL-UK-3.0",
28
26
  "repository": "https://github.com/DEFRA/ffc-pay-etl-framework",
@@ -62,27 +60,19 @@
62
60
  ]
63
61
  },
64
62
  "devDependencies": {
65
- "all-contributors-cli": "^6.26.1",
66
- "debug": "^4.3.6",
67
- "jest": "^29.7.0",
68
- "jest-junit": "^16.0.0",
69
- "nodemon": "^3.1.4",
70
- "prettier": "3.3.3",
71
- "sequelize-mock": "^0.10.2",
72
- "supports-color": "^9.4.0"
63
+ "debug": "4.3.6",
64
+ "eslint": "9.39.1",
65
+ "jest": "29.7.0",
66
+ "jest-junit": "16.0.0",
67
+ "neostandard": "0.12.2",
68
+ "nodemon": "3.1.4",
69
+ "prettier": "3.3.3"
73
70
  },
74
71
  "dependencies": {
75
- "@faker-js/faker": "^8.4.1",
76
- "csv": "^6.3.9",
77
- "mariadb": "^3.3.1",
78
- "mysql2": "^3.14.1",
79
- "oracledb": "^6.5.1",
80
- "pg": "^8.12.0",
81
- "pg-hstore": "^2.3.4",
82
- "sequelize": "^6.37.3",
83
- "tedious": "^18.2.4",
84
- "typescript": "^4.0.0",
85
- "validator": "^13.12.0"
72
+ "@faker-js/faker": "8.4.1",
73
+ "csv-parse": "6.1.0",
74
+ "sequelize": "6.37.3",
75
+ "validator": "13.15.23"
86
76
  },
87
77
  "files": [
88
78
  "/dist/**/*"
@@ -1,6 +0,0 @@
1
- const { PostgresDatabaseConnection } = require("./postgresDatabaseConnection");
2
- const { ProvidedConnection } = require("./providedConnection");
3
- module.exports = {
4
- PostgresDatabaseConnection,
5
- ProvidedConnection
6
- };
@@ -1,55 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- const DEFAULT_PORT = 5432;
11
- const { Sequelize } = require('sequelize');
12
- const debug = require('debug')('connection');
13
- /**
14
- *
15
- * @param {Object} options
16
- * @param {Object} options.connectionname
17
- * @param {Object} options.username
18
- * @param {Object} options.password
19
- * @param {Object} options.database
20
- * @param {Object} options.host
21
- * @param {Object} options.port
22
- * @returns Connection
23
- */
24
- function PostgresDatabaseConnection(options) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const connectionname = options.connectionname;
27
- const username = options.username;
28
- const password = options.password;
29
- const database = options.database;
30
- const host = options.host;
31
- const port = options.port || DEFAULT_PORT;
32
- const sequelize = new Sequelize(database, username, password, {
33
- host: host,
34
- port: port,
35
- dialect: 'postgres',
36
- logging: false
37
- });
38
- try {
39
- yield sequelize.authenticate();
40
- debug('sequelize.authenticate succeeded');
41
- return {
42
- name: connectionname,
43
- db: sequelize
44
- };
45
- }
46
- catch (e) {
47
- debug('sequelize.authenticate failed');
48
- debug(e);
49
- throw e;
50
- }
51
- });
52
- }
53
- module.exports = {
54
- PostgresDatabaseConnection
55
- };
@@ -1,29 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /**
11
- *
12
- * @param {Object} options
13
- * @param {Object} options.connectionname
14
- * @param {Object} options.sequelize
15
- * @returns Connection
16
- */
17
- function ProvidedConnection(options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const connectionname = options.connectionname;
20
- const sequelize = options.sequelize;
21
- return {
22
- name: connectionname,
23
- db: sequelize
24
- };
25
- });
26
- }
27
- module.exports = {
28
- ProvidedConnection
29
- };
@@ -1,37 +0,0 @@
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
- const writable = new Writable({
11
- objectMode: true,
12
- write(chunk, _, callback) {
13
- var _a;
14
- if (chunk.errors.length === 0 || includeErrors)
15
- console.log(chunk);
16
- // @ts-ignore
17
- (_a = this.tasks) === null || _a === void 0 ? void 0 : _a.forEach(task => task.write(chunk));
18
- callback();
19
- }
20
- });
21
- Object.assign(writable, {
22
- setConnection: function (connection) {
23
- this.connection = connection;
24
- }.bind(writable),
25
- getConnectionName: function () {
26
- var _a;
27
- return (_a = this.connection) === null || _a === void 0 ? void 0 : _a.name;
28
- }.bind(writable),
29
- setTasks: function (tasks) {
30
- this.tasks = tasks;
31
- }.bind(writable)
32
- });
33
- return writable;
34
- }
35
- module.exports = {
36
- ConsoleDestination
37
- };
@@ -1,74 +0,0 @@
1
- const EventEmitter = require('node:events');
2
- const util = require('node:util');
3
- const { Writable } = require("node:stream");
4
- const fs = require("fs");
5
- /**
6
- *
7
- * @param {Object} options
8
- * @param {String} options.fileName
9
- * @param {Boolean} options.headers
10
- * @param {Boolean} options.includeErrors
11
- * @param {Boolean} options.quotationMarks
12
- * @returns Writable
13
- */
14
- function CSVFileDestination(options) {
15
- EventEmitter.call(this);
16
- let lastChunk;
17
- const fileName = options.fileName;
18
- const headers = options.headers;
19
- const includeErrors = options.includeErrors;
20
- const quotationMarks = options.quotationMarks;
21
- let fileHandle;
22
- fs.open(fileName, 'w+', ((error, fd) => {
23
- fileHandle = fd;
24
- }));
25
- let headersWritten = false;
26
- const writable = new Writable({
27
- objectMode: true,
28
- write(chunk, _, callback) {
29
- var _a;
30
- if (!headersWritten && headers) {
31
- if (quotationMarks) {
32
- fs.writeFileSync(fileHandle, `${chunk._columns.map(c => `"${c}"`).join(",")}\n`);
33
- }
34
- else {
35
- fs.writeFileSync(fileHandle, `${chunk._columns.join(",")}\n`);
36
- }
37
- headersWritten = true;
38
- }
39
- if (chunk.errors.length === 0 || includeErrors) {
40
- if (quotationMarks) {
41
- fs.writeFileSync(fileHandle, `${chunk.map(c => `"${c}"`).join(",")}\n`);
42
- }
43
- else {
44
- fs.writeFileSync(fileHandle, `${chunk.map(c => `"${c}"`).join(",")}\n`);
45
- }
46
- }
47
- // @ts-ignore
48
- (_a = this.tasks) === null || _a === void 0 ? void 0 : _a.forEach(task => task.write(chunk));
49
- lastChunk = chunk;
50
- callback();
51
- },
52
- final(callback) {
53
- this.emit('result', lastChunk);
54
- callback();
55
- }
56
- });
57
- Object.assign(writable, {
58
- setConnection: function (connection) {
59
- this.connection = connection;
60
- }.bind(writable),
61
- getConnectionName: function () {
62
- var _a;
63
- return (_a = this.connection) === null || _a === void 0 ? void 0 : _a.name;
64
- }.bind(writable),
65
- setTasks: function (tasks) {
66
- this.tasks = tasks;
67
- }.bind(writable)
68
- });
69
- return writable;
70
- }
71
- util.inherits(CSVFileDestination, EventEmitter);
72
- module.exports = {
73
- CSVFileDestination
74
- };
@@ -1,11 +0,0 @@
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
- };
@@ -1,139 +0,0 @@
1
- const EventEmitter = require('node:events');
2
- const { Transform } = require('node:stream');
3
- const debug = require('debug')('destination');
4
- const DEFAULT_PORT = 5432;
5
- function isKeyWord(column) {
6
- return ['USER'].includes(column.toUpperCase());
7
- }
8
- function getMappingForColumn(mapping, column) {
9
- if (mapping.length === 0) {
10
- return {};
11
- }
12
- const [map] = mapping.filter(m => m.column === column);
13
- return map;
14
- }
15
- function hasReturningColumns(mapping) {
16
- return mapping.filter(m => m.returning === true).length > 0;
17
- }
18
- function getReturningColumns(mapping) {
19
- return mapping.filter(m => m.returning === true).map(m => m === null || m === void 0 ? void 0 : m.targetColumn);
20
- }
21
- function writeInsertStatement(columnMapping, table, chunk, schema, ignoredColumns = []) {
22
- const filteredColumns = chunk._columns.filter(column => {
23
- const mapping = getMappingForColumn(columnMapping, column);
24
- const targetColumn = (mapping === null || mapping === void 0 ? void 0 : mapping.targetColumn) ? mapping === null || mapping === void 0 ? void 0 : mapping.targetColumn : mapping === null || mapping === void 0 ? void 0 : mapping.column;
25
- return !ignoredColumns.includes(targetColumn);
26
- });
27
- let statement = `INSERT INTO ${schema !== null && schema !== void 0 ? schema : 'public'}."${table}" (${filteredColumns.map(column => {
28
- const mapping = getMappingForColumn(columnMapping, column);
29
- return (mapping === null || mapping === void 0 ? void 0 : mapping.targetColumn) ? `"${mapping.targetColumn}"` : `"${mapping === null || mapping === void 0 ? void 0 : mapping.column}"`;
30
- })
31
- .join(",")}) VALUES (${filteredColumns.map(column => {
32
- const index = chunk._columns.indexOf(column);
33
- const mapping = getMappingForColumn(columnMapping, column);
34
- if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
35
- debug('Source data is not a number.');
36
- return 0;
37
- }
38
- if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "varchar" || (mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "char") {
39
- return `'${chunk[index]}'`;
40
- }
41
- if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "date") {
42
- if (!chunk[index]) {
43
- return `''`;
44
- }
45
- return `to_timestamp('${chunk[index]}','${mapping === null || mapping === void 0 ? void 0 : mapping.format}')`;
46
- }
47
- return chunk[index] ? chunk[index] : 'null';
48
- })})`;
49
- if (hasReturningColumns(columnMapping)) {
50
- statement = statement + ` RETURNING ${getReturningColumns(columnMapping).join(',')}`;
51
- }
52
- return statement;
53
- }
54
- /**
55
- *
56
- * @param {Object} options
57
- * @param {Object} options.table
58
- * @param {Object} options.connectionname
59
- * @param {Object} options.mapping
60
- * @param {Object} options.includeErrors
61
- * @param {String} [options.schema]
62
- * @param {Array<String>} [options.ignoredColumns]
63
- * @returns Transform
64
- */
65
- function PostgresDestination(options) {
66
- var _a;
67
- EventEmitter.call(this);
68
- const table = options.table;
69
- const connectionname = options.connectionname;
70
- const mapping = options.mapping;
71
- const includeErrors = options.includeErrors;
72
- const schema = options.schema;
73
- const ignoredColumns = (_a = options.ignoredColumns) !== null && _a !== void 0 ? _a : [];
74
- let lastChunk;
75
- const transform = new Transform({
76
- objectMode: true,
77
- emitClose: true,
78
- construct(callback) {
79
- // @ts-ignore
80
- this.connectionname = connectionname;
81
- callback();
82
- },
83
- write(chunk, _, callback) {
84
- let insertStatement;
85
- // @ts-ignore
86
- if (chunk.errors.length === 0 || options.includeErrors) {
87
- insertStatement = writeInsertStatement(mapping, table, chunk, schema, ignoredColumns);
88
- debug('Insert statement: [%s]', insertStatement);
89
- // @ts-ignore
90
- this.connection.db.query(insertStatement)
91
- .then(result => {
92
- var _a;
93
- debug('result %o', result);
94
- chunk._result = result;
95
- lastChunk = chunk;
96
- // @ts-ignore
97
- (_a = this.tasks) === null || _a === void 0 ? void 0 : _a.forEach(task => task.write(chunk));
98
- // @ts-ignore
99
- callback(null, chunk);
100
- }).catch(error => {
101
- debug('error %o', error);
102
- chunk.errors.push(error);
103
- lastChunk = chunk;
104
- // @ts-ignore
105
- callback(error, chunk);
106
- });
107
- }
108
- else {
109
- debug('Chunk has errors %o', chunk);
110
- }
111
- },
112
- final(callback) {
113
- this.emit('result', lastChunk);
114
- callback();
115
- }
116
- });
117
- Object.assign(Transform.prototype, {
118
- type: 'PostgresDestination',
119
- setConnection: function (connection) {
120
- this.connection = connection;
121
- }.bind(transform),
122
- getConnectionName: function () {
123
- var _a;
124
- return (_a = this.connection) === null || _a === void 0 ? void 0 : _a.name;
125
- }.bind(transform),
126
- setTasks: function (tasks) {
127
- this.tasks = tasks;
128
- }.bind(transform)
129
- });
130
- return transform;
131
- }
132
- module.exports = {
133
- PostgresDestination,
134
- writeInsertStatement,
135
- isKeyWord,
136
- getMappingForColumn,
137
- hasReturningColumns,
138
- getReturningColumns
139
- };
@@ -1,79 +0,0 @@
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
- //TODO
41
- }
42
- const writable = new Writable({
43
- objectMode: true,
44
- write(chunk, _, callback) {
45
- if (chunk.errors.length === 0)
46
- if (sqlMode === SQL_MODE.INSERT_MODE) {
47
- // @ts-ignore
48
- if (chunk.errors.length === 0 | includeErrors) {
49
- writeInsertStatement(chunk);
50
- }
51
- }
52
- // TODO - Disabled because Sonar
53
- // } else if (sqlMode === SQL_MODE.UPDATE_MODE){
54
- // // @ts-ignore
55
- // if(chunk.errors.length === 0 | includeErrors){
56
- // writeUpdateStatement(chunk)
57
- // }
58
- // }
59
- callback();
60
- }
61
- });
62
- Object.assign(writable, {
63
- setConnection: function (connection) {
64
- this.connection = connection;
65
- }.bind(writable),
66
- getConnectionName: function () {
67
- var _a;
68
- return (_a = this.connection) === null || _a === void 0 ? void 0 : _a.name;
69
- }.bind(writable),
70
- setTasks: function (tasks) {
71
- this.tasks = tasks;
72
- }.bind(writable)
73
- });
74
- return writable;
75
- }
76
- module.exports = {
77
- SQLFileDestination,
78
- SQL_MODE
79
- };
package/dist/cjs/index.js DELETED
@@ -1,14 +0,0 @@
1
- const Validators = require("./validators");
2
- const Transformers = require("./transformers");
3
- const Loaders = require("./loaders");
4
- const Destinations = require("./destinations");
5
- const Connections = require("./database_connections");
6
- const Etl = require("./lib");
7
- module.exports = {
8
- Etl,
9
- Validators,
10
- Transformers,
11
- Loaders,
12
- Destinations,
13
- Connections
14
- };
@@ -1,91 +0,0 @@
1
- // @ts-nocheck
2
- const EventEmitter = require('node:events');
3
- const util = require('node:util');
4
- const { RowMetaData } = require("./rowMetaData");
5
- const { compose } = require("node:stream");
6
- const { Destinations } = require('..');
7
- /**
8
- * @typedef {Object} Etl
9
- * @function loader
10
- * @function pump
11
- * @function connection
12
- * @function validator
13
- * @function destination
14
- * @function transform
15
- */
16
- /**
17
- *
18
- * @returns Etl
19
- */
20
- function Etl() {
21
- EventEmitter.call(this);
22
- const self = this;
23
- self.store = [];
24
- self.beforeETLList = [];
25
- self.connectionList = [];
26
- self.validatorList = [];
27
- self.transformationList = [];
28
- self.destinationList = [];
29
- this.loader = (loader) => {
30
- self.loader = loader;
31
- return self;
32
- };
33
- this.pump = () => {
34
- this.beforeETLList.forEach(task => {
35
- task.write({});
36
- });
37
- this.loader
38
- .pump(this.loader)
39
- .pipe(compose(RowMetaData(), ...self.validatorList, ...self.transformationList, ...self.destinationList.map(dl => dl.on('result', (data) => self.emit('result', data))))
40
- // @ts-ignore
41
- )
42
- .on('error', (err) => self.emit('error', err));
43
- return self;
44
- };
45
- this.beforeETL = (pipelineTask) => {
46
- const connectionname = pipelineTask.getConnectionName();
47
- const connection = this.connectionList.filter(c => c.name === connectionname)[0];
48
- if (!connection) {
49
- throw new Error(`Connection with name ${connectionname} not found`);
50
- }
51
- pipelineTask.setConnection(connection);
52
- pipelineTask.setETL(self);
53
- self.beforeETLList.push(pipelineTask);
54
- return self;
55
- };
56
- this.connection = (connection) => {
57
- self.connectionList.push(connection);
58
- return self;
59
- };
60
- this.validator = (validator) => {
61
- self.validatorList.push(validator);
62
- return self;
63
- };
64
- this.destination = (destination, ...tasks) => {
65
- const connectionname = destination.getConnectionName();
66
- const connection = this.connectionList.filter(c => c.name === connectionname)[0];
67
- if (!connection && destination.type === 'PostgresDestination') {
68
- throw new Error(`No connection could be found with name ${connectionname}`);
69
- }
70
- else {
71
- destination.setConnection(connection);
72
- }
73
- if (tasks) {
74
- for (const task of tasks) {
75
- task.setETL(self);
76
- }
77
- destination.setTasks(tasks);
78
- }
79
- self.destinationList.push(destination);
80
- return self;
81
- };
82
- this.transform = (transform) => {
83
- self.transformationList.push(transform);
84
- return self;
85
- };
86
- return;
87
- }
88
- util.inherits(Etl, EventEmitter);
89
- module.exports = {
90
- Etl
91
- };
@@ -1,23 +0,0 @@
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
- };