2024-07-23 00:23:42 +02:00
export const metadata = {
title: 'Entities',
description:
2024-08-13 16:47:37 +02:00
'Entities are simple JSON objects that represent the core data structures in Versia.',
2024-07-23 00:23:42 +02:00
}
# Entities
2024-08-13 16:47:37 +02:00
Entities are the foundation of the Versia protocol. A similar concept to entities are the [ActivityStreams](https://www.w3.org/TR/activitystreams-core/) objects, which are used to represent activities in the [ActivityPub](https://www.w3.org/TR/activitypub/) protocol. {{ className: 'lead' }}
2024-07-23 00:23:42 +02:00
## Entity Definition
2024-08-13 16:47:37 +02:00
An entity is a simple JSON object that represents a core data structure in Versia. Entities are used to represent various types of data, such as users, notes, and more. Each entity has a unique `id` property that is used to identify it within the instance.
2024-07-23 00:23:42 +02:00
Any field in an entity not marked as `required` may be omitted or set to `null`.
<Row>
<Col>
2024-12-24 14:01:09 +01:00
<Properties name="Entity">
2024-08-02 16:14:03 +02:00
<Property name="id" type="string" required={true}>
2025-05-05 14:08:20 +02:00
Unique identifier for the entity. Must be unique within the instance. Can be any string with the following character sets:
- `a-z`
- `A-Z`
- `0-9`
- `-`, `_`
2024-07-23 00:23:42 +02:00
</Property>
<Property name="type" type="string" required={true}>
2024-08-24 14:29:54 +02:00
Type of the entity. Custom types must follow [Extension Naming](/extensions#naming).
2024-07-23 00:23:42 +02:00
</Property>
2024-10-18 15:00:47 +02:00
<Property name="created_at" type="RFC3339" required={true} typeLink="/types#rfc3339">
Date and time when the entity was created. Must be an [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) timestamp.
2024-07-23 00:23:42 +02:00
<Note>
Handling of dates that are valid but obviously incorrect (e.g. in the future) is left to the Implementation's discretion.
</Note>
</Property>
2024-10-18 15:10:23 +02:00
<Property name="$schema" type="string" required={false}>
URL of any JSON Schema that the entity adheres to.
<Note>
This is for human use only, and not to be used by either clients or servers as a way to validate the entity.
</Note>
</Property>
2024-07-23 00:23:42 +02:00
<Property name="extensions" type="Extensions" required={false} typeLink="/types#extensions">
Extensions to the entity. Use this to add custom properties to the entity.
2024-07-31 18:58:19 +02:00
Each custom property must be namespaced with the organization's reversed domain name, followed by the property name. Extensions should be used sparingly and only when necessary.
2024-07-23 00:23:42 +02:00
</Property>
</Properties>
</Col>
<Col sticky>
```jsonc {{ 'title': 'Example Entity' }}
{
"id": "9a8928b6-2526-4979-aab1-ef2f88cd5700",
2024-08-13 15:59:25 +02:00
"type": "Delete",
2024-07-23 00:23:42 +02:00
"created_at": "2022-01-01T12:00:00Z",
2025-04-21 18:17:45 +02:00
"author": "63a00ab3-39b1-49eb-b88e-ed65d2361f3e",
"deleted": "54059ce2-9332-46fa-bf6a-598b5493b81b",
2024-07-23 00:23:42 +02:00
}
2024-07-31 21:05:42 +02:00
```
2024-07-23 00:23:42 +02:00
```jsonc {{ 'title': 'With Extensions' }}
{
"id": "f0aacf0b-df7a-4ee5-a2ba-6c4acafd8642",
2024-08-24 14:29:54 +02:00
"type": "org.space:Zlorbs/Zlorb",
2024-07-23 00:23:42 +02:00
"created_at": "2023-04-13T08:00:00Z",
"extensions": { // [!code focus:100]
"org.space:zlorbs": {
"zlorb_type": "giant",
"zlorb_size": "huge"
},
2024-08-13 16:47:37 +02:00
"pub.versia:location": {
2024-07-23 00:23:42 +02:00
"latitude": 37.7749,
"longitude": -122.4194
}
}
}
```
</Col>
</Row>
2024-12-10 17:44:51 +01:00
## Transient Entities
2025-05-05 14:08:20 +02:00
Some entities are transient, meaning they cannot be refetched using the [Federation API](/api/endpoints). These entities are used for actions that do not require a permanent record, such as deletions or migrations.
2024-12-10 17:44:51 +01:00
Implementations **must not** rely on other implementations to store transient entities in their database.
2024-07-23 00:23:42 +02:00
## Serialization
2024-10-18 10:52:00 +02:00
When serialized to a string, the JSON representation of an entity must follow the following rules:
2024-07-23 00:23:42 +02:00
- Keys must be sorted lexicographically.
2024-10-18 10:52:00 +02:00
- Must use UTF-8 encoding.
2025-05-05 14:08:20 +02:00
- Must be **signed** using the the [instance's private key](/entities/instance-metadata).
2024-10-18 10:52:00 +02:00
- Must use Unix-style `\n` line endings (LF).