@lowdefy/operators 3.22.0 → 4.0.0-alpha.1

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 (75) hide show
  1. package/dist/common/and.js +8 -24
  2. package/dist/common/args.js +10 -31
  3. package/dist/common/array.js +244 -153
  4. package/dist/common/change_case.js +114 -160
  5. package/dist/common/date.js +33 -54
  6. package/dist/common/divide.js +16 -36
  7. package/dist/common/eq.js +10 -28
  8. package/dist/common/function.js +27 -59
  9. package/dist/common/get.js +21 -46
  10. package/dist/common/gt.js +10 -28
  11. package/dist/common/gte.js +10 -28
  12. package/dist/common/if.js +9 -26
  13. package/dist/common/if_none.js +13 -32
  14. package/dist/common/index.js +39 -53
  15. package/dist/common/json.js +53 -57
  16. package/dist/common/log.js +5 -18
  17. package/dist/common/lt.js +10 -28
  18. package/dist/common/lte.js +10 -28
  19. package/dist/common/math.js +255 -194
  20. package/dist/common/mql.js +93 -102
  21. package/dist/common/ne.js +10 -28
  22. package/dist/common/not.js +3 -16
  23. package/dist/common/number.js +130 -108
  24. package/dist/common/nunjucks.js +24 -44
  25. package/dist/common/object.js +89 -98
  26. package/dist/common/operator.js +33 -44
  27. package/dist/common/or.js +8 -24
  28. package/dist/common/product.js +11 -29
  29. package/dist/common/random.js +74 -109
  30. package/dist/common/regex.js +26 -49
  31. package/dist/common/string.js +270 -171
  32. package/dist/common/subtract.js +13 -32
  33. package/dist/common/sum.js +11 -29
  34. package/dist/common/switch.js +30 -0
  35. package/dist/common/type.js +36 -67
  36. package/dist/common/uri.js +29 -46
  37. package/dist/common/user.js +10 -35
  38. package/dist/common/uuid.js +48 -59
  39. package/dist/common/yaml.js +56 -63
  40. package/dist/getFromArray.js +22 -44
  41. package/dist/getFromObject.js +25 -70
  42. package/dist/index.js +14 -20
  43. package/dist/node/base64.js +31 -48
  44. package/dist/node/diff.js +30 -47
  45. package/dist/node/hash.js +55 -71
  46. package/dist/node/index.js +6 -14
  47. package/dist/{web/list_contexts.js → node/payload.js} +9 -16
  48. package/dist/node/secret.js +32 -53
  49. package/dist/nodeParser.js +95 -146
  50. package/dist/runClass.js +57 -82
  51. package/dist/runInstance.js +60 -84
  52. package/dist/web/_index.js +25 -0
  53. package/dist/web/actions.js +10 -31
  54. package/dist/web/base64.js +29 -46
  55. package/dist/{common/_index.js → web/event.js} +10 -30
  56. package/dist/web/event_log.js +10 -35
  57. package/dist/web/format.js +15 -37
  58. package/dist/web/global.js +25 -0
  59. package/dist/web/index.js +17 -21
  60. package/dist/{common/event.js → web/input.js} +10 -31
  61. package/dist/web/js.js +10 -30
  62. package/dist/web/location.js +44 -59
  63. package/dist/web/media.js +46 -75
  64. package/dist/web/menu.js +10 -28
  65. package/dist/web/request.js +19 -40
  66. package/dist/web/request_details.js +10 -35
  67. package/dist/web/state.js +25 -0
  68. package/dist/web/url_query.js +25 -0
  69. package/dist/webParser.js +115 -157
  70. package/package.json +16 -15
  71. package/dist/common/global.js +0 -50
  72. package/dist/common/input.js +0 -50
  73. package/dist/common/state.js +0 -50
  74. package/dist/common/url_query.js +0 -50
  75. package/dist/getFromOtherContext.js +0 -96
