"use strict";(()=>{vare={};e.id=861,e.ids=[861],e.modules={60818:e=>{e.exports=require("dotenv")},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:()=>P,default:()=>N,routeModule:()=>A});vars={};t.r(s),t.d(s,{default:()=>I});vara=t(89947),o=t(2706),n=t(96762),l=t(51348),i=t.n(l),d=t(39831),u=t.n(d),c=t(48225),f=t.n(c),p=t(6420),_=t.n(p),b=t(2258),m=t(29021),S=t.n(m),E=t(27825),h=t.n(E),D=t(19261),g=t.n(D);t(29021),t(33873);let{execSync:v}=t(79646);asyncfunctionI(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await_()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.schema,a=e.body.database,o=e.body.table;e.body.delegated;try{letn;letl=awaitu()({request:e,user:t,databaseSlug:a,query:e.query}),d=l?.rootUserId?l.rootUserId:t.id,c=`datasquirel_user_${d}_${a}`.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:d});if(!f)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:t,schema:s,table:a,userId:o}){letn=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/main.json`;try{if(!e)throwError("Database schema not found!");leto=h().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!");letd=s.find(e=>e.dbFullName===t);if(!d)throwError("New Database schema not found!");if(r?.delegated&&(r.priviledges?.match(/create.?table/i),!r.priviledges?.match(/edit.?table/i)))throwError("Unauthorized!");letu=d.tables.find(e=>e.tableName==a.tableName);if(!u)throwError("Table schema not found!");letc=l.tables.findIndex(e=>e.tableName==a.tableName);u&&(o[i].tables[c]=u);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=h().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=h().cloneDeep(u.fields),o[r].tables[t].indexes=h().cloneDeep(u.indexes))}),S().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.js ERROR: ",e.message),!1}}({dbFullName:c,dbSchemaData:f,delegatedUser:l,schema:s,table:o,userId:d}))throwError("Update Failed!");returnawaitg()({userId:d,targetDatabase:c}),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})}}letN=(0,n.M)(s,"default"),P=(0,n.M)(s,"config"),A=newa.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:s})},39831:(e,r,t)=>{t(81630);lets=t(72835);e.exports=asyncfunction({request:e,databaseSlug:r,user:t,query:a}){try{leto=t.id,n=null;if(!a?.delegated)return{dbUserId:o};letl=a.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[d])throwError("Cook