Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScript
open Axial.Configuration
open Reified
open Reified.SchemaDSLAxial.Configuration replaces ad-hoc environment reads with layered configuration. Every source produces
Reified.Data; later sources win, and one Reified schema decodes the merged result. Missing and malformed settings
are values in a ConfigError list, not exceptions, and all of them are reported at once.
Fable: Axial 0.12 requires Reified 0.12.1. Its Fable schema builder supports typed
schema<...>construction andConfig.loaddecoding, so source loading, merging, plain reads and watching use the same typed path on Fable.
Show page setup
// Setup for the checked examples on this page.
open System
open Axial
open Axial.Configuration
open Axial.FileSystem
open Axial
open Reified
open Reified.SchemaDSL
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualopen System
open Axial
open Axial.Configuration
open Reified
SystemAxialConfigurationReifiedSources
| Source | Constructor | Notes |
|---|---|---|
| Environment | ConfigSource.environment (Some "MYAPP") |
Reads the process environment once, splitting MYAPP__Db__Port on __ |
| Fixed environment | ConfigSource.environmentOf prefix pairs |
The same conversion from pairs supplied by a test or host |
| Command line | ConfigSource.commandLine argv |
--Db:Port=5432, --flag, --no-flag; positionals arrive under _ |
| JSON file | ConfigSource.jsonFile path |
Reads through IHasFileSystem; optionalJsonFile treats a missing file as an empty object |
| JSON text | ConfigSource.json name text |
For embedded or already-read JSON |
| Browser query | ConfigSource.queryString search |
?Db.Port=5432; use BrowserApp.queryParameters () from the browser host |
| Microsoft configuration | HostConfiguration.source "host" configuration |
In Axial.Hosting; keeps appsettings.json, user secrets and CreateDefaultBuilder(args) |
| Fixed data | ConfigSource.ofData name data |
Defaults and fixtures |
List order is precedence, and later wins. Keys match case-insensitively across layers, so Db.Port from JSON,
MYAPP__DB__PORT from the environment and --Db:Port from arguments address the same field.
Decode a typed model
type Db = { Host: string; Port: int }
type Settings = { Db: Db; Timeout: int }
let settingsSchema () =
schema<Settings> {
field (fun (settings: Settings) -> settings.Db) {
withSchema (
schema<Db> {
field (fun (db: Db) -> db.Host)
field (fun (db: Db) -> db.Port)
construct (fun host port -> { Host = host; Port = port })
}
)
}
field (fun (settings: Settings) -> settings.Timeout)
construct (fun db timeout -> { Db = db; Timeout = timeout })
}
let loadSettings argv =
Config.load
(settingsSchema ())
[ ConfigSource.ofData "defaults" (Data.Object [ "Db", Data.Object [ "Host", Data.Text "localhost" ] ])
ConfigSource.environment (Some "MYAPP")
ConfigSource.commandLine argv ]
FsLiveDocsGeneratedPage1_070DEED2BF82.DbHost: stringstringAn abbreviation for the CLI type . Basic Types
Port: intintAn abbreviation for the CLI type . Basic Types
FsLiveDocsGeneratedPage1_070DEED2BF82.SettingsDb: DbTimeout: intsettingsSchema: unit -> Schema<Settings>schema: SchemaCeBuilder.SchemaBuilder<'model>Record-schema computation expression.
``.ctor``: Quotations.Expr<(Settings -> Db)> -> field<Settings,Db>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
``.ctor``: Quotations.Expr<('model -> 'target)> -> field<'model,'target>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
settings: SettingsWithSchema: SchemaFieldSteps.FieldInitial<Settings,Db> * Schema<'current> -> SchemaFieldSteps.FieldWorking<Settings,Db,'current>Supplies the schema transformed by the remaining operations in this field block.
``.ctor``: Quotations.Expr<(Db -> string)> -> field<Db,string>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
db: Db``.ctor``: Quotations.Expr<(Db -> int)> -> field<Db,int>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
construct: 'constructor -> SchemaCeBuilder.ConstructorStep<'model,'constructor>Closes a record schema with a total constructor.
host: stringport: int``.ctor``: Quotations.Expr<(Settings -> int)> -> field<Settings,int>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
timeout: intloadSettings: string list -> Flow<'a,ConfigError list,Settings>argv: string listAxial.Configuration.ConfigLoads, decodes and watches layered configuration. Axial 0.12 requires Reified 0.12.1 or later; its Fable schema builder supports typed schema construction and Config.load decoding on Fable.
load: Schema<'model> -> ConfigSource<'env> list -> Flow<'env,ConfigError list,'model>Reads every source, merges them with later-wins precedence and decodes the result with . Every source failure is reported together; the schema is not run when any source failed.
Axial.Configuration.ConfigSourceofData: string -> Data -> ConfigSource<'env>Reads structured data provided by the caller; use it for defaults, fixtures and fakes.
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
ObjectAn ordered collection of named structured values.
TextA text value.
environment: string option -> ConfigSource<'env>Reads the live process environment once, split by the __ convention, optionally under a prefix. is the application prefix without the separator, for example Some "MYAPP".
SomeThe representation of "Value of type 'T" The input value. An option representing the value.
commandLine: string list -> ConfigSource<'env>Reads command-line arguments, including nested --Db:Port, repeated values and positionals.
Requires & types
Requires: open Axial.Configuration; open Reified; open Reified.SchemaDSL (packages: Axial.Configuration)val settingsSchema: unit -> Schema<Settings>val loadSettings: string list -> Flow<'a,ConfigError list,Settings>loadSettings [ "--Db:Port=5432"; "--Timeout=30" ]
|> Flow.run ()
|> shouldEqual
(Exit.Success
{ Db = { Host = "localhost"; Port = 5432 }
Timeout = 30 })
loadSettings: string list -> Flow<'a,ConfigError list,Settings>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowrun: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
shouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Db: DbHost: stringPort: intTimeout: intRequires & types
Requires: open Axial (packages: Axial)ConfigError.Invalid carries every SchemaIssue keyed by SchemaPath. ConfigError.describe renders an error in
invariant, path-sorted order without needing a loaded configuration. When an omitted path should list the spelling each
source uses, call ConfigError.describeWithSources:
let describeFailure config errors =
errors |> List.map (ConfigError.describeWithSources config) |> String.concat Environment.NewLine
describeFailure: IConfig -> ConfigError list -> stringconfig: IConfigerrors: ConfigError list(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Microsoft.FSharp.Collections.ListModuleContains operations for working with values of type . Operations for collections such as lists, arrays, sets, maps and sequences. See also F# Collection Types in the F# Language Guide.
map: ('T -> 'U) -> 'T list -> 'U listBuilds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The function to transform elements from the input list. The input list. The list of transformed elements. let inputs = [ "a"; "bbb"; "cc" ] inputs |> List.map (fun x -> x.Length) Evaluates to [ 1; 3; 2 ] This is an O(n) operation, where n is the length of the list.
Axial.Configuration.ConfigErrorModuledescribeWithSources: IConfig -> ConfigError -> stringRenders a failure with the spellings of the loaded sources, for omission hints.
Microsoft.FSharp.Core.StringModuleFunctional programming operators for string processing. Further string operations are available via the member functions on strings and other functionality in System.String and System.Text.RegularExpressions types. Strings and Text
concat: string -> string seq -> stringReturns a new string made by concatenating the given strings with separator sep, that is a1 + sep + ... + sep + aN. The separator string to be inserted between the strings of the input sequence. The sequence of strings to be concatenated. A new string consisting of the concatenated strings separated by the separation string. Thrown when strings is null. let input1 = ["Stefan"; "says:"; "Hello"; "there!"] input1 |> String.concat " " // evaluates "Stefan says: Hello there!" let input2 = [0..9] |> List.map string input2 |> String.concat "" // evaluates "0123456789" input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" let input3 = ["No comma"] input3 |> String.concat "," // evaluates "No comma"
System.EnvironmentProvides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.
NewLine: stringGets the newline string defined for this environment. A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.
Requires & types
Requires: open Axial.Configuration; open System (packages: Axial.Configuration)val describeFailure: IConfig -> ConfigError list -> stringA source failure (unreadable file or malformed JSON) is reported as ConfigError.SourceFailed, and schema decoding
is skipped so one bad file does not produce misleading omission messages.
Secrets
Declare a secret in the model with Secret<'v> from Reified.Refinements. Its value never appears in ToString,
%A, %O, schema errors, ConfigError.describe or log entries:
open Reified.Refinements
type Credentials = { Password: Secret<string> }
let credentialsSchema () =
schema<Credentials> {
field (fun (credentials: Credentials) -> credentials.Password) {
withSchema (Schema.secretWith Schema.text)
}
construct (fun password -> { Password = password })
}
ReifiedRefinementsFsLiveDocsGeneratedPage1_070DEED2BF82.CredentialsPassword: Secret<string>Reified.Refinements.Secret`1A reference-equality value with redacted display and explicit Secret.reveal access. The payload is captured in a private closure rather than an enumerable raw field. This is redaction, not encryption or access control. Caller-owned plaintext and explicitly revealed values remain the caller's responsibility.
stringAn abbreviation for the CLI type . Basic Types
credentialsSchema: unit -> Schema<Credentials>schema: SchemaCeBuilder.SchemaBuilder<'model>Record-schema computation expression.
``.ctor``: Quotations.Expr<(Credentials -> Secret<string>)> -> field<Credentials,Secret<string>>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
``.ctor``: Quotations.Expr<('model -> 'target)> -> field<'model,'target>Declares a field, deriving its camel-cased wire name from the property getter. type Signup = { Email: string } field (fun (s: Signup) -> s.Email) // wire name "email"
credentials: CredentialsWithSchema: SchemaFieldSteps.FieldInitial<Credentials,Secret<string>> * Schema<'current> -> SchemaFieldSteps.FieldWorking<Credentials,Secret<string>,'current>Supplies the schema transformed by the remaining operations in this field block.
Reified.SchemaConstruction, composition, parsing, and checking for universal schemas.
secretWith: Schema<'a> -> Schema<Secret<'a>>Seals a payload schema behind a redacted parse/check/codec boundary. Errors collapse to a value-free issue at the secret field path. Codecs accept the payload wire shape but encode the string <redacted>, not the payload; encoding is deliberately not a round trip. Only Secret.reveal returns the payload. This is log redaction, not memory encryption. let passwordSchema = Schema.secretWith Schema.text
text: Schema<string>Describes text input.
construct: 'constructor -> SchemaCeBuilder.ConstructorStep<'model,'constructor>Closes a record schema with a total constructor.
password: Secret<string>Requires & types
Requires: open Reified; open Reified.Refinements; open Reified.SchemaDSLval credentialsSchema: unit -> Schema<Credentials>Use Config.processArg to pass a secret to a process. It yields a redacted argument, so plans, transcripts and
failures show *** while the child receives the real value:
let deploy (token: Secret<string>) =
Axial.Process.DSL.cmd $"deploy --token {Config.processArg token}"Plain string reads
For one or two settings a schema is ceremony. Config.required and Config.optional read text from an
IHasConfig environment, and Config.tryFind is the pure form:
type ToolEnv =
{ Config: IConfig }
interface IHasConfig with
member this.Config = this.Config
let readEndpoint : Flow<ToolEnv, ConfigError, string> = Config.required "Api.Endpoint"
let readProxy : Flow<ToolEnv, ConfigError, string option> = Config.optional "Api.Proxy"
FsLiveDocsGeneratedPage1_070DEED2BF82.ToolEnvConfig: IConfigAxial.Configuration.IConfigOne immutable merged configuration snapshot.
Axial.Configuration.IHasConfigAn application environment that carries a merged configuration snapshot.
this: ToolEnvConfig: ToolEnv -> unit -> IConfigreadEndpoint: Flow<ToolEnv,ConfigError,string>Axial.Flow`3Axial.Configuration.ConfigErrorEvery configuration failure is a value; loading and reading never throw.
stringAn abbreviation for the CLI type . Basic Types
Axial.Configuration.ConfigLoads, decodes and watches layered configuration. Axial 0.12 requires Reified 0.12.1 or later; its Fable schema builder supports typed schema construction and Config.load decoding on Fable.
required: string -> Flow<'env,ConfigError,string>Reads a required text value at a Reified data path, comparing keys ordinal-ignore-case.
readProxy: Flow<ToolEnv,ConfigError,string option>optionThe type of optional values. When used from other CLI languages the empty option is the null value. Use the constructors Some and None to create values of this type. Use the values in the Option module to manipulate values of this type, or pattern match against the values directly. 'None' values will appear as the value null to other CLI languages. Instance methods on this type will appear as static methods to other CLI languages due to the use of null as a value representation. Options
optional: string -> Flow<'env,ConfigError,string option>Reads an optional text value at a Reified data path; absent is None, not an error.
Requires & types
Requires: open Axial; open Axial.Configuration (packages: Axial, Axial.Configuration)val readEndpoint: Flow<ToolEnv,ConfigError,string>val readProxy: Flow<ToolEnv,ConfigError,string option>Numbers and booleans come back as their text; use a schema when the value needs typed validation.
Watch file sources
Config.watch sources schema loads once and returns a ConfigWatch: Current is a SubscriptionRef of the latest
successfully decoded value, and Errors is a stream of failed reloads. File changes are debounced, all sources are
re-read and merged, and a failed decode keeps the last good value, logs the failure, and emits it on Errors.
Environment and command-line sources are not watched.
let watchSettings<'env when 'env :> IHasFileSystem> argv =
Config.watch
[ ConfigSource.jsonFile "appsettings.json"
ConfigSource.commandLine argv ]
(settingsSchema ())
watchSettings: string list -> Flow<IHasFileSystem,ConfigError list,ConfigWatch<IHasFileSystem,Settings>>envAxial.FileSystem.IHasFileSystemargv: string listAxial.Configuration.ConfigLoads, decodes and watches layered configuration. Axial 0.12 requires Reified 0.12.1 or later; its Fable schema builder supports typed schema construction and Config.load decoding on Fable.
watch: ConfigSource<'env> list -> Schema<'model> -> Flow<'env,ConfigError list,ConfigWatch<'env,'model>>Watches file sources and publishes each successfully decoded configuration. The initial configuration is loaded before this returns, so an invalid initial configuration fails the flow. File changes are debounced by 200 ms. A failed reload keeps the last valid value, logs the failure and emits it on Errors. Environment and argument sources are read once per reload and are otherwise static.
Axial.Configuration.ConfigSourcejsonFile: string -> ConfigSource<'env>Reads one JSON file through ; a missing file is a source failure.
commandLine: string list -> ConfigSource<'env>Reads command-line arguments, including nested --Db:Port, repeated values and positionals.
settingsSchema: unit -> Schema<Settings>Requires & types
Requires: open Axial.Configuration; open Axial.FileSystem (packages: Axial.Configuration, Axial.FileSystem)val watchSettings: string list -> Flow<IHasFileSystem,ConfigError list,ConfigWatch<IHasFileSystem,Settings>>Load once, pass the value
Configuration is usually loaded once at startup into a plain record, like Elm flags. Put the value, or the section
a service needs, in the application environment and read it with Flow.envWith; build handlers and Elmish programs
as closures over it. Config.section path schema exists for libraries that own one section.
The Microsoft IConfiguration path is a supported alternative. Pass
HostConfiguration.source "host" builder.Configuration as one layer, or keep IOptions<T> for components that
already depend on it.

