Skip to content

Commit

Permalink
Other: Use more precise types for message-like plain objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 21, 2017
1 parent 5a1f861 commit 588ffd9
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 415 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Note that **Message** refers to any message type below.
```

* **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
is an automatically generated message specific encoder expecting a valid message or plain object. Note that this methods does not implicitly verify the message and that it's up to the user to make sure that the data can actually be encoded properly.
is an automatically generated message specific encoder expecting a valid message or plain object. Note that this method does not implicitly verify the message and that it's up to the user to make sure that the data can actually be encoded properly.

```js
var buffer = AwesomeMessage.encode(message).finish();
Expand Down
11 changes: 5 additions & 6 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function buildType(ref, type) {
push("");
pushComment([
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
"@param {" + fullName + "|Object} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
"@param {" + fullName + "|Object.<string,*>} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
Expand All @@ -404,7 +404,7 @@ function buildType(ref, type) {
push("");
pushComment([
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
"@param {" + fullName + "|Object} message " + type.name + " message or plain object to encode",
"@param {" + fullName + "|Object.<string,*>} message " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [writer] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
Expand Down Expand Up @@ -456,11 +456,10 @@ function buildType(ref, type) {
push("");
pushComment([
"Verifies " + aOrAn(type.name) + " message.",
"@param {" + fullName + "|Object} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to verify",
"@param {Object.<string,*>} " + (config.beautify ? "message" : "m") + " " + type.name + " object to verify",
"@returns {?string} `null` if valid, otherwise the reason why it is not"
]);
buildFunction(type, "verify", protobuf.verifier(type));

}

if (config.convert) {
Expand Down Expand Up @@ -570,7 +569,7 @@ function buildService(ref, service) {
push("");
pushComment([
method.comment || "Calls " + method.name + ".",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " message or plain object",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object.<string,*>} request " + method.resolvedRequestType.name + " message or plain object",
"@param {" + cbName + "} callback Node-style callback called with the error, if any, and " + method.resolvedResponseType.name,
"@returns {undefined}"
]);
Expand All @@ -585,7 +584,7 @@ function buildService(ref, service) {
method.comment || "Calls " + method.name + ".",
"@name " + name(service.name) + "#" + lcName,
"@function",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " message or plain object",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object.<string,*>} request " + method.resolvedRequestType.name + " message or plain object",
"@returns {Promise<"+method.resolvedResponseType.fullName.substring(1)+">} Promise",
"@variation 2"
]);
Expand Down
6 changes: 3 additions & 3 deletions src/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Class.prototype = Message;
* Encodes a message of this type.
* @name Class#encode
* @function
* @param {Message|Object} message Message to encode
* @param {Message|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
Expand All @@ -145,7 +145,7 @@ Class.prototype = Message;
* Encodes a message of this type preceeded by its length as a varint.
* @name Class#encodeDelimited
* @function
* @param {Message|Object} message Message to encode
* @param {Message|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
Expand All @@ -170,6 +170,6 @@ Class.prototype = Message;
* Verifies a message of this type.
* @name Class#verify
* @function
* @param {Message|Object} message Message or plain object to verify
* @param {Message|Object.<string,*>} message Message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
6 changes: 3 additions & 3 deletions src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Message(properties) {

/**
* Encodes a message of this type.
* @param {Message|Object} message Message to encode
* @param {Message|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
Expand All @@ -44,7 +44,7 @@ Message.encode = function encode(message, writer) {

/**
* Encodes a message of this type preceeded by its length as a varint.
* @param {Message|Object} message Message to encode
* @param {Message|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ Message.decodeDelimited = function decodeDelimited(reader) {
* Verifies a message of this type.
* @name Message.verify
* @function
* @param {Message|Object} message Message or plain object to verify
* @param {Message|Object.<string,*>} message Message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Message.verify = function verify(message) {
Expand Down
2 changes: 1 addition & 1 deletion src/oneof.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Field = require("./field");
* @extends ReflectionObject
* @constructor
* @param {string} name Oneof name
* @param {string[]|Object} [fieldNames] Field names
* @param {string[]|Object.<string,*>} [fieldNames] Field names
* @param {Object.<string,*>} [options] Declared options
*/
function OneOf(name, fieldNames, options) {
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var util = require("../util/minimal");
* A service method part of a {@link rpc.ServiceMethodMixin|ServiceMethodMixin} and thus {@link rpc.Service} as created by {@link Service.create}.
* @typedef rpc.ServiceMethod
* @type {function}
* @param {Message|Object} request Request message or plain object
* @param {Message|Object.<string,*>} request Request message or plain object
* @param {rpc.ServiceMethodCallback} [callback] Node-style callback called with the error, if any, and the response message
* @returns {Promise<Message>} Promise if `callback` has been omitted, otherwise `undefined`
*/
Expand Down Expand Up @@ -79,7 +79,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
* @param {Method|rpc.ServiceMethod} method Reflected or static method
* @param {function} requestCtor Request constructor
* @param {function} responseCtor Response constructor
* @param {Message|Object} request Request message or plain object
* @param {Message|Object.<string,*>} request Request message or plain object
* @param {rpc.ServiceMethodCallback} callback Service callback
* @returns {undefined}
*/
Expand Down
8 changes: 4 additions & 4 deletions src/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Type.prototype.setup = function setup() {

/**
* Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
* @param {Message|Object} message Message instance or plain object
* @param {Message|Object.<string,*>} message Message instance or plain object
* @param {Writer} [writer] Writer to encode to
* @returns {Writer} writer
*/
Expand All @@ -408,7 +408,7 @@ Type.prototype.encode = function encode_setup(message, writer) {

/**
* Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
* @param {Message|Object} message Message instance or plain object
* @param {Message|Object.<string,*>} message Message instance or plain object
* @param {Writer} [writer] Writer to encode to
* @returns {Writer} writer
*/
Expand Down Expand Up @@ -443,7 +443,7 @@ Type.prototype.decodeDelimited = function decodeDelimited(reader) {

/**
* Verifies that field values are valid and that required fields are present.
* @param {Message|Object} message Message to verify
* @param {Object.<string,*>} message Plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Type.prototype.verify = function verify_setup(message) {
Expand All @@ -452,7 +452,7 @@ Type.prototype.verify = function verify_setup(message) {

/**
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
* @param {Object.<string,*>} object Plain object
* @param {Object.<string,*>} object Plain object to convert
* @returns {Message} Message instance
*/
Type.prototype.fromObject = function fromObject(object) {
Expand Down
12 changes: 6 additions & 6 deletions tests/data/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $root.Test1 = (function() {

/**
* Encodes the specified Test1 message. Does not implicitly {@link Test1.verify|verify} messages.
* @param {Test1|Object} message Test1 message or plain object to encode
* @param {Test1|Object.<string,*>} message Test1 message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand All @@ -77,7 +77,7 @@ $root.Test1 = (function() {

/**
* Encodes the specified Test1 message, length delimited. Does not implicitly {@link Test1.verify|verify} messages.
* @param {Test1|Object} message Test1 message or plain object to encode
* @param {Test1|Object.<string,*>} message Test1 message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ $root.Test1 = (function() {

/**
* Verifies a Test1 message.
* @param {Test1|Object} message Test1 message or plain object to verify
* @param {Object.<string,*>} message Test1 object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Test1.verify = function verify(message) {
Expand Down Expand Up @@ -246,7 +246,7 @@ $root.Test2 = (function() {

/**
* Encodes the specified Test2 message. Does not implicitly {@link Test2.verify|verify} messages.
* @param {Test2|Object} message Test2 message or plain object to encode
* @param {Test2|Object.<string,*>} message Test2 message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand All @@ -258,7 +258,7 @@ $root.Test2 = (function() {

/**
* Encodes the specified Test2 message, length delimited. Does not implicitly {@link Test2.verify|verify} messages.
* @param {Test2|Object} message Test2 message or plain object to encode
* @param {Test2|Object.<string,*>} message Test2 message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -304,7 +304,7 @@ $root.Test2 = (function() {

/**
* Verifies a Test2 message.
* @param {Test2|Object} message Test2 message or plain object to verify
* @param {Object.<string,*>} message Test2 object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Test2.verify = function verify(message) {
Expand Down
6 changes: 3 additions & 3 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $root.Message = (function() {

/**
* Encodes the specified Message message. Does not implicitly {@link Message.verify|verify} messages.
* @param {Message|Object} message Message message or plain object to encode
* @param {Message|Object.<string,*>} message Message message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -138,7 +138,7 @@ $root.Message = (function() {

/**
* Encodes the specified Message message, length delimited. Does not implicitly {@link Message.verify|verify} messages.
* @param {Message|Object} message Message message or plain object to encode
* @param {Message|Object.<string,*>} message Message message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -234,7 +234,7 @@ $root.Message = (function() {

/**
* Verifies a Message message.
* @param {Message|Object} message Message message or plain object to verify
* @param {Object.<string,*>} message Message object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Message.verify = function verify(message) {
Expand Down
24 changes: 12 additions & 12 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Tile message. Does not implicitly {@link vector_tile.Tile.verify|verify} messages.
* @param {vector_tile.Tile|Object} message Tile message or plain object to encode
* @param {vector_tile.Tile|Object.<string,*>} message Tile message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand All @@ -72,7 +72,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Tile message, length delimited. Does not implicitly {@link vector_tile.Tile.verify|verify} messages.
* @param {vector_tile.Tile|Object} message Tile message or plain object to encode
* @param {vector_tile.Tile|Object.<string,*>} message Tile message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -123,7 +123,7 @@ $root.vector_tile = (function() {

/**
* Verifies a Tile message.
* @param {vector_tile.Tile|Object} message Tile message or plain object to verify
* @param {Object.<string,*>} message Tile object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Tile.verify = function verify(message) {
Expand Down Expand Up @@ -295,7 +295,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Value message. Does not implicitly {@link vector_tile.Tile.Value.verify|verify} messages.
* @param {vector_tile.Tile.Value|Object} message Value message or plain object to encode
* @param {vector_tile.Tile.Value|Object.<string,*>} message Value message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand All @@ -321,7 +321,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Value message, length delimited. Does not implicitly {@link vector_tile.Tile.Value.verify|verify} messages.
* @param {vector_tile.Tile.Value|Object} message Value message or plain object to encode
* @param {vector_tile.Tile.Value|Object.<string,*>} message Value message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -388,7 +388,7 @@ $root.vector_tile = (function() {

/**
* Verifies a Value message.
* @param {vector_tile.Tile.Value|Object} message Value message or plain object to verify
* @param {Object.<string,*>} message Value object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Value.verify = function verify(message) {
Expand Down Expand Up @@ -605,7 +605,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Feature message. Does not implicitly {@link vector_tile.Tile.Feature.verify|verify} messages.
* @param {vector_tile.Tile.Feature|Object} message Feature message or plain object to encode
* @param {vector_tile.Tile.Feature|Object.<string,*>} message Feature message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -633,7 +633,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Feature message, length delimited. Does not implicitly {@link vector_tile.Tile.Feature.verify|verify} messages.
* @param {vector_tile.Tile.Feature|Object} message Feature message or plain object to encode
* @param {vector_tile.Tile.Feature|Object.<string,*>} message Feature message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -705,7 +705,7 @@ $root.vector_tile = (function() {

/**
* Verifies a Feature message.
* @param {vector_tile.Tile.Feature|Object} message Feature message or plain object to verify
* @param {Object.<string,*>} message Feature object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Feature.verify = function verify(message) {
Expand Down Expand Up @@ -932,7 +932,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Layer message. Does not implicitly {@link vector_tile.Tile.Layer.verify|verify} messages.
* @param {vector_tile.Tile.Layer|Object} message Layer message or plain object to encode
* @param {vector_tile.Tile.Layer|Object.<string,*>} message Layer message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand All @@ -957,7 +957,7 @@ $root.vector_tile = (function() {

/**
* Encodes the specified Layer message, length delimited. Does not implicitly {@link vector_tile.Tile.Layer.verify|verify} messages.
* @param {vector_tile.Tile.Layer|Object} message Layer message or plain object to encode
* @param {vector_tile.Tile.Layer|Object.<string,*>} message Layer message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Expand Down Expand Up @@ -1031,7 +1031,7 @@ $root.vector_tile = (function() {

/**
* Verifies a Layer message.
* @param {vector_tile.Tile.Layer|Object} message Layer message or plain object to verify
* @param {Object.<string,*>} message Layer object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Layer.verify = function verify(message) {
Expand Down
Loading

0 comments on commit 588ffd9

Please sign in to comment.