import { type LinkResolver, type PartPointer, type RenderBlock } from '@estiva-app/protocol'; import type { QueryFn } from './projection.js'; /** What one link names: an address or a message's event id, and the block when it links to one. */ export interface LinkAnswer { value: string | null; block?: PartPointer; } /** The comment a body is written in: its file and the message it replies to, which its tags never repeat as a mention. */ export interface OwnPlace { /** The file the comment is on, `kind:pubkey:d`: its `A`, never also an `a` for a link to it. */ file?: string; /** The event id it replies to: its `e`, never also a `q`. */ parent?: string; } export interface LinkReaderOptions { /** A read as the viewer. Throws when the relay could not be asked. */ query: QueryFn; /** * The published manifests, `kind:31990` (§7.2). Omitted: one read of every * manifest through `query`, kept for the reader's life and forgotten when it * fails. An app that already holds them passes its own. */ manifests?: () => Promise; /** How many times a failed read is said as a change, after 5, 10, 20… seconds. Default 3; 0 says none. */ retries?: number; } export interface LinkReader { /** What one link names; rejects when the relay could not be asked (and the next ask tries again). */ answerOf(url: string): Promise; /** * Ask what each of these links names; settles when every answer is in, and * rejects when a read failed (it left no answer), so a `LinkChips` forgets * those links and asks again. */ ask(urls: readonly string[]): Promise; /** What a link names, from what has come back: undefined until it has, and for nothing. A `LinkResolver`. */ known: LinkResolver; /** The file and block a link to one block names, from what has come back. */ knownBlock(url: string): PartPointer | undefined; /** Whether a link's answer has come back, naming something or nothing. */ answered(url: string): boolean; /** Called each time an answer comes back, or a failed one may be asked again. Returns the unsubscribe. */ changed(listener: () => void): () => void; /** How many times {@link changed} has fired: a snapshot for `useSyncExternalStore`. */ version(): number; /** * The `a`, `q` and `part` tags a body earns ({@link linkTagsOf}), asking * first what its links name and waiting at most `waitMs` (default 5 s): a * link not answered by then earns nothing, and the body keeps it. */ tagsFor(blocks: readonly RenderBlock[], own: OwnPlace, options?: { waitMs?: number; edit?: boolean; inOrder?: readonly string[]; }): Promise; /** {@link writtenOpenerOf} against the hosts the manifests read so far declare. */ opener(url: string | undefined, opens: string | undefined, origin: string): string | undefined; /** Every host an app declares its paths on, as the manifests read so far said. */ declaredOrigins(): ReadonlySet; } /** Wait for `work`, but no longer than `ms`; never rejects. */ export declare function within(work: Promise, ms: number): Promise; /** How many links one body asks about, the first ones — as `LinkChips`' `limit`: each answer can cost a relay query. */ export declare const MAX_LINKS_ASKED = 24; /** One link reader for an app: its relay reads, and the manifests it holds. */ export declare function linkReader(options: LinkReaderOptions): LinkReader; /** * Every link a body names something by, in the order it names them: the URLs * {@link valuesIn} asks a `LinkResolver` about — bare, or a link on words' * target, and none in code. What a sender asks about before it tags. */ export declare function linksIn(blocks: readonly RenderBlock[]): string[]; /** * The tags a message's body earns for what it names (§13.1, §13.6.1): an `a` * per address and a `q` per message, by a `nostr:` reference or an app link * `resolve` answers, in the order the body first names them; then one `part` * per file a link to one of its blocks names, the first link's, when * `blockOf` is given. The comment's own file earns neither an `a` nor a part * (it is the `A`), and the message it replies to no `q` (it is the `e`). * * A send and an edit carry the same `a` and `q` set: an edit says what the * message links now. An edit carries no `part` (pass no `blockOf`), and a * person is never here: `p` and `urgent` stay as the send wrote them. * * A file whose type the relay keeps in order (`inOrder`) is named by its id * too: an `o` after its `a`, and its `part` by the id (§6.4, §13.6.1). An * edit carries the `o` as a send does (§6.8). * * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-says-what-the-message-links-now.md * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-named-by-its-id-in-a-capital-and-small-tag.md */ export declare function linkTagsOf(blocks: readonly RenderBlock[], own: OwnPlace, resolve: LinkResolver, blockOf?: (url: string) => PartPointer | undefined, inOrder?: readonly string[]): string[][]; /** * Where a card or chip written as a URL opens: the address as written, in the * app it names (§7.7, LTX-6), so `leaf.estiva.app/issue/…` opens Leaf, not * Ship. Undefined for anything but https, and for a host that is neither this * app's (`origin`), the one its file opens on (`opens`), nor one an app * declares: a card that draws one file never opens a site no app serves from * (WBM-11 security review). The same rule in every app. * * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-files-path-is-the-same-on-every-apps-host.md */ export declare function writtenOpenerOf(url: string | undefined, opens: string | undefined, origin: string, declared: ReadonlySet): string | undefined; //# sourceMappingURL=links.d.ts.map