Socket
Socket
Sign inDemoInstall

edge-runtime

Package Overview
Dependencies
12
Maintainers
1
Versions
111
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.4.0 to 2.4.1

6

dist/cli/repl.js

@@ -9,4 +9,4 @@ "use strict";

const repl_1 = __importDefault(require("repl"));
// import { homedir } from 'os'
// import { join } from 'path'
const os_1 = require("os");
const path_1 = require("path");
const edge_runtime_1 = require("../edge-runtime");

@@ -19,3 +19,3 @@ const format = (0, format_1.createFormat)();

exports.repl = repl;
repl.setupHistory('.edge_repl_history', () => { });
repl.setupHistory((0, path_1.join)((0, os_1.homedir)(), '.edge_runtime_repl_history'), () => { });
Object.getOwnPropertyNames(repl.context).forEach((mod) => delete repl.context[mod]);

@@ -22,0 +22,0 @@ const runtime = new edge_runtime_1.EdgeRuntime();

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

export { consumeUint8ArrayReadableStream, createHandler, runServer, } from './server';
export { consumeUint8ArrayReadableStream, pipeBodyStreamToResponse, createHandler, runServer, } from './server';
export { EdgeRuntime } from './edge-runtime';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EdgeRuntime = exports.runServer = exports.createHandler = exports.consumeUint8ArrayReadableStream = void 0;
exports.EdgeRuntime = exports.runServer = exports.createHandler = exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = void 0;
var server_1 = require("./server");
Object.defineProperty(exports, "consumeUint8ArrayReadableStream", { enumerable: true, get: function () { return server_1.consumeUint8ArrayReadableStream; } });
Object.defineProperty(exports, "pipeBodyStreamToResponse", { enumerable: true, get: function () { return server_1.pipeBodyStreamToResponse; } });
Object.defineProperty(exports, "createHandler", { enumerable: true, get: function () { return server_1.createHandler; } });

@@ -7,0 +8,0 @@ Object.defineProperty(exports, "runServer", { enumerable: true, get: function () { return server_1.runServer; } });

/// <reference types="node" />
import type { IncomingMessage } from 'http';
import type { IncomingMessage, ServerResponse } from 'http';
type BodyStream = ReadableStream<Uint8Array>;

@@ -27,2 +27,8 @@ /**

export declare function consumeUint8ArrayReadableStream(body?: ReadableStream): AsyncGenerator<Uint8Array, void, unknown>;
/**
* Pipes the chunks of a BodyStream into a Response. This optimizes for
* laziness, pauses reading if we experience back-pressure, and handles early
* disconnects by the client on the other end of the server response.
*/
export declare function pipeBodyStreamToResponse(body: BodyStream | null, res: ServerResponse): Promise<void>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.consumeUint8ArrayReadableStream = exports.getClonableBodyStream = void 0;
exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = exports.getClonableBodyStream = void 0;
const stream_1 = require("stream");

