import {z} from 'zod' export type ApiKeywordMatch = {id?: string | undefined, name?: string | undefined, keyword?: string | undefined, category?: (Array<'GENERAL' | 'SOLID_TUMOR' | 'HEMATO' | 'NON_NEOPLASTIC' | 'SEERRX' | 'SEER_TRAINING' | 'LYMPH_NODES' | 'STAGING'>) | undefined, start?: number | undefined, end?: number | undefined}; export type GlossaryResource = {name?: string | undefined, subtitle?: string | undefined, reference_type?: string | undefined, url?: string | undefined, edition?: string | undefined, year?: string | undefined, page?: string | undefined, citation?: string | undefined}; export type Glossary = {id?: string | undefined, name?: string | undefined, version?: string | undefined, hidden?: boolean | undefined, status?: string | undefined, assigned_to?: string | undefined, first_published?: string | undefined, last_modified?: string | undefined, fingerprint?: string | undefined, note?: string | undefined, field_notes?: {[key: string]: string} | undefined, score?: number | undefined, glossary?: Array | undefined, definition?: string | undefined, alternate_name?: Array | undefined, abstractor_note?: string | undefined, histology?: Array | undefined, primary_site?: Array | undefined, category?: (Array<'GENERAL' | 'SOLID_TUMOR' | 'HEMATO' | 'NON_NEOPLASTIC' | 'SEERRX' | 'SEER_TRAINING' | 'LYMPH_NODES' | 'STAGING'>) | undefined, subcategory?: Array | undefined, resource?: Array | undefined}; export type UpdateApiRestGlossaryVersionUpdateArgs = {version: string, body: Glossary}; export type UpdateApiRestGlossaryVersionUpdateOptions = {baseUrl?: string | undefined, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; export const apiKeywordMatch = z.object({id: z.string().optional(), name: z.string().optional(), keyword: z.string().optional(), category: z.array(z.enum(["GENERAL", "SOLID_TUMOR", "HEMATO", "NON_NEOPLASTIC", "SEERRX", "SEER_TRAINING", "LYMPH_NODES", "STAGING"])).optional(), start: z.number().int().optional(), end: z.number().int().optional()}); export const glossaryResource = z.object({name: z.string().optional(), subtitle: z.string().optional(), reference_type: z.string().optional(), url: z.string().optional(), edition: z.string().optional(), year: z.string().optional(), page: z.string().optional(), citation: z.string().optional()}); export const glossary = z.object({id: z.string().optional(), name: z.string().optional(), version: z.string().optional(), hidden: z.boolean().optional(), status: z.string().optional(), assigned_to: z.string().optional(), first_published: z.string().optional(), last_modified: z.string().optional(), fingerprint: z.string().optional(), note: z.string().optional(), field_notes: z.record(z.string(), z.string()).optional(), score: z.number().optional(), glossary: z.array(apiKeywordMatch).optional(), definition: z.string().optional(), alternate_name: z.array(z.string()).optional(), abstractor_note: z.string().optional(), histology: z.array(z.string()).optional(), primary_site: z.array(z.string()).optional(), category: z.array(z.enum(["GENERAL", "SOLID_TUMOR", "HEMATO", "NON_NEOPLASTIC", "SEERRX", "SEER_TRAINING", "LYMPH_NODES", "STAGING"])).optional(), subcategory: z.array(z.string()).optional(), resource: z.array(glossaryResource).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a glossary entry * * PUT /rest/glossary/{version}/update */ export const updateApiRestGlossaryVersionUpdate = async (args: UpdateApiRestGlossaryVersionUpdateArgs, options?: UpdateApiRestGlossaryVersionUpdateOptions) => { const {baseUrl = "https://api.seer.cancer.gov", fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyScheme !== undefined) headers.set("X-SEERAPI-Key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/rest/glossary/${encodeURIComponent(String(args.version))}/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(glossary, await res.json()) };