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  from "effect/Effect";
import { ,  } from "sidetrack/effect";
 
type  = {
  : { : string };
};
 
const  = <>();
 
const  = <>({
  : {
    : .["DATABASE_URL"]!,
  },
  : {
    : {
      : async () => {
        .(`Welcome ${.payload.email}`);
      },
    },
  },
});
 
const  = .(
  .(, () =>
    .insertJob("userOnboarding", { : "hello@example.com" }),
  ).(.()),
);
⚠️

If the sidetrack/effect import doesn’t work, you will need to use

import { SidetrackEffect } from "sidetrack";

and access the methods on that export (e.g. SidetrackEffect.makeLayer). Certain TypeScript configurations don’t allow for that import to work correctly.

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.