Skip to content

Commit

Permalink
Merge #305
Browse files Browse the repository at this point in the history
305: Changes related to the next Meilisearch release (v0.28.0) r=brunoocasali a=meili-bot

Related to this issue: meilisearch/integration-guides#205

This PR:
- gathers the changes related to the next Meilisearch release (v0.28.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.28.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.28.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._


Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
  • Loading branch information
3 people authored Aug 4, 2022
2 parents 8b97325 + 29631df commit 545fb26
Show file tree
Hide file tree
Showing 45 changed files with 1,035 additions and 653 deletions.
2 changes: 1 addition & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ get_all_tasks_1: |-
}
}
get_one_key_1: |-
self.client.getKey(key: "d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4") { result in
self.client.getKey(keyOrUid: "d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4") { result in
switch result {
case .success(let key):
print(key)
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,8 @@ Output:
- "Drama"
- offset: 0
- limit: 20
- nbHits: 1
▿ exhaustiveNbHits: Optional(false)
- some: false
- facetsDistribution: nil
- exhaustiveFacetsCount: nil
- estimatedTotalHits: 1
- facetDistribution: nil
▿ processingTimeMs: Optional(1)
- some: 1
▿ query: Optional("philoudelphia")
Expand All @@ -190,7 +187,7 @@ Since Meilisearch is typo-tolerant, the movie `philadelphia` is a valid search r

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).

## 💡 Learn More

Expand Down
61 changes: 27 additions & 34 deletions Sources/MeiliSearch/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct MeiliSearch {
public func createIndex(
uid: String,
primaryKey: String? = nil,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
Indexes.create(uid: uid, primaryKey: primaryKey, config: self.config, completion)
}

Expand All @@ -93,8 +93,9 @@ public struct MeiliSearch {
value. If the request was sucessful or `Error` if a failure occured.
*/
public func getIndexes(
_ completion: @escaping (Result<[Index], Swift.Error>) -> Void) {
Indexes.getAll(config: self.config, completion)
params: IndexesQuery? = nil,
_ completion: @escaping (Result<IndexesResults, Swift.Error>) -> Void) {
Indexes.getAll(config: self.config, params: params, completion)
}

/**
Expand All @@ -109,7 +110,7 @@ public struct MeiliSearch {
public func updateIndex(
uid: String,
primaryKey: String,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.index(uid).update(primaryKey: primaryKey, completion)
}

Expand All @@ -123,7 +124,7 @@ public struct MeiliSearch {
*/
public func deleteIndex(
_ uid: String,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.index(uid).delete(completion)
}

Expand Down Expand Up @@ -163,6 +164,14 @@ public struct MeiliSearch {
self.tasks.waitForTask(task: task, options: options, completion)
}

public func waitForTask(
task: TaskInfo,
options: WaitOptions? = nil,
_ completion: @escaping (Result<Task, Swift.Error>
) -> Void) {
self.tasks.waitForTask(taskUid: task.taskUid, options: options, completion)
}

// MARK: Tasks

/**
Expand All @@ -180,15 +189,17 @@ public struct MeiliSearch {
}

/**
Get all tasks.
List tasks based on an optional pagination criteria

- parameter completion: The completion closure used to notify when the server
- parameter params: A TasksQuery object with pagination metadata.
completes the query request, it returns a `Result` object that contains `Key` value.
If the request was sucessful or `Error` if a failure occured.
*/
public func getTasks(
_ completion: @escaping (Result<Results<Task>, Swift.Error>) -> Void) {
self.tasks.getAll(completion)
params: TasksQuery? = nil,
_ completion: @escaping (Result<TasksResults, Swift.Error>) -> Void) {
self.tasks.getTasks(params: params, completion)
}

// MARK: Keys
Expand All @@ -201,22 +212,23 @@ public struct MeiliSearch {
If the request was sucessful or `Error` if a failure occured.
*/
public func getKeys(
_ completion: @escaping (Result<Results<Key>, Swift.Error>) -> Void) {
self.keys.getAll(completion)
params: KeysQuery? = nil,
_ completion: @escaping (Result<KeysResults, Swift.Error>) -> Void) {
self.keys.getAll(params: params, completion)
}

/**
Get one key's information using the key value.

- parameter key: The key value.
- parameter keyOrUid: The key value.
- parameter completion: The completion closure used to notify when the server
completes the query request, it returns a `Result` object that contains `Key` value.
If the request was sucessful or `Error` if a failure occured.
*/
public func getKey(
key: String,
keyOrUid: String,
_ completion: @escaping (Result<Key, Swift.Error>) -> Void) {
self.keys.get(key: key, completion)
self.keys.get(key: keyOrUid, completion)
}

/**
Expand Down Expand Up @@ -244,7 +256,7 @@ public struct MeiliSearch {
*/
public func updateKey(
key: String,
keyParams: KeyParams,
keyParams: KeyUpdateParams,
_ completion: @escaping (Result<Key, Swift.Error>) -> Void) {
self.keys.update(
key: key,
Expand Down Expand Up @@ -336,26 +348,7 @@ public struct MeiliSearch {
value that can be used later to check the status of the dump.
If the request was successful or `Error` if a failure occurred.
*/
public func createDump(_ completion: @escaping (Result<Dump, Swift.Error>) -> Void) {
public func createDump(_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.dumps.create(completion)
}

/**
Get the status of a dump creation process using the uid returned after calling the dump creation route.
The returned status could be:

`Dump.Status.inProgress`: Dump creation is in progress.
`Dump.Status.failed`: An error occurred during the dump process, and the task was aborted.
`Dump.Status.done`: Dump creation is finished and was successful.

- parameter completion: The completion closure used to notify when the server
completes the dump request, it returns a `Dump` object that contains `uid`
value that can be used later to check the status of the Dump.
If the request was successful or `Error` if a failure occurred.
*/
public func getDumpStatus(
_ uid: String,
_ completion: @escaping (Result<Dump, Swift.Error>) -> Void) {
self.dumps.status(uid, completion)
}
}
59 changes: 29 additions & 30 deletions Sources/MeiliSearch/Documents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@ struct Documents {
func get<T>(
_ uid: String,
_ identifier: String,
fields: [String]? = nil,
_ completion: @escaping (Result<T, Swift.Error>) -> Void)
where T: Codable, T: Equatable {
let query: String = "/indexes/\(uid)/documents/\(identifier)"
var query: String = "/indexes/\(uid)/documents/\(identifier)"

if fields != nil {
let fieldsQuery = "?fields=\(fields?.joined(separator: ",") ?? "")"
query.append(fieldsQuery)
}

self.request.get(api: query) { result in
switch result {
case .success(let data):
guard let data: Data = data else {
completion(.failure(MeiliSearch.Error.dataNotFound))
return
}
Documents.decodeJSON(data, completion: completion)

Documents.decodeJSON(data, completion: completion)
case .failure(let error):
completion(.failure(error))
}
Expand All @@ -36,30 +43,22 @@ struct Documents {

func getAll<T>(
_ uid: String,
_ options: GetParameters? = nil,
_ completion: @escaping (Result<[T], Swift.Error>) -> Void)
params: DocumentsQuery? = nil,
_ completion: @escaping (Result<DocumentsResults<T>, Swift.Error>) -> Void)
where T: Codable, T: Equatable {
do {
var queryParameters = ""
if let parameters: GetParameters = options {
queryParameters = try parameters.toQueryParameters()
}
let query: String = "/indexes/\(uid)/documents\(queryParameters)"
request.get(api: query) { result in
switch result {
case .success(let data):
guard let data: Data = data else {
completion(.failure(MeiliSearch.Error.dataNotFound))
return
}
Documents.decodeJSON(data, completion: completion)

case .failure(let error):
completion(.failure(error))
let queryParams = params?.toQuery() ?? ""

request.get(api: "/indexes/\(uid)/documents\(queryParams)") { result in
switch result {
case .success(let data):
guard let data: Data = data else {
completion(.failure(MeiliSearch.Error.dataNotFound))
return
}
Documents.decodeJSON(data, completion: completion)
case .failure(let error):
completion(.failure(error))
}
} catch let error {
completion(.failure(error))
}
}

Expand All @@ -69,7 +68,7 @@ struct Documents {
_ uid: String,
_ document: Data,
_ primaryKey: String? = nil,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {

var query: String = "/indexes/\(uid)/documents"
if let primaryKey: String = primaryKey {
Expand All @@ -91,7 +90,7 @@ struct Documents {
_ documents: [T],
_ encoder: JSONEncoder? = nil,
_ primaryKey: String? = nil,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) where T: Encodable {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) where T: Encodable {
var query: String = "/indexes/\(uid)/documents"
if let primaryKey: String = primaryKey {
query += "?primaryKey=\(primaryKey)"
Expand Down Expand Up @@ -120,7 +119,7 @@ struct Documents {
_ uid: String,
_ document: Data,
_ primaryKey: String? = nil,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {

var query: String = "/indexes/\(uid)/documents"
if let primaryKey: String = primaryKey {
Expand All @@ -142,7 +141,7 @@ struct Documents {
_ documents: [T],
_ encoder: JSONEncoder? = nil,
_ primaryKey: String? = nil,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) where T: Encodable {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) where T: Encodable {

var query: String = "/indexes/\(uid)/documents"
if let primaryKey: String = primaryKey {
Expand Down Expand Up @@ -173,7 +172,7 @@ struct Documents {
func delete(
_ uid: String,
_ identifier: String,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {

self.request.delete(api: "/indexes/\(uid)/documents/\(identifier)") { result in
switch result {
Expand All @@ -192,7 +191,7 @@ struct Documents {

func deleteAll(
_ uid: String,
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {

self.request.delete(api: "/indexes/\(uid)/documents") { result in
switch result {
Expand All @@ -214,7 +213,7 @@ struct Documents {
func deleteBatch(
_ uid: String,
_ documentsIdentifiers: [Int],
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {

let data: Data

Expand Down
28 changes: 2 additions & 26 deletions Sources/MeiliSearch/Dumps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,12 @@ struct Dumps {

// MARK: Create

func create(_ completion: @escaping (Result<Dump, Swift.Error>) -> Void) {
func create(_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.request.post(api: "/dumps", Data()) { result in
switch result {
case .success(let data):
do {
let result: Dump = try Constants.customJSONDecoder.decode(Dump.self, from: data)
completion(.success(result))
} catch {
completion(.failure(error))
}
case .failure(let error):
completion(.failure(error))
}
}
}

// MARK: Status

func status(
_ uid: String,
_ completion: @escaping (Result<Dump, Swift.Error>) -> Void) {
self.request.get(api: "/dumps/\(uid)/status") { result in
switch result {
case .success(let data):
guard let data: Data = data else {
completion(.failure(MeiliSearch.Error.dataNotFound))
return
}
do {
let result: Dump = try Constants.customJSONDecoder.decode(Dump.self, from: data)
let result: TaskInfo = try Constants.customJSONDecoder.decode(TaskInfo.self, from: data)
completion(.success(result))
} catch {
completion(.failure(error))
Expand Down
Loading

0 comments on commit 545fb26

Please sign in to comment.