tcmts.hub

http/
2 definitions
pages/
28 definitions
session/
17 definitions
test/
18 definitions

Apps

App () => Element
The hub (`tcm hub` runs it): what's been released lately, every library, search across them, a page for each library and person, and each library's code, shown by the forge's pages. Its jobs (`ingest`, and `mirror` as releases arrive) run beside it. `tcm dev tcmts.hub.App` serves it while you work on it.

Types

AttestationState type
Where an attestation stands: being checked, its writer's (it matches their signed record), or not.
Cursor type
How far a feed has been read.
HubAttestation type
A review, an advisory or a yank the hub knows of.
HubRelease type
A release the hub knows of: the record announcing it, and what's become of it.
HubServices type
Where a visitor's browser signs in and looks people up, as this hub is set up (`$TCM_ATPROTO_DIRECTORY` for all).
HubStar type
A star the hub knows of.
Library type
A library: an announced package, by its author's DID, its versions (newest first), and who uses it.
LibraryHits type
What a search finds in one library: its newest mirrored version, and its definitions that match, best first, each with where it runs (a term's), whether it's a type's near match (`close`), and whether it reaches outside the codebase.
Person type
Someone the hub knows (they've announced a release, or said something of one): their DID, their handle as their DID document last named it (checked both ways), and their Bluesky profile as their repository signs it, read again daily (`profileAt`).
ReleaseFacts type
What the hub works out about a release once it's mirrored: from its code, not from what anyone says.
ReleaseState type
Where a release stands: being mirrored, mirrored (its author checked), failed (and why), or withdrawn.
Someone type
Someone, as the hub shows them: who they are (Trusted), and their profile's name, bio and picture, if they have them.
Use type
A library a mirrored release holds: by the hashes in its namespace, exactly.
Who type
Someone, as the hub knows them: their DID, and their handle if it checks out.

Data

attestations Table<HubAttestation>
cursors Table<Cursor>
people Table<Person>
releases Table<HubRelease>
stars Table<HubStar>
uses Table<Use>

Jobs

ingest RecurringJob
Read Jetstream every minute, from where it was left, until caught up; then work out again the facts of releases mirrored before they were all kept (renewFacts), and read again the profiles due (renewProfiles).

Server

catchUpFromRelay (take: (e: RawEvent) => Promise<void>) => Promise<number>
Catch up without Jetstream's archive: ask the relay which accounts have records of each collection the hub keeps (`com.atproto.sync.listReposByCollection`), and read each one's from its PDS, as Jetstream would have sent them. Each is given to `take` as a commit event (seq 0: it moves no cursor). An account that can't be read is said, and skipped.
checkAttestation (uri: string) => Promise<void>
Check an attestation against its writer's signed repository (a job, queued as it arrives): only then is it shown as theirs, saying what the signed record says (not what the event did). One that doesn't check out is failed; a PDS that doesn't answer is retried, as a job is.
checkStar (uri: string) => Promise<boolean>
Check a star against its writer's signed repository (a job, or when they've just starred): verified, or gone if their repository doesn't hold it (they took it back). Returns whether it's theirs now. Only a star at its own place counts: `at://<DID>/codes.tcm.star/<its library's key>`, so one person's star of a library is one row.
everyone () => Promise<Map<string, Someone>>
Everyone the hub knows, by DID.
hubCodebase () => Codebase
The hub's own codebase, holding what it mirrors: at hubDir (made if need be).
hubDir () => string
Where the hub's own codebase is: `$TCM_HUB_CODEBASE`, else `.tcm/data/hub`.
hubServices () => Promise<HubServices>
The services a visitor's browser uses, and the hub reads follows from (`$TCM_APPVIEW`, else Bluesky's).
hubShare () => void
Set up the forge's pages to show the hub's codebase, read-only, in the hub's frame: what every page does first. Everyone is a reader (a token no one has, so no one is the maintainer).
jetstreamService () => string
The Jetstream (v2) the hub reads: `$TCM_JETSTREAM`, else Bluesky's.
keepStar (row: HubStar) => Promise<void>
Keep a star's row: the one at its URI replaced, else a new one, in one transaction. Jetstream's event and the visitor's own restar can both be keeping the same star at once, and the URI is unique.
libraries (o?: { yanked?: boolean | undefined; }) => Promise<Library[]>
The libraries the hub shows: releases that mirrored (their authors checked), and ones withdrawn since, by package and author, without the versions their authors yanked (yanksOf). One that failed isn't shown as anyone's, and one whose every version is yanked isn't shown, unless `yanked` (for its own page, and the codebases using it).
librariesOfRemote (remote: Pick<Remote, "branch" | "get">) => Promise<Set<string>>
The libraries a codebase's main branch holds, by `libraryKey`, from its library records (outermost only, as `tcm lib` lists them): each by its author's DID and package where it was added as an announced release, else by its namespace, if the hub has a release of it.
librariesUsed (did: string, codebase?: string | undefined) => Promise<Set<string>>
The libraries someone uses, by `libraryKey`: those the releases they've announced hold (the hub knows them by hash), and those a codebase they named holds (`codebase`, a `tcm serve` URL: its main branch's library records).
matchLibraries (s: Pick<Share, "cache" | "cb">, shown: Library[], q: string, by?: string | undefined) => LibraryHi…
What matches `q` in each of `shown` (libraries mirrored in `s`'s codebase): by name, words in docs, or a type, as `tcm find` does, but each name as its library shows it (`geo.area`, not where the hub mounts it). `by` says which (`name`: names, then docs where no name matches; `docs`: docs alone; `type`); without it, a type if `q` looks like one, names otherwise. Its own definitions only: not what it holds, nor its tests. Each library with what matches in it, best match first; the libraries by their best match, then most used. A type's near matches (more general, or more specific) are `close`; a definition whose code, or what it uses, reaches outside the codebase (or that uses a package that does) `reaches`.
mirror (uri: string) => Promise<void>
Mirror a release (a job, queued as it's announced): check its record against its author's signed repository, then fetch its namespace by hash from its sources (re-hashed as it arrives) into the hub's codebase, mounted read-only at mountFor, and note the libraries it holds (and, if the version after it mirrored first, say that one's changes since it). A record that doesn't check out fails it, and it never shows as that author's; a source that doesn't answer is retried, as a job is.
profileOf (did: string) => Promise<Omit<Someone, "did">>
Someone's Bluesky profile (`app.bsky.actor.profile/self`), as their repository signs it (signedRecord): their display name, bio and picture. Nothing, if they have none.
readJetstream (o?: { idleMs?: number | undefined; mostMs?: number | undefined; }) => Promise<{ events: number; }>
Read Jetstream's `codes.tcm.*` commits from the stored cursor until caught up (nothing new for a few seconds, or at most `mostMs`): each event's rows and the new cursor written in one transaction. With no cursor, it starts from the archive's beginning when there's an API key (`$JETSTREAM_API_KEY`, for Jetstream's archive); without one, it reads every account's records as the relay lists them (catchUpFromRelay), then the live stream from 36 hours back, as far as it reaches. A cursor the live stream no longer reaches (the hub was down for longer) is replayed the same way: from the archive, or the relay.
recheckAttestation (uri: string) => Promise<void>
When Jetstream says a review, advisory or yank was deleted (a job): gone, if its writer's repository no longer holds it; kept, if it does (an event alone removes nothing).
recheckRelease (uri: string) => Promise<void>
Check a release again against its author's repository, when Jetstream says its record changed or went (a job): a hub keeps only what the repository signs, so an event alone changes nothing. A record that's gone withdraws a release the hub checked (its code stays) and drops one it never did; one that's changed is taken as it's signed now (another namespace under its version fails it); one not checked yet is mirrored.
relayService () => string
The relay asked who has records of a collection: `$TCM_RELAY`, else Bluesky's.
releaseFacts (cb: Codebase, rows: NameRow[], before?: { version: string; rows: NameRow[]; } | undefined) => Rele…
A mirrored release's facts: its manifest's description and licence, where its code runs, what it reaches, and how its API changed since `before` (the version before it, mirrored too).
releaseOfNamespace (namespace: string) => Promise<HubRelease | undefined>
The release a namespace is, among the ones shown (a library a release holds, by hash), if the hub has it.
renewFacts () => Promise<number>
Work out again the facts of mirrored releases whose facts are older than what the hub keeps now (no `effects`): each once, against the version they were compared with. How many it did.
renewProfiles (most?: number) => Promise<number>
Read again the profiles of people the hub knows whose profile it read a day ago or more, or never: `most` at a time. One whose repository doesn't answer keeps what it had, until the next day. How many it read.
restar (did: string, author: string, pkg: string) => Promise<{ count: number; starred: boolean; }>
Called by a visitor's browser once it's starred a library, or taken a star back: checked against their repository at once, rather than when Jetstream says so. The library's stars now, and whether theirs is among them. Anyone can call it, so it takes DIDs alone (no star elsewhere can be made to count), and a few calls a minute from each address.
searchLibraries (q: string, by?: string | undefined) => Promise<LibraryHits[]>
Search every library's newest mirrored version: by name, words in docs, or a type (`:(s: Shape) => number`), as `tcm find` does, or as `by` says (matchLibraries).
shownAttestations () => Promise<HubAttestation[]>
What the hub shows of what people say: reviews and advisories checked against their writers' repositories, and yanks only from the release's own author: someone with a release of that namespace the hub checked (`shownRelease`), saying it's theirs.
starCounts () => Promise<Map<string, number>>
Each library's stars, by `libraryKey`.
takeAttestation (e: EventBase & { kind: "commit"; commit: RawCommit<RawRecord>; } & { kind: "commit"; }) => Promise…
A review, advisory or yank Jetstream sent: kept, to be checked against its writer's repository; or, deleted, gone once its repository no longer holds it (`recheckAttestation`).
takeEvent (e: RawEvent) => Promise<void>
One Jetstream event, into the tables: a release record announced (a new row, not shown until it's checked and mirrored), changed or deleted (checked again against its author's repository first, `recheckRelease`: an event alone changes nothing the hub has checked); or a review, advisory, yank or star (its check queued), or one deleted.
takeStar (e: EventBase & { kind: "commit"; commit: RawCommit<RawRecord>; } & { kind: "commit"; }) => Promise…
A star Jetstream sent: kept, to be checked against its writer's repository; or, deleted, gone once its repository no longer holds it (`checkStar`).
usersByNamespace (shown: HubRelease[]) => Promise<Map<string, HubRelease[]>>
The releases holding each namespace as a library of theirs (exactly: by hash), among `shown`.
visitor () => Promise<Trusted | undefined>
Who the page is for: the DID the visitor's browser says it's signed in as. Only what they're shown depends on it (whose releases they follow, which libraries they use); what anyone can write is checked against their repository.
whoIs (who: string) => Promise<Someone | undefined>
Who a page's `@<handle>` (or `@<DID>`) is: someone the hub knows, by the handle they have now.

Shared

CODEBASE_COOKIE "hub_codebase"
The cookie holding the codebase a visitor said they use (a `tcm serve` URL).
COLLECTIONS readonly ["codes.tcm.*"]
The collections the hub reads.
HUB_COLLECTIONS string[]
The records the hub keeps: releases, what people say about them, and stars.
HUB_LIMITS { readonly releasesPerAccount: 1000; readonly definitionsPerRelease: 50000; readonly pagesPerListin…
How much a hub takes from anyone, so no one can make it hold, fetch or remember without end: releases mirrored per account, definitions a release's namespace may name, pages of a listing read (of 100 records each, or 500 accounts), and visitors' follows and codebases remembered.
LIVE_LOOKBACK_MS number
How far back the live stream reaches, where there's no archive to start from (Jetstream keeps 36 hours).
SIGNED_IN_COOKIE "hub_did"
The cookie a visitor's browser sets to their DID once signed in, so pages can show them what's theirs.
addLine (who: { did: string; handle?: string | undefined; }, pkg: string, version: string) => string
The `tcm lib add` line for a library's version, by its author's handle (or DID), called after its package: quoted as a shell needs it, so a line copied from a page runs `tcm` and nothing else.
attestationFields (a: Attestation) => Pick<HubAttestation, "author" | "body" | "createdAt" | "fixedIn" | "kind" | "na…
What an attestation row says of its record: taken from the record as its writer's repository signs it.
cached (key: string, fn: () => Promise<Set<string>>) => Promise<Set<string>>
`fn`'s answer for `key`, kept for five minutes; the least lately used are forgotten past `HUB_LIMITS.rememberedVisitors`.
changeText (findings: Finding[]) => string
How an API changed, said briefly, from its semver findings.
changesHref (w: Who, pkg: string, from: string, to: string) => string
What changed between two versions of a library.
followsOf (did: string) => Promise<Set<string>>
The DIDs someone follows on Bluesky, as the AppView says (`app.bsky.graph.getFollows`), up to a few thousand.
handleOfDid (did: string) => Promise<string>
A visitor's handle, as their DID document says it (for showing who's signed in), or their DID.
hubOpened Map<string, Codebase>
The hub's codebase, by directory, once opened.
latestRelease (versions: HubRelease[], yanks: Map<string, unknown>) => HubRelease
A library's latest version, of its versions (newest first): the newest mirrored one its author didn't yank, else the newest they didn't yank (withdrawn, say), else, every one yanked, the newest mirrored, else the newest.
librariesOfCodebase (cb: Codebase, url: string) => Promise<Set<string>>
The libraries a served codebase holds, by `libraryKey` (`librariesOfRemote`): an http(s) address alone, at a public address, asked with no credentials (`publicRemote`: never a path, or a remote's name). A codebase that can't be read holds none.
libraryHref (w: Who, pkg: string, version?: string | undefined, tab?: string | undefined) => string
A library's page, or one version's (and a tab of it).
libraryKey (r: Pick<HubRelease, "did" | "package">) => string
A library's key: its author's DID and its package.
mountFor (did: string, pkg: string, version: string) => string
Where a release is mounted in the hub's codebase: by its author's DID (a handle can change, a DID can't), its package and its version, each made a name: `plc_ewvi7nxz….geo.v1_3_0`.
ownNames (cb: Codebase, mount: string) => NameRow[]
A mirrored release's own names, as its library page lists them: everything mounted at `mount`, files kept with its code included (its README), but not the libraries it holds, nor their record.
profileFields (record: unknown, pds: string, did: string) => Omit<Someone, "did">
What a Bluesky profile record says, as the hub shows it: its display name and bio (trimmed, and cut short), and its picture, served by its owner's PDS (`com.atproto.sync.getBlob`). What isn't a string, or a blob's CID, isn't taken.
reachesShort (f: Pick<ReleaseFacts, "effects" | "reaches" | "unknown">) => string
What a release reaches outside itself, said in a line, its names in backticks: "reaches nothing outside itself", "only `fetchTiles` reaches the network", "`Pages`, `Stylesheet` and `createRouter` reach the environment, the clock and 2 more, through react" (what they reach is the package's doing). Facts worked out before effects were kept say it as they did.
reachesText (r: { reaches: Map<Effect, string[]>; unknown: string[]; }) => string
Where a release reaches outside itself, said plainly.
recordOf (raw: unknown) => ReleaseRecord | undefined
A record as an event carries it (JSON live, DAG-CBOR from the archive), as a release record if it is one.
releaseFields (r: ReleaseRecord) => Pick<HubRelease, "createdAt" | "entry" | "namespace" | "notes" | "package" | …
What a release row says of its record: taken from the record as its author's repository signs it.
safeLex (raw: Uint8Array<ArrayBufferLike>) => unknown
An archive record's DAG-CBOR, as data (undefined if it isn't any).
said (w: Who) => string
Someone, said: `@handle`, or their DID.
shownRelease (r: HubRelease) => boolean
Whether a release is one the hub shows, and attributes anything by: mirrored (checked against its author's signed record), or withdrawn after it was. A pending or failed one names nobody's code: anyone can announce someone else's namespace hash, and theirs fails.
signedRelease (did: string, rkey: string) => Promise<{ cid: string; record: ReleaseRecord; }>
The release record at `did`/`rkey`, as its author's repository signs it (signedRecord).
someone (p: Person) => Someone
A person as the hub shows them.
visitorCache Map<string, { at: number; value: Set<string>; }>
What's been read, kept a few minutes: follows and codebases change, but not by the second.
whoHref (w: Who) => string
Someone's page.
yanksOf (shown: HubRelease[], said: HubAttestation[]) => Map<string, HubAttestation>
The releases their authors yanked, by URI, each with its yank: one of its namespace, written by the release's own author, of what the hub shows (shownAttestations). Anyone else's yank of it yanks nothing.