UNPKG

@ultipa-graph/ultipa-node-sdk

Version:

NodeJS SDK for ultipa-server 4.0

372 lines 15.2 kB
"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 __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyExtra = void 0; const connection_base_1 = require("./connection.base"); const types_1 = require("../../types"); const utils_1 = require("../../utils"); const lodash_1 = __importDefault(require("lodash")); const { CommandList, SchemaStringWithDefault } = utils_1.UQLMAKER; class PropertyExtra extends connection_base_1.ConnectionBase { /** * 得到点边的属性 */ showAllProperty(commonReq) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { let command = CommandList.showProperty; let uqlMaker = new utils_1.UQLMAKER(command, commonReq); let res = yield connection_base_1.ConnectionBase.UqlListSimpleAuto(this, uqlMaker); let { data } = res, others = __rest(res, ["data"]); return Object.assign(Object.assign({}, others), { data: { edge: ((_a = data.find((d) => d.name == "_edgeProperty")) === null || _a === void 0 ? void 0 : _a.values) || [], node: ((_b = data.find((d) => d.name == "_nodeProperty")) === null || _b === void 0 ? void 0 : _b.values) || [], } }); }); } /** * 得到点或者边的属性 */ // async showProperty( // req?: RequestType.ListProperty, // commonReq?: RequestType.RequestConfig // ) showProperty(dbType, schemaName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let command = dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.showNodeProperty : CommandList.showEdgeProperty; let commandP = null; if (schemaName) { commandP = SchemaStringWithDefault(schemaName); } let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandP); return connection_base_1.ConnectionBase.UqlListSimple(this, uqlMaker); }); } /** * 得到点的属性 */ showNodeProperty(schemaName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { return this.showProperty(types_1.ULTIPA.DBType.DBNODE, schemaName, requestConfig); }); } /** * 得到边的属性 */ showEdgeProperty(schemaName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { return this.showProperty(types_1.ULTIPA.DBType.DBEDGE, schemaName, requestConfig); }); } /** * 获取单个属性 * @param dbType * @param schemaName * @param propertyName * @param requestConfig */ getSingleProperty(dbType, schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let command = dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.showNodeProperty : CommandList.showEdgeProperty; let commandP = null; if (schemaName) { commandP = SchemaStringWithDefault(schemaName); } let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandP); let listProperty = yield connection_base_1.ConnectionBase.UqlListSimple(this, uqlMaker); let targetProperty = listProperty.data.find((property) => { property.name == propertyName; }); return Object.assign(Object.assign({}, listProperty), { data: targetProperty }); }); } /** * 获取属性 * @param dbType: DBType * @param schemaName: String * @param propertyName: String * @param requestConfig: RequestConfig */ // async getProperty(req: RequestType.GetProperty, commonReq?: RequestType.RequestConfig) { getProperty(dbType, schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = { name: propertyName, dbType, schema: schemaName }; let listProperty = yield this.showProperty(req.dbType, req.schema, requestConfig); // if (listProperty.status.code !== ULTIPA.Code.SUCCESS) // return listProperty; let propertyItem = listProperty.data.find((property) => property.name === req.name); return Object.assign(Object.assign({}, listProperty), { data: propertyItem || null }); }); } /** * 获取点某个属性 */ // async getNodeProperty(req: RequestType.GetNodeEdgeProperty, commonReq?: RequestType.RequestConfig) { getNodeProperty(schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { return this.getProperty(types_1.ULTIPA.DBType.DBNODE, schemaName, propertyName, requestConfig); }); } /** * 获取边某个属性 * @param req * @param commonReq */ getEdgeProperty(schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { return this.getProperty(types_1.ULTIPA.DBType.DBEDGE, schemaName, propertyName, requestConfig); }); } /** * 属性是否存在 * @param req * @param commonReq * @private */ hasProperty(request, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let res; request.dbType == types_1.ULTIPA.DBType.DBNODE ? res = yield this.getNodeProperty(request.schema, request.name, requestConfig) : res = yield this.getEdgeProperty(request.schema, request.name, requestConfig); return { status: utils_1.FormatResponse.successStatus(), statistics: utils_1.FormatResponse.statisticsSum(), data: !lodash_1.default.isEmpty(res.data) }; }); } /** * 创建点或者边属性 */ // async createProperty( // req: RequestType.CreateProperty, // commonReq?: RequestType.RequestConfig // ) { createProperty(dbType, schemaName, prop, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = Object.assign(Object.assign({}, prop), { dbType, schema: schemaName }); try { let command = req.dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.createNodeProperty : CommandList.createEdgeProperty; let p_type = req.type ? req.type : types_1.ULTIPA.PropertyType.PROPERTY_STRING; let commandParams = [ SchemaStringWithDefault(req.schema), utils_1.UQLMAKER.ForceString(req.name), utils_1.PropertyUtils.GetPropertyTypeDesc(p_type, req.subTypes, req.extra), req.description || "", ]; let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams); return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker); } catch (error) { return utils_1.FormatResponse.catchUltipaUqlError(error); } }); } // /** // * 创建点属性 // */ // async createNodeProperty( // req: RequestType.CreateProperty, // commonReq?: RequestType.RequestConfig // ) { // return this.createProperty({ ...req, dbType: ULTIPA.DBType.DBNODE }, commonReq); // } // /** // * 创建边属性 // */ // async createEdgeProperty( // req: RequestType.CreateProperty, // commonReq?: RequestType.RequestConfig // ) { // return this.createProperty({ ...req, dbType: ULTIPA.DBType.DBEDGE }, commonReq); // } /** * 不存在,再创建属性 * @param req * @param commonReq */ createPropertyIfNotExist(dbType, schemaName, prop, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = Object.assign(Object.assign({}, prop), { dbType, schema: schemaName }); let isPropertyExist = yield this.hasProperty(req, requestConfig); if (isPropertyExist.data) { return { status: utils_1.FormatResponse.successStatus(), statistics: utils_1.FormatResponse.statisticsSum(), data: true, }; } let res = yield this.createProperty(dbType, schemaName, prop, requestConfig); return Object.assign(Object.assign({}, res), { data: false }); }); } /** * 删除点或者边属性 */ dropProperty(dbType, schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = { name: propertyName, dbType, schema: schemaName }; let command = req.dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.dropNodeProperty : CommandList.dropEdgeProperty; let commandParams = SchemaStringWithDefault(req.schema, req.name); let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams); return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker); }); } // /** // * 删除点属性 // */ // async deleteNodeProperty( // req: RequestType.DeletePropertyBase, // commonReq?: RequestType.RequestConfig // ) { // return this.dropProperty({ ...req, dbType: ULTIPA.DBType.DBNODE }, commonReq); // } // /** // * 删除边属性 // */ // async deleteEdgeProperty( // req: RequestType.DeletePropertyBase, // commonReq?: RequestType.RequestConfig // ) { // return this.dropProperty({ ...req, dbType: ULTIPA.DBType.DBEDGE }, commonReq); // } /** * 更新点或者边属性 */ alterProperty(dbType, property, newProperty, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = { dbType, schema: property.schema, name: property.name, newName: newProperty.name, newDesc: newProperty.description }; let command = req.dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.updateNodeProperty : CommandList.updateEdgeProperty; let commandParams = SchemaStringWithDefault(req.schema, req.name); let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams); let set = {}; if (req.newName) { set.name = req.newName; } if ((0, utils_1.isNotNullString)(req.newDesc)) { set.description = req.newDesc; } uqlMaker.addParam("set", set); return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker); }); } // /** // * 更新点属性 // */ // async updateNodeProperty( // req: RequestType.UpdatePropertyBase, // commonReq?: RequestType.RequestConfig // ) { // return this.alterProperty({ ...req, dbType: ULTIPA.DBType.DBNODE }, commonReq); // } // /** // * 更新边属性 // */ // async updateEdgeProperty( // req: RequestType.UpdatePropertyBase, // commonReq?: RequestType.RequestConfig // ) { // return this.alterProperty({ ...req, dbType: ULTIPA.DBType.DBEDGE }, commonReq); // } /** * 加载点或边属性到引擎(LTE) */ // async lte( // req: RequestType.LoadToEngin, // commonReq?: RequestType.RequestConfig // ) { lte(dbType, schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = { dbType: dbType, schema: schemaName, name: propertyName, }; let command = req.dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.lteNode : CommandList.lteEdge; let commandParams = SchemaStringWithDefault(req.schema, req.name); let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams); return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker); }); } // /** // * 加载点属性到引擎(LTE) // */ // async LoadToEngineNode( // req: RequestType.LoadToEnginBase, // commonReq?: RequestType.RequestConfig // ) { // return this.lte({ ...req, dbType: ULTIPA.DBType.DBNODE }, commonReq); // } // /** // * 加载边属性到引擎(LTE) // */ // async LoadToEngineEdge( // req: RequestType.LoadToEngin, // commonReq?: RequestType.RequestConfig // ) { // return this.lte({ ...req, dbType: ULTIPA.DBType.DBEDGE }, commonReq); // } /** * 卸载引擎的点或边属性(UFE) */ ufe(dbType, schemaName, propertyName, requestConfig) { return __awaiter(this, void 0, void 0, function* () { let req = { dbType: dbType, schema: schemaName, name: propertyName, }; let command = req.dbType === types_1.ULTIPA.DBType.DBNODE ? CommandList.ufeNode : CommandList.ufeEdge; let commandParams = SchemaStringWithDefault(req.schema, req.name); let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams); return connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker); }); } } exports.PropertyExtra = PropertyExtra; //# sourceMappingURL=property.extra.js.map