Skip to content

Commit

Permalink
fix(element): add children types for jsx
Browse files Browse the repository at this point in the history
also re-add abstract websocket types
  • Loading branch information
shigma committed Feb 23, 2024
1 parent 3224f5d commit e476344
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Awaitable, remove, Time } from 'cosmokit'
import { Status } from '@satorijs/protocol'
import { WebSocket } from 'undios'
import { Status, WebSocket } from '@satorijs/protocol'
import { z } from 'cordis'
import { Context } from '.'
import { Bot } from './bot'
Expand Down
2 changes: 2 additions & 0 deletions packages/element/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ declare global {
message: {
id?: string
forward?: boolean
children?: any[]
}
quote: {
id?: string
name?: string
avatar?: string
children?: any[]
}
at: {
id?: string
Expand Down
57 changes: 57 additions & 0 deletions packages/protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,60 @@ export interface GatewayBody {
logins: Login[]
}
}

export namespace WebSocket {
/** The connection is not yet open. */
export const CONNECTING = 0
/** The connection is open and ready to communicate. */
export const OPEN = 1
/** The connection is in the process of closing. */
export const CLOSING = 2
/** The connection is closed. */
export const CLOSED = 3

export type ReadyState =
| typeof CONNECTING
| typeof OPEN
| typeof CLOSING
| typeof CLOSED

export interface EventMap {
open: Event
error: ErrorEvent
message: MessageEvent
close: CloseEvent
}

export interface EventListener {
(event: Event): void
}

export interface Event {
type: string
target: WebSocket
}

export interface CloseEvent extends Event {
code: number
reason: string
}

export interface MessageEvent extends Event {
data: string
}

export interface ErrorEvent extends Event {
message?: string
}
}

export interface WebSocket {
readonly url?: string
readonly protocol?: string
readonly readyState?: number
close(code?: number, reason?: string): void
send(data: string): void
dispatchEvent?(event: any): boolean
addEventListener<K extends keyof WebSocket.EventMap>(type: K, listener: (event: WebSocket.EventMap[K]) => void): void
removeEventListener<K extends keyof WebSocket.EventMap>(type: K, listener: (event: WebSocket.EventMap[K]) => void): void
}

0 comments on commit e476344

Please sign in to comment.