@openfn/language-common 1.14.0 → 1.15.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 CHANGED
@@ -56,15 +56,15 @@
56
56
  "description": null,
57
57
  "type": null
58
58
  },
59
- {
60
- "title": "example",
61
- "description": "fn(state => {\n // do some things to state\n return state;\n});"
62
- },
63
59
  {
64
60
  "title": "function",
65
61
  "description": null,
66
62
  "name": null
67
63
  },
64
+ {
65
+ "title": "example",
66
+ "description": "fn(state => {\n // do some things to state\n return state;\n});"
67
+ },
68
68
  {
69
69
  "title": "param",
70
70
  "description": "is the function",
@@ -100,15 +100,15 @@
100
100
  "description": null,
101
101
  "type": null
102
102
  },
103
- {
104
- "title": "example",
105
- "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
106
- },
107
103
  {
108
104
  "title": "function",
109
105
  "description": null,
110
106
  "name": null
111
107
  },
108
+ {
109
+ "title": "example",
110
+ "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
111
+ },
112
112
  {
113
113
  "title": "param",
114
114
  "description": "The condition that returns true",
@@ -153,15 +153,15 @@
153
153
  "description": null,
154
154
  "type": null
155
155
  },
156
- {
157
- "title": "example",
158
- "description": "jsonValue({ a:1 }, 'a')"
159
- },
160
156
  {
161
157
  "title": "function",
162
158
  "description": null,
163
159
  "name": null
164
160
  },
161
+ {
162
+ "title": "example",
163
+ "description": "jsonValue({ a:1 }, 'a')"
164
+ },
165
165
  {
166
166
  "title": "param",
167
167
  "description": "A valid JSON object.",
@@ -205,15 +205,15 @@
205
205
  "description": null,
206
206
  "type": null
207
207
  },
208
- {
209
- "title": "example",
210
- "description": "sourceValue('$.key')"
211
- },
212
208
  {
213
209
  "title": "function",
214
210
  "description": null,
215
211
  "name": null
216
212
  },
213
+ {
214
+ "title": "example",
215
+ "description": "sourceValue('$.key')"
216
+ },
217
217
  {
218
218
  "title": "param",
219
219
  "description": "JSONPath referencing a point in `state`.",
@@ -248,15 +248,15 @@
248
248
  "description": null,
249
249
  "type": null
250
250
  },
251
- {
252
- "title": "example",
253
- "description": "source('$.key')"
254
- },
255
251
  {
256
252
  "title": "function",
257
253
  "description": null,
258
254
  "name": null
259
255
  },
256
+ {
257
+ "title": "example",
258
+ "description": "source('$.key')"
259
+ },
260
260
  {
261
261
  "title": "param",
262
262
  "description": "JSONPath referencing a point in `state`.",
@@ -309,15 +309,15 @@
309
309
  "description": null,
310
310
  "type": null
311
311
  },
312
- {
313
- "title": "example",
314
- "description": "dataPath('key')"
315
- },
316
312
  {
317
313
  "title": "function",
318
314
  "description": null,
319
315
  "name": null
320
316
  },
317
+ {
318
+ "title": "example",
319
+ "description": "dataPath('key')"
320
+ },
321
321
  {
322
322
  "title": "param",
323
323
  "description": "JSONPath referencing a point in `data`.",
@@ -352,15 +352,15 @@
352
352
  "description": null,
353
353
  "type": null
354
354
  },
355
- {
356
- "title": "example",
357
- "description": "dataValue('key')"
358
- },
359
355
  {
360
356
  "title": "function",
361
357
  "description": null,
362
358
  "name": null
363
359
  },
360
+ {
361
+ "title": "example",
362
+ "description": "dataValue('key')"
363
+ },
364
364
  {
365
365
  "title": "param",
366
366
  "description": "JSONPath referencing a point in `data`.",
@@ -395,15 +395,15 @@
395
395
  "description": null,
396
396
  "type": null
397
397
  },
398
- {
399
- "title": "example",
400
- "description": "referencePath('key')"
401
- },
402
398
  {
403
399
  "title": "function",
404
400
  "description": null,
405
401
  "name": null
406
402
  },
403
+ {
404
+ "title": "example",
405
+ "description": "referencePath('key')"
406
+ },
407
407
  {
408
408
  "title": "param",
409
409
  "description": "JSONPath referencing a point in `references`.",
@@ -438,15 +438,15 @@
438
438
  "description": null,
439
439
  "type": null
440
440
  },
441
- {
442
- "title": "example",
443
- "description": "lastReferenceValue('key')"
444
- },
445
441
  {
446
442
  "title": "function",
447
443
  "description": null,
448
444
  "name": null
449
445
  },
