protobufjs 8.6.0 → 8.6.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 (108) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +441 -441
  3. package/dist/light/protobuf.js +8473 -8516
  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 +3018 -3061
  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 +10376 -10419
  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/README.md +70 -70
  16. package/ext/debug/README.md +4 -4
  17. package/ext/debug/index.js +71 -71
  18. package/ext/descriptor/README.md +5 -5
  19. package/ext/descriptor/index.d.ts +2 -2
  20. package/ext/descriptor/index.js +2 -2
  21. package/ext/descriptor.d.ts +87 -86
  22. package/ext/descriptor.generated.d.ts +14 -6
  23. package/ext/descriptor.js +1354 -1303
  24. package/ext/protojson.LICENSE +201 -201
  25. package/ext/protojson.d.ts +20 -20
  26. package/ext/protojson.js +925 -903
  27. package/ext/textformat.d.ts +19 -19
  28. package/ext/textformat.js +1256 -1256
  29. package/google/LICENSE +27 -27
  30. package/google/README.md +1 -1
  31. package/google/api/annotations.json +82 -82
  32. package/google/api/annotations.proto +10 -10
  33. package/google/api/http.json +85 -85
  34. package/google/api/http.proto +30 -30
  35. package/google/protobuf/api.json +117 -117
  36. package/google/protobuf/api.proto +33 -33
  37. package/google/protobuf/compiler/plugin.json +126 -126
  38. package/google/protobuf/compiler/plugin.proto +47 -47
  39. package/google/protobuf/descriptor.json +1381 -1381
  40. package/google/protobuf/descriptor.proto +534 -534
  41. package/google/protobuf/source_context.json +19 -19
  42. package/google/protobuf/source_context.proto +7 -7
  43. package/google/protobuf/type.json +201 -201
  44. package/google/protobuf/type.proto +89 -89
  45. package/index.d.ts +10 -18
  46. package/index.js +4 -4
  47. package/light.d.ts +2 -2
  48. package/light.js +3 -3
  49. package/minimal.d.ts +2 -2
  50. package/minimal.js +4 -4
  51. package/package.json +93 -93
  52. package/src/common.js +399 -399
  53. package/src/converter.js +344 -344
  54. package/src/decoder.js +208 -208
  55. package/src/encoder.js +111 -111
  56. package/src/enum.js +231 -231
  57. package/src/field.js +497 -497
  58. package/src/index-light.js +104 -104
  59. package/src/index-minimal.js +36 -36
  60. package/src/index.js +12 -12
  61. package/src/mapfield.js +136 -136
  62. package/src/message.js +137 -137
  63. package/src/method.js +175 -175
  64. package/src/namespace.js +565 -565
  65. package/src/object.js +382 -382
  66. package/src/oneof.js +225 -225
  67. package/src/parse.js +1068 -1068
  68. package/src/reader.js +543 -543
  69. package/src/reader_buffer.js +72 -72
  70. package/src/root.js +416 -416
  71. package/src/roots.js +18 -18
  72. package/src/rpc/service.js +148 -148
  73. package/src/rpc.js +36 -36
  74. package/src/service.js +198 -198
  75. package/src/tokenize.js +421 -421
  76. package/src/type.js +655 -655
  77. package/src/types.js +196 -196
  78. package/src/typescript.js +25 -25
  79. package/src/util/aspromise.d.ts +13 -13
  80. package/src/util/aspromise.js +52 -52
  81. package/src/util/base64.d.ts +32 -32
  82. package/src/util/base64.js +146 -146
  83. package/src/util/codegen.d.ts +31 -31
  84. package/src/util/codegen.js +113 -113
  85. package/src/util/eventemitter.d.ts +45 -45
  86. package/src/util/eventemitter.js +86 -86
  87. package/src/util/fetch.d.ts +56 -56
  88. package/src/util/fetch.js +112 -112
  89. package/src/util/float.d.ts +83 -83
  90. package/src/util/float.js +335 -335
  91. package/src/util/fs.js +11 -11
  92. package/src/util/longbits.js +200 -200
  93. package/src/util/minimal.js +515 -518
  94. package/src/util/path.d.ts +22 -22
  95. package/src/util/path.js +72 -72
  96. package/src/util/patterns.js +7 -7
  97. package/src/util/pool.d.ts +32 -32
  98. package/src/util/pool.js +48 -48
  99. package/src/util/utf8.d.ts +24 -24
  100. package/src/util/utf8.js +130 -130
  101. package/src/util.js +242 -242
  102. package/src/verifier.js +180 -180
  103. package/src/wrappers.js +106 -106
  104. package/src/writer.js +495 -495
  105. package/src/writer_buffer.js +102 -102
  106. package/tsconfig.json +6 -6
  107. package/src/util/inquire.d.ts +0 -10
  108. package/src/util/inquire.js +0 -38
