@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.
- package/dist/common/change_case.js +114 -160
- package/dist/common/index.js +39 -54
- package/dist/common/mql.js +93 -102
- package/dist/common/uuid.js +48 -59
- package/dist/common/yaml.js +56 -63
- package/dist/getFromArray.js +22 -44
- package/dist/getFromObject.js +25 -70
- package/dist/index.js +18 -20
- package/dist/node/diff.js +30 -47
- package/dist/node/index.js +6 -14
- package/dist/nodeParser.js +83 -146
- package/dist/runClass.js +57 -82
- package/dist/runInstance.js +60 -84
- package/dist/web/format.js +15 -37
- package/dist/web/index.js +17 -21
- package/dist/web/js.js +10 -30
- package/dist/webParser.js +99 -157
- package/package.json +16 -15
- package/dist/common/_index.js +0 -45
- package/dist/common/and.js +0 -39
- package/dist/common/args.js +0 -46
- package/dist/common/array.js +0 -170
- package/dist/common/date.js +0 -75
- package/dist/common/divide.js +0 -51
- package/dist/common/eq.js +0 -43
- package/dist/common/event.js +0 -46
- package/dist/common/function.js +0 -78
- package/dist/common/get.js +0 -61
- package/dist/common/global.js +0 -50
- package/dist/common/gt.js +0 -43
- package/dist/common/gte.js +0 -43
- package/dist/common/if.js +0 -41
- package/dist/common/if_none.js +0 -47
- package/dist/common/input.js +0 -50
- package/dist/common/json.js +0 -64
- package/dist/common/log.js +0 -33
- package/dist/common/lt.js +0 -43
- package/dist/common/lte.js +0 -43
- package/dist/common/math.js +0 -210
- package/dist/common/ne.js +0 -43
- package/dist/common/not.js +0 -31
- package/dist/common/number.js +0 -125
- package/dist/common/nunjucks.js +0 -60
- package/dist/common/object.js +0 -118
- package/dist/common/operator.js +0 -49
- package/dist/common/or.js +0 -39
- package/dist/common/product.js +0 -45
- package/dist/common/random.js +0 -132
- package/dist/common/regex.js +0 -65
- package/dist/common/state.js +0 -50
- package/dist/common/string.js +0 -188
- package/dist/common/subtract.js +0 -47
- package/dist/common/sum.js +0 -45
- package/dist/common/switch.js +0 -49
- package/dist/common/type.js +0 -82
- package/dist/common/uri.js +0 -67
- package/dist/common/url_query.js +0 -50
- package/dist/common/user.js +0 -50
- package/dist/getFromOtherContext.js +0 -96
- package/dist/node/base64.js +0 -69
- package/dist/node/hash.js +0 -100
- package/dist/node/secret.js +0 -54
- package/dist/web/actions.js +0 -46
- package/dist/web/base64.js +0 -67
- package/dist/web/event_log.js +0 -50
- package/dist/web/list_contexts.js +0 -31
- package/dist/web/location.js +0 -74
- package/dist/web/media.js +0 -90
- package/dist/web/menu.js +0 -43
- package/dist/web/request.js +0 -56
- package/dist/web/request_details.js +0 -50
package/dist/nodeParser.js
CHANGED
|
@@ -1,149 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
|
-
class NodeParser {
|
|
27
|
-
constructor() {
|
|
28
|
-
var {
|
|
29
|
-
arrayIndices,
|
|
30
|
-
input,
|
|
31
|
-
lowdefyGlobal,
|
|
32
|
-
secrets,
|
|
33
|
-
state,
|
|
34
|
-
urlQuery,
|
|
35
|
-
user
|
|
36
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
|
-
this.arrayIndices = arrayIndices;
|
|
38
|
-
this.input = input;
|
|
39
|
-
this.lowdefyGlobal = lowdefyGlobal;
|
|
40
|
-
this.secrets = secrets;
|
|
41
|
-
this.state = state;
|
|
42
|
-
this.urlQuery = urlQuery;
|
|
43
|
-
this.user = user;
|
|
44
|
-
this.parse = this.parse.bind(this);
|
|
45
|
-
this.operators = _objectSpread(_objectSpread({}, _common.default), _node.default);
|
|
46
|
-
this.operations = {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
init() {
|
|
50
|
-
var _this = this;
|
|
51
|
-
|
|
52
|
-
return _asyncToGenerator(function* () {
|
|
53
|
-
yield Promise.all(Object.keys(_this.operators).map( /*#__PURE__*/function () {
|
|
54
|
-
var _ref = _asyncToGenerator(function* (operator) {
|
|
55
|
-
var fn = require("./".concat(_this.operators[operator], ".js"));
|
|
56
|
-
|
|
57
|
-
_this.operations[operator] = fn.default;
|
|
58
|
-
|
|
59
|
-
if (_this.operations[operator].init) {
|
|
60
|
-
yield _this.operations[operator].init();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return function (_x) {
|
|
65
|
-
return _ref.apply(this, arguments);
|
|
66
|
-
};
|
|
67
|
-
}()));
|
|
68
|
-
})();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
parse(_ref2) {
|
|
72
|
-
var {
|
|
73
|
-
actions,
|
|
74
|
-
args,
|
|
75
|
-
event,
|
|
76
|
-
input,
|
|
77
|
-
location
|
|
78
|
-
} = _ref2;
|
|
79
|
-
|
|
80
|
-
if (_helpers.type.isUndefined(input)) {
|
|
81
|
-
return {
|
|
82
|
-
output: input,
|
|
83
|
-
errors: []
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (event && !_helpers.type.isObject(event)) {
|
|
88
|
-
throw new Error('Operator parser event must be a object.');
|
|
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
|
+
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
|
+
}));
|
|
89
23
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
24
|
+
parse({ args , input , location }) {
|
|
25
|
+
const operators = this.operators;
|
|
26
|
+
const secrets = this.secrets;
|
|
27
|
+
const payload = this.payload;
|
|
28
|
+
const user = this.user;
|
|
29
|
+
if (type.isUndefined(input)) {
|
|
30
|
+
return {
|
|
31
|
+
output: input,
|
|
32
|
+
errors: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (args && !type.isArray(args)) {
|
|
36
|
+
throw new Error('Operator parser args must be an array.');
|
|
37
|
+
}
|
|
38
|
+
if (!type.isString(location)) {
|
|
39
|
+
throw new Error('Operator parser location must be a string.');
|
|
40
|
+
}
|
|
41
|
+
const errors = [];
|
|
42
|
+
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
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
output: serializer.copy(input, {
|
|
73
|
+
reviver
|
|
74
|
+
}),
|
|
75
|
+
errors
|
|
76
|
+
};
|
|
93
77
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
constructor({ payload , secrets , user , operators }){
|
|
79
|
+
this.operators = operators;
|
|
80
|
+
this.payload = payload;
|
|
81
|
+
this.secrets = secrets;
|
|
82
|
+
this.user = user;
|
|
83
|
+
this.parse = this.parse.bind(this);
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var reviver = (_, value) => {
|
|
102
|
-
if (_helpers.type.isObject(value) && Object.keys(value).length === 1) {
|
|
103
|
-
var key = Object.keys(value)[0];
|
|
104
|
-
var [op, methodName] = key.split('.');
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
if (!_helpers.type.isUndefined(this.operations[op])) {
|
|
108
|
-
var res = this.operations[op]({
|
|
109
|
-
actions,
|
|
110
|
-
args,
|
|
111
|
-
arrayIndices: this.arrayIndices,
|
|
112
|
-
env: 'node',
|
|
113
|
-
event,
|
|
114
|
-
input: this.input,
|
|
115
|
-
location,
|
|
116
|
-
lowdefyGlobal: this.lowdefyGlobal,
|
|
117
|
-
methodName,
|
|
118
|
-
operations: this.operations,
|
|
119
|
-
params: value[key],
|
|
120
|
-
secrets: this.secrets,
|
|
121
|
-
state: this.state,
|
|
122
|
-
urlQuery: this.urlQuery,
|
|
123
|
-
user: this.user,
|
|
124
|
-
parser: this
|
|
125
|
-
});
|
|
126
|
-
return res;
|
|
127
|
-
}
|
|
128
|
-
} catch (e) {
|
|
129
|
-
errors.push(e);
|
|
130
|
-
console.error(e);
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return value;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
output: _helpers.serializer.copy(input, {
|
|
140
|
-
reviver
|
|
141
|
-
}),
|
|
142
|
-
errors
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var _default = NodeParser;
|
|
149
|
-
exports.default = _default;
|
|
85
|
+
};
|
|
86
|
+
export default NodeParser;
|
package/dist/runClass.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,82 +12,66 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
methodName
|
|
39
|
-
}
|
|
40
|
-
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
const runClass = ({ location , meta , methodName , operator , params , functions , defaultFunction })=>{
|
|
17
|
+
if (!methodName) {
|
|
18
|
+
if (meta[params]) {
|
|
19
|
+
methodName = params;
|
|
20
|
+
} else if (defaultFunction) {
|
|
21
|
+
methodName = defaultFunction;
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(`Operator Error: ${operator} requires a valid method name, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
24
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!meta[methodName] && !functions[methodName]) {
|
|
28
|
+
throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
29
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
30
|
+
}
|
|
31
|
+
// validate params type
|
|
32
|
+
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
|
|
33
|
+
throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
|
|
34
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
35
|
+
}
|
|
36
|
+
if (meta[methodName].noArgs) {
|
|
37
|
+
try {
|
|
38
|
+
return functions[methodName]();
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error(`Operator Error: ${operator}: - ${e.message} Received: {"${operator}":${JSON.stringify(params)}} at ${location}.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let args = [];
|
|
44
|
+
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
45
|
+
args = [
|
|
46
|
+
params
|
|
47
|
+
];
|
|
41
48
|
} else {
|
|
42
|
-
|
|
49
|
+
if (type.isArray(params)) {
|
|
50
|
+
args = params;
|
|
51
|
+
}
|
|
52
|
+
if (type.isObject(params)) {
|
|
53
|
+
args.push(...(meta[methodName].namedArgs || []).map((key)=>params[key]
|
|
54
|
+
));
|
|
55
|
+
if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
|
|
56
|
+
throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
|
|
57
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
58
|
+
}
|
|
59
|
+
args.push(...params[meta[methodName].spreadArgs] || []);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} // validate params type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(_helpers.type.typeOf(params))) {
|
|
52
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " accepts one of the following types: ").concat(meta[methodName].validTypes.join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (meta[methodName].noArgs) {
|
|
56
|
-
try {
|
|
57
|
-
return functions[methodName]();
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new Error("Operator Error: ".concat(operator, ": - ").concat(e.message, " Received: {\"").concat(operator, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
62
|
+
if (type.isFunction(meta[methodName].prep)) {
|
|
63
|
+
args = meta[methodName].prep(args, {
|
|
64
|
+
location
|
|
65
|
+
});
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
66
|
-
args = [params];
|
|
67
|
-
} else {
|
|
68
|
-
if (_helpers.type.isArray(params)) {
|
|
69
|
-
args = params;
|
|
67
|
+
// for property
|
|
68
|
+
if (meta[methodName].property) {
|
|
69
|
+
return functions[methodName];
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!_helpers.type.isNone(meta[methodName].spreadArgs) && !_helpers.type.isArray(params[meta[methodName].spreadArgs])) {
|
|
76
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " takes an array as input argument for ").concat(meta[methodName].spreadArgs, ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
args.push(...(params[meta[methodName].spreadArgs] || []));
|
|
71
|
+
try {
|
|
72
|
+
return functions[methodName](...args);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
80
75
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (_helpers.type.isFunction(meta[methodName].prep)) {
|
|
84
|
-
args = meta[methodName].prep(args, {
|
|
85
|
-
location
|
|
86
|
-
});
|
|
87
|
-
} // for property
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (meta[methodName].property) {
|
|
91
|
-
return functions[methodName];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
return functions[methodName](...args);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " - ").concat(e.message, " Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
98
|
-
}
|
|
99
76
|
};
|
|
100
|
-
|
|
101
|
-
var _default = runClass;
|
|
102
|
-
exports.default = _default;
|
|
77
|
+
export default runClass;
|
package/dist/runInstance.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,81 +12,66 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
methodName,
|
|
30
|
-
operator,
|
|
31
|
-
params,
|
|
32
|
-
instanceType
|
|
33
|
-
} = _ref;
|
|
34
|
-
|
|
35
|
-
if (!meta[methodName]) {
|
|
36
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " is not supported, use one of the following: ").concat(Object.keys(meta).join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
37
|
-
} // validate params type
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(_helpers.type.typeOf(params))) {
|
|
41
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " accepts one of the following types: ").concat(meta[methodName].validTypes.join(', '), ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var instance;
|
|
45
|
-
var args = [];
|
|
46
|
-
|
|
47
|
-
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
48
|
-
instance = params;
|
|
49
|
-
} else {
|
|
50
|
-
if (_helpers.type.isArray(params)) {
|
|
51
|
-
// Instance must be zero in list args.
|
|
52
|
-
instance = params[0];
|
|
53
|
-
args = params.slice(1);
|
|
54
|
-
} // Instance must be listed first in named args.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (_helpers.type.isObject(params)) {
|
|
58
|
-
instance = params[meta[methodName].namedArgs[0]];
|
|
59
|
-
args.push(...meta[methodName].namedArgs.slice(1).map(key => params[key]));
|
|
60
|
-
|
|
61
|
-
if (!_helpers.type.isNone(meta[methodName].spreadArgs) && !_helpers.type.isArray(params[meta[methodName].spreadArgs])) {
|
|
62
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " takes an array as input argument for ").concat(meta[methodName].spreadArgs, ".\n Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
args.push(...(params[meta[methodName].spreadArgs] || []));
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
const runInstance = ({ location , meta , methodName , operator , params , instanceType })=>{
|
|
17
|
+
if (!meta[methodName]) {
|
|
18
|
+
throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
|
|
19
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
66
20
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
21
|
+
// validate params type
|
|
22
|
+
if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
|
|
23
|
+
throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
|
|
24
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
25
|
+
}
|
|
26
|
+
let instance;
|
|
27
|
+
let args = [];
|
|
28
|
+
if (meta[methodName].singleArg || meta[methodName].property) {
|
|
29
|
+
instance = params;
|
|
30
|
+
} else {
|
|
31
|
+
if (type.isArray(params)) {
|
|
32
|
+
// Instance must be zero in list args.
|
|
33
|
+
instance = params[0];
|
|
34
|
+
args = params.slice(1);
|
|
35
|
+
}
|
|
36
|
+
// Instance must be listed first in named args.
|
|
37
|
+
if (type.isObject(params)) {
|
|
38
|
+
instance = params[meta[methodName].namedArgs[0]];
|
|
39
|
+
args.push(...meta[methodName].namedArgs.slice(1).map((key)=>params[key]
|
|
40
|
+
));
|
|
41
|
+
if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
|
|
42
|
+
throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
|
|
43
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
44
|
+
}
|
|
45
|
+
args.push(...params[meta[methodName].spreadArgs] || []);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (type.isFunction(meta[methodName].prep)) {
|
|
49
|
+
[instance, ...args] = meta[methodName].prep([
|
|
50
|
+
instance,
|
|
51
|
+
...args
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if (type.typeOf(instance) !== instanceType) {
|
|
55
|
+
throw new Error(`Operator Error: ${operator}.${methodName} must be evaluated on an ${instanceType} instance. For named args provide an ${instanceType} instance to the "on" property, for listed args provide and ${instanceType} instance as the first element in the operator argument array.
|
|
56
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
57
|
+
}
|
|
58
|
+
// Error for invalid method key.
|
|
59
|
+
if (type.isNone(instance[methodName])) {
|
|
60
|
+
throw new Error(`Operator Error: ${operator} must be evaluated using one of the following: ${Object.keys(meta).join(', ')}.
|
|
61
|
+
Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
62
|
+
}
|
|
63
|
+
// for property
|
|
64
|
+
if (meta[methodName].property) {
|
|
65
|
+
return instance[methodName];
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const result = instance[methodName](...args);
|
|
69
|
+
if (meta[methodName].returnInstance) {
|
|
70
|
+
return instance;
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
92
75
|
}
|
|
93
|
-
|
|
94
|
-
return result;
|
|
95
|
-
} catch (e) {
|
|
96
|
-
throw new Error("Operator Error: ".concat(operator, ".").concat(methodName, " - ").concat(e.message, " Received: {\"").concat(operator, ".").concat(methodName, "\":").concat(JSON.stringify(params), "} at ").concat(location, "."));
|
|
97
|
-
}
|
|
98
76
|
};
|
|
99
|
-
|
|
100
|
-
var _default = runInstance;
|
|
101
|
-
exports.default = _default;
|
|
77
|
+
export default runInstance;
|
package/dist/web/format.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
|
-
var _format2 = _interopRequireDefault(require("@lowdefy/format"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
1
|
/*
|
|
15
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
16
3
|
|
|
@@ -25,28 +12,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
13
|
See the License for the specific language governing permissions and
|
|
27
14
|
limitations under the License.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!_helpers.type.isObject(params.params) && !_helpers.type.isUndefined(params.params)) {
|
|
45
|
-
throw new Error("Operator Error: _format params argument should be an object or undefined. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return _format2.default[methodName](params.params)(params.on);
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import formatters from '@lowdefy/format';
|
|
17
|
+
function _format({ location , methodName , params }) {
|
|
18
|
+
if (!formatters[methodName]) {
|
|
19
|
+
throw new Error(`Operator Error: $_format.${methodName} is not supported, use one of the following: ${Object.keys(formatters).join(', ')}.
|
|
20
|
+
Received: {"_format.${methodName}":${JSON.stringify(params)}} at ${location}.`);
|
|
21
|
+
}
|
|
22
|
+
if (!type.isObject(params)) {
|
|
23
|
+
throw new Error(`Operator Error: _format takes an object as arguments. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
24
|
+
}
|
|
25
|
+
if (!type.isObject(params.params) && !type.isUndefined(params.params)) {
|
|
26
|
+
throw new Error(`Operator Error: _format params argument should be an object or undefined. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
27
|
+
}
|
|
28
|
+
return formatters[methodName](params.params)(params.on);
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
var _default = _format;
|
|
52
|
-
exports.default = _default;
|
|
30
|
+
export default _format;
|
package/dist/web/index.js
CHANGED
|
@@ -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,18 +12,21 @@ 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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
*/ export default {
|
|
16
|
+
_actions: 'web/actions',
|
|
17
|
+
_base64: 'web/base64',
|
|
18
|
+
_event_log: 'web/event_log',
|
|
19
|
+
_event: 'web/event',
|
|
20
|
+
_format: 'web/format',
|
|
21
|
+
_global: 'web/global',
|
|
22
|
+
_index: 'web/_index',
|
|
23
|
+
_input: 'web/input',
|
|
24
|
+
_js: 'web/js',
|
|
25
|
+
_location: 'web/location',
|
|
26
|
+
_media: 'web/media',
|
|
27
|
+
_menu: 'web/menu',
|
|
28
|
+
_request_details: 'web/request_details',
|
|
29
|
+
_request: 'web/request',
|
|
30
|
+
_state: 'web/state',
|
|
31
|
+
_url_query: 'web/url_query'
|
|
35
32
|
};
|
|
36
|
-
exports.default = _default;
|