UNPKG

ipfsd-ctl

Version:

Spawn IPFS Daemons, Kubo or...

15 lines (14 loc) 21.7 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpfsdCtl = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var IpfsdCtl=(()=>{var Pe=Object.create;var R=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Re=(e,t)=>{for(var r in t)R(e,r,{get:t[r],enumerable:!0})},Y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ke(t))!Le.call(e,o)&&o!==r&&R(e,o,{get:()=>t[o],enumerable:!(n=je(t,o))||n.enumerable});return e};var H=(e,t,r)=>(r=e!=null?Pe(Ne(e)):{},Y(t||!e||!e.__esModule?R(r,"default",{value:e,enumerable:!0}):r,e)),Te=e=>Y(R({},"__esModule",{value:!0}),e);var de=D((er,ue)=>{"use strict";ue.exports=e=>{if(Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}});var ye=D((ge,we)=>{"use strict";var z=de(),{hasOwnProperty:me}=Object.prototype,{propertyIsEnumerable:ot}=Object,k=(e,t,r)=>Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}),st=ge,he={concatArrays:!1,ignoreUndefined:!1},I=e=>{let t=[];for(let r in e)me.call(e,r)&&t.push(r);if(Object.getOwnPropertySymbols){let r=Object.getOwnPropertySymbols(e);for(let n of r)ot.call(e,n)&&t.push(n)}return t};function N(e){return Array.isArray(e)?it(e):z(e)?at(e):e}function it(e){let t=e.slice(0,0);return I(e).forEach(r=>{k(t,r,N(e[r]))}),t}function at(e){let t=Object.getPrototypeOf(e)===null?Object.create(null):{};return I(e).forEach(r=>{k(t,r,N(e[r]))}),t}var be=(e,t,r,n)=>(r.forEach(o=>{typeof t[o]>"u"&&n.ignoreUndefined||(o in e&&e[o]!==Object.getPrototypeOf(e)?k(e,o,W(e[o],t[o],n)):k(e,o,N(t[o])))}),e),ct=(e,t,r)=>{let n=e.slice(0,0),o=0;return[e,t].forEach(i=>{let p=[];for(let f=0;f<i.length;f++)me.call(i,f)&&(p.push(String(f)),i===e?k(n,o++,i[f]):k(n,o++,N(i[f])));n=be(n,i,I(i).filter(f=>!p.includes(f)),r)}),n};function W(e,t,r){return r.concatArrays&&Array.isArray(e)&&Array.isArray(t)?ct(e,t,r):!z(t)||!z(e)?N(t):be(e,t,I(t),r)}we.exports=function(...e){let t=W(N(he),this!==st&&this||{},he),r={_:{}};for(let n of e)if(n!==void 0){if(!z(n))throw new TypeError("`"+n+"` is not an Option Object");r=W(r,{_:n},t)}return r._}});var Ee=D((rr,Fe)=>{function ft(){return!!(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&process.versions.electron||typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Electron")>=0)}Fe.exports=ft});var ht={};Re(ht,{createFactory:()=>Oe,createNode:()=>ut,createServer:()=>dt});var J=class{options;port;host;constructor(t={port:43134,host:"localhost"}){this.options=t,this.port=this.options.port??43134,this.host=this.options.host??"localhost",console.warn("Server not implemented in the browser")}async start(){return console.warn("Server not implemented in the browser"),this}async stop(){console.warn("Server not implemented in the browser")}},ee=J;var gt=new Uint8Array(0);function te(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Me(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),p=i.charCodeAt(0);if(r[p]!==255)throw new TypeError(i+" is ambiguous");r[p]=o}var f=e.length,E=e.charAt(0),A=Math.log(f)/Math.log(256),s=Math.log(256)/Math.log(f);function a(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var m=0,d=0,l=0,h=c.length;l!==h&&c[l]===0;)l++,m++;for(var b=(h-l)*s+1>>>0,C=new Uint8Array(b);l!==h;){for(var g=c[l],S=0,w=b-1;(g!==0||S<d)&&w!==-1;w--,S++)g+=256*C[w]>>>0,C[w]=g%f>>>0,g=g/f>>>0;if(g!==0)throw new Error("Non-zero carry");d=S,l++}for(var F=b-d;F!==b&&C[F]===0;)F++;for(var O=E.repeat(m);F<b;++F)O+=e.charAt(C[F]);return O}function u(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var m=0;if(c[m]!==" "){for(var d=0,l=0;c[m]===E;)d++,m++;for(var h=(c.length-m)*A+1>>>0,b=new Uint8Array(h);c[m];){var C=r[c.charCodeAt(m)];if(C===255)return;for(var g=0,S=h-1;(C!==0||g<l)&&S!==-1;S--,g++)C+=f*b[S]>>>0,b[S]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");l=g,m++}if(c[m]!==" "){for(var w=h-l;w!==h&&b[w]===0;)w++;for(var F=new Uint8Array(d+(h-w)),O=d;w!==h;)F[O++]=b[w++];return F}}}function $(c){var m=u(c);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:u,decode:$}}var ze=Me,Ie=ze,re=Ie;var _=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},V=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ne(this,t)}},B=class{decoders;constructor(t){this.decoders=t}or(t){return ne(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ne(e,t){return new B({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var K=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new _(t,r,n),this.decoder=new V(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function oe({name:e,prefix:t,encode:r,decode:n}){return new K(e,t,r,n)}function q({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=re(r,e);return oe({prefix:t,name:e,encode:n,decode:i=>te(o(i))})}function De(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),p=0,f=0,E=0;for(let A=0;A<o;++A){let s=t[e[A]];if(s===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|s,p+=r,p>=8&&(p-=8,i[E++]=255&f>>p)}if(p>=r||(255&f<<8-p)!==0)throw new SyntaxError("Unexpected end of data");return i}function Je(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",p=0,f=0;for(let E=0;E<e.length;++E)for(f=f<<8|e[E],p+=8;p>r;)p-=r,i+=t[o&f>>p];if(p!==0&&(i+=t[o&f<<r-p]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function _e(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=_e(n);return oe({prefix:t,name:e,encode(i){return Je(i,n,r)},decode(i){return De(i,o,r,e)}})}var se=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),St=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vt=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),At=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$t=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ot=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ut=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Pt=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jt=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ie=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Lt=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ae=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mt=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zt=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),It=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Ve(e,t){if(typeof e=="string")return Be(e);if(typeof e=="number")return Ge(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var T=Ve;function Be(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Ke(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function qe(e){let t=Math.abs(e);return t>=315576e5?U(e,t,315576e5,"year"):t>=26298e5?U(e,t,26298e5,"month"):t>=6048e5?U(e,t,6048e5,"week"):t>=864e5?U(e,t,864e5,"day"):t>=36e5?U(e,t,36e5,"hour"):t>=6e4?U(e,t,6e4,"minute"):t>=1e3?U(e,t,1e3,"second"):`${e} ms`}function Ge(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?qe(e):Ke(e)}function U(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function G(e){r.debug=r,r.default=r,r.coerce=E,r.disable=i,r.enable=o,r.enabled=p,r.humanize=T,r.destroy=A,Object.keys(e).forEach(s=>{r[s]=e[s]}),r.names=[],r.skips=[],r.formatters={};function t(s){let a=0;for(let u=0;u<s.length;u++)a=(a<<5)-a+s.charCodeAt(u),a|=0;return r.colors[Math.abs(a)%r.colors.length]}r.selectColor=t;function r(s,a){let u,$=null,c,m;function d(...l){if(!d.enabled)return;let h=d,b=Number(new Date),C=b-(u||b);h.diff=C,h.prev=u,h.curr=b,u=b,l[0]=r.coerce(l[0]),typeof l[0]!="string"&&l.unshift("%O");let g=0;l[0]=l[0].replace(/%([a-zA-Z%])/g,(w,F)=>{if(w==="%%")return"%";g++;let O=r.formatters[F];if(typeof O=="function"){let Ue=l[g];w=O.call(h,Ue),l.splice(g,1),g--}return w}),r.formatArgs.call(h,l),a?.onLog!=null&&a.onLog(...l),(h.log||r.log).apply(h,l)}return d.namespace=s,d.useColors=r.useColors(),d.color=r.selectColor(s),d.extend=n,d.destroy=r.destroy,Object.defineProperty(d,"enabled",{enumerable:!0,configurable:!1,get:()=>$!==null?$:(c!==r.namespaces&&(c=r.namespaces,m=r.enabled(s)),m),set:l=>{$=l}}),typeof r.init=="function"&&r.init(d),d}function n(s,a){let u=r(this.namespace+(typeof a>"u"?":":a)+s);return u.log=this.log,u}function o(s){r.save(s),r.namespaces=s,r.names=[],r.skips=[];let a,u=(typeof s=="string"?s:"").split(/[\s,]+/),$=u.length;for(a=0;a<$;a++)u[a]&&(s=u[a].replace(/\*/g,".*?"),s[0]==="-"?r.skips.push(new RegExp("^"+s.substr(1)+"$")):r.names.push(new RegExp("^"+s+"$")))}function i(){let s=[...r.names.map(f),...r.skips.map(f).map(a=>"-"+a)].join(",");return r.enable(""),s}function p(s){if(s[s.length-1]==="*")return!0;let a,u;for(a=0,u=r.skips.length;a<u;a++)if(r.skips[a].test(s))return!1;for(a=0,u=r.names.length;a<u;a++)if(r.names[a].test(s))return!0;return!1}function f(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function E(s){return s instanceof Error?s.stack??s.message:s}function A(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var M=et(),We=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Xe(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Ze(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+T(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var Qe=console.debug??console.log??(()=>{});function Ye(e){try{e?M?.setItem("debug",e):M?.removeItem("debug")}catch{}}function He(){let e;try{e=M?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function et(){try{return localStorage}catch{}}function tt(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ce=G({formatArgs:Ze,save:Ye,load:He,useColors:Xe,setupFormatters:tt,colors:We,storage:M,log:Qe});var x=ce;x.formatters.b=e=>e==null?"undefined":ie.baseEncode(e);x.formatters.t=e=>e==null?"undefined":se.baseEncode(e);x.formatters.m=e=>e==null?"undefined":ae.baseEncode(e);x.formatters.p=e=>e==null?"undefined":e.toString();x.formatters.c=e=>e==null?"undefined":e.toString();x.formatters.k=e=>e==null?"undefined":e.toString();x.formatters.a=e=>e==null?"undefined":e.toString();function fe(e,t=""){let r=le(e.message),n=le(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(` `).join(` ${t}`)}`:`${r} ${t}${n.split(` `).join(` ${t}`)}`:n!=null?`${n.split(` `).join(` ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function rt(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function pe(e,t=""){if(rt(e)){let r=fe(e,t);return e.errors.length>0?(t=`${t} `,r+=` ${t}${e.errors.map(n=>`${pe(n,`${t}`)}`).join(` ${t}`)}`):r+=` ${t}[Error list was empty]`,r.trim()}return fe(e,t)}x.formatters.e=e=>e==null?"undefined":pe(e);function nt(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function L(e,t){let r=nt(`${e}:trace`);return x.enabled(`${e}:trace`)&&x.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=x(`${e}:trace`,t)),Object.assign(x(e,t),{error:x(`${e}:error`,t),trace:r,newScope:n=>L(`${e}:${n}`,t)})}function le(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Ce=H(ye(),1),xe=Ce.default;var Se=H(Ee(),1),lt=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,ve=(0,Se.default)();var Ae=ve&&!lt;var $e=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!ve,nr=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,or=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",sr=typeof navigator<"u"&&navigator.product==="ReactNative";var v=L("ipfsd-ctl:kubo:client"),P=class{options;peerInfo;id;disposable;repo;endpoint;_api;initArgs;startArgs;stopArgs;constructor(t){if(t.rpc==null)throw new Error("Please pass an rpc option");this.options=t,this.endpoint=t.endpoint,this.disposable=t.disposable,this.id=t.id,this.repo=t.repo,t.init!=null&&typeof t.init!="boolean"&&(this.initArgs=t.init),t.start!=null&&typeof t.start!="boolean"&&(this.startArgs=t.start),t.stop!=null&&(this.stopArgs=t.stop)}get api(){if(this._api==null)throw new Error("Not started");return this._api}async info(){v("info %s/info?%s",this.endpoint,new URLSearchParams({id:this.id}).toString());let t=await fetch(`${this.endpoint}/info?${new URLSearchParams({id:this.id})}`,{method:"GET"});if(v("info %s/info?%s %d",this.endpoint,new URLSearchParams({id:this.id}).toString(),t.status),!t.ok)throw new Error(`Error getting remote kubo info - ${await t.text()}`);return t.json()}async init(t){v("init %s/init?%s",this.endpoint,new URLSearchParams({id:this.id}).toString());let r=await fetch(`${this.endpoint}/init?${new URLSearchParams({id:this.id})}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...this.initArgs??{},...t??{}})});if(v("init %s/init?%s %d",this.endpoint,new URLSearchParams({id:this.id}).toString(),r.status),!r.ok)throw new Error(`Error initializing remote kubo - ${await r.text()}`)}async start(t){v("start %s/start?%s",this.endpoint,new URLSearchParams({id:this.id}).toString());let r=await fetch(`${this.endpoint}/start?${new URLSearchParams({id:this.id})}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...this.startArgs??{},...t??{}})});if(!r.ok)throw new Error(`Error starting remote kubo - ${await r.text()}`);let n=await r.json();this._api=this.options.rpc(n.api)}async stop(t){v("stop %s/stop?%s",this.endpoint,new URLSearchParams({id:this.id}).toString());let r=await fetch(`${this.endpoint}/stop?${new URLSearchParams({id:this.id})}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...this.stopArgs??{},...t??{}})});if(v("stop %s/stop?%s %d",this.endpoint,new URLSearchParams({id:this.id}).toString(),r.status),!r.ok)throw new Error(`Error stopping remote kubo - ${await r.text()}`);this.disposable&&await this.cleanup()}async cleanup(){v("cleanup %s/cleanup?%s",this.endpoint,new URLSearchParams({id:this.id}).toString());let t=await fetch(`${this.endpoint}/cleanup?${new URLSearchParams({id:this.id})}`,{method:"POST"});if(v("cleanup %s/cleanup?%s %d",this.endpoint,new URLSearchParams({id:this.id}).toString(),t.status),!t.ok)throw new Error(`Error cleaning up remote kubo - ${await t.text()}`)}};var j=L("ipfsd-ctl:factory"),X=xe.bind({ignoreUndefined:!0}),pt={endpoint:process.env.IPFSD_CTL_SERVER??"http://localhost:43134",remote:!$e&&!Ae,disposable:!0,test:!1,type:"kubo",env:{},args:[],forceKill:!0,forceKillTimeout:5e3},Z=class{options;controllers;overrides;constructor(t={},r={}){this.options=X({},pt,t),this.overrides=X({kubo:this.options},r),this.controllers=[]}async spawn(t){let r=t?.type??this.options.type??"kubo",n=X({},this.options,this.overrides[r],t),o;if(r==="kubo")if(n.remote===!0){j("spawn remote %s node",r);let i=await fetch(`${n.endpoint}/spawn`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...n,remote:!1})});j("spawned remote %s node",r);let p=await i.json();j("remote %s node %o",r,p),o=new P({...n,...p})}else j("spawn local %s node",r),o=new P(n);if(o==null)throw new Error(`Unsupported type "${r}" - configured types [${[...new Set([this.options.type,...Object.keys(this.overrides)].filter(Boolean))].join(", ")}]`);return this.controllers.push(o),n.init!==!1&&(j("spawn init %s %s node",n.remote?"remote":"local",r),await o.init(n.init)),n.start!==!1&&(j("spawn start %s %s node",n.remote?"remote":"local",r),await o.start(n.start)),j("spawned %s %s node",n.remote?"remote":"local",r),o}async clean(){await Promise.all(this.controllers.map(async t=>t.stop())),this.controllers=[]}},Q=Z;function Oe(e,t){return new Q(e,t)}async function ut(e){return new Q().spawn(e)}var dt=(e,t={},r={})=>{let n;return typeof e=="number"?n=e:e!=null&&(n=e.port),new ee({port:n,host:"127.0.0.1"},Oe(t,r))};return Te(ht);})(); return IpfsdCtl})); //# sourceMappingURL=index.min.js.map