-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract models into a separate Core module #437
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,23 +2,64 @@ | |||||
|
||||||
import PackageDescription | ||||||
|
||||||
let MeiliSearch = "MeiliSearch" | ||||||
let MeiliSearchCore = "MeiliSearchCore" | ||||||
let MeiliSearchNIO = "MeiliSearchNIO" | ||||||
|
||||||
var products: [PackageDescription.Product] = [ | ||||||
.library(name: MeiliSearch, targets: [MeiliSearch]), | ||||||
.library(name: MeiliSearchCore, targets: [MeiliSearchCore]) | ||||||
] | ||||||
|
||||||
var dependencies = [PackageDescription.Package.Dependency]() | ||||||
|
||||||
var targets: [PackageDescription.Target] = [ | ||||||
.target( | ||||||
name: MeiliSearch, | ||||||
dependencies: [ | ||||||
.target(name: MeiliSearchCore) | ||||||
] | ||||||
), | ||||||
.target( | ||||||
name: MeiliSearchCore, | ||||||
dependencies: [] | ||||||
), | ||||||
.testTarget( | ||||||
name: "MeiliSearchUnitTests", | ||||||
dependencies: ["MeiliSearch"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: where we reference target names, let's be consistent and use the static variable
Suggested change
|
||||||
), | ||||||
.testTarget( | ||||||
name: "MeiliSearchIntegrationTests", | ||||||
dependencies: ["MeiliSearch"] | ||||||
) | ||||||
] | ||||||
|
||||||
#if os(Linux) || USE_NIO | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment: I like the use of |
||||||
products.append(.library(name: MeiliSearchNIO, targets: [MeiliSearchNIO])) | ||||||
dependencies.append(.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0")) | ||||||
targets.append( | ||||||
.target( | ||||||
name: MeiliSearchNIO, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. major: this PR will currently fail to build as-is due to this target path not existing. shall we delete this entire Linux section until you contribute the NIO integration in your next PR? |
||||||
dependencies: [ | ||||||
.product(name: "AsyncHTTPClient", package: "async-http-client"), | ||||||
.target(name: MeiliSearchCore) | ||||||
] | ||||||
) | ||||||
) | ||||||
|
||||||
targets.append( | ||||||
.testTarget( | ||||||
name: "MeiliSearchNIOTests", | ||||||
dependencies: [ | ||||||
.target(name: MeiliSearchNIO) | ||||||
] | ||||||
) | ||||||
) | ||||||
#endif | ||||||
|
||||||
let package = Package( | ||||||
name: "meilisearch-swift", | ||||||
products: [ | ||||||
.library(name: "MeiliSearch", targets: ["MeiliSearch"]) | ||||||
], | ||||||
targets: [ | ||||||
.target( | ||||||
name: "MeiliSearch", | ||||||
dependencies: [] | ||||||
), | ||||||
.testTarget( | ||||||
name: "MeiliSearchUnitTests", | ||||||
dependencies: ["MeiliSearch"] | ||||||
), | ||||||
.testTarget( | ||||||
name: "MeiliSearchIntegrationTests", | ||||||
dependencies: ["MeiliSearch"] | ||||||
) | ||||||
] | ||||||
products: products, | ||||||
dependencies: dependencies, | ||||||
targets: targets | ||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import Foundation | ||
import MeiliSearchCore | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import Foundation | ||
import MeiliSearchCore | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import Foundation | ||
import MeiliSearchCore | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
|
||
public struct ErrorResponse: Error, Codable, Hashable { | ||
/// A human-readable description of the error | ||
public let message: String | ||
|
||
/// The error code (https://www.meilisearch.com/docs/reference/errors/error_codes) | ||
public let code: String | ||
|
||
/// The error type (https://www.meilisearch.com/docs/reference/errors/overview#errors) | ||
public let type: String | ||
|
||
/// A link to the relevant section of the documentation | ||
public let link: String? | ||
|
||
public init(message: String, code: String, type: String, link: String? = nil) { | ||
self.message = message | ||
self.code = code | ||
self.type = type | ||
self.link = link | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
internal struct PackageVersion { | ||
public struct PackageVersion { | ||
/// This is the current version of the meilisearch-swift package | ||
private static let current = "0.15.0" | ||
public static let current = "0.15.0" | ||
Comment on lines
-8
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: why has the access level of this variable changed? where else is it used?
Comment on lines
-8
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: let's make sure we update the documentation where this line of code is referenced (the path to this file)
Comment on lines
-8
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: let's make sure we update the Podspec where this line of code is referenced (the path to this file) |
||
|
||
/** | ||
Retrieves the current version of the MeiliSearch Swift package and formats accordingly. | ||
|
||
- returns: String containing the qualified version of this package eg. `Meilisearch Swift (v1.0.0)` | ||
*/ | ||
static func qualifiedVersion(_ rawVersion: String? = nil) -> String { | ||
public static func qualifiedVersion(_ rawVersion: String? = nil) -> String { | ||
"Meilisearch Swift (v\(rawVersion ?? self.current))" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
|
||
public struct UpdateIndexPayload: Codable { | ||
public let primaryKey: String | ||
|
||
public init(primaryKey: String) { | ||
self.primaryKey = primaryKey | ||
} | ||
} | ||
|
||
public struct CreateIndexPayload: Codable { | ||
public let uid: String | ||
public let primaryKey: String? | ||
|
||
public init(uid: String, primaryKey: String? = nil) { | ||
self.uid = uid | ||
self.primaryKey = primaryKey | ||
} | ||
} | ||
|
||
public struct SwapIndexPayload: Codable, Equatable { | ||
public let indexes: [String] | ||
|
||
public init(indexes: [String]) { | ||
self.indexes = indexes | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: this new target should not break the Podspec as it does a global search for all Swift files within the Sources directory, however when we do add the NIO target it will fail to compile due to the lack of the dependency.
AHC (or NIO) is not available officially on CocoaPods, so this will be a SPM-only feature. I'm okay with that but we must document it and ensure that CocoaPods does continue to work (even if only using Foundation).