ts-proto 1.122.0 → 1.123.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.123.0](https://github.com/stephenh/ts-proto/compare/v1.122.0...v1.123.0) (2022-08-27)
2
+
3
+
4
+ ### Features
5
+
6
+ * Bump ts-poet for dprint, also use tsx ([#660](https://github.com/stephenh/ts-proto/issues/660)) ([348a465](https://github.com/stephenh/ts-proto/commit/348a4651b42d5ff64fd07e36ef9ca7d7e76f4277))
7
+
1
8
  # [1.122.0](https://github.com/stephenh/ts-proto/compare/v1.121.6...v1.122.0) (2022-08-15)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -113,6 +113,9 @@ version: v1
113
113
  plugins:
114
114
  - remote: buf.build/stephenh/plugins/ts-proto
115
115
  out: ../gen/ts
116
+ opt:
117
+ - outputServices=...
118
+ - useExactTypes=...
116
119
  ```
117
120
 
118
121
  # Goals
package/build/case.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camelCase = exports.capitalize = exports.camelToSnake = exports.snakeToCamel = exports.maybeSnakeToCamel = void 0;
4
4
  /** Converts `key` to TS/JS camel-case idiom, unless overridden not to. */
5
5
  function maybeSnakeToCamel(key, options) {
6
- if (options.snakeToCamel.includes('keys') && key.includes('_')) {
6
+ if (options.snakeToCamel.includes("keys") && key.includes("_")) {
7
7
  return snakeToCamel(key);
8
8
  }
9
9
  else {
@@ -14,17 +14,17 @@ exports.maybeSnakeToCamel = maybeSnakeToCamel;
14
14
  function snakeToCamel(s) {
15
15
  const hasLowerCase = !!s.match(/[a-z]/);
16
16
  return s
17
- .split('_')
17
+ .split("_")
18
18
  .map((word, i) => {
19
19
  // If the word is already mixed case, leave the existing case as-is
20
20
  word = hasLowerCase ? word : word.toLowerCase();
21
21
  return i === 0 ? word : capitalize(word);
22
22
  })
23
- .join('');
23
+ .join("");
24
24
  }
25
25
  exports.snakeToCamel = snakeToCamel;
26
26
  function camelToSnake(s) {
27
- return s.replace(/\w([A-Z])/g, (m) => m[0] + '_' + m[1]).toUpperCase();
27
+ return s.replace(/\w([A-Z])/g, (m) => m[0] + "_" + m[1]).toUpperCase();
28
28
  }
29
29
  exports.camelToSnake = camelToSnake;
30
30
  function capitalize(s) {
package/build/encode.js CHANGED
@@ -10,36 +10,36 @@ function generateEncoder(ctx, typeName) {
10
10
  if (!name) {
11
11
  return (0, ts_poet_1.code) `${(0, types_1.messageToTypeName)(ctx, typeName, { keepValueType: true })}.encode(value).finish()`;
12
12
  }
13
- if (name == 'Timestamp') {
14
- const TimestampValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/timestamp', name);
13
+ if (name == "Timestamp") {
14
+ const TimestampValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", name);
15
15
  return (0, ts_poet_1.code) `${TimestampValue}.encode(${ctx.utils.toTimestamp}(value)).finish()`;
16
16
  }
17
- if (name == 'Struct') {
18
- const StructType = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
17
+ if (name == "Struct") {
18
+ const StructType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
19
19
  return (0, ts_poet_1.code) `${StructType}.encode(${StructType}.wrap(value)).finish()`;
20
20
  }
21
- if (name == 'ListValue') {
22
- const ListValueType = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
21
+ if (name == "ListValue") {
22
+ const ListValueType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
23
23
  return (0, ts_poet_1.code) `${ListValueType}.encode({values: value ?? []}).finish()`;
24
24
  }
25
- const TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/wrappers', name);
25
+ const TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", name);
26
26
  switch (name) {
27
- case 'StringValue':
27
+ case "StringValue":
28
28
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? ""}).finish()`;
29
- case 'Int32Value':
30
- case 'UInt32Value':
31
- case 'DoubleValue':
32
- case 'FloatValue':
29
+ case "Int32Value":
30
+ case "UInt32Value":
31
+ case "DoubleValue":
32
+ case "FloatValue":
33
33
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? 0}).finish()`;
34
- case 'Int64Value':
35
- case 'UInt64Value':
34
+ case "Int64Value":
35
+ case "UInt64Value":
36
36
  if (ctx.options.forceLong === options_1.LongOption.LONG) {
37
37
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ? value.toNumber(): 0}).finish()`;
38
38
  }
39
39
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? 0 }).finish()`;
40
- case 'BoolValue':
40
+ case "BoolValue":
41
41
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? false}).finish()`;
42
- case 'BytesValue':
42
+ case "BytesValue":
43
43
  return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? new Uint8Array()}).finish()`;
44
44
  }
45
45
  throw new Error(`unknown wrapper type: ${name}`);
@@ -52,15 +52,15 @@ function generateDecoder(ctx, typeName) {
52
52
  return (0, ts_poet_1.code) `${(0, types_1.messageToTypeName)(ctx, typeName, { keepValueType: true })}.decode(value)`;
53
53
  }
54
54
  let TypeValue;
55
- if (name == 'Timestamp') {
56
- TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/timestamp', name);
55
+ if (name == "Timestamp") {
56
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/timestamp", name);
57
57
  return (0, ts_poet_1.code) `${TypeValue}.decode(value)`;
58
58
  }
59
- if (name == 'Struct' || name == 'ListValue') {
60
- TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
59
+ if (name == "Struct" || name == "ListValue") {
60
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
61
61
  return (0, ts_poet_1.code) `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
62
62
  }
63
- TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/wrappers', name);
63
+ TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/wrappers", name);
64
64
  return (0, ts_poet_1.code) `${TypeValue}.decode(value).value`;
65
65
  }
66
66
  exports.generateDecoder = generateDecoder;
package/build/enums.js CHANGED
@@ -5,7 +5,7 @@ const ts_poet_1 = require("ts-poet");
5
5
  const utils_1 = require("./utils");
6
6
  const case_1 = require("./case");
7
7
  const sourceInfo_1 = require("./sourceInfo");
8
- const UNRECOGNIZED_ENUM_NAME = 'UNRECOGNIZED';
8
+ const UNRECOGNIZED_ENUM_NAME = "UNRECOGNIZED";
9
9
  const UNRECOGNIZED_ENUM_VALUE = -1;
10
10
  // Output the `enum { Foo, A = 0, B = 1 }`
11
11
  function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
@@ -17,9 +17,9 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
17
17
  chunks.push((0, ts_poet_1.code) `export const ${(0, ts_poet_1.def)(fullName)} = {`);
18
18
  }
19
19
  else {
20
- chunks.push((0, ts_poet_1.code) `export ${options.constEnums ? 'const ' : ''}enum ${(0, ts_poet_1.def)(fullName)} {`);
20
+ chunks.push((0, ts_poet_1.code) `export ${options.constEnums ? "const " : ""}enum ${(0, ts_poet_1.def)(fullName)} {`);
21
21
  }
22
- const delimiter = options.enumsAsLiterals ? ':' : '=';
22
+ const delimiter = options.enumsAsLiterals ? ":" : "=";
23
23
  enumDesc.value.forEach((valueDesc, index) => {
24
24
  var _a;
25
25
  const info = sourceInfo.lookup(sourceInfo_1.Fields.enum.value, index);
@@ -49,14 +49,14 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
49
49
  chunks.push((0, ts_poet_1.code) `\n`);
50
50
  chunks.push(generateEnumToNumber(ctx, fullName, enumDesc));
51
51
  }
52
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
52
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
53
53
  }
54
54
  exports.generateEnum = generateEnum;
55
55
  /** Generates a function with a big switch statement to decode JSON -> our enum. */
