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

@retreejs/query

v0.8.0

Published

Backend-agnostic async query nodes for Retree reactive state.

Readme

Retree Query

@retreejs/query is the backend-agnostic async-query layer for Retree. It provides QueryNode, a ReactiveNode that subscribes to any async source and writes emitted values into Retree state with a full status machine (pending / success / error / skipped), deep-compared argument lifecycle, observation-driven subscription cleanup, optimistic updates with generation-tracked rollback, and identity-preserving reconciliation.

@retreejs/convex builds its ConvexQueryNode and ConvexPaginatedQueryNode on this package. Use @retreejs/query directly when you want the same machinery over your own backend.

How to install

npm i @retreejs/core @retreejs/query

How to use

Drive a QueryNode from any backend by implementing IQuerySubscriptionSource:

import { Retree } from "@retreejs/core";
import { QueryNode, IQuerySubscriptionSource } from "@retreejs/query";

const source: IQuerySubscriptionSource<{ room: string }, string[]> = {
    subscribe(args, onValue, onError) {
        const socket = openRoomSocket(args.room, onValue, onError);
        return {
            unsubscribe: () => socket.close(),
            getCurrentValue: () => socket.cachedMessages,
        };
    },
};

const messages = Retree.root(
    new QueryNode(source, { args: { room: "general" }, initialState: [] })
);

Retree.on(messages, "nodeChanged", (next) => {
    console.log(next.result.status, next.state);
});

The subscription opens when the node gains its first Retree observer and closes when it loses its last one. updateArgs(nextArgs) resubscribes only when the args actually changed (deep comparison); pass "skip" to disable the query. After result.status === "error", call retry(). Construct the node with keepPreviousData: true to keep the previous state visible (with result.isStale set) while a subscription opened by updateArgs loads, instead of resetting to pending.

Fetch adapter

For plain async functions (REST endpoints, RPC calls), fetchQueryNode runs a one-shot or polled fetch through the same node:

import { fetchQueryNode } from "@retreejs/query";

const weather = Retree.root(
    fetchQueryNode((args: { city: string }) => fetchWeather(args.city), {
        args: { city: "Seattle" },
        refetchInterval: 60_000,
    })
);

Optimistic updates

optimisticUpdate mutates the current state immediately and, when given a mutation promise, rolls back to the latest clean server baseline if the mutation rejects — overlapping mutations are generation-tracked so an older confirmation or failure never clobbers newer local edits:

node.optimisticUpdate({
    ctx: { promise: saveTask(taskId) },
    apply(tasks) {
        const task = tasks.find((item) => item.id === taskId);
        if (task) task.isCompleted = true;
    },
});

Reconciliation

Pass reconcile to keep item identity stable across emissions so useNode(item) rows do not re-render when unrelated rows change:

import { reconcileArrayById } from "@retreejs/query";

const node = fetchQueryNode(listTasks, {
    reconcile: reconcileArrayById("id"),
});

See the Async queries guide for the full documentation, including custom reconcilers and the protected hooks for non-plain state shapes.

Licensing & Copyright

Copyright (c) Ryan Bliss. All rights reserved. Licensed under MIT license.