UNPKG

lakutata

Version:

An IoC-based universal application framework.

269 lines (217 loc) 5.57 kB
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */ import { DependencyInjectionTypeError as t } from "./Errors.mjs"; import { InjectionMode as e } from "./InjectionMode.mjs"; import { Lifetime as n } from "./Lifetime.mjs"; import { parseParameterList as r } from "./ParamParser.mjs"; import { isFunction as o, uniq as i } from "./Utils.mjs"; import "../../exceptions/di/DependencyInjectionException.mjs"; import "../base/abstracts/Exception.mjs"; import "../../../vendor/Package.internal.5.mjs"; import "../helpers/As.mjs"; import "../../../vendor/Package.internal.2.mjs"; import "../../../vendor/Package.internal.6.mjs"; import "../base/internal/ThrowWarning.mjs"; import "../helpers/Templating.mjs"; import "../base/internal/CamelCase.mjs"; import "../helpers/NoCase.mjs"; import "../helpers/DevNull.mjs"; import "../base/internal/ConstructorSymbol.mjs"; import "../../constants/DIMetadataKey.mjs"; import "../../../vendor/Package.internal.1.mjs"; import "node:crypto"; import "../../../vendor/Package.internal.7.mjs"; import "../../../vendor/Package.internal.3.mjs"; import "../base/internal/DataValidator.mjs"; import "node:util/types"; import "../validation/VLD.mjs"; import "url"; import "util"; import "../../exceptions/dto/InvalidValueException.mjs"; import "../../../vendor/Package.internal.8.mjs"; import "../helpers/IsHtml.mjs"; import "../helpers/IsXML.mjs"; import "../../constants/DTOMetadataKey.mjs"; import "../helpers/ObjectConstructor.mjs"; import "../helpers/ObjectParentConstructors.mjs"; import "../helpers/ObjectParentConstructor.mjs"; import "../helpers/ObjectPrototype.mjs"; import "./FunctionTokenizer.mjs"; const s = Symbol("Dependency Injection Resolver Config"); function c(t) { return { resolve: () => t, isLeakSafe: true }; } function m(e, r) { if (!o(e)) { throw new t("asFunction", "fn", "function", e); } const i = { lifetime: n.TRANSIENT }; r = j(i, r, e[s]); const c = g(e); const m = { resolve: c, ...r }; return l(p(m)); } function a(e, r) { if (!o(e)) { throw new t("asClass", "Type", "class", e); } const i = { lifetime: n.TRANSIENT }; r = j(i, r, e[s]); const c = function t(...n) { return Reflect.construct(e, n); }; const m = g(c, e); return l(p({ ...r, resolve: m })); } function u(t) { return { resolve(e) { return e.resolve(t); }, isLeakSafe: true }; } function p(t) { function r(t) { return p({ ...this, lifetime: t }); } function o(t) { return p({ ...this, injectionMode: t }); } function i(t) { return p({ ...this, injector: t }); } return d(t, { setLifetime: r, inject: i, transient: f(r, n.TRANSIENT), scoped: f(r, n.SCOPED), singleton: f(r, n.SINGLETON), setInjectionMode: o, proxy: f(o, e.PROXY), classic: f(o, e.CLASSIC) }); } function l(t) { function e(t) { return l({ ...this, dispose: t }); } return d(t, { disposer: e }); } function f(t, e) { return function n() { return t.call(this, e); }; } function j(t, ...e) { return Object.assign({}, t, ...e); } function d(t, e) { const n = { ...t, ...e }; return n; } function h(t, e) { return function n(r, o) { if (r in e) { return e[r]; } return t.resolve(r, o); }; } function y(t, e) { const n = e(t); const r = i([ ...Reflect.ownKeys(t.cradle), ...Reflect.ownKeys(n) ]); const o = new Proxy({}, { get(e, r) { if (r === Symbol.iterator) { return function* e() { for (const e in t.cradle) { yield e; } for (const t in n) { yield t; } }; } if (r in n) { return n[r]; } return t.resolve(r); }, ownKeys() { return r; }, getOwnPropertyDescriptor(t, e) { if (r.indexOf(e) > -1) { return { enumerable: true, configurable: true }; } return undefined; } }); return o; } function g(t, n) { if (!n) { n = t; } const r = v(n); return function n(o) { const i = this.injectionMode || o.options.injectionMode || e.PROXY; if (i !== e.CLASSIC) { const e = this.injector ? y(o, this.injector) : o.cradle; return t(e); } if (r.length > 0) { const e = this.injector ? h(o, this.injector(o)) : o.resolve; const n = r.map(t => e(t.name, { allowUnregistered: t.optional })); return t(...n); } return t(); }; } function v(t) { const e = r(t.toString()); if (!e) { const e = Object.getPrototypeOf(t); if (typeof e === "function" && e !== Function.prototype) { return v(e); } return []; } return e; } export { s as RESOLVER, u as aliasTo, a as asClass, m as asFunction, c as asValue };