Loading packages/fedify/src/federation/handler.ts +23 −23 Original line number Diff line number Diff line Loading @@ -910,7 +910,7 @@ export interface CustomCollectionCallbacks< /** * Parameters for handling a custom collection. * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context, extending {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @since 1.8.0 Loading Loading @@ -1001,7 +1001,7 @@ async function _handleCustomCollection< /** * Handles an ordered collection request. * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context, extending {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @param request The HTTP request. Loading Loading @@ -1067,7 +1067,7 @@ async function _handleOrderedCollection< * The main flow is on `getCollection`, `dispatch`. * * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context. {@link Context} or {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @template TCollection The type of the collection, extending {@link Collection}. Loading Loading @@ -1114,14 +1114,14 @@ class CustomCollectionHandler< /** * Creates a new CustomCollection instance. * @param {string} name The name of the collection. * @param {TParams} values The parameter values for the collection. * @param {TContext} context The request context. * @param {CustomCollectionCallbacks} callbacks The collection callbacks. * @param {TracerProvider} tracerProvider The tracer provider for telemetry. * @param {ConstructorWithTypeId<TCollection>} Collection The Collection constructor. * @param {ConstructorWithTypeId<TCollectionPage>} CollectionPage The CollectionPage constructor. * @param {(item: TItem) => boolean} filterPredicate Optional filter predicate for items. * @param name The name of the collection. * @param values The parameter values for the collection. * @param context The request context. * @param callbacks The collection callbacks. * @param tracerProvider The tracer provider for telemetry. * @param Collection The Collection constructor. * @param CollectionPage The CollectionPage constructor. * @param filterPredicate Optional filter predicate for items. */ constructor( private readonly name: string, Loading Loading @@ -1277,7 +1277,7 @@ class CustomCollectionHandler< /** * Creates a function to wrap the dispatcher so tracing can be applied. * @param params Parameters including cursor and total items. * @returns {(span: Span) => Promise<PageItems<TItem>>} A function that handles the span operation. * @returns A function that handles the span operation. */ spanPages: (params: { totalItems?: number | null; Loading Loading @@ -1305,8 +1305,8 @@ class CustomCollectionHandler< /** * Dispatches the collection request to get items. * @param {string | null} cursor The cursor for pagination, or null for the first page. * @returns {Promise<PageItems<TItem>>} A promise that resolves to the page items. * @param cursor The cursor for pagination, or null for the first page. * @returns A promise that resolves to the page items. */ async dispatch( cursor: string | null = null, Loading @@ -1320,8 +1320,8 @@ class CustomCollectionHandler< /** * Filters the items in the collection. * @param {TItem[]} items The items to filter. * @returns {(Object | Link | URL)[]} The filtered items. * @param items The items to filter. * @returns The filtered items. */ filterItems(items: TItem[]): (Object | Link | URL)[] { return filterCollectionItems(items, this.name, this.filterPredicate); Loading @@ -1329,7 +1329,7 @@ class CustomCollectionHandler< /** * Appends a cursor to the URL if it exists. * @param {string | null | undefined} cursor The cursor to append, or null/undefined. * @param cursor The cursor to append, or null/undefined. * @returns The URL with cursor appended, or null if cursor is null/undefined. */ appendToUrl<Cursor extends string | null | undefined>( Loading @@ -1340,8 +1340,7 @@ class CustomCollectionHandler< /** * Gets the stored collection or collection page. * @returns {Promise<TCollection | TCollectionPage>} A promise that resolves to the collection or collection page. * @returns A promise that resolves to the collection or collection page. */ get collection(): Promise<TCollection | TCollectionPage> { if (this.#collection === null) { Loading @@ -1352,8 +1351,8 @@ class CustomCollectionHandler< /** * Gets the total number of items in the collection. * @returns {Promise<number | null>} A promise that resolves to the total items count, or null if not available. * @returns A promise that resolves to the total items count, * or null if not available. */ get totalItems(): Promise<number | null> { if (this.#totalItems === undefined) { Loading @@ -1376,8 +1375,8 @@ class CustomCollectionHandler< /** * Gets the first cursor for pagination. * @returns {Promise<string | null>} A promise that resolves to the first cursor, or null if not available. * @returns A promise that resolves to the first cursor, * or null if not available. */ get firstCursor(): Promise<string | null> { const cursor = this.callbacks.firstCursor?.(this.context, this.values); Loading @@ -1396,6 +1395,7 @@ class CustomCollectionHandler< TYPE: "activitypub.collection.type", } as const; } /** Type for `CustomCollection.TotalItems`.*/ type TotalItems = number | bigint | null | undefined; Loading Loading
packages/fedify/src/federation/handler.ts +23 −23 Original line number Diff line number Diff line Loading @@ -910,7 +910,7 @@ export interface CustomCollectionCallbacks< /** * Parameters for handling a custom collection. * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context, extending {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @since 1.8.0 Loading Loading @@ -1001,7 +1001,7 @@ async function _handleCustomCollection< /** * Handles an ordered collection request. * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context, extending {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @param request The HTTP request. Loading Loading @@ -1067,7 +1067,7 @@ async function _handleOrderedCollection< * The main flow is on `getCollection`, `dispatch`. * * @template TItem The type of items in the collection. * @template TParams The parameter names of the requested URL. * @template TParam The parameter names of the requested URL. * @template TContext The type of the context. {@link Context} or {@link RequestContext}. * @template TContextData The context data to pass to the `TContext`. * @template TCollection The type of the collection, extending {@link Collection}. Loading Loading @@ -1114,14 +1114,14 @@ class CustomCollectionHandler< /** * Creates a new CustomCollection instance. * @param {string} name The name of the collection. * @param {TParams} values The parameter values for the collection. * @param {TContext} context The request context. * @param {CustomCollectionCallbacks} callbacks The collection callbacks. * @param {TracerProvider} tracerProvider The tracer provider for telemetry. * @param {ConstructorWithTypeId<TCollection>} Collection The Collection constructor. * @param {ConstructorWithTypeId<TCollectionPage>} CollectionPage The CollectionPage constructor. * @param {(item: TItem) => boolean} filterPredicate Optional filter predicate for items. * @param name The name of the collection. * @param values The parameter values for the collection. * @param context The request context. * @param callbacks The collection callbacks. * @param tracerProvider The tracer provider for telemetry. * @param Collection The Collection constructor. * @param CollectionPage The CollectionPage constructor. * @param filterPredicate Optional filter predicate for items. */ constructor( private readonly name: string, Loading Loading @@ -1277,7 +1277,7 @@ class CustomCollectionHandler< /** * Creates a function to wrap the dispatcher so tracing can be applied. * @param params Parameters including cursor and total items. * @returns {(span: Span) => Promise<PageItems<TItem>>} A function that handles the span operation. * @returns A function that handles the span operation. */ spanPages: (params: { totalItems?: number | null; Loading Loading @@ -1305,8 +1305,8 @@ class CustomCollectionHandler< /** * Dispatches the collection request to get items. * @param {string | null} cursor The cursor for pagination, or null for the first page. * @returns {Promise<PageItems<TItem>>} A promise that resolves to the page items. * @param cursor The cursor for pagination, or null for the first page. * @returns A promise that resolves to the page items. */ async dispatch( cursor: string | null = null, Loading @@ -1320,8 +1320,8 @@ class CustomCollectionHandler< /** * Filters the items in the collection. * @param {TItem[]} items The items to filter. * @returns {(Object | Link | URL)[]} The filtered items. * @param items The items to filter. * @returns The filtered items. */ filterItems(items: TItem[]): (Object | Link | URL)[] { return filterCollectionItems(items, this.name, this.filterPredicate); Loading @@ -1329,7 +1329,7 @@ class CustomCollectionHandler< /** * Appends a cursor to the URL if it exists. * @param {string | null | undefined} cursor The cursor to append, or null/undefined. * @param cursor The cursor to append, or null/undefined. * @returns The URL with cursor appended, or null if cursor is null/undefined. */ appendToUrl<Cursor extends string | null | undefined>( Loading @@ -1340,8 +1340,7 @@ class CustomCollectionHandler< /** * Gets the stored collection or collection page. * @returns {Promise<TCollection | TCollectionPage>} A promise that resolves to the collection or collection page. * @returns A promise that resolves to the collection or collection page. */ get collection(): Promise<TCollection | TCollectionPage> { if (this.#collection === null) { Loading @@ -1352,8 +1351,8 @@ class CustomCollectionHandler< /** * Gets the total number of items in the collection. * @returns {Promise<number | null>} A promise that resolves to the total items count, or null if not available. * @returns A promise that resolves to the total items count, * or null if not available. */ get totalItems(): Promise<number | null> { if (this.#totalItems === undefined) { Loading @@ -1376,8 +1375,8 @@ class CustomCollectionHandler< /** * Gets the first cursor for pagination. * @returns {Promise<string | null>} A promise that resolves to the first cursor, or null if not available. * @returns A promise that resolves to the first cursor, * or null if not available. */ get firstCursor(): Promise<string | null> { const cursor = this.callbacks.firstCursor?.(this.context, this.values); Loading @@ -1396,6 +1395,7 @@ class CustomCollectionHandler< TYPE: "activitypub.collection.type", } as const; } /** Type for `CustomCollection.TotalItems`.*/ type TotalItems = number | bigint | null | undefined; Loading