hysteria-orm 10.8.3 → 10.8.4
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.js +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +56 -48
- package/lib/index.d.ts +56 -48
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ ${t}${Ze.reset}
|
|
|
8
8
|
`:`[${r}] ${e}
|
|
9
9
|
${t}
|
|
10
10
|
`}var Xe=class{static setCustomLogger(t){this.loggerInstance=t;}static info(t){this.loggerInstance.info(t);}static error(t){if(t instanceof Error){this.loggerInstance.error(String(t));return}this.loggerInstance.error(t);}static warn(t){this.loggerInstance.warn(t);}};Xe.loggerInstance={info(t){console.log(so("info",t));},error(t){console.error(so("error",t));},warn(t){console.warn(so("warn",t));}};function bf(i){return i.map(t=>typeof t=="object"?JSON.stringify(t):typeof t=="string"?`'${t}'`:typeof t=="number"?t:typeof t=="boolean"?t?"true":"false":t).join(", ")}function oe(i,t,e){if(!hf(t))return;i=sqlHighlight.highlight(i,{colors:{keyword:"\x1B[34m",string:"\x1B[32m",number:"\x1B[33m",bracket:"\x1B[36m",clear:"\x1B[0m",comment:"\x1B[90m",function:"\x1B[35m",identifier:"\x1B[37m",special:"\x1B[31m"}});let r=`${i} [${bf(e||[])}]`;Xe.loggerInstance.info(r);}function _l(i,t,e=false){yf(e,t)&&Xe.loggerInstance[t](i);}var M=Xe;var et=class{constructor(t){switch(this.type=t?.type||I.DB_TYPE,this.type){case "mongo":this.handleMongoSource(t);break;case "cockroachdb":this.handleCockroachdbSource(t);break;case "postgres":this.handlePostgresSource(t);break;case "mariadb":case "mysql":this.handleMysqlSource(t);break;case "sqlite":this.handleSqliteSource(t);break;case "mssql":this.handleMssqlSource(t);break;case "oracledb":this.handleOracleDBSource(t);break;default:throw new h(`Invalid database type: ${this.type}, please provide a valid database type in your input or in the .env file with the key DB_TYPE
|
|
11
|
-
Valid database types are: [mongo, postgres, cockroachdb, mysql, mariadb, sqlite]`,`UNSUPPORTED_DATABASE_TYPE_${this.type}`)}let e=vt(this.logs);e?.customLogger&&M.setCustomLogger(e.customLogger);}handleCockroachdbSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=26257);}handlePostgresSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=5432);}handleMysqlSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=3306);}handleSqliteSource(t){this.database=t?.database||I.DB_DATABASE||":memory:",this.logs=t?.logs||I.DB_LOGS||false;}handleMongoSource(t){this.url=t?.url||I.MONGO_URL,this.logs=t?.logs||I.MONGO_LOGS||false;}handleMssqlSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=1433);}handleOracleDBSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=1521);}};var Tf=i=>{let{required:t,...e}=i.openApi||{},r={...e,type:i.openApi?.type||"string",description:i.openApi?.description??`Property: ${i.columnName}`};return i.openApi?.type?{...r,type:i.openApi.type}:Array.isArray(i.type)?{...r,type:"string",enum:i.type}:i.type==="date"||i.type==="datetime"||i.type==="timestamp"||i.type==="time"?{...r,type:"string",format:"date-time"}:i.type==="boolean"?{...r,type:"boolean"}:i.type==="integer"||i.type==="tinyint"||i.type==="smallint"||i.type==="mediumint"||i.type==="increment"?{...r,type:"integer",format:"int32"}:i.type==="biginteger"||i.type==="bigIncrement"?{...r,type:"integer",format:"int64"}:i.type==="float"||i.type==="real"?{...r,type:"number",format:"float"}:i.type==="double"?{...r,type:"number",format:"double"}:i.type==="decimal"||i.type==="numeric"?{...r,type:"number"}:i.type==="json"||i.type==="jsonb"?{...r,type:"object"}:i.type==="uuid"?{...r,type:"string",format:"uuid"}:i.type==="ulid"?{...r,type:"string",format:"ulid"}:i.type==="string"||i.type==="char"||i.type==="varchar"||i.type==="text"||i.type==="longtext"||i.type==="mediumtext"||i.type==="tinytext"?{...r,type:"string"}:i.type==="blob"||i.type==="binary"||i.type==="varbinary"||i.type==="tinyblob"||i.type==="mediumblob"||i.type==="longblob"?{...r,type:"string",format:"binary"}:i.type==="year"?{...r,type:"integer",format:"int32"}:r},wf=i=>i.openApi?.required??false,Nf=i=>{let t=i.getColumns(),e={};for(let r of t)r.hidden||(e[r.columnName]=Tf(r));return e},Sf=i=>{let t=i.getColumns(),e=[];for(let r of t)wf(r)&&e.push(r.columnName);return e||[]},io=i=>{let t=Nf(i),e=Sf(i);return {type:"object",properties:t,required:e.length?e:[]}},Th=i=>i.map(t=>io(t)),wh=i=>io(i),Ol=i=>i.map(t=>({...io(t),modelName:t.name,$id:t.name}));var ao=(i,t)=>{let e=Me__default.default.createHash("sha256"),r=i;return e.update(r),e.digest("hex")};var lo=i=>{switch(i){case "mysql":return "mysql";case "mariadb":return "mariadb";case "postgres":case "cockroachdb":return "postgresql";case "sqlite":return "sqlite";case "mssql":return "transactsql";case "oracledb":return "plsql";default:return "sql"}},kt=i=>{if(i==null)return "NULL";if(i instanceof Date)return `'${i.toISOString()}'`;let t=typeof i;return t==="boolean"?i?"TRUE":"FALSE":t==="number"&&Number.isFinite(i)||t==="bigint"?String(i):t==="string"?`'${i.replace(/'/g,"''")}'`:Array.isArray(i)||t==="object"&&Object.keys(i).length>0?`'${JSON.stringify(i).replace(/'/g,"''")}'`:String(i)},tt=(i,t)=>{let e=i;for(let r=0;r<t.length&&e.includes("?");r++)e=e.replace(/\?/,kt(t[r]));for(let r=0;r<t.length;r++){let o=new RegExp(`\\$${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}for(let r=0;r<t.length;r++){let o=new RegExp(`\\@${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}for(let r=0;r<t.length;r++){let o=new RegExp(`:${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}return e},rt=(i,t)=>t?i==="mysql"||i==="mariadb"?t.code==="ER_NO_SUCH_TABLE"||t.errno===1146:i==="postgres"||i==="cockroachdb"?t.code==="42P01":i==="sqlite"?/no such table/i.test(String(t.message||"")):i==="mssql"?t.number===208:i==="oracledb"?t.errorNum===942:false:false,Pe=(i,t)=>{let e=i.getDbType(),r;try{r=sqlFormatter.format(t,{...i.inputDetails.queryFormatOptions,language:lo(e)});}catch{try{r=sqlFormatter.format(t,{...i.inputDetails.queryFormatOptions});}catch{r=t;}}return r};var uo=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.column]),n=e.inlineConstraints;if(n&&n.length){let s=[];for(let a of n){let{sql:l}=r.parse([a]);s.push(l);}s.length&&(o+=` ${s.join(" ")}`);}return {sql:`add ${o}`,bindings:[]}}},xl=new uo;var co=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.constraint]);return {sql:`add ${o}`,bindings:[]}}},Il=new co;var mo=class{toSql(t){return {sql:`add primary key (${t.columns.map(o=>`[${o}]`).join(", ")})`,bindings:[]}}},Dl=new mo;var po=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.newType]),[,...n]=o.trim().split(/\s+/),s=n.join(" "),a="";e.options.nullable!==void 0&&(a=e.options.nullable?" null":" not null");let l=`alter column [${e.column}] ${s}${a}`;if(e.options.dropDefault&&(l=`drop constraint DF_${e.column}, ${l}`),e.options.default!==void 0&&!e.options.dropDefault){let d=e.options.default;d===null?d="null":typeof d=="string"&&(d==="NULL"?d="null":d==="TRUE"||d==="FALSE"?d=d==="TRUE"?"1":"0":d=`'${d}'`),l+=`, add constraint DF_${e.column} default ${d} for [${e.column}]`;}return e.options.unique!==void 0&&e.options.unique&&(l+=`, add constraint UQ_${e.column} unique ([${e.column}])`),{sql:l,bindings:[]}}},Pl=new po;var N=class{constructor(t,e=false){this.currParamIndex=1;this.isRawValue=false;this.keyword=t,this.isRawValue=e;}};var ot=class extends N{constructor(e){super("rename to");this.chainsWith=",";this.canKeywordBeSeenMultipleTimes=false;this.folder="alter_table";this.file="rename_table";this.newName=e;}};var qf=i=>{if(i==null||typeof i!="object"||i instanceof Date)return false;if(Array.isArray(i))return true;let t=Object.getPrototypeOf(i);return t===Object.prototype||t===null},y=class{constructor(t){this.model=t;let e=Qt(t);this.modelColumnsMap=new Map(e.map(r=>[r.columnName,r]));}formatStringColumn(t,e){if(e==="*")return "*";if(e.includes(".")){let[n,s]=e.split(".");if(s==="*")switch(t){case "mysql":case "mariadb":return `\`${n}\`.*`;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${n}".*`;case "mssql":return `[${n}].*`;default:throw new Error(`Unsupported database type: ${t}`)}let a=this.modelColumnsMap.get(s)?.databaseName??L(s,this.model.databaseCaseConvention);switch(t){case "mysql":case "mariadb":return `\`${n}\`.\`${a}\``;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${n}"."${a}"`;case "mssql":return `[${n}].[${a}]`;default:throw new Error(`Unsupported database type: ${t}`)}}let o=this.modelColumnsMap.get(e)?.databaseName??L(e,this.model.databaseCaseConvention);switch(t){case "mysql":case "mariadb":return `\`${o}\``;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${o}"`;case "mssql":return `[${o}]`;default:throw new Error(`Unsupported database type: ${t}`)}}formatStringTable(t,e){e=e.replace(/\s+/g," ").trim();let r="";switch(e.toLowerCase().includes(" as ")&&([e,r]=e.split(" as ")),t){case "mysql":case "mariadb":return `\`${e}\`${r?` as \`${r}\``:""}`;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${e}"${r?` as "${r}"`:""}`;case "mssql":return `[${e}]${r?` as [${r}]`:""}`;default:return `${e}${r?` as ${r}`:""}`}}async prepareColumns(t,e,r="insert"){if(!t.length)return {columns:t,values:e};let o=[],n=[];for(let s=0;s<t.length;s++){let a=t[s],l=e[s];a!=="*"&&(o.push(a),n.push(l));}await Promise.all(o.map(async(s,a)=>{let l=o[a],d=n[a],u=this.modelColumnsMap.get(l),f=d;u?r==="insert"&&u.prepare?f=await u.prepare(d):r==="update"&&(f=await u.prepare?.(d)??d):qf(d)&&(f=JSON.stringify(d)),n[a]=f;}));for(let s of this.modelColumnsMap.keys())if(!o.includes(s)){let a=this.modelColumnsMap.get(s);if(!a||r==="insert"&&s===this.model.primaryKey&&!a.prepare)continue;if(r==="insert"||a.autoUpdate){o.push(s);let l=a.prepare?await a.prepare(void 0):void 0;n.push(l??void 0);}}return {columns:o,values:n}}getFromForWriteOperations(t,e){if(typeof e.table=="string")return this.formatStringTable(t,e.table);let r=new T(this.model,t);return Array.isArray(e.table)?`(${r.parse(e.table).sql})`:`(${r.parse([e.table]).sql})`}};var fo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);if(!e.children||!e.children.length)return {sql:"",bindings:[]};if(e.children.length===1&&e.children[0]instanceof ot){let u=e.children[0];return {sql:`EXEC sp_rename '${e.table}', '${u.newName}'`,bindings:[]}}let n=new T(this.model,"mssql"),s=[],a=[];for(let u of e.children){let{sql:f,bindings:c}=n.parse([u]);s.push(f.trim()),a.push(...c);}let l=s.join(", ");return {sql:`${o} ${l}`,bindings:a}}},$l=new fo;var yo=class{toSql(t){return {sql:`drop column [${t.column}]`,bindings:[]}}},El=new yo;var ho=class{toSql(t){return {sql:`drop constraint [${t.constraintName}]`,bindings:[]}}},Bl=new ho;var go=class{toSql(t){return {sql:`drop constraint DF_${t.column}`,bindings:[]}}},vl=new go;var bo=class{toSql(t){let e=t;return M.warn("MSSQL requires the full column type when altering nullability. This operation may need manual adjustment."),{sql:`alter column [${e.column}] null`,bindings:[]}}},kl=new bo;var To=class{toSql(t){return {sql:`drop constraint [${`pk_${t.table}`}]`,bindings:[]}}},Ql=new To;var wo=class{toSql(t){let e=t;return {sql:`sp_rename '${this.model?.table??""}.${e.oldName}', '${e.newName}', 'COLUMN'`,bindings:[]}}},Kl=new wo;var No=class{toSql(t){return {sql:`[${t.newName}]`,bindings:[]}}},Ll=new No;var D=class extends N{constructor(e){super("raw",true);this.canKeywordBeSeenMultipleTimes=true;this.chainsWith=" ";this.currParamIndex=0;this.isRawValue=true;this.folder="raw";this.file="raw";this.rawValue=e;}};var So=class{toSql(t){let e=t,r;return e.defaultValue instanceof D?r=e.defaultValue.rawValue:e.defaultValue==="NULL"||e.defaultValue===null?r="null":e.defaultValue==="TRUE"?r="1":e.defaultValue==="FALSE"?r="0":typeof e.defaultValue=="string"&&e.defaultValue!=="null"&&e.defaultValue!=="1"&&e.defaultValue!=="0"?r=`'${e.defaultValue}'`:r=String(e.defaultValue),{sql:`add constraint DF_${e.column} default ${r} for [${e.column}]`,bindings:[]}}},Wl=new So;var Co=class{toSql(t){let e=t;return M.warn("MSSQL requires the full column type when altering nullability. This operation may need manual adjustment."),{sql:`alter column [${e.column}] not null`,bindings:[]}}},Fl=new Co;var qo=class{toSql(t){return {sql:"",bindings:[]}}},jl=new qo;var Mo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:[]};let o=new y(this.model).formatStringColumn("mssql",S(e.column)),n=e.dataType.toLowerCase();if(n==="char"){let s=e.length??1;return {sql:`${o} char(${s})`,bindings:[]}}if(n==="varchar"){let s=e.length??255;return {sql:`${o} varchar(${s})`,bindings:[]}}if(n==="text"||n==="longtext"||n==="mediumtext"||n==="tinytext")return {sql:`${o} varchar(max)`,bindings:[]};if(n==="uuid")return {sql:`${o} uniqueidentifier`,bindings:[]};if(n==="ulid")return {sql:`${o} varchar(26)`,bindings:[]};if(n==="bigint")return e.autoIncrement?{sql:`${o} bigint identity(1,1)`,bindings:[]}:{sql:`${o} bigint`,bindings:[]};if(n==="tinyint")return {sql:`${o} tinyint`,bindings:[]};if(n==="smallint")return {sql:`${o} smallint`,bindings:[]};if(n==="mediumint")return {sql:`${o} int`,bindings:[]};if(n==="float"||n==="real")return {sql:`${o} real`,bindings:[]};if(n==="double")return {sql:`${o} float`,bindings:[]};if(n==="decimal"||n==="numeric"){let s=e.precision??10,a=e.scale??0;return {sql:`${o} decimal(${s}, ${a})`,bindings:[]}}if(n==="date")return {sql:`${o} date`,bindings:[]};if(n==="year")return {sql:`${o} smallint`,bindings:[]};if(n==="time"){let s=typeof e.precision=="number"?`(${e.precision})`:"";return {sql:`${o} time${s}`,bindings:[]}}if(n==="datetime"||n==="timestamp"){let s=typeof e.precision=="number"?`(${e.precision})`:"",a=`${o} datetime2${s}`;return e.autoCreate&&(a+=" default current_timestamp"),{sql:a,bindings:[]}}if(n==="boolean"||n==="bool")return {sql:`${o} bit`,bindings:[]};if(n==="bytea"||n==="binary"||n==="varbinary"||n==="blob"||n==="longblob"||n==="mediumblob"||n==="tinyblob")return {sql:`${o} varbinary(max)`,bindings:[]};if(n==="json"||n==="jsonb")return {sql:`${o} nvarchar(max)`,bindings:[]};if(n==="enum"){if(e.enumValues&&e.enumValues.length>0){let s=e.enumValues.map(a=>`'${a}'`).join(", ");return {sql:`${o} varchar(255) check (${o} in (${s}))`,bindings:[]}}return {sql:`${o} varchar(255)`,bindings:[]}}return n==="integer"||n==="int"?e.autoIncrement?{sql:`${o} int identity(1,1)`,bindings:[]}:{sql:`${o} int`,bindings:[]}:n==="geometry"?{sql:`${o} geometry`,bindings:[]}:n==="point"?{sql:`${o} geometry`,bindings:[]}:n==="linestring"?{sql:`${o} geometry`,bindings:[]}:n==="polygon"?{sql:`${o} geometry`,bindings:[]}:n==="multipoint"?{sql:`${o} geometry`,bindings:[]}:{sql:`${o} ${n}${e.length?`(${e.length})`:""}`,bindings:[]}}},Ul=new Mo;var Ro=class{toSql(t){return {sql:"",bindings:[]}}},Vl=new Ro;var _o=class{toSql(t){let e=t,r=new y(this.model);if(e.constraintType==="primary_key"){if(e.columns&&e.columns.length){let o=e.constraintName?`constraint [${e.constraintName}] `:"",n=(e.columns??[]).map(s=>r.formatStringColumn("mssql",S(s))).join(", ");return {sql:`${o}primary key (${n})`,bindings:[]}}return {sql:"primary key",bindings:[]}}if(e.constraintType==="unique"){if(e.columns&&e.columns.length>0){let o=e.columns??[],n=e.constraintName?`constraint [${e.constraintName}] `:"",s=o.map(a=>r.formatStringColumn("mssql",S(a))).join(", ");return e.constraintName?{sql:`${n}unique (${s})`,bindings:[]}:{sql:"unique",bindings:[]}}return {sql:"unique",bindings:[]}}if(e.constraintType==="not_null")return {sql:"not null",bindings:[]};if(e.constraintType==="null")return {sql:"null",bindings:[]};if(e.constraintType==="default"){if(e.defaultValue!==void 0){let o=e.defaultValue;return o instanceof D?{sql:`default ${o.rawValue}`,bindings:[]}:o==="NULL"||o===null?{sql:"default null",bindings:[]}:o==="TRUE"?{sql:"default 1",bindings:[]}:o==="FALSE"?{sql:"default 0",bindings:[]}:typeof o=="string"?{sql:`default '${o}'`,bindings:[]}:{sql:`default ${o}`,bindings:[]}}return {sql:"default null",bindings:[]}}if(e.constraintType==="foreign_key"){if(!e.columns||!e.columns.length)return {sql:"",bindings:[]};let o=e.columns.map(d=>r.formatStringColumn("mssql",S(d))).join(", ");if(!e.references)return {sql:"",bindings:[]};let n=r.formatStringTable("mssql",e.references.table),s=e.references.columns.map(d=>r.formatStringColumn("mssql",S(d))).join(", "),l=`${e.constraintName?`constraint [${e.constraintName}] `:""}foreign key (${o}) references ${n}(${s})`;return e.onDelete&&(l+=` on delete ${e.onDelete}`),e.onUpdate&&(l+=` on update ${e.onUpdate}`),{sql:l,bindings:[]}}return e.constraintType==="check"?e.checkExpression?{sql:`${e.constraintName?`constraint [${e.constraintName}] `:""}check (${e.checkExpression})`,bindings:[]}:{sql:"",bindings:[]}:{sql:"",bindings:[]}}},Jl=new _o;var Oo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);if(!e.children||!e.children.length)return {sql:`${o} ()`,bindings:[]};let n=new T(this.model,"mssql"),s=[],a=[];for(let m of e.children){let{sql:g,bindings:b}=n.parse([m]);if(m.folder==="constraint"){let w=s.pop()??"",C=g;if(/not null/i.test(C)||/null/i.test(C)||/default/i.test(C)){let _=`${w} ${C}`.trim();_=_.replace(/(references\s+\[[^\]]+\]\s*\([^)]*\))\s+not null/i,"not null $1"),s.push(_),a.push(...b);continue}s.push(w),s.push(C),a.push(...b);continue}s.push(g),a.push(...b);}for(let m of e.namedConstraints){let{sql:g,bindings:b}=n.parse([m]);s.push(g),a.push(...b);}let l=s.join(", "),d=[];e.dataCompression&&d.push(`DATA_COMPRESSION = ${e.dataCompression}`);let u=e.onFilegroup?` ON [${e.onFilegroup}]`:"",f=e.textImageOn?` TEXTIMAGE_ON [${e.textImageOn}]`:"",c=d.length>0?` WITH (${d.join(", ")})`:"";return {sql:`${o} (${l})${c}${u}${f}`,bindings:a}}},Hl=new Oo;var Ao=class{toSql(t){let e=t;return e.isRawValue&&typeof e.fromNode.table=="string"?{sql:e.fromNode.table,bindings:[]}:{sql:new y(this.model).getFromForWriteOperations("mssql",e.fromNode),bindings:[]}}},zl=new Ao;var xo=class{toSql(t){return {sql:"",bindings:[]}}},Yl=new xo;var Io=class{toSql(t){return M.warn("MSSQL does not support DISTINCT ON. This clause will be ignored."),{sql:"",bindings:[]}}},Gl=new Io;var Do=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);return {sql:`${e.ifExists?"if exists ":""}${o}`,bindings:[]}}},Zl=new Do;var Po=class{toSql(t){return {sql:`-- MSSQL does not support extensions (extension: ${t.extensionName})`,bindings:[]}}},Xl=new Po;var $o=class{toSql(t){let e=t;if(typeof e.table=="string"){let a=new y(this.model);return e.alias&&e.alias.length>0?{sql:`${a.formatStringTable("mssql",e.table)} as [${e.alias}]`,bindings:[]}:{sql:a.formatStringTable("mssql",e.table),bindings:[]}}let r=Array.isArray(e.table)?e.table:[e.table],n=new T(this.model,"mssql").parse(r),s=e.alias&&e.alias.length?` as [${e.alias}]`:"";return {sql:`(${n.sql})${s}`,bindings:n.bindings}}},ed=new $o;var Eo=class{toSql(t){let e=t;return e.isRawValue?{sql:e.column,bindings:[]}:{sql:new y(this.model).formatStringColumn("mssql",e.column),bindings:[]}}},td=new Eo;var Bo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:e.value};let r=e.currParamIndex,o="",n=[];if(!(e.value instanceof N)&&!Array.isArray(e.value)&&(o=`${new y(this.model).formatStringColumn("mssql",e.column)} ${e.operator} @${r}`,n=[e.value]),Array.isArray(e.value)){let s=e.value.map((a,l)=>`@${r+l}`).join(", ");o=`${new y(this.model).formatStringColumn("mssql",e.column)} ${e.operator} (${s})`,n=e.value;}return e.isNegated&&(o=`not (${o})`),{sql:o.trim(),bindings:n}}},rd=new Bo;var vo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table),n=e.columns.map(a=>`[${a}]`).join(", ");return {sql:`${e.unique?"unique ":""}[${e.indexName}] on ${o} (${n})`,bindings:[]}}},od=new vo;var ko=class{toSql(t){let e=t;return {sql:`[${e.indexName}] on [${e.table}]`,bindings:[]}}},nd=new ko;var Qo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.fromNode.table,bindings:[]};let r=new y(this.model),o=r.getFromForWriteOperations("mssql",e.fromNode);if(!e.records.length)return {sql:o,bindings:[]};let n=e.records[0],s=Object.keys(n).filter(c=>n[c]!==void 0);if(!s.length)return {sql:o,bindings:[]};let a=s.map(c=>r.formatStringColumn("mssql",c)).join(", "),l=[],d=[],u=e.currParamIndex;for(let c of e.records){let p=s.map(g=>c[g]),m=[];for(let g of p)g instanceof D?m.push(g.rawValue):(l.push(g),m.push(`@${u++}`));d.push(`(${m.join(", ")})`);}let f=`${o} (${a}) values ${d.join(", ")}`;if(!e.disableReturning)if(e.returning&&e.returning.length){let c=e.returning.map(p=>`inserted.${r.formatStringColumn("mssql",p)}`).join(", ");f=f.replace(") values",`) output ${c} values`);}else {let c=this.getOutputColumns(s,r);f=f.replace(") values",`) output ${c} values`);}return {sql:f,bindings:l}}getOutputColumns(t,e){let r=[...t],o=this.model.primaryKey;return o&&!t.includes(o)&&r.push(o),r.map(n=>`inserted.${e.formatStringColumn("mssql",n)}`).join(", ")}},sd=new Qo;var Ko=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.table,bindings:[]};let r=new y(this.model),o=e.left;o.includes(".")||(o=`${e.table}.${o}`);let n=e.right;n.includes(".")||(n=`${this.model.table}.${n}`);let s=r.formatStringColumn("mssql",o),a=r.formatStringColumn("mssql",n),d=`${r.formatStringTable("mssql",e.table)} on ${s} ${e.on?.operator} ${a}`,u=[];if(e.additionalConditions&&e.additionalConditions.length>0){let f=new T(this.model,"mssql");for(let c of e.additionalConditions){let p=f.parse([c]);if(p.sql){let m=p.sql.replace(/^where\s+/i,"");d+=` and ${m}`,u.push(...p.bindings);}}}return {sql:d,bindings:u}}},id=new Ko;var Lo=class{toSql(t){let e=t;return {sql:`fetch next @${e.currParamIndex} rows only`,bindings:[e.limit]}}},ad=new Lo;var Wo=class{toSql(t){return {sql:"",bindings:[]}}},ld=new Wo;var Fo=class{toSql(t){let e=t;return {sql:`offset @${e.currParamIndex} rows`,bindings:[e.offset]}}},dd=new Fo;var jo=class{toSql(t){let e=t;return e.isRawValue?{sql:e.table,bindings:[]}:(M.warn("MSSQL does not support ON CONFLICT or ON DUPLICATE KEY. Use MERGE statement for upsert operations. This clause will be ignored. Consider using raw queries for MSSQL upserts."),{sql:"",bindings:[]})}},ud=new jo;var Uo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:[]};let r=new y(this.model).formatStringColumn("mssql",e.column),o=e.direction.toLowerCase();return {sql:`${r} ${o}`,bindings:[]}}},cd=new Uo;var Vo=class{toSql(t){return {sql:t.rawValue,bindings:[]}}},md=new Vo;var Jo=class{toSql(t){return {sql:`SELECT
|
|
11
|
+
Valid database types are: [mongo, postgres, cockroachdb, mysql, mariadb, sqlite]`,`UNSUPPORTED_DATABASE_TYPE_${this.type}`)}let e=vt(this.logs);e?.customLogger&&M.setCustomLogger(e.customLogger);}handleCockroachdbSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=26257);}handlePostgresSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=5432);}handleMysqlSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=3306);}handleSqliteSource(t){this.database=t?.database||I.DB_DATABASE||":memory:",this.logs=t?.logs||I.DB_LOGS||false;}handleMongoSource(t){this.url=t?.url||I.MONGO_URL,this.logs=t?.logs||I.MONGO_LOGS||false;}handleMssqlSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=1433);}handleOracleDBSource(t){this.host=t?.host||I.DB_HOST,this.port=+t?.port||+I.DB_PORT,this.username=t?.username||I.DB_USER,this.password=t?.password||I.DB_PASSWORD,this.database=t?.database||I.DB_DATABASE,this.logs=t?.logs||I.DB_LOGS||false,this.port||(this.port=1521);}};var Tf=i=>{let{required:t,...e}=i.openApi||{},r={...e,type:i.openApi?.type||"string",description:i.openApi?.description??`Property: ${i.columnName}`};return i.openApi?.type?{...r,type:i.openApi.type}:Array.isArray(i.type)?{...r,type:"string",enum:i.type}:i.type==="date"||i.type==="datetime"||i.type==="timestamp"||i.type==="time"?{...r,type:"string",format:"date-time"}:i.type==="boolean"?{...r,type:"boolean"}:i.type==="integer"||i.type==="tinyint"||i.type==="smallint"||i.type==="mediumint"||i.type==="increment"?{...r,type:"integer",format:"int32"}:i.type==="biginteger"||i.type==="bigIncrement"?{...r,type:"integer",format:"int64"}:i.type==="float"||i.type==="real"?{...r,type:"number",format:"float"}:i.type==="double"?{...r,type:"number",format:"double"}:i.type==="decimal"||i.type==="numeric"?{...r,type:"number"}:i.type==="json"||i.type==="jsonb"?{...r,type:"object"}:i.type==="uuid"?{...r,type:"string",format:"uuid"}:i.type==="ulid"?{...r,type:"string",format:"ulid"}:i.type==="string"||i.type==="char"||i.type==="varchar"||i.type==="text"||i.type==="longtext"||i.type==="mediumtext"||i.type==="tinytext"?{...r,type:"string"}:i.type==="blob"||i.type==="binary"||i.type==="varbinary"||i.type==="tinyblob"||i.type==="mediumblob"||i.type==="longblob"?{...r,type:"string",format:"binary"}:i.type==="year"?{...r,type:"integer",format:"int32"}:r},wf=i=>i.openApi?.required??false,Nf=i=>{let t=i.getColumns(),e={};for(let r of t)r.hidden||(e[r.columnName]=Tf(r));return e},Sf=i=>{let t=i.getColumns(),e=[];for(let r of t)wf(r)&&e.push(r.columnName);return e||[]},io=i=>{let t=Nf(i),e=Sf(i);return {type:"object",properties:t,required:e.length?e:[]}},Th=i=>i.map(t=>io(t)),wh=i=>io(i),Ol=i=>i.map(t=>({...io(t),modelName:t.name,$id:t.name}));var ao=(i,t)=>{let e=Me__default.default.createHash("sha256"),r=i;return e.update(r),e.digest("hex")};var lo=i=>{switch(i){case "mysql":return "mysql";case "mariadb":return "mariadb";case "postgres":case "cockroachdb":return "postgresql";case "sqlite":return "sqlite";case "mssql":return "transactsql";case "oracledb":return "plsql";default:return "sql"}},kt=i=>{if(i==null)return "NULL";if(i instanceof Date)return `'${i.toISOString()}'`;let t=typeof i;return t==="boolean"?i?"TRUE":"FALSE":t==="number"&&Number.isFinite(i)||t==="bigint"?String(i):t==="string"?`'${i.replace(/'/g,"''")}'`:Array.isArray(i)||t==="object"&&Object.keys(i).length>0?`'${JSON.stringify(i).replace(/'/g,"''")}'`:String(i)},tt=(i,t)=>{let e=i;for(let r=0;r<t.length&&e.includes("?");r++)e=e.replace(/\?/,kt(t[r]));for(let r=0;r<t.length;r++){let o=new RegExp(`\\$${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}for(let r=0;r<t.length;r++){let o=new RegExp(`\\@${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}for(let r=0;r<t.length;r++){let o=new RegExp(`:${r+1}(?!\\d)`,"g");e=e.replace(o,kt(t[r]));}return e},rt=(i,t)=>t?i==="mysql"||i==="mariadb"?t.code==="ER_NO_SUCH_TABLE"||t.errno===1146:i==="postgres"||i==="cockroachdb"?t.code==="42P01":i==="sqlite"?/no such table/i.test(String(t.message||"")):i==="mssql"?t.number===208:i==="oracledb"?t.errorNum===942:false:false,Pe=(i,t)=>{let e=i.getDbType(),r;try{r=sqlFormatter.format(t,{...i.inputDetails.queryFormatOptions,language:lo(e)});}catch{try{r=sqlFormatter.format(t,{...i.inputDetails.queryFormatOptions});}catch{r=t;}}return r};var uo=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.column]),n=e.inlineConstraints;if(n&&n.length){let s=[];for(let a of n){let{sql:l}=r.parse([a]);s.push(l);}s.length&&(o+=` ${s.join(" ")}`);}return {sql:`add ${o}`,bindings:[]}}},xl=new uo;var co=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.constraint]);return {sql:`add ${o}`,bindings:[]}}},Il=new co;var mo=class{toSql(t){return {sql:`add primary key (${t.columns.map(o=>`[${o}]`).join(", ")})`,bindings:[]}}},Dl=new mo;var po=class{toSql(t){let e=t,r=new T(this.model,"mssql"),{sql:o}=r.parse([e.newType]),[,...n]=o.trim().split(/\s+/),s=n.join(" "),a="";e.options.nullable!==void 0&&(a=e.options.nullable?" null":" not null");let l=`alter column [${e.column}] ${s}${a}`;if(e.options.dropDefault&&(l=`drop constraint DF_${e.column}, ${l}`),e.options.default!==void 0&&!e.options.dropDefault){let d=e.options.default;d===null?d="null":typeof d=="string"&&(d==="NULL"?d="null":d==="TRUE"||d==="FALSE"?d=d==="TRUE"?"1":"0":d=`'${d}'`),l+=`, add constraint DF_${e.column} default ${d} for [${e.column}]`;}return e.options.unique!==void 0&&e.options.unique&&(l+=`, add constraint UQ_${e.column} unique ([${e.column}])`),{sql:l,bindings:[]}}},Pl=new po;var N=class{constructor(t,e=false){this.currParamIndex=1;this.isRawValue=false;this.keyword=t,this.isRawValue=e;}};var ot=class extends N{constructor(e){super("rename to");this.chainsWith=",";this.canKeywordBeSeenMultipleTimes=false;this.folder="alter_table";this.file="rename_table";this.newName=e;}};var qf=i=>{if(i==null||typeof i!="object"||i instanceof Date)return false;if(Array.isArray(i))return true;let t=Object.getPrototypeOf(i);return t===Object.prototype||t===null},y=class{constructor(t){this.model=t;let e=Qt(t);this.modelColumnsMap=new Map(e.map(r=>[r.columnName,r]));}formatStringColumn(t,e){if(e==="*")return "*";if(e.includes(".")){let[n,s]=e.split(".");if(s==="*")switch(t){case "mysql":case "mariadb":return `\`${n}\`.*`;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${n}".*`;case "mssql":return `[${n}].*`;default:throw new Error(`Unsupported database type: ${t}`)}let a=this.modelColumnsMap.get(s)?.databaseName??L(s,this.model.databaseCaseConvention);switch(t){case "mysql":case "mariadb":return `\`${n}\`.\`${a}\``;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${n}"."${a}"`;case "mssql":return `[${n}].[${a}]`;default:throw new Error(`Unsupported database type: ${t}`)}}let o=this.modelColumnsMap.get(e)?.databaseName??L(e,this.model.databaseCaseConvention);switch(t){case "mysql":case "mariadb":return `\`${o}\``;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${o}"`;case "mssql":return `[${o}]`;default:throw new Error(`Unsupported database type: ${t}`)}}formatStringTable(t,e){e=e.replace(/\s+/g," ").trim();let r="";switch(e.toLowerCase().includes(" as ")&&([e,r]=e.split(" as ")),t){case "mysql":case "mariadb":return `\`${e}\`${r?` as \`${r}\``:""}`;case "postgres":case "cockroachdb":case "sqlite":case "oracledb":return `"${e}"${r?` as "${r}"`:""}`;case "mssql":return `[${e}]${r?` as [${r}]`:""}`;default:return `${e}${r?` as ${r}`:""}`}}async prepareColumns(t,e,r="insert"){if(!t.length)return {columns:t,values:e};let o=[],n=[];for(let s=0;s<t.length;s++){let a=t[s],l=e[s];a!=="*"&&(o.push(a),n.push(l));}await Promise.all(o.map(async(s,a)=>{let l=o[a],d=n[a],u=this.modelColumnsMap.get(l),f=d;u?r==="insert"&&u.prepare?f=await u.prepare(d):r==="update"&&(f=await u.prepare?.(d)??d):qf(d)&&(f=JSON.stringify(d)),n[a]=f;}));for(let s of this.modelColumnsMap.keys())if(!o.includes(s)){let a=this.modelColumnsMap.get(s);if(!a||r==="insert"&&s===this.model.primaryKey&&!a.prepare)continue;if(r==="insert"&&a.prepare||a.autoUpdate){o.push(s);let l=a.prepare?await a.prepare(void 0):void 0;n.push(l??void 0);}}return {columns:o,values:n}}getFromForWriteOperations(t,e){if(typeof e.table=="string")return this.formatStringTable(t,e.table);let r=new T(this.model,t);return Array.isArray(e.table)?`(${r.parse(e.table).sql})`:`(${r.parse([e.table]).sql})`}};var fo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);if(!e.children||!e.children.length)return {sql:"",bindings:[]};if(e.children.length===1&&e.children[0]instanceof ot){let u=e.children[0];return {sql:`EXEC sp_rename '${e.table}', '${u.newName}'`,bindings:[]}}let n=new T(this.model,"mssql"),s=[],a=[];for(let u of e.children){let{sql:f,bindings:c}=n.parse([u]);s.push(f.trim()),a.push(...c);}let l=s.join(", ");return {sql:`${o} ${l}`,bindings:a}}},$l=new fo;var yo=class{toSql(t){return {sql:`drop column [${t.column}]`,bindings:[]}}},El=new yo;var ho=class{toSql(t){return {sql:`drop constraint [${t.constraintName}]`,bindings:[]}}},Bl=new ho;var go=class{toSql(t){return {sql:`drop constraint DF_${t.column}`,bindings:[]}}},vl=new go;var bo=class{toSql(t){let e=t;return M.warn("MSSQL requires the full column type when altering nullability. This operation may need manual adjustment."),{sql:`alter column [${e.column}] null`,bindings:[]}}},kl=new bo;var To=class{toSql(t){return {sql:`drop constraint [${`pk_${t.table}`}]`,bindings:[]}}},Ql=new To;var wo=class{toSql(t){let e=t;return {sql:`sp_rename '${this.model?.table??""}.${e.oldName}', '${e.newName}', 'COLUMN'`,bindings:[]}}},Kl=new wo;var No=class{toSql(t){return {sql:`[${t.newName}]`,bindings:[]}}},Ll=new No;var D=class extends N{constructor(e){super("raw",true);this.canKeywordBeSeenMultipleTimes=true;this.chainsWith=" ";this.currParamIndex=0;this.isRawValue=true;this.folder="raw";this.file="raw";this.rawValue=e;}};var So=class{toSql(t){let e=t,r;return e.defaultValue instanceof D?r=e.defaultValue.rawValue:e.defaultValue==="NULL"||e.defaultValue===null?r="null":e.defaultValue==="TRUE"?r="1":e.defaultValue==="FALSE"?r="0":typeof e.defaultValue=="string"&&e.defaultValue!=="null"&&e.defaultValue!=="1"&&e.defaultValue!=="0"?r=`'${e.defaultValue}'`:r=String(e.defaultValue),{sql:`add constraint DF_${e.column} default ${r} for [${e.column}]`,bindings:[]}}},Wl=new So;var Co=class{toSql(t){let e=t;return M.warn("MSSQL requires the full column type when altering nullability. This operation may need manual adjustment."),{sql:`alter column [${e.column}] not null`,bindings:[]}}},Fl=new Co;var qo=class{toSql(t){return {sql:"",bindings:[]}}},jl=new qo;var Mo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:[]};let o=new y(this.model).formatStringColumn("mssql",S(e.column)),n=e.dataType.toLowerCase();if(n==="char"){let s=e.length??1;return {sql:`${o} char(${s})`,bindings:[]}}if(n==="varchar"){let s=e.length??255;return {sql:`${o} varchar(${s})`,bindings:[]}}if(n==="text"||n==="longtext"||n==="mediumtext"||n==="tinytext")return {sql:`${o} varchar(max)`,bindings:[]};if(n==="uuid")return {sql:`${o} uniqueidentifier`,bindings:[]};if(n==="ulid")return {sql:`${o} varchar(26)`,bindings:[]};if(n==="bigint")return e.autoIncrement?{sql:`${o} bigint identity(1,1)`,bindings:[]}:{sql:`${o} bigint`,bindings:[]};if(n==="tinyint")return {sql:`${o} tinyint`,bindings:[]};if(n==="smallint")return {sql:`${o} smallint`,bindings:[]};if(n==="mediumint")return {sql:`${o} int`,bindings:[]};if(n==="float"||n==="real")return {sql:`${o} real`,bindings:[]};if(n==="double")return {sql:`${o} float`,bindings:[]};if(n==="decimal"||n==="numeric"){let s=e.precision??10,a=e.scale??0;return {sql:`${o} decimal(${s}, ${a})`,bindings:[]}}if(n==="date")return {sql:`${o} date`,bindings:[]};if(n==="year")return {sql:`${o} smallint`,bindings:[]};if(n==="time"){let s=typeof e.precision=="number"?`(${e.precision})`:"";return {sql:`${o} time${s}`,bindings:[]}}if(n==="datetime"||n==="timestamp"){let s=typeof e.precision=="number"?`(${e.precision})`:"",a=`${o} datetime2${s}`;return e.autoCreate&&(a+=" default current_timestamp"),{sql:a,bindings:[]}}if(n==="boolean"||n==="bool")return {sql:`${o} bit`,bindings:[]};if(n==="bytea"||n==="binary"||n==="varbinary"||n==="blob"||n==="longblob"||n==="mediumblob"||n==="tinyblob")return {sql:`${o} varbinary(max)`,bindings:[]};if(n==="json"||n==="jsonb")return {sql:`${o} nvarchar(max)`,bindings:[]};if(n==="enum"){if(e.enumValues&&e.enumValues.length>0){let s=e.enumValues.map(a=>`'${a}'`).join(", ");return {sql:`${o} varchar(255) check (${o} in (${s}))`,bindings:[]}}return {sql:`${o} varchar(255)`,bindings:[]}}return n==="integer"||n==="int"?e.autoIncrement?{sql:`${o} int identity(1,1)`,bindings:[]}:{sql:`${o} int`,bindings:[]}:n==="geometry"?{sql:`${o} geometry`,bindings:[]}:n==="point"?{sql:`${o} geometry`,bindings:[]}:n==="linestring"?{sql:`${o} geometry`,bindings:[]}:n==="polygon"?{sql:`${o} geometry`,bindings:[]}:n==="multipoint"?{sql:`${o} geometry`,bindings:[]}:{sql:`${o} ${n}${e.length?`(${e.length})`:""}`,bindings:[]}}},Ul=new Mo;var Ro=class{toSql(t){return {sql:"",bindings:[]}}},Vl=new Ro;var _o=class{toSql(t){let e=t,r=new y(this.model);if(e.constraintType==="primary_key"){if(e.columns&&e.columns.length){let o=e.constraintName?`constraint [${e.constraintName}] `:"",n=(e.columns??[]).map(s=>r.formatStringColumn("mssql",S(s))).join(", ");return {sql:`${o}primary key (${n})`,bindings:[]}}return {sql:"primary key",bindings:[]}}if(e.constraintType==="unique"){if(e.columns&&e.columns.length>0){let o=e.columns??[],n=e.constraintName?`constraint [${e.constraintName}] `:"",s=o.map(a=>r.formatStringColumn("mssql",S(a))).join(", ");return e.constraintName?{sql:`${n}unique (${s})`,bindings:[]}:{sql:"unique",bindings:[]}}return {sql:"unique",bindings:[]}}if(e.constraintType==="not_null")return {sql:"not null",bindings:[]};if(e.constraintType==="null")return {sql:"null",bindings:[]};if(e.constraintType==="default"){if(e.defaultValue!==void 0){let o=e.defaultValue;return o instanceof D?{sql:`default ${o.rawValue}`,bindings:[]}:o==="NULL"||o===null?{sql:"default null",bindings:[]}:o==="TRUE"?{sql:"default 1",bindings:[]}:o==="FALSE"?{sql:"default 0",bindings:[]}:typeof o=="string"?{sql:`default '${o}'`,bindings:[]}:{sql:`default ${o}`,bindings:[]}}return {sql:"default null",bindings:[]}}if(e.constraintType==="foreign_key"){if(!e.columns||!e.columns.length)return {sql:"",bindings:[]};let o=e.columns.map(d=>r.formatStringColumn("mssql",S(d))).join(", ");if(!e.references)return {sql:"",bindings:[]};let n=r.formatStringTable("mssql",e.references.table),s=e.references.columns.map(d=>r.formatStringColumn("mssql",S(d))).join(", "),l=`${e.constraintName?`constraint [${e.constraintName}] `:""}foreign key (${o}) references ${n}(${s})`;return e.onDelete&&(l+=` on delete ${e.onDelete}`),e.onUpdate&&(l+=` on update ${e.onUpdate}`),{sql:l,bindings:[]}}return e.constraintType==="check"?e.checkExpression?{sql:`${e.constraintName?`constraint [${e.constraintName}] `:""}check (${e.checkExpression})`,bindings:[]}:{sql:"",bindings:[]}:{sql:"",bindings:[]}}},Jl=new _o;var Oo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);if(!e.children||!e.children.length)return {sql:`${o} ()`,bindings:[]};let n=new T(this.model,"mssql"),s=[],a=[];for(let m of e.children){let{sql:g,bindings:b}=n.parse([m]);if(m.folder==="constraint"){let w=s.pop()??"",C=g;if(/not null/i.test(C)||/null/i.test(C)||/default/i.test(C)){let _=`${w} ${C}`.trim();_=_.replace(/(references\s+\[[^\]]+\]\s*\([^)]*\))\s+not null/i,"not null $1"),s.push(_),a.push(...b);continue}s.push(w),s.push(C),a.push(...b);continue}s.push(g),a.push(...b);}for(let m of e.namedConstraints){let{sql:g,bindings:b}=n.parse([m]);s.push(g),a.push(...b);}let l=s.join(", "),d=[];e.dataCompression&&d.push(`DATA_COMPRESSION = ${e.dataCompression}`);let u=e.onFilegroup?` ON [${e.onFilegroup}]`:"",f=e.textImageOn?` TEXTIMAGE_ON [${e.textImageOn}]`:"",c=d.length>0?` WITH (${d.join(", ")})`:"";return {sql:`${o} (${l})${c}${u}${f}`,bindings:a}}},Hl=new Oo;var Ao=class{toSql(t){let e=t;return e.isRawValue&&typeof e.fromNode.table=="string"?{sql:e.fromNode.table,bindings:[]}:{sql:new y(this.model).getFromForWriteOperations("mssql",e.fromNode),bindings:[]}}},zl=new Ao;var xo=class{toSql(t){return {sql:"",bindings:[]}}},Yl=new xo;var Io=class{toSql(t){return M.warn("MSSQL does not support DISTINCT ON. This clause will be ignored."),{sql:"",bindings:[]}}},Gl=new Io;var Do=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table);return {sql:`${e.ifExists?"if exists ":""}${o}`,bindings:[]}}},Zl=new Do;var Po=class{toSql(t){return {sql:`-- MSSQL does not support extensions (extension: ${t.extensionName})`,bindings:[]}}},Xl=new Po;var $o=class{toSql(t){let e=t;if(typeof e.table=="string"){let a=new y(this.model);return e.alias&&e.alias.length>0?{sql:`${a.formatStringTable("mssql",e.table)} as [${e.alias}]`,bindings:[]}:{sql:a.formatStringTable("mssql",e.table),bindings:[]}}let r=Array.isArray(e.table)?e.table:[e.table],n=new T(this.model,"mssql").parse(r),s=e.alias&&e.alias.length?` as [${e.alias}]`:"";return {sql:`(${n.sql})${s}`,bindings:n.bindings}}},ed=new $o;var Eo=class{toSql(t){let e=t;return e.isRawValue?{sql:e.column,bindings:[]}:{sql:new y(this.model).formatStringColumn("mssql",e.column),bindings:[]}}},td=new Eo;var Bo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:e.value};let r=e.currParamIndex,o="",n=[];if(!(e.value instanceof N)&&!Array.isArray(e.value)&&(o=`${new y(this.model).formatStringColumn("mssql",e.column)} ${e.operator} @${r}`,n=[e.value]),Array.isArray(e.value)){let s=e.value.map((a,l)=>`@${r+l}`).join(", ");o=`${new y(this.model).formatStringColumn("mssql",e.column)} ${e.operator} (${s})`,n=e.value;}return e.isNegated&&(o=`not (${o})`),{sql:o.trim(),bindings:n}}},rd=new Bo;var vo=class{toSql(t){let e=t,o=new y(this.model).formatStringTable("mssql",e.table),n=e.columns.map(a=>`[${a}]`).join(", ");return {sql:`${e.unique?"unique ":""}[${e.indexName}] on ${o} (${n})`,bindings:[]}}},od=new vo;var ko=class{toSql(t){let e=t;return {sql:`[${e.indexName}] on [${e.table}]`,bindings:[]}}},nd=new ko;var Qo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.fromNode.table,bindings:[]};let r=new y(this.model),o=r.getFromForWriteOperations("mssql",e.fromNode);if(!e.records.length)return {sql:o,bindings:[]};let n=e.records[0],s=Object.keys(n).filter(c=>n[c]!==void 0);if(!s.length)return {sql:o,bindings:[]};let a=s.map(c=>r.formatStringColumn("mssql",c)).join(", "),l=[],d=[],u=e.currParamIndex;for(let c of e.records){let p=s.map(g=>c[g]),m=[];for(let g of p)g instanceof D?m.push(g.rawValue):(l.push(g),m.push(`@${u++}`));d.push(`(${m.join(", ")})`);}let f=`${o} (${a}) values ${d.join(", ")}`;if(!e.disableReturning)if(e.returning&&e.returning.length){let c=e.returning.map(p=>`inserted.${r.formatStringColumn("mssql",p)}`).join(", ");f=f.replace(") values",`) output ${c} values`);}else {let c=this.getOutputColumns(s,r);f=f.replace(") values",`) output ${c} values`);}return {sql:f,bindings:l}}getOutputColumns(t,e){let r=[...t],o=this.model.primaryKey;return o&&!t.includes(o)&&r.push(o),r.map(n=>`inserted.${e.formatStringColumn("mssql",n)}`).join(", ")}},sd=new Qo;var Ko=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.table,bindings:[]};let r=new y(this.model),o=e.left;o.includes(".")||(o=`${e.table}.${o}`);let n=e.right;n.includes(".")||(n=`${this.model.table}.${n}`);let s=r.formatStringColumn("mssql",o),a=r.formatStringColumn("mssql",n),d=`${r.formatStringTable("mssql",e.table)} on ${s} ${e.on?.operator} ${a}`,u=[];if(e.additionalConditions&&e.additionalConditions.length>0){let f=new T(this.model,"mssql");for(let c of e.additionalConditions){let p=f.parse([c]);if(p.sql){let m=p.sql.replace(/^where\s+/i,"");d+=` and ${m}`,u.push(...p.bindings);}}}return {sql:d,bindings:u}}},id=new Ko;var Lo=class{toSql(t){let e=t;return {sql:`fetch next @${e.currParamIndex} rows only`,bindings:[e.limit]}}},ad=new Lo;var Wo=class{toSql(t){return {sql:"",bindings:[]}}},ld=new Wo;var Fo=class{toSql(t){let e=t;return {sql:`offset @${e.currParamIndex} rows`,bindings:[e.offset]}}},dd=new Fo;var jo=class{toSql(t){let e=t;return e.isRawValue?{sql:e.table,bindings:[]}:(M.warn("MSSQL does not support ON CONFLICT or ON DUPLICATE KEY. Use MERGE statement for upsert operations. This clause will be ignored. Consider using raw queries for MSSQL upserts."),{sql:"",bindings:[]})}},ud=new jo;var Uo=class{toSql(t){let e=t;if(e.isRawValue)return {sql:e.column,bindings:[]};let r=new y(this.model).formatStringColumn("mssql",e.column),o=e.direction.toLowerCase();return {sql:`${r} ${o}`,bindings:[]}}},cd=new Uo;var Vo=class{toSql(t){return {sql:t.rawValue,bindings:[]}}},md=new Vo;var Jo=class{toSql(t){return {sql:`SELECT
|
|
12
12
|
cc.name AS name,
|
|
13
13
|
cc.definition AS expression
|
|
14
14
|
FROM sys.check_constraints cc
|
|
@@ -213,7 +213,7 @@ ORDER BY ordinal_position`,bindings:[]}}},cm=new Vi;var Ji=class{toSql(t){let e=
|
|
|
213
213
|
ELSE
|
|
214
214
|
:result := 0;
|
|
215
215
|
END IF;
|
|
216
|
-
END;`))?.outBinds?.result===1}catch(o){let n=o instanceof Error?o:new Error(String(o));return M.warn(`Oracle lock release may have failed: ${n.message}`),!1}case "sqlite":return !0;default:return M.warn(`Advisory locks not implemented for database type: ${r}`),!0}}catch(o){let n=o instanceof Error?o:new Error(String(o));return M.error(`Failed to release lock: ${n.message||JSON.stringify(o)} (dbType: ${r}, lockKey: ${e}). Full error: ${JSON.stringify(o)}`),false}}hashStringToLockId(e){let r=0;for(let o=0;o<e.length;o++){let n=e.charCodeAt(o);r=(r<<5)-r+n,r=r&r;}return Math.abs(r)}async executeOnSlave(e){let r=this.getSlave();if(!r)return e(this);try{return await e(r)}catch(o){let n=o instanceof Error?o:new Error(String(o));if(this.onSlaveServerFailure)return await this.onSlaveServerFailure(n,{host:r.host,port:r.port,username:r.username,password:r.password,database:r.database,type:r.sqlType}),e(this);throw n}}async connectWithoutSettingPrimary(){this.sqlPool=await xt(this.sqlType,this.inputDetails),this.ownsPool=true;}};Te=new WeakMap,$t(Ae,Te,null);var be=Ae;var Ip=["postgres","cockroachdb"];var Dt=class Dt extends Ie{static get table(){let t=Object.getOwnPropertyDescriptor(this,"table");return t&&"value"in t?t.value:Op(this)}static set table(t){Object.defineProperty(this,"table",{value:t,writable:true,enumerable:true,configurable:true});}static get primaryKey(){return Pp(this)}constructor(t){super(),t&&this.constructor.combineProps(this,t);}static from(t){let e=new this;return this.combineProps(e,t),e}static async all(t={}){return await this.dispatchModelManager(t).find({ignoreHooks:t.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static query(t){return this.dispatchModelManager(t).query()}static async first(t){return this.dispatchModelManager(t).query().one({ignoreHooks:t?.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static async find(t,e){return await this.dispatchModelManager(e).find(t)}static async findOneOrFail(t,e){return await this.dispatchModelManager(e).findOneOrFail(t)}static async findOne(t,e){return await this.dispatchModelManager(e).findOne(t)}static async findBy(t,e,r={}){return await this.dispatchModelManager(r).find({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:{[t]:e}})}static async findOneBy(t,e,r={}){return await this.dispatchModelManager(r).findOne({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:{[t]:e}})}static async findOneByPrimaryKey(t,e={}){return await this.dispatchModelManager(e).findOneByPrimaryKey(t)}static async refresh(t,e={}){let n=await this.dispatchModelManager(e).findOneByPrimaryKey(t);return n||null}static insert(t,e={}){return this.dispatchModelManager(e).insert(t,{ignoreHooks:e.ignoreHooks,returning:e.returning})}static insertMany(t,e={}){let o=this.dispatchModelManager(e);if(!t.length){let n=!e.returning||e.returning.length===0;return new V(()=>({sql:"",bindings:[]}),()=>"",async()=>n?void 0:[])}return o.insertMany(t,{ignoreHooks:e.ignoreHooks,returning:e.returning})}static async sync(t,e,r,o,n={}){if(Array.isArray(r)||(r=[r]),!r.length)return;let s=this,l=br(s).find(m=>m.columnName===t);if(!l)throw new h(`${s.name}::sync`,"RELATION_NOT_FOUND");if(l.type!=="manyToMany")throw new h(`${s.name}::sync`,"RELATION_NOT_MANY_TO_MANY");let d=L(l.leftForeignKey,n.caseConvention||s.databaseCaseConvention),u=L(l.rightForeignKey,n.caseConvention||s.databaseCaseConvention),f=r.map((m,g)=>({[d]:e[s.primaryKey],[u]:m[l.model.primaryKey],...o?o(m,g):{}}));class c extends Dt{static get table(){return l.throughModel}}c.databaseCaseConvention="preserve",c.modelCaseConvention="preserve",await c.dispatchModelManager(n).insertMany(f);}static async updateRecord(t,e,r={}){try{let n=this.dispatchModelManager(r);if(!r.returning||r.returning.length===0){await n.updateRecord(t,e);return}return await n.updateRecord(t,e,{returning:r.returning})}catch(o){throw o instanceof h&&o.message==="MODEL_HAS_NO_PRIMARY_KEY"?new h(`${this.name}::updateRecord`,"MODEL_HAS_NO_PRIMARY_KEY"):o}}static async firstOrInsert(t,e,r={}){r.fullResponse||(r.fullResponse=false);let n=this.dispatchModelManager(r),s=await n.findOne({where:t});if(s)return r.fullResponse?{isNew:false,model:s}:s;let a=await n.insert(e,{returning:["*"]});return r.fullResponse?{isNew:true,model:a}:a}static async upsert(t,e,r={updateOnConflict:true}){let o=this,n=o.dispatchModelManager(r),s=Object.keys(t).length>0,a=!r.returning||r.returning.length===0,l=s?await n.findOne({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:t}):null;if(l){let d=l[o.primaryKey];if(r.updateOnConflict??true){if(a){await n.updateRecord(d,e);return}return await n.updateRecord(d,e,{returning:r.returning})}return a?void 0:l}return await n.insert(e,{ignoreHooks:r.ignoreHooks,returning:r.returning})}static async upsertMany(t,e,r={updateOnConflict:true}){if(!e.length)return [];let o=this,n=o.dispatchModelManager(r),s=!r.returning||r.returning.length===0;if(!e.every(c=>{let p=new Set(Object.keys(c));return t.every(m=>p.has(m))}))throw new h("Model::upsertMany","CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA");let a=Object.keys(e[0]),l=await n.upsertMany(t,a,e,{ignoreHooks:r.ignoreHooks,returning:r.returning,updateOnConflict:r.updateOnConflict??true});if(s)return;let d=o.sqlInstance.getDbType();if(Ip.includes(d))return await we(l,o,r.returning);let u=n.query();r.returning?.length&&u.select(...r.returning);let f=new Map;return t.forEach(c=>{e.forEach(p=>{f.set(c,[...f.get(c)||[],p[c]]);});}),u.where(c=>{t.forEach(p=>{c.orWhereIn(p,f.get(p)||[]);});}),u.many({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static async deleteRecord(t,e){return this.dispatchModelManager(e).deleteRecord(t)}static async save(t,e={}){let r=this,o=r.primaryKey;if(!o)throw new h(r.name+"::save","MODEL_HAS_NO_PRIMARY_KEY");let n=t[o],s=n?{[o]:n}:{},a=t;return await r.upsert.call(this,s,a,{updateOnConflict:true,returning:e.returning,...e})}static async softDelete(t,e,r){let o=this,{column:n=o.softDeleteColumn,value:s=o.softDeleteValue}=e||{},a={[n]:s},l=o.dispatchModelManager({trx:r?.trx,connection:r?.connection});if(!r?.returning||r.returning.length===0){await l.updateRecord(t,a);return}return await l.updateRecord(t,a,{returning:r.returning})}static async truncate(t={}){return this.dispatchModelManager(t).query().truncate()}static async getTableInfo(){let t=this;return t.establishConnection(),t.sqlInstance.getTableInfo(t.table)}static async getIndexInfo(){let t=this;return t.establishConnection(),t.sqlInstance.getIndexInfo(t.table)}static async getTableSchema(){let t=this;return t.establishConnection(),t.sqlInstance.getTableSchema(t.table)}static combineProps(t,e){for(let r in e)Object.assign(t,{[r]:e[r]});}static getColumns(){return Qt(this)}static getRelations(){return Dp(this)}static getIndexes(){return $p(this)}static getUniques(){return Ep(this)}static getChecks(){return Bp(this)}static column(t,...e){q(...e)(this.prototype,t);}static dateColumn(t,...e){q.date(...e)(this.prototype,t);}static datetimeColumn(t,...e){q.datetime(...e)(this.prototype,t);}static timestampColumn(t,...e){q.timestamp(...e)(this.prototype,t);}static timeColumn(t,...e){q.time(...e)(this.prototype,t);}static booleanColumn(t,...e){q.boolean(...e)(this.prototype,t);}static jsonColumn(t,...e){q.json(...e)(this.prototype,t);}static uuidColumn(t,...e){q.uuid(...e)(this.prototype,t);}static ulidColumn(t,...e){q.ulid(...e)(this.prototype,t);}static integerColumn(t,...e){q.integer(...e)(this.prototype,t);}static floatColumn(t,...e){q.float(...e)(this.prototype,t);}static incrementColumn(t,...e){q.increment(...e)(this.prototype,t);}static bigIncrementColumn(t,...e){q.bigIncrement(...e)(this.prototype,t);}static encryptionSymmetricColumn(t,...e){q.encryption.symmetric(...e)(this.prototype,t);}static encryptionAsymmetricColumn(t,...e){q.encryption.asymmetric(...e)(this.prototype,t);}static hasOne(t,...e){Br(...e)(this.prototype,t);}static hasMany(t,...e){vr(...e)(this.prototype,t);}static belongsTo(t,...e){Er(...e)(this.prototype,t);}static manyToMany(t,...e){kr(...e)(this.prototype,t);}static establishConnection(){let t=be.instance;if(!t)throw new h("sqlInstance not initialized, did you defined it in SqlDataSource.connect static method?","CONNECTION_NOT_ESTABLISHED");this.sqlInstance=t;}static dispatchModelManager(t){let e;if(t?.connection)e=t.connection.getModelManager(this);else if(t?.trx)e=t.trx.sql.getModelManager(this);else {let r=this;r.establishConnection(),e=r.sqlInstance.getModelManager(r);}return t?.replicationMode&&e.setReplicationMode(t.replicationMode),e}};Dt.softDeleteColumn="deletedAt",Dt.softDeleteValue=Ye();var U=Dt;var Ne=class{constructor(t,e){this.model=U;this.columnName="";this.relatedModel="";this.model=t,this.columnName=e,this.relatedModel=this.model.table;}};var Qr=class extends Ne{constructor(t,e,r){super(t,e),this.foreignKey=r,this.type="belongsTo";}};var Kr=class extends Ne{constructor(e,r,o){super(e,r);this.type="hasMany";this.foreignKey=o,this.type="hasMany";}};var Lr=class extends Ne{constructor(t,e,r){super(t,e),this.foreignKey=r,this.type="hasOne";}};var Wr=class extends Ne{constructor(e,r,o){super(e,r);this.type="manyToMany";this.primaryModel=o.primaryModel,this.relatedModel=e.table,this.throughModel=o.throughModel,this.leftForeignKey=o.leftForeignKey,this.rightForeignKey=o.rightForeignKey;}};function rl(i,t){return e=>{let r=Array.isArray(i)?i:[i],o=Q.getMetadata(nr,e.prototype)||[];o.push({columns:r,name:t??ar(e.table,r.join("_"))}),Q.defineMetadata(nr,o,e.prototype);}}function ol(i,t){return e=>{let r=Array.isArray(i)?i:[i],o=Q.getMetadata(sr,e.prototype)||[];o.push({columns:r,name:t??ce(e.table,r.join("_"))}),Q.defineMetadata(sr,o,e.prototype);}}function nl(i,t){return e=>{let r=Q.getMetadata(ir,e.prototype)||[];r.push({expression:i,name:t??wp(e.table,i)}),Q.defineMetadata(ir,r,e.prototype);}}function zk(i){return t=>{let e=t,r=e.query;e.query=function(...o){let n=r.bind(this).call(this,...o);return i(n),n};}}function q(i={primaryKey:false}){let t=i?.primaryKey??false;return (e,r)=>{let o=e.constructor;if(t){if(Q.getMetadata(at,e))throw new h("ModelDecorator::column","MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED");Q.defineMetadata(at,r,e),Q.defineMetadata(at,r,e.constructor);}let n=i.databaseName??L(r,o.databaseCaseConvention),s={columnName:r,serialize:i.serialize,prepare:i.prepare,hidden:i.hidden,isPrimary:t,primaryKeyConstraintName:i.primaryKeyConstraintName??Ee(o.table,r),autoUpdate:i.autoUpdate,databaseName:n,openApi:i.openApi,type:i.type,length:i?.length,precision:i?.precision,scale:i?.scale,withTimezone:i?.withTimezone,constraints:{nullable:i.nullable,default:i.default}},a=Q.getMetadata(or,e)||[];a.push(s),Q.defineMetadata(or,a,e);}}q.primary=Lf;q.date=oy;q.datetime=ny;q.timestamp=sy;q.time=iy;q.boolean=ry;q.json=ay;q.uuid=Vf;q.ulid=Jf;q.integer=Ff;q.bigInteger=Yf;q.float=Wf;q.decimal=Gf;q.increment=jf;q.bigIncrement=Uf;q.string=Hf;q.text=zf;q.binary=Zf;q.enum=Xf;q.encryption={symmetric:ey,asymmetric:ty};function Lf(i={}){return q({...i,primaryKey:true})}function Wf(i={}){return q({type:"float",...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:typeof t=="string"?Number.parseInt(t):Number.parseFloat(t)},openApi:{type:"number",format:"float",description:"A floating point number",...i.openApi||{}}})}function Ff(i={}){return q({type:"integer",...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:typeof t=="string"?+t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An integer number",...i.openApi||{}}})}function jf(i={}){return q({type:"increment",...i,primaryKey:true,nullable:false,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An auto-incrementing integer number",...i.openApi||{}}})}function Uf(i={}){return q({type:"bigIncrement",...i,primaryKey:true,nullable:false,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An auto-incrementing bigint number",...i.openApi||{}}})}function Vf(i={}){return q({type:"uuid",...i,prepare:t=>t||Me__default.default.randomUUID(),openApi:{type:"string",format:"uuid",description:"uuid (Universally Unique Identifier)",...i.openApi||{}}})}function Jf(i={}){return q({type:"ulid",...i,prepare:t=>t||Nl(),openApi:{type:"string",format:"ulid",description:"ulid (Universally Unique Lexicographically Sortable Identifier)",...i.openApi||{}}})}function Hf(i={}){return q({type:"string",...i,openApi:{type:"string",description:"A string value",...i.openApi||{}}})}function zf(i={}){return q({type:"longtext",...i,openApi:{type:"string",description:"A text value",...i.openApi||{}}})}function Yf(i={}){return q({type:"bigint",...i,serialize:t=>{if(t!==void 0){if(t===null)return null;if(typeof t=="number")return t;if(typeof t=="string")return Number.parseInt(t);if(typeof t=="bigint")return Number(t)}},openApi:{type:"integer",format:"int64",description:"A bigint number",...i.openApi||{}}})}function Gf(i={}){return q({type:"decimal",precision:i.precision??10,scale:i.scale??2,...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseFloat(t)},openApi:{type:"number",format:"double",description:"A decimal number",...i.openApi||{}}})}function Zf(i={}){return q({type:"binary",...i,openApi:{type:"string",format:"binary",description:"Binary data",...i.openApi||{}}})}function Xf(i,t={}){return q({type:i,...t,openApi:{type:"string",enum:i,description:"An enum value",...t.openApi||{}}})}function ey(i){return q({...i,prepare:t=>t&&gl(i.key,t),serialize:t=>t&&bl(i.key,t)})}function ty(i){return q({...i,prepare:t=>t&&Tl(i.publicKey,t),serialize:t=>t&&wl(i.privateKey,t)})}function ry(i={}){return q({type:"boolean",...i,serialize:t=>!!t,prepare:t=>!!t,openApi:{type:"boolean",description:"A boolean value",...i.openApi||{}}})}function oy(i={}){let{timezone:t="UTC",autoUpdate:e=false,autoCreate:r=false,prepare:o,serialize:n,...s}=i,a=d=>d?e?se(new Date,"DATE_ONLY",t):typeof d=="string"?d:se(d,"DATE_ONLY",t):r?se(new Date,"DATE_ONLY",t):null,l=d=>{if(d!==void 0)return d===null?null:ft(d,void 0,t)};return q({type:"date",...s,autoUpdate:e,prepare:d=>{let u=a(d);return o?o(u):u},serialize:d=>{let u=l(d);return n?n(u):u},openApi:{type:"string",format:"date",description:"YYYY-MM-DD",...s.openApi||{}}})}function ny(i={}){let{timezone:t,withTimezone:e,autoUpdate:r=false,autoCreate:o=false,prepare:n,serialize:s,...a}=i,l=t??"UTC",d=e??t!==void 0,u=c=>c?r?se(new Date,"ISO",l):typeof c=="string"?c:se(c,"ISO",l):o?se(new Date,"ISO",l):null,f=c=>{if(c!==void 0)return c===null?null:ft(c,void 0,l)};return q({type:"datetime",...a,withTimezone:d,autoUpdate:r,prepare:c=>{let p=u(c);return n?n(p):p},serialize:c=>{let p=f(c);return s?s(p):p},openApi:{type:"string",format:"date-time",description:"YYYY-MM-DD HH:mm:ss",...a.openApi||{}}})}function sy(i={}){let{timezone:t,withTimezone:e,autoUpdate:r=false,autoCreate:o=false,prepare:n,serialize:s,...a}=i,l=t??"UTC",d=e??t!==void 0,u=c=>c?r?se(new Date,"TIMESTAMP",l):typeof c=="string"?c:se(c,"TIMESTAMP",l):o?se(new Date,"TIMESTAMP",l):null,f=c=>{if(c!==void 0)return c===null?null:ft(c,void 0,l)};return q({type:"timestamp",...a,withTimezone:d,autoUpdate:r,prepare:c=>{let p=u(c);return n?n(p):p},serialize:c=>{let p=f(c);return s?s(p):p},openApi:{type:"string",format:"date-time",description:"Unix timestamp",...a.openApi||{}}})}function iy(i={}){let{timezone:t="UTC",autoUpdate:e=false,autoCreate:r=false,prepare:o,serialize:n,...s}=i,a=d=>d?e?se(new Date,"TIME_ONLY",t):typeof d=="string"?d:se(d,"TIME_ONLY",t):r?se(new Date,"TIME_ONLY",t):null,l=d=>{if(d!==void 0)return d===null?null:ft(d,void 0,t)};return q({type:"time",...s,autoUpdate:e,prepare:d=>{let u=a(d);return o?o(u):u},serialize:d=>{let u=l(d);return n?n(u):u},openApi:{type:"string",format:"time",description:"HH:mm:ss",...s.openApi||{}}})}function ay(i={}){return q({type:"jsonb",...i,serialize:t=>typeof t=="string"?JSON.parse(t):t,prepare:t=>typeof t!="string"?JSON.stringify(t):t,openApi:{type:"object",description:"A JSON object",...i.openApi||{}}})}function Qt(i){try{return Q.getMetadata(or,i.prototype)||[]}catch{return []}}function Er(i,t,e){return((r,o)=>{let n=()=>$e(i().table),s=()=>{let d=r.constructor.table,u=t||n();return ee(d,u,i().table)},a={type:"belongsTo",columnName:o,model:i,foreignKey:t?String(t):n,constraintName:e?.constraintName??s,onUpdate:e?.onUpdate,onDelete:e?.onDelete},l=Q.getMetadata(he,r)||[];l.push(a),Q.defineMetadata(he,l,r);})}function Br(i,t){return((e,r)=>{let o=()=>$e(e.constructor.table),n={type:"hasOne",columnName:r,model:i,constraintName:"None",foreignKey:t?String(t):o},s=Q.getMetadata(he,e)||[];s.push(n),Q.defineMetadata(he,s,e);})}function vr(i,t){return((e,r)=>{let o=()=>$e(e.constructor.table),n={type:"hasMany",columnName:r,model:i,constraintName:"None",foreignKey:t?String(t):o},s=Q.getMetadata(he,e)||[];s.push(n),Q.defineMetadata(he,s,e);})}function kr(i,t,e,r){return((o,n)=>{let{leftForeignKey:s,rightForeignKey:a}=e??{},l=typeof t!="string",d=typeof t=="string"?t:()=>t().table,u=o.constructor.table,f=()=>$e(u),c=()=>$e(i().table),p=()=>ee(S(d),s?String(s):f()),m={type:"manyToMany",columnName:n,model:i,constraintName:r?.constraintName??p,foreignKey:s?String(s):f,onDelete:r?.onDelete,onUpdate:r?.onUpdate,manyToManyOptions:{primaryModel:u,throughModel:d,leftForeignKey:s?String(s):f,rightForeignKey:a?String(a):c,wasModelProvided:l}},g=Q.getMetadata(he,o)||[];g.push(m),Q.defineMetadata(he,g,o);})}function Dp(i){return Q.getMetadata(he,i.prototype)||[]}function br(i){return (Q.getMetadata(he,i.prototype)||[]).map(e=>{let{type:r,model:o,columnName:n,foreignKey:s}=e,a=S(s),l=o();switch(r){case "belongsTo":return new Qr(l,n,a);case "hasOne":return new Lr(l,n,a);case "hasMany":return new Kr(l,n,a);case "manyToMany":if(!e.manyToManyOptions)throw new h("ModelDecorator::getRelations","MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL");let d=o();return new Wr(d,n,{primaryModel:e.manyToManyOptions.primaryModel,throughModel:S(e.manyToManyOptions.throughModel),leftForeignKey:S(e.manyToManyOptions.leftForeignKey),rightForeignKey:S(e.manyToManyOptions.rightForeignKey)});default:throw new h("ModelDecorator::getRelations",`UNKNOWN_RELATION_TYPE_${r}`)}})}function Pp(i){return Q.getMetadata(at,i)||Q.getMetadata(at,i.prototype)}function $p(i){return Q.getMetadata(nr,i.prototype)||[]}function Ep(i){return Q.getMetadata(sr,i.prototype)||[]}function Bp(i){return Q.getMetadata(ir,i.prototype)||[]}function H(i){return {_phantom:void 0,_apply:i}}function Fr(i){return {_phantom:void 0,_apply:i}}function G(i={}){return H((t,e)=>{q(i)(t,e);})}G.primary=function(t={}){return H((e,r)=>{q.primary(t)(e,r);})};G.string=function(t){return H((e,r)=>{q.string(t??{})(e,r);})};G.text=function(t){return H((e,r)=>{q.text(t??{})(e,r);})};G.integer=function(t){return H((e,r)=>{q.integer(t??{})(e,r);})};G.bigInteger=function(t){return H((e,r)=>{q.bigInteger(t??{})(e,r);})};G.float=function(t){return H((e,r)=>{q.float(t??{})(e,r);})};G.decimal=function(t){return H((e,r)=>{q.decimal(t??{})(e,r);})};G.increment=function(t={}){return H((e,r)=>{q.increment(t)(e,r);})};G.bigIncrement=function(t={}){return H((e,r)=>{q.bigIncrement(t)(e,r);})};G.boolean=function(t){return H((e,r)=>{q.boolean(t??{})(e,r);})};G.date=function(t){return H((e,r)=>{q.date(t??{})(e,r);})};G.datetime=function(t){return H((e,r)=>{q.datetime(t??{})(e,r);})};G.timestamp=function(t){return H((e,r)=>{q.timestamp(t??{})(e,r);})};G.time=function(t){return H((e,r)=>{q.time(t??{})(e,r);})};G.json=function(t){return H((e,r)=>{q.json(t??{})(e,r);})};G.uuid=function(t){return H((e,r)=>{q.uuid(t??{})(e,r);})};G.ulid=function(t){return H((e,r)=>{q.ulid(t??{})(e,r);})};G.binary=function(t){return H((e,r)=>{q.binary(t??{})(e,r);})};G.enum=function(t,e){return H((r,o)=>{q.enum(t,e??{})(r,o);})};G.encryption={symmetric(i){return H((t,e)=>{q.encryption.symmetric(i)(t,e);})},asymmetric(i){return H((t,e)=>{q.encryption.asymmetric(i)(t,e);})}};var ly=G,dy={hasOne(i,t,e){return Fr((r,o)=>{Br(()=>i(r.constructor),t)(r,o);})},hasMany(i,t,e){return Fr((r,o)=>{vr(()=>i(r.constructor),t)(r,o);})},belongsTo(i,t,e){return Fr((r,o)=>{Er(()=>i(r.constructor),t,e)(r,o);})},manyToMany(i,t,e,r){return Fr((o,n)=>{kr(()=>i(o.constructor),t,e,r)(o,n);})}};function uy(i,t){let{columns:e,relations:r,indexes:o,uniques:n,checks:s,hooks:a,options:l}=t;class d extends U{}d.table=i,l?.modelCaseConvention&&(d.modelCaseConvention=l.modelCaseConvention),l?.databaseCaseConvention&&(d.databaseCaseConvention=l.databaseCaseConvention),l?.softDeleteColumn&&(d.softDeleteColumn=l.softDeleteColumn),l?.softDeleteValue!==void 0&&(d.softDeleteValue=l.softDeleteValue);for(let[u,f]of Object.entries(e))f._apply(d.prototype,u);if(r)for(let[u,f]of Object.entries(r))f._apply(d.prototype,u);if(o)for(let u of o)cy(d,u);if(n)for(let u of n)my(d,u);if(s)for(let u of s)py(d,u);return a&&(a.beforeFetch&&(d.beforeFetch=a.beforeFetch),a.afterFetch&&(d.afterFetch=a.afterFetch),a.beforeInsert&&(d.beforeInsert=a.beforeInsert),a.beforeInsertMany&&(d.beforeInsertMany=a.beforeInsertMany),a.beforeUpdate&&(d.beforeUpdate=a.beforeUpdate),a.beforeDelete&&(d.beforeDelete=a.beforeDelete)),d}function cy(i,t){Array.isArray(t)?rl(t)(i):rl(t.columns,t.name)(i);}function my(i,t){Array.isArray(t)?ol(t)(i):ol(t.columns,t.name)(i);}function py(i,t){typeof t=="string"?nl(t)(i):nl(t.expression,t.name)(i);}var sl=class{constructor(t,e){this.typeofModel=t,this.modelData=e;}merge(t){this.modelData={...this.modelData,...t};}async create(t){if(t<=0)return [];let e=this.typeofModel;if(t===1)return await e.insert(this.modelData,{returning:["*"]});let r=Array.from({length:t});return await e.insertMany(r.map(()=>({...this.modelData})),{returning:["*"]})}},fy=(i,t)=>new sl(i,t);function yy(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.column("id",{openApi:{type:"number",required:true},...o,primaryKey:true});let n=s;return n}function hy(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.column("id",{openApi:{type:"number",required:true},...o,primaryKey:true});let n=s;return n}function vp(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.ulidColumn("id",{type:"ulid",openApi:{type:"string",format:"ulid",required:true},...o,primaryKey:true});let n=s;return n}var gy=vp;function kp(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.uuidColumn("id",{type:"uuid",openApi:{type:"string",format:"uuid",required:true},...o,primaryKey:true});let n=s;return n}var by=kp;function Ty(i,t){let e=s=>typeof s=="function",r=e(i)?i:U,o=e(i)?t:i;class n extends r{}return U.datetimeColumn("createdAt",{type:"datetime",autoCreate:true,openApi:{type:"string",format:"date-time",required:true},...o?.createdAt}),U.datetimeColumn("updatedAt",{autoUpdate:true,openApi:{type:"string",format:"date-time",required:true},...o?.updatedAt}),U.datetimeColumn("deletedAt",{nullable:true,openApi:{type:"string",format:"date-time",required:false},...o?.deletedAt}),n}var Qp=i=>{let t=()=>{for(let[r,o]of Object.entries(i))U.column(r,o);};function e(r){var s;let o=r??U;return s=class extends o{},t(),s}return e},wy=Qp;var Kp=class{constructor(t){this.ioRedisOptions=t;}async getClient(){if(this.redisInstance)return this.redisInstance;let{default:t}=await import('ioredis').catch(()=>{throw M.error("RedisCacheAdapter::getClient ioredis driver not found and required for the RedisCacheAdapter"),new K("ioredis")});return this.redisInstance=new t(this.ioRedisOptions),this.redisInstance}async get(t){let r=await(await this.getClient()).get(t);if(r!=null)return this.deserializeData(r)}async set(t,e,r){let o=await this.getClient(),n=this.serializeData(e);if(n){if(r){await o.set(t,n,"PX",r);return}await o.set(t,n);}}async invalidate(t){await(await this.getClient()).del(t);}async invalidateAll(t){let e=await this.getClient(),r=await e.keys(`${t}:*`);for(let o of r)await e.del(o);}serializeData(t){if(t!=null){if(typeof t=="string")return t;if(Buffer.isBuffer(t))return t.toString("base64");if(typeof t=="object"||Array.isArray(t))try{return JSON.stringify(t)}catch(e){throw M.error("RedisCacheAdapter::set failed to serialize data"),e}return String(t)}}deserializeData(t){try{return JSON.parse(t)}catch{return t}}async disconnect(){this.redisInstance&&await this.redisInstance.quit();}};var{plural:Sy}=Of__default.default;function Lp(i){let t=i.name,e=L(t,"snake");return Sy(e)}function Wp(){return {$annotations:{}}}var mt=class extends Ie{static get collection(){return this._collection||Lp(this)}static query(t={}){return this.dispatchModelManager(t).query()}static rawCollection(){return this.mongoInstance.getCurrentConnection().db().collection(this.collection)}static async find(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).find(t)}static async findOne(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).findOne(t)}static async findOneOrFail(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).findOneOrFail(t)}static async insert(t,e={}){return await this.dispatchModelManager(e).insert(t)}static async insertMany(t,e={}){return await this.dispatchModelManager(e).insertMany(t)}static async updateRecord(t,e={}){return await this.dispatchModelManager(e).updateRecord(t)}static async deleteRecord(t,e={}){await this.dispatchModelManager(e).deleteRecord(t);}static establishConnection(){let t=Pt.getInstance();if(!t)throw new h("Collection::establishConnection","CONNECTION_NOT_ESTABLISHED");this.mongoInstance=t;}static dispatchModelManager(t){if(t.useConnection)return t.useConnection.getModelManager(this,t.useConnection);if(t.session)return this.mongoInstance.getModelManager(this,this.mongoInstance,t.session);let e=this;return e.establishConnection(),e.mongoInstance.getModelManager(e,e.mongoInstance)}static beforeFetch(t){}static beforeInsert(t){return t}static beforeUpdate(t){}static beforeDelete(t){}static property(t){Xr()(this.prototype,t);}static async afterFetch(t){return t}};fl([Xr()],mt.prototype,"id");async function Ke(i,t,e){if(!t)return null;let r=Wp(),o=hl(i);return (!e||!e.length)&&(e=o),e.includes("id")||e.push("id"),r.$annotations||(r.$annotations={}),await Promise.all(Object.keys(t).map(async n=>{if(n==="_id"){r.id=t._id?.toString();return}if(!o.includes(n)){let a=L(n,i.modelCaseConvention);r.$annotations[a]=t[n];return}let s=L(n,i.modelCaseConvention);r[s]=t[n];})),Object.keys(r.$annotations).length||delete r.$annotations,await Promise.all(e.map(async n=>{if(n!=="id"&&!t.hasOwnProperty(n)){let s=L(n,i.modelCaseConvention);r[s]=null;}})),r}async function jr(i,t,e){return (await Promise.all(t.map(async o=>await Ke(i,o,e)))).filter(o=>o!==null)}var Ur=class{constructor(t,e,r,o=false){this.model=t,this.idObject={},this.whereObject={},this.logs=o,this.session,this.mongoDataSource=e,this.collection=this.mongoDataSource.getCurrentConnection().db().collection(this.model.collection);}async one(t={throwErrorOnNull:false}){t.ignoreHooks?.includes("beforeFetch")||this.model.beforeFetch(this);let e={...this.whereObject};Object.keys(this.idObject).length&&(e._id=this.idObject);let r=await this.collection.findOne(e,{projection:this.selectObject,session:this.session}),o=await Ke(this.model,r,this.selectFields);return t.ignoreHooks?.includes("afterFetch")?o:(await this.model.afterFetch([o]))[0]}async oneOrFail(t={throwErrorOnNull:true}){let e=await this.one(t);if(!e)throw new h("MongoQueryBuilder::oneOrFail","ROW_NOT_FOUND");return e}async many(t={}){t.ignoreHooks?.includes("beforeFetch")||this.model.beforeFetch(this);let e={...this.whereObject};Object.keys(this.idObject).length&&(e._id=this.idObject);let r=await this.collection.find(e,{projection:this.selectFields,sort:this.sortObject,limit:this.limitNumber,skip:this.offsetNumber,session:this.session}).toArray(),o=await jr(this.model,r,this.selectFields);return t.ignoreHooks?.includes("afterFetch")?o:await this.model.afterFetch(o)}async insert(t,e={}){e.ignoreHooks||this.model.beforeInsert(t);let r=await this.collection.insertOne(t,{session:this.session});if(!e.returning)return {id:r.insertedId.toString()};let o=await this.collection.findOne({_id:r.insertedId});return await Ke(this.model,o,this.selectFields)}async insertMany(t,e={}){e.ignoreHooks||this.model.beforeInsert(t);let r=await this.collection.insertMany(t,{session:this.session});if(!e.returning)return Object.values(r.insertedIds).map(n=>({id:n.toString()}));let o=await this.collection.find({_id:{$in:Object.values(r.insertedIds)}}).toArray();return await jr(this.model,o,this.selectFields)}async update(t,e={}){if(e.ignoreHooks||this.model.beforeUpdate(this),(await this.collection.updateMany({_id:this.idObject,...this.whereObject},{$set:t,session:this.session})).modifiedCount===0)return [];let o=await this.collection.find({_id:Object.keys(this.idObject).length?this.idObject:void 0,...this.whereObject},{projection:this.selectFields}).toArray();return await jr(this.model,o,this.selectFields)}async delete(t={}){t.ignoreHooks||this.model.beforeDelete(this),await this.collection.deleteMany(this.whereObject,{session:this.session});}async count(t={}){return t.ignoreHooks||this.model.beforeFetch(this),this.collection.countDocuments(this.whereObject,{session:this.session})}select(t){return this.selectFields=t,this.selectObject=t.reduce((e,r)=>(e[r]=1,e),{}),this}where(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb");if(t==="id")return this.idObject={$eq:new s.ObjectId(n)},this;let a={[t]:{[o]:n}};return this.whereObject?(this.whereObject.$and||(this.whereObject.$and=[]),this.whereObject.$and.push(a)):this.whereObject={$and:[a]},this}andWhere(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb"),a={[t]:{[o]:n}};return t==="id"?(this.idObject={$eq:new s.ObjectId(n)},this):(this.whereObject?(this.whereObject.$and||(this.whereObject.$and=[]),this.whereObject.$and.push(a)):this.whereObject={$and:[a]},this)}orWhere(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb"),a={[t]:{[o]:n}};return t==="id"?(this.idObject={$eq:new s.ObjectId(n)},this):(this.whereObject?(this.whereObject.$or||(this.whereObject.$or=[]),this.whereObject.$or.push(a)):this.whereObject={$or:[a]},this)}whereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereRaw(t){return this.whereObject={...this.whereObject,...t},this}andRawWhere(t){return this.whereObject={...this.whereObject,...t},this}orRawWhere(t){return this.whereObject.$or||(this.whereObject.$or=[]),this.whereObject.$or.push(t),this}sortById(t){return this.sortObject={_id:t},this}sort(t){return typeof t=="number"?(this.sortObject={_id:t},this):typeof t=="string"?(this.sortObject={[t]:1},this):Array.isArray(t)?(this.sortObject=t.reduce((e,r)=>{if(typeof r=="string")return e[r]=1,e;let o=Object.keys(r)[0],n=Object.values(r)[0];return e[o]=+n,e},{}),this):(this.sortObject=t,this)}limit(t){return this.limitNumber=t,this}offset(t){return this.offsetNumber=t,this}};var Vr=class{constructor(t,e,r,o=false){this.logs=o,this.session=r,this.mongoDataSource=e,this.collection=mt,this.mongoClient=this.mongoDataSource.getCurrentConnection(),this.collectionInstance=this.mongoClient.db().collection(this.collection.collection);}async find(t){let e=this.query();return t?(t.select&&e.select(t.select),t.where&&Object.entries(t.where).forEach(([r,o])=>{e.where(r,o);}),t.sort&&e.sort(t.sort),t.limit&&e.limit(t.limit),t.offset&&e.offset(t.offset),e.many({ignoreHooks:t.ignoreHooks})):e.many()}async findOne(t){let e=this.query();return t?(t.where&&Object.entries(t.where).forEach(([r,o])=>{e.where(r,o);}),e.one({ignoreHooks:t.ignoreHooks})):e.oneOrFail()}async findOneOrFail(t){let e=this.query();if(!t)return e.oneOrFail();t.select&&e.select(t.select),t.where&&Object.entries(t.where).forEach(([o,n])=>{e.where(o,n);});let r=await e.one({ignoreHooks:t.ignoreHooks});if(r===null)throw t.customError?t.customError:new h("CollectionManager::findOneOrFail No record found","ROW_NOT_FOUND");return r}query(){return new Ur(this.collection,this.mongoDataSource,this.session,this.logs)}async insert(t,e={}){e.ignoreHooks||this.collection.beforeInsert(t);let o=(await this.collectionInstance.insertOne(t)).insertedId,n=await this.collectionInstance.findOne({_id:o},{session:this.session});return await Ke(this.collection,n)}async insertMany(t,e={}){e.ignoreHooks||t.forEach(s=>{this.collection.beforeInsert(s);});let o=(await this.collectionInstance.insertMany(t)).insertedIds,n=await this.collectionInstance.find({_id:{$in:Object.values(o)}},{session:this.session}).toArray();return Promise.all(n.map(async s=>await Ke(this.collection,s)))}async updateRecord(t){let e=t.id;if(!e)throw new h("CollectionManager::updateRecord","ROW_NOT_FOUND");let r=await import('mongodb');if((await this.collectionInstance.updateOne({_id:new r.ObjectId(e)},{$set:t})).modifiedCount===0)throw new h("CollectionManager::updateRecord","ROW_NOT_FOUND");let n=await this.collectionInstance.findOne({_id:new r.ObjectId(e)},{session:this.session});return await Ke(this.collection,n)}async deleteRecord(t){let e=t.id;if(!e)throw new h("CollectionManager::deleteRecord","ROW_NOT_FOUND");let r=await import('mongodb');return await this.collectionInstance.deleteOne({_id:new r.ObjectId(e)},{session:this.session}),t}};var Le=class Le extends et{constructor(e){super({type:"mongo",url:e?.url,logs:e?.logs});this.mongoClient=null;this.isConnected=false,this.mongoOptions=e?.options,this.url||(this.url=I.MONGO_URL);}async connect(){if(!this.url)throw new h("MongoDataSource::connect url is required to connect to mongo database and was not provided in the options nor the environment variables","REQUIRED_VALUE_NOT_SET");let e=(await de.getDriver("mongo")).client;this.mongoClient=new e.MongoClient(this.url,this.mongoOptions),await this.mongoClient.connect(),this.isConnected=true,Le.instance=this;}async connectWithoutSettingPrimary(){if(!this.url)throw new h("MongoDataSource::connect url is required to connect to mongo database and was not provided in the options nor the environment variables","REQUIRED_VALUE_NOT_SET");let e=(await de.getDriver("mongo")).client;this.mongoClient=new e.MongoClient(this.url,this.mongoOptions),await this.mongoClient.connect(),this.isConnected=true;}getCurrentConnection(){if(!this.mongoClient)throw new h("MongoDataSource::getCurrentConnection mongo database connection not established","CONNECTION_NOT_ESTABLISHED");return this.mongoClient}static async connectToSecondarySource(e){let r=new Le(e);return await r.connectWithoutSettingPrimary(),r}static getInstance(){if(!Le.instance)throw new h("MongoDataSource::getInstance mongo database connection not established","CONNECTION_NOT_ESTABLISHED");return Le.instance}startSession(){if(!this.mongoClient)throw new h("MongoDataSource::startSession mongo database connection not established","CONNECTION_NOT_ESTABLISHED");let e=this.mongoClient.startSession();return e.startTransaction(),e}static async disconnect(){if(!this.instance)throw new h("MongoDataSource::disconnect mongo database connection not established","CONNECTION_NOT_ESTABLISHED");await this.instance.disconnect();}async disconnect(){this.mongoClient&&await this.mongoClient.close(),this.isConnected=false;}async closeConnection(){await this.disconnect();}static async closeConnection(){await this.disconnect();}static async useConnection(e,r){let o=new Le(e);await o.connectWithoutSettingPrimary();try{await r(o);}finally{await o.disconnect();}}static query(e){return this.getInstance().query(e)}query(e){if(!this.isConnected)throw new h("MongoDataSource::query","CONNECTION_NOT_ESTABLISHED");return this.getModelManager({_collection:e},this).query()}getModelManager(e,r,o){return new Vr(e,r,o,this.logs)}};Le.instance=null;var Pt=Le;var Z=class Z{constructor(t){this.OK="OK";this.isConnected=false,this.ioRedisConnection=t;}static get ioredis(){return this.redisDataSourceInstance.ioRedisConnection}get ioredis(){return this.ioRedisConnection}static async connect(t){if(this.isConnected)return;let e=t?.port||+I.REDIS_PORT||6379,r=await import('ioredis').catch(()=>{throw new K("ioredis")});this.redisDataSourceInstance=new Z(new r.default({host:t?.host||I.REDIS_HOST,username:t?.username||I.REDIS_USERNAME,port:e,password:t?.password||I.REDIS_PASSWORD,...t}));try{await this.redisDataSourceInstance.ioRedisConnection.ping(),this.redisDataSourceInstance.isConnected=!0,this.isConnected=!0;}catch{throw new h("RedisDataSource::connect","CONNECTION_NOT_ESTABLISHED")}}static async getConnection(t){let e=await import('ioredis').catch(()=>{throw new K("ioredis")}),r=new e.default({host:t?.host||I.REDIS_HOST,username:t?.username||I.REDIS_USERNAME,port:t?.port||+I.REDIS_PORT||6379,password:t?.password||I.REDIS_PASSWORD,...t}),o=new Z(r);return await o.ioRedisConnection.ping(),o.isConnected=true,o}static async set(t,e,r){r=r?r/1e3:void 0,typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());try{if(r){await this.redisDataSourceInstance.ioRedisConnection.setex(t,r,e);return}await this.redisDataSourceInstance.ioRedisConnection.set(t,e);}catch{throw new h("RedisDataSource::set","SET_FAILED")}}static async get(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.get(t);return this.getValue(e)}catch{throw new h("RedisDataSource::get","SET_FAILED")}}static async getBuffer(t){try{return await this.redisDataSourceInstance.ioRedisConnection.getBuffer(t)}catch{throw new h("RedisDataSource::getBuffer","GET_FAILED")}}static async consume(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.get(t);return await this.redisDataSourceInstance.ioRedisConnection.del(t),this.getValue(e)}catch{throw new h("RedisDataSource::consume","GET_FAILED")}}static async delete(t){try{await this.redisDataSourceInstance.ioRedisConnection.del(t);}catch{throw new h("RedisDataSource::delete","DELETE_FAILED")}}static async flushAll(){try{await this.redisDataSourceInstance.ioRedisConnection.flushall();}catch{throw new h("RedisDataSource::flushAll","FLUSH_FAILED")}}static async disconnect(){try{await this.redisDataSourceInstance.ioRedisConnection.quit(),this.redisDataSourceInstance.isConnected=!1;}catch{throw new h("RedisDataSource::disconnect","DISCONNECT_FAILED")}}async set(t,e,r){r=r?r/1e3:void 0,typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());try{if(r){await this.ioRedisConnection.setex(t,r,e);return}await this.ioRedisConnection.set(t,e);}catch{throw new h("RedisDataSource::set","SET_FAILED")}}async get(t){try{let e=await this.ioRedisConnection.get(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::get","GET_FAILED")}}async getBuffer(t){try{return await this.ioRedisConnection.getBuffer(t)}catch{throw new h("RedisDataSource::getBuffer","GET_FAILED")}}async consume(t){try{let e=await this.ioRedisConnection.get(t);return await this.ioRedisConnection.del(t),Z.getValue(e)}catch{throw new h("RedisDataSource::consume","GET_FAILED")}}async delete(t){try{await this.ioRedisConnection.del(t);}catch{throw new h("RedisDataSource::delete","DELETE_FAILED")}}async flushAll(){try{await this.ioRedisConnection.flushall();}catch{throw new h("RedisDataSource::flushAll","FLUSH_FAILED")}}async disconnect(t){try{await this.ioRedisConnection.quit(),this.isConnected=!1;}catch{if(t)throw new h("RedisDataSource::disconnect","DISCONNECT_FAILED");M.warn("RedisDataSource::disconnect DISCONNECT_FAILED");}}static async lpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.lpush(t,...r)}catch{throw new h("RedisDataSource::lpush","LPUSH_FAILED")}}static async rpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.rpush(t,...r)}catch{throw new h("RedisDataSource::rpush","RPUSH_FAILED")}}static async lpop(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.lpop(t);return this.getValue(e)}catch{throw new h("RedisDataSource::lpop","LPOP_FAILED")}}static async rpop(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.rpop(t);return this.getValue(e)}catch{throw new h("RedisDataSource::rpop","RPOP_FAILED")}}static async lrange(t,e,r){try{return (await this.redisDataSourceInstance.ioRedisConnection.lrange(t,e,r)).map(n=>this.getValue(n)).filter(n=>n!==null)}catch{throw new h("RedisDataSource::lrange","LRANGE_FAILED")}}static async llen(t){try{return await this.redisDataSourceInstance.ioRedisConnection.llen(t)}catch{throw new h("RedisDataSource::llen","LLEN_FAILED")}}async lpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.lpush(t,...r)}catch{throw new h("RedisDataSource::lpush","LPUSH_FAILED")}}async rpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.rpush(t,...r)}catch{throw new h("RedisDataSource::rpush","RPUSH_FAILED")}}async lpop(t){try{let e=await this.ioRedisConnection.lpop(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::lpop","LPOP_FAILED")}}async rpop(t){try{let e=await this.ioRedisConnection.rpop(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::rpop","RPOP_FAILED")}}async lrange(t,e,r){try{return (await this.ioRedisConnection.lrange(t,e,r)).map(n=>Z.getValue(n)).filter(n=>n!==null)}catch{throw new h("RedisDataSource::lrange","LRANGE_FAILED")}}async llen(t){try{return await this.ioRedisConnection.llen(t)}catch{throw new h("RedisDataSource::llen","LLEN_FAILED")}}static async hset(t,e,r){try{return typeof r=="object"&&!Buffer.isBuffer(r)&&(r=JSON.stringify(r)),typeof r=="boolean"&&(r=r.toString()),await this.redisDataSourceInstance.ioRedisConnection.hset(t,e,r)}catch{throw new h("RedisDataSource::hset","HSET_FAILED")}}static async hmset(t,e){try{let r={};for(let[o,n]of Object.entries(e))typeof n=="object"&&!Buffer.isBuffer(n)?r[o]=JSON.stringify(n):typeof n=="boolean"?r[o]=n.toString():r[o]=String(n);return await this.redisDataSourceInstance.ioRedisConnection.hmset(t,r)}catch{throw new h("RedisDataSource::hmset","HMSET_FAILED")}}static async hget(t,e){try{let r=await this.redisDataSourceInstance.ioRedisConnection.hget(t,e);return this.getValue(r)}catch{throw new h("RedisDataSource::hget","HGET_FAILED")}}static async hgetall(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.hgetall(t),r={};for(let[o,n]of Object.entries(e))r[o]=this.getValue(n);return r}catch{throw new h("RedisDataSource::hgetall","HGETALL_FAILED")}}static async hmget(t,...e){try{return (await this.redisDataSourceInstance.ioRedisConnection.hmget(t,...e)).map(o=>this.getValue(o))}catch{throw new h("RedisDataSource::hmget","HMGET_FAILED")}}static async hdel(t,...e){try{return await this.redisDataSourceInstance.ioRedisConnection.hdel(t,...e)}catch{throw new h("RedisDataSource::hdel","HDEL_FAILED")}}static async hexists(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.hexists(t,e)}catch{throw new h("RedisDataSource::hexists","HEXISTS_FAILED")}}static async hkeys(t){try{return await this.redisDataSourceInstance.ioRedisConnection.hkeys(t)}catch{throw new h("RedisDataSource::hkeys","HKEYS_FAILED")}}static async hlen(t){try{return await this.redisDataSourceInstance.ioRedisConnection.hlen(t)}catch{throw new h("RedisDataSource::hlen","HLEN_FAILED")}}async hset(t,e,r){try{return typeof r=="object"&&!Buffer.isBuffer(r)&&(r=JSON.stringify(r)),typeof r=="boolean"&&(r=r.toString()),await this.ioRedisConnection.hset(t,e,r)}catch{throw new h("RedisDataSource::hset","HSET_FAILED")}}async hmset(t,e){try{let r={};for(let[o,n]of Object.entries(e))typeof n=="object"&&!Buffer.isBuffer(n)?r[o]=JSON.stringify(n):typeof n=="boolean"?r[o]=n.toString():r[o]=String(n);return await this.ioRedisConnection.hmset(t,r)}catch{throw new h("RedisDataSource::hmset","HMSET_FAILED")}}async hget(t,e){try{let r=await this.ioRedisConnection.hget(t,e);return Z.getValue(r)}catch{throw new h("RedisDataSource::hget","HGET_FAILED")}}async hgetall(t){try{let e=await this.ioRedisConnection.hgetall(t),r={};for(let[o,n]of Object.entries(e))r[o]=Z.getValue(n);return r}catch{throw new h("RedisDataSource::hgetall","HGETALL_FAILED")}}async hmget(t,...e){try{return (await this.ioRedisConnection.hmget(t,...e)).map(o=>Z.getValue(o))}catch{throw new h("RedisDataSource::hmget","HMGET_FAILED")}}async hdel(t,...e){try{return await this.ioRedisConnection.hdel(t,...e)}catch{throw new h("RedisDataSource::hdel","HDEL_FAILED")}}async hexists(t,e){try{return await this.ioRedisConnection.hexists(t,e)}catch{throw new h("RedisDataSource::hexists","HEXISTS_FAILED")}}async hkeys(t){try{return await this.ioRedisConnection.hkeys(t)}catch{throw new h("RedisDataSource::hkeys","HKEYS_FAILED")}}async hlen(t){try{return await this.ioRedisConnection.hlen(t)}catch{throw new h("RedisDataSource::hlen","HLEN_FAILED")}}static async sadd(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.sadd(t,...r)}catch{throw new h("RedisDataSource::sadd","SADD_FAILED")}}static async smembers(t){try{return (await this.redisDataSourceInstance.ioRedisConnection.smembers(t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::smembers","SMEMBERS_FAILED")}}static async srem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.srem(t,...r)}catch{throw new h("RedisDataSource::srem","SREM_FAILED")}}static async sismember(t,e){try{return typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString()),await this.redisDataSourceInstance.ioRedisConnection.sismember(t,e)}catch{throw new h("RedisDataSource::sismember","SISMEMBER_FAILED")}}static async scard(t){try{return await this.redisDataSourceInstance.ioRedisConnection.scard(t)}catch{throw new h("RedisDataSource::scard","SCARD_FAILED")}}static async sinter(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sinter(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sinter","SINTER_FAILED")}}static async sunion(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sunion(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sunion","SUNION_FAILED")}}static async sdiff(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sdiff(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sdiff","SDIFF_FAILED")}}async sadd(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.sadd(t,...r)}catch{throw new h("RedisDataSource::sadd","SADD_FAILED")}}async smembers(t){try{return (await this.ioRedisConnection.smembers(t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::smembers","SMEMBERS_FAILED")}}async srem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.srem(t,...r)}catch{throw new h("RedisDataSource::srem","SREM_FAILED")}}async sismember(t,e){try{return typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString()),await this.ioRedisConnection.sismember(t,e)}catch{throw new h("RedisDataSource::sismember","SISMEMBER_FAILED")}}async scard(t){try{return await this.ioRedisConnection.scard(t)}catch{throw new h("RedisDataSource::scard","SCARD_FAILED")}}async sinter(...t){try{return (await this.ioRedisConnection.sinter(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sinter","SINTER_FAILED")}}async sunion(...t){try{return (await this.ioRedisConnection.sunion(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sunion","SUNION_FAILED")}}async sdiff(...t){try{return (await this.ioRedisConnection.sdiff(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sdiff","SDIFF_FAILED")}}static async zadd(t,e,r){try{if(typeof e=="number"&&r!==void 0){let o=r;return typeof r=="object"&&!Buffer.isBuffer(r)?o=JSON.stringify(r):typeof r=="boolean"&&(o=r.toString()),await this.redisDataSourceInstance.ioRedisConnection.zadd(t,e,o)}else if(Array.isArray(e)){let o=[];for(let[n,s]of e)o.push(n),typeof s=="object"&&!Buffer.isBuffer(s)?o.push(JSON.stringify(s)):typeof s=="boolean"?o.push(s.toString()):o.push(s);return await this.redisDataSourceInstance.ioRedisConnection.zadd(t,...o)}throw new Error("Invalid arguments for zadd")}catch{throw new h("RedisDataSource::zadd","ZADD_FAILED")}}static async zrange(t,e,r,o=false){try{let n;if(o){n=await this.redisDataSourceInstance.ioRedisConnection.zrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=this.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.redisDataSourceInstance.ioRedisConnection.zrange(t,e,r),n.map(s=>this.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrange","ZRANGE_FAILED")}}static async zrevrange(t,e,r,o=false){try{let n;if(o){n=await this.redisDataSourceInstance.ioRedisConnection.zrevrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=this.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.redisDataSourceInstance.ioRedisConnection.zrevrange(t,e,r),n.map(s=>this.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrevrange","ZREVRANGE_FAILED")}}static async zrem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.zrem(t,...r)}catch{throw new h("RedisDataSource::zrem","ZREM_FAILED")}}static async zscore(t,e){try{typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());let r=await this.redisDataSourceInstance.ioRedisConnection.zscore(t,e);return r!==null?Number(r):null}catch{throw new h("RedisDataSource::zscore","ZSCORE_FAILED")}}static async zcard(t){try{return await this.redisDataSourceInstance.ioRedisConnection.zcard(t)}catch{throw new h("RedisDataSource::zcard","ZCARD_FAILED")}}async zadd(t,e,r){try{if(typeof e=="number"&&r!==void 0){let o=r;return typeof r=="object"&&!Buffer.isBuffer(r)?o=JSON.stringify(r):typeof r=="boolean"&&(o=r.toString()),await this.ioRedisConnection.zadd(t,e,o)}else if(Array.isArray(e)){let o=[];for(let[n,s]of e)o.push(n),typeof s=="object"&&!Buffer.isBuffer(s)?o.push(JSON.stringify(s)):typeof s=="boolean"?o.push(s.toString()):o.push(s);return await this.ioRedisConnection.zadd(t,...o)}throw new Error("Invalid arguments for zadd")}catch{throw new h("RedisDataSource::zadd","ZADD_FAILED")}}async zrange(t,e,r,o=false){try{let n;if(o){n=await this.ioRedisConnection.zrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=Z.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.ioRedisConnection.zrange(t,e,r),n.map(s=>Z.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrange","ZRANGE_FAILED")}}async zrevrange(t,e,r,o=false){try{let n;if(o){n=await this.ioRedisConnection.zrevrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=Z.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.ioRedisConnection.zrevrange(t,e,r),n.map(s=>Z.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrevrange","ZREVRANGE_FAILED")}}async zrem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.zrem(t,...r)}catch{throw new h("RedisDataSource::zrem","ZREM_FAILED")}}async zscore(t,e){try{typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());let r=await this.ioRedisConnection.zscore(t,e);return r!==null?Number(r):null}catch{throw new h("RedisDataSource::zscore","ZSCORE_FAILED")}}async zcard(t){try{return await this.ioRedisConnection.zcard(t)}catch{throw new h("RedisDataSource::zcard","ZCARD_FAILED")}}static async subscribe(t,e){try{await this.redisDataSourceInstance.ioRedisConnection.subscribe(...t),this.redisDataSourceInstance.ioRedisConnection.on("message",e);}catch{throw new h("RedisDataSource::subscribe","SUBSCRIBE_FAILED")}}static async unsubscribe(...t){try{await this.redisDataSourceInstance.ioRedisConnection.unsubscribe(...t);}catch{throw new h("RedisDataSource::unsubscribe","UNSUBSCRIBE_FAILED")}}static async publish(t,e){try{let r;return typeof e=="object"&&!Buffer.isBuffer(e)?r=JSON.stringify(e):typeof e=="boolean"||typeof e=="number"?r=e.toString():Buffer.isBuffer(e)?r=e:r=String(e),await this.redisDataSourceInstance.ioRedisConnection.publish(t,r)}catch{throw new h("RedisDataSource::publish","PUBLISH_FAILED")}}static async psubscribe(t,e){try{await this.redisDataSourceInstance.ioRedisConnection.psubscribe(...t),this.redisDataSourceInstance.ioRedisConnection.on("pmessage",(r,o,n)=>{e(o,n);});}catch{throw new h("RedisDataSource::psubscribe","PSUBSCRIBE_FAILED")}}static async punsubscribe(...t){try{await this.redisDataSourceInstance.ioRedisConnection.punsubscribe(...t);}catch{throw new h("RedisDataSource::punsubscribe","PUNSUBSCRIBE_FAILED")}}async subscribe(t,e){try{await this.ioRedisConnection.subscribe(...t),this.ioRedisConnection.on("message",e);}catch{throw new h("RedisDataSource::subscribe","SUBSCRIBE_FAILED")}}async unsubscribe(...t){try{await this.ioRedisConnection.unsubscribe(...t);}catch{throw new h("RedisDataSource::unsubscribe","UNSUBSCRIBE_FAILED")}}async publish(t,e){try{let r;return typeof e=="object"&&!Buffer.isBuffer(e)?r=JSON.stringify(e):typeof e=="boolean"||typeof e=="number"?r=e.toString():Buffer.isBuffer(e)?r=e:r=String(e),await this.ioRedisConnection.publish(t,r)}catch{throw new h("RedisDataSource::publish","PUBLISH_FAILED")}}async psubscribe(t,e){try{await this.ioRedisConnection.psubscribe(...t),this.ioRedisConnection.on("pmessage",(r,o,n)=>{e(o,n);});}catch{throw new h("RedisDataSource::psubscribe","PSUBSCRIBE_FAILED")}}async punsubscribe(...t){try{await this.ioRedisConnection.punsubscribe(...t);}catch{throw new h("RedisDataSource::punsubscribe","PUNSUBSCRIBE_FAILED")}}static async exists(t){try{return await this.redisDataSourceInstance.ioRedisConnection.exists(t)}catch{throw new h("RedisDataSource::exists","EXISTS_FAILED")}}static async expire(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.expire(t,e)}catch{throw new h("RedisDataSource::expire","EXPIRE_FAILED")}}static async expireat(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.expireat(t,e)}catch{throw new h("RedisDataSource::expireat","EXPIREAT_FAILED")}}static async pexpire(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.pexpire(t,e)}catch{throw new h("RedisDataSource::pexpire","PEXPIRE_FAILED")}}static async ttl(t){try{return await this.redisDataSourceInstance.ioRedisConnection.ttl(t)}catch{throw new h("RedisDataSource::ttl","TTL_FAILED")}}static async pttl(t){try{return await this.redisDataSourceInstance.ioRedisConnection.pttl(t)}catch{throw new h("RedisDataSource::pttl","PTTL_FAILED")}}static async persist(t){try{return await this.redisDataSourceInstance.ioRedisConnection.persist(t)}catch{throw new h("RedisDataSource::persist","PERSIST_FAILED")}}static async keys(t){try{return await this.redisDataSourceInstance.ioRedisConnection.keys(t)}catch{throw new h("RedisDataSource::keys","KEYS_FAILED")}}static async rename(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.rename(t,e)}catch{throw new h("RedisDataSource::rename","RENAME_FAILED")}}static async type(t){try{return await this.redisDataSourceInstance.ioRedisConnection.type(t)}catch{throw new h("RedisDataSource::type","TYPE_FAILED")}}async exists(t){try{return await this.ioRedisConnection.exists(t)}catch{throw new h("RedisDataSource::exists","EXISTS_FAILED")}}async expire(t,e){try{return await this.ioRedisConnection.expire(t,e)}catch{throw new h("RedisDataSource::expire","EXPIRE_FAILED")}}async expireat(t,e){try{return await this.ioRedisConnection.expireat(t,e)}catch{throw new h("RedisDataSource::expireat","EXPIREAT_FAILED")}}async pexpire(t,e){try{return await this.ioRedisConnection.pexpire(t,e)}catch{throw new h("RedisDataSource::pexpire","PEXPIRE_FAILED")}}async ttl(t){try{return await this.ioRedisConnection.ttl(t)}catch{throw new h("RedisDataSource::ttl","TTL_FAILED")}}async pttl(t){try{return await this.ioRedisConnection.pttl(t)}catch{throw new h("RedisDataSource::pttl","PTTL_FAILED")}}async persist(t){try{return await this.ioRedisConnection.persist(t)}catch{throw new h("RedisDataSource::persist","PERSIST_FAILED")}}async keys(t){try{return await this.ioRedisConnection.keys(t)}catch{throw new h("RedisDataSource::keys","KEYS_FAILED")}}async rename(t,e){try{return await this.ioRedisConnection.rename(t,e)}catch{throw new h("RedisDataSource::rename","RENAME_FAILED")}}async type(t){try{return await this.ioRedisConnection.type(t)}catch{throw new h("RedisDataSource::type","TYPE_FAILED")}}static getValue(t){if(!t)return null;try{return JSON.parse(t)}catch{}return t==="true"||t==="false"?!!t:Number.isNaN(Number(t))?t:Number(t)}};Z.OK="OK";var il=Z;var al=class{constructor(t){this.dbType=t,this.migrationName=pt__default.default.basename(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))),this.schema=new ie(this.dbType);}};async function _y(i){try{return import(url.pathToFileURL(i).href)}catch{let e=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))(i);return {default:e.default||e,...e}}}async function Oy(i){let{build:t}=await import('esbuild').catch(()=>{throw new Error("esbuild is required to import TypeScript files. Install it with: npm install esbuild -D")}),e=Math.random().toString(36).slice(2,8),r=i.replace(/\.ts$/,`.bundled_${e}.mjs`);try{return await t({entryPoints:[i],bundle:!0,platform:"node",format:"esm",sourcemap:"inline",outfile:r,packages:"external",logLevel:"silent"}),await import(url.pathToFileURL(r).href)}finally{await Jr__default.default.promises.unlink(r).catch(()=>{});}}async function Up(i,t){let e=pt__default.default.isAbsolute(i)?i:pt__default.default.resolve(process.cwd(),i);return e.endsWith(".ts")?Oy(e):_y(e)}var ll=class{parseGetAllTables(t,e,r){switch(t){case "mysql":case "mariadb":return r[0].map(n=>n[`Tables_in_${e}`]);case "cockroachdb":case "postgres":return r.rows.map(n=>n.table_name);case "mssql":return r.recordset.map(n=>n.TABLE_NAME);case "oracledb":return (r.rows||[]).map(n=>Array.isArray(n)?n[0]:n?.TABLE_NAME).filter(n=>typeof n=="string"&&n.length>0);default:throw new Error(`Unsupported database type: ${t}`)}}getAllTablesTemplate(t,e){switch(t){case "mysql":case "mariadb":return `SHOW TABLES FROM ${e};`;case "cockroachdb":case "postgres":return `SELECT table_name
|
|
216
|
+
END;`))?.outBinds?.result===1}catch(o){let n=o instanceof Error?o:new Error(String(o));return M.warn(`Oracle lock release may have failed: ${n.message}`),!1}case "sqlite":return !0;default:return M.warn(`Advisory locks not implemented for database type: ${r}`),!0}}catch(o){let n=o instanceof Error?o:new Error(String(o));return M.error(`Failed to release lock: ${n.message||JSON.stringify(o)} (dbType: ${r}, lockKey: ${e}). Full error: ${JSON.stringify(o)}`),false}}hashStringToLockId(e){let r=0;for(let o=0;o<e.length;o++){let n=e.charCodeAt(o);r=(r<<5)-r+n,r=r&r;}return Math.abs(r)}async executeOnSlave(e){let r=this.getSlave();if(!r)return e(this);try{return await e(r)}catch(o){let n=o instanceof Error?o:new Error(String(o));if(this.onSlaveServerFailure)return await this.onSlaveServerFailure(n,{host:r.host,port:r.port,username:r.username,password:r.password,database:r.database,type:r.sqlType}),e(this);throw n}}async connectWithoutSettingPrimary(){this.sqlPool=await xt(this.sqlType,this.inputDetails),this.ownsPool=true;}};Te=new WeakMap,$t(Ae,Te,null);var be=Ae;var Ip=["postgres","cockroachdb"];var Dt=class Dt extends Ie{static get table(){let t=Object.getOwnPropertyDescriptor(this,"table");return t&&"value"in t?t.value:Op(this)}static set table(t){Object.defineProperty(this,"table",{value:t,writable:true,enumerable:true,configurable:true});}static get primaryKey(){return Pp(this)}constructor(t){super(),t&&this.constructor.combineProps(this,t);}static from(t){let e=new this;return this.combineProps(e,t),e}static async all(t={}){return await this.dispatchModelManager(t).find({ignoreHooks:t.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static query(t){return this.dispatchModelManager(t).query()}static async first(t){return this.dispatchModelManager(t).query().one({ignoreHooks:t?.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static async find(t,e){return await this.dispatchModelManager(e).find(t)}static async findOneOrFail(t,e){return await this.dispatchModelManager(e).findOneOrFail(t)}static async findOne(t,e){return await this.dispatchModelManager(e).findOne(t)}static async findBy(t,e,r={}){return await this.dispatchModelManager(r).find({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:{[t]:e}})}static async findOneBy(t,e,r={}){return await this.dispatchModelManager(r).findOne({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:{[t]:e}})}static async findOneByPrimaryKey(t,e={}){return await this.dispatchModelManager(e).findOneByPrimaryKey(t)}static async refresh(t,e={}){let n=await this.dispatchModelManager(e).findOneByPrimaryKey(t);return n||null}static insert(t,e={}){return this.dispatchModelManager(e).insert(t,{ignoreHooks:e.ignoreHooks,returning:e.returning})}static insertMany(t,e={}){let o=this.dispatchModelManager(e);if(!t.length){let n=!e.returning||e.returning.length===0;return new V(()=>({sql:"",bindings:[]}),()=>"",async()=>n?void 0:[])}return o.insertMany(t,{ignoreHooks:e.ignoreHooks,returning:e.returning})}static async sync(t,e,r,o,n={}){if(Array.isArray(r)||(r=[r]),!r.length)return;let s=this,l=br(s).find(m=>m.columnName===t);if(!l)throw new h(`${s.name}::sync`,"RELATION_NOT_FOUND");if(l.type!=="manyToMany")throw new h(`${s.name}::sync`,"RELATION_NOT_MANY_TO_MANY");let d=L(l.leftForeignKey,n.caseConvention||s.databaseCaseConvention),u=L(l.rightForeignKey,n.caseConvention||s.databaseCaseConvention),f=r.map((m,g)=>({[d]:e[s.primaryKey],[u]:m[l.model.primaryKey],...o?o(m,g):{}}));class c extends Dt{static get table(){return l.throughModel}}c.databaseCaseConvention="preserve",c.modelCaseConvention="preserve",await c.dispatchModelManager(n).insertMany(f);}static async updateRecord(t,e,r={}){try{let n=this.dispatchModelManager(r);if(!r.returning||r.returning.length===0){await n.updateRecord(t,e);return}return await n.updateRecord(t,e,{returning:r.returning})}catch(o){throw o instanceof h&&o.message==="MODEL_HAS_NO_PRIMARY_KEY"?new h(`${this.name}::updateRecord`,"MODEL_HAS_NO_PRIMARY_KEY"):o}}static async firstOrInsert(t,e,r={}){r.fullResponse||(r.fullResponse=false);let n=this.dispatchModelManager(r),s=await n.findOne({where:t});if(s)return r.fullResponse?{isNew:false,model:s}:s;let a=await n.insert(e,{returning:["*"]});return r.fullResponse?{isNew:true,model:a}:a}static async upsert(t,e,r={updateOnConflict:true}){let o=this,n=o.dispatchModelManager(r),s=Object.keys(t).length>0,a=!r.returning||r.returning.length===0,l=s?await n.findOne({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[],where:t}):null;if(l){let d=l[o.primaryKey];if(r.updateOnConflict??true){if(a){await n.updateRecord(d,e);return}return await n.updateRecord(d,e,{returning:r.returning})}return a?void 0:l}return await n.insert(e,{ignoreHooks:r.ignoreHooks,returning:r.returning})}static async upsertMany(t,e,r={updateOnConflict:true}){if(!e.length)return [];let o=this,n=o.dispatchModelManager(r),s=!r.returning||r.returning.length===0;if(!e.every(c=>{let p=new Set(Object.keys(c));return t.every(m=>p.has(m))}))throw new h("Model::upsertMany","CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA");let a=Object.keys(e[0]),l=await n.upsertMany(t,a,e,{ignoreHooks:r.ignoreHooks,returning:r.returning,updateOnConflict:r.updateOnConflict??true});if(s)return;let d=o.sqlInstance.getDbType();if(Ip.includes(d))return await we(l,o,r.returning);let u=n.query();r.returning?.length&&u.select(...r.returning);let f=new Map;return t.forEach(c=>{e.forEach(p=>{f.set(c,[...f.get(c)||[],p[c]]);});}),u.where(c=>{t.forEach(p=>{c.orWhereIn(p,f.get(p)||[]);});}),u.many({ignoreHooks:r.ignoreHooks?["afterFetch","beforeFetch"]:[]})}static async deleteRecord(t,e){return this.dispatchModelManager(e).deleteRecord(t)}static async save(t,e={}){let r=this,o=r.primaryKey;if(!o)throw new h(r.name+"::save","MODEL_HAS_NO_PRIMARY_KEY");let n=t[o],s=n?{[o]:n}:{},a=t;return await r.upsert.call(this,s,a,{updateOnConflict:true,returning:e.returning,...e})}static async softDelete(t,e,r){let o=this,{column:n=o.softDeleteColumn,value:s=o.softDeleteValue}=e||{},a={[n]:s},l=o.dispatchModelManager({trx:r?.trx,connection:r?.connection});if(!r?.returning||r.returning.length===0){await l.updateRecord(t,a);return}return await l.updateRecord(t,a,{returning:r.returning})}static async truncate(t={}){return this.dispatchModelManager(t).query().truncate()}static async getTableInfo(){let t=this;return t.establishConnection(),t.sqlInstance.getTableInfo(t.table)}static async getIndexInfo(){let t=this;return t.establishConnection(),t.sqlInstance.getIndexInfo(t.table)}static async getTableSchema(){let t=this;return t.establishConnection(),t.sqlInstance.getTableSchema(t.table)}static combineProps(t,e){for(let r in e)Object.assign(t,{[r]:e[r]});}static getColumns(){return Qt(this)}static getRelations(){return Dp(this)}static getIndexes(){return $p(this)}static getUniques(){return Ep(this)}static getChecks(){return Bp(this)}static column(t,...e){q(...e)(this.prototype,t);}static dateColumn(t,...e){q.date(...e)(this.prototype,t);}static datetimeColumn(t,...e){q.datetime(...e)(this.prototype,t);}static timestampColumn(t,...e){q.timestamp(...e)(this.prototype,t);}static timeColumn(t,...e){q.time(...e)(this.prototype,t);}static booleanColumn(t,...e){q.boolean(...e)(this.prototype,t);}static jsonColumn(t,...e){q.json(...e)(this.prototype,t);}static uuidColumn(t,...e){q.uuid(...e)(this.prototype,t);}static ulidColumn(t,...e){q.ulid(...e)(this.prototype,t);}static integerColumn(t,...e){q.integer(...e)(this.prototype,t);}static floatColumn(t,...e){q.float(...e)(this.prototype,t);}static incrementColumn(t,...e){q.increment(...e)(this.prototype,t);}static bigIncrementColumn(t,...e){q.bigIncrement(...e)(this.prototype,t);}static encryptionSymmetricColumn(t,...e){q.encryption.symmetric(...e)(this.prototype,t);}static encryptionAsymmetricColumn(t,...e){q.encryption.asymmetric(...e)(this.prototype,t);}static hasOne(t,...e){Br(...e)(this.prototype,t);}static hasMany(t,...e){vr(...e)(this.prototype,t);}static belongsTo(t,...e){Er(...e)(this.prototype,t);}static manyToMany(t,...e){kr(...e)(this.prototype,t);}static establishConnection(){let t=be.instance;if(!t)throw new h("sqlInstance not initialized, did you defined it in SqlDataSource.connect static method?","CONNECTION_NOT_ESTABLISHED");this.sqlInstance=t;}static dispatchModelManager(t){let e;if(t?.connection)e=t.connection.getModelManager(this);else if(t?.trx)e=t.trx.sql.getModelManager(this);else {let r=this;r.establishConnection(),e=r.sqlInstance.getModelManager(r);}return t?.replicationMode&&e.setReplicationMode(t.replicationMode),e}};Dt.softDeleteColumn="deletedAt",Dt.softDeleteValue=Ye();var U=Dt;var Ne=class{constructor(t,e){this.model=U;this.columnName="";this.relatedModel="";this.model=t,this.columnName=e,this.relatedModel=this.model.table;}};var Qr=class extends Ne{constructor(t,e,r){super(t,e),this.foreignKey=r,this.type="belongsTo";}};var Kr=class extends Ne{constructor(e,r,o){super(e,r);this.type="hasMany";this.foreignKey=o,this.type="hasMany";}};var Lr=class extends Ne{constructor(t,e,r){super(t,e),this.foreignKey=r,this.type="hasOne";}};var Wr=class extends Ne{constructor(e,r,o){super(e,r);this.type="manyToMany";this.primaryModel=o.primaryModel,this.relatedModel=e.table,this.throughModel=o.throughModel,this.leftForeignKey=o.leftForeignKey,this.rightForeignKey=o.rightForeignKey;}};function rl(i,t){return e=>{let r=Array.isArray(i)?i:[i],o=Q.getMetadata(nr,e.prototype)||[];o.push({columns:r,name:t??ar(e.table,r.join("_"))}),Q.defineMetadata(nr,o,e.prototype);}}function ol(i,t){return e=>{let r=Array.isArray(i)?i:[i],o=Q.getMetadata(sr,e.prototype)||[];o.push({columns:r,name:t??ce(e.table,r.join("_"))}),Q.defineMetadata(sr,o,e.prototype);}}function nl(i,t){return e=>{let r=Q.getMetadata(ir,e.prototype)||[];r.push({expression:i,name:t??wp(e.table,i)}),Q.defineMetadata(ir,r,e.prototype);}}function zk(i){return t=>{let e=t,r=e.query;e.query=function(...o){let n=r.bind(this).call(this,...o);return i(n),n};}}function q(i={primaryKey:false}){let t=i?.primaryKey??false;return (e,r)=>{let o=e.constructor;if(t){if(Q.getMetadata(at,e))throw new h("ModelDecorator::column","MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED");Q.defineMetadata(at,r,e),Q.defineMetadata(at,r,e.constructor);}let n=i.databaseName??L(r,o.databaseCaseConvention),s={columnName:r,serialize:i.serialize,prepare:i.prepare,hidden:i.hidden,isPrimary:t,primaryKeyConstraintName:i.primaryKeyConstraintName??Ee(o.table,r),autoUpdate:i.autoUpdate,databaseName:n,openApi:i.openApi,type:i.type,length:i?.length,precision:i?.precision,scale:i?.scale,withTimezone:i?.withTimezone,constraints:{nullable:i.nullable,default:i.default}},a=Q.getMetadata(or,e)||[];a.push(s),Q.defineMetadata(or,a,e);}}q.primary=Lf;q.date=oy;q.datetime=ny;q.timestamp=sy;q.time=iy;q.boolean=ry;q.json=ay;q.uuid=Vf;q.ulid=Jf;q.integer=Ff;q.bigInteger=Yf;q.float=Wf;q.decimal=Gf;q.increment=jf;q.bigIncrement=Uf;q.string=Hf;q.text=zf;q.binary=Zf;q.enum=Xf;q.encryption={symmetric:ey,asymmetric:ty};function Lf(i={}){return q({...i,primaryKey:true})}function Wf(i={}){return q({type:"float",...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:typeof t=="string"?Number.parseInt(t):Number.parseFloat(t)},openApi:{type:"number",format:"float",description:"A floating point number",...i.openApi||{}}})}function Ff(i={}){return q({type:"integer",...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:typeof t=="string"?+t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An integer number",...i.openApi||{}}})}function jf(i={}){return q({type:"increment",...i,primaryKey:true,nullable:false,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An auto-incrementing integer number",...i.openApi||{}}})}function Uf(i={}){return q({type:"bigIncrement",...i,primaryKey:true,nullable:false,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseInt(t)},openApi:{type:"integer",format:"int64",description:"An auto-incrementing bigint number",...i.openApi||{}}})}function Vf(i={}){return q({type:"uuid",...i,prepare:t=>t||Me__default.default.randomUUID(),openApi:{type:"string",format:"uuid",description:"uuid (Universally Unique Identifier)",...i.openApi||{}}})}function Jf(i={}){return q({type:"ulid",...i,prepare:t=>t||Nl(),openApi:{type:"string",format:"ulid",description:"ulid (Universally Unique Lexicographically Sortable Identifier)",...i.openApi||{}}})}function Hf(i={}){return q({type:"string",...i,openApi:{type:"string",description:"A string value",...i.openApi||{}}})}function zf(i={}){return q({type:"longtext",...i,openApi:{type:"string",description:"A text value",...i.openApi||{}}})}function Yf(i={}){return q({type:"bigint",...i,serialize:t=>{if(t!==void 0){if(t===null)return null;if(typeof t=="number")return t;if(typeof t=="string")return Number.parseInt(t);if(typeof t=="bigint")return Number(t)}},openApi:{type:"integer",format:"int64",description:"A bigint number",...i.openApi||{}}})}function Gf(i={}){return q({type:"decimal",precision:i.precision??10,scale:i.scale??2,...i,serialize:t=>{if(t!==void 0)return t===null?null:typeof t=="number"?t:Number.parseFloat(t)},openApi:{type:"number",format:"double",description:"A decimal number",...i.openApi||{}}})}function Zf(i={}){return q({type:"binary",...i,openApi:{type:"string",format:"binary",description:"Binary data",...i.openApi||{}}})}function Xf(i,t={}){return q({type:i,...t,openApi:{type:"string",enum:i,description:"An enum value",...t.openApi||{}}})}function ey(i){return q({...i,prepare:t=>t&&gl(i.key,t),serialize:t=>t&&bl(i.key,t)})}function ty(i){return q({...i,prepare:t=>t&&Tl(i.publicKey,t),serialize:t=>t&&wl(i.privateKey,t)})}function ry(i={}){return q({type:"boolean",...i,serialize:t=>!!t,prepare:t=>{if(t!=null)return !!t},openApi:{type:"boolean",description:"A boolean value",...i.openApi||{}}})}function oy(i={}){let{timezone:t="UTC",autoUpdate:e=false,autoCreate:r=false,prepare:o,serialize:n,...s}=i,a=d=>d?e?se(new Date,"DATE_ONLY",t):typeof d=="string"?d:se(d,"DATE_ONLY",t):r?se(new Date,"DATE_ONLY",t):null,l=d=>{if(d!==void 0)return d===null?null:ft(d,void 0,t)};return q({type:"date",...s,autoUpdate:e,prepare:d=>{let u=a(d);return o?o(u):u},serialize:d=>{let u=l(d);return n?n(u):u},openApi:{type:"string",format:"date",description:"YYYY-MM-DD",...s.openApi||{}}})}function ny(i={}){let{timezone:t,withTimezone:e,autoUpdate:r=false,autoCreate:o=false,prepare:n,serialize:s,...a}=i,l=t??"UTC",d=e??t!==void 0,u=c=>c?r?se(new Date,"ISO",l):typeof c=="string"?c:se(c,"ISO",l):o?se(new Date,"ISO",l):null,f=c=>{if(c!==void 0)return c===null?null:ft(c,void 0,l)};return q({type:"datetime",...a,withTimezone:d,autoUpdate:r,prepare:c=>{let p=u(c);return n?n(p):p},serialize:c=>{let p=f(c);return s?s(p):p},openApi:{type:"string",format:"date-time",description:"YYYY-MM-DD HH:mm:ss",...a.openApi||{}}})}function sy(i={}){let{timezone:t,withTimezone:e,autoUpdate:r=false,autoCreate:o=false,prepare:n,serialize:s,...a}=i,l=t??"UTC",d=e??t!==void 0,u=c=>c?r?se(new Date,"TIMESTAMP",l):typeof c=="string"?c:se(c,"TIMESTAMP",l):o?se(new Date,"TIMESTAMP",l):null,f=c=>{if(c!==void 0)return c===null?null:ft(c,void 0,l)};return q({type:"timestamp",...a,withTimezone:d,autoUpdate:r,prepare:c=>{let p=u(c);return n?n(p):p},serialize:c=>{let p=f(c);return s?s(p):p},openApi:{type:"string",format:"date-time",description:"Unix timestamp",...a.openApi||{}}})}function iy(i={}){let{timezone:t="UTC",autoUpdate:e=false,autoCreate:r=false,prepare:o,serialize:n,...s}=i,a=d=>d?e?se(new Date,"TIME_ONLY",t):typeof d=="string"?d:se(d,"TIME_ONLY",t):r?se(new Date,"TIME_ONLY",t):null,l=d=>{if(d!==void 0)return d===null?null:ft(d,void 0,t)};return q({type:"time",...s,autoUpdate:e,prepare:d=>{let u=a(d);return o?o(u):u},serialize:d=>{let u=l(d);return n?n(u):u},openApi:{type:"string",format:"time",description:"HH:mm:ss",...s.openApi||{}}})}function ay(i={}){return q({type:"jsonb",...i,serialize:t=>typeof t=="string"?JSON.parse(t):t,prepare:t=>typeof t!="string"?JSON.stringify(t):t,openApi:{type:"object",description:"A JSON object",...i.openApi||{}}})}function Qt(i){try{return Q.getMetadata(or,i.prototype)||[]}catch{return []}}function Er(i,t,e){return((r,o)=>{let n=()=>$e(i().table),s=()=>{let d=r.constructor.table,u=t||n();return ee(d,u,i().table)},a={type:"belongsTo",columnName:o,model:i,foreignKey:t?String(t):n,constraintName:e?.constraintName??s,onUpdate:e?.onUpdate,onDelete:e?.onDelete},l=Q.getMetadata(he,r)||[];l.push(a),Q.defineMetadata(he,l,r);})}function Br(i,t){return((e,r)=>{let o=()=>$e(e.constructor.table),n={type:"hasOne",columnName:r,model:i,constraintName:"None",foreignKey:t?String(t):o},s=Q.getMetadata(he,e)||[];s.push(n),Q.defineMetadata(he,s,e);})}function vr(i,t){return((e,r)=>{let o=()=>$e(e.constructor.table),n={type:"hasMany",columnName:r,model:i,constraintName:"None",foreignKey:t?String(t):o},s=Q.getMetadata(he,e)||[];s.push(n),Q.defineMetadata(he,s,e);})}function kr(i,t,e,r){return((o,n)=>{let{leftForeignKey:s,rightForeignKey:a}=e??{},l=typeof t!="string",d=typeof t=="string"?t:()=>t().table,u=o.constructor.table,f=()=>$e(u),c=()=>$e(i().table),p=()=>ee(S(d),s?String(s):f()),m={type:"manyToMany",columnName:n,model:i,constraintName:r?.constraintName??p,foreignKey:s?String(s):f,onDelete:r?.onDelete,onUpdate:r?.onUpdate,manyToManyOptions:{primaryModel:u,throughModel:d,leftForeignKey:s?String(s):f,rightForeignKey:a?String(a):c,wasModelProvided:l}},g=Q.getMetadata(he,o)||[];g.push(m),Q.defineMetadata(he,g,o);})}function Dp(i){return Q.getMetadata(he,i.prototype)||[]}function br(i){return (Q.getMetadata(he,i.prototype)||[]).map(e=>{let{type:r,model:o,columnName:n,foreignKey:s}=e,a=S(s),l=o();switch(r){case "belongsTo":return new Qr(l,n,a);case "hasOne":return new Lr(l,n,a);case "hasMany":return new Kr(l,n,a);case "manyToMany":if(!e.manyToManyOptions)throw new h("ModelDecorator::getRelations","MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL");let d=o();return new Wr(d,n,{primaryModel:e.manyToManyOptions.primaryModel,throughModel:S(e.manyToManyOptions.throughModel),leftForeignKey:S(e.manyToManyOptions.leftForeignKey),rightForeignKey:S(e.manyToManyOptions.rightForeignKey)});default:throw new h("ModelDecorator::getRelations",`UNKNOWN_RELATION_TYPE_${r}`)}})}function Pp(i){return Q.getMetadata(at,i)||Q.getMetadata(at,i.prototype)}function $p(i){return Q.getMetadata(nr,i.prototype)||[]}function Ep(i){return Q.getMetadata(sr,i.prototype)||[]}function Bp(i){return Q.getMetadata(ir,i.prototype)||[]}function H(i){return {_phantom:void 0,_apply:i}}function Fr(i){return {_phantom:void 0,_apply:i}}function G(i={}){return H((t,e)=>{q(i)(t,e);})}G.primary=function(t={}){return H((e,r)=>{q.primary(t)(e,r);})};G.string=function(t){return H((e,r)=>{q.string(t??{})(e,r);})};G.text=function(t){return H((e,r)=>{q.text(t??{})(e,r);})};G.integer=function(t){return H((e,r)=>{q.integer(t??{})(e,r);})};G.bigInteger=function(t){return H((e,r)=>{q.bigInteger(t??{})(e,r);})};G.float=function(t){return H((e,r)=>{q.float(t??{})(e,r);})};G.decimal=function(t){return H((e,r)=>{q.decimal(t??{})(e,r);})};G.increment=function(t={}){return H((e,r)=>{q.increment(t)(e,r);})};G.bigIncrement=function(t={}){return H((e,r)=>{q.bigIncrement(t)(e,r);})};G.boolean=function(t){return H((e,r)=>{q.boolean(t??{})(e,r);})};G.date=function(t){return H((e,r)=>{q.date(t??{})(e,r);})};G.datetime=function(t){return H((e,r)=>{q.datetime(t??{})(e,r);})};G.timestamp=function(t){return H((e,r)=>{q.timestamp(t??{})(e,r);})};G.time=function(t){return H((e,r)=>{q.time(t??{})(e,r);})};G.json=function(t){return H((e,r)=>{q.json(t??{})(e,r);})};G.uuid=function(t){return H((e,r)=>{q.uuid(t??{})(e,r);})};G.ulid=function(t){return H((e,r)=>{q.ulid(t??{})(e,r);})};G.binary=function(t){return H((e,r)=>{q.binary(t??{})(e,r);})};G.enum=function(t,e){return H((r,o)=>{q.enum(t,e??{})(r,o);})};G.encryption={symmetric(i){return H((t,e)=>{q.encryption.symmetric(i)(t,e);})},asymmetric(i){return H((t,e)=>{q.encryption.asymmetric(i)(t,e);})}};var ly=G,dy={hasOne(i,t,e){return Fr((r,o)=>{Br(()=>i(r.constructor),t)(r,o);})},hasMany(i,t,e){return Fr((r,o)=>{vr(()=>i(r.constructor),t)(r,o);})},belongsTo(i,t,e){return Fr((r,o)=>{Er(()=>i(r.constructor),t,e)(r,o);})},manyToMany(i,t,e,r){return Fr((o,n)=>{kr(()=>i(o.constructor),t,e,r)(o,n);})}};function uy(i,t){let{columns:e,relations:r,indexes:o,uniques:n,checks:s,hooks:a,options:l}=t;class d extends U{}d.table=i,l?.modelCaseConvention&&(d.modelCaseConvention=l.modelCaseConvention),l?.databaseCaseConvention&&(d.databaseCaseConvention=l.databaseCaseConvention),l?.softDeleteColumn&&(d.softDeleteColumn=l.softDeleteColumn),l?.softDeleteValue!==void 0&&(d.softDeleteValue=l.softDeleteValue);for(let[u,f]of Object.entries(e))f._apply(d.prototype,u);if(r)for(let[u,f]of Object.entries(r))f._apply(d.prototype,u);if(o)for(let u of o)cy(d,u);if(n)for(let u of n)my(d,u);if(s)for(let u of s)py(d,u);return a&&(a.beforeFetch&&(d.beforeFetch=a.beforeFetch),a.afterFetch&&(d.afterFetch=a.afterFetch),a.beforeInsert&&(d.beforeInsert=a.beforeInsert),a.beforeInsertMany&&(d.beforeInsertMany=a.beforeInsertMany),a.beforeUpdate&&(d.beforeUpdate=a.beforeUpdate),a.beforeDelete&&(d.beforeDelete=a.beforeDelete)),d}function cy(i,t){Array.isArray(t)?rl(t)(i):rl(t.columns,t.name)(i);}function my(i,t){Array.isArray(t)?ol(t)(i):ol(t.columns,t.name)(i);}function py(i,t){typeof t=="string"?nl(t)(i):nl(t.expression,t.name)(i);}var sl=class{constructor(t,e){this.typeofModel=t,this.modelData=e;}merge(t){this.modelData={...this.modelData,...t};}async create(t){if(t<=0)return [];let e=this.typeofModel;if(t===1)return await e.insert(this.modelData,{returning:["*"]});let r=Array.from({length:t});return await e.insertMany(r.map(()=>({...this.modelData})),{returning:["*"]})}},fy=(i,t)=>new sl(i,t);function yy(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.column("id",{openApi:{type:"number",required:true},...o,primaryKey:true});let n=s;return n}function hy(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.column("id",{openApi:{type:"number",required:true},...o,primaryKey:true});let n=s;return n}function vp(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.ulidColumn("id",{type:"ulid",openApi:{type:"string",format:"ulid",required:true},...o,primaryKey:true});let n=s;return n}var gy=vp;function kp(i,t){let e=a=>typeof a=="function",r=e(i)?i:U,o=e(i)?t:i,s=class s extends r{};s.uuidColumn("id",{type:"uuid",openApi:{type:"string",format:"uuid",required:true},...o,primaryKey:true});let n=s;return n}var by=kp;function Ty(i,t){let e=s=>typeof s=="function",r=e(i)?i:U,o=e(i)?t:i;class n extends r{}return U.datetimeColumn("createdAt",{type:"datetime",autoCreate:true,openApi:{type:"string",format:"date-time",required:true},...o?.createdAt}),U.datetimeColumn("updatedAt",{autoUpdate:true,openApi:{type:"string",format:"date-time",required:true},...o?.updatedAt}),U.datetimeColumn("deletedAt",{nullable:true,openApi:{type:"string",format:"date-time",required:false},...o?.deletedAt}),n}var Qp=i=>{let t=()=>{for(let[r,o]of Object.entries(i))U.column(r,o);};function e(r){var s;let o=r??U;return s=class extends o{},t(),s}return e},wy=Qp;var Kp=class{constructor(t){this.ioRedisOptions=t;}async getClient(){if(this.redisInstance)return this.redisInstance;let{default:t}=await import('ioredis').catch(()=>{throw M.error("RedisCacheAdapter::getClient ioredis driver not found and required for the RedisCacheAdapter"),new K("ioredis")});return this.redisInstance=new t(this.ioRedisOptions),this.redisInstance}async get(t){let r=await(await this.getClient()).get(t);if(r!=null)return this.deserializeData(r)}async set(t,e,r){let o=await this.getClient(),n=this.serializeData(e);if(n){if(r){await o.set(t,n,"PX",r);return}await o.set(t,n);}}async invalidate(t){await(await this.getClient()).del(t);}async invalidateAll(t){let e=await this.getClient(),r=await e.keys(`${t}:*`);for(let o of r)await e.del(o);}serializeData(t){if(t!=null){if(typeof t=="string")return t;if(Buffer.isBuffer(t))return t.toString("base64");if(typeof t=="object"||Array.isArray(t))try{return JSON.stringify(t)}catch(e){throw M.error("RedisCacheAdapter::set failed to serialize data"),e}return String(t)}}deserializeData(t){try{return JSON.parse(t)}catch{return t}}async disconnect(){this.redisInstance&&await this.redisInstance.quit();}};var{plural:Sy}=Of__default.default;function Lp(i){let t=i.name,e=L(t,"snake");return Sy(e)}function Wp(){return {$annotations:{}}}var mt=class extends Ie{static get collection(){return this._collection||Lp(this)}static query(t={}){return this.dispatchModelManager(t).query()}static rawCollection(){return this.mongoInstance.getCurrentConnection().db().collection(this.collection)}static async find(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).find(t)}static async findOne(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).findOne(t)}static async findOneOrFail(t){return await this.dispatchModelManager({session:t?.session,useConnection:t?.useConnection}).findOneOrFail(t)}static async insert(t,e={}){return await this.dispatchModelManager(e).insert(t)}static async insertMany(t,e={}){return await this.dispatchModelManager(e).insertMany(t)}static async updateRecord(t,e={}){return await this.dispatchModelManager(e).updateRecord(t)}static async deleteRecord(t,e={}){await this.dispatchModelManager(e).deleteRecord(t);}static establishConnection(){let t=Pt.getInstance();if(!t)throw new h("Collection::establishConnection","CONNECTION_NOT_ESTABLISHED");this.mongoInstance=t;}static dispatchModelManager(t){if(t.useConnection)return t.useConnection.getModelManager(this,t.useConnection);if(t.session)return this.mongoInstance.getModelManager(this,this.mongoInstance,t.session);let e=this;return e.establishConnection(),e.mongoInstance.getModelManager(e,e.mongoInstance)}static beforeFetch(t){}static beforeInsert(t){return t}static beforeUpdate(t){}static beforeDelete(t){}static property(t){Xr()(this.prototype,t);}static async afterFetch(t){return t}};fl([Xr()],mt.prototype,"id");async function Ke(i,t,e){if(!t)return null;let r=Wp(),o=hl(i);return (!e||!e.length)&&(e=o),e.includes("id")||e.push("id"),r.$annotations||(r.$annotations={}),await Promise.all(Object.keys(t).map(async n=>{if(n==="_id"){r.id=t._id?.toString();return}if(!o.includes(n)){let a=L(n,i.modelCaseConvention);r.$annotations[a]=t[n];return}let s=L(n,i.modelCaseConvention);r[s]=t[n];})),Object.keys(r.$annotations).length||delete r.$annotations,await Promise.all(e.map(async n=>{if(n!=="id"&&!t.hasOwnProperty(n)){let s=L(n,i.modelCaseConvention);r[s]=null;}})),r}async function jr(i,t,e){return (await Promise.all(t.map(async o=>await Ke(i,o,e)))).filter(o=>o!==null)}var Ur=class{constructor(t,e,r,o=false){this.model=t,this.idObject={},this.whereObject={},this.logs=o,this.session,this.mongoDataSource=e,this.collection=this.mongoDataSource.getCurrentConnection().db().collection(this.model.collection);}async one(t={throwErrorOnNull:false}){t.ignoreHooks?.includes("beforeFetch")||this.model.beforeFetch(this);let e={...this.whereObject};Object.keys(this.idObject).length&&(e._id=this.idObject);let r=await this.collection.findOne(e,{projection:this.selectObject,session:this.session}),o=await Ke(this.model,r,this.selectFields);return t.ignoreHooks?.includes("afterFetch")?o:(await this.model.afterFetch([o]))[0]}async oneOrFail(t={throwErrorOnNull:true}){let e=await this.one(t);if(!e)throw new h("MongoQueryBuilder::oneOrFail","ROW_NOT_FOUND");return e}async many(t={}){t.ignoreHooks?.includes("beforeFetch")||this.model.beforeFetch(this);let e={...this.whereObject};Object.keys(this.idObject).length&&(e._id=this.idObject);let r=await this.collection.find(e,{projection:this.selectFields,sort:this.sortObject,limit:this.limitNumber,skip:this.offsetNumber,session:this.session}).toArray(),o=await jr(this.model,r,this.selectFields);return t.ignoreHooks?.includes("afterFetch")?o:await this.model.afterFetch(o)}async insert(t,e={}){e.ignoreHooks||this.model.beforeInsert(t);let r=await this.collection.insertOne(t,{session:this.session});if(!e.returning)return {id:r.insertedId.toString()};let o=await this.collection.findOne({_id:r.insertedId});return await Ke(this.model,o,this.selectFields)}async insertMany(t,e={}){e.ignoreHooks||this.model.beforeInsert(t);let r=await this.collection.insertMany(t,{session:this.session});if(!e.returning)return Object.values(r.insertedIds).map(n=>({id:n.toString()}));let o=await this.collection.find({_id:{$in:Object.values(r.insertedIds)}}).toArray();return await jr(this.model,o,this.selectFields)}async update(t,e={}){if(e.ignoreHooks||this.model.beforeUpdate(this),(await this.collection.updateMany({_id:this.idObject,...this.whereObject},{$set:t,session:this.session})).modifiedCount===0)return [];let o=await this.collection.find({_id:Object.keys(this.idObject).length?this.idObject:void 0,...this.whereObject},{projection:this.selectFields}).toArray();return await jr(this.model,o,this.selectFields)}async delete(t={}){t.ignoreHooks||this.model.beforeDelete(this),await this.collection.deleteMany(this.whereObject,{session:this.session});}async count(t={}){return t.ignoreHooks||this.model.beforeFetch(this),this.collection.countDocuments(this.whereObject,{session:this.session})}select(t){return this.selectFields=t,this.selectObject=t.reduce((e,r)=>(e[r]=1,e),{}),this}where(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb");if(t==="id")return this.idObject={$eq:new s.ObjectId(n)},this;let a={[t]:{[o]:n}};return this.whereObject?(this.whereObject.$and||(this.whereObject.$and=[]),this.whereObject.$and.push(a)):this.whereObject={$and:[a]},this}andWhere(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb"),a={[t]:{[o]:n}};return t==="id"?(this.idObject={$eq:new s.ObjectId(n)},this):(this.whereObject?(this.whereObject.$and||(this.whereObject.$and=[]),this.whereObject.$and.push(a)):this.whereObject={$and:[a]},this)}orWhere(t,e,r){let o="$eq",n;typeof e=="string"&&r!==void 0?(o=e,n=r):(n=e,o="$eq");let s=re("mongodb"),a={[t]:{[o]:n}};return t==="id"?(this.idObject={$eq:new s.ObjectId(n)},this):(this.whereObject?(this.whereObject.$or||(this.whereObject.$or=[]),this.whereObject.$or.push(a)):this.whereObject={$or:[a]},this)}whereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereExists(t){let e={[t]:{$exists:true}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNotExists(t){let e={[t]:{$exists:false}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereNot(t,e){let r={[t]:{$ne:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereLike(t,e){let r={[t]:{$regex:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}andWhereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(r),this):(this.whereObject.$and=[r],this):(this.whereObject={$and:[r]},this)}orWhereNotLike(t,e){let r={[t]:{$not:{$regex:e}}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(r),this):(this.whereObject.$or=[r],this):(this.whereObject={$or:[r]},this)}whereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$in:n},this}let o={[t]:{$in:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereNotIn(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$nin:e}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:null};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}andWhereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(e),this):(this.whereObject.$and=[e],this):(this.whereObject={$and:[e]},this)}orWhereNotNull(t){if(t==="id")return M.warn("Id cannot be null"),this;let e={[t]:{$ne:null}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(e),this):(this.whereObject.$or=[e],this):(this.whereObject={$or:[e]},this)}whereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$gte:e[0],$lte:e[1]}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}andWhereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$and?(this.whereObject.$and.push(o),this):(this.whereObject.$and=[o],this):(this.whereObject={$and:[o]},this)}orWhereNotBetween(t,e){let r=re("mongodb");if(t==="id"){let n=e.map(s=>new r.ObjectId(s));return this.idObject={$nin:n},this}let o={[t]:{$lt:e[0],$gt:e[1]}};return this.whereObject?this.whereObject.$or?(this.whereObject.$or.push(o),this):(this.whereObject.$or=[o],this):(this.whereObject={$or:[o]},this)}whereRaw(t){return this.whereObject={...this.whereObject,...t},this}andRawWhere(t){return this.whereObject={...this.whereObject,...t},this}orRawWhere(t){return this.whereObject.$or||(this.whereObject.$or=[]),this.whereObject.$or.push(t),this}sortById(t){return this.sortObject={_id:t},this}sort(t){return typeof t=="number"?(this.sortObject={_id:t},this):typeof t=="string"?(this.sortObject={[t]:1},this):Array.isArray(t)?(this.sortObject=t.reduce((e,r)=>{if(typeof r=="string")return e[r]=1,e;let o=Object.keys(r)[0],n=Object.values(r)[0];return e[o]=+n,e},{}),this):(this.sortObject=t,this)}limit(t){return this.limitNumber=t,this}offset(t){return this.offsetNumber=t,this}};var Vr=class{constructor(t,e,r,o=false){this.logs=o,this.session=r,this.mongoDataSource=e,this.collection=mt,this.mongoClient=this.mongoDataSource.getCurrentConnection(),this.collectionInstance=this.mongoClient.db().collection(this.collection.collection);}async find(t){let e=this.query();return t?(t.select&&e.select(t.select),t.where&&Object.entries(t.where).forEach(([r,o])=>{e.where(r,o);}),t.sort&&e.sort(t.sort),t.limit&&e.limit(t.limit),t.offset&&e.offset(t.offset),e.many({ignoreHooks:t.ignoreHooks})):e.many()}async findOne(t){let e=this.query();return t?(t.where&&Object.entries(t.where).forEach(([r,o])=>{e.where(r,o);}),e.one({ignoreHooks:t.ignoreHooks})):e.oneOrFail()}async findOneOrFail(t){let e=this.query();if(!t)return e.oneOrFail();t.select&&e.select(t.select),t.where&&Object.entries(t.where).forEach(([o,n])=>{e.where(o,n);});let r=await e.one({ignoreHooks:t.ignoreHooks});if(r===null)throw t.customError?t.customError:new h("CollectionManager::findOneOrFail No record found","ROW_NOT_FOUND");return r}query(){return new Ur(this.collection,this.mongoDataSource,this.session,this.logs)}async insert(t,e={}){e.ignoreHooks||this.collection.beforeInsert(t);let o=(await this.collectionInstance.insertOne(t)).insertedId,n=await this.collectionInstance.findOne({_id:o},{session:this.session});return await Ke(this.collection,n)}async insertMany(t,e={}){e.ignoreHooks||t.forEach(s=>{this.collection.beforeInsert(s);});let o=(await this.collectionInstance.insertMany(t)).insertedIds,n=await this.collectionInstance.find({_id:{$in:Object.values(o)}},{session:this.session}).toArray();return Promise.all(n.map(async s=>await Ke(this.collection,s)))}async updateRecord(t){let e=t.id;if(!e)throw new h("CollectionManager::updateRecord","ROW_NOT_FOUND");let r=await import('mongodb');if((await this.collectionInstance.updateOne({_id:new r.ObjectId(e)},{$set:t})).modifiedCount===0)throw new h("CollectionManager::updateRecord","ROW_NOT_FOUND");let n=await this.collectionInstance.findOne({_id:new r.ObjectId(e)},{session:this.session});return await Ke(this.collection,n)}async deleteRecord(t){let e=t.id;if(!e)throw new h("CollectionManager::deleteRecord","ROW_NOT_FOUND");let r=await import('mongodb');return await this.collectionInstance.deleteOne({_id:new r.ObjectId(e)},{session:this.session}),t}};var Le=class Le extends et{constructor(e){super({type:"mongo",url:e?.url,logs:e?.logs});this.mongoClient=null;this.isConnected=false,this.mongoOptions=e?.options,this.url||(this.url=I.MONGO_URL);}async connect(){if(!this.url)throw new h("MongoDataSource::connect url is required to connect to mongo database and was not provided in the options nor the environment variables","REQUIRED_VALUE_NOT_SET");let e=(await de.getDriver("mongo")).client;this.mongoClient=new e.MongoClient(this.url,this.mongoOptions),await this.mongoClient.connect(),this.isConnected=true,Le.instance=this;}async connectWithoutSettingPrimary(){if(!this.url)throw new h("MongoDataSource::connect url is required to connect to mongo database and was not provided in the options nor the environment variables","REQUIRED_VALUE_NOT_SET");let e=(await de.getDriver("mongo")).client;this.mongoClient=new e.MongoClient(this.url,this.mongoOptions),await this.mongoClient.connect(),this.isConnected=true;}getCurrentConnection(){if(!this.mongoClient)throw new h("MongoDataSource::getCurrentConnection mongo database connection not established","CONNECTION_NOT_ESTABLISHED");return this.mongoClient}static async connectToSecondarySource(e){let r=new Le(e);return await r.connectWithoutSettingPrimary(),r}static getInstance(){if(!Le.instance)throw new h("MongoDataSource::getInstance mongo database connection not established","CONNECTION_NOT_ESTABLISHED");return Le.instance}startSession(){if(!this.mongoClient)throw new h("MongoDataSource::startSession mongo database connection not established","CONNECTION_NOT_ESTABLISHED");let e=this.mongoClient.startSession();return e.startTransaction(),e}static async disconnect(){if(!this.instance)throw new h("MongoDataSource::disconnect mongo database connection not established","CONNECTION_NOT_ESTABLISHED");await this.instance.disconnect();}async disconnect(){this.mongoClient&&await this.mongoClient.close(),this.isConnected=false;}async closeConnection(){await this.disconnect();}static async closeConnection(){await this.disconnect();}static async useConnection(e,r){let o=new Le(e);await o.connectWithoutSettingPrimary();try{await r(o);}finally{await o.disconnect();}}static query(e){return this.getInstance().query(e)}query(e){if(!this.isConnected)throw new h("MongoDataSource::query","CONNECTION_NOT_ESTABLISHED");return this.getModelManager({_collection:e},this).query()}getModelManager(e,r,o){return new Vr(e,r,o,this.logs)}};Le.instance=null;var Pt=Le;var Z=class Z{constructor(t){this.OK="OK";this.isConnected=false,this.ioRedisConnection=t;}static get ioredis(){return this.redisDataSourceInstance.ioRedisConnection}get ioredis(){return this.ioRedisConnection}static async connect(t){if(this.isConnected)return;let e=t?.port||+I.REDIS_PORT||6379,r=await import('ioredis').catch(()=>{throw new K("ioredis")});this.redisDataSourceInstance=new Z(new r.default({host:t?.host||I.REDIS_HOST,username:t?.username||I.REDIS_USERNAME,port:e,password:t?.password||I.REDIS_PASSWORD,...t}));try{await this.redisDataSourceInstance.ioRedisConnection.ping(),this.redisDataSourceInstance.isConnected=!0,this.isConnected=!0;}catch{throw new h("RedisDataSource::connect","CONNECTION_NOT_ESTABLISHED")}}static async getConnection(t){let e=await import('ioredis').catch(()=>{throw new K("ioredis")}),r=new e.default({host:t?.host||I.REDIS_HOST,username:t?.username||I.REDIS_USERNAME,port:t?.port||+I.REDIS_PORT||6379,password:t?.password||I.REDIS_PASSWORD,...t}),o=new Z(r);return await o.ioRedisConnection.ping(),o.isConnected=true,o}static async set(t,e,r){r=r?r/1e3:void 0,typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());try{if(r){await this.redisDataSourceInstance.ioRedisConnection.setex(t,r,e);return}await this.redisDataSourceInstance.ioRedisConnection.set(t,e);}catch{throw new h("RedisDataSource::set","SET_FAILED")}}static async get(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.get(t);return this.getValue(e)}catch{throw new h("RedisDataSource::get","SET_FAILED")}}static async getBuffer(t){try{return await this.redisDataSourceInstance.ioRedisConnection.getBuffer(t)}catch{throw new h("RedisDataSource::getBuffer","GET_FAILED")}}static async consume(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.get(t);return await this.redisDataSourceInstance.ioRedisConnection.del(t),this.getValue(e)}catch{throw new h("RedisDataSource::consume","GET_FAILED")}}static async delete(t){try{await this.redisDataSourceInstance.ioRedisConnection.del(t);}catch{throw new h("RedisDataSource::delete","DELETE_FAILED")}}static async flushAll(){try{await this.redisDataSourceInstance.ioRedisConnection.flushall();}catch{throw new h("RedisDataSource::flushAll","FLUSH_FAILED")}}static async disconnect(){try{await this.redisDataSourceInstance.ioRedisConnection.quit(),this.redisDataSourceInstance.isConnected=!1;}catch{throw new h("RedisDataSource::disconnect","DISCONNECT_FAILED")}}async set(t,e,r){r=r?r/1e3:void 0,typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());try{if(r){await this.ioRedisConnection.setex(t,r,e);return}await this.ioRedisConnection.set(t,e);}catch{throw new h("RedisDataSource::set","SET_FAILED")}}async get(t){try{let e=await this.ioRedisConnection.get(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::get","GET_FAILED")}}async getBuffer(t){try{return await this.ioRedisConnection.getBuffer(t)}catch{throw new h("RedisDataSource::getBuffer","GET_FAILED")}}async consume(t){try{let e=await this.ioRedisConnection.get(t);return await this.ioRedisConnection.del(t),Z.getValue(e)}catch{throw new h("RedisDataSource::consume","GET_FAILED")}}async delete(t){try{await this.ioRedisConnection.del(t);}catch{throw new h("RedisDataSource::delete","DELETE_FAILED")}}async flushAll(){try{await this.ioRedisConnection.flushall();}catch{throw new h("RedisDataSource::flushAll","FLUSH_FAILED")}}async disconnect(t){try{await this.ioRedisConnection.quit(),this.isConnected=!1;}catch{if(t)throw new h("RedisDataSource::disconnect","DISCONNECT_FAILED");M.warn("RedisDataSource::disconnect DISCONNECT_FAILED");}}static async lpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.lpush(t,...r)}catch{throw new h("RedisDataSource::lpush","LPUSH_FAILED")}}static async rpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.rpush(t,...r)}catch{throw new h("RedisDataSource::rpush","RPUSH_FAILED")}}static async lpop(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.lpop(t);return this.getValue(e)}catch{throw new h("RedisDataSource::lpop","LPOP_FAILED")}}static async rpop(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.rpop(t);return this.getValue(e)}catch{throw new h("RedisDataSource::rpop","RPOP_FAILED")}}static async lrange(t,e,r){try{return (await this.redisDataSourceInstance.ioRedisConnection.lrange(t,e,r)).map(n=>this.getValue(n)).filter(n=>n!==null)}catch{throw new h("RedisDataSource::lrange","LRANGE_FAILED")}}static async llen(t){try{return await this.redisDataSourceInstance.ioRedisConnection.llen(t)}catch{throw new h("RedisDataSource::llen","LLEN_FAILED")}}async lpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.lpush(t,...r)}catch{throw new h("RedisDataSource::lpush","LPUSH_FAILED")}}async rpush(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.rpush(t,...r)}catch{throw new h("RedisDataSource::rpush","RPUSH_FAILED")}}async lpop(t){try{let e=await this.ioRedisConnection.lpop(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::lpop","LPOP_FAILED")}}async rpop(t){try{let e=await this.ioRedisConnection.rpop(t);return Z.getValue(e)}catch{throw new h("RedisDataSource::rpop","RPOP_FAILED")}}async lrange(t,e,r){try{return (await this.ioRedisConnection.lrange(t,e,r)).map(n=>Z.getValue(n)).filter(n=>n!==null)}catch{throw new h("RedisDataSource::lrange","LRANGE_FAILED")}}async llen(t){try{return await this.ioRedisConnection.llen(t)}catch{throw new h("RedisDataSource::llen","LLEN_FAILED")}}static async hset(t,e,r){try{return typeof r=="object"&&!Buffer.isBuffer(r)&&(r=JSON.stringify(r)),typeof r=="boolean"&&(r=r.toString()),await this.redisDataSourceInstance.ioRedisConnection.hset(t,e,r)}catch{throw new h("RedisDataSource::hset","HSET_FAILED")}}static async hmset(t,e){try{let r={};for(let[o,n]of Object.entries(e))typeof n=="object"&&!Buffer.isBuffer(n)?r[o]=JSON.stringify(n):typeof n=="boolean"?r[o]=n.toString():r[o]=String(n);return await this.redisDataSourceInstance.ioRedisConnection.hmset(t,r)}catch{throw new h("RedisDataSource::hmset","HMSET_FAILED")}}static async hget(t,e){try{let r=await this.redisDataSourceInstance.ioRedisConnection.hget(t,e);return this.getValue(r)}catch{throw new h("RedisDataSource::hget","HGET_FAILED")}}static async hgetall(t){try{let e=await this.redisDataSourceInstance.ioRedisConnection.hgetall(t),r={};for(let[o,n]of Object.entries(e))r[o]=this.getValue(n);return r}catch{throw new h("RedisDataSource::hgetall","HGETALL_FAILED")}}static async hmget(t,...e){try{return (await this.redisDataSourceInstance.ioRedisConnection.hmget(t,...e)).map(o=>this.getValue(o))}catch{throw new h("RedisDataSource::hmget","HMGET_FAILED")}}static async hdel(t,...e){try{return await this.redisDataSourceInstance.ioRedisConnection.hdel(t,...e)}catch{throw new h("RedisDataSource::hdel","HDEL_FAILED")}}static async hexists(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.hexists(t,e)}catch{throw new h("RedisDataSource::hexists","HEXISTS_FAILED")}}static async hkeys(t){try{return await this.redisDataSourceInstance.ioRedisConnection.hkeys(t)}catch{throw new h("RedisDataSource::hkeys","HKEYS_FAILED")}}static async hlen(t){try{return await this.redisDataSourceInstance.ioRedisConnection.hlen(t)}catch{throw new h("RedisDataSource::hlen","HLEN_FAILED")}}async hset(t,e,r){try{return typeof r=="object"&&!Buffer.isBuffer(r)&&(r=JSON.stringify(r)),typeof r=="boolean"&&(r=r.toString()),await this.ioRedisConnection.hset(t,e,r)}catch{throw new h("RedisDataSource::hset","HSET_FAILED")}}async hmset(t,e){try{let r={};for(let[o,n]of Object.entries(e))typeof n=="object"&&!Buffer.isBuffer(n)?r[o]=JSON.stringify(n):typeof n=="boolean"?r[o]=n.toString():r[o]=String(n);return await this.ioRedisConnection.hmset(t,r)}catch{throw new h("RedisDataSource::hmset","HMSET_FAILED")}}async hget(t,e){try{let r=await this.ioRedisConnection.hget(t,e);return Z.getValue(r)}catch{throw new h("RedisDataSource::hget","HGET_FAILED")}}async hgetall(t){try{let e=await this.ioRedisConnection.hgetall(t),r={};for(let[o,n]of Object.entries(e))r[o]=Z.getValue(n);return r}catch{throw new h("RedisDataSource::hgetall","HGETALL_FAILED")}}async hmget(t,...e){try{return (await this.ioRedisConnection.hmget(t,...e)).map(o=>Z.getValue(o))}catch{throw new h("RedisDataSource::hmget","HMGET_FAILED")}}async hdel(t,...e){try{return await this.ioRedisConnection.hdel(t,...e)}catch{throw new h("RedisDataSource::hdel","HDEL_FAILED")}}async hexists(t,e){try{return await this.ioRedisConnection.hexists(t,e)}catch{throw new h("RedisDataSource::hexists","HEXISTS_FAILED")}}async hkeys(t){try{return await this.ioRedisConnection.hkeys(t)}catch{throw new h("RedisDataSource::hkeys","HKEYS_FAILED")}}async hlen(t){try{return await this.ioRedisConnection.hlen(t)}catch{throw new h("RedisDataSource::hlen","HLEN_FAILED")}}static async sadd(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.sadd(t,...r)}catch{throw new h("RedisDataSource::sadd","SADD_FAILED")}}static async smembers(t){try{return (await this.redisDataSourceInstance.ioRedisConnection.smembers(t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::smembers","SMEMBERS_FAILED")}}static async srem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.srem(t,...r)}catch{throw new h("RedisDataSource::srem","SREM_FAILED")}}static async sismember(t,e){try{return typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString()),await this.redisDataSourceInstance.ioRedisConnection.sismember(t,e)}catch{throw new h("RedisDataSource::sismember","SISMEMBER_FAILED")}}static async scard(t){try{return await this.redisDataSourceInstance.ioRedisConnection.scard(t)}catch{throw new h("RedisDataSource::scard","SCARD_FAILED")}}static async sinter(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sinter(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sinter","SINTER_FAILED")}}static async sunion(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sunion(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sunion","SUNION_FAILED")}}static async sdiff(...t){try{return (await this.redisDataSourceInstance.ioRedisConnection.sdiff(...t)).map(r=>this.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sdiff","SDIFF_FAILED")}}async sadd(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.sadd(t,...r)}catch{throw new h("RedisDataSource::sadd","SADD_FAILED")}}async smembers(t){try{return (await this.ioRedisConnection.smembers(t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::smembers","SMEMBERS_FAILED")}}async srem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.srem(t,...r)}catch{throw new h("RedisDataSource::srem","SREM_FAILED")}}async sismember(t,e){try{return typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString()),await this.ioRedisConnection.sismember(t,e)}catch{throw new h("RedisDataSource::sismember","SISMEMBER_FAILED")}}async scard(t){try{return await this.ioRedisConnection.scard(t)}catch{throw new h("RedisDataSource::scard","SCARD_FAILED")}}async sinter(...t){try{return (await this.ioRedisConnection.sinter(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sinter","SINTER_FAILED")}}async sunion(...t){try{return (await this.ioRedisConnection.sunion(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sunion","SUNION_FAILED")}}async sdiff(...t){try{return (await this.ioRedisConnection.sdiff(...t)).map(r=>Z.getValue(r)).filter(r=>r!==null)}catch{throw new h("RedisDataSource::sdiff","SDIFF_FAILED")}}static async zadd(t,e,r){try{if(typeof e=="number"&&r!==void 0){let o=r;return typeof r=="object"&&!Buffer.isBuffer(r)?o=JSON.stringify(r):typeof r=="boolean"&&(o=r.toString()),await this.redisDataSourceInstance.ioRedisConnection.zadd(t,e,o)}else if(Array.isArray(e)){let o=[];for(let[n,s]of e)o.push(n),typeof s=="object"&&!Buffer.isBuffer(s)?o.push(JSON.stringify(s)):typeof s=="boolean"?o.push(s.toString()):o.push(s);return await this.redisDataSourceInstance.ioRedisConnection.zadd(t,...o)}throw new Error("Invalid arguments for zadd")}catch{throw new h("RedisDataSource::zadd","ZADD_FAILED")}}static async zrange(t,e,r,o=false){try{let n;if(o){n=await this.redisDataSourceInstance.ioRedisConnection.zrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=this.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.redisDataSourceInstance.ioRedisConnection.zrange(t,e,r),n.map(s=>this.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrange","ZRANGE_FAILED")}}static async zrevrange(t,e,r,o=false){try{let n;if(o){n=await this.redisDataSourceInstance.ioRedisConnection.zrevrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=this.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.redisDataSourceInstance.ioRedisConnection.zrevrange(t,e,r),n.map(s=>this.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrevrange","ZREVRANGE_FAILED")}}static async zrem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.redisDataSourceInstance.ioRedisConnection.zrem(t,...r)}catch{throw new h("RedisDataSource::zrem","ZREM_FAILED")}}static async zscore(t,e){try{typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());let r=await this.redisDataSourceInstance.ioRedisConnection.zscore(t,e);return r!==null?Number(r):null}catch{throw new h("RedisDataSource::zscore","ZSCORE_FAILED")}}static async zcard(t){try{return await this.redisDataSourceInstance.ioRedisConnection.zcard(t)}catch{throw new h("RedisDataSource::zcard","ZCARD_FAILED")}}async zadd(t,e,r){try{if(typeof e=="number"&&r!==void 0){let o=r;return typeof r=="object"&&!Buffer.isBuffer(r)?o=JSON.stringify(r):typeof r=="boolean"&&(o=r.toString()),await this.ioRedisConnection.zadd(t,e,o)}else if(Array.isArray(e)){let o=[];for(let[n,s]of e)o.push(n),typeof s=="object"&&!Buffer.isBuffer(s)?o.push(JSON.stringify(s)):typeof s=="boolean"?o.push(s.toString()):o.push(s);return await this.ioRedisConnection.zadd(t,...o)}throw new Error("Invalid arguments for zadd")}catch{throw new h("RedisDataSource::zadd","ZADD_FAILED")}}async zrange(t,e,r,o=false){try{let n;if(o){n=await this.ioRedisConnection.zrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=Z.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.ioRedisConnection.zrange(t,e,r),n.map(s=>Z.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrange","ZRANGE_FAILED")}}async zrevrange(t,e,r,o=false){try{let n;if(o){n=await this.ioRedisConnection.zrevrange(t,e,r,"WITHSCORES");let s=[];for(let a=0;a<n.length;a+=2){let l=Z.getValue(n[a]),d=Number(n[a+1]);l!==null&&s.push({value:l,score:d});}return s}return n=await this.ioRedisConnection.zrevrange(t,e,r),n.map(s=>Z.getValue(s)).filter(s=>s!==null)}catch{throw new h("RedisDataSource::zrevrange","ZREVRANGE_FAILED")}}async zrem(t,...e){try{let r=e.map(o=>typeof o=="object"&&!Buffer.isBuffer(o)?JSON.stringify(o):typeof o=="boolean"?o.toString():o);return await this.ioRedisConnection.zrem(t,...r)}catch{throw new h("RedisDataSource::zrem","ZREM_FAILED")}}async zscore(t,e){try{typeof e=="object"&&!Buffer.isBuffer(e)&&(e=JSON.stringify(e)),typeof e=="boolean"&&(e=e.toString());let r=await this.ioRedisConnection.zscore(t,e);return r!==null?Number(r):null}catch{throw new h("RedisDataSource::zscore","ZSCORE_FAILED")}}async zcard(t){try{return await this.ioRedisConnection.zcard(t)}catch{throw new h("RedisDataSource::zcard","ZCARD_FAILED")}}static async subscribe(t,e){try{await this.redisDataSourceInstance.ioRedisConnection.subscribe(...t),this.redisDataSourceInstance.ioRedisConnection.on("message",e);}catch{throw new h("RedisDataSource::subscribe","SUBSCRIBE_FAILED")}}static async unsubscribe(...t){try{await this.redisDataSourceInstance.ioRedisConnection.unsubscribe(...t);}catch{throw new h("RedisDataSource::unsubscribe","UNSUBSCRIBE_FAILED")}}static async publish(t,e){try{let r;return typeof e=="object"&&!Buffer.isBuffer(e)?r=JSON.stringify(e):typeof e=="boolean"||typeof e=="number"?r=e.toString():Buffer.isBuffer(e)?r=e:r=String(e),await this.redisDataSourceInstance.ioRedisConnection.publish(t,r)}catch{throw new h("RedisDataSource::publish","PUBLISH_FAILED")}}static async psubscribe(t,e){try{await this.redisDataSourceInstance.ioRedisConnection.psubscribe(...t),this.redisDataSourceInstance.ioRedisConnection.on("pmessage",(r,o,n)=>{e(o,n);});}catch{throw new h("RedisDataSource::psubscribe","PSUBSCRIBE_FAILED")}}static async punsubscribe(...t){try{await this.redisDataSourceInstance.ioRedisConnection.punsubscribe(...t);}catch{throw new h("RedisDataSource::punsubscribe","PUNSUBSCRIBE_FAILED")}}async subscribe(t,e){try{await this.ioRedisConnection.subscribe(...t),this.ioRedisConnection.on("message",e);}catch{throw new h("RedisDataSource::subscribe","SUBSCRIBE_FAILED")}}async unsubscribe(...t){try{await this.ioRedisConnection.unsubscribe(...t);}catch{throw new h("RedisDataSource::unsubscribe","UNSUBSCRIBE_FAILED")}}async publish(t,e){try{let r;return typeof e=="object"&&!Buffer.isBuffer(e)?r=JSON.stringify(e):typeof e=="boolean"||typeof e=="number"?r=e.toString():Buffer.isBuffer(e)?r=e:r=String(e),await this.ioRedisConnection.publish(t,r)}catch{throw new h("RedisDataSource::publish","PUBLISH_FAILED")}}async psubscribe(t,e){try{await this.ioRedisConnection.psubscribe(...t),this.ioRedisConnection.on("pmessage",(r,o,n)=>{e(o,n);});}catch{throw new h("RedisDataSource::psubscribe","PSUBSCRIBE_FAILED")}}async punsubscribe(...t){try{await this.ioRedisConnection.punsubscribe(...t);}catch{throw new h("RedisDataSource::punsubscribe","PUNSUBSCRIBE_FAILED")}}static async exists(t){try{return await this.redisDataSourceInstance.ioRedisConnection.exists(t)}catch{throw new h("RedisDataSource::exists","EXISTS_FAILED")}}static async expire(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.expire(t,e)}catch{throw new h("RedisDataSource::expire","EXPIRE_FAILED")}}static async expireat(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.expireat(t,e)}catch{throw new h("RedisDataSource::expireat","EXPIREAT_FAILED")}}static async pexpire(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.pexpire(t,e)}catch{throw new h("RedisDataSource::pexpire","PEXPIRE_FAILED")}}static async ttl(t){try{return await this.redisDataSourceInstance.ioRedisConnection.ttl(t)}catch{throw new h("RedisDataSource::ttl","TTL_FAILED")}}static async pttl(t){try{return await this.redisDataSourceInstance.ioRedisConnection.pttl(t)}catch{throw new h("RedisDataSource::pttl","PTTL_FAILED")}}static async persist(t){try{return await this.redisDataSourceInstance.ioRedisConnection.persist(t)}catch{throw new h("RedisDataSource::persist","PERSIST_FAILED")}}static async keys(t){try{return await this.redisDataSourceInstance.ioRedisConnection.keys(t)}catch{throw new h("RedisDataSource::keys","KEYS_FAILED")}}static async rename(t,e){try{return await this.redisDataSourceInstance.ioRedisConnection.rename(t,e)}catch{throw new h("RedisDataSource::rename","RENAME_FAILED")}}static async type(t){try{return await this.redisDataSourceInstance.ioRedisConnection.type(t)}catch{throw new h("RedisDataSource::type","TYPE_FAILED")}}async exists(t){try{return await this.ioRedisConnection.exists(t)}catch{throw new h("RedisDataSource::exists","EXISTS_FAILED")}}async expire(t,e){try{return await this.ioRedisConnection.expire(t,e)}catch{throw new h("RedisDataSource::expire","EXPIRE_FAILED")}}async expireat(t,e){try{return await this.ioRedisConnection.expireat(t,e)}catch{throw new h("RedisDataSource::expireat","EXPIREAT_FAILED")}}async pexpire(t,e){try{return await this.ioRedisConnection.pexpire(t,e)}catch{throw new h("RedisDataSource::pexpire","PEXPIRE_FAILED")}}async ttl(t){try{return await this.ioRedisConnection.ttl(t)}catch{throw new h("RedisDataSource::ttl","TTL_FAILED")}}async pttl(t){try{return await this.ioRedisConnection.pttl(t)}catch{throw new h("RedisDataSource::pttl","PTTL_FAILED")}}async persist(t){try{return await this.ioRedisConnection.persist(t)}catch{throw new h("RedisDataSource::persist","PERSIST_FAILED")}}async keys(t){try{return await this.ioRedisConnection.keys(t)}catch{throw new h("RedisDataSource::keys","KEYS_FAILED")}}async rename(t,e){try{return await this.ioRedisConnection.rename(t,e)}catch{throw new h("RedisDataSource::rename","RENAME_FAILED")}}async type(t){try{return await this.ioRedisConnection.type(t)}catch{throw new h("RedisDataSource::type","TYPE_FAILED")}}static getValue(t){if(!t)return null;try{return JSON.parse(t)}catch{}return t==="true"||t==="false"?!!t:Number.isNaN(Number(t))?t:Number(t)}};Z.OK="OK";var il=Z;var al=class{constructor(t){this.dbType=t,this.migrationName=pt__default.default.basename(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))),this.schema=new ie(this.dbType);}};async function _y(i){try{return import(url.pathToFileURL(i).href)}catch{let e=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))(i);return {default:e.default||e,...e}}}async function Oy(i){let{build:t}=await import('esbuild').catch(()=>{throw new Error("esbuild is required to import TypeScript files. Install it with: npm install esbuild -D")}),e=Math.random().toString(36).slice(2,8),r=i.replace(/\.ts$/,`.bundled_${e}.mjs`);try{return await t({entryPoints:[i],bundle:!0,platform:"node",format:"esm",sourcemap:"inline",outfile:r,packages:"external",logLevel:"silent"}),await import(url.pathToFileURL(r).href)}finally{await Jr__default.default.promises.unlink(r).catch(()=>{});}}async function Up(i,t){let e=pt__default.default.isAbsolute(i)?i:pt__default.default.resolve(process.cwd(),i);return e.endsWith(".ts")?Oy(e):_y(e)}var ll=class{parseGetAllTables(t,e,r){switch(t){case "mysql":case "mariadb":return r[0].map(n=>n[`Tables_in_${e}`]);case "cockroachdb":case "postgres":return r.rows.map(n=>n.table_name);case "mssql":return r.recordset.map(n=>n.TABLE_NAME);case "oracledb":return (r.rows||[]).map(n=>Array.isArray(n)?n[0]:n?.TABLE_NAME).filter(n=>typeof n=="string"&&n.length>0);default:throw new Error(`Unsupported database type: ${t}`)}}getAllTablesTemplate(t,e){switch(t){case "mysql":case "mariadb":return `SHOW TABLES FROM ${e};`;case "cockroachdb":case "postgres":return `SELECT table_name
|
|
217
217
|
FROM information_schema.tables
|
|
218
218
|
WHERE table_catalog = '${e}'
|
|
219
219
|
AND table_schema = 'public'
|