Skip to Content
GuidesUsing Sidetrack With Effect

Using Effect-TS?

If you are using Effect-TS, Sidetrack exports an Effect-based API as well.

Sidetrack is written with Effect, which means that you can use the Effect API directly if you prefer.

import * as Effect from "effect/Effect"; // import { createSidetrackServiceTag, makeLayer } from "sidetrack/effect"; import { SidetrackEffect } from "sidetrack"; type Queues = { userOnboarding: { email: string }; }; const SidetrackService = SidetrackEffect.getSidetrackService<Queues>(); const sidetrackLayer = SidetrackEffect.layer<Queues>({ databaseOptions: { databaseUrl: process.env["DATABASE_URL"]!, }, queues: { userOnboarding: { run: async (payload) => { console.log(`Welcome ${payload.email}`); }, }, }, }); Effect.runPromise( Effect.flatMap(SidetrackService, (sidetrack) => sidetrack.insertJob("userOnboarding", { email: "hello@example.com" }), ).pipe(Effect.provide(sidetrackLayer)), );
⚠️

If you use ESM, you can use the sidetrack/effect import if you want.

You can find the remaining reference documentation for the Effect docs here. The functions are similar to the ones in the class-based API, but they return Effects instead of Promises, with some error handling. Over time, the Effect API might be expanded to include more features. Please open an issue if you have any requests for how we can make the API more ergonomic or “Effectful.”

The test utils mentioned in the Testing Sidetrack section can also be found under the testUtils key in the sidetrack service. For example, you can do sidetrack.testUtils.runJob in the example above.

Last updated on