ffc-pay-etl-framework 1.1.0-alpha.2 → 1.1.0-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.
- package/dist/cjs/destinations/postgresDestination.js +12 -12
- package/dist/cjs/lib/index.js +4 -0
- package/dist/cjs/types/destinations/postgresDestination.d.ts.map +1 -1
- package/dist/cjs/types/lib/index.d.ts.map +1 -1
- package/dist/esm/destinations/postgresDestination.js +12 -12
- package/dist/esm/lib/index.js +4 -0
- package/dist/esm/types/destinations/postgresDestination.d.ts.map +1 -1
- package/dist/esm/types/lib/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const EventEmitter = require('node:events');
|
|
2
2
|
const { Transform } = require('node:stream');
|
|
3
|
-
const { Sequelize } = require('sequelize');
|
|
4
3
|
const debug = require('debug')('destination');
|
|
5
4
|
const DEFAULT_PORT = 5432;
|
|
6
5
|
function isKeyWord(column) {
|
|
7
6
|
return ['USER'].includes(column.toUpperCase());
|
|
8
7
|
}
|
|
9
8
|
function getMappingForColumn(mapping, column) {
|
|
9
|
+
if (mapping.length === 0) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
10
12
|
const [map] = mapping.filter(m => m.column === column);
|
|
11
13
|
return map;
|
|
12
14
|
}
|
|
@@ -14,34 +16,31 @@ function hasReturningColumns(mapping) {
|
|
|
14
16
|
return mapping.filter(m => m.returning === true).length > 0;
|
|
15
17
|
}
|
|
16
18
|
function getReturningColumns(mapping) {
|
|
17
|
-
return mapping.filter(m => m.returning === true).map(m => m.targetColumn);
|
|
19
|
+
return mapping.filter(m => m.returning === true).map(m => m === null || m === void 0 ? void 0 : m.targetColumn);
|
|
18
20
|
}
|
|
19
21
|
function writeInsertStatement(columnMapping, table, chunk) {
|
|
20
22
|
let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
|
|
21
23
|
const mapping = getMappingForColumn(columnMapping, column);
|
|
22
|
-
return mapping.targetColumn
|
|
24
|
+
return (mapping === null || mapping === void 0 ? void 0 : mapping.targetColumn)
|
|
23
25
|
?
|
|
24
26
|
isKeyWord(mapping.targetColumn)
|
|
25
27
|
? `"${mapping.targetColumn}"`
|
|
26
28
|
: mapping.targetColumn
|
|
27
29
|
: isKeyWord(column)
|
|
28
|
-
? `"${mapping.column}"`
|
|
29
|
-
: mapping.column;
|
|
30
|
+
? `"${mapping === null || mapping === void 0 ? void 0 : mapping.column}"`
|
|
31
|
+
: mapping === null || mapping === void 0 ? void 0 : mapping.column;
|
|
30
32
|
})
|
|
31
33
|
.join(",")}) VALUES (${chunk._columns.map((column, index) => {
|
|
32
34
|
const mapping = getMappingForColumn(columnMapping, column);
|
|
33
|
-
if (
|
|
34
|
-
debug('Mapping not found for column %s', column);
|
|
35
|
-
}
|
|
36
|
-
if (mapping.targetType === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
|
|
35
|
+
if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
|
|
37
36
|
debug('Source data is not a number');
|
|
38
37
|
return 0;
|
|
39
38
|
}
|
|
40
|
-
if (mapping.targetType === "varchar" || mapping.targetType === "char") {
|
|
39
|
+
if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "varchar" || (mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "char") {
|
|
41
40
|
return `'${chunk[index]}'`;
|
|
42
41
|
}
|
|
43
|
-
if (mapping.targetType === "date") {
|
|
44
|
-
return `to_date('${chunk[index]}','${mapping.format}')`;
|
|
42
|
+
if ((mapping === null || mapping === void 0 ? void 0 : mapping.targetType) === "date") {
|
|
43
|
+
return `to_date('${chunk[index]}','${mapping === null || mapping === void 0 ? void 0 : mapping.format}')`;
|
|
45
44
|
}
|
|
46
45
|
return chunk[index] ? chunk[index] : 'null';
|
|
47
46
|
})})`;
|
|
@@ -109,6 +108,7 @@ function PostgresDestination(options) {
|
|
|
109
108
|
}
|
|
110
109
|
});
|
|
111
110
|
Object.assign(Transform.prototype, {
|
|
111
|
+
type: 'PostgresDestination',
|
|
112
112
|
setConnection: function (connection) {
|
|
113
113
|
this.connection = connection;
|
|
114
114
|
}.bind(transform),
|
package/dist/cjs/lib/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const EventEmitter = require('node:events');
|
|
|
3
3
|
const util = require('node:util');
|
|
4
4
|
const { RowMetaData } = require("./rowMetaData");
|
|
5
5
|
const { compose } = require("node:stream");
|
|
6
|
+
const { Destinations } = require('..');
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {Object} Etl
|
|
8
9
|
* @function loader
|
|
@@ -65,6 +66,9 @@ function Etl() {
|
|
|
65
66
|
if (connection) {
|
|
66
67
|
destination.setConnection(connection);
|
|
67
68
|
}
|
|
69
|
+
else if (destination.type === 'PostgresDestination') {
|
|
70
|
+
throw new Error(`No connection could be found with name ${connectionname}`);
|
|
71
|
+
}
|
|
68
72
|
if (tasks) {
|
|
69
73
|
for (const task of tasks) {
|
|
70
74
|
task.setETL(self);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAuDA;;;;;;;;GAQG;AACH;IAN2B,KAAK;IACL,cAAc;IACd,OAAO;IACP,aAAa;cAgEvC;AAtGD,yFA8BC;AAhDD,gDAEC;AAED,oEAIC;AAED,2DAEC;AAED,uDAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";AAOA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,4BAgFC;;IA7EG,aAAe;IACf,qBAAuB;IACvB,sBAAwB;IACxB,qBAAuB;IACvB,0BAA4B;IAC5B,uBAAyB;IAEzB,6BAGC;IAED,gBAgBC;IAED,sCAUC;IAED,qCAGC;IAED,mCAGC;IAED,wDAiBC;IAED,mCAGC"}
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const EventEmitter = require('node:events');
|
|
4
4
|
const { Transform } = require('node:stream');
|
|
5
|
-
const { Sequelize } = require('sequelize');
|
|
6
5
|
const debug = require('debug')('destination');
|
|
7
6
|
const DEFAULT_PORT = 5432;
|
|
8
7
|
function isKeyWord(column) {
|
|
9
8
|
return ['USER'].includes(column.toUpperCase());
|
|
10
9
|
}
|
|
11
10
|
function getMappingForColumn(mapping, column) {
|
|
11
|
+
if (mapping.length === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
12
14
|
const [map] = mapping.filter(m => m.column === column);
|
|
13
15
|
return map;
|
|
14
16
|
}
|
|
@@ -16,34 +18,31 @@ function hasReturningColumns(mapping) {
|
|
|
16
18
|
return mapping.filter(m => m.returning === true).length > 0;
|
|
17
19
|
}
|
|
18
20
|
function getReturningColumns(mapping) {
|
|
19
|
-
return mapping.filter(m => m.returning === true).map(m => m
|
|
21
|
+
return mapping.filter(m => m.returning === true).map(m => m?.targetColumn);
|
|
20
22
|
}
|
|
21
23
|
function writeInsertStatement(columnMapping, table, chunk) {
|
|
22
24
|
let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
|
|
23
25
|
const mapping = getMappingForColumn(columnMapping, column);
|
|
24
|
-
return mapping
|
|
26
|
+
return mapping?.targetColumn
|
|
25
27
|
?
|
|
26
28
|
isKeyWord(mapping.targetColumn)
|
|
27
29
|
? `"${mapping.targetColumn}"`
|
|
28
30
|
: mapping.targetColumn
|
|
29
31
|
: isKeyWord(column)
|
|
30
|
-
? `"${mapping
|
|
31
|
-
: mapping
|
|
32
|
+
? `"${mapping?.column}"`
|
|
33
|
+
: mapping?.column;
|
|
32
34
|
})
|
|
33
35
|
.join(",")}) VALUES (${chunk._columns.map((column, index) => {
|
|
34
36
|
const mapping = getMappingForColumn(columnMapping, column);
|
|
35
|
-
if (
|
|
36
|
-
debug('Mapping not found for column %s', column);
|
|
37
|
-
}
|
|
38
|
-
if (mapping.targetType === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
|
|
37
|
+
if (mapping?.targetType === "number" && (isNaN(chunk[index]) || chunk[index] === '')) {
|
|
39
38
|
debug('Source data is not a number');
|
|
40
39
|
return 0;
|
|
41
40
|
}
|
|
42
|
-
if (mapping
|
|
41
|
+
if (mapping?.targetType === "varchar" || mapping?.targetType === "char") {
|
|
43
42
|
return `'${chunk[index]}'`;
|
|
44
43
|
}
|
|
45
|
-
if (mapping
|
|
46
|
-
return `to_date('${chunk[index]}','${mapping
|
|
44
|
+
if (mapping?.targetType === "date") {
|
|
45
|
+
return `to_date('${chunk[index]}','${mapping?.format}')`;
|
|
47
46
|
}
|
|
48
47
|
return chunk[index] ? chunk[index] : 'null';
|
|
49
48
|
})})`;
|
|
@@ -110,6 +109,7 @@ function PostgresDestination(options) {
|
|
|
110
109
|
}
|
|
111
110
|
});
|
|
112
111
|
Object.assign(Transform.prototype, {
|
|
112
|
+
type: 'PostgresDestination',
|
|
113
113
|
setConnection: function (connection) {
|
|
114
114
|
this.connection = connection;
|
|
115
115
|
}.bind(transform),
|
package/dist/esm/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const EventEmitter = require('node:events');
|
|
|
5
5
|
const util = require('node:util');
|
|
6
6
|
const { RowMetaData } = require("./rowMetaData");
|
|
7
7
|
const { compose } = require("node:stream");
|
|
8
|
+
const { Destinations } = require('..');
|
|
8
9
|
/**
|
|
9
10
|
* @typedef {Object} Etl
|
|
10
11
|
* @function loader
|
|
@@ -67,6 +68,9 @@ function Etl() {
|
|
|
67
68
|
if (connection) {
|
|
68
69
|
destination.setConnection(connection);
|
|
69
70
|
}
|
|
71
|
+
else if (destination.type === 'PostgresDestination') {
|
|
72
|
+
throw new Error(`No connection could be found with name ${connectionname}`);
|
|
73
|
+
}
|
|
70
74
|
if (tasks) {
|
|
71
75
|
for (const task of tasks) {
|
|
72
76
|
task.setETL(self);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgresDestination.d.ts","sourceRoot":"","sources":["../../../../src/destinations/postgresDestination.js"],"names":[],"mappings":"AAuDA;;;;;;;;GAQG;AACH;IAN2B,KAAK;IACL,cAAc;IACd,OAAO;IACP,aAAa;cAgEvC;AAtGD,yFA8BC;AAhDD,gDAEC;AAED,oEAIC;AAED,2DAEC;AAED,uDAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/index.js"],"names":[],"mappings":";AAOA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,4BAgFC;;IA7EG,aAAe;IACf,qBAAuB;IACvB,sBAAwB;IACxB,qBAAuB;IACvB,0BAA4B;IAC5B,uBAAyB;IAEzB,6BAGC;IAED,gBAgBC;IAED,sCAUC;IAED,qCAGC;IAED,mCAGC;IAED,wDAiBC;IAED,mCAGC"}
|