@lowdefy/operators-js 4.7.3 → 5.1.0
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/operators/client/media.js +14 -6
- package/dist/operators/client/media.schema.js +6 -2
- package/dist/operators/client/menu.js +26 -3
- package/dist/operators/client/theme.js +26 -0
- package/dist/operators/shared/date.js +4 -2
- package/dist/operators/shared/math.js +13 -1
- package/dist/operators/shared/user.js +64 -2
- package/dist/operators/shared/user.schema.js +8 -1
- package/dist/operatorsClient.js +1 -0
- package/dist/types.js +98 -5
- package/package.json +8 -7
|
@@ -13,12 +13,18 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { getFromObject } from '@lowdefy/operators';
|
|
16
|
+
function getDarkModePreference(window) {
|
|
17
|
+
return window.localStorage?.getItem('lowdefy_darkMode') ?? 'system';
|
|
18
|
+
}
|
|
19
|
+
function getDarkMode(window) {
|
|
20
|
+
return window.__lowdefy_isDark ?? false;
|
|
21
|
+
}
|
|
16
22
|
const breakpoints = {
|
|
17
|
-
xs:
|
|
23
|
+
xs: 640,
|
|
18
24
|
sm: 768,
|
|
19
|
-
md:
|
|
20
|
-
lg:
|
|
21
|
-
xl:
|
|
25
|
+
md: 1024,
|
|
26
|
+
lg: 1280,
|
|
27
|
+
xl: 1536
|
|
22
28
|
};
|
|
23
29
|
function _media({ arrayIndices, location, params, globals }) {
|
|
24
30
|
const { window } = globals;
|
|
@@ -43,13 +49,15 @@ function _media({ arrayIndices, location, params, globals }) {
|
|
|
43
49
|
size = 'xl';
|
|
44
50
|
break;
|
|
45
51
|
default:
|
|
46
|
-
size = '
|
|
52
|
+
size = '2xl';
|
|
47
53
|
break;
|
|
48
54
|
}
|
|
49
55
|
const media = {
|
|
50
56
|
size,
|
|
51
57
|
width: window.innerWidth,
|
|
52
|
-
height: window.innerHeight
|
|
58
|
+
height: window.innerHeight,
|
|
59
|
+
darkMode: getDarkMode(window),
|
|
60
|
+
darkModePreference: getDarkModePreference(window)
|
|
53
61
|
};
|
|
54
62
|
return getFromObject({
|
|
55
63
|
arrayIndices,
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
enum: [
|
|
22
22
|
'size',
|
|
23
23
|
'width',
|
|
24
|
-
'height'
|
|
24
|
+
'height',
|
|
25
|
+
'darkMode',
|
|
26
|
+
'darkModePreference'
|
|
25
27
|
],
|
|
26
28
|
description: 'Media property to return.'
|
|
27
29
|
},
|
|
@@ -40,7 +42,9 @@
|
|
|
40
42
|
enum: [
|
|
41
43
|
'size',
|
|
42
44
|
'width',
|
|
43
|
-
'height'
|
|
45
|
+
'height',
|
|
46
|
+
'darkMode',
|
|
47
|
+
'darkModePreference'
|
|
44
48
|
],
|
|
45
49
|
description: 'Media property to return.'
|
|
46
50
|
},
|
|
@@ -12,15 +12,38 @@
|
|
|
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 { getFromArray } from '@lowdefy/operators';
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
*/ import { getFromArray, getFromObject } from '@lowdefy/operators';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
function _menu({ params, arrayIndices, menus, location }) {
|
|
18
|
+
// Support dot-path access: _menu: menuId.path.into.links
|
|
19
|
+
if (type.isString(params) && params.includes('.')) {
|
|
20
|
+
const dotIndex = params.indexOf('.');
|
|
21
|
+
const menuId = params.slice(0, dotIndex);
|
|
22
|
+
const path = params.slice(dotIndex + 1);
|
|
23
|
+
const menu = menus.find((item)=>item.menuId === menuId);
|
|
24
|
+
if (!menu) return undefined;
|
|
25
|
+
const links = menu.links ?? [];
|
|
26
|
+
return getFromObject({
|
|
27
|
+
params: path,
|
|
28
|
+
object: links,
|
|
29
|
+
arrayIndices,
|
|
30
|
+
operator: '_menu',
|
|
31
|
+
location
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const result = getFromArray({
|
|
18
35
|
params,
|
|
19
36
|
array: menus,
|
|
20
37
|
key: 'menuId',
|
|
21
38
|
operator: '_menu',
|
|
22
39
|
location
|
|
23
40
|
});
|
|
41
|
+
// When selecting a single menu, return its links array directly.
|
|
42
|
+
// _menu: true and { all: true } return the full menus array (result is an array).
|
|
43
|
+
if (result && !Array.isArray(result)) {
|
|
44
|
+
return result.links ?? [];
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
24
47
|
}
|
|
25
48
|
_menu.dynamic = true;
|
|
26
49
|
export default _menu;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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 '@lowdefy/operators';
|
|
16
|
+
function _theme({ arrayIndices, location, theme, params }) {
|
|
17
|
+
return getFromObject({
|
|
18
|
+
arrayIndices,
|
|
19
|
+
location,
|
|
20
|
+
object: theme?._resolvedAntdToken ?? theme?.antd?.token ?? {},
|
|
21
|
+
operator: '_theme',
|
|
22
|
+
params
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_theme.dynamic = true;
|
|
26
|
+
export default _theme;
|
|
@@ -172,6 +172,16 @@ const meta = {
|
|
|
172
172
|
'array'
|
|
173
173
|
]
|
|
174
174
|
},
|
|
175
|
+
mod: {
|
|
176
|
+
namedArgs: [
|
|
177
|
+
'dividend',
|
|
178
|
+
'divisor'
|
|
179
|
+
],
|
|
180
|
+
validTypes: [
|
|
181
|
+
'object',
|
|
182
|
+
'array'
|
|
183
|
+
]
|
|
184
|
+
},
|
|
175
185
|
pow: {
|
|
176
186
|
namedArgs: [
|
|
177
187
|
'base',
|
|
@@ -259,9 +269,11 @@ const meta = {
|
|
|
259
269
|
property: true
|
|
260
270
|
}
|
|
261
271
|
};
|
|
272
|
+
const functions = Object.create(Math);
|
|
273
|
+
functions.mod = (a, b)=>a % b;
|
|
262
274
|
function _math({ params, location, methodName }) {
|
|
263
275
|
return runClass({
|
|
264
|
-
functions
|
|
276
|
+
functions,
|
|
265
277
|
location,
|
|
266
278
|
meta,
|
|
267
279
|
methodName,
|
|
@@ -12,8 +12,70 @@
|
|
|
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 {
|
|
16
|
-
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import { getFromObject } from '@lowdefy/operators';
|
|
17
|
+
const roleMethods = [
|
|
18
|
+
'hasRole',
|
|
19
|
+
'hasSomeRoles',
|
|
20
|
+
'hasAllRoles'
|
|
21
|
+
];
|
|
22
|
+
function getUserRoles({ user, methodName }) {
|
|
23
|
+
const roles = user?.roles;
|
|
24
|
+
if (type.isNone(roles)) return [];
|
|
25
|
+
if (!type.isArray(roles)) {
|
|
26
|
+
throw new Error(`_user.${methodName} expects "user.roles" to be an array of strings. Received ${JSON.stringify(roles)}.`);
|
|
27
|
+
}
|
|
28
|
+
return roles;
|
|
29
|
+
}
|
|
30
|
+
function validateRoleString({ params, methodName }) {
|
|
31
|
+
if (!type.isString(params)) {
|
|
32
|
+
throw new Error(`_user.${methodName} accepts a string. Received ${JSON.stringify(params)}.`);
|
|
33
|
+
}
|
|
34
|
+
return params;
|
|
35
|
+
}
|
|
36
|
+
function validateRoleArray({ params, methodName }) {
|
|
37
|
+
if (!type.isArray(params) || !params.every((role)=>type.isString(role))) {
|
|
38
|
+
throw new Error(`_user.${methodName} accepts an array of strings. Received ${JSON.stringify(params)}.`);
|
|
39
|
+
}
|
|
40
|
+
return params;
|
|
41
|
+
}
|
|
42
|
+
function _user({ arrayIndices, location, methodName, params, user }) {
|
|
43
|
+
if (methodName === 'hasRole') {
|
|
44
|
+
const role = validateRoleString({
|
|
45
|
+
params,
|
|
46
|
+
methodName
|
|
47
|
+
});
|
|
48
|
+
const userRoles = getUserRoles({
|
|
49
|
+
user,
|
|
50
|
+
methodName
|
|
51
|
+
});
|
|
52
|
+
return userRoles.includes(role);
|
|
53
|
+
}
|
|
54
|
+
if (methodName === 'hasSomeRoles') {
|
|
55
|
+
const required = validateRoleArray({
|
|
56
|
+
params,
|
|
57
|
+
methodName
|
|
58
|
+
});
|
|
59
|
+
const userRoles = getUserRoles({
|
|
60
|
+
user,
|
|
61
|
+
methodName
|
|
62
|
+
});
|
|
63
|
+
return required.some((role)=>userRoles.includes(role));
|
|
64
|
+
}
|
|
65
|
+
if (methodName === 'hasAllRoles') {
|
|
66
|
+
const required = validateRoleArray({
|
|
67
|
+
params,
|
|
68
|
+
methodName
|
|
69
|
+
});
|
|
70
|
+
const userRoles = getUserRoles({
|
|
71
|
+
user,
|
|
72
|
+
methodName
|
|
73
|
+
});
|
|
74
|
+
return required.every((role)=>userRoles.includes(role));
|
|
75
|
+
}
|
|
76
|
+
if (!type.isUndefined(methodName)) {
|
|
77
|
+
throw new Error(`_user.${methodName} is not supported, use one of the following: ${roleMethods.join(', ')}.`);
|
|
78
|
+
}
|
|
17
79
|
return getFromObject({
|
|
18
80
|
arrayIndices,
|
|
19
81
|
location,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
oneOf: [
|
|
19
19
|
{
|
|
20
20
|
type: 'string',
|
|
21
|
-
description: 'Dot-notation path to value in user object.'
|
|
21
|
+
description: 'Dot-notation path to value in user object, or a role name when used with a role method.'
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
type: 'integer',
|
|
@@ -31,6 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
description: 'Return all user data.'
|
|
33
33
|
},
|
|
34
|
+
{
|
|
35
|
+
type: 'array',
|
|
36
|
+
items: {
|
|
37
|
+
type: 'string'
|
|
38
|
+
},
|
|
39
|
+
description: 'Array of role names when used with a role method.'
|
|
40
|
+
},
|
|
34
41
|
{
|
|
35
42
|
type: 'object',
|
|
36
43
|
properties: {
|
package/dist/operatorsClient.js
CHANGED
|
@@ -61,4 +61,5 @@ export { default as _media } from './operators/client/media.js';
|
|
|
61
61
|
export { default as _menu } from './operators/client/menu.js';
|
|
62
62
|
export { default as _request_details } from './operators/client/request_details.js';
|
|
63
63
|
export { default as _request } from './operators/client/request.js';
|
|
64
|
+
export { default as _theme } from './operators/client/theme.js';
|
|
64
65
|
export { default as _url_query } from './operators/client/url_query.js';
|
package/dist/types.js
CHANGED
|
@@ -12,11 +12,104 @@
|
|
|
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
|
-
*/
|
|
16
|
-
import * as server from './operatorsServer.js';
|
|
17
|
-
export default {
|
|
15
|
+
*/ export default {
|
|
18
16
|
operators: {
|
|
19
|
-
client:
|
|
20
|
-
|
|
17
|
+
client: [
|
|
18
|
+
'_actions',
|
|
19
|
+
'_and',
|
|
20
|
+
'_api',
|
|
21
|
+
'_args',
|
|
22
|
+
'_array',
|
|
23
|
+
'_base64',
|
|
24
|
+
'_date',
|
|
25
|
+
'_divide',
|
|
26
|
+
'_eq',
|
|
27
|
+
'_event',
|
|
28
|
+
'_event_log',
|
|
29
|
+
'_function',
|
|
30
|
+
'_get',
|
|
31
|
+
'_global',
|
|
32
|
+
'_gt',
|
|
33
|
+
'_gte',
|
|
34
|
+
'_if',
|
|
35
|
+
'_if_none',
|
|
36
|
+
'_index',
|
|
37
|
+
'_input',
|
|
38
|
+
'_intl',
|
|
39
|
+
'_js',
|
|
40
|
+
'_json',
|
|
41
|
+
'_location',
|
|
42
|
+
'_log',
|
|
43
|
+
'_lt',
|
|
44
|
+
'_lte',
|
|
45
|
+
'_math',
|
|
46
|
+
'_media',
|
|
47
|
+
'_menu',
|
|
48
|
+
'_ne',
|
|
49
|
+
'_not',
|
|
50
|
+
'_number',
|
|
51
|
+
'_object',
|
|
52
|
+
'_operator',
|
|
53
|
+
'_or',
|
|
54
|
+
'_product',
|
|
55
|
+
'_random',
|
|
56
|
+
'_regex',
|
|
57
|
+
'_request',
|
|
58
|
+
'_request_details',
|
|
59
|
+
'_state',
|
|
60
|
+
'_string',
|
|
61
|
+
'_subtract',
|
|
62
|
+
'_sum',
|
|
63
|
+
'_switch',
|
|
64
|
+
'_theme',
|
|
65
|
+
'_type',
|
|
66
|
+
'_uri',
|
|
67
|
+
'_url_query',
|
|
68
|
+
'_user'
|
|
69
|
+
],
|
|
70
|
+
server: [
|
|
71
|
+
'_and',
|
|
72
|
+
'_args',
|
|
73
|
+
'_array',
|
|
74
|
+
'_base64',
|
|
75
|
+
'_date',
|
|
76
|
+
'_divide',
|
|
77
|
+
'_eq',
|
|
78
|
+
'_function',
|
|
79
|
+
'_get',
|
|
80
|
+
'_gt',
|
|
81
|
+
'_gte',
|
|
82
|
+
'_hash',
|
|
83
|
+
'_if',
|
|
84
|
+
'_if_none',
|
|
85
|
+
'_intl',
|
|
86
|
+
'_item',
|
|
87
|
+
'_js',
|
|
88
|
+
'_json',
|
|
89
|
+
'_log',
|
|
90
|
+
'_lt',
|
|
91
|
+
'_lte',
|
|
92
|
+
'_math',
|
|
93
|
+
'_ne',
|
|
94
|
+
'_not',
|
|
95
|
+
'_number',
|
|
96
|
+
'_object',
|
|
97
|
+
'_operator',
|
|
98
|
+
'_or',
|
|
99
|
+
'_payload',
|
|
100
|
+
'_product',
|
|
101
|
+
'_random',
|
|
102
|
+
'_regex',
|
|
103
|
+
'_secret',
|
|
104
|
+
'_state',
|
|
105
|
+
'_step',
|
|
106
|
+
'_string',
|
|
107
|
+
'_subtract',
|
|
108
|
+
'_sum',
|
|
109
|
+
'_switch',
|
|
110
|
+
'_type',
|
|
111
|
+
'_uri',
|
|
112
|
+
'_user'
|
|
113
|
+
]
|
|
21
114
|
}
|
|
22
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -43,14 +43,15 @@
|
|
|
43
43
|
"dist/*"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lowdefy/helpers": "
|
|
47
|
-
"@lowdefy/operators": "
|
|
46
|
+
"@lowdefy/helpers": "5.1.0",
|
|
47
|
+
"@lowdefy/operators": "5.1.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@jest/globals": "28.1.3",
|
|
51
|
-
"@
|
|
52
|
-
"@swc/
|
|
53
|
-
"@swc/
|
|
51
|
+
"@lowdefy/node-utils": "5.1.0",
|
|
52
|
+
"@swc/cli": "0.8.0",
|
|
53
|
+
"@swc/core": "1.15.18",
|
|
54
|
+
"@swc/jest": "0.2.39",
|
|
54
55
|
"jest": "28.1.3",
|
|
55
56
|
"jest-environment-jsdom": "28.1.3"
|
|
56
57
|
},
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"access": "public"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
|
-
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --
|
|
62
|
+
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --cli-config-file ../../../../.swc-cli.json --copy-files",
|
|
62
63
|
"clean": "rm -rf dist",
|
|
63
64
|
"test": "TZ=UTC node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
64
65
|
}
|