From 8c68ae9417bba8910548df3eead8d422a02e1ac9 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 12 Oct 2025 13:24:42 +0200 Subject: [PATCH] Defined the InputValidationRule protocol in the library target. --- .../Errors/InputValidationError.swift | 21 ++++++++++++ .../Protocols/InputValidationRule.swift | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Sources/DiscogsService/Internal/Errors/InputValidationError.swift create mode 100644 Sources/DiscogsService/Internal/Protocols/InputValidationRule.swift diff --git a/Sources/DiscogsService/Internal/Errors/InputValidationError.swift b/Sources/DiscogsService/Internal/Errors/InputValidationError.swift new file mode 100644 index 000000000..e4299b690 --- /dev/null +++ b/Sources/DiscogsService/Internal/Errors/InputValidationError.swift @@ -0,0 +1,21 @@ +// ===----------------------------------------------------------------------=== +// +// 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 representation of all the possible validation error that could be thrown while validating an input. +enum InputValidationError: Error { + /// An input is empty. + case inputIsEmpty + /// An input is nil. + case inputIsNil +} diff --git a/Sources/DiscogsService/Internal/Protocols/InputValidationRule.swift b/Sources/DiscogsService/Internal/Protocols/InputValidationRule.swift new file mode 100644 index 000000000..e82ad8953 --- /dev/null +++ b/Sources/DiscogsService/Internal/Protocols/InputValidationRule.swift @@ -0,0 +1,34 @@ +// ===----------------------------------------------------------------------=== +// +// 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 + +}