import {z} from 'zod' export type RawDataFilterCategory = 'training' | 'testing' | 'validation' | 'post-processing' | 'all'; export type EditSampleLabelRequest = {label?: string | undefined}; export type CreateApiApiProjectIdRawDataBatchEditLabelsArgs = {projectId: number, category: RawDataFilterCategory, labels?: string | undefined, filename?: string | undefined, maxLength?: number | undefined, minLength?: number | undefined, minFrequency?: number | undefined, maxFrequency?: number | undefined, signatureValidity?: ('both' | 'valid' | 'invalid') | undefined, includeDisabled?: ('both' | 'enabled' | 'disabled') | undefined, ids?: string | undefined, excludeIds?: string | undefined, minLabel?: number | undefined, maxLabel?: number | undefined, search?: string | undefined, dataType?: ('audio' | 'image') | undefined, minId?: number | undefined, maxId?: number | undefined, metadata?: string | undefined, minDate?: string | undefined, maxDate?: string | undefined, body: EditSampleLabelRequest}; export type CreateApiApiProjectIdRawDataBatchEditLabelsOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const genericApiResponse = z.object({success: z.boolean(), error: z.string().optional()}); export const startJobResponse = z.object({success: z.boolean(), error: z.string().optional(), id: z.number().int()}); export const createApiApiProjectIdRawDataBatchEditLabelsResponse = z.union([genericApiResponse, startJobResponse]); 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 }; /** * Edit labels for multiple samples * * POST /api/{projectId}/raw-data/batch/edit-labels * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const createApiApiProjectIdRawDataBatchEditLabels = async (args: CreateApiApiProjectIdRawDataBatchEditLabelsArgs, options?: CreateApiApiProjectIdRawDataBatchEditLabelsOptions) => { const {baseUrl = "https://studio.edgeimpulse.com/v1", fetch: fetchFn = fetch, ApiKeyAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.category != null) query.append("category", String(args.category)) if (args.labels != null) query.append("labels", String(args.labels)) if (args.filename != null) query.append("filename", String(args.filename)) if (args.maxLength != null) query.append("maxLength", String(args.maxLength)) if (args.minLength != null) query.append("minLength", String(args.minLength)) if (args.minFrequency != null) query.append("minFrequency", String(args.minFrequency)) if (args.maxFrequency != null) query.append("maxFrequency", String(args.maxFrequency)) if (args.signatureValidity != null) query.append("signatureValidity", String(args.signatureValidity)) if (args.includeDisabled != null) query.append("includeDisabled", String(args.includeDisabled)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.excludeIds != null) query.append("excludeIds", String(args.excludeIds)) if (args.minLabel != null) query.append("minLabel", String(args.minLabel)) if (args.maxLabel != null) query.append("maxLabel", String(args.maxLabel)) if (args.search != null) query.append("search", String(args.search)) if (args.dataType != null) query.append("dataType", String(args.dataType)) if (args.minId != null) query.append("minId", String(args.minId)) if (args.maxId != null) query.append("maxId", String(args.maxId)) if (args.metadata != null) query.append("metadata", String(args.metadata)) if (args.minDate != null) query.append("minDate", String(args.minDate)) if (args.maxDate != null) query.append("maxDate", String(args.maxDate)) if (ApiKeyAuthentication !== undefined) headers.set("x-api-key", ApiKeyAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.projectId))}/raw-data/batch/edit-labels${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(createApiApiProjectIdRawDataBatchEditLabelsResponse, await res.json()) };