protobufjs 7.3.2 → 7.3.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 (77) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +727 -727
  3. package/ext/debug/README.md +4 -4
  4. package/ext/debug/index.js +71 -71
  5. package/ext/descriptor/README.md +72 -72
  6. package/ext/descriptor/index.d.ts +191 -191
  7. package/ext/descriptor/index.js +1052 -1052
  8. package/ext/descriptor/test.js +54 -54
  9. package/google/LICENSE +27 -27
  10. package/google/README.md +1 -1
  11. package/google/api/annotations.json +82 -82
  12. package/google/api/annotations.proto +10 -10
  13. package/google/api/http.json +85 -85
  14. package/google/api/http.proto +30 -30
  15. package/google/protobuf/api.json +117 -117
  16. package/google/protobuf/api.proto +33 -33
  17. package/google/protobuf/descriptor.json +738 -738
  18. package/google/protobuf/descriptor.proto +286 -286
  19. package/google/protobuf/source_context.json +19 -19
  20. package/google/protobuf/source_context.proto +7 -7
  21. package/google/protobuf/type.json +201 -201
  22. package/google/protobuf/type.proto +89 -89
  23. package/index.d.ts +2741 -2741
  24. package/index.js +4 -4
  25. package/light.d.ts +2 -2
  26. package/light.js +3 -3
  27. package/minimal.d.ts +2 -2
  28. package/minimal.js +4 -4
  29. package/package.json +111 -111
  30. package/scripts/postinstall.js +32 -32
  31. package/src/common.js +399 -399
  32. package/src/converter.js +301 -301
  33. package/src/decoder.js +129 -129
  34. package/src/encoder.js +100 -100
  35. package/src/enum.js +198 -198
  36. package/src/field.js +377 -377
  37. package/src/index-light.js +104 -104
  38. package/src/index-minimal.js +36 -36
  39. package/src/index.js +12 -12
  40. package/src/mapfield.js +126 -126
  41. package/src/message.js +138 -138
  42. package/src/method.js +160 -160
  43. package/src/namespace.js +433 -433
  44. package/src/object.js +243 -243
  45. package/src/oneof.js +203 -203
  46. package/src/parse.js +893 -889
  47. package/src/reader.js +416 -416
  48. package/src/reader_buffer.js +51 -51
  49. package/src/root.js +368 -368
  50. package/src/roots.js +18 -18
  51. package/src/rpc/service.js +142 -142
  52. package/src/rpc.js +36 -36
  53. package/src/service.js +167 -167
  54. package/src/tokenize.js +416 -416
  55. package/src/type.js +589 -589
  56. package/src/types.js +196 -196
  57. package/src/typescript.jsdoc +15 -15
  58. package/src/util/longbits.js +200 -200
  59. package/src/util/minimal.js +438 -438
  60. package/src/util.js +212 -212
  61. package/src/verifier.js +176 -176
  62. package/src/wrappers.js +102 -102
  63. package/src/writer.js +465 -465
  64. package/src/writer_buffer.js +85 -85
  65. package/tsconfig.json +7 -7
  66. package/dist/light/protobuf.js +0 -7381
  67. package/dist/light/protobuf.js.map +0 -1
  68. package/dist/light/protobuf.min.js +0 -8
  69. package/dist/light/protobuf.min.js.map +0 -1
  70. package/dist/minimal/protobuf.js +0 -2736
  71. package/dist/minimal/protobuf.js.map +0 -1
  72. package/dist/minimal/protobuf.min.js +0 -8
  73. package/dist/minimal/protobuf.min.js.map +0 -1
  74. package/dist/protobuf.js +0 -9105
  75. package/dist/protobuf.js.map +0 -1
  76. package/dist/protobuf.min.js +0 -8
  77. package/dist/protobuf.min.js.map +0 -1