@@ -1,149 +1,98 @@
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
- };
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
+ import commonOperators from './common/index.js';
17
+ import nodeOperators from './node/index.js';
18
+ let NodeParser = class NodeParser {
19
+ async init() {
20
+ const operators = this.operators;
21
+ const operations = this.operations;
22
+ await Promise.all(Object.keys(operators).map(async (operator)=>{
23
+ const fn = await import(`./${operators[operator]}.js`);
24
+ operations[operator] = fn.default;
25
+ if (operations[operator].init) {
26
+ await operations[operator].init();
27
+ }
28
+ }));
85
29
  }
86
-
87
- if (event && !_helpers.type.isObject(event)) {
88
- throw new Error('Operator parser event must be a object.');
89
- }
90
-
91
- if (args && !_helpers.type.isArray(args)) {
92
- throw new Error('Operator parser args must be an array.');
30
+ parse({ args , input , location }) {
31
+ const operations = this.operations;
32
+ const secrets = this.secrets;
33
+ const payload = this.payload;
34
+ const user = this.user;
35
+ if (type.isUndefined(input)) {
36
+ return {
37
+ output: input,
38
+ errors: []
39
+ };
40
+ }
41
+ if (args && !type.isArray(args)) {
42
+ throw new Error('Operator parser args must be an array.');
43
+ }
44
+ if (location && !type.isString(location)) {
45
+ throw new Error('Operator parser location must be a string.');
46
+ }
47
+ const errors = [];
48
+ const reviver = (_, value)=>{
49
+ if (type.isObject(value) && Object.keys(value).length === 1) {
50
+ const key = Object.keys(value)[0];
51
+ const [op, methodName] = key.split('.');
52
+ try {
53
+ if (!type.isUndefined(operations[op])) {
54
+ const res = operations[op]({
55
+ args,
56
+ arrayIndices: [],
57
+ env: 'node',
58
+ location,
59
+ methodName,
60
+ operations: operations,
61
+ params: value[key],
62
+ secrets,
63
+ payload,
64
+ user,
65
+ parser: this
66
+ });
67
+ return res;
68
+ }
69
+ } catch (e) {
70
+ errors.push(e);
71
+ console.error(e);
72
+ return null;
73
+ }
74
+ }
75
+ return value;
76
+ };
77
+ return {
78
+ output: serializer.copy(input, {
79
+ reviver
80
+ }),
81
+ errors
82
+ };
93
83
  }
94
-
95
- if (location && !_helpers.type.isString(location)) {
96
- throw new Error('Operator parser location must be a string.');
84
+ constructor({ payload , secrets , user } = {
85
+ }){
86
+ this.payload = payload;
87
+ this.secrets = secrets;
88
+ this.user = user;
89
+ this.parse = this.parse.bind(this);
90
+ this.operators = {
91
+ ...commonOperators,
92
+ ...nodeOperators
93
+ };
94
+ this.operations = {
95
+ };
97
96
  }
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;
97
+ };
98
+ 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;
@@ -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,81 +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 runInstance = _ref => {
26
- var {
27
- location,
28
- meta,
29
- methodName,
30
- operator,
31
- params,
32
- instanceType
33
- } = _ref;
34
-
35
- if (!meta[methodName]) {
36
- 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, "."));
37
- } // validate params type
38
-
39
-
40
- if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(_helpers.type.typeOf(params))) {
41
- 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, "."));
42
- }
43
-
44
- var instance;
45
- var args = [];
46
-
47
- if (meta[methodName].singleArg || meta[methodName].property) {
48
- instance = params;
49
- } else {
50
- if (_helpers.type.isArray(params)) {
51
- // Instance must be zero in list args.
52
- instance = params[0];
53
- args = params.slice(1);
54
- } // Instance must be listed first in named args.
55
-
56
-
57
- if (_helpers.type.isObject(params)) {
58
- instance = params[meta[methodName].namedArgs[0]];
59
- args.push(...meta[methodName].namedArgs.slice(1).map(key => params[key]));
60
-
61
- if (!_helpers.type.isNone(meta[methodName].spreadArgs) && !_helpers.type.isArray(params[meta[methodName].spreadArgs])) {
62
- 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, "."));
63
- }
64
-
65
- args.push(...(params[meta[methodName].spreadArgs] || []));
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}.`);
66
20
  }
67
- }
68
-
69
- if (_helpers.type.isFunction(meta[methodName].prep)) {
70
- [instance, ...args] = meta[methodName].prep([instance, ...args]);
71
- }
72
-
73
- if (_helpers.type.typeOf(instance) !== instanceType) {
74
- throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " must be evaluated on an ").concat(instanceType, " instance. For named args provide an ").concat(instanceType, " instance to the \"on\" property, for listed args provide and ").concat(instanceType, " instance as the first element in the operator argument array.\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
75
- } // Error for invalid method key.
76
-
77
-
78
- if (_helpers.type.isNone(instance[methodName])) {
79
- throw new Error("Operator Error: ".concat(operator, " must be evaluated using one of the following: ").concat(Object.keys(meta).join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
80
- } // for property
81
-
82
-
83
- if (meta[methodName].property) {
84
- return instance[methodName];
85
- }
86
-
87
- try {
88
- var result = instance[methodName](...args);
89
-
90
- if (meta[methodName].returnInstance) {
91
- return instance;
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
+ ));
41
+ if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
42
+ throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
43
+ Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
44
+ }
45
+ args.push(...params[meta[methodName].spreadArgs] || []);
46
+ }
47
+ }
48
+ if (type.isFunction(meta[methodName].prep)) {
49
+ [instance, ...args] = meta[methodName].prep([
50
+ instance,
51
+ ...args
52
+ ]);
53
+ }
54
+ if (type.typeOf(instance) !== instanceType) {
55
+ 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.
56
+ Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
57
+ }
58
+ // Error for invalid method key.
59
+ if (type.isNone(instance[methodName])) {
60
+ throw new Error(`Operator Error: ${operator} must be evaluated using one of the following: ${Object.keys(meta).join(', ')}.
61
+ Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
62
+ }
63
+ // for property
64
+ if (meta[methodName].property) {
65
+ return instance[methodName];
66
+ }
67
+ try {
68
+ const result = instance[methodName](...args);
69
+ if (meta[methodName].returnInstance) {
70
+ return instance;
71
+ }
72
+ return result;
73
+ } catch (e) {
74
+ throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
92
75
  }
