Methods to manage relationships for the `Me` class, with enforced relationship types and validation.
Methods
# static addRelationship(relationships, relationship)
Add a relationship to the `me` instance.
Enforces relationship types and allows additional metadata for extensibility.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
relationships |
Array
|
The relationships array to update. | |
relationship |
Object
|
The relationship to add. | |
type |
string
|
The type of relationship (e.g., "friend", "colleague"). | |
username |
string
|
The username of the related entity. | |
meta |
Object
|
<optional> |
Additional metadata for the relationship (optional). |
If the relationship type or username is invalid.
Error
Example
// Adding a friend
addRelationship(relationships, { type: "friend", username: "alice" });
// Adding a group with metadata
addRelationship(relationships, {
type: "group",
username: "FamilyGroup",
meta: { members: ["alice", "bob"] }
});
# static getRelationships(relationships, typeopt) → {Array}
Retrieve all relationships for the `me` instance, optionally filtered by type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
relationships |
Array
|
The relationships array to retrieve from. | |
type |
string
|
<optional> |
The type of relationship to filter by (e.g., "friend", "family"). |
The filtered or full relationships array.
Array
Example
// Get all relationships
getRelationships(relationships);
// Get only friends
getRelationships(relationships, "friend");