PushStorage

public protocol PushStorage : Sendable

Protocol for Push-specific storage operations. Extends the base storage capabilities with Push-specific functionality.

Implementations of this protocol must be thread-safe and handle concurrent access properly.

Credential Operations

  • Store a push credential.

    Throws

    PushStorageError.storageFailure if the credential cannot be stored.

    Throws

    PushStorageError.duplicateCredential if a credential with the same ID already exists.

    Declaration

    Swift

    func storePushCredential(_ credential: PushCredential) async throws

    Parameters

    credential

    The Push credential to be stored.

  • Retrieve all stored push credentials.

    Throws

    PushStorageError.storageFailure if the credentials cannot be retrieved.

    Declaration

    Swift

    func getAllPushCredentials() async throws -> [PushCredential]

    Return Value

    A list of all Push credentials.

  • Retrieve a specific push credential by ID.

    Throws

    PushStorageError.storageFailure if the credential cannot be retrieved.

    Declaration

    Swift

    func retrievePushCredential(credentialId: String) async throws -> PushCredential?

    Parameters

    credentialId

    The ID of the credential to retrieve.

    Return Value

    The Push credential, or nil if not found.

  • Remove a push credential by its ID.

    Throws

    PushStorageError.storageFailure if the credential cannot be removed.

    Declaration

    Swift

    func removePushCredential(credentialId: String) async throws -> Bool

    Parameters

    credentialId

    The ID of the credential to remove.

    Return Value

    true if the credential was successfully removed, false if it didn’t exist.

  • clearPushCredentials() Asynchronous

    Clear all Push credentials from the storage.

    Throws

    PushStorageError.storageFailure if the credentials cannot be cleared.

    Declaration

    Swift

    func clearPushCredentials() async throws
  • Retrieve a push credential by issuer and account name. Used for duplicate detection during credential registration.

    Throws

    PushStorageError.storageFailure if the credential cannot be retrieved.

    Declaration

    Swift

    func getCredentialByIssuerAndAccount(issuer: String, accountName: String) async throws -> PushCredential?

    Parameters

    issuer

    The issuer of the credential.

    accountName

    The account name of the credential.

    Return Value

    The Push credential if found, nil otherwise.

Notification Operations

  • Store a push notification.

    Throws

    PushStorageError.storageFailure if the notification cannot be stored.

    Declaration

    Swift

    func storePushNotification(_ notification: PushNotification) async throws

    Parameters

    notification

    The Push notification to be stored.

  • Update a push notification.

    Throws

    PushStorageError.storageFailure if the notification cannot be updated.

    Declaration

    Swift

    func updatePushNotification(_ notification: PushNotification) async throws

    Parameters

    notification

    The Push notification to update.

  • Retrieve all stored push notifications.

    Throws

    PushStorageError.storageFailure if the notifications cannot be retrieved.

    Declaration

    Swift

    func getAllPushNotifications() async throws -> [PushNotification]

    Return Value

    A list of all Push notifications.

  • Retrieve all pending push notifications.

    Throws

    PushStorageError.storageFailure if the notifications cannot be retrieved.

    Declaration

    Swift

    func getPendingPushNotifications() async throws -> [PushNotification]

    Return Value

    A list of pending Push notifications.

  • Retrieve a specific push notification by ID.

    Throws

    PushStorageError.storageFailure if the notification cannot be retrieved.

    Declaration

    Swift

    func retrievePushNotification(notificationId: String) async throws -> PushNotification?

    Parameters

    notificationId

    The ID of the notification to retrieve.

    Return Value

    The Push notification, or nil if not found.

  • Retrieve a push notification by message ID.

    Throws

    PushStorageError.storageFailure if the notification cannot be retrieved.

    Declaration

    Swift

    func getNotificationByMessageId(messageId: String) async throws -> PushNotification?

    Parameters

    messageId

    The message ID of the notification to retrieve.

    Return Value

    The Push notification, or nil if not found.

  • Remove a push notification by its ID.

    Throws

    PushStorageError.storageFailure if the notification cannot be removed.

    Declaration

    Swift

    func removePushNotification(notificationId: String) async throws -> Bool

    Parameters

    notificationId

    The ID of the notification to remove.

    Return Value

    true if the notification was successfully removed, false if it didn’t exist.

  • Remove all push notifications associated with a credential.

    Throws

    PushStorageError.storageFailure if the notifications cannot be removed.

    Declaration

    Swift

    func removePushNotificationsForCredential(credentialId: String) async throws -> Int

    Parameters

    credentialId

    The ID of the credential.

    Return Value

    The number of notifications removed.

  • Clear all Push notifications from the storage.

    Throws

    PushStorageError.storageFailure if the notifications cannot be cleared.

    Declaration

    Swift

    func clearPushNotifications() async throws

Device Token Operations

  • Store a push device token.

    Throws

    PushStorageError.storageFailure if the token cannot be stored.

    Declaration

    Swift

    func storePushDeviceToken(_ token: PushDeviceToken) async throws

    Parameters

    token

    The Push device token to be stored.

  • Retrieve the current push device token.

    Throws

    PushStorageError.storageFailure if the token cannot be retrieved.

    Declaration

    Swift

    func getCurrentPushDeviceToken() async throws -> PushDeviceToken?

    Return Value

    The current Push device token, or nil if not found.

  • Clear all Push device tokens from the storage.

    Throws

    PushStorageError.storageFailure if the tokens cannot be cleared.

    Declaration

    Swift

    func clearPushDeviceTokens() async throws

Notification Cleanup Operations

  • Count the number of push notifications.

    Throws

    PushStorageError.storageFailure if the count cannot be retrieved.

    Declaration

    Swift

    func countPushNotifications(credentialId: String?) async throws -> Int

    Parameters

    credentialId

    Optional ID of a specific credential to count notifications for.

    Return Value

    The count of push notifications.

  • Retrieve the oldest push notifications.

    Throws

    PushStorageError.storageFailure if the notifications cannot be retrieved.

    Declaration

    Swift

    func getOldestPushNotifications(limit: Int, credentialId: String?) async throws -> [PushNotification]

    Parameters

    limit

    The maximum number of notifications to retrieve.

    credentialId

    Optional ID of a specific credential to retrieve notifications for.

    Return Value

    A list of the oldest push notifications.

  • Purge push notifications by age.

    Throws

    PushStorageError.storageFailure if the notifications cannot be purged.

    Declaration

    Swift

    func purgePushNotificationsByAge(maxAgeDays: Int, credentialId: String?) async throws -> Int

    Parameters

    maxAgeDays

    The maximum age in days for notifications to keep.

    credentialId

    Optional ID of a specific credential to purge notifications for.

    Return Value

    The number of notifications removed.

  • Purge push notifications by count (removes oldest notifications when count exceeds the limit).

    Throws

    PushStorageError.storageFailure if the notifications cannot be purged.

    Declaration

    Swift

    func purgePushNotificationsByCount(maxCount: Int, credentialId: String?) async throws -> Int

    Parameters

    maxCount

    The maximum number of notifications to keep.

    credentialId

    Optional ID of a specific credential to purge notifications for.

    Return Value

    The number of notifications removed.