ts-proto 2.5.0 → 2.6.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.
@@ -12,7 +12,7 @@ function generateEncoder(ctx, typeName) {
12
12
  return (0, ts_poet_1.code) `${(0, types_1.messageToTypeName)(ctx, typeName, { keepValueType: true })}.encode(value).finish()`;
13
13
  }
14
14
  if (name == "Timestamp") {
15
- const TimestampValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", name);
15
+ const TimestampValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", (0, utils_1.wrapTypeName)(ctx.options, name));
16
16
  let value = (0, ts_poet_1.code) `value`;
17
17
  if (ctx.options.useDate === options_1.DateOption.DATE ||
18
18
  ctx.options.useDate === options_1.DateOption.STRING ||
@@ -22,14 +22,14 @@ function generateEncoder(ctx, typeName) {
22
22
  return (0, ts_poet_1.code) `${TimestampValue}.encode(${value}).finish()`;
23
23
  }
24
24
  if (name == "Struct" || name == "Value") {
25
- const StructType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
25
+ const StructType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", (0, utils_1.wrapTypeName)(ctx.options, name));
26
26
  return (0, ts_poet_1.code) `${StructType}.encode(${StructType}.wrap(value)).finish()`;
27
27
  }
28
28
  if (name == "ListValue") {
29
- const ListValueType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
29
+ const ListValueType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", (0, utils_1.wrapTypeName)(ctx.options, name));
30
30
  return (0, ts_poet_1.code) `${ListValueType}.encode({values: value ?? []}).finish()`;
31
31
  }
32
- const TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", name);
32
+ const TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", (0, utils_1.wrapTypeName)(ctx.options, name));
33
33
  switch (name) {
34
34
  case "StringValue":
35
35
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? ""}).finish()`;
@@ -59,7 +59,7 @@ function generateDecoder(ctx, typeName) {
59
59
  }
60
60
  let TypeValue;
61
61
  if (name == "Timestamp") {
62
- TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", options.typePrefix + name + options.typeSuffix);
62
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", (0, utils_1.wrapTypeName)(ctx.options, name));
63
63
  const decoder = (0, ts_poet_1.code) `${TypeValue}.decode(value)`;
64
64
  if (ctx.options.useDate === options_1.DateOption.DATE ||
65
65
  ctx.options.useDate === options_1.DateOption.STRING ||
@@ -69,9 +69,9 @@ function generateDecoder(ctx, typeName) {
69
69
  return decoder;
70
70
  }
71
71
  if (name == "Struct" || name == "ListValue" || name == "Value") {
72
- TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
72
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", (0, utils_1.wrapTypeName)(ctx.options, name));
73
73
  return (0, ts_poet_1.code) `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
74
74
  }
75
- TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", name);
75
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", (0, utils_1.wrapTypeName)(ctx.options, name));
76
76
  return (0, ts_poet_1.code) `${TypeValue}.decode(value).value`;
77
77
  }
@@ -6,6 +6,7 @@ exports.generateUnwrapDeep = generateUnwrapDeep;
6
6
  exports.generateWrapShallow = generateWrapShallow;
7
7
  exports.generateUnwrapShallow = generateUnwrapShallow;
8
8
  const ts_poet_1 = require("ts-poet");
9
+ const utils_1 = require("./utils");
9
10
  const types_1 = require("./types");
10
11
  const options_1 = require("./options");
11
12
  /** Whether we need to generate `.wrap` and `.unwrap` methods for the given type. */
@@ -23,16 +24,16 @@ function isWrapperType(fullProtoTypeName) {
23
24
  function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
24
25
  const chunks = [];
25
26
  if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
26
- let setStatement = "struct.fields[key] = Value.wrap(object[key]);";
27
+ let setStatement = `struct.fields[key] = ${(0, utils_1.wrapTypeName)(ctx.options, "Value")}.wrap(object[key]);`;
27
28
  let defaultFields = "struct.fields ??= {};";
28
29
  if (ctx.options.useMapType) {
29
- setStatement = "struct.fields.set(key, Value.wrap(object[key]));";
30
+ setStatement = `struct.fields.set(key, ${(0, utils_1.wrapTypeName)(ctx.options, "Value")}.wrap(object[key]));`;
30
31
  defaultFields = "struct.fields ??= new Map<string, any | undefined>();";
31
32
  }
32
33
  if (ctx.options.useOptionals !== "all")
33
34
  defaultFields = "";
34
- chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): Struct {
35
- const struct = createBaseStruct();
35
+ chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")} {
36
+ const struct = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}();
36
37
  ${defaultFields}
