@lowdefy/operators 3.23.0 → 4.0.0-alpha.5

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/common/change_case.js +114 -160
  2. package/dist/common/index.js +39 -54
  3. package/dist/common/mql.js +93 -102
  4. package/dist/common/uuid.js +48 -59
  5. package/dist/common/yaml.js +56 -63
  6. package/dist/getFromArray.js +22 -44
  7. package/dist/getFromObject.js +25 -70
  8. package/dist/index.js +18 -20
  9. package/dist/node/diff.js +30 -47
  10. package/dist/node/index.js +6 -14
  11. package/dist/nodeParser.js +83 -146
  12. package/dist/runClass.js +57 -82
  13. package/dist/runInstance.js +60 -84
  14. package/dist/web/format.js +15 -37
  15. package/dist/web/index.js +17 -21
  16. package/dist/web/js.js +10 -30
  17. package/dist/webParser.js +99 -157
  18. package/package.json +16 -15
  19. package/dist/common/_index.js +0 -45
  20. package/dist/common/and.js +0 -39
  21. package/dist/common/args.js +0 -46
  22. package/dist/common/array.js +0 -170
  23. package/dist/common/date.js +0 -75
  24. package/dist/common/divide.js +0 -51
  25. package/dist/common/eq.js +0 -43
  26. package/dist/common/event.js +0 -46
  27. package/dist/common/function.js +0 -78
  28. package/dist/common/get.js +0 -61
  29. package/dist/common/global.js +0 -50
  30. package/dist/common/gt.js +0 -43
  31. package/dist/common/gte.js +0 -43
  32. package/dist/common/if.js +0 -41
  33. package/dist/common/if_none.js +0 -47
  34. package/dist/common/input.js +0 -50
  35. package/dist/common/json.js +0 -64
  36. package/dist/common/log.js +0 -33
  37. package/dist/common/lt.js +0 -43
  38. package/dist/common/lte.js +0 -43
  39. package/dist/common/math.js +0 -210
  40. package/dist/common/ne.js +0 -43
  41. package/dist/common/not.js +0 -31
  42. package/dist/common/number.js +0 -125
  43. package/dist/common/nunjucks.js +0 -60
  44. package/dist/common/object.js +0 -118
  45. package/dist/common/operator.js +0 -49
  46. package/dist/common/or.js +0 -39
  47. package/dist/common/product.js +0 -45
  48. package/dist/common/random.js +0 -132
  49. package/dist/common/regex.js +0 -65
  50. package/dist/common/state.js +0 -50
  51. package/dist/common/string.js +0 -188
  52. package/dist/common/subtract.js +0 -47
  53. package/dist/common/sum.js +0 -45
  54. package/dist/common/switch.js +0 -49
  55. package/dist/common/type.js +0 -82
  56. package/dist/common/uri.js +0 -67
  57. package/dist/common/url_query.js +0 -50
  58. package/dist/common/user.js +0 -50
  59. package/dist/getFromOtherContext.js +0 -96
  60. package/dist/node/base64.js +0 -69
  61. package/dist/node/hash.js +0 -100
  62. package/dist/node/secret.js +0 -54
  63. package/dist/web/actions.js +0 -46
  64. package/dist/web/base64.js +0 -67
  65. package/dist/web/event_log.js +0 -50
  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,18 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _changeCase = require("change-case");
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,159 +12,128 @@ 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
-
32
- /* eslint-disable import/namespace */
33
- var changeCase = {
34
- camelCase: _changeCase.camelCase,
35
- capitalCase: _changeCase.capitalCase,
36
- constantCase: _changeCase.constantCase,
37
- dotCase: _changeCase.dotCase,
38
- headerCase: _changeCase.headerCase,
39
- noCase: _changeCase.noCase,
40
- paramCase: _changeCase.paramCase,
41
- pascalCase: _changeCase.pascalCase,
42
- pathCase: _changeCase.pathCase,
43
- sentenceCase: _changeCase.sentenceCase,
44
- snakeCase: _changeCase.snakeCase
15
+ */ /* eslint-disable import/namespace */ import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
16
+ import { get, type } from '@lowdefy/helpers';
17
+ import runClass from '../runClass.js';
18
+ const changeCase = {
19
+ camelCase,
20
+ capitalCase,
21
+ constantCase,
22
+ dotCase,
23
+ headerCase,
24
+ noCase,
25
+ paramCase,
26
+ pascalCase,
27
+ pathCase,
28
+ sentenceCase,
29
+ snakeCase
45
30
  };
46
-
47
- var prepRegex = (prop, location) => {
48
- var regex = _helpers.type.isString(prop) ? {
49
- pattern: prop
50
- } : prop;
51
-
52
- if (!_helpers.type.isObject(regex)) {
53
- throw new Error("Operator Error: regex must be string or an object. Received ".concat(JSON.stringify(prop), " at ").concat(location, "."));
54
- }
55
-
56
- try {
57
- return new RegExp(regex.pattern, regex.flags || 'gm');
58
- } catch (e) {
59
- throw new Error("Operator Error: ".concat(e.message, ". Received: ").concat(JSON.stringify(prop), " at ").concat(location, "."));
60
- }
61
- };
62
-
63
- var prep = (args, _ref) => {
64
- var {
65
- location
66
- } = _ref;
67
- var options = args[1];
68
-
69
- if (!_helpers.type.isNone(options) && !_helpers.type.isObject(options)) {
70
- throw new Error("Operator Error: options must be an object. Received ".concat(JSON.stringify(options), " at ").concat(location, "."));
71
- }
72
-
73
- if (_helpers.type.isObject(options)) {
74
- if (options.splitRegexp) {
75
- options.splitRegexp = prepRegex(options.splitRegexp, location);
31
+ const prepRegex = (prop, location)=>{
32
+ const regex = type.isString(prop) ? {
33
+ pattern: prop
34
+ } : prop;
35
+ if (!type.isObject(regex)) {
36
+ throw new Error(`Operator Error: regex must be string or an object. Received ${JSON.stringify(prop)} at ${location}.`);
76
37
  }
77
-
78
- if (options.stripRegexp) {
79
- options.stripRegexp = prepRegex(options.stripRegexp, location);
38
+ try {
39
+ return new RegExp(regex.pattern, regex.flags || 'gm');
40
+ } catch (e) {
41
+ throw new Error(`Operator Error: ${e.message}. Received: ${JSON.stringify(prop)} at ${location}.`);
80
42
  }
81
- }
82
-
83
- return args;
84
43
  };
85
-
86
- var convertArray = _ref2 => {
87
- var {
88
- methodName,
89
- on,
90
- options
91
- } = _ref2;
92
- return on.map(item => {
93
- if (_helpers.type.isString(item)) {
94
- return changeCase[methodName](item, options);
44
+ const prep = (args, { location })=>{
45
+ const options = args[1];
46
+ if (!type.isNone(options) && !type.isObject(options)) {
47
+ throw new Error(`Operator Error: options must be an object. Received ${JSON.stringify(options)} at ${location}.`);
95
48
  }
96
-
97
- return item;
98
- });
99
- };
100
-
101
- var convertObject = _ref3 => {
102
- var {
103
- methodName,
104
- on,
105
- options
106
- } = _ref3;
107
- var result = {};
108
- var keyConverter = (0, _helpers.get)(options, 'convertKeys') ? key => changeCase[methodName](key, options) : key => key;
109
- var valueConverter = (0, _helpers.get)(options, 'convertValues', {
110
- default: true
111
- }) ? val => changeCase[methodName](val, options) : val => val;
112
- Object.entries(on).forEach(_ref4 => {
113
- var [key, value] = _ref4;
114
-
115
- if (_helpers.type.isString(value)) {
116
- result[keyConverter(key)] = valueConverter(value);
117
- } else {
118
- result[keyConverter(key)] = value;
49
+ if (type.isObject(options)) {
50
+ if (options.splitRegexp) {
51
+ options.splitRegexp = prepRegex(options.splitRegexp, location);
52
+ }
53
+ if (options.stripRegexp) {
54
+ options.stripRegexp = prepRegex(options.stripRegexp, location);
55
+ }
119
56
  }
120
- });
121
- return result;
57
+ return args;
122
58
  };
123
-
124
- var makeCaseChanger = _ref5 => {
125
- var {
126
- methodName
127
- } = _ref5;
128
- return function (on) {
129
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
130
-
131
- if (_helpers.type.isString(on)) {
132
- return changeCase[methodName](on, options);
133
- }
134
-
135
- if (_helpers.type.isArray(on)) {
136
- return convertArray({
137
- methodName,
138
- on,
139
- options
140
- });
141
- }
142
-
143
- if (_helpers.type.isObject(on)) {
144
- return convertObject({
145
- methodName,
146
- on,
147
- options
148
- });
59
+ const convertArray = ({ methodName , on , options })=>{
60
+ return on.map((item)=>{
61
+ if (type.isString(item)) {
62
+ return changeCase[methodName](item, options);
63
+ }
64
+ return item;
65
+ });
66
+ };
67
+ const convertObject = ({ methodName , on , options })=>{
68
+ const result = {
69
+ };
70
+ const keyConverter = get(options, 'convertKeys') ? (key)=>changeCase[methodName](key, options)
71
+ : (key)=>key
72
+ ;
73
+ const valueConverter = get(options, 'convertValues', {
74
+ default: true
75
+ }) ? (val)=>changeCase[methodName](val, options)
76
+ : (val)=>val
77
+ ;
78
+ Object.entries(on).forEach(([key, value])=>{
79
+ if (type.isString(value)) {
80
+ result[keyConverter(key)] = valueConverter(value);
81
+ } else {
82
+ result[keyConverter(key)] = value;
83
+ }
84
+ });
85
+ return result;
86
+ };
87
+ const makeCaseChanger = ({ methodName })=>(on, options = {
88
+ })=>{
89
+ if (type.isString(on)) {
90
+ return changeCase[methodName](on, options);
91
+ }
92
+ if (type.isArray(on)) {
93
+ return convertArray({
94
+ methodName,
95
+ on,
96
+ options
97
+ });
98
+ }
99
+ if (type.isObject(on)) {
100
+ return convertObject({
101
+ methodName,
102
+ on,
103
+ options
104
+ });
105
+ }
106
+ return on;
149
107
  }
150
-
151
- return on;
152
- };
108
+ ;
109
+ const functions = {
153
110
  };
154
-
155
- var functions = {};
156
- var meta = {};
157
- Object.keys(changeCase).forEach(methodName => {
158
- functions[methodName] = makeCaseChanger({
159
- methodName
160
- });
161
- meta[methodName] = {
162
- namedArgs: ['on', 'options'],
163
- validTypes: ['array', 'object'],
164
- prep
165
- };
111
+ const meta = {
112
+ };
113
+ Object.keys(changeCase).forEach((methodName)=>{
114
+ functions[methodName] = makeCaseChanger({
115
+ methodName
116
+ });
117
+ meta[methodName] = {
118
+ namedArgs: [
119
+ 'on',
120
+ 'options'
121
+ ],
122
+ validTypes: [
123
+ 'array',
124
+ 'object'
125
+ ],
126
+ prep
127
+ };
166
128
  });
167
-
168
- function change_case(_ref6) {
169
- var {
170
- params,
171
- location,
172
- methodName
173
- } = _ref6;
174
- return (0, _runClass.default)({
175
- functions,
176
- location,
177
- meta,
178
- methodName,
179
- operator: '_change_case',
180
- params
181
- });
129
+ function change_case({ params , location , methodName }) {
130
+ return runClass({
131
+ functions,
132
+ location,
133
+ meta,
134
+ methodName,
135
+ operator: '_change_case',
136
+ params
137
+ });
182
138
  }
183
-
184
- var _default = change_case;
185
- exports.default = _default;
139
+ export default change_case;
@@ -1,10 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
1
  /*
9
2
  Copyright 2020-2021 Lowdefy, Inc
10
3
 
@@ -19,51 +12,43 @@ exports.default = void 0;
19
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
13
  See the License for the specific language governing permissions and
21
14
  limitations under the License.
22
- */
23
- var _default = {
24
- _and: 'common/and',
25
- _args: 'common/args',
26
- _array: 'common/array',
27
- _change_case: 'common/change_case',
28
- _date: 'common/date',
29
- _divide: 'common/divide',
30
- _eq: 'common/eq',
31
- _event: 'common/event',
32
- _function: 'common/function',
33
- _get: 'common/get',
34
- _global: 'common/global',
35
- _gt: 'common/gt',
36
- _gte: 'common/gte',
37
- _if_none: 'common/if_none',
38
- _if: 'common/if',
39
- _index: 'common/_index',
40
- _input: 'common/input',
41
- _json: 'common/json',
42
- _log: 'common/log',
43
- _lt: 'common/lt',
44
- _lte: 'common/lte',
45
- _math: 'common/math',
46
- _mql: 'common/mql',
47
- _ne: 'common/ne',
48
- _not: 'common/not',
49
- _number: 'common/number',
50
- _nunjucks: 'common/nunjucks',
51
- _object: 'common/object',
52
- _operator: 'common/operator',
53
- _or: 'common/or',
54
- _product: 'common/product',
55
- _random: 'common/random',
56
- _regex: 'common/regex',
57
- _state: 'common/state',
58
- _string: 'common/string',
59
- _subtract: 'common/subtract',
60
- _sum: 'common/sum',
61
- _switch: 'common/switch',
62
- _type: 'common/type',
63
- _uri: 'common/uri',
64
- _url_query: 'common/url_query',
65
- _user: 'common/user',
66
- _uuid: 'common/uuid',
67
- _yaml: 'common/yaml'
15
+ */ export default {
16
+ _and: 'common/and',
17
+ _args: 'common/args',
18
+ _array: 'common/array',
19
+ _change_case: 'common/change_case',
20
+ _date: 'common/date',
21
+ _divide: 'common/divide',
22
+ _eq: 'common/eq',
23
+ _function: 'common/function',
24
+ _get: 'common/get',
25
+ _gt: 'common/gt',
26
+ _gte: 'common/gte',
27
+ _if_none: 'common/if_none',
28
+ _if: 'common/if',
29
+ _json: 'common/json',
30
+ _log: 'common/log',
31
+ _lt: 'common/lt',
32
+ _lte: 'common/lte',
33
+ _math: 'common/math',
34
+ _mql: 'common/mql',
35
+ _ne: 'common/ne',
36
+ _not: 'common/not',
37
+ _number: 'common/number',
38
+ _nunjucks: 'common/nunjucks',
39
+ _object: 'common/object',
40
+ _operator: 'common/operator',
41
+ _or: 'common/or',
42
+ _product: 'common/product',
43
+ _random: 'common/random',
44
+ _regex: 'common/regex',
45
+ _string: 'common/string',
46
+ _subtract: 'common/subtract',
47
+ _sum: 'common/sum',
48
+ _switch: 'common/switch',
49
+ _type: 'common/type',
50
+ _uri: 'common/uri',
51
+ _user: 'common/user',
52
+ _uuid: 'common/uuid',
53
+ _yaml: 'common/yaml'
68
54
  };
69
- exports.default = _default;
@@ -1,20 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _mingo = _interopRequireDefault(require("mingo"));
9
-
10
- var _helpers = require("@lowdefy/helpers");
11
-
12
- var _runClass = _interopRequireDefault(require("../runClass"));
13
-
14
- require("mingo/init/system");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
1
  /*
19
2
  Copyright 2020-2021 Lowdefy, Inc
20
3
 
@@ -29,96 +12,104 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
13
  See the License for the specific language governing permissions and
31
14
  limitations under the License.
32
- */
15
+ */ import mingo from 'mingo';
16
+ import { get, type } from '@lowdefy/helpers';
17
+ import runClass from '../runClass.js';
18
+ import 'mingo/init/system';
33
19
  function aggregate(data, pipeline) {
34
- if (data === null) {
35
- data = [];
36
- }
37
-
38
- if (!_helpers.type.isArray(data)) {
39
- throw new Error('Data must be of type array.');
40
- }
41
-
42
- if (!_helpers.type.isArray(pipeline)) {
43
- throw new Error('Pipeline must be of type array.');
44
- }
45
-
46
- var agg = new _mingo.default.Aggregator(pipeline);
47
- return agg.run(data);
20
+ if (data === null) {
21
+ data = [];
22
+ }
23
+ if (!type.isArray(data)) {
24
+ throw new Error('Data must be of type array.');
25
+ }
26
+ if (!type.isArray(pipeline)) {
27
+ throw new Error('Pipeline must be of type array.');
28
+ }
29
+ const agg = new mingo.Aggregator(pipeline);
30
+ return agg.run(data);
48
31
  }
49
-
50
- function expr(data, expr) {
51
- if (data === null) {
52
- data = {};
53
- }
54
-
55
- if (!_helpers.type.isObject(data)) {
56
- throw new Error('Data must be of type object.');
57
- }
58
-
59
- var agg = new _mingo.default.Aggregator([{
60
- $project: {
61
- value: expr
32
+ function expr1(data, expr) {
33
+ if (data === null) {
34
+ data = {
35
+ };
62
36
  }
63
- }]);
64
- var res = agg.run([data]);
65
- return (0, _helpers.get)(res, '0.value', {
66
- default: null
67
- });
37
+ if (!type.isObject(data)) {
38
+ throw new Error('Data must be of type object.');
39
+ }
40
+ const agg = new mingo.Aggregator([
41
+ {
42
+ $project: {
43
+ value: expr
44
+ }
45
+ },
46
+ ]);
47
+ const res = agg.run([
48
+ data
49
+ ]);
50
+ return get(res, '0.value', {
51
+ default: null
52
+ });
68
53
  }
69
-
70
- function test(data, test) {
71
- if (data === null) {
72
- data = {};
73
- }
74
-
75
- if (!_helpers.type.isObject(data)) {
76
- throw new Error('Data must be of type object.');
77
- }
78
-
79
- if (!_helpers.type.isObject(test)) {
80
- throw new Error('Query test must be of type object.');
81
- }
82
-
83
- var query = new _mingo.default.Query(test);
84
- return query.test(data);
54
+ function test1(data, test) {
55
+ if (data === null) {
56
+ data = {
57
+ };
58
+ }
59
+ if (!type.isObject(data)) {
60
+ throw new Error('Data must be of type object.');
61
+ }
62
+ if (!type.isObject(test)) {
63
+ throw new Error('Query test must be of type object.');
64
+ }
65
+ const query = new mingo.Query(test);
66
+ return query.test(data);
85
67
  }
86
-
87
- var meta = {
88
- aggregate: {
89
- namedArgs: ['on', 'pipeline'],
90
- validTypes: ['array', 'object']
91
- },
92
- expr: {
93
- namedArgs: ['on', 'expr'],
94
- validTypes: ['array', 'object']
95
- },
96
- test: {
97
- namedArgs: ['on', 'test'],
98
- validTypes: ['array', 'object']
99
- }
68
+ const meta = {
69
+ aggregate: {
70
+ namedArgs: [
71
+ 'on',
72
+ 'pipeline'
73
+ ],
74
+ validTypes: [
75
+ 'array',
76
+ 'object'
77
+ ]
78
+ },
79
+ expr: {
80
+ namedArgs: [
81
+ 'on',
82
+ 'expr'
83
+ ],
84
+ validTypes: [
85
+ 'array',
86
+ 'object'
87
+ ]
88
+ },
89
+ test: {
90
+ namedArgs: [
91
+ 'on',
92
+ 'test'
93
+ ],
94
+ validTypes: [
95
+ 'array',
96
+ 'object'
97
+ ]
98
+ }
100
99
  };
101
- var functions = {
102
- aggregate,
103
- expr,
104
- test
100
+ const functions = {
101
+ aggregate,
102
+ expr: expr1,
103
+ test: test1
105
104
  };
106
-
107
- function mql(_ref) {
108
- var {
109
- params,
110
- location,
111
- methodName
112
- } = _ref;
113
- return (0, _runClass.default)({
114
- functions,
115
- location,
116
- meta,
117
- methodName,
118
- operator: '_mql',
119
- params
120
- });
105
+ function mql({ params , location , methodName }) {
106
+ return runClass({
107
+ functions,
108
+ location,
109
+ meta,
110
+ methodName,
111
+ operator: '_mql',
112
+ params
113
+ });
121
114
  }
122
-
123
- var _default = mql;
124
- exports.default = _default;
115
+ export default mql;