/** * Column type validators for Tinybird datasources * Similar to Convex's `v.*` pattern, but for ClickHouse types */ declare const VALIDATOR_BRAND: unique symbol; /** * Base interface for all type validators * The phantom types enable TypeScript to infer the correct types */ export interface TypeValidator { readonly [VALIDATOR_BRAND]: true; /** The inferred TypeScript type */ readonly _type: TType; /** The Tinybird/ClickHouse type string */ readonly _tinybirdType: TTinybirdType; /** Metadata about modifiers applied */ readonly _modifiers: TModifiers; /** Mark this output field as optional (it may be absent from endpoint responses) */ optional(): TypeValidator; /** Make this column nullable */ nullable(): TypeValidator; /** Apply LowCardinality optimization (for strings with few unique values) */ lowCardinality(): TypeValidator; /** Set a default value for the column */ default(value: TType): TypeValidator; /** Set a default SQL expression for the column (for example: generateUUIDv4()) */ defaultExpr(expression: string): TypeValidator; /** Set a codec for compression */ codec(codec: string): TypeValidator; /** Set an explicit JSON path for extraction (overrides autogenerated path) */ jsonPath(path: string): TypeValidator; } export interface TypeModifiers { optional?: boolean; nullable?: boolean; lowCardinality?: boolean; hasDefault?: boolean; defaultValue?: unknown; defaultExpression?: string; codec?: string; jsonPath?: string; } type AggregateFunctionValidator = { (func: TFunc): TypeValidator; , ...TypeValidator[] ]>(func: TFunc, ...types: TTypes): TypeValidator, AggregateFunctionTinybirdType, TypeModifiers>; }; type AggregateFunctionValue[]> = TTypes extends readonly [ infer TFirst extends TypeValidator, ...TypeValidator[] ] ? TFirst["_type"] : unknown; type AggregateFunctionArgs[]> = TTypes extends readonly [ infer TFirst extends TypeValidator, ...infer TRest extends TypeValidator[] ] ? TRest extends [] ? TFirst["_tinybirdType"] : `${TFirst["_tinybirdType"]}, ${AggregateFunctionArgs}` : never; type AggregateFunctionTinybirdType[]> = TTypes extends [] ? `AggregateFunction(${TFunc})` : `AggregateFunction(${TFunc}, ${AggregateFunctionArgs})`; /** * Type validators for Tinybird columns * * @example * ```ts * import { t } from '@tinybirdco/sdk'; * * const schema = { * id: t.string(), * count: t.int32(), * timestamp: t.dateTime(), * tags: t.array(t.string()), * metadata: t.json(), * }; * * // With custom types for narrower type inference: * type UserId = string & { readonly __brand: 'UserId' }; * type Timestamp = string & { readonly __brand: 'Timestamp' }; * * const typedSchema = { * user_id: t.string(), * created_at: t.dateTime(), * }; * ``` */ export declare const t: { /** String type - variable length UTF-8 string */ readonly string: () => TypeValidator; /** FixedString(N) - fixed length string, padded with null bytes */ readonly fixedString: (length: number) => TypeValidator; /** UUID - 16-byte universally unique identifier */ readonly uuid: () => TypeValidator; /** Int8 - signed 8-bit integer (-128 to 127) */ readonly int8: () => TypeValidator; /** Int16 - signed 16-bit integer */ readonly int16: () => TypeValidator; /** Int32 - signed 32-bit integer */ readonly int32: () => TypeValidator; /** Int64 - signed 64-bit integer (represented as number, may lose precision) */ readonly int64: () => TypeValidator; /** Int128 - signed 128-bit integer (represented as bigint) */ readonly int128: () => TypeValidator; /** Int256 - signed 256-bit integer (represented as bigint) */ readonly int256: () => TypeValidator; /** UInt8 - unsigned 8-bit integer (0 to 255) */ readonly uint8: () => TypeValidator; /** UInt16 - unsigned 16-bit integer */ readonly uint16: () => TypeValidator; /** UInt32 - unsigned 32-bit integer */ readonly uint32: () => TypeValidator; /** UInt64 - unsigned 64-bit integer (represented as number, may lose precision) */ readonly uint64: () => TypeValidator; /** UInt128 - unsigned 128-bit integer (represented as bigint) */ readonly uint128: () => TypeValidator; /** UInt256 - unsigned 256-bit integer (represented as bigint) */ readonly uint256: () => TypeValidator; /** Float32 - 32-bit floating point */ readonly float32: () => TypeValidator; /** Float64 - 64-bit floating point (double precision) */ readonly float64: () => TypeValidator; /** Decimal(precision, scale) - fixed-point decimal number */ readonly decimal: (precision: number, scale: number) => TypeValidator; /** Bool - boolean value (true/false) */ readonly bool: () => TypeValidator; /** Date - string in YYYY-MM-DD format (e.g. 2024-01-15) */ readonly date: () => TypeValidator; /** Date32 - string in YYYY-MM-DD format (e.g. 2024-01-15, extended date range) */ readonly date32: () => TypeValidator; /** DateTime - string in YYYY-MM-DD HH:MM:SS format (e.g. 2024-01-15 10:30:00) */ readonly dateTime: (timezone?: string) => TypeValidator | TypeValidator; /** DateTime64 - string in YYYY-MM-DD HH:MM:SS[.fraction] format (e.g. 2024-01-15 10:30:00.123) */ readonly dateTime64: (precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9, timezone?: string) => TypeValidator | TypeValidator; /** Array(T) - array of elements of type T */ readonly array: >(element: TElement) => TypeValidator; /** Tuple(T1, T2, ...) - tuple of heterogeneous types */ readonly tuple: []>(...elements: TElements) => TypeValidator<{ [K in keyof TElements]: TElements[K]["_type"]; }, `Tuple(${string})`, TypeModifiers>; /** Map(K, V) - dictionary/map type */ readonly map: , TValue extends TypeValidator>(keyType: TKey, valueType: TValue) => TypeValidator, `Map(${TKey["_tinybirdType"]}, ${TValue["_tinybirdType"]})`, TypeModifiers>; /** JSON - semi-structured JSON data */ readonly json: () => TypeValidator; /** Enum8 - enumeration stored as Int8 */ readonly enum8: (...values: TValues) => TypeValidator; /** Enum16 - enumeration stored as Int16 */ readonly enum16: (...values: TValues) => TypeValidator; /** IPv4 - IPv4 address */ readonly ipv4: () => TypeValidator; /** IPv6 - IPv6 address */ readonly ipv6: () => TypeValidator; /** SimpleAggregateFunction - for materialized views with simple aggregates */ readonly simpleAggregateFunction: >(func: TFunc, type: TType) => TypeValidator; /** AggregateFunction - for materialized views with complex aggregates */ readonly aggregateFunction: AggregateFunctionValidator; }; /** Type alias for any type validator */ export type AnyTypeValidator = TypeValidator; /** Extract the TypeScript type from a type validator */ export type InferType = T["_type"]; /** Extract the Tinybird type string from a type validator */ export type TinybirdType = T["_tinybirdType"]; /** Helper to check if a value is a type validator */ export declare function isTypeValidator(value: unknown): value is AnyTypeValidator; /** Get the Tinybird type string from a validator */ export declare function getTinybirdType(validator: AnyTypeValidator): string; /** Get the modifiers from a validator */ export declare function getModifiers(validator: AnyTypeValidator): TypeModifiers; export {}; //# sourceMappingURL=types.d.ts.map