move types to helper file
This commit is contained in:
parent
ebc31004c5
commit
0241c86ea2
27
src/helper.ts
Normal file
27
src/helper.ts
Normal file
@ -0,0 +1,27 @@
|
||||
type Join<K, P> = K extends string ? (P extends string ? `${K}${'' extends P ? '' : '.'}${P}` : never) : never
|
||||
|
||||
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]
|
||||
|
||||
export type Column<T, D extends number = 2> = [D] extends [never]
|
||||
? never
|
||||
: T extends Record<string, any>
|
||||
? {
|
||||
[K in keyof T]-?: K extends string
|
||||
? T[K] extends Date
|
||||
? `${K}`
|
||||
: T[K] extends Array<infer U>
|
||||
? `${K}` | Join<K, Column<U, Prev[D]>>
|
||||
: `${K}` | Join<K, Column<T[K], Prev[D]>>
|
||||
: never
|
||||
}[keyof T]
|
||||
: ''
|
||||
|
||||
export type RelationColumn<T> = Extract<
|
||||
Column<T>,
|
||||
{
|
||||
[K in Column<T>]: K extends `${infer R}.${string}` ? R : never
|
||||
}[Column<T>]
|
||||
>
|
||||
|
||||
export type Order<T> = [Column<T>, 'ASC' | 'DESC']
|
||||
export type SortBy<T> = Order<T>[]
|
@ -20,31 +20,7 @@ import { ServiceUnavailableException } from '@nestjs/common'
|
||||
import { values, mapKeys } from 'lodash'
|
||||
import { stringify } from 'querystring'
|
||||
import { WherePredicateOperator } from 'typeorm/query-builder/WhereClause'
|
||||
import { Join, Prev } from './utils'
|
||||
|
||||
type Column<T, D extends number = 2> = [D] extends [never]
|
||||
? never
|
||||
: T extends Record<string, any>
|
||||
? {
|
||||
[K in keyof T]-?: K extends string
|
||||
? T[K] extends Date
|
||||
? `${K}`
|
||||
: T[K] extends Array<infer U>
|
||||
? `${K}` | Join<K, Column<U, Prev[D]>>
|
||||
: `${K}` | Join<K, Column<T[K], Prev[D]>>
|
||||
: never
|
||||
}[keyof T]
|
||||
: ''
|
||||
|
||||
type RelationColumn<T> = Extract<
|
||||
Column<T>,
|
||||
{
|
||||
[K in Column<T>]: K extends `${infer R}.${string}` ? R : never
|
||||
}[Column<T>]
|
||||
>
|
||||
|
||||
type Order<T> = [Column<T>, 'ASC' | 'DESC']
|
||||
type SortBy<T> = Order<T>[]
|
||||
import { Column, Order, RelationColumn, SortBy } from './helper'
|
||||
|
||||
export class Paginated<T> {
|
||||
data: T[]
|
||||
|
@ -1,3 +0,0 @@
|
||||
export type Join<K, P> = K extends string ? (P extends string ? `${K}${'' extends P ? '' : '.'}${P}` : never) : never
|
||||
|
||||
export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]
|
Loading…
Reference in New Issue
Block a user