game-session-api-shema.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { z } from "zod";
  2. import { ZGameSessionShema, ZSpecificGame } from "../game-session-shema.js";
  3. import { DbShema } from "../db-shema.js";
  4. import { GameShema } from "../game-shema.js";
  5. class GameSessionApiShema {
  6. //
  7. // z.object({
  8. // sessionId: ZGameSessionShema.shape.sessionId,
  9. // players: ZGameSessionShema.shape.players,
  10. // sessionStart: z.string(),
  11. // sessionPlanEnd: z.string(),
  12. // sessionStage: ZGameSessionShema.shape.sessionStage,
  13. // currentGameIdx: ZGameSessionShema.shape.currentGameIdx,
  14. // games: ZGameSessionShema.shape.games,
  15. // });
  16. public ZMediaControlCommand = z.enum([
  17. "play",
  18. "pause",
  19. "mute",
  20. "unMute",
  21. "restart",
  22. ]);
  23. public ZSessionSubscribe = {
  24. res: z.object({
  25. isUnfinishedSession: z.boolean().optional(),
  26. session: ZGameSessionShema.nullish(),
  27. currentGame: ZSpecificGame.optional(),
  28. timer: z.number().nullish(),
  29. mediaControl: z
  30. .object({
  31. meidaPlayerId: z.string(),
  32. command: this.ZMediaControlCommand,
  33. currentTime: z.number().optional(),
  34. })
  35. .optional(),
  36. }),
  37. };
  38. public ZHistorySubscribe = {
  39. res: z.object({
  40. history: z.array(
  41. z.object({
  42. note_id: DbShema.ZHistoryNotes.shape.note_id,
  43. timestamp: DbShema.ZHistoryNotes.shape.timestamp,
  44. text: DbShema.ZHistoryNotes.shape.text,
  45. }),
  46. ),
  47. }),
  48. };
  49. public ZUpdatePlayerLate = {
  50. req: z.object({
  51. playerIdx: z.number(),
  52. newVal: z.boolean(),
  53. }),
  54. };
  55. public ZMediaControl = {
  56. req: z.object({
  57. meidaPlayerId: z.string(),
  58. command: this.ZMediaControlCommand,
  59. currentTime: z.number().optional(),
  60. }),
  61. };
  62. public ZChangeSessionStage = {
  63. req: z.object({
  64. stage: ZGameSessionShema.shape.sessionStage,
  65. }),
  66. };
  67. public ZChangeGameStage = {
  68. req: z.object({
  69. gameId: GameShema.Z_GAMES_TYPES,
  70. gameStage: GameShema.ZGame.shape.gameStage,
  71. }),
  72. };
  73. }
  74. export default new GameSessionApiShema();