new RoomBridgeStore(db, opts)
Construct a store suitable for room bridging information. Data is stored
as RoomBridgeStore~Entrys which have the following
serialized format:
{ id: "unique_id", // customisable matrix_id: "room_id", remote_id: "remote_room_id", matrix: { serialised matrix room info }, remote: { serialised remote room info }, data: { ... any additional info ... } }
If a unique 'id' is not given, the store will generate one by concatenating
the matrix_id
and the remote_id
. The delimiter
used is a property on this store and can be modified.
The structure of Entry objects means that it is efficient to select based off the 'id', 'matrix_id' or 'remote_id'. Additional indexes can be added manually.
Parameters:
Name | Type | Description |
---|---|---|
db |
Datastore | The connected NEDB database instance |
opts |
Object | Options for this store. |
Properties:
Name | Type | Description |
---|---|---|
delimiter |
string | The delimiter between matrix and remote IDs. Defaults to three spaces. If the schema of your remote IDs allows spaces, you will need to change this. |
- Source:
Methods
batchGetLinkedRemoteRooms(matrixIds) → {Object.<string, RemoteRoom>}
A batched version of
getLinkedRemoteRooms
.
Parameters:
Name | Type | Description |
---|---|---|
matrixIds |
Array.<string> |
Returns:
A mapping of room_id to RemoteRoom.
- Type
- Object.<string, RemoteRoom>
getEntriesByLinkData(data) → {Array.<RoomBridgeStore~Entry>}
Get a list of entries based on the link's data value.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data values to retrieve based from. |
- Source:
Returns:
A list of entries
- Type
- Array.<RoomBridgeStore~Entry>
Example
store.linkRooms(matrixRoom, remoteRoom, { some_key: "some_val" });
store.getEntriesByLinkData({
some_key: "some_val"
});
getEntriesByMatrixId(matrixId) → {Array.<RoomBridgeStore~Entry>}
Get a list of entries based on the matrix_id of each entry.
Parameters:
Name | Type | Description |
---|---|---|
matrixId |
string |
- Source:
Returns:
- Type
- Array.<RoomBridgeStore~Entry>
getEntriesByMatrixIds(ids) → {Object.<string, Array.<RoomBridgeStore~Entry>>}
A batch version of
getEntriesByMatrixId
.
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array.<String> |
- Source:
Returns:
Resolves
to a map of room_id => Entry[]
- Type
- Object.<string, Array.<RoomBridgeStore~Entry>>
getEntriesByMatrixRoomData(data) → {Array.<RoomBridgeStore~Entry>}
Get a list of entries based on a MatrixRoom data value.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data values to retrieve based from. |
- Source:
Returns:
A list of entries
- Type
- Array.<RoomBridgeStore~Entry>
Example
matrixRoom.set("some_key", "some_val");
// store matrixRoom and then:
store.getEntriesByMatrixRoomData({
some_key: "some_val"
});
getEntriesByRemoteId(remoteId) → {Array.<RoomBridgeStore~Entry>}
Get a list of entries based on the remote_id of each entry.
Parameters:
Name | Type | Description |
---|---|---|
remoteId |
String |
- Source:
Returns:
- Type
- Array.<RoomBridgeStore~Entry>
getEntriesByRemoteRoomData(data) → {Array.<RoomBridgeStore~Entry>}
Get a list of entries based on a RemoteRoom data value.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data values to retrieve based from. |
- Source:
Returns:
A list of entries
- Type
- Array.<RoomBridgeStore~Entry>
Example
remoteRoom.set("some_key", "some_val");
// store remoteRoom and then:
store.getEntriesByRemoteRoomData({
some_key: "some_val"
});
getEntryById(id) → (nullable) {RoomBridgeStore~Entry}
Get an existing entry based on the provided entry ID.
Parameters:
Name | Type | Description |
---|---|---|
id |
String | The ID of the entry to retrieve. |
- Source:
Returns:
A promise which resolves to the entry or null.
getLinkedMatrixRooms(remoteId) → {Array.<MatrixRoom>}
Get all entries with the given remote_id which have a Matrix room within.
Parameters:
Name | Type | Description |
---|---|---|
remoteId |
string |
- Source:
Returns:
- Type
- Array.<MatrixRoom>
getLinkedRemoteRooms(matrixId) → {Array.<RemoteRoom>}
Get all entries with the given matrix_id which have a Remote room within.
Parameters:
Name | Type | Description |
---|---|---|
matrixId |
string |
- Source:
Returns:
- Type
- Array.<RemoteRoom>
getMatrixRoom(roomId) → (nullable) {MatrixRoom}
Get an entry's Matrix room based on the provided room_id. The entry MUST have
an 'id' of the room_id and there MUST be a Matrix room contained within the
entry for this to return.
Parameters:
Name | Type | Description |
---|---|---|
roomId |
string |
Returns:
- Type
- MatrixRoom
linkRooms(matrixRoom, remoteRoom, dataopt, linkIdopt) → {Promise}
Create a link between a matrix room and remote room. This will create an entry with:
- The matrix_id set to the matrix room ID.
- The remote_id set to the remote room ID.
- The id set to the id value given OR a concatenation of the matrix and remote IDs if one is not provided.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
matrixRoom |
MatrixRoom | The matrix room | |
remoteRoom |
RemoteRoom | The remote room | |
data |
Object |
<optional> |
Information about this mapping. |
linkId |
string |
<optional> |
The id value to set. If not given, a unique ID will be created from the matrix_id and remote_id. |
- Source:
Returns:
- Type
- Promise
removeEntriesByLinkData(data) → {Promise}
Remove entries based on the link's data value.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data to match. |
- Source:
Returns:
- Type
- Promise
Example
store.linkRooms(matrixRoom, remoteRoom, { a_key: "a_val" });
store.removeEntriesByLinkData({
a_key: "a_val"
});
removeEntriesByMatrixRoomData(data) → {Promise}
Remove entries based on matrix room data.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data to match. |
- Source:
Returns:
- Type
- Promise
Example
matrixRoom.set("a_key", "a_val");
// store matrixRoom and then:
store.removeEntriesByMatrixRoomData({
a_key: "a_val"
});
removeEntriesByMatrixRoomId(matrixId) → {Promise}
Remove entries with this matrix room id.
Parameters:
Name | Type | Description |
---|---|---|
matrixId |
Object | The matrix id. |
- Source:
Returns:
- Type
- Promise
Example
new MatrixRoom("!foobar:matrix.org");
// store the MatrixRoom and then:
store.removeEntriesByMatrixRoomId("!foobar:matrix.org");
removeEntriesByRemoteRoomData(data) → {Promise}
Remove entries based on remote room data.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | The data to match. |
- Source:
Returns:
- Type
- Promise
Example
remoteRoom.set("a_key", "a_val");
// store remoteRoom and then:
store.removeEntriesByRemoteRoomData({
a_key: "a_val"
});
removeEntriesByRemoteRoomId(remoteId) → {Promise}
Remove entries with this remote room id.
Parameters:
Name | Type | Description |
---|---|---|
remoteId |
Object | The remote id. |
- Source:
Returns:
- Type
- Promise
Example
new RemoteRoom("foobar");
// store the RemoteRoom and then:
store.removeEntriesByRemoteRoomId("foobar");
setMatrixRoom(matrixRoom) → {Promise}
Create an entry with only a matrix room. Sets the 'id' of the entry to the
Matrix room ID. If an entry already exists with this 'id', it will be replaced.
This function is useful if you just want to store a room with some data and not
worry about any mappings.
Parameters:
Name | Type | Description |
---|---|---|
matrixRoom |
MatrixRoom |
Returns:
- Type
- Promise
upsertEntry(entry) → {Promise}
Insert an entry, clobbering based on the ID of the entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
RoomBridgeStore~Entry |
- Source:
Returns:
- Type
- Promise
Type Definitions
Entry
Construct a new RoomBridgeStore Entry.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
id |
string | The unique ID for this entry. | |
matrix |
MatrixRoom |
<nullable> |
The matrix room, if applicable. |
remote |
RemoteRoom |
<nullable> |
The remote room, if applicable. |
data |
Object |
<nullable> |
Information about this mapping, which may be an empty. |
- Source: