UNPKG

3.78 kBJavaScriptView Raw
1/*! firebase-admin v10.0.0 */
2"use strict";
3/*!
4 * Copyright 2020 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.getDatabaseWithUrl = exports.getDatabase = exports.ServerValue = exports.enableLogging = void 0;
20var standalone_1 = require("@firebase/database-compat/standalone");
21var app_1 = require("../app");
22var database_1 = require("./database");
23// TODO: Remove the following any-cast once the typins in @firebase/database-types are fixed.
24/**
25 * {@link https://firebase.google.com/docs/reference/js/firebase.database#enablelogging | enableLogging}
26 * function from the `@firebase/database` package.
27 */
28exports.enableLogging = standalone_1.enableLogging;
29/**
30 * {@link https://firebase.google.com/docs/reference/js/firebase.database.ServerValue | ServerValue}
31 * constant from the `@firebase/database` package.
32 */
33exports.ServerValue = standalone_1.ServerValue;
34/**
35 * Gets the {@link Database} service for the default
36 * app or a given app.
37 *
38 * `getDatabase()` can be called with no arguments to access the default
39 * app's `Database` service or as `getDatabase(app)` to access the
40 * `Database` service associated with a specific app.
41 *
42 * @example
43 * ```javascript
44 * // Get the Database service for the default app
45 * const defaultDatabase = getDatabase();
46 * ```
47 *
48 * @example
49 * ```javascript
50 * // Get the Database service for a specific app
51 * const otherDatabase = getDatabase(app);
52 * ```
53 *
54 * @param App - whose `Database` service to
55 * return. If not provided, the default `Database` service will be returned.
56 *
57 * @returns The default `Database` service if no app
58 * is provided or the `Database` service associated with the provided app.
59 */
60function getDatabase(app) {
61 return getDatabaseInstance({ app: app });
62}
63exports.getDatabase = getDatabase;
64/**
65 * Gets the {@link Database} service for the default
66 * app or a given app.
67 *
68 * `getDatabaseWithUrl()` can be called with no arguments to access the default
69 * app's {@link Database} service or as `getDatabaseWithUrl(app)` to access the
70 * {@link Database} service associated with a specific app.
71 *
72 * @example
73 * ```javascript
74 * // Get the Database service for the default app
75 * const defaultDatabase = getDatabaseWithUrl('https://example.firebaseio.com');
76 * ```
77 *
78 * @example
79 * ```javascript
80 * // Get the Database service for a specific app
81 * const otherDatabase = getDatabaseWithUrl('https://example.firebaseio.com', app);
82 * ```
83 *
84 * @param App - whose `Database` service to
85 * return. If not provided, the default `Database` service will be returned.
86 *
87 * @returns The default `Database` service if no app
88 * is provided or the `Database` service associated with the provided app.
89 */
90function getDatabaseWithUrl(url, app) {
91 return getDatabaseInstance({ url: url, app: app });
92}
93exports.getDatabaseWithUrl = getDatabaseWithUrl;
94function getDatabaseInstance(options) {
95 var app = options.app;
96 if (typeof app === 'undefined') {
97 app = app_1.getApp();
98 }
99 var firebaseApp = app;
100 var dbService = firebaseApp.getOrInitService('database', function (app) { return new database_1.DatabaseService(app); });
101 return dbService.getDatabase(options.url);
102}