Skip to content

Remove use of deprecated grpc.load() method #1669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@firebase/firestore-types": "1.2.1",
"@firebase/logger": "0.1.13",
"@firebase/webchannel-wrapper": "0.2.19",
"@grpc/proto-loader": "^0.5.0",
"grpc": "1.20.0",
"tslib": "1.9.3"
},
Expand Down Expand Up @@ -62,6 +63,7 @@
"npm-run-all": "4.1.5",
"nyc": "14.0.0",
"prettier": "1.17.0",
"protobufjs": "6.8.8",
"rollup": "1.10.1",
"rollup-plugin-copy-assets": "1.1.0",
"rollup-plugin-node-resolve": "4.2.3",
Expand Down
58 changes: 47 additions & 11 deletions packages/firestore/src/platform_node/load_protos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,64 @@
* limitations under the License.
*/

import * as protoLoader from '@grpc/proto-loader';
import * as grpc from 'grpc';
import { resolve } from 'path';
import * as path from 'path';
import * as ProtobufJS from 'protobufjs';

/** Used by tests so we can match @grpc/proto-loader behavior. */
export const protoLoaderOptions: ProtobufJS.IConversionOptions = {
longs: String,
enums: String,
defaults: true,
oneofs: false
};

/**
* Loads the protocol buffer definitions for Firestore.
*
* @returns The GrpcObject representing our protos.
*/
export function loadProtos(): grpc.GrpcObject {
const options = {
// Beware that converting fields to camel case does not convert the tag
// fields in oneof groups (!!!). This will likely be fixed when we upgrade
// to protobufjs 6.x
convertFieldsToCamelCase: true
};
const root = resolve(
const root = path.resolve(
__dirname,
process.env.FIRESTORE_PROTO_ROOT || '../protos'
);
const firestoreProtoFile = path.join(
root,
'google/firestore/v1/firestore.proto'
);

const packageDefinition = protoLoader.loadSync(firestoreProtoFile, {
...protoLoaderOptions,
includeDirs: [root]
});

return grpc.loadPackageDefinition(packageDefinition);
}

/** Used by tests so we can directly create ProtobufJS proto message objects from JSON protos. */
export function loadRawProtos(): ProtobufJS.Root {
const root = path.resolve(
__dirname,
process.env.FIRESTORE_PROTO_ROOT || '../protos'
);
const firestoreProtoFile = {
const firestoreProtoFile = path.join(
root,
file: 'google/firestore/v1/firestore.proto'
'google/firestore/v1/firestore.proto'
);

const protoRoot = new ProtobufJS.Root();
// Override the resolvePath function to look for protos in the 'root'
// directory.
protoRoot.resolvePath = (origin: string, target: string) => {
if (path.isAbsolute(target)) {
return target;
}
return path.join(root, target);
};
return grpc.load(firestoreProtoFile, /*format=*/ 'proto', options);

protoRoot.loadSync(firestoreProtoFile);
protoRoot.resolveAll();
return protoRoot;
}
4 changes: 2 additions & 2 deletions packages/firestore/src/protos/firestore_proto_api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ export declare namespace firestoreV1ApiClientInterfaces {
booleanValue?: boolean;
integerValue?: string;
doubleValue?: number;
timestampValue?: string;
timestampValue?: string | { seconds: long; nanos: long };
stringValue?: string;
bytesValue?: string;
bytesValue?: string | Uint8Array;
referenceValue?: string;
geoPointValue?: LatLng;
arrayValue?: ArrayValue;
Expand Down
Loading