@ultipa-graph/ultipa-driver
Version:
NodeJS SDK for ultipa-server 5.2
91 lines • 3.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserExtra = void 0;
const connection_base_1 = require("./connection.base");
const utils_1 = require("../../utils");
const { CommandList } = utils_1.UQLMAKER;
class UserExtra extends connection_base_1.ConnectionBase {
/**
* Retrieves all database users from the instance.
*/
async showUser(config) {
let command = CommandList.showUser;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
return res.items["_user"]?.asUsers() || [];
}
/**
* Retrieves a database user from the instance by its username.
*/
async getUser(username, config) {
let command = CommandList.getUser;
let uqlMaker = new utils_1.UQLMAKER(command, config, username);
let res = await this.showUser();
return res.find((item) => item.username === username);
}
/**
* Gets the current user's information.
*/
async getSelfInfo(config) {
let command = CommandList.getSelfInfo;
let uqlMaker = new utils_1.UQLMAKER(command, config);
let res = await this.uql(uqlMaker.toString(), config);
return res.items["_user"].asUsers();
}
/**
* Creates a database user in the instance.
*/
async createUser(user, config) {
let command = CommandList.createUser;
//, Object.fromEntries(user.graphPrivileges), user.systemPrivileges, user.propertyPrivileges
let req = {
graph_privileges: {},
system_privileges: user.systemPrivileges || [],
property_privileges: user.propertyPrivileges || {},
policies: user.policies || [],
};
if (user?.graphPrivileges) {
req.graph_privileges = Object.fromEntries(user?.graphPrivileges) || {};
}
;
let params = [user.username, user.password];
let uqlMaker = new utils_1.UQLMAKER(command, config, params);
uqlMaker.addParam("params", req);
return this.uql(uqlMaker.toString(), config);
}
/**
* Drops one database user from the instance by its username.
*/
async dropUser(username, config) {
let command = CommandList.dropUser;
let uqlMaker = new utils_1.UQLMAKER(command, config, username);
return this.uql(uqlMaker.toString(), config);
}
/**
* Alters the password, system privileges, graph privileges, property privileges and policies of one existing database user in the instance by its username.
*/
async alterUser(user, config) {
let command = CommandList.alterUser;
let uqlMaker = new utils_1.UQLMAKER(command, config, user.username);
let set = {};
if (user.password) {
set.password = user.password;
}
if (user.systemPrivileges) {
set.system_privileges = user.systemPrivileges;
}
if (user.graphPrivileges) {
set.graph_privileges = Object.fromEntries(user?.graphPrivileges);
}
if (user.propertyPrivileges) {
set.property_privileges = user.propertyPrivileges;
}
if (user.policies) {
set.policies = user.policies;
}
uqlMaker.addParam("set", set);
return this.uql(uqlMaker.toString(), config);
}
}
exports.UserExtra = UserExtra;
//# sourceMappingURL=user.extra.js.map