@lowdefy/operators 4.0.0-alpha.5 → 4.0.0-alpha.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/webParser.js CHANGED
@@ -58,22 +58,17 @@ let WebParser = class WebParser {
58
58
  context: context,
59
59
  env: 'web',
60
60
  event,
61
- input: inputs ? inputs[context.id] : {
62
- },
61
+ input: inputs ? inputs[context.id] : {},
63
62
  location: applyArrayIndices(arrayIndices, location),
64
- lowdefyGlobal: lowdefyGlobal || {
65
- },
66
- menus: menus || {
67
- },
63
+ lowdefyGlobal: lowdefyGlobal || {},
64
+ menus: menus || {},
68
65
  methodName,
69
66
  operators: operators,
70
67
  params: value[key],
71
68
  requests: context.requests,
72
69
  state: context.state,
73
- urlQuery: urlQuery || {
74
- },
75
- user: user || {
76
- },
70
+ urlQuery: urlQuery || {},
71
+ user: user || {},
77
72
  parser: this
78
73
  });
79
74
  return res;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.6",
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/format": "4.0.0-alpha.5",
42
- "@lowdefy/helpers": "4.0.0-alpha.5",
43
- "@lowdefy/nunjucks": "4.0.0-alpha.5",
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.6"
49
42
  },
50
43
  "devDependencies": {
51
- "@swc/cli": "0.1.52",
52
- "@swc/core": "1.2.112",
53
- "@swc/jest": "0.2.9",
44
+ "@swc/cli": "0.1.55",
45
+ "@swc/core": "1.2.130",
46
+ "@swc/jest": "0.2.17",
54
47
  "jest": "27.3.1"
55
48
  },
56
49
  "publishConfig": {
57
50
  "access": "public"
58
51
  },
59
- "gitHead": "995fcdb020927f3cdc626fc99c15a2e4137bd962"
52
+ "gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
60
53
  }
