import { Atomic, IReadableURLSearchParams, IValidation, Resolved, } from "@typia/interface"; import { TypeGuardError } from "./TypeGuardError"; import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError"; /* =========================================================== HTTP - FORM-DATA - QUERY - HEADERS - PARAMETER - FACTORY FUNCTIONS ============================================================== FORM-DATA ----------------------------------------------------------- */ /** * Decodes `FormData` into type `T`. * * Parses a `FormData` instance with automatic type casting. Properties typed as * `boolean` or `Blob` are cast to expected types during decoding. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array * types allowed * 4. No union types allowed * * Does not validate the decoded value. For validation, use: * * - {@link assertFormData} — Throws on type mismatch * - {@link isFormData} — Returns `null` on type mismatch * - {@link validateFormData} — Returns detailed validation errors * * @template T Target object type * @param input FormData instance to decode * @returns Decoded object of type `T` * @danger You must configure the generic argument `T` */ export function formData(input: FormData): Resolved; /** @internal */ export function formData(): never { NoTransformConfigurationError("http.formData"); } /** * Decodes `FormData` into type `T` with assertion. * * Parses a `FormData` instance with automatic type casting, then validates the * result via {@link assert}. Throws {@link TypeGuardError} on mismatch. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array * types allowed * 4. No union types allowed * * Related functions: * * - {@link formData} — No validation * - {@link isFormData} — Returns `null` instead of throwing * - {@link validateFormData} — Returns detailed validation errors * * @template T Target object type * @param input FormData instance to decode * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Decoded object of type `T` * @throws {TypeGuardError} When decoded value doesn't conform to type `T` * @danger You must configure the generic argument `T` */ export function assertFormData( input: FormData, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): Resolved; /** @internal */ export function assertFormData(): never { NoTransformConfigurationError("http.assertFormData"); } /** * Decodes `FormData` into type `T` with type checking. * * Parses a `FormData` instance with automatic type casting, then validates the * result via {@link is}. Returns `null` on type mismatch. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array * types allowed * 4. No union types allowed * * Related functions: * * - {@link formData} — No validation * - {@link assertFormData} — Throws instead of returning `null` * - {@link validateFormData} — Returns detailed validation errors * * @template T Target object type * @param input FormData instance to decode * @returns Decoded object of type `T`, or `null` if invalid * @danger You must configure the generic argument `T` */ export function isFormData( input: FormData, ): Resolved | null; /** @internal */ export function isFormData(): never { NoTransformConfigurationError("http.isFormData"); } /** * Decodes `FormData` into type `T` with validation. * * Parses a `FormData` instance with automatic type casting, then validates the * result via {@link validate}. Returns {@link IValidation.IFailure} with all * errors on mismatch, or {@link IValidation.ISuccess} with decoded value. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array * types allowed * 4. No union types allowed * * Related functions: * * - {@link formData} — No validation * - {@link assertFormData} — Throws on first error * - {@link isFormData} — Returns `null` instead of error details * * @template T Target object type * @param input FormData instance to decode * @returns Validation result containing decoded value or errors * @danger You must configure the generic argument `T` */ export function validateFormData( input: FormData, ): IValidation>; /** @internal */ export function validateFormData(): never { NoTransformConfigurationError("http.validateFormData"); } /* ----------------------------------------------------------- QUERY ----------------------------------------------------------- */ /** * Decodes URL query string into type `T`. * * Parses a query string or `URLSearchParams` instance with automatic type * casting. Properties typed as `boolean` or `number` are cast to expected types * during decoding. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 4. No union types allowed * * Does not validate the decoded value. For validation, use: * * - {@link assertQuery} — Throws on type mismatch * - {@link isQuery} — Returns `null` on type mismatch * - {@link validateQuery} — Returns detailed validation errors * * @template T Target object type * @param input Query string or URLSearchParams instance * @returns Decoded object of type `T` * @danger You must configure the generic argument `T` */ export function query( input: string | IReadableURLSearchParams, ): Resolved; /** @internal */ export function query(): never { NoTransformConfigurationError("http.query"); } /** * Decodes URL query string into type `T` with assertion. * * Parses a query string or `URLSearchParams` instance with automatic type * casting, then validates the result via {@link assert}. Throws * {@link TypeGuardError} on mismatch. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 4. No union types allowed * * Related functions: * * - {@link query} — No validation * - {@link isQuery} — Returns `null` instead of throwing * - {@link validateQuery} — Returns detailed validation errors * * @template T Target object type * @param input Query string or URLSearchParams instance * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Decoded object of type `T` * @throws {TypeGuardError} When decoded value doesn't conform to type `T` * @danger You must configure the generic argument `T` */ export function assertQuery( input: string | IReadableURLSearchParams, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): Resolved; /** @internal */ export function assertQuery(): never { NoTransformConfigurationError("http.assertQuery"); } /** * Decodes URL query string into type `T` with type checking. * * Parses a query string or `URLSearchParams` instance with automatic type * casting, then validates the result via {@link is}. Returns `null` on type * mismatch. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 4. No union types allowed * * Related functions: * * - {@link query} — No validation * - {@link assertQuery} — Throws instead of returning `null` * - {@link validateQuery} — Returns detailed validation errors * * @template T Target object type * @param input Query string or URLSearchParams instance * @returns Decoded object of type `T`, or `null` if invalid * @danger You must configure the generic argument `T` */ export function isQuery( input: string | IReadableURLSearchParams, ): Resolved | null; /** @internal */ export function isQuery(): never { NoTransformConfigurationError("http.isQuery"); } /** * Decodes URL query string into type `T` with validation. * * Parses a query string or `URLSearchParams` instance with automatic type * casting, then validates the result via {@link validate}. Returns * {@link IValidation.IFailure} with all errors on mismatch, or * {@link IValidation.ISuccess} with decoded value. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 4. No union types allowed * * Related functions: * * - {@link query} — No validation * - {@link assertQuery} — Throws on first error * - {@link isQuery} — Returns `null` instead of error details * * @template T Target object type * @param input Query string or URLSearchParams instance * @returns Validation result containing decoded value or errors * @danger You must configure the generic argument `T` */ export function validateQuery( input: string | IReadableURLSearchParams, ): IValidation>; /** @internal */ export function validateQuery(): never { NoTransformConfigurationError("http.validateQuery"); } /* ----------------------------------------------------------- HEADERS ----------------------------------------------------------- */ /** * Decodes HTTP headers into type `T`. * * Parses HTTP headers object with automatic type casting. Properties typed as * `boolean` or `number` are cast to expected types during decoding. Compatible * with Express and Fastify request headers. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Property keys must be lowercase * 4. Property values cannot be `null` (but `undefined` is allowed) * 5. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 6. No union types allowed * 7. Property `set-cookie` must be array type * 8. These properties cannot be array type: `age`, `authorization`, * `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, * `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`, * `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, * `user-agent` * * Does not validate the decoded value. For validation, use: * * - {@link assertHeaders} — Throws on type mismatch * - {@link isHeaders} — Returns `null` on type mismatch * - {@link validateHeaders} — Returns detailed validation errors * * @template T Target object type * @param input Headers object from HTTP request * @returns Decoded object of type `T` * @danger You must configure the generic argument `T` */ export function headers( input: Record, ): Resolved; /** @internal */ export function headers(): never { NoTransformConfigurationError("http.headers"); } /** * Decodes HTTP headers into type `T` with assertion. * * Parses HTTP headers object with automatic type casting, then validates the * result via {@link assert}. Throws {@link TypeGuardError} on mismatch. * Compatible with Express and Fastify request headers. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Property keys must be lowercase * 4. Property values cannot be `null` (but `undefined` is allowed) * 5. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 6. No union types allowed * 7. Property `set-cookie` must be array type * 8. These properties cannot be array type: `age`, `authorization`, * `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, * `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`, * `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, * `user-agent` * * Related functions: * * - {@link headers} — No validation * - {@link isHeaders} — Returns `null` instead of throwing * - {@link validateHeaders} — Returns detailed validation errors * * @template T Target object type * @param input Headers object from HTTP request * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Decoded object of type `T` * @throws {TypeGuardError} When decoded value doesn't conform to type `T` * @danger You must configure the generic argument `T` */ export function assertHeaders( input: Record, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): Resolved; /** @internal */ export function assertHeaders(): never { NoTransformConfigurationError("http.assertHeaders"); } /** * Decodes HTTP headers into type `T` with type checking. * * Parses HTTP headers object with automatic type casting, then validates the * result via {@link is}. Returns `null` on type mismatch. Compatible with * Express and Fastify request headers. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Property keys must be lowercase * 4. Property values cannot be `null` (but `undefined` is allowed) * 5. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 6. No union types allowed * 7. Property `set-cookie` must be array type * 8. These properties cannot be array type: `age`, `authorization`, * `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, * `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`, * `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, * `user-agent` * * Related functions: * * - {@link headers} — No validation * - {@link assertHeaders} — Throws instead of returning `null` * - {@link validateHeaders} — Returns detailed validation errors * * @template T Target object type * @param input Headers object from HTTP request * @returns Decoded object of type `T`, or `null` if invalid * @danger You must configure the generic argument `T` */ export function isHeaders( input: Record, ): Resolved | null; /** @internal */ export function isHeaders(): never { NoTransformConfigurationError("http.isHeaders"); } /** * Decodes HTTP headers into type `T` with validation. * * Parses HTTP headers object with automatic type casting, then validates the * result via {@link validate}. Returns {@link IValidation.IFailure} with all * errors on mismatch, or {@link IValidation.ISuccess} with decoded value. * Compatible with Express and Fastify request headers. * * Type `T` constraints: * * 1. Must be an object type * 2. No dynamic properties allowed * 3. Property keys must be lowercase * 4. Property values cannot be `null` (but `undefined` is allowed) * 5. Only `boolean`, `bigint`, `number`, `string` or their array types allowed * 6. No union types allowed * 7. Property `set-cookie` must be array type * 8. These properties cannot be array type: `age`, `authorization`, * `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, * `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`, * `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, * `user-agent` * * Related functions: * * - {@link headers} — No validation * - {@link assertHeaders} — Throws on first error * - {@link isHeaders} — Returns `null` instead of error details * * @template T Target object type * @param input Headers object from HTTP request * @returns Validation result containing decoded value or errors * @danger You must configure the generic argument `T` */ export function validateHeaders( input: Record, ): IValidation>; /** @internal */ export function validateHeaders(): never { NoTransformConfigurationError("http.validateHeaders"); } /* ----------------------------------------------------------- PARAMETER ----------------------------------------------------------- */ /** * Decodes URL path parameter into type `T`. * * Parses a path parameter string with automatic type casting. When type `T` is * `boolean` or `number`, casts the string value to the expected type. Also * performs type assertion via {@link assert}, throwing {@link TypeGuardError} on * mismatch. * * @template T Target atomic type (`boolean`, `bigint`, `number`, `string`, or * `null`) * @param input Path parameter string * @returns Decoded value of type `T` * @throws {TypeGuardError} When decoded value doesn't conform to type `T` * @danger You must configure the generic argument `T` */ export function parameter( input: string, ): Resolved; /** @internal */ export function parameter(): never { NoTransformConfigurationError("http.parameter"); } /* ----------------------------------------------------------- FACTORY FUNCTIONS ----------------------------------------------------------- */ /** * Creates reusable {@link formData} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createFormData(): never; /** * Creates reusable {@link formData} function. * * @template T Target object type * @returns Reusable decoder function */ export function createFormData(): (input: FormData) => T; /** @internal */ export function createFormData(): (input: FormData) => T { NoTransformConfigurationError("http.createFormData"); } /** * Creates reusable {@link assertFormData} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @danger You must configure the generic argument `T` */ export function createAssertFormData( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): never; /** * Creates reusable {@link assertFormData} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable decoder function */ export function createAssertFormData( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): (input: FormData) => T; /** @internal */ export function createAssertFormData(): (input: FormData) => T { NoTransformConfigurationError("http.createAssertFormData"); } /** * Creates reusable {@link isFormData} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createIsFormData(): never; /** * Creates reusable {@link isFormData} function. * * @template T Target object type * @returns Reusable decoder function */ export function createIsFormData(): ( input: FormData, ) => T | null; /** @internal */ export function createIsFormData(): (input: FormData) => T | null { NoTransformConfigurationError("http.createIsFormData"); } /** * Creates reusable {@link validateFormData} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createValidateFormData(): never; /** * Creates reusable {@link validateFormData} function. * * @template T Target object type * @returns Reusable decoder function */ export function createValidateFormData(): ( input: FormData, ) => IValidation>; /** @internal */ export function createValidateFormData(): ( input: FormData, ) => IValidation> { NoTransformConfigurationError("http.createValidateFormData"); } /** * Creates reusable {@link query} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createQuery(): never; /** * Creates reusable {@link query} function. * * @template T Target object type * @returns Reusable decoder function */ export function createQuery(): ( input: string | IReadableURLSearchParams, ) => T; /** @internal */ export function createQuery(): ( input: string | IReadableURLSearchParams, ) => T { NoTransformConfigurationError("http.createQuery"); } /** * Creates reusable {@link assertQuery} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @danger You must configure the generic argument `T` */ export function createAssertQuery( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): never; /** * Creates reusable {@link assertQuery} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable decoder function */ export function createAssertQuery( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): (input: string | IReadableURLSearchParams) => T; /** @internal */ export function createAssertQuery(): ( input: string | IReadableURLSearchParams, ) => T { NoTransformConfigurationError("http.createAssertQuery"); } /** * Creates reusable {@link isQuery} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createIsQuery(): never; /** * Creates reusable {@link isQuery} function. * * @template T Target object type * @returns Reusable decoder function */ export function createIsQuery(): ( input: string | IReadableURLSearchParams, ) => T | null; /** @internal */ export function createIsQuery(): ( input: string | IReadableURLSearchParams, ) => T | null { NoTransformConfigurationError("http.createIsQuery"); } /** * Creates reusable {@link validateQuery} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createValidateQuery(): never; /** * Creates reusable {@link validateQuery} function. * * @template T Target object type * @returns Reusable decoder function */ export function createValidateQuery(): ( input: string | IReadableURLSearchParams, ) => IValidation>; /** @internal */ export function createValidateQuery(): ( input: string | IReadableURLSearchParams, ) => IValidation> { NoTransformConfigurationError("http.createValidateQuery"); } /** * Creates reusable {@link headers} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createHeaders(): never; /** * Creates reusable {@link headers} function. * * @template T Target object type * @returns Reusable decoder function */ export function createHeaders(): ( input: Record, ) => T; /** @internal */ export function createHeaders(): ( input: Record, ) => T { NoTransformConfigurationError("http.createHeaders"); } /** * Creates reusable {@link assertHeaders} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @danger You must configure the generic argument `T` */ export function createAssertHeaders( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): never; /** * Creates reusable {@link assertHeaders} function. * * @template T Target object type * @param errorFactory Custom error factory receiving * {@link TypeGuardError.IProps} * @returns Reusable decoder function */ export function createAssertHeaders( errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error), ): (input: Record) => T; /** @internal */ export function createAssertHeaders(): ( input: Record, ) => T { NoTransformConfigurationError("http.createAssertHeaders"); } /** * Creates reusable {@link isHeaders} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createIsHeaders(): never; /** * Creates reusable {@link isHeaders} function. * * @template T Target object type * @returns Reusable decoder function */ export function createIsHeaders(): ( input: Record, ) => T | null; /** @internal */ export function createIsHeaders(): ( input: Record, ) => T | null { NoTransformConfigurationError("http.createIsHeaders"); } /** * Creates reusable {@link validateHeaders} function. * * @template T Target object type * @danger You must configure the generic argument `T` */ export function createValidateHeaders(): never; /** * Creates reusable {@link validateHeaders} function. * * @template T Target object type * @returns Reusable decoder function */ export function createValidateHeaders(): ( input: Record, ) => IValidation>; /** @internal */ export function createValidateHeaders(): ( input: Record, ) => IValidation> { NoTransformConfigurationError("http.createValidateHeaders"); } /** * Creates reusable {@link parameter} function. * * @template T Target atomic type * @danger You must configure the generic argument `T` */ export function createParameter(): never; /** * Creates reusable {@link parameter} function. * * @template T Target atomic type * @returns Reusable decoder function */ export function createParameter(): ( input: string, ) => T; /** @internal */ export function createParameter(): ( input: string, ) => T { NoTransformConfigurationError("http.createParameter"); }