UNPKG

cassandra-codegen

Version:

Generate type definitions from a Cassandra database

26 lines (25 loc) 1.07 kB
import { mapping } from "cassandra-driver"; export type PartitionKey<T> = T & { __partitionKey: never; }; export type Clustering<T, ClusteringOrder> = T & { __clustering: never; }; export type CodegenQueryOperator<T> = mapping.q.QueryOperator & T; type IfNotNever<T, K> = T extends never ? never : K; export type DrainOuterGeneric<T> = [T] extends [unknown] ? T : never; export type PartitionKeyType<T> = T extends PartitionKey<infer U> ? U | CodegenQueryOperator<U> : never; export type PrimaryKeyType<T> = T extends (PartitionKey<infer U> | Clustering<infer U, any>) ? U | CodegenQueryOperator<U> : never; type NonNeverPartitionKeys<T> = { [K in keyof T]: IfNotNever<PartitionKeyType<T[K]>, K>; }[keyof T]; type NonNeverPrimaryKeys<T> = { [K in keyof T]: IfNotNever<PrimaryKeyType<T[K]>, K>; }[keyof T]; export type PartitionKeyColumns<T> = DrainOuterGeneric<{ [K in NonNeverPartitionKeys<T>]: PartitionKeyType<T[K]>; }>; export type PrimaryKeyColumns<T> = DrainOuterGeneric<{ [K in NonNeverPrimaryKeys<T>]: PrimaryKeyType<T[K]>; }>; export {};