protobufjs 7.0.0 → 7.1.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/dist/light/protobuf.js +39 -15
- 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 +2 -2
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +56 -17
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +8 -3
- package/package.json +5 -5
- package/src/converter.js +9 -3
- package/src/enum.js +24 -7
- package/src/namespace.js +3 -2
- package/src/parse.js +17 -2
- package/tsconfig.json +2 -1
- package/dist/README.md +0 -31
- package/dist/light/README.md +0 -31
- package/dist/minimal/README.md +0 -31
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.
|
|
1
|
+
// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run build:types'.
|
|
2
2
|
|
|
3
3
|
export as namespace protobuf;
|
|
4
4
|
|
|
@@ -160,8 +160,9 @@ export class Enum extends ReflectionObject {
|
|
|
160
160
|
* @param [options] Declared options
|
|
161
161
|
* @param [comment] The comment for this enum
|
|
162
162
|
* @param [comments] The value comments for this enum
|
|
163
|
+
* @param [valuesOptions] The value options for this enum
|
|
163
164
|
*/
|
|
164
|
-
constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any }, comment?: string, comments?: { [k: string]: string });
|
|
165
|
+
constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any }, comment?: string, comments?: { [k: string]: string }, valuesOptions?: ({ [k: string]: { [k: string]: any } }|undefined));
|
|
165
166
|
|
|
166
167
|
/** Enum values by id. */
|
|
167
168
|
public valuesById: { [k: number]: string };
|
|
@@ -175,6 +176,9 @@ export class Enum extends ReflectionObject {
|
|
|
175
176
|
/** Value comment texts, if any. */
|
|
176
177
|
public comments: { [k: string]: string };
|
|
177
178
|
|
|
179
|
+
/** Values options, if any */
|
|
180
|
+
public valuesOptions?: { [k: string]: { [k: string]: any } };
|
|
181
|
+
|
|
178
182
|
/** Reserved ranges, if any. */
|
|
179
183
|
public reserved: (number[]|string)[];
|
|
180
184
|
|
|
@@ -199,11 +203,12 @@ export class Enum extends ReflectionObject {
|
|
|
199
203
|
* @param name Value name
|
|
200
204
|
* @param id Value id
|
|
201
205
|
* @param [comment] Comment, if any
|
|
206
|
+
* @param {Object.<string, *>|undefined} [options] Options, if any
|
|
202
207
|
* @returns `this`
|
|
203
208
|
* @throws {TypeError} If arguments are invalid
|
|
204
209
|
* @throws {Error} If there is already a value with this name or id
|
|
205
210
|
*/
|
|
206
|
-
public add(name: string, id: number, comment?: string): Enum;
|
|
211
|
+
public add(name: string, id: number, comment?: string, options?: ({ [k: string]: any }|undefined)): Enum;
|
|
207
212
|
|
|
208
213
|
/**
|
|
209
214
|
* Removes a value from this enum
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript (& TypeScript).",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"lint:sources": "eslint \"**/*.js\" -c config/eslint.json",
|
|
32
32
|
"lint:types": "tslint \"**/*.d.ts\" -e \"**/node_modules/**\" -t stylish -c config/tslint.json",
|
|
33
33
|
"pages": "node scripts/pages",
|
|
34
|
+
"prepublish": "cd cli && npm install && cd .. && npm run build",
|
|
34
35
|
"postinstall": "node scripts/postinstall",
|
|
35
36
|
"prof": "node bench/prof",
|
|
36
37
|
"test": "npm run test:sources && npm run test:types",
|
|
37
38
|
"test:sources": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
38
|
-
"test:types": "tsc tests/comp_typescript.ts --lib es2015 --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/*.ts --lib es2015 --noEmit --strictNullChecks",
|
|
39
|
+
"test:types": "tsc tests/comp_typescript.ts --lib es2015 --esModuleInterop --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --esModuleInterop --noEmit --strictNullChecks && tsc tests/data/*.ts --lib es2015 --esModuleInterop --noEmit --strictNullChecks",
|
|
39
40
|
"make": "npm run lint:sources && npm run build && npm run lint:types && node ./scripts/gentests.js && npm test"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
@@ -49,7 +50,6 @@
|
|
|
49
50
|
"@protobufjs/path": "^1.1.2",
|
|
50
51
|
"@protobufjs/pool": "^1.1.0",
|
|
51
52
|
"@protobufjs/utf8": "^1.1.0",
|
|
52
|
-
"@types/long": "^4.0.1",
|
|
53
53
|
"@types/node": ">=13.7.0",
|
|
54
54
|
"long": "^5.0.0"
|
|
55
55
|
},
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"chalk": "^4.0.0",
|
|
62
62
|
"escodegen": "^1.13.0",
|
|
63
63
|
"eslint": "^8.15.0",
|
|
64
|
-
"espree": "^
|
|
64
|
+
"espree": "^9.0.0",
|
|
65
65
|
"estraverse": "^5.1.0",
|
|
66
|
-
"gh-pages": "^
|
|
66
|
+
"gh-pages": "^4.0.0",
|
|
67
67
|
"git-raw-commits": "^2.0.3",
|
|
68
68
|
"git-semver-tags": "^4.0.0",
|
|
69
69
|
"google-protobuf": "^3.11.3",
|
package/src/converter.js
CHANGED
|
@@ -23,8 +23,14 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
23
23
|
if (field.resolvedType instanceof Enum) { gen
|
|
24
24
|
("switch(d%s){", prop);
|
|
25
25
|
for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
|
|
26
|
-
|
|
27
|
-
(
|
|
26
|
+
// enum unknown values passthrough
|
|
27
|
+
if (values[keys[i]] === field.typeDefault) { gen
|
|
28
|
+
("default:")
|
|
29
|
+
("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
|
|
30
|
+
if (!field.repeated) gen // fallback to default value only for
|
|
31
|
+
// arrays, to avoid leaving holes.
|
|
32
|
+
("break"); // for non-repeated fields, just ignore
|
|
33
|
+
}
|
|
28
34
|
gen
|
|
29
35
|
("case%j:", keys[i])
|
|
30
36
|
("case %i:", values[keys[i]])
|
|
@@ -156,7 +162,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
|
|
|
156
162
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
157
163
|
if (field.resolvedType) {
|
|
158
164
|
if (field.resolvedType instanceof Enum) gen
|
|
159
|
-
("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);
|
|
165
|
+
("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
|
|
160
166
|
else gen
|
|
161
167
|
("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
|
|
162
168
|
} else {
|
package/src/enum.js
CHANGED
|
@@ -18,8 +18,9 @@ var Namespace = require("./namespace"),
|
|
|
18
18
|
* @param {Object.<string,*>} [options] Declared options
|
|
19
19
|
* @param {string} [comment] The comment for this enum
|
|
20
20
|
* @param {Object.<string,string>} [comments] The value comments for this enum
|
|
21
|
+
* @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
|
|
21
22
|
*/
|
|
22
|
-
function Enum(name, values, options, comment, comments) {
|
|
23
|
+
function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
23
24
|
ReflectionObject.call(this, name, options);
|
|
24
25
|
|
|
25
26
|
if (values && typeof values !== "object")
|
|
@@ -49,6 +50,12 @@ function Enum(name, values, options, comment, comments) {
|
|
|
49
50
|
*/
|
|
50
51
|
this.comments = comments || {};
|
|
51
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Values options, if any
|
|
55
|
+
* @type {Object<string, Object<string, *>>|undefined}
|
|
56
|
+
*/
|
|
57
|
+
this.valuesOptions = valuesOptions;
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* Reserved ranges, if any.
|
|
54
61
|
* @type {Array.<number[]|string>}
|
|
@@ -93,11 +100,12 @@ Enum.fromJSON = function fromJSON(name, json) {
|
|
|
93
100
|
Enum.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
94
101
|
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
95
102
|
return util.toObject([
|
|
96
|
-
"options"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
103
|
+
"options" , this.options,
|
|
104
|
+
"valuesOptions" , this.valuesOptions,
|
|
105
|
+
"values" , this.values,
|
|
106
|
+
"reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
|
|
107
|
+
"comment" , keepComments ? this.comment : undefined,
|
|
108
|
+
"comments" , keepComments ? this.comments : undefined
|
|
101
109
|
]);
|
|
102
110
|
};
|
|
103
111
|
|
|
@@ -106,11 +114,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
106
114
|
* @param {string} name Value name
|
|
107
115
|
* @param {number} id Value id
|
|
108
116
|
* @param {string} [comment] Comment, if any
|
|
117
|
+
* @param {Object.<string, *>|undefined} [options] Options, if any
|
|
109
118
|
* @returns {Enum} `this`
|
|
110
119
|
* @throws {TypeError} If arguments are invalid
|
|
111
120
|
* @throws {Error} If there is already a value with this name or id
|
|
112
121
|
*/
|
|
113
|
-
Enum.prototype.add = function add(name, id, comment) {
|
|
122
|
+
Enum.prototype.add = function add(name, id, comment, options) {
|
|
114
123
|
// utilized by the parser but not by .fromJSON
|
|
115
124
|
|
|
116
125
|
if (!util.isString(name))
|
|
@@ -135,6 +144,12 @@ Enum.prototype.add = function add(name, id, comment) {
|
|
|
135
144
|
} else
|
|
136
145
|
this.valuesById[this.values[name] = id] = name;
|
|
137
146
|
|
|
147
|
+
if (options) {
|
|
148
|
+
if (this.valuesOptions === undefined)
|
|
149
|
+
this.valuesOptions = {};
|
|
150
|
+
this.valuesOptions[name] = options || null;
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
this.comments[name] = comment || null;
|
|
139
154
|
return this;
|
|
140
155
|
};
|
|
@@ -158,6 +173,8 @@ Enum.prototype.remove = function remove(name) {
|
|
|
158
173
|
delete this.valuesById[val];
|
|
159
174
|
delete this.values[name];
|
|
160
175
|
delete this.comments[name];
|
|
176
|
+
if (this.valuesOptions)
|
|
177
|
+
delete this.valuesOptions[name];
|
|
161
178
|
|
|
162
179
|
return this;
|
|
163
180
|
};
|
package/src/namespace.js
CHANGED
|
@@ -6,7 +6,8 @@ var ReflectionObject = require("./object");
|
|
|
6
6
|
((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
|
|
7
7
|
|
|
8
8
|
var Field = require("./field"),
|
|
9
|
-
util = require("./util")
|
|
9
|
+
util = require("./util"),
|
|
10
|
+
OneOf = require("./oneof");
|
|
10
11
|
|
|
11
12
|
var Type, // cyclic
|
|
12
13
|
Service,
|
|
@@ -217,7 +218,7 @@ Namespace.prototype.getEnum = function getEnum(name) {
|
|
|
217
218
|
*/
|
|
218
219
|
Namespace.prototype.add = function add(object) {
|
|
219
220
|
|
|
220
|
-
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
221
|
+
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
221
222
|
throw TypeError("object must be a valid nested object");
|
|
222
223
|
|
|
223
224
|
if (!this.nested)
|
package/src/parse.js
CHANGED
|
@@ -443,6 +443,14 @@ function parse(source, root, options) {
|
|
|
443
443
|
}
|
|
444
444
|
break;
|
|
445
445
|
|
|
446
|
+
case "message":
|
|
447
|
+
parseType(type, token);
|
|
448
|
+
break;
|
|
449
|
+
|
|
450
|
+
case "enum":
|
|
451
|
+
parseEnum(type, token);
|
|
452
|
+
break;
|
|
453
|
+
|
|
446
454
|
/* istanbul ignore next */
|
|
447
455
|
default:
|
|
448
456
|
throw illegal(token); // there are no groups with proto3 semantics
|
|
@@ -543,7 +551,14 @@ function parse(source, root, options) {
|
|
|
543
551
|
|
|
544
552
|
skip("=");
|
|
545
553
|
var value = parseId(next(), true),
|
|
546
|
-
dummy = {
|
|
554
|
+
dummy = {
|
|
555
|
+
options: undefined
|
|
556
|
+
};
|
|
557
|
+
dummy.setOption = function(name, value) {
|
|
558
|
+
if (this.options === undefined)
|
|
559
|
+
this.options = {};
|
|
560
|
+
this.options[name] = value;
|
|
561
|
+
};
|
|
547
562
|
ifBlock(dummy, function parseEnumValue_block(token) {
|
|
548
563
|
|
|
549
564
|
/* istanbul ignore else */
|
|
@@ -556,7 +571,7 @@ function parse(source, root, options) {
|
|
|
556
571
|
}, function parseEnumValue_line() {
|
|
557
572
|
parseInlineOptions(dummy); // skip
|
|
558
573
|
});
|
|
559
|
-
parent.add(token, value, dummy.comment);
|
|
574
|
+
parent.add(token, value, dummy.comment, dummy.options);
|
|
560
575
|
}
|
|
561
576
|
|
|
562
577
|
function parseOption(parent, token) {
|
package/tsconfig.json
CHANGED
package/dist/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
This folder contains prebuilt browser versions of the full library. When sending pull requests, it is not required to update these.
|
|
2
|
-
|
|
3
|
-
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
|
|
4
|
-
|
|
5
|
-
CDN usage
|
|
6
|
-
---------
|
|
7
|
-
|
|
8
|
-
Development:
|
|
9
|
-
```
|
|
10
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/protobuf.js"></script>
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Production:
|
|
14
|
-
```
|
|
15
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/protobuf.min.js"></script>
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/tags) your project depends upon.
|
|
19
|
-
|
|
20
|
-
Frontend usage
|
|
21
|
-
--------------
|
|
22
|
-
|
|
23
|
-
Development:
|
|
24
|
-
```
|
|
25
|
-
<script src="node_modules/protobufjs/dist/protobuf.js"></script>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Production:
|
|
29
|
-
```
|
|
30
|
-
<script src="node_modules/protobufjs/dist/protobuf.min.js"></script>
|
|
31
|
-
```
|
package/dist/light/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
This folder contains prebuilt browser versions of the light library suitable for use with reflection, static code and JSON descriptors / modules. When sending pull requests, it is not required to update these.
|
|
2
|
-
|
|
3
|
-
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
|
|
4
|
-
|
|
5
|
-
CDN usage
|
|
6
|
-
---------
|
|
7
|
-
|
|
8
|
-
Development:
|
|
9
|
-
```
|
|
10
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.js"></script>
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Production:
|
|
14
|
-
```
|
|
15
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/light/protobuf.min.js"></script>
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/tags) your project depends upon.
|
|
19
|
-
|
|
20
|
-
Frontend usage
|
|
21
|
-
--------------
|
|
22
|
-
|
|
23
|
-
Development:
|
|
24
|
-
```
|
|
25
|
-
<script src="node_modules/protobufjs/dist/light/protobuf.js"></script>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Production:
|
|
29
|
-
```
|
|
30
|
-
<script src="node_modules/protobufjs/dist/light/protobuf.min.js"></script>
|
|
31
|
-
```
|
package/dist/minimal/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
This folder contains prebuilt browser versions of the minimal library suitable for use with statically generated code only. When sending pull requests, it is not required to update these.
|
|
2
|
-
|
|
3
|
-
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
|
|
4
|
-
|
|
5
|
-
CDN usage
|
|
6
|
-
---------
|
|
7
|
-
|
|
8
|
-
Development:
|
|
9
|
-
```
|
|
10
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/minimal/protobuf.js"></script>
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Production:
|
|
14
|
-
```
|
|
15
|
-
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/minimal/protobuf.min.js"></script>
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/tags) your project depends upon.
|
|
19
|
-
|
|
20
|
-
Frontend usage
|
|
21
|
-
--------------
|
|
22
|
-
|
|
23
|
-
Development:
|
|
24
|
-
```
|
|
25
|
-
<script src="node_modules/protobufjs/dist/minimal/protobuf.js"></script>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Production:
|
|
29
|
-
```
|
|
30
|
-
<script src="node_modules/protobufjs/dist/minimal/protobuf.min.js"></script>
|
|
31
|
-
```
|