Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
export all types in typescript declaration file and work around the f…
Browse files Browse the repository at this point in the history
…act typescript can't handle union of promise type (#87)

fix(types): Export types from the declaration file and work around for union of promise types.

Co-authored-by: 牛牛 <[email protected]>
Co-authored-by: 電ちゃん <[email protected]>
Co-authored-by: 徐岱青 <[email protected]>
  • Loading branch information
4 people authored Mar 16, 2020
1 parent 573bcce commit d0c76d3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
40 changes: 20 additions & 20 deletions cq-websocket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum WebSocketState {
export interface CQRequestOptions {
timeout: number
}
type WebSocketProtocol = "http:" | "https:" | "ws:" | "wss:"
export type WebSocketProtocol = "http:" | "https:" | "ws:" | "wss:"
export interface CQWebSocketOption {
accessToken: string
enableAPI: boolean
Expand All @@ -32,20 +32,20 @@ export interface CQWebSocketOption {
requestOptions: CQRequestOptions
}

type BaseEvents = 'message'
export type BaseEvents = 'message'
| 'notice'
| 'request'
| 'error'
| 'ready'
type MessageEvents = 'message.private'
export type MessageEvents = 'message.private'
| 'message.discuss'
| 'message.discuss.@'
| '[email protected]'
| 'message.group'
| 'message.group.@'
| '[email protected]'

type NoticeEvents = 'notice.group_upload'
export type NoticeEvents = 'notice.group_upload'
| 'notice.group_admin.set'
| 'notice.group_admin.unset'
| 'notice.group_decrease.leave'
Expand All @@ -59,16 +59,16 @@ type NoticeEvents = 'notice.group_upload'
| 'notice.group_decrease'
| 'notice.group_increase'

type RequestEvents = 'request.friend'
export type RequestEvents = 'request.friend'
| 'request.group.add'
| 'request.group.invite'
// node
| 'request.group'

type MetaEvents = 'meta_event.lifecycle'
export type MetaEvents = 'meta_event.lifecycle'
| 'meta_event.heartbeat'

type SocketEvents = 'socket.connecting'
export type SocketEvents = 'socket.connecting'
| 'socket.connect'
| 'socket.failed'
| 'socket.reconnecting'
Expand All @@ -79,17 +79,17 @@ type SocketEvents = 'socket.connecting'
| 'socket.close'
| 'socket.error'

type APIEvents = 'api.send.pre' | 'api.send.post' | 'api.response'
export type APIEvents = 'api.send.pre' | 'api.send.post' | 'api.response'

type Events = BaseEvents | MessageEvents | NoticeEvents | RequestEvents | SocketEvents | APIEvents
export type Events = BaseEvents | MessageEvents | NoticeEvents | RequestEvents | SocketEvents | APIEvents

type ListenerReturn = void | Promise<void>
type ArrayMessage = (CQTag|CQHTTPMessage|string)[]
type MessageListenerReturn = ListenerReturn | string | Promise<string> | ArrayMessage | Promise<ArrayMessage>
type MessageEventListener = (event: CQEvent, context: Record<string, any>, tags: CQTag[]) => MessageListenerReturn
type ContextEventListener = (context: Record<string, any>) => ListenerReturn
type SocketEventListener = (type: WebSocketType, attempts: number) => ListenerReturn
type SocketExcludeType = 'socket.connect' | 'socket.closing' | 'socket.close' | 'socket.error'
export type ListenerReturn = void | Promise<void>
export type ArrayMessage = (CQTag|CQHTTPMessage|string)[]
export type MessageListenerReturn = ListenerReturn | string | Promise<string> | ArrayMessage | Promise<ArrayMessage> | Promise<void | string | ArrayMessage>
export type MessageEventListener = (event: CQEvent, context: Record<string, any>, tags: CQTag[]) => MessageListenerReturn
export type ContextEventListener = (context: Record<string, any>) => ListenerReturn
export type SocketEventListener = (type: WebSocketType, attempts: number) => ListenerReturn
export type SocketExcludeType = 'socket.connect' | 'socket.closing' | 'socket.close' | 'socket.error'

export interface APITimeoutError extends Error {
readonly req: APIRequest
Expand All @@ -111,7 +111,7 @@ export interface UnexpectedContextError extends Error {
readonly reason: string
}

declare class CQEvent {
export declare class CQEvent {
readonly messageFormat: "string" | "array"
stopPropagation (): void
getMessage (): string | ArrayMessage
Expand Down Expand Up @@ -183,14 +183,14 @@ export default CQWebSocket

/******************************************/

type Serializable = string | number | boolean
export type Serializable = string | number | boolean

interface CQHTTPMessage {
export interface CQHTTPMessage {
type: string
data: Record<string, string> | null
}

declare class CQTag {
export declare class CQTag {
readonly tagName: string
readonly data: Readonly<Record<string, Serializable>>
modifier: Record<string, Serializable>
Expand Down
2 changes: 1 addition & 1 deletion dist/cq-websocket.kaomojified.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cq-websocket.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CQWebSocket

# [2.1.0](https://github.com/momocow/node-cq-websocket/compare/v2.0.2...v2.1.0) (2020-01-31)


### Features

* add group_ban event ([928e257](https://github.com/momocow/node-cq-websocket/commit/928e257)), closes [#84](https://github.com/momocow/node-cq-websocket/issues/84)

## [2.0.2](https://github.com/momocow/node-cq-websocket/compare/v2.0.1...v2.0.2) (2019-07-23)


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cq-websocket",
"version": "2.0.2",
"version": "2.1.0",
"description": "A Node SDK for developing QQ chatbots based on WebSocket, which is depending on CoolQ and CQHTTP API plugin. ",
"engines": {
"cqhttp": "^4.5.0",
Expand Down

0 comments on commit d0c76d3

Please sign in to comment.