@openfn/language-common 1.10.2 → 1.10.3
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/index.cjs +32 -6
- package/dist/index.js +32 -6
- package/dist/util.cjs +13 -1
- package/dist/util.js +13 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -99,16 +99,29 @@ var import_curry = __toESM(require("lodash/fp/curry.js"), 1);
|
|
|
99
99
|
var import_fromPairs = __toESM(require("lodash/fp/fromPairs.js"), 1);
|
|
100
100
|
var import_jsonpath_plus = require("jsonpath-plus");
|
|
101
101
|
var import_csv_parse = require("csv-parse");
|
|
102
|
+
var import_node_stream2 = require("stream");
|
|
102
103
|
|
|
103
104
|
// src/util.js
|
|
105
|
+
var import_node_stream = require("stream");
|
|
104
106
|
function expandReferences(state, ...args) {
|
|
105
107
|
return args.map((value) => expandReference(state, value));
|
|
106
108
|
}
|
|
109
|
+
var isStream = (value) => {
|
|
110
|
+
if (value && typeof value == "object") {
|
|
111
|
+
if (value instanceof import_node_stream.Readable || value instanceof import_node_stream.Writable) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
if (value.pipeTo || value.pipe) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
107
120
|
function expandReference(state, value) {
|
|
108
121
|
if (Array.isArray(value)) {
|
|
109
122
|
return value.map((v) => expandReference(state, v));
|
|
110
123
|
}
|
|
111
|
-
if (typeof value == "object" && !!value) {
|
|
124
|
+
if (typeof value == "object" && !!value && !isStream(value)) {
|
|
112
125
|
return Object.keys(value).reduce((acc, key) => {
|
|
113
126
|
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
114
127
|
}, {});
|
|
@@ -444,6 +457,16 @@ function chunk(array, chunkSize) {
|
|
|
444
457
|
output.push(array.slice(i, i + chunkSize));
|
|
445
458
|
return output;
|
|
446
459
|
}
|
|
460
|
+
var getParser = (csvData, options2) => {
|
|
461
|
+
if (typeof csvData === "string") {
|
|
462
|
+
return (0, import_csv_parse.parse)(csvData, options2);
|
|
463
|
+
}
|
|
464
|
+
let stream = csvData;
|
|
465
|
+
if (csvData instanceof ReadableStream) {
|
|
466
|
+
stream = import_node_stream2.Readable.from(csvData);
|
|
467
|
+
}
|
|
468
|
+
return stream.pipe((0, import_csv_parse.parse)(options2));
|
|
469
|
+
};
|
|
447
470
|
function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
448
471
|
const defaultOptions = {
|
|
449
472
|
delimiter: ",",
|
|
@@ -473,22 +496,25 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
473
496
|
throw new Error("chunkSize must be at least 1");
|
|
474
497
|
}
|
|
475
498
|
let buffer = [];
|
|
476
|
-
const parser =
|
|
499
|
+
const parser = getParser(resolvedCsvData, options2);
|
|
477
500
|
const flushBuffer = async (currentState) => {
|
|
478
501
|
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
479
502
|
buffer = [];
|
|
480
503
|
return [nextState, buffer];
|
|
481
504
|
};
|
|
505
|
+
let result = state;
|
|
482
506
|
for await (const record of parser) {
|
|
483
507
|
buffer.push(record);
|
|
484
508
|
if (buffer.length === options2.chunkSize) {
|
|
485
|
-
const [nextState, nextBuffer] = await flushBuffer(
|
|
486
|
-
|
|
509
|
+
const [nextState, nextBuffer] = await flushBuffer(result);
|
|
510
|
+
result = nextState;
|
|
487
511
|
buffer = nextBuffer;
|
|
488
512
|
}
|
|
489
513
|
}
|
|
490
|
-
|
|
491
|
-
|
|
514
|
+
if (buffer.length) {
|
|
515
|
+
[result] = await flushBuffer(result);
|
|
516
|
+
}
|
|
517
|
+
return result;
|
|
492
518
|
};
|
|
493
519
|
}
|
|
494
520
|
|
package/dist/index.js
CHANGED
|
@@ -43,16 +43,29 @@ import curry from "lodash/fp/curry.js";
|
|
|
43
43
|
import fromPairs from "lodash/fp/fromPairs.js";
|
|
44
44
|
import { JSONPath } from "jsonpath-plus";
|
|
45
45
|
import { parse as parse2 } from "csv-parse";
|
|
46
|
+
import { Readable as Readable2 } from "stream";
|
|
46
47
|
|
|
47
48
|
// src/util.js
|
|
49
|
+
import { Readable, Writable } from "stream";
|
|
48
50
|
function expandReferences(state, ...args) {
|
|
49
51
|
return args.map((value) => expandReference(state, value));
|
|
50
52
|
}
|
|
53
|
+
var isStream = (value) => {
|
|
54
|
+
if (value && typeof value == "object") {
|
|
55
|
+
if (value instanceof Readable || value instanceof Writable) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (value.pipeTo || value.pipe) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
51
64
|
function expandReference(state, value) {
|
|
52
65
|
if (Array.isArray(value)) {
|
|
53
66
|
return value.map((v) => expandReference(state, v));
|
|
54
67
|
}
|
|
55
|
-
if (typeof value == "object" && !!value) {
|
|
68
|
+
if (typeof value == "object" && !!value && !isStream(value)) {
|
|
56
69
|
return Object.keys(value).reduce((acc, key) => {
|
|
57
70
|
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
58
71
|
}, {});
|
|
@@ -388,6 +401,16 @@ function chunk(array, chunkSize) {
|
|
|
388
401
|
output.push(array.slice(i, i + chunkSize));
|
|
389
402
|
return output;
|
|
390
403
|
}
|
|
404
|
+
var getParser = (csvData, options2) => {
|
|
405
|
+
if (typeof csvData === "string") {
|
|
406
|
+
return parse2(csvData, options2);
|
|
407
|
+
}
|
|
408
|
+
let stream = csvData;
|
|
409
|
+
if (csvData instanceof ReadableStream) {
|
|
410
|
+
stream = Readable2.from(csvData);
|
|
411
|
+
}
|
|
412
|
+
return stream.pipe(parse2(options2));
|
|
413
|
+
};
|
|
391
414
|
function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
392
415
|
const defaultOptions = {
|
|
393
416
|
delimiter: ",",
|
|
@@ -417,22 +440,25 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
417
440
|
throw new Error("chunkSize must be at least 1");
|
|
418
441
|
}
|
|
419
442
|
let buffer = [];
|
|
420
|
-
const parser =
|
|
443
|
+
const parser = getParser(resolvedCsvData, options2);
|
|
421
444
|
const flushBuffer = async (currentState) => {
|
|
422
445
|
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
423
446
|
buffer = [];
|
|
424
447
|
return [nextState, buffer];
|
|
425
448
|
};
|
|
449
|
+
let result = state;
|
|
426
450
|
for await (const record of parser) {
|
|
427
451
|
buffer.push(record);
|
|
428
452
|
if (buffer.length === options2.chunkSize) {
|
|
429
|
-
const [nextState, nextBuffer] = await flushBuffer(
|
|
430
|
-
|
|
453
|
+
const [nextState, nextBuffer] = await flushBuffer(result);
|
|
454
|
+
result = nextState;
|
|
431
455
|
buffer = nextBuffer;
|
|
432
456
|
}
|
|
433
457
|
}
|
|
434
|
-
|
|
435
|
-
|
|
458
|
+
if (buffer.length) {
|
|
459
|
+
[result] = await flushBuffer(result);
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
436
462
|
};
|
|
437
463
|
}
|
|
438
464
|
|
package/dist/util.cjs
CHANGED
|
@@ -23,14 +23,26 @@ __export(util_exports, {
|
|
|
23
23
|
normalizeOauthConfig: () => normalizeOauthConfig
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(util_exports);
|
|
26
|
+
var import_node_stream = require("stream");
|
|
26
27
|
function expandReferences(state, ...args) {
|
|
27
28
|
return args.map((value) => expandReference(state, value));
|
|
28
29
|
}
|
|
30
|
+
var isStream = (value) => {
|
|
31
|
+
if (value && typeof value == "object") {
|
|
32
|
+
if (value instanceof import_node_stream.Readable || value instanceof import_node_stream.Writable) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (value.pipeTo || value.pipe) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
29
41
|
function expandReference(state, value) {
|
|
30
42
|
if (Array.isArray(value)) {
|
|
31
43
|
return value.map((v) => expandReference(state, v));
|
|
32
44
|
}
|
|
33
|
-
if (typeof value == "object" && !!value) {
|
|
45
|
+
if (typeof value == "object" && !!value && !isStream(value)) {
|
|
34
46
|
return Object.keys(value).reduce((acc, key) => {
|
|
35
47
|
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
36
48
|
}, {});
|
package/dist/util.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
// src/util.js
|
|
2
|
+
import { Readable, Writable } from "stream";
|
|
2
3
|
function expandReferences(state, ...args) {
|
|
3
4
|
return args.map((value) => expandReference(state, value));
|
|
4
5
|
}
|
|
6
|
+
var isStream = (value) => {
|
|
7
|
+
if (value && typeof value == "object") {
|
|
8
|
+
if (value instanceof Readable || value instanceof Writable) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (value.pipeTo || value.pipe) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
5
17
|
function expandReference(state, value) {
|
|
6
18
|
if (Array.isArray(value)) {
|
|
7
19
|
return value.map((v) => expandReference(state, v));
|
|
8
20
|
}
|
|
9
|
-
if (typeof value == "object" && !!value) {
|
|
21
|
+
if (typeof value == "object" && !!value && !isStream(value)) {
|
|
10
22
|
return Object.keys(value).reduce((acc, key) => {
|
|
11
23
|
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
12
24
|
}, {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-common",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
4
4
|
"description": "Common Expressions for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"esno": "^0.16.3",
|
|
49
49
|
"mocha": "9.2.2",
|
|
50
50
|
"nock": "13.2.9",
|
|
51
|
-
"rimraf": "^3.0.2"
|
|
51
|
+
"rimraf": "^3.0.2",
|
|
52
|
+
"undici": "^5.22.1"
|
|
52
53
|
},
|
|
53
54
|
"main": "dist/index.cjs",
|
|
54
55
|
"scripts": {
|