@ultipa-graph/ultipa-driver 5.1.4-s5.1 → 6.0.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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/dist/client.d.ts +194 -0
  4. package/dist/client.js +390 -0
  5. package/dist/config.d.ts +65 -0
  6. package/dist/config.js +135 -0
  7. package/dist/connection.d.ts +30 -0
  8. package/dist/connection.js +190 -0
  9. package/dist/errors.d.ts +99 -0
  10. package/dist/errors.js +237 -0
  11. package/dist/index.d.ts +14 -5
  12. package/dist/index.js +88 -39
  13. package/dist/printers.d.ts +33 -0
  14. package/dist/printers.js +312 -0
  15. package/dist/proto/gqldb.proto +632 -0
  16. package/dist/response.d.ts +256 -0
  17. package/dist/response.js +723 -0
  18. package/dist/services/admin-service.d.ts +40 -0
  19. package/dist/services/admin-service.js +115 -0
  20. package/dist/services/bulk-import-service.d.ts +35 -0
  21. package/dist/services/bulk-import-service.js +108 -0
  22. package/dist/services/converters.d.ts +57 -0
  23. package/dist/services/converters.js +254 -0
  24. package/dist/services/data-service.d.ts +44 -0
  25. package/dist/services/data-service.js +206 -0
  26. package/dist/services/graph-service.d.ts +32 -0
  27. package/dist/services/graph-service.js +127 -0
  28. package/dist/services/health-service.d.ts +50 -0
  29. package/dist/services/health-service.js +78 -0
  30. package/dist/services/index.d.ts +13 -0
  31. package/dist/services/index.js +30 -0
  32. package/dist/services/query-service.d.ts +39 -0
  33. package/dist/services/query-service.js +112 -0
  34. package/dist/services/service-context.d.ts +39 -0
  35. package/dist/services/service-context.js +73 -0
  36. package/dist/services/session-service.d.ts +24 -0
  37. package/dist/services/session-service.js +66 -0
  38. package/dist/services/transaction-service.d.ts +33 -0
  39. package/dist/services/transaction-service.js +100 -0
  40. package/dist/services.d.ts +28 -0
  41. package/dist/services.js +122 -0
  42. package/dist/session.d.ts +45 -0
  43. package/dist/session.js +75 -0
  44. package/dist/transaction.d.ts +42 -0
  45. package/dist/transaction.js +89 -0
  46. package/dist/types/bulk_import.d.ts +53 -0
  47. package/dist/types/bulk_import.js +6 -0
  48. package/dist/types/data_types.d.ts +116 -0
  49. package/dist/types/data_types.js +122 -0
  50. package/dist/types/enums.d.ts +59 -0
  51. package/dist/types/enums.js +67 -0
  52. package/dist/types/graph_models.d.ts +54 -0
  53. package/dist/types/graph_models.js +6 -0
  54. package/dist/types/index.d.ts +11 -5
  55. package/dist/types/index.js +36 -37
  56. package/dist/types/metadata.d.ts +60 -0
  57. package/dist/types/metadata.js +6 -0
  58. package/dist/types/schema.d.ts +31 -0
  59. package/dist/types/schema.js +6 -0
  60. package/dist/types/typed_value.d.ts +25 -0
  61. package/dist/types/typed_value.js +1176 -0
  62. package/dist/types/wrappers.d.ts +23 -0
  63. package/dist/types/wrappers.js +39 -0
  64. package/dist/types.d.ts +7 -0
  65. package/dist/types.js +24 -0
  66. package/package.json +40 -53
  67. package/dist/connection/connection.final.d.ts +0 -14
  68. package/dist/connection/connection.final.js +0 -96
  69. package/dist/connection/connection.final.js.map +0 -1
  70. package/dist/connection/connection.pool.d.ts +0 -21
  71. package/dist/connection/connection.pool.js +0 -103
  72. package/dist/connection/connection.pool.js.map +0 -1
  73. package/dist/connection/extra/base.extra.d.ts +0 -18
  74. package/dist/connection/extra/base.extra.js +0 -111
  75. package/dist/connection/extra/base.extra.js.map +0 -1
  76. package/dist/connection/extra/batch.insert.extra.d.ts +0 -58
  77. package/dist/connection/extra/batch.insert.extra.js +0 -353
  78. package/dist/connection/extra/batch.insert.extra.js.map +0 -1
  79. package/dist/connection/extra/connection.base.d.ts +0 -112
  80. package/dist/connection/extra/connection.base.js +0 -528
  81. package/dist/connection/extra/connection.base.js.map +0 -1
  82. package/dist/connection/extra/connection.d.ts +0 -17
  83. package/dist/connection/extra/connection.js +0 -44
  84. package/dist/connection/extra/connection.js.map +0 -1
  85. package/dist/connection/extra/graph.extra.d.ts +0 -54
  86. package/dist/connection/extra/graph.extra.js +0 -151
  87. package/dist/connection/extra/graph.extra.js.map +0 -1
  88. package/dist/connection/extra/hdc.extra.d.ts +0 -89
  89. package/dist/connection/extra/hdc.extra.js +0 -322
  90. package/dist/connection/extra/hdc.extra.js.map +0 -1
  91. package/dist/connection/extra/index.extra.d.ts +0 -102
  92. package/dist/connection/extra/index.extra.js +0 -210
  93. package/dist/connection/extra/index.extra.js.map +0 -1
  94. package/dist/connection/extra/job.extra.d.ts +0 -32
  95. package/dist/connection/extra/job.extra.js +0 -122
  96. package/dist/connection/extra/job.extra.js.map +0 -1
  97. package/dist/connection/extra/policy.extra.d.ts +0 -32
  98. package/dist/connection/extra/policy.extra.js +0 -114
  99. package/dist/connection/extra/policy.extra.js.map +0 -1
  100. package/dist/connection/extra/privilege.extra.d.ts +0 -8
  101. package/dist/connection/extra/privilege.extra.js +0 -20
  102. package/dist/connection/extra/privilege.extra.js.map +0 -1
  103. package/dist/connection/extra/property.extra.d.ts +0 -66
  104. package/dist/connection/extra/property.extra.js +0 -190
  105. package/dist/connection/extra/property.extra.js.map +0 -1
  106. package/dist/connection/extra/schema.extra.d.ts +0 -108
  107. package/dist/connection/extra/schema.extra.js +0 -253
  108. package/dist/connection/extra/schema.extra.js.map +0 -1
  109. package/dist/connection/extra/user.extra.d.ts +0 -28
  110. package/dist/connection/extra/user.extra.js +0 -91
  111. package/dist/connection/extra/user.extra.js.map +0 -1
  112. package/dist/connection/index.d.ts +0 -5
  113. package/dist/connection/index.js +0 -13
  114. package/dist/connection/index.js.map +0 -1
  115. package/dist/connection/network.manager.d.ts +0 -28
  116. package/dist/connection/network.manager.js +0 -179
  117. package/dist/connection/network.manager.js.map +0 -1
  118. package/dist/index.js.map +0 -1
  119. package/dist/printers/alias.d.ts +0 -2
  120. package/dist/printers/alias.js +0 -39
  121. package/dist/printers/alias.js.map +0 -1
  122. package/dist/printers/any.d.ts +0 -2
  123. package/dist/printers/any.js +0 -63
  124. package/dist/printers/any.js.map +0 -1
  125. package/dist/printers/array.aio.d.ts +0 -3
  126. package/dist/printers/array.aio.js +0 -259
  127. package/dist/printers/array.aio.js.map +0 -1
  128. package/dist/printers/edge.d.ts +0 -5
  129. package/dist/printers/edge.js +0 -78
  130. package/dist/printers/edge.js.map +0 -1
  131. package/dist/printers/explain.plan.d.ts +0 -2
  132. package/dist/printers/explain.plan.js +0 -46
  133. package/dist/printers/explain.plan.js.map +0 -1
  134. package/dist/printers/index.d.ts +0 -24
  135. package/dist/printers/index.js +0 -43
  136. package/dist/printers/index.js.map +0 -1
  137. package/dist/printers/node.d.ts +0 -5
  138. package/dist/printers/node.js +0 -77
  139. package/dist/printers/node.js.map +0 -1
  140. package/dist/printers/path.d.ts +0 -3
  141. package/dist/printers/path.js +0 -62
  142. package/dist/printers/path.js.map +0 -1
  143. package/dist/printers/status.d.ts +0 -3
  144. package/dist/printers/status.js +0 -68
  145. package/dist/printers/status.js.map +0 -1
  146. package/dist/printers/table.d.ts +0 -2
  147. package/dist/printers/table.js +0 -56
  148. package/dist/printers/table.js.map +0 -1
  149. package/dist/proto/tmp.js +0 -366
  150. package/dist/proto/ultipa_grpc_pb.d.ts +0 -258
  151. package/dist/proto/ultipa_grpc_pb.js +0 -366
  152. package/dist/proto/ultipa_grpc_pb.js.map +0 -1
  153. package/dist/proto/ultipa_pb.d.ts +0 -1
  154. package/dist/proto/ultipa_pb.js +0 -11002
  155. package/dist/proto/ultipa_pb.js.map +0 -1
  156. package/dist/types/index.js.map +0 -1
  157. package/dist/types/types.algos.params.d.ts +0 -545
  158. package/dist/types/types.algos.params.js +0 -16
  159. package/dist/types/types.algos.params.js.map +0 -1
  160. package/dist/types/types.d.ts +0 -1204
  161. package/dist/types/types.extra.d.ts +0 -146
  162. package/dist/types/types.extra.js +0 -27
  163. package/dist/types/types.extra.js.map +0 -1
  164. package/dist/types/types.js +0 -1596
  165. package/dist/types/types.js.map +0 -1
  166. package/dist/types/util.d.ts +0 -15
  167. package/dist/types/util.js +0 -136
  168. package/dist/types/util.js.map +0 -1
  169. package/dist/utils/common.d.ts +0 -3
  170. package/dist/utils/common.js +0 -22
  171. package/dist/utils/common.js.map +0 -1
  172. package/dist/utils/format.d.ts +0 -45
  173. package/dist/utils/format.js +0 -877
  174. package/dist/utils/format.js.map +0 -1
  175. package/dist/utils/index.d.ts +0 -10
  176. package/dist/utils/index.js +0 -30
  177. package/dist/utils/index.js.map +0 -1
  178. package/dist/utils/property.d.ts +0 -18
  179. package/dist/utils/property.js +0 -153
  180. package/dist/utils/property.js.map +0 -1
  181. package/dist/utils/serialize/commont.d.ts +0 -12
  182. package/dist/utils/serialize/commont.js +0 -46
  183. package/dist/utils/serialize/commont.js.map +0 -1
  184. package/dist/utils/serialize/deserialize.d.ts +0 -9
  185. package/dist/utils/serialize/deserialize.js +0 -166
  186. package/dist/utils/serialize/deserialize.js.map +0 -1
  187. package/dist/utils/serialize/null.d.ts +0 -25
  188. package/dist/utils/serialize/null.js +0 -136
  189. package/dist/utils/serialize/null.js.map +0 -1
  190. package/dist/utils/serialize/serialize.d.ts +0 -10
  191. package/dist/utils/serialize/serialize.js +0 -144
  192. package/dist/utils/serialize/serialize.js.map +0 -1
  193. package/dist/utils/stream.helper.d.ts +0 -10
  194. package/dist/utils/stream.helper.js +0 -71
  195. package/dist/utils/stream.helper.js.map +0 -1
  196. package/dist/utils/time.record.d.ts +0 -15
  197. package/dist/utils/time.record.js +0 -52
  198. package/dist/utils/time.record.js.map +0 -1
  199. package/dist/utils/ultipa.datetime.d.ts +0 -14
  200. package/dist/utils/ultipa.datetime.js +0 -160
  201. package/dist/utils/ultipa.datetime.js.map +0 -1
  202. package/dist/utils/uql-maker.d.ts +0 -165
  203. package/dist/utils/uql-maker.js +0 -402
  204. package/dist/utils/uql-maker.js.map +0 -1
  205. package/dist/utils/uql.parse.d.ts +0 -27
  206. package/dist/utils/uql.parse.js +0 -205
  207. package/dist/utils/uql.parse.js.map +0 -1
  208. package/readme.md +0 -65
  209. package/src/proto/build.sh +0 -41
  210. package/src/proto/build_windows.sh +0 -40
  211. package/src/proto/ultipa.proto +0 -492
  212. package/src/proto/ultipa_grpc_pb.d.ts +0 -92
  213. package/src/proto/ultipa_grpc_pb.js +0 -414
  214. package/src/proto/ultipa_pb.d.ts +0 -1806
  215. package/src/proto/ultipa_pb.js +0 -13499
