Skip to content

Commit

Permalink
Added variations for Root#load, see #527
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 7, 2016
1 parent 7c3bf8d commit 9df6a3d
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 59 deletions.
56 changes: 32 additions & 24 deletions 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.

4 changes: 2 additions & 2 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.

8 changes: 4 additions & 4 deletions src/codegen/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ var Enum = require("../enum"),

/**
* Decodes a message of `this` message's type.
* @param {Reader} reader Reader to decode from
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Length of the message, if known beforehand
* @returns {Prototype} Populated runtime message
* @this Type
*/
decode.fallback = function decode_fallback(reader, length) {
decode.fallback = function decode_fallback(readerOrBuffer, length) {
/* eslint-disable no-invalid-this, block-scoped-var, no-redeclare */
var fields = this.getFieldsById(),
reader = reader instanceof Reader ? reader : Reader.create(reader),
reader = readerOrBuffer instanceof Reader ? readerOrBuffer : Reader.create(readerOrBuffer),
limit = length === undefined ? reader.len : reader.pos + length,
message = new (this.getCtor())();
while (reader.pos < limit) {
Expand Down Expand Up @@ -87,7 +87,7 @@ decode.fallback = function decode_fallback(reader, length) {
/**
* Generates a decoder specific to the specified message type, with an identical signature to {@link codegen.decode.fallback}.
* @param {Type} mtype Message type
* @returns {function(string, ...*):string} {@link codegen} instance
* @returns {CodegenInstance} {@link codegen|Codegen} instance
*/
decode.generate = function decode_generate(mtype) {
/* eslint-disable no-unexpected-multiline */
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ encode.fallback = function encode_fallback(message, writer) {
/**
* Generates an encoder specific to the specified message type, with an identical signature to {@link codegen.encode.fallback}.
* @param {Type} mtype Message type
* @returns {function(string, ...*):string} {@link codegen} instance
* @returns {CodegenInstance} {@link codegen|Codegen} instance
*/
encode.generate = function encode_generate(mtype) {
/* eslint-disable no-unexpected-multiline */
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ verify.fallback = function verify_fallback(message) {
/**
* Generates a verifier specific to the specified message type, with an identical signature to {@link codegen.verify.fallback}.
* @param {Type} mtype Message type
* @returns {function(string, ...*):string} {@link codegen} instance
* @returns {CodegenInstance} {@link codegen|Codegen} instance
*/
verify.generate = function verify_generate(mtype) {
/* eslint-disable no-unexpected-multiline */
Expand Down
4 changes: 2 additions & 2 deletions src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var _TypeError = util._TypeError;
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} type Value type
* @param {string} [rule=optional] Field rule
* @param {string} [extend] Extended type if different from parent
* @param {string|Object} [rule="optional"] Field rule
* @param {string|Object} [extend] Extended type if different from parent
* @param {Object} [options] Declared options
*/
function Field(name, id, type, rule, extend, options) {
Expand Down
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var protobuf = global.protobuf = exports;

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param {string|string[]} filename One or multiple files to load
* @param {Root} root Root namespace, defaults to create a new one if omitted.
* @param {function(?Error, Root=)} callback Callback function
Expand All @@ -17,9 +17,10 @@ function load(filename, root, callback) {
root = new protobuf.Root();
return root.load(filename, callback);
}
// function load(filename:string, root:Root, callback:function):undefined

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
Expand All @@ -28,19 +29,19 @@ function load(filename, root, callback) {
* @throws {TypeError} If arguments are invalid
* @variation 2
*/
// function load(filename, callback)
// function load(filename:string, callback:function):undefined

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Promise<Root>} A promise
* @returns {Promise<Root>} Promise
* @throws {TypeError} If arguments are invalid
* @variation 3
*/
// function load(filename, [root]):Promise
// function load(filename:string, [root:Root]):Promise<Root>

protobuf.load = load;

Expand Down
18 changes: 15 additions & 3 deletions src/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ Root.fromJSON = function fromJSON(json, root) {
RootPrototype.resolvePath = util.resolvePath;

/**
* Loads one or multiple .proto or preprocessed .json files into this root namespace.
* Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
* @param {string|string[]} filename Names of one or multiple files to load
* @param {function(?Error, Root=)} [callback] Node-style callback function
* @returns {Promise<Root>|undefined} A promise if `callback` has been omitted
* @param {function(?Error, Root=)} callback Node-style callback function
* @returns {undefined}
* @throws {TypeError} If arguments are invalid
*/
RootPrototype.load = function load(filename, callback) {
Expand Down Expand Up @@ -155,6 +155,18 @@ RootPrototype.load = function load(filename, callback) {
finish(null);
return undefined;
};
// function load(filename:string, callback:function):undefined

/**
* Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
* @name Root#load
* @function
* @param {string|string[]} filename Names of one or multiple files to load
* @returns {Promise<Root>} Promise
* @throws {TypeError} If arguments are invalid
* @variation 2
*/
// function load(filename:string):Promise<Root>

/**
* Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
Expand Down
39 changes: 25 additions & 14 deletions types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
* protobuf.js v6.1.0 TypeScript definitions
* Generated Wed, 07 Dec 2016 19:27:57 UTC
* Generated Wed, 07 Dec 2016 21:12:41 UTC
*/
declare module "protobufjs" {

Expand Down Expand Up @@ -132,8 +132,8 @@ declare module "protobufjs" {
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} type Value type
* @param {string} [rule=optional] Field rule
* @param {string} [extend] Extended type if different from parent
* @param {string|Object} [rule="optional"] Field rule
* @param {string|Object} [extend] Extended type if different from parent
* @param {Object} [options] Declared options
*/
class Field extends ReflectionObject {
Expand All @@ -145,11 +145,11 @@ declare module "protobufjs" {
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} type Value type
* @param {string} [rule=optional] Field rule
* @param {string} [extend] Extended type if different from parent
* @param {string|Object} [rule="optional"] Field rule
* @param {string|Object} [extend] Extended type if different from parent
* @param {Object} [options] Declared options
*/
constructor(name: string, id: number, type: string, rule?: string, extend?: string, options?: Object);
constructor(name: string, id: number, type: string, rule?: (string|Object), extend?: (string|Object), options?: Object);

/**
* Field rule, if any.
Expand Down Expand Up @@ -292,7 +292,7 @@ declare module "protobufjs" {
}

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param {string|string[]} filename One or multiple files to load
* @param {Root} root Root namespace, defaults to create a new one if omitted.
* @param {function(?Error, Root=)} callback Callback function
Expand All @@ -302,7 +302,7 @@ declare module "protobufjs" {
function load(filename: (string|string[]), root: Root, callback: (() => any)): undefined;

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
Expand All @@ -314,12 +314,12 @@ declare module "protobufjs" {
function load(filename: (string|string[]), callback: (() => any)): undefined;

/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Promise<Root>} A promise
* @returns {Promise<Root>} Promise
* @throws {TypeError} If arguments are invalid
* @variation 3
*/
Expand Down Expand Up @@ -1189,13 +1189,24 @@ declare module "protobufjs" {
resolvePath(origin: string, target: string): string;

/**
* Loads one or multiple .proto or preprocessed .json files into this root namespace.
* Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
* @param {string|string[]} filename Names of one or multiple files to load
* @param {function(?Error, Root=)} [callback] Node-style callback function
* @returns {Promise<Root>|undefined} A promise if `callback` has been omitted
* @param {function(?Error, Root=)} callback Node-style callback function
* @returns {undefined}
* @throws {TypeError} If arguments are invalid
*/
load(filename: (string|string[]), callback: (() => any)): undefined;

/**
* Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
* @name Root#load
* @function
* @param {string|string[]} filename Names of one or multiple files to load
* @returns {Promise<Root>} Promise
* @throws {TypeError} If arguments are invalid
* @variation 2
*/
load(filename: (string|string[]), callback?: (() => any)): (Promise<Root>|undefined);
load(filename: (string|string[])): Promise<Root>;

}

Expand Down

0 comments on commit 9df6a3d

Please sign in to comment.