Class Environment<Name, Data, R>

Represents an environment with its name, data structure, and resolution methods.

Each environment can have multiple resolution methods (hardcoded, from-env, etc.) and maintains type safety for the environment data and resolution payloads.

Type Parameters

  • Name extends string = string

    The name of the environment

  • Data = any

    The data structure for this environment

  • R extends Resolution<string, Data> = Resolution<string, Data>

    The union of all resolution types for this environment

Properties

dataType: TypeDef<Data> = ...

Type definition for the environment data structure.

name: Name

The name of the environment

resolutions: R[]

Array of resolution methods for this environment

Methods

  • Internal

    Creates a new Environment with the specified name and data type.

    Type Parameters

    • Name extends string

      The name of the environment

    • Data

      The data structure for this environment

    Parameters

    • name: Name

      The name of the environment

    Returns Environment<Name, Data, never>

    A new Environment with no resolutions

  • Adds a synchronous resolution method to the environment.

    Type Parameters

    • Tag extends string

      The unique tag for this resolution method

    • Payload

      The payload type for this resolution

    Parameters

    • tag: RemoveLiteral<Tag, R["tag"]>

      The unique tag for this resolution method

    • _payloadType: TypeDef<Payload>

      Type definition for the payload (used for type inference)

    • resolve: Resolve<Data, Payload, "sync">

      The synchronous resolve function

    Returns Environment<Name, Data, R | Resolution<Tag, Data, Payload, "sync">>

    A new Environment with the added resolution

    (env) => env
    .addResolution("hardcoded", defineType<string>(), (data) => data.payload)
    .addResolution("from-env", defineType<undefined>(), (data) =>
    data.envData.env[data.payload ?? data.variableName])
  • Adds an asynchronous resolution method to the environment.

    Type Parameters

    • Tag extends string

      The unique tag for this resolution method

    • Payload

      The payload type for this resolution

    Parameters

    • tag: Tag

      The unique tag for this resolution method

    • _payloadType: TypeDef<Payload>

      Type definition for the payload (used for type inference)

    • resolve: Resolve<Data, Payload, "async">

      The asynchronous resolve function

    Returns Environment<Name, Data, R | Resolution<Tag, Data, Payload, "async">>

    A new Environment with the added resolution

    (env) => env
    .addResolution("from-aws-secrets", defineType<undefined>(), async (data) => {
    await new Promise(resolve => setTimeout(resolve, 1000))
    return `secret for ${data.variableName} from aws`
    })