import {z} from 'zod' export type CreateApiV1NameFilesystemMoveArgs = {name: string, body: {sourcePath: string, destinationPath: string, overwrite?: (boolean | null) | undefined, createParentDirectories?: boolean | undefined}}; export type CreateApiV1NameFilesystemMoveOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1FileType = z.enum(["FILE_TYPE_UNSPECIFIED", "FILE_TYPE_REGULAR", "FILE_TYPE_DIRECTORY", "FILE_TYPE_SYMLINK"]); export const v1FileInfo = z.object({path: z.string().optional(), size: z.string().optional(), type: v1FileType.optional(), modifyTime: z.string().optional(), mode: z.string().optional()}); export const v1MoveResponse = z.object({fileInfo: v1FileInfo.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 }; /** * (-- api-linter: core::0136::verb-noun=disabled * aip.dev/not-precedent: Move is a custom method on a singleton * resource. The "move" verb follows Unix convention (mv) and clearly * conveys imperative action for filesystem operations. --) * Moves or renames a file, directory, or symbolic link. * By default, fails if the destination already exists. * If the source is a symbolic link, the link itself is moved, not its target. * If the destination exists and is a symbolic link, it will be replaced. * * POST /v1/{name}/filesystem:move */ export const createApiV1NameFilesystemMove = async (args: CreateApiV1NameFilesystemMoveArgs, options: CreateApiV1NameFilesystemMoveOptions) => { 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/${encodeURIComponent(String(args.name))}/filesystem:move${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(v1MoveResponse, await res.json()) };