import {z} from 'zod' export type GetApiV2EntityIngestionConfigsIngestionConfigIdRunsArgs = {ingestion_config_id: string, pageSize?: number | undefined, pageOffset?: number | undefined}; export type GetApiV2EntityIngestionConfigsIngestionConfigIdRunsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svstoreEntityIngestionRunStatus = z.enum(["ENTITY_INGESTION_RUN_STATUS_UNSPECIFIED", "ENTITY_INGESTION_RUN_STATUS_RUNNING", "ENTITY_INGESTION_RUN_STATUS_COMPLETED", "ENTITY_INGESTION_RUN_STATUS_FAILED"]); export const googleProtobufTimestamp = z.string(); export const svstoreEntityIngestionRunFailureReason = z.enum(["ENTITY_INGESTION_RUN_FAILURE_REASON_UNSPECIFIED", "ENTITY_INGESTION_RUN_FAILURE_REASON_DATA_INGESTION", "ENTITY_INGESTION_RUN_FAILURE_REASON_SCHEMA_EXTRACTION", "ENTITY_INGESTION_RUN_FAILURE_REASON_INFERENCE", "ENTITY_INGESTION_RUN_FAILURE_REASON_PUBLISHING"]); export const svstoreEntityIngestionRun = z.object({id: z.string().optional(), ingestionConfigId: z.string().optional(), status: svstoreEntityIngestionRunStatus.optional(), startedAt: googleProtobufTimestamp.optional(), completedAt: googleProtobufTimestamp.optional(), itemsAddedCount: z.number().int().nullable().optional(), itemsUpdatedCount: z.number().int().nullable().optional(), itemsDeletedCount: z.number().int().nullable().optional(), itemsUnchangedCount: z.number().int().nullable().optional(), itemsErroredCount: z.number().int().nullable().optional(), failureReason: svstoreEntityIngestionRunFailureReason.optional(), failureMessage: z.string().optional(), svRunId: z.string().optional(), isFullSync: z.boolean().optional()}); export const svstorePublicapiListEntityIngestionRunsResponse = z.object({data: z.array(svstoreEntityIngestionRun).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 }; /** * List Entity Ingestion Runs * * GET /v2/entity-ingestion-configs/{ingestion_config_id}/runs */ export const getApiV2EntityIngestionConfigsIngestionConfigIdRuns = async (args: GetApiV2EntityIngestionConfigsIngestionConfigIdRunsArgs, options?: GetApiV2EntityIngestionConfigsIngestionConfigIdRunsOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageOffset != null) query.append("pageOffset", String(args.pageOffset)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/entity-ingestion-configs/${encodeURIComponent(String(args.ingestion_config_id))}/runs${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(svstorePublicapiListEntityIngestionRunsResponse, await res.json()) };