37
38
  if (object !== undefined) {
38
39
  for (const key of Object.keys(object)) {
@@ -44,10 +45,10 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
44
45
  }
45
46
  if ((0, types_1.isAnyValueTypeName)(fullProtoTypeName)) {
46
47
  // Turn ts-proto representation --> proto representation
47
- chunks.push((0, ts_poet_1.code) `wrap(value: any): Value {
48
+ chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
48
49
  const result = {} as any;
49
50
  if (value === null) {
50
- result.${fieldNames.nullValue} = NullValue.NULL_VALUE;
51
+ result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE;
51
52
  } else if (typeof value === 'boolean') {
52
53
  result.${fieldNames.boolValue} = value;
53
54
  } else if (typeof value === 'number') {
@@ -55,9 +56,9 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
55
56
  } else if (typeof value === 'string') {
56
57
  result.${fieldNames.stringValue} = value;
57
58
  } else if (${ctx.utils.globalThis}.Array.isArray(value)) {
58
- result.${fieldNames.listValue} = ListValue.wrap(value);
59
+ result.${fieldNames.listValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")}.wrap(value);
59
60
  } else if (typeof value === 'object') {
60
- result.${fieldNames.structValue} = Struct.wrap(value);
61
+ result.${fieldNames.structValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}.wrap(value);
61
62
  } else if (typeof value !== 'undefined') {
62
63
  throw new ${ctx.utils.globalThis}.Error('Unsupported any value type: ' + typeof value);
63
64
  }
@@ -66,15 +67,15 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
66
67
  }
67
68
  if ((0, types_1.isListValueTypeName)(fullProtoTypeName)) {
68
69
  const maybeReadyOnly = ctx.options.useReadonlyTypes ? "Readonly" : "";
69
- chunks.push((0, ts_poet_1.code) `wrap(array: ${maybeReadyOnly}Array<any> | undefined): ListValue {
70
- const result = createBaseListValue()${maybeAsAny(ctx.options)};
71
- result.values = (array ?? []).map(Value.wrap);
70
+ chunks.push((0, ts_poet_1.code) `wrap(array: ${maybeReadyOnly}Array<any> | undefined): ${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")} {
71
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")}()${maybeAsAny(ctx.options)};
72
+ result.values = (array ?? []).map(${(0, utils_1.wrapTypeName)(ctx.options, "Value")}.wrap);
72
73
  return result;
73
74
  }`);
74
75
  }
75
76
  if ((0, types_1.isFieldMaskTypeName)(fullProtoTypeName)) {
76
- chunks.push((0, ts_poet_1.code) `wrap(paths: ${maybeReadonly(ctx.options)} string[]): FieldMask {
77
- const result = createBaseFieldMask()${maybeAsAny(ctx.options)};
77
+ chunks.push((0, ts_poet_1.code) `wrap(paths: ${maybeReadonly(ctx.options)} string[]): ${(0, utils_1.wrapTypeName)(ctx.options, "FieldMask")} {
78
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "FieldMask")}()${maybeAsAny(ctx.options)};
78
79
  result.paths = paths;
79
80
  return result;
80
81
  }`);
@@ -90,7 +91,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
90
91
  const chunks = [];
91
92
  if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
92
93
  if (ctx.options.useMapType) {
93
- chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
94
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}: {[key: string]: any} {
94
95
  const object: { [key: string]: any } = {};
95
96
  if (message.fields) {
96
97
  for (const key of message.fields.keys()) {
@@ -101,7 +102,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
101
102
  }`);
102
103
  }
103
104
  else {
104
- chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
105
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
105
106
  const object: { [key: string]: any } = {};
106
107
  if (message.fields) {
107
108
  for (const key of Object.keys(message.fields)) {
@@ -124,9 +125,9 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
124
125
  } else if (message?.hasOwnProperty('${fieldNames.boolValue}') && message?.${fieldNames.boolValue} !== undefined) {
125
126
  return message.${fieldNames.boolValue};
126
127
  } else if (message?.hasOwnProperty('${fieldNames.structValue}') && message?.${fieldNames.structValue} !== undefined) {
127
- return Struct.unwrap(message.${fieldNames.structValue} as any);
128
+ return ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}.unwrap(message.${fieldNames.structValue} as any);
128
129
  } else if (message?.hasOwnProperty('${fieldNames.listValue}') && message?.${fieldNames.listValue} !== undefined) {
129
- return ListValue.unwrap(message.${fieldNames.listValue});
130
+ return ${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")}.unwrap(message.${fieldNames.listValue});
130
131
  } else if (message?.hasOwnProperty('${fieldNames.nullValue}') && message?.${fieldNames.nullValue} !== undefined) {
131
132
  return null;
132
133
  }
@@ -134,7 +135,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
134
135
  }`);
135
136
  }
136
137
  if ((0, types_1.isListValueTypeName)(fullProtoTypeName)) {
137
- chunks.push((0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : "ListValue"}): Array<any> {
138
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : (0, utils_1.wrapTypeName)(ctx.options, "ListValue")}): Array<any> {
138
139
  if (message?.hasOwnProperty('values') && ${ctx.utils.globalThis}.Array.isArray(message.values)) {
139
140
  return message.values.map(Value.unwrap);
140
141
  } else {
@@ -163,8 +164,8 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
163
164
  }
164
165
  if (ctx.options.useOptionals !== "all")
165
166
  defaultFields = "";
166
- chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): Struct {
167
- const struct = createBaseStruct();
167
+ chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")} {
168
+ const struct = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}();
168
169
  ${defaultFields}
169
170
  if (object !== undefined) {
170
171
  for (const key of Object.keys(object)) {
@@ -176,10 +177,10 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
176
177
  }
177
178
  if ((0, types_1.isAnyValueTypeName)(fullProtoTypeName)) {
178
179
  if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
179
- chunks.push((0, ts_poet_1.code) `wrap(value: any): Value {
180
- const result = createBaseValue()${maybeAsAny(ctx.options)};
180
+ chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
181
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
181
182
  if (value === null) {
182
- result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: NullValue.NULL_VALUE};
183
+ result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE};
183
184
  } else if (typeof value === 'boolean') {
184
185
  result.kind = {$case: '${fieldNames.boolValue}', ${fieldNames.boolValue}: value};
185
186
  } else if (typeof value === 'number') {
@@ -197,8 +198,8 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
197
198
  }`);
198
199
  }
199
200
  else if (ctx.options.oneof === options_1.OneofOption.UNIONS_VALUE) {
200
- chunks.push((0, ts_poet_1.code) `wrap(value: any): Value {
201
- const result = createBaseValue()${maybeAsAny(ctx.options)};
201
+ chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
202
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
202
203
  if (value === null) {
203
204
  result.kind = {$case: '${fieldNames.nullValue}', value };
204
205
  } else if (typeof value === 'boolean') {
@@ -218,10 +219,10 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
218
219
  }`);
219
220
  }
220
221
  else {
221
- chunks.push((0, ts_poet_1.code) `wrap(value: any): Value {
222
- const result = createBaseValue()${maybeAsAny(ctx.options)};
222
+ chunks.push((0, ts_poet_1.code) `wrap(value: any): ${(0, utils_1.wrapTypeName)(ctx.options, "Value")} {
223
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Value")}()${maybeAsAny(ctx.options)};
223
224
  if (value === null) {
224
- result.${fieldNames.nullValue} = NullValue.NULL_VALUE;
225
+ result.${fieldNames.nullValue} = ${(0, utils_1.wrapTypeName)(ctx.options, "NullValue")}.NULL_VALUE;
225
226
  } else if (typeof value === 'boolean') {
226
227
  result.${fieldNames.boolValue} = value;
227
228
  } else if (typeof value === 'number') {
@@ -241,15 +242,15 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
241
242
  }
242
243
  if ((0, types_1.isListValueTypeName)(fullProtoTypeName)) {
243
244
  const maybeReadyOnly = ctx.options.useReadonlyTypes ? "Readonly" : "";
244
- chunks.push((0, ts_poet_1.code) `wrap(array: ${maybeReadyOnly}Array<any> | undefined): ListValue {
245
- const result = createBaseListValue()${maybeAsAny(ctx.options)};
245
+ chunks.push((0, ts_poet_1.code) `wrap(array: ${maybeReadyOnly}Array<any> | undefined): ${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")} {
246
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "ListValue")}()${maybeAsAny(ctx.options)};
246
247
  result.values = array ?? [];
247
248
  return result;
248
249
  }`);
249
250
  }
250
251
  if ((0, types_1.isFieldMaskTypeName)(fullProtoTypeName)) {
251
- chunks.push((0, ts_poet_1.code) `wrap(paths: ${maybeReadonly(ctx.options)} string[]): FieldMask {
252
- const result = createBaseFieldMask()${maybeAsAny(ctx.options)};
252
+ chunks.push((0, ts_poet_1.code) `wrap(paths: ${maybeReadonly(ctx.options)} string[]): ${(0, utils_1.wrapTypeName)(ctx.options, "FieldMask")} {
253
+ const result = createBase${(0, utils_1.wrapTypeName)(ctx.options, "FieldMask")}()${maybeAsAny(ctx.options)};
253
254
  result.paths = paths;
254
255
  return result;
255
256
  }`);
@@ -265,7 +266,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
265
266
  const chunks = [];
266
267
  if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
267
268
  if (ctx.options.useMapType) {
268
- chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
269
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
269
270
  const object: { [key: string]: any } = {};
270
271
  if (message.fields) {
271
272
  for (const key of message.fields.keys()) {
@@ -276,7 +277,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
276
277
  }`);
277
278
  }
278
279
  else {
279
- chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
280
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
280
281
  const object: { [key: string]: any } = {};
281
282
  if (message.fields) {
282
283
  for (const key of Object.keys(message.fields)) {
@@ -289,7 +290,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
289
290
  }
290
291
  if ((0, types_1.isAnyValueTypeName)(fullProtoTypeName)) {
291
292
  if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
292
- chunks.push((0, ts_poet_1.code) `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
293
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Value")}): string | number | boolean | Object | null | Array<any> | undefined {
293
294
  if (message.kind?.$case === '${fieldNames.nullValue}') {
294
295
  return null;
295
296
  } else if (message.kind?.$case === '${fieldNames.numberValue}') {
@@ -308,7 +309,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
308
309
  }`);
309
310
  }
310
311
  else if (ctx.options.oneof === options_1.OneofOption.UNIONS_VALUE) {
311
- chunks.push((0, ts_poet_1.code) `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
312
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Value")}): string | number | boolean | Object | null | Array<any> | undefined {
312
313
  return message.kind?.value;
313
314
  }`);
314
315
  }
@@ -332,7 +333,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
332
333
  }
333
334
  }
334
335
  if ((0, types_1.isListValueTypeName)(fullProtoTypeName)) {
335
- chunks.push((0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : "ListValue"}): Array<any> {
336
+ chunks.push((0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : (0, utils_1.wrapTypeName)(ctx.options, "ListValue")}): Array<any> {
336
337
  if (message?.hasOwnProperty('values') && ${ctx.utils.globalThis}.Array.isArray(message.values)) {
337
338
  return message.values;
338
339
  } else {
@@ -348,7 +349,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
348
349
  function generateFieldMaskUnwrap(ctx) {
349
350
  const returnType = ctx.options.useOptionals === "all" ? "string[] | undefined" : "string[]";
350
351
  const pathModifier = ctx.options.useOptionals === "all" ? "?" : "";
351
- return (0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : "FieldMask"}): ${returnType} {
352
+ return (0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : (0, utils_1.wrapTypeName)(ctx.options, "FieldMask")}): ${returnType} {
352
353
  return message${pathModifier}.paths;
353
354
  }`;
354
355
  }
package/build/src/main.js CHANGED
@@ -360,7 +360,7 @@ function makeProtobufTimestampWrapper() {
360
360
  }
361
361
  function makeProtobufStructWrapper(options) {
362
362
  const wrappers = (0, ts_poet_1.imp)("wrappers@protobufjs");
363
- const Struct = (0, utils_1.impProto)(options, "google/protobuf/struct", "Struct");
363
+ const Struct = (0, utils_1.impProto)(options, "google/protobuf/struct", (0, utils_1.wrapTypeName)(options, "Struct"));
364
364
  return (0, ts_poet_1.code) `
365
365
  ${wrappers}['.google.protobuf.Struct'] = {
366
366
  fromObject: ${Struct}.wrap,
@@ -593,26 +593,26 @@ function makeMessageFns(options, deepPartial, extension) {
593
593
  `);
594
594
  const StructWrapperFns = (0, ts_poet_1.conditionalOutput)("StructWrapperFns", (0, ts_poet_1.code) `
595
595
  ${maybeExport} interface StructWrapperFns {
596
- wrap(object: {[key: string]: any} | undefined): Struct;
597
- unwrap(message: Struct): {[key: string]: any};
596
+ wrap(object: {[key: string]: any} | undefined): ${(0, utils_1.wrapTypeName)(options, "Struct")};
597
+ unwrap(message: ${(0, utils_1.wrapTypeName)(options, "Struct")}): {[key: string]: any};
598
598
  }
599
599
  `);
600
600
  const AnyValueWrapperFns = (0, ts_poet_1.conditionalOutput)("AnyValueWrapperFns", (0, ts_poet_1.code) `
601
601
  ${maybeExport} interface AnyValueWrapperFns {
602
- wrap(value: any): Value;
602
+ wrap(value: any): ${(0, utils_1.wrapTypeName)(options, "Value")};
603
603
  unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined;
604
604
  }
605
605
  `);
606
606
  const ListValueWrapperFns = (0, ts_poet_1.conditionalOutput)("ListValueWrapperFns", (0, ts_poet_1.code) `
607
607
  ${maybeExport} interface ListValueWrapperFns {
608
- wrap(array: ${options.useReadonlyTypes ? "Readonly" : ""}Array<any> | undefined): ListValue;
609
- unwrap(message: ${options.useReadonlyTypes ? "any" : "ListValue"}): Array<any>;
608
+ wrap(array: ${options.useReadonlyTypes ? "Readonly" : ""}Array<any> | undefined): ${(0, utils_1.wrapTypeName)(options, "ListValue")};
609
+ unwrap(message: ${options.useReadonlyTypes ? "any" : (0, utils_1.wrapTypeName)(options, "ListValue")}): Array<any>;
610
610
  }
611
611
  `);
612
612
  const FieldMaskWrapperFns = (0, ts_poet_1.conditionalOutput)("FieldMaskWrapperFns", (0, ts_poet_1.code) `
613
613
  ${maybeExport} interface FieldMaskWrapperFns {
614
- wrap(paths: ${options.useReadonlyTypes ? "readonly" : ""} string[]): FieldMask;
615
- unwrap(message: ${options.useReadonlyTypes ? "any" : "FieldMask"}): string[] ${options.useOptionals === "all" ? "| undefined" : ""};
614
+ wrap(paths: ${options.useReadonlyTypes ? "readonly" : ""} string[]): ${(0, utils_1.wrapTypeName)(options, "FieldMask")};
615
+ unwrap(message: ${options.useReadonlyTypes ? "any" : (0, utils_1.wrapTypeName)(options, "FieldMask")}): string[] ${options.useOptionals === "all" ? "| undefined" : ""};
616
616
  }
617
617
  `);
618
618
  return {
@@ -652,7 +652,7 @@ function makeObjectIdMethods() {
652
652
  return { fromJsonObjectId, fromProtoObjectId, toProtoObjectId };
653
653
  }
654
654
  function makeTimestampMethods(options, longs, bytes) {
655
- const Timestamp = (0, utils_1.impProto)(options, "google/protobuf/timestamp", `${options.typePrefix}Timestamp${options.typeSuffix}`);
655
+ const Timestamp = (0, utils_1.impProto)(options, "google/protobuf/timestamp", (0, utils_1.wrapTypeName)(options, "Timestamp"));
656
656
  const NanoDate = (0, ts_poet_1.imp)("NanoDate=nano-date");
657
657
  let seconds = "Math.trunc(date.getTime() / 1_000)";
658
658
  let toNumberCode = "t.seconds";
@@ -742,18 +742,18 @@ function makeTimestampMethods(options, longs, bytes) {
742
742
  } else if (typeof o === "string") {
743
743
  return new ${bytes.globalThis}.Date(o);
744
744
  } else {
745
- return ${fromTimestamp}(${options.typePrefix}Timestamp${options.typeSuffix}.fromJSON(o));
745
+ return ${fromTimestamp}(${(0, utils_1.wrapTypeName)(options, "Timestamp")}.fromJSON(o));
746
746
  }
747
747
  }
748
748
  `
749
749
  : (0, ts_poet_1.code) `
750
- function fromJsonTimestamp(o: any): ${options.typePrefix}Timestamp${options.typeSuffix} {
750
+ function fromJsonTimestamp(o: any): ${(0, utils_1.wrapTypeName)(options, "Timestamp")} {
751
751
  if (o instanceof ${bytes.globalThis}.Date) {
752
752
  return ${toTimestamp}(o);
753
753
  } else if (typeof o === "string") {
754
754
  return ${toTimestamp}(new ${bytes.globalThis}.Date(o));
755
755
  } else {
756
- return Timestamp.fromJSON(o);
756
+ return ${options.typePrefix}Timestamp${options.typeSuffix}.fromJSON(o);
757
757
  }
758
758
  }
759
759
  `);
@@ -80,3 +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;
@@ -28,6 +28,7 @@ exports.withOrMaybeCheckIsNull = withOrMaybeCheckIsNull;
28
28
  exports.withAndMaybeCheckIsNotNull = withAndMaybeCheckIsNotNull;
29
29
  exports.withAndMaybeCheckIsNull = withAndMaybeCheckIsNull;
30
30
  exports.getVersions = getVersions;
31
+ exports.wrapTypeName = wrapTypeName;
31
32
  const path = require("path");
32
33
  const ts_poet_1 = require("ts-poet");
33
34
  const options_1 = require("./options");
@@ -307,3 +308,6 @@ async function readPackageJson() {
307
308
  return await Promise.resolve(`${"../package.json"}`).then(s => require(s));
308
309
  }
309
310
  }
311
+ function wrapTypeName(options, name) {
312
+ return options.typePrefix + name + options.typeSuffix;
313
+ }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.visit = visit;
4
4
  exports.visitServices = visitServices;
5
+ const utils_1 = require("./utils");
5
6
  const sourceInfo_1 = require("./sourceInfo");
6
7
  const case_1 = require("./case");
7
8
  function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPrefix = "", protoPrefix = "") {
@@ -12,7 +13,7 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
12
13
  const protoFullName = protoPrefix + enumDesc.name;
13
14
  // I.e. FooBar_ZazInner
14
15
  const tsFullName = tsPrefix + (0, case_1.maybeSnakeToCamel)(enumDesc.name, options);
15
- const tsFullNameWithAffixes = messageName(`${options.typePrefix}${tsFullName}${options.typeSuffix}`);
16
+ const tsFullNameWithAffixes = messageName((0, utils_1.wrapTypeName)(options, tsFullName));
16
17
  const nestedSourceInfo = sourceInfo.open(childEnumType, index);
17
18
  enumFn(tsFullNameWithAffixes, enumDesc, nestedSourceInfo, protoFullName);
18
19
  });
@@ -23,7 +24,7 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
23
24
  const protoFullName = protoPrefix + message.name;
24
25
  // I.e. FooBar_ZazInner
25
26
  const tsFullName = tsPrefix + (0, case_1.maybeSnakeToCamel)(message.name, options);
26
- const tsFullNameWithAffixes = messageName(`${options.typePrefix}${tsFullName}${options.typeSuffix}`);
27
+ const tsFullNameWithAffixes = messageName((0, utils_1.wrapTypeName)(options, tsFullName));
27
28
  const nestedSourceInfo = sourceInfo.open(childType, index);
28
29
  messageFn(tsFullNameWithAffixes, message, nestedSourceInfo, protoFullName);
29
30
  const delim = options.useSnakeTypeName ? "_" : "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",