@openfn/language-common 2.3.3 → 2.5.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 +98 -0
- package/dist/index.cjs +38 -10
- package/dist/index.js +36 -10
- package/dist/util.cjs +16 -8
- package/dist/util.js +16 -8
- package/package.json +2 -2
- package/types/Adaptor.d.ts +31 -0
- package/types/http.d.ts +11 -10
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,
|
|
@@ -195,9 +199,10 @@ var makeBasicAuthHeader = (username, password) => {
|
|
|
195
199
|
return { Authorization: `Basic ${credentials}` };
|
|
196
200
|
};
|
|
197
201
|
var logResponse = (response) => {
|
|
198
|
-
const { method, url, statusCode, duration } = response;
|
|
202
|
+
const { method, url, statusCode, duration, query } = response;
|
|
199
203
|
if (method && url && duration && statusCode) {
|
|
200
|
-
const
|
|
204
|
+
const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
|
|
205
|
+
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
201
206
|
if (response instanceof Error) {
|
|
202
207
|
console.error(message);
|
|
203
208
|
console.error("response body: ");
|
|
@@ -306,12 +311,13 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
306
311
|
maxRedirections
|
|
307
312
|
} = options2;
|
|
308
313
|
const client = getClient(baseUrl, { tls });
|
|
314
|
+
const queryParams = {
|
|
315
|
+
...optionQuery,
|
|
316
|
+
...urlQuery
|
|
317
|
+
};
|
|
309
318
|
const response = await client.request({
|
|
310
319
|
path: path2,
|
|
311
|
-
query:
|
|
312
|
-
...optionQuery,
|
|
313
|
-
...urlQuery
|
|
314
|
-
},
|
|
320
|
+
query: queryParams,
|
|
315
321
|
method,
|
|
316
322
|
headers,
|
|
317
323
|
body: encodeRequestBody(body),
|
|
@@ -326,7 +332,7 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
326
332
|
const responseBody = await readResponseBody(response, parseAs);
|
|
327
333
|
const endTime = Date.now();
|
|
328
334
|
const duration = endTime - startTime;
|
|
329
|
-
|
|
335
|
+
const requestResponse = {
|
|
330
336
|
url,
|
|
331
337
|
method,
|
|
332
338
|
statusCode: response.statusCode,
|
|
@@ -335,6 +341,10 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
335
341
|
body: responseBody,
|
|
336
342
|
duration
|
|
337
343
|
};
|
|
344
|
+
if (Object.keys(queryParams).length > 0) {
|
|
345
|
+
requestResponse.query = queryParams;
|
|
346
|
+
}
|
|
347
|
+
return requestResponse;
|
|
338
348
|
}
|
|
339
349
|
function encodeRequestBody(body) {
|
|
340
350
|
if (!body) {
|
|
@@ -353,7 +363,9 @@ function encodeRequestBody(body) {
|
|
|
353
363
|
}
|
|
354
364
|
async function readResponseBody(response, parseAs) {
|
|
355
365
|
var _a;
|
|
356
|
-
const contentLength = (
|
|
366
|
+
const contentLength = parseInt(
|
|
367
|
+
response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
|
|
368
|
+
);
|
|
357
369
|
const contentType = response.headers["content-type"];
|
|
358
370
|
try {
|
|
359
371
|
if (Number.isNaN(contentLength) || contentLength === 0) {
|
|
@@ -865,6 +877,20 @@ function assert(expression, errorMessage) {
|
|
|
865
877
|
return state;
|
|
866
878
|
};
|
|
867
879
|
}
|
|
880
|
+
function log(...args) {
|
|
881
|
+
return (state) => {
|
|
882
|
+
const [resolvedArgs] = expandReferences(state, args);
|
|
883
|
+
console.log(...resolvedArgs);
|
|
884
|
+
return state;
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
function debug(...args) {
|
|
888
|
+
return (state) => {
|
|
889
|
+
const [resolvedArgs] = expandReferences(state, args);
|
|
890
|
+
console.debug(...resolvedArgs);
|
|
891
|
+
return state;
|
|
892
|
+
};
|
|
893
|
+
}
|
|
868
894
|
|
|
869
895
|
// src/beta.js
|
|
870
896
|
var beta_exports = {};
|
|
@@ -958,8 +984,8 @@ var req = function(method, url, options2) {
|
|
|
958
984
|
function get3(url, options2) {
|
|
959
985
|
return req("GET", url, options2);
|
|
960
986
|
}
|
|
961
|
-
function post2(
|
|
962
|
-
return req("POST",
|
|
987
|
+
function post2(url, data, options2) {
|
|
988
|
+
return req("POST", url, { body: data, ...options2 });
|
|
963
989
|
}
|
|
964
990
|
|
|
965
991
|
// src/dateFns.js
|
|
@@ -986,6 +1012,7 @@ var src_default = Adaptor_exports;
|
|
|
986
1012
|
dataPath,
|
|
987
1013
|
dataValue,
|
|
988
1014
|
dateFns,
|
|
1015
|
+
debug,
|
|
989
1016
|
each,
|
|
990
1017
|
execute,
|
|
991
1018
|
expandReferences,
|
|
@@ -1000,6 +1027,7 @@ var src_default = Adaptor_exports;
|
|
|
1000
1027
|
join,
|
|
1001
1028
|
jsonValue,
|
|
1002
1029
|
lastReferenceValue,
|
|
1030
|
+
log,
|
|
1003
1031
|
map,
|
|
1004
1032
|
merge,
|
|
1005
1033
|
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,
|
|
@@ -133,9 +135,10 @@ var makeBasicAuthHeader = (username, password) => {
|
|
|
133
135
|
return { Authorization: `Basic ${credentials}` };
|
|
134
136
|
};
|
|
135
137
|
var logResponse = (response) => {
|
|
136
|
-
const { method, url, statusCode, duration } = response;
|
|
138
|
+
const { method, url, statusCode, duration, query } = response;
|
|
137
139
|
if (method && url && duration && statusCode) {
|
|
138
|
-
const
|
|
140
|
+
const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
|
|
141
|
+
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
139
142
|
if (response instanceof Error) {
|
|
140
143
|
console.error(message);
|
|
141
144
|
console.error("response body: ");
|
|
@@ -244,12 +247,13 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
244
247
|
maxRedirections
|
|
245
248
|
} = options2;
|
|
246
249
|
const client = getClient(baseUrl, { tls });
|
|
250
|
+
const queryParams = {
|
|
251
|
+
...optionQuery,
|
|
252
|
+
...urlQuery
|
|
253
|
+
};
|
|
247
254
|
const response = await client.request({
|
|
248
255
|
path: path2,
|
|
249
|
-
query:
|
|
250
|
-
...optionQuery,
|
|
251
|
-
...urlQuery
|
|
252
|
-
},
|
|
256
|
+
query: queryParams,
|
|
253
257
|
method,
|
|
254
258
|
headers,
|
|
255
259
|
body: encodeRequestBody(body),
|
|
@@ -264,7 +268,7 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
264
268
|
const responseBody = await readResponseBody(response, parseAs);
|
|
265
269
|
const endTime = Date.now();
|
|
266
270
|
const duration = endTime - startTime;
|
|
267
|
-
|
|
271
|
+
const requestResponse = {
|
|
268
272
|
url,
|
|
269
273
|
method,
|
|
270
274
|
statusCode: response.statusCode,
|
|
@@ -273,6 +277,10 @@ async function request(method, fullUrlOrPath, options2 = {}) {
|
|
|
273
277
|
body: responseBody,
|
|
274
278
|
duration
|
|
275
279
|
};
|
|
280
|
+
if (Object.keys(queryParams).length > 0) {
|
|
281
|
+
requestResponse.query = queryParams;
|
|
282
|
+
}
|
|
283
|
+
return requestResponse;
|
|
276
284
|
}
|
|
277
285
|
function encodeRequestBody(body) {
|
|
278
286
|
if (!body) {
|
|
@@ -291,7 +299,9 @@ function encodeRequestBody(body) {
|
|
|
291
299
|
}
|
|
292
300
|
async function readResponseBody(response, parseAs) {
|
|
293
301
|
var _a;
|
|
294
|
-
const contentLength = (
|
|
302
|
+
const contentLength = parseInt(
|
|
303
|
+
response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
|
|
304
|
+
);
|
|
295
305
|
const contentType = response.headers["content-type"];
|
|
296
306
|
try {
|
|
297
307
|
if (Number.isNaN(contentLength) || contentLength === 0) {
|
|
@@ -803,6 +813,20 @@ function assert(expression, errorMessage) {
|
|
|
803
813
|
return state;
|
|
804
814
|
};
|
|
805
815
|
}
|
|
816
|
+
function log(...args) {
|
|
817
|
+
return (state) => {
|
|
818
|
+
const [resolvedArgs] = expandReferences(state, args);
|
|
819
|
+
console.log(...resolvedArgs);
|
|
820
|
+
return state;
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
function debug(...args) {
|
|
824
|
+
return (state) => {
|
|
825
|
+
const [resolvedArgs] = expandReferences(state, args);
|
|
826
|
+
console.debug(...resolvedArgs);
|
|
827
|
+
return state;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
806
830
|
|
|
807
831
|
// src/beta.js
|
|
808
832
|
var beta_exports = {};
|
|
@@ -896,8 +920,8 @@ var req = function(method, url, options2) {
|
|
|
896
920
|
function get3(url, options2) {
|
|
897
921
|
return req("GET", url, options2);
|
|
898
922
|
}
|
|
899
|
-
function post2(
|
|
900
|
-
return req("POST",
|
|
923
|
+
function post2(url, data, options2) {
|
|
924
|
+
return req("POST", url, { body: data, ...options2 });
|
|
901
925
|
}
|
|
902
926
|
|
|
903
927
|
// src/dateFns.js
|
|
@@ -926,6 +950,7 @@ export {
|
|
|
926
950
|
dataPath,
|
|
927
951
|
dataValue,
|
|
928
952
|
dateFns_exports as dateFns,
|
|
953
|
+
debug,
|
|
929
954
|
src_default as default,
|
|
930
955
|
each,
|
|
931
956
|
execute,
|
|
@@ -941,6 +966,7 @@ export {
|
|
|
941
966
|
join,
|
|
942
967
|
jsonValue,
|
|
943
968
|
lastReferenceValue,
|
|
969
|
+
log,
|
|
944
970
|
map,
|
|
945
971
|
merge,
|
|
946
972
|
parseCsv,
|
package/dist/util.cjs
CHANGED
|
@@ -104,9 +104,10 @@ var makeBasicAuthHeader = (username, password) => {
|
|
|
104
104
|
return { Authorization: `Basic ${credentials}` };
|
|
105
105
|
};
|
|
106
106
|
var logResponse = (response) => {
|
|
107
|
-
const { method, url, statusCode, duration } = response;
|
|
107
|
+
const { method, url, statusCode, duration, query } = response;
|
|
108
108
|
if (method && url && duration && statusCode) {
|
|
109
|
-
const
|
|
109
|
+
const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
|
|
110
|
+
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
110
111
|
if (response instanceof Error) {
|
|
111
112
|
console.error(message);
|
|
112
113
|
console.error("response body: ");
|
|
@@ -215,12 +216,13 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
215
216
|
maxRedirections
|
|
216
217
|
} = options;
|
|
217
218
|
const client = getClient(baseUrl, { tls });
|
|
219
|
+
const queryParams = {
|
|
220
|
+
...optionQuery,
|
|
221
|
+
...urlQuery
|
|
222
|
+
};
|
|
218
223
|
const response = await client.request({
|
|
219
224
|
path: path2,
|
|
220
|
-
query:
|
|
221
|
-
...optionQuery,
|
|
222
|
-
...urlQuery
|
|
223
|
-
},
|
|
225
|
+
query: queryParams,
|
|
224
226
|
method,
|
|
225
227
|
headers,
|
|
226
228
|
body: encodeRequestBody(body),
|
|
@@ -235,7 +237,7 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
235
237
|
const responseBody = await readResponseBody(response, parseAs);
|
|
236
238
|
const endTime = Date.now();
|
|
237
239
|
const duration = endTime - startTime;
|
|
238
|
-
|
|
240
|
+
const requestResponse = {
|
|
239
241
|
url,
|
|
240
242
|
method,
|
|
241
243
|
statusCode: response.statusCode,
|
|
@@ -244,6 +246,10 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
244
246
|
body: responseBody,
|
|
245
247
|
duration
|
|
246
248
|
};
|
|
249
|
+
if (Object.keys(queryParams).length > 0) {
|
|
250
|
+
requestResponse.query = queryParams;
|
|
251
|
+
}
|
|
252
|
+
return requestResponse;
|
|
247
253
|
}
|
|
248
254
|
function encodeRequestBody(body) {
|
|
249
255
|
if (!body) {
|
|
@@ -262,7 +268,9 @@ function encodeRequestBody(body) {
|
|
|
262
268
|
}
|
|
263
269
|
async function readResponseBody(response, parseAs) {
|
|
264
270
|
var _a;
|
|
265
|
-
const contentLength = (
|
|
271
|
+
const contentLength = parseInt(
|
|
272
|
+
response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
|
|
273
|
+
);
|
|
266
274
|
const contentType = response.headers["content-type"];
|
|
267
275
|
try {
|
|
268
276
|
if (Number.isNaN(contentLength) || contentLength === 0) {
|
package/dist/util.js
CHANGED
|
@@ -55,9 +55,10 @@ var makeBasicAuthHeader = (username, password) => {
|
|
|
55
55
|
return { Authorization: `Basic ${credentials}` };
|
|
56
56
|
};
|
|
57
57
|
var logResponse = (response) => {
|
|
58
|
-
const { method, url, statusCode, duration } = response;
|
|
58
|
+
const { method, url, statusCode, duration, query } = response;
|
|
59
59
|
if (method && url && duration && statusCode) {
|
|
60
|
-
const
|
|
60
|
+
const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
|
|
61
|
+
const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
|
|
61
62
|
if (response instanceof Error) {
|
|
62
63
|
console.error(message);
|
|
63
64
|
console.error("response body: ");
|
|
@@ -166,12 +167,13 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
166
167
|
maxRedirections
|
|
167
168
|
} = options;
|
|
168
169
|
const client = getClient(baseUrl, { tls });
|
|
170
|
+
const queryParams = {
|
|
171
|
+
...optionQuery,
|
|
172
|
+
...urlQuery
|
|
173
|
+
};
|
|
169
174
|
const response = await client.request({
|
|
170
175
|
path: path2,
|
|
171
|
-
query:
|
|
172
|
-
...optionQuery,
|
|
173
|
-
...urlQuery
|
|
174
|
-
},
|
|
176
|
+
query: queryParams,
|
|
175
177
|
method,
|
|
176
178
|
headers,
|
|
177
179
|
body: encodeRequestBody(body),
|
|
@@ -186,7 +188,7 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
186
188
|
const responseBody = await readResponseBody(response, parseAs);
|
|
187
189
|
const endTime = Date.now();
|
|
188
190
|
const duration = endTime - startTime;
|
|
189
|
-
|
|
191
|
+
const requestResponse = {
|
|
190
192
|
url,
|
|
191
193
|
method,
|
|
192
194
|
statusCode: response.statusCode,
|
|
@@ -195,6 +197,10 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
195
197
|
body: responseBody,
|
|
196
198
|
duration
|
|
197
199
|
};
|
|
200
|
+
if (Object.keys(queryParams).length > 0) {
|
|
201
|
+
requestResponse.query = queryParams;
|
|
202
|
+
}
|
|
203
|
+
return requestResponse;
|
|
198
204
|
}
|
|
199
205
|
function encodeRequestBody(body) {
|
|
200
206
|
if (!body) {
|
|
@@ -213,7 +219,9 @@ function encodeRequestBody(body) {
|
|
|
213
219
|
}
|
|
214
220
|
async function readResponseBody(response, parseAs) {
|
|
215
221
|
var _a;
|
|
216
|
-
const contentLength = (
|
|
222
|
+
const contentLength = parseInt(
|
|
223
|
+
response.headers["content-length"] ?? ((_a = response.body) == null ? void 0 : _a.readableLength)
|
|
224
|
+
);
|
|
217
225
|
const contentType = response.headers["content-type"];
|
|
218
226
|
try {
|
|
219
227
|
if (Number.isNaN(contentLength) || contentLength === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-common",
|
|
3
|
-
"
|
|
3
|
+
"label": "Common",
|
|
4
|
+
"version": "2.5.0",
|
|
4
5
|
"description": "Common Expressions for OpenFn",
|
|
5
6
|
"homepage": "https://docs.openfn.org",
|
|
6
7
|
"repository": {
|
|
@@ -46,7 +47,6 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"chai": "4.3.6",
|
|
48
49
|
"deep-eql": "4.1.1",
|
|
49
|
-
"esno": "^0.16.3",
|
|
50
50
|
"nock": "13.2.9",
|
|
51
51
|
"rimraf": "^3.0.2"
|
|
52
52
|
},
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -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
|
package/types/http.d.ts
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* easily add commonly used options. The return object is chainable so you can set
|
|
4
4
|
* as many options as you want.
|
|
5
5
|
* Pass an object to set your own options.
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {OptionsHelpers} opts - options to pass to the request
|
|
7
7
|
* @returns {OptionsHelpers}
|
|
8
8
|
* @function
|
|
9
9
|
* @public
|
|
10
|
-
* @example <caption>Get with a query an
|
|
11
|
-
* get($.data.url, http.options({ query: $.query }).
|
|
10
|
+
* @example <caption>Get with a query an oauth token</caption>
|
|
11
|
+
* http.get($.data.url, http.options({ query: $.query }).oauth($.configuration.access_token))
|
|
12
12
|
*/
|
|
13
|
-
export function options(opts?:
|
|
13
|
+
export function options(opts?: any): any;
|
|
14
14
|
/**
|
|
15
15
|
* Make a GET request.
|
|
16
16
|
* @public
|
|
@@ -38,17 +38,18 @@ export function get(url: string, options: CommonRequestOptions): Operation;
|
|
|
38
38
|
* @public
|
|
39
39
|
* @function
|
|
40
40
|
* @example <caption>Post a JSON object (setting the content-type header)</caption>
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* http.post(
|
|
42
|
+
* "https://jsonplaceholder.typicode.com/todos",
|
|
43
|
+
* $.data,
|
|
44
|
+
* http.options().json()
|
|
45
|
+
* );
|
|
46
46
|
* @param {string} url - URL to access
|
|
47
|
+
* @param {object} data - Body data to append to the request.
|
|
47
48
|
* @param {CommonRequestOptions} options - Request options
|
|
48
49
|
* @state {CommonHttpState}
|
|
49
50
|
* @returns {Operation}
|
|
50
51
|
*/
|
|
51
|
-
export function post(
|
|
52
|
+
export function post(url: string, data: object, options: CommonRequestOptions): Operation;
|
|
52
53
|
export { req as request };
|
|
53
54
|
/**
|
|
54
55
|
* Helper functions provided by `http.options`.
|