Merge pull request #662 from GetStream/feat/filters
feat(llc): add `Filter.contains` and `Filter.empty`
This commit is contained in:
@@ -107,6 +107,48 @@ The 'exists' filter matches values that exist, or don't exist, based on the spec
|
|||||||
Filter.exists('name', true)
|
Filter.exists('name', true)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Filter.contains
|
||||||
|
|
||||||
|
The 'contains' filter matches any list that contains the specified value.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Filter.contains('teams', 'red')
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Filter.empty
|
||||||
|
|
||||||
|
The 'empty' filter constructor returns an empty filter. It's the equivalent of an empty map `{}`;
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Filter.empty();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Filter.raw
|
||||||
|
|
||||||
|
The 'raw' filter constructor lets you specify a raw filter. We suggest using this only if you can't manage to build what you want using the other constructors.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Filter.raw(value: {
|
||||||
|
'members': [
|
||||||
|
..._selectedUsers.map((e) => e.id),
|
||||||
|
chatState.currentUser!.id,
|
||||||
|
],
|
||||||
|
'distinct': true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Filter.custom
|
||||||
|
|
||||||
|
The 'custom' filter is used to create a custom filter in case it does not exists or it's not been added to the SDK yet.
|
||||||
|
Note that the filter must be supported by the Stream backend in order to work.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Filter.custom(
|
||||||
|
operator: '\$max',
|
||||||
|
value: 10,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
### Group Queries
|
### Group Queries
|
||||||
|
|
||||||
#### Filter.and
|
#### Filter.and
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
- `updatePinnedMessageReactions`
|
- `updatePinnedMessageReactions`
|
||||||
- `deletePinnedMessageReactionsByMessageId`
|
- `deletePinnedMessageReactionsByMessageId`
|
||||||
|
|
||||||
|
✅ Added
|
||||||
|
|
||||||
|
- Added `Filter.contains` and `Filter.empty`
|
||||||
|
|
||||||
## 2.2.1
|
## 2.2.1
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ enum FilterOperator {
|
|||||||
|
|
||||||
/// Matches none of the values specified in an array.
|
/// Matches none of the values specified in an array.
|
||||||
nor,
|
nor,
|
||||||
|
|
||||||
|
/// Matches any list that contains the specified value
|
||||||
|
contains,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper extension for [FilterOperator]
|
/// Helper extension for [FilterOperator]
|
||||||
@@ -71,6 +74,7 @@ extension FilterOperatorX on FilterOperator {
|
|||||||
FilterOperator.and: '\$and',
|
FilterOperator.and: '\$and',
|
||||||
FilterOperator.or: '\$or',
|
FilterOperator.or: '\$or',
|
||||||
FilterOperator.nor: '\$nor',
|
FilterOperator.nor: '\$nor',
|
||||||
|
FilterOperator.contains: '\$contains',
|
||||||
}[this]!;
|
}[this]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +161,10 @@ class Filter extends Equatable {
|
|||||||
factory Filter.exists(String key, {bool exists = true}) =>
|
factory Filter.exists(String key, {bool exists = true}) =>
|
||||||
Filter._(operator: FilterOperator.exists, key: key, value: exists);
|
Filter._(operator: FilterOperator.exists, key: key, value: exists);
|
||||||
|
|
||||||
|
/// Matches any list that contains the specified values
|
||||||
|
factory Filter.contains(String key, Object value) =>
|
||||||
|
Filter._(operator: FilterOperator.contains, key: key, value: value);
|
||||||
|
|
||||||
/// Creates a custom [Filter] if there isn't one already available.
|
/// Creates a custom [Filter] if there isn't one already available.
|
||||||
const factory Filter.custom({
|
const factory Filter.custom({
|
||||||
required Object value,
|
required Object value,
|
||||||
@@ -164,6 +172,9 @@ class Filter extends Equatable {
|
|||||||
String? key,
|
String? key,
|
||||||
}) = Filter.__;
|
}) = Filter.__;
|
||||||
|
|
||||||
|
/// An empty filter
|
||||||
|
factory Filter.empty() => const Filter.raw(value: {});
|
||||||
|
|
||||||
/// Creates a custom [Filter] from a raw map value
|
/// Creates a custom [Filter] from a raw map value
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
|
|||||||
@@ -138,6 +138,20 @@ void main() {
|
|||||||
expect(filter.value, value);
|
expect(filter.value, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('empty', () {
|
||||||
|
final filter = Filter.empty();
|
||||||
|
expect(filter.value, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('contains', () {
|
||||||
|
const key = 'testKey';
|
||||||
|
const values = 'testValue';
|
||||||
|
final filter = Filter.contains(key, values);
|
||||||
|
expect(filter.key, key);
|
||||||
|
expect(filter.value, values);
|
||||||
|
expect(filter.operator, FilterOperator.contains.rawValue);
|
||||||
|
});
|
||||||
|
|
||||||
group('groupedOperator', () {
|
group('groupedOperator', () {
|
||||||
final filter1 = Filter.equal('testKey', 'testValue');
|
final filter1 = Filter.equal('testKey', 'testValue');
|
||||||
final filter2 = Filter.in_('testKey', const ['testValue']);
|
final filter2 = Filter.in_('testKey', const ['testValue']);
|
||||||
|
|||||||
Reference in New Issue
Block a user