@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 67 lines 2.23 KB
Raw
1 import type { ConfigError } from "effect/Config";
2 import * as Effect from "effect/Effect";
3 import type * as Scope from "effect/Scope";
4 import { AlchemyContext } from "./AlchemyContext.ts";
5 import * as Apply from "./Apply.ts";
6 import { evalStack } from "./EvalStack.ts";
7 import type { Input } from "./Input.ts";
8 import * as Plan from "./Plan.ts";
9 import { renderApply } from "./Report.ts";
10 import type { ResourceSelection, SelectionOutput } from "./ResourceSelection.ts";
11 import type { CompiledStack, StackEffect } from "./Stack.ts";
12 import { Stage } from "./Stage.ts";
13
14 export interface DeployOptions<A> extends Plan.MakePlanOptions {
15 stack: StackEffect<CompiledStack<A>, ConfigError, Stage | AlchemyContext>;
16 stage: string;
17 dev?: boolean;
18 /** See {@link evalStack} — when set, scoped resources outlive `deploy`. */
19 scope?: Scope.Scope;
20 }
21
22 export type DeployResult<A> = Effect.Effect<
23 Input.Resolve<A>,
24 Effect.Error<ReturnType<typeof deployStack<A>>>,
25 Effect.Services<ReturnType<typeof deployStack<A>>>
26 >;
27
28 export interface FilteredDeployOptions<A>
29 extends Omit<DeployOptions<A>, keyof ResourceSelection>, ResourceSelection {}
30
31 /**
32 * Reconcile a stack. Filters select nodes and their transitive dependencies,
33 * not declaration evaluation: the whole stack program still runs. Filtered
34 * deployments return void and leave persisted full-stack outputs unchanged.
35 */
36 export function deploy<A, Options extends FilteredDeployOptions<A> = DeployOptions<A>>(
37 options: FilteredDeployOptions<A> & Options,
38 ): DeployResult<SelectionOutput<A, Options>>;
39 export function deploy<A>(options: FilteredDeployOptions<A>) {
40 return deployStack(options);
41 }
42
43 /**
44 * Apply `plan`, drawing its progress through the ambient `Cli` when there
45 * is one. The engine only emits events; this is where they are rendered.
46 */
47 export const applyAndRender = <P extends Plan.Plan>(plan: P) =>
48 Apply.apply(plan).pipe(renderApply(plan));
49
50 const deployStack = <A>({
51 stack,
52 stage,
53 dev,
54 scope,
55 force,
56 include,
57 exclude,
58 }: FilteredDeployOptions<A>) =>
59 evalStack(
60 stack,
61 (stack) =>
62 Effect.gen(function* () {
63 const plan = yield* Plan.make(stack, { force, include, exclude });
64 return yield* applyAndRender(plan);
65 }),
66 { stage, dev, scope },
67 );