ts-proto 2.8.1 → 2.8.2
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.markdown +10 -0
- package/build/src/enums.js +9 -2
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -392,6 +392,16 @@ Generated code will be placed in the Gradle build directory.
|
|
|
392
392
|
|
|
393
393
|
`FooBar.FOO_BAR_BAZ = "FOO_BAR_BAZ"` will generate `FooBar.BAZ = "FOO_BAR_BAZ"`
|
|
394
394
|
|
|
395
|
+
If any value in the enum would be made invalid by removing the enum name, the enum name will be present for all the values in the enum.
|
|
396
|
+
|
|
397
|
+
`FooBar.FOO_BAR_1 = "FOO_BAR_BAZ"` will generate `FooBar.FOO_BAR_1 = "FOO_BAR_BAZ"`
|
|
398
|
+
|
|
399
|
+
`FooBar.FOO_BAR_1A = "FOO_BAR_BAZ"` will generate `FooBar.FOO_BAR_1A = "FOO_BAR_BAZ"`
|
|
400
|
+
|
|
401
|
+
`FooBar.FOO_BAR_Infinity = "FOO_BAR_BAZ"` will generate `FooBar.FOO_BAR_Infinity = "FOO_BAR_BAZ"` (this is technically valid but is likely to lead to downstream issues)
|
|
402
|
+
|
|
403
|
+
`FooBar.FOO_BAR_INFINITY = "FOO_BAR_BAZ"` will generate `FooBar.INFINITY = "FOO_BAR_BAZ"`
|
|
404
|
+
|
|
395
405
|
- With `--ts_proto_opt=lowerCaseServiceMethods=true`, the method names of service methods will be lowered/camel-case, i.e. `service.findFoo` instead of `service.FindFoo`.
|
|
396
406
|
|
|
397
407
|
- With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case in both the message keys and the `toJSON` / `fromJSON` methods.
|
package/build/src/enums.js
CHANGED
|
@@ -208,9 +208,16 @@ function generateEnumToNumber(ctx, fullName, enumDesc, unrecognizedEnum) {
|
|
|
208
208
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
209
209
|
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
210
210
|
}
|
|
211
|
+
const withoutEnumPrefix = (valueName, enumName) => valueName.replace(`${(0, case_1.camelToSnake)(enumName)}_`, "");
|
|
212
|
+
const isNumeric = (str) => !isNaN(Number(str));
|
|
211
213
|
function getMemberName(ctx, enumDesc, valueDesc) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
const areAnyMembersNumericWithoutPrefix = enumDesc.value.some((v) => {
|
|
215
|
+
const withoutPrefix = withoutEnumPrefix(v.name, enumDesc.name);
|
|
216
|
+
return isNumeric(withoutPrefix) || isNumeric(withoutPrefix[0]);
|
|
217
|
+
});
|
|
218
|
+
const nameWithoutPrefix = withoutEnumPrefix(valueDesc.name, enumDesc.name);
|
|
219
|
+
if (ctx.options.removeEnumPrefix && !areAnyMembersNumericWithoutPrefix) {
|
|
220
|
+
return nameWithoutPrefix;
|
|
214
221
|
}
|
|
215
222
|
return valueDesc.name;
|
|
216
223
|
}
|