Feed + Log API

Types

// store any valid primitive JS type.
// Maintains type on retrieval.
type Content = string | number | boolean | object | Content[]

interface FeedlogEntry = {
    id: string
    createdAt: number
    updatedAt: number
    createdBy: string
    updatedBy: string
    content: Content
    links: object // authors as keys, Content as values
}

Feedlog Methods

post

feedlog.post(content: Content)

Params: content to post to the feedlog.

Returns: A promise resolving to a string (the post ID) on success or undefined on failure.

Add a new post to the feedlog. Automatically stores the creation time and author.

const id = await feedlog.post({ foo: ['bar', 3, true] })

edit

feedlog.edit(id: string, newContent: Content)

Params: The id of the post to edit, and newContent to replace it with.

Returns: A promise resolving to a string (the post ID) on success or undefined on failure.

Edit a post in the feedlog. Automatically stores the updated time and author.

const id = await feedlog.post('original post')
if (id) {
    await feedlog.edit(id, 'edited post')
}

delete

feedlog.delete(id: string)

Params: The id of the post to delete.

Returns: A promise resolving to true on success or false on failure.

Delete a post from the feedlog. If the post with id does not exist, returns true.

const id = await feedlog.post('original post')
if (id) {
    await feedlog.delete(id)
}

clear

feedlog.clear()

Returns: A promise resolving to true on success or false on failure.

Clear all posts from the feedlog.

await feedlog.clear()

get

feedlog.get(id: string, allowCachedValue: boolean = true)

Params: The id of the post to retrieve. If allowCachedValue is true, we will check the cache before querying Urbit.

Returns: A promise resolving to a FeedlogEntry or undefined if the post does not exist.

Get the post from the feedlog with the given id.

await feedlog.get('foo')

all

feedlog.all(useCache: boolean = false)

Params: If useCache is true, return the current cache instead of querying Urbit. Only relevant if preload was set to false.

Returns: A promise resolving to a FeedlogEntry[]

Retrieve all posts from the feedlog, sorted by newest first.

await feedlog.all()

Feed Methods

feed.setLink(id: string, content: Content)

Params: The id of the post to link to, and the content to associate with it.

Returns: A promise resolving to true on success or false on failure.

Associate a "link" (comment, reaction, etc.) with the feed post corresponding to id. Post links are stored as an object where keys are ship names and values are content. setLink will overwrite the link for the current ship, so call get first if you would like to append.

const id = await feedlog.post('original post')
if (id) {
    await feed.setLink(id, { comment: 'first comment!', time: Date.now() })
}

feed.removeLink(id: string)

Params: The id of the post to remove the link from.

Returns: A promise resolving to true on success or false on failure.

Remove the current ship's link to the feed post corresponding to id. If the post with id does not exist, returns true.

const id = await feedlog.post('original post')
if (id) {
    await feed.setLink(id, { comment: 'first comment!', time: Date.now() })
    await feed.removeLink(id)
}

Last updated