15
15
* limitations under the License.
16
16
*/
17
17
18
+ import * as protoLoader from '@grpc/proto-loader' ;
18
19
import * as grpc from 'grpc' ;
19
20
import { resolve } from 'path' ;
21
+ import * as ProtobufJS from 'protobufjs' ;
20
22
21
23
/**
22
24
* Loads the protocol buffer definitions for Firestore.
23
25
*
24
26
* @returns The GrpcObject representing our protos.
25
27
*/
26
28
export function loadProtos ( ) : grpc . GrpcObject {
29
+ const root = resolve (
30
+ __dirname ,
31
+ process . env . FIRESTORE_PROTO_ROOT || '../protos'
32
+ ) ;
33
+ const firestoreProtoFile = root + '/google/firestore/v1/firestore.proto' ;
34
+
35
+ // Beware that converting fields to camel case (the default behaviour with
36
+ // protoLoader) does not convert the tag fields in oneof groups (!!!). This
37
+ // will likely be fixed when we upgrade to protobufjs 6.x
38
+ const packageDefinition = protoLoader . loadSync (
39
+ firestoreProtoFile ,
40
+ { longs : String , enums : String , defaults : true , oneofs : true , includeDirs : [ root ] } ) ;
41
+
42
+ return grpc . loadPackageDefinition ( packageDefinition ) ;
43
+ }
44
+
45
+ export function loadRawProtos ( ) : any {
27
46
const options = {
28
47
// Beware that converting fields to camel case does not convert the tag
29
48
// fields in oneof groups (!!!). This will likely be fixed when we upgrade
@@ -38,5 +57,8 @@ export function loadProtos(): grpc.GrpcObject {
38
57
root,
39
58
file : 'google/firestore/v1/firestore.proto'
40
59
} ;
41
- return grpc . load ( firestoreProtoFile , /*format=*/ 'proto' , options ) ;
60
+
61
+ let builder = ProtobufJS . newBuilder ( options ) ;
62
+ builder = ProtobufJS . loadProtoFile ( firestoreProtoFile , builder ) ;
63
+ return builder . build ( ) ;
42
64
}
0 commit comments