Skip to content

Commit

Permalink
feat(types): DTOFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed May 28, 2021
1 parent fde654a commit b861719
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion __tests__/__fixtures__/cars.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { MangoFinderOptionsDTO } from '@/dtos'
import type { MangoCacheFinder } from '@/interfaces'
import type { MangoParsedUrlQuery, MangoSearchParams, UID } from '@/types'
import type {
DTOFilter,
MangoParsedUrlQuery,
MangoSearchParams,
UID
} from '@/types'
import { IsNotEmpty, IsNumber, IsString } from 'class-validator'

/**
Expand All @@ -19,6 +24,8 @@ export type CarUID = 'vin'
export type CarParams = MangoSearchParams<ICar>
export type CarQuery = MangoParsedUrlQuery<ICar>

export type CarDTOFilter = DTOFilter<ICar, 'make' | 'model' | 'model_year'>

export class Car implements ICar {
@IsString()
@IsNotEmpty()
Expand Down
26 changes: 25 additions & 1 deletion src/types/repository.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import type { ObjectEmpty, ObjectPlain } from '@flex-development/tutils'
import type {
DeepPartialByRequiredHelper,
ObjectEmpty,
ObjectPlain,
ObjectUnknown,
Path
} from '@flex-development/tutils'
import type { UID } from './utils.types'

/**
* @file Type Definitions - Repositories
* @module types/repository
*/

/**
* DTO filter object.
*
* @template E - Entity
* @template P - Required object field paths
* @template F - Object field path filter object. Omits fields
*
* @example
* interface IUser{ ... }
* type Filter = DTOFilter<IUser, 'first_name', { created_at: never }>
*/
export type DTOFilter<
E extends ObjectPlain = ObjectUnknown,
P extends Path<E> = Path<E>,
/* eslint-disable-next-line @typescript-eslint/ban-types */
F extends Partial<Record<Path<E>, never>> = {}
> = DeepPartialByRequiredHelper<E, P, F>

/**
* Type representing the root of a repository.
*
Expand Down

0 comments on commit b861719

Please sign in to comment.