import type { Codec } from "../Codecs"; import type { Routeway } from "../Routeways"; /** * Base structure of codec definitions. Useful for generic constraints. */ export type CodecMap = Record>; /** * Defines the type of path, which is any string that starts with a `/` char. */ export type PathLike = `/${string}`; /** * Transform a record of codecs to a record based on the types of each codec. */ export type CodecsToRecord = { [K in keyof T]: T[K] extends Codec ? V : never; }; /** * Merges the path variables and query parameter in a single object. * * @param V the record type of the path variables * @param Q the record type of the query parameters */ export type RouteParams< V extends CodecMap, Q extends CodecMap, > = CodecsToRecord & Partial>; /** * Infers the query parameters type of a route. * * @example * ``` * type UsersQueryParams = InferQueryParams; * // ^ type = { search?: string; page?: number; } * ``` * * @param T the type of the route to make the infer */ export type InferQueryParams = T extends Routeway> ? Partial> : never; export function safeKeys(obj: T): Extract[] { const keys = Object.keys(obj).filter(key => key in obj); return keys as Extract[]; } export function isValidDate(date: Date): boolean { return !isNaN(date.getTime()); }