@@ -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;
@@ -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
- */ export default {
16
- _and: 'common/and',
17
- _args: 'common/args',
18
- _array: 'common/array',
19
- _change_case: 'common/change_case',
20
- _date: 'common/date',
21
- _divide: 'common/divide',
22
- _eq: 'common/eq',
23
- _function: 'common/function',
24
- _get: 'common/get',
25
- _gt: 'common/gt',
26
- _gte: 'common/gte',
27
- _if_none: 'common/if_none',
28
- _if: 'common/if',
29
- _json: 'common/json',
30
- _log: 'common/log',
31
- _lt: 'common/lt',
32
- _lte: 'common/lte',
33
- _math: 'common/math',
34
- _mql: 'common/mql',
35
- _ne: 'common/ne',
36
- _not: 'common/not',
37
- _number: 'common/number',
38
- _nunjucks: 'common/nunjucks',
39
- _object: 'common/object',
40
- _operator: 'common/operator',
41
- _or: 'common/or',
42
- _product: 'common/product',
43
- _random: 'common/random',
44
- _regex: 'common/regex',
45
- _string: 'common/string',
46
- _subtract: 'common/subtract',
47
- _sum: 'common/sum',
48
- _switch: 'common/switch',
49
- _type: 'common/type',
50
- _uri: 'common/uri',
51
- _user: 'common/user',
52
- _uuid: 'common/uuid',
53
- _yaml: 'common/yaml'
54
- };
@@ -1,115 +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 mingo from 'mingo';
16
- import { get, type } from '@lowdefy/helpers';
17
- import runClass from '../runClass.js';
18
- import 'mingo/init/system';
19
- function aggregate(data, pipeline) {
20
- if (data === null) {
21
- data = [];
22
- }
23
- if (!type.isArray(data)) {
24
- throw new Error('Data must be of type array.');
25
- }
26
- if (!type.isArray(pipeline)) {
27
- throw new Error('Pipeline must be of type array.');
28
- }
29
- const agg = new mingo.Aggregator(pipeline);
30
- return agg.run(data);
31
- }
32
- function expr1(data, expr) {
33
- if (data === null) {
34
- data = {
35
- };
36
- }
37
- if (!type.isObject(data)) {
38
- throw new Error('Data must be of type object.');
39
- }
40
- const agg = new mingo.Aggregator([
41
- {
42
- $project: {
43
- value: expr
44
- }
45
- },
46
- ]);
47
- const res = agg.run([
48
- data
49
- ]);
50
- return get(res, '0.value', {
51
- default: null
52
- });
53
- }
54
- function test1(data, test) {
55
- if (data === null) {
56
- data = {
57
- };
58
- }
59
- if (!type.isObject(data)) {
60
- throw new Error('Data must be of type object.');
61
- }
62
- if (!type.isObject(test)) {
63
- throw new Error('Query test must be of type object.');
64
- }
65
- const query = new mingo.Query(test);
66
- return query.test(data);
67
- }
68
- const meta = {
69
- aggregate: {
70
- namedArgs: [
71
- 'on',
72
- 'pipeline'
73
- ],
74
- validTypes: [
75
- 'array',
76
- 'object'
77
- ]
78
- },
79
- expr: {
80
- namedArgs: [
81
- 'on',
82
- 'expr'
83
- ],
84
- validTypes: [
85
- 'array',
86
- 'object'
87
- ]
88
- },
89
- test: {
90
- namedArgs: [
91
- 'on',
92
- 'test'
93
- ],
94
- validTypes: [
95
- 'array',
96
- 'object'
97
- ]
98
- }
99
- };
100
- const functions = {
101
- aggregate,
102
- expr: expr1,
103
- test: test1
104
- };
105
- function mql({ params , location , methodName }) {
106
- return runClass({
107
- functions,
108
- location,
109
- meta,
110
- methodName,
111
- operator: '_mql',
112
- params
113
- });
114
- }
115
- export default mql;
@@ -1,65 +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 { v1, v3, v4, v5 } from 'uuid';
16
- import { type } from '@lowdefy/helpers';
17
- import runClass from '../runClass.js';
18
- const meta = {
19
- v1: {
20
- noArgs: true
21
- },
22
- v3: {
23
- namedArgs: [
24
- 'name',
25
- 'namespace'
26
- ],
27
- validTypes: [
28
- 'array',
29
- 'object'
30
- ]
31
- },
32
- v4: {
33
- noArgs: true
34
- },
35
- v5: {
36
- namedArgs: [
37
- 'name',
38
- 'namespace'
39
- ],
40
- validTypes: [
41
- 'array',
42
- 'object'
43
- ]
44
- }
45
- };
46
- const functions = {
47
- v1,
48
- v3,
49
- v4,
50
- v5
51
- };
52
- function _uuid({ params , location , methodName }) {
53
- if (type.isNone(methodName) && (type.isNone(params) || params === true)) {
54
- return v4();
55
- }
56
- return runClass({
57
- functions: functions,
58
- location,
59
- meta,
60
- methodName,
61
- operator: '_uuid',
62
- params
63
- });
64
- }
65
- export default _uuid;
@@ -1,63 +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 YAML from 'js-yaml';
16
- import { serializer } from '@lowdefy/helpers';
17
- import runClass from '../runClass.js';
18
- function parse(input) {
19
- if (input === 'undefined') return undefined;
20
- const loaded = YAML.load(input);
21
- return serializer.deserialize(loaded);
22
- }
23
- function stringify(input, options) {
24
- return YAML.dump(serializer.serialize(input, {
25
- isoStringDates: true
26
- }), {
27
- sortKeys: true,
28
- ...options
29
- });
30
- }
31
- const functions = {
32
- parse,
33
- stringify
34
- };
35
- const meta = {
36
- stringify: {
37
- namedArgs: [
38
- 'on',
39
- 'options'
40
- ],
41
- validTypes: [
42
- 'object',
43
- 'array'
44
- ]
45
- },
46
- parse: {
47
- singleArg: true,
48
- validTypes: [
49
- 'string'
50
- ]
51
- }
52
- };
53
- function _yaml({ params , location , methodName }) {
54
- return runClass({
55
- functions,
56
- location,
57
- meta,
58
- methodName,
59
- operator: '_yaml',
60
- params
61
- });
62
- }
63
- export default _yaml;
package/dist/node/diff.js DELETED
@@ -1,49 +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 { diff } from 'deep-diff';
16
- import runClass from '../runClass.js';
17
- function deep(lhs, rhs) {
18
- const result = diff(lhs, rhs);
19
- if (!result) {
20
- return [];
21
- }
22
- return result;
23
- }
24
- const functions = {
25
- deep
26
- };
27
- const meta = {
28
- deep: {
29
- namedArgs: [
30
- 'lhs',
31
- 'rhs'
32
- ],
33
- validTypes: [
34
- 'object',
35
- 'array'
36
- ]
37
- }
38
- };
39
- function _diff({ params , location , methodName }) {
40
- return runClass({
41
- functions,
42
- location,
43
- meta,
44
- methodName,
45
- operator: '_diff',
46
- params
47
- });
48
- }
49
- export default _diff;
@@ -1,21 +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
- */ export default {
16
- _base64: 'node/base64',
17
- _diff: 'node/diff',
18
- _hash: 'node/hash',
19
- _payload: 'node/payload',
20
- _secret: 'node/secret'
21
- };
@@ -1,30 +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 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);
29
- }
30
- export default _format;
package/dist/web/index.js DELETED
@@ -1,32 +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
- */ 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'
32
- };
package/dist/web/js.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 _js({ context , params , location , methodName }) {
17
- if (!type.isFunction(context.lowdefy.imports.jsOperators[methodName])) {
18
- throw new Error(`Operator Error: _js.${methodName} is not a function.`);
19
- }
20
- if (!type.isNone(params) && !type.isArray(params)) {
21
- throw new Error(`Operator Error: _js.${methodName} takes an array as input at ${location}.`);
22
- }
23
- return context.lowdefy.imports.jsOperators[methodName](...params || []);
24
- }
25
- export default _js;