@noormdev/cli 1.0.0-alpha.0 → 1.0.0-alpha.1

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.
@@ -0,0 +1 @@
1
+ import{a as O}from"./chunk-4MUZ22JB.js";import{a as R,b as I,c as L,d as N,e as d,f as k}from"./chunk-MQJKW43U.js";import{G as P,K as u,W as l,a as C,b as E,c as b,d as g,e as A,f as D,g as v,h as S,k as c}from"./chunk-O7NFFKRC.js";import"./chunk-DGJUBN33.js";var h=class extends N{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await l`exec sp_getapplock @DbPrincipal = ${l.lit("dbo")}, @Resource = ${l.lit(d)}, @LockMode = ${l.lit("Exclusive")}`.execute(e)}async releaseMigrationLock(){}};var x=Symbol(),q=Symbol(),j=Symbol(),p=class{#e;#t;constructor(e){this.#e=c({...e});let{tarn:t,tedious:n,validateConnections:s}=this.#e,{validateConnections:i,...a}=t.options;this.#t=new t.Pool({...a,create:async()=>{let r=await n.connectionFactory();return await new T(r,n).connect()},destroy:async r=>{await r[q]()},validate:s===!1||i===!1?void 0:r=>r[j]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){(this.#e.resetConnectionsOnRelease||this.#e.tedious.resetConnectionOnRelease)&&await e[x](),this.#t.release(e)}async destroy(){await this.#t.destroy()}},T=class{#e;#t;#n;constructor(e,t){this.#e=e,this.#t=!1,this.#n=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((n,s)=>this.#e.beginTransaction(i=>{i?s(i):n(void 0)},t?P(8):void 0,t?this.#i(t):void 0))}async commitTransaction(){await new Promise((e,t)=>this.#e.commitTransaction(n=>{n?t(n):e(void 0)}))}async connect(){let{promise:e,reject:t,resolve:n}=new u;this.#e.connect(i=>{if(i)return t(i);n()}),this.#e.on("error",i=>{i instanceof Error&&"code"in i&&i.code==="ESOCKET"&&(this.#t=!0),console.error(i),t(i)});function s(){t(new Error("The connection ended without ever completing the connection"))}return this.#e.once("end",s),await e,this.#e.off("end",s),this}async executeQuery(e){try{let t=new u,n=new m({compiledQuery:e,tedious:this.#n,onDone:t});this.#e.execSql(n.request);let{rowCount:s,rows:i}=await t.promise;return{numAffectedRows:s!==void 0?BigInt(s):void 0,rows:i}}catch(t){throw O(t,new Error)}}async rollbackTransaction(e){await new Promise((t,n)=>this.#e.rollbackTransaction(s=>{s?n(s):t(void 0)},e))}async savepoint(e){await new Promise((t,n)=>this.#e.saveTransaction(s=>{s?n(s):t(void 0)},e))}async*streamQuery(e,t){if(!Number.isInteger(t)||t<=0)throw new Error("chunkSize must be a positive integer");let n=new m({compiledQuery:e,streamChunkSize:t,tedious:this.#n});this.#e.execSql(n.request);try{for(;;){let s=await n.readChunk();if(s.length===0||(yield{rows:s},s.length<t))break}}finally{await this.#s(n)}}#i(e){let{ISOLATION_LEVEL:t}=this.#n,s={"read committed":t.READ_COMMITTED,"read uncommitted":t.READ_UNCOMMITTED,"repeatable read":t.REPEATABLE_READ,serializable:t.SERIALIZABLE,snapshot:t.SNAPSHOT}[e];if(s===void 0)throw new Error(`Unknown isolation level: ${e}`);return s}#s(e){return new Promise(t=>{e.request.once("requestCompleted",t),this.#e.cancel()||(e.request.off("requestCompleted",t),t())})}[q](){return"closed"in this.#e&&this.#e.closed?Promise.resolve():new Promise(e=>{this.#e.once("end",e),this.#e.close()})}async[x](){await new Promise((e,t)=>{this.#e.reset(n=>{if(n)return t(n);e()})})}async[j](){if(this.#t||this.#o())return!1;try{let e=new u,t=new m({compiledQuery:L.raw("select 1"),onDone:e,tedious:this.#n});return this.#e.execSql(t.request),await e.promise,!0}catch{return!1}}#o(){return"closed"in this.#e&&!!this.#e.closed}},m=class{#e;#t;#n;#i;#s;#o;constructor(e){let{compiledQuery:t,onDone:n,streamChunkSize:s,tedious:i}=e;if(this.#t=[],this.#n=s,this.#i={},this.#s=i,n){let a="onDone";this.#i[a]=(r,w)=>{if(r!=="chunkReady"){if(delete this.#i[a],r==="error")return n.reject(w);n.resolve({rowCount:this.#o,rows:this.#t})}}}this.#e=new this.#s.Request(t.sql,(a,r)=>{if(a)return Object.values(this.#i).forEach(w=>w("error",a instanceof AggregateError?a.errors:a));this.#o=r}),this.#a(t.parameters),this.#r()}get request(){return this.#e}readChunk(){let e=this.readChunk.name;return new Promise((t,n)=>{this.#i[e]=(s,i)=>{if(delete this.#i[e],s==="error")return n(i);t(this.#t.splice(0,this.#n))},this.#e.resume()})}#a(e){for(let t=0;t<e.length;t++){let n=e[t];this.#e.addParameter(String(t+1),this.#c(n),n)}}#r(){let e=this.#n?()=>{this.#n<=this.#t.length&&(this.#e.pause(),Object.values(this.#i).forEach(n=>n("chunkReady")))}:()=>{},t=n=>{let s={};for(let i of n)s[i.metadata.colName]=i.value;this.#t.push(s),e()};this.#e.on("row",t),this.#e.once("requestCompleted",()=>{Object.values(this.#i).forEach(n=>n("completed")),this.#e.off("row",t)})}#c(e){return A(e)||C(e)||E(e)?this.#s.TYPES.NVarChar:v(e)||b(e)&&e%1===0?e<-2147483648||e>2147483647?this.#s.TYPES.BigInt:this.#s.TYPES.Int:b(e)?this.#s.TYPES.Float:g(e)?this.#s.TYPES.Bit:D(e)?this.#s.TYPES.DateTime:S(e)?this.#s.TYPES.VarBinary:this.#s.TYPES.NVarChar}};var _=class{#e;constructor(e){this.#e=e}async getSchemas(){return await this.#e.selectFrom("sys.schemas").select("name").execute()}async getTables(e={withInternalKyselyTables:!1}){let t=await this.#e.selectFrom("sys.tables as tables").leftJoin("sys.schemas as table_schemas","table_schemas.schema_id","tables.schema_id").innerJoin("sys.columns as columns","columns.object_id","tables.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",s=>s.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!e.withInternalKyselyTables,s=>s.where("tables.name","!=",d).where("tables.name","!=",k)).select(["tables.name as table_name",s=>s.ref("tables.type").$castTo().as("table_type"),"table_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"]).unionAll(this.#e.selectFrom("sys.views as views").leftJoin("sys.schemas as view_schemas","view_schemas.schema_id","views.schema_id").innerJoin("sys.columns as columns","columns.object_id","views.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",s=>s.onRef("comments.major_id","=","views.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).select(["views.name as table_name","views.type as table_type","view_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"])).orderBy("table_schema_name").orderBy("table_name").orderBy("column_name").execute(),n={};for(let s of t){let i=`${s.table_schema_name}.${s.table_name}`;(n[i]=n[i]||c({columns:[],isView:s.table_type==="V ",name:s.table_name,schema:s.table_schema_name??void 0})).columns.push(c({dataType:s.type_name,dataTypeSchema:s.type_schema_name??void 0,hasDefaultValue:s.column_default_object_id>0||s.column_generated_always_type!=="NOT_APPLICABLE"||s.column_is_identity||s.column_is_computed||s.column_is_rowguidcol,isAutoIncrementing:s.column_is_identity,isNullable:s.column_is_nullable&&s.type_is_nullable,name:s.column_name,comment:s.column_comment??void 0}))}return Object.values(n)}async getMetadata(e){return{tables:await this.getTables(e)}}};var B=/^[a-z0-9_]$/i,y=class extends I{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(e){super.visitOffset(e),this.append(" rows")}compileColumnAlterations(e){let t={};for(let s of e)t[s.kind]||(t[s.kind]=[]),t[s.kind].push(s);let n=!0;t.AddColumnNode&&(this.append("add "),this.compileList(t.AddColumnNode),n=!1),t.AlterColumnNode&&(n||this.append(", "),this.compileList(t.AlterColumnNode)),t.DropColumnNode&&(n||this.append(", "),this.append("drop column "),this.compileList(t.DropColumnNode)),t.ModifyColumnNode&&(n||this.append(", "),this.compileList(t.ModifyColumnNode)),t.RenameColumnNode&&(n||this.append(", "),this.compileList(t.RenameColumnNode))}visitAddColumn(e){this.visitNode(e.column)}visitDropColumn(e){this.visitNode(e.column)}visitMergeQuery(e){super.visitMergeQuery(e),this.append(";")}visitCollate(e){this.append("collate ");let{name:t}=e.collation;for(let n of t)if(!B.test(n))throw new Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}};var f=class{#e;constructor(e){this.#e=e}createDriver(){return new p(this.#e)}createQueryCompiler(){return new y}createAdapter(){return new h}createIntrospector(e){return new _(e)}};async function ae(o){let e=await import("./tedious-R2TVM4UU.js"),t=await import("./tarn-E5JKU5EV.js"),n=new R({dialect:new f({tarn:{...t,options:{min:o.pool?.min??0,max:o.pool?.max??10}},tedious:{...e,connectionFactory:()=>new e.Connection({server:o.host??"localhost",authentication:{type:"default",options:{userName:o.user,password:o.password}},options:{port:o.port??1433,database:o.database,trustServerCertificate:!o.ssl,encrypt:!!o.ssl}})}})});return{db:n,dialect:"mssql",destroy:()=>n.destroy()}}export{ae as createMssqlConnection};
@@ -0,0 +1 @@
1
+ import{a as M}from"./chunk-4MUZ22JB.js";import{a as u}from"./chunk-BX5KFQ6D.js";import{a as T,b as y,c,d as _,e as L,f as C}from"./chunk-MQJKW43U.js";import{H as l,W as o,i as A,j as w,k as i}from"./chunk-O7NFFKRC.js";import"./chunk-DGJUBN33.js";var N=Symbol(),m=class{#e;#t=new WeakMap;#n;constructor(e){this.#e=i({...e})}async init(){this.#n=A(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#s(),t=this.#t.get(e);return t||(t=new E(e),this.#t.set(e,t),this.#e?.onCreateConnection&&await this.#e.onCreateConnection(t)),this.#e?.onReserveConnection&&await this.#e.onReserveConnection(t),t}async#s(){return new Promise((e,t)=>{this.#n.getConnection(async(n,s)=>{n?t(n):e(s)})})}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let n=[];t.isolationLevel&&n.push(`isolation level ${t.isolationLevel}`),t.accessMode&&n.push(t.accessMode);let s=`set transaction ${n.join(", ")}`;await e.executeQuery(c.raw(s))}await e.executeQuery(c.raw("begin"))}async commitTransaction(e){await e.executeQuery(c.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(c.raw("rollback"))}async savepoint(e,t,n){await e.executeQuery(n(u("savepoint",t),l()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(u("rollback to",t),l()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(u("release savepoint",t),l()))}async releaseConnection(e){e[N]()}async destroy(){return new Promise((e,t)=>{this.#n.end(n=>{n?t(n):e()})})}};function O(r){return w(r)&&"insertId"in r&&"affectedRows"in r}var E=class{#e;constructor(e){this.#e=e}async executeQuery(e){try{let t=await this.#t(e);if(O(t)){let{insertId:n,affectedRows:s,changedRows:a}=t;return{insertId:n!=null&&n.toString()!=="0"?BigInt(n):void 0,numAffectedRows:s!=null?BigInt(s):void 0,numChangedRows:a!=null?BigInt(a):void 0,rows:[]}}else if(Array.isArray(t))return{rows:t};return{rows:[]}}catch(t){throw M(t,new Error)}}#t(e){return new Promise((t,n)=>{this.#e.query(e.sql,e.parameters,(s,a)=>{s?n(s):t(a)})})}async*streamQuery(e,t){let n=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let s of n)yield{rows:[s]}}catch(s){if(s&&typeof s=="object"&&"code"in s&&s.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw s}}[N](){this.#e.release()}};var I=/`/g,p=class extends y{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return"`"}getRightIdentifierWrapper(){return"`"}sanitizeIdentifier(e){return e.replace(I,"``")}visitCreateIndex(e){this.append("create "),e.unique&&this.append("unique "),this.append("index "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),e.using&&(this.append(" using "),this.visitNode(e.using)),e.table&&(this.append(" on "),this.visitNode(e.table)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.where&&(this.append(" "),this.visitNode(e.where))}};var f=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map(t=>({name:t.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",s=>s.onRef("columns.TABLE_CATALOG","=","tables.TABLE_CATALOG").onRef("columns.TABLE_SCHEMA","=","tables.TABLE_SCHEMA").onRef("columns.TABLE_NAME","=","tables.TABLE_NAME")).select(["columns.COLUMN_NAME","columns.COLUMN_DEFAULT","columns.TABLE_NAME","columns.TABLE_SCHEMA","tables.TABLE_TYPE","columns.IS_NULLABLE","columns.DATA_TYPE","columns.EXTRA","columns.COLUMN_COMMENT"]).where("columns.TABLE_SCHEMA","=",o`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();e.withInternalKyselyTables||(t=t.where("columns.TABLE_NAME","!=",L).where("columns.TABLE_NAME","!=",C));let n=await t.execute();return this.#t(n)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){return e.reduce((t,n)=>{let s=t.find(a=>a.name===n.TABLE_NAME);return s||(s=i({name:n.TABLE_NAME,isView:n.TABLE_TYPE==="VIEW",schema:n.TABLE_SCHEMA,columns:[]}),t.push(s)),s.columns.push(i({name:n.COLUMN_NAME,dataType:n.DATA_TYPE,isNullable:n.IS_NULLABLE==="YES",isAutoIncrementing:n.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:n.COLUMN_DEFAULT!==null,comment:n.COLUMN_COMMENT===""?void 0:n.COLUMN_COMMENT})),t},[])}};var x="ea586330-2c93-47c8-908d-981d9d270f9d",R=3600,h=class extends _{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await o`select get_lock(${o.lit(x)}, ${o.lit(R)})`.execute(e)}async releaseMigrationLock(e,t){await o`select release_lock(${o.lit(x)})`.execute(e)}};var d=class{#e;constructor(e){this.#e=e}createDriver(){return new m(this.#e)}createQueryCompiler(){return new p}createAdapter(){return new h}createIntrospector(e){return new f(e)}};async function X(r){let e=await import("./mysql2-KRZWXZIF.js"),n=(e.default?.createPool??e.createPool)({host:r.host??"localhost",port:r.port??3306,user:r.user,password:r.password,database:r.database,connectionLimit:r.pool?.max??10,ssl:r.ssl?{}:void 0}),s=new T({dialect:new d({pool:n})});return{db:s,dialect:"mysql",destroy:()=>s.destroy()}}export{X as createMysqlConnection};