import {z} from 'zod' export type ResourcePoolsLicense = 'PERSISTED_WRITES_STANDARD' | 'PERSISTED_WRITES_HISTOGRAM' | 'PERSISTED_CARDINALITY_STANDARD' | 'PERSISTED_CARDINALITY_HISTOGRAM' | 'MATCHED_WRITES_STANDARD' | 'MATCHED_WRITES_HISTOGRAM'; export type AllocationFixedValue = {license?: ResourcePoolsLicense | undefined, value?: unknown | undefined}; export type AllocationThreshold = {percent_of_pool_allocation?: number | undefined, fixed_value?: unknown | undefined}; export type AllocationThresholds = {license?: ResourcePoolsLicense | undefined, all_priorities?: AllocationThreshold | undefined, default_and_low_priority?: AllocationThreshold | undefined, low_priority?: AllocationThreshold | undefined}; export type Configv1ResourcePoolsAllocation = {percent_of_license?: number | undefined, fixed_values?: Array | undefined, priority_thresholds?: Array | undefined}; export type Configv1LabelFilter = {name?: string | undefined, value_glob?: string | undefined}; export type ResourcePoolsPriorities = {high_priority_filters?: Array | undefined, low_priority_filters?: Array | undefined}; export type ResourcePoolsDefaultPool = {allocation?: Configv1ResourcePoolsAllocation | undefined, priorities?: ResourcePoolsPriorities | undefined, priority_thresholds?: Array | undefined}; export type ResourcePoolsPool = {name?: string | undefined, allocation?: Configv1ResourcePoolsAllocation | undefined, filters?: Array | undefined, priorities?: ResourcePoolsPriorities | undefined}; export type Configv1ResourcePools = {created_at?: string | undefined, updated_at?: string | undefined, default_pool?: ResourcePoolsDefaultPool | undefined, pools?: Array | undefined}; export type Configv1UpdateResourcePoolsRequest = {resource_pools?: Configv1ResourcePools | undefined, create_if_missing?: boolean | undefined, dry_run?: boolean | undefined}; export type UpdateApiApiV1ConfigResourcePoolsArgs = {body: Configv1UpdateResourcePoolsRequest}; export type UpdateApiApiV1ConfigResourcePoolsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const resourcePoolsLicense = z.enum(["PERSISTED_WRITES_STANDARD", "PERSISTED_WRITES_HISTOGRAM", "PERSISTED_CARDINALITY_STANDARD", "PERSISTED_CARDINALITY_HISTOGRAM", "MATCHED_WRITES_STANDARD", "MATCHED_WRITES_HISTOGRAM"]); export const allocationFixedValue = z.object({license: resourcePoolsLicense.optional(), value: z.string().optional()}); export const allocationThreshold = z.object({percent_of_pool_allocation: z.number().optional(), fixed_value: z.string().optional()}); export const allocationThresholds = z.object({license: resourcePoolsLicense.optional(), all_priorities: allocationThreshold.optional(), default_and_low_priority: allocationThreshold.optional(), low_priority: allocationThreshold.optional()}); export const configv1ResourcePoolsAllocation = z.object({percent_of_license: z.number().optional(), fixed_values: z.array(allocationFixedValue).optional(), priority_thresholds: z.array(allocationThresholds).optional()}); export const configv1LabelFilter = z.object({name: z.string().optional(), value_glob: z.string().optional()}); export const resourcePoolsPriorities = z.object({high_priority_filters: z.array(configv1LabelFilter).optional(), low_priority_filters: z.array(configv1LabelFilter).optional()}); export const resourcePoolsDefaultPool = z.object({allocation: configv1ResourcePoolsAllocation.optional(), priorities: resourcePoolsPriorities.optional(), priority_thresholds: z.array(allocationThresholds).optional()}); export const resourcePoolsPool = z.object({name: z.string().optional(), allocation: configv1ResourcePoolsAllocation.optional(), filters: z.array(configv1LabelFilter).optional(), priorities: resourcePoolsPriorities.optional()}); export const configv1ResourcePools = z.object({created_at: z.string().optional(), updated_at: z.string().optional(), default_pool: resourcePoolsDefaultPool.optional(), pools: z.array(resourcePoolsPool).optional()}); export const configv1UpdateResourcePoolsResponse = z.object({resource_pools: configv1ResourcePools.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 }; /** * PUT /api/v1/config/resource-pools */ export const updateApiApiV1ConfigResourcePools = async (args: UpdateApiApiV1ConfigResourcePoolsArgs, options: UpdateApiApiV1ConfigResourcePoolsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/resource-pools${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(configv1UpdateResourcePoolsResponse, await res.json()) };