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