"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:()=>A,routeModule:()=>O});vars={};t.r(s),t.d(s,{default:()=>N});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),_=t.n(c),p=t(6420),f=t.n(p),m=t(2258),b=t.n(m),S=t(29021),E=t.n(S),D=t(27825),h=t.n(D),g=t(19261),I=t.n(g);t(29021),t(33873);let{execSync:v}=t(79646);asyncfunctionN(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitf()(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"});let_=b()({userId:d});if(!_)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);let_=l?.childrenDatabases;_?.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))}),E().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.js ERROR: ",e.message),!1}}({dbFullName:c,dbSchemaData:_,delegatedUser:l,schema:s,table:o,userId:d}))throwError("Update Failed!");returnawaitI()({userId:d,targetDatabase:c}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),_()({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}letA=(0,n.M)(s,"default"),P=(0,n.M)(s,"config"),O=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("Cooki