"use strict";(()=>{var e={};e.id=538,e.ids=[538],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")},69653:(e,r,a)=>{a.r(r),a.d(r,{config:()=>h,default:()=>E,routeModule:()=>_});var t={};a.r(t),a.d(t,{default:()=>g});var s=a(89947),d=a(2706),i=a(96762),o=a(67619),l=a(69842),u=a(27825),n=a.n(u),c=a(48786),b=a(33170);async function p({tbls:e,user:r,query:a}){let t;if(!a?.delegated)return{isPriviledged:!0,rootUserId:r.id};try{for(let a=0;ae.dbFullName==l),E=o.find(e=>e.dbFullName==u),h=g?.tables.find(e=>e.tableName==i.table),_=E?.tables.find(e=>e.tableName==d.table);if(!h||!_)throw Error("Operation Failed! Tables Schemas not present.");if(!n().isEqual(_.fields,h.fields))throw Error("Tables incompatible");switch(s){case"Push":let y=await (0,c.A)(`SELECT * FROM ${u}.${d.table}`),q=await (0,b.A)({dbName:i.db,paradigm:"import",payload:y,tableName:i.table,userId:t.rootUserId,payloadType:"object"});return await f({dbName:i.db,tableName:i.table,data:y,userId:t.rootUserId}),r.json({success:!0,payload:q});case"Pull":let A=await (0,c.A)(`SELECT * FROM ${l}.${i.table}`),$=await (0,b.A)({dbName:d.db,paradigm:"import",payload:A,tableName:d.table,userId:t.rootUserId,payloadType:"object"});return await f({dbName:d.db,tableName:d.table,data:A,userId:t.rootUserId}),r.json({success:!0,payload:$})}r.json({success:!1})}catch(e){console.log(e.message),(0,o.A)({component:"/api/sync-table-data",message:e.message,user:a}),r.json({success:!1,msg:e.message})}}async function f({dbName:e,tableName:r,data:a,userId:t}){let s=`${process.env.DSQL_USER_DB_PREFIX}${t}_${e.replace(/ /g,"")}`,d=a.map(e=>e.id),i=`DELETE FROM ${s}.${r}`;d?.[0]&&(i+=` WHERE id NOT IN (${d.join(",")})`),await (0,c.A)(i)}let E=(0,i.M)(t,"default"),h=(0,i.M)(t,"config"),_=new s.PagesAPIRouteModule({definition:{kind:d.A.PAGES_API,page:"/api/sync-table-data",pathname:"/api/sync-table-data",bundlePath:"",filename:""},userland:t})},4820:(e,r,a)=>{a.d(r,{A:()=>l});var t=a(67619),s=a(29021),d=a.n(s),i=a(33873),o=a.n(i);function l({userId:e}){try{let r=o().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return JSON.parse(d().readFileSync(r,"utf-8"))}catch(e){return(0,t.A)({component:"grabUserSchemaData",message:e.message}),global.ERROR_CALLBACK?.("Error Grabbing User Schema Data",e),null}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var a=e=>r(r.s=e),t=r.X(0,[7337],()=>a(69653));module.exports=t})();