@@ -70,2 +70,6 @@ /**

}
function isUint8ArrayChunk(value) {
var _a;
return ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) == 'Uint8Array';
}
/**

@@ -77,3 +81,2 @@ * Creates an async iterator from a ReadableStream that ensures that every

async function* consumeUint8ArrayReadableStream(body) {
var _a;
const reader = body === null || body === void 0 ? void 0 : body.getReader();

@@ -86,3 +89,3 @@ if (reader) {

}
if (((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'Uint8Array') {
if (!isUint8ArrayChunk(value)) {
throw new TypeError('This ReadableStream did not return bytes.');

@@ -95,2 +98,55 @@ }

exports.consumeUint8ArrayReadableStream = consumeUint8ArrayReadableStream;
/**
* Pipes the chunks of a BodyStream into a Response. This optimizes for
* laziness, pauses reading if we experience back-pressure, and handles early
* disconnects by the client on the other end of the server response.
*/
async function pipeBodyStreamToResponse(body, res) {
if (!body)
return;
// If the client has already disconnected, then we don't need to pipe anything.
if (res.destroyed)
return body.cancel();
// When the server pushes more data than the client reads, then we need to
// wait for the client to catch up before writing more data. We register this
// generic handler once so that we don't incur constant register/unregister
// calls.
let drainResolve;
res.on('drain', () => drainResolve === null || drainResolve === void 0 ? void 0 : drainResolve());
// If the user aborts, then we'll receive a close event before the
// body closes. In that case, we want to end the streaming.
let open = true;
res.on('close', () => {
open = false;
drainResolve === null || drainResolve === void 0 ? void 0 : drainResolve();
});
const reader = body.getReader();
while (open) {
const { done, value } = await reader.read();
if (done)
break;
if (!isUint8ArrayChunk(value)) {
const error = new TypeError('This ReadableStream did not return bytes.');
reader.cancel(error);
throw error;
}
if (open) {
const bufferSpaceAvailable = res.write(value);
// If there's no more space in the buffer, then we need to wait on the
// client to read data before pushing again.
if (!bufferSpaceAvailable) {
await new Promise((res) => {
drainResolve = res;
});
}
}
// If the client disconnected early, then we need to cleanup the stream.
// This cannot be joined with the above if-statement, because the client may
// have disconnected while waiting for a drain signal.
if (!open) {
return reader.cancel();
}
}
}
exports.pipeBodyStreamToResponse = pipeBodyStreamToResponse;
//# sourceMappingURL=body-streams.js.map

@@ -8,3 +8,2 @@ "use strict";

const body_streams_1 = require("./body-streams");
const body_streams_2 = require("./body-streams");
const pretty_ms_1 = __importDefault(require("pretty-ms"));

@@ -27,3 +26,3 @@ const time_span_1 = __importDefault(require("time-span"));

const body = req.method !== 'GET' && req.method !== 'HEAD'
? (0, body_streams_2.getClonableBodyStream)(req, options.runtime.evaluate('Uint8Array'), options.runtime.context.TransformStream)
? (0, body_streams_1.getClonableBodyStream)(req, options.runtime.evaluate('Uint8Array'), options.runtime.context.TransformStream)
: undefined;

@@ -45,7 +44,3 @@ const response = await options.runtime.dispatchFetch(String(getURL(req)), {

}
if (response.body) {
for await (const chunk of (0, body_streams_1.consumeUint8ArrayReadableStream)(response.body)) {
res.write(chunk);
}
}
await (0, body_streams_1.pipeBodyStreamToResponse)(response.body, res);
const subject = `${req.socket.remoteAddress} ${req.method} ${req.url}`;

@@ -52,0 +47,0 @@ const time = `${(_a = (0, pretty_ms_1.default)(start())

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

export { consumeUint8ArrayReadableStream } from './body-streams';
export { consumeUint8ArrayReadableStream, pipeBodyStreamToResponse, } from './body-streams';
export { createHandler } from './create-handler';
export { runServer, EdgeRuntimeServer } from './run-server';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runServer = exports.createHandler = exports.consumeUint8ArrayReadableStream = void 0;
exports.runServer = exports.createHandler = exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = void 0;
var body_streams_1 = require("./body-streams");
Object.defineProperty(exports, "consumeUint8ArrayReadableStream", { enumerable: true, get: function () { return body_streams_1.consumeUint8ArrayReadableStream; } });
Object.defineProperty(exports, "pipeBodyStreamToResponse", { enumerable: true, get: function () { return body_streams_1.pipeBodyStreamToResponse; } });
var create_handler_1 = require("./create-handler");

@@ -7,0 +8,0 @@ Object.defineProperty(exports, "createHandler", { enumerable: true, get: function () { return create_handler_1.createHandler; } });

@@ -5,3 +5,3 @@ {

"homepage": "https://edge-runtime.vercel.app/packages/runtime",
"version": "2.4.0",
"version": "2.4.1",
"main": "dist/index.js",

@@ -8,0 +8,0 @@ "bin": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc