feat(packages): add shared package

This commit is contained in:
PalmDevs
2023-11-24 23:03:24 +07:00
parent e4dbbfd68c
commit abf532704f
14 changed files with 1015 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/**
* Disconnect reasons for clients
*/
enum DisconnectReason {
/**
* Unknown reason
*/
Generic = 1,
/**
* The client did not respond in time
*/
TimedOut,
/**
* The client sent an invalid packet (unserializable or invalid JSON)
*/
InvalidPacket,
/**
* The server has encountered an internal error
*/
ServerError,
/**
* The client had never connected to the server (**CLIENT-ONLY**)
*/
NeverConnected
}
export default DisconnectReason

View File

@@ -0,0 +1,11 @@
import DisconnectReason from './DisconnectReason.js'
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'
} as const satisfies Record<DisconnectReason, string>
export default HumanizedDisconnectReason

View File

@@ -0,0 +1,57 @@
/**
* Client operation codes for the gateway
*/
export enum ClientOperation {
/**
* Client's heartbeat (to check if the connection is dead or not)
*/
Heartbeat = 100,
/**
* Client's request to parse text
*/
ParseText = 110,
/**
* Client's request to parse image
*/
ParseImage,
}
/**
* Server operation codes for the gateway
*/
export enum ServerOperation {
/**
* Server's acknowledgement of a client's heartbeat
*/
HeartbeatAck = 1,
/**
* Server's initial response to a client's connection
*/
Hello,
/**
* Server's response to client's request to parse text
*/
ParsedText = 10,
/**
* Server's response to client's request to parse image
*/
ParsedImage,
/**
* Server's failure response to client's request to parse text
*/
ParseTextFailed,
/**
* Server's failure response to client's request to parse image
*/
ParseImageFailed,
/**
* Server's disconnect message
*/
Disconnect = 20
}
export const Operation = { ...ClientOperation, ...ServerOperation } as const
export type Operation = (ClientOperation | ServerOperation)

View File

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