56
56
  function generateEnumFromJson(ctx, fullName, enumDesc) {
57
57
  const { options, utils } = ctx;
58
58
  const chunks = [];
59
- const functionName = (0, case_1.camelCase)(fullName) + 'FromJSON';
59
+ const functionName = (0, case_1.camelCase)(fullName) + "FromJSON";
60
60
  chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: any): ${fullName} {`);
61
61
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
62
62
  for (const valueDesc of enumDesc.value) {
@@ -83,15 +83,15 @@ function generateEnumFromJson(ctx, fullName, enumDesc) {
83
83
  }
84
84
  chunks.push((0, ts_poet_1.code) `}`);
85
85
  chunks.push((0, ts_poet_1.code) `}`);
86
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
86
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
87
87
  }
88
88
  exports.generateEnumFromJson = generateEnumFromJson;
89
89
  /** Generates a function with a big switch statement to encode our enum -> JSON. */
90
90
  function generateEnumToJson(ctx, fullName, enumDesc) {
91
91
  const { options, utils } = ctx;
92
92
  const chunks = [];
93
- const functionName = (0, case_1.camelCase)(fullName) + 'ToJSON';
94
- chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): ${ctx.options.useNumericEnumForJson ? 'number' : 'string'} {`);
93
+ const functionName = (0, case_1.camelCase)(fullName) + "ToJSON";
94
+ chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): ${ctx.options.useNumericEnumForJson ? "number" : "string"} {`);
95
95
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
96
96
  for (const valueDesc of enumDesc.value) {
97
97
  if (ctx.options.useNumericEnumForJson) {
@@ -126,14 +126,14 @@ function generateEnumToJson(ctx, fullName, enumDesc) {
126
126
  }
127
127
  chunks.push((0, ts_poet_1.code) `}`);
128
128
  chunks.push((0, ts_poet_1.code) `}`);
129
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
129
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
130
130
  }
131
131
  exports.generateEnumToJson = generateEnumToJson;
132
132
  /** Generates a function with a big switch statement to encode our string enum -> int value. */
133
133
  function generateEnumToNumber(ctx, fullName, enumDesc) {
134
134
  const { options, utils } = ctx;
135
135
  const chunks = [];
136
- const functionName = (0, case_1.camelCase)(fullName) + 'ToNumber';
136
+ const functionName = (0, case_1.camelCase)(fullName) + "ToNumber";
137
137
  chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): number {`);
138
138
  chunks.push((0, ts_poet_1.code) `switch (object) {`);
139
139
  for (const valueDesc of enumDesc.value) {
@@ -155,6 +155,6 @@ function generateEnumToNumber(ctx, fullName, enumDesc) {
155
155
  }
156
156
  chunks.push((0, ts_poet_1.code) `}`);
157
157
  chunks.push((0, ts_poet_1.code) `}`);
158
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
158
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
159
159
  }
160
160
  exports.generateEnumToNumber = generateEnumToNumber;
@@ -40,7 +40,7 @@ function generateGenericServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc
40
40
  },
41
41
  } as const;
