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

@shapeshift-labs/frontier-state-cache

v0.1.2

Published

Normalized query-result cache for Frontier packages and application state.

Readme

Frontier State Cache

Normalized query-result cache for Frontier packages and application state.

This package stores query results with normalized entities, query/entity watchers, optimistic layers, persistence helpers, and a small mutation bridge for committing @shapeshift-labs/frontier-mutation plans into cached queries or entities.

Related Packages

Package source repositories:

Install

npm install @shapeshift-labs/frontier @shapeshift-labs/frontier-query @shapeshift-labs/frontier-state-cache

Install mutation too if you use the mutation bridge:

npm install @shapeshift-labs/frontier-mutation

Usage

import { createQueryCache } from '@shapeshift-labs/frontier-state-cache';

const cache = createQueryCache();
const key = ['todos', { status: 'open' }];

cache.writeQuery(key, [
  { __typename: 'Todo', id: 't1', text: 'ship', done: false }
]);

cache.watchQuery(key, (patch) => {
  console.log('query patch', patch);
});

cache.modifyEntity('Todo:t1', (todo) => ({
  ...todo,
  done: true
}));

console.log(cache.getQueryData(key));

API

import {
  createQueryCache,
  createQueryCacheChangeLog,
  createQueryCacheMemoryStorageAdapter,
  mergeOffsetPage,
  mergeUniqueList,
  persistQueryCache,
  summarizeQueryCacheChanges,
  type QueryCache
} from '@shapeshift-labs/frontier-state-cache';

Core exports:

  • createQueryCache(options?) creates an in-memory normalized query cache.
  • cache.writeQuery(key, data, options?) stores a query result and normalizes identifiable entities.
  • cache.getQueryData(key) reads the current denormalized query result.
  • cache.modifyEntity(entity, updater) updates one normalized entity and repairs dependent query snapshots.
  • cache.watchQuery(key, callback) subscribes to compact Frontier patches for one query.
  • cache.watchEntity(entity, callback) subscribes to compact Frontier patches for one entity.
  • cache.invalidateQueries(filter?) and cache.invalidateEntity(entity) mark affected queries stale.
  • cache.optimistic(layerId, callback), resolveOptimistic(layerId), and rollbackOptimistic(layerId) manage optimistic layers.
  • cache.extract() and cache.restore(snapshot) move cache state across storage boundaries.

Entity Identity

By default entities are identified by __typename plus id or _id.

const cache = createQueryCache({
  identify(value) {
    if (value.kind === 'Issue' && typeof value.slug === 'string') {
      return 'Issue:' + value.slug;
    }
    return null;
  }
});

Merge Policies

writeQuery() accepts merge functions for pagination and list repair:

import { mergeOffsetPage, mergeUniqueList } from '@shapeshift-labs/frontier-state-cache';

cache.writeQuery(['todos'], nextPage, {
  merge: (existing, incoming) => mergeOffsetPage(existing, incoming, { offset: 40 })
});

cache.writeQuery(['todos'], incomingRows, {
  merge: (existing, incoming) => mergeUniqueList(existing, incoming, { key: 'id' })
});

Persistence And Change Logs

import {
  createQueryCacheChangeLog,
  createQueryCacheMemoryStorageAdapter,
  persistQueryCache
} from '@shapeshift-labs/frontier-state-cache';

const storage = createQueryCacheMemoryStorageAdapter();
const persistence = persistQueryCache(cache, storage, { debounceMs: 100 });
await persistence.flush();

const log = createQueryCacheChangeLog(cache, { capacity: 256 });
const entries = log.readSince(log.checkpoint);

Mutation Bridge

The mutation bridge is isolated in an optional subpath so normal cache imports do not load mutation planning code:

import { createMutationPlan, select } from '@shapeshift-labs/frontier-mutation';
import { commitCacheQueryMutation } from '@shapeshift-labs/frontier-state-cache/mutation';

const plan = createMutationPlan()
  .forEach(select('/*').where('done', '==', false).keyBy('id'), (rows) => {
    rows.set('done', true);
  });

const result = commitCacheQueryMutation(cache, ['todos', { status: 'open' }], plan);

console.log(result.patch);      // mutation patch
console.log(result.cachePatch); // cache watcher patch

Mutation bridge exports:

  • compileCacheQueryMutation(cache, key, plan, options?) compiles a plan against a cached query without committing it.
  • commitCacheQueryMutation(cache, key, plan, options?) writes the resulting query value back to the cache.
  • commitCacheEntityMutation(cache, entity, plan, options?) compiles and commits a plan against one normalized entity.

Subpath Imports

import { createQueryCache } from '@shapeshift-labs/frontier-state-cache';
import { commitCacheEntityMutation } from '@shapeshift-labs/frontier-state-cache/mutation';

Package Scope

This package owns normalized query-result storage:

  • query-key hashing and partial matching through @shapeshift-labs/frontier-query,
  • entity normalization and denormalized query repair,
  • query/entity patch watchers,
  • optimistic layers,
  • persistence snapshots and bounded change logs,
  • optional mutation bridge helpers.

It does not own selector syntax, core diff/apply, planned diff engines, CRDT documents, sync providers, rich text, or patch codecs.

TypeScript

The package ships ESM JavaScript plus .d.ts declarations for the root export and the ./mutation subpath. The package-local TypeScript source lives in src/ and compiles directly to dist/.

Validation

npm test
npm run fuzz
npm run bench
npm run pack:dry

Benchmarks

Run the package-local benchmark:

npm run bench

Latest local package benchmark on Node v26.1.0, darwin arm64, default rounds:

| Fixture | Median | p95 | | --- | ---: | ---: | | Write normalized query result | 129.02 us | 191.15 us | | Modify normalized entity | 8.25 us | 32.13 us | | Modify entity with query watchers | 8.54 us | 32.83 us | | Offset page merge write | 1.20 ms | 2.29 ms | | Memory persistence flush | 537.38 us | 2.21 ms | | Bounded change-log read | 0.29 us | 0.83 us | | Mutation bridge query commit | 3.11 ms | 10.69 ms | | Mutation bridge entity commit | 9.33 us | 15.08 us |

These are Frontier-only package measurements, not competitor comparisons.

License

MIT. See LICENSE.