@lowdefy/operators-js 5.5.1 → 6.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.
@@ -22,5 +22,5 @@ function _env({ arrayIndices, env, location, params }) {
22
22
  params
23
23
  });
24
24
  }
25
- _env.dynamic = false;
25
+ _env.dynamic = true;
26
26
  export default _env;
@@ -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 { get, type } from '@lowdefy/helpers';
15
+ */ import { ReservedKeyError, get, type } from '@lowdefy/helpers';
16
16
  function _api({ params, apiResponses }) {
17
17
  if (!type.isString(params)) {
18
18
  throw new Error(`_api accepts a string value.`);
@@ -25,10 +25,18 @@ function _api({ params, apiResponses }) {
25
25
  return entry;
26
26
  }
27
27
  const key = keyParts.join('.');
28
- return get(entry, key, {
29
- copy: true,
30
- default: null
31
- });
28
+ try {
29
+ return get(entry, key, {
30
+ copy: true,
31
+ default: null
32
+ });
33
+ } catch (error) {
34
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
35
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
36
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
37
+ if (error instanceof ReservedKeyError) return null;
38
+ throw error;
39
+ }
32
40
  }
33
41
  return null;
34
42
  }
@@ -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 { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
15
+ */ import { ReservedKeyError, applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
16
16
  function _request({ arrayIndices, params, requests }) {
17
17
  if (!type.isString(params)) {
18
18
  throw new Error(`_request accepts a string value.`);
@@ -25,10 +25,18 @@ function _request({ arrayIndices, params, requests }) {
25
25
  return serializer.copy(entry.response);
26
26
  }
27
27
  const key = keyParts.reduce((acc, value)=>acc === '' ? value : acc.concat('.', value), '');
28
- return get(entry.response, applyArrayIndices(arrayIndices, key), {
29
- copy: true,
30
- default: null
31
- });
28
+ try {
29
+ return get(entry.response, applyArrayIndices(arrayIndices, key), {
30
+ copy: true,
31
+ default: null
32
+ });
33
+ } catch (error) {
34
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
35
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
36
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
37
+ if (error instanceof ReservedKeyError) return null;
38
+ throw error;
39
+ }
32
40
  }
33
41
  return null;
34
42
  }
@@ -0,0 +1,47 @@
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 { ReservedKeyError, applyArrayIndices, get, type } from '@lowdefy/helpers';
16
+ function _websocket({ arrayIndices, params, websockets }) {
17
+ if (!type.isString(params)) {
18
+ throw new Error(`_websocket accepts a string value.`);
19
+ }
20
+ if (type.isNone(websockets)) {
21
+ return null;
22
+ }
23
+ const splitKey = params.split('.');
24
+ const [websocketId, ...keyParts] = splitKey;
25
+ const channel = websockets[websocketId];
26
+ if (type.isNone(channel)) {
27
+ return null;
28
+ }
29
+ if (splitKey.length === 1) {
30
+ return channel;
31
+ }
32
+ const key = keyParts.reduce((acc, value)=>acc === '' ? value : acc.concat('.', value), '');
33
+ try {
34
+ return get(channel, applyArrayIndices(arrayIndices, key), {
35
+ copy: true,
36
+ default: null
37
+ });
38
+ } catch (error) {
39
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
40
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
41
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
42
+ if (error instanceof ReservedKeyError) return null;
43
+ throw error;
44
+ }
45
+ }
46
+ _websocket.dynamic = true;
47
+ export default _websocket;
@@ -13,14 +13,24 @@
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
+ import { ConfigError } from '@lowdefy/errors';
17
+ import { type } from '@lowdefy/helpers';
16
18
  function _app({ arrayIndices, location, lowdefyApp, params }) {
17
- return getFromObject({
19
+ const value = getFromObject({
18
20
  arrayIndices,
19
21
  location,
20
22
  object: lowdefyApp,
21
23
  operator: '_app',
22
24
  params
23
25
  });
26
+ if (params === 'slug' && type.isNone(value)) {
27
+ throw new ConfigError('`slug` is required on the app but is not set. Declare `slug` in `lowdefy.yaml`.', {
28
+ received: {
29
+ slug: value
30
+ }
31
+ });
32
+ }
33
+ return value;
24
34
  }
25
- _app.dynamic = true;
35
+ _app.dynamic = false;
26
36
  export default _app;
@@ -12,18 +12,36 @@
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 { get, type } from '@lowdefy/helpers';
15
+ */ import { ReservedKeyError, get, type } from '@lowdefy/helpers';
16
16
  function _regex({ location, params, state }) {
17
17
  const pattern = type.isObject(params) ? params.pattern : params;
18
18
  if (!type.isString(pattern)) {
19
19
  throw new Error(`_regex.pattern must be a string.`);
20
20
  }
21
- let on = !type.isUndefined(params.on) ? params.on : get(state, location);
21
+ let on = params.on;
22
+ if (type.isUndefined(on)) {
23
+ try {
24
+ on = get(state, location);
25
+ } catch (error) {
26
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
27
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
28
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
29
+ if (!(error instanceof ReservedKeyError)) throw error;
30
+ }
31
+ }
22
32
  if (!type.isUndefined(params.key)) {
23
33
  if (!type.isString(params.key)) {
24
34
  throw new Error(`_regex.key must be a string.`);
25
35
  }
26
- on = get(state, params.key);
36
+ try {
37
+ on = get(state, params.key);
38
+ } catch (error) {
39
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
40
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
41
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
42
+ if (!(error instanceof ReservedKeyError)) throw error;
43
+ on = undefined;
44
+ }
27
45
  }
28
46
  if (type.isNone(on)) {
29
47
  return false;
@@ -12,15 +12,27 @@
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 { get, type } from '@lowdefy/helpers';
15
+ */ import { ReservedKeyError, get, type } from '@lowdefy/helpers';
16
16
  function _type({ location, params, state }) {
17
17
  const typeName = type.isObject(params) ? params.type : params;
18
18
  if (!type.isString(typeName)) {
19
19
  throw new Error(`_type.type must be a string.`);
20
20
  }
21
- const on = Object.prototype.hasOwnProperty.call(params, 'on') ? params.on : get(state, get(params, 'key', {
22
- default: location
23
- }));
21
+ let on;
22
+ if (Object.prototype.hasOwnProperty.call(params, 'on')) {
23
+ on = params.on;
24
+ } else {
25
+ try {
26
+ on = get(state, get(params, 'key', {
27
+ default: location
28
+ }));
29
+ } catch (error) {
30
+ // A runtime read: the key comes from app data or an author keypath evaluated at render time,
31
+ // and there is no config location to attach in the browser. The reserved rule's job — refusing
32
+ // the read — is already done, so degrade to the miss value rather than crashing the page.
33
+ if (!(error instanceof ReservedKeyError)) throw error;
34
+ }
35
+ }
24
36
  switch(typeName){
25
37
  case 'string':
26
38
  return type.isString(on);
@@ -13,6 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import _and from './operators/shared/and.js';
16
+ import _app from './operators/shared/app.js';
16
17
  import _args from './operators/shared/args.js';
17
18
  import _array from './operators/shared/array.js';
18
19
  import _boolean from './operators/shared/boolean.js';
@@ -51,6 +52,7 @@ import _hash from './operators/server/hash.js';
51
52
  import _env from './operators/build/env.js';
52
53
  export default {
53
54
  _and,
55
+ _app,
54
56
  _args,
55
57
  _array,
56
58
  _base64,
@@ -67,3 +67,4 @@ export { default as _request_details } from './operators/client/request_details.
67
67
  export { default as _request } from './operators/client/request.js';
68
68
  export { default as _theme } from './operators/client/theme.js';
69
69
  export { default as _url_query } from './operators/client/url_query.js';
70
+ export { default as _websocket } from './operators/client/websocket.js';
package/dist/types.js CHANGED
@@ -69,7 +69,8 @@
69
69
  '_type',
70
70
  '_uri',
71
71
  '_url_query',
72
- '_user'
72
+ '_user',
73
+ '_websocket'
73
74
  ],
74
75
  server: [
75
76
  '_and',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators-js",
3
- "version": "5.5.1",
3
+ "version": "6.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -43,15 +43,16 @@
43
43
  "dist/*"
44
44
  ],
45
45
  "dependencies": {
46
- "@lowdefy/helpers": "5.5.1",
47
- "@lowdefy/operators": "5.5.1",
46
+ "@lowdefy/errors": "6.0.0",
47
+ "@lowdefy/helpers": "6.0.0",
48
+ "@lowdefy/operators": "6.0.0",
48
49
  "intl-messageformat": "11.2.7"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@jest/globals": "28.1.3",
52
- "@lowdefy/node-utils": "5.5.1",
53
- "@swc/cli": "0.8.0",
54
- "@swc/core": "1.15.18",
53
+ "@lowdefy/node-utils": "6.0.0",
54
+ "@swc/cli": "0.8.1",
55
+ "@swc/core": "1.15.32",
55
56
  "@swc/jest": "0.2.39",
56
57
  "jest": "28.1.3",
57
58
  "jest-environment-jsdom": "28.1.3"