ts-proto 1.115.3 → 1.116.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,24 @@
1
+ # [1.116.0](https://github.com/stephenh/ts-proto/compare/v1.115.5...v1.116.0) (2022-07-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * add option to use async iterables ([#605](https://github.com/stephenh/ts-proto/issues/605)) ([ca8ea8d](https://github.com/stephenh/ts-proto/commit/ca8ea8d761c02d3ca4da6eaa156acff35d88c510)), closes [#600](https://github.com/stephenh/ts-proto/issues/600)
7
+
8
+ ## [1.115.5](https://github.com/stephenh/ts-proto/compare/v1.115.4...v1.115.5) (2022-06-22)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove Long import statement when Long was unused ([#599](https://github.com/stephenh/ts-proto/issues/599)) ([58dc10c](https://github.com/stephenh/ts-proto/commit/58dc10c61ec5a76d4b54ba9eddf34021979dd4aa))
14
+
15
+ ## [1.115.4](https://github.com/stephenh/ts-proto/compare/v1.115.3...v1.115.4) (2022-06-05)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * Struct wrap/unwrap snake case [#579](https://github.com/stephenh/ts-proto/issues/579) ([#588](https://github.com/stephenh/ts-proto/issues/588)) ([33f89bf](https://github.com/stephenh/ts-proto/commit/33f89bfcf0d5d9e64a6fd360eaefc140055e9291))
21
+
1
22
  ## [1.115.3](https://github.com/stephenh/ts-proto/compare/v1.115.2...v1.115.3) (2022-06-03)
2
23
 
3
24
 
package/README.markdown CHANGED
@@ -381,6 +381,8 @@ Generated code will be placed in the Gradle build directory.
381
381
 
382
382
  - With `--ts_proto_opt=outputServices=false`, or `=none`, ts-proto will output NO service definitions.
383
383
 
384
+ - With `--ts_proto_opt=useAsyncIterable=true`, the generated services will use `AsyncIterable` instead of `Observable`.
385
+
384
386
  - With `--ts_proto_opt=emitImportedFiles=false`, ts-proto will not emit `google/protobuf/*` files unless you explicit add files to `protoc` like this
385
387
  `protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto my_message.proto google/protobuf/duration.proto`
386
388
 
package/build/encode.js CHANGED
@@ -6,61 +6,61 @@ const types_1 = require("./types");
6
6
  const options_1 = require("./options");
7
7
  const utils_1 = require("./utils");
8
8
  function generateEncoder(ctx, typeName) {
9
- const name = types_1.wrapperTypeName(typeName);
9
+ const name = (0, types_1.wrapperTypeName)(typeName);
10
10
  if (!name) {
11
- return ts_poet_1.code `${types_1.messageToTypeName(ctx, typeName, { keepValueType: true })}.encode(value).finish()`;
11
+ return (0, ts_poet_1.code) `${(0, types_1.messageToTypeName)(ctx, typeName, { keepValueType: true })}.encode(value).finish()`;
12
12
  }
13
13
  if (name == 'Timestamp') {
14
- const TimestampValue = utils_1.impProto(ctx.options, 'google/protobuf/timestamp', name);
15
- return ts_poet_1.code `${TimestampValue}.encode(${ctx.utils.toTimestamp}(value)).finish()`;
14
+ const TimestampValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/timestamp', name);
15
+ return (0, ts_poet_1.code) `${TimestampValue}.encode(${ctx.utils.toTimestamp}(value)).finish()`;
16
16
  }
17
17
  if (name == 'Struct') {
18
- const StructType = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
19
- return ts_poet_1.code `${StructType}.encode(${StructType}.wrap(value)).finish()`;
18
+ const StructType = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
19
+ return (0, ts_poet_1.code) `${StructType}.encode(${StructType}.wrap(value)).finish()`;
20
20
  }
21
21
  if (name == 'ListValue') {
22
- const ListValueType = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
23
- return ts_poet_1.code `${ListValueType}.encode({values: value ?? []}).finish()`;
22
+ const ListValueType = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
23
+ return (0, ts_poet_1.code) `${ListValueType}.encode({values: value ?? []}).finish()`;
24
24
  }
25
- const TypeValue = 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
27
  case 'StringValue':
28
- return ts_poet_1.code `${TypeValue}.encode({value: value ?? ""}).finish()`;
28
+ return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? ""}).finish()`;
29
29
  case 'Int32Value':
30
30
  case 'UInt32Value':
31
31
  case 'DoubleValue':
32
32
  case 'FloatValue':
33
- return ts_poet_1.code `${TypeValue}.encode({value: value ?? 0}).finish()`;
33
+ return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? 0}).finish()`;
34
34
  case 'Int64Value':
