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-engine

v0.1.1

Published

Stateful planned diff engine, adaptive profiles, and reusable diff planning for Frontier.

Downloads

739

Readme

Frontier Engine

Stateful planned diff engine, adaptive profiles, history planning, and reusable diff caches for Frontier.

This package sits above @shapeshift-labs/frontier, the small JSON diff/apply core package. It uses @shapeshift-labs/frontier-codec for patch-history byte helpers. Keeping the engine separate keeps core imports small while giving state, history, and CRDT layers a shared planning surface.

Related Packages

Package source repositories:

Install

npm install @shapeshift-labs/frontier @shapeshift-labs/frontier-codec @shapeshift-labs/frontier-engine

Usage

import { applyPatchImmutable } from '@shapeshift-labs/frontier';
import { createDiffEngine } from '@shapeshift-labs/frontier-engine';

const engine = createDiffEngine({
  schema: {
    type: 'array',
    path: ['todos'],
    key: 'id',
    item: {
      type: 'object',
      fields: ['id', 'done', 'title']
    }
  }
});

const before = {
  todos: [{ id: 'a', done: false, title: 'Draft' }]
};
const after = {
  todos: [{ id: 'a', done: true, title: 'Draft' }]
};

const patch = engine.diff(before, after);
const next = applyPatchImmutable(before, patch);

API

import {
  createDiffEngine,
  cloneProfilePlans,
  createEngineProfilePlansSnapshot,
  mergeProfilePlans,
  readProfilePlans,
  type DiffEngine,
  type DiffProfile,
  type EngineOptions,
  type ProfilePlans
} from '@shapeshift-labs/frontier-engine';

createDiffEngine(options?)

Creates a reusable diff engine with optional schema, adaptive learning, history planning, and equality/profile helpers.

const engine = createDiffEngine({
  adaptive: true,
  adaptiveThreshold: 2,
  arrayKey: 'id'
});

const patch = engine.diff(before, after);
const reusable = [];
engine.diffInto(before, after, reusable);

Schema Plans

Schema plans are trusted shape hints for hot JSON structures. They let the engine skip generic discovery and emit compact patches for common record-array and object shapes.

const engine = createDiffEngine({
  schema: {
    type: 'array',
    path: ['rows'],
    key: 'id',
    item: {
      type: 'object',
      fields: ['id', 'score', 'active', 'label']
    }
  }
});

Adaptive Profiles

Adaptive engines can learn a profile from representative before/after pairs and replay that profile later.

const trainer = createDiffEngine({ adaptive: true });
const profile = trainer.train([[before, after]]);

const profiled = createDiffEngine({ profile });
const patch = profiled.diff(before, after);

History Helpers

The engine can plan patch histories, then delegate binary history encoding to @shapeshift-labs/frontier-codec.

const patches = engine.diffHistory(initial, states);
const bytes = engine.encodeHistory(patches);
const final = engine.applyEncodedHistory(initial, bytes);

Profile Plan Helpers

const plans = createEngineProfilePlansSnapshot(undefined, {
  schemaCount: 1,
  adaptivePlan: false,
  historyStrategy: 'auto'
});

const merged = mergeProfilePlans(plans, { codec: { history: 'binary' } });

Subpath Imports

import { createDiffEngine } from '@shapeshift-labs/frontier-engine/engine';
import { mergeProfilePlans } from '@shapeshift-labs/frontier-engine/profile';
import type { DiffEngine } from '@shapeshift-labs/frontier-engine/types';

Package Scope

This package owns:

  • createDiffEngine().
  • Adaptive shape learning.
  • Explicit schema/profile diff planning.
  • Reusable engine caches.
  • Profile plan snapshots shared by state/history/codec/CRDT layers.
  • Engine-level history helpers that delegate byte formats to frontier-codec.

It does not own:

  • Stateless diff/apply primitives. Those stay in @shapeshift-labs/frontier.
  • Patch wire formats. Those stay in @shapeshift-labs/frontier-codec.
  • State subscriptions, routers, or maintained views. Those stay in Frontier state packages.
  • CRDT actors, updates, heads, branches, sync, awareness, rich text, or providers.

TypeScript

The package ships ESM JavaScript plus .d.ts declarations for the root export and public subpaths. The package-local TypeScript source lives in src/ and compiles directly to dist/; it is not copied from the monorepo root build output.

Validation

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

The package test suite covers root and subpath imports, schema diff/apply replay, profile snapshots, history planning, encoded history replay, and the absence of state/CRDT exports. The fuzzer covers schema and adaptive profile round-trips over record-array and object-shaped JSON.

Benchmarks

Run the package-local benchmark:

npm run bench

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

| Fixture | Median | p95 | | --- | ---: | ---: | | Engine schema diff, 1k rows | 17.02 us | 17.53 us | | Engine apply via core patch | 0.58 us | 0.62 us | | Engine equality no-op | 9.08 us | 9.14 us | | Engine history encode/decode/apply | 4.13 us | 4.46 us |

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

License

MIT. See LICENSE.