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 }; export interface GetLocationRequest { /** ID of the Location. */ id: number; } export interface GetLocationResponseLocation { /** 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; } export interface GetLocationResponse { location: GetLocationResponseLocation; } export type ListLocationsRequestSortItem = | "id" | "id:asc" | "id:desc" | "name" | "name:asc" | "name:desc"; export type ListLocationsRequestSortList = Array; export interface ListLocationsRequest { /** Filter resources by their name. The response will only contain the resources matching exactly the specified name. */ name?: string; /** Sort resources by field and direction. May be used multiple times. For more information, see "[Sorting](#description/sorting)". */ sort?: ListLocationsRequestSortList; /** 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; } export type ListLocationsResponseLocationsItem = GetLocationResponseLocation; /** List of [Locations](#tag/locations). */ export type ListLocationsResponseLocationsList = Array; /** See "[Pagination](#description/pagination)" for more information. */ export interface ListLocationsResponseMetaPagination { /** 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 ListLocationsResponseMeta { /** See "[Pagination](#description/pagination)" for more information. */ pagination: ListLocationsResponseMetaPagination; } export interface ListLocationsResponse { /** List of [Locations](#tag/locations). */ locations: ListLocationsResponseLocationsList; meta: ListLocationsResponseMeta; } export type GetLocationError = HetznerOpError; /** Get a Location Returns a [Location](#tag/locations). */ export const getLocation: API.OperationMethod< GetLocationRequest, GetLocationResponse, GetLocationError, HetznerOpContext > = /*@__PURE__*/ API.make(() => ({ input: __S(0, __c0, 0) as any as S.Schema, output: __S(1, __c0, 1) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, })); export type ListLocationsError = HetznerOpError; /** List Locations Returns all [Locations](#tag/locations). */ export const listLocations: API.PaginatedOperationMethod< ListLocationsRequest, ListLocationsResponse, ListLocationsError, HetznerOpContext, GetLocationResponseLocation > = /*@__PURE__*/ API.makePaginated( () => ({ input: __S(17, __c2, 1) as any as S.Schema, output: __S(21, __c2, 5) as any as S.Schema, errors: [UnknownHetznerError], protocol: HetznerProtocol, retry: Retry.Retry, pagination: { mode: "page", inputToken: "page", outputToken: "meta.pagination.next_page", items: "locations", pageSize: "per_page", } as const, }), paginatePageNumber, ) as any; // 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({ id: S.Number.pipe(T.Label()), }).pipe(T.Http({ method: "GET", uri: "/locations/{id}", code: 200 })), ).annotate({ identifier: "GetLocationRequest" }); case 1: return S.suspend(() => S.Struct({ location: __S(8, __c1, 0), }), ).annotate({ identifier: "GetLocationResponse" }); } } function __c1(j: number): any { switch (j) { case 0: 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: "GetLocationResponseLocation" }); } } function __c2(j: number): any { switch (j) { case 0: return S.Array(S.String); case 1: return S.suspend(() => S.Struct({ name: S.optional(S.String.pipe(T.Query())), sort: S.optional(__S(16, __c2, 0).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: "/locations", code: 200 })), ).annotate({ identifier: "ListLocationsRequest" }); case 2: return S.Array(__S(8, __c1, 0)); 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: "ListLocationsResponseMetaPagination" }); case 4: return S.suspend(() => S.Struct({ pagination: __S(19, __c2, 3), }), ).annotate({ identifier: "ListLocationsResponseMeta" }); case 5: return S.suspend(() => S.Struct({ locations: __S(18, __c2, 2), meta: __S(20, __c2, 4), }), ).annotate({ identifier: "ListLocationsResponse" }); } } // 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)); }