protobufjs 6.8.8 → 6.8.9

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 (104) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +879 -879
  3. package/cli/LICENSE +33 -33
  4. package/cli/README.md +11 -11
  5. package/cli/index.d.ts +3 -3
  6. package/cli/index.js +3 -3
  7. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  8. package/cli/lib/tsd-jsdoc/README.md +23 -23
  9. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  10. package/cli/lib/tsd-jsdoc/publish.js +693 -693
  11. package/cli/lib/tsd-jsdoc.json +18 -18
  12. package/cli/package.standalone.json +31 -31
  13. package/cli/pbjs.d.ts +9 -9
  14. package/cli/pbjs.js +329 -329
  15. package/cli/pbts.d.ts +9 -9
  16. package/cli/pbts.js +197 -197
  17. package/cli/targets/json-module.js +38 -38
  18. package/cli/targets/json.js +8 -8
  19. package/cli/targets/proto.js +326 -326
  20. package/cli/targets/proto2.js +10 -10
  21. package/cli/targets/proto3.js +10 -10
  22. package/cli/targets/static-module.js +29 -29
  23. package/cli/targets/static.js +702 -702
  24. package/cli/util.js +183 -183
  25. package/cli/wrappers/amd.js +7 -7
  26. package/cli/wrappers/closure.js +7 -7
  27. package/cli/wrappers/commonjs.js +7 -7
  28. package/cli/wrappers/default.js +15 -15
  29. package/cli/wrappers/es6.js +5 -5
  30. package/dist/README.md +31 -31
  31. package/dist/light/README.md +31 -31
  32. package/dist/light/protobuf.js +6030 -6030
  33. package/dist/light/protobuf.js.map +1 -1
  34. package/dist/light/protobuf.min.js +1 -1
  35. package/dist/light/protobuf.min.js.map +1 -1
  36. package/dist/minimal/README.md +31 -31
  37. package/dist/minimal/protobuf.js +1876 -1876
  38. package/dist/minimal/protobuf.js.map +1 -1
  39. package/dist/minimal/protobuf.min.js +1 -1
  40. package/dist/minimal/protobuf.min.js.map +1 -1
  41. package/dist/protobuf.js +7595 -7595
  42. package/dist/protobuf.js.map +1 -1
  43. package/dist/protobuf.min.js +1 -1
  44. package/dist/protobuf.min.js.map +1 -1
  45. package/ext/debug/README.md +4 -4
  46. package/ext/debug/index.js +71 -71
  47. package/ext/descriptor/README.md +72 -72
  48. package/ext/descriptor/index.js +1052 -1052
  49. package/ext/descriptor/test.js +54 -54
  50. package/google/LICENSE +27 -27
  51. package/google/README.md +1 -1
  52. package/google/api/annotations.proto +10 -10
  53. package/google/protobuf/descriptor.proto +286 -286
  54. package/google/protobuf/source_context.proto +7 -7
  55. package/index.js +4 -4
  56. package/light.d.ts +2 -2
  57. package/light.js +3 -3
  58. package/minimal.d.ts +2 -2
  59. package/minimal.js +4 -4
  60. package/package-lock.json +1748 -642
  61. package/package.json +119 -122
  62. package/scripts/changelog.js +150 -150
  63. package/scripts/postinstall.js +35 -35
  64. package/src/common.js +399 -399
  65. package/src/converter.js +293 -293
  66. package/src/decoder.js +106 -106
  67. package/src/encoder.js +99 -99
  68. package/src/enum.js +181 -181
  69. package/src/field.js +371 -371
  70. package/src/index-light.js +104 -104
  71. package/src/index-minimal.js +36 -36
  72. package/src/index.js +12 -12
  73. package/src/mapfield.js +126 -126
  74. package/src/message.js +138 -138
  75. package/src/method.js +151 -151
  76. package/src/namespace.js +433 -433
  77. package/src/object.js +200 -200
  78. package/src/oneof.js +203 -203
  79. package/src/parse.js +758 -758
  80. package/src/reader.js +405 -405
  81. package/src/reader_buffer.js +44 -44
  82. package/src/root.js +351 -351
  83. package/src/roots.js +18 -18
  84. package/src/rpc/service.js +142 -142
  85. package/src/rpc.js +36 -36
  86. package/src/service.js +167 -167
  87. package/src/tokenize.js +397 -397
  88. package/src/type.js +589 -589
  89. package/src/types.js +196 -196
  90. package/src/typescript.jsdoc +15 -15
  91. package/src/util/longbits.js +200 -200
  92. package/src/util/minimal.js +414 -414
  93. package/src/util.js +178 -178
  94. package/src/verifier.js +176 -176
  95. package/src/wrappers.js +83 -83
  96. package/src/writer.js +459 -459
  97. package/src/writer_buffer.js +81 -81
  98. package/tsconfig.json +6 -6
  99. package/cli/node_modules/os-tmpdir/index.js +0 -25
  100. package/cli/node_modules/os-tmpdir/license +0 -21
  101. package/cli/node_modules/os-tmpdir/readme.md +0 -32
  102. package/cli/node_modules/tmp/LICENSE +0 -21
  103. package/cli/node_modules/tmp/README.md +0 -314
  104. package/cli/node_modules/tmp/lib/tmp.js +0 -611
