import {z} from 'zod' export type NotificationConfig = {pubsubTopic?: string | undefined, sendForBulkImport?: boolean | undefined}; export type DicomNotificationConfig = {pubsubTopic?: string | undefined}; export type SchemaFlattened = Record; export type SchemaJSON = Record; export type GoogleCloudHealthcareV1DicomBigQueryDestination = {force?: boolean | undefined, includeSourceStore?: boolean | undefined, schemaFlattened?: SchemaFlattened | undefined, schemaJson?: SchemaJSON | undefined, tableUri?: string | undefined, writeDisposition?: ('WRITE_DISPOSITION_UNSPECIFIED' | 'WRITE_EMPTY' | 'WRITE_TRUNCATE' | 'WRITE_APPEND') | undefined}; export type GoogleCloudHealthcareV1DicomStreamConfig = {bigqueryDestination?: GoogleCloudHealthcareV1DicomBigQueryDestination | undefined}; export type DicomStore = {labels?: {[key: string]: string} | undefined, name?: string | undefined, notificationConfig?: NotificationConfig | undefined, notificationConfigs?: Array | undefined, streamConfigs?: Array | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDicomStoresArgs = {projectsId: string, locationsId: string, datasetsId: string, dicomStoreId?: string | undefined, body: DicomStore}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDicomStoresOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationConfig = z.object({pubsubTopic: z.string().optional(), sendForBulkImport: z.boolean().optional()}); export const dicomNotificationConfig = z.object({pubsubTopic: z.string().optional()}); export const schemaFlattened = z.object({}); export const schemaJSON = z.object({}); export const googleCloudHealthcareV1DicomBigQueryDestination = z.object({force: z.boolean().optional(), includeSourceStore: z.boolean().optional(), schemaFlattened: schemaFlattened.optional(), schemaJson: schemaJSON.optional(), tableUri: z.string().optional(), writeDisposition: z.enum(["WRITE_DISPOSITION_UNSPECIFIED", "WRITE_EMPTY", "WRITE_TRUNCATE", "WRITE_APPEND"]).optional()}); export const googleCloudHealthcareV1DicomStreamConfig = z.object({bigqueryDestination: googleCloudHealthcareV1DicomBigQueryDestination.optional()}); export const dicomStore = z.object({labels: z.record(z.string(), z.string()).optional(), name: z.string().optional(), notificationConfig: notificationConfig.optional(), notificationConfigs: z.array(dicomNotificationConfig).optional(), streamConfigs: z.array(googleCloudHealthcareV1DicomStreamConfig).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 }; /** * Creates a new DICOM store within the parent dataset. * * POST /v1/projects/{projectsId}/locations/{locationsId}/datasets/{datasetsId}/dicomStores * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDicomStores = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDicomStoresArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDicomStoresOptions) => { const {baseUrl = "https://healthcare.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dicomStoreId != null) query.append("dicomStoreId", String(args.dicomStoreId)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/datasets/${encodeURIComponent(String(args.datasetsId))}/dicomStores${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(dicomStore, await res.json()) };