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
6 changes: 3 additions & 3 deletions Sources/Configuration/ConfigProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public protocol ConfigProvider: Sendable {
/// significant performance impact.
///
/// - Returns: An immutable snapshot that represents the current provider state.
func snapshot() -> any ConfigSnapshotProtocol
func snapshot() -> any ConfigSnapshot

/// Monitors the provider's state for changes by emitting snapshots.
///
Expand All @@ -129,7 +129,7 @@ public protocol ConfigProvider: Sendable {
/// - Throws: Provider-specific errors or errors thrown by the handler closure.
/// - Returns: The value returned by the closure.
func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return
}

Expand All @@ -139,7 +139,7 @@ public protocol ConfigProvider: Sendable {
/// capturing the provider's state at a specific moment. This prevents the underlying
/// data from changing between individual key lookups.
@available(Configuration 1.0, *)
public protocol ConfigSnapshotProtocol: Sendable {
public protocol ConfigSnapshot: Sendable {

/// The human-readable name of the configuration provider that created this snapshot.
///
Expand Down
12 changes: 5 additions & 7 deletions Sources/Configuration/ConfigProviderHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension ConfigProvider {
///
/// ```swift
/// func watchSnapshot(
/// updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Void
/// updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Void
/// ) async throws {
/// try await watchSnapshotFromSnapshot(updatesHandler)
/// }
Expand All @@ -85,12 +85,10 @@ extension ConfigProvider {
/// - Parameter updatesHandler: The closure that processes the async sequence of snapshot updates.
/// - Returns: The value returned by the handler closure.
/// - Throws: Provider-specific errors or errors thrown by the handler.
nonisolated(nonsending)
public func watchSnapshotFromSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
) async throws -> Return
{
let (stream, continuation) = AsyncStream<any ConfigSnapshotProtocol>
nonisolated(nonsending) public func watchSnapshotFromSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
let (stream, continuation) = AsyncStream<any ConfigSnapshot>
.makeStream(bufferingPolicy: .bufferingNewest(1))
let initialValue = snapshot()
continuation.yield(initialValue)
Expand Down
5 changes: 5 additions & 0 deletions Sources/Configuration/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ public typealias ReloadingYAMLProvider = ReloadingFileProvider<YAMLSnapshot>
#endif

#endif

/// An immutable snapshot of a configuration provider's state.
@available(Configuration 1.0, *)
@available(*, deprecated, renamed: "ConfigSnapshot")
public typealias ConfigSnapshotProtocol = ConfigSnapshot
2 changes: 1 addition & 1 deletion Sources/Configuration/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Any package can implement a ``ConfigProvider``, making the ecosystem extensible
- ``KeyMappingProvider``

### Creating a custom provider
- ``ConfigSnapshotProtocol``
- ``ConfigSnapshot``
- ``FileParsingOptions``
- ``ConfigProvider``
- ``ConfigContent``
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ``Configuration/ConfigSnapshot``

## Topics

### Required methods

- ``ConfigSnapshot/providerName``
- ``ConfigSnapshot/value(forKey:type:)``

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

### Protocol requirements

- ``ConfigSnapshotProtocol``
- ``ConfigSnapshot``
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
### Snapshot configuration

- ``FileConfigSnapshot``
- ``ConfigSnapshotProtocol``
- ``ConfigSnapshot``
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
### Snapshot configuration

- ``FileConfigSnapshot``
- ``ConfigSnapshotProtocol``
- ``ConfigSnapshot``
4 changes: 2 additions & 2 deletions Sources/Configuration/MultiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension MultiProvider: CustomStringConvertible {
struct MultiSnapshot {

/// The individual snapshots from each nested provider, maintained in precedence order.
var snapshots: [any ConfigSnapshotProtocol]
var snapshots: [any ConfigSnapshot]

/// Resolves a configuration value by querying nested provider snapshots in precedence order.
/// - Parameters:
Expand Down Expand Up @@ -201,7 +201,7 @@ extension MultiProvider {
) async throws -> Return
{
let providers = storage.providers
typealias UpdatesSequence = any (AsyncSequence<any ConfigSnapshotProtocol, Never> & Sendable)
typealias UpdatesSequence = any (AsyncSequence<any ConfigSnapshot, Never> & Sendable)
var updateSequences: [UpdatesSequence] = []
updateSequences.reserveCapacity(providers.count)
return try await withProvidersWatchingSnapshot(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Configuration/Providers/CLI/CLISnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal struct CLISnapshot {
}

@available(Configuration 1.0, *)
extension CLISnapshot: ConfigSnapshotProtocol {
extension CLISnapshot: ConfigSnapshot {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
func value(forKey key: AbsoluteConfigKey, type: ConfigType) throws -> LookupResult {
let encodedKey = keyEncoder.encode(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ extension CommandLineArgumentsProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
_snapshot
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ extension EnvironmentVariablesProvider.Snapshot {
}

@available(Configuration 1.0, *)
extension EnvironmentVariablesProvider.Snapshot: ConfigSnapshotProtocol {
extension EnvironmentVariablesProvider.Snapshot: ConfigSnapshot {
func value(
forKey key: AbsoluteConfigKey,
type: ConfigType
Expand Down Expand Up @@ -495,13 +495,13 @@ extension EnvironmentVariablesProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
_snapshot
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ extension DirectoryFilesProvider.Snapshot {
}

@available(Configuration 1.0, *)
extension DirectoryFilesProvider.Snapshot: ConfigSnapshotProtocol {
extension DirectoryFilesProvider.Snapshot: ConfigSnapshot {
func value(
forKey key: AbsoluteConfigKey,
type: ConfigType
Expand Down Expand Up @@ -433,13 +433,13 @@ extension DirectoryFilesProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
_snapshot
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Configuration/Providers/Files/FileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ extension FileProvider: ConfigProvider {

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)
}
Expand All @@ -195,7 +195,7 @@ extension FileProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
_snapshot
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public protocol FileParsingOptions: Sendable {

/// A protocol for configuration snapshots created from file data.
///
/// This protocol extends ``ConfigSnapshotProtocol`` to provide file-specific functionality
/// This protocol extends ``ConfigSnapshot`` to provide file-specific functionality
/// for creating configuration snapshots from raw file data. Types conforming to this protocol
/// can parse various file formats (such as JSON and YAML) and convert them into configuration values.
///
Expand Down Expand Up @@ -75,7 +75,7 @@ public protocol FileParsingOptions: Sendable {
/// The snapshot is responsible for parsing the file data and converting it into a
/// representation of configuration values that can be queried by the configuration system.
@available(Configuration 1.0, *)
public protocol FileConfigSnapshot: ConfigSnapshotProtocol, CustomStringConvertible,
public protocol FileConfigSnapshot: ConfigSnapshot, CustomStringConvertible,
CustomDebugStringConvertible
{
/// The parsing options type used for parsing this snapshot.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Configuration/Providers/Files/JSONSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ extension JSONSnapshot: FileConfigSnapshot {
}

@available(Configuration 1.0, *)
extension JSONSnapshot: ConfigSnapshotProtocol {
extension JSONSnapshot: ConfigSnapshot {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func value(forKey key: AbsoluteConfigKey, type: ConfigType) throws -> LookupResult {
let encodedKey = Self.keyEncoder.encode(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ extension ReloadingFileProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
storage.withLock { $0.snapshot }
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
let (stream, continuation) = AsyncStream<Snapshot>.makeStream(bufferingPolicy: .bufferingNewest(1))
let id = UUID()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Configuration/Providers/Files/YAMLSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ extension YAMLSnapshot: FileConfigSnapshot {
}

@available(Configuration 1.0, *)
extension YAMLSnapshot: ConfigSnapshotProtocol {
extension YAMLSnapshot: ConfigSnapshot {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func value(forKey key: AbsoluteConfigKey, type: ConfigType) throws -> LookupResult {
let encodedKey = Self.keyEncoder.encode(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension InMemoryProvider: CustomDebugStringConvertible {
}

@available(Configuration 1.0, *)
extension InMemoryProvider.Snapshot: ConfigSnapshotProtocol {
extension InMemoryProvider.Snapshot: ConfigSnapshot {
func value(
forKey key: AbsoluteConfigKey,
type: ConfigType
Expand Down Expand Up @@ -226,13 +226,13 @@ extension InMemoryProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
_snapshot
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ extension MutableInMemoryProvider {
}

@available(Configuration 1.0, *)
extension MutableInMemoryProvider.Snapshot: ConfigSnapshotProtocol {
extension MutableInMemoryProvider.Snapshot: ConfigSnapshot {
func value(forKey key: AbsoluteConfigKey, type: ConfigType) throws -> LookupResult {
try MutableInMemoryProvider.parseValue(
values[key],
Expand Down Expand Up @@ -450,13 +450,13 @@ extension MutableInMemoryProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
storage.withLock { $0.snapshot }
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
let (stream, continuation) = AsyncStream<Snapshot>.makeStream(bufferingPolicy: .bufferingNewest(1))
let id = UUID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ extension KeyMappingProvider: ConfigProvider {
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func snapshot() -> any ConfigSnapshotProtocol {
public func snapshot() -> any ConfigSnapshot {
MappedKeySnapshot(mapKey: self.mapKey, upstream: self.upstream.snapshot())
}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
) async throws -> Return {
try await upstream.watchSnapshot { sequence in
try await updatesHandler(
Expand All @@ -135,13 +135,13 @@ extension KeyMappingProvider: ConfigProvider {

/// A configuration snapshot that maps all keys before delegating to an upstream snapshot.
@available(Configuration 1.0, *)
private struct MappedKeySnapshot: ConfigSnapshotProtocol {
private struct MappedKeySnapshot: ConfigSnapshot {

/// The prefix key to prepend to all configuration keys.
let mapKey: @Sendable (AbsoluteConfigKey) -> AbsoluteConfigKey

/// The upstream configuration snapshot to delegate to after prefixing keys.
var upstream: any ConfigSnapshotProtocol
var upstream: any ConfigSnapshot

var providerName: String {
"KeyMappingProvider[upstream: \(self.upstream.providerName)]"
Expand Down
6 changes: 3 additions & 3 deletions Sources/ConfigurationTestingInternal/TestProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension TestProvider {
}

@available(Configuration 1.0, *)
extension TestProvider: ConfigProvider, ConfigSnapshotProtocol {
extension TestProvider: ConfigProvider, ConfigSnapshot {
package var providerName: String {
"TestProvider"
}
Expand All @@ -103,12 +103,12 @@ extension TestProvider: ConfigProvider, ConfigSnapshotProtocol {
}
}

package func snapshot() -> any ConfigSnapshotProtocol {
package func snapshot() -> any ConfigSnapshot {
self
}

package func watchSnapshot<Return>(
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshotProtocol, Never>) async throws -> Return
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
)
async throws -> Return
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/ConfigurationTests/KeyMappingProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct KeyMappingProviderTests {
}
}

var receivedSnapshots: [any ConfigSnapshotProtocol] = []
var receivedSnapshots: [any ConfigSnapshot] = []
try await mapper.watchSnapshot { sequence in
for try await snapshot in sequence {
receivedSnapshots.append(snapshot)
Expand Down
Loading
Loading