"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")},79646:e=>{e.exports=require("child_process")},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:()=>g,default:()=>h,routeModule:()=>D});vara={};t.r(a),t.d(a,{default:()=>S});vars=t(89947),n=t(2706),o=t(96762),l=t(48786),i=t(60125),d=t(67619),u=t(69842),c=t(4820),f=t(29021),_=t.n(f),b=t(27825),E=t.n(b),m=t(76856);t(29021),t(33873);let{execSync:p}=t(79646);asyncfunctionS(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,n=e.body.table;e.body.delegated;try{leto;letd=await(0,i.A)({request:e,user:t,databaseSlug:s,query:e.query}),u=d?.rootUserId?d.rootUserId:t.id,f=`datasquirel_user_${u}_${s}`.replace(/[^a-z\_0-9]/g,"");if(d?.delegated){lete=await(0,l.A)("SELECT * FROM user_users WHERE invited_user_id=? AND user_id=? AND user_priviledge LIKE '%Edit Tables%'",[t.id,d.rootUserId]);e&&e[0]&&(o=!0)}elseo=!0;if(!o)returnr.json({success:!1,msg:"Unauthorized"});letb=(0,c.A)({userId:u});if(!b)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:t,schema:a,table:s,userId:n}){leto=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${n}/main.json`;try{if(!e)throwError("Database schema not found!");letn=E().cloneDeep(e),l=n.find(e=>e.dbFullName==t);if(!l)throwError("Old Database schema not found!");leti=n.findIndex(e=>e.dbFullName==t);if(i<0)throwError("Target Database index not found!");letd=a.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==s.tableName);if(!u)throwError("Table schema not found!");letc=l.tables.findIndex(e=>e.tableName==s.tableName);u&&(n[i].tables[c]=u);letf=l?.childrenDatabases;f?.forEach(e=>{letr=n.findIndex(r=>r.dbFullName===e.dbFullName);n[r]&&l&&(n[r].tables=l.tables.map(e=>{letr=E().cloneDeep(e);returndeleter.childrenTables,r}))});letb=n?.[i]?.tables?.[c]?.childrenTables;returnb&&b.forEach(e=>{letr=n.findIndex(r=>r.dbFullName==e.dbNameFull),t=n[r]?.tables?.findIndex(r=>r.tableName===e.tableName);n[r]?.tables[t]&&(n[r].tables[t].fields=E().cloneDeep(u.fields),n[r].tables[t].indexes=E().cloneDeep(u.indexes))}),_().writeFileSync(`${o}`,JSON.stringify(n),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.ts ERROR: ",e.message),!1}}({dbFullName:f,dbSchemaData:b,delegatedUser:d,schema:a,table:n,userId:u}))throwError("Update Failed!");returnawait(0,m.A)({userId:u,targetDatabase:f}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),(0,d.default)({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}leth=(0,o.M)(a,"default"),g=(0,o.M)(a,"config"),D=news.PagesAPIRouteModule({definition:{kind:n.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{letn=t.id,o=null;if(!s?.delegated)return{dbUserId:n};letl=s.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("Cookie not present");lett=(0,a.A)({encryptedString:e.cookies[d]});if(!t)throwError("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUse