import {z} from 'zod' export type HealthConfig = {Test?: Array | undefined, Interval?: number | undefined, Timeout?: number | undefined, Retries?: number | undefined, StartPeriod?: number | undefined, StartInterval?: number | undefined}; export type ThrottleDevice = {Path?: string | undefined, Rate?: number | undefined}; export type DeviceMapping = {PathOnHost?: string | undefined, PathInContainer?: string | undefined, CgroupPermissions?: string | undefined}; export type DeviceRequest = {Driver?: string | undefined, Count?: number | undefined, DeviceIDs?: Array | undefined, Capabilities?: Array> | undefined, Options?: {[key: string]: string} | undefined}; export type PortBinding = {HostIp?: string | undefined, HostPort?: string | undefined}; export type PortMap = {[key: string]: Array | null}; export type RestartPolicy = {Name?: ('' | 'no' | 'always' | 'unless-stopped' | 'on-failure') | undefined, MaximumRetryCount?: number | undefined}; export type Mount = {Target?: string | undefined, Source?: string | undefined, Type?: ('bind' | 'volume' | 'image' | 'tmpfs' | 'npipe' | 'cluster') | undefined, ReadOnly?: boolean | undefined, Consistency?: string | undefined, BindOptions?: ({Propagation?: ('private' | 'rprivate' | 'shared' | 'rshared' | 'slave' | 'rslave') | undefined, NonRecursive?: boolean | undefined, CreateMountpoint?: boolean | undefined, ReadOnlyNonRecursive?: boolean | undefined, ReadOnlyForceRecursive?: boolean | undefined}) | undefined, VolumeOptions?: ({NoCopy?: boolean | undefined, Labels?: {[key: string]: string} | undefined, DriverConfig?: ({Name?: string | undefined, Options?: {[key: string]: string} | undefined}) | undefined, Subpath?: string | undefined}) | undefined, ImageOptions?: ({Subpath?: string | undefined}) | undefined, TmpfsOptions?: ({SizeBytes?: number | undefined, Mode?: number | undefined, Options?: Array> | undefined}) | undefined}; export type HostConfig = {CpuShares?: number | undefined, Memory?: number | undefined, CgroupParent?: string | undefined, BlkioWeight?: number | undefined, BlkioWeightDevice?: (Array<{Path?: string | undefined, Weight?: number | undefined}>) | undefined, BlkioDeviceReadBps?: Array | undefined, BlkioDeviceWriteBps?: Array | undefined, BlkioDeviceReadIOps?: Array | undefined, BlkioDeviceWriteIOps?: Array | undefined, CpuPeriod?: number | undefined, CpuQuota?: number | undefined, CpuRealtimePeriod?: number | undefined, CpuRealtimeRuntime?: number | undefined, CpusetCpus?: string | undefined, CpusetMems?: string | undefined, Devices?: Array | undefined, DeviceCgroupRules?: Array | undefined, DeviceRequests?: Array | undefined, KernelMemoryTCP?: number | undefined, MemoryReservation?: number | undefined, MemorySwap?: number | undefined, MemorySwappiness?: number | undefined, NanoCpus?: number | undefined, OomKillDisable?: boolean | undefined, Init?: (boolean | null) | undefined, PidsLimit?: (number | null) | undefined, Ulimits?: (Array<{Name?: string | undefined, Soft?: number | undefined, Hard?: number | undefined}>) | undefined, CpuCount?: number | undefined, CpuPercent?: number | undefined, IOMaximumIOps?: number | undefined, IOMaximumBandwidth?: number | undefined, Binds?: Array | undefined, ContainerIDFile?: string | undefined, LogConfig?: ({Type?: ('local' | 'json-file' | 'syslog' | 'journald' | 'gelf' | 'fluentd' | 'awslogs' | 'splunk' | 'etwlogs' | 'none') | undefined, Config?: {[key: string]: string} | undefined}) | undefined, NetworkMode?: string | undefined, PortBindings?: PortMap | undefined, RestartPolicy?: RestartPolicy | undefined, AutoRemove?: boolean | undefined, VolumeDriver?: string | undefined, VolumesFrom?: Array | undefined, Mounts?: Array | undefined, ConsoleSize?: (Array | null) | undefined, Annotations?: {[key: string]: string} | undefined, CapAdd?: Array | undefined, CapDrop?: Array | undefined, CgroupnsMode?: ('private' | 'host') | undefined, Dns?: Array | undefined, DnsOptions?: Array | undefined, DnsSearch?: Array | undefined, ExtraHosts?: Array | undefined, GroupAdd?: Array | undefined, IpcMode?: string | undefined, Cgroup?: string | undefined, Links?: Array | undefined, OomScoreAdj?: number | undefined, PidMode?: string | undefined, Privileged?: boolean | undefined, PublishAllPorts?: boolean | undefined, ReadonlyRootfs?: boolean | undefined, SecurityOpt?: Array | undefined, StorageOpt?: {[key: string]: string} | undefined, Tmpfs?: {[key: string]: string} | undefined, UTSMode?: string | undefined, UsernsMode?: string | undefined, ShmSize?: number | undefined, Sysctls?: ({[key: string]: string} | null) | undefined, Runtime?: (string | null) | undefined, Isolation?: ('default' | 'process' | 'hyperv' | '') | undefined, MaskedPaths?: Array | undefined, ReadonlyPaths?: Array | undefined}; export type EndpointIPAMConfig = {IPv4Address?: string | undefined, IPv6Address?: string | undefined, LinkLocalIPs?: Array | undefined} | null; export type EndpointSettings = {IPAMConfig?: EndpointIPAMConfig | undefined, Links?: Array | undefined, MacAddress?: string | undefined, Aliases?: Array | undefined, DriverOpts?: ({[key: string]: string} | null) | undefined, GwPriority?: number | undefined, NetworkID?: string | undefined, EndpointID?: string | undefined, Gateway?: string | undefined, IPAddress?: string | undefined, IPPrefixLen?: number | undefined, IPv6Gateway?: string | undefined, GlobalIPv6Address?: string | undefined, GlobalIPv6PrefixLen?: number | undefined, DNSNames?: Array | undefined}; export type NetworkingConfig = {EndpointsConfig?: {[key: string]: EndpointSettings} | undefined}; export type CreateApiContainersCreateArgs = {name?: string | undefined, platform?: string | undefined, body: {Hostname?: string | undefined, Domainname?: string | undefined, User?: string | undefined, AttachStdin?: boolean | undefined, AttachStdout?: boolean | undefined, AttachStderr?: boolean | undefined, ExposedPorts?: ({[key: string]: Record} | null) | undefined, Tty?: boolean | undefined, OpenStdin?: boolean | undefined, StdinOnce?: boolean | undefined, Env?: Array | undefined, Cmd?: Array | undefined, Healthcheck?: HealthConfig | undefined, ArgsEscaped?: (boolean | null) | undefined, Image?: string | undefined, Volumes?: {[key: string]: Record} | undefined, WorkingDir?: string | undefined, Entrypoint?: Array | undefined, NetworkDisabled?: (boolean | null) | undefined, MacAddress?: (string | null) | undefined, OnBuild?: (Array | null) | undefined, Labels?: {[key: string]: string} | undefined, StopSignal?: (string | null) | undefined, StopTimeout?: (number | null) | undefined, Shell?: (Array | null) | undefined, HostConfig?: HostConfig | undefined, NetworkingConfig?: NetworkingConfig | undefined}}; export type CreateApiContainersCreateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const containerCreateResponse = z.object({Id: z.string(), Warnings: z.array(z.string())}); 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 }; /** * Create a container * * POST /containers/create */ export const createApiContainersCreate = async (args: CreateApiContainersCreateArgs, options: CreateApiContainersCreateOptions) => { 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") if (args.name != null) query.append("name", String(args.name)) if (args.platform != null) query.append("platform", String(args.platform)) const url = `${baseUrl.replace(/\/+$/, '')}/containers/create${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(containerCreateResponse, await res.json()) };