Class Variable<EnvReg, N, DR>

Represents a single environment variable with definitions for different environments.

The Variable class provides a fluent API for defining how a variable should be resolved in different environments. It supports both static resolution methods (hardcoded values, environment variables) and dynamic resolution (runtime values).

const variable = Variable.create("DATABASE_URL")
.for("local", "from-env")
.for("workflows", "from-github-secrets")

const workflowVar = Variable.create("IS_WORKFLOW")
.for("local", "hardcoded", "false")
.for("workflows", "hardcoded", "true")

const dynamicVar = Variable.create("DOCUMENT_BUCKET")
.dynamicFor("local", "documentBucket")

Type Parameters

  • EnvReg extends EnvironmentRegistry

    The environment registry type

  • N extends Uppercase<string> = Uppercase<string>

    The name of the variable (must be uppercase)

  • DR extends res.DefinedResolution<EnvReg> = res.DefinedResolution<EnvReg>

    The union of all defined resolution types for this variable

Properties

name: N

The name of the variable (must be uppercase)

definitions: DR[]

Array of resolution definitions for different environments

Methods

  • Internal

    Creates a new Variable with the specified name.

    Type Parameters

    • EnvReg extends EnvironmentRegistry<
          Environment<string, any, Resolution<string, any, any, AsyncStatus>>,
      >

      The environment registry type

    • N extends string

      The name of the variable (must be uppercase)

    Parameters

    • name: N

      The name of the variable (must be uppercase)

    Returns Variable<EnvReg, N, never>

    A new Variable with no environment definitions

    const variable = Variable.create("DATABASE_URL")
    
  • Defines how this variable should be resolved for a specific environment.

    The payload parameter is optional and depends on the resolution method type.

    Type Parameters

    • EnvName extends string

      The environment name (must be unique across definitions)

    • Tag extends string

      The resolution method tag for this environment

    • Payload extends any

      The payload type for this resolution (inferred automatically)

    Parameters

    • envName: EnvName

      The environment name to define resolution for

    • tag: Tag

      The resolution method tag (e.g., "hardcoded", "from-env")

    • ...args: OptionalIf<Payload, Extends<undefined, Payload>>

      Optional payload (required for methods like "hardcoded")

    Returns Variable<
        EnvReg,
        N,
        | DR
        | DefinedResolution<
            EnvReg,
            EnvName,
            { type: "user-defined"; tag: Tag; payload: Payload },
        >,
    >

    A new Variable with the added environment definition

    const variable = Variable.create("DATABASE_URL")
    .for("local", "from-env") // No payload needed
    .for("workflows", "from-github-secrets") // No payload needed

    const workflowVar = Variable.create("IS_WORKFLOW")
    .for("local", "hardcoded", "false") // Payload required
    .for("workflows", "hardcoded", "true") // Payload required
  • Defines this variable to use dynamic resolution for a specific environment.

    Dynamic resolution allows the variable value to be provided at runtime when creating a resolver, rather than being hardcoded or derived from environment data.

    Type Parameters

    • EnvName extends string

      The environment name (must be unique across definitions)

    • DynamicName extends string

      The name of the dynamic data property

    Parameters

    • envName: EnvName

      The environment name to define dynamic resolution for

    • dynamicName: DynamicName

      The name of the dynamic data property to use

    Returns Variable<
        EnvReg,
        N,
        | DR
        | DefinedResolution<
            EnvReg,
            EnvName,
            { type: "dynamic"; dynamicName: DynamicName },
        >,
    >

    A new Variable with the added dynamic environment definition

    const variable = Variable.create("DOCUMENT_BUCKET")
    .dynamicFor("local", "documentBucket")
    .for("workflows", "hardcoded", "my-production-bucket")

    // When creating a resolver, provide the dynamic data:
    const resolver = varReg.createResolver("local", envData, {
    documentBucket: "my document bucket name"
    })