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

Commit dc47fe5

Browse files
authored
fix(deps): Updates core to 6.0.2. (#11)
BREAKING CHANGE: The `filter`, `sort`, and `paginate` options are now optional. BREAKING CHANGE: The `upsertEntity` function has been removed due to filter issues. BREAKING CHANGE: The `overwriteEntity` function was renamed to `replaceEntity`. BREAKING CHANGE: Removes Id interface from all functions.
1 parent 7833e7f commit dc47fe5

40 files changed

+319
-264
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
command: npm run lint
3939
- run:
4040
name: Checking Code Duplication
41-
command: npm run duplication -- --limit 10
41+
command: npm run duplication -- --limit 15
4242
- deploy:
4343
name: Semantic Release
4444
command: npm run semantic-release

package-lock.json

Lines changed: 13 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
"check-coverage": true
2626
},
2727
"dependencies": {
28-
"@js-entity-repos/core": "^4.1.2",
28+
"@js-entity-repos/core": "^6.0.2",
2929
"axios": "^0.17.1",
3030
"http-status-codes": "^1.3.0",
3131
"lodash": "^4.17.4"
3232
},
3333
"devDependencies": {
3434
"@ht2-labs/semantic-release": "1.0.27",
3535
"@ht2-labs/typescript-project": "1.0.9",
36-
"@js-entity-repos/memory": "1.0.3",
36+
"@js-entity-repos/memory": "^3.0.0",
3737
"@types/body-parser": "1.16.8",
3838
"@types/dotenv": "4.0.2",
3939
"@types/express": "4.11.1",

readme.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,59 @@
44
### Usage
55
1. Install it with `npm i @js-entity-repos/axios`.
66
1. For each entity you will need to do the following.
7-
1. [Create Id and Entity interfaces](#id-and-entity-interface).
8-
1. [Create a facade config](#facade-config).
9-
1. [Construct the facade with the config and interfaces](#calling-the-facade).
7+
1. [Create an Entity interface](#entity-interface).
8+
1. [Create a factory config](#factory-config).
9+
1. [Construct the facade](#construct-the-facade).
1010
1. [Use the facade](https://github.com/js-entity-repos/core/blob/master/docs/facade.md).
1111

12-
### Id and Entity Interface
12+
### Entity Interface
1313

1414
```ts
15-
export interface TodoId {
16-
readonly id: string;
17-
}
15+
import Entity from '@js-entity-repos/core/dist/types/Entity';
1816

19-
export interface TodoEntity extends TodoId {
17+
export interface TodoEntity extends Entity {
2018
readonly description: string;
2119
readonly completed: boolean;
2220
}
2321
```
2422

25-
### Facade Config
23+
### Factory Config
2624

2725
```ts
28-
import FacadeConfig from '@js-entity-repos/axios/dist/Config';
29-
import connectToDb from '@js-entity-repos/axios/dist/utils/connectToDb';
26+
import FactoryConfig from '@js-entity-repos/axios/dist/FactoryConfig';
3027
import axios from 'axios';
3128

32-
const todoFacadeConfig: FacadeConfig = {
29+
const todoFactoryConfig: FactoryConfig = {
3330
axios: axios.create({
3431
baseURL: `http://localhost:80/api/todos`,
3532
}),
36-
constructDocument: (id, patch) => {
37-
// Converts an entity to a document for the database.
38-
return { ...patch, ...id }
33+
constructDocument: (patch) => {
34+
// Optional property that converts an entity to a document for the database.
35+
return patch;
3936
},
4037
constructEntity: (document) => {
41-
// Converts a document from the database to an entity.
38+
// Optional property that converts a document from the database to an entity.
4239
return document;
4340
},
41+
constructFilter: (filter) => {
42+
// Optional property that converts an entity filter to a filter for the DB.
43+
return filter;
44+
},
45+
constructSort: (sort) => {
46+
// Optional property that converts an entity sort to a sort for the DB.
47+
return sort;
48+
},
49+
defaultPaginationLimit: 100, // Optional property.
4450
entityName: 'todo',
4551
};
4652
```
4753

48-
The tests in this package contain a [demonstration of how to implement an Express router for the functions in this facade](./src/utils/express).
54+
The tests in this package contain a [demonstration of how to implement an Express router for the functions in this facade](./src/utils/expressPresenter).
4955

5056
### Construct the Facade
5157

5258
```ts
53-
import facade from '@js-entity-repos/axios/dist/facade';
59+
import factory from '@js-entity-repos/axios/dist/factory';
5460

55-
const todosFacade = facade<TodoId, TodoEntity>(todoFacadeConfig);
61+
const todosFacade = factory(todoFactoryConfig);
5662
```

src/Config.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/FacadeConfig.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Entity from '@js-entity-repos/core/dist/types/Entity';
2+
import { Filter } from '@js-entity-repos/core/dist/types/Filter';
3+
import Sort from '@js-entity-repos/core/dist/types/Sort';
4+
import { AxiosInstance } from 'axios';
5+
6+
export type Document = any;
7+
8+
export default interface FacadeConfig<E extends Entity> {
9+
readonly axios: AxiosInstance;
10+
readonly constructDocument: (patch: Partial<E>) => Document;
11+
readonly constructEntity: (document: Document) => E;
12+
readonly constructFilter: (filter: Filter<E>) => any;
13+
readonly constructSort: (sort: Sort<E>) => any;
14+
readonly defaultPaginationLimit: number;
15+
readonly entityName: string;
16+
}

src/FactoryConfig.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Entity from '@js-entity-repos/core/dist/types/Entity';
2+
import { Filter } from '@js-entity-repos/core/dist/types/Filter';
3+
import Sort from '@js-entity-repos/core/dist/types/Sort';
4+
import { AxiosInstance } from 'axios';
5+
6+
export type Document = any;
7+
8+
export default interface FactoryConfig<E extends Entity> {
9+
readonly axios: AxiosInstance;
10+
readonly constructDocument?: (patch: Partial<E>) => Document;
11+
readonly constructEntity?: (document: Document) => E;
12+
readonly constructFilter?: (filter: Filter<E>) => any;
13+
readonly constructSort?: (sort: Sort<E>) => any;
14+
readonly defaultPaginationLimit?: number;
15+
readonly entityName: string;
16+
}

src/facade.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/facade.test.ts renamed to src/factory.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as sourceMapSupport from 'source-map-support';
22
sourceMapSupport.install();
33

44
import facadeTest from '@js-entity-repos/core/dist/tests';
5-
import { TestEntity, TestId } from '@js-entity-repos/core/dist/tests/utils/testEntity';
5+
import { TestEntity } from '@js-entity-repos/core/dist/tests/utils/testEntity';
66
import axios from 'axios';
77
import { config } from 'dotenv';
88
import 'mocha'; // tslint:disable-line:no-import-side-effect
9-
import facade from './facade';
9+
import factory from './factory';
1010
import createTestServer from './utils/createTestServer';
1111
config();
1212

@@ -27,15 +27,13 @@ before(async () => {
2727
});
2828

2929
after(async () => {
30-
const app = await testServer;
31-
app.close();
30+
const server = await testServer;
31+
server.close();
3232
});
3333

34-
facadeTest(facade<TestId, TestEntity>({
34+
facadeTest(factory<TestEntity>({
3535
axios: axios.create({
3636
baseURL: `http://localhost:${testServerPort}${testServerRoute}`,
3737
}),
38-
constructDocument: (id, patch) => ({ ...patch, ...id }),
39-
constructEntity: (document) => document,
4038
entityName: 'Test Entity',
4139
}));

src/factory.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Facade from '@js-entity-repos/core/dist/Facade';
2+
import Entity from '@js-entity-repos/core/dist/types/Entity';
3+
import FacadeConfig from './FacadeConfig';
4+
import FactoryConfig from './FactoryConfig';
5+
import countEntities from './functions/countEntities';
6+
import createEntity from './functions/createEntity';
7+
import getEntities from './functions/getEntities';
8+
import getEntity from './functions/getEntity';
9+
import patchEntity from './functions/patchEntity';
10+
import removeEntities from './functions/removeEntities';
11+
import removeEntity from './functions/removeEntity';
12+
import replaceEntity from './functions/replaceEntity';
13+
14+
export default <E extends Entity>(factoryConfig: FactoryConfig<E>): Facade<E> => {
15+
const facadeConfig: FacadeConfig<E> = {
16+
constructDocument: (patch) => patch,
17+
constructEntity: (document) => document,
18+
constructFilter: (filter) => filter,
19+
constructSort: (sort) => sort,
20+
defaultPaginationLimit: 100,
21+
...factoryConfig,
22+
};
23+
return {
24+
countEntities: countEntities<E>(facadeConfig),
25+
createEntity: createEntity<E>(facadeConfig),
26+
getEntities: getEntities<E>(facadeConfig),
27+
getEntity: getEntity<E>(facadeConfig),
28+
patchEntity: patchEntity<E>(facadeConfig),
29+
removeEntities: removeEntities<E>(facadeConfig),
30+
removeEntity: removeEntity<E>(facadeConfig),
31+
replaceEntity: replaceEntity<E>(facadeConfig),
32+
};
33+
};

0 commit comments

Comments
 (0)