@lowdefy/operators 3.23.2 → 4.0.0-alpha.6
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/getFromArray.js +22 -44
- package/dist/getFromObject.js +25 -70
- package/dist/index.js +18 -20
- package/dist/nodeParser.js +83 -146
- package/dist/runClass.js +57 -82
- package/dist/runInstance.js +60 -84
- package/dist/webParser.js +94 -157
- package/package.json +13 -19
- package/dist/common/_index.js +0 -45
- package/dist/common/and.js +0 -39
- package/dist/common/args.js +0 -46
- package/dist/common/array.js +0 -170
- package/dist/common/change_case.js +0 -185
- package/dist/common/date.js +0 -75
- package/dist/common/divide.js +0 -51
- package/dist/common/eq.js +0 -43
- package/dist/common/event.js +0 -46
- package/dist/common/function.js +0 -78
- package/dist/common/get.js +0 -61
- package/dist/common/global.js +0 -50
- package/dist/common/gt.js +0 -43
- package/dist/common/gte.js +0 -43
- package/dist/common/if.js +0 -41
- package/dist/common/if_none.js +0 -47
- package/dist/common/index.js +0 -69
- package/dist/common/input.js +0 -50
- package/dist/common/json.js +0 -64
- package/dist/common/log.js +0 -33
- package/dist/common/lt.js +0 -43
- package/dist/common/lte.js +0 -43
- package/dist/common/math.js +0 -210
- package/dist/common/mql.js +0 -124
- package/dist/common/ne.js +0 -43
- package/dist/common/not.js +0 -31
- package/dist/common/number.js +0 -125
- package/dist/common/nunjucks.js +0 -60
- package/dist/common/object.js +0 -118
- package/dist/common/operator.js +0 -49
- package/dist/common/or.js +0 -39
- package/dist/common/product.js +0 -45
- package/dist/common/random.js +0 -132
- package/dist/common/regex.js +0 -65
- package/dist/common/state.js +0 -50
- package/dist/common/string.js +0 -188
- package/dist/common/subtract.js +0 -47
- package/dist/common/sum.js +0 -45
- package/dist/common/switch.js +0 -49
- package/dist/common/type.js +0 -82
- package/dist/common/uri.js +0 -67
- package/dist/common/url_query.js +0 -50
- package/dist/common/user.js +0 -50
- package/dist/common/uuid.js +0 -76
- package/dist/common/yaml.js +0 -70
- package/dist/getFromOtherContext.js +0 -96
- package/dist/node/base64.js +0 -69
- package/dist/node/diff.js +0 -66
- package/dist/node/hash.js +0 -100
- package/dist/node/index.js +0 -29
- package/dist/node/secret.js +0 -54
- package/dist/web/actions.js +0 -46
- package/dist/web/base64.js +0 -67
- package/dist/web/event_log.js +0 -50
- package/dist/web/format.js +0 -52
- package/dist/web/index.js +0 -36
- package/dist/web/js.js +0 -45
- package/dist/web/list_contexts.js +0 -31
- package/dist/web/location.js +0 -74
- package/dist/web/media.js +0 -90
- package/dist/web/menu.js +0 -43
- package/dist/web/request.js +0 -56
- package/dist/web/request_details.js +0 -50
package/dist/getFromArray.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,41 +12,28 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
function getFromArray(
|
|
26
|
-
|
|
27
|
-
params
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
operator,
|
|
31
|
-
location
|
|
32
|
-
} = _ref;
|
|
33
|
-
if (params === true) return array;
|
|
34
|
-
|
|
35
|
-
if (_helpers.type.isString(params)) {
|
|
36
|
-
return array.find(item => item[key] === params);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (_helpers.type.isNumber(params)) {
|
|
40
|
-
return array[params];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (_helpers.type.isObject(params)) {
|
|
44
|
-
if (params.all === true) return array;
|
|
45
|
-
if (_helpers.type.isString(params.value)) return array.find(item => item[key] === params.value);
|
|
46
|
-
if (_helpers.type.isNumber(params.index)) return array[params.index];
|
|
47
|
-
|
|
48
|
-
if (!_helpers.type.isNone(params.value) && !_helpers.type.isString(params.value)) {
|
|
49
|
-
throw new Error("Operator Error: ".concat(operator, ".value must be of type string. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
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
|
+
);
|
|
50
21
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw new Error("Operator Error: ".concat(operator, ".index must be of type number. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
22
|
+
if (type.isNumber(params)) {
|
|
23
|
+
return array[params];
|
|
54
24
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
25
|
+
if (type.isObject(params)) {
|
|
26
|
+
if (params.all === true) return array;
|
|
27
|
+
if (type.isString(params.value)) return array.find((item)=>item[key] === params.value
|
|
28
|
+
);
|
|
29
|
+
if (type.isNumber(params.index)) return array[params.index];
|
|
30
|
+
if (!type.isNone(params.value) && !type.isString(params.value)) {
|
|
31
|
+
throw new Error(`Operator Error: ${operator}.value must be of type string. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
32
|
+
}
|
|
33
|
+
if (!type.isNone(params.index) && !type.isNumber(params.index)) {
|
|
34
|
+
throw new Error(`Operator Error: ${operator}.index must be of type number. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Operator Error: ${operator} must be of type string, number or object. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
58
38
|
}
|
|
59
|
-
|
|
60
|
-
var _default = getFromArray;
|
|
61
|
-
exports.default = _default;
|
|
39
|
+
export default getFromArray;
|
package/dist/getFromObject.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
|
-
var _getFromOtherContext = _interopRequireDefault(require("./getFromOtherContext"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
1
|
/*
|
|
15
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
16
3
|
|
|
@@ -25,63 +12,31 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
13
|
See the License for the specific language governing permissions and
|
|
27
14
|
limitations under the License.
|
|
28
|
-
*/
|
|
29
|
-
function getFromObject(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
env
|
|
39
|
-
} = _ref;
|
|
40
|
-
if (params === true) params = {
|
|
41
|
-
all: true
|
|
42
|
-
};
|
|
43
|
-
if (_helpers.type.isString(params) || _helpers.type.isInt(params)) params = {
|
|
44
|
-
key: params
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
if (!_helpers.type.isObject(params)) {
|
|
48
|
-
throw new Error("Operator Error: ".concat(operator, " params must be of type string, integer, boolean or object. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (params.key === null) return (0, _helpers.get)(params, 'default', {
|
|
52
|
-
default: null,
|
|
53
|
-
copy: true
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
if (params.contextId) {
|
|
57
|
-
if (env === 'node') {
|
|
58
|
-
throw new Error("Operator Error: Accessing a context using contextId is only available in a client environment. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
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}.`);
|
|
59
25
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
68
40
|
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (params.all === true) return _helpers.serializer.copy(object);
|
|
72
|
-
|
|
73
|
-
if (!_helpers.type.isString(params.key) && !_helpers.type.isInt(params.key)) {
|
|
74
|
-
throw new Error("Operator Error: ".concat(operator, ".key must be of type string or integer. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (0, _helpers.get)(object, (0, _helpers.applyArrayIndices)(arrayIndices, params.key), {
|
|
78
|
-
default: (0, _helpers.get)(params, 'default', {
|
|
79
|
-
default: null,
|
|
80
|
-
copy: true
|
|
81
|
-
}),
|
|
82
|
-
copy: true
|
|
83
|
-
});
|
|
84
41
|
}
|
|
85
|
-
|
|
86
|
-
var _default = getFromObject;
|
|
87
|
-
exports.default = _default;
|
|
42
|
+
export default getFromObject;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "NodeParser", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _nodeParser.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "WebParser", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _webParser.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
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
|
|
18
7
|
|
|
19
|
-
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
20
9
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
CHANGED
|
@@ -1,149 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
|
-
class NodeParser {
|
|
27
|
-
constructor() {
|
|
28
|
-
var {
|
|
29
|
-
arrayIndices,
|
|
30
|
-
input,
|
|
31
|
-
lowdefyGlobal,
|
|
32
|
-
secrets,
|
|
33
|
-
state,
|
|
34
|
-
urlQuery,
|
|
35
|
-
user
|
|
36
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
|
-
this.arrayIndices = arrayIndices;
|
|
38
|
-
this.input = input;
|
|
39
|
-
this.lowdefyGlobal = lowdefyGlobal;
|
|
40
|
-
this.secrets = secrets;
|
|
41
|
-
this.state = state;
|
|
42
|
-
this.urlQuery = urlQuery;
|
|
43
|
-
this.user = user;
|
|
44
|
-
this.parse = this.parse.bind(this);
|
|
45
|
-
this.operators = _objectSpread(_objectSpread({}, _common.default), _node.default);
|
|
46
|
-
this.operations = {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
init() {
|
|
50
|
-
var _this = this;
|
|
51
|
-
|
|
52
|
-
return _asyncToGenerator(function* () {
|
|
53
|
-
yield Promise.all(Object.keys(_this.operators).map( /*#__PURE__*/function () {
|
|
54
|
-
var _ref = _asyncToGenerator(function* (operator) {
|
|
55
|
-
var fn = require("./".concat(_this.operators[operator], ".js"));
|
|
56
|
-
|
|
57
|
-
_this.operations[operator] = fn.default;
|
|
58
|
-
|
|
59
|
-
if (_this.operations[operator].init) {
|
|
60
|
-
yield _this.operations[operator].init();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return function (_x) {
|
|
65
|
-
return _ref.apply(this, arguments);
|
|
66
|
-
};
|
|
67
|
-
}()));
|
|
68
|
-
})();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
parse(_ref2) {
|
|
72
|
-
var {
|
|
73
|
-
actions,
|
|
74
|
-
args,
|
|
75
|
-
event,
|
|
76
|
-
input,
|
|
77
|
-
location
|
|
78
|
-
} = _ref2;
|
|
79
|
-
|
|
80
|
-
if (_helpers.type.isUndefined(input)) {
|
|
81
|
-
return {
|
|
82
|
-
output: input,
|
|
83
|
-
errors: []
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (event && !_helpers.type.isObject(event)) {
|
|
88
|
-
throw new Error('Operator parser event must be a object.');
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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
|
+
async init() {
|
|
18
|
+
await Promise.all(Object.values(this.operators).map(async (operator)=>{
|
|
19
|
+
if (operator.init) {
|
|
20
|
+
await operator.init();
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
89
23
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
24
|
+
parse({ args , input , location }) {
|
|
25
|
+
const operators = this.operators;
|
|
26
|
+
const secrets = this.secrets;
|
|
27
|
+
const payload = this.payload;
|
|
28
|
+
const user = this.user;
|
|
29
|
+
if (type.isUndefined(input)) {
|
|
30
|
+
return {
|
|
31
|
+
output: input,
|
|
32
|
+
errors: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (args && !type.isArray(args)) {
|
|
36
|
+
throw new Error('Operator parser args must be an array.');
|
|
37
|
+
}
|
|
38
|
+
if (!type.isString(location)) {
|
|
39
|
+
throw new Error('Operator parser location must be a string.');
|
|
40
|
+
}
|
|
41
|
+
const errors = [];
|
|
42
|
+
const reviver = (_, value)=>{
|
|
43
|
+
if (type.isObject(value) && Object.keys(value).length === 1) {
|
|
44
|
+
const key = Object.keys(value)[0];
|
|
45
|
+
const [op, methodName] = key.split('.');
|
|
46
|
+
try {
|
|
47
|
+
if (!type.isUndefined(operators[op])) {
|
|
48
|
+
const res = operators[op]({
|
|
49
|
+
args,
|
|
50
|
+
arrayIndices: [],
|
|
51
|
+
env: 'node',
|
|
52
|
+
location,
|
|
53
|
+
methodName,
|
|
54
|
+
operators: operators,
|
|
55
|
+
params: value[key],
|
|
56
|
+
secrets,
|
|
57
|
+
payload,
|
|
58
|
+
user,
|
|
59
|
+
parser: this
|
|
60
|
+
});
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
errors.push(e);
|
|
65
|
+
console.error(e);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
output: serializer.copy(input, {
|
|
73
|
+
reviver
|
|
74
|
+
}),
|
|
75
|
+
errors
|
|
76
|
+
};
|
|
93
77
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
constructor({ payload , secrets , user , operators }){
|
|
79
|
+
this.operators = operators;
|
|
80
|
+
this.payload = payload;
|
|
81
|
+
this.secrets = secrets;
|
|
82
|
+
this.user = user;
|
|
83
|
+
this.parse = this.parse.bind(this);
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var reviver = (_, value) => {
|
|
102
|
-
if (_helpers.type.isObject(value) && Object.keys(value).length === 1) {
|
|
103
|
-
var key = Object.keys(value)[0];
|
|
104
|
-
var [op, methodName] = key.split('.');
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
if (!_helpers.type.isUndefined(this.operations[op])) {
|
|
108
|
-
var res = this.operations[op]({
|
|
109
|
-
actions,
|
|
110
|
-
args,
|
|
111
|
-
arrayIndices: this.arrayIndices,
|
|
112
|
-
env: 'node',
|
|
113
|
-
event,
|
|
114
|
-
input: this.input,
|
|
115
|
-
location,
|
|
116
|
-
lowdefyGlobal: this.lowdefyGlobal,
|
|
117
|
-
methodName,
|
|
118
|
-
operations: this.operations,
|
|
119
|
-
params: value[key],
|
|
120
|
-
secrets: this.secrets,
|
|
121
|
-
state: this.state,
|
|
122
|
-
urlQuery: this.urlQuery,
|
|
123
|
-
user: this.user,
|
|
124
|
-
parser: this
|
|
125
|
-
});
|
|
126
|
-
return res;
|
|
127
|
-
}
|
|
128
|
-
} catch (e) {
|
|
129
|
-
errors.push(e);
|
|
130
|
-
console.error(e);
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return value;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
output: _helpers.serializer.copy(input, {
|
|
140
|
-
reviver
|
|
141
|
-
}),
|
|
142
|
-
errors
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var _default = NodeParser;
|
|
149
|
-
exports.default = _default;
|
|
85
|
+
};
|
|
86
|
+
export default NodeParser;
|
package/dist/runClass.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,82 +12,66 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
methodName
|
|
39
|
-
}
|
|
40
|
-
|
|
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
|
+
];
|
|
41
48
|
} else {
|
|
42
|
-
|
|
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
|
+
));
|
|
55
|
+
if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
|
|
56
|
+
throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
|
|
57
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
58
|
+
}
|
|
59
|
+
args.push(...params[meta[methodName].spreadArgs] || []);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} // validate params type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(_helpers.type.typeOf(params))) {
|
|
52
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " accepts one of the following types: ").concat(meta[methodName].validTypes.join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (meta[methodName].noArgs) {
|
|
56
|
-
try {
|
|
57
|
-
return functions[methodName]();
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new Error("Operator Error: ".concat(operator, ": - ").concat(e.message, " Received: {\"").concat(operator, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
62
|
+
if (type.isFunction(meta[methodName].prep)) {
|
|
63
|
+
args = meta[methodName].prep(args, {
|
|
64
|
+
location
|
|
65
|
+
});
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
66
|
-
args = [params];
|
|
67
|
-
} else {
|
|
68
|
-
if (_helpers.type.isArray(params)) {
|
|
69
|
-
args = params;
|
|
67
|
+
// for property
|
|
68
|
+
if (meta[methodName].property) {
|
|
69
|
+
return functions[methodName];
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!_helpers.type.isNone(meta[methodName].spreadArgs) && !_helpers.type.isArray(params[meta[methodName].spreadArgs])) {
|
|
76
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " takes an array as input argument for ").concat(meta[methodName].spreadArgs, ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
args.push(...(params[meta[methodName].spreadArgs] || []));
|
|
71
|
+
try {
|
|
72
|
+
return functions[methodName](...args);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
80
75
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (_helpers.type.isFunction(meta[methodName].prep)) {
|
|
84
|
-
args = meta[methodName].prep(args, {
|
|
85
|
-
location
|
|
86
|
-
});
|
|
87
|
-
} // for property
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (meta[methodName].property) {
|
|
91
|
-
return functions[methodName];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
return functions[methodName](...args);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " - ").concat(e.message, " Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
98
|
-
}
|
|
99
76
|
};
|
|
100
|
-
|
|
101
|
-
var _default = runClass;
|
|
102
|
-
exports.default = _default;
|
|
77
|
+
export default runClass;
|