import{prefixUrl as e}from"@clevercloud/client/esm/prefix-url.js";import{request as t}from"@clevercloud/client/esm/request.fetch.js";import{withOptions as o}from"@clevercloud/client/esm/with-options.js";class r{constructor(e){this._apiConfig=e,this._abortController=new AbortController}close(){this._abortController.abort()}async ping(){return"PONG"===(await this.sendCommand("PING",[])).result}scanKeys({cursor:e,count:t,type:o,match:r}={}){return Promise.resolve({method:"post",url:"/keys/_scan",body:{cursor:e,count:t,type:o,match:r}}).then(this._sendToKvProxy())}deleteKey(e){return Promise.resolve({method:"post",url:"/key/_delete",body:{key:e}}).then(this._sendToKvProxy())}getStringKey(e,t){return Promise.resolve({method:"post",url:"/key/string/_get",body:{key:e}}).then(this._sendToKvProxy(t))}createStringKey(e,t){return Promise.resolve({method:"post",url:"/key/string/_create",body:{key:e,value:t}}).then(this._sendToKvProxy())}updateStringKey(e,t){return Promise.resolve({method:"post",url:"/key/string/_update",body:{key:e,value:t}}).then(this._sendToKvProxy())}createHashKey(e,t){return Promise.resolve({method:"post",url:"/key/hash/_create",body:{key:e,elements:t}}).then(this._sendToKvProxy())}scanHash(e,t,{cursor:o,count:r,match:s}={}){return Promise.resolve({method:"post",url:"/key/hash/_scan",body:{key:e,cursor:o,count:r,match:s}}).then(this._sendToKvProxy(t))}deleteHashElement(e,t){return Promise.resolve({method:"post",url:"/key/hash/_delete",body:{key:e,field:t}}).then(this._sendToKvProxy())}setHashElement(e,t,o){return Promise.resolve({method:"post",url:"/key/hash/_set",body:{key:e,field:t,value:o}}).then(this._sendToKvProxy())}createListKey(e,t){return Promise.resolve({method:"post",url:"/key/list/_create",body:{key:e,elements:t}}).then(this._sendToKvProxy())}scanList(e,t,{cursor:o,count:r,match:s}={}){return Promise.resolve({method:"post",url:"/key/list/_scan",body:{key:e,cursor:o,count:r,match:s}}).then(this._sendToKvProxy(t))}getListElementAt(e,t,o){return Promise.resolve({method:"post",url:"/key/list/_get",body:{key:e,index:t}}).then(this._sendToKvProxy(o))}updateListElement(e,t,o){return Promise.resolve({method:"post",url:"/key/list/_update",body:{key:e,index:t,value:o}}).then(this._sendToKvProxy())}pushListElement(e,t,o){return Promise.resolve({method:"post",url:"/key/list/_push",body:{key:e,position:t,value:o}}).then(this._sendToKvProxy())}createSetKey(e,t){return Promise.resolve({method:"post",url:"/key/set/_create",body:{key:e,elements:t}}).then(this._sendToKvProxy())}scanSet(e,t,{cursor:o,count:r,match:s}={}){return Promise.resolve({method:"post",url:"/key/set/_scan",body:{key:e,cursor:o,count:r,match:s}}).then(this._sendToKvProxy(t))}deleteSetElement(e,t){return Promise.resolve({method:"post",url:"/key/set/_delete",body:{key:e,element:t}}).then(this._sendToKvProxy())}addSetElement(e,t){return Promise.resolve({method:"post",url:"/key/set/_set",body:{key:e,element:t}}).then(this._sendToKvProxy())}sendCommandLine(e){return Promise.resolve({method:"post",url:"/command/cli",body:{commandLine:e}}).then(this._sendToKvProxy())}sendCommand(e,t){return Promise.resolve({method:"post",url:"/command",body:{command:e,args:t}}).then(this._sendToKvProxy())}_sendToKvProxy(r){return s=>{const{url:n,backendUrl:l}=this._apiConfig;return Promise.resolve(s).then(e(n)).then((e=>{return{...e,body:{...(t=e.body,Object.fromEntries(Object.entries(t).filter((([,e])=>null!=e)))),backendUrl:l},headers:{Accept:"application/json","Content-Type":"application/json"}};var t})).then(o({signal:r??this._abortController.signal})).then(t)}}}export{r as KvClient};
//# sourceMappingURL=kv-client.js.map