@@ -1,877 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.FormatResponse = exports.FormatType = exports.mergeQueryResponse = void 0;
30
- const ultipa_pb_1 = require("../proto/ultipa_pb");
31
- const ULTIPA = __importStar(require("../types/types"));
32
- const lodash_1 = __importDefault(require("lodash"));
33
- const index_1 = require("../utils/index");
34
- const types_1 = require("../types/types");
35
- let ULITPA_PRIVATE_KEYS = {
36
- id: "_id",
37
- from: "_from",
38
- to: "_to",
39
- uuid: "_uuid",
40
- from_uuid: "_from_uuid",
41
- to_uuid: "_to_uuid",
42
- };
43
- const _mapValues = (values, types, timezone) => {
44
- let result = {};
45
- values.forEach((v, index) => {
46
- let pty = types[index];
47
- result[pty.getPropertyName()] = index_1.DESERIALIZE.deserialize(v, pty.getPropertyType(), pty.getSubTypesList(), timezone);
48
- });
49
- return result;
50
- };
51
- const DataMerge = {
52
- arrayDiff: (arr1, arr2) => {
53
- let diff = [];
54
- arr2.forEach((s) => {
55
- if (!arr1.includes(s)) {
56
- diff.push(s);
57
- }
58
- });
59
- return diff;
60
- },
61
- merge: (o1, o2, ignoreKeys) => {
62
- if (!o2) {
63
- return o1;
64
- }
65
- function customizer(objValue, srcValue, key) {
66
- if (ignoreKeys && ignoreKeys.includes(key)) {
67
- return srcValue;
68
- }
69
- if (lodash_1.default.isArray(srcValue)) {
70
- return srcValue.concat(objValue);
71
- }
72
- }
73
- return lodash_1.default.mergeWith(o2, o1, customizer);
74
- },
75
- concat: (arr1, arr2, byKey, ignoreKeys) => {
76
- if (!arr2?.length) {
77
- return arr1;
78
- }
79
- if (byKey) {
80
- let newArray = [...arr1];
81
- let diff = DataMerge.arrayDiff(arr1.map((o) => o[byKey]), arr2.map((o) => o[byKey]));
82
- diff.forEach((k) => newArray.push({
83
- [byKey]: k,
84
- }));
85
- let results = [];
86
- newArray.forEach((o) => {
87
- let newObj = o;
88
- let finds = arr2.filter((o2) => {
89
- return o2[byKey] == o[byKey];
90
- });
91
- finds.forEach((f) => {
92
- newObj = DataMerge.merge(newObj, f, ignoreKeys);
93
- });
94
- results.push(newObj);
95
- });
96
- return results;
97
- }
98
- return [...arr1, ...arr2];
99
- },
100
- };
101
- const mergeQueryResponse = (res1, res2) => {
102
- if (!res1.explainPlan) {
103
- res1.explainPlan = new ULTIPA.ExplainPlan();
104
- }
105
- res1.status = res2.status;
106
- if (!res2?.items) {
107
- return res1;
108
- }
109
- res1.aliases = res1.aliases || [];
110
- const aliasMap = new Map();
111
- [...res1.aliases, ...(res2.aliases || [])].forEach(alias => {
112
- if (alias.type === 0) {
113
- return;
114
- }
115
- const existingAlias = aliasMap.get(alias.name);
116
- if (existingAlias) {
117
- if (existingAlias.type === 0 && alias.type !== 0) {
118
- aliasMap.set(alias.name, alias);
119
- }
120
- }
121
- else {
122
- aliasMap.set(alias.name, alias);
123
- }
124
- });
125
- res1.aliases = Array.from(aliasMap.values());
126
- res1.explainPlan.planNodes = res1.explainPlan?.planNodes || [];
127
- res1.explainPlan.planNodes = [...new Set([...res1.explainPlan.planNodes, ...(res2.explainPlan?.planNodes || [])].map(item => JSON.stringify(item)))].map(item => JSON.parse(item));
128
- res1.items = res1.items || {};
129
- for (const [key, value] of Object.entries(res2.items)) {
130
- if (key in res1.items) {
131
- const existingItem = res1.items[key];
132
- switch (existingItem.type) {
133
- case ULTIPA.ResultType.RESULT_TYPE_TABLE:
134
- existingItem.entities.rows = [...existingItem.entities.rows, ...value.entities.rows];
135
- break;
136
- case ULTIPA.ResultType.RESULT_TYPE_PATH:
137
- if (!existingItem.entities) {
138
- existingItem.entities = [];
139
- }
140
- existingItem.entities.paths = [...existingItem.entities.paths, ...value.entities.paths];
141
- Object.entries(value.entities.nodes).forEach(([uuid, node]) => {
142
- existingItem.entities.nodes[uuid] = node;
143
- });
144
- Object.entries(value.entities.edges).forEach(([uuid, edge]) => {
145
- existingItem.entities.edges[uuid] = edge;
146
- });
147
- break;
148
- case ULTIPA.ResultType.RESULT_TYPE_NODE:
149
- case ULTIPA.ResultType.RESULT_TYPE_EDGE:
150
- if (!existingItem.entities) {
151
- existingItem.entities = [];
152
- }
153
- if (!value.entities) {
154
- value.entities = [];
155
- }
156
- existingItem.entities = [...existingItem.entities, ...value.entities];
157
- break;
158
- case ULTIPA.ResultType.RESULT_TYPE_ATTR:
159
- if (!existingItem.entities) {
160
- existingItem.entities = new ULTIPA.Attr();
161
- }
162
- if (!value.entities) {
163
- value.entities = new ULTIPA.Attr();
164
- }
165
- existingItem.entities.values = [
166
- ...(existingItem.entities.values || []),
167
- ...(value.entities.values || [])
168
- ];
169
- break;
170
- default:
171
- if (!existingItem.entities) {
172
- existingItem.entities = [];
173
- }
174
- if (!value.entities) {
175
- value.entities = [];
176
- }
177
- existingItem.entities = [...existingItem.entities, ...value.entities];
178
- }
179
- res1.items[key] = existingItem;
180
- }
181
- else {
182
- res1.items[key] = value;
183
- }
184
- }
185
- if (res2?.statistics) {
186
- res1.statistics = res1.statistics || { totalCost: 0, engineCost: 0 };
187
- res1.statistics.totalCost += res2.statistics.totalCost;
188
- res1.statistics.engineCost += res2.statistics.engineCost;
189
- }
190
- return res1;
191
- };
192
- exports.mergeQueryResponse = mergeQueryResponse;
193
- exports.FormatType = {
194
- queryResponse: (res, timezone) => {
195
- let response = new ULTIPA.Response();
196
- if (res.hasStatus()) {
197
- response.status = exports.FormatType.status(res.getStatus());
198
- }
199
- else {
200
- response.status = exports.FormatResponse.successStatus();
201
- }
202
- let statistics = exports.FormatType.table(res.getStatistics(), timezone)?.toKV()?.[0];
203
- if (statistics) {
204
- statistics = {
205
- totalCost: +statistics.total_time_cost || 0,
206
- engineCost: +statistics.engine_time_cost || 0,
207
- nodeAffected: +statistics.node_affected || 0,
208
- edgeAffected: +statistics.edge_affected || 0,
209
- };
210
- }
211
- response.statistics = statistics;
212
- response.aliases = res.getAliasList().map(i => ({ name: i.getAlias(), type: i.getResultType() }));
213
- response.explainPlan = exports.FormatType.explainPlan(res.getExplainPlan());
214
- let items = {};
215
- res.getNodesList()?.forEach((nodeTableData) => {
216
- let dataItem = new types_1.DataItem(nodeTableData.getAlias(), ULTIPA.ResultType.RESULT_TYPE_NODE, exports.FormatType.nodeTable(nodeTableData.getNodeTable(), timezone));
217
- items[dataItem.alias] = dataItem;
218
- });
219
- res.getEdgesList()?.forEach((edgeTableData) => {
220
- let dataItem = new types_1.DataItem(edgeTableData.getAlias(), ULTIPA.ResultType.RESULT_TYPE_EDGE, exports.FormatType.edgeTable(edgeTableData.getEdgeTable(), timezone));
221
- items[dataItem.alias] = dataItem;
222
- });
223
- res.getPathsList()?.forEach((pathTableData) => {
224
- let dataItem = new types_1.DataItem(pathTableData.getAlias(), ULTIPA.ResultType.RESULT_TYPE_PATH, exports.FormatType.graph(pathTableData.getPathsList(), timezone));
225
- items[dataItem.alias] = dataItem;
226
- });
227
- res.getAttrsList()?.forEach((attrTableData) => {
228
- let attr = exports.FormatType.attr(attrTableData.getAttr(), timezone);
229
- attr.name = attrTableData.getAlias();
230
- attr.resultType = ULTIPA.ResultType.RESULT_TYPE_ATTR;
231
- let dataItem = new types_1.DataItem(attrTableData.getAlias(), ULTIPA.ResultType.RESULT_TYPE_ATTR, attr);
232
- const existingAliasIndex = response.aliases.findIndex(a => a.name === attrTableData.getAlias());
233
- if (existingAliasIndex !== -1) {
234
- response.aliases[existingAliasIndex].type = ULTIPA.ResultType.RESULT_TYPE_ATTR;
235
- }
236
- else {
237
- response.aliases.push({ name: attrTableData.getAlias(), type: ULTIPA.ResultType.RESULT_TYPE_ATTR });
238
- }
239
- items[dataItem.alias] = dataItem;
240
- });
241
- res.getTablesList()?.forEach((tableData) => {
242
- let dataItem = new types_1.DataItem(tableData.getTableName(), ULTIPA.ResultType.RESULT_TYPE_TABLE, exports.FormatType.table(tableData, timezone));
243
- items[dataItem.alias] = dataItem;
244
- });
245
- response.items = items;
246
- return response;
247
- },
248
- status: (statusData, p) => {
249
- let status = {
250
- code: ULTIPA.ErrorCode.SUCCESS,
251
- message: ULTIPA.ErrorCode[ultipa_pb_1.ErrorCode.SUCCESS],
252
- };
253
- if (statusData !== undefined) {
254
- status.code = statusData.getErrorCode();
255
- status.message = statusData.getMsg();
256
- }
257
- if (statusData?.getErrorCode() === ULTIPA.ErrorCode.SUCCESS) {
258
- status.message = ULTIPA.ErrorCode[ultipa_pb_1.ErrorCode.SUCCESS];
259
- }
260
- return status;
261
- },
262
- alias: (resultAlias) => {
263
- return resultAlias.map(alias => ({ name: alias.getAlias(), type: alias.getResultType() }));
264
- },
265
- keyValue: (keyValuesData) => {
266
- if (!keyValuesData || keyValuesData.length == 0) {
267
- return {};
268
- }
269
- let keyValue = {};
270
- keyValuesData.forEach((kv) => {
271
- keyValue[kv.getKey()] = kv.getValue();
272
- });
273
- return keyValue;
274
- },
275
- paths: (paths) => {
276
- let newPaths = [];
277
- paths.forEach(o => {
278
- let p = new ULTIPA.Path();
279
- p.nodeUuids = exports.FormatType.uuids(o.getNodeTable());
280
- p.edgeUuids = exports.FormatType.uuids(o.getEdgeTable());
281
- // p.length = p.edges.keys.length
282
- newPaths.push(p);
283
- });
284
- return newPaths;
285
- },
286
- graph: (paths, timezone) => {
287
- let graph = new ULTIPA.Graph();
288
- graph.paths = exports.FormatType.paths(paths);
289
- graph.nodes ??= new Map();
290
- graph.edges ??= new Map();
291
- paths.forEach(o => {
292
- let nodes = exports.FormatType.nodeTable(o.getNodeTable(), timezone);
293
- nodes.forEach(n => {
294
- graph.nodes.set(n.uuid, n);
295
- });
296
- let edges = exports.FormatType.edgeTable(o.getEdgeTable(), timezone);
297
- edges.forEach(e => {
298
- graph.edges.set(e.uuid, e);
299
- });
300
- });
301
- return graph;
302
- },
303
- explainPlan: (data) => {
304
- if (!data) {
305
- return null;
306
- }
307
- let explainPlan = {
308
- planNodes: []
309
- };
310
- let planNodes = [];
311
- data.getPlanNodesList().forEach(plan => {
312
- let one = {
313
- alias: plan.getAlias(),
314
- childrenNum: plan.getChildrenNum(),
315
- infos: plan.getInfos(),
316
- uql: plan.getQueryText(),
317
- };
318
- planNodes.push(one);
319
- });
320
- explainPlan.planNodes = planNodes;
321
- return explainPlan;
322
- },
323
- table: (tableData, timezone) => {
324
- if (!tableData) {
325
- return null;
326
- }
327
- let tableRows = [];
328
- let tableHeaders = [];
329
- tableData.getHeadersList().forEach(h => {
330
- let header = new types_1.Header();
331
- header.propertyName = h.getPropertyName();
332
- header.propertyType = h.getPropertyType();
333
- tableHeaders.push(header);
334
- });
335
- tableData.getTableRowsList().forEach((tableRowData) => {
336
- let values = [];
337
- tableRowData.getValuesList_asU8().forEach((v, i) => {
338
- let header = tableHeaders[i];
339
- values.push(index_1.DESERIALIZE.deserialize(v, header.propertyType, undefined, timezone));
340
- });
341
- tableRows.push(values);
342
- });
343
- let t = new ULTIPA.Table();
344
- t.name = tableData.getTableName();
345
- t.headers = tableHeaders;
346
- t.rows = tableRows;
347
- return t;
348
- },
349
- tables: (tablesData, timezone) => {
350
- if (!tablesData || tablesData.length == 0) {
351
- return [];
352
- }
353
- let tables = [];
354
- tablesData.forEach((tableData) => {
355
- tables.push(exports.FormatType.table(tableData, timezone));
356
- });
357
- return tables;
358
- },
359
- toEdgeTable: (propertyTypeObject, schemaName, headers, rows, timezone) => {
360
- let edgeTable = new ultipa_pb_1.EntityTable();
361
- let handles = [ULITPA_PRIVATE_KEYS.uuid, ULITPA_PRIVATE_KEYS.from, ULITPA_PRIVATE_KEYS.to, ULITPA_PRIVATE_KEYS.from_uuid, ULITPA_PRIVATE_KEYS.to_uuid];
362
- let schemaHeaders = [];
363
- let schemaHeader = new ultipa_pb_1.Schema();
364
- schemaHeader.setSchemaName(schemaName);
365
- let headerList = [];
366
- headers.forEach((h) => {
367
- if (handles.includes(h)) {
368
- return;
369
- }
370
- let header = new ultipa_pb_1.Property();
371
- header.setPropertyName(h);
372
- let typeCfg = index_1.PropertyUtils.GetPropertyType(propertyTypeObject[h]);
373
- header.setPropertyType(typeCfg.type);
374
- if (typeCfg.subTypes) {
375
- header.setSubTypesList(typeCfg.subTypes);
376
- }
377
- headerList.push(header);
378
- });
379
- schemaHeader.setPropertiesList(headerList);
380
- schemaHeaders.push(schemaHeader);
381
- edgeTable.setSchemasList(schemaHeaders);
382
- let edgeRowsList = [];
383
- rows.forEach(rowsObj => {
384
- let edgeRow = new ultipa_pb_1.EntityRow();
385
- if (!rowsObj) {
386
- edgeRow.setIsNull(true);
387
- edgeRowsList.push(edgeRow);
388
- return;
389
- }
390
- edgeRow.setSchemaName(schemaName);
391
- let rowValues = rowsObj;
392
- let values = [];
393
- headers.forEach((h, index) => {
394
- if (h === ULITPA_PRIVATE_KEYS.from) {
395
- edgeRow.setFromId(rowValues[index]);
396
- return;
397
- }
398
- if (h === ULITPA_PRIVATE_KEYS.to) {
399
- edgeRow.setToId(rowValues[index]);
400
- return;
401
- }
402
- if (h === ULITPA_PRIVATE_KEYS.uuid) {
403
- let uuid = rowValues[index];
404
- if (uuid) {
405
- uuid += "";
406
- }
407
- edgeRow.setUuid(uuid);
408
- return;
409
- }
410
- if (h === ULITPA_PRIVATE_KEYS.from_uuid) {
411
- edgeRow.setFromUuid(rowValues[index]);
412
- return;
413
- }
414
- if (h === ULITPA_PRIVATE_KEYS.to_uuid) {
415
- edgeRow.setToUuid(rowValues[index]);
416
- return;
417
- }
418
- let typeCfg = index_1.PropertyUtils.GetPropertyType(propertyTypeObject[h]);
419
- values.push(index_1.SERIALIZE.serialize(rowValues[index], typeCfg.type, typeCfg.subTypes, timezone));
420
- });
421
- edgeRow.setValuesList(values);
422
- edgeRowsList.push(edgeRow);
423
- });
424
- edgeTable.setEntityRowsList(edgeRowsList);
425
- return edgeTable;
426
- },
427
- toPropertyTypeObject: (properties) => {
428
- let object = {};
429
- properties.forEach(p => {
430
- object[p.name] = p.type;
431
- });
432
- return object;
433
- },
434
- toNodeTable: (propertyTypeObject, schemaName, headers, rows, timezone) => {
435
- let nodeTable = new ultipa_pb_1.EntityTable();
436
- let handles = [ULITPA_PRIVATE_KEYS.id, ULITPA_PRIVATE_KEYS.uuid];
437
- let schemaHeaders = [];
438
- let schemaHeader = new ultipa_pb_1.Schema();
439
- schemaHeader.setSchemaName(schemaName);
440
- let headerList = [];
441
- headers.forEach((h) => {
442
- if (handles.includes(h)) {
443
- return;
444
- }
445
- let header = new ultipa_pb_1.Property();
446
- header.setPropertyName(h);
447
- let typeCfg = index_1.PropertyUtils.GetPropertyType(propertyTypeObject[h]);
448
- header.setPropertyType(typeCfg.type);
449
- if (typeCfg.subTypes) {
450
- header.setSubTypesList(typeCfg.subTypes);
451
- }
452
- headerList.push(header);
453
- });
454
- schemaHeader.setPropertiesList(headerList);
455
- schemaHeaders.push(schemaHeader);
456
- nodeTable.setSchemasList(schemaHeaders);
457
- let nodeRowsList = [];
458
- rows.forEach(rowObj => {
459
- let nodeRow = new ultipa_pb_1.EntityRow();
460
- if (!rowObj) {
461
- nodeRow.setIsNull(true);
462
- nodeRowsList.push(nodeRow);
463
- return;
464
- }
465
- nodeRow.setSchemaName(schemaName);
466
- let values = [];
467
- let rowValues = rowObj;
468
- headers.forEach((h, index) => {
469
- if (h === ULITPA_PRIVATE_KEYS.id) {
470
- nodeRow.setId(rowValues[index]);
471
- return;
472
- }
473
- if (h === ULITPA_PRIVATE_KEYS.uuid) {
474
- let uuid = rowValues[index];
475
- if (uuid) {
476
- uuid += "";
477
- }
478
- nodeRow.setUuid(uuid);
479
- return;
480
- }
481
- let typeCfg = index_1.PropertyUtils.GetPropertyType(propertyTypeObject[h]);
482
- values.push(index_1.SERIALIZE.serialize(rowValues[index], typeCfg.type, typeCfg.subTypes, timezone));
483
- });
484
- nodeRow.setValuesList(values);
485
- nodeRowsList.push(nodeRow);
486
- });
487
- nodeTable.setEntityRowsList(nodeRowsList);
488
- return nodeTable;
489
- },
490
- toEdgeTableWithSchema: (schema, rows, timezone) => {
491
- let table = new ultipa_pb_1.EntityTable();
492
- let handles = [ULITPA_PRIVATE_KEYS.uuid, ULITPA_PRIVATE_KEYS.from, ULITPA_PRIVATE_KEYS.to, ULITPA_PRIVATE_KEYS.from_uuid, ULITPA_PRIVATE_KEYS.to_uuid];
493
- let schemaHeaders = [];
494
- let schemaHeader = new ultipa_pb_1.Schema();
495
- schemaHeader.setSchemaName(schema.name);
496
- let headerList = [];
497
- schema.properties.forEach((o) => {
498
- let { name, type, subType } = o;
499
- if (handles.includes(name)) {
500
- return;
501
- }
502
- let header = new ultipa_pb_1.Property();
503
- header.setPropertyName(name);
504
- header.setPropertyType(type);
505
- if (subType) {
506
- header.setSubTypesList(subType);
507
- }
508
- headerList.push(header);
509
- });
510
- schemaHeader.setPropertiesList(headerList);
511
- schemaHeaders.push(schemaHeader);
512
- table.setSchemasList(schemaHeaders);
513
- let rowList = [];
514
- rows.forEach(rowObj => {
515
- let row = new ultipa_pb_1.EntityRow();
516
- if (!rowObj) {
517
- row.setIsNull(true);
518
- rowList.push(row);
519
- return;
520
- }
521
- row.setSchemaName(schema.name);
522
- if (!!rowObj.uuid) {
523
- row.setUuid(rowObj.uuid);
524
- }
525
- if (!!rowObj.from) {
526
- row.setFromId(rowObj.from);
527
- }
528
- if (!!rowObj.to) {
529
- row.setToId(rowObj.to);
530
- }
531
- if (!!rowObj.fromUuid) {
532
- row.setFromUuid(rowObj.fromUuid);
533
- }
534
- if (!!rowObj.toUuid) {
535
- row.setToUuid(rowObj.toUuid);
536
- }
537
- let values = [];
538
- let rowValues = rowObj.values || {};
539
- headerList.forEach((o, index) => {
540
- let name = o.getPropertyName();
541
- let type = o.getPropertyType();
542
- let subTypes = o.getSubTypesList();
543
- values.push(index_1.SERIALIZE.serialize(rowValues[name], type, subTypes, timezone));
544
- });
545
- row.setValuesList(values);
546
- rowList.push(row);
547
- });
548
- table.setEntityRowsList(rowList);
549
- return table;
550
- },
551
- toNodeTableWithSchema: (schema, rows, timezone) => {
552
- let nodeTable = new ultipa_pb_1.EntityTable();
553
- let handles = [ULITPA_PRIVATE_KEYS.id, ULITPA_PRIVATE_KEYS.uuid];
554
- let schemaHeaders = [];
555
- let schemaHeader = new ultipa_pb_1.Schema();
556
- schemaHeader.setSchemaName(schema.name);
557
- let headerList = [];
558
- schema.properties.forEach((o) => {
559
- let { name, type, subType } = o;
560
- if (handles.includes(name)) {
561
- return;
562
- }
563
- let header = new ultipa_pb_1.Property();
564
- header.setPropertyName(name);
565
- header.setPropertyType(type);
566
- if (subType) {
567
- header.setSubTypesList(subType);
568
- }
569
- headerList.push(header);
570
- });
571
- schemaHeader.setPropertiesList(headerList);
572
- schemaHeaders.push(schemaHeader);
573
- nodeTable.setSchemasList(schemaHeaders);
574
- let nodeRowsList = [];
575
- rows.forEach(rowObj => {
576
- let nodeRow = new ultipa_pb_1.EntityRow();
577
- if (!rowObj) {
578
- nodeRow.setIsNull(true);
579
- nodeRowsList.push(nodeRow);
580
- return;
581
- }
582
- if (!!rowObj.id) {
583
- nodeRow.setId(rowObj.id);
584
- }
585
- if (!!rowObj.uuid) {
586
- nodeRow.setUuid(rowObj.uuid);
587
- }
588
- nodeRow.setSchemaName(schema.name);
589
- let values = [];
590
- let rowValues = rowObj.values || {};
591
- headerList.forEach((o, index) => {
592
- let name = o.getPropertyName();
593
- let type = o.getPropertyType();
594
- let subTypes = o.getSubTypesList();
595
- values.push(index_1.SERIALIZE.serialize(rowValues[name], type, subTypes, timezone));
596
- });
597
- nodeRow.setValuesList(values);
598
- nodeRowsList.push(nodeRow);
599
- });
600
- nodeTable.setEntityRowsList(nodeRowsList);
601
- return nodeTable;
602
- },
603
- uuids: (tableData) => {
604
- if (!tableData) {
605
- return [];
606
- }
607
- let rowsData = tableData.getEntityRowsList();
608
- let uuids = [];
609
- rowsData.forEach((data) => {
610
- uuids.push(data.getUuid());
611
- });
612
- return uuids;
613
- },
614
- nodeTable: (nodeTableData, timezone) => {
615
- let tables = [];
616
- if (!nodeTableData) {
617
- return tables;
618
- }
619
- let headerMap = {};
620
- nodeTableData.getSchemasList().forEach((sh) => {
621
- let schema = sh.getSchemaName();
622
- headerMap[schema] = sh.getPropertiesList();
623
- });
624
- let nodeRowsData = nodeTableData.getEntityRowsList();
625
- nodeRowsData.forEach((nodeRowData) => {
626
- if (nodeRowData.getIsNull()) {
627
- tables.push(null);
628
- return;
629
- }
630
- let schema = nodeRowData.getSchemaName();
631
- let ptys = headerMap[schema];
632
- let values = nodeRowData.getValuesList_asU8();
633
- let _v = _mapValues(values, ptys, timezone);
634
- let nodeRow = new ULTIPA.Node();
635
- nodeRow.id = nodeRowData.getId(),
636
- nodeRow.uuid = nodeRowData.getUuid(),
637
- nodeRow.schema = schema,
638
- nodeRow.values = _v,
639
- tables.push(nodeRow);
640
- });
641
- return tables;
642
- },
643
- edgeTable: (edgeTableData, timezone) => {
644
- let tables = [];
645
- if (!edgeTableData) {
646
- return tables;
647
- }
648
- let headerMap = {};
649
- edgeTableData.getSchemasList().forEach((sh) => {
650
- let schema = sh.getSchemaName();
651
- headerMap[schema] = sh.getPropertiesList();
652
- });
653
- edgeTableData.getSchemasList().forEach((sh) => {
654
- let schema = sh.getSchemaName();
655
- headerMap[schema] = sh.getPropertiesList();
656
- });
657
- let edgeRowsData = edgeTableData.getEntityRowsList();
658
- edgeRowsData.forEach((rowData) => {
659
- if (rowData.getIsNull()) {
660
- tables.push(null);
661
- return;
662
- }
663
- let schema = rowData.getSchemaName();
664
- let ptys = headerMap[schema];
665
- let values = rowData.getValuesList_asU8();
666
- let _v = _mapValues(values, ptys, timezone);
667
- let edgeRow = new ULTIPA.Edge();
668
- // id: rowData.getId(),
669
- edgeRow.from = rowData.getFromId();
670
- edgeRow.to = rowData.getToId();
671
- edgeRow.uuid = rowData.getUuid();
672
- edgeRow.fromUuid = rowData.getFromUuid();
673
- edgeRow.toUuid = rowData.getToUuid();
674
- edgeRow.schema = schema;
675
- edgeRow.values = _v;
676
- tables.push(edgeRow);
677
- });
678
- return tables;
679
- },
680
- attr(attr, timezone) {
681
- let type = attr.getValueType();
682
- let result = new ULTIPA.Attr();
683
- result.values = [];
684
- result.resultType = ultipa_pb_1.ResultType.RESULT_TYPE_ATTR;
685
- result.propertyType = type;
686
- attr.getValuesList_asU8().forEach((v) => {
687
- if (type == ULTIPA.UltipaPropertyType.NULL) {
688
- return result.values.push(null);
689
- }
690
- if (type == ULTIPA.UltipaPropertyType.LIST) {
691
- let attrListData = ultipa_pb_1.AttrListData.deserializeBinary(v);
692
- if (attrListData.getIsNull()) {
693
- return result.values.push(null);
694
- }
695
- let result_type = attrListData.getType();
696
- switch (result_type) {
697
- case ultipa_pb_1.ResultType.RESULT_TYPE_NODE:
698
- {
699
- let v = {
700
- type: result_type,
701
- type_desc: ULTIPA.ResultType[result_type],
702
- nodes: exports.FormatType.nodeTable(attrListData.getNodes(), timezone)
703
- };
704
- result.values.push(v);
705
- }
706
- break;
707
- case ultipa_pb_1.ResultType.RESULT_TYPE_EDGE:
708
- {
709
- let v = {
710
- type: result_type,
711
- type_desc: ULTIPA.ResultType[result_type],
712
- edges: exports.FormatType.edgeTable(attrListData.getEdges(), timezone)
713
- };
714
- result.values.push(v);
715
- }
716
- break;
717
- case ultipa_pb_1.ResultType.RESULT_TYPE_PATH:
718
- {
719
- let v = {
720
- type: result_type,
721
- type_desc: ULTIPA.ResultType[result_type],
722
- paths: exports.FormatType.paths(attrListData.getPathsList())
723
- };
724
- result.values.push(v);
725
- }
726
- break;
727
- case ultipa_pb_1.ResultType.RESULT_TYPE_ATTR: {
728
- {
729
- let attrs = [];
730
- attrListData.getAttrsList().forEach(o => {
731
- let attr = exports.FormatType.attr(o, timezone);
732
- if (!attr.values) {
733
- attrs.push(attr.values);
734
- }
735
- else {
736
- attrs.push(...attr.values);
737
- }
738
- });
739
- // let v: ULTIPA.AttrListData = {
740
- // type: result_type,
741
- // type_desc: ULTIPA.ResultType[result_type],
742
- // attrs: attrs,
743
- // }
744
- if (attrs.length != 0) {
745
- }
746
- result.values.push(attrs);
747
- }
748
- break;
749
- }
750
- }
751
- }
752
- else {
753
- let v1 = index_1.DESERIALIZE.base(v, type, timezone);
754
- result.values.push(v1);
755
- }
756
- });
757
- return result;
758
- },
759
- graphPrivileges(graphPrivileges) {
760
- let new_graphPrivileges = [];
761
- if (graphPrivileges) {
762
- graphPrivileges.forEach((graphPrivilege) => {
763
- let new_graphPrivilege = { ...graphPrivilege };
764
- Object.keys(new_graphPrivilege).forEach((key) => {
765
- new_graphPrivilege["name"] = key;
766
- new_graphPrivilege["values"] = new_graphPrivilege[key];
767
- delete new_graphPrivilege[key];
768
- });
769
- new_graphPrivileges.push(new_graphPrivilege);
770
- });
771
- }
772
- return new_graphPrivileges;
773
- },
774
- };
775
- exports.FormatResponse = {
776
- tableToArray: (table) => {
777
- let res = [];
778
- if (table) {
779
- try {
780
- table.rows.forEach((row) => {
781
- let item = {};
782
- row.forEach((value, index) => {
783
- let header = table.headers[index];
784
- item[header.propertyName] = value;
785
- });
786
- res.push(item);
787
- });
788
- }
789
- catch (error) {
790
- console.log(error);
791
- }
792
- }
793
- return res;
794
- },
795
- formatObjects: (objs, keysFormat) => {
796
- if (!keysFormat) {
797
- return objs;
798
- }
799
- let newObjs = [];
800
- if (objs?.length > 0) {
801
- objs.forEach((obj) => {
802
- newObjs.push(exports.FormatResponse.formatObject(obj, keysFormat));
803
- });
804
- }
805
- return newObjs;
806
- },
807
- formatObject: (_obj, keysFormat) => {
808
- if (!keysFormat) {
809
- return _obj;
810
- }
811
- let obj = { ..._obj };
812
- if (keysFormat?.jsonKeys) {
813
- keysFormat.jsonKeys.forEach((k) => {
814
- try {
815
- if (obj[k]) {
816
- obj[k] = JSON.parse(obj[k]);
817
- }
818
- }
819
- catch (error) {
820
- console.log(error, k, obj);
821
- }
822
- });
823
- }
824
- if (keysFormat?.boolKeys) {
825
- keysFormat.boolKeys.forEach((k) => {
826
- try {
827
- if (obj[k]) {
828
- obj[k] = obj[k] == "true";
829
- }
830
- }
831
- catch (error) {
832
- console.log(error, k, obj);
833
- }
834
- });
835
- }
836
- if (keysFormat?.keyReplace) {
837
- Object.keys(keysFormat.keyReplace).forEach((k) => {
838
- if (obj[k]) {
839
- obj[keysFormat.keyReplace[k]] = obj[k];
840
- delete obj[k];
841
- }
842
- });
843
- }
844
- if (keysFormat?.dataFormat) {
845
- obj = keysFormat.dataFormat(obj);
846
- }
847
- return obj;
848
- },
849
- successStatus: () => {
850
- return {
851
- code: ULTIPA.ErrorCode.SUCCESS,
852
- message: ULTIPA.ErrorCode[ULTIPA.ErrorCode.SUCCESS]
853
- // message: "ok",
854
- };
855
- },
856
- statisticsSum: (one, sumOne) => {
857
- return {
858
- totalCost: (one?.totalCost || 0) + (sumOne?.totalCost || 0),
859
- engineCost: (one?.engineCost || 0) + (sumOne?.engineCost || 0),
860
- nodeAffected: (one?.nodeAffected || 0) + (sumOne?.nodeAffected || 0),
861
- edgeAffected: (one?.edgeAffected || 0) + (sumOne?.edgeAffected || 0),
862
- };
863
- },
864
- unknownError: (err, res) => {
865
- res.status = {
866
- code: ULTIPA.ErrorCode.UNKNOWN_ERROR,
867
- message: err.message || err.detail,
868
- };
869
- return res;
870
- },
871
- catchUltipaUqlError: (error) => {
872
- let response = new ULTIPA.Response();
873
- response = exports.FormatResponse.unknownError(error, response);
874
- return response;
875
- },
876
- };
877
- //# sourceMappingURL=format.js.map