MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / toApiHandler

Function toApiHandler

packages/core/api/src/server/host-foundation.ts:246–265  ·  view source on GitHub ↗
(
  // The app layer must already provide every route requirement; only the HTTP
  // platform is missing, which `HttpServer.layerServices` supplies below. Typed
  // loosely (success/error/requirement channels erased) because each host's app
  // layer has a different, fully-resolved set — self-host's `AppLayer` outputs
  // `never`, local's outputs `ExecutorService | …` (provideMerge keeps them in
  // the success channel). The runtime contract is the same either way.
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  appLayer: Layer.Layer<any, any, any>,
)

Source from the content-addressed store, hash-verified

244 * synthetic platform.
245 */
246export const toApiHandler = (
247 // The app layer must already provide every route requirement; only the HTTP
248 // platform is missing, which `HttpServer.layerServices` supplies below. Typed
249 // loosely (success/error/requirement channels erased) because each host's app
250 // layer has a different, fully-resolved set — self-host's `AppLayer` outputs
251 // `never`, local's outputs `ExecutorService | …` (provideMerge keeps them in
252 // the success channel). The runtime contract is the same either way.
253 // eslint-disable-next-line @typescript-eslint/no-explicit-any
254 appLayer: Layer.Layer<any, any, any>,
255): ApiHandler => {
256 // `HttpServer.layerServices` supplies the synthetic HTTP platform so
257 // `toWebHandler` can run handlers without a listening socket.
258 const web = HttpRouter.toWebHandler(appLayer.pipe(Layer.provideMerge(HttpServer.layerServices)));
259 // With every requirement provided the leftover `HR` is `never`, so `handler`
260 // is the one-arg `(request) => Promise<Response>` form — but the loose
261 // `R = any` input widens `HR` to `any` (a two-arg signature), so narrow back
262 // to the runtime contract.
263 const handler = web.handler as (request: Request) => Promise<Response>;
264 return { handler, dispose: web.dispose };
265};

Callers 1

makeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected