ts-proto 2.15.3 → 2.16.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/README.markdown CHANGED
@@ -612,6 +612,8 @@ With `--ts_proto_opt=protoJsonFormat=false`, strict proto3 compliance is disable
612
612
 
613
613
  - With `--ts_proto_opt=typeSuffix=MySuffix`, the generated interfaces, enums, and factories will have a suffix of `MySuffix` in their names.
614
614
 
615
+ - With `--ts_proto_opt=messagePrefix=MyPrefix` / `messageSuffix=MySuffix`, only the generated message interfaces and factories get the prefix/suffix, and with `enumPrefix=MyPrefix` / `enumSuffix=MySuffix` only the enums do. They are added inside `typePrefix`/`typeSuffix` when both are set, e.g. `typePrefix=T,messagePrefix=M` gives `TMFoo`.
616
+
615
617
  ```protobuf
616
618
  message ProfileInfo {
617
619
  int32 id = 1;
@@ -48,7 +48,7 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
48
48
  chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
49
49
  const result = {} as any;
50
50
  if (value === null) {
51
- result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE;
51
+ result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue", "enum")}.NULL_VALUE;
52
52
  } else if (typeof value === 'boolean') {
53
53
  result.${fieldNames.boolValue} = value;
54
54
  } else if (typeof value === 'number') {
@@ -180,7 +180,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
180
180
  chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
181
181
  const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
182
182
  if (value === null) {
183
- result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE};
183
+ result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue", "enum")}.NULL_VALUE};
184
184
  } else if (typeof value === 'boolean') {
185
185
  result.kind = {$case: '${fieldNames.boolValue}', ${fieldNames.boolValue}: value};
186
186
  } else if (typeof value === 'number') {
@@ -201,7 +201,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
201
201
  chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
202
202
  const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
203
203
  if (value === null) {
204
- result.kind = {$case: '${fieldNames.nullValue}', value: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE};
204
+ result.kind = {$case: '${fieldNames.nullValue}', value: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue", "enum")}.NULL_VALUE};
205
205
  } else if (typeof value === 'boolean') {
206
206
  result.kind = {$case: '${fieldNames.boolValue}', value };
207
207
  } else if (typeof value === 'number') {
@@ -222,7 +222,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
222
222
  chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
223
223
  const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
224
224
  if (value === null) {
225
- result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE;
225
+ result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue", "enum")}.NULL_VALUE;
226
226
  } else if (typeof value === 'boolean') {
227
227
  result.${fieldNames.boolValue} = value;
228
228
  } else if (typeof value === 'number') {
@@ -121,6 +121,10 @@ export type Options = {
121
121
  bigIntLiteral: boolean;
122
122
  typePrefix: string;
123
123
  typeSuffix: string;
124
+ messagePrefix: string;
125
+ messageSuffix: string;
126
+ enumPrefix: string;
127
+ enumSuffix: string;
124
128
  useDuration: DurationOption;
125
129
  anyType: AnyTypeOption;
126
130
  };
@@ -135,6 +135,10 @@ function defaultOptions() {
135
135
  bigIntLiteral: true,
136
136
  typePrefix: "",
137
137
  typeSuffix: "",
138
+ messagePrefix: "",
139
+ messageSuffix: "",
140
+ enumPrefix: "",
141
+ enumSuffix: "",
138
142
  useDuration: DurationOption.DURATION,
139
143
  anyType: AnyTypeOption.AT_TYPE,
140
144
  };
@@ -80,4 +80,4 @@ export declare function getVersions(request: CodeGeneratorRequest): Promise<{
80
80
  protocVersion: string;
81
81
  tsProtoVersion: string;
82
82
  }>;
83
- export declare function wrapTypeName(options: Options, name: string): string;
83
+ export declare function wrapTypeName(options: Options, name: string, kind?: "message" | "enum"): string;
@@ -308,6 +308,7 @@ async function readPackageJson() {
308
308
  return await Promise.resolve(`${"../package.json"}`).then(s => require(s));
309
309
  }
310
310
  }
311
- function wrapTypeName(options, name) {
312
- return options.typePrefix + name + options.typeSuffix;
311
+ function wrapTypeName(options, name, kind = "message") {
312
+ const [prefix, suffix] = kind === "enum" ? [options.enumPrefix, options.enumSuffix] : [options.messagePrefix, options.messageSuffix];
313
+ return options.typePrefix + prefix + name + suffix + options.typeSuffix;
313
314
  }
@@ -13,7 +13,7 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
13
13
  const protoFullName = protoPrefix + enumDesc.name;
14
14
  // I.e. FooBar_ZazInner
15
15
  const tsFullName = tsPrefix + (0, case_1.maybeSnakeToCamel)(enumDesc.name, options);
16
- const tsFullNameWithAffixes = messageName((0, utils_1.wrapTypeName)(options, tsFullName));
16
+ const tsFullNameWithAffixes = messageName((0, utils_1.wrapTypeName)(options, tsFullName, "enum"));
17
17
  const nestedSourceInfo = sourceInfo.open(childEnumType, index);
18
18
  enumFn(tsFullNameWithAffixes, enumDesc, nestedSourceInfo, protoFullName);
19
19
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.15.3",
3
+ "version": "2.16.0",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",