@openfn/language-http 4.3.2 → 5.0.0

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 CHANGED
@@ -367,59 +367,6 @@
367
367
  ]
368
368
  },
369
369
  "valid": true
370
- },
371
- {
372
- "name": "parseCSV",
373
- "params": [
374
- "target",
375
- "config"
376
- ],
377
- "docs": {
378
- "description": "CSV-Parse for CSV conversion to JSON",
379
- "tags": [
380
- {
381
- "title": "public",
382
- "description": null,
383
- "type": null
384
- },
385
- {
386
- "title": "example",
387
- "description": "parseCSV(\"/home/user/someData.csv\", {\n\t quoteChar: '\"',\n\t header: false,\n\t});"
388
- },
389
- {
390
- "title": "function",
391
- "description": null,
392
- "name": null
393
- },
394
- {
395
- "title": "param",
396
- "description": "string or local file with CSV data",
397
- "type": {
398
- "type": "NameExpression",
399
- "name": "String"
400
- },
401
- "name": "target"
402
- },
403
- {
404
- "title": "param",
405
- "description": "csv-parse config object",
406
- "type": {
407
- "type": "NameExpression",
408
- "name": "Object"
409
- },
410
- "name": "config"
411
- },
412
- {
413
- "title": "returns",
414
- "description": null,
415
- "type": {
416
- "type": "NameExpression",
417
- "name": "Operation"
418
- }
419
- }
420
- ]
421
- },
422
- "valid": true
423
370
  }
424
371
  ],
425
372
  "exports": [],
@@ -1023,6 +970,73 @@
1023
970
  },
1024
971
  "valid": true
1025
972
  },
973
+ {
974
+ "name": "splitKeys",
975
+ "params": [
976
+ "obj",
977
+ "keys"
978
+ ],
979
+ "docs": {
980
+ "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.",
981
+ "tags": [
982
+ {
983
+ "title": "public",
984
+ "description": null,
985
+ "type": null
986
+ },
987
+ {
988
+ "title": "function",
989
+ "description": null,
990
+ "name": null
991
+ },
992
+ {
993
+ "title": "param",
994
+ "description": "The object to split.",
995
+ "type": {
996
+ "type": "NameExpression",
997
+ "name": "Object"
998
+ },
999
+ "name": "obj"
1000
+ },
1001
+ {
1002
+ "title": "param",
1003
+ "description": "List of keys to split on.",
1004
+ "type": {
1005
+ "type": "TypeApplication",
1006
+ "expression": {
1007
+ "type": "NameExpression",
1008
+ "name": "Array"
1009
+ },
1010
+ "applications": [
1011
+ {
1012
+ "type": "NameExpression",
1013
+ "name": "string"
1014
+ }
1015
+ ]
1016
+ },
1017
+ "name": "keys"
1018
+ },
1019
+ {
1020
+ "title": "returns",
1021
+ "description": "Tuple of objects, first object contains keys not in list, second contains keys that are.",
1022
+ "type": {
1023
+ "type": "TypeApplication",
1024
+ "expression": {
1025
+ "type": "NameExpression",
1026
+ "name": "Array"
1027
+ },
1028
+ "applications": [
1029
+ {
1030
+ "type": "NameExpression",
1031
+ "name": "Object"
1032
+ }
1033
+ ]
1034
+ }
1035
+ }
1036
+ ]
1037
+ },
1038
+ "valid": true
1039
+ },
1026
1040
  {
1027
1041
  "name": "scrubEmojis",
1028
1042
  "params": [
@@ -1075,6 +1089,80 @@
1075
1089
  ]
1076
1090
  },
1077
1091
  "valid": true
