protobufjs 8.2.1 → 8.4.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 +61 -23
- package/dist/light/protobuf.js +28 -18
- 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 +3 -3
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +2 -2
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +28 -18
- 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.d.ts +11 -234
- package/ext/descriptor.generated.d.ts +409 -0
- package/ext/descriptor.js +89 -64
- package/ext/textformat.d.ts +2 -7
- package/ext/textformat.generated.d.ts +11 -0
- package/ext/textformat.js +11 -3
- package/index.d.ts +302 -268
- package/package.json +5 -5
- package/src/converter.js +5 -3
- package/src/enum.js +8 -3
- package/src/field.js +2 -0
- package/src/message.js +3 -6
- package/src/method.js +1 -1
- package/src/object.js +0 -1
- package/src/oneof.js +1 -0
- package/src/service.js +2 -0
- package/src/type.js +3 -1
- package/src/typescript.js +19 -0
- package/src/util/pool.js +1 -1
- package/tsconfig.json +2 -4
- package/src/typescript.jsdoc +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript & TypeScript.",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"bench": "node bench",
|
|
27
27
|
"build": "npm run build:bundle && npm run build:types",
|
|
28
28
|
"build:bundle": "gulp --gulpfile scripts/gulpfile.js",
|
|
29
|
-
"build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/",
|
|
29
|
+
"build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ && node cli/bin/pbts --main --import \"\\$protobuf=..\" --out ext/descriptor.generated.d.ts ext/descriptor.js && node cli/bin/pbts --main --out ext/textformat.generated.d.ts ext/textformat.js",
|
|
30
30
|
"coverage": "npm run coverage:test && npm run coverage:report",
|
|
31
31
|
"coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
32
32
|
"coverage:report": "nyc report --reporter=lcov --reporter=text",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"prof": "node bench/prof",
|
|
43
43
|
"test": "npm run test:sources && npm run test:types",
|
|
44
44
|
"test:sources": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
45
|
-
"test:types": "tsc tests/comp_typescript.ts --
|
|
45
|
+
"test:types": "tsc tests/comp_typescript.ts --target es2019 --module commonjs --types node --lib es2019 --esModuleInterop --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc -p tsconfig.test-types.json",
|
|
46
46
|
"make": "npm run lint:sources && npm run build && npm run lint:types && node ./scripts/gentests.js && npm test"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"long": "^5.0.0"
|
|
49
|
+
"long": "^5.3.2"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@eslint/js": "^10.0.0",
|
|
53
|
+
"@types/node": ">=13.7.0",
|
|
54
54
|
"browserify": "^17.0.0",
|
|
55
55
|
"browserify-wrap": "^1.0.2",
|
|
56
56
|
"bundle-collapser": "^1.3.0",
|
package/src/converter.js
CHANGED
|
@@ -209,7 +209,9 @@ function genValuePartial_toObject(gen, field, fieldIndex, dstProp, srcProp) {
|
|
|
209
209
|
case "sint64":
|
|
210
210
|
case "fixed64":
|
|
211
211
|
case "sfixed64": gen
|
|
212
|
-
("if(typeof
|
|
212
|
+
("if(typeof BigInt!==\"undefined\"&&o.longs===BigInt)")
|
|
213
|
+
("d%s=typeof m%s===\"number\"?BigInt(m%s):util.Long.fromBits(m%s.low>>>0,m%s.high>>>0,%j).toBigInt()", dstProp, srcProp, srcProp, srcProp, srcProp, isUnsigned)
|
|
214
|
+
("else if(typeof m%s===\"number\")", srcProp)
|
|
213
215
|
("d%s=o.longs===String?String(m%s):m%s", dstProp, srcProp, srcProp)
|
|
214
216
|
("else") // Long-like
|
|
215
217
|
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", dstProp, srcProp, srcProp, srcProp, isUnsigned ? "true": "", srcProp);
|
|
@@ -277,9 +279,9 @@ converter.toObject = function toObject(mtype) {
|
|
|
277
279
|
else if (field.long) gen
|
|
278
280
|
("if(util.Long){")
|
|
279
281
|
("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
|
|
280
|
-
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
|
|
282
|
+
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():typeof BigInt!==\"undefined\"&&o.longs===BigInt?n.toBigInt():n", prop)
|
|
281
283
|
("}else")
|
|
282
|
-
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
|
|
284
|
+
("d%s=o.longs===String?%j:typeof BigInt!==\"undefined\"&&o.longs===BigInt?BigInt(%j):%i", prop, field.typeDefault.toString(), field.typeDefault.toString(), field.typeDefault.toNumber());
|
|
283
285
|
else if (field.bytes) {
|
|
284
286
|
var arrayDefault = Array.prototype.slice.call(field.typeDefault);
|
|
285
287
|
gen
|
package/src/enum.js
CHANGED
|
@@ -17,7 +17,7 @@ var Namespace = require("./namespace"),
|
|
|
17
17
|
* @param {Object.<string,number>} [values] Enum values as an object, by name
|
|
18
18
|
* @param {Object.<string,*>} [options] Declared options
|
|
19
19
|
* @param {string} [comment] The comment for this enum
|
|
20
|
-
* @param {Object.<string,string>} [comments] The value comments for this enum
|
|
20
|
+
* @param {Object.<string,string|null>} [comments] The value comments for this enum
|
|
21
21
|
* @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
|
|
22
22
|
*/
|
|
23
23
|
function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
@@ -46,7 +46,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Value comment texts, if any.
|
|
49
|
-
* @type {Object.<string,string>}
|
|
49
|
+
* @type {Object.<string,string|null>}
|
|
50
50
|
*/
|
|
51
51
|
this.comments = comments || {};
|
|
52
52
|
|
|
@@ -96,8 +96,13 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
96
96
|
/**
|
|
97
97
|
* Enum descriptor.
|
|
98
98
|
* @interface IEnum
|
|
99
|
+
* @property {string} [edition] Edition
|
|
99
100
|
* @property {Object.<string,number>} values Enum values
|
|
100
101
|
* @property {Object.<string,*>} [options] Enum options
|
|
102
|
+
* @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
|
|
103
|
+
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
104
|
+
* @property {string|null} [comment] Enum comment
|
|
105
|
+
* @property {Object.<string,string|null>} [comments] Value comments
|
|
101
106
|
*/
|
|
102
107
|
|
|
103
108
|
/**
|
|
@@ -108,7 +113,7 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
108
113
|
* @throws {TypeError} If arguments are invalid
|
|
109
114
|
*/
|
|
110
115
|
Enum.fromJSON = function fromJSON(name, json) {
|
|
111
|
-
var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
|
|
116
|
+
var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
|
|
112
117
|
enm.reserved = json.reserved;
|
|
113
118
|
if (json.edition)
|
|
114
119
|
enm._edition = json.edition;
|
package/src/field.js
CHANGED
|
@@ -259,10 +259,12 @@ Field.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
|
259
259
|
/**
|
|
260
260
|
* Field descriptor.
|
|
261
261
|
* @interface IField
|
|
262
|
+
* @property {string} [edition] Edition
|
|
262
263
|
* @property {string} [rule="optional"] Field rule
|
|
263
264
|
* @property {string} type Field type
|
|
264
265
|
* @property {number} id Field id
|
|
265
266
|
* @property {Object.<string,*>} [options] Field options
|
|
267
|
+
* @property {string|null} [comment] Field comment
|
|
266
268
|
*/
|
|
267
269
|
|
|
268
270
|
/**
|
package/src/message.js
CHANGED
|
@@ -14,12 +14,9 @@ var util = require("./util/minimal");
|
|
|
14
14
|
function Message(properties) {
|
|
15
15
|
// not used internally
|
|
16
16
|
if (properties)
|
|
17
|
-
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
continue;
|
|
21
|
-
this[key] = properties[key];
|
|
22
|
-
}
|
|
17
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
18
|
+
if (properties[keys[i]] != null && keys[i] !== "__proto__")
|
|
19
|
+
this[keys[i]] = properties[keys[i]];
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
/**
|
package/src/method.js
CHANGED
|
@@ -111,7 +111,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
111
111
|
* @property {boolean} [requestStream=false] Whether requests are streamed
|
|
112
112
|
* @property {boolean} [responseStream=false] Whether responses are streamed
|
|
113
113
|
* @property {Object.<string,*>} [options] Method options
|
|
114
|
-
* @property {string} comment Method
|
|
114
|
+
* @property {string|null} [comment] Method comment
|
|
115
115
|
* @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
|
|
116
116
|
*/
|
|
117
117
|
|
package/src/object.js
CHANGED
|
@@ -142,7 +142,6 @@ Object.defineProperties(ReflectionObject.prototype, {
|
|
|
142
142
|
/**
|
|
143
143
|
* Converts this reflection object to its descriptor representation.
|
|
144
144
|
* @returns {Object.<string,*>} Descriptor
|
|
145
|
-
* @abstract
|
|
146
145
|
*/
|
|
147
146
|
ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
|
|
148
147
|
throw Error(); // not implemented, shouldn't happen
|
package/src/oneof.js
CHANGED
package/src/service.js
CHANGED
|
@@ -41,7 +41,9 @@ function Service(name, options) {
|
|
|
41
41
|
* Service descriptor.
|
|
42
42
|
* @interface IService
|
|
43
43
|
* @extends INamespace
|
|
44
|
+
* @property {string} [edition] Edition
|
|
44
45
|
* @property {Object.<string,IMethod>} methods Method descriptors
|
|
46
|
+
* @property {string|null} [comment] Service comment
|
|
45
47
|
*/
|
|
46
48
|
|
|
47
49
|
/**
|
package/src/type.js
CHANGED
|
@@ -226,11 +226,13 @@ function clearCache(type) {
|
|
|
226
226
|
* Message type descriptor.
|
|
227
227
|
* @interface IType
|
|
228
228
|
* @extends INamespace
|
|
229
|
+
* @property {string} [edition] Edition
|
|
229
230
|
* @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
|
|
230
231
|
* @property {Object.<string,IField>} fields Field descriptors
|
|
231
232
|
* @property {number[][]} [extensions] Extension ranges
|
|
232
233
|
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
233
234
|
* @property {boolean} [group=false] Whether a legacy group or not
|
|
235
|
+
* @property {string|null} [comment] Message type comment
|
|
234
236
|
*/
|
|
235
237
|
|
|
236
238
|
/**
|
|
@@ -583,7 +585,7 @@ Type.prototype.fromObject = function fromObject(object) { // eslint-disable-line
|
|
|
583
585
|
* Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
|
|
584
586
|
* @interface IConversionOptions
|
|
585
587
|
* @property {Function} [longs] Long conversion type.
|
|
586
|
-
* Valid values are `String` and `Number` (the global types).
|
|
588
|
+
* Valid values are `BigInt`, `String` and `Number` (the global types).
|
|
587
589
|
* Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
|
|
588
590
|
* @property {Function} [enums] Enum value conversion type.
|
|
589
591
|
* Only valid value is `String` (the global type).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
|
|
4
|
+
// Global TypeScript helper typedefs. The unused vars anchor these typedefs so
|
|
5
|
+
// both TypeScript checkJs and pbts can discover them from this script file.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constructor type.
|
|
9
|
+
* @template T
|
|
10
|
+
* @typedef {Function & { new(...params: any[]): T; prototype: T }} Constructor
|
|
11
|
+
*/
|
|
12
|
+
var Constructor;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Properties type.
|
|
16
|
+
* @template T
|
|
17
|
+
* @typedef {{ [P in keyof T]?: T[P] }} Properties
|
|
18
|
+
*/
|
|
19
|
+
var Properties;
|
package/src/util/pool.js
CHANGED
package/tsconfig.json
CHANGED
package/src/typescript.jsdoc
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constructor type.
|
|
3
|
-
* @interface Constructor
|
|
4
|
-
* @extends Function
|
|
5
|
-
* @template T
|
|
6
|
-
* @tstype new(...params: any[]): T; prototype: T;
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Properties type.
|
|
11
|
-
* @typedef Properties
|
|
12
|
-
* @template T
|
|
13
|
-
* @type {Object.<string,*>}
|
|
14
|
-
* @tstype { [P in keyof T]?: T[P] }
|
|
15
|
-
*/
|