package/src/object.js CHANGED
@@ -1,382 +1,382 @@
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
- */
146
- ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
147
- throw Error(); // not implemented, shouldn't happen
148
- };
149
-
150
- /**
151
- * Called when this object is added to a parent.
152
- * @param {ReflectionObject} parent Parent added to
153
- * @returns {undefined}
154
- */
155
- ReflectionObject.prototype.onAdd = function onAdd(parent) {
156
- if (this.parent && this.parent !== parent)
157
- this.parent.remove(this);
158
- this.parent = parent;
159
- this.resolved = false;
160
- var root = parent.root;
161
- if (root instanceof Root)
162
- root._handleAdd(this);
163
- };
164
-
165
- /**
166
- * Called when this object is removed from a parent.
167
- * @param {ReflectionObject} parent Parent removed from
168
- * @returns {undefined}
169
- */
170
- ReflectionObject.prototype.onRemove = function onRemove(parent) {
171
- var root = parent.root;
172
- if (root instanceof Root)
173
- root._handleRemove(this);
174
- this.parent = null;
175
- this.resolved = false;
176
- };
177
-
178
- /**
179
- * Resolves this objects type references.
180
- * @returns {ReflectionObject} `this`
181
- */
182
- ReflectionObject.prototype.resolve = function resolve() {
183
- if (this.resolved)
184
- return this;
185
- if (this.root instanceof Root)
186
- this.resolved = true; // only if part of a root
187
- return this;
188
- };
189
-
190
- /**
191
- * Resolves this objects editions features.
192
- * @param {string} edition The edition we're currently resolving for.
193
- * @returns {ReflectionObject} `this`
194
- */
195
- ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
196
- return this._resolveFeatures(this._edition || edition);
197
- };
198
-
199
- /**
200
- * Resolves child features from parent features
201
- * @param {string} edition The edition we're currently resolving for.
202
- * @returns {undefined}
203
- */
204
- ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
205
- if (this._featuresResolved) {
206
- return;
207
- }
208
-
209
- var defaults = {};
210
-
211
- /* istanbul ignore if */
212
- if (!edition) {
213
- throw new Error("Unknown edition for " + this.fullName);
214
- }
215
-
216
- var protoFeatures = util.merge({}, this.options && this.options.features,
217
- this._inferLegacyProtoFeatures(edition));
218
-
219
- if (this._edition) {
220
- // For a namespace marked with a specific edition, reset defaults.
221
- /* istanbul ignore else */
222
- if (edition === "proto2") {
223
- defaults = Object.assign({}, proto2Defaults);
224
- } else if (edition === "proto3") {
225
- defaults = Object.assign({}, proto3Defaults);
226
- } else if (edition === "2023") {
227
- defaults = Object.assign({}, editions2023Defaults);
228
- } else if (edition === "2024") {
229
- defaults = Object.assign({}, editions2024Defaults);
230
- } else {
231
- throw new Error("Unknown edition: " + edition);
232
- }
233
- this._features = util.merge(defaults, protoFeatures);
234
- } else {
235
- // fields in Oneofs aren't actually children of them, so we have to
236
- // special-case it
237
- /* istanbul ignore else */
238
- if (this.partOf instanceof OneOf) {
239
- var lexicalParentFeaturesCopy = util.merge({}, this.partOf._features);
240
- this._features = util.merge(lexicalParentFeaturesCopy, protoFeatures);
241
- } else if (this.declaringField) {
242
- // Skip feature resolution of sister fields.
243
- } else if (this.parent) {
244
- var parentFeaturesCopy = util.merge({}, this.parent._features);
245
- this._features = util.merge(parentFeaturesCopy, protoFeatures);
246
- } else {
247
- throw new Error("Unable to find a parent for " + this.fullName);
248
- }
249
- }
250
- if (this.extensionField) {
251
- // Sister fields should have the same features as their extensions.
252
- this.extensionField._features = this._features;
253
- }
254
- this._featuresResolved = true;
255
- };
256
-
257
- /**
258
- * Infers features from legacy syntax that may have been specified differently.
259
- * in older editions.
260
- * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
261
- * @returns {object} The feature values to override
262
- */
263
- ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
264
- return {};
265
- };
266
-
267
- /**
268
- * Gets an option value.
269
- * @param {string} name Option name
270
- * @returns {*} Option value or `undefined` if not set
271
- */
272
- ReflectionObject.prototype.getOption = function getOption(name) {
273
- if (this.options)
274
- return this.options[name];
275
- return undefined;
276
- };
277
-
278
- /**
279
- * Sets an option.
280
- * @param {string} name Option name
281
- * @param {*} value Option value
282
- * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
283
- * @returns {ReflectionObject} `this`
284
- */
285
- ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
286
- if (name === "__proto__")
287
- return this;
288
- if (!this.options)
289
- this.options = {};
290
- if (/^features\./.test(name)) {
291
- util.setProperty(this.options, name, value, ifNotSet);
292
- } else if (!ifNotSet || this.options[name] === undefined) {
293
- if (this.getOption(name) !== value) this.resolved = false;
294
- this.options[name] = value;
295
- }
296
-
297
- return this;
298
- };
299
-
300
- /**
301
- * Sets a parsed option.
302
- * @param {string} name parsed Option name
303
- * @param {*} value Option value
304
- * @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
305
- * @returns {ReflectionObject} `this`
306
- */
307
- ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
308
- if (name === "__proto__")
309
- return this;
310
- if (!this.parsedOptions) {
311
- this.parsedOptions = [];
312
- }
313
- var parsedOptions = this.parsedOptions;
314
- if (propName) {
315
- // If setting a sub property of an option then try to merge it
316
- // with an existing option
317
- var opt = parsedOptions.find(function (opt) {
318
- return Object.prototype.hasOwnProperty.call(opt, name);
319
- });
320
- if (opt) {
321
- // If we found an existing option - just merge the property value
322
- // (If it's a feature, will just write over)
323
- var newValue = opt[name];
324
- util.setProperty(newValue, propName, value);
325
- } else {
326
- // otherwise, create a new option, set its property and add it to the list
327
- opt = {};
328
- opt[name] = util.setProperty({}, propName, value);
329
- parsedOptions.push(opt);
330
- }
331
- } else {
332
- // Always create a new option when setting the value of the option itself
333
- var newOpt = {};
334
- newOpt[name] = value;
335
- parsedOptions.push(newOpt);
336
- }
337
-
338
- return this;
339
- };
340
-
341
- /**
342
- * Sets multiple options.
343
- * @param {Object.<string,*>} options Options to set
344
- * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
345
- * @returns {ReflectionObject} `this`
346
- */
347
- ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
348
- if (options)
349
- for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
350
- this.setOption(keys[i], options[keys[i]], ifNotSet);
351
- return this;
352
- };
353
-
354
- /**
355
- * Converts this instance to its string representation.
356
- * @returns {string} Class name[, space, full name]
357
- */
358
- ReflectionObject.prototype.toString = function toString() {
359
- var className = this.constructor.className,
360
- fullName = this.fullName;
361
- if (fullName.length)
362
- return className + " " + fullName;
363
- return className;
364
- };
365
-
366
- /**
367
- * Converts the edition this object is pinned to for JSON format.
368
- * @returns {string|undefined} The edition string for JSON representation
369
- */
370
- ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
371
- if (!this._edition || this._edition === "proto3") {
372
- // Avoid emitting proto3 since we need to default to it for backwards
373
- // compatibility anyway.
374
- return undefined;
375
- }
376
- return this._edition;
377
- };
378
-
379
- // Sets up cyclic dependencies (called in index-light)
380
- ReflectionObject._configure = function(Root_) {
381
- Root = Root_;
382
- };
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
+ */
146
+ ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
147
+ throw Error(); // not implemented, shouldn't happen
148
+ };
149
+
150
+ /**
151
+ * Called when this object is added to a parent.
152
+ * @param {ReflectionObject} parent Parent added to
153
+ * @returns {undefined}
154
+ */
155
+ ReflectionObject.prototype.onAdd = function onAdd(parent) {
156
+ if (this.parent && this.parent !== parent)
157
+ this.parent.remove(this);
158
+ this.parent = parent;
159
+ this.resolved = false;
160
+ var root = parent.root;
161
+ if (root instanceof Root)
162
+ root._handleAdd(this);
163
+ };
164
+
165
+ /**
166
+ * Called when this object is removed from a parent.
167
+ * @param {ReflectionObject} parent Parent removed from
168
+ * @returns {undefined}
169
+ */
170
+ ReflectionObject.prototype.onRemove = function onRemove(parent) {
171
+ var root = parent.root;
172
+ if (root instanceof Root)
173
+ root._handleRemove(this);
174
+ this.parent = null;
175
+ this.resolved = false;
176
+ };
177
+
178
+ /**
179
+ * Resolves this objects type references.
180
+ * @returns {ReflectionObject} `this`
181
+ */
182
+ ReflectionObject.prototype.resolve = function resolve() {
183
+ if (this.resolved)
184
+ return this;
185
+ if (this.root instanceof Root)
186
+ this.resolved = true; // only if part of a root
187
+ return this;
188
+ };
189
+
190
+ /**
191
+ * Resolves this objects editions features.
192
+ * @param {string} edition The edition we're currently resolving for.
193
+ * @returns {ReflectionObject} `this`
194
+ */
195
+ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
196
+ return this._resolveFeatures(this._edition || edition);
197
+ };
198
+
199
+ /**
200
+ * Resolves child features from parent features
201
+ * @param {string} edition The edition we're currently resolving for.
202
+ * @returns {undefined}
203
+ */
204
+ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
205
+ if (this._featuresResolved) {
206
+ return;
207
+ }
208
+
209
+ var defaults = {};
210
+
211
+ /* istanbul ignore if */
212
+ if (!edition) {
213
+ throw new Error("Unknown edition for " + this.fullName);
214
+ }
215
+
216
+ var protoFeatures = util.merge({}, this.options && this.options.features,
217
+ this._inferLegacyProtoFeatures(edition));
218
+
219
+ if (this._edition) {
220
+ // For a namespace marked with a specific edition, reset defaults.
221
+ /* istanbul ignore else */
222
+ if (edition === "proto2") {
223
+ defaults = Object.assign({}, proto2Defaults);
224
+ } else if (edition === "proto3") {
225
+ defaults = Object.assign({}, proto3Defaults);
226
+ } else if (edition === "2023") {
227
+ defaults = Object.assign({}, editions2023Defaults);
228
+ } else if (edition === "2024") {
229
+ defaults = Object.assign({}, editions2024Defaults);
230
+ } else {
231
+ throw new Error("Unknown edition: " + edition);
232
+ }
233
+ this._features = util.merge(defaults, protoFeatures);
234
+ } else {
235
+ // fields in Oneofs aren't actually children of them, so we have to
236
+ // special-case it
237
+ /* istanbul ignore else */
238
+ if (this.partOf instanceof OneOf) {
239
+ var lexicalParentFeaturesCopy = util.merge({}, this.partOf._features);
240
+ this._features = util.merge(lexicalParentFeaturesCopy, protoFeatures);
241
+ } else if (this.declaringField) {
242
+ // Skip feature resolution of sister fields.
243
+ } else if (this.parent) {
244
+ var parentFeaturesCopy = util.merge({}, this.parent._features);
245
+ this._features = util.merge(parentFeaturesCopy, protoFeatures);
246
+ } else {
247
+ throw new Error("Unable to find a parent for " + this.fullName);
248
+ }
249
+ }
250
+ if (this.extensionField) {
251
+ // Sister fields should have the same features as their extensions.
252
+ this.extensionField._features = this._features;
253
+ }
254
+ this._featuresResolved = true;
255
+ };
256
+
257
+ /**
258
+ * Infers features from legacy syntax that may have been specified differently.
259
+ * in older editions.
260
+ * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
261
+ * @returns {object} The feature values to override
262
+ */
263
+ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
264
+ return {};
265
+ };
266
+
267
+ /**
268
+ * Gets an option value.
269
+ * @param {string} name Option name
270
+ * @returns {*} Option value or `undefined` if not set
271
+ */
272
+ ReflectionObject.prototype.getOption = function getOption(name) {
273
+ if (this.options)
274
+ return this.options[name];
275
+ return undefined;
276
+ };
277
+
278
+ /**
279
+ * Sets an option.
280
+ * @param {string} name Option name
281
+ * @param {*} value Option value
282
+ * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
283
+ * @returns {ReflectionObject} `this`
284
+ */
285
+ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
286
+ if (name === "__proto__")
287
+ return this;
288
+ if (!this.options)
289
+ this.options = {};
290
+ if (/^features\./.test(name)) {
291
+ util.setProperty(this.options, name, value, ifNotSet);
292
+ } else if (!ifNotSet || this.options[name] === undefined) {
293
+ if (this.getOption(name) !== value) this.resolved = false;
294
+ this.options[name] = value;
295
+ }
296
+
297
+ return this;
298
+ };
299
+
300
+ /**
301
+ * Sets a parsed option.
302
+ * @param {string} name parsed Option name
303
+ * @param {*} value Option value
304
+ * @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
305
+ * @returns {ReflectionObject} `this`
306
+ */
307
+ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
308
+ if (name === "__proto__")
309
+ return this;
310
+ if (!this.parsedOptions) {
311
+ this.parsedOptions = [];
312
+ }
313
+ var parsedOptions = this.parsedOptions;
314
+ if (propName) {
315
+ // If setting a sub property of an option then try to merge it
316
+ // with an existing option
317
+ var opt = parsedOptions.find(function (opt) {
318
+ return Object.prototype.hasOwnProperty.call(opt, name);
319
+ });
320
+ if (opt) {
321
+ // If we found an existing option - just merge the property value
322
+ // (If it's a feature, will just write over)
323
+ var newValue = opt[name];
324
+ util.setProperty(newValue, propName, value);
325
+ } else {
326
+ // otherwise, create a new option, set its property and add it to the list
327
+ opt = {};
328
+ opt[name] = util.setProperty({}, propName, value);
329
+ parsedOptions.push(opt);
330
+ }
331
+ } else {
332
+ // Always create a new option when setting the value of the option itself
333
+ var newOpt = {};
334
+ newOpt[name] = value;
335
+ parsedOptions.push(newOpt);
336
+ }
337
+
338
+ return this;
339
+ };
340
+
341
+ /**
342
+ * Sets multiple options.
343
+ * @param {Object.<string,*>} options Options to set
344
+ * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
345
+ * @returns {ReflectionObject} `this`
346
+ */
347
+ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
348
+ if (options)
349
+ for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
350
+ this.setOption(keys[i], options[keys[i]], ifNotSet);
351
+ return this;
352
+ };
353
+
354
+ /**
355
+ * Converts this instance to its string representation.
356
+ * @returns {string} Class name[, space, full name]
357
+ */
358
+ ReflectionObject.prototype.toString = function toString() {
359
+ var className = this.constructor.className,
360
+ fullName = this.fullName;
361
+ if (fullName.length)
362
+ return className + " " + fullName;
363
+ return className;
364
+ };
365
+
366
+ /**
367
+ * Converts the edition this object is pinned to for JSON format.
368
+ * @returns {string|undefined} The edition string for JSON representation
369
+ */
370
+ ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
371
+ if (!this._edition || this._edition === "proto3") {
372
+ // Avoid emitting proto3 since we need to default to it for backwards
373
+ // compatibility anyway.
374
+ return undefined;
375
+ }
376
+ return this._edition;
377
+ };
378
+
379
+ // Sets up cyclic dependencies (called in index-light)
380
+ ReflectionObject._configure = function(Root_) {
381
+ Root = Root_;
382
+ };