@lowdefy/operators 4.0.0-rc.5 → 4.0.0-rc.6
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.
- package/dist/buildParser.js +84 -0
- package/dist/index.js +4 -3
- package/dist/{nodeParser.js → serverParser.js} +8 -4
- package/dist/webParser.js +8 -4
- package/package.json +3 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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
|
+
let BuildParser = class BuildParser {
|
|
17
|
+
// TODO: Look at logging here
|
|
18
|
+
// TODO: Remove console.error = () => {}; from tests
|
|
19
|
+
parse({ args , input , location , operatorPrefix ='_' }) {
|
|
20
|
+
if (type.isUndefined(input)) {
|
|
21
|
+
return {
|
|
22
|
+
output: input,
|
|
23
|
+
errors: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (args && !type.isArray(args)) {
|
|
27
|
+
throw new Error('Operator parser args must be an array.');
|
|
28
|
+
}
|
|
29
|
+
if (!type.isString(location)) {
|
|
30
|
+
throw new Error('Operator parser location must be a string.');
|
|
31
|
+
}
|
|
32
|
+
const errors = [];
|
|
33
|
+
const reviver = (_, value)=>{
|
|
34
|
+
if (!type.isObject(value)) return value;
|
|
35
|
+
// TODO: pass _r_ in errors. Build does not have _k_.
|
|
36
|
+
if (type.isString(value._r_)) return value;
|
|
37
|
+
if (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(this.operators[op])) return value;
|
|
42
|
+
try {
|
|
43
|
+
const res = this.operators[op]({
|
|
44
|
+
args,
|
|
45
|
+
arrayIndices: [],
|
|
46
|
+
env: this.env,
|
|
47
|
+
location,
|
|
48
|
+
methodName,
|
|
49
|
+
operators: this.operators,
|
|
50
|
+
params: value[key],
|
|
51
|
+
operatorPrefix,
|
|
52
|
+
parser: this,
|
|
53
|
+
payload: this.payload,
|
|
54
|
+
runtime: 'node',
|
|
55
|
+
secrets: this.secrets,
|
|
56
|
+
user: this.user
|
|
57
|
+
});
|
|
58
|
+
return res;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
errors.push(e);
|
|
61
|
+
if (this.verbose) {
|
|
62
|
+
console.error(e);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
output: serializer.copy(input, {
|
|
69
|
+
reviver
|
|
70
|
+
}),
|
|
71
|
+
errors
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
constructor({ env , payload , secrets , user , operators , verbose }){
|
|
75
|
+
this.env = env;
|
|
76
|
+
this.operators = operators;
|
|
77
|
+
this.parse = this.parse.bind(this);
|
|
78
|
+
this.payload = payload;
|
|
79
|
+
this.secrets = secrets;
|
|
80
|
+
this.user = user;
|
|
81
|
+
this.verbose = verbose;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export default BuildParser;
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,11 @@
|
|
|
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
|
|
15
|
+
*/ import BuildParser from './buildParser.js';
|
|
16
|
+
import getFromArray from './getFromArray.js';
|
|
16
17
|
import getFromObject from './getFromObject.js';
|
|
17
|
-
import
|
|
18
|
+
import ServerParser from './serverParser.js';
|
|
18
19
|
import runClass from './runClass.js';
|
|
19
20
|
import runInstance from './runInstance.js';
|
|
20
21
|
import WebParser from './webParser.js';
|
|
21
|
-
export { getFromArray, getFromObject,
|
|
22
|
+
export { BuildParser, getFromArray, getFromObject, ServerParser, runClass, runInstance, WebParser };
|
|
@@ -13,7 +13,7 @@
|
|
|
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
|
-
let
|
|
16
|
+
let ServerParser = class ServerParser {
|
|
17
17
|
// TODO: Look at logging here
|
|
18
18
|
// TODO: Remove console.error = () => {}; from tests
|
|
19
19
|
parse({ args , input , location , operatorPrefix ='_' }) {
|
|
@@ -31,7 +31,11 @@ let NodeParser = class NodeParser {
|
|
|
31
31
|
}
|
|
32
32
|
const errors = [];
|
|
33
33
|
const reviver = (_, value)=>{
|
|
34
|
-
if (!type.isObject(value)
|
|
34
|
+
if (!type.isObject(value)) return value;
|
|
35
|
+
// TODO: pass _k_ in errors.
|
|
36
|
+
// const _k_ = value._k_;
|
|
37
|
+
delete value._k_;
|
|
38
|
+
if (Object.keys(value).length !== 1) return value;
|
|
35
39
|
const key = Object.keys(value)[0];
|
|
36
40
|
if (!key.startsWith(operatorPrefix)) return value;
|
|
37
41
|
const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
|
|
@@ -75,7 +79,7 @@ let NodeParser = class NodeParser {
|
|
|
75
79
|
this.secrets = secrets;
|
|
76
80
|
this.user = user;
|
|
77
81
|
this.parse = this.parse.bind(this);
|
|
78
|
-
this.verbose;
|
|
82
|
+
this.verbose = verbose;
|
|
79
83
|
}
|
|
80
84
|
};
|
|
81
|
-
export default
|
|
85
|
+
export default ServerParser;
|
package/dist/webParser.js
CHANGED
|
@@ -33,7 +33,11 @@ let WebParser = class WebParser {
|
|
|
33
33
|
const errors = [];
|
|
34
34
|
const { basePath , home , inputs , lowdefyGlobal , menus , pageId , user , _internal } = this.context._internal.lowdefy;
|
|
35
35
|
const reviver = (_, value)=>{
|
|
36
|
-
if (!type.isObject(value)
|
|
36
|
+
if (!type.isObject(value)) return value;
|
|
37
|
+
// TODO: pass _k_ in errors.
|
|
38
|
+
// const _k_ = value._k_;
|
|
39
|
+
delete value._k_;
|
|
40
|
+
if (Object.keys(value).length !== 1) return value;
|
|
37
41
|
const key = Object.keys(value)[0];
|
|
38
42
|
if (!key.startsWith(operatorPrefix)) return value;
|
|
39
43
|
const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
|
|
@@ -48,10 +52,10 @@ let WebParser = class WebParser {
|
|
|
48
52
|
eventLog: this.context.eventLog,
|
|
49
53
|
globals: _internal.globals,
|
|
50
54
|
home,
|
|
51
|
-
input: inputs
|
|
55
|
+
input: inputs[this.context.id],
|
|
52
56
|
location: applyArrayIndices(arrayIndices, location),
|
|
53
|
-
lowdefyGlobal: lowdefyGlobal
|
|
54
|
-
menus: menus
|
|
57
|
+
lowdefyGlobal: lowdefyGlobal,
|
|
58
|
+
menus: menus,
|
|
55
59
|
methodName,
|
|
56
60
|
operatorPrefix,
|
|
57
61
|
operators: this.operators,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=10000"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@lowdefy/helpers": "4.0.0-rc.
|
|
43
|
+
"@lowdefy/helpers": "4.0.0-rc.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jest/globals": "28.1.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "8238145a9eb26c6f3dc48661ab6eca6e3aca4f83"
|
|
57
57
|
}
|