protobufjs 7.5.1 → 7.5.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.
- package/dist/light/protobuf.js +75 -15
- 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 +2 -2
- package/dist/minimal/protobuf.min.js +2 -2
- package/dist/protobuf.js +75 -15
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +3 -15
- package/package.json +1 -1
- package/src/namespace.js +41 -9
- package/src/object.js +4 -0
- package/src/root.js +24 -4
- package/src/service.js +2 -0
- package/src/type.js +2 -0
package/index.d.ts
CHANGED
|
@@ -753,6 +753,9 @@ export abstract class NamespaceBase extends ReflectionObject {
|
|
|
753
753
|
/** Whether or not objects contained in this namespace need feature resolution. */
|
|
754
754
|
protected _needsRecursiveFeatureResolution: boolean;
|
|
755
755
|
|
|
756
|
+
/** Whether or not objects contained in this namespace need a resolve. */
|
|
757
|
+
protected _needsRecursiveResolve: boolean;
|
|
758
|
+
|
|
756
759
|
/** Nested objects of this namespace as an array for iteration. */
|
|
757
760
|
public readonly nestedArray: ReflectionObject[];
|
|
758
761
|
|
|
@@ -900,21 +903,6 @@ export abstract class ReflectionObject {
|
|
|
900
903
|
/** Unique name within its namespace. */
|
|
901
904
|
public name: string;
|
|
902
905
|
|
|
903
|
-
/** The edition specified for this object. Only relevant for top-level objects. */
|
|
904
|
-
public _edition: string;
|
|
905
|
-
|
|
906
|
-
/**
|
|
907
|
-
* The default edition to use for this object if none is specified. For legacy reasons,
|
|
908
|
-
* this is proto2 except in the JSON parsing case where it was proto3.
|
|
909
|
-
*/
|
|
910
|
-
public _defaultEdition: string;
|
|
911
|
-
|
|
912
|
-
/** Resolved Features. */
|
|
913
|
-
public _features: object;
|
|
914
|
-
|
|
915
|
-
/** Whether or not features have been resolved. */
|
|
916
|
-
public _featuresResolved: boolean;
|
|
917
|
-
|
|
918
906
|
/** Parent namespace. */
|
|
919
907
|
public parent: (Namespace|null);
|
|
920
908
|
|
package/package.json
CHANGED
package/src/namespace.js
CHANGED
|
@@ -124,6 +124,13 @@ function Namespace(name, options) {
|
|
|
124
124
|
* @protected
|
|
125
125
|
*/
|
|
126
126
|
this._needsRecursiveFeatureResolution = true;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Whether or not objects contained in this namespace need a resolve.
|
|
130
|
+
* @type {boolean}
|
|
131
|
+
* @protected
|
|
132
|
+
*/
|
|
133
|
+
this._needsRecursiveResolve = true;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
function clearCache(namespace) {
|
|
@@ -273,11 +280,13 @@ Namespace.prototype.add = function add(object) {
|
|
|
273
280
|
}
|
|
274
281
|
|
|
275
282
|
this._needsRecursiveFeatureResolution = true;
|
|
283
|
+
this._needsRecursiveResolve = true;
|
|
276
284
|
|
|
277
285
|
// Also clear parent caches, since they need to recurse down.
|
|
278
286
|
var parent = this;
|
|
279
287
|
while(parent = parent.parent) {
|
|
280
288
|
parent._needsRecursiveFeatureResolution = true;
|
|
289
|
+
parent._needsRecursiveResolve = true;
|
|
281
290
|
}
|
|
282
291
|
|
|
283
292
|
object.onAdd(this);
|
|
@@ -341,6 +350,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
341
350
|
* @returns {Namespace} `this`
|
|
342
351
|
*/
|
|
343
352
|
Namespace.prototype.resolveAll = function resolveAll() {
|
|
353
|
+
if (!this._needsRecursiveResolve) return this;
|
|
354
|
+
|
|
344
355
|
var nested = this.nestedArray, i = 0;
|
|
345
356
|
this.resolve();
|
|
346
357
|
while (i < nested.length)
|
|
@@ -348,6 +359,7 @@ Namespace.prototype.resolveAll = function resolveAll() {
|
|
|
348
359
|
nested[i++].resolveAll();
|
|
349
360
|
else
|
|
350
361
|
nested[i++].resolve();
|
|
362
|
+
this._needsRecursiveResolve = false;
|
|
351
363
|
return this;
|
|
352
364
|
};
|
|
353
365
|
|
|
@@ -389,29 +401,47 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
|
|
|
389
401
|
} else if (!path.length)
|
|
390
402
|
return this;
|
|
391
403
|
|
|
404
|
+
var flatPath = path.join(".");
|
|
405
|
+
|
|
392
406
|
// Start at root if path is absolute
|
|
393
407
|
if (path[0] === "")
|
|
394
408
|
return this.root.lookup(path.slice(1), filterTypes);
|
|
395
409
|
|
|
396
|
-
|
|
410
|
+
// Early bailout for objects with matching absolute paths
|
|
411
|
+
var found = this.root._fullyQualifiedObjects["." + flatPath];
|
|
412
|
+
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
413
|
+
return found;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Do a regular lookup at this namespace and below
|
|
417
|
+
found = this._lookupImpl(path, flatPath);
|
|
397
418
|
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
398
419
|
return found;
|
|
399
420
|
}
|
|
400
421
|
|
|
401
|
-
|
|
402
|
-
if (this.parent === null || parentAlreadyChecked)
|
|
422
|
+
if (parentAlreadyChecked)
|
|
403
423
|
return null;
|
|
404
|
-
|
|
424
|
+
|
|
425
|
+
// If there hasn't been a match, walk up the tree and look more broadly
|
|
426
|
+
var current = this;
|
|
427
|
+
while (current.parent) {
|
|
428
|
+
found = current.parent._lookupImpl(path, flatPath);
|
|
429
|
+
if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
|
|
430
|
+
return found;
|
|
431
|
+
}
|
|
432
|
+
current = current.parent;
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
405
435
|
};
|
|
406
436
|
|
|
407
437
|
/**
|
|
408
438
|
* Internal helper for lookup that handles searching just at this namespace and below along with caching.
|
|
409
439
|
* @param {string[]} path Path to look up
|
|
440
|
+
* @param {string} flatPath Flattened version of the path to use as a cache key
|
|
410
441
|
* @returns {ReflectionObject|null} Looked up object or `null` if none could be found
|
|
411
442
|
* @private
|
|
412
443
|
*/
|
|
413
|
-
Namespace.prototype._lookupImpl = function lookup(path) {
|
|
414
|
-
var flatPath = path.join(".");
|
|
444
|
+
Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
|
|
415
445
|
if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
|
|
416
446
|
return this._lookupCache[flatPath];
|
|
417
447
|
}
|
|
@@ -422,13 +452,15 @@ Namespace.prototype._lookupImpl = function lookup(path) {
|
|
|
422
452
|
if (found) {
|
|
423
453
|
if (path.length === 1) {
|
|
424
454
|
exact = found;
|
|
425
|
-
} else if (found instanceof Namespace
|
|
426
|
-
|
|
455
|
+
} else if (found instanceof Namespace) {
|
|
456
|
+
path = path.slice(1);
|
|
457
|
+
exact = found._lookupImpl(path, path.join("."));
|
|
458
|
+
}
|
|
427
459
|
|
|
428
460
|
// Otherwise try each nested namespace
|
|
429
461
|
} else {
|
|
430
462
|
for (var i = 0; i < this.nestedArray.length; ++i)
|
|
431
|
-
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path)))
|
|
463
|
+
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
|
|
432
464
|
exact = found;
|
|
433
465
|
}
|
|
434
466
|
|
package/src/object.js
CHANGED
|
@@ -51,6 +51,7 @@ function ReflectionObject(name, options) {
|
|
|
51
51
|
/**
|
|
52
52
|
* The edition specified for this object. Only relevant for top-level objects.
|
|
53
53
|
* @type {string}
|
|
54
|
+
* @private
|
|
54
55
|
*/
|
|
55
56
|
this._edition = null;
|
|
56
57
|
|
|
@@ -58,18 +59,21 @@ function ReflectionObject(name, options) {
|
|
|
58
59
|
* The default edition to use for this object if none is specified. For legacy reasons,
|
|
59
60
|
* this is proto2 except in the JSON parsing case where it was proto3.
|
|
60
61
|
* @type {string}
|
|
62
|
+
* @private
|
|
61
63
|
*/
|
|
62
64
|
this._defaultEdition = "proto2";
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
* Resolved Features.
|
|
66
68
|
* @type {object}
|
|
69
|
+
* @private
|
|
67
70
|
*/
|
|
68
71
|
this._features = {};
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* Whether or not features have been resolved.
|
|
72
75
|
* @type {boolean}
|
|
76
|
+
* @private
|
|
73
77
|
*/
|
|
74
78
|
this._featuresResolved = false;
|
|
75
79
|
|
package/src/root.js
CHANGED
|
@@ -36,8 +36,19 @@ function Root(options) {
|
|
|
36
36
|
*/
|
|
37
37
|
this.files = [];
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Edition, defaults to proto2 if unspecified.
|
|
41
|
+
* @type {string}
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
40
44
|
this._edition = "proto2";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Global lookup cache of fully qualified names.
|
|
48
|
+
* @type {Object.<string,ReflectionObject>}
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
this._fullyQualifiedObjects = {};
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
/**
|
|
@@ -51,7 +62,7 @@ Root.fromJSON = function fromJSON(json, root) {
|
|
|
51
62
|
root = new Root();
|
|
52
63
|
if (json.options)
|
|
53
64
|
root.setOptions(json.options);
|
|
54
|
-
return root.addJSON(json.nested).
|
|
65
|
+
return root.addJSON(json.nested).resolveAll();
|
|
55
66
|
};
|
|
56
67
|
|
|
57
68
|
/**
|
|
@@ -100,7 +111,7 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
100
111
|
// Finishes loading by calling the callback (exactly once)
|
|
101
112
|
function finish(err, root) {
|
|
102
113
|
if (root) {
|
|
103
|
-
root.
|
|
114
|
+
root.resolveAll();
|
|
104
115
|
}
|
|
105
116
|
/* istanbul ignore if */
|
|
106
117
|
if (!callback) {
|
|
@@ -219,7 +230,7 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
219
230
|
if (resolved = self.resolvePath("", filename[i]))
|
|
220
231
|
fetch(resolved);
|
|
221
232
|
if (sync) {
|
|
222
|
-
self.
|
|
233
|
+
self.resolveAll();
|
|
223
234
|
return self;
|
|
224
235
|
}
|
|
225
236
|
if (!queued) {
|
|
@@ -268,6 +279,8 @@ Root.prototype.loadSync = function loadSync(filename, options) {
|
|
|
268
279
|
* @override
|
|
269
280
|
*/
|
|
270
281
|
Root.prototype.resolveAll = function resolveAll() {
|
|
282
|
+
if (!this._needsRecursiveResolve) return this;
|
|
283
|
+
|
|
271
284
|
if (this.deferred.length)
|
|
272
285
|
throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
|
|
273
286
|
return "'extend " + field.extend + "' in " + field.parent.fullName;
|
|
@@ -335,6 +348,11 @@ Root.prototype._handleAdd = function _handleAdd(object) {
|
|
|
335
348
|
object.parent[object.name] = object; // expose namespace as property of its parent
|
|
336
349
|
}
|
|
337
350
|
|
|
351
|
+
if (object instanceof Type || object instanceof Enum || object instanceof Field) {
|
|
352
|
+
// Only store types and enums for quick lookup during resolve.
|
|
353
|
+
this._fullyQualifiedObjects[object.fullName] = object;
|
|
354
|
+
}
|
|
355
|
+
|
|
338
356
|
// The above also adds uppercased (and thus conflict-free) nested types, services and enums as
|
|
339
357
|
// properties of namespaces just like static code does. This allows using a .d.ts generated for
|
|
340
358
|
// a static module with reflection-based solutions where the condition is met.
|
|
@@ -375,6 +393,8 @@ Root.prototype._handleRemove = function _handleRemove(object) {
|
|
|
375
393
|
delete object.parent[object.name]; // unexpose namespaces
|
|
376
394
|
|
|
377
395
|
}
|
|
396
|
+
|
|
397
|
+
delete this._fullyQualifiedObjects[object.fullName];
|
|
378
398
|
};
|
|
379
399
|
|
|
380
400
|
// Sets up cyclic dependencies (called in index-light)
|
package/src/service.js
CHANGED
|
@@ -110,6 +110,8 @@ Service.prototype.get = function get(name) {
|
|
|
110
110
|
* @override
|
|
111
111
|
*/
|
|
112
112
|
Service.prototype.resolveAll = function resolveAll() {
|
|
113
|
+
if (!this._needsRecursiveResolve) return this;
|
|
114
|
+
|
|
113
115
|
Namespace.prototype.resolve.call(this);
|
|
114
116
|
var methods = this.methodsArray;
|
|
115
117
|
for (var i = 0; i < methods.length; ++i)
|
package/src/type.js
CHANGED
|
@@ -303,6 +303,8 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
303
303
|
* @override
|
|
304
304
|
*/
|
|
305
305
|
Type.prototype.resolveAll = function resolveAll() {
|
|
306
|
+
if (!this._needsRecursiveResolve) return this;
|
|
307
|
+
|
|
306
308
|
Namespace.prototype.resolveAll.call(this);
|
|
307
309
|
var oneofs = this.oneofsArray; i = 0;
|
|
308
310
|
while (i < oneofs.length)
|