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

@whatwg-node/server

Package Overview
Dependencies
Maintainers
1
Versions
726
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/server - npm Package Compare versions

Comparing version 0.9.35-alpha-20240621184419-14214132bfbf4c88ffb67a154bee0b11eb55bd56 to 0.9.35-alpha-20240726142004-1c1d9312228f171ca7294d8e8d301ccf033e7932

3

cjs/createServerAdapter.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServerAdapter = createServerAdapter;
exports.createServerAdapter = void 0;
const tslib_1 = require("tslib");

@@ -327,1 +327,2 @@ /* eslint-disable @typescript-eslint/ban-types */

}
exports.createServerAdapter = createServerAdapter;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCORSHeadersByRequestAndOptions = getCORSHeadersByRequestAndOptions;
exports.useCORS = useCORS;
exports.useCORS = exports.getCORSHeadersByRequestAndOptions = void 0;
function getCORSHeadersByRequestAndOptions(request, corsOptions) {

@@ -77,2 +76,3 @@ const currentOrigin = request.headers.get('origin');

}
exports.getCORSHeadersByRequestAndOptions = getCORSHeadersByRequestAndOptions;
async function getCORSResponseHeaders(request, corsOptionsFactory, serverContext) {

@@ -124,1 +124,2 @@ const corsOptions = await corsOptionsFactory(request, serverContext);

}
exports.useCORS = useCORS;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTTPError = void 0;
exports.createDefaultErrorHandler = createDefaultErrorHandler;
exports.useErrorHandling = useErrorHandling;
exports.useErrorHandling = exports.HTTPError = exports.createDefaultErrorHandler = void 0;
const fetch_1 = require("@whatwg-node/fetch");

