@lowdefy/operators-js 6.1.0 → 7.0.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.
Files changed (81) hide show
  1. package/dist/checks.js +24 -0
  2. package/dist/metas.js +26 -0
  3. package/dist/operators/build/authConfig.js +62 -0
  4. package/dist/operators/build/authConfig.schema.js +37 -0
  5. package/dist/operators/client/_index.js +6 -0
  6. package/dist/operators/client/actions.js +4 -0
  7. package/dist/operators/client/api.js +9 -0
  8. package/dist/operators/client/base64.js +3 -0
  9. package/dist/operators/client/event.js +4 -0
  10. package/dist/operators/client/event_log.js +4 -0
  11. package/dist/operators/client/global.js +9 -1
  12. package/dist/operators/client/input.js +9 -1
  13. package/dist/operators/client/js.js +15 -1
  14. package/dist/operators/client/location.js +13 -0
  15. package/dist/operators/client/media.js +17 -33
  16. package/dist/operators/client/menu.js +6 -0
  17. package/dist/operators/client/path_params.js +31 -0
  18. package/dist/operators/client/path_params.schema.js +49 -0
  19. package/dist/operators/client/request.js +9 -0
  20. package/dist/operators/client/request_details.js +10 -1
  21. package/dist/operators/client/theme.js +7 -0
  22. package/dist/operators/client/url_query.js +4 -0
  23. package/dist/operators/client/websocket.js +4 -0
  24. package/dist/operators/server/agent.js +29 -0
  25. package/dist/operators/server/agent.schema.js +61 -0
  26. package/dist/operators/server/credential.js +22 -0
  27. package/dist/operators/server/credential.schema.js +20 -0
  28. package/dist/operators/server/hmac.js +72 -0
  29. package/dist/operators/server/hmac.schema.js +35 -0
  30. package/dist/operators/server/js.js +1 -1
  31. package/dist/operators/server/organization.js +40 -0
  32. package/dist/operators/server/organization.schema.js +59 -0
  33. package/dist/operators/shared/and.js +3 -0
  34. package/dist/operators/shared/app.js +3 -0
  35. package/dist/operators/shared/args.js +4 -0
  36. package/dist/operators/shared/array.js +116 -1
  37. package/dist/operators/shared/boolean.js +3 -0
  38. package/dist/operators/shared/date.js +16 -0
  39. package/dist/operators/shared/divide.js +3 -0
  40. package/dist/operators/shared/eq.js +3 -0
  41. package/dist/operators/shared/error.js +4 -0
  42. package/dist/operators/shared/function.js +4 -0
  43. package/dist/operators/shared/get.js +3 -0
  44. package/dist/operators/shared/gt.js +3 -0
  45. package/dist/operators/shared/gte.js +3 -0
  46. package/dist/operators/shared/if.check.js +25 -0
  47. package/dist/operators/shared/if.js +3 -0
  48. package/dist/operators/shared/if_none.js +3 -0
  49. package/dist/operators/shared/intl.js +14 -1
  50. package/dist/operators/shared/json.js +3 -0
  51. package/dist/operators/shared/locale.js +7 -0
  52. package/dist/operators/shared/log.js +4 -0
  53. package/dist/operators/shared/lt.js +3 -0
  54. package/dist/operators/shared/lte.js +3 -0
  55. package/dist/operators/shared/math.js +6 -0
  56. package/dist/operators/shared/ne.js +3 -0
  57. package/dist/operators/shared/not.js +3 -0
  58. package/dist/operators/shared/number.js +3 -0
  59. package/dist/operators/shared/object.js +3 -0
  60. package/dist/operators/shared/operator.js +17 -2
  61. package/dist/operators/shared/operator.schema.js +7 -0
  62. package/dist/operators/shared/or.js +3 -0
  63. package/dist/operators/shared/product.js +3 -0
  64. package/dist/operators/shared/random.js +3 -0
  65. package/dist/operators/shared/regex.js +28 -0
  66. package/dist/operators/shared/state.js +9 -1
  67. package/dist/operators/shared/string.js +3 -0
  68. package/dist/operators/shared/subtract.js +3 -0
  69. package/dist/operators/shared/sum.js +3 -0
  70. package/dist/operators/shared/switch.js +3 -0
  71. package/dist/operators/shared/t.js +7 -0
  72. package/dist/operators/shared/type.js +23 -0
  73. package/dist/operators/shared/type.schema.js +3 -1
  74. package/dist/operators/shared/uri.js +3 -0
  75. package/dist/operators/shared/user.js +19 -1
  76. package/dist/operatorsBuild.js +4 -0
  77. package/dist/operatorsClient.js +1 -0
  78. package/dist/operatorsServer.js +4 -0
  79. package/dist/schemas.js +6 -0
  80. package/dist/types.js +5 -0
  81. package/package.json +11 -6
