@whatwg-node/server 0.7.7 → 0.8.0
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/package.json +5 -2
- package/createServerAdapter.d.ts +0 -9
- package/index.d.ts +0 -7
- package/index.js +0 -666
- package/index.mjs +0 -643
- package/plugins/types.d.ts +0 -21
- package/plugins/useCors.d.ts +0 -13
- package/plugins/useErrorHandling.d.ts +0 -11
- package/types.d.ts +0 -56
- package/utils.d.ts +0 -33
package/types.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { RequestListener } from 'node:http';
|
|
3
|
-
import type { NodeRequest, NodeResponse } from './utils';
|
|
4
|
-
export interface FetchEvent extends Event {
|
|
5
|
-
waitUntil(f: Promise<void> | void): void;
|
|
6
|
-
request: Request;
|
|
7
|
-
respondWith(r: Response | PromiseLike<Response>): void;
|
|
8
|
-
}
|
|
9
|
-
export interface ServerAdapterBaseObject<TServerContext, THandleRequest extends ServerAdapterRequestHandler<TServerContext> = ServerAdapterRequestHandler<TServerContext>> {
|
|
10
|
-
/**
|
|
11
|
-
* An async function that takes `Request` and the server context and returns a `Response`.
|
|
12
|
-
* If you use `requestListener`, the server context is `{ req: IncomingMessage, res: ServerResponse }`.
|
|
13
|
-
*/
|
|
14
|
-
handle: THandleRequest;
|
|
15
|
-
}
|
|
16
|
-
export interface ServerAdapterObject<TServerContext> extends EventListenerObject {
|
|
17
|
-
/**
|
|
18
|
-
* A basic request listener that takes a `Request` with the server context and returns a `Response`.
|
|
19
|
-
*/
|
|
20
|
-
handleRequest: (request: Request, ctx: TServerContext) => Promise<Response>;
|
|
21
|
-
/**
|
|
22
|
-
* WHATWG Fetch spec compliant `fetch` function that can be used for testing purposes.
|
|
23
|
-
*/
|
|
24
|
-
fetch(request: Request, ctx: TServerContext): Promise<Response> | Response;
|
|
25
|
-
fetch(request: Request, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
26
|
-
fetch(urlStr: string, ctx: TServerContext): Promise<Response> | Response;
|
|
27
|
-
fetch(urlStr: string, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
28
|
-
fetch(urlStr: string, init: RequestInit, ctx: TServerContext): Promise<Response> | Response;
|
|
29
|
-
fetch(urlStr: string, init: RequestInit, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
30
|
-
fetch(url: URL, ctx: TServerContext): Promise<Response> | Response;
|
|
31
|
-
fetch(url: URL, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
32
|
-
fetch(url: URL, init: RequestInit, ctx: TServerContext): Promise<Response> | Response;
|
|
33
|
-
fetch(url: URL, init: RequestInit, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
34
|
-
/**
|
|
35
|
-
* This function takes Node's request object and returns a WHATWG Fetch spec compliant `Response` object.
|
|
36
|
-
**/
|
|
37
|
-
handleNodeRequest(nodeRequest: NodeRequest, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
38
|
-
/**
|
|
39
|
-
* A request listener function that can be used with any Node server variation.
|
|
40
|
-
*/
|
|
41
|
-
requestListener: RequestListener;
|
|
42
|
-
handle(req: NodeRequest, res: NodeResponse, ...ctx: Partial<TServerContext>[]): Promise<void>;
|
|
43
|
-
handle(request: Request, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
44
|
-
handle(fetchEvent: FetchEvent & Partial<TServerContext>, ...ctx: Partial<TServerContext>[]): void;
|
|
45
|
-
handle(container: {
|
|
46
|
-
request: Request;
|
|
47
|
-
} & Partial<TServerContext>, ...ctx: Partial<TServerContext>[]): Promise<Response> | Response;
|
|
48
|
-
}
|
|
49
|
-
export type ServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>> = TBaseObject & ServerAdapterObject<TServerContext>['handle'] & ServerAdapterObject<TServerContext>;
|
|
50
|
-
export type ServerAdapterRequestHandler<TServerContext> = (request: Request, ctx: TServerContext) => Promise<Response> | Response;
|
|
51
|
-
export type ServerAdapterNodeContext = {
|
|
52
|
-
req: NodeRequest;
|
|
53
|
-
res: NodeResponse;
|
|
54
|
-
};
|
|
55
|
-
export type WaitUntilFn = (promise: Promise<void> | void) => void;
|
|
56
|
-
export type FetchAPI = ReturnType<typeof import('@whatwg-node/fetch').createFetch>;
|
package/utils.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
-
import type { Http2ServerRequest, Http2ServerResponse, OutgoingHttpHeaders } from 'node:http2';
|
|
7
|
-
import type { Socket } from 'node:net';
|
|
8
|
-
import type { Readable } from 'node:stream';
|
|
9
|
-
import { FetchEvent } from './types';
|
|
10
|
-
export declare function isAsyncIterable(body: any): body is AsyncIterable<any>;
|
|
11
|
-
export interface NodeRequest {
|
|
12
|
-
protocol?: string;
|
|
13
|
-
hostname?: string;
|
|
14
|
-
body?: any;
|
|
15
|
-
url?: string;
|
|
16
|
-
originalUrl?: string;
|
|
17
|
-
method?: string;
|
|
18
|
-
headers?: any;
|
|
19
|
-
req?: IncomingMessage | Http2ServerRequest;
|
|
20
|
-
raw?: IncomingMessage | Http2ServerRequest;
|
|
21
|
-
socket?: Socket;
|
|
22
|
-
query?: any;
|
|
23
|
-
}
|
|
24
|
-
export type NodeResponse = ServerResponse | Http2ServerResponse;
|
|
25
|
-
export declare function normalizeNodeRequest(nodeRequest: NodeRequest, RequestCtor: typeof Request): Request;
|
|
26
|
-
export declare function isReadable(stream: any): stream is Readable;
|
|
27
|
-
export declare function isNodeRequest(request: any): request is NodeRequest;
|
|
28
|
-
export declare function isServerResponse(stream: any): stream is NodeResponse;
|
|
29
|
-
export declare function isReadableStream(stream: any): stream is ReadableStream;
|
|
30
|
-
export declare function isFetchEvent(event: any): event is FetchEvent;
|
|
31
|
-
export declare function getHeadersObj(headers: Headers): OutgoingHttpHeaders;
|
|
32
|
-
export declare function sendNodeResponse(fetchResponse: Response, serverResponse: NodeResponse, nodeRequest: NodeRequest): Promise<void>;
|
|
33
|
-
export declare function isRequestInit(val: unknown): val is RequestInit;
|