Constructs a new root namespace instance.
Parameters:
options |
Object.<string, *> |
optional
Top level options |
Extends
Members
-
Comment text, if any.
-
Deferred extension fields.
-
Defining file name.
-
Resolved file names of loaded files.
-
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 -
Fetch content from file path or url
This method exists so you can override it with your own logic.Parameters:
pathstring File path or url
callbackFetchCallback Callback function
Returns:
undefined -
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 -
Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
Parameters:
filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions Parse options
callbackLoadCallback Callback function
Returns:
undefined -
Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
Parameters:
filenamestring | Array.<string> Names of one or multiple files to load
callbackLoadCallback Callback function
Returns:
undefined -
Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
Parameters:
filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Returns:
Promise.<Root> Promise -
Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
Parameters:
filenamestring | Array.<string> Names of one or multiple files to load
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Throws:
Error If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
Returns:
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.
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 -
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.Parameters:
originstring The file name of the importing file
targetstring The file name being imported
Returns:
string | null Resolved path to targetornullto skip the file -
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] -
Loads a namespace descriptor into a root namespace.
Parameters:
jsonINamespace Namespace descriptor
rootRoot optional Root namespace, defaults to create a new one if omitted
depthnumber optional Current nesting depth, defaults to
0Returns:
Root Root namespace