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,37 +1,37 @@
{
"name": "@revanced/bot-shared",
"type": "module",
"version": "0.1.0",
"description": "🙌🏻 Shared components for bots assisting ReVanced",
"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/shared"
},
"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": {
"bson": "^6.2.0",
"valibot": "^0.21.0",
"zod": "^3.22.4"
}
}
{
"name": "@revanced/bot-shared",
"type": "module",
"version": "0.1.0",
"description": "🙌🏻 Shared components for bots assisting ReVanced",
"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/shared"
},
"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": {
"bson": "^6.2.0",
"valibot": "^0.21.0",
"zod": "^3.22.4"
}
}

View File

@@ -19,9 +19,9 @@ enum DisconnectReason {
*/
ServerError,
/**
* The client had never connected to the server (**CLIENT-ONLY**)
* The client had never connected to the server (**CLIENT-ONLY**)
*/
NeverConnected
NeverConnected,
}
export default DisconnectReason
export default DisconnectReason

View File

@@ -4,8 +4,9 @@ const HumanizedDisconnectReason = {
[DisconnectReason.InvalidPacket]: 'has sent invalid packet',
[DisconnectReason.Generic]: 'has been disconnected for unknown reasons',
[DisconnectReason.TimedOut]: 'has timed out',
[DisconnectReason.ServerError]: 'has been disconnected due to an internal server error',
[DisconnectReason.NeverConnected]: 'had never connected to the server'
[DisconnectReason.ServerError]:
'has been disconnected due to an internal server error',
[DisconnectReason.NeverConnected]: 'had never connected to the server',
} as const satisfies Record<DisconnectReason, string>
export default HumanizedDisconnectReason
export default HumanizedDisconnectReason

View File

@@ -50,8 +50,8 @@ export enum ServerOperation {
/**
* Server's disconnect message
*/
Disconnect = 20
Disconnect = 20,
}
export const Operation = { ...ClientOperation, ...ServerOperation } as const
export type Operation = (ClientOperation | ServerOperation)
export type Operation = ClientOperation | ServerOperation

View File

@@ -1,3 +1,3 @@
export { default as DisconnectReason } from './DisconnectReason.js'
export { default as HumanizedDisconnectReason } from './HumanizedDisconnectReason.js'
export * from './Operation.js'
export * from './Operation.js'

View File

@@ -1,3 +1,3 @@
export * from './constants/index.js'
export * from './schemas/index.js'
export * from './utils/index.js'
export * from './utils/index.js'

View File

@@ -1 +1 @@
export * from './Packet.js'
export * from './Packet.js'

View File

@@ -1,5 +1,9 @@
import { Packet } from '../schemas/Packet.js'
import { ClientOperation, Operation, ServerOperation } from '../constants/Operation.js'
import {
ClientOperation,
Operation,
ServerOperation,
} from '../constants/Operation.js'
/**
* Checks whether a packet is trying to do the given operation
@@ -7,7 +11,10 @@ import { ClientOperation, Operation, ServerOperation } from '../constants/Operat
* @param packet A packet
* @returns Whether this packet is trying to do the operation given
*/
export function packetMatchesOperation<TOp extends Operation>(op: TOp, packet: Packet): packet is Packet<TOp> {
export function packetMatchesOperation<TOp extends Operation>(
op: TOp,
packet: Packet
): packet is Packet<TOp> {
return packet.op === op
}
@@ -16,7 +23,9 @@ export function packetMatchesOperation<TOp extends Operation>(op: TOp, packet: P
* @param packet A packet
* @returns Whether this packet is a client packet
*/
export function isClientPacket(packet: Packet): packet is Packet<ClientOperation> {
export function isClientPacket(
packet: Packet
): packet is Packet<ClientOperation> {
return packet.op in ClientOperation
}
@@ -25,6 +34,8 @@ export function isClientPacket(packet: Packet): packet is Packet<ClientOperation
* @param packet A packet
* @returns Whether this packet is a server packet
*/
export function isServerPacket(packet: Packet): packet is Packet<ServerOperation> {
export function isServerPacket(
packet: Packet
): packet is Packet<ServerOperation> {
return packet.op in ServerOperation
}
}

View File

@@ -20,4 +20,4 @@ export function serializePacket<TOp extends Operation>(packet: Packet<TOp>) {
export function deserializePacket(buffer: Buffer) {
const data = BSON.deserialize(buffer)
return parse(PacketSchema, data) as Packet
}
}

View File

@@ -1,3 +1,3 @@
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
return str.charAt(0).toLowerCase() + str.slice(1) as Uncapitalize<T>
}
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>
}

View File

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