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

Commit

Permalink
fix: Fix typing (#87) and upgrade dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
momocow committed Mar 23, 2020
1 parent 04ed2ec commit bbb54ad
Show file tree
Hide file tree
Showing 3 changed files with 3,885 additions and 2,475 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.@'
| 'message.discuss.@.me'
| 'message.group'
| 'message.group.@'
| 'message.group.@.me'

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
Loading

0 comments on commit bbb54ad

Please sign in to comment.