npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

eden-tanstack-react-query

v0.1.4

Published

Type-safe TanStack Query integration for Elysia Eden - like tRPC for Elysia

Readme

eden-tanstack-react-query

License: Apache 2.0 TypeScript Tests

Type-safe TanStack Query integration for Elysia Eden. Like @trpc/react-query, but for Elysia.

Size: 9.76 KB (gzipped: 2.42 KB)

✨ Features

  • End-to-end type safety - Full TypeScript inference from Elysia routes
  • Native TanStack Query patterns - Use standard useQuery, useMutation, useInfiniteQuery
  • Query options factories - queryOptions(), mutationOptions(), infiniteQueryOptions()
  • Automatic query key generation - Type-safe keys derived from route paths
  • Path parameter support - eden.users({ id: '1' }).get.queryOptions()
  • Query invalidation helpers - queryFilter() for cache management

📦 Installation

bun add eden-tanstack-react-query @tanstack/react-query @elysiajs/eden

🚀 Quick Start

1. Define your Elysia server

// server.ts
import { Elysia, t } from 'elysia'

const app = new Elysia()
  .get('/users', () => [
    { id: '1', name: 'Alice' },
    { id: '2', name: 'Bob' }
  ])
  .get('/users/:id', ({ params }) => ({
    id: params.id,
    name: `User ${params.id}`
  }))
  .post('/users', ({ body }) => ({
    id: String(Date.now()),
    ...body
  }), {
    body: t.Object({ name: t.String() })
  })
  .listen(3000)

export type App = typeof app

2. Create typed hooks

// lib/eden.ts
import { createEdenTanStackQuery } from 'eden-tanstack-react-query'
import { treaty } from '@elysiajs/eden'
import type { App } from './server'

export const { EdenProvider, useEden, useEdenClient } = createEdenTanStackQuery<App>()
export const edenClient = treaty<App>('http://localhost:3000')

3. Set up providers

// App.tsx
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { EdenProvider, edenClient } from './lib/eden'

const queryClient = new QueryClient()

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <EdenProvider client={edenClient} queryClient={queryClient}>
        <YourApp />
      </EdenProvider>
    </QueryClientProvider>
  )
}

4. Use in components

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { useEden } from './lib/eden'

function UserList() {
  const eden = useEden()
  const queryClient = useQueryClient()

  // Query
  const { data: users } = useQuery(eden.users.get.queryOptions())

  // Query with path params
  const { data: user } = useQuery(
    eden.users({ id: '1' }).get.queryOptions()
  )

  // Mutation with cache invalidation
  const createUser = useMutation({
    ...eden.users.post.mutationOptions(),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: eden.users.get.queryKey() })
    }
  })

  return (
    <div>
      <ul>
        {users?.map(user => <li key={user.id}>{user.name}</li>)}
      </ul>
      <button onClick={() => createUser.mutate({ name: 'New User' })}>
        Add User
      </button>
    </div>
  )
}

📖 API Reference

createEdenTanStackQuery()

Creates typed providers and hooks for your Elysia app.

const { EdenProvider, useEden, useEdenClient } = createEdenTanStackQuery<App>()

useEden()

Returns the Eden options proxy with methods for each route.

Query Methods (GET, HEAD, OPTIONS)

| Method | Description | |--------|-------------| | .queryOptions(input?, opts?) | Options for useQuery | | .queryKey(input?) | Query key for cache operations | | .infiniteQueryOptions(input, opts) | Options for useInfiniteQuery |

Mutation Methods (POST, PUT, PATCH, DELETE)

| Method | Description | |--------|-------------| | .mutationOptions(opts?) | Options for useMutation | | .mutationKey() | Mutation key |

Path Parameters

Access routes with path params using function calls:

// Route: /users/:id
eden.users({ id: '123' }).get.queryOptions()

// Nested: /posts/:postId/comments/:commentId
eden.posts({ postId: '1' }).comments({ commentId: '2' }).get.queryOptions()

Infinite Queries

For paginated data:

import { useInfiniteQuery } from '@tanstack/react-query'

const { data, fetchNextPage, hasNextPage } = useInfiniteQuery(
  eden.posts.get.infiniteQueryOptions(
    { limit: 10 },
    {
      getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
      initialPageParam: null,
    }
  )
)

Query with Input

Pass query parameters or request body:

// Query params: GET /users?role=admin
eden.users.get.queryOptions({ query: { role: 'admin' } })

// With headers
eden.users.get.queryOptions({
  query: { role: 'admin' },
  headers: { 'X-Custom': 'value' }
})

🔄 Comparison

| Feature | eden-tanstack-react-query | eden-query | |---------|---------------------------|------------| | API Style | useQuery(eden.users.get.queryOptions()) | eden.users.get.useQuery() | | TanStack Query Native | ✅ Standard hooks | ❌ Custom wrappers | | Query Options | ✅ Full access | ❌ Limited | | Learning Curve | Standard TanStack Query | Custom API | | Bundle Size | ~10 KB | Larger |

📄 License

Apache-2.0

Copyright 2025 Ilya Zhidkov