@lowdefy/operators-js 5.1.0 → 5.3.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/dist/operators/client/api.js +4 -3
- package/dist/operators/client/js.js +9 -5
- package/dist/operators/client/js.schema.js +22 -2
- package/dist/operators/client/request.js +4 -3
- package/dist/operators/server/js.js +9 -5
- package/dist/operators/server/js.schema.js +22 -2
- package/dist/operators/shared/function.js +4 -2
- package/dist/operators/shared/string.js +31 -0
- package/dist/operators/shared/string.schema.js +1 -1
- package/package.json +4 -4
|
@@ -19,12 +19,13 @@ function _api({ params, apiResponses }) {
|
|
|
19
19
|
}
|
|
20
20
|
const splitKey = params.split('.');
|
|
21
21
|
const [endpoint, ...keyParts] = splitKey;
|
|
22
|
-
|
|
22
|
+
const entry = apiResponses[endpoint]?.[0];
|
|
23
|
+
if (entry && (!entry.loading || entry.holdValue)) {
|
|
23
24
|
if (splitKey.length === 1) {
|
|
24
|
-
return
|
|
25
|
+
return entry;
|
|
25
26
|
}
|
|
26
27
|
const key = keyParts.join('.');
|
|
27
|
-
return get(
|
|
28
|
+
return get(entry, key, {
|
|
28
29
|
copy: true,
|
|
29
30
|
default: null
|
|
30
31
|
});
|
|
@@ -12,17 +12,21 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function js(operatorContext) {
|
|
16
17
|
const { jsMap, operators, params } = operatorContext;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const hash = type.isString(params) ? params : params?.fn;
|
|
19
|
+
const args = type.isObject(params) ? params.args : undefined;
|
|
20
|
+
if (!jsMap[hash]) {
|
|
21
|
+
throw new Error(`_js function not found. The function may not have been built yet. Received hash: ${hash}`);
|
|
19
22
|
}
|
|
20
23
|
try {
|
|
21
|
-
return jsMap[
|
|
24
|
+
return jsMap[hash]({
|
|
22
25
|
actions: (p)=>operators._actions({
|
|
23
26
|
...operatorContext,
|
|
24
27
|
params: p
|
|
25
28
|
}),
|
|
29
|
+
args,
|
|
26
30
|
event: (p)=>operators._event({
|
|
27
31
|
...operatorContext,
|
|
28
32
|
params: p
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
})
|
|
58
62
|
});
|
|
59
63
|
} catch (error) {
|
|
60
|
-
throw new Error(`_js function execution error. Function: ${jsMap[
|
|
64
|
+
throw new Error(`_js function execution error. Function: ${jsMap[hash].toString()}`, {
|
|
61
65
|
cause: error
|
|
62
66
|
});
|
|
63
67
|
}
|
|
@@ -15,7 +15,27 @@
|
|
|
15
15
|
*/ export default {
|
|
16
16
|
type: 'object',
|
|
17
17
|
params: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
oneOf: [
|
|
19
|
+
{
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Hash identifier of the pre-built JavaScript function to execute.'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: [
|
|
26
|
+
'fn'
|
|
27
|
+
],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
fn: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Hash identifier of the pre-built JavaScript function to execute.'
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
description: 'Pre-resolved values injected into the JavaScript function as `args`.'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
20
40
|
}
|
|
21
41
|
};
|
|
@@ -19,12 +19,13 @@ function _request({ arrayIndices, params, requests }) {
|
|
|
19
19
|
}
|
|
20
20
|
const splitKey = params.split('.');
|
|
21
21
|
const [requestId, ...keyParts] = splitKey;
|
|
22
|
-
|
|
22
|
+
const entry = requests[requestId]?.[0];
|
|
23
|
+
if (entry && (!entry.loading || entry.holdValue)) {
|
|
23
24
|
if (splitKey.length === 1) {
|
|
24
|
-
return serializer.copy(
|
|
25
|
+
return serializer.copy(entry.response);
|
|
25
26
|
}
|
|
26
27
|
const key = keyParts.reduce((acc, value)=>acc === '' ? value : acc.concat('.', value), '');
|
|
27
|
-
return get(
|
|
28
|
+
return get(entry.response, applyArrayIndices(arrayIndices, key), {
|
|
28
29
|
copy: true,
|
|
29
30
|
default: null
|
|
30
31
|
});
|
|
@@ -12,13 +12,17 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function js(operatorContext) {
|
|
16
17
|
const { jsMap, operators, location, params } = operatorContext;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const hash = type.isString(params) ? params : params?.fn;
|
|
19
|
+
const args = type.isObject(params) ? params.args : undefined;
|
|
20
|
+
if (!jsMap[hash]) {
|
|
21
|
+
throw new Error(`_js function not found. The function may not have been built yet. Received hash: ${hash}`);
|
|
19
22
|
}
|
|
20
23
|
try {
|
|
21
|
-
return jsMap[
|
|
24
|
+
return jsMap[hash]({
|
|
25
|
+
args,
|
|
22
26
|
payload: (p)=>operators._payload({
|
|
23
27
|
...operatorContext,
|
|
24
28
|
params: p
|
|
@@ -45,7 +49,7 @@
|
|
|
45
49
|
})
|
|
46
50
|
});
|
|
47
51
|
} catch (error) {
|
|
48
|
-
throw new Error(`_js function execution error. Function: ${jsMap[
|
|
52
|
+
throw new Error(`_js function execution error. Function: ${jsMap[hash].toString()}`, {
|
|
49
53
|
cause: error
|
|
50
54
|
});
|
|
51
55
|
}
|
|
@@ -15,7 +15,27 @@
|
|
|
15
15
|
*/ export default {
|
|
16
16
|
type: 'object',
|
|
17
17
|
params: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
oneOf: [
|
|
19
|
+
{
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Hash identifier of the pre-built JavaScript function to execute.'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: [
|
|
26
|
+
'fn'
|
|
27
|
+
],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
fn: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Hash identifier of the pre-built JavaScript function to execute.'
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
description: 'Pre-resolved values injected into the JavaScript function as `args`.'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
20
40
|
}
|
|
21
41
|
};
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
-
function _function({ actions, arrayIndices, event, location, operatorPrefix, params, parser }) {
|
|
16
|
+
function _function({ actions, arrayIndices, event, location, operatorPrefix, params, parser, payload, steps }) {
|
|
17
17
|
return (...args)=>{
|
|
18
18
|
const { output, errors } = parser.parse({
|
|
19
19
|
actions,
|
|
@@ -22,7 +22,9 @@ function _function({ actions, arrayIndices, event, location, operatorPrefix, par
|
|
|
22
22
|
event,
|
|
23
23
|
input: serializer.copy(params),
|
|
24
24
|
location,
|
|
25
|
-
operatorPrefix: `_${operatorPrefix}
|
|
25
|
+
operatorPrefix: `_${operatorPrefix}`,
|
|
26
|
+
payload,
|
|
27
|
+
steps
|
|
26
28
|
});
|
|
27
29
|
if (errors.length > 0) {
|
|
28
30
|
throw errors[0];
|
|
@@ -279,7 +279,38 @@ const meta = {
|
|
|
279
279
|
prep
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
|
+
function runFormat({ params, location }) {
|
|
283
|
+
let template;
|
|
284
|
+
let lookup;
|
|
285
|
+
if (type.isArray(params)) {
|
|
286
|
+
if (!type.isString(params[0])) {
|
|
287
|
+
throw new Error(`Operator Error: _string.format - first array element must be the template string at ${location}.`);
|
|
288
|
+
}
|
|
289
|
+
template = params[0];
|
|
290
|
+
const values = params.slice(1);
|
|
291
|
+
lookup = (key)=>values[Number(key)];
|
|
292
|
+
} else if (type.isObject(params)) {
|
|
293
|
+
if (!type.isString(params.template)) {
|
|
294
|
+
throw new Error(`Operator Error: _string.format - "template" must be a string at ${location}.`);
|
|
295
|
+
}
|
|
296
|
+
template = params.template;
|
|
297
|
+
const on = params.on ?? {};
|
|
298
|
+
lookup = (key)=>on[key];
|
|
299
|
+
} else {
|
|
300
|
+
throw new Error(`Operator Error: _string.format accepts an array or object at ${location}.`);
|
|
301
|
+
}
|
|
302
|
+
return template.replace(/\{\{|\}\}|\{(\w+)\}/g, (match, key)=>{
|
|
303
|
+
if (match === '{{') return '{';
|
|
304
|
+
if (match === '}}') return '}';
|
|
305
|
+
const v = lookup(key);
|
|
306
|
+
return type.isNone(v) ? '' : String(v);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
282
309
|
function _string({ params, location, methodName }) {
|
|
310
|
+
if (methodName === 'format') return runFormat({
|
|
311
|
+
params,
|
|
312
|
+
location
|
|
313
|
+
});
|
|
283
314
|
return runInstance({
|
|
284
315
|
location,
|
|
285
316
|
meta,
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
*/ export default {
|
|
16
16
|
type: 'object',
|
|
17
17
|
params: {
|
|
18
|
-
description: 'String method params. Accepts array positional args or object with named args depending on method.'
|
|
18
|
+
description: 'String method params. Accepts array positional args or object with named args depending on method. The "format" method takes a template string with {0}/{1} positional placeholders (array form) or {name} placeholders (object form: { template, on }).'
|
|
19
19
|
}
|
|
20
20
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators-js",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"dist/*"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lowdefy/helpers": "5.
|
|
47
|
-
"@lowdefy/operators": "5.
|
|
46
|
+
"@lowdefy/helpers": "5.3.0",
|
|
47
|
+
"@lowdefy/operators": "5.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@jest/globals": "28.1.3",
|
|
51
|
-
"@lowdefy/node-utils": "5.
|
|
51
|
+
"@lowdefy/node-utils": "5.3.0",
|
|
52
52
|
"@swc/cli": "0.8.0",
|
|
53
53
|
"@swc/core": "1.15.18",
|
|
54
54
|
"@swc/jest": "0.2.39",
|