Skip to content

Commit 1cce950

Browse files
Add Typeings for Webchannel
1 parent 542240d commit 1cce950

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

packages/firestore/src/platform_browser/webchannel_connection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ export class WebChannelConnection implements Connection {
9898
const url = this.makeUrl(rpcName);
9999

100100
return new Promise((resolve: Resolver<Resp>, reject: Rejecter) => {
101-
// XhrIo doesn't have TS typings.
102-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
103-
const xhr: any = new XhrIo();
101+
const xhr = new XhrIo();
104102
xhr.listenOnce(EventType.COMPLETE, () => {
105103
try {
106104
switch (xhr.getLastErrorCode()) {
@@ -191,6 +189,7 @@ export class WebChannelConnection implements Connection {
191189

192190
this.modifyHeadersForRequest(headers, token);
193191

192+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
194193
xhr.send(url, 'POST', requestString, headers, XHR_TIMEOUT_SECS);
195194
});
196195
}

packages/webchannel-wrapper/src/index.d.ts

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,59 @@
1515
* limitations under the License.
1616
*/
1717

18-
// TODO(mikelehen): Flesh out proper types (or figure out how to generate via
19-
// clutz or something).
20-
export class XhrIo {}
21-
export const ErrorCode: any;
22-
export const EventType: any;
18+
export enum EventType {
19+
OPEN = 'open',
20+
CLOSE = 'close',
21+
ERROR = 'error',
22+
MESSAGE = 'message',
23+
COMPLETE = 'complete'
24+
}
25+
2326
export namespace WebChannel {
24-
export type EventType = any;
25-
export const EventType: any;
27+
export const EventType: EventType;
28+
}
29+
30+
export enum ErrorCode {
31+
NO_ERROR = 0,
32+
ACCESS_DENIED,
33+
FILE_NOT_FOUND,
34+
FF_SILENT_ERROR,
35+
CUSTOM_ERROR,
36+
EXCEPTION,
37+
HTTP_ERROR,
38+
ABORT,
39+
TIMEOUT,
40+
OFFLINE
41+
}
42+
43+
export interface Headers {
44+
[name: string]: string | number;
45+
}
46+
47+
export class XhrIo {
48+
send(
49+
url: string,
50+
method?: string,
51+
body?: ArrayBufferView | Blob | string | null,
52+
headers?: Headers,
53+
timeoutInterval?: number
54+
): Promise<XhrIo>;
55+
56+
getLastErrorCode(): ErrorCode;
57+
58+
getLastError(): string;
59+
60+
getStatus(): number;
61+
62+
getResponseText(): string;
63+
64+
getResponseJson(): Object | any;
65+
66+
abort(): void;
67+
68+
getResponseHeader(header: string): { [key: string]: string };
69+
70+
listenOnce<T>(type: EventType, cb: (param: T) => void): void;
2671
}
2772

2873
type StringMap = { [key: string]: string };
@@ -31,7 +76,9 @@ export interface WebChannelOptions {
3176
messageHeaders?: StringMap;
3277
initMessageHeaders?: StringMap;
3378
messageContentType?: string;
34-
messageUrlParams?: StringMap;
79+
messageUrlParams?: {
80+
database?: string;
81+
};
3582
clientProtocolHeaderRequired?: boolean;
3683
concurrentRequestLimit?: number;
3784
supportsCrossDomainXhr?: boolean;
@@ -44,13 +91,23 @@ export interface WebChannelOptions {
4491
fastHandshake?: boolean;
4592
disableRedac?: boolean;
4693
clientProfile?: string;
47-
internalChannelParams?: { [key: string]: boolean | number };
94+
internalChannelParams?: {
95+
forwardChannelRequestTimeoutMs?: number;
96+
};
4897
xmlHttpFactory?: unknown;
4998
requestRefreshThresholds?: { [key: string]: number };
5099
}
51100

101+
export interface WebChannel {
102+
open(): void;
103+
close(): void;
104+
halfClose(): void;
105+
listen<T>(type: EventType, cb: (param: T) => void): void;
106+
send<T>(msg: T): void;
107+
}
108+
52109
export interface WebChannelTransport {
53-
createWebChannel(url: string, options: WebChannelOptions): any;
110+
createWebChannel(url: string, options: WebChannelOptions): WebChannel;
54111
}
55112

56113
export function createWebChannelTransport(): WebChannelTransport;

0 commit comments

Comments
 (0)