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

optimistic-reconcile

v0.1.0

Published

Reconcile optimistic entities with canonical server records across HTTP, WebSocket, SSE, and refetch.

Readme

optimistic-reconcile

CI npm license

Reconcile optimistic entities with canonical server records across HTTP, WebSocket, SSE, and refetch—without changing the key your UI renders.

optimistic-reconcile is a framework-neutral TypeScript library for one narrow problem: a client creates a temporary entity, the server assigns its canonical ID, and several transports may deliver the same entity in different orders.

Why this exists

An optimistic create can become two rows when a push event or refetch returns the saved entity before the original request completes. Replacing a temporary ID with a server ID can also remount UI state. Generic optimistic-state helpers usually handle rollback, but not identity across multiple sources.

This library keeps an immutable viewKey while explicitly linking:

client mutation ID  ─────┐
                         ├── stable view key
canonical server ID ─────┘

It never merges records because their content looks similar. Reconciliation requires a mutation ID echoed by the server, an acknowledgement that maps the mutation to a canonical ID, or an already-known canonical ID.

Install

npm install optimistic-reconcile

Node.js 20 or newer is supported. The package is ESM-only and has no runtime dependencies.

Quick start

import { createReconciler } from "optimistic-reconcile";

type Message = {
  id?: string;
  clientMutationId?: string;
  text: string;
  delivered?: boolean;
};

const messages = createReconciler<Message>({
  getId: (message) => message.id,
  getMutationId: (message) => message.clientMutationId,
  merge: (current, incoming) => ({ ...current, ...incoming }),
});

const mutationId = crypto.randomUUID();
const pending = messages.insertOptimistic(
  { clientMutationId: mutationId, text: "Hello" },
  { mutationId },
);

// A WebSocket or SSE event may arrive first.
messages.observe({
  id: "message-42",
  clientMutationId: mutationId,
  text: "Hello",
  delivered: true,
});

// A late HTTP response is idempotent.
messages.acknowledge(mutationId, { canonicalId: "message-42" });

messages.getSnapshot(); // one entity, not two
messages.canonicalIdFor(mutationId); // "message-42"
pending.viewKey; // unchanged for the entity's UI lifetime

If the server cannot echo clientMutationId, acknowledge the explicit mapping:

messages.acknowledge(mutationId, {
  canonicalId: response.id,
  entity: response,
});

Then later observe() calls with that canonical ID update the same entry.

Lifecycle

| Status | Meaning | | -------------- | ------------------------------------------------------------------------ | | pending | Optimistic entity exists locally. | | acknowledged | The mutation has a canonical ID, but no observed sync event has arrived. | | synced | A canonical entity was observed by any transport. | | failed | An unsettled mutation was rejected. |

A late failure never downgrades an entity that was already observed as synced. Call remove(viewKey) when an entry leaves your cache so its identity mappings can be released.

Integration

getSnapshot() and subscribe() follow the external-store shape used by UI frameworks. For React, for example:

const entities = useSyncExternalStore(
  messages.subscribe,
  messages.getSnapshot,
  messages.getSnapshot,
);

The library does not send requests, own a cache, retry mutations, persist data, or guess identity. Those remain the responsibility of your application or data library.

Documentation

Contributing

See CONTRIBUTING.md. Bug reports and small, focused pull requests are welcome.

License

MIT