GrpcClient

GrpcClient

new GrpcClient(options)

gRPC-fallback version of GrpcClient Implements GrpcClient API for a browser using grpc-fallback protocol (sends serialized protobuf to HTTP/1 $rpc endpoint).

Parameters:
Name Type Description
options

GrpcClientOptions

Members

authClient

baseDirectory

Base directory for resolving client certificates.

Methods

(async) _detectClientCertificate(optionsopt) → {Promise}

Detect mTLS client certificate based on logic described in https://google.aip.dev/auth/4114.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object.

Returns:
Type Description
Promise

Resolves array of strings representing cert and key.

_mtlsServicePath(servicePath, customServicePath, hasCertificate) → {string}

Return service path, taking into account mTLS logic. See: https://google.aip.dev/auth/4114

Parameters:
Name Type Description
servicePath string | undefined

The path of the service.

customServicePath string | undefined

Did the user provide a custom service URL.

hasCertificate boolean

Was a certificate found.

Returns:
Type Description
string

The DNS address for this service.

constructSettings(serviceName, clientConfig, configOverrides, headers) → {Object}

gRPC-fallback version of constructSettings A wrapper of constructSettings function under the gRPC context.

Most of parameters are common among constructSettings, please take a look.

Parameters:
Name Type Description
serviceName string

The fullly-qualified name of the service.

clientConfig Object

A dictionary of the client config.

configOverrides Object

A dictionary of overriding configs.

headers Object

A dictionary of additional HTTP header name to its value.

Returns:
Type Description
Object

A mapping of method names to CallSettings.

constructSettings(serviceName, clientConfig, configOverrides, headers) → {Object}

A wrapper of constructSettings function under the gRPC context.

Most of parameters are common among constructSettings, please take a look.

Parameters:
Name Type Description
serviceName string

The fullly-qualified name of the service.

clientConfig Object

A dictionary of the client config.

configOverrides Object

A dictionary of overriding configs.

headers Object

A dictionary of additional HTTP header name to its value.

Returns:
Type Description
Object

A mapping of method names to CallSettings.

(async) createStub(CreateStub, service, opts) → {Promise}

gRPC-fallback version of createStub Creates a gRPC-fallback stub with authentication headers built from supplied AuthClient instance

Parameters:
Name Type Description
CreateStub function

The constructor function of the stub.

service Object

A protobufjs Service object (as returned by lookupService)

opts Object

Connection options, as described below.

Properties
Name Type Description
servicePath string

The hostname of the API endpoint service.

port number

The port of the service.

Returns:
Type Description
Promise

A promise which resolves to a gRPC-fallback service stub, which is a protobuf.js service stub instance modified to match the gRPC stub API

(async) createStub(CreateStub, options, defaultServicePath) → {Promise}

Creates a gRPC stub with current gRPC and auth.

Parameters:
Name Type Description
CreateStub function

The constructor function of the stub.

options Object

The optional arguments to customize gRPC connection. This options will be passed to the constructor of gRPC client too.

Properties
Name Type Attributes Description
servicePath string

The name of the server of the service.

port number

The port of the service.

sslCreds grpcTypes.ClientCredentials <optional>

The credentials to be used to set up gRPC connection.

defaultServicePath string

The default service path.

Returns:
Type Description
Promise

A promise which resolves to a gRPC stub instance.

loadFromProto(filename, options, ignoreCache)

Loads the gRPC service from the proto file(s) at the given path and with the given options. Caches the loaded protos so the subsequent loads don't do any disk reads.

Parameters:
Name Type Default Description
filename

The path to the proto file(s).

options

Options for loading the proto file.

ignoreCache false

Defaults to false. Set it to true if the caching logic incorrectly decides that the options object is the same, or if you want to re-read the protos from disk for any other reason.

loadProto(jsonObject) → {Object}

gRPC-fallback version of loadProto Loads the protobuf root object from a JSON object created from a proto file

Parameters:
Name Type Description
jsonObject Object

A JSON version of a protofile created usin protobuf.js

Returns:
Type Description
Object

Root namespace of proto JSON

loadProto(protoPath, filename, ignoreCache) → {Object.<string, *>}

Load gRPC proto service from a filename looking in googleapis common protos when necessary. Caches the loaded protos so the subsequent loads don't do any disk reads.

Parameters:
Name Type Default Description
protoPath String

