Implemented the User Agent middleware #6

Merged
javier merged 23 commits from library/user-agent-middleware into main 2025-10-13 00:54:21 +00:00
Showing only changes of commit 630f8a03f7 - Show all commits
@@ -0,0 +1,38 @@
// ===----------------------------------------------------------------------===
//
// 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 validation rule type that checks whether an input is empty or not.
struct NotEmptyValidationRule: InputValidationRule {
// MARK: Functions
func validate(_ input: String?) throws -> Bool {
guard let input else {
return false
}
guard !input.isEmpty else {
throw InputValidationError.inputIsEmpty
}
return true
}
}
// MARK: - Constants
extension InputValidationRule where Self == NotEmptyValidationRule {
/// A validation rule that checks whether an input is empty or not.
static var notEmpty: Self { .init() }
}