|
| 1 | +/** |
| 2 | + * Public types snapshot from the Firebase JS SDK (@firebase/database). |
| 3 | + * |
| 4 | + * Source: firebase-js-sdk API report for "@firebase/database" |
| 5 | + * Modality: modular (tree-shakeable) API only |
| 6 | + */ |
| 7 | + |
| 8 | +import { FirebaseApp } from '@firebase/app'; |
| 9 | + |
| 10 | +export declare type EmulatorMockTokenOptions = ({ user_id: string } | { sub: string }) & |
| 11 | + Partial<{ |
| 12 | + iss: string; |
| 13 | + aud: string; |
| 14 | + sub: string; |
| 15 | + iat: number; |
| 16 | + exp: number; |
| 17 | + user_id: string; |
| 18 | + auth_time: number; |
| 19 | + provider_id?: 'anonymous'; |
| 20 | + email?: string; |
| 21 | + email_verified?: boolean; |
| 22 | + phone_number?: string; |
| 23 | + name?: string; |
| 24 | + picture?: string; |
| 25 | + firebase: { |
| 26 | + sign_in_provider: |
| 27 | + | 'custom' |
| 28 | + | 'email' |
| 29 | + | 'password' |
| 30 | + | 'phone' |
| 31 | + | 'anonymous' |
| 32 | + | 'google.com' |
| 33 | + | 'facebook.com' |
| 34 | + | 'github.com' |
| 35 | + | 'twitter.com' |
| 36 | + | 'microsoft.com' |
| 37 | + | 'apple.com'; |
| 38 | + identities?: { |
| 39 | + custom?: string[]; |
| 40 | + email?: string[]; |
| 41 | + password?: string[]; |
| 42 | + phone?: string[]; |
| 43 | + anonymous?: string[]; |
| 44 | + 'google.com'?: string[]; |
| 45 | + 'facebook.com'?: string[]; |
| 46 | + 'github.com'?: string[]; |
| 47 | + 'twitter.com'?: string[]; |
| 48 | + 'microsoft.com'?: string[]; |
| 49 | + 'apple.com'?: string[]; |
| 50 | + }; |
| 51 | + }; |
| 52 | + uid?: never; |
| 53 | + [claim: string]: unknown; |
| 54 | + }>; |
| 55 | + |
| 56 | +export declare function child(parent: DatabaseReference, path: string): DatabaseReference; |
| 57 | + |
| 58 | +export declare function connectDatabaseEmulator( |
| 59 | + db: Database, |
| 60 | + host: string, |
| 61 | + port: number, |
| 62 | + options?: { |
| 63 | + mockUserToken?: EmulatorMockTokenOptions | string; |
| 64 | + }, |
| 65 | +): void; |
| 66 | + |
| 67 | +export declare class Database { |
| 68 | + readonly app: FirebaseApp; |
| 69 | + readonly type: 'database'; |
| 70 | +} |
| 71 | + |
| 72 | +export declare interface DatabaseReference extends Query { |
| 73 | + readonly key: string | null; |
| 74 | + readonly parent: DatabaseReference | null; |
| 75 | + readonly root: DatabaseReference; |
| 76 | +} |
| 77 | + |
| 78 | +export declare class DataSnapshot { |
| 79 | + readonly key: string | null; |
| 80 | + readonly priority: string | number | null; |
| 81 | + readonly ref: DatabaseReference; |
| 82 | + readonly size: number; |
| 83 | + child(path: string): DataSnapshot; |
| 84 | + exists(): boolean; |
| 85 | + exportVal(): any; |
| 86 | + forEach(action: (child: IteratedDataSnapshot) => boolean | void): boolean; |
| 87 | + hasChild(path: string): boolean; |
| 88 | + hasChildren(): boolean; |
| 89 | + toJSON(): object | null; |
| 90 | + val(): any; |
| 91 | +} |
| 92 | + |
| 93 | +export declare function enableLogging(enabled: boolean, persistent?: boolean): any; |
| 94 | +export declare function enableLogging(logger: (message: string) => unknown): any; |
| 95 | + |
| 96 | +export declare function endAt( |
| 97 | + value: number | string | boolean | null, |
| 98 | + key?: string, |
| 99 | +): QueryConstraint; |
| 100 | + |
| 101 | +export declare function endBefore( |
| 102 | + value: number | string | boolean | null, |
| 103 | + key?: string, |
| 104 | +): QueryConstraint; |
| 105 | + |
| 106 | +export declare function equalTo( |
| 107 | + value: number | string | boolean | null, |
| 108 | + key?: string, |
| 109 | +): QueryConstraint; |
| 110 | + |
| 111 | +export declare type EventType = |
| 112 | + | 'value' |
| 113 | + | 'child_added' |
| 114 | + | 'child_changed' |
| 115 | + | 'child_moved' |
| 116 | + | 'child_removed'; |
| 117 | + |
| 118 | +export declare function forceLongPolling(): void; |
| 119 | +export declare function forceWebSockets(): void; |
| 120 | + |
| 121 | +export declare function get(query: Query): Promise<DataSnapshot>; |
| 122 | +export declare function getDatabase(app?: FirebaseApp, url?: string): Database; |
| 123 | +export declare function goOffline(db: Database): void; |
| 124 | +export declare function goOnline(db: Database): void; |
| 125 | +export declare function increment(delta: number): object; |
| 126 | + |
| 127 | +export declare interface IteratedDataSnapshot extends DataSnapshot { |
| 128 | + key: string; |
| 129 | +} |
| 130 | + |
| 131 | +export declare function limitToFirst(limit: number): QueryConstraint; |
| 132 | +export declare function limitToLast(limit: number): QueryConstraint; |
| 133 | + |
| 134 | +export declare interface ListenOptions { |
| 135 | + readonly onlyOnce?: boolean; |
| 136 | +} |
| 137 | + |
| 138 | +export declare function off( |
| 139 | + query: Query, |
| 140 | + eventType?: EventType, |
| 141 | + callback?: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown, |
| 142 | +): void; |
| 143 | + |
| 144 | +export declare function onChildAdded( |
| 145 | + query: Query, |
| 146 | + callback: (snapshot: DataSnapshot, previousChildName?: string | null) => unknown, |
| 147 | + cancelCallback?: (error: Error) => unknown, |
| 148 | +): Unsubscribe; |
| 149 | +export declare function onChildAdded( |
| 150 | + query: Query, |
| 151 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 152 | + options: ListenOptions, |
| 153 | +): Unsubscribe; |
| 154 | +export declare function onChildAdded( |
| 155 | + query: Query, |
| 156 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 157 | + cancelCallback: (error: Error) => unknown, |
| 158 | + options: ListenOptions, |
| 159 | +): Unsubscribe; |
| 160 | + |
| 161 | +export declare function onChildChanged( |
| 162 | + query: Query, |
| 163 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 164 | + cancelCallback?: (error: Error) => unknown, |
| 165 | +): Unsubscribe; |
| 166 | +export declare function onChildChanged( |
| 167 | + query: Query, |
| 168 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 169 | + options: ListenOptions, |
| 170 | +): Unsubscribe; |
| 171 | +export declare function onChildChanged( |
| 172 | + query: Query, |
| 173 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 174 | + cancelCallback: (error: Error) => unknown, |
| 175 | + options: ListenOptions, |
| 176 | +): Unsubscribe; |
| 177 | + |
| 178 | +export declare function onChildMoved( |
| 179 | + query: Query, |
| 180 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 181 | + cancelCallback?: (error: Error) => unknown, |
| 182 | +): Unsubscribe; |
| 183 | +export declare function onChildMoved( |
| 184 | + query: Query, |
| 185 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 186 | + options: ListenOptions, |
| 187 | +): Unsubscribe; |
| 188 | +export declare function onChildMoved( |
| 189 | + query: Query, |
| 190 | + callback: (snapshot: DataSnapshot, previousChildName: string | null) => unknown, |
| 191 | + cancelCallback: (error: Error) => unknown, |
| 192 | + options: ListenOptions, |
| 193 | +): Unsubscribe; |
| 194 | + |
| 195 | +export declare function onChildRemoved( |
| 196 | + query: Query, |
| 197 | + callback: (snapshot: DataSnapshot) => unknown, |
| 198 | + cancelCallback?: (error: Error) => unknown, |
| 199 | +): Unsubscribe; |
| 200 | +export declare function onChildRemoved( |
| 201 | + query: Query, |
| 202 | + callback: (snapshot: DataSnapshot) => unknown, |
| 203 | + options: ListenOptions, |
| 204 | +): Unsubscribe; |
| 205 | +export declare function onChildRemoved( |
| 206 | + query: Query, |
| 207 | + callback: (snapshot: DataSnapshot) => unknown, |
| 208 | + cancelCallback: (error: Error) => unknown, |
| 209 | + options: ListenOptions, |
| 210 | +): Unsubscribe; |
| 211 | + |
| 212 | +export declare class OnDisconnect { |
| 213 | + cancel(): Promise<void>; |
| 214 | + remove(): Promise<void>; |
| 215 | + set(value: unknown): Promise<void>; |
| 216 | + setWithPriority(value: unknown, priority: string | number | null): Promise<void>; |
| 217 | + update(values: object): Promise<void>; |
| 218 | +} |
| 219 | + |
| 220 | +export declare function onDisconnect(ref: DatabaseReference): OnDisconnect; |
| 221 | + |
| 222 | +export declare function onValue( |
| 223 | + query: Query, |
| 224 | + callback: (snapshot: DataSnapshot) => unknown, |
| 225 | + cancelCallback?: (error: Error) => unknown, |
| 226 | +): Unsubscribe; |
| 227 | +export declare function onValue( |
| 228 | + query: Query, |
| 229 | + callback: (snapshot: DataSnapshot) => unknown, |
| 230 | + options: ListenOptions, |
| 231 | +): Unsubscribe; |
| 232 | +export declare function onValue( |
| 233 | + query: Query, |
| 234 | + callback: (snapshot: DataSnapshot) => unknown, |
| 235 | + cancelCallback: (error: Error) => unknown, |
| 236 | + options: ListenOptions, |
| 237 | +): Unsubscribe; |
| 238 | + |
| 239 | +export declare function orderByChild(path: string): QueryConstraint; |
| 240 | +export declare function orderByKey(): QueryConstraint; |
| 241 | +export declare function orderByPriority(): QueryConstraint; |
| 242 | +export declare function orderByValue(): QueryConstraint; |
| 243 | + |
| 244 | +export declare function push(parent: DatabaseReference, value?: unknown): ThenableReference; |
| 245 | + |
| 246 | +export declare interface Query { |
| 247 | + isEqual(other: Query | null): boolean; |
| 248 | + readonly ref: DatabaseReference; |
| 249 | + toJSON(): string; |
| 250 | + toString(): string; |
| 251 | +} |
| 252 | + |
| 253 | +export declare function query(query: Query, ...queryConstraints: QueryConstraint[]): Query; |
| 254 | + |
| 255 | +export declare abstract class QueryConstraint { |
| 256 | + abstract readonly type: QueryConstraintType; |
| 257 | +} |
| 258 | + |
| 259 | +export declare type QueryConstraintType = |
| 260 | + | 'endAt' |
| 261 | + | 'endBefore' |
| 262 | + | 'startAt' |
| 263 | + | 'startAfter' |
| 264 | + | 'limitToFirst' |
| 265 | + | 'limitToLast' |
| 266 | + | 'orderByChild' |
| 267 | + | 'orderByKey' |
| 268 | + | 'orderByPriority' |
| 269 | + | 'orderByValue' |
| 270 | + | 'equalTo'; |
| 271 | + |
| 272 | +export declare function ref(db: Database, path?: string): DatabaseReference; |
| 273 | +export declare function refFromURL(db: Database, url: string): DatabaseReference; |
| 274 | +export declare function remove(ref: DatabaseReference): Promise<void>; |
| 275 | + |
| 276 | +export declare function runTransaction( |
| 277 | + ref: DatabaseReference, |
| 278 | + transactionUpdate: (currentData: any) => unknown, |
| 279 | + options?: TransactionOptions, |
| 280 | +): Promise<TransactionResult>; |
| 281 | + |
| 282 | +export declare function serverTimestamp(): object; |
| 283 | +export declare function set(ref: DatabaseReference, value: unknown): Promise<void>; |
| 284 | +export declare function setPriority( |
| 285 | + ref: DatabaseReference, |
| 286 | + priority: string | number | null, |
| 287 | +): Promise<void>; |
| 288 | +export declare function setWithPriority( |
| 289 | + ref: DatabaseReference, |
| 290 | + value: unknown, |
| 291 | + priority: string | number | null, |
| 292 | +): Promise<void>; |
| 293 | + |
| 294 | +export declare function startAfter( |
| 295 | + value: number | string | boolean | null, |
| 296 | + key?: string, |
| 297 | +): QueryConstraint; |
| 298 | +export declare function startAt( |
| 299 | + value?: number | string | boolean | null, |
| 300 | + key?: string, |
| 301 | +): QueryConstraint; |
| 302 | + |
| 303 | +export declare interface ThenableReference |
| 304 | + extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> { |
| 305 | + key: string; |
| 306 | + parent: DatabaseReference; |
| 307 | +} |
| 308 | + |
| 309 | +export declare interface TransactionOptions { |
| 310 | + readonly applyLocally?: boolean; |
| 311 | +} |
| 312 | + |
| 313 | +export declare class TransactionResult { |
| 314 | + readonly committed: boolean; |
| 315 | + readonly snapshot: DataSnapshot; |
| 316 | + toJSON(): object; |
| 317 | +} |
| 318 | + |
| 319 | +export declare type Unsubscribe = () => void; |
| 320 | + |
| 321 | +export declare function update(ref: DatabaseReference, values: object): Promise<void>; |
0 commit comments