docker-api-nodejs
Version:
Docker API for NodeJS
2 lines • 31.4 kB
JavaScript
"use strict";var ye=Object.create;var Y=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var Ce=Reflect.get;var we=(o,t)=>{for(var e in t)Y(o,e,{get:t[e],enumerable:!0})},ce=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of fe(t))!he.call(o,s)&&s!==e&&Y(o,s,{get:()=>t[s],enumerable:!(r=Se(t,s))||r.enumerable});return o};var me=(o,t,e)=>(e=o!=null?ye(le(o)):{},ce(t||!o||!o.__esModule?Y(e,"default",{value:o,enumerable:!0}):e,o)),be=o=>ce(Y({},"__esModule",{value:!0}),o);var ee=(o,t,e)=>Ce(le(o),e,t);var i=(o,t,e)=>new Promise((r,s)=>{var a=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(a,n);c((e=e.apply(o,t)).next())});var Me={};we(Me,{ClusterVolumeHandle:()=>T,ConfigHandle:()=>w,Configs:()=>b,ContainerHandle:()=>O,Containers:()=>j,Handle:()=>m,ImageHandle:()=>R,Images:()=>K,Modem:()=>U,NetworkHandle:()=>M,Networks:()=>k,NodeHandle:()=>H,Nodes:()=>J,PluginHandle:()=>E,Plugins:()=>z,SecretHandle:()=>P,Secrets:()=>A,ServiceHandle:()=>D,Services:()=>f,StackHandle:()=>N,Stacks:()=>q,Swarm:()=>W,System:()=>$,TaskHandle:()=>G,Tasks:()=>X,VolumeHandle:()=>v,Volumes:()=>h});module.exports=be(Me);var pe=me(require("http")),ue=me(require("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?"?"+ue.default.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,a=t.headers?Object.fromEntries(t.headers):{};return s&&(a["Content-Type"]="application/json",a["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:a},S=pe.default.request(g);S.on("upgrade",function(d,I,V){l||(l=!0,n(I))}),S.on("response",function(d){let I=d.statusCode;if(!I){c(new Error("Status is not defined"));return}if(C.responseIsStream(d)||t.isStream){if(l)return;l=!0,n(d);return}let V=C.getResponseContentHandler(d),Q=I<300,F=new Array,B=function(p){F.push(p)},L=function(){if(l)return;l=!0;let _=Buffer.concat(F).toString("utf-8"),Z=V(_);Q?n(Z):c(Z)};d.on("error",c),d.on("data",B),d.on("end",L),d.on("close",L)}),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 w=class o 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 a=e.Spec;a.Labels=t.Labels;let n={path:"/configs/"+this.id+"/update",method:"POST",query:s,body:a};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&o.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 o(t,r)}};var b=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 a={path:"/configs",method:"GET",query:s};return yield t.dial(a)})}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 w(t,s.ID)})}static getHandle(t,e){return new w(t,e)}};var O=class o 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,a,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",(a=t.until)!=null?a: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 o(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 a={path:"/containers/json",method:"GET",query:s};return yield t.dial(a)})}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 O(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 a={path:"/containers/prune",method:"POST",query:s};return yield t.dial(a)})}static getHandle(t,e){return new O(t,e)}};var R=class o 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 a={path:`/images/${this.id}/push`,method:"POST",headers:r,query:s};return yield this.modem.dial(a)})}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 o(t,e.Id)}};var x=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 a={path:"/images/json",method:"GET",query:s};return yield t.dial(a)})}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 a=new Map;a.set("fromImage",e.fromImage),e.tag&&a.set("tag",e.tag),e.changes&&a.set("changes",e.changes),e.platform&&a.set("platform",e.platform);let n={path:"/images/create",method:"POST",headers:s,query:a,isStream:!0},c=yield t.dial(n),l=new R(t,e.fromImage),g=new x(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 a={path:"/images/create",method:"POST",query:s,body:r,isStream:!0},n=yield t.dial(a),c=new R(t,e.repo),l=new x(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 a={path:"/commit",method:"POST",query:s,body:r};return yield t.dial(a)})}static getHandle(t,e){return new R(t,e)}};var M=class o 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()&&o.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 o(t,r)}};var k=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 a={path:"/networks",method:"GET",query:s};return yield t.dial(a)})}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 M(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 a={path:"/networks/prune",method:"POST",query:s};return yield t.dial(a)})}static getHandle(t,e){return new M(t,e)}};var H=class o 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 a={path:"/nodes/"+this.id+"/update",method:"POST",query:s,body:t};yield this.modem.dial(a)})}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 o(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 a={path:"/nodes",method:"GET",query:s};return yield t.dial(a)})}static getHandle(t,e){return new H(t,e)}};var E=class o 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 o(t,r)}};var z=class o{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 a={path:"/plugins",method:"GET",query:s};return yield t.dial(a)})}static getPrivileges(t,e,r){return i(this,null,function*(){let s=new Map;r&&s.set("X-Registry-Auth",r);let a=new Map;a.set("remote",e.remote);let n={path:"/plugins/privileges",method:"GET",headers:s,query:a};return yield t.dial(n)})}static install(t,e,r,s){return i(this,null,function*(){let a=new Map;s&&a.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:a,query:n,body:r,isStream:!0},l=e.name?e.name:e.remote,g=yield t.dial(c),S=new E(t,l),d=new x(S,g);return yield d.drainLogStream(),d})}static installGrantAllPrivileges(t,e,r){return i(this,null,function*(){let s=yield o.getPrivileges(t,e,r);return yield o.install(t,e,s,r)})}static getHandle(t,e){return new E(t,e)}};var W=class o{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 a={path:"/swarm/leave",method:"POST",query:s};return yield t.dial(a)})}static update(s){return i(this,arguments,function*(t,e={},r){let n=(yield o.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 P=class o 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 a=e.Spec;a.Labels=t.Labels;let n={path:"/secrets/"+this.id+"/update",method:"POST",query:s,body:a};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&o.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 o(t,r)}};var A=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 a={path:"/secrets",method:"GET",query:s};return yield t.dial(a)})}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 P(t,s.ID)})}static getHandle(t,e){return new P(t,e)}};var f=class{static list(r){return i(this,arguments,function*(t,e={}){let s=typeof e.status=="undefined"?!0:e.status,a=new Map;a.set("status",s?"true":"false"),e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let n={path:"/services",method:"GET",query:a};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 a={path:"/services/create",method:"POST",headers:s,body:e},n=yield t.dial(a);return new D(t,n.ID)})}static getHandle(t,e){return new D(t,e)}};var D=class o 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()&&o.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,a,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&&((a=e.Mode)!=null&&a.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()&&o.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 o(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 a={path:"/events",method:"GET",query:s,isStream:!0};return yield t.dial(a)})}static usageData(r){return i(this,arguments,function*(t,e={}){let s=new Map;e.type&&s.set("type",JSON.stringify(e.type));let a={path:"/system/df",method:"GET",query:s};return yield t.dial(a)})}};var G=class o 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 o(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 a={path:"/tasks",method:"GET",query:s};return yield t.dial(a)})}static getHandle(t,e){return new G(t,e)}};var v=class o 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()&&o.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 o(t,r)}};var T=class o extends v{inspect(){return i(this,null,function*(){return yield ee(o.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},a=new Map;a.set("version",r.toString()),s.Spec.Availability=t.ClusterVolumeSpec.Availability;let n={path:"/volumes/"+this.id,method:"PUT",query:a,body:s};yield this.modem.dial(n)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&o.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 ee(o.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 o(t,r)}};var h=class o{static _list(s,a){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=a=>!("ClusterVolume"in a);return o._list(t,s,e)})}static listCluster(r){return i(this,arguments,function*(t,e={}){let s=a=>"ClusterVolume"in a;return o._list(t,s,e)})}static create(t,e){return i(this,null,function*(){let r=yield o._create(t,e);return new v(t,r.Name)})}static createCluster(t,e){return i(this,null,function*(){let r=yield o._create(t,e);return new T(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 a={path:"/volumes/prune",method:"POST",query:s};return yield t.dial(a)})}static getHandle(t,e){return new v(t,e)}static getClusterHandle(t,e){return new T(t,e)}};var te=class o extends D{shouldThrowStackError(){return!1}static fromService(t,e){let r=e.ID;return new o(t,r)}},re=class o extends M{shouldThrowStackError(){return!1}static fromNetwork(t,e){let r=e.Id;return new o(t,r)}},se=class o extends w{shouldThrowStackError(){return!1}static fromConfig(t,e){let r=e.ID;return new o(t,r)}},ie=class o extends P{shouldThrowStackError(){return!1}static fromSecret(t,e){let r=e.ID;return new o(t,r)}},oe=class o extends T{shouldThrowStackError(){return!1}static fromClusterVolume(t,e){let r=e.ClusterVolume.ID;return new o(t,r)}},N=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 b.list(this.modem,e),a=yield A.list(this.modem,e),n=yield k.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:a,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},a=(yield f.list(this.modem,e)).map(p=>te.fromService(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),l=(yield k.list(this.modem,e)).map(p=>re.fromNetwork(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),d=(yield b.list(this.modem,e)).map(p=>se.fromConfig(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),Q=(yield A.list(this.modem,e)).map(p=>ie.fromSecret(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()})),L=(yield h.listCluster(this.modem,e)).Volumes.map(p=>oe.fromClusterVolume(this.modem,p)).map(p=>i(this,null,function*(){yield p.remove()}));yield Promise.all(a),yield Promise.all(Array.of(...l,...d,...Q,...L))})}};var de=require("child_process"),ge=require("stream");function ae(o,t){if(!t.Labels||!(u in t.Labels))return o;let e=t.Labels[u];return o.has(e)||o.set(e,new Array),o.get(e).push(t),o}function ne(o,t){if(!t.Spec.Labels||!(u in t.Spec.Labels))return o;let e=t.Spec.Labels[u];return o.has(e)||o.set(e,new Array),o.get(e).push(t),o}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),a=b.list(t,r),n=A.list(t,r),c=k.list(t,r),l=h.list(t,r),g=h.listCluster(t,r),S=Array.of(s,a,n),d=yield Promise.all(S),I=d[0].reduce(ne,new Map),V=d[1].reduce(ne,new Map),Q=d[2].reduce(ne,new Map),F=(yield c).reduce(ae,new Map),B=(yield l).Volumes.reduce(ae,new Map),L=(yield g).Volumes.reduce(ae,new Map),p=Array.of(...Array.from(I.keys()),...Array.from(V.keys()),...Array.from(Q.keys()),...Array.from(F.keys()),...Array.from(B.keys()),...Array.from(L.keys())),_=new Set(p);return Array.from(_).map(y=>({Spec:{Name:y},Services:I.has(y)?Array.from(I.get(y)):new Array,Configs:V.has(y)?Array.from(V.get(y)):new Array,Secrets:Q.has(y)?Array.from(Q.get(y)):new Array,Networks:F.has(y)?Array.from(F.get(y)):new Array,Volumes:B.has(y)?Array.from(B.get(y)):new Array,ClusterVolumes:L.has(y)?Array.from(L.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 a=(0,de.execFile)("docker",["stack","deploy","-d","--compose-file -",e.Name],function(c,l,g){c&&s(c)}),n=new ge.Readable;n.push(e.Yaml),n.push(null),a.stdin&&n.pipe(a.stdin),r(!0)}),new N(t,e.Name)})}static getHandle(t,e){return new N(t,e)}};0&&(module.exports={ClusterVolumeHandle,ConfigHandle,Configs,ContainerHandle,Containers,Handle,ImageHandle,Images,Modem,NetworkHandle,Networks,NodeHandle,Nodes,PluginHandle,Plugins,SecretHandle,Secrets,ServiceHandle,Services,StackHandle,Stacks,Swarm,System,TaskHandle,Tasks,VolumeHandle,Volumes});
//# sourceMappingURL=index.js.map