The directory to search for the protofile.

filename String | Array.<String>

The filename(s) of the proto(s) to be loaded. If omitted, protoPath will be treated as a file path to load.

ignoreCache false

Defaults to false. Set it to true if the caching logic incorrectly decides that the options object is the same, or if you want to re-read the protos from disk for any other reason.

Returns:
Type Description
Object.<string, *>

The gRPC loaded result (the toplevel namespace object).

(static) clearProtoCache()

In rare cases users might need to deallocate all memory consumed by loaded protos. This method will delete the proto cache content.

(static) clearProtoCache()

In rare cases users might need to deallocate all memory consumed by loaded protos. This method will delete the proto cache content.

(static) createByteLengthFunction(message) → {function}

Creates a 'bytelength' function for a given proto message class.

See BundleDescriptor about the meaning of the return value.

Parameters:
Name Type Description
message function

a constructor function that is generated by protobuf.js. Assumes 'encoder' field in the message.

Returns:
Type Description
function
  • a function to compute the byte length for an object.

(static) createByteLengthFunction(message) → {function}

Creates a 'bytelength' function for a given proto message class.

See BundleDescriptor about the meaning of the return value.

Parameters:
Name Type Description
message function

a constructor function that is generated by protobuf.js. Assumes 'encoder' field in the message.

Returns:
Type Description
function
  • a function to compute the byte length for an object.

(static) protoCacheKey()

Key for proto cache map. We are doing our best to make sure we respect the options, so if the same proto file is loaded with different set of options, the cache won't be used. Since some of the options are Functions (e.g. enums: String - see below in loadProto()), they will be omitted from the cache key. If the cache breaks anything for you, use the ignoreCache parameter of loadProto() to disable it.

(static) protobufFromJSON(jsonObject) → {Object}

Loads the protobuf root object from a JSON object created from a proto file. By default, this is cached in a global cache and the results should not be mutated.

Parameters:
Name Type Description
jsonObject Object

A JSON version of a protofile created usin protobuf.js

Returns:
Type Description
Object

Root namespace of proto JSON

GrpcClient

new GrpcClient(optionsopt)

A class which keeps the context of gRPC and auth for the gRPC.

Parameters:
Name Type Attributes Description
options Object <optional>

The optional parameters. It will be directly passed to google-auth-library library, so parameters like keyFile or credentials will be valid.

Properties
Name Type Attributes Description
auth Object <optional>

An instance of google-auth-library. When specified, this auth instance will be used instead of creating a new one.

grpc Object <optional>

When specified, this will be used for the 'grpc' module in this context. By default, it will load the grpc module in the standard way.

Members

authClient

baseDirectory

Base directory for resolving client certificates.

Methods

(async) _detectClientCertificate(optionsopt) → {Promise}

Detect mTLS client certificate based on logic described in https://google.aip.dev/auth/4114.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object.

Returns:
Type Description
Promise

Resolves array of strings representing cert and key.

_mtlsServicePath(servicePath, customServicePath, hasCertificate) → {string}

Return service path, taking into account mTLS logic. See: https://google.aip.dev/auth/4114

Parameters:
Name Type Description
servicePath string | undefined

The path of the service.

customServicePath string | undefined

Did the user provide a custom service URL.

hasCertificate boolean

Was a certificate found.

Returns:
Type Description
string

The DNS address for this service.

constructSettings(serviceName, clientConfig, configOverrides, headers) → {Object}

gRPC-fallback version of constructSettings A wrapper of constructSettings function under the gRPC context.

Most of parameters are common among constructSettings, please take a look.

Parameters:
Name Type Description
serviceName string

The fullly-qualified name of the service.

clientConfig Object

A dictionary of the client config.

configOverrides Object

A dictionary of overriding configs.

headers Object

A dictionary of additional HTTP header name to its value.

Returns:
Type Description
Object

A mapping of method names to CallSettings.

constructSettings(serviceName, clientConfig, configOverrides, headers) → {Object}

A wrapper of constructSettings function under the gRPC context.

Most of parameters are common among constructSettings, please take a look.

Parameters:
Name Type Description
serviceName string

The fullly-qualified name of the service.

clientConfig Object

A dictionary of the client config.

configOverrides Object

A dictionary of overriding configs.

headers Object

A dictionary of additional HTTP header name to its value.

Returns:
Type Description
Object

A mapping of method names to CallSettings.

