"use strict";(()=>{vare={};e.id=861,e.ids=[861],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,t){returntinr?r[t]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,t)):"function"==typeofr&&"default"===t?r:void0}}})},23249:(e,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>v,routeModule:()=>P});vara={};t.r(a),t.d(a,{default:()=>y});vars=t(89947),o=t(2706),n=t(96762),l=t(51348),i=t.n(l),u=t(39831),d=t.n(u),c=t(77538),f=t.n(c),p=t(6420),m=t.n(p),b=t(49827),S=t(29021),_=t.n(S),h=t(27825),E=t.n(h);t(29021);letg=t(33873),{execSync:D}=t(79646);asyncfunctiony(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitm()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});leta=e.body.schema,s=e.body.database,o=e.body.table;e.body.delegated;try{letn;letl=awaitd()({request:e,user:t,databaseSlug:s,query:e.query}),u=l?.rootUserId?l.rootUserId:t.id,c=`datasquirel_user_${u}_${s}`.replace(/[^a-z\_0-9]/g,"");if(l?.delegated){lete=awaiti()("SELECT * FROM user_users WHERE invited_user_id=? AND user_id=? AND user_priviledge LIKE '%Edit Tables%'",[t.id,l.rootUserId]);e&&e[0]&&(n=!0)}elsen=!0;if(!n)returnr.json({success:!1,msg:"Unauthorized"});letf=(0,b.default)({userId:u});if(!f)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:t,schema:a,table:s,userId:o}){letn=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/main.json`;try{if(!e)throwError("Database schema not found!");leto=E().cloneDeep(e),l=o.find(e=>e.dbFullName==t);if(!l)throwError("Old Database schema not found!");leti=o.findIndex(e=>e.dbFullName==t);if(i<0)throwError("Target Database index not found!");letu=a.find(e=>e.dbFullName===t);if(!u)throwError("New Database schema not found!");if(r?.delegated&&(r.priviledges?.match(/create.?table/i),!r.priviledges?.match(/edit.?table/i)))throwError("Unauthorized!");letd=u.tables.find(e=>e.tableName==s.tableName);if(!d)throwError("Table schema not found!");letc=l.tables.findIndex(e=>e.tableName==s.tableName);d&&(o[i].tables[c]=d);letf=l?.childrenDatabases;f?.forEach(e=>{letr=o.findIndex(r=>r.dbFullName===e.dbFullName);o[r]&&l&&(o[r].tables=l.tables.map(e=>{letr=E().cloneDeep(e);returndeleter.childrenTables,r}))});letp=o?.[i]?.tables?.[c]?.childrenTables;returnp&&p.forEach(e=>{letr=o.findIndex(r=>r.dbFullName==e.dbNameFull),t=o[r]?.tables?.findIndex(r=>r.tableName===e.tableName);o[r]?.tables[t]&&(o[r].tables[t].fields=E().cloneDeep(d.fields),o[r].tables[t].indexes=E().cloneDeep(d.indexes))}),_().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.js ERROR: ",e.message),!1}}({dbFullName:c,dbSchemaData:f,delegatedUser:l,schema:a,table:o,userId:u}))throwError("Update Failed!");letp=g.join(process.cwd(),"/shell");D(`node createDbFromSchema.js --user ${u} --database ${c}`,{cwd:p}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),f()({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}letv=(0,n.M)(a,"default"),A=(0,n.M)(a,"config"),P=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:a})},39831:(e,r,t)=>{t(81630);leta=t(72907);e.exports=asyncfunction({request:e,databaseSlug:r,user:t,query:s}){try{leto=t.id,n=null;if(!s?.delegated)return{dbUserId:o};letl=s.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[u])throwError(