import { ExtraRequestInit } from "./client/request.js"; import { EmptyMeta } from "./codecs.js"; import { HeadersExtra } from "./headers.js"; import { SchemaDefinition } from "./schema.js"; import { WireFormat } from "./wireFormat.js"; export type HasOnlyOptionalProps = { [K in keyof T]-?: object extends Pick ? never : K; } extends { [K2 in keyof T]: never; } ? true : false; export type PathParams = Record; export type QueryParams = Record; export type HeaderParams = Record; export type RequestData

= { params?: P; query?: Q; headers?: H; }; export type JsonRequestData = RequestData & { body?: B; }; export type SszRequestData

= Omit & ("body" extends keyof P ? (P["body"] extends void ? { body?: never; } : { body: Uint8Array; }) : { body?: never; }); export type HttpMethod = "GET" | "POST" | "DELETE"; /** * This type describes the general shape of a route * * This includes both http and application-level shape * - The http method * - Used to more strictly enforce the shape of the request * - The application-level parameters * - this enforces the shape of the input data passed by the client and to the route handler * - The http request * - this enforces the shape of the querystring, url params, request body * - The application-level return data * - this enforces the shape of the output data passed back to the client and returned by the route handler * - The application-level return metadata * - this enforces the shape of the returned metadata, used informationally and to help decode the return data */ export type Endpoint = { method: Method; /** The parameters the client passes / server app code ingests */ args: ArgsType; /** The parameters in the http request */ request: RequestType; /** The return data */ return: ReturnType; /** The return metadata */ meta: Meta; }; /** Encode / decode requests to & from function params, as well as schema definitions */ export type RequestWithoutBodyCodec = { writeReq: (p: E["args"]) => E["request"]; parseReq: (r: E["request"]) => E["args"]; schema: SchemaDefinition; }; export type JsonRequestMethods = { writeReqJson: (p: E["args"]) => E["request"]; parseReqJson: (r: E["request"]) => E["args"]; }; export type SszRequestMethods = { writeReqSsz: (p: E["args"]) => SszRequestData; parseReqSsz: (r: SszRequestData) => E["args"]; }; export type RequestWithBodyCodec = JsonRequestMethods & SszRequestMethods & { schema: SchemaDefinition; /** Support ssz-only or json-only requests */ onlySupport?: WireFormat; }; /** * Handles translation between `Endpoint["args"]` and `Endpoint["request"]` */ export type RequestCodec = E["method"] extends "GET" ? RequestWithoutBodyCodec : "body" extends keyof E["request"] ? RequestWithBodyCodec : RequestWithoutBodyCodec; export declare function isRequestWithoutBody(definition: RouteDefinition): definition is RouteDefinition & { req: RequestWithoutBodyCodec; }; export type ResponseDataCodec = { toJson: (data: T, meta: M) => unknown; fromJson: (data: unknown, meta: M) => T; serialize: (data: T, meta: M) => Uint8Array; deserialize: (data: Uint8Array, meta: any) => T; }; export type ResponseMetadataCodec = { toJson: (val: T) => unknown; fromJson: (val: unknown) => T; toHeadersObject: (val: T) => Record; fromHeaders: (headers: HeadersExtra) => T; }; export type ResponseCodec = { data: ResponseDataCodec; meta: ResponseMetadataCodec; /** Occasionally, json responses require an extra transformation to separate the data from metadata */ transform?: { toResponse: (data: unknown, meta: unknown) => unknown; fromResponse: (resp: unknown) => { data: E["return"]; } & (E["meta"] extends EmptyMeta ? { meta?: never; } : { meta: E["meta"]; }); }; /** Support ssz-only or json-only responses */ onlySupport?: WireFormat; /** Indicator used to handle empty responses */ isEmpty?: true; }; /** * Top-level definition of a route used by both the client and server * - url and method * - request and response codec * - request json schema */ export type RouteDefinition = { url: string; method: E["method"]; req: RequestCodec; resp: ResponseCodec; init?: ExtraRequestInit; }; export type RouteDefinitions> = { [K in keyof Es]: RouteDefinition; }; //# sourceMappingURL=types.d.ts.map