ts-proto 1.115.1 → 1.115.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.115.2](https://github.com/stephenh/ts-proto/compare/v1.115.1...v1.115.2) (2022-06-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * simplify handling useJsonWireFormat=true and fix onlyTypes=true ([#583](https://github.com/stephenh/ts-proto/issues/583)) ([6e7f938](https://github.com/stephenh/ts-proto/commit/6e7f9387d144f506ded982604f32981ac5e327de))
7
+
1
8
  ## [1.115.1](https://github.com/stephenh/ts-proto/compare/v1.115.0...v1.115.1) (2022-06-02)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -396,7 +396,7 @@ Generated code will be placed in the Gradle build directory.
396
396
 
397
397
  - With `--ts_proto_opt=onlyTypes=true`, only types will be emitted, and imports for `long` and `protobufjs/minimal` will be excluded.
398
398
 
399
- Note: _This is a combination_ of `outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false,nestJs=false`
399
+ This is the same as setting `outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false,nestJs=false`
400
400
 
401
401
  - With `--ts_proto_opt=usePrototypeForDefaults=true`, the generated code will wrap new objects with `Object.create`.
402
402
 
@@ -411,12 +411,6 @@ Generated code will be placed in the Gradle build directory.
411
411
  Requires `onlyTypes=true`. Implies `useDate=string` and `stringEnums=true`. This option is to generate types that can be directly used with marshalling/unmarshalling Protobuf messages serialized as JSON.
412
412
  You may also want to set `useOptionals=all`, as gRPC gateways are not required to send default value for scalar values.
413
413
 
414
- ### Only Types
415
-
416
- If you're looking for `ts-proto` to generate only types for your Protobuf types then passing all three of `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` as `false` is probably what you want, i.e.:
417
-
418
- `--ts_proto_opt=onlyTypes=true`.
419
-
420
414
  ### NestJS Support
421
415
 
422
416
  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/enums.js CHANGED
@@ -20,16 +20,15 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
20
20
  chunks.push(ts_poet_1.code `export ${options.constEnums ? 'const ' : ''}enum ${ts_poet_1.def(fullName)} {`);
21
21
  }
22
22
  const delimiter = options.enumsAsLiterals ? ':' : '=';
