Skip to content

feat: add @tuyau/svelte-query adapter#111

Open
ebauger wants to merge 2 commits intoJulien-R44:mainfrom
ebauger:main
Open

feat: add @tuyau/svelte-query adapter#111
ebauger wants to merge 2 commits intoJulien-R44:mainfrom
ebauger:main

Conversation

@ebauger
Copy link
Copy Markdown

@ebauger ebauger commented Apr 8, 2026

Because I love Svelte and Tuyau, cadeau pour la communauté Adonis.js! Merci @Julien-R44

Summary

Adds a new @tuyau/svelte-query package — a Svelte 5 adapter for Tuyau's type-safe TanStack Query integration, following the same architecture as @tuyau/react-query and @tuyau/vue-query.

  • createTuyauSvelteQueryClient() — Proxy-based factory mirroring the API route tree, identical pattern to the Vue/React adapters
  • Type-safe query/mutation/infinite query options builders — delegates to @tuyau/query-core for shared logic
  • Svelte context helperssetTuyauContext(), useTuyau(), useTuyauClient() using Svelte's setContext/getContext
  • Full skipToken support for conditional queries
  • Peers on @tanstack/svelte-query ^6.1.0 (Svelte Query v6 requires Svelte 5, shares @tanstack/query-core v5 with the React/Vue adapters)

Design decisions

Inlined identity functions instead of importing from @tanstack/svelte-query:
The barrel export of @tanstack/svelte-query re-exports .svelte component files (HydrationBoundary, QueryClientProvider) and .svelte.js rune files that Node.js cannot load without the Svelte compiler. Since queryOptions/mutationOptions/infiniteQueryOptions are pure identity functions (they just return their input for type inference), we construct the result objects directly. Types are still imported via import type from @tanstack/svelte-query (safe — erased at build time).

Dual test runner setup:
Option-object-level tests run in Japa (37 tests, no Svelte compiler needed). Integration tests (createQuery, createMutation, createInfiniteQuery end-to-end) run in vitest with @sveltejs/vite-plugin-svelte, using $effect.root() via a withEffectRoot helper — matching TanStack/query's own Svelte test patterns.

@tanstack/query-core bump to ^5.96.2:
Required because @tanstack/svelte-query@6.1.13 depends on @tanstack/query-core@5.96.2. Without aligning all workspace packages to the same version, pnpm resolves two separate copies, causing skipToken (a unique Symbol) to differ between modules and silently breaking conditional query detection.

Test plan

  • pnpm --filter @tuyau/svelte-query build — tsup ESM + DTS (17 KB)
  • pnpm --filter @tuyau/svelte-query typecheck — clean
  • pnpm --filter @tuyau/svelte-query lint — 0 warnings, 0 errors
  • pnpm --filter @tuyau/svelte-query test — 37 Japa + 7 vitest = 44 tests passing
  • pnpm --filter @tuyau/query-core test — 23/23 (no regression)
  • pnpm --filter @tuyau/vue-query test — 47/47 (no regression)
  • pnpm --filter @tuyau/react-query test — 80/80 (no regression)

ebauger added 2 commits April 8, 2026 11:53
Align all packages to the same @tanstack/query-core version to prevent
skipToken Symbol mismatches caused by duplicate module instances in the
pnpm workspace.
Add a Svelte 5 adapter for Tuyau's type-safe TanStack Query integration,
following the same architecture as @tuyau/react-query and @tuyau/vue-query.

Features:
- createTuyauSvelteQueryClient() factory with Proxy-based API tree
- Type-safe queryOptions, mutationOptions, infiniteQueryOptions builders
- Svelte context helpers (setTuyauContext, useTuyau, useTuyauClient)
- Full skipToken support for conditional queries
- Query key/filter helpers for cache management

Key design decisions:
- queryOptions/mutationOptions/infiniteQueryOptions are inlined as identity
  functions because @tanstack/svelte-query's barrel export re-exports .svelte
  component files that Node.js cannot load without a compiler
- Types imported via `import type` from @tanstack/svelte-query (safe, erased
  at build time)
- Peer depends on @tanstack/svelte-query ^6.1.0 (Svelte Query v6 requires
  Svelte 5, uses same @tanstack/query-core v5 as react/vue adapters)
- Integration tests use vitest with @sveltejs/vite-plugin-svelte following
  TanStack/query's own test patterns ($effect.root + withEffectRoot helper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant