UNPKG

lakutata

Version:

An IoC-based universal application framework.

109 lines (86 loc) 2.91 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const e = require("node:util/types"); const t = require("../../../exceptions/InvalidAssistantFunctionTypeException.cjs"); const n = require("../../helpers/As.cjs"); require("../abstracts/Exception.cjs"); require("./BasicInfo.cjs"); require("../../../../vendor/Package.6.cjs"); require("../../../../vendor/Package.5.cjs"); require("../../../../vendor/Package.7.cjs"); require("./ThrowWarning.cjs"); require("../../helpers/Templating.cjs"); require("./CamelCase.cjs"); require("../../helpers/NoCase.cjs"); const s = Symbol("ASST.BEFORE.FUNC.SET"); const i = Symbol("ASST.AFTER.FUNC.SET"); const c = Symbol("ASST.MODIFIED"); function a(e, t, n, s) { n.value = r(e, t, f(n.value, s), { before: s }); return n; } function o(e, t, n, s) { n.value = r(e, t, f(n.value, s), { after: s }); return n; } function r(t, a, o, r) { const f = Reflect.getOwnMetadata(s, t, a) || new Set; const u = Reflect.getOwnMetadata(i, t, a) || new Set; if (r.before) { f.add(r.before); Reflect.defineMetadata(s, f, t, a); } if (r.after) { u.add(r.after); Reflect.defineMetadata(i, u, t, a); } if (Reflect.hasOwnMetadata(c, t, a)) return n.As(o); Reflect.defineMetadata(c, true, t, a); let l; if (e.isAsyncFunction(o)) { l = async function(...e) { const n = Reflect.getOwnMetadata(s, t, a) || new Set; const c = Reflect.getOwnMetadata(i, t, a) || new Set; for (const t of n) { const n = await t.call(this, ...e); if (n !== undefined) e = n; } let r = await o.call(this, ...e); for (const e of c) { const t = await e.call(this, r); if (t !== undefined) r = t; } return r; }; } else { l = function(...e) { const c = Reflect.getOwnMetadata(s, t, a) || new Set; const r = Reflect.getOwnMetadata(i, t, a) || new Set; for (const t of c) { const s = n.As(t.call(this, ...e)); if (s !== undefined) e = s; } let f = o.call(this, ...e); for (const e of r) { const t = n.As(e.call(this, f)); if (t !== undefined) f = t; } return f; }; } return l; } function f(n, s) { if (!n) throw new t.InvalidAssistantFunctionTypeException("Target method is undefined"); if (e.isAsyncFunction(n)) return n; if (!e.isAsyncFunction(s)) return n; throw new t.InvalidAssistantFunctionTypeException("Assistant function must not be async function when target method is not async function"); } exports.RegisterAfterFunction = o; exports.RegisterBeforeFunction = a;