23
- const stringEnums = options.stringEnums || (options.onlyTypes && options.useJsonWireFormat);
24
23
  enumDesc.value.forEach((valueDesc, index) => {
25
24
  var _a;
26
25
  const info = sourceInfo.lookup(sourceInfo_1.Fields.enum.value, index);
27
26
  utils_1.maybeAddComment(info, chunks, (_a = valueDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated, `${valueDesc.name} - `);
28
- chunks.push(ts_poet_1.code `${valueDesc.name} ${delimiter} ${stringEnums ? `"${valueDesc.name}"` : valueDesc.number.toString()},`);
27
+ chunks.push(ts_poet_1.code `${valueDesc.name} ${delimiter} ${options.stringEnums ? `"${valueDesc.name}"` : valueDesc.number.toString()},`);
29
28
  });
30
29
  if (options.unrecognizedEnum)
31
30
  chunks.push(ts_poet_1.code `
32
- ${UNRECOGNIZED_ENUM_NAME} ${delimiter} ${stringEnums ? `"${UNRECOGNIZED_ENUM_NAME}"` : UNRECOGNIZED_ENUM_VALUE.toString()},`);
31
+ ${UNRECOGNIZED_ENUM_NAME} ${delimiter} ${options.stringEnums ? `"${UNRECOGNIZED_ENUM_NAME}"` : UNRECOGNIZED_ENUM_VALUE.toString()},`);
33
32
  if (options.enumsAsLiterals) {
34
33
  chunks.push(ts_poet_1.code `} as const`);
35
34
  chunks.push(ts_poet_1.code `\n`);
@@ -38,7 +37,7 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
38
37
  else {
39
38
  chunks.push(ts_poet_1.code `}`);
40
39
  }
41
- if (options.outputJsonMethods || (stringEnums && options.outputEncodeMethods)) {
40
+ if (options.outputJsonMethods || (options.stringEnums && options.outputEncodeMethods)) {
42
41
  chunks.push(ts_poet_1.code `\n`);
43
42
  chunks.push(generateEnumFromJson(ctx, fullName, enumDesc));
44
43
  }
@@ -46,7 +45,7 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
46
45
  chunks.push(ts_poet_1.code `\n`);
47
46
  chunks.push(generateEnumToJson(ctx, fullName, enumDesc));
48
47
  }
49
- if (stringEnums && options.outputEncodeMethods) {
48
+ if (options.stringEnums && options.outputEncodeMethods) {
50
49
  chunks.push(ts_poet_1.code `\n`);
51
50
  chunks.push(generateEnumToNumber(ctx, fullName, enumDesc));
52
51
  }
package/build/options.js CHANGED
@@ -88,8 +88,17 @@ function optionsFromParameter(parameter) {
88
88
  }
89
89
  Object.assign(options, parsed);
90
90
  }
91
- // We should promote onlyTypes to its own documented flag, but just an alias for now
92
- if (!options.outputJsonMethods && !options.outputEncodeMethods && !options.outputClientImpl && !options.nestJs) {
91
+ // onlyTypes=true implies outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false,nestJs=false
92
+ if (options.onlyTypes) {
93
+ options.outputJsonMethods = false;
94
+ options.outputEncodeMethods = false;
95
+ options.outputClientImpl = false;
96
+ options.nestJs = false;
97
+ }
98
+ else if (!options.outputJsonMethods &&
99
+ !options.outputEncodeMethods &&
100
+ !options.outputClientImpl &&
101
+ !options.nestJs) {
93
102
  options.onlyTypes = true;
94
103
  }
95
104
  // Treat forceLong=true as LONG
@@ -124,6 +133,17 @@ function optionsFromParameter(parameter) {
124
133
  else if (typeof options.snakeToCamel === 'string') {
125
134
  options.snakeToCamel = [options.snakeToCamel];
126
135
  }
136
+ if (options.useJsonWireFormat) {
137
+ if (!options.onlyTypes) {
138
+ // useJsonWireFormat requires onlyTypes=true
139
+ options.useJsonWireFormat = false;
140
+ }
141
+ else {
142
+ // useJsonWireFormat implies stringEnums=true and useDate=string
143
+ options.stringEnums = true;
144
+ options.useDate = DateOption.STRING;
145
+ }
146
+ }
127
147
  return options;
128
148
  }
129
149
  exports.optionsFromParameter = optionsFromParameter;
package/build/types.js CHANGED
@@ -436,7 +436,6 @@ function isEmptyType(typeName) {
436
436
  }
437
437
  exports.isEmptyType = isEmptyType;
438
438
  function valueTypeName(ctx, typeName) {
439
- const useJsonWireFormat = ctx.options.onlyTypes && ctx.options.useJsonWireFormat;
440
439
  switch (typeName) {
441
440
  case '.google.protobuf.StringValue':
442
441
  return ts_poet_1.code `string`;
@@ -452,7 +451,11 @@ function valueTypeName(ctx, typeName) {
452
451
  case '.google.protobuf.BoolValue':
453
452
  return ts_poet_1.code `boolean`;
454
453
  case '.google.protobuf.BytesValue':
455
- return ctx.options.env === options_1.EnvOption.NODE ? ts_poet_1.code `Buffer` : useJsonWireFormat ? ts_poet_1.code `string` : ts_poet_1.code `Uint8Array`;
454
+ return ctx.options.env === options_1.EnvOption.NODE
455
+ ? ts_poet_1.code `Buffer`
456
+ : ctx.options.useJsonWireFormat
457
+ ? ts_poet_1.code `string`
458
+ : ts_poet_1.code `Uint8Array`;
456
459
  case '.google.protobuf.ListValue':
457
460
  return ts_poet_1.code `Array<any>`;
458
461
  case '.google.protobuf.Value':
@@ -460,11 +463,11 @@ function valueTypeName(ctx, typeName) {
460
463
  case '.google.protobuf.Struct':
461
464
  return ts_poet_1.code `{[key: string]: any}`;
462
465
  case '.google.protobuf.FieldMask':
463
- return useJsonWireFormat ? ts_poet_1.code `string` : ts_poet_1.code `string[]`;
466
+ return ctx.options.useJsonWireFormat ? ts_poet_1.code `string` : ts_poet_1.code `string[]`;
464
467
  case '.google.protobuf.Duration':
465
- return useJsonWireFormat ? ts_poet_1.code `string` : undefined;
468
+ return ctx.options.useJsonWireFormat ? ts_poet_1.code `string` : undefined;
466
469
  case '.google.protobuf.Timestamp':
467
- return useJsonWireFormat ? ts_poet_1.code `string` : undefined;
470
+ return ctx.options.useJsonWireFormat ? ts_poet_1.code `string` : undefined;
468
471
  default:
469
472
  return undefined;
470
473
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.115.1",
3
+ "version": "1.115.2",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",