Files
discogs-service/Sources/DiscogsService/Internal/Protocols/InputValidationRule.swift
T
javier a1a649838c Implemented an input validation mechanism (#4)
This PR contains the work done to implement the `ValidateInputUseCase` use case and the `InputValidationRule` protocol, that is essential to define custom validation rules for inputs. In addition, the `NotEmptyValidationRule` and `NotNilValidationRule` rules have also been implemented.

Reviewed-on: #4
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2025-10-12 13:25:25 +00:00

35 lines
1.4 KiB
Swift

// ===----------------------------------------------------------------------===
//
// This source file is part of the DiscogsService open source project
//
// Copyright (c) 2025 Röck+Cöde VoF. and the DiscogsService project authors
// Licensed under Apache license v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of DiscogsService project authors
//
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
/// A protocol that defines an input validation rule to be applied to an input by the ``ValidateInputUseCase`` use case.
protocol InputValidationRule {
// MARK: Functions
#if swift(>=6.0)
/// Validates a given input against a validation rule.
/// - Parameter input: An input to be validated.
/// - Returns: A flag that indicates whether an input has been validated or not.
/// - Throws: An error of type ``InputValidationError`` in case a given input failed a validation.
@discardableResult func validate(_ input: String?) throws(InputValidationError) -> Bool
#else
/// Validates a given input against a validation rule.
/// - Parameter input: An input to be validated.
/// - Returns: A flag that indicates whether an input has been validated or not.
/// - Throws: An error of type ``InputValidationError`` in case a given input failed a validation.
@discardableResult func validate(_ input: String?) throws -> Bool
#endif
}