UNPKG

lakutata

Version:

An IoC-based universal application framework.

102 lines (82 loc) 2.84 kB
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */ 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 "../../../../vendor/Package.internal.5.mjs"; import "../../../../vendor/Package.internal.2.mjs"; import "../../../../vendor/Package.internal.6.mjs"; import "./ThrowWarning.mjs"; import "../../helpers/Templating.mjs"; import "./CamelCase.mjs"; import "../../helpers/NoCase.mjs"; import "../../helpers/DevNull.mjs"; const a = Symbol("ASST.BEFORE.FUNC.SET"); const o = Symbol("ASST.AFTER.FUNC.SET"); const i = Symbol("ASST.MODIFIED"); function r(t, e, n, a) { n.value = f(t, e, c(n.value, a), { before: a }); return n; } function s(t, e, n, a) { n.value = f(t, e, c(n.value, a), { after: a }); return n; } function f(e, r, s, f) { const c = Reflect.getOwnMetadata(a, e, r) || new Set; const l = Reflect.getOwnMetadata(o, e, r) || new Set; if (f.before) { c.add(f.before); Reflect.defineMetadata(a, c, e, r); } if (f.after) { l.add(f.after); Reflect.defineMetadata(o, l, e, r); } if (Reflect.hasOwnMetadata(i, e, r)) return n(s); Reflect.defineMetadata(i, true, e, r); let d; if (t(s)) { d = async function(...t) { const n = Reflect.getOwnMetadata(a, e, r) || new Set; const i = Reflect.getOwnMetadata(o, e, r) || new Set; for (const e of n) { const n = await e.call(this, ...t); if (n !== undefined) t = n; } let f = await s.call(this, ...t); for (const t of i) { const e = await t.call(this, f); if (e !== undefined) f = e; } return f; }; } else { d = function(...t) { const i = Reflect.getOwnMetadata(a, e, r) || new Set; const f = Reflect.getOwnMetadata(o, e, r) || new Set; for (const e of i) { const a = n(e.call(this, ...t)); if (a !== undefined) t = a; } let c = s.call(this, ...t); for (const t of f) { 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 { s as RegisterAfterFunction, r as RegisterBeforeFunction };