42
42
  `);
43
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
43
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
44
44
  }
45
45
  exports.generateGenericServiceDefinition = generateGenericServiceDefinition;
46
46
  function generateMethodDefinition(ctx, methodDesc) {
@@ -69,5 +69,5 @@ function generateMethodOptions(options) {
69
69
  }
70
70
  }
71
71
  chunks.push((0, ts_poet_1.code) `}`);
72
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
72
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
73
73
  }
@@ -6,22 +6,22 @@ const sourceInfo_1 = require("./sourceInfo");
6
6
  const types_1 = require("./types");
7
7
  const utils_1 = require("./utils");
8
8
  const encode_1 = require("./encode");
9
- const CallOptions = (0, ts_poet_1.imp)('CallOptions@@grpc/grpc-js');
10
- const ChannelCredentials = (0, ts_poet_1.imp)('ChannelCredentials@@grpc/grpc-js');
11
- const ChannelOptions = (0, ts_poet_1.imp)('ChannelOptions@@grpc/grpc-js');
12
- const Client = (0, ts_poet_1.imp)('Client@@grpc/grpc-js');
13
- const ClientDuplexStream = (0, ts_poet_1.imp)('ClientDuplexStream@@grpc/grpc-js');
14
- const ClientReadableStream = (0, ts_poet_1.imp)('ClientReadableStream@@grpc/grpc-js');
15
- const ClientUnaryCall = (0, ts_poet_1.imp)('ClientUnaryCall@@grpc/grpc-js');
16
- const ClientWritableStream = (0, ts_poet_1.imp)('ClientWritableStream@@grpc/grpc-js');
17
- const handleBidiStreamingCall = (0, ts_poet_1.imp)('handleBidiStreamingCall@@grpc/grpc-js');
18
- const handleClientStreamingCall = (0, ts_poet_1.imp)('handleClientStreamingCall@@grpc/grpc-js');
19
- const handleServerStreamingCall = (0, ts_poet_1.imp)('handleServerStreamingCall@@grpc/grpc-js');
20
- const handleUnaryCall = (0, ts_poet_1.imp)('handleUnaryCall@@grpc/grpc-js');
21
- const UntypedServiceImplementation = (0, ts_poet_1.imp)('UntypedServiceImplementation@@grpc/grpc-js');
22
- const makeGenericClientConstructor = (0, ts_poet_1.imp)('makeGenericClientConstructor@@grpc/grpc-js');
23
- const Metadata = (0, ts_poet_1.imp)('Metadata@@grpc/grpc-js');
24
- const ServiceError = (0, ts_poet_1.imp)('ServiceError@@grpc/grpc-js');
9
+ const CallOptions = (0, ts_poet_1.imp)("CallOptions@@grpc/grpc-js");
10
+ const ChannelCredentials = (0, ts_poet_1.imp)("ChannelCredentials@@grpc/grpc-js");
11
+ const ChannelOptions = (0, ts_poet_1.imp)("ChannelOptions@@grpc/grpc-js");
12
+ const Client = (0, ts_poet_1.imp)("Client@@grpc/grpc-js");
13
+ const ClientDuplexStream = (0, ts_poet_1.imp)("ClientDuplexStream@@grpc/grpc-js");
14
+ const ClientReadableStream = (0, ts_poet_1.imp)("ClientReadableStream@@grpc/grpc-js");
15
+ const ClientUnaryCall = (0, ts_poet_1.imp)("ClientUnaryCall@@grpc/grpc-js");
16
+ const ClientWritableStream = (0, ts_poet_1.imp)("ClientWritableStream@@grpc/grpc-js");
17
+ const handleBidiStreamingCall = (0, ts_poet_1.imp)("handleBidiStreamingCall@@grpc/grpc-js");
18
+ const handleClientStreamingCall = (0, ts_poet_1.imp)("handleClientStreamingCall@@grpc/grpc-js");
19
+ const handleServerStreamingCall = (0, ts_poet_1.imp)("handleServerStreamingCall@@grpc/grpc-js");
20
+ const handleUnaryCall = (0, ts_poet_1.imp)("handleUnaryCall@@grpc/grpc-js");
21
+ const UntypedServiceImplementation = (0, ts_poet_1.imp)("UntypedServiceImplementation@@grpc/grpc-js");
22
+ const makeGenericClientConstructor = (0, ts_poet_1.imp)("makeGenericClientConstructor@@grpc/grpc-js");
23
+ const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
24
+ const ServiceError = (0, ts_poet_1.imp)("ServiceError@@grpc/grpc-js");
25
25
  /**
26
26
  * Generates a service definition and server / client stubs for the
27
27
  * `@grpc/grpc-js` library.
@@ -35,7 +35,7 @@ function generateGrpcJsService(ctx, fileDesc, sourceInfo, serviceDesc) {
35
35
  chunks.push(generateClientStub(ctx, sourceInfo, serviceDesc));
36
36
  chunks.push(generateClientConstructor(fileDesc, serviceDesc));
37
37
  }
38
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n\n' });
38
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
39
39
  }
40
40
  exports.generateGrpcJsService = generateGrpcJsService;
41
41
  function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
@@ -76,7 +76,7 @@ function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
76
76
  `);
77
77
  }
78
78
  chunks.push((0, ts_poet_1.code) `} as const;`);
79
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
79
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
80
80
  }
81
81
  function generateServerStub(ctx, sourceInfo, serviceDesc) {
82
82
  var _a;
@@ -100,7 +100,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
100
100
  `);
101
101
  }
102
102
  chunks.push((0, ts_poet_1.code) `}`);
103
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
103
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
104
104
  }
105
105
  function generateClientStub(ctx, sourceInfo, serviceDesc) {
106
106
  var _a;
@@ -187,7 +187,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
187
187
  }
188
188
  }
189
189
  chunks.push((0, ts_poet_1.code) `}`);
190
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
190
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
191
191
  }
192
192
  function generateClientConstructor(fileDesc, serviceDesc) {
193
193
  return (0, ts_poet_1.code) `
@@ -4,10 +4,10 @@ exports.addGrpcWebMisc = exports.generateGrpcMethodDesc = exports.generateGrpcSe
4
4
  const types_1 = require("./types");
5
5
  const ts_poet_1 = require("ts-poet");
6
6
  const utils_1 = require("./utils");
