| 167 | * @since 3.16.0 |
| 168 | */ |
| 169 | export const make = <const Steps extends NonEmptyReadonlyArray<make.Step>>( |
| 170 | ...steps: Steps & { [K in keyof Steps]: make.Step } |
| 171 | ): ExecutionPlan<{ |
| 172 | provides: make.StepProvides<Steps> |
| 173 | input: make.StepInput<Steps> |
| 174 | error: |
| 175 | | (Steps[number]["provide"] extends Context.Context<infer _P> | Layer.Layer<infer _P, infer E, infer _R> ? E |
| 176 | : never) |
| 177 | | (Steps[number]["while"] extends (input: infer _I) => Effect.Effect<infer _A, infer _E, infer _R> ? _E : never) |
| 178 | requirements: |
| 179 | | (Steps[number]["provide"] extends Layer.Layer<infer _A, infer _E, infer R> ? R : never) |
| 180 | | (Steps[number]["while"] extends (input: infer _I) => Effect.Effect<infer _A, infer _E, infer R> ? R : never) |
| 181 | | (Steps[number]["schedule"] extends Schedule.Schedule<infer _O, infer _I, infer R> ? R : never) |
| 182 | }> => |
| 183 | makeProto(steps.map((options, i) => { |
| 184 | if (options.attempts !== undefined && options.attempts < 1) { |
| 185 | throw new Error(`ExecutionPlan.make: step[${i}].attempts must be greater than 0`) |
| 186 | } |
| 187 | return { |
| 188 | schedule: options.schedule, |
| 189 | attempts: options.attempts, |
| 190 | while: options.while |
| 191 | ? (input: any) => |
| 192 | effect.suspend(() => { |
| 193 | const result = options.while!(input) |
| 194 | return typeof result === "boolean" ? effect.succeed(result) : result |
| 195 | }) |
| 196 | : undefined, |
| 197 | provide: options.provide |
| 198 | } |
| 199 | }) as any) |
| 200 | |
| 201 | /** |
| 202 | * Namespace containing type helpers used by `ExecutionPlan.make`. |