new Service(name, options)
Constructs a new service instance.
Name | Type | Description |
---|---|---|
name |
string |
Service name |
options |
Object.<string, *> |
optional
Service options |
Throws:
Type | Description |
---|---|
TypeError |
If arguments are invalid |
Extends
Members
-
comment { string | null }
-
Comment text, if any.
-
filename { string | null }
-
Defining file name.
-
fullName readonly{ string }
-
Full name including leading dot.
-
methods { Object<string, Method> }
-
Service methods.
-
methodsArray readonly{ Method[] }
-
Methods of this service as an array for iteration.
-
name { string }
-
Unique name within its namespace.
-
nested { Object<string, ReflectionObject> | undefined }
-
Nested objects by name.
-
nestedArray readonly{ ReflectionObject[] }
-
Nested objects of this namespace as an array for iteration.
-
options { Object<string, *> | undefined }
-
Options.
-
parent { Namespace | null }
-
Parent namespace.
-
resolved { boolean }
-
Whether already resolved or not.
-
root readonly{ Root }
-
Reference to the root namespace.
Methods
-
Service.fromJSON(name, json){ Service }
-
Constructs a service from a service descriptor.
Name Type Description name
string Service name
json
IService Service descriptor
Throws:
Type Description TypeError If arguments are invalid
Returns:
Type Description Service Created service -
Adds a nested object to this namespace.
Name Type Description object
ReflectionObject Nested object to add
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If there is already a nested object with this name
Returns:
Type Description Namespace this
-
-
Adds nested objects to this namespace from nested object descriptors.
Name Type Description nestedJson
Object.<string, AnyNestedObject> Any nested object descriptors
Returns:
Type Description Namespace this
-
create(rpcImpl, requestDelimited, responseDelimited){ rpc.Service }
-
Creates a runtime service using the specified rpc implementation.
Name Type Default Description rpcImpl
RPCImpl RPC implementation
requestDelimited
boolean false optional Whether requests are length-delimited
responseDelimited
boolean false optional Whether responses are length-delimited
Returns:
Type Description rpc.Service RPC service. Useful where requests and/or responses are streamed. -
Defines additial namespaces within this one if not yet existing.
Name Type Description path
string | Array.<string> Path to create
json
* optional Nested types to create from JSON
Returns:
Type Description Namespace Pointer to the last namespace created or this
if path is empty -
inherited get(name){ ReflectionObject | null }
-
Gets the nested object of the specified name.
Name Type Description name
string Nested object name
Returns:
Type Description ReflectionObject | null The reflection object or null
if it doesn't exist -
inherited getEnum(name){ Object<string, number> }
-
Gets the values of the nested enum of the specified name.
This methods differs from get in that it returns an enum's values directly and throws instead of returningnull
.Name Type Description name
string Nested enum name
Throws:
Type Description Error If there is no such enum
Returns:
Type Description Object.<string, number> Enum values -
inherited getOption(name){ * }
-
Gets an option value.
Name Type Description name
string Option name
Returns:
Type Description * Option value or undefined
if not set -
inherited lookup(path, filterTypes, parentAlreadyChecked){ ReflectionObject | null }
-
Recursively looks up the reflection object matching the specified path in the scope of this namespace.
Name Type Default Description path
string | Array.<string> Path to look up
filterTypes
* | Array.<*> Filter types, any combination of the constructors of
protobuf.Type
,protobuf.Enum
,protobuf.Service
etc.parentAlreadyChecked
boolean false optional If known, whether the parent has already been checked
Returns:
Type Description ReflectionObject | null Looked up object or null
if none could be found -
inherited lookup(path, parentAlreadyChecked){ ReflectionObject | null }
-
Looks up the reflection object at the specified path, relative to this namespace.
Name Type Default Description path
string | Array.<string> Path to look up
parentAlreadyChecked
boolean false optional Whether the parent has already been checked
Returns:
Type Description ReflectionObject | null Looked up object or null
if none could be found -
Looks up the values of the enum at the specified path, relative to this namespace.
Besides its signature, this methods differs from lookup in that it throws instead of returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to an enumReturns:
Type Description Enum Looked up enum -
Looks up the service at the specified path, relative to this namespace.
Besides its signature, this methods differs from lookup in that it throws instead of returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a serviceReturns:
Type Description Service Looked up service -
Looks up the type at the specified path, relative to this namespace.
Besides its signature, this methods differs from lookup in that it throws instead of returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a typeReturns:
Type Description Type Looked up type -
Looks up the type or enum at the specified path, relative to this namespace.
Besides its signature, this methods differs from lookup in that it throws instead of returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a type or enumReturns:
Type Description Type Looked up type or enum -
inherited onAdd(parent){ undefined }
-
Called when this object is added to a parent.
Name Type Description parent
ReflectionObject Parent added to
Returns:
Type Description undefined -
inherited onRemove(parent){ undefined }
-
Called when this object is removed from a parent.
Name Type Description parent
ReflectionObject Parent removed from
Returns:
Type Description undefined -
Removes a nested object from this namespace.
Name Type Description object
ReflectionObject Nested object to remove
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If
object
is not a member of this namespace
Returns:
Type Description Namespace this
-
-
inherited resolve(){ ReflectionObject }
-
Resolves this objects type references.
Returns:
Type Description ReflectionObject this
-
Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
Returns:
Type Description Namespace this
-
inherited setOption(name, value, ifNotSet){ ReflectionObject }
-
Sets an option.
Name Type Description name
string Option name
value
* Option value
ifNotSet
boolean optional Sets the option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
inherited setOptions(options, ifNotSet){ ReflectionObject }
-
Sets multiple options.
Name Type Description options
Object.<string, *> Options to set
ifNotSet
boolean optional Sets an option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
toJSON(){ IService }
-
Converts this service to a service descriptor.
Returns:
Type Description IService Service descriptor -
inherited toString(){ string }
-
Converts this instance to its string representation.
Returns:
Type Description string Class name[, space, full name]