docker-api-nodejs
Version:
Docker API for NodeJS
2 lines • 30.5 kB
JavaScript
var ne=Object.getPrototypeOf;var le=Reflect.get;var Z=(a,t,e)=>le(ne(a),e,t);var i=(a,t,e)=>new Promise((r,s)=>{var o=l=>{try{c(e.next(l))}catch(g){s(g)}},n=l=>{try{c(e.throw(l))}catch(g){s(g)}},c=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,n);c((e=e.apply(a,t)).next())});import ce from"http";import me from"node:querystring";var C=class C{constructor(t){this.socketPath=t}static responseIsStream(t){let e=t.headers["content-type"];return e?C.responseStreamContentType.includes(e):!1}static getResponseContentHandler(t){switch(t.headers["content-type"]){case"application/json":return e=>JSON.parse(e);default:return e=>null}}static getQueryString(t){return t&&t.size>0?"?"+me.stringify(Object.fromEntries(t)):""}dial(t){return i(this,null,function*(){let e=this.socketPath,r=(C.version?"/"+C.version:"")+t.path,s=t.body?JSON.stringify(t.body):null,o=t.headers?Object.fromEntries(t.headers):{};return s&&(o["Content-Type"]="application/json",o["Content-Length"]=Buffer.byteLength(s)),yield new Promise(function(n,c){let l=!1,g={socketPath:e,path:r+C.getQueryString(t.query),method:t.method,headers:o},S=ce.request(g);S.on("upgrade",function(d,w,x){l||(l=!0,n(w))}),S.on("response",function(d){let w=d.statusCode;if(!w){c(new Error("Status is not defined"));return}if(C.responseIsStream(d)||t.isStream){if(l)return;l=!0,n(d);return}let x=C.getResponseContentHandler(d),E=w<300,N=new Array,H=function(p){N.push(p)},R=function(){if(l)return;l=!0;let Y=Buffer.concat(N).toString("utf-8"),_=x(Y);E?n(_):c(_)};d.on("error",c),d.on("data",H),d.on("end",R),d.on("close",R)}),s&&S.write(s),S.on("error",c),S.end()}).catch(function(n){return Promise.reject("message"in n?n.message:n)})})}};C.version="v1.44",C.responseStreamContentType=["application/vnd.docker.raw-stream","application/vnd.docker.multiplexed-stream"];var U=C;var m=class{constructor(t,e){this.modem=t,this.id=e}};var u="com.docker.stack.namespace";var b=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/configs/"+this.id,method:"GET"};return yield this.modem.dial(t)})}update(t){return i(this,null,function*(){let e=yield this.inspect(),r=e.Version.Index,s=new Map;s.set("version",r);let o=e.Spec;o.Labels=t.Labels;let n={path:"/configs/"+this.id+"/update",method:"POST",query:s,body:o};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&a.isPartOfStack(t))throw new Error("The current config was created by a stack, it can not be removed individually");let e={path:"/configs/"+this.id,method:"DELETE"};yield this.modem.dial(e)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Spec.Labels&&u in t.Spec.Labels}static fromConfig(t,e){let r=e.ID;return new a(t,r)}};var M=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/configs",method:"GET",query:s};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/configs/create",method:"POST",body:e},s=yield t.dial(r);return new b(t,s.ID)})}static getHandle(t,e){return new b(t,e)}};var V=class a extends m{inspect(){return i(this,arguments,function*(t={}){let e=new Map;"size"in t&&e.set("size",t.size?"true":"false");let r={path:"/containers/"+this.id+"/json",method:"GET",query:e};return yield this.modem.dial(r)})}listProcesses(){return i(this,arguments,function*(t={}){var s;let e=new Map;e.set("ps_args",(s=t.ps_args)!=null?s:"-ef");let r={path:`/containers/${this.id}/top`,method:"GET",query:e};return yield this.modem.dial(r)})}getLogs(){return i(this,arguments,function*(t={}){var s,o,n;let e=new Map;e.set("follow",t.follow?"true":"false"),e.set("stdout",t.stdout?"true":"false"),e.set("stderr",t.stderr?"true":"false"),e.set("since",(s=t.since)!=null?s:0),e.set("until",(o=t.until)!=null?o:0),e.set("timestamps",t.timestamps?"true":"false"),e.set("tail",(n=t.tail)!=null?n:"all");let r={path:`/containers/${this.id}/logs`,method:"GET",query:e};return yield this.modem.dial(r)})}changes(){return i(this,null,function*(){let t={path:`/containers/${this.id}/changes`,method:"GET"};return yield this.modem.dial(t)})}export(){return i(this,null,function*(){let t={path:`/containers/${this.id}/export`,method:"GET",isStream:!0};return yield this.modem.dial(t)})}stats(){return i(this,arguments,function*(t={}){let e=new Map;"stream"in t&&e.set("stream",t.stream?"true":"false"),"oneShot"in t&&e.set("one-shot",t.oneShot?"true":"false");let r={path:"/containers/"+this.id+"/stats",method:"GET",query:e,isStream:t.stream};return yield this.modem.dial(r)})}resize(t){return i(this,null,function*(){let e=new Map;e.set("h",t.h),e.set("w",t.w);let r={path:`/containers/${this.id}/resize`,method:"POST",query:e};return yield this.modem.dial(r)})}start(){return i(this,arguments,function*(t={}){let e=new Map;t.detachKeys&&e.set("detachKeys",t.detachKeys);let r={path:`/containers/${this.id}/start`,method:"POST",query:e};return yield this.modem.dial(r)})}stop(){return i(this,arguments,function*(t={}){var s;let e=new Map;e.set("signal",(s=t.signal)!=null?s:"SIGINT"),e.set("t",typeof t.t=="undefined"?5:t.t);let r={path:`/containers/${this.id}/stop`,method:"POST",query:e};return yield this.modem.dial(r)})}restart(){return i(this,arguments,function*(t={}){var s;let e=new Map;e.set("signal",(s=t.signal)!=null?s:"SIGINT"),e.set("t",t.t);let r={path:`/containers/${this.id}/restart`,method:"POST",query:e};return yield this.modem.dial(r)})}kill(){return i(this,arguments,function*(t={}){var s;let e=new Map;e.set("signal",(s=t.signal)!=null?s:"SIGKILL");let r={path:`/containers/${this.id}/kill`,method:"POST",query:e};return yield this.modem.dial(r)})}update(t){return i(this,null,function*(){let e={path:`/containers/${this.id}/update`,method:"POST",body:t};return yield this.modem.dial(e)})}rename(t){return i(this,null,function*(){let e=new Map;e.set("name",t.name);let r={path:`/containers/${this.id}/rename`,method:"POST",query:e};return yield this.modem.dial(r)})}pause(){return i(this,null,function*(){let t={path:`/containers/${this.id}/pause`,method:"GET",isStream:!0};return yield this.modem.dial(t)})}unpause(){return i(this,null,function*(){let t={path:`/containers/${this.id}/unpause`,method:"GET",isStream:!0};return yield this.modem.dial(t)})}wait(){return i(this,arguments,function*(t={}){var s;let e=new Map;e.set("condition",(s=t.condition)!=null?s:"not-running");let r={path:`/containers/${this.id}/wait`,method:"POST",query:e};return yield this.modem.dial(r)})}remove(){return i(this,arguments,function*(t={}){let e=new Map;e.set("v",t.v?"true":"false"),e.set("force",t.force?"true":"false"),e.set("link",t.link?"true":"false");let r={path:"/containers/"+this.id,method:"DELETE",query:e};yield this.modem.dial(r)})}static fromContainer(t,e){return new a(t,e.Id)}};var j=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.all&&s.set("all",e.all?"true":"false"),e.size&&s.set("size",e.size?"true":"false"),e.limit&&s.set("limit",e.limit),e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/containers/json",method:"GET",query:s};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/containers/create",method:"POST",body:e},s=yield t.dial(r);return new V(t,s.Id)})}static prune(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/containers/prune",method:"POST",query:s};return yield t.dial(o)})}static getHandle(t,e){return new V(t,e)}};var L=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/images/"+this.id+"/json",method:"GET"};return yield this.modem.dial(t)})}history(){return i(this,null,function*(){let t={path:`/images/${this.id}/history`,method:"GET"};return yield this.modem.dial(t)})}push(){return i(this,arguments,function*(t={},e){let r=new Map;e&&r.set("X-Registry-Auth",e);let s=new Map;t.tag&&s.set("tag",t.tag);let o={path:`/images/${this.id}/push`,method:"POST",headers:r,query:s};return yield this.modem.dial(o)})}tag(t){return i(this,null,function*(){let e=new Map;e.set("repo",t.repo),e.set("tag",t.tag);let r={path:`/images/${this.id}/tag`,method:"POST",query:e};return yield this.modem.dial(r)})}remove(){return i(this,arguments,function*(t={}){let e=new Map;t.force&&e.set("force",t.force?"true":"false"),t.noprune&&e.set("noprune",t.noprune?"true":"false");let r={path:"/images/"+this.id,method:"DELETE",query:e};yield this.modem.dial(r)})}static fromImage(t,e){return new a(t,e.Id)}};var O=class{constructor(t,e){this.handle=t,this.logStream=e,this.logChunks=new Array}drainLogStream(){return i(this,null,function*(){if(!this.logStream)return;let t=this,e=this.logStream;yield new Promise(function(r){e.on("data",function(s){t.logChunks.push(s.toString())}),e.on("end",r)})})}get Handle(){return this.handle}get LogChunks(){return this.logChunks}};var K=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.all&&s.set("all",e.all?"true":"false"),e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters))),e.sharedSize&&s.set("shared-size",e.sharedSize?"true":"false"),e.digests&&s.set("digests",e.digests?"true":"false");let o={path:"/images/json",method:"GET",query:s};return yield t.dial(o)})}static pruneBuilderCache(t,e){return i(this,null,function*(){let r=new Map;r.set("keep-storage",e.keepStorage),r.set("all",e.all?"true":"false"),e.filters&&r.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let s={path:"/build/prune",method:"POST",query:r};return yield t.dial(s)})}static pull(t,e,r){return i(this,null,function*(){let s=new Map;r&&s.set("X-Registry-Auth",r);let o=new Map;o.set("fromImage",e.fromImage),e.tag&&o.set("tag",e.tag),e.changes&&o.set("changes",e.changes),e.platform&&o.set("platform",e.platform);let n={path:"/images/create",method:"POST",headers:s,query:o,isStream:!0},c=yield t.dial(n),l=new L(t,e.fromImage),g=new O(l,c);return yield g.drainLogStream(),g})}static import(t,e,r){return i(this,null,function*(){let s=new Map;s.set("fromSrc",e.fromSrc),s.set("repo",e.repo),e.message&&s.set("message",e.message),e.changes&&s.set("changes",e.changes),e.platform&&s.set("platform",e.platform);let o={path:"/images/create",method:"POST",query:s,body:r,isStream:!0},n=yield t.dial(o),c=new L(t,e.repo),l=new O(c,n);return yield l.drainLogStream(),l})}static search(t,e){return i(this,null,function*(){let r=new Map;r.set("term",e.term),r.set("limit",e.limit),e.filters&&r.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let s={path:"/images/search",method:"GET",query:r};return yield t.dial(s)})}static prune(t,e){return i(this,null,function*(){let r=new Map;e&&r.set("filters",JSON.stringify(Object.fromEntries(e)));let s={path:"/images/prune",method:"POST",query:r};return yield t.dial(s)})}static commit(t,e,r){return i(this,null,function*(){var n,c,l;if(!r&&!e.container)throw new Error("Either containerConfig or queryOption 'container' must be specified");let s=new Map;s.set("repo",e.repo),s.set("tag",(n=e.tag)!=null?n:""),s.set("comment",(c=e.comment)!=null?c:""),s.set("author",(l=e.author)!=null?l:""),s.set("pause",e.pause?"true":"false"),e.container&&s.set("container",e.container),e.changes&&s.set("changes",e.changes);let o={path:"/commit",method:"POST",query:s,body:r};return yield t.dial(o)})}static getHandle(t,e){return new L(t,e)}};var k=class a extends m{inspect(){return i(this,arguments,function*(t={}){let e=new Map;e.set("verbose",t.verbose?"true":"false"),t.scope&&e.set("scope",t.scope);let r={path:"/networks/"+this.id,method:"GET",query:e};return yield this.modem.dial(r)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&a.isPartOfStack(t))throw new Error("The current network was created by a stack, it can not be removed individually");let e={path:"/networks/"+this.id,method:"DELETE"};yield this.modem.dial(e)})}connectContainer(t){return i(this,null,function*(){let e={path:`/networks/${this.id}/connect`,method:"POST",body:t};return yield this.modem.dial(e)})}disconnectContainer(t){return i(this,null,function*(){let e={path:`/networks/${this.id}/disconnect`,method:"POST",body:t};return yield this.modem.dial(e)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Labels&&u in t.Labels}static fromNetwork(t,e){let r=e.Id;return new a(t,r)}};var P=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/networks",method:"GET",query:s};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/networks/create",method:"POST",body:e},s=yield t.dial(r);return new k(t,s.Id)})}static prune(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/networks/prune",method:"POST",query:s};return yield t.dial(o)})}static getHandle(t,e){return new k(t,e)}};var G=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/nodes/"+this.id,method:"GET"};return yield this.modem.dial(t)})}update(t){return i(this,null,function*(){let r=(yield this.inspect()).Version.Index,s=new Map;s.set("version",r);let o={path:"/nodes/"+this.id+"/update",method:"POST",query:s,body:t};yield this.modem.dial(o)})}remove(t){return i(this,null,function*(){let e=new Map;e.set("force",t.force?"true":"false");let r={path:"/nodes/"+this.id,method:"DELETE",query:e};yield this.modem.dial(r)})}static fromNode(t,e){let r=e.ID;return new a(t,r)}};var J=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/nodes",method:"GET",query:s};return yield t.dial(o)})}static getHandle(t,e){return new G(t,e)}};var Q=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/plugins/"+this.id+"/json",method:"GET"};return yield this.modem.dial(t)})}remove(){return i(this,arguments,function*(t={}){let e=new Map;e.set("force",t.force?"true":"false");let r={path:"/plugins/"+this.id,method:"DELETE",query:e};yield this.modem.dial(r)})}enable(){return i(this,arguments,function*(t={}){let e=new Map;e.set("timeout",t.timeout?t.timeout:0);let r={path:"/plugins/"+this.id+"/enable",method:"POST",query:e};yield this.modem.dial(r)})}disable(){return i(this,arguments,function*(t={}){let e=new Map;e.set("force",t.force?"true":"false");let r={path:"/plugins/"+this.id+"/disable",method:"POST",query:e};yield this.modem.dial(r)})}static fromPlugin(t,e){let r=e.Id;return new a(t,r)}};var z=class a{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filter",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/plugins",method:"GET",query:s};return yield t.dial(o)})}static getPrivileges(t,e,r){return i(this,null,function*(){let s=new Map;r&&s.set("X-Registry-Auth",r);let o=new Map;o.set("remote",e.remote);let n={path:"/plugins/privileges",method:"GET",headers:s,query:o};return yield t.dial(n)})}static install(t,e,r,s){return i(this,null,function*(){let o=new Map;s&&o.set("X-Registry-Auth",s);let n=new Map;n.set("remote",e.remote),e.name&&n.set("name",e.name);let c={path:"/plugins/pull",method:"POST",headers:o,query:n,body:r,isStream:!0},l=e.name?e.name:e.remote,g=yield t.dial(c),S=new Q(t,l),d=new O(S,g);return yield d.drainLogStream(),d})}static installGrantAllPrivileges(t,e,r){return i(this,null,function*(){let s=yield a.getPrivileges(t,e,r);return yield a.install(t,e,s,r)})}static getHandle(t,e){return new Q(t,e)}};var W=class a{static inspect(t){return i(this,null,function*(){let e={path:"/swarm",method:"GET"};return yield t.dial(e)})}static initialize(t,e){return i(this,null,function*(){let r={path:"/swarm/init",method:"POST",body:e};return yield t.dial(r)})}static join(t,e){return i(this,null,function*(){let r={path:"/swarm/join",method:"POST",body:e};return yield t.dial(r)})}static leave(r){return i(this,arguments,function*(t,e={}){let s=new Map;s.set("force",e.force?"true":"false");let o={path:"/swarm/leave",method:"POST",query:s};return yield t.dial(o)})}static update(s){return i(this,arguments,function*(t,e={},r){let n=(yield a.inspect(t)).Version.Index,c=new Map;c.set("version",n),c.set("rotateWorkerToken",e.rotateWorkerToken?"true":"false"),c.set("rotateManagerToken",e.rotateManagerToken?"true":"false"),c.set("rotateManagerUnlockKey",e.rotateManagerUnlockKey?"true":"false");let l={path:"/swarm/update",method:"POST",query:c,body:r};return yield t.dial(l)})}static getUnlockKey(t){return i(this,null,function*(){let e={path:"/swarm/unlockkey",method:"GET"};return yield t.dial(e)})}static unlock(t,e){return i(this,null,function*(){let r={path:"/swarm/unlock",method:"POST",body:e};return yield t.dial(r)})}};var A=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/secrets/"+this.id,method:"GET"};return yield this.modem.dial(t)})}update(t){return i(this,null,function*(){let e=yield this.inspect(),r=e.Version.Index,s=new Map;s.set("version",r);let o=e.Spec;o.Labels=t.Labels;let n={path:"/secrets/"+this.id+"/update",method:"POST",query:s,body:o};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&a.isPartOfStack(t))throw new Error("The current secret was created by a stack, it can not be removed individually");let e={path:"/secrets/"+this.id,method:"DELETE"};yield this.modem.dial(e)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Spec.Labels&&u in t.Spec.Labels}static fromSecret(t,e){let r=e.ID;return new a(t,r)}};var D=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/secrets",method:"GET",query:s};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/secrets/create",method:"POST",body:e},s=yield t.dial(r);return new A(t,s.ID)})}static getHandle(t,e){return new A(t,e)}};var f=class{static list(r){return i(this,arguments,function*(t,e={}){let s=typeof e.status=="undefined"?!0:e.status,o=new Map;o.set("status",s?"true":"false"),e.filters&&o.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let n={path:"/services",method:"GET",query:o};return yield t.dial(n)})}static create(t,e,r){return i(this,null,function*(){let s=new Map;r&&s.set("X-Registry-Auth",r);let o={path:"/services/create",method:"POST",headers:s,body:e},n=yield t.dial(o);return new v(t,n.ID)})}static getHandle(t,e){return new v(t,e)}};var v=class a extends m{inspect(){return i(this,arguments,function*(t={}){let e=new Map;e.set("insertDefaults",t.insertDefaults?"true":"false");let r={path:"/services/"+this.id,method:"GET",query:e};return yield this.modem.dial(r)})}getLogs(){return i(this,arguments,function*(t={}){let e=new Map;e.set("details",t.details?"true":"false"),e.set("follow",t.follow?"true":"false"),e.set("stdout",t.stdout?"true":"false"),e.set("stderr",t.stdout?"true":"false"),e.set("since",t.since||0),e.set("timestamps",t.timestamps?"true":"false"),e.set("tail",t.tail||"all");let r={path:"/services/"+this.id+"/logs",method:"GET",query:e};return yield this.modem.dial(r)})}update(s){return i(this,arguments,function*(t,e={},r){let n=(yield this.inspect()).Version.Index,c=new Map;r&&c.set("X-Registry-Auth",r);let l=new Map;l.set("version",n),l.set("registryAuthFrom",e.registryAuthFrom||"spec"),e.rollback&&l.set("rollback",e.rollback);let g=t,S={path:"/services/"+this.id+"/update",method:"POST",headers:c,query:l,body:g};return yield this.modem.dial(S)})}redeploy(t){return i(this,null,function*(){let e=yield this.inspect({insertDefaults:!0});if(this.shouldThrowStackError()&&a.isPartOfStack(e))throw new Error("The current service was created by a stack, consider redeploying the stack");let r=e.Spec;return yield this.remove(),yield f.create(this.modem,r,t)})}rollback(){return i(this,arguments,function*(t={registryAuthFrom:"spec"},e){let r=yield this.inspect(),s=Object.assign(t,{rollback:"previous"});return yield this.update(r.Spec,s,e)})}stop(){return i(this,null,function*(){var r,s;let e=(yield this.inspect()).Spec;if((r=e.Mode)!=null&&r.Replicated&&e.Mode.Replicated.Replicas>0)return e.Mode.Replicated.Replicas=0,yield this.update(e);throw(s=e.Mode)!=null&&s.Replicated&&e.Mode.Replicated.Replicas<=0?new Error("This service is already stoppped"):new Error("The service is not a replicated service and can not be stopped")})}start(){return i(this,null,function*(){var s,o,n,c,l;let t=yield this.inspect(),e=t.Spec,r=t.PreviousSpec;if(r&&((s=r.Mode)!=null&&s.Replicated)&&r.Mode.Replicated.Replicas>0&&((o=e.Mode)!=null&&o.Replicated)&&e.Mode.Replicated.Replicas<=0)return yield this.rollback();throw r&&((n=r.Mode)!=null&&n.Replicated)&&r.Mode.Replicated.Replicas>0&&((c=e.Mode)!=null&&c.Replicated)&&e.Mode.Replicated.Replicas>0?new Error("This service is not stoppped"):r&&((l=r.Mode)!=null&&l.Replicated)&&r.Mode.Replicated.Replicas<=0?new Error("This service can not be started, scale it to any number"):r?new Error("Unexpected error"):new Error("This service never started, scale it to any number first")})}remove(){return i(this,null,function*(){let t=yield this.inspect({insertDefaults:!0});if(this.shouldThrowStackError()&&a.isPartOfStack(t))throw new Error("The current service was created by a stack, it can not be removed individually");let e={path:"/services/"+this.id,method:"DELETE"};return yield this.modem.dial(e)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Spec.Labels&&u in t.Spec.Labels}static fromService(t,e){let r=e.ID;return new a(t,r)}};var $=class{static auth(t,e){return i(this,null,function*(){let r={path:"/auth",method:"POST",body:e};return yield t.dial(r)})}static info(t){return i(this,null,function*(){let e={path:"/info",method:"GET"};return yield t.dial(e)})}static version(t){return i(this,null,function*(){let e={path:"/version",method:"GET"};return yield t.dial(e)})}static ping(t){return i(this,null,function*(){let e={path:"/_ping",method:"GET"};yield t.dial(e)})}static monitorEvents(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.since&&s.set("since",e.since),e.until&&s.set("until",e.until),e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/events",method:"GET",query:s,isStream:!0};return yield t.dial(o)})}static usageData(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.type&&s.set("type",JSON.stringify(e.type));let o={path:"/system/df",method:"GET",query:s};return yield t.dial(o)})}};var B=class a extends m{inspect(){return i(this,null,function*(){let t={path:"/tasks/"+this.id,method:"GET"};return yield this.modem.dial(t)})}getLogs(){return i(this,arguments,function*(t={}){let e=new Map;e.set("details",t.details?"true":"false"),e.set("follow",t.follow?"true":"false"),e.set("stdout",t.stdout?"true":"false"),e.set("stderr",t.stderr?"true":"false"),e.set("since",t.since?t.since:0),e.set("timestamps",t.timestamps?"true":"false"),e.set("tail",t.tail);let r={path:"/tasks/"+this.id+"/logs",method:"GET",query:e};return yield this.modem.dial(r)})}static fromTask(t,e){let r=e.ID;return new a(t,r)}};var X=class{static list(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/tasks",method:"GET",query:s};return yield t.dial(o)})}static getHandle(t,e){return new B(t,e)}};var T=class a extends m{constructor(t,e){super(t,e)}inspectResult(){return i(this,null,function*(){let t=new Map;t.set("name",this.id);let e={path:"/volumes/"+this.id,method:"GET",query:t};return yield this.modem.dial(e)})}inspect(){return i(this,null,function*(){return yield this.inspectResult()})}remove(){return i(this,arguments,function*(t={}){let e=yield this.inspect();if(this.shouldThrowStackError()&&a.isPartOfStack(e))throw new Error("The current volume was created by a stack, it can not be removed individually");let r=new Map;r.set("force",t.force?"true":"false");let s={path:"/volumes/"+this.id,method:"DELETE",query:r};yield this.modem.dial(s)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Labels&&u in t.Labels}static fromVolume(t,e){let r=e.Name;return new a(t,r)}};var I=class a extends T{inspect(){return i(this,null,function*(){return yield Z(a.prototype,this,"inspectResult").call(this)})}update(t){return i(this,null,function*(){let e=yield this.inspect(),r=e.ClusterVolume.Version.Index,s={Spec:e.ClusterVolume.Spec},o=new Map;o.set("version",r.toString()),s.Spec.Availability=t.ClusterVolumeSpec.Availability;let n={path:"/volumes/"+this.id,method:"PUT",query:o,body:s};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&a.isPartOfStack(t))throw new Error("The current cluster-volume was created by a stack, it can not be removed individually");let e={force:!0};yield Z(a.prototype,this,"remove").call(this,e)})}static isPartOfStack(t){return t.Labels&&u in t.Labels}static fromClusterVolume(t,e){let r=e.ClusterVolume.ID;return new a(t,r)}};var h=class a{static _list(s,o){return i(this,arguments,function*(t,e,r={}){let n=new Map;r.filters&&n.set("filters",JSON.stringify(Object.fromEntries(r.filters)));let c={path:"/volumes",method:"GET",query:n},l=yield t.dial(c);return l.Volumes=l.Volumes.filter(e),l})}static _create(t,e){return i(this,null,function*(){let r={path:"/volumes/create",method:"POST",body:e};return yield t.dial(r)})}static list(r){return i(this,arguments,function*(t,e={}){let s=o=>!("ClusterVolume"in o);return a._list(t,s,e)})}static listCluster(r){return i(this,arguments,function*(t,e={}){let s=o=>"ClusterVolume"in o;return a._list(t,s,e)})}static create(t,e){return i(this,null,function*(){let r=yield a._create(t,e);return new T(t,r.Name)})}static createCluster(t,e){return i(this,null,function*(){let r=yield a._create(t,e);return new I(t,r.ClusterVolume.ID)})}static prune(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.filters&&s.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/volumes/prune",method:"POST",query:s};return yield t.dial(o)})}static getHandle(t,e){return new T(t,e)}static getClusterHandle(t,e){return new I(t,e)}};var ee=class a extends v{shouldThrowStackError(){return!1}static fromService(t,e){let r=e.ID;return new a(t,r)}},te=class a extends k{shouldThrowStackError(){return!1}static fromNetwork(t,e){let r=e.Id;return new a(t,r)}},re=class a extends b{shouldThrowStackError(){return!1}static fromConfig(t,e){let r=e.ID;return new a(t,r)}},se=class a extends A{shouldThrowStackError(){return!1}static fromSecret(t,e){let r=e.ID;return new a(t,r)}},ie=class a extends I{shouldThrowStackError(){return!1}static fromClusterVolume(t,e){let r=e.ClusterVolume.ID;return new a(t,r)}},F=class extends m{constructor(t,e){super(t,e)}inspect(){return i(this,null,function*(){let t=new Map;t.set("label",Array.of(u+"="+this.id));let e={filters:t},r=yield f.list(this.modem,e),s=yield M.list(this.modem,e),o=yield D.list(this.modem,e),n=yield P.list(this.modem,e),c=(yield h.list(this.modem,e)).Volumes,l=(yield h.listCluster(this.modem,e)).Volumes;return{Spec:{Name:this.id},Services:r,Configs:s,Secrets:o,Networks:n,Volumes:c,ClusterVolumes:l}})}remove(){return i(this,null,function*(){let t=new Map;t.set("label",Array.of(u+"="+this.id));let e={filters:t},o=(yield f.list(this.modem,e)).map(p=>ee.fromService(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),l=(yield P.list(this.modem,e)).map(p=>te.fromNetwork(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),d=(yield M.list(this.modem,e)).map(p=>re.fromConfig(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),E=(yield D.list(this.modem,e)).map(p=>se.fromSecret(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),R=(yield h.listCluster(this.modem,e)).Volumes.map(p=>ie.fromClusterVolume(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()}));yield Promise.all(o),yield Promise.all(Array.of(...l,...d,...E,...R))})}};import{execFile as pe}from"child_process";import{Readable as ue}from"stream";function oe(a,t){if(!t.Labels||!(u in t.Labels))return a;let e=t.Labels[u];return a.has(e)||a.set(e,new Array),a.get(e).push(t),a}function ae(a,t){if(!t.Spec.Labels||!(u in t.Spec.Labels))return a;let e=t.Spec.Labels[u];return a.has(e)||a.set(e,new Array),a.get(e).push(t),a}var q=class{static list(t){return i(this,null,function*(){let e=new Map;e.set("label",Array.of(u));let r={filters:e},s=f.list(t,r),o=M.list(t,r),n=D.list(t,r),c=P.list(t,r),l=h.list(t,r),g=h.listCluster(t,r),S=Array.of(s,o,n),d=yield Promise.all(S),w=d[0].reduce(ae,new Map),x=d[1].reduce(ae,new Map),E=d[2].reduce(ae,new Map),N=(yield c).reduce(oe,new Map),H=(yield l).Volumes.reduce(oe,new Map),R=(yield g).Volumes.reduce(oe,new Map),p=Array.of(...Array.from(w.keys()),...Array.from(x.keys()),...Array.from(E.keys()),...Array.from(N.keys()),...Array.from(H.keys()),...Array.from(R.keys())),Y=new Set(p);return Array.from(Y).map(y=>({Spec:{Name:y},Services:w.has(y)?Array.from(w.get(y)):new Array,Configs:x.has(y)?Array.from(x.get(y)):new Array,Secrets:E.has(y)?Array.from(E.get(y)):new Array,Networks:N.has(y)?Array.from(N.get(y)):new Array,Volumes:H.has(y)?Array.from(H.get(y)):new Array,ClusterVolumes:R.has(y)?Array.from(R.get(y)):new Array}))})}static create(t,e){return i(this,null,function*(){return yield new Promise(function(r,s){if(!e.Yaml){s(new Error("Stack cannot be created without valid compose data"));return}let o=pe("docker",["stack","deploy","-d","--compose-file -",e.Name],function(c,l,g){c&&s(c)}),n=new ue;n.push(e.Yaml),n.push(null),o.stdin&&n.pipe(o.stdin),r(!0)}),new F(t,e.Name)})}static getHandle(t,e){return new F(t,e)}};export{I as ClusterVolumeHandle,b as ConfigHandle,M as Configs,V as ContainerHandle,j as Containers,m as Handle,L as ImageHandle,K as Images,U as Modem,k as NetworkHandle,P as Networks,G as NodeHandle,J as Nodes,Q as PluginHandle,z as Plugins,A as SecretHandle,D as Secrets,v as ServiceHandle,f as Services,F as StackHandle,q as Stacks,W as Swarm,$ as System,B as TaskHandle,X as Tasks,T as VolumeHandle,h as Volumes};
//# sourceMappingURL=index.mjs.map