@@ -23,4 +23,7 @@ function _ne({ params }) {
23
23
  return params[0] !== params[1];
24
24
  }
25
25
  _ne.dynamic = false;
26
+ _ne.tracking = {
27
+ kind: 'pure'
28
+ };
26
29
  export default _ne;
@@ -16,4 +16,7 @@
16
16
  return !params;
17
17
  }
18
18
  _not.dynamic = false;
19
+ _not.tracking = {
20
+ kind: 'pure'
21
+ };
19
22
  export default _not;
@@ -145,5 +145,8 @@ function _number({ params, location, methodName }) {
145
145
  });
146
146
  }
147
147
  _number.dynamic = false;
148
+ _number.tracking = {
149
+ kind: 'pure'
150
+ };
148
151
  _number.meta = meta;
149
152
  export default _number;
@@ -127,4 +127,7 @@ function _object({ params, location, methodName }) {
127
127
  });
128
128
  }
129
129
  _object.dynamic = false;
130
+ _object.tracking = {
131
+ kind: 'pure'
132
+ };
130
133
  export default _object;
@@ -18,13 +18,24 @@ function _operator(options) {
18
18
  if (!type.isString(params.name)) {
19
19
  throw new Error(`_operator.name must be a valid operator name as string.`);
20
20
  }
21
- if (params.name === '_operator') {
21
+ const [operator, methodName] = params.name.split('.');
22
+ if (operator === '_operator') {
22
23
  throw new Error(`_operator.name cannot be set to _operator to avoid infinite loop reference.`);
23
24
  }
24
25
  if (params.name.includes('experimental')) {
25
26
  throw new Error(`Experimental operators cannot be used with _operator.`);
26
27
  }
27
- const [operator, methodName] = params.name.split('.');
28
+ // A name read at runtime comes with the operators it may call (the build
29
+ // requires the list and bundles exactly those). A listed operator allows
30
+ // every method; a listed method allows only itself.
31
+ if (!type.isNone(params.operators)) {
32
+ if (!type.isArray(params.operators)) {
33
+ throw new Error(`_operator.operators must be an array of operator names.`);
34
+ }
35
+ if (!params.operators.some((name)=>name === operator || name === params.name)) {
36
+ throw new Error(`_operator - "${params.name}" is not in _operator.operators.`);
37
+ }
38
+ }
28
39
  if (Object.prototype.hasOwnProperty.call(operators, operator)) {
29
40
  return operators[operator]({
30
41
  ...options,
@@ -36,4 +47,8 @@ function _operator(options) {
36
47
  throw new Error(`_operator - Invalid operator name.`);
37
48
  }
38
49
  _operator.dynamic = true;
50
+ // The operator it dispatches to is called through the tracked registry view, so it records itself.
51
+ _operator.tracking = {
52
+ kind: 'pure'
53
+ };
39
54
  export default _operator;
@@ -26,6 +26,13 @@
26
26
  },
27
27
  params: {
28
28
  description: 'Params to pass to the operator.'
29
+ },
30
+ operators: {
31
+ type: 'array',
32
+ items: {
33
+ type: 'string'
34
+ },
35
+ description: 'The operators the call may evaluate. Required when name is read at runtime; any other name is refused.'
29
36
  }
30
37
  },
31
38
  additionalProperties: false
@@ -20,4 +20,7 @@ function _or({ params }) {
20
20
  return !!params.reduce((acc, el)=>acc || el, false);
21
21
  }
22
22
  _or.dynamic = false;
23
+ _or.tracking = {
24
+ kind: 'pure'
25
+ };
23
26
  export default _or;
@@ -25,4 +25,7 @@ function _product({ params }) {
25
25
  }, 1);
26
26
  }
27
27
  _product.dynamic = false;
28
+ _product.tracking = {
29
+ kind: 'pure'
30
+ };
28
31
  export default _product;
@@ -90,4 +90,7 @@ function _random({ params }) {
90
90
  return generateRandomString(params.length);
91
91
  }
92
92
  _random.dynamic = true;
93
+ _random.tracking = {
94
+ kind: 'volatile'
95
+ };
93
96
  export default _random;
@@ -59,4 +59,32 @@ function _regex({ location, params, state }) {
59
59
  }
60
60
  }
61
61
  _regex.dynamic = true;