446
+ {
447
+ "title": "example",
448
+ "description": "lastReferenceValue('key')"
449
+ },
450
450
  {
451
451
  "title": "param",
452
452
  "description": "JSONPath referencing a point in `references`.",
@@ -482,15 +482,15 @@
482
482
  "description": null,
483
483
  "type": null
484
484
  },
485
- {
486
- "title": "example",
487
- "description": "asData('$.key'| key | callback)"
488
- },
489
485
  {
490
486
  "title": "function",
491
487
  "description": null,
492
488
  "name": null
493
489
  },
490
+ {
491
+ "title": "example",
492
+ "description": "asData('$.key'| key | callback)"
493
+ },
494
494
  {
495
495
  "title": "param",
496
496
  "description": null,
@@ -548,15 +548,15 @@
548
548
  "description": null,
549
549
  "type": null
550
550
  },
551
- {
552
- "title": "example",
553
- "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
554
- },
555
551
  {
556
552
  "title": "function",
557
553
  "description": null,
558
554
  "name": null
559
555
  },
556
+ {
557
+ "title": "example",
558
+ "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
559
+ },
560
560
  {
561
561
  "title": "param",
562
562
  "description": "JSONPath referencing a point in `state`.",
@@ -600,15 +600,15 @@
600
600
  "description": null,
601
601
  "type": null
602
602
  },
603
- {
604
- "title": "example",
605
- "description": "combine(\n create('foo'),\n delete('bar')\n)"
606
- },
607
603
  {
608
604
  "title": "function",
609
605
  "description": null,
610
606
  "name": null
611
607
  },
608
+ {
609
+ "title": "example",
610
+ "description": "combine(\n create('foo'),\n delete('bar')\n)"
611
+ },
612
612
  {
613
613
  "title": "param",
614
614
  "description": "Operations to be performed.",
@@ -645,15 +645,15 @@
645
645
  "description": null,
646
646
  "type": null
647
647
  },
648
- {
649
- "title": "example",
650
- "description": "join('$.key','$.data','newKey')"
651
- },
652
648
  {
653
649
  "title": "function",
654
650
  "description": null,
655
651
  "name": null
656
652
  },
653
+ {
654
+ "title": "example",
655
+ "description": "join('$.key','$.data','newKey')"
656
+ },
657
657
  {
658
658
  "title": "param",
659
659
  "description": "Target path",
@@ -759,15 +759,15 @@
759
759
  "description": null,
760
760
  "type": null
761
761
  },
762
- {
763
- "title": "example",
764
- "description": "field('destination_field_name__c', 'value')"
765
- },
766
762
  {
767
763
  "title": "function",
768
764
  "description": null,
769
765
  "name": null
770
766
  },
767
+ {
768
+ "title": "example",
769
+ "description": "field('destination_field_name__c', 'value')"
770
+ },
771
771
  {
772
772
  "title": "param",
773
773
  "description": "Name of the field",
@@ -811,15 +811,15 @@
811
811
  "description": null,
812
812
  "type": null
813
813
  },
814
- {
815
- "title": "example",
816
- "description": "fields(list_of_fields)"
817
- },
818
814
  {
819
815
  "title": "function",
820
816
  "description": null,
821
817
  "name": null
822
818
  },
819
+ {
820
+ "title": "example",
821
+ "description": "fields(list_of_fields)"
822
+ },
823
823
  {
824
824
  "title": "param",
825
825
  "description": "a list of fields",
@@ -864,6 +864,11 @@
864
864
  "description": null,
865
865
  "name": null
866
866
  },
867
+ {
868
+ "title": "public",
869
+ "description": null,
870
+ "type": null
871
+ },
867
872
  {
868
873
  "title": "param",
869
874
  "description": null,
@@ -895,10 +900,14 @@
895
900
  "valid": true
896
901
  },
