protobufjs 8.4.1 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/light/protobuf.js +67 -29
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +36 -16
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +75 -34
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor.js +31 -9
- package/index.d.ts +22 -9
- package/package.json +3 -2
- package/src/converter.js +4 -2
- package/src/decoder.js +4 -2
- package/src/method.js +16 -2
- package/src/namespace.js +5 -5
- package/src/parse.js +8 -5
- package/src/reader.js +12 -0
- package/src/roots.js +1 -1
- package/src/rpc/service.js +10 -4
- package/src/writer.js +11 -9
package/README.md
CHANGED
|
@@ -105,9 +105,9 @@ const decoded = AwesomeMessage.decode(encoded);
|
|
|
105
105
|
|
|
106
106
|
`encode` expects a message instance or equivalent plain object and does not verify input implicitly. Use `verify` for plain objects whose shape is not guaranteed, `create` to create a message instance from already valid data when useful, and `fromObject` when conversion from broader JavaScript objects is needed.
|
|
107
107
|
|
|
108
|
-
Plain objects can be encoded directly when they already use protobuf.js runtime types: numbers for 32-bit numeric fields, booleans for `bool`, strings for `string`, `Uint8Array` or `Buffer` for `bytes`, arrays for repeated fields, and plain objects for maps. Map keys are the string representation of the respective value or an 8-character hash string for 64-bit/`Long` keys.
|
|
108
|
+
Plain objects can be encoded directly when they already use protobuf.js runtime types: numbers for 32-bit numeric fields, booleans for `bool`, strings for `string`, `Uint8Array` or `Buffer` for `bytes`, arrays for repeated fields, and plain objects for maps. Map keys are the string representation of the respective value or an 8-character hash string for 64-bit/`Long` keys. When exact 64-bit integer support is required, install [`long`](https://github.com/dcodeIO/long.js) with protobuf.js.
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Unknown fields present on the wire are preserved by default in `message.$unknowns` and forwarded when the message is re-encoded. Unknown field data can be dropped from a decoded message with `delete message.$unknowns`, discarded during decode per reader with `reader.discardUnknown = true`, or disabled by default for subsequently created readers with `Reader.discardUnknown = true`.
|
|
111
111
|
|
|
112
112
|
### Convert plain objects
|
|
113
113
|
|
|
@@ -167,6 +167,8 @@ Message types expose focused methods for validation, conversion, and binary I/O.
|
|
|
167
167
|
* **message#toJSON**(): `object`
|
|
168
168
|
Converts a message instance to JSON-compatible output using default conversion options.
|
|
169
169
|
|
|
170
|
+
Message instances provide runtime identity, so they can be tested with `instanceof`. Their `toJSON` method integrates them with `JSON.stringify`.
|
|
171
|
+
|
|
170
172
|
Length-delimited methods read and write a varint byte length before the message, which is useful for streams and framed protocols.
|
|
171
173
|
|
|
172
174
|
If required fields are missing while decoding proto2 data, `decode` throws `protobuf.util.ProtocolError` with the partially decoded message available as `err.instance`.
|
|
@@ -311,7 +313,23 @@ protobuf.js will populate the constructor with the usual static runtime methods
|
|
|
311
313
|
|
|
312
314
|
### Services
|
|
313
315
|
|
|
314
|
-
protobuf.js supports service clients built from
|
|
316
|
+
protobuf.js supports service clients built from service definitions. The service API is transport-agnostic: provide an `rpcImpl` function to connect it to HTTP, WebSocket, gRPC, or another transport.
|
|
317
|
+
|
|
318
|
+
```js
|
|
319
|
+
function myRpcImpl(method, requestData, callback) {
|
|
320
|
+
// method.name
|
|
321
|
+
// method.path
|
|
322
|
+
// method.requestStream?
|
|
323
|
+
// method.responseStream?
|
|
324
|
+
performRequest(requestData, function(err, responseData) {
|
|
325
|
+
callback(err, responseData);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const myService = MyService.create(myRpcImpl/*, requestDelimited?, responseDelimited? */);
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
See [examples/streaming-rpc.js](./examples/streaming-rpc.js) for a streaming example.
|
|
315
333
|
|
|
316
334
|
### Descriptors
|
|
317
335
|
|
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js v8.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v8.5.0 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled fri, 29 may 2026 22:57:25 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -84,7 +84,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
84
84
|
} gen
|
|
85
85
|
("}");
|
|
86
86
|
} else gen
|
|
87
|
-
("if(
|
|
87
|
+
("if(!util.isObject(d%s))", prop)
|
|
88
88
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
89
89
|
("m%s=types[%i].fromObject(d%s,q+1)", prop, fieldIndex, prop);
|
|
90
90
|
} else {
|
|
@@ -151,6 +151,8 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
151
151
|
var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
|
|
152
152
|
("if(d instanceof C)")
|
|
153
153
|
("return d")
|
|
154
|
+
("if(!util.isObject(d))")
|
|
155
|
+
("throw TypeError(%j)", mtype.fullName + ": object expected")
|
|
154
156
|
("if(q===undefined)q=0")
|
|
155
157
|
("if(q>util.recursionLimit)")
|
|
156
158
|
("throw Error(\"max depth exceeded\")");
|
|
@@ -167,7 +169,7 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
167
169
|
// Map fields
|
|
168
170
|
if (field.map) { gen
|
|
169
171
|
("if(d%s){", prop)
|
|
170
|
-
("if(
|
|
172
|
+
("if(!util.isObject(d%s))", prop)
|
|
171
173
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
172
174
|
("m%s={}", prop)
|
|
173
175
|
("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
|
|
@@ -572,8 +574,10 @@ function decoder(mtype) {
|
|
|
572
574
|
// Unknown fields
|
|
573
575
|
gen
|
|
574
576
|
("r.skipType(%s,q,t)", i ? "u" : "t&7")
|
|
575
|
-
("
|
|
576
|
-
|
|
577
|
+
("if(!r.discardUnknown){")
|
|
578
|
+
("util.makeProp(m,\"$unknowns\",false);")
|
|
579
|
+
("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
|
|
580
|
+
("}")
|
|
577
581
|
("}")
|
|
578
582
|
("if(z!==undefined)")
|
|
579
583
|
("throw Error(\"missing end group\")");
|
|
@@ -1870,7 +1874,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
1870
1874
|
|
|
1871
1875
|
/**
|
|
1872
1876
|
* Whether requests are streamed or not.
|
|
1873
|
-
* @type {
|
|
1877
|
+
* @type {true|undefined}
|
|
1874
1878
|
*/
|
|
1875
1879
|
this.requestStream = requestStream ? true : undefined; // toJSON
|
|
1876
1880
|
|
|
@@ -1882,10 +1886,16 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
1882
1886
|
|
|
1883
1887
|
/**
|
|
1884
1888
|
* Whether responses are streamed or not.
|
|
1885
|
-
* @type {
|
|
1889
|
+
* @type {true|undefined}
|
|
1886
1890
|
*/
|
|
1887
1891
|
this.responseStream = responseStream ? true : undefined; // toJSON
|
|
1888
1892
|
|
|
1893
|
+
/**
|
|
1894
|
+
* gRPC-style method path.
|
|
1895
|
+
* @type {string}
|
|
1896
|
+
*/
|
|
1897
|
+
this.path = "/" + this.name;
|
|
1898
|
+
|
|
1889
1899
|
/**
|
|
1890
1900
|
* Resolved request type.
|
|
1891
1901
|
* @type {Type|null}
|
|
@@ -1963,6 +1973,14 @@ Method.prototype.resolve = function resolve() {
|
|
|
1963
1973
|
if (this.resolved)
|
|
1964
1974
|
return this;
|
|
1965
1975
|
|
|
1976
|
+
if (this.parent) {
|
|
1977
|
+
var serviceName = this.parent.fullName;
|
|
1978
|
+
if (serviceName.charAt(0) === ".")
|
|
1979
|
+
serviceName = serviceName.substring(1);
|
|
1980
|
+
this.path = "/" + serviceName + "/" + this.name;
|
|
1981
|
+
} else
|
|
1982
|
+
this.path = "/" + this.name;
|
|
1983
|
+
|
|
1966
1984
|
this.resolvedRequestType = this.parent.lookupType(this.requestType);
|
|
1967
1985
|
this.resolvedResponseType = this.parent.lookupType(this.responseType);
|
|
1968
1986
|
|
|
@@ -2040,7 +2058,7 @@ Namespace.arrayToJSON = arrayToJSON;
|
|
|
2040
2058
|
Namespace.isReservedId = function isReservedId(reserved, id) {
|
|
2041
2059
|
if (reserved)
|
|
2042
2060
|
for (var i = 0; i < reserved.length; ++i)
|
|
2043
|
-
if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1]
|
|
2061
|
+
if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] >= id)
|
|
2044
2062
|
return true;
|
|
2045
2063
|
return false;
|
|
2046
2064
|
};
|
|
@@ -2398,14 +2416,14 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
|
|
|
2398
2416
|
if (path[0] === "")
|
|
2399
2417
|
return this.root.lookup(path.slice(1), filterTypes);
|
|
2400
2418
|
|
|
2401
|
-
//
|
|
2402
|
-
var found = this.
|
|
2419
|
+
// Lookup at this namespace and below
|
|
2420
|
+
var found = this._lookupImpl(path, flatPath);
|
|
2403
2421
|
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
2404
2422
|
return found;
|
|
2405
2423
|
}
|
|
2406
2424
|
|
|
2407
|
-
//
|
|
2408
|
-
found = this.
|
|
2425
|
+
// Fall back to respective absolute path once relative scope has been checked (non-standard)
|
|
2426
|
+
found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
|
|
2409
2427
|
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
2410
2428
|
return found;
|
|
2411
2429
|
}
|
|
@@ -3188,6 +3206,12 @@ function Reader(buffer) {
|
|
|
3188
3206
|
* @type {number}
|
|
3189
3207
|
*/
|
|
3190
3208
|
this.len = buffer.length;
|
|
3209
|
+
|
|
3210
|
+
/**
|
|
3211
|
+
* Whether to discard unknown fields while decoding.
|
|
3212
|
+
* @type {boolean}
|
|
3213
|
+
*/
|
|
3214
|
+
this.discardUnknown = Reader.discardUnknown;
|
|
3191
3215
|
}
|
|
3192
3216
|
|
|
3193
3217
|
var create_array = typeof Uint8Array !== "undefined"
|
|
@@ -3600,6 +3624,12 @@ Reader.prototype.skip = function skip(length) {
|
|
|
3600
3624
|
*/
|
|
3601
3625
|
Reader.recursionLimit = util.recursionLimit;
|
|
3602
3626
|
|
|
3627
|
+
/**
|
|
3628
|
+
* Whether readers discard unknown fields while decoding.
|
|
3629
|
+
* @type {boolean}
|
|
3630
|
+
*/
|
|
3631
|
+
Reader.discardUnknown = false;
|
|
3632
|
+
|
|
3603
3633
|
/**
|
|
3604
3634
|
* Skips the next element of the specified wire type.
|
|
3605
3635
|
* @param {number} wireType Wire type received
|
|
@@ -4174,7 +4204,7 @@ Root._configure = function(Type_, parse_, common_) {
|
|
|
4174
4204
|
|
|
4175
4205
|
},{"12":12,"14":14,"24":24,"5":5,"6":6}],18:[function(require,module,exports){
|
|
4176
4206
|
"use strict";
|
|
4177
|
-
module.exports =
|
|
4207
|
+
module.exports = Object.create(null);
|
|
4178
4208
|
|
|
4179
4209
|
/**
|
|
4180
4210
|
* Named roots.
|
|
@@ -4256,10 +4286,16 @@ var util = require(34);
|
|
|
4256
4286
|
* @typedef rpc.ServiceMethod
|
|
4257
4287
|
* @template TReq extends Message<TReq>
|
|
4258
4288
|
* @template TRes extends Message<TRes>
|
|
4259
|
-
* @type {
|
|
4260
|
-
*
|
|
4261
|
-
*
|
|
4262
|
-
*
|
|
4289
|
+
* @type {{
|
|
4290
|
+
* (request: TReq|Properties<TReq>, callback: rpc.ServiceMethodCallback<TRes>): void;
|
|
4291
|
+
* (request: TReq|Properties<TReq>): Promise<TRes>;
|
|
4292
|
+
* readonly name: string;
|
|
4293
|
+
* readonly path: string;
|
|
4294
|
+
* readonly requestType: string;
|
|
4295
|
+
* readonly responseType: string;
|
|
4296
|
+
* readonly requestStream: true|undefined;
|
|
4297
|
+
* readonly responseStream: true|undefined;
|
|
4298
|
+
* }}
|
|
4263
4299
|
*/
|
|
4264
4300
|
|
|
4265
4301
|
/**
|
|
@@ -8062,7 +8098,7 @@ Writer.prototype.uint32 = function write_uint32(value) {
|
|
|
8062
8098
|
* @returns {Writer} `this`
|
|
8063
8099
|
*/
|
|
8064
8100
|
Writer.prototype.int32 = function write_int32(value) {
|
|
8065
|
-
return value < 0
|
|
8101
|
+
return (value |= 0) < 0
|
|
8066
8102
|
? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
|
|
8067
8103
|
: this.uint32(value);
|
|
8068
8104
|
};
|
|
@@ -8077,16 +8113,18 @@ Writer.prototype.sint32 = function write_sint32(value) {
|
|
|
8077
8113
|
};
|
|
8078
8114
|
|
|
8079
8115
|
function writeVarint64(val, buf, pos) {
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8116
|
+
var lo = val.lo,
|
|
8117
|
+
hi = val.hi;
|
|
8118
|
+
while (hi) {
|
|
8119
|
+
buf[pos++] = lo & 127 | 128;
|
|
8120
|
+
lo = (lo >>> 7 | hi << 25) >>> 0;
|
|
8121
|
+
hi >>>= 7;
|
|
8122
|
+
}
|
|
8123
|
+
while (lo > 127) {
|
|
8124
|
+
buf[pos++] = lo & 127 | 128;
|
|
8125
|
+
lo = lo >>> 7;
|
|
8126
|
+
}
|
|
8127
|
+
buf[pos++] = lo;
|
|
8090
8128
|
}
|
|
8091
8129
|
|
|
8092
8130
|
/**
|