import type { z } from 'zod'; import { type ResponseSelector } from '@equinor/fusion-framework-module-http/selectors'; import type { ApiVersionContract, ExtractApiVersion, VersionedParsedArgs, VersionedResponse } from './types.js'; /** * Resolves an API version string from a named key or a raw version value. * * Endpoint functions accept both `'v1'` and `'1.0'`, so this lookup normalises * the caller's version identifier before a request path or schema is selected. * The version key is checked first; otherwise the value is matched directly. * * @template TApiVersions - Record mapping version keys to version strings. * @template TVersion - The version key or value provided by the caller. * @param apiVersions - Map of version keys to version strings. * @param version - Version key or raw version string to resolve. * @returns The resolved API version string. * @throws {Error} When the version is neither a key nor a value of `apiVersions`. * * @example * ```ts * enum ApiVersion { v1 = '1.0', v2 = '2.0' } * extractVersion(ApiVersion, 'v1'); // '1.0' * extractVersion(ApiVersion, '1.0'); // '1.0' * ``` */ export declare const extractVersion: , TVersion extends string>(apiVersions: TApiVersions, version: TVersion) => ExtractApiVersion; /** * Creates a response selector that validates the HTTP response body with a Zod schema. * * Combines the HTTP module's `jsonSelector` with Zod parsing, so an endpoint * rejects payloads the service contract does not allow instead of forwarding * them to the caller as loosely typed data. * * @template Output - The validated output type produced by the schema. * @param schema - The Zod schema used to parse and validate the response body. * @returns A `ResponseSelector` that extracts JSON and runs it through `schema.parse`. * * @example * ```ts * import { z } from 'zod'; * const RoleSchema = z.object({ id: z.string(), name: z.string() }); * const selector = schemaSelector(RoleSchema); * ``` */ export declare const schemaSelector: (schema: z.ZodSchema) => ResponseSelector; /** * Validates an empty successful response without attempting to parse a JSON body. * * Use this selector for endpoints whose contract specifies an empty body with a success status * other than `204 No Content`; `jsonSelector` only skips parsing for 204 responses. * * @param response - HTTP response whose success status must be validated. * @returns A promise that resolves to `undefined` after a successful response. * @throws {HttpJsonResponseError} When an unsuccessful response cannot be parsed as JSON. */ export declare const emptyResponseSelector: ResponseSelector; /** * Parses caller input with the argument schema a version contract publishes for `version`. * * Endpoints resolve the concrete version first and then look the schema up, so * this helper keeps the parsed value typed by the *same* deferred version * expression the request builders declare. Parsing inline instead would collapse * the result to one version's concrete shape and break that association as soon * as a second version is added. * * @template TContract - The endpoint's version contract. * @template TVersion - Concrete API version to resolve. * @param contract - Version contract to read the argument schema from. * @param version - Concrete API version selecting the contract entry. * @param input - Caller-supplied arguments. * @returns The arguments parsed by the schema this version publishes. * @throws {z.ZodError} When the input does not satisfy the version's argument schema. * * @example * ```ts * const args = parseVersionedArgs(VersionContract, apiVersion, input); * ``` */ export declare const parseVersionedArgs: (contract: TContract, version: TVersion, input: unknown) => VersionedParsedArgs; /** * Builds a response selector from the schema a version contract publishes for `version`. * * Pairing the selector with the same contract entry the arguments were parsed * from is what guarantees a request cannot be validated against another * version's response shape. * * @template TContract - The endpoint's version contract. * @template TVersion - Concrete API version to resolve. * @param contract - Version contract to read the response schema from. * @param version - Concrete API version selecting the contract entry. * @returns A selector validating the response with this version's schema. * * @example * ```ts * const selector = versionedResponseSelector(VersionContract, apiVersion); * ``` */ export declare const versionedResponseSelector: (contract: TContract, version: TVersion) => ResponseSelector>; /** * Builds a response selector that reads a binary body and validates it with the schema a version * contract publishes for `version`. * * Some operations serve archives and static assets rather than JSON, so their body cannot be * parsed as a document. Reading it as a blob keeps those endpoints on the same version contract * as every other operation: the contract entry still owns the response type, it simply describes * the blob result the HTTP client's `blobSelector` produces. * * @template TContract - The endpoint's version contract. * @template TVersion - Concrete API version to resolve. * @param contract - Version contract to read the response schema from. * @param version - Concrete API version selecting the contract entry. * @returns A selector reading the body as a blob and validating it with this version's schema. * @throws {Error} From the returned selector, when the response is unsuccessful, carries no * content, or cannot be read as a blob. * * @example * ```ts * const selector = versionedBlobSelector(VersionContract, apiVersion); * ``` */ export declare const versionedBlobSelector: (contract: TContract, version: TVersion) => ResponseSelector>;