diff options
Diffstat (limited to 'src/types.ts')
| -rw-r--r-- | src/types.ts | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..0e11bee --- /dev/null +++ b/src/types.ts | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | export type Headers = [string, string][]; | ||
| 2 | export type Method = | ||
| 3 | | "GET" | ||
| 4 | | "HEAD" | ||
| 5 | | "POST" | ||
| 6 | | "PUT" | ||
| 7 | | "DELETE" | ||
| 8 | | "CONNECT" | ||
| 9 | | "OPTIONS" | ||
| 10 | | "TRACE" | ||
| 11 | | "PATCH"; | ||
| 12 | |||
| 13 | export interface RequestPayload { | ||
| 14 | id: string; | ||
| 15 | timestamp: string; | ||
| 16 | body: string; | ||
| 17 | headers: Headers; | ||
| 18 | method: Method; | ||
| 19 | path: string; | ||
| 20 | } | ||
| 21 | |||
| 22 | export interface Request { | ||
| 23 | type: "request"; | ||
| 24 | payload: RequestPayload; | ||
| 25 | } | ||
| 26 | |||
| 27 | export interface ResponsePayload { | ||
| 28 | id: string; | ||
| 29 | timing: number; | ||
| 30 | body: string; | ||
| 31 | headers: Headers; | ||
| 32 | status: number; | ||
| 33 | } | ||
| 34 | |||
| 35 | export interface Response { | ||
| 36 | type: "response"; | ||
| 37 | payload: ResponsePayload; | ||
| 38 | } | ||
| 39 | |||
| 40 | export type RequestResponseType = Request | Response; | ||
| 41 | |||
| 42 | export interface WebsocketConnectPayload { | ||
| 43 | method: "GET"; | ||
| 44 | id: string; | ||
| 45 | headers: Headers; | ||
| 46 | path: string; | ||
| 47 | timestamp: string; | ||
| 48 | } | ||
| 49 | |||
| 50 | export interface WebsocketConnect { | ||
| 51 | type: "websocket_connect"; | ||
| 52 | payload: WebsocketConnectPayload; | ||
| 53 | } | ||
| 54 | |||
| 55 | export interface WebsocketConnectedPayload { | ||
| 56 | id: string; | ||
| 57 | timing: number; | ||
| 58 | status: 101; | ||
| 59 | } | ||
| 60 | |||
| 61 | export interface WebsocketConnected { | ||
| 62 | type: "websocket_connected"; | ||
| 63 | payload: WebsocketConnectedPayload; | ||
| 64 | } | ||
| 65 | |||
| 66 | export interface WebsocketInboundPayload { | ||
| 67 | id: string; | ||
| 68 | timestamp: string; | ||
| 69 | body: string; | ||
| 70 | } | ||
| 71 | |||
| 72 | interface WebsocketInbound { | ||
| 73 | type: "websocket_inbound"; | ||
| 74 | payload: WebsocketInboundPayload; | ||
| 75 | } | ||
| 76 | |||
| 77 | export interface WebsocketOutboundPayload { | ||
| 78 | id: string; | ||
| 79 | timestamp: string; | ||
| 80 | body: string; | ||
| 81 | } | ||
| 82 | |||
| 83 | interface WebsocketOutbound { | ||
| 84 | type: "websocket_outbound"; | ||
| 85 | payload: WebsocketOutboundPayload; | ||
| 86 | } | ||
| 87 | |||
| 88 | export interface WebsocketDisconnectPayload { | ||
| 89 | id: string; | ||
| 90 | timestamp: string; | ||
| 91 | close_code: number; | ||
| 92 | } | ||
| 93 | |||
| 94 | interface WebsocketDisconnect { | ||
| 95 | type: "websocket_disconnect"; | ||
| 96 | payload: WebsocketDisconnectPayload; | ||
| 97 | } | ||
| 98 | |||
| 99 | export type WebsocketType = | ||
| 100 | | WebsocketConnect | ||
| 101 | | WebsocketConnected | ||
| 102 | | WebsocketInbound | ||
| 103 | | WebsocketOutbound | ||
| 104 | | WebsocketDisconnect; | ||
| 105 | |||
| 106 | export interface Historic { | ||
| 107 | type: "historic"; | ||
| 108 | payload: (RequestResponseType | WebsocketType)[]; | ||
| 109 | } | ||
| 110 | |||
| 111 | export interface RequestResponse { | ||
| 112 | type: "RequestResponse"; | ||
| 113 | request: RequestPayload; | ||
| 114 | response?: ResponsePayload; | ||
| 115 | } | ||
| 116 | |||
| 117 | export type Frame = WebsocketDisconnect | WebsocketInbound | WebsocketOutbound; | ||
| 118 | export interface WebsocketConnection { | ||
| 119 | type: "WebsocketConnection"; | ||
| 120 | request: WebsocketConnectPayload; | ||
| 121 | response?: WebsocketConnectedPayload; | ||
| 122 | frames?: Frame[]; | ||
| 123 | } | ||
| 124 | |||
| 125 | export type Call = RequestResponse | WebsocketConnection; | ||
| 126 | |||
| 127 | export type Requests = Array<Request | WebsocketConnect>; | ||
| 128 | export type Responses = { [id: string]: Response | WebsocketConnected }; | ||
| 129 | export type Frames = { [id: string]: Frame[] }; | ||
| 130 | |||
| 131 | export enum ReadyState { | ||
| 132 | CONNECTING = 0, | ||
| 133 | OPEN = 1, | ||
| 134 | CLOSING = 2, | ||
| 135 | CLOSED = 3, | ||
| 136 | } | ||
