UNPKG

7.18 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17import { AppCheckTokenProvider } from './AppCheckTokenProvider';
18import { AuthTokenProvider } from './AuthTokenProvider';
19import { PersistentConnection } from './PersistentConnection';
20import { RepoInfo } from './RepoInfo';
21import { ServerActions } from './ServerActions';
22import { Node } from './snap/Node';
23import { SnapshotHolder } from './SnapshotHolder';
24import { SparseSnapshotTree } from './SparseSnapshotTree';
25import { StatsCollection } from './stats/StatsCollection';
26import { StatsListener } from './stats/StatsListener';
27import { StatsReporter } from './stats/StatsReporter';
28import { SyncTree } from './SyncTree';
29import { Indexable } from './util/misc';
30import { Path } from './util/Path';
31import { Tree } from './util/Tree';
32import { EventQueue } from './view/EventQueue';
33import { EventRegistration, QueryContext } from './view/EventRegistration';
34declare const enum TransactionStatus {
35 RUN = 0,
36 SENT = 1,
37 COMPLETED = 2,
38 SENT_NEEDS_ABORT = 3,
39 NEEDS_ABORT = 4
40}
41interface Transaction {
42 path: Path;
43 update: (a: unknown) => unknown;
44 onComplete: (error: Error | null, committed: boolean, node: Node | null) => void;
45 status: TransactionStatus;
46 order: number;
47 applyLocally: boolean;
48 retryCount: number;
49 unwatcher: () => void;
50 abortReason: string | null;
51 currentWriteId: number;
52 currentInputSnapshot: Node | null;
53 currentOutputSnapshotRaw: Node | null;
54 currentOutputSnapshotResolved: Node | null;
55}
56/**
57 * A connection to a single data repository.
58 */
59export declare class Repo {
60 repoInfo_: RepoInfo;
61 forceRestClient_: boolean;
62 authTokenProvider_: AuthTokenProvider;
63 appCheckProvider_: AppCheckTokenProvider;
64 /** Key for uniquely identifying this repo, used in RepoManager */
65 readonly key: string;
66 dataUpdateCount: number;
67 infoSyncTree_: SyncTree;
68 serverSyncTree_: SyncTree;
69 stats_: StatsCollection;
70 statsListener_: StatsListener | null;
71 eventQueue_: EventQueue;
72 nextWriteId_: number;
73 server_: ServerActions;
74 statsReporter_: StatsReporter;
75 infoData_: SnapshotHolder;
76 interceptServerDataCallback_: ((a: string, b: unknown) => void) | null;
77 /** A list of data pieces and paths to be set when this client disconnects. */
78 onDisconnect_: SparseSnapshotTree;
79 /** Stores queues of outstanding transactions for Firebase locations. */
80 transactionQueueTree_: Tree<Transaction[]>;
81 persistentConnection_: PersistentConnection | null;
82 constructor(repoInfo_: RepoInfo, forceRestClient_: boolean, authTokenProvider_: AuthTokenProvider, appCheckProvider_: AppCheckTokenProvider);
83 /**
84 * @returns The URL corresponding to the root of this Firebase.
85 */
86 toString(): string;
87}
88export declare function repoStart(repo: Repo, appId: string, authOverride?: object): void;
89/**
90 * @returns The time in milliseconds, taking the server offset into account if we have one.
91 */
92export declare function repoServerTime(repo: Repo): number;
93/**
94 * Generate ServerValues using some variables from the repo object.
95 */
96export declare function repoGenerateServerValues(repo: Repo): Indexable;
97export declare function repoInterceptServerData(repo: Repo, callback: ((a: string, b: unknown) => unknown) | null): void;
98/**
99 * The purpose of `getValue` is to return the latest known value
100 * satisfying `query`.
101 *
102 * This method will first check for in-memory cached values
103 * belonging to active listeners. If they are found, such values
104 * are considered to be the most up-to-date.
105 *
106 * If the client is not connected, this method will try to
107 * establish a connection and request the value for `query`. If
108 * the client is not able to retrieve the query result, it reports
109 * an error.
110 *
111 * @param query - The query to surface a value for.
112 */
113export declare function repoGetValue(repo: Repo, query: QueryContext): Promise<Node>;
114export declare function repoSetWithPriority(repo: Repo, path: Path, newVal: unknown, newPriority: number | string | null, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
115export declare function repoUpdate(repo: Repo, path: Path, childrenToMerge: {
116 [k: string]: unknown;
117}, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
118export declare function repoOnDisconnectCancel(repo: Repo, path: Path, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
119export declare function repoOnDisconnectSet(repo: Repo, path: Path, value: unknown, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
120export declare function repoOnDisconnectSetWithPriority(repo: Repo, path: Path, value: unknown, priority: unknown, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
121export declare function repoOnDisconnectUpdate(repo: Repo, path: Path, childrenToMerge: {
122 [k: string]: unknown;
123}, onComplete: ((status: Error | null, errorReason?: string) => void) | null): void;
124export declare function repoAddEventCallbackForQuery(repo: Repo, query: QueryContext, eventRegistration: EventRegistration): void;
125export declare function repoRemoveEventCallbackForQuery(repo: Repo, query: QueryContext, eventRegistration: EventRegistration): void;
126export declare function repoInterrupt(repo: Repo): void;
127export declare function repoResume(repo: Repo): void;
128export declare function repoStats(repo: Repo, showDelta?: boolean): void;
129export declare function repoStatsIncrementCounter(repo: Repo, metric: string): void;
130export declare function repoCallOnCompleteCallback(repo: Repo, callback: ((status: Error | null, errorReason?: string) => void) | null, status: string, errorReason?: string | null): void;
131/**
132 * Creates a new transaction, adds it to the transactions we're tracking, and
133 * sends it to the server if possible.
134 *
135 * @param path - Path at which to do transaction.
136 * @param transactionUpdate - Update callback.
137 * @param onComplete - Completion callback.
138 * @param unwatcher - Function that will be called when the transaction no longer
139 * need data updates for `path`.
140 * @param applyLocally - Whether or not to make intermediate results visible
141 */
142export declare function repoStartTransaction(repo: Repo, path: Path, transactionUpdate: (a: unknown) => unknown, onComplete: ((error: Error, committed: boolean, node: Node) => void) | null, unwatcher: () => void, applyLocally: boolean): void;
143export {};
144
\No newline at end of file