@lowdefy/operators 4.0.0-alpha.1 → 4.0.0-alpha.10

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 (70) hide show
  1. package/dist/getFromArray.js +1 -1
  2. package/dist/getFromObject.js +1 -1
  3. package/dist/index.js +7 -3
  4. package/dist/nodeParser.js +32 -50
  5. package/dist/runClass.js +1 -1
  6. package/dist/runInstance.js +1 -1
  7. package/dist/webParser.js +37 -71
  8. package/package.json +11 -14
  9. package/dist/common/and.js +0 -23
  10. package/dist/common/args.js +0 -25
  11. package/dist/common/array.js +0 -261
  12. package/dist/common/change_case.js +0 -139
  13. package/dist/common/date.js +0 -54
  14. package/dist/common/divide.js +0 -31
  15. package/dist/common/eq.js +0 -25
  16. package/dist/common/function.js +0 -46
  17. package/dist/common/get.js +0 -36
  18. package/dist/common/gt.js +0 -25
  19. package/dist/common/gte.js +0 -25
  20. package/dist/common/if.js +0 -24
  21. package/dist/common/if_none.js +0 -28
  22. package/dist/common/index.js +0 -54
  23. package/dist/common/json.js +0 -60
  24. package/dist/common/log.js +0 -20
  25. package/dist/common/lt.js +0 -25
  26. package/dist/common/lte.js +0 -25
  27. package/dist/common/math.js +0 -271
  28. package/dist/common/mql.js +0 -115
  29. package/dist/common/ne.js +0 -25
  30. package/dist/common/not.js +0 -18
  31. package/dist/common/number.js +0 -147
  32. package/dist/common/nunjucks.js +0 -40
  33. package/dist/common/object.js +0 -109
  34. package/dist/common/operator.js +0 -38
  35. package/dist/common/or.js +0 -23
  36. package/dist/common/product.js +0 -27
  37. package/dist/common/random.js +0 -97
  38. package/dist/common/regex.js +0 -42
  39. package/dist/common/string.js +0 -287
  40. package/dist/common/subtract.js +0 -28
  41. package/dist/common/sum.js +0 -27
  42. package/dist/common/switch.js +0 -30
  43. package/dist/common/type.js +0 -51
  44. package/dist/common/uri.js +0 -50
  45. package/dist/common/user.js +0 -25
  46. package/dist/common/uuid.js +0 -65
  47. package/dist/common/yaml.js +0 -63
  48. package/dist/node/base64.js +0 -52
  49. package/dist/node/diff.js +0 -49
  50. package/dist/node/hash.js +0 -84
  51. package/dist/node/index.js +0 -21
  52. package/dist/node/payload.js +0 -24
  53. package/dist/node/secret.js +0 -33
  54. package/dist/web/_index.js +0 -25
  55. package/dist/web/actions.js +0 -25
  56. package/dist/web/base64.js +0 -50
  57. package/dist/web/event.js +0 -25
  58. package/dist/web/event_log.js +0 -25
  59. package/dist/web/format.js +0 -30
  60. package/dist/web/global.js +0 -25
  61. package/dist/web/index.js +0 -32
  62. package/dist/web/input.js +0 -25
  63. package/dist/web/js.js +0 -25
  64. package/dist/web/location.js +0 -59
  65. package/dist/web/media.js +0 -61
  66. package/dist/web/menu.js +0 -25
  67. package/dist/web/request.js +0 -35
  68. package/dist/web/request_details.js +0 -25
  69. package/dist/web/state.js +0 -25
  70. package/dist/web/url_query.js +0 -25
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,6 +12,10 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import NodeParser from './nodeParser.js';
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';
16
20
  import WebParser from './webParser.js';
