"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")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},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}}})},15679:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>h,routeModule:()=>g});vara={};t.r(a),t.d(a,{default:()=>m});vars=t(89947),o=t(2706),n=t(96762),i=t(48786),d=t(60125),l=t(67619),u=t(69842),c=t(4820),f=t(29021),_=t.n(f),E=t(27825),b=t.n(E),p=t(76856);asyncfunctionm(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,u.A)(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=await(0,d.A)({request:e,user:t,databaseSlug:s,query:e.query}),u=l?.rootUserId?l.rootUserId:t.id,f=`datasquirel_user_${u}_${s}`.replace(/[^a-z\_0-9]/g,"");if(l?.delegated){lete=await(0,i.A)("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"});letE=(0,c.A)({userId:u});if(!E)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=b().cloneDeep(e),i=o.find(e=>e.dbFullName==t);if(!i)throwError("Old Database schema not found!");letd=o.findIndex(e=>e.dbFullName==t);if(d<0)throwError("Target Database index not found!");letl=a.find(e=>e.dbFullName===t);if(!l)throwError("New Database schema not found!");if(r?.delegated&&(r.priviledges?.match(/create.?table/i),!r.priviledges?.match(/edit.?table/i)))throwError("Unauthorized!");letu=l.tables.find(e=>e.tableName==s.tableName);if(!u)throwError("Table schema not found!");letc=i.tables.findIndex(e=>e.tableName==s.tableName);u&&(o[d].tables[c]=u);letf=i?.childrenDatabases;f?.forEach(e=>{letr=o.findIndex(r=>r.dbFullName===e.dbFullName);o[r]&&i&&(o[r].tables=i.tables.map(e=>{letr=b().cloneDeep(e);returndeleter.childrenTables,r}))});letE=o?.[d]?.tables?.[c]?.childrenTables;returnE&&E.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=b().cloneDeep(u.fields),o[r].tables[t].indexes=b().cloneDeep(u.indexes))}),_().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.ts ERROR: ",e.message),!1}}({dbFullName:f,dbSchemaData:E,delegatedUser:l,schema:a,table:o,userId:u}))throwError("Update Failed!");returnawait(0,p.A)({userId:u,targetDatabase:f}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),(0,l.A)({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}leth=(0,n.M)(a,"default"),S=(0,n.M)(a,"config"),g=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:a})},60125:(e,r,t)=>{t.d(r,{A:()=>s});vara=t(95969);asyncfunctions({request:e,databaseSlug:r,user:t,query:s}){try{leto=t.id,n=null;if(!s?.delegated)return{dbUserId:o};leti=s.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,l=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[l])throwError("Cookie not present");lett=(0,a.A)({encryptedString:e.cookies[l]});if(!t)throwError("Invalid Token");if((n=JSON.parse(t)).databaseSlug===r)return{dbUserId:o=n.rootUserId,rootUserId:n.rootUserId,rootUserName:n.rootUserName,rootUserEmail:n.rootUser