Skip to content

Commit 01365ba

Browse files
committed
Added Namespace#lookupType and Namespace#lookupService (throw instead of returning null), see #544
1 parent b8bce03 commit 01365ba

9 files changed

+99
-9
lines changed

cli/targets/json-module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var path = require("path"),
77

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

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

1212
function json_module(root, options, callback) {
1313

cli/targets/static-module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var path = require("path"),
1212

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

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

1717
function static_module_target(root, options, callback) {
1818
require("./static")(root, options, function(err, output) {

dist/protobuf.js

+29-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

45 Bytes
Binary file not shown.

dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/namespace.js

+28
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,31 @@ NamespacePrototype.lookup = function lookup(path, parentAlreadyChecked) {
267267
return null;
268268
return this.parent.lookup(path);
269269
};
270+
271+
/**
272+
* Looks up the {@link Type|type} at the specified path, relative to this namespace.
273+
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
274+
* @param {string|string[]} path Path to look up
275+
* @returns {Type} Looked up type
276+
* @throws {Error} If `path` does not point to a type
277+
*/
278+
NamespacePrototype.lookupType = function lookupType(path) {
279+
var found = this.lookup(path);
280+
if (!(found instanceof Type))
281+
throw Error("no such type");
282+
return found;
283+
};
284+
285+
/**
286+
* Looks up the {@link Service|service} at the specified path, relative to this namespace.
287+
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
288+
* @param {string|string[]} path Path to look up
289+
* @returns {Service} Looked up service
290+
* @throws {Error} If `path` does not point to a service
291+
*/
292+
NamespacePrototype.lookupService = function lookupService(path) {
293+
var found = this.lookup(path);
294+
if (!(found instanceof Service))
295+
throw Error("no such service");
296+
return found;
297+
};

types/protobuf.js.d.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* protobuf.js v6.1.0 TypeScript definitions
3-
* Generated Sun, 11 Dec 2016 12:37:58 UTC
3+
* Generated Sun, 11 Dec 2016 23:22:51 UTC
44
*/
55
declare module "protobufjs" {
66

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

777+
/**
778+
* Looks up the {@link Type|type} at the specified path, relative to this namespace.
779+
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
780+
* @param {string|string[]} path Path to look up
781+
* @returns {Type} Looked up type
782+
* @throws {Error} If `path` does not point to a type
783+
*/
784+
lookupType(path: (string|string[])): Type;
785+
786+
/**
787+
* Looks up the {@link Service|service} at the specified path, relative to this namespace.
788+
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
789+
* @param {string|string[]} path Path to look up
790+
* @returns {Service} Looked up service
791+
* @throws {Error} If `path` does not point to a service
792+
*/
793+
lookupService(path: (string|string[])): Service;
794+
777795
}
778796

779797
/**
@@ -926,6 +944,14 @@ declare module "protobufjs" {
926944
*/
927945
oneof: string[];
928946

947+
/**
948+
* Fields that belong to this oneof as an array for iteration.
949+
* @name OneOf#fieldsArray
950+
* @type {Field[]}
951+
* @readonly
952+
*/
953+
fieldsArray: Field[];
954+
929955
/**
930956
* Tests if the specified JSON object describes a oneof.
931957
* @param {*} json JSON object
@@ -1745,6 +1771,14 @@ declare module "protobufjs" {
17451771

17461772
}
17471773

1774+
/**
1775+
* Fast 64 bit floats for buffers.
1776+
* @memberof util
1777+
* @namespace
1778+
*/
1779+
module f64 {
1780+
}
1781+
17481782
/**
17491783
* Constructs new long bits.
17501784
* @classdesc Helper class for working with the low and high bits of a 64 bit value.

0 commit comments

Comments
 (0)