11import GetEntities from '@js-entity-repos/core/dist/signatures/GetEntities' ;
22import Entity from '@js-entity-repos/core/dist/types/Entity' ;
3+ import Pagination from '@js-entity-repos/core/dist/types/Pagination' ;
4+ import { forward } from '@js-entity-repos/core/dist/types/PaginationDirection' ;
35import Sort from '@js-entity-repos/core/dist/types/Sort' ;
6+ import SortOrder , { asc } from '@js-entity-repos/core/dist/types/SortOrder' ;
47import createCursorFromEntity from '@js-entity-repos/core/dist/utils/createCursorFromEntity' ;
58import createPaginationFilter from '@js-entity-repos/core/dist/utils/createPaginationFilter' ;
69import { first , last , mapValues } from 'lodash' ;
@@ -11,21 +14,21 @@ const xor = (conditionA: boolean, conditionB: boolean) => {
1114} ;
1215
1316export default < E extends Entity > ( config : FacadeConfig < E > ) : GetEntities < E > => {
14- const defaultPagination = {
17+ const defaultPagination : Pagination = {
1518 cursor : undefined ,
16- forward : true ,
19+ direction : forward ,
1720 limit : config . defaultPaginationLimit ,
1821 } ;
19- const defaultSort = { id : true } as Sort < E > ;
22+ const defaultSort = { id : asc } as Sort < E > ;
2023 return async ( { filter = { } , sort = defaultSort , pagination = defaultPagination } ) => {
2124 const collection = ( await config . collection ( ) ) ;
2225
2326 const paginationFilter = createPaginationFilter ( pagination , sort ) ;
2427 const fullFilter = { $and : [ filter , paginationFilter ] } ;
2528 const constructedFilter = config . constructFilter ( fullFilter ) ;
2629 const constructedSort = config . constructSort ( sort ) ;
27- const mongoSort = mapValues ( constructedSort , ( sortValue : boolean ) => {
28- return ! xor ( pagination . forward , sortValue ) ? 1 : - 1 ;
30+ const mongoSort = mapValues ( constructedSort , ( sortOrder : SortOrder ) => {
31+ return ! xor ( pagination . direction === forward , sortOrder === asc ) ? 1 : - 1 ;
2932 } ) ;
3033
3134 const documents = await collection
0 commit comments