ts-proto 1.159.0 → 1.159.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
@@ -325,8 +325,8 @@ Generated code will be placed in the Gradle build directory.
325
325
 
326
326
  ```typescript
327
327
  interface SomeMessage {
328
- firstName: string | undefined;
329
- lastName: string | undefined;
328
+ firstName: string;
329
+ lastName: string;
330
330
  }
331
331
  // Declared with a typo
332
332
  const data = { firstName: "a", lastTypo: "b" };
@@ -334,13 +334,13 @@ Generated code will be placed in the Gradle build directory.
334
334
  const message: SomeMessage = { ...data };
335
335
  ```
336
336
 
337
- For a consistent API, if `SomeMessage.lastName` is optional `lastName?`, then readers have to check _two_ empty conditions: a) is `lastName` `undefined` (b/c it was created in-memory and left unset), or b) is `lastName` empty string (b/c we read `SomeMessage` off the wire and correctly set `lastName` to empty string)?
337
+ For a consistent API, if `SomeMessage.lastName` is optional `lastName?`, then readers have to check _two_ empty conditions: a) is `lastName` `undefined` (b/c it was created in-memory and left unset), or b) is `lastName` empty string (b/c we read `SomeMessage` off the wire and, per the proto3 spec, initialized `lastName` to empty string)?
338
338
 
339
339
  For ensuring proper initialization, if later `SomeMessage.middleInitial` is added, but it's marked as optional `middleInitial?`, you may have many call sites in production code that _should_ now be passing `middleInitial` to create a valid `SomeMessage`, but are not.
340
340
 
341
341
  So, between typo-prevention, reader inconsistency, and proper initialization, ts-proto recommends using `useOptionals=none` as the "most safe" option.
342
342
 
343
- All that said, this approach does require writers/creators to set every field (although `fromPartial` and `create` are meant to address this), so if you still want to have optional fields, you can set `useOptionals=messages` or `useOptionals=all`.
343
+ All that said, this approach does require writers/creators to set every field (although `fromPartial` and `create` are meant to address this), so if you still want to have optional keys, you can set `useOptionals=messages` or `useOptionals=all`.
344
344
 
345
345
  (See [this issue](https://github.com/stephenh/ts-proto/issues/120#issuecomment-678375833) and [this issue](https://github.com/stephenh/ts-proto/issues/397#issuecomment-977259118) for discussions on `useOptional`.)
346
346
 
package/build/main.js CHANGED
@@ -424,8 +424,8 @@ function makeDeepPartial(options, longs) {
424
424
  ${maybeExport} type DeepPartial<T> = T extends ${Builtin}
425
425
  ? T
426
426
  ${maybeLong}
427
- : T extends Array<infer U>
428
- ? Array<DeepPartial<U>>
427
+ : T extends globalThis.Array<infer U>
428
+ ? globalThis.Array<DeepPartial<U>>
429
429
  : T extends ReadonlyArray<infer U>
430
430
  ? ReadonlyArray<DeepPartial<U>>${oneofCase}
431
431
  : T extends {}
@@ -1438,7 +1438,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1438
1438
  }
1439
1439
  else {
1440
1440
  const cstr = (0, case_1.capitalize)((0, types_1.basicTypeName)(ctx, field, { keepValueType: true }).toCodeString([]));
1441
- return (0, ts_poet_1.code) `${cstr}(${from})`;
1441
+ return (0, ts_poet_1.code) `${utils.globalThis}.${cstr}(${from})`;
1442
1442
  }
1443
1443
  }
1444
1444
  else if ((0, types_1.isObjectId)(field) && options.useMongoObjectId) {
@@ -1870,7 +1870,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
1870
1870
  }
1871
1871
  else {
1872
1872
  const cstr = (0, case_1.capitalize)(valueType.toCodeString([]));
1873
- return (0, ts_poet_1.code) `${cstr}(${from})`;
1873
+ return (0, ts_poet_1.code) `${utils.globalThis}.${cstr}(${from})`;
1874
1874
  }
1875
1875
  }
1876
1876
  else if ((0, types_1.isAnyValueType)(valueField)) {
@@ -1995,6 +1995,9 @@ function convertFromObjectKey(ctx, messageDesc, field, variableName) {
1995
1995
  return (0, ts_poet_1.code) `${ctx.utils.globalThis}.Number(${variableName})`;
1996
1996
  }
1997
1997
  }
1998
+ else if (keyField.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_BOOL) {
1999
+ return (0, ts_poet_1.code) `${ctx.utils.globalThis}.Boolean(${variableName})`;
2000
+ }
1998
2001
  else {
1999
2002
  return (0, ts_poet_1.code) `${ctx.utils.globalThis}.Number(${variableName})`;
2000
2003
  }
@@ -2015,6 +2018,9 @@ function convertToObjectKey(ctx, messageDesc, field, variableName) {
2015
2018
  return (0, ts_poet_1.code) `${variableName}`;
2016
2019
  }
2017
2020
  }
2021
+ else if (keyField.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_BOOL) {
2022
+ return (0, ts_poet_1.code) `${ctx.utils.globalThis}.String(${variableName})`;
2023
+ }
2018
2024
  else {
2019
2025
  return (0, ts_poet_1.code) `${variableName}`;
2020
2026
  }
package/build/types.js CHANGED
@@ -642,7 +642,8 @@ function shouldGenerateJSMapType(ctx, message, field) {
642
642
  if (!mapType) {
643
643
  return false;
644
644
  }
645
- return isLong(mapType.keyField) && ctx.options.forceLong === options_1.LongOption.LONG;
645
+ return (mapType.keyField.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_BOOL ||
646
+ (isLong(mapType.keyField) && ctx.options.forceLong === options_1.LongOption.LONG));
646
647
  }
647
648
  exports.shouldGenerateJSMapType = shouldGenerateJSMapType;
648
649
  function detectMapType(ctx, messageDesc, fieldDesc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.159.0",
3
+ "version": "1.159.2",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",