20 lines
498 B
TypeScript
20 lines
498 B
TypeScript
export class UserId {
|
|
private constructor(public readonly value: bigint) {}
|
|
|
|
static create(value: bigint | string | number): UserId {
|
|
const bigIntValue = typeof value === 'bigint' ? value : BigInt(value);
|
|
if (bigIntValue <= 0n) {
|
|
throw new Error('用户ID必须大于0');
|
|
}
|
|
return new UserId(bigIntValue);
|
|
}
|
|
|
|
equals(other: UserId): boolean {
|
|
return this.value === other.value;
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value.toString();
|
|
}
|
|
}
|