62
+ // With no `on`, _regex reads state at `key`, or at its own location.
63
+ _regex.tracking = ({ location, params })=>{
64
+ const pattern = type.isObject(params) ? params.pattern : params;
65
+ if (!type.isString(pattern)) {
66
+ return {
67
+ kind: 'pure'
68
+ };
69
+ }
70
+ if (!type.isUndefined(params.key)) {
71
+ return {
72
+ kind: 'read',
73
+ keys: [
74
+ type.isString(params.key) ? `state:${params.key}` : 'state:*'
75
+ ]
76
+ };
77
+ }
78
+ if (type.isUndefined(params.on)) {
79
+ return {
80
+ kind: 'read',
81
+ keys: [
82
+ `state:${location}`
83
+ ]
84
+ };
85
+ }
86
+ return {
87
+ kind: 'pure'
88
+ };
89
+ };
62
90
  export default _regex;
@@ -12,7 +12,7 @@
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 { getFromObject } from '@lowdefy/operators';
15
+ */ import { getFromObject, getObjectReadKeys } from '@lowdefy/operators';
16
16
  function _state({ arrayIndices, location, params, state }) {
17
17
  return getFromObject({
18
18
  arrayIndices,
@@ -23,4 +23,12 @@ function _state({ arrayIndices, location, params, state }) {
23
23
  });
24
24
  }
25
25
  _state.dynamic = true;
26
+ _state.tracking = {
27
+ kind: 'read',
28
+ keys: ({ arrayIndices, params })=>getObjectReadKeys({
29
+ arrayIndices,
30
+ namespace: 'state',
31
+ params
32
+ })
33
+ };
26
34
  export default _state;
@@ -321,4 +321,7 @@ function _string({ params, location, methodName }) {
321
321
  });
322
322
  }
323
323
  _string.dynamic = false;
324
+ _string.tracking = {
325
+ kind: 'pure'
326
+ };
324
327
  export default _string;
@@ -26,4 +26,7 @@ function _subtract({ params }) {
26
26
  return params[0] - params[1];
27
27
  }
28
28
  _subtract.dynamic = false;
29
+ _subtract.tracking = {
30
+ kind: 'pure'
31
+ };
29
32
  export default _subtract;
@@ -25,4 +25,7 @@ function _sum({ params }) {
25
25
  }, 0);
26
26
  }
27
27
  _sum.dynamic = false;
28
+ _sum.tracking = {
29
+ kind: 'pure'
30
+ };
28
31
  export default _sum;
@@ -28,4 +28,7 @@ function _switch({ params }) {
28
28
  return params.default;
29
29
  }
30
30
  _switch.dynamic = false;
31
+ _switch.tracking = {
32
+ kind: 'pure'
33
+ };
31
34
  export default _switch;
@@ -31,4 +31,11 @@ function _t({ params, i18n }) {
31
31
  throw new Error('_t takes a string key or an object { key, values, locale } — received ' + JSON.stringify(params));
32
32
  }
33
33
  _t.dynamic = true;
34
+ // i18n changes reach the engine through the full render-time pass, which evaluates every block.
35
+ _t.tracking = {
36
+ kind: 'read',
37
+ keys: ()=>[
38
+ 'i18n'
39
+ ]
40
+ };
34
41
  export default _t;
@@ -54,6 +54,10 @@ function _type({ location, params, state }) {
54
54
  return type.isUndefined(on);
55
55
  case 'none':
56
56
  return type.isNone(on);
57
+ // `empty` is what a form author means by "no value" - null, undefined, '' and [];
58
+ // 0, false and {} are values.
59
+ case 'empty':
60
+ return type.isNone(on) || on === '' || type.isArray(on) && on.length === 0;
57
61
  case 'primitive':
58
62
  return type.isPrimitive(on);
59
63
  default:
@@ -61,4 +65,23 @@ function _type({ location, params, state }) {
61
65
  }
62
66
  }
63
67
  _type.dynamic = true;
68
+ // With no `on`, _type reads state at `key`, or at its own location: the engine's required check
69
+ // is a _type on the input's own value.
70
+ _type.tracking = ({ location, params })=>{
71
+ const typeName = type.isObject(params) ? params.type : params;
72
+ if (!type.isString(typeName) || Object.prototype.hasOwnProperty.call(params, 'on')) {
73
+ return {
74
+ kind: 'pure'
75
+ };
76
+ }
77
+ const key = get(params, 'key', {
78
+ default: location
79
+ });
80
+ return {
81
+ kind: 'read',
82
+ keys: [
83
+ type.isString(key) ? `state:${key}` : 'state:*'
84
+ ]
85
+ };
86
+ };
64
87
  export default _type;
