@lowdefy/operators-js 5.5.1 → 5.6.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.
@@ -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
  }
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators-js",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -43,13 +43,13 @@
43
43
  "dist/*"
44
44
  ],
45
45
  "dependencies": {
46
- "@lowdefy/helpers": "5.5.1",
47
- "@lowdefy/operators": "5.5.1",
46
+ "@lowdefy/helpers": "5.6.0",
47
+ "@lowdefy/operators": "5.6.0",
48
48
  "intl-messageformat": "11.2.7"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@jest/globals": "28.1.3",
52
- "@lowdefy/node-utils": "5.5.1",
52
+ "@lowdefy/node-utils": "5.6.0",
53
53
  "@swc/cli": "0.8.0",
54
54
  "@swc/core": "1.15.18",
55
55
  "@swc/jest": "0.2.39",