{"version":3,"file":"common.cjs","sources":["../../../src/lib/helpers/common.ts"],"sourcesContent":["import type { Codec } from \"../Codecs\";\nimport type { Routeway } from \"../Routeways\";\n\n/**\n * Base structure of codec definitions. Useful for generic constraints.\n */\nexport type CodecMap = Record<string, Codec<unknown>>;\n\n/**\n * Defines the type of path, which is any string that starts with a `/` char.\n */\nexport type PathLike = `/${string}`;\n\n/**\n * Transform a record of codecs to a record based on the types of each codec.\n */\nexport type CodecsToRecord<T extends CodecMap> = {\n  [K in keyof T]: T[K] extends Codec<infer V>\n    ? V\n    : never;\n};\n\n/**\n * Merges the path variables and query parameter in a single object.\n *\n * @param V the record type of the path variables\n * @param Q the record type of the query parameters\n */\nexport type RouteParams<\n  V extends CodecMap,\n  Q extends CodecMap,\n> = CodecsToRecord<V> & Partial<CodecsToRecord<Q>>;\n\n/**\n * Infers the query parameters type of a route.\n *\n * @example\n * ```\n * type UsersQueryParams = InferQueryParams<typeof MainRoutes.home.users>;\n * //   ^ type = { search?: string; page?: number; }\n * ```\n *\n * @param T the type of the route to make the infer\n */\nexport type InferQueryParams<T extends Routeway> =\n  T extends Routeway<PathLike, CodecMap, infer Q, Record<never, Routeway>>\n    ? Partial<CodecsToRecord<Q>>\n    : never;\n\nexport function safeKeys<T extends object>(obj: T): Extract<keyof T, string>[] {\n  const keys = Object.keys(obj).filter(key => key in obj);\n\n  return keys as Extract<keyof T, string>[];\n}\n\nexport function isValidDate(date: Date): boolean {\n  return !isNaN(date.getTime());\n}\n"],"names":[],"mappings":";;AAiDO,SAAS,SAA2B,KAAoC;AACvE,QAAA,OAAO,OAAO,KAAK,GAAG,EAAE,OAAO,CAAA,QAAO,OAAO,GAAG;AAE/C,SAAA;AACT;AAEO,SAAS,YAAY,MAAqB;AAC/C,SAAO,CAAC,MAAM,KAAK,QAAS,CAAA;AAC9B;;;"}