@libp2p/echo 3.1.18 → 3.1.19-848e26488
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.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +4 -4
- package/dist/typedoc-urls.json +0 -10
package/dist/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PEcho = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PEcho=(()=>{var U=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var W=(s,t)=>{for(var e in t)U(s,e,{get:t[e],enumerable:!0})},Y=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of K(t))!z.call(s,n)&&n!==e&&U(s,n,{get:()=>t[n],enumerable:!(r=Q(t,n))||r.enumerable});return s};var _=s=>Y(U({},"__esModule",{value:!0}),s);var it={};W(it,{echo:()=>ot});var y=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}},g=class extends Error{static name="TimeoutError";constructor(t="Timed out"){super(t),this.name="TimeoutError"}};function d(s=0){return new Uint8Array(s)}function p(s=0){return new Uint8Array(s)}function G(s){return s?.buffer instanceof ArrayBuffer}function S(s){if(G(s))return s;let t=s.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function A(s,t){t==null&&(t=s.reduce((n,o)=>n+o.length,0));let e=p(t),r=0;for(let n of s)e.set(n,r),r+=n.length;return S(e)}function V(s,t){if(s===t)return!0;if(s.byteLength!==t.byteLength)return!1;for(let e=0;e<s.byteLength;e++)if(s[e]!==t[e])return!1;return!0}var C=Symbol.for("@achingbrain/uint8arraylist");function N(s,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let r of s){let n=e+r.byteLength;if(t<n)return{buf:r,index:t-e};e=n}throw new RangeError("index is out of bounds")}function w(s){return!!s?.[C]}var E=class s{bufs;length;[C]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let r of t)if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.push(r);else if(w(r)){e+=r.byteLength;for(let n of r.bufs)this.bufs.push(n)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let r of t.reverse())if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.unshift(r);else if(w(r))e+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=N(this.bufs,t);return e.buf[e.index]}set(t,e){let r=N(this.bufs,t);r.buf[r.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let r=0;r<t.length;r++)this.set(e+r,t[r]);else if(w(t))for(let r=0;r<t.length;r++)this.set(e+r,t.get(r));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:r,length:n}=this._subList(t,e);return A(r,n)}subarray(t,e){let{bufs:r,length:n}=this._subList(t,e);return r.length===1?r[0]:A(r,n)}sublist(t,e){let{bufs:r,length:n}=this._subList(t,e),o=new s;return o.length=n,o.bufs=r,o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let r=[],n=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=n,u=a+i.byteLength;if(n=u,t>=u)continue;let b=t>=a&&t<u,f=e>a&&e<=u;if(b&&f){if(t===a&&e===u){r.push(i);break}let c=t-a;r.push(i.subarray(c,c+(e-t)));break}if(b){if(t===0){r.push(i);continue}r.push(i.subarray(t-a));continue}if(f){if(e===u){r.push(i);break}r.push(i.subarray(0,e-a));break}r.push(i)}return{bufs:r,length:e-t}}indexOf(t,e=0){if(!w(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let c=0;c<o;c++)i[c]=-1;for(let c=0;c<n;c++)i[r[c]]=c;let a=i,u=this.byteLength-r.byteLength,b=r.byteLength-1,f;for(let c=e;c<=u;c+=f){f=0;for(let l=b;l>=0;l--){let h=this.get(c+l);if(r[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return c}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let r=p(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,e),this.write(r,t)}getInt16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,e)}setInt16(t,e,r){let n=d(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,r),this.write(n,t)}getInt32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,e)}setInt32(t,e,r){let n=d(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,r),this.write(n,t)}getBigInt64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,e)}setBigInt64(t,e,r){let n=d(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,r),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let r=p(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,e),this.write(r,t)}getUint16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,e)}setUint16(t,e,r){let n=d(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,r),this.write(n,t)}getUint32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,e)}setUint32(t,e,r){let n=d(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,r),this.write(n,t)}getBigUint64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,e)}setBigUint64(t,e,r){let n=d(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,r),this.write(n,t)}getFloat32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,e)}setFloat32(t,e,r){let n=d(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,r),this.write(n,t)}getFloat64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,e)}setFloat64(t,e,r){let n=d(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,r),this.write(n,t)}equals(t){if(t==null||!(t instanceof s)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!V(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let r=new s;return r.bufs=t,e==null&&(e=t.reduce((n,o)=>n+o.byteLength,0)),r.length=e,r}};var T=class s extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,s)}},M=s=>s.reason??new DOMException("This operation was aborted.","AbortError");function O(s,t){let{milliseconds:e,fallback:r,message:n,customTimers:o={setTimeout,clearTimeout},signal:i}=t,a,u,f=new Promise((c,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){l(M(i)),s.then(c,l);return}if(i&&(u=()=>{l(M(i))},i.addEventListener("abort",u,{once:!0})),s.then(c,l),e===Number.POSITIVE_INFINITY)return;let h=new T;a=o.setTimeout.call(void 0,()=>{if(r){try{c(r())}catch(v){l(v)}return}typeof s.cancel=="function"&&s.cancel(),n===!1?c():n instanceof Error?l(n):(h.message=n??`Promise timed out after ${e} milliseconds`,l(h))},e)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var F=s=>typeof s=="function"?{filter:s}:{...s},J=s=>s===1/0||Number.isSafeInteger(s)&&s>=0,X=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Z=s=>{for(let[t,e]of X){let r=s?.[t],n=s?.[e];if(typeof r=="function"&&typeof n=="function")return{addListener:r.bind(s),removeListener:n.bind(s)}}throw new TypeError("Emitter is not compatible")},tt=s=>{let t=new Map;for(let[e,r]of s)for(let n of Array.isArray(e)?e:[e])t.has(n)||t.set(n,r);return t},et=({addListener:s,removeListener:t,handlers:e,signal:r,abortHandler:n,isDone:o})=>{r?.addEventListener("abort",n,{once:!0});for(let[i,a]of e)if(s(i,a),o()){t(i,a);return}},rt=({removeListener:s,handlers:t,signal:e,abortHandler:r})=>{for(let[n,o]of t)s(n,o);e?.removeEventListener("abort",r)},nt=(s,t,e)=>{let r=Promise.resolve();return(n,o)=>{r=r.then(async()=>{if(t())return;let i;try{i=s?await s(n):!0}catch(a){t()||e(a);return}t()||o(i)})}};function st(s,t,e){let r=()=>{},n=!1,o,i=new Promise((a,u)=>{e=F(e);let{filter:b}=e;if(!J(e.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof e.timeout=="number"&&!(e.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${e.timeout}\``);e.signal?.throwIfAborted();let{addListener:f,removeListener:c}=Z(s);if(e.count===0){a([]);return}let l=[],h=m=>{r(),u(m)},v=nt(b,()=>n,h),P=m=>{l.push(m),e.count===l.length&&(r(),a(l))},j=(...m)=>{if(n)return;let I=e.multiArgs?m:m[0];if(!b){P(I);return}v(I,q=>{q&&P(I)})},H=(...m)=>{h(e.rejectionMultiArgs?m:m[0])},$=()=>{h(e.signal.reason)},D={addListener:f,removeListener:c,handlers:tt([[t,j],[e.rejectionEvents??["error"],H]]),signal:e.signal,abortHandler:$,isDone:()=>n};r=()=>{n=!0,clearTimeout(o),rt(D)},et(D),!(n||!e.resolveImmediately)&&(Number.isFinite(e.timeout)&&(o=setTimeout(r,e.timeout)),a(l))});if(i.cancel=r,typeof e.timeout=="number"&&e.timeout>0&&!e.resolveImmediately){let a=O(i,{milliseconds:e.timeout});return a.cancel=()=>{r(),a.clear()},a}return i}function B(s,t,e){let r=st(s,t,{...F(e),count:1,resolveImmediately:!1}),n=r.then(o=>o[0]);return n.cancel=r.cancel,n}var x=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var R="1.0.0",k="echo";var L=class{protocol;components;started;init;timeout;constructor(t,e={}){this.started=!1,this.components=t,this.protocol=`/${[e.protocolPrefix,k,R].filter(Boolean).join("/")}`,this.init=e,this.timeout=e.timeout??2e4}[Symbol.toStringTag]="@libp2p/echo";async start(){await this.components.registrar.handle(this.protocol,this.onEcho.bind(this),{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams,runOnLimitedConnection:this.init.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async onEcho(t){let e=t.log.newScope("echo"),r=Date.now(),n=AbortSignal.timeout(this.timeout);let o=0;n.addEventListener("abort",()=>{t.abort(new g)});for await(let i of t){if(o+=i.byteLength,t.status!=="open"){e("stream status changed to %s",t.status);break}t.send(i)?e("sent %d bytes",o):(e("sent %d bytes, wait for drain",o),await B(t,"drain",{rejectionEvents:["close"],signal:n}))}e("echoed %d bytes in %dms",o,Date.now()-r),await t.close({signal:n})}async echo(t,e,r){let n=await this.components.connectionManager.openStream(t,this.protocol,{...this.init,...r}),o=n.log.newScope("echo"),i=new E,a=Promise.withResolvers();return n.addEventListener("message",u=>{i.append(u.data),o("received %d/%d bytes",i.byteLength,e.byteLength)}),n.addEventListener("close",u=>{u.error!=null&&a.reject(u.error),i.byteLength>e.byteLength&&a.reject(new y(`Overread: ${i.byteLength}/${e.byteLength} bytes`)),i.byteLength<e.byteLength&&a.reject(new x(`Underread: ${i.byteLength}/${e.byteLength} bytes`)),a.resolve(i)}),o("sending %d bytes",e.byteLength),n.send(e),await n.close(r).catch(u=>{a.reject(u)}),a.promise}};function ot(s={}){return t=>new L(t,s)}return _(it);})();
|
|
2
|
+
"use strict";var Libp2PEcho=(()=>{var O=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var z=(s,t)=>{for(var e in t)O(s,e,{get:t[e],enumerable:!0})},W=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Q(t))!K.call(s,n)&&n!==e&&O(s,n,{get:()=>t[n],enumerable:!(r=q(t,n))||r.enumerable});return s};var G=s=>W(O({},"__esModule",{value:!0}),s);var ct={};z(ct,{echo:()=>at});var w=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}},E=class extends Error{static name="TimeoutError";constructor(t="Timed out"){super(t),this.name="TimeoutError"}};function b(s=0){return new Uint8Array(s)}function y(s=0){return new Uint8Array(s)}function J(s){return s?.buffer instanceof ArrayBuffer}function C(s){if(J(s))return s;let t=s.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function P(s,t){t==null&&(t=s.reduce((n,o)=>n+o.length,0));let e=y(t),r=0;for(let n of s)e.set(n,r),r+=n.length;return C(e)}function M(s,t){if(s===t)return!0;if(s.byteLength!==t.byteLength)return!1;for(let e=0;e<s.byteLength;e++)if(s[e]!==t[e])return!1;return!0}var B=Symbol.for("@achingbrain/uint8arraylist");function N(s,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let r of s){let n=e+r.byteLength;if(t<n)return{buf:r,index:t-e};e=n}throw new RangeError("index is out of bounds")}function x(s){return!!s?.[B]}var L=class s{bufs;length;[B]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let r of t)if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.push(r);else if(x(r)){e+=r.byteLength;for(let n of r.bufs)this.bufs.push(n)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let r of t.reverse())if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.unshift(r);else if(x(r))e+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=N(this.bufs,t);return e.buf[e.index]}set(t,e){let r=N(this.bufs,t);r.buf[r.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let r=0;r<t.length;r++)this.set(e+r,t[r]);else if(x(t))for(let r=0;r<t.length;r++)this.set(e+r,t.get(r));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:r,length:n}=this._subList(t,e);return P(r,n)}subarray(t,e){let{bufs:r,length:n}=this._subList(t,e);return r.length===1?r[0]:P(r,n)}sublist(t,e){let{bufs:r,length:n}=this._subList(t,e),o=new s;return o.length=n,o.bufs=r,o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let r=[],n=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=n,c=a+i.byteLength;if(n=c,t>=c)continue;let h=t>=a&&t<c,m=e>a&&e<=c;if(h&&m){if(t===a&&e===c){r.push(i);break}let u=t-a;r.push(i.subarray(u,u+(e-t)));break}if(h){if(t===0){r.push(i);continue}r.push(i.subarray(t-a));continue}if(m){if(e===c){r.push(i);break}r.push(i.subarray(0,e-a));break}r.push(i)}return{bufs:r,length:e-t}}indexOf(t,e=0){if(!x(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let n=r.byteLength;if(n===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<n;u++)i[r[u]]=u;let a=i,c=this.byteLength-r.byteLength,h=r.byteLength-1,m;for(let u=e;u<=c;u+=m){m=0;for(let l=h;l>=0;l--){let f=this.get(u+l);if(r[l]!==f){m=Math.max(1,l-a[f]);break}}if(m===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let r=y(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,e),this.write(r,t)}getInt16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,e)}setInt16(t,e,r){let n=b(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt16(0,e,r),this.write(n,t)}getInt32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,e)}setInt32(t,e,r){let n=b(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt32(0,e,r),this.write(n,t)}getBigInt64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,e)}setBigInt64(t,e,r){let n=b(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigInt64(0,e,r),this.write(n,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let r=y(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,e),this.write(r,t)}getUint16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,e)}setUint16(t,e,r){let n=b(2);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint16(0,e,r),this.write(n,t)}getUint32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,e)}setUint32(t,e,r){let n=b(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint32(0,e,r),this.write(n,t)}getBigUint64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,e)}setBigUint64(t,e,r){let n=b(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setBigUint64(0,e,r),this.write(n,t)}getFloat32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,e)}setFloat32(t,e,r){let n=b(4);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat32(0,e,r),this.write(n,t)}getFloat64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,e)}setFloat64(t,e,r){let n=b(8);new DataView(n.buffer,n.byteOffset,n.byteLength).setFloat64(0,e,r),this.write(n,t)}equals(t){if(t==null||!(t instanceof s)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!M(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let r=new s;return r.bufs=t,e==null&&(e=t.reduce((n,o)=>n+o.byteLength,0)),r.length=e,r}};var D=class s extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,s)}},X=s=>"reason"in s?s.reason:new DOMException("This operation was aborted.","AbortError"),Y=2**31-1,Z=(s,t)=>{if(typeof s!="number"||Math.sign(s)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${s}\``);if(typeof t?.setTimeout!="function"||typeof t?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function S(s,t){let{milliseconds:e,fallback:r,message:n,customTimers:o={setTimeout,clearTimeout},signal:i}=t,a,c,h=()=>{try{s.cancel?.()}catch{}},u=new Promise((l,f)=>{let g=()=>{f(X(i)),h()},p=Z(e,o);try{p?f(p):i?.aborted?g():i&&(c=g,i.addEventListener("abort",c,{once:!0}))}finally{s.then(l,f)}if(p||i?.aborted||e>Y)return;let T=r||n===!1||n instanceof Error?void 0:new D(n??`Promise timed out after ${e} milliseconds`);a=o.setTimeout.call(void 0,()=>{if(r)try{l(r())}catch(U){f(U)}else n===!1?l():f(n instanceof Error?n:T);h()},e)}).finally(()=>{try{u.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return u.clear=()=>{a!==void 0&&(o.clearTimeout.call(void 0,a),a=void 0)},u}var F=s=>typeof s=="function"?{filter:s}:{...s},_=s=>s===1/0||Number.isSafeInteger(s)&&s>=0,tt=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],et=s=>{for(let[t,e]of tt){let r=s?.[t],n=s?.[e];if(typeof r=="function"&&typeof n=="function")return{addListener:r.bind(s),removeListener:n.bind(s)}}throw new TypeError("Emitter is not compatible")},rt=s=>{let t=new Map;for(let[e,r]of s)for(let n of Array.isArray(e)?e:[e])t.has(n)||t.set(n,r);return t},nt=({addListener:s,removeListener:t,handlers:e,signal:r,abortHandler:n,isDone:o})=>{r?.addEventListener("abort",n,{once:!0});for(let[i,a]of e)if(s(i,a),o()){t(i,a);return}},st=({removeListener:s,handlers:t,signal:e,abortHandler:r})=>{for(let[n,o]of t)s(n,o);e?.removeEventListener("abort",r)},ot=(s,t,e)=>{let r=Promise.resolve();return(n,o)=>{r=r.then(async()=>{if(t())return;let i;try{i=s?await s(n):!0}catch(a){t()||e(a);return}t()||o(i)})}};function it(s,t,e){let r=()=>{},n=!1,o,i=new Promise((a,c)=>{e=F(e);let{filter:h}=e;if(!_(e.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof e.timeout=="number"&&!(e.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${e.timeout}\``);e.signal?.throwIfAborted();let{addListener:m,removeListener:u}=et(s);if(e.count===0){a([]);return}let l=[],f=d=>{r(),c(d)},g=ot(h,()=>n,f),p=d=>{l.push(d),e.count===l.length&&(r(),a(l))},T=(...d)=>{if(n)return;let A=e.multiArgs?d:d[0];if(!h){p(A);return}g(A,$=>{$&&p(A)})},U=(...d)=>{f(e.rejectionMultiArgs?d:d[0])},H=()=>{f(e.signal.reason)},V={addListener:m,removeListener:u,handlers:rt([[t,T],[e.rejectionEvents??["error"],U]]),signal:e.signal,abortHandler:H,isDone:()=>n};r=()=>{n=!0,clearTimeout(o),st(V)},nt(V),!(n||!e.resolveImmediately)&&(Number.isFinite(e.timeout)&&e.timeout<=2**31-1&&(o=setTimeout(r,e.timeout)),a(l))});if(i.cancel=r,typeof e.timeout=="number"&&e.timeout>0&&!e.resolveImmediately){let a=S(i,{milliseconds:e.timeout});return a.cancel=()=>{r(),a.clear()},a}return i}function R(s,t,e){let r=it(s,t,{...F(e),count:1,resolveImmediately:!1}),n=r.then(o=>o[0]);return n.cancel=r.cancel,n}var v=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var k="1.0.0",j="echo";var I=class{protocol;components;started;init;timeout;constructor(t,e={}){this.started=!1,this.components=t,this.protocol=`/${[e.protocolPrefix,j,k].filter(Boolean).join("/")}`,this.init=e,this.timeout=e.timeout??2e4}[Symbol.toStringTag]="@libp2p/echo";async start(){await this.components.registrar.handle(this.protocol,this.onEcho.bind(this),{maxInboundStreams:this.init.maxInboundStreams,maxOutboundStreams:this.init.maxOutboundStreams,runOnLimitedConnection:this.init.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async onEcho(t){let e=t.log.newScope("echo"),r=Date.now(),n=AbortSignal.timeout(this.timeout);let o=0;n.addEventListener("abort",()=>{t.abort(new E)});for await(let i of t){if(o+=i.byteLength,t.status!=="open"){e("stream status changed to %s",t.status);break}t.send(i)?e("sent %d bytes",o):(e("sent %d bytes, wait for drain",o),await R(t,"drain",{rejectionEvents:["close"],signal:n}))}e("echoed %d bytes in %dms",o,Date.now()-r),await t.close({signal:n})}async echo(t,e,r){let n=await this.components.connectionManager.openStream(t,this.protocol,{...this.init,...r}),o=n.log.newScope("echo"),i=new L,a=Promise.withResolvers();return n.addEventListener("message",c=>{i.append(c.data),o("received %d/%d bytes",i.byteLength,e.byteLength)}),n.addEventListener("close",c=>{c.error!=null&&a.reject(c.error),i.byteLength>e.byteLength&&a.reject(new w(`Overread: ${i.byteLength}/${e.byteLength} bytes`)),i.byteLength<e.byteLength&&a.reject(new v(`Underread: ${i.byteLength}/${e.byteLength} bytes`)),a.resolve(i)}),o("sending %d bytes",e.byteLength),n.send(e),await n.close(r).catch(c=>{a.reject(c)}),a.promise}};function at(s={}){return t=>new I(t,s)}return G(ct);})();
|
|
3
3
|
return Libp2PEcho}));
|
|
4
4
|
//# sourceMappingURL=index.min.js.map
|
package/dist/index.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../../interface/src/errors.ts", "../../../node_modules/uint8arrays/src/alloc.ts", "../../../node_modules/uint8arrays/src/util/as-uint8array.ts", "../../../node_modules/uint8arrays/src/concat.ts", "../../../node_modules/uint8arrays/src/equals.ts", "../../../node_modules/uint8arraylist/src/index.ts", "../../../node_modules/p-timeout/index.js", "../../../node_modules/p-event/index.js", "../../utils/src/errors.ts", "../src/constants.ts", "../src/echo.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @packageDocumentation\n *\n * An implementation of a simple Echo protocol.\n *\n * Any data received by the receiver will be sent back to the sender.\n *\n * @example\n *\n * ```TypeScript\n * import { noise } from '@libp2p/noise'\n * import { yamux } from '@libp2p/yamux'\n * import { echo } from '@libp2p/echo'\n * import { peerIdFromString } from '@libp2p/peer-id'\n * import { createLibp2p } from 'libp2p'\n *\n * const receiver = await createLibp2p({\n * addresses: {\n * listen: ['/ip4/0.0.0.0/tcp/0']\n * },\n * connectionEncrypters: [noise()],\n * streamMuxers: [yamux()],\n * services: {\n * echo: echo()\n * }\n * })\n *\n * const sender = await createLibp2p({\n * addresses: {\n * listen: ['/ip4/0.0.0.0/tcp/0']\n * },\n * connectionEncrypters: [noise()],\n * streamMuxers: [yamux()],\n * services: {\n * echo: echo()\n * }\n * })\n *\n * const stream = await sender.dialProtocol(receiver.getMultiaddrs(), sender.services.echo.protocol)\n *\n * // write/read stream\n * ```\n */\n\nimport { Echo as EchoClass } from './echo.ts'\nimport type { DialProtocolOptions, DialTarget } from '@libp2p/interface'\nimport type { ConnectionManager, Registrar } from '@libp2p/interface-internal'\nimport type { Uint8ArrayList } from 'uint8arraylist'\n\nexport interface EchoInit {\n protocolPrefix?: string\n maxInboundStreams?: number\n maxOutboundStreams?: number\n runOnLimitedConnection?: boolean\n timeout?: number\n}\n\nexport interface EchoComponents {\n registrar: Registrar\n connectionManager: ConnectionManager\n}\n\nexport interface Echo {\n protocol: string\n echo(peer: DialTarget, buf: Uint8Array | Uint8ArrayList, options?: DialProtocolOptions): Promise<Uint8ArrayList>\n}\n\nexport function echo (init: EchoInit = {}): (components: EchoComponents) => Echo {\n return (components) => new EchoClass(components, init)\n}\n", "/**\n * When this error is thrown it means an operation was aborted,\n * usually in response to the `abort` event being emitted by an\n * AbortSignal.\n */\nexport class AbortError extends Error {\n static name = 'AbortError'\n\n constructor (message: string = 'The operation was aborted') {\n super(message)\n this.name = 'AbortError'\n }\n}\n\n/**\n * Thrown when a remote Peer ID does not match the expected one\n */\nexport class UnexpectedPeerError extends Error {\n static name = 'UnexpectedPeerError'\n\n constructor (message = 'Unexpected Peer') {\n super(message)\n this.name = 'UnexpectedPeerError'\n }\n}\n\n/**\n * Thrown when a crypto exchange fails\n */\nexport class InvalidCryptoExchangeError extends Error {\n static name = 'InvalidCryptoExchangeError'\n\n constructor (message = 'Invalid crypto exchange') {\n super(message)\n this.name = 'InvalidCryptoExchangeError'\n }\n}\n\n/**\n * Thrown when invalid parameters are passed to a function or method call\n */\nexport class InvalidParametersError extends Error {\n static name = 'InvalidParametersError'\n\n constructor (message = 'Invalid parameters') {\n super(message)\n this.name = 'InvalidParametersError'\n }\n}\n\n/**\n * Thrown when a public key is invalid\n */\nexport class InvalidPublicKeyError extends Error {\n static name = 'InvalidPublicKeyError'\n\n constructor (message = 'Invalid public key') {\n super(message)\n this.name = 'InvalidPublicKeyError'\n }\n}\n\n/**\n * Thrown when a private key is invalid\n */\nexport class InvalidPrivateKeyError extends Error {\n static name = 'InvalidPrivateKeyError'\n\n constructor (message = 'Invalid private key') {\n super(message)\n this.name = 'InvalidPrivateKeyError'\n }\n}\n\n/**\n * Thrown when a operation is unsupported\n */\nexport class UnsupportedOperationError extends Error {\n static name = 'UnsupportedOperationError'\n\n constructor (message = 'Unsupported operation') {\n super(message)\n this.name = 'UnsupportedOperationError'\n }\n}\n\n/**\n * Thrown when a connection is closing\n */\nexport class ConnectionClosingError extends Error {\n static name = 'ConnectionClosingError'\n\n constructor (message = 'The connection is closing') {\n super(message)\n this.name = 'ConnectionClosingError'\n }\n}\n\n/**\n * Thrown when a connection is closed\n */\nexport class ConnectionClosedError extends Error {\n static name = 'ConnectionClosedError'\n\n constructor (message = 'The connection is closed') {\n super(message)\n this.name = 'ConnectionClosedError'\n }\n}\n\n/**\n * Thrown when a connection fails\n */\nexport class ConnectionFailedError extends Error {\n static name = 'ConnectionFailedError'\n\n constructor (message = 'Connection failed') {\n super(message)\n this.name = 'ConnectionFailedError'\n }\n}\n\n/**\n * Thrown when the muxer is closed and an attempt to open a stream occurs\n */\nexport class MuxerClosedError extends Error {\n static name = 'MuxerClosedError'\n\n constructor (message = 'The muxer is closed') {\n super(message)\n this.name = 'MuxerClosedError'\n }\n}\n\n/**\n * Thrown when a protocol stream is reset by the remote muxer\n */\nexport class StreamResetError extends Error {\n static name = 'StreamResetError'\n\n constructor (message = 'The stream has been reset') {\n super(message)\n this.name = 'StreamResetError'\n }\n}\n\n/**\n * Thrown when a protocol stream is aborted locally\n */\nexport class StreamAbortedError extends Error {\n static name = 'StreamAbortedError'\n\n constructor (message = 'The stream has been aborted') {\n super(message)\n this.name = 'StreamAbortedError'\n }\n}\n\n/**\n * Thrown when a stream is in an invalid state\n */\nexport class StreamStateError extends Error {\n static name = 'StreamStateError'\n\n constructor (message = 'The stream is in an invalid state') {\n super(message)\n this.name = 'StreamStateError'\n }\n}\n\n/**\n * Thrown when a stream buffer is full\n */\nexport class StreamBufferError extends Error {\n static name = 'StreamBufferError'\n\n constructor (message = 'The stream buffer was full') {\n super(message)\n this.name = 'StreamBufferError'\n }\n}\n\n/**\n * Thrown when a value could not be found\n */\nexport class NotFoundError extends Error {\n static name = 'NotFoundError'\n\n constructor (message = 'Not found') {\n super(message)\n this.name = 'NotFoundError'\n }\n}\n\n/**\n * Thrown when an invalid peer ID is encountered\n */\nexport class InvalidPeerIdError extends Error {\n static name = 'InvalidPeerIdError'\n\n constructor (message = 'Invalid PeerID') {\n super(message)\n this.name = 'InvalidPeerIdError'\n }\n}\n\n/**\n * Thrown when an invalid multiaddr is encountered\n */\nexport class InvalidMultiaddrError extends Error {\n static name = 'InvalidMultiaddrError'\n\n constructor (message = 'Invalid multiaddr') {\n super(message)\n this.name = 'InvalidMultiaddrError'\n }\n}\n\n/**\n * Thrown when an invalid CID is encountered\n */\nexport class InvalidCIDError extends Error {\n static name = 'InvalidCIDError'\n\n constructor (message = 'Invalid CID') {\n super(message)\n this.name = 'InvalidCIDError'\n }\n}\n\n/**\n * Thrown when an invalid multihash is encountered\n */\nexport class InvalidMultihashError extends Error {\n static name = 'InvalidMultihashError'\n\n constructor (message = 'Invalid Multihash') {\n super(message)\n this.name = 'InvalidMultihashError'\n }\n}\n\n/**\n * Thrown when a protocol is not supported\n */\nexport class UnsupportedProtocolError extends Error {\n static name = 'UnsupportedProtocolError'\n\n constructor (message = 'Unsupported protocol error') {\n super(message)\n this.name = 'UnsupportedProtocolError'\n }\n}\n\n/**\n * An invalid or malformed message was encountered during a protocol exchange\n */\nexport class InvalidMessageError extends Error {\n static name = 'InvalidMessageError'\n\n constructor (message = 'Invalid message') {\n super(message)\n this.name = 'InvalidMessageError'\n }\n}\n\n/**\n * Thrown when a remote peer sends a structurally valid message that does not\n * comply with the protocol\n */\nexport class ProtocolError extends Error {\n static name = 'ProtocolError'\n\n constructor (message = 'Protocol error') {\n super(message)\n this.name = 'ProtocolError'\n }\n}\n\n/**\n * Throw when an operation times out\n */\nexport class TimeoutError extends Error {\n static name = 'TimeoutError'\n\n constructor (message = 'Timed out') {\n super(message)\n this.name = 'TimeoutError'\n }\n}\n\n/**\n * Thrown when a startable component is interacted with but it has not been\n * started yet\n */\nexport class NotStartedError extends Error {\n static name = 'NotStartedError'\n\n constructor (message = 'Not started') {\n super(message)\n this.name = 'NotStartedError'\n }\n}\n\n/**\n * Thrown when a component is started that has already been started\n */\nexport class AlreadyStartedError extends Error {\n static name = 'AlreadyStartedError'\n\n constructor (message = 'Already started') {\n super(message)\n this.name = 'AlreadyStartedError'\n }\n}\n\n/**\n * Thrown when dialing an address failed\n */\nexport class DialError extends Error {\n static name = 'DialError'\n\n constructor (message = 'Dial error') {\n super(message)\n this.name = 'DialError'\n }\n}\n\n/**\n * Thrown when listening on an address failed\n */\nexport class ListenError extends Error {\n static name = 'ListenError'\n\n constructor (message = 'Listen error') {\n super(message)\n this.name = 'ListenError'\n }\n}\n\n/**\n * This error is thrown when a limited connection is encountered, i.e. if the\n * user tried to open a stream on a connection for a protocol that is not\n * configured to run over limited connections.\n */\nexport class LimitedConnectionError extends Error {\n static name = 'LimitedConnectionError'\n\n constructor (message = 'Limited connection') {\n super(message)\n this.name = 'LimitedConnectionError'\n }\n}\n\n/**\n * This error is thrown where there are too many inbound protocols streams open\n */\nexport class TooManyInboundProtocolStreamsError extends Error {\n static name = 'TooManyInboundProtocolStreamsError'\n\n constructor (message = 'Too many inbound protocol streams') {\n super(message)\n this.name = 'TooManyInboundProtocolStreamsError'\n }\n}\n\n/**\n * This error is thrown where there are too many outbound protocols streams open\n */\nexport class TooManyOutboundProtocolStreamsError extends Error {\n static name = 'TooManyOutboundProtocolStreamsError'\n\n constructor (message = 'Too many outbound protocol streams') {\n super(message)\n this.name = 'TooManyOutboundProtocolStreamsError'\n }\n}\n\n/**\n * Thrown when an attempt to operate on an unsupported key was made\n */\nexport class UnsupportedKeyTypeError extends Error {\n static name = 'UnsupportedKeyTypeError'\n\n constructor (message = 'Unsupported key type') {\n super(message)\n this.name = 'UnsupportedKeyTypeError'\n }\n}\n\n/**\n * Thrown when an operation has not been implemented\n */\nexport class NotImplementedError extends Error {\n static name = 'NotImplementedError'\n\n constructor (message = 'Not implemented') {\n super(message)\n this.name = 'NotImplementedError'\n }\n}\n", "/**\n * Returns a `Uint8Array` of the requested size. Referenced memory will\n * be initialized to 0.\n */\nexport function alloc (size: number = 0): Uint8Array<ArrayBuffer> {\n return new Uint8Array(size)\n}\n\n/**\n * Where possible returns a Uint8Array of the requested size that references\n * uninitialized memory. Only use if you are certain you will immediately\n * overwrite every value in the returned `Uint8Array`.\n */\nexport function allocUnsafe (size: number = 0): Uint8Array<ArrayBuffer> {\n return new Uint8Array(size)\n}\n", "function isByteArrayWithArrayBuffer (b?: Uint8Array): b is Uint8Array<ArrayBuffer> {\n return b?.buffer instanceof ArrayBuffer\n}\n\n/**\n * To guarantee Uint8Array semantics, convert nodejs Buffers\n * into vanilla Uint8Arrays\n */\nexport function asUint8Array (buf: Uint8Array): Uint8Array<ArrayBuffer> {\n if (isByteArrayWithArrayBuffer(buf)) {\n return buf\n }\n\n const b = buf.slice()\n\n return new Uint8Array(b.buffer, 0, b.byteLength)\n}\n", "import { allocUnsafe } from '#alloc'\nimport { asUint8Array } from '#util/as-uint8array'\n\n/**\n * Returns a new Uint8Array created by concatenating the passed Uint8Arrays\n */\nexport function concat (arrays: Uint8Array[], length?: number): Uint8Array<ArrayBuffer> {\n if (length == null) {\n length = arrays.reduce((acc, curr) => acc + curr.length, 0)\n }\n\n const output = allocUnsafe(length)\n let offset = 0\n\n for (const arr of arrays) {\n output.set(arr, offset)\n offset += arr.length\n }\n\n return asUint8Array(output)\n}\n", "/**\n * Returns true if the two passed Uint8Arrays have the same content\n */\nexport function equals (a: Uint8Array, b: Uint8Array): boolean {\n if (a === b) {\n return true\n }\n\n if (a.byteLength !== b.byteLength) {\n return false\n }\n\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n\n return true\n}\n", "/**\n * @packageDocumentation\n *\n * A class that lets you do operations over a list of Uint8Arrays without\n * copying them.\n *\n * ```js\n * import { Uint8ArrayList } from 'uint8arraylist'\n *\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.subarray()\n * // -> Uint8Array([0, 1, 2, 3, 4, 5])\n *\n * list.consume(3)\n * list.subarray()\n * // -> Uint8Array([3, 4, 5])\n *\n * // you can also iterate over the list\n * for (const buf of list) {\n * // ..do something with `buf`\n * }\n *\n * list.subarray(0, 1)\n * // -> Uint8Array([0])\n * ```\n *\n * ## Converting Uint8ArrayLists to Uint8Arrays\n *\n * There are two ways to turn a `Uint8ArrayList` into a `Uint8Array` - `.slice` and `.subarray` and one way to turn a `Uint8ArrayList` into a `Uint8ArrayList` with different contents - `.sublist`.\n *\n * ### slice\n *\n * Slice follows the same semantics as [Uint8Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice) in that it creates a new `Uint8Array` and copies bytes into it using an optional offset & length.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.slice(0, 1)\n * // -> Uint8Array([0])\n * ```\n *\n * ### subarray\n *\n * Subarray attempts to follow the same semantics as [Uint8Array.subarray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) with one important different - this is a no-copy operation, unless the requested bytes span two internal buffers in which case it is a copy operation.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.subarray(0, 1)\n * // -> Uint8Array([0]) - no-copy\n *\n * list.subarray(2, 5)\n * // -> Uint8Array([2, 3, 4]) - copy\n * ```\n *\n * ### sublist\n *\n * Sublist creates and returns a new `Uint8ArrayList` that shares the underlying buffers with the original so is always a no-copy operation.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.sublist(0, 1)\n * // -> Uint8ArrayList([0]) - no-copy\n *\n * list.sublist(2, 5)\n * // -> Uint8ArrayList([2], [3, 4]) - no-copy\n * ```\n *\n * ## Inspiration\n *\n * Borrows liberally from [bl](https://www.npmjs.com/package/bl) but only uses native JS types.\n */\nimport { allocUnsafe, alloc } from 'uint8arrays/alloc'\nimport { concat } from 'uint8arrays/concat'\nimport { equals } from 'uint8arrays/equals'\n\nconst symbol = Symbol.for('@achingbrain/uint8arraylist')\n\nexport type Appendable<T extends ArrayBufferLike = ArrayBuffer> = Uint8ArrayList<T> | Uint8Array<T>\n\nfunction findBufAndOffset (bufs: Uint8Array[], index: number): { buf: Uint8Array, index: number } {\n if (index == null || index < 0) {\n throw new RangeError('index is out of bounds')\n }\n\n let offset = 0\n\n for (const buf of bufs) {\n const bufEnd = offset + buf.byteLength\n\n if (index < bufEnd) {\n return {\n buf,\n index: index - offset\n }\n }\n\n offset = bufEnd\n }\n\n throw new RangeError('index is out of bounds')\n}\n\n/**\n * Check if object is a CID instance\n *\n * @example\n *\n * ```js\n * import { isUint8ArrayList, Uint8ArrayList } from 'uint8arraylist'\n *\n * isUint8ArrayList(true) // false\n * isUint8ArrayList([]) // false\n * isUint8ArrayList(new Uint8ArrayList()) // true\n * ```\n */\nexport function isUint8ArrayList (value: any): value is Uint8ArrayList {\n return Boolean(value?.[symbol])\n}\n\nexport class Uint8ArrayList <T extends ArrayBufferLike = ArrayBufferLike> implements Iterable<Uint8Array<T>> {\n private bufs: Uint8Array<T>[]\n public length: number\n public readonly [symbol] = true\n\n constructor (...data: Appendable<T>[]) {\n this.bufs = []\n this.length = 0\n\n if (data.length > 0) {\n this.appendAll(data)\n }\n }\n\n * [Symbol.iterator] (): Iterator<Uint8Array<T>> {\n yield * this.bufs\n }\n\n get byteLength (): number {\n return this.length\n }\n\n /**\n * Add one or more `bufs` to the end of this Uint8ArrayList\n */\n append (...bufs: Appendable<T>[]): void {\n this.appendAll(bufs)\n }\n\n /**\n * Add all `bufs` to the end of this Uint8ArrayList\n */\n appendAll (bufs: Appendable<T>[]): void {\n let length = 0\n\n for (const buf of bufs) {\n if (buf instanceof Uint8Array) {\n length += buf.byteLength\n this.bufs.push(buf)\n } else if (isUint8ArrayList(buf)) {\n length += buf.byteLength\n for (const chunk of buf.bufs) {\n this.bufs.push(chunk)\n }\n } else {\n throw new Error('Could not append value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n this.length += length\n }\n\n /**\n * Add one or more `bufs` to the start of this Uint8ArrayList\n */\n prepend (...bufs: Appendable<T>[]): void {\n this.prependAll(bufs)\n }\n\n /**\n * Add all `bufs` to the start of this Uint8ArrayList\n */\n prependAll (bufs: Appendable<T>[]): void {\n let length = 0\n\n for (const buf of bufs.reverse()) {\n if (buf instanceof Uint8Array) {\n length += buf.byteLength\n this.bufs.unshift(buf)\n } else if (isUint8ArrayList(buf)) {\n length += buf.byteLength\n this.bufs.unshift(...buf.bufs)\n } else {\n throw new Error('Could not prepend value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n this.length += length\n }\n\n /**\n * Read the value at `index`\n */\n get (index: number): number {\n const res = findBufAndOffset(this.bufs, index)\n\n return res.buf[res.index]\n }\n\n /**\n * Set the value at `index` to `value`\n */\n set (index: number, value: number): void {\n const res = findBufAndOffset(this.bufs, index)\n\n res.buf[res.index] = value\n }\n\n /**\n * Copy bytes from `buf` to the index specified by `offset`\n */\n write (buf: Appendable<T | ArrayBuffer>, offset: number = 0): void {\n if (buf instanceof Uint8Array) {\n for (let i = 0; i < buf.length; i++) {\n this.set(offset + i, buf[i])\n }\n } else if (isUint8ArrayList(buf)) {\n for (let i = 0; i < buf.length; i++) {\n this.set(offset + i, buf.get(i))\n }\n } else {\n throw new Error('Could not write value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n /**\n * Remove bytes from the front of the pool\n */\n consume (bytes: number): void {\n // first, normalize the argument, in accordance with how Buffer does it\n bytes = Math.trunc(bytes)\n\n // do nothing if not a positive number\n if (Number.isNaN(bytes) || bytes <= 0) {\n return\n }\n\n // if consuming all bytes, skip iterating\n if (bytes === this.byteLength) {\n this.bufs = []\n this.length = 0\n return\n }\n\n while (this.bufs.length > 0) {\n if (bytes >= this.bufs[0].byteLength) {\n bytes -= this.bufs[0].byteLength\n this.length -= this.bufs[0].byteLength\n this.bufs.shift()\n } else {\n this.bufs[0] = this.bufs[0].subarray(bytes)\n this.length -= bytes\n break\n }\n }\n }\n\n /**\n * Extracts a section of an array and returns a new array.\n *\n * This is a copy operation as it is with Uint8Arrays and Arrays\n * - note this is different to the behaviour of Node Buffers.\n */\n slice (beginInclusive?: number, endExclusive?: number): Uint8Array<ArrayBuffer> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n return concat(bufs, length)\n }\n\n /**\n * Returns a section of the array from the given start and end element index.\n *\n * This is a no-copy operation where the data extracted data comes from a\n * single Uint8Array internally, otherwise it is a copy operation.\n */\n subarray (beginInclusive?: number, endExclusive?: number): Uint8Array<T | ArrayBuffer> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n if (bufs.length === 1) {\n return bufs[0]\n }\n\n return concat(bufs, length)\n }\n\n /**\n * Returns a new Uint8ArrayList from the given start and end element index.\n *\n * This is a no-copy operation.\n */\n sublist (beginInclusive?: number, endExclusive?: number): Uint8ArrayList<T> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n const list = new Uint8ArrayList<T>()\n list.length = length\n // don't loop, just set the bufs\n list.bufs = bufs\n\n return list\n }\n\n private _subList (beginInclusive?: number, endExclusive?: number): { bufs: Uint8Array<T>[], length: number } {\n beginInclusive = beginInclusive ?? 0\n endExclusive = endExclusive ?? this.length\n\n if (beginInclusive < 0) {\n beginInclusive = this.length + beginInclusive\n }\n\n if (endExclusive < 0) {\n endExclusive = this.length + endExclusive\n }\n\n if (beginInclusive < 0 || endExclusive > this.length) {\n throw new RangeError('index is out of bounds')\n }\n\n if (beginInclusive === endExclusive) {\n return { bufs: [], length: 0 }\n }\n\n if (beginInclusive === 0 && endExclusive === this.length) {\n return { bufs: [...this.bufs], length: this.length }\n }\n\n const bufs: Uint8Array<T>[] = []\n let offset = 0\n\n for (let i = 0; i < this.bufs.length; i++) {\n const buf = this.bufs[i]\n const bufStart = offset\n const bufEnd = bufStart + buf.byteLength\n\n // for next loop\n offset = bufEnd\n\n if (beginInclusive >= bufEnd) {\n // start after this buf\n continue\n }\n\n const sliceStartInBuf = beginInclusive >= bufStart && beginInclusive < bufEnd\n const sliceEndsInBuf = endExclusive > bufStart && endExclusive <= bufEnd\n\n if (sliceStartInBuf && sliceEndsInBuf) {\n // slice is wholly contained within this buffer\n if (beginInclusive === bufStart && endExclusive === bufEnd) {\n // requested whole buffer\n bufs.push(buf)\n break\n }\n\n // requested part of buffer\n const start = beginInclusive - bufStart\n bufs.push(buf.subarray(start, start + (endExclusive - beginInclusive)))\n break\n }\n\n if (sliceStartInBuf) {\n // slice starts in this buffer\n if (beginInclusive === 0) {\n // requested whole buffer\n bufs.push(buf)\n continue\n }\n\n // requested part of buffer\n bufs.push(buf.subarray(beginInclusive - bufStart))\n continue\n }\n\n if (sliceEndsInBuf) {\n if (endExclusive === bufEnd) {\n // requested whole buffer\n bufs.push(buf)\n break\n }\n\n // requested part of buffer\n bufs.push(buf.subarray(0, endExclusive - bufStart))\n break\n }\n\n // slice started before this buffer and ends after it\n bufs.push(buf)\n }\n\n return { bufs, length: endExclusive - beginInclusive }\n }\n\n indexOf (search: Uint8ArrayList | Uint8Array, offset: number = 0): number {\n if (!isUint8ArrayList(search) && !(search instanceof Uint8Array)) {\n throw new TypeError('The \"value\" argument must be a Uint8ArrayList or Uint8Array')\n }\n\n const needle = search instanceof Uint8Array ? search : search.subarray()\n\n offset = Number(offset ?? 0)\n\n if (isNaN(offset)) {\n offset = 0\n }\n\n if (offset < 0) {\n offset = this.length + offset\n }\n\n if (offset < 0) {\n offset = 0\n }\n\n if (search.length === 0) {\n return offset > this.length ? this.length : offset\n }\n\n // https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm\n const M: number = needle.byteLength\n\n if (M === 0) {\n throw new TypeError('search must be at least 1 byte long')\n }\n\n // radix\n const radix: number = 256\n const rightmostPositions: Int32Array = new Int32Array(radix)\n\n // position of the rightmost occurrence of the byte c in the pattern\n for (let c: number = 0; c < radix; c++) {\n // -1 for bytes not in pattern\n rightmostPositions[c] = -1\n }\n\n for (let j = 0; j < M; j++) {\n // rightmost position for bytes in pattern\n rightmostPositions[needle[j]] = j\n }\n\n // Return offset of first match, -1 if no match\n const right = rightmostPositions\n const lastIndex = this.byteLength - needle.byteLength\n const lastPatIndex = needle.byteLength - 1\n let skip: number\n\n for (let i = offset; i <= lastIndex; i += skip) {\n skip = 0\n\n for (let j = lastPatIndex; j >= 0; j--) {\n const char: number = this.get(i + j)\n\n if (needle[j] !== char) {\n skip = Math.max(1, j - right[char])\n break\n }\n }\n\n if (skip === 0) {\n return i\n }\n }\n\n return -1\n }\n\n getInt8 (byteOffset: number): number {\n const buf = this.subarray(byteOffset, byteOffset + 1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt8(0)\n }\n\n setInt8 (byteOffset: number, value: number): void {\n const buf = allocUnsafe(1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt8(0, value)\n\n this.write(buf, byteOffset)\n }\n\n getInt16 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt16(0, littleEndian)\n }\n\n setInt16 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt16(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getInt32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt32(0, littleEndian)\n }\n\n setInt32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getBigInt64 (byteOffset: number, littleEndian?: boolean): bigint {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getBigInt64(0, littleEndian)\n }\n\n setBigInt64 (byteOffset: number, value: bigint, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setBigInt64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getUint8 (byteOffset: number): number {\n const buf = this.subarray(byteOffset, byteOffset + 1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint8(0)\n }\n\n setUint8 (byteOffset: number, value: number): void {\n const buf = allocUnsafe(1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint8(0, value)\n\n this.write(buf, byteOffset)\n }\n\n getUint16 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint16(0, littleEndian)\n }\n\n setUint16 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint16(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getUint32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint32(0, littleEndian)\n }\n\n setUint32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getBigUint64 (byteOffset: number, littleEndian?: boolean): bigint {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getBigUint64(0, littleEndian)\n }\n\n setBigUint64 (byteOffset: number, value: bigint, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setBigUint64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getFloat32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getFloat32(0, littleEndian)\n }\n\n setFloat32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setFloat32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getFloat64 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getFloat64(0, littleEndian)\n }\n\n setFloat64 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setFloat64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n equals (other: any): other is Uint8ArrayList {\n if (other == null) {\n return false\n }\n\n if (!(other instanceof Uint8ArrayList)) {\n return false\n }\n\n if (other.bufs.length !== this.bufs.length) {\n return false\n }\n\n for (let i = 0; i < this.bufs.length; i++) {\n if (!equals(this.bufs[i], other.bufs[i])) {\n return false\n }\n }\n\n return true\n }\n\n /**\n * Create a Uint8ArrayList from a pre-existing list of Uint8Arrays. Use this\n * method if you know the total size of all the Uint8Arrays ahead of time.\n */\n static fromUint8Arrays <T extends ArrayBufferLike> (bufs: Uint8Array<T>[], length?: number): Uint8ArrayList<T> {\n const list = new Uint8ArrayList<T>()\n list.bufs = bufs\n\n if (length == null) {\n length = bufs.reduce((acc, curr) => acc + curr.byteLength, 0)\n }\n\n list.length = length\n\n return list\n }\n}\n\n/*\nfunction indexOf (needle: Uint8Array, haystack: Uint8Array, offset = 0) {\n for (let i = offset; i < haystack.byteLength; i++) {\n for (let j = 0; j < needle.length; j++) {\n if (haystack[i + j] !== needle[j]) {\n break\n }\n\n if (j === needle.byteLength -1) {\n return i\n }\n }\n\n if (haystack.byteLength - i < needle.byteLength) {\n break\n }\n }\n\n return -1\n}\n*/\n", "export class TimeoutError extends Error {\n\tname = 'TimeoutError';\n\n\tconstructor(message, options) {\n\t\tsuper(message, options);\n\t\tError.captureStackTrace?.(this, TimeoutError);\n\t}\n}\n\nconst getAbortedReason = signal => signal.reason ?? new DOMException('This operation was aborted.', 'AbortError');\n\nexport default function pTimeout(promise, options) {\n\tconst {\n\t\tmilliseconds,\n\t\tfallback,\n\t\tmessage,\n\t\tcustomTimers = {setTimeout, clearTimeout},\n\t\tsignal,\n\t} = options;\n\n\tlet timer;\n\tlet abortHandler;\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tif (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {\n\t\t\tthrow new TypeError(`Expected \\`milliseconds\\` to be a positive number, got \\`${milliseconds}\\``);\n\t\t}\n\n\t\tif (signal?.aborted) {\n\t\t\treject(getAbortedReason(signal));\n\t\t\t// The input still needs a rejection handler even though cancellation won.\n\t\t\t// eslint-disable-next-line promise/prefer-await-to-then, promise/prefer-catch\n\t\t\tpromise.then(resolve, reject);\n\t\t\treturn;\n\t\t}\n\n\t\tif (signal) {\n\t\t\tabortHandler = () => {\n\t\t\t\treject(getAbortedReason(signal));\n\t\t\t};\n\n\t\t\tsignal.addEventListener('abort', abortHandler, {once: true});\n\t\t}\n\n\t\t// Use .then() instead of async IIFE to preserve stack traces\n\t\t// eslint-disable-next-line promise/prefer-await-to-then, promise/prefer-catch\n\t\tpromise.then(resolve, reject);\n\n\t\tif (milliseconds === Number.POSITIVE_INFINITY) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We create the error outside of `setTimeout` to preserve the stack trace.\n\t\tconst timeoutError = new TimeoutError();\n\n\t\t// `.call(undefined, ...)` is needed for custom timers to avoid context issues\n\t\ttimer = customTimers.setTimeout.call(undefined, () => {\n\t\t\tif (fallback) {\n\t\t\t\ttry {\n\t\t\t\t\tresolve(fallback());\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (typeof promise.cancel === 'function') {\n\t\t\t\tpromise.cancel();\n\t\t\t}\n\n\t\t\tif (message === false) {\n\t\t\t\tresolve();\n\t\t\t} else if (message instanceof Error) {\n\t\t\t\treject(message);\n\t\t\t} else {\n\t\t\t\ttimeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;\n\t\t\t\treject(timeoutError);\n\t\t\t}\n\t\t}, milliseconds);\n\t});\n\n\t// eslint-disable-next-line promise/prefer-await-to-then\n\tconst cancelablePromise = wrappedPromise.finally(() => {\n\t\tcancelablePromise.clear();\n\t\tif (abortHandler && signal) {\n\t\t\tsignal.removeEventListener('abort', abortHandler);\n\t\t}\n\t});\n\n\tcancelablePromise.clear = () => {\n\t\t// `.call(undefined, ...)` is needed for custom timers to avoid context issues\n\t\tcustomTimers.clearTimeout.call(undefined, timer);\n\t\ttimer = undefined;\n\t};\n\n\treturn cancelablePromise;\n}\n", "import pTimeout from 'p-timeout';\n\n// A filter function can stand in for the options. The options are copied, so a later change to the caller's object cannot reach the call.\nconst normalizeOptions = options => typeof options === 'function' ? {filter: options} : {...options};\n\n// A `count` or `limit`: a whole number of zero or more, or `Infinity`.\nconst isCount = value => value === Infinity || (Number.isSafeInteger(value) && value >= 0);\n\n// The removal method has to come from the same family as the one used to add, otherwise the listener is never detached.\nconst listenerMethodPairs = [\n\t['addEventListener', 'removeEventListener'],\n\t['on', 'off'],\n\t['addListener', 'removeListener'],\n];\n\nconst normalizeEmitter = emitter => {\n\tfor (const [addMethod, removeMethod] of listenerMethodPairs) {\n\t\tconst addListener = emitter?.[addMethod];\n\t\tconst removeListener = emitter?.[removeMethod];\n\n\t\tif (typeof addListener === 'function' && typeof removeListener === 'function') {\n\t\t\treturn {\n\t\t\t\taddListener: addListener.bind(emitter),\n\t\t\t\tremoveListener: removeListener.bind(emitter),\n\t\t\t};\n\t\t}\n\t}\n\n\tthrow new TypeError('Emitter is not compatible');\n};\n\n// Which handler serves each event name. A single name is a list of one. A name claimed by an earlier family keeps that handler, so the main event takes priority over `rejectionEvents`, which in turn takes priority over `resolutionEvents`. Registration and removal both walk the returned map, so they always agree, a repeated name gets one listener, and a later edit to the caller's arrays cannot reach them.\nconst listenerHandlers = families => {\n\tconst handlers = new Map();\n\n\tfor (const [names, handler] of families) {\n\t\tfor (const name of Array.isArray(names) ? names : [names]) {\n\t\t\tif (!handlers.has(name)) {\n\t\t\t\thandlers.set(name, handler);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn handlers;\n};\n\n// Attaches the abort handler first, so an emitter that fires the abort itself while a listener is being attached still reaches the caller. An emitter that hands over buffered events the moment a listener is attached can end the call part way through, and anything attached after that would never be removed, so attaching stops once the call is done. The call can also end before the emitter stores the listener, since Node's `EventEmitter` emits `newListener` first, so the cleanup misses that listener and it is removed here.\nconst attachListeners = ({addListener, removeListener, handlers, signal, abortHandler, isDone}) => {\n\tsignal?.addEventListener('abort', abortHandler, {once: true});\n\n\tfor (const [eventName, listener] of handlers) {\n\t\taddListener(eventName, listener);\n\n\t\tif (isDone()) {\n\t\t\tremoveListener(eventName, listener);\n\t\t\treturn;\n\t\t}\n\t}\n};\n\n// `once: true` only detaches the abort handler when the signal fires, so a call that ended another way has to remove it.\nconst detachListeners = ({removeListener, handlers, signal, abortHandler}) => {\n\tfor (const [eventName, listener] of handlers) {\n\t\tremoveListener(eventName, listener);\n\t}\n\n\tsignal?.removeEventListener('abort', abortHandler);\n};\n\n// Filters run one after another, so that an asynchronous one cannot reorder the values or read a `limit` that belongs to a later event. A verdict or a failure that arrives once the call is done is dropped, since the outcome is already decided and a cancelled promise must never settle.\nconst createFilterQueue = (filter, isDone, onError) => {\n\tlet queue = Promise.resolve();\n\n\treturn (value, onVerdict) => {\n\t\tqueue = queue.then(async () => {\n\t\t\t// The call is over, so the filter could only produce a verdict that is discarded.\n\t\t\tif (isDone()) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet isAccepted;\n\t\t\t// The filter's return value is a verdict rather than a rejection, so it is checked instead of caught.\n\t\t\ttry {\n\t\t\t\tisAccepted = filter ? await filter(value) : true;\n\t\t\t} catch (error) {\n\t\t\t\tif (!isDone()) {\n\t\t\t\t\tonError(error);\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDone()) {\n\t\t\t\tonVerdict(isAccepted);\n\t\t\t}\n\t\t});\n\t};\n};\n\nexport function pEventMultiple(emitter, event, options) {\n\t// The setup below can throw before `cancel` is assigned, and the returned promise documents a `.cancel()` method, so it starts out as a no-op.\n\tlet cancel = () => {};\n\t// Set by `cancel()`, which every path that stops listening runs, so an event still going through an asynchronous `filter` can tell that its result is no longer wanted.\n\tlet isDone = false;\n\tlet deadlineTimer;\n\tconst returnValue = new Promise((resolve, reject) => {\n\t\toptions = normalizeOptions(options);\n\n\t\t// Held in a local so the filter is called on its own, and `this` inside it is not the options object the library works from.\n\t\tconst {filter} = options;\n\n\t\tif (!isCount(options.count)) {\n\t\t\tthrow new TypeError('The `count` option should be at least 0 or more');\n\t\t}\n\n\t\t// Checked here, before anything is attached, because `p-timeout` throws for it before it subscribes to this promise, which would leave the listeners attached and this rejection unhandled.\n\t\tif (typeof options.timeout === 'number'\n\t\t\t&& !(options.timeout > 0)) {\n\t\t\tthrow new TypeError(`Expected the \\`timeout\\` option to be a positive number, got \\`${options.timeout}\\``);\n\t\t}\n\n\t\toptions.signal?.throwIfAborted();\n\n\t\tconst {addListener, removeListener} = normalizeEmitter(emitter);\n\n\t\t// A count of zero is already satisfied, so it must not wait for an event or leave a listener behind.\n\t\tif (options.count === 0) {\n\t\t\tresolve([]);\n\t\t\treturn;\n\t\t}\n\n\t\tconst items = [];\n\n\t\t// The reason is a single value, so it must not be wrapped the way a rejection event's arguments are.\n\t\tconst rejectWithReason = reason => {\n\t\t\tcancel();\n\t\t\treject(reason);\n\t\t};\n\n\t\tconst queueFilter = createFilterQueue(filter, () => isDone, rejectWithReason);\n\n\t\tconst acceptItem = value => {\n\t\t\titems.push(value);\n\n\t\t\tif (options.count !== items.length) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcancel();\n\t\t\tresolve(items);\n\t\t};\n\n\t\tconst onItem = (...arguments_) => {\n\t\t\t// The promise is already settled, so the array the caller holds must not keep growing. An emitter can still call a listener it removed during the same emit.\n\t\t\tif (isDone) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\n\t\t\tif (!filter) {\n\t\t\t\tacceptItem(value);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tqueueFilter(value, isAccepted => {\n\t\t\t\tif (isAccepted) {\n\t\t\t\t\tacceptItem(value);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\n\t\tconst rejectHandler = (...arguments_) => {\n\t\t\trejectWithReason(options.rejectionMultiArgs ? arguments_ : arguments_[0]);\n\t\t};\n\n\t\tconst abortHandler = () => {\n\t\t\trejectWithReason(options.signal.reason);\n\t\t};\n\n\t\t// Allow multiple events. The main event takes priority over a rejection event, as documented. An explicit `undefined` reads as \"not set\" rather than overriding the default, so a forwarded partial options object does not end up listening for the literal name `\"undefined\"`.\n\t\tconst listening = {\n\t\t\taddListener,\n\t\t\tremoveListener,\n\t\t\thandlers: listenerHandlers([[event, onItem], [options.rejectionEvents ?? ['error'], rejectHandler]]),\n\t\t\tsignal: options.signal,\n\t\t\tabortHandler,\n\t\t\tisDone: () => isDone,\n\t\t};\n\n\t\tcancel = () => {\n\t\t\tisDone = true;\n\n\t\t\t// Stopping the listening on any path has to release the deadline too, or it would hold the event loop open for a timer that can no longer do anything.\n\t\t\tclearTimeout(deadlineTimer);\n\n\t\t\tdetachListeners(listening);\n\t\t};\n\n\t\tattachListeners(listening);\n\n\t\t// A call that settled above was already cleaned up by `cancel()`, abort handler included.\n\t\tif (isDone || !options.resolveImmediately) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The promise is fulfilled right away, and `pTimeout` clears its timer as soon as the promise settles, so the deadline is tracked here instead. An infinite deadline has nothing to wait for, and `setTimeout` would clamp it to 1 millisecond.\n\t\tif (Number.isFinite(options.timeout)) {\n\t\t\tdeadlineTimer = setTimeout(cancel, options.timeout);\n\t\t}\n\n\t\tresolve(items);\n\t});\n\n\treturnValue.cancel = cancel;\n\n\t// An invalid `timeout` already rejected the promise above, so it must not reach `pTimeout`.\n\tif (typeof options.timeout === 'number' && options.timeout > 0 && !options.resolveImmediately) {\n\t\tconst timeout = pTimeout(returnValue, {milliseconds: options.timeout});\n\t\t// When cancelling, also clear the timeout timer\n\t\ttimeout.cancel = () => {\n\t\t\tcancel();\n\t\t\ttimeout.clear();\n\t\t};\n\n\t\treturn timeout;\n\t}\n\n\treturn returnValue;\n}\n\nexport function pEvent(emitter, event, options) {\n\tconst arrayPromise = pEventMultiple(emitter, event, {\n\t\t...normalizeOptions(options),\n\t\tcount: 1,\n\t\tresolveImmediately: false,\n\t});\n\tconst promise = arrayPromise.then(array => array[0]);\n\tpromise.cancel = arrayPromise.cancel;\n\n\treturn promise;\n}\n\nexport function pEventIterator(emitter, event, options) {\n\toptions = normalizeOptions(options);\n\n\t// Held in a local so the filter is called on its own, and `this` inside it is not the options object the library works from.\n\tconst {filter} = options;\n\n\t// An explicit `undefined` reads as \"not set\" rather than overriding the default.\n\tconst limit = options.limit ?? Infinity;\n\tif (!isCount(limit)) {\n\t\tthrow new TypeError('The `limit` option should be a non-negative integer or Infinity');\n\t}\n\n\toptions.signal?.throwIfAborted();\n\n\tconst {addListener, removeListener} = normalizeEmitter(emitter);\n\n\tlet isDone = false;\n\t// Set as soon as a resolution event arrives, so no further value can enter the iteration while the queued filters drain.\n\tlet isResolving = false;\n\t// Wrapped as `{reason}`, so a rejection whose reason is `undefined` still counts as one.\n\tlet pendingError;\n\t// The payload of the resolution event, held until a read reports the iteration as done. See `cancel()`.\n\tlet resolutionValue;\n\tconst nextQueue = [];\n\tconst valueQueue = [];\n\tlet eventCount = 0;\n\n\tconst cancel = finalValue => {\n\t\tisDone = true;\n\t\tdetachListeners(listening);\n\n\t\t// The first read that reports the iteration as done carries the payload of the resolution event, the same way a generator's first `{done: true}` result carries its return value. Published versions handed it over like this, and the async iterator protocol allows it, so `next()` callers can still read a final payload such as an exit code. Every read after that one gets `undefined`, as the protocol requires. Without a pending read, the payload waits in `resolutionValue` for the next one.\n\t\tresolutionValue = finalValue;\n\t\tfor (const {resolve} of nextQueue.splice(0)) {\n\t\t\tresolve({done: true, value: resolutionValue});\n\t\t\tresolutionValue = undefined;\n\t\t}\n\t};\n\n\tconst rejectIterator = reason => {\n\t\tif (isDone) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (nextQueue.length > 0) {\n\t\t\tnextQueue.shift().reject(reason);\n\t\t} else {\n\t\t\tpendingError = {reason};\n\t\t}\n\n\t\tcancel();\n\t};\n\n\tconst queueFilter = createFilterQueue(filter, () => isDone, rejectIterator);\n\n\tconst acceptValue = value => {\n\t\tif (nextQueue.length > 0) {\n\t\t\tnextQueue.shift().resolve({done: false, value});\n\t\t} else {\n\t\t\tvalueQueue.push(value);\n\t\t}\n\t};\n\n\tconst valueHandler = (...arguments_) => {\n\t\t// The iteration is over, so a value that is still arriving must not be added to the queue. A resolution event ends the iteration, so a value emitted after it does not belong to it, not even in the same burst before the queued filters have drained.\n\t\tif (isDone || isResolving) {\n\t\t\treturn;\n\t\t}\n\n\t\teventCount++;\n\t\tconst isLastEvent = eventCount === limit;\n\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\n\t\tconst onVerdict = isAccepted => {\n\t\t\tif (isAccepted) {\n\t\t\t\tacceptValue(value);\n\t\t\t}\n\n\t\t\t// A rejected value still counts towards the limit, so the iterator ends either way.\n\t\t\tif (isLastEvent) {\n\t\t\t\tcancel();\n\t\t\t}\n\t\t};\n\n\t\tif (filter) {\n\t\t\tqueueFilter(value, onVerdict);\n\t\t} else {\n\t\t\tonVerdict(true);\n\t\t}\n\t};\n\n\tconst rejectHandler = (...arguments_) => {\n\t\trejectIterator(options.rejectionMultiArgs ? arguments_ : arguments_[0]);\n\t};\n\n\tconst resolveHandler = (...arguments_) => {\n\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\t\tisResolving = true;\n\n\t\t// The event ends the iteration, so its payload is never yielded as a value. It queues behind the value filters, even without a filter, so that a value which was already received still gets in. The event ends the iteration either way: the verdict only decides whether its payload is handed over as the final value, which is how published versions behaved, and a failure in the filter rejects the iteration.\n\t\tqueueFilter(value, isAccepted => {\n\t\t\t// `cancel()` settles any pending read, and the first one gets the payload.\n\t\t\tcancel(isAccepted ? value : undefined);\n\t\t});\n\t};\n\n\t// The reason is a single value, so it must not be wrapped the way a rejection event's arguments are.\n\tconst abortHandler = () => {\n\t\trejectIterator(options.signal.reason);\n\t};\n\n\t// Allow multiple events. A name that is already handled as a value must not also reject or end the iteration, and a rejection wins over a resolution, so a name never ends up with two handlers. An explicit `undefined` reads as \"not set\" rather than overriding the default, so a forwarded partial options object does not end up listening for the literal name `\"undefined\"`.\n\tconst listening = {\n\t\taddListener,\n\t\tremoveListener,\n\t\thandlers: listenerHandlers([\n\t\t\t[event, valueHandler],\n\t\t\t[options.rejectionEvents ?? ['error'], rejectHandler],\n\t\t\t[options.resolutionEvents ?? [], resolveHandler],\n\t\t]),\n\t\tsignal: options.signal,\n\t\tabortHandler,\n\t\tisDone: () => isDone,\n\t};\n\n\tconst iterator = {\n\t\t[Symbol.asyncIterator]() {\n\t\t\treturn this;\n\t\t},\n\t\tasync next() {\n\t\t\tif (valueQueue.length > 0) {\n\t\t\t\t// A value that was already received is always handed over, so the iteration is never reported done while one is still buffered.\n\t\t\t\treturn {\n\t\t\t\t\tdone: false,\n\t\t\t\t\tvalue: valueQueue.shift(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (pendingError) {\n\t\t\t\tconst {reason} = pendingError;\n\t\t\t\tpendingError = undefined;\n\t\t\t\tthrow reason;\n\t\t\t}\n\n\t\t\tif (isDone) {\n\t\t\t\t// Handed over once, so only the first read after the buffered values gets the payload of the resolution event.\n\t\t\t\tconst value = resolutionValue;\n\t\t\t\tresolutionValue = undefined;\n\n\t\t\t\treturn {\n\t\t\t\t\tdone: true,\n\t\t\t\t\tvalue,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tnextQueue.push({resolve, reject});\n\t\t\t});\n\t\t},\n\t\tasync return(value) {\n\t\t\t// Without a final value, `cancel()` also drops the payload of a resolution event that was not read yet.\n\t\t\tcancel();\n\n\t\t\t// The consumer ended the iteration, so nothing that is still buffered can come out of it.\n\t\t\tvalueQueue.length = 0;\n\t\t\tpendingError = undefined;\n\n\t\t\treturn {\n\t\t\t\tdone: true,\n\t\t\t\tvalue,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Return an empty async iterator to avoid any further cost. A limit of zero is already reached, so nothing is attached, and `cancel()` has nothing to remove.\n\tif (limit === 0) {\n\t\tisDone = true;\n\t\tlistening.handlers.clear();\n\t\treturn iterator;\n\t}\n\n\tattachListeners(listening);\n\n\t// Ending above runs `cancel()`, which already took the abort handler off, so there is nothing left here.\n\treturn iterator;\n}\n\nexport {TimeoutError} from 'p-timeout';\n", "import type { RateLimiterResult } from './rate-limiter.ts'\n\n/**\n * A rate limit was hit\n */\nexport class RateLimitError extends Error {\n remainingPoints: number\n msBeforeNext: number\n consumedPoints: number\n isFirstInDuration: boolean\n\n constructor (message = 'Rate limit exceeded', props: RateLimiterResult) {\n super(message)\n this.name = 'RateLimitError'\n this.remainingPoints = props.remainingPoints\n this.msBeforeNext = props.msBeforeNext\n this.consumedPoints = props.consumedPoints\n this.isFirstInDuration = props.isFirstInDuration\n }\n}\n\nexport class QueueFullError extends Error {\n static name = 'QueueFullError'\n\n constructor (message: string = 'The queue was full') {\n super(message)\n this.name = 'QueueFullError'\n }\n}\n\nexport class UnexpectedEOFError extends Error {\n static name = 'UnexpectedEOFError'\n name = 'UnexpectedEOFError'\n}\n\nexport class MaxEarlyStreamsError extends Error {\n static name = 'MaxEarlyStreamsError'\n name = 'MaxEarlyStreamsError'\n}\n\nexport class StreamClosedError extends Error {\n static name = 'StreamClosedError'\n name = 'StreamClosedError'\n}\n", "export const PROTOCOL_VERSION = '1.0.0'\nexport const PROTOCOL_NAME = 'echo'\n", "import { ProtocolError, setMaxListeners, TimeoutError } from '@libp2p/interface'\nimport { UnexpectedEOFError } from '@libp2p/utils'\nimport { pEvent } from 'p-event'\nimport { Uint8ArrayList } from 'uint8arraylist'\nimport { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.ts'\nimport type { Echo as EchoInterface, EchoComponents, EchoInit } from './index.ts'\nimport type { DialProtocolOptions, DialTarget, Startable, Stream } from '@libp2p/interface'\n\n/**\n * A simple echo stream, any data received will be sent back to the sender\n */\nexport class Echo implements Startable, EchoInterface {\n public readonly protocol: string\n private readonly components: EchoComponents\n private started: boolean\n private readonly init: EchoInit\n private readonly timeout: number\n\n constructor (components: EchoComponents, init: EchoInit = {}) {\n this.started = false\n this.components = components\n this.protocol = `/${[init.protocolPrefix, PROTOCOL_NAME, PROTOCOL_VERSION].filter(Boolean).join('/')}`\n this.init = init\n this.timeout = init.timeout ?? 20_000\n }\n\n readonly [Symbol.toStringTag] = '@libp2p/echo'\n\n async start (): Promise<void> {\n await this.components.registrar.handle(this.protocol, this.onEcho.bind(this), {\n maxInboundStreams: this.init.maxInboundStreams,\n maxOutboundStreams: this.init.maxOutboundStreams,\n runOnLimitedConnection: this.init.runOnLimitedConnection\n })\n this.started = true\n }\n\n async stop (): Promise<void> {\n await this.components.registrar.unhandle(this.protocol)\n this.started = false\n }\n\n isStarted (): boolean {\n return this.started\n }\n\n async onEcho (stream: Stream): Promise<void> {\n const log = stream.log.newScope('echo')\n const start = Date.now()\n const signal = AbortSignal.timeout(this.timeout)\n setMaxListeners(Infinity, signal)\n let bytes = 0\n\n signal.addEventListener('abort', () => {\n stream.abort(new TimeoutError())\n })\n\n for await (const buf of stream) {\n bytes += buf.byteLength\n\n if (stream.status !== 'open') {\n log('stream status changed to %s', stream.status)\n break\n }\n\n if (!stream.send(buf)) {\n log('sent %d bytes, wait for drain', bytes)\n await pEvent(stream, 'drain', {\n rejectionEvents: [\n 'close'\n ],\n signal\n })\n } else {\n log('sent %d bytes', bytes)\n }\n }\n\n log('echoed %d bytes in %dms', bytes, Date.now() - start)\n\n await stream.close({\n signal\n })\n }\n\n async echo (peer: DialTarget, buf: Uint8Array | Uint8ArrayList, options?: DialProtocolOptions): Promise<Uint8ArrayList> {\n const stream = await this.components.connectionManager.openStream(peer, this.protocol, {\n ...this.init,\n ...options\n })\n\n const log = stream.log.newScope('echo')\n\n const received = new Uint8ArrayList()\n const output = Promise.withResolvers<Uint8ArrayList>()\n\n stream.addEventListener('message', (evt) => {\n received.append(evt.data)\n log('received %d/%d bytes', received.byteLength, buf.byteLength)\n })\n\n stream.addEventListener('close', (evt) => {\n if (evt.error != null) {\n output.reject(evt.error)\n }\n\n if (received.byteLength > buf.byteLength) {\n output.reject(new ProtocolError(`Overread: ${received.byteLength}/${buf.byteLength} bytes`))\n }\n\n if (received.byteLength < buf.byteLength) {\n output.reject(new UnexpectedEOFError(`Underread: ${received.byteLength}/${buf.byteLength} bytes`))\n }\n\n output.resolve(received)\n })\n\n log('sending %d bytes', buf.byteLength)\n stream.send(buf)\n\n await stream.close(options).catch(err => {\n output.reject(err)\n })\n\n return output.promise\n }\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B,CAAC,EAEMJ,EAAO,OAChB,GX1DI,SAAUK,GAAMC,EAAiB,CAAA,EAAE,CACvC,OAAQC,GAAe,IAAIC,EAAUD,EAAYD,CAAI,CACvD",
|
|
6
|
-
"names": ["index_exports", "__export", "echo", "ProtocolError", "message", "TimeoutError", "alloc", "size", "allocUnsafe", "isByteArrayWithArrayBuffer", "b", "asUint8Array", "buf", "concat", "arrays", "length", "acc", "curr", "output", "allocUnsafe", "offset", "arr", "asUint8Array", "equals", "a", "b", "i", "symbol", "findBufAndOffset", "bufs", "index", "offset", "buf", "bufEnd", "isUint8ArrayList", "value", "Uint8ArrayList", "_Uint8ArrayList", "data", "length", "chunk", "res", "i", "bytes", "beginInclusive", "endExclusive", "concat", "list", "bufStart", "sliceStartInBuf", "sliceEndsInBuf", "start", "search", "needle", "M", "radix", "rightmostPositions", "j", "right", "lastIndex", "lastPatIndex", "skip", "char", "byteOffset", "allocUnsafe", "littleEndian", "alloc", "other", "equals", "acc", "curr", "TimeoutError", "_TimeoutError", "message", "options", "getAbortedReason", "signal", "
|
|
4
|
+
"sourcesContent": ["/**\n * @packageDocumentation\n *\n * An implementation of a simple Echo protocol.\n *\n * Any data received by the receiver will be sent back to the sender.\n *\n * @example\n *\n * ```TypeScript\n * import { noise } from '@libp2p/noise'\n * import { yamux } from '@libp2p/yamux'\n * import { echo } from '@libp2p/echo'\n * import { peerIdFromString } from '@libp2p/peer-id'\n * import { createLibp2p } from 'libp2p'\n *\n * const receiver = await createLibp2p({\n * addresses: {\n * listen: ['/ip4/0.0.0.0/tcp/0']\n * },\n * connectionEncrypters: [noise()],\n * streamMuxers: [yamux()],\n * services: {\n * echo: echo()\n * }\n * })\n *\n * const sender = await createLibp2p({\n * addresses: {\n * listen: ['/ip4/0.0.0.0/tcp/0']\n * },\n * connectionEncrypters: [noise()],\n * streamMuxers: [yamux()],\n * services: {\n * echo: echo()\n * }\n * })\n *\n * const stream = await sender.dialProtocol(receiver.getMultiaddrs(), sender.services.echo.protocol)\n *\n * // write/read stream\n * ```\n */\n\nimport { Echo as EchoClass } from './echo.ts'\nimport type { DialProtocolOptions, DialTarget } from '@libp2p/interface'\nimport type { ConnectionManager, Registrar } from '@libp2p/interface-internal'\nimport type { Uint8ArrayList } from 'uint8arraylist'\n\nexport interface EchoInit {\n protocolPrefix?: string\n maxInboundStreams?: number\n maxOutboundStreams?: number\n runOnLimitedConnection?: boolean\n timeout?: number\n}\n\nexport interface EchoComponents {\n registrar: Registrar\n connectionManager: ConnectionManager\n}\n\nexport interface Echo {\n protocol: string\n echo(peer: DialTarget, buf: Uint8Array | Uint8ArrayList, options?: DialProtocolOptions): Promise<Uint8ArrayList>\n}\n\nexport function echo (init: EchoInit = {}): (components: EchoComponents) => Echo {\n return (components) => new EchoClass(components, init)\n}\n", "/**\n * When this error is thrown it means an operation was aborted,\n * usually in response to the `abort` event being emitted by an\n * AbortSignal.\n */\nexport class AbortError extends Error {\n static name = 'AbortError'\n\n constructor (message: string = 'The operation was aborted') {\n super(message)\n this.name = 'AbortError'\n }\n}\n\n/**\n * Thrown when a remote Peer ID does not match the expected one\n */\nexport class UnexpectedPeerError extends Error {\n static name = 'UnexpectedPeerError'\n\n constructor (message = 'Unexpected Peer') {\n super(message)\n this.name = 'UnexpectedPeerError'\n }\n}\n\n/**\n * Thrown when a crypto exchange fails\n */\nexport class InvalidCryptoExchangeError extends Error {\n static name = 'InvalidCryptoExchangeError'\n\n constructor (message = 'Invalid crypto exchange') {\n super(message)\n this.name = 'InvalidCryptoExchangeError'\n }\n}\n\n/**\n * Thrown when invalid parameters are passed to a function or method call\n */\nexport class InvalidParametersError extends Error {\n static name = 'InvalidParametersError'\n\n constructor (message = 'Invalid parameters') {\n super(message)\n this.name = 'InvalidParametersError'\n }\n}\n\n/**\n * Thrown when a public key is invalid\n */\nexport class InvalidPublicKeyError extends Error {\n static name = 'InvalidPublicKeyError'\n\n constructor (message = 'Invalid public key') {\n super(message)\n this.name = 'InvalidPublicKeyError'\n }\n}\n\n/**\n * Thrown when a private key is invalid\n */\nexport class InvalidPrivateKeyError extends Error {\n static name = 'InvalidPrivateKeyError'\n\n constructor (message = 'Invalid private key') {\n super(message)\n this.name = 'InvalidPrivateKeyError'\n }\n}\n\n/**\n * Thrown when a operation is unsupported\n */\nexport class UnsupportedOperationError extends Error {\n static name = 'UnsupportedOperationError'\n\n constructor (message = 'Unsupported operation') {\n super(message)\n this.name = 'UnsupportedOperationError'\n }\n}\n\n/**\n * Thrown when a connection is closing\n */\nexport class ConnectionClosingError extends Error {\n static name = 'ConnectionClosingError'\n\n constructor (message = 'The connection is closing') {\n super(message)\n this.name = 'ConnectionClosingError'\n }\n}\n\n/**\n * Thrown when a connection is closed\n */\nexport class ConnectionClosedError extends Error {\n static name = 'ConnectionClosedError'\n\n constructor (message = 'The connection is closed') {\n super(message)\n this.name = 'ConnectionClosedError'\n }\n}\n\n/**\n * Thrown when a connection fails\n */\nexport class ConnectionFailedError extends Error {\n static name = 'ConnectionFailedError'\n\n constructor (message = 'Connection failed') {\n super(message)\n this.name = 'ConnectionFailedError'\n }\n}\n\n/**\n * Thrown when the muxer is closed and an attempt to open a stream occurs\n */\nexport class MuxerClosedError extends Error {\n static name = 'MuxerClosedError'\n\n constructor (message = 'The muxer is closed') {\n super(message)\n this.name = 'MuxerClosedError'\n }\n}\n\n/**\n * Thrown when a protocol stream is reset by the remote muxer\n */\nexport class StreamResetError extends Error {\n static name = 'StreamResetError'\n\n constructor (message = 'The stream has been reset') {\n super(message)\n this.name = 'StreamResetError'\n }\n}\n\n/**\n * Thrown when a protocol stream is aborted locally\n */\nexport class StreamAbortedError extends Error {\n static name = 'StreamAbortedError'\n\n constructor (message = 'The stream has been aborted') {\n super(message)\n this.name = 'StreamAbortedError'\n }\n}\n\n/**\n * Thrown when a stream is in an invalid state\n */\nexport class StreamStateError extends Error {\n static name = 'StreamStateError'\n\n constructor (message = 'The stream is in an invalid state') {\n super(message)\n this.name = 'StreamStateError'\n }\n}\n\n/**\n * Thrown when a stream buffer is full\n */\nexport class StreamBufferError extends Error {\n static name = 'StreamBufferError'\n\n constructor (message = 'The stream buffer was full') {\n super(message)\n this.name = 'StreamBufferError'\n }\n}\n\n/**\n * Thrown when a value could not be found\n */\nexport class NotFoundError extends Error {\n static name = 'NotFoundError'\n\n constructor (message = 'Not found') {\n super(message)\n this.name = 'NotFoundError'\n }\n}\n\n/**\n * Thrown when an invalid peer ID is encountered\n */\nexport class InvalidPeerIdError extends Error {\n static name = 'InvalidPeerIdError'\n\n constructor (message = 'Invalid PeerID') {\n super(message)\n this.name = 'InvalidPeerIdError'\n }\n}\n\n/**\n * Thrown when an invalid multiaddr is encountered\n */\nexport class InvalidMultiaddrError extends Error {\n static name = 'InvalidMultiaddrError'\n\n constructor (message = 'Invalid multiaddr') {\n super(message)\n this.name = 'InvalidMultiaddrError'\n }\n}\n\n/**\n * Thrown when an invalid CID is encountered\n */\nexport class InvalidCIDError extends Error {\n static name = 'InvalidCIDError'\n\n constructor (message = 'Invalid CID') {\n super(message)\n this.name = 'InvalidCIDError'\n }\n}\n\n/**\n * Thrown when an invalid multihash is encountered\n */\nexport class InvalidMultihashError extends Error {\n static name = 'InvalidMultihashError'\n\n constructor (message = 'Invalid Multihash') {\n super(message)\n this.name = 'InvalidMultihashError'\n }\n}\n\n/**\n * Thrown when a protocol is not supported\n */\nexport class UnsupportedProtocolError extends Error {\n static name = 'UnsupportedProtocolError'\n\n constructor (message = 'Unsupported protocol error') {\n super(message)\n this.name = 'UnsupportedProtocolError'\n }\n}\n\n/**\n * An invalid or malformed message was encountered during a protocol exchange\n */\nexport class InvalidMessageError extends Error {\n static name = 'InvalidMessageError'\n\n constructor (message = 'Invalid message') {\n super(message)\n this.name = 'InvalidMessageError'\n }\n}\n\n/**\n * Thrown when a remote peer sends a structurally valid message that does not\n * comply with the protocol\n */\nexport class ProtocolError extends Error {\n static name = 'ProtocolError'\n\n constructor (message = 'Protocol error') {\n super(message)\n this.name = 'ProtocolError'\n }\n}\n\n/**\n * Throw when an operation times out\n */\nexport class TimeoutError extends Error {\n static name = 'TimeoutError'\n\n constructor (message = 'Timed out') {\n super(message)\n this.name = 'TimeoutError'\n }\n}\n\n/**\n * Thrown when a startable component is interacted with but it has not been\n * started yet\n */\nexport class NotStartedError extends Error {\n static name = 'NotStartedError'\n\n constructor (message = 'Not started') {\n super(message)\n this.name = 'NotStartedError'\n }\n}\n\n/**\n * Thrown when a component is started that has already been started\n */\nexport class AlreadyStartedError extends Error {\n static name = 'AlreadyStartedError'\n\n constructor (message = 'Already started') {\n super(message)\n this.name = 'AlreadyStartedError'\n }\n}\n\n/**\n * Thrown when dialing an address failed\n */\nexport class DialError extends Error {\n static name = 'DialError'\n\n constructor (message = 'Dial error') {\n super(message)\n this.name = 'DialError'\n }\n}\n\n/**\n * Thrown when listening on an address failed\n */\nexport class ListenError extends Error {\n static name = 'ListenError'\n\n constructor (message = 'Listen error') {\n super(message)\n this.name = 'ListenError'\n }\n}\n\n/**\n * This error is thrown when a limited connection is encountered, i.e. if the\n * user tried to open a stream on a connection for a protocol that is not\n * configured to run over limited connections.\n */\nexport class LimitedConnectionError extends Error {\n static name = 'LimitedConnectionError'\n\n constructor (message = 'Limited connection') {\n super(message)\n this.name = 'LimitedConnectionError'\n }\n}\n\n/**\n * This error is thrown where there are too many inbound protocols streams open\n */\nexport class TooManyInboundProtocolStreamsError extends Error {\n static name = 'TooManyInboundProtocolStreamsError'\n\n constructor (message = 'Too many inbound protocol streams') {\n super(message)\n this.name = 'TooManyInboundProtocolStreamsError'\n }\n}\n\n/**\n * This error is thrown where there are too many outbound protocols streams open\n */\nexport class TooManyOutboundProtocolStreamsError extends Error {\n static name = 'TooManyOutboundProtocolStreamsError'\n\n constructor (message = 'Too many outbound protocol streams') {\n super(message)\n this.name = 'TooManyOutboundProtocolStreamsError'\n }\n}\n\n/**\n * Thrown when an attempt to operate on an unsupported key was made\n */\nexport class UnsupportedKeyTypeError extends Error {\n static name = 'UnsupportedKeyTypeError'\n\n constructor (message = 'Unsupported key type') {\n super(message)\n this.name = 'UnsupportedKeyTypeError'\n }\n}\n\n/**\n * Thrown when an operation has not been implemented\n */\nexport class NotImplementedError extends Error {\n static name = 'NotImplementedError'\n\n constructor (message = 'Not implemented') {\n super(message)\n this.name = 'NotImplementedError'\n }\n}\n", "/**\n * Returns a `Uint8Array` of the requested size. Referenced memory will\n * be initialized to 0.\n */\nexport function alloc (size: number = 0): Uint8Array<ArrayBuffer> {\n return new Uint8Array(size)\n}\n\n/**\n * Where possible returns a Uint8Array of the requested size that references\n * uninitialized memory. Only use if you are certain you will immediately\n * overwrite every value in the returned `Uint8Array`.\n */\nexport function allocUnsafe (size: number = 0): Uint8Array<ArrayBuffer> {\n return new Uint8Array(size)\n}\n", "function isByteArrayWithArrayBuffer (b?: Uint8Array): b is Uint8Array<ArrayBuffer> {\n return b?.buffer instanceof ArrayBuffer\n}\n\n/**\n * To guarantee Uint8Array semantics, convert nodejs Buffers\n * into vanilla Uint8Arrays\n */\nexport function asUint8Array (buf: Uint8Array): Uint8Array<ArrayBuffer> {\n if (isByteArrayWithArrayBuffer(buf)) {\n return buf\n }\n\n const b = buf.slice()\n\n return new Uint8Array(b.buffer, 0, b.byteLength)\n}\n", "import { allocUnsafe } from '#alloc'\nimport { asUint8Array } from '#util/as-uint8array'\n\n/**\n * Returns a new Uint8Array created by concatenating the passed Uint8Arrays\n */\nexport function concat (arrays: Uint8Array[], length?: number): Uint8Array<ArrayBuffer> {\n if (length == null) {\n length = arrays.reduce((acc, curr) => acc + curr.length, 0)\n }\n\n const output = allocUnsafe(length)\n let offset = 0\n\n for (const arr of arrays) {\n output.set(arr, offset)\n offset += arr.length\n }\n\n return asUint8Array(output)\n}\n", "/**\n * Returns true if the two passed Uint8Arrays have the same content\n */\nexport function equals (a: Uint8Array, b: Uint8Array): boolean {\n if (a === b) {\n return true\n }\n\n if (a.byteLength !== b.byteLength) {\n return false\n }\n\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n\n return true\n}\n", "/**\n * @packageDocumentation\n *\n * A class that lets you do operations over a list of Uint8Arrays without\n * copying them.\n *\n * ```js\n * import { Uint8ArrayList } from 'uint8arraylist'\n *\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.subarray()\n * // -> Uint8Array([0, 1, 2, 3, 4, 5])\n *\n * list.consume(3)\n * list.subarray()\n * // -> Uint8Array([3, 4, 5])\n *\n * // you can also iterate over the list\n * for (const buf of list) {\n * // ..do something with `buf`\n * }\n *\n * list.subarray(0, 1)\n * // -> Uint8Array([0])\n * ```\n *\n * ## Converting Uint8ArrayLists to Uint8Arrays\n *\n * There are two ways to turn a `Uint8ArrayList` into a `Uint8Array` - `.slice` and `.subarray` and one way to turn a `Uint8ArrayList` into a `Uint8ArrayList` with different contents - `.sublist`.\n *\n * ### slice\n *\n * Slice follows the same semantics as [Uint8Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice) in that it creates a new `Uint8Array` and copies bytes into it using an optional offset & length.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.slice(0, 1)\n * // -> Uint8Array([0])\n * ```\n *\n * ### subarray\n *\n * Subarray attempts to follow the same semantics as [Uint8Array.subarray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) with one important different - this is a no-copy operation, unless the requested bytes span two internal buffers in which case it is a copy operation.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.subarray(0, 1)\n * // -> Uint8Array([0]) - no-copy\n *\n * list.subarray(2, 5)\n * // -> Uint8Array([2, 3, 4]) - copy\n * ```\n *\n * ### sublist\n *\n * Sublist creates and returns a new `Uint8ArrayList` that shares the underlying buffers with the original so is always a no-copy operation.\n *\n * ```js\n * const list = new Uint8ArrayList()\n * list.append(Uint8Array.from([0, 1, 2]))\n * list.append(Uint8Array.from([3, 4, 5]))\n *\n * list.sublist(0, 1)\n * // -> Uint8ArrayList([0]) - no-copy\n *\n * list.sublist(2, 5)\n * // -> Uint8ArrayList([2], [3, 4]) - no-copy\n * ```\n *\n * ## Inspiration\n *\n * Borrows liberally from [bl](https://www.npmjs.com/package/bl) but only uses native JS types.\n */\nimport { allocUnsafe, alloc } from 'uint8arrays/alloc'\nimport { concat } from 'uint8arrays/concat'\nimport { equals } from 'uint8arrays/equals'\n\nconst symbol = Symbol.for('@achingbrain/uint8arraylist')\n\nexport type Appendable<T extends ArrayBufferLike = ArrayBuffer> = Uint8ArrayList<T> | Uint8Array<T>\n\nfunction findBufAndOffset (bufs: Uint8Array[], index: number): { buf: Uint8Array, index: number } {\n if (index == null || index < 0) {\n throw new RangeError('index is out of bounds')\n }\n\n let offset = 0\n\n for (const buf of bufs) {\n const bufEnd = offset + buf.byteLength\n\n if (index < bufEnd) {\n return {\n buf,\n index: index - offset\n }\n }\n\n offset = bufEnd\n }\n\n throw new RangeError('index is out of bounds')\n}\n\n/**\n * Check if object is a CID instance\n *\n * @example\n *\n * ```js\n * import { isUint8ArrayList, Uint8ArrayList } from 'uint8arraylist'\n *\n * isUint8ArrayList(true) // false\n * isUint8ArrayList([]) // false\n * isUint8ArrayList(new Uint8ArrayList()) // true\n * ```\n */\nexport function isUint8ArrayList (value: any): value is Uint8ArrayList {\n return Boolean(value?.[symbol])\n}\n\nexport class Uint8ArrayList <T extends ArrayBufferLike = ArrayBufferLike> implements Iterable<Uint8Array<T>> {\n private bufs: Uint8Array<T>[]\n public length: number\n public readonly [symbol] = true\n\n constructor (...data: Appendable<T>[]) {\n this.bufs = []\n this.length = 0\n\n if (data.length > 0) {\n this.appendAll(data)\n }\n }\n\n * [Symbol.iterator] (): Iterator<Uint8Array<T>> {\n yield * this.bufs\n }\n\n get byteLength (): number {\n return this.length\n }\n\n /**\n * Add one or more `bufs` to the end of this Uint8ArrayList\n */\n append (...bufs: Appendable<T>[]): void {\n this.appendAll(bufs)\n }\n\n /**\n * Add all `bufs` to the end of this Uint8ArrayList\n */\n appendAll (bufs: Appendable<T>[]): void {\n let length = 0\n\n for (const buf of bufs) {\n if (buf instanceof Uint8Array) {\n length += buf.byteLength\n this.bufs.push(buf)\n } else if (isUint8ArrayList(buf)) {\n length += buf.byteLength\n for (const chunk of buf.bufs) {\n this.bufs.push(chunk)\n }\n } else {\n throw new Error('Could not append value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n this.length += length\n }\n\n /**\n * Add one or more `bufs` to the start of this Uint8ArrayList\n */\n prepend (...bufs: Appendable<T>[]): void {\n this.prependAll(bufs)\n }\n\n /**\n * Add all `bufs` to the start of this Uint8ArrayList\n */\n prependAll (bufs: Appendable<T>[]): void {\n let length = 0\n\n for (const buf of bufs.reverse()) {\n if (buf instanceof Uint8Array) {\n length += buf.byteLength\n this.bufs.unshift(buf)\n } else if (isUint8ArrayList(buf)) {\n length += buf.byteLength\n this.bufs.unshift(...buf.bufs)\n } else {\n throw new Error('Could not prepend value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n this.length += length\n }\n\n /**\n * Read the value at `index`\n */\n get (index: number): number {\n const res = findBufAndOffset(this.bufs, index)\n\n return res.buf[res.index]\n }\n\n /**\n * Set the value at `index` to `value`\n */\n set (index: number, value: number): void {\n const res = findBufAndOffset(this.bufs, index)\n\n res.buf[res.index] = value\n }\n\n /**\n * Copy bytes from `buf` to the index specified by `offset`\n */\n write (buf: Appendable<T | ArrayBuffer>, offset: number = 0): void {\n if (buf instanceof Uint8Array) {\n for (let i = 0; i < buf.length; i++) {\n this.set(offset + i, buf[i])\n }\n } else if (isUint8ArrayList(buf)) {\n for (let i = 0; i < buf.length; i++) {\n this.set(offset + i, buf.get(i))\n }\n } else {\n throw new Error('Could not write value, must be an Uint8Array or a Uint8ArrayList')\n }\n }\n\n /**\n * Remove bytes from the front of the pool\n */\n consume (bytes: number): void {\n // first, normalize the argument, in accordance with how Buffer does it\n bytes = Math.trunc(bytes)\n\n // do nothing if not a positive number\n if (Number.isNaN(bytes) || bytes <= 0) {\n return\n }\n\n // if consuming all bytes, skip iterating\n if (bytes === this.byteLength) {\n this.bufs = []\n this.length = 0\n return\n }\n\n while (this.bufs.length > 0) {\n if (bytes >= this.bufs[0].byteLength) {\n bytes -= this.bufs[0].byteLength\n this.length -= this.bufs[0].byteLength\n this.bufs.shift()\n } else {\n this.bufs[0] = this.bufs[0].subarray(bytes)\n this.length -= bytes\n break\n }\n }\n }\n\n /**\n * Extracts a section of an array and returns a new array.\n *\n * This is a copy operation as it is with Uint8Arrays and Arrays\n * - note this is different to the behaviour of Node Buffers.\n */\n slice (beginInclusive?: number, endExclusive?: number): Uint8Array<ArrayBuffer> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n return concat(bufs, length)\n }\n\n /**\n * Returns a section of the array from the given start and end element index.\n *\n * This is a no-copy operation where the data extracted data comes from a\n * single Uint8Array internally, otherwise it is a copy operation.\n */\n subarray (beginInclusive?: number, endExclusive?: number): Uint8Array<T | ArrayBuffer> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n if (bufs.length === 1) {\n return bufs[0]\n }\n\n return concat(bufs, length)\n }\n\n /**\n * Returns a new Uint8ArrayList from the given start and end element index.\n *\n * This is a no-copy operation.\n */\n sublist (beginInclusive?: number, endExclusive?: number): Uint8ArrayList<T> {\n const { bufs, length } = this._subList(beginInclusive, endExclusive)\n\n const list = new Uint8ArrayList<T>()\n list.length = length\n // don't loop, just set the bufs\n list.bufs = bufs\n\n return list\n }\n\n private _subList (beginInclusive?: number, endExclusive?: number): { bufs: Uint8Array<T>[], length: number } {\n beginInclusive = beginInclusive ?? 0\n endExclusive = endExclusive ?? this.length\n\n if (beginInclusive < 0) {\n beginInclusive = this.length + beginInclusive\n }\n\n if (endExclusive < 0) {\n endExclusive = this.length + endExclusive\n }\n\n if (beginInclusive < 0 || endExclusive > this.length) {\n throw new RangeError('index is out of bounds')\n }\n\n if (beginInclusive === endExclusive) {\n return { bufs: [], length: 0 }\n }\n\n if (beginInclusive === 0 && endExclusive === this.length) {\n return { bufs: [...this.bufs], length: this.length }\n }\n\n const bufs: Uint8Array<T>[] = []\n let offset = 0\n\n for (let i = 0; i < this.bufs.length; i++) {\n const buf = this.bufs[i]\n const bufStart = offset\n const bufEnd = bufStart + buf.byteLength\n\n // for next loop\n offset = bufEnd\n\n if (beginInclusive >= bufEnd) {\n // start after this buf\n continue\n }\n\n const sliceStartInBuf = beginInclusive >= bufStart && beginInclusive < bufEnd\n const sliceEndsInBuf = endExclusive > bufStart && endExclusive <= bufEnd\n\n if (sliceStartInBuf && sliceEndsInBuf) {\n // slice is wholly contained within this buffer\n if (beginInclusive === bufStart && endExclusive === bufEnd) {\n // requested whole buffer\n bufs.push(buf)\n break\n }\n\n // requested part of buffer\n const start = beginInclusive - bufStart\n bufs.push(buf.subarray(start, start + (endExclusive - beginInclusive)))\n break\n }\n\n if (sliceStartInBuf) {\n // slice starts in this buffer\n if (beginInclusive === 0) {\n // requested whole buffer\n bufs.push(buf)\n continue\n }\n\n // requested part of buffer\n bufs.push(buf.subarray(beginInclusive - bufStart))\n continue\n }\n\n if (sliceEndsInBuf) {\n if (endExclusive === bufEnd) {\n // requested whole buffer\n bufs.push(buf)\n break\n }\n\n // requested part of buffer\n bufs.push(buf.subarray(0, endExclusive - bufStart))\n break\n }\n\n // slice started before this buffer and ends after it\n bufs.push(buf)\n }\n\n return { bufs, length: endExclusive - beginInclusive }\n }\n\n indexOf (search: Uint8ArrayList | Uint8Array, offset: number = 0): number {\n if (!isUint8ArrayList(search) && !(search instanceof Uint8Array)) {\n throw new TypeError('The \"value\" argument must be a Uint8ArrayList or Uint8Array')\n }\n\n const needle = search instanceof Uint8Array ? search : search.subarray()\n\n offset = Number(offset ?? 0)\n\n if (isNaN(offset)) {\n offset = 0\n }\n\n if (offset < 0) {\n offset = this.length + offset\n }\n\n if (offset < 0) {\n offset = 0\n }\n\n if (search.length === 0) {\n return offset > this.length ? this.length : offset\n }\n\n // https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm\n const M: number = needle.byteLength\n\n if (M === 0) {\n throw new TypeError('search must be at least 1 byte long')\n }\n\n // radix\n const radix: number = 256\n const rightmostPositions: Int32Array = new Int32Array(radix)\n\n // position of the rightmost occurrence of the byte c in the pattern\n for (let c: number = 0; c < radix; c++) {\n // -1 for bytes not in pattern\n rightmostPositions[c] = -1\n }\n\n for (let j = 0; j < M; j++) {\n // rightmost position for bytes in pattern\n rightmostPositions[needle[j]] = j\n }\n\n // Return offset of first match, -1 if no match\n const right = rightmostPositions\n const lastIndex = this.byteLength - needle.byteLength\n const lastPatIndex = needle.byteLength - 1\n let skip: number\n\n for (let i = offset; i <= lastIndex; i += skip) {\n skip = 0\n\n for (let j = lastPatIndex; j >= 0; j--) {\n const char: number = this.get(i + j)\n\n if (needle[j] !== char) {\n skip = Math.max(1, j - right[char])\n break\n }\n }\n\n if (skip === 0) {\n return i\n }\n }\n\n return -1\n }\n\n getInt8 (byteOffset: number): number {\n const buf = this.subarray(byteOffset, byteOffset + 1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt8(0)\n }\n\n setInt8 (byteOffset: number, value: number): void {\n const buf = allocUnsafe(1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt8(0, value)\n\n this.write(buf, byteOffset)\n }\n\n getInt16 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt16(0, littleEndian)\n }\n\n setInt16 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt16(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getInt32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getInt32(0, littleEndian)\n }\n\n setInt32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setInt32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getBigInt64 (byteOffset: number, littleEndian?: boolean): bigint {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getBigInt64(0, littleEndian)\n }\n\n setBigInt64 (byteOffset: number, value: bigint, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setBigInt64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getUint8 (byteOffset: number): number {\n const buf = this.subarray(byteOffset, byteOffset + 1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint8(0)\n }\n\n setUint8 (byteOffset: number, value: number): void {\n const buf = allocUnsafe(1)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint8(0, value)\n\n this.write(buf, byteOffset)\n }\n\n getUint16 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint16(0, littleEndian)\n }\n\n setUint16 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(2)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint16(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getUint32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getUint32(0, littleEndian)\n }\n\n setUint32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setUint32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getBigUint64 (byteOffset: number, littleEndian?: boolean): bigint {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getBigUint64(0, littleEndian)\n }\n\n setBigUint64 (byteOffset: number, value: bigint, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setBigUint64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getFloat32 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getFloat32(0, littleEndian)\n }\n\n setFloat32 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(4)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setFloat32(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n getFloat64 (byteOffset: number, littleEndian?: boolean): number {\n const buf = this.subarray(byteOffset, byteOffset + 8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n\n return view.getFloat64(0, littleEndian)\n }\n\n setFloat64 (byteOffset: number, value: number, littleEndian?: boolean): void {\n const buf = alloc(8)\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)\n view.setFloat64(0, value, littleEndian)\n\n this.write(buf, byteOffset)\n }\n\n equals (other: any): other is Uint8ArrayList {\n if (other == null) {\n return false\n }\n\n if (!(other instanceof Uint8ArrayList)) {\n return false\n }\n\n if (other.bufs.length !== this.bufs.length) {\n return false\n }\n\n for (let i = 0; i < this.bufs.length; i++) {\n if (!equals(this.bufs[i], other.bufs[i])) {\n return false\n }\n }\n\n return true\n }\n\n /**\n * Create a Uint8ArrayList from a pre-existing list of Uint8Arrays. Use this\n * method if you know the total size of all the Uint8Arrays ahead of time.\n */\n static fromUint8Arrays <T extends ArrayBufferLike> (bufs: Uint8Array<T>[], length?: number): Uint8ArrayList<T> {\n const list = new Uint8ArrayList<T>()\n list.bufs = bufs\n\n if (length == null) {\n length = bufs.reduce((acc, curr) => acc + curr.byteLength, 0)\n }\n\n list.length = length\n\n return list\n }\n}\n\n/*\nfunction indexOf (needle: Uint8Array, haystack: Uint8Array, offset = 0) {\n for (let i = offset; i < haystack.byteLength; i++) {\n for (let j = 0; j < needle.length; j++) {\n if (haystack[i + j] !== needle[j]) {\n break\n }\n\n if (j === needle.byteLength -1) {\n return i\n }\n }\n\n if (haystack.byteLength - i < needle.byteLength) {\n break\n }\n }\n\n return -1\n}\n*/\n", "export class TimeoutError extends Error {\n\tname = 'TimeoutError';\n\n\tconstructor(message, options) {\n\t\tsuper(message, options);\n\t\t// V8-only, and it does exactly one thing here: it hides this constructor frame from the stack.\n\t\t// eslint-disable-next-line unicorn/no-useless-error-capture-stack-trace, unicorn/no-nonstandard-builtin-properties\n\t\tError.captureStackTrace?.(this, TimeoutError);\n\t}\n}\n\n// An `AbortSignal` always has a reason once aborted, and that reason is whatever the caller passed to `abort()`, including `null`. Only hand-rolled signal objects can lack the property entirely.\nconst getAbortedReason = signal => 'reason' in signal\n\t? signal.reason\n\t: new DOMException('This operation was aborted.', 'AbortError');\n\n// `setTimeout` stores its delay in a 32-bit signed integer, so this is the largest delay it can represent.\nconst maximumDelay = (2 ** 31) - 1;\n\nconst getOptionsError = (milliseconds, customTimers) => {\n\tif (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {\n\t\treturn new TypeError(`Expected \\`milliseconds\\` to be a positive number, got \\`${milliseconds}\\``);\n\t}\n\n\tif (typeof customTimers?.setTimeout !== 'function' || typeof customTimers?.clearTimeout !== 'function') {\n\t\treturn new TypeError('Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function');\n\t}\n};\n\nexport default function pTimeout(promise, options) {\n\tconst {\n\t\tmilliseconds,\n\t\tfallback,\n\t\tmessage,\n\t\tcustomTimers = {setTimeout, clearTimeout},\n\t\tsignal,\n\t} = options;\n\n\tlet timer;\n\tlet abortHandler;\n\n\t// Best-effort cancellation of the input, so a throwing `.cancel()` can neither escape the timer callback as an uncaught exception nor prevent us from settling. Anything that is not callable is skipped by the same `try`. It always runs after the outcome is decided, as `.cancel()` may settle the input synchronously through the handlers we passed to `then`.\n\tconst cancelInput = () => {\n\t\ttry {\n\t\t\tpromise.cancel?.();\n\t\t} catch {\n\t\t\t// Ignored: the outcome matters more than a failure to stop the work early.\n\t\t}\n\t};\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tconst abort = () => {\n\t\t\treject(getAbortedReason(signal));\n\t\t\t// The caller no longer wants the result, so stop the underlying work, the same as a timeout does.\n\t\t\tcancelInput();\n\t\t};\n\n\t\t// `input` is a `PromiseLike`, so it may settle during the call to `then`. Anything that has to win over its outcome, an invalid option or an abort the caller already committed to, is therefore decided before it is attached. Otherwise a synchronous thenable settles the wrapper first and buries both.\n\t\tconst optionsError = getOptionsError(milliseconds, customTimers);\n\n\t\ttry {\n\t\t\tif (optionsError) {\n\t\t\t\treject(optionsError);\n\t\t\t} else if (signal?.aborted) {\n\t\t\t\tabort();\n\t\t\t} else if (signal) {\n\t\t\t\t// A synchronous thenable can abort the signal and settle during the call to `then`, so attach the listener first to preserve their order. An `AbortSignal` does not replay the event to a listener added later.\n\t\t\t\tabortHandler = abort;\n\t\t\t\tsignal.addEventListener('abort', abortHandler, {once: true});\n\t\t\t}\n\t\t} finally {\n\t\t\t// Use .then() instead of async IIFE to preserve stack traces. This also observes the input when it has already lost or the signal cannot take a listener, so its rejection cannot escape as an unhandled rejection that crashes the process and hides the real error. It has to be the only handler on the input, as an extra one costs the input's rejection its caller frames in the stack trace.\n\t\t\t// eslint-disable-next-line unicorn/prefer-then-catch\n\t\t\tpromise.then(resolve, reject);\n\t\t}\n\n\t\t// A delay that `setTimeout` cannot represent never elapses, so there is nothing to time out. Without this, `setTimeout` silently clamps anything above 2 ** 31 - 1 to 1ms and the timeout fires at once.\n\t\tif (optionsError || signal?.aborted || milliseconds > maximumDelay) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We create the error outside of `setTimeout` to preserve the stack trace, but only when the timeout can actually reject with it, since capturing a stack trace is expensive and most promises settle first.\n\t\tconst timeoutError = fallback || message === false || message instanceof Error\n\t\t\t? undefined\n\t\t\t: new TimeoutError(message ?? `Promise timed out after ${milliseconds} milliseconds`);\n\n\t\t// `.call(undefined, ...)` is needed for custom timers to avoid context issues\n\t\ttimer = customTimers.setTimeout.call(undefined, () => {\n\t\t\tif (fallback) {\n\t\t\t\ttry {\n\t\t\t\t\tresolve(fallback());\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t}\n\t\t\t} else if (message === false) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\treject(message instanceof Error ? message : timeoutError);\n\t\t\t}\n\n\t\t\t// The input timed out even when a fallback takes over, and the readme promises `.cancel()` runs on timeout.\n\t\t\tcancelInput();\n\t\t}, milliseconds);\n\t});\n\n\tconst cancelablePromise = wrappedPromise.finally(() => {\n\t\t// The outcome is already decided, so a failing cleanup step must neither change it nor stop the other step: a `clearTimeout` that throws must not leave the abort listener attached.\n\t\ttry {\n\t\t\tcancelablePromise.clear();\n\t\t} catch {\n\t\t\t// Ignored. The timer handle is deliberately left in place so an explicit `clear()` can still retry.\n\t\t}\n\n\t\ttry {\n\t\t\tif (abortHandler) {\n\t\t\t\tsignal.removeEventListener('abort', abortHandler);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignored, for the same reason.\n\t\t}\n\t});\n\n\tcancelablePromise.clear = () => {\n\t\t// A timeout that never elapses creates no timer, and a custom `clearTimeout` is entitled to reject `undefined`.\n\t\tif (timer === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// `.call(undefined, ...)` is needed for custom timers to avoid context issues\n\t\tcustomTimers.clearTimeout.call(undefined, timer);\n\t\ttimer = undefined;\n\t};\n\n\treturn cancelablePromise;\n}\n", "import pTimeout from 'p-timeout';\n\n// A filter function can stand in for the options. The options are copied, so a later change to the caller's object cannot reach the call.\nconst normalizeOptions = options => typeof options === 'function' ? {filter: options} : {...options};\n\n// A `count` or `limit`: a whole number of zero or more, or `Infinity`.\nconst isCount = value => value === Infinity || (Number.isSafeInteger(value) && value >= 0);\n\n// The removal method has to come from the same family as the one used to add, otherwise the listener is never detached.\nconst listenerMethodPairs = [\n\t['addEventListener', 'removeEventListener'],\n\t['on', 'off'],\n\t['addListener', 'removeListener'],\n];\n\nconst normalizeEmitter = emitter => {\n\tfor (const [addMethod, removeMethod] of listenerMethodPairs) {\n\t\tconst addListener = emitter?.[addMethod];\n\t\tconst removeListener = emitter?.[removeMethod];\n\n\t\tif (typeof addListener === 'function' && typeof removeListener === 'function') {\n\t\t\treturn {\n\t\t\t\taddListener: addListener.bind(emitter),\n\t\t\t\tremoveListener: removeListener.bind(emitter),\n\t\t\t};\n\t\t}\n\t}\n\n\tthrow new TypeError('Emitter is not compatible');\n};\n\n// Which handler serves each event name. A single name is a list of one. A name claimed by an earlier family keeps that handler, so the main event takes priority over `rejectionEvents`, which in turn takes priority over `resolutionEvents`. Registration and removal both walk the returned map, so they always agree, a repeated name gets one listener, and a later edit to the caller's arrays cannot reach them.\nconst listenerHandlers = families => {\n\tconst handlers = new Map();\n\n\tfor (const [names, handler] of families) {\n\t\tfor (const name of Array.isArray(names) ? names : [names]) {\n\t\t\tif (!handlers.has(name)) {\n\t\t\t\thandlers.set(name, handler);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn handlers;\n};\n\n// Attaches the abort handler first, so an emitter that fires the abort itself while a listener is being attached still reaches the caller. An emitter that hands over buffered events the moment a listener is attached can end the call part way through, and anything attached after that would never be removed, so attaching stops once the call is done. The call can also end before the emitter stores the listener, since Node's `EventEmitter` emits `newListener` first, so the cleanup misses that listener and it is removed here.\nconst attachListeners = ({addListener, removeListener, handlers, signal, abortHandler, isDone}) => {\n\tsignal?.addEventListener('abort', abortHandler, {once: true});\n\n\tfor (const [eventName, listener] of handlers) {\n\t\taddListener(eventName, listener);\n\n\t\tif (isDone()) {\n\t\t\tremoveListener(eventName, listener);\n\t\t\treturn;\n\t\t}\n\t}\n};\n\n// `once: true` only detaches the abort handler when the signal fires, so a call that ended another way has to remove it.\nconst detachListeners = ({removeListener, handlers, signal, abortHandler}) => {\n\tfor (const [eventName, listener] of handlers) {\n\t\tremoveListener(eventName, listener);\n\t}\n\n\tsignal?.removeEventListener('abort', abortHandler);\n};\n\n// Filters run one after another, so that an asynchronous one cannot reorder the values or read a `limit` that belongs to a later event. A verdict or a failure that arrives once the call is done is dropped, since the outcome is already decided and a cancelled promise must never settle.\nconst createFilterQueue = (filter, isDone, onError) => {\n\tlet queue = Promise.resolve();\n\n\treturn (value, onVerdict) => {\n\t\tqueue = queue.then(async () => {\n\t\t\t// The call is over, so the filter could only produce a verdict that is discarded.\n\t\t\tif (isDone()) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet isAccepted;\n\t\t\t// The filter's return value is a verdict rather than a rejection, so it is checked instead of caught.\n\t\t\ttry {\n\t\t\t\tisAccepted = filter ? await filter(value) : true;\n\t\t\t} catch (error) {\n\t\t\t\tif (!isDone()) {\n\t\t\t\t\tonError(error);\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDone()) {\n\t\t\t\tonVerdict(isAccepted);\n\t\t\t}\n\t\t});\n\t};\n};\n\nexport function pEventMultiple(emitter, event, options) {\n\t// The setup below can throw before `cancel` is assigned, and the returned promise documents a `.cancel()` method, so it starts out as a no-op.\n\tlet cancel = () => {};\n\t// Set by `cancel()`, which every path that stops listening runs, so an event still going through an asynchronous `filter` can tell that its result is no longer wanted.\n\tlet isDone = false;\n\tlet deadlineTimer;\n\tconst returnValue = new Promise((resolve, reject) => {\n\t\toptions = normalizeOptions(options);\n\n\t\t// Held in a local so the filter is called on its own, and `this` inside it is not the options object the library works from.\n\t\tconst {filter} = options;\n\n\t\tif (!isCount(options.count)) {\n\t\t\tthrow new TypeError('The `count` option should be at least 0 or more');\n\t\t}\n\n\t\t// Checked here, before anything is attached, because `p-timeout` rejects an invalid deadline without cancelling this promise, which would leave the listeners attached.\n\t\tif (typeof options.timeout === 'number'\n\t\t\t&& !(options.timeout > 0)) {\n\t\t\tthrow new TypeError(`Expected the \\`timeout\\` option to be a positive number, got \\`${options.timeout}\\``);\n\t\t}\n\n\t\toptions.signal?.throwIfAborted();\n\n\t\tconst {addListener, removeListener} = normalizeEmitter(emitter);\n\n\t\t// A count of zero is already satisfied, so it must not wait for an event or leave a listener behind.\n\t\tif (options.count === 0) {\n\t\t\tresolve([]);\n\t\t\treturn;\n\t\t}\n\n\t\tconst items = [];\n\n\t\t// The reason is a single value, so it must not be wrapped the way a rejection event's arguments are.\n\t\tconst rejectWithReason = reason => {\n\t\t\tcancel();\n\t\t\treject(reason);\n\t\t};\n\n\t\tconst queueFilter = createFilterQueue(filter, () => isDone, rejectWithReason);\n\n\t\tconst acceptItem = value => {\n\t\t\titems.push(value);\n\n\t\t\tif (options.count !== items.length) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcancel();\n\t\t\tresolve(items);\n\t\t};\n\n\t\tconst onItem = (...arguments_) => {\n\t\t\t// The promise is already settled, so the array the caller holds must not keep growing. An emitter can still call a listener it removed during the same emit.\n\t\t\tif (isDone) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\n\t\t\tif (!filter) {\n\t\t\t\tacceptItem(value);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tqueueFilter(value, isAccepted => {\n\t\t\t\tif (isAccepted) {\n\t\t\t\t\tacceptItem(value);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\n\t\tconst rejectHandler = (...arguments_) => {\n\t\t\trejectWithReason(options.rejectionMultiArgs ? arguments_ : arguments_[0]);\n\t\t};\n\n\t\tconst abortHandler = () => {\n\t\t\trejectWithReason(options.signal.reason);\n\t\t};\n\n\t\t// Allow multiple events. The main event takes priority over a rejection event, as documented. An explicit `undefined` reads as \"not set\" rather than overriding the default, so a forwarded partial options object does not end up listening for the literal name `\"undefined\"`.\n\t\tconst listening = {\n\t\t\taddListener,\n\t\t\tremoveListener,\n\t\t\thandlers: listenerHandlers([[event, onItem], [options.rejectionEvents ?? ['error'], rejectHandler]]),\n\t\t\tsignal: options.signal,\n\t\t\tabortHandler,\n\t\t\tisDone: () => isDone,\n\t\t};\n\n\t\tcancel = () => {\n\t\t\tisDone = true;\n\n\t\t\t// Stopping the listening on any path has to release the deadline too, or it would hold the event loop open for a timer that can no longer do anything.\n\t\t\tclearTimeout(deadlineTimer);\n\n\t\t\tdetachListeners(listening);\n\t\t};\n\n\t\tattachListeners(listening);\n\n\t\t// A call that settled above was already cleaned up by `cancel()`, abort handler included.\n\t\tif (isDone || !options.resolveImmediately) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The promise is fulfilled right away, and `pTimeout` clears its timer as soon as the promise settles, so the deadline is tracked here instead. An infinite deadline has nothing to wait for, and neither does one above `2 ** 31 - 1` milliseconds, the largest delay `setTimeout` can represent. `setTimeout` would clamp either to 1 millisecond. This matches `pTimeout`.\n\t\tif (Number.isFinite(options.timeout) && options.timeout <= (2 ** 31) - 1) {\n\t\t\tdeadlineTimer = setTimeout(cancel, options.timeout);\n\t\t}\n\n\t\tresolve(items);\n\t});\n\n\treturnValue.cancel = cancel;\n\n\t// An invalid `timeout` already rejected the promise above, so it must not reach `pTimeout`.\n\tif (typeof options.timeout === 'number' && options.timeout > 0 && !options.resolveImmediately) {\n\t\tconst timeout = pTimeout(returnValue, {milliseconds: options.timeout});\n\t\t// When cancelling, also clear the timeout timer\n\t\ttimeout.cancel = () => {\n\t\t\tcancel();\n\t\t\ttimeout.clear();\n\t\t};\n\n\t\treturn timeout;\n\t}\n\n\treturn returnValue;\n}\n\nexport function pEvent(emitter, event, options) {\n\tconst arrayPromise = pEventMultiple(emitter, event, {\n\t\t...normalizeOptions(options),\n\t\tcount: 1,\n\t\tresolveImmediately: false,\n\t});\n\tconst promise = arrayPromise.then(array => array[0]);\n\tpromise.cancel = arrayPromise.cancel;\n\n\treturn promise;\n}\n\nexport function pEventIterator(emitter, event, options) {\n\toptions = normalizeOptions(options);\n\n\t// Held in a local so the filter is called on its own, and `this` inside it is not the options object the library works from.\n\tconst {filter} = options;\n\n\t// An explicit `undefined` reads as \"not set\" rather than overriding the default.\n\tconst limit = options.limit ?? Infinity;\n\tif (!isCount(limit)) {\n\t\tthrow new TypeError('The `limit` option should be a non-negative integer or Infinity');\n\t}\n\n\toptions.signal?.throwIfAborted();\n\n\tconst {addListener, removeListener} = normalizeEmitter(emitter);\n\n\tlet isDone = false;\n\t// Set as soon as a resolution event arrives, so no further value can enter the iteration while the queued filters drain.\n\tlet isResolving = false;\n\t// Wrapped as `{reason}`, so a rejection whose reason is `undefined` still counts as one.\n\tlet pendingError;\n\t// The payload of the resolution event, held until a read reports the iteration as done. See `cancel()`.\n\tlet resolutionValue;\n\tconst nextQueue = [];\n\tconst valueQueue = [];\n\tlet eventCount = 0;\n\n\tconst cancel = finalValue => {\n\t\tisDone = true;\n\t\tdetachListeners(listening);\n\n\t\t// The first read that reports the iteration as done carries the payload of the resolution event, the same way a generator's first `{done: true}` result carries its return value. Published versions handed it over like this, and the async iterator protocol allows it, so `next()` callers can still read a final payload such as an exit code. Every read after that one gets `undefined`, as the protocol requires. Without a pending read, the payload waits in `resolutionValue` for the next one.\n\t\tresolutionValue = finalValue;\n\t\tfor (const {resolve} of nextQueue.splice(0)) {\n\t\t\tresolve({done: true, value: resolutionValue});\n\t\t\tresolutionValue = undefined;\n\t\t}\n\t};\n\n\tconst rejectIterator = reason => {\n\t\tif (isDone) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (nextQueue.length > 0) {\n\t\t\tnextQueue.shift().reject(reason);\n\t\t} else {\n\t\t\tpendingError = {reason};\n\t\t}\n\n\t\tcancel();\n\t};\n\n\tconst queueFilter = createFilterQueue(filter, () => isDone, rejectIterator);\n\n\tconst acceptValue = value => {\n\t\tif (nextQueue.length > 0) {\n\t\t\tnextQueue.shift().resolve({done: false, value});\n\t\t} else {\n\t\t\tvalueQueue.push(value);\n\t\t}\n\t};\n\n\tconst valueHandler = (...arguments_) => {\n\t\t// The iteration is over, so a value that is still arriving must not be added to the queue. A resolution event ends the iteration, so a value emitted after it does not belong to it, not even in the same burst before the queued filters have drained.\n\t\tif (isDone || isResolving) {\n\t\t\treturn;\n\t\t}\n\n\t\teventCount++;\n\t\tconst isLastEvent = eventCount === limit;\n\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\n\t\tconst onVerdict = isAccepted => {\n\t\t\tif (isAccepted) {\n\t\t\t\tacceptValue(value);\n\t\t\t}\n\n\t\t\t// A rejected value still counts towards the limit, so the iterator ends either way.\n\t\t\tif (isLastEvent) {\n\t\t\t\tcancel();\n\t\t\t}\n\t\t};\n\n\t\tif (filter) {\n\t\t\tqueueFilter(value, onVerdict);\n\t\t} else {\n\t\t\tonVerdict(true);\n\t\t}\n\t};\n\n\tconst rejectHandler = (...arguments_) => {\n\t\trejectIterator(options.rejectionMultiArgs ? arguments_ : arguments_[0]);\n\t};\n\n\tconst resolveHandler = (...arguments_) => {\n\t\tconst value = options.multiArgs ? arguments_ : arguments_[0];\n\t\tisResolving = true;\n\n\t\t// The event ends the iteration, so its payload is never yielded as a value. It queues behind the value filters, even without a filter, so that a value which was already received still gets in. The event ends the iteration either way: the verdict only decides whether its payload is handed over as the final value, which is how published versions behaved, and a failure in the filter rejects the iteration.\n\t\tqueueFilter(value, isAccepted => {\n\t\t\t// `cancel()` settles any pending read, and the first one gets the payload.\n\t\t\tcancel(isAccepted ? value : undefined);\n\t\t});\n\t};\n\n\t// The reason is a single value, so it must not be wrapped the way a rejection event's arguments are.\n\tconst abortHandler = () => {\n\t\trejectIterator(options.signal.reason);\n\t};\n\n\t// Allow multiple events. A name that is already handled as a value must not also reject or end the iteration, and a rejection wins over a resolution, so a name never ends up with two handlers. An explicit `undefined` reads as \"not set\" rather than overriding the default, so a forwarded partial options object does not end up listening for the literal name `\"undefined\"`.\n\tconst listening = {\n\t\taddListener,\n\t\tremoveListener,\n\t\thandlers: listenerHandlers([\n\t\t\t[event, valueHandler],\n\t\t\t[options.rejectionEvents ?? ['error'], rejectHandler],\n\t\t\t[options.resolutionEvents ?? [], resolveHandler],\n\t\t]),\n\t\tsignal: options.signal,\n\t\tabortHandler,\n\t\tisDone: () => isDone,\n\t};\n\n\tconst iterator = {\n\t\t[Symbol.asyncIterator]() {\n\t\t\treturn this;\n\t\t},\n\t\tasync next() {\n\t\t\tif (valueQueue.length > 0) {\n\t\t\t\t// A value that was already received is always handed over, so the iteration is never reported done while one is still buffered.\n\t\t\t\treturn {\n\t\t\t\t\tdone: false,\n\t\t\t\t\tvalue: valueQueue.shift(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (pendingError) {\n\t\t\t\tconst {reason} = pendingError;\n\t\t\t\tpendingError = undefined;\n\t\t\t\tthrow reason;\n\t\t\t}\n\n\t\t\tif (isDone) {\n\t\t\t\t// Handed over once, so only the first read after the buffered values gets the payload of the resolution event.\n\t\t\t\tconst value = resolutionValue;\n\t\t\t\tresolutionValue = undefined;\n\n\t\t\t\treturn {\n\t\t\t\t\tdone: true,\n\t\t\t\t\tvalue,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tnextQueue.push({resolve, reject});\n\t\t\t});\n\t\t},\n\t\tasync return(value) {\n\t\t\t// Without a final value, `cancel()` also drops the payload of a resolution event that was not read yet.\n\t\t\tcancel();\n\n\t\t\t// The consumer ended the iteration, so nothing that is still buffered can come out of it.\n\t\t\tvalueQueue.length = 0;\n\t\t\tpendingError = undefined;\n\n\t\t\treturn {\n\t\t\t\tdone: true,\n\t\t\t\tvalue,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Return an empty async iterator to avoid any further cost. A limit of zero is already reached, so nothing is attached, and `cancel()` has nothing to remove.\n\tif (limit === 0) {\n\t\tisDone = true;\n\t\tlistening.handlers.clear();\n\t\treturn iterator;\n\t}\n\n\tattachListeners(listening);\n\n\t// Ending above runs `cancel()`, which already took the abort handler off, so there is nothing left here.\n\treturn iterator;\n}\n\nexport {TimeoutError} from 'p-timeout';\n", "import type { RateLimiterResult } from './rate-limiter.ts'\n\n/**\n * A rate limit was hit\n */\nexport class RateLimitError extends Error {\n remainingPoints: number\n msBeforeNext: number\n consumedPoints: number\n isFirstInDuration: boolean\n\n constructor (message = 'Rate limit exceeded', props: RateLimiterResult) {\n super(message)\n this.name = 'RateLimitError'\n this.remainingPoints = props.remainingPoints\n this.msBeforeNext = props.msBeforeNext\n this.consumedPoints = props.consumedPoints\n this.isFirstInDuration = props.isFirstInDuration\n }\n}\n\nexport class QueueFullError extends Error {\n static name = 'QueueFullError'\n\n constructor (message: string = 'The queue was full') {\n super(message)\n this.name = 'QueueFullError'\n }\n}\n\nexport class UnexpectedEOFError extends Error {\n static name = 'UnexpectedEOFError'\n name = 'UnexpectedEOFError'\n}\n\nexport class MaxEarlyStreamsError extends Error {\n static name = 'MaxEarlyStreamsError'\n name = 'MaxEarlyStreamsError'\n}\n\nexport class StreamClosedError extends Error {\n static name = 'StreamClosedError'\n name = 'StreamClosedError'\n}\n", "export const PROTOCOL_VERSION = '1.0.0'\nexport const PROTOCOL_NAME = 'echo'\n", "import { ProtocolError, setMaxListeners, TimeoutError } from '@libp2p/interface'\nimport { UnexpectedEOFError } from '@libp2p/utils'\nimport { pEvent } from 'p-event'\nimport { Uint8ArrayList } from 'uint8arraylist'\nimport { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.ts'\nimport type { Echo as EchoInterface, EchoComponents, EchoInit } from './index.ts'\nimport type { DialProtocolOptions, DialTarget, Startable, Stream } from '@libp2p/interface'\n\n/**\n * A simple echo stream, any data received will be sent back to the sender\n */\nexport class Echo implements Startable, EchoInterface {\n public readonly protocol: string\n private readonly components: EchoComponents\n private started: boolean\n private readonly init: EchoInit\n private readonly timeout: number\n\n constructor (components: EchoComponents, init: EchoInit = {}) {\n this.started = false\n this.components = components\n this.protocol = `/${[init.protocolPrefix, PROTOCOL_NAME, PROTOCOL_VERSION].filter(Boolean).join('/')}`\n this.init = init\n this.timeout = init.timeout ?? 20_000\n }\n\n readonly [Symbol.toStringTag] = '@libp2p/echo'\n\n async start (): Promise<void> {\n await this.components.registrar.handle(this.protocol, this.onEcho.bind(this), {\n maxInboundStreams: this.init.maxInboundStreams,\n maxOutboundStreams: this.init.maxOutboundStreams,\n runOnLimitedConnection: this.init.runOnLimitedConnection\n })\n this.started = true\n }\n\n async stop (): Promise<void> {\n await this.components.registrar.unhandle(this.protocol)\n this.started = false\n }\n\n isStarted (): boolean {\n return this.started\n }\n\n async onEcho (stream: Stream): Promise<void> {\n const log = stream.log.newScope('echo')\n const start = Date.now()\n const signal = AbortSignal.timeout(this.timeout)\n setMaxListeners(Infinity, signal)\n let bytes = 0\n\n signal.addEventListener('abort', () => {\n stream.abort(new TimeoutError())\n })\n\n for await (const buf of stream) {\n bytes += buf.byteLength\n\n if (stream.status !== 'open') {\n log('stream status changed to %s', stream.status)\n break\n }\n\n if (!stream.send(buf)) {\n log('sent %d bytes, wait for drain', bytes)\n await pEvent(stream, 'drain', {\n rejectionEvents: [\n 'close'\n ],\n signal\n })\n } else {\n log('sent %d bytes', bytes)\n }\n }\n\n log('echoed %d bytes in %dms', bytes, Date.now() - start)\n\n await stream.close({\n signal\n })\n }\n\n async echo (peer: DialTarget, buf: Uint8Array | Uint8ArrayList, options?: DialProtocolOptions): Promise<Uint8ArrayList> {\n const stream = await this.components.connectionManager.openStream(peer, this.protocol, {\n ...this.init,\n ...options\n })\n\n const log = stream.log.newScope('echo')\n\n const received = new Uint8ArrayList()\n const output = Promise.withResolvers<Uint8ArrayList>()\n\n stream.addEventListener('message', (evt) => {\n received.append(evt.data)\n log('received %d/%d bytes', received.byteLength, buf.byteLength)\n })\n\n stream.addEventListener('close', (evt) => {\n if (evt.error != null) {\n output.reject(evt.error)\n }\n\n if (received.byteLength > buf.byteLength) {\n output.reject(new ProtocolError(`Overread: ${received.byteLength}/${buf.byteLength} bytes`))\n }\n\n if (received.byteLength < buf.byteLength) {\n output.reject(new UnexpectedEOFError(`Underread: ${received.byteLength}/${buf.byteLength} bytes`))\n }\n\n output.resolve(received)\n })\n\n log('sending %d bytes', buf.byteLength)\n stream.send(buf)\n\n await stream.close(options).catch(err => {\n output.reject(err)\n })\n\n return output.promise\n }\n}\n"],
|
|
5
|
+
"mappings": ";8bAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,UAAAE,KC8QM,IAAOC,EAAP,cAA6B,KAAK,CACtC,OAAO,KAAO,gBAEd,YAAaC,EAAU,iBAAgB,CACrC,MAAMA,CAAO,EACb,KAAK,KAAO,eACd,GAMWC,EAAP,cAA4B,KAAK,CACrC,OAAO,KAAO,eAEd,YAAaD,EAAU,YAAW,CAChC,MAAMA,CAAO,EACb,KAAK,KAAO,cACd,GC5RI,SAAUE,EAAOC,EAAe,EAAC,CACrC,OAAO,IAAI,WAAWA,CAAI,CAC5B,CAOM,SAAUC,EAAaD,EAAe,EAAC,CAC3C,OAAO,IAAI,WAAWA,CAAI,CAC5B,CCfA,SAASE,EAA4BC,EAAc,CACjD,OAAOA,GAAG,kBAAkB,WAC9B,CAMM,SAAUC,EAAcC,EAAe,CAC3C,GAAIH,EAA2BG,CAAG,EAChC,OAAOA,EAGT,IAAMF,EAAIE,EAAI,MAAK,EAEnB,OAAO,IAAI,WAAWF,EAAE,OAAQ,EAAGA,EAAE,UAAU,CACjD,CCVM,SAAUG,EAAQC,EAAsBC,EAAe,CACvDA,GAAU,OACZA,E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AA6B,CAC3F,IAAMT,EAAS,MAAM,KAAK,WAAW,kBAAkB,WAAWQ,EAAM,KAAK,SAAU,CACrF,GAAG,KAAK,KACR,GAAGC,EACJ,EAEKR,EAAMD,EAAO,IAAI,SAAS,MAAM,EAEhCU,EAAW,IAAIC,EACfC,EAAS,QAAQ,cAAa,EAEpC,OAAAZ,EAAO,iBAAiB,UAAYa,GAAO,CACzCH,EAAS,OAAOG,EAAI,IAAI,EACxBZ,EAAI,uBAAwBS,EAAS,WAAYJ,EAAI,UAAU,CACjE,CAAC,EAEDN,EAAO,iBAAiB,QAAUa,GAAO,CACnCA,EAAI,OAAS,MACfD,EAAO,OAAOC,EAAI,KAAK,EAGrBH,EAAS,WAAaJ,EAAI,YAC5BM,EAAO,OAAO,IAAIE,EAAc,aAAaJ,EAAS,UAAU,IAAIJ,EAAI,UAAU,QAAQ,CAAC,EAGzFI,EAAS,WAAaJ,EAAI,YAC5BM,EAAO,OAAO,IAAIG,EAAmB,cAAcL,EAAS,UAAU,IAAIJ,EAAI,UAAU,QAAQ,CAAC,EAGnGM,EAAO,QAAQF,CAAQ,CACzB,CAAC,EAEDT,EAAI,mBAAoBK,EAAI,UAAU,EACtCN,EAAO,KAAKM,CAAG,EAEf,MAAMN,EAAO,MAAMS,CAAO,EAAE,MAAMO,GAAM,CACtCJ,EAAO,OAAOI,CAAG,CACnB,CAAC,EAEMJ,EAAO,OAChB,GX1DI,SAAUK,GAAMC,EAAiB,CAAA,EAAE,CACvC,OAAQC,GAAe,IAAIC,EAAUD,EAAYD,CAAI,CACvD",
|
|
6
|
+
"names": ["index_exports", "__export", "echo", "ProtocolError", "message", "TimeoutError", "alloc", "size", "allocUnsafe", "isByteArrayWithArrayBuffer", "b", "asUint8Array", "buf", "concat", "arrays", "length", "acc", "curr", "output", "allocUnsafe", "offset", "arr", "asUint8Array", "equals", "a", "b", "i", "symbol", "findBufAndOffset", "bufs", "index", "offset", "buf", "bufEnd", "isUint8ArrayList", "value", "Uint8ArrayList", "_Uint8ArrayList", "data", "length", "chunk", "res", "i", "bytes", "beginInclusive", "endExclusive", "concat", "list", "bufStart", "sliceStartInBuf", "sliceEndsInBuf", "start", "search", "needle", "M", "radix", "rightmostPositions", "c", "j", "right", "lastIndex", "lastPatIndex", "skip", "char", "byteOffset", "allocUnsafe", "littleEndian", "alloc", "other", "equals", "acc", "curr", "TimeoutError", "_TimeoutError", "message", "options", "getAbortedReason", "signal", "maximumDelay", "getOptionsError", "milliseconds", "customTimers", "pTimeout", "promise", "fallback", "timer", "abortHandler", "cancelInput", "cancelablePromise", "resolve", "reject", "abort", "optionsError", "timeoutError", "error", "normalizeOptions", "options", "isCount", "value", "listenerMethodPairs", "normalizeEmitter", "emitter", "addMethod", "removeMethod", "addListener", "removeListener", "listenerHandlers", "families", "handlers", "names", "handler", "name", "attachListeners", "signal", "abortHandler", "isDone", "eventName", "listener", "detachListeners", "createFilterQueue", "filter", "onError", "queue", "onVerdict", "isAccepted", "error", "pEventMultiple", "event", "cancel", "deadlineTimer", "returnValue", "resolve", "reject", "items", "rejectWithReason", "reason", "queueFilter", "acceptItem", "onItem", "arguments_", "rejectHandler", "listening", "timeout", "pTimeout", "pEvent", "arrayPromise", "promise", "array", "UnexpectedEOFError", "PROTOCOL_VERSION", "PROTOCOL_NAME", "Echo", "components", "init", "PROTOCOL_NAME", "PROTOCOL_VERSION", "stream", "log", "start", "signal", "bytes", "TimeoutError", "buf", "pEvent", "peer", "options", "received", "Uint8ArrayList", "output", "evt", "ProtocolError", "UnexpectedEOFError", "err", "echo", "init", "components", "Echo"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/echo",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.19-848e26488",
|
|
4
4
|
"description": "Implementation of an Echo protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-echo#readme",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/interface": "
|
|
49
|
-
"@libp2p/interface-internal": "
|
|
50
|
-
"@libp2p/utils": "
|
|
48
|
+
"@libp2p/interface": "3.4.0-848e26488",
|
|
49
|
+
"@libp2p/interface-internal": "3.2.3-848e26488",
|
|
50
|
+
"@libp2p/utils": "7.4.6-848e26488",
|
|
51
51
|
"p-event": "^8.0.1",
|
|
52
52
|
"uint8arraylist": "^3.0.2"
|
|
53
53
|
},
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Echo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.Echo.html",
|
|
3
|
-
".:Echo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.Echo.html",
|
|
4
|
-
"EchoComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.EchoComponents.html",
|
|
5
|
-
".:EchoComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.EchoComponents.html",
|
|
6
|
-
"EchoInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.EchoInit.html",
|
|
7
|
-
".:EchoInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_echo.EchoInit.html",
|
|
8
|
-
"echo": "https://libp2p.github.io/js-libp2p/functions/_libp2p_echo.echo.html",
|
|
9
|
-
".:echo": "https://libp2p.github.io/js-libp2p/functions/_libp2p_echo.echo.html"
|
|
10
|
-
}
|