1 |
|
2 | import { PassThrough, Stream } from 'stream';
|
3 | import type { IncomingMessage, ServerResponse } from 'http';
|
4 |
|
5 | export interface CompatFastifyReply {
|
6 | raw: ServerResponse;
|
7 | status(statusCode: number): CompatFastifyReply;
|
8 | headers(values: {
|
9 | [key: string]: any;
|
10 | }): CompatFastifyReply;
|
11 | send(payload?: any): CompatFastifyReply;
|
12 | }
|
13 | export interface CompatFastifyRequest {
|
14 | raw: IncomingMessage;
|
15 | body: unknown;
|
16 | readonly headers: {
|
17 | [key: string]: unknown;
|
18 | };
|
19 | }
|
20 |
|
21 |
|
22 | export interface CompatKoaContext {
|
23 | [key: string]: any;
|
24 | req: IncomingMessage;
|
25 | res: ServerResponse;
|
26 | }
|
27 |
|
28 | declare module 'http' {
|
29 | interface IncomingMessage {
|
30 | _koaCtx?: CompatKoaContext;
|
31 | _fastifyRequest?: CompatFastifyRequest;
|
32 | _body?: boolean;
|
33 | body?: any;
|
34 | originalUrl?: string;
|
35 | }
|
36 | }
|
37 | declare type Headers = {
|
38 | [header: string]: string;
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export declare abstract class PostGraphileResponse {
|
45 | private _headers;
|
46 | private _body;
|
47 | private _setHeaders;
|
48 | statusCode: number;
|
49 | private _setHeadersOnce;
|
50 | setHeader(header: string, value: string): void;
|
51 | |
52 |
|
53 |
|
54 | endWithStream(): PassThrough;
|
55 | |
56 |
|
57 |
|
58 | end(moreBody?: Buffer | string | null): void;
|
59 | |
60 |
|
61 |
|
62 | abstract getNodeServerRequest(): IncomingMessage;
|
63 | abstract getNodeServerResponse(): ServerResponse;
|
64 | abstract setHeaders(statusCode: number, headers: Headers): void;
|
65 | abstract setBody(body: Stream | Buffer | string | undefined): void;
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 | export declare class PostGraphileResponseNode extends PostGraphileResponse {
|
71 | private _req;
|
72 | private _res;
|
73 | private _next;
|
74 | constructor(req: IncomingMessage, res: ServerResponse, next: (e?: 'route' | Error) => void);
|
75 | getNodeServerRequest(): IncomingMessage;
|
76 | getNodeServerResponse(): ServerResponse;
|
77 | getNextCallback(): (e?: Error | "route" | undefined) => void;
|
78 | setHeaders(statusCode: number, headers: Headers): void;
|
79 | setBody(body: Stream | Buffer | string | undefined): void;
|
80 | }
|
81 | export declare type CompatKoaNext = (error?: Error) => Promise<any>;
|
82 | /**
|
83 | * Suitable for Koa.
|
84 | */
|
85 | export declare class PostGraphileResponseKoa extends PostGraphileResponse {
|
86 | private _ctx;
|
87 | private _next;
|
88 | constructor(ctx: CompatKoaContext, next: CompatKoaNext);
|
89 | getNodeServerRequest(): IncomingMessage;
|
90 | getNodeServerResponse(): ServerResponse;
|
91 | getNextCallback(): CompatKoaNext;
|
92 | setHeaders(statusCode: number, headers: Headers): void;
|
93 | endWithStream(): PassThrough;
|
94 | setBody(body: Stream | Buffer | string | undefined): void;
|
95 | }
|
96 | /**
|
97 | * Suitable for Fastify v3 (use PostGraphileResponseNode and middleware
|
98 | * approach for Fastify v2)
|
99 | */
|
100 | export declare class PostGraphileResponseFastify3 extends PostGraphileResponse {
|
101 | private _request;
|
102 | private _reply;
|
103 | constructor(request: CompatFastifyRequest, reply: CompatFastifyReply);
|
104 | getNodeServerRequest(): IncomingMessage;
|
105 | getNodeServerResponse(): ServerResponse;
|
106 | setHeaders(statusCode: number, headers: Headers): void;
|
107 | endWithStream(): PassThrough;
|
108 | setBody(body: Stream | Buffer | string | undefined): void;
|
109 | }
|
110 | export {};
|