PR #8465 added support for packageDefinition for ClientGrpc, this commit adds it to ServerGrpc.
Exported common packageDefinition logic to getGrpcPackageDefinition and used it in both gRPC Server & Client, for consistency.
This change means that protoPath is now optional - getGrpcPackageDefinition verifies that either protoPath or PackageDefinition exist.
Also, fixed the error thrown from ServerGrpc.loadProto: was Error, now InvalidProtoDefinitionException, as it is in ClientGrpc
RPC methods in protobuf are commonly declare in PascalCase, but they were generated lowercase
by ClientGrpcProxy.getService method.
Protobuf and gRPC have tools to generate interface and message in Typescript directly from
protobuf. It's a powerful feature that's helping to maintain only one source of truth.
But with that lowercase method generation, developers were forced to define their own interface
which can be painful to maintain.
This commit fix that issue by generating methods both in lowercase and in uppercase.
Solves #9047
Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
Removed GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH and GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH constants. This default values are already the same in the underlying gRPC library. If the gRPC team decides to change that values in the future, nestjs should adopt the new values automatically.
Calling getService of grpc clients with multiple packages shows error
'Channel third argument (options) must be an object with string keys
and integer or string values'. Which is caused by passing options with
GrpcOptions['options'] format to grpc client's constructor.
As the options are transformed and kept in 'maxMessageLengthOptions' and
'keepaliveOptions', we can remove and skip passing ClientGrpcProxy's
options to node grpc Client's constructor.
I use to have the following exception:
```
(node:19) UnhandledPromiseRejectionWarning: TypeError: Channel options must be an object with string keys and integer or string values
```
I was passing down a credential object to the options like this:
```
const credentials = grpc.credentials.createSsl(
readFileSync('/srv/certs/rootCA.pem'),
readFileSync('/srv/certs/server.key'),
readFileSync('/srv/certs/server.crt')
);
// later
@Client({
transport: Transport.GRPC,
options: {
url: 'ms-proxy:50051',
package: 'hero',
protoPath: join(__dirname, '..', 'proto/hero.proto'),
credentials,
},
})
``