Skip to content

Commit

Permalink
Added Namespace#lookupType and Namespace#lookupService (throw instead…
Browse files Browse the repository at this point in the history
… of returning null), see #544
  • Loading branch information
dcodeIO committed Dec 11, 2016
1 parent b8bce03 commit 01365ba
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/targets/json-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var path = require("path"),

var protobuf = require("../..");

json_module.description = "JSON representation as a module (AMD, CommonJS, global)"
json_module.description = "JSON representation as a module"

function json_module(root, options, callback) {

Expand Down
2 changes: 1 addition & 1 deletion cli/targets/static-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var path = require("path"),

var protobuf = require("../..");

static_module_target.description = "Static code without reflection as a module (AMD, CommonJS, global)";
static_module_target.description = "Static code without reflection as a module";

function static_module_target(root, options, callback) {
require("./static")(root, options, function(err, output) {
Expand Down
30 changes: 29 additions & 1 deletion dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,31 @@ NamespacePrototype.lookup = function lookup(path, parentAlreadyChecked) {
return null;
return this.parent.lookup(path);
};

/**
* Looks up the {@link Type|type} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Type} Looked up type
* @throws {Error} If `path` does not point to a type
*/
NamespacePrototype.lookupType = function lookupType(path) {
var found = this.lookup(path);
if (!(found instanceof Type))
throw Error("no such type");
return found;
};

/**
* Looks up the {@link Service|service} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Service} Looked up service
* @throws {Error} If `path` does not point to a service
*/
NamespacePrototype.lookupService = function lookupService(path) {
var found = this.lookup(path);
if (!(found instanceof Service))
throw Error("no such service");
return found;
};
36 changes: 35 additions & 1 deletion types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* protobuf.js v6.1.0 TypeScript definitions
* Generated Sun, 11 Dec 2016 12:37:58 UTC
* Generated Sun, 11 Dec 2016 23:22:51 UTC
*/
declare module "protobufjs" {

Expand Down Expand Up @@ -774,6 +774,24 @@ declare module "protobufjs" {
*/
lookup(path: (string|string[]), parentAlreadyChecked?: boolean): ReflectionObject;

/**
* Looks up the {@link Type|type} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Type} Looked up type
* @throws {Error} If `path` does not point to a type
*/
lookupType(path: (string|string[])): Type;

/**
* Looks up the {@link Service|service} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Service} Looked up service
* @throws {Error} If `path` does not point to a service
*/
lookupService(path: (string|string[])): Service;

}

/**
Expand Down Expand Up @@ -926,6 +944,14 @@ declare module "protobufjs" {
*/
oneof: string[];

/**
* Fields that belong to this oneof as an array for iteration.
* @name OneOf#fieldsArray
* @type {Field[]}
* @readonly
*/
fieldsArray: Field[];

/**
* Tests if the specified JSON object describes a oneof.
* @param {*} json JSON object
Expand Down Expand Up @@ -1745,6 +1771,14 @@ declare module "protobufjs" {

}

/**
* Fast 64 bit floats for buffers.
* @memberof util
* @namespace
*/
module f64 {
}

/**
* Constructs new long bits.
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
Expand Down

0 comments on commit 01365ba

Please sign in to comment.