Updated typings

Removed I from interfaces.
Renamed interfaces to be more clear.
Added TODO: Create typings on protodef to define here.
Added supportedVersions static strings.
Rearranged order of exports and properties.
Changed unused returns of functions from any to void (More strict).
Put entire typings inside module declaration.

Now works in strict mode.
Suggestion: Add typings to protodef so createSerializer and createDeserializer have valid types.
This commit is contained in:
Shayne Hartford 2018-10-03 07:37:19 -04:00 committed by GitHub
parent eac4f3d8ac
commit 566b766f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

200
src/index.d.ts vendored
View File

@ -1,113 +1,114 @@
import {Socket} from 'net'
import { EventEmitter } from 'events';
import { Socket } from 'net'
import * as Stream from 'stream'
import EventEmitter = NodeJS.EventEmitter
declare enum EnumStates {
HANDSHAKING = 'handshaking',
STATUS = 'status',
LOGIN = 'login',
PLAY = 'play',
}
export interface IPacketMeta {
name: string
state: EnumStates
}
export declare class Client extends EventEmitter {
declare module 'minecraft-protocol' {
export class Client extends EventEmitter {
constructor(isServer: boolean, version: string, customPackets?: any)
write(name: string, params: any)
end(reason: string)
state: EnumStates
isServer: boolean
socket: Socket
uuid: string
username: string
session: any
profile: any
latency: number
on(event: 'packet', handler: (data: any, packetMeta: IPacketMeta) => any)
on(event: 'raw', handler: (data: any, packetMeta: IPacketMeta) => any)
on(event: 'state', handler: (newState: EnumStates, oldState: EnumStates) => any)
on(event: 'session', handler: (session: any) => any)
writeChannel(channel: any, params: any)
registerChannel(name: string, typeDefinition: any, custom?: boolean)
unregisterChannel(name: string)
}
profile: any
session: any
socket: Socket
state: States
username: string
uuid: string
end(reason: string): void
registerChannel(name: string, typeDefinition: any, custom?: boolean): void
unregisterChannel(name: string): void
write(name: string, params: any): void
writeChannel(channel: any, params: any): void
on(event: 'packet', handler: (data: any, packetMeta: PacketMeta) => void): this
on(event: 'raw', handler: (data: any, packetMeta: PacketMeta) => void): this
on(event: 'session', handler: (session: any) => void): this
on(event: 'state', handler: (newState: States, oldState: States) => void): this
}
interface IClientsMap {
[key: string]: Client
}
export interface ClientOptions {
accessToken?: string
checkTimeoutInterval?: number
clientToken?: string
customPackets?: any
hideErrors?: boolean
host?: string
keepAlive?: boolean
password?: string
port?: number
username: string
version?: string
}
export declare class Server extends EventEmitter {
export class Server extends EventEmitter {
constructor(version: string, customPackets?: any)
onlineModeExceptions: object
clients: IClientsMap
playerCount: number
clients: ClientsMap
favicon: string
maxPlayers: number
motd: string
favicon: string
on(event: 'connection', handler: (client: Client) => any)
on(event: 'login', handler: (client: Client) => any)
}
onlineModeExceptions: object
playerCount: number
on(event: 'connection', handler: (client: Client) => void): this
on(event: 'login', handler: (client: Client) => void): this
}
export interface ICreateServerOptions {
host?: string
port?: number
kickTimeout?: number
checkTimeoutInterval?: number
export interface ServerOptions {
'online-mode'?: boolean
motd?: string
maxPlayers?: number
keepAlive?: boolean
version?: string
customPackets?: any
stream?: Stream
beforePing?: (response: any, client: Client, callback?: (result: any) => any) => any
errorHandler?: (client: Client, error: Error) => any
connect?: (client: Client) => any
hideErrors?: boolean
}
export interface ICreateClientOptions {
username: string
port?: number
password?: string
host?: string
clientToken?: string
accessToken?: string
keepAlive?: boolean
checkTimeoutInterval?: number
version?: string
customPackets?: any
hideErrors?: boolean
}
export interface ICreateSerializerOptions {
state?: EnumStates
isServer?: boolean
version: string
customPackets: any
}
export interface IPingOptions {
host?: string
keepAlive?: boolean
kickTimeout?: number
maxPlayers?: number
motd?: string
port?: number
stream?: Stream
version?: string
majorVersion?: string
protocolVersion?: string
}
beforePing?: (response: any, client: Client, callback?: (result: any) => any) => any
connect?: (client: Client) => void
errorHandler?: (client: Client, error: Error) => void
}
export interface IPingOldResult {
export interface SerializerOptions {
customPackets: any
isServer?: boolean
state?: States
version: string
}
enum States {
HANDSHAKING = 'handshaking',
LOGIN = 'login',
PLAY = 'play',
STATUS = 'status',
}
export interface PacketMeta {
name: string
state: States
}
interface ClientsMap {
[key: string]: Client
}
export interface PingOptions {
host?: string
majorVersion?: string
port?: number
protocolVersion?: string
version?: string
}
export interface OldPingResult {
maxPlayers: number,
motd: string
playerCount: number
prefix: string
protocol: string
version: string
motd: string
playerCount: number
maxPlayers: number,
}
}
export interface IPingNewResult {
export interface NewPingResult {
description: string
players: {
max: number
@ -123,16 +124,17 @@ export interface IPingNewResult {
}
favicon: string
latency: number
}
export const state: States
export const supportedVersions: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.1']
export function createServer(options: ServerOptions): Server
export function createClient(options: ClientOptions): Client
// TODO: Create typings on protodef to define here
export function createSerializer({ state, isServer, version, customPackets }: SerializerOptions): any
export function createDeserializer({ state, isServer, version, customPackets }: SerializerOptions): any
export function ping(options: PingOptions, callback: (error: Error, result: OldPingResult | NewPingResult) => void): void
}
export declare function createServer(options: ICreateServerOptions): Server
export declare function createClient(options: ICreateClientOptions): Client
export const state: EnumStates
export declare function createSerializer({state, isServer, version, customPackets}: ICreateSerializerOptions)
export declare function createDeserializer({state, isServer, version, customPackets}: ICreateSerializerOptions)
export declare function ping(options: IPingOptions, callback: (err: Error, result: IPingOldResult | IPingNewResult) => any);
export const supportedVersions: string[]