ts-proto 1.124.0 → 1.125.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.125.0](https://github.com/stephenh/ts-proto/compare/v1.124.0...v1.125.0) (2022-09-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * omit optional fields in base instance ([#669](https://github.com/stephenh/ts-proto/issues/669)) ([47b60aa](https://github.com/stephenh/ts-proto/commit/47b60aab95533542cf762f152138f7ab4234de88))
7
+
1
8
  # [1.124.0](https://github.com/stephenh/ts-proto/compare/v1.123.1...v1.124.0) (2022-09-03)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -448,6 +448,8 @@ Generated code will be placed in the Gradle build directory.
448
448
 
449
449
  - With `--ts_proto_opt=useNumericEnumForJson=true`, the JSON converter (`toJSON`) will encode enum values as int, rather than a string literal.
450
450
 
451
+ - With `--ts_proto_opt=initializeFieldsAsUndefined=false`, all optional field initializers will be omited from the generated base instances.
452
+
451
453
  ### NestJS Support
452
454
 
453
455
  We have a great way of working together with [nestjs](https://docs.nestjs.com/microservices/grpc). `ts-proto` generates `interfaces` and `decorators` for you controller, client. For more information see the [nestjs readme](NESTJS.markdown).
package/build/main.js CHANGED
@@ -549,6 +549,7 @@ function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
549
549
  }
550
550
  // Create a function that constructs 'base' instance with default values for decode to use as a prototype
551
551
  function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
552
+ const { options } = ctx;
552
553
  const fields = [];
553
554
  // When oneof=unions, we generate a single property with an ADT per `oneof` clause.
554
555
  const processedOneofs = new Set();
@@ -562,6 +563,9 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
562
563
  }
563
564
  continue;
564
565
  }
566
+ if (!options.initializeFieldsAsUndefined && (0, types_1.isOptionalProperty)(field, messageDesc.options, options)) {
567
+ continue;
568
+ }
565
569
  const name = (0, case_1.maybeSnakeToCamel)(field.name, ctx.options);
566
570
  const val = (0, types_1.isWithinOneOf)(field)
567
571
  ? "undefined"
package/build/options.js CHANGED
@@ -71,6 +71,7 @@ function defaultOptions() {
71
71
  usePrototypeForDefaults: false,
72
72
  useJsonWireFormat: false,
73
73
  useNumericEnumForJson: false,
74
+ initializeFieldsAsUndefined: true,
74
75
  };
75
76
  }
76
77
  exports.defaultOptions = defaultOptions;
@@ -147,6 +148,9 @@ function optionsFromParameter(parameter) {
147
148
  options.useDate = DateOption.STRING;
148
149
  }
149
150
  }
151
+ if (options.nestJs) {
152
+ options.initializeFieldsAsUndefined = false;
153
+ }
150
154
  return options;
151
155
  }
152
156
  exports.optionsFromParameter = optionsFromParameter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.124.0",
3
+ "version": "1.125.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",