index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*! firebase-admin v12.1.1 */
  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. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.FirebaseDatabaseError = exports.getDatabaseWithUrl = exports.getDatabase = exports.ServerValue = exports.enableLogging = void 0;
  20. const standalone_1 = require("@firebase/database-compat/standalone");
  21. const app_1 = require("../app");
  22. const 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/v8/firebase.database#enablelogging | enableLogging}
  26. * function from the `@firebase/database-compat` package.
  27. */
  28. exports.enableLogging = standalone_1.enableLogging;
  29. /**
  30. * {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.ServerValue | ServerValue}
  31. * constant from the `@firebase/database-compat` package.
  32. */
  33. // eslint-disable-next-line @typescript-eslint/naming-convention
  34. exports.ServerValue = standalone_1.ServerValue;
  35. /**
  36. * Gets the {@link Database} service for the default
  37. * app or a given app.
  38. *
  39. * `getDatabase()` can be called with no arguments to access the default
  40. * app's `Database` service or as `getDatabase(app)` to access the
  41. * `Database` service associated with a specific app.
  42. *
  43. * @example
  44. * ```javascript
  45. * // Get the Database service for the default app
  46. * const defaultDatabase = getDatabase();
  47. * ```
  48. *
  49. * @example
  50. * ```javascript
  51. * // Get the Database service for a specific app
  52. * const otherDatabase = getDatabase(app);
  53. * ```
  54. *
  55. * @param App - whose `Database` service to
  56. * return. If not provided, the default `Database` service will be returned.
  57. *
  58. * @returns The default `Database` service if no app
  59. * is provided or the `Database` service associated with the provided app.
  60. */
  61. function getDatabase(app) {
  62. return getDatabaseInstance({ app });
  63. }
  64. exports.getDatabase = getDatabase;
  65. /**
  66. * Gets the {@link Database} service for the default
  67. * app or a given app.
  68. *
  69. * `getDatabaseWithUrl()` can be called with no arguments to access the default
  70. * app's {@link Database} service or as `getDatabaseWithUrl(app)` to access the
  71. * {@link Database} service associated with a specific app.
  72. *
  73. * @example
  74. * ```javascript
  75. * // Get the Database service for the default app
  76. * const defaultDatabase = getDatabaseWithUrl('https://example.firebaseio.com');
  77. * ```
  78. *
  79. * @example
  80. * ```javascript
  81. * // Get the Database service for a specific app
  82. * const otherDatabase = getDatabaseWithUrl('https://example.firebaseio.com', app);
  83. * ```
  84. *
  85. * @param App - whose `Database` service to
  86. * return. If not provided, the default `Database` service will be returned.
  87. *
  88. * @returns The default `Database` service if no app
  89. * is provided or the `Database` service associated with the provided app.
  90. */
  91. function getDatabaseWithUrl(url, app) {
  92. return getDatabaseInstance({ url, app });
  93. }
  94. exports.getDatabaseWithUrl = getDatabaseWithUrl;
  95. function getDatabaseInstance(options) {
  96. let { app } = options;
  97. if (typeof app === 'undefined') {
  98. app = (0, app_1.getApp)();
  99. }
  100. const firebaseApp = app;
  101. const dbService = firebaseApp.getOrInitService('database', (app) => new database_1.DatabaseService(app));
  102. return dbService.getDatabase(options.url);
  103. }
  104. var error_1 = require("../utils/error");
  105. Object.defineProperty(exports, "FirebaseDatabaseError", { enumerable: true, get: function () { return error_1.FirebaseDatabaseError; } });