@lowdefy/operators 4.5.2 → 4.7.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.
@@ -0,0 +1,180 @@
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 { ConfigError, OperatorError } from '@lowdefy/errors';
16
+ import { type } from '@lowdefy/helpers';
17
+ function setDynamicMarker(node) {
18
+ if (type.isObject(node) || type.isArray(node)) {
19
+ Object.defineProperty(node, '~dyn', {
20
+ value: true,
21
+ enumerable: false,
22
+ configurable: true
23
+ });
24
+ }
25
+ return node;
26
+ }
27
+ function hasDynChild(node) {
28
+ if (type.isArray(node)) {
29
+ return node.some((item)=>{
30
+ if (type.isArray(item) && item['~dyn'] === true) return true;
31
+ if (type.isObject(item) && item['~dyn'] === true) return true;
32
+ return false;
33
+ });
34
+ }
35
+ if (type.isObject(node)) {
36
+ return Object.values(node).some((item)=>{
37
+ if (type.isArray(item) && item['~dyn'] === true) return true;
38
+ if (type.isObject(item) && item['~dyn'] === true) return true;
39
+ return false;
40
+ });
41
+ }
42
+ return false;
43
+ }
44
+ function hasDynamicMarker(value) {
45
+ if ((type.isArray(value) || type.isObject(value)) && value['~dyn'] === true) return true;
46
+ return hasDynChild(value);
47
+ }
48
+ function evaluateOperators({ input, operators, operatorPrefix = '_', env, dynamicIdentifiers, typeNames, args }) {
49
+ if (type.isUndefined(input)) {
50
+ return {
51
+ output: input,
52
+ errors: []
53
+ };
54
+ }
55
+ if (args && !type.isArray(args)) {
56
+ throw new Error('Operator parser args must be an array.');
57
+ }
58
+ const resolvedDynamicIdentifiers = dynamicIdentifiers ?? new Set();
59
+ const resolvedTypeNames = typeNames ?? new Set();
60
+ const errors = [];
61
+ const parser = {
62
+ parse: ({ args: callArgs, input: callInput, operatorPrefix: callPrefix })=>evaluateOperators({
63
+ input: callInput,
64
+ operators,
65
+ operatorPrefix: callPrefix ?? operatorPrefix,
66
+ env,
67
+ dynamicIdentifiers: resolvedDynamicIdentifiers,
68
+ typeNames: resolvedTypeNames,
69
+ args: callArgs
70
+ })
71
+ };
72
+ function walk(node) {
73
+ // Primitives pass through
74
+ if (!type.isObject(node) && !type.isArray(node)) return node;
75
+ // Arrays: walk children, then bubble up
76
+ if (type.isArray(node)) {
77
+ for(let i = 0; i < node.length; i++){
78
+ node[i] = walk(node[i]);
79
+ }
80
+ if (hasDynamicMarker(node)) {
81
+ return setDynamicMarker(node);
82
+ }
83
+ return node;
84
+ }
85
+ // Object handling
86
+ // Walk children in-place (bottom-up)
87
+ const keys = Object.keys(node);
88
+ for (const k of keys){
89
+ node[k] = walk(node[k]);
90
+ }
91
+ // Operator detection (before type boundary and bubble-up, to match BuildParser order)
92
+ const nonTildeKeys = keys.filter((k)=>!k.startsWith('~'));
93
+ const isSingleKeyObject = nonTildeKeys.length === 1;
94
+ const key = isSingleKeyObject ? nonTildeKeys[0] : null;
95
+ const isOperatorObject = key && key.startsWith(operatorPrefix);
96
+ // Type boundary reset
97
+ const isTypeBoundary = type.isString(node.type) && resolvedTypeNames.has(node.type);
98
+ if (isTypeBoundary) {
99
+ delete node['~dyn'];
100
+ }
101
+ // Bubble up ~dyn from children (but not at type boundaries).
102
+ // _build.* operators always evaluate even with dynamic params, so skip bubble-up for them.
103
+ const isBuildOperator = isOperatorObject && operatorPrefix === '_build.';
104
+ if (!isTypeBoundary && !isBuildOperator && hasDynamicMarker(node)) {
105
+ return setDynamicMarker(node);
106
+ }
107
+ // Skip non-operator objects with ~r marker
108
+ if (type.isString(node['~r']) && !isOperatorObject) return node;
109
+ if (!isSingleKeyObject) return node;
110
+ if (!isOperatorObject) return node;
111
+ const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
112
+ // Dynamic identifier check — skip for _build.* operators
113
+ const fullIdentifier = methodName ? `${op}.${methodName}` : op;
114
+ if (operatorPrefix !== '_build.') {
115
+ if (resolvedDynamicIdentifiers.has(fullIdentifier) || resolvedDynamicIdentifiers.has(op)) {
116
+ return setDynamicMarker(node);
117
+ }
118
+ }
119
+ // Unknown operator — mark as dynamic
120
+ if (type.isUndefined(operators[op])) {
121
+ return setDynamicMarker(node);
122
+ }
123
+ // Dynamic params check — skip for _build.* operators (they always evaluate)
124
+ if (operatorPrefix !== '_build.') {
125
+ if (hasDynamicMarker(node[key])) {
126
+ return setDynamicMarker(node);
127
+ }
128
+ }
129
+ const configKey = node['~k'];
130
+ const lineNumber = node['~l'];
131
+ const refId = node['~r'];
132
+ const params = node[key];
133
+ try {
134
+ return operators[op]({
135
+ args,
136
+ arrayIndices: [],
137
+ env,
138
+ methodName,
139
+ operators,
140
+ params,
141
+ operatorPrefix,
142
+ parser,
143
+ runtime: 'node'
144
+ });
145
+ } catch (e) {
146
+ if (e instanceof ConfigError) {
147
+ if (!e.configKey) {
148
+ e.configKey = configKey;
149
+ }
150
+ if (!e.lineNumber) {
151
+ e.lineNumber = lineNumber;
152
+ }
153
+ if (!e.refId) {
154
+ e.refId = refId;
155
+ }
156
+ errors.push(e);
157
+ return null;
158
+ }
159
+ const operatorError = new OperatorError(e.message, {
160
+ cause: e,
161
+ typeName: op,
162
+ received: {
163
+ [key]: params
164
+ },
165
+ configKey: e.configKey ?? configKey
166
+ });
167
+ operatorError.lineNumber = lineNumber;
168
+ operatorError.refId = refId;
169
+ errors.push(operatorError);
170
+ return null;
171
+ }
172
+ }
173
+ const output = walk(input);
174
+ return {
175
+ output,
176
+ errors
177
+ };
178
+ }
179
+ export default evaluateOperators;
180
+ export { hasDynamicMarker, hasDynChild };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -26,12 +26,12 @@ function getFromArray({ params, array, key, operator, location }) {
26
26
  if (type.isString(params.value)) return array.find((item)=>item[key] === params.value);
27
27
  if (type.isNumber(params.index)) return array[params.index];
28
28
  if (!type.isNone(params.value) && !type.isString(params.value)) {
29
- throw new Error(`Operator Error: ${operator}.value must be of type string. Received: ${JSON.stringify(params)} at ${location}.`);
29
+ throw new Error(`${operator}.value must be of type string.`);
30
30
  }
31
31
  if (!type.isNone(params.index) && !type.isNumber(params.index)) {
32
- throw new Error(`Operator Error: ${operator}.index must be of type number. Received: ${JSON.stringify(params)} at ${location}.`);
32
+ throw new Error(`${operator}.index must be of type number.`);
33
33
  }
34
34
  }
