bellboy 8.4.0 → 8.5.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/README.md +1 -1
- package/lib/destinations/base/database-destination.js +10 -70
- package/lib/destinations/base/destination.js +10 -47
- package/lib/destinations/http-destination.js +20 -98
- package/lib/destinations/mssql-destination.js +41 -137
- package/lib/destinations/mysql-destination.js +30 -109
- package/lib/destinations/postgres-destination.js +49 -119
- package/lib/destinations/stdout-destination.js +11 -67
- package/lib/job.js +169 -424
- package/lib/processors/base/database-processor.js +8 -23
- package/lib/processors/base/directory-processor.js +16 -33
- package/lib/processors/base/processor.js +7 -47
- package/lib/processors/delimited-processor.js +43 -111
- package/lib/processors/dynamic-processor.js +12 -72
- package/lib/processors/excel-processor.js +43 -122
- package/lib/processors/firebird-processor.js +31 -96
- package/lib/processors/http-processor.js +82 -175
- package/lib/processors/json-processor.js +27 -99
- package/lib/processors/mqtt-processor.js +24 -91
- package/lib/processors/mssql-processor.js +79 -179
- package/lib/processors/mysql-processor.js +15 -81
- package/lib/processors/postgres-processor.js +17 -83
- package/lib/processors/tail-processor.js +33 -102
- package/lib/reporters/base/reporter.js +5 -7
- package/lib/types.d.ts +6 -7
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js +91 -281
- package/package.json +31 -31
package/README.md
CHANGED
|
@@ -817,7 +817,7 @@ class CustomReporter extends bellboy.Reporter {
|
|
|
817
817
|
|
|
818
818
|
## Testing
|
|
819
819
|
|
|
820
|
-
Tests can be run by using `docker
|
|
820
|
+
Tests can be run by using `docker compose up --abort-on-container-exit --exit-code-from test --build test` command.
|
|
821
821
|
|
|
822
822
|
[mssql-url]: https://github.com/tediousjs/node-mssql
|
|
823
823
|
[tedious-url]: https://www.npmjs.com/package/tedious
|
|
@@ -1,75 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
26
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
-
function step(op) {
|
|
29
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
-
while (_) try {
|
|
31
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
32
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
-
switch (op[0]) {
|
|
34
|
-
case 0: case 1: t = op; break;
|
|
35
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
-
default:
|
|
39
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
-
if (t[2]) _.ops.pop();
|
|
44
|
-
_.trys.pop(); continue;
|
|
45
|
-
}
|
|
46
|
-
op = body.call(thisArg, _);
|
|
47
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
3
|
exports.DatabaseDestination = void 0;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
4
|
+
const destination_1 = require("./destination");
|
|
5
|
+
class DatabaseDestination extends destination_1.Destination {
|
|
6
|
+
table;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
this.table = config.table;
|
|
10
|
+
}
|
|
11
|
+
async loadBatch(data) {
|
|
12
|
+
await super.loadBatch(data);
|
|
60
13
|
}
|
|
61
|
-
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
return __generator(this, function (_a) {
|
|
64
|
-
switch (_a.label) {
|
|
65
|
-
case 0: return [4 /*yield*/, _super.prototype.loadBatch.call(this, data)];
|
|
66
|
-
case 1:
|
|
67
|
-
_a.sent();
|
|
68
|
-
return [2 /*return*/];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
return DatabaseDestination;
|
|
74
|
-
}(destination_1.Destination));
|
|
14
|
+
}
|
|
75
15
|
exports.DatabaseDestination = DatabaseDestination;
|
|
@@ -1,44 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.Destination = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
4
|
+
class Destination {
|
|
5
|
+
batchSize;
|
|
6
|
+
recordGenerator;
|
|
7
|
+
batchTransformer;
|
|
8
|
+
disableLoad;
|
|
9
|
+
constructor(config) {
|
|
42
10
|
this.batchSize = 0;
|
|
43
11
|
this.disableLoad = false;
|
|
44
12
|
if (config) {
|
|
@@ -48,13 +16,8 @@ var Destination = /** @class */ (function () {
|
|
|
48
16
|
this.disableLoad = !!config.disableLoad;
|
|
49
17
|
}
|
|
50
18
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
return Destination;
|
|
59
|
-
}());
|
|
19
|
+
async loadBatch(data) {
|
|
20
|
+
throw new Error('Method not implemented.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
60
23
|
exports.Destination = Destination;
|
|
@@ -1,104 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __assign = (this && this.__assign) || function () {
|
|
16
|
-
__assign = Object.assign || function(t) {
|
|
17
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
-
s = arguments[i];
|
|
19
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
-
t[p] = s[p];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
return __assign.apply(this, arguments);
|
|
25
|
-
};
|
|
26
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
37
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
38
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
-
function step(op) {
|
|
40
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
-
while (_) try {
|
|
42
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
43
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
-
switch (op[0]) {
|
|
45
|
-
case 0: case 1: t = op; break;
|
|
46
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
-
default:
|
|
50
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
-
if (t[2]) _.ops.pop();
|
|
55
|
-
_.trys.pop(); continue;
|
|
56
|
-
}
|
|
57
|
-
op = body.call(thisArg, _);
|
|
58
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
63
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
|
-
};
|
|
65
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
3
|
exports.HttpDestination = void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const destination_1 = require("./base/destination");
|
|
8
|
+
class HttpDestination extends destination_1.Destination {
|
|
9
|
+
request;
|
|
10
|
+
authorizationRequest;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config);
|
|
13
|
+
this.request = config.request;
|
|
14
|
+
this.authorizationRequest = config.authorizationRequest;
|
|
77
15
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
case 1:
|
|
85
|
-
_a.sent();
|
|
86
|
-
i = 0;
|
|
87
|
-
_a.label = 2;
|
|
88
|
-
case 2:
|
|
89
|
-
if (!(i < data.length)) return [3 /*break*/, 5];
|
|
90
|
-
return [4 /*yield*/, axios_1.default(__assign(__assign({}, this.request), { data: data[i] }))];
|
|
91
|
-
case 3:
|
|
92
|
-
_a.sent();
|
|
93
|
-
_a.label = 4;
|
|
94
|
-
case 4:
|
|
95
|
-
i++;
|
|
96
|
-
return [3 /*break*/, 2];
|
|
97
|
-
case 5: return [2 /*return*/];
|
|
98
|
-
}
|
|
16
|
+
async loadBatch(data) {
|
|
17
|
+
await (0, utils_1.applyHttpAuthorization)(this.request, this.authorizationRequest);
|
|
18
|
+
for (let i = 0; i < data.length; i++) {
|
|
19
|
+
await (0, axios_1.default)({
|
|
20
|
+
...this.request,
|
|
21
|
+
data: data[i],
|
|
99
22
|
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}(destination_1.Destination));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
104
26
|
exports.HttpDestination = HttpDestination;
|
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __assign = (this && this.__assign) || function () {
|
|
16
|
-
__assign = Object.assign || function(t) {
|
|
17
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
-
s = arguments[i];
|
|
19
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
-
t[p] = s[p];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
return __assign.apply(this, arguments);
|
|
25
|
-
};
|
|
26
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
27
3
|
if (k2 === undefined) k2 = k;
|
|
28
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
29
9
|
}) : (function(o, m, k, k2) {
|
|
30
10
|
if (k2 === undefined) k2 = k;
|
|
31
11
|
o[k2] = m[k];
|
|
@@ -42,119 +22,43 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
42
22
|
__setModuleDefault(result, mod);
|
|
43
23
|
return result;
|
|
44
24
|
};
|
|
45
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
46
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
47
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
48
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
49
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
50
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
51
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
55
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
56
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
57
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
58
|
-
function step(op) {
|
|
59
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
60
|
-
while (_) try {
|
|
61
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
62
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
63
|
-
switch (op[0]) {
|
|
64
|
-
case 0: case 1: t = op; break;
|
|
65
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
66
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
67
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
68
|
-
default:
|
|
69
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
70
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
71
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
72
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
73
|
-
if (t[2]) _.ops.pop();
|
|
74
|
-
_.trys.pop(); continue;
|
|
75
|
-
}
|
|
76
|
-
op = body.call(thisArg, _);
|
|
77
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
78
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
26
|
exports.MssqlDestination = void 0;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
27
|
+
const database_destination_1 = require("./base/database-destination");
|
|
28
|
+
class MssqlDestination extends database_destination_1.DatabaseDestination {
|
|
29
|
+
connection;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
super(config);
|
|
32
|
+
this.connection = config.connection;
|
|
33
|
+
}
|
|
34
|
+
async loadBatch(data) {
|
|
35
|
+
const sql = this.connection.driver ?? await Promise.resolve().then(() => __importStar(require('mssql')));
|
|
36
|
+
const pool = new sql.ConnectionPool({ ...this.connection });
|
|
37
|
+
const db = await pool.connect();
|
|
38
|
+
const query = await db.request().query(`SELECT TOP(0) * FROM ${this.table}`);
|
|
39
|
+
let table = query.recordset.toTable(this.table);
|
|
40
|
+
const columns = table.columns.map((x) => x.name);
|
|
41
|
+
for (let x of data) {
|
|
42
|
+
let args = [];
|
|
43
|
+
for (let ii = 0; ii < columns.length; ii++) {
|
|
44
|
+
args.push(x[columns[ii]]);
|
|
45
|
+
}
|
|
46
|
+
table.rows.add(...args);
|
|
47
|
+
}
|
|
48
|
+
const transaction = new sql.Transaction(db);
|
|
49
|
+
try {
|
|
50
|
+
await transaction.begin();
|
|
51
|
+
await transaction.request().bulk(table);
|
|
52
|
+
await transaction.commit();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (!transaction._aborted) {
|
|
56
|
+
await transaction.rollback();
|
|
57
|
+
}
|
|
58
|
+
await pool.close();
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
await pool.close();
|
|
90
62
|
}
|
|
91
|
-
|
|
92
|
-
var _a;
|
|
93
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
-
var sql, _b, pool, db, query, table, columns, _i, data_1, x, args, ii, transaction, err_1;
|
|
95
|
-
var _c;
|
|
96
|
-
return __generator(this, function (_d) {
|
|
97
|
-
switch (_d.label) {
|
|
98
|
-
case 0:
|
|
99
|
-
if (!((_a = this.connection.driver) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
100
|
-
_b = _a;
|
|
101
|
-
return [3 /*break*/, 3];
|
|
102
|
-
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('mssql')); })];
|
|
103
|
-
case 2:
|
|
104
|
-
_b = _d.sent();
|
|
105
|
-
_d.label = 3;
|
|
106
|
-
case 3:
|
|
107
|
-
sql = _b;
|
|
108
|
-
pool = new sql.ConnectionPool(__assign({}, this.connection));
|
|
109
|
-
return [4 /*yield*/, pool.connect()];
|
|
110
|
-
case 4:
|
|
111
|
-
db = _d.sent();
|
|
112
|
-
return [4 /*yield*/, db.request().query("SELECT TOP(0) * FROM " + this.table)];
|
|
113
|
-
case 5:
|
|
114
|
-
query = _d.sent();
|
|
115
|
-
table = query.recordset.toTable(this.table);
|
|
116
|
-
columns = table.columns.map(function (x) { return x.name; });
|
|
117
|
-
for (_i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
118
|
-
x = data_1[_i];
|
|
119
|
-
args = [];
|
|
120
|
-
for (ii = 0; ii < columns.length; ii++) {
|
|
121
|
-
args.push(x[columns[ii]]);
|
|
122
|
-
}
|
|
123
|
-
(_c = table.rows).add.apply(_c, args);
|
|
124
|
-
}
|
|
125
|
-
transaction = new sql.Transaction(db);
|
|
126
|
-
_d.label = 6;
|
|
127
|
-
case 6:
|
|
128
|
-
_d.trys.push([6, 10, , 14]);
|
|
129
|
-
return [4 /*yield*/, transaction.begin()];
|
|
130
|
-
case 7:
|
|
131
|
-
_d.sent();
|
|
132
|
-
return [4 /*yield*/, transaction.request().bulk(table)];
|
|
133
|
-
case 8:
|
|
134
|
-
_d.sent();
|
|
135
|
-
return [4 /*yield*/, transaction.commit()];
|
|
136
|
-
case 9:
|
|
137
|
-
_d.sent();
|
|
138
|
-
return [3 /*break*/, 14];
|
|
139
|
-
case 10:
|
|
140
|
-
err_1 = _d.sent();
|
|
141
|
-
if (!!transaction._aborted) return [3 /*break*/, 12];
|
|
142
|
-
return [4 /*yield*/, transaction.rollback()];
|
|
143
|
-
case 11:
|
|
144
|
-
_d.sent();
|
|
145
|
-
_d.label = 12;
|
|
146
|
-
case 12: return [4 /*yield*/, pool.close()];
|
|
147
|
-
case 13:
|
|
148
|
-
_d.sent();
|
|
149
|
-
throw err_1;
|
|
150
|
-
case 14: return [4 /*yield*/, pool.close()];
|
|
151
|
-
case 15:
|
|
152
|
-
_d.sent();
|
|
153
|
-
return [2 /*return*/];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
return MssqlDestination;
|
|
159
|
-
}(database_destination_1.DatabaseDestination));
|
|
63
|
+
}
|
|
160
64
|
exports.MssqlDestination = MssqlDestination;
|
|
@@ -1,114 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
26
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
-
function step(op) {
|
|
29
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
-
while (_) try {
|
|
31
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
32
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
-
switch (op[0]) {
|
|
34
|
-
case 0: case 1: t = op; break;
|
|
35
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
-
default:
|
|
39
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
-
if (t[2]) _.ops.pop();
|
|
44
|
-
_.trys.pop(); continue;
|
|
45
|
-
}
|
|
46
|
-
op = body.call(thisArg, _);
|
|
47
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
-
};
|
|
54
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
3
|
exports.MySqlDestination = void 0;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const database_destination_1 = require("./base/database-destination");
|
|
6
|
+
const promise_1 = tslib_1.__importDefault(require("mysql2-stream-fix/promise"));
|
|
7
|
+
class MySqlDestination extends database_destination_1.DatabaseDestination {
|
|
8
|
+
connection;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.connection = config.connection;
|
|
12
|
+
}
|
|
13
|
+
async loadBatch(data) {
|
|
14
|
+
const pool = promise_1.default.createPool(this.connection);
|
|
15
|
+
const dbConnection = await pool.getConnection();
|
|
16
|
+
const [columns] = await dbConnection.query(`DESCRIBE ${this.table}`);
|
|
17
|
+
const columnNames = columns.map((col) => `\`${col.Field}\``);
|
|
18
|
+
const insertQuery = `INSERT INTO ${this.table} (${columnNames.join(', ')}) VALUES ?`;
|
|
19
|
+
await dbConnection.beginTransaction();
|
|
20
|
+
try {
|
|
21
|
+
const insertData = data.map(row => columnNames.map(column => row[column.replace(/`/g, '')])); // Remove backticks when accessing row data
|
|
22
|
+
await dbConnection.beginTransaction();
|
|
23
|
+
await dbConnection.query(insertQuery, [insertData]);
|
|
24
|
+
await dbConnection.commit();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
await dbConnection.rollback();
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await pool.end();
|
|
32
|
+
}
|
|
64
33
|
}
|
|
65
|
-
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var pool, dbConnection, columns, columnNames, insertQuery, insertData, err_1;
|
|
68
|
-
return __generator(this, function (_a) {
|
|
69
|
-
switch (_a.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
pool = promise_1.default.createPool(this.connection);
|
|
72
|
-
return [4 /*yield*/, pool.getConnection()];
|
|
73
|
-
case 1:
|
|
74
|
-
dbConnection = _a.sent();
|
|
75
|
-
return [4 /*yield*/, dbConnection.query("DESCRIBE " + this.table)];
|
|
76
|
-
case 2:
|
|
77
|
-
columns = (_a.sent())[0];
|
|
78
|
-
columnNames = columns.map(function (col) { return "`" + col.Field + "`"; });
|
|
79
|
-
insertQuery = "INSERT INTO " + this.table + " (" + columnNames.join(', ') + ") VALUES ?";
|
|
80
|
-
return [4 /*yield*/, dbConnection.beginTransaction()];
|
|
81
|
-
case 3:
|
|
82
|
-
_a.sent();
|
|
83
|
-
_a.label = 4;
|
|
84
|
-
case 4:
|
|
85
|
-
_a.trys.push([4, 8, 10, 12]);
|
|
86
|
-
insertData = data.map(function (row) { return columnNames.map(function (column) { return row[column.replace(/`/g, '')]; }); });
|
|
87
|
-
return [4 /*yield*/, dbConnection.beginTransaction()];
|
|
88
|
-
case 5:
|
|
89
|
-
_a.sent();
|
|
90
|
-
return [4 /*yield*/, dbConnection.query(insertQuery, [insertData])];
|
|
91
|
-
case 6:
|
|
92
|
-
_a.sent();
|
|
93
|
-
return [4 /*yield*/, dbConnection.commit()];
|
|
94
|
-
case 7:
|
|
95
|
-
_a.sent();
|
|
96
|
-
return [3 /*break*/, 12];
|
|
97
|
-
case 8:
|
|
98
|
-
err_1 = _a.sent();
|
|
99
|
-
return [4 /*yield*/, dbConnection.rollback()];
|
|
100
|
-
case 9:
|
|
101
|
-
_a.sent();
|
|
102
|
-
throw err_1;
|
|
103
|
-
case 10: return [4 /*yield*/, pool.end()];
|
|
104
|
-
case 11:
|
|
105
|
-
_a.sent();
|
|
106
|
-
return [7 /*endfinally*/];
|
|
107
|
-
case 12: return [2 /*return*/];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
return MySqlDestination;
|
|
113
|
-
}(database_destination_1.DatabaseDestination));
|
|
34
|
+
}
|
|
114
35
|
exports.MySqlDestination = MySqlDestination;
|