import { Effect, Layer } from 'effect' import { encodeImage } from './jsquash' import { EncodeError, ImageEncoder } from './service' /** * The jSquash-backed encoder: the default implementation of `ImageEncoder`. * Runs the encode inline in the calling context; the frontend provides a * worker-backed layer for the app (see docs/adr/0006). */ export const ImageEncoderLive = Layer.succeed( ImageEncoder, ImageEncoder.of({ encode: ({ image, settings }) => Effect.tryPromise({ catch: (cause) => new EncodeError({ cause, message: cause instanceof Error ? cause.message : String(cause), }), try: async () => await encodeImage(image, settings), }), }), )