rwadurian/backend/services/presence-service/src/domain/value-objects/install-id.vo.ts

38 lines
973 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { v4 as uuidv4, validate as uuidValidate } from 'uuid';
import { DomainException } from '../../shared/exceptions/domain.exception';
export class InstallId {
private readonly _value: string;
private constructor(value: string) {
this._value = value;
}
get value(): string {
return this._value;
}
static generate(): InstallId {
return new InstallId(uuidv4());
}
static fromString(value: string): InstallId {
if (!value || value.trim() === '') {
throw new DomainException('InstallId cannot be empty');
}
// 允许非UUID格式但需要有基本长度
if (value.length < 8 || value.length > 128) {
throw new DomainException('InstallId length must be between 8 and 128 characters');
}
return new InstallId(value.trim());
}
equals(other: InstallId): boolean {
return this._value === other._value;
}
toString(): string {
return this._value;
}
}