Base class for all record types.
const newRecord = PostRecord.new(...);
const updatedRecord = TaskRecord.update(...);
const subscription = FileRecord.subscribe(...);
Record
delete(entity, record, action?)
: NoContentRecord
Create a NoContentRecord
tombstone from an existing record.
entity
Entity
record
Record
action
NoContentRecordAction optional
Type of deletion to perform.
Defaults to delete
.
isPublic(record: Record)
: boolean
hasType<T>(record: Record, type: RecordType<T>)
: boolean
Check whether a record is of a given type.
Acts as a type guard for record
as T
.
toKey(record: Record)
: RecordKey
toLink(record: Record)
: RecordLink
toVersionHash(record: Record)
: VersionHash | undefined
Available on any specific record type derived from the base Record
class like those generated by the CLI.
new(entity, content, options?)
: Record
Create a new record of that record type.
entity
Entity
content
object
Options
id
string optional
mode
RecordMode optional
Should the record be synchronized or kept local.
Defaults to synced
.
permissions
RecordPermissions optional
Permissions for the record.
Defaults to private permissions.
update(entity, record, content, options?)
: Record
Update an existing record of that record type.
entity
Entity
record
Record
content
object
Accepts the same options as new()
.
subscribe(entity, publisherEntity, options?)
: Record
Subscribe to records of that record type from a given publisher.
Options
id
string optional
readPermissions
“public” | EntityLink[] optional
Read permissions for the subscription record.
Defaults to private permissions.
link
: RecordLink
author
EntityLink
id
RecordId
source
RecordMode
createdAt
Date
receivedAt
Date optional
Date at which the record was received by the server.
Not available when not synchronized with the server.
version
RecordVersion
permissions
RecordPermissions
type
VersionLink
content
object
mode
RecordMode
RecordKey
Unique string identifier that combines a record’s author entity and ID. It makes it possible to pass around a string to identify a record without losing typing information.
const key: RecordKey<T>;
"entity.host.com+ce85c896c24a4685b5a5d480cc4814ef"
RecordSource
Enum that indicates where the record came from.
Possible values:
self
: Created by the server’s user.
resolution
: Record downloaded from a link.
notification
: Received through a notification.
notification_unknown
: From a user with no Standing record.
subscription
: Received through a subscription.
proxy
: Proxied record.
RecordMode
Enum for the SDK to know whether a record should pushed to the server.
Possible values:
synced
: The record should be synchronized with the server.
local
: The record is local-only.
RecordVersion
author
EntityLink
hash
VersionHash optional
SHA256 hash of the canonical JSON representation of the record.
Not available when not synchronized with the server.
createdAt
Date
receivedAt
Date optional
Date at which the record version was received by the server.
Not available when not synchronized with the server.
parentHash
VersionHash optional
NoContentRecord
“Tombstone” that replaces a record after it gets deleted.
Same as Record
, except that content
is replaced with the following:
noContent
object
Properties
action
NoContentRecordAction
Type of deletion.
Defaults to delete
.
NoContentRecordAction
Type of deletion for a NoContentRecord
.
delete
: Standard deletion, propagate to others.local
: Only delete from the user’s server, not propagated.leave
: Remove our user without deleting for others.The methods provided on a Record Type class help creating records by providing full type-checking of the record’s content. Here we create a new private Task record.
import {TaskRecord} from "./baq/taskRecord.js";
function createTask(entity, title) {
return TaskRecord.new(entity, {
title,
completed: false,
});
}
Records are private by default. Making one public requires explicit permissions. Here we create a public Post record with a short text as content.
import {RecordPermissions} from "@baqhub/sdk";
import {PostRecord} from "./baq/postRecord.js";
function createPost(entity, text) {
return PostRecord.new(
entity,
{text},
{permissions: RecordPermissions.public}
);
}
Updating a record requires providing the existing record. This will set the parent_hash
value and opt into optimistic concurrency control when the record is synchronized with the server.
Here we update a Task record by changing the completed
value in its content.
import {TaskRecord} from "./baq/taskRecord.js";
function markTaskAsCompleted(entity, task) {
return TaskRecord.update(task, entity, {
...task.content,
completed: true,
});
}
Deleting a record requires providing the existing record. This will set the parent_hash
value and opt into optimistic concurrency control when the record is synchronized with the server.
Here we delete create a NoContentRecord
from a Task record.
import {Record} from "@baqhub/sdk";
function deleteTask(entity, task) {
return Record.delete(entity, task);
}
Subscribing to another user’s public records is done by creating a Subscription record for a given type. Here we create a private subscription to Post records.
import {PostRecord} from "./baq/postRecord.js";
function subscribeToPosts(entity, publisherEntity) {
return PostRecord.subscribe(entity, publisherEntity);
}