Extensible property graph database stored in JSON-LD.
This helper function logs the current version of GraphletDB to the console.
aboutGraphletDB(); // Outputs "GraphletDB v0.0.1"
This helper function creates a random hexadecimal token of the length
specified by len
. It ensures the uniqueness of the token
within the provided nodes
array. Each node in the array is
expected to have an id
property, which is used to check for
uniqueness. The function repeatedly generates new tokens until it finds
one that is not already present in the nodes
array.
Parameters:
nodes
array of objects where each
object represents a node. The function only cares that each node has an
id
property.len
integer number of characters to
generate in the hexadecimal string.Returns a unique lowercase hexadecimal string of the specified length.
let nodes = [{ id: 'a1b2' }, { id: 'c3d4' }];
let tokenLength = 4;
let newToken = getRandomToken(nodes, tokenLength);
console.log(newToken); // Outputs a unique 4-character hexadecimal string
This helper function returns a list of all nodes with the label
Label
. If the objOrIds
parameter is
obj
, the function returns a list of Label node objects. If
the objOrIds
parameter is id
, the function
returns a list of id
strings.
Parameters:
nodes
array of objects where each
object represents a node. The function only cares that each node has an
id
property.objOrIds
string determines the
type of the returned list. Use obj
to get a list of node
objects, and id
to get a list of id
strings.Returns an array of either id
strings
or full node objects, depending on the objOrIds
parameter
value.
let nodes = [
id: 'node1', label: 'Label', data: {...} },
{ id: 'node2', label: 'Label', data: {...} },
{ ;
]
// Example 1: Get list of node objects
let labelObjects = getListOfLabels('obj');
console.log(labelObjects);
// Example 2: Get list of id strings
let labelIds = getListOfLabels('id');
console.log(labelIds);
This function initializes returns a predefined minimal list that meets the GraphletDB schema. This can be used to set up or reset a list to a known default state that contains one Label object.
Returns an array containing a single Label object.
The structure and content of the Label object are determined by the
initLabelNode
.
let newList = initList();
console.log(newList); // Outputs the content of initLabelNode
If a Label node exists for that label, create and return a list containing the new node using the Label node as a template.
If a Label node does not exist for that label, create the Label node, then create and return an array of both node
Return a single object of type Label, if that label exists.
This function retrieves one or more nodes from a list based on a
specified key-value pair. If boolFirstOnly
is true, the
function returns the first node that matches the key-value pair. If
false, it returns all nodes matching the key-value pair.
Parameters:
nodes
(Array): An array of objects, each representing a
node.key
(String): The key to match within each node
object.value
(Any): The value to match for the given key.boolFirstOnly
(Boolean): Determines whether to return
only the first matching node (true
) or all matching nodes
(false
).Returns an array containing the matching node(s). If
boolFirstOnly
is true, the array contains only the first
matching node or is empty if no match is found. If
boolFirstOnly
is false, the array contains all nodes that
match the key-value pair or is empty if no matches are found.
let nodes = [
id: 'node1', type: 'Label', data: {...} },
{ id: 'node2', type: 'Label', data: {...} },
{ ;
]
let firstLabelNode = getNodeByKeyPair(nodes, 'type', 'Label', true);
console.log(firstLabelNode);
let allLabelNodes = getNodeByKeyPair(nodes, 'type', 'Label', false);
console.log(allLabelNodes);
Optional: if doFix is true, return a fixed list.