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

feat: Add the ability to access ParseConfig as a dictionary #68

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Conversation

cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Mar 10, 2023

New Pull Request Checklist

Issue Description

Addresses feature ask in #57.

Approach

Add a new type called ParseConfigCodable which is interoperable with any type that conforms to ParseConfig. That means that either can be used to save/fetch the Config either from the Server or from local storage (Memory/Keychain). Below is an example of how to use the new ParseConfigCodable with a type erased AnyCodable values. Note that any Codable type can be used for the value of the Dictionary. The keys will always be strings:

// Fetching Config
let fetched: [String: AnyCodable] = try await ParseConfigCodable.fetch()

for (key, value) in fetched {
  guard let fetchedValue = fetched[key]?.value as? String else {
    print("Could not cast value as String")
    return
  }
  print("Key: \(key), Value: \(value)")
}

// Saving/Updating Config
let key = "welcomeMessage"
let value = "Hello"
var config = [String: AnyCodable]()
config[key] = AnyCodable(value)

let saved = try await ParseConfigCodable.save(config)
print(saved)

// Accessing Config from Keychain
let currentConfig: [String: AnyCodable] = try await ParseConfigCodable.current()
print(currentConfig)

TODOs before merging

  • Add tests
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)

options: options,
completion: promise)
}
}

Check warning

Code scanning / Tailor (reported by Codacy)

Function should have at least one blank line after it

Function should have at least one blank line after it
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
desires a different policy, it should be inserted in `options`.
*/
static func fetch(options: API.Options = []) async throws -> [String: V] {

Check warning

Code scanning / Tailor (reported by Codacy)

Function should have at least one blank line after it

Function should have at least one blank line after it
- throws: An error of type `ParseError`.
*/
static func save(_ config: [String: V],
options: API.Options = []) async throws -> Bool {

Check warning

Code scanning / Tailor (reported by Codacy)

Function should have at least one blank line after it

Function should have at least one blank line after it
@@ -407,7 +407,7 @@
return modifiedACL
}

internal static func deleteDefaultFromKeychain() async {
internal static func deleteDefaultFromStorage() async {

Check warning

Code scanning / Tailor (reported by Codacy)

Function should have at least one blank line after it

Function should have at least one blank line after it
@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #68 (26b69e3) into main (11bb8e6) will decrease coverage by 2.84%.
The diff coverage is 99.29%.

@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
- Coverage   90.49%   87.65%   -2.84%     
==========================================
  Files         166      128      -38     
  Lines       14955    12439    -2516     
==========================================
- Hits        13533    10903    -2630     
- Misses       1422     1536     +114     
Impacted Files Coverage Δ
...urces/ParseSwift/Protocols/ParseConfig+async.swift 100.00% <ø> (ø)
Sources/ParseSwift/Objects/ParseUser.swift 90.34% <91.66%> (-0.44%) ⬇️
...s/ParseSwift/Objects/ParseInstallation+async.swift 92.34% <100.00%> (-0.33%) ⬇️
Sources/ParseSwift/Objects/ParseInstallation.swift 88.05% <100.00%> (-0.26%) ⬇️
Sources/ParseSwift/Objects/ParseUser+async.swift 94.16% <100.00%> (-0.12%) ⬇️
Sources/ParseSwift/Parse.swift 84.02% <100.00%> (-13.97%) ⬇️
Sources/ParseSwift/Protocols/ParseConfig.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Types/ParseACL.swift 93.56% <100.00%> (ø)
...es/ParseSwift/Types/ParseConfigCodable+async.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Types/ParseConfigCodable.swift 100.00% <100.00%> (ø)
... and 1 more

... and 57 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cbaker6 cbaker6 merged commit 6a3176e into main Mar 10, 2023
@cbaker6 cbaker6 deleted the config branch March 10, 2023 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant