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

@pocket-architect/core

v0.1.36

Published

```typescript // Створює копію властивостей сутності у вигляді простого об'єкта. // Також зберігає початковий стан для відстеження змін (dirty checking). const snapshot = entity.snapshot();

Readme

Entity

Snapshots

// Створює копію властивостей сутності у вигляді простого об'єкта.
// Також зберігає початковий стан для відстеження змін (dirty checking).
const snapshot = entity.snapshot();

entity.isDirty(); // Повертає true, якщо сутність була змінена після створення знімка.
entity.snapshotDiff(); // Повертає об'єкт з відмінностями між поточним станом сутності та знімком. Або null, якщо змін немає.

Events

EventBus

Сутність для керування подіями в системі. В монолітних застосунках зазвичай використовується один глобальний EventBus і його можна описати за допомогою InMemoryEventBus, не потрібно залучати чергу, бо всі обробники працюють в одному процесі.

// Спершу треба описати події, які є в домені. Для цього є клас DomainEvent, який треба наслідувати.
class UserCreatedEvent extends DomainEvent<{ userId: string; username: string }> {
  readonly eventName = 'UserCreatedEvent'; // без цього не буде працювати статична типізація
}
class UserUpdatedEvent extends DomainEvent<{ userId: string; username: string }> {
  readonly eventName = 'UserUpdatedEvent';
}

// Далі створюємо підписника на події, реалізуючи інтерфейс DomainEventSubscriber
class NewUserSubscriber implements DomainEventSubscriber {
  // Підписуємося на події, які нас цікавлять
  subscribedTo() {
    return [UserCreatedEvent, UserUpdatedEvent];
  }
  
  // Реалізуємо логіку обробки подій
  async on(domainEvent: UserCreatedEvent|UserUpdatedEvent) {
    console.log('Event received:', domainEvent);
  }
}

// Далі створюємо EventBus і реєструємо підписника
const eventBus = new InMemoryEventBus();
const subscriber = new NewUserSubscriber();
eventBus.addSubscribers([subscriber]);
const event = new UserCreatedEvent({ userId: '1', username: 'john_doe' });
const event2 = new UserUpdatedEvent({ userId: '1', username: 'john_doe_updated' });
// Публікуємо події
await eventBus.publish([event, event2]);

У поєднанні snapshot та EventBus можна реалізувати відстеження змін в сутностях і публікації відповідних подій.

class UserId extends EntityId<string> {}

interface IUser {
  id: UserId;
  username: string;
}

class User extends Entity<IUser, string, UserId> {
}

class UserCreatedEvent extends DomainEvent<Partial<IUser>> {
  readonly eventName = 'UserCreatedEvent'; // без цього не буде працювати статична типізація
}

class ChangeLoggerSubscriber implements DomainEventSubscriber {
  // Підписуємося на події, які нас цікавлять
  subscribedTo() {
    return [UserCreatedEvent];
  }

  // Реалізуємо логіку обробки подій
  async on(domainEvent: UserCreatedEvent) {
    console.log('Username changed:', domainEvent.username);
  }
}

// Далі створюємо EventBus і реєструємо підписника
const eventBus = new InMemoryEventBus();
const subscriber = new NewUserSubscriber();
eventBus.addSubscribers([subscriber]);

const user = User.create({ id: new UserId('1'), username: 'john_doe' });
// Створюємо знімок початкового стану
user.snapshot();
// Змінюємо ім'я користувача
user.username = 'john_doe_updated';
// Перевіряємо, чи є зміни
if (user.isDirty()) {
  const diff = user.snapshotDiff();
  if (diff) {
    // записуємо подію в чергу (не publish). Бо якщо в циклі може бути багато подій і їх треба назбирати, а потім виконати, тому збираємо через push
    eventBus.push(new UserCreatedEvent(diff));
  }
}
// Публікуємо всі події в черзі
await eventBus.publish();