ts-proto 1.91.0 → 1.93.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 +28 -0
- package/README.markdown +23 -8
- package/build/encode.js +9 -7
- package/build/generate-type-registry.js +1 -1
- package/build/main.js +34 -22
- package/build/options.js +1 -0
- package/build/types.js +4 -4
- package/build/utils.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.93.0](https://github.com/stephenh/ts-proto/compare/v1.92.2...v1.93.0) (2021-12-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Allow optional suffix for generated files ([#431](https://github.com/stephenh/ts-proto/issues/431)) ([d826966](https://github.com/stephenh/ts-proto/commit/d826966f22830920444963b3894ffc0be9b7c319))
|
|
7
|
+
|
|
8
|
+
## [1.92.2](https://github.com/stephenh/ts-proto/compare/v1.92.1...v1.92.2) (2021-12-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* noImplicitReturns error in Value.unwrap ([#436](https://github.com/stephenh/ts-proto/issues/436)) ([2d7a5d0](https://github.com/stephenh/ts-proto/commit/2d7a5d04c72ace58fa3a6745c3857f6cc0468543)), closes [#432](https://github.com/stephenh/ts-proto/issues/432)
|
|
14
|
+
|
|
15
|
+
## [1.92.1](https://github.com/stephenh/ts-proto/compare/v1.92.0...v1.92.1) (2021-12-02)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Respect stringEnums option in wrap function ([#420](https://github.com/stephenh/ts-proto/issues/420)) ([7adf90c](https://github.com/stephenh/ts-proto/commit/7adf90c23c46950bcf457b317764393ff4af2bf2))
|
|
21
|
+
|
|
22
|
+
# [1.92.0](https://github.com/stephenh/ts-proto/compare/v1.91.0...v1.92.0) (2021-11-28)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* Use exact types for fromPartial ([#412](https://github.com/stephenh/ts-proto/issues/412)) ([808f8a7](https://github.com/stephenh/ts-proto/commit/808f8a7a77d56f65dd4a4643dd66158f106ab755)), closes [#156](https://github.com/stephenh/ts-proto/issues/156)
|
|
28
|
+
|
|
1
29
|
# [1.91.0](https://github.com/stephenh/ts-proto/compare/v1.90.1...v1.91.0) (2021-11-27)
|
|
2
30
|
|
|
3
31
|
|
package/README.markdown
CHANGED
|
@@ -9,25 +9,29 @@
|
|
|
9
9
|
|
|
10
10
|
## Table of contents
|
|
11
11
|
|
|
12
|
+
- [ts-proto](#ts-proto)
|
|
13
|
+
- [Table of contents](#table-of-contents)
|
|
14
|
+
- [Overview](#overview)
|
|
12
15
|
- [QuickStart](#quickstart)
|
|
13
16
|
- [Goals](#goals)
|
|
14
17
|
- [Example Types](#example-types)
|
|
15
18
|
- [Highlights](#highlights)
|
|
16
19
|
- [Auto-Batching / N+1 Prevention](#auto-batching--n1-prevention)
|
|
17
20
|
- [Usage](#usage)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
- [Supported options](#supported-options)
|
|
22
|
+
- [Only Types](#only-types)
|
|
23
|
+
- [NestJS Support](#nestjs-support)
|
|
24
|
+
- [Watch Mode](#watch-mode)
|
|
25
|
+
- [Sponsors](#sponsors)
|
|
21
26
|
- [Development](#development)
|
|
22
27
|
- [Assumptions](#assumptions)
|
|
23
28
|
- [Todo](#todo)
|
|
24
29
|
- [OneOf Handling](#oneof-handling)
|
|
25
|
-
- [Default
|
|
30
|
+
- [Default values and unset fields](#default-values-and-unset-fields)
|
|
26
31
|
- [Well-Known Types](#well-known-types)
|
|
27
32
|
- [Wrapper Types](#wrapper-types)
|
|
28
33
|
- [JSON Types (Struct Types)](#json-types-struct-types)
|
|
29
|
-
- [
|
|
30
|
-
- [Wrapper Types](#wrapper-types)
|
|
34
|
+
- [Timestamp](#timestamp)
|
|
31
35
|
- [Number Types](#number-types)
|
|
32
36
|
- [Current Status of Optional Values](#current-status-of-optional-values)
|
|
33
37
|
|
|
@@ -329,7 +333,7 @@ Generated code will be placed in the Gradle build directory.
|
|
|
329
333
|
|
|
330
334
|
Note that `addGrpcMetadata`, `addNestjsRestParameter` and `returnObservable` will still be false.
|
|
331
335
|
|
|
332
|
-
- With `--ts_proto_opt=useDate=false`, fields of type `google.protobuf.Timestamp` will not be mapped to type `Date` in the generated types. See [
|
|
336
|
+
- With `--ts_proto_opt=useDate=false`, fields of type `google.protobuf.Timestamp` will not be mapped to type `Date` in the generated types. See [Timestamp](#timestamp) for more details.
|
|
333
337
|
|
|
334
338
|
- With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.
|
|
335
339
|
|
|
@@ -337,13 +341,15 @@ Generated code will be placed in the Gradle build directory.
|
|
|
337
341
|
|
|
338
342
|
- With `--ts_proto_opt=outputServices=grpc-js`, ts-proto will output service definitions and server / client stubs in [grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) format.
|
|
339
343
|
|
|
340
|
-
- With `--ts_proto_opt=outputServices=generic-definitions`, ts-proto will output generic (framework-agnostic) service definitions.
|
|
344
|
+
- With `--ts_proto_opt=outputServices=generic-definitions`, ts-proto will output generic (framework-agnostic) service definitions. These definitions contain descriptors for each method with links to request and response types, which allows to generate server and client stubs at runtime, and also generate strong types for them at compile time. An example of a library that uses this approach is [nice-grpc](https://github.com/deeplay-io/nice-grpc).
|
|
341
345
|
|
|
342
346
|
- With `--ts_proto_opt=outputServices=false`, or `=none`, ts-proto will output NO service definitions.
|
|
343
347
|
|
|
344
348
|
- With `--ts_proto_opt=emitImportedFiles=false`, ts-proto will not emit `google/protobuf/*` files unless you explicit add files to `protoc` like this
|
|
345
349
|
`protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto my_message.proto google/protobuf/duration.proto`
|
|
346
350
|
|
|
351
|
+
- With `--ts_proto_opt=fileSuffix=<SUFFIX>`, ts-proto will emit generated files using the specified suffix. A `helloworld.proto` file with `fileSuffix=.pb` would be generated as `helloworld.pb.ts`. This is common behavior in other protoc plugins and provides a way to quickly glob all the generated files.
|
|
352
|
+
|
|
347
353
|
### Only Types
|
|
348
354
|
|
|
349
355
|
If you're looking for `ts-proto` to generate only types for your Protobuf types then passing all three of `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` as `false` is probably what you want, i.e.:
|
|
@@ -354,6 +360,15 @@ If you're looking for `ts-proto` to generate only types for your Protobuf types
|
|
|
354
360
|
|
|
355
361
|
We have a great way of working together with [nestjs](https://docs.nestjs.com/microservices/grpc). `ts-proto` generates `interfaces` and `decorators` for you controller, client. For more information see the [nestjs readme](NESTJS.markdown).
|
|
356
362
|
|
|
363
|
+
### Watch Mode
|
|
364
|
+
|
|
365
|
+
If you want to run `ts-proto` on every change of a proto file, you'll need to use a tool like [chokidar-cli](https://www.npmjs.com/package/chokidar-cli) and use it as a script in `package.json`:
|
|
366
|
+
|
|
367
|
+
```json
|
|
368
|
+
"proto:generate": "protoc --ts_proto_out=. ./<proto_path>/<proto_name>.proto --ts_proto_opt=esModuleInterop=true",
|
|
369
|
+
"proto:watch": "chokidar \"**/*.proto\" -c \"npm run proto:generate\""
|
|
370
|
+
```
|
|
371
|
+
|
|
357
372
|
# Sponsors
|
|
358
373
|
|
|
359
374
|
Kudos to our sponsors:
|
package/build/encode.js
CHANGED
|
@@ -4,24 +4,25 @@ exports.generateDecoder = exports.generateEncoder = void 0;
|
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
const options_1 = require("./options");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
7
8
|
function generateEncoder(ctx, typeName) {
|
|
8
9
|
const name = types_1.wrapperTypeName(typeName);
|
|
9
10
|
if (!name) {
|
|
10
11
|
return ts_poet_1.code `${types_1.messageToTypeName(ctx, typeName, { keepValueType: true })}.encode(value).finish()`;
|
|
11
12
|
}
|
|
12
13
|
if (name == 'Timestamp') {
|
|
13
|
-
const TimestampValue =
|
|
14
|
+
const TimestampValue = utils_1.impProto(ctx.options, 'google/protobuf/timestamp', name);
|
|
14
15
|
return ts_poet_1.code `${TimestampValue}.encode(${ctx.utils.toTimestamp}(value)).finish()`;
|
|
15
16
|
}
|
|
16
17
|
if (name == 'Struct') {
|
|
17
|
-
const StructType =
|
|
18
|
+
const StructType = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
|
|
18
19
|
return ts_poet_1.code `${StructType}.encode(${StructType}.wrap(value)).finish()`;
|
|
19
20
|
}
|
|
20
21
|
if (name == 'ListValue') {
|
|
21
|
-
const ListValueType =
|
|
22
|
+
const ListValueType = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
|
|
22
23
|
return ts_poet_1.code `${ListValueType}.encode({values: value ?? []}).finish()`;
|
|
23
24
|
}
|
|
24
|
-
const TypeValue =
|
|
25
|
+
const TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/wrappers', name);
|
|
25
26
|
switch (name) {
|
|
26
27
|
case 'StringValue':
|
|
27
28
|
return ts_poet_1.code `${TypeValue}.encode({value: value ?? ""}).finish()`;
|
|
@@ -45,20 +46,21 @@ function generateEncoder(ctx, typeName) {
|
|
|
45
46
|
}
|
|
46
47
|
exports.generateEncoder = generateEncoder;
|
|
47
48
|
function generateDecoder(ctx, typeName) {
|
|
49
|
+
const { options } = ctx;
|
|
48
50
|
let name = types_1.wrapperTypeName(typeName);
|
|
49
51
|
if (!name) {
|
|
50
52
|
return ts_poet_1.code `${types_1.messageToTypeName(ctx, typeName, { keepValueType: true })}.decode(value)`;
|
|
51
53
|
}
|
|
52
54
|
let TypeValue;
|
|
53
55
|
if (name == 'Timestamp') {
|
|
54
|
-
TypeValue =
|
|
56
|
+
TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/timestamp', name);
|
|
55
57
|
return ts_poet_1.code `${TypeValue}.decode(value)`;
|
|
56
58
|
}
|
|
57
59
|
if (name == 'Struct' || name == 'ListValue') {
|
|
58
|
-
TypeValue =
|
|
60
|
+
TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/struct', name);
|
|
59
61
|
return ts_poet_1.code `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
|
|
60
62
|
}
|
|
61
|
-
TypeValue =
|
|
63
|
+
TypeValue = utils_1.impProto(ctx.options, 'google/protobuf/wrappers', name);
|
|
62
64
|
return ts_poet_1.code `${TypeValue}.decode(value).value`;
|
|
63
65
|
}
|
|
64
66
|
exports.generateDecoder = generateDecoder;
|
|
@@ -13,7 +13,7 @@ function generateTypeRegistry(ctx) {
|
|
|
13
13
|
chunks.push(ts_poet_1.code `
|
|
14
14
|
export const messageTypeRegistry = new Map<string, MessageType>();
|
|
15
15
|
`);
|
|
16
|
-
chunks.push(ts_poet_1.code
|
|
16
|
+
chunks.push(ts_poet_1.code ` ${ctx.utils.Builtin.ifUsed} ${ctx.utils.DeepPartial.ifUsed}`);
|
|
17
17
|
return ts_poet_1.joinCode(chunks, { on: '\n\n' });
|
|
18
18
|
}
|
|
19
19
|
exports.generateTypeRegistry = generateTypeRegistry;
|
package/build/main.js
CHANGED
|
@@ -30,7 +30,8 @@ function generateFile(ctx, fileDesc) {
|
|
|
30
30
|
//
|
|
31
31
|
// We'll also assume that the fileDesc.name is already the `company/foo.proto` path, with
|
|
32
32
|
// the package already implicitly in it, so we won't re-append/strip/etc. it out/back in.
|
|
33
|
-
const
|
|
33
|
+
const suffix = `${options.fileSuffix}.ts`;
|
|
34
|
+
const moduleName = fileDesc.name.replace('.proto', suffix);
|
|
34
35
|
const chunks = [];
|
|
35
36
|
// Indicate this file's source protobuf package for reflective use with google.protobuf.Any
|
|
36
37
|
if (options.exportCommonSymbols) {
|
|
@@ -289,11 +290,20 @@ function makeDeepPartial(options, longs) {
|
|
|
289
290
|
const maybeExport = options.exportCommonSymbols ? 'export' : '';
|
|
290
291
|
// Allow passing longs as numbers or strings, nad we'll convert them
|
|
291
292
|
const maybeLong = options.forceLong === options_1.LongOption.LONG ? ts_poet_1.code ` : T extends ${longs.Long} ? string | number | Long ` : '';
|
|
292
|
-
const
|
|
293
|
+
const Builtin = ts_poet_1.conditionalOutput('Builtin', ts_poet_1.code `type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;`);
|
|
294
|
+
// Based on https://github.com/sindresorhus/type-fest/pull/259
|
|
295
|
+
const maybeExcludeType = options.outputTypeRegistry ? `| '$type'` : '';
|
|
296
|
+
const Exact = ts_poet_1.conditionalOutput('Exact', ts_poet_1.code `
|
|
297
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
298
|
+
${maybeExport} type Exact<P, I extends P> = P extends ${Builtin}
|
|
299
|
+
? P
|
|
300
|
+
: P &
|
|
301
|
+
{ [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>, never>;
|
|
302
|
+
`);
|
|
293
303
|
// Based on the type from ts-essentials
|
|
304
|
+
const keys = options.outputTypeRegistry ? ts_poet_1.code `Exclude<keyof T, '$type'>` : ts_poet_1.code `keyof T`;
|
|
294
305
|
const DeepPartial = ts_poet_1.conditionalOutput('DeepPartial', ts_poet_1.code `
|
|
295
|
-
type
|
|
296
|
-
${maybeExport} type DeepPartial<T> = T extends Builtin
|
|
306
|
+
${maybeExport} type DeepPartial<T> = T extends ${Builtin}
|
|
297
307
|
? T
|
|
298
308
|
${maybeLong}
|
|
299
309
|
: T extends Array<infer U>
|
|
@@ -304,10 +314,10 @@ function makeDeepPartial(options, longs) {
|
|
|
304
314
|
? { [K in ${keys}]?: DeepPartial<T[K]> }
|
|
305
315
|
: Partial<T>;
|
|
306
316
|
`);
|
|
307
|
-
return { DeepPartial };
|
|
317
|
+
return { Builtin, DeepPartial, Exact };
|
|
308
318
|
}
|
|
309
319
|
function makeTimestampMethods(options, longs) {
|
|
310
|
-
const Timestamp =
|
|
320
|
+
const Timestamp = utils_1.impProto(options, 'google/protobuf/timestamp', 'Timestamp');
|
|
311
321
|
let seconds = 'date.getTime() / 1_000';
|
|
312
322
|
let toNumberCode = 't.seconds';
|
|
313
323
|
if (options.forceLong === options_1.LongOption.LONG) {
|
|
@@ -521,7 +531,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
521
531
|
}
|
|
522
532
|
else if (types_1.isEnum(field)) {
|
|
523
533
|
if (options.stringEnums) {
|
|
524
|
-
const fromJson = types_1.getEnumMethod(
|
|
534
|
+
const fromJson = types_1.getEnumMethod(ctx, field.typeName, 'FromJSON');
|
|
525
535
|
readSnippet = ts_poet_1.code `${fromJson}(${readSnippet})`;
|
|
526
536
|
}
|
|
527
537
|
else {
|
|
@@ -620,7 +630,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
620
630
|
let writeSnippet;
|
|
621
631
|
if (types_1.isEnum(field) && options.stringEnums) {
|
|
622
632
|
const tag = ((field.number << 3) | types_1.basicWireType(field.type)) >>> 0;
|
|
623
|
-
const toNumber = types_1.getEnumMethod(
|
|
633
|
+
const toNumber = types_1.getEnumMethod(ctx, field.typeName, 'ToNumber');
|
|
624
634
|
writeSnippet = (place) => ts_poet_1.code `writer.uint32(${tag}).${types_1.toReaderCall(field)}(${toNumber}(${place}))`;
|
|
625
635
|
}
|
|
626
636
|
else if (types_1.isScalar(field) || types_1.isEnum(field)) {
|
|
@@ -682,7 +692,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
682
692
|
// embedded inside of it, and we want to drop that so that we can encode it packed
|
|
683
693
|
// (i.e. just one tag and multiple values).
|
|
684
694
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
685
|
-
const toNumber = types_1.getEnumMethod(
|
|
695
|
+
const toNumber = types_1.getEnumMethod(ctx, field.typeName, 'ToNumber');
|
|
686
696
|
chunks.push(ts_poet_1.code `
|
|
687
697
|
writer.uint32(${tag}).fork();
|
|
688
698
|
for (const v of message.${fieldName}) {
|
|
@@ -762,7 +772,7 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
762
772
|
// get a generic 'reader.doSomething' bit that is specific to the basic type
|
|
763
773
|
const readSnippet = (from) => {
|
|
764
774
|
if (types_1.isEnum(field)) {
|
|
765
|
-
const fromJson = types_1.getEnumMethod(
|
|
775
|
+
const fromJson = types_1.getEnumMethod(ctx, field.typeName, 'FromJSON');
|
|
766
776
|
return ts_poet_1.code `${fromJson}(${from})`;
|
|
767
777
|
}
|
|
768
778
|
else if (types_1.isPrimitive(field)) {
|
|
@@ -934,7 +944,7 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
934
944
|
const jsonName = utils_1.determineFieldJsonName(field, options);
|
|
935
945
|
const readSnippet = (from) => {
|
|
936
946
|
if (types_1.isEnum(field)) {
|
|
937
|
-
const toJson = types_1.getEnumMethod(
|
|
947
|
+
const toJson = types_1.getEnumMethod(ctx, field.typeName, 'ToJSON');
|
|
938
948
|
return types_1.isWithinOneOf(field)
|
|
939
949
|
? ts_poet_1.code `${from} !== undefined ? ${toJson}(${from}) : undefined`
|
|
940
950
|
: ts_poet_1.code `${toJson}(${from})`;
|
|
@@ -952,7 +962,7 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
952
962
|
// For map types, drill-in and then admittedly re-hard-code our per-value-type logic
|
|
953
963
|
const valueType = typeMap.get(field.typeName)[2].field[1];
|
|
954
964
|
if (types_1.isEnum(valueType)) {
|
|
955
|
-
const toJson = types_1.getEnumMethod(
|
|
965
|
+
const toJson = types_1.getEnumMethod(ctx, valueType.typeName, 'ToJSON');
|
|
956
966
|
return ts_poet_1.code `${toJson}(${from})`;
|
|
957
967
|
}
|
|
958
968
|
else if (types_1.isBytes(valueType)) {
|
|
@@ -1043,10 +1053,11 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1043
1053
|
function generateFromPartial(ctx, fullName, messageDesc) {
|
|
1044
1054
|
const { options, utils, typeMap } = ctx;
|
|
1045
1055
|
const chunks = [];
|
|
1046
|
-
const Timestamp =
|
|
1056
|
+
const Timestamp = utils_1.impProto(options, 'google/protobuf/timestamp', 'Timestamp');
|
|
1047
1057
|
// create the basic function declaration
|
|
1058
|
+
const paramName = messageDesc.field.length > 0 ? 'object' : '_';
|
|
1048
1059
|
chunks.push(ts_poet_1.code `
|
|
1049
|
-
fromPartial
|
|
1060
|
+
fromPartial<I extends ${utils.Exact}<${utils.DeepPartial}<${fullName}>, I>>(${paramName}: I): ${fullName} {
|
|
1050
1061
|
const message = { ...base${fullName} } as ${fullName};
|
|
1051
1062
|
`);
|
|
1052
1063
|
// add a check for each incoming field
|
|
@@ -1122,7 +1133,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1122
1133
|
}
|
|
1123
1134
|
else {
|
|
1124
1135
|
chunks.push(ts_poet_1.code `
|
|
1125
|
-
message.${fieldName} =
|
|
1136
|
+
message.${fieldName} = object.${fieldName}?.map((e) => ${readSnippet('e')}) || [];
|
|
1126
1137
|
`);
|
|
1127
1138
|
}
|
|
1128
1139
|
}
|
|
@@ -1174,7 +1185,7 @@ function generateWrap(fullProtoTypeName) {
|
|
|
1174
1185
|
if (types_1.isAnyValueTypeName(fullProtoTypeName)) {
|
|
1175
1186
|
chunks.push(ts_poet_1.code `wrap(value: any): Value {
|
|
1176
1187
|
if (value === null) {
|
|
1177
|
-
return {nullValue:
|
|
1188
|
+
return {nullValue: NullValue.NULL_VALUE} as Value;
|
|
1178
1189
|
} else if (typeof value === 'boolean') {
|
|
1179
1190
|
return {boolValue: value} as Value;
|
|
1180
1191
|
} else if (typeof value === 'number') {
|
|
@@ -1212,19 +1223,20 @@ function generateUnwrap(fullProtoTypeName) {
|
|
|
1212
1223
|
}
|
|
1213
1224
|
if (types_1.isAnyValueTypeName(fullProtoTypeName)) {
|
|
1214
1225
|
chunks.push(ts_poet_1.code `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
|
|
1215
|
-
if (message
|
|
1226
|
+
if (message?.stringValue !== undefined) {
|
|
1216
1227
|
return message.stringValue;
|
|
1217
|
-
} else if (message
|
|
1228
|
+
} else if (message?.numberValue !== undefined) {
|
|
1218
1229
|
return message.numberValue;
|
|
1219
|
-
} else if (message
|
|
1230
|
+
} else if (message?.boolValue !== undefined) {
|
|
1220
1231
|
return message.boolValue;
|
|
1221
|
-
} else if (message
|
|
1232
|
+
} else if (message?.structValue !== undefined) {
|
|
1222
1233
|
return message.structValue;
|
|
1223
|
-
} else if (message
|
|
1234
|
+
} else if (message?.listValue !== undefined) {
|
|
1224
1235
|
return message.listValue;
|
|
1225
|
-
} else if (message
|
|
1236
|
+
} else if (message?.nullValue !== undefined) {
|
|
1226
1237
|
return null;
|
|
1227
1238
|
}
|
|
1239
|
+
return undefined;
|
|
1228
1240
|
}`);
|
|
1229
1241
|
}
|
|
1230
1242
|
if (types_1.isListValueTypeName(fullProtoTypeName)) {
|
package/build/options.js
CHANGED
package/build/types.js
CHANGED
|
@@ -481,16 +481,16 @@ function messageToTypeName(ctx, protoType, typeOptions = {}) {
|
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
483
|
const [module, type] = toModuleAndType(typeMap, protoType);
|
|
484
|
-
return ts_poet_1.code `${
|
|
484
|
+
return ts_poet_1.code `${utils_1.impProto(options, module, type)}`;
|
|
485
485
|
}
|
|
486
486
|
exports.messageToTypeName = messageToTypeName;
|
|
487
487
|
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message', Descriptor]. */
|
|
488
488
|
function toModuleAndType(typeMap, protoType) {
|
|
489
489
|
return typeMap.get(protoType) || utils_1.fail(`No type found for ${protoType}`);
|
|
490
490
|
}
|
|
491
|
-
function getEnumMethod(
|
|
492
|
-
const [module, type] = toModuleAndType(typeMap, enumProtoType);
|
|
493
|
-
return
|
|
491
|
+
function getEnumMethod(ctx, enumProtoType, methodSuffix) {
|
|
492
|
+
const [module, type] = toModuleAndType(ctx.typeMap, enumProtoType);
|
|
493
|
+
return utils_1.impProto(ctx.options, module, `${case_1.camelCase(type)}${methodSuffix}`);
|
|
494
494
|
}
|
|
495
495
|
exports.getEnumMethod = getEnumMethod;
|
|
496
496
|
/** Return the TypeName for any field (primitive/message/etc.) as exposed in the interface. */
|
package/build/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determineFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
|
|
3
|
+
exports.impProto = exports.determineFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
5
|
const options_1 = require("./options");
|
|
6
6
|
const case_1 = require("./case");
|
|
@@ -153,3 +153,7 @@ function determineFieldJsonName(field, options) {
|
|
|
153
153
|
return case_1.maybeSnakeToCamel(field.name, options);
|
|
154
154
|
}
|
|
155
155
|
exports.determineFieldJsonName = determineFieldJsonName;
|
|
156
|
+
function impProto(options, module, type) {
|
|
157
|
+
return ts_poet_1.imp(`${type}@./${module}${options.fileSuffix}`);
|
|
158
|
+
}
|
|
159
|
+
exports.impProto = impProto;
|