@@ -20,2 +18,3 @@ const utils_js_1 = require("../utils.js");

}
exports.createDefaultErrorHandler = createDefaultErrorHandler;
function createDefaultErrorResponse(ResponseCtor) {

@@ -59,1 +58,2 @@ if (ResponseCtor.error) {

}
exports.useErrorHandling = useErrorHandling;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeRequestResponseMap = exports.ServerAdapterRequestAbortSignal = void 0;
exports.isAsyncIterable = isAsyncIterable;
exports.normalizeNodeRequest = normalizeNodeRequest;
exports.isReadable = isReadable;
exports.isNodeRequest = isNodeRequest;
exports.isServerResponse = isServerResponse;
exports.isReadableStream = isReadableStream;
exports.isFetchEvent = isFetchEvent;
exports.sendNodeResponse = sendNodeResponse;
exports.isRequestInit = isRequestInit;
exports.completeAssign = completeAssign;
exports.isPromise = isPromise;
exports.iterateAsyncVoid = iterateAsyncVoid;
exports.handleErrorFromRequestHandler = handleErrorFromRequestHandler;
exports.isolateObject = isolateObject;
exports.createDeferredPromise = createDeferredPromise;
exports.handleAbortSignalAndPromiseResponse = handleAbortSignalAndPromiseResponse;
exports.handleAbortSignalAndPromiseResponse = exports.createDeferredPromise = exports.isolateObject = exports.handleErrorFromRequestHandler = exports.iterateAsyncVoid = exports.isPromise = exports.completeAssign = exports.isRequestInit = exports.sendNodeResponse = exports.isFetchEvent = exports.isReadableStream = exports.isServerResponse = exports.isNodeRequest = exports.isReadable = exports.normalizeNodeRequest = exports.nodeRequestResponseMap = exports.ServerAdapterRequestAbortSignal = exports.isAsyncIterable = void 0;
const fetch_1 = require("@whatwg-node/fetch");

@@ -24,2 +8,3 @@ function isAsyncIterable(body) {

}
exports.isAsyncIterable = isAsyncIterable;
function getPort(nodeRequest) {

@@ -99,5 +84,2 @@ if (nodeRequest.socket?.localPort) {

}
any(signals) {
return AbortSignal.any([...signals]);
}
}

@@ -227,8 +209,11 @@ exports.ServerAdapterRequestAbortSignal = ServerAdapterRequestAbortSignal;

}
exports.normalizeNodeRequest = normalizeNodeRequest;
function isReadable(stream) {
return stream.read != null;
}
exports.isReadable = isReadable;
function isNodeRequest(request) {
return isReadable(request);
}
exports.isNodeRequest = isNodeRequest;
function isServerResponse(stream) {

@@ -242,8 +227,11 @@ // Check all used functions are defined

}
exports.isServerResponse = isServerResponse;
function isReadableStream(stream) {
return stream != null && stream.getReader != null;
}
exports.isReadableStream = isReadableStream;
function isFetchEvent(event) {
return event != null && event.request != null && event.respondWith != null;
}
exports.isFetchEvent = isFetchEvent;
function configureSocket(rawRequest) {

@@ -327,2 +315,3 @@ rawRequest?.socket?.setTimeout?.(0);

}
exports.sendNodeResponse = sendNodeResponse;
function isRequestInit(val) {

@@ -345,2 +334,3 @@ return (val != null &&

}
exports.isRequestInit = isRequestInit;
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#copying_accessors

@@ -367,5 +357,7 @@ function completeAssign(...args) {

}
exports.completeAssign = completeAssign;
function isPromise(val) {
return val?.then != null;
}
exports.isPromise = isPromise;
function iterateAsyncVoid(iterable, callback) {

@@ -398,2 +390,3 @@ const iterator = iterable[Symbol.iterator]();

}
exports.iterateAsyncVoid = iterateAsyncVoid;
function handleErrorFromRequestHandler(error, ResponseCtor) {

@@ -404,2 +397,3 @@ return new ResponseCtor(error.stack || error.message || error.toString(), {

}
exports.handleErrorFromRequestHandler = handleErrorFromRequestHandler;
function isolateObject(originalCtx, waitUntilPromises) {

@@ -477,2 +471,3 @@ if (originalCtx == null) {

}
exports.isolateObject = isolateObject;
function createDeferredPromise() {

@@ -495,2 +490,3 @@ let resolveFn;

}
exports.createDeferredPromise = createDeferredPromise;
function handleAbortSignalAndPromiseResponse(response$, abortSignal) {

@@ -513,1 +509,2 @@ if (isPromise(response$) && abortSignal) {

}
exports.handleAbortSignalAndPromiseResponse = handleAbortSignalAndPromiseResponse;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUWSResponse = isUWSResponse;
exports.getRequestFromUWSRequest = getRequestFromUWSRequest;
exports.sendResponseToUwsOpts = sendResponseToUwsOpts;
exports.sendResponseToUwsOpts = exports.getRequestFromUWSRequest = exports.isUWSResponse = void 0;
function isUWSResponse(res) {
return !!res.onData;
}
exports.isUWSResponse = isUWSResponse;
function getRequestFromUWSRequest({ req, res, fetchAPI, signal }) {

@@ -42,2 +41,3 @@ let body;

}
exports.getRequestFromUWSRequest = getRequestFromUWSRequest;
async function forwardResponseBodyToUWSResponse(uwsResponse, fetchResponse, signal) {

@@ -96,1 +96,2 @@ for await (const chunk of fetchResponse.body) {

}
exports.sendResponseToUwsOpts = sendResponseToUwsOpts;

@@ -79,5 +79,2 @@ import { URL } from '@whatwg-node/fetch';

}
any(signals) {
return AbortSignal.any([...signals]);
}
}

@@ -84,0 +81,0 @@ let bunNodeCompatModeWarned = false;

{
"name": "@whatwg-node/server",
"version": "0.9.35-alpha-20240621184419-14214132bfbf4c88ffb67a154bee0b11eb55bd56",
"version": "0.9.35-alpha-20240726142004-1c1d9312228f171ca7294d8e8d301ccf033e7932",
"description": "Fetch API compliant HTTP Server adapter",
"sideEffects": false,
"dependencies": {
"@whatwg-node/fetch": "^0.9.17",
"@whatwg-node/fetch": "0.9.18-alpha-20240726142004-1c1d9312228f171ca7294d8e8d301ccf033e7932",
"tslib": "^2.3.1"

@@ -9,0 +9,0 @@ },

@@ -155,3 +155,3 @@ # WHATWG Node Generic Server Adapter

```ts
import fastify, { FastifyReply, FastifyRequest } from 'fastify'
import fastify from 'fastify'
import myServerAdapter from './myServerAdapter'

@@ -170,18 +170,7 @@

method: ['GET', 'POST', 'OPTIONS'],
handler: async (req, reply) => {
const response = await myServerAdapter.handleNodeRequestAndResponse(req, reply, {
handler: (req, reply) =>
myServerAdapter.handleNodeRequestAndResponse(req, reply, {
req,
reply
})
response.headers.forEach((value, key) => {
reply.header(key, value)
})
reply.status(response.status)
// Fastify doesn't accept `null` as a response body
reply.send(response.body || undefined)
return reply
}
})

@@ -188,0 +177,0 @@

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

/// <reference types="@whatwg-node/fetch" />
export * from './createServerAdapter.js';

@@ -2,0 +3,0 @@ export * from './types.js';

@@ -7,7 +7,7 @@ import { ServerAdapterPlugin } from './types.js';

headers: HeadersInit;
details?: any | undefined;
details?: any;
name: string;
constructor(status: number, message: string, headers?: HeadersInit, details?: any | undefined);
constructor(status: number, message: string, headers?: HeadersInit, details?: any);
}
export type ErrorHandler<TServerContext> = (e: any, request: Request, ctx: TServerContext) => Response | Promise<Response>;
export declare function useErrorHandling<TServerContext>(onError?: ErrorHandler<TServerContext>): ServerAdapterPlugin<TServerContext>;

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

/// <reference types="node" />
/// <reference types="@whatwg-node/fetch" />
import type { RequestListener } from 'http';

@@ -2,0 +4,0 @@ import type { NodeRequest, NodeResponse } from './utils.js';

@@ -0,1 +1,5 @@

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

@@ -25,3 +29,3 @@ import type { Http2ServerRequest, Http2ServerResponse } from 'http2';

aborted: boolean;
private _onabort;
_onabort: ((this: AbortSignal, ev: Event) => any) | null;
reason: any;

@@ -32,3 +36,2 @@ throwIfAborted(): void;

set onabort(value: ((this: AbortSignal, ev: Event) => any) | null);
any(signals: Iterable<AbortSignal>): AbortSignal;
}

@@ -35,0 +38,0 @@ export declare const nodeRequestResponseMap: WeakMap<NodeRequest, NodeResponse>;

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc