chore(packages): add more docs and improve types

This commit is contained in:
PalmDevs
2023-11-25 23:01:49 +07:00
parent 306f627cef
commit a49f45127c
5 changed files with 91 additions and 36 deletions

View File

@@ -1,5 +1,8 @@
import DisconnectReason from './DisconnectReason.js'
/**
* Humanized disconnect reasons for logs
*/
const HumanizedDisconnectReason = {
[DisconnectReason.InvalidPacket]: 'has sent invalid packet',
[DisconnectReason.Generic]: 'has been disconnected for unknown reasons',

View File

@@ -44,33 +44,6 @@ export const PacketSchema = special<Packet>(input => {
return false
}, 'Invalid packet data')
// merge([
// object({
// op: nativeEnum(Operation, 'Not a valid operation number'),
// }),
// object({
// d: special<Packet['d']>(input => {
// if (
// typeof input === 'object' &&
// input &&
// 'op' in input &&
// typeof input.op === 'number' &&
// input.op in Operation &&
// 'd' in input &&
// typeof input.d === 'object'
// ) {
// try {
// PacketDataSchemas[input.op as Operation].parse(input)
// return true
// } catch {
// return false
// }
// }
// return false
// }, 'Invalid packet data'),
// }),
// ])
/**
* Schema to validate packet data for each possible operations
*/
@@ -118,6 +91,7 @@ export const PacketDataSchemas = {
}),
} as const satisfies Record<
Operation,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ObjectSchema<any> | AnySchema | NullSchema
>

View File

@@ -1,3 +1,8 @@
/**
* Uncapitalizes the first letter of a string
* @param str The string to uncapitalize
* @returns The uncapitalized string
*/
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>
}