diff --git a/README.md b/README.md index 55643a32..7ae61bb8 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,36 @@ protoc \ ## OpenAPI +Learn more about the RESTful API service for Wechaty from [Wechaty OpenAPI](https://github.com/wechaty/openapi). + +## gRPC Web + +- [gRPC-Web ReactJS client, Golang Server](https://github.com/longfellowone/grpcwebtest) + +## RESOURCES + +### Documentation + +- [Protocol Buffers Language Guide (proto3)](https://developers.google.com/protocol-buffers/docs/proto3) +- [Google Protocol Buffers Style Guide](https://developers.google.com/protocol-buffers/docs/style) +- [Protocol Buffers for TypeScript with Decorators](https://github.com/protobufjs/protobuf.js#using-decorators) +- [Troubleshooting gRPC](https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md) +- [gRPC environment variables](https://github.com/grpc/grpc/blob/master/doc/environment_variables.md) +- [How to Interact With and Debug a gRPC Server](https://medium.com/@EdgePress/how-to-interact-with-and-debug-a-grpc-server-c4bc30ddeb0b) + +### Links + +- [探讨gRPC的Node技术生态及实现工具](https://xenojoshua.com/2018/02/grpc-node-ecosystem/) +- [gRPC Basics - Node.js](https://grpc.io/docs/tutorials/basic/node.html) +- [Building a gRPC service with Node.js](https://codelabs.developers.google.com/codelabs/cloud-grpc/) +- [gRPC in 3 minutes (Node.js)](https://github.com/grpc/grpc/tree/master/examples/node) +- [Listen gRPC and HTTP requests on the same port](https://medium.com/@drgarcia1986/listen-grpc-and-http-requests-on-the-same-port-263c40cb45ff) +- [gRPC to JSON proxy generator following the gRPC HTTP spec](https://github.com/grpc-ecosystem/grpc-gateway) +- [如何在 Node.js 中更优雅地使用 gRPC:grpc-helper](https://github.com/xizhibei/blog/issues/86) +- [Comparing OpenAPI With gRPC](https://dzone.com/articles/comparing-openapi-with-grpc) + +#### Protocol Buffer + Thanks to the ecosystem of gRPC, we can generate OpenAPI Specification from our gRPC proto definitions automatically. We are using [gRPC to JSON proxy generator following the gRPC HTTP spec](https://github.com/grpc-ecosystem/grpc-gateway) as the OpenAPI Specification generator ([protoc-gen-openapiv2](https://github.com/grpc-ecosystem/grpc-gateway/tree/master/protoc-gen-openapiv2)), and using [Like grpc-gateway, but written in node and dynamic](https://github.com/konsumer/grpc-dynamic-gateway) project to serve an HTTP RESTful API to gRPC proxy. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..9f383b4a --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,11 @@ +.PHONY: all +all : docs + +.PHONY: docs +docs: + protoc \ + -I ../third-party/ \ + -I ../proto/ \ + --doc_out=./ \ + --doc_opt=markdown,README.md \ + ../proto/wechaty/puppet.proto diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..58e34add --- /dev/null +++ b/docs/README.md @@ -0,0 +1,120 @@ +# Protocol Documentation + + +## Table of Contents + +- [wechaty/puppet.proto](#wechaty/puppet.proto) + - [Puppet](#wechaty.Puppet) + +- [Scalar Value Types](#scalar-value-types) + + + + +
+ +## wechaty/puppet.proto +Wechaty Puppet gRPC Protocol Buffers + https://github.com/wechaty/grpc/ + Huan LI <zixia@zixia.net> + Apr 2018 + License: Apache-2.0 + +Google Protocol Buffers + Style Guide - https://developers.google.com/protocol-buffers/docs/style + + + + + + + + + + +### Puppet + + +| Method Name | Request Type | Response Type | Description | +| ----------- | ------------ | ------------- | ------------| +| Start | [puppet.StartRequest](#wechaty.puppet.StartRequest) | [puppet.StartResponse](#wechaty.puppet.StartResponse) | Base | +| Stop | [puppet.StopRequest](#wechaty.puppet.StopRequest) | [puppet.StopResponse](#wechaty.puppet.StopResponse) | | +| Logout | [puppet.LogoutRequest](#wechaty.puppet.LogoutRequest) | [puppet.LogoutResponse](#wechaty.puppet.LogoutResponse) | | +| Ding | [puppet.DingRequest](#wechaty.puppet.DingRequest) | [puppet.DingResponse](#wechaty.puppet.DingResponse) | | +| Version | [puppet.VersionRequest](#wechaty.puppet.VersionRequest) | [puppet.VersionResponse](#wechaty.puppet.VersionResponse) | | +| Event | [puppet.EventRequest](#wechaty.puppet.EventRequest) | [puppet.EventResponse](#wechaty.puppet.EventResponse) stream | Event - Server Stream | +| DirtyPayload | [puppet.DirtyPayloadRequest](#wechaty.puppet.DirtyPayloadRequest) | [puppet.DirtyPayloadResponse](#wechaty.puppet.DirtyPayloadResponse) | | +| ContactSelfQRCode | [puppet.ContactSelfQRCodeRequest](#wechaty.puppet.ContactSelfQRCodeRequest) | [puppet.ContactSelfQRCodeResponse](#wechaty.puppet.ContactSelfQRCodeResponse) | Contact Self | +| ContactSelfName | [puppet.ContactSelfNameRequest](#wechaty.puppet.ContactSelfNameRequest) | [puppet.ContactSelfNameResponse](#wechaty.puppet.ContactSelfNameResponse) | | +| ContactSelfSignature | [puppet.ContactSelfSignatureRequest](#wechaty.puppet.ContactSelfSignatureRequest) | [puppet.ContactSelfSignatureResponse](#wechaty.puppet.ContactSelfSignatureResponse) | | +| ContactPayload | [puppet.ContactPayloadRequest](#wechaty.puppet.ContactPayloadRequest) | [puppet.ContactPayloadResponse](#wechaty.puppet.ContactPayloadResponse) | Contact | +| ContactAlias | [puppet.ContactAliasRequest](#wechaty.puppet.ContactAliasRequest) | [puppet.ContactAliasResponse](#wechaty.puppet.ContactAliasResponse) | | +| ContactAvatar | [puppet.ContactAvatarRequest](#wechaty.puppet.ContactAvatarRequest) | [puppet.ContactAvatarResponse](#wechaty.puppet.ContactAvatarResponse) | | +| ContactPhone | [puppet.ContactPhoneRequest](#wechaty.puppet.ContactPhoneRequest) | [puppet.ContactPhoneResponse](#wechaty.puppet.ContactPhoneResponse) | | +| ContactCorporationRemark | [puppet.ContactCorporationRemarkRequest](#wechaty.puppet.ContactCorporationRemarkRequest) | [puppet.ContactCorporationRemarkResponse](#wechaty.puppet.ContactCorporationRemarkResponse) | | +| ContactDescription | [puppet.ContactDescriptionRequest](#wechaty.puppet.ContactDescriptionRequest) | [puppet.ContactDescriptionResponse](#wechaty.puppet.ContactDescriptionResponse) | | +| ContactList | [puppet.ContactListRequest](#wechaty.puppet.ContactListRequest) | [puppet.ContactListResponse](#wechaty.puppet.ContactListResponse) | Huan(202002): consider changing response to a stream in the future for better performance | +| FriendshipPayload | [puppet.FriendshipPayloadRequest](#wechaty.puppet.FriendshipPayloadRequest) | [puppet.FriendshipPayloadResponse](#wechaty.puppet.FriendshipPayloadResponse) | Friendship | +| FriendshipSearchPhone | [puppet.FriendshipSearchPhoneRequest](#wechaty.puppet.FriendshipSearchPhoneRequest) | [puppet.FriendshipSearchPhoneResponse](#wechaty.puppet.FriendshipSearchPhoneResponse) | | +| FriendshipSearchWeixin | [puppet.FriendshipSearchWeixinRequest](#wechaty.puppet.FriendshipSearchWeixinRequest) | [puppet.FriendshipSearchWeixinResponse](#wechaty.puppet.FriendshipSearchWeixinResponse) | | +| FriendshipAdd | [puppet.FriendshipAddRequest](#wechaty.puppet.FriendshipAddRequest) | [puppet.FriendshipAddResponse](#wechaty.puppet.FriendshipAddResponse) | | +| FriendshipAccept | [puppet.FriendshipAcceptRequest](#wechaty.puppet.FriendshipAcceptRequest) | [puppet.FriendshipAcceptResponse](#wechaty.puppet.FriendshipAcceptResponse) | | +| MessageFile | [puppet.MessageFileRequest](#wechaty.puppet.MessageFileRequest) | [puppet.MessageFileResponse](#wechaty.puppet.MessageFileResponse) | @deprecated: using MessageFileStream to transfer files Huan(202010): will be removed (replaced by MessageFileStream) after Dec 31, 2021 | +| MessageImage | [puppet.MessageImageRequest](#wechaty.puppet.MessageImageRequest) | [puppet.MessageImageResponse](#wechaty.puppet.MessageImageResponse) | @deprecated: using MessageImageStream to transfer images Huan(202010): will be removed (replaced by MessageImageStream) after Dec 31, 2021 | +| MessageSendFile | [puppet.MessageSendFileRequest](#wechaty.puppet.MessageSendFileRequest) | [puppet.MessageSendFileResponse](#wechaty.puppet.MessageSendFileResponse) | @deprecated: using MesageSendFileStream to transfer file message to server Huan(202010): will be removed (replaced by MessageSendFileStream) after Dec 31, 2021 | +| MessagePayload | [puppet.MessagePayloadRequest](#wechaty.puppet.MessagePayloadRequest) | [puppet.MessagePayloadResponse](#wechaty.puppet.MessagePayloadResponse) | | +| MessageContact | [puppet.MessageContactRequest](#wechaty.puppet.MessageContactRequest) | [puppet.MessageContactResponse](#wechaty.puppet.MessageContactResponse) | | +| MessageFileStream | [puppet.MessageFileStreamRequest](#wechaty.puppet.MessageFileStreamRequest) | [puppet.MessageFileStreamResponse](#wechaty.puppet.MessageFileStreamResponse) stream | | +| MessageImageStream | [puppet.MessageImageStreamRequest](#wechaty.puppet.MessageImageStreamRequest) | [puppet.MessageImageStreamResponse](#wechaty.puppet.MessageImageStreamResponse) stream | | +| MessageMiniProgram | [puppet.MessageMiniProgramRequest](#wechaty.puppet.MessageMiniProgramRequest) | [puppet.MessageMiniProgramResponse](#wechaty.puppet.MessageMiniProgramResponse) | | +| MessageUrl | [puppet.MessageUrlRequest](#wechaty.puppet.MessageUrlRequest) | [puppet.MessageUrlResponse](#wechaty.puppet.MessageUrlResponse) | | +| MessageRecall | [puppet.MessageRecallRequest](#wechaty.puppet.MessageRecallRequest) | [puppet.MessageRecallResponse](#wechaty.puppet.MessageRecallResponse) | | +| MessageForward | [puppet.MessageForwardRequest](#wechaty.puppet.MessageForwardRequest) | [puppet.MessageForwardResponse](#wechaty.puppet.MessageForwardResponse) | | +| MessageSendContact | [puppet.MessageSendContactRequest](#wechaty.puppet.MessageSendContactRequest) | [puppet.MessageSendContactResponse](#wechaty.puppet.MessageSendContactResponse) | | +| MessageSendFileStream | [puppet.MessageSendFileStreamRequest](#wechaty.puppet.MessageSendFileStreamRequest) stream | [puppet.MessageSendFileStreamResponse](#wechaty.puppet.MessageSendFileStreamResponse) | | +| MessageSendText | [puppet.MessageSendTextRequest](#wechaty.puppet.MessageSendTextRequest) | [puppet.MessageSendTextResponse](#wechaty.puppet.MessageSendTextResponse) | | +| MessageSendMiniProgram | [puppet.MessageSendMiniProgramRequest](#wechaty.puppet.MessageSendMiniProgramRequest) | [puppet.MessageSendMiniProgramResponse](#wechaty.puppet.MessageSendMiniProgramResponse) | | +| MessageSendUrl | [puppet.MessageSendUrlRequest](#wechaty.puppet.MessageSendUrlRequest) | [puppet.MessageSendUrlResponse](#wechaty.puppet.MessageSendUrlResponse) | | +| RoomPayload | [puppet.RoomPayloadRequest](#wechaty.puppet.RoomPayloadRequest) | [puppet.RoomPayloadResponse](#wechaty.puppet.RoomPayloadResponse) | Room | +| RoomList | [puppet.RoomListRequest](#wechaty.puppet.RoomListRequest) | [puppet.RoomListResponse](#wechaty.puppet.RoomListResponse) | | +| RoomAdd | [puppet.RoomAddRequest](#wechaty.puppet.RoomAddRequest) | [puppet.RoomAddResponse](#wechaty.puppet.RoomAddResponse) | | +| RoomAvatar | [puppet.RoomAvatarRequest](#wechaty.puppet.RoomAvatarRequest) | [puppet.RoomAvatarResponse](#wechaty.puppet.RoomAvatarResponse) | | +| RoomCreate | [puppet.RoomCreateRequest](#wechaty.puppet.RoomCreateRequest) | [puppet.RoomCreateResponse](#wechaty.puppet.RoomCreateResponse) | | +| RoomDel | [puppet.RoomDelRequest](#wechaty.puppet.RoomDelRequest) | [puppet.RoomDelResponse](#wechaty.puppet.RoomDelResponse) | | +| RoomQuit | [puppet.RoomQuitRequest](#wechaty.puppet.RoomQuitRequest) | [puppet.RoomQuitResponse](#wechaty.puppet.RoomQuitResponse) | | +| RoomTopic | [puppet.RoomTopicRequest](#wechaty.puppet.RoomTopicRequest) | [puppet.RoomTopicResponse](#wechaty.puppet.RoomTopicResponse) | | +| RoomQRCode | [puppet.RoomQRCodeRequest](#wechaty.puppet.RoomQRCodeRequest) | [puppet.RoomQRCodeResponse](#wechaty.puppet.RoomQRCodeResponse) | | +| RoomAnnounce | [puppet.RoomAnnounceRequest](#wechaty.puppet.RoomAnnounceRequest) | [puppet.RoomAnnounceResponse](#wechaty.puppet.RoomAnnounceResponse) | | +| RoomMemberPayload | [puppet.RoomMemberPayloadRequest](#wechaty.puppet.RoomMemberPayloadRequest) | [puppet.RoomMemberPayloadResponse](#wechaty.puppet.RoomMemberPayloadResponse) | Room Member | +| RoomMemberList | [puppet.RoomMemberListRequest](#wechaty.puppet.RoomMemberListRequest) | [puppet.RoomMemberListResponse](#wechaty.puppet.RoomMemberListResponse) | | +| RoomInvitationPayload | [puppet.RoomInvitationPayloadRequest](#wechaty.puppet.RoomInvitationPayloadRequest) | [puppet.RoomInvitationPayloadResponse](#wechaty.puppet.RoomInvitationPayloadResponse) | Room Invitation | +| RoomInvitationAccept | [puppet.RoomInvitationAcceptRequest](#wechaty.puppet.RoomInvitationAcceptRequest) | [puppet.RoomInvitationAcceptResponse](#wechaty.puppet.RoomInvitationAcceptResponse) | | +| TagContactAdd | [puppet.TagContactAddRequest](#wechaty.puppet.TagContactAddRequest) | [puppet.TagContactAddResponse](#wechaty.puppet.TagContactAddResponse) | Tag | +| TagContactRemove | [puppet.TagContactRemoveRequest](#wechaty.puppet.TagContactRemoveRequest) | [puppet.TagContactRemoveResponse](#wechaty.puppet.TagContactRemoveResponse) | | +| TagContactDelete | [puppet.TagContactDeleteRequest](#wechaty.puppet.TagContactDeleteRequest) | [puppet.TagContactDeleteResponse](#wechaty.puppet.TagContactDeleteResponse) | Operate Sub-Collections https://cloud.google.com/apis/design/design_patterns#list_sub-collections | +| TagContactList | [puppet.TagContactListRequest](#wechaty.puppet.TagContactListRequest) | [puppet.TagContactListResponse](#wechaty.puppet.TagContactListResponse) | | + + + + + +## Scalar Value Types + +| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby | +| ----------- | ----- | --- | ---- | ------ | -- | -- | --- | ---- | +| double | | double | double | float | float64 | double | float | Float | +| float | | float | float | float | float32 | float | float | Float | +| int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) | +| int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long | int/long | int64 | long | integer/string | Bignum | +| uint32 | Uses variable-length encoding. | uint32 | int | int/long | uint32 | uint | integer | Bignum or Fixnum (as required) | +| uint64 | Uses variable-length encoding. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum or Fixnum (as required) | +| sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) | +| sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long | int64 | long | integer/string | Bignum | +| fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 2^28. | uint32 | int | int | uint32 | uint | integer | Bignum or Fixnum (as required) | +| fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum | +| sfixed32 | Always four bytes. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) | +| sfixed64 | Always eight bytes. | int64 | long | int/long | int64 | long | integer/string | Bignum | +| bool | | bool | boolean | boolean | bool | bool | boolean | TrueClass/FalseClass | +| string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode | string | string | string | String (UTF-8) | +| bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str | []byte | ByteString | string | String (ASCII-8BIT) | + diff --git a/package.json b/package.json index e0dcd857..2d52cb90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wechaty-grpc", - "version": "0.29.38", + "version": "0.29.46", "description": "gRPC for Wechaty", "type": "module", "exports": { @@ -29,7 +29,7 @@ "lint": "npm-run-all lint:es lint:ts lint:proto", "lint:es": "eslint --ignore-pattern fixtures/ \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"", "lint:ts": "tsc --isolatedModules --noEmit", - "lint:proto": "bash -c 'protoc -I third-party -I proto --lint_out=. $(find proto/ -type f -name *.proto)'", + "lint:proto": "bash -c 'protoc -I third-party -I proto --lint_out=sort_imports:. $(find proto/ -type f -name *.proto)'", "install:protoc": "bash -x scripts/install-protoc.sh", "test": "npm-run-all lint test:unit test:commonjs", "test:pack": "bash -x scripts/npm-pack-testing.sh", diff --git a/proto/wechaty/puppet.proto b/proto/wechaty/puppet.proto index 7c8f487b..95058dcb 100644 --- a/proto/wechaty/puppet.proto +++ b/proto/wechaty/puppet.proto @@ -13,19 +13,19 @@ syntax = "proto3"; package wechaty; +import "google/api/annotations.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + import "wechaty/puppet/base.proto"; import "wechaty/puppet/contact.proto"; import "wechaty/puppet/event.proto"; import "wechaty/puppet/friendship.proto"; import "wechaty/puppet/message.proto"; -import "wechaty/puppet/room.proto"; import "wechaty/puppet/room-invitation.proto"; import "wechaty/puppet/room-member.proto"; +import "wechaty/puppet/room.proto"; import "wechaty/puppet/tag.proto"; -import "google/api/annotations.proto"; -import "protoc-gen-openapiv2/options/annotations.proto"; - option java_package="io.github.wechaty.grpc"; option go_package="github.com/wechaty/go-grpc/wechaty"; diff --git a/proto/wechaty/puppet/friendship.proto b/proto/wechaty/puppet/friendship.proto index 828bb381..41616fa5 100644 --- a/proto/wechaty/puppet/friendship.proto +++ b/proto/wechaty/puppet/friendship.proto @@ -68,8 +68,10 @@ message FriendshipSearchWeixinResponse { message FriendshipAddRequest { string contact_id = 1; string hello = 2; - google.protobuf.StringValue source_room_id = 3; - google.protobuf.StringValue source_contact_id = 4; + google.protobuf.StringValue source_room_id_string_value_deprecated = 3 [deprecated = true]; // Deprecated: will be removed after Dec 31, 2022 + google.protobuf.StringValue source_contact_id_string_value_deprecated = 4 [deprecated = true]; // Deprecated: will be removed after Dec 31, 2022 + string source_room_id = 5; + string source_contact_id = 6; } message FriendshipAddResponse {} diff --git a/proto/wechaty/puppet/message.proto b/proto/wechaty/puppet/message.proto index 51e61ef4..7914db47 100644 --- a/proto/wechaty/puppet/message.proto +++ b/proto/wechaty/puppet/message.proto @@ -6,6 +6,12 @@ option java_package="io.github.wechaty.grpc.puppet"; option csharp_namespace = "github.wechaty.grpc.puppet"; import "google/protobuf/timestamp.proto"; + +/** + * @deprecated + * Huan(202109): will be removed after Dec 31, 2022 + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ import "google/protobuf/wrappers.proto"; import "wechaty/puppet/file-box.proto"; @@ -133,8 +139,13 @@ message MessageSendContactRequest { string contact_id = 2; } message MessageSendContactResponse { - // nullable - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageSendFileRequest { @@ -142,7 +153,13 @@ message MessageSendFileRequest { string filebox = 2; } message MessageSendFileResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageSendFileStreamRequest { @@ -152,7 +169,13 @@ message MessageSendFileStreamRequest { }; } message MessageSendFileStreamResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageSendTextRequest { @@ -164,7 +187,13 @@ message MessageSendTextRequest { repeated string mentional_ids = 3; } message MessageSendTextResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageSendMiniProgramRequest { @@ -177,7 +206,13 @@ message MessageSendMiniProgramRequest { MiniProgramPayload mini_program = 3; } message MessageSendMiniProgramResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageSendUrlRequest { @@ -190,7 +225,13 @@ message MessageSendUrlRequest { UrlLinkPayload url_link = 3; } message MessageSendUrlResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageRecallRequest { @@ -204,7 +245,13 @@ message MessageForwardRequest{ string conversation_id = 2; } message MessageForwardResponse { - google.protobuf.StringValue id = 1; + /** + * @deprecated: use payload instead. + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue id_string_value_deprecated = 1 [deprecated = true]; // Deprecated after Sep 31, 2021, will be removed after Dec 31, 2022 + string id = 2; } message MessageLocationRequest{ diff --git a/proto/wechaty/puppet/room-invitation.proto b/proto/wechaty/puppet/room-invitation.proto index c083f2e3..331f4c99 100644 --- a/proto/wechaty/puppet/room-invitation.proto +++ b/proto/wechaty/puppet/room-invitation.proto @@ -6,6 +6,12 @@ option java_package="io.github.wechaty.grpc.puppet"; option csharp_namespace = "github.wechaty.grpc.puppet"; import "google/protobuf/timestamp.proto"; + +/** + * @deprecated + * Huan(202109): will be removed after Dec 31, 2022 + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ import "google/protobuf/wrappers.proto"; message RoomInvitationPayloadRequest { @@ -14,8 +20,13 @@ message RoomInvitationPayloadRequest { * Huan(202002): `payload` should be removed. * The puppet server should take the responsibilities * for storing the unaccepted friend-request payload. + * + * @deprecated: use payload instead. + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields */ - google.protobuf.StringValue payload = 2; + google.protobuf.StringValue payload_string_value_deprecated = 2 [deprecated = true]; // Deprecated: will be removed after Dec 31, 2022 + string payload = 3; } message RoomInvitationPayloadResponse { string id = 1; @@ -27,7 +38,7 @@ message RoomInvitationPayloadResponse { * @deprecated will be removed after Dec 31, 2022 * Huan(202109): use receive_time(10) instead */ - uint64 timestamp_deprecated = 6 [deprecated = true]; // deprecated + uint64 timestamp_uint64_deprecated = 6 [deprecated = true]; // Deprecated: will be removed after Dec 31, 2022 string avatar = 7; string invitation = 8; string receiver_id = 9; diff --git a/proto/wechaty/puppet/tag.proto b/proto/wechaty/puppet/tag.proto index e9a42ab4..86aed43e 100644 --- a/proto/wechaty/puppet/tag.proto +++ b/proto/wechaty/puppet/tag.proto @@ -5,7 +5,12 @@ option go_package="github.com/wechaty/go-grpc/wechaty/puppet"; option java_package="io.github.wechaty.grpc.puppet"; option csharp_namespace = "github.wechaty.grpc.puppet"; -import "google/protobuf/wrappers.proto"; +/** + * @deprecated + * Huan(202109): will be removed after Dec 31, 2022 + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + import "google/protobuf/wrappers.proto"; message TagContactAddRequest { string id = 1; @@ -25,7 +30,13 @@ message TagContactDeleteRequest { message TagContactDeleteResponse {} message TagContactListRequest { - google.protobuf.StringValue contact_id = 1; + /* + * @deprecated: + * Huan(202109): Wrapper types must not be used going forward. + * https://cloud.google.com/apis/design/design_patterns#optional_primitive_fields + */ + google.protobuf.StringValue contact_id_string_value_deprecated = 1 [deprecated = true]; // Deprecated: will be removed after Dec 31, 2022 + string contact_id = 2; } message TagContactListResponse { repeated string ids = 1; diff --git a/scripts/generate-stub.sh b/scripts/generate-stub.sh index 1fde5204..4d9c4518 100755 --- a/scripts/generate-stub.sh +++ b/scripts/generate-stub.sh @@ -34,6 +34,7 @@ function gen_js_stub () { # # 2. JS for gRPC Stubs # - https://www.npmjs.com/package/grpc-tools + # - https://github.com/grpc/grpc/tree/master/examples/node/static_codegen # # Generate: wechaty-puppet_grpc_pb.js $PROTOC_CMD \ diff --git a/scripts/install-protoc.sh b/scripts/install-protoc.sh index 76f5e8d2..efdb061d 100755 --- a/scripts/install-protoc.sh +++ b/scripts/install-protoc.sh @@ -3,9 +3,10 @@ set -e set -o pipefail # https://stackoverflow.com/a/4774063/1123955 -SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; pwd -P )" +WORK_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; pwd -P )" +REPO_DIR="$( cd "$WORK_DIR/../" >/dev/null 2>&1 ; pwd -P )" -THIRD_PARTY_DIR="${SCRIPTPATH}/../third-party/" +THIRD_PARTY_DIR="$REPO_DIR/third-party/" function install_protoc () { if command -v protoc > /dev/null; then @@ -36,9 +37,9 @@ function check_protoc_version () { exit 1 } - # https://github.com/wechaty/grpc/issues/116 - (($minorVer >= 5)) || { - echo "protoc minor version must >= 5 (the installed version is $protocVersion)" + # https://github.com/wechaty/grpc/issues/109 + (($minorVer >= 18)) || { + echo "protoc minor version must >= 18 (the installed version is $protocVersion)" exit 1 } @@ -62,7 +63,7 @@ function install_proto_google_api () { } function install_protoc_gen_openapiv2 () { - pushd "${SCRIPTPATH}/../openapi" + pushd "$REPO_DIR/openapi" make install popd } @@ -79,12 +80,21 @@ function install_protoc_gen_openapiv2 () { # https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/descriptor.proto # } +function install_protoc_gen_doc () { + if command -v protoc-gen-doc; then + echo "install skipped: $(command -v protoc-gen-doc) exists" + return 0 + fi + go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest +} + function main () { install_protoc check_protoc_version install_protoc_gen_lint install_protoc_gen_openapiv2 + install_protoc_gen_doc install_proto_google_api } diff --git a/src/google.spec.ts b/src/google.spec.ts new file mode 100755 index 00000000..202b49bd --- /dev/null +++ b/src/google.spec.ts @@ -0,0 +1,13 @@ +#!/usr/bin/env -S node --no-warnings --loader ts-node/esm + +import { test } from 'tstest' + +import { + Timestamp, +} from './google.js' + +test('Timestamp', async t => { + const timestamp: Timestamp = new Timestamp() + timestamp.fromDate(new Date()) + t.ok(timestamp, 'should create a timestamp protocol buffer') +}) diff --git a/src/google.ts b/src/google.ts index df1946a0..b90abfb1 100644 --- a/src/google.ts +++ b/src/google.ts @@ -1,13 +1,8 @@ -import wrappers from 'google-protobuf/google/protobuf/wrappers_pb.js' -import timestamp from 'google-protobuf/google/protobuf/timestamp_pb.js' +import timestamp from 'google-protobuf/google/protobuf/timestamp_pb.js' +import wrappers from 'google-protobuf/google/protobuf/wrappers_pb.js' -const { - StringValue, -} = wrappers - -const { - Timestamp, -} = timestamp +class StringValue extends wrappers.StringValue {} +class Timestamp extends timestamp.Timestamp {} export { StringValue, diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 67f2421d..b542512b 100755 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -83,6 +83,11 @@ test('integration testing', async t => { /** * Close Client & Server */ + + /** + * Issue #130: Assertion `(current_nghttp2_memory_) >= (previous_size)' failed. + * https://github.com/wechaty/grpc/issues/130 + */ await new Promise