lakutata
Version:
An IoC-based universal application framework.
862 lines (678 loc) • 30 kB
JavaScript
/* 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("../../../vendor/Package.internal.3.cjs");
const t = require("./Provider.cjs");
const r = require("../../decorators/di/Configurable.cjs");
const n = require("../../../vendor/Package.internal.7.cjs");
const i = require("path");
const a = require("../../../vendor/Package.internal.512.cjs");
const o = require("../../../vendor/Package.internal.51.cjs");
const s = require("../../../vendor/Package.internal.310.cjs");
const c = require("fs/promises");
const u = require("../../../vendor/Package.internal.2.cjs");
const l = require("../../decorators/di/Lifetime.cjs");
const p = require("./Module.cjs");
const d = require("../../../vendor/Package.internal.4.cjs");
const h = require("../base/internal/ApplicationConfigLoader.cjs");
const g = require("../../options/ApplicationOptions.cjs");
const m = require("./Alias.cjs");
const f = require("../../../vendor/Package.internal.5.cjs");
const y = require("../../components/entrypoint/Entrypoint.cjs");
const q = require("../../../vendor/Package.internal.54.cjs");
const j = require("../../decorators/dto/Accept.cjs");
const b = require("fs");
const x = require("node:path");
const v = require("node:fs");
const E = require("../helpers/As.cjs");
const O = require("../base/EventEmitter.cjs");
const w = require("../base/internal/DatabaseSymbol.cjs");
require("../base/async-constructor/AsyncConstructor.cjs");
require("../base/async-constructor/Append.cjs");
require("../helpers/IsPromiseLike.cjs");
require("../helpers/IsPromise.cjs");
require("util/types");
require("../../exceptions/MethodNotFoundException.cjs");
require("../base/abstracts/Exception.cjs");
require("../helpers/Templating.cjs");
require("../base/internal/CamelCase.cjs");
require("../helpers/NoCase.cjs");
require("../helpers/DevNull.cjs");
require("../../../vendor/Package.internal.6.cjs");
require("../base/internal/ThrowWarning.cjs");
require("../ioc/DependencyInjectionContainer.cjs");
require("util");
require("../ioc/Errors.cjs");
require("../../exceptions/di/DependencyInjectionException.cjs");
require("../base/internal/ConstructorSymbol.cjs");
require("../../constants/DIMetadataKey.cjs");
require("../../../vendor/Package.internal.1.cjs");
require("node:crypto");
require("../base/internal/DataValidator.cjs");
require("node:util/types");
require("../validation/VLD.cjs");
require("url");
require("../../exceptions/dto/InvalidValueException.cjs");
require("../../../vendor/Package.internal.8.cjs");
require("../helpers/IsHtml.cjs");
require("../helpers/IsXML.cjs");
require("../../constants/DTOMetadataKey.cjs");
require("../helpers/ObjectConstructor.cjs");
require("../helpers/ObjectParentConstructors.cjs");
require("../helpers/ObjectParentConstructor.cjs");
require("../helpers/ObjectPrototype.cjs");
require("../ioc/InjectionMode.cjs");
require("../ioc/Lifetime.cjs");
require("../ioc/ListModules.cjs");
require("os");
require("stream");
require("events");
require("../ioc/Utils.cjs");
require("../ioc/FunctionTokenizer.cjs");
require("../ioc/LoadModules.cjs");
require("../ioc/Resolvers.cjs");
require("../ioc/ParamParser.cjs");
require("../base/internal/ObjectLifetime.cjs");
require("../../exceptions/di/LifetimeLockedException.cjs");
require("../base/internal/ObjectWeakRefs.cjs");
require("../base/internal/ConfigurableRecordsInjection.cjs");
require("../base/internal/ObjectConfiguration.cjs");
require("../base/internal/ObjectInjection.cjs");
require("../base/internal/ObjectContainer.cjs");
require("../../decorators/dto/Expect.cjs");
require("../../decorators/dto/IndexSignature.cjs");
require("../base/internal/MethodValidation.cjs");
require("../../exceptions/dto/InvalidMethodAcceptException.cjs");
require("../../exceptions/dto/InvalidMethodReturnException.cjs");
require("../helpers/IsEmptyObject.cjs");
require("../../../vendor/Package.internal.52.cjs");
require("buffer");
require("tty");
require("crypto");
require("module");
require("node:url");
require("node:fs/promises");
require("node:events");
require("node:stream");
require("node:string_decoder");
require("./Component.cjs");
require("../../options/ModuleOptions.cjs");
require("../../options/ModuleLoadObjectsOptions.cjs");
require("../../options/LoadNamedObjectOptions.cjs");
require("../../options/LoadAnonymousObjectOptions.cjs");
require("../../options/OverridableNamedObjectOptions.cjs");
require("../../options/OverridableObjectOptions.cjs");
require("../base/internal/ModuleConfigLoader.cjs");
require("../../exceptions/di/OverridableObjectTargetConfigNotFoundException.cjs");
require("../../exceptions/InvalidObjectTypeException.cjs");
require("../helpers/ArrayToSet.cjs");
require("../helpers/SetToArray.cjs");
require("../helpers/NonceStr.cjs");
require("../helpers/RandomString.cjs");
require("../../exceptions/alias/InvalidAliasNameException.cjs");
require("../../exceptions/alias/AliasExistsException.cjs");
require("../../exceptions/alias/AliasNotFoundException.cjs");
require("../base/internal/ControllerEntrypoint.cjs");
require("../helpers/ObjectHash.cjs");
require("../helpers/GetObjectNestingDepth.cjs");
require("../../exceptions/InvalidActionPatternDepthException.cjs");
require("../base/internal/StringifyPattern.cjs");
require("../../../vendor/Package.internal.522.cjs");
require("../../../vendor/Package.internal.55.cjs");
require("../base/internal/PatternManager.cjs");
require("../../components/entrypoint/lib/Controller.cjs");
require("../context/CLIContext.cjs");
require("../base/Context.cjs");
require("../context/HTTPContext.cjs");
require("node:http");
require("../context/ServiceContext.cjs");
require("../../components/entrypoint/exceptions/ControllerActionNotFoundException.cjs");
require("../../exceptions/DestroyRuntimeContainerException.cjs");
require("../helpers/GetObjectPropertyPaths.cjs");
require("../helpers/UniqueArray.cjs");
require("../../components/entrypoint/exceptions/DuplicateActionNameException.cjs");
require("../../components/entrypoint/lib/AccessControl.cjs");
require("../../components/entrypoint/exceptions/AccessDenyException.cjs");
require("../../components/entrypoint/lib/AccessControlRule.cjs");
require("../../components/entrypoint/exceptions/InvalidActionGroupException.cjs");
require("node:os");
require("node:diagnostics_channel");
require("assert");
require("worker_threads");
require("string_decoder");
require("node:worker_threads");
const _ = e => e && e.__esModule ? e : {
default: e
};
const A = _(i);
const S = _(c);
const C = _(x);
var D = {};
Object.defineProperty(D, "__esModule", {
value: true
});
var M = D.CommandUtils = void 0;
const T = s.require$$0;
const I = T.__importDefault(S.default);
const P = T.__importDefault(A.default);
const R = o.error;
const k = o.InstanceChecker;
const L = o.requireImportUtils();
class CommandUtils {
static async loadDataSource(e) {
let t;
try {
[t] = await (0, L.importOrRequireFile)(e);
} catch (t) {
throw new Error(`Unable to open file: "${e}". ${t.message}`);
}
if (!t || typeof t !== "object") {
throw new Error(`Given data source file must contain export of a DataSource instance`);
}
if (k.InstanceChecker.isDataSource(t)) {
return t;
}
const r = [];
for (const e in t) {
const n = t[e];
const i = await n;
if (k.InstanceChecker.isDataSource(i)) {
r.push(i);
}
}
if (r.length === 0) {
throw new Error(`Given data source file must contain export of a DataSource instance`);
}
if (r.length > 1) {
throw new Error(`Given data source file must contain only one export of DataSource instance`);
}
return r[0];
}
static async createDirectories(e) {
await I.default.mkdir(e, {
recursive: true
});
}
static async createFile(e, t, r = true) {
await CommandUtils.createDirectories(P.default.dirname(e));
if (r === false && await CommandUtils.fileExists(e)) {
return;
}
await I.default.writeFile(e, t);
}
static async readFile(e) {
const t = await I.default.readFile(e);
return t.toString();
}
static async fileExists(e) {
try {
await I.default.access(e, I.default.constants.F_OK);
return true;
} catch {
return false;
}
}
static getTimestamp(e) {
if (e && (isNaN(e) || e < 0)) {
throw new R.TypeORMError(`timestamp option should be a non-negative number. received: ${e}`);
}
return e ? new Date(Number(e)).getTime() : Date.now();
}
}
M = D.CommandUtils = CommandUtils;
var N = {
exports: {}
};
N.exports;
let B, $, G, {defineProperty: F, setPrototypeOf: U, create: Q, keys: H} = Object, J = "", {round: V, max: z} = Math, W = e => {
let t = /([a-f\d]{3,6})/i.exec(e)?.[1], r = t?.length, n = parseInt(6 ^ r ? 3 ^ r ? "0" : t[0] + t[0] + t[1] + t[1] + t[2] + t[2] : t, 16);
return [ n >> 16 & 255, n >> 8 & 255, 255 & n ];
}, X = (e, t, r) => e ^ t || t ^ r ? 16 + 36 * V(e / 51) + 6 * V(t / 51) + V(r / 51) : 8 > e ? 16 : e > 248 ? 231 : V(24 * (e - 8) / 247) + 232, K = e => {
let t, r, n, i, a;
return 8 > e ? 30 + e : 16 > e ? e - 8 + 90 : (232 > e ? (a = (e -= 16) % 36, t = (e / 36 | 0) / 5,
r = (a / 6 | 0) / 5, n = a % 6 / 5) : t = r = n = (10 * (e - 232) + 8) / 255, i = 2 * z(t, r, n),
i ? 30 + (V(n) << 2 | V(r) << 1 | V(t)) + (2 ^ i ? 0 : 60) : 30);
}, Y = (() => {
let e = e => n.some(t => e.test(t)), t = globalThis, r = t.process ?? {}, n = r.argv ?? [], i = r.env ?? {}, a = -1;
try {
B = "," + H(i).join(",");
} catch (e) {
i = {}, a = 0;
}
let o = "FORCE_COLOR", s = {
false: 0,
0: 0,
1: 1,
2: 2,
3: 3
}[i[o]] ?? -1, c = o in i && s || e(/^--color=?(true|always)?$/);
return c && (a = s), ~a || (a = ((e, t, r) => ($ = e.TERM, {
"24bit": 3,
truecolor: 3,
ansi256: 2,
ansi: 1
}[e.COLORTERM] || (e.CI ? /,GITHUB/.test(B) ? 3 : 1 : t && "dumb" !== $ ? r ? 3 : /-256/.test($) ? 2 : 1 : 0)))(i, !!i.PM2_HOME || i.NEXT_RUNTIME?.includes("edge") || !!r.stdout?.isTTY, "win32" === r.platform)),
!s || i.NO_COLOR || e(/^--(no-color|color=(false|never))$/) ? 0 : t.window?.chrome || c && !a ? 3 : a;
})(), Z = {
open: J,
close: J
}, ee = 39, te = 49, re = {}, ne = ({p: e}, {open: t, close: r}) => {
let n = (e, ...i) => {
if (!e) {
if (t && t === r) return t;
if ((e ?? J) === J) return J;
}
let a, o = e.raw ? String.raw({
raw: e
}, ...i) : J + e, s = n.p, c = s.o, u = s.c;
if (o.includes("")) for (;s; s = s.p) {
let {open: e, close: t} = s, r = t.length, n = J, i = 0;
if (r) for (;~(a = o.indexOf(t, i)); i = a + r) n += o.slice(i, a) + e;
o = n + o.slice(i);
}
return c + (o.includes("\n") ? o.replace(/(\r?\n)/g, u + "$1" + c) : o) + u;
}, i = t, a = r;
return e && (i = e.o + t, a = r + e.c), U(n, G), n.p = {
open: t,
close: r,
o: i,
c: a,
p: e
}, n.open = i, n.close = a, n;
};
const ie = new function e(t = Y) {
let r = {
Ansis: e,
level: t,
isSupported: () => i,
strip: e => e.replace(/[][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, J),
extend(e) {
for (let t in e) {
let r = e[t], i = (typeof r)[0];
"s" === i ? (n(t, l(...W(r))), n(f(t), p(...W(r)))) : n(t, r, "f" === i);
}
return G = Q({}, re), U(r, G), r;
}
}, n = (e, t, r) => {
re[e] = {
get() {
let n = r ? (...e) => ne(this, t(...e)) : ne(this, t);
return F(this, e, {
value: n
}), n;
}
};
}, i = t > 0, a = (e, t) => i ? {
open: `[${e}m`,
close: `[${t}m`
} : Z, o = e => t => e(...W(t)), s = (e, t) => (r, n, i) => a(`${e}8;2;${r};${n};${i}`, t), c = (e, t) => (r, n, i) => a(((e, t, r) => K(X(e, t, r)))(r, n, i) + e, t), u = e => (t, r, n) => e(X(t, r, n)), l = s(3, ee), p = s(4, te), d = e => a("38;5;" + e, ee), h = e => a("48;5;" + e, te);
2 === t ? (l = u(d), p = u(h)) : 1 === t && (l = c(0, ee), p = c(10, te), d = e => a(K(e), ee),
h = e => a(K(e) + 10, te));
let g, m = {
fg: d,
bg: h,
rgb: l,
bgRgb: p,
hex: o(l),
bgHex: o(p),
visible: Z,
reset: a(0, 0),
bold: a(1, 22),
dim: a(2, 22),
italic: a(3, 23),
underline: a(4, 24),
inverse: a(7, 27),
hidden: a(8, 28),
strikethrough: a(9, 29)
}, f = e => "bg" + e[0].toUpperCase() + e.slice(1), y = "Bright";
return "black,red,green,yellow,blue,magenta,cyan,white,gray".split(",").map((e, t) => {
g = f(e), 8 > t ? (m[e + y] = a(90 + t, ee), m[g + y] = a(100 + t, te)) : t = 60,
m[e] = a(30 + t, ee), m[g] = a(40 + t, te);
}), r.extend(m);
};
N.exports = ie, ie.default = ie;
var ae = N.exports;
const oe = u.getDefaultExportFromCjs(ae);
const {Ansis: se, fg: ce, bg: ue, rgb: le, bgRgb: pe, hex: de, bgHex: he, reset: ge, inverse: me, hidden: fe, visible: ye, bold: qe, dim: je, italic: be, underline: xe, strikethrough: ve, black: Ee, red: Oe, green: we, yellow: _e, blue: Ae, magenta: Se, cyan: Ce, white: De, gray: Me, redBright: Te, greenBright: Ie, yellowBright: Pe, blueBright: Re, magentaBright: ke, cyanBright: Le, whiteBright: Ne, bgBlack: Be, bgRed: $e, bgGreen: Ge, bgYellow: Fe, bgBlue: Ue, bgMagenta: Qe, bgCyan: He, bgWhite: Je, bgGray: Ve, bgRedBright: ze, bgGreenBright: We, bgYellowBright: Xe, bgBlueBright: Ke, bgMagentaBright: Ye, bgCyanBright: Ze, bgWhiteBright: et} = oe;
exports.ApplicationState = void 0;
(function(e) {
e["Launched"] = "LAUNCHED";
e["Done"] = "DONE";
e["UncaughtException"] = "UNCAUGHT_EXCEPTION";
e["FatalException"] = "FATAL_EXCEPTION";
})(exports.ApplicationState || (exports.ApplicationState = {}));
class Application extends p.Module {
constructor() {
super(...arguments);
this.ConfigLoader = h.ApplicationConfigLoader;
this.options = {
components: {
log: {
class: q.Logger
},
entrypoint: {
class: y.Entrypoint
}
},
bootstrap: [ "log" ]
};
}
static {
this.eventEmitter = new O.EventEmitter;
}
static {
this.environmentVariableMap = new Map;
}
static {
this.aliasDeclarations = [];
}
static async getLogger() {
return this.appInstance ? await this.appInstance.getObject("log") : await (new d.Container).set(q.Logger);
}
static env(e) {
Object.keys(e).forEach(t => this.environmentVariableMap.set(t, e[t]));
return this.launch();
}
static alias(e, t = false) {
this.aliasDeclarations.push({
alias: e ? e : {},
createIfNotExist: t
});
return this.launch();
}
static onLaunched(e) {
this.eventEmitter.once(exports.ApplicationState.Launched, async t => e(t, await t.getObject("log")));
return this.launch();
}
static onDone(e) {
this.eventEmitter.once(exports.ApplicationState.Done, async t => e(t, await t.getObject("log")));
return this.launch();
}
static onUncaughtException(e) {
this.eventEmitter.on(exports.ApplicationState.UncaughtException, async t => {
const r = await this.getLogger();
await e(t, r);
});
return this.launch();
}
static onFatalException(e) {
this.eventEmitter.once(exports.ApplicationState.FatalException, async t => {
const r = await this.getLogger();
let n = await e(t, r);
if (typeof n !== "number") n = 1;
return process.exit(n);
});
return this.launch();
}
static run(e) {
Reflect.set(this, "launchOptions", e);
return this.launch();
}
static launch() {
if (this.launchTimeout) clearTimeout(this.launchTimeout);
this.launchTimeout = setTimeout(async () => {
process.on("uncaughtException", async e => {
if (this.eventEmitter.listenerCount(exports.ApplicationState.UncaughtException)) return this.eventEmitter.emit(exports.ApplicationState.UncaughtException, e);
const t = await this.getLogger();
return t.warn(new Error("UncaughtException", {
cause: e
}));
});
try {
Reflect.set(this, "appInstance", await this.launchApplication());
} catch (e) {
this.processFatalException(e);
}
});
return this;
}
static processFatalException(e) {
if (!this.eventEmitter.listenerCount(exports.ApplicationState.FatalException)) {
return process.nextTick(async () => {
const t = await this.getLogger();
t.error(new Error("FatalException", {
cause: e
}));
});
}
this.eventEmitter.emit(exports.ApplicationState.FatalException, e);
}
static async launchApplication() {
this.eventEmitter.once("exit", async (e, t) => {
try {
await this.eventEmitter.emitRequest(exports.ApplicationState.Done, e);
await r.destroy();
process.exit(t ? t : 0);
} catch (e) {
process.exit(1);
}
});
this.environmentVariableMap.forEach((e, t) => process.env[t] = e);
const e = m.Alias.getAliasInstance();
e.set("@runtime", process.cwd());
this.aliasDeclarations.forEach(t => {
const r = t.alias;
const n = t.createIfNotExist;
Object.keys(r).forEach(t => {
e.set(t, r[t]);
if (n) {
const e = C.default.resolve(t);
if (!v.existsSync(e)) b.mkdirSync(C.default.resolve(t), {
recursive: true
});
}
});
});
const t = typeof this.launchOptions === "object" ? this.launchOptions : await this.launchOptions();
for (const e in process.env) {
switch (e.toUpperCase()) {
case "MIGRATION_GENERATE":
{
this.eventEmitter.removeAllListeners(exports.ApplicationState.Launched);
this.eventEmitter.removeAllListeners(exports.ApplicationState.Done);
this.eventEmitter.removeAllListeners(exports.ApplicationState.UncaughtException);
this.eventEmitter.removeAllListeners(exports.ApplicationState.FatalException);
const r = process.env[e];
const n = e => {
const t = [];
for (const r in e) {
if (e[r] && e[r].class && e[r].class.databaseSymbol && e[r].class.databaseSymbol === w.DatabaseSymbol) {
const n = e[r].options;
if (!n) continue;
Reflect.set(n, "dataSourceName", r);
t.push(n);
}
}
return t;
};
const i = [ ...t.components ? n(t.components) : [], ...t.providers ? n(t.providers) : [] ];
if (!i.length) process.exit(0);
t.bootstrap = [];
i.forEach((e, n) => {
const a = `GenerateMigration${n}${Date.now()}`;
if (!t.providers) t.providers = {};
t.providers[a] = {
class: exports.GenerateMigration,
path: r,
outputJs: false,
exitProcess: n === i.length - 1,
dataSourceName: Reflect.get(e, "dataSourceName"),
dataSource: e
};
t.bootstrap.push(a);
});
}
break;
}
}
const r = new d.Container;
return new Promise((e, n) => {
g.ApplicationOptions.validateAsync(t).then(t => {
t.bootstrap?.push(async e => {
const t = function() {
this.options.bootstrap?.pop();
E.As(Reflect.getOwnMetadata("#bootstrap", this))?.pop();
};
t.bind(E.As(e))();
this.eventEmitter.emit(exports.ApplicationState.Launched, E.As(e));
});
r.set(Application, {
options: t
}).then(t => t.once(p.MODULE_INITIALIZED, () => e(t)).once(p.MODULE_INITIALIZE_ERROR, e => this.processFatalException(e))).catch(n);
}).catch(n);
});
}
get alias() {
return m.Alias.getAliasInstance();
}
get appId() {
return f.GetBasicInfo().appId;
}
get appName() {
return f.GetBasicInfo().appName;
}
get timezone() {
return f.GetBasicInfo().timezone;
}
get uptime() {
return Math.floor(process.uptime());
}
exit(e) {
if (typeof e === "boolean" && e) {
return process.exit(2);
} else {
Application.eventEmitter.emit("exit", this, e ? e : 0);
}
}
}
e.__decorate([ j.Accept(n.DTO.Object().pattern(n.DTO.String(), n.DTO.String()).required()), e.__metadata("design:type", Function), e.__metadata("design:paramtypes", [ Object ]), e.__metadata("design:returntype", Object) ], Application, "env", null);
e.__decorate([ j.Accept(n.DTO.Object().pattern(n.DTO.String(), n.DTO.String()).required(), n.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Function), e.__metadata("design:paramtypes", [ Object, Boolean ]), e.__metadata("design:returntype", Object) ], Application, "alias", null);
var tt;
exports.GenerateMigration = tt = class GenerateMigration extends t.Provider {
get extension() {
return this.outputJs ? ".js" : ".ts";
}
get filename() {
return this.timestamp + "-" + (this.dataSourceName ? this.dataSourceName : A.default.basename(this.path)) + this.extension;
}
#e;
#t;
async init() {
this.#e = await this.getObject(Application);
this.#t = new a.DataSourceExports.DataSource(this.dataSource);
this.#t.setOptions({
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: false
});
this.#t = await this.#t.initialize();
await this.handle();
}
async destroy() {
await (this.#t?.destroy());
}
async handle() {
try {
const e = [], t = [];
try {
const r = await this.#t.driver.createSchemaBuilder().log();
if (this.pretty) {
r.upQueries.forEach(e => {
e.query = tt.prettifyQuery(e.query);
});
r.downQueries.forEach(e => {
e.query = tt.prettifyQuery(e.query);
});
}
r.upQueries.forEach(t => {
e.push(" await queryRunner.query(`" + t.query.replaceAll("`", "\\`") + "`" + tt.queryParams(t.parameters) + ");");
});
r.downQueries.forEach(e => {
t.push(" await queryRunner.query(`" + e.query.replaceAll("`", "\\`") + "`" + tt.queryParams(e.parameters) + ");");
});
} finally {
await this.#t.destroy();
}
if (!e.length) {
if (this.check) {
console.log(oe.green`No changes in database schema were found`);
if (this.exitProcess) {
return this.#e.exit(0);
} else {
return;
}
} else {
console.log(oe.yellow`No changes in database schema were found`);
if (this.exitProcess) {
return this.#e.exit(1);
} else {
return;
}
}
} else if (!this.path) {
console.log(oe.yellow`Please specify a migration path`);
return this.#e.exit(1);
}
const r = this.outputJs ? tt.getJavascriptTemplate(A.default.basename(this.path), this.timestamp, e, t.reverse(), this.esm) : tt.getTemplate(A.default.basename(this.path), this.timestamp, e, t.reverse());
if (this.check) {
console.log(oe.yellow`Unexpected changes in database schema were found in check mode:\n\n${oe.white(r)}`);
if (this.exitProcess) {
return this.#e.exit(0);
} else {
return;
}
}
if (this.dryRun) {
console.log(oe.green(`Migration ${oe.blue(this.path + this.extension)} has content:\n\n${oe.white(r)}`));
} else {
const e = A.default.isAbsolute(this.path) ? A.default.join(this.path, this.filename) : A.default.join(process.cwd(), this.path, this.filename);
await M.createFile(e, r);
console.log(oe.green`Migration ${oe.blue(e)} has been generated successfully.`);
if (this.exitProcess) {
return this.#e.exit(0);
} else {
return;
}
}
} catch (e) {
o.PlatformTools.PlatformTools.logCmdErr("Error during migration generation:", e);
return this.#e.exit(1);
}
}
static queryParams(e) {
if (!e || !e.length) {
return "";
}
return `, ${JSON.stringify(e)}`;
}
static getTemplate(e, t, r, n) {
const i = `${o.camelCase_1(e, true)}${t}`;
return `import { MigrationInterface, QueryRunner } from "lakutata/orm";\n\nexport class ${i} implements MigrationInterface {\n name = '${i}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${r.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${n.join(`\n`)}\n }\n\n}\n`;
}
static getJavascriptTemplate(e, t, r, n, i) {
const a = `${o.camelCase_1(e, true)}${t}`;
const s = i ? "export" : "module.exports =";
return `/**\n * @typedef {import('lakutata/orm').MigrationInterface} MigrationInterface\n * @typedef {import('lakutata/orm').QueryRunner} QueryRunner\n */\n\n/**\n * @class\n * @implements {MigrationInterface}\n */\n${s} class ${a} {\n name = '${a}'\n\n /**\n * @param {QueryRunner} queryRunner\n */\n async up(queryRunner) {\n${r.join(`\n`)}\n }\n\n /**\n * @param {QueryRunner} queryRunner\n */\n async down(queryRunner) {\n${n.join(`\n`)}\n }\n}\n`;
}
static prettifyQuery(e) {
const t = o.sqlFormatter.format(e, {
indent: " "
});
return "\n" + t.replace(/^/gm, " ") + "\n ";
}
};
e.__decorate([ r.Configurable(n.DTO.String().required()), e.__metadata("design:type", String) ], exports.GenerateMigration.prototype, "path", void 0);
e.__decorate([ r.Configurable(n.DTO.String().allow("").optional().default("")), e.__metadata("design:type", String) ], exports.GenerateMigration.prototype, "dataSourceName", void 0);
e.__decorate([ r.Configurable(), e.__metadata("design:type", Object) ], exports.GenerateMigration.prototype, "dataSource", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(true)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "pretty", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "outputJs", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "esm", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "dryRun", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "check", void 0);
e.__decorate([ r.Configurable(n.DTO.Number().optional().default(() => Date.now())), e.__metadata("design:type", Number) ], exports.GenerateMigration.prototype, "timestamp", void 0);
e.__decorate([ r.Configurable(n.DTO.Boolean().optional().default(true)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "exitProcess", void 0);
exports.GenerateMigration = tt = e.__decorate([ l.Transient() ], exports.GenerateMigration);
exports.Application = Application;