@lowdefy/operators 4.0.0-alpha.9 → 4.0.0-rc.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.
@@ -16,16 +16,14 @@
16
16
  function getFromArray({ params , array , key , operator , location }) {
17
17
  if (params === true) return array;
18
18
  if (type.isString(params)) {
19
- return array.find((item)=>item[key] === params
20
- );
19
+ return array.find((item)=>item[key] === params);
21
20
  }
22
21
  if (type.isNumber(params)) {
23
22
  return array[params];
24
23
  }
25
24
  if (type.isObject(params)) {
26
25
  if (params.all === true) return array;
27
- if (type.isString(params.value)) return array.find((item)=>item[key] === params.value
28
- );
26
+ if (type.isString(params.value)) return array.find((item)=>item[key] === params.value);
29
27
  if (type.isNumber(params.index)) return array[params.index];
30
28
  if (!type.isNone(params.value) && !type.isString(params.value)) {
31
29
  throw new Error(`Operator Error: ${operator}.value must be of type string. Received: ${JSON.stringify(params)} at ${location}.`);
@@ -14,12 +14,9 @@
14
14
  limitations under the License.
15
15
  */ import { serializer, type } from '@lowdefy/helpers';
16
16
  let NodeParser = class NodeParser {
17
+ // TODO: Look at logging here
18
+ // TODO: Remove console.error = () => {}; from tests
17
19
  parse({ args , input , location , operatorPrefix ='_' }) {
18
- const env = this.env;
19
- const operators = this.operators;
20
- const secrets = this.secrets;
21
- const payload = this.payload;
22
- const user = this.user;
23
20
  if (type.isUndefined(input)) {
24
21
  return {
25
22
  output: input,
@@ -38,26 +35,29 @@ let NodeParser = class NodeParser {
38
35
  const key = Object.keys(value)[0];
39
36
  if (!key.startsWith(operatorPrefix)) return value;
40
37
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
41
- if (type.isUndefined(operators[op])) return value;
38
+ if (type.isUndefined(this.operators[op])) return value;
42
39
  try {
43
- const res = operators[op]({
40
+ const res = this.operators[op]({
44
41
  args,
45
42
  arrayIndices: [],
46
- env,
43
+ env: this.env,
47
44
  location,
48
45
  methodName,
49
- operators: operators,
46
+ operators: this.operators,
50
47
  params: value[key],
51
48
  operatorPrefix,
52
49
  parser: this,
53
- payload,
54
- secrets,
55
- user
50
+ payload: this.payload,
51
+ runtime: 'node',
52
+ secrets: this.secrets,
53
+ user: this.user
56
54
  });
57
55
  return res;
58
56
  } catch (e) {
59
57
  errors.push(e);
60
- console.error(e);
58
+ if (this.verbose) {
59
+ console.error(e);
60
+ }
61
61
  return null;
62
62
  }
63
63
  };
@@ -68,13 +68,14 @@ let NodeParser = class NodeParser {
68
68
  errors
69
69
  };
70
70
  }
71
- constructor({ env , payload , secrets , user , operators }){
71
+ constructor({ env , payload , secrets , user , operators , verbose }){
72
72
  this.env = env;
73
73
  this.operators = operators;
74
74
  this.payload = payload;
75
75
  this.secrets = secrets;
76
76
  this.user = user;
77
77
  this.parse = this.parse.bind(this);
78
+ this.verbose;
78
79
  }
79
80
  };
80
81
  export default NodeParser;
package/dist/runClass.js CHANGED
@@ -50,8 +50,7 @@ const runClass = ({ location , meta , methodName , operator , params , functions
50
50
  args = params;
51
51
  }
52
52
  if (type.isObject(params)) {
53
- args.push(...(meta[methodName].namedArgs || []).map((key)=>params[key]
54
- ));
53
+ args.push(...(meta[methodName].namedArgs || []).map((key)=>params[key]));
55
54
  if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
56
55
  throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
57
56
  Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
@@ -36,8 +36,7 @@ const runInstance = ({ location , meta , methodName , operator , params , instan
36
36
  // Instance must be listed first in named args.
37
37
  if (type.isObject(params)) {
38
38
  instance = params[meta[methodName].namedArgs[0]];
39
- args.push(...meta[methodName].namedArgs.slice(1).map((key)=>params[key]
40
- ));
39
+ args.push(...meta[methodName].namedArgs.slice(1).map((key)=>params[key]));
41
40
  if (!type.isNone(meta[methodName].spreadArgs) && !type.isArray(params[meta[methodName].spreadArgs])) {
42
41
  throw new Error(`Operator Error: ${operator}.${methodName} takes an array as input argument for ${meta[methodName].spreadArgs}.
43
42
  Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
package/dist/webParser.js CHANGED
@@ -15,8 +15,6 @@
15
15
  */ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
16
  let WebParser = class WebParser {
17
17
  parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
18
- const operators = this.operators;
19
- const context = this.context;
20
18
  if (type.isUndefined(input)) {
21
19
  return {
22
20
  output: input,
@@ -33,34 +31,37 @@ let WebParser = class WebParser {
33
31
  throw new Error('Operator parser location must be a string.');
34
32
  }
35
33
  const errors = [];
36
- const { inputs , lowdefyGlobal , menus , urlQuery , user } = context._internal.lowdefy;
34
+ const { basePath , home , inputs , lowdefyGlobal , menus , pageId , user , _internal } = this.context._internal.lowdefy;
37
35
  const reviver = (_, value)=>{
38
36
  if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
39
37
  const key = Object.keys(value)[0];
40
38
  if (!key.startsWith(operatorPrefix)) return value;
41
39
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
42
- if (type.isUndefined(operators[op])) return value;
40
+ if (type.isUndefined(this.operators[op])) return value;
43
41
  try {
44
- const res = operators[op]({
45
- eventLog: context.eventLog,
42
+ const res = this.operators[op]({
46
43
  actions,
47
44
  args,
48
45
  arrayIndices,
49
- context,
46
+ basePath,
50
47
  event,
51
- input: inputs ? inputs[context.id] : {},
48
+ eventLog: this.context.eventLog,
49
+ globals: _internal.globals,
50
+ home,
51
+ input: inputs ? inputs[this.context.id] : {},
52
52
  location: applyArrayIndices(arrayIndices, location),
53
- lowdefyGlobal: lowdefyGlobal || {},
54
- menus: menus || {},
53
+ lowdefyGlobal: lowdefyGlobal ?? {},
54
+ menus: menus ?? [],
55
55
  methodName,
56
- operators,
57
56
  operatorPrefix,
57
+ operators: this.operators,
58
+ pageId,
58
59
  params: value[key],
59
- requests: context.requests,
60
- state: context.state,
61
- urlQuery: urlQuery || {},
62
- user: user || {},
63
- parser: this
60
+ parser: this,
61
+ requests: this.context.requests,
62
+ runtime: 'browser',
63
+ state: this.context.state,
64
+ user: user ?? {}
64
65
  });
65
66
  return res;
66
67
  } catch (e) {
@@ -78,8 +79,8 @@ let WebParser = class WebParser {
78
79
  }
79
80
  constructor({ context , operators }){
80
81
  this.context = context;
81
- this.parse = this.parse.bind(this);
82
82
  this.operators = operators;
83
+ this.parse = this.parse.bind(this);
83
84
  }
84
85
  };
85
86
  export default WebParser;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-alpha.9",
4
- "licence": "Apache-2.0",
3
+ "version": "4.0.0-rc.0",
4
+ "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
7
7
  "keywords": [
@@ -34,24 +34,24 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "scripts": {
37
- "build": "yarn clean && yarn swc",
37
+ "build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
38
38
  "clean": "rm -rf dist",
39
- "prepare": "yarn build",
40
- "swc": "swc src --out-dir dist --config-file ../../.swcrc",
39
+ "prepublishOnly": "pnpm build",
41
40
  "test": "jest --coverage --testTimeout=10000",
42
41
  "test:watch": "jest --coverage --watch"
43
42
  },
44
43
  "dependencies": {
45
- "@lowdefy/helpers": "4.0.0-alpha.9"
44
+ "@lowdefy/helpers": "4.0.0-rc.0"
46
45
  },
47
46
  "devDependencies": {
48
- "@swc/cli": "0.1.55",
49
- "@swc/core": "1.2.135",
50
- "@swc/jest": "0.2.17",
51
- "jest": "27.5.1"
47
+ "@swc/cli": "0.1.57",
48
+ "@swc/core": "1.2.194",
49
+ "@swc/jest": "0.2.21",
50
+ "jest": "28.1.0",
51
+ "jest-environment-jsdom": "28.1.0"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
56
+ "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
57
57
  }