package/src/root.js CHANGED
@@ -1,351 +1,351 @@
1
- "use strict";
2
- module.exports = Root;
3
-
4
- // extends Namespace
5
- var Namespace = require("./namespace");
6
- ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
7
-
8
- var Field = require("./field"),
9
- Enum = require("./enum"),
10
- OneOf = require("./oneof"),
11
- util = require("./util");
12
-
13
- var Type, // cyclic
14
- parse, // might be excluded
15
- common; // "
16
-
17
- /**
18
- * Constructs a new root namespace instance.
19
- * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.
20
- * @extends NamespaceBase
21
- * @constructor
22
- * @param {Object.<string,*>} [options] Top level options
23
- */
24
- function Root(options) {
25
- Namespace.call(this, "", options);
26
-
27
- /**
28
- * Deferred extension fields.
29
- * @type {Field[]}
30
- */
31
- this.deferred = [];
32
-
33
- /**
34
- * Resolved file names of loaded files.
35
- * @type {string[]}
36
- */
37
- this.files = [];
38
- }
39
-
40
- /**
41
- * Loads a namespace descriptor into a root namespace.
42
- * @param {INamespace} json Nameespace descriptor
43
- * @param {Root} [root] Root namespace, defaults to create a new one if omitted
44
- * @returns {Root} Root namespace
45
- */
46
- Root.fromJSON = function fromJSON(json, root) {
47
- if (!root)
48
- root = new Root();
49
- if (json.options)
50
- root.setOptions(json.options);
51
- return root.addJSON(json.nested);
52
- };
53
-
54
- /**
55
- * Resolves the path of an imported file, relative to the importing origin.
56
- * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
57
- * @function
58
- * @param {string} origin The file name of the importing file
59
- * @param {string} target The file name being imported
60
- * @returns {string|null} Resolved path to `target` or `null` to skip the file
61
- */
62
- Root.prototype.resolvePath = util.path.resolve;
63
-
64
- // A symbol-like function to safely signal synchronous loading
65
- /* istanbul ignore next */
66
- function SYNC() {} // eslint-disable-line no-empty-function
67
-
68
- /**
69
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
70
- * @param {string|string[]} filename Names of one or multiple files to load
71
- * @param {IParseOptions} options Parse options
72
- * @param {LoadCallback} callback Callback function
73
- * @returns {undefined}
74
- */
75
- Root.prototype.load = function load(filename, options, callback) {
76
- if (typeof options === "function") {
77
- callback = options;
78
- options = undefined;
79
- }
80
- var self = this;
81
- if (!callback)
82
- return util.asPromise(load, self, filename, options);
83
-
84
- var sync = callback === SYNC; // undocumented
85
-
86
- // Finishes loading by calling the callback (exactly once)
87
- function finish(err, root) {
88
- /* istanbul ignore if */
89
- if (!callback)
90
- return;
91
- var cb = callback;
92
- callback = null;
93
- if (sync)
94
- throw err;
95
- cb(err, root);
96
- }
97
-
98
- // Processes a single file
99
- function process(filename, source) {
100
- try {
101
- if (util.isString(source) && source.charAt(0) === "{")
102
- source = JSON.parse(source);
103
- if (!util.isString(source))
104
- self.setOptions(source.options).addJSON(source.nested);
105
- else {
106
- parse.filename = filename;
107
- var parsed = parse(source, self, options),
108
- resolved,
109
- i = 0;
110
- if (parsed.imports)
111
- for (; i < parsed.imports.length; ++i)
112
- if (resolved = self.resolvePath(filename, parsed.imports[i]))
113
- fetch(resolved);
114
- if (parsed.weakImports)
115
- for (i = 0; i < parsed.weakImports.length; ++i)
116
- if (resolved = self.resolvePath(filename, parsed.weakImports[i]))
117
- fetch(resolved, true);
118
- }
119
- } catch (err) {
120
- finish(err);
121
- }
122
- if (!sync && !queued)
123
- finish(null, self); // only once anyway
124
- }
125
-
126
- // Fetches a single file
127
- function fetch(filename, weak) {
128
-
129
- // Strip path if this file references a bundled definition
130
- var idx = filename.lastIndexOf("google/protobuf/");
131
- if (idx > -1) {
132
- var altname = filename.substring(idx);
133
- if (altname in common)
134
- filename = altname;
135
- }
136
-
137
- // Skip if already loaded / attempted
138
- if (self.files.indexOf(filename) > -1)
139
- return;
140
- self.files.push(filename);
141
-
142
- // Shortcut bundled definitions
143
- if (filename in common) {
144
- if (sync)
145
- process(filename, common[filename]);
146
- else {
147
- ++queued;
148
- setTimeout(function() {
149
- --queued;
150
- process(filename, common[filename]);
151
- });
152
- }
153
- return;
154
- }
155
-
156
- // Otherwise fetch from disk or network
157
- if (sync) {
158
- var source;
159
- try {
160
- source = util.fs.readFileSync(filename).toString("utf8");
161
- } catch (err) {
162
- if (!weak)
163
- finish(err);
164
- return;
165
- }
166
- process(filename, source);
167
- } else {
168
- ++queued;
169
- util.fetch(filename, function(err, source) {
170
- --queued;
171
- /* istanbul ignore if */
172
- if (!callback)
173
- return; // terminated meanwhile
174
- if (err) {
175
- /* istanbul ignore else */
176
- if (!weak)
177
- finish(err);
178
- else if (!queued) // can't be covered reliably
179
- finish(null, self);
180
- return;
181
- }
182
- process(filename, source);
183
- });
184
- }
185
- }
186
- var queued = 0;
187
-
188
- // Assembling the root namespace doesn't require working type
189
- // references anymore, so we can load everything in parallel
190
- if (util.isString(filename))
191
- filename = [ filename ];
192
- for (var i = 0, resolved; i < filename.length; ++i)
193
- if (resolved = self.resolvePath("", filename[i]))
194
- fetch(resolved);
195
-
196
- if (sync)
197
- return self;
198
- if (!queued)
199
- finish(null, self);
200
- return undefined;
201
- };
202
- // function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
203
-
204
- /**
205
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
206
- * @function Root#load
207
- * @param {string|string[]} filename Names of one or multiple files to load
208
- * @param {LoadCallback} callback Callback function
209
- * @returns {undefined}
210
- * @variation 2
211
- */
212
- // function load(filename:string, callback:LoadCallback):undefined
213
-
214
- /**
215
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
216
- * @function Root#load
217
- * @param {string|string[]} filename Names of one or multiple files to load
218
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
219
- * @returns {Promise<Root>} Promise
220
- * @variation 3
221
- */
222
- // function load(filename:string, [options:IParseOptions]):Promise<Root>
223
-
224
- /**
225
- * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
226
- * @function Root#loadSync
227
- * @param {string|string[]} filename Names of one or multiple files to load
228
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
229
- * @returns {Root} Root namespace
230
- * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
231
- */
232
- Root.prototype.loadSync = function loadSync(filename, options) {
233
- if (!util.isNode)
234
- throw Error("not supported");
235
- return this.load(filename, options, SYNC);
236
- };
237
-
238
- /**
239
- * @override
240
- */
241
- Root.prototype.resolveAll = function resolveAll() {
242
- if (this.deferred.length)
243
- throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
244
- return "'extend " + field.extend + "' in " + field.parent.fullName;
245
- }).join(", "));
246
- return Namespace.prototype.resolveAll.call(this);
247
- };
248
-
249
- // only uppercased (and thus conflict-free) children are exposed, see below
250
- var exposeRe = /^[A-Z]/;
251
-
252
- /**
253
- * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
254
- * @param {Root} root Root instance
255
- * @param {Field} field Declaring extension field witin the declaring type
256
- * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise
257
- * @inner
258
- * @ignore
259
- */
260
- function tryHandleExtension(root, field) {
261
- var extendedType = field.parent.lookup(field.extend);
262
- if (extendedType) {
263
- var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
264
- sisterField.declaringField = field;
265
- field.extensionField = sisterField;
266
- extendedType.add(sisterField);
267
- return true;
268
- }
269
- return false;
270
- }
271
-
272
- /**
273
- * Called when any object is added to this root or its sub-namespaces.
274
- * @param {ReflectionObject} object Object added
275
- * @returns {undefined}
276
- * @private
277
- */
278
- Root.prototype._handleAdd = function _handleAdd(object) {
279
- if (object instanceof Field) {
280
-
281
- if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)
282
- if (!tryHandleExtension(this, object))
283
- this.deferred.push(object);
284
-
285
- } else if (object instanceof Enum) {
286
-
287
- if (exposeRe.test(object.name))
288
- object.parent[object.name] = object.values; // expose enum values as property of its parent
289
-
290
- } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {
291
-
292
- if (object instanceof Type) // Try to handle any deferred extensions
293
- for (var i = 0; i < this.deferred.length;)
294
- if (tryHandleExtension(this, this.deferred[i]))
295
- this.deferred.splice(i, 1);
296
- else
297
- ++i;
298
- for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace
299
- this._handleAdd(object._nestedArray[j]);
300
- if (exposeRe.test(object.name))
301
- object.parent[object.name] = object; // expose namespace as property of its parent
302
- }
303
-
304
- // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
305
- // properties of namespaces just like static code does. This allows using a .d.ts generated for
306
- // a static module with reflection-based solutions where the condition is met.
307
- };
308
-
309
- /**
310
- * Called when any object is removed from this root or its sub-namespaces.
311
- * @param {ReflectionObject} object Object removed
312
- * @returns {undefined}
313
- * @private
314
- */
315
- Root.prototype._handleRemove = function _handleRemove(object) {
316
- if (object instanceof Field) {
317
-
318
- if (/* an extension field */ object.extend !== undefined) {
319
- if (/* already handled */ object.extensionField) { // remove its sister field
320
- object.extensionField.parent.remove(object.extensionField);
321
- object.extensionField = null;
322
- } else { // cancel the extension
323
- var index = this.deferred.indexOf(object);
324
- /* istanbul ignore else */
325
- if (index > -1)
326
- this.deferred.splice(index, 1);
327
- }
328
- }
329
-
330
- } else if (object instanceof Enum) {
331
-
332
- if (exposeRe.test(object.name))
333
- delete object.parent[object.name]; // unexpose enum values
334
-
335
- } else if (object instanceof Namespace) {
336
-
337
- for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace
338
- this._handleRemove(object._nestedArray[i]);
339
-
340
- if (exposeRe.test(object.name))
341
- delete object.parent[object.name]; // unexpose namespaces
342
-
343
- }
344
- };
345
-
346
- // Sets up cyclic dependencies (called in index-light)
347
- Root._configure = function(Type_, parse_, common_) {
348
- Type = Type_;
349
- parse = parse_;
350
- common = common_;
351
- };
1
+ "use strict";
2
+ module.exports = Root;
3
+
4
+ // extends Namespace
5
+ var Namespace = require("./namespace");
6
+ ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
7
+
8
+ var Field = require("./field"),
9
+ Enum = require("./enum"),
10
+ OneOf = require("./oneof"),
11
+ util = require("./util");
12
+
13
+ var Type, // cyclic
14
+ parse, // might be excluded
15
+ common; // "
16
+
17
+ /**
18
+ * Constructs a new root namespace instance.
19
+ * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.
20
+ * @extends NamespaceBase
21
+ * @constructor
22
+ * @param {Object.<string,*>} [options] Top level options
23
+ */
24
+ function Root(options) {
25
+ Namespace.call(this, "", options);
26
+
27
+ /**
28
+ * Deferred extension fields.
29
+ * @type {Field[]}
30
+ */
31
+ this.deferred = [];
32
+
33
+ /**
34
+ * Resolved file names of loaded files.
35
+ * @type {string[]}
36
+ */
37
+ this.files = [];
38
+ }
39
+
40
+ /**
41
+ * Loads a namespace descriptor into a root namespace.
42
+ * @param {INamespace} json Nameespace descriptor
43
+ * @param {Root} [root] Root namespace, defaults to create a new one if omitted
44
+ * @returns {Root} Root namespace
45
+ */
46
+ Root.fromJSON = function fromJSON(json, root) {
47
+ if (!root)
48
+ root = new Root();
49
+ if (json.options)
50
+ root.setOptions(json.options);
51
+ return root.addJSON(json.nested);
52
+ };
53
+
54
+ /**
55
+ * Resolves the path of an imported file, relative to the importing origin.
56
+ * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
57
+ * @function
58
+ * @param {string} origin The file name of the importing file
59
+ * @param {string} target The file name being imported
60
+ * @returns {string|null} Resolved path to `target` or `null` to skip the file
61
+ */
62
+ Root.prototype.resolvePath = util.path.resolve;
63
+
64
+ // A symbol-like function to safely signal synchronous loading
65
+ /* istanbul ignore next */
66
+ function SYNC() {} // eslint-disable-line no-empty-function
67
+
68
+ /**
69
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
70
+ * @param {string|string[]} filename Names of one or multiple files to load
71
+ * @param {IParseOptions} options Parse options
72
+ * @param {LoadCallback} callback Callback function
73
+ * @returns {undefined}
74
+ */
75
+ Root.prototype.load = function load(filename, options, callback) {
76
+ if (typeof options === "function") {
77
+ callback = options;
78
+ options = undefined;
79
+ }
80
+ var self = this;
81
+ if (!callback)
82
+ return util.asPromise(load, self, filename, options);
83
+
84
+ var sync = callback === SYNC; // undocumented
85
+
86
+ // Finishes loading by calling the callback (exactly once)
87
+ function finish(err, root) {
88
+ /* istanbul ignore if */
89
+ if (!callback)
90
+ return;
91
+ var cb = callback;
92
+ callback = null;
93
+ if (sync)
94
+ throw err;
95
+ cb(err, root);
96
+ }
97
+
98
+ // Processes a single file
99
+ function process(filename, source) {
100
+ try {
101
+ if (util.isString(source) && source.charAt(0) === "{")
102
+ source = JSON.parse(source);
103
+ if (!util.isString(source))
104
+ self.setOptions(source.options).addJSON(source.nested);
105
+ else {
106
+ parse.filename = filename;
107
+ var parsed = parse(source, self, options),
108
+ resolved,
109
+ i = 0;
110
+ if (parsed.imports)
111
+ for (; i < parsed.imports.length; ++i)
112
+ if (resolved = self.resolvePath(filename, parsed.imports[i]))
113
+ fetch(resolved);
114
+ if (parsed.weakImports)
115
+ for (i = 0; i < parsed.weakImports.length; ++i)
116
+ if (resolved = self.resolvePath(filename, parsed.weakImports[i]))
117
+ fetch(resolved, true);
118
+ }
119
+ } catch (err) {
120
+ finish(err);
121
+ }
122
+ if (!sync && !queued)
123
+ finish(null, self); // only once anyway
124
+ }
125
+
126
+ // Fetches a single file
127
+ function fetch(filename, weak) {
128
+
129
+ // Strip path if this file references a bundled definition
130
+ var idx = filename.lastIndexOf("google/protobuf/");
131
+ if (idx > -1) {
132
+ var altname = filename.substring(idx);
133
+ if (altname in common)
134
+ filename = altname;
135
+ }
136
+
137
+ // Skip if already loaded / attempted
138
+ if (self.files.indexOf(filename) > -1)
139
+ return;
140
+ self.files.push(filename);
141
+
142
+ // Shortcut bundled definitions
143
+ if (filename in common) {
144
+ if (sync)
145
+ process(filename, common[filename]);
146
+ else {
147
+ ++queued;
148
+ setTimeout(function() {
149
+ --queued;
150
+ process(filename, common[filename]);
151
+ });
152
+ }
153
+ return;
154
+ }
155
+
156
+ // Otherwise fetch from disk or network
157
+ if (sync) {
158
+ var source;
159
+ try {
160
+ source = util.fs.readFileSync(filename).toString("utf8");
161
+ } catch (err) {
162
+ if (!weak)
163
+ finish(err);
164
+ return;
165
+ }
166
+ process(filename, source);
167
+ } else {
168
+ ++queued;
169
+ util.fetch(filename, function(err, source) {
170
+ --queued;
171
+ /* istanbul ignore if */
172
+ if (!callback)
173
+ return; // terminated meanwhile
174
+ if (err) {
175
+ /* istanbul ignore else */
176
+ if (!weak)
177
+ finish(err);
178
+ else if (!queued) // can't be covered reliably
179
+ finish(null, self);
180
+ return;
181
+ }
182
+ process(filename, source);
183
+ });
184
+ }
185
+ }
186
+ var queued = 0;
187
+
188
+ // Assembling the root namespace doesn't require working type
189
+ // references anymore, so we can load everything in parallel
190
+ if (util.isString(filename))
191
+ filename = [ filename ];
192
+ for (var i = 0, resolved; i < filename.length; ++i)
193
+ if (resolved = self.resolvePath("", filename[i]))
194
+ fetch(resolved);
195
+
196
+ if (sync)
197
+ return self;
198
+ if (!queued)
199
+ finish(null, self);
200
+ return undefined;
201
+ };
202
+ // function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
203
+
204
+ /**
205
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
206
+ * @function Root#load
207
+ * @param {string|string[]} filename Names of one or multiple files to load
208
+ * @param {LoadCallback} callback Callback function
209
+ * @returns {undefined}
210
+ * @variation 2
211
+ */
212
+ // function load(filename:string, callback:LoadCallback):undefined
213
+
214
+ /**
215
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
216
+ * @function Root#load
217
+ * @param {string|string[]} filename Names of one or multiple files to load
218
+ * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
219
+ * @returns {Promise<Root>} Promise
220
+ * @variation 3
221
+ */
222
+ // function load(filename:string, [options:IParseOptions]):Promise<Root>
223
+
224
+ /**
225
+ * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
226
+ * @function Root#loadSync
227
+ * @param {string|string[]} filename Names of one or multiple files to load
228
+ * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
229
+ * @returns {Root} Root namespace
230
+ * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
231
+ */
232
+ Root.prototype.loadSync = function loadSync(filename, options) {
233
+ if (!util.isNode)
234
+ throw Error("not supported");
235
+ return this.load(filename, options, SYNC);
236
+ };
237
+
238
+ /**
239
+ * @override
240
+ */
241
+ Root.prototype.resolveAll = function resolveAll() {
242
+ if (this.deferred.length)
243
+ throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
244
+ return "'extend " + field.extend + "' in " + field.parent.fullName;
245
+ }).join(", "));
246
+ return Namespace.prototype.resolveAll.call(this);
247
+ };
248
+
249
+ // only uppercased (and thus conflict-free) children are exposed, see below
250
+ var exposeRe = /^[A-Z]/;
251
+
252
+ /**
253
+ * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
254
+ * @param {Root} root Root instance
255
+ * @param {Field} field Declaring extension field witin the declaring type
256
+ * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise
257
+ * @inner
258
+ * @ignore
259
+ */
260
+ function tryHandleExtension(root, field) {
261
+ var extendedType = field.parent.lookup(field.extend);
262
+ if (extendedType) {
263
+ var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
264
+ sisterField.declaringField = field;
265
+ field.extensionField = sisterField;
266
+ extendedType.add(sisterField);
267
+ return true;
268
+ }
269
+ return false;
270
+ }
271
+
272
+ /**
273
+ * Called when any object is added to this root or its sub-namespaces.
274
+ * @param {ReflectionObject} object Object added
275
+ * @returns {undefined}
276
+ * @private
277
+ */
278
+ Root.prototype._handleAdd = function _handleAdd(object) {
279
+ if (object instanceof Field) {
280
+
281
+ if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)
282
+ if (!tryHandleExtension(this, object))
283
+ this.deferred.push(object);
284
+
285
+ } else if (object instanceof Enum) {
286
+
287
+ if (exposeRe.test(object.name))
288
+ object.parent[object.name] = object.values; // expose enum values as property of its parent
289
+
290
+ } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {
291
+
292
+ if (object instanceof Type) // Try to handle any deferred extensions
293
+ for (var i = 0; i < this.deferred.length;)
294
+ if (tryHandleExtension(this, this.deferred[i]))
295
+ this.deferred.splice(i, 1);
296
+ else
297
+ ++i;
298
+ for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace
299
+ this._handleAdd(object._nestedArray[j]);
300
+ if (exposeRe.test(object.name))
301
+ object.parent[object.name] = object; // expose namespace as property of its parent
302
+ }
303
+
304
+ // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
305
+ // properties of namespaces just like static code does. This allows using a .d.ts generated for
306
+ // a static module with reflection-based solutions where the condition is met.
307
+ };
308
+
309
+ /**
310
+ * Called when any object is removed from this root or its sub-namespaces.
311
+ * @param {ReflectionObject} object Object removed
312
+ * @returns {undefined}
313
+ * @private
314
+ */
315
+ Root.prototype._handleRemove = function _handleRemove(object) {
316
+ if (object instanceof Field) {
317
+
318
+ if (/* an extension field */ object.extend !== undefined) {
319
+ if (/* already handled */ object.extensionField) { // remove its sister field
320
+ object.extensionField.parent.remove(object.extensionField);
321
+ object.extensionField = null;
322
+ } else { // cancel the extension
323
+ var index = this.deferred.indexOf(object);
324
+ /* istanbul ignore else */
325
+ if (index > -1)
326
+ this.deferred.splice(index, 1);
327
+ }
328
+ }
329
+
330
+ } else if (object instanceof Enum) {
331
+
332
+ if (exposeRe.test(object.name))
333
+ delete object.parent[object.name]; // unexpose enum values
334
+
335
+ } else if (object instanceof Namespace) {
336
+
337
+ for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace
338
+ this._handleRemove(object._nestedArray[i]);
339
+
340
+ if (exposeRe.test(object.name))
341
+ delete object.parent[object.name]; // unexpose namespaces
342
+
343
+ }
344
+ };
345
+
346
+ // Sets up cyclic dependencies (called in index-light)
347
+ Root._configure = function(Type_, parse_, common_) {
348
+ Type = Type_;
349
+ parse = parse_;
350
+ common = common_;
351
+ };