ts-proto 1.156.3 → 1.156.4
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/build/enums.js +2 -1
- package/build/types.js +10 -4
- package/package.json +1 -1
package/build/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateEnumToNumber = exports.generateEnumToJson = exports.generateEnumFromJson = exports.generateEnum = void 0;
|
|
3
|
+
exports.getMemberName = exports.generateEnumToNumber = exports.generateEnumToJson = exports.generateEnumFromJson = exports.generateEnum = void 0;
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const case_1 = require("./case");
|
|
@@ -171,6 +171,7 @@ function getMemberName(ctx, fullName, valueDesc) {
|
|
|
171
171
|
}
|
|
172
172
|
return valueDesc.name;
|
|
173
173
|
}
|
|
174
|
+
exports.getMemberName = getMemberName;
|
|
174
175
|
function getValueName(ctx, fullName, valueDesc) {
|
|
175
176
|
return valueDesc.name;
|
|
176
177
|
}
|
package/build/types.js
CHANGED
|
@@ -8,6 +8,7 @@ const visit_1 = require("./visit");
|
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const sourceInfo_1 = require("./sourceInfo");
|
|
10
10
|
const case_1 = require("./case");
|
|
11
|
+
const enums_1 = require("./enums");
|
|
11
12
|
/** Based on https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js#L37. */
|
|
12
13
|
function basicWireType(type) {
|
|
13
14
|
switch (type) {
|
|
@@ -179,11 +180,13 @@ function defaultValue(ctx, field) {
|
|
|
179
180
|
// to probe and see if zero is an allowed value. If it's not, pick the first one.
|
|
180
181
|
// This is probably not great, but it's only used in fromJSON and fromPartial,
|
|
181
182
|
// and I believe the semantics of those in the proto2 world are generally undefined.
|
|
182
|
-
const
|
|
183
|
+
const typeInfo = typeMap.get(field.typeName);
|
|
184
|
+
const enumProto = typeInfo[2];
|
|
185
|
+
const enumFullName = typeInfo[1];
|
|
183
186
|
const zerothValue = enumProto.value.find((v) => v.number === 0) || enumProto.value[0];
|
|
184
187
|
if (options.stringEnums) {
|
|
185
188
|
const enumType = messageToTypeName(ctx, field.typeName);
|
|
186
|
-
return (0, ts_poet_1.code) `${enumType}.${zerothValue
|
|
189
|
+
return (0, ts_poet_1.code) `${enumType}.${(0, enums_1.getMemberName)(ctx, enumFullName, zerothValue)}`;
|
|
187
190
|
}
|
|
188
191
|
else {
|
|
189
192
|
return zerothValue.number;
|
|
@@ -254,11 +257,14 @@ function notDefaultCheck(ctx, field, messageOptions, place) {
|
|
|
254
257
|
// to probe and see if zero is an allowed value. If it's not, pick the first one.
|
|
255
258
|
// This is probably not great, but it's only used in fromJSON and fromPartial,
|
|
256
259
|
// and I believe the semantics of those in the proto2 world are generally undefined.
|
|
257
|
-
const
|
|
260
|
+
const typeInfo = typeMap.get(field.typeName);
|
|
261
|
+
const enumProto = typeInfo[2];
|
|
262
|
+
const enumFullName = typeInfo[1];
|
|
258
263
|
const zerothValue = enumProto.value.find((v) => v.number === 0) || enumProto.value[0];
|
|
259
264
|
if (options.stringEnums) {
|
|
260
265
|
const enumType = messageToTypeName(ctx, field.typeName);
|
|
261
|
-
|
|
266
|
+
const enumValue = (0, enums_1.getMemberName)(ctx, enumFullName, zerothValue);
|
|
267
|
+
return (0, ts_poet_1.code) `${maybeNotUndefinedAnd} ${place} !== ${enumType}.${enumValue}`;
|
|
262
268
|
}
|
|
263
269
|
else {
|
|
264
270
|
return (0, ts_poet_1.code) `${maybeNotUndefinedAnd} ${place} !== ${zerothValue.number}`;
|