protobufjs
Advanced tools
Comparing version
/*! | ||
* protobuf.js v8.0.4-experimental (c) 2016, daniel wirtz | ||
* compiled thu, 27 mar 2025 04:14:10 utc | ||
* protobuf.js v8.1.0-experimental (c) 2016, daniel wirtz | ||
* compiled wed, 07 may 2025 17:43:49 utc | ||
* licensed under the bsd-3-clause license | ||
@@ -5,0 +5,0 @@ * see: https://github.com/dcodeio/protobuf.js for details |
{ | ||
"name": "protobufjs", | ||
"version": "8.0.4-experimental", | ||
"version": "8.1.0-experimental", | ||
"versionScheme": "~", | ||
@@ -36,3 +36,5 @@ "description": "Protocol Buffers for JavaScript (& TypeScript).", | ||
"changelog": "node scripts/changelog -w", | ||
"coverage": "nyc tape -r ./lib/tape-adapter tests/*.js tests/node/*.js", | ||
"coverage": "npm run coverage:test && npm run coverage:report", | ||
"coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js", | ||
"coverage:report": "nyc report --reporter=lcov --reporter=text", | ||
"docs": "jsdoc -c config/jsdoc.json -R README.md --verbose --pedantic", | ||
@@ -39,0 +41,0 @@ "lint": "npm run lint:sources && npm run lint:types", |
@@ -66,8 +66,2 @@ "use strict"; | ||
/** | ||
* Unresolved values features, if any | ||
* @type {Object<string, Object<string, *>>|undefined} | ||
*/ | ||
this._valuesProtoFeatures = {}; | ||
/** | ||
* Reserved ranges, if any. | ||
@@ -92,8 +86,8 @@ * @type {Array.<number[]|string>} | ||
Enum.prototype._resolveFeatures = function _resolveFeatures(edition) { | ||
var edition = this._edition || edition; | ||
edition = this._edition || edition; | ||
ReflectionObject.prototype._resolveFeatures.call(this, edition); | ||
Object.keys(this._valuesProtoFeatures).forEach(key => { | ||
Object.keys(this.values).forEach(key => { | ||
var parentFeaturesCopy = Object.assign({}, this._features); | ||
this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this._valuesProtoFeatures[key] || {}); | ||
this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features); | ||
}); | ||
@@ -184,19 +178,4 @@ | ||
this.valuesOptions[name] = options || null; | ||
for (var key of Object.keys(this.valuesOptions)) { | ||
var features = Array.isArray(this.valuesOptions[key]) ? this.valuesOptions[key].find(x => {return Object.prototype.hasOwnProperty.call(x, "features");}) : this.valuesOptions[key] === "features"; | ||
if (features) { | ||
this._valuesProtoFeatures[key] = features.features; | ||
} else { | ||
this._valuesProtoFeatures[key] = {}; | ||
} | ||
} | ||
} | ||
for (var enumValue of Object.keys(this.values)) { | ||
if (!this._valuesProtoFeatures[enumValue]) { | ||
this._valuesProtoFeatures[enumValue] = {}; | ||
} | ||
} | ||
this.comments[name] = comment || null; | ||
@@ -203,0 +182,0 @@ return this; |
@@ -369,12 +369,18 @@ "use strict"; | ||
if (edition !== "proto2" && edition !== "proto3") { | ||
return; | ||
return {}; | ||
} | ||
var features = {}; | ||
this.resolve(); | ||
if (this.rule === "required") { | ||
features.field_presence = "LEGACY_REQUIRED"; | ||
} | ||
if (this.resolvedType instanceof Type && this.resolvedType.group) { | ||
features.message_encoding = "DELIMITED"; | ||
if (this.parent && types.defaults[this.type] === undefined) { | ||
// We can't use resolvedType because types may not have been resolved yet. However, | ||
// legacy groups are always in the same scope as the field so we don't have to do a | ||
// full scan of the tree. | ||
var type = this.parent.get(this.type.split(".").pop()); | ||
if (type && type instanceof Type && type.group) { | ||
features.message_encoding = "DELIMITED"; | ||
} | ||
} | ||
@@ -381,0 +387,0 @@ if (this.getOption("packed") === true) { |
@@ -101,5 +101,5 @@ "use strict"; | ||
// Set up possibly cyclic reflection dependencies | ||
protobuf.ReflectionObject._configure(protobuf.Root, protobuf.Namespace); | ||
protobuf.ReflectionObject._configure(protobuf.Root); | ||
protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum); | ||
protobuf.Root._configure(protobuf.Type); | ||
protobuf.Field._configure(protobuf.Type); |
@@ -327,3 +327,3 @@ "use strict"; | ||
Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) { | ||
var edition = this._edition || edition; | ||
edition = this._edition || edition; | ||
@@ -330,0 +330,0 @@ ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition); |
@@ -9,3 +9,3 @@ "use strict"; | ||
var Root, Namespace; // cyclic | ||
var Root; // cyclic | ||
@@ -200,2 +200,3 @@ /* eslint-disable no-warning-comments */ | ||
/* istanbul ignore if */ | ||
if (!edition) { | ||
@@ -210,2 +211,3 @@ throw new Error("Unknown edition for " + this.fullName); | ||
// For a namespace marked with a specific edition, reset defaults. | ||
/* istanbul ignore else */ | ||
if (edition === "proto2") { | ||
@@ -226,2 +228,3 @@ defaults = Object.assign({}, proto2Defaults); | ||
// special-case it | ||
/* istanbul ignore else */ | ||
if (this.partOf instanceof OneOf) { | ||
@@ -236,3 +239,3 @@ var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features); | ||
} else { | ||
this._features = Object.assign({}, protoFeatures); | ||
throw new Error("Unable to find a parent for " + this.fullName); | ||
} | ||
@@ -276,9 +279,3 @@ if (this.extensionField) { | ||
this.options = {}; | ||
if (name === "features") { | ||
if (ifNotSet) { | ||
this.options.features = Object.assign(Object.assign({}, value), this.options.features || {}); | ||
} else { | ||
this.options.features = Object.assign(this.options.features || {}, value); | ||
} | ||
} else if (/^features\./.test(name)) { | ||
if (/^features\./.test(name)) { | ||
util.setProperty(this.options, name, value, ifNotSet); | ||
@@ -304,3 +301,2 @@ } else if (!ifNotSet || this.options[name] === undefined) { | ||
} | ||
var isFeature = /^features$/.test(name); | ||
var parsedOptions = this.parsedOptions; | ||
@@ -370,8 +366,7 @@ if (propName) { | ||
return this._edition; | ||
} | ||
}; | ||
// Sets up cyclic dependencies (called in index-light) | ||
ReflectionObject._configure = function(Root_, Namespace_) { | ||
ReflectionObject._configure = function(Root_) { | ||
Root = Root_; | ||
Namespace = Namespace_; | ||
}; |
@@ -83,5 +83,3 @@ "use strict"; | ||
weakImports, | ||
edition = "proto2", | ||
isProto3 = false, | ||
isProto2 = true; | ||
edition = "proto2"; | ||
@@ -100,3 +98,3 @@ var ptr = root; | ||
if (obj.getOption(opt) !== undefined) return; | ||
obj.setOption(opt, topLevelOptions[opt]); | ||
obj.setOption(opt, topLevelOptions[opt], true); | ||
}); | ||
@@ -156,9 +154,13 @@ }); | ||
do { | ||
if (acceptStrings && ((token = peek()) === "\"" || token === "'")) | ||
target.push(readString()); | ||
else { | ||
if (acceptStrings && ((token = peek()) === "\"" || token === "'")) { | ||
var str = readString(); | ||
target.push(str); | ||
if (edition >= 2023) { | ||
throw illegal(str, "id"); | ||
} | ||
} else { | ||
try { | ||
target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]); | ||
} catch (err) { | ||
if (typeRefRe.test(token) && (!isProto2 && !isProto3)) { | ||
if (acceptStrings && typeRefRe.test(token) && edition >= 2023) { | ||
target.push(token); | ||
@@ -284,7 +286,5 @@ } else { | ||
edition = readString(); | ||
isProto3 = edition === "proto3"; | ||
isProto2 = edition === "proto2"; | ||
/* istanbul ignore if */ | ||
if (!isProto3 && !isProto2) | ||
if (edition < 2023) | ||
throw illegal(edition, "syntax"); | ||
@@ -298,4 +298,2 @@ | ||
edition = readString(); | ||
isProto3 = false; | ||
isProto2 = false; | ||
const supportedEditions = ["2023"]; | ||
@@ -378,3 +376,3 @@ | ||
case "required": | ||
if (!isProto2) | ||
if (edition !== "proto2") | ||
throw illegal(token); | ||
@@ -388,5 +386,5 @@ /* eslint-disable no-fallthrough */ | ||
/* istanbul ignore if */ | ||
if (isProto3) { | ||
if (edition === "proto3") { | ||
parseField(type, "proto3_optional"); | ||
} else if (!isProto2) { | ||
} else if (edition !== "proto2") { | ||
throw illegal(token); | ||
@@ -412,3 +410,3 @@ } else { | ||
/* istanbul ignore if */ | ||
if (isProto2 || !typeRefRe.test(token)) { | ||
if (edition === "proto2" || !typeRefRe.test(token)) { | ||
throw illegal(token); | ||
@@ -489,2 +487,5 @@ } | ||
function parseGroup(parent, rule) { | ||
if (edition >= 2023) { | ||
throw illegal("group"); | ||
} | ||
var name = next(); | ||
@@ -519,3 +520,3 @@ | ||
/* istanbul ignore if */ | ||
if (isProto3) { | ||
if (edition === "proto3") { | ||
parseField(type, "proto3_optional"); | ||
@@ -618,2 +619,3 @@ } else { | ||
readRanges(enm.reserved || (enm.reserved = []), true); | ||
if(enm.reserved === undefined) enm.reserved = []; | ||
break; | ||
@@ -642,14 +644,9 @@ | ||
}; | ||
dummy.getOption = function(name) { | ||
return this.options[name]; | ||
}; | ||
dummy.setOption = function(name, value) { | ||
if (this.options === undefined) | ||
this.options = {}; | ||
this.options[name] = value; | ||
ReflectionObject.prototype.setOption.call(dummy, name, value); | ||
}; | ||
dummy.setParsedOption = function(name, value, propName) { | ||
// In order to not change existing behavior, only calling | ||
// this for features | ||
if (/^features$/.test(name)) { | ||
return ReflectionObject.prototype.setParsedOption.call(dummy, name, value, propName); | ||
} | ||
dummy.setParsedOption = function() { | ||
return undefined; | ||
@@ -885,3 +882,3 @@ }; | ||
/* istanbul ignore if */ | ||
if (isProto3) { | ||
if (edition === "proto3") { | ||
parseField(parent, "proto3_optional", reference); | ||
@@ -895,3 +892,3 @@ } else { | ||
/* istanbul ignore if */ | ||
if (isProto2 || !typeRefRe.test(token)) | ||
if (edition === "proto2" || !typeRefRe.test(token)) | ||
throw illegal(token); | ||
@@ -898,0 +895,0 @@ push(token); |
@@ -54,3 +54,3 @@ "use strict"; | ||
root.setOptions(json.options); | ||
return root.addJSON(json.nested).resolveAll(); | ||
return root.addJSON(json.nested)._resolveFeaturesRecursive(); | ||
}; | ||
@@ -103,2 +103,5 @@ | ||
function finish(err, root) { | ||
if (root) { | ||
root._resolveFeaturesRecursive(); | ||
} | ||
/* istanbul ignore if */ | ||
@@ -113,5 +116,2 @@ if (!callback) { | ||
callback = null; | ||
if (root) { | ||
root.resolveAll(); | ||
} | ||
cb(err, root); | ||
@@ -224,4 +224,4 @@ } | ||
fetch(resolved); | ||
self.resolveAll(); | ||
if (sync) { | ||
self._resolveFeaturesRecursive(); | ||
return self; | ||
@@ -228,0 +228,0 @@ } |
@@ -124,7 +124,7 @@ "use strict"; | ||
Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) { | ||
var edition = this._edition || edition; | ||
edition = this._edition || edition; | ||
Namespace.prototype._resolveFeaturesRecursive.call(this, edition); | ||
this.methodsArray.forEach(method => { | ||
method._resolveFeaturesRecursive(edition); | ||
method._resolveFeaturesRecursive(edition); | ||
}); | ||
@@ -131,0 +131,0 @@ return this; |
@@ -237,3 +237,3 @@ "use strict"; | ||
*/ | ||
Type.fromJSON = function fromJSON(name, json, nested) { | ||
Type.fromJSON = function fromJSON(name, json) { | ||
var type = new Type(name, json.options); | ||
@@ -321,10 +321,10 @@ type.extensions = json.extensions; | ||
Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) { | ||
var edition = this._edition || edition; | ||
edition = this._edition || edition; | ||
Namespace.prototype._resolveFeaturesRecursive.call(this, edition); | ||
this.oneofsArray.forEach(oneof => { | ||
oneof._resolveFeatures(edition); | ||
oneof._resolveFeatures(edition); | ||
}); | ||
this.fieldsArray.forEach(field => { | ||
field._resolveFeatures(edition); | ||
field._resolveFeatures(edition); | ||
}); | ||
@@ -331,0 +331,0 @@ return this; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
2881788
-0.24%30386
-0.2%