typia
Version:
Superfast runtime validators with only one line
328 lines (327 loc) • 11.6 kB
TypeScript
import { IValidation, Resolved } from "@typia/interface";
import { TypeGuardError } from "./TypeGuardError";
/**
* Generates Protocol Buffer message schema.
*
* @danger You must configure the generic argument `T`
*/
export declare function message(): never;
/**
* Generates Protocol Buffer message schema for type `T`.
*
* Creates a `.proto` message definition string from a TypeScript type. Use for
* sharing schemas with other languages/frameworks.
*
* Protocol Buffer has limited expressiveness compared to TypeScript.
* Incompatible types cause compilation errors.
*
* @template T Target type
* @returns Protocol Buffer message schema string
* @see https://typia.io/docs/protobuf/message/#restrictions
*/
export declare function message<T>(): string;
/**
* Decodes Protocol Buffer binary.
*
* @danger You must configure the generic argument `T`
*/
export declare function decode(input: Uint8Array): never;
/**
* Decodes Protocol Buffer binary to type `T`.
*
* Converts Protocol Buffer binary data to a TypeScript instance. Binary data
* must have been encoded from a `T`-typed value—invalid data causes undefined
* behavior or errors.
*
* For type safety, ensure data was encoded via:
*
* - {@link assertEncode} — Encodes with type assertion
* - {@link isEncode} — Encodes with type checking
* - {@link validateEncode} — Encodes with validation
*
* Note: Decoder validation ({@link assertDecode}, etc.) only checks custom tags
* like `number & Minimum<7>`, not structural type safety.
*
* @template T Target type
* @param input Protocol Buffer binary data
* @returns Decoded value of type `T`
*/
export declare function decode<T>(input: Uint8Array): Resolved<T>;
/**
* Decodes Protocol Buffer binary with assertion.
*
* @danger You must configure the generic argument `T`
*/
export declare function assertDecode(input: Uint8Array, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never;
/**
* Decodes Protocol Buffer binary with assertion (partial safety).
*
* Combines {@link decode} with {@link assert}. Throws {@link TypeGuardError} on
* validation failure.
*
* Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &
* Format<"uuid">`), not structural type correctness. Ensure source data was
* encoded with type-safe encoders.
*
* Related functions:
*
* - {@link decode} — No validation
* - {@link isDecode} — Returns `null` instead of throwing
* - {@link validateDecode} — Returns detailed validation errors
*
* @template T Target type
* @param input Protocol Buffer binary data
* @param errorFactory Custom error factory receiving
* {@link TypeGuardError.IProps}
* @returns Decoded value of type `T`
* @throws {TypeGuardError} When custom tag validation fails
*/
export declare function assertDecode<T>(input: Uint8Array, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): Resolved<T>;
/**
* Decodes Protocol Buffer binary with type checking.
*
* @danger You must configure the generic argument `T`
*/
export declare function isDecode(input: Uint8Array): never;
/**
* Decodes Protocol Buffer binary with type checking (partial safety).
*
* Combines {@link decode} with {@link is}. Returns `null` on validation failure.
*
* Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &
* Format<"uuid">`), not structural type correctness. Ensure source data was
* encoded with type-safe encoders.
*
* Related functions:
*
* - {@link decode} — No validation
* - {@link assertDecode} — Throws instead of returning `null`
* - {@link validateDecode} — Returns detailed validation errors
*
* @template T Target type
* @param input Protocol Buffer binary data
* @returns Decoded value of type `T`, or `null` if invalid
*/
export declare function isDecode<T>(input: Uint8Array): Resolved<T> | null;
/**
* Decodes Protocol Buffer binary with validation.
*
* @danger You must configure the generic argument `T`
*/
export declare function validateDecode(input: Uint8Array): never;
/**
* Decodes Protocol Buffer binary with validation (partial safety).
*
* Combines {@link decode} with {@link validate}. Returns
* {@link IValidation.IFailure} with errors on mismatch, or
* {@link IValidation.ISuccess} with decoded value.
*
* Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &
* Format<"uuid">`), not structural type correctness. Ensure source data was
* encoded with type-safe encoders.
*
* Related functions:
*
* - {@link decode} — No validation
* - {@link assertDecode} — Throws on first error
* - {@link isDecode} — Returns `null` instead of error details
*
* @template T Target type
* @param input Protocol Buffer binary data
* @returns Validation result containing decoded value or errors
*/
export declare function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;
/**
* Encodes value to Protocol Buffer binary.
*
* Converts a TypeScript value to Protocol Buffer binary format.
*
* Does not validate the input. For validation, use:
*
* - {@link assertEncode} — Throws on type mismatch
* - {@link isEncode} — Returns `null` on type mismatch
* - {@link validateEncode} — Returns detailed validation errors
*
* Protocol Buffer has limited expressiveness compared to TypeScript.
* Incompatible types cause compilation errors.
*
* @template T Type of input value
* @param input Value to encode
* @returns Protocol Buffer binary data
* @see https://typia.io/docs/protobuf/message/#restrictions
*/
export declare function encode<T>(input: T): Uint8Array;
/**
* Encodes value to Protocol Buffer binary with assertion.
*
* Combines {@link assert} with {@link encode}. Throws {@link TypeGuardError} on
* type mismatch.
*
* Related functions:
*
* - {@link encode} — No validation
* - {@link isEncode} — Returns `null` instead of throwing
* - {@link validateEncode} — Returns detailed validation errors
*
* Protocol Buffer has limited expressiveness compared to TypeScript.
* Incompatible types cause compilation errors.
*
* @template T Type of input value
* @param input Value to encode
* @param errorFactory Custom error factory receiving
* {@link TypeGuardError.IProps}
* @returns Protocol Buffer binary data
* @throws {TypeGuardError} When input doesn't conform to type `T`
* @see https://typia.io/docs/protobuf/message/#restrictions
*/
export declare function assertEncode<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): Uint8Array;
/**
* Encodes value to Protocol Buffer binary with type checking.
*
* Combines {@link is} with {@link encode}. Returns `null` on type mismatch.
*
* Related functions:
*
* - {@link encode} — No validation
* - {@link assertEncode} — Throws instead of returning `null`
* - {@link validateEncode} — Returns detailed validation errors
*
* Protocol Buffer has limited expressiveness compared to TypeScript.
* Incompatible types cause compilation errors.
*
* @template T Type of input value
* @param input Value to encode
* @returns Protocol Buffer binary data, or `null` if invalid
* @see https://typia.io/docs/protobuf/message/#restrictions
*/
export declare function isEncode<T>(input: T): Uint8Array | null;
/**
* Encodes value to Protocol Buffer binary with validation.
*
* Combines {@link validate} with {@link encode}. Returns
* {@link IValidation.IFailure} with all errors on mismatch, or
* {@link IValidation.ISuccess} with binary data.
*
* Related functions:
*
* - {@link encode} — No validation
* - {@link assertEncode} — Throws on first error
* - {@link isEncode} — Returns `null` instead of error details
*
* Protocol Buffer has limited expressiveness compared to TypeScript.
* Incompatible types cause compilation errors.
*
* @template T Type of input value
* @param input Value to encode
* @returns Validation result containing binary data or errors
* @see https://typia.io/docs/protobuf/message/#restrictions
*/
export declare function validateEncode<T>(input: T): IValidation<Uint8Array>;
/**
* Creates reusable {@link decode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createDecode(): never;
/**
* Creates reusable {@link decode} function.
*
* @template T Target type
* @returns Reusable decoder function
*/
export declare function createDecode<T>(): (input: Uint8Array) => Resolved<T>;
/**
* Creates reusable {@link isDecode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createIsDecode(): never;
/**
* Creates reusable {@link isDecode} function.
*
* @template T Target type
* @returns Reusable decoder function
*/
export declare function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;
/**
* Creates reusable {@link assertDecode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createAssertDecode(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never;
/**
* Creates reusable {@link assertDecode} function.
*
* @template T Target type
* @param errorFactory Custom error factory receiving
* {@link TypeGuardError.IProps}
* @returns Reusable decoder function
*/
export declare function createAssertDecode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: Uint8Array) => Resolved<T>;
/**
* Creates reusable {@link validateDecode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createValidateDecode(): never;
/**
* Creates reusable {@link validateDecode} function.
*
* @template T Target type
* @returns Reusable decoder function
*/
export declare function createValidateDecode<T>(): (input: Uint8Array) => IValidation<Resolved<T>>;
/**
* Creates reusable {@link encode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createEncode(): never;
/**
* Creates reusable {@link encode} function.
*
* @template T Type of input value
* @returns Reusable encoder function
*/
export declare function createEncode<T>(): (input: T) => Uint8Array;
/**
* Creates reusable {@link isEncode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createIsEncode(): never;
/**
* Creates reusable {@link isEncode} function.
*
* @template T Type of input value
* @returns Reusable encoder function
*/
export declare function createIsEncode<T>(): (input: T) => Uint8Array | null;
/**
* Creates reusable {@link assertEncode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createAssertEncode(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): never;
/**
* Creates reusable {@link assertEncode} function.
*
* @template T Type of input value
* @param errorFactory Custom error factory receiving
* {@link TypeGuardError.IProps}
* @returns Reusable encoder function
*/
export declare function createAssertEncode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => Uint8Array;
/**
* Creates reusable {@link validateEncode} function.
*
* @danger You must configure the generic argument `T`
*/
export declare function createValidateEncode(): never;
/**
* Creates reusable {@link validateEncode} function.
*
* @template T Type of input value
* @returns Reusable encoder function
*/
export declare function createValidateEncode<T>(): (input: T) => IValidation<Uint8Array>;