import {z} from 'zod' export type SortOrder = string; export type FileItemListMetadata = {filter?: string | undefined, kind?: string | undefined, sort_order?: SortOrder | undefined, offset?: number | undefined, length?: number | undefined, sort_attribute?: string | undefined}; export type CreateApiFileStoreListArgs = {body: FileItemListMetadata}; export type CreateApiFileStoreListOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const availabilityZoneReference = z.object({kind: z.string(), name: z.string().optional(), uuid: z.string()}); export const messageResource = z.object({message: z.string(), reason: z.string(), details: z.record(z.string(), z.string()).optional()}); export const clusterReference = z.object({kind: z.string(), name: z.string().optional(), uuid: z.string()}); export const checksumAlgorithm = z.string(); export const checksum = z.object({checksum_algorithm: checksumAlgorithm, checksum_value: z.string()}); export const awsCredentials = z.object({access_key: z.string(), secret_key: z.string()}); export const credentials = z.object({username: z.string(), password: z.string().optional()}); export const sourceAuth = z.object({aws_auth: awsCredentials.optional(), basic_auth: credentials.optional()}); export const fileItemResourcesDefStatus = z.object({retrieval_uri_list: z.array(z.string()).optional(), checksum: checksum.optional(), source_uri: z.string().optional(), source_auth: sourceAuth.optional(), size_bytes: z.number().int().optional()}); export const fileItemDefStatus = z.object({state: z.string().optional(), name: z.string(), availability_zone_reference: availabilityZoneReference.optional(), message_list: z.array(messageResource).optional(), cluster_reference: clusterReference.optional(), resources: fileItemResourcesDefStatus, description: z.string().optional()}); export const fileItemResources = z.object({checksum: checksum.optional(), source_uri: z.string().optional(), source_auth: sourceAuth.optional()}); export const fileItem = z.object({description: z.string().max(1000).optional(), resources: fileItemResources, cluster_reference: clusterReference.optional(), name: z.string().max(64), availability_zone_reference: availabilityZoneReference.optional()}); export const userReference = z.object({kind: z.string(), name: z.string().optional(), uuid: z.string()}); export const fileItemMetadata = z.object({last_update_time: z.string().optional(), kind: z.string(), uuid: z.string().optional(), spec_version: z.number().int().optional(), creation_time: z.string().optional(), spec_hash: z.string().optional(), should_force_translate: z.boolean().optional(), owner_reference: userReference.optional(), categories: z.record(z.string(), z.string()).optional(), name: z.string().max(64).optional()}); export const fileItemIntentResource = z.object({status: fileItemDefStatus.optional(), spec: fileItem.optional(), api_version: z.string().optional(), metadata: fileItemMetadata}); export const sortOrder = z.string(); export const fileItemListMetadataOutput = z.object({filter: z.string().optional(), kind: z.string().optional(), sort_order: sortOrder.optional(), offset: z.number().int().optional(), total_matches: z.number().int().optional(), length: z.number().int().optional(), sort_attribute: z.string().optional()}); export const fileItemListIntentResponse = z.object({entities: z.array(fileItemIntentResource).optional(), api_version: z.string(), metadata: fileItemListMetadataOutput}); 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 file_items * * POST /file_store/list */ export const createApiFileStoreList = async (args: CreateApiFileStoreListArgs, options: CreateApiFileStoreListOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/file_store/list${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(fileItemListIntentResponse, await res.json()) };