@openfn/language-common 1.10.1 → 1.10.2
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 +42 -16
- package/dist/index.js +42 -16
- package/package.json +1 -1
- package/types/util.d.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
default: () => src_default,
|
|
39
39
|
each: () => each2,
|
|
40
40
|
execute: () => execute,
|
|
41
|
-
expandReferences: () =>
|
|
41
|
+
expandReferences: () => expandReferences2,
|
|
42
42
|
field: () => field,
|
|
43
43
|
fields: () => fields,
|
|
44
44
|
fn: () => fn,
|
|
@@ -75,7 +75,7 @@ __export(Adaptor_exports, {
|
|
|
75
75
|
dateFns: () => dateFns_exports,
|
|
76
76
|
each: () => each2,
|
|
77
77
|
execute: () => execute,
|
|
78
|
-
expandReferences: () =>
|
|
78
|
+
expandReferences: () => expandReferences2,
|
|
79
79
|
field: () => field,
|
|
80
80
|
fields: () => fields,
|
|
81
81
|
fn: () => fn,
|
|
@@ -100,6 +100,25 @@ 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
102
|
|
|
103
|
+
// src/util.js
|
|
104
|
+
function expandReferences(state, ...args) {
|
|
105
|
+
return args.map((value) => expandReference(state, value));
|
|
106
|
+
}
|
|
107
|
+
function expandReference(state, value) {
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
return value.map((v) => expandReference(state, v));
|
|
110
|
+
}
|
|
111
|
+
if (typeof value == "object" && !!value) {
|
|
112
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
113
|
+
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
114
|
+
}, {});
|
|
115
|
+
}
|
|
116
|
+
if (typeof value == "function") {
|
|
117
|
+
return expandReference(state, value(state));
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
103
122
|
// src/beta.js
|
|
104
123
|
var beta_exports = {};
|
|
105
124
|
__export(beta_exports, {
|
|
@@ -165,7 +184,7 @@ function expandRequestReferences(params) {
|
|
|
165
184
|
return true;
|
|
166
185
|
};
|
|
167
186
|
return (state) => {
|
|
168
|
-
const expandedParams =
|
|
187
|
+
const expandedParams = expandReferences2(toExpand, skipFormData)(state);
|
|
169
188
|
const safelyExpandedParams = { ...toKeep, ...expandedParams };
|
|
170
189
|
return safelyExpandedParams;
|
|
171
190
|
};
|
|
@@ -333,20 +352,20 @@ function join(targetPath, sourcePath, targetKey) {
|
|
|
333
352
|
});
|
|
334
353
|
};
|
|
335
354
|
}
|
|
336
|
-
function
|
|
355
|
+
function expandReferences2(value, skipFilter) {
|
|
337
356
|
return (state) => {
|
|
338
357
|
if (skipFilter && skipFilter(value))
|
|
339
358
|
return value;
|
|
340
359
|
if (Array.isArray(value)) {
|
|
341
|
-
return value.map((v) =>
|
|
360
|
+
return value.map((v) => expandReferences2(v)(state));
|
|
342
361
|
}
|
|
343
362
|
if (typeof value == "object" && !!value) {
|
|
344
363
|
return Object.keys(value).reduce((acc, key) => {
|
|
345
|
-
return { ...acc, [key]:
|
|
364
|
+
return { ...acc, [key]: expandReferences2(value[key])(state) };
|
|
346
365
|
}, {});
|
|
347
366
|
}
|
|
348
367
|
if (typeof value == "function") {
|
|
349
|
-
return
|
|
368
|
+
return expandReferences2(value(state))(state);
|
|
350
369
|
}
|
|
351
370
|
return value;
|
|
352
371
|
};
|
|
@@ -360,7 +379,7 @@ function fields(...fields2) {
|
|
|
360
379
|
function merge(dataSource, fields2) {
|
|
361
380
|
return (state) => {
|
|
362
381
|
const initialData = source(dataSource)(state);
|
|
363
|
-
const additionalData =
|
|
382
|
+
const additionalData = expandReferences2(fields2)(state);
|
|
364
383
|
return initialData.reduce((acc, dataItem) => {
|
|
365
384
|
return [...acc, { ...dataItem, ...additionalData }];
|
|
366
385
|
}, []);
|
|
@@ -438,16 +457,23 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
438
457
|
chunkSize: Infinity,
|
|
439
458
|
skip_empty_lines: true
|
|
440
459
|
};
|
|
441
|
-
const filteredOptions = Object.fromEntries(
|
|
442
|
-
Object.entries(parsingOptions).filter(([key]) => key in defaultOptions)
|
|
443
|
-
);
|
|
444
|
-
const options2 = { ...defaultOptions, ...filteredOptions };
|
|
445
|
-
if (options2.chunkSize < 1) {
|
|
446
|
-
throw new Error("chunkSize must be at least 1");
|
|
447
|
-
}
|
|
448
460
|
return async (state) => {
|
|
461
|
+
const [resolvedCsvData, resolvedParsingOptions] = expandReferences(
|
|
462
|
+
state,
|
|
463
|
+
csvData,
|
|
464
|
+
parsingOptions
|
|
465
|
+
);
|
|
466
|
+
const filteredOptions = Object.fromEntries(
|
|
467
|
+
Object.entries(resolvedParsingOptions).filter(
|
|
468
|
+
([key]) => key in defaultOptions
|
|
469
|
+
)
|
|
470
|
+
);
|
|
471
|
+
const options2 = { ...defaultOptions, ...filteredOptions };
|
|
472
|
+
if (options2.chunkSize < 1) {
|
|
473
|
+
throw new Error("chunkSize must be at least 1");
|
|
474
|
+
}
|
|
449
475
|
let buffer = [];
|
|
450
|
-
const parser = typeof
|
|
476
|
+
const parser = typeof resolvedCsvData === "string" ? (0, import_csv_parse.parse)(resolvedCsvData, options2) : resolvedCsvData.pipe((0, import_csv_parse.parse)(options2));
|
|
451
477
|
const flushBuffer = async (currentState) => {
|
|
452
478
|
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
453
479
|
buffer = [];
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ __export(Adaptor_exports, {
|
|
|
19
19
|
dateFns: () => dateFns_exports,
|
|
20
20
|
each: () => each2,
|
|
21
21
|
execute: () => execute,
|
|
22
|
-
expandReferences: () =>
|
|
22
|
+
expandReferences: () => expandReferences2,
|
|
23
23
|
field: () => field,
|
|
24
24
|
fields: () => fields,
|
|
25
25
|
fn: () => fn,
|
|
@@ -44,6 +44,25 @@ import fromPairs from "lodash/fp/fromPairs.js";
|
|
|
44
44
|
import { JSONPath } from "jsonpath-plus";
|
|
45
45
|
import { parse as parse2 } from "csv-parse";
|
|
46
46
|
|
|
47
|
+
// src/util.js
|
|
48
|
+
function expandReferences(state, ...args) {
|
|
49
|
+
return args.map((value) => expandReference(state, value));
|
|
50
|
+
}
|
|
51
|
+
function expandReference(state, value) {
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map((v) => expandReference(state, v));
|
|
54
|
+
}
|
|
55
|
+
if (typeof value == "object" && !!value) {
|
|
56
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
57
|
+
return { ...acc, [key]: expandReference(state, value[key]) };
|
|
58
|
+
}, {});
|
|
59
|
+
}
|
|
60
|
+
if (typeof value == "function") {
|
|
61
|
+
return expandReference(state, value(state));
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
// src/beta.js
|
|
48
67
|
var beta_exports = {};
|
|
49
68
|
__export(beta_exports, {
|
|
@@ -109,7 +128,7 @@ function expandRequestReferences(params) {
|
|
|
109
128
|
return true;
|
|
110
129
|
};
|
|
111
130
|
return (state) => {
|
|
112
|
-
const expandedParams =
|
|
131
|
+
const expandedParams = expandReferences2(toExpand, skipFormData)(state);
|
|
113
132
|
const safelyExpandedParams = { ...toKeep, ...expandedParams };
|
|
114
133
|
return safelyExpandedParams;
|
|
115
134
|
};
|
|
@@ -277,20 +296,20 @@ function join(targetPath, sourcePath, targetKey) {
|
|
|
277
296
|
});
|
|
278
297
|
};
|
|
279
298
|
}
|
|
280
|
-
function
|
|
299
|
+
function expandReferences2(value, skipFilter) {
|
|
281
300
|
return (state) => {
|
|
282
301
|
if (skipFilter && skipFilter(value))
|
|
283
302
|
return value;
|
|
284
303
|
if (Array.isArray(value)) {
|
|
285
|
-
return value.map((v) =>
|
|
304
|
+
return value.map((v) => expandReferences2(v)(state));
|
|
286
305
|
}
|
|
287
306
|
if (typeof value == "object" && !!value) {
|
|
288
307
|
return Object.keys(value).reduce((acc, key) => {
|
|
289
|
-
return { ...acc, [key]:
|
|
308
|
+
return { ...acc, [key]: expandReferences2(value[key])(state) };
|
|
290
309
|
}, {});
|
|
291
310
|
}
|
|
292
311
|
if (typeof value == "function") {
|
|
293
|
-
return
|
|
312
|
+
return expandReferences2(value(state))(state);
|
|
294
313
|
}
|
|
295
314
|
return value;
|
|
296
315
|
};
|
|
@@ -304,7 +323,7 @@ function fields(...fields2) {
|
|
|
304
323
|
function merge(dataSource, fields2) {
|
|
305
324
|
return (state) => {
|
|
306
325
|
const initialData = source(dataSource)(state);
|
|
307
|
-
const additionalData =
|
|
326
|
+
const additionalData = expandReferences2(fields2)(state);
|
|
308
327
|
return initialData.reduce((acc, dataItem) => {
|
|
309
328
|
return [...acc, { ...dataItem, ...additionalData }];
|
|
310
329
|
}, []);
|
|
@@ -382,16 +401,23 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
382
401
|
chunkSize: Infinity,
|
|
383
402
|
skip_empty_lines: true
|
|
384
403
|
};
|
|
385
|
-
const filteredOptions = Object.fromEntries(
|
|
386
|
-
Object.entries(parsingOptions).filter(([key]) => key in defaultOptions)
|
|
387
|
-
);
|
|
388
|
-
const options2 = { ...defaultOptions, ...filteredOptions };
|
|
389
|
-
if (options2.chunkSize < 1) {
|
|
390
|
-
throw new Error("chunkSize must be at least 1");
|
|
391
|
-
}
|
|
392
404
|
return async (state) => {
|
|
405
|
+
const [resolvedCsvData, resolvedParsingOptions] = expandReferences(
|
|
406
|
+
state,
|
|
407
|
+
csvData,
|
|
408
|
+
parsingOptions
|
|
409
|
+
);
|
|
410
|
+
const filteredOptions = Object.fromEntries(
|
|
411
|
+
Object.entries(resolvedParsingOptions).filter(
|
|
412
|
+
([key]) => key in defaultOptions
|
|
413
|
+
)
|
|
414
|
+
);
|
|
415
|
+
const options2 = { ...defaultOptions, ...filteredOptions };
|
|
416
|
+
if (options2.chunkSize < 1) {
|
|
417
|
+
throw new Error("chunkSize must be at least 1");
|
|
418
|
+
}
|
|
393
419
|
let buffer = [];
|
|
394
|
-
const parser = typeof
|
|
420
|
+
const parser = typeof resolvedCsvData === "string" ? parse2(resolvedCsvData, options2) : resolvedCsvData.pipe(parse2(options2));
|
|
395
421
|
const flushBuffer = async (currentState) => {
|
|
396
422
|
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
397
423
|
buffer = [];
|
|
@@ -426,7 +452,7 @@ export {
|
|
|
426
452
|
src_default as default,
|
|
427
453
|
each2 as each,
|
|
428
454
|
execute,
|
|
429
|
-
expandReferences,
|
|
455
|
+
expandReferences2 as expandReferences,
|
|
430
456
|
field,
|
|
431
457
|
fields,
|
|
432
458
|
fn,
|
package/package.json
CHANGED
package/types/util.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General-purpose utility functions
|
|
3
|
+
*
|
|
4
|
+
* These are designed more for use in adaptor code than job code
|
|
5
|
+
* (but we could choose to export util from common)
|
|
6
|
+
*
|
|
7
|
+
* None of these functions are operation factories
|
|
8
|
+
*/
|
|
9
|
+
export function expandReferences(state: any, ...args: any[]): any[];
|
|
10
|
+
export function normalizeOauthConfig(configuration: any): any;
|