| 60 | } |
| 61 | |
| 62 | function provide(node: Spec.Any, handlers: ReadonlyArray<LazyHandler>): ProvidedCommand { |
| 63 | const handler = handlers.find((handler) => handler.spec === node.spec) |
| 64 | const spec = handler |
| 65 | ? node.spec.pipe( |
| 66 | Command.withHandler((input) => |
| 67 | Effect.gen(function* () { |
| 68 | yield* Effect.flatMap(Effect.promise(handler.load), (module) => module.default(input)) |
| 69 | }), |
| 70 | ), |
| 71 | ) |
| 72 | : node.spec |
| 73 | if (!Object.keys(node.commands).length) return spec as ProvidedCommand |
| 74 | return spec.pipe( |
| 75 | Command.withSubcommands(Object.values(node.commands).map((child) => provide(child, handlers))), |
| 76 | ) as ProvidedCommand |
| 77 | } |
| 78 | |
| 79 | export * as Runtime from "./runtime" |