protobufjs 8.0.3-experimental → 8.0.3

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 -7352
  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 +9588 -9131
  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 -1052
  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 -738
  30. package/google/protobuf/descriptor.proto +535 -286
  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 -2792
  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 -112
  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 -241
  48. package/src/field.js +453 -432
  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 -139
  54. package/src/method.js +160 -160
  55. package/src/namespace.js +550 -434
  56. package/src/object.js +385 -330
  57. package/src/oneof.js +222 -222
  58. package/src/parse.js +1024 -944
  59. package/src/reader.js +426 -416
  60. package/src/reader_buffer.js +51 -51
  61. package/src/root.js +404 -384
  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 -168
  66. package/src/tokenize.js +421 -416
  67. package/src/type.js +625 -590
  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 -213
  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,241 +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
- * Unresolved values features, if any
67
- * @type {Object<string, Object<string, *>>|undefined}
68
- */
69
- this._valuesProtoFeatures = {};
70
-
71
- /**
72
- * Reserved ranges, if any.
73
- * @type {Array.<number[]|string>}
74
- */
75
- this.reserved = undefined; // toJSON
76
-
77
- // Note that values inherit valuesById on their prototype which makes them a TypeScript-
78
- // compatible enum. This is used by pbts to write actual enum definitions that work for
79
- // static and reflection code alike instead of emitting generic object definitions.
80
-
81
- if (values)
82
- for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
83
- if (typeof values[keys[i]] === "number") // use forward entries only
84
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
85
- }
86
-
87
- /**
88
- * Resolves value features
89
- * @returns {Enum} `this`
90
- */
91
- Enum.prototype.resolve = function resolve() {
92
- ReflectionObject.prototype.resolve.call(this);
93
-
94
- for (var key of Object.keys(this._valuesProtoFeatures)) {
95
- var parentFeaturesCopy = Object.assign({}, this._features);
96
- this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this._valuesProtoFeatures[key] || {});
97
- }
98
-
99
- return this;
100
- };
101
-
102
-
103
- /**
104
- * Enum descriptor.
105
- * @interface IEnum
106
- * @property {Object.<string,number>} values Enum values
107
- * @property {Object.<string,*>} [options] Enum options
108
- */
109
-
110
- /**
111
- * Constructs an enum from an enum descriptor.
112
- * @param {string} name Enum name
113
- * @param {IEnum} json Enum descriptor
114
- * @returns {Enum} Created enum
115
- * @throws {TypeError} If arguments are invalid
116
- */
117
- Enum.fromJSON = function fromJSON(name, json) {
118
- var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
119
- enm.reserved = json.reserved;
120
- return enm;
121
- };
122
-
123
- /**
124
- * Converts this enum to an enum descriptor.
125
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
126
- * @returns {IEnum} Enum descriptor
127
- */
128
- Enum.prototype.toJSON = function toJSON(toJSONOptions) {
129
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
130
- return util.toObject([
131
- "options" , this.options,
132
- "valuesOptions" , this.valuesOptions,
133
- "values" , this.values,
134
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
135
- "comment" , keepComments ? this.comment : undefined,
136
- "comments" , keepComments ? this.comments : undefined
137
- ]);
138
- };
139
-
140
- /**
141
- * Adds a value to this enum.
142
- * @param {string} name Value name
143
- * @param {number} id Value id
144
- * @param {string} [comment] Comment, if any
145
- * @param {Object.<string, *>|undefined} [options] Options, if any
146
- * @returns {Enum} `this`
147
- * @throws {TypeError} If arguments are invalid
148
- * @throws {Error} If there is already a value with this name or id
149
- */
150
- Enum.prototype.add = function add(name, id, comment, options) {
151
- // utilized by the parser but not by .fromJSON
152
-
153
- if (!util.isString(name))
154
- throw TypeError("name must be a string");
155
-
156
- if (!util.isInteger(id))
157
- throw TypeError("id must be an integer");
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
- for (var key of Object.keys(this.valuesOptions)) {
181
- var features = Array.isArray(this.valuesOptions[key]) ? this.valuesOptions[key].find(x => {return Object.prototype.hasOwnProperty.call(x, "features");}) : this.valuesOptions[key] === "features";
182
- if (features) {
183
- this._valuesProtoFeatures[key] = features.features;
184
- } else {
185
- this._valuesProtoFeatures[key] = {};
186
- }
187
- }
188
- }
189
-
190
- for (var enumValue of Object.keys(this.values)) {
191
- if (!this._valuesProtoFeatures[enumValue]) {
192
- this._valuesProtoFeatures[enumValue] = {};
193
- }
194
- }
195
-
196
- this.comments[name] = comment || null;
197
- return this;
198
- };
199
-
200
- /**
201
- * Removes a value from this enum
202
- * @param {string} name Value name
203
- * @returns {Enum} `this`
204
- * @throws {TypeError} If arguments are invalid
205
- * @throws {Error} If `name` is not a name of this enum
206
- */
207
- Enum.prototype.remove = function remove(name) {
208
-
209
- if (!util.isString(name))
210
- throw TypeError("name must be a string");
211
-
212
- var val = this.values[name];
213
- if (val == null)
214
- throw Error("name '" + name + "' does not exist in " + this);
215
-
216
- delete this.valuesById[val];
217
- delete this.values[name];
218
- delete this.comments[name];
219
- if (this.valuesOptions)
220
- delete this.valuesOptions[name];
221
-
222
- return this;
223
- };
224
-
225
- /**
226
- * Tests if the specified id is reserved.
227
- * @param {number} id Id to test
228
- * @returns {boolean} `true` if reserved, otherwise `false`
229
- */
230
- Enum.prototype.isReservedId = function isReservedId(id) {
231
- return Namespace.isReservedId(this.reserved, id);
232
- };
233
-
234
- /**
235
- * Tests if the specified name is reserved.
236
- * @param {string} name Name to test
237
- * @returns {boolean} `true` if reserved, otherwise `false`
238
- */
239
- Enum.prototype.isReservedName = function isReservedName(name) {
240
- return Namespace.isReservedName(this.reserved, name);
241
- };
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
+ };