Skip to content

Commit

Permalink
Make api sections in readme a little prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed Sep 16, 2021
1 parent 4e4fb63 commit b4b234d
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ npm install cabal-core

> var Cabal = require('cabal-core')
### var cabal = Cabal([storage][, key][, opts])
### `var cabal = Cabal([storage][, key][, opts])`

Create a cabal p2p database using storage `storage`, which must be either a
string (filepath to directory on disk) or an instance of
Expand All @@ -36,11 +36,11 @@ Other `opts` include:
- `opts.modKeys`: an array of keys to be considered moderators from this user's perspective.
- `opts.adminKeys`: an array of keys to be considered administrators from this user's perspective.

### cabal.getLocalKey(cb)
### `cabal.getLocalKey(cb)`

Returns the local user's key (as a hex string).

### var ds = cabal.replicate(isInitiator[, opts])
### `var ds = cabal.replicate(isInitiator[, opts])`

Creates a new, live replication stream. This duplex stream can be piped into any
transport expressed as a node stream (tcp, websockets, udp, utp, etc).
Expand All @@ -49,60 +49,60 @@ Ensure that `isInitiator` to `true` to one side, and `false` on the other. This

`opts` are passed down into the underlying `hypercore` replication.

### cabal.ready(cb)
### `cabal.ready(cb)`

Calls `cb()` when the underlying indexes are caught up.

### cabal.close(cb)
### `cabal.close(cb)`

Calls `cb()` when the cabal and its resources have been closed. This also leaves the swarm, if joined.

### cabal.getMessage(key, cb)
### `cabal.getMessage(key, cb)`

Read a message from `key`, a string of `feedKey@seq` or an object of
`{ key, seq }` as `cb(err, node)` from the underlying hypercore.

### Channels

#### cabal.channels.get(function (error, channels) {})
#### `cabal.channels.get(function (error, channels) {})`

Retrieve a list of all channel names that exist in this cabal.

#### cabal.channels.events.on('add', function (channel) {})
#### `cabal.channels.events.on('add', function (channel) {})`

Emitted when a new channel is added to the cabal.

### Messages

#### var rs = cabal.messages.read(channel, opts)
#### `var rs = cabal.messages.read(channel, opts)`

Returns a readable stream of messages (most recent first) from a channel.

Pass `opts.limit` to set a maximum number of messages to read.

#### cabal.messages.events.on('message', fn)
#### `cabal.messages.events.on('message', fn)`

Calls `fn` with every new message that arrives, regardless of channel.

#### cabal.messages.events.on(channel, fn)
#### `cabal.messages.events.on(channel, fn)`

Calls `fn` with every new message that arrives in `channel`.

### Network

> var swarm = require('cabal-core/swarm')
#### cabal.swarm(cb)
#### `cabal.swarm(cb)`

Joins the P2P swarm for a cabal. This seeks out peers who are also part of this cabal by various means (internet, local network), connects to them, and replicates cabal messages between them.

The returned object is an instance of [discovery-swarm](https://github.com/mafintosh/discovery-swarm).

#### cabal.on('peer-added', function (key) {})
#### `cabal.on('peer-added', function (key) {})`

Emitted when you connect to a peer. `key` is a hex string of their public key.

#### cabal.on('peer-dropped', function (key) {})
#### `cabal.on('peer-dropped', function (key) {})`

Emitted when you lose a connection to a peer. `key` is a hex string of their
public key.
Expand All @@ -128,7 +128,7 @@ This means that if a group of people all specify the same _moderation key_,
they will collectively see the same set of administrators, moderators, and
banned users.

#### cabal.moderation.listByFlag({ channel, flag })
#### `cabal.moderation.listByFlag({ channel, flag })`

Return a readable object stream of records for `channel` that for each user with
`flag` set. Flags used by cabal-core include: "hide", "mute", "block", "admin",
Expand All @@ -142,7 +142,7 @@ Each `row` object in the output stream has:

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.list(cb)
#### `cabal.moderation.list(cb)`

Return a readable object stream of records for all moderation actions across all
channels.
Expand All @@ -156,31 +156,31 @@ Each `row` object in the output stream has:

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listBlocks(channel, cb)
#### `cabal.moderation.listBlocks(channel, cb)`

Return a readable object stream of records for the blocks in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listHides(channel, cb)
#### `cabal.moderation.listHides(channel, cb)`

Return a readable object stream of records for the hides in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listMutes(channel, cb)
#### `cabal.moderation.listMutes(channel, cb)`

Return a readable object stream of records for the mutes in `channel`.

The objects in the output have the same form as `listByFlag()`.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.listModerationBy(key, cb)
#### `cabal.moderation.listModerationBy(key, cb)`

Return a readable object stream of moderation documents authored by `key`.

Expand All @@ -196,64 +196,64 @@ setting flags.

Optionally collect results into `cb(err, rows)`.

#### cabal.moderation.getFlags({ id, channel }, cb)
#### `cabal.moderation.getFlags({ id, channel }, cb)`

Get a list of flags set for the user identified by `id` in `channel` as
`cb(err, flags)`.

#### cabal.moderation.setFlags({ id, channel, flags }, cb)
#### `cabal.moderation.setFlags({ id, channel, flags }, cb)`

Set an array of `flags` for `id` in `channel`.

#### cabal.moderation.addFlags({ id, channel, flags }, cb)
#### `cabal.moderation.addFlags({ id, channel, flags }, cb)`

Add an array of `flags` to the existing set of flags for `id` in `channel`.

#### cabal.moderation.removeFlags({ id, channel, flags }, cb)
#### `cabal.moderation.removeFlags({ id, channel, flags }, cb)`

Remove an array of `flags` from the existing set of flags for `id` in `channel`.

#### cabal.moderation.events.on('update', function (update) {})
#### `cabal.moderation.events.on('update', function (update) {})`

This event happens when a user's flags change with `update`, the log record
responsible for the state change.

#### cabal.moderation.events.on('skip', function (skip) {})
#### `cabal.moderation.events.on('skip', function (skip) {})`

This event happens when a moderation update was skipped with `skip`, the log
record responsible for the state change.

### Private Messages

#### cabal.publishPrivateMessage(text, recipientKey, cb)
#### `cabal.publishPrivateMessage(text, recipientKey, cb)`

Write the private message string `text` to be encrypted so that only
`recipientKey` (the public key of its recipient) can read it.

A `timestamp` field is set automatically with the current local system time.

#### cabal.privateMessages.list(cb)
#### `cabal.privateMessages.list(cb)`

Returns a list of strings of all users' public keys that have sent a PM to you,
or who you have sent a PM to.

#### var rs = cabal.privateMessages.read(channel, opts)
#### `var rs = cabal.privateMessages.read(channel, opts)`

Returns a readable stream of messages (most recent first) from a channel.

Pass `opts.limit` to set a maximum number of messages to read.

#### cabal.privateMessages.events.on('message', fn)
#### `cabal.privateMessages.events.on('message', fn)`

Calls `fn` with every new private message that arrives.

#### cabal.privateMessages.events.on(publicKey, fn)
#### `cabal.privateMessages.events.on(publicKey, fn)`

Calls `fn` with every new message that arrives to or from `publicKey`.

### Publishing

#### cabal.publish(message, opts, cb)
#### `cabal.publish(message, opts, cb)`

Publish `message` to your feed. `message` must have a `type` field set. If not,
it defaults to `chat/text`. In general, a message is formatted as
Expand Down

0 comments on commit b4b234d

Please sign in to comment.