A social knowledge tool for researchers built on ATProto
at development 40 lines 889 B view raw
1import { ValueObject } from 'src/shared/domain/ValueObject'; 2import { ATUri } from './ATUri'; 3 4interface StrongRefProps { 5 uri: string; 6 cid: string; 7} 8export class StrongRef extends ValueObject<StrongRefProps> { 9 readonly $type = 'com.atproto.repo.strongRef'; 10 11 private readonly _atUri: ATUri; 12 13 get atUri(): ATUri { 14 return this._atUri; 15 } 16 17 get cid(): string { 18 return this.props.cid; 19 } 20 21 getValue(): StrongRefProps { 22 return this.props; 23 } 24 25 constructor(props: StrongRefProps) { 26 super(props); 27 const atUriResult = ATUri.create(props.uri); 28 if (atUriResult.isErr()) { 29 throw new Error(`Invalid AT URI: ${atUriResult.error.message}`); 30 } 31 const atUri = atUriResult.value; 32 this._atUri = atUri; 33 } 34 35 equals(other: StrongRef): boolean { 36 return ( 37 this.props.cid === other.props.cid && this.props.uri === other.props.uri 38 ); 39 } 40}