UNPKG

lakutata

Version:

An IoC-based universal application framework.

110 lines (87 loc) 3.02 kB
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */ "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("../../../../vendor/Package.internal.5.cjs"); require("../../../../vendor/Package.internal.2.cjs"); require("../../../../vendor/Package.internal.6.cjs"); require("./ThrowWarning.cjs"); require("../../helpers/Templating.cjs"); require("./CamelCase.cjs"); require("../../helpers/NoCase.cjs"); require("../../helpers/DevNull.cjs"); const i = Symbol("ASST.BEFORE.FUNC.SET"); const s = Symbol("ASST.AFTER.FUNC.SET"); const a = Symbol("ASST.MODIFIED"); function c(e, t, n, i) { n.value = o(e, t, f(n.value, i), { before: i }); return n; } function r(e, t, n, i) { n.value = o(e, t, f(n.value, i), { after: i }); return n; } function o(t, c, r, o) { const f = Reflect.getOwnMetadata(i, t, c) || new Set; const u = Reflect.getOwnMetadata(s, t, c) || new Set; if (o.before) { f.add(o.before); Reflect.defineMetadata(i, f, t, c); } if (o.after) { u.add(o.after); Reflect.defineMetadata(s, u, t, c); } if (Reflect.hasOwnMetadata(a, t, c)) return n.As(r); Reflect.defineMetadata(a, true, t, c); let l; if (e.isAsyncFunction(r)) { l = async function(...e) { const n = Reflect.getOwnMetadata(i, t, c) || new Set; const a = Reflect.getOwnMetadata(s, t, c) || new Set; for (const t of n) { const n = await t.call(this, ...e); if (n !== undefined) e = n; } let o = await r.call(this, ...e); for (const e of a) { const t = await e.call(this, o); if (t !== undefined) o = t; } return o; }; } else { l = function(...e) { const a = Reflect.getOwnMetadata(i, t, c) || new Set; const o = Reflect.getOwnMetadata(s, t, c) || new Set; for (const t of a) { const i = n.As(t.call(this, ...e)); if (i !== undefined) e = i; } let f = r.call(this, ...e); for (const e of o) { const t = n.As(e.call(this, f)); if (t !== undefined) f = t; } return f; }; } return l; } function f(n, i) { if (!n) throw new t.InvalidAssistantFunctionTypeException("Target method is undefined"); if (e.isAsyncFunction(n)) return n; if (!e.isAsyncFunction(i)) return n; throw new t.InvalidAssistantFunctionTypeException("Assistant function must not be async function when target method is not async function"); } exports.RegisterAfterFunction = r; exports.RegisterBeforeFunction = c;