UNPKG

lakutata

Version:

An IoC-based universal application framework.

440 lines (305 loc) 11.6 kB
import { _ as t, a as e } from "../../../vendor/Package.1.mjs"; import { Module as o, MODULE_INITIALIZED as i, MODULE_INITIALIZE_ERROR as s } from "./Module.mjs"; import { Singleton as r } from "../../decorators/di/Lifetime.mjs"; import { C as n } from "../../../vendor/Package.3.mjs"; import { ApplicationConfigLoader as a } from "../base/internal/ApplicationConfigLoader.mjs"; import { ApplicationOptions as m } from "../../options/ApplicationOptions.mjs"; import { Alias as p } from "./Alias.mjs"; import { GetBasicInfo as c } from "../base/internal/BasicInfo.mjs"; import { Entrypoint as l } from "../../components/entrypoint/Entrypoint.mjs"; import { L as j } from "../../../vendor/Package.17.mjs"; import { Accept as h } from "../../decorators/dto/Accept.mjs"; import { D as u } from "../../../vendor/Package.2.mjs"; import { mkdirSync as d } from "fs"; import g from "node:path"; import { existsSync as b } from "node:fs"; import { As as x } from "../helpers/As.mjs"; import { EventEmitter as E } from "../base/EventEmitter.mjs"; import "./Component.mjs"; import "./Provider.mjs"; import "../base/async-constructor/AsyncConstructor.mjs"; import "../base/async-constructor/Append.mjs"; import "../helpers/IsPromiseLike.mjs"; import "../helpers/IsPromise.mjs"; import "util/types"; import "../../exceptions/MethodNotFoundException.mjs"; import "../base/abstracts/Exception.mjs"; import "../helpers/Templating.mjs"; import "../base/internal/CamelCase.mjs"; import "../helpers/NoCase.mjs"; import "../../../vendor/Package.6.mjs"; import "../../../vendor/Package.5.mjs"; import "../../../vendor/Package.7.mjs"; import "../base/internal/ThrowWarning.mjs"; import "../ioc/DependencyInjectionContainer.mjs"; import "util"; import "../ioc/Errors.mjs"; import "../../exceptions/di/DependencyInjectionException.mjs"; import "../base/internal/ConstructorSymbol.mjs"; import "../../constants/DIMetadataKey.mjs"; import "../../../vendor/Package.4.mjs"; import "node:crypto"; import "../base/internal/DataValidator.mjs"; import "node:util/types"; import "../validation/VLD.mjs"; import "../../../vendor/Package.11.mjs"; import "url"; import "../../../vendor/Package.10.mjs"; import "../../exceptions/dto/InvalidValueException.mjs"; import "../../../vendor/Package.9.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 "../ioc/InjectionMode.mjs"; import "../ioc/Lifetime.mjs"; import "../ioc/ListModules.mjs"; import "../../../vendor/Package.8.mjs"; import "os"; import "path"; import "stream"; import "events"; import "../ioc/Utils.mjs"; import "../ioc/FunctionTokenizer.mjs"; import "../ioc/LoadModules.mjs"; import "../ioc/Resolvers.mjs"; import "../ioc/ParamParser.mjs"; import "../base/internal/ObjectLifetime.mjs"; import "../../exceptions/di/LifetimeLockedException.mjs"; import "../base/internal/ObjectWeakRefs.mjs"; import "../base/internal/ConfigurableRecordsInjection.mjs"; import "../base/internal/ObjectConfiguration.mjs"; import "../base/internal/ObjectInjection.mjs"; import "../base/internal/ObjectContainer.mjs"; import "../helpers/DevNull.mjs"; import "../../decorators/dto/Expect.mjs"; import "../../decorators/dto/IndexSignature.mjs"; import "../base/internal/MethodValidation.mjs"; import "../../exceptions/dto/InvalidMethodAcceptException.mjs"; import "../../exceptions/dto/InvalidMethodReturnException.mjs"; import "../helpers/IsEmptyObject.mjs"; import "../../options/ModuleOptions.mjs"; import "../../options/ModuleLoadObjectsOptions.mjs"; import "../../options/LoadNamedObjectOptions.mjs"; import "../../options/LoadAnonymousObjectOptions.mjs"; import "../../options/OverridableNamedObjectOptions.mjs"; import "../../options/OverridableObjectOptions.mjs"; import "../base/internal/ModuleConfigLoader.mjs"; import "../../exceptions/di/OverridableObjectTargetConfigNotFoundException.mjs"; import "../../exceptions/InvalidObjectTypeException.mjs"; import "../helpers/ArrayToSet.mjs"; import "../helpers/SetToArray.mjs"; import "../../decorators/di/Configurable.mjs"; import "../helpers/NonceStr.mjs"; import "../helpers/RandomString.mjs"; import "../../../vendor/Package.15.mjs"; import "crypto"; import "../../exceptions/alias/InvalidAliasNameException.mjs"; import "../../exceptions/alias/AliasExistsException.mjs"; import "../../exceptions/alias/AliasNotFoundException.mjs"; import "../base/internal/ControllerEntrypoint.mjs"; import "../helpers/ObjectHash.mjs"; import "../helpers/GetObjectNestingDepth.mjs"; import "../../exceptions/InvalidActionPatternDepthException.mjs"; import "../base/internal/PatternManager.mjs"; import "../../components/entrypoint/lib/Controller.mjs"; import "../context/CLIContext.mjs"; import "../base/Context.mjs"; import "../context/HTTPContext.mjs"; import "node:http"; import "../context/ServiceContext.mjs"; import "../../components/entrypoint/exceptions/ControllerActionNotFoundException.mjs"; import "../../exceptions/DestroyRuntimeContainerException.mjs"; import "../helpers/GetObjectPropertyPaths.mjs"; import "../helpers/UniqueArray.mjs"; import "worker_threads"; import "../../../vendor/Package.132.mjs"; import "../../../vendor/Package.14.mjs"; import "buffer"; import "module"; import "tty"; import "../../../vendor/Package.18.mjs"; import "assert"; import "string_decoder"; import "node:stream"; var f; var v; (function(t) { t["Launched"] = "LAUNCHED"; t["Done"] = "DONE"; t["UncaughtException"] = "UNCAUGHT_EXCEPTION"; t["FatalException"] = "FATAL_EXCEPTION"; })(v || (v = {})); let y = class Application extends o { constructor() { super(...arguments); this.ConfigLoader = a; this.options = { components: { log: { class: j }, entrypoint: { class: l } }, bootstrap: [ "log" ] }; } static { f = this; } static { this.eventEmitter = new E; } static { this.environmentVariableMap = new Map; } static { this.aliasDeclarations = []; } static async getLogger() { return this.appInstance ? await this.appInstance.getObject("log") : await (new n).set(j); } static env(t) { Object.keys(t).forEach((e => this.environmentVariableMap.set(e, t[e]))); return this.launch(); } static alias(t, e = false) { this.aliasDeclarations.push({ alias: t ? t : {}, createIfNotExist: e }); return this.launch(); } static onLaunched(t) { this.eventEmitter.once(v.Launched, (async e => t(e, await e.getObject("log")))); return this.launch(); } static onDone(t) { this.eventEmitter.once(v.Done, (async e => t(e, await e.getObject("log")))); return this.launch(); } static onUncaughtException(t) { this.eventEmitter.on(v.UncaughtException, (async e => { const o = await this.getLogger(); await t(e, o); })); return this.launch(); } static onFatalException(t) { this.eventEmitter.once(v.FatalException, (async e => { const o = await this.getLogger(); let i = await t(e, o); if (typeof i !== "number") i = 1; return process.exit(i); })); return this.launch(); } static run(t) { Reflect.set(this, "launchOptions", t); return this.launch(); } static launch() { if (this.launchTimeout) clearTimeout(this.launchTimeout); this.launchTimeout = setTimeout((async () => { process.on("uncaughtException", (async t => { if (this.eventEmitter.listenerCount(v.UncaughtException)) return this.eventEmitter.emit(v.UncaughtException, t); const e = await this.getLogger(); return e.warn(new Error("UncaughtException", { cause: t })); })); try { Reflect.set(this, "appInstance", await this.launchApplication()); } catch (t) { this.processFatalException(t); } })); return this; } static processFatalException(t) { if (!this.eventEmitter.listenerCount(v.FatalException)) { return process.nextTick((async () => { const e = await this.getLogger(); e.error(new Error("FatalException", { cause: t })); })); } this.eventEmitter.emit(v.FatalException, t); } static async launchApplication() { this.eventEmitter.once("exit", (async (t, e) => { try { await this.eventEmitter.emitRequest(v.Done, t); await o.destroy(); process.exit(e ? e : 0); } catch (t) { process.exit(1); } })); this.environmentVariableMap.forEach(((t, e) => process.env[e] = t)); const t = p.getAliasInstance(); t.set("@runtime", process.cwd()); this.aliasDeclarations.forEach((e => { const o = e.alias; const i = e.createIfNotExist; Object.keys(o).forEach((e => { t.set(e, o[e]); if (i) { const t = g.resolve(e); if (!b(t)) d(g.resolve(e), { recursive: true }); } })); })); const e = typeof this.launchOptions === "object" ? this.launchOptions : await this.launchOptions(); const o = new n; return new Promise(((t, r) => { m.validateAsync(e).then((e => { e.bootstrap?.push((async t => { const e = function() { this.options.bootstrap?.pop(); x(Reflect.getOwnMetadata("#bootstrap", this))?.pop(); }; e.bind(x(t))(); this.eventEmitter.emit(v.Launched, x(t)); })); o.set(f, { options: e }).then((e => e.once(i, (() => t(e))).once(s, (t => this.processFatalException(t))))).catch(r); })).catch(r); })); } get alias() { return p.getAliasInstance(); } get appId() { return c().appId; } get appName() { return c().appName; } get timezone() { return c().timezone; } get uptime() { return Math.floor(process.uptime()); } exit(t) { if (typeof t === "boolean" && t) { return process.exit(2); } else { f.eventEmitter.emit("exit", this, t ? t : 0); } } }; t([ h(u.Object().pattern(u.String(), u.String()).required()), e("design:type", Function), e("design:paramtypes", [ Object ]), e("design:returntype", Object) ], y, "env", null); t([ h(u.Object().pattern(u.String(), u.String()).required(), u.Boolean().optional().default(false)), e("design:type", Function), e("design:paramtypes", [ Object, Boolean ]), e("design:returntype", Object) ], y, "alias", null); y = f = t([ r(true) ], y); export { y as Application, v as ApplicationState };