import {z} from 'zod' export type Configv1LabelFilter = {name?: string | undefined, value_glob?: string | undefined}; export type Configv1AggregationType = 'LAST' | 'MIN' | 'MAX' | 'MEAN' | 'MEDIAN' | 'COUNT' | 'SUM' | 'SUMSQ' | 'STDEV' | 'P10' | 'P20' | 'P30' | 'P40' | 'P50' | 'P60' | 'P70' | 'P80' | 'P90' | 'P95' | 'P99' | 'P999' | 'P9999' | 'P25' | 'P75' | 'COUNT_SAMPLES' | 'HISTOGRAM'; export type Configv1MappingRuleStoragePolicy = {resolution?: string | undefined, retention?: string | undefined}; export type MappingRuleAggregationPolicy = {aggregation?: Configv1AggregationType | undefined, storage_policy?: Configv1MappingRuleStoragePolicy | undefined, interval?: string | undefined, drop_timestamp?: boolean | undefined}; export type Configv1MappingRuleMode = 'ENABLED' | 'PREVIEW'; export type Configv1MappingRule = {slug?: string | undefined, name?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, bucket_slug?: string | undefined, filters?: Array | undefined, aggregation_policy?: MappingRuleAggregationPolicy | undefined, drop?: boolean | undefined, mode?: Configv1MappingRuleMode | undefined}; export type ConfigV1UpdateMappingRuleBody = {mapping_rule?: Configv1MappingRule | undefined, create_if_missing?: boolean | undefined, dry_run?: boolean | undefined}; export type UpdateApiApiV1ConfigMappingRulesSlugArgs = {slug: string, body: ConfigV1UpdateMappingRuleBody}; export type UpdateApiApiV1ConfigMappingRulesSlugOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const configv1LabelFilter = z.object({name: z.string().optional(), value_glob: z.string().optional()}); export const configv1AggregationType = z.enum(["LAST", "MIN", "MAX", "MEAN", "MEDIAN", "COUNT", "SUM", "SUMSQ", "STDEV", "P10", "P20", "P30", "P40", "P50", "P60", "P70", "P80", "P90", "P95", "P99", "P999", "P9999", "P25", "P75", "COUNT_SAMPLES", "HISTOGRAM"]); export const configv1MappingRuleStoragePolicy = z.object({resolution: z.string().optional(), retention: z.string().optional()}); export const mappingRuleAggregationPolicy = z.object({aggregation: configv1AggregationType.optional(), storage_policy: configv1MappingRuleStoragePolicy.optional(), interval: z.string().optional(), drop_timestamp: z.boolean().optional()}); export const configv1MappingRuleMode = z.enum(["ENABLED", "PREVIEW"]); export const configv1MappingRule = z.object({slug: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), bucket_slug: z.string().optional(), filters: z.array(configv1LabelFilter).optional(), aggregation_policy: mappingRuleAggregationPolicy.optional(), drop: z.boolean().optional(), mode: configv1MappingRuleMode.optional()}); export const configv1UpdateMappingRuleResponse = z.object({mapping_rule: configv1MappingRule.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/mapping-rules/{slug} */ export const updateApiApiV1ConfigMappingRulesSlug = async (args: UpdateApiApiV1ConfigMappingRulesSlugArgs, options: UpdateApiApiV1ConfigMappingRulesSlugOptions) => { 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/mapping-rules/${encodeURIComponent(String(args.slug))}${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(configv1UpdateMappingRuleResponse, await res.json()) };