new Namespace(name, options)
Constructs a new namespace instance.
Parameters:
name |
string |
Namespace name |
options |
Object.<string, *> |
optional
Declared options |
Extends
Members
-
Comment text, if any.
-
Defining file name.
-
Full name including leading dot.
-
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.
-
Parent namespace.
-
Parsed Options.
-
Whether already resolved or not.
-
Reference to the root namespace.
Methods
-
Adds a nested object to this namespace.
Parameters:
objectReflectionObject Nested object to add
Throws:
TypeError If arguments are invalid
Error If there is already a nested object with this name
Returns:
Namespace this -
Adds nested objects to this namespace from nested object descriptors.
Parameters:
nestedJsonObject.<string, AnyNestedObject> Any nested object descriptors
depthnumber optional Current nesting depth, defaults to
0Returns:
Namespace this -
Defines additial namespaces within this one if not yet existing.
Parameters:
pathstring | Array.<string> Path to create
json* optional Nested types to create from JSON
Returns:
Namespace Pointer to the last namespace created or thisif path is empty -
inherited get(name){ ReflectionObject | null }
-
Gets the nested object of the specified name.
Parameters:
namestring Nested object name
Returns:
ReflectionObject | null The reflection object or nullif 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.Parameters:
namestring Nested enum name
Throws:
Error If there is no such enum
Returns:
Object.<string, number> Enum values -
Gets an option value.
Parameters:
namestring Option name
Returns:
* Option value or undefinedif 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.
Parameters:
pathstring | Array.<string> Path to look up
filterTypes* | Array.<*> Filter types, any combination of the constructors of
protobuf.Type,protobuf.Enum,protobuf.Serviceetc.parentAlreadyCheckedboolean false optional If known, whether the parent has already been checked
Returns:
ReflectionObject | null Looked up object or nullif none could be found -
inherited lookup(path, parentAlreadyChecked){ ReflectionObject | null }
-
Looks up the reflection object at the specified path, relative to this namespace.
Parameters:
pathstring | Array.<string> Path to look up
parentAlreadyCheckedboolean false optional Whether the parent has already been checked
Returns:
ReflectionObject | null Looked up object or nullif 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.Parameters:
pathstring | Array.<string> Path to look up
Throws:
Error If
pathdoes not point to an enumReturns:
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.Parameters:
pathstring | Array.<string> Path to look up
Throws:
Error If
pathdoes not point to a serviceReturns:
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.Parameters:
pathstring | Array.<string> Path to look up
Throws:
Error If
pathdoes not point to a typeReturns:
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.Parameters:
pathstring | Array.<string> Path to look up
Throws:
Error If
pathdoes not point to a type or enumReturns:
Type Looked up type or enum -
Called when this object is added to a parent.
Parameters:
parentReflectionObject Parent added to
Returns:
undefined -
Called when this object is removed from a parent.
Parameters:
parentReflectionObject Parent removed from
Returns:
undefined -
Removes a nested object from this namespace.
Parameters:
objectReflectionObject Nested object to remove
Throws:
TypeError If arguments are invalid
Error If
objectis not a member of this namespaceReturns:
Namespace this -
inherited resolve(){ ReflectionObject }
-
Resolves this objects type references.
Returns:
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:
Namespace this -
inherited setOption(name, value, ifNotSet){ ReflectionObject }
-
Sets an option.
Parameters:
namestring Option name
value* Option value
ifNotSetboolean | undefined optional Sets the option only if it isn't currently set
Returns:
ReflectionObject this -
inherited setOptions(options, ifNotSet){ ReflectionObject }
-
Sets multiple options.
Parameters:
optionsObject.<string, *> Options to set
ifNotSetboolean optional Sets an option only if it isn't currently set
Returns:
ReflectionObject this -
inherited setParsedOption(name, value, propName){ ReflectionObject }
-
Sets a parsed option.
Parameters:
namestring parsed Option name
value* Option value
propNamestring dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
Returns:
ReflectionObject this -
inherited toJSON(toJSONOptions){ INamespace }
-
Converts this namespace to a namespace descriptor.
Parameters:
toJSONOptionsIToJSONOptions optional JSON conversion options
Returns:
INamespace Namespace descriptor -
Converts this instance to its string representation.
Returns:
string Class name[, space, full name] -
Namespace.arrayToJSON(array, toJSONOptions){ Object<string, *> | undefined }
-
Converts an array of reflection objects to JSON.
Parameters:
arrayArray.<ReflectionObject> Object array
toJSONOptionsIToJSONOptions optional JSON conversion options
Returns:
Object.<string, *> | undefined JSON object or undefinedwhen array is empty -
Namespace.fromJSON(name, json, depth){ Namespace }
-
Constructs a namespace from JSON.
Parameters:
namestring Namespace name
jsonObject.<string, *> JSON object
depthnumber optional Current nesting depth, defaults to
0Throws:
TypeError If arguments are invalid
Returns:
Namespace Created namespace -
Namespace.isReservedId(reserved, id){ boolean }
-
Tests if the specified id is reserved.
Parameters:
reservedArray.<(Array.<number>|string)> | undefined Array of reserved ranges and names
idnumber Id to test
Returns:
boolean trueif reserved, otherwisefalse -
Namespace.isReservedName(reserved, name){ boolean }
-
Tests if the specified name is reserved.
Parameters:
reservedArray.<(Array.<number>|string)> | undefined Array of reserved ranges and names
namestring Name to test
Returns:
boolean trueif reserved, otherwisefalse