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.
@@ -1,108 +1,39 @@
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.TailProcessor = void 0;
56
- var path_1 = __importDefault(require("path"));
57
- var stream_1 = require("stream");
58
- var directory_processor_1 = require("./base/directory-processor");
59
- var Tail = require('tail').Tail;
60
- var TailProcessor = /** @class */ (function (_super) {
61
- __extends(TailProcessor, _super);
62
- function TailProcessor(config) {
63
- var _this = _super.call(this, config) || this;
64
- _this.fromBeginning = !!config.fromBeginning;
65
- return _this;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const stream_1 = require("stream");
7
+ const directory_processor_1 = require("./base/directory-processor");
8
+ const Tail = require('tail').Tail;
9
+ class TailProcessor extends directory_processor_1.DirectoryProcessor {
10
+ fromBeginning;
11
+ constructor(config) {
12
+ super(config);
13
+ this.fromBeginning = !!config.fromBeginning;
66
14
  }
67
- TailProcessor.prototype.process = function (processStream) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- var readStream, tails, _loop_1, this_1, _i, _a, file;
70
- return __generator(this, function (_b) {
71
- switch (_b.label) {
72
- case 0:
73
- readStream = new stream_1.Readable({
74
- objectMode: true,
75
- read: function () { },
76
- });
77
- tails = [];
78
- _loop_1 = function (file) {
79
- var filePath = path_1.default.join(this_1.path, file);
80
- var tail = new Tail(filePath, {
81
- fromBeginning: this_1.fromBeginning,
82
- });
83
- tail.on('line', function (data) {
84
- readStream.push({ file: file, data: data });
85
- });
86
- tail.on('error', function (exception) {
87
- readStream.emit('error', exception);
88
- });
89
- tails.push(tail);
90
- };
91
- this_1 = this;
92
- for (_i = 0, _a = this.files; _i < _a.length; _i++) {
93
- file = _a[_i];
94
- _loop_1(file);
95
- }
96
- ;
97
- return [4 /*yield*/, processStream(readStream)];
98
- case 1:
99
- _b.sent();
100
- tails.forEach(function (tail) { return tail.unwatch(); });
101
- return [2 /*return*/];
102
- }
103
- });
15
+ async process(processStream) {
16
+ const readStream = new stream_1.Readable({
17
+ objectMode: true,
18
+ read() { },
104
19
  });
105
- };
106
- return TailProcessor;
107
- }(directory_processor_1.DirectoryProcessor));
20
+ const tails = [];
21
+ for (const file of this.files) {
22
+ const filePath = path_1.default.join(this.path, file);
23
+ const tail = new Tail(filePath, {
24
+ fromBeginning: this.fromBeginning,
25
+ });
26
+ tail.on('line', (data) => {
27
+ readStream.push({ file, data });
28
+ });
29
+ tail.on('error', (exception) => {
30
+ readStream.emit('error', exception);
31
+ });
32
+ tails.push(tail);
33
+ }
34
+ ;
35
+ await processStream(readStream);
36
+ tails.forEach(tail => tail.unwatch());
37
+ }
38
+ }
108
39
  exports.TailProcessor = TailProcessor;
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Reporter = void 0;
4
- var Reporter = /** @class */ (function () {
5
- function Reporter() {
6
- }
7
- Reporter.prototype.report = function (job) {
4
+ class Reporter {
5
+ constructor() { }
6
+ report(job) {
8
7
  throw new Error('Method not implemented.');
9
- };
10
- return Reporter;
11
- }());
8
+ }
9
+ }
12
10
  exports.Reporter = Reporter;
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AxiosRequestConfig } from 'axios';
3
2
  import { Readable } from 'stream';
4
3
  import { IWorksheet } from 'xlstream/lib/types';
@@ -43,7 +42,7 @@ export interface IMySqlDbConnection {
43
42
  host?: string;
44
43
  database?: string;
45
44
  }
46
- export declare type IDbConnection = IPostgresDbConnection | IMssqlDbConnection | IMySqlDbConnection;
45
+ export type IDbConnection = IPostgresDbConnection | IMssqlDbConnection | IMySqlDbConnection;
47
46
  export interface IReporter {
48
47
  report(job: IJob): Promise<void> | void;
49
48
  }
@@ -174,8 +173,8 @@ export interface IBellboyEvent {
174
173
  timestamp: number;
175
174
  jobStopped: boolean;
176
175
  }
