@ultipa-graph/ultipa-driver 5.0.0-s5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist/.DS_Store +0 -0
  2. package/dist/connection/connection.final.d.ts +45 -0
  3. package/dist/connection/connection.final.js +600 -0
  4. package/dist/connection/connection.final.js.map +1 -0
  5. package/dist/connection/connection.pool.d.ts +26 -0
  6. package/dist/connection/connection.pool.js +121 -0
  7. package/dist/connection/connection.pool.js.map +1 -0
  8. package/dist/connection/extra/algos/algo.extra.d.ts +34 -0
  9. package/dist/connection/extra/algos/algo.extra.js +81 -0
  10. package/dist/connection/extra/algos/algo.extra.js.map +1 -0
  11. package/dist/connection/extra/algos/algo.utils.d.ts +3 -0
  12. package/dist/connection/extra/algos/algo.utils.js +71 -0
  13. package/dist/connection/extra/algos/algo.utils.js.map +1 -0
  14. package/dist/connection/extra/algos/community.d.ts +27 -0
  15. package/dist/connection/extra/algos/community.js +129 -0
  16. package/dist/connection/extra/algos/community.js.map +1 -0
  17. package/dist/connection/extra/algos/degrees.d.ts +10 -0
  18. package/dist/connection/extra/algos/degrees.js +43 -0
  19. package/dist/connection/extra/algos/degrees.js.map +1 -0
  20. package/dist/connection/extra/algos/embedding.d.ts +13 -0
  21. package/dist/connection/extra/algos/embedding.js +58 -0
  22. package/dist/connection/extra/algos/embedding.js.map +1 -0
  23. package/dist/connection/extra/algos/index.d.ts +5 -0
  24. package/dist/connection/extra/algos/index.js +14 -0
  25. package/dist/connection/extra/algos/index.js.map +1 -0
  26. package/dist/connection/extra/base.extra.d.ts +71 -0
  27. package/dist/connection/extra/base.extra.js +183 -0
  28. package/dist/connection/extra/base.extra.js.map +1 -0
  29. package/dist/connection/extra/connection.base.d.ts +82 -0
  30. package/dist/connection/extra/connection.base.js +623 -0
  31. package/dist/connection/extra/connection.base.js.map +1 -0
  32. package/dist/connection/extra/connection.d.ts +16 -0
  33. package/dist/connection/extra/connection.js +46 -0
  34. package/dist/connection/extra/connection.js.map +1 -0
  35. package/dist/connection/extra/graph.extra.d.ts +85 -0
  36. package/dist/connection/extra/graph.extra.js +241 -0
  37. package/dist/connection/extra/graph.extra.js.map +1 -0
  38. package/dist/connection/extra/index.extra.d.ts +70 -0
  39. package/dist/connection/extra/index.extra.js +201 -0
  40. package/dist/connection/extra/index.extra.js.map +1 -0
  41. package/dist/connection/extra/job.extra.d.ts +32 -0
  42. package/dist/connection/extra/job.extra.js +145 -0
  43. package/dist/connection/extra/job.extra.js.map +1 -0
  44. package/dist/connection/extra/meta.extra.d.ts +91 -0
  45. package/dist/connection/extra/meta.extra.js +441 -0
  46. package/dist/connection/extra/meta.extra.js.map +1 -0
  47. package/dist/connection/extra/property.extra.d.ts +81 -0
  48. package/dist/connection/extra/property.extra.js +268 -0
  49. package/dist/connection/extra/property.extra.js.map +1 -0
  50. package/dist/connection/extra/schema.extra.d.ts +50 -0
  51. package/dist/connection/extra/schema.extra.js +248 -0
  52. package/dist/connection/extra/schema.extra.js.map +1 -0
  53. package/dist/connection/extra/search.extra.d.ts +12 -0
  54. package/dist/connection/extra/search.extra.js +126 -0
  55. package/dist/connection/extra/search.extra.js.map +1 -0
  56. package/dist/connection/extra/task.extra.d.ts +24 -0
  57. package/dist/connection/extra/task.extra.js +126 -0
  58. package/dist/connection/extra/task.extra.js.map +1 -0
  59. package/dist/connection/extra/user.privilege.extra.d.ts +64 -0
  60. package/dist/connection/extra/user.privilege.extra.js +348 -0
  61. package/dist/connection/extra/user.privilege.extra.js.map +1 -0
  62. package/dist/connection/index.d.ts +4 -0
  63. package/dist/connection/index.js +10 -0
  64. package/dist/connection/index.js.map +1 -0
  65. package/dist/connection/network.manager.d.ts +27 -0
  66. package/dist/connection/network.manager.js +178 -0
  67. package/dist/connection/network.manager.js.map +1 -0
  68. package/dist/index.d.ts +4 -0
  69. package/dist/index.js +14 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/printers/alias.d.ts +2 -0
  72. package/dist/printers/alias.js +15 -0
  73. package/dist/printers/alias.js.map +1 -0
  74. package/dist/printers/any.d.ts +2 -0
  75. package/dist/printers/any.js +40 -0
  76. package/dist/printers/any.js.map +1 -0
  77. package/dist/printers/array.aio.d.ts +44 -0
  78. package/dist/printers/array.aio.js +240 -0
  79. package/dist/printers/array.aio.js.map +1 -0
  80. package/dist/printers/common.d.ts +0 -0
  81. package/dist/printers/common.js +1 -0
  82. package/dist/printers/common.js.map +1 -0
  83. package/dist/printers/edge.d.ts +5 -0
  84. package/dist/printers/edge.js +49 -0
  85. package/dist/printers/edge.js.map +1 -0
  86. package/dist/printers/explain.plan.d.ts +2 -0
  87. package/dist/printers/explain.plan.js +24 -0
  88. package/dist/printers/explain.plan.js.map +1 -0
  89. package/dist/printers/graph.d.ts +2 -0
  90. package/dist/printers/graph.js +34 -0
  91. package/dist/printers/graph.js.map +1 -0
  92. package/dist/printers/index.d.ts +25 -0
  93. package/dist/printers/index.js +44 -0
  94. package/dist/printers/index.js.map +1 -0
  95. package/dist/printers/node.d.ts +5 -0
  96. package/dist/printers/node.js +49 -0
  97. package/dist/printers/node.js.map +1 -0
  98. package/dist/printers/path.d.ts +3 -0
  99. package/dist/printers/path.js +42 -0
  100. package/dist/printers/path.js.map +1 -0
  101. package/dist/printers/status.d.ts +3 -0
  102. package/dist/printers/status.js +45 -0
  103. package/dist/printers/status.js.map +1 -0
  104. package/dist/printers/table.d.ts +2 -0
  105. package/dist/printers/table.js +31 -0
  106. package/dist/printers/table.js.map +1 -0
  107. package/dist/proto/tmp.js +366 -0
  108. package/dist/proto/ultipa_grpc_pb.d.ts +257 -0
  109. package/dist/proto/ultipa_grpc_pb.js +366 -0
  110. package/dist/proto/ultipa_grpc_pb.js.map +1 -0
  111. package/dist/proto/ultipa_pb.d.ts +1 -0
  112. package/dist/proto/ultipa_pb.js +11002 -0
  113. package/dist/proto/ultipa_pb.js.map +1 -0
  114. package/dist/transaction/UltipaSession.d.ts +28 -0
  115. package/dist/transaction/UltipaSession.js +148 -0
  116. package/dist/transaction/UltipaSession.js.map +1 -0
  117. package/dist/transaction/UltipaTransaction.Recorder.d.ts +20 -0
  118. package/dist/transaction/UltipaTransaction.Recorder.js +23 -0
  119. package/dist/transaction/UltipaTransaction.Recorder.js.map +1 -0
  120. package/dist/transaction/UltipaTransaction.d.ts +35 -0
  121. package/dist/transaction/UltipaTransaction.js +203 -0
  122. package/dist/transaction/UltipaTransaction.js.map +1 -0
  123. package/dist/transaction/UltipaTransactionSession.d.ts +15 -0
  124. package/dist/transaction/UltipaTransactionSession.js +46 -0
  125. package/dist/transaction/UltipaTransactionSession.js.map +1 -0
  126. package/dist/transaction/operations/Transaction.Deletes.d.ts +4 -0
  127. package/dist/transaction/operations/Transaction.Deletes.js +52 -0
  128. package/dist/transaction/operations/Transaction.Deletes.js.map +1 -0
  129. package/dist/transaction/operations/Transaction.Inserts.d.ts +4 -0
  130. package/dist/transaction/operations/Transaction.Inserts.js +78 -0
  131. package/dist/transaction/operations/Transaction.Inserts.js.map +1 -0
  132. package/dist/transaction/operations/Transaction.Update.d.ts +4 -0
  133. package/dist/transaction/operations/Transaction.Update.js +43 -0
  134. package/dist/transaction/operations/Transaction.Update.js.map +1 -0
  135. package/dist/types/index.d.ts +4 -0
  136. package/dist/types/index.js +13 -0
  137. package/dist/types/index.js.map +1 -0
  138. package/dist/types/types.algos.params.d.ts +545 -0
  139. package/dist/types/types.algos.params.js +16 -0
  140. package/dist/types/types.algos.params.js.map +1 -0
  141. package/dist/types/types.d.ts +496 -0
  142. package/dist/types/types.extra.d.ts +788 -0
  143. package/dist/types/types.extra.js +49 -0
  144. package/dist/types/types.extra.js.map +1 -0
  145. package/dist/types/types.js +706 -0
  146. package/dist/types/types.js.map +1 -0
  147. package/dist/types/util.d.ts +15 -0
  148. package/dist/types/util.js +163 -0
  149. package/dist/types/util.js.map +1 -0
  150. package/dist/utils/common.d.ts +3 -0
  151. package/dist/utils/common.js +31 -0
  152. package/dist/utils/common.js.map +1 -0
  153. package/dist/utils/config.d.ts +3 -0
  154. package/dist/utils/config.js +7 -0
  155. package/dist/utils/config.js.map +1 -0
  156. package/dist/utils/format.d.ts +49 -0
  157. package/dist/utils/format.js +990 -0
  158. package/dist/utils/format.js.map +1 -0
  159. package/dist/utils/index.d.ts +12 -0
  160. package/dist/utils/index.js +34 -0
  161. package/dist/utils/index.js.map +1 -0
  162. package/dist/utils/params.validate.d.ts +4 -0
  163. package/dist/utils/params.validate.js +14 -0
  164. package/dist/utils/params.validate.js.map +1 -0
  165. package/dist/utils/property.d.ts +15 -0
  166. package/dist/utils/property.js +117 -0
  167. package/dist/utils/property.js.map +1 -0
  168. package/dist/utils/raft.retry.d.ts +0 -0
  169. package/dist/utils/raft.retry.js +1 -0
  170. package/dist/utils/raft.retry.js.map +1 -0
  171. package/dist/utils/serialize/commont.d.ts +12 -0
  172. package/dist/utils/serialize/commont.js +46 -0
  173. package/dist/utils/serialize/commont.js.map +1 -0
  174. package/dist/utils/serialize/deserialize.d.ts +9 -0
  175. package/dist/utils/serialize/deserialize.js +164 -0
  176. package/dist/utils/serialize/deserialize.js.map +1 -0
  177. package/dist/utils/serialize/null.d.ts +24 -0
  178. package/dist/utils/serialize/null.js +133 -0
  179. package/dist/utils/serialize/null.js.map +1 -0
  180. package/dist/utils/serialize/serialize.d.ts +10 -0
  181. package/dist/utils/serialize/serialize.js +135 -0
  182. package/dist/utils/serialize/serialize.js.map +1 -0
  183. package/dist/utils/stream.helper.d.ts +9 -0
  184. package/dist/utils/stream.helper.js +97 -0
  185. package/dist/utils/stream.helper.js.map +1 -0
  186. package/dist/utils/time.record.d.ts +15 -0
  187. package/dist/utils/time.record.js +50 -0
  188. package/dist/utils/time.record.js.map +1 -0
  189. package/dist/utils/timezone.d.ts +7 -0
  190. package/dist/utils/timezone.js +21 -0
  191. package/dist/utils/timezone.js.map +1 -0
  192. package/dist/utils/ultipa.datetime.d.ts +8 -0
  193. package/dist/utils/ultipa.datetime.js +120 -0
  194. package/dist/utils/ultipa.datetime.js.map +1 -0
  195. package/dist/utils/uql-maker.d.ts +164 -0
  196. package/dist/utils/uql-maker.js +400 -0
  197. package/dist/utils/uql-maker.js.map +1 -0
  198. package/dist/utils/uql.parse.d.ts +27 -0
  199. package/dist/utils/uql.parse.js +206 -0
  200. package/dist/utils/uql.parse.js.map +1 -0
  201. package/package.json +62 -0
  202. package/readme.md +63 -0
