ts-proto 2.8.1 → 2.8.3

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 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.
@@ -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
- if (ctx.options.removeEnumPrefix) {
213
- return valueDesc.name.replace(`${(0, case_1.camelToSnake)(enumDesc.name)}_`, "");
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
  }
@@ -201,7 +201,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
201
201
  chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
202
202
  const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
203
203
  if (value === null) {
204
- result.kind = {$case: '${fieldNames.nullValue}', value };
204
+ result.kind = {$case: '${fieldNames.nullValue}', value: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE};
205
205
  } else if (typeof value === 'boolean') {
206
206
  result.kind = {$case: '${fieldNames.boolValue}', value };
207
207
  } else if (typeof value === 'number') {
@@ -310,7 +310,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
310
310
  }
311
311
  else if (ctx.options.oneof === options_1.OneofOption.UNIONS_VALUE) {
312
312
  chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Value")}): string | number | boolean | Object | null | Array<any> | undefined {
313
- return message.kind?.value;
313
+ return (message.kind?.$case === '${fieldNames.nullValue}') ? null : message.kind?.value;
314
314
  }`);
315
315
  }
316
316
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",