@lowdefy/operators 4.0.0-alpha.4 → 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 (56) hide show
  1. package/dist/index.js +6 -2
  2. package/dist/nodeParser.js +10 -22
  3. package/dist/webParser.js +11 -27
  4. package/package.json +5 -5
  5. package/dist/common/and.js +0 -23
  6. package/dist/common/args.js +0 -25
  7. package/dist/common/array.js +0 -261
  8. package/dist/common/date.js +0 -54
  9. package/dist/common/divide.js +0 -31
  10. package/dist/common/eq.js +0 -25
  11. package/dist/common/function.js +0 -46
  12. package/dist/common/get.js +0 -36
  13. package/dist/common/gt.js +0 -25
  14. package/dist/common/gte.js +0 -25
  15. package/dist/common/if.js +0 -24
  16. package/dist/common/if_none.js +0 -28
  17. package/dist/common/json.js +0 -60
  18. package/dist/common/log.js +0 -20
  19. package/dist/common/lt.js +0 -25
  20. package/dist/common/lte.js +0 -25
  21. package/dist/common/math.js +0 -271
  22. package/dist/common/ne.js +0 -25
  23. package/dist/common/not.js +0 -18
  24. package/dist/common/number.js +0 -147
  25. package/dist/common/nunjucks.js +0 -40
  26. package/dist/common/object.js +0 -109
  27. package/dist/common/operator.js +0 -38
  28. package/dist/common/or.js +0 -23
  29. package/dist/common/product.js +0 -27
  30. package/dist/common/random.js +0 -97
  31. package/dist/common/regex.js +0 -42
  32. package/dist/common/string.js +0 -287
  33. package/dist/common/subtract.js +0 -28
  34. package/dist/common/sum.js +0 -27
  35. package/dist/common/switch.js +0 -30
  36. package/dist/common/type.js +0 -51
  37. package/dist/common/uri.js +0 -50
  38. package/dist/common/user.js +0 -25
  39. package/dist/node/base64.js +0 -52
  40. package/dist/node/hash.js +0 -84
  41. package/dist/node/payload.js +0 -24
  42. package/dist/node/secret.js +0 -33
  43. package/dist/web/_index.js +0 -25
  44. package/dist/web/actions.js +0 -25
  45. package/dist/web/base64.js +0 -50
  46. package/dist/web/event.js +0 -25
  47. package/dist/web/event_log.js +0 -25
  48. package/dist/web/global.js +0 -25
  49. package/dist/web/input.js +0 -25
  50. package/dist/web/location.js +0 -59
  51. package/dist/web/media.js +0 -61
  52. package/dist/web/menu.js +0 -25
  53. package/dist/web/request.js +0 -35
  54. package/dist/web/request_details.js +0 -25
  55. package/dist/web/state.js +0 -25
  56. package/dist/web/url_query.js +0 -25
package/dist/index.js CHANGED
@@ -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 };
@@ -13,22 +13,16 @@
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
17
  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();
18
+ await Promise.all(Object.values(this.operators).map(async (operator)=>{
19
+ if (operator.init) {
20
+ await operator.init();
27
21
  }
28
22
  }));
29
23
  }