package/dist/.DS_Store ADDED
Binary file
@@ -0,0 +1,45 @@
1
+ import { Connection } from "./extra/connection";
2
+ import { RequestType, ResponseType, ULTIPA } from "../types";
3
+ export declare class ConnectionFinal extends Connection {
4
+ testConnectResult: boolean;
5
+ setGraph(graphName: string): void;
6
+ /**
7
+ * 拷贝数据集
8
+ */
9
+ copyGraph(req: RequestType.CopyGraph, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<any>>;
10
+ /** 卸载算法 */
11
+ uninstallAlgo(req: RequestType.UninstallAlgo, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<boolean>>;
12
+ /**卸载HDC算法 */
13
+ uninstallHDCAlgo(algoName: string, hdcName: string, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<boolean>>;
14
+ /** 回滚算法 */
15
+ rollbackAlgo(algoName: string, hdcName: string, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<boolean>>;
16
+ /** 安装算法 */
17
+ installAlgo(req: RequestType.InstallAlgo, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<boolean>>;
18
+ /** 安装HDC算法 */
19
+ installHdcAlgo(soFile: string, ymlFile: string, hdcName: string, commonReq?: RequestType.RequestConfig): Promise<ULTIPA.Response<boolean>>;
20
+ /** 安装算法 */
21
+ private installAlgoAio;
22
+ private _installAlgo;
23
+ insertNodesBatchAuto(rows: ULTIPA.Node[], config?: RequestType.InsertRequestConfig): Promise<ULTIPA.Response<ResponseType.InsertNodes>>;
24
+ /**
25
+ * 插入大量的点
26
+ */
27
+ insertHugeNodes(req: RequestType.InsertHugeNodes, config?: RequestType.InsertRequestConfig): Promise<ULTIPA.Response<ResponseType.InsertNodes>>;
28
+ validEdgeRows(rows: ULTIPA.Edge[]): {
29
+ ok: boolean;
30
+ msg?: string;
31
+ failedIndex?: number;
32
+ };
33
+ insertEdgesBatchAuto(rows: ULTIPA.Edge[], config: RequestType.InsertRequestConfig): Promise<ULTIPA.Response<ResponseType.InsertEdges>>;
34
+ /**
35
+ * 插入大量的边
36
+ */
37
+ insertHugeEdges(req: RequestType.InsertHugeEdges, config?: RequestType.InsertRequestConfig): Promise<ULTIPA.Response<ResponseType.InsertEdges>>;
38
+ /**
39
+ * 查看HDC算法
40
+ * @param hdcName
41
+ */
42
+ showHdcAlgo(hdcName: string, requestConfig?: RequestType.RequestConfig): Promise<ULTIPA.Response<any>>;
43
+ /** 创建点或者边的schema */
44
+ createSchema(schema: ULTIPA.Schema, isCreateProperties?: boolean, requestConfig?: RequestType.RequestConfig): Promise<ULTIPA.Response<null>>;
45
+ }
@@ -0,0 +1,600 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.ConnectionFinal = void 0;
39
+ const connection_1 = require("./extra/connection");
40
+ const types_1 = require("../types");
41
+ const utils_1 = require("../utils");
42
+ const utils_2 = require("../utils");
43
+ const ultipa_pb_1 = require("../proto/ultipa_pb");
44
+ const fs = __importStar(require("fs-extra"));
45
+ const crypto_1 = __importDefault(require("crypto"));
46
+ const path_1 = __importDefault(require("path"));
47
+ const connection_base_1 = require("./extra/connection.base");
48
+ const { CommandList, SchemaStringWithDefault } = utils_1.UQLMAKER;
49
+ // 做一些扩展性的接口
50
+ class ConnectionFinal extends connection_1.Connection {
51
+ setGraph(graphName) {
52
+ this.defaultConfig.graphSetName = graphName;
53
+ }
54
+ /**
55
+ * 拷贝数据集
56
+ */
57
+ copyGraph(req, commonReq) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ let success = types_1.ULTIPA.Code.SUCCESS;
60
+ let resCreate = yield this.createGraph({ name: req.newGraphSetName }, ["1"], {}, commonReq);
61
+ if (resCreate.status.code !== success) {
62
+ return resCreate;
63
+ }
64
+ yield (0, utils_2.sleepSeconds)(10); // 新创建的图集集群需要同步
65
+ // let resListSchema = await this.showSchema({ graphSetName: req.fromGraphSetName });
66
+ let resNodeListSchema = yield this.showNodeSchema({ graphSetName: req.fromGraphSetName });
67
+ let resEdgeListSchema = yield this.showEdgeSchema({ graphSetName: req.fromGraphSetName });
68
+ let copyCommonReq = {
69
+ graphSetName: req.newGraphSetName
70
+ };
71
+ let resListSchema = [{
72
+ listSchema: resNodeListSchema,
73
+ dbType: types_1.ULTIPA.DBType.DBNODE
74
+ }, {
75
+ listSchema: resEdgeListSchema,
76
+ dbType: types_1.ULTIPA.DBType.DBEDGE
77
+ }];
78
+ const createSchema = (listSchema, dbType) => __awaiter(this, void 0, void 0, function* () {
79
+ for (let schemaObj of listSchema === null || listSchema === void 0 ? void 0 : listSchema.data) {
80
+ if (schemaObj.name != "default") {
81
+ let res = yield this.createSchema({
82
+ name: schemaObj.name,
83
+ dbType,
84
+ description: schemaObj.description
85
+ }, false, copyCommonReq);
86
+ if (res.status.code !== success) {
87
+ return res;
88
+ }
89
+ }
90
+ for (let p of schemaObj.properties) {
91
+ if (p.name.startsWith('#'))
92
+ continue;
93
+ let typeCfg = utils_1.PropertyUtils.GetPropertyType(p.type);
94
+ let res = yield this.createProperty(dbType, p.name, Object.assign(Object.assign({}, p), typeCfg), copyCommonReq);
95
+ if (res.status.code !== success) {
96
+ return res;
97
+ }
98
+ }
99
+ // }
100
+ }
101
+ });
102
+ resListSchema.forEach((list) => { createSchema(list.listSchema, list.dbType); });
103
+ return resCreate;
104
+ });
105
+ }
106
+ /** 卸载算法 */
107
+ uninstallAlgo(req, commonReq) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
110
+ try {
111
+ let clientInfo = yield this.getClientInfo({
112
+ graphSetName: commonReq === null || commonReq === void 0 ? void 0 : commonReq.graphSetName,
113
+ clusterId: commonReq === null || commonReq === void 0 ? void 0 : commonReq.clusterId,
114
+ type: types_1.ULTIPA.ClientType.Update,
115
+ isGlobal: true,
116
+ timeZone: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZone,
117
+ timeZoneOffset: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZoneOffset,
118
+ });
119
+ let request = new ultipa_pb_1.UninstallAlgoRequest();
120
+ request.setAlgoName(req.algoName);
121
+ clientInfo.client.controlsClient.uninstallAlgo(request, clientInfo.metadata, (err, reply) => {
122
+ let response = new types_1.ULTIPA.Response();
123
+ if (err) {
124
+ response = utils_1.FormatResponse.unknownError(err, response);
125
+ resolve(response);
126
+ return;
127
+ }
128
+ response = {
129
+ status: utils_1.FormatType.status(reply.getStatus()),
130
+ data: true
131
+ };
132
+ resolve(response);
133
+ });
134
+ }
135
+ catch (error) {
136
+ reject(error);
137
+ }
138
+ }));
139
+ });
140
+ }
141
+ /**卸载HDC算法 */
142
+ uninstallHDCAlgo(algoName, hdcName, commonReq) {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ let req = {
145
+ algoName: algoName,
146
+ hdcName: hdcName
147
+ };
148
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
149
+ try {
150
+ let clientInfo = yield this.getClientInfo({
151
+ graphSetName: commonReq === null || commonReq === void 0 ? void 0 : commonReq.graphSetName,
152
+ clusterId: commonReq === null || commonReq === void 0 ? void 0 : commonReq.clusterId,
153
+ type: types_1.ULTIPA.ClientType.Update,
154
+ isGlobal: true,
155
+ timeZone: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZone,
156
+ timeZoneOffset: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZoneOffset,
157
+ });
158
+ let request = new ultipa_pb_1.UninstallAlgoRequest();
159
+ request.setAlgoName(req.algoName);
160
+ if (req.hdcName) {
161
+ let with_server = new ultipa_pb_1.WithServer();
162
+ with_server.setHdcServerName(req.hdcName);
163
+ request.setWithServer(with_server);
164
+ }
165
+ clientInfo.client.controlsClient.uninstallAlgo(request, clientInfo.metadata, (err, reply) => {
166
+ let response = new types_1.ULTIPA.Response();
167
+ if (err) {
168
+ response = utils_1.FormatResponse.unknownError(err, response);
169
+ resolve(response);
170
+ return;
171
+ }
172
+ response = {
173
+ status: utils_1.FormatType.status(reply.getStatus()),
174
+ data: true
175
+ };
176
+ resolve(response);
177
+ });
178
+ }
179
+ catch (error) {
180
+ reject(error);
181
+ }
182
+ }));
183
+ });
184
+ }
185
+ /** 回滚算法 */
186
+ rollbackAlgo(algoName, hdcName, commonReq) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ let req = {
189
+ algoName, hdcName
190
+ };
191
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
192
+ try {
193
+ let clientInfo = yield this.getClientInfo({
194
+ graphSetName: commonReq === null || commonReq === void 0 ? void 0 : commonReq.graphSetName,
195
+ clusterId: commonReq === null || commonReq === void 0 ? void 0 : commonReq.clusterId,
196
+ type: types_1.ULTIPA.ClientType.Update,
197
+ isGlobal: true,
198
+ timeZone: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZone,
199
+ timeZoneOffset: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZoneOffset,
200
+ });
201
+ let request = new ultipa_pb_1.RollbackAlgoRequest();
202
+ request.setAlgoName(req.algoName);
203
+ let with_server = new ultipa_pb_1.WithServer();
204
+ with_server.setHdcServerName(req.hdcName);
205
+ request.setWithServer(with_server);
206
+ clientInfo.client.controlsClient.rollbackAlgo(request, clientInfo.metadata, (err, reply) => {
207
+ let response = new types_1.ULTIPA.Response();
208
+ if (err) {
209
+ response = utils_1.FormatResponse.unknownError(err, response);
210
+ resolve(response);
211
+ return;
212
+ }
213
+ response = {
214
+ status: utils_1.FormatType.status(reply.getStatus()),
215
+ data: true
216
+ };
217
+ resolve(response);
218
+ });
219
+ }
220
+ catch (error) {
221
+ reject(error);
222
+ }
223
+ }));
224
+ });
225
+ }
226
+ /** 安装算法 */
227
+ installAlgo(req, commonReq) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ return this.installAlgoAio(Object.assign({}, req), commonReq);
230
+ });
231
+ }
232
+ /** 安装HDC算法 */
233
+ installHdcAlgo(soFile, ymlFile, hdcName, commonReq) {
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ let req = {
236
+ soFile: soFile,
237
+ ymlFile: ymlFile,
238
+ hdcName: hdcName
239
+ };
240
+ return this.installAlgoAio({
241
+ hdc: req.hdcName,
242
+ paths: {
243
+ algoFilePath: req.soFile,
244
+ infoFilePath: req.ymlFile
245
+ },
246
+ isHdc: true
247
+ }, commonReq);
248
+ });
249
+ }
250
+ /** 安装算法 */
251
+ installAlgoAio(req, commonReq) {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ if (req.datas) {
254
+ return this._installAlgo(Object.assign(Object.assign({}, req.datas), { isHdc: req === null || req === void 0 ? void 0 : req.isHdc }), commonReq);
255
+ }
256
+ let filePaths = [req.paths.algoFilePath, req.paths.infoFilePath];
257
+ let _req = {
258
+ datas: [],
259
+ isHdc: req.isHdc,
260
+ hdc: req.hdc
261
+ };
262
+ for (let i = 0; i < filePaths.length; i++) {
263
+ const filePath = filePaths[i];
264
+ let chunk = fs.readFileSync(filePath);
265
+ let md5 = crypto_1.default.createHash("md5").update(chunk).digest("hex");
266
+ let fileName = path_1.default.basename(filePath);
267
+ _req.datas.push({
268
+ chunk,
269
+ md5,
270
+ fileName,
271
+ });
272
+ }
273
+ return this._installAlgo(_req, commonReq);
274
+ });
275
+ }
276
+ _installAlgo(req, commonReq) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
279
+ try {
280
+ let clientInfo = yield this.getClientInfo({
281
+ graphSetName: commonReq === null || commonReq === void 0 ? void 0 : commonReq.graphSetName,
282
+ clusterId: commonReq === null || commonReq === void 0 ? void 0 : commonReq.clusterId,
283
+ type: types_1.ULTIPA.ClientType.Update,
284
+ isGlobal: true,
285
+ timeZone: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZone,
286
+ timeZoneOffset: commonReq === null || commonReq === void 0 ? void 0 : commonReq.timeZoneOffset,
287
+ });
288
+ let isError = null;
289
+ let callback = (err, reply) => {
290
+ let response = new types_1.ULTIPA.Response();
291
+ if (err) {
292
+ isError = err;
293
+ response = utils_1.FormatResponse.unknownError(err, response);
294
+ resolve(response);
295
+ return;
296
+ }
297
+ response = {
298
+ status: utils_1.FormatType.status(reply.getStatus()),
299
+ data: true
300
+ };
301
+ resolve(response);
302
+ };
303
+ let v = clientInfo.client.controlsClient.installAlgo(clientInfo.metadata, callback);
304
+ for (let i = 0; i < req.datas.length; i++) {
305
+ if (isError) {
306
+ break;
307
+ }
308
+ const { chunk, md5, fileName } = req.datas[i];
309
+ let request = new ultipa_pb_1.InstallAlgoRequest();
310
+ request.setFileName(fileName);
311
+ request.setMd5(md5);
312
+ if (req === null || req === void 0 ? void 0 : req.isHdc) {
313
+ let ws = new ultipa_pb_1.WithServer();
314
+ ws.setHdcServerName(req.hdc);
315
+ request.setWithServer(ws);
316
+ }
317
+ let bufferSize = 1 * 1024 * 1024;
318
+ let sum = 0;
319
+ console.log("Install Algo", {
320
+ fileName,
321
+ chunkLength: chunk.length,
322
+ md5,
323
+ });
324
+ for (let index = 0; index < chunk.length; index += bufferSize) {
325
+ if (isError) {
326
+ break;
327
+ }
328
+ let sub_chunk = chunk.slice(index, index + bufferSize);
329
+ request.setChunk(sub_chunk);
330
+ sum += sub_chunk.length;
331
+ let sendAlready = () => __awaiter(this, void 0, void 0, function* () {
332
+ return new Promise((resolve, reject) => {
333
+ v.write(request, null, () => {
334
+ // console.log("sending ",index, sub_chunk.length);
335
+ resolve(1);
336
+ });
337
+ });
338
+ });
339
+ yield sendAlready();
340
+ }
341
+ if (!isError) {
342
+ console.log("End and sending sum: ", fileName, sum);
343
+ }
344
+ }
345
+ v.end();
346
+ if (!isError) {
347
+ console.log(`${JSON.stringify(req.datas.map(o => o.fileName))} upload finished!`);
348
+ }
349
+ }
350
+ catch (error) {
351
+ reject(error);
352
+ }
353
+ }));
354
+ });
355
+ }
356
+ insertNodesBatchAuto(rows, config) {
357
+ var _a, _b, _c, _d, _e;
358
+ return __awaiter(this, void 0, void 0, function* () {
359
+ let lastResponse = new types_1.ULTIPA.Response();
360
+ lastResponse.status = utils_1.FormatResponse.successStatus();
361
+ lastResponse.statistics = {
362
+ engineCost: 0,
363
+ totalCost: 0,
364
+ edgeAffected: 0,
365
+ nodeAffected: 0,
366
+ };
367
+ lastResponse.data = {
368
+ ids: [],
369
+ uuids: [],
370
+ ignore_indexes: [],
371
+ ignore_error_codes: [],
372
+ };
373
+ if (!rows || rows.length == 0) {
374
+ return lastResponse;
375
+ }
376
+ let schemas = yield this.showNodeSchema(config);
377
+ let schemaMap = {};
378
+ (_a = schemas.data) === null || _a === void 0 ? void 0 : _a.forEach(s => {
379
+ schemaMap[s.name] = s;
380
+ });
381
+ let batchMap = {};
382
+ rows.forEach((r, index) => {
383
+ r.set("_index", index);
384
+ if (!schemaMap[r.schema]) {
385
+ throw new Error(`Row[${index}] Node Schema not found:[${r.schema}]`);
386
+ }
387
+ if (!batchMap[r.schema]) {
388
+ batchMap[r.schema] = [];
389
+ }
390
+ batchMap[r.schema].push(r);
391
+ });
392
+ let schemaNames = Object.keys(batchMap);
393
+ let mergeResult = lastResponse.data;
394
+ let msgs = [];
395
+ for (let index = 0; index < schemaNames.length; index++) {
396
+ const schemaName = schemaNames[index];
397
+ let s = schemaMap[schemaName];
398
+ let newS = {
399
+ dbType: types_1.ULTIPA.DBType.DBNODE,
400
+ name: s.name,
401
+ properties: s.properties.map(o => {
402
+ let typeObj = utils_1.PropertyUtils.GetPropertyType(o.type);
403
+ return {
404
+ name: o.name,
405
+ type: typeObj.type,
406
+ subTypes: typeObj.subTypes,
407
+ };
408
+ }),
409
+ };
410
+ let insertRows = batchMap[schemaName];
411
+ let nodeTable = utils_1.FormatType.toNodeTableWithSchema(newS, insertRows, this.getTimeZoneType(config));
412
+ let res = yield this.insertNodesBatch(nodeTable, config);
413
+ if (res.status.code != types_1.ULTIPA.Code.SUCCESS) {
414
+ let code = res.status.code;
415
+ lastResponse.status.code = code;
416
+ lastResponse.status.code_desc = types_1.ULTIPA.Code[code];
417
+ msgs.push(`${schemaName}: ${res.status.message}`);
418
+ }
419
+ var ignoreIndexes = [];
420
+ (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.ignore_indexes.forEach(i => {
421
+ ignoreIndexes.push(insertRows[i].get("_index"));
422
+ });
423
+ mergeResult.ids.push(...(((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.ids) || []));
424
+ mergeResult.uuids.push(...(((_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.uuids) || []));
425
+ mergeResult.ignore_indexes.push(...ignoreIndexes);
426
+ mergeResult.ignore_error_codes.push(...(((_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.ignore_error_codes) || []));
427
+ lastResponse.statistics = utils_1.FormatResponse.statisticsSum(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.statistics, res === null || res === void 0 ? void 0 : res.statistics);
428
+ }
429
+ if (msgs.length > 0) {
430
+ lastResponse.status.message = msgs.join(";");
431
+ }
432
+ return lastResponse;
433
+ });
434
+ }
435
+ /**
436
+ * 插入大量的点
437
+ */
438
+ insertHugeNodes(req, config) {
439
+ return __awaiter(this, void 0, void 0, function* () {
440
+ let res_properties = yield this.showNodeProperty(req.schemaName, config);
441
+ let propertyTypeObject = utils_1.FormatType.toPropertyTypeObject(res_properties.data);
442
+ let nodeTable = utils_1.FormatType.toNodeTable(propertyTypeObject, req.schemaName, req.headers, req.rows, this.getTimeZoneType(config));
443
+ return this.insertNodesBatch(nodeTable, config);
444
+ });
445
+ }
446
+ validEdgeRows(rows) {
447
+ let validResult = {
448
+ ok: true
449
+ };
450
+ let setFailed = (index, msg) => {
451
+ validResult.ok = false;
452
+ validResult.msg = msg;
453
+ validResult.failedIndex = index;
454
+ };
455
+ for (let index = 0; index < rows.length; index++) {
456
+ const row = rows[index];
457
+ if (!row._to && !row._from) {
458
+ let msg = `_from/_from_uuid and _to/_to_uuid are null`;
459
+ setFailed(index, msg);
460
+ break;
461
+ }
462
+ if (row._from && !row._to) {
463
+ let msg = `_from has value [${row._from}] but _to got ${row._to}`;
464
+ setFailed(index, msg);
465
+ break;
466
+ }
467
+ if (row._to && !row._from) {
468
+ let msg = `_to has value [${row._to}] but _from got ${row._from}`;
469
+ setFailed(index, msg);
470
+ break;
471
+ }
472
+ }
473
+ return validResult;
474
+ }
475
+ insertEdgesBatchAuto(rows, config) {
476
+ var _a, _b, _c, _d, _e;
477
+ return __awaiter(this, void 0, void 0, function* () {
478
+ let valid = this.validEdgeRows(rows);
479
+ if (!valid.ok) {
480
+ throw new Error(`row[${valid.failedIndex}] error: ${valid.msg}`);
481
+ }
482
+ let lastResponse = new types_1.ULTIPA.Response();
483
+ lastResponse.status = utils_1.FormatResponse.successStatus();
484
+ lastResponse.statistics = { engineCost: 0, totalCost: 0 };
485
+ lastResponse.data = {
486
+ uuids: [],
487
+ ignore_indexes: [],
488
+ ignore_error_codes: [],
489
+ edges: [],
490
+ };
491
+ if (!rows || rows.length == 0) {
492
+ return lastResponse;
493
+ }
494
+ let schemas = yield this.showEdgeSchema(config);
495
+ let schemaMap = {};
496
+ (_a = schemas.data) === null || _a === void 0 ? void 0 : _a.forEach(s => {
497
+ schemaMap[s.name] = s;
498
+ });
499
+ let batchMap = {};
500
+ rows.forEach((r, index) => {
501
+ r.set("_index", index);
502
+ if (!schemaMap[r.schema]) {
503
+ throw new Error(`Row[${index}] Edge Schema not found:[${r.schema}]`);
504
+ }
505
+ if (!batchMap[r.schema]) {
506
+ batchMap[r.schema] = [];
507
+ }
508
+ batchMap[r.schema].push(r);
509
+ });
510
+ let schemaNames = Object.keys(batchMap);
511
+ let mergeResult = lastResponse.data;
512
+ let msgs = [];
513
+ for (let index = 0; index < schemaNames.length; index++) {
514
+ const schemaName = schemaNames[index];
515
+ let s = schemaMap[schemaName];
516
+ let newS = {
517
+ name: s.name,
518
+ properties: s.properties.map(o => {
519
+ let typeObj = utils_1.PropertyUtils.GetPropertyType(o.type);
520
+ return {
521
+ name: o.name,
522
+ type: typeObj.type,
523
+ subTypes: typeObj.subTypes,
524
+ };
525
+ }),
526
+ };
527
+ let insertRows = batchMap[schemaName];
528
+ let table = utils_1.FormatType.toEdgeTableWithSchema(newS, insertRows, this.getTimeZoneType(config));
529
+ let res = yield this.insertEdgesBatch(table, config);
530
+ if (res.status.code != types_1.ULTIPA.Code.SUCCESS) {
531
+ let code = res.status.code;
532
+ lastResponse.status.code = code;
533
+ lastResponse.status.code_desc = types_1.ULTIPA.Code[code];
534
+ msgs.push(`${schemaName}: ${res.status.message}`);
535
+ }
536
+ var ignoreIndexes = [];
537
+ (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.ignore_indexes.forEach(i => {
538
+ ignoreIndexes.push(insertRows[i].get("_index"));
539
+ });
540
+ mergeResult.uuids.push(...(((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.uuids) || []));
541
+ mergeResult.edges.push(...(((_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.edges) || []));
542
+ mergeResult.ignore_indexes.push(...ignoreIndexes);
543
+ mergeResult.ignore_error_codes.push(...(((_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.ignore_error_codes) || []));
544
+ lastResponse.statistics = utils_1.FormatResponse.statisticsSum(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.statistics, res === null || res === void 0 ? void 0 : res.statistics);
545
+ }
546
+ if (msgs.length > 0) {
547
+ lastResponse.status.message = msgs.join(";");
548
+ }
549
+ return lastResponse;
550
+ });
551
+ }
552
+ /**
553
+ * 插入大量的边
554
+ */
555
+ insertHugeEdges(req, config) {
556
+ return __awaiter(this, void 0, void 0, function* () {
557
+ let res_properties = yield this.showEdgeProperty(req.schemaName, config);
558
+ let propertyTypeObject = utils_1.FormatType.toPropertyTypeObject(res_properties.data);
559
+ let table = utils_1.FormatType.toEdgeTable(propertyTypeObject, req.schemaName, req.headers, req.rows, this.getTimeZoneType(config));
560
+ return this.insertEdgesBatch(table, config);
561
+ });
562
+ }
563
+ /**
564
+ * 查看HDC算法
565
+ * @param hdcName
566
+ */
567
+ showHdcAlgo(hdcName, requestConfig) {
568
+ var _a;
569
+ return __awaiter(this, void 0, void 0, function* () {
570
+ let command = utils_1.UQLMAKER.CommandList.showHDCAlgo;
571
+ let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, hdcName);
572
+ let res = yield connection_base_1.ConnectionBase.UqlListSimpleAuto(this, uqlMaker);
573
+ let data = (_a = res.data) === null || _a === void 0 ? void 0 : _a.filter(d => { if (d.name == `_algoList_from_${hdcName}`) {
574
+ return d;
575
+ } });
576
+ let algoList = [...data[0].values];
577
+ return Object.assign(Object.assign({}, res), { data: algoList });
578
+ });
579
+ }
580
+ /** 创建点或者边的schema */
581
+ createSchema(schema, isCreateProperties = false, requestConfig) {
582
+ var _a;
583
+ return __awaiter(this, void 0, void 0, function* () {
584
+ let command = schema.dbType === types_1.ULTIPA.DBType.DBNODE
585
+ ? CommandList.createNodeSchema
586
+ : CommandList.createEdgeSchema;
587
+ let commandParams = [utils_1.UQLMAKER.ForceString(schema.name), schema.description || ""];
588
+ let uqlMaker = new utils_1.UQLMAKER(command, requestConfig, commandParams);
589
+ let response = connection_base_1.ConnectionBase.UqlUpdateSimple(this, uqlMaker);
590
+ if (isCreateProperties) {
591
+ (_a = schema.properties) === null || _a === void 0 ? void 0 : _a.forEach(prop => {
592
+ this.createProperty(schema.dbType, schema.name, Object.assign(Object.assign({}, prop), { schema: schema.name }), requestConfig);
593
+ });
594
+ }
595
+ return response;
596
+ });
597
+ }
598
+ }
599
+ exports.ConnectionFinal = ConnectionFinal;
600
+ //# sourceMappingURL=connection.final.js.map