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

@sejohnson/streamed-resource

v0.0.2

Published

Give me your promises, and I will keep them.

Readme

@sejohnson/streamed-resource

Give me your promises, and I will keep them.

[!NOTE] This library works great along with the excellent sveltekit-search-params!

Why?

SvelteKit's streamed promises are an awesome feature, but they can be annoying to work with. Consider the following setup:

// +page.server.ts
export function load() {
	return {
		postsQuery: getPosts()
	};
}
<!-- +page.svelte -->
<script>
	const { data } = $props();
</script>

{#await data.postsQuery}
	<pre>Loading...</pre>
{:then result}
	<pre>{JSON.stringify(data, undefined, 2)}</pre>
{:catch error}
	<pre>{JSON.stringify(error, undefined, 2)}</pre>
{/await}

<button onclick={() => invalidateAll()}>invalidate</button>

This works great, right up until you revalidate the page by clicking the button. Because data.postsQuery becomes a new promise, you get the Loading... UI again, throwing out your old data instead of keeping the old data until the new data is ready. You can get around this by doing a bunch of gross effect-based stuff, but... that's gross and effect-based.

Instead... you can use this library!

Add the transporter to hooks.ts:

import type { Transport } from '@sveltejs/kit';
import { transport as StreamedResource } from '@sejohnson/streamed-resource/transport';

export const transport: Transport = {
	StreamedResource
};

...and your setup can now look like this:

import { createStreamedResource } from '@sejohnson/streamed-resource';

// +page.server.ts
export function load() {
	return {
		postsQuery: createStreamedResource(['posts'], getPosts())
	};
}
<!-- +page.svelte -->
<script>
	const { data } = $props();
</script>

{#if data.postsQuery.status === 'loading'}
	<pre>Loading...</pre>
{:else if data.postsQuery.status === 'error'}
	<pre>{JSON.stringify(data.postsQuery.error, undefined, 2)}</pre>
{:else}
	<pre>{JSON.stringify(data.postsQuery.data, undefined, 2)}</pre>
{/if}

{#if data.revalidating}
	<pre>Revalidating...</pre>
{/if}

<button onclick={() => invalidateAll()}>invalidate</button>

What changed?

  • We added a transporter that handles moving our streamed resource from the server to the client
  • Instead of a Promise<T>, we now have a StreamedResource<T>, which has SWR-like behavior and typings
    • status === 'loading' is only true once, the first time the data for this key is fetched (this is reset on hard reloads)
    • revalidating is true every time we refetch the data, except when status is 'loading' (the first time we fetch the data)
    • data is:
      • undefined while status is 'loading', unless initialData (the third argument to createStreamedResource) is provided, in which case it's always T
      • undefined while status is 'error'
      • T while status is 'success'
    • error is:
      • undefined while status is 'success' or 'loading'
      • TError while status is 'error'
  • The StreamedResource does not wipe out its data property on refetches!

Things to be aware of

  • This library expects that there is only ever one copy of a StreamedResource with a given key at the same time -- so don't go creating two resources with identical keys in two places that are both rendered simultaneously. Instead, create the resource in a shared layout -- it'll be inhereted on data and page.data just like it should be!
  • If you want a refetch to re-trigger loading, you should key the resource on something that changes. For example, createStreamedResource(['user', userId], getUser(userId)) will re-trigger when userId changes, but revalidate when it is the same.