@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,49 +1,38 @@
1
- "use strict";
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
2
3
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
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
7
 
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
- 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; }
11
-
12
- 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; }
13
-
14
- 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; }
8
+ http://www.apache.org/licenses/LICENSE-2.0
15
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
16
  function _operator(options) {
17
- var {
18
- operations,
19
- params,
20
- location
21
- } = options;
22
-
23
- if (!_helpers.type.isString(params.name)) {
24
- throw new Error("Operator Error: _operator.name must be a valid operator name as string. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
25
- }
26
-
27
- if (params.name === '_operator') {
28
- throw new Error("Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
29
- }
30
-
31
- if (params.name.includes('experimental')) {
32
- throw new Error("Operator Error: Experimental operators cannot be used with _operator. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
33
- }
34
-
35
- var [operator, methodName] = params.name.split('.');
36
-
37
- if (Object.prototype.hasOwnProperty.call(operations, operator)) {
38
- return operations[operator](_objectSpread(_objectSpread({}, options), {}, {
39
- location,
40
- params: params && params.params,
41
- methodName
42
- }));
43
- }
44
-
45
- throw new Error("Operator Error: _operator - Invalid operator name. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
17
+ const { operations , params , location } = options;
18
+ if (!type.isString(params.name)) {
19
+ throw new Error(`Operator Error: _operator.name must be a valid operator name as string. Received: ${JSON.stringify(params)} at ${location}.`);
20
+ }
21
+ if (params.name === '_operator') {
22
+ throw new Error(`Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: ${JSON.stringify(params)} at ${location}.`);
23
+ }
24
+ if (params.name.includes('experimental')) {
25
+ throw new Error(`Operator Error: Experimental operators cannot be used with _operator. Received: ${JSON.stringify(params)} at ${location}.`);
26
+ }
27
+ const [operator, methodName] = params.name.split('.');
28
+ if (Object.prototype.hasOwnProperty.call(operations, operator)) {
29
+ return operations[operator]({
30
+ ...options,
31
+ location,
32
+ params: params && params.params,
33
+ methodName
34
+ });
35
+ }
36
+ throw new Error(`Operator Error: _operator - Invalid operator name. Received: ${JSON.stringify(params)} at ${location}.`);
46
37
  }
47
-
48
- var _default = _operator;
49
- exports.default = _default;
38
+ export default _operator;
package/dist/common/or.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,19 +12,12 @@ 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 _or(_ref) {
26
- var {
27
- location,
28
- params
29
- } = _ref;
30
-
31
- if (!_helpers.type.isArray(params)) {
32
- throw new Error("Operator Error: _or takes an array type. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
33
- }
34
-
35
- return !!params.reduce((acc, el) => acc || el, false);
15
+ */ import { type } from '@lowdefy/helpers';
16
+ function _or({ location , params }) {
17
+ if (!type.isArray(params)) {
18
+ throw new Error(`Operator Error: _or takes an array type. Received: ${JSON.stringify(params)} at ${location}.`);
19
+ }
20
+ return !!params.reduce((acc, el)=>acc || el
21
+ , false);
36
22
  }
37
-
38
- var _default = _or;
39
- exports.default = _default;
23
+ export default _or;
@@ -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,25 +12,16 @@ 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 _product(_ref) {
26
- var {
27
- params,
28
- location
29
- } = _ref;
30
-
31
- if (!_helpers.type.isArray(params)) {
32
- throw new Error("Operator Error: _product takes an array type as input. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
33
- }
34
-
35
- return params.reduce((accumulator, value) => {
36
- if (_helpers.type.isNumber(value)) {
37
- return accumulator * value;
15
+ */ import { type } from '@lowdefy/helpers';
16
+ function _product({ params , location }) {
17
+ if (!type.isArray(params)) {
18
+ throw new Error(`Operator Error: _product takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
38
19
  }
39
-
40
- return accumulator;
41
- }, 1);
20
+ return params.reduce((accumulator, value)=>{
21
+ if (type.isNumber(value)) {
22
+ return accumulator * value;
23
+ }
24
+ return accumulator;
25
+ }, 1);
42
26
  }
43
-
44
- var _default = _product;
45
- exports.default = _default;
27
+ export default _product;
@@ -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,112 +12,86 @@ 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 typesEnum = ['string', 'integer', 'float'];
26
-
27
- function generateRandomString(length) {
28
- var randomString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
29
- randomString += Math.random().toString(36).substr(2, length);
30
- if (randomString.length > length) return randomString.slice(0, length);
31
- return generateRandomString(length, randomString);
32
- } // Both minimum and maximum is inclusive.
33
-
34
-
15
+ */ import { type } from '@lowdefy/helpers';
16
+ const typesEnum = [
17
+ 'string',
18
+ 'integer',
19
+ 'float'
20
+ ];
21
+ function generateRandomString(length, randomString = '') {
22
+ randomString += Math.random().toString(36).substr(2, length);
23
+ if (randomString.length > length) return randomString.slice(0, length);
24
+ return generateRandomString(length, randomString);
25
+ }
26
+ // Both minimum and maximum is inclusive.
35
27
  function getRandomInt(min, max) {
36
- return Math.floor(Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min));
28
+ return Math.floor(Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min));
37
29
  }
38
-
39
30
  function getRandomFloat(min, max) {
40
- return Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min);
31
+ return Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min);
41
32
  }
42
-
43
- function evaluateDefaultNumber(_ref) {
44
- var {
45
- key,
46
- defaultValue,
47
- params,
48
- location
49
- } = _ref;
50
-
51
- if (_helpers.type.isUndefined(params[key])) {
52
- params[key] = defaultValue;
53
- }
54
-
55
- if (!_helpers.type.isNumber(params[key])) {
56
- throw new Error("Operator Error: _random.".concat(key, " takes an number type. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
57
- }
33
+ function evaluateDefaultNumber({ key , defaultValue , params , location }) {
34
+ if (type.isUndefined(params[key])) {
35
+ params[key] = defaultValue;
36
+ }
37
+ if (!type.isNumber(params[key])) {
38
+ throw new Error(`Operator Error: _random.${key} takes an number type. Received: ${JSON.stringify(params)} at ${location}.`);
39
+ }
58
40
  }
59
-
60
- function _random(_ref2) {
61
- var {
62
- location,
63
- params
64
- } = _ref2;
65
-
66
- if (!_helpers.type.isString(params) && !_helpers.type.isObject(params)) {
67
- throw new Error("Operator Error: _random takes an string or object type. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
68
- }
69
-
70
- if (!_helpers.type.isObject(params)) {
71
- params = {
72
- type: params
73
- };
74
- }
75
-
76
- if (!typesEnum.includes(params.type)) {
77
- throw new Error("Operator Error: _random type can be either 'string', 'integer' or 'float'. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
78
- }
79
-
80
- if (params.type === 'float') {
81
- evaluateDefaultNumber({
82
- key: 'min',
83
- defaultValue: 0,
84
- params,
85
- location
86
- });
87
- evaluateDefaultNumber({
88
- key: 'max',
89
- defaultValue: params.min + 1,
90
- params,
91
- location
92
- });
93
-
94
- if (params.max < params.min) {
95
- throw new Error("Operator Error: _random.min must be less than _random.max. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
41
+ function _random({ location , params }) {
42
+ if (!type.isString(params) && !type.isObject(params)) {
43
+ throw new Error(`Operator Error: _random takes an string or object type. Received: ${JSON.stringify(params)} at ${location}.`);
44
+ }
45
+ if (!type.isObject(params)) {
46
+ params = {
47
+ type: params
48
+ };
49
+ }
50
+ if (!typesEnum.includes(params.type)) {
51
+ throw new Error(`Operator Error: _random type can be either 'string', 'integer' or 'float'. Received: ${JSON.stringify(params)} at ${location}.`);
52
+ }
53
+ if (params.type === 'float') {
54
+ evaluateDefaultNumber({
55
+ key: 'min',
56
+ defaultValue: 0,
57
+ params,
58
+ location
59
+ });
60
+ evaluateDefaultNumber({
61
+ key: 'max',
62
+ defaultValue: params.min + 1,
63
+ params,
64
+ location
65
+ });
66
+ if (params.max < params.min) {
67
+ throw new Error(`Operator Error: _random.min must be less than _random.max. Received: ${JSON.stringify(params)} at ${location}.`);
68
+ }
69
+ return getRandomFloat(params.min, params.max);
70
+ }
71
+ if (params.type === 'integer') {
72
+ evaluateDefaultNumber({
73
+ key: 'min',
74
+ defaultValue: 0,
75
+ params,
76
+ location
77
+ });
78
+ evaluateDefaultNumber({
79
+ key: 'max',
80
+ defaultValue: params.min + 100,
81
+ params,
82
+ location
83
+ });
84
+ if (params.max < params.min) {
85
+ throw new Error(`Operator Error: _random.min must be less than _random.max. Received: ${JSON.stringify(params)} at ${location}.`);
86
+ }
87
+ return getRandomInt(params.min, params.max);
96
88
  }
97
-
98
- return getRandomFloat(params.min, params.max);
99
- }
100
-
101
- if (params.type === 'integer') {
102
- evaluateDefaultNumber({
103
- key: 'min',
104
- defaultValue: 0,
105
- params,
106
- location
107
- });
108
89
  evaluateDefaultNumber({
109
- key: 'max',
110
- defaultValue: params.min + 100,
111
- params,
112
- location
90
+ key: 'length',
91
+ defaultValue: 8,
92
+ params,
93
+ location
113
94
  });
114
-
115
- if (params.max < params.min) {
116
- throw new Error("Operator Error: _random.min must be less than _random.max. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
117
- }
118
-
119
- return getRandomInt(params.min, params.max);
120
- }
121
-
122
- evaluateDefaultNumber({
123
- key: 'length',
124
- defaultValue: 8,
125
- params,
126
- location
127
- });
128
- return generateRandomString(params.length);
95
+ return generateRandomString(params.length);
129
96
  }
130
-
131
- var _default = _random;
132
- exports.default = _default;
97
+ export default _random;
@@ -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,45 +12,31 @@ 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 _regex(_ref) {
26
- var {
27
- location,
28
- params,
29
- state
30
- } = _ref;
31
- var pattern = _helpers.type.isObject(params) ? params.pattern : params;
32
-
33
- if (!_helpers.type.isString(pattern)) {
34
- throw new Error("Operator Error: _regex.pattern must be a string. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
35
- }
36
-
37
- var on = !_helpers.type.isUndefined(params.on) ? params.on : (0, _helpers.get)(state, location);
38
-
39
- if (!_helpers.type.isUndefined(params.key)) {
40
- if (!_helpers.type.isString(params.key)) {
41
- throw new Error("Operator Error: _regex.key must be a string. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
15
+ */ import { get, type } from '@lowdefy/helpers';
16
+ function _regex({ location , params , state }) {
17
+ const pattern = type.isObject(params) ? params.pattern : params;
18
+ if (!type.isString(pattern)) {
19
+ throw new Error(`Operator Error: _regex.pattern must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
20
+ }
21
+ let on = !type.isUndefined(params.on) ? params.on : get(state, location);
22
+ if (!type.isUndefined(params.key)) {
23
+ if (!type.isString(params.key)) {
24
+ throw new Error(`Operator Error: _regex.key must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
25
+ }
26
+ on = get(state, params.key);
27
+ }
28
+ if (type.isNone(on)) {
29
+ return false;
30
+ }
31
+ if (!type.isString(on)) {
32
+ throw new Error(`Operator Error: _regex.on must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
33
+ }
34
+ try {
35
+ const re = new RegExp(pattern, params.flags || 'gm');
36
+ return re.test(on);
37
+ } catch (e) {
38
+ // log e to LowdefyError
39
+ throw new Error(`Operator Error: _regex failed to execute RegExp.test. Received: ${JSON.stringify(params)} at ${location}.`);
42
40
  }
43
-
44
- on = (0, _helpers.get)(state, params.key);
45
- }
46
-
47
- if (_helpers.type.isNone(on)) {
48
- return false;
49
- }
50
-
51
- if (!_helpers.type.isString(on)) {
52
- throw new Error("Operator Error: _regex.on must be a string. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
53
- }
54
-
55
- try {
56
- var re = new RegExp(pattern, params.flags || 'gm');
57
- return re.test(on);
58
- } catch (e) {
59
- // log e to LowdefyError
60
- throw new Error("Operator Error: _regex failed to execute RegExp.test. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
61
- }
62
41
  }
63
-
64
- var _default = _regex;
65
- exports.default = _default;
42
+ export default _regex;