Skip to content

Commit

Permalink
Add argument overrida
Browse files Browse the repository at this point in the history
  • Loading branch information
greenscreens-io committed Oct 7, 2023
1 parent bc9e9cf commit de08dbe
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Generator extends QuarkEvent {
}
action = tree[api.action];

me.#reduce(api.methods)?.forEach(v => me.#buildMethod(api.namespace, api.action, action, v, me.#id));
me.#reduce(api.methods)?.forEach(v => me.#buildMethod(action, v, me.#id));

}

Expand All @@ -143,10 +143,11 @@ class Generator extends QuarkEvent {
}

const obj = objs.filter(r => r.name === v.name).reduce((a, v) => {
a.mid.push(v.mid);
a.len.push(v.len);
a.async[v.len] = v.async;
return a;
}, { name: v.name, len: [], async: {} });
}, { name: v.name, mid: [], len: [], async: {} });

a.push(obj);
return a
Expand Down Expand Up @@ -186,17 +187,16 @@ class Generator extends QuarkEvent {
/**
* Build instance methods
*
* @param {String} namespace
* @param {String} action
* @param {String} instance
* @param {Array} api
* @param {String} id
*/
#buildMethod(namespace, action, instance, api, id) {
#buildMethod(instance, api, id) {

const enc = api.encrypt === false ? false : true;
const cfg = {
l: api.len,
a: api.async,
a: api.async || false,
x: api.mid,
e: enc,
i: id
Expand Down Expand Up @@ -227,11 +227,12 @@ class Generator extends QuarkEvent {
const len = isOverride ? prop.l.filter(v => v === args.length).pop() : prop.l;
if (args.length != len) throw new Error(`Invalid arguments length. Required (${prop.l})`);

const handle = Array.isArray(prop.x) ? prop.x[len-1] : prop.x;
const isAsync = isOverride ? prop.a[args.length] : prop.a;
const timeout = isAsync ? 0 : me.#timeout;

const req = {
"handle": prop.x,
"handle": handle,
"id": prop.i,
"enc": prop.e,
"data": args,
Expand Down

0 comments on commit de08dbe

Please sign in to comment.