ts-proto 1.169.1 → 1.170.0

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/main.js CHANGED
@@ -895,7 +895,7 @@ function generateDecode(ctx, fullName, messageDesc) {
895
895
  const initializerNecessary = !options.initializeFieldsAsUndefined &&
896
896
  (0, types_1.isOptionalProperty)(field, messageDesc.options, options, currentFile.isProto3Syntax);
897
897
  if ((0, types_1.isRepeated)(field)) {
898
- const maybeNonNullAssertion = ctx.options.useOptionals === "all" ? "!" : "";
898
+ const maybeNonNullAssertion = ctx.options.useOptionals === "all" || ctx.options.useOptionals === "deprecatedOnly" ? "!" : "";
899
899
  const mapType = (0, types_1.detectMapType)(ctx, messageDesc, field);
900
900
  if (mapType) {
901
901
  // We need a unique const within the `cast` statement
package/build/types.js CHANGED
@@ -330,15 +330,20 @@ function isScalar(field) {
330
330
  }
331
331
  exports.isScalar = isScalar;
332
332
  // When useOptionals='messages', non-scalar fields are translated into optional
333
- // properties. When useOptionals='all', all fields are translated into
333
+ // properties.
334
+ // When useOptionals='all', all fields are translated into
335
+ // optional properties, with the exception of map Entry key/values, which must
336
+ // always be present.
337
+ // When useOptionals='deprecatedOnly', all deprecated fields are translated into
334
338
  // optional properties, with the exception of map Entry key/values, which must
335
339
  // always be present.
336
340
  // OneOf fields are always optional, whenever oneof=unions option not in use.
337
341
  function isOptionalProperty(field, messageOptions, options, isProto3Syntax) {
338
342
  const optionalMessages = options.useOptionals === true || options.useOptionals === "messages" || options.useOptionals === "all";
339
343
  const optionalAll = options.useOptionals === "all";
344
+ const deprecatedOnly = options.useOptionals === "deprecatedOnly" && field.options && field.options.deprecated;
340
345
  return ((optionalMessages && isMessage(field) && !isRepeated(field)) ||
341
- (optionalAll && !(messageOptions === null || messageOptions === void 0 ? void 0 : messageOptions.mapEntry)) ||
346
+ ((optionalAll || deprecatedOnly) && !(messageOptions === null || messageOptions === void 0 ? void 0 : messageOptions.mapEntry)) ||
342
347
  // file is proto2, we have enabled proto2 optionals, and the field itself is optional
343
348
  (!isProto3Syntax &&
344
349
  field.label === ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_OPTIONAL &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.169.1",
3
+ "version": "1.170.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",