mirror of https://github.com/grpc/grpc-node.git
proto-loader: include Google well known protos
This commit ensures that the Google well known protos are available because protobufjs only exposes a subset of them.
This commit is contained in:
parent
f345593d1d
commit
cbff0b4601
|
@ -293,3 +293,20 @@ export function loadSync(filename: string, options?: Options): PackageDefinition
|
|||
loadedRoot.resolveAll();
|
||||
return createPackageDefinition(root, options!);
|
||||
}
|
||||
|
||||
// Load Google's well-known proto files that aren't exposed by Protobuf.js.
|
||||
{
|
||||
// Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp,
|
||||
// and wrappers. compiler/plugin is excluded in Protobuf.js and here.
|
||||
const wellKnownProtos = ['api', 'descriptor', 'source_context', 'type'];
|
||||
const sourceDir = path.join(path.dirname(require.resolve('protobufjs')),
|
||||
'google', 'protobuf');
|
||||
|
||||
for (const proto of wellKnownProtos) {
|
||||
const file = path.join(sourceDir, `${proto}.proto`);
|
||||
const descriptor = Protobuf.loadSync(file).toJSON();
|
||||
|
||||
// @ts-ignore
|
||||
Protobuf.common(proto, descriptor.nested.google.nested);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,4 +67,9 @@ describe('Descriptor types', () => {
|
|||
done();
|
||||
}, (error) => {done(error);});
|
||||
});
|
||||
});
|
||||
|
||||
it('Can use well known Google protos', () => {
|
||||
// This will throw if the well known protos are not available.
|
||||
proto_loader.loadSync(`${TEST_PROTO_DIR}/well_known.proto`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2019 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
extend google.protobuf.FieldOptions {
|
||||
bool redact = 52000;
|
||||
}
|
Loading…
Reference in New Issue