hysteria-orm 10.3.9 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';var commander=require('commander'),de=require('fs'),Be=require('path'),Ia=require('fs/promises'),sqlHighlight=require('sql-highlight'),module$1=require('module'),url=require('url'),Ne=require('crypto'),sqlFormatter=require('sql-formatter'),ve=require('dayjs'),Np=require('dayjs/plugin/customParseFormat.js'),wp=require('dayjs/plugin/timezone.js'),qp=require('dayjs/plugin/utc.js'),Ip=require('pluralize'),stream=require('stream'),child_process=require('child_process');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var de__default=/*#__PURE__*/_interopDefault(de);var Be__default=/*#__PURE__*/_interopDefault(Be);var Ia__default=/*#__PURE__*/_interopDefault(Ia);var Ne__default=/*#__PURE__*/_interopDefault(Ne);var ve__default=/*#__PURE__*/_interopDefault(ve);var Np__default=/*#__PURE__*/_interopDefault(Np);var wp__default=/*#__PURE__*/_interopDefault(wp);var qp__default=/*#__PURE__*/_interopDefault(qp);var Ip__default=/*#__PURE__*/_interopDefault(Ip);var Aa=i=>{throw TypeError(i)};var xa=(i,t,e)=>t.has(i)||Aa("Cannot "+e);var $e=(i,t,e)=>(xa(i,t,"read from private field"),e?e.call(i):t.get(i)),Pa=(i,t,e)=>t.has(i)?Aa("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),$r=(i,t,e,r)=>(xa(i,t,"write to private field"),t.set(i,e),e);var T=class extends Error{constructor(t,e,r){super(t+" - "+e),this.code=e,this.caller=t,this.error=r;}};var z=class{constructor(t){this.options=t;}static async createDriver(t){throw new T("Driver::createDriver This error should never happen. Please report it to the developers.","DEVELOPMENT_ERROR")}};var Q=class extends Error{constructor(t){super(""),this.message=`Driver '${t}' not found, it's likely not installed, try running 'npm install ${t}'`;}};var ze=class ze extends z{constructor(e,r){super(r);this.type="mongo";this.client=e;}static async createDriver(){if(this.mongoClient)return new ze(this.mongoClient);let e=await import('mongodb').catch(()=>{throw new Q("mongodb")});if(this.mongoClient=e.default??e,!this.mongoClient)throw new Q("mongodb");return new ze(this.mongoClient)}};ze.mongoClient=null;var Nt=ze;var Ze=class Ze extends z{constructor(e,r){super(r);this.type="mssql";this.client=e;}static async createDriver(){if(this.mssqlClient)return new Ze(this.mssqlClient);let e=await import('mssql').catch(()=>{throw new Q("mssql")});if(this.mssqlClient=e.default??e,!this.mssqlClient)throw new Q("mssql");return new Ze(this.mssqlClient)}};Ze.mssqlClient=null;var wt=Ze;var Xe=class Xe extends z{constructor(e,r){super(r);this.type="mysql";this.client=e;}static async createDriver(){if(this.mysqlClient)return new Xe(this.mysqlClient);let e=await import('mysql2/promise').catch(()=>{throw new Q("mysql2")});if(this.mysqlClient=e.default??e,!this.mysqlClient)throw new Q("mysql2");return new Xe(this.mysqlClient)}};Xe.mysqlClient=null;var qt=Xe;var et=class et extends z{constructor(e,r){super(r);this.type="oracledb";this.client=e;}static async createDriver(){if(this.oracledbClient)return new et(this.oracledbClient);let e=await import('oracledb').catch(()=>{throw new Q("oracledb")});if(this.oracledbClient=e.default??e,!this.oracledbClient)throw new Q("oracledb");return new et(this.oracledbClient)}};et.oracledbClient=null;var St=et;var tt=class tt extends z{constructor(e,r){super(r);this.type="postgres";this.client=e;}static async createDriver(){if(this.pgClient)return new tt(this.pgClient);let e=await import('pg').catch(()=>{throw new Q("pg")});if(this.pgClient=e.default??e,!this.pgClient)throw new Q("pg");return new tt(this.pgClient)}};tt.pgClient=null;var Mt=tt;var rt=class rt extends z{constructor(e,r){super(r);this.type="sqlite";this.client=e;}static async createDriver(){if(this.sqlite3Client)return new rt(this.sqlite3Client);let e=await import('sqlite3').catch(()=>{throw new Q("sqlite3")});if(this.sqlite3Client=e.default??e,!this.sqlite3Client)throw new Q("sqlite3");return new rt(this.sqlite3Client)}};rt.sqlite3Client=null;var _t=rt;var me=class{static async getDriver(t){let e=this.getExistingDriver(t);if(e)return e;switch(t){case "mysql":case "mariadb":return this.mysqlDriver=await qt.createDriver(),this.mysqlDriver;case "postgres":case "cockroachdb":return this.pgDriver=await Mt.createDriver(),this.pgDriver;case "sqlite":return this.sqliteDriver=await _t.createDriver(),this.sqliteDriver;case "mongo":return this.mongodbDriver=await Nt.createDriver(),this.mongodbDriver;case "mssql":return this.mssqlDriver=await wt.createDriver(),this.mssqlDriver;case "oracledb":return this.oracledbDriver=await St.createDriver(),this.oracledbDriver;default:throw new T(`DriverFactory::getDriver Driver ${t} not supported`,"DRIVER_NOT_FOUND")}}static getExistingDriver(t){switch(t){case "mysql":case "mariadb":return this.mysqlDriver;case "postgres":case "cockroachdb":return this.pgDriver;case "sqlite":return this.sqliteDriver;case "mongo":return this.mongodbDriver;case "mssql":return this.mssqlDriver;case "oracledb":return this.oracledbDriver;default:return null}}};me.mysqlDriver=null,me.pgDriver=null,me.sqliteDriver=null,me.mssqlDriver=null,me.oracledbDriver=null,me.mongodbDriver=null;var P={DB_TYPE:process.env.DB_TYPE,DB_HOST:process.env.DB_HOST,DB_PORT:process.env.DB_PORT,DB_USER:process.env.DB_USER,DB_PASSWORD:process.env.DB_PASSWORD,DB_DATABASE:process.env.DB_DATABASE,DB_LOGS:process.env.DB_LOGS==="true",MIGRATION_PATH:process.env.MIGRATION_PATH||"database/migrations",REDIS_HOST:process.env.REDIS_HOST,REDIS_PORT:process.env.REDIS_PORT,REDIS_USERNAME:process.env.REDIS_USERNAME,REDIS_PASSWORD:process.env.REDIS_PASSWORD,REDIS_DATABASE:process.env.REDIS_DATABASE,MONGO_URL:process.env.MONGO_URL,MONGO_LOGS:process.env.MONGO_LOGS==="true",MSSQL_TRUST_SERVER_CERTIFICATE:process.env.MSSQL_TRUST_SERVER_CERTIFICATE==="true"||false},Gc=()=>{try{de__default.default.readFileSync(".env","utf8").split(`
2
+ 'use strict';var commander=require('commander'),de=require('fs'),Be=require('path'),Ia=require('fs/promises'),sqlHighlight=require('sql-highlight'),module$1=require('module'),url=require('url'),Ne=require('crypto'),sqlFormatter=require('sql-formatter'),ve=require('dayjs'),Np=require('dayjs/plugin/customParseFormat.js'),wp=require('dayjs/plugin/timezone.js'),qp=require('dayjs/plugin/utc.js'),Ip=require('pluralize'),stream=require('stream'),child_process=require('child_process'),uf=require('readline');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var de__default=/*#__PURE__*/_interopDefault(de);var Be__default=/*#__PURE__*/_interopDefault(Be);var Ia__default=/*#__PURE__*/_interopDefault(Ia);var Ne__default=/*#__PURE__*/_interopDefault(Ne);var ve__default=/*#__PURE__*/_interopDefault(ve);var Np__default=/*#__PURE__*/_interopDefault(Np);var wp__default=/*#__PURE__*/_interopDefault(wp);var qp__default=/*#__PURE__*/_interopDefault(qp);var Ip__default=/*#__PURE__*/_interopDefault(Ip);var uf__default=/*#__PURE__*/_interopDefault(uf);var Aa=i=>{throw TypeError(i)};var xa=(i,t,e)=>t.has(i)||Aa("Cannot "+e);var $e=(i,t,e)=>(xa(i,t,"read from private field"),e?e.call(i):t.get(i)),Pa=(i,t,e)=>t.has(i)?Aa("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),$r=(i,t,e,r)=>(xa(i,t,"write to private field"),t.set(i,e),e);var T=class extends Error{constructor(t,e,r){super(t+" - "+e),this.code=e,this.caller=t,this.error=r;}};var z=class{constructor(t){this.options=t;}static async createDriver(t){throw new T("Driver::createDriver This error should never happen. Please report it to the developers.","DEVELOPMENT_ERROR")}};var Q=class extends Error{constructor(t){super(""),this.message=`Driver '${t}' not found, it's likely not installed, try running 'npm install ${t}'`;}};var ze=class ze extends z{constructor(e,r){super(r);this.type="mongo";this.client=e;}static async createDriver(){if(this.mongoClient)return new ze(this.mongoClient);let e=await import('mongodb').catch(()=>{throw new Q("mongodb")});if(this.mongoClient=e.default??e,!this.mongoClient)throw new Q("mongodb");return new ze(this.mongoClient)}};ze.mongoClient=null;var Nt=ze;var Ze=class Ze extends z{constructor(e,r){super(r);this.type="mssql";this.client=e;}static async createDriver(){if(this.mssqlClient)return new Ze(this.mssqlClient);let e=await import('mssql').catch(()=>{throw new Q("mssql")});if(this.mssqlClient=e.default??e,!this.mssqlClient)throw new Q("mssql");return new Ze(this.mssqlClient)}};Ze.mssqlClient=null;var wt=Ze;var Xe=class Xe extends z{constructor(e,r){super(r);this.type="mysql";this.client=e;}static async createDriver(){if(this.mysqlClient)return new Xe(this.mysqlClient);let e=await import('mysql2/promise').catch(()=>{throw new Q("mysql2")});if(this.mysqlClient=e.default??e,!this.mysqlClient)throw new Q("mysql2");return new Xe(this.mysqlClient)}};Xe.mysqlClient=null;var qt=Xe;var et=class et extends z{constructor(e,r){super(r);this.type="oracledb";this.client=e;}static async createDriver(){if(this.oracledbClient)return new et(this.oracledbClient);let e=await import('oracledb').catch(()=>{throw new Q("oracledb")});if(this.oracledbClient=e.default??e,!this.oracledbClient)throw new Q("oracledb");return new et(this.oracledbClient)}};et.oracledbClient=null;var St=et;var tt=class tt extends z{constructor(e,r){super(r);this.type="postgres";this.client=e;}static async createDriver(){if(this.pgClient)return new tt(this.pgClient);let e=await import('pg').catch(()=>{throw new Q("pg")});if(this.pgClient=e.default??e,!this.pgClient)throw new Q("pg");return new tt(this.pgClient)}};tt.pgClient=null;var Mt=tt;var rt=class rt extends z{constructor(e,r){super(r);this.type="sqlite";this.client=e;}static async createDriver(){if(this.sqlite3Client)return new rt(this.sqlite3Client);let e=await import('sqlite3').catch(()=>{throw new Q("sqlite3")});if(this.sqlite3Client=e.default??e,!this.sqlite3Client)throw new Q("sqlite3");return new rt(this.sqlite3Client)}};rt.sqlite3Client=null;var _t=rt;var me=class{static async getDriver(t){let e=this.getExistingDriver(t);if(e)return e;switch(t){case "mysql":case "mariadb":return this.mysqlDriver=await qt.createDriver(),this.mysqlDriver;case "postgres":case "cockroachdb":return this.pgDriver=await Mt.createDriver(),this.pgDriver;case "sqlite":return this.sqliteDriver=await _t.createDriver(),this.sqliteDriver;case "mongo":return this.mongodbDriver=await Nt.createDriver(),this.mongodbDriver;case "mssql":return this.mssqlDriver=await wt.createDriver(),this.mssqlDriver;case "oracledb":return this.oracledbDriver=await St.createDriver(),this.oracledbDriver;default:throw new T(`DriverFactory::getDriver Driver ${t} not supported`,"DRIVER_NOT_FOUND")}}static getExistingDriver(t){switch(t){case "mysql":case "mariadb":return this.mysqlDriver;case "postgres":case "cockroachdb":return this.pgDriver;case "sqlite":return this.sqliteDriver;case "mongo":return this.mongodbDriver;case "mssql":return this.mssqlDriver;case "oracledb":return this.oracledbDriver;default:return null}}};me.mysqlDriver=null,me.pgDriver=null,me.sqliteDriver=null,me.mssqlDriver=null,me.oracledbDriver=null,me.mongodbDriver=null;var P={DB_TYPE:process.env.DB_TYPE,DB_HOST:process.env.DB_HOST,DB_PORT:process.env.DB_PORT,DB_USER:process.env.DB_USER,DB_PASSWORD:process.env.DB_PASSWORD,DB_DATABASE:process.env.DB_DATABASE,DB_LOGS:process.env.DB_LOGS==="true",MIGRATION_PATH:process.env.MIGRATION_PATH||"database/migrations",REDIS_HOST:process.env.REDIS_HOST,REDIS_PORT:process.env.REDIS_PORT,REDIS_USERNAME:process.env.REDIS_USERNAME,REDIS_PASSWORD:process.env.REDIS_PASSWORD,REDIS_DATABASE:process.env.REDIS_DATABASE,MONGO_URL:process.env.MONGO_URL,MONGO_LOGS:process.env.MONGO_LOGS==="true",MSSQL_TRUST_SERVER_CERTIFICATE:process.env.MSSQL_TRUST_SERVER_CERTIFICATE==="true"||false},Gc=()=>{try{de__default.default.readFileSync(".env","utf8").split(`
3
3
  `).forEach(e=>{let[r,o]=e.split("="),n=r.trim(),s=o.trim();switch(n){case "DB_TYPE":P.DB_TYPE||(P.DB_TYPE=s);break;case "DB_HOST":P.DB_HOST||(P.DB_HOST=s);break;case "DB_PORT":P.DB_PORT||(P.DB_PORT=s);break;case "DB_USER":P.DB_USER||(P.DB_USER=s);break;case "DB_PASSWORD":P.DB_PASSWORD||(P.DB_PASSWORD=s);break;case "DB_DATABASE":P.DB_DATABASE||(P.DB_DATABASE=s);break;case "MIGRATION_PATH":P.MIGRATION_PATH||(P.MIGRATION_PATH=s||"database/migrations");break;case "REDIS_HOST":P.REDIS_HOST||(P.REDIS_HOST=s);break;case "REDIS_PORT":P.REDIS_PORT||(P.REDIS_PORT=s);break;case "REDIS_USERNAME":P.REDIS_USERNAME||(P.REDIS_USERNAME=s);break;case "REDIS_PASSWORD":P.REDIS_PASSWORD||(P.REDIS_PASSWORD=s);break;case "REDIS_DATABASE":P.REDIS_DATABASE||(P.REDIS_DATABASE=s);break;case "MONGO_URL":P.MONGO_URL||(P.MONGO_URL=s);break;case "MSSQL_TRUST_SERVER_CERTIFICATE":P.MSSQL_TRUST_SERVER_CERTIFICATE||(P.MSSQL_TRUST_SERVER_CERTIFICATE=s==="true");break}});}catch{}finally{return P}},R=Gc();var zc=async i=>(await me.getDriver(i)).client,Oe=async(i,t)=>{let e=await zc(i);switch(i){case "mariadb":case "mysql":let r=t;return e.createPool({host:r.host,port:r.port,user:r.username,password:r.password,database:r.database,...r?.driverOptions});case "postgres":case "cockroachdb":let s=t,a=e;return new a.Pool({host:s.host,port:s.port,user:s.username,password:s.password,database:s.database,...s?.driverOptions});case "sqlite":let d=e,m=t,u=m?.database;return new d.Database(u,m?.driverOptions?.mode??void 0,A=>{if(A)throw new T("SqliteDataSource::createSqlPool","CONNECTION_NOT_ESTABLISHED")});case "mssql":let p=e,y=t,{options:h,...N}=y.driverOptions??{};return await p.connect({server:y.host??"localhost",port:y.port,database:y.database,user:y.username,password:y.password,...N,options:{trustServerCertificate:R.MSSQL_TRUST_SERVER_CERTIFICATE??void 0,...h,abortTransactionOnError:false,enableImplicitTransactions:false}});case "oracledb":let $=e,V=t,C=`${V.host}/${V.database}`;return await $.createPool({user:V.username,password:V.password,connectString:C,...V.driverOptions});default:throw new T("SqlConnectionUtils::createSqlPool",`UNSUPPORTED_DATABASE_TYPE_${i}`)}};var Le={info:"\x1B[32m",warn:"\x1B[33m",error:"\x1B[31m",reset:"\x1B[0m"};function Xc(){let i=new Date,t=e=>e.toString().padStart(2,"0");return `${i.getFullYear()}-${t(i.getMonth()+1)}-${t(i.getDate())} ${t(i.getHours())}:${t(i.getMinutes())}:${t(i.getSeconds())}`}function Or(i,t){let e=Xc(),r=i.toUpperCase();return i==="error"?`${Le.error}[${r}] ${e}
4
4
  ${t}${Le.reset}
5
5
  `:i==="warn"?`${Le.warn}[${r}] ${e}
@@ -367,5 +367,7 @@ export default class extends BaseSeeder {
367
367
  console.log('Seeder completed');
368
368
  }
369
369
  }
