protobufjs 8.6.4 → 8.6.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/README.md +8 -8
- package/dist/light/protobuf.js +334 -100
- 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 +51 -6
- 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 +340 -101
- 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 +4 -2
- package/ext/protojson.js +3 -1
- package/ext/textformat.js +26 -6
- package/package.json +2 -2
- package/src/converter.js +27 -19
- package/src/decoder.js +108 -40
- package/src/encoder.js +16 -1
- package/src/enum.js +10 -2
- package/src/field.js +9 -1
- package/src/mapfield.js +9 -1
- package/src/method.js +9 -1
- package/src/namespace.js +9 -1
- package/src/object.js +21 -11
- package/src/oneof.js +9 -1
- package/src/parse.js +6 -1
- package/src/reader_buffer.js +8 -1
- package/src/root.js +9 -1
- package/src/rpc/service.js +8 -1
- package/src/service.js +9 -1
- package/src/type.js +16 -2
- package/src/util/codegen.js +6 -1
- package/src/util/minimal.js +25 -1
- package/src/verifier.js +14 -9
- package/src/wrappers.js +2 -2
- package/src/writer_buffer.js +8 -1
package/src/parse.js
CHANGED
|
@@ -745,6 +745,9 @@ function parse(source, root, options) {
|
|
|
745
745
|
}
|
|
746
746
|
|
|
747
747
|
while (token !== "=") {
|
|
748
|
+
if (token === null) {
|
|
749
|
+
throw illegal(token, "end of input");
|
|
750
|
+
}
|
|
748
751
|
if (token === "(") {
|
|
749
752
|
var parensValue = next();
|
|
750
753
|
skip(")");
|
|
@@ -819,7 +822,9 @@ function parse(source, root, options) {
|
|
|
819
822
|
setOption(parent, name + "." + token, value);
|
|
820
823
|
}
|
|
821
824
|
|
|
822
|
-
var prevValue = objectResult
|
|
825
|
+
var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
|
|
826
|
+
? objectResult[propName]
|
|
827
|
+
: undefined;
|
|
823
828
|
|
|
824
829
|
if (prevValue)
|
|
825
830
|
value = [].concat(prevValue).concat(value);
|
package/src/reader_buffer.js
CHANGED
|
@@ -3,7 +3,14 @@ module.exports = BufferReader;
|
|
|
3
3
|
|
|
4
4
|
// extends Reader
|
|
5
5
|
var Reader = require("./reader");
|
|
6
|
-
|
|
6
|
+
BufferReader.prototype = Object.create(Reader.prototype, {
|
|
7
|
+
constructor: {
|
|
8
|
+
value: BufferReader,
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
7
14
|
|
|
8
15
|
var util = require("./util/minimal");
|
|
9
16
|
|
package/src/root.js
CHANGED
|
@@ -3,7 +3,15 @@ module.exports = Root;
|
|
|
3
3
|
|
|
4
4
|
// extends Namespace
|
|
5
5
|
var Namespace = require("./namespace");
|
|
6
|
-
|
|
6
|
+
Root.prototype = Object.create(Namespace.prototype, {
|
|
7
|
+
constructor: {
|
|
8
|
+
value: Root,
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Root.className = "Root";
|
|
7
15
|
|
|
8
16
|
var Field = require("./field"),
|
|
9
17
|
Enum = require("./enum"),
|
package/src/rpc/service.js
CHANGED
|
@@ -4,7 +4,14 @@ module.exports = Service;
|
|
|
4
4
|
var util = require("../util/minimal");
|
|
5
5
|
|
|
6
6
|
// Extends EventEmitter
|
|
7
|
-
|
|
7
|
+
Service.prototype = Object.create(util.EventEmitter.prototype, {
|
|
8
|
+
constructor: {
|
|
9
|
+
value: Service,
|
|
10
|
+
writable: true,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
configurable: true
|
|
13
|
+
}
|
|
14
|
+
});
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
|
package/src/service.js
CHANGED
|
@@ -3,7 +3,15 @@ module.exports = Service;
|
|
|
3
3
|
|
|
4
4
|
// extends Namespace
|
|
5
5
|
var Namespace = require("./namespace");
|
|
6
|
-
|
|
6
|
+
Service.prototype = Object.create(Namespace.prototype, {
|
|
7
|
+
constructor: {
|
|
8
|
+
value: Service,
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Service.className = "Service";
|
|
7
15
|
|
|
8
16
|
var Method = require("./method"),
|
|
9
17
|
util = require("./util"),
|
package/src/type.js
CHANGED
|
@@ -3,7 +3,15 @@ module.exports = Type;
|
|
|
3
3
|
|
|
4
4
|
// extends Namespace
|
|
5
5
|
var Namespace = require("./namespace");
|
|
6
|
-
|
|
6
|
+
Type.prototype = Object.create(Namespace.prototype, {
|
|
7
|
+
constructor: {
|
|
8
|
+
value: Type,
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Type.className = "Type";
|
|
7
15
|
|
|
8
16
|
var Enum = require("./enum"),
|
|
9
17
|
OneOf = require("./oneof"),
|
|
@@ -168,7 +176,13 @@ Object.defineProperties(Type.prototype, {
|
|
|
168
176
|
// Ensure proper prototype
|
|
169
177
|
var prototype = ctor.prototype;
|
|
170
178
|
if (!(prototype instanceof Message)) {
|
|
171
|
-
|
|
179
|
+
ctor.prototype = new Message();
|
|
180
|
+
Object.defineProperty(ctor.prototype, "constructor", {
|
|
181
|
+
value: ctor,
|
|
182
|
+
writable: true,
|
|
183
|
+
enumerable: false,
|
|
184
|
+
configurable: true
|
|
185
|
+
});
|
|
172
186
|
util.merge(ctor.prototype, prototype);
|
|
173
187
|
}
|
|
174
188
|
|
package/src/util/codegen.js
CHANGED
|
@@ -81,7 +81,12 @@ function codegen(functionParams, functionName) {
|
|
|
81
81
|
return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
Codegen
|
|
84
|
+
Object.defineProperty(Codegen, "toString", {
|
|
85
|
+
value: toString,
|
|
86
|
+
writable: true,
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true
|
|
89
|
+
});
|
|
85
90
|
return Codegen;
|
|
86
91
|
}
|
|
87
92
|
|
package/src/util/minimal.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* global globalThis */
|
|
2
3
|
var util = exports;
|
|
3
4
|
|
|
4
5
|
// used to return a Promise where callback is omitted
|
|
@@ -53,6 +54,7 @@ util.isNode = Boolean(typeof global !== "undefined"
|
|
|
53
54
|
util.global = util.isNode && global
|
|
54
55
|
|| typeof window !== "undefined" && window
|
|
55
56
|
|| typeof self !== "undefined" && self
|
|
57
|
+
|| typeof globalThis !== "undefined" && globalThis
|
|
56
58
|
|| this; // eslint-disable-line no-invalid-this
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -167,6 +169,28 @@ util.newBuffer = function newBuffer(sizeOrArray) {
|
|
|
167
169
|
: new Uint8Array(sizeOrArray);
|
|
168
170
|
};
|
|
169
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Prepends a raw field tag to raw field data.
|
|
174
|
+
* @param {number} id Field id
|
|
175
|
+
* @param {number} wireType Wire type
|
|
176
|
+
* @param {Uint8Array} data Raw field data
|
|
177
|
+
* @returns {Uint8Array|Buffer} Raw field bytes
|
|
178
|
+
* @ignore
|
|
179
|
+
*/
|
|
180
|
+
util.rawField = function rawField(id, wireType, data) {
|
|
181
|
+
var out = [],
|
|
182
|
+
tag = id << 3 | wireType;
|
|
183
|
+
tag >>>= 0;
|
|
184
|
+
while (tag > 127) {
|
|
185
|
+
out.push(tag & 127 | 128);
|
|
186
|
+
tag >>>= 7;
|
|
187
|
+
}
|
|
188
|
+
out.push(tag);
|
|
189
|
+
for (var i = 0; i < data.length; ++i)
|
|
190
|
+
out.push(data[i]);
|
|
191
|
+
return util.newBuffer(out);
|
|
192
|
+
};
|
|
193
|
+
|
|
170
194
|
/**
|
|
171
195
|
* Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
|
|
172
196
|
* @type {Constructor<Uint8Array>}
|
|
@@ -280,7 +304,7 @@ function merge(dst) { // used by converters
|
|
|
280
304
|
if (!src)
|
|
281
305
|
continue;
|
|
282
306
|
for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
|
|
283
|
-
if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined
|
|
307
|
+
if (!isUnsafeProperty(keys[i]) && (!ifNotSet || !Object.prototype.hasOwnProperty.call(dst, keys[i]) || dst[keys[i]] === undefined))
|
|
284
308
|
dst[keys[i]] = src[keys[i]];
|
|
285
309
|
}
|
|
286
310
|
return dst;
|
package/src/verifier.js
CHANGED
|
@@ -19,16 +19,21 @@ function invalid(field, expected) {
|
|
|
19
19
|
*/
|
|
20
20
|
function genVerifyValue(gen, field, fieldIndex, ref) {
|
|
21
21
|
/* eslint-disable no-unexpected-multiline */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
var resolvedType = field.resolvedType;
|
|
23
|
+
if (resolvedType) {
|
|
24
|
+
if (resolvedType instanceof Enum) {
|
|
25
|
+
if (resolvedType._features.enum_type === "CLOSED") { gen
|
|
26
|
+
("switch(%s){", ref)
|
|
27
|
+
("default:")
|
|
28
|
+
("return%j", invalid(field, "enum value"));
|
|
29
|
+
for (var keys = Object.keys(resolvedType.values), j = 0; j < keys.length; ++j) gen
|
|
30
|
+
("case %i:", resolvedType.values[keys[j]]);
|
|
31
|
+
gen
|
|
32
|
+
("break")
|
|
33
|
+
("}");
|
|
34
|
+
} else gen
|
|
35
|
+
("if(typeof %s!==\"number\"||(%s|0)!==%s)", ref, ref, ref)
|
|
26
36
|
("return%j", invalid(field, "enum value"));
|
|
27
|
-
for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
|
|
28
|
-
("case %i:", field.resolvedType.values[keys[j]]);
|
|
29
|
-
gen
|
|
30
|
-
("break")
|
|
31
|
-
("}");
|
|
32
37
|
} else {
|
|
33
38
|
gen
|
|
34
39
|
("{")
|
package/src/wrappers.js
CHANGED
|
@@ -45,7 +45,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
45
45
|
if (object && object["@type"]) {
|
|
46
46
|
// Only use fully qualified type name after the last '/'
|
|
47
47
|
var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
|
|
48
|
-
var type = this.lookup(name);
|
|
48
|
+
var type = this.lookup(name, [ this.constructor ]);
|
|
49
49
|
/* istanbul ignore else */
|
|
50
50
|
if (type) {
|
|
51
51
|
// type_url does not accept leading "."
|
|
@@ -81,7 +81,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
81
81
|
name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
|
|
82
82
|
// Separate the prefix used
|
|
83
83
|
prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
|
|
84
|
-
var type = this.lookup(name);
|
|
84
|
+
var type = this.lookup(name, [ this.constructor ]);
|
|
85
85
|
/* istanbul ignore else */
|
|
86
86
|
if (type)
|
|
87
87
|
message = type.decode(message.value, undefined, undefined, depth + 1);
|
package/src/writer_buffer.js
CHANGED
|
@@ -3,7 +3,14 @@ module.exports = BufferWriter;
|
|
|
3
3
|
|
|
4
4
|
// extends Writer
|
|
5
5
|
var Writer = require("./writer");
|
|
6
|
-
|
|
6
|
+
BufferWriter.prototype = Object.create(Writer.prototype, {
|
|
7
|
+
constructor: {
|
|
8
|
+
value: BufferWriter,
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
7
14
|
|
|
8
15
|
var util = require("./util/minimal");
|
|
9
16
|
|