This section introduces methods for controlling access to the database, graphs, and data.
Privilege
showPrivilege()
Retrieves all system privileges and graph privileges.
Parameters
config: RequestConfig
(Optional): Request configuration.
Returns
Privilege[]
: The list of retrieved privileges.
// Retrieves all system privileges and graph privileges
const privileges = await conn.showPrivilege();
const graphPriviledgeNames = privileges
.filter((p) => p.level === PrivilegeLevel.GraphLevel)
.map((p) => p.name)
.join(", ");
console.log("Graph privileges: " + graphPriviledgeNames);
const systemPriviledgeNames = privileges
.filter((p) => p.level === PrivilegeLevel.SystemLevel)
.map((p) => p.name)
.join(", ");
console.log("System privileges: " + systemPriviledgeNames);
Graph privileges: ['READ', 'INSERT', 'UPSERT', 'UPDATE', 'DELETE', 'CREATE_SCHEMA', 'DROP_SCHEMA', 'ALTER_SCHEMA', 'SHOW_SCHEMA', 'RELOAD_SCHEMA', 'CREATE_PROPERTY', 'DROP_PROPERTY', 'ALTER_PROPERTY', 'SHOW_PROPERTY', 'CREATE_FULLTEXT', 'DROP_FULLTEXT', 'SHOW_FULLTEXT', 'CREATE_INDEX', 'DROP_INDEX', 'SHOW_INDEX', 'LTE', 'UFE', 'CLEAR_JOB', 'STOP_JOB', 'SHOW_JOB', 'ALGO', 'CREATE_PROJECT', 'SHOW_PROJECT', 'DROP_PROJECT', 'CREATE_HDC_GRAPH', 'SHOW_HDC_GRAPH', 'DROP_HDC_GRAPH', 'COMPACT_HDC_GRAPH', 'SHOW_VECTOR_INDEX', 'CREATE_VECTOR_INDEX', 'DROP_VECTOR_INDEX', 'SHOW_CONSTRAINT', 'CREATE_CONSTRAINT', 'DROP_CONSTRAINT']
System privileges: ['TRUNCATE', 'COMPACT', 'CREATE_GRAPH', 'SHOW_GRAPH', 'DROP_GRAPH', 'ALTER_GRAPH', 'TOP', 'KILL', 'STAT', 'SHOW_POLICY', 'CREATE_POLICY', 'DROP_POLICY', 'ALTER_POLICY', 'SHOW_USER', 'CREATE_USER', 'DROP_USER', 'ALTER_USER', 'SHOW_PRIVILEGE', 'SHOW_META', 'SHOW_SHARD', 'ADD_SHARD', 'DELETE_SHARD', 'REPLACE_SHARD', 'SHOW_HDC_SERVER', 'ADD_HDC_SERVER', 'DELETE_HDC_SERVER', 'LICENSE_UPDATE', 'LICENSE_DUMP', 'GRANT', 'REVOKE', 'SHOW_BACKUP', 'CREATE_BACKUP', 'SHOW_VECTOR_SERVER', 'ADD_VECTOR_SERVER', 'DELETE_VECTOR_SERVER']
Policy (Role)
showPolicy()
Retrieves all policies in the database.
Parameters
config: RequestConfig
(Optional): Request configuration.
Returns
Policy[]
: The list of retrieved policies.
// Retrieves all policies
const policies = await conn.showPolicy();
for (const policy of policies) {
console.log(policy.name);
}
manager
Tester
sales
superADM
getPolicy()
Retrieves a specified policy from the database.
Parameters
policyName: string
: Name of the policy.config: RequestConfig
(Optional): Request configuration.
Returns
Policy
: The retrieved policy.
// Retrieves the policy 'Tester'
const policy = await conn.getPolicy("Tester")
console.log("Graph privileges: ", policy.graphPrivileges);
console.log("System privileges: ", policy.systemPrivileges);
console.log("Property privileges:");
console.log("- Node (Read): ", policy.propertyPrivileges?.node?.read);
console.log("- Node (Write): ", policy.propertyPrivileges?.node?.write);
console.log("- Node (Deny): ", policy.propertyPrivileges?.node?.deny);
console.log("- Edge (Read): ", policy.propertyPrivileges?.edge?.read);
console.log("- Edge (Write): ", policy.propertyPrivileges?.edge?.write);
console.log("- Edge (Deny): ", policy.propertyPrivileges?.edge?.deny);
console.log("Policies: ", policy.policies);
Graph Privileges: Map(2) {
'amz' => [ 'ALGO', 'DROP_FULLTEXT', 'INSERT', 'DELETE', 'UPSERT'],
'StoryGraph' => [ 'UPDATE', 'READ' ]
}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
createPolicy()
Creates a policy in the database.
Parameters
policy: Policy
: The policy to be created; the attributename
is mandatory,systemPrivileges
,graphPrivileges
,propertyPrivilege
, andpolicies
are optional.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Creates a new policy 'operator'
const graphPrivileges = new Map<string, string[]>();
graphPrivileges.set("lcc", ["UPDATE", "INSERT", "DELETE", "UPSERT"]);
const propertyPrivilege = {
node: {
read: [
["miniCircle", "account", "*"],
["miniCircle", "movie", "name"],
],
write: [["lcc", "*", "*"]],
},
edge: { read: [["*", "*", "*"]], deny: [["miniCircle", "*", "*"]] },
};
const policy: Policy = {
name: "operator",
systemPrivileges: ["SHOW_GRAPH", "TRUNCATE"],
graphPrivileges: graphPrivileges,
propertyPrivileges: propertyPrivilege,
policies: ["manager", "sales"],
};
const response = await conn.createPolicy(policy);
console.log(response.status?.message);
SUCCESS
alterPolicy()
Alters the privileges and policies included in a policy. Note that only the mentioned attributes will be updated, others remain unchanged.
Parameters
policy: Policy
: APolicy
object used to set the newsystemPrivileges
,graphPrivileges
,propertyPrivilege
, andpolicies
of an existing policy identified by thename
attribute.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Alters the policy 'operator'
const policy: Policy = {
name: "operator",
systemPrivileges: ["CREATE_GRAPH","SHOW_GRAPH","SHOW_GRAPH","TRUNCATE"],
policies: ["manager"],
};
const response = await conn.alterPolicy(policy);
console.log(response.status?.message);
SUCCESS
dropPolicy()
Drops a specified policy from the database.
Parameters
policyName: string
: Name of the policy.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Drops the policy 'operator'
const response = await conn.dropPolicy("operator");
console.log(response.status?.message);
SUCCESS
User
showUser()
Retrieves all database users.
Parameters
config: RequestConfig
(Optional): Request configuration.
Returns
User[]
: The list of retrieved users.
// Retrieves all database users
const users = await conn.showUser();
for(const user of users){
console.log(user.username)
}
johndoe
root
admin
getUser()
Retrieves a specified database user.
Parameters
username: string
: Username.config: RequestConfig
(Optional): Request configuration.
Returns
User
: The retrieved user.
// Retrieves the database user 'johndoe'
const user = await conn.getUser("root");
console.log("CreatedTime: ", user.createdTime);
console.log("Graph privileges: ", user.graphPrivileges);
console.log("System privileges: ", user.systemPrivileges);
console.log("Property privileges:");
console.log("- Node (Read): ", user.propertyPrivileges?.node?.read);
console.log("- Node (Write): ", user.propertyPrivileges?.node?.write);
console.log("- Node (Deny): ", user.propertyPrivileges?.node?.deny);
console.log("- Edge (Read): ", user.propertyPrivileges?.edge?.read);
console.log("- Edge (Write): ", user.propertyPrivileges?.edge?.write);
console.log("- Edge (Deny): ", user.propertyPrivileges?.edge?.deny);
console.log("Policies: ", user.policies);
Created Time: 2025-04-02 11:08:38
Graph Privileges: {'amz': ['ALGO', 'INSERT', 'DELETE', 'UPSERT'], 'StoryGraph': ['UPDATE', 'READ']}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
createUser()
Creates a database user.
Parameters
user: User
: The user to be created; the attributesusername
andpassword
are mandatory,systemPrivileges
,graphPrivileges
,propertyPrivilege
, andpolicies
are optional.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Creates a new user 'user01'
const graphPrivileges = new Map<string, string[]>();
graphPrivileges.set("lcc", ["UPDATE", "INSERT", "DELETE", "UPSERT"]);
const propertyPrivilege = {
node: {
read: [
["miniCircle", "account", "*"],
["miniCircle", "movie", "name"],
],
write: [["lcc", "*", "*"]],
},
edge: { read: [["*", "*", "*"]], deny: [["miniCircle", "*", "*"]] },
};
const user : User ={
username: "user01",
password: "U7MRDBFXd2Ab",
systemPrivileges:["CREATE_GRAPH","SHOW_GRAPH","SHOW_GRAPH","TRUNCATE"],
graphPrivileges:graphPrivileges,
propertyPrivileges: propertyPrivilege,
policies:["manager", "sales"],
}
const response = await conn.createUser(user);
console.log(response.status?.message)
SUCCESS
alterUser()
Alters the password, privileges and policies of a user. Note that only the mentioned attributes will be updated, others remain unchanged.
Parameters
user: User
: AUser
object used to set the newpassword
,systemPrivileges
,graphPrivileges
,propertyPrivilege
, andpolicies
of an existing user identified by theusername
attribute.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Alters the user 'user01'
const user: User = {
username: "user01",
systemPrivileges: ["CREATE_GRAPH", "SHOW_GRAPH", "SHOW_GRAPH", "TRUNCATE"],
policies: ["manager"],
};
const response = await conn.alterUser(user);
console.log(response.status?.message);
SUCCESS
dropUser()
Drops a specified database user.
Parameters
username: string
: Username.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Drops the user 'user01'
const response = await conn.dropUser("user01");
console.log(response.status?.message);
SUCCESS
Full Example
import { UltipaDriver } from "@ultipa-graph/ultipa-driver";
import { ULTIPA } from "@ultipa-graph/ultipa-driver/dist/types";
import { Policy } from "@ultipa-graph/ultipa-driver/dist/types/types";
let sdkUsage = async () => {
// URI example: ultipaConfig.hosts: ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
const ultipaConfig: ULTIPA.UltipaConfig = {
hosts: ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"],
username: "<username>",
password: "<password>"
};
const conn = new UltipaDriver(ultipaConfig);
const isSuccess = await conn.test();
console.log(`Connection succeeds: ${isSuccess}`);
// Creates a new policy 'operator'
const graphPrivileges = new Map<string, string[]>();
graphPrivileges.set("lcc", ["UPDATE", "INSERT", "DELETE", "UPSERT"]);
const propertyPrivilege = {
node: {
read: [
["miniCircle", "account", "*"],
["miniCircle", "movie", "name"],
],
write: [["lcc", "*", "*"]],
},
edge: { read: [["*", "*", "*"]], deny: [["miniCircle", "*", "*"]] },
};
const policy: Policy = {
name: "operator",
systemPrivileges: ["SHOW_GRAPH", "TRUNCATE"],
graphPrivileges: graphPrivileges,
propertyPrivileges: propertyPrivilege,
policies: ["manager", "sales"],
};
const response = await conn.createPolicy(policy);
console.log(response.status?.message);
};
sdkUsage().catch(console.error);