Skip to content

Commit cc590d0

Browse files
committed
Workaround for deprecated grpc.load() method
1 parent bcb1dfe commit cc590d0

File tree

4 files changed

+908
-3
lines changed

4 files changed

+908
-3
lines changed

packages/firestore/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@firebase/firestore-types": "1.1.1",
3131
"@firebase/logger": "0.1.10",
3232
"@firebase/webchannel-wrapper": "0.2.16",
33+
"@grpc/proto-loader": "^0.4.0",
3334
"grpc": "1.19.0",
3435
"tslib": "1.9.3"
3536
},

packages/firestore/src/platform_node/load_protos.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as protoLoader from '@grpc/proto-loader';
1819
import * as grpc from 'grpc';
1920
import { resolve } from 'path';
21+
import * as ProtobufJS from 'protobufjs';
2022

2123
/**
2224
* Loads the protocol buffer definitions for Firestore.
2325
*
2426
* @returns The GrpcObject representing our protos.
2527
*/
2628
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 {
2746
const options = {
2847
// Beware that converting fields to camel case does not convert the tag
2948
// fields in oneof groups (!!!). This will likely be fixed when we upgrade
@@ -38,5 +57,8 @@ export function loadProtos(): grpc.GrpcObject {
3857
root,
3958
file: 'google/firestore/v1/firestore.proto'
4059
};
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();
4264
}

0 commit comments

Comments
 (0)