@hateoas-ts/resource - v1.4.3
    Preparing search index...

    Type Alias Collection<TEntity>

    Collection: Entity<
        {
            page: {
                number: number;
                size: number;
                totalElements: number;
                totalPages: number;
            };
        },
        {
            first: Collection<TEntity>;
            last: Collection<TEntity>;
            next: Collection<TEntity>;
            prev: Collection<TEntity>;
            self: Collection<TEntity>;
        },
    >

    Represents a paginated collection of resources in HAL format.

    Collection is a specialized Entity type for paginated lists. It includes:

    • page: Pagination metadata (size, totalElements, totalPages, number)
    • navigation links: first, prev, self, next, last for page traversal

    The collection items are accessible via state.collection after fetching.

    Type Parameters

    • TEntity extends Entity

      The entity type of items in this collection

    import { Entity, Collection } from '@hateoas-ts/resource';

    type Post = Entity<
    { id: string; title: string },
    { self: Post; author: User }
    >;

    type User = Entity<
    { id: string; name: string },
    { self: User; posts: Collection<Post> }
    >;

    // Fetch a collection
    const user = await client.go<User>('/users/123').get();
    const postsState = await user.follow('posts').get();

    // Access pagination metadata
    console.log(`Page ${postsState.data.page.number} of ${postsState.data.page.totalPages}`);
    console.log(`Total items: ${postsState.data.page.totalElements}`);

    // Iterate collection items
    for (const postState of postsState.collection) {
    console.log(postState.data.title);
    }

    // Navigate to next page
    const nextPage = await postsState.follow('next').get();