package/src/enum.js CHANGED
@@ -1,198 +1,198 @@
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
- * Reserved ranges, if any.
61
- * @type {Array.<number[]|string>}
62
- */
63
- this.reserved = undefined; // toJSON
64
-
65
- // Note that values inherit valuesById on their prototype which makes them a TypeScript-
66
- // compatible enum. This is used by pbts to write actual enum definitions that work for
67
- // static and reflection code alike instead of emitting generic object definitions.
68
-
69
- if (values)
70
- for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
71
- if (typeof values[keys[i]] === "number") // use forward entries only
72
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
73
- }
74
-
75
- /**
76
- * Enum descriptor.
77
- * @interface IEnum
78
- * @property {Object.<string,number>} values Enum values
79
- * @property {Object.<string,*>} [options] Enum options
80
- */
81
-
82
- /**
83
- * Constructs an enum from an enum descriptor.
84
- * @param {string} name Enum name
85
- * @param {IEnum} json Enum descriptor
86
- * @returns {Enum} Created enum
87
- * @throws {TypeError} If arguments are invalid
88
- */
89
- Enum.fromJSON = function fromJSON(name, json) {
90
- var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
91
- enm.reserved = json.reserved;
92
- return enm;
93
- };
94
-
95
- /**
96
- * Converts this enum to an enum descriptor.
97
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
98
- * @returns {IEnum} Enum descriptor
99
- */
100
- Enum.prototype.toJSON = function toJSON(toJSONOptions) {
101
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
102
- return util.toObject([
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
109
- ]);
110
- };
111
-
112
- /**
113
- * Adds a value to this enum.
114
- * @param {string} name Value name
115
- * @param {number} id Value id
116
- * @param {string} [comment] Comment, if any
117
- * @param {Object.<string, *>|undefined} [options] Options, if any
118
- * @returns {Enum} `this`
119
- * @throws {TypeError} If arguments are invalid
120
- * @throws {Error} If there is already a value with this name or id
121
- */
122
- Enum.prototype.add = function add(name, id, comment, options) {
123
- // utilized by the parser but not by .fromJSON
124
-
125
- if (!util.isString(name))
126
- throw TypeError("name must be a string");
127
-
128
- if (!util.isInteger(id))
129
- throw TypeError("id must be an integer");
130
-
131
- if (this.values[name] !== undefined)
132
- throw Error("duplicate name '" + name + "' in " + this);
133
-
134
- if (this.isReservedId(id))
135
- throw Error("id " + id + " is reserved in " + this);
136
-
137
- if (this.isReservedName(name))
138
- throw Error("name '" + name + "' is reserved in " + this);
139
-
140
- if (this.valuesById[id] !== undefined) {
141
- if (!(this.options && this.options.allow_alias))
142
- throw Error("duplicate id " + id + " in " + this);
143
- this.values[name] = id;
144
- } else
145
- this.valuesById[this.values[name] = id] = name;
146
-
147
- if (options) {
148
- if (this.valuesOptions === undefined)
149
- this.valuesOptions = {};
150
- this.valuesOptions[name] = options || null;
151
- }
152
-
153
- this.comments[name] = comment || null;
154
- return this;
155
- };
156
-
157
- /**
158
- * Removes a value from this enum
159
- * @param {string} name Value name
160
- * @returns {Enum} `this`
161
- * @throws {TypeError} If arguments are invalid
162
- * @throws {Error} If `name` is not a name of this enum
163
- */
164
- Enum.prototype.remove = function remove(name) {
165
-
166
- if (!util.isString(name))
167
- throw TypeError("name must be a string");
168
-
169
- var val = this.values[name];
170
- if (val == null)
171
- throw Error("name '" + name + "' does not exist in " + this);
172
-
173
- delete this.valuesById[val];
174
- delete this.values[name];
175
- delete this.comments[name];
176
- if (this.valuesOptions)
177
- delete this.valuesOptions[name];
178
-
179
- return this;
180
- };
181
-
182
- /**
183
- * Tests if the specified id is reserved.
184
- * @param {number} id Id to test
185
- * @returns {boolean} `true` if reserved, otherwise `false`
186
- */
187
- Enum.prototype.isReservedId = function isReservedId(id) {
188
- return Namespace.isReservedId(this.reserved, id);
189
- };
190
-
191
- /**
192
- * Tests if the specified name is reserved.
193
- * @param {string} name Name to test
194
- * @returns {boolean} `true` if reserved, otherwise `false`
195
- */
196
- Enum.prototype.isReservedName = function isReservedName(name) {
197
- return Namespace.isReservedName(this.reserved, name);
198
- };
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
+ * Reserved ranges, if any.
61
+ * @type {Array.<number[]|string>}
62
+ */
63
+ this.reserved = undefined; // toJSON
64
+
65
+ // Note that values inherit valuesById on their prototype which makes them a TypeScript-
66
+ // compatible enum. This is used by pbts to write actual enum definitions that work for
67
+ // static and reflection code alike instead of emitting generic object definitions.
68
+
69
+ if (values)
70
+ for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
71
+ if (typeof values[keys[i]] === "number") // use forward entries only
72
+ this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
73
+ }
74
+
75
+ /**
76
+ * Enum descriptor.
77
+ * @interface IEnum
78
+ * @property {Object.<string,number>} values Enum values
79
+ * @property {Object.<string,*>} [options] Enum options
80
+ */
81
+
82
+ /**
83
+ * Constructs an enum from an enum descriptor.
84
+ * @param {string} name Enum name
85
+ * @param {IEnum} json Enum descriptor
86
+ * @returns {Enum} Created enum
87
+ * @throws {TypeError} If arguments are invalid
88
+ */
89
+ Enum.fromJSON = function fromJSON(name, json) {
90
+ var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
91
+ enm.reserved = json.reserved;
92
+ return enm;
93
+ };
94
+
95
+ /**
96
+ * Converts this enum to an enum descriptor.
97
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
98
+ * @returns {IEnum} Enum descriptor
99
+ */
100
+ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
101
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
102
+ return util.toObject([
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
109
+ ]);
110
+ };
111
+
112
+ /**
113
+ * Adds a value to this enum.
114
+ * @param {string} name Value name
115
+ * @param {number} id Value id
116
+ * @param {string} [comment] Comment, if any
117
+ * @param {Object.<string, *>|undefined} [options] Options, if any
118
+ * @returns {Enum} `this`
119
+ * @throws {TypeError} If arguments are invalid
120
+ * @throws {Error} If there is already a value with this name or id
121
+ */
122
+ Enum.prototype.add = function add(name, id, comment, options) {
123
+ // utilized by the parser but not by .fromJSON
124
+
125
+ if (!util.isString(name))
126
+ throw TypeError("name must be a string");
127
+
128
+ if (!util.isInteger(id))
129
+ throw TypeError("id must be an integer");
130
+
131
+ if (this.values[name] !== undefined)
132
+ throw Error("duplicate name '" + name + "' in " + this);
133
+
134
+ if (this.isReservedId(id))
135
+ throw Error("id " + id + " is reserved in " + this);
136
+
137
+ if (this.isReservedName(name))
138
+ throw Error("name '" + name + "' is reserved in " + this);
139
+
140
+ if (this.valuesById[id] !== undefined) {
141
+ if (!(this.options && this.options.allow_alias))
142
+ throw Error("duplicate id " + id + " in " + this);
143
+ this.values[name] = id;
144
+ } else
145
+ this.valuesById[this.values[name] = id] = name;
146
+
147
+ if (options) {
148
+ if (this.valuesOptions === undefined)
149
+ this.valuesOptions = {};
150
+ this.valuesOptions[name] = options || null;
151
+ }
152
+
153
+ this.comments[name] = comment || null;
154
+ return this;
155
+ };
156
+
157
+ /**
158
+ * Removes a value from this enum
159
+ * @param {string} name Value name
160
+ * @returns {Enum} `this`
161
+ * @throws {TypeError} If arguments are invalid
162
+ * @throws {Error} If `name` is not a name of this enum
163
+ */
164
+ Enum.prototype.remove = function remove(name) {
165
+
166
+ if (!util.isString(name))
167
+ throw TypeError("name must be a string");
168
+
169
+ var val = this.values[name];
170
+ if (val == null)
171
+ throw Error("name '" + name + "' does not exist in " + this);
172
+
173
+ delete this.valuesById[val];
174
+ delete this.values[name];
175
+ delete this.comments[name];
176
+ if (this.valuesOptions)
177
+ delete this.valuesOptions[name];
178
+
179
+ return this;
180
+ };
181
+
182
+ /**
183
+ * Tests if the specified id is reserved.
184
+ * @param {number} id Id to test
185
+ * @returns {boolean} `true` if reserved, otherwise `false`
186
+ */
187
+ Enum.prototype.isReservedId = function isReservedId(id) {
188
+ return Namespace.isReservedId(this.reserved, id);
189
+ };
190
+
191
+ /**
192
+ * Tests if the specified name is reserved.
193
+ * @param {string} name Name to test
194
+ * @returns {boolean} `true` if reserved, otherwise `false`
195
+ */
196
+ Enum.prototype.isReservedName = function isReservedName(name) {
197
+ return Namespace.isReservedName(this.reserved, name);
198
+ };