1515 * limitations under the License.
1616 */
1717
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' ;
2421
2522import { Token } from '../../api/credentials' ;
2623import { DatabaseInfo } from '../../core/database_info' ;
@@ -46,12 +43,12 @@ function createMetadata(
4643 authToken : Token | null ,
4744 appCheckToken : Token | null ,
4845 appId : string
49- ) : Metadata {
46+ ) : grpc . Metadata {
5047 hardAssert (
5148 authToken === null || authToken . type === 'OAuth' ,
5249 'If provided, token must be OAuth'
5350 ) ;
54- const metadata = new Metadata ( ) ;
51+ const metadata = new grpc . Metadata ( ) ;
5552 if ( authToken ) {
5653 authToken . headers . forEach ( ( value , key ) => metadata . set ( key , value ) ) ;
5754 }
@@ -84,7 +81,7 @@ export class GrpcConnection implements Connection {
8481 // We cache stubs for the most-recently-used token.
8582 private cachedStub : GeneratedGrpcStub | null = null ;
8683
87- constructor ( protos : GrpcObject , private databaseInfo : DatabaseInfo ) {
84+ constructor ( protos : grpc . GrpcObject , private databaseInfo : DatabaseInfo ) {
8885 // eslint-disable-next-line @typescript-eslint/no-explicit-any
8986 this . firestore = ( protos as any ) [ 'google' ] [ 'firestore' ] [ 'v1' ] ;
9087 this . databasePath = `projects/${ databaseInfo . databaseId . projectId } /databases/${ databaseInfo . databaseId . database } ` ;
@@ -94,8 +91,8 @@ export class GrpcConnection implements Connection {
9491 if ( ! this . cachedStub ) {
9592 logDebug ( LOG_TAG , 'Creating Firestore stub.' ) ;
9693 const credentials = this . databaseInfo . ssl
97- ? GrpcCredentials . createSsl ( )
98- : GrpcCredentials . createInsecure ( ) ;
94+ ? grpc . credentials . createSsl ( )
95+ : grpc . credentials . createInsecure ( ) ;
9996 this . cachedStub = new this . firestore . Firestore (
10097 this . databaseInfo . host ,
10198 credentials
@@ -125,7 +122,7 @@ export class GrpcConnection implements Connection {
125122 return stub [ rpcName ] (
126123 jsonRequest ,
127124 metadata ,
128- ( grpcError ?: ServiceError , value ?: Resp ) => {
125+ ( grpcError ?: grpc . ServiceError , value ?: Resp ) => {
129126 if ( grpcError ) {
130127 logDebug ( LOG_TAG , `RPC '${ rpcName } ' failed with error:` , grpcError ) ;
131128 callback (
@@ -179,7 +176,7 @@ export class GrpcConnection implements Connection {
179176 logDebug ( LOG_TAG , `RPC '${ rpcName } ' completed.` ) ;
180177 responseDeferred . resolve ( results ) ;
181178 } ) ;
182- stream . on ( 'error' , ( grpcError : ServiceError ) => {
179+ stream . on ( 'error' , ( grpcError : grpc . ServiceError ) => {
183180 logDebug ( LOG_TAG , `RPC '${ rpcName } ' failed with error:` , grpcError ) ;
184181 const code = mapCodeFromRpcCode ( grpcError . code ) ;
185182 responseDeferred . reject ( new FirestoreError ( code , grpcError . message ) ) ;
@@ -247,7 +244,7 @@ export class GrpcConnection implements Connection {
247244 close ( ) ;
248245 } ) ;
249246
250- grpcStream . on ( 'error' , ( grpcError : ServiceError ) => {
247+ grpcStream . on ( 'error' , ( grpcError : grpc . ServiceError ) => {
251248 if ( ! closed ) {
252249 logWarn (
253250 LOG_TAG ,
0 commit comments