import * as API from "@distilled.cloud/core/api"; // AUTO-GENERATED by scripts/generate.ts from .generated-specs (specs/spec-mirror-hetzner/specs/cloud.spec.json). Do not edit. import * as S from "@distilled.cloud/core/schema-lite"; import * as __L from "@distilled.cloud/core/schema-lite"; import { UnknownHetznerError } from "../errors.ts"; import { paginatePageNumber } from "../pagination.ts"; import { HetznerProtocol, type HetznerOpError, type HetznerOpContext } from "../protocol.ts"; import * as Retry from "../retry.ts"; import * as T from "../traits.ts"; // Schema table, filled on first reach (see __S at the end). const __s: any[] = []; export type { HetznerOpError, HetznerOpContext }; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ export type CreateVolumeRequestLabelsMap = { [key: string]: string | undefined }; export interface CreateVolumeRequest { /** Size of the Volume in GB. */ size: number; /** Name of the volume. */ name: string; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ labels?: CreateVolumeRequestLabelsMap; /** Auto-mount Volume after attach. `server` must be provided. */ automount?: boolean; /** Format Volume after creation. One of: `xfs`, `ext4`. */ format?: string; /** Location to create the Volume in (can be omitted if Server is specified). */ location?: string; /** Server to which to attach the Volume once it's created (Volume will be created in the same Location as the server). */ server?: number; } /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ export interface CreateVolumeResponseVolumeLocation { /** ID of the [Location](#tag/locations). */ id: number; /** Unique identifier of the [Location](#tag/locations). */ name: string; /** Human readable description of the [Location](#tag/locations). */ description: string; /** Country the [Location](#tag/locations) resides in. ISO 3166-1 alpha-2 code of the country. */ country: string; /** Name of the closest city to the [Location](#tag/locations). City name or city name and state in short form. E.g. `Falkenstein` or `Ashburn, VA`. */ city: string; /** Latitude of the city closest to the [Location](#tag/locations). */ latitude: number; /** Longitude of the city closest to the [Location](#tag/locations). */ longitude: number; /** Name of the Network Zone this [Location](#tag/locations) resides in. */ network_zone: string; } /** Protection configuration for the Resource. */ export interface CreateVolumeResponseVolumeProtection { /** Prevent the Resource from being deleted. */ delete: boolean; } /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ export type CreateVolumeResponseVolumeLabelsMap = { [key: string]: string | undefined }; /** Status of the Volume. */ export type CreateVolumeResponseVolumeStatus = "available" | "creating"; export interface CreateVolumeResponseVolume { /** ID of the [Volume](#tag/volumes). */ id: number; /** Point in time when the Resource was created (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ created: string; /** Name of the Resource. Must be unique per Project. */ name: string; /** ID of the Server the Volume is attached to, null if it is not attached at all. */ server: number | null; /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ location: CreateVolumeResponseVolumeLocation; /** Size in GB of the Volume. */ size: number; /** Device path on the file system for the Volume. */ linux_device: string; /** Protection configuration for the Resource. */ protection: CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ labels: CreateVolumeResponseVolumeLabelsMap; /** Status of the Volume. */ status: CreateVolumeResponseVolumeStatus; /** Filesystem of the Volume if formatted on creation, null if not formatted on creation. */ format: string | null; } /** Status of the Action. */ export type CreateVolumeResponseActionStatus = "running" | "success" | "error"; export interface CreateVolumeResponseActionResourcesItem { /** ID of the Resource. */ id: number; /** Type of the Resource. */ type: string; } /** Resources the Action relates to. */ export type CreateVolumeResponseActionResourcesList = Array; /** Error message for the Action if an error occurred, otherwise null. */ export interface CreateVolumeResponseActionError { /** Fixed error code for machines. */ code: string; /** Error message for humans. */ message: string; } export interface CreateVolumeResponseAction { /** ID of the [Action](#description/actions). */ id: number; /** Command executed in the Action. */ command: string; /** Status of the Action. */ status: CreateVolumeResponseActionStatus; /** Point in time when the Action was started (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ started: string; /** Point in time when the Action was finished (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). Only set if the Action is finished otherwise null. */ finished: string | null; /** Progress of the Action in percent. */ progress: number; /** Resources the Action relates to. */ resources: CreateVolumeResponseActionResourcesList; /** Error message for the Action if an error occurred, otherwise null. */ error: CreateVolumeResponseActionError | null; } /** Status of the Action. */ export type CreateVolumeResponseNextActionsItemStatus = "running" | "success" | "error"; export type CreateVolumeResponseNextActionsItemResourcesItem = CreateVolumeResponseActionResourcesItem; /** Resources the Action relates to. */ export type CreateVolumeResponseNextActionsItemResourcesList = Array; /** Error message for the Action if an error occurred, otherwise null. */ export type CreateVolumeResponseNextActionsItemError = CreateVolumeResponseActionError; export interface CreateVolumeResponseNextActionsItem { /** ID of the [Action](#description/actions). */ id: number; /** Command executed in the Action. */ command: string; /** Status of the Action. */ status: CreateVolumeResponseNextActionsItemStatus; /** Point in time when the Action was started (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ started: string; /** Point in time when the Action was finished (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). Only set if the Action is finished otherwise null. */ finished: string | null; /** Progress of the Action in percent. */ progress: number; /** Resources the Action relates to. */ resources: CreateVolumeResponseNextActionsItemResourcesList; /** Error message for the Action if an error occurred, otherwise null. */ error: CreateVolumeResponseActionError | null; } export type CreateVolumeResponseNextActionsList = Array; export interface CreateVolumeResponse { volume: CreateVolumeResponseVolume; action: CreateVolumeResponseAction; next_actions: CreateVolumeResponseNextActionsList; } export interface DeleteVolumeRequest { /** ID of the Volume. */ id: number; } export interface DeleteVolumeResponse {} export interface GetVolumeRequest { /** ID of the Volume. */ id: number; } /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ export type GetVolumeResponseVolumeLocation = CreateVolumeResponseVolumeLocation; /** Protection configuration for the Resource. */ export type GetVolumeResponseVolumeProtection = CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ export type GetVolumeResponseVolumeLabelsMap = { [key: string]: string | undefined }; /** Status of the Volume. */ export type GetVolumeResponseVolumeStatus = "available" | "creating"; export interface GetVolumeResponseVolume { /** ID of the [Volume](#tag/volumes). */ id: number; /** Point in time when the Resource was created (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ created: string; /** Name of the Resource. Must be unique per Project. */ name: string; /** ID of the Server the Volume is attached to, null if it is not attached at all. */ server: number | null; /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ location: CreateVolumeResponseVolumeLocation; /** Size in GB of the Volume. */ size: number; /** Device path on the file system for the Volume. */ linux_device: string; /** Protection configuration for the Resource. */ protection: CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ labels: GetVolumeResponseVolumeLabelsMap; /** Status of the Volume. */ status: GetVolumeResponseVolumeStatus; /** Filesystem of the Volume if formatted on creation, null if not formatted on creation. */ format: string | null; } export interface GetVolumeResponse { volume: GetVolumeResponseVolume; } /** Status of the Volume. */ export type ListVolumesRequestStatusItem = "available" | "creating"; export type ListVolumesRequestStatusList = Array; export type ListVolumesRequestSortItem = | "id" | "id:asc" | "id:desc" | "name" | "name:asc" | "name:desc" | "created" | "created:asc" | "created:desc"; export type ListVolumesRequestSortList = Array; export interface ListVolumesRequest { /** Filter resources by status. May be used multiple times. The response will only contain the resources with the specified status. */ status?: ListVolumesRequestStatusList; /** Sort resources by field and direction. May be used multiple times. For more information, see "[Sorting](#description/sorting)". */ sort?: ListVolumesRequestSortList; /** Filter resources by their name. The response will only contain the resources matching exactly the specified name. */ name?: string; /** Filter resources by labels. The response will only contain resources matching the label selector. For more information, see "[Label Selector](#description/label-selector)". */ label_selector?: string; /** Page number to return. For more information, see "[Pagination](#description/pagination)". */ page?: number; /** Maximum number of entries returned per page. For more information, see "[Pagination](#description/pagination)". */ per_page?: number; } /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ export type ListVolumesResponseVolumesItemLocation = CreateVolumeResponseVolumeLocation; /** Protection configuration for the Resource. */ export type ListVolumesResponseVolumesItemProtection = CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ export type ListVolumesResponseVolumesItemLabelsMap = { [key: string]: string | undefined }; /** Status of the Volume. */ export type ListVolumesResponseVolumesItemStatus = "available" | "creating"; export interface ListVolumesResponseVolumesItem { /** ID of the [Volume](#tag/volumes). */ id: number; /** Point in time when the Resource was created (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ created: string; /** Name of the Resource. Must be unique per Project. */ name: string; /** ID of the Server the Volume is attached to, null if it is not attached at all. */ server: number | null; /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ location: CreateVolumeResponseVolumeLocation; /** Size in GB of the Volume. */ size: number; /** Device path on the file system for the Volume. */ linux_device: string; /** Protection configuration for the Resource. */ protection: CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ labels: ListVolumesResponseVolumesItemLabelsMap; /** Status of the Volume. */ status: ListVolumesResponseVolumesItemStatus; /** Filesystem of the Volume if formatted on creation, null if not formatted on creation. */ format: string | null; } export type ListVolumesResponseVolumesList = Array; /** See "[Pagination](#description/pagination)" for more information. */ export interface ListVolumesResponseMetaPagination { /** Current page number. */ page: number; /** Maximum number of entries returned per page. */ per_page: number; /** Page number of the previous page. Can be null if the current page is the first one. */ previous_page: number | null; /** Page number of the next page. Can be null if the current page is the last one. */ next_page: number | null; /** Page number of the last page available. Can be null if the current page is the last one. */ last_page: number | null; /** Total number of entries that exist for this query. Can be null if unknown. */ total_entries: number | null; } export interface ListVolumesResponseMeta { /** See "[Pagination](#description/pagination)" for more information. */ pagination: ListVolumesResponseMetaPagination; } export interface ListVolumesResponse { volumes: ListVolumesResponseVolumesList; meta: ListVolumesResponseMeta; } /** User-defined labels (`key/value` pairs) for the Resource. Note that the set of [Labels](#description/labels) provided in the request will overwrite the existing one. For more information, see "[Labels](#description/labels)". */ export type UpdateVolumeRequestLabelsMap = { [key: string]: string | undefined }; export interface UpdateVolumeRequest { /** ID of the Volume. */ id: number; /** New Volume name. */ name?: string; /** User-defined labels (`key/value` pairs) for the Resource. Note that the set of [Labels](#description/labels) provided in the request will overwrite the existing one. For more information, see "[Labels](#description/labels)". */ labels?: UpdateVolumeRequestLabelsMap; } /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ export type UpdateVolumeResponseVolumeLocation = CreateVolumeResponseVolumeLocation; /** Protection configuration for the Resource. */ export type UpdateVolumeResponseVolumeProtection = CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ export type UpdateVolumeResponseVolumeLabelsMap = { [key: string]: string | undefined }; /** Status of the Volume. */ export type UpdateVolumeResponseVolumeStatus = "available" | "creating"; export interface UpdateVolumeResponseVolume { /** ID of the [Volume](#tag/volumes). */ id: number; /** Point in time when the Resource was created (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). */ created: string; /** Name of the Resource. Must be unique per Project. */ name: string; /** ID of the Server the Volume is attached to, null if it is not attached at all. */ server: number | null; /** Location of the Volume. Volume can only be attached to Servers in the same Location. */ location: CreateVolumeResponseVolumeLocation; /** Size in GB of the Volume. */ size: number; /** Device path on the file system for the Volume. */ linux_device: string; /** Protection configuration for the Resource. */ protection: CreateVolumeResponseVolumeProtection; /** User-defined labels (`key/value` pairs) for the Resource. For more information, see "[Labels](#description/labels)". */ labels: UpdateVolumeResponseVolumeLabelsMap; /** Status of the Volume. */ status: UpdateVolumeResponseVolumeStatus; /** Filesystem of the Volume if formatted on creation, null if not formatted on creation. */ format: string | null; } export interface UpdateVolumeResponse { volume: UpdateVolumeResponseVolume; } export type CreateVolumeError = HetznerOpError; /** Create a Volume Creates a new Volume attached to a Server. If you want to create a Volume that is not attached to a Server, you need to provide the `location` key instead of `server`. This can be either the ID or the name of the Location this Volume will be created in. Note that a Volume can be attached to a Server only in the same Location as the Volume itself. Specifying the Server during Volume creation will automatically attach the Volume to that Server after it has been initialized. In that case, the `next_actions` key in the response is an array which contains a single `attach_volume` action. The minimum Volume size is 10GB and the maximum size is 10TB (10240GB). A volume's name can consist of alphanumeric characters, dashes, underscores, and dots, but has to start and end with an alphanumeric character. The total length is limited to 64 characters. Volume names must be unique per Project. #### Operation specific errors */ export const createVolume: API.OperationMethod< CreateVolumeRequest, CreateVolumeResponse, CreateVolumeError, HetznerOpContext > = /*@__PURE__*/ API.make(() => ({ input: __S(0, __c0, 0) as any as S.Schema, output: __S(6, __c0, 6) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, })); export type DeleteVolumeError = HetznerOpError; /** Delete a Volume Deletes a volume. All Volume data is irreversibly destroyed. The Volume must not be attached to a Server and it must not have delete protection enabled. */ export const deleteVolume: API.OperationMethod< DeleteVolumeRequest, DeleteVolumeResponse, DeleteVolumeError, HetznerOpContext > = /*@__PURE__*/ API.make(() => ({ input: __S(16, __c2, 0) as any as S.Schema, output: __S(17, __c2, 1) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, })); export type GetVolumeError = HetznerOpError; /** Get a Volume Gets a specific Volume object. */ export const getVolume: API.OperationMethod< GetVolumeRequest, GetVolumeResponse, GetVolumeError, HetznerOpContext > = /*@__PURE__*/ API.make(() => ({ input: __S(24, __c3, 0) as any as S.Schema, output: __S(32, __c4, 0) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, })); export type ListVolumesError = HetznerOpError; /** List Volumes Gets all existing Volumes that you have available. */ export const listVolumes: API.PaginatedOperationMethod< ListVolumesRequest, ListVolumesResponse, ListVolumesError, HetznerOpContext, ListVolumesResponseVolumesItem > = /*@__PURE__*/ API.makePaginated( () => ({ input: __S(41, __c5, 1) as any as S.Schema, output: __S(45, __c5, 5) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, pagination: { mode: "page", inputToken: "page", outputToken: "meta.pagination.next_page", items: "volumes", pageSize: "per_page", } as const, }), paginatePageNumber, ) as any; export type UpdateVolumeError = HetznerOpError; /** Update a Volume Updates the Volume properties. */ export const updateVolume: API.OperationMethod< UpdateVolumeRequest, UpdateVolumeResponse, UpdateVolumeError, HetznerOpContext > = /*@__PURE__*/ API.make(() => ({ input: __S(48, __c6, 0) as any as S.Schema, output: __S(32, __c4, 0) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, })); // Schema builders: each runs one schema initializer, on that schema's first use. function __c0(j: number): any { switch (j) { case 0: return S.suspend(() => S.Struct({ size: S.Number, name: S.String, labels: S.optional(__S(8, __c1, 0)), automount: S.optional(S.Boolean), format: S.optional(S.String), location: S.optional(S.String), server: S.optional(S.Number), }).pipe(T.Http({ method: "POST", uri: "/volumes", code: 200 })), ).annotate({ identifier: "CreateVolumeRequest" }); case 1: return S.suspend(() => S.Struct({ id: S.Number, type: S.String, }), ).annotate({ identifier: "CreateVolumeResponseActionResourcesItem" }); case 2: return S.Array(__S(1, __c0, 1)); case 3: return S.suspend(() => S.Struct({ code: S.String, message: S.String, }), ).annotate({ identifier: "CreateVolumeResponseActionError" }); case 4: return S.suspend(() => S.Struct({ id: S.Number, command: S.String, status: S.String, started: S.String, finished: S.NullOr(S.String), progress: S.Number, resources: __S(2, __c0, 2), error: S.NullOr(__S(3, __c0, 3)), }), ).annotate({ identifier: "CreateVolumeResponseAction" }); case 5: return S.Array(__S(4, __c0, 4)); case 6: return S.suspend(() => S.Struct({ volume: __S(11, __c1, 3), action: __S(4, __c0, 4), next_actions: __S(5, __c0, 5), }), ).annotate({ identifier: "CreateVolumeResponse" }); } } function __c1(j: number): any { switch (j) { case 0: return S.Record(S.String, S.String); case 1: return S.suspend(() => S.Struct({ id: S.Number, name: S.String, description: S.String, country: S.String, city: S.String, latitude: S.Number, longitude: S.Number, network_zone: S.String, }), ).annotate({ identifier: "CreateVolumeResponseVolumeLocation" }); case 2: return S.suspend(() => S.Struct({ delete: S.Boolean, }), ).annotate({ identifier: "CreateVolumeResponseVolumeProtection" }); case 3: return S.suspend(() => S.Struct({ id: S.Number, created: S.String, name: S.String, server: S.NullOr(S.Number), location: __S(9, __c1, 1), size: S.Number, linux_device: S.String, protection: __S(10, __c1, 2), labels: __S(8, __c1, 0), status: S.String, format: S.NullOr(S.String), }), ).annotate({ identifier: "CreateVolumeResponseVolume" }); } } function __c2(j: number): any { switch (j) { case 0: return S.suspend(() => S.Struct({ id: S.Number.pipe(T.Label()), }).pipe(T.Http({ method: "DELETE", uri: "/volumes/{id}", code: 200 })), ).annotate({ identifier: "DeleteVolumeRequest" }); case 1: return S.suspend(() => S.Struct({})).annotate({ identifier: "DeleteVolumeResponse" }); } } function __c3(j: number): any { switch (j) { case 0: return S.suspend(() => S.Struct({ id: S.Number.pipe(T.Label()), }).pipe(T.Http({ method: "GET", uri: "/volumes/{id}", code: 200 })), ).annotate({ identifier: "GetVolumeRequest" }); } } function __c4(j: number): any { switch (j) { case 0: return S.suspend(() => S.Struct({ volume: __S(11, __c1, 3), }), ).annotate({ identifier: "GetVolumeResponse" }); } } function __c5(j: number): any { switch (j) { case 0: return S.Array(S.String); case 1: return S.suspend(() => S.Struct({ status: S.optional(__S(40, __c5, 0).pipe(T.Query())), sort: S.optional(__S(40, __c5, 0).pipe(T.Query())), name: S.optional(S.String.pipe(T.Query())), label_selector: S.optional(S.String.pipe(T.Query())), page: S.optional(S.Number.pipe(T.Query())), per_page: S.optional(S.Number.pipe(T.Query())), }).pipe(T.Http({ method: "GET", uri: "/volumes", code: 200 })), ).annotate({ identifier: "ListVolumesRequest" }); case 2: return S.Array(__S(11, __c1, 3)); case 3: return S.suspend(() => S.Struct({ page: S.Number, per_page: S.Number, previous_page: S.NullOr(S.Number), next_page: S.NullOr(S.Number), last_page: S.NullOr(S.Number), total_entries: S.NullOr(S.Number), }), ).annotate({ identifier: "ListVolumesResponseMetaPagination" }); case 4: return S.suspend(() => S.Struct({ pagination: __S(43, __c5, 3), }), ).annotate({ identifier: "ListVolumesResponseMeta" }); case 5: return S.suspend(() => S.Struct({ volumes: __S(42, __c5, 2), meta: __S(44, __c5, 4), }), ).annotate({ identifier: "ListVolumesResponse" }); } } function __c6(j: number): any { switch (j) { case 0: return S.suspend(() => S.Struct({ id: S.Number.pipe(T.Label()), name: S.optional(S.String), labels: S.optional(__S(8, __c1, 0)), }).pipe(T.Http({ method: "PUT", uri: "/volumes/{id}", code: 200 })), ).annotate({ identifier: "UpdateVolumeRequest" }); } } // Schema table: entry i is schema j of builder f, made on first reach. function __S(i: number, f: (j: number) => unknown, j: number): any { return (__s[i] ??= __L.at(f, j)); }