TypeScript: Creating a Supabase Client with Effect and Layer

I had doubts whether I should post it here or in TS, but here we are
export const make = Effect.gen(function* () {
  const cfg = yield* SupabaseConfig

  const client = createClient(cfg.Url, Redacted.value(cfg.Key))

  return {
    exec: <A>(f: (a: SupabaseClient, signal: AbortSignal) => PromiseLike<A>) =>
      Effect.tryPromise({
        async try(signal) {
          return f(client, signal)
        },
        catch(cause) {
          return new SupabaseError({ cause })
        },
      }),
  }
})

export class Supabase extends Effect.Tag(`Supabase`)<
  Supabase,
  Effect.Effect.Success<typeof make>
>() {
  static layer = Layer.effect(this, make)
}
Was this page helpful?