goals.schema.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * goals domain zod schemas. Mutation-only shapes: every value schema is a
  3. * `{ ref }` acknowledgement (clear: `{ cleared }`) — the current goal state
  4. * travels exclusively on the 'goal' session projection.
  5. */
  6. import { z } from 'zod'
  7. import type { Wire } from './rpc.schema.ts'
  8. import type { GoalRef, RequestPayload, ResponseValue } from './index.ts'
  9. /** GoalRef schema. */
  10. export const goalRefSchema = z.object({
  11. id: z.string(),
  12. revision: z.number().int().positive(),
  13. }) as unknown as z.ZodType<Wire<GoalRef>>
  14. /** Shared `{ ref }` acknowledgement value of every non-clear mutation. */
  15. const goalRefValueSchema = z.object({ ref: goalRefSchema })
  16. /** goal.create request payload. */
  17. export const goalCreateRequestSchema = z.object({
  18. sessionId: z.string(),
  19. objective: z.string().min(1),
  20. maxGoalRounds: z.number().int().positive().optional(),
  21. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.create'>>>
  22. /** goal.create response value. */
  23. export const goalCreateValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.create'>>>
  24. /** goal.edit request payload. */
  25. export const goalEditRequestSchema = z.object({
  26. sessionId: z.string(),
  27. ref: goalRefSchema,
  28. objective: z.string().min(1).optional(),
  29. maxGoalRounds: z.number().int().positive().optional(),
  30. }).refine(value => value.objective !== undefined || value.maxGoalRounds !== undefined, {
  31. message: 'goal.edit requires objective or maxGoalRounds',
  32. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.edit'>>>
  33. /** goal.edit response value. */
  34. export const goalEditValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.edit'>>>
  35. /** goal.pause request payload. */
  36. export const goalPauseRequestSchema = z.object({
  37. sessionId: z.string(),
  38. ref: goalRefSchema,
  39. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.pause'>>>
  40. /** goal.pause response value. */
  41. export const goalPauseValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.pause'>>>
  42. /** goal.resume request payload. */
  43. export const goalResumeRequestSchema = z.object({
  44. sessionId: z.string(),
  45. ref: goalRefSchema,
  46. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.resume'>>>
  47. /** goal.resume response value. */
  48. export const goalResumeValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.resume'>>>
  49. /** goal.complete request payload. */
  50. export const goalCompleteRequestSchema = z.object({
  51. sessionId: z.string(),
  52. ref: goalRefSchema,
  53. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.complete'>>>
  54. /** goal.complete response value. */
  55. export const goalCompleteValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.complete'>>>
  56. /** goal.clear request payload. */
  57. export const goalClearRequestSchema = z.object({
  58. sessionId: z.string(),
  59. ref: goalRefSchema,
  60. }) as unknown as z.ZodType<Wire<RequestPayload<'goal.clear'>>>
  61. /** goal.clear response value. */
  62. export const goalClearValueSchema = z.object({
  63. cleared: z.literal(true),
  64. }) as unknown as z.ZodType<Wire<ResponseValue<'goal.clear'>>>