@lowdefy/operators 4.0.0-alpha.26 → 4.0.0-alpha.29
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/package.json +5 -6
- package/dist/getFromArray.js +0 -37
- package/dist/getFromObject.js +0 -42
- package/dist/index.js +0 -21
- package/dist/nodeParser.js +0 -81
- package/dist/runClass.js +0 -76
- package/dist/runInstance.js +0 -76
- package/dist/webParser.js +0 -86
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,15 +34,14 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "
|
|
37
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
38
38
|
"clean": "rm -rf dist",
|
|
39
|
-
"
|
|
40
|
-
"swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
39
|
+
"prepublishOnly": "pnpm build",
|
|
41
40
|
"test": "jest --coverage --testTimeout=10000",
|
|
42
41
|
"test:watch": "jest --coverage --watch"
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
44
|
+
"@lowdefy/helpers": "4.0.0-alpha.29"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@swc/cli": "0.1.57",
|
|
@@ -54,5 +53,5 @@
|
|
|
54
53
|
"publishConfig": {
|
|
55
54
|
"access": "public"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
|
|
58
57
|
}
|
package/dist/getFromArray.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
function getFromArray({ params , array , key , operator , location }) {
|
|
17
|
-
if (params === true) return array;
|
|
18
|
-
if (type.isString(params)) {
|
|
19
|
-
return array.find((item)=>item[key] === params);
|
|
20
|
-
}
|
|
21
|
-
if (type.isNumber(params)) {
|
|
22
|
-
return array[params];
|
|
23
|
-
}
|
|
24
|
-
if (type.isObject(params)) {
|
|
25
|
-
if (params.all === true) return array;
|
|
26
|
-
if (type.isString(params.value)) return array.find((item)=>item[key] === params.value);
|
|
27
|
-
if (type.isNumber(params.index)) return array[params.index];
|
|
28
|
-
if (!type.isNone(params.value) && !type.isString(params.value)) {
|
|
29
|
-
throw new Error(`Operator Error: ${operator}.value must be of type string. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
30
|
-
}
|
|
31
|
-
if (!type.isNone(params.index) && !type.isNumber(params.index)) {
|
|
32
|
-
throw new Error(`Operator Error: ${operator}.index must be of type number. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw new Error(`Operator Error: ${operator} must be of type string, number or object. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
36
|
-
}
|
|
37
|
-
export default getFromArray;
|
package/dist/getFromObject.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
|
|
16
|
-
function getFromObject({ params , object , arrayIndices , operator , location }) {
|
|
17
|
-
if (params === true) params = {
|
|
18
|
-
all: true
|
|
19
|
-
};
|
|
20
|
-
if (type.isString(params) || type.isInt(params)) params = {
|
|
21
|
-
key: params
|
|
22
|
-
};
|
|
23
|
-
if (!type.isObject(params)) {
|
|
24
|
-
throw new Error(`Operator Error: ${operator} params must be of type string, integer, boolean or object. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
25
|
-
}
|
|
26
|
-
if (params.key === null) return get(params, 'default', {
|
|
27
|
-
default: null,
|
|
28
|
-
copy: true
|
|
29
|
-
});
|
|
30
|
-
if (params.all === true) return serializer.copy(object);
|
|
31
|
-
if (!type.isString(params.key) && !type.isInt(params.key)) {
|
|
32
|
-
throw new Error(`Operator Error: ${operator}.key must be of type string or integer. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
33
|
-
}
|
|
34
|
-
return get(object, applyArrayIndices(arrayIndices, params.key), {
|
|
35
|
-
default: get(params, 'default', {
|
|
36
|
-
default: null,
|
|
37
|
-
copy: true
|
|
38
|
-
}),
|
|
39
|
-
copy: true
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
export default getFromObject;
|
package/dist/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import getFromArray from './getFromArray.js';
|
|
16
|
-
import getFromObject from './getFromObject.js';
|
|
17
|
-
import NodeParser from './nodeParser.js';
|
|
18
|
-
import runClass from './runClass.js';
|
|
19
|
-
import runInstance from './runInstance.js';
|
|
20
|
-
import WebParser from './webParser.js';
|
|
21
|
-
export { getFromArray, getFromObject, NodeParser, runClass, runInstance, WebParser };
|
package/dist/nodeParser.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { serializer, type } from '@lowdefy/helpers';
|
|
16
|
-
let NodeParser = class NodeParser {
|
|
17
|
-
// TODO: Look at logging here
|
|
18
|
-
// TODO: Remove console.error = () => {}; from tests
|
|
19
|
-
parse({ args , input , location , operatorPrefix ='_' }) {
|
|
20
|
-
if (type.isUndefined(input)) {
|
|
21
|
-
return {
|
|
22
|
-
output: input,
|
|
23
|
-
errors: []
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (args && !type.isArray(args)) {
|
|
27
|
-
throw new Error('Operator parser args must be an array.');
|
|
28
|
-
}
|
|
29
|
-
if (!type.isString(location)) {
|
|
30
|
-
throw new Error('Operator parser location must be a string.');
|
|
31
|
-
}
|
|
32
|
-
const errors = [];
|
|
33
|
-
const reviver = (_, value)=>{
|
|
34
|
-
if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
|
|
35
|
-
const key = Object.keys(value)[0];
|
|
36
|
-
if (!key.startsWith(operatorPrefix)) return value;
|
|
37
|
-
const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
|
|
38
|
-
if (type.isUndefined(this.operators[op])) return value;
|
|
39
|
-
try {
|
|
40
|
-
const res = this.operators[op]({
|
|
41
|
-
args,
|
|
42
|
-
arrayIndices: [],
|
|
43
|
-
env: this.env,
|
|
44
|
-
location,
|
|
45
|
-
methodName,
|
|
46
|
-
operators: this.operators,
|
|
47
|
-
params: value[key],
|
|
48
|
-
operatorPrefix,
|
|
49
|
-
parser: this,
|
|
50
|
-
payload: this.payload,
|
|
51
|
-
runtime: 'node',
|
|
52
|
-
secrets: this.secrets,
|
|
53
|
-
user: this.user
|
|
54
|
-
});
|
|
55
|
-
return res;
|
|
56
|
-
} catch (e) {
|
|
57
|
-
errors.push(e);
|
|
58
|
-
if (this.verbose) {
|
|
59
|
-
console.error(e);
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
output: serializer.copy(input, {
|
|
66
|
-
reviver
|
|
67
|
-
}),
|
|
68
|
-
errors
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
constructor({ env , payload , secrets , user , operators , verbose }){
|
|
72
|
-
this.env = env;
|
|
73
|
-
this.operators = operators;
|
|
74
|
-
this.payload = payload;
|
|
75
|
-
this.secrets = secrets;
|
|
76
|
-
this.user = user;
|
|
77
|
-
this.parse = this.parse.bind(this);
|
|
78
|
-
this.verbose;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
export default NodeParser;
|
package/dist/runClass.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
const runClass = ({ location , meta , methodName , operator , params , functions , defaultFunction })=>{
|
|
17
|
-
if (!methodName) {
|
|
18
|
-
if (meta[params]) {
|
|
19
|
-
methodName = params;
|
|
20
|
-
} else if (defaultFunction) {
|
|
21
|
-
methodName = defaultFunction;
|
|
22
|
-
} else {
|
|
23
|
-
throw new Error(`Operator Error: ${operator} requires a valid method name, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
24
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!meta[methodName] && !functions[methodName]) {
|
|
28
|
-
throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
29
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
30
|
-
}
|
|
31
|
-
// validate params type
|
|
32
|
-
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
|
|
33
|
-
throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
|
|
34
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
35
|
-
}
|
|
36
|
-
if (meta[methodName].noArgs) {
|
|
37
|
-
try {
|
|
38
|
-
return functions[methodName]();
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw new Error(`Operator Error: ${operator}: - ${e.message} Received: {"${operator}":${JSON.stringify(params)}} at ${location}.`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let args = [];
|
|
44
|
-
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
45
|
-
args = [
|
|
46
|
-
params
|
|
47
|
-
];
|
|
48
|
-
} else {
|
|
49
|
-
if (type.isArray(params)) {
|
|
50
|
-
args = params;
|
|
51
|
-
}
|
|
52
|
-
if (type.isObject(params)) {
|
|
53
|
-
args.push(...(meta[methodName].namedArgs || []).map((key)=>params[key]));
|
|
54
|
-
if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
|
|
55
|
-
throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
|
|
56
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
57
|
-
}
|
|
58
|
-
args.push(...params[meta[methodName].spreadArgs] || []);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (type.isFunction(meta[methodName].prep)) {
|
|
62
|
-
args = meta[methodName].prep(args, {
|
|
63
|
-
location
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
// for property
|
|
67
|
-
if (meta[methodName].property) {
|
|
68
|
-
return functions[methodName];
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
return functions[methodName](...args);
|
|
72
|
-
} catch (e) {
|
|
73
|
-
throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
export default runClass;
|
package/dist/runInstance.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
const runInstance = ({ location , meta , methodName , operator , params , instanceType })=>{
|
|
17
|
-
if (!meta[methodName]) {
|
|
18
|
-
throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
19
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
20
|
-
}
|
|
21
|
-
// validate params type
|
|
22
|
-
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
|
|
23
|
-
throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
|
|
24
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
25
|
-
}
|
|
26
|
-
let instance;
|
|
27
|
-
let args = [];
|
|
28
|
-
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
29
|
-
instance = params;
|
|
30
|
-
} else {
|
|
31
|
-
if (type.isArray(params)) {
|
|
32
|
-
// Instance must be zero in list args.
|
|
33
|
-
instance = params[0];
|
|
34
|
-
args = params.slice(1);
|
|
35
|
-
}
|
|
36
|
-
// Instance must be listed first in named args.
|
|
37
|
-
if (type.isObject(params)) {
|
|
38
|
-
instance = params[meta[methodName].namedArgs[0]];
|
|
39
|
-
args.push(...meta[methodName].namedArgs.slice(1).map((key)=>params[key]));
|
|
40
|
-
if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
|
|
41
|
-
throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
|
|
42
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
43
|
-
}
|
|
44
|
-
args.push(...params[meta[methodName].spreadArgs] || []);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (type.isFunction(meta[methodName].prep)) {
|
|
48
|
-
[instance, ...args] = meta[methodName].prep([
|
|
49
|
-
instance,
|
|
50
|
-
...args
|
|
51
|
-
]);
|
|
52
|
-
}
|
|
53
|
-
if (type.typeOf(instance) !== instanceType) {
|
|
54
|
-
throw new Error(`Operator Error: ${operator}.${methodName} must be evaluated on an ${instanceType} instance. For named args provide an ${instanceType} instance to the "on" property, for listed args provide and ${instanceType} instance as the first element in the operator argument array.
|
|
55
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
56
|
-
}
|
|
57
|
-
// Error for invalid method key.
|
|
58
|
-
if (type.isNone(instance[methodName])) {
|
|
59
|
-
throw new Error(`Operator Error: ${operator} must be evaluated using one of the following: ${Object.keys(meta).join(', ')}.
|
|
60
|
-
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
61
|
-
}
|
|
62
|
-
// for property
|
|
63
|
-
if (meta[methodName].property) {
|
|
64
|
-
return instance[methodName];
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
const result = instance[methodName](...args);
|
|
68
|
-
if (meta[methodName].returnInstance) {
|
|
69
|
-
return instance;
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
} catch (e) {
|
|
73
|
-
throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
export default runInstance;
|
package/dist/webParser.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
|
|
16
|
-
let WebParser = class WebParser {
|
|
17
|
-
parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
|
|
18
|
-
if (type.isUndefined(input)) {
|
|
19
|
-
return {
|
|
20
|
-
output: input,
|
|
21
|
-
errors: []
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
if (event && !type.isObject(event)) {
|
|
25
|
-
throw new Error('Operator parser event must be a object.');
|
|
26
|
-
}
|
|
27
|
-
if (args && !type.isArray(args)) {
|
|
28
|
-
throw new Error('Operator parser args must be an array.');
|
|
29
|
-
}
|
|
30
|
-
if (!type.isString(location)) {
|
|
31
|
-
throw new Error('Operator parser location must be a string.');
|
|
32
|
-
}
|
|
33
|
-
const errors = [];
|
|
34
|
-
const { basePath , home , inputs , lowdefyGlobal , menus , pageId , user , _internal } = this.context._internal.lowdefy;
|
|
35
|
-
const reviver = (_, value)=>{
|
|
36
|
-
if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
|
|
37
|
-
const key = Object.keys(value)[0];
|
|
38
|
-
if (!key.startsWith(operatorPrefix)) return value;
|
|
39
|
-
const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
|
|
40
|
-
if (type.isUndefined(this.operators[op])) return value;
|
|
41
|
-
try {
|
|
42
|
-
const res = this.operators[op]({
|
|
43
|
-
actions,
|
|
44
|
-
args,
|
|
45
|
-
arrayIndices,
|
|
46
|
-
basePath,
|
|
47
|
-
event,
|
|
48
|
-
eventLog: this.context.eventLog,
|
|
49
|
-
globals: _internal.globals,
|
|
50
|
-
home,
|
|
51
|
-
input: inputs ? inputs[this.context.id] : {},
|
|
52
|
-
location: applyArrayIndices(arrayIndices, location),
|
|
53
|
-
lowdefyGlobal: lowdefyGlobal ?? {},
|
|
54
|
-
menus: menus ?? [],
|
|
55
|
-
methodName,
|
|
56
|
-
operatorPrefix,
|
|
57
|
-
operators: this.operators,
|
|
58
|
-
pageId,
|
|
59
|
-
params: value[key],
|
|
60
|
-
parser: this,
|
|
61
|
-
requests: this.context.requests,
|
|
62
|
-
runtime: 'browser',
|
|
63
|
-
state: this.context.state,
|
|
64
|
-
user: user ?? {}
|
|
65
|
-
});
|
|
66
|
-
return res;
|
|
67
|
-
} catch (e) {
|
|
68
|
-
errors.push(e);
|
|
69
|
-
console.error(e);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
output: serializer.copy(input, {
|
|
75
|
-
reviver
|
|
76
|
-
}),
|
|
77
|
-
errors
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
constructor({ context , operators }){
|
|
81
|
-
this.context = context;
|
|
82
|
-
this.operators = operators;
|
|
83
|
-
this.parse = this.parse.bind(this);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
export default WebParser;
|