1092
+ },
1093
+ {
1094
+ "name": "parseCsv",
1095
+ "params": [
1096
+ "csvData",
1097
+ "parsingOptions",
1098
+ "callback"
1099
+ ],
1100
+ "docs": {
1101
+ "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`",
1102
+ "tags": [
1103
+ {
1104
+ "title": "public",
1105
+ "description": null,
1106
+ "type": null
1107
+ },
1108
+ {
1109
+ "title": "function",
1110
+ "description": null,
1111
+ "name": null
1112
+ },
1113
+ {
1114
+ "title": "param",
1115
+ "description": "A CSV string or a readable stream",
1116
+ "type": {
1117
+ "type": "UnionType",
1118
+ "elements": [
1119
+ {
1120
+ "type": "NameExpression",
1121
+ "name": "String"
1122
+ },
1123
+ {
1124
+ "type": "NameExpression",
1125
+ "name": "Stream"
1126
+ }
1127
+ ]
1128
+ },
1129
+ "name": "csvData"
1130
+ },
1131
+ {
1132
+ "title": "param",
1133
+ "description": "Optional. Parsing options for converting CSV to JSON.",
1134
+ "type": {
1135
+ "type": "OptionalType",
1136
+ "expression": {
1137
+ "type": "NameExpression",
1138
+ "name": "Object"
1139
+ }
1140
+ },
1141
+ "name": "parsingOptions"
1142
+ },
1143
+ {
1144
+ "title": "param",
1145
+ "description": "(Optional) callback function. If used it will be called state and an array of rows.",
1146
+ "type": {
1147
+ "type": "OptionalType",
1148
+ "expression": {
1149
+ "type": "NameExpression",
1150
+ "name": "function"
1151
+ }
1152
+ },
1153
+ "name": "callback"
1154
+ },
1155
+ {
1156
+ "title": "returns",
1157
+ "description": "The function returns a Promise that resolves to the result of parsing a CSV `stringOrStream`.",
1158
+ "type": {
1159
+ "type": "NameExpression",
1160
+ "name": "Operation"
1161
+ }
1162
+ }
1163
+ ]
1164
+ },
1165
+ "valid": true
1078
1166
  }
1079
1167
  ]
1080
1168
  }
