Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ abstract class MeiliSearchClient {
/// Find index by matching [uid]. Throws error if index is not exists.
Future<MeiliSearchIndex> getIndex(String uid);

/// Find index by matching [uid] and responds with raw information from API.
/// Throws error if index is not exists.
Future<Map<String, dynamic>> getRawIndex(String uid);

/// Create a new index by given [uid] and optional [primaryKey] parameter.
/// Throws an error if index is already exists.
Future<TaskInfo> createIndex(String uid, {String primaryKey});
Expand Down
14 changes: 12 additions & 2 deletions lib/src/client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,22 @@ class MeiliSearchClientImpl implements MeiliSearchClient {

@override
Future<MeiliSearchIndex> getIndex(String uid) async {
final response =
await http.getMethod<Map<String, dynamic>>('/indexes/$uid');
final response = await _getIndex(uid);

return MeiliSearchIndexImpl.fromMap(this, response.data!);
}

@override
Future<Map<String, dynamic>> getRawIndex(String uid) async {
final response = await _getIndex(uid);

return response.data!;
}

Future<Response<Map<String, dynamic>>> _getIndex(String uid) {
return http.getMethod<Map<String, dynamic>>('/indexes/$uid');
}

@override
Future<List<MeiliSearchIndex>> getIndexes() async {
final response = await http.getMethod<List<dynamic>>('/indexes');
Expand Down
13 changes: 13 additions & 0 deletions test/indexes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ void main() {
expect(index.primaryKey, null);
});

test('gets raw information about an index', () async {
final uid = randomUid();
await client.createIndex(uid).waitFor();

final index = await client.getRawIndex(uid);
final keys = ['uid', 'name', 'primaryKey', 'createdAt', 'updatedAt'];

expect(index.keys, containsAll(keys));
expect(index.keys.length, keys.length);
expect(index['primaryKey'], isNull);
expect(index['name'], equals(uid));
});

test('throws exception with a non-existing index', () async {
expect(client.getIndex(randomUid('loremIpsum')),
throwsA(isA<MeiliSearchApiException>()));
Expand Down