import {z} from 'zod' export type GetApiRestV1HoldingsUnreleasedArgs = {ids: string}; export type GetApiRestV1HoldingsUnreleasedOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const rcsbRepositoryHoldingsPrerelease = z.object({entity_id: z.string(), seq_one_letter_code: z.string().optional()}); export const rcsbRepositoryHoldingsUnreleased = z.object({audit_authors: z.array(z.string()).optional(), author_prerelease_sequence_status: z.enum(["HOLD FOR PUBLICATION", "HOLD FOR RELEASE", "RELEASE IMMEDIATELY", "RELEASE NOW"]).optional(), deposit_date: z.string().optional(), deposit_date_coordinates: z.string().optional(), deposit_date_nmr_restraints: z.string().optional(), deposit_date_structure_factors: z.string().optional(), hold_date_coordinates: z.string().optional(), hold_date_nmr_restraints: z.string().optional(), hold_date_structure_factors: z.string().optional(), prerelease_sequence_available_flag: z.enum(["N", "Y"]).optional(), release_date: z.string().optional(), status_code: z.enum(["AUCO", "AUTH", "HOLD", "HPUB", "POLC", "PROC", "REFI", "REPL", "WAIT", "WDRN"]).optional(), title: z.string().optional()}); export const rcsbRepositoryHoldingsUnreleasedEntryContainerIdentifiers = z.object({entry_id: z.string(), rcsb_id: z.string().optional(), update_id: z.string().optional()}); export const unreleasedEntry = z.object({rcsb_repository_holdings_prerelease: z.array(rcsbRepositoryHoldingsPrerelease).optional(), rcsb_repository_holdings_unreleased: rcsbRepositoryHoldingsUnreleased.optional(), rcsb_repository_holdings_unreleased_entry_container_identifiers: rcsbRepositoryHoldingsUnreleasedEntryContainerIdentifiers.optional(), rcsb_id: z.string()}); export const getApiRestV1HoldingsUnreleasedResponse = z.array(unreleasedEntry); 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 }; /** * Get a list of unreleased structures with descriptions. * * GET /rest/v1/holdings/unreleased */ export const getApiRestV1HoldingsUnreleased = async (args: GetApiRestV1HoldingsUnreleasedArgs, options: GetApiRestV1HoldingsUnreleasedOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;charset=utf-8") if (args.ids != null) query.append("ids", String(args.ids)) const url = `${baseUrl.replace(/\/+$/, '')}/rest/v1/holdings/unreleased${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiRestV1HoldingsUnreleasedResponse, await res.json()) };