Skip to content
VPaganiPublic

About

A readable syntax for EffectTS

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

EffScript

A readable syntax for Effect. EffScript is to Effect what JSX was to React: a small language that compiles to the TypeScript you would write by hand, minus the incantations. If you know async function and await, you already know effect function and run.

Try it in the browser at effscript.vpagani.dev/playground.

error UserNotFound { id: UserId }

service UserRepo {
  find(id: UserId): Effect<User, UserNotFound>;
}

export effect function greet(id: UserId) {
  const repo = use UserRepo;
  const user = run repo.find(id)
    |> Effect.retry(Schedule.recurs(2))
    |> Effect.timeout("1 second");
  run Effect.log(`Hello, ${user.name}`);
  return user;
}

export const main = greet(UserId.make("u-1"))
  catch {
    UserNotFound(e) => Effect.log(`no user ${e.id}`)
    TimeoutError => Effect.log("too slow")
  }
  with UserRepoLive;
  • Plain output. It compiles to ordinary Effect code (Effect.fn, Context.Service, Data.TaggedError, Effect.catchTags), as TypeScript or JavaScript with source maps. There is no runtime. Core modules such as Effect, Schema and Console need no import (the prelude); the output imports them.
  • The whole ecosystem. Services, errors, schemas, match, streams, layers (with Effect's own Layer API), effect-machine state machines and Effect UI components with JSX-like markup.
  • Real types. Type checked by tsrs, the Rust port of the TypeScript 7 checker, with errors at EffScript positions. EffScript and TypeScript files import each other freely.
  • Tooling included. efs builds, checks, formats and lints, and runs a language server. Plugins for Vite, Rollup, Rolldown, esbuild, Bun and webpack.

Quick start

cargo install --path crates/efs_cli
efs init hello && cd hello && pnpm install && efs check && efs build

Documentation

Status

An early release for Effect 4. Machines and components follow effect-machine and Effect UI, which are pre-1.0, so their syntax may change with them. See Not supported.

License

MIT

About

A readable syntax for EffectTS

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages