Skip to content

Commit

Permalink
working on documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Apr 1, 2023
1 parent 3b602f6 commit fad1b0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/StealthyStash/KeychainRepository+StealthyRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extension KeychainRepository {
return itemDictionaries
}

/// Creates a new keychain item.
/// - Parameter item: Property which will be stored in the keychain.
public func create(_ item: AnyStealthyProperty) throws {
let defaults = defaultProvider?.attributesForNewItem(ofType: item.propertyType) ?? [:]
let itemDictionary = item.property.addQuery()
Expand All @@ -39,6 +41,10 @@ extension KeychainRepository {
}
}

/// Updates the keychain item based on the property changes.
/// - Parameters:
/// - item: New updated item.
/// - previousItem: The previous item to use for fetching.
public func update<StealthyPropertyType: StealthyProperty>(
_ item: StealthyPropertyType,
from previousItem: StealthyPropertyType
Expand All @@ -63,6 +69,8 @@ extension KeychainRepository {
}
}

/// Delete a property from the keychain..
/// - Parameter item: The keychain item to delete.
public func delete(_ item: AnyStealthyProperty) throws {
let deleteQuery = item.property
.deleteQuery()
Expand All @@ -76,6 +84,9 @@ extension KeychainRepository {
}
}

/// Queries the keychain for items.
/// - Parameter query: The query to use.
/// - Returns: A collection of keychain items.
public func query(_ query: Query) throws -> [AnyStealthyProperty] {
let defaults = defaultProvider?.attributesForQuery(ofType: query.type) ?? [:]
let dictionaryAny = query
Expand Down
13 changes: 13 additions & 0 deletions Sources/StealthyStash/StealthyRepository+StealthyModel.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extension StealthyRepository {
/// Saves the keychain items based on the model.
/// - Parameter model: The model which contains the properties to create.
public func create<StealthyModelType: StealthyModel>(
_ model: StealthyModelType
) throws {
Expand All @@ -8,6 +10,10 @@ extension StealthyRepository {
}
}

/// Updates the keychain based on changes to the model.
/// - Parameters:
/// - previousItem: The previous model.
/// - newItem: The updated model.
public func update<StealthyModelType: StealthyModel>(
from previousItem: StealthyModelType,
to newItem: StealthyModelType
Expand All @@ -22,6 +28,8 @@ extension StealthyRepository {
}
}

/// Deletes the model's properties from the repository.
/// - Parameter model: The model to delete.
public func delete<StealthyModelType: StealthyModel>(
_ model: StealthyModelType
) throws {
Expand All @@ -34,6 +42,9 @@ extension StealthyRepository {
}
}

/// Fetches the model based on the query given.
/// - Parameter query: The query.
/// - Returns: The Model if it exists.
public func fetch<StealthyModelType: StealthyModel>(
_ query: StealthyModelType.QueryBuilder.QueryType
) async throws -> StealthyModelType? {
Expand All @@ -56,6 +67,8 @@ extension StealthyRepository {
return try StealthyModelType.QueryBuilder.model(from: properties)
}

/// If there should only be one instance in the keychain, this will return that item.
/// - Returns: The Model if it exists.
public func fetch<StealthyModelType: StealthyModel>() async throws -> StealthyModelType?
where StealthyModelType.QueryBuilder.QueryType == Void {
try await fetch(())
Expand Down

0 comments on commit fad1b0a

Please sign in to comment.