new Root(options)
Constructs a new root namespace instance.
| Name | Type | Description |
|---|---|---|
options |
Object.<string, *> |
optional
Top level options |
Extends
Members
-
comment { string | null }
-
Comment text, if any.
-
deferred { Field[] }
-
Deferred extension fields.
-
filename { string | null }
-
Defining file name.
-
files { string[] }
-
Resolved file names of loaded files.
-
fullName readonly{ string }
-
Full name including leading dot.
-
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
-
Root.fromJSON(json, root){ Root }
-
Loads a namespace descriptor into a root namespace.
Name Type Description jsonINamespace Nameespace descriptor
rootRoot optional Root namespace, defaults to create a new one if omitted
Returns:
Type Description Root Root namespace -
Adds a nested object to this namespace.
Name Type Description objectReflectionObject 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 nestedJsonObject.<string, AnyNestedObject> Any nested object descriptors
Returns:
Type Description Namespace this -
Defines additial namespaces within this one if not yet existing.
Name Type Description pathstring | Array.<string> Path to create
json* optional Nested types to create from JSON
Returns:
Type Description 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.
Name Type Description namestring Nested object name
Returns:
Type Description 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.Name Type Description namestring 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 namestring Option name
Returns:
Type Description * Option value or undefinedif not set -
load(filename, options, callback){ undefined }
-
Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
Name Type Description filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions Parse options
callbackLoadCallback Callback function
Returns:
Type Description undefined -
load(filename, callback){ undefined }
-
Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
Name Type Description filenamestring | Array.<string> Names of one or multiple files to load
callbackLoadCallback Callback function
Returns:
Type Description undefined -
load(filename, options){ Promise<Root> }
-
Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
Name Type Description filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Returns:
Type Description Promise.<Root> Promise -
loadSync(filename, options){ Root }
-
Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
Name Type Description filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Throws:
Type Description Error If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
Returns:
Type Description Root Root namespace -
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 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:
Type Description 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.
Name Type Default Description pathstring | Array.<string> Path to look up
parentAlreadyCheckedboolean false optional Whether the parent has already been checked
Returns:
Type Description 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.Name Type Description pathstring | Array.<string> Path to look up
Throws:
Type Description Error If
pathdoes 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 pathstring | Array.<string> Path to look up
Throws:
Type Description Error If
pathdoes 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 pathstring | Array.<string> Path to look up
Throws:
Type Description Error If
pathdoes 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 pathstring | Array.<string> Path to look up
Throws:
Type Description Error If
pathdoes 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 parentReflectionObject Parent added to
Returns:
Type Description undefined -
inherited onRemove(parent){ undefined }
-
Called when this object is removed from a parent.
Name Type Description parentReflectionObject Parent removed from
Returns:
Type Description undefined -
Removes a nested object from this namespace.
Name Type Description objectReflectionObject Nested object to remove
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If
objectis 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 -
resolvePath(origin, target){ string | null }
-
Resolves the path of an imported file, relative to the importing origin.
This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.Name Type Description originstring The file name of the importing file
targetstring The file name being imported
Returns:
Type Description string | null Resolved path to targetornullto skip the file -
inherited setOption(name, value, ifNotSet){ ReflectionObject }
-
Sets an option.
Name Type Description namestring Option name
value* Option value
ifNotSetboolean 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 optionsObject.<string, *> Options to set
ifNotSetboolean optional Sets an option only if it isn't currently set
Returns:
Type Description ReflectionObject this -
inherited toJSON(){ INamespace }
-
Converts this namespace to a namespace descriptor.
Returns:
Type Description INamespace Namespace descriptor -
inherited toString(){ string }
-
Converts this instance to its string representation.
Returns:
Type Description string Class name[, space, full name]