177
- export declare type DbTypes = 'postgres' | 'mssql' | 'mysql' | 'firebird';
178
- export declare type event = (...args: any) => Promise<any>;
179
- export declare type extendedEvent = (bellboyEvent: IBellboyEvent) => Promise<any>;
180
- export declare type sheetGetter = (sheets: IWorksheet[]) => Promise<string[]>;
181
- export declare type processStream = (readStream: Readable | AsyncGenerator, ...args: any) => Promise<any>;
176
+ export type DbTypes = 'postgres' | 'mssql' | 'mysql' | 'firebird';
177
+ export type event = (...args: any) => Promise<any>;
178
+ export type extendedEvent = (bellboyEvent: IBellboyEvent) => Promise<any>;
179
+ export type sheetGetter = (sheets: IWorksheet[]) => Promise<string[]>;
180
+ export type processStream = (readStream: Readable | AsyncGenerator, ...args: any) => Promise<any>;
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AxiosRequestConfig } from 'axios';
3
2
  import { Transform } from 'stream';
4
3
  import { AuthorizationRequest, DbTypes, IDbConnection } from './types';
package/lib/utils.js CHANGED
@@ -1,240 +1,100 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
31
- };
32
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
- step((generator = generator.apply(thisArg, _arguments || [])).next());
39
- });
40
- };
41
- var __generator = (this && this.__generator) || function (thisArg, body) {
42
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
- function verb(n) { return function (v) { return step([n, v]); }; }
45
- function step(op) {
46
- if (f) throw new TypeError("Generator is already executing.");
47
- while (_) try {
48
- 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;
49
- if (y = 0, t) op = [op[0] & 2, t.value];
50
- switch (op[0]) {
51
- case 0: case 1: t = op; break;
52
- case 4: _.label++; return { value: op[1], done: false };
53
- case 5: _.label++; y = op[1]; op = [0]; continue;
54
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
- default:
56
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
- if (t[2]) _.ops.pop();
61
- _.trys.pop(); continue;
62
- }
63
- op = body.call(thisArg, _);
64
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
- }
67
- };
68
- var __asyncValues = (this && this.__asyncValues) || function (o) {
69
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
70
- var m = o[Symbol.asyncIterator], i;
71
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
72
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
73
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
74
- };
75
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
76
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
77
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
78
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
79
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
80
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
81
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
82
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
83
- function fulfill(value) { resume("next", value); }
84
- function reject(value) { resume("throw", value); }
85
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
86
- };
87
- var __importDefault = (this && this.__importDefault) || function (mod) {
88
- return (mod && mod.__esModule) ? mod : { "default": mod };
89
- };
90
2
  Object.defineProperty(exports, "__esModule", { value: true });
91
- exports.applyHttpAuthorization = exports.getDelimitedGenerator = exports.removeCircularReferencesFromChunk = exports.getValueFromJSONChunk = exports.closeDbConnection = exports.getDb = void 0;
92
- var axios_1 = __importDefault(require("axios"));
93
- var promise_1 = __importDefault(require("mysql2-stream-fix/promise"));
94
- var stream_1 = require("stream");
95
- var cachedDbConnections = new Map();
3
+ exports.getDb = getDb;
4
+ exports.closeDbConnection = closeDbConnection;
5
+ exports.getValueFromJSONChunk = getValueFromJSONChunk;
6
+ exports.removeCircularReferencesFromChunk = removeCircularReferencesFromChunk;
7
+ exports.getDelimitedGenerator = getDelimitedGenerator;
8
+ exports.applyHttpAuthorization = applyHttpAuthorization;
9
+ const tslib_1 = require("tslib");
10
+ const axios_1 = tslib_1.__importDefault(require("axios"));
11
+ const promise_1 = tslib_1.__importDefault(require("mysql2-stream-fix/promise"));
12
+ const stream_1 = require("stream");
13
+ const cachedDbConnections = new Map();
96
14
  function getCachedDbConnection(databaseConfig) {
97
- var dbKey = getDbKey(databaseConfig);
15
+ const dbKey = getDbKey(databaseConfig);
98
16
  return cachedDbConnections.get(dbKey);
99
17
  }
100
18
  function getDbKey(databaseConfig) {
101
19
  if ('driver' in databaseConfig) {
102
- var configWithoutDriver = __assign({}, databaseConfig);
20
+ const configWithoutDriver = { ...databaseConfig };
103
21
  delete configWithoutDriver.driver;
104
22
  return JSON.stringify(configWithoutDriver);
105
23
  }
106
24
  return JSON.stringify(databaseConfig);
107
25
  }
108
26
  function setCachedDbConnection(databaseConfig, db, close) {
109
- var dbKey = getDbKey(databaseConfig);
110
- cachedDbConnections.set(dbKey, { db: db, close: close });
27
+ const dbKey = getDbKey(databaseConfig);
28
+ cachedDbConnections.set(dbKey, { db, close });
111
29
  }
