chore: format and remove unneccessary code

This commit is contained in:
PalmDevs
2023-11-25 22:45:27 +07:00
parent 72adec51b4
commit 306f627cef
39 changed files with 690 additions and 647 deletions

View File

@@ -1,40 +1,40 @@
{
"name": "@revanced/bot-api",
"type": "module",
"version": "0.1.0",
"description": "🙌🏻 Programmatic API for bots assisting ReVanced to communicate to its API server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "bun bundle && bun types",
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
"bundle:watch": "bun run bundle --watch",
"types": "tsc --declaration --emitDeclarationOnly",
"types:watch": "bun types --watch --preserveWatchOutput",
"types:clean": "bun types --build --clean"
},
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git",
"directory": "packages/api"
},
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
"contributors": [
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
],
"license": "GPL-3.0-or-later",
"bugs": {
"url": "https://github.com/revanced/revanced-helper/issues"
},
"homepage": "https://github.com/revanced/revanced-helper#readme",
"dependencies": {
"@revanced/bot-shared": "workspace:*",
"ws": "^8.14.2"
},
"devDependencies": {
"@types/ws": "^8.5.10",
"typed-emitter": "^2.1.0"
}
}
{
"name": "@revanced/bot-api",
"type": "module",
"version": "0.1.0",
"description": "🙌🏻 Programmatic API for bots assisting ReVanced to communicate to its API server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "bun bundle && bun types",
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
"bundle:watch": "bun run bundle --watch",
"types": "tsc --declaration --emitDeclarationOnly",
"types:watch": "bun types --watch --preserveWatchOutput",
"types:clean": "bun types --build --clean"
},
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git",
"directory": "packages/api"
},
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
"contributors": [
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
],
"license": "GPL-3.0-or-later",
"bugs": {
"url": "https://github.com/revanced/revanced-helper/issues"
},
"homepage": "https://github.com/revanced/revanced-helper#readme",
"dependencies": {
"@revanced/bot-shared": "workspace:*",
"ws": "^8.14.2"
},
"devDependencies": {
"@types/ws": "^8.5.10",
"typed-emitter": "^2.1.0"
}
}

View File

@@ -49,7 +49,9 @@ export default class Client {
rs(packet)
}
const parseTextFailedListener = (packet: Packet<ServerOperation.ParseTextFailed>) => {
const parseTextFailedListener = (
packet: Packet<ServerOperation.ParseTextFailed>
) => {
if (packet.d.id !== currentId) return
this.gateway.off('parseTextFailed', parseTextFailedListener)
rj(packet)
@@ -84,7 +86,9 @@ export default class Client {
rs(packet)
}
const parseImageFailedListener = (packet: Packet<ServerOperation.ParseImageFailed>) => {
const parseImageFailedListener = (
packet: Packet<ServerOperation.ParseImageFailed>
) => {
if (packet.d.id !== currentId) return
this.gateway.off('parseImageFailed', parseImageFailedListener)
rj(packet)

View File

@@ -24,8 +24,7 @@ export default class ClientGateway {
#hbTimeout: NodeJS.Timeout = null!
#socket: WebSocket = null!
#emitter =
new EventEmitter() as TypedEmitter<ClientGatewayEventHandlers>
#emitter = new EventEmitter() as TypedEmitter<ClientGatewayEventHandlers>
constructor(options: ClientGatewayOptions) {
this.url = options.url
@@ -110,6 +109,7 @@ export default class ClientGateway {
switch (packet.op) {
case ServerOperation.Hello:
// eslint-disable-next-line no-case-declarations
const data = Object.freeze(
(packet as Packet<ServerOperation.Hello>).d
)
@@ -124,9 +124,11 @@ export default class ClientGateway {
default:
return this.#emitter.emit(
uncapitalize(
ServerOperation[packet.op] as ClientGatewayServerEventName
ServerOperation[
packet.op
] as ClientGatewayServerEventName
),
// @ts-expect-error
// @ts-expect-error TypeScript doesn't know that the lines above negate the type enough
packet
)
}

View File

@@ -1,4 +1,4 @@
export { default as Client } from './Client.js'
export * from './Client.js'
export { default as ClientGateway } from './ClientGateway.js'
export * from './ClientGateway.js'
export * from './ClientGateway.js'

View File

@@ -5,7 +5,7 @@
"rootDir": "./src",
"outDir": "dist",
"module": "ESNext",
"composite": true,
"composite": true
},
"exclude": ["node_modules", "dist"]
}
}

View File

@@ -1 +1 @@
type RequiredProperty<T> = { [P in keyof T]: Required<NonNullable<T[P]>>; };
type RequiredProperty<T> = { [P in keyof T]: Required<NonNullable<T[P]>> }