@@ -29,9 +29,10 @@
29
29
  'null',
30
30
  'undefined',
31
31
  'none',
32
+ 'empty',
32
33
  'primitive'
33
34
  ],
34
- description: 'Type name to test against state value at current location.'
35
+ description: 'Type name to test against state value at current location. The "empty" test is true for null, undefined, \'\' and [], and false for 0, false and {}.'
35
36
  },
36
37
  {
37
38
  type: 'object',
@@ -52,6 +53,7 @@
52
53
  'null',
53
54
  'undefined',
54
55
  'none',
56
+ 'empty',
55
57
  'primitive'
56
58
  ],
57
59
  description: 'Type name to test.'
@@ -48,4 +48,7 @@ function _uri({ params, location, methodName }) {
48
48
  });
49
49
  }
50
50
  _uri.dynamic = false;
51
+ _uri.tracking = {
52
+ kind: 'pure'
53
+ };
51
54
  export default _uri;
@@ -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 { type } from '@lowdefy/helpers';
16
- import { getFromObject } from '@lowdefy/operators';
16
+ import { getFromObject, getObjectReadKeys } from '@lowdefy/operators';
17
17
  const roleMethods = [
18
18
  'hasRole',
19
19
  'hasSomeRoles',
@@ -85,4 +85,22 @@ function _user({ arrayIndices, location, methodName, params, user }) {
85
85
  });
86
86
  }
87
87
  _user.dynamic = true;
88
+ _user.tracking = ({ arrayIndices, methodName, params })=>{
89
+ if (roleMethods.includes(methodName)) {
90
+ return {
91
+ kind: 'read',
92
+ keys: [
93
+ 'user:roles'
94
+ ]
95
+ };
96
+ }
97
+ return {
98
+ kind: 'read',
99
+ keys: getObjectReadKeys({
100
+ arrayIndices,
101
+ namespace: 'user',
102
+ params
103
+ })
104
+ };
105
+ };
88
106
  export default _user;
@@ -49,12 +49,15 @@ import _type from './operators/shared/type.js';
49
49
  import _uri from './operators/shared/uri.js';
50
50
  import _base64 from './operators/server/base64.js';
51
51
  import _hash from './operators/server/hash.js';
52
+ import _hmac from './operators/server/hmac.js';
53
+ import _authConfig from './operators/build/authConfig.js';
52
54
  import _env from './operators/build/env.js';
