protobufjs 7.5.4 → 7.5.6
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/dist/light/protobuf.js +238 -110
- 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 +90 -38
- 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 +242 -113
- 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/index.d.ts +4 -0
- package/ext/descriptor/index.js +35 -16
- package/index.d.ts +22 -4
- package/package.json +7 -4
- package/src/converter.js +14 -5
- package/src/decoder.js +17 -9
- package/src/enum.js +4 -1
- package/src/message.js +7 -3
- package/src/namespace.js +10 -6
- package/src/object.js +4 -0
- package/src/parse.js +4 -3
- package/src/reader.js +12 -2
- package/src/service.js +8 -4
- package/src/type.js +23 -12
- package/src/types.js +1 -1
- package/src/util/minimal.js +24 -1
- package/src/util/patterns.js +8 -0
- package/src/util.js +9 -9
- package/src/verifier.js +7 -4
- package/src/wrappers.js +4 -3
package/src/type.js
CHANGED
|
@@ -29,6 +29,7 @@ var Enum = require("./enum"),
|
|
|
29
29
|
* @param {Object.<string,*>} [options] Declared options
|
|
30
30
|
*/
|
|
31
31
|
function Type(name, options) {
|
|
32
|
+
name = name.replace(/\W/g, "");
|
|
32
33
|
Namespace.call(this, name, options);
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -204,7 +205,7 @@ Type.generateConstructor = function generateConstructor(mtype) {
|
|
|
204
205
|
else if (field.repeated) gen
|
|
205
206
|
("this%s=[]", util.safeProp(field.name));
|
|
206
207
|
return gen
|
|
207
|
-
("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null
|
|
208
|
+
("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null&&ks[i]!==\"__proto__\")") // omit undefined or null
|
|
208
209
|
("this[ks[i]]=p[ks[i]]");
|
|
209
210
|
/* eslint-enable no-unexpected-multiline */
|
|
210
211
|
};
|
|
@@ -337,10 +338,13 @@ Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(ed
|
|
|
337
338
|
* @override
|
|
338
339
|
*/
|
|
339
340
|
Type.prototype.get = function get(name) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
341
|
+
if (Object.prototype.hasOwnProperty.call(this.fields, name))
|
|
342
|
+
return this.fields[name];
|
|
343
|
+
if (this.oneofs && Object.prototype.hasOwnProperty.call(this.oneofs, name))
|
|
344
|
+
return this.oneofs[name];
|
|
345
|
+
if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name))
|
|
346
|
+
return this.nested[name];
|
|
347
|
+
return null;
|
|
344
348
|
};
|
|
345
349
|
|
|
346
350
|
/**
|
|
@@ -351,7 +355,6 @@ Type.prototype.get = function get(name) {
|
|
|
351
355
|
* @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
|
|
352
356
|
*/
|
|
353
357
|
Type.prototype.add = function add(object) {
|
|
354
|
-
|
|
355
358
|
if (this.get(object.name))
|
|
356
359
|
throw Error("duplicate name '" + object.name + "' in " + this);
|
|
357
360
|
|
|
@@ -367,6 +370,8 @@ Type.prototype.add = function add(object) {
|
|
|
367
370
|
throw Error("id " + object.id + " is reserved in " + this);
|
|
368
371
|
if (this.isReservedName(object.name))
|
|
369
372
|
throw Error("name '" + object.name + "' is reserved in " + this);
|
|
373
|
+
if (object.name === "__proto__")
|
|
374
|
+
return this;
|
|
370
375
|
|
|
371
376
|
if (object.parent)
|
|
372
377
|
object.parent.remove(object);
|
|
@@ -376,6 +381,8 @@ Type.prototype.add = function add(object) {
|
|
|
376
381
|
return clearCache(this);
|
|
377
382
|
}
|
|
378
383
|
if (object instanceof OneOf) {
|
|
384
|
+
if (object.name === "__proto__")
|
|
385
|
+
return this;
|
|
379
386
|
if (!this.oneofs)
|
|
380
387
|
this.oneofs = {};
|
|
381
388
|
this.oneofs[object.name] = object;
|
|
@@ -524,12 +531,14 @@ Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
|
|
|
524
531
|
* Decodes a message of this type.
|
|
525
532
|
* @param {Reader|Uint8Array} reader Reader or buffer to decode from
|
|
526
533
|
* @param {number} [length] Length of the message, if known beforehand
|
|
534
|
+
* @param {number} [end] Expected group end tag, if decoding a group
|
|
535
|
+
* @param {number} [depth] Current nesting depth
|
|
527
536
|
* @returns {Message<{}>} Decoded message
|
|
528
537
|
* @throws {Error} If the payload is not a reader or valid buffer
|
|
529
538
|
* @throws {util.ProtocolError<{}>} If required fields are missing
|
|
530
539
|
*/
|
|
531
|
-
Type.prototype.decode = function decode_setup(reader, length) {
|
|
532
|
-
return this.setup().decode(reader, length); // overrides this method
|
|
540
|
+
Type.prototype.decode = function decode_setup(reader, length, end, depth) {
|
|
541
|
+
return this.setup().decode(reader, length, end, depth); // overrides this method
|
|
533
542
|
};
|
|
534
543
|
|
|
535
544
|
/**
|
|
@@ -548,19 +557,21 @@ Type.prototype.decodeDelimited = function decodeDelimited(reader) {
|
|
|
548
557
|
/**
|
|
549
558
|
* Verifies that field values are valid and that required fields are present.
|
|
550
559
|
* @param {Object.<string,*>} message Plain object to verify
|
|
560
|
+
* @param {number} [depth] Current nesting depth
|
|
551
561
|
* @returns {null|string} `null` if valid, otherwise the reason why it is not
|
|
552
562
|
*/
|
|
553
|
-
Type.prototype.verify = function verify_setup(message) {
|
|
554
|
-
return this.setup().verify(message); // overrides this method
|
|
563
|
+
Type.prototype.verify = function verify_setup(message, depth) {
|
|
564
|
+
return this.setup().verify(message, depth); // overrides this method
|
|
555
565
|
};
|
|
556
566
|
|
|
557
567
|
/**
|
|
558
568
|
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
|
559
569
|
* @param {Object.<string,*>} object Plain object to convert
|
|
570
|
+
* @param {number} [depth] Current nesting depth
|
|
560
571
|
* @returns {Message<{}>} Message instance
|
|
561
572
|
*/
|
|
562
|
-
Type.prototype.fromObject = function fromObject(object) {
|
|
563
|
-
return this.setup().fromObject(object);
|
|
573
|
+
Type.prototype.fromObject = function fromObject(object, depth) {
|
|
574
|
+
return this.setup().fromObject(object, depth);
|
|
564
575
|
};
|
|
565
576
|
|
|
566
577
|
/**
|
package/src/types.js
CHANGED
package/src/util/minimal.js
CHANGED
|
@@ -237,12 +237,35 @@ util.longFromHash = function longFromHash(hash, unsigned) {
|
|
|
237
237
|
function merge(dst, src, ifNotSet) { // used by converters
|
|
238
238
|
for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
|
|
239
239
|
if (dst[keys[i]] === undefined || !ifNotSet)
|
|
240
|
-
|
|
240
|
+
if (keys[i] !== "__proto__")
|
|
241
|
+
dst[keys[i]] = src[keys[i]];
|
|
241
242
|
return dst;
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
util.merge = merge;
|
|
245
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Recursion limit.
|
|
249
|
+
* @memberof util
|
|
250
|
+
* @type {number}
|
|
251
|
+
*/
|
|
252
|
+
util.recursionLimit = 100;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Makes a property safe for assignment as an own property.
|
|
256
|
+
* @memberof util
|
|
257
|
+
* @param {Object.<string,*>} obj Object
|
|
258
|
+
* @param {string} key Property key
|
|
259
|
+
* @returns {undefined}
|
|
260
|
+
*/
|
|
261
|
+
util.makeProp = function makeProp(obj, key) {
|
|
262
|
+
Object.defineProperty(obj, key, {
|
|
263
|
+
enumerable: true,
|
|
264
|
+
configurable: true,
|
|
265
|
+
writable: true
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
|
|
246
269
|
/**
|
|
247
270
|
* Converts the first character of a string to lower case.
|
|
248
271
|
* @param {string} str String to convert
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var patterns = exports;
|
|
4
|
+
|
|
5
|
+
patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
6
|
+
patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
|
|
7
|
+
patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
|
|
8
|
+
patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
|
package/src/util.js
CHANGED
|
@@ -14,6 +14,10 @@ var Type, // cyclic
|
|
|
14
14
|
util.codegen = require("@protobufjs/codegen");
|
|
15
15
|
util.fetch = require("@protobufjs/fetch");
|
|
16
16
|
util.path = require("@protobufjs/path");
|
|
17
|
+
util.patterns = require("./util/patterns");
|
|
18
|
+
|
|
19
|
+
var reservedRe = util.patterns.reservedRe,
|
|
20
|
+
unsafePropertyRe = util.patterns.unsafePropertyRe;
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Node's fs module if available.
|
|
@@ -55,16 +59,13 @@ util.toObject = function toObject(array) {
|
|
|
55
59
|
return object;
|
|
56
60
|
};
|
|
57
61
|
|
|
58
|
-
var safePropBackslashRe = /\\/g,
|
|
59
|
-
safePropQuoteRe = /"/g;
|
|
60
|
-
|
|
61
62
|
/**
|
|
62
63
|
* Tests whether the specified name is a reserved word in JS.
|
|
63
64
|
* @param {string} name Name to test
|
|
64
65
|
* @returns {boolean} `true` if reserved, otherwise `false`
|
|
65
66
|
*/
|
|
66
67
|
util.isReserved = function isReserved(name) {
|
|
67
|
-
return
|
|
68
|
+
return reservedRe.test(name);
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
/**
|
|
@@ -73,8 +74,8 @@ util.isReserved = function isReserved(name) {
|
|
|
73
74
|
* @returns {string} Safe accessor
|
|
74
75
|
*/
|
|
75
76
|
util.safeProp = function safeProp(prop) {
|
|
76
|
-
if (!/^[$\w_]+$/.test(prop) ||
|
|
77
|
-
return "[
|
|
77
|
+
if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
|
|
78
|
+
return "[" + JSON.stringify(prop) + "]";
|
|
78
79
|
return "." + prop;
|
|
79
80
|
};
|
|
80
81
|
|
|
@@ -177,9 +178,8 @@ util.decorateEnum = function decorateEnum(object) {
|
|
|
177
178
|
util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
178
179
|
function setProp(dst, path, value) {
|
|
179
180
|
var part = path.shift();
|
|
180
|
-
if (part
|
|
181
|
-
|
|
182
|
-
}
|
|
181
|
+
if (unsafePropertyRe.test(part))
|
|
182
|
+
return dst;
|
|
183
183
|
if (path.length > 0) {
|
|
184
184
|
dst[part] = setProp(dst[part] || {}, path, value);
|
|
185
185
|
} else {
|
package/src/verifier.js
CHANGED
|
@@ -32,7 +32,7 @@ function genVerifyValue(gen, field, fieldIndex, ref) {
|
|
|
32
32
|
} else {
|
|
33
33
|
gen
|
|
34
34
|
("{")
|
|
35
|
-
("var e=types[%i].verify(%s);", fieldIndex, ref)
|
|
35
|
+
("var e=types[%i].verify(%s,n+1);", fieldIndex, ref)
|
|
36
36
|
("if(e)")
|
|
37
37
|
("return%j+e", field.name + ".")
|
|
38
38
|
("}");
|
|
@@ -122,9 +122,12 @@ function genVerifyKey(gen, field, ref) {
|
|
|
122
122
|
function verifier(mtype) {
|
|
123
123
|
/* eslint-disable no-unexpected-multiline */
|
|
124
124
|
|
|
125
|
-
var gen = util.codegen(["m"], mtype.name + "$verify")
|
|
125
|
+
var gen = util.codegen(["m", "n"], mtype.name + "$verify")
|
|
126
126
|
("if(typeof m!==\"object\"||m===null)")
|
|
127
|
-
("return%j", "object expected")
|
|
127
|
+
("return%j", "object expected")
|
|
128
|
+
("if(n===undefined)n=0")
|
|
129
|
+
("if(n>util.recursionLimit)")
|
|
130
|
+
("return%j", "maximum nesting depth exceeded");
|
|
128
131
|
var oneofs = mtype.oneofsArray,
|
|
129
132
|
seenFirstField = {};
|
|
130
133
|
if (oneofs.length) gen
|
|
@@ -174,4 +177,4 @@ function verifier(mtype) {
|
|
|
174
177
|
return gen
|
|
175
178
|
("return null");
|
|
176
179
|
/* eslint-enable no-unexpected-multiline */
|
|
177
|
-
}
|
|
180
|
+
}
|
package/src/wrappers.js
CHANGED
|
@@ -38,7 +38,7 @@ var Message = require("./message");
|
|
|
38
38
|
// Custom wrapper for Any
|
|
39
39
|
wrappers[".google.protobuf.Any"] = {
|
|
40
40
|
|
|
41
|
-
fromObject: function(object) {
|
|
41
|
+
fromObject: function(object, depth) {
|
|
42
42
|
|
|
43
43
|
// unwrap value type if mapped
|
|
44
44
|
if (object && object["@type"]) {
|
|
@@ -54,14 +54,15 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
54
54
|
if (type_url.indexOf("/") === -1) {
|
|
55
55
|
type_url = "/" + type_url;
|
|
56
56
|
}
|
|
57
|
+
var nextDepth = depth === undefined ? 1 : depth + 1;
|
|
57
58
|
return this.create({
|
|
58
59
|
type_url: type_url,
|
|
59
|
-
value: type.encode(type.fromObject(object)).finish()
|
|
60
|
+
value: type.encode(type.fromObject(object, nextDepth)).finish()
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
return this.fromObject(object);
|
|
65
|
+
return this.fromObject(object, depth);
|
|
65
66
|
},
|
|
66
67
|
|
|
67
68
|
toObject: function(message, options) {
|