require("./init-common-modules");const fs=require("fs"),path=require("path"),{parseJsonByPath:parseJsonByPath}=require("./utils"),UniCloud=require(path.resolve(process.env.UNICLOUD_DEBUGGER_PATH,process.env.UNICLOUD_SPACE_PROVIDER,"@dcloudio/serverless/lib/dcloud","uni-cloud.js"));function getConfig(){const e=path.resolve(process.env.WORKSPACE_FOLDER,"uniCloud-"+process.env.UNICLOUD_SPACE_PROVIDER,"config.json"),o=path.resolve(process.env.WORKSPACE_FOLDER,"uniCloud-"+process.env.UNICLOUD_SPACE_PROVIDER,"file/permission.json");let s;if(fs.existsSync(e))try{s=parseJsonByPath(e)}catch(o){throw process.send&&process.send({action:"server/error",data:{message:`Error: invalid json file: ${e}`}}),new Error(`invalid json file: ${e}`)}if(fs.existsSync(o))try{const r=parseJsonByPath(o);if(s&&!(s.storage instanceof Object))throw process.send&&process.send({action:"server/error",data:{message:`Error: invalid storage config: ${e}`}}),new Error(`invalid storage config: ${e}`);s.storage.permission=r}catch(e){throw process.send&&process.send({action:"server/error",data:{message:`Error: invalid json file: ${o}`}}),new Error(`invalid json file: ${o}`)}return s}let localConfig;try{localConfig=getConfig()}catch(e){throw process.send&&process.send({action:"server/error",data:{message:`Error: ${e.message}`}}),e}if(global.uniCloudLocalConfig=localConfig,!global.uniCloud)try{global.uniCloud=new UniCloud({spaceId:localConfig.spaceId,clientSecret:localConfig.clientSecret,mongodb:localConfig.mongodb,redis:localConfig.redis,storage:localConfig.storage,config:localConfig||{}})}catch(e){throw process.send&&process.send({action:"server/error",data:{message:`Error: ${e.message}`}}),e}