ts-proto 2.18.4 → 2.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.markdown
CHANGED
|
@@ -493,7 +493,7 @@ With `--ts_proto_opt=protoJsonFormat=false`, strict proto3 compliance is disable
|
|
|
493
493
|
|
|
494
494
|
- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration, or `--ts_proto_opt=outputTypeAnnotations=optional` to make it an optional property on the `interface` definition. The latter option may be useful if you want to use the `$type` field for runtime type checking on responses from a server.
|
|
495
495
|
|
|
496
|
-
- With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will be given a `$type` field containing its fully-qualified name.
|
|
496
|
+
- With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will be given a `$type` field containing its fully-qualified name. The registry's `MessageType` only declares the methods that are generated, so it also works with options like `outputEncodeMethods=encode-only` or `outputJsonMethods=to-only`.
|
|
497
497
|
|
|
498
498
|
- 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.
|
|
499
499
|
|
|
@@ -91,7 +91,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
|
|
|
91
91
|
const chunks = [];
|
|
92
92
|
if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
|
|
93
93
|
if (ctx.options.useMapType) {
|
|
94
|
-
chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}: {[key: string]: any} {
|
|
94
|
+
chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
|
|
95
95
|
const object: { [key: string]: any } = {};
|
|
96
96
|
if (message.fields) {
|
|
97
97
|
for (const key of message.fields.keys()) {
|
|
@@ -33,14 +33,25 @@ function generateMessageType(ctx) {
|
|
|
33
33
|
else {
|
|
34
34
|
chunks.push((0, ts_poet_1.code) `$type: string;`);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// Only declare the methods that are actually generated on each message, e.g. with
|
|
37
|
+
// `outputJsonMethods=to-only` the messages have no `fromJSON` to register.
|
|
38
|
+
const { outputEncodeMethods, outputJsonMethods } = ctx.options;
|
|
39
|
+
const hasEncode = outputEncodeMethods === true ||
|
|
40
|
+
outputEncodeMethods === "encode-only" ||
|
|
41
|
+
outputEncodeMethods === "encode-no-creation";
|
|
42
|
+
const hasDecode = outputEncodeMethods === true || outputEncodeMethods === "decode-only";
|
|
43
|
+
const BinaryReader = (0, ts_poet_1.imp)("t:BinaryReader@@bufbuild/protobuf/wire");
|
|
44
|
+
const BinaryWriter = (0, ts_poet_1.imp)("t:BinaryWriter@@bufbuild/protobuf/wire");
|
|
45
|
+
if (hasEncode) {
|
|
39
46
|
chunks.push((0, ts_poet_1.code) `encode(message: Message, writer?: ${BinaryWriter}): ${BinaryWriter};`);
|
|
47
|
+
}
|
|
48
|
+
if (hasDecode) {
|
|
40
49
|
chunks.push((0, ts_poet_1.code) `decode(input: ${BinaryReader} | Uint8Array, length?: number): Message;`);
|
|
41
50
|
}
|
|
42
|
-
if (
|
|
51
|
+
if (outputJsonMethods === true || outputJsonMethods === "from-only") {
|
|
43
52
|
chunks.push((0, ts_poet_1.code) `fromJSON(object: any): Message;`);
|
|
53
|
+
}
|
|
54
|
+
if (outputJsonMethods === true || outputJsonMethods === "to-only") {
|
|
44
55
|
chunks.push((0, ts_poet_1.code) `toJSON(message: Message): unknown;`);
|
|
45
56
|
}
|
|
46
57
|
if (ctx.options.outputPartialMethods) {
|