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

@technote-space/vo-entity-ts

v0.18.1

Published

[![npm version](https://badge.fury.io/js/%40technote-space%2Fvo-entity-ts.svg)](https://badge.fury.io/js/%40technote-space%2Fvo-entity-ts) [![CI Status](https://github.com/technote-space/vo-entity-ts/workflows/CI/badge.svg)](https://github.com/technote-sp

Readme

Vo Entity Ts

npm version CI Status codecov CodeFactor License: MIT

Table of Contents

Setup

yarn

  • yarn add @technote-space/vo-entity-ts

npm

  • npm i @technote-space/vo-entity-ts

Author

GitHub (Technote)
Blog

特徴

  • Value Object と Entity の基本クラスを提供
  • 型安全な実装
  • バリデーション機能
  • イミュータブルな値の取り扱い
  • コレクションのサポート

Value Object

Value Object は不変な値オブジェクトを表現するための基本クラスです。以下のような Value Object が提供されています:

  • DateObject: 日付を表現する Value Object
  • Flags: フラグを表現する Value Object
  • Float: 浮動小数点数を表現する Value Object
  • Int: 整数を表現する Value Object
  • ObjectValue: オブジェクトを表現する Value Object
  • Phone: 電話番号を表現する Value Object
  • StringId: 文字列IDを表現する Value Object
  • Text: テキストを表現する Value Object
  • Url: URLを表現する Value Object
  • Email: メールアドレスを表現する Value Object

使用例

import { Text, Email, ObjectValue } from 'vo-entity-ts';

class UserName extends Text {
  protected get symbol() {
    return Symbol();
  }

  protected override getValidationMinLength(): number | undefined {
    return 3;
  }
}

class UserEmail extends Email {
  protected get symbol() {
    return Symbol();
  }
}

// 使用例
const name1 = new UserName('John');
const name2 = new UserName('Jane');
const shortName = new UserName('Jo');

// 比較
name1.equals(name2); // false
name1.equals(new UserName('John')); // true

// 値の取得
name1.value; // 'John'

// バリデーション
name1.getErrors('name'); // undefined
shortName.getErrors('name'); // [{ name: 'name', error: '3文字より長く入力してください' }]

// イミュータブルな値
const name = name1.value;
name = 'New Name'; // エラー: Cannot assign to 'name' because it is a read-only property

その他の使用例

各 Value Object のより詳細な使用例や実装パターンについては、以下のテストファイルを参照してください:

これらのテストファイルには、実際の使用例、エラーハンドリング、エッジケースの処理方法などが含まれています。

Entity

Entity は識別子を持ち、ライフサイクルを通じて同一性を維持するオブジェクトを表現するための基本クラスです。

Entity を実装する際は、_create_reconstruct_update メソッドに対して、実装する Entity の型(例:User)をジェネリクスの型パラメータとして渡すことが重要です:

// 正しい使用法
public static create(...): User {
  return User._create<User>({ ... });
}

public static reconstruct(...): User {
  return User._reconstruct<User>({ ... });
}

public update(...): User {
  return User._update<User>(this, { ... });
}

使用例

import { Entity, Text } from 'vo-entity-ts';

class User extends Entity {
  protected constructor(props: {
    name: UserName;
    email: UserEmail;
    status?: UserStatus;
  }) {
    super(props);
  }

  public static create(name: UserName, email: UserEmail): User {
    return User._create<User>({ name, email });
  }

  public static reconstruct(
    name: UserName,
    email: UserEmail,
    status?: UserStatus,
  ): User {
    return User._reconstruct<User>({ name, email, status });
  }

  public update({ status }: { status?: UserStatus }): User {
    return User._update<User>(this, { status });
  }

  public equals(other: User): boolean {
    return this.get('email').equals(other.get('email'));
  }
}

// 使用例
// 新規作成
const name = new UserName('John Doe');
const email = new UserEmail('[email protected]');
const user = User.create(name, email);

// 再構築(バリデーションをスキップ)
const status = new UserStatus('active');
const reconstructedUser = User.reconstruct(name, email, status);

// 更新
const newStatus = new UserStatus('inactive');
const updatedUser = user.update({ status: newStatus });

// プロパティの取得
user.get('name').value; // 'John Doe'
user.get('email').value; // '[email protected]'
user.get('status')?.value; // undefined

// 比較
user.equals(updatedUser); // true(email が同じため)
user.equals(User.create(new UserName('Jane Doe'), new UserEmail('[email protected]'))); // false

// バリデーションエラー
try {
  User.create(
    new UserName('Jo'),
    new UserEmail('invalid-email')
  );
} catch (error) {
  if (error instanceof ValidationException) {
    console.log(error.errors);
    // {
    //   name: ['3文字より長く入力してください'],
    //   email: ['有効なメールアドレスを指定してください']
    // }
  }
}

コレクション

ValueObject のコレクションを扱うための Collection クラスが提供されています。

import { Collection } from 'vo-entity-ts';

class UserEmails extends Collection<UserEmail> {
  // カスタムのコレクション実装
}

ライセンス

MIT

開発

# 依存関係のインストール
npm install

# テストの実行
npm test

# ビルド
npm run build