@ultipa-graph/ultipa-node-sdk
Version:
NodeJS SDK for ultipa-server 4.0
154 lines • 5.94 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphExra = void 0;
const connection_base_1 = require("./connection.base");
const utils_1 = require("../../utils");
const lodash_1 = __importDefault(require("lodash"));
const CommandList = utils_1.UQLMAKER.CommandList;
const KEY_REPLACE = {
"graph": "name"
};
class GraphExra extends connection_base_1.ConnectionBase {
/**
* 查看图集列表
* @deprecated Use `showGraph`
*/
listGraph(commonReq) {
return __awaiter(this, void 0, void 0, function* () {
return this.showGraph(commonReq);
});
}
/**
* 查看图集列表
*/
showGraph(requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.listGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig);
return connection_base_1.ConnectionBase.UqlListSimple(this, uqlMaker, {
keyReplace: KEY_REPLACE
});
});
}
/**
* 获取图集信息
*/
getGraph(graphName, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.getGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, graphName);
return connection_base_1.ConnectionBase.UqlGetSimple(this, uqlMaker, {
keyReplace: KEY_REPLACE
});
});
}
/**
* 图集是否存在
*/
hasGraph(graphName, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let res = yield this.getGraph(graphName, requestConfig);
return Object.assign(Object.assign({}, res), { data: !lodash_1.default.isEmpty(res.data) });
});
}
/**
* 创建图集
*/
createGraph(req, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.createGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, [req.name, req.description || ""]);
return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
});
}
/**
* 创建不存在的图集
* @param req
* @param commonReq
*/
createGraphIfNotExit(graph, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let isGraphExit = yield this.hasGraph(graph.name);
if (isGraphExit.data) {
return {
status: utils_1.FormatResponse.successStatus(),
statistics: utils_1.FormatResponse.statisticsSum(),
data: true,
};
}
let res = yield this.createGraph(graph, requestConfig);
return Object.assign(Object.assign({}, res), { data: false });
});
}
/**
* 删除图集
*/
dropGraph(graphName, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.dropGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, graphName);
return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
});
}
/**
* 更新图集,目前只支持图集名称修改
*/
alterGraph(oldGraph, newGraph, commonReq) {
return __awaiter(this, void 0, void 0, function* () {
let req = {
oldGraphSetName: oldGraph.name,
newGraphSetName: newGraph.name,
newDesc: newGraph.description
};
let command = CommandList.updateGraph;
let uqlMaker = new utils_1.UQLMAKER(command, commonReq, req.oldGraphSetName);
let set = {};
if (req.newGraphSetName) {
set.name = req.newGraphSetName;
}
if ((0, utils_1.isNotNullString)(req.newDesc)) {
set.description = req.newDesc;
}
uqlMaker.addParam("set", set);
return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
});
}
/**
* 挂载图集
* @param graphName
* @param commonReq
*/
mountGraph(graphName, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.mountGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, graphName);
return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
});
}
/**
* 卸载图集
* @param graphName
* @param commonReq
*/
unmountGraph(graphName, requestConfig) {
return __awaiter(this, void 0, void 0, function* () {
let command = CommandList.unmountGraph;
let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, graphName);
return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
});
}
}
exports.GraphExra = GraphExra;
//# sourceMappingURL=graph.extra.js.map