@forzalabs/remora 0.0.22 → 0.0.24
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/Constants.js +1 -1
- package/actions/run.js +10 -3
- package/engines/ParseManager.js +7 -5
- package/engines/ProducerEngine.js +2 -2
- package/engines/ai/DeveloperEngine.js +1 -1
- package/engines/consumer/PostProcessor.js +9 -3
- package/engines/execution/ExecutionEnvironment.js +1 -1
- package/engines/validation/Validator.js +10 -3
- package/package.json +1 -1
package/Constants.js
CHANGED
package/actions/run.js
CHANGED
|
@@ -26,9 +26,16 @@ const run = (consumerName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
26
26
|
console.log();
|
|
27
27
|
const spinner = (0, ora_1.default)(chalk_1.default.blue('Running consumer(s)...\n')).start();
|
|
28
28
|
const user = UserManager_1.default.getUser();
|
|
29
|
-
const consumersToExecute =
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const consumersToExecute = [];
|
|
30
|
+
if (consumerName && consumerName.length > 0) {
|
|
31
|
+
const cons = Environment_1.default.getConsumer(consumerName);
|
|
32
|
+
if (!cons)
|
|
33
|
+
throw new Error(`Consumer with name "${consumerName}" was not found.`);
|
|
34
|
+
consumersToExecute.push(cons);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
consumersToExecute.push(...Environment_1.default._env.consumers);
|
|
38
|
+
}
|
|
32
39
|
const results = [];
|
|
33
40
|
for (let i = 0; i < consumersToExecute.length; i++) {
|
|
34
41
|
const consumer = consumersToExecute[i];
|
package/engines/ParseManager.js
CHANGED
|
@@ -11,16 +11,15 @@ class ParseManagerClass {
|
|
|
11
11
|
this.csvToJson = (csv, producer) => {
|
|
12
12
|
(0, Affirm_1.default)(csv, 'Invalid csv content');
|
|
13
13
|
Affirm_1.default.hasValue(csv.length, 'Invalid csv content length');
|
|
14
|
-
|
|
15
|
-
return this.csvLinesToJson(fileRows, producer);
|
|
14
|
+
return this.csvLinesToJson(csv, producer);
|
|
16
15
|
};
|
|
17
|
-
this.csvLinesToJson = (lines, producer) => {
|
|
16
|
+
this.csvLinesToJson = (lines, producer, discover) => {
|
|
18
17
|
var _a;
|
|
19
18
|
(0, Affirm_1.default)(lines, 'Invalid csv lines');
|
|
20
19
|
Affirm_1.default.hasValue(lines.length, 'Invalid csv lines length');
|
|
21
20
|
const delimiterChar = (_a = producer.settings.delimiter) !== null && _a !== void 0 ? _a : ',';
|
|
22
21
|
const rows = lines.slice(1).map(x => x.split(delimiterChar).map(k => k.trim()));
|
|
23
|
-
const headerColumns = this._extractHeader(lines[0], delimiterChar, producer);
|
|
22
|
+
const headerColumns = this._extractHeader(lines[0], delimiterChar, producer, discover);
|
|
24
23
|
const result = [];
|
|
25
24
|
for (const row of rows) {
|
|
26
25
|
const rowObject = {};
|
|
@@ -32,7 +31,7 @@ class ParseManagerClass {
|
|
|
32
31
|
}
|
|
33
32
|
return result;
|
|
34
33
|
};
|
|
35
|
-
this._extractHeader = (headerLine, delimiter, producer) => {
|
|
34
|
+
this._extractHeader = (headerLine, delimiter, producer, discover) => {
|
|
36
35
|
var _a;
|
|
37
36
|
(0, Affirm_1.default)(headerLine, 'Invalid CSV header line');
|
|
38
37
|
(0, Affirm_1.default)(delimiter, 'Invalid CSV delimiter');
|
|
@@ -40,6 +39,9 @@ class ParseManagerClass {
|
|
|
40
39
|
const source = Environment_1.default.getSource(producer.source);
|
|
41
40
|
const columns = FileCompiler_1.default.compileProducer(producer, source);
|
|
42
41
|
const headerColumns = headerLine.split(delimiter).map(x => x.trim());
|
|
42
|
+
// If I'm discovering the file, then it means that the dimensions are not set, so I use the ones that I get from the file directly
|
|
43
|
+
if (discover)
|
|
44
|
+
columns.push(...headerColumns.map(x => ({ nameInProducer: x })));
|
|
43
45
|
const csvColumns = [];
|
|
44
46
|
for (const pColumn of columns) {
|
|
45
47
|
const columnKey = (_a = pColumn.aliasInProducer) !== null && _a !== void 0 ? _a : pColumn.nameInProducer;
|
|
@@ -111,7 +111,7 @@ class ProducerEngineClass {
|
|
|
111
111
|
throw new Error(`Invalid file type "${producer.settings.fileType}" for engine type "${source.engine}" for producer "${producer.name}": not supported`);
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
|
-
this.readSampleData = (producer_1, ...args_1) => __awaiter(this, [producer_1, ...args_1], void 0, function* (producer, sampleSize = 10) {
|
|
114
|
+
this.readSampleData = (producer_1, ...args_1) => __awaiter(this, [producer_1, ...args_1], void 0, function* (producer, sampleSize = 10, discover = false) {
|
|
115
115
|
var _a, _b, _c;
|
|
116
116
|
(0, Affirm_1.default)(producer, 'Invalid producer');
|
|
117
117
|
(0, Affirm_1.default)(sampleSize > 0, 'Sample size must be greater than 0');
|
|
@@ -132,7 +132,7 @@ class ProducerEngineClass {
|
|
|
132
132
|
case 'aws-s3': {
|
|
133
133
|
const fileData = yield this.readFile(producer, { readmode: 'lines', lines: { from: 0, to: sampleSize } });
|
|
134
134
|
if (((_a = producer.settings.fileType) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CSV') {
|
|
135
|
-
sampleData = ParseManager_1.default.csvLinesToJson(fileData.data, producer);
|
|
135
|
+
sampleData = ParseManager_1.default.csvLinesToJson(fileData.data, producer, discover);
|
|
136
136
|
}
|
|
137
137
|
else if (((_b = producer.settings.fileType) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'JSON' || ((_c = producer.settings.fileType) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === 'JSONL') {
|
|
138
138
|
// With JSON or JSONL the readFile function already parses the strings
|
|
@@ -21,7 +21,7 @@ class DeveloperEngineClass {
|
|
|
21
21
|
this.discover = (producer) => __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
var _a;
|
|
23
23
|
(0, Affirm_1.default)(producer, 'Invalid producer');
|
|
24
|
-
const sampleData = yield ProducerEngine_1.default.readSampleData(producer);
|
|
24
|
+
const sampleData = yield ProducerEngine_1.default.readSampleData(producer, 10, true);
|
|
25
25
|
(0, Affirm_1.default)(sampleData, 'Discover process failed: no result found');
|
|
26
26
|
const typeDefinitions = this.extractFieldTypes(sampleData);
|
|
27
27
|
const mappedProducer = {
|
|
@@ -145,10 +145,16 @@ class PostProcessorClass {
|
|
|
145
145
|
return unpackedData;
|
|
146
146
|
};
|
|
147
147
|
this._getFieldValue = (record, field) => {
|
|
148
|
+
var _a, _b, _c;
|
|
148
149
|
const fieldValue = record[field.cField.key];
|
|
149
|
-
if (Algo_1.default.hasVal(fieldValue))
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (Algo_1.default.hasVal(fieldValue) && !isNaN(fieldValue)) {
|
|
151
|
+
const fieldType = (_b = (_a = field.dimension) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'string';
|
|
152
|
+
if (fieldType === 'number' && typeof fieldValue === 'string' && fieldValue.length === 0)
|
|
153
|
+
return (_c = field.cField.default) !== null && _c !== void 0 ? _c : fieldValue;
|
|
154
|
+
else
|
|
155
|
+
return fieldValue;
|
|
156
|
+
}
|
|
157
|
+
else if ((!Algo_1.default.hasVal(fieldValue) || isNaN(fieldValue)) && Algo_1.default.hasVal(field.cField.default))
|
|
152
158
|
return field.cField.default;
|
|
153
159
|
else
|
|
154
160
|
return fieldValue;
|
|
@@ -83,7 +83,7 @@ class ExecutionEnvironment {
|
|
|
83
83
|
(0, Affirm_1.default)(this._fetchedData, 'Invalid data');
|
|
84
84
|
(0, Affirm_1.default)(Array.isArray(this._fetchedData), 'Invalid data type, must be an array');
|
|
85
85
|
(0, Affirm_1.default)(planStep.producer, `Invalid producer in csv-to-json step`);
|
|
86
|
-
const csv = this._fetchedData
|
|
86
|
+
const csv = this._fetchedData;
|
|
87
87
|
this._fetchedData = ParseManager_1.default.csvToJson(csv, planStep.producer);
|
|
88
88
|
break;
|
|
89
89
|
}
|
|
@@ -130,9 +130,16 @@ class ValidatorClass {
|
|
|
130
130
|
const errors = [];
|
|
131
131
|
const trxsFields = fields.filter(x => x.transform);
|
|
132
132
|
for (const field of trxsFields) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
133
|
+
const trxToValidate = [];
|
|
134
|
+
if (Array.isArray(field.transform))
|
|
135
|
+
trxToValidate.push(...field.transform);
|
|
136
|
+
else
|
|
137
|
+
trxToValidate.push(field.transform);
|
|
138
|
+
for (const trans of trxToValidate) {
|
|
139
|
+
const trxKeys = Object.keys(trans);
|
|
140
|
+
if (trxKeys.length !== 1)
|
|
141
|
+
errors.push(`There can only be 1 transformation type in your transformation pipeline. Field "${field.key}" got ${trxKeys.length}`);
|
|
142
|
+
}
|
|
136
143
|
}
|
|
137
144
|
return errors;
|
|
138
145
|
};
|