protobufjs 8.0.1 → 8.0.2

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.
Files changed (98) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +727 -727
  3. package/dist/light/protobuf.js +7724 -7591
  4. package/dist/light/protobuf.js.map +1 -1
  5. package/dist/light/protobuf.min.js +3 -3
  6. package/dist/light/protobuf.min.js.map +1 -1
  7. package/dist/minimal/protobuf.js +2606 -2546
  8. package/dist/minimal/protobuf.js.map +1 -1
  9. package/dist/minimal/protobuf.min.js +3 -3
  10. package/dist/minimal/protobuf.min.js.map +1 -1
  11. package/dist/protobuf.js +9593 -9436
  12. package/dist/protobuf.js.map +1 -1
  13. package/dist/protobuf.min.js +3 -3
  14. package/dist/protobuf.min.js.map +1 -1
  15. package/ext/debug/README.md +4 -4
  16. package/ext/debug/index.js +71 -71
  17. package/ext/descriptor/README.md +72 -72
  18. package/ext/descriptor/index.d.ts +195 -191
  19. package/ext/descriptor/index.js +1181 -1163
  20. package/ext/descriptor/test.js +54 -54
  21. package/google/LICENSE +27 -27
  22. package/google/README.md +1 -1
  23. package/google/api/annotations.json +82 -82
  24. package/google/api/annotations.proto +10 -10
  25. package/google/api/http.json +85 -85
  26. package/google/api/http.proto +30 -30
  27. package/google/protobuf/api.json +117 -117
  28. package/google/protobuf/api.proto +33 -33
  29. package/google/protobuf/descriptor.json +1381 -1381
  30. package/google/protobuf/descriptor.proto +534 -534
  31. package/google/protobuf/source_context.json +19 -19
  32. package/google/protobuf/source_context.proto +7 -7
  33. package/google/protobuf/type.json +201 -201
  34. package/google/protobuf/type.proto +89 -89
  35. package/index.d.ts +2817 -2799
  36. package/index.js +4 -4
  37. package/light.d.ts +2 -2
  38. package/light.js +3 -3
  39. package/minimal.d.ts +2 -2
  40. package/minimal.js +4 -4
  41. package/package.json +96 -114
  42. package/scripts/postinstall.js +32 -32
  43. package/src/common.js +399 -399
  44. package/src/converter.js +310 -301
  45. package/src/decoder.js +135 -127
  46. package/src/encoder.js +100 -100
  47. package/src/enum.js +226 -223
  48. package/src/field.js +453 -453
  49. package/src/index-light.js +104 -104
  50. package/src/index-minimal.js +36 -36
  51. package/src/index.js +12 -12
  52. package/src/mapfield.js +126 -126
  53. package/src/message.js +139 -143
  54. package/src/method.js +160 -160
  55. package/src/namespace.js +550 -546
  56. package/src/object.js +385 -381
  57. package/src/oneof.js +222 -222
  58. package/src/parse.js +1032 -1013
  59. package/src/reader.js +426 -416
  60. package/src/reader_buffer.js +51 -51
  61. package/src/root.js +403 -403
  62. package/src/roots.js +17 -17
  63. package/src/rpc/service.js +142 -142
  64. package/src/rpc.js +36 -36
  65. package/src/service.js +193 -189
  66. package/src/tokenize.js +421 -416
  67. package/src/type.js +625 -615
  68. package/src/types.js +196 -196
  69. package/src/typescript.jsdoc +15 -15
  70. package/src/util/aspromise.d.ts +13 -0
  71. package/src/util/aspromise.js +52 -0
  72. package/src/util/base64.d.ts +32 -0
  73. package/src/util/base64.js +139 -0
  74. package/src/util/codegen.d.ts +31 -0
  75. package/src/util/codegen.js +113 -0
  76. package/src/util/eventemitter.d.ts +45 -0
  77. package/src/util/eventemitter.js +84 -0
  78. package/src/util/fetch.d.ts +56 -0
  79. package/src/util/fetch.js +114 -0
  80. package/src/util/float.d.ts +83 -0
  81. package/src/util/float.js +335 -0
  82. package/src/util/inquire.d.ts +9 -0
  83. package/src/util/inquire.js +37 -0
  84. package/src/util/longbits.js +200 -200
  85. package/src/util/minimal.js +461 -438
  86. package/src/util/path.d.ts +22 -0
  87. package/src/util/path.js +72 -0
  88. package/src/util/patterns.js +8 -0
  89. package/src/util/pool.d.ts +32 -0
  90. package/src/util/pool.js +48 -0
  91. package/src/util/utf8.d.ts +24 -0
  92. package/src/util/utf8.js +104 -0
  93. package/src/util.js +215 -215
  94. package/src/verifier.js +180 -177
  95. package/src/wrappers.js +103 -102
  96. package/src/writer.js +465 -465
  97. package/src/writer_buffer.js +85 -85
  98. package/tsconfig.json +8 -8
