"use strict";(()=>{vare={};e.id=861,e.ids=[861],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},15679:(e,r,a)=>{a.r(r),a.d(r,{config:()=>h,default:()=>D,routeModule:()=>E});vart={};a.r(t),a.d(t,{default:()=>b});vars=a(89947),o=a(2706),l=a(96762),n=a(48786),i=a(60125),d=a(67619),u=a(69842),c=a(4820),p=a(29021),m=a.n(p),_=a(27825),f=a.n(_),S=a(10776);asyncfunctionb(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});let{user:a,appData:t}=await(0,u.A)(e,r,!0);if(!a)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.schema,o=e.body.database,l=e.body.table;e.body.delegated;try{lett;letd=await(0,i.A)({request:e,user:a,databaseSlug:o,query:e.query}),u=d?.rootUserId?d.rootUserId:a.id,p=`datasquirel_user_${u}_${o}`.replace(/[^a-z\_0-9]/g,"");if(d?.delegated){lete=await(0,n.A)("SELECT * FROM user_users WHERE invited_user_id=? AND user_id=? AND user_priviledge LIKE '%Edit Tables%'",[a.id,d.rootUserId]);e&&e[0]&&(t=!0)}elset=!0;if(!t)returnr.json({success:!1,msg:"Unauthorized"});let_=(0,c.A)({userId:u});if(!_)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:a,schema:t,table:s,userId:o}){letl=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/main.json`;try{if(!e)throwError("Database schema not found!");leto=f().cloneDeep(e),n=o.find(e=>e.dbFullName==a);if(!n)throwError("Old Database schema not found!");leti=o.findIndex(e=>e.dbFullName==a);if(i<0)throwError("Target Database index not found!");letd=t.find(e=>e.dbFullName===a);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=n.tables.findIndex(e=>e.tableName==s.tableName);u&&(o[i].tables[c]=u);letp=n?.childrenDatabases;p?.forEach(e=>{letr=o.findIndex(r=>r.dbFullName===e.dbFullName);o[r]&&n&&(o[r].tables=n.tables.map(e=>{letr=f().cloneDeep(e);returndeleter.childrenTables,r}))});let_=o?.[i]?.tables?.[c]?.childrenTables;return_&&_.forEach(e=>{letr=o.findIndex(r=>r.dbFullName==e.dbNameFull),a=o[r]?.tables?.findIndex(r=>r.tableName===e.tableName);o[r]?.tables[a]&&(o[r].tables[a].fields=f().cloneDeep(u.fields),o[r].tables[a].indexes=f().cloneDeep(u.indexes))}),m().writeFileSync(`${l}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.ts ERROR: ",e.message),!1}}({dbFullName:p,dbSchemaData:_,delegatedUser:d,schema:s,table:l,userId:u}))throwError("Update Failed!");returnawait(0,S.A)({userId:u,targetDatabase:p}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),(0,d.A)({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:a}),r.json({success:!1,msg:e.message})}}letD=(0,l.M)(t,"default"),h=(0,l.M)(t,"config"),E=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:t})},55153:(e,r,a)=>{a.d(r,{On:()=>s.a,_n:()=>l}),a(76102);vart=a(65967),s=a.n(t);a(30889);varo=a(93726);letl=a.n(o)()},60125:(e,r,a)=>{a.d(r,{A:()=>s});vart=a(95969);asyncfunctions({request:e,databaseSlug:r,user:a,query:s}){try{leto=a.id,l