This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
65 lines (55 loc) · 1.48 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Parameter, RequestBody, Server } from "loas3/dist/generated/full";
export const RESTMethodTypes = ["get", "head", "post", "put", "patch", "delete", "options", "trace"] as const;
export type HTTPMethod = typeof RESTMethodTypes[number];
/**
* Analogous to `IncomingHttpHeaders` in @types/node.
* Header names are expected to be _lowercased_.
*/
export interface IIncomingHeaders {
[header: string]: string | string[] | undefined;
}
/**
* Analogous to `OutgoingHttpHeaders` in @types/node.
* Allows numbers as they are converted to strings internally.
*/
export interface IOutgoingHeaders {
[header: string]: string | string[] | number | undefined;
}
export interface IIncomingQuery {
[key: string]: string | string[] | undefined;
}
export type IProtocol = "http" | "https";
export const isProtocol = (s: string): s is IProtocol => {
return /https?/.test(s);
};
export interface ISerializedRequest {
body?: string | object;
headers?: IIncomingHeaders;
host: string;
method: HTTPMethod;
/**
* Full path containing query parameters
*/
path: string;
/**
* Path name not containing query parameters
*/
pathname: string;
/**
* Query parameters
*/
query: IIncomingQuery;
protocol: IProtocol;
}
// "Operation"
export type PartialRequestTemplate = {
method: HTTPMethod;
body?: RequestBody;
parameters: Parameter[];
servers: Server[];
};
export interface ISerializedResponse {
statusCode: number;
body?: string;
headers?: IIncomingHeaders;
}