UNPKG

dagger-env

Version:

A type-safe, reusable environment configuration abstraction for Dagger modules.

72 lines 2.53 kB
import { z } from 'zod/v4'; import type { Container, Secret } from '@dagger.io/dagger'; /** * Generic configuration for DaggerEnv */ export type DaggerEnvConfig = { /** Arguments schema */ args: z.ZodObject<any>; /** Environment variables schema */ env: z.ZodObject<any>; /** Secrets schema */ secrets: z.ZodObject<any>; /** Secret presets mapping preset names to arrays of secret names */ secretPresets: Record<string, readonly string[]>; /** Derived environment variables based on secret names */ derivedEnvVars: Record<string, Record<string, string>>; }; /** * Inferred options type from config */ export type DaggerOptionsFromConfig<T extends DaggerEnvConfig> = { args: z.output<T['args']>; env: z.output<T['env']>; secrets: z.output<T['secrets']>; }; /** * Reusable Dagger environment abstraction */ export declare class DaggerEnv<T extends DaggerEnvConfig> { private readonly config; private readonly optionsSchema; constructor(config: T); /** * Parse dagger options from a Secret */ parseDaggerOptions(options: Secret): Promise<DaggerOptionsFromConfig<T>>; /** * Create a function that applies environment variables and secrets to a container * based on the provided Dagger options, secret presets, and additional secret names. */ getWithEnv(daggerOptions: Secret | DaggerOptionsFromConfig<T>, secretPresets: Array<Extract<keyof T['secretPresets'], string>>, secretNames?: Array<Extract<keyof z.output<T['secrets']>, string>>): Promise<{ /** * Apply environment variables and secrets to a container */ withEnv: (con: Container) => Container; /** * Remove environment variables and secrets from a container */ withoutEnv: (con: Container) => Container; }>; /** * Get the options schema for this DaggerEnv instance */ getOptionsSchema(): z.ZodObject<{ args: T["args"]; env: T["env"]; secrets: T["secrets"]; }, z.core.$strip>; /** * Get available secret presets */ getSecretPresets(): Array<keyof T['secretPresets']>; /** * Get secrets for a specific preset */ getPresetSecrets(preset: Extract<keyof T['secretPresets'], string>): readonly string[]; } /** * Helper function to create a DaggerEnv instance with proper typing */ export declare function createDaggerEnv<T extends DaggerEnvConfig>(config: T): DaggerEnv<T>; //# sourceMappingURL=dagger-env.d.ts.map