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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stackra/query

v2.0.0

Published

Store-backed data fetching for the Stackra framework — TanStack Query-backed cache + fetcher registry, DI-integrated. Composable with @stackra/state stores for cross-app reactive reads.

Downloads

330

Readme

@stackra/query

TanStack Query-backed data fetching for the Stackra framework, with three Stackra-specific add-ons:

  1. DI-native. QueryClient + QueryService are bound in the container. Non-React consumers (action handlers, SSR loaders, background workers) inject QUERY_CLIENT and get the same cache the React hooks use.
  2. liveMode realtime invalidation. useQuery({ liveMode: 'auto', liveChannel: 'themes' }) subscribes to @stackra/realtime events and calls queryClient.invalidateQueries on every message.
  3. Three mutation modes. useMutation({ mutationMode }) supports 'pessimistic' (default), 'optimistic' (auto-rollback on throw), and 'undoable' (Gmail-style countdown with cancel, coordinated by UndoableQueueService).

Under the hood: @tanstack/query-core + @tanstack/react-query (v5).

Install

pnpm add @stackra/query @stackra/container @stackra/contracts \
  @tanstack/query-core @tanstack/react-query

Optional peers: @stackra/state (for state-store writes), @stackra/realtime (for liveMode), @stackra/actions (for the shipped action handlers).

Subpaths

| Import | Contents | | ------------------------ | ---------------------------------------------------------------------------------------- | | @stackra/query | QueryModule, QueryService, UndoableQueueService, tokens | | @stackra/query/react | <StackraQueryProvider>, useQuery, useMutation, useLiveSubscription, usePublish | | @stackra/query/actions | QueryHandler, RefreshHandler | | @stackra/query/testing | MockQueryClient for handler tests |

Quick start

import { Module } from "@stackra/container";
import { QueryModule } from "@stackra/query";

@Module({
  imports: [
    QueryModule.forRoot({
      defaultStaleTime: 5 * 60 * 1000,
      defaultMutationMode: "optimistic",
      defaultLiveMode: "auto",
    }),
  ],
})
export class AppModule {}

React tree:

import { ContainerProvider } from "@stackra/container/react";
import { StackraQueryProvider } from "@stackra/query/react";

<ContainerProvider context={app}>
  <StackraQueryProvider>
    <YourApp />
  </StackraQueryProvider>
</ContainerProvider>;

useQuery

import { useQuery } from "@stackra/query/react";

function ThemeList() {
  const { data, isLoading, error, refetch } = useQuery({
    queryKey: ["themes"],
    fetcher: () => api.listThemes(),
  });

  if (isLoading) return <Spinner />;
  if (error) return <ErrorDisplay error={error} onRetry={refetch} />;
  return (
    <ul>
      {data?.map((t) => (
        <li key={t.id}>{t.label}</li>
      ))}
    </ul>
  );
}

Optional state-store write (for cross-app reactive reads via useSelector):

useQuery(THEMES_STORE, {
  queryKey: ["themes"],
  fetcher: () => api.listThemes(),
});

Auto-invalidate on a realtime channel:

useQuery({
  queryKey: ["themes"],
  fetcher: () => api.listThemes(),
  liveMode: "auto",
  liveChannel: "themes",
});

useMutation

import { useMutation } from "@stackra/query/react";

// Pessimistic (default) — wait for server before updating UI.
const { mutate, isPending } = useMutation({
  mutationFn: (creds) => authService.login(creds),
});

// Optimistic — write locally now, roll back on error.
const { mutate } = useMutation({
  mutationFn: (theme) => api.saveTheme(theme),
  mutationMode: "optimistic",
  optimistic: { store: themeStore, apply: (_, next) => next },
});

// Undoable — Gmail-style "undo send" with countdown.
const { mutate } = useMutation({
  mutationFn: (id) => api.deleteThread(id),
  mutationMode: "undoable",
  undoableTimeout: 5000,
  undoableLabel: "Thread deleted",
  optimistic: {
    store: threadsStore,
    apply: (s, id) => ({ ...s, items: s.items.filter((t) => t.id !== id) }),
  },
  onCancel: (cancel) => showUndoToast({ onUndo: cancel }),
});

Non-React usage

import { QUERY_CLIENT, type IQueryClient } from "@stackra/contracts";

class ThemeService {
  constructor(
    @Inject(QUERY_CLIENT) private readonly queryClient: IQueryClient,
  ) {}

  async loadThemes(): Promise<Theme[]> {
    return this.queryClient.fetch(["themes"], async () => api.listThemes());
  }

  async invalidate(): Promise<void> {
    await this.queryClient.invalidate(["themes"]);
    // Every active useQuery(['themes']) hook refetches.
  }
}

License

MIT © Figentra L.L.C.