Skip to content
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

chore(geo): resolve swiftformat errors and warnings #3849

Open
wants to merge 3 commits into
base: chore/resolve_swiftformat
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading