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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@palantir/pack.state.core

v0.2.2

Published

PACK State logic and utilities

Readme

@palantir/pack.state.core

Real-time state management system.

Overview

This package provides the core state management infrastructure for PACK, built around the concept of Documents that can be synchronized in real-time across multiple clients.

StateModule via app.state is the main public interface.

Key Concepts

Terminology

TODO: These need another pass for consistent naming, there's a confusing interchange of Schema & Model between document & record layer.

  • Document - An instance of a document, as loaded by id. A document is a collection of Records.
  • DocumentType - The backend-registered metadata describing app-specific archetypes of Documents.
  • DocumentSchema - Describes the Record types in a Document Type. Used internally at runtime for type inspection, validation, and read/writes to underlying document implementation.
    • Model<Data, Schema> - Effectively a Record Type - A runtime type unifying ModelData and ModelSchema.
    • via sdk generators:
      • DocumentModel - The runtime definition of the document type, ie the Models that make up the document.
      • ModelData - The user-friendly type for a record. This is the type that app code uses.
      • ModelSchema - The runtime definition of the record. Generally for internal use only at this stage.
  • Record - An instance of an object stored in the document. Note this is not a typescript Record<K,V>, it is an immutable object corresponding to the defined Model. This is the primary concept that apps use for state management.
  • RecordCollection - All Records are stored in a document internally in their own (per-Model) collection. This means all model types marked as primary in the schema are accessible with a map-like interface.

Reference Types

Reference (or ref) objects provide the main public api for interacting with documents, providing a clean, async API on top of the DocumentSchema/Models.

  • DocumentRef<DocumentSchema> - References to documents with validation utilities
  • RecordCollectionRef<ModelSchema> - References to collections of records
  • RecordRef<ModelSchema> - References to individual records within documents

Note: Refs are created immediately though the underlying data may not be loaded. DocumentService implementations won't load/subscribe to data unless there are subscriptions on the document or collection/records within the document.

Note: All ref objects are stable, deduplicated automatically via weak ref caches. This means they are suitable for use as keys in maps, cache deps in react etc, as long as the application holds a ref it will never receive a duplicate.

Internal Notes

Document Services

DocumentService is an internal service used to implement connections to a backend.

  • DocumentService - Abstract interface for document state management
  • BaseYjsDocumentService - Base implementation using Yjs for real-time collaboration (TODO: This will move out of state-core)
  • createInMemoryDocumentServiceConfig() - Configuration for in-memory document service, useful for testing

Internal Development Notes

  • Use Symbols for meta fields on objects allows for iteration of keys without meta fields.
  • Records should always be treated as having high cardinality. So prefer iterative approach to working with RecordCollections.
  • Use method type interfaces / classes. Eg we do not want to instantiate bound methods for every record.