30
24
  parse({ args , input , location }) {
31
- const operations = this.operations;
25
+ const operators = this.operators;
32
26
  const secrets = this.secrets;
33
27
  const payload = this.payload;
34
28
  const user = this.user;
@@ -41,7 +35,7 @@ let NodeParser = class NodeParser {
41
35
  if (args && !type.isArray(args)) {
42
36
  throw new Error('Operator parser args must be an array.');
43
37
  }
44
- if (location && !type.isString(location)) {
38
+ if (!type.isString(location)) {
45
39
  throw new Error('Operator parser location must be a string.');
46
40
  }
47
41
  const errors = [];
@@ -50,14 +44,14 @@ let NodeParser = class NodeParser {
50
44
  const key = Object.keys(value)[0];
51
45
  const [op, methodName] = key.split('.');
52
46
  try {
53
- if (!type.isUndefined(operations[op])) {
54
- const res = operations[op]({
47
+ if (!type.isUndefined(operators[op])) {
48
+ const res = operators[op]({
55
49
  args,
56
50
  arrayIndices: [],
57
51
  env: 'node',
58
52
  location,
59
53
  methodName,
60
- operations: operations,
54
+ operators: operators,
61
55
  params: value[key],
62
56
  secrets,
63
57
  payload,
@@ -81,18 +75,12 @@ let NodeParser = class NodeParser {
81
75
  errors
82
76
  };
83
77
  }
84
- constructor({ payload , secrets , user } = {
85
- }){
78
+ constructor({ payload , secrets , user , operators }){
79
+ this.operators = operators;
86
80
  this.payload = payload;
87
81
  this.secrets = secrets;
88
82
  this.user = user;
89
83
  this.parse = this.parse.bind(this);
90
- this.operators = {
91
- ...commonOperators,
92
- ...nodeOperators
93
- };
94
- this.operations = {
95
- };
96
84
  }
97
85
  };
98
86
  export default NodeParser;
package/dist/webParser.js CHANGED
@@ -13,30 +13,19 @@
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
17
  async init() {
20
18
  if (!type.isObject(this.context._internal.lowdefy)) {
21
19
  throw new Error('context._internal.lowdefy must be an object.');
22
20
  }
23
- if (!type.isArray(this.context._internal.operators)) {
24
- throw new Error('context._internal.operators must be an array.');
25
- }
26
- 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
- }
21
+ await Promise.all(Object.values(this.operators).map(async (operator)=>{
22
+ if (operator.init) {
23
+ await operator.init();
35
24
  }
36
25
  }));
37
26
  }
38
27
  parse({ actions , args , arrayIndices , event , input , location }) {
39
- const operations = this.operations;
28
+ const operators = this.operators;
40
29
  const context = this.context;
41
30
  if (type.isUndefined(input)) {
42
31
  return {
@@ -50,7 +39,7 @@ let WebParser = class WebParser {
50
39
  if (args && !type.isArray(args)) {
51
40
  throw new Error('Operator parser args must be an array.');
52
41
  }
53
- if (location && !type.isString(location)) {
42
+ if (!type.isString(location)) {
54
43
  throw new Error('Operator parser location must be a string.');
55
44
  }
56
45
  const errors = [];
@@ -60,8 +49,8 @@ let WebParser = class WebParser {
60
49
  const key = Object.keys(value)[0];
61
50
  const [op, methodName] = key.split('.');
62
51
  try {
63
- if (!type.isUndefined(operations[op])) {
64
- const res = operations[op]({
52
+ if (!type.isUndefined(operators[op])) {
53
+ const res = operators[op]({
65
54
  eventLog: context.eventLog,
66
55
  actions,
67
56
  args,
@@ -71,13 +60,13 @@ let WebParser = class WebParser {
71
60
  event,
72
61
  input: inputs ? inputs[context.id] : {
73
62
  },
74
- location: location ? applyArrayIndices(arrayIndices, location) : null,
63
+ location: applyArrayIndices(arrayIndices, location),
75
64
  lowdefyGlobal: lowdefyGlobal || {
76
65
  },
77
66
  menus: menus || {
78
67
  },
79
68
  methodName,
80
- operations: operations,
69
+ operators: operators,
81
70
  params: value[key],
82
71
  requests: context.requests,
83
72
  state: context.state,
@@ -104,16 +93,11 @@ let WebParser = class WebParser {
104
93
  errors
105
94
  };
106
95
  }
107
- constructor({ context }){
96
+ constructor({ context , operators }){
108
97
  this.context = context;
109
98
  this.init = this.init.bind(this);
110
99
  this.parse = this.parse.bind(this);
111
- this.operators = {
112
- ...commonOperators,
113
- ...webOperators
114
- };
115
- this.operations = {
116
- };
100
+ this.operators = operators;
117
101
  }
118
102
  };
119
103
  export default WebParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.5",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -38,9 +38,9 @@
38
38
  "test:watch": "jest --coverage --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@lowdefy/format": "4.0.0-alpha.4",
42
- "@lowdefy/helpers": "4.0.0-alpha.4",
43
- "@lowdefy/nunjucks": "4.0.0-alpha.4",
41
+ "@lowdefy/format": "4.0.0-alpha.5",
42
+ "@lowdefy/helpers": "4.0.0-alpha.5",
43
+ "@lowdefy/nunjucks": "4.0.0-alpha.5",
44
44
  "change-case": "4.1.2",
45
45
  "deep-diff": "1.0.2",
46
46
  "js-yaml": "4.1.0",
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "537d166ba3f6e017b8a61c2a7e5c12fd0a48bf67"
59
+ "gitHead": "995fcdb020927f3cdc626fc99c15a2e4137bd962"
60
60
  }
@@ -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;
@@ -1,54 +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 runClass from '../runClass.js';
17
- function date(input) {
18
- const result = new Date(input);
19
- if (!type.isDate(result)) {
20
- throw new Error(`${input} could not resolve as a valid javascript date.`);
21
- }
22
- return result;
23
- }
24
- function now() {
25
- return new Date();
26
- }
27
- const functions = {
28
- __default: date,
29
- now
30
- };
31
- const meta = {
32
- __default: {
33
- singleArg: true,
34
- validTypes: [
35
- 'number',
36
- 'string'
37
- ]
38
- },
39
- now: {
40
- noArgs: true
41
- }
42
- };
43
- function _date({ params , location , methodName }) {
44
- return runClass({
45
- functions,
46
- location,
47
- meta,
48
- methodName: methodName,
49
- operator: '_date',
50
- params,
51
- defaultFunction: '__default'
52
- });
53
- }
54
- export default _date;
@@ -1,31 +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 _divide({ params , location }) {
17
- if (!type.isArray(params)) {
18
- throw new Error(`Operator Error: _divide takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
19
- }
20
- if (params.length !== 2) {
21
- throw new Error(`Operator Error: _divide takes an array of length 2 as input. Received: ${JSON.stringify(params)} at ${location}.`);
22
- }
23
- if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
24
- throw new Error(`Operator Error: _divide takes an array of 2 numbers. Received: ${JSON.stringify(params)} at ${location}.`);
25
- }
26
- if (params[1] === 0) {
27
- throw new Error(`Operator Error: _divide by zero not allowed. Received: ${JSON.stringify(params)} at ${location}.`);
28
- }
29
- return params[0] / params[1];
30
- }
31
- export default _divide;
package/dist/common/eq.js DELETED
@@ -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 { type } from '@lowdefy/helpers';
16
- function _eq({ params , location }) {
17
- if (!type.isArray(params)) {
18
- throw new Error(`Operator Error: _eq takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
19
- }
20
- if (params.length !== 2) {
21
- throw new Error(`Operator Error: _eq takes an array of length 2 as input. Received: ${JSON.stringify(params)} at ${location}.`);
22
- }
23
- return params[0] === params[1];
24
- }
25
- export default _eq;
@@ -1,46 +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 { serializer, type } from '@lowdefy/helpers';
16
- function removeUnderscore(_, value) {
17
- if (type.isObject(value) && Object.keys(value).length === 1) {
18
- const key = Object.keys(value)[0];
19
- if (key.startsWith('__')) {
20
- const newKey = key.substring(1);
21
- return {
22
- [newKey]: value[key]
23
- };
24
- }
25
- }
26
- return value;
27
- }
28
- function _function({ arrayIndices , event , location , params , parser }) {
29
- const preparedParams = serializer.copy(params, {
30
- reviver: removeUnderscore
31
- });
32
- return (...args)=>{
33
- const { output , errors } = parser.parse({
34
- arrayIndices,
35
- args,
36
- event,
37
- input: preparedParams,
38
- location
39
- });
40
- if (errors.length > 0) {
41
- throw new Error(errors[0]);
42
- }
43
- return output;
44
- };
45
- }
46
- export default _function;