ts-proto 2.8.0 → 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 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
  }
package/build/src/main.js CHANGED
@@ -707,12 +707,10 @@ function makeTimestampMethods(options, longs, bytes) {
707
707
  ? (0, ts_poet_1.code) `
708
708
  function toTimestamp(instant: Temporal.Instant): ${Timestamp} {
709
709
  const date = {
710
- getTime: (): number => Math.trunc(instant.epochMilliseconds / 1_000),
710
+ getTime: (): number => instant.epochMilliseconds,
711
711
  } as const;
712
712
  const seconds = ${seconds};
713
- const remainder = ${bytes.globalThis}.Temporal.Instant
714
- .fromEpochMilliseconds(instant.epochMilliseconds)
715
- .until(instant);
713
+ const remainder = instant.round({ smallestUnit: "seconds", roundingMode: "floor" }).until(instant);
716
714
  const nanos = (remainder.milliseconds * 1_000_000) + (remainder.microseconds * 1_000) + remainder.nanoseconds;
717
715
 
718
716
  return { ${maybeTypeField} seconds, nanos };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",