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 | */
|
17 | /**
|
18 | * This is part of a workaround for an issue in the no-modular '@firebase/database' where its typings
|
19 | * reference types from `@firebase/app-exp`.
|
20 | */
|
21 | declare type QueryContext = any;
|
22 | /**
|
23 | * Returns a locally-unique ID (generated by just incrementing up from 0 each time its called).
|
24 | */
|
25 | export declare const LUIDGenerator: () => number;
|
26 | /**
|
27 | * Sha1 hash of the input string
|
28 | * @param str - The string to hash
|
29 | * @returns {!string} The resulting hash
|
30 | */
|
31 | export declare const sha1: (str: string) => string;
|
32 | /**
|
33 | * Use this for all debug messages in Firebase.
|
34 | */
|
35 | export declare let logger: ((a: string) => void) | null;
|
36 | /**
|
37 | * The implementation of Firebase.enableLogging (defined here to break dependencies)
|
38 | * @param logger_ - A flag to turn on logging, or a custom logger
|
39 | * @param persistent - Whether or not to persist logging settings across refreshes
|
40 | */
|
41 | export declare const enableLogging: (logger_?: boolean | ((a: string) => void), persistent?: boolean) => void;
|
42 | export declare const log: (...varArgs: unknown[]) => void;
|
43 | export declare const logWrapper: (prefix: string) => (...varArgs: unknown[]) => void;
|
44 | export declare const error: (...varArgs: string[]) => void;
|
45 | export declare const fatal: (...varArgs: string[]) => never;
|
46 | export declare const warn: (...varArgs: unknown[]) => void;
|
47 | /**
|
48 | * Logs a warning if the containing page uses https. Called when a call to new Firebase
|
49 | * does not use https.
|
50 | */
|
51 | export declare const warnIfPageIsSecure: () => void;
|
52 | export declare const warnAboutUnsupportedMethod: (methodName: string) => void;
|
53 | /**
|
54 | * Returns true if data is NaN, or +/- Infinity.
|
55 | */
|
56 | export declare const isInvalidJSONNumber: (data: unknown) => boolean;
|
57 | export declare const executeWhenDOMReady: (fn: () => void) => void;
|
58 | /**
|
59 | * Minimum key name. Invalid for actual data, used as a marker to sort before any valid names
|
60 | */
|
61 | export declare const MIN_NAME = "[MIN_NAME]";
|
62 | /**
|
63 | * Maximum key name. Invalid for actual data, used as a marker to sort above any valid names
|
64 | */
|
65 | export declare const MAX_NAME = "[MAX_NAME]";
|
66 | /**
|
67 | * Compares valid Firebase key names, plus min and max name
|
68 | */
|
69 | export declare const nameCompare: (a: string, b: string) => number;
|
70 | /**
|
71 | * @returns {!number} comparison result.
|
72 | */
|
73 | export declare const stringCompare: (a: string, b: string) => number;
|
74 | export declare const requireKey: (key: string, obj: {
|
75 | [k: string]: unknown;
|
76 | }) => unknown;
|
77 | export declare const ObjectToUniqueKey: (obj: unknown) => string;
|
78 | /**
|
79 | * Splits a string into a number of smaller segments of maximum size
|
80 | * @param str - The string
|
81 | * @param segsize - The maximum number of chars in the string.
|
82 | * @returns The string, split into appropriately-sized chunks
|
83 | */
|
84 | export declare const splitStringBySize: (str: string, segsize: number) => string[];
|
85 | /**
|
86 | * Apply a function to each (key, value) pair in an object or
|
87 | * apply a function to each (index, value) pair in an array
|
88 | * @param obj - The object or array to iterate over
|
89 | * @param fn - The function to apply
|
90 | */
|
91 | export declare function each(obj: object, fn: (k: string, v: unknown) => void): void;
|
92 | /**
|
93 | * Like goog.bind, but doesn't bother to create a closure if opt_context is null/undefined.
|
94 | * @param callback - Callback function.
|
95 | * @param context - Optional context to bind to.
|
96 | *
|
97 | */
|
98 | export declare const bindCallback: (callback: (a: unknown) => void, context?: object | null) => (a: unknown) => void;
|
99 | /**
|
100 | * Borrowed from http://hg.secondlife.com/llsd/src/tip/js/typedarray.js (MIT License)
|
101 | * I made one modification at the end and removed the NaN / Infinity
|
102 | * handling (since it seemed broken [caused an overflow] and we don't need it). See MJL comments.
|
103 | * @param v - A double
|
104 | *
|
105 | */
|
106 | export declare const doubleToIEEE754String: (v: number) => string;
|
107 | /**
|
108 | * Used to detect if we're in a Chrome content script (which executes in an
|
109 | * isolated environment where long-polling doesn't work).
|
110 | */
|
111 | export declare const isChromeExtensionContentScript: () => boolean;
|
112 | /**
|
113 | * Used to detect if we're in a Windows 8 Store app.
|
114 | */
|
115 | export declare const isWindowsStoreApp: () => boolean;
|
116 | /**
|
117 | * Converts a server error code to a Javascript Error
|
118 | */
|
119 | export declare function errorForServerCode(code: string, query: QueryContext): Error;
|
120 | /**
|
121 | * Used to test for integer-looking strings
|
122 | */
|
123 | export declare const INTEGER_REGEXP_: RegExp;
|
124 | /**
|
125 | * For use in keys, the minimum possible 32-bit integer.
|
126 | */
|
127 | export declare const INTEGER_32_MIN = -2147483648;
|
128 | /**
|
129 | * For use in kyes, the maximum possible 32-bit integer.
|
130 | */
|
131 | export declare const INTEGER_32_MAX = 2147483647;
|
132 | /**
|
133 | * If the string contains a 32-bit integer, return it. Else return null.
|
134 | */
|
135 | export declare const tryParseInt: (str: string) => number | null;
|
136 | /**
|
137 | * Helper to run some code but catch any exceptions and re-throw them later.
|
138 | * Useful for preventing user callbacks from breaking internal code.
|
139 | *
|
140 | * Re-throwing the exception from a setTimeout is a little evil, but it's very
|
141 | * convenient (we don't have to try to figure out when is a safe point to
|
142 | * re-throw it), and the behavior seems reasonable:
|
143 | *
|
144 | * * If you aren't pausing on exceptions, you get an error in the console with
|
145 | * the correct stack trace.
|
146 | * * If you're pausing on all exceptions, the debugger will pause on your
|
147 | * exception and then again when we rethrow it.
|
148 | * * If you're only pausing on uncaught exceptions, the debugger will only pause
|
149 | * on us re-throwing it.
|
150 | *
|
151 | * @param fn - The code to guard.
|
152 | */
|
153 | export declare const exceptionGuard: (fn: () => void) => void;
|
154 | /**
|
155 | * Helper function to safely call opt_callback with the specified arguments. It:
|
156 | * 1. Turns into a no-op if opt_callback is null or undefined.
|
157 | * 2. Wraps the call inside exceptionGuard to prevent exceptions from breaking our state.
|
158 | *
|
159 | * @param callback - Optional onComplete callback.
|
160 | * @param varArgs - Arbitrary args to be passed to opt_onComplete
|
161 | */
|
162 | export declare const callUserCallback: (callback?: Function | null, ...varArgs: unknown[]) => void;
|
163 | /**
|
164 | * @returns {boolean} true if we think we're currently being crawled.
|
165 | */
|
166 | export declare const beingCrawled: () => boolean;
|
167 | /**
|
168 | * Export a property of an object using a getter function.
|
169 | */
|
170 | export declare const exportPropGetter: (object: object, name: string, fnGet: () => unknown) => void;
|
171 | /**
|
172 | * Same as setTimeout() except on Node.JS it will /not/ prevent the process from exiting.
|
173 | *
|
174 | * It is removed with clearTimeout() as normal.
|
175 | *
|
176 | * @param fn - Function to run.
|
177 | * @param time - Milliseconds to wait before running.
|
178 | * @returns The setTimeout() return value.
|
179 | */
|
180 | export declare const setTimeoutNonBlocking: (fn: () => void, time: number) => number | object;
|
181 | export {};
|