package/src/enum.js CHANGED
@@ -1,223 +1,226 @@
1
- "use strict";
2
- module.exports = Enum;
3
-
4
- // extends ReflectionObject
5
- var ReflectionObject = require("./object");
6
- ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
7
-
8
- var Namespace = require("./namespace"),
9
- util = require("./util");
10
-
11
- /**
12
- * Constructs a new enum instance.
13
- * @classdesc Reflected enum.
14
- * @extends ReflectionObject
15
- * @constructor
16
- * @param {string} name Unique name within its namespace
17
- * @param {Object.<string,number>} [values] Enum values as an object, by name
18
- * @param {Object.<string,*>} [options] Declared options
19
- * @param {string} [comment] The comment for this enum
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
22
- */
23
- function Enum(name, values, options, comment, comments, valuesOptions) {
24
- ReflectionObject.call(this, name, options);
25
-
26
- if (values && typeof values !== "object")
27
- throw TypeError("values must be an object");
28
-
29
- /**
30
- * Enum values by id.
31
- * @type {Object.<number,string>}
32
- */
33
- this.valuesById = {};
34
-
35
- /**
36
- * Enum values by name.
37
- * @type {Object.<string,number>}
38
- */
39
- this.values = Object.create(this.valuesById); // toJSON, marker
40
-
41
- /**
42
- * Enum comment text.
43
- * @type {string|null}
44
- */
45
- this.comment = comment;
46
-
47
- /**
48
- * Value comment texts, if any.
49
- * @type {Object.<string,string>}
50
- */
51
- this.comments = comments || {};
52
-
53
- /**
54
- * Values options, if any
55
- * @type {Object<string, Object<string, *>>|undefined}
56
- */
57
- this.valuesOptions = valuesOptions;
58
-
59
- /**
60
- * Resolved values features, if any
61
- * @type {Object<string, Object<string, *>>|undefined}
62
- */
63
- this._valuesFeatures = {};
64
-
65
- /**
66
- * Reserved ranges, if any.
67
- * @type {Array.<number[]|string>}
68
- */
69
- this.reserved = undefined; // toJSON
70
-
71
- // Note that values inherit valuesById on their prototype which makes them a TypeScript-
72
- // compatible enum. This is used by pbts to write actual enum definitions that work for
73
- // static and reflection code alike instead of emitting generic object definitions.
74
-
75
- if (values)
76
- for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
77
- if (typeof values[keys[i]] === "number") // use forward entries only
78
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
79
- }
80
-
81
- /**
82
- * @override
83
- */
84
- Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
85
- edition = this._edition || edition;
86
- ReflectionObject.prototype._resolveFeatures.call(this, edition);
87
-
88
- Object.keys(this.values).forEach(key => {
89
- var parentFeaturesCopy = Object.assign({}, this._features);
90
- this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features);
91
- });
92
-
93
- return this;
94
- };
95
-
96
- /**
97
- * Enum descriptor.
98
- * @interface IEnum
99
- * @property {Object.<string,number>} values Enum values
100
- * @property {Object.<string,*>} [options] Enum options
101
- */
102
-
103
- /**
104
- * Constructs an enum from an enum descriptor.
105
- * @param {string} name Enum name
106
- * @param {IEnum} json Enum descriptor
107
- * @returns {Enum} Created enum
108
- * @throws {TypeError} If arguments are invalid
109
- */
110
- Enum.fromJSON = function fromJSON(name, json) {
111
- var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
112
- enm.reserved = json.reserved;
113
- if (json.edition)
114
- enm._edition = json.edition;
115
- enm._defaultEdition = "proto3"; // For backwards-compatibility.
116
- return enm;
117
- };
118
-
119
- /**
120
- * Converts this enum to an enum descriptor.
121
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
122
- * @returns {IEnum} Enum descriptor
123
- */
124
- Enum.prototype.toJSON = function toJSON(toJSONOptions) {
125
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
126
- return util.toObject([
127
- "edition" , this._editionToJSON(),
128
- "options" , this.options,
129
- "valuesOptions" , this.valuesOptions,
130
- "values" , this.values,
131
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
132
- "comment" , keepComments ? this.comment : undefined,
133
- "comments" , keepComments ? this.comments : undefined
134
- ]);
135
- };
136
-
137
- /**
138
- * Adds a value to this enum.
139
- * @param {string} name Value name
140
- * @param {number} id Value id
141
- * @param {string} [comment] Comment, if any
142
- * @param {Object.<string, *>|undefined} [options] Options, if any
143
- * @returns {Enum} `this`
144
- * @throws {TypeError} If arguments are invalid
145
- * @throws {Error} If there is already a value with this name or id
146
- */
147
- Enum.prototype.add = function add(name, id, comment, options) {
148
- // utilized by the parser but not by .fromJSON
149
-
150
- if (!util.isString(name))
151
- throw TypeError("name must be a string");
152
-
153
- if (!util.isInteger(id))
154
- throw TypeError("id must be an integer");
155
-
156
- if (this.values[name] !== undefined)
157
- throw Error("duplicate name '" + name + "' in " + this);
158
-
159
- if (this.isReservedId(id))
160
- throw Error("id " + id + " is reserved in " + this);
161
-
162
- if (this.isReservedName(name))
163
- throw Error("name '" + name + "' is reserved in " + this);
164
-
165
- if (this.valuesById[id] !== undefined) {
166
- if (!(this.options && this.options.allow_alias))
167
- throw Error("duplicate id " + id + " in " + this);
168
- this.values[name] = id;
169
- } else
170
- this.valuesById[this.values[name] = id] = name;
171
-
172
- if (options) {
173
- if (this.valuesOptions === undefined)
174
- this.valuesOptions = {};
175
- this.valuesOptions[name] = options || null;
176
- }
177
-
178
- this.comments[name] = comment || null;
179
- return this;
180
- };
181
-
182
- /**
183
- * Removes a value from this enum
184
- * @param {string} name Value name
185
- * @returns {Enum} `this`
186
- * @throws {TypeError} If arguments are invalid
187
- * @throws {Error} If `name` is not a name of this enum
188
- */
189
- Enum.prototype.remove = function remove(name) {
190
-
191
- if (!util.isString(name))
192
- throw TypeError("name must be a string");
193
-
194
- var val = this.values[name];
195
- if (val == null)
196
- throw Error("name '" + name + "' does not exist in " + this);
197
-
198
- delete this.valuesById[val];
199
- delete this.values[name];
200
- delete this.comments[name];
201
- if (this.valuesOptions)
202
- delete this.valuesOptions[name];
203
-
204
- return this;
205
- };
206
-
207
- /**
208
- * Tests if the specified id is reserved.
209
- * @param {number} id Id to test
210
- * @returns {boolean} `true` if reserved, otherwise `false`
211
- */
212
- Enum.prototype.isReservedId = function isReservedId(id) {
213
- return Namespace.isReservedId(this.reserved, id);
214
- };
215
-
216
- /**
217
- * Tests if the specified name is reserved.
218
- * @param {string} name Name to test
219
- * @returns {boolean} `true` if reserved, otherwise `false`
220
- */
221
- Enum.prototype.isReservedName = function isReservedName(name) {
222
- return Namespace.isReservedName(this.reserved, name);
223
- };
1
+ "use strict";
2
+ module.exports = Enum;
3
+
4
+ // extends ReflectionObject
5
+ var ReflectionObject = require("./object");
6
+ ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
7
+
8
+ var Namespace = require("./namespace"),
9
+ util = require("./util");
10
+
11
+ /**
12
+ * Constructs a new enum instance.
13
+ * @classdesc Reflected enum.
14
+ * @extends ReflectionObject
15
+ * @constructor
16
+ * @param {string} name Unique name within its namespace
17
+ * @param {Object.<string,number>} [values] Enum values as an object, by name
18
+ * @param {Object.<string,*>} [options] Declared options
19
+ * @param {string} [comment] The comment for this enum
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
22
+ */
23
+ function Enum(name, values, options, comment, comments, valuesOptions) {
24
+ ReflectionObject.call(this, name, options);
25
+
26
+ if (values && typeof values !== "object")
27
+ throw TypeError("values must be an object");
28
+
29
+ /**
30
+ * Enum values by id.
31
+ * @type {Object.<number,string>}
32
+ */
33
+ this.valuesById = {};
34
+
35
+ /**
36
+ * Enum values by name.
37
+ * @type {Object.<string,number>}
38
+ */
39
+ this.values = Object.create(this.valuesById); // toJSON, marker
40
+
41
+ /**
42
+ * Enum comment text.
43
+ * @type {string|null}
44
+ */
45
+ this.comment = comment;
46
+
47
+ /**
48
+ * Value comment texts, if any.
49
+ * @type {Object.<string,string>}
50
+ */
51
+ this.comments = comments || {};
52
+
53
+ /**
54
+ * Values options, if any
55
+ * @type {Object<string, Object<string, *>>|undefined}
56
+ */
57
+ this.valuesOptions = valuesOptions;
58
+
59
+ /**
60
+ * Resolved values features, if any
61
+ * @type {Object<string, Object<string, *>>|undefined}
62
+ */
63
+ this._valuesFeatures = {};
64
+
65
+ /**
66
+ * Reserved ranges, if any.
67
+ * @type {Array.<number[]|string>}
68
+ */
69
+ this.reserved = undefined; // toJSON
70
+
71
+ // Note that values inherit valuesById on their prototype which makes them a TypeScript-
72
+ // compatible enum. This is used by pbts to write actual enum definitions that work for
73
+ // static and reflection code alike instead of emitting generic object definitions.
74
+
75
+ if (values)
76
+ for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
77
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
78
+ this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
79
+ }
80
+
81
+ /**
82
+ * @override
83
+ */
84
+ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
85
+ edition = this._edition || edition;
86
+ ReflectionObject.prototype._resolveFeatures.call(this, edition);
87
+
88
+ Object.keys(this.values).forEach(key => {
89
+ var parentFeaturesCopy = Object.assign({}, this._features);
90
+ this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features);
91
+ });
92
+
93
+ return this;
94
+ };
95
+
96
+ /**
97
+ * Enum descriptor.
98
+ * @interface IEnum
99
+ * @property {Object.<string,number>} values Enum values
100
+ * @property {Object.<string,*>} [options] Enum options
101
+ */
102
+
103
+ /**
104
+ * Constructs an enum from an enum descriptor.
105
+ * @param {string} name Enum name
106
+ * @param {IEnum} json Enum descriptor
107
+ * @returns {Enum} Created enum
108
+ * @throws {TypeError} If arguments are invalid
109
+ */
110
+ Enum.fromJSON = function fromJSON(name, json) {
111
+ var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
112
+ enm.reserved = json.reserved;
113
+ if (json.edition)
114
+ enm._edition = json.edition;
115
+ enm._defaultEdition = "proto3"; // For backwards-compatibility.
116
+ return enm;
117
+ };
118
+
119
+ /**
120
+ * Converts this enum to an enum descriptor.
121
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
122
+ * @returns {IEnum} Enum descriptor
123
+ */
124
+ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
125
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
126
+ return util.toObject([
127
+ "edition" , this._editionToJSON(),
128
+ "options" , this.options,
129
+ "valuesOptions" , this.valuesOptions,
130
+ "values" , this.values,
131
+ "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
132
+ "comment" , keepComments ? this.comment : undefined,
133
+ "comments" , keepComments ? this.comments : undefined
134
+ ]);
135
+ };
136
+
137
+ /**
138
+ * Adds a value to this enum.
139
+ * @param {string} name Value name
140
+ * @param {number} id Value id
141
+ * @param {string} [comment] Comment, if any
142
+ * @param {Object.<string, *>|undefined} [options] Options, if any
143
+ * @returns {Enum} `this`
144
+ * @throws {TypeError} If arguments are invalid
145
+ * @throws {Error} If there is already a value with this name or id
146
+ */
147
+ Enum.prototype.add = function add(name, id, comment, options) {
148
+ // utilized by the parser but not by .fromJSON
149
+
150
+ if (!util.isString(name))
151
+ throw TypeError("name must be a string");
152
+
153
+ if (!util.isInteger(id))
154
+ throw TypeError("id must be an integer");
155
+
156
+ if (name === "__proto__")
157
+ return this;
158
+
159
+ if (this.values[name] !== undefined)
160
+ throw Error("duplicate name '" + name + "' in " + this);
161
+
162
+ if (this.isReservedId(id))
163
+ throw Error("id " + id + " is reserved in " + this);
164
+
165
+ if (this.isReservedName(name))
166
+ throw Error("name '" + name + "' is reserved in " + this);
167
+
168
+ if (this.valuesById[id] !== undefined) {
169
+ if (!(this.options && this.options.allow_alias))
170
+ throw Error("duplicate id " + id + " in " + this);
171
+ this.values[name] = id;
172
+ } else
173
+ this.valuesById[this.values[name] = id] = name;
174
+
175
+ if (options) {
176
+ if (this.valuesOptions === undefined)
177
+ this.valuesOptions = {};
178
+ this.valuesOptions[name] = options || null;
179
+ }
180
+
181
+ this.comments[name] = comment || null;
182
+ return this;
183
+ };
184
+
185
+ /**
186
+ * Removes a value from this enum
187
+ * @param {string} name Value name
188
+ * @returns {Enum} `this`
189
+ * @throws {TypeError} If arguments are invalid
190
+ * @throws {Error} If `name` is not a name of this enum
191
+ */
192
+ Enum.prototype.remove = function remove(name) {
193
+
194
+ if (!util.isString(name))
195
+ throw TypeError("name must be a string");
196
+
197
+ var val = this.values[name];
198
+ if (val == null)
199
+ throw Error("name '" + name + "' does not exist in " + this);
200
+
201
+ delete this.valuesById[val];
202
+ delete this.values[name];
203
+ delete this.comments[name];
204
+ if (this.valuesOptions)
205
+ delete this.valuesOptions[name];
206
+
207
+ return this;
208
+ };
209
+
210
+ /**
211
+ * Tests if the specified id is reserved.
212
+ * @param {number} id Id to test
213
+ * @returns {boolean} `true` if reserved, otherwise `false`
214
+ */
215
+ Enum.prototype.isReservedId = function isReservedId(id) {
216
+ return Namespace.isReservedId(this.reserved, id);
217
+ };
218
+
219
+ /**
220
+ * Tests if the specified name is reserved.
221
+ * @param {string} name Name to test
222
+ * @returns {boolean} `true` if reserved, otherwise `false`
223
+ */
224
+ Enum.prototype.isReservedName = function isReservedName(name) {
225
+ return Namespace.isReservedName(this.reserved, name);
226
+ };