import { Stream } from "../../../common/util/Stream"; import { TypeDBTransaction } from "../../connection/TypeDBTransaction"; import { RelationType } from "../type/RelationType"; import { RoleType } from "../type/RoleType"; import { Thing } from "./Thing"; /** * Relation is an instance of a relation type and can be uniquely addressed by * a combination of its type, owned attributes and role players. */ export interface Relation extends Thing { /** * The type which this Relation belongs to. */ readonly type: RelationType; /** * Adds a new role player to play the given role in this Relation. * * ### Examples * * ```ts * relation.addRolePlayer(transaction, roleType, player) * ``` * * @param transaction - The current transaction * @param roleType - The role to be played by the player * @param player - The thing to play the role */ addRolePlayer(transaction: TypeDBTransaction, roleType: RoleType, player: Thing): Promise; /** * Removes the association of the given instance that plays the given role in this Relation. * * ### Examples * * ```ts * relation.removeRolePlayer(transaction, roleType, player) * ``` * * @param transaction - The current transaction * @param roleType - The role to no longer be played by the thing in this Relation * @param player - The instance to no longer play the role in this Relation */ removeRolePlayer(transaction: TypeDBTransaction, roleType: RoleType, player: Thing): Promise; /** * Retrieves all role players of this Relation, optionally filtered by given role types. * * ### Examples * * ```ts * relation.getPlayersByRoleType(transaction) * relation.getPlayersByRoleType(transaction, [roleType1, roleType2]) * ``` * * @param transaction - The current transaction * @param roleTypes - 0 or more role types */ getPlayersByRoleType(transaction: TypeDBTransaction): Stream; /** * Retrieves all role players of this Relation, optionally filtered by given role types. * * ### Examples * * ```ts * relation.getPlayersByRoleType(transaction) * relation.getPlayersByRoleType(transaction, [roleType1, roleType2]) * ``` * * @param transaction - The current transaction * @param roleTypes - 0 or more role types */ getPlayersByRoleType(transaction: TypeDBTransaction, roleTypes: RoleType[]): Stream; /** * Retrieves a mapping of all instances involved in the Relation and the role each play. * * ### Examples * * ```ts * relation.getRolePlayers(transaction) * ``` * * @param transaction - The current transaction */ getRolePlayers(transaction: TypeDBTransaction): Promise>; /** * Retrieves all role types currently played in this Relation. * * ### Examples * * ```ts * relation.getRelating(transaction) * ``` * * @param transaction - The current transaction */ getRelating(transaction: TypeDBTransaction): Stream; } export declare namespace Relation { function proto(relation: Relation): import("typedb-protocol/proto/concept").Relation; }