@lowdefy/operators 4.0.0-alpha.6 → 4.0.0-alpha.9

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.
@@ -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.
@@ -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.
@@ -14,14 +14,8 @@
14
14
  limitations under the License.
15
15
  */ import { serializer, type } from '@lowdefy/helpers';
16
16
  let NodeParser = class NodeParser {
17
- async init() {
18
- await Promise.all(Object.values(this.operators).map(async (operator)=>{
19
- if (operator.init) {
20
- await operator.init();
21
- }
22
- }));
23
- }
24
- parse({ args , input , location }) {
17
+ parse({ args , input , location , operatorPrefix ='_' }) {
18
+ const env = this.env;
25
19
  const operators = this.operators;
26
20
  const secrets = this.secrets;
27
21
  const payload = this.payload;
@@ -40,33 +34,32 @@ let NodeParser = class NodeParser {
40
34
  }
41
35
  const errors = [];
42
36
  const reviver = (_, value)=>{
43
- if (type.isObject(value) && Object.keys(value).length === 1) {
44
- const key = Object.keys(value)[0];
45
- const [op, methodName] = key.split('.');
46
- try {
47
- if (!type.isUndefined(operators[op])) {
48
- const res = operators[op]({
49
- args,
50
- arrayIndices: [],
51
- env: 'node',
52
- location,
53
- methodName,
54
- operators: operators,
55
- params: value[key],
56
- secrets,
57
- payload,
58
- user,
59
- parser: this
60
- });
61
- return res;
62
- }
63
- } catch (e) {
64
- errors.push(e);
65
- console.error(e);
66
- return null;
67
- }
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;
68
62
  }
69
- return value;
70
63
  };
71
64
  return {
72
65
  output: serializer.copy(input, {
@@ -75,7 +68,8 @@ let NodeParser = class NodeParser {
75
68
  errors
76
69
  };
77
70
  }
78
- constructor({ payload , secrets , user , operators }){
71
+ constructor({ env , payload , secrets , user , operators }){
72
+ this.env = env;
79
73
  this.operators = operators;
80
74
  this.payload = payload;
81
75
  this.secrets = secrets;
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.
@@ -14,17 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
16
  let WebParser = class WebParser {
17
- async init() {
18
- if (!type.isObject(this.context._internal.lowdefy)) {
19
- throw new Error('context._internal.lowdefy must be an object.');
20
- }
21
- await Promise.all(Object.values(this.operators).map(async (operator)=>{
22
- if (operator.init) {
23
- await operator.init();
24
- }
25
- }));
26
- }
27
- parse({ actions , args , arrayIndices , event , input , location }) {
17
+ parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
28
18
  const operators = this.operators;
29
19
  const context = this.context;
30
20
  if (type.isUndefined(input)) {
@@ -45,41 +35,39 @@ let WebParser = class WebParser {
45
35
  const errors = [];
46
36
  const { inputs , lowdefyGlobal , menus , urlQuery , user } = context._internal.lowdefy;
47
37
  const reviver = (_, value)=>{
48
- if (type.isObject(value) && Object.keys(value).length === 1) {
49
- const key = Object.keys(value)[0];
50
- const [op, methodName] = key.split('.');
51
- try {
52
- if (!type.isUndefined(operators[op])) {
53
- const res = operators[op]({
54
- eventLog: context.eventLog,
55
- actions,
56
- args,
57
- arrayIndices,
58
- context: context,
59
- env: 'web',
60
- event,
61
- input: inputs ? inputs[context.id] : {},
62
- location: applyArrayIndices(arrayIndices, location),
63
- lowdefyGlobal: lowdefyGlobal || {},
64
- menus: menus || {},
65
- methodName,
66
- operators: operators,
67
- params: value[key],
68
- requests: context.requests,
69
- state: context.state,
70
- urlQuery: urlQuery || {},
71
- user: user || {},
72
- parser: this
73
- });
74
- return res;
75
- }
76
- } catch (e) {
77
- errors.push(e);
78
- console.error(e);
79
- return null;
80
- }
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;
81
70
  }
82
- return value;
83
71
  };
84
72
  return {
85
73
  output: serializer.copy(input, {
@@ -90,7 +78,6 @@ let WebParser = class WebParser {
90
78
  }
91
79
  constructor({ context , operators }){
92
80
  this.context = context;
93
- this.init = this.init.bind(this);
94
81
  this.parse = this.parse.bind(this);
95
82
  this.operators = operators;
96
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.9",
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,16 +42,16 @@
38
42
  "test:watch": "jest --coverage --watch"
39
43
  },
40
44
  "dependencies": {
41
- "@lowdefy/helpers": "4.0.0-alpha.6"
45
+ "@lowdefy/helpers": "4.0.0-alpha.9"
42
46
  },
43
47
  "devDependencies": {
44
48
  "@swc/cli": "0.1.55",
45
- "@swc/core": "1.2.130",
49
+ "@swc/core": "1.2.135",
46
50
  "@swc/jest": "0.2.17",
47
- "jest": "27.3.1"
51
+ "jest": "27.5.1"
48
52
  },
49
53
  "publishConfig": {
50
54
  "access": "public"
51
55
  },
52
- "gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
56
+ "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
53
57
  }