Set up API spec and basic components

This commit is contained in:
Ben Grant 2023-05-20 01:52:44 +10:00
parent 2adecd13f7
commit 61bd31eb7e
20 changed files with 353 additions and 26 deletions

View file

@ -0,0 +1,44 @@
// TODO: Write a simple rust crate that generates these from the OpenAPI spec
import { z } from 'zod'
if (process.env.NEXT_PUBLIC_API_URL === undefined) {
throw new Error('Expected API url environment variable')
}
export const API_BASE = new URL(process.env.NEXT_PUBLIC_API_URL)
export const EventInput = z.object({
name: z.string().optional(),
times: z.string().array(),
timezone: z.string(),
})
export type EventInput = z.infer<typeof EventInput>
export const EventResponse = z.object({
id: z.string(),
name: z.string(),
times: z.string().array(),
timezone: z.string(),
created_at: z.number(),
})
export type EventResponse = z.infer<typeof EventResponse>
export const PersonInput = z.object({
availability: z.string().array(),
})
export type PersonInput = z.infer<typeof PersonInput>
export const PersonResponse = z.object({
name: z.string(),
availability: z.string().array(),
created_at: z.number(),
})
export type PersonResponse = z.infer<typeof PersonResponse>
export const StatsResponse = z.object({
event_count: z.number(),
person_count: z.number(),
version: z.string(),
})
export type StatsResponse = z.infer<typeof StatsResponse>