Skip to content

Commit

Permalink
refactor(types)!: ProjectionCriteria -> Projection
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed May 13, 2021
1 parent 2edd850 commit e766561
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/projection-operators.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { QueryOperators } from './query-operators.interface'
*/

/**
* [Projection Selector][1] operators.
* [Projection Operators][1].
*
* [1]: https://docs.mongodb.com/manual/reference/operator/query/#projection-operators
*/
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
EntityPath,
OneOrMany,
PartialOr,
ProjectionCriteria,
Projection,
ProjectStage,
QueryParams,
RepoCache,
Expand Down Expand Up @@ -322,7 +322,7 @@ export default class Repository<
* @param {ProjectStage<E>} [params.$project] - Fields to include
* @param {number} [params.$skip] - Skips the first n entities
* @param {Record<EntityPath<E>, SortOrder>} [params.$sort] - Sorting rules
* @param {ProjectionCriteria<E>} [params.projection] - Projection operators
* @param {Projection<E>} [params.projection] - Projection operators
* @return {PartialOr<E>[]} Search results
* @throws {Exception}
*/
Expand Down
16 changes: 9 additions & 7 deletions src/types/mingo.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,25 @@ export type FieldPath<E extends IEntity = IEntity> = `$${EntityPath<E>}`
export type LiteralExpression<T = any> = { $literal: T }

/**
* [Aggregation Pipeline Stage - `$project`][1].
* Entity attributes mapped to [Projection Operators][1].
*
* @template E - Entity
*
* [1]: https://docs.mongodb.com/manual/reference/operator/aggregation/project
* [1]: https://docs.mongodb.com/manual/reference/operator/query/#projection-operators
*/
export type ProjectStage<E extends IEntity = IEntity> = Partial<
Record<EntityPath<E>, boolean | 0 | 1>
export type Projection<E extends IEntity = IEntity> = Partial<
Record<EntityPath<E>, ProjectionOperators>
>

/**
* Projection query parameters mapped to entity field names.
* [Aggregation Pipeline Stage - `$project`][1].
*
* @template E - Entity
*
* [1]: https://docs.mongodb.com/manual/reference/operator/aggregation/project
*/
export type ProjectionCriteria<E extends IEntity = IEntity> = Partial<
Record<EntityPath<E>, ProjectionOperators>
export type ProjectStage<E extends IEntity = IEntity> = Partial<
Record<EntityPath<E>, boolean | 0 | 1>
>

/**
Expand Down
4 changes: 2 additions & 2 deletions src/types/repository.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ClassType } from 'class-transformer-validator'
import { SortOrder } from '../enums/sort-order.enum'
import type { AggregationStages, IEntity } from '../interfaces'
import type { EmptyObject, ObjectPath } from './global.types'
import type { ProjectionCriteria, QueryCriteria } from './mingo.types'
import type { Projection, QueryCriteria } from './mingo.types'

/**
* @file Type Definitions - Repositories
Expand Down Expand Up @@ -57,7 +57,7 @@ export type EntityReadonlyProps = 'created_at' | 'id' | 'updated_at'
export type QueryParams<E extends IEntity = IEntity> = QueryCriteria<E> &
Pick<AggregationStages<E>, '$limit' | '$project' | '$skip'> & {
$sort?: Partial<Record<EntityPath<E>, SortOrder>>
projection?: ProjectionCriteria<E>
projection?: Projection<E>
}

/**
Expand Down

0 comments on commit e766561

Please sign in to comment.