UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.2

114 lines 4.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PolicyExtra = void 0; const connection_base_1 = require("./connection.base"); const utils_1 = require("../../utils"); const types_extra_1 = require("../../types/types.extra"); const { CommandList } = utils_1.UQLMAKER; class PolicyExtra extends connection_base_1.ConnectionBase { /** * Retrieves all policies from the instance. A policy includes system privileges, graph privileges, property privileges and other policies. */ async showPolicy(config) { let command = CommandList.showPolicy; let uqlMaker = new utils_1.UQLMAKER(command, config); let res = await this.uql(uqlMaker.toString(), config); return res.items[types_extra_1.ResponseTableName.POLICY]?.asPolicies(); } /** * Retrieves a policy from the instance by its name. */ async getPolicy(policyName, config) { let command = CommandList.getPolicy; let uqlMaker = new utils_1.UQLMAKER(command, config, policyName); let res = await this.uql(uqlMaker.toString(), config); return res.items[types_extra_1.ResponseTableName.POLICY]?.asPolicies().find(v => v.name == policyName); } /** * Creates a policy in the instance. */ async createPolicy(policy, config) { let command = CommandList.createPolicy; let uqlMaker = new utils_1.UQLMAKER(command, config, [policy.name, policy?.graphPrivileges ? Object.fromEntries(policy?.graphPrivileges) : {}, policy.systemPrivileges || [], policy.policies || [], policy.propertyPrivileges || {}]); return this.uql(uqlMaker.toString(), config); } /** * Alters the system privileges, graph privileges, property privileges and policies of one existing policy in the instance by its name. */ async alterPolicy(policy, config) { let command = CommandList.alterPolicy; let uqlMaker = new utils_1.UQLMAKER(command, config, policy.name); let set = {}; if (policy?.graphPrivileges) { set.graph_privileges = policy?.graphPrivileges ? Object.fromEntries(policy?.graphPrivileges) : {}; } if (policy?.systemPrivileges) { set.system_privileges = policy.systemPrivileges; } if (policy?.policies) { set.policies = policy.policies; } if (policy?.propertyPrivileges) { set.property_privileges = policy.propertyPrivileges; } uqlMaker.addParam("set", set); return this.uql(uqlMaker.toString(), config); } /** * Drops one policy from the instance by its name. */ async dropPolicy(policyName, config) { let command = CommandList.dropPolicy; let uqlMaker = new utils_1.UQLMAKER(command, config, policyName); return this.uql(uqlMaker.toString(), config); } /** * Grant user policy */ async grantPolicy(userName, graphPrivileges, systemPrivileges, policies, PropertyPrivilege, config) { let command = CommandList.grantUser; let uqlMaker = new utils_1.UQLMAKER(command, config, userName); let set = {}; if (graphPrivileges) { graphPrivileges ? Object.fromEntries(graphPrivileges) : {}; } if (systemPrivileges) { set.system_privileges = systemPrivileges; } if (policies) { set.policies = policies; } if (PropertyPrivilege) { set.property_privileges = PropertyPrivilege; } uqlMaker.addParam("params", set); return this.uql(uqlMaker.toString(), config); } /** * Revoke user policy List */ async revokePolicy(userName, graphPrivileges, systemPrivileges, policies, PropertyPrivilege, config) { let command = CommandList.revokeUser; let uqlMaker = new utils_1.UQLMAKER(command, config, userName); let set = {}; if (graphPrivileges) { set.graph_privileges = graphPrivileges ? Object.fromEntries(graphPrivileges) : {}; } if (systemPrivileges) { set.system_privileges = systemPrivileges; } if (policies) { set.policies = policies; } if (PropertyPrivilege) { set.property_privileges = PropertyPrivilege; } uqlMaker.addParam("params", set); return this.uql(uqlMaker.toString(), config); } } exports.PolicyExtra = PolicyExtra; //# sourceMappingURL=policy.extra.js.map