03. Sovereign Edge CMS/Collections
Querying Collections & Items
Collections represent dynamic, repeatable content streams like Blog Posts, Team Rosters, Products, and Portfolio Projects with built-in pagination, multi-field filtering, and full-text search.
N+1 PROBLEM SOLVED
20ms
Automated Request Batcher Window
“getItem() calls fired across multiple nested components are coalesced into a single network payload automatically.”
RequestBatcher Engine
GET/content/:projectId/collection/:collectionId
The getCollection() Method
Queries collection records with server-side pagination, structured filters, and sorting:
tsx
| 1 | import { nexus } from "@nexushub/client"; |
| 2 | import type { BlogPost } from "@/types/nexus"; |
| 3 | import { generateDocMetadata } from "@/lib/docs-metadata"; |
| 4 | |
| 5 | // Auto-generated SEO Metadata |
| 6 | export const metadata = generateDocMetadata("/docs/content/fetching-collections"); |
| 7 | |
| 8 | export default async function BlogArchive({ searchParams }: { searchParams: { page?: string, q?: string } }) { |
| 9 | const pageNumber = Number(searchParams.page) || 1; |
| 10 | |
| 11 | // Query collection with filters, search, and sorting |
| 12 | const result = await nexus.content.getCollection<BlogPost>("blog_posts", { |
| 13 | page: pageNumber, |
| 14 | limit: 12, |
| 15 | sort: "published_at", |
| 16 | order: "desc", |
| 17 | search: searchParams.q, |
| 18 | filter: { |
| 19 | category: "Engineering", |
| 20 | is_featured: true, |
| 21 | }, |
| 22 | }); |
| 23 | |
| 24 | return ( |
| 25 | <div> |
| 26 | <p>Showing {result.items.length} of {result.total} posts</p> |
| 27 | <div className="grid grid-cols-3 gap-6"> |
| 28 | {result.items.map((post) => ( |
| 29 | <article key={post.id}> |
| 30 | <h2>{post.title}</h2> |
| 31 | <p>{post.excerpt}</p> |
| 32 | </article> |
| 33 | ))} |
| 34 | </div> |
| 35 | </div> |
| 36 | ); |
| 37 | } |
Query Parameters & Filtering
| Parameter | Type | Requirement | Description |
|---|---|---|---|
| page | number | Optional | The 1-based page index to retrieve. Default: 1 |
| limit | number | Optional | Number of records to return per page (min: 1, max: 100). Default: 10 |
| sort | string | Optional | The field identifier to sort records by. Default: 'createdAt' |
| order | 'asc' | 'desc' | Optional | Sort order direction. Default: 'desc' |
| search | string | Optional | Full-text search query across all string and rich-text fields. |
| filter | Record<string, any> | Optional | Exact or array-inclusive matching criteria (e.g., { status: 'published', tag: ['tech', 'news'] }). |
| include | string[] | Optional | Array of relational Reference field keys to expand and hydrate in-place. |
Request Batching with getItem()
When building modular interfaces (like an e-commerce cart or author avatar list), multiple components may call getItem() simultaneously. The SDK includes a built-in RequestBatcher that merges all calls made within a 20ms microtask window into a single HTTP round-trip:
tsx
| 1 | import { nexus } from "@nexushub/client"; |
| 2 | |
| 3 | // Multiple instances of this component on the same page will NOT trigger N requests |
| 4 | export async function AuthorAvatar({ authorId }: { authorId: string }) { |
| 5 | const author = await nexus.content.getItem("authors", authorId, { |
| 6 | revalidate: 3600, |
| 7 | }); |
| 8 | |
| 9 | return ( |
| 10 | <div className="flex items-center gap-2"> |
| 11 | <img src={author.avatar?.url} className="h-8 w-8 rounded-full" /> |
| 12 | <span>{author.name}</span> |
| 13 | </div> |
| 14 | ); |
| 15 | } |
Full-Text Search Across Collections
Query across multiple collections simultaneously with a single query:
typescript
| 1 | import { nexus } from "@nexushub/client"; |
| 2 | |
| 3 | const { results, total } = await nexus.content.search("artificial intelligence", { |
| 4 | collections: ["blog_posts", "documentation", "products"], |
| 5 | limit: 20, |
| 6 | }); |