Initial Commit

This commit is contained in:
2026-03-06 04:54:20 -04:00
commit 63677bfcf5
9332 changed files with 1507319 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { _FirebaseService, FirebaseApp } from '@firebase/app';
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { Provider } from '@firebase/component';
import { EmulatorMockTokenOptions } from '@firebase/util';
import { Repo } from '../core/Repo';
import { ReferenceImpl } from './Reference_impl';
export { EmulatorMockTokenOptions } from '@firebase/util';
/**
* This function should only ever be called to CREATE a new database instance.
* @internal
*/
export declare function repoManagerDatabaseFromApp(app: FirebaseApp, authProvider: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>, url?: string, nodeAdmin?: boolean): Database;
/**
* Forces us to use ReadonlyRestClient instead of PersistentConnection for new Repos.
*/
export declare function repoManagerForceRestClient(forceRestClient: boolean): void;
/**
* Class representing a Firebase Realtime Database.
*/
export declare class Database implements _FirebaseService {
_repoInternal: Repo;
/** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
readonly app: FirebaseApp;
/** Represents a `Database` instance. */
readonly 'type' = "database";
/** Track if the instance has been used (root or repo accessed) */
_instanceStarted: boolean;
/** Backing state for root_ */
private _rootInternal?;
/** @hideconstructor */
constructor(_repoInternal: Repo,
/** The {@link @firebase/app#FirebaseApp} associated with this Realtime Database instance. */
app: FirebaseApp);
get _repo(): Repo;
get _root(): ReferenceImpl;
_delete(): Promise<void>;
_checkNotDeleted(apiName: string): void;
}
/**
* Force the use of websockets instead of longPolling.
*/
export declare function forceWebSockets(): void;
/**
* Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
*/
export declare function forceLongPolling(): void;
/**
* Returns the instance of the Realtime Database SDK that is associated with the provided
* {@link @firebase/app#FirebaseApp}. Initializes a new instance with default settings if
* no instance exists or if the existing instance uses a custom database URL.
*
* @param app - The {@link @firebase/app#FirebaseApp} instance that the returned Realtime
* Database instance is associated with.
* @param url - The URL of the Realtime Database instance to connect to. If not
* provided, the SDK connects to the default instance of the Firebase App.
* @returns The `Database` instance of the provided app.
*/
export declare function getDatabase(app?: FirebaseApp, url?: string): Database;
/**
* Modify the provided instance to communicate with the Realtime Database
* emulator.
*
* <p>Note: This method must be called before performing any other operation.
*
* @param db - The instance to modify.
* @param host - The emulator host (ex: localhost)
* @param port - The emulator port (ex: 8080)
* @param options.mockUserToken - the mock auth token to use for unit testing Security Rules
*/
export declare function connectDatabaseEmulator(db: Database, host: string, port: number, options?: {
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;
/**
* Disconnects from the server (all Database operations will be completed
* offline).
*
* The client automatically maintains a persistent connection to the Database
* server, which will remain active indefinitely and reconnect when
* disconnected. However, the `goOffline()` and `goOnline()` methods may be used
* to control the client connection in cases where a persistent connection is
* undesirable.
*
* While offline, the client will no longer receive data updates from the
* Database. However, all Database operations performed locally will continue to
* immediately fire events, allowing your application to continue behaving
* normally. Additionally, each operation performed locally will automatically
* be queued and retried upon reconnection to the Database server.
*
* To reconnect to the Database and begin receiving remote events, see
* `goOnline()`.
*
* @param db - The instance to disconnect.
*/
export declare function goOffline(db: Database): void;
/**
* Reconnects to the server and synchronizes the offline Database state
* with the server state.
*
* This method should be used after disabling the active connection with
* `goOffline()`. Once reconnected, the client will transmit the proper data
* and fire the appropriate events so that your client "catches up"
* automatically.
*
* @param db - The instance to reconnect.
*/
export declare function goOnline(db: Database): void;
/**
* Logs debugging information to the console.
*
* @param enabled - Enables logging if `true`, disables logging if `false`.
* @param persistent - Remembers the logging state between page refreshes if
* `true`.
*/
export declare function enableLogging(enabled: boolean, persistent?: boolean): any;
/**
* Logs debugging information to the console.
*
* @param logger - A custom logger function to control how things get logged.
*/
export declare function enableLogging(logger: (message: string) => unknown): any;

View File

@@ -0,0 +1,110 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Repo } from '../core/Repo';
import { Path } from '../core/util/Path';
/**
* The `onDisconnect` class allows you to write or clear data when your client
* disconnects from the Database server. These updates occur whether your
* client disconnects cleanly or not, so you can rely on them to clean up data
* even if a connection is dropped or a client crashes.
*
* The `onDisconnect` class is most commonly used to manage presence in
* applications where it is useful to detect how many clients are connected and
* when other clients disconnect. See
* {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
* for more information.
*
* To avoid problems when a connection is dropped before the requests can be
* transferred to the Database server, these functions should be called before
* writing any data.
*
* Note that `onDisconnect` operations are only triggered once. If you want an
* operation to occur each time a disconnect occurs, you'll need to re-establish
* the `onDisconnect` operations each time you reconnect.
*/
export declare class OnDisconnect {
private _repo;
private _path;
/** @hideconstructor */
constructor(_repo: Repo, _path: Path);
/**
* Cancels all previously queued `onDisconnect()` set or update events for this
* location and all children.
*
* If a write has been queued for this location via a `set()` or `update()` at a
* parent location, the write at this location will be canceled, though writes
* to sibling locations will still occur.
*
* @returns Resolves when synchronization to the server is complete.
*/
cancel(): Promise<void>;
/**
* Ensures the data at this location is deleted when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues).
*
* @returns Resolves when synchronization to the server is complete.
*/
remove(): Promise<void>;
/**
* Ensures the data at this location is set to the specified value when the
* client is disconnected (due to closing the browser, navigating to a new page,
* or network issues).
*
* `set()` is especially useful for implementing "presence" systems, where a
* value should be changed or cleared when a user disconnects so that they
* appear "offline" to other users. See
* {@link https://firebase.google.com/docs/database/web/offline-capabilities | Enabling Offline Capabilities in JavaScript}
* for more information.
*
* Note that `onDisconnect` operations are only triggered once. If you want an
* operation to occur each time a disconnect occurs, you'll need to re-establish
* the `onDisconnect` operations each time.
*
* @param value - The value to be written to this location on disconnect (can
* be an object, array, string, number, boolean, or null).
* @returns Resolves when synchronization to the Database is complete.
*/
set(value: unknown): Promise<void>;
/**
* Ensures the data at this location is set to the specified value and priority
* when the client is disconnected (due to closing the browser, navigating to a
* new page, or network issues).
*
* @param value - The value to be written to this location on disconnect (can
* be an object, array, string, number, boolean, or null).
* @param priority - The priority to be written (string, number, or null).
* @returns Resolves when synchronization to the Database is complete.
*/
setWithPriority(value: unknown, priority: number | string | null): Promise<void>;
/**
* Writes multiple values at this location when the client is disconnected (due
* to closing the browser, navigating to a new page, or network issues).
*
* The `values` argument contains multiple property-value pairs that will be
* written to the Database together. Each child property can either be a simple
* property (for example, "name") or a relative path (for example, "name/first")
* from the current location to the data to update.
*
* As opposed to the `set()` method, `update()` can be use to selectively update
* only the referenced properties at the current location (instead of replacing
* all the child properties at the current location).
*
* @param values - Object containing multiple values.
* @returns Resolves when synchronization to the Database is complete.
*/
update(values: object): Promise<void>;
}

View File

@@ -0,0 +1,124 @@
import { Repo } from '../core/Repo';
import { Path } from '../core/util/Path';
import { QueryContext } from '../core/view/EventRegistration';
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A `Query` sorts and filters the data at a Database location so only a subset
* of the child data is included. This can be used to order a collection of
* data by some attribute (for example, height of dinosaurs) as well as to
* restrict a large list of items (for example, chat messages) down to a number
* suitable for synchronizing to the client. Queries are created by chaining
* together one or more of the filter methods defined here.
*
* Just as with a `DatabaseReference`, you can receive data from a `Query` by using the
* `on*()` methods. You will only receive events and `DataSnapshot`s for the
* subset of the data that matches your query.
*
* See {@link https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data}
* for more information.
*/
export interface Query extends QueryContext {
/** The `DatabaseReference` for the `Query`'s location. */
readonly ref: DatabaseReference;
/**
* Returns whether or not the current and provided queries represent the same
* location, have the same query parameters, and are from the same instance of
* `FirebaseApp`.
*
* Two `DatabaseReference` objects are equivalent if they represent the same location
* and are from the same instance of `FirebaseApp`.
*
* Two `Query` objects are equivalent if they represent the same location,
* have the same query parameters, and are from the same instance of
* `FirebaseApp`. Equivalent queries share the same sort order, limits, and
* starting and ending points.
*
* @param other - The query to compare against.
* @returns Whether or not the current and provided queries are equivalent.
*/
isEqual(other: Query | null): boolean;
/**
* Returns a JSON-serializable representation of this object.
*
* @returns A JSON-serializable representation of this object.
*/
toJSON(): string;
/**
* Gets the absolute URL for this location.
*
* The `toString()` method returns a URL that is ready to be put into a
* browser, curl command, or a `refFromURL()` call. Since all of those expect
* the URL to be url-encoded, `toString()` returns an encoded URL.
*
* Append '.json' to the returned URL when typed into a browser to download
* JSON-formatted data. If the location is secured (that is, not publicly
* readable), you will get a permission-denied error.
*
* @returns The absolute URL for this location.
*/
toString(): string;
}
/**
* A `DatabaseReference` represents a specific location in your Database and can be used
* for reading or writing data to that Database location.
*
* You can reference the root or child location in your Database by calling
* `ref()` or `ref("child/path")`.
*
* Writing is done with the `set()` method and reading can be done with the
* `on*()` method. See {@link
* https://firebase.google.com/docs/database/web/read-and-write}
*/
export interface DatabaseReference extends Query {
/**
* The last part of the `DatabaseReference`'s path.
*
* For example, `"ada"` is the key for
* `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
*
* The key of a root `DatabaseReference` is `null`.
*/
readonly key: string | null;
/**
* The parent location of a `DatabaseReference`.
*
* The parent of a root `DatabaseReference` is `null`.
*/
readonly parent: DatabaseReference | null;
/** The root `DatabaseReference` of the Database. */
readonly root: DatabaseReference;
}
/**
* A `Promise` that can also act as a `DatabaseReference` when returned by
* {@link push}. The reference is available immediately and the `Promise` resolves
* as the write to the backend completes.
*/
export interface ThenableReference extends DatabaseReference, Pick<Promise<DatabaseReference>, 'then' | 'catch'> {
key: string;
parent: DatabaseReference;
}
/** A callback that can invoked to remove a listener. */
export type Unsubscribe = () => void;
/** An options objects that can be used to customize a listener. */
export interface ListenOptions {
/** Whether to remove the listener after its first invocation. */
readonly onlyOnce?: boolean;
}
export interface ReferenceConstructor {
new (repo: Repo, path: Path): DatabaseReference;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Returns a placeholder value for auto-populating the current timestamp (time
* since the Unix epoch, in milliseconds) as determined by the Firebase
* servers.
*/
export declare function serverTimestamp(): object;
/**
* Returns a placeholder value that can be used to atomically increment the
* current database value by the provided delta.
*
* @param delta - the amount to modify the current value atomically.
* @returns A placeholder value for modifying data atomically server-side.
*/
export declare function increment(delta: number): object;

View File

@@ -0,0 +1,83 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DatabaseReference } from './Reference';
import { DataSnapshot } from './Reference_impl';
/** An options object to configure transactions. */
export interface TransactionOptions {
/**
* By default, events are raised each time the transaction update function
* runs. So if it is run multiple times, you may see intermediate states. You
* can set this to false to suppress these intermediate states and instead
* wait until the transaction has completed before events are raised.
*/
readonly applyLocally?: boolean;
}
/**
* A type for the resolve value of {@link runTransaction}.
*/
export declare class TransactionResult {
/** Whether the transaction was successfully committed. */
readonly committed: boolean;
/** The resulting data snapshot. */
readonly snapshot: DataSnapshot;
/** @hideconstructor */
constructor(
/** Whether the transaction was successfully committed. */
committed: boolean,
/** The resulting data snapshot. */
snapshot: DataSnapshot);
/** Returns a JSON-serializable representation of this object. */
toJSON(): object;
}
/**
* Atomically modifies the data at this location.
*
* Atomically modify the data at this location. Unlike a normal `set()`, which
* just overwrites the data regardless of its previous value, `runTransaction()` is
* used to modify the existing value to a new value, ensuring there are no
* conflicts with other clients writing to the same location at the same time.
*
* To accomplish this, you pass `runTransaction()` an update function which is
* used to transform the current value into a new value. If another client
* writes to the location before your new value is successfully written, your
* update function will be called again with the new current value, and the
* write will be retried. This will happen repeatedly until your write succeeds
* without conflict or you abort the transaction by not returning a value from
* your update function.
*
* Note: Modifying data with `set()` will cancel any pending transactions at
* that location, so extreme care should be taken if mixing `set()` and
* `runTransaction()` to update the same data.
*
* Note: When using transactions with Security and Firebase Rules in place, be
* aware that a client needs `.read` access in addition to `.write` access in
* order to perform a transaction. This is because the client-side nature of
* transactions requires the client to read the data in order to transactionally
* update it.
*
* @param ref - The location to atomically modify.
* @param transactionUpdate - A developer-supplied function which will be passed
* the current data stored at this location (as a JavaScript object). The
* function should return the new value it would like written (as a JavaScript
* object). If `undefined` is returned (i.e. you return with no arguments) the
* transaction will be aborted and the data at this location will not be
* modified.
* @param options - An options object to configure transactions.
* @returns A `Promise` that can optionally be used instead of the `onComplete`
* callback to handle success and failure.
*/
export declare function runTransaction(ref: DatabaseReference, transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions): Promise<TransactionResult>;

View File

@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PersistentConnection } from '../core/PersistentConnection';
import { RepoInfo } from '../core/RepoInfo';
import { Connection } from '../realtime/Connection';
export declare const DataConnection: typeof PersistentConnection;
export declare const RealTimeConnection: typeof Connection;
/**
* @internal
*/
export declare const hijackHash: (newHash: () => string) => () => void;
export declare const ConnectionTarget: typeof RepoInfo;
/**
* Forces the RepoManager to create Repos that use ReadonlyRestClient instead of PersistentConnection.
* @internal
*/
export declare const forceRestClient: (forceRestClient: boolean) => void;