| 140 | * `composePluginHandlerLayer` + `providePluginExtensions` instead. |
| 141 | */ |
| 142 | export const composePluginHandlers = <TPlugins extends readonly AnyPlugin[]>( |
| 143 | plugins: TPlugins, |
| 144 | extensions: PluginExtensions<TPlugins>, |
| 145 | ): AnyLayer => { |
| 146 | const layers: AnyLayer[] = []; |
| 147 | for (const p of plugins) { |
| 148 | if (!p.handlers) continue; |
| 149 | const handlerLayer = p.handlers(); |
| 150 | if (!p.extensionService) { |
| 151 | layers.push(handlerLayer); |
| 152 | continue; |
| 153 | } |
| 154 | const ext = (extensions as Record<string, unknown>)[p.id]; |
| 155 | layers.push( |
| 156 | handlerLayer.pipe( |
| 157 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 158 | Layer.provide(Layer.succeed(p.extensionService)(ext as any)), |
| 159 | ), |
| 160 | ); |
| 161 | } |
| 162 | // `Layer.empty` is `Layer<never, never, never>`; widening to `AnyLayer` |
| 163 | // (`Layer<any, any, any>`) needs the unknown step because TS can't see |
| 164 | // through Layer's variance markers without it. |
| 165 | // oxlint-disable-next-line executor/no-double-cast |
| 166 | if (layers.length === 0) return Layer.empty as unknown as AnyLayer; |
| 167 | return Layer.mergeAll(...(layers as [AnyLayer, ...AnyLayer[]])); |
| 168 | }; |
| 169 | |
| 170 | /** |
| 171 | * Build the merged late-binding Layer of plugin handler implementations |