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

@usirin/forge

v0.2.0

Published

A library for creating and managing type-safe entities

Readme

@usirin/forge

Create type-safe, uniquely identifiable entities for your domain model. It's simple and focused on making entity management in TypeScript a breeze.

Overview

While developing domain models, you often need entities that are:

  1. Always uniquely identifiable
  2. Type-safe when referenced
  3. Easy to compose
  4. Simple to validate

Forge makes this easy with a minimal yet powerful API.

Installation

npm install @usirin/forge   # npm
yarn add @usirin/forge      # yarn
pnpm add @usirin/forge      # pnpm
bun add @usirin/forge       # bun

Basic Usage

Creating Entities with Factory

import { factory } from '@usirin/forge'

// Define a post entity
const createPost = factory('post', (title: string, body: string) => ({
  title,
  body
}))

// Create a post - automatically gets unique ID
const post = createPost('Hello World', 'This is my first post')
// Result: { tag: 'post', id: 'post_x7f2k...', title: 'Hello World', body: '...' }

type PostEntity = ReturnType<typeof createPost>

Entity Relationships

import { factory, type Ref } from '@usirin/forge'

const createComment = factory('comment', (postID: Ref<PostEntity>, text: string) => ({
  postID,
  text
}))

// Create a comment for a post
const comment = createComment(post.id, 'Great post!')
// Result: { tag: 'comment', id: 'comment_j9k2l...', postID: 'post_x7f2k...', text: '...' }

// Type system ensures you can't use wrong ID types
createComment('wrong_id', 'text') // Type error!

Schema Validation

Forge integrates with Standard Schema to enable type-safe validation.

Using struct with Validation Libraries

import { struct } from '@usirin/forge'
import { z } from 'zod'
import * as v from 'valibot'

// With Zod
const createUser = struct('user', z.object({
  name: z.string(),
  email: z.string().email(),
  age: z.number().min(18)
}))

// With Valibot
const createUserV = struct('user', v.object({
  name: v.string(),
  age: v.number()
}))

// Create validated entities
const user1 = createUser({ name: 'John', email: '[email protected]', age: 25 })
const user2 = createUserV({ name: 'Alice', age: 30 })

// Invalid data will throw validation errors
try {
  createUser({ name: 'Invalid', email: 'not-an-email', age: 15 })
} catch (error) {
  console.error('Validation failed:', error)
}

Advanced Features

Unique ID Generation & Type Utilities

import { id, type Entity, type Ref } from '@usirin/forge'

// Generate a unique ID
const userID = id('user')  // 'user_9wDHM7drQWZE7Jm3RaxV8'

// Define entity types
type UserEntity = Entity<'user'>  // { tag: 'user', id: 'user_...' }
type PostEntity = Entity<'post'>  // { tag: 'post', id: 'post_...' }

// Type-safe function that only accepts references to specific entities
function getUserPosts(userID: Ref<UserEntity>): PostEntity[] {
  // Implementation...
}

Philosophy

Forge doesn't try to solve every use case, but focuses on making entities uniquely identifiable and type-safe to cover most domain modeling needs:

  • Minimal: Simple API with just a few functions
  • Type-safe: Full TypeScript support for entity relationships
  • Standards-based: Uses Standard Schema for validation
  • Interoperable: Works with various validation libraries
  • Fast: Efficient ID generation and validation

License

MIT