@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,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,62 +12,40 @@ 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 _type(_ref) {
26
- var {
27
- location,
28
- params,
29
- state
30
- } = _ref;
31
- var typeName = _helpers.type.isObject(params) ? params.type : params;
32
-
33
- if (!_helpers.type.isString(typeName)) {
34
- throw new Error("Operator Error: _type.type must be a string. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
35
- }
36
-
37
- var on = Object.prototype.hasOwnProperty.call(params, 'on') ? params.on : (0, _helpers.get)(state, (0, _helpers.get)(params, 'key', {
38
- default: location
39
- }));
40
-
41
- switch (typeName) {
42
- case 'string':
43
- return _helpers.type.isString(on);
44
-
45
- case 'array':
46
- return _helpers.type.isArray(on);
47
-
48
- case 'date':
49
- return _helpers.type.isDate(on);
50
- // Testing for date is problematic due to stringify
51
-
52
- case 'object':
53
- return _helpers.type.isObject(on);
54
-
55
- case 'boolean':
56
- return _helpers.type.isBoolean(on);
57
-
58
- case 'number':
59
- return _helpers.type.isNumber(on);
60
-
61
- case 'integer':
62
- return _helpers.type.isInt(on);
63
-
64
- case 'null':
65
- return _helpers.type.isNull(on);
66
-
67
- case 'undefined':
68
- return _helpers.type.isUndefined(on);
69
-
70
- case 'none':
71
- return _helpers.type.isNone(on);
72
-
73
- case 'primitive':
74
- return _helpers.type.isPrimitive(on);
75
-
76
- default:
77
- throw new Error("Operator Error: \"".concat(typeName, "\" is not a valid _type test. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
78
- }
15
+ */ import { get, type } from '@lowdefy/helpers';
16
+ function _type({ location , params , state }) {
17
+ const typeName = type.isObject(params) ? params.type : params;
18
+ if (!type.isString(typeName)) {
19
+ throw new Error(`Operator Error: _type.type must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
20
+ }
21
+ const on = Object.prototype.hasOwnProperty.call(params, 'on') ? params.on : get(state, get(params, 'key', {
22
+ default: location
23
+ }));
24
+ switch(typeName){
25
+ case 'string':
26
+ return type.isString(on);
27
+ case 'array':
28
+ return type.isArray(on);
29
+ case 'date':
30
+ return type.isDate(on); // Testing for date is problematic due to stringify
31
+ case 'object':
32
+ return type.isObject(on);
33
+ case 'boolean':
34
+ return type.isBoolean(on);
35
+ case 'number':
36
+ return type.isNumber(on);
37
+ case 'integer':
38
+ return type.isInt(on);
39
+ case 'null':
40
+ return type.isNull(on);
41
+ case 'undefined':
42
+ return type.isUndefined(on);
43
+ case 'none':
44
+ return type.isNone(on);
45
+ case 'primitive':
46
+ return type.isPrimitive(on);
47
+ default:
48
+ throw new Error(`Operator Error: "${typeName}" is not a valid _type test. Received: ${JSON.stringify(params)} at ${location}.`);
49
+ }
79
50
  }
80
-
81
- var _default = _type;
82
- exports.default = _default;
51
+ export default _type;
@@ -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 _runClass = _interopRequireDefault(require("../runClass"));
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,45 +12,39 @@ 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
- */
15
+ */ import runClass from '../runClass.js';
27
16
  function decode(input) {
28
- return decodeURIComponent(input);
17
+ return decodeURIComponent(input);
29
18
  }
30
-
31
19
  function encode(input) {
32
- return encodeURIComponent(input);
20
+ return encodeURIComponent(input);
33
21
  }
34
-
35
- var functions = {
36
- encode,
37
- decode
22
+ const functions = {
23
+ encode,
24
+ decode
38
25
  };
39
- var meta = {
40
- encode: {
41
- singleArg: true,
42
- validTypes: ['string']
43
- },
44
- decode: {
45
- singleArg: true,
46
- validTypes: ['string']
47
- }
26
+ const meta = {
27
+ encode: {
28
+ singleArg: true,
29
+ validTypes: [
30
+ 'string'
31
+ ]
32
+ },
33
+ decode: {
34
+ singleArg: true,
35
+ validTypes: [
36
+ 'string'
37
+ ]
38
+ }
48
39
  };
49
-
50
- function _uri(_ref) {
51
- var {
52
- params,
53
- location,
54
- methodName
55
- } = _ref;
56
- return (0, _runClass.default)({
57
- functions,
58
- location,
59
- meta,
60
- methodName,
61
- operator: '_uri',
62
- params
63
- });
40
+ function _uri({ params , location , methodName }) {
41
+ return runClass({
42
+ functions,
43
+ location,
44
+ meta,
45
+ methodName,
46
+ operator: '_uri',
47
+ params
48
+ });
64
49
  }
65
-
66
- var _default = _uri;
67
- exports.default = _default;
50
+ export default _uri;
@@ -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,28 +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 _user(_ref) {
28
- var {
29
- arrayIndices,
30
- context,
31
- contexts,
32
- env,
33
- location,
34
- params,
35
- user
36
- } = _ref;
37
- return (0, _getFromObject.default)({
38
- arrayIndices,
39
- context,
40
- contexts,
41
- env,
42
- location,
43
- object: user,
44
- operator: '_user',
45
- params
46
- });
15
+ */ import getFromObject from '../getFromObject.js';
16
+ function _user({ arrayIndices , location , params , user }) {
17
+ return getFromObject({
18
+ arrayIndices,
19
+ location,
20
+ object: user,
21
+ operator: '_user',
22
+ params
23
+ });
47
24
  }
48
-
49
- var _default = _user;
50
- exports.default = _default;
25
+ export default _user;
@@ -1,18 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _uuid2 = require("uuid");
9
-
10
- var _helpers = require("@lowdefy/helpers");
11
-
12
- var _runClass = _interopRequireDefault(require("../runClass"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
1
  /*
17
2
  Copyright 2020-2021 Lowdefy, Inc
18
3
 
@@ -27,50 +12,54 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
27
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
13
  See the License for the specific language governing permissions and
29
14
  limitations under the License.
30
- */
31
- var meta = {
32
- v1: {
33
- noArgs: true
34
- },
35
- v3: {
36
- namedArgs: ['name', 'namespace'],
37
- validTypes: ['array', 'object']
38
- },
39
- v4: {
40
- noArgs: true
41
- },
42
- v5: {
43
- namedArgs: ['name', 'namespace'],
44
- validTypes: ['array', 'object']
45
- }
15
+ */ import { v1, v3, v4, v5 } from 'uuid';
16
+ import { type } from '@lowdefy/helpers';
17
+ import runClass from '../runClass.js';
18
+ const meta = {
19
+ v1: {
20
+ noArgs: true
21
+ },
22
+ v3: {
23
+ namedArgs: [
24
+ 'name',
25
+ 'namespace'
26
+ ],
27
+ validTypes: [
28
+ 'array',
29
+ 'object'
30
+ ]
31
+ },
32
+ v4: {
33
+ noArgs: true
34
+ },
35
+ v5: {
36
+ namedArgs: [
37
+ 'name',
38
+ 'namespace'
39
+ ],
40
+ validTypes: [
41
+ 'array',
42
+ 'object'
43
+ ]
44
+ }
46
45
  };
47
- var functions = {
48
- v1: _uuid2.v1,
49
- v3: _uuid2.v3,
50
- v4: _uuid2.v4,
51
- v5: _uuid2.v5
46
+ const functions = {
47
+ v1,
48
+ v3,
49
+ v4,
50
+ v5
52
51
  };
53
-
54
- function _uuid(_ref) {
55
- var {
56
- params,
57
- location,
58
- methodName
59
- } = _ref;
60
-
61
- if (_helpers.type.isNone(methodName) && (_helpers.type.isNone(params) || params === true)) {
62
- return (0, _uuid2.v4)();
63
- }
64
-
65
- return (0, _runClass.default)({
66
- functions: functions,
67
- location,
68
- meta,
69
- methodName,
70
- operator: '_uuid',
71
- params
72
- });
52
+ function _uuid({ params , location , methodName }) {
53
+ if (type.isNone(methodName) && (type.isNone(params) || params === true)) {
54
+ return v4();
55
+ }
56
+ return runClass({
57
+ functions: functions,
58
+ location,
59
+ meta,
60
+ methodName,
61
+ operator: '_uuid',
62
+ params
63
+ });
73
64
  }
74
-
75
- var _default = _uuid;
76
- exports.default = _default;
65
+ export default _uuid;
@@ -1,70 +1,63 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _jsYaml = _interopRequireDefault(require("js-yaml"));
9
-
10
- var _helpers = require("@lowdefy/helpers");
11
-
12
- var _runClass = _interopRequireDefault(require("../runClass"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- 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; }
17
-
18
- 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; }
19
-
20
- 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; }
21
-
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 YAML from 'js-yaml';
16
+ import { serializer } from '@lowdefy/helpers';
17
+ import runClass from '../runClass.js';
22
18
  function parse(input) {
23
- if (input === 'undefined') return undefined;
24
-
25
- var loaded = _jsYaml.default.load(input);
26
-
27
- return _helpers.serializer.deserialize(loaded);
19
+ if (input === 'undefined') return undefined;
20
+ const loaded = YAML.load(input);
21
+ return serializer.deserialize(loaded);
28
22
  }
29
-
30
23
  function stringify(input, options) {
31
- return _jsYaml.default.dump(_helpers.serializer.serialize(input, {
32
- isoStringDates: true
33
- }), _objectSpread({
34
- sortKeys: true
35
- }, options));
24
+ return YAML.dump(serializer.serialize(input, {
25
+ isoStringDates: true
26
+ }), {
27
+ sortKeys: true,
28
+ ...options
29
+ });
36
30
  }
37
-
38
- var functions = {
39
- parse,
40
- stringify
31
+ const functions = {
32
+ parse,
33
+ stringify
41
34
  };
42
- var meta = {
43
- stringify: {
44
- namedArgs: ['on', 'options'],
45
- validTypes: ['object', 'array']
46
- },
47
- parse: {
48
- singleArg: true,
49
- validTypes: ['string']
50
- }
35
+ const meta = {
36
+ stringify: {
37
+ namedArgs: [
38
+ 'on',
39
+ 'options'
40
+ ],
41
+ validTypes: [
42
+ 'object',
43
+ 'array'
44
+ ]
45
+ },
46
+ parse: {
47
+ singleArg: true,
48
+ validTypes: [
49
+ 'string'
50
+ ]
51
+ }
51
52
  };
52
-
53
- function _yaml(_ref) {
54
- var {
55
- params,
56
- location,
57
- methodName
58
- } = _ref;
59
- return (0, _runClass.default)({
60
- functions,
61
- location,
62
- meta,
63
- methodName,
64
- operator: '_yaml',
65
- params
66
- });
53
+ function _yaml({ params , location , methodName }) {
54
+ return runClass({
55
+ functions,
56
+ location,
57
+ meta,
58
+ methodName,
59
+ operator: '_yaml',
60
+ params
61
+ });
67
62
  }
68
-
69
- var _default = _yaml;
70
- exports.default = _default;
63
+ export default _yaml;
@@ -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;