@lowdefy/operators 4.0.0-alpha.8 → 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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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.
@@ -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}.`);
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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,19 +14,9 @@
14
14
  limitations under the License.
15
15
  */ import { serializer, type } from '@lowdefy/helpers';
16
16
  let NodeParser = class NodeParser {
17
- async init() {
18
- await Promise.all(Object.values(this.operators).map(async (operator)=>{
19
- if (operator.init) {
20
- await operator.init();
21
- }
22
- }));
23
- }
17
+ // TODO: Look at logging here
18
+ // TODO: Remove console.error = () => {}; from tests
24
19
  parse({ args , input , location , operatorPrefix ='_' }) {
25
- const env = this.env;
26
- const operators = this.operators;
27
- const secrets = this.secrets;
28
- const payload = this.payload;
29
- const user = this.user;
30
20
  if (type.isUndefined(input)) {
31
21
  return {
32
22
  output: input,
@@ -45,26 +35,29 @@ let NodeParser = class NodeParser {
45
35
  const key = Object.keys(value)[0];
46
36
  if (!key.startsWith(operatorPrefix)) return value;
47
37
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
48
- if (type.isUndefined(operators[op])) return value;
38
+ if (type.isUndefined(this.operators[op])) return value;
49
39
  try {
50
- const res = operators[op]({
40
+ const res = this.operators[op]({
51
41
  args,
52
42
  arrayIndices: [],
53
- env,
43
+ env: this.env,
54
44
  location,
55
45
  methodName,
56
- operators: operators,
46
+ operators: this.operators,
57
47
  params: value[key],
58
48
  operatorPrefix,
59
49
  parser: this,
60
- payload,
61
- secrets,
62
- user
50
+ payload: this.payload,
51
+ runtime: 'node',
52
+ secrets: this.secrets,
53
+ user: this.user
63
54
  });
64
55
  return res;
65
56
  } catch (e) {
66
57
  errors.push(e);
67
- console.error(e);
58
+ if (this.verbose) {
59
+ console.error(e);
60
+ }
68
61
  return null;
69
62
  }
70
63
  };
@@ -75,13 +68,14 @@ let NodeParser = class NodeParser {
75
68
  errors
76
69
  };
77
70
  }
78
- constructor({ env , payload , secrets , user , operators }){
71
+ constructor({ env , payload , secrets , user , operators , verbose }){
79
72
  this.env = env;
80
73
  this.operators = operators;
81
74
  this.payload = payload;
82
75
  this.secrets = secrets;
83
76
  this.user = user;
84
77
  this.parse = this.parse.bind(this);
78
+ this.verbose;
85
79
  }
86
80
  };
87
81
  export default NodeParser;
package/dist/runClass.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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.
@@ -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}.`);
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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.
@@ -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
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 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,19 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
16
  let WebParser = class WebParser {
17
- async init() {
18
- if (!type.isObject(this.context._internal.lowdefy)) {
19
- throw new Error('context._internal.lowdefy must be an object.');
20
- }
21
- await Promise.all(Object.values(this.operators).map(async (operator)=>{
22
- if (operator.init) {
23
- await operator.init();
24
- }
25
- }));
26
- }
27
17
  parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
28
- const operators = this.operators;
29
- const context = this.context;
30
18
  if (type.isUndefined(input)) {
31
19
  return {
32
20
  output: input,
@@ -43,33 +31,37 @@ let WebParser = class WebParser {
43
31
  throw new Error('Operator parser location must be a string.');
44
32
  }
45
33
  const errors = [];
46
- const { inputs , lowdefyGlobal , menus , urlQuery , user } = context._internal.lowdefy;
34
+ const { basePath , home , inputs , lowdefyGlobal , menus , pageId , user , _internal } = this.context._internal.lowdefy;
47
35
  const reviver = (_, value)=>{
48
36
  if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
49
37
  const key = Object.keys(value)[0];
50
38
  if (!key.startsWith(operatorPrefix)) return value;
51
39
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
52
- if (type.isUndefined(operators[op])) return value;
40
+ if (type.isUndefined(this.operators[op])) return value;
53
41
  try {
54
- const res = operators[op]({
55
- eventLog: context.eventLog,
42
+ const res = this.operators[op]({
56
43
  actions,
57
44
  args,
58
45
  arrayIndices,
59
- context: context,
46
+ basePath,
60
47
  event,
61
- input: inputs ? inputs[context.id] : {},
48
+ eventLog: this.context.eventLog,
49
+ globals: _internal.globals,
50
+ home,
51
+ input: inputs ? inputs[this.context.id] : {},
62
52
  location: applyArrayIndices(arrayIndices, location),
63
- lowdefyGlobal: lowdefyGlobal || {},
64
- menus: menus || {},
53
+ lowdefyGlobal: lowdefyGlobal ?? {},
54
+ menus: menus ?? [],
65
55
  methodName,
66
- operators: operators,
56
+ operatorPrefix,
57
+ operators: this.operators,
58
+ pageId,
67
59
  params: value[key],
68
- requests: context.requests,
69
- state: context.state,
70
- urlQuery: urlQuery || {},
71
- user: user || {},
72
- parser: this
60
+ parser: this,
61
+ requests: this.context.requests,
62
+ runtime: 'browser',
63
+ state: this.context.state,
64
+ user: user ?? {}
73
65
  });
74
66
  return res;
75
67
  } catch (e) {
@@ -87,9 +79,8 @@ let WebParser = class WebParser {
87
79
  }
88
80
  constructor({ context , operators }){
89
81
  this.context = context;
90
- this.init = this.init.bind(this);
91
- this.parse = this.parse.bind(this);
92
82
  this.operators = operators;
83
+ this.parse = this.parse.bind(this);
93
84
  }
94
85
  };
95
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.8",
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.8"
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": "9d56b83cf45e868afe3a1eeba750fe826eb74c8c"
56
+ "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
57
57
  }