Skip to content

Commit

Permalink
chore(geo): resolve swiftformat errors and warnings (#3849)
Browse files Browse the repository at this point in the history
* chore(geo): resolve swiftformat errors and warnings

* updated swiftformat rules

* update rules
  • Loading branch information
phantumcode authored Oct 10, 2024
1 parent 748755e commit b10caf8
Show file tree
Hide file tree
Showing 21 changed files with 491 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

import AWSLocation

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {

// MARK: - Search

Expand All @@ -30,8 +30,10 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func search(for text: String,
options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place] {
func search(
for text: String,
options: Geo.SearchForTextOptions? = nil
) async throws -> [Geo.Place] {

var request = SearchPlaceIndexForTextInput()

Expand All @@ -41,21 +43,26 @@ extension AWSLocationGeoPlugin {
guard request.indexName != nil else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingDefaultSearchIndex.errorDescription,
GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion)
GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion
)
}

request.text = text

if let area = options?.area {
switch area {
case .near(let coordinates):
request.biasPosition = [coordinates.longitude,
coordinates.latitude]
request.biasPosition = [
coordinates.longitude,
coordinates.latitude
]
case .within(let boundingBox):
request.filterBBox = [boundingBox.southwest.longitude,
boundingBox.southwest.latitude,
boundingBox.northeast.longitude,
boundingBox.northeast.latitude]
request.filterBBox = [
boundingBox.southwest.longitude,
boundingBox.southwest.latitude,
boundingBox.northeast.longitude,
boundingBox.northeast.latitude
]
}
}

Expand All @@ -73,9 +80,7 @@ extension AWSLocationGeoPlugin {
let response = try await locationService.searchPlaceIndex(forText: request)
var results = [LocationClientTypes.Place]()
if let responseResults = response.results {
results = responseResults.compactMap {
$0.place
}
results = responseResults.compactMap(\.place)
}

let places: [Geo.Place] = results.compactMap {
Expand All @@ -85,16 +90,18 @@ extension AWSLocationGeoPlugin {
return nil
}

return Geo.Place(coordinates: Geo.Coordinates(latitude: lat, longitude: long),
label: $0.label,
addressNumber: $0.addressNumber,
street: $0.street,
municipality: $0.municipality,
neighborhood: $0.neighborhood,
region: $0.region,
subRegion: $0.subRegion,
postalCode: $0.postalCode,
country: $0.country)
return Geo.Place(
coordinates: Geo.Coordinates(latitude: lat, longitude: long),
label: $0.label,
addressNumber: $0.addressNumber,
street: $0.street,
municipality: $0.municipality,
neighborhood: $0.neighborhood,
region: $0.region,
subRegion: $0.subRegion,
postalCode: $0.postalCode,
country: $0.country
)
}
return places
} catch let error as GeoErrorConvertible {
Expand Down Expand Up @@ -123,8 +130,10 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func search(for coordinates: Geo.Coordinates,
options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place] {
func search(
for coordinates: Geo.Coordinates,
options: Geo.SearchForCoordinatesOptions? = nil
) async throws -> [Geo.Place] {

var request = SearchPlaceIndexForPositionInput()

Expand All @@ -134,11 +143,14 @@ extension AWSLocationGeoPlugin {
guard request.indexName != nil else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingDefaultSearchIndex.errorDescription,
GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion)
GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion
)
}

request.position = [coordinates.longitude,
coordinates.latitude]
request.position = [
coordinates.longitude,
coordinates.latitude
]

if let maxResults = options?.maxResults {
request.maxResults = maxResults as Int
Expand All @@ -148,9 +160,7 @@ extension AWSLocationGeoPlugin {
let response = try await locationService.searchPlaceIndex(forPosition: request)
var results = [LocationClientTypes.Place]()
if let responseResults = response.results {
results = responseResults.compactMap {
$0.place
}
results = responseResults.compactMap(\.place)
}

let places: [Geo.Place] = results.compactMap {
Expand All @@ -160,16 +170,18 @@ extension AWSLocationGeoPlugin {
return nil
}

return Geo.Place(coordinates: Geo.Coordinates(latitude: lat, longitude: long),
label: $0.label,
addressNumber: $0.addressNumber,
street: $0.street,
municipality: $0.municipality,
neighborhood: $0.neighborhood,
region: $0.region,
subRegion: $0.subRegion,
postalCode: $0.postalCode,
country: $0.country)
return Geo.Place(
coordinates: Geo.Coordinates(latitude: lat, longitude: long),
label: $0.label,
addressNumber: $0.addressNumber,
street: $0.street,
municipality: $0.municipality,
neighborhood: $0.neighborhood,
region: $0.region,
subRegion: $0.subRegion,
postalCode: $0.postalCode,
country: $0.country
)
}
return places
} catch let error as GeoErrorConvertible {
Expand All @@ -194,12 +206,13 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func availableMaps() async throws -> [Geo.MapStyle] {
func availableMaps() async throws -> [Geo.MapStyle] {
let mapStyles = Array(pluginConfig.maps.values)
guard !mapStyles.isEmpty else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingMaps.errorDescription,
GeoPluginErrorConstants.missingMaps.recoverySuggestion)
GeoPluginErrorConstants.missingMaps.recoverySuggestion
)
}
return mapStyles
}
Expand All @@ -213,11 +226,12 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func defaultMap() async throws -> Geo.MapStyle {
func defaultMap() async throws -> Geo.MapStyle {
guard let mapName = pluginConfig.defaultMap, let mapStyle = pluginConfig.maps[mapName] else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingDefaultMap.errorDescription,
GeoPluginErrorConstants.missingDefaultMap.recoverySuggestion)
GeoPluginErrorConstants.missingDefaultMap.recoverySuggestion
)
}
return mapStyle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

import Foundation
@_spi(InternalAmplifyConfiguration) import Amplify
import AWSClientRuntime
import AWSLocation
import AWSPluginsCore
@_spi(PluginHTTPClientEngine) import InternalAmplifyCredentials
import AWSLocation
import AWSClientRuntime

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {
/// Configures AWSLocationPlugin with the specified configuration.
///
/// This method will be invoked as part of the Amplify configuration flow.
///
/// - Parameter configuration: The configuration specified for this plugin.
/// - Throws:
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty.
public func configure(using configuration: Any?) throws {
func configure(using configuration: Any?) throws {
let pluginConfiguration: AWSLocationGeoPluginConfiguration
if let configuration = configuration as? AmplifyOutputsData {
pluginConfiguration = try AWSLocationGeoPluginConfiguration(config: configuration)
Expand All @@ -34,7 +34,7 @@ extension AWSLocationGeoPlugin {
}

/// Configure AWSLocationPlugin programatically using AWSLocationPluginConfiguration
public func configure(using configuration: AWSLocationGeoPluginConfiguration) throws {
func configure(using configuration: AWSLocationGeoPluginConfiguration) throws {
let authService = AWSAuthService()
let credentialsProvider = authService.getCredentialsProvider()
let region = configuration.regionName
Expand All @@ -49,9 +49,11 @@ extension AWSLocationGeoPlugin {
let location = LocationClient(config: serviceConfiguration)
let locationService = AWSLocationAdapter(location: location)

configure(locationService: locationService,
authService: authService,
pluginConfig: configuration)
configure(
locationService: locationService,
authService: authService,
pluginConfig: configuration
)
}

// MARK: - Internal
Expand All @@ -64,9 +66,11 @@ extension AWSLocationGeoPlugin {
/// - locationService: The location service object.
/// - authService: The authentication service object.
/// - pluginConfig: The configuration for the plugin.
func configure(locationService: AWSLocationBehavior,
authService: AWSAuthServiceBehavior,
pluginConfig: AWSLocationGeoPluginConfiguration) {
internal func configure(
locationService: AWSLocationBehavior,
authService: AWSAuthServiceBehavior,
pluginConfig: AWSLocationGeoPluginConfiguration
) {
self.locationService = locationService
self.authService = authService
self.pluginConfig = pluginConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import Amplify
import Foundation

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {

/// Resets the state of the plugin.
///
/// Sets stored objects to nil to allow deallocation, then calls onComplete closure
/// to signal the reset has completed.
public func reset() async {
func reset() async {
locationService = nil
authService = nil
pluginConfig = nil
Expand Down
Loading

0 comments on commit b10caf8

Please sign in to comment.