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

@happyvertical/smrt-web

v0.40.63

Published

SMRT browser client data runtime: typed collection factory wrapping the client-data engine over generated REST clients

Downloads

16,855

Readme

@happyvertical/smrt-web

Framework-agnostic browser data runtime for generated s-m-r-t REST collections. It turns manifest-generated collection definitions into cached, reactive, optimistic client collections while keeping the underlying data engine behind a s-m-r-t-owned public contract.

Use it for browser-side collection state, shared request deduplication, offline writes, persisted read caches, and live invalidation. Svelte bindings live in @happyvertical/smrt-svelte/web.

Installation

pnpm add @happyvertical/smrt-web

Quick start

s-m-r-t's Vite plugin emits collection definitions through the @happyvertical/smrt-virt-web virtual module:

import {
  createSmrtCollection,
  createSmrtWebClient,
} from '@happyvertical/smrt-web';
import { getCollectionDefinition } from '@happyvertical/smrt-virt-web';

const client = createSmrtWebClient();
const products = createSmrtCollection(
  getCollectionDefinition('products'),
  { basePath: '/api/v1', client },
);

await products.preload();
console.log(products.toArray);

const transaction = products.insert({
  id: crypto.randomUUID(),
  name: 'New product',
});
await transaction.isPersisted.promise;

Pass the same client to related collections for shared cache identity, in-flight request deduplication, and relationship-derived invalidation.

Data behavior

  • Reads are stale-while-revalidate; staleTimeMs defaults to 30 seconds.
  • Concurrent identical reads coalesce into one network request.
  • Inserts are optimistic and roll back if persistence fails.
  • initialData seeds SSR-hydrated rows without a duplicate first-render fetch.
  • Public rows are plain DTOs; data-engine types and virtual fields do not cross the package boundary.

Optional capabilities

Capabilities are opt-in per collection and run through a stable lifecycle seam. A collection without them preserves the basic runtime behavior.

Durable offline writes

import { offlineOutbox } from '@happyvertical/smrt-web';

const products = createSmrtCollection(definition, {
  capabilities: [
    offlineOutbox({
      object: definition,
      namespace: {
        apiBase: '/api',
        tenantId,
        identityId: userId,
        manifestHash,
      },
      syncApplyBasePath: '/api',
    }),
  ],
});

The IndexedDB outbox replays FIFO through the generated sync-apply contract. Client UUIDs and idempotent strict inserts reconcile the optimistic row instead of creating a second server identity. Web Locks elect one replay leader across tabs when supported.

Persisted read cache

persistCollection() warm-starts from an IndexedDB snapshot, then revalidates in the background. Its namespace includes API, tenant, identity, and manifest hash, so user switches and contract changes cannot hydrate another scope's rows. Sensitive collections should omit this capability.

Live invalidation

Create one app-wide createSmrtWebEventSubscriber() and register liveInvalidation({ subscriber, tableName }) on each collection. It consumes named _events SSE frames and permanently downgrades to _changes polling when SSE is unavailable or fatally closed. Authorization and tenancy stay on the generated server read path; signals contain no row payload.

Update awareness

createUpdateState() combines bundle-update and manifest-contract signals. The Svelte adapter useUpdateAvailable connects it to SvelteKit's update store.

Engine boundary

The current implementation uses TanStack DB internally, but no @tanstack/* type may appear in the public API or generated declarations. Applications must depend on SmrtWebCollection and SmrtWebClient, which keeps the engine replaceable and prevents Svelte-only exports from entering the framework-neutral core.

Public API groups

| Group | Main exports | | --- | --- | | Collections | createSmrtCollection, createSmrtWebClient, newLocalId | | HTTP | createDefinitionFetchers, unwrapListResult, unwrapItemResult | | Offline | offlineOutbox, getOutboxHandle | | Persistence | persistCollection, wipeDurableStore | | Live updates | createSmrtWebEventSubscriber, liveInvalidation | | Version awareness | createUpdateState | | WebMCP | registerWebMcpTools |

Development

pnpm --filter @happyvertical/smrt-web test
pnpm --filter @happyvertical/smrt-web typecheck
pnpm --filter @happyvertical/smrt-web build

The build includes a generated-declaration scan that rejects leaked engine types. See AGENTS.md for cache, outbox, SSE, persistence, and engine-boundary invariants.