feat(apis/websocket): return true for data on a TrainedMessage packet

This commit is contained in:
PalmDevs
2024-08-04 02:46:01 +07:00
parent 2c2f6b76d4
commit 65add4dfee
2 changed files with 7 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = asy
client.send( client.send(
{ {
op: ServerOperation.TrainedMessage, op: ServerOperation.TrainedMessage,
d: null, d: true,
}, },
nextSeq, nextSeq,
) )

View File

@@ -1,9 +1,9 @@
import { import {
url,
type AnySchema, type AnySchema,
type NullSchema, type NullSchema,
type ObjectSchema, type ObjectSchema,
type Output, type Output,
type BooleanSchema,
array, array,
enum_, enum_,
null_, null_,
@@ -11,6 +11,8 @@ import {
parse, parse,
special, special,
string, string,
boolean,
url,
// merge // merge
} from 'valibot' } from 'valibot'
import DisconnectReason from '../constants/DisconnectReason' import DisconnectReason from '../constants/DisconnectReason'
@@ -26,8 +28,7 @@ export const PacketSchema = special<Packet>(input => {
'op' in input && 'op' in input &&
typeof input.op === 'number' && typeof input.op === 'number' &&
input.op in Operation && input.op in Operation &&
'd' in input && 'd' in input
typeof input.d === 'object'
) { ) {
if (input.op in ServerOperation && !('s' in input && typeof input.s === 'number')) return false if (input.op in ServerOperation && !('s' in input && typeof input.s === 'number')) return false
@@ -62,7 +63,7 @@ export const PacketDataSchemas = {
[ServerOperation.Disconnect]: object({ [ServerOperation.Disconnect]: object({
reason: enum_(DisconnectReason), reason: enum_(DisconnectReason),
}), }),
[ServerOperation.TrainedMessage]: null_(), [ServerOperation.TrainedMessage]: boolean(),
[ServerOperation.TrainMessageFailed]: null_(), [ServerOperation.TrainMessageFailed]: null_(),
[ClientOperation.ParseText]: object({ [ClientOperation.ParseText]: object({
@@ -78,7 +79,7 @@ export const PacketDataSchemas = {
} as const satisfies Record< } as const satisfies Record<
Operation, Operation,
// biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it // biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it
ObjectSchema<any> | AnySchema | NullSchema ObjectSchema<any> | AnySchema | NullSchema | BooleanSchema
> >
export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation