@dockstat/docker 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/types.d.ts +2442 -0
- package/package.json +10 -3
- package/src/docker.ts +0 -35
- package/src/environment.d.ts +0 -15
- package/src/index.ts +0 -9
- package/src/modules/_socket/index.ts +0 -106
- package/src/modules/base/index.ts +0 -30
- package/src/modules/base/types.ts +0 -17
- package/src/modules/container/index.ts +0 -384
- package/src/modules/container/types.ts +0 -673
- package/src/modules/distribution/index.ts +0 -14
- package/src/modules/distribution/types.ts +0 -24
- package/src/modules/exec/index.ts +0 -60
- package/src/modules/exec/types.ts +0 -64
- package/src/modules/images/index.ts +0 -220
- package/src/modules/images/types.ts +0 -686
- package/src/modules/networks/index.ts +0 -87
- package/src/modules/networks/types.ts +0 -258
- package/src/modules/nodes/index.ts +0 -48
- package/src/modules/nodes/types.ts +0 -69
- package/src/modules/plugins/index.ts +0 -128
- package/src/modules/plugins/types.ts +0 -114
- package/src/modules/secrets/index.ts +0 -5
- package/src/modules/secrets/types.ts +0 -0
- package/src/modules/volumes/index.ts +0 -65
- package/src/modules/volumes/types.ts +0 -197
- package/src/utils/env.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/request-options.ts +0 -68
- package/src/utils/response.ts +0 -31
- package/src/utils/url.ts +0 -48
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function w(E,C,M,F,A){let K=typeof M==="object"&&!(M instanceof FormData)&&M!==void 0,R={Host:"localhost"};if(K)R["Content-Type"]="application/json";if(F)if(F instanceof Headers)F.forEach(($,G)=>{R[G]=$});else if(Array.isArray(F))F.forEach(([$,G])=>{if($!==void 0&&G!==void 0)R[$]=G});else Object.assign(R,F);let Q=K?JSON.stringify(M):M,O={method:C,headers:R,body:Q};if(E.mode!=="unix"&&A)try{let $=new URL(A);R.Host=$.host}catch($){}if(E.mode==="unix"&&E.socketPath)O.unix=E.socketPath;if(E.tls)O.tls=E.tls;return O}class N extends Error{status;path;version;params;constructor(E,C,M,F,A){super(E);this.name="DockerError",this.status=C,this.path=M,this.version=F,this.params=A,Object.setPrototypeOf(this,N.prototype)}}async function x(E,C,M,F){if(!E.ok){let A=await E.text();try{let K=JSON.parse(A);if(K.message)A=K.message}catch(K){}throw new N(`Docker API Error (${E.status}): ${A}`,E.status,C,M,F||"No params defined")}return E}function H(E){if(!E)return;let C=new URLSearchParams;for(let[M,F]of Object.entries(E)){if(F===void 0)continue;if(typeof F==="string")C.append(M,F);else if(typeof F==="number"||typeof F==="boolean")C.append(M,F.toString());else C.append(M,JSON.stringify(F))}return C.toString()}function l(E,C,M,F){let A=M?`?${M}`:"";if(E.mode==="unix")return`http://localhost/${F}${C}${A}`;let K=E.baseUrl||"",R=K.endsWith("/")?"":"/";return`${K}${R}${F}${C}${A}`}class j{static CONNECTING=0;static OPEN=1;static CLOSING=2;static CLOSED=3;readyStateValue=j.CONNECTING;listeners=new Map;reader=null;addEventListener(E,C){if(!this.listeners.has(E))this.listeners.set(E,[]);this.listeners.get(E)?.push(C)}removeEventListener(E,C){let M=this.listeners.get(E);if(M){let F=M.indexOf(C);if(F>-1)M.splice(F,1)}}async attach(E){if(!E.body){this.emit("error",Error("Response has no body")),this.readyStateValue=j.CLOSED,this.emit("close",{});return}this.reader=E.body.getReader(),this.readyStateValue=j.OPEN,this.emit("open",{});try{while(this.readyStateValue===j.OPEN){let{done:C,value:M}=await this.reader.read();if(C)break;let F=new TextDecoder().decode(M);this.emit("message",{data:F})}}catch(C){if(this.readyStateValue!==j.CLOSING)this.emit("error",C)}finally{this.readyStateValue=j.CLOSED,this.emit("close",{})}}close(){if(this.readyStateValue===j.CLOSED)return;if(this.readyStateValue=j.CLOSING,this.reader)this.reader.cancel().catch(()=>{});this.readyStateValue=j.CLOSED,this.emit("close",{})}get CONNECTING(){return j.CONNECTING}get OPEN(){return j.OPEN}get CLOSING(){return j.CLOSING}get CLOSED(){return j.CLOSED}get readyState(){return this.readyStateValue}emit(E,C){let M=this.listeners.get(E);if(M)for(let F of M)F(C)}}class _{config;constructor(E){this.config=E}ws=new j;async request(E,C="GET",M,F,A){let K=this.config.dockerAPIVersion||"1.54",R=H(A),Q=l(this.config,E,R,K),O=w(this.config,C,M,F,Q),$=await fetch(Q,O);return x($,E,K,A)}}class X extends _{async list(E){return await(await this.request("/containers/json","GET",void 0,void 0,E)).json()}async create(E,C){return await(await this.request("/containers/create","POST",E,void 0,C)).json()}async inspect(E,C=!1){return await(await this.request(`/containers/${E}/json`,"GET",void 0,void 0,{size:C})).json()}async start(E,C){await this.request(`/containers/${E}/start`,"POST",void 0,void 0,{detachKeys:C})}async stop(E,C){await this.request(`/containers/${E}/stop`,"POST",void 0,void 0,{t:C})}async restart(E,C){await this.request(`/containers/${E}/restart`,"POST",void 0,void 0,{t:C})}async kill(E,C){await this.request(`/containers/${E}/kill`,"POST",void 0,void 0,{signal:C})}async remove(E,C=!1,M=!1,F=!1){await this.request(`/containers/${E}`,"DELETE",void 0,void 0,{v:C,force:M,link:F})}async rename(E,C){await this.request(`/containers/${E}/rename`,"POST",void 0,void 0,{name:C})}async pause(E){await this.request(`/containers/${E}/pause`,"POST")}async unpause(E){await this.request(`/containers/${E}/unpause`,"POST")}async wait(E,C){return await(await this.request(`/containers/${E}/wait`,"POST",void 0,void 0,{condition:C})).json()}async top(E,C){return await(await this.request(`/containers/${E}/top`,"GET",void 0,void 0,{ps_args:encodeURIComponent(C||"")})).json()}async logs(E,C){return await this.request(`/containers/${E}/logs`,"GET",void 0,void 0,C)}async stats(E,C){let M=await this.request(`/containers/${E}/stats`,"GET",void 0,void 0,C);if(C?.stream)return M;return await M.json()}async changes(E){return await(await this.request(`/containers/${E}/changes`,"GET")).json()}async export(E){return await this.request(`/containers/${E}/export`,"GET")}async update(E,C){return(await this.request(`/containers/${E}/update`,"POST",C)).json()}async resize(E,C,M){await this.request(`/containers/${E}/resize`,"POST",void 0,void 0,{h:C,w:M})}async attach(E,C){return await this.request(`/containers/${E}/attach`,"POST",void 0,void 0,C)}async attachWebSocket(E,C){let M=await this.request(`/containers/${E}/attach`,"POST",void 0,void 0,C);return this.ws.attach(M),this.ws}async getArchive(E,C){return await this.request(`/containers/${E}/archive`,"GET",void 0,void 0,{path:C})}async archiveInfo(E,C){let F=(await this.request(`/containers/${E}/archive`,"HEAD",void 0,void 0,{path:C})).headers.get("X-Docker-Container-Path-Stat");if(!F)return null;try{return JSON.parse(F)}catch{return null}}async putArchive(E,C,M,F=!1,A=!1){await this.request(`/containers/${E}/archive`,"PUT",M,void 0,{path:C,noOverwriteDirNonDir:F,copyUIDGID:A})}async execCreate(E,C){return await(await this.request(`/containers/${E}/exec`,"POST",C)).json()}async execStart(E,C){return await this.request(`/exec/${E}/start`,"POST",void 0,void 0,C)}async execInspect(E){return await(await this.request(`/exec/${E}/json`,"GET")).json()}async execResize(E,C,M){await this.request(`/exec/${E}/resize`,"POST",void 0,void 0,{h:C,w:M})}async prune(E){return await(await this.request("/containers/prune","POST",void 0,void 0,E)).json()}}class Y extends _{async getImageInfo(E){let C=`/distribution/${E}/json`;return await(await this.request(C,"GET")).json()}}class Z extends _{async create(E,C){let M=`/containers/${E}/exec`;return await(await this.request(M,"POST",C)).json()}async start(E,C){let M=`/exec/${E}/start`;return await this.request(M,"POST",C)}async inspect(E){let C=`/exec/${E}/json`;return await(await this.request(C,"GET")).json()}async resize(E,C,M){await this.request(`/exec/${E}/resize`,"POST",void 0,void 0,{h:C,w:M})}}class u extends _{async list(E){return await(await this.request("/images/json","GET",void 0,void 0,E)).json()}async pull(E){let C={};if(E.authHeader)C["X-Registry-Auth"]=E.authHeader;return await(await this.request("/images/create","POST",E.inputImage,C,E)).json()}async inspect(E,C){return await(await this.request(`/images/${E}/json`,"GET",void 0,void 0,C)).json()}async history(E,C){return await(await this.request(`/images/${E}/history`,"GET",void 0,void 0,C)).json()}async push(E,C){let M={"X-Registry-Auth":C.authHeader};return await(await this.request(`/images/${E}/push`,"POST",void 0,M,C)).json()}async tag(E,C){await this.request(`/images/${E}/tag`,"POST",void 0,void 0,C)}async remove(E,C){return await(await this.request(`/images/${E}`,"DELETE",void 0,void 0,C)).json()}async search(E){return await(await this.request("/images/search","GET",void 0,void 0,E)).json()}async prune(E){return await(await this.request("/images/prune","POST",void 0,void 0,E)).json()}async get(E,C){return await this.request(`/images/${E}/get`,"GET",void 0,void 0,C)}async getAll(E){return await this.request("/images/get","GET",void 0,void 0,E)}async load(E){return await(await this.request("/images/load","POST",E.imagesTarball,void 0,E)).json()}async build(E){let C={"Content-Type":"application/x-tar"};if(E.authConfig)C["X-Registry-Config"]=E.authConfig;return await this.request("/build","POST",E.inputStream,C,E),!0}async pruneBuild(E){return await(await this.request("/build/prune","POST",void 0,void 0,E)).json()}async commit(E,C){return await(await this.request("/commit","POST",E,void 0,C)).json()}}class V extends _{async list(E){return await(await this.request("/networks","GET",void 0,void 0,E)).json()}async create(E){return await(await this.request("/networks/create","POST",E)).json()}async inspect(E,C){return await(await this.request(`/networks/${E}`,"GET",void 0,void 0,C)).json()}async remove(E){await this.request(`/networks/${E}`,"DELETE")}async connect(E,C){await this.request(`/networks/${E}/connect`,"POST",C)}async disconnect(E,C){await this.request(`/networks/${E}/disconnect`,"POST",C)}async prune(E){return await(await this.request("/networks/prune","POST",void 0,void 0,E)).json()}}class z extends _{async list(E){return await(await this.request("/nodes","GET",void 0,void 0,E)).json()}async inspect(E){return await(await this.request(`/nodes/${E}`,"GET")).json()}async delete(E,C=!1){return await this.request(`/nodes/${E}`,"DELETE",void 0,void 0,{force:C}),!0}async update(E,C,M){return await this.request(`/nodes/${E}/update`,"POST",M,void 0,{version:C}),!0}}class B extends _{async list(E){return await(await this.request("/volumes","GET",void 0,void 0,E)).json()}async create(E){return await(await this.request("/volumes/create","POST",E)).json()}async inspect(E){return await(await this.request(`/volumes/${encodeURIComponent(E)}`)).json()}async update(E,C,M){await this.request(`/volumes/${encodeURIComponent(E)}`,"PUT",C,void 0,{version:M})}async remove(E,C=!1){await this.request(`/volumes/${encodeURIComponent(E)}`,"DELETE",void 0,void 0,{force:C})}async prune(E){return await(await this.request("/volumes/prune","POST",void 0,void 0,E)).json()}}class J{config;containers;images;networks;volumes;exec;distribution;nodes;constructor(E){this.config=E;this.containers=new X(E),this.images=new u(E),this.networks=new V(E),this.volumes=new B(E),this.exec=new Z(E),this.distribution=new Y(E),this.nodes=new z(E)}async ping(){return(await new _(this.config).request("/_ping","GET")).ok}}import{env as L}from"process";var P=()=>{if(!(L.CERT_FILE&&L.KEY_FILE))return;return{ca:L.CA_FILE?Bun.file(L.CA_FILE):void 0,cert:L.CERT_FILE?Bun.file(L.CERT_FILE):void 0,key:L.KEY_FILE?Bun.file(L.KEY_FILE):void 0}},q=()=>{let E=L.DOCKER_SOCKET||"/var/run/docker.sock",C=P();if(E.startsWith("unix://"))return{mode:"unix",socketPath:E.replace("unix://",""),tls:C};if(E.startsWith("tcp://")||E.startsWith("http://")){let M="http://";if(C)M="https://";let F=E.replace(/^tcp:\/\/|^http:\/\//,"");return{mode:"tcp",baseUrl:`${M}${F}`,tls:C}}return{mode:"unix",socketPath:E,tls:C}};var GE=()=>{let E=q();return new J(E)};export{GE as createDockerFromEnv,J as Docker};
|