Skip to main content

Interface: IRepository

Defined in: src/types/interfaces/repository.interface.ts:130

Repository interface for fetching records from user PDSes.

Remarks

This interface is read-only; Chive does not write to user PDSes.

Implementation uses AT Protocol endpoints: com.atproto.repo.getRecord for single records, com.atproto.repo.listRecords for collections, and com.atproto.sync.getBlob for blob data. All fetches go directly to the user's PDS via DID resolution.

Methods

getBlob()

getBlob(did, cid): Promise<ReadableStream<Uint8Array>>

Defined in: src/types/interfaces/repository.interface.ts:219

Fetches a blob from a user's PDS.

Parameters

did

DID

Repository DID

cid

CID

Blob CID

Returns

Promise<ReadableStream<Uint8Array>>

Blob data as readable stream

Remarks

This method fetches blobs for proxying only; Chive does not store blob data. The stream is piped directly to the client. Use this for proxying PDF downloads, serving images via CDN, or streaming large files.

Example

const pdfStream = await repository.getBlob(
toDID('did:plc:abc123')!,
toCID('bafyreib2rxk...')!
);

// Pipe to response
return new Response(pdfStream, {
headers: { 'Content-Type': 'application/pdf' }
});

getRecord()

getRecord<T>(uri, options?): Promise<null | RepositoryRecord<T>>

Defined in: src/types/interfaces/repository.interface.ts:156

Fetches a single record by AT URI.

Type Parameters

T

Record value type

Parameters

uri

AtUri

AT URI of the record

options?

GetRecordOptions

Fetch options (CID for specific version)

Returns

Promise<null | RepositoryRecord<T>>

Record if found, null otherwise

Remarks

This method fetches the record from the user's PDS. If the record doesn't exist or the PDS is unreachable, returns null.

Example

const record = await repository.getRecord<PreprintRecord>(
toAtUri('at://did:plc:abc123/pub.chive.preprint.submission/xyz789')!
);

if (record) {
console.log('Title:', record.value.title);
}

listRecords()

listRecords<T>(did, collection, options?): AsyncIterable<RepositoryRecord<T>>

Defined in: src/types/interfaces/repository.interface.ts:186

Lists records from a collection in a user's repository.

Type Parameters

T

Record value type

Parameters

did

DID

Repository DID

collection

NSID

Collection NSID

options?

ListRecordsOptions

List options (limit, cursor, reverse)

Returns

AsyncIterable<RepositoryRecord<T>>

Async iterable of records

Remarks

Returns an async iterable for memory-efficient streaming of large collections. Use for await...of to iterate.

Example

const preprints = repository.listRecords<PreprintRecord>(
toDID('did:plc:abc123')!,
toNSID('pub.chive.preprint.submission')!,
{ limit: 10 }
);

for await (const record of preprints) {
console.log('Preprint:', record.value.title);
}