import type { textTypes } from '../req/parse-body.js'; import type { VovkHandlerSchema, VovkSchema } from './core.js'; import type { StandardJSONSchemaV1, StandardSchemaV1 } from './standard-schema.js'; import type { KnownAny } from './utils.js'; export interface CombinedProps extends StandardSchemaV1.Props, StandardJSONSchemaV1.Props { } /** * An interface that combines StandardJSONSchema and StandardSchema. * */ export interface CombinedSpec { '~standard': CombinedProps; } export declare namespace CombinedSpec { type Target = StandardJSONSchemaV1.Target; type InferInput = StandardSchemaV1.InferInput; type InferOutput = StandardSchemaV1.InferOutput; type SuccessResult = StandardSchemaV1.SuccessResult; } /** The type of a procedure() schema option that is left out. */ export type VovkNoSchema = CombinedSpec & { readonly __noSchema: true; }; type EmptyValueCheck = unknown extends CombinedSpec.InferInput ? CombinedSpec.InferOutput : CombinedSpec.InferInput; /** * What a procedure's RPC method takes: a key for each schema, typed with the schema's input and optional when the * server accepts a request without it (it validates a missing body as undefined, a missing query or params as {}). */ export type VovkProcedureInput = ([TBody] extends [VovkNoSchema] ? TContentType[number] extends 'application/json' ? unknown : { body?: BodyTypeFromContentType; } : undefined extends EmptyValueCheck ? { body?: BodyTypeFromContentType>; } : { body: BodyTypeFromContentType>; }) & ([TQuery] extends [VovkNoSchema] ? unknown : {} extends EmptyValueCheck ? { query?: CombinedSpec.InferInput; } : { query: CombinedSpec.InferInput; }) & ([TParams] extends [VovkNoSchema] ? { params?: Record; } : {} extends EmptyValueCheck ? { params?: CombinedSpec.InferInput; } : { params: CombinedSpec.InferInput; }); export type ProcedureFnInput = ([TBody] extends [VovkNoSchema] ? { body?: unknown; } : unknown) & ([TQuery] extends [VovkNoSchema] ? { query?: unknown; } : unknown) & VovkProcedureInput; /** Application MIME types that are parsed as text (derived from parseBody.ts textTypes). */ type TextLikeApplicationType = (typeof textTypes)[number]; export type ContentType = 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded' | 'text/plain' | 'application/octet-stream' | TextLikeApplicationType | `text/${string}` | `application/${string}` | `${string}+json` | `${string}+xml` | `${string}+text` | `${string}+yaml` | `${string}+json-seq` | '*/*' | (string & {}); export type NormalizeContentType = T extends ContentType[] ? T : [T & ContentType]; export type BodyTypeFromContentType = T[number] extends infer A ? A extends '*/*' ? TBody | URLSearchParams | FormData | ArrayBuffer | Uint8Array | Blob : A extends 'application/json' | `${string}+json` ? TBody | Blob : A extends 'multipart/form-data' ? TBody | FormData | Blob : A extends 'application/x-www-form-urlencoded' ? TBody | URLSearchParams | FormData | Blob : A extends `text/${string}` | TextLikeApplicationType | `${string}+xml` | `${string}+text` | `${string}+yaml` | `${string}+json-seq` ? string | Blob : ArrayBuffer | Uint8Array | Blob : never; /** What req.vovk.body() parses a body of these content types into when there is no body schema. */ export type ParsedBodyTypeFromContentType = T[number] extends infer A ? A extends '*/*' | 'application/json' | `${string}+json` ? unknown : A extends 'multipart/form-data' | 'application/x-www-form-urlencoded' ? Record : A extends `text/${string}` | TextLikeApplicationType | `${string}+xml` | `${string}+text` | `${string}+yaml` | `${string}+json-seq` ? string : File : never; export type VovkTypedProcedure unknown, B = unknown, Q = unknown, P = unknown, O = unknown, I = unknown, TContentType extends ContentType | ContentType[] = ['application/json']> = T & { __types: { body: B; query: Q; params: P; output: O; iteration: I; contentType: NormalizeContentType; }; isRPC?: boolean; }; /** * Client-side validation function type. * @see https://vovk.dev/imports */ export type VovkValidateOnClient = (input: { body?: unknown; query?: unknown; params?: unknown; meta?: unknown; } & TFetcherOptions, validation: Omit, 'output' | 'iteration'>, meta: { fullSchema: VovkSchema; endpoint: string; }) => KnownAny | Promise; export {};