"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:()=>E,default:()=>h,routeModule:()=>y});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),h=o.find(e=>e.dbFullName==u),E=g?.tables.find(e=>e.tableName==d.table),y=h?.tables.find(e=>e.tableName==s.table);if(!E||!y)throw Error("Operation Failed! Tables Schemas not present.");if(!n().isEqual(y.fields,E.fields))throw Error("Tables incompatible");switch(t){case"Push":let _=await (0,c.A)(`SELECT * FROM ${u}.${s.table}`),q=await (0,b.A)({dbName:d.db,paradigm:"import",payload:_,tableName:d.table,userId:i.rootUserId,payloadType:"object"});return await f({dbName:d.db,tableName:d.table,data:_,userId:i.rootUserId}),r.json({success:!0,payload:q});case"Pull":let $=await (0,c.A)(`SELECT * FROM ${l}.${d.table}`),I=await (0,b.A)({dbName:s.db,paradigm:"import",payload:$,tableName:s.table,userId:i.rootUserId,payloadType:"object"});return await f({dbName:s.db,tableName:s.table,data:$,userId:i.rootUserId}),r.json({success:!0,payload:I})}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 h=(0,i.M)(t,"default"),E=(0,i.M)(t,"config"),y=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}),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})();