import type { ConfigError } from "effect/Config"; import * as Effect from "effect/Effect"; import type * as Scope from "effect/Scope"; import { AlchemyContext } from "./AlchemyContext.ts"; import * as Apply from "./Apply.ts"; import { evalStack } from "./EvalStack.ts"; import type { Input } from "./Input.ts"; import * as Plan from "./Plan.ts"; import { renderApply } from "./Report.ts"; import type { ResourceSelection, SelectionOutput } from "./ResourceSelection.ts"; import type { CompiledStack, StackEffect } from "./Stack.ts"; import { Stage } from "./Stage.ts"; export interface DeployOptions extends Plan.MakePlanOptions { stack: StackEffect, ConfigError, Stage | AlchemyContext>; stage: string; dev?: boolean; /** See {@link evalStack} — when set, scoped resources outlive `deploy`. */ scope?: Scope.Scope; } export type DeployResult = Effect.Effect< Input.Resolve, Effect.Error>>, Effect.Services>> >; export interface FilteredDeployOptions extends Omit, keyof ResourceSelection>, ResourceSelection {} /** * Reconcile a stack. Filters select nodes and their transitive dependencies, * not declaration evaluation: the whole stack program still runs. Filtered * deployments return void and leave persisted full-stack outputs unchanged. */ export function deploy = DeployOptions>( options: FilteredDeployOptions & Options, ): DeployResult>; export function deploy(options: FilteredDeployOptions) { return deployStack(options); } /** * Apply `plan`, drawing its progress through the ambient `Cli` when there * is one. The engine only emits events; this is where they are rendered. */ export const applyAndRender =

(plan: P) => Apply.apply(plan).pipe(renderApply(plan)); const deployStack = ({ stack, stage, dev, scope, force, include, exclude, }: FilteredDeployOptions) => evalStack( stack, (stack) => Effect.gen(function* () { const plan = yield* Plan.make(stack, { force, include, exclude }); return yield* applyAndRender(plan); }), { stage, dev, scope }, );