| 1 | import type { ConfigError } from "effect/Config"; |
| 2 | import { Effect } from "effect"; |
| 3 | import type * as Scope from "effect/Scope"; |
| 4 | import type { AlchemyContext } from "./AlchemyContext.ts"; |
| 5 | import * as Apply from "./Apply.ts"; |
| 6 | import * as Plan from "./Plan.ts"; |
| 7 | import type { CompiledStack, StackEffect } from "./Stack.ts"; |
| 8 | import { evalStack } from "./Stack.ts"; |
| 9 | import type { Stage } from "./Stage.ts"; |
| 10 | |
| 11 | export const destroy = ({ |
| 12 | stack, |
| 13 | stage, |
| 14 | dev, |
| 15 | scope, |
| 16 | include, |
| 17 | exclude, |
| 18 | }: { |
| 19 | stack: StackEffect<CompiledStack, ConfigError, Stage | AlchemyContext>; |
| 20 | stage: string; |
| 21 | dev?: boolean; |
| 22 | /** See {@link evalStack} — when set, scoped resources outlive `destroy`. */ |
| 23 | scope?: Scope.Scope; |
| 24 | /** Destroy always operates on the full stack. */ |
| 25 | include?: never; |
| 26 | exclude?: never; |
| 27 | }) => |
| 28 | include !== undefined || exclude !== undefined |
| 29 | ? Effect.die( |
| 30 | new Plan.InvalidResourceSelection({ |
| 31 | message: "Filtered destroy is not supported.", |
| 32 | }), |
| 33 | ) |
| 34 | : evalStack( |
| 35 | stack, |
| 36 | (stack) => Plan.destroy(stack).pipe(Effect.flatMap(Apply.apply)), |
| 37 | { stage, dev, scope }, |
| 38 | ); |