ffc-pay-etl-framework 0.0.9-alpha.13 → 0.0.9-alpha.4

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.
@@ -43,15 +43,29 @@ function PostgresDestination(options) {
43
43
  const [map] = mapping.filter(m => m.column === column);
44
44
  return map;
45
45
  }
46
+ function isKeyWord(column) {
47
+ return ['USER'].includes(column.toUpperCase());
48
+ }
46
49
  function writeInsertStatement(chunk) {
47
50
  let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
48
51
  let mapping = getMappingForColumn(column);
49
- return mapping ? mapping.targetColumn : column;
52
+ return mapping
53
+ ?
54
+ isKeyWord(mapping.targetColumn)
55
+ ? `"${mapping.targetColumn}"`
56
+ : mapping.targetColumn
57
+ : isKeyWord(column)
58
+ ? `"${mapping.column}"`
59
+ : mapping.column;
50
60
  })
51
61
  .join(",")}) VALUES (${chunk._columns.map((column, index) => {
52
62
  let mapping = getMappingForColumn(column);
53
63
  if (!mapping)
54
64
  debug('Mapping not found for column %s', column);
65
+ if (mapping.targetType === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
66
+ debug('Source data is not a number');
67
+ return 0;
68
+ }
55
69
  if (mapping.targetType === "varchar" || mapping.targetType === "char")
56
70
  return `'${chunk[index]}'`;
57
71
  return chunk[index] ? chunk[index] : 'null';
@@ -1,4 +1,6 @@
1
1
  // @ts-nocheck
2
+ const EventEmitter = require('node:events');
3
+ const util = require('node:util');
2
4
  const { RowMetaData } = require("./rowMetaData");
3
5
  const { compose } = require("node:stream");
4
6
  /**
@@ -14,6 +16,7 @@ const { compose } = require("node:stream");
14
16
  * @returns Etl
15
17
  */
16
18
  function Etl() {
19
+ EventEmitter.call(this);
17
20
  let self = this;
18
21
  self.validatorList = [];
19
22
  self.transformationList = [];
@@ -25,7 +28,10 @@ function Etl() {
25
28
  this.pump = () => {
26
29
  this.loader
27
30
  .pump(this.loader)
28
- .pipe(compose(RowMetaData(), ...self.validatorList, ...self.transformationList, ...self.destinationList));
31
+ .pipe(compose(RowMetaData(), ...self.validatorList, ...self.transformationList, ...self.destinationList)
32
+ // @ts-ignore
33
+ ).on('finish', (data) => self.emit('finish', data));
34
+ return self;
29
35
  };
30
36
  this.validator = (validator) => {
31
37
  self.validatorList.push(validator);
@@ -41,6 +47,7 @@ function Etl() {
41
47
  };
42
48
  return;
43
49
  }
50
+ util.inherits(Etl, EventEmitter);
44
51
  module.exports = {
45
52
  Etl
46
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,6CAVG;IAAwB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,aAAa;CACrC,aA+EF"}
1
+ {"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,6CAVG;IAAwB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,aAAa;CACrC,aA6FF"}
@@ -17,7 +17,7 @@ export class Etl {
17
17
  transformationList: any[];
18
18
  destinationList: any[];
19
19
  loader: (loader: any) => this;
20
- pump: () => void;
20
+ pump: () => this;
21
21
  validator: (validator: any) => this;
22
22
  destination: (destination: any) => this;
23
23
  transform: (transform: any) => this;
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";AAMA;;;;;;;GAOG;AAEH;;;GAGG;AACH,4BA2CC;;IAxCG,qBAAuB;IACvB,0BAA4B;IAC5B,uBAAyB;IAEzB,8BAGC;IAED,iBAaC;IAED,oCAGC;IAED,wCAGC;IAED,oCAGC"}
@@ -44,15 +44,29 @@ function PostgresDestination(options) {
44
44
  const [map] = mapping.filter(m => m.column === column);
45
45
  return map;
46
46
  }
47
+ function isKeyWord(column) {
48
+ return ['USER'].includes(column.toUpperCase());
49
+ }
47
50
  function writeInsertStatement(chunk) {
48
51
  let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
49
52
  let mapping = getMappingForColumn(column);
50
- return mapping ? mapping.targetColumn : column;
53
+ return mapping
54
+ ?
55
+ isKeyWord(mapping.targetColumn)
56
+ ? `"${mapping.targetColumn}"`
57
+ : mapping.targetColumn
58
+ : isKeyWord(column)
59
+ ? `"${mapping.column}"`
60
+ : mapping.column;
51
61
  })
52
62
  .join(",")}) VALUES (${chunk._columns.map((column, index) => {
53
63
  let mapping = getMappingForColumn(column);
54
64
  if (!mapping)
55
65
  debug('Mapping not found for column %s', column);
66
+ if (mapping.targetType === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
67
+ debug('Source data is not a number');
68
+ return 0;
69
+ }
56
70
  if (mapping.targetType === "varchar" || mapping.targetType === "char")
57
71
  return `'${chunk[index]}'`;
58
72
  return chunk[index] ? chunk[index] : 'null';
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
+ const EventEmitter = require('node:events');
4
+ const util = require('node:util');
3
5
  const { RowMetaData } = require("./rowMetaData");
4
6
  const { compose } = require("node:stream");
5
7
  /**
@@ -15,6 +17,7 @@ const { compose } = require("node:stream");
15
17
  * @returns Etl
16
18
  */
17
19
  function Etl() {
20
+ EventEmitter.call(this);
18
21
  let self = this;
19
22
  self.validatorList = [];
20
23
  self.transformationList = [];
@@ -26,7 +29,10 @@ function Etl() {
26
29
  this.pump = () => {
27
30
  this.loader
28
31
  .pump(this.loader)
29
- .pipe(compose(RowMetaData(), ...self.validatorList, ...self.transformationList, ...self.destinationList));
32
+ .pipe(compose(RowMetaData(), ...self.validatorList, ...self.transformationList, ...self.destinationList)
33
+ // @ts-ignore
34
+ ).on('finish', (data) => self.emit('finish', data));
35
+ return self;
30
36
  };
31
37
  this.validator = (validator) => {
32
38
  self.validatorList.push(validator);
@@ -42,6 +48,7 @@ function Etl() {
42
48
  };
43
49
  return;
44
50
  }
51
+ util.inherits(Etl, EventEmitter);
45
52
  module.exports = {
46
53
  Etl
47
54
  };
@@ -1 +1 @@
1
- {"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,6CAVG;IAAwB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,aAAa;CACrC,aA+EF"}
1
+ {"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,6CAVG;IAAwB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,aAAa;CACrC,aA6FF"}
@@ -17,7 +17,7 @@ export class Etl {
17
17
  transformationList: any[];
18
18
  destinationList: any[];
19
19
  loader: (loader: any) => this;
20
- pump: () => void;
20
+ pump: () => this;
21
21
  validator: (validator: any) => this;
22
22
  destination: (destination: any) => this;
23
23
  transform: (transform: any) => this;
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";AAMA;;;;;;;GAOG;AAEH;;;GAGG;AACH,4BA2CC;;IAxCG,qBAAuB;IACvB,0BAA4B;IAC5B,uBAAyB;IAEzB,8BAGC;IAED,iBAaC;IAED,oCAGC;IAED,wCAGC;IAED,oCAGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffc-pay-etl-framework",
3
- "version": "0.0.9-alpha.13",
3
+ "version": "0.0.9-alpha.4",
4
4
  "publisher": "Defra",
5
5
  "main": "dist/cjs/index.js",
6
6
  "private": false,
@@ -24,35 +24,6 @@
24
24
  "jest": {
25
25
  "setupFiles": [
26
26
  "<rootDir>/jest/setEnvVars.js"
27
- ],
28
- "collectCoverage": true,
29
- "collectCoverageFrom": [
30
- "**/*.js",
31
- "!**/*.test.js"
32
- ],
33
- "coverageDirectory": "test-output",
34
- "coverageReporters": [
35
- "text-summary",
36
- "lcov"
37
- ],
38
- "coveragePathIgnorePatterns": [
39
- "<rootDir>/node_modules/",
40
- "<rootDir>/test-output/",
41
- "<rootDir>/test/"
42
- ],
43
- "modulePathIgnorePatterns": [
44
- "node_modules"
45
- ],
46
- "reporters": [
47
- "default",
48
- [
49
- "jest-junit",
50
- {
51
- "suiteName": "jest tests",
52
- "outputDirectory": "test-output",
53
- "outputName": "junit.xml"
54
- }
55
- ]
56
27
  ]
57
28
  },
58
29
  "devDependencies": {
@@ -66,7 +37,6 @@
66
37
  "dependencies": {
67
38
  "@faker-js/faker": "^8.4.1",
68
39
  "csv": "^6.3.9",
69
- "jest-junit": "16.0.0",
70
40
  "mariadb": "^3.3.1",
71
41
  "mysql2": "^3.10.3",
72
42
  "oracledb": "^6.5.1",