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

@uncaged/json-cas

v0.6.0

Published

Readme

@uncaged/json-cas

Core CAS engine — hashing, schema, store, verify, bootstrap.

Overview

@uncaged/json-cas is the foundation of the json-cas monorepo. It defines content-addressed nodes (CasNode), the Store interface, XXH64-based hashing with deterministic CBOR, JSON Schema registration and validation (including cas_ref links between nodes), bootstrap seeding, and integrity verification.

Other packages build on this layer: json-cas-fs provides persistence, and cli-json-cas exposes store operations on the command line.

Dependencies: ajv, cborg, xxhash-wasm

Installation

bun add @uncaged/json-cas

API

All symbols below are exported from src/index.ts.

Types

/** 13-character uppercase Crockford Base32 (XXH64) */
type Hash = string;

type CasNode<T = unknown> = {
  type: Hash;
  payload: T;
  timestamp: number; // Unix epoch ms
};

type Store = {
  put(typeHash: Hash, payload: unknown): Promise<Hash>;
  get(hash: Hash): CasNode | null;
  has(hash: Hash): boolean;
  listByType(typeHash: Hash): Hash[];
};

type JSONSchema = Record<string, unknown>;

type BootstrapCapableStore = Store & {
  [BOOTSTRAP_STORE](payload: unknown): Promise<Hash>;
};

Hashing

function computeHash(typeHash: Hash, payload: unknown): Promise<Hash>;
function computeSelfHash(payload: unknown): Promise<Hash>;
function cborEncode(value: unknown): Uint8Array;

computeHashXXH64(utf8(typeHash) ++ CBOR(payload)) for normal nodes.

computeSelfHashXXH64(CBOR(payload)) for bootstrap nodes where type === hash.

Bootstrap

const BOOTSTRAP_STORE: unique symbol;

async function bootstrap(store: Store): Promise<Hash>;

Writes the meta-schema seed node (idempotent). Requires a BootstrapCapableStore (e.g. from createMemoryStore()).

Schema

class SchemaValidationError extends Error;

async function putSchema(store: Store, jsonSchema: JSONSchema): Promise<Hash>;
function getSchema(store: Store, typeHash: Hash): JSONSchema | null;
function validate(store: Store, node: CasNode): boolean;
function refs(store: Store, node: CasNode): Hash[];
function walk(
  store: Store,
  rootHash: Hash,
  visitor: (hash: Hash, node: CasNode) => void,
): void;
  • putSchema — stores a schema typed by the meta-schema; returned hash is the typeHash for conforming payloads.
  • refs — collects all format: "cas_ref" values in the payload per schema shape.
  • walk — BFS from rootHash, following cas_ref edges; cycles are visited once.

Store

function createMemoryStore(): BootstrapCapableStore;

In-memory Store with type indexing, suitable for tests and ephemeral use.

Verify

async function verify(hash: Hash, node: CasNode): Promise<boolean>;

Recomputes hash from node and compares to hash (self-referencing vs normal rules).

Example

import {
  bootstrap,
  createMemoryStore,
  putSchema,
  refs,
  validate,
  walk,
} from "@uncaged/json-cas";

const store = createMemoryStore();
const metaHash = await bootstrap(store);

const personType = await putSchema(store, {
  type: "object",
  properties: {
    name: { type: "string" },
    friend: { type: "string", format: "cas_ref" },
  },
  required: ["name"],
  additionalProperties: false,
});

const aliceHash = await store.put(personType, { name: "Alice" });
const bobHash = await store.put(personType, {
  name: "Bob",
  friend: aliceHash,
});

const bob = store.get(bobHash)!;
console.log(validate(store, bob));           // true
console.log(refs(store, bob));               // [aliceHash]
walk(store, bobHash, (h) => console.log(h)); // bobHash, aliceHash

Internal Structure

| File | Purpose | |------|---------| | types.ts | Hash, CasNode, Store | | hash.ts | computeHash, computeSelfHash | | cbor.ts | Deterministic CBOR encoding | | bootstrap-capable.ts | BOOTSTRAP_STORE symbol and capability check | | bootstrap.ts | Meta-schema seed and bootstrap() | | store.ts | createMemoryStore() | | mem-store.ts | Alternate in-memory store (tests only; not exported) | | schema.ts | Schema put/get/validate, refs, walk | | verify.ts | Node integrity verification | | index.ts | Public exports |

Tests live in src/*.test.ts and tests/.