Sekhmet
Sekhmet is a set of small TypeScript libraries for expressing program states and effects in types: Rust-style enums (Option, Result and your own), an effect system with fibers and cancellation, and the primitives they share.
The packages are ESM-only, have no runtime dependencies outside the repository, run in any JavaScript runtime (Deno, Node.js, Bun, browsers), and are compiled with TypeScript's strictest settings, including isolatedDeclarations.
Packages
| Package | What it is |
|---|---|
@sekhmet/enum | Rust-style enums: Enum, Option, Result, Ordering, Latch and Poll |
@sekhmet/effect | Effects run on fibers: typed errors, schedulers, concurrency, cancellation with cleanup |
@sekhmet/vow | Vow, a promise-like value that resolves synchronously |
@sekhmet/matrix | matrix(), every combination of a set of values, for parameterized tests |
@sekhmet/panic | Rust-style panics: a reporting hook and a catchUnwind recovery boundary, with no global state |
@sekhmet/primordials | Struct, Subtle, block and define: the building blocks of the other packages |
@sekhmet/workflow | todo/unimplemented, unreachable and invariant checks: panics that mark the state of the code |
Guides for each package are on the docs site, and the API reference is on JSR.
Using Sekhmet
Every package is published on JSR. Add one with Deno:
deno add jsr:@sekhmet/enumor, for Node.js and other npm-compatible tools, through JSR's npm compatibility layer:
npx jsr add @sekhmet/enum # npm
pnpm dlx jsr add @sekhmet/enum # pnpm
yarn dlx jsr add @sekhmet/enum # yarn
bunx jsr add @sekhmet/enum # bunImport a feature by its entrypoint. @sekhmet/enum and @sekhmet/primordials have no root export, so name the feature:
import { assertEquals } from "@std/assert";
import { Err, Ok, type Result } from "@sekhmet/enum/result";
const half = (n: number): Result<number, string> =>
n % 2 === 0 ? Ok(n / 2) : Err(`${n} is odd`);
assertEquals(
half(10)
.map((n) => n + 1)
.unwrapOr(0),
6,
);
assertEquals(half(3).unwrapOr(0), 0);Larger features come in two styles with the same behaviour:
- main (
@sekhmet/enum/option): classes with methods that chain, such asSome(1).map(f).unwrapOr(0); - mini (
@sekhmet/enum/option/mini): free functions, such asunwrapOr(map(Some(1), f), 0), so a bundler keeps only what you import.
A main value is also a mini value, so the two styles mix.
Contributing
See CONTRIBUTING.md. deno task ci runs every check; deno task docs:dev serves the docs site locally.
License
MIT. See LICENSE.md.