UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.2

190 lines 8.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyExtra = void 0; const connection_base_1 = require("./connection.base"); const types_1 = require("../../types/types"); const utils_1 = require("../../utils"); const { CommandList, SchemaStringWithDefault } = utils_1.UQLMAKER; class PropertyExtra extends connection_base_1.ConnectionBase { /** * Loads one custom property of nodes or edges to the computing engine for query acceleration. */ async lte(dbType, propertyName, schemaName, config) { let command = dbType === types_1.DBType.DBNODE ? CommandList.lteNode : CommandList.lteEdge; let commandParams = SchemaStringWithDefault(schemaName, propertyName); let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams); return this.uqlJobResponse(uqlMaker, config); } /** * Unloads one custom property of nodes or edges from the computing engine to save the memory. */ async ufe(dbType, propertyName, schemaName, config) { let command = dbType === types_1.DBType.DBNODE ? CommandList.ufeNode : CommandList.ufeEdge; let commandParams = SchemaStringWithDefault(schemaName, propertyName); let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams); return this.uql(uqlMaker.toString(), config); } /** * Retrieves custom properties of nodes or edges from the current graphset.if have dbType param,return List<property>.if not,return AllProperties */ async showProperty(dbType, schemaName, config) { let command = CommandList.showProperty; let commandP = null; if (dbType !== undefined) { command = dbType === types_1.DBType.DBNODE ? CommandList.showNodeProperty : CommandList.showEdgeProperty; if (schemaName) { commandP = SchemaStringWithDefault(schemaName); } } let uqlMaker = new utils_1.UQLMAKER(command, config, commandP); let res = await this.uql(uqlMaker.toString(), config); let nodeProperty = res.aliases.find(a => a.name === "_nodeProperty") ? res.items["_nodeProperty"].asProperties() : []; let edgeProperty = res.aliases.find(a => a.name === "_edgeProperty") ? res.items["_edgeProperty"].asProperties() : []; return { nodeProperties: nodeProperty || [], edgeProperties: edgeProperty || [], }; } /** * Retrieves custom properties of nodes from the current graphset. */ async showNodeProperty(schemaName, config) { let command = CommandList.showNodeProperty; let commandP = SchemaStringWithDefault(schemaName); let uqlMaker = new utils_1.UQLMAKER(command, config, commandP); let res = await this.uql(uqlMaker.toString(), config); return res.items["_nodeProperty"].asProperties(); } /** * Retrieves custom properties of edges from the current graphset. */ async showEdgeProperty(schemaName, config) { let command = CommandList.showEdgeProperty; let commandP = SchemaStringWithDefault(schemaName); let uqlMaker = new utils_1.UQLMAKER(command, config, commandP); let res = await this.uql(uqlMaker.toString(), config); return res.items["_edgeProperty"].asProperties(); } /** * Retrieves a custom property of nodes or edges from the current graphset. * @param dbType: DBType * @param schemaName: String * @param propertyName: String * @param config: RequestConfig */ async getProperty(dbType, schemaName, propertyName, config) { let listProperty = await this.showProperty(dbType, schemaName, config); let properties = dbType === types_1.DBType.DBNODE ? listProperty.nodeProperties : listProperty.edgeProperties; let propertyItem = properties.find((property) => property.name === propertyName); // if (propertyItem == undefined) { // throw new Error(`Property ${propertyName} not found in ${DBType[dbType]} ${schemaName}`) // } return propertyItem; } /** * Retrieves a custom property of nodes from the current graphset. */ async getNodeProperty(schemaName, propertyName, config) { return this.getProperty(types_1.DBType.DBNODE, schemaName, propertyName, config); } /** * Retrieves a custom property of edges from the current graphset. */ async getEdgeProperty(schemaName, propertyName, config) { return this.getProperty(types_1.DBType.DBEDGE, schemaName, propertyName, config); } /** * Checks if a specified node or edge has a certain property * @param dbType * @param schemaName * @param propertyName * @param config * @returns * @private */ async hasProperty(dbType, schemaName, propertyName, config) { let res; dbType === types_1.DBType.DBNODE ? res = await this.getNodeProperty(schemaName, propertyName, config) : res = await this.getEdgeProperty(schemaName, propertyName, config); return res != null; } /** * Creates a new property for a node or edge schema in the current graphset. */ async createProperty(dbType, property, config) { try { let command = dbType === types_1.DBType.DBNODE ? CommandList.createNodeProperty : CommandList.createEdgeProperty; let p_type = property.type ? property.type : types_1.UltipaPropertyType.STRING; let commandParams = [ SchemaStringWithDefault(property?.schema), utils_1.UQLMAKER.ForceString(property.name), utils_1.PropertyUtils.GetPropertyTypeDesc(p_type, property.subType, property.decimalExtra).toLowerCase(), property.description || "", ]; let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams); return this.uql(uqlMaker.toString(), config); } catch (error) { return utils_1.FormatResponse.catchUltipaUqlError(error); } } /** * Creates a new property for a node or edge schema in the current graphset, handling cases where the given property name already exists by ignoring the error. */ async createPropertyIfNotExist(dbType, property, config) { let isPropertyExist = await this.hasProperty(dbType, property.schema, property.name, config); if (isPropertyExist) { return { exist: true, response: { status: utils_1.FormatResponse.successStatus(), statistics: utils_1.FormatResponse.statisticsSum(), } }; } let res = await this.createProperty(dbType, property, config); return { exist: false, response: res }; } /** * Drops one custom property from the current graphset by its name and the associated schema. */ async dropProperty(dbType, property, config) { let command = dbType === types_1.DBType.DBNODE ? CommandList.dropNodeProperty : CommandList.dropEdgeProperty; let commandParams = SchemaStringWithDefault(property.schema, property.name); let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams); return this.uql(uqlMaker.toString(), config); } /** * Alters the name and description of one existing custom property in the current graphset by its name. */ async alterProperty(dbType, originProp, newProp, config) { let command = dbType === types_1.DBType.DBNODE ? CommandList.updateNodeProperty : CommandList.updateEdgeProperty; let commandParams = SchemaStringWithDefault(originProp.schema, originProp.name); let uqlMaker = new utils_1.UQLMAKER(command, config, commandParams); let set = {}; if (newProp.name) { set.name = newProp.name; } if ((0, utils_1.isNotNullString)(newProp.description)) { set.description = newProp.description; } uqlMaker.addParam("set", set); return this.uql(uqlMaker.toString(), config); } } exports.PropertyExtra = PropertyExtra; //# sourceMappingURL=property.extra.js.map