import {z} from 'zod' export type UpdateSettingsWrapperString = {add?: Array | undefined, remove?: Array | undefined}; export type CrossLinkField = {alias?: (string | null) | undefined, name: string}; export type UpdateSettingsWrapperCrossLink = {add?: (Array<{fields?: Array | undefined, name: string, url: string}>) | undefined, remove?: (Array<{fields?: Array | undefined, name: string, url: string}>) | undefined}; export type UpdateSettingsWrapperTimeRange = {add?: Array<{end: number, start: number}> | undefined, remove?: Array<{end: number, start: number}> | undefined}; export type StreamPartitionType = 'value' | {hash: number} | 'prefix'; export type UpdateSettingsWrapperStreamPartition = {add?: (Array<{disabled?: boolean | undefined, field: string, types?: StreamPartitionType | undefined}>) | undefined, remove?: (Array<{disabled?: boolean | undefined, field: string, types?: StreamPartitionType | undefined}>) | undefined}; export type PartitionTimeLevel = 'unset' | 'hourly' | 'daily'; export type UpdateSettingsWrapperPatternAssociation = {add?: Array<{apply_at: string, description: string, field: string, pattern: string, pattern_id: string, pattern_name: string, policy: string}> | undefined, remove?: Array<{apply_at: string, description: string, field: string, pattern: string, pattern_id: string, pattern_name: string, policy: string}> | undefined}; export type StorageType = 'normal' | 'compliance'; export type UpdateApiApiOrgIdStreamsStreamNameSettingsArgs = {org_id: string, stream_name: string, type?: string | undefined, body: {approx_partition?: (boolean | null) | undefined, bloom_filter_fields?: UpdateSettingsWrapperString | undefined, cross_links?: UpdateSettingsWrapperCrossLink | undefined, data_retention?: (number | null) | undefined, defined_schema_fields?: UpdateSettingsWrapperString | undefined, distinct_value_fields?: UpdateSettingsWrapperString | undefined, dynamic_partition?: (boolean | null) | undefined, enable_distinct_fields?: (boolean | null) | undefined, enable_log_patterns_extraction?: (boolean | null) | undefined, extended_retention_days?: UpdateSettingsWrapperTimeRange | undefined, flatten_level?: (number | null) | undefined, full_text_search_keys?: UpdateSettingsWrapperString | undefined, index_all_values?: (boolean | null) | undefined, index_fields?: UpdateSettingsWrapperString | undefined, index_original_data?: (boolean | null) | undefined, is_llm_stream?: (boolean | null) | undefined, max_query_range?: (number | null) | undefined, partition_keys?: UpdateSettingsWrapperStreamPartition | undefined, partition_time_level?: (PartitionTimeLevel | null) | undefined, pattern_associations?: UpdateSettingsWrapperPatternAssociation | undefined, storage_type?: (StorageType | null) | undefined, store_original_data?: (boolean | null) | undefined}}; export type UpdateApiApiOrgIdStreamsStreamNameSettingsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const httpResponse = z.object({code: z.number().int().gte(0), error_detail: z.string().nullable().optional(), hint: z.string().nullable().optional(), id: z.string().nullable().optional(), message: z.string(), name: z.string().nullable().optional(), suggestions: z.array(z.string()).nullable().optional(), trace_id: z.string().nullable().optional(), warnings: z.array(z.string()).nullable().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 }; /** * Update stream settings * * PUT /api/{org_id}/streams/{stream_name}/settings */ export const updateApiApiOrgIdStreamsStreamNameSettings = async (args: UpdateApiApiOrgIdStreamsStreamNameSettingsArgs, options: UpdateApiApiOrgIdStreamsStreamNameSettingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/streams/${encodeURIComponent(String(args.stream_name))}/settings${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(httpResponse, await res.json()) };