35
- throw new Error(`Operator Error: ${operator} must be of type string, number or object. Received: ${JSON.stringify(params)} at ${location}.`);
35
+ throw new Error(`${operator} must be of type string, number or object.`);
36
36
  }
37
37
  export default getFromArray;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ function getFromObject({ params, object, arrayIndices, operator, location }) {
21
21
  key: params
22
22
  };
23
23
  if (!type.isObject(params)) {
24
- throw new Error(`Operator Error: ${operator} params must be of type string, integer, boolean or object. Received: ${JSON.stringify(params)} at ${location}.`);
24
+ throw new Error(`${operator} params must be of type string, integer, boolean or object.`);
25
25
  }
26
26
  if (params.key === null) return get(params, 'default', {
27
27
  default: null,
@@ -29,7 +29,7 @@ function getFromObject({ params, object, arrayIndices, operator, location }) {
29
29
  });
30
30
  if (params.all === true) return serializer.copy(object);
31
31
  if (!type.isString(params.key) && !type.isInt(params.key)) {
32
- throw new Error(`Operator Error: ${operator}.key must be of type string or integer. Received: ${JSON.stringify(params)} at ${location}.`);
32
+ throw new Error(`${operator}.key must be of type string or integer.`);
33
33
  }
34
34
  return get(object, applyArrayIndices(arrayIndices, params.key), {
35
35
  default: get(params, 'default', {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,11 +12,11 @@
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 BuildParser from './buildParser.js';
15
+ */ import evaluateOperators, { hasDynamicMarker, hasDynChild } from './evaluateOperators.js';
16
16
  import getFromArray from './getFromArray.js';
17
17
  import getFromObject from './getFromObject.js';
18
18
  import ServerParser from './serverParser.js';
19
19
  import runClass from './runClass.js';
20
20
  import runInstance from './runInstance.js';
21
21
  import WebParser from './webParser.js';
22
- export { BuildParser, getFromArray, getFromObject, ServerParser, runClass, runInstance, WebParser };
22
+ export { evaluateOperators, hasDynamicMarker, hasDynChild, getFromArray, getFromObject, ServerParser, runClass, runInstance, WebParser };
package/dist/runClass.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -20,25 +20,18 @@ const runClass = ({ location, meta, methodName, operator, params, functions, def
20
20
  } else if (defaultFunction) {
21
21
  methodName = defaultFunction;
22
22
  } else {
23
- throw new Error(`Operator Error: ${operator} requires a valid method name, use one of the following: ${Object.keys(meta).join(', ')}.
24
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
23
+ throw new Error(`${operator} requires a valid method name, use one of the following: ${Object.keys(meta).join(', ')}.`);
25
24
  }
26
25
  }
27
26
  if (!meta[methodName] && !functions[methodName]) {
28
- throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
29
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
27
+ throw new Error(`${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.`);
30
28
  }
31
29
  // validate params type
32
30
  if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
33
- throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
34
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
31
+ throw new Error(`${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.`);
35
32
  }
36
33
  if (meta[methodName].noArgs) {
37
- try {
38
- return functions[methodName]();
39
- } catch (e) {
40
- throw new Error(`Operator Error: ${operator}: - ${e.message} Received: {"${operator}":${JSON.stringify(params)}} at ${location}.`);
41
- }
34
+ return functions[methodName]();
42
35
  }
43
36
  let args = [];
44
37
  if (meta[methodName].singleArg || meta[methodName].property) {
@@ -52,8 +45,7 @@ const runClass = ({ location, meta, methodName, operator, params, functions, def
52
45
  if (type.isObject(params)) {
53
46
  args.push(...(meta[methodName].namedArgs || []).map((key)=>params[key]));
54
47
  if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
55
- throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
56
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
48
+ throw new Error(`${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.`);
57
49
  }
58
50
  args.push(...params[meta[methodName].spreadArgs] || []);
59
51
  }
@@ -67,10 +59,6 @@ const runClass = ({ location, meta, methodName, operator, params, functions, def
67
59
  if (meta[methodName].property) {
68
60
  return functions[methodName];
69
61
  }
70
- try {
71
- return functions[methodName](...args);
72
- } catch (e) {
73
- throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
74
- }
62
+ return functions[methodName](...args);
75
63
  };
76
64
  export default runClass;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,14 +14,15 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  const runInstance = ({ location, meta, methodName, operator, params, instanceType })=>{
17
+ if (type.isUndefined(methodName)) {
18
+ throw new Error(`${operator} requires a method. Use one of the following: ${Object.keys(meta).join(', ')}.`);
19
+ }
17
20
  if (!meta[methodName]) {
18
- throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
19
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
21
+ throw new Error(`${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.`);
20
22
  }
21
23
  // validate params type
22
24
  if (meta[methodName].validTypes && !meta[methodName].validTypes.includes(type.typeOf(params))) {
23
- throw new Error(`Operator Error: ${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.
24
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
25
+ throw new Error(`${operator}.${methodName} accepts one of the following types: ${meta[methodName].validTypes.join(', ')}.`);
25
26
  }
26
27
  let instance;
27
28
  let args = [];
@@ -38,8 +39,7 @@ const runInstance = ({ location, meta, methodName, operator, params, instanceTyp
38
39
  instance = params[meta[methodName].namedArgs[0]];
39
40
  args.push(...meta[methodName].namedArgs.slice(1).map((key)=>params[key]));
40
41
  if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
41
- throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
42
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
42
+ throw new Error(`${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.`);
43
43
  }
44
44
  args.push(...params[meta[methodName].spreadArgs] || []);
45
45
  }
@@ -51,26 +51,20 @@ const runInstance = ({ location, meta, methodName, operator, params, instanceTyp
51
51
  ]);
52
52
  }
53
53
  if (type.typeOf(instance) !== instanceType) {
54
- throw new Error(`Operator Error: ${operator}.${methodName} must be evaluated on an ${instanceType} instance. For named args provide an ${instanceType} instance to the "on" property, for listed args provide and ${instanceType} instance as the first element in the operator argument array.
55
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
54
+ throw new Error(`${operator}.${methodName} must be evaluated on an ${instanceType} instance. For named args provide an ${instanceType} instance to the "on" property, for listed args provide an ${instanceType} instance as the first element in the operator argument array.`);
56
55
  }
57
56
  // Error for invalid method key.
58
57
  if (type.isNone(instance[methodName])) {
59
- throw new Error(`Operator Error: ${operator} must be evaluated using one of the following: ${Object.keys(meta).join(', ')}.
60
- Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
58
+ throw new Error(`${operator} must be evaluated using one of the following: ${Object.keys(meta).join(', ')}.`);
61
59
  }
62
60
  // for property
63
61
  if (meta[methodName].property) {
64
62
  return instance[methodName];
65
63
  }
66
- try {
67
- const result = instance[methodName](...args);
68
- if (meta[methodName].returnInstance) {
69
- return instance;
70
- }
71
- return result;
72
- } catch (e) {
73
- throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
64
+ const result = instance[methodName](...args);
65
+ if (meta[methodName].returnInstance) {
66
+ return instance;
74
67
  }
68
+ return result;
75
69
  };
76
70
  export default runInstance;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,10 +12,9 @@
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 { serializer, type } from '@lowdefy/helpers';
15
+ */ import { ConfigError, OperatorError } from '@lowdefy/errors';
16
+ import { serializer, type } from '@lowdefy/helpers';
16
17
  let ServerParser = class ServerParser {
17
- // TODO: Look at logging here
18
- // TODO: Remove console.error = () => {}; from tests
19
18
  parse({ args, input, items, location, operatorPrefix = '_' }) {
20
19
  if (type.isUndefined(input)) {
21
20
  return {
@@ -32,14 +31,13 @@ let ServerParser = class ServerParser {
32
31
  const errors = [];
33
32
  const reviver = (_, value)=>{
34
33
  if (!type.isObject(value)) return value;
35
- // TODO: pass ~k in errors.
36
- // const _k = value['~k'];
37
- delete value['~k'];
38
34
  if (Object.keys(value).length !== 1) return value;
39
35
  const key = Object.keys(value)[0];
40
36
  if (!key.startsWith(operatorPrefix)) return value;
41
37
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
42
38
  if (type.isUndefined(this.operators[op])) return value;
39
+ const configKey = value['~k'];
40
+ const params = value[key];
43
41
  try {
44
42
  const res = this.operators[op]({
45
43
  args,
@@ -51,7 +49,7 @@ let ServerParser = class ServerParser {
51
49
  methodName,
52
50
  operatorPrefix,
53
51
  operators: this.operators,
54
- params: value[key],
52
+ params,
55
53
  parser: this,
56
54
  payload: this.payload,
57
55
  runtime: 'node',
@@ -62,10 +60,24 @@ let ServerParser = class ServerParser {
62
60
  });
63
61
  return res;
64
62
  } catch (e) {
65
- errors.push(e);
66
- if (this.verbose) {
67
- console.error(e);
63
+ if (e instanceof ConfigError) {
64
+ if (!e.configKey) {
65
+ e.configKey = configKey;
66
+ }
67
+ errors.push(e);
68
+ return null;
68
69
  }
70
+ const operatorError = new OperatorError(e.message, {
71
+ cause: e,
72
+ typeName: op,
73
+ methodName,
74
+ received: {
75
+ [key]: params
76
+ },
77
+ location,
78
+ configKey: e.configKey ?? configKey
79
+ });
80
+ errors.push(operatorError);
69
81
  return null;
70
82
  }
71
83
  };
@@ -76,7 +88,7 @@ let ServerParser = class ServerParser {
76
88
  errors
77
89
  };
78
90
  }
79
- constructor({ env, jsMap, operators, payload, secrets, state, steps, user, verbose }){
91
+ constructor({ env, jsMap, operators, payload, secrets, state, steps, user }){
80
92
  this.env = env;
81
93
  this.jsMap = jsMap;
82
94
  this.operators = operators;
@@ -86,7 +98,6 @@ let ServerParser = class ServerParser {
86
98
  this.state = state;
87
99
  this.steps = steps;
88
100
  this.user = user;
89
- this.verbose = verbose;
90
101
  }
91
102
  };
92
103
  export default ServerParser;
package/dist/webParser.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,8 @@
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, serializer, type } from '@lowdefy/helpers';
15
+ */ import { ConfigError, OperatorError } from '@lowdefy/errors';
16
+ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
17
  let WebParser = class WebParser {
17
18
  parse({ actions, args, arrayIndices, event, input, location, operatorPrefix = '_' }) {
18
19
  if (type.isUndefined(input)) {
@@ -34,14 +35,14 @@ let WebParser = class WebParser {
34
35
  const { apiResponses, basePath, home, inputs, lowdefyGlobal, menus, pageId, user, _internal } = this.context._internal.lowdefy;
35
36
  const reviver = (_, value)=>{
36
37
  if (!type.isObject(value)) return value;
37
- // TODO: pass ~k in errors.
38
- // const _k = value['~k'];
39
- delete value['~k'];
40
38
  if (Object.keys(value).length !== 1) return value;
41
39
  const key = Object.keys(value)[0];
42
40
  if (!key.startsWith(operatorPrefix)) return value;
43
41
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
44
42
  if (type.isUndefined(this.operators[op])) return value;
43
+ const configKey = value['~k'];
44
+ const params = value[key];
45
+ const operatorLocation = applyArrayIndices(arrayIndices, location);
45
46
  try {
46
47
  const res = this.operators[op]({
47
48
  actions,
@@ -55,14 +56,14 @@ let WebParser = class WebParser {
55
56
  home,
56
57
  input: inputs[this.context.id],
57
58
  jsMap: this.context.jsMap,
58
- location: applyArrayIndices(arrayIndices, location),
59
+ location: operatorLocation,
59
60
  lowdefyGlobal,
60
61
  menus,
61
62
  methodName,
62
63
  operatorPrefix,
63
64
  operators: this.operators,
64
65
  pageId,
65
- params: value[key],
66
+ params,
66
67
  parser: this,
67
68
  requests: this.context.requests,
68
69
  runtime: 'browser',
@@ -71,8 +72,25 @@ let WebParser = class WebParser {
71
72
  });
72
73
  return res;
73
74
  } catch (e) {
74
- errors.push(e);
75
- console.error(e);
75
+ // ConfigError from plugin - add configKey and re-throw structure
76
+ if (e instanceof ConfigError) {
77
+ if (!e.configKey) {
78
+ e.configKey = configKey;
79
+ }
80
+ errors.push(e);
81
+ return null;
82
+ }
83
+ // Plain error from plugin - wrap in OperatorError
84
+ errors.push(new OperatorError(e.message, {
85
+ cause: e,
86
+ typeName: op,
87
+ methodName,
88
+ received: {
89
+ [key]: params
90
+ },
91
+ location: operatorLocation,
92
+ configKey: e.configKey ?? configKey
93
+ }));
76
94
  return null;
77
95
  }
78
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.5.2",
3
+ "version": "4.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -34,7 +34,8 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "dependencies": {
37
- "@lowdefy/helpers": "4.5.2"
37
+ "@lowdefy/errors": "4.7.0",
38
+ "@lowdefy/helpers": "4.7.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@jest/globals": "28.1.3",
@@ -1,84 +0,0 @@
1
- /*
2
- Copyright 2020-2024 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 { serializer, type } from '@lowdefy/helpers';
16
- let BuildParser = class BuildParser {
17
- // TODO: Look at logging here
18
- // TODO: Remove console.error = () => {}; from tests
19
- parse({ args, input, location, operatorPrefix = '_' }) {
20
- if (type.isUndefined(input)) {
21
- return {
22
- output: input,
23
- errors: []
24
- };
25
- }
26
- if (args && !type.isArray(args)) {
27
- throw new Error('Operator parser args must be an array.');
28
- }
29
- if (!type.isString(location)) {
30
- throw new Error('Operator parser location must be a string.');
31
- }
32
- const errors = [];
33
- const reviver = (_, value)=>{
34
- if (!type.isObject(value)) return value;
35
- // TODO: pass ~r in errors. Build does not have ~k.
36
- if (type.isString(value['~r'])) return value;
37
- if (Object.keys(value).length !== 1) return value;
38
- const key = Object.keys(value)[0];
39
- if (!key.startsWith(operatorPrefix)) return value;
40
- const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
41
- if (type.isUndefined(this.operators[op])) return value;
42
- try {
43
- const res = this.operators[op]({
44
- args,
45
- arrayIndices: [],
46
- env: this.env,
47
- location,
48
- methodName,
49
- operators: this.operators,
50
- params: value[key],
51
- operatorPrefix,
52
- parser: this,
53
- payload: this.payload,
54
- runtime: 'node',
55
- secrets: this.secrets,
56
- user: this.user
57
- });
58
- return res;
59
- } catch (e) {
60
- errors.push(e);
61
- if (this.verbose) {
62
- console.error(e);
63
- }
64
- return null;
65
- }
66
- };
67
- return {
68
- output: serializer.copy(input, {
69
- reviver
70
- }),
71
- errors
72
- };
73
- }
74
- constructor({ env, payload, secrets, user, operators, verbose }){
75
- this.env = env;
76
- this.operators = operators;
77
- this.parse = this.parse.bind(this);
78
- this.payload = payload;
79
- this.secrets = secrets;
80
- this.user = user;
81
- this.verbose = verbose;
82
- }
83
- };
84
- export default BuildParser;