Skip to content

Commit

Permalink
updated swiftformat rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 9, 2024
1 parent baa308c commit 9becf9e
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public 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
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 @@ -42,21 +43,26 @@ public 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 Down Expand Up @@ -84,16 +90,18 @@ public 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 @@ -122,9 +130,10 @@ public 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
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 @@ public 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 @@ -158,16 +170,18 @@ public 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 @@ -197,7 +211,8 @@ public extension AWSLocationGeoPlugin {
guard !mapStyles.isEmpty else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingMaps.errorDescription,
GeoPluginErrorConstants.missingMaps.recoverySuggestion)
GeoPluginErrorConstants.missingMaps.recoverySuggestion
)
}
return mapStyles
}
Expand All @@ -215,7 +230,8 @@ public extension AWSLocationGeoPlugin {
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 @@ -49,9 +49,11 @@ public 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,10 +66,11 @@ public extension AWSLocationGeoPlugin {
/// - locationService: The location service object.
/// - authService: The authentication service object.
/// - pluginConfig: The configuration for the plugin.
internal 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 @@ -22,18 +22,24 @@ public struct AWSLocationGeoPluginConfiguration {
public let regionName: String

init(config: JSONValue) throws {
let configObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .plugin,
configJSON: config)
let configObject = try AWSLocationGeoPluginConfiguration.getConfigObject(
section: .plugin,
configJSON: config
)
let regionName = try AWSLocationGeoPluginConfiguration.getRegion(configObject)

var maps = [String: Geo.MapStyle]()
var defaultMap: String?
if let mapsConfigJSON = configObject[Section.maps.key] {
let mapsConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .maps,
configJSON: mapsConfigJSON)
let mapsConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(
section: .maps,
configJSON: mapsConfigJSON
)
maps = try AWSLocationGeoPluginConfiguration.getMaps(mapConfig: mapsConfigObject, regionName: regionName)
defaultMap = try AWSLocationGeoPluginConfiguration.getDefault(section: .maps,
configObject: mapsConfigObject)
defaultMap = try AWSLocationGeoPluginConfiguration.getDefault(
section: .maps,
configObject: mapsConfigObject
)
guard let map = defaultMap, maps[map] != nil else {
throw GeoPluginConfigError.mapDefaultNotFound(mapName: defaultMap)
}
Expand All @@ -42,23 +48,31 @@ public struct AWSLocationGeoPluginConfiguration {
var searchIndices = [String]()
var defaultSearchIndex: String?
if let searchConfigJSON = configObject[Section.searchIndices.key] {
let searchConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .searchIndices,
configJSON: searchConfigJSON)
searchIndices = try AWSLocationGeoPluginConfiguration.getItemsStrings(section: .searchIndices,
configObject: searchConfigObject)
defaultSearchIndex = try AWSLocationGeoPluginConfiguration.getDefault(section: .searchIndices,
configObject: searchConfigObject)
let searchConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(
section: .searchIndices,
configJSON: searchConfigJSON
)
searchIndices = try AWSLocationGeoPluginConfiguration.getItemsStrings(
section: .searchIndices,
configObject: searchConfigObject
)
defaultSearchIndex = try AWSLocationGeoPluginConfiguration.getDefault(
section: .searchIndices,
configObject: searchConfigObject
)

guard let index = defaultSearchIndex, searchIndices.contains(index) else {
throw GeoPluginConfigError.searchDefaultNotFound(indexName: defaultSearchIndex)
}
}

self.init(regionName: regionName,
defaultMap: defaultMap,
maps: maps,
defaultSearchIndex: defaultSearchIndex,
searchIndices: searchIndices)
self.init(
regionName: regionName,
defaultMap: defaultMap,
maps: maps,
defaultSearchIndex: defaultSearchIndex,
searchIndices: searchIndices
)
}

init(config: AmplifyOutputsData) throws {
Expand All @@ -71,7 +85,8 @@ public struct AWSLocationGeoPluginConfiguration {
if let geoMaps = geo.maps {
maps = try AWSLocationGeoPluginConfiguration.getMaps(
mapConfig: geoMaps,
regionName: geo.awsRegion)
regionName: geo.awsRegion
)
defaultMap = geoMaps.default

// Validate that the default map exists in `maps`
Expand All @@ -91,19 +106,22 @@ public struct AWSLocationGeoPluginConfiguration {
}
}

self.init(regionName: geo.awsRegion,
defaultMap: defaultMap,
maps: maps,
defaultSearchIndex: defaultSearchIndex,
searchIndices: searchIndices)
self.init(
regionName: geo.awsRegion,
defaultMap: defaultMap,
maps: maps,
defaultSearchIndex: defaultSearchIndex,
searchIndices: searchIndices
)
}

init(regionName: String,
defaultMap: String?,
maps: [String: Geo.MapStyle],
defaultSearchIndex: String?,
searchIndices: [String])
{
init(
regionName: String,
defaultMap: String?,
maps: [String: Geo.MapStyle],
defaultSearchIndex: String?,
searchIndices: [String]
) {
self.regionName = regionName
self.defaultMap = defaultMap
self.maps = maps
Expand Down Expand Up @@ -163,9 +181,10 @@ public struct AWSLocationGeoPluginConfiguration {
return itemsJSON
}

private static func getItemsObject(section: Section,
configObject: [String: JSONValue]) throws -> [String: JSONValue]
{
private static func getItemsObject(
section: Section,
configObject: [String: JSONValue]
) throws -> [String: JSONValue] {
let itemsJSON = try getItemsJSON(section: section, configObject: configObject)
let itemsObject = try getConfigObject(section: section, configJSON: itemsJSON)
return itemsObject
Expand Down Expand Up @@ -202,8 +221,10 @@ public struct AWSLocationGeoPluginConfiguration {
throw GeoPluginConfigError.mapStyleIsNotString(mapName: mapName)
}

let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName,
mapName: mapName))
let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(
regionName: regionName,
mapName: mapName
))
guard let styleURL = url else {
throw GeoPluginConfigError.mapStyleURLInvalid(mapName: mapName)
}
Expand All @@ -217,12 +238,15 @@ public struct AWSLocationGeoPluginConfiguration {
return mapStyles
}

private static func getMaps(mapConfig: AmplifyOutputsData.Geo.Maps,
regionName: String) throws -> [String: Geo.MapStyle]
{
private static func getMaps(
mapConfig: AmplifyOutputsData.Geo.Maps,
regionName: String
) throws -> [String: Geo.MapStyle] {
let mapTuples: [(String, Geo.MapStyle)] = try mapConfig.items.map { map in
let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName,
mapName: map.key))
let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(
regionName: regionName,
mapName: map.key
))
guard let styleURL = url else {
throw GeoPluginConfigError.mapStyleURLInvalid(mapName: map.key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import Foundation
enum GeoPluginErrorConstants {
static let missingDefaultSearchIndex: GeoPluginErrorString = (
"No default search index was found.",
"Please ensure you have added search to your project before calling search functions.")
"Please ensure you have added search to your project before calling search functions."
)

static let missingDefaultMap: GeoPluginErrorString = (
"No default map was found.",
"Please ensure you have added maps to your project before calling map-related functions.")
"Please ensure you have added maps to your project before calling map-related functions."
)

static let missingMaps: GeoPluginErrorString = (
"No maps are available.",
"Please ensure you have added maps to your project before calling map-related functions.")
"Please ensure you have added maps to your project before calling map-related functions."
)
}

// Recovery Messages
Expand Down
Loading

0 comments on commit 9becf9e

Please sign in to comment.