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

Commit ccb868d

Browse files
committed
docs(filter): Moves filter docs into options for simplicity.
1 parent 41d69b6 commit ccb868d

File tree

3 files changed

+71
-73
lines changed

3 files changed

+71
-73
lines changed

docs/filter.md

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

docs/functions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The [facade](./facade.md) contains common functions for storage and retrieval of
1212
- [replaceEntity](#replaceentity)
1313

1414
### countEntities
15-
Counts the number of entities that match the [`filter`](./filter.md) option.
15+
Counts the number of entities that match the [`filter`](./options.md#filter) option.
1616

1717
```ts
1818
const { count } = await facade.countEntities({
@@ -44,7 +44,7 @@ try {
4444
This package contains the [create entity tests](../src/tests/createEntity) and the [create entity signature](../src/signatures/CreateEntity.ts) for this function.
4545

4646
### getEntities
47-
Retreives a sorted paginated array of entities that match the [`filter`](./filter.md) option.
47+
Retreives a sorted paginated array of entities that match the [`filter`](./options.md#filter) option.
4848

4949
```ts
5050
const { entities, nextCursor, previousCursor } = await facade.getEntities({
@@ -67,7 +67,7 @@ const firstPage = await facade.getEntities({
6767
This package contains the [get entities tests](../src/tests/getEntities) and the [get entities signature](../src/signatures/GetEntities.ts) for this function.
6868

6969
### getEntity
70-
Retrieves a single entity that matches the [`id`](./options.md#id) and [`filter`](./filter.md) options.
70+
Retrieves a single entity that matches the [`id`](./options.md#id) and [`filter`](./options.md#filter) options.
7171

7272
```ts
7373
import MissingEntityError from 'js-entity-repos/core/dist/errors/MissingEntityError';
@@ -88,7 +88,7 @@ try {
8888
This package contains the [get entity tests](../src/tests/getEntity) and the [get entity signature](../src/signatures/GetEntity.ts) for this function.
8989

9090
### patchEntity
91-
For an entity that matches the [`id`](./options.md#id) and [`filter`](./filter.md) options, it changes some of an entity's properties using the [`patch`](./options.md#patch) option.
91+
For an entity that matches the [`id`](./options.md#id) and [`filter`](./options.md#filter) options, it changes some of an entity's properties using the [`patch`](./options.md#patch) option.
9292

9393
```ts
9494
import MissingEntityError from 'js-entity-repos/core/dist/errors/MissingEntityError';
@@ -110,7 +110,7 @@ try {
110110
This package contains the [patch entity tests](../src/tests/patchEntity) and the [patch entity signature](../src/signatures/PatchEntity.ts) for this function.
111111

112112
### removeEntities
113-
Removes all entities that match the [`filter`](./filter.md) option.
113+
Removes all entities that match the [`filter`](./options.md#filter) option.
114114

115115
```ts
116116
await facade.removeEntities({
@@ -121,7 +121,7 @@ await facade.removeEntities({
121121
This package contains the [remove entities tests](../src/tests/removesEntities) and the [remove entities signature](../src/signatures/RemoveEntities.ts) for this function.
122122

123123
### removeEntity
124-
Removes an entity that matches the [`id`](./options.md#id) and [`filter`](./filter.md) options.
124+
Removes an entity that matches the [`id`](./options.md#id) and [`filter`](./options.md#filter) options.
125125

126126
```ts
127127
import MissingEntityError from 'js-entity-repos/core/dist/errors/MissingEntityError';
@@ -142,7 +142,7 @@ try {
142142
This package contains the [remove entity tests](../src/tests/removesEntity) and the [remove entity signature](../src/signatures/RemoveEntity.ts) for this function.
143143

144144
### replaceEntity
145-
For an entity that matches the [`id`](./options.md#id) and [`filter`](./filter.md) options, it changes all of an entity's properties using the [`entity`](./options.md#entity) option.
145+
For an entity that matches the [`id`](./options.md#id) and [`filter`](./options.md#filter) options, it changes all of an entity's properties using the [`entity`](./options.md#entity) option.
146146

147147
```ts
148148
import MissingEntityError from 'js-entity-repos/core/dist/errors/MissingEntityError';

docs/options.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The [facade](./facade.md) [functions](./functions.md) have some common options t
55
- [Id](#id)
66
- [Entity](#entity)
77
- [Patch](#patch)
8-
- [Filter](./filter.md)
8+
- [Filter](#filter.md)
99
- [Sort](#sort)
1010
- [Pagination](#pagination)
1111

@@ -36,7 +36,69 @@ interface TodoEntity extends Entity {
3636
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>`).
3737

3838
### Filter
39-
This is an object that filters the entities. More information can be found in the [filter documentation](./filter.md). This package contains the [TypeScript Filter type definition](../src/types/Filter.ts).
39+
This is an object that filters the entities. The [filter type definition](../src/types/Filter.ts) currently supports the following operators which have been [borrowed from Mongo](https://docs.mongodb.com/manual/reference/operator/query/).
40+
41+
Operator | Description
42+
--- | ---
43+
[$and](https://docs.mongodb.com/manual/reference/operator/query/and/#op._S_and) | Includes entities where all of the specified filters are true.
44+
[$or](https://docs.mongodb.com/manual/reference/operator/query/or/#op._S_or) | Includes entities where some of the specified filters are true.
45+
[$nor](https://docs.mongodb.com/manual/reference/operator/query/nor/#op._S_nor) | Includes entities where some of the specified filters are false.
46+
[$not](https://docs.mongodb.com/manual/reference/operator/query/no/#op._S_no) | Includes entities where a specified filter is not true.
47+
[$eq](https://docs.mongodb.com/manual/reference/operator/query/eq/#op._S_eq) | Includes entities where the value of a given property is equal to the specified value.
48+
[$ne](https://docs.mongodb.com/manual/reference/operator/query/ne/#op._S_ne) | Includes entities where the value of a given property is not equal to the specified value.
49+
[$lt](https://docs.mongodb.com/manual/reference/operator/query/lt/#op._S_lt) | Includes entities where the value of a given property is less than the specified value.
50+
[$lte](https://docs.mongodb.com/manual/reference/operator/query/lt/#op._S_lt) | Includes entities where the value of a given property is less than or equal to the specified value.
51+
[$gt](https://docs.mongodb.com/manual/reference/operator/query/gt/#op._S_gt) | Includes entities where the value of a given property is greater than the specified value.
52+
[$gte](https://docs.mongodb.com/manual/reference/operator/query/gt/#op._S_gt) | Includes entities where the value of a given property is greater than or equal to the specified value.
53+
[$in](https://docs.mongodb.com/manual/reference/operator/query/in/#op._S_in) | Includes entities where the value of a given property is equal to one of the specified values.
54+
[$nin](https://docs.mongodb.com/manual/reference/operator/query/ni/#op._S_ni) | Includes entities where the value of a given property is not equal to any of the specified values.
55+
56+
The filter below is comprehensive example using all of the operators.
57+
58+
```json
59+
{
60+
"$or": [
61+
{
62+
"numberProp1": {
63+
"$not": {
64+
"$gt": 0,
65+
"$lt": 1
66+
}
67+
}
68+
},
69+
{
70+
"$and": [
71+
{
72+
"stringProp1": "string value 1",
73+
"numberProp2": {
74+
"$gte": 0,
75+
"$lte": 1
76+
},
77+
"numberProp3": { "$ne": 0 },
78+
"numberProp4": { "$eq": 0 }
79+
},
80+
{
81+
"stringProp2": {
82+
"$in": ["string value 2", "string value 3"]
83+
},
84+
"stringProp3": {
85+
"$nin": ["string value 4", "string value 5"]
86+
}
87+
}
88+
]
89+
},
90+
,
91+
{
92+
"$nor": [
93+
{
94+
"stringProp4": "string value 6"
95+
}
96+
]
97+
}
98+
]
99+
}
100+
```
101+
40102

41103
### Sort
42104
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.

0 commit comments

Comments
 (0)