17
- export { NodeParser, WebParser };
21
+ export { getFromArray, getFromObject, NodeParser, runClass, runInstance, WebParser };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,22 +13,10 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { serializer, type } from '@lowdefy/helpers';
16
- import commonOperators from './common/index.js';
17
- import nodeOperators from './node/index.js';
18
16
  let NodeParser = class NodeParser {
19
- async init() {
17
+ parse({ args , input , location , operatorPrefix ='_' }) {
18
+ const env = this.env;
20
19
  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
- }));
29
- }
30
- parse({ args , input , location }) {
31
- const operations = this.operations;
32
20
  const secrets = this.secrets;
33
21
  const payload = this.payload;
34
22
  const user = this.user;
@@ -41,38 +29,37 @@ let NodeParser = class NodeParser {
41
29
  if (args && !type.isArray(args)) {
42
30
  throw new Error('Operator parser args must be an array.');
43
31
  }
44
- if (location && !type.isString(location)) {
32
+ if (!type.isString(location)) {
45
33
  throw new Error('Operator parser location must be a string.');
46
34
  }
47
35
  const errors = [];
48
36
  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
- }
37
+ if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
38
+ const key = Object.keys(value)[0];
39
+ if (!key.startsWith(operatorPrefix)) return value;
40
+ const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
41
+ if (type.isUndefined(operators[op])) return value;
42
+ try {
43
+ const res = operators[op]({
44
+ args,
45
+ arrayIndices: [],
46
+ env,
47
+ location,
48
+ methodName,
49
+ operators: operators,
50
+ params: value[key],
51
+ operatorPrefix,
52
+ parser: this,
53
+ payload,
54
+ secrets,
55
+ user
56
+ });
57
+ return res;
58
+ } catch (e) {
59
+ errors.push(e);
60
+ console.error(e);
61
+ return null;
74
62
  }
75
- return value;
76
63
  };
77
64
  return {
78
65
  output: serializer.copy(input, {
@@ -81,18 +68,13 @@ let NodeParser = class NodeParser {
81
68
  errors
82
69
  };
83
70
  }
84
- constructor({ payload , secrets , user } = {
85
- }){
71
+ constructor({ env , payload , secrets , user , operators }){
72
+ this.env = env;
73
+ this.operators = operators;
86
74
  this.payload = payload;
87
75
  this.secrets = secrets;
88
76
  this.user = user;
89
77
  this.parse = this.parse.bind(this);
90
- this.operators = {
91
- ...commonOperators,
92
- ...nodeOperators
93
- };
94
- this.operations = {
95
- };
96
78
  }
97
79
  };
98
80
  export default NodeParser;
package/dist/runClass.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/webParser.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,30 +13,9 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
- import commonOperators from './common/index.js';
17
- import webOperators from './web/index.js';
18
16
  let WebParser = class WebParser {
19
- async init() {
20
- if (!type.isObject(this.context._internal.lowdefy)) {
21
- throw new Error('context._internal.lowdefy must be an object.');
22
- }
23
- if (!type.isArray(this.context._internal.operators)) {
24
- throw new Error('context._internal.operators must be an array.');
25
- }
17
+ parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
26
18
  const operators = this.operators;
27
- const operations = this.operations;
28
- await Promise.all(this.context._internal.operators.map(async (operator)=>{
29
- if (operators[operator]) {
30
- const fn = await import(`./${operators[operator]}.js`);
31
- operations[operator] = fn.default;
32
- if (operations[operator].init) {
33
- await operations[operator].init();
34
- }
35
- }
36
- }));
37
- }
38
- parse({ actions , args , arrayIndices , event , input , location }) {
39
- const operations = this.operations;
40
19
  const context = this.context;
41
20
  if (type.isUndefined(input)) {
42
21
  return {
@@ -50,52 +29,45 @@ let WebParser = class WebParser {
50
29
  if (args && !type.isArray(args)) {
51
30
  throw new Error('Operator parser args must be an array.');
52
31
  }
53
- if (location && !type.isString(location)) {
32
+ if (!type.isString(location)) {
54
33
  throw new Error('Operator parser location must be a string.');
55
34
  }
56
35
  const errors = [];
57
36
  const { inputs , lowdefyGlobal , menus , urlQuery , user } = context._internal.lowdefy;
58
37
  const reviver = (_, value)=>{
59
- if (type.isObject(value) && Object.keys(value).length === 1) {
60
- const key = Object.keys(value)[0];
61
- const [op, methodName] = key.split('.');
62
- try {
63
- if (!type.isUndefined(operations[op])) {
64
- const res = operations[op]({
65
- eventLog: context.eventLog,
66
- actions,
67
- args,
68
- arrayIndices,
69
- context: context,
70
- env: 'web',
71
- event,
72
- input: inputs ? inputs[context.id] : {
73
- },
74
- location: location ? applyArrayIndices(arrayIndices, location) : null,
75
- lowdefyGlobal: lowdefyGlobal || {
76
- },
77
- menus: menus || {
78
- },
79
- methodName,
80
- operations: operations,
81
- params: value[key],
82
- requests: context.requests,
83
- state: context.state,
84
- urlQuery: urlQuery || {
85
- },
86
- user: user || {
87
- },
88
- parser: this
89
- });
90
- return res;
91
- }
92
- } catch (e) {
93
- errors.push(e);
94
- console.error(e);
95
- return null;
96
- }
38
+ if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
39
+ const key = Object.keys(value)[0];
40
+ if (!key.startsWith(operatorPrefix)) return value;
41
+ const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
42
+ if (type.isUndefined(operators[op])) return value;
43
+ try {
44
+ const res = operators[op]({
45
+ eventLog: context.eventLog,
46
+ actions,
47
+ args,
48
+ arrayIndices,
49
+ context,
50
+ event,
51
+ input: inputs ? inputs[context.id] : {},
52
+ location: applyArrayIndices(arrayIndices, location),
53
+ lowdefyGlobal: lowdefyGlobal || {},
54
+ menus: menus || {},
55
+ methodName,
56
+ operators,
57
+ operatorPrefix,
58
+ params: value[key],
59
+ requests: context.requests,
60
+ state: context.state,
61
+ urlQuery: urlQuery || {},
62
+ user: user || {},
63
+ parser: this
64
+ });
65
+ return res;
66
+ } catch (e) {
67
+ errors.push(e);
68
+ console.error(e);
69
+ return null;
97
70
  }
98
- return value;
99
71
  };
100
72
  return {
101
73
  output: serializer.copy(input, {
@@ -104,16 +76,10 @@ let WebParser = class WebParser {
104
76
  errors
105
77
  };
106
78
  }
107
- constructor({ context }){
79
+ constructor({ context , operators }){
108
80
  this.context = context;
109
- this.init = this.init.bind(this);
110
81
  this.parse = this.parse.bind(this);
111
- this.operators = {
112
- ...commonOperators,
113
- ...webOperators
114
- };
115
- this.operations = {
116
- };
82
+ this.operators = operators;
117
83
  }
118
84
  };
119
85
  export default WebParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.10",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -18,6 +18,10 @@
18
18
  {
19
19
  "name": "Gerrie van Wyk",
20
20
  "url": "https://github.com/Gervwyk"
21
+ },
22
+ {
23
+ "name": "Johann Möller",
24
+ "url": "https://github.com/JohannMoller"
21
25
  }
22
26
  ],
23
27
  "repository": {
@@ -38,23 +42,16 @@
38
42
  "test:watch": "jest --coverage --watch"
39
43
  },
40
44
  "dependencies": {
41
- "@lowdefy/format": "4.0.0-alpha.1",
42
- "@lowdefy/helpers": "4.0.0-alpha.1",
43
- "@lowdefy/nunjucks": "4.0.0-alpha.1",
44
- "change-case": "4.1.2",
45
- "deep-diff": "1.0.2",
46
- "js-yaml": "4.1.0",
47
- "mingo": "4.2.0",
48
- "uuid": "8.3.2"
45
+ "@lowdefy/helpers": "4.0.0-alpha.10"
49
46
  },
50
47
  "devDependencies": {
51
- "@swc/cli": "0.1.52",
52
- "@swc/core": "1.2.112",
53
- "@swc/jest": "0.2.9",
54
- "jest": "27.3.1"
48
+ "@swc/cli": "0.1.55",
49
+ "@swc/core": "1.2.135",
50
+ "@swc/jest": "0.2.17",
51
+ "jest": "27.5.1"
55
52
  },
56
53
  "publishConfig": {
57
54
  "access": "public"
58
55
  },
59
- "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
56
+ "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
60
57
  }
@@ -1,23 +0,0 @@
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 { type } from '@lowdefy/helpers';
16
- function _and({ params , location }) {
17
- if (!type.isArray(params)) {
18
- throw new Error(`Operator Error: _and takes an array type. Received: ${JSON.stringify(params)} at ${location}.`);
19
- }
20
- return !!params.reduce((acc, el)=>acc && el
21
- , true);
22
- }
23
- export default _and;
@@ -1,25 +0,0 @@
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 _args({ args , arrayIndices , location , params }) {
17
- return getFromObject({
18
- arrayIndices,
19
- location,
20
- object: args,
21
- operator: '_args',
22
- params
23
- });
24
- }
25
- export default _args;
@@ -1,261 +0,0 @@
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 { type } from '@lowdefy/helpers';
16
- import runInstance from '../runInstance.js';
17
- const prep = (args)=>{
18
- if (type.isNone(args[0])) {
19
- args[0] = [];
20
- }
21
- return args;
22
- };
23
- const meta = {
24
- concat: {
25
- prep,
26
- validTypes: [
27
- 'array'
28
- ]
29
- },
30
- copyWithin: {
31
- namedArgs: [
32
- 'on',
33
- 'target',
34
- 'start',
35
- 'end'
36
- ],
37
- prep,
38
- validTypes: [
39
- 'array',
40
- 'object'
41
- ]
42
- },
43
- every: {
44
- namedArgs: [
45
- 'on',
46
- 'callback'
47
- ],
48
- prep,
49
- validTypes: [
50
- 'array',
51
- 'object'
52
- ]
53
- },
54
- fill: {
55
- namedArgs: [
56
- 'on',
57
- 'value',
58
- 'start',
59
- 'end'
60
- ],
61
- prep,
62
- validTypes: [
63
- 'array',
64
- 'object'
65
- ]
66
- },
67
- filter: {
68
- namedArgs: [
69
- 'on',
70
- 'callback'
71
- ],
72
- prep,
73
- validTypes: [
74
- 'array',
75
- 'object'
76
- ]
77
- },
78
- find: {
79
- namedArgs: [
80
- 'on',
81
- 'callback'
82
- ],
83
- prep,
84
- validTypes: [
85
- 'array',
86
- 'object'
87
- ]
88
- },
89
- findIndex: {
90
- namedArgs: [
91
- 'on',
92
- 'callback'
93
- ],
94
- prep,
95
- validTypes: [
96
- 'array',
97
- 'object'
98
- ]
99
- },
100
- flat: {
101
- namedArgs: [
102
- 'on',
103
- 'depth'
104
- ],
105
- prep,
106
- validTypes: [
107
- 'array',
108
- 'object'
109
- ]
110
- },
111
- includes: {
112
- namedArgs: [
113
- 'on',
114
- 'value'
115
- ],
116
- prep,
117
- validTypes: [
118
- 'array',
119
- 'object'
120
- ]
121
- },
122
- indexOf: {
123
- namedArgs: [
124
- 'on',
125
- 'value'
126
- ],
127
- prep,
128
- validTypes: [
129
- 'array',
130
- 'object'
131
- ]
132
- },
133
- join: {
134
- namedArgs: [
135
- 'on',
136
- 'separator'
137
- ],
138
- prep,
139
- validTypes: [
140
- 'array',
141
- 'object'
142
- ]
143
- },
144
- lastIndexOf: {
145
- namedArgs: [
146
- 'on',
147
- 'value'
148
- ],
149
- prep,
150
- validTypes: [
151
- 'array',
152
- 'object'
153
- ]
154
- },
155
- map: {
156
- namedArgs: [
157
- 'on',
158
- 'callback'
159
- ],
160
- prep,
161
- validTypes: [
162
- 'array',
163
- 'object'
164
- ]
165
- },
166
- reduce: {
167
- namedArgs: [
168
- 'on',
169
- 'callback',
170
- 'initialValue'
171
- ],
172
- prep,
173
- validTypes: [
174
- 'array',
175
- 'object'
176
- ]
177
- },
178
- reduceRight: {
179
- namedArgs: [
180
- 'on',
181
- 'callback',
182
- 'initialValue'
183
- ],
184
- prep,
185
- validTypes: [
186
- 'array',
187
- 'object'
188
- ]
189
- },
190
- reverse: {
191
- prep,
192
- validTypes: [
193
- 'array'
194
- ],
195
- singleArg: true
196
- },
197
- slice: {
198
- namedArgs: [
199
- 'on',
200
- 'start',
201
- 'end'
202
- ],
203
- prep,
204
- validTypes: [
205
- 'array',
206
- 'object'
207
- ]
208
- },
209
- some: {
210
- namedArgs: [
211
- 'on',
212
- 'callback'
213
- ],
214
- prep,
215
- validTypes: [
216
- 'array',
217
- 'object'
218
- ]
219
- },
220
- sort: {
221
- namedArgs: [
222
- 'on'
223
- ],
224
- prep,
225
- validTypes: [
226
- 'array'
227
- ]
228
- },
229
- splice: {
230
- namedArgs: [
231
- 'on',
232
- 'start',
233
- 'deleteCount'
234
- ],
235
- spreadArgs: 'insert',
236
- returnInstance: true,
237
- prep,
238
- validTypes: [
239
- 'array',
240
- 'object'
241
- ]
242
- },
243
- length: {
244
- validTypes: [
245
- 'array'
246
- ],
247
- prep,
248
- property: true
249
- }
250
- };
251
- function _array({ params , location , methodName }) {
252
- return runInstance({
253
- location,
254
- meta,
255
- methodName,
256
- operator: '_array',
257
- params,
258
- instanceType: 'array'
259
- });
260
- }
261
- export default _array;