@@ -28,16 +28,13 @@ public import SystemPackage
2828///
2929/// ## Key mapping
3030///
31- /// By default, configuration keys are transformed into file names using these rules:
32- /// - Components are joined with dashes
33- /// - Non-alphanumeric characters (except dashes) are replaced with underscores
31+ /// Configuration keys are transformed into file names using these rules:
32+ /// - Components are joined with dashes.
33+ /// - Non-alphanumeric characters (except dashes) are replaced with underscores.
3434///
3535/// For example:
3636/// - `database.password` -> `database-password`
3737///
38- /// You can customize this key mapping by providing a custom `ConfigKeyEncoder` implementation
39- /// to the initializer.
40- ///
4138/// ## Value handling
4239///
4340/// The provider reads file contents as UTF-8 strings and converts them to the requested
@@ -103,24 +100,6 @@ public import SystemPackage
103100/// // ["host1.example.com", "host2.example.com", "host3.example.com"]
104101/// ```
105102///
106- /// ### Custom key encoding
107- ///
108- /// ```swift
109- /// // Custom key encoder that uses underscores instead of dashes
110- /// struct CustomKeyEncoder: ConfigKeyEncoder {
111- /// func encode(_ key: AbsoluteConfigKey) -> String {
112- /// key.components.joined(separator: "_")
113- /// }
114- /// }
115- ///
116- /// let provider = try await DirectoryFilesProvider(
117- /// directoryPath: "/etc/config",
118- /// keyEncoder: CustomKeyEncoder()
119- /// )
120- ///
121- /// // Now "database.password" maps to file "database_password" instead of "database-password"
122- /// ```
123- ///
124103/// ## Configuration context
125104///
126105/// This provider ignores the context passed in ``AbsoluteConfigKey/context``.
@@ -152,7 +131,7 @@ public struct DirectoryFilesProvider: Sendable {
152131 var arrayDecoder : DirectoryFilesValueArrayDecoder
153132
154133 /// The key encoder for converting config keys to file names.
155- var keyEncoder : any ConfigKeyEncoder
134+ var keyEncoder : any ConfigKeyEncoder = . directoryFiles
156135 }
157136
158137 /// The underlying snapshot of the provider.
@@ -178,22 +157,19 @@ public struct DirectoryFilesProvider: Sendable {
178157 /// - When `true`, if the directory is missing, treats it as empty.
179158 /// - secretsSpecifier: Specifies which values should be treated as secrets.
180159 /// - arraySeparator: The character used to separate elements in array values.
181- /// - keyEncoder: The encoder to use for converting configuration keys to file names.
182160 /// - Throws: If the directory cannot be found or read.
183161 public init (
184162 directoryPath: FilePath ,
185163 allowMissing: Bool = false ,
186164 secretsSpecifier: SecretsSpecifier < String , Data > = . all,
187- arraySeparator: Character = " , " ,
188- keyEncoder: some ConfigKeyEncoder = . directoryFiles
165+ arraySeparator: Character = " , "
189166 ) async throws {
190167 try await self . init (
191168 directoryPath: directoryPath,
192169 allowMissing: allowMissing,
193170 fileSystem: LocalCommonProviderFileSystem ( ) ,
194171 secretsSpecifier: secretsSpecifier,
195- arraySeparator: arraySeparator,
196- keyEncoder: keyEncoder
172+ arraySeparator: arraySeparator
197173 )
198174 }
199175
@@ -210,15 +186,13 @@ public struct DirectoryFilesProvider: Sendable {
210186 /// - fileSystem: The file system implementation to use.
211187 /// - secretsSpecifier: Specifies which values should be treated as secrets. Defaults to `.all`.
212188 /// - arraySeparator: The character used to separate elements in array values. Defaults to comma.
213- /// - keyEncoder: The encoder to use for converting configuration keys to file names.
214189 /// - Throws: If the directory cannot be found or read.
215190 internal init (
216191 directoryPath: FilePath ,
217192 allowMissing: Bool ,
218193 fileSystem: some CommonProviderFileSystem ,
219194 secretsSpecifier: SecretsSpecifier < String , Data > = . all,
220- arraySeparator: Character = " , " ,
221- keyEncoder: some ConfigKeyEncoder = . directoryFiles
195+ arraySeparator: Character = " , "
222196 ) async throws {
223197 let fileValues = try await Self . loadDirectory (
224198 at: directoryPath,
@@ -228,8 +202,7 @@ public struct DirectoryFilesProvider: Sendable {
228202 )
229203 self . _snapshot = . init(
230204 fileValues: fileValues,
231- arrayDecoder: DirectoryFilesValueArrayDecoder ( separator: arraySeparator) ,
232- keyEncoder: keyEncoder
205+ arrayDecoder: DirectoryFilesValueArrayDecoder ( separator: arraySeparator)
233206 )
234207 }
235208
@@ -478,15 +451,15 @@ extension DirectoryFilesProvider: ConfigProvider {
478451/// - Components are joined with dashes
479452/// - Non-alphanumeric characters (except dashes) are replaced with underscores
480453@available ( Configuration 1 . 0 , * )
481- public struct DirectoryFileKeyEncoder {
454+ internal struct DirectoryFileKeyEncoder {
482455 /// Creates a default directory key encoder that follows standard file naming conventions.
483456 public init ( ) { }
484457}
485458
486459@available ( Configuration 1 . 0 , * )
487460extension DirectoryFileKeyEncoder : ConfigKeyEncoder {
488461 // swift-format-ignore: AllPublicDeclarationsHaveDocumentation
489- public func encode( _ key: AbsoluteConfigKey ) -> String {
462+ func encode( _ key: AbsoluteConfigKey ) -> String {
490463 key. components
491464 . map { component in
492465 component
@@ -513,7 +486,7 @@ extension ConfigKeyEncoder where Self == DirectoryFileKeyEncoder {
513486 /// - Non-alphanumeric characters (except dashes) are replaced with underscores
514487 ///
515488 /// - Returns: A new key encoder.
516- public static var directoryFiles : Self {
489+ static var directoryFiles : Self {
517490 DirectoryFileKeyEncoder ( )
518491 }
519492}
0 commit comments