1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import { FirebaseApp } from '@firebase/app-types';
|
19 | import { EmulatorMockTokenOptions } from '@firebase/util';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export interface IteratedDataSnapshot extends DataSnapshot {
|
25 | key: string;
|
26 | }
|
27 |
|
28 | export interface DataSnapshot {
|
29 | child(path: string): DataSnapshot;
|
30 | exists(): boolean;
|
31 | exportVal(): any;
|
32 | forEach(action: (a: IteratedDataSnapshot) => boolean | void): boolean;
|
33 | getPriority(): string | number | null;
|
34 | hasChild(path: string): boolean;
|
35 | hasChildren(): boolean;
|
36 | key: string | null;
|
37 | numChildren(): number;
|
38 | ref: Reference;
|
39 | toJSON(): Object | null;
|
40 | val(): any;
|
41 | }
|
42 |
|
43 | export interface Database {
|
44 | app: FirebaseApp;
|
45 | useEmulator(
|
46 | host: string,
|
47 | port: number,
|
48 | options?: {
|
49 | mockUserToken?: EmulatorMockTokenOptions | string;
|
50 | }
|
51 | ): void;
|
52 | goOffline(): void;
|
53 | goOnline(): void;
|
54 | ref(path?: string | Reference): Reference;
|
55 | refFromURL(url: string): Reference;
|
56 | }
|
57 |
|
58 | export class FirebaseDatabase implements Database {
|
59 | private constructor();
|
60 | app: FirebaseApp;
|
61 | useEmulator(
|
62 | host: string,
|
63 | port: number,
|
64 | options?: {
|
65 | mockUserToken?: EmulatorMockTokenOptions | string;
|
66 | }
|
67 | ): void;
|
68 | goOffline(): void;
|
69 | goOnline(): void;
|
70 | ref(path?: string | Reference): Reference;
|
71 | refFromURL(url: string): Reference;
|
72 | }
|
73 |
|
74 | export interface OnDisconnect {
|
75 | cancel(onComplete?: (a: Error | null) => any): Promise<void>;
|
76 | remove(onComplete?: (a: Error | null) => any): Promise<void>;
|
77 | set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
|
78 | setWithPriority(
|
79 | value: any,
|
80 | priority: number | string | null,
|
81 | onComplete?: (a: Error | null) => any
|
82 | ): Promise<any>;
|
83 | update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
|
84 | }
|
85 |
|
86 | type EventType =
|
87 | | 'value'
|
88 | | 'child_added'
|
89 | | 'child_changed'
|
90 | | 'child_moved'
|
91 | | 'child_removed';
|
92 |
|
93 | export interface Query {
|
94 | endBefore(value: number | string | boolean | null, key?: string): Query;
|
95 | endAt(value: number | string | boolean | null, key?: string): Query;
|
96 | equalTo(value: number | string | boolean | null, key?: string): Query;
|
97 | isEqual(other: Query | null): boolean;
|
98 | limitToFirst(limit: number): Query;
|
99 | limitToLast(limit: number): Query;
|
100 | off(
|
101 | eventType?: EventType,
|
102 | callback?: (a: DataSnapshot, b?: string | null) => any,
|
103 | context?: Object | null
|
104 | ): void;
|
105 | get(): Promise<DataSnapshot>;
|
106 | on(
|
107 | eventType: EventType,
|
108 | callback: (a: DataSnapshot, b?: string | null) => any,
|
109 | cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
|
110 | context?: Object | null
|
111 | ): (a: DataSnapshot | null, b?: string | null) => any;
|
112 | once(
|
113 | eventType: EventType,
|
114 | successCallback?: (a: DataSnapshot, b?: string | null) => any,
|
115 | failureCallbackOrContext?: ((a: Error) => void) | Object | null,
|
116 | context?: Object | null
|
117 | ): Promise<DataSnapshot>;
|
118 | orderByChild(path: string): Query;
|
119 | orderByKey(): Query;
|
120 | orderByPriority(): Query;
|
121 | orderByValue(): Query;
|
122 | ref: Reference;
|
123 | startAt(value: number | string | boolean | null, key?: string): Query;
|
124 | startAfter(value: number | string | boolean | null, key?: string): Query;
|
125 | toJSON(): Object;
|
126 | toString(): string;
|
127 | }
|
128 |
|
129 | export interface Reference extends Query {
|
130 | child(path: string): Reference;
|
131 | key: string | null;
|
132 | onDisconnect(): OnDisconnect;
|
133 | parent: Reference | null;
|
134 | push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
|
135 | remove(onComplete?: (a: Error | null) => void): Promise<void>;
|
136 | root: Reference;
|
137 | set(value: any, onComplete?: (a: Error | null) => void): Promise<void>;
|
138 | setPriority(
|
139 | priority: string | number | null,
|
140 | onComplete: (a: Error | null) => void
|
141 | ): Promise<void>;
|
142 | setWithPriority(
|
143 | newVal: any,
|
144 | newPriority: string | number | null,
|
145 | onComplete?: (a: Error | null) => void
|
146 | ): Promise<void>;
|
147 | transaction(
|
148 | transactionUpdate: (a: any) => any,
|
149 | onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => void,
|
150 | applyLocally?: boolean
|
151 | ): Promise<TransactionResult>;
|
152 | update(values: Object, onComplete?: (a: Error | null) => void): Promise<void>;
|
153 | }
|
154 |
|
155 | export interface ServerValue {
|
156 | TIMESTAMP: Object;
|
157 | increment(delta: number): Object;
|
158 | }
|
159 |
|
160 | export interface TransactionResult {
|
161 | committed: boolean;
|
162 | snapshot: DataSnapshot;
|
163 | }
|
164 |
|
165 | export interface ThenableReference
|
166 | extends Reference,
|
167 | Pick<Promise<Reference>, 'then' | 'catch'> {}
|
168 |
|
169 | export function enableLogging(
|
170 | logger?: boolean | ((a: string) => any),
|
171 | persistent?: boolean
|
172 | ): any;
|
173 |
|
174 | declare module '@firebase/component' {
|
175 | interface NameServiceMapping {
|
176 | 'database-compat': FirebaseDatabase;
|
177 | }
|
178 | }
|
179 |
|
\ | No newline at end of file |