"use strict";(()=>{vare={};e.id=8275,e.ids=[8275],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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")},47122:(e,a,t)=>{t.r(a),t.d(a,{config:()=>h,default:()=>f,routeModule:()=>g});varl={};t.r(l),t.d(l,{default:()=>N});vars=t(89947),r=t(2706),d=t(96762),i=t(67619),n=t(69842),u=t(4820),b=t(27825),o=t.n(b),c=t(21724),m=t(48786),p=t(98e3),_=t(76856);asyncfunctionN(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lett=await(0,n.A)(e,a,!0);if(!t)returnconsole.log("No User"),a.json({success:!1,msg:"Unauthorized"});let{payload:l}=e.body,s=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),r=e.body.dbSlug,d=e.body.dbId,b=e.body.parentDatabase,N=e.body.parentTable;try{lete=(0,u.A)({userId:t.id});if(!e)throwError("No User Schema found!");letn=e.findIndex(e=>e.dbFullName===s),f=e[n];if(!f)throwError("No Target Database Found!");leth=f.tables.findIndex(e=>e.tableName===l.tableName);if(h>=0?e[n].tables[h]=l:e[n].tables.push(l),l?.childTable){leta=e.find(e=>e.dbFullName===b),t=a?.tables.find(e=>{if(e.tableName===N)return!0});if(!t)throwError("Child Table Parent Doesn't Exist!");t.childrenTables?.[0]?t.childrenTables.push({dbNameFull:s,tableName:l.tableName,tableNameFull:l.tableNameFull}):t.childrenTables=[{dbNameFull:s,tableName:l.tableName,tableNameFull:l.tableFullName}]}if(f.childrenDatabases)for(leta=0;a<f.childrenDatabases.length;a++){lets=f.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===s.dbFullName);e[a]&&(e[a].tables=o().cloneDeep(f.tables));letr=await(0,m.A)("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[t.id,s.dbFullName]),d=await(0,m.A)("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[r[0].id,t.id,l.tableName]);if(d?.[0])continue;await(0,p.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:t.id,db_id:r[0].id,db_slug:r[0].db_slug,table_name:l.tableFullName,table_slug:l.tableName}})}catch(e){(0,i.A)({component:"/api/addUserTable/lines-124-140",message:e.message,user:t})}}(0,c.A)({userId:t.id,schemaData:e});letg={user_id:t.id,db_id:d,db_slug:r,table_name:l.tableFullName,table_slug:l.tableName};l?.childTable&&(g.child_table="1",g.child_table_parent_database=b,g.child_table_parent_table=N),await(0,p.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:g}),await(0,_.A)({userId:t.id,targetDatabase:s}),a.json({success:!0})}catch(e){console.log(e.message),(0,i.A)({component:"/api/addUserTable/main-catch-error",message:e.message,user:t}),a.json({success:!1,msg:"Database Files could not be written!"})}}letf=(0,d.M)(l,"default"),h=(0,d.M)(l,"config"),g=news.PagesAPIRouteModule({definition:{kind:r.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:l})},69842:(e,a,t)=>{t.d(a,{A:()=>r});varl=t(39908),s=t.n(l);asyncfunctionr(e,a,t){letl=s()({req:e,level:t?"deep":void0});returnconsole.log(l),l.payload}},4820:(e,a,t)=>{t.d(a,{A:()=>n});varl=t(67619),s=t(29021),r=t.n(s),d=t(33873),i=t.n(d);functionn({userId:e}){try{leta=i().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);returnJSON.parse(r().readFileSync(a,"utf-8"))}catch(e){return(0,l.A)({component:"grabUserSchemaData",message:e.message}),null}}},21724:(e,a,t)=>{t.d(a,{A:()=>n});varl=t(67619),s=t(29021),r=t.n(s),d=t(33873),i=t.n(d);functionn({userId:e,schemaData:a}){try{lett=i().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);returnr().writeFileSync(t,JSON.stringify(a),"utf8"),!0}catch(e){return(0,l.A)({component:"/functions/backend/setUserSchemaData",message:e.message}),!1}}}};vara=require("../../webpack-api-runtime.j