35
35
  case 'UInt64Value':
36
36
  if (ctx.options.forceLong === options_1.LongOption.LONG) {
37
- return ts_poet_1.code `${TypeValue}.encode({value: value ? value.toNumber(): 0}).finish()`;
37
+ return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ? value.toNumber(): 0}).finish()`;
38
38
  }
39
- return ts_poet_1.code `${TypeValue}.encode({value: value ?? 0 }).finish()`;
39
+ return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? 0 }).finish()`;
40
40
  case 'BoolValue':
41
- return ts_poet_1.code `${TypeValue}.encode({value: value ?? false}).finish()`;
41
+ return (0, ts_poet_1.code) `${TypeValue}.encode({value: value ?? false}).finish()`;
42
42
  case 'BytesValue':
43
- return ts_poet_1.code `${TypeValue}.encode({value: value ?? new Uint8Array()}).finish()`;
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}`);
46
46
  }
47
47
  exports.generateEncoder = generateEncoder;
48
48
  function generateDecoder(ctx, typeName) {
49
49
  const { options } = ctx;
50
- let name = types_1.wrapperTypeName(typeName);
50
+ let name = (0, types_1.wrapperTypeName)(typeName);
51
51
  if (!name) {
52
- return ts_poet_1.code `${types_1.messageToTypeName(ctx, typeName, { keepValueType: true })}.decode(value)`;
52
+ return (0, ts_poet_1.code) `${(0, types_1.messageToTypeName)(ctx, typeName, { keepValueType: true })}.decode(value)`;
53
53
  }
54
54
  let TypeValue;
55
55
  if (name == 'Timestamp') {
56
- TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/timestamp', name);
57
- return ts_poet_1.code `${TypeValue}.decode(value)`;
56
+ TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/timestamp', name);
57
+ return (0, ts_poet_1.code) `${TypeValue}.decode(value)`;
58
58
  }
59
59
  if (name == 'Struct' || name == 'ListValue') {
60
- TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
61
- return ts_poet_1.code `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
60
+ TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/struct', name);
61
+ return (0, ts_poet_1.code) `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
62
62
  }
63
- TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/wrappers', name);
64
- return ts_poet_1.code `${TypeValue}.decode(value).value`;
63
+ TypeValue = (0, utils_1.impProto)(ctx.options, 'google/protobuf/wrappers', name);
64
+ return (0, ts_poet_1.code) `${TypeValue}.decode(value).value`;
65
65
  }
66
66
  exports.generateDecoder = generateDecoder;
package/build/enums.js CHANGED
@@ -12,62 +12,62 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
12
12
  var _a;
13
13
  const { options } = ctx;
14
14
  const chunks = [];
15
- utils_1.maybeAddComment(sourceInfo, chunks, (_a = enumDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
15
+ (0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = enumDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
16
16
  if (options.enumsAsLiterals) {
17
- chunks.push(ts_poet_1.code `export const ${ts_poet_1.def(fullName)} = {`);
17
+ chunks.push((0, ts_poet_1.code) `export const ${(0, ts_poet_1.def)(fullName)} = {`);
18
18
  }
19
19
  else {
20
- chunks.push(ts_poet_1.code `export ${options.constEnums ? 'const ' : ''}enum ${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
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);
26
- utils_1.maybeAddComment(info, chunks, (_a = valueDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated, `${valueDesc.name} - `);
27
- chunks.push(ts_poet_1.code `${valueDesc.name} ${delimiter} ${options.stringEnums ? `"${valueDesc.name}"` : valueDesc.number.toString()},`);
26
+ (0, utils_1.maybeAddComment)(info, chunks, (_a = valueDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated, `${valueDesc.name} - `);
27
+ chunks.push((0, ts_poet_1.code) `${valueDesc.name} ${delimiter} ${options.stringEnums ? `"${valueDesc.name}"` : valueDesc.number.toString()},`);
28
28
  });
29
29
  if (options.unrecognizedEnum)
30
- chunks.push(ts_poet_1.code `
30
+ chunks.push((0, ts_poet_1.code) `
31
31
  ${UNRECOGNIZED_ENUM_NAME} ${delimiter} ${options.stringEnums ? `"${UNRECOGNIZED_ENUM_NAME}"` : UNRECOGNIZED_ENUM_VALUE.toString()},`);
32
32
  if (options.enumsAsLiterals) {
33
- chunks.push(ts_poet_1.code `} as const`);
34
- chunks.push(ts_poet_1.code `\n`);
35
- chunks.push(ts_poet_1.code `export type ${ts_poet_1.def(fullName)} = typeof ${ts_poet_1.def(fullName)}[keyof typeof ${ts_poet_1.def(fullName)}]`);
33
+ chunks.push((0, ts_poet_1.code) `} as const`);
34
+ chunks.push((0, ts_poet_1.code) `\n`);
35
+ chunks.push((0, ts_poet_1.code) `export type ${(0, ts_poet_1.def)(fullName)} = typeof ${(0, ts_poet_1.def)(fullName)}[keyof typeof ${(0, ts_poet_1.def)(fullName)}]`);
36
36
  }
37
37
  else {
38
- chunks.push(ts_poet_1.code `}`);
38
+ chunks.push((0, ts_poet_1.code) `}`);
39
39
  }
40
40
  if (options.outputJsonMethods || (options.stringEnums && options.outputEncodeMethods)) {
41
- chunks.push(ts_poet_1.code `\n`);
41
+ chunks.push((0, ts_poet_1.code) `\n`);
42
42
  chunks.push(generateEnumFromJson(ctx, fullName, enumDesc));
43
43
  }
44
44
  if (options.outputJsonMethods) {
45
- chunks.push(ts_poet_1.code `\n`);
45
+ chunks.push((0, ts_poet_1.code) `\n`);
46
46
  chunks.push(generateEnumToJson(ctx, fullName, enumDesc));
47
47
  }
48
48
  if (options.stringEnums && options.outputEncodeMethods) {
49
- chunks.push(ts_poet_1.code `\n`);
49
+ chunks.push((0, ts_poet_1.code) `\n`);
50
50
  chunks.push(generateEnumToNumber(ctx, fullName, enumDesc));
51
51
  }
52
- return 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 = case_1.camelCase(fullName) + 'FromJSON';
60
- chunks.push(ts_poet_1.code `export function ${ts_poet_1.def(functionName)}(object: any): ${fullName} {`);
61
- chunks.push(ts_poet_1.code `switch (object) {`);
59
+ const functionName = (0, case_1.camelCase)(fullName) + 'FromJSON';
60
+ chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: any): ${fullName} {`);
61
+ chunks.push((0, ts_poet_1.code) `switch (object) {`);
62
62
  for (const valueDesc of enumDesc.value) {
63
- chunks.push(ts_poet_1.code `
63
+ chunks.push((0, ts_poet_1.code) `
64
64
  case ${valueDesc.number}:
65
65
  case "${valueDesc.name}":
66
66
  return ${fullName}.${valueDesc.name};
67
67
  `);
68
68
  }
69
69
  if (options.unrecognizedEnum) {
70
- chunks.push(ts_poet_1.code `
70
+ chunks.push((0, ts_poet_1.code) `
71
71
  case ${UNRECOGNIZED_ENUM_VALUE}:
72
72
  case "${UNRECOGNIZED_ENUM_NAME}":
73
73
  default:
@@ -76,28 +76,28 @@ function generateEnumFromJson(ctx, fullName, enumDesc) {
76
76
  }
77
77
  else {
78
78
  // We use globalThis to avoid conflicts on protobuf types named `Error`.
79
- chunks.push(ts_poet_1.code `
79
+ chunks.push((0, ts_poet_1.code) `
80
80
  default:
81
81
  throw new ${utils.globalThis}.Error("Unrecognized enum value " + object + " for enum ${fullName}");
82
82
  `);
83
83
  }
84
- chunks.push(ts_poet_1.code `}`);
85
- chunks.push(ts_poet_1.code `}`);
86
- return ts_poet_1.joinCode(chunks, { on: '\n' });
84
+ chunks.push((0, ts_poet_1.code) `}`);
85
+ chunks.push((0, ts_poet_1.code) `}`);
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 = case_1.camelCase(fullName) + 'ToJSON';
94
- chunks.push(ts_poet_1.code `export function ${ts_poet_1.def(functionName)}(object: ${fullName}): string {`);
95
- chunks.push(ts_poet_1.code `switch (object) {`);
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}): string {`);
95
+ chunks.push((0, ts_poet_1.code) `switch (object) {`);
96
96
  for (const valueDesc of enumDesc.value) {
97
- chunks.push(ts_poet_1.code `case ${fullName}.${valueDesc.name}: return "${valueDesc.name}";`);
97
+ chunks.push((0, ts_poet_1.code) `case ${fullName}.${valueDesc.name}: return "${valueDesc.name}";`);
98
98
  }
99
99
  if (options.unrecognizedEnum) {
100
- chunks.push(ts_poet_1.code `
100
+ chunks.push((0, ts_poet_1.code) `
101
101
  case ${fullName}.${UNRECOGNIZED_ENUM_NAME}:
102
102
  default:
103
103
  return "${UNRECOGNIZED_ENUM_NAME}";
@@ -105,28 +105,28 @@ function generateEnumToJson(ctx, fullName, enumDesc) {
105
105
  }
106
106
  else {
107
107
  // We use globalThis to avoid conflicts on protobuf types named `Error`.
108
- chunks.push(ts_poet_1.code `
108
+ chunks.push((0, ts_poet_1.code) `
109
109
  default:
110
110
  throw new ${utils.globalThis}.Error("Unrecognized enum value " + object + " for enum ${fullName}");
111
111
  `);
112
112
  }
113
- chunks.push(ts_poet_1.code `}`);
114
- chunks.push(ts_poet_1.code `}`);
115
- return ts_poet_1.joinCode(chunks, { on: '\n' });
113
+ chunks.push((0, ts_poet_1.code) `}`);
114
+ chunks.push((0, ts_poet_1.code) `}`);
115
+ return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
116
116
  }
117
117
  exports.generateEnumToJson = generateEnumToJson;
118
118
  /** Generates a function with a big switch statement to encode our string enum -> int value. */
119
119
  function generateEnumToNumber(ctx, fullName, enumDesc) {
120
120
  const { options, utils } = ctx;
121
121
  const chunks = [];
122
- const functionName = case_1.camelCase(fullName) + 'ToNumber';
123
- chunks.push(ts_poet_1.code `export function ${ts_poet_1.def(functionName)}(object: ${fullName}): number {`);
124
- chunks.push(ts_poet_1.code `switch (object) {`);
122
+ const functionName = (0, case_1.camelCase)(fullName) + 'ToNumber';
123
+ chunks.push((0, ts_poet_1.code) `export function ${(0, ts_poet_1.def)(functionName)}(object: ${fullName}): number {`);
124
+ chunks.push((0, ts_poet_1.code) `switch (object) {`);
125
125
  for (const valueDesc of enumDesc.value) {
126
- chunks.push(ts_poet_1.code `case ${fullName}.${valueDesc.name}: return ${valueDesc.number};`);
126
+ chunks.push((0, ts_poet_1.code) `case ${fullName}.${valueDesc.name}: return ${valueDesc.number};`);
127
127
  }
128
128
  if (options.unrecognizedEnum) {
129
- chunks.push(ts_poet_1.code `
129
+ chunks.push((0, ts_poet_1.code) `
130
130
  case ${fullName}.${UNRECOGNIZED_ENUM_NAME}:
131
131
  default:
132
132
  return ${UNRECOGNIZED_ENUM_VALUE};
@@ -134,13 +134,13 @@ function generateEnumToNumber(ctx, fullName, enumDesc) {
134
134
  }
135
135
  else {
136
136
  // We use globalThis to avoid conflicts on protobuf types named `Error`.
137
- chunks.push(ts_poet_1.code `
137
+ chunks.push((0, ts_poet_1.code) `
138
138
  default:
139
139
  throw new ${utils.globalThis}.Error("Unrecognized enum value " + object + " for enum ${fullName}");
140
140
  `);
141
141
  }
142
- chunks.push(ts_poet_1.code `}`);
143
- chunks.push(ts_poet_1.code `}`);
144
- return ts_poet_1.joinCode(chunks, { on: '\n' });
142
+ chunks.push((0, ts_poet_1.code) `}`);
143
+ chunks.push((0, ts_poet_1.code) `}`);
144
+ return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
145
145
  }
146
146
  exports.generateEnumToNumber = generateEnumToNumber;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDecodeTransform = exports.generateEncodeTransform = void 0;
4
+ const ts_poet_1 = require("ts-poet");
5
+ /** Creates a function to transform a message Source to a Uint8Array Source. */
6
+ function generateEncodeTransform(fullName) {
7
+ return (0, ts_poet_1.code) `
8
+ // encodeTransform encodes a source of message objects.
9
+ // Transform<${fullName}, Uint8Array>
10
+ async *encodeTransform(
11
+ source: AsyncIterable<${fullName} | ${fullName}[]> | Iterable<${fullName} | ${fullName}[]>
12
+ ): AsyncIterable<Uint8Array> {
13
+ for await (const pkt of source) {
14
+ if (Array.isArray(pkt)) {
15
+ for (const p of pkt) {
16
+ yield* [${fullName}.encode(p).finish()]
17
+ }
18
+ } else {
19
+ yield* [${fullName}.encode(pkt).finish()]
20
+ }
21
+ }
22
+ }
23
+ `;
24
+ }
25
+ exports.generateEncodeTransform = generateEncodeTransform;
26
+ /** Creates a function to transform a Uint8Array Source to a message Source. */
27
+ function generateDecodeTransform(fullName) {
28
+ return (0, ts_poet_1.code) `
29
+ // decodeTransform decodes a source of encoded messages.
30
+ // Transform<Uint8Array, ${fullName}>
31
+ async *decodeTransform(
32
+ source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>
33
+ ): AsyncIterable<${fullName}> {
34
+ for await (const pkt of source) {
35
+ if (Array.isArray(pkt)) {
36
+ for (const p of pkt) {
37
+ yield* [${fullName}.decode(p)]
38
+ }
39
+ } else {
40
+ yield* [${fullName}.decode(pkt)]
41
+ }
42
+ }
43
+ }
44
+ `;
45
+ }
46
+ exports.generateDecodeTransform = generateDecodeTransform;
@@ -13,40 +13,40 @@ const utils_1 = require("./utils");
13
13
  function generateGenericServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
14
14
  var _a, _b, _c;
15
15
  const chunks = [];
16
- utils_1.maybeAddComment(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
16
+ (0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
17
17
  // Service definition type
18
- const name = ts_poet_1.def(`${serviceDesc.name}Definition`);
19
- chunks.push(ts_poet_1.code `
18
+ const name = (0, ts_poet_1.def)(`${serviceDesc.name}Definition`);
19
+ chunks.push((0, ts_poet_1.code) `
20
20
  export type ${name} = typeof ${name};
21
21
  `);
22
22
  // Service definition
23
- chunks.push(ts_poet_1.code `
23
+ chunks.push((0, ts_poet_1.code) `
24
24
  export const ${name} = {
25
25
  `);
26
26
  (_b = serviceDesc.options) === null || _b === void 0 ? void 0 : _b.uninterpretedOption;
27
- chunks.push(ts_poet_1.code `
27
+ chunks.push((0, ts_poet_1.code) `
28
28
  name: '${serviceDesc.name}',
29
- fullName: '${utils_1.maybePrefixPackage(fileDesc, serviceDesc.name)}',
29
+ fullName: '${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}',
30
30
  methods: {
31
31
  `);
32
32
  for (const [index, methodDesc] of serviceDesc.method.entries()) {
33
33
  const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
34
- utils_1.maybeAddComment(info, chunks, (_c = methodDesc.options) === null || _c === void 0 ? void 0 : _c.deprecated);
35
- chunks.push(ts_poet_1.code `
36
- ${case_1.camelCase(methodDesc.name)}: ${generateMethodDefinition(ctx, methodDesc)},
34
+ (0, utils_1.maybeAddComment)(info, chunks, (_c = methodDesc.options) === null || _c === void 0 ? void 0 : _c.deprecated);
35
+ chunks.push((0, ts_poet_1.code) `
36
+ ${(0, case_1.camelCase)(methodDesc.name)}: ${generateMethodDefinition(ctx, methodDesc)},
37
37
  `);
38
38
  }
39
- chunks.push(ts_poet_1.code `
39
+ chunks.push((0, ts_poet_1.code) `
40
40
  },
41
41
  } as const;
42
42
  `);
43
- return 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) {
47
- const inputType = types_1.messageToTypeName(ctx, methodDesc.inputType, { keepValueType: true });
48
- const outputType = types_1.messageToTypeName(ctx, methodDesc.outputType, { keepValueType: true });
49
- return ts_poet_1.code `
47
+ const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType, { keepValueType: true });
48
+ const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType, { keepValueType: true });
49
+ return (0, ts_poet_1.code) `
50
50
  {
51
51
  name: '${methodDesc.name}',
52
52
  requestType: ${inputType},
@@ -59,15 +59,15 @@ function generateMethodDefinition(ctx, methodDesc) {
59
59
  }
60
60
  function generateMethodOptions(options) {
61
61
  const chunks = [];
62
- chunks.push(ts_poet_1.code `{`);
62
+ chunks.push((0, ts_poet_1.code) `{`);
63
63
  if (options != null) {
64
64
  if (options.idempotencyLevel === ts_proto_descriptors_1.MethodOptions_IdempotencyLevel.IDEMPOTENT) {
65
- chunks.push(ts_poet_1.code `idempotencyLevel: 'IDEMPOTENT',`);
65
+ chunks.push((0, ts_poet_1.code) `idempotencyLevel: 'IDEMPOTENT',`);
66
66
  }
67
67
  else if (options.idempotencyLevel === ts_proto_descriptors_1.MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS) {
68
- chunks.push(ts_poet_1.code `idempotencyLevel: 'NO_SIDE_EFFECTS',`);
68
+ chunks.push((0, ts_poet_1.code) `idempotencyLevel: 'NO_SIDE_EFFECTS',`);
69
69
  }
70
70
  }
71
- chunks.push(ts_poet_1.code `}`);
72
- return ts_poet_1.joinCode(chunks, { on: '\n' });
71
+ chunks.push((0, ts_poet_1.code) `}`);
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 = ts_poet_1.imp('CallOptions@@grpc/grpc-js');
10
- const ChannelCredentials = ts_poet_1.imp('ChannelCredentials@@grpc/grpc-js');
11
- const ChannelOptions = ts_poet_1.imp('ChannelOptions@@grpc/grpc-js');
12
- const Client = ts_poet_1.imp('Client@@grpc/grpc-js');
13
- const ClientDuplexStream = ts_poet_1.imp('ClientDuplexStream@@grpc/grpc-js');
14
- const ClientReadableStream = ts_poet_1.imp('ClientReadableStream@@grpc/grpc-js');
15
- const ClientUnaryCall = ts_poet_1.imp('ClientUnaryCall@@grpc/grpc-js');
16
- const ClientWritableStream = ts_poet_1.imp('ClientWritableStream@@grpc/grpc-js');
17
- const handleBidiStreamingCall = ts_poet_1.imp('handleBidiStreamingCall@@grpc/grpc-js');
18
- const handleClientStreamingCall = ts_poet_1.imp('handleClientStreamingCall@@grpc/grpc-js');
19
- const handleServerStreamingCall = ts_poet_1.imp('handleServerStreamingCall@@grpc/grpc-js');
20
- const handleUnaryCall = ts_poet_1.imp('handleUnaryCall@@grpc/grpc-js');
21
- const UntypedServiceImplementation = ts_poet_1.imp('UntypedServiceImplementation@@grpc/grpc-js');
22
- const makeGenericClientConstructor = ts_poet_1.imp('makeGenericClientConstructor@@grpc/grpc-js');
23
- const Metadata = ts_poet_1.imp('Metadata@@grpc/grpc-js');
24
- const ServiceError = 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,35 +35,35 @@ 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 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) {
42
42
  var _a, _b;
43
43
  const chunks = [];
44
- utils_1.maybeAddComment(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
44
+ (0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
45
45
  // Service definition type
46
- const name = ts_poet_1.def(`${serviceDesc.name}Service`);
47
- chunks.push(ts_poet_1.code `
46
+ const name = (0, ts_poet_1.def)(`${serviceDesc.name}Service`);
47
+ chunks.push((0, ts_poet_1.code) `
48
48
  export type ${name} = typeof ${name};
49
49
  `);
50
50
  // Service definition
51
- chunks.push(ts_poet_1.code `
51
+ chunks.push((0, ts_poet_1.code) `
52
52
  export const ${name} = {
53
53
  `);
54
54
  for (const [index, methodDesc] of serviceDesc.method.entries()) {
55
- utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
56
- const inputType = types_1.messageToTypeName(ctx, methodDesc.inputType);
57
- const outputType = types_1.messageToTypeName(ctx, methodDesc.outputType);
55
+ (0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
56
+ const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
57
+ const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
58
58
  const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
59
- utils_1.maybeAddComment(info, chunks, (_b = methodDesc.options) === null || _b === void 0 ? void 0 : _b.deprecated);
60
- const inputEncoder = encode_1.generateEncoder(ctx, methodDesc.inputType);
61
- const outputEncoder = encode_1.generateEncoder(ctx, methodDesc.outputType);
62
- const inputDecoder = encode_1.generateDecoder(ctx, methodDesc.inputType);
63
- const outputDecoder = encode_1.generateDecoder(ctx, methodDesc.outputType);
64
- chunks.push(ts_poet_1.code `
59
+ (0, utils_1.maybeAddComment)(info, chunks, (_b = methodDesc.options) === null || _b === void 0 ? void 0 : _b.deprecated);
60
+ const inputEncoder = (0, encode_1.generateEncoder)(ctx, methodDesc.inputType);
61
+ const outputEncoder = (0, encode_1.generateEncoder)(ctx, methodDesc.outputType);
62
+ const inputDecoder = (0, encode_1.generateDecoder)(ctx, methodDesc.inputType);
63
+ const outputDecoder = (0, encode_1.generateDecoder)(ctx, methodDesc.outputType);
64
+ chunks.push((0, ts_poet_1.code) `
65
65
  ${methodDesc.formattedName}: {
66
- path: '/${utils_1.maybePrefixPackage(fileDesc, serviceDesc.name)}/${methodDesc.name}',
66
+ path: '/${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}/${methodDesc.name}',
67
67
  requestStream: ${methodDesc.clientStreaming},
68
68
  responseStream: ${methodDesc.serverStreaming},
69
69
  requestSerialize: (value: ${inputType}) =>
@@ -75,19 +75,19 @@ function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
75
75
  },
76
76
  `);
77
77
  }
78
- chunks.push(ts_poet_1.code `} as const;`);
79
- return ts_poet_1.joinCode(chunks, { on: '\n' });
78
+ chunks.push((0, ts_poet_1.code) `} as const;`);
79
+ return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
80
80
  }
81
81
  function generateServerStub(ctx, sourceInfo, serviceDesc) {
82
82
  var _a;
83
83
  const chunks = [];
84
- chunks.push(ts_poet_1.code `export interface ${ts_poet_1.def(`${serviceDesc.name}Server`)} extends ${UntypedServiceImplementation} {`);
84
+ chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(`${serviceDesc.name}Server`)} extends ${UntypedServiceImplementation} {`);
85
85
  for (const [index, methodDesc] of serviceDesc.method.entries()) {
86
- utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
87
- const inputType = types_1.messageToTypeName(ctx, methodDesc.inputType);
88
- const outputType = types_1.messageToTypeName(ctx, methodDesc.outputType);
86
+ (0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
87
+ const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
88
+ const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
89
89
  const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
90
- utils_1.maybeAddComment(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
90
+ (0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
91
91
  const callType = methodDesc.clientStreaming
92
92
  ? methodDesc.serverStreaming
93
93
  ? handleBidiStreamingCall
@@ -95,28 +95,28 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
95
95
  : methodDesc.serverStreaming
96
96
  ? handleServerStreamingCall
97
97
  : handleUnaryCall;
98
- chunks.push(ts_poet_1.code `
98
+ chunks.push((0, ts_poet_1.code) `
99
99
  ${methodDesc.formattedName}: ${callType}<${inputType}, ${outputType}>;
100
100
  `);
101
101
  }
102
- chunks.push(ts_poet_1.code `}`);
103
- return ts_poet_1.joinCode(chunks, { on: '\n' });
102
+ chunks.push((0, ts_poet_1.code) `}`);
103
+ return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
104
104
  }
105
105
  function generateClientStub(ctx, sourceInfo, serviceDesc) {
106
106
  var _a;
107
107
  const chunks = [];
108
- chunks.push(ts_poet_1.code `export interface ${ts_poet_1.def(`${serviceDesc.name}Client`)} extends ${Client} {`);
108
+ chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(`${serviceDesc.name}Client`)} extends ${Client} {`);
109
109
  for (const [index, methodDesc] of serviceDesc.method.entries()) {
110
- utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
111
- const inputType = types_1.messageToTypeName(ctx, methodDesc.inputType);
112
- const outputType = types_1.messageToTypeName(ctx, methodDesc.outputType);
110
+ (0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
111
+ const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
112
+ const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
113
113
  const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
114
- utils_1.maybeAddComment(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
115
- const responseCallback = ts_poet_1.code `(error: ${ServiceError} | null, response: ${outputType}) => void`;
114
+ (0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
115
+ const responseCallback = (0, ts_poet_1.code) `(error: ${ServiceError} | null, response: ${outputType}) => void`;
116
116
  if (methodDesc.clientStreaming) {
117
117
  if (methodDesc.serverStreaming) {
118
118
  // bidi streaming
119
- chunks.push(ts_poet_1.code `
119
+ chunks.push((0, ts_poet_1.code) `
120
120
  ${methodDesc.formattedName}(): ${ClientDuplexStream}<${inputType}, ${outputType}>;
121
121
  ${methodDesc.formattedName}(
122
122
  options: Partial<${CallOptions}>,
@@ -129,7 +129,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
129
129
  }
130
130
  else {
131
131
  // client streaming
132
- chunks.push(ts_poet_1.code `
132
+ chunks.push((0, ts_poet_1.code) `
133
133
  ${methodDesc.formattedName}(
134
134
  callback: ${responseCallback},
135
135
  ): ${ClientWritableStream}<${inputType}>;
@@ -152,7 +152,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
152
152
  else {
153
153
  if (methodDesc.serverStreaming) {
154
154
  // server streaming
155
- chunks.push(ts_poet_1.code `
155
+ chunks.push((0, ts_poet_1.code) `
156
156
  ${methodDesc.formattedName}(
157
157
  request: ${inputType},
158
158
  options?: Partial<${CallOptions}>,
@@ -166,7 +166,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
166
166
  }
167
167
  else {
168
168
  // unary
169
- chunks.push(ts_poet_1.code `
169
+ chunks.push((0, ts_poet_1.code) `
170
170
  ${methodDesc.formattedName}(
171
171
  request: ${inputType},
172
172
  callback: ${responseCallback},
@@ -186,14 +186,14 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
186
186
  }
187
187
  }
188
188
  }
189
- chunks.push(ts_poet_1.code `}`);
190
- return ts_poet_1.joinCode(chunks, { on: '\n' });
189
+ chunks.push((0, ts_poet_1.code) `}`);
190
+ return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
191
191
  }
192
192
  function generateClientConstructor(fileDesc, serviceDesc) {
193
- return ts_poet_1.code `
194
- export const ${ts_poet_1.def(`${serviceDesc.name}Client`)} = ${makeGenericClientConstructor}(
193
+ return (0, ts_poet_1.code) `
194
+ export const ${(0, ts_poet_1.def)(`${serviceDesc.name}Client`)} = ${makeGenericClientConstructor}(
195
195
  ${serviceDesc.name}Service,
196
- '${utils_1.maybePrefixPackage(fileDesc, serviceDesc.name)}'
196
+ '${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}'
197
197
  ) as unknown as {
198
198
  new (
199
199
  address: string,