diff --git a/Bible.xcodeproj/project.xcworkspace/xcuserdata/plarson.xcuserdatad/UserInterfaceState.xcuserstate b/Bible.xcodeproj/project.xcworkspace/xcuserdata/plarson.xcuserdatad/UserInterfaceState.xcuserstate index b3a1ce9..36a33cc 100644 Binary files a/Bible.xcodeproj/project.xcworkspace/xcuserdata/plarson.xcuserdatad/UserInterfaceState.xcuserstate and b/Bible.xcodeproj/project.xcworkspace/xcuserdata/plarson.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/BibleCore/Sources/BibleClient/Client.swift b/BibleCore/Sources/BibleClient/Client.swift new file mode 100644 index 0000000..cf9bba7 --- /dev/null +++ b/BibleCore/Sources/BibleClient/Client.swift @@ -0,0 +1,34 @@ +// +// BibleClient.swift +// TCA-Bible +// +// Created by Peter Larson on 7/18/23. +// + +import Foundation +import BibleCore +import ComposableArchitecture + +public struct BibleClient { + public var translations: @Sendable () async throws -> [Translation] + public var translation: @Sendable (TranslationID) async throws -> Translation + public var genres: @Sendable () async throws -> [Genre] + public var genre: @Sendable (GenreID) async throws -> Genre + public var books: @Sendable () async throws -> [Book] + public var book: @Sendable (BookID) async throws -> Book + public var chapters: @Sendable (BookID) async throws -> [Chapter] + public var verses: @Sendable (BookID, ChapterID) async throws -> [Verse] + public var verse: @Sendable (BookID, ChapterID, VerseID) async throws -> Verse +} + +extension DependencyValues { + public var bible: BibleClient { + get { + self[BibleClient.self] + } + + set { + self[BibleClient.self] = newValue + } + } +} diff --git a/BibleCore/Sources/BibleClient/BibleClient.swift b/BibleCore/Sources/BibleClient/Live.swift similarity index 70% rename from BibleCore/Sources/BibleClient/BibleClient.swift rename to BibleCore/Sources/BibleClient/Live.swift index 9e8f33d..9165999 100644 --- a/BibleCore/Sources/BibleClient/BibleClient.swift +++ b/BibleCore/Sources/BibleClient/Live.swift @@ -1,26 +1,7 @@ -// -// BibleClient.swift -// TCA-Bible -// -// Created by Peter Larson on 7/18/23. -// - import Foundation import BibleCore import ComposableArchitecture -public struct BibleClient { - public var translations: @Sendable () async throws -> [Translation] - public var translation: @Sendable (TranslationID) async throws -> Translation - public var genres: @Sendable () async throws -> [Genre] - public var genre: @Sendable (GenreID) async throws -> Genre - public var books: @Sendable () async throws -> [Book] - public var book: @Sendable (BookID) async throws -> Book - public var chapters: @Sendable (BookID) async throws -> [Chapter] - public var verses: @Sendable (BookID, ChapterID) async throws -> [Verse] - public var verse: @Sendable (BookID, ChapterID, VerseID) async throws -> Verse -} - fileprivate let decoder = JSONDecoder() extension BibleClient: DependencyKey { @@ -107,30 +88,6 @@ extension BibleClient: DependencyKey { ) } -enum BibleClientError: Error { - case unknown -} - -extension BibleClient { - public static var testValue: BibleClient = Self( - translations: { [.mock] }, - translation: { _ in .mock }, - genres: { [.mock] }, - genre: { _ in .mock }, - books: { [.genesis, .exodus, .leviticus] }, - book: { id in - guard let book = IdentifiedArray(uniqueElements: [Book].mock)[id: id] else { - throw BibleClientError.unknown - } - - return book - }, - chapters: { _ in [.mock] }, - verses: { _, _ in [.mock] }, - verse: { _, _, _ in .mock } - ) -} - //extension BibleClient { // public static var previewValue: BibleClient = Self( // translations: <#@Sendable () async throws -> [Translation]#>, @@ -144,16 +101,3 @@ extension BibleClient { // verse: <#@Sendable (BookID, ChapterID, VerseID) async throws -> Verse#> // ) //} - -extension DependencyValues { - public var bible: BibleClient { - get { - self[BibleClient.self] - } - - set { - self[BibleClient.self] = newValue - } - } -} - diff --git a/BibleCore/Sources/BibleClient/Test.swift b/BibleCore/Sources/BibleClient/Test.swift new file mode 100644 index 0000000..5fc782e --- /dev/null +++ b/BibleCore/Sources/BibleClient/Test.swift @@ -0,0 +1,27 @@ +import BibleCore +import Foundation +import ComposableArchitecture + +enum BibleClientError: Error { + case unknown +} + +extension BibleClient { + public static var testValue: BibleClient = Self( + translations: { [.mock] }, + translation: { _ in .mock }, + genres: { [.mock] }, + genre: { _ in .mock }, + books: { [.genesis, .exodus, .leviticus] }, + book: { id in + guard let book = IdentifiedArray(uniqueElements: [Book].mock)[id: id] else { + throw BibleClientError.unknown + } + + return book + }, + chapters: { _ in [.mock] }, + verses: { _, _ in [.mock] }, + verse: { _, _, _ in .mock } + ) +}