ts-proto 1.146.0 → 1.147.1

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
@@ -220,7 +220,7 @@ creating a class and calling the right getters/setters.
220
220
 
221
221
  - ObjectIds can be mapped as `mongodb.ObjectId`
222
222
 
223
- (Configurable with the `useObjectId` parameter.)
223
+ (Configurable with the `useMongoObjectId` parameter.)
224
224
 
225
225
  # Auto-Batching / N+1 Prevention
226
226
 
@@ -410,11 +410,13 @@ Generated code will be placed in the Gradle build directory.
410
410
 
411
411
  - With `--ts_proto_opt=useDate=false`, fields of type `google.protobuf.Timestamp` will not be mapped to type `Date` in the generated types. See [Timestamp](#timestamp) for more details.
412
412
 
413
- - With `--ts_proto_opt=useObjectId=true`, fields of a type called ObjectId where the message is constructed to have on field called value that is a string will be mapped to type `mongodb.ObjectId` in the generated types. This will require your project to install the mongodb npm package. See [ObjectId](#objectid) for more details.
413
+ - With `--ts_proto_opt=useMongoObjectId=true`, fields of a type called ObjectId where the message is constructed to have on field called value that is a string will be mapped to type `mongodb.ObjectId` in the generated types. This will require your project to install the mongodb npm package. See [ObjectId](#objectid) for more details.
414
414
 
415
415
  - With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.
416
416
 
417
- - With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will get extra `$type` field containing fully-qualified name.
417
+ - With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name.
418
+
419
+ - With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will be given a `$type` field containing its fully-qualified name.
418
420
 
419
421
  - With `--ts_proto_opt=outputServices=grpc-js`, ts-proto will output service definitions and server / client stubs in [grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) format.
420
422
 
package/build/case.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.camelCaseGrpc = exports.camelCase = exports.capitalize = exports.camelToSnake = exports.snakeToCamel = exports.maybeSnakeToCamel = void 0;
3
+ exports.camelCaseGrpc = exports.uncapitalize = exports.capitalize = exports.camelToSnake = exports.snakeToCamel = exports.maybeSnakeToCamel = void 0;
4
4
  const case_anything_1 = require("case-anything");
5
5
  /** Converts `key` to TS/JS camel-case idiom, unless overridden not to. */
6
6
  function maybeSnakeToCamel(key, options) {
@@ -32,16 +32,16 @@ function capitalize(s) {
32
32
  return s.substring(0, 1).toUpperCase() + s.substring(1);
33
33
  }
34
34
  exports.capitalize = capitalize;
35
- function camelCase(s) {
35
+ function uncapitalize(s) {
36
36
  return s.substring(0, 1).toLowerCase() + s.substring(1);
37
37
  }
38
- exports.camelCase = camelCase;
38
+ exports.uncapitalize = uncapitalize;
39
+ /* This function uses the exact same semantics found inside the grpc
40
+ * nodejs library. Camel case splitting must be done by word i.e
41
+ * GetAPIValue must become getApiValue (notice the API becomes Api).
42
+ * This needs to be followed otherwise it will not succeed in the grpc nodejs module.
43
+ */
39
44
  function camelCaseGrpc(s) {
40
- /* This function uses the exact same semantics found inside the grpc
41
- * nodejs library. Camel case splitting must be done by word i.e
42
- * GetAPIValue must become getApiValue (notice the API becomes Api).
43
- * This needs to be followed otherwise it will not succeed in the grpc nodejs module.
44
- */
45
45
  return (0, case_anything_1.camelCase)(s);
46
46
  }
47
47
  exports.camelCaseGrpc = camelCaseGrpc;
package/build/enums.js CHANGED
@@ -58,7 +58,7 @@ exports.generateEnum = generateEnum;
58
58
  function generateEnumFromJson(ctx, fullName, enumDesc) {
59
59
  const { options, utils } = ctx;
60
60
  const chunks = [];
61
- const functionName = (0, case_1.camelCase)(fullName) + "FromJSON";
61
+ const functionName = (0, case_1.uncapitalize)(fullName) + "FromJSON";
62
62
  chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: any): ${fullName} {`);
63
63
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
64
64
  for (const valueDesc of enumDesc.value) {
@@ -94,7 +94,7 @@ exports.generateEnumFromJson = generateEnumFromJson;
94
94
  function generateEnumToJson(ctx, fullName, enumDesc) {
95
95
  const { options, utils } = ctx;
96
96
  const chunks = [];
97
- const functionName = (0, case_1.camelCase)(fullName) + "ToJSON";
97
+ const functionName = (0, case_1.uncapitalize)(fullName) + "ToJSON";
98
98
  chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): ${ctx.options.useNumericEnumForJson ? "number" : "string"} {`);
99
99
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
100
100
  for (const valueDesc of enumDesc.value) {
@@ -140,7 +140,7 @@ exports.generateEnumToJson = generateEnumToJson;
140
140
  function generateEnumToNumber(ctx, fullName, enumDesc) {
141
141
  const { options, utils } = ctx;
142
142
  const chunks = [];
143
- const functionName = (0, case_1.camelCase)(fullName) + "ToNumber";
143
+ const functionName = (0, case_1.uncapitalize)(fullName) + "ToNumber";
144
144
  chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): number {`);
145
145
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
146
146
  for (const valueDesc of enumDesc.value) {
@@ -33,7 +33,7 @@ function generateGenericServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc
33
33
  const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
34
34
  (0, utils_1.maybeAddComment)(info, chunks, (_c = methodDesc.options) === null || _c === void 0 ? void 0 : _c.deprecated);
35
35
  chunks.push((0, ts_poet_1.code) `
36
- ${(0, case_1.camelCase)(methodDesc.name)}: ${generateMethodDefinition(ctx, methodDesc)},
36
+ ${(0, case_1.uncapitalize)(methodDesc.name)}: ${generateMethodDefinition(ctx, methodDesc)},
37
37
  `);
38
38
  }
39
39
  chunks.push((0, ts_poet_1.code) `
@@ -76,10 +76,10 @@ function generateMethodOptions(ctx, options) {
76
76
  for (const value of values) {
77
77
  valuesChunks.push((0, ts_poet_1.code) `${ctx.options.env == "node" ? "Buffer.from" : "new Uint8Array"}([${value.join(", ")}])`);
78
78
  }
79
- unknownFieldsChunks.push((0, ts_poet_1.code) `${key}: [\n${(0, ts_poet_1.joinCode)(valuesChunks, { on: "," }).toCodeString([])}\n],`);
79
+ unknownFieldsChunks.push((0, ts_poet_1.code) `${key}: [\n${(0, ts_poet_1.joinCode)(valuesChunks, { on: "," })}\n],`);
80
80
  }
81
81
  unknownFieldsChunks.push((0, ts_poet_1.code) `}`);
82
- chunks.push((0, ts_poet_1.code) `_unknownFields: ${(0, ts_poet_1.joinCode)(unknownFieldsChunks, { on: "\n" }).toCodeString([])}`);
82
+ chunks.push((0, ts_poet_1.code) `_unknownFields: ${(0, ts_poet_1.joinCode)(unknownFieldsChunks, { on: "\n" })}`);
83
83
  }
84
84
  }
85
85
  chunks.push((0, ts_poet_1.code) `}`);
@@ -37,7 +37,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
37
37
  if (methodDesc.serverStreaming) {
38
38
  // bidi streaming
39
39
  chunks.push((0, ts_poet_1.code) `
40
- ${(0, case_1.camelCase)(methodDesc.name)}(
40
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
41
41
  request: AsyncIterable<${inputType}>,
42
42
  context: ${CallContext} & CallContextExt,
43
43
  ): ${ServerStreamingMethodResult}<${outputType}>;
@@ -46,7 +46,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
46
46
  else {
47
47
  // client streaming
48
48
  chunks.push((0, ts_poet_1.code) `
49
- ${(0, case_1.camelCase)(methodDesc.name)}(
49
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
50
50
  request: AsyncIterable<${inputType}>,
51
51
  context: ${CallContext} & CallContextExt,
52
52
  ): Promise<${outputType}>;
@@ -57,7 +57,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
57
57
  if (methodDesc.serverStreaming) {
58
58
  // server streaming
59
59
  chunks.push((0, ts_poet_1.code) `
60
- ${(0, case_1.camelCase)(methodDesc.name)}(
60
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
61
61
  request: ${inputType},
62
62
  context: ${CallContext} & CallContextExt,
63
63
  ): ${ServerStreamingMethodResult}<${outputType}>;
@@ -66,7 +66,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
66
66
  else {
67
67
  // unary
68
68
  chunks.push((0, ts_poet_1.code) `
69
- ${(0, case_1.camelCase)(methodDesc.name)}(
69
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
70
70
  request: ${inputType},
71
71
  context: ${CallContext} & CallContextExt,
72
72
  ): Promise<${outputType}>;
@@ -94,7 +94,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
94
94
  if (methodDesc.serverStreaming) {
95
95
  // bidi streaming
96
96
  chunks.push((0, ts_poet_1.code) `
97
- ${(0, case_1.camelCase)(methodDesc.name)}(
97
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
98
98
  request: AsyncIterable<${inputType}>,
99
99
  options?: ${CallOptions} & CallOptionsExt,
100
100
  ): AsyncIterable<${outputType}>;
@@ -103,7 +103,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
103
103
  else {
104
104
  // client streaming
105
105
  chunks.push((0, ts_poet_1.code) `
106
- ${(0, case_1.camelCase)(methodDesc.name)}(
106
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
107
107
  request: AsyncIterable<${inputType}>,
108
108
  options?: ${CallOptions} & CallOptionsExt,
109
109
  ): Promise<${outputType}>;
@@ -114,7 +114,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
114
114
  if (methodDesc.serverStreaming) {
115
115
  // server streaming
116
116
  chunks.push((0, ts_poet_1.code) `
117
- ${(0, case_1.camelCase)(methodDesc.name)}(
117
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
118
118
  request: ${inputType},
119
119
  options?: ${CallOptions} & CallOptionsExt,
120
120
  ): AsyncIterable<${outputType}>;
@@ -123,7 +123,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
123
123
  else {
124
124
  // unary
125
125
  chunks.push((0, ts_poet_1.code) `
126
- ${(0, case_1.camelCase)(methodDesc.name)}(
126
+ ${(0, case_1.uncapitalize)(methodDesc.name)}(
127
127
  request: ${inputType},
128
128
  options?: ${CallOptions} & CallOptionsExt,
129
129
  ): Promise<${outputType}>;
package/build/main.js CHANGED
@@ -77,7 +77,11 @@ function generateFile(ctx, fileDesc) {
77
77
  // We add `nestJs` here because enough though it doesn't use our encode/decode methods
78
78
  // for most/vanilla messages, we do generate static wrap/unwrap methods for the special
79
79
  // Struct/Value/wrapper types and use the `wrappers[...]` to have NestJS know about them.
80
- if (options.outputEncodeMethods || options.outputJsonMethods || options.outputTypeRegistry || options.nestJs) {
80
+ if (options.outputEncodeMethods ||
81
+ options.outputJsonMethods ||
82
+ options.outputTypeAnnotations ||
83
+ options.outputTypeRegistry ||
84
+ options.nestJs) {
81
85
  // then add the encoder/decoder/base instance
82
86
  (0, visit_1.visit)(fileDesc, sourceInfo, (fullName, message, _sInfo, fullProtoTypeName) => {
83
87
  const fullTypeName = (0, utils_1.maybePrefixPackage)(fileDesc, fullProtoTypeName);
@@ -89,7 +93,7 @@ function generateFile(ctx, fileDesc) {
89
93
  chunks.push(generateBaseInstanceFactory(ctx, fullName, message, fullTypeName));
90
94
  }
91
95
  const staticMembers = [];
92
- if (options.outputTypeRegistry) {
96
+ if (options.outputTypeAnnotations || options.outputTypeRegistry) {
93
97
  staticMembers.push((0, ts_poet_1.code) `$type: '${fullTypeName}' as const`);
94
98
  }
95
99
  if (options.outputExtensions) {
@@ -414,7 +418,7 @@ function makeDeepPartial(options, longs) {
414
418
  const maybeLong = options.forceLong === options_1.LongOption.LONG ? (0, ts_poet_1.code) ` : T extends ${longs.Long} ? string | number | Long ` : "";
415
419
  const Builtin = (0, ts_poet_1.conditionalOutput)("Builtin", (0, ts_poet_1.code) `type Builtin = Date | Function | Uint8Array | string | number | boolean |${options.forceLong === options_1.LongOption.BIGINT ? " bigint |" : ""} undefined;`);
416
420
  // Based on https://github.com/sindresorhus/type-fest/pull/259
417
- const maybeExcludeType = options.outputTypeRegistry ? `| '$type'` : "";
421
+ const maybeExcludeType = options.outputTypeAnnotations || options.outputTypeRegistry ? `| '$type'` : "";
418
422
  const Exact = (0, ts_poet_1.conditionalOutput)("Exact", (0, ts_poet_1.code) `
419
423
  type KeysOfUnion<T> = T extends T ? keyof T : never;
420
424
  ${maybeExport} type Exact<P, I extends P> = P extends ${Builtin}
@@ -423,7 +427,7 @@ function makeDeepPartial(options, longs) {
423
427
  { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
424
428
  `);
425
429
  // Based on the type from ts-essentials
426
- const keys = options.outputTypeRegistry ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
430
+ const keys = options.outputTypeAnnotations || options.outputTypeRegistry ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
427
431
  const DeepPartial = (0, ts_poet_1.conditionalOutput)("DeepPartial", (0, ts_poet_1.code) `
428
432
  ${maybeExport} type DeepPartial<T> = T extends ${Builtin}
429
433
  ? T
@@ -483,7 +487,7 @@ function makeTimestampMethods(options, longs) {
483
487
  // (note this only occurs when the string is > 8 characters)
484
488
  seconds = "Math.trunc(date.getTime() / 1_000).toString()";
485
489
  }
486
- const maybeTypeField = options.outputTypeRegistry ? `$type: 'google.protobuf.Timestamp',` : "";
490
+ const maybeTypeField = options.outputTypeAnnotations || options.outputTypeRegistry ? `$type: 'google.protobuf.Timestamp',` : "";
487
491
  const toTimestamp = (0, ts_poet_1.conditionalOutput)("toTimestamp", options.useDate === options_1.DateOption.STRING
488
492
  ? (0, ts_poet_1.code) `
489
493
  function toTimestamp(dateStr: string): ${Timestamp} {
@@ -593,7 +597,7 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
593
597
  (0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = messageDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
594
598
  // interface name should be defined to avoid import collisions
595
599
  chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(fullName)} {`);
596
- if (ctx.options.outputTypeRegistry) {
600
+ if (ctx.options.outputTypeAnnotations || ctx.options.outputTypeRegistry) {
597
601
  chunks.push((0, ts_poet_1.code) `$type: '${fullTypeName}',`);
598
602
  }
599
603
  // When oneof=unions, we generate a single property with an ADT per `oneof` clause.
@@ -684,7 +688,7 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
684
688
  : (0, types_1.defaultValue)(ctx, field);
685
689
  fields.push((0, ts_poet_1.code) `${name}: ${val}`);
686
690
  }
687
- if (ctx.options.outputTypeRegistry) {
691
+ if (ctx.options.outputTypeAnnotations || ctx.options.outputTypeRegistry) {
688
692
  fields.unshift((0, ts_poet_1.code) `$type: '${fullTypeName}'`);
689
693
  }
690
694
  if (ctx.options.unknownFields && ctx.options.initializeFieldsAsUndefined) {
@@ -751,10 +755,12 @@ function getDecodeReadSnippet(ctx, field) {
751
755
  }
752
756
  else if ((0, types_1.isMessage)(field)) {
753
757
  const type = (0, types_1.basicTypeName)(ctx, field);
754
- if (field.type == ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_GROUP)
758
+ if (field.type == ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_GROUP) {
755
759
  readSnippet = (0, ts_poet_1.code) `${type}.decode(reader)`;
756
- else
760
+ }
761
+ else {
757
762
  readSnippet = (0, ts_poet_1.code) `${type}.decode(reader, reader.uint32())`;
763
+ }
758
764
  }
759
765
  else {
760
766
  throw new Error(`Unhandled field ${field}`);
@@ -792,8 +798,9 @@ function generateDecode(ctx, fullName, messageDesc) {
792
798
  chunks.push((0, ts_poet_1.code) `case ${field.number}:`);
793
799
  const tag = ((field.number << 3) | (0, types_1.basicWireType)(field.type)) >>> 0;
794
800
  const tagCheck = (0, ts_poet_1.code) `
795
- if(tag != ${tag})
801
+ if (tag !== ${tag}) {
796
802
  break;
803
+ }
797
804
  `;
798
805
  // get a generic 'reader.doSomething' bit that is specific to the basic type
799
806
  const readSnippet = getDecodeReadSnippet(ctx, field);
@@ -809,9 +816,9 @@ function generateDecode(ctx, fullName, messageDesc) {
809
816
  : `message.${fieldName}${maybeNonNullAssertion}[${varName}.key] = ${varName}.value`;
810
817
  const initializerSnippet = initializerNecessary
811
818
  ? `
812
- if(message.${fieldName} === undefined)
819
+ if (message.${fieldName} === undefined) {
813
820
  message.${fieldName} = ${ctx.options.useMapType ? "new Map()" : "{}"};
814
- `
821
+ }`
815
822
  : "";
816
823
  chunks.push((0, ts_poet_1.code) `
817
824
  ${tagCheck}
@@ -824,8 +831,10 @@ function generateDecode(ctx, fullName, messageDesc) {
824
831
  }
825
832
  else {
826
833
  const initializerSnippet = initializerNecessary
827
- ? `if(message.${fieldName} === undefined)
828
- message.${fieldName} = [];`
834
+ ? `
835
+ if (message.${fieldName} === undefined) {
836
+ message.${fieldName} = [];
837
+ }`
829
838
  : "";
830
839
  if ((0, types_1.packedType)(field.type) === undefined) {
831
840
  chunks.push((0, ts_poet_1.code) `
@@ -837,13 +846,14 @@ function generateDecode(ctx, fullName, messageDesc) {
837
846
  else {
838
847
  const packedTag = ((field.number << 3) | 2) >>> 0;
839
848
  chunks.push((0, ts_poet_1.code) `
840
- if(tag == ${tag}){
849
+ if (tag === ${tag}) {
841
850
  ${initializerSnippet}
842
851
  message.${fieldName}${maybeNonNullAssertion}.push(${readSnippet});
852
+
843
853
  continue;
844
854
  }
845
855
 
846
- if(tag == ${packedTag}){
856
+ if (tag === ${packedTag}) {
847
857
  ${initializerSnippet}
848
858
  const end2 = reader.uint32() + reader.pos;
849
859
  while (reader.pos < end2) {
@@ -871,21 +881,24 @@ function generateDecode(ctx, fullName, messageDesc) {
871
881
  message.${fieldName} = ${readSnippet};
872
882
  `);
873
883
  }
874
- if (!(0, types_1.isRepeated)(field) || (0, types_1.packedType)(field.type) === undefined)
884
+ if (!(0, types_1.isRepeated)(field) || (0, types_1.packedType)(field.type) === undefined) {
875
885
  chunks.push((0, ts_poet_1.code) `continue;`);
886
+ }
876
887
  });
877
888
  chunks.push((0, ts_poet_1.code) `}`);
878
889
  chunks.push((0, ts_poet_1.code) `
879
- if((tag & 7) == 4 || tag == 0)
890
+ if ((tag & 7) === 4 || tag === 0) {
880
891
  break;
892
+ }
881
893
  `);
882
894
  if (options.unknownFields) {
883
895
  let unknownFieldsInitializerSnippet = "";
884
896
  let maybeNonNullAssertion = options.initializeFieldsAsUndefined ? "!" : "";
885
897
  if (!options.initializeFieldsAsUndefined) {
886
898
  unknownFieldsInitializerSnippet = `
887
- if(message._unknownFields === undefined)
899
+ if (message._unknownFields === undefined) {
888
900
  message._unknownFields = {};
901
+ }
889
902
  `;
890
903
  }
891
904
  chunks.push((0, ts_poet_1.code) `
@@ -896,10 +909,11 @@ function generateDecode(ctx, fullName, messageDesc) {
896
909
  ${unknownFieldsInitializerSnippet}
897
910
  const list = message._unknownFields${maybeNonNullAssertion}[tag];
898
911
 
899
- if(list === undefined)
912
+ if (list === undefined) {
900
913
  message._unknownFields${maybeNonNullAssertion}[tag] = [buf];
901
- else
914
+ } else {
902
915
  list.push(buf);
916
+ }
903
917
  `);
904
918
  }
905
919
  else {
@@ -940,7 +954,7 @@ function getEncodeWriteSnippet(ctx, field) {
940
954
  return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.uint32(${tag}).fork()).ldelim()`;
941
955
  }
942
956
  else if ((0, types_1.isValueType)(ctx, field)) {
943
- const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
957
+ const maybeTypeField = options.outputTypeAnnotations || options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
944
958
  const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
945
959
  const wrappedValue = (place) => {
946
960
  if ((0, types_1.isAnyValueType)(field) || (0, types_1.isListValueType)(field) || (0, types_1.isStructType)(field) || (0, types_1.isFieldMaskType)(field)) {
@@ -989,7 +1003,7 @@ function generateEncode(ctx, fullName, messageDesc) {
989
1003
  if ((0, types_1.isRepeated)(field)) {
990
1004
  if ((0, types_1.isMapType)(ctx, messageDesc, field)) {
991
1005
  const valueType = typeMap.get(field.typeName)[2].field[1];
992
- const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
1006
+ const maybeTypeField = options.outputTypeAnnotations || options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
993
1007
  const entryWriteSnippet = (0, types_1.isValueType)(ctx, valueType)
994
1008
  ? (0, ts_poet_1.code) `
995
1009
  if (value !== undefined) {
@@ -1144,7 +1158,7 @@ function generateSetExtension(ctx, fullName) {
1144
1158
  setExtension <T> (message: ${fullName}, extension: ${ctx.utils.Extension}<T>, value: T): void {
1145
1159
  const encoded = extension.encode!(value);
1146
1160
 
1147
- if (message._unknownFields !== undefined){
1161
+ if (message._unknownFields !== undefined) {
1148
1162
  delete message._unknownFields[extension.tag];
1149
1163
 
1150
1164
  if (extension.singularTag !== undefined) {
@@ -1241,7 +1255,7 @@ function generateExtension(ctx, message, extension) {
1241
1255
  return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.fork()).ldelim()`;
1242
1256
  }
1243
1257
  else if ((0, types_1.isValueType)(ctx, field)) {
1244
- const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
1258
+ const maybeTypeField = options.outputTypeAnnotations || options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : "";
1245
1259
  const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
1246
1260
  const wrappedValue = (place) => {
1247
1261
  if ((0, types_1.isAnyValueType)(field) || (0, types_1.isListValueType)(field) || (0, types_1.isStructType)(field) || (0, types_1.isFieldMaskType)(field)) {
@@ -1326,12 +1340,12 @@ function generateExtension(ctx, message, extension) {
1326
1340
  }
1327
1341
  else {
1328
1342
  chunks.push((0, ts_poet_1.code) `
1329
- if(tag == ${packedTag}){
1343
+ if (tag == ${packedTag}) {
1330
1344
  const end2 = reader.uint32() + reader.pos;
1331
1345
  while (reader.pos < end2) {
1332
1346
  values.push(${readSnippet});
1333
1347
  }
1334
- }else{
1348
+ } else {
1335
1349
  values.push(${readSnippet});
1336
1350
  }
1337
1351
  `);
@@ -1373,7 +1387,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1373
1387
  fromJSON(${messageDesc.field.length > 0 ? "object" : "_"}: any): ${fullName} {
1374
1388
  return {
1375
1389
  `);
1376
- if (ctx.options.outputTypeRegistry) {
1390
+ if (ctx.options.outputTypeAnnotations || ctx.options.outputTypeRegistry) {
1377
1391
  chunks.push((0, ts_poet_1.code) `$type: ${fullName}.$type,`);
1378
1392
  }
1379
1393
  const oneofFieldsCases = messageDesc.oneofDecl.map((oneof, oneofIndex) => messageDesc.field.filter(types_1.isWithinOneOf).filter((field) => field.oneofIndex === oneofIndex));
package/build/options.js CHANGED
@@ -49,6 +49,7 @@ function defaultOptions() {
49
49
  outputEncodeMethods: true,
50
50
  outputJsonMethods: true,
51
51
  outputPartialMethods: true,
52
+ outputTypeAnnotations: false,
52
53
  outputTypeRegistry: false,
53
54
  stringEnums: false,
54
55
  constEnums: false,
package/build/types.js CHANGED
@@ -571,7 +571,7 @@ function toModuleAndType(typeMap, protoType) {
571
571
  }
572
572
  function getEnumMethod(ctx, enumProtoType, methodSuffix) {
573
573
  const [module, type] = toModuleAndType(ctx.typeMap, enumProtoType);
574
- return (0, utils_1.impProto)(ctx.options, module, `${(0, case_1.camelCase)(type)}${methodSuffix}`);
574
+ return (0, utils_1.impProto)(ctx.options, module, `${(0, case_1.uncapitalize)(type)}${methodSuffix}`);
575
575
  }
576
576
  exports.getEnumMethod = getEnumMethod;
577
577
  /** Return the TypeName for any field (primitive/message/etc.) as exposed in the interface. */
package/build/utils.js CHANGED
@@ -138,7 +138,8 @@ class FormattedMethodDescriptor {
138
138
  static formatName(methodName, options) {
139
139
  let result = methodName;
140
140
  if (options.lowerCaseServiceMethods || options.outputServices.includes(options_1.ServiceOption.GRPC)) {
141
- result = (0, case_1.camelCaseGrpc)(result);
141
+ if (options.snakeToCamel)
142
+ result = (0, case_1.camelCaseGrpc)(result);
142
143
  }
143
144
  return result;
144
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.146.0",
3
+ "version": "1.147.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",
@@ -65,7 +65,7 @@
65
65
  "object-hash": "^1.3.1",
66
66
  "protobufjs": "^6.11.3",
67
67
  "ts-poet": "^6.4.1",
68
- "ts-proto-descriptors": "1.8.0"
68
+ "ts-proto-descriptors": "1.9.0"
69
69
  },
70
70
  "packageManager": "yarn@3.3.0"
71
71
  }