UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

115 lines 3.87 kB
import * as dntShim from "../_dnt.shims.js"; import { type TracerProvider } from "@opentelemetry/api"; import { type DocumentLoader, type GetUserAgentOptions } from "../runtime/docloader.js"; import { type Collection, type Link, Object } from "./vocab.js"; /** * Options for the {@link lookupObject} function. * * @since 0.2.0 */ export interface LookupObjectOptions { /** * The document loader for loading remote JSON-LD documents. */ documentLoader?: DocumentLoader; /** * The context loader for loading remote JSON-LD contexts. * @since 0.8.0 */ contextLoader?: DocumentLoader; /** * The options for making `User-Agent` header. * If a string is given, it is used as the `User-Agent` header value. * If an object is given, it is passed to {@link getUserAgent} to generate * the `User-Agent` header value. * @since 1.3.0 */ userAgent?: GetUserAgentOptions | string; /** * The OpenTelemetry tracer provider. If omitted, the global tracer provider * is used. * @since 1.3.0 */ tracerProvider?: TracerProvider; } /** * Looks up an ActivityStreams object by its URI (including `acct:` URIs) * or a fediverse handle (e.g., `@user@server` or `user@server`). * * @example * ``` typescript * // Look up an actor by its fediverse handle: * await lookupObject("@hongminhee@fosstodon.org"); * // returning a `Person` object. * * // A fediverse handle can omit the leading '@': * await lookupObject("hongminhee@fosstodon.org"); * // returning a `Person` object. * * // A `acct:` URI can be used as well: * await lookupObject("acct:hongminhee@fosstodon.org"); * // returning a `Person` object. * * // Look up an object by its URI: * await lookupObject("https://todon.eu/@hongminhee/112060633798771581"); * // returning a `Note` object. * * // It can be a `URL` object as well: * await lookupObject(new URL("https://todon.eu/@hongminhee/112060633798771581")); * // returning a `Note` object. * ``` * * @param identifier The URI or fediverse handle to look up. * @param options Lookup options. * @returns The object, or `null` if not found. * @since 0.2.0 */ export declare function lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object | null>; /** * Options for the {@link traverseCollection} function. * @since 1.1.0 */ export interface TraverseCollectionOptions { /** * The document loader for loading remote JSON-LD documents. */ documentLoader?: DocumentLoader; /** * The context loader for loading remote JSON-LD contexts. */ contextLoader?: DocumentLoader; /** * Whether to suppress errors when fetching pages. If `true`, * errors will be logged but not thrown. Defaults to `false`. */ suppressError?: boolean; /** * The interval to wait between fetching pages. Zero or negative * values will disable the interval. Disabled by default. * * @default `{ seconds: 0 }` */ interval?: dntShim.Temporal.Duration | dntShim.Temporal.DurationLike; } /** * Traverses a collection, yielding each item in the collection. * If the collection is paginated, it will fetch the next page * automatically. * * @example * ``` typescript * const collection = await lookupObject(collectionUrl); * if (collection instanceof Collection) { * for await (const item of traverseCollection(collection)) { * console.log(item.id?.href); * } * } * ``` * * @param collection The collection to traverse. * @param options Options for traversing the collection. * @returns An async iterable of each item in the collection. * @since 1.1.0 */ export declare function traverseCollection(collection: Collection, options?: TraverseCollectionOptions): AsyncIterable<Object | Link>; //# sourceMappingURL=lookup.d.ts.map