@openfn/language-common 1.10.0 → 1.10.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/ast.json +141 -0
- package/dist/index.cjs +18 -28
- package/dist/index.js +18 -28
- package/package.json +1 -1
- package/types/Adaptor.d.ts +29 -17
package/ast.json
CHANGED
|
@@ -1065,6 +1065,73 @@
|
|
|
1065
1065
|
},
|
|
1066
1066
|
"valid": true
|
|
1067
1067
|
},
|
|
1068
|
+
{
|
|
1069
|
+
"name": "splitKeys",
|
|
1070
|
+
"params": [
|
|
1071
|
+
"obj",
|
|
1072
|
+
"keys"
|
|
1073
|
+
],
|
|
1074
|
+
"docs": {
|
|
1075
|
+
"description": "Splits an object into two objects based on a list of keys.\nThe first object contains the keys that are not in the list,\nand the second contains the keys that are.",
|
|
1076
|
+
"tags": [
|
|
1077
|
+
{
|
|
1078
|
+
"title": "public",
|
|
1079
|
+
"description": null,
|
|
1080
|
+
"type": null
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
"title": "function",
|
|
1084
|
+
"description": null,
|
|
1085
|
+
"name": null
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
"title": "param",
|
|
1089
|
+
"description": "The object to split.",
|
|
1090
|
+
"type": {
|
|
1091
|
+
"type": "NameExpression",
|
|
1092
|
+
"name": "Object"
|
|
1093
|
+
},
|
|
1094
|
+
"name": "obj"
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
"title": "param",
|
|
1098
|
+
"description": "List of keys to split on.",
|
|
1099
|
+
"type": {
|
|
1100
|
+
"type": "TypeApplication",
|
|
1101
|
+
"expression": {
|
|
1102
|
+
"type": "NameExpression",
|
|
1103
|
+
"name": "Array"
|
|
1104
|
+
},
|
|
1105
|
+
"applications": [
|
|
1106
|
+
{
|
|
1107
|
+
"type": "NameExpression",
|
|
1108
|
+
"name": "string"
|
|
1109
|
+
}
|
|
1110
|
+
]
|
|
1111
|
+
},
|
|
1112
|
+
"name": "keys"
|
|
1113
|
+
},
|
|
1114
|
+
{
|
|
1115
|
+
"title": "returns",
|
|
1116
|
+
"description": "Tuple of objects, first object contains keys not in list, second contains keys that are.",
|
|
1117
|
+
"type": {
|
|
1118
|
+
"type": "TypeApplication",
|
|
1119
|
+
"expression": {
|
|
1120
|
+
"type": "NameExpression",
|
|
1121
|
+
"name": "Array"
|
|
1122
|
+
},
|
|
1123
|
+
"applications": [
|
|
1124
|
+
{
|
|
1125
|
+
"type": "NameExpression",
|
|
1126
|
+
"name": "Object"
|
|
1127
|
+
}
|
|
1128
|
+
]
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
]
|
|
1132
|
+
},
|
|
1133
|
+
"valid": true
|
|
1134
|
+
},
|
|
1068
1135
|
{
|
|
1069
1136
|
"name": "scrubEmojis",
|
|
1070
1137
|
"params": [
|
|
@@ -1171,6 +1238,80 @@
|
|
|
1171
1238
|
},
|
|
1172
1239
|
"valid": true
|
|
1173
1240
|
},
|
|
1241
|
+
{
|
|
1242
|
+
"name": "parseCsv",
|
|
1243
|
+
"params": [
|
|
1244
|
+
"csvData",
|
|
1245
|
+
"parsingOptions",
|
|
1246
|
+
"callback"
|
|
1247
|
+
],
|
|
1248
|
+
"docs": {
|
|
1249
|
+
"description": "Takes a CSV file string or stream and parsing options as input, and returns a promise that\nresolves to the parsed CSV data as an array of objects.\nOptions for `parsingOptions` include:\n- `delimiter` {string/Buffer/[string/Buffer]} - Defines the character(s) used to delineate the fields inside a record. Default: `','`\n- `quote` {string/Buffer/[string/Buffer]} - Defines the characters used to surround a field. Default: `'\"'`\n- `escape` {Buffer/string/null/boolean} - Set the escape character as one character/byte only. Default: `\"`\n- `columns` {boolean / array / function} - Generates record in the form of object literals. Default: `true`\n- `bom` {boolean} - Strips the {@link https://en.wikipedia.org/wiki/Byte_order_mark byte order mark (BOM)} from the input string or buffer. Default: `true`\n- `trim` {boolean} - Ignore whitespace characters immediately around the `delimiter`. Default: `true`\n- `ltrim` {boolean} - Ignore whitespace characters from the left side of a CSV field. Default: `true`\n- `rtrim` {boolean} - Ignore whitespace characters from the right side of a CSV field. Default: `true`\n- `chunkSize` {number} - The size of each chunk of CSV data. Default: `Infinity`\n- `skip_empty_lines` {boolean} - Ignore empty lines in the CSV file. Default: `true`",
|
|
1250
|
+
"tags": [
|
|
1251
|
+
{
|
|
1252
|
+
"title": "public",
|
|
1253
|
+
"description": null,
|
|
1254
|
+
"type": null
|
|
1255
|
+
},
|
|
1256
|
+
{
|
|
1257
|
+
"title": "function",
|
|
1258
|
+
"description": null,
|
|
1259
|
+
"name": null
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
"title": "param",
|
|
1263
|
+
"description": "A CSV string or a readable stream",
|
|
1264
|
+
"type": {
|
|
1265
|
+
"type": "UnionType",
|
|
1266
|
+
"elements": [
|
|
1267
|
+
{
|
|
1268
|
+
"type": "NameExpression",
|
|
1269
|
+
"name": "String"
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
"type": "NameExpression",
|
|
1273
|
+
"name": "Stream"
|
|
1274
|
+
}
|
|
1275
|
+
]
|
|
1276
|
+
},
|
|
1277
|
+
"name": "csvData"
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
"title": "param",
|
|
1281
|
+
"description": "Optional. Parsing options for converting CSV to JSON.",
|
|
1282
|
+
"type": {
|
|
1283
|
+
"type": "OptionalType",
|
|
1284
|
+
"expression": {
|
|
1285
|
+
"type": "NameExpression",
|
|
1286
|
+
"name": "Object"
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
"name": "parsingOptions"
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
"title": "param",
|
|
1293
|
+
"description": "(Optional) callback function. If used it will be called state and an array of rows.",
|
|
1294
|
+
"type": {
|
|
1295
|
+
"type": "OptionalType",
|
|
1296
|
+
"expression": {
|
|
1297
|
+
"type": "NameExpression",
|
|
1298
|
+
"name": "function"
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
"name": "callback"
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
"title": "returns",
|
|
1305
|
+
"description": "The function returns a Promise that resolves to the result of parsing a CSV `stringOrStream`.",
|
|
1306
|
+
"type": {
|
|
1307
|
+
"type": "NameExpression",
|
|
1308
|
+
"name": "Operation"
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
]
|
|
1312
|
+
},
|
|
1313
|
+
"valid": true
|
|
1314
|
+
},
|
|
1174
1315
|
{
|
|
1175
1316
|
"name": "map",
|
|
1176
1317
|
"params": [
|
package/dist/index.cjs
CHANGED
|
@@ -445,34 +445,24 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
445
445
|
if (options2.chunkSize < 1) {
|
|
446
446
|
throw new Error("chunkSize must be at least 1");
|
|
447
447
|
}
|
|
448
|
-
return (state) => {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
parser.on("error", function(error) {
|
|
469
|
-
reject(error);
|
|
470
|
-
});
|
|
471
|
-
parser.on("end", function() {
|
|
472
|
-
const [finalState] = flushBuffer(state);
|
|
473
|
-
resolve(finalState);
|
|
474
|
-
});
|
|
475
|
-
});
|
|
448
|
+
return async (state) => {
|
|
449
|
+
let buffer = [];
|
|
450
|
+
const parser = typeof csvData === "string" ? (0, import_csv_parse.parse)(csvData, options2) : csvData.pipe((0, import_csv_parse.parse)(options2));
|
|
451
|
+
const flushBuffer = async (currentState) => {
|
|
452
|
+
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
453
|
+
buffer = [];
|
|
454
|
+
return [nextState, buffer];
|
|
455
|
+
};
|
|
456
|
+
for await (const record of parser) {
|
|
457
|
+
buffer.push(record);
|
|
458
|
+
if (buffer.length === options2.chunkSize) {
|
|
459
|
+
const [nextState, nextBuffer] = await flushBuffer(state);
|
|
460
|
+
state = nextState;
|
|
461
|
+
buffer = nextBuffer;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const [finalState] = await flushBuffer(state);
|
|
465
|
+
return finalState;
|
|
476
466
|
};
|
|
477
467
|
}
|
|
478
468
|
|
package/dist/index.js
CHANGED
|
@@ -389,34 +389,24 @@ function parseCsv(csvData, parsingOptions = {}, callback) {
|
|
|
389
389
|
if (options2.chunkSize < 1) {
|
|
390
390
|
throw new Error("chunkSize must be at least 1");
|
|
391
391
|
}
|
|
392
|
-
return (state) => {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
parser.on("error", function(error) {
|
|
413
|
-
reject(error);
|
|
414
|
-
});
|
|
415
|
-
parser.on("end", function() {
|
|
416
|
-
const [finalState] = flushBuffer(state);
|
|
417
|
-
resolve(finalState);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
392
|
+
return async (state) => {
|
|
393
|
+
let buffer = [];
|
|
394
|
+
const parser = typeof csvData === "string" ? parse2(csvData, options2) : csvData.pipe(parse2(options2));
|
|
395
|
+
const flushBuffer = async (currentState) => {
|
|
396
|
+
const nextState = callback ? await callback(currentState, buffer) : composeNextState(currentState, buffer);
|
|
397
|
+
buffer = [];
|
|
398
|
+
return [nextState, buffer];
|
|
399
|
+
};
|
|
400
|
+
for await (const record of parser) {
|
|
401
|
+
buffer.push(record);
|
|
402
|
+
if (buffer.length === options2.chunkSize) {
|
|
403
|
+
const [nextState, nextBuffer] = await flushBuffer(state);
|
|
404
|
+
state = nextState;
|
|
405
|
+
buffer = nextBuffer;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const [finalState] = await flushBuffer(state);
|
|
409
|
+
return finalState;
|
|
420
410
|
};
|
|
421
411
|
}
|
|
422
412
|
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -276,7 +276,17 @@ export function composeNextState(state: State, response: any): State;
|
|
|
276
276
|
* @returns {string}
|
|
277
277
|
*/
|
|
278
278
|
export function humanProper(str: string): string;
|
|
279
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Splits an object into two objects based on a list of keys.
|
|
281
|
+
* The first object contains the keys that are not in the list,
|
|
282
|
+
* and the second contains the keys that are.
|
|
283
|
+
* @public
|
|
284
|
+
* @function
|
|
285
|
+
* @param {Object} obj - The object to split.
|
|
286
|
+
* @param {string[]} keys - List of keys to split on.
|
|
287
|
+
* @returns {Object[]} - Tuple of objects, first object contains keys not in list, second contains keys that are.
|
|
288
|
+
*/
|
|
289
|
+
export function splitKeys(obj: any, keys: string[]): any[];
|
|
280
290
|
/**
|
|
281
291
|
* Replaces emojis in a string.
|
|
282
292
|
* @public
|
|
@@ -300,25 +310,27 @@ export function scrubEmojis(text: string, replacementChars: string): string;
|
|
|
300
310
|
*/
|
|
301
311
|
export function chunk(array: any, chunkSize: Integer): any;
|
|
302
312
|
/**
|
|
303
|
-
*
|
|
304
|
-
* resolves to the parsed CSV data.
|
|
313
|
+
* Takes a CSV file string or stream and parsing options as input, and returns a promise that
|
|
314
|
+
* resolves to the parsed CSV data as an array of objects.
|
|
315
|
+
* Options for `parsingOptions` include:
|
|
316
|
+
* - `delimiter` {string/Buffer/[string/Buffer]} - Defines the character(s) used to delineate the fields inside a record. Default: `','`
|
|
317
|
+
* - `quote` {string/Buffer/[string/Buffer]} - Defines the characters used to surround a field. Default: `'"'`
|
|
318
|
+
* - `escape` {Buffer/string/null/boolean} - Set the escape character as one character/byte only. Default: `"`
|
|
319
|
+
* - `columns` {boolean / array / function} - Generates record in the form of object literals. Default: `true`
|
|
320
|
+
* - `bom` {boolean} - Strips the {@link https://en.wikipedia.org/wiki/Byte_order_mark byte order mark (BOM)} from the input string or buffer. Default: `true`
|
|
321
|
+
* - `trim` {boolean} - Ignore whitespace characters immediately around the `delimiter`. Default: `true`
|
|
322
|
+
* - `ltrim` {boolean} - Ignore whitespace characters from the left side of a CSV field. Default: `true`
|
|
323
|
+
* - `rtrim` {boolean} - Ignore whitespace characters from the right side of a CSV field. Default: `true`
|
|
324
|
+
* - `chunkSize` {number} - The size of each chunk of CSV data. Default: `Infinity`
|
|
325
|
+
* - `skip_empty_lines` {boolean} - Ignore empty lines in the CSV file. Default: `true`
|
|
326
|
+
* @public
|
|
327
|
+
* @function
|
|
305
328
|
* @param {String | Stream} csvData - A CSV string or a readable stream
|
|
306
329
|
* @param {Object} [parsingOptions] - Optional. Parsing options for converting CSV to JSON.
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* - `quote` {string|Buffer|[string|Buffer]} - Defines the characters used to surround a field. Default: `'"'`
|
|
310
|
-
* - `escape` {Buffer|string|null|boolean} - Set the escape character as one character/byte only. Default: `"`
|
|
311
|
-
* - `columns` {boolean | array | function} - Generates record in the form of object literals. Default: `true`
|
|
312
|
-
* - `bom` {boolean} - Strips the {@link https://en.wikipedia.org/wiki/Byte_order_mark byte order mark (BOM)} from the input string or buffer. Default: `true`
|
|
313
|
-
* - `trim` {boolean} - Ignore whitespace characters immediately around the `delimiter`. Default: `true`
|
|
314
|
-
* - `ltrim` {boolean} - Ignore whitespace characters from the left side of a CSV field. Default: `true`
|
|
315
|
-
* - `rtrim` {boolean} - Ignore whitespace characters from the right side of a CSV field. Default: `true`
|
|
316
|
-
* - `chunkSize` {number} - The size of each chunk of CSV data. Default: `Infinity`
|
|
317
|
-
* - `skip_empty_lines` {boolean} - The `skip_empty_lines` skips any line which is empty. Default: `true`
|
|
318
|
-
* @param {function} callback - (Optional) callback function. If used it will take state and csvRows
|
|
319
|
-
* @returns {Promise} The function returns a Promise that resolves to the result of parsing a CSV `stringOrStream`.
|
|
330
|
+
* @param {function} [callback] - (Optional) callback function. If used it will be called state and an array of rows.
|
|
331
|
+
* @returns {Operation} The function returns a Promise that resolves to the result of parsing a CSV `stringOrStream`.
|
|
320
332
|
*/
|
|
321
|
-
export function parseCsv(csvData: string | Stream, parsingOptions?: any, callback
|
|
333
|
+
export function parseCsv(csvData: string | Stream, parsingOptions?: any, callback?: Function): Operation;
|
|
322
334
|
export * as beta from "./beta";
|
|
323
335
|
export * as http from "./http";
|
|
324
336
|
export * as dateFns from "./dateFns";
|