|
2 | 2 |
|
3 | 3 | The [facade](./facade.md) [functions](./functions.md) have some common options that they use.
|
4 | 4 |
|
5 |
| -- [Entity](#entity) |
6 | 5 | - [Id](#id)
|
| 6 | +- [Entity](#entity) |
7 | 7 | - [Patch](#patch)
|
8 | 8 | - [Filter](#filter)
|
9 | 9 | - [Sort](#sort)
|
10 | 10 | - [Pagination](#pagination)
|
11 | 11 |
|
| 12 | +### Id |
| 13 | +This is an object that contains only the properties required to distinctly identify an entity. In most common cases there is a single property making the [unique key](https://en.wikipedia.org/wiki/Unique_key) so it will likely just contain the `id` property. However, for entities with multiple properties making the unique key it will contain those properties. |
| 14 | + |
| 15 | +This interface is user-defined hence not contained in this package, the interface below demonstrates what this will look like in most cases. |
| 16 | + |
| 17 | +```ts |
| 18 | +interface Id { |
| 19 | + readonly id: string; |
| 20 | +} |
| 21 | +``` |
| 22 | + |
12 | 23 | ### Entity
|
13 | 24 | This is an object contains all of the entity's properties. The word "entity" has been borrowed from Entity-Relationship Models/Diagrams and has been used instead of the word "model" to avoid confusion with MVC.
|
14 | 25 |
|
15 |
| -### Id |
16 |
| -This is an object that contains only the properties required to distinctly identify an entity. In most common cases there is a single property making the [unique key](https://en.wikipedia.org/wiki/Unique_key) so it will likely just contain the `id` property. However, for entities with multiple properties making the unique key it will contain those properties. |
| 26 | +This interface is user-defined hence not contained in this package, the interface below demonstrates what this might look like for a todo entity and extends the [Id interface from the Id example](#id). |
| 27 | + |
| 28 | +```ts |
| 29 | +interface TodoEntity extends Id { |
| 30 | + readonly description: string; |
| 31 | + readonly completed: boolean; |
| 32 | +} |
| 33 | +``` |
17 | 34 |
|
18 | 35 | ### Patch
|
19 |
| -This is an object containing some of the entity's properties. |
| 36 | +This is an object containing some of the entity's properties. This package uses [TypeScript's Partial type](https://www.typescriptlang.org/docs/handbook/advanced-types.html) applied to an [Entity](#entity) (using `Partial<Entity>`). |
20 | 37 |
|
21 | 38 | ### Filter
|
22 | 39 | This is an object that filters the entities. More information can be found in the [filter documentation](./filter.md).
|
23 | 40 |
|
24 | 41 | ### Sort
|
25 | 42 | This is an object where a key represents the entity property to be sorted and the value represents the direction to sort. The value should be `true` to sort in ascending order and `false` to sort in descending order. The properties are sorted in order of their definition in the sort option, for example, the following sort option `{ createdAt: false, id: true }` will sort by the `createdAt` property first and then the the `id` property.
|
26 | 43 |
|
| 44 | +This package contains the [TypeScript Sort type definition](../src/types/Sort.ts) |
| 45 | + |
27 | 46 | ### Pagination
|
28 | 47 | This is an object with three properties, `limit`, `forward`, and `cursor`. The `limit` property defines how many entities to return (maximum). The `forward` property defines whether the entities should be iterate through the entities forwards (when `true`) or backwards (when `false`) from the `cursor`. The `cursor` property defines where to start iterating through the entities.
|
29 | 48 |
|
30 |
| -Concrete implementations of the facade can use the [`createCursorFromEntity`](../src/utils/createCursorFromEntity) and [`createPaginationFilter`](../src/utils/createPaginationFilter) util functions to generate cursors. |
| 49 | +Concrete implementations of the facade can use the [`createCursorFromEntity`](../src/utils/createCursorFromEntity) and [`createPaginationFilter`](../src/utils/createPaginationFilter) util functions to generate cursors. |
| 50 | + |
| 51 | +This package also contains the [TypeScript Pagination interface](../src/types/Pagination.ts) and the [TypeScript Cursor type definition](../src/types/Cursor.ts). |
0 commit comments