import { SnakeToCamel, SnakeToPascal } from '@waiting/shared-types' /** * kmore.tables, tables dict of the database * * @example * ```ts * type { * tb_user: 'tb_user' * tb_user_ext: 'tb_user_ext' * } * ``` */ export type DictTables = { [TbName in keyof D]: TbName & string } /** * @returns * ```ts * type { * tb_user: { * uid: 'uid' * name: 'name' * }, * tb_user_ext: {}, * } * ``` */ export type DictColumns = { [TbName in keyof D]: Columns } /** * @returns * ```ts * type { * tb_user: { * uid: "tb_user.uid" * uid: "tb_user.name" * }, * * tb_user_ext: {}, * } * ``` */ export type DictScoped = { [TbName in keyof D]: ScopedColumns } /** * @returns * ```ts * type { * tb_user: { * uid: { tbUserUid: "tb_user.uid" } * name: { tbUserName: "tb_user.name" } * }, * tb_user_ext: {}, * } * ``` */ export type DictAlias = { [TbName in keyof D]: AliasColumns } export type Columns = { [F in keyof T]: F } export type ScopedColumns = { [F in keyof T]: `${K}.${F & string}` } export type AliasColumns = { [F in keyof T]: Record<`${SnakeToCamel}${SnakeToPascal}`, `${K}.${F & string}`> } export type TableAlias = string export type TableColAlias = string export type TableName = string export type FieldName = string export type FilePath = string export type FileName = string export type CallerFuncNameSet = Set /** * Name of the function * for call expression such as `genDbDict()` */ export type CallerFuncName = string /** * Build tables columns type * ```ts * type { * tb_user: { * uid: number * name: string * tbUserUid: number * tbUserName: string * 'tb_user.uid': number * 'tb_user.name': string * }, * tb_user_ext: { * ... * } * } * ``` */ export type DbDictType = { [TbName in keyof D]: TableFieldsType } /** * Build table columns type * ```ts * type { * uid: number * name: string * tbUserUid: number * tbUserName: string * 'tb_user.uid': number * 'tb_user.name': string * } * ``` */ export type TableFieldsType = ColumnsType & ScopedColumnsType & AliasColumnsType /** * Build table columns type * ```ts * type { * uid: number * name: string * } * ``` */ export type ColumnsType = { [F in keyof T]: T[F] } /** * Build table scoped columns type * ```ts * type { * 'tb_user.uid': number * 'tb_user.name': string * } * ``` */ export type ScopedColumnsType = { [F in keyof T as `${K}.${F & string}`]: T[F] } /** * Build table alias columns type * ```ts * type { * tbUserUid: number * tbUserName: string * } * ``` */ export type AliasColumnsType = { [F in keyof T as `${SnakeToCamel}${SnakeToPascal}`]: T[F] }