370
- `}};var lf=(i,t,e)=>{let r=e||"database/seeders",o=t?".js":".ts",s=`${Date.now()}_${i}${o}`;de__default.default.existsSync(r)||(de__default.default.mkdirSync(r,{recursive:true}),g.info(`Created seeders directory: ${r}`));let a=Be__default.default.join(r,s),l=xr.seederTemplate();de__default.default.writeFileSync(a,l),g.info(`Seeder created successfully: ${a}`);},Wc=lf;var df=async(i,t,e)=>{let r=[];for(let o of t){let n=Be__default.default.resolve(process.cwd(),o);de__default.default.existsSync(n)||(g.error(`Path not found: ${n}`),process.exit(1));let s=de__default.default.statSync(n);if(s.isDirectory()){let a=de__default.default.readdirSync(n).filter(l=>l.endsWith(".ts")||l.endsWith(".js")).sort();for(let l of a)r.push({file:l,folder:n});}else if(s.isFile()){let a=Be__default.default.basename(n),l=Be__default.default.dirname(n);a.endsWith(".ts")||a.endsWith(".js")?r.push({file:a,folder:l}):(g.error(`File must be a .ts or .js file: ${a}`),process.exit(1));}}if(!r.length){g.info("No seeders found");return}g.info(`Found ${r.length} seeder(s) to run`),i.isConnected||await i.connect();for(let{file:o,folder:n}of r)try{g.info(`Running seeder: ${o}`);let s=Be__default.default.resolve(n,o),a=await ne(s,e);if(!a.default){g.error(`Seeder ${o} does not export a default class`);continue}let l=new a.default(i);if(typeof l.run!="function"){g.error(`Seeder ${o} must have a run() method. Make sure it extends BaseSeeder from hysteria-orm`);continue}await l.run(),g.info(`\u2713 Completed seeder: ${o}`);}catch(s){throw g.error(`Failed to run seeder ${o}: ${s}`),s}g.info("All seeders completed successfully");},jc=df;var Hc=()=>de__default.default.existsSync(Be__default.default.join(process.cwd(),"yarn.lock"))?["yarn","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"pnpm-lock.yaml"))?["pnpm","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"package-lock.json"))?["npm","install"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"bun.lockb"))?["bun","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"deno.lock"))?["deno","add"]:["npm","install"],Jc=(i,t,e)=>{let r=Dr.includes(e)?["bundle-require@^5.1.0","typescript@^5.9.3","esbuild@^0.27.0"]:[],o="";switch(e){case "mariadb":case "mysql":o="mysql2@^3.15.3",r.push("@types/mysql2@github:types/mysql2");break;case "cockroachdb":case "postgres":o="pg@^8.16.3",r.push("@types/pg@^8.16.0");break;case "sqlite":o="sqlite3@^5.1.7",r.push("@types/sqlite3@^5.1.0");break;case "mongo":o="mongodb@^7.0.0",r.push("@types/mongodb@^4.0.7");break;case "redis":o="ioredis@^5.8.2",r.push("@types/ioredis@^5.0.0");break;case "mssql":o="mssql@^12.2.0",r.push("@types/mssql@^9.1.8");break;case "oracledb":o="oracledb@^6.10.0",r.push("@types/oracledb@^6.10.0");break;default:throw new Error(`Invalid database type: ${e}`)}g.info(`installing dev dependencies: ${r.join(" ")}`);let n=i==="deno"?"--dev":"-D";child_process.execSync(`${i} ${t} ${r.join(" ")} ${n}`,{stdio:"inherit"}),o&&(g.info(`installing driver dependency: ${o}`),child_process.execSync(`${i} ${t} ${o}`,{stdio:"inherit"}));};var Dr=["sqlite","mysql","postgres","mariadb","cockroachdb","mssql"],Ir=Dr.concat("mongodb","redis"),be=new commander.Command;be.command("init",{isDefault:false}).option("-t, --type [type]",`Type of the database to connect to, available types: ${Ir.join(", ")}`,void 0).description("Initialize the hysteria-orm with standard configuration, it will create a database if not exists and a migrations folder inside it if not exists, it will also create a index.ts file in the database folder").action(async i=>{let t=Ir.join(", ");i.type||(g.error(`Database type is required (-t|--type), available types: ${t}`),process.exit(1)),Ir.includes(i.type)||(g.error(`Invalid database type: ${i.type}, available types: ${Ir.join(", ")}`),process.exit(1)),g.info("Initializing hysteria-orm with standard configuration"),g.info(`Database type: ${i.type||"not specified (will use env DB_TYPE)"}`);let[e,r]=Hc();g.info(`Package manager: ${e}`),g.info("Installing base dependencies"),Jc(e,r,i.type);let o=Rr.initTemplate(i.type);de__default.default.existsSync("database")?g.info("database folder already exists, skipping"):de__default.default.mkdirSync("database",{recursive:true}),de__default.default.existsSync("database/index.ts")?g.info("database/index.ts file already exists, skipping"):de__default.default.writeFileSync("database/index.ts",o),Dr.includes(i.type)&&!de__default.default.existsSync("database/migrations")?de__default.default.mkdirSync("database/migrations",{recursive:true}):g.info("database/migrations folder already exists or is not a sql database, skipping"),g.info("Initialization completed successfully");});be.command("sql [sql]").alias("run:sql").option("-f, --file [path]","Path to the sql file",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-o, --out [query]","File path to save the query result",void 0).option("-t, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).description("Run a sql file or a sql query directly from the command line for the given connection defined in the env file").action(async(i,t)=>{g.info("Starting SQL execution"),t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let e=t?.file;!i&&!e&&(g.error("SQL query or file path is required"),process.exit(1)),i&&e&&(g.error("Cannot provide both sql query and file path"),process.exit(1));let r=Be__default.default.resolve(process.cwd(),t.datasource),{default:o}=await ne(r,t?.tsconfigPath);if(i){g.info("Executing SQL query directly from command line");try{await Ar(i,o,t?.out),g.info("SQL execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL execution failed: ${s}`),process.exit(1);}}e||(g.error("No SQL statement or file provided"),process.exit(1)),g.info(`Reading SQL from file: ${e}`),e=Be__default.default.resolve(process.cwd(),e),de__default.default.existsSync(e)||(g.error(`File not found: ${e}`),process.exit(1));let n=de__default.default.readFileSync(e,"utf-8");g.info(`SQL file loaded successfully (${n.length} characters)`);try{await Ar(n,o,t?.out),g.info("SQL file execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL file execution failed: ${s}`),process.exit(1);}});be.command("create:migration <name>").description("Create a new migration file, standard folder is migrations from the current directory you are now, you can change it in the env MIGRATION_PATH").option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-a, --alter","Generate a template for an alter table migration",false).option("-c, --create","Generate a template for a create table migration",false).option("-t, --table <table>","Specifies the target table name for the migration",false).action((i,t)=>{g.info(`Creating migration: ${i}`),g.info(`Migration options: javascript=${t.javascript}, alter=${t.alter}, create=${t.create}, table=${t.table||"not specified"}`),i||(g.error("Migration name is required"),process.exit(1)),t.alter&&t.create&&(g.error("Cannot use --alter and --create at the same time"),process.exit(1)),t.table&&!(t.create||t.alter)&&(g.error("Cannot use --table without --create or --alter"),process.exit(1));let e=t.alter?"alter":t.create?"create":"basic";g.info(`Migration mode: ${e}`),Oa(i,t.javascript,e,t.table||i);});be.command("migrate [runUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, only applies to postgres",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Run pending migrations, if runUntil is provided, it will run all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await nt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("rollback [rollbackUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Rollbacks every migration that has been run, if rollbackUntil is provided, it will rollback all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await gt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("refresh").option("-f, --force","Drop all tables in the database before running the migrations instead of running the down migrations",false).option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).option("-m, --migration-path [path]","Path to the migrations",void 0).description("Rollbacks every migration that has been run and then run the migrations").action(async i=>{let t=i?.force||false;i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),r=i?.migrationPath||e.migrationConfig.path,o=i?.tsconfigPath||e.migrationConfig.tsconfig,n=i?.lock??e.migrationConfig.lock,s=i?.lockTimeout?parseInt(i.lockTimeout,10):e.migrationConfig.lockTimeout,a=i?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock for refresh operation"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}t?await Er(e,!1,a):await gt(e,void 0,r,o,a),await nt(e,void 0,r,o,a);}catch(d){console.error(d);}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("generate:migrations").description("Generate a migration file based on the database schema and the models metadata, not supported for sqlite").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-f, --dry","Does not create a migration file but only outputs sql statements",false).option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-m, --migration-path [path]","Path to the migrations",void 0).option("-n, --name [name]","Name of the migration",void 0).action(async i=>{i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1)),i?.name||(i.name="auto_generated_migration"),i.name=`${Date.now()}_${i.name}`;let{default:t}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e=i?.migrationPath||t.migrationConfig.path;["mysql","postgres","mariadb","cockroachdb"].includes(t.getDbType())||(g.error(`generate:migrations is not supported for ${t.getDbType()}, it's suggested to use manual migrations instead`),process.exit(1));try{let n=(await Je.makeDiff(t)).getSqlStatements();if(n.length||(g.info("No new changes detected between database schema and models metadata"),process.exit(0)),i.dry){for(let l of n)console.log(l);process.exit(0);}de__default.default.existsSync(e)||de__default.default.mkdirSync(e,{recursive:!0});let s=await Cr.generate(n),a=i?.javascript?".js":".ts";de__default.default.writeFileSync(`${e}/${i?.name}${a}`,s),g.info(`Migration file created successfully: ${i?.name}${a}`),await t.closeConnection(),process.exit(0);}catch(o){console.error(o),await t.closeConnection(),process.exit(1);}});be.command("create:seeder <name>").description("Create a new seeder file").option("-j, --javascript","Generate a javascript seeder file instead of a default typescript one",false).option("-s, --seeder-path [path]","Path to the seeders",void 0).action((i,t)=>{g.info(`Creating seeder: ${i}`),g.info(`Seeder options: javascript=${t.javascript}`),i||(g.error("Seeder name is required"),process.exit(1)),Wc(i,t.javascript,t.seederPath);});be.command("seed").description("Run database seeders from folder or specific files").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-s, --seeder-path [path]","Path to seeder folder or file (can be specified multiple times or comma-separated)",(i,t=[])=>[...t,i]).action(async i=>{g.info("Starting seeder execution"),i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:t}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e;i?.seederPath&&i.seederPath.length>0?e=i.seederPath.flatMap(o=>o.split(",").map(n=>n.trim())):e=[t.seederConfig.path];let r=i?.tsconfigPath||t.seederConfig.tsconfig;try{await jc(t,e,r),await t.closeConnection(),g.info("Seeding completed successfully"),process.exit(0);}catch(o){console.error(o),await t.closeConnection(),process.exit(1);}});be.parse(process.argv);exports.sqlDatabaseTypes=Dr;//# sourceMappingURL=cli.cjs.map
370
+ `}};var lf=(i,t,e)=>{let r=e||"database/seeders",o=t?".js":".ts",s=`${Date.now()}_${i}${o}`;de__default.default.existsSync(r)||(de__default.default.mkdirSync(r,{recursive:true}),g.info(`Created seeders directory: ${r}`));let a=Be__default.default.join(r,s),l=xr.seederTemplate();de__default.default.writeFileSync(a,l),g.info(`Seeder created successfully: ${a}`);},Wc=lf;var df=async(i,t,e)=>{let r=[];for(let o of t){let n=Be__default.default.resolve(process.cwd(),o);de__default.default.existsSync(n)||(g.error(`Path not found: ${n}`),process.exit(1));let s=de__default.default.statSync(n);if(s.isDirectory()){let a=de__default.default.readdirSync(n).filter(l=>l.endsWith(".ts")||l.endsWith(".js")).sort();for(let l of a)r.push({file:l,folder:n});}else if(s.isFile()){let a=Be__default.default.basename(n),l=Be__default.default.dirname(n);a.endsWith(".ts")||a.endsWith(".js")?r.push({file:a,folder:l}):(g.error(`File must be a .ts or .js file: ${a}`),process.exit(1));}}if(!r.length){g.info("No seeders found");return}g.info(`Found ${r.length} seeder(s) to run`),i.isConnected||await i.connect();for(let{file:o,folder:n}of r)try{g.info(`Running seeder: ${o}`);let s=Be__default.default.resolve(n,o),a=await ne(s,e);if(!a.default){g.error(`Seeder ${o} does not export a default class`);continue}let l=new a.default(i);if(typeof l.run!="function"){g.error(`Seeder ${o} must have a run() method. Make sure it extends BaseSeeder from hysteria-orm`);continue}await l.run(),g.info(`\u2713 Completed seeder: ${o}`);}catch(s){throw g.error(`Failed to run seeder ${o}: ${s}`),s}g.info("All seeders completed successfully");},jc=df;var Hc=()=>de__default.default.existsSync(Be__default.default.join(process.cwd(),"yarn.lock"))?["yarn","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"pnpm-lock.yaml"))?["pnpm","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"package-lock.json"))?["npm","install"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"bun.lockb"))?["bun","add"]:de__default.default.existsSync(Be__default.default.join(process.cwd(),"deno.lock"))?["deno","add"]:["npm","install"],Vc=async(i,t,e,r)=>{let o=uf__default.default.createInterface({input:process.stdin,output:process.stdout}),n=e.join(", "),s=`Do you want to install the following dependencies using ${t}?
371
+ ${n}
372
+ (y/n): `;return new Promise(a=>{o.question(s,l=>{if(o.close(),l.toLowerCase()==="y"||l.toLowerCase()==="yes"){child_process.execSync(i,r),a(true);return}a(false);});})},Jc=async(i,t,e)=>{let r=Dr.includes(e)?["bundle-require@^5.1.0","typescript@^5.9.3","esbuild@^0.27.0"]:[],o="";switch(e){case "mariadb":case "mysql":o="mysql2@^3.15.3",r.push("@types/mysql2@github:types/mysql2");break;case "cockroachdb":case "postgres":o="pg@^8.16.3",r.push("@types/pg@^8.16.0");break;case "sqlite":o="sqlite3@^5.1.7",r.push("@types/sqlite3@^5.1.0");break;case "mongo":o="mongodb@^7.0.0",r.push("@types/mongodb@^4.0.7");break;case "redis":o="ioredis@^5.8.2",r.push("@types/ioredis@^5.0.0");break;case "mssql":o="mssql@^12.2.0",r.push("@types/mssql@^9.1.8");break;case "oracledb":o="oracledb@^6.10.0",r.push("@types/oracledb@^6.10.0");break;default:throw new Error(`Invalid database type: ${e}`)}if(o){let s=await Vc(`${i} ${t} ${o}`,i,[o],{stdio:"inherit"});s&&g.info("Driver dependency installed successfully"),s||g.info("Driver dependency installation skipped");}let n=i==="deno"?"--dev":"-D";if(r.length){let s=await Vc(`${i} ${t} ${r.join(" ")} ${n}`,i,r,{stdio:"inherit"});s&&g.info("Dev dependencies installed successfully"),s||g.info("Dev dependencies installation skipped");}};var Dr=["sqlite","mysql","postgres","mariadb","cockroachdb","mssql"],Ir=Dr.concat("mongodb","redis"),be=new commander.Command;be.command("init",{isDefault:false}).option("-t, --type [type]",`Type of the database to connect to, available types: ${Ir.join(", ")}`,void 0).description("Initialize the hysteria-orm with standard configuration, it will create a database if not exists and a migrations folder inside it if not exists, it will also create a index.ts file in the database folder").action(async i=>{let t=Ir.join(", ");i.type||(g.error(`Database type is required (-t|--type), available types: ${t}`),process.exit(1)),Ir.includes(i.type)||(g.error(`Invalid database type: ${i.type}, available types: ${Ir.join(", ")}`),process.exit(1)),g.info("Initializing hysteria-orm with standard configuration"),g.info(`Database type: ${i.type||"not specified (will use env DB_TYPE)"}`);let[e,r]=Hc();g.info(`Package manager: ${e}`),g.info("Installing base dependencies"),await Jc(e,r,i.type);let o=Rr.initTemplate(i.type);de__default.default.existsSync("database")?g.info("database folder already exists, skipping"):de__default.default.mkdirSync("database",{recursive:true}),de__default.default.existsSync("database/index.ts")?g.info("database/index.ts file already exists, skipping"):de__default.default.writeFileSync("database/index.ts",o),Dr.includes(i.type)&&!de__default.default.existsSync("database/migrations")?de__default.default.mkdirSync("database/migrations",{recursive:true}):g.info("database/migrations folder already exists or is not a sql database, skipping"),g.info("Initialization completed successfully");});be.command("sql [sql]").alias("run:sql").option("-f, --file [path]","Path to the sql file",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-o, --out [query]","File path to save the query result",void 0).option("-t, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).description("Run a sql file or a sql query directly from the command line for the given connection defined in the env file").action(async(i,t)=>{g.info("Starting SQL execution"),t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let e=t?.file;!i&&!e&&(g.error("SQL query or file path is required"),process.exit(1)),i&&e&&(g.error("Cannot provide both sql query and file path"),process.exit(1));let r=Be__default.default.resolve(process.cwd(),t.datasource),{default:o}=await ne(r,t?.tsconfigPath);if(i){g.info("Executing SQL query directly from command line");try{await Ar(i,o,t?.out),g.info("SQL execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL execution failed: ${s}`),process.exit(1);}}e||(g.error("No SQL statement or file provided"),process.exit(1)),g.info(`Reading SQL from file: ${e}`),e=Be__default.default.resolve(process.cwd(),e),de__default.default.existsSync(e)||(g.error(`File not found: ${e}`),process.exit(1));let n=de__default.default.readFileSync(e,"utf-8");g.info(`SQL file loaded successfully (${n.length} characters)`);try{await Ar(n,o,t?.out),g.info("SQL file execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL file execution failed: ${s}`),process.exit(1);}});be.command("create:migration <name>").description("Create a new migration file, standard folder is migrations from the current directory you are now, you can change it in the env MIGRATION_PATH").option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-a, --alter","Generate a template for an alter table migration",false).option("-c, --create","Generate a template for a create table migration",false).option("-t, --table <table>","Specifies the target table name for the migration",false).action((i,t)=>{g.info(`Creating migration: ${i}`),g.info(`Migration options: javascript=${t.javascript}, alter=${t.alter}, create=${t.create}, table=${t.table||"not specified"}`),i||(g.error("Migration name is required"),process.exit(1)),t.alter&&t.create&&(g.error("Cannot use --alter and --create at the same time"),process.exit(1)),t.table&&!(t.create||t.alter)&&(g.error("Cannot use --table without --create or --alter"),process.exit(1));let e=t.alter?"alter":t.create?"create":"basic";g.info(`Migration mode: ${e}`),Oa(i,t.javascript,e,t.table||i);});be.command("migrate [runUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, only applies to postgres",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Run pending migrations, if runUntil is provided, it will run all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await nt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("rollback [rollbackUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Rollbacks every migration that has been run, if rollbackUntil is provided, it will rollback all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await gt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("refresh").option("-f, --force","Drop all tables in the database before running the migrations instead of running the down migrations",false).option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).option("-m, --migration-path [path]","Path to the migrations",void 0).description("Rollbacks every migration that has been run and then run the migrations").action(async i=>{let t=i?.force||false;i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),r=i?.migrationPath||e.migrationConfig.path,o=i?.tsconfigPath||e.migrationConfig.tsconfig,n=i?.lock??e.migrationConfig.lock,s=i?.lockTimeout?parseInt(i.lockTimeout,10):e.migrationConfig.lockTimeout,a=i?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock for refresh operation"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}t?await Er(e,!1,a):await gt(e,void 0,r,o,a),await nt(e,void 0,r,o,a);}catch(d){console.error(d);}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.closeConnection();}});be.command("generate:migrations").description("Generate a migration file based on the database schema and the models metadata, not supported for sqlite").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-f, --dry","Does not create a migration file but only outputs sql statements",false).option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-m, --migration-path [path]","Path to the migrations",void 0).option("-n, --name [name]","Name of the migration",void 0).action(async i=>{i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1)),i?.name||(i.name="auto_generated_migration"),i.name=`${Date.now()}_${i.name}`;let{default:t}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e=i?.migrationPath||t.migrationConfig.path;["mysql","postgres","mariadb","cockroachdb"].includes(t.getDbType())||(g.error(`generate:migrations is not supported for ${t.getDbType()}, it's suggested to use manual migrations instead`),process.exit(1));try{let n=(await Je.makeDiff(t)).getSqlStatements();if(n.length||(g.info("No new changes detected between database schema and models metadata"),process.exit(0)),i.dry){for(let l of n)console.log(l);process.exit(0);}de__default.default.existsSync(e)||de__default.default.mkdirSync(e,{recursive:!0});let s=await Cr.generate(n),a=i?.javascript?".js":".ts";de__default.default.writeFileSync(`${e}/${i?.name}${a}`,s),g.info(`Migration file created successfully: ${i?.name}${a}`),await t.closeConnection(),process.exit(0);}catch(o){console.error(o),await t.closeConnection(),process.exit(1);}});be.command("create:seeder <name>").description("Create a new seeder file").option("-j, --javascript","Generate a javascript seeder file instead of a default typescript one",false).option("-s, --seeder-path [path]","Path to the seeders",void 0).action((i,t)=>{g.info(`Creating seeder: ${i}`),g.info(`Seeder options: javascript=${t.javascript}`),i||(g.error("Seeder name is required"),process.exit(1)),Wc(i,t.javascript,t.seederPath);});be.command("seed").description("Run database seeders from folder or specific files").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-s, --seeder-path [path]","Path to seeder folder or file (can be specified multiple times or comma-separated)",(i,t=[])=>[...t,i]).action(async i=>{g.info("Starting seeder execution"),i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:t}=await ne(Be__default.default.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e;i?.seederPath&&i.seederPath.length>0?e=i.seederPath.flatMap(o=>o.split(",").map(n=>n.trim())):e=[t.seederConfig.path];let r=i?.tsconfigPath||t.seederConfig.tsconfig;try{await jc(t,e,r),await t.closeConnection(),g.info("Seeding completed successfully"),process.exit(0);}catch(o){console.error(o),await t.closeConnection(),process.exit(1);}});be.parse(process.argv);exports.sqlDatabaseTypes=Dr;//# sourceMappingURL=cli.cjs.map
371
373
  //# sourceMappingURL=cli.cjs.map