7
- const grpc = (0, ts_poet_1.imp)('grpc@@improbable-eng/grpc-web');
8
- const share = (0, ts_poet_1.imp)('share@rxjs/operators');
9
- const take = (0, ts_poet_1.imp)('take@rxjs/operators');
10
- const BrowserHeaders = (0, ts_poet_1.imp)('BrowserHeaders@browser-headers');
7
+ const grpc = (0, ts_poet_1.imp)("grpc@@improbable-eng/grpc-web");
8
+ const share = (0, ts_poet_1.imp)("share@rxjs/operators");
9
+ const take = (0, ts_poet_1.imp)("take@rxjs/operators");
10
+ const BrowserHeaders = (0, ts_poet_1.imp)("BrowserHeaders@browser-headers");
11
11
  /** Generates a client that uses the `@improbable-web/grpc-web` library. */
12
12
  function generateGrpcClientImpl(ctx, _fileDesc, serviceDesc) {
13
13
  const chunks = [];
@@ -33,7 +33,7 @@ function generateGrpcClientImpl(ctx, _fileDesc, serviceDesc) {
33
33
  chunks.push(generateRpcMethod(ctx, serviceDesc, methodDesc));
34
34
  }
35
35
  chunks.push((0, ts_poet_1.code) `}`);
36
- return (0, ts_poet_1.joinCode)(chunks, { trim: false, on: '\n' });
36
+ return (0, ts_poet_1.joinCode)(chunks, { trim: false, on: "\n" });
37
37
  }
38
38
  exports.generateGrpcClientImpl = generateGrpcClientImpl;
39
39
  /** Creates the RPC methods that client code actually calls. */
@@ -52,7 +52,7 @@ function generateRpcMethod(ctx, serviceDesc, methodDesc) {
52
52
  }
53
53
  `;
54
54
  }
55
- const method = methodDesc.serverStreaming ? 'invoke' : 'unary';
55
+ const method = methodDesc.serverStreaming ? "invoke" : "unary";
56
56
  return (0, ts_poet_1.code) `
57
57
  ${methodDesc.formattedName}(
58
58
  request: ${inputType},
@@ -115,7 +115,7 @@ function generateGrpcMethodDesc(ctx, serviceDesc, methodDesc) {
115
115
  methodName: "${methodDesc.name}",
116
116
  service: ${serviceDesc.name}Desc,
117
117
  requestStream: false,
118
- responseStream: ${methodDesc.serverStreaming ? 'true' : 'false'},
118
+ responseStream: ${methodDesc.serverStreaming ? "true" : "false"},
119
119
  requestType: ${requestFn} as any,
120
120
  responseType: ${responseFn} as any,
121
121
  };
@@ -135,14 +135,14 @@ function addGrpcWebMisc(ctx, hasStreamingMethods) {
135
135
  chunks.push((0, ts_poet_1.code) `type UnaryMethodDefinitionish = UnaryMethodDefinitionishR;`);
136
136
  chunks.push(generateGrpcWebRpcType(ctx, options.returnObservable, hasStreamingMethods));
137
137
  chunks.push(generateGrpcWebImpl(ctx, options.returnObservable, hasStreamingMethods));
138
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n\n' });
138
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
139
139
  }
140
140
  exports.addGrpcWebMisc = addGrpcWebMisc;
141
141
  /** Makes an `Rpc` interface to decouple from the low-level grpc-web `grpc.invoke and grpc.unary`/etc. methods. */
142
142
  function generateGrpcWebRpcType(ctx, returnObservable, hasStreamingMethods) {
143
143
  const chunks = [];
144
144
  chunks.push((0, ts_poet_1.code) `interface Rpc {`);
145
- const wrapper = returnObservable ? (0, types_1.observableType)(ctx) : 'Promise';
145
+ const wrapper = returnObservable ? (0, types_1.observableType)(ctx) : "Promise";
146
146
  chunks.push((0, ts_poet_1.code) `
147
147
  unary<T extends UnaryMethodDefinitionish>(
148
148
  methodDesc: T,
@@ -160,14 +160,14 @@ function generateGrpcWebRpcType(ctx, returnObservable, hasStreamingMethods) {
160
160
  `);
161
161
  }
162
162
  chunks.push((0, ts_poet_1.code) `}`);
163
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
163
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
164
164
  }
165
165
  /** Implements the `Rpc` interface by making calls using the `grpc.unary` method. */
