# All files / src/preview types.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 0/0
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    10x
    10x

    10x

     /**
     * Preview Deployment Types
     *
     * Configuration and status types for Docker-based preview deployments.
     * Docker IS the source of truth — no database table needed.
     */

    /**
     * Service configuration within a preview deployment.
     */
    export interface PreviewServiceConfig {
      name: string;
      build?: { context: string; dockerfile: string } | string;
      image?: string;
      port: number;
      route?: string;
      internal?: boolean;
      healthcheck?: { path: string; interval?: string; retries?: number };
      env?: Record<string, string>;
      volumes?: string[];
    }

    /**
     * Preview deployment configuration.
     * Parsed from `.cw-preview.yml`, existing compose file, or inferred from Dockerfile.
     */
    export interface PreviewConfig {
      version: 1;
      compose?: string;
      services: Record<string, PreviewServiceConfig>;
    }

    /**
     * Runtime status of a preview deployment.
     * Reconstructed from Docker state + container labels.
     */
    export interface PreviewStatus {
      id: string;
      projectName: string;
      initiativeId: string;
      phaseId?: string;
      projectId: string;
      branch: string;
      port: number;
      status: 'building' | 'running' | 'stopped' | 'failed';
      services: Array<{ name: string; state: string; health: string }>;
      composePath: string;
    }

    /**
     * Docker labels applied to preview containers for metadata retrieval.
     */
    export const PREVIEW_LABEL_PREFIX = 'cw';
    export const PREVIEW_LABELS = {
      preview: `${PREVIEW_LABEL_PREFIX}.preview`,
      initiativeId: `${PREVIEW_LABEL_PREFIX}.initiative-id`,
      phaseId: `${PREVIEW_LABEL_PREFIX}.phase-id`,
      branch: `${PREVIEW_LABEL_PREFIX}.branch`,
      projectId: `${PREVIEW_LABEL_PREFIX}.project-id`,
      port: `${PREVIEW_LABEL_PREFIX}.port`,
      previewId: `${PREVIEW_LABEL_PREFIX}.preview-id`,
    } as const;

    /**
     * Compose project name prefix for all preview deployments.
     */
    export const COMPOSE_PROJECT_PREFIX = 'cw-preview-';

    /**
     * Options for starting a preview deployment.
     */
    export interface StartPreviewOptions {
      initiativeId: string;
      phaseId?: string;
      projectId: string;
      branch: string;
    }

    /**
     * Health check result for a single service.
     */
    export interface HealthResult {
      name: string;
      healthy: boolean;
      error?: string;
    }