@protobuf-ts/runtime
Advanced tools
Comparing version 2.0.7 to 2.1.0
@@ -24,25 +24,17 @@ "use strict"; | ||
const json = {}, source = message; | ||
for (const field of this.fields.filter(f => !f.oneof)) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
if (jsonValue !== undefined) | ||
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; | ||
} | ||
// flatten all oneof`s | ||
for (const field of this.fields) { | ||
if (!field.oneof) | ||
// field is not part of a oneof, simply write as is | ||
if (!field.oneof) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
if (jsonValue !== undefined) | ||
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; | ||
continue; | ||
} | ||
// field is part of a oneof | ||
const group = source[field.oneof]; | ||
if (group.oneofKind !== field.localName) | ||
// if field is not selected, skip | ||
continue; | ||
let jsonValue = undefined; | ||
if (field.kind == 'scalar' || field.kind == 'enum') | ||
// for a selected oneof member, we must emit the default value | ||
jsonValue = this.field(field, group[field.localName], { | ||
enumAsInteger: options.enumAsInteger, | ||
useProtoFieldName: options.useProtoFieldName, | ||
emitDefaultValues: true | ||
}); | ||
else | ||
jsonValue = this.field(field, group[field.localName], options); | ||
continue; // not selected, skip | ||
const opt = field.kind == 'scalar' || field.kind == 'enum' | ||
? Object.assign(Object.assign({}, options), { emitDefaultValues: true }) : options; | ||
let jsonValue = this.field(field, group[field.localName], opt); | ||
assert_1.assert(jsonValue !== undefined); | ||
@@ -49,0 +41,0 @@ json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; |
@@ -21,25 +21,17 @@ import { base64encode } from "./base64"; | ||
const json = {}, source = message; | ||
for (const field of this.fields.filter(f => !f.oneof)) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
if (jsonValue !== undefined) | ||
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; | ||
} | ||
// flatten all oneof`s | ||
for (const field of this.fields) { | ||
if (!field.oneof) | ||
// field is not part of a oneof, simply write as is | ||
if (!field.oneof) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
if (jsonValue !== undefined) | ||
json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; | ||
continue; | ||
} | ||
// field is part of a oneof | ||
const group = source[field.oneof]; | ||
if (group.oneofKind !== field.localName) | ||
// if field is not selected, skip | ||
continue; | ||
let jsonValue = undefined; | ||
if (field.kind == 'scalar' || field.kind == 'enum') | ||
// for a selected oneof member, we must emit the default value | ||
jsonValue = this.field(field, group[field.localName], { | ||
enumAsInteger: options.enumAsInteger, | ||
useProtoFieldName: options.useProtoFieldName, | ||
emitDefaultValues: true | ||
}); | ||
else | ||
jsonValue = this.field(field, group[field.localName], options); | ||
continue; // not selected, skip | ||
const opt = field.kind == 'scalar' || field.kind == 'enum' | ||
? Object.assign(Object.assign({}, options), { emitDefaultValues: true }) : options; | ||
let jsonValue = this.field(field, group[field.localName], opt); | ||
assert(jsonValue !== undefined); | ||
@@ -46,0 +38,0 @@ json[options.useProtoFieldName ? field.name : field.jsonName] = jsonValue; |
{ | ||
"name": "@protobuf-ts/runtime", | ||
"version": "2.0.7", | ||
"version": "2.1.0", | ||
"description": "Runtime library for code generated by the protoc plugin \"protobuf-ts\"", | ||
@@ -40,3 +40,3 @@ "license": "(Apache-2.0 AND BSD-3-Clause)", | ||
}, | ||
"gitHead": "360626e838b67cbd13937c12bb9669f4de83cc25" | ||
"gitHead": "bc8be3ac6a109d66d3c602b1309e136980933c1d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340889
8661