/* @alwatr/storage-sdk v4.2.1 */ "use strict";var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(r,e,t)=>e in r?i(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},m=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!p.call(r,n)&&n!==t&&i(r,n,{get:()=>e[n],enumerable:!(o=g(e,n))||o.enumerable});return r};var y=r=>m(i({},"__esModule",{value:!0}),r);var l=(r,e,t)=>(f(r,typeof e!="symbol"?e+"":e,t),t);var _={};u(_,{AlwatrStorage:()=>c});module.exports=y(_);var s=require("@alwatr/fetch"),a=require("@alwatr/logger");(0,a.definePackage)("storage-sdk","4.*");var c=class{constructor(e){this.config=e;l(this,"_logger",(0,a.createLogger)("alwatr/storage-sdk"+(this.config.name==null?"":":"+this.config.name),this.config.devMode));l(this,"fetchOption",{url:"http://"+this.config.host+":"+this.config.port+"/",keepalive:!0,timeout:this.config.timeout??0,cacheStrategy:"network_only",removeDuplicate:"never",retry:3,retryDelay:500,token:this.config.token});this._logger.logMethodArgs?.("constructor",e)}async get(e,t=this.config.name){if(this._logger.logMethodArgs?.("get",{storage:t,documentId:e}),t==null)throw new Error("storage_not_defined");return(await(0,s.serviceRequest)({...this.fetchOption,queryParameters:{storage:t,id:e}})).data}async has(e,t=this.config.name){if(this._logger.logMethodArgs?.("has",{storage:t,documentId:e}),t==null)throw new Error("storage_not_defined");let o=await(0,s.serviceRequest)({...this.fetchOption,url:this.fetchOption.url+"has",queryParameters:{storage:t,id:e}});if(typeof o.data!="boolean")throw this._logger.error("has","invalid_response_data",{responseJson:o}),new Error("invalid_response_data");return o.data}async set(e,t=this.config.name){if(this._logger.logMethodArgs?.("set",{storage:t,documentId:e.id}),t==null)throw new Error("storage_not_defined");let o=await(0,s.serviceRequest)({...this.fetchOption,method:"PATCH",queryParameters:{storage:t},bodyJson:e});if(typeof o.data?.id!="string")throw this._logger.error("set","invalid_response_data",{responseJson:o}),new Error("invalid_response_data");return o.data}async touch(e=this.config.name){if(this._logger.logMethodArgs?.("touch",{storage:e}),e==null)throw new Error("storage_not_defined");await(0,s.serviceRequest)({...this.fetchOption,method:"GET",url:this.fetchOption.url+"touch",queryParameters:{storage:e}})}async link(e,t){this._logger.logMethodArgs?.("link",{src:e,dest:t}),await(0,s.serviceRequest)({...this.fetchOption,method:"GET",url:this.fetchOption.url+"link",queryParameters:{src:e,dest:t}})}async cacheApiResponse(e,t){this._logger.logMethodArgs?.("cacheApiResponse",{path:e,data:t}),await(0,s.serviceRequest)({...this.fetchOption,method:"PUT",url:this.fetchOption.url+"cache-api-response",bodyJson:{path:e,data:t}})}async delete(e,t=this.config.name){if(this._logger.logMethodArgs?.("delete",{storage:t,documentId:e}),t==null)throw new Error("storage_not_defined");let o=await(0,s.serviceRequest)({...this.fetchOption,method:"DELETE",queryParameters:{storage:t,id:e}});if(typeof o.data!="boolean")throw this._logger.error("delete","invalid_response_data",{responseJson:o}),new Error("invalid_response_data");return o.data}async getStorage(e=this.config.name){if(this._logger.logMethodArgs?.("getStorage",{name:e}),e==null)throw new Error("storage_not_defined");let t=await(0,s.serviceRequest)({...this.fetchOption,url:this.fetchOption.url+"storage",queryParameters:{name:e}}),o=typeof t.data=="object",n=typeof t.meta=="object",h=typeof t.meta.lastUpdated=="number";if(!o||!n||!h)throw this._logger.error("getStorage","invalid_response_data",{responseJson:t}),new Error("invalid_response_data");return t}async keys(e=this.config.name){if(this._logger.logMethodArgs?.("keys",{storage:e}),e==null)throw new Error("storage_not_defined");let t=await(0,s.serviceRequest)({...this.fetchOption,url:this.fetchOption.url+"keys",queryParameters:{storage:e}});if(!Array.isArray(t.data))throw this._logger.error("keys","invalid_response_data",{responseJson:t}),new Error("invalid_response_data");return t.data}};0&&(module.exports={AlwatrStorage}); //# sourceMappingURL=main.cjs.map