@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.
Files changed (71) hide show
  1. package/dist/getFromArray.js +22 -44
  2. package/dist/getFromObject.js +25 -70
  3. package/dist/index.js +18 -20
  4. package/dist/nodeParser.js +83 -146
  5. package/dist/runClass.js +57 -82
  6. package/dist/runInstance.js +60 -84
  7. package/dist/webParser.js +94 -157
  8. package/package.json +13 -19
  9. package/dist/common/_index.js +0 -45
  10. package/dist/common/and.js +0 -39
  11. package/dist/common/args.js +0 -46
  12. package/dist/common/array.js +0 -170
  13. package/dist/common/change_case.js +0 -185
  14. package/dist/common/date.js +0 -75
  15. package/dist/common/divide.js +0 -51
  16. package/dist/common/eq.js +0 -43
  17. package/dist/common/event.js +0 -46
  18. package/dist/common/function.js +0 -78
  19. package/dist/common/get.js +0 -61
  20. package/dist/common/global.js +0 -50
  21. package/dist/common/gt.js +0 -43
  22. package/dist/common/gte.js +0 -43
  23. package/dist/common/if.js +0 -41
  24. package/dist/common/if_none.js +0 -47
  25. package/dist/common/index.js +0 -69
  26. package/dist/common/input.js +0 -50
  27. package/dist/common/json.js +0 -64
  28. package/dist/common/log.js +0 -33
  29. package/dist/common/lt.js +0 -43
  30. package/dist/common/lte.js +0 -43
  31. package/dist/common/math.js +0 -210
  32. package/dist/common/mql.js +0 -124
  33. package/dist/common/ne.js +0 -43
  34. package/dist/common/not.js +0 -31
  35. package/dist/common/number.js +0 -125
  36. package/dist/common/nunjucks.js +0 -60
  37. package/dist/common/object.js +0 -118
  38. package/dist/common/operator.js +0 -49
  39. package/dist/common/or.js +0 -39
  40. package/dist/common/product.js +0 -45
  41. package/dist/common/random.js +0 -132
  42. package/dist/common/regex.js +0 -65
  43. package/dist/common/state.js +0 -50
  44. package/dist/common/string.js +0 -188
  45. package/dist/common/subtract.js +0 -47
  46. package/dist/common/sum.js +0 -45
  47. package/dist/common/switch.js +0 -49
  48. package/dist/common/type.js +0 -82
  49. package/dist/common/uri.js +0 -67
  50. package/dist/common/url_query.js +0 -50
  51. package/dist/common/user.js +0 -50
  52. package/dist/common/uuid.js +0 -76
  53. package/dist/common/yaml.js +0 -70
  54. package/dist/getFromOtherContext.js +0 -96
  55. package/dist/node/base64.js +0 -69
  56. package/dist/node/diff.js +0 -66
  57. package/dist/node/hash.js +0 -100
  58. package/dist/node/index.js +0 -29
  59. package/dist/node/secret.js +0 -54
  60. package/dist/web/actions.js +0 -46
  61. package/dist/web/base64.js +0 -67
  62. package/dist/web/event_log.js +0 -50
  63. package/dist/web/format.js +0 -52
  64. package/dist/web/index.js +0 -36
  65. package/dist/web/js.js +0 -45
  66. package/dist/web/list_contexts.js +0 -31
  67. package/dist/web/location.js +0 -74
  68. package/dist/web/media.js +0 -90
  69. package/dist/web/menu.js +0 -43
  70. package/dist/web/request.js +0 -56
  71. package/dist/web/request_details.js +0 -50
@@ -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(_ref) {
26
- var {
27
- params,
28
- array,
29
- key,
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
- if (!_helpers.type.isNone(params.index) && !_helpers.type.isNumber(params.index)) {
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
- throw new Error("Operator Error: ".concat(operator, " must be of type string, number or object. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
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;
@@ -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(_ref) {
30
- var {
31
- params,
32
- object,
33
- context,
34
- contexts,
35
- arrayIndices,
36
- operator,
37
- location,
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
- return (0, _getFromOtherContext.default)({
62
- arrayIndices,
63
- context,
64
- contexts,
65
- location,
66
- operator,
67
- params
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
- "use strict";
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
2
3
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- var _nodeParser = _interopRequireDefault(require("./nodeParser"));
8
+ http://www.apache.org/licenses/LICENSE-2.0
20
9
 
21
- var _webParser = _interopRequireDefault(require("./webParser"));
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 };
@@ -1,149 +1,86 @@
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 _common = _interopRequireDefault(require("./common"));
11
-
12
- var _node = _interopRequireDefault(require("./node"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
-
18
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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
- if (args && !_helpers.type.isArray(args)) {
92
- throw new Error('Operator parser args must be an array.');
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
- if (location && !_helpers.type.isString(location)) {
96
- throw new Error('Operator parser location must be a string.');
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
- var errors = [];
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
- var runClass = _ref => {
26
- var {
27
- location,
28
- meta,
29
- methodName,
30
- operator,
31
- params,
32
- functions,
33
- defaultFunction
34
- } = _ref;
35
-
36
- if (!methodName) {
37
- if (meta[params]) {
38
- methodName = params;
39
- } else if (defaultFunction) {
40
- methodName = defaultFunction;
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
- throw new Error("Operator Error: ".concat(operator, " requires a valid method name, use one of the following: ").concat(Object.keys(meta).join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
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
- if (!meta[methodName] && !functions[methodName]) {
47
- throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " is not supported, use one of the following: ").concat(Object.keys(meta).join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
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
- var args = [];
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
- if (_helpers.type.isObject(params)) {
73
- args.push(...(meta[methodName].namedArgs || []).map(key => params[key]));
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;