32 lines
627 B
TypeScript
32 lines
627 B
TypeScript
import { z } from "zod";
|
|
|
|
const TrackIdSchema = z.string().uuid("TrackId must be a valid UUID");
|
|
|
|
export class TrackId {
|
|
private readonly _value: string;
|
|
|
|
private constructor(value: string) {
|
|
this._value = value;
|
|
}
|
|
|
|
static create(value: string): TrackId {
|
|
const validated = TrackIdSchema.parse(value);
|
|
return new TrackId(validated);
|
|
}
|
|
|
|
static fromString(value: string): TrackId {
|
|
return new TrackId(value);
|
|
}
|
|
|
|
get value(): string {
|
|
return this._value;
|
|
}
|
|
|
|
equals(other: TrackId): boolean {
|
|
return this._value === other._value;
|
|
}
|
|
|
|
toString(): string {
|
|
return this._value;
|
|
}
|
|
} |