93
-
94
- return result;
95
- } catch (e) {
96
- throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " - ").concat(e.message, " Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
97
- }
98
76
  };
99
-
100
- var _default = runInstance;
101
- exports.default = _default;
77
+ export default runInstance;
@@ -0,0 +1,25 @@
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 getFromObject from '../getFromObject.js';
16
+ function _index({ arrayIndices , location , params }) {
17
+ return getFromObject({
18
+ arrayIndices,
19
+ location,
20
+ object: arrayIndices,
21
+ operator: '_index',
22
+ params
23
+ });
24
+ }
25
+ export default _index;
@@ -1,14 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _getFromObject = _interopRequireDefault(require("../getFromObject"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
1
  /*
13
2
  Copyright 2020-2021 Lowdefy, Inc
14
3
 
@@ -23,24 +12,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
23
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
13
  See the License for the specific language governing permissions and
25
14
  limitations under the License.
26
- */
27
- function _actions(_ref) {
28
- var {
29
- actions,
30
- arrayIndices,
31
- env,
32
- location,
33
- params
34
- } = _ref;
35
- return (0, _getFromObject.default)({
36
- arrayIndices,
37
- env,
38
- location,
39
- object: actions,
40
- operator: '_actions',
41
- params
42
- });
15
+ */ import getFromObject from '../getFromObject.js';
16
+ function _actions({ actions , arrayIndices , location , params }) {
17
+ return getFromObject({
18
+ arrayIndices,
19
+ location,
20
+ object: actions,
21
+ operator: '_actions',
22
+ params
23
+ });
43
24
  }
44
-
45
- var _default = _actions;
46
- exports.default = _default;
25
+ export default _actions;