112
30
  function unsetCachedDbConnection(databaseConfig) {
113
- var dbKey = getDbKey(databaseConfig);
31
+ const dbKey = getDbKey(databaseConfig);
114
32
  cachedDbConnections.delete(dbKey);
115
33
  }
116
- function getDb(databaseConfig, dbType) {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var dbConnection, _a;
119
- return __generator(this, function (_b) {
120
- switch (_b.label) {
121
- case 0:
122
- dbConnection = getCachedDbConnection(databaseConfig);
123
- if (dbConnection) {
124
- return [2 /*return*/, dbConnection.db];
125
- }
126
- _a = dbType;
127
- switch (_a) {
128
- case 'mssql': return [3 /*break*/, 1];
129
- case 'firebird': return [3 /*break*/, 3];
130
- case 'mysql': return [3 /*break*/, 5];
131
- case 'postgres': return [3 /*break*/, 6];
132
- }
133
- return [3 /*break*/, 6];
134
- case 1: return [4 /*yield*/, getMssqlDb(databaseConfig)];
135
- case 2: return [2 /*return*/, _b.sent()];
136
- case 3: return [4 /*yield*/, getFirebirdDb(databaseConfig)];
137
- case 4: return [2 /*return*/, _b.sent()];
138
- case 5: return [2 /*return*/, getMySqlDb(databaseConfig)];
139
- case 6: return [2 /*return*/, getPostgresDb(databaseConfig)];
140
- }
141
- });
142
- });
34
+ async function getDb(databaseConfig, dbType) {
35
+ const dbConnection = getCachedDbConnection(databaseConfig);
36
+ if (dbConnection) {
37
+ return dbConnection.db;
38
+ }
39
+ switch (dbType) {
40
+ case 'mssql':
41
+ return await getMssqlDb(databaseConfig);
42
+ case 'firebird':
43
+ return await getFirebirdDb(databaseConfig);
44
+ case 'mysql':
45
+ return getMySqlDb(databaseConfig);
46
+ case 'postgres':
47
+ default:
48
+ return getPostgresDb(databaseConfig);
49
+ }
143
50
  }
144
- exports.getDb = getDb;
145
- function getMySqlDb(databaseConfig) {
146
- return __awaiter(this, void 0, void 0, function () {
147
- var dbConnection;
148
- return __generator(this, function (_a) {
149
- dbConnection = promise_1.default.createPool(databaseConfig);
150
- setCachedDbConnection(databaseConfig, dbConnection, dbConnection.end.bind(dbConnection));
151
- return [2 /*return*/, dbConnection];
152
- });
153
- });
51
+ async function getMySqlDb(databaseConfig) {
52
+ const dbConnection = promise_1.default.createPool(databaseConfig);
53
+ setCachedDbConnection(databaseConfig, dbConnection, dbConnection.end.bind(dbConnection));
54
+ return dbConnection;
154
55
  }
155
- function getMssqlDb(databaseConfig) {
156
- var _a;
157
- return __awaiter(this, void 0, void 0, function () {
158
- var driver, _b, pool, db;
159
- return __generator(this, function (_c) {
160
- switch (_c.label) {
161
- case 0:
162
- if (!((_a = databaseConfig.driver) !== null && _a !== void 0)) return [3 /*break*/, 1];
163
- _b = _a;
164
- return [3 /*break*/, 3];
165
- case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('mssql')); })];
166
- case 2:
167
- _b = _c.sent();
168
- _c.label = 3;
169
- case 3:
170
- driver = _b;
171
- pool = getMssqlDbPool(driver, databaseConfig);
172
- return [4 /*yield*/, pool.connect()];
173
- case 4:
174
- db = _c.sent();
175
- setCachedDbConnection(databaseConfig, db, pool.close.bind(pool));
176
- return [2 /*return*/, db];
177
- }
178
- });
179
- });
56
+ async function getMssqlDb(databaseConfig) {
57
+ const driver = databaseConfig.driver ?? await Promise.resolve().then(() => tslib_1.__importStar(require('mssql')));
58
+ const pool = getMssqlDbPool(driver, databaseConfig);
59
+ const db = await pool.connect();
60
+ setCachedDbConnection(databaseConfig, db, pool.close.bind(pool));
61
+ return db;
180
62
  }
181
63
  function getMssqlDbPool(driver, databaseConfig) {
182
- var poolConfig = __assign({}, databaseConfig);
64
+ const poolConfig = { ...databaseConfig };
183
65
  delete poolConfig.driver;
184
- return new driver.ConnectionPool(__assign({}, databaseConfig));
66
+ return new driver.ConnectionPool({ ...databaseConfig });
185
67
  }
