protobufjs 8.1.6-experimental → 8.2.1
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/README.md +225 -570
- package/dist/light/protobuf.js +2041 -1482
- 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 +1167 -863
- 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 +2173 -1527
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/README.md +81 -0
- package/ext/descriptor/README.md +3 -70
- package/ext/descriptor/index.d.ts +1 -190
- package/ext/descriptor/index.js +1 -1161
- package/ext/descriptor.d.ts +309 -0
- package/ext/descriptor.js +1241 -0
- package/ext/textformat.d.ts +24 -0
- package/ext/textformat.js +1227 -0
- package/google/protobuf/compiler/plugin.json +126 -0
- package/google/protobuf/compiler/plugin.proto +47 -0
- package/google/protobuf/descriptor.json +2 -2
- package/google/protobuf/descriptor.proto +2 -1
- package/index.d.ts +585 -476
- package/package.json +22 -40
- package/src/converter.js +63 -27
- package/src/decoder.js +126 -49
- package/src/encoder.js +10 -2
- package/src/enum.js +4 -1
- package/src/field.js +10 -7
- package/src/mapfield.js +1 -0
- package/src/message.js +7 -6
- package/src/method.js +4 -3
- package/src/namespace.js +31 -12
- package/src/object.js +24 -19
- package/src/oneof.js +2 -0
- package/src/parse.js +128 -46
- package/src/reader.js +145 -30
- package/src/reader_buffer.js +24 -3
- package/src/root.js +10 -4
- package/src/service.js +15 -6
- package/src/tokenize.js +6 -1
- package/src/type.js +57 -27
- package/src/types.js +1 -1
- 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 +146 -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 +112 -0
- package/src/util/float.d.ts +83 -0
- package/src/util/float.js +335 -0
- package/src/util/fs.js +11 -0
- package/src/util/inquire.d.ts +10 -0
- package/src/util/inquire.js +38 -0
- package/src/util/minimal.js +74 -12
- 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 +130 -0
- package/src/util.js +18 -13
- package/src/verifier.js +7 -4
- package/src/wrappers.js +4 -3
- package/src/writer.js +33 -5
- package/src/writer_buffer.js +18 -1
- package/tsconfig.json +2 -2
- package/ext/descriptor/test.js +0 -54
package/src/mapfield.js
CHANGED
|
@@ -108,6 +108,7 @@ MapField.prototype.resolve = function resolve() {
|
|
|
108
108
|
* @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
|
|
109
109
|
* @returns {FieldDecorator} Decorator function
|
|
110
110
|
* @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
|
|
111
|
+
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
111
112
|
*/
|
|
112
113
|
MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
|
|
113
114
|
|
package/src/message.js
CHANGED
|
@@ -8,13 +8,18 @@ var util = require("./util/minimal");
|
|
|
8
8
|
* @classdesc Abstract runtime message.
|
|
9
9
|
* @constructor
|
|
10
10
|
* @param {Properties<T>} [properties] Properties to set
|
|
11
|
+
* @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
|
|
11
12
|
* @template T extends object = object
|
|
12
13
|
*/
|
|
13
14
|
function Message(properties) {
|
|
14
15
|
// not used internally
|
|
15
16
|
if (properties)
|
|
16
|
-
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
17
|
-
|
|
17
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) {
|
|
18
|
+
var key = keys[i];
|
|
19
|
+
if (key === "__proto__")
|
|
20
|
+
continue;
|
|
21
|
+
this[key] = properties[key];
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
/**
|
|
@@ -31,8 +36,6 @@ function Message(properties) {
|
|
|
31
36
|
* @readonly
|
|
32
37
|
*/
|
|
33
38
|
|
|
34
|
-
/*eslint-disable valid-jsdoc*/
|
|
35
|
-
|
|
36
39
|
/**
|
|
37
40
|
* Creates a new message of this type using the specified properties.
|
|
38
41
|
* @param {Object.<string,*>} [properties] Properties to set
|
|
@@ -135,5 +138,3 @@ Message.toObject = function toObject(message, options) {
|
|
|
135
138
|
Message.prototype.toJSON = function toJSON() {
|
|
136
139
|
return this.$type.toObject(this, util.toJSONOptions);
|
|
137
140
|
};
|
|
138
|
-
|
|
139
|
-
/*eslint-enable valid-jsdoc*/
|
package/src/method.js
CHANGED
|
@@ -20,7 +20,7 @@ var util = require("./util");
|
|
|
20
20
|
* @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
|
|
21
21
|
* @param {Object.<string,*>} [options] Declared options
|
|
22
22
|
* @param {string} [comment] The comment for this method
|
|
23
|
-
* @param {Object.<string
|
|
23
|
+
* @param {Array.<Object.<string,*>>} [parsedOptions] Declared options, properly parsed into objects
|
|
24
24
|
*/
|
|
25
25
|
function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment, parsedOptions) {
|
|
26
26
|
|
|
@@ -96,7 +96,8 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
96
96
|
this.comment = comment;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* Options properly parsed into
|
|
99
|
+
* Options properly parsed into objects
|
|
100
|
+
* @type {Array.<Object.<string,*>>|undefined}
|
|
100
101
|
*/
|
|
101
102
|
this.parsedOptions = parsedOptions;
|
|
102
103
|
}
|
|
@@ -111,7 +112,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
111
112
|
* @property {boolean} [responseStream=false] Whether responses are streamed
|
|
112
113
|
* @property {Object.<string,*>} [options] Method options
|
|
113
114
|
* @property {string} comment Method comments
|
|
114
|
-
* @property {Object.<string
|
|
115
|
+
* @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
|
|
115
116
|
*/
|
|
116
117
|
|
|
117
118
|
/**
|
package/src/namespace.js
CHANGED
|
@@ -29,11 +29,16 @@ var Type, // cyclic
|
|
|
29
29
|
* @function
|
|
30
30
|
* @param {string} name Namespace name
|
|
31
31
|
* @param {Object.<string,*>} json JSON object
|
|
32
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
32
33
|
* @returns {Namespace} Created namespace
|
|
33
34
|
* @throws {TypeError} If arguments are invalid
|
|
34
35
|
*/
|
|
35
|
-
Namespace.fromJSON = function fromJSON(name, json) {
|
|
36
|
-
|
|
36
|
+
Namespace.fromJSON = function fromJSON(name, json, depth) {
|
|
37
|
+
if (depth === undefined)
|
|
38
|
+
depth = 0;
|
|
39
|
+
if (depth > util.recursionLimit)
|
|
40
|
+
throw Error("max depth exceeded");
|
|
41
|
+
return new Namespace(name, json.options).addJSON(json.nested, depth);
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
/**
|
|
@@ -116,7 +121,7 @@ function Namespace(name, options) {
|
|
|
116
121
|
* @type {Object.<string,ReflectionObject|null>}
|
|
117
122
|
* @private
|
|
118
123
|
*/
|
|
119
|
-
this._lookupCache =
|
|
124
|
+
this._lookupCache = Object.create(null);
|
|
120
125
|
|
|
121
126
|
/**
|
|
122
127
|
* Whether or not objects contained in this namespace need feature resolution.
|
|
@@ -135,12 +140,12 @@ function Namespace(name, options) {
|
|
|
135
140
|
|
|
136
141
|
function clearCache(namespace) {
|
|
137
142
|
namespace._nestedArray = null;
|
|
138
|
-
namespace._lookupCache =
|
|
143
|
+
namespace._lookupCache = Object.create(null);
|
|
139
144
|
|
|
140
145
|
// Also clear parent caches, since they include nested lookups.
|
|
141
146
|
var parent = namespace;
|
|
142
147
|
while(parent = parent.parent) {
|
|
143
|
-
parent._lookupCache =
|
|
148
|
+
parent._lookupCache = Object.create(null);
|
|
144
149
|
}
|
|
145
150
|
return namespace;
|
|
146
151
|
}
|
|
@@ -191,9 +196,14 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
191
196
|
/**
|
|
192
197
|
* Adds nested objects to this namespace from nested object descriptors.
|
|
193
198
|
* @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
|
|
199
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
194
200
|
* @returns {Namespace} `this`
|
|
195
201
|
*/
|
|
196
|
-
Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
202
|
+
Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
|
|
203
|
+
if (depth === undefined)
|
|
204
|
+
depth = 0;
|
|
205
|
+
if (depth > util.recursionLimit)
|
|
206
|
+
throw Error("max depth exceeded");
|
|
197
207
|
var ns = this;
|
|
198
208
|
/* istanbul ignore else */
|
|
199
209
|
if (nestedJson) {
|
|
@@ -208,7 +218,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
|
208
218
|
? Service.fromJSON
|
|
209
219
|
: nested.id !== undefined
|
|
210
220
|
? Field.fromJSON
|
|
211
|
-
: Namespace.fromJSON )(names[i], nested)
|
|
221
|
+
: Namespace.fromJSON )(names[i], nested, depth + 1)
|
|
212
222
|
);
|
|
213
223
|
}
|
|
214
224
|
}
|
|
@@ -221,8 +231,9 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
|
221
231
|
* @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
|
|
222
232
|
*/
|
|
223
233
|
Namespace.prototype.get = function get(name) {
|
|
224
|
-
return this.nested && this.nested
|
|
225
|
-
|
|
234
|
+
return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
|
|
235
|
+
? this.nested[name]
|
|
236
|
+
: null;
|
|
226
237
|
};
|
|
227
238
|
|
|
228
239
|
/**
|
|
@@ -233,7 +244,7 @@ Namespace.prototype.get = function get(name) {
|
|
|
233
244
|
* @throws {Error} If there is no such enum
|
|
234
245
|
*/
|
|
235
246
|
Namespace.prototype.getEnum = function getEnum(name) {
|
|
236
|
-
if (this.nested && this.nested[name] instanceof Enum)
|
|
247
|
+
if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
|
|
237
248
|
return this.nested[name].values;
|
|
238
249
|
throw Error("no such enum: " + name);
|
|
239
250
|
};
|
|
@@ -250,6 +261,9 @@ Namespace.prototype.add = function add(object) {
|
|
|
250
261
|
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
251
262
|
throw TypeError("object must be a valid nested object");
|
|
252
263
|
|
|
264
|
+
if (object.name === "__proto__")
|
|
265
|
+
return this;
|
|
266
|
+
|
|
253
267
|
if (!this.nested)
|
|
254
268
|
this.nested = {};
|
|
255
269
|
else {
|
|
@@ -329,6 +343,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
329
343
|
throw TypeError("illegal path");
|
|
330
344
|
if (path && path.length && path[0] === "")
|
|
331
345
|
throw Error("path must be relative");
|
|
346
|
+
if (path.length > util.recursionLimit)
|
|
347
|
+
throw Error("max depth exceeded");
|
|
332
348
|
|
|
333
349
|
var ptr = this;
|
|
334
350
|
while (path.length > 0) {
|
|
@@ -352,7 +368,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
352
368
|
Namespace.prototype.resolveAll = function resolveAll() {
|
|
353
369
|
if (!this._needsRecursiveResolve) return this;
|
|
354
370
|
|
|
355
|
-
|
|
371
|
+
if (this._needsRecursiveFeatureResolution)
|
|
372
|
+
this._resolveFeaturesRecursive(this._edition);
|
|
356
373
|
|
|
357
374
|
var nested = this.nestedArray, i = 0;
|
|
358
375
|
this.resolve();
|
|
@@ -462,8 +479,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
|
|
|
462
479
|
// Otherwise try each nested namespace
|
|
463
480
|
} else {
|
|
464
481
|
for (var i = 0; i < this.nestedArray.length; ++i)
|
|
465
|
-
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
|
|
482
|
+
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
|
|
466
483
|
exact = found;
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
467
486
|
}
|
|
468
487
|
|
|
469
488
|
// Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
|
package/src/object.js
CHANGED
|
@@ -10,9 +10,10 @@ var Root; // cyclic
|
|
|
10
10
|
|
|
11
11
|
/* eslint-disable no-warning-comments */
|
|
12
12
|
// TODO: Replace with embedded proto.
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
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" };
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Constructs a new reflection object instance.
|
|
@@ -225,27 +226,27 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
225
226
|
defaults = Object.assign({}, proto3Defaults);
|
|
226
227
|
} else if (edition === "2023") {
|
|
227
228
|
defaults = Object.assign({}, editions2023Defaults);
|
|
229
|
+
} else if (edition === "2024") {
|
|
230
|
+
defaults = Object.assign({}, editions2024Defaults);
|
|
228
231
|
} else {
|
|
229
232
|
throw new Error("Unknown edition: " + edition);
|
|
230
233
|
}
|
|
231
234
|
this._features = Object.assign(defaults, protoFeatures || {});
|
|
232
|
-
this._featuresResolved = true;
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// fields in Oneofs aren't actually children of them, so we have to
|
|
237
|
-
// special-case it
|
|
238
|
-
/* istanbul ignore else */
|
|
239
|
-
if (this.partOf instanceof OneOf) {
|
|
240
|
-
var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
|
|
241
|
-
this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
|
|
242
|
-
} else if (this.declaringField) {
|
|
243
|
-
// Skip feature resolution of sister fields.
|
|
244
|
-
} else if (this.parent) {
|
|
245
|
-
var parentFeaturesCopy = Object.assign({}, this.parent._features);
|
|
246
|
-
this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
|
|
247
235
|
} else {
|
|
248
|
-
|
|
236
|
+
// fields in Oneofs aren't actually children of them, so we have to
|
|
237
|
+
// special-case it
|
|
238
|
+
/* istanbul ignore else */
|
|
239
|
+
if (this.partOf instanceof OneOf) {
|
|
240
|
+
var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
|
|
241
|
+
this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
|
|
242
|
+
} else if (this.declaringField) {
|
|
243
|
+
// Skip feature resolution of sister fields.
|
|
244
|
+
} else if (this.parent) {
|
|
245
|
+
var parentFeaturesCopy = Object.assign({}, this.parent._features);
|
|
246
|
+
this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
|
|
247
|
+
} else {
|
|
248
|
+
throw new Error("Unable to find a parent for " + this.fullName);
|
|
249
|
+
}
|
|
249
250
|
}
|
|
250
251
|
if (this.extensionField) {
|
|
251
252
|
// Sister fields should have the same features as their extensions.
|
|
@@ -283,6 +284,8 @@ ReflectionObject.prototype.getOption = function getOption(name) {
|
|
|
283
284
|
* @returns {ReflectionObject} `this`
|
|
284
285
|
*/
|
|
285
286
|
ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
287
|
+
if (name === "__proto__")
|
|
288
|
+
return this;
|
|
286
289
|
if (!this.options)
|
|
287
290
|
this.options = {};
|
|
288
291
|
if (/^features\./.test(name)) {
|
|
@@ -303,6 +306,8 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
|
|
|
303
306
|
* @returns {ReflectionObject} `this`
|
|
304
307
|
*/
|
|
305
308
|
ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
|
|
309
|
+
if (name === "__proto__")
|
|
310
|
+
return this;
|
|
306
311
|
if (!this.parsedOptions) {
|
|
307
312
|
this.parsedOptions = [];
|
|
308
313
|
}
|
package/src/oneof.js
CHANGED
|
@@ -197,6 +197,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
|
|
|
197
197
|
* @param {Object} prototype Target prototype
|
|
198
198
|
* @param {string} oneofName OneOf name
|
|
199
199
|
* @returns {undefined}
|
|
200
|
+
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
200
201
|
*/
|
|
201
202
|
|
|
202
203
|
/**
|
|
@@ -205,6 +206,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
|
|
|
205
206
|
* @param {...string} fieldNames Field names
|
|
206
207
|
* @returns {OneOfDecorator} Decorator function
|
|
207
208
|
* @template T extends string
|
|
209
|
+
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
208
210
|
*/
|
|
209
211
|
OneOf.d = function decorateOneOf() {
|
|
210
212
|
var fieldNames = new Array(arguments.length),
|