Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
research-tool social-network tools-for-thought atproto
Something went wrong. Try again.
TypeScript
at development
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import { Result, ok, err } from '../../../../shared/core/Result';import { IAtUriResolutionService, AtUriResourceType, AtUriResolutionResult,} from '../../domain/services/IAtUriResolutionService';import { CollectionId } from '../../domain/value-objects/CollectionId';import { InMemoryCollectionRepository } from './InMemoryCollectionRepository';
export class InMemoryAtUriResolutionService implements IAtUriResolutionService { constructor(private collectionRepository: InMemoryCollectionRepository) {}
async resolveAtUri( atUri: string, ): Promise<Result<AtUriResolutionResult | null>> { try { // Get all collections and check if any have a published record with this URI const allCollections = this.collectionRepository.getAllCollections();
for (const collection of allCollections) { if (collection.publishedRecordId?.uri === atUri) { return ok({ type: AtUriResourceType.COLLECTION, id: collection.collectionId, }); } }
return ok(null); } catch (error) { return err(error as Error); } }
async resolveCollectionId( atUri: string, ): Promise<Result<CollectionId | null>> { const result = await this.resolveAtUri(atUri);
if (result.isErr()) { return err(result.error); }
if (!result.value || result.value.type !== AtUriResourceType.COLLECTION) { return ok(null); }
return ok(result.value.id as CollectionId); }}