@firebase/util 1.4.3 → 1.5.0-canary.3198d58dc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/util.d.ts ADDED
@@ -0,0 +1,911 @@
1
+
2
+ /**
3
+ *
4
+ * This method checks whether cookie is enabled within current browser
5
+ * @return true if cookie is enabled within current browser
6
+ */
7
+ export declare function areCookiesEnabled(): boolean;
8
+
9
+ /**
10
+ * Throws an error if the provided assertion is falsy
11
+ */
12
+ export declare const assert: (assertion: unknown, message: string) => void;
13
+
14
+ /**
15
+ * Returns an Error object suitable for throwing.
16
+ */
17
+ export declare const assertionError: (message: string) => Error;
18
+
19
+ /** Turn synchronous function into one called asynchronously. */
20
+ export declare function async(fn: Function, onError?: ErrorFn): Function;
21
+
22
+ /**
23
+ * @license
24
+ * Copyright 2017 Google LLC
25
+ *
26
+ * Licensed under the Apache License, Version 2.0 (the "License");
27
+ * you may not use this file except in compliance with the License.
28
+ * You may obtain a copy of the License at
29
+ *
30
+ * http://www.apache.org/licenses/LICENSE-2.0
31
+ *
32
+ * Unless required by applicable law or agreed to in writing, software
33
+ * distributed under the License is distributed on an "AS IS" BASIS,
34
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
+ * See the License for the specific language governing permissions and
36
+ * limitations under the License.
37
+ */
38
+ declare interface Base64 {
39
+ byteToCharMap_: {
40
+ [key: number]: string;
41
+ } | null;
42
+ charToByteMap_: {
43
+ [key: string]: number;
44
+ } | null;
45
+ byteToCharMapWebSafe_: {
46
+ [key: number]: string;
47
+ } | null;
48
+ charToByteMapWebSafe_: {
49
+ [key: string]: number;
50
+ } | null;
51
+ ENCODED_VALS_BASE: string;
52
+ readonly ENCODED_VALS: string;
53
+ readonly ENCODED_VALS_WEBSAFE: string;
54
+ HAS_NATIVE_SUPPORT: boolean;
55
+ encodeByteArray(input: number[] | Uint8Array, webSafe?: boolean): string;
56
+ encodeString(input: string, webSafe?: boolean): string;
57
+ decodeString(input: string, webSafe: boolean): string;
58
+ decodeStringToByteArray(input: string, webSafe: boolean): number[];
59
+ init_(): void;
60
+ }
61
+
62
+ export declare const base64: Base64;
63
+
64
+ /**
65
+ * URL-safe base64 decoding
66
+ *
67
+ * NOTE: DO NOT use the global atob() function - it does NOT support the
68
+ * base64Url variant encoding.
69
+ *
70
+ * @param str To be decoded
71
+ * @return Decoded result, if possible
72
+ */
73
+ export declare const base64Decode: (str: string) => string | null;
74
+
75
+ /**
76
+ * URL-safe base64 encoding
77
+ */
78
+ export declare const base64Encode: (str: string) => string;
79
+
80
+ /**
81
+ * URL-safe base64 encoding (without "." padding in the end).
82
+ * e.g. Used in JSON Web Token (JWT) parts.
83
+ */
84
+ export declare const base64urlEncodeWithoutPadding: (str: string) => string;
85
+
86
+ /**
87
+ * Based on the backoff method from
88
+ * https://github.com/google/closure-library/blob/master/closure/goog/math/exponentialbackoff.js.
89
+ * Extracted here so we don't need to pass metadata and a stateful ExponentialBackoff object around.
90
+ */
91
+ export declare function calculateBackoffMillis(backoffCount: number, intervalMillis?: number, backoffFactor?: number): number;
92
+
93
+ /**
94
+ * @license
95
+ * Copyright 2017 Google LLC
96
+ *
97
+ * Licensed under the Apache License, Version 2.0 (the "License");
98
+ * you may not use this file except in compliance with the License.
99
+ * You may obtain a copy of the License at
100
+ *
101
+ * http://www.apache.org/licenses/LICENSE-2.0
102
+ *
103
+ * Unless required by applicable law or agreed to in writing, software
104
+ * distributed under the License is distributed on an "AS IS" BASIS,
105
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106
+ * See the License for the specific language governing permissions and
107
+ * limitations under the License.
108
+ */
109
+ declare interface Claims {
110
+ [key: string]: {};
111
+ }
112
+
113
+ /**
114
+ * @license
115
+ * Copyright 2021 Google LLC
116
+ *
117
+ * Licensed under the Apache License, Version 2.0 (the "License");
118
+ * you may not use this file except in compliance with the License.
119
+ * You may obtain a copy of the License at
120
+ *
121
+ * http://www.apache.org/licenses/LICENSE-2.0
122
+ *
123
+ * Unless required by applicable law or agreed to in writing, software
124
+ * distributed under the License is distributed on an "AS IS" BASIS,
125
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126
+ * See the License for the specific language governing permissions and
127
+ * limitations under the License.
128
+ */
129
+ export declare interface Compat<T> {
130
+ _delegate: T;
131
+ }
132
+
133
+ export declare type CompleteFn = () => void;
134
+
135
+ /**
136
+ * @fileoverview Firebase constants. Some of these (@defines) can be overridden at compile-time.
137
+ */
138
+ export declare const CONSTANTS: {
139
+ /**
140
+ * @define {boolean} Whether this is the client Node.js SDK.
141
+ */
142
+ NODE_CLIENT: boolean;
143
+ /**
144
+ * @define {boolean} Whether this is the Admin Node.js SDK.
145
+ */
146
+ NODE_ADMIN: boolean;
147
+ /**
148
+ * Firebase SDK Version
149
+ */
150
+ SDK_VERSION: string;
151
+ };
152
+
153
+ /**
154
+ * @license
155
+ * Copyright 2017 Google LLC
156
+ *
157
+ * Licensed under the Apache License, Version 2.0 (the "License");
158
+ * you may not use this file except in compliance with the License.
159
+ * You may obtain a copy of the License at
160
+ *
161
+ * http://www.apache.org/licenses/LICENSE-2.0
162
+ *
163
+ * Unless required by applicable law or agreed to in writing, software
164
+ * distributed under the License is distributed on an "AS IS" BASIS,
165
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166
+ * See the License for the specific language governing permissions and
167
+ * limitations under the License.
168
+ */
169
+ export declare function contains<T extends object>(obj: T, key: string): boolean;
170
+
171
+ export declare function createMockUserToken(token: EmulatorMockTokenOptions, projectId?: string): string;
172
+
173
+ /**
174
+ * Helper to make a Subscribe function (just like Promise helps make a
175
+ * Thenable).
176
+ *
177
+ * @param executor Function which can make calls to a single Observer
178
+ * as a proxy.
179
+ * @param onNoObservers Callback when count of Observers goes to zero.
180
+ */
181
+ export declare function createSubscribe<T>(executor: Executor<T>, onNoObservers?: Executor<T>): Subscribe<T>;
182
+
183
+ /**
184
+ * @license
185
+ * Copyright 2022 Google LLC
186
+ *
187
+ * Licensed under the Apache License, Version 2.0 (the "License");
188
+ * you may not use this file except in compliance with the License.
189
+ * You may obtain a copy of the License at
190
+ *
191
+ * http://www.apache.org/licenses/LICENSE-2.0
192
+ *
193
+ * Unless required by applicable law or agreed to in writing, software
194
+ * distributed under the License is distributed on an "AS IS" BASIS,
195
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
+ * See the License for the specific language governing permissions and
197
+ * limitations under the License.
198
+ */
199
+ /**
200
+ * @internal
201
+ */
202
+ export declare class DBWrapper {
203
+ private _db;
204
+ objectStoreNames: DOMStringList;
205
+ constructor(_db: IDBDatabase);
206
+ transaction(storeNames: string[] | string, mode?: IDBTransactionMode): TransactionWrapper;
207
+ createObjectStore(storeName: string, options?: IDBObjectStoreParameters): ObjectStoreWrapper;
208
+ close(): void;
209
+ }
210
+
211
+ /**
212
+ * Decodes a Firebase auth. token into constituent parts.
213
+ *
214
+ * Notes:
215
+ * - May return with invalid / incomplete claims if there's no native base64 decoding support.
216
+ * - Doesn't check if the token is actually valid.
217
+ */
218
+ export declare const decode: (token: string) => DecodedToken;
219
+
220
+ declare interface DecodedToken {
221
+ header: object;
222
+ claims: Claims;
223
+ data: object;
224
+ signature: string;
225
+ }
226
+
227
+ declare interface DecodedToken {
228
+ header: object;
229
+ claims: Claims;
230
+ data: object;
231
+ signature: string;
232
+ }
233
+
234
+ /**
235
+ * @license
236
+ * Copyright 2017 Google LLC
237
+ *
238
+ * Licensed under the Apache License, Version 2.0 (the "License");
239
+ * you may not use this file except in compliance with the License.
240
+ * You may obtain a copy of the License at
241
+ *
242
+ * http://www.apache.org/licenses/LICENSE-2.0
243
+ *
244
+ * Unless required by applicable law or agreed to in writing, software
245
+ * distributed under the License is distributed on an "AS IS" BASIS,
246
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
247
+ * See the License for the specific language governing permissions and
248
+ * limitations under the License.
249
+ */
250
+ /**
251
+ * Do a deep-copy of basic JavaScript Objects or Arrays.
252
+ */
253
+ export declare function deepCopy<T>(value: T): T;
254
+
255
+ /**
256
+ * Deep equal two objects. Support Arrays and Objects.
257
+ */
258
+ export declare function deepEqual(a: object, b: object): boolean;
259
+
260
+ /**
261
+ * Copy properties from source to target (recursively allows extension
262
+ * of Objects and Arrays). Scalar values in the target are over-written.
263
+ * If target is undefined, an object of the appropriate type will be created
264
+ * (and returned).
265
+ *
266
+ * We recursively copy all child properties of plain Objects in the source- so
267
+ * that namespace- like dictionaries are merged.
268
+ *
269
+ * Note that the target can be a function, in which case the properties in
270
+ * the source Object are copied onto it as static properties of the Function.
271
+ *
272
+ * Note: we don't merge __proto__ to prevent prototype pollution
273
+ */
274
+ export declare function deepExtend(target: unknown, source: unknown): unknown;
275
+
276
+ /**
277
+ * @license
278
+ * Copyright 2017 Google LLC
279
+ *
280
+ * Licensed under the Apache License, Version 2.0 (the "License");
281
+ * you may not use this file except in compliance with the License.
282
+ * You may obtain a copy of the License at
283
+ *
284
+ * http://www.apache.org/licenses/LICENSE-2.0
285
+ *
286
+ * Unless required by applicable law or agreed to in writing, software
287
+ * distributed under the License is distributed on an "AS IS" BASIS,
288
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
289
+ * See the License for the specific language governing permissions and
290
+ * limitations under the License.
291
+ */
292
+ export declare class Deferred<R> {
293
+ promise: Promise<R>;
294
+ reject: (value?: unknown) => void;
295
+ resolve: (value?: unknown) => void;
296
+ constructor();
297
+ /**
298
+ * Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
299
+ * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
300
+ * and returns a node-style callback which will resolve or reject the Deferred's promise.
301
+ */
302
+ wrapCallback(callback?: (error?: unknown, value?: unknown) => void): (error: unknown, value?: unknown) => void;
303
+ }
304
+
305
+ /**
306
+ * @internal
307
+ */
308
+ export declare function deleteDB(dbName: string): Promise<void>;
309
+
310
+ export declare type EmulatorMockTokenOptions = ({
311
+ user_id: string;
312
+ } | {
313
+ sub: string;
314
+ }) & Partial<FirebaseIdToken>;
315
+
316
+ export declare interface ErrorData {
317
+ [key: string]: unknown;
318
+ }
319
+
320
+ export declare class ErrorFactory<ErrorCode extends string, ErrorParams extends {
321
+ readonly [K in ErrorCode]?: ErrorData;
322
+ } = {}> {
323
+ private readonly service;
324
+ private readonly serviceName;
325
+ private readonly errors;
326
+ constructor(service: string, serviceName: string, errors: ErrorMap<ErrorCode>);
327
+ create<K extends ErrorCode>(code: K, ...data: K extends keyof ErrorParams ? [ErrorParams[K]] : []): FirebaseError;
328
+ }
329
+
330
+ export declare type ErrorFn = (error: Error) => void;
331
+
332
+ /**
333
+ * @license
334
+ * Copyright 2017 Google LLC
335
+ *
336
+ * Licensed under the Apache License, Version 2.0 (the "License");
337
+ * you may not use this file except in compliance with the License.
338
+ * You may obtain a copy of the License at
339
+ *
340
+ * http://www.apache.org/licenses/LICENSE-2.0
341
+ *
342
+ * Unless required by applicable law or agreed to in writing, software
343
+ * distributed under the License is distributed on an "AS IS" BASIS,
344
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
345
+ * See the License for the specific language governing permissions and
346
+ * limitations under the License.
347
+ */
348
+ /**
349
+ * @fileoverview Standardized Firebase Error.
350
+ *
351
+ * Usage:
352
+ *
353
+ * // Typescript string literals for type-safe codes
354
+ * type Err =
355
+ * 'unknown' |
356
+ * 'object-not-found'
357
+ * ;
358
+ *
359
+ * // Closure enum for type-safe error codes
360
+ * // at-enum {string}
361
+ * var Err = {
362
+ * UNKNOWN: 'unknown',
363
+ * OBJECT_NOT_FOUND: 'object-not-found',
364
+ * }
365
+ *
366
+ * let errors: Map<Err, string> = {
367
+ * 'generic-error': "Unknown error",
368
+ * 'file-not-found': "Could not find file: {$file}",
369
+ * };
370
+ *
371
+ * // Type-safe function - must pass a valid error code as param.
372
+ * let error = new ErrorFactory<Err>('service', 'Service', errors);
373
+ *
374
+ * ...
375
+ * throw error.create(Err.GENERIC);
376
+ * ...
377
+ * throw error.create(Err.FILE_NOT_FOUND, {'file': fileName});
378
+ * ...
379
+ * // Service: Could not file file: foo.txt (service/file-not-found).
380
+ *
381
+ * catch (e) {
382
+ * assert(e.message === "Could not find file: foo.txt.");
383
+ * if (e.code === 'service/file-not-found') {
384
+ * console.log("Could not read file: " + e['file']);
385
+ * }
386
+ * }
387
+ */
388
+ export declare type ErrorMap<ErrorCode extends string> = {
389
+ readonly [K in ErrorCode]: string;
390
+ };
391
+
392
+ /**
393
+ * Generates a string to prefix an error message about failed argument validation
394
+ *
395
+ * @param fnName The function name
396
+ * @param argName The name of the argument
397
+ * @return The prefix to add to the error thrown for validation.
398
+ */
399
+ export declare function errorPrefix(fnName: string, argName: string): string;
400
+
401
+ export declare type Executor<T> = (observer: Observer<T>) => void;
402
+
403
+ /**
404
+ * Extract the query string part of a URL, including the leading question mark (if present).
405
+ */
406
+ export declare function extractQuerystring(url: string): string;
407
+
408
+ export declare class FirebaseError extends Error {
409
+ /** The error code for this error. */
410
+ readonly code: string;
411
+ /** Custom data for this error. */
412
+ customData?: Record<string, unknown> | undefined;
413
+ /** The custom name for all FirebaseErrors. */
414
+ readonly name: string;
415
+ constructor(
416
+ /** The error code for this error. */
417
+ code: string, message: string,
418
+ /** Custom data for this error. */
419
+ customData?: Record<string, unknown> | undefined);
420
+ }
421
+
422
+ declare interface FirebaseIdToken {
423
+ iss: string;
424
+ aud: string;
425
+ sub: string;
426
+ iat: number;
427
+ exp: number;
428
+ user_id: string;
429
+ auth_time: number;
430
+ provider_id?: 'anonymous';
431
+ email?: string;
432
+ email_verified?: boolean;
433
+ phone_number?: string;
434
+ name?: string;
435
+ picture?: string;
436
+ firebase: {
437
+ sign_in_provider: FirebaseSignInProvider;
438
+ identities?: {
439
+ [provider in FirebaseSignInProvider]?: string[];
440
+ };
441
+ };
442
+ [claim: string]: unknown;
443
+ uid?: never;
444
+ }
445
+
446
+ /**
447
+ * @license
448
+ * Copyright 2021 Google LLC
449
+ *
450
+ * Licensed under the Apache License, Version 2.0 (the "License");
451
+ * you may not use this file except in compliance with the License.
452
+ * You may obtain a copy of the License at
453
+ *
454
+ * http://www.apache.org/licenses/LICENSE-2.0
455
+ *
456
+ * Unless required by applicable law or agreed to in writing, software
457
+ * distributed under the License is distributed on an "AS IS" BASIS,
458
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
459
+ * See the License for the specific language governing permissions and
460
+ * limitations under the License.
461
+ */
462
+ export declare type FirebaseSignInProvider = 'custom' | 'email' | 'password' | 'phone' | 'anonymous' | 'google.com' | 'facebook.com' | 'github.com' | 'twitter.com' | 'microsoft.com' | 'apple.com';
463
+
464
+ /**
465
+ * Polyfill for `globalThis` object.
466
+ * @returns the `globalThis` object for the given environment.
467
+ */
468
+ export declare function getGlobal(): typeof globalThis;
469
+
470
+ export declare function getModularInstance<ExpService>(service: Compat<ExpService> | ExpService): ExpService;
471
+
472
+ /**
473
+ * @license
474
+ * Copyright 2017 Google LLC
475
+ *
476
+ * Licensed under the Apache License, Version 2.0 (the "License");
477
+ * you may not use this file except in compliance with the License.
478
+ * You may obtain a copy of the License at
479
+ *
480
+ * http://www.apache.org/licenses/LICENSE-2.0
481
+ *
482
+ * Unless required by applicable law or agreed to in writing, software
483
+ * distributed under the License is distributed on an "AS IS" BASIS,
484
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
485
+ * See the License for the specific language governing permissions and
486
+ * limitations under the License.
487
+ */
488
+ /**
489
+ * Returns navigator.userAgent string or '' if it's not defined.
490
+ * @return user agent string
491
+ */
492
+ export declare function getUA(): string;
493
+
494
+ /**
495
+ * @internal
496
+ */
497
+ declare class IndexWrapper {
498
+ private _index;
499
+ constructor(_index: IDBIndex);
500
+ get(key: string): Promise<unknown>;
501
+ }
502
+
503
+ /**
504
+ * Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
505
+ *
506
+ * Notes:
507
+ * - May return a false negative if there's no native base64 decoding support.
508
+ * - Doesn't check if the token is actually valid.
509
+ */
510
+ export declare const isAdmin: (token: string) => boolean;
511
+
512
+ /**
513
+ * Detect Browser Environment
514
+ */
515
+ export declare function isBrowser(): boolean;
516
+
517
+ export declare function isBrowserExtension(): boolean;
518
+
519
+ /** Detects Electron apps. */
520
+ export declare function isElectron(): boolean;
521
+
522
+ export declare function isEmpty(obj: object): obj is {};
523
+
524
+ /** Detects Internet Explorer. */
525
+ export declare function isIE(): boolean;
526
+
527
+ /**
528
+ * This method checks if indexedDB is supported by current browser/service worker context
529
+ * @return true if indexedDB is supported by current browser/service worker context
530
+ */
531
+ export declare function isIndexedDBAvailable(): boolean;
532
+
533
+ /**
534
+ * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
535
+ *
536
+ * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
537
+ * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
538
+ * wait for a callback.
539
+ */
540
+ export declare function isMobileCordova(): boolean;
541
+
542
+ /**
543
+ * Detect Node.js.
544
+ *
545
+ * @return true if Node.js environment is detected.
546
+ */
547
+ export declare function isNode(): boolean;
548
+
549
+ /**
550
+ * Detect whether the current SDK build is the Node version.
551
+ *
552
+ * @return true if it's the Node SDK build.
553
+ */
554
+ export declare function isNodeSdk(): boolean;
555
+
556
+ /**
557
+ * Detect React Native.
558
+ *
559
+ * @return true if ReactNative environment is detected.
560
+ */
561
+ export declare function isReactNative(): boolean;
562
+
563
+ /** Returns true if we are running in Safari. */
564
+ export declare function isSafari(): boolean;
565
+
566
+ /**
567
+ * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
568
+ *
569
+ * Notes:
570
+ * - May return null if there's no native base64 decoding support.
571
+ * - Doesn't check if the token is actually valid.
572
+ */
573
+ export declare const issuedAtTime: (token: string) => number | null;
574
+
575
+ /** Detects Universal Windows Platform apps. */
576
+ export declare function isUWP(): boolean;
577
+
578
+ /**
579
+ * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
580
+ *
581
+ * Notes:
582
+ * - May return a false negative if there's no native base64 decoding support.
583
+ * - Doesn't check if the token is actually valid.
584
+ */
585
+ export declare const isValidFormat: (token: string) => boolean;
586
+
587
+ /**
588
+ * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
589
+ * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
590
+ *
591
+ * Notes:
592
+ * - May return a false negative if there's no native base64 decoding support.
593
+ * - Doesn't check if the token is actually valid.
594
+ */
595
+ export declare const isValidTimestamp: (token: string) => boolean;
596
+
597
+ /**
598
+ * @license
599
+ * Copyright 2017 Google LLC
600
+ *
601
+ * Licensed under the Apache License, Version 2.0 (the "License");
602
+ * you may not use this file except in compliance with the License.
603
+ * You may obtain a copy of the License at
604
+ *
605
+ * http://www.apache.org/licenses/LICENSE-2.0
606
+ *
607
+ * Unless required by applicable law or agreed to in writing, software
608
+ * distributed under the License is distributed on an "AS IS" BASIS,
609
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
610
+ * See the License for the specific language governing permissions and
611
+ * limitations under the License.
612
+ */
613
+ /**
614
+ * Evaluates a JSON string into a javascript object.
615
+ *
616
+ * @param {string} str A string containing JSON.
617
+ * @return {*} The javascript object representing the specified JSON.
618
+ */
619
+ export declare function jsonEval(str: string): unknown;
620
+
621
+ export declare function map<K extends string, V, U>(obj: {
622
+ [key in K]: V;
623
+ }, fn: (value: V, key: K, obj: {
624
+ [key in K]: V;
625
+ }) => U, contextObj?: unknown): {
626
+ [key in K]: U;
627
+ };
628
+
629
+ /**
630
+ * The maximum milliseconds to increase to.
631
+ *
632
+ * <p>Visible for testing
633
+ */
634
+ export declare const MAX_VALUE_MILLIS: number;
635
+
636
+ /**
637
+ * @license
638
+ * Copyright 2017 Google LLC
639
+ *
640
+ * Licensed under the Apache License, Version 2.0 (the "License");
641
+ * you may not use this file except in compliance with the License.
642
+ * You may obtain a copy of the License at
643
+ *
644
+ * http://www.apache.org/licenses/LICENSE-2.0
645
+ *
646
+ * Unless required by applicable law or agreed to in writing, software
647
+ * distributed under the License is distributed on an "AS IS" BASIS,
648
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
649
+ * See the License for the specific language governing permissions and
650
+ * limitations under the License.
651
+ */
652
+ export declare type NextFn<T> = (value: T) => void;
653
+
654
+ /**
655
+ * @internal
656
+ */
657
+ declare class ObjectStoreWrapper {
658
+ private _store;
659
+ constructor(_store: IDBObjectStore);
660
+ index(name: string): IndexWrapper;
661
+ createIndex(name: string, keypath: string, options: IDBIndexParameters): IndexWrapper;
662
+ get(key: string): Promise<unknown>;
663
+ put(value: unknown, key?: string): Promise<unknown>;
664
+ delete(key: string): Promise<unknown>;
665
+ clear(): Promise<unknown>;
666
+ }
667
+
668
+ export declare interface Observable<T> {
669
+ subscribe: Subscribe<T>;
670
+ }
671
+
672
+ export declare interface Observer<T> {
673
+ next: NextFn<T>;
674
+ error: ErrorFn;
675
+ complete: CompleteFn;
676
+ }
677
+
678
+ /**
679
+ * @internal
680
+ */
681
+ export declare function openDB(dbName: string, dbVersion: number, upgradeCallback: (db: DBWrapper, oldVersion: number, newVersion: number | null, transaction: TransactionWrapper) => void): Promise<DBWrapper>;
682
+
683
+ /**
684
+ * @license
685
+ * Copyright 2020 Google LLC
686
+ *
687
+ * Licensed under the Apache License, Version 2.0 (the "License");
688
+ * you may not use this file except in compliance with the License.
689
+ * You may obtain a copy of the License at
690
+ *
691
+ * http://www.apache.org/licenses/LICENSE-2.0
692
+ *
693
+ * Unless required by applicable law or agreed to in writing, software
694
+ * distributed under the License is distributed on an "AS IS" BASIS,
695
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
696
+ * See the License for the specific language governing permissions and
697
+ * limitations under the License.
698
+ */
699
+ /**
700
+ * Provide English ordinal letters after a number
701
+ */
702
+ export declare function ordinal(i: number): string;
703
+
704
+ export declare type PartialObserver<T> = Partial<Observer<T>>;
705
+
706
+ /**
707
+ * @license
708
+ * Copyright 2017 Google LLC
709
+ *
710
+ * Licensed under the Apache License, Version 2.0 (the "License");
711
+ * you may not use this file except in compliance with the License.
712
+ * You may obtain a copy of the License at
713
+ *
714
+ * http://www.apache.org/licenses/LICENSE-2.0
715
+ *
716
+ * Unless required by applicable law or agreed to in writing, software
717
+ * distributed under the License is distributed on an "AS IS" BASIS,
718
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
719
+ * See the License for the specific language governing permissions and
720
+ * limitations under the License.
721
+ */
722
+ /**
723
+ * Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a
724
+ * params object (e.g. {arg: 'val', arg2: 'val2'})
725
+ * Note: You must prepend it with ? when adding it to a URL.
726
+ */
727
+ export declare function querystring(querystringParams: {
728
+ [key: string]: string | number;
729
+ }): string;
730
+
731
+ /**
732
+ * Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object
733
+ * (e.g. {arg: 'val', arg2: 'val2'})
734
+ */
735
+ export declare function querystringDecode(querystring: string): Record<string, string>;
736
+
737
+ /**
738
+ * The percentage of backoff time to randomize by.
739
+ * See
740
+ * http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
741
+ * for context.
742
+ *
743
+ * <p>Visible for testing
744
+ */
745
+ export declare const RANDOM_FACTOR = 0.5;
746
+
747
+ export declare function safeGet<T extends object, K extends keyof T>(obj: T, key: K): T[K] | undefined;
748
+
749
+ /**
750
+ * @license
751
+ * Copyright 2017 Google LLC
752
+ *
753
+ * Licensed under the Apache License, Version 2.0 (the "License");
754
+ * you may not use this file except in compliance with the License.
755
+ * You may obtain a copy of the License at
756
+ *
757
+ * http://www.apache.org/licenses/LICENSE-2.0
758
+ *
759
+ * Unless required by applicable law or agreed to in writing, software
760
+ * distributed under the License is distributed on an "AS IS" BASIS,
761
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
762
+ * See the License for the specific language governing permissions and
763
+ * limitations under the License.
764
+ */
765
+ /**
766
+ * @fileoverview SHA-1 cryptographic hash.
767
+ * Variable names follow the notation in FIPS PUB 180-3:
768
+ * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
769
+ *
770
+ * Usage:
771
+ * var sha1 = new sha1();
772
+ * sha1.update(bytes);
773
+ * var hash = sha1.digest();
774
+ *
775
+ * Performance:
776
+ * Chrome 23: ~400 Mbit/s
777
+ * Firefox 16: ~250 Mbit/s
778
+ *
779
+ */
780
+ /**
781
+ * SHA-1 cryptographic hash constructor.
782
+ *
783
+ * The properties declared here are discussed in the above algorithm document.
784
+ * @constructor
785
+ * @final
786
+ * @struct
787
+ */
788
+ export declare class Sha1 {
789
+ /**
790
+ * Holds the previous values of accumulated variables a-e in the compress_
791
+ * function.
792
+ * @private
793
+ */
794
+ private chain_;
795
+ /**
796
+ * A buffer holding the partially computed hash result.
797
+ * @private
798
+ */
799
+ private buf_;
800
+ /**
801
+ * An array of 80 bytes, each a part of the message to be hashed. Referred to
802
+ * as the message schedule in the docs.
803
+ * @private
804
+ */
805
+ private W_;
806
+ /**
807
+ * Contains data needed to pad messages less than 64 bytes.
808
+ * @private
809
+ */
810
+ private pad_;
811
+ /**
812
+ * @private {number}
813
+ */
814
+ private inbuf_;
815
+ /**
816
+ * @private {number}
817
+ */
818
+ private total_;
819
+ blockSize: number;
820
+ constructor();
821
+ reset(): void;
822
+ /**
823
+ * Internal compress helper function.
824
+ * @param buf Block to compress.
825
+ * @param offset Offset of the block in the buffer.
826
+ * @private
827
+ */
828
+ compress_(buf: number[] | Uint8Array | string, offset?: number): void;
829
+ update(bytes?: number[] | Uint8Array | string, length?: number): void;
830
+ /** @override */
831
+ digest(): number[];
832
+ }
833
+
834
+ /**
835
+ * Returns JSON representing a javascript object.
836
+ * @param {*} data Javascript object to be stringified.
837
+ * @return {string} The JSON contents of the object.
838
+ */
839
+ export declare function stringify(data: unknown): string;
840
+
841
+ /**
842
+ * Calculate length without actually converting; useful for doing cheaper validation.
843
+ * @param {string} str
844
+ * @return {number}
845
+ */
846
+ export declare const stringLength: (str: string) => number;
847
+
848
+ export declare interface StringLike {
849
+ toString(): string;
850
+ }
851
+
852
+ /**
853
+ * @param {string} str
854
+ * @return {Array}
855
+ */
856
+ export declare const stringToByteArray: (str: string) => number[];
857
+
858
+ /**
859
+ * The Subscribe interface has two forms - passing the inline function
860
+ * callbacks, or a object interface with callback properties.
861
+ */
862
+ export declare interface Subscribe<T> {
863
+ (next?: NextFn<T>, error?: ErrorFn, complete?: CompleteFn): Unsubscribe;
864
+ (observer: PartialObserver<T>): Unsubscribe;
865
+ }
866
+
867
+ /**
868
+ * @internal
869
+ */
870
+ declare class TransactionWrapper {
871
+ private _transaction;
872
+ complete: Promise<void>;
873
+ constructor(_transaction: IDBTransaction);
874
+ objectStore(storeName: string): ObjectStoreWrapper;
875
+ }
876
+
877
+ export declare type Unsubscribe = () => void;
878
+
879
+ /**
880
+ * Check to make sure the appropriate number of arguments are provided for a public function.
881
+ * Throws an error if it fails.
882
+ *
883
+ * @param fnName The function name
884
+ * @param minCount The minimum number of arguments to allow for the function call
885
+ * @param maxCount The maximum number of argument to allow for the function call
886
+ * @param argCount The actual number of arguments provided.
887
+ */
888
+ export declare const validateArgCount: (fnName: string, minCount: number, maxCount: number, argCount: number) => void;
889
+
890
+ export declare function validateCallback(fnName: string, argumentName: string, callback: Function, optional: boolean): void;
891
+
892
+ export declare function validateContextObject(fnName: string, argumentName: string, context: unknown, optional: boolean): void;
893
+
894
+ /**
895
+ * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
896
+ * if errors occur during the database open operation.
897
+ *
898
+ * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
899
+ * private browsing)
900
+ */
901
+ export declare function validateIndexedDBOpenable(): Promise<boolean>;
902
+
903
+ /**
904
+ * @param fnName
905
+ * @param argumentNumber
906
+ * @param namespace
907
+ * @param optional
908
+ */
909
+ export declare function validateNamespace(fnName: string, namespace: string, optional: boolean): void;
910
+
911
+ export { }