@ultipa-graph/ultipa-driver
Version:
NodeJS SDK for ultipa-server 5.2
1,215 lines (1,214 loc) • 25 kB
TypeScript
/**
* Ultipa Configuration is the basic configuration that used for establishing the connections.
*/
export declare 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: string[];
/** Username for authentication (Required) */
username: string;
/** Password for authentication (Required) */
password: string;
/** Default graph to interact with (Optional) */
defaultGraph?: string;
/** Path string to CRT file, used for SSL connections. */
crt?: string;
/**
* Password encryption method
* @default "MD5"
*/
passwordEncrypt?: "MD5" | "LDAP" | "NOTHING";
/**
* Request timeout in seconds
* @default 2147483647
*/
timeout?: number;
/**
* Heartbeat interval in milliseconds
* Set to 0 to disable heartbeat
* Used for keeping connection alive
* @default 0
*/
heartbeat?: number;
/**
* Maximum receive size in megabytes
* @default 32
*/
maxRecvSize?: number;
}
/**
* Configuration for each request, can be null
*/
export declare class RequestConfig {
/**
* specify graphName, if null will use defaultGraph of UltipaConfiguration
*/
graph?: string;
/**
* Operation timeout in seconds
*/
timeout?: number;
/**
* Specify the host to execute the request
* */
host?: string;
/**
* request,thread num
*/
thread?: number;
/**
* name of time zone,
* default: current time zone.
* e.g. Aisa/Shanghai
*/
timezone?: string;
/**
* hour elapse from UTC
* When both `timezone` and `timezoneOffset` are provided, `timezoneOffset` takes precedence.
* Unit: hour. Example:” +08:30”,”-05:00”,“+2”,“-0300”
*/
timezoneOffset?: string;
/**
* If true the queryText will be logged.
*/
logQueryText?: boolean;
/**
* If true the request info will be logged.
*/
withRequestInfo?: boolean;
}
/**
* configuration for insert request. extends RequestConfig,have all RequestConfig property
*/
export declare class InsertRequestConfig extends RequestConfig {
/**
* NORMAL,
* OVERWRITE,
* UPSERT
*/
insertType: InsertType;
/**
* Return data or not when insert/delete batch. true - not return data, false - return data.
*/
silent: boolean;
}
/**
* The insert error code from server.
*/
export declare enum InsertErrorCode {
ID_NOT_MATCH_UUID = 10001,
ID_UUID_NOT_MATCH_SCHEMA = 10002,
FROM_ID_NOT_EXISTED = 10003,
TO_ID_NOT_EXISTED = 10004,
ID_LEN = 10005,
NOT_NULL = 10006,
UNIQUCHECK = 10007,
ID_EMPTY = 10008,
FROM_ID_EMPTY = 10009,
TO_ID_EMPTY = 10010,
DUPLICATE_ID = 10011,
KEY_CONSTRAINT_VIOLATED = 10012,
INVALID_FORMAT = 10013,
OK_BUT_ID_EXISTED = 11001,
OTHERS = 19999
}
export declare const InsertErrorMessages: {
10001: string;
10002: string;
10003: string;
10004: string;
10005: string;
10006: string;
10007: string;
10008: string;
10009: string;
10010: string;
10011: string;
10012: string;
10013: string;
11001: string;
19999: string;
};
export declare function getInsertErrorMessage(errorCode: InsertErrorCode | number): string;
/**
* TODO: delete Timezone
*/
export interface Timezone {
timezone?: string;
timezoneOffset?: string;
timestampToString?: boolean;
}
/**
* The schema property type.When create property.Need set property type.
*/
export declare enum UltipaPropertyType {
/**
* Ultipa schema id type
*/
ID = -1,
/**
* Ultipa schema uuid type
*/
UUID = -2,
/**
* Ultipa edge schema from_id type
*/
FROM = -3,
/**
* Ultipa edge schema to_id type
*/
TO = -4,
/**
* Ultipa edge schema from_uuid type
*/
FROM_UUID = -5,
/**
* Ultipa edge schema to_uuid type
*/
TO_UUID = -6,
/**
* Ignore
*/
IGNORE = -7,
/**
* No type set
*/
UNSET = 0,
/**
* Signed 32 integer
*/
INT32 = 1,
/**
* Unsigned 32 integer
*/
UINT32 = 2,
/**
* Signed 64 integer
*/
INT64 = 3,
/**
* Unsigned 64 integer
*/
UINT64 = 4,
/**
* Single floating-point number
*/
FLOAT = 5,
/**
* Double-precision floating-point numbers
*/
DOUBLE = 6,
/**
* A data type that represents a sequence of characters
*/
STRING = 7,
/**
* Represents a combination of a date and a time
*/
DATETIME = 8,
/**
* A data type that typically represents a specific point in time, often with a high level of precision
*/
TIMESTAMP = 9,
/**
* Used to store large amounts of text data
*/
TEXT = 10,
/**
* Stands for Binary Large Object
*/
BLOB = 11,
/**
* In the context of databases dealing with spatial data (e.g., in GIS systems)
*/
POINT = 12,
/**
* Represents a fixed-point number with a specified precision and scale
*/
DECIMAL = 13,
/**
* A data structure that can hold a collection of elements
*/
LIST = 14,
/**
* A data structure that stores a collection of unique elements
*/
SET = 15,
/**
* A data structure that stores key-value pairs
*/
MAP = 16,
/**
* Null type
*/
NULL = 17,
/**
* Stands for Boolean
*/
BOOL = 18,
LOCAL_DATETIME = 19,
ZONED_DATETIME = 20,
DATE = 21,
ZONED_TIME = 22,
LOCAL_TIME = 23,
YEAR_TO_MONTH = 24,
DAY_TO_SECOND = 25,
JSON = 26
}
/**
* The insertion mode.
*/
export declare enum InsertType {
/**
* Insert new data
*/
NORMAL = 0,
/**
* The insert overwrite operation first clears the existing data in the target location and then inserts new data
*/
OVERWRITE = 1,
/**
* 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
*/
UPSERT = 2
}
/**
* Algorithm Detail Response Data
*/
export declare class Algo {
/**
* name
*/
name?: string;
/**
* type
*/
type?: string;
/**
* write support type
*/
writeSupportType?: string;
/**
* Whether the algorithm can be rolled back to previous version.
*/
canRollback?: string;
/**
* config context
*/
configContext?: string;
/**
* version
*/
version?: string;
/**
* algo params
*/
params?: AlgoParam[];
/**
* algo description
*/
description?: string;
}
export interface AlgoParam {
name: string;
desc?: string;
}
/**
* TODO delete Code
*/
export declare enum ErrorCode {
SUCCESS,
FAILED,
PARAM_ERROR,
BASE_DB_ERROR,
ENGINE_ERROR,
SYSTEM_ERROR,
SYNTAX_ERROR,
PERMISSION_DENIED,
DUPLICATE_ID,
RAFT_REDIRECT,
RAFT_LEADER_NOT_YET_ELECTED,
RAFT_LOG_ERROR,
NOT_RAFT_MODE,
RAFT_NO_AVAILABLE_FOLLOWERS,
RAFT_NO_AVAILABLE_ALGO_SERVERS,
UNKNOWN_ERROR = 1000
}
export declare enum ResultType {
RESULT_TYPE_UNSET,
RESULT_TYPE_PATH,
RESULT_TYPE_NODE,
RESULT_TYPE_EDGE,
RESULT_TYPE_ATTR,
RESULT_TYPE_TABLE
}
export declare enum AuthenticateType {
PERMISSION_TYPE_UNSET,
PERMISSION_TYPE_UQL,
PERMISSION_TYPE_GQL,
PERMISSION_TYPE_INSERTNODES,
PERMISSION_TYPE_INSERTEDGES,
PERMISSION_TYPE_EXPORT,
PERMISSION_TYPE_DOWNLOADFILE,
PERMISSION_TYPE_INSTALLALGO,
PERMISSION_TYPE_UNINSTALLALGO,
PERMISSION_TYPE_ROLLBACKALGO
}
/**
* privilege level type
*/
export declare enum PrivilegeLevel {
/**
* Graph privilege type
*/
GraphLevel = 0,
/**
* System privilege type
*/
SystemLevel = 1
}
/**
* HDC synchronization type.
*/
export declare enum HDCSyncType {
/**
* Static synchronization
*/
STATIC = "static",
/**
* Asynchronous synchronization
*/
ASYNC = "async",
/**
* Synchronous synchronization
*/
SYNC = "sync"
}
/** Query type contains UQL,GQL */
export declare enum QueryType {
QL_UNSET = 0,
UQL = 1,
GQL = 2
}
/**
* The schema type in database.
*/
export declare enum DBType {
/**
* Node
*/
DBNODE,
/**
* Edge
*/
DBEDGE
}
/**
* Job status
*/
export declare enum JOB_STATUS {
JOB_PENDING,
JOB_COMPUTING,
JOB_WRITING,
JOB_DONE,
JOB_FAILED,
JOB_STOPPED
}
/**
* Property index
*/
export declare class Index {
id?: string;
/**
* Index name
*/
name: string;
/**
* Index on which properties
*/
properties: string;
/**
* Index on which scehma
*/
schema: string;
/**
* Index status
*/
status: string;
/**
* Index size
*/
size?: string;
/**
* Node index or edge index
*/
dbType?: DBType;
}
/**
* User
*/
export declare class User {
/**
* username
*/
username?: string;
/**
* pasword
*/
password?: string;
/**
* create time
*/
createdTime?: Date;
/**
* System privileges list
*/
systemPrivileges?: string[];
/**
* Graph privileges key value map
*/
graphPrivileges?: Map<string, string[]>;
/**
* Property privileges
*/
propertyPrivileges?: PropertyPrivilege;
/**
* Policy list
*/
policies?: string[];
}
export interface PropertyPrivilege {
node?: PropertyPrivilegeElement;
edge?: PropertyPrivilegeElement;
}
export interface PropertyPrivilegeElement {
read?: string[][];
write?: string[][];
deny?: string[][];
}
/**
* 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.
*/
export declare class Policy {
/** Policy name */
name?: string;
/** Atlas permissions included in the policy */
systemPrivileges?: string[];
/** System permissions included in the policy */
graphPrivileges?: Map<string, string[]>;
/** Permissions for properties included in the policy */
propertyPrivileges?: PropertyPrivilege;
/** Other strategies included in the policy */
policies?: string[];
}
/**
* Control user permissions to operate on the graph database
*/
export declare class Privilege {
/**
* privilege name
*/
name?: string;
/**
* privilege type
*/
level?: PrivilegeLevel;
}
/**
* 连接返回的统一状态
*/
export type Status = {
code: ErrorCode;
message: string;
};
/**
* The background job INFO from database.
*/
export declare class Job {
/**
* job id
*/
id?: string;
/**
* job run in graph name
*/
graphName?: string;
/**
* job query
*/
query?: string;
/**
* Job types, such as CREATE_INDEX, CACHE, COMPACT
*/
type?: string;
/**
* Error messages encountered during job execution (if any)
*/
errMsg?: string;
/**
* The results generated by assignments, such as output files or statistical overviews of algorithms.
*/
result?: Map<any, any>;
/**
* job start time
*/
startTime?: string;
/**
* job end time
*/
endTime?: string;
/**
* Current state of the job, which can be FINISHED, RUNNING, STOPPING, STOPPED or FAILED.
*/
status?: "FINISHED" | "RUNNING" | "STOPPING" | "STOPPED" | "FAILED";
/**
* Progress updates for the job, such as indications that the write operation has been started.
*/
progress?: string;
}
/**
* The response items of top()
*/
export declare class Process {
/**
* process id
*/
processId?: string;
/**
* process query
*/
processQuery?: string;
/**
* duration
*/
duration?: string;
/**
* status
*/
status?: string;
}
/**
* hdc.graph.show()
*/
export declare class HDCGraph {
/**
* name
*/
name?: string;
/**
* graph name
*/
graphName?: string;
/**
* status
*/
status?: string;
/**
* stats
*/
stats?: string;
/**
* is default
*/
isDefault?: string;
/**
* hdc server name
*/
hdcServerName?: string;
/**
* hdc server status
*/
hdcServerStatus?: string;
/**
* hdc config name
*/
config?: string;
}
/**
* projection
*/
export declare class Projection {
/**
* name
*/
name?: string;
/**
* graph name
*/
graphName?: string;
/**
* status
*/
status?: string;
/**
* stats
*/
stats?: string;
/**
* config
*/
config?: string;
}
/**
* Statistics information about license and usage limits
*/
export interface Stats {
/**
* License uuid
*/
licenseUuid?: string;
/**
* Company name
*/
company?: string;
/**
* Department name
*/
department?: string;
/**
* Maximum number of users allowed
*/
limitedUser?: string;
/**
* Maximum number of graphs allowed
*/
limitedGraph?: string;
/**
* Maximum number of nodes allowed
*/
limitedNode?: string;
/**
* Maximum number of edges allowed
*/
limitedEdge?: string;
/**
* Maximum number of shards allowed
*/
limitedShard?: string;
/**
* Maximum number of HDC connections allowed
*/
limitedHdc?: string;
/**
* License expiration date
*/
expiredDate?: string;
}
/**
* The graph data about nodes.
*/
export declare class Node {
/**
* _uuid
*/
uuid?: string;
/**
* _id
*/
id?: string;
/**
* schema
*/
schema?: string;
/**
* key: value
*/
values?: {
[key: string]: any;
};
/**
* returns property value
* @param propName property name
* @returns property value
*/
get?(propName: string): any;
/**
* sets property value
* @param propName
* @param value
*/
set?(propName: string, value: any): void;
}
/**
* Stores edge data.
*/
export declare class Edge {
/**
* _uuid
*/
uuid?: string;
/**
* _from_uuid
*/
fromUuid?: string;
/**
* _to_uuid
*/
toUuid?: string;
/**
* _from: from id
*/
from?: string;
/**
* _to: to id
*/
to?: string;
/**
* schema
*/
schema?: string;
/**
* key: value
*/
values?: {
[key: string]: any;
};
/**
* returns property value
* @param propName property name
* @returns property value
*/
get?(propName: string): any;
/**
* set property value
* @param propName
* @param value
*/
set?(propName: string, value: any): void;
}
/**
* 一组边
*/
export type EdgeAlias = {
edges: Edge[];
alias: string;
};
/**
* Path entity
*/
export declare class Path {
/**
* Node uuid list
*/
nodeUuids?: string[];
/**
* Edge uuid list
*/
edgeUuids?: string[];
/**
* nodes details
*/
nodes?: Map<string, Node>;
/**
* edges details
*/
edges?: Map<string, Edge>;
/**
* return node by index
* @param index node index
* @returns node
/**
* return edge length
* @returns edge length
*/
length?(): number;
}
/**
* Graph that contains nodes, edges maps and paths.
*/
export declare class Graph {
/**
* Graph path list
*/
paths?: Path[];
/**
* Graph all nodes
*/
nodes?: Map<string, Node>;
/**
* Graph all edges
*/
edges?: Map<string, Edge>;
/**
* Convert path list to
* @returns Path[]
*/
getPaths(): Path[];
/**
* Add node to nodes
* @param node new Node
*/
addNode(node: Node): void;
/**
* Add edge to graph
* @param edge new Edge
*/
addEdge(edge: Edge): void;
}
/**
* GraphSet that contains the graph name and total nodes and edges.
*/
export declare class GraphSet {
/**
* graph id
*/
id?: string;
/**
* graph name
*/
name: string;
/**
* number of nodes
*/
totalNodes?: string;
/**
* number of edges
*/
totalEdges?: string;
/**
* graph shards list
*/
shards?: string[];
/**
* the partition type of graph
*/
partitionBy?: string;
/**
* status
*/
status?: string;
/**
* graph description
*/
description?: string | null;
/**
* the number of slots
*/
slotNum?: number | 0;
}
/**
* Node or edge schemas
*/
export declare class Schema {
/**
* schema name
*/
name: string;
/**
* schema description
*/
description?: string;
/**
* properties of schema
*/
properties?: Property[];
/**
* schema type
*/
dbType: DBType;
/**
* node or edge count
*/
total?: string;
/**
* schema id
*/
id?: string;
/**
* store the count for each pair of start and end node schemas of current edge schema.
*/
stats?: SchemaStat[];
/**
* Convert list of schemas to a map of schema Schema name -> Schema
* @param schemas
* @returns
*/
static toDict?(schemas: Schema[]): Map<string, Schema>;
}
/**
* Statistics for node schema pairs in edge schema
*/
export declare class SchemaStat {
/**
* Schema type
*/
dbType?: DBType;
/**
* Schema name
*/
schema?: string;
/**
* From Schema name
*/
fromSchema: string;
/**
* To Schema name
*/
toSchema: string;
/**
* Number of edges between these node schemas
*/
count: string;
}
export declare class SchemaStats {
stats: SchemaStat[];
}
/**
* The properties of schema
*/
export declare class Property {
/**
* Property name
*/
name: string;
/**
* PropertyType Enum
*/
type: UltipaPropertyType;
/**
* Sub PropertyType Enum
*/
subType?: UltipaPropertyType[];
/**
* This property is lte
*/
lte?: boolean;
/**
* Whether it has read permission or not true-yes,false-no
*/
read?: boolean;
/**
* Whether it has write permission or not true-yes,false-no
*/
write?: boolean;
/**
* Property`s schema name
*/
schema: string;
/**
* Property`s description
*/
description?: string;
/**
* encrypt method for this property, if null, value is not encrypted
*/
encrypt?: string;
/**
* additional info for this property. For decimal property, it represents the length and precision in parentheses, default is "(20,8)"
*/
decimalExtra?: DecimalExtra;
}
/**
* Decimal additional info
*/
export interface DecimalExtra {
precision: number;
scale: number;
}
export interface AllProperties {
nodeProperties: Property[];
edgeProperties: Property[];
}
export declare class Header {
propertyName: string;
propertyType: UltipaPropertyType;
}
/**
* Table
*/
export declare class Table {
/**
* Table name
*/
name?: string;
/**
* Table headers
*/
headers?: Header[];
/**
* Table rows
*/
rows?: any[][];
/**
* Convert table to list of KV
* @returns
*/
toKV(): any[];
getHeaders(): Header[];
getRows(): any[][];
}
export type Replica = {
addr: string;
status: string;
streamAddr: string;
lastHearBeat: string;
};
export type Statistics = {
nodeAffected?: number;
edgeAffected?: number;
totalCost: number;
engineCost: number;
};
/**
* Attribute Response Data
*/
export declare class Attr {
/**
* Ultipa property type
*/
propertyType?: UltipaPropertyType;
/**
* Ultipa result type
*/
resultType?: ResultType;
/**
* Attr values
*/
values?: object[];
/**
* Attr name
*/
name?: string;
}
export type AttrListData = {
type: ResultType;
type_desc: string;
nodes?: Node[];
edges?: Edge[];
paths?: Path[];
attrs?: Attr[];
};
export declare class ExplainPlan {
planNodes: PlanNode[];
}
export declare class PlanNode {
alias: string;
childrenNum: number;
uql: string;
infos: string;
}
export declare function getExplainPlansTreeTopNode(plans: ExplainPlan): PlanNode;
/**
* 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.
*/
export declare class DataItem {
/**
* Alias name
*/
alias?: string;
/**
* Ultipa result type
*/
type?: ResultType;
/**
* result entity
*/
entities?: any;
constructor(alias: string, type: ResultType, entities: any);
private _asTypeError;
asNodes(): Node[];
asFirstNode(): Node;
asEdges(): Edge[];
asFirstEdge(): Edge;
asPaths(): Path[];
asGraph(): Graph;
asTable(): Table;
asAttr(): Attr;
asGraphSets(): GraphSet[];
asProperties(): Property[];
asSchemas(): Schema[];
asIndexes(): Index[];
asPolicies(): Policy[];
asUsers(): User[];
asPrivileges(): Privilege[];
asProcesses(): Process[];
asHDCGraphs(): HDCGraph[];
asProjections(): Projection[];
asAlgos(): Algo[];
asJobs(): Job[];
asAny(): any;
asTableWithT<T>(): T[];
toJSONString(): string;
}
/**
* Unified response structure for all requests
*/
export declare class Response {
/**
* Holds statistics field of rpc response
*/
statistics?: Statistics;
/**
* Holds status field of rpc response
*/
status?: Status;
/**
* Holds all alias result of grpc api
*/
aliases?: Alias[];
/**
* Holds all result of grpc api, from aliases
*/
items: {
[key: string]: DataItem;
};
requestInfo?: any;
/**
* Holds result of explain uql.
*/
explainPlan?: ExplainPlan;
constructor(status?: Status);
get(index: number): DataItem;
alias(alias: string): DataItem;
}
export declare class InsertResponse {
ids?: string[];
uuids?: string[];
errorItems?: Map<number, InsertErrorCode>;
/**
* Holds statistics field of rpc response
*/
statistics?: Statistics;
/**
* Holds status field of rpc response
*/
status?: Status;
}
/**
* Remarks: A language that cannot return two results, use this to return results
*/
export declare class ResponseWithExistCheck {
/**
* When insert,return insert item exist
*/
exist?: boolean;
/**
* The insert response
*/
response: Response;
}
export declare class JobResponse {
jobId?: string;
/**
* Holds statistics field of response
*/
statistics?: Statistics;
/**
* Holds status field of response
*/
status?: Status;
}
export interface Alias {
name?: string;
type?: ResultType;
}
export type AttrAlias = {
values: any[];
type: ResultType;
type_desc: string;
alias: string;
};