Skip to content

Commit

Permalink
chore(operators): Cleanup operator classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gervwyk committed May 24, 2022
1 parent e8da9c0 commit 7324826
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
20 changes: 7 additions & 13 deletions packages/operators/src/nodeParser.js
Expand Up @@ -27,12 +27,6 @@ class NodeParser {
}

parse({ args, input, location, operatorPrefix = '_' }) {
const env = this.env;
const operators = this.operators;
const secrets = this.secrets;
const payload = this.payload;
const user = this.user;

if (type.isUndefined(input)) {
return { output: input, errors: [] };
}
Expand All @@ -50,21 +44,21 @@ class NodeParser {
if (!key.startsWith(operatorPrefix)) return value;

const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
if (type.isUndefined(operators[op])) return value;
if (type.isUndefined(this.operators[op])) return value;
try {
const res = operators[op]({
const res = this.operators[op]({
args,
arrayIndices: [],
env,
env: this.env,
location,
methodName,
operators: operators,
operators: this.operators,
params: value[key],
operatorPrefix,
parser: this,
payload,
secrets,
user,
payload: this.payload,
secrets: this.secrets,
user: this.user,
});
return res;
} catch (e) {
Expand Down
21 changes: 9 additions & 12 deletions packages/operators/src/webParser.js
Expand Up @@ -19,14 +19,11 @@ import { applyArrayIndices, serializer, type } from '@lowdefy/helpers';
class WebParser {
constructor({ context, operators }) {
this.context = context;
this.parse = this.parse.bind(this);
this.operators = operators;
this.parse = this.parse.bind(this);
}

parse({ actions, args, arrayIndices, event, input, location, operatorPrefix = '_' }) {
const operators = this.operators;
const context = this.context;

if (type.isUndefined(input)) {
return { output: input, errors: [] };
}
Expand All @@ -41,37 +38,37 @@ class WebParser {
}
const errors = [];
const { basePath, home, inputs, lowdefyGlobal, menus, pageId, urlQuery, user, _internal } =
context._internal.lowdefy;
this.context._internal.lowdefy;
const reviver = (_, value) => {
if (!type.isObject(value) || Object.keys(value).length !== 1) return value;

const key = Object.keys(value)[0];
if (!key.startsWith(operatorPrefix)) return value;

const [op, methodName] = `_${key.substring(operatorPrefix.length)}`.split('.');
if (type.isUndefined(operators[op])) return value;
if (type.isUndefined(this.operators[op])) return value;

try {
const res = operators[op]({
const res = this.operators[op]({
actions,
args,
arrayIndices,
basePath,
event,
eventLog: context.eventLog,
eventLog: this.context.eventLog,
home,
input: inputs ? inputs[context.id] : {},
input: inputs ? inputs[this.context.id] : {},
location: applyArrayIndices(arrayIndices, location),
lowdefyGlobal: lowdefyGlobal || {},
menus: menus || {},
methodName,
operatorPrefix,
operators,
operators: this.operators,
pageId,
params: value[key],
parser: this,
requests: context.requests,
state: context.state,
requests: this.context.requests,
state: this.context.state,
urlQuery: urlQuery || {},
user: user || {},
window: _internal.window,
Expand Down

0 comments on commit 7324826

Please sign in to comment.