proto3-json-serializer
Advanced tools
Comparing version 0.1.2 to 0.1.3
import * as protobuf from 'protobufjs'; | ||
import { JSONValue } from './types'; | ||
export declare function resolveEnumValueToString(enumType: protobuf.Enum, enumValue: JSONValue): string; | ||
export declare function resolveEnumValueToString(enumType: protobuf.Enum, enumValue: JSONValue): string | number; |
@@ -18,6 +18,10 @@ "use strict"; | ||
function resolveEnumValueToString(enumType, enumValue) { | ||
// for unknown enum values, do not fail and try to do the best we could. | ||
// protobuf.js fromObject() will likely ignore unknown values, but at least | ||
// we won't fail. | ||
if (typeof enumValue === 'number') { | ||
const value = enumType.valuesById[enumValue]; | ||
if (typeof value === 'undefined') { | ||
throw new Error(`enumFromProto3JSON: unknown value id ${enumValue}`); | ||
// unknown value, cannot convert to string, returning number as is | ||
return enumValue; | ||
} | ||
@@ -27,6 +31,3 @@ return value; | ||
if (typeof enumValue === 'string') { | ||
const id = enumType.values[enumValue]; | ||
if (typeof id === 'undefined') { | ||
throw new Error(`enumFromProto3JSON: unknown value ${enumValue}`); | ||
} | ||
// for strings, just accept what we got | ||
return enumValue; | ||
@@ -33,0 +34,0 @@ } |
# Changelog | ||
### [0.1.3](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.2...v0.1.3) (2021-08-18) | ||
### Bug Fixes | ||
* do not fail for unknown enum values ([#11](https://www.github.com/googleapis/proto3-json-serializer-nodejs/issues/11)) ([ff9f0f1](https://www.github.com/googleapis/proto3-json-serializer-nodejs/commit/ff9f0f1881b1aafacd693b4e24eaee9e56aff79c)) | ||
### [0.1.2](https://www.github.com/googleapis/proto3-json-serializer-nodejs/compare/v0.1.1...v0.1.2) (2021-08-17) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "proto3-json-serializer", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": "googleapis/proto3-json-serializer-nodejs", | ||
@@ -5,0 +5,0 @@ "description": "Support for proto3 JSON serialiazation/deserialization for protobuf.js", |
Sorry, the diff of this file is not supported yet
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
76346
906