15
15
* limitations under the License.
16
16
*/
17
17
18
- import {
19
- Metadata ,
20
- GrpcObject ,
21
- credentials as GrpcCredentials ,
22
- ServiceError
23
- } from '@grpc/grpc-js' ;
18
+ // Note: We have to use a package import here to avoid build errors such as
19
+ // https://github.com/firebase/firebase-js-sdk/issues/5983
20
+ import * as grpc from '@grpc/grpc-js' ;
24
21
25
22
import { Token } from '../../api/credentials' ;
26
23
import { DatabaseInfo } from '../../core/database_info' ;
@@ -46,12 +43,12 @@ function createMetadata(
46
43
authToken : Token | null ,
47
44
appCheckToken : Token | null ,
48
45
appId : string
49
- ) : Metadata {
46
+ ) : grpc . Metadata {
50
47
hardAssert (
51
48
authToken === null || authToken . type === 'OAuth' ,
52
49
'If provided, token must be OAuth'
53
50
) ;
54
- const metadata = new Metadata ( ) ;
51
+ const metadata = new grpc . Metadata ( ) ;
55
52
if ( authToken ) {
56
53
authToken . headers . forEach ( ( value , key ) => metadata . set ( key , value ) ) ;
57
54
}
@@ -84,7 +81,7 @@ export class GrpcConnection implements Connection {
84
81
// We cache stubs for the most-recently-used token.
85
82
private cachedStub : GeneratedGrpcStub | null = null ;
86
83
87
- constructor ( protos : GrpcObject , private databaseInfo : DatabaseInfo ) {
84
+ constructor ( protos : grpc . GrpcObject , private databaseInfo : DatabaseInfo ) {
88
85
// eslint-disable-next-line @typescript-eslint/no-explicit-any
89
86
this . firestore = ( protos as any ) [ 'google' ] [ 'firestore' ] [ 'v1' ] ;
90
87
this . databasePath = `projects/${ databaseInfo . databaseId . projectId } /databases/${ databaseInfo . databaseId . database } ` ;
@@ -94,8 +91,8 @@ export class GrpcConnection implements Connection {
94
91
if ( ! this . cachedStub ) {
95
92
logDebug ( LOG_TAG , 'Creating Firestore stub.' ) ;
96
93
const credentials = this . databaseInfo . ssl
97
- ? GrpcCredentials . createSsl ( )
98
- : GrpcCredentials . createInsecure ( ) ;
94
+ ? grpc . credentials . createSsl ( )
95
+ : grpc . credentials . createInsecure ( ) ;
99
96
this . cachedStub = new this . firestore . Firestore (
100
97
this . databaseInfo . host ,
101
98
credentials
@@ -125,7 +122,7 @@ export class GrpcConnection implements Connection {
125
122
return stub [ rpcName ] (
126
123
jsonRequest ,
127
124
metadata ,
128
- ( grpcError ?: ServiceError , value ?: Resp ) => {
125
+ ( grpcError ?: grpc . ServiceError , value ?: Resp ) => {
129
126
if ( grpcError ) {
130
127
logDebug ( LOG_TAG , `RPC '${ rpcName } ' failed with error:` , grpcError ) ;
131
128
callback (
@@ -179,7 +176,7 @@ export class GrpcConnection implements Connection {
179
176
logDebug ( LOG_TAG , `RPC '${ rpcName } ' completed.` ) ;
180
177
responseDeferred . resolve ( results ) ;
181
178
} ) ;
182
- stream . on ( 'error' , ( grpcError : ServiceError ) => {
179
+ stream . on ( 'error' , ( grpcError : grpc . ServiceError ) => {
183
180
logDebug ( LOG_TAG , `RPC '${ rpcName } ' failed with error:` , grpcError ) ;
184
181
const code = mapCodeFromRpcCode ( grpcError . code ) ;
185
182
responseDeferred . reject ( new FirestoreError ( code , grpcError . message ) ) ;
@@ -247,7 +244,7 @@ export class GrpcConnection implements Connection {
247
244
close ( ) ;
248
245
} ) ;
249
246
250
- grpcStream . on ( 'error' , ( grpcError : ServiceError ) => {
247
+ grpcStream . on ( 'error' , ( grpcError : grpc . ServiceError ) => {
251
248
if ( ! closed ) {
252
249
logWarn (
253
250
LOG_TAG ,
0 commit comments