UNPKG

2.89 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright The Closure Library Authors.
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7// Based on
8// https://github.com/firebase/firebase-js-sdk/blob/ce88e71e738ac7bb2cd5d63e4e314e2de82f72ef/packages/webchannel-wrapper/src/index.d.ts.
9// WARNING: This is not a complete set of types and functions that exist in the
10// Closure WebChannel code - it is merely meant to support the usage patterns of
11// the Firestore SDK.
12
13export var EventType: {COMPLETE: string;};
14
15export namespace WebChannel {
16 export var EventType:
17 {OPEN: string; CLOSE: string; ERROR: string; MESSAGE: string;};
18}
19
20export var Event: {STAT_EVENT: string;};
21
22export var Stat: {PROXY: number; NOPROXY: number;};
23
24export var ErrorCode: {NO_ERROR: number; HTTP_ERROR: number; TIMEOUT: number;};
25
26export interface Headers {
27 [name: string]: string|number;
28}
29
30export interface WebChannelError {
31 error?: {status: string; message: string};
32}
33
34export class XhrIo {
35 send(
36 url: string, method?: string, body?: string, headers?: Headers,
37 timeoutInterval?: number): void;
38 getLastErrorCode(): number;
39 getLastError(): string;
40 getStatus(): number;
41 getResponseText(): string;
42 getResponseJson(): WebChannelError|object;
43 listenOnce(type: string, cb: (param: unknown) => void): void;
44 setWithCredentials(withCredentials: boolean): void;
45}
46
47export interface WebChannelOptions {
48 messageHeaders?: {
49 // To ensure compatibility with property minifcation tools, keys need to
50 // be listed explicitly.
51 [k: string]: never;
52 };
53 initMessageHeaders?: {
54 // To ensure compatibility with property minifcation tools, keys need to
55 // be listed explicitly.
56 [k: string]: never;
57 };
58 messageContentType?: string;
59 messageUrlParams?: {database?: string;};
60 clientProtocolHeaderRequired?: boolean;
61 concurrentRequestLimit?: number;
62 supportsCrossDomainXhr?: boolean;
63 sendRawJson?: boolean;
64 httpSessionIdParam?: string;
65 encodeInitMessageHeaders?: boolean;
66 forceLongPolling?: boolean;
67 detectBufferingProxy?: boolean;
68 longPollingTimeout?: number;
69 fastHandshake?: boolean;
70 disableRedac?: boolean;
71 clientProfile?: string;
72 internalChannelParams?: {forwardChannelRequestTimeoutMs?: number;};
73 useFetchStreams?: boolean;
74 xmlHttpFactory?: unknown;
75 requestRefreshThresholds?: {[key: string]: number};
76}
77
78export interface EventTarget {
79 listen(type: string|number, cb: (param: unknown) => void): void;
80}
81
82export interface WebChannel extends EventTarget {
83 open(): void;
84 close(): void;
85 send(msg: unknown): void;
86}
87
88export interface StatEvent {
89 stat: number;
90}
91
92export interface WebChannelTransport {
93 createWebChannel(url: string, options: WebChannelOptions): WebChannel;
94}
95
96export function createWebChannelTransport(): WebChannelTransport;
97
98export function getStatEventTarget(): EventTarget;
99
100export class FetchXmlHttpFactory {
101 constructor(options: {});
102}