diff --git a/lib/src/client.dart b/lib/src/client.dart index 604a08e1..2d7129dc 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -32,6 +32,10 @@ abstract class MeiliSearchClient { /// Find index by matching [uid]. Throws error if index is not exists. Future getIndex(String uid); + /// Find index by matching [uid] and responds with raw information from API. + /// Throws error if index is not exists. + Future> getRawIndex(String uid); + /// Create a new index by given [uid] and optional [primaryKey] parameter. /// Throws an error if index is already exists. Future createIndex(String uid, {String primaryKey}); diff --git a/lib/src/client_impl.dart b/lib/src/client_impl.dart index 2b13d37a..6108bbe1 100644 --- a/lib/src/client_impl.dart +++ b/lib/src/client_impl.dart @@ -52,12 +52,22 @@ class MeiliSearchClientImpl implements MeiliSearchClient { @override Future getIndex(String uid) async { - final response = - await http.getMethod>('/indexes/$uid'); + final response = await _getIndex(uid); return MeiliSearchIndexImpl.fromMap(this, response.data!); } + @override + Future> getRawIndex(String uid) async { + final response = await _getIndex(uid); + + return response.data!; + } + + Future>> _getIndex(String uid) { + return http.getMethod>('/indexes/$uid'); + } + @override Future> getIndexes() async { final response = await http.getMethod>('/indexes'); diff --git a/test/indexes_test.dart b/test/indexes_test.dart index 4523012a..92a4f68c 100644 --- a/test/indexes_test.dart +++ b/test/indexes_test.dart @@ -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()));