1414 * See the License for the specific language governing permissions and
1515 * limitations under the License.
1616 */
17-
18- import { FirebaseApp , FirebaseNamespace } from '@firebase/app-types' ;
17+ import firebase from '@firebase/app-compat' ;
18+ import { FirebaseNamespace } from '@firebase/app-types' ;
1919import { _FirebaseNamespace } from '@firebase/app-types/private' ;
20- import { FirebaseAuthInternal } from '@firebase/auth-interop-types' ;
2120import { Component , ComponentType } from '@firebase/component' ;
2221import { enableLogging } from '@firebase/database' ;
2322import * as types from '@firebase/database-types' ;
24- import { CONSTANTS , isNodeSdk } from '@firebase/util' ;
2523
2624import { name , version } from '../package.json' ;
2725import { Database } from '../src/api/Database' ;
@@ -30,45 +28,9 @@ import { DataSnapshot, Query, Reference } from '../src/api/Reference';
3028
3129const ServerValue = Database . ServerValue ;
3230
33- /**
34- * A one off register function which returns a database based on the app and
35- * passed database URL. (Used by the Admin SDK)
36- *
37- * @param app - A valid FirebaseApp-like object
38- * @param url - A valid Firebase databaseURL
39- * @param version - custom version e.g. firebase-admin version
40- * @param nodeAdmin - true if the SDK is being initialized from Firebase Admin.
41- */
42- export function initStandalone (
43- app : FirebaseApp ,
44- url : string ,
45- version : string ,
46- nodeAdmin = true
47- ) {
48- CONSTANTS . NODE_ADMIN = nodeAdmin ;
49- return INTERNAL . initStandalone ( {
50- app,
51- url,
52- version,
53- // firebase-admin-node's app.INTERNAL implements FirebaseAuthInternal interface
54- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55- customAuthImpl : ( app as any ) . INTERNAL as FirebaseAuthInternal ,
56- namespace : {
57- Reference,
58- Query,
59- Database,
60- DataSnapshot,
61- enableLogging,
62- INTERNAL ,
63- ServerValue
64- } ,
65- nodeAdmin
66- } ) ;
67- }
68-
69- export function registerDatabase ( instance : FirebaseNamespace ) {
31+ function registerDatabase ( instance : FirebaseNamespace ) {
7032 // Register the Database Service with the 'firebase' namespace.
71- const namespace = ( instance as _FirebaseNamespace ) . INTERNAL . registerComponent (
33+ ( instance as _FirebaseNamespace ) . INTERNAL . registerComponent (
7234 new Component (
7335 'database-compat' ,
7436 ( container , { instanceIdentifier : url } ) => {
@@ -98,33 +60,9 @@ export function registerDatabase(instance: FirebaseNamespace) {
9860 ) ;
9961
10062 instance . registerVersion ( name , version , 'node' ) ;
101-
102- if ( isNodeSdk ( ) ) {
103- module . exports = Object . assign ( { } , namespace , { initStandalone } ) ;
104- }
105- }
106-
107- try {
108- // If @firebase /app is not present, skip registering database.
109- // It could happen when this package is used in firebase-admin which doesn't depend on @firebase/app.
110- // Previously firebase-admin depends on @firebase/app, which causes version conflict on
111- // @firebase /app when used together with the js sdk. More detail:
112- // https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596
113- // eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports
114- const firebase = require ( '@firebase/app-compat' ) . default ;
115- registerDatabase ( firebase ) ;
116- } catch ( err ) {
117- // catch and ignore 'MODULE_NOT_FOUND' error in firebase-admin context
118- // we can safely ignore this error because RTDB in firebase-admin works without @firebase/app
119- if ( err . code !== 'MODULE_NOT_FOUND' ) {
120- throw err ;
121- }
12263}
12364
124- // Types to export for the admin SDK
125- export { Database , Query , Reference , enableLogging , ServerValue } ;
126-
127- export { OnDisconnect } from '@firebase/database' ;
65+ registerDatabase ( firebase ) ;
12866
12967declare module '@firebase/app-compat' {
13068 interface FirebaseNamespace {
@@ -139,4 +77,3 @@ declare module '@firebase/app-compat' {
13977 database ?( ) : types . FirebaseDatabase ;
14078 }
14179}
142- export { DataSnapshot } from '../src/api/Reference' ;
0 commit comments