New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mercuryworkshop/bare-mux

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mercuryworkshop/bare-mux - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0

6

dist/client.d.ts
import { BareHeaders, BareTransport } from './baretypes';
import { WorkerConnection } from './connection';
import { BareWebSocket } from './websocket';
export declare function validProtocol(protocol: string): boolean;
export type WebSocketImpl = {
new (...args: ConstructorParameters<typeof WebSocket>): WebSocket;
};
/**

@@ -35,4 +33,4 @@ * A Response with additional properties.

constructor(worker?: string | Promise<MessagePort> | MessagePort);
createWebSocket(remote: string | URL, protocols?: string | string[] | undefined, webSocketImpl?: WebSocketImpl, requestHeaders?: BareHeaders, arrayBufferImpl?: ArrayBuffer): WebSocket;
createWebSocket(remote: string | URL, protocols?: string | string[] | undefined, __deprecated_donotuse_websocket?: any, requestHeaders?: BareHeaders): BareWebSocket;
fetch(url: string | URL, init?: RequestInit): Promise<BareResponseFetch>;
}

@@ -6,2 +6,3 @@ export * from './baretypes';

export { WebSocketFields } from "./snapshot";
export { BareWebSocket } from "./websocket";
export type * from './baretypes';

@@ -8,0 +9,0 @@ export type * from './client';

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BareMux={})}(this,(function(e){"use strict";const t=globalThis.fetch,s=globalThis.WebSocket,o=globalThis.Request,r=globalThis.Response,a=globalThis.SharedWorker,n=globalThis.localStorage,i=globalThis.navigator.serviceWorker,c={prototype:{send:s.prototype.send},CLOSED:s.CLOSED,CLOSING:s.CLOSING,CONNECTING:s.CONNECTING,OPEN:s.OPEN};async function l(){const e=(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).map((async e=>{const t=await function(e){let t=new MessageChannel;return new Promise((s=>{e.postMessage({type:"getPort",port:t.port2},[t.port2]),t.port1.onmessage=e=>{s(e.data)}}))}(e);return await h(t),t})),t=Promise.race([Promise.any(e),new Promise(((e,t)=>setTimeout(t,1e3,new TypeError("timeout"))))]);try{return await t}catch(e){if(e instanceof AggregateError)throw console.error("bare-mux: failed to get a bare-mux SharedWorker MessagePort as all clients returned an invalid MessagePort."),new Error("All clients returned an invalid MessagePort.");return console.warn("bare-mux: failed to get a bare-mux SharedWorker MessagePort within 1s, retrying"),await l()}}function h(e){const t=new MessageChannel,s=new Promise(((e,s)=>{t.port1.onmessage=t=>{"pong"===t.data.type&&e()},setTimeout(s,1500)}));return e.postMessage({message:{type:"ping"},port:t.port2},[t.port2]),s}function p(e,t){const s=new a(e,"bare-mux-worker");return t&&i.addEventListener("message",(t=>{if("getPort"===t.data.type&&t.data.port){console.debug("bare-mux: recieved request for port from sw");const s=new a(e,"bare-mux-worker");t.data.port.postMessage(s.port,[s.port])}})),s.port}let d=null;function u(){if(null===d){const e=new MessageChannel,t=new ReadableStream;let s;try{e.port1.postMessage(t,[t]),s=!0}catch(e){s=!1}return d=s,s}return d}class w{constructor(e){this.channel=new BroadcastChannel("bare-mux"),e instanceof MessagePort||e instanceof Promise?this.port=e:this.createChannel(e,!0)}createChannel(e,t){if(self.clients)this.port=l(),this.channel.onmessage=e=>{"refreshPort"===e.data.type&&(this.port=l())};else if(e&&a){if(!e.startsWith("/")&&!e.includes("://"))throw new Error("Invalid URL. Must be absolute or start at the root.");this.port=p(e,t),console.debug("bare-mux: setting localStorage bare-mux-path to",e),n["bare-mux-path"]=e}else{if(!a)throw new Error("Unable to get a channel to the SharedWorker.");{const e=n["bare-mux-path"];if(console.debug("bare-mux: got localStorage bare-mux-path:",e),!e)throw new Error("Unable to get bare-mux workerPath from localStorage.");this.port=p(e,t)}}}async sendMessage(e,t){this.port instanceof Promise&&(this.port=await this.port);try{await h(this.port)}catch{return console.warn("bare-mux: Failed to get a ping response from the worker within 1.5s. Assuming port is dead."),this.createChannel(),await this.sendMessage(e,t)}const s=new MessageChannel,o=[s.port2,...t||[]],r=new Promise(((e,t)=>{s.port1.onmessage=s=>{const o=s.data;"error"===o.type?t(o.error):e(o)}}));return this.port.postMessage({message:e,port:s.port2},o),await r}}class g extends EventTarget{constructor(e,t=[],s,o,r){super(),this.protocols=[],this.readyState=c.CONNECTING,this.binaryType="blob",this.onopen=null,this.onerror=null,this.onmessage=null,this.onclose=null,this.url=e.toString(),this.protocols=t;const a=e=>{this.readyState=c.OPEN,this.protocols=e,this.meta={headers:{"sec-websocket-protocol":e}};const t=new Event("open");this.dispatchEvent(t),this.onopen&&this.onopen(t)},n=async e=>{"string"==typeof e||("byteLength"in e?"blob"===this.binaryType?e=new Blob([e]):Object.setPrototypeOf(e,r):"arrayBuffer"in e&&"arraybuffer"===this.binaryType&&(e=await e.arrayBuffer(),Object.setPrototypeOf(e,r)));const t=new MessageEvent("message",{data:e});this.dispatchEvent(t),this.onmessage&&this.onmessage(t)},i=(e,t)=>{this.readyState=c.CLOSED;const s=new CloseEvent("close",{code:e,reason:t});this.dispatchEvent(s),this.onclose&&this.onclose(s)},l=()=>{this.readyState=c.CLOSED;const e=new Event("error");this.dispatchEvent(e),this.onerror&&this.onerror(e)};this.channel=new MessageChannel,this.channel.port1.onmessage=e=>{"open"===e.data.type?a(e.data.args[0]):"message"===e.data.type?n(e.data.args[0]):"close"===e.data.type?i(e.data.args[0],e.data.args[1]):"error"===e.data.type&&l()},s.sendMessage({type:"websocket",websocket:{url:e.toString(),origin:origin,protocols:t,requestHeaders:o,channel:this.channel.port2}},[this.channel.port2])}send(...e){if(this.readyState===c.CONNECTING)throw new DOMException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.");let t=e[0];t.buffer&&(t=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)),this.channel.port1.postMessage({type:"data",data:t},t instanceof ArrayBuffer?[t]:[])}close(e,t){this.readyState=c.CLOSING,this.channel.port1.postMessage({type:"close",closeCode:e,closeReason:t})}get bufferedAmount(){return 0}get protocol(){return Array.isArray(this.protocols)?this.protocols[0]||"":this.protocols||""}get extensions(){return""}}function f(e,t,s){console.error(`error while processing '${s}': `,t),e.postMessage({type:"error",error:t})}g.prototype.CONNECTING=c.CONNECTING,g.prototype.OPEN=c.OPEN,g.prototype.CLOSING=c.CLOSING,g.prototype.CLOSED=c.CLOSED;function y(e){for(let t=0;t<e.length;t++){const s=e[t];if(!"!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~".includes(s))return!1}return!0}const b=["ws:","wss:"],m=[101,204,205,304],M=[301,302,303,307,308];class C{constructor(e){this.worker=new w(e)}createWebSocket(e,t=[],o,r,a){try{e=new URL(e)}catch(t){throw new DOMException(`Faiiled to construct 'WebSocket': The URL '${e}' is invalid.`)}if(!b.includes(e.protocol))throw new DOMException(`Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${e.protocol}' is not allowed.`);Array.isArray(t)||(t=[t]),t=t.map(String);for(const e of t)if(!y(e))throw new DOMException(`Failed to construct 'WebSocket': The subprotocol '${e}' is invalid.`);a=a||(o||s).constructor.constructor("return ArrayBuffer")().prototype,(r=r||{}).Host=new URL(e).host,r.Pragma="no-cache",r["Cache-Control"]="no-cache",r.Upgrade="websocket",r.Connection="Upgrade";return new g(e,t,this.worker,r,a)}async fetch(e,s){const a=new o(e,s),n=s?.headers||a.headers,i=n instanceof Headers?Object.fromEntries(n):n,c=a.body;let l=new URL(a.url);if(l.protocol.startsWith("blob:")){const e=await t(l),s=new r(e.body,e);return s.rawHeaders=Object.fromEntries(e.headers),s.rawResponse=e,s}for(let e=0;;e++){"host"in i?i.host=l.host:i.Host=l.host;let t=(await this.worker.sendMessage({type:"fetch",fetch:{remote:l.toString(),method:a.method,headers:i,body:c||void 0}},c?[c]:[])).fetch,o=new r(m.includes(t.status)?void 0:t.body,{headers:new Headers(t.headers),status:t.status,statusText:t.statusText});o.rawHeaders=t.headers,o.rawResponse=new r(t.body),o.finalURL=l.toString();const n=s?.redirect||a.redirect;if(!M.includes(o.status))return o;switch(n){case"follow":{const t=o.headers.get("location");if(20>e&&null!==t){l=new URL(t,l);continue}throw new TypeError("Failed to fetch")}case"error":throw new TypeError("Failed to fetch");case"manual":return o}}}}e.BareClient=C,e.BareMuxConnection=class{constructor(e){this.worker=new w(e)}async getTransport(){return(await this.worker.sendMessage({type:"get"})).name}async setTransport(e,t,s){await this.setManualTransport(`\n\t\t\tconst { default: BareTransport } = await import("${e}");\n\t\t\treturn [BareTransport, "${e}"];\n\t\t`,t,s)}async setManualTransport(e,t,s){if("bare-mux-remote"===e)throw new Error("Use setRemoteTransport.");await this.worker.sendMessage({type:"set",client:{function:e,args:t}},s)}async setRemoteTransport(e,t){const s=new MessageChannel;s.port1.onmessage=async t=>{const s=t.data.port,o=t.data.message;if("fetch"===o.type)try{e.ready||await e.init(),await async function(e,t,s){const o=await s.request(new URL(e.fetch.remote),e.fetch.method,e.fetch.body,e.fetch.headers,null);if(!u()&&o.body instanceof ReadableStream){const e=new r(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?t.postMessage({type:"fetch",fetch:o},[o.body]):t.postMessage({type:"fetch",fetch:o})}(o,s,e)}catch(e){f(s,e,"fetch")}else if("websocket"===o.type)try{e.ready||await e.init(),await async function(e,t,s){const[o,r]=s.connect(new URL(e.websocket.url),e.websocket.origin,e.websocket.protocols,e.websocket.requestHeaders,(t=>{e.websocket.channel.postMessage({type:"open",args:[t]})}),(t=>{t instanceof ArrayBuffer?e.websocket.channel.postMessage({type:"message",args:[t]},[t]):e.websocket.channel.postMessage({type:"message",args:[t]})}),((t,s)=>{e.websocket.channel.postMessage({type:"close",args:[t,s]})}),(t=>{e.websocket.channel.postMessage({type:"error",args:[t]})}));e.websocket.channel.onmessage=e=>{"data"===e.data.type?o(e.data.data):"close"===e.data.type&&r(e.data.closeCode,e.data.closeReason)},t.postMessage({type:"websocket"})}(o,s,e)}catch(e){f(s,e,"websocket")}},await this.worker.sendMessage({type:"set",client:{function:"bare-mux-remote",args:[s.port2,t]}},[s.port2])}getInnerPort(){return this.worker.port}},e.WebSocketFields=c,e.WorkerConnection=w,e.browserSupportsTransferringStreams=u,e.default=C,e.maxRedirects=20,e.validProtocol=y,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BareMux={})}(this,(function(e){"use strict";const t=globalThis.fetch,r=globalThis.localStorage,o=globalThis.navigator.serviceWorker,s=MessagePort.prototype.postMessage,a={prototype:{send:WebSocket.prototype.send},CLOSED:WebSocket.CLOSED,CLOSING:WebSocket.CLOSING,CONNECTING:WebSocket.CONNECTING,OPEN:WebSocket.OPEN};async function n(){const e=(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).map((async e=>{const t=await function(e){let t=new MessageChannel;return new Promise((r=>{e.postMessage({type:"getPort",port:t.port2},[t.port2]),t.port1.onmessage=e=>{r(e.data)}}))}(e);return await c(t),t})),t=Promise.race([Promise.any(e),new Promise(((e,t)=>setTimeout(t,1e3,new TypeError("timeout"))))]);try{return await t}catch(e){if(e instanceof AggregateError)throw console.error("bare-mux: failed to get a bare-mux SharedWorker MessagePort as all clients returned an invalid MessagePort."),new Error("All clients returned an invalid MessagePort.");return console.warn("bare-mux: failed to get a bare-mux SharedWorker MessagePort within 1s, retrying"),await n()}}function c(e){const t=new MessageChannel,r=new Promise(((e,r)=>{t.port1.onmessage=t=>{"pong"===t.data.type&&e()},setTimeout(r,1500)}));return s.call(e,{message:{type:"ping"},port:t.port2},[t.port2]),r}function i(e,t){const r=new SharedWorker(e,"bare-mux-worker");return t&&o.addEventListener("message",(t=>{if("getPort"===t.data.type&&t.data.port){console.debug("bare-mux: recieved request for port from sw");const r=new SharedWorker(e,"bare-mux-worker");s.call(t.data.port,r.port,[r.port])}})),r.port}let l=null;function h(){if(null===l){const e=new MessageChannel,t=new ReadableStream;let r;try{s.call(e.port1,t,[t]),r=!0}catch(e){r=!1}return l=r,r}return l}class d{constructor(e){this.channel=new BroadcastChannel("bare-mux"),e instanceof MessagePort||e instanceof Promise?this.port=e:this.createChannel(e,!0)}createChannel(e,t){if(self.clients)this.port=n(),this.channel.onmessage=e=>{"refreshPort"===e.data.type&&(this.port=n())};else if(e&&SharedWorker){if(!e.startsWith("/")&&!e.includes("://"))throw new Error("Invalid URL. Must be absolute or start at the root.");this.port=i(e,t),console.debug("bare-mux: setting localStorage bare-mux-path to",e),r["bare-mux-path"]=e}else{if(!SharedWorker)throw new Error("Unable to get a channel to the SharedWorker.");{const e=r["bare-mux-path"];if(console.debug("bare-mux: got localStorage bare-mux-path:",e),!e)throw new Error("Unable to get bare-mux workerPath from localStorage.");this.port=i(e,t)}}}async sendMessage(e,t){this.port instanceof Promise&&(this.port=await this.port);try{await c(this.port)}catch{return console.warn("bare-mux: Failed to get a ping response from the worker within 1.5s. Assuming port is dead."),this.createChannel(),await this.sendMessage(e,t)}const r=new MessageChannel,o=[r.port2,...t||[]],a=new Promise(((e,t)=>{r.port1.onmessage=r=>{const o=r.data;"error"===o.type?t(o.error):e(o)}}));return s.call(this.port,{message:e,port:r.port2},o),await a}}class p extends EventTarget{constructor(e,t=[],r,o){super(),this.protocols=t,this.readyState=a.CONNECTING,this.url=e.toString(),this.protocols=t;const s=e=>{this.protocols=e,this.readyState=a.OPEN;const t=new Event("open");this.dispatchEvent(t)},n=async e=>{const t=new MessageEvent("message",{data:e});this.dispatchEvent(t)},c=(e,t)=>{this.readyState=a.CLOSED;const r=new CloseEvent("close",{code:e,reason:t});this.dispatchEvent(r)},i=()=>{this.readyState=a.CLOSED;const e=new Event("error");this.dispatchEvent(e)};this.channel=new MessageChannel,this.channel.port1.onmessage=e=>{"open"===e.data.type?s(e.data.args[0]):"message"===e.data.type?n(e.data.args[0]):"close"===e.data.type?c(e.data.args[0],e.data.args[1]):"error"===e.data.type&&i()},r.sendMessage({type:"websocket",websocket:{url:e.toString(),origin:origin,protocols:t,requestHeaders:o,channel:this.channel.port2}},[this.channel.port2])}send(...e){if(this.readyState===a.CONNECTING)throw new DOMException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.");let t=e[0];t.buffer&&(t=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)),s.call(this.channel.port1,{type:"data",data:t},t instanceof ArrayBuffer?[t]:[])}close(e,t){s.call(this.channel.port1,{type:"close",closeCode:e,closeReason:t})}}function w(e,t,r){console.error(`error while processing '${r}': `,t),e.postMessage({type:"error",error:t})}function u(e){for(let t=0;t<e.length;t++){const r=e[t];if(!"!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~".includes(r))return!1}return!0}const f=["ws:","wss:"],g=[101,204,205,304],y=[301,302,303,307,308];class b{constructor(e){this.worker=new d(e)}createWebSocket(e,t=[],r,o){try{e=new URL(e)}catch(t){throw new DOMException(`Faiiled to construct 'WebSocket': The URL '${e}' is invalid.`)}if(!f.includes(e.protocol))throw new DOMException(`Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${e.protocol}' is not allowed.`);Array.isArray(t)||(t=[t]),t=t.map(String);for(const e of t)if(!u(e))throw new DOMException(`Failed to construct 'WebSocket': The subprotocol '${e}' is invalid.`);(o=o||{}).Host=new URL(e).host,o.Pragma="no-cache",o["Cache-Control"]="no-cache",o.Upgrade="websocket",o.Connection="Upgrade";return new p(e,t,this.worker,o)}async fetch(e,r){const o=new Request(e,r),s=r?.headers||o.headers,a=s instanceof Headers?Object.fromEntries(s):s,n=o.body;let c=new URL(o.url);if(c.protocol.startsWith("blob:")){const e=await t(c),r=new Response(e.body,e);return r.rawHeaders=Object.fromEntries(e.headers),r.rawResponse=e,r}for(let e=0;;e++){"host"in a?a.host=c.host:a.Host=c.host;let t=(await this.worker.sendMessage({type:"fetch",fetch:{remote:c.toString(),method:o.method,headers:a,body:n||void 0}},n?[n]:[])).fetch,s=new Response(g.includes(t.status)?void 0:t.body,{headers:new Headers(t.headers),status:t.status,statusText:t.statusText});s.rawHeaders=t.headers,s.rawResponse=new Response(t.body),s.finalURL=c.toString();const i=r?.redirect||o.redirect;if(!y.includes(s.status))return s;switch(i){case"follow":{const t=s.headers.get("location");if(20>e&&null!==t){c=new URL(t,c);continue}throw new TypeError("Failed to fetch")}case"error":throw new TypeError("Failed to fetch");case"manual":return s}}}}console.debug("bare-mux: running v2.1.0"),e.BareClient=b,e.BareMuxConnection=class{constructor(e){this.worker=new d(e)}async getTransport(){return(await this.worker.sendMessage({type:"get"})).name}async setTransport(e,t,r){await this.setManualTransport(`\n\t\t\tconst { default: BareTransport } = await import("${e}");\n\t\t\treturn [BareTransport, "${e}"];\n\t\t`,t,r)}async setManualTransport(e,t,r){if("bare-mux-remote"===e)throw new Error("Use setRemoteTransport.");await this.worker.sendMessage({type:"set",client:{function:e,args:t}},r)}async setRemoteTransport(e,t){const r=new MessageChannel;r.port1.onmessage=async t=>{const r=t.data.port,o=t.data.message;if("fetch"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const o=await r.request(new URL(e.fetch.remote),e.fetch.method,e.fetch.body,e.fetch.headers,null);if(!h()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?s.call(t,{type:"fetch",fetch:o},[o.body]):s.call(t,{type:"fetch",fetch:o})}(o,r,e)}catch(e){w(r,e,"fetch")}else if("websocket"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const[o,a]=r.connect(new URL(e.websocket.url),e.websocket.origin,e.websocket.protocols,e.websocket.requestHeaders,(t=>{s.call(e.websocket.channel,{type:"open",args:[t]})}),(t=>{t instanceof ArrayBuffer?s.call(e.websocket.channel,{type:"message",args:[t]},[t]):s.call(e.websocket.channel,{type:"message",args:[t]})}),((t,r)=>{s.call(e.websocket.channel,{type:"close",args:[t,r]})}),(t=>{s.call(e.websocket.channel,{type:"error",args:[t]})}));e.websocket.channel.onmessage=e=>{"data"===e.data.type?o(e.data.data):"close"===e.data.type&&a(e.data.closeCode,e.data.closeReason)},s.call(t,{type:"websocket"})}(o,r,e)}catch(e){w(r,e,"websocket")}},await this.worker.sendMessage({type:"set",client:{function:"bare-mux-remote",args:[r.port2,t]}},[r.port2])}getInnerPort(){return this.worker.port}},e.BareWebSocket=p,e.WebSocketFields=a,e.WorkerConnection=d,e.browserSupportsTransferringStreams=h,e.default=b,e.maxRedirects=20,e.validProtocol=u,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

export declare const fetch: typeof globalThis.fetch;
export declare const WebSocket: {
export declare const nativeFetch: typeof fetch;
export declare const nativeWebSocket: {
new (url: string | URL, protocols?: string | string[]): WebSocket;

@@ -10,28 +10,12 @@ prototype: WebSocket;

};
export declare const Request: {
new (input: RequestInfo | URL, init?: RequestInit): Request;
prototype: Request;
};
export declare const Response: {
new (body?: BodyInit | null, init?: ResponseInit): Response;
prototype: Response;
error(): Response;
json(data: any, init?: ResponseInit): Response;
redirect(url: string | URL, status?: number): Response;
};
export declare const XMLHttpRequest: {
new (): XMLHttpRequest;
prototype: XMLHttpRequest;
readonly UNSENT: 0;
readonly OPENED: 1;
readonly HEADERS_RECEIVED: 2;
readonly LOADING: 3;
readonly DONE: 4;
};
export declare const SharedWorker: {
export declare const nativeSharedWorker: {
new (scriptURL: string | URL, options?: string | WorkerOptions): SharedWorker;
prototype: SharedWorker;
};
export declare const localStorage: Storage;
export declare const serviceWorker: ServiceWorkerContainer;
export declare const nativeLocalStorage: Storage;
export declare const nativeServiceWorker: ServiceWorkerContainer;
export declare const nativePostMessage: {
(message: any, transfer: Transferable[]): void;
(message: any, options?: StructuredSerializeOptions): void;
};
export declare const WebSocketFields: {

@@ -38,0 +22,0 @@ prototype: {

import type { WorkerConnection } from "./connection";
import { BareHeaders } from "./baretypes";
export declare class BareWebSocket extends EventTarget {
protocols: string | string[] | undefined;
url: string;
protocols: string | string[] | undefined;
readyState: number;
binaryType: string;
onopen: any;
onerror: any;
onmessage: any;
onclose: any;
channel: MessageChannel;
constructor(remote: string | URL, protocols: string | string[] | undefined, worker: WorkerConnection, requestHeaders?: BareHeaders, arrayBufferImpl?: ArrayBuffer);
constructor(remote: string | URL, protocols: string | string[] | undefined, worker: WorkerConnection, requestHeaders?: BareHeaders);
send(...args: any[]): void;
close(code: any, reason: any): void;
get bufferedAmount(): number;
get protocol(): string;
get extensions(): string;
}

@@ -1,2 +0,2 @@

!function(){"use strict";const e=globalThis.Response;let t=null;function s(e,t,s){console.error(`error while processing '${s}': `,t),e.postMessage({type:"error",error:t})}async function a(s,a,n){const o=await n.request(new URL(s.fetch.remote),s.fetch.method,s.fetch.body,s.fetch.headers,null);if(!function(){if(null===t){const e=new MessageChannel,s=new ReadableStream;let a;try{e.port1.postMessage(s,[s]),a=!0}catch(e){a=!1}return t=a,a}return t}()&&o.body instanceof ReadableStream){const t=new e(o.body);o.body=await t.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?a.postMessage({type:"fetch",fetch:o},[o.body]):a.postMessage({type:"fetch",fetch:o})}let n=null,o="";function r(){return new Error("there are no bare clients",{cause:"No BareTransport was set. Try creating a BareMuxConnection and calling setTransport() or setManualTransport() on it before using BareClient."})}function c(e,t){const s=n;let a=[t];e.fetch?.body&&a.push(e.fetch.body),e.websocket?.channel&&a.push(e.websocket.channel),s.postMessage({message:e,port:t},a)}function i(e){e.onmessage=async e=>{const t=e.data.port,i=e.data.message;if("ping"===i.type)t.postMessage({type:"pong"});else if("set"===i.type)try{const e=async function(){}.constructor;if("bare-mux-remote"===i.client.function)n=i.client.args[0],o=`bare-mux-remote (${i.client.args[1]})`;else{const t=new e(i.client.function),[s,a]=await t();n=new s(...i.client.args),o=a}console.log("set transport to ",n,o),t.postMessage({type:"set"})}catch(e){s(t,e,"set")}else if("get"===i.type)t.postMessage({type:"get",name:o});else if("fetch"===i.type)try{if(!n)throw r();if(n instanceof MessagePort)return void c(i,t);n.ready||await n.init(),await a(i,t,n)}catch(e){s(t,e,"fetch")}else if("websocket"===i.type)try{if(!n)throw r();if(n instanceof MessagePort)return void c(i,t);n.ready||await n.init(),await async function(e,t,s){const[a,n]=s.connect(new URL(e.websocket.url),e.websocket.origin,e.websocket.protocols,e.websocket.requestHeaders,(t=>{e.websocket.channel.postMessage({type:"open",args:[t]})}),(t=>{t instanceof ArrayBuffer?e.websocket.channel.postMessage({type:"message",args:[t]},[t]):e.websocket.channel.postMessage({type:"message",args:[t]})}),((t,s)=>{e.websocket.channel.postMessage({type:"close",args:[t,s]})}),(t=>{e.websocket.channel.postMessage({type:"error",args:[t]})}));e.websocket.channel.onmessage=e=>{"data"===e.data.type?a(e.data.data):"close"===e.data.type&&n(e.data.closeCode,e.data.closeReason)},t.postMessage({type:"websocket"})}(i,t,n)}catch(e){s(t,e,"websocket")}}}new BroadcastChannel("bare-mux").postMessage({type:"refreshPort"}),self.onconnect=e=>{i(e.ports[0])}}();
!function(){"use strict";const e=MessagePort.prototype.postMessage;let t=null;function a(e,t,a){console.error(`error while processing '${a}': `,t),e.postMessage({type:"error",error:t})}async function n(a,n,s){const o=await s.request(new URL(a.fetch.remote),a.fetch.method,a.fetch.body,a.fetch.headers,null);if(!function(){if(null===t){const a=new MessageChannel,n=new ReadableStream;let s;try{e.call(a.port1,n,[n]),s=!0}catch(e){s=!1}return t=s,s}return t}()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?e.call(n,{type:"fetch",fetch:o},[o.body]):e.call(n,{type:"fetch",fetch:o})}let s=null,o="";function c(){return new Error("there are no bare clients",{cause:"No BareTransport was set. Try creating a BareMuxConnection and calling setTransport() or setManualTransport() on it before using BareClient."})}function r(t,a){const n=s;let o=[a];t.fetch?.body&&o.push(t.fetch.body),t.websocket?.channel&&o.push(t.websocket.channel),e.call(n,{message:t,port:a},o)}function l(t){t.onmessage=async t=>{const l=t.data.port,i=t.data.message;if("ping"===i.type)e.call(l,{type:"pong"});else if("set"===i.type)try{const t=async function(){}.constructor;if("bare-mux-remote"===i.client.function)s=i.client.args[0],o=`bare-mux-remote (${i.client.args[1]})`;else{const e=new t(i.client.function),[a,n]=await e();s=new a(...i.client.args),o=n}console.log("set transport to ",s,o),e.call(l,{type:"set"})}catch(e){a(l,e,"set")}else if("get"===i.type)l.postMessage({type:"get",name:o});else if("fetch"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await n(i,l,s)}catch(e){a(l,e,"fetch")}else if("websocket"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await async function(t,a,n){const[s,o]=n.connect(new URL(t.websocket.url),t.websocket.origin,t.websocket.protocols,t.websocket.requestHeaders,(a=>{e.call(t.websocket.channel,{type:"open",args:[a]})}),(a=>{a instanceof ArrayBuffer?e.call(t.websocket.channel,{type:"message",args:[a]},[a]):e.call(t.websocket.channel,{type:"message",args:[a]})}),((a,n)=>{e.call(t.websocket.channel,{type:"close",args:[a,n]})}),(a=>{e.call(t.websocket.channel,{type:"error",args:[a]})}));t.websocket.channel.onmessage=e=>{"data"===e.data.type?s(e.data.data):"close"===e.data.type&&o(e.data.closeCode,e.data.closeReason)},e.call(a,{type:"websocket"})}(i,l,s)}catch(e){a(l,e,"websocket")}}}new BroadcastChannel("bare-mux").postMessage({type:"refreshPort"}),self.onconnect=e=>{l(e.ports[0])},console.debug("bare-mux: running v2.1.0")}();
//# sourceMappingURL=worker.js.map
{
"name": "@mercuryworkshop/bare-mux",
"version": "2.0.9",
"version": "2.1.0",
"description": "",

@@ -25,3 +25,2 @@ "type": "module",

"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-replace": "^5.0.5",

@@ -28,0 +27,0 @@ "rollup": "^4.9.6",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc