import {z} from 'zod' export type IamV1UpdateMenuRequest = {component?: string | undefined, external?: boolean | undefined, icon?: string | undefined, id?: string | undefined, keepAlive?: boolean | undefined, name?: string | undefined, parentId?: string | undefined, path?: string | undefined, permCode?: string | undefined, redirect?: string | undefined, sortOrder?: number | undefined, status?: number | undefined, type?: number | undefined, visible?: boolean | undefined}; export type UpdateApiV1IamMenusIdArgs = {id: string, body: IamV1UpdateMenuRequest}; export type UpdateApiV1IamMenusIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const iamV1Menu: z.ZodType = z.object({children: z.array(z.lazy(() => iamV1Menu)).optional(), code: z.string().optional(), component: z.string().optional(), createdAt: z.string().optional(), external: z.boolean().optional(), icon: z.string().optional(), id: z.string().optional(), isBuiltin: z.boolean().optional(), keepAlive: z.boolean().optional(), name: z.string().optional(), parentId: z.string().optional(), path: z.string().optional(), permCode: z.string().optional(), redirect: z.string().optional(), sortOrder: z.number().int().optional(), status: z.number().int().optional(), type: z.number().int().optional(), updatedAt: z.string().optional(), visible: z.boolean().optional()}); export const iamV1UpdateMenuReply = z.object({menu: iamV1Menu.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 }; /** * UpdateMenu 更新菜单,采用 PATCH 语义:仅 optional 字段存在时更新。 * * PUT /v1/iam/menus/{id} */ export const updateApiV1IamMenusId = async (args: UpdateApiV1IamMenusIdArgs, options: UpdateApiV1IamMenusIdOptions) => { 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(/\/+$/, '')}/v1/iam/menus/${encodeURIComponent(String(args.id))}${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(iamV1UpdateMenuReply, await res.json()) };