Skip to content

Commit 6a3176e

Browse files
authored
feat: Add the ability to access ParseConfig as a dictionary (#68)
* wip * feat: Add the ability to access ParseConfig as a dictionary * nits * nits
1 parent 11bb8e6 commit 6a3176e

26 files changed

+1171
-265
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

88
__New features__
9+
* Add ParseConfigCodable type that allows access to the Parse Server Config as a dictionary. ParseConfigCodable and types that conform to ParseConfig are interoperable ([#68](https://github.com/netreconlab/Parse-Swift/pull/68)), thanks to [Corey Baker](https://github.com/cbaker6).
910
* Make it easier to login with email or authData ([#67](https://github.com/netreconlab/Parse-Swift/pull/67)), thanks to [Corey Baker](https://github.com/cbaker6).
1011
* Add missing async/await and Combine ParseUser.become() type methods ([#66](https://github.com/netreconlab/Parse-Swift/pull/66)), thanks to [Corey Baker](https://github.com/cbaker6).
1112

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 49 additions & 3 deletions
Large diffs are not rendered by default.

Sources/ParseSwift/Objects/ParseInstallation+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ internal extension ParseInstallation {
352352
callbackQueue: callbackQueue,
353353
childObjects: savedChildObjects,
354354
childFiles: savedChildFiles)
355-
try? await Self.updateKeychainIfNeeded([saved])
355+
try? await Self.updateStorageIfNeeded([saved])
356356
return saved
357357
} catch {
358358
throw error as? ParseError ?? ParseError(swift: error)
@@ -424,7 +424,7 @@ internal extension Sequence where Element: ParseInstallation {
424424
childFiles: childFiles)
425425
returnBatch.append(contentsOf: saved)
426426
}
427-
try? await Self.Element.updateKeychainIfNeeded(returnBatch.compactMap {try? $0.get()})
427+
try? await Self.Element.updateStorageIfNeeded(returnBatch.compactMap {try? $0.get()})
428428
return returnBatch
429429
} catch {
430430
throw error as? ParseError ?? ParseError(swift: error)

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public extension ParseInstallation {
270270
await Self.setCurrentContainer(currentContainer)
271271
}
272272

273-
internal static func deleteCurrentContainerFromKeychain() async {
273+
internal static func deleteCurrentContainerFromStorage() async {
274274
try? await ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
275275
#if !os(Linux) && !os(Android) && !os(Windows)
276276
try? await KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
@@ -484,7 +484,7 @@ extension ParseInstallation {
484484

485485
// MARK: Fetchable
486486
extension ParseInstallation {
487-
internal static func updateKeychainIfNeeded(_ results: [Self], deleting: Bool = false) async throws {
487+
internal static func updateStorageIfNeeded(_ results: [Self], deleting: Bool = false) async throws {
488488
let currentInstallation = try await Self.current()
489489
var foundCurrentInstallationObjects = results.filter { $0.hasSameInstallationId(as: currentInstallation) }
490490
foundCurrentInstallationObjects = try foundCurrentInstallationObjects.sorted(by: {
@@ -499,7 +499,7 @@ extension ParseInstallation {
499499
if !deleting {
500500
await Self.setCurrent(foundCurrentInstallation)
501501
} else {
502-
await Self.deleteCurrentContainerFromKeychain()
502+
await Self.deleteCurrentContainerFromStorage()
503503
}
504504
}
505505
}
@@ -535,7 +535,7 @@ extension ParseInstallation {
535535
if case .success(let foundResult) = result {
536536
Task {
537537
do {
538-
try await Self.updateKeychainIfNeeded([foundResult])
538+
try await Self.updateStorageIfNeeded([foundResult])
539539
completion(.success(foundResult))
540540
} catch {
541541
let parseError = error as? ParseError ?? ParseError(swift: error)
@@ -834,7 +834,7 @@ extension ParseInstallation {
834834
case .success:
835835
Task {
836836
do {
837-
try await Self.updateKeychainIfNeeded([self], deleting: true)
837+
try await Self.updateStorageIfNeeded([self], deleting: true)
838838
completion(.success(()))
839839
} catch {
840840
let parseError = error as? ParseError ?? ParseError(swift: error)
@@ -1113,7 +1113,7 @@ public extension Sequence where Element: ParseInstallation {
11131113
}
11141114
let fetchedObjectsToReturn = fetchedObjectsToReturnMutable
11151115
Task {
1116-
try? await Self.Element.updateKeychainIfNeeded(fetchedObjects)
1116+
try? await Self.Element.updateStorageIfNeeded(fetchedObjects)
11171117
completion(.success(fetchedObjectsToReturn))
11181118
}
11191119
case .failure(let error):
@@ -1185,7 +1185,7 @@ public extension Sequence where Element: ParseInstallation {
11851185
if completed == (batches.count - 1) {
11861186
let returnBatchImmutable = returnBatch
11871187
Task {
1188-
try? await Self.Element.updateKeychainIfNeeded(self.compactMap {$0},
1188+
try? await Self.Element.updateStorageIfNeeded(self.compactMap {$0},
11891189
deleting: true)
11901190
completion(.success(returnBatchImmutable))
11911191
}

Sources/ParseSwift/Objects/ParseUser+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ internal extension ParseUser {
553553
callbackQueue: callbackQueue,
554554
childObjects: savedChildObjects,
555555
childFiles: savedChildFiles)
556-
try? await Self.updateKeychainIfNeeded([saved])
556+
try? await Self.updateStorageIfNeeded([saved])
557557
return saved
558558
} catch {
559559
throw error as? ParseError ?? ParseError(swift: error)
@@ -625,7 +625,7 @@ internal extension Sequence where Element: ParseUser {
625625
childFiles: childFiles)
626626
returnBatch.append(contentsOf: saved)
627627
}
628-
try? await Self.Element.updateKeychainIfNeeded(returnBatch.compactMap {try? $0.get()})
628+
try? await Self.Element.updateStorageIfNeeded(returnBatch.compactMap {try? $0.get()})
629629
return returnBatch
630630
} catch {
631631
throw error as? ParseError ?? ParseError(swift: error)

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ extension ParseUser {
110110
}
111111

112112
static func deleteCurrentKeychain() async {
113-
await deleteCurrentContainerFromKeychain()
114-
await BaseParseInstallation.deleteCurrentContainerFromKeychain()
115-
await ParseACL.deleteDefaultFromKeychain()
116-
await BaseConfig.deleteCurrentContainerFromKeychain()
113+
await deleteCurrentContainerFromStorage()
114+
await BaseParseInstallation.deleteCurrentContainerFromStorage()
115+
await ParseACL.deleteDefaultFromStorage()
116+
await BaseConfig.deleteCurrentContainerFromStorage()
117117
clearCache()
118118
}
119119
}
@@ -147,7 +147,7 @@ public extension ParseUser {
147147
#endif
148148
}
149149

150-
internal static func deleteCurrentContainerFromKeychain() async {
150+
internal static func deleteCurrentContainerFromStorage() async {
151151
try? await ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentUser)
152152
#if !os(Linux) && !os(Android) && !os(Windows)
153153
await URLSession.liveQuery.closeAll()
@@ -399,7 +399,7 @@ extension ParseUser {
399399
if let current = try? await Self.current() {
400400
let isAnonymous = await self.anonymous.isLinked()
401401
if !current.hasSameObjectId(as: user) && isAnonymous {
402-
await Self.deleteCurrentContainerFromKeychain()
402+
await Self.deleteCurrentContainerFromStorage()
403403
}
404404
}
405405

@@ -777,7 +777,7 @@ extension ParseUser {
777777

778778
// MARK: Fetchable
779779
extension ParseUser {
780-
internal static func updateKeychainIfNeeded(_ results: [Self], deleting: Bool = false) async throws {
780+
internal static func updateStorageIfNeeded(_ results: [Self], deleting: Bool = false) async throws {
781781
let currentUser = try await Self.current()
782782
var foundCurrentUserObjects = results.filter { $0.hasSameObjectId(as: currentUser) }
783783
foundCurrentUserObjects = try foundCurrentUserObjects.sorted(by: {
@@ -792,7 +792,7 @@ extension ParseUser {
792792
if !deleting {
793793
try await Self.setCurrent(foundCurrentUser)
794794
} else {
795-
await Self.deleteCurrentContainerFromKeychain()
795+
await Self.deleteCurrentContainerFromStorage()
796796
}
797797
}
798798
}
@@ -826,7 +826,7 @@ extension ParseUser {
826826
callbackQueue: callbackQueue) { result in
827827
if case .success(let foundResult) = result {
828828
Task {
829-
try? await Self.updateKeychainIfNeeded([foundResult])
829+
try? await Self.updateStorageIfNeeded([foundResult])
830830
completion(.success(foundResult))
831831
}
832832
} else {
@@ -1127,7 +1127,7 @@ extension ParseUser {
11271127

11281128
case .success:
11291129
Task {
1130-
try? await Self.updateKeychainIfNeeded([self], deleting: true)
1130+
try? await Self.updateStorageIfNeeded([self], deleting: true)
11311131
completion(.success(()))
11321132
}
11331133
case .failure(let error):
@@ -1404,7 +1404,7 @@ public extension Sequence where Element: ParseUser {
14041404
}
14051405
let fetchedObjectsToReturn = fetchedObjectsToReturnMutable
14061406
Task {
1407-
try? await Self.Element.updateKeychainIfNeeded(fetchedObjects)
1407+
try? await Self.Element.updateStorageIfNeeded(fetchedObjects)
14081408
callbackQueue.async {
14091409
completion(.success(fetchedObjectsToReturn))
14101410
}
@@ -1478,7 +1478,7 @@ public extension Sequence where Element: ParseUser {
14781478
if completed == (batches.count - 1) {
14791479
let returnBatchImmutable = returnBatch
14801480
Task {
1481-
try? await Self.Element.updateKeychainIfNeeded(self.compactMap {$0},
1481+
try? await Self.Element.updateStorageIfNeeded(self.compactMap {$0},
14821482
deleting: true)
14831483
callbackQueue.async {
14841484
completion(.success(returnBatchImmutable))

Sources/ParseSwift/Parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public func initialize(configuration: ParseConfiguration) async throws { // swif
147147
// Migrate old installations made with ParseSwift < 1.3.0
148148
if let currentInstallation = await BaseParseInstallation.currentContainer().currentInstallation {
149149
if currentInstallation.objectId == nil {
150-
await BaseParseInstallation.deleteCurrentContainerFromKeychain()
150+
await BaseParseInstallation.deleteCurrentContainerFromStorage()
151151
// Prepare installation
152152
await BaseParseInstallation.createNewInstallationIfNeeded()
153153
}

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.0.1"
13+
static let version = "5.1.0"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

0 commit comments

Comments
 (0)