897
902
  {
898
- "name": "index",
899
- "params": [],
903
+ "name": "group",
904
+ "params": [
905
+ "arrayOfObjects",
906
+ "keyPath",
907
+ "callback"
908
+ ],
900
909
  "docs": {
901
- "description": "Returns the index of the current array being iterated.\nTo be used with `each` as a data source.",
910
+ "description": "Groups an array of objects by a specified key path.",
902
911
  "tags": [
903
912
  {
904
913
  "title": "public",
@@ -907,13 +916,86 @@
907
916
  },
908
917
  {
909
918
  "title": "example",
910
- "description": "index()"
919
+ "description": "const users = [\n { name: 'Alice', age: 25, city: 'New York' },\n { name: 'Bob', age: 30, city: 'San Francisco' },\n { name: 'Charlie', age: 25, city: 'New York' },\n { name: 'David', age: 30, city: 'San Francisco' }\n];\ngroup(users, 'city');\n// state is { data: { 'New York': [/Alice, Charlie/], 'San Francisco': [ /Bob, David / ] }"
920
+ },
921
+ {
922
+ "title": "function",
923
+ "description": null,
924
+ "name": null
925
+ },
926
+ {
927
+ "title": "public",
928
+ "description": null,
929
+ "type": null
930
+ },
931
+ {
932
+ "title": "param",
933
+ "description": "The array of objects to be grouped.",
934
+ "type": {
935
+ "type": "TypeApplication",
936
+ "expression": {
937
+ "type": "NameExpression",
938
+ "name": "Array"
939
+ },
940
+ "applications": [
941
+ {
942
+ "type": "NameExpression",
943
+ "name": "Object"
944
+ }
945
+ ]
946
+ },
947
+ "name": "arrayOfObjects"
948
+ },
949
+ {
950
+ "title": "param",
951
+ "description": "The key path to group by.",
952
+ "type": {
953
+ "type": "NameExpression",
954
+ "name": "string"
955
+ },
956
+ "name": "keyPath"
957
+ },
958
+ {
959
+ "title": "param",
960
+ "description": "(Optional) Callback function",
961
+ "type": {
962
+ "type": "NameExpression",
963
+ "name": "function"
964
+ },
965
+ "name": "callback"
966
+ },
967
+ {
968
+ "title": "returns",
969
+ "description": null,
970
+ "type": {
971
+ "type": "NameExpression",
972
+ "name": "Operation"
973
+ }
974
+ }
975
+ ]
976
+ },
977
+ "valid": true
978
+ },
979
+ {
980
+ "name": "index",
981
+ "params": [],
982
+ "docs": {
983
+ "description": "Returns the index of the current array being iterated.\nTo be used with `each` as a data source.",
984
+ "tags": [
985
+ {
986
+ "title": "public",
987
+ "description": null,
988
+ "type": null
911
989
  },
912
990
  {
913
991
  "title": "function",
914
992
  "description": null,
915
993
  "name": null
916
994
  },
995
+ {
996
+ "title": "example",
997
+ "description": "index()"
998
+ },
917
999
  {
918
1000
  "title": "returns",
919
1001
  "description": null,
@@ -940,15 +1022,15 @@
940
1022
  "description": null,
941
1023
  "type": null
942
1024
  },
943
- {
944
- "title": "example",
945
- "description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
946
- },
947
1025
  {
948
1026
  "title": "function",
949
1027
  "description": null,
950
1028
  "name": null
951
1029
  },
1030
+ {
1031
+ "title": "example",
1032
+ "description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
1033
+ },
952
1034
  {
953
1035
  "title": "param",
954
1036
  "description": "Array of toString'able primatives.",
@@ -992,15 +1074,15 @@
992
1074
  "description": null,
993
1075
  "type": null
994
1076
  },
995
- {
996
- "title": "example",
997
- "description": "each(function(state) {\n return toArray( dataValue(\"path_of_array\")(state) )\n}, ...)"
998
- },
999
1077
  {
1000
1078
  "title": "function",
1001
1079
  "description": null,
1002
1080
  "name": null
1003
1081
  },
1082
+ {
1083
+ "title": "example",
1084
+ "description": "each(function(state) {\n return toArray( dataValue(\"path_of_array\")(state) )\n}, ...)"
1085
+ },
1004
1086
  {
1005
1087
  "title": "param",
1006
1088
  "description": "Data required to be in an array",
@@ -1036,15 +1118,15 @@
1036
1118
  "description": null,
1037
1119
  "type": null
1038
1120
  },
1039
- {
1040
- "title": "example",
1041
- "description": "composeNextState(state, response)"
1042
- },
1043
1121
  {
1044
1122
  "title": "function",
1045
1123
  "description": null,
1046
1124
  "name": null
1047
1125
  },
1126
+ {
1127
+ "title": "example",
1128
+ "description": "composeNextState(state, response)"
1129
+ },
1048
1130
  {
1049
1131
  "title": "param",
1050
1132
  "description": "state",
@@ -1088,15 +1170,15 @@
1088
1170
  "description": null,
1089
1171
  "type": null
1090
1172
  },
1091
- {
1092
- "title": "example",
1093
- "description": "field(\"destination_string__c\", humanProper(state.data.path_to_string))"
1094
- },
1095
1173
  {
1096
1174
  "title": "function",
1097
1175
  "description": null,
1098
1176
  "name": null
1099
1177
  },
1178
+ {
1179
+ "title": "example",
1180
+ "description": "field(\"destination_string__c\", humanProper(state.data.path_to_string))"
1181
+ },
1100
1182
  {
1101
1183
  "title": "param",
1102
1184
  "description": "String that needs converting",
@@ -1199,15 +1281,15 @@
1199
1281
  "description": null,
1200
1282
  "type": null
1201
1283
  },
1202
- {
1203
- "title": "example",
1204
- "description": "scrubEmojis('Dove🕊️⭐ 29')"
1205
- },
1206
1284
  {
1207
1285
  "title": "function",
1208
1286
  "description": null,
1209
1287
  "name": null
1210
1288
  },
1289
+ {
1290
+ "title": "example",
1291
+ "description": "scrubEmojis('Dove🕊️⭐ 29')"
1292
+ },
1211
1293
  {
1212
1294
  "title": "param",
1213
1295
  "description": "String that needs to be cleaned",
@@ -1252,15 +1334,15 @@
1252
1334
  "description": null,
1253
1335
  "type": null
1254
1336
  },
1255
- {
1256
- "title": "example",
1257
- "description": "chunk([1,2,3,4,5], 2)"
1258
- },
1259
1337
  {
1260
1338
  "title": "function",
1261
1339
  "description": null,
1262
1340
  "name": null
1263
1341
  },
1342
+ {
1343
+ "title": "example",
1344
+ "description": "chunk([1,2,3,4,5], 2)"
1345
+ },
1264
1346
  {
1265
1347
  "title": "param",
1266
1348
  "description": "Array to be chunked",
@@ -1379,6 +1461,11 @@
1379
1461
  "description": null,
1380
1462
  "type": null
1381
1463
  },
1464
+ {
1465
+ "title": "function",
1466
+ "description": null,
1467
+ "name": null
1468
+ },
1382
1469
  {
1383
1470
  "title": "example",
1384
1471
  "description": "cursor($.cursor, { defaultValue: 'today' })",
@@ -1389,11 +1476,6 @@
1389
1476
  "description": "cursor(22)",
1390
1477
  "caption": "Use a pagination cursor"
1391
1478
  },
1392
- {
1393
- "title": "function",
1394
- "description": null,
1395
- "name": null
1396
- },
1397
1479
  {
1398
1480
  "title": "param",
1399
1481
  "description": "the cursor value. Usually an ISO date, natural language date, or page number",
@@ -1466,15 +1548,15 @@
1466
1548
  "description": null,
1467
1549
  "type": null
1468
1550
  },
1469
- {
1470
- "title": "example",
1471
- "description": "map(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
1472
- },
1473
1551
  {
1474
1552
  "title": "function",
1475
1553
  "description": null,
1476
1554
  "name": null
1477
1555
  },
1556
+ {
1557
+ "title": "example",
1558
+ "description": "map(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
1559
+ },
1478
1560
  {
1479
1561
  "title": "param",
1480
1562
  "description": "JSONPath referencing a point in `state.data`.",
package/dist/index.cjs CHANGED
@@ -44,6 +44,7 @@ __export(src_exports, {
44
44
  fields: () => fields,
45
45
  fn: () => fn,
46
46
  fnIf: () => fnIf,
47
+ group: () => group,
47
48
  http: () => http_deprecated_exports,
48
49
  humanProper: () => humanProper,
49
50
  index: () => index,
@@ -84,6 +85,7 @@ __export(Adaptor_exports, {
84
85
  fields: () => fields,
85
86
  fn: () => fn,
86
87
  fnIf: () => fnIf,
88
+ group: () => group,
87
89
  http: () => http_deprecated_exports,
88
90
  humanProper: () => humanProper,
89
91
  index: () => index,
@@ -101,7 +103,10 @@ __export(Adaptor_exports, {
101
103
  toArray: () => toArray,
102
104
  validate: () => validate
103
105
  });
106
+ var import_get = __toESM(require("lodash/get.js"), 1);
107
+ var import_omit = __toESM(require("lodash/omit.js"), 1);
104
108
  var import_curry = __toESM(require("lodash/fp/curry.js"), 1);
109
+ var import_groupBy = __toESM(require("lodash/groupBy.js"), 1);
105
110
  var import_fromPairs = __toESM(require("lodash/fp/fromPairs.js"), 1);
106
111
  var import_jsonpath_plus = require("jsonpath-plus");
107
112
  var import_csv_parse = require("csv-parse");
@@ -462,6 +467,17 @@ function merge(dataSource, fields2) {
462
467
  }, []);
463
468
  };
464
469
  }
470
+ function group(arrayOfObjects, keyPath, callback = (s) => s) {
471
+ return (state) => {
472
+ const [resolvedArray, resolvedKeyPath] = expandReferences(
473
+ state,
474
+ arrayOfObjects,
475
+ keyPath
476
+ );
477
+ const results = (0, import_groupBy.default)(resolvedArray, (item) => (0, import_get.default)(item, resolvedKeyPath));
478
+ return callback({ ...state, data: (0, import_omit.default)(results, [void 0]) });
479
+ };
480
+ }
465
481
  function index() {
466
482
  return (state) => {
467
483
  return state.index;
@@ -474,6 +490,9 @@ function toArray(arg) {
474
490
  return new Array().concat(arg);
475
491
  }
476
492
  function composeNextState(state, response) {
493
+ if (!state.references) {
494
+ state.references = [];
495
+ }
477
496
  return {
478
497
  ...state,
479
498
  data: response,
@@ -708,6 +727,7 @@ var src_default = Adaptor_exports;
708
727
  fields,
709
728
  fn,
710
729
  fnIf,
730
+ group,
711
731
  http,
712
732
  humanProper,
713
733
  index,
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(Adaptor_exports, {
25
25
  fields: () => fields,
26
26
  fn: () => fn,
27
27
  fnIf: () => fnIf,
28
+ group: () => group,
28
29
  http: () => http_deprecated_exports,
29
30
  humanProper: () => humanProper,
30
31
  index: () => index,
@@ -42,7 +43,10 @@ __export(Adaptor_exports, {
42
43
  toArray: () => toArray,
43
44
  validate: () => validate
44
45
  });
46
+ import get2 from "lodash/get.js";
47
+ import omit from "lodash/omit.js";
45
48
  import curry from "lodash/fp/curry.js";
49
+ import groupBy from "lodash/groupBy.js";
46
50
  import fromPairs from "lodash/fp/fromPairs.js";
47
51
  import { JSONPath } from "jsonpath-plus";
48
52
  import { parse as parse2 } from "csv-parse";
@@ -254,7 +258,10 @@ __export(dateFns_exports, {
254
258
  format: () => format,
255
259
  parse: () => parse
256
260
  });
257
- import { parse, format } from "date-fns";
261
+ import {
262
+ parse,
263
+ format
264
+ } from "date-fns";
258
265
 
259
266
  // src/Adaptor.js
260
267
  var schemaCache = {};
@@ -401,6 +408,17 @@ function merge(dataSource, fields2) {
401
408
  }, []);
402
409
  };
403
410
  }
411
+ function group(arrayOfObjects, keyPath, callback = (s) => s) {
412
+ return (state) => {
413
+ const [resolvedArray, resolvedKeyPath] = expandReferences(
414
+ state,
415
+ arrayOfObjects,
416
+ keyPath
417
+ );
418
+ const results = groupBy(resolvedArray, (item) => get2(item, resolvedKeyPath));
419
+ return callback({ ...state, data: omit(results, [void 0]) });
420
+ };
421
+ }
404
422
  function index() {
405
423
  return (state) => {
406
424
  return state.index;
@@ -413,6 +431,9 @@ function toArray(arg) {
413
431
  return new Array().concat(arg);
414
432
  }
415
433
  function composeNextState(state, response) {
434
+ if (!state.references) {
435
+ state.references = [];
436
+ }
416
437
  return {
417
438
  ...state,
418
439
  data: response,
@@ -647,6 +668,7 @@ export {
647
668
  fields,
648
669
  fn,
649
670
  fnIf,
671
+ group,
650
672
  http_deprecated_exports as http,
651
673
  humanProper,
652
674
  index,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "1.14.0",
3
+ "version": "1.15.1",
4
4
  "description": "Common Expressions for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -22,12 +22,12 @@ export function alterState(func: Function): Operation;
22
22
  /**
23
23
  * Creates a custom step (or operation) for more flexible job writing.
24
24
  * @public
25
+ * @function
25
26
  * @example
26
27
  * fn(state => {
27
28
  * // do some things to state
28
29
  * return state;
29
30
  * });
30
- * @function
31
31
  * @param {Function} func is the function
32
32
  * @returns {Operation}
33
33
  */
@@ -35,9 +35,9 @@ export function fn(func: Function): Operation;
35
35
  /**
36
36
  * A custom operation that will only execute the function if the condition returns true
37
37
  * @public
38
+ * @function
38
39
  * @example
39
40
  * fnIf((state) => state?.data?.name, get("https://example.com"));
40
- * @function
41
41
  * @param {Boolean} condition - The condition that returns true
42
42
  * @param {Operation} operation - The operation needed to be executed.
43
43
  * @returns {Operation}
@@ -48,9 +48,9 @@ export function fnIf(condition: boolean, operation: Operation): Operation;
48
48
  * If a JSONPath returns more than one value for the reference, the first
49
49
  * item will be returned.
50
50
  * @public
51
+ * @function
51
52
  * @example
52
53
  * jsonValue({ a:1 }, 'a')
53
- * @function
54
54
  * @param {object} obj - A valid JSON object.
55
55
  * @param {String} path - JSONPath referencing a point in given JSON object.
56
56
  * @returns {Operation}
@@ -61,9 +61,9 @@ export function jsonValue(obj: object, path: string): Operation;
61
61
  * If a JSONPath returns more than one value for the reference, the first
62
62
  * item will be returned.
63
63
  * @public
64
+ * @function
64
65
  * @example
65
66
  * sourceValue('$.key')
66
- * @function
67
67
  * @param {String} path - JSONPath referencing a point in `state`.
68
68
  * @returns {Operation}
69
69
  */
@@ -73,9 +73,9 @@ export function sourceValue(path: string): Operation;
73
73
  * Will return whatever JSONPath returns, which will always be an array.
74
74
  * If you need a single value use `sourceValue` instead.
75
75
  * @public
76
+ * @function
76
77
  * @example
77
78
  * source('$.key')
78
- * @function
79
79
  * @param {String} path - JSONPath referencing a point in `state`.
80
80
  * @returns {Array.<String|Object>}
81
81
  */
@@ -83,9 +83,9 @@ export function source(path: string): Array<string | any>;
83
83
  /**
84
84
  * Ensures a path points at the data.
85
85
  * @public
86
+ * @function
86
87
  * @example
87
88
  * dataPath('key')
88
- * @function
89
89
  * @param {string} path - JSONPath referencing a point in `data`.
90
90
  * @returns {string}
91
91
  */
@@ -95,9 +95,9 @@ export function dataPath(path: string): string;
95
95
  * If a JSONPath returns more than one value for the reference, the first
96
96
  * item will be returned.
97
97
  * @public
98
+ * @function
98
99
  * @example
99
100
  * dataValue('key')
100
- * @function
101
101
  * @param {String} path - JSONPath referencing a point in `data`.
102
102
  * @returns {Operation}
103
103
  */
@@ -105,9 +105,9 @@ export function dataValue(path: string): Operation;
105
105
  /**
106
106
  * Ensures a path points at references.
107
107
  * @public
108
+ * @function
108
109
  * @example
109
110
  * referencePath('key')
110
- * @function
111
111
  * @param {string} path - JSONPath referencing a point in `references`.
112
112
  * @returns {string}
113
113
  */
@@ -115,9 +115,9 @@ export function referencePath(path: string): string;
115
115
  /**
116
116
  * Picks out the last reference value from source data.
117
117
  * @public
118
+ * @function
118
119
  * @example
119
120
  * lastReferenceValue('key')
120
- * @function
121
121
  * @param {String} path - JSONPath referencing a point in `references`.
122
122
  * @returns {Operation}
123
123
  */
@@ -129,9 +129,9 @@ export function lastReferenceValue(path: string): Operation;
129
129
  * - Object Literal of the data itself.
130
130
  * - Function to be called with state.
131
131
  * @public
132
+ * @function
132
133
  * @example
133
134
  * asData('$.key'| key | callback)
134
- * @function
135
135
  * @param {String|object|function} data
136
136
  * @param {object} state - The current state.
137
137
  * @returns {array}
@@ -147,13 +147,13 @@ export function asData(data: string | object | Function, state: object): any[];
147
147
  * It also ensures the results of an operation make their way back into
148
148
  * the state's references.
149
149
  * @public
150
+ * @function
150
151
  * @example
151
152
  * each("$.[*]",
152
153
  * create("SObject",
153
154
  * field("FirstName", sourceValue("$.firstName"))
154
155
  * )
155
156
  * )
156
- * @function
157
157
  * @param {DataSource} dataSource - JSONPath referencing a point in `state`.
158
158
  * @param {Operation} operation - The operation needed to be repeated.
159
159
  * @returns {Operation}
@@ -162,12 +162,12 @@ export function each(dataSource: DataSource, operation: Operation): Operation;
162
162
  /**
163
163
  * Combines two operations into one
164
164
  * @public
165
+ * @function
165
166
  * @example
166
167
  * combine(
167
168
  * create('foo'),
168
169
  * delete('bar')
169
170
  * )
170
- * @function
171
171
  * @param {Operations} operations - Operations to be performed.
172
172
  * @returns {Operation}
173
173
  */
@@ -175,9 +175,9 @@ export function combine(...operations: Operations): Operation;
175
175
  /**
176
176
  * Adds data from a target object
177
177
  * @public
178
+ * @function
178
179
  * @example
179
180
  * join('$.key','$.data','newKey')
180
- * @function
181
181
  * @param {String} targetPath - Target path
182
182
  * @param {String} sourcePath - Source path
183
183
  * @param {String} targetKey - Target Key
@@ -196,9 +196,9 @@ export function expandReferences(value: object, skipFilter?: Function): Operatio
196
196
  /**
197
197
  * Returns a key, value pair in an array.
198
198
  * @public
199
+ * @function
199
200
  * @example
200
201
  * field('destination_field_name__c', 'value')
201
- * @function
202
202
  * @param {string} key - Name of the field
203
203
  * @param {Value} value - The value itself or a sourceable operation.
204
204
  * @returns {Field}
@@ -207,9 +207,9 @@ export function field(key: string, value: Value): Field;
207
207
  /**
208
208
  * Zips key value pairs into an object.
209
209
  * @public
210
+ * @function
210
211
  * @example
211
212
  * fields(list_of_fields)
212
- * @function
213
213
  * @param {Fields} fields - a list of fields
214
214
  * @returns {Object}
215
215
  */
@@ -225,29 +225,50 @@ export function fields(...fields: Fields): any;
225
225
  * )
226
226
  * )
227
227
  * @function
228
+ * @public
228
229
  * @param {DataSource} dataSource
229
230
  * @param {Object} fields - Group of fields to merge in.
230
231
  * @returns {DataSource}
231
232
  */
232
233
  export function merge(dataSource: DataSource, fields: any): DataSource;
234
+ /**
235
+ * Groups an array of objects by a specified key path.
236
+ * @public
237
+ * @example
238
+ * const users = [
239
+ * { name: 'Alice', age: 25, city: 'New York' },
240
+ * { name: 'Bob', age: 30, city: 'San Francisco' },
241
+ * { name: 'Charlie', age: 25, city: 'New York' },
242
+ * { name: 'David', age: 30, city: 'San Francisco' }
243
+ * ];
244
+ * group(users, 'city');
245
+ * // state is { data: { 'New York': [/Alice, Charlie/], 'San Francisco': [ /Bob, David / ] }
246
+ * @function
247
+ * @public
248
+ * @param {Object[]} arrayOfObjects - The array of objects to be grouped.
249
+ * @param {string} keyPath - The key path to group by.
250
+ * @param {function} callback - (Optional) Callback function
251
+ * @returns {Operation}
252
+ */
253
+ export function group(arrayOfObjects: any[], keyPath: string, callback?: Function): Operation;
233
254
  /**
234
255
  * Returns the index of the current array being iterated.
235
256
  * To be used with `each` as a data source.
236
257
  * @public
258
+ * @function
237
259
  * @example
238
260
  * index()
239
- * @function
240
261
  * @returns {DataSource}
241
262
  */
242
263
  export function index(): DataSource;
243
264
  /**
244
265
  * Turns an array into a string, separated by X.
245
266
  * @public
267
+ * @function
246
268
  * @example
247
269
  * field("destination_string__c", function(state) {
248
270
  * return arrayToString(dataValue("path_of_array")(state), ', ')
249
271
  * })
250
- * @function
251
272
  * @param {array} arr - Array of toString'able primatives.
252
273
  * @param {string} separator - Separator string.
253
274
  * @returns {string}
@@ -257,11 +278,11 @@ export function arrayToString(arr: any[], separator: string): string;
257
278
  * Ensures primitive data types are wrapped in an array.
258
279
  * Does not affect array objects.
259
280
  * @public
281
+ * @function
260
282
  * @example
261
283
  * each(function(state) {
262
284
  * return toArray( dataValue("path_of_array")(state) )
263
285
  * }, ...)
264
- * @function
265
286
  * @param {any} arg - Data required to be in an array
266
287
  * @returns {array}
267
288
  */
@@ -269,9 +290,9 @@ export function toArray(arg: any): any[];
269
290
  /**
270
291
  * Prepares next state
271
292
  * @public
293
+ * @function
272
294
  * @example
273
295
  * composeNextState(state, response)
274
- * @function
275
296
  * @param {State} state - state
276
297
  * @param {Object} response - Response to be added
277
298
  * @returns {State}
@@ -280,9 +301,9 @@ export function composeNextState(state: State, response: any): State;
280
301
  /**
281
302
  * Substitutes underscores for spaces and proper-cases a string
282
303
  * @public
304
+ * @function
283
305
  * @example
284
306
  * field("destination_string__c", humanProper(state.data.path_to_string))
285
- * @function
286
307
  * @param {string} str - String that needs converting
287
308
  * @returns {string}
288
309
  */
@@ -301,9 +322,9 @@ export function splitKeys(obj: any, keys: string[]): any[];
301
322
  /**
302
323
  * Replaces emojis in a string.
303
324
  * @public
325
+ * @function
304
326
  * @example
305
327
  * scrubEmojis('Dove🕊️⭐ 29')
306
- * @function
307
328
  * @param {string} text - String that needs to be cleaned
308
329
  * @param {string} replacementChars - Characters that replace the emojis
309
330
  * @returns {string}
@@ -312,9 +333,9 @@ export function scrubEmojis(text: string, replacementChars: string): string;
312
333
  /**
313
334
  * Chunks an array into an array of arrays, each with no more than a certain size.
314
335
  * @public
336
+ * @function
315
337
  * @example
316
338
  * chunk([1,2,3,4,5], 2)
317
- * @function
318
339
  * @param {Object} array - Array to be chunked
319
340
  * @param {Integer} chunkSize - The maxiumum size of each chunks
320
341
  * @returns {Object}
@@ -347,6 +368,8 @@ export function parseCsv(csvData: string | Stream, parsingOptions?: any, callbac
347
368
  * Schema can be passed directly, loaded as a JSON path from state, or loaded from a URL
348
369
  * Data can be passed directly or loaded as a JSON path from state.
349
370
  * By default, schema is loaded from `state.schema` and data from `state.data`.
371
+ * @pubic
372
+ * @function
350
373
  * @param {string|object} schema - The schema, path or URL to validate against
351
374
  * @param {string|object} data - The data or path to validate
352
375
  * @example <caption>Validate `state.data` with `state.schema`</caption>
@@ -367,11 +390,11 @@ export function validate(schema?: string | object, data?: string | object): Oper
367
390
  * different inputs. The custom formatter runs after natural language date conversion.
368
391
  * See the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}
369
392
  * @public
393
+ * @function
370
394
  * @example <caption>Use a cursor from state if present, or else use the default value</caption>
371
395
  * cursor($.cursor, { defaultValue: 'today' })
372
396
  * @example <caption>Use a pagination cursor</caption>
373
397
  * cursor(22)
374
- * @function
375
398
  * @param {any} value - the cursor value. Usually an ISO date, natural language date, or page number
376
399
  * @param {object} options - options to control the cursor.
377
400
  * @param {string} options.key - set the cursor key. Will persist through the whole run.
@@ -394,13 +417,13 @@ export * as dateFns from "./dateFns";
394
417
  * The operation will receive a slice of the data based of each item
395
418
  * of the JSONPath provided.
396
419
  * @public
420
+ * @function
397
421
  * @example
398
422
  * map("$.[*]",
399
423
  * create("SObject",
400
424
  * field("FirstName", sourceValue("$.firstName"))
401
425
  * )
402
426
  * )
403
- * @function
404
427
  * @param {string} path - JSONPath referencing a point in `state.data`.
405
428
  * @param {function} operation - The operation needed to be repeated.
406
429
  * @param {State} state - Runtime state.
@@ -14,7 +14,7 @@ export function expandRequestReferences(params: any): Operation;
14
14
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
15
15
  * @returns {Operation} - Function which takes state and returns a Promise
16
16
  * @example <caption>Get an item with a specified id from state</caption>
17
- * get({
17
+ * http.get({
18
18
  * url: state => `https://www.example.com/api/items/${state.id},
19
19
  * headers: {"content-type": "application/json"}
20
20
  * });
@@ -26,13 +26,13 @@ export function get(requestParams: object): Operation;
26
26
  * @function
27
27
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
28
28
  * @example <caption>Sending a payload with data that comes from state</caption>
29
- * post({
29
+ * http.post({
30
30
  * url: "https://example.com",
31
31
  * data: (state) => state.data
32
32
  * });
33
33
  * @example <caption> Capturing the response for later use in state </caption>
34
- * alterState((state) => {
35
- * return post({
34
+ * fn((state) => {
35
+ * return http.post({
36
36
  * url: "https://example.com",
37
37
  * data: (state) => state.data
38
38
  * })(state).then(({response}) => {
@@ -48,7 +48,7 @@ export function post(requestParams: object): Operation;
48
48
  * @function
49
49
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
50
50
  * @example <caption>Gets the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method</caption>
51
- * head({
51
+ * http.head({
52
52
  * url: 'https://www.example.com/api/items',
53
53
  * });
54
54
  * @returns {Operation} - Function which takes state and returns a Promise
@@ -60,7 +60,7 @@ export function head(requestParams: object): Operation;
60
60
  * @function
61
61
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
62
62
  * @example <caption>Creates a new resource or replaces a representation of the target resource with the request payload, with data from state.</caption>
63
- * put({
63
+ * http.put({
64
64
  * url: state => `https://www.example.com/api/items/${state.id}`,
65
65
  * data: state => state.data
66
66
  * });
@@ -73,7 +73,7 @@ export function put(requestParams: object): Operation;
73
73
  * @function
74
74
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
75
75
  * @example <caption>Applies partial modifications to a resource, with data from state.</caption>
76
- * patch({
76
+ * http.patch({
77
77
  * url: state => `https://www.example.com/api/items/${state.id}`,
78
78
  * data: state => state.data
79
79
  * });
@@ -86,7 +86,7 @@ export function patch(requestParams: object): Operation;
86
86
  * @function
87
87
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
88
88
  * @example <caption>Requests permitted communication options for a given URL or server, with data from state.</caption>
89
- * options({
89
+ * http.options({
90
90
  * url: 'https://www.example.com/api/items',
91
91
  * });
92
92
  * @returns {Operation} - Function which takes state and returns a Promise
@@ -99,7 +99,7 @@ import axios from "axios";
99
99
  * @function
100
100
  * @param {object} requestParams - Supports the exact parameters as Axios. See {@link https://github.com/axios/axios#axios-api here}
101
101
  * @example <caption>Deleting a record with data that comes from state</caption>
102
- * delete({
102
+ * http.delete({
103
103
  * url: state => `https://www.example.com/api/items/${state.id}`,
104
104
  * })(state);
105
105
  * @returns {Operation} - Function which takes state and returns a Promise