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

@crazygiscool/cap

v1.2.2

Published

The Central Archive Protocol core library for lore documentation

Readme

CAP — Central Archive Protocol

Configuration-driven TypeScript library for lore documentation. Wraps MongoDB with Zod validation to standardize irregular, deeply nested lore data across fictional universes.

Install

npm install cap
# peer deps (must install yourself)
npm install mongodb@^6 zod@^3

Quick Start

import { loadSettings, generateDynamicSchema, CAPRepository, ICAPBaseDocument } from "cap";
import { MongoClient, Db } from "mongodb";

// 1. Load universe config
const config = loadSettings("./settings.json");

// 2. Build dynamic validation schema
const schema = generateDynamicSchema(config.entryFormat.customFields ?? []);

// 3. Connect to MongoDB
const client = new MongoClient("mongodb://localhost:27017");
const db = client.db(config.databaseName);

// 4. Define an entry type
interface CharacterEntry extends ICAPBaseDocument {
  sparkId: string;
  firepower: number;
  isOnline: boolean;
}

// 5. Extend the repository
class CharacterRepo extends CAPRepository<CharacterEntry> {
  constructor(db: Db) {
    super(db, "characters");
  }
}

// 6. Use it
const repo = new CharacterRepo(db);

const optimus = await repo.create({
  name: "Optimus Prime",
  description: "Leader of the Autobots",
  continuityId: "g1",
  factions: ["Autobots"],
  sparkId: "SP-2187",
  firepower: 9000,
  isOnline: true,
});

console.log(optimus.id); // auto-generated UUID

const found = await repo.findById(optimus.id);
const updated = await repo.update(optimus.id, { firepower: 9500 });
await repo.delete(optimus.id);

// Validate incoming data at runtime
const parsed = schema.parse({
  name: "Bumblebee",
  description: "Autobot scout",
  continuityId: "animated",
  factions: ["Autobots"],
  sparkId: "SP-0001",
  firepower: 500,
  isOnline: true,
});

API

CAPRepository<T>

Abstract class you extend. T must implement ICAPBaseDocument.

| Method | Returns | Description | |--------|---------|-------------| | create(data) | T & { id: string } | Insert doc with auto-generated UUID + createdAt / updatedAt | | findById(id) | T \| null | Lookup by string id | | findByName(name) | T \| null | Case-insensitive regex match on name | | listAll() | T[] | All documents in the collection | | update(id, data) | T \| null | Partial update, auto-bumps updatedAt. Returns updated doc or null | | delete(id) | boolean | Delete by id. Returns true if a document was removed |

generateDynamicSchema(customFields)

Creates a Zod schema from a settings.json customFields array and merges it with CAPBaseSchema.

const schema = generateDynamicSchema([
  { key: "sparkId", type: "string", label: "Spark Signature" },
  { key: "firepower", type: "number", label: "Firepower Rating" },
]);
// Result: CAPBaseSchema extended with sparkId (z.string()) + firepower (z.number())

Supported field types: "string" | "number" | "boolean" | "date"

loadSettings(path)

Reads a JSON file from disk, validates it against CAPSettingsSchema, and returns a typed SettingsConfig.

const config = loadSettings("./settings.json");
// config.databaseName       → string
// config.entryFormat        → { requiredFields?, customFields? }

Configuration

Create a settings.json at your app root:

{
  "databaseName": "Nova Cronum",
  "entryFormat": {
    "requiredFields": ["name", "description", "continuityId", "factions"],
    "customFields": [
      { "key": "sparkId", "type": "string", "label": "Spark Signature" },
      { "key": "primaryFunction", "type": "string", "label": "Designated Function" },
      { "key": "firepower", "type": "number", "label": "Firepower Rating" }
    ]
  }
}

Build & Test

npm run build          # tsc → dist/
npm test               # vitest run --coverage
npm run test:watch     # vitest (watch mode)

Exports

| Export | Kind | |--------|------| | ICAPBaseDocument | interface | | ILoreVariant<T> | interface | | CAPBaseSchema | Zod schema | | CAPRepository<T> | abstract class | | generateDynamicSchema | function | | loadSettings | function | | CAPSettingsSchema | Zod schema | | CustomFieldConfig | interface | | EntryFormatConfig | interface | | SettingsConfig | interface | | FieldType | type ("string" | "number" | "boolean" | "date") |

Module System

ESM ("type": "module") with NodeNext module resolution. Import sibling files with .js extension.

import { CAPRepository } from "cap";