@lowdefy/operators 4.0.0-rc.1 → 4.0.0-rc.11

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,84 @@
1
+ /*
2
+ Copyright 2020-2023 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;
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- function getFromArray({ params , array , key , operator , location }) {
16
+ function getFromArray({ params, array, key, operator, location }) {
17
17
  if (params === true) return array;
18
18
  if (type.isString(params)) {
19
19
  return array.find((item)=>item[key] === params);
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
16
- function getFromObject({ params , object , arrayIndices , operator , location }) {
16
+ function getFromObject({ params, object, arrayIndices, operator, location }) {
17
17
  if (params === true) params = {
18
18
  all: true
19
19
  };
package/dist/index.js CHANGED
@@ -12,10 +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 getFromArray from './getFromArray.js';
15
+ */ import BuildParser from './buildParser.js';
16
+ import getFromArray from './getFromArray.js';
16
17
  import getFromObject from './getFromObject.js';
17
- import NodeParser from './nodeParser.js';
18
+ import ServerParser from './serverParser.js';
18
19
  import runClass from './runClass.js';
19
20
  import runInstance from './runInstance.js';
20
21
  import WebParser from './webParser.js';
21
- export { getFromArray, getFromObject, NodeParser, runClass, runInstance, WebParser };
22
+ export { BuildParser, getFromArray, getFromObject, ServerParser, runClass, runInstance, WebParser };
package/dist/runClass.js CHANGED
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- const runClass = ({ location , meta , methodName , operator , params , functions , defaultFunction })=>{
16
+ const runClass = ({ location, meta, methodName, operator, params, functions, defaultFunction })=>{
17
17
  if (!methodName) {
18
18
  if (meta[params]) {
19
19
  methodName = params;
@@ -69,8 +69,8 @@ const runClass = ({ location , meta , methodName , operator , params , functions
69
69
  }
70
70
  try {
71
71
  return functions[methodName](...args);
72
- } catch (e1) {
73
- throw new Error(`Operator Error: ${operator}.${methodName} - ${e1.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
72
+ } catch (e) {
73
+ throw new Error(`Operator Error: ${operator}.${methodName} - ${e.message} Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
74
74
  }
75
75
  };
76
76
  export default runClass;
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- const runInstance = ({ location , meta , methodName , operator , params , instanceType })=>{
16
+ const runInstance = ({ location, meta, methodName, operator, params, instanceType })=>{
17
17
  if (!meta[methodName]) {
18
18
  throw new Error(`Operator Error: ${operator}.${methodName} is not supported, use one of the following: ${Object.keys(meta).join(', ')}.
19
19
  Received: {"${operator}.${methodName}":${JSON.stringify(params)}} at ${location}.`);
@@ -13,10 +13,10 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { serializer, type } from '@lowdefy/helpers';
16
- let NodeParser = class NodeParser {
16
+ let ServerParser = class ServerParser {
17
17
  // TODO: Look at logging here
18
18
  // TODO: Remove console.error = () => {}; from tests
19
- parse({ args , input , location , operatorPrefix ='_' }) {
19
+ parse({ args, input, location, operatorPrefix = '_' }) {
20
20
  if (type.isUndefined(input)) {
21
21
  return {
22
22
  output: input,
@@ -31,7 +31,11 @@ let NodeParser = class NodeParser {
31
31
  }
32
32
  const errors = [];
33
33
  const reviver = (_, value)=>{
34
- if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
34
+ if (!type.isObject(value)) return value;
35
+ // TODO: pass ~k in errors.
36
+ // const _k = value['~k'];
37
+ delete value['~k'];
38
+ if (Object.keys(value).length !== 1) return value;
35
39
  const key = Object.keys(value)[0];
36
40
  if (!key.startsWith(operatorPrefix)) return value;
37
41
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
@@ -68,14 +72,14 @@ let NodeParser = class NodeParser {
68
72
  errors
69
73
  };
70
74
  }
71
- constructor({ env , payload , secrets , user , operators , verbose }){
75
+ constructor({ env, payload, secrets, user, operators, verbose }){
72
76
  this.env = env;
73
77
  this.operators = operators;
74
78
  this.payload = payload;
75
79
  this.secrets = secrets;
76
80
  this.user = user;
77
81
  this.parse = this.parse.bind(this);
78
- this.verbose;
82
+ this.verbose = verbose;
79
83
  }
80
84
  };
81
- export default NodeParser;
85
+ export default ServerParser;
package/dist/webParser.js CHANGED
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
16
16
  let WebParser = class WebParser {
17
- parse({ actions , args , arrayIndices , event , input , location , operatorPrefix ='_' }) {
17
+ parse({ actions, args, arrayIndices, event, input, location, operatorPrefix = '_' }) {
18
18
  if (type.isUndefined(input)) {
19
19
  return {
20
20
  output: input,
@@ -31,9 +31,13 @@ let WebParser = class WebParser {
31
31
  throw new Error('Operator parser location must be a string.');
32
32
  }
33
33
  const errors = [];
34
- const { basePath , home , inputs , lowdefyGlobal , menus , pageId , user , _internal } = this.context._internal.lowdefy;
34
+ const { basePath, home, inputs, lowdefyGlobal, menus, pageId, user, _internal } = this.context._internal.lowdefy;
35
35
  const reviver = (_, value)=>{
36
- if (!type.isObject(value) || Object.keys(value).length !== 1) return value;
36
+ if (!type.isObject(value)) return value;
37
+ // TODO: pass ~k in errors.
38
+ // const _k = value['~k'];
39
+ delete value['~k'];
40
+ if (Object.keys(value).length !== 1) return value;
37
41
  const key = Object.keys(value)[0];
38
42
  if (!key.startsWith(operatorPrefix)) return value;
39
43
  const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
@@ -48,10 +52,10 @@ let WebParser = class WebParser {
48
52
  eventLog: this.context.eventLog,
49
53
  globals: _internal.globals,
50
54
  home,
51
- input: inputs ? inputs[this.context.id] : {},
55
+ input: inputs[this.context.id],
52
56
  location: applyArrayIndices(arrayIndices, location),
53
- lowdefyGlobal: lowdefyGlobal ?? {},
54
- menus: menus ?? [],
57
+ lowdefyGlobal: lowdefyGlobal,
58
+ menus: menus,
55
59
  methodName,
56
60
  operatorPrefix,
57
61
  operators: this.operators,
@@ -77,7 +81,7 @@ let WebParser = class WebParser {
77
81
  errors
78
82
  };
79
83
  }
80
- constructor({ context , operators }){
84
+ constructor({ context, operators }){
81
85
  this.context = context;
82
86
  this.operators = operators;
83
87
  this.parse = this.parse.bind(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -40,18 +40,18 @@
40
40
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=10000"
41
41
  },
42
42
  "dependencies": {
43
- "@lowdefy/helpers": "4.0.0-rc.1"
43
+ "@lowdefy/helpers": "4.0.0-rc.11"
44
44
  },
45
45
  "devDependencies": {
46
- "@jest/globals": "28.1.0",
47
- "@swc/cli": "0.1.59",
48
- "@swc/core": "1.3.24",
49
- "@swc/jest": "0.2.24",
50
- "jest": "28.1.0",
51
- "jest-environment-jsdom": "28.1.0"
46
+ "@jest/globals": "28.1.3",
47
+ "@swc/cli": "0.1.62",
48
+ "@swc/core": "1.3.92",
49
+ "@swc/jest": "0.2.29",
50
+ "jest": "28.1.3",
51
+ "jest-environment-jsdom": "28.1.3"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
56
+ "gitHead": "dbc49d3688a6d2f44de25cc3f4bc071627f7ebfa"
57
57
  }