186
68
  function getPostgresDb(databaseConfig) {
187
- var pgp = require('pg-promise')({ schema: databaseConfig.schema || 'public' });
188
- var db = pgp(databaseConfig);
69
+ const pgp = require('pg-promise')({ schema: databaseConfig.schema || 'public' });
70
+ const db = pgp(databaseConfig);
189
71
  setCachedDbConnection(databaseConfig, db, pgp.end);
190
72
  return db;
191
73
  }
192
- function getFirebirdDb(databaseConfig) {
193
- return __awaiter(this, void 0, void 0, function () {
194
- var Firebird, db;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0:
198
- Firebird = databaseConfig.useClavizNodeFirebird ? require('claviz-node-firebird') : require('node-firebird');
199
- return [4 /*yield*/, new Promise(function (resolve, reject) {
200
- Firebird.attach(databaseConfig, function (err, db) {
201
- if (err)
202
- reject(err);
203
- else
204
- resolve(db);
205
- });
206
- })];
207
- case 1:
208
- db = _a.sent();
209
- setCachedDbConnection(databaseConfig, db, db.detach.bind(db));
210
- return [2 /*return*/, db];
211
- }
74
+ async function getFirebirdDb(databaseConfig) {
75
+ const Firebird = databaseConfig.useClavizNodeFirebird ? require('claviz-node-firebird') : require('node-firebird');
76
+ const db = await new Promise((resolve, reject) => {
77
+ Firebird.attach(databaseConfig, (err, db) => {
78
+ if (err)
79
+ reject(err);
80
+ else
81
+ resolve(db);
212
82
  });
213
83
  });
84
+ setCachedDbConnection(databaseConfig, db, db.detach.bind(db));
85
+ return db;
214
86
  }
215
- function closeDbConnection(databaseConfig) {
216
- return __awaiter(this, void 0, void 0, function () {
217
- var dbConnection;
218
- return __generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0:
221
- dbConnection = getCachedDbConnection(databaseConfig);
222
- if (!dbConnection) return [3 /*break*/, 2];
223
- return [4 /*yield*/, dbConnection.close()];
224
- case 1:
225
- _a.sent();
226
- unsetCachedDbConnection(databaseConfig);
227
- _a.label = 2;
228
- case 2: return [2 /*return*/];
229
- }
230
- });
231
- });
87
+ async function closeDbConnection(databaseConfig) {
88
+ const dbConnection = getCachedDbConnection(databaseConfig);
89
+ if (dbConnection) {
90
+ await dbConnection.close();
91
+ unsetCachedDbConnection(databaseConfig);
92
+ }
232
93
  }