166
166
  function generateGrpcWebImpl(ctx, returnObservable, hasStreamingMethods) {
167
167
  const options = (0, ts_poet_1.code) `
168
168
  {
169
169
  transport?: grpc.TransportFactory,
170
- ${hasStreamingMethods ? 'streamingTransport?: grpc.TransportFactory,' : ``}
170
+ ${hasStreamingMethods ? "streamingTransport?: grpc.TransportFactory," : ``}
171
171
  debug?: boolean,
172
172
  metadata?: grpc.Metadata,
173
173
  upStreamRetryCodes?: number[],
@@ -10,9 +10,9 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
10
10
  var _a;
11
11
  const { options } = ctx;
12
12
  const chunks = [];
13
- const Metadata = (0, ts_poet_1.imp)('Metadata@@grpc/grpc-js');
13
+ const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
14
14
  (0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
15
- const t = options.context ? `<${main_1.contextTypeVar}>` : '';
15
+ const t = options.context ? `<${main_1.contextTypeVar}>` : "";
16
16
  chunks.push((0, ts_poet_1.code) `
17
17
  export interface ${serviceDesc.name}Controller${t} {
18
18
  `);
@@ -28,7 +28,7 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
28
28
  params.push((0, ts_poet_1.code) `request: ${(0, types_1.requestType)(ctx, methodDesc)}`);
29
29
  // Use metadata as last argument for interface only configuration
30
30
  if (options.addGrpcMetadata) {
31
- const q = options.addNestjsRestParameter ? '' : '?';
31
+ const q = options.addNestjsRestParameter ? "" : "?";
32
32
  params.push((0, ts_poet_1.code) `metadata${q}: ${Metadata}`);
33
33
  }
34
34
  if (options.addNestjsRestParameter) {
@@ -51,12 +51,12 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
51
51
  `;
52
52
  }
53
53
  chunks.push((0, ts_poet_1.code) `
54
- ${methodDesc.formattedName}(${(0, ts_poet_1.joinCode)(params, { on: ', ' })}): ${returns};
54
+ ${methodDesc.formattedName}(${(0, ts_poet_1.joinCode)(params, { on: ", " })}): ${returns};
55
55
  `);
56
56
  if (options.context) {
57
57
  const batchMethod = (0, types_1.detectBatchMethod)(ctx, fileDesc, serviceDesc, methodDesc);
58
58
  if (batchMethod) {
59
- const maybeCtx = options.context ? 'ctx: Context,' : '';
59
+ const maybeCtx = options.context ? "ctx: Context," : "";
60
60
  chunks.push((0, ts_poet_1.code) `
61
61
  ${batchMethod.singleMethodName}(
62
62
  ${maybeCtx}
@@ -67,13 +67,13 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
67
67
  }
68
68
  });
69
69
  chunks.push((0, ts_poet_1.code) `}`);
70
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n\n' });
70
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
71
71
  }
72
72
  exports.generateNestjsServiceController = generateNestjsServiceController;
73
73
  function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
74
74
  const { options } = ctx;
75
75
  const chunks = [];
76
- const Metadata = (0, ts_poet_1.imp)('Metadata@@grpc/grpc-js');
76
+ const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
77
77
  (0, utils_1.maybeAddComment)(sourceInfo, chunks);
78
78
  const t = options.context ? `<${main_1.contextTypeVar}>` : ``;
79
79
  chunks.push((0, ts_poet_1.code) `
@@ -89,7 +89,7 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
89
89
  params.push((0, ts_poet_1.code) `request: ${(0, types_1.requestType)(ctx, methodDesc)}`);
90
90
  // Use metadata as last argument for interface only configuration
91
91
  if (options.addGrpcMetadata) {
92
- const q = options.addNestjsRestParameter ? '' : '?';
92
+ const q = options.addNestjsRestParameter ? "" : "?";
93
93
  params.push((0, ts_poet_1.code) `metadata${q}: ${Metadata}`);
94
94
  }
95
95
  if (options.addNestjsRestParameter) {
@@ -101,13 +101,13 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
101
101
  (0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
102
102
  chunks.push((0, ts_poet_1.code) `
103
103
  ${methodDesc.formattedName}(
104
- ${(0, ts_poet_1.joinCode)(params, { on: ',' })}
104
+ ${(0, ts_poet_1.joinCode)(params, { on: "," })}
105
105
  ): ${returns};
106
106
  `);
107
107
  if (options.context) {
108
108
  const batchMethod = (0, types_1.detectBatchMethod)(ctx, fileDesc, serviceDesc, methodDesc);
109
109
  if (batchMethod) {
110
- const maybeContext = options.context ? `ctx: Context,` : '';
110
+ const maybeContext = options.context ? `ctx: Context,` : "";
111
111
  chunks.push((0, ts_poet_1.code) `
112
112
  ${batchMethod.singleMethodName}(
113
113
  ${maybeContext}
@@ -118,13 +118,13 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
118
118
  }
119
119
  });
120
120
  chunks.push((0, ts_poet_1.code) `}`);
121
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n\n' });
121
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
122
122
  }
123
123
  exports.generateNestjsServiceClient = generateNestjsServiceClient;
124
124
  function generateNestjsGrpcServiceMethodsDecorator(ctx, serviceDesc) {
125
125
  const { options } = ctx;
126
- const GrpcMethod = (0, ts_poet_1.imp)('GrpcMethod@@nestjs/microservices');
127
- const GrpcStreamMethod = (0, ts_poet_1.imp)('GrpcStreamMethod@@nestjs/microservices');
126
+ const GrpcMethod = (0, ts_poet_1.imp)("GrpcMethod@@nestjs/microservices");
127
+ const GrpcStreamMethod = (0, ts_poet_1.imp)("GrpcStreamMethod@@nestjs/microservices");
128
128
  const grpcMethods = serviceDesc.method
129
129
  .filter((m) => !m.clientStreaming)
130
130
  .map((m) => {
@@ -142,12 +142,12 @@ function generateNestjsGrpcServiceMethodsDecorator(ctx, serviceDesc) {
142
142
  return (0, ts_poet_1.code) `
143
143
  export function ${serviceDesc.name}ControllerMethods() {
144
144
  return function(constructor: Function) {
145
- const grpcMethods: string[] = [${grpcMethods.join(', ')}];
145
+ const grpcMethods: string[] = [${grpcMethods.join(", ")}];
146
146
  for (const method of grpcMethods) {
147
147
  const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
148
148
  ${GrpcMethod}('${serviceDesc.name}', method)(constructor.prototype[method], method, descriptor);
149
149
  }
150
- const grpcStreamMethods: string[] = [${grpcStreamMethods.join(', ')}];
150
+ const grpcStreamMethods: string[] = [${grpcStreamMethods.join(", ")}];
151
151
  for (const method of grpcStreamMethods) {
152
152
  const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
153
153
  ${GrpcStreamMethod}('${serviceDesc.name}', method)(constructor.prototype[method], method, descriptor);
@@ -6,8 +6,8 @@ const case_1 = require("./case");
6
6
  const sourceInfo_1 = require("./sourceInfo");
7
7
  const types_1 = require("./types");
8
8
  const utils_1 = require("./utils");
9
- const CallOptions = (0, ts_poet_1.imp)('CallOptions@nice-grpc-common');
10
- const CallContext = (0, ts_poet_1.imp)('CallContext@nice-grpc-common');
9
+ const CallOptions = (0, ts_poet_1.imp)("CallOptions@nice-grpc-common");
10
+ const CallContext = (0, ts_poet_1.imp)("CallContext@nice-grpc-common");
11
11
  /**
12
12
  * Generates server / client stubs for `nice-grpc` library.
13
13
  */
@@ -15,7 +15,7 @@ function generateNiceGrpcService(ctx, fileDesc, sourceInfo, serviceDesc) {
15
15
  const chunks = [];
16
16
  chunks.push(generateServerStub(ctx, sourceInfo, serviceDesc));
17
17
  chunks.push(generateClientStub(ctx, sourceInfo, serviceDesc));
18
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n\n' });
18
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
19
19
  }
20
20
  exports.generateNiceGrpcService = generateNiceGrpcService;
21
21
  function generateServerStub(ctx, sourceInfo, serviceDesc) {
@@ -74,7 +74,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
74
74
  }
75
75
  }
76
76
  chunks.push((0, ts_poet_1.code) `}`);
77
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
77
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
78
78
  }
79
79
  function generateClientStub(ctx, sourceInfo, serviceDesc) {
80
80
  var _a;
@@ -131,5 +131,5 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
131
131
  }
132
132
  }
133
133
  chunks.push((0, ts_poet_1.code) `}`);
134
- return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
134
+ return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
135
135
  }