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

typeorm-auditable

v1.0.4

Published

Auditing for TypeORM

Readme

typeorm-auditable

An audit helper for TypeORM that records audit events any time you create, update, or remove an entity. It wraps a standard TypeORM repository so every persistence operation also writes a companion event row with the change payload and the actor who performed it.

What it gives you

  • Drop-in AuditableRepository that mirrors save and remove with audit logging
  • AuditableEntity base class for event rows (id, aggregate id, type, actor UUID, payload, timestamp)
  • CreateAuditableTable migration helper to create the audit/event table schema

Install

npm install typeorm-auditable
# or
yarn add typeorm-auditable

Quick start

  1. Create an event entity extending AuditableEntity and point it at your audit table name.
// src/entities/UserEvent.ts
import { Entity } from 'typeorm';
import { AuditableEntity } from 'typeorm-auditable';

@Entity('user_events')
export class UserEvent extends AuditableEntity {}
  1. Create the audit table using the migration helper.
// migrations/1680000000000-CreateUserEventsTable.ts
import { CreateAuditableTable } from 'typeorm-auditable';

export class CreateUserEventsTable1680000000000 extends CreateAuditableTable {
  tableName = 'user_events';
}
  1. Wrap your repository with AuditableRepository.
// src/repositories/userRepository.ts
import { DataSource } from 'typeorm';
import { AuditableRepository } from 'typeorm-auditable';
import { User } from '../entities/User';
import { UserEvent } from '../entities/UserEvent';

export const userRepository = (dataSource: DataSource) => {
  const repository = dataSource.getRepository(User);
  return new AuditableRepository(User, UserEvent, { repository });
};
// Or mix the auditable methods into an existing repo instance
export const userRepositoryWithExtend = (dataSource: DataSource) => {
  const repository = dataSource.getRepository(User);
  const auditableRepository = new AuditableRepository(User, UserEvent, { repository });
  return repository.extend(auditableRepository);
};
  1. Save or remove through the wrapper and include the actor_uuid.
const repo = userRepository(AppDataSource);

// create
await repo.save(new User({ given_name: 'Ada' }), { actor_uuid: userUuid });

// update
const user = await repo.save(existingUser, { actor_uuid: userUuid });
user.status = 'disabled';
await repo.save(user, { actor_uuid: userUuid });

// remove
await repo.remove(user, { actor_uuid: userUuid });

Each save writes the entity and then appends an event row with a JSON payload of changed fields (before/after). remove appends a removed event then deletes the record.

API

AuditableRepository

Constructor: (entityTarget, eventTarget, { repository })

  • save(entity | entity[], { actor_uuid }) — persists and logs created or updated with a diff payload
  • remove(entity | entity[], { actor_uuid }) — logs removed then deletes

Notes:

  • Arrays are handled in parallel with Promise.all.
  • Changes for JSON-like columns are compared via JSON.stringify to catch deep equality.

AuditableEntity

Fields: id, aggregate_id, type ('created' | 'updated' | 'removed'), actor_uuid, payload, timestamp.

CreateAuditableTable

  • Extend, set tableName, and add to your migrations. Creates the audit table with the same columns as AuditableEntity.

Development

  • Run tests: npm test
  • Lint: npm run lint

License

MIT