import { pipe } from "../../Function"; import type { Has, Region, Tag } from "../../Has"; import * as M from "../Managed"; import * as T from "../Task/_core"; import type { Runtime } from "../Task/combinators/runtime"; import { makeRuntime } from "../Task/combinators/runtime"; import * as L from "./core"; import { LayerFreshInstruction } from "./model"; /** * Embed the requird environment in a region */ export const region = (h: Tag>) => (_: L.Layer): L.Layer>> => pipe(L.fromRawTask(T.asks((r: T): Has> => ({ [h.key]: r } as any))), L.andTo(_, "no-erase")); /** * Converts a layer to a managed runtime */ export const toRuntime = (_: L.Layer): M.Managed> => M.map_(L.build(_), makeRuntime); /** * Returns a fresh version of a potentially memoized layer, * note that this will override the memoMap for the layer and its children */ export const fresh = (layer: L.Layer): L.Layer => new LayerFreshInstruction(layer);