typesense / typesense-swift

Swift Client for Typesense ⚡️🔎
https://typesense.org/docs/
Apache License 2.0
39 stars 16 forks source link

Throw better errors, allow search grouping of multiple fields with different data type, bug fixes 🐛 , ... #35

Closed phiHero closed 2 months ago

phiHero commented 2 months ago

Change Summary

Fixes:

Features:

// type of num_employees is Int, country is String and metadata is Boolean
// before, if we try grouping these fields together, Swift will throw a decoding error 
let searchParams = SearchParameters(q: "*", queryBy: "company_name", groupBy: "num_employees,country,metadata")
let (data, _) =  try await client.collection(name: "companies").documents().search(searchParams, for: Company.self)

if let groupKey = data?.groupedHits?.first?.groupKey{
    if let num_employees = groupKey[0].value as? Int{
        print(num_employees)
    }
   // do the same for country and metadata
}
do {
    let (data, _) = try await client.keys().retrieve(id: 1)
    // all endpoints will now throw HTTPError client & server error
} catch HTTPError.clientError(let code, let desc){
    print(code, desc)
} catch HTTPError.serverError(let code, let desc){
    print(code, desc)
    // instead of ResponseError
    // catch ResponseError.apiKeyNotFound(let desc) {
    //            print(desc)
    // }
} catch (let error) {
    print(error)
}

Deprecation

// `/documents` endpoint
// deprecated 
func delete(filter: String, batchSize: Int? = nil) async throws -> (Data?, URLResponse?)
func importBatch(_ documents: Data, action: ActionModes? = ActionModes.create) async throws -> (Data?, URLResponse?)
// in favor of
func delete(options: DeleteDocumentsParameters) async throws -> (DeleteDocumentsResponse?, URLResponse?)
func importBatch(_ documents: Data, options: ImportDocumentsParameters) async throws -> (Data?, URLResponse?)

PR Checklist