2024-08-06 14:18:47 +02:00
export const metadata = {
title: 'Collection',
description: 'Definition of the Collection structure',
}
# Collection
Collections are a way to represent paginated groups of entities. They are used everywhere lists of entities can be found, such as a user's outbox. {{ className: 'lead' }}
Pages should be limited to a reasonable number of entities, such as 20 or 80.
2024-08-06 14:22:17 +02:00
<Note>
As Collections are independent and not part of a larger entity (like [ContentFormat](/structures/content-format)), they should have a valid [Signature](/signatures).
</Note>
2024-08-06 14:18:47 +02:00
## Entity Definition
<Row>
<Col>
<Properties>
2024-08-17 14:48:43 +02:00
<Property name="author" type="URI | null" required={true} typeLink="/types#uri">
2024-08-17 22:16:59 +02:00
Author of the collection. Usually the user who owns the collection. [Can be set to `null` to represent the instance](/entities/instance-metadata#the-null-author).
2024-08-06 14:18:47 +02:00
</Property>
<Property name="first" type="URI" required={true} typeLink="/types#uri">
URI to the first page of the collection. Query parameters are allowed.
</Property>
<Property name="last" type="URI" required={true} typeLink="/types#uri">
URI to the last page of the collection. Query parameters are allowed.
If the collection only has one page, this should be the same as `first`.
</Property>
2024-08-06 14:25:22 +02:00
<Property name="total" type="number" required={true} numberType="u64">
2024-08-06 14:18:47 +02:00
Total number of entities in the collection, across all pages.
</Property>
<Property name="next" type="URI" required={false} typeLink="/types#uri">
URI to the next page of the collection. Query parameters are allowed.
If there is no next page, this should be `null`.
</Property>
2024-08-23 08:52:03 +02:00
<Property name="previous" type="URI" required={false} typeLink="/types#uri">
2024-08-06 14:18:47 +02:00
URI to the previous page of the collection. Query parameters are allowed.
2024-08-06 14:22:17 +02:00
2024-08-06 14:18:47 +02:00
If there is no previous page, this should be `null`.
</Property>
<Property name="items" type="Entity[]" required={true}>
Collection contents. Must be an array of entities.
</Property>
</Properties>
</Col>
<Col sticky>
```jsonc {{ 'title': 'Example Collection' }}
{
2024-08-13 16:47:37 +02:00
"author": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771",
"first": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/outbox?page=1",
"last": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/outbox?page=3",
2024-08-06 14:18:47 +02:00
"total": 46,
2024-08-13 16:47:37 +02:00
"next": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/outbox?page=2",
2024-08-23 08:52:03 +02:00
"previous": null,
2024-08-06 14:18:47 +02:00
"items": [
{
"id": "456df8ed-daf1-4062-abab-491071c7b8dd",
"type": "Note",
2024-08-13 16:47:37 +02:00
"uri": "https://versia.social/notes/456df8ed-daf1-4062-abab-491071c7b8dd",
2024-08-06 14:18:47 +02:00
"created_at": "2024-04-09T01:38:51.743Z",
2024-11-03 12:43:27 +01:00
"collections": {
"replies": "https://versia.social/notes/456df8ed-daf1-4062-abab-491071c7b8dd/replies",
"quotes": "https://versia.social/notes/456df8ed-daf1-4062-abab-491071c7b8dd/quotes"
},
2024-08-06 14:18:47 +02:00
"content": {
"text/plain": {
"content": "Hello, world!"
}
}
}
]
}
```
2024-11-03 12:19:21 +01:00
</Col>
</Row>
## URI Collection
URI Collections are identical to regular collections, but they contain only URIs instead of full entities. They are useful for cases when remote entities need to be included in a collection, as those are typically not stored in implementation databases. {{ className: 'lead' }}
<Row>
<Col>
<Properties>
<Property name="author" type="URI | null" required={true} typeLink="/types#uri">
Author of the collection. Usually the user who owns the collection. [Can be set to `null` to represent the instance](/entities/instance-metadata#the-null-author).
</Property>
<Property name="first" type="URI" required={true} typeLink="/types#uri">
URI to the first page of the collection. Query parameters are allowed.
</Property>
<Property name="last" type="URI" required={true} typeLink="/types#uri">
URI to the last page of the collection. Query parameters are allowed.
If the collection only has one page, this should be the same as `first`.
</Property>
<Property name="total" type="number" required={true} numberType="u64">
Total number of entities in the collection, across all pages.
</Property>
<Property name="next" type="URI" required={false} typeLink="/types#uri">
URI to the next page of the collection. Query parameters are allowed.
If there is no next page, this should be `null`.
</Property>
<Property name="previous" type="URI" required={false} typeLink="/types#uri">
URI to the previous page of the collection. Query parameters are allowed.
If there is no previous page, this should be `null`.
</Property>
<Property name="items" type="URI[]" required={true}>
Collection contents. Must be an array of URIs.
</Property>
</Properties>
</Col>
<Col sticky>
```jsonc {{ 'title': 'Example URI Collection' }}
{
"author": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771",
"first": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/followers?page=1",
"last": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/followers?page=3",
"total": 46,
"next": "https://versia.social/users/018ec082-0ae1-761c-b2c5-22275a611771/followers?page=2",
"previous": null,
"items": [
"https://versia.social/users/f8b0d4b4-d354-4798-bbc5-c2ba8acabfe3",
"https://social.bob.com/u/2B27E62snga763"
]
}
```
2024-08-06 14:18:47 +02:00
</Col>
</Row>