From d23a52c7898de3713c4ba069fb0a6e70261c76a0 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Fri, 13 Sep 2024 13:41:46 +0000 Subject: [PATCH 1/6] feat(event-emitter): add `promise` method --- packages/client/libs/thrift/line_types.ts | 120 ++++++------------ .../libs/typed-event-emitter/index.test.ts | 18 +++ .../client/libs/typed-event-emitter/index.ts | 15 +++ 3 files changed, 73 insertions(+), 80 deletions(-) create mode 100644 packages/client/libs/typed-event-emitter/index.test.ts diff --git a/packages/client/libs/thrift/line_types.ts b/packages/client/libs/thrift/line_types.ts index 1adf9df..f184e9d 100644 --- a/packages/client/libs/thrift/line_types.ts +++ b/packages/client/libs/thrift/line_types.ts @@ -313,8 +313,7 @@ export enum ErrorCode { INTERNAL_ERROR = 20, _NO_SUCH_IDENTITY_IDENFIER = "NO_SUCH_IDENTITY_IDENFIER", NO_SUCH_IDENTITY_IDENFIER = 21, - _DEACTIVATED_ACCOUNT_BOUND_TO_THIS_IDENTITY = - "DEACTIVATED_ACCOUNT_BOUND_TO_THIS_IDENTITY", + _DEACTIVATED_ACCOUNT_BOUND_TO_THIS_IDENTITY = "DEACTIVATED_ACCOUNT_BOUND_TO_THIS_IDENTITY", DEACTIVATED_ACCOUNT_BOUND_TO_THIS_IDENTITY = 22, _ILLEGAL_IDENTITY_CREDENTIAL = "ILLEGAL_IDENTITY_CREDENTIAL", ILLEGAL_IDENTITY_CREDENTIAL = 23, @@ -392,16 +391,13 @@ export enum ErrorCode { NO_CALLER_ID_LIMIT_EXCEEDED = 61, _CALLER_ID_VERIFICATION_REQUIRED = "CALLER_ID_VERIFICATION_REQUIRED", CALLER_ID_VERIFICATION_REQUIRED = 62, - _NO_CALLER_ID_LIMIT_EXCEEDED_AND_VERIFICATION_REQUIRED = - "NO_CALLER_ID_LIMIT_EXCEEDED_AND_VERIFICATION_REQUIRED", + _NO_CALLER_ID_LIMIT_EXCEEDED_AND_VERIFICATION_REQUIRED = "NO_CALLER_ID_LIMIT_EXCEEDED_AND_VERIFICATION_REQUIRED", NO_CALLER_ID_LIMIT_EXCEEDED_AND_VERIFICATION_REQUIRED = 63, _MESSAGE_NOT_FOUND = "MESSAGE_NOT_FOUND", MESSAGE_NOT_FOUND = 64, - _INVALID_ACCOUNT_MIGRATION_PINCODE_FORMAT = - "INVALID_ACCOUNT_MIGRATION_PINCODE_FORMAT", + _INVALID_ACCOUNT_MIGRATION_PINCODE_FORMAT = "INVALID_ACCOUNT_MIGRATION_PINCODE_FORMAT", INVALID_ACCOUNT_MIGRATION_PINCODE_FORMAT = 65, - _ACCOUNT_MIGRATION_PINCODE_NOT_MATCHED = - "ACCOUNT_MIGRATION_PINCODE_NOT_MATCHED", + _ACCOUNT_MIGRATION_PINCODE_NOT_MATCHED = "ACCOUNT_MIGRATION_PINCODE_NOT_MATCHED", ACCOUNT_MIGRATION_PINCODE_NOT_MATCHED = 66, _ACCOUNT_MIGRATION_PINCODE_BLOCKED = "ACCOUNT_MIGRATION_PINCODE_BLOCKED", ACCOUNT_MIGRATION_PINCODE_BLOCKED = 67, @@ -415,11 +411,9 @@ export enum ErrorCode { PAID_CALL_REDEEM_FAILED = 72, _PREVENTED_JOIN_BY_TICKET = "PREVENTED_JOIN_BY_TICKET", PREVENTED_JOIN_BY_TICKET = 73, - _SEND_MESSAGE_NOT_PERMITTED_FROM_LINE_AT = - "SEND_MESSAGE_NOT_PERMITTED_FROM_LINE_AT", + _SEND_MESSAGE_NOT_PERMITTED_FROM_LINE_AT = "SEND_MESSAGE_NOT_PERMITTED_FROM_LINE_AT", SEND_MESSAGE_NOT_PERMITTED_FROM_LINE_AT = 75, - _SEND_MESSAGE_NOT_PERMITTED_WHILE_AUTO_REPLY = - "SEND_MESSAGE_NOT_PERMITTED_WHILE_AUTO_REPLY", + _SEND_MESSAGE_NOT_PERMITTED_WHILE_AUTO_REPLY = "SEND_MESSAGE_NOT_PERMITTED_WHILE_AUTO_REPLY", SEND_MESSAGE_NOT_PERMITTED_WHILE_AUTO_REPLY = 76, _SECURITY_CENTER_NOT_VERIFIED = "SECURITY_CENTER_NOT_VERIFIED", SECURITY_CENTER_NOT_VERIFIED = 77, @@ -687,8 +681,7 @@ export enum PwlessCredentialErrorCode { NOT_SUPPORTED = 101, _FORBIDDEN = "FORBIDDEN", FORBIDDEN = 102, - _FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = - "FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR", + _FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = "FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR", FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = 201, } @@ -747,8 +740,7 @@ export enum SecondaryPwlessLoginErrorCode { FORBIDDEN = 103, _FIDO_UNKNOWN_CREDENTIAL_ID = "FIDO_UNKNOWN_CREDENTIAL_ID", FIDO_UNKNOWN_CREDENTIAL_ID = 200, - _FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = - "FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR", + _FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = "FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR", FIDO_RETRY_WITH_ANOTHER_AUTHENTICATOR = 201, _FIDO_UNACCEPTABLE_CONTENT = "FIDO_UNACCEPTABLE_CONTENT", FIDO_UNACCEPTABLE_CONTENT = 202, @@ -1710,11 +1702,9 @@ export enum VerificationMethod { } export enum ContactSetting { - _CONTACT_SETTING_NOTIFICATION_DISABLE = - "CONTACT_SETTING_NOTIFICATION_DISABLE", + _CONTACT_SETTING_NOTIFICATION_DISABLE = "CONTACT_SETTING_NOTIFICATION_DISABLE", CONTACT_SETTING_NOTIFICATION_DISABLE = 1, - _CONTACT_SETTING_DISPLAY_NAME_OVERRIDE = - "CONTACT_SETTING_DISPLAY_NAME_OVERRIDE", + _CONTACT_SETTING_DISPLAY_NAME_OVERRIDE = "CONTACT_SETTING_DISPLAY_NAME_OVERRIDE", CONTACT_SETTING_DISPLAY_NAME_OVERRIDE = 2, _CONTACT_SETTING_CONTACT_HIDE = "CONTACT_SETTING_CONTACT_HIDE", CONTACT_SETTING_CONTACT_HIDE = 4, @@ -2109,8 +2099,7 @@ export enum SquareEventType { NOTIFIED_DESTROY_MESSAGE = 5, _NOTIFIED_MARK_AS_READ = "NOTIFIED_MARK_AS_READ", NOTIFIED_MARK_AS_READ = 6, - _NOTIFIED_UPDATE_SQUARE_MEMBER_PROFILE = - "NOTIFIED_UPDATE_SQUARE_MEMBER_PROFILE", + _NOTIFIED_UPDATE_SQUARE_MEMBER_PROFILE = "NOTIFIED_UPDATE_SQUARE_MEMBER_PROFILE", NOTIFIED_UPDATE_SQUARE_MEMBER_PROFILE = 7, _NOTIFIED_KICKOUT_FROM_SQUARE = "NOTIFIED_KICKOUT_FROM_SQUARE", NOTIFIED_KICKOUT_FROM_SQUARE = 19, @@ -2118,17 +2107,13 @@ export enum SquareEventType { NOTIFIED_SHUTDOWN_SQUARE = 18, _NOTIFIED_DELETE_SQUARE_CHAT = "NOTIFIED_DELETE_SQUARE_CHAT", NOTIFIED_DELETE_SQUARE_CHAT = 20, - _NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_NAME = - "NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_NAME", + _NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_NAME = "NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_NAME", NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_NAME = 30, - _NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_IMAGE = - "NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_IMAGE", + _NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_IMAGE = "NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_IMAGE", NOTIFIED_UPDATE_SQUARE_CHAT_PROFILE_IMAGE = 31, - _NOTIFIED_UPDATE_SQUARE_CHAT_MAX_MEMBER_COUNT = - "NOTIFIED_UPDATE_SQUARE_CHAT_MAX_MEMBER_COUNT", + _NOTIFIED_UPDATE_SQUARE_CHAT_MAX_MEMBER_COUNT = "NOTIFIED_UPDATE_SQUARE_CHAT_MAX_MEMBER_COUNT", NOTIFIED_UPDATE_SQUARE_CHAT_MAX_MEMBER_COUNT = 38, - _NOTIFIED_UPDATE_SQUARE_CHAT_ANNOUNCEMENT = - "NOTIFIED_UPDATE_SQUARE_CHAT_ANNOUNCEMENT", + _NOTIFIED_UPDATE_SQUARE_CHAT_ANNOUNCEMENT = "NOTIFIED_UPDATE_SQUARE_CHAT_ANNOUNCEMENT", NOTIFIED_UPDATE_SQUARE_CHAT_ANNOUNCEMENT = 37, _NOTIFIED_ADD_BOT = "NOTIFIED_ADD_BOT", NOTIFIED_ADD_BOT = 33, @@ -2160,13 +2145,11 @@ export enum SquareEventType { NOTIFIED_CREATE_SQUARE_MEMBER = 15, _NOTIFIED_CREATE_SQUARE_CHAT_MEMBER = "NOTIFIED_CREATE_SQUARE_CHAT_MEMBER", NOTIFIED_CREATE_SQUARE_CHAT_MEMBER = 16, - _NOTIFIED_UPDATE_SQUARE_MEMBER_RELATION = - "NOTIFIED_UPDATE_SQUARE_MEMBER_RELATION", + _NOTIFIED_UPDATE_SQUARE_MEMBER_RELATION = "NOTIFIED_UPDATE_SQUARE_MEMBER_RELATION", NOTIFIED_UPDATE_SQUARE_MEMBER_RELATION = 17, _NOTIFIED_UPDATE_SQUARE_FEATURE_SET = "NOTIFIED_UPDATE_SQUARE_FEATURE_SET", NOTIFIED_UPDATE_SQUARE_FEATURE_SET = 32, - _NOTIFIED_UPDATE_SQUARE_CHAT_FEATURE_SET = - "NOTIFIED_UPDATE_SQUARE_CHAT_FEATURE_SET", + _NOTIFIED_UPDATE_SQUARE_CHAT_FEATURE_SET = "NOTIFIED_UPDATE_SQUARE_CHAT_FEATURE_SET", NOTIFIED_UPDATE_SQUARE_CHAT_FEATURE_SET = 50, _NOTIFIED_UPDATE_SQUARE_NOTE_STATUS = "NOTIFIED_UPDATE_SQUARE_NOTE_STATUS", NOTIFIED_UPDATE_SQUARE_NOTE_STATUS = 36, @@ -2361,16 +2344,13 @@ export enum SquareChatThreadeMembershipState { export enum LiveTalkEventType { _NOTIFIED_UPDATE_LIVE_TALK_TITLE = "NOTIFIED_UPDATE_LIVE_TALK_TITLE", NOTIFIED_UPDATE_LIVE_TALK_TITLE = 1, - _NOTIFIED_UPDATE_LIVE_TALK_SPEAKER_SETTING = - "NOTIFIED_UPDATE_LIVE_TALK_SPEAKER_SETTING", + _NOTIFIED_UPDATE_LIVE_TALK_SPEAKER_SETTING = "NOTIFIED_UPDATE_LIVE_TALK_SPEAKER_SETTING", NOTIFIED_UPDATE_LIVE_TALK_SPEAKER_SETTING = 2, - _NOTIFIED_UPDATE_LIVE_TALK_ANNOUNCEMENT = - "NOTIFIED_UPDATE_LIVE_TALK_ANNOUNCEMENT", + _NOTIFIED_UPDATE_LIVE_TALK_ANNOUNCEMENT = "NOTIFIED_UPDATE_LIVE_TALK_ANNOUNCEMENT", NOTIFIED_UPDATE_LIVE_TALK_ANNOUNCEMENT = 3, _NOTIFIED_UPDATE_SQUARE_MEMBER_ROLE = "NOTIFIED_UPDATE_SQUARE_MEMBER_ROLE", NOTIFIED_UPDATE_SQUARE_MEMBER_ROLE = 4, - _NOTIFIED_UPDATE_LIVE_TALK_ALLOW_REQUEST_TO_SPEAK = - "NOTIFIED_UPDATE_LIVE_TALK_ALLOW_REQUEST_TO_SPEAK", + _NOTIFIED_UPDATE_LIVE_TALK_ALLOW_REQUEST_TO_SPEAK = "NOTIFIED_UPDATE_LIVE_TALK_ALLOW_REQUEST_TO_SPEAK", NOTIFIED_UPDATE_LIVE_TALK_ALLOW_REQUEST_TO_SPEAK = 5, } @@ -5429,8 +5409,7 @@ export declare class SquareEventPayload { notifiedLeaveSquareChat: SquareEventNotifiedLeaveSquareChat; notifiedDestroyMessage: SquareEventNotifiedDestroyMessage; notifiedMarkAsRead: SquareEventNotifiedMarkAsRead; - notifiedUpdateSquareMemberProfile: - SquareEventNotifiedUpdateSquareMemberProfile; + notifiedUpdateSquareMemberProfile: SquareEventNotifiedUpdateSquareMemberProfile; notifiedUpdateSquare: SquareEventNotifiedUpdateSquare; notifiedUpdateSquareMember: SquareEventNotifiedUpdateSquareMember; notifiedUpdateSquareChat: SquareEventNotifiedUpdateSquareChat; @@ -5440,8 +5419,7 @@ export declare class SquareEventPayload { notifiedUpdateSquareChatStatus: SquareEventNotifiedUpdateSquareChatStatus; notifiedCreateSquareMember: SquareEventNotifiedCreateSquareMember; notifiedCreateSquareChatMember: SquareEventNotifiedCreateSquareChatMember; - notifiedUpdateSquareMemberRelation: - SquareEventNotifiedUpdateSquareMemberRelation; + notifiedUpdateSquareMemberRelation: SquareEventNotifiedUpdateSquareMemberRelation; notifiedShutdownSquare: SquareEventNotifiedShutdownSquare; notifiedKickoutFromSquare: SquareEventNotifiedKickoutFromSquare; notifiedDeleteSquareChat: SquareEventNotifiedDeleteSquareChat; @@ -5454,18 +5432,14 @@ export declare class SquareEventPayload { notificationSquareDelete: SquareEventNotificationSquareDelete; notificationSquareChatDelete: SquareEventNotificationSquareChatDelete; notificationMessage: SquareEventNotificationMessage; - notifiedUpdateSquareChatProfileName: - SquareEventNotifiedUpdateSquareChatProfileName; - notifiedUpdateSquareChatProfileImage: - SquareEventNotifiedUpdateSquareChatProfileImage; + notifiedUpdateSquareChatProfileName: SquareEventNotifiedUpdateSquareChatProfileName; + notifiedUpdateSquareChatProfileImage: SquareEventNotifiedUpdateSquareChatProfileImage; notifiedUpdateSquareFeatureSet: SquareEventNotifiedUpdateSquareFeatureSet; notifiedAddBot: SquareEventNotifiedAddBot; notifiedRemoveBot: SquareEventNotifiedRemoveBot; notifiedUpdateSquareNoteStatus: SquareEventNotifiedUpdateSquareNoteStatus; - notifiedUpdateSquareChatAnnouncement: - SquareEventNotifiedUpdateSquareChatAnnouncement; - notifiedUpdateSquareChatMaxMemberCount: - SquareEventNotifiedUpdateSquareChatMaxMemberCount; + notifiedUpdateSquareChatAnnouncement: SquareEventNotifiedUpdateSquareChatAnnouncement; + notifiedUpdateSquareChatMaxMemberCount: SquareEventNotifiedUpdateSquareChatMaxMemberCount; notificationPostAnnouncement: SquareEventNotificationPostAnnouncement; notificationPost: SquareEventNotificationPost; mutateMessage: SquareEventMutateMessage; @@ -5475,8 +5449,7 @@ export declare class SquareEventPayload { notificationMessageReaction: SquareEventNotificationMessageReaction; chatPopup: SquareEventChatPopup; notifiedSystemMessage: SquareEventNotifiedSystemMessage; - notifiedUpdateSquareChatFeatureSet: - SquareEventNotifiedUpdateSquareChatFeatureSet; + notifiedUpdateSquareChatFeatureSet: SquareEventNotifiedUpdateSquareChatFeatureSet; constructor(args?: { receiveMessage: SquareEventReceiveMessage; @@ -5486,8 +5459,7 @@ export declare class SquareEventPayload { notifiedLeaveSquareChat: SquareEventNotifiedLeaveSquareChat; notifiedDestroyMessage: SquareEventNotifiedDestroyMessage; notifiedMarkAsRead: SquareEventNotifiedMarkAsRead; - notifiedUpdateSquareMemberProfile: - SquareEventNotifiedUpdateSquareMemberProfile; + notifiedUpdateSquareMemberProfile: SquareEventNotifiedUpdateSquareMemberProfile; notifiedUpdateSquare: SquareEventNotifiedUpdateSquare; notifiedUpdateSquareMember: SquareEventNotifiedUpdateSquareMember; notifiedUpdateSquareChat: SquareEventNotifiedUpdateSquareChat; @@ -5497,8 +5469,7 @@ export declare class SquareEventPayload { notifiedUpdateSquareChatStatus: SquareEventNotifiedUpdateSquareChatStatus; notifiedCreateSquareMember: SquareEventNotifiedCreateSquareMember; notifiedCreateSquareChatMember: SquareEventNotifiedCreateSquareChatMember; - notifiedUpdateSquareMemberRelation: - SquareEventNotifiedUpdateSquareMemberRelation; + notifiedUpdateSquareMemberRelation: SquareEventNotifiedUpdateSquareMemberRelation; notifiedShutdownSquare: SquareEventNotifiedShutdownSquare; notifiedKickoutFromSquare: SquareEventNotifiedKickoutFromSquare; notifiedDeleteSquareChat: SquareEventNotifiedDeleteSquareChat; @@ -5511,18 +5482,14 @@ export declare class SquareEventPayload { notificationSquareDelete: SquareEventNotificationSquareDelete; notificationSquareChatDelete: SquareEventNotificationSquareChatDelete; notificationMessage: SquareEventNotificationMessage; - notifiedUpdateSquareChatProfileName: - SquareEventNotifiedUpdateSquareChatProfileName; - notifiedUpdateSquareChatProfileImage: - SquareEventNotifiedUpdateSquareChatProfileImage; + notifiedUpdateSquareChatProfileName: SquareEventNotifiedUpdateSquareChatProfileName; + notifiedUpdateSquareChatProfileImage: SquareEventNotifiedUpdateSquareChatProfileImage; notifiedUpdateSquareFeatureSet: SquareEventNotifiedUpdateSquareFeatureSet; notifiedAddBot: SquareEventNotifiedAddBot; notifiedRemoveBot: SquareEventNotifiedRemoveBot; notifiedUpdateSquareNoteStatus: SquareEventNotifiedUpdateSquareNoteStatus; - notifiedUpdateSquareChatAnnouncement: - SquareEventNotifiedUpdateSquareChatAnnouncement; - notifiedUpdateSquareChatMaxMemberCount: - SquareEventNotifiedUpdateSquareChatMaxMemberCount; + notifiedUpdateSquareChatAnnouncement: SquareEventNotifiedUpdateSquareChatAnnouncement; + notifiedUpdateSquareChatMaxMemberCount: SquareEventNotifiedUpdateSquareChatMaxMemberCount; notificationPostAnnouncement: SquareEventNotificationPostAnnouncement; notificationPost: SquareEventNotificationPost; mutateMessage: SquareEventMutateMessage; @@ -5532,8 +5499,7 @@ export declare class SquareEventPayload { notificationMessageReaction: SquareEventNotificationMessageReaction; chatPopup: SquareEventChatPopup; notifiedSystemMessage: SquareEventNotifiedSystemMessage; - notifiedUpdateSquareChatFeatureSet: - SquareEventNotifiedUpdateSquareChatFeatureSet; + notifiedUpdateSquareChatFeatureSet: SquareEventNotifiedUpdateSquareChatFeatureSet; }); } @@ -5913,23 +5879,17 @@ export declare class LiveTalkEventNotifiedUpdateLiveTalkAllowRequestToSpeak { export declare class LiveTalkEventPayload { notifiedUpdateLiveTalkTitle: LiveTalkEventNotifiedUpdateLiveTalkTitle; - notifiedUpdateLiveTalkSpeakerSetting: - LiveTalkEventNotifiedUpdateLiveTalkSpeakerSetting; - notifiedUpdateLiveTalkAnnouncement: - LiveTalkEventNotifiedUpdateLiveTalkAnnouncement; + notifiedUpdateLiveTalkSpeakerSetting: LiveTalkEventNotifiedUpdateLiveTalkSpeakerSetting; + notifiedUpdateLiveTalkAnnouncement: LiveTalkEventNotifiedUpdateLiveTalkAnnouncement; notifiedUpdateSquareMemberRole: LiveTalkEventNotifiedUpdateSquareMemberRole; - notifiedUpdateLiveTalkAllowRequestToSpeak: - LiveTalkEventNotifiedUpdateLiveTalkAllowRequestToSpeak; + notifiedUpdateLiveTalkAllowRequestToSpeak: LiveTalkEventNotifiedUpdateLiveTalkAllowRequestToSpeak; constructor(args?: { notifiedUpdateLiveTalkTitle: LiveTalkEventNotifiedUpdateLiveTalkTitle; - notifiedUpdateLiveTalkSpeakerSetting: - LiveTalkEventNotifiedUpdateLiveTalkSpeakerSetting; - notifiedUpdateLiveTalkAnnouncement: - LiveTalkEventNotifiedUpdateLiveTalkAnnouncement; + notifiedUpdateLiveTalkSpeakerSetting: LiveTalkEventNotifiedUpdateLiveTalkSpeakerSetting; + notifiedUpdateLiveTalkAnnouncement: LiveTalkEventNotifiedUpdateLiveTalkAnnouncement; notifiedUpdateSquareMemberRole: LiveTalkEventNotifiedUpdateSquareMemberRole; - notifiedUpdateLiveTalkAllowRequestToSpeak: - LiveTalkEventNotifiedUpdateLiveTalkAllowRequestToSpeak; + notifiedUpdateLiveTalkAllowRequestToSpeak: LiveTalkEventNotifiedUpdateLiveTalkAllowRequestToSpeak; }); } diff --git a/packages/client/libs/typed-event-emitter/index.test.ts b/packages/client/libs/typed-event-emitter/index.test.ts new file mode 100644 index 0000000..75a5fd6 --- /dev/null +++ b/packages/client/libs/typed-event-emitter/index.test.ts @@ -0,0 +1,18 @@ +import { assertEquals } from "@std/assert"; +import { TypedEventEmitter } from "./index.ts"; + +Deno.test("promise() should be vaild", async () => { + type Events = { + example: (v: number) => void; + }; + class Client extends TypedEventEmitter {} + const client = new Client(); + + const promise = client.promise("example"); + + client.emit("example", 123456); + + const [v] = await promise; + + assertEquals(v, 123456); +}); diff --git a/packages/client/libs/typed-event-emitter/index.ts b/packages/client/libs/typed-event-emitter/index.ts index 49446f1..073ce2c 100644 --- a/packages/client/libs/typed-event-emitter/index.ts +++ b/packages/client/libs/typed-event-emitter/index.ts @@ -41,4 +41,19 @@ export class TypedEventEmitter< return this; } + + /** + * Creating a promise, you can use it for once event. + */ + public promise>( + event: E2, + ): Promise

{ + return new Promise

((resolve) => { + const listener = ((...args) => { + this.off(event, listener); + resolve(args as P); + }) as T[E2]; + this.on(event, listener); + }); + } } From b1278c09f2c9ea3ecbc36a912d884e66fc8cb135 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Fri, 13 Sep 2024 13:42:50 +0000 Subject: [PATCH 2/6] fix jsdoc --- packages/client/libs/typed-event-emitter/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client/libs/typed-event-emitter/index.ts b/packages/client/libs/typed-event-emitter/index.ts index 073ce2c..5c2dd36 100644 --- a/packages/client/libs/typed-event-emitter/index.ts +++ b/packages/client/libs/typed-event-emitter/index.ts @@ -43,7 +43,8 @@ export class TypedEventEmitter< } /** - * Creating a promise, you can use it for once event. + * This creates a promise that you can use for a single event. + * @param event A event name */ public promise>( event: E2, From ad9520a8cfe4e70687f494b9416fc3464753e06e Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Fri, 13 Sep 2024 13:45:58 +0000 Subject: [PATCH 3/6] chore: remove deno fmt --- deno.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/deno.json b/deno.json index b0774e1..0ede756 100644 --- a/deno.json +++ b/deno.json @@ -8,14 +8,6 @@ "./storage": "./packages/storage/index.ts", "./rate-limit": "./packages/rate-limit/index.ts" }, - "fmt": { - "indentWidth": 2, - "singleQuote": false, - "useTabs": true, - "exclude": [ - "./docs/" - ] - }, "imports": { "@std/assert": "jsr:@std/assert@^1.0.2", "curve25519-js": "npm:curve25519-js@^0.0.4", @@ -24,7 +16,7 @@ "tweetnacl": "npm:tweetnacl@^1.0.3" }, "tasks": { - "format": "deno fmt & deno run -A npm:@biomejs/biome format --write ./packages/**/*.ts", + "format": "deno run -A npm:@biomejs/biome format --write ./packages/**/*.ts", "lint": "deno run -A npm:@biomejs/biome lint ./packages/**/*.ts", "check": "deno run -A npm:@biomejs/biome check ./packages/**/*.ts" } From 86e3dd3081c9787336fd7644957773c51b9ff0e8 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Fri, 13 Sep 2024 23:17:43 +0900 Subject: [PATCH 4/6] feat: smarter types Co-authored-by: EdamAmex <121654029+EdamAme-x@users.noreply.github.com> --- packages/client/libs/typed-event-emitter/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/libs/typed-event-emitter/index.ts b/packages/client/libs/typed-event-emitter/index.ts index 5c2dd36..5f9d124 100644 --- a/packages/client/libs/typed-event-emitter/index.ts +++ b/packages/client/libs/typed-event-emitter/index.ts @@ -46,7 +46,7 @@ export class TypedEventEmitter< * This creates a promise that you can use for a single event. * @param event A event name */ - public promise>( + public promise>( event: E2, ): Promise

{ return new Promise

((resolve) => { From 8ccf8c039dcc7fc5e34a8561db051aee5f50d9f7 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Fri, 13 Sep 2024 14:25:29 +0000 Subject: [PATCH 5/6] feat: rename `promise` to `waitFor` --- packages/client/libs/typed-event-emitter/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/libs/typed-event-emitter/index.ts b/packages/client/libs/typed-event-emitter/index.ts index 5c2dd36..5d1ec12 100644 --- a/packages/client/libs/typed-event-emitter/index.ts +++ b/packages/client/libs/typed-event-emitter/index.ts @@ -46,7 +46,7 @@ export class TypedEventEmitter< * This creates a promise that you can use for a single event. * @param event A event name */ - public promise>( + public waitFor>( event: E2, ): Promise

{ return new Promise

((resolve) => { From b92996ff6016db31bdf2bfb5b9002d278aeaa276 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura Date: Fri, 13 Sep 2024 14:27:22 +0000 Subject: [PATCH 6/6] fix test --- packages/client/libs/typed-event-emitter/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/libs/typed-event-emitter/index.test.ts b/packages/client/libs/typed-event-emitter/index.test.ts index 75a5fd6..4cc061a 100644 --- a/packages/client/libs/typed-event-emitter/index.test.ts +++ b/packages/client/libs/typed-event-emitter/index.test.ts @@ -8,7 +8,7 @@ Deno.test("promise() should be vaild", async () => { class Client extends TypedEventEmitter {} const client = new Client(); - const promise = client.promise("example"); + const promise = client.waitFor("example"); client.emit("example", 123456);