UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

212 lines (211 loc) • 6.88 kB
import { Temporal } from "@js-temporal/polyfill"; import { URLPattern } from "urlpattern-polyfill"; import { DocumentLoader, GetUserAgentOptions } from "./docloader-Q42SMRIB.js"; import { Collection, Link, Object as Object$1 } from "./vocab-CzEfWQk2.js"; import { TracerProvider } from "@opentelemetry/api"; //#region vocab/lookup.d.ts /** * Options for the {@link lookupObject} function. * * @since 0.2.0 */ 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 */ declare function lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object$1 | null>; /** * Options for the {@link traverseCollection} function. * @since 1.1.0 */ 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?: Temporal.Duration | 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 */ declare function traverseCollection(collection: Collection, options?: TraverseCollectionOptions): AsyncIterable<Object$1 | Link>; //#endregion //#region vocab/constants.d.ts /** * The special public collection for [public addressing]. *Do not mutate this * object.* * * [public addressing]: https://www.w3.org/TR/activitypub/#public-addressing * * @since 0.7.0 */ declare const PUBLIC_COLLECTION: URL; //#endregion //#region vocab/type.d.ts /** * Returns the type URI of the given object. * * @example * ``` typescript * import { getTypeId, Person } from "@fedify/fedify"; * * const obj = new Person({}); * console.log(getTypeId(obj)); * // => new URL("https://www.w3.org/ns/activitystreams#Person") * ``` * * @param object The Activity Vocabulary object. * @returns The type URI of the object, e.g., * `new URL("https://www.w3.org/ns/activitystreams#Person")`. * If the given `object` is `null` or `undefined`, returns `null` or * `undefined`, respectively. * @since 1.3.0 */ declare function getTypeId(object: Object$1 | Link): URL; /** * Returns the type URI of the given object. * * @example * ``` typescript * import { getTypeId, Person } from "@fedify/fedify"; * * const obj = new Person({}); * console.log(getTypeId(obj)); * // => new URL("https://www.w3.org/ns/activitystreams#Person") * ``` * * @param object The Activity Vocabulary object. * @returns The type URI of the object, e.g., * `new URL("https://www.w3.org/ns/activitystreams#Person")`. * If the given `object` is `null` or `undefined`, returns `null` or * `undefined`, respectively. * @since 1.3.0 */ declare function getTypeId(object: Object$1 | Link | undefined): URL | undefined; /** * Returns the type URI of the given object. * * @example * ``` typescript * import { getTypeId, Person } from "@fedify/fedify"; * * const obj = new Person({}); * console.log(getTypeId(obj)); * // => new URL("https://www.w3.org/ns/activitystreams#Person") * ``` * * @param object The Activity Vocabulary object. * @returns The type URI of the object, e.g., * `new URL("https://www.w3.org/ns/activitystreams#Person")`. * If the given `object` is `null` or `undefined`, returns `null` or * `undefined`, respectively. * @since 1.3.0 */ declare function getTypeId(object: Object$1 | Link | null): URL | null; /** * Returns the type URI of the given object. * * @example * ``` typescript * import { getTypeId, Person } from "@fedify/fedify"; * * const obj = new Person({}); * console.log(getTypeId(obj)); * // => new URL("https://www.w3.org/ns/activitystreams#Person") * ``` * * @param object The Activity Vocabulary object. * @returns The type URI of the object, e.g., * `new URL("https://www.w3.org/ns/activitystreams#Person")`. * If the given `object` is `null` or `undefined`, returns `null` or * `undefined`, respectively. * @since 1.3.0 */ declare function getTypeId(object: Object$1 | Link | null | undefined): URL | null | undefined; //#endregion export { LookupObjectOptions, PUBLIC_COLLECTION, TraverseCollectionOptions, getTypeId, lookupObject, traverseCollection };