Skip to content

Commit 588ffd9

Browse files
committed
Other: Use more precise types for message-like plain objects
1 parent 5a1f861 commit 588ffd9

File tree

15 files changed

+405
-415
lines changed

15 files changed

+405
-415
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Note that **Message** refers to any message type below.
101101
```
102102

103103
* **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
104-
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.
104+
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.
105105

106106
```js
107107
var buffer = AwesomeMessage.encode(message).finish();

cli/targets/static.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ function buildType(ref, type) {
394394
push("");
395395
pushComment([
396396
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
397-
"@param {" + fullName + "|Object} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
397+
"@param {" + fullName + "|Object.<string,*>} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
398398
"@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to",
399399
"@returns {$protobuf.Writer} Writer"
400400
]);
@@ -404,7 +404,7 @@ function buildType(ref, type) {
404404
push("");
405405
pushComment([
406406
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
407-
"@param {" + fullName + "|Object} message " + type.name + " message or plain object to encode",
407+
"@param {" + fullName + "|Object.<string,*>} message " + type.name + " message or plain object to encode",
408408
"@param {$protobuf.Writer} [writer] Writer to encode to",
409409
"@returns {$protobuf.Writer} Writer"
410410
]);
@@ -456,11 +456,10 @@ function buildType(ref, type) {
456456
push("");
457457
pushComment([
458458
"Verifies " + aOrAn(type.name) + " message.",
459-
"@param {" + fullName + "|Object} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to verify",
459+
"@param {Object.<string,*>} " + (config.beautify ? "message" : "m") + " " + type.name + " object to verify",
460460
"@returns {?string} `null` if valid, otherwise the reason why it is not"
461461
]);
462462
buildFunction(type, "verify", protobuf.verifier(type));
463-
464463
}
465464

466465
if (config.convert) {
@@ -570,7 +569,7 @@ function buildService(ref, service) {
570569
push("");
571570
pushComment([
572571
method.comment || "Calls " + method.name + ".",
573-
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " message or plain object",
572+
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object.<string,*>} request " + method.resolvedRequestType.name + " message or plain object",
574573
"@param {" + cbName + "} callback Node-style callback called with the error, if any, and " + method.resolvedResponseType.name,
575574
"@returns {undefined}"
576575
]);
@@ -585,7 +584,7 @@ function buildService(ref, service) {
585584
method.comment || "Calls " + method.name + ".",
586585
"@name " + name(service.name) + "#" + lcName,
587586
"@function",
588-
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " message or plain object",
587+
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object.<string,*>} request " + method.resolvedRequestType.name + " message or plain object",
589588
"@returns {Promise<"+method.resolvedResponseType.fullName.substring(1)+">} Promise",
590589
"@variation 2"
591590
]);

src/class.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Class.prototype = Message;
136136
* Encodes a message of this type.
137137
* @name Class#encode
138138
* @function
139-
* @param {Message|Object} message Message to encode
139+
* @param {Message|Object.<string,*>} message Message to encode
140140
* @param {Writer} [writer] Writer to use
141141
* @returns {Writer} Writer
142142
*/
@@ -145,7 +145,7 @@ Class.prototype = Message;
145145
* Encodes a message of this type preceeded by its length as a varint.
146146
* @name Class#encodeDelimited
147147
* @function
148-
* @param {Message|Object} message Message to encode
148+
* @param {Message|Object.<string,*>} message Message to encode
149149
* @param {Writer} [writer] Writer to use
150150
* @returns {Writer} Writer
151151
*/
@@ -170,6 +170,6 @@ Class.prototype = Message;
170170
* Verifies a message of this type.
171171
* @name Class#verify
172172
* @function
173-
* @param {Message|Object} message Message or plain object to verify
173+
* @param {Message|Object.<string,*>} message Message or plain object to verify
174174
* @returns {?string} `null` if valid, otherwise the reason why it is not
175175
*/

src/message.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Message(properties) {
3434

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

4545
/**
4646
* Encodes a message of this type preceeded by its length as a varint.
47-
* @param {Message|Object} message Message to encode
47+
* @param {Message|Object.<string,*>} message Message to encode
4848
* @param {Writer} [writer] Writer to use
4949
* @returns {Writer} Writer
5050
*/
@@ -78,7 +78,7 @@ Message.decodeDelimited = function decodeDelimited(reader) {
7878
* Verifies a message of this type.
7979
* @name Message.verify
8080
* @function
81-
* @param {Message|Object} message Message or plain object to verify
81+
* @param {Message|Object.<string,*>} message Message or plain object to verify
8282
* @returns {?string} `null` if valid, otherwise the reason why it is not
8383
*/
8484
Message.verify = function verify(message) {

src/oneof.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Field = require("./field");
1313
* @extends ReflectionObject
1414
* @constructor
1515
* @param {string} name Oneof name
16-
* @param {string[]|Object} [fieldNames] Field names
16+
* @param {string[]|Object.<string,*>} [fieldNames] Field names
1717
* @param {Object.<string,*>} [options] Declared options
1818
*/
1919
function OneOf(name, fieldNames, options) {

src/rpc/service.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var util = require("../util/minimal");
2121
* A service method part of a {@link rpc.ServiceMethodMixin|ServiceMethodMixin} and thus {@link rpc.Service} as created by {@link Service.create}.
2222
* @typedef rpc.ServiceMethod
2323
* @type {function}
24-
* @param {Message|Object} request Request message or plain object
24+
* @param {Message|Object.<string,*>} request Request message or plain object
2525
* @param {rpc.ServiceMethodCallback} [callback] Node-style callback called with the error, if any, and the response message
2626
* @returns {Promise<Message>} Promise if `callback` has been omitted, otherwise `undefined`
2727
*/
@@ -79,7 +79,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
7979
* @param {Method|rpc.ServiceMethod} method Reflected or static method
8080
* @param {function} requestCtor Request constructor
8181
* @param {function} responseCtor Response constructor
82-
* @param {Message|Object} request Request message or plain object
82+
* @param {Message|Object.<string,*>} request Request message or plain object
8383
* @param {rpc.ServiceMethodCallback} callback Service callback
8484
* @returns {undefined}
8585
*/

src/type.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ Type.prototype.setup = function setup() {
398398

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

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

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

453453
/**
454454
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
455-
* @param {Object.<string,*>} object Plain object
455+
* @param {Object.<string,*>} object Plain object to convert
456456
* @returns {Message} Message instance
457457
*/
458458
Type.prototype.fromObject = function fromObject(object) {

tests/data/comments.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $root.Test1 = (function() {
5959

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

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

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

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

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

305305
/**
306306
* Verifies a Test2 message.
307-
* @param {Test2|Object} message Test2 message or plain object to verify
307+
* @param {Object.<string,*>} message Test2 object to verify
308308
* @returns {?string} `null` if valid, otherwise the reason why it is not
309309
*/
310310
Test2.verify = function verify(message) {

tests/data/convert.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $root.Message = (function() {
9797

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

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

235235
/**
236236
* Verifies a Message message.
237-
* @param {Message|Object} message Message message or plain object to verify
237+
* @param {Object.<string,*>} message Message object to verify
238238
* @returns {?string} `null` if valid, otherwise the reason why it is not
239239
*/
240240
Message.verify = function verify(message) {

tests/data/mapbox/vector_tile.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $root.vector_tile = (function() {
5757

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

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

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

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

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

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

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

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

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

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

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

10321032
/**
10331033
* Verifies a Layer message.
1034-
* @param {vector_tile.Tile.Layer|Object} message Layer message or plain object to verify
1034+
* @param {Object.<string,*>} message Layer object to verify
10351035
* @returns {?string} `null` if valid, otherwise the reason why it is not
10361036
*/
10371037
Layer.verify = function verify(message) {

0 commit comments

Comments
 (0)