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/object.js CHANGED
@@ -1,330 +1,385 @@
1
- "use strict";
2
- module.exports = ReflectionObject;
3
-
4
- ReflectionObject.className = "ReflectionObject";
5
-
6
- const OneOf = require("./oneof");
7
- var util = require("./util");
8
-
9
- var Root, Namespace; // cyclic
10
-
11
- /* eslint-disable no-warning-comments */
12
- // TODO: Replace with embedded proto.
13
- var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
14
- var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
15
- var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
16
-
17
- /**
18
- * Constructs a new reflection object instance.
19
- * @classdesc Base class of all reflection objects.
20
- * @constructor
21
- * @param {string} name Object name
22
- * @param {Object.<string,*>} [options] Declared options
23
- * @abstract
24
- */
25
- function ReflectionObject(name, options) {
26
-
27
- if (!util.isString(name))
28
- throw TypeError("name must be a string");
29
-
30
- if (options && !util.isObject(options))
31
- throw TypeError("options must be an object");
32
-
33
- /**
34
- * Options.
35
- * @type {Object.<string,*>|undefined}
36
- */
37
- this.options = options; // toJSON
38
-
39
- /**
40
- * Parsed Options.
41
- * @type {Array.<Object.<string,*>>|undefined}
42
- */
43
- this.parsedOptions = null;
44
-
45
- /**
46
- * Unique name within its namespace.
47
- * @type {string}
48
- */
49
- this.name = name;
50
-
51
- /**
52
- * Resolved Features.
53
- */
54
- this._features = {};
55
-
56
- /**
57
- * Unresolved Features.
58
- */
59
- this._protoFeatures = null;
60
-
61
- /**
62
- * Parent namespace.
63
- * @type {Namespace|null}
64
- */
65
- this.parent = null;
66
-
67
- /**
68
- * Whether already resolved or not.
69
- * @type {boolean}
70
- */
71
- this.resolved = false;
72
-
73
- /**
74
- * Comment text, if any.
75
- * @type {string|null}
76
- */
77
- this.comment = null;
78
-
79
- /**
80
- * Defining file name.
81
- * @type {string|null}
82
- */
83
- this.filename = null;
84
- }
85
-
86
- Object.defineProperties(ReflectionObject.prototype, {
87
-
88
- /**
89
- * Reference to the root namespace.
90
- * @name ReflectionObject#root
91
- * @type {Root}
92
- * @readonly
93
- */
94
- root: {
95
- get: function() {
96
- var ptr = this;
97
- while (ptr.parent !== null)
98
- ptr = ptr.parent;
99
- return ptr;
100
- }
101
- },
102
-
103
- /**
104
- * Full name including leading dot.
105
- * @name ReflectionObject#fullName
106
- * @type {string}
107
- * @readonly
108
- */
109
- fullName: {
110
- get: function() {
111
- var path = [ this.name ],
112
- ptr = this.parent;
113
- while (ptr) {
114
- path.unshift(ptr.name);
115
- ptr = ptr.parent;
116
- }
117
- return path.join(".");
118
- }
119
- }
120
- });
121
-
122
- /**
123
- * Converts this reflection object to its descriptor representation.
124
- * @returns {Object.<string,*>} Descriptor
125
- * @abstract
126
- */
127
- ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
128
- throw Error(); // not implemented, shouldn't happen
129
- };
130
-
131
- /**
132
- * Called when this object is added to a parent.
133
- * @param {ReflectionObject} parent Parent added to
134
- * @returns {undefined}
135
- */
136
- ReflectionObject.prototype.onAdd = function onAdd(parent) {
137
- if (this.parent && this.parent !== parent)
138
- this.parent.remove(this);
139
- this.parent = parent;
140
- this.resolved = false;
141
- var root = parent.root;
142
- if (root instanceof Root)
143
- root._handleAdd(this);
144
- };
145
-
146
- /**
147
- * Called when this object is removed from a parent.
148
- * @param {ReflectionObject} parent Parent removed from
149
- * @returns {undefined}
150
- */
151
- ReflectionObject.prototype.onRemove = function onRemove(parent) {
152
- var root = parent.root;
153
- if (root instanceof Root)
154
- root._handleRemove(this);
155
- this.parent = null;
156
- this.resolved = false;
157
- };
158
-
159
- /**
160
- * Resolves this objects type references.
161
- * @returns {ReflectionObject} `this`
162
- */
163
- ReflectionObject.prototype.resolve = function resolve() {
164
- if (this.resolved)
165
- return this;
166
- var edition = this.getOption("edition");
167
- if ((this instanceof Namespace && edition) || (this.parent && this.parent.resolved)) {
168
- this._resolveFeatures();
169
- this.resolved = true;
170
- }
171
- return this;
172
- };
173
-
174
- /**
175
- * Resolves child features from parent features
176
- * @returns {undefined}
177
- */
178
- ReflectionObject.prototype._resolveFeatures = function _resolveFeatures() {
179
- var defaults = {};
180
-
181
- var protoFeatures = Object.assign(Object.assign({}, this._protoFeatures), this._inferLegacyProtoFeatures(edition));
182
-
183
- var edition = this.getOption("edition");
184
- if (this instanceof Namespace && edition) {
185
- // For a namespace marked with a specific edition, reset defaults.
186
- if (edition === "proto2") {
187
- defaults = Object.assign({}, proto2Defaults);
188
- } else if (edition === "proto3") {
189
- defaults = Object.assign({}, proto3Defaults);
190
- } else if (edition === "2023") {
191
- defaults = Object.assign({}, editions2023Defaults);
192
- } else {
193
- throw new Error("Unknown edition: " + edition);
194
- }
195
- this._features = Object.assign(defaults, protoFeatures || {});
196
- return;
197
- }
198
-
199
- // fields in Oneofs aren't actually children of them, so we have to
200
- // special-case it
201
- if (this.partOf instanceof OneOf) {
202
- var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
203
- this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
204
- } else if (this.declaringField) {
205
- // Skip feature resolution of sister fields.
206
- } else if (this.parent) {
207
- var parentFeaturesCopy = Object.assign({}, this.parent._features);
208
- this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
209
- } else {
210
- this._features = Object.assign({}, protoFeatures);
211
- }
212
- if (this.extensionField) {
213
- // Sister fields should have the same features as their extensions.
214
- this.extensionField._features = this._features;
215
- }
216
- };
217
-
218
- /**
219
- * Infers features from legacy syntax that may have been specified differently.
220
- * in older editions.
221
- * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
222
- * @returns {object} The feature values to override
223
- * @abstract
224
- */
225
- ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
226
- return {};
227
- };
228
-
229
- /**
230
- * Gets an option value.
231
- * @param {string} name Option name
232
- * @returns {*} Option value or `undefined` if not set
233
- */
234
- ReflectionObject.prototype.getOption = function getOption(name) {
235
- if (this.options)
236
- return this.options[name];
237
- return undefined;
238
- };
239
-
240
- /**
241
- * Sets an option.
242
- * @param {string} name Option name
243
- * @param {*} value Option value
244
- * @param {boolean} [ifNotSet] Sets the option only if it isn't currently set
245
- * @returns {ReflectionObject} `this`
246
- */
247
- ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
248
- if (!ifNotSet || !this.options || this.options[name] === undefined) {
249
- if (this.getOption(name) !== value) this.resolved = false;
250
- (this.options || (this.options = {}))[name] = value;
251
- }
252
- return this;
253
- };
254
-
255
- /**
256
- * Sets a parsed option.
257
- * @param {string} name parsed Option name
258
- * @param {*} value Option value
259
- * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
260
- * @returns {ReflectionObject} `this`
261
- */
262
- ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
263
- if (!this.parsedOptions) {
264
- this.parsedOptions = [];
265
- }
266
- var isFeature = /^features$/.test(name);
267
- var parsedOptions = this.parsedOptions;
268
- if (propName) {
269
- // If setting a sub property of an option then try to merge it
270
- // with an existing option
271
- var opt = parsedOptions.find(function (opt) {
272
- return Object.prototype.hasOwnProperty.call(opt, name);
273
- });
274
- if (opt) {
275
- // If we found an existing option - just merge the property value
276
- // (If it's a feature, will just write over)
277
- var newValue = opt[name];
278
- util.setProperty(newValue, propName, value);
279
- } else {
280
- // otherwise, create a new option, set its property and add it to the list
281
- opt = {};
282
- opt[name] = util.setProperty({}, propName, value);
283
- parsedOptions.push(opt);
284
- }
285
- } else {
286
- // Always create a new option when setting the value of the option itself
287
- var newOpt = {};
288
- newOpt[name] = value;
289
- parsedOptions.push(newOpt);
290
- }
291
-
292
-
293
- if (isFeature) {
294
- var features = parsedOptions.find(x => {return Object.prototype.hasOwnProperty.call(x, "features");});
295
- this._protoFeatures = features.features || {};
296
- }
297
-
298
- return this;
299
- };
300
-
301
- /**
302
- * Sets multiple options.
303
- * @param {Object.<string,*>} options Options to set
304
- * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
305
- * @returns {ReflectionObject} `this`
306
- */
307
- ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
308
- if (options)
309
- for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
310
- this.setOption(keys[i], options[keys[i]], ifNotSet);
311
- return this;
312
- };
313
-
314
- /**
315
- * Converts this instance to its string representation.
316
- * @returns {string} Class name[, space, full name]
317
- */
318
- ReflectionObject.prototype.toString = function toString() {
319
- var className = this.constructor.className,
320
- fullName = this.fullName;
321
- if (fullName.length)
322
- return className + " " + fullName;
323
- return className;
324
- };
325
-
326
- // Sets up cyclic dependencies (called in index-light)
327
- ReflectionObject._configure = function(Root_, Namespace_) {
328
- Root = Root_;
329
- Namespace = Namespace_;
330
- };
1
+ "use strict";
2
+ module.exports = ReflectionObject;
3
+
4
+ ReflectionObject.className = "ReflectionObject";
5
+
6
+ const OneOf = require("./oneof");
7
+ var util = require("./util");
8
+
9
+ var Root; // cyclic
10
+
11
+ /* eslint-disable no-warning-comments */
12
+ // TODO: Replace with embedded proto.
13
+ var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
14
+ var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
15
+ var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
16
+ var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
17
+
18
+ /**
19
+ * Constructs a new reflection object instance.
20
+ * @classdesc Base class of all reflection objects.
21
+ * @constructor
22
+ * @param {string} name Object name
23
+ * @param {Object.<string,*>} [options] Declared options
24
+ * @abstract
25
+ */
26
+ function ReflectionObject(name, options) {
27
+
28
+ if (!util.isString(name))
29
+ throw TypeError("name must be a string");
30
+
31
+ if (options && !util.isObject(options))
32
+ throw TypeError("options must be an object");
33
+
34
+ /**
35
+ * Options.
36
+ * @type {Object.<string,*>|undefined}
37
+ */
38
+ this.options = options; // toJSON
39
+
40
+ /**
41
+ * Parsed Options.
42
+ * @type {Array.<Object.<string,*>>|undefined}
43
+ */
44
+ this.parsedOptions = null;
45
+
46
+ /**
47
+ * Unique name within its namespace.
48
+ * @type {string}
49
+ */
50
+ this.name = name;
51
+
52
+ /**
53
+ * The edition specified for this object. Only relevant for top-level objects.
54
+ * @type {string}
55
+ * @private
56
+ */
57
+ this._edition = null;
58
+
59
+ /**
60
+ * The default edition to use for this object if none is specified. For legacy reasons,
61
+ * this is proto2 except in the JSON parsing case where it was proto3.
62
+ * @type {string}
63
+ * @private
64
+ */
65
+ this._defaultEdition = "proto2";
66
+
67
+ /**
68
+ * Resolved Features.
69
+ * @type {object}
70
+ * @private
71
+ */
72
+ this._features = {};
73
+
74
+ /**
75
+ * Whether or not features have been resolved.
76
+ * @type {boolean}
77
+ * @private
78
+ */
79
+ this._featuresResolved = false;
80
+
81
+ /**
82
+ * Parent namespace.
83
+ * @type {Namespace|null}
84
+ */
85
+ this.parent = null;
86
+
87
+ /**
88
+ * Whether already resolved or not.
89
+ * @type {boolean}
90
+ */
91
+ this.resolved = false;
92
+
93
+ /**
94
+ * Comment text, if any.
95
+ * @type {string|null}
96
+ */
97
+ this.comment = null;
98
+
99
+ /**
100
+ * Defining file name.
101
+ * @type {string|null}
102
+ */
103
+ this.filename = null;
104
+ }
105
+
106
+ Object.defineProperties(ReflectionObject.prototype, {
107
+
108
+ /**
109
+ * Reference to the root namespace.
110
+ * @name ReflectionObject#root
111
+ * @type {Root}
112
+ * @readonly
113
+ */
114
+ root: {
115
+ get: function() {
116
+ var ptr = this;
117
+ while (ptr.parent !== null)
118
+ ptr = ptr.parent;
119
+ return ptr;
120
+ }
121
+ },
122
+
123
+ /**
124
+ * Full name including leading dot.
125
+ * @name ReflectionObject#fullName
126
+ * @type {string}
127
+ * @readonly
128
+ */
129
+ fullName: {
130
+ get: function() {
131
+ var path = [ this.name ],
132
+ ptr = this.parent;
133
+ while (ptr) {
134
+ path.unshift(ptr.name);
135
+ ptr = ptr.parent;
136
+ }
137
+ return path.join(".");
138
+ }
139
+ }
140
+ });
141
+
142
+ /**
143
+ * Converts this reflection object to its descriptor representation.
144
+ * @returns {Object.<string,*>} Descriptor
145
+ * @abstract
146
+ */
147
+ ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
148
+ throw Error(); // not implemented, shouldn't happen
149
+ };
150
+
151
+ /**
152
+ * Called when this object is added to a parent.
153
+ * @param {ReflectionObject} parent Parent added to
154
+ * @returns {undefined}
155
+ */
156
+ ReflectionObject.prototype.onAdd = function onAdd(parent) {
157
+ if (this.parent && this.parent !== parent)
158
+ this.parent.remove(this);
159
+ this.parent = parent;
160
+ this.resolved = false;
161
+ var root = parent.root;
162
+ if (root instanceof Root)
163
+ root._handleAdd(this);
164
+ };
165
+
166
+ /**
167
+ * Called when this object is removed from a parent.
168
+ * @param {ReflectionObject} parent Parent removed from
169
+ * @returns {undefined}
170
+ */
171
+ ReflectionObject.prototype.onRemove = function onRemove(parent) {
172
+ var root = parent.root;
173
+ if (root instanceof Root)
174
+ root._handleRemove(this);
175
+ this.parent = null;
176
+ this.resolved = false;
177
+ };
178
+
179
+ /**
180
+ * Resolves this objects type references.
181
+ * @returns {ReflectionObject} `this`
182
+ */
183
+ ReflectionObject.prototype.resolve = function resolve() {
184
+ if (this.resolved)
185
+ return this;
186
+ if (this.root instanceof Root)
187
+ this.resolved = true; // only if part of a root
188
+ return this;
189
+ };
190
+
191
+ /**
192
+ * Resolves this objects editions features.
193
+ * @param {string} edition The edition we're currently resolving for.
194
+ * @returns {ReflectionObject} `this`
195
+ */
196
+ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
197
+ return this._resolveFeatures(this._edition || edition);
198
+ };
199
+
200
+ /**
201
+ * Resolves child features from parent features
202
+ * @param {string} edition The edition we're currently resolving for.
203
+ * @returns {undefined}
204
+ */
205
+ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
206
+ if (this._featuresResolved) {
207
+ return;
208
+ }
209
+
210
+ var defaults = {};
211
+
212
+ /* istanbul ignore if */
213
+ if (!edition) {
214
+ throw new Error("Unknown edition for " + this.fullName);
215
+ }
216
+
217
+ var protoFeatures = Object.assign(this.options ? Object.assign({}, this.options.features) : {},
218
+ this._inferLegacyProtoFeatures(edition));
219
+
220
+ if (this._edition) {
221
+ // For a namespace marked with a specific edition, reset defaults.
222
+ /* istanbul ignore else */
223
+ if (edition === "proto2") {
224
+ defaults = Object.assign({}, proto2Defaults);
225
+ } else if (edition === "proto3") {
226
+ defaults = Object.assign({}, proto3Defaults);
227
+ } else if (edition === "2023") {
228
+ defaults = Object.assign({}, editions2023Defaults);
229
+ } else if (edition === "2024") {
230
+ defaults = Object.assign({}, editions2024Defaults);
231
+ } else {
232
+ throw new Error("Unknown edition: " + edition);
233
+ }
234
+ this._features = Object.assign(defaults, protoFeatures || {});
235
+ this._featuresResolved = true;
236
+ return;
237
+ }
238
+
239
+ // fields in Oneofs aren't actually children of them, so we have to
240
+ // special-case it
241
+ /* istanbul ignore else */
242
+ if (this.partOf instanceof OneOf) {
243
+ var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
244
+ this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
245
+ } else if (this.declaringField) {
246
+ // Skip feature resolution of sister fields.
247
+ } else if (this.parent) {
248
+ var parentFeaturesCopy = Object.assign({}, this.parent._features);
249
+ this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
250
+ } else {
251
+ throw new Error("Unable to find a parent for " + this.fullName);
252
+ }
253
+ if (this.extensionField) {
254
+ // Sister fields should have the same features as their extensions.
255
+ this.extensionField._features = this._features;
256
+ }
257
+ this._featuresResolved = true;
258
+ };
259
+
260
+ /**
261
+ * Infers features from legacy syntax that may have been specified differently.
262
+ * in older editions.
263
+ * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
264
+ * @returns {object} The feature values to override
265
+ */
266
+ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
267
+ return {};
268
+ };
269
+
270
+ /**
271
+ * Gets an option value.
272
+ * @param {string} name Option name
273
+ * @returns {*} Option value or `undefined` if not set
274
+ */
275
+ ReflectionObject.prototype.getOption = function getOption(name) {
276
+ if (this.options)
277
+ return this.options[name];
278
+ return undefined;
279
+ };
280
+
281
+ /**
282
+ * Sets an option.
283
+ * @param {string} name Option name
284
+ * @param {*} value Option value
285
+ * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
286
+ * @returns {ReflectionObject} `this`
287
+ */
288
+ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
289
+ if (name === "__proto__")
290
+ return this;
291
+ if (!this.options)
292
+ this.options = {};
293
+ if (/^features\./.test(name)) {
294
+ util.setProperty(this.options, name, value, ifNotSet);
295
+ } else if (!ifNotSet || this.options[name] === undefined) {
296
+ if (this.getOption(name) !== value) this.resolved = false;
297
+ this.options[name] = value;
298
+ }
299
+
300
+ return this;
301
+ };
302
+
303
+ /**
304
+ * Sets a parsed option.
305
+ * @param {string} name parsed Option name
306
+ * @param {*} value Option value
307
+ * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
308
+ * @returns {ReflectionObject} `this`
309
+ */
310
+ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
311
+ if (name === "__proto__")
312
+ return this;
313
+ if (!this.parsedOptions) {
314
+ this.parsedOptions = [];
315
+ }
316
+ var parsedOptions = this.parsedOptions;
317
+ if (propName) {
318
+ // If setting a sub property of an option then try to merge it
319
+ // with an existing option
320
+ var opt = parsedOptions.find(function (opt) {
321
+ return Object.prototype.hasOwnProperty.call(opt, name);
322
+ });
323
+ if (opt) {
324
+ // If we found an existing option - just merge the property value
325
+ // (If it's a feature, will just write over)
326
+ var newValue = opt[name];
327
+ util.setProperty(newValue, propName, value);
328
+ } else {
329
+ // otherwise, create a new option, set its property and add it to the list
330
+ opt = {};
331
+ opt[name] = util.setProperty({}, propName, value);
332
+ parsedOptions.push(opt);
333
+ }
334
+ } else {
335
+ // Always create a new option when setting the value of the option itself
336
+ var newOpt = {};
337
+ newOpt[name] = value;
338
+ parsedOptions.push(newOpt);
339
+ }
340
+
341
+ return this;
342
+ };
343
+
344
+ /**
345
+ * Sets multiple options.
346
+ * @param {Object.<string,*>} options Options to set
347
+ * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
348
+ * @returns {ReflectionObject} `this`
349
+ */
350
+ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
351
+ if (options)
352
+ for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
353
+ this.setOption(keys[i], options[keys[i]], ifNotSet);
354
+ return this;
355
+ };
356
+
357
+ /**
358
+ * Converts this instance to its string representation.
359
+ * @returns {string} Class name[, space, full name]
360
+ */
361
+ ReflectionObject.prototype.toString = function toString() {
362
+ var className = this.constructor.className,
363
+ fullName = this.fullName;
364
+ if (fullName.length)
365
+ return className + " " + fullName;
366
+ return className;
367
+ };
368
+
369
+ /**
370
+ * Converts the edition this object is pinned to for JSON format.
371
+ * @returns {string|undefined} The edition string for JSON representation
372
+ */
373
+ ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
374
+ if (!this._edition || this._edition === "proto3") {
375
+ // Avoid emitting proto3 since we need to default to it for backwards
376
+ // compatibility anyway.
377
+ return undefined;
378
+ }
379
+ return this._edition;
380
+ };
381
+
382
+ // Sets up cyclic dependencies (called in index-light)
383
+ ReflectionObject._configure = function(Root_) {
384
+ Root = Root_;
385
+ };