dsql-admin/dsql-app/.local_dist/server/chunks/9814.js

25 lines
13 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";exports.id=9814,exports.ids=[9814],exports.modules={67619:(e,a,t)=>{t.d(a,{A:()=>i});var l=t(29021),r=t.n(l);async function i({user:e,message:a,component:t,noMail:l,req:i}){let n=new Date,d=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],a=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],l=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||l||a||i.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let l=`🚀 SERVER ERROR ===========================
Error Message: ${a}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(l+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),i?.url&&(l+=`
URL: ${i.url}`),i?.body&&(l+=`
Request Body: ${JSON.stringify(i.body,null,4)}`),d&&(l+=`
IP: ${d}`),l+=`
Date: ${n.toDateString()}
========================================`,r().existsSync("./.tmp/error.log")||r().writeFileSync("./.tmp/error.log","","utf-8");let u=r().readFileSync("./.tmp/error.log","utf-8");r().writeFileSync("./.tmp/error.log",l),r().appendFileSync("./.tmp/error.log",`
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},76856:(e,a,t)=>{t.d(a,{A:()=>T});var l=t(33873),r=t.n(l),i=t(29021),n=t.n(i),d=t(66866),u=t(41864);async function s({queryString:e,queryValuesArray:a}){let t;try{t=e&&a&&Array.isArray(a)&&a[0]?await (0,u.A)({query:e,values:a}):await (0,u.A)({query:e})}catch(e){console.log("Shell Vardb Error =>",e.message)}return t}function E({columnData:e,primaryKeySet:a}){let{fieldName:t,dataType:l,nullValue:r,primaryKey:i,autoIncrement:n,defaultValue:d,defaultValueLiteral:u,onUpdateLiteral:s,notNullValue:E}=e,o="";return o+=`\`${t}\` ${l}`,r?o+=" DEFAULT NULL":u?o+=` DEFAULT ${u}`:d?String(d).match(/uuid\(\)/i)?o+=" DEFAULT UUID()":o+=` DEFAULT '${d}'`:E&&(o+=" NOT NULL"),s&&(o+=` ON UPDATE ${s}`),i&&!a&&(o+=" PRIMARY KEY",a=!0),n&&(o+=" AUTO_INCREMENT",a=!0),{fieldEntryText:o,newPrimaryKeySet:a||!1}}async function o({dbFullName:e,tableName:a,tableInfoArray:l,tableSchema:r,recordedDbEntry:i}){let n=function({tableInfoArray:e}){let a=t(95610),l=e.filter(e=>e.primaryKey);return a.forEach(a=>{let t=e.filter(e=>e.fieldName===a.fieldName);t&&t[0]||("id"!==a.fieldName||l[0]?e.push(a):e.unshift(a))}),e}({tableInfoArray:l}),d=[];d.push(`CREATE TABLE IF NOT EXISTS \`${e}\`.\`${a}\` (`);try{if(!i)throw Error("Recorded Db entry not found!");let e=await s({queryString:"SELECT * FROM datasquirel.user_database_tables WHERE db_id = ? AND table_slug = ?",queryValuesArray:[i.id,r?.tableName]}),a=e?.[0];a?.id||await (0,u.A)({query:"INSERT INTO datasquirel.user_database_tables SET ?",values:{user_id:i.user_id,db_id:i.id,db_slug:i.db_slug,table_name:r?.tableFullName,table_slug:r?.tableName,child_table:r?.childTable?"1":null,child_table_parent_database:r?.childTableDbFullName||null,child_table_parent_table:r?.childTableName||null,date_created:Date(),date_created_code:Date.now(),date_updated:Date(),date_updated_code:Date.now()}})}catch(e){}let o=!1,N=[];for(let e=0;e<n.length;e++){let a=n[e],{fieldName:t,dataType:l,nullValue:r,primaryKey:i,autoIncrement:u,defaultValue:s,defaultValueLiteral:c,foreignKey:f,updatedField:T,onUpdate:m,onUpdateLiteral:A,onDelete:_,onDeleteLiteral:b,defaultField:S,encrypted:y,json:$,newTempField:g,notNullValue:R,originName:h,plainText:p,pattern:D,patternFlags:O,richText:I}=a;f&&N.push({...a});let{fieldEntryText:L,newPrimaryKeySet:C}=E({columnData:a,primaryKeySet:o});o=C;let M=N[0]?",":e===n.length-1?"":",";d.push(" "+L+M)}N[0]&&N.forEach((e,a,t)=>{let l=e.fieldName,r=e.foreignKey?.destinationTableName,i=e.foreignKey?.destinationTableColumnName,n=e.foreignKey?.cascadeDelete,u=e.foreignKey?.cascadeUpdate,s=e.foreignKey?.foreignKeyName,E=a===N.length-1?"":",";d.push(` CONSTRAINT \`${s}\` FOREIGN KEY (\`${l}\`) REFERENCES \`${r}\`(${i})${n?" ON DELETE CASCADE":""}${u?" ON UPDATE CASCADE":""}${E}`)}),d.push(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");let c=d.join("\n");return await s({queryString:c})}let N=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function c({dbFullName:e,tableName:a,tableInfoArray:t,userId:l,dbSchema:r,tableIndexes:i,tableSchema:d,clone:o,childDb:c,tableIndex:f,tableNameFull:T,recordedDbEntry:m}){let A=[],_=t;try{let t=[];if(t.push(`ALTER TABLE \`${e}\`.\`${a}\``),c)try{if(!m)throw Error("Recorded Db entry not found!");let e=await s({queryString:"SELECT * FROM datasquirel.user_database_tables WHERE db_id = ? AND table_slug = ?",queryValuesArray:[m.id,a]}),t=e?.[0];t?.id||await (0,u.A)({query:"INSERT INTO datasquirel.user_database_tables SET ?",values:{user_id:m.user_id,db_id:m.id,db_slug:m.db_slug,table_name:T,table_slug:a,child_table:d?.childTable?"1":null,child_table_parent_database:d?.childTableDbFullName||null,child_table_parent_table:d.childTableName||null,date_created:Date(),date_created_code:Date.now(),date_updated:Date(),date_updated_code:Date.now()}})}catch(e){}let f=await s({queryString:`SHOW INDEXES FROM \`${e}\`.\`${a}\``}),b=await s({queryString:`SHOW COLUMNS FROM \`${e}\`.\`${a}\``}),S=[];for
SELECT EXISTS (
SELECT
TABLE_NAME
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = ? AND
TABLE_NAME = ?
) AS tableExists`,queryValuesArray:[r,t.tableName]});if(N&&N[0]?.tableExists>0){if(await c({dbFullName:r,tableName:d,tableNameFull:t.tableFullName,tableInfoArray:u,userId:e,dbSchema:i,tableIndexes:E,tableIndex:a,childDb:l.childDatabase||void 0,recordedDbEntry:b,tableSchema:t}),t.childrenTables&&t.childrenTables[0])for(let a=0;a<t.childrenTables.length;a++){let r=t.childrenTables[a];await c({dbFullName:r.dbNameFull,tableName:r.tableName,tableNameFull:r.tableNameFull,tableInfoArray:u,userId:e,dbSchema:i,tableIndexes:E,clone:!0,childDb:l.childDatabase||void 0,recordedDbEntry:b,tableSchema:t})}}else if(await o({tableName:d,tableInfoArray:u,dbFullName:r,tableSchema:t,recordedDbEntry:b}),E&&E[0]&&E&&E[0])for(let e=0;e<E.length;e++){let{indexType:a,indexName:t,indexTableFields:l,alias:i}=E[e];if(i?.match(/./))try{if(!(await s({queryString:`SHOW INDEXES FROM \`${r}\`.\`${d}\``})).filter(e=>e.Key_name===i)[0])throw Error("This Index Does not Exist")}catch(e){await s({queryString:`CREATE${a?.match(/fullText/i)?" FULLTEXT":""} INDEX \`${i}\` ON \`${r}\`.\`${d}\`(${l?.map(e=>e.value).map(e=>`\`${e}\``).join(",")}) COMMENT 'schema_index'`})}}}if(f?.[0])for(let a=0;a<f.length;a++){let{dbFullName:t}=f[a];await T({userId:e,targetDatabase:t})}}}},41864:(e,a,t)=>{t.d(a,{A:()=>u});var l=t(29021),r=t.n(l),i=t(33873),n=t.n(i),d=t(7447);async function u({query:e,values:a}){let t;let l=(0,d.A)();try{t=e&&a?await l.query(e,a):await l.query(e)}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(l.config()),r().appendFileSync(n().resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),t=null}finally{await l?.end()}return t?JSON.parse(JSON.stringify(t)):null}},66866:(e,a,t)=>{t.d(a,{A:()=>r});var l=t(41864);async function r(e){let a;try{a=await (0,l.A)({query:e})}catch(e){console.log("ERROR in noDatabaseDbHandler =>",e.message)}return a||null}},59338:(e,a,t)=>{t.d(a,{A:()=>l});let l={parse:function(e,a){if(e){if("object"==typeof e)return e;if("string"==typeof e)try{return JSON.parse(e,a)}catch(e){return}}},stringify:function(e,a,t){try{return JSON.stringify(e,a||void 0,t)}catch(e){return}}}},95610:e=>{e.exports=JSON.parse('[{"fieldName":"id","dataType":"BIGINT","notNullValue":true,"primaryKey":true,"autoIncrement":true},{"fieldName":"uuid","dataType":"UUID","defaultValueLiteral":"UUID()"},{"fieldName":"date_created","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_created_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_created_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP"},{"fieldName":"date_updated","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_updated_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_updated_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP","onUpdateLiteral":"CURRENT_TIMESTAMP"}]')}};