@lowdefy/operators 4.0.0-alpha.1 → 4.0.0-alpha.7
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/index.js +6 -2
- package/dist/nodeParser.js +10 -22
- package/dist/webParser.js +16 -37
- package/package.json +7 -14
- package/dist/common/and.js +0 -23
- package/dist/common/args.js +0 -25
- package/dist/common/array.js +0 -261
- package/dist/common/change_case.js +0 -139
- package/dist/common/date.js +0 -54
- package/dist/common/divide.js +0 -31
- package/dist/common/eq.js +0 -25
- package/dist/common/function.js +0 -46
- package/dist/common/get.js +0 -36
- package/dist/common/gt.js +0 -25
- package/dist/common/gte.js +0 -25
- package/dist/common/if.js +0 -24
- package/dist/common/if_none.js +0 -28
- package/dist/common/index.js +0 -54
- package/dist/common/json.js +0 -60
- package/dist/common/log.js +0 -20
- package/dist/common/lt.js +0 -25
- package/dist/common/lte.js +0 -25
- package/dist/common/math.js +0 -271
- package/dist/common/mql.js +0 -115
- package/dist/common/ne.js +0 -25
- package/dist/common/not.js +0 -18
- package/dist/common/number.js +0 -147
- package/dist/common/nunjucks.js +0 -40
- package/dist/common/object.js +0 -109
- package/dist/common/operator.js +0 -38
- package/dist/common/or.js +0 -23
- package/dist/common/product.js +0 -27
- package/dist/common/random.js +0 -97
- package/dist/common/regex.js +0 -42
- package/dist/common/string.js +0 -287
- package/dist/common/subtract.js +0 -28
- package/dist/common/sum.js +0 -27
- package/dist/common/switch.js +0 -30
- package/dist/common/type.js +0 -51
- package/dist/common/uri.js +0 -50
- package/dist/common/user.js +0 -25
- package/dist/common/uuid.js +0 -65
- package/dist/common/yaml.js +0 -63
- package/dist/node/base64.js +0 -52
- package/dist/node/diff.js +0 -49
- package/dist/node/hash.js +0 -84
- package/dist/node/index.js +0 -21
- package/dist/node/payload.js +0 -24
- package/dist/node/secret.js +0 -33
- package/dist/web/_index.js +0 -25
- package/dist/web/actions.js +0 -25
- package/dist/web/base64.js +0 -50
- package/dist/web/event.js +0 -25
- package/dist/web/event_log.js +0 -25
- package/dist/web/format.js +0 -30
- package/dist/web/global.js +0 -25
- package/dist/web/index.js +0 -32
- package/dist/web/input.js +0 -25
- package/dist/web/js.js +0 -25
- package/dist/web/location.js +0 -59
- package/dist/web/media.js +0 -61
- package/dist/web/menu.js +0 -25
- package/dist/web/request.js +0 -35
- package/dist/web/request_details.js +0 -25
- package/dist/web/state.js +0 -25
- 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
|
|
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 };
|
package/dist/nodeParser.js
CHANGED
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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 (
|
|
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(
|
|
54
|
-
const res =
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
|
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 (
|
|
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(
|
|
64
|
-
const res =
|
|
52
|
+
if (!type.isUndefined(operators[op])) {
|
|
53
|
+
const res = operators[op]({
|
|
65
54
|
eventLog: context.eventLog,
|
|
66
55
|
actions,
|
|
67
56
|
args,
|
|
@@ -69,22 +58,17 @@ let WebParser = class WebParser {
|
|
|
69
58
|
context: context,
|
|
70
59
|
env: 'web',
|
|
71
60
|
event,
|
|
72
|
-
input: inputs ? inputs[context.id] : {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
menus: menus || {
|
|
78
|
-
},
|
|
61
|
+
input: inputs ? inputs[context.id] : {},
|
|
62
|
+
location: applyArrayIndices(arrayIndices, location),
|
|
63
|
+
lowdefyGlobal: lowdefyGlobal || {},
|
|
64
|
+
menus: menus || {},
|
|
79
65
|
methodName,
|
|
80
|
-
|
|
66
|
+
operators: operators,
|
|
81
67
|
params: value[key],
|
|
82
68
|
requests: context.requests,
|
|
83
69
|
state: context.state,
|
|
84
|
-
urlQuery: urlQuery || {
|
|
85
|
-
},
|
|
86
|
-
user: user || {
|
|
87
|
-
},
|
|
70
|
+
urlQuery: urlQuery || {},
|
|
71
|
+
user: user || {},
|
|
88
72
|
parser: this
|
|
89
73
|
});
|
|
90
74
|
return res;
|
|
@@ -104,16 +88,11 @@ let WebParser = class WebParser {
|
|
|
104
88
|
errors
|
|
105
89
|
};
|
|
106
90
|
}
|
|
107
|
-
constructor({ context }){
|
|
91
|
+
constructor({ context , operators }){
|
|
108
92
|
this.context = context;
|
|
109
93
|
this.init = this.init.bind(this);
|
|
110
94
|
this.parse = this.parse.bind(this);
|
|
111
|
-
this.operators =
|
|
112
|
-
...commonOperators,
|
|
113
|
-
...webOperators
|
|
114
|
-
};
|
|
115
|
-
this.operations = {
|
|
116
|
-
};
|
|
95
|
+
this.operators = operators;
|
|
117
96
|
}
|
|
118
97
|
};
|
|
119
98
|
export default WebParser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -38,23 +38,16 @@
|
|
|
38
38
|
"test:watch": "jest --coverage --watch"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@lowdefy/
|
|
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"
|
|
41
|
+
"@lowdefy/helpers": "4.0.0-alpha.7"
|
|
49
42
|
},
|
|
50
43
|
"devDependencies": {
|
|
51
|
-
"@swc/cli": "0.1.
|
|
52
|
-
"@swc/core": "1.2.
|
|
53
|
-
"@swc/jest": "0.2.
|
|
54
|
-
"jest": "27.
|
|
44
|
+
"@swc/cli": "0.1.55",
|
|
45
|
+
"@swc/core": "1.2.135",
|
|
46
|
+
"@swc/jest": "0.2.17",
|
|
47
|
+
"jest": "27.5.1"
|
|
55
48
|
},
|
|
56
49
|
"publishConfig": {
|
|
57
50
|
"access": "public"
|
|
58
51
|
},
|
|
59
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
|
|
60
53
|
}
|
package/dist/common/and.js
DELETED
|
@@ -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;
|
package/dist/common/args.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 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;
|
package/dist/common/array.js
DELETED
|
@@ -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,139 +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
|
-
*/ /* eslint-disable import/namespace */ import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
|
|
16
|
-
import { get, type } from '@lowdefy/helpers';
|
|
17
|
-
import runClass from '../runClass.js';
|
|
18
|
-
const changeCase = {
|
|
19
|
-
camelCase,
|
|
20
|
-
capitalCase,
|
|
21
|
-
constantCase,
|
|
22
|
-
dotCase,
|
|
23
|
-
headerCase,
|
|
24
|
-
noCase,
|
|
25
|
-
paramCase,
|
|
26
|
-
pascalCase,
|
|
27
|
-
pathCase,
|
|
28
|
-
sentenceCase,
|
|
29
|
-
snakeCase
|
|
30
|
-
};
|
|
31
|
-
const prepRegex = (prop, location)=>{
|
|
32
|
-
const regex = type.isString(prop) ? {
|
|
33
|
-
pattern: prop
|
|
34
|
-
} : prop;
|
|
35
|
-
if (!type.isObject(regex)) {
|
|
36
|
-
throw new Error(`Operator Error: regex must be string or an object. Received ${JSON.stringify(prop)} at ${location}.`);
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
return new RegExp(regex.pattern, regex.flags || 'gm');
|
|
40
|
-
} catch (e) {
|
|
41
|
-
throw new Error(`Operator Error: ${e.message}. Received: ${JSON.stringify(prop)} at ${location}.`);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const prep = (args, { location })=>{
|
|
45
|
-
const options = args[1];
|
|
46
|
-
if (!type.isNone(options) && !type.isObject(options)) {
|
|
47
|
-
throw new Error(`Operator Error: options must be an object. Received ${JSON.stringify(options)} at ${location}.`);
|
|
48
|
-
}
|
|
49
|
-
if (type.isObject(options)) {
|
|
50
|
-
if (options.splitRegexp) {
|
|
51
|
-
options.splitRegexp = prepRegex(options.splitRegexp, location);
|
|
52
|
-
}
|
|
53
|
-
if (options.stripRegexp) {
|
|
54
|
-
options.stripRegexp = prepRegex(options.stripRegexp, location);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return args;
|
|
58
|
-
};
|
|
59
|
-
const convertArray = ({ methodName , on , options })=>{
|
|
60
|
-
return on.map((item)=>{
|
|
61
|
-
if (type.isString(item)) {
|
|
62
|
-
return changeCase[methodName](item, options);
|
|
63
|
-
}
|
|
64
|
-
return item;
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
const convertObject = ({ methodName , on , options })=>{
|
|
68
|
-
const result = {
|
|
69
|
-
};
|
|
70
|
-
const keyConverter = get(options, 'convertKeys') ? (key)=>changeCase[methodName](key, options)
|
|
71
|
-
: (key)=>key
|
|
72
|
-
;
|
|
73
|
-
const valueConverter = get(options, 'convertValues', {
|
|
74
|
-
default: true
|
|
75
|
-
}) ? (val)=>changeCase[methodName](val, options)
|
|
76
|
-
: (val)=>val
|
|
77
|
-
;
|
|
78
|
-
Object.entries(on).forEach(([key, value])=>{
|
|
79
|
-
if (type.isString(value)) {
|
|
80
|
-
result[keyConverter(key)] = valueConverter(value);
|
|
81
|
-
} else {
|
|
82
|
-
result[keyConverter(key)] = value;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
return result;
|
|
86
|
-
};
|
|
87
|
-
const makeCaseChanger = ({ methodName })=>(on, options = {
|
|
88
|
-
})=>{
|
|
89
|
-
if (type.isString(on)) {
|
|
90
|
-
return changeCase[methodName](on, options);
|
|
91
|
-
}
|
|
92
|
-
if (type.isArray(on)) {
|
|
93
|
-
return convertArray({
|
|
94
|
-
methodName,
|
|
95
|
-
on,
|
|
96
|
-
options
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (type.isObject(on)) {
|
|
100
|
-
return convertObject({
|
|
101
|
-
methodName,
|
|
102
|
-
on,
|
|
103
|
-
options
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return on;
|
|
107
|
-
}
|
|
108
|
-
;
|
|
109
|
-
const functions = {
|
|
110
|
-
};
|
|
111
|
-
const meta = {
|
|
112
|
-
};
|
|
113
|
-
Object.keys(changeCase).forEach((methodName)=>{
|
|
114
|
-
functions[methodName] = makeCaseChanger({
|
|
115
|
-
methodName
|
|
116
|
-
});
|
|
117
|
-
meta[methodName] = {
|
|
118
|
-
namedArgs: [
|
|
119
|
-
'on',
|
|
120
|
-
'options'
|
|
121
|
-
],
|
|
122
|
-
validTypes: [
|
|
123
|
-
'array',
|
|
124
|
-
'object'
|
|
125
|
-
],
|
|
126
|
-
prep
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
function change_case({ params , location , methodName }) {
|
|
130
|
-
return runClass({
|
|
131
|
-
functions,
|
|
132
|
-
location,
|
|
133
|
-
meta,
|
|
134
|
-
methodName,
|
|
135
|
-
operator: '_change_case',
|
|
136
|
-
params
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
export default change_case;
|