matrix-appservice-bridge
    Preparing search index...

    Class RoomBridgeStore

    Base class for bridge stores.

    Hierarchy (View Summary)

    Index

    Constructors

    • Construct a store suitable for room bridging information. Data is stored as RoomBridgeStoreEntrys 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

      • db: Nedb

        The connected NEDB database instance

      Returns RoomBridgeStore

    Properties

    db: Nedb
    delimiter: string = " "

    Methods

    • A batched version of getLinkedRemoteRooms.

      Parameters

      • matrixIds: string[]

      Returns Promise<{ [roomId: string]: RemoteRoom[] }>

      A mapping of room_id to RemoteRoom.

      RoomBridgeStore#getLinkedRemoteRooms

    • Convenience method to convert a document to something.

      Type Parameters

      • T
      • O

      Parameters

      • func: (input: T) => O

        The function which will be called with a single document object. Guaranteed not to be null.

      Returns (doc: T) => O

      A transformFn function to pass to the standard select/delete/upsert/etc methods.

    • DELETE multiple documents.

      Parameters

      • query: Query

      Returns Promise<number>

    • Get a list of entries based on the link's data value.

      Parameters

      • data: Record<string, unknown>

        The data values to retrieve based from.

      Returns Promise<RoomBridgeStoreEntry[]>

      store.linkRooms(matrixRoom, remoteRoom, { some_key: "some_val" });
      store.getEntriesByLinkData({
      some_key: "some_val"
      });
    • Get a list of entries based on the matrix_id of each entry.

      Parameters

      • matrixId: string

      Returns Promise<RoomBridgeStoreEntry[]>

    • A batch version of getEntriesByMatrixId.

      Parameters

      • ids: string[]

      Returns Promise<{ [matrixId: string]: RoomBridgeStoreEntry[] }>

      Resolves to a map of room_id => Entry[]

    • Get a list of entries based on a MatrixRoom data value.

      Parameters

      • data: Record<string, unknown>

        The data values to retrieve based from.

      Returns Promise<RoomBridgeStoreEntry[]>

      matrixRoom.set("some_key", "some_val");
      // store matrixRoom and then:
      store.getEntriesByMatrixRoomData({
      some_key: "some_val"
      });
    • Get a list of entries based on the remote_id of each entry.

      Parameters

      • remoteId: string

      Returns Promise<RoomBridgeStoreEntry[]>

    • Get a list of entries based on a RemoteRoom data value.

      Parameters

      • data: Record<string, unknown>

        The data values to retrieve based from.

      Returns Promise<RoomBridgeStoreEntry[]>

      remoteRoom.set("some_key", "some_val");
      // store remoteRoom and then:
      store.getEntriesByRemoteRoomData({
      some_key: "some_val"
      });
    • Get an existing entry based on the provided entry ID.

      Parameters

      • id: string

        The ID of the entry to retrieve.

      Returns Promise<null | RoomBridgeStoreEntry>

    • Get all entries with the given remote_id which have a Matrix room within.

      Parameters

      • remoteId: string

      Returns Promise<MatrixRoom[]>

    • Get all entries with the given matrix_id which have a Remote room within.

      Parameters

      • matrixId: string

      Returns Promise<RemoteRoom[]>

    • 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

      • roomId: string

      Returns Promise<undefined | null | MatrixRoom>

      RoomBridgeStore#setMatrixRoom

    • INSERT a multiple documents.

      Parameters

      • objects: unknown

      Returns Promise<any[]>

    • INSERT IF NOT EXISTS a single document

      Parameters

      • query: Query
      • insertObj: Record<string, unknown>

      Returns Promise<void>

    • 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

      • matrixRoom: MatrixRoom

        The matrix room

      • remoteRoom: RemoteRoom

        The remote room

      • data: Record<string, unknown> = {}

        Information about this mapping.

      • OptionallinkId: string

        The id value to set. If not given, a unique ID will be created from the matrix_id and remote_id.

      Returns Promise<void>

    • Remove entries based on the link's data value.

      Parameters

      • data: Record<string, unknown>

        The data to match.

      Returns Promise<number>

      store.linkRooms(matrixRoom, remoteRoom, { a_key: "a_val" });
      store.removeEntriesByLinkData({
      a_key: "a_val"
      });
    • Remove entries based on matrix room data.

      Parameters

      • data: Record<string, unknown>

        The data to match.

      Returns Promise<number>

      matrixRoom.set("a_key", "a_val");
      // store matrixRoom and then:
      store.removeEntriesByMatrixRoomData({
      a_key: "a_val"
      });
    • Remove entries with this matrix room id.

      Parameters

      • matrixId: string

        The matrix id.

      Returns Promise<number>

      new MatrixRoom("!foobar:matrix.org");
      // store the MatrixRoom and then:
      store.removeEntriesByMatrixRoomId("!foobar:matrix.org");
    • Remove entries based on remote room data.

      Parameters

      • data: Record<string, unknown>

        The data to match.

      Returns Promise<number>

      remoteRoom.set("a_key", "a_val");
      // store remoteRoom and then:
      store.removeEntriesByRemoteRoomData({
      a_key: "a_val"
      });
    • Remove entries with this remote room id.

      Parameters

      • remoteId: string

        The remote id.

      Returns Promise<number>

      new RemoteRoom("foobar");
      // store the RemoteRoom and then:
      store.removeEntriesByRemoteRoomId("foobar");
    • Remove an existing entry based on the provided entry ID.

      Parameters

      • id: string

        The ID of the entry to remove.

      Returns Promise<number>

      store.removeEntryById("anid");
      
    • SELECT a number of documents.

      Type Parameters

      • T
      • O

      Parameters

      • query: Query
      • OptionaltransformFn: (input: T) => O

      Returns Promise<O[]>

    • SELECT a single document.

      Type Parameters

      • T
      • O

      Parameters

      • query: Query
      • OptionaltransformFn: (input: T) => O

      Returns Promise<null | O>

    • 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

      Returns Promise<void>

      RoomBridgeStore#getMatrixRoom

    • Set a UNIQUE key constraint on the given field.

      Parameters

      • fieldName: string

        The field name. Use dot notation for nested objects.

      • sparse: boolean = false

        Allow sparse entries (undefined won't cause a key violation).

      Returns void

    • UPDATE a single document. If the document already exists, this will NOT update it.

      Parameters

      • query: Query
      • updateVals: Record<string, unknown>

      Returns Promise<void>

    • UPSERT a single document

      Type Parameters

      • T

      Parameters

      • query: Query
      • updateVals: T

      Returns Promise<void>

    • Insert an entry, clobbering based on the ID of the entry.

      Parameters

      Returns Promise<void>

    • Parameters

      • matrixRoomId: string
      • remoteRoomId: string
      • delimiter: string

      Returns string