UNPKG

docker-api-nodejs

Version:
2 lines 37.5 kB
var fe=Object.getPrototypeOf;var he=Reflect.get;var ie=(n,t,e)=>he(fe(n),e,t);var i=(n,t,e)=>new Promise((r,a)=>{var o=c=>{try{m(e.next(c))}catch(u){a(u)}},l=c=>{try{m(e.throw(c))}catch(u){a(u)}},m=c=>c.done?r(c.value):Promise.resolve(c.value).then(o,l);m((e=e.apply(n,t)).next())});import Ce from"http";import we from"querystring";var x=class x{constructor(t){this.socketPath=t}static responseIsStream(t){let e=t.headers["content-type"];return e?x.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?"?"+we.stringify(Object.fromEntries(t)):""}dial(t){return i(this,null,function*(){let e=this.socketPath,r=(x.version?"/"+x.version:"")+t.path,a=t.body?JSON.stringify(t.body):null,o=t.headers?Object.fromEntries(t.headers):{};return a&&(o["Content-Type"]="application/json",o["Content-Length"]=Buffer.byteLength(a).toString()),yield new Promise(function(l,m){let c=!1,u={socketPath:e,path:r+x.getQueryString(t.query),method:t.method,headers:o},f=Ce.request(u);f.on("upgrade",function(h,A,v){c||(c=!0,l(A))}),f.on("response",function(h){let A=h.statusCode;if(!A){m(new Error("Status is not defined"));return}if(x.responseIsStream(h)||t.isStream){if(c)return;c=!0,l(h);return}let v=x.getResponseContentHandler(h),w=A<300,D=new Array,Q=function(d){D.push(d)},P=function(){if(c)return;c=!0;let J=Buffer.concat(D).toString("utf-8"),z=v(J);w?l(z):m(z)};h.on("error",m),h.on("data",Q),h.on("end",P),h.on("close",P)}),a&&f.write(a),f.on("error",m),f.end()}).catch(function(l){return Promise.reject("message"in l?l.message:l)})})}};x.version="v1.44",x.responseStreamContentType=["application/vnd.docker.raw-stream","application/vnd.docker.multiplexed-stream"];var X=x;var g=class{constructor(t,e){this.modem=t,this.id=e}};var S="com.docker.stack.namespace";var R=class n extends g{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,a=new Map;a.set("version",r);let o=e.Spec;o.Labels=t.Labels;let l={path:"/configs/"+this.id+"/update",method:"POST",query:a,body:o};yield this.modem.dial(l)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&n.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&&S in t.Spec.Labels}static fromConfig(t,e){let r=e.ID;return new n(t,r)}};var T=class n{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/configs",method:"GET",query:a};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/configs/create",method:"POST",body:e},a=yield t.dial(r);return new R(t,a.ID)})}static exists(t,e){return i(this,null,function*(){let r=new Map;r.set("name",Array.of(e));let a=yield n.list(t,{filters:r});return{exists:a.length>0,handle:a.length>0?R.fromConfig(t,a[0]):void 0}})}static getHandle(t,e){return new R(t,e)}};var U=class n extends g{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 a;let e=new Map;e.set("ps_args",(a=t.ps_args)!=null?a:"-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 a,o,l;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",(a=t.since)!=null?a:0),e.set("until",(o=t.until)!=null?o:0),e.set("timestamps",t.timestamps?"true":"false"),e.set("tail",(l=t.tail)!=null?l:"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 a;let e=new Map;e.set("signal",(a=t.signal)!=null?a:"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 a;let e=new Map;e.set("signal",(a=t.signal)!=null?a:"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 a;let e=new Map;e.set("signal",(a=t.signal)!=null?a:"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 a;let e=new Map;e.set("condition",(a=t.condition)!=null?a:"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 n(t,e.Id)}};var q=class{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.all&&a.set("all",e.all?"true":"false"),e.size&&a.set("size",e.size?"true":"false"),e.limit&&a.set("limit",e.limit),e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/containers/json",method:"GET",query:a};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/containers/create",method:"POST",body:e},a=yield t.dial(r);return new U(t,a.Id)})}static prune(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/containers/prune",method:"POST",query:a};return yield t.dial(o)})}static getHandle(t,e){return new U(t,e)}};var F=class n extends g{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 a=new Map;t.tag&&a.set("tag",t.tag);let o={path:`/images/${this.id}/push`,method:"POST",headers:r,query:a};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 n(t,e.Id)}};var B=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(a){t.logChunks.push(a.toString())}),e.on("end",r)})})}get Handle(){return this.handle}get LogChunks(){return this.logChunks}};var Y=class{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.all&&a.set("all",e.all?"true":"false"),e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters))),e.sharedSize&&a.set("shared-size",e.sharedSize?"true":"false"),e.digests&&a.set("digests",e.digests?"true":"false");let o={path:"/images/json",method:"GET",query:a};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 a={path:"/build/prune",method:"POST",query:r};return yield t.dial(a)})}static pull(t,e,r){return i(this,null,function*(){let a=new Map;r&&a.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 l={path:"/images/create",method:"POST",headers:a,query:o,isStream:!0},m=yield t.dial(l),c=new F(t,e.fromImage),u=new B(c,m);return yield u.drainLogStream(),u})}static import(t,e,r){return i(this,null,function*(){let a=new Map;a.set("fromSrc",e.fromSrc),a.set("repo",e.repo),e.message&&a.set("message",e.message),e.changes&&a.set("changes",e.changes),e.platform&&a.set("platform",e.platform);let o={path:"/images/create",method:"POST",query:a,body:r,isStream:!0},l=yield t.dial(o),m=new F(t,e.repo),c=new B(m,l);return yield c.drainLogStream(),c})}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 a={path:"/images/search",method:"GET",query:r};return yield t.dial(a)})}static prune(t,e){return i(this,null,function*(){let r=new Map;e&&r.set("filters",JSON.stringify(Object.fromEntries(e)));let a={path:"/images/prune",method:"POST",query:r};return yield t.dial(a)})}static commit(t,e,r){return i(this,null,function*(){var l,m,c;if(!r&&!e.container)throw new Error("Either containerConfig or queryOption 'container' must be specified");let a=new Map;a.set("repo",e.repo),a.set("tag",(l=e.tag)!=null?l:""),a.set("comment",(m=e.comment)!=null?m:""),a.set("author",(c=e.author)!=null?c:""),a.set("pause",e.pause?"true":"false"),e.container&&a.set("container",e.container),e.changes&&a.set("changes",e.changes);let o={path:"/commit",method:"POST",query:a,body:r};return yield t.dial(o)})}static getHandle(t,e){return new F(t,e)}};var L=class n extends g{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()&&n.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&&S in t.Labels}static fromNetwork(t,e){let r=e.Id;return new n(t,r)}};var I=class n{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/networks",method:"GET",query:a};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/networks/create",method:"POST",body:e},a=yield t.dial(r);return new L(t,a.Id)})}static existsCluster(t,e){return i(this,null,function*(){let r=new Map;r.set("name",Array.of(e)),r.set("scope",Array.of("swarm"));let a=yield n.list(t,{filters:r});return{exists:a.length>0,handle:a.length>0?L.fromNetwork(t,a[0]):void 0}})}static prune(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/networks/prune",method:"POST",query:a};return yield t.dial(o)})}static getHandle(t,e){return new L(t,e)}};var W=class n extends g{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,a=new Map;a.set("version",r);let o={path:"/nodes/"+this.id+"/update",method:"POST",query:a,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 n(t,r)}};var Z=class{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/nodes",method:"GET",query:a};return yield t.dial(o)})}static getHandle(t,e){return new W(t,e)}};var K=class n extends g{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 n(t,r)}};var _=class n{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filter",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/plugins",method:"GET",query:a};return yield t.dial(o)})}static getPrivileges(t,e,r){return i(this,null,function*(){let a=new Map;r&&a.set("X-Registry-Auth",r);let o=new Map;o.set("remote",e.remote);let l={path:"/plugins/privileges",method:"GET",headers:a,query:o};return yield t.dial(l)})}static install(t,e,r,a){return i(this,null,function*(){let o=new Map;a&&o.set("X-Registry-Auth",a);let l=new Map;l.set("remote",e.remote),e.name&&l.set("name",e.name);let m={path:"/plugins/pull",method:"POST",headers:o,query:l,body:r,isStream:!0},c=e.name?e.name:e.remote,u=yield t.dial(m),f=new K(t,c),h=new B(f,u);return yield h.drainLogStream(),h})}static installGrantAllPrivileges(t,e,r){return i(this,null,function*(){let a=yield n.getPrivileges(t,e,r);return yield n.install(t,e,a,r)})}static getHandle(t,e){return new K(t,e)}};var ee=class n{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 a=new Map;a.set("force",e.force?"true":"false");let o={path:"/swarm/leave",method:"POST",query:a};return yield t.dial(o)})}static update(a){return i(this,arguments,function*(t,e={},r){let l=(yield n.inspect(t)).Version.Index,m=new Map;m.set("version",l),m.set("rotateWorkerToken",e.rotateWorkerToken?"true":"false"),m.set("rotateManagerToken",e.rotateManagerToken?"true":"false"),m.set("rotateManagerUnlockKey",e.rotateManagerUnlockKey?"true":"false");let c={path:"/swarm/update",method:"POST",query:m,body:r};return yield t.dial(c)})}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 O=class n extends g{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,a=new Map;a.set("version",r);let o=e.Spec;o.Labels=t.Labels;let l={path:"/secrets/"+this.id+"/update",method:"POST",query:a,body:o};yield this.modem.dial(l)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&n.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&&S in t.Spec.Labels}static fromSecret(t,e){let r=e.ID;return new n(t,r)}};var N=class n{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/secrets",method:"GET",query:a};return yield t.dial(o)})}static create(t,e){return i(this,null,function*(){let r={path:"/secrets/create",method:"POST",body:e},a=yield t.dial(r);return new O(t,a.ID)})}static exists(t,e){return i(this,null,function*(){let r=new Map;r.set("name",Array.of(e));let a=yield n.list(t,{filters:r});return{exists:a.length>0,handle:a.length>0?O.fromSecret(t,a[0]):void 0}})}static getHandle(t,e){return new O(t,e)}};var b=class n{static list(r){return i(this,arguments,function*(t,e={}){let a=typeof e.status=="undefined"?!0:e.status,o=new Map;o.set("status",a?"true":"false"),e.filters&&o.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let l={path:"/services",method:"GET",query:o};return yield t.dial(l)})}static create(t,e,r){return i(this,null,function*(){let a=new Map;r&&a.set("X-Registry-Auth",r);let o={path:"/services/create",method:"POST",headers:a,body:e},l=yield t.dial(o);return new V(t,l.ID)})}static exists(t,e){return i(this,null,function*(){let r=new Map;r.set("name",Array.of(e));let a=yield n.list(t,{filters:r});return{exists:a.length>0,handle:a.length>0?V.fromService(t,a[0]):void 0}})}static getHandle(t,e){return new V(t,e)}};var V=class n extends g{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(a){return i(this,arguments,function*(t,e={},r){let l=(yield this.inspect()).Version.Index,m=new Map;r&&m.set("X-Registry-Auth",r);let c=new Map;c.set("version",l),c.set("registryAuthFrom",e.registryAuthFrom||"spec"),e.rollback&&c.set("rollback",e.rollback);let u=t,f={path:"/services/"+this.id+"/update",method:"POST",headers:m,query:c,body:u};return yield this.modem.dial(f)})}redeploy(t){return i(this,null,function*(){let e=yield this.inspect({insertDefaults:!0});if(this.shouldThrowStackError()&&n.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 b.create(this.modem,r,t)})}rollback(){return i(this,arguments,function*(t={registryAuthFrom:"spec"},e){let r=yield this.inspect(),a=Object.assign(t,{rollback:"previous"});return yield this.update(r.Spec,a,e)})}stop(){return i(this,null,function*(){var r,a;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(a=e.Mode)!=null&&a.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 a,o,l,m,c;let t=yield this.inspect(),e=t.Spec,r=t.PreviousSpec;if(r&&((a=r.Mode)!=null&&a.Replicated)&&r.Mode.Replicated.Replicas>0&&((o=e.Mode)!=null&&o.Replicated)&&e.Mode.Replicated.Replicas<=0)return yield this.rollback();throw r&&((l=r.Mode)!=null&&l.Replicated)&&r.Mode.Replicated.Replicas>0&&((m=e.Mode)!=null&&m.Replicated)&&e.Mode.Replicated.Replicas>0?new Error("This service is not stoppped"):r&&((c=r.Mode)!=null&&c.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()&&n.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&&S in t.Spec.Labels}static fromService(t,e){let r=e.ID;return new n(t,r)}};var te=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 a=new Map;e.since&&a.set("since",e.since),e.until&&a.set("until",e.until),e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/events",method:"GET",query:a,isStream:!0};return yield t.dial(o)})}static usageData(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.type&&a.set("type",JSON.stringify(e.type));let o={path:"/system/df",method:"GET",query:a};return yield t.dial(o)})}};var $=class n extends g{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 n(t,r)}};var re=class{static list(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/tasks",method:"GET",query:a};return yield t.dial(o)})}static getHandle(t,e){return new $(t,e)}};var H=class n extends g{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()&&n.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 a={path:"/volumes/"+this.id,method:"DELETE",query:r};yield this.modem.dial(a)})}shouldThrowStackError(){return!0}static isPartOfStack(t){return t.Labels&&S in t.Labels}static fromVolume(t,e){let r=e.Name;return new n(t,r)}};var E=class n extends H{inspect(){return i(this,null,function*(){return yield ie(n.prototype,this,"inspectResult").call(this)})}update(t){return i(this,null,function*(){let e=yield this.inspect(),r=e.ClusterVolume.Version.Index,a={Spec:e.ClusterVolume.Spec},o=new Map;o.set("version",r.toString()),a.Spec.Availability=t.ClusterVolumeSpec.Availability;let l={path:"/volumes/"+this.id,method:"PUT",query:o,body:a};yield this.modem.dial(l)})}remove(){return i(this,null,function*(){let t=yield this.inspect();if(this.shouldThrowStackError()&&n.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 ie(n.prototype,this,"remove").call(this,e)})}static isPartOfStack(t){return t.Labels&&S in t.Labels}static fromClusterVolume(t,e){let r=e.ClusterVolume.ID;return new n(t,r)}};var M=class n{static _list(a,o){return i(this,arguments,function*(t,e,r={}){let l=new Map;r.filters&&l.set("filters",JSON.stringify(Object.fromEntries(r.filters)));let m={path:"/volumes",method:"GET",query:l},c=yield t.dial(m);return c.Volumes=c.Volumes.filter(e),c})}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 a=o=>!("ClusterVolume"in o);return n._list(t,a,e)})}static listCluster(r){return i(this,arguments,function*(t,e={}){let a=o=>"ClusterVolume"in o;return n._list(t,a,e)})}static create(t,e){return i(this,null,function*(){let r=yield n._create(t,e);return new H(t,r.Name)})}static createCluster(t,e){return i(this,null,function*(){let r=yield n._create(t,e);return new E(t,r.ClusterVolume.ID)})}static existsCluster(t,e){return i(this,null,function*(){let r=new Map;r.set("name",Array.of(e));let a=yield n.listCluster(t,{filters:r});return{exists:a.Volumes.length>0,handle:a.Volumes.length>0?E.fromClusterVolume(t,a.Volumes[0]):void 0}})}static prune(r){return i(this,arguments,function*(t,e={}){let a=new Map;e.filters&&a.set("filters",JSON.stringify(Object.fromEntries(e.filters)));let o={path:"/volumes/prune",method:"POST",query:a};return yield t.dial(o)})}static getHandle(t,e){return new H(t,e)}static getClusterHandle(t,e){return new E(t,e)}static isClusterVolume(t){return typeof t=="object"&&"ClusterVolumeSpec"in t}};var se=class n extends V{shouldThrowStackError(){return!1}static fromService(t,e){let r=e.ID;return new n(t,r)}},oe=class n extends L{shouldThrowStackError(){return!1}static fromNetwork(t,e){let r=e.Id;return new n(t,r)}},ne=class n extends R{shouldThrowStackError(){return!1}static fromConfig(t,e){let r=e.ID;return new n(t,r)}},le=class n extends O{shouldThrowStackError(){return!1}static fromSecret(t,e){let r=e.ID;return new n(t,r)}},ce=class n extends E{shouldThrowStackError(){return!1}static fromClusterVolume(t,e){let r=e.ClusterVolume.ID;return new n(t,r)}},G=class extends g{constructor(t,e){super(t,e)}inspect(){return i(this,null,function*(){let t=new Map;t.set("label",Array.of(S+"="+this.id));let e={filters:t},r=yield b.list(this.modem,e),a=yield T.list(this.modem,e),o=yield N.list(this.modem,e),l=yield I.list(this.modem,e),m=(yield M.list(this.modem,e)).Volumes,c=(yield M.listCluster(this.modem,e)).Volumes;return{Spec:{Name:this.id},Services:r,Configs:a,Secrets:o,Networks:l,Volumes:m,ClusterVolumes:c}})}remove(){return i(this,null,function*(){let t=new Map;t.set("label",Array.of(S+"="+this.id));let e={filters:t},o=(yield b.list(this.modem,e)).map(d=>se.fromService(this.modem,d)).map(d=>i(this,null,function*(){yield d.remove()})),c=(yield I.list(this.modem,e)).map(d=>oe.fromNetwork(this.modem,d)).map(d=>i(this,null,function*(){yield d.remove()})),h=(yield T.list(this.modem,e)).map(d=>ne.fromConfig(this.modem,d)).map(d=>i(this,null,function*(){yield d.remove()})),w=(yield N.list(this.modem,e)).map(d=>le.fromSecret(this.modem,d)).map(d=>i(this,null,function*(){yield d.remove()})),P=(yield M.listCluster(this.modem,e)).Volumes.map(d=>ce.fromClusterVolume(this.modem,d)).map(d=>i(this,null,function*(){yield d.remove()}));yield Promise.all(o),yield Promise.all(Array.of(...c,...h,...w,...P))})}};import{execFile as be}from"child_process";import{Readable as Me}from"stream";import ke from"crypto";var C=n=>t=>{let e=typeof t=="undefined"||typeof t=="string"?t:t.Name;return e&&e.startsWith(`${n}_`)?e:`${n}_${e!=null?e:ke.randomBytes(16).toString("hex")}`},k=n=>t=>(t.Labels||(t.Labels={}),t.Name=C(n)(t),t.Labels[S]=n,t);function me(n,t){if(!t.Labels||!(S in t.Labels))return n;let e=t.Labels[S];return n.has(e)||n.set(e,new Array),n.get(e).push(t),n}function pe(n,t){if(!t.Spec.Labels||!(S in t.Spec.Labels))return n;let e=t.Spec.Labels[S];return n.has(e)||n.set(e,new Array),n.get(e).push(t),n}var ae=class n{static list(t){return i(this,null,function*(){let e=new Map;e.set("label",Array.of(S));let r={filters:e},a=b.list(t,r),o=T.list(t,r),l=N.list(t,r),m=I.list(t,r),c=M.list(t,r),u=M.listCluster(t,r),f=Array.of(a,o,l),h=yield Promise.all(f),A=h[0].reduce(pe,new Map),v=h[1].reduce(pe,new Map),w=h[2].reduce(pe,new Map),D=(yield m).reduce(me,new Map),Q=(yield c).Volumes.reduce(me,new Map),P=(yield u).Volumes.reduce(me,new Map),d=Array.of(...Array.from(A.keys()),...Array.from(v.keys()),...Array.from(w.keys()),...Array.from(D.keys()),...Array.from(Q.keys()),...Array.from(P.keys())),J=new Set(d);return Array.from(J).map(s=>({Spec:{Name:s},Services:A.has(s)?Array.from(A.get(s)):new Array,Configs:v.has(s)?Array.from(v.get(s)):new Array,Secrets:w.has(s)?Array.from(w.get(s)):new Array,Networks:D.has(s)?Array.from(D.get(s)):new Array,Volumes:Q.has(s)?Array.from(Q.get(s)):new Array,ClusterVolumes:P.has(s)?Array.from(P.get(s)):new Array}))})}static create(t,e){return i(this,null,function*(){return yield new Promise(function(r,a){if(!e.Yaml){a(new Error("Stack cannot be created without valid compose data"));return}let o=be("docker",["stack","deploy","-d","--compose-file -",e.Name],function(m,c,u){m&&a(m)}),l=new Me;l.push(e.Yaml),l.push(null),o.stdin&&l.pipe(o.stdin),r(!0)}),new G(t,e.Name)})}static getObjectState(t,e,r,a){return i(this,null,function*(){let o=yield Promise.all(r.map(u=>i(null,null,function*(){return Object.assign(yield a(t,u),{name:u})}))),l=o.filter(u=>!u.exists&&r.includes(u.name)).map(u=>u.name),m=o.filter(u=>u.exists&&r.includes(u.name)&&e.includes(u.name)).reduce((u,f)=>u.set(f.name,f.handle),new Map),c=o.filter(u=>u.exists&&!r.includes(u.name)&&e.includes(u.name)).reduce((u,f)=>u.set(f.name,f.handle),new Map);return{crt:l,upd:m,rem:c}})}static createFromScratch(t,e){return i(this,null,function*(){var d,J,z;let r=yield n.getHandle(t,e.Name).inspect(),a=e.Configs?yield n.getObjectState(t,r.Configs.map(s=>s.Spec).map(C(e.Name)),e.Configs.map(C(e.Name)),T.exists):null,o=e.Secrets?yield n.getObjectState(t,r.Secrets.map(s=>s.Spec).map(C(e.Name)),e.Secrets.map(C(e.Name)),N.exists):null,l=e.Networks?yield n.getObjectState(t,r.Networks.map(C(e.Name)),e.Networks.map(C(e.Name)),I.existsCluster):null,m=e.Volumes?yield n.getObjectState(t,r.ClusterVolumes.map(C(e.Name)),e.Volumes.filter(s=>s.Name).map(C(e.Name)),M.existsCluster):null,c=yield n.getObjectState(t,r.Services.map(s=>s.Spec).map(C(e.Name)),e.Services.map(s=>s.Spec).map(C(e.Name)),b.exists),u=(d=e.Configs)==null?void 0:d.some(s=>typeof s.ProvisionalId=="undefined"&&(a==null?void 0:a.crt.includes(s.Name))),f=(J=e.Secrets)==null?void 0:J.some(s=>typeof s.ProvisionalId=="undefined"&&(o==null?void 0:o.crt.includes(s.Name))),h=(z=e.Networks)==null?void 0:z.some(s=>typeof s.ProvisionalId=="undefined"&&(l==null?void 0:l.crt.includes(s.Name)));if(u||f||h)throw new Error("Newly created configs, secrets or networks need to specifiy a provisional id in order to match them with the corresponding services or volumes");function A(s){return s.Scope="swarm",s.Driver="overlay",s}let v=e.Configs&&a?(yield Promise.all(e.Configs.map(k(e.Name)).filter(s=>a.crt.includes(s.Name)).map(s=>i(null,null,function*(){return{handle:yield T.create(t,s),provId:s.ProvisionalId}})))).reduce((s,p)=>s.set(p.provId,p.handle),new Map):null,w=e.Secrets&&o?(yield Promise.all(e.Secrets.map(k(e.Name)).filter(s=>o.crt.includes(s.Name)).map(s=>i(null,null,function*(){return{handle:yield N.create(t,s),provId:s.ProvisionalId}})))).reduce((s,p)=>s.set(p.provId,p.handle),new Map):null,D=e.Networks&&l?(yield Promise.all(e.Networks.map(k(e.Name)).filter(s=>l.crt.includes(s.Name)).map(A).map(s=>i(null,null,function*(){return{handle:yield I.create(t,s),provId:s.ProvisionalId}})))).reduce((s,p)=>s.set(p.provId,p.handle),new Map):null;e.Configs&&a&&(yield Promise.all(e.Configs.map(k(e.Name)).filter(s=>Array.from(a.upd.keys()).includes(s.Name)).map(s=>{var p;return(p=a.upd.get(s.Name))==null?void 0:p.update(s)}))),e.Secrets&&o&&(yield Promise.all(e.Secrets.map(k(e.Name)).filter(s=>Array.from(o.upd.keys()).includes(s.Name)).map(s=>{var p;return(p=o.upd.get(s.Name))==null?void 0:p.update(s)})));function Q(s){var p;return w&&(s.ClusterVolumeSpec.Secrets=(p=s.ClusterVolumeSpec.Secrets)==null?void 0:p.map(j=>w.has(j.Secret)?Object.assign(j,{Secret:w.get(j.Secret).id}):j)),s}function P(s){var p,j,ue,de,ge,ye,Se;return v&&(s.Spec.TaskTemplate.ContainerSpec.Configs=(j=(p=s.Spec.TaskTemplate.ContainerSpec)==null?void 0:p.Configs)==null?void 0:j.map(y=>v.has(y.ConfigID)?Object.assign(y,{ConfigID:v.get(y.ConfigID).id,ConfigName:C(e.Name)(y.ConfigName)}):y)),w&&(s.Spec.TaskTemplate.ContainerSpec.Secrets=(de=(ue=s.Spec.TaskTemplate.ContainerSpec)==null?void 0:ue.Secrets)==null?void 0:de.map(y=>w.has(y.SecretID)?Object.assign(y,{SecretID:w.get(y.SecretID).id,SecretName:C(e.Name)(y.SecretName)}):y)),D&&(s.Spec.TaskTemplate.Networks=(ge=s.Spec.TaskTemplate.Networks)==null?void 0:ge.map(y=>D.has(y.Target)?Object.assign(y,{Target:D.get(y.Target)}):y)),s.Spec.TaskTemplate.ContainerSpec.Mounts=(Se=(ye=s.Spec.TaskTemplate.ContainerSpec)==null?void 0:ye.Mounts)==null?void 0:Se.map(y=>(y.Type==="volume"||y.Type==="cluster")&&y.Source?Object.assign(y,{Source:C(e.Name)(y.Source)}):y),s}return e.Volumes&&m&&(yield Promise.all(e.Volumes.map(k(e.Name)).filter(s=>m.crt.includes(s.Name)).map(Q).map(s=>M.createCluster(t,s))),yield Promise.all(e.Volumes.map(k(e.Name)).filter(s=>Array.from(m.upd.keys()).includes(s.Name)).map(Q).map(s=>{var p;return(p=m.upd.get(s.Name))==null?void 0:p.update(s)}))),yield Promise.all(e.Services.map(P).filter(s=>c.crt.includes(C(e.Name)(s.Spec.Name))).map(s=>b.create(t,k(e.Name)(s.Spec),s.RegistryAuth))),yield Promise.all(e.Services.map(P).filter(s=>Array.from(c.upd.keys()).includes(C(e.Name)(s.Spec.Name))).map(s=>{var p;return(p=c.upd.get(C(e.Name)(s.Spec.Name)))==null?void 0:p.update(k(e.Name)(s.Spec),{registryAuthFrom:s.RegistryAuth?"spec":"previous-spec"},s.RegistryAuth)})),yield Promise.all(e.Services.map(P).filter(s=>Array.from(c.rem.keys()).includes(C(e.Name)(s.Spec.Name))).map(s=>{var p;return(p=c.rem.get(C(e.Name)(s.Spec.Name)))==null?void 0:p.remove()})),e.Volumes&&m&&(yield Promise.all(e.Volumes.map(k(e.Name)).filter(s=>Array.from(m.rem.keys()).includes(s.Name)).map(s=>{var p;return(p=m.rem.get(s.Name))==null?void 0:p.remove()}))),e.Configs&&a&&(yield Promise.all(e.Configs.map(k(e.Name)).filter(s=>Array.from(a.rem.keys()).includes(s.Name)).map(s=>{var p;return(p=a.rem.get(s.Name))==null?void 0:p.remove()}))),e.Secrets&&o&&(yield Promise.all(e.Secrets.map(k(e.Name)).filter(s=>Array.from(o.rem.keys()).includes(s.Name)).map(s=>{var p;return(p=o.rem.get(s.Name))==null?void 0:p.remove()}))),e.Networks&&l&&(yield Promise.all(e.Networks.map(k(e.Name)).filter(s=>Array.from(l.rem.keys()).includes(s.Name)).map(s=>{var p;return(p=l.rem.get(s.Name))==null?void 0:p.remove()}))),new G(t,e.Name)})}static getHandle(t,e){return new G(t,e)}};export{E as ClusterVolumeHandle,R as ConfigHandle,T as Configs,U as ContainerHandle,q as Containers,g as Handle,F as ImageHandle,Y as Images,X as Modem,L as NetworkHandle,I as Networks,W as NodeHandle,Z as Nodes,K as PluginHandle,_ as Plugins,O as SecretHandle,N as Secrets,V as ServiceHandle,b as Services,G as StackHandle,ae as Stacks,ee as Swarm,te as System,$ as TaskHandle,re as Tasks,H as VolumeHandle,M as Volumes}; //# sourceMappingURL=index.mjs.map