package/dist/index.cjs CHANGED
@@ -44,7 +44,7 @@ __export(src_exports, {
44
44
  humanProper: () => import_language_common2.humanProper,
45
45
  lastReferenceValue: () => import_language_common2.lastReferenceValue,
46
46
  merge: () => import_language_common2.merge,
47
- parseCSV: () => parseCSV,
47
+ parseCsv: () => import_language_common2.parseCsv,
48
48
  parseXML: () => parseXML,
49
49
  patch: () => patch,
50
50
  post: () => post,
@@ -78,7 +78,7 @@ __export(Adaptor_exports, {
78
78
  humanProper: () => import_language_common2.humanProper,
79
79
  lastReferenceValue: () => import_language_common2.lastReferenceValue,
80
80
  merge: () => import_language_common2.merge,
81
- parseCSV: () => parseCSV,
81
+ parseCsv: () => import_language_common2.parseCsv,
82
82
  parseXML: () => parseXML,
83
83
  patch: () => patch,
84
84
  post: () => post,
@@ -199,8 +199,6 @@ var import_language_common = require("@openfn/language-common");
199
199
  var import_request = __toESM(require("request"), 1);
200
200
  var import_cheerio = __toESM(require("cheerio"), 1);
201
201
  var import_cheerio_tableparser = __toESM(require("cheerio-tableparser"), 1);
202
- var import_fs = __toESM(require("fs"), 1);
203
- var import_csv_parse = __toESM(require("csv-parse"), 1);
204
202
  var import_tough_cookie = __toESM(require("tough-cookie"), 1);
205
203
  var import_language_common2 = require("@openfn/language-common");
206
204
  var { axios } = import_language_common.http;
@@ -357,34 +355,6 @@ function parseXML(body, script) {
357
355
  }
358
356
  };
359
357
  }
360
- function parseCSV(target, config) {
361
- return (state) => {
362
- return new Promise((resolve, reject) => {
363
- var csvData = [];
364
- try {
365
- import_fs.default.readFileSync(target);
366
- import_fs.default.createReadStream(target).pipe((0, import_csv_parse.default)(config)).on("data", (csvrow) => {
367
- console.log(csvrow);
368
- csvData.push(csvrow);
369
- }).on("end", () => {
370
- console.log(csvData);
371
- resolve((0, import_language_common.composeNextState)(state, csvData));
372
- });
373
- } catch (err) {
374
- var csvString;
375
- if (typeof target === "string") {
376
- csvString = target;
377
- } else {
378
- csvString = (0, import_language_common.expandReferences)(target)(state);
379
- }
380
- csvData = (0, import_csv_parse.default)(csvString, config, (err2, output) => {
381
- console.log(output);
382
- resolve((0, import_language_common.composeNextState)(state, output));
383
- });
384
- }
385
- });
386
- };
387
- }
388
358
  function request(params) {
389
359
  return (state) => {
390
360
  const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
@@ -424,7 +394,7 @@ var src_default = Adaptor_exports;
424
394
  humanProper,
425
395
  lastReferenceValue,
426
396
  merge,
427
- parseCSV,
397
+ parseCsv,
428
398
  parseXML,
429
399
  patch,
430
400
  post,
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ __export(Adaptor_exports, {
25
25
  humanProper: () => humanProper,
26
26
  lastReferenceValue: () => lastReferenceValue,
27
27
  merge: () => merge,
28
- parseCSV: () => parseCSV,
28
+ parseCsv: () => parseCsv,
29
29
  parseXML: () => parseXML,
30
30
  patch: () => patch,
31
31
  post: () => post,
@@ -151,8 +151,6 @@ import {
151
151
  import nodeRequest from "request";
152
152
  import cheerio from "cheerio";
153
153
  import cheerioTableparser from "cheerio-tableparser";
154
- import fs from "fs";
155
- import parse from "csv-parse";
156
154
  import tough from "tough-cookie";
157
155
  import {
158
156
  alterState,
@@ -172,7 +170,8 @@ import {
172
170
  scrubEmojis,
173
171
  sourceValue,
174
172
  splitKeys,
175
- toArray
173
+ toArray,
174
+ parseCsv
176
175
  } from "@openfn/language-common";
177
176
  var { axios } = http;
178
177
  function execute(...operations) {
@@ -328,34 +327,6 @@ function parseXML(body, script) {
328
327
  }
329
328
  };
330
329
  }
331
- function parseCSV(target, config) {
332
- return (state) => {
333
- return new Promise((resolve, reject) => {
334
- var csvData = [];
335
- try {
336
- fs.readFileSync(target);
337
- fs.createReadStream(target).pipe(parse(config)).on("data", (csvrow) => {
338
- console.log(csvrow);
339
- csvData.push(csvrow);
340
- }).on("end", () => {
341
- console.log(csvData);
342
- resolve(composeNextState(state, csvData));
343
- });
344
- } catch (err) {
345
- var csvString;
346
- if (typeof target === "string") {
347
- csvString = target;
348
- } else {
349
- csvString = expandReferences(target)(state);
350
- }
351
- csvData = parse(csvString, config, (err2, output) => {
352
- console.log(output);
353
- resolve(composeNextState(state, output));
354
- });
355
- }
356
- });
357
- };
358
- }
359
330
  function request(params) {
360
331
  return (state) => {
361
332
  const resolvedParams = http.expandRequestReferences(params)(state);
@@ -395,7 +366,7 @@ export {
395
366
  humanProper,
396
367
  lastReferenceValue,
397
368
  merge,
398
- parseCSV,
369
+ parseCsv,
399
370
  parseXML,
400
371
  patch,
401
372
  post,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-http",
3
- "version": "4.3.2",
3
+ "version": "5.0.0",
4
4
  "description": "An HTTP request language package for use with Open Function",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "configuration-schema.json"
26
26
  ],
27
27
  "dependencies": {
28
- "@openfn/language-common": "1.9.0",
28
+ "@openfn/language-common": "1.10.1",
29
29
  "cheerio": "^1.0.0-rc.10",
30
30
  "cheerio-tableparser": "^1.0.1",
31
31
  "csv-parse": "^4.10.1",
@@ -102,20 +102,6 @@ export function del(path: string, params: object, callback: Function): Operation
102
102
  * @returns {Operation}
103
103
  */
104
104
  export function parseXML(body: string, script: Function): Operation;
105
- /**
106
- * CSV-Parse for CSV conversion to JSON
107
- * @public
108
- * @example
109
- * parseCSV("/home/user/someData.csv", {
110
- * quoteChar: '"',
111
- * header: false,
112
- * });
113
- * @function
114
- * @param {String} target - string or local file with CSV data
115
- * @param {Object} config - csv-parse config object
116
- * @returns {Operation}
117
- */
118
- export function parseCSV(target: string, config: any): Operation;
119
105
  /**
120
106
  * Make a request using the 'request' node module. This module is deprecated.
121
107
  * @example
@@ -126,4 +112,4 @@ export function parseCSV(target: string, config: any): Operation;
126
112
  */
127
113
  export function request(params: object): Operation;
128
114
  export const axios: import("../../common/node_modules/axios").AxiosStatic;
129
- export { alterState, arrayToString, combine, dataPath, dataValue, dateFns, each, field, fields, fn, http, humanProper, lastReferenceValue, merge, scrubEmojis, sourceValue, splitKeys, toArray } from "@openfn/language-common";
115
+ export { alterState, arrayToString, combine, dataPath, dataValue, dateFns, each, field, fields, fn, http, humanProper, lastReferenceValue, merge, scrubEmojis, sourceValue, splitKeys, toArray, parseCsv } from "@openfn/language-common";