---
title: "Collection, Tree, Item"
description: "The return types of defineCollection, defineTree, and defineItem."
canonical: "https://www.qino.works/docs/api/types/primitives"
---

# Collection, Tree, Item

> The return types of defineCollection, defineTree, and defineItem.

Use these to type a function that accepts a primitive, or to constrain a generic.

```ts title="@qino/cms"
import type { Collection, Item, Tree } from "@qino/cms";
```

## Collection

```ts title="@qino/cms"
type Collection<
  Schema extends StandardSchemaV1<unknown, Record<string, unknown>>,
  Ext extends ".md" | ".mdx" | ".markdown" | ".json",
  Rels extends Relations<Schema> = object,
  Dir extends `/${string}` = `/${string}`,
  Views extends object = object,
> = {
  getAllSlugs(): Promise<Array<SlugFor<Dir>>>;
  getEntries(options?: { view?: keyof Views }): Promise<Array<Entry>>;
  getEntry(
    slug: SlugFor<Dir>,
    options?: { view?: keyof Views },
  ): Promise<Entry>;
  getPageMarkdown(): Promise<string>;
  getPageMarkdown(
    slug: string,
    options?: { view?: keyof Views },
  ): Promise<string | null>;
  getMarkdownUrl(): string;
  getMarkdownUrl(slug: SlugFor<Dir>): string;
};
```

## Tree

```ts title="@qino/cms"
type Tree<
  Schema,
  Ext,
  Title extends StringKeys<Schema>,
  Rels = object,
  Dir extends `/${string}` = `/${string}`,
  Views extends object = object,
> = {
  getTree(): Promise<Array<TreeNode>>;
  getTree(slug: SlugFor<Dir>): Promise<TreeNode>;
  getFlatTree(): Promise<Array<TreeNode>>;
  getEntries(options?: { view?: keyof Views }): Promise<Array<Entry>>;
  getEntry(
    slug: SlugFor<Dir>,
    options?: { view?: keyof Views },
  ): Promise<Entry>;
  getAncestorNodes(slug: SlugFor<Dir>): Promise<Array<TreeNode>>;
  getNextNode(slug: SlugFor<Dir>): Promise<TreeNode | null>;
  getPreviousNode(slug: SlugFor<Dir>): Promise<TreeNode | null>;
  getPageMarkdown(): Promise<string>;
  getPageMarkdown(slug: string): Promise<string | null>;
  getMarkdownUrl(): string;
  getMarkdownUrl(slug: SlugFor<Dir>): string;
};
```

## Item

```ts title="@qino/cms"
type Item<Schema, Ext, Rels = object, Views extends object = object> = {
  getEntry(options?: { view?: keyof Views }): Promise<Entry>;
  getPageMarkdown(): Promise<string>;
  getMarkdownUrl(): string;
};
```

## Generics

| Parameter | Description                                                             |
| --------- | ----------------------------------------------------------------------- |
| `Schema`  | The Standard Schema validator passed as `schema`                        |
| `Ext`     | The content extension                                                   |
| `Title`   | Tree only. The `titleField` key                                         |
| `Rels`    | The `relations` map                                                     |
| `Dir`     | The `directory` literal. Looked up in `QinoSlugRegistry` for slug types |
| `Views`   | The object returned by the `views` factory                              |

Each type also carries a hidden marker with the definition metadata and the inference data that [Infer](https://www.qino.works/docs/api/types/infer) reads. In practice you rarely write these generics by hand; `typeof postCollection` is the usual spelling.

## Example

```ts title="src/lib/count-entries.ts"
import type { Collection } from "@qino/cms";

async function countEntries<C extends Collection<any, any, any, any, any>>(
  collection: C,
) {
  return (await collection.getAllSlugs()).length;
}
```
