Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Configuration/ConfigContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// A value that can be stored in a configuration context.
///
/// Context values support common data types used for configuration metadata.
@available(Configuration 1.0, *)
public enum ConfigContextValue: Sendable, Equatable, Hashable {

/// A string value.
Expand All @@ -30,6 +31,7 @@ public enum ConfigContextValue: Sendable, Equatable, Hashable {
case bool(Bool)
}

@available(Configuration 1.0, *)
extension ConfigContextValue: CustomStringConvertible {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public var description: String {
Expand All @@ -46,34 +48,39 @@ extension ConfigContextValue: CustomStringConvertible {
}
}

@available(Configuration 1.0, *)
extension ConfigContextValue: ExpressibleByStringLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(stringLiteral value: String) {
self = .string(value)
}
}

@available(Configuration 1.0, *)
extension ConfigContextValue: ExpressibleByIntegerLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(integerLiteral value: Int) {
self = .int(value)
}
}

@available(Configuration 1.0, *)
extension ConfigContextValue: ExpressibleByFloatLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(floatLiteral value: Double) {
self = .double(value)
}
}

@available(Configuration 1.0, *)
extension ConfigContextValue: ExpressibleByBooleanLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(booleanLiteral value: Bool) {
self = .bool(value)
}
}

@available(Configuration 1.0, *)
extension [String: ConfigContextValue] {
/// Creates a sorted string representation of the context, used primarily for sorting and logging.
///
Expand Down
2 changes: 2 additions & 0 deletions Sources/Configuration/SecretsSpecifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
/// secretsSpecifier: .none
/// )
/// ```
@available(Configuration 1.0, *)
public enum SecretsSpecifier<KeyType: Sendable & Hashable, ValueType: Sendable>: Sendable {

/// The library treats all configuration values as secrets.
Expand Down Expand Up @@ -103,6 +104,7 @@ public enum SecretsSpecifier<KeyType: Sendable & Hashable, ValueType: Sendable>:
case dynamic(@Sendable (KeyType, ValueType) -> Bool)
}

@available(Configuration 1.0, *)
extension SecretsSpecifier {
/// Determines whether a configuration value should be treated as secret.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Foundation
/// let decoder: ConfigBytesFromStringDecoder = .base64
/// let bytes = decoder.decode("SGVsbG8gV29ybGQ=") // "Hello World" in base64
/// ```
@available(Configuration 1.0, *)
public protocol ConfigBytesFromStringDecoder: Sendable {

/// Decodes a string value into an array of bytes.
Expand All @@ -52,12 +53,14 @@ public protocol ConfigBytesFromStringDecoder: Sendable {
///
/// This decoder interprets string configuration values as base64-encoded data
/// and converts them to their binary representation.
@available(Configuration 1.0, *)
public struct ConfigBytesFromBase64StringDecoder: Sendable {

/// Creates a new base64 decoder.
public init() {}
}

@available(Configuration 1.0, *)
extension ConfigBytesFromBase64StringDecoder: ConfigBytesFromStringDecoder {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func decode(_ value: String) -> [UInt8]? {
Expand All @@ -68,6 +71,7 @@ extension ConfigBytesFromBase64StringDecoder: ConfigBytesFromStringDecoder {
}
}

@available(Configuration 1.0, *)
extension ConfigBytesFromStringDecoder where Self == ConfigBytesFromBase64StringDecoder {

/// A decoder that interprets string values as base64-encoded data.
Expand All @@ -85,12 +89,14 @@ extension ConfigBytesFromStringDecoder where Self == ConfigBytesFromBase64String
/// The decoder expects strings with an even number of characters, where each
/// pair of characters represents one byte. For example, "48656C6C6F" represents
/// the bytes for "Hello".
@available(Configuration 1.0, *)
public struct ConfigBytesFromHexStringDecoder: Sendable {

/// Creates a new hexadecimal decoder.
public init() {}
}

@available(Configuration 1.0, *)
extension ConfigBytesFromHexStringDecoder: ConfigBytesFromStringDecoder {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func decode(_ value: String) -> [UInt8]? {
Expand All @@ -113,6 +119,7 @@ extension ConfigBytesFromHexStringDecoder: ConfigBytesFromStringDecoder {
}
}

@available(Configuration 1.0, *)
extension ConfigBytesFromStringDecoder where Self == ConfigBytesFromHexStringDecoder {

/// A decoder that interprets string values as hexadecimal-encoded data.
Expand Down
2 changes: 1 addition & 1 deletion Tests/ConfigurationTests/ReloadingFileProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct ReloadingFileProviderTests {

// Check empty value
let result2 = try provider.value(forKey: ["key1"], type: .string)
#expect(try result2.value == nil)
#expect(result2.value == nil)

// Update to a new valid file
fileSystem.update(
Expand Down
Loading