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

@ts-pf/swr

v0.1.3

Published

Opt-in SWR keys, fetchers, mutators, and matchers

Downloads

946

Readme

@ts-pf/swr

Opt-in SWR helpers for a ts-pf client. Typed keys, fetchers, mutators, matchers, and stream subscribers — you still call useSWR yourself.

Agent skill: skills/ts-pf-swr/. Sync with npx skills experimental_sync -y.

This package does not wrap useSWR, add a React provider, switch RPC to GET, or fold into @ts-pf/client. Pass the client from createClient<typeof contract>(link) or createClient<Contract>(link) with a generated Contract from @ts-pf/codegen.

Setup

import { createClient } from '@ts-pf/client'
import { FetchLink } from '@ts-pf/client-http'
import { createSwr } from '@ts-pf/swr'
import type { contract } from './contract'

const client = createClient<typeof contract>(new FetchLink({ url: '/rpc' }))
export const swr = createSwr(client)

Pass { prefix: 'user' } when two utils trees would otherwise share keys.

Data fetching

import useSWR from 'swr'

const { data, error, isLoading } = useSWR(
  swr.planet.find.key({ input: { id: 123 } }),
  swr.planet.find.fetcher(),
)

SWR’s error is the thrown PFError. error.code still narrows declared errors; isLocalFailure(error) is local === true. Fetchers do not wrap asResult.

Skip a request with a null key: id ? swr.planet.find.key({ input: { id } }) : null.

Infinite queries

import useSWRInfinite from 'swr/infinite'

const { data, size, setSize } = useSWRInfinite(
  (index, previousPage) => {
    if (previousPage && !previousPage.nextCursor) {
      return null
    }
    return swr.planet.list.key({
      input: { cursor: previousPage?.nextCursor },
    })
  },
  swr.planet.list.fetcher(),
)

The fetcher reads input from the key, so each page can pass a different cursor.

Mutations

import useSWRMutation from 'swr/mutation'

const { trigger, isMutating } = useSWRMutation(
  swr.planet.list.key(),
  swr.planet.create.mutator(),
)

trigger({ name: 'New Planet' })

The useSWRMutation key is the cache entry to revalidate (often a list). trigger is the mutating procedure’s input.

Manual revalidation

import { mutate } from 'swr'

mutate(swr.matcher())
mutate(swr.planet.matcher())
mutate(
  swr.planet.find.matcher({ input: { id: 123 }, strategy: 'exact' }),
)

Default matcher strategy is 'partial' (path prefix + nested input subset).

Subscriptions

For procedures whose output is AsyncIterable (typically stream()):

import useSWRSubscription from 'swr/subscription'

const { data, error } = useSWRSubscription(
  swr.planet.describe.key({ input: { id: 3 } }),
  swr.planet.describe.subscriber({ maxChunks: 10 }),
)

liveSubscriber() keeps the latest event instead of an array. Unsubscribe aborts the call via CallOptions.signal.

Calling clients

The procedure utils object is callable, and .call is the underlying client:

const planet = await swr.planet.find({ id: 123 })
const same = await swr.planet.find.call({ id: 123 })

Not in this package

  • TanStack Query
  • GET vs POST / client operation context
  • Wrapping useSWR as swr.planet.find.useSWR(input)
  • Retry (RetryPlugin on createClient)
  • React components or an SWRConfig provider