233
- exports.closeDbConnection = closeDbConnection;
234
94
  function getValueFromJSONChunk() {
235
95
  return new stream_1.Transform({
236
96
  objectMode: true,
237
- transform: function (chunk, encoding, callback) {
97
+ transform(chunk, encoding, callback) {
238
98
  if (chunk.value) {
239
99
  this.push(chunk.value);
240
100
  }
@@ -242,14 +102,13 @@ function getValueFromJSONChunk() {
242
102
  }
243
103
  });
244
104
  }
245
- exports.getValueFromJSONChunk = getValueFromJSONChunk;
246
105
  function removeCircularReferencesFromChunk() {
247
106
  return new stream_1.Transform({
248
107
  objectMode: true,
249
- transform: function (chunk, encoding, callback) {
108
+ transform(chunk, encoding, callback) {
250
109
  function getCircularReplacer() {
251
- var seen = new WeakSet();
252
- return function (key, value) {
110
+ const seen = new WeakSet();
111
+ return (key, value) => {
253
112
  if (typeof value === "object" && value !== null) {
254
113
  if (seen.has(value)) {
255
114
  return;
@@ -264,88 +123,39 @@ function removeCircularReferencesFromChunk() {
264
123
  }
265
124
  });
266
125
  }
267
- exports.removeCircularReferencesFromChunk = removeCircularReferencesFromChunk;
268
- function getDelimitedGenerator(_a) {
269
- var readStream = _a.readStream, hasHeader = _a.hasHeader;
270
- var header = [];
271
- var processRow = function (_a) {
272
- var raw = _a.raw, record = _a.record;
126
+ function getDelimitedGenerator({ readStream, hasHeader, }) {
127
+ let header = [];
128
+ const processRow = ({ raw, record }) => {
273
129
  if (hasHeader && !header.length) {
274
- header = record.map(function (x) { return x.trim(); });
130
+ header = record.map((x) => x.trim());
275
131
  }
276
132
  else {
277
- var obj = void 0;
133
+ let obj;
278
134
  if (header.length) {
279
- obj = Object.fromEntries(header.map(function (x, i) { return [x, record[i]]; }));
135
+ obj = Object.fromEntries(header.map((x, i) => [x, record[i]]));
280
136
  }
281
- return { header: header, arr: record, obj: obj, row: raw };
137
+ return { header, arr: record, obj, row: raw };
282
138
  }
283
139
  };
284
- var generator = function () {
285
- return __asyncGenerator(this, arguments, function () {
286
- var readStream_1, readStream_1_1, row, result, e_1_1;
287
- var e_1, _a;
288
- return __generator(this, function (_b) {
289
- switch (_b.label) {
290
- case 0:
291
- _b.trys.push([0, 7, 8, 13]);
292
- readStream_1 = __asyncValues(readStream);
293
- _b.label = 1;
294
- case 1: return [4 /*yield*/, __await(readStream_1.next())];
295
- case 2:
296
- if (!(readStream_1_1 = _b.sent(), !readStream_1_1.done)) return [3 /*break*/, 6];
297
- row = readStream_1_1.value;
298
- result = processRow(row);
299
- if (!result) return [3 /*break*/, 5];
300
- return [4 /*yield*/, __await(result)];
301
- case 3: return [4 /*yield*/, _b.sent()];
302
- case 4:
303
- _b.sent();
304
- _b.label = 5;
305
- case 5: return [3 /*break*/, 1];
306
- case 6: return [3 /*break*/, 13];
307
- case 7:
308
- e_1_1 = _b.sent();
309
- e_1 = { error: e_1_1 };
310
- return [3 /*break*/, 13];
311
- case 8:
312
- _b.trys.push([8, , 11, 12]);
313
- if (!(readStream_1_1 && !readStream_1_1.done && (_a = readStream_1.return))) return [3 /*break*/, 10];
314
- return [4 /*yield*/, __await(_a.call(readStream_1))];
315
- case 9:
316
- _b.sent();
317
- _b.label = 10;
318
- case 10: return [3 /*break*/, 12];
319
- case 11:
320
- if (e_1) throw e_1.error;
321
- return [7 /*endfinally*/];
322
- case 12: return [7 /*endfinally*/];
323
- case 13: return [2 /*return*/];
324
- }
325
- });
326
- });
140
+ const generator = async function* () {
141
+ for await (const row of readStream) {
142
+ const result = processRow(row);
143
+ if (result) {
144
+ yield result;
145
+ }
146
+ }
327
147
  };
328
148
  return generator;
329
149
  }
330
- exports.getDelimitedGenerator = getDelimitedGenerator;
331
- function applyHttpAuthorization(connection, authorizationRequest) {
332
- return __awaiter(this, void 0, void 0, function () {
333
- var authorizationResponse, authorizationToken, applyTo;
334
- var _a;
335
- return __generator(this, function (_b) {
336
- switch (_b.label) {
337
- case 0:
338
- if (!authorizationRequest) return [3 /*break*/, 2];
339
- return [4 /*yield*/, axios_1.default(authorizationRequest.connection)];
340
- case 1:
341
- authorizationResponse = _b.sent();
342
- authorizationToken = authorizationResponse.data[authorizationRequest.sourceField];
343
- applyTo = authorizationRequest.applyTo === 'header' ? 'headers' : 'params';
344
- connection[applyTo] = __assign(__assign({}, connection[applyTo]), (_a = {}, _a[authorizationRequest.destinationField] = authorizationRequest.prefix ? "" + authorizationRequest.prefix + authorizationToken : authorizationToken, _a));
345
- _b.label = 2;
346
- case 2: return [2 /*return*/];
347
- }
348
- });
349
- });
150
+ async function applyHttpAuthorization(connection, authorizationRequest) {
151
+ if (authorizationRequest) {
152
+ const authorizationResponse = await (0, axios_1.default)(authorizationRequest.connection);
153
+ let sourceField = authorizationRequest.sourceField.split('.');
154
+ const authorizationToken = sourceField.reduce((acc, key) => acc[key], authorizationResponse.data);
155
+ const applyTo = authorizationRequest.applyTo === 'header' ? 'headers' : 'params';
156
+ connection[applyTo] = {
157
+ ...connection[applyTo],
158
+ [authorizationRequest.destinationField]: authorizationRequest.prefix ? `${authorizationRequest.prefix}${authorizationToken}` : authorizationToken,
159
+ };
160
+ }
350
161
  }
351
- exports.applyHttpAuthorization = applyHttpAuthorization;