Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miniflare/web-sockets

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/web-sockets - npm Package Compare versions

Comparing version 2.0.0-rc.3 to 2.0.0-rc.4

98

dist/src/index.js

@@ -0,20 +1,49 @@

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
// packages/web-sockets/src/index.ts
__export(exports, {
CloseEvent: () => CloseEvent,
ErrorEvent: () => ErrorEvent,
MessageEvent: () => MessageEvent,
WebSocket: () => WebSocket,
WebSocketPair: () => WebSocketPair,
WebSocketPlugin: () => WebSocketPlugin,
coupleWebSocket: () => coupleWebSocket,
upgradingFetch: () => upgradingFetch
});
// packages/web-sockets/src/fetch.ts
import { URL } from "url";
import {
Request,
Response,
fetch
} from "@miniflare/core";
import StandardWebSocket2 from "ws";
var import_url = __toModule(require("url"));
var import_core = __toModule(require("@miniflare/core"));
var import_ws2 = __toModule(require("ws"));
// packages/web-sockets/src/couple.ts
import { viewToBuffer } from "@miniflare/shared";
import StandardWebSocket from "ws";
var import_shared2 = __toModule(require("@miniflare/shared"));
var import_ws = __toModule(require("ws"));
// packages/web-sockets/src/websocket.ts
import assert from "assert";
import {
InputGatedEventTarget,
waitForOpenOutputGate
} from "@miniflare/shared";
var import_assert = __toModule(require("assert"));
var import_shared = __toModule(require("@miniflare/shared"));
var MessageEvent = class extends Event {

@@ -50,3 +79,3 @@ data;

var kClose = Symbol("kClose");
var WebSocket = class extends InputGatedEventTarget {
var WebSocket = class extends import_shared.InputGatedEventTarget {
#sendQueue = [];

@@ -82,3 +111,3 @@ [kPair];

async #dispatchMessageEvent(event) {
await waitForOpenOutputGate();
await (0, import_shared.waitForOpenOutputGate)();
const pair = this[kPair];

@@ -89,3 +118,3 @@ if (pair[kAccepted]) {

const sendQueue = pair.#sendQueue;
assert(sendQueue !== void 0);
(0, import_assert.default)(sendQueue !== void 0);
sendQueue.push(event);

@@ -116,3 +145,3 @@ }

async #dispatchCloseEvent(code, reason) {
await waitForOpenOutputGate();
await (0, import_shared.waitForOpenOutputGate)();
this.dispatchEvent(new CloseEvent("close", { code, reason }));

@@ -142,3 +171,3 @@ this[kPair].dispatchEvent(new CloseEvent("close", { code, reason }));

if (isBinary) {
pair.send(viewToBuffer(message));
pair.send((0, import_shared2.viewToBuffer)(message));
} else {

@@ -159,6 +188,6 @@ pair.send(message.toString());

pair.addEventListener("close", (e) => {
if (ws.readyState < StandardWebSocket.CLOSING)
if (ws.readyState < import_ws.default.CLOSING)
ws.close(e.code, e.reason);
});
if (ws.readyState === StandardWebSocket.CONNECTING) {
if (ws.readyState === import_ws.default.CONNECTING) {
await new Promise((resolve, reject) => {

@@ -178,3 +207,3 @@ ws.once("open", () => {

pair[kCoupled] = true;
if (ws.readyState >= StandardWebSocket.CLOSING) {
if (ws.readyState >= import_ws.default.CLOSING) {
throw new TypeError("Incoming WebSocket connection already closed.");

@@ -187,5 +216,5 @@ }

async function upgradingFetch(input, init) {
const request = new Request(input, init);
const request = new import_core.Request(input, init);
if (request.method === "GET" && request.headers.get("upgrade") === "websocket") {
const url = new URL(request.url);
const url = new import_url.URL(request.url);
if (url.protocol !== "http:" && url.protocol !== "https:") {

@@ -205,3 +234,3 @@ throw new TypeError(`Fetch API cannot load: ${url.toString()}.

}
const ws = new StandardWebSocket2(url, protocols, {
const ws = new import_ws2.default(url, protocols, {
followRedirects: request.redirect === "follow",

@@ -212,3 +241,3 @@ headers

await coupleWebSocket(ws, client);
return new Response(null, {
return new import_core.Response(null, {
status: 101,

@@ -218,12 +247,10 @@ webSocket: worker

}
return fetch(request);
return (0, import_core.fetch)(request);
}
// packages/web-sockets/src/plugin.ts
import {
createCompatFetch
} from "@miniflare/core";
import { Plugin } from "@miniflare/shared";
var import_core2 = __toModule(require("@miniflare/core"));
var import_shared3 = __toModule(require("@miniflare/shared"));
var constructError = "Failed to construct 'WebSocket': the constructor is not implemented.";
var WebSocketPlugin = class extends Plugin {
var WebSocketPlugin = class extends import_shared3.Plugin {
#webSockets = new Set();

@@ -233,3 +260,3 @@ #upgradingFetch;

super(ctx);
this.#upgradingFetch = createCompatFetch(ctx.log, ctx.compat, upgradingFetch);
this.#upgradingFetch = (0, import_core2.createCompatFetch)(ctx.log, ctx.compat, upgradingFetch);
}

@@ -271,3 +298,4 @@ setup() {

};
export {
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CloseEvent,

@@ -281,3 +309,3 @@ ErrorEvent,

upgradingFetch
};
});
//# sourceMappingURL=index.js.map
{
"name": "@miniflare/web-sockets",
"version": "2.0.0-rc.3",
"version": "2.0.0-rc.4",
"description": "WebSocket module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

@@ -14,4 +14,3 @@ "keywords": [

"license": "MIT",
"type": "module",
"exports": "./dist/src/index.js",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",

@@ -40,4 +39,4 @@ "files": [

"dependencies": {
"@miniflare/core": "2.0.0-rc.3",
"@miniflare/shared": "2.0.0-rc.3",
"@miniflare/core": "2.0.0-rc.4",
"@miniflare/shared": "2.0.0-rc.4",
"ws": "^8.2.2",

@@ -47,5 +46,5 @@ "undici": "^4.11.1"

"devDependencies": {
"@miniflare/shared-test": "2.0.0-rc.3",
"@miniflare/shared-test": "2.0.0-rc.4",
"@types/ws": "^8.2.0"
}
}

@@ -5,3 +5,3 @@ # `@miniflare/web-sockets`

fun, full-featured, fully-local simulator for Cloudflare Workers. See
[✉️ WebSockets](https://miniflare.dev/web-sockets.html) for more details.
[✉️ WebSockets](https://v2.miniflare.dev/core/web-sockets) for more details.

@@ -8,0 +8,0 @@ ## Example

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