{product.title}
++ + {product.category} + +
+${product.price}
+{product.stock} in stock
+diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 764da51..c0957c3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,6 +7,11 @@ on:
push:
branches: [main]
pull_request:
+ # Weekly, so a new Effect 4.x or TypeScript 7.x that breaks Effetch shows
+ # up without waiting for a push: those jobs install the newest versions.
+ schedule:
+ - cron: "0 6 * * 1"
+ workflow_dispatch:
permissions:
contents: read
@@ -68,6 +73,130 @@ jobs:
- name: Build and test
run: pnpm run typecheck && pnpm test && pnpm run build
+ newest-effect:
+ name: check (newest effect)
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v7
+
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v6
+ with:
+ version: 10.12.1
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v7
+ with:
+ node-version: 24
+ cache: pnpm
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ # The peer range is `^4.0.0`, so a new 4.x reaches users without a
+ # release of Effetch. The versions are looked up, because pnpm keeps
+ # the lockfile's version for a range it already satisfies.
+ # npm lists versions in publish order, so a backport can come last:
+ # sort them first.
+ - name: Install newest effect 4.x
+ shell: bash
+ run: |
+ set -euo pipefail
+ newest() {
+ npm view "$1@^4" version --json |
+ node -p '[].concat(JSON.parse(require("fs").readFileSync(0, "utf8"))).sort((a, b) => a.localeCompare(b, "en", { numeric: true })).pop()'
+ }
+ effect="$(newest effect)"
+ vitest="$(newest @effect/vitest)"
+ for version in "$effect" "$vitest"; do
+ if ! [[ "$version" =~ ^4\.[0-9]+\.[0-9]+$ ]]; then
+ echo "::error::Couldn't look up the newest 4.x version (got '$version')"
+ exit 1
+ fi
+ done
+ echo "Testing effect@$effect with @effect/vitest@$vitest"
+ pnpm add --workspace-root --save-dev --save-exact \
+ "effect@$effect" "@effect/vitest@$vitest"
+
+ - name: Build and test
+ run: pnpm run typecheck && pnpm test && pnpm run build
+
+ # The installed package against the TypeScript versions and runtimes the
+ # docs name, beyond the `check` job's TypeScript 6 and Node.js 24. Each
+ # reuses the smoke test's consumer program (scripts/compat.sh).
+ compatibility:
+ name: ${{ matrix.name }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - name: typescript 5.7 (oldest supported)
+ mode: typescript
+ target: "5.7"
+ - name: typescript 7
+ mode: typescript
+ target: "7"
+ - name: node.js 20
+ mode: runtime
+ target: node
+ node: 20
+ - name: node.js 22
+ mode: runtime
+ target: node
+ node: 22
+ - name: bun
+ mode: runtime
+ target: bun
+ - name: deno
+ mode: runtime
+ target: deno
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v7
+
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v6
+ with:
+ version: 10.12.1
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v7
+ with:
+ node-version: 24
+ cache: pnpm
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ # Builds, packs and writes the consumer program the check reuses.
+ - name: Smoke test
+ run: pnpm run smoke
+
+ - name: Set up Node.js ${{ matrix.node }}
+ if: matrix.node
+ uses: actions/setup-node@v7
+ with:
+ node-version: ${{ matrix.node }}
+
+ - name: Set up Bun
+ if: matrix.target == 'bun'
+ uses: oven-sh/setup-bun@v2
+ with:
+ bun-version: 1.x
+
+ - name: Set up Deno
+ if: matrix.target == 'deno'
+ uses: denoland/setup-deno@v2
+ with:
+ deno-version: 2.x
+
+ - name: Check ${{ matrix.mode }} ${{ matrix.target }}
+ run: bash scripts/compat.sh ${{ matrix.mode }} ${{ matrix.target }}
+
site:
name: build docs site
runs-on: ubuntu-latest
diff --git a/.oxlintrc.json b/.oxlintrc.json
index 0f8293d..6fc92c7 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -76,6 +76,22 @@
]
}
},
+ {
+ "files": ["examples/store-react/**"],
+ "plugins": [
+ "import",
+ "promise",
+ "typescript",
+ "unicorn",
+ "react",
+ "jsx-a11y"
+ ],
+ "env": { "browser": true, "node": true },
+ "rules": {
+ "react/exhaustive-deps": "warn",
+ "jsx-a11y/alt-text": "error"
+ }
+ },
{
"files": ["site/**"],
"plugins": [
diff --git a/AGENTS.md b/AGENTS.md
index 7de0dc1..a1e7e6f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -24,7 +24,8 @@
inline conditional types. One exception: `CallEffect` and the call
signatures (`NoBodyMethod`, `BodyMethod`, `RequestMethod`, `Endpoint`)
write out the members of `CallError` and `CallServices`, so hovers show
- the errors rather than the alias. Keep them in sync; the type tests check
+ the errors rather than the alias, and `Fetch.errorCodec` writes out
+ those of `ErrorCodecErrors`. Keep them in sync; the type tests check
each one against the aliases.
4. **Runtime targets: browsers, React Native (Hermes/Metro), Node ≥ 20, Bun,
Deno.** No `node:` imports, no Node globals, **no `new URL()`** (React
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c785b7..83e26a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,12 +2,98 @@
All notable changes to `@monarcode/effetch`, newest first.
-## Unreleased
+## 0.1.0
+
+The first stable release. From here, an update within 0.1.x doesn't break
+code written for 0.1.0, apart from the few exceptions that
+[Versioning](https://effetch.monarcode.dev/docs/reference/compatibility#versioning)
+lists. The changes since 0.1.0-rc.5:
+
+### Added
+
+- `Fetch.errorCodec` builds a codec (a schema with a JSON encoding) for
+ every error a call can fail with, to send its failures where only data
+ goes: an Effect RPC's `error`, a server-rendered page, a worker. The
+ other side gets the same errors back, typed as on the server: an
+ `HttpError`'s body is decoded again from the response text with the
+ call's error schema, and the `statusErrors` errors come back as their own
+ classes.
+ - Give it a bound endpoint (`Fetch.errorCodec(todos.get)`), a definition
+ and its client (`Fetch.errorCodec(getTodo, { client: Api })`), or the
+ schemas of a plain method call
+ (`Fetch.errorCodec({ error: ApiError, statusErrors: { 404: NotFound } })`).
+ - Add plugins' errors, such as `TimeoutError`, as `errors`.
+ - Headers, a `NetworkError`'s `cause` and a `DecodeError`'s `issue` stay
+ behind.
+ - An error whose schema sends no `_tag` goes with its schema's name,
+ the `_tag` it leaves out or its identifier, such as a class's name, so
+ it decodes with its own schema, even when the other side lists its
+ errors in another order. A schema without a name of its own goes by
+ its place among those, so both sides must list them in the same order.
+
+ It comes with the types `ErrorCodec`, `ErrorCodecErrors`,
+ `ErrorCodecSource`, `ErrorCodecClient` and `ErrorCodecOptions`. A new
+ page,
+ [Send errors across the wire](https://effetch.monarcode.dev/docs/errors/across-the-wire),
+ shows it with an RPC.
+
+### Fixed
+
+- `HttpError`, `NetworkError` and `DecodeError` now encode to JSON and
+ decode back into the same classes, so they can be an Effect RPC's `error`
+ or cross from the server to the browser. Before,
+ `Schema.toCodecJson(Fetch.HttpError)` couldn't decode any `HttpError`, and
+ the other two couldn't be encoded. What's sent:
+ - an `HttpError` goes without its headers, which decode as empty, so
+ `set-cookie` and the like stay where they were. Its `body` goes when
+ it's JSON. A body decoded into something else, such as a class,
+ doesn't, and decodes as `undefined`.
+ - a `NetworkError` goes without its `cause`, and a `DecodeError` without
+ its `issue`. Both decode as `undefined`.
+
+ Constructing the errors and reading their fields are unchanged. Their
+ schemas' `Encoded` types now match what's sent.
### Changed
- The documentation site moved to https://effetch.monarcode.dev. The old
address, https://effetch.pages.dev, still serves it.
+- CI now runs the installed package on Node.js 20 and 22, Bun 1 and Deno 2,
+ compiles it with TypeScript 5.7 (the oldest supported) and 7, and runs the
+ tests against the newest Effect 4.x. The
+ [Compatibility](https://effetch.monarcode.dev/docs/reference/compatibility)
+ page lists what each job covers.
+
+### Documentation
+
+- Effetch has a versioning policy, in the README and on the
+ [Compatibility](https://effetch.monarcode.dev/docs/reference/compatibility#versioning)
+ page. An update within 0.1.x doesn't break code written for 0.1.0: the
+ API, the fields errors encode to and the supported TypeScript versions
+ and runtimes stay as they are, and breaking changes wait for 0.2.0. The
+ exceptions follow Effect, which marks its HTTP modules and `encoding/Sse`
+ unstable: when they change, a 0.1.x update can change the types that come
+ from them, how Server-Sent Events behave, or the oldest `effect` it
+ supports. In 0.2.0, `retry` waits as a `Retry-After` header asks by
+ default. The "release candidate" notes are gone.
+- The examples are new. Each one does a real task against a free public
+ API that needs no key, and runs with `pnpm example
+ There's no such page. Back to the store
+ No products here. This product isn't in the store.
+
+ {product.category}
+
+ ${product.price} {product.stock} in stock There's no page here. This page's address has a search param it can't read. {describeError(error)}{category}
+
+ {products.map((product) => (
+
+ )}
+
+ >
+ );
+}
+
+/**
+ * The cart workflow, from a form: the button waits while it runs, and its
+ * message, such as an `OutOfStock`, shows under it. Leaving the page
+ * while it runs interrupts it.
+ */
+function BuyCheapest({ category }: { readonly category: string }) {
+ const { runtime } = categoryRoute.useRouteContext();
+ const action = useActionCategories
+
+ {categories.map((category) => (
+
+ >
+ );
+}
diff --git a/examples/store-react/src/main.tsx b/examples/store-react/src/main.tsx
new file mode 100644
index 0000000..5b4a321
--- /dev/null
+++ b/examples/store-react/src/main.tsx
@@ -0,0 +1,21 @@
+import { RouterProvider } from "@tanstack/react-router";
+import { StrictMode } from "react";
+import { createRoot } from "react-dom/client";
+
+import { makeRouter } from "./router.ts";
+import { runtime } from "./store.ts";
+
+import "./styles.css";
+
+// The store example's runtime: its modules, on its client, on the browser's
+// `fetch`. The router hands it to every loader in its context.
+const router = makeRouter(runtime);
+
+const root = document.querySelector("#root");
+if (root === null) throw new Error("index.html has no #root element");
+
+createRoot(root).render(
+ {product.title}
+
new URL()
- , so it runs on Hermes too. CI tests on Node.js 24.
+ , so it runs on Hermes too. CI runs it on Node.js 20 to 24,
+ Bun and Deno.