53
55
  export default {
54
56
  _and,
55
57
  _app,
56
58
  _args,
57
59
  _array,
60
+ _authConfig,
58
61
  _base64,
59
62
  _boolean,
60
63
  _date,
@@ -66,6 +69,7 @@ export default {
66
69
  _gt,
67
70
  _gte,
68
71
  _hash,
72
+ _hmac,
69
73
  _if_none,
70
74
  _if,
71
75
  _intl,
@@ -64,6 +64,7 @@ export { default as _js } from './operators/client/js.js';
64
64
  export { default as _location } from './operators/client/location.js';
65
65
  export { default as _media } from './operators/client/media.js';
66
66
  export { default as _menu } from './operators/client/menu.js';
67
+ export { default as _path_params } from './operators/client/path_params.js';
67
68
  export { default as _request_details } from './operators/client/request_details.js';
68
69
  export { default as _request } from './operators/client/request.js';
69
70
  export { default as _theme } from './operators/client/theme.js';
@@ -51,11 +51,15 @@ export { default as _t } from './operators/shared/t.js';
51
51
  export { default as _type } from './operators/shared/type.js';
52
52
  export { default as _uri } from './operators/shared/uri.js';
53
53
  export { default as _user } from './operators/shared/user.js';
54
+ export { default as _agent } from './operators/server/agent.js';
54
55
  export { default as _base64 } from './operators/server/base64.js';
56
+ export { default as _credential } from './operators/server/credential.js';
55
57
  export { default as _error } from './operators/shared/error.js';
56
58
  export { default as _hash } from './operators/server/hash.js';
59
+ export { default as _hmac } from './operators/server/hmac.js';
57
60
  export { default as _item } from './operators/server/item.js';
58
61
  export { default as _js } from './operators/server/js.js';
62
+ export { default as _organization } from './operators/server/organization.js';
59
63
  export { default as _payload } from './operators/server/payload.js';
60
64
  export { default as _secret } from './operators/server/secret.js';
61
65
  export { default as _step } from './operators/server/step.js';
package/dist/schemas.js CHANGED
@@ -66,14 +66,20 @@ export { default as _js } from './operators/client/js.schema.js';
66
66
  export { default as _location } from './operators/client/location.schema.js';
67
67
  export { default as _media } from './operators/client/media.schema.js';
68
68
  export { default as _menu } from './operators/client/menu.schema.js';
69
+ export { default as _path_params } from './operators/client/path_params.schema.js';
69
70
  export { default as _request } from './operators/client/request.schema.js';
70
71
  export { default as _request_details } from './operators/client/request_details.schema.js';
71
72
  export { default as _url_query } from './operators/client/url_query.schema.js';
72
73
  // Server operators
74
+ export { default as _agent } from './operators/server/agent.schema.js';
75
+ export { default as _credential } from './operators/server/credential.schema.js';
73
76
  export { default as _hash } from './operators/server/hash.schema.js';
77
+ export { default as _hmac } from './operators/server/hmac.schema.js';
74
78
  export { default as _item } from './operators/server/item.schema.js';
79
+ export { default as _organization } from './operators/server/organization.schema.js';
75
80
  export { default as _payload } from './operators/server/payload.schema.js';
76
81
  export { default as _secret } from './operators/server/secret.schema.js';
77
82
  export { default as _step } from './operators/server/step.schema.js';
78
83
  // Build operators
84
+ export { default as _authConfig } from './operators/build/authConfig.schema.js';
79
85
  export { default as _env } from './operators/build/env.schema.js';
package/dist/types.js CHANGED
@@ -55,6 +55,7 @@
55
55
  '_object',
56
56
  '_operator',
57
57
  '_or',
58
+ '_path_params',
58
59
  '_product',
59
60
  '_random',
60
61
  '_regex',
@@ -74,12 +75,14 @@
74
75
  '_websocket'
75
76
  ],
76
77
  server: [
78
+ '_agent',
77
79
  '_and',
78
80
  '_app',
79
81
  '_args',
80
82
  '_array',
81
83
  '_base64',
82
84
  '_boolean',
85
+ '_credential',
83
86
  '_date',
84
87
  '_divide',
85
88
  '_eq',
@@ -89,6 +92,7 @@
89
92
  '_gt',
90
93
  '_gte',
91
94
  '_hash',
95
+ '_hmac',
92
96
  '_if',
93
97
  '_if_none',
94
98
  '_intl',
@@ -106,6 +110,7 @@
106
110
  '_object',
107
111
  '_operator',
108
112
  '_or',
113
+ '_organization',
109
114
  '_payload',
110
115
  '_product',
111
116
  '_random',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators-js",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -31,11 +31,16 @@
31
31
  "url": "https://github.com/lowdefy/lowdefy.git"
32
32
  },
33
33
  "type": "module",
34
+ "sideEffects": [
35
+ "**/*.css"
36
+ ],
34
37
  "exports": {
35
38
  ".": "./dist/index.js",
36
39
  "./operators/build": "./dist/operatorsBuild.js",
37
40
  "./operators/client": "./dist/operatorsClient.js",
38
41
  "./operators/server": "./dist/operatorsServer.js",
42
+ "./metas": "./dist/metas.js",
43
+ "./checks": "./dist/checks.js",
39
44
  "./schemas": "./dist/schemas.js",
40
45
  "./types": "./dist/types.js"
41
46
  },
@@ -43,14 +48,14 @@
43
48
  "dist/*"
44
49
  ],
45
50
  "dependencies": {
46
- "@lowdefy/errors": "6.1.0",
47
- "@lowdefy/helpers": "6.1.0",
48
- "@lowdefy/operators": "6.1.0",
51
+ "@lowdefy/errors": "7.0.0",
52
+ "@lowdefy/helpers": "7.0.0",
53
+ "@lowdefy/operators": "7.0.0",
49
54
  "intl-messageformat": "11.2.7"
50
55
  },
51
56
  "devDependencies": {
52
57
  "@jest/globals": "28.1.3",
53
- "@lowdefy/node-utils": "6.1.0",
58
+ "@lowdefy/node-utils": "7.0.0",
54
59
  "@swc/cli": "0.8.1",
55
60
  "@swc/core": "1.15.32",
56
61
  "@swc/jest": "0.2.39",
@@ -63,6 +68,6 @@
63
68
  "scripts": {
64
69
  "build": "swc src --out-dir dist --config-file ../../../../.swcrc --cli-config-file ../../../../.swc-cli.json --copy-files",
65
70
  "clean": "rm -rf dist",
66
- "test": "TZ=UTC node --experimental-vm-modules node_modules/jest/bin/jest.js"
71
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
67
72
  }
68
73
  }