Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Configuration file support for Optique with Standard Schema validation
Functions
Binds a parser to configuration values with fallback priority.
Creates a config context for use with Optique parsers.
Interfaces
Options for binding a parser to config values.
- context: ConfigContext<T, TConfigMeta>
The config context to use for fallback values.
- default: TValue
Default value to use when neither CLI nor config provides a value. If not specified, the parser will fail when no value is available.
- key:keyof T
| (() => TValue)config: T,meta: TConfigMeta | undefinedKey or accessor function to extract the value from config. Can be a property key (for top-level config values) or a function that extracts nested values. Accessor callbacks receive config metadata, if available, as the second argument.
A config context that provides configuration data via annotations.
- schema: StandardSchemaV1<unknown, T>
The Standard Schema validator for the config file.
Options for creating a config context.
- fileParser: (contents: Uint8Array) => unknown
Custom parser function for reading config file contents. If not provided, defaults to JSON.parse.
- schema: StandardSchemaV1<unknown, T>
Standard Schema validator for the config file. Accepts any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.).
Required options for ConfigContext when used with runWith() or run().
The ParserValuePlaceholder will be substituted with the actual parser
result type by runWith().
- getConfigPath: (parsed: ParserValuePlaceholder) => string | undefined
Function to extract config file path from parsed CLI arguments. Used in single-file mode. The
parsedparameter is typed as the parser's result type. - load: (parsed: ParserValuePlaceholder) =>Promise<ConfigLoadResult<TConfigMeta> | undefined | null>
| ConfigLoadResult<TConfigMeta>
| undefined
| nullCustom loader function that receives the first-pass parse result and returns the config data (or a Promise of it). This allows full control over file discovery, loading, merging, and error handling.
Result type for custom config loading.
- config: unknown
Raw config data to validate against the schema. The value is always passed to the schema validator, even when
undefinedornull. To signal "no config found" without validation, returnundefinedornulldirectly fromload()instead of wrapping it in an object. - meta: TConfigMeta | undefined
Metadata about where the config came from, if available.
Metadata about the loaded config source.
- configDir: string
Directory containing the config file.
- configPath: string
Absolute path to the config file.