protobufjs 7.3.0 → 7.3.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 (77) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +727 -740
  3. package/dist/light/protobuf.js +6264 -6264
  4. package/dist/light/protobuf.js.map +1 -1
  5. package/dist/light/protobuf.min.js +2 -2
  6. package/dist/light/protobuf.min.js.map +1 -1
  7. package/dist/minimal/protobuf.js +1928 -1928
  8. package/dist/minimal/protobuf.js.map +1 -1
  9. package/dist/minimal/protobuf.min.js +2 -2
  10. package/dist/minimal/protobuf.min.js.map +1 -1
  11. package/dist/protobuf.js +7978 -7978
  12. package/dist/protobuf.js.map +1 -1
  13. package/dist/protobuf.min.js +2 -2
  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 +191 -191
  19. package/ext/descriptor/index.js +1052 -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 +738 -738
  30. package/google/protobuf/descriptor.proto +286 -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 +2741 -2741
  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 +111 -111
  42. package/scripts/postinstall.js +32 -32
  43. package/src/common.js +399 -399
  44. package/src/converter.js +301 -301
  45. package/src/decoder.js +129 -129
  46. package/src/encoder.js +100 -100
  47. package/src/enum.js +198 -198
  48. package/src/field.js +377 -377
  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 +138 -138
  54. package/src/method.js +160 -160
  55. package/src/namespace.js +433 -433
  56. package/src/object.js +243 -243
  57. package/src/oneof.js +203 -203
  58. package/src/parse.js +889 -889
  59. package/src/reader.js +416 -416
  60. package/src/reader_buffer.js +51 -51
  61. package/src/root.js +368 -368
  62. package/src/roots.js +18 -18
  63. package/src/rpc/service.js +142 -142
  64. package/src/rpc.js +36 -36
  65. package/src/service.js +167 -167
  66. package/src/tokenize.js +416 -416
  67. package/src/type.js +589 -589
  68. package/src/types.js +196 -196
  69. package/src/typescript.jsdoc +15 -15
  70. package/src/util/longbits.js +200 -200
  71. package/src/util/minimal.js +438 -438
  72. package/src/util.js +212 -212
  73. package/src/verifier.js +176 -176
  74. package/src/wrappers.js +102 -102
  75. package/src/writer.js +465 -465
  76. package/src/writer_buffer.js +85 -85
  77. package/tsconfig.json +7 -7
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
+ };