Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ Cached queries, mutations and invalidation, built on `effect/reactivity` and
`readonly foo?: T | undefined`.
- The build is plain `tsc` (`scripts/build.mjs`), not a bundler. Bundlers
rewrite `export * as Query` into a synthetic namespace whose name shows up
in consumers' hovers. Stay on TypeScript 6: TypeScript 7 ships no compiler
API, which `check-docs.mjs`, `editor-check.mjs` and the Effect language
service need.
in consumers' hovers. After `tsc`, the build rewrites `dist/index.d.ts`
to declare each namespace with its JSDoc
(`declare namespace Query { export { … } }`), since TypeScript shows no
JSDoc for `export * as` in a hover. `pnpm run dev` (`tsc --watch`)
skips that step, so run `pnpm run build` before checking hovers. Stay on
TypeScript 6: TypeScript 7 ships no compiler API, which `check-docs.mjs`, `editor-check.mjs` and
the Effect language service need.

## Testing

Expand Down
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,65 @@

All notable changes to `@monarcode/effetch-query`, newest first.

## 0.1.0-rc.5

Additive: opt-in entity sync, two exported errors, named types for
`api.query`, and namespace docs in editor hovers. It works with
`@monarcode/effetch` 0.1.0-rc.4 and later in 0.1, as rc.4 does. One fix
can surface in your app: `useRefetch` with a key that holds a query now
throws `Query.KeyHoldsTargetError` instead of doing nothing (see Fixed).

### Added

- `Query.KeyHoldsTargetError` and, from `@monarcode/effetch-query/effetch`,
`EndpointQueryError` are exported, so you can check for them with
`instanceof` and name their types. They were thrown before, but only
their `_tag` could be matched. Their tags and messages are unchanged,
and their fields (`key`; `route` and `cause`) are documented.
- Named types for what `api.query` takes and gives:
`EndpointQueryValue`, `EndpointQueryCallError` and
`EndpointQueryOptionsFor`. `api.query`'s declaration uses them in place
of inline conditional types, so Go to Definition and its hover read
more simply. The types they resolve to, at each call, are unchanged.
- `api.query`, `api.infiniteQuery` and `api.mutation` have examples in
their hovers.
- Entity sync: `QueryClient.make({ entities: { sync: [Todos] } })` keeps
the cached copies of those entities in sync. When a query's fetch
succeeds, each copy in its value goes over the older copies with the
same id in every other query that holds the entity, so a details
refetch updates the list rows, and a list fetch updates the cached
details, with no other fetch. The newer copy wins, by when its fetch
started (each page's own request, for an infinite query's refetch), and
loading the next page sends only that page. A write counts as newer than fetches in flight, but only
fetched copies are synced to other queries. A query opts out with
`entities: { sync: false }` (`Query.EntitiesOptions`). See "Keep copies
in sync" in the README.
- The README explains decoding an endpoint's own response shape to an
entity's schema ("Responses in other shapes"), and what server
rendering needs from a schema that transforms ("Schemas that
transform"): a query whose schema can't encode its value is left out
of `dehydrate` with no error, and the browser fetches it again.

### Fixed

- `useRefetch` with a key that holds a query, a family or a group, such as
`useRefetch([todos, profile])`, now throws `Query.KeyHoldsTargetError` as
it renders, as the README said it fails. Before, its `refetch` did
nothing and the error was lost. Pass a `Query.group` instead.

### Changed

- Hovers on the core namespaces (`Entity`, `InfiniteQuery`, `Mutation`,
`Query`, `QueryClient` and `Signals`) show their docs. Before, a hover
showed only the module's path, such as
`(alias) module ".../dist/Query"`. A member's hover now reads
`(alias) const Query.make: …`, with its docs as before. Go to Definition
on a namespace lands on `index.d.ts`; on a member, it still lands on the
member's own declaration. Completions after `Query.` list each member as
an alias, as Effetch's `Fetch.` does.
- Developed and tested against `effect` 4.1.5 (and `@effect/atom-react`
4.1.5). The peer ranges are unchanged.

## 0.1.0-rc.4

Released alongside `@monarcode/effetch` 0.1.0-rc.4, which it needs: upgrade
Expand Down
316 changes: 292 additions & 24 deletions README.md

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@monarcode/effetch-query",
"version": "0.1.0-rc.4",
"version": "0.1.0-rc.5",
"description": "Effectful queries and mutations for Effect 4, inspired by TanStack Query. Cached, kept fresh, typed end to end, and made to pair with effetch.",
"keywords": [
"TanStack",
Expand Down Expand Up @@ -83,32 +83,32 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.18.5",
"@effect/atom-react": "4.1.1",
"@effect/atom-react": "4.1.5",
"@effect/language-service": "0.87.5",
"@effect/vitest": "4.1.1",
"@effect/vitest": "4.1.5",
"@monarcode/effetch": "0.1.0-rc.4",
"@react-router/dev": "8.5.1",
"@react-router/dev": "8.5.2",
"@tanstack/react-router": "1.170.46",
"@tanstack/react-start": "1.169.4",
"@tanstack/react-start": "1.169.7",
"@testing-library/dom": "10.4.2",
"@testing-library/react": "16.3.3",
"@types/node": "26.6.6",
"@types/react": "19.3.0",
"@types/react-dom": "19.3.0",
"@vitejs/plugin-react": "6.1.2",
"effect": "4.1.1",
"@vitejs/plugin-react": "6.3.0",
"effect": "4.1.5",
"happy-dom": "21.0.4",
"husky": "9.1.7",
"oxfmt": "0.75.0",
"oxlint": "1.90.0",
"oxfmt": "0.79.0",
"oxlint": "1.94.0",
"publint": "0.3.25",
"react": "19.3.1",
"react-dom": "19.3.1",
"react-router": "8.5.1",
"react-router": "8.5.2",
"scheduler": "0.28.0",
"typescript": "6.0.3",
"vite": "8.3.5",
"vitest": "5.0.5"
"vite": "8.3.8",
"vitest": "5.1.1"
},
"peerDependencies": {
"@effect/atom-react": "^4.1.0",
Expand Down
Loading