Skip to main content
Entities are the core content objects in Sublay — posts, articles, products, or any item in your application that users interact with. The entities module gives you full control over their lifecycle, reactions, and drafts. All actions are performed on behalf of the logged-in user.

createEntity

Creates a new entity, optionally as a draft or without attributing it to the logged-in user.
string
Your application’s identifier for this entity. Used for idempotent lookups via fetchEntityByForeignId.
string
An optional secondary identifier for grouping or filtering entities.
string
The space this entity belongs to.
string
Title text for the entity.
string
Body/content text for the entity.
Record<string, any>[]
File or media attachments.
string[]
Tags or keywords used for filtering and discovery.
Mention[]
User mentions embedded in the entity.
object
Geographic coordinates { latitude: number; longitude: number }.
Record<string, any>
Arbitrary public metadata.
boolean
When true, the entity is created as an unpublished draft.
boolean
When true, creates the entity without attributing it to the logged-in user (authorless).
ReturnsPromise<Entity>

fetchEntity

Fetches a single entity by its Sublay ID.
string
required
The Sublay entity ID.
string
Comma-separated list of associations to populate.
string
Opts the returned entity’s author into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<Entity>

fetchEntityByForeignId

Fetches an entity by your application’s own identifier. Optionally creates it if not found.
string
required
Your application’s entity identifier.
boolean
When true, creates a stub entity if no match is found.
string
Comma-separated list of associations to populate.
ReturnsPromise<Entity>

fetchEntityByShortId

Fetches an entity by its short, human-readable ID (used in share URLs).
string
required
The entity’s short ID.
string
Comma-separated list of associations to populate.
ReturnsPromise<Entity>

fetchManyEntities

Fetches a filtered, paginated list of entities (feeds). Supports rich filtering by metadata, keywords, location, and more.
string
Filter by source ID.
string
Filter to entities within a specific space.
string
Sort order: "createdAt" (chronological — honors sortDir), "hot" (trending), "top" (highest scored), or "controversial". A "metadata.<prop>" value is also accepted to sort by a metadata field.
string
Sort direction: "asc" or "desc".
string
How to interpret a metadata sort value: "auto", "numeric", "text", "boolean", or "timestamp".
string
Sort by the count of a specific reaction: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny".
number
Page number (1-indexed).
number
Results per page.
string
Comma-separated list of associations to populate (e.g. "user").
string
Time window to restrict results to: "hour", "day", "week", "month", or "year".
string
The author to filter by, also used as the viewing user to resolve followedOnly.
"true" | "false"
When "true", returns only entities from users the given userId follows.
object
Filter by keyword tags: { includes?: string[]; doesNotInclude?: string[] }.
object
Filter by metadata fields: { includes?: object; includesAny?: object[]; doesNotInclude?: object; exists?: string[]; doesNotExist?: string[] }.
object
Filter by title: { hasTitle?: "true" | "false"; includes?: string | string[]; doesNotInclude?: string | string[] }.
object
Filter by content: { hasContent?: "true" | "false"; includes?: string | string[]; doesNotInclude?: string | string[] }.
object
Filter by attachments: { hasAttachments?: "true" | "false" }.
object
Filter within a geographic radius: { latitude: string; longitude: string; radius: string }.
string
Opts each returned entity’s author into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context — resolved per-row from the space each entity belongs to). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<PaginatedResponse<Entity>>

updateEntity

Updates fields on an existing entity.
string
required
The Sublay entity ID to update.
string
New title.
string
New content body.
Record<string, any>[]
Updated attachments list.
string[]
Updated keywords list.
Mention[]
Updated user mentions list.
object
Updated coordinates { latitude: number; longitude: number }.
Record<string, any>
Updated metadata. Merged with existing values.
ReturnsPromise<Entity>

deleteEntity

Permanently deletes an entity and its associated data.
string
required
The Sublay entity ID to delete.
ReturnsPromise<void>

fetchDrafts

Fetches the logged-in user’s unpublished draft entities.
number
Page number (1-indexed).
number
Results per page.
string
Filter drafts by source ID.
string
Filter drafts to a specific space.
string
Comma-separated list of associations to populate.
ReturnsPromise<PaginatedResponse<Entity>>

publishDraft

Publishes a draft entity, making it publicly visible.
string
required
The Sublay entity ID of the draft to publish.
ReturnsPromise<Entity>

fetchTopComment

Fetches the highest-scored (top) comment on an entity. Returns null if the entity has no comments.
string
required
The Sublay entity ID.
ReturnsPromise<TopComment | null>

addReaction

Adds the logged-in user’s reaction to an entity and returns the updated entity.
string
required
The Sublay entity ID.
ReactionType
required
One of: "upvote", "downvote", "like", "love", "wow", "sad", "angry", "funny".
ReturnsPromise<Entity>

removeReaction

Removes the logged-in user’s reaction from an entity and returns the updated entity.
string
required
The Sublay entity ID.
ReturnsPromise<Entity>

fetchReactions

Fetches a paginated list of reactions on an entity, optionally filtered by reaction type.
string
required
The Sublay entity ID.
ReactionType
Filter to a specific reaction type.
number
Page number (1-indexed).
number
Results per page.
string
Sort direction: "asc" or "desc".
string
Opts each returned reactor into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<{ data: Reaction[]; pagination: { page: number; limit: number; total: number; totalPages: number; hasMore: boolean } }>

getUserReaction

Gets the logged-in user’s reaction on an entity. Returns null if there is no reaction.
string
required
The Sublay entity ID.
ReturnsPromise<{ reactionType: ReactionType | null }>

isEntitySaved

Checks whether the logged-in user has saved an entity, and in which collections.
string
required
The Sublay entity ID.
ReturnsPromise<{ saved: boolean; collections: { id: string; name: string }[] }>