14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
-
18
- import { FirebaseApp , FirebaseNamespace } from '@firebase/app-types' ;
17
+ import firebase from '@firebase/app-compat' ;
18
+ import { FirebaseNamespace } from '@firebase/app-types' ;
19
19
import { _FirebaseNamespace } from '@firebase/app-types/private' ;
20
- import { FirebaseAuthInternal } from '@firebase/auth-interop-types' ;
21
20
import { Component , ComponentType } from '@firebase/component' ;
22
21
import { enableLogging } from '@firebase/database' ;
23
22
import * as types from '@firebase/database-types' ;
24
- import { CONSTANTS , isNodeSdk } from '@firebase/util' ;
25
23
26
24
import { name , version } from '../package.json' ;
27
25
import { Database } from '../src/api/Database' ;
@@ -30,45 +28,9 @@ import { DataSnapshot, Query, Reference } from '../src/api/Reference';
30
28
31
29
const ServerValue = Database . ServerValue ;
32
30
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 ) {
70
32
// Register the Database Service with the 'firebase' namespace.
71
- const namespace = ( instance as _FirebaseNamespace ) . INTERNAL . registerComponent (
33
+ ( instance as _FirebaseNamespace ) . INTERNAL . registerComponent (
72
34
new Component (
73
35
'database-compat' ,
74
36
( container , { instanceIdentifier : url } ) => {
@@ -98,33 +60,9 @@ export function registerDatabase(instance: FirebaseNamespace) {
98
60
) ;
99
61
100
62
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
- }
122
63
}
123
64
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 ) ;
128
66
129
67
declare module '@firebase/app-compat' {
130
68
interface FirebaseNamespace {
@@ -139,4 +77,3 @@ declare module '@firebase/app-compat' {
139
77
database ?( ) : types . FirebaseDatabase ;
140
78
}
141
79
}
142
- export { DataSnapshot } from '../src/api/Reference' ;
0 commit comments