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.
- package/LICENSE +39 -39
- package/README.md +727 -727
- package/dist/light/protobuf.js +7724 -7352
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +2606 -2546
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +9588 -9131
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/debug/README.md +4 -4
- package/ext/debug/index.js +71 -71
- package/ext/descriptor/README.md +72 -72
- package/ext/descriptor/index.d.ts +195 -191
- package/ext/descriptor/index.js +1181 -1052
- package/ext/descriptor/test.js +54 -54
- package/google/LICENSE +27 -27
- package/google/README.md +1 -1
- package/google/api/annotations.json +82 -82
- package/google/api/annotations.proto +10 -10
- package/google/api/http.json +85 -85
- package/google/api/http.proto +30 -30
- package/google/protobuf/api.json +117 -117
- package/google/protobuf/api.proto +33 -33
- package/google/protobuf/descriptor.json +1381 -738
- package/google/protobuf/descriptor.proto +535 -286
- package/google/protobuf/source_context.json +19 -19
- package/google/protobuf/source_context.proto +7 -7
- package/google/protobuf/type.json +201 -201
- package/google/protobuf/type.proto +89 -89
- package/index.d.ts +2817 -2792
- package/index.js +4 -4
- package/light.d.ts +2 -2
- package/light.js +3 -3
- package/minimal.d.ts +2 -2
- package/minimal.js +4 -4
- package/package.json +96 -112
- package/scripts/postinstall.js +32 -32
- package/src/common.js +399 -399
- package/src/converter.js +310 -301
- package/src/decoder.js +135 -127
- package/src/encoder.js +100 -100
- package/src/enum.js +226 -241
- package/src/field.js +453 -432
- package/src/index-light.js +104 -104
- package/src/index-minimal.js +36 -36
- package/src/index.js +12 -12
- package/src/mapfield.js +126 -126
- package/src/message.js +139 -139
- package/src/method.js +160 -160
- package/src/namespace.js +550 -434
- package/src/object.js +385 -330
- package/src/oneof.js +222 -222
- package/src/parse.js +1024 -944
- package/src/reader.js +426 -416
- package/src/reader_buffer.js +51 -51
- package/src/root.js +404 -384
- package/src/roots.js +17 -17
- package/src/rpc/service.js +142 -142
- package/src/rpc.js +36 -36
- package/src/service.js +193 -168
- package/src/tokenize.js +421 -416
- package/src/type.js +625 -590
- package/src/types.js +196 -196
- package/src/typescript.jsdoc +15 -15
- package/src/util/aspromise.d.ts +13 -0
- package/src/util/aspromise.js +52 -0
- package/src/util/base64.d.ts +32 -0
- package/src/util/base64.js +139 -0
- package/src/util/codegen.d.ts +31 -0
- package/src/util/codegen.js +113 -0
- package/src/util/eventemitter.d.ts +45 -0
- package/src/util/eventemitter.js +84 -0
- package/src/util/fetch.d.ts +56 -0
- package/src/util/fetch.js +114 -0
- package/src/util/float.d.ts +83 -0
- package/src/util/float.js +335 -0
- package/src/util/inquire.d.ts +9 -0
- package/src/util/inquire.js +37 -0
- package/src/util/longbits.js +200 -200
- package/src/util/minimal.js +461 -438
- package/src/util/path.d.ts +22 -0
- package/src/util/path.js +72 -0
- package/src/util/patterns.js +8 -0
- package/src/util/pool.d.ts +32 -0
- package/src/util/pool.js +48 -0
- package/src/util/utf8.d.ts +24 -0
- package/src/util/utf8.js +104 -0
- package/src/util.js +215 -213
- package/src/verifier.js +180 -177
- package/src/wrappers.js +103 -102
- package/src/writer.js +465 -465
- package/src/writer_buffer.js +85 -85
- 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
|
|
10
|
-
|
|
11
|
-
/* eslint-disable no-warning-comments */
|
|
12
|
-
// TODO: Replace with embedded proto.
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @param {
|
|
23
|
-
* @
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
*/
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @type {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (this
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
*
|
|
305
|
-
* @
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
+
};
|