import { Context, Layer } from "effect" import type { Mutable } from "effect/Types" import * as ErrorHandler from "./ErrorHandler.js" export interface QueryClient { readonly ErrorHandler: Context.Tag> } const id = "@reffuse/extension-query/QueryClient" export type TagClassShape = Context.TagClassShape> export type GenericTagClass = Context.TagClass, typeof id, QueryClient> export const makeGenericTagClass = (): GenericTagClass => Context.Tag(id)() export interface ServiceProps { readonly ErrorHandler?: Context.Tag> } export interface ServiceResult extends Context.TagClass> { readonly Live: Layer.Layer } export const Service = < EH = ErrorHandler.DefaultErrorHandler, HandledE = ErrorHandler.Error>, >( props?: ServiceProps ) => ( (): ServiceResult => { const TagClass = Context.Tag(id)() as ServiceResult (TagClass as Mutable).Live = Layer.succeed(TagClass, { ErrorHandler: (props?.ErrorHandler ?? ErrorHandler.DefaultErrorHandler) as Context.Tag> }) return TagClass } )