-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1.d.ts
199 lines (193 loc) · 5.7 KB
/
v1.d.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
declare module "@carbon-standards/types/v1" {
/**
* Represents messages sent between the client and server.
*/
export type CarbonPacket =
| CarbonRequest
| CarbonResponse
| CarbonOpen
| CarbonClose
| CarbonMessage
| CarbonError;
/**
* Signals to the server that a remote request or connection should be made.
*/
export type CarbonRequest = {
/**
* A 32 character HEX string identifying the request.
*
* This should be randomly generated uppon each request in order to ensure there are no response collisions.
* If this isn't set or is invalid, the server will respond with an INVALID_REQUEST error.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "request";
/**
* HTTP method to be used when making the request.
*
* If an invalid HTTP method is provided, the server will respond with an INVALID_REQUEST error.
*/
method: string;
/**
* The remote URL of the request.
*
* If this isn't set or cannot be parsed, the server will respond with an INVALID_REQUEST error.
*
* If the server fails to establish a connection, the server will respond with a CONNECTION_FAILED error.
*/
url: string;
/**
* Outgoing headers that will be sent to the remote.
*
* If the headers are in an invalid format, the server will respond with an INVALID_REQUEST error.
*/
headers: Record<string, string>;
/**
* An integer value representing the size of the body in bytes.
*
* If this value exceeds the `maxBodySize` value provided by the server, the server will respond with a BODY_TOO_LARGE error.
*/
body?: number;
};
/**
* Represents a response from the remote.
*/
export type CarbonResponse = {
/**
* A 32 character HEX string identifying the request.
*
* This should be randomly generated uppon each request in order to ensure there are no response collisions.
* If this isn't set or is invalid, the server will respond with an UNKNOWN_REQUEST error.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "response";
/**
* The HTTP status code provided by the remote resource.
*/
status: number;
/**
* The HTTP status text provided by the remote resource.
*/
statusText: string;
/**
* The response headers provided by the remote.
*/
headers: Record<string, string>;
/**
* An integer value representing the size of the body in bytes.
*
* If this value exceeds the `maxBodySize` value set by the server, the server will respond with a BODY_TOO_LARGE error.
*/
body?: number;
};
/**
* Signals to the client or server that a websocket connection has been opened.
*/
export type CarbonOpen = {
/**
* A 32 character HEX string identifying the connection.
*
* This should be randomly generated uppon each connection in order to ensure there are no collisions.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "open";
/**
* The response headers provided by the remote.
*/
headers: Record<string, string>;
};
/**
* Signals to the client or server that a websocket connection should be closed.
*/
export type CarbonClose = {
/**
* A 32 character HEX string identifying the connection.
*
* This should be randomly generated uppon each connection in order to ensure there are no collisions.
* If this isn't set or is invalid, the server will respond with an UNKNOWN_REQUEST error.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "close";
/**
* The status code for closing the connection.
*/
code: number;
/**
* The reason for closing the connection.
*/
reason: string;
};
/**
* Represents a message sent over a websocket connection.
*/
export type CarbonMessage = {
/**
* A 32 character HEX string identifying the message.
*
* This should be randomly generated uppon each message in order to ensure there are no collisions.
* If this isn't set or is invalid, the server will respond with an INVALID_REQUEST error.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "message";
/**
* A 32 character HEX string identifying the connection.
*
* If this isn't set or is invalid, the server will respond with an UNKNOWN_REQUEST error.
*/
connection: string;
/**
* The data type of the message.
*/
dataType: "text" | "binary";
/**
* An integer value representing the size of the message in bytes.
*
* If this value exceeds the `maxMessageSize` value set by the server, the server will respond with a BODY_TOO_LARGE error.
*/
data: number;
};
/**
* Represents an error that occured on the server.
*/
export type CarbonError = {
/**
* A 32 character HEX string identifying the connection.
*
* This should be randomly generated uppon each connection in order to ensure there are no collisions.
* If this isn't set or is invalid, the server will respond with an UNKNOWN_REQUEST error.
*/
id: string;
/**
* This value identifies what kind of action is being made.
*/
type: "error";
/**
* The error code.
*/
code:
| "UNKNOWN_REQUEST"
| "INVALID_REQUEST"
| "CONNECTION_FAILED"
| "REQUEST_TIMEOUT"
| "BODY_TOO_LARGE"
| "UNKNOWN";
/**
* The error message.
*/
message: string;
};
}