Gets the value of a variable for the current environment.
This method provides type-safe access to variable values. It automatically handles both synchronous and asynchronous resolutions based on the variable definition and environment configuration.
The name of the variable to resolve
The resolved value (string for sync, Promise
const resolver = varReg.createResolver("local", { env: { DATABASE_URL: "test" } })
// Get a hardcoded value
const isWorkflow = resolver.get("IS_WORKFLOW") // "false"
// Get a value from environment data
const dbUrl = resolver.get("DATABASE_URL") // "test"
// Get a dynamic value
const bucket = resolver.get("DOCUMENT_BUCKET") // "my document bucket name"
// Get an async value (requires await)
const apiKey = await resolver.get("OPENAI_API_KEY") // "secret for OPENAI_API_KEY from aws"
Gets the values of all accessible variables for the current environment.
This method returns an object mapping variable names to their resolved values.
If any variable resolves asynchronously, the whole result is a Promise that
resolves to the final object. For resolvers created with multiple possible
environments (via createDynamicResolver
), only variables that are defined
in every possible environment are included for type safety.
The same validation rules as in get apply to each variable: a runtime
error is thrown if a variable resolves to undefined
, null
, or a non-string
value, or if a resolution method cannot be found.
An object of variable values, or a Promise of that object if async
Gets the values of variables that use a specific resolution tag in another environment.
This method allows you to get values that would be resolved with a specific tag in a different environment. It filters variables based on their resolution method in the target environment but resolves their values in the current environment.
The method enforces several type safety constraints:
The return type is Promise
The name of the target environment to filter variables by
The resolution tag to filter variables by in the target environment
The type of variables that use the specified tag in the target environment
An object mapping variable names to their resolved values from the current environment. Returns a Promise if any variable resolves asynchronously.
const resolver = varReg.createResolver("env1", { env: {} })
// Get values that use "hardcoded" resolution in env2
const values = resolver.getAllFor("env2", "hardcoded")
// { VAR1: "value1", VAR2: "value2" }
// If any variable has async resolution in env1, result is Promise
const asyncValues = await resolver.getAllFor("env2", "hardcoded")
// Promise<{ VAR1: string, VAR2: string }>
// Type error: Cannot use "env1" as target (same as current environment)
resolver.getAllFor("env1", "hardcoded")
// Type error: "invalid-tag" is not a valid resolution tag for env2
resolver.getAllFor("env2", "invalid-tag")
// Type error: Some variables not available in current environment
resolver.getAllFor("env2", "hardcoded") // if VAR2 not in env1
Resolves variable values for a specific environment.
The Resolver provides type-safe access to variable values based on the environment configuration and variable definitions. It handles both synchronous and asynchronous resolutions automatically.
Example