lakutata
Version:
An IoC-based universal application framework.
101 lines (81 loc) • 2.73 kB
JavaScript
import { isAsyncFunction as t } from "node:util/types";
import { InvalidAssistantFunctionTypeException as e } from "../../../exceptions/InvalidAssistantFunctionTypeException.mjs";
import { As as n } from "../../helpers/As.mjs";
import "../abstracts/Exception.mjs";
import "./BasicInfo.mjs";
import "../../../../vendor/Package.6.mjs";
import "../../../../vendor/Package.5.mjs";
import "../../../../vendor/Package.7.mjs";
import "./ThrowWarning.mjs";
import "../../helpers/Templating.mjs";
import "./CamelCase.mjs";
import "../../helpers/NoCase.mjs";
const a = Symbol("ASST.BEFORE.FUNC.SET");
const o = Symbol("ASST.AFTER.FUNC.SET");
const i = Symbol("ASST.MODIFIED");
function s(t, e, n, a) {
n.value = r(t, e, c(n.value, a), {
before: a
});
return n;
}
function f(t, e, n, a) {
n.value = r(t, e, c(n.value, a), {
after: a
});
return n;
}
function r(e, s, f, r) {
const c = Reflect.getOwnMetadata(a, e, s) || new Set;
const l = Reflect.getOwnMetadata(o, e, s) || new Set;
if (r.before) {
c.add(r.before);
Reflect.defineMetadata(a, c, e, s);
}
if (r.after) {
l.add(r.after);
Reflect.defineMetadata(o, l, e, s);
}
if (Reflect.hasOwnMetadata(i, e, s)) return n(f);
Reflect.defineMetadata(i, true, e, s);
let d;
if (t(f)) {
d = async function(...t) {
const n = Reflect.getOwnMetadata(a, e, s) || new Set;
const i = Reflect.getOwnMetadata(o, e, s) || new Set;
for (const e of n) {
const n = await e.call(this, ...t);
if (n !== undefined) t = n;
}
let r = await f.call(this, ...t);
for (const t of i) {
const e = await t.call(this, r);
if (e !== undefined) r = e;
}
return r;
};
} else {
d = function(...t) {
const i = Reflect.getOwnMetadata(a, e, s) || new Set;
const r = Reflect.getOwnMetadata(o, e, s) || new Set;
for (const e of i) {
const a = n(e.call(this, ...t));
if (a !== undefined) t = a;
}
let c = f.call(this, ...t);
for (const t of r) {
const e = n(t.call(this, c));
if (e !== undefined) c = e;
}
return c;
};
}
return d;
}
function c(n, a) {
if (!n) throw new e("Target method is undefined");
if (t(n)) return n;
if (!t(a)) return n;
throw new e("Assistant function must not be async function when target method is not async function");
}
export { f as RegisterAfterFunction, s as RegisterBeforeFunction };