(async) createStub(CreateStub, service, opts) → {Promise}

gRPC-fallback version of createStub Creates a gRPC-fallback stub with authentication headers built from supplied AuthClient instance

Parameters:
Name Type Description
CreateStub function

The constructor function of the stub.

service Object

A protobufjs Service object (as returned by lookupService)

opts Object

Connection options, as described below.

Properties
Name Type Description
servicePath string

The hostname of the API endpoint service.

port number

The port of the service.

Returns:
Type Description
Promise

A promise which resolves to a gRPC-fallback service stub, which is a protobuf.js service stub instance modified to match the gRPC stub API

(async) createStub(CreateStub, options, defaultServicePath) → {Promise}

Creates a gRPC stub with current gRPC and auth.

Parameters:
Name Type Description
CreateStub function

The constructor function of the stub.

options Object

The optional arguments to customize gRPC connection. This options will be passed to the constructor of gRPC client too.

Properties
Name Type Attributes Description
servicePath string

The name of the server of the service.

port number

The port of the service.

sslCreds grpcTypes.ClientCredentials <optional>

The credentials to be used to set up gRPC connection.

defaultServicePath string

The default service path.

Returns:
Type Description
Promise

A promise which resolves to a gRPC stub instance.

loadFromProto(filename, options, ignoreCache)

Loads the gRPC service from the proto file(s) at the given path and with the given options. Caches the loaded protos so the subsequent loads don't do any disk reads.

Parameters:
Name Type Default Description
filename

The path to the proto file(s).

options

Options for loading the proto file.

ignoreCache false

Defaults to false. Set it to true if the caching logic incorrectly decides that the options object is the same, or if you want to re-read the protos from disk for any other reason.

loadProto(jsonObject) → {Object}

gRPC-fallback version of loadProto Loads the protobuf root object from a JSON object created from a proto file

Parameters:
Name Type Description
jsonObject Object

A JSON version of a protofile created usin protobuf.js

Returns:
Type Description
Object

Root namespace of proto JSON

loadProto(protoPath, filename, ignoreCache) → {Object.<string, *>}

Load gRPC proto service from a filename looking in googleapis common protos when necessary. Caches the loaded protos so the subsequent loads don't do any disk reads.

Parameters:
Name Type Default Description
protoPath String

The directory to search for the protofile.

filename String | Array.<String>

The filename(s) of the proto(s) to be loaded. If omitted, protoPath will be treated as a file path to load.

ignoreCache false

Defaults to false. Set it to true if the caching logic incorrectly decides that the options object is the same, or if you want to re-read the protos from disk for any other reason.

Returns:
Type Description
Object.<string, *>

The gRPC loaded result (the toplevel namespace object).

(static) clearProtoCache()

In rare cases users might need to deallocate all memory consumed by loaded protos. This method will delete the proto cache content.

(static) clearProtoCache()

In rare cases users might need to deallocate all memory consumed by loaded protos. This method will delete the proto cache content.

(static) createByteLengthFunction(message) → {function}

Creates a 'bytelength' function for a given proto message class.

See BundleDescriptor about the meaning of the return value.

Parameters:
Name Type Description
message function

a constructor function that is generated by protobuf.js. Assumes 'encoder' field in the message.

Returns:
Type Description
function
  • a function to compute the byte length for an object.

(static) createByteLengthFunction(message) → {function}

Creates a 'bytelength' function for a given proto message class.

See BundleDescriptor about the meaning of the return value.

Parameters:
Name Type Description
message function

a constructor function that is generated by protobuf.js. Assumes 'encoder' field in the message.

Returns:
Type Description
function
  • a function to compute the byte length for an object.

(static) protoCacheKey()

Key for proto cache map. We are doing our best to make sure we respect the options, so if the same proto file is loaded with different set of options, the cache won't be used. Since some of the options are Functions (e.g. enums: String - see below in loadProto()), they will be omitted from the cache key. If the cache breaks anything for you, use the ignoreCache parameter of loadProto() to disable it.

(static) protobufFromJSON(jsonObject) → {Object}

Loads the protobuf root object from a JSON object created from a proto file. By default, this is cached in a global cache and the results should not be mutated.

Parameters:
Name Type Description
jsonObject Object

A JSON version of a protofile created usin protobuf.js

Returns:
Type Description
Object

Root namespace of proto JSON