@ultipa-graph/ultipa-driver
Version:
NodeJS SDK for ultipa-server 5.2
1,606 lines • 47.1 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JobResponse = exports.ResponseWithExistCheck = exports.InsertResponse = exports.Response = exports.DataItem = exports.getExplainPlansTreeTopNode = exports.PlanNode = exports.ExplainPlan = exports.Attr = exports.Table = exports.Header = exports.Property = exports.SchemaStats = exports.SchemaStat = exports.Schema = exports.GraphSet = exports.Graph = exports.Path = exports.Edge = exports.Node = exports.Projection = exports.HDCGraph = exports.Process = exports.Job = exports.Privilege = exports.Policy = exports.User = exports.Index = exports.JOB_STATUS = exports.DBType = exports.QueryType = exports.HDCSyncType = exports.PrivilegeLevel = exports.AuthenticateType = exports.ResultType = exports.ErrorCode = exports.Algo = exports.InsertType = exports.UltipaPropertyType = exports.getInsertErrorMessage = exports.InsertErrorMessages = exports.InsertErrorCode = exports.InsertRequestConfig = exports.RequestConfig = exports.UltipaConfig = void 0;
const utils_1 = require("../utils");
const ULTIPA_RPC = __importStar(require("../proto/ultipa_pb"));
let { PropertyType: RRC_PropertyType, ResultType: RRC_ResultType, ErrorCode: RPC_ErrorCode, DBType: RPC_DBType, JOB_STATUS: RPC_JOB_STATUS, FollowerRole: RCP_FollowerRole, ResultType: RPC_ResultType, InsertType: RPC_InsertType, PlanNode: RPC_PlanNode, QueryType: RPC_QueryType } = ULTIPA_RPC;
/**
* Ultipa Configuration is the basic configuration that used for establishing the connections.
*/
class UltipaConfig {
/**
* List of host addresses (IPs or URLs)
* - Supports IPv4 and IPv6 addresses
* - Supports URLs (if prefixed with https://, uses secure connection)
* - Required
*/
hosts;
/** Username for authentication (Required) */
username;
/** Password for authentication (Required) */
password;
/** Default graph to interact with (Optional) */
defaultGraph;
/** Path string to CRT file, used for SSL connections. */
crt = undefined;
/**
* Password encryption method
* @default "MD5"
*/
passwordEncrypt = "MD5";
/**
* Request timeout in seconds
* @default 2147483647
*/
timeout = 2147483647;
/**
* Heartbeat interval in milliseconds
* Set to 0 to disable heartbeat
* Used for keeping connection alive
* @default 0
*/
heartbeat = 0;
/**
* Maximum receive size in megabytes
* @default 32
*/
maxRecvSize = 32;
}
exports.UltipaConfig = UltipaConfig;
/**
* Configuration for each request, can be null
*/
class RequestConfig {
/**
* specify graphName, if null will use defaultGraph of UltipaConfiguration
*/
graph;
/**
* Operation timeout in seconds
*/
timeout;
/**
* Specify the host to execute the request
* */
host;
/**
* request,thread num
*/
thread;
/**
* name of time zone,
* default: current time zone.
* e.g. Aisa/Shanghai
*/
timezone;
/**
* hour elapse from UTC
* When both `timezone` and `timezoneOffset` are provided, `timezoneOffset` takes precedence.
* Unit: hour. Example:” +08:30”,”-05:00”,“+2”,“-0300”
*/
timezoneOffset;
/**
* If true the queryText will be logged.
*/
logQueryText = false;
/**
* If true the request info will be logged.
*/
withRequestInfo = false;
}
exports.RequestConfig = RequestConfig;
/**
* configuration for insert request. extends RequestConfig,have all RequestConfig property
*/
class InsertRequestConfig extends RequestConfig {
/**
* NORMAL,
* OVERWRITE,
* UPSERT
*/
insertType = InsertType.NORMAL;
/**
* Return data or not when insert/delete batch. true - not return data, false - return data.
*/
silent = true;
}
exports.InsertRequestConfig = InsertRequestConfig;
/**
* The insert error code from server.
*/
var InsertErrorCode;
(function (InsertErrorCode) {
InsertErrorCode[InsertErrorCode["ID_NOT_MATCH_UUID"] = 10001] = "ID_NOT_MATCH_UUID";
InsertErrorCode[InsertErrorCode["ID_UUID_NOT_MATCH_SCHEMA"] = 10002] = "ID_UUID_NOT_MATCH_SCHEMA";
InsertErrorCode[InsertErrorCode["FROM_ID_NOT_EXISTED"] = 10003] = "FROM_ID_NOT_EXISTED";
InsertErrorCode[InsertErrorCode["TO_ID_NOT_EXISTED"] = 10004] = "TO_ID_NOT_EXISTED";
InsertErrorCode[InsertErrorCode["ID_LEN"] = 10005] = "ID_LEN";
InsertErrorCode[InsertErrorCode["NOT_NULL"] = 10006] = "NOT_NULL";
InsertErrorCode[InsertErrorCode["UNIQUCHECK"] = 10007] = "UNIQUCHECK";
InsertErrorCode[InsertErrorCode["ID_EMPTY"] = 10008] = "ID_EMPTY";
InsertErrorCode[InsertErrorCode["FROM_ID_EMPTY"] = 10009] = "FROM_ID_EMPTY";
InsertErrorCode[InsertErrorCode["TO_ID_EMPTY"] = 10010] = "TO_ID_EMPTY";
InsertErrorCode[InsertErrorCode["DUPLICATE_ID"] = 10011] = "DUPLICATE_ID";
InsertErrorCode[InsertErrorCode["KEY_CONSTRAINT_VIOLATED"] = 10012] = "KEY_CONSTRAINT_VIOLATED";
InsertErrorCode[InsertErrorCode["INVALID_FORMAT"] = 10013] = "INVALID_FORMAT";
InsertErrorCode[InsertErrorCode["OK_BUT_ID_EXISTED"] = 11001] = "OK_BUT_ID_EXISTED";
InsertErrorCode[InsertErrorCode["OTHERS"] = 19999] = "OTHERS";
})(InsertErrorCode = exports.InsertErrorCode || (exports.InsertErrorCode = {}));
exports.InsertErrorMessages = {
[InsertErrorCode.ID_NOT_MATCH_UUID]: "id and uuid do not match",
[InsertErrorCode.ID_UUID_NOT_MATCH_SCHEMA]: "id and schema do not match",
[InsertErrorCode.FROM_ID_NOT_EXISTED]: "fromId does not exist",
[InsertErrorCode.TO_ID_NOT_EXISTED]: "toId does not exist",
[InsertErrorCode.ID_LEN]: "length of id exceeds the maximum length (128 bytes)",
[InsertErrorCode.NOT_NULL]: "violation of the NOT NULL constraint",
[InsertErrorCode.UNIQUCHECK]: "violation of the UNIQUE constraint",
[InsertErrorCode.ID_EMPTY]: "id cannot be empty",
[InsertErrorCode.FROM_ID_EMPTY]: "fromId cannot be empty",
[InsertErrorCode.TO_ID_EMPTY]: "toId cannot be empty",
[InsertErrorCode.DUPLICATE_ID]: "duplicated id",
[InsertErrorCode.KEY_CONSTRAINT_VIOLATED]: "violation of the EDGE KEY constraint",
[InsertErrorCode.INVALID_FORMAT]: "invalid format",
[InsertErrorCode.OK_BUT_ID_EXISTED]: "id already exists",
[InsertErrorCode.OTHERS]: "other error"
};
function getInsertErrorMessage(errorCode) {
return exports.InsertErrorMessages[errorCode] || exports.InsertErrorMessages[InsertErrorCode.OTHERS];
}
exports.getInsertErrorMessage = getInsertErrorMessage;
/**
* The schema property type.When create property.Need set property type.
*/
var UltipaPropertyType;
(function (UltipaPropertyType) {
/**
* Ultipa schema id type
*/
UltipaPropertyType[UltipaPropertyType["ID"] = -1] = "ID";
/**
* Ultipa schema uuid type
*/
UltipaPropertyType[UltipaPropertyType["UUID"] = -2] = "UUID";
/**
* Ultipa edge schema from_id type
*/
UltipaPropertyType[UltipaPropertyType["FROM"] = -3] = "FROM";
/**
* Ultipa edge schema to_id type
*/
UltipaPropertyType[UltipaPropertyType["TO"] = -4] = "TO";
/**
* Ultipa edge schema from_uuid type
*/
UltipaPropertyType[UltipaPropertyType["FROM_UUID"] = -5] = "FROM_UUID";
/**
* Ultipa edge schema to_uuid type
*/
UltipaPropertyType[UltipaPropertyType["TO_UUID"] = -6] = "TO_UUID";
/**
* Ignore
*/
UltipaPropertyType[UltipaPropertyType["IGNORE"] = -7] = "IGNORE";
/**
* No type set
*/
UltipaPropertyType[UltipaPropertyType["UNSET"] = 0] = "UNSET";
/**
* Signed 32 integer
*/
UltipaPropertyType[UltipaPropertyType["INT32"] = 1] = "INT32";
/**
* Unsigned 32 integer
*/
UltipaPropertyType[UltipaPropertyType["UINT32"] = 2] = "UINT32";
/**
* Signed 64 integer
*/
UltipaPropertyType[UltipaPropertyType["INT64"] = 3] = "INT64";
/**
* Unsigned 64 integer
*/
UltipaPropertyType[UltipaPropertyType["UINT64"] = 4] = "UINT64";
/**
* Single floating-point number
*/
UltipaPropertyType[UltipaPropertyType["FLOAT"] = 5] = "FLOAT";
/**
* Double-precision floating-point numbers
*/
UltipaPropertyType[UltipaPropertyType["DOUBLE"] = 6] = "DOUBLE";
/**
* A data type that represents a sequence of characters
*/
UltipaPropertyType[UltipaPropertyType["STRING"] = 7] = "STRING";
/**
* Represents a combination of a date and a time
*/
UltipaPropertyType[UltipaPropertyType["DATETIME"] = 8] = "DATETIME";
/**
* A data type that typically represents a specific point in time, often with a high level of precision
*/
UltipaPropertyType[UltipaPropertyType["TIMESTAMP"] = 9] = "TIMESTAMP";
/**
* Used to store large amounts of text data
*/
UltipaPropertyType[UltipaPropertyType["TEXT"] = 10] = "TEXT";
/**
* Stands for Binary Large Object
*/
UltipaPropertyType[UltipaPropertyType["BLOB"] = 11] = "BLOB";
/**
* In the context of databases dealing with spatial data (e.g., in GIS systems)
*/
UltipaPropertyType[UltipaPropertyType["POINT"] = 12] = "POINT";
/**
* Represents a fixed-point number with a specified precision and scale
*/
UltipaPropertyType[UltipaPropertyType["DECIMAL"] = 13] = "DECIMAL";
/**
* A data structure that can hold a collection of elements
*/
UltipaPropertyType[UltipaPropertyType["LIST"] = 14] = "LIST";
/**
* A data structure that stores a collection of unique elements
*/
UltipaPropertyType[UltipaPropertyType["SET"] = 15] = "SET";
/**
* A data structure that stores key-value pairs
*/
UltipaPropertyType[UltipaPropertyType["MAP"] = 16] = "MAP";
/**
* Null type
*/
UltipaPropertyType[UltipaPropertyType["NULL"] = 17] = "NULL";
/**
* Stands for Boolean
*/
UltipaPropertyType[UltipaPropertyType["BOOL"] = 18] = "BOOL";
UltipaPropertyType[UltipaPropertyType["LOCAL_DATETIME"] = 19] = "LOCAL_DATETIME";
UltipaPropertyType[UltipaPropertyType["ZONED_DATETIME"] = 20] = "ZONED_DATETIME";
UltipaPropertyType[UltipaPropertyType["DATE"] = 21] = "DATE";
UltipaPropertyType[UltipaPropertyType["ZONED_TIME"] = 22] = "ZONED_TIME";
UltipaPropertyType[UltipaPropertyType["LOCAL_TIME"] = 23] = "LOCAL_TIME";
UltipaPropertyType[UltipaPropertyType["YEAR_TO_MONTH"] = 24] = "YEAR_TO_MONTH";
UltipaPropertyType[UltipaPropertyType["DAY_TO_SECOND"] = 25] = "DAY_TO_SECOND";
UltipaPropertyType[UltipaPropertyType["JSON"] = 26] = "JSON";
})(UltipaPropertyType = exports.UltipaPropertyType || (exports.UltipaPropertyType = {}));
/**
* The insertion mode.
*/
var InsertType;
(function (InsertType) {
/**
* Insert new data
*/
InsertType[InsertType["NORMAL"] = 0] = "NORMAL";
/**
* The insert overwrite operation first clears the existing data in the target location and then inserts new data
*/
InsertType[InsertType["OVERWRITE"] = 1] = "OVERWRITE";
/**
* If the data record to be inserted already exists in the target location the record will be updated; if it does not exist, a new record will be inserted
*/
InsertType[InsertType["UPSERT"] = 2] = "UPSERT";
})(InsertType = exports.InsertType || (exports.InsertType = {}));
/**
* Algorithm Detail Response Data
*/
class Algo {
/**
* name
*/
name;
/**
* type
*/
type;
/**
* write support type
*/
writeSupportType;
/**
* Whether the algorithm can be rolled back to previous version.
*/
canRollback;
/**
* config context
*/
configContext;
/**
* version
*/
version;
/**
* algo params
*/
params;
/**
* algo description
*/
description;
}
exports.Algo = Algo;
/**
* TODO delete Code
*/
var ErrorCode;
(function (ErrorCode) {
ErrorCode[ErrorCode["SUCCESS"] = RPC_ErrorCode.SUCCESS] = "SUCCESS";
ErrorCode[ErrorCode["FAILED"] = RPC_ErrorCode.FAILED] = "FAILED";
ErrorCode[ErrorCode["PARAM_ERROR"] = RPC_ErrorCode.PARAM_ERROR] = "PARAM_ERROR";
ErrorCode[ErrorCode["BASE_DB_ERROR"] = RPC_ErrorCode.BASE_DB_ERROR] = "BASE_DB_ERROR";
ErrorCode[ErrorCode["ENGINE_ERROR"] = RPC_ErrorCode.ENGINE_ERROR] = "ENGINE_ERROR";
ErrorCode[ErrorCode["SYSTEM_ERROR"] = RPC_ErrorCode.SYSTEM_ERROR] = "SYSTEM_ERROR";
ErrorCode[ErrorCode["SYNTAX_ERROR"] = RPC_ErrorCode.SYNTAX_ERROR] = "SYNTAX_ERROR";
ErrorCode[ErrorCode["PERMISSION_DENIED"] = RPC_ErrorCode.PERMISSION_DENIED] = "PERMISSION_DENIED";
ErrorCode[ErrorCode["DUPLICATE_ID"] = RPC_ErrorCode.DUPLICATE_ID] = "DUPLICATE_ID";
ErrorCode[ErrorCode["RAFT_REDIRECT"] = RPC_ErrorCode.RAFT_REDIRECT] = "RAFT_REDIRECT";
ErrorCode[ErrorCode["RAFT_LEADER_NOT_YET_ELECTED"] = RPC_ErrorCode.RAFT_LEADER_NOT_YET_ELECTED] = "RAFT_LEADER_NOT_YET_ELECTED";
ErrorCode[ErrorCode["RAFT_LOG_ERROR"] = RPC_ErrorCode.RAFT_LOG_ERROR] = "RAFT_LOG_ERROR";
ErrorCode[ErrorCode["NOT_RAFT_MODE"] = RPC_ErrorCode.NOT_RAFT_MODE] = "NOT_RAFT_MODE";
ErrorCode[ErrorCode["RAFT_NO_AVAILABLE_FOLLOWERS"] = RPC_ErrorCode.RAFT_NO_AVAILABLE_FOLLOWERS] = "RAFT_NO_AVAILABLE_FOLLOWERS";
ErrorCode[ErrorCode["RAFT_NO_AVAILABLE_ALGO_SERVERS"] = RPC_ErrorCode.RAFT_NO_AVAILABLE_ALGO_SERVERS] = "RAFT_NO_AVAILABLE_ALGO_SERVERS";
ErrorCode[ErrorCode["UNKNOWN_ERROR"] = 1000] = "UNKNOWN_ERROR";
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
var ResultType;
(function (ResultType) {
ResultType[ResultType["RESULT_TYPE_UNSET"] = RPC_ResultType.RESULT_TYPE_UNSET] = "RESULT_TYPE_UNSET";
ResultType[ResultType["RESULT_TYPE_PATH"] = RPC_ResultType.RESULT_TYPE_PATH] = "RESULT_TYPE_PATH";
ResultType[ResultType["RESULT_TYPE_NODE"] = RPC_ResultType.RESULT_TYPE_NODE] = "RESULT_TYPE_NODE";
ResultType[ResultType["RESULT_TYPE_EDGE"] = RPC_ResultType.RESULT_TYPE_EDGE] = "RESULT_TYPE_EDGE";
ResultType[ResultType["RESULT_TYPE_ATTR"] = RPC_ResultType.RESULT_TYPE_ATTR] = "RESULT_TYPE_ATTR";
ResultType[ResultType["RESULT_TYPE_TABLE"] = RPC_ResultType.RESULT_TYPE_TABLE] = "RESULT_TYPE_TABLE";
})(ResultType = exports.ResultType || (exports.ResultType = {}));
var AuthenticateType;
(function (AuthenticateType) {
AuthenticateType[AuthenticateType["PERMISSION_TYPE_UNSET"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_UNSET] = "PERMISSION_TYPE_UNSET";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_UQL"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_UQL] = "PERMISSION_TYPE_UQL";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_GQL"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_GQL] = "PERMISSION_TYPE_GQL";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_INSERTNODES"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_INSERTNODES] = "PERMISSION_TYPE_INSERTNODES";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_INSERTEDGES"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_INSERTEDGES] = "PERMISSION_TYPE_INSERTEDGES";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_EXPORT"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_EXPORT] = "PERMISSION_TYPE_EXPORT";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_DOWNLOADFILE"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_DOWNLOADFILE] = "PERMISSION_TYPE_DOWNLOADFILE";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_INSTALLALGO"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_INSTALLALGO] = "PERMISSION_TYPE_INSTALLALGO";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_UNINSTALLALGO"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_UNINSTALLALGO] = "PERMISSION_TYPE_UNINSTALLALGO";
AuthenticateType[AuthenticateType["PERMISSION_TYPE_ROLLBACKALGO"] = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_ROLLBACKALGO] = "PERMISSION_TYPE_ROLLBACKALGO";
// PERMISSION_TYPE_UPLOADER = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_UPLOADER,
// PERMISSION_TYPE_CREATEGRAPHBYUPLOADER = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_CREATEGRAPHBYUPLOADER,
// PERMISSION_TYPE_INSTALLEXTA = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_INSTALLEXTA,
// PERMISSION_TYPE_UNINSTALLEXTA = ULTIPA_RPC.AuthenticateType.PERMISSION_TYPE_UNINSTALLEXTA,
})(AuthenticateType = exports.AuthenticateType || (exports.AuthenticateType = {}));
/**
* privilege level type
*/
var PrivilegeLevel;
(function (PrivilegeLevel) {
/**
* Graph privilege type
*/
PrivilegeLevel[PrivilegeLevel["GraphLevel"] = 0] = "GraphLevel";
/**
* System privilege type
*/
PrivilegeLevel[PrivilegeLevel["SystemLevel"] = 1] = "SystemLevel";
})(PrivilegeLevel = exports.PrivilegeLevel || (exports.PrivilegeLevel = {}));
/**
* HDC synchronization type.
*/
var HDCSyncType;
(function (HDCSyncType) {
/**
* Static synchronization
*/
HDCSyncType["STATIC"] = "static";
/**
* Asynchronous synchronization
*/
HDCSyncType["ASYNC"] = "async";
/**
* Synchronous synchronization
*/
HDCSyncType["SYNC"] = "sync";
})(HDCSyncType = exports.HDCSyncType || (exports.HDCSyncType = {}));
/** Query type contains UQL,GQL */
var QueryType;
(function (QueryType) {
QueryType[QueryType["QL_UNSET"] = 0] = "QL_UNSET";
QueryType[QueryType["UQL"] = 1] = "UQL";
QueryType[QueryType["GQL"] = 2] = "GQL";
})(QueryType = exports.QueryType || (exports.QueryType = {}));
/**
* The schema type in database.
*/
var DBType;
(function (DBType) {
/**
* Node
*/
DBType[DBType["DBNODE"] = RPC_DBType.DBNODE] = "DBNODE";
/**
* Edge
*/
DBType[DBType["DBEDGE"] = RPC_DBType.DBEDGE] = "DBEDGE";
})(DBType = exports.DBType || (exports.DBType = {}));
/**
* Job status
*/
var JOB_STATUS;
(function (JOB_STATUS) {
JOB_STATUS[JOB_STATUS["JOB_PENDING"] = RPC_JOB_STATUS.JOB_PENDING] = "JOB_PENDING";
JOB_STATUS[JOB_STATUS["JOB_COMPUTING"] = RPC_JOB_STATUS.JOB_COMPUTING] = "JOB_COMPUTING";
JOB_STATUS[JOB_STATUS["JOB_WRITING"] = RPC_JOB_STATUS.JOB_WRITING] = "JOB_WRITING";
JOB_STATUS[JOB_STATUS["JOB_DONE"] = RPC_JOB_STATUS.JOB_DONE] = "JOB_DONE";
JOB_STATUS[JOB_STATUS["JOB_FAILED"] = RPC_JOB_STATUS.JOB_FAILED] = "JOB_FAILED";
JOB_STATUS[JOB_STATUS["JOB_STOPPED"] = RPC_JOB_STATUS.JOB_STOPPED] = "JOB_STOPPED";
})(JOB_STATUS = exports.JOB_STATUS || (exports.JOB_STATUS = {}));
/**
* Property index
*/
class Index {
id;
/**
* Index name
*/
name;
/**
* Index on which properties
*/
properties;
/**
* Index on which scehma
*/
schema;
/**
* Index status
*/
status;
/**
* Index size
*/
size;
/**
* Node index or edge index
*/
dbType;
}
exports.Index = Index;
/**
* User
*/
class User {
/**
* username
*/
username;
/**
* pasword
*/
password;
/**
* create time
*/
createdTime;
/**
* System privileges list
*/
systemPrivileges;
/**
* Graph privileges key value map
*/
graphPrivileges;
/**
* Property privileges
*/
propertyPrivileges;
/**
* Policy list
*/
policies;
}
exports.User = User;
/**
* A policy is a set of privileges designed for a specific user role, often encompassing multiple privileges and other policies. Effective policy design and usage enable role-based access control.
*/
class Policy {
/** Policy name */
name;
/** Atlas permissions included in the policy */
systemPrivileges;
/** System permissions included in the policy */
graphPrivileges;
/** Permissions for properties included in the policy */
propertyPrivileges;
/** Other strategies included in the policy */
policies;
}
exports.Policy = Policy;
/**
* Control user permissions to operate on the graph database
*/
class Privilege {
/**
* privilege name
*/
name;
/**
* privilege type
*/
level;
}
exports.Privilege = Privilege;
/**
* The background job INFO from database.
*/
class Job {
/**
* job id
*/
id;
/**
* job run in graph name
*/
graphName;
/**
* job query
*/
query;
/**
* Job types, such as CREATE_INDEX, CACHE, COMPACT
*/
type;
/**
* Error messages encountered during job execution (if any)
*/
errMsg;
/**
* The results generated by assignments, such as output files or statistical overviews of algorithms.
*/
result;
/**
* job start time
*/
startTime;
/**
* job end time
*/
endTime;
/**
* Current state of the job, which can be FINISHED, RUNNING, STOPPING, STOPPED or FAILED.
*/
status;
/**
* Progress updates for the job, such as indications that the write operation has been started.
*/
progress;
}
exports.Job = Job;
/**
* The response items of top()
*/
class Process {
/**
* process id
*/
processId;
/**
* process query
*/
processQuery;
/**
* duration
*/
duration;
/**
* status
*/
status;
}
exports.Process = Process;
/**
* hdc.graph.show()
*/
class HDCGraph {
/**
* name
*/
name;
/**
* graph name
*/
graphName;
/**
* status
*/
status;
/**
* stats
*/
stats;
/**
* is default
*/
isDefault;
/**
* hdc server name
*/
hdcServerName;
/**
* hdc server status
*/
hdcServerStatus;
/**
* hdc config name
*/
config;
}
exports.HDCGraph = HDCGraph;
/**
* projection
*/
class Projection {
/**
* name
*/
name;
/**
* graph name
*/
graphName;
/**
* status
*/
status;
/**
* stats
*/
stats;
/**
* config
*/
config;
}
exports.Projection = Projection;
/**
* The graph data about nodes.
*/
class Node {
/**
* _uuid
*/
uuid;
/**
* _id
*/
id;
/**
* schema
*/
schema;
/**
* key: value
*/
values;
/**
* returns property value
* @param propName property name
* @returns property value
*/
get(propName) {
return this.values[propName];
}
/**
* sets property value
* @param propName
* @param value
*/
set(propName, value) {
if (!this.values) {
this.values = {};
}
if (this.values) {
this.values[propName] = value;
}
}
}
exports.Node = Node;
function NewNodeRow(jsonObj) {
let v = new Node();
Object.assign(v, jsonObj);
return v;
}
function NewNodeTable(jsonArray) {
let v = [];
jsonArray?.forEach(o => {
v.push(NewNodeRow(o));
});
return v;
}
/**
* Stores edge data.
*/
class Edge {
// _id: string; TBD
/**
* _uuid
*/
uuid;
/**
* _from_uuid
*/
fromUuid;
/**
* _to_uuid
*/
toUuid;
/**
* _from: from id
*/
from;
/**
* _to: to id
*/
to;
/**
* schema
*/
schema;
/**
* key: value
*/
values;
/**
* returns property value
* @param propName property name
* @returns property value
*/
get(propName) {
return this.values[propName];
}
/**
* set property value
* @param propName
* @param value
*/
set(propName, value) {
if (!this.values) {
this.values = {};
}
if (this.values) {
this.values[propName] = value;
}
}
}
exports.Edge = Edge;
function NewEdgeRow(jsonObj) {
let v = new Edge();
Object.assign(v, jsonObj);
return v;
}
function NewEdgeTable(jsonArray) {
let v = [];
jsonArray?.forEach(o => {
v.push(NewEdgeRow(o));
});
return v;
}
function NewEdgeAlias(jsonObj) {
let v = {};
Object.assign(v, jsonObj);
v.edges = NewEdgeTable(v.edges);
return v;
}
/**
* Path entity
*/
class Path {
/**
* Node uuid list
*/
nodeUuids;
/**
* Edge uuid list
*/
edgeUuids;
/**
* nodes details
*/
nodes = new Map();
/**
* edges details
*/
edges = new Map();
/**
* return node by index
* @param index node index
* @returns node
/**
* return edge length
* @returns edge length
*/
length() {
return this.edgeUuids?.length || 0;
}
}
exports.Path = Path;
function NewPath(jsonObj) {
let v = new Path();
Object.assign(v, jsonObj);
if (v.nodeUuids) {
v.nodeUuids = NewNodeTable(jsonObj).map(j => j.uuid);
}
if (v.edgeUuids) {
v.edgeUuids = NewEdgeTable(jsonObj).map(j => j.uuid);
}
return v;
}
function NewPaths(jsonArray) {
let v = [];
jsonArray?.forEach(obj => {
v.push(NewPath(obj));
});
return v;
}
/**
* Graph that contains nodes, edges maps and paths.
*/
class Graph {
/**
* Graph path list
*/
paths;
/**
* Graph all nodes
*/
nodes;
/**
* Graph all edges
*/
edges;
/**
* Convert path list to
* @returns Path[]
*/
getPaths() {
return this.paths;
}
/**
* Add node to nodes
* @param node new Node
*/
addNode(node) {
this.nodes.set(node.uuid, node);
}
/**
* Add edge to graph
* @param edge new Edge
*/
addEdge(edge) {
this.edges.set(edge.uuid, edge);
}
}
exports.Graph = Graph;
function NewGraph(jsonArray) {
let v = new Graph();
Object.assign(v, jsonArray);
if (v.paths) {
v.paths = NewPaths(jsonArray.paths);
}
if (v.edges) {
v.edges = new Map();
NewEdgeTable(jsonArray.edges).forEach(e => {
v.edges.set(e.uuid, e);
});
}
if (v.nodes) {
v.nodes = new Map();
NewNodeTable(jsonArray.nodes).forEach(n => {
v.nodes.set(n.uuid, n);
});
}
return v;
}
/**
* GraphSet that contains the graph name and total nodes and edges.
*/
class GraphSet {
/**
* graph id
*/
id;
/**
* graph name
*/
name;
/**
* number of nodes
*/
totalNodes;
/**
* number of edges
*/
totalEdges;
/**
* graph shards list
*/
shards;
/**
* the partition type of graph
*/
partitionBy;
/**
* status
*/
status;
/**
* graph description
*/
description;
/**
* the number of slots
*/
slotNum;
}
exports.GraphSet = GraphSet;
/**
* Node or edge schemas
*/
class Schema {
/**
* schema name
*/
name;
/**
* schema description
*/
description;
/**
* properties of schema
*/
properties;
/**
* schema type
*/
dbType;
/**
* node or edge count
*/
total;
/**
* schema id
*/
id;
/**
* store the count for each pair of start and end node schemas of current edge schema.
*/
stats = [];
/**
* Convert list of schemas to a map of schema Schema name -> Schema
* @param schemas
* @returns
*/
static toDict(schemas) {
let dict = new Map();
schemas.forEach(schema => {
dict.set(schema.name, schema);
});
return dict;
}
}
exports.Schema = Schema;
/**
* Statistics for node schema pairs in edge schema
*/
class SchemaStat {
/**
* Schema type
*/
dbType;
/**
* Schema name
*/
schema;
/**
* From Schema name
*/
fromSchema;
/**
* To Schema name
*/
toSchema;
/**
* Number of edges between these node schemas
*/
count;
}
exports.SchemaStat = SchemaStat;
class SchemaStats {
stats = [];
}
exports.SchemaStats = SchemaStats;
/**
* The properties of schema
*/
class Property {
/**
* Property name
*/
name;
/**
* PropertyType Enum
*/
type;
/**
* Sub PropertyType Enum
*/
subType;
/**
* This property is lte
*/
lte;
/**
* Whether it has read permission or not true-yes,false-no
*/
read;
/**
* Whether it has write permission or not true-yes,false-no
*/
write;
/**
* Property`s schema name
*/
schema;
/**
* Property`s description
*/
description;
/**
* encrypt method for this property, if null, value is not encrypted
*/
encrypt;
/**
* additional info for this property. For decimal property, it represents the length and precision in parentheses, default is "(20,8)"
*/
decimalExtra;
}
exports.Property = Property;
class Header {
propertyName;
propertyType;
}
exports.Header = Header;
/**
* Table
*/
class Table {
/**
* Table name
*/
name;
/**
* Table headers
*/
headers;
/**
* Table rows
*/
rows;
/**
* Convert table to list of KV
* @returns
*/
toKV() {
return utils_1.FormatResponse.tableToArray(this);
}
getHeaders() {
return this.headers;
}
getRows() {
return this.rows;
}
}
exports.Table = Table;
;
/**
* Attribute Response Data
*/
class Attr {
/**
* Ultipa property type
*/
propertyType;
/**
* Ultipa result type
*/
resultType;
/**
* Attr values
*/
values;
/**
* Attr name
*/
name;
}
exports.Attr = Attr;
class ExplainPlan {
planNodes = [];
}
exports.ExplainPlan = ExplainPlan;
class PlanNode {
alias;
childrenNum;
uql;
infos;
}
exports.PlanNode = PlanNode;
function getExplainPlansTreeTopNode(plans) {
let top = null;
let nodes = [];
plans?.planNodes.forEach((node, i) => {
node = {
...node
};
if (i == 0) {
top = node;
}
let lastNode = nodes[nodes.length - 1];
// if (node.childrenNum > 0) {
// node.children = []
// nodes.push(node)
// }
// if (lastNode) {
// lastNode.children.push(node)
// if (lastNode.children.length == lastNode.childrenNum) {
// nodes = nodes.filter(n => n != lastNode)
// }
// }
});
return top;
}
exports.getExplainPlansTreeTopNode = getExplainPlansTreeTopNode;
/**
* The get () method or alias () method of the Response class returns a DataItem embedded in the query result. You need to use the as < Type > () method of the DataItem to convert the result to the appropriate driver type.
*/
class DataItem {
/**
* Alias name
*/
alias;
/**
* Ultipa result type
*/
type;
/**
* result entity
*/
entities;
constructor(alias, type, entities) {
this.entities = entities;
this.alias = alias;
this.type = type;
}
_asTypeError(type) {
if (this.type != type) {
throw new Error(`DataItem ${this.alias} is not type ${ResultType[type]}, but ${ResultType[this.type]}`);
}
}
asNodes() {
this._asTypeError(ResultType.RESULT_TYPE_NODE);
return this.entities;
}
asFirstNode() {
return this.asNodes()[0];
}
asEdges() {
this._asTypeError(ResultType.RESULT_TYPE_EDGE);
return this.entities;
}
asFirstEdge() {
this._asTypeError(ResultType.RESULT_TYPE_EDGE);
return this.asEdges()[0];
}
asPaths() {
this._asTypeError(ResultType.RESULT_TYPE_PATH);
return this.asGraph().paths;
}
asGraph() {
this._asTypeError(ResultType.RESULT_TYPE_PATH);
let graph = this.entities;
graph.paths.forEach(p => {
p.nodes = new Map();
p.edges = new Map();
p.nodeUuids.forEach(uuid => {
p.nodes.set(uuid, graph.nodes.get(uuid));
});
p.edgeUuids.forEach(uuid => {
p.edges.set(uuid, graph.edges.get(uuid));
});
});
return graph;
}
asTable() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let table = new Table();
Object.assign(table, this.entities);
return table;
}
asAttr() {
this._asTypeError(ResultType.RESULT_TYPE_ATTR);
return this.entities;
}
asGraphSets() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let table = this.asTable().toKV();
let graphSets = [];
table.forEach((kv) => {
let graphSet = new GraphSet();
graphSet.name = kv["name"];
graphSet.totalEdges = kv["total_edges"];
graphSet.totalNodes = kv["total_nodes"];
graphSet.description = kv["description"];
graphSet.status = kv["status"];
graphSet.partitionBy = kv["partition_by"];
graphSet.slotNum = parseInt(kv["slot_num"]);
graphSet.shards = kv["shards"].split(',').map(shard => shard.trim());
graphSet.id = kv["id"];
graphSets.push(graphSet);
});
return graphSets;
}
asProperties() {
let properties = [];
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let dbType;
if (this.alias.startsWith("_node")) {
dbType = DBType.DBNODE;
}
else if (this.alias.startsWith("_edge")) {
dbType = DBType.DBEDGE;
}
else {
throw new Error(`DataItem ${this.alias} cannot transfer to Property`);
}
let table = this.asTable().toKV();
table.forEach(row => {
let property = new Property();
property.name = row["name"];
property.lte = row["lte"].toLowerCase() === "true" ? true : false;
property.read = row["read"] === "1" ? true : false;
property.write = row["write"] === "1" ? true : false;
property.schema = row["schema"];
property.description = row["description"];
property.encrypt = row["encrypt"];
let type = row['type'];
let resType = utils_1.PropertyUtils.GetPropertyType(type);
if (resType.decimalExtra) {
property.decimalExtra = resType.decimalExtra;
}
property.type = resType.type;
property.subType = resType.subTypes;
properties.push(property);
});
return properties;
}
asSchemas() {
// return this.asTableWithT<Schema>()
let schemas = [];
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
// let dbType = this.alias?.startsWith("_node") ? DBType.DBNODE;
let dbType;
if (this.alias.startsWith("_node")) {
dbType = DBType.DBNODE;
}
else if (this.alias.startsWith("_edge")) {
dbType = DBType.DBEDGE;
}
else {
throw new Error(`DataItem ${this.alias} cannot transfer to Schema`);
}
let table = this.asTable().toKV();
table.forEach(row => {
let schema = new Schema();
schema.dbType = dbType;
schema.id = row["id"];
schema.name = row["name"];
schema.description = row["description"];
let properties = [];
JSON.parse(row['properties'].toString()).forEach(o => {
let property = new Property();
let type = utils_1.PropertyUtils.GetPropertyType(o.type);
property.name = o.name;
property.type = type.type;
property.subType = type.subTypes;
property.lte = o.lte === "true" ? true : false;
property.read = o.read;
property.write = o.write;
property.schema = schema.name;
property.description = o.description;
property.encrypt = o.encrypt;
properties.push(property);
});
schema.properties = properties;
schemas.push(schema);
});
return schemas;
}
asIndexes() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let dbType;
if (this.alias.startsWith("_node")) {
dbType = DBType.DBNODE;
}
else if (this.alias.startsWith("_edge")) {
dbType = DBType.DBEDGE;
}
let indexes = [];
let table = this.asTable().toKV();
table.forEach(row => {
let index = new Index();
index.id = row["id"];
index.name = row["name"];
index.schema = row["schema"];
index.properties = row["properties"];
index.status = row["status"];
index.dbType = dbType;
indexes.push(index);
});
return indexes;
}
asPolicies() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let policies = [];
let table = this.asTable().toKV();
table.forEach(row => {
let policy = new Policy();
policy.name = row["name"];
policy.graphPrivileges = new Map(Object.entries(JSON.parse(row["graphPrivileges"])));
policy.systemPrivileges = JSON.parse(row["systemPrivileges"]);
policy.propertyPrivileges = JSON.parse(row["propertyPrivileges"]);
policy.policies = JSON.parse(row["policies"]);
policies.push(policy);
});
return policies;
}
asUsers() {
// return this.asTableWithT<User>()
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let users = [];
let table = this.asTable().toKV();
table.forEach(row => {
let user = new User();
user.username = row["username"];
user.createdTime = row["create"];
user.graphPrivileges = new Map(Object.entries(JSON.parse(row["graphPrivileges"])));
user.systemPrivileges = JSON.parse(row["systemPrivileges"]);
user.propertyPrivileges = JSON.parse(row["propertyPrivileges"]);
user.policies = JSON.parse(row["policies"]);
users.push(user);
});
return users;
}
asPrivileges() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let privileges = [];
let table = this.asTable().toKV();
table.forEach(row => {
let graphPrivileges = JSON.parse(row['graphPrivileges']);
graphPrivileges.forEach((privilege) => {
let graphPrivilege = new Privilege();
graphPrivilege.name = privilege;
graphPrivilege.level = PrivilegeLevel.GraphLevel;
privileges.push(graphPrivilege);
});
let systemPrivileges = JSON.parse(row['systemPrivileges']);
systemPrivileges.forEach((privilege) => {
let systemPrivilege = new Privilege();
systemPrivilege.name = privilege;
systemPrivilege.level = PrivilegeLevel.SystemLevel;
privileges.push(systemPrivilege);
});
});
return privileges;
}
asProcesses() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let processes = [];
let table = this.asTable().toKV();
table.forEach(row => {
let process = new Process();
process.processId = row["process_id"];
process.processQuery = row["process_query"];
process.duration = row["duration"];
process.status = row["status"];
processes.push(process);
});
return processes;
}
asHDCGraphs() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let hdcGraphs = [];
let table = this.asTable().toKV();
table.forEach(row => {
let hdcGraph = new HDCGraph();
hdcGraph.name = row['name'];
hdcGraph.graphName = row['graph_name'];
hdcGraph.status = row['status'];
hdcGraph.stats = row['stats'];
hdcGraph.isDefault = row['is_default'];
hdcGraph.hdcServerName = row['hdc_server_name'];
hdcGraph.hdcServerStatus = row['hdc_server_status'];
hdcGraph.config = row['config'];
hdcGraphs.push(hdcGraph);
});
return hdcGraphs;
}
asProjections() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let projections = [];
let table = this.asTable();
table.rows.forEach(row => {
let projection = new Projection();
projection.name = row[0];
projection.graphName = row[1];
projection.status = row[2];
projection.stats = row[3];
projection.config = row[4];
projections.push(projection);
});
return projections;
}
asAlgos() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let algos = [];
let table = this.asTable().toKV();
table.forEach(row => {
let algo = new Algo();
algo.name = row["name"];
algo.version = row["version"];
algo.type = row["type"];
algo.writeSupportType = row["write_support_type"];
algo.canRollback = row["can_rollback"];
algo.description = row["description"];
algo.configContext = row["config_context"];
// algo.params = []
algos.push(algo);
});
return algos;
}
asJobs() {
this._asTypeError(ResultType.RESULT_TYPE_TABLE);
let jobs = [];
let table = this.asTable().toKV();
table.forEach(row => {
let job = new Job();
job.id = row['job_id'];
job.graphName = row['graph_name'];
job.type = row['type'];
job.query = row['query'];
job.status = row['status'];
job.errMsg = row['err_msg'];
job.result = row['result'] ? new Map(Object.entries(JSON.parse(row['result']))) : null;
job.startTime = row['start_time'];
job.endTime = row['end_time'];
job.progress = row['progress'];
jobs.push(job);
});
return jobs;
}
asAny() {
return this.entities;
}
asTableWithT() {
return this.asTable()?.toKV();
}
toJSONString() {
return JSON.stringify(this);
}
}
exports.DataItem = DataItem;
/**
* Unified response structure for all requests
*/
class Response {
/**
* Holds statistics field of rpc response
*/
statistics;
/**
* Holds status field of rpc response
*/
status;
/**
* Holds all alias result of grpc api
*/
aliases = [];
/**
* Holds all result of grpc api, from aliases
*/
items = {};
requestInfo;
/**
* Holds result of explain uql.
*/
explainPlan;
constructor(status) {
this.status = status;
}
get(index) {
const keys = Object.keys(this.items);
if (index >= keys.length) {
throw new Error(`index ${index} out of range`);
}
return this.items[keys[index]];
}
alias(alias) {
if (!(alias in this.items)) {
throw new Error(`alias ${alias} not found`);
}
return this.items[alias];
}
}
exports.Response = Response;
class InsertResponse {
ids;
uuids;
errorItems;
/**
* Holds statistics field of rpc response
*/
statistics;
/**
* Holds status field of rpc response
*/
status;
}
exports.InsertResponse = InsertResponse;
/**
* Remarks: A language that cannot return two results, use this to return results
*/
class ResponseWithExistCheck {
/**
* When insert,return insert item exist
*/
exist;
/**
* The insert response
*/
response;
}
exports.ResponseWithExistCheck = ResponseWithExistCheck;
class JobResponse {
jobId;
/**
* Holds statistics field of response
*/
statistics;
/**
* Holds status field of response
*/
status;
}
exports.JobResponse = JobResponse;
//# sourceMappingURL=types.js.map