// Friendly names over the GENERATED contract schema: everything below aliases `schema.ts`, // which openapi-typescript produces from `docs/api-contract/openapi.yaml`. // // Screens still run on `types.ts`, a working hypothesis that predates the contract. Moving them // onto these types and deleting `types.ts` is S3 work, gated on ratification of the spec. import type { components } from './schema'; type Schemas = components['schemas']; export type Library = Schemas['Library']; export type Book = Schemas['Book']; export type BookDetail = Schemas['BookDetail']; export type BookStatus = Schemas['BookStatus']; export type Progress = Schemas['Progress']; export type Run = Schemas['Run']; export type Chapter = Schemas['Chapter']; export type ChapterList = Schemas['ChapterList']; export type Unit = Schemas['Unit']; export type UnitState = Schemas['UnitState']; export type Note = Schemas['Note']; export type NoteSeverity = Schemas['NoteSeverity']; export type BankTerm = Schemas['BankTerm']; export type TermKind = Schemas['TermKind']; export type TermStatus = Schemas['TermStatus']; export type TermOrigin = Schemas['TermOrigin']; export type BankDecision = Schemas['BankDecision']; export type Problem = Schemas['Problem']; /** * Seam for a value that came off the wire. The generator turns `enum` into a CLOSED union, yet a * value outside the vocabulary is legal under a minor bump, and the typechecker does not catch * it: indexing a `Record` by a finite union compiles silently. An unknown value gets `null` here * instead of blowing up on `undefined.tone` inside a component. */ export function known(vocabulary: readonly T[], value: string): T | null { return (vocabulary as readonly string[]).includes(value) ? (value as T) : null; } /** Version 0.1 vocabularies, listed for `known()`. They grow with the schema, not instead of it. */ export const bookStatuses = [ 'uploading', 'parsing', 'not_started', 'translating', 'awaiting_bank', 'finalizing', 'ready', 'stopped', 'rejected', 'failed', ] as const satisfies readonly BookStatus[]; export const unitStates = [ 'translated', 'withheld', 'pending', ] as const satisfies readonly UnitState[]; export const noteSeverities = ['attention', 'glance'] as const satisfies readonly NoteSeverity[]; export const termKinds = [ 'name', 'place', 'title', 'term', 'nickname', ] as const satisfies readonly TermKind[]; export const termStatuses = ['auto', 'draft', 'approved'] as const satisfies readonly TermStatus[]; export const termOrigins = ['seed', 'ruby', 'mined'] as const satisfies readonly TermOrigin[];