Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit f5ced71

Browse files
authored
fix(deps): Updates to core v7. (#13)
BREAKING CHANGE: Updates to [core v7](https://github.com/js-entity-repos/core/releases/tag/v7.0.0).
1 parent 03a6f03 commit f5ced71

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"check-coverage": true
2626
},
2727
"dependencies": {
28-
"@js-entity-repos/core": "^6.0.2",
28+
"@js-entity-repos/core": "^7.1.0",
2929
"lodash": "^4.17.4",
3030
"mongodb": "^3.0.0"
3131
},

src/functions/getEntities.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import GetEntities from '@js-entity-repos/core/dist/signatures/GetEntities';
22
import 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';
35
import Sort from '@js-entity-repos/core/dist/types/Sort';
6+
import SortOrder, { asc } from '@js-entity-repos/core/dist/types/SortOrder';
47
import createCursorFromEntity from '@js-entity-repos/core/dist/utils/createCursorFromEntity';
58
import createPaginationFilter from '@js-entity-repos/core/dist/utils/createPaginationFilter';
69
import { first, last, mapValues } from 'lodash';
@@ -11,21 +14,21 @@ const xor = (conditionA: boolean, conditionB: boolean) => {
1114
};
1215

1316
export 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

Comments
 (0)