@openfn/language-common 1.13.4 → 1.14.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 +54 -1
- package/dist/index.cjs +15 -1
- package/dist/index.js +13 -1
- package/dist/util.cjs +20 -4
- package/dist/util.js +14 -4
- package/package.json +1 -1
- package/types/Adaptor.d.ts +11 -0
- package/types/util/http.d.ts +1 -0
package/ast.json
CHANGED
|
@@ -86,6 +86,59 @@
|
|
|
86
86
|
},
|
|
87
87
|
"valid": true
|
|
88
88
|
},
|
|
89
|
+
{
|
|
90
|
+
"name": "fnIf",
|
|
91
|
+
"params": [
|
|
92
|
+
"condition",
|
|
93
|
+
"operation"
|
|
94
|
+
],
|
|
95
|
+
"docs": {
|
|
96
|
+
"description": "A custom operation that will only execute the function if the condition returns true",
|
|
97
|
+
"tags": [
|
|
98
|
+
{
|
|
99
|
+
"title": "public",
|
|
100
|
+
"description": null,
|
|
101
|
+
"type": null
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"title": "example",
|
|
105
|
+
"description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"title": "function",
|
|
109
|
+
"description": null,
|
|
110
|
+
"name": null
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"title": "param",
|
|
114
|
+
"description": "The condition that returns true",
|
|
115
|
+
"type": {
|
|
116
|
+
"type": "NameExpression",
|
|
117
|
+
"name": "Boolean"
|
|
118
|
+
},
|
|
119
|
+
"name": "condition"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"title": "param",
|
|
123
|
+
"description": "The operation needed to be executed.",
|
|
124
|
+
"type": {
|
|
125
|
+
"type": "NameExpression",
|
|
126
|
+
"name": "Operation"
|
|
127
|
+
},
|
|
128
|
+
"name": "operation"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"title": "returns",
|
|
132
|
+
"description": null,
|
|
133
|
+
"type": {
|
|
134
|
+
"type": "NameExpression",
|
|
135
|
+
"name": "Operation"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"valid": true
|
|
141
|
+
},
|
|
89
142
|
{
|
|
90
143
|
"name": "jsonValue",
|
|
91
144
|
"params": [
|
|
@@ -1319,7 +1372,7 @@
|
|
|
1319
1372
|
"options"
|
|
1320
1373
|
],
|
|
1321
1374
|
"docs": {
|
|
1322
|
-
"description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones
|
|
1375
|
+
"description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
|
|
1323
1376
|
"tags": [
|
|
1324
1377
|
{
|
|
1325
1378
|
"title": "public",
|
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
field: () => field,
|
|
44
44
|
fields: () => fields,
|
|
45
45
|
fn: () => fn,
|
|
46
|
+
fnIf: () => fnIf,
|
|
46
47
|
http: () => http_deprecated_exports,
|
|
47
48
|
humanProper: () => humanProper,
|
|
48
49
|
index: () => index,
|
|
@@ -82,6 +83,7 @@ __export(Adaptor_exports, {
|
|
|
82
83
|
field: () => field,
|
|
83
84
|
fields: () => fields,
|
|
84
85
|
fn: () => fn,
|
|
86
|
+
fnIf: () => fnIf,
|
|
85
87
|
http: () => http_deprecated_exports,
|
|
86
88
|
humanProper: () => humanProper,
|
|
87
89
|
index: () => index,
|
|
@@ -111,6 +113,7 @@ var import_date_fns3 = __toESM(require("date-fns"), 1);
|
|
|
111
113
|
var import_undici = require("undici");
|
|
112
114
|
var import_http_status_codes = require("http-status-codes");
|
|
113
115
|
var import_node_stream = require("stream");
|
|
116
|
+
var import_node_querystring = __toESM(require("querystring"), 1);
|
|
114
117
|
|
|
115
118
|
// src/util/references.js
|
|
116
119
|
var import_node_stream2 = require("stream");
|
|
@@ -332,6 +335,12 @@ function fn(func) {
|
|
|
332
335
|
return func(state);
|
|
333
336
|
};
|
|
334
337
|
}
|
|
338
|
+
function fnIf(condition, operation) {
|
|
339
|
+
return (state) => {
|
|
340
|
+
const [resolvedCondition] = expandReferences(state, condition);
|
|
341
|
+
return resolvedCondition ? operation(state) : state;
|
|
342
|
+
};
|
|
343
|
+
}
|
|
335
344
|
function jsonValue(obj, path) {
|
|
336
345
|
return (0, import_jsonpath_plus.JSONPath)({ path, json: obj })[0];
|
|
337
346
|
}
|
|
@@ -646,7 +655,11 @@ var cursorKey = "cursor";
|
|
|
646
655
|
function cursor(value, options2 = {}) {
|
|
647
656
|
return (state) => {
|
|
648
657
|
const { format: format2, ...optionsWithoutFormat } = options2;
|
|
649
|
-
const [resolvedValue, resolvedOptions] = expandReferences(
|
|
658
|
+
const [resolvedValue, resolvedOptions] = expandReferences(
|
|
659
|
+
state,
|
|
660
|
+
value,
|
|
661
|
+
optionsWithoutFormat
|
|
662
|
+
);
|
|
650
663
|
const {
|
|
651
664
|
defaultValue,
|
|
652
665
|
key
|
|
@@ -694,6 +707,7 @@ var src_default = Adaptor_exports;
|
|
|
694
707
|
field,
|
|
695
708
|
fields,
|
|
696
709
|
fn,
|
|
710
|
+
fnIf,
|
|
697
711
|
http,
|
|
698
712
|
humanProper,
|
|
699
713
|
index,
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(Adaptor_exports, {
|
|
|
24
24
|
field: () => field,
|
|
25
25
|
fields: () => fields,
|
|
26
26
|
fn: () => fn,
|
|
27
|
+
fnIf: () => fnIf,
|
|
27
28
|
http: () => http_deprecated_exports,
|
|
28
29
|
humanProper: () => humanProper,
|
|
29
30
|
index: () => index,
|
|
@@ -273,6 +274,12 @@ function fn(func) {
|
|
|
273
274
|
return func(state);
|
|
274
275
|
};
|
|
275
276
|
}
|
|
277
|
+
function fnIf(condition, operation) {
|
|
278
|
+
return (state) => {
|
|
279
|
+
const [resolvedCondition] = expandReferences(state, condition);
|
|
280
|
+
return resolvedCondition ? operation(state) : state;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
276
283
|
function jsonValue(obj, path) {
|
|
277
284
|
return JSONPath({ path, json: obj })[0];
|
|
278
285
|
}
|
|
@@ -587,7 +594,11 @@ var cursorKey = "cursor";
|
|
|
587
594
|
function cursor(value, options2 = {}) {
|
|
588
595
|
return (state) => {
|
|
589
596
|
const { format: format2, ...optionsWithoutFormat } = options2;
|
|
590
|
-
const [resolvedValue, resolvedOptions] = expandReferences(
|
|
597
|
+
const [resolvedValue, resolvedOptions] = expandReferences(
|
|
598
|
+
state,
|
|
599
|
+
value,
|
|
600
|
+
optionsWithoutFormat
|
|
601
|
+
);
|
|
591
602
|
const {
|
|
592
603
|
defaultValue,
|
|
593
604
|
key
|
|
@@ -635,6 +646,7 @@ export {
|
|
|
635
646
|
field,
|
|
636
647
|
fields,
|
|
637
648
|
fn,
|
|
649
|
+
fnIf,
|
|
638
650
|
http_deprecated_exports as http,
|
|
639
651
|
humanProper,
|
|
640
652
|
index,
|
package/dist/util.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
17
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
24
|
|
|
19
25
|
// src/util/index.js
|
|
@@ -38,6 +44,7 @@ module.exports = __toCommonJS(util_exports);
|
|
|
38
44
|
var import_undici = require("undici");
|
|
39
45
|
var import_http_status_codes = require("http-status-codes");
|
|
40
46
|
var import_node_stream = require("stream");
|
|
47
|
+
var import_node_querystring = __toESM(require("querystring"), 1);
|
|
41
48
|
var clients = /* @__PURE__ */ new Map();
|
|
42
49
|
var makeBasicAuthHeader = (username, password) => {
|
|
43
50
|
const buff = Buffer.from(`${username}:${password}`);
|
|
@@ -109,15 +116,21 @@ var parseUrl = (pathOrUrl = "", baseUrl) => {
|
|
|
109
116
|
return {
|
|
110
117
|
url: url.toString(),
|
|
111
118
|
baseUrl: url.origin,
|
|
112
|
-
path: url.pathname
|
|
119
|
+
path: url.pathname,
|
|
120
|
+
query: import_node_querystring.default.parse(url.searchParams.toString())
|
|
113
121
|
};
|
|
114
122
|
};
|
|
115
123
|
async function request(method, fullUrlOrPath, options = {}) {
|
|
116
124
|
const startTime = Date.now();
|
|
117
|
-
const {
|
|
125
|
+
const {
|
|
126
|
+
url,
|
|
127
|
+
baseUrl,
|
|
128
|
+
path,
|
|
129
|
+
query: urlQuery
|
|
130
|
+
} = parseUrl(fullUrlOrPath, options.baseUrl);
|
|
118
131
|
const {
|
|
119
132
|
headers = {},
|
|
120
|
-
query = {},
|
|
133
|
+
query: optionQuery = {},
|
|
121
134
|
body,
|
|
122
135
|
errors = {},
|
|
123
136
|
timeout = 3e5,
|
|
@@ -128,7 +141,10 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
128
141
|
const client = getClient(baseUrl, { tls });
|
|
129
142
|
const response = await client.request({
|
|
130
143
|
path,
|
|
131
|
-
query
|
|
144
|
+
query: {
|
|
145
|
+
...optionQuery,
|
|
146
|
+
...urlQuery
|
|
147
|
+
},
|
|
132
148
|
method,
|
|
133
149
|
headers,
|
|
134
150
|
body: encodeRequestBody(body),
|
package/dist/util.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Client, MockAgent } from "undici";
|
|
3
3
|
import { getReasonPhrase } from "http-status-codes";
|
|
4
4
|
import { Readable } from "stream";
|
|
5
|
+
import querystring from "querystring";
|
|
5
6
|
var clients = /* @__PURE__ */ new Map();
|
|
6
7
|
var makeBasicAuthHeader = (username, password) => {
|
|
7
8
|
const buff = Buffer.from(`${username}:${password}`);
|
|
@@ -73,15 +74,21 @@ var parseUrl = (pathOrUrl = "", baseUrl) => {
|
|
|
73
74
|
return {
|
|
74
75
|
url: url.toString(),
|
|
75
76
|
baseUrl: url.origin,
|
|
76
|
-
path: url.pathname
|
|
77
|
+
path: url.pathname,
|
|
78
|
+
query: querystring.parse(url.searchParams.toString())
|
|
77
79
|
};
|
|
78
80
|
};
|
|
79
81
|
async function request(method, fullUrlOrPath, options = {}) {
|
|
80
82
|
const startTime = Date.now();
|
|
81
|
-
const {
|
|
83
|
+
const {
|
|
84
|
+
url,
|
|
85
|
+
baseUrl,
|
|
86
|
+
path,
|
|
87
|
+
query: urlQuery
|
|
88
|
+
} = parseUrl(fullUrlOrPath, options.baseUrl);
|
|
82
89
|
const {
|
|
83
90
|
headers = {},
|
|
84
|
-
query = {},
|
|
91
|
+
query: optionQuery = {},
|
|
85
92
|
body,
|
|
86
93
|
errors = {},
|
|
87
94
|
timeout = 3e5,
|
|
@@ -92,7 +99,10 @@ async function request(method, fullUrlOrPath, options = {}) {
|
|
|
92
99
|
const client = getClient(baseUrl, { tls });
|
|
93
100
|
const response = await client.request({
|
|
94
101
|
path,
|
|
95
|
-
query
|
|
102
|
+
query: {
|
|
103
|
+
...optionQuery,
|
|
104
|
+
...urlQuery
|
|
105
|
+
},
|
|
96
106
|
method,
|
|
97
107
|
headers,
|
|
98
108
|
body: encodeRequestBody(body),
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -32,6 +32,17 @@ export function alterState(func: Function): Operation;
|
|
|
32
32
|
* @returns {Operation}
|
|
33
33
|
*/
|
|
34
34
|
export function fn(func: Function): Operation;
|
|
35
|
+
/**
|
|
36
|
+
* A custom operation that will only execute the function if the condition returns true
|
|
37
|
+
* @public
|
|
38
|
+
* @example
|
|
39
|
+
* fnIf((state) => state?.data?.name, get("https://example.com"));
|
|
40
|
+
* @function
|
|
41
|
+
* @param {Boolean} condition - The condition that returns true
|
|
42
|
+
* @param {Operation} operation - The operation needed to be executed.
|
|
43
|
+
* @returns {Operation}
|
|
44
|
+
*/
|
|
45
|
+
export function fnIf(condition: boolean, operation: Operation): Operation;
|
|
35
46
|
/**
|
|
36
47
|
* Picks out a single value from a JSON object.
|
|
37
48
|
* If a JSONPath returns more than one value for the reference, the first
|