54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/**
|
|
* Transient State Schemas - SINGLE SOURCE OF TRUTH
|
|
*
|
|
* Define transient fields here ONCE. Both TypeScript types and runtime operations
|
|
* derive from these schemas, ensuring DRY compliance.
|
|
*
|
|
* To add a new transient field:
|
|
* 1. Add it to the appropriate schema below
|
|
* 2. That's it! All preserve/restore/strip operations automatically include it
|
|
*/
|
|
|
|
/**
|
|
* Transient Session Fields Schema
|
|
* These fields are never persisted to the database
|
|
*/
|
|
export const TRANSIENT_SESSION_SCHEMA = {
|
|
ws: undefined as any,
|
|
short: undefined as string | undefined,
|
|
keepAlive: undefined as NodeJS.Timeout | undefined,
|
|
pingInterval: undefined as NodeJS.Timeout | undefined,
|
|
lastPong: undefined as number | undefined,
|
|
initialSnapshotSent: undefined as boolean | undefined,
|
|
_getBatch: undefined as { fields: Set<string>; timer?: any } | undefined,
|
|
_pendingMessage: undefined as any,
|
|
_pendingTimeout: undefined as any,
|
|
live: false as boolean,
|
|
hasAudio: undefined as boolean | undefined,
|
|
audio: undefined as any,
|
|
video: undefined as any,
|
|
ping: undefined as number | undefined,
|
|
};
|
|
|
|
/**
|
|
* Transient Game Fields Schema
|
|
* These fields are never persisted to the database
|
|
*/
|
|
export const TRANSIENT_GAME_SCHEMA = {
|
|
turnTimer: undefined as any,
|
|
unselected: undefined as any[] | undefined,
|
|
};
|
|
|
|
// Derive runtime key arrays from schemas
|
|
export const TRANSIENT_SESSION_KEYS = Object.keys(TRANSIENT_SESSION_SCHEMA) as (keyof typeof TRANSIENT_SESSION_SCHEMA)[];
|
|
export const TRANSIENT_GAME_KEYS = Object.keys(TRANSIENT_GAME_SCHEMA) as (keyof typeof TRANSIENT_GAME_SCHEMA)[];
|
|
|
|
// Export TypeScript types derived from schemas
|
|
export type TransientSessionState = {
|
|
[K in keyof typeof TRANSIENT_SESSION_SCHEMA]?: typeof TRANSIENT_SESSION_SCHEMA[K];
|
|
};
|
|
|
|
export type TransientGameState = {
|
|
[K in keyof typeof TRANSIENT_GAME_SCHEMA]?: typeof TRANSIENT_GAME_SCHEMA[K];
|
|
};
|