@openfn/language-common 2.3.2 → 2.4.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
@@ -1597,6 +1597,104 @@
1597
1597
  },
1598
1598
  "valid": true
1599
1599
  },
1600
+ {
1601
+ "name": "log",
1602
+ "params": [
1603
+ "args"
1604
+ ],
1605
+ "docs": {
1606
+ "description": "Outputs a message, like calling `console.log`. Use this at the top level of your job code, but not inside callbacks.",
1607
+ "tags": [
1608
+ {
1609
+ "title": "public",
1610
+ "description": null,
1611
+ "type": null
1612
+ },
1613
+ {
1614
+ "title": "function",
1615
+ "description": null,
1616
+ "name": null
1617
+ },
1618
+ {
1619
+ "title": "example",
1620
+ "description": "log('Patient List::', $.patients);",
1621
+ "caption": "Log values from state"
1622
+ },
1623
+ {
1624
+ "title": "example",
1625
+ "description": "fn((state) => {\n console.log(state.data);\n return state;\n})",
1626
+ "caption": "Use console.log inside a callback or fn block"
1627
+ },
1628
+ {
1629
+ "title": "param",
1630
+ "description": "A value or message to display in the logs",
1631
+ "type": {
1632
+ "type": "NameExpression",
1633
+ "name": "any"
1634
+ },
1635
+ "name": "args"
1636
+ },
1637
+ {
1638
+ "title": "returns",
1639
+ "description": null,
1640
+ "type": {
1641
+ "type": "NameExpression",
1642
+ "name": "Operation"
1643
+ }
1644
+ }
1645
+ ]
1646
+ },
1647
+ "valid": true
1648
+ },
1649
+ {
1650
+ "name": "debug",
1651
+ "params": [
1652
+ "args"
1653
+ ],
1654
+ "docs": {
1655
+ "description": "Outputs a message to the console with the debug log level. This is usually filtered out by default. Use this at the top level of your job code, but not inside callbacks.",
1656
+ "tags": [
1657
+ {
1658
+ "title": "public",
1659
+ "description": null,
1660
+ "type": null
1661
+ },
1662
+ {
1663
+ "title": "function",
1664
+ "description": null,
1665
+ "name": null
1666
+ },
1667
+ {
1668
+ "title": "example",
1669
+ "description": "debug('Patient List::', $.patients);",
1670
+ "caption": "Log values from state"
1671
+ },
1672
+ {
1673
+ "title": "example",
1674
+ "description": "fn((state) => {\n console.debug(state.data);\n return state;\n})",
1675
+ "caption": "Use console.debug inside a callback or fn block"
1676
+ },
1677
+ {
1678
+ "title": "param",
1679
+ "description": "A value or message to display in the logs",
1680
+ "type": {
1681
+ "type": "NameExpression",
1682
+ "name": "any"
1683
+ },
1684
+ "name": "args"
1685
+ },
1686
+ {
1687
+ "title": "returns",
1688
+ "description": null,
1689
+ "type": {
1690
+ "type": "NameExpression",
1691
+ "name": "Operation"
1692
+ }
1693
+ }
1694
+ ]
1695
+ },
1696
+ "valid": true
1697
+ },
1600
1698
  {
1601
1699
  "name": "map",
1602
1700
  "params": [
package/dist/index.cjs CHANGED
@@ -37,6 +37,7 @@ __export(src_exports, {
37
37
  dataPath: () => dataPath,
38
38
  dataValue: () => dataValue,
39
39
  dateFns: () => dateFns_exports,
40
+ debug: () => debug,
40
41
  default: () => src_default,
41
42
  each: () => each,
42
43
  execute: () => execute,
@@ -52,6 +53,7 @@ __export(src_exports, {
52
53
  join: () => join,
53
54
  jsonValue: () => jsonValue,
54
55
  lastReferenceValue: () => lastReferenceValue,
56
+ log: () => log,
55
57
  map: () => map,
56
58
  merge: () => merge,
57
59
  parseCsv: () => parseCsv,
@@ -79,6 +81,7 @@ __export(Adaptor_exports, {
79
81
  cursor: () => cursor,
80
82
  dataPath: () => dataPath,
81
83
  dataValue: () => dataValue,
84
+ debug: () => debug,
82
85
  each: () => each,
83
86
  execute: () => execute,
84
87
  expandReferences: () => expandReferences2,
@@ -92,6 +95,7 @@ __export(Adaptor_exports, {
92
95
  join: () => join,
93
96
  jsonValue: () => jsonValue,
94
97
  lastReferenceValue: () => lastReferenceValue,
98
+ log: () => log,
95
99
  map: () => map,
96
100
  merge: () => merge,
97
101
  parseCsv: () => parseCsv,
@@ -162,6 +166,31 @@ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
162
166
  throw e;
163
167
  };
164
168
 
169
+ // src/util/base64.js
170
+ var import_lodash = __toESM(require("lodash"), 1);
171
+ var encode = (data, options2 = { parseJson: true }) => {
172
+ let str = data;
173
+ if (typeof data !== "string" && options2.parseJson) {
174
+ try {
175
+ str = JSON.stringify(str);
176
+ } catch (e) {
177
+ console.log(e.message);
178
+ }
179
+ }
180
+ return Buffer.from(str, "utf-8").toString("base64");
181
+ };
182
+ var decode = (base64Data, options2 = { parseJson: true }) => {
183
+ let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
184
+ if ((import_lodash.default.startsWith(decodedValue, "[") || import_lodash.default.startsWith(decodedValue, "{")) && options2.parseJson) {
185
+ try {
186
+ decodedValue = JSON.parse(decodedValue);
187
+ } catch (e) {
188
+ console.log(e.message);
189
+ }
190
+ }
191
+ return decodedValue;
192
+ };
193
+
165
194
  // src/util/http.js
166
195
  var clients = /* @__PURE__ */ new Map();
167
196
  var makeBasicAuthHeader = (username, password) => {
@@ -169,10 +198,11 @@ var makeBasicAuthHeader = (username, password) => {
169
198
  const credentials = buff.toString("base64");
170
199
  return { Authorization: `Basic ${credentials}` };
171
200
  };
172
- var logResponse = (response) => {
201
+ var logResponse = (response, query = {}) => {
173
202
  const { method, url, statusCode, duration } = response;
174
203
  if (method && url && duration && statusCode) {
175
- const message = `${method} ${url} - ${statusCode} in ${duration}ms`;
204
+ const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
205
+ const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
176
206
  if (response instanceof Error) {
177
207
  console.error(message);
178
208
  console.error("response body: ");
@@ -328,7 +358,9 @@ function encodeRequestBody(body) {
328
358
  }
329
359
  async function readResponseBody(response, parseAs) {
330
360
  var _a;
331
- const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
361
+ const contentLength = parseInt(
362
+ response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
363
+ );
332
364
  const contentType = response.headers["content-type"];
333
365
  try {
334
366
  if (Number.isNaN(contentLength) || contentLength === 0) {
@@ -341,6 +373,9 @@ async function readResponseBody(response, parseAs) {
341
373
  return response.body.text();
342
374
  case "stream":
343
375
  return response.body;
376
+ case "base64":
377
+ const arrayBuffer = await response.body.arrayBuffer();
378
+ return encode(arrayBuffer, { parseJson: false });
344
379
  default:
345
380
  return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
346
381
  }
@@ -436,31 +471,6 @@ var parse_date_default = (d, startDate) => {
436
471
  return d;
437
472
  };
438
473
 
439
- // src/util/base64.js
440
- var import_lodash = __toESM(require("lodash"), 1);
441
- var encode = (data, options2 = { parseJson: true }) => {
442
- let str = data;
443
- if (typeof data !== "string" && options2.parseJson) {
444
- try {
445
- str = JSON.stringify(str);
446
- } catch (e) {
447
- console.log(e.message);
448
- }
449
- }
450
- return Buffer.from(str, "utf-8").toString("base64");
451
- };
452
- var decode = (base64Data, options2 = { parseJson: true }) => {
453
- let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
454
- if ((import_lodash.default.startsWith(decodedValue, "[") || import_lodash.default.startsWith(decodedValue, "{")) && options2.parseJson) {
455
- try {
456
- decodedValue = JSON.parse(decodedValue);
457
- } catch (e) {
458
- console.log(e.message);
459
- }
460
- }
461
- return decodedValue;
462
- };
463
-
464
474
  // src/util/uuid.js
465
475
  var import_node_crypto = require("crypto");
466
476
  var uuid = () => (0, import_node_crypto.randomUUID)();
@@ -862,6 +872,20 @@ function assert(expression, errorMessage) {
862
872
  return state;
863
873
  };
864
874
  }
875
+ function log(...args) {
876
+ return (state) => {
877
+ const [resolvedArgs] = expandReferences(state, args);
878
+ console.log(...resolvedArgs);
879
+ return state;
880
+ };
881
+ }
882
+ function debug(...args) {
883
+ return (state) => {
884
+ const [resolvedArgs] = expandReferences(state, args);
885
+ console.debug(...resolvedArgs);
886
+ return state;
887
+ };
888
+ }
865
889
 
866
890
  // src/beta.js
867
891
  var beta_exports = {};
@@ -983,6 +1007,7 @@ var src_default = Adaptor_exports;
983
1007
  dataPath,
984
1008
  dataValue,
985
1009
  dateFns,
1010
+ debug,
986
1011
  each,
987
1012
  execute,
988
1013
  expandReferences,
@@ -997,6 +1022,7 @@ var src_default = Adaptor_exports;
997
1022
  join,
998
1023
  jsonValue,
999
1024
  lastReferenceValue,
1025
+ log,
1000
1026
  map,
1001
1027
  merge,
1002
1028
  parseCsv,
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ __export(Adaptor_exports, {
17
17
  cursor: () => cursor,
18
18
  dataPath: () => dataPath,
19
19
  dataValue: () => dataValue,
20
+ debug: () => debug,
20
21
  each: () => each,
21
22
  execute: () => execute,
22
23
  expandReferences: () => expandReferences2,
@@ -30,6 +31,7 @@ __export(Adaptor_exports, {
30
31
  join: () => join,
31
32
  jsonValue: () => jsonValue,
32
33
  lastReferenceValue: () => lastReferenceValue,
34
+ log: () => log,
33
35
  map: () => map,
34
36
  merge: () => merge,
35
37
  parseCsv: () => parseCsv,
@@ -100,6 +102,31 @@ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
100
102
  throw e;
101
103
  };
102
104
 
105
+ // src/util/base64.js
106
+ import _ from "lodash";
107
+ var encode = (data, options2 = { parseJson: true }) => {
108
+ let str = data;
109
+ if (typeof data !== "string" && options2.parseJson) {
110
+ try {
111
+ str = JSON.stringify(str);
112
+ } catch (e) {
113
+ console.log(e.message);
114
+ }
115
+ }
116
+ return Buffer.from(str, "utf-8").toString("base64");
117
+ };
118
+ var decode = (base64Data, options2 = { parseJson: true }) => {
119
+ let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
120
+ if ((_.startsWith(decodedValue, "[") || _.startsWith(decodedValue, "{")) && options2.parseJson) {
121
+ try {
122
+ decodedValue = JSON.parse(decodedValue);
123
+ } catch (e) {
124
+ console.log(e.message);
125
+ }
126
+ }
127
+ return decodedValue;
128
+ };
129
+
103
130
  // src/util/http.js
104
131
  var clients = /* @__PURE__ */ new Map();
105
132
  var makeBasicAuthHeader = (username, password) => {
@@ -107,10 +134,11 @@ var makeBasicAuthHeader = (username, password) => {
107
134
  const credentials = buff.toString("base64");
108
135
  return { Authorization: `Basic ${credentials}` };
109
136
  };
110
- var logResponse = (response) => {
137
+ var logResponse = (response, query = {}) => {
111
138
  const { method, url, statusCode, duration } = response;
112
139
  if (method && url && duration && statusCode) {
113
- const message = `${method} ${url} - ${statusCode} in ${duration}ms`;
140
+ const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
141
+ const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
114
142
  if (response instanceof Error) {
115
143
  console.error(message);
116
144
  console.error("response body: ");
@@ -266,7 +294,9 @@ function encodeRequestBody(body) {
266
294
  }
267
295
  async function readResponseBody(response, parseAs) {
268
296
  var _a;
269
- const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
297
+ const contentLength = parseInt(
298
+ response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
299
+ );
270
300
  const contentType = response.headers["content-type"];
271
301
  try {
272
302
  if (Number.isNaN(contentLength) || contentLength === 0) {
@@ -279,6 +309,9 @@ async function readResponseBody(response, parseAs) {
279
309
  return response.body.text();
280
310
  case "stream":
281
311
  return response.body;
312
+ case "base64":
313
+ const arrayBuffer = await response.body.arrayBuffer();
314
+ return encode(arrayBuffer, { parseJson: false });
282
315
  default:
283
316
  return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
284
317
  }
@@ -374,31 +407,6 @@ var parse_date_default = (d, startDate) => {
374
407
  return d;
375
408
  };
376
409
 
377
- // src/util/base64.js
378
- import _ from "lodash";
379
- var encode = (data, options2 = { parseJson: true }) => {
380
- let str = data;
381
- if (typeof data !== "string" && options2.parseJson) {
382
- try {
383
- str = JSON.stringify(str);
384
- } catch (e) {
385
- console.log(e.message);
386
- }
387
- }
388
- return Buffer.from(str, "utf-8").toString("base64");
389
- };
390
- var decode = (base64Data, options2 = { parseJson: true }) => {
391
- let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
392
- if ((_.startsWith(decodedValue, "[") || _.startsWith(decodedValue, "{")) && options2.parseJson) {
393
- try {
394
- decodedValue = JSON.parse(decodedValue);
395
- } catch (e) {
396
- console.log(e.message);
397
- }
398
- }
399
- return decodedValue;
400
- };
401
-
402
410
  // src/util/uuid.js
403
411
  import { randomUUID } from "crypto";
404
412
  var uuid = () => randomUUID();
@@ -800,6 +808,20 @@ function assert(expression, errorMessage) {
800
808
  return state;
801
809
  };
802
810
  }
811
+ function log(...args) {
812
+ return (state) => {
813
+ const [resolvedArgs] = expandReferences(state, args);
814
+ console.log(...resolvedArgs);
815
+ return state;
816
+ };
817
+ }
818
+ function debug(...args) {
819
+ return (state) => {
820
+ const [resolvedArgs] = expandReferences(state, args);
821
+ console.debug(...resolvedArgs);
822
+ return state;
823
+ };
824
+ }
803
825
 
804
826
  // src/beta.js
805
827
  var beta_exports = {};
@@ -923,6 +945,7 @@ export {
923
945
  dataPath,
924
946
  dataValue,
925
947
  dateFns_exports as dateFns,
948
+ debug,
926
949
  src_default as default,
927
950
  each,
928
951
  execute,
@@ -938,6 +961,7 @@ export {
938
961
  join,
939
962
  jsonValue,
940
963
  lastReferenceValue,
964
+ log,
941
965
  map,
942
966
  merge,
943
967
  parseCsv,
package/dist/util.cjs CHANGED
@@ -71,6 +71,31 @@ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
71
71
  throw e;
72
72
  };
73
73
 
74
+ // src/util/base64.js
75
+ var import_lodash = __toESM(require("lodash"), 1);
76
+ var encode = (data, options = { parseJson: true }) => {
77
+ let str = data;
78
+ if (typeof data !== "string" && options.parseJson) {
79
+ try {
80
+ str = JSON.stringify(str);
81
+ } catch (e) {
82
+ console.log(e.message);
83
+ }
84
+ }
85
+ return Buffer.from(str, "utf-8").toString("base64");
86
+ };
87
+ var decode = (base64Data, options = { parseJson: true }) => {
88
+ let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
89
+ if ((import_lodash.default.startsWith(decodedValue, "[") || import_lodash.default.startsWith(decodedValue, "{")) && options.parseJson) {
90
+ try {
91
+ decodedValue = JSON.parse(decodedValue);
92
+ } catch (e) {
93
+ console.log(e.message);
94
+ }
95
+ }
96
+ return decodedValue;
97
+ };
98
+
74
99
  // src/util/http.js
75
100
  var clients = /* @__PURE__ */ new Map();
76
101
  var makeBasicAuthHeader = (username, password) => {
@@ -78,10 +103,11 @@ var makeBasicAuthHeader = (username, password) => {
78
103
  const credentials = buff.toString("base64");
79
104
  return { Authorization: `Basic ${credentials}` };
80
105
  };
81
- var logResponse = (response) => {
106
+ var logResponse = (response, query = {}) => {
82
107
  const { method, url, statusCode, duration } = response;
83
108
  if (method && url && duration && statusCode) {
84
- const message = `${method} ${url} - ${statusCode} in ${duration}ms`;
109
+ const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
110
+ const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
85
111
  if (response instanceof Error) {
86
112
  console.error(message);
87
113
  console.error("response body: ");
@@ -237,7 +263,9 @@ function encodeRequestBody(body) {
237
263
  }
238
264
  async function readResponseBody(response, parseAs) {
239
265
  var _a;
240
- const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
266
+ const contentLength = parseInt(
267
+ response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
268
+ );
241
269
  const contentType = response.headers["content-type"];
242
270
  try {
243
271
  if (Number.isNaN(contentLength) || contentLength === 0) {
@@ -250,6 +278,9 @@ async function readResponseBody(response, parseAs) {
250
278
  return response.body.text();
251
279
  case "stream":
252
280
  return response.body;
281
+ case "base64":
282
+ const arrayBuffer = await response.body.arrayBuffer();
283
+ return encode(arrayBuffer, { parseJson: false });
253
284
  default:
254
285
  return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
255
286
  }
@@ -345,31 +376,6 @@ var parse_date_default = (d, startDate) => {
345
376
  return d;
346
377
  };
347
378
 
348
- // src/util/base64.js
349
- var import_lodash = __toESM(require("lodash"), 1);
350
- var encode = (data, options = { parseJson: true }) => {
351
- let str = data;
352
- if (typeof data !== "string" && options.parseJson) {
353
- try {
354
- str = JSON.stringify(str);
355
- } catch (e) {
356
- console.log(e.message);
357
- }
358
- }
359
- return Buffer.from(str, "utf-8").toString("base64");
360
- };
361
- var decode = (base64Data, options = { parseJson: true }) => {
362
- let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
363
- if ((import_lodash.default.startsWith(decodedValue, "[") || import_lodash.default.startsWith(decodedValue, "{")) && options.parseJson) {
364
- try {
365
- decodedValue = JSON.parse(decodedValue);
366
- } catch (e) {
367
- console.log(e.message);
368
- }
369
- }
370
- return decodedValue;
371
- };
372
-
373
379
  // src/util/uuid.js
374
380
  var import_node_crypto = require("crypto");
375
381
  var uuid = () => (0, import_node_crypto.randomUUID)();
package/dist/util.js CHANGED
@@ -22,6 +22,31 @@ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
22
22
  throw e;
23
23
  };
24
24
 
25
+ // src/util/base64.js
26
+ import _ from "lodash";
27
+ var encode = (data, options = { parseJson: true }) => {
28
+ let str = data;
29
+ if (typeof data !== "string" && options.parseJson) {
30
+ try {
31
+ str = JSON.stringify(str);
32
+ } catch (e) {
33
+ console.log(e.message);
34
+ }
35
+ }
36
+ return Buffer.from(str, "utf-8").toString("base64");
37
+ };
38
+ var decode = (base64Data, options = { parseJson: true }) => {
39
+ let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
40
+ if ((_.startsWith(decodedValue, "[") || _.startsWith(decodedValue, "{")) && options.parseJson) {
41
+ try {
42
+ decodedValue = JSON.parse(decodedValue);
43
+ } catch (e) {
44
+ console.log(e.message);
45
+ }
46
+ }
47
+ return decodedValue;
48
+ };
49
+
25
50
  // src/util/http.js
26
51
  var clients = /* @__PURE__ */ new Map();
27
52
  var makeBasicAuthHeader = (username, password) => {
@@ -29,10 +54,11 @@ var makeBasicAuthHeader = (username, password) => {
29
54
  const credentials = buff.toString("base64");
30
55
  return { Authorization: `Basic ${credentials}` };
31
56
  };
32
- var logResponse = (response) => {
57
+ var logResponse = (response, query = {}) => {
33
58
  const { method, url, statusCode, duration } = response;
34
59
  if (method && url && duration && statusCode) {
35
- const message = `${method} ${url} - ${statusCode} in ${duration}ms`;
60
+ const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
61
+ const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
36
62
  if (response instanceof Error) {
37
63
  console.error(message);
38
64
  console.error("response body: ");
@@ -188,7 +214,9 @@ function encodeRequestBody(body) {
188
214
  }
189
215
  async function readResponseBody(response, parseAs) {
190
216
  var _a;
191
- const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
217
+ const contentLength = parseInt(
218
+ response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
219
+ );
192
220
  const contentType = response.headers["content-type"];
193
221
  try {
194
222
  if (Number.isNaN(contentLength) || contentLength === 0) {
@@ -201,6 +229,9 @@ async function readResponseBody(response, parseAs) {
201
229
  return response.body.text();
202
230
  case "stream":
203
231
  return response.body;
232
+ case "base64":
233
+ const arrayBuffer = await response.body.arrayBuffer();
234
+ return encode(arrayBuffer, { parseJson: false });
204
235
  default:
205
236
  return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
206
237
  }
@@ -296,31 +327,6 @@ var parse_date_default = (d, startDate) => {
296
327
  return d;
297
328
  };
298
329
 
299
- // src/util/base64.js
300
- import _ from "lodash";
301
- var encode = (data, options = { parseJson: true }) => {
302
- let str = data;
303
- if (typeof data !== "string" && options.parseJson) {
304
- try {
305
- str = JSON.stringify(str);
306
- } catch (e) {
307
- console.log(e.message);
308
- }
309
- }
310
- return Buffer.from(str, "utf-8").toString("base64");
311
- };
312
- var decode = (base64Data, options = { parseJson: true }) => {
313
- let decodedValue = Buffer.from(base64Data, "base64").toString("utf-8");
314
- if ((_.startsWith(decodedValue, "[") || _.startsWith(decodedValue, "{")) && options.parseJson) {
315
- try {
316
- decodedValue = JSON.parse(decodedValue);
317
- } catch (e) {
318
- console.log(e.message);
319
- }
320
- }
321
- return decodedValue;
322
- };
323
-
324
330
  // src/util/uuid.js
325
331
  import { randomUUID } from "crypto";
326
332
  var uuid = () => randomUUID();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "2.3.2",
3
+ "version": "2.4.0",
4
4
  "description": "Common Expressions for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -434,6 +434,37 @@ export function cursor(value: any, options?: {
434
434
  * @returns {operation}
435
435
  */
436
436
  export function assert(expression: any, errorMessage: string): operation;
437
+ /**
438
+ * Outputs a message, like calling `console.log`. Use this at the top level of your job code, but not inside callbacks.
439
+ * @public
440
+ * @function
441
+ * @example <caption>Log values from state</caption>
442
+ * log('Patient List::', $.patients);
443
+ * @example <caption>Use console.log inside a callback or fn block</caption>
444
+ * fn((state) => {
445
+ * console.log(state.data);
446
+ * return state;
447
+ * })
448
+ * @param {any} args - A value or message to display in the logs
449
+ * @returns {Operation}
450
+ */
451
+ export function log(...args: any): Operation;
452
+ /**
453
+ * Outputs a message to the console with the debug log level. This is usually filtered out by default. Use this at the top level of your job code, but not inside callbacks.
454
+ * @public
455
+ * @function
456
+ * @example <caption>Log values from state</caption>
457
+ * debug('Patient List::', $.patients);
458
+ * @example <caption>Use console.debug inside a callback or fn block</caption>
459
+ * fn((state) => {
460
+ * console.debug(state.data);
461
+ * return state;
462
+ * })
463
+
464
+ * @param {any} args - A value or message to display in the logs
465
+ * @returns {Operation}
466
+ */
467
+ export function debug(...args: any): Operation;
437
468
  /**
438
469
  * Scopes an array of data based on a JSONPath.
439
470
  * Useful when the source data has `n` items you would like to map to
@@ -27,7 +27,7 @@ export function request(method: any, fullUrlOrPath: any, options?: {}): Promise<
27
27
  export function makeBasicAuthHeader(username: any, password: any): {
28
28
  Authorization: string;
29
29
  };
30
- export function logResponse(response: any): any;
30
+ export function logResponse(response: any, query?: {}): any;
31
31
  export function enableMockClient(baseUrl: any): import("undici/types/mock-interceptor").Interceptable;
32
32
  export const ERROR_ABSOLUTE_URL: "Absolute URLs not suppored";
33
33
  export function assertRelativeUrl(path: any): void;