@hpcc-js/comms 2.89.0 → 2.90.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.
@@ -0,0 +1,759 @@
1
+ // Ported from: https://github.com/hpcc-systems/HPCC-Platform/blob/f0ed9dbeca49c39fb55aa28fec295c89407ac663/esp/src/src/ESPGraph.ts
2
+ import { __extends, __spreadArray } from "tslib";
3
+ export function safeAssign(obj, key, value) {
4
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
5
+ return;
6
+ obj[key] = value;
7
+ }
8
+ function xmlEncode(str) {
9
+ str = "" + str;
10
+ return str.replace(/&/g, "&")
11
+ .replace(/"/g, """)
12
+ .replace(/'/g, "'")
13
+ .replace(/</g, "&lt;")
14
+ .replace(/>/g, "&gt;")
15
+ .replace(/\n/g, "&#10;")
16
+ .replace(/\r/g, "&#13;");
17
+ }
18
+ function espTime2Seconds(duration) {
19
+ if (!duration) {
20
+ return 0;
21
+ }
22
+ else if (!isNaN(+duration)) {
23
+ return parseFloat(duration);
24
+ }
25
+ var re = /(?:(?:(\d+).days.)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+\.\d+|\d+)s))|(?:(\d+\.\d+|\d+)ms|(\d+\.\d+|\d+)us|(\d+\.\d+|\d+)ns)/;
26
+ var match = re.exec(duration);
27
+ if (!match)
28
+ return 0;
29
+ var days = +match[1] || 0;
30
+ var hours = +match[2] || 0;
31
+ var mins = +match[3] || 0;
32
+ var secs = +match[4] || 0;
33
+ var ms = +match[5] || 0;
34
+ var us = +match[6] || 0;
35
+ var ns = +match[7] || 0;
36
+ return (days * 24 * 60 * 60) + (hours * 60 * 60) + (mins * 60) + secs + ms / 1000 + us / 1000000 + ns / 1000000000;
37
+ }
38
+ function unitTest(size, unit) {
39
+ var nsIndex = size.indexOf(unit);
40
+ if (nsIndex !== -1) {
41
+ return parseFloat(size.substring(0, nsIndex));
42
+ }
43
+ return -1;
44
+ }
45
+ function espSize2Bytes(size) {
46
+ if (!size) {
47
+ return 0;
48
+ }
49
+ else if (!isNaN(+size)) {
50
+ return parseFloat(size);
51
+ }
52
+ var retVal = unitTest(size, "Kb");
53
+ if (retVal >= 0) {
54
+ return retVal * 1024;
55
+ }
56
+ retVal = unitTest(size, "Mb");
57
+ if (retVal >= 0) {
58
+ return retVal * Math.pow(1024, 2);
59
+ }
60
+ retVal = unitTest(size, "Gb");
61
+ if (retVal >= 0) {
62
+ return retVal * Math.pow(1024, 3);
63
+ }
64
+ retVal = unitTest(size, "Tb");
65
+ if (retVal >= 0) {
66
+ return retVal * Math.pow(1024, 4);
67
+ }
68
+ retVal = unitTest(size, "Pb");
69
+ if (retVal >= 0) {
70
+ return retVal * Math.pow(1024, 5);
71
+ }
72
+ retVal = unitTest(size, "Eb");
73
+ if (retVal >= 0) {
74
+ return retVal * Math.pow(1024, 6);
75
+ }
76
+ retVal = unitTest(size, "Zb");
77
+ if (retVal >= 0) {
78
+ return retVal * Math.pow(1024, 7);
79
+ }
80
+ retVal = unitTest(size, "b");
81
+ if (retVal >= 0) {
82
+ return retVal;
83
+ }
84
+ return 0;
85
+ }
86
+ function espSkew2Number(skew) {
87
+ if (!skew) {
88
+ return 0;
89
+ }
90
+ return parseFloat(skew);
91
+ }
92
+ var GRAPH_TYPE;
93
+ (function (GRAPH_TYPE) {
94
+ GRAPH_TYPE[GRAPH_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
95
+ GRAPH_TYPE[GRAPH_TYPE["GRAPH"] = 1] = "GRAPH";
96
+ GRAPH_TYPE[GRAPH_TYPE["SUBGRAPH"] = 2] = "SUBGRAPH";
97
+ GRAPH_TYPE[GRAPH_TYPE["VERTEX"] = 3] = "VERTEX";
98
+ GRAPH_TYPE[GRAPH_TYPE["EDGE"] = 4] = "EDGE";
99
+ GRAPH_TYPE[GRAPH_TYPE["LAST"] = 5] = "LAST";
100
+ })(GRAPH_TYPE || (GRAPH_TYPE = {}));
101
+ var GRAPH_TYPE_STRING;
102
+ (function (GRAPH_TYPE_STRING) {
103
+ GRAPH_TYPE_STRING["UNKNOWN"] = "Unknown";
104
+ GRAPH_TYPE_STRING["GRAPH"] = "Graph";
105
+ GRAPH_TYPE_STRING["SUBGRAPH"] = "Cluster";
106
+ GRAPH_TYPE_STRING["VERTEX"] = "Vertex";
107
+ GRAPH_TYPE_STRING["EDGE"] = "Edge";
108
+ GRAPH_TYPE_STRING["LAST"] = "Last";
109
+ })(GRAPH_TYPE_STRING || (GRAPH_TYPE_STRING = {}));
110
+ var LocalisedXGMMLWriter = /** @class */ (function () {
111
+ function LocalisedXGMMLWriter(graph) {
112
+ this.graph = graph;
113
+ this.m_xgmml = "";
114
+ this.m_visibleSubgraphs = {};
115
+ this.m_visibleVertices = {};
116
+ this.m_semiVisibleVertices = {};
117
+ this.m_visibleEdges = {};
118
+ }
119
+ LocalisedXGMMLWriter.prototype.calcVisibility = function (items, localisationDepth, localisationDistance, noSpills) {
120
+ var _this = this;
121
+ this.noSpills = noSpills;
122
+ items.forEach(function (item) {
123
+ if (_this.graph.isVertex(item)) {
124
+ _this.calcInVertexVisibility(item, localisationDistance);
125
+ _this.calcOutVertexVisibility(item, localisationDistance);
126
+ }
127
+ else if (_this.graph.isEdge(item)) {
128
+ _this.calcInVertexVisibility(item.getSource(), localisationDistance - 1);
129
+ _this.calcOutVertexVisibility(item.getTarget(), localisationDistance - 1);
130
+ }
131
+ else if (_this.graph.isSubgraph(item)) {
132
+ _this.m_visibleSubgraphs[item.__hpcc_id] = item;
133
+ _this.calcSubgraphVisibility(item, localisationDepth - 1);
134
+ }
135
+ });
136
+ this.calcVisibility2();
137
+ };
138
+ LocalisedXGMMLWriter.prototype.calcInVertexVisibility = function (vertex, localisationDistance) {
139
+ var _this = this;
140
+ if (this.noSpills && vertex.isSpill()) {
141
+ localisationDistance++;
142
+ }
143
+ this.m_visibleVertices[vertex.__hpcc_id] = vertex;
144
+ if (localisationDistance > 0) {
145
+ vertex.getInEdges().forEach(function (edge) {
146
+ _this.calcInVertexVisibility(edge.getSource(), localisationDistance - 1);
147
+ });
148
+ }
149
+ };
150
+ LocalisedXGMMLWriter.prototype.calcOutVertexVisibility = function (vertex, localisationDistance) {
151
+ var _this = this;
152
+ if (this.noSpills && vertex.isSpill()) {
153
+ localisationDistance++;
154
+ }
155
+ this.m_visibleVertices[vertex.__hpcc_id] = vertex;
156
+ if (localisationDistance > 0) {
157
+ vertex.getOutEdges().forEach(function (edge) {
158
+ _this.calcOutVertexVisibility(edge.getTarget(), localisationDistance - 1);
159
+ });
160
+ }
161
+ };
162
+ LocalisedXGMMLWriter.prototype.calcSubgraphVisibility = function (subgraph, localisationDepth) {
163
+ var _this = this;
164
+ if (localisationDepth < 0) {
165
+ return;
166
+ }
167
+ if (localisationDepth > 0) {
168
+ subgraph.__hpcc_subgraphs.forEach(function (subgraph, idx) {
169
+ _this.calcSubgraphVisibility(subgraph, localisationDepth - 1);
170
+ });
171
+ }
172
+ subgraph.__hpcc_subgraphs.forEach(function (subgraph, idx) {
173
+ _this.m_visibleSubgraphs[subgraph.__hpcc_id] = subgraph;
174
+ });
175
+ subgraph.__hpcc_vertices.forEach(function (vertex, idx) {
176
+ _this.m_visibleVertices[vertex.__hpcc_id] = vertex;
177
+ });
178
+ // Calculate edges that pass through the subgraph ---
179
+ var dedupEdges = {};
180
+ this.graph.edges.forEach(function (edge, idx) {
181
+ if (edge.getSource().__hpcc_parent !== edge.getTarget().__hpcc_parent && subgraph === _this.getCommonAncestor(edge)) {
182
+ // Only include one unique edge between subgraphs ---
183
+ if (!dedupEdges[edge.getSource().__hpcc_parent.__hpcc_id + "::" + edge.getTarget().__hpcc_parent.__hpcc_id]) {
184
+ dedupEdges[edge.getSource().__hpcc_parent.__hpcc_id + "::" + edge.getTarget().__hpcc_parent.__hpcc_id] = true;
185
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
186
+ }
187
+ }
188
+ });
189
+ };
190
+ LocalisedXGMMLWriter.prototype.buildVertexString = function (vertex, isPoint) {
191
+ var attrStr = "";
192
+ var propsStr = "";
193
+ var props = vertex.getProperties();
194
+ for (var key in props) {
195
+ if (isPoint && key.indexOf("_kind") >= 0) {
196
+ propsStr += "<att name=\"_kind\" value=\"point\"/>";
197
+ }
198
+ else if (key === "id" || key === "label") {
199
+ attrStr += " " + key + "=\"" + xmlEncode(props[key]) + "\"";
200
+ }
201
+ else {
202
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
203
+ }
204
+ }
205
+ return "<node" + attrStr + ">" + propsStr + "</node>";
206
+ };
207
+ LocalisedXGMMLWriter.prototype.buildEdgeString = function (edge) {
208
+ var attrStr = "";
209
+ var propsStr = "";
210
+ var props = edge.getProperties();
211
+ for (var key in props) {
212
+ if (key.toLowerCase() === "id" ||
213
+ key.toLowerCase() === "label" ||
214
+ key.toLowerCase() === "source" ||
215
+ key.toLowerCase() === "target") {
216
+ attrStr += " " + key + "=\"" + xmlEncode(props[key]) + "\"";
217
+ }
218
+ else {
219
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
220
+ }
221
+ }
222
+ return "<edge" + attrStr + ">" + propsStr + "</edge>";
223
+ };
224
+ LocalisedXGMMLWriter.prototype.getAncestors = function (v, ancestors) {
225
+ var parent = v.__hpcc_parent;
226
+ while (parent) {
227
+ ancestors.push(parent);
228
+ parent = parent.__hpcc_parent;
229
+ }
230
+ };
231
+ LocalisedXGMMLWriter.prototype.getCommonAncestorV = function (v1, v2) {
232
+ var v1_ancestors = [];
233
+ var v2_ancestors = [];
234
+ this.getAncestors(v1, v1_ancestors);
235
+ this.getAncestors(v2, v2_ancestors);
236
+ var finger1 = v1_ancestors.length - 1;
237
+ var finger2 = v2_ancestors.length - 1;
238
+ var retVal = null;
239
+ while (finger1 >= 0 && finger2 >= 0 && v1_ancestors[finger1] === v2_ancestors[finger2]) {
240
+ retVal = v1_ancestors[finger1];
241
+ --finger1;
242
+ --finger2;
243
+ }
244
+ return retVal;
245
+ };
246
+ LocalisedXGMMLWriter.prototype.getCommonAncestor = function (e) {
247
+ return this.getCommonAncestorV(e.getSource(), e.getTarget());
248
+ };
249
+ LocalisedXGMMLWriter.prototype.calcAncestorVisibility = function (vertex) {
250
+ var _this = this;
251
+ var ancestors = [];
252
+ this.getAncestors(vertex, ancestors);
253
+ ancestors.forEach(function (item, idx) {
254
+ _this.m_visibleSubgraphs[item.__hpcc_id] = item;
255
+ });
256
+ };
257
+ LocalisedXGMMLWriter.prototype.calcVisibility2 = function () {
258
+ var _this = this;
259
+ for (var key in this.m_visibleVertices) {
260
+ var vertex = this.m_visibleVertices[key];
261
+ vertex.getInEdges().forEach(function (edge, idx) {
262
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
263
+ });
264
+ vertex.getOutEdges().forEach(function (edge, idx) {
265
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
266
+ });
267
+ this.calcAncestorVisibility(vertex);
268
+ }
269
+ this.calcSemiVisibleVertices();
270
+ };
271
+ LocalisedXGMMLWriter.prototype.addSemiVisibleEdge = function (edge) {
272
+ if (edge && !this.m_visibleEdges[edge.__hpcc_id]) {
273
+ this.m_visibleEdges[edge.__hpcc_id] = edge;
274
+ }
275
+ };
276
+ LocalisedXGMMLWriter.prototype.addSemiVisibleVertex = function (vertex) {
277
+ if (!this.m_visibleVertices[vertex.__hpcc_id]) {
278
+ this.m_semiVisibleVertices[vertex.__hpcc_id] = vertex;
279
+ this.calcAncestorVisibility(vertex);
280
+ }
281
+ };
282
+ LocalisedXGMMLWriter.prototype.calcSemiVisibleVertices = function () {
283
+ for (var key in this.m_visibleEdges) {
284
+ var edge = this.m_visibleEdges[key];
285
+ var source = edge.getSource();
286
+ this.addSemiVisibleVertex(source);
287
+ while (this.noSpills && source.isSpill()) {
288
+ var inEdges = source.getInEdges();
289
+ if (inEdges.length) {
290
+ this.addSemiVisibleEdge(inEdges[0]);
291
+ source = inEdges[0].getSource();
292
+ this.addSemiVisibleVertex(source);
293
+ }
294
+ else {
295
+ break;
296
+ }
297
+ }
298
+ var target = edge.getTarget();
299
+ this.addSemiVisibleVertex(target);
300
+ while (this.noSpills && target.isSpill()) {
301
+ var outEdges = target.getOutEdges();
302
+ if (outEdges.length) {
303
+ this.addSemiVisibleEdge(outEdges[0]);
304
+ target = outEdges[0].getTarget();
305
+ this.addSemiVisibleVertex(target);
306
+ }
307
+ else {
308
+ break;
309
+ }
310
+ }
311
+ }
312
+ };
313
+ LocalisedXGMMLWriter.prototype.writeXgmml = function () {
314
+ var _this = this;
315
+ this.subgraphVisited(this.graph.subgraphs[0], true);
316
+ this.graph.edges.forEach(function (edge, idx) {
317
+ _this.edgeVisited(edge);
318
+ });
319
+ };
320
+ LocalisedXGMMLWriter.prototype.subgraphVisited = function (subgraph, root) {
321
+ if (root === void 0) { root = false; }
322
+ if (this.m_visibleSubgraphs[subgraph.__hpcc_id]) {
323
+ var propsStr = "";
324
+ this.m_xgmml += root ? "" : "<node id=\"" + subgraph.__hpcc_id + "\"><att><graph>";
325
+ var xgmmlLen = this.m_xgmml.length;
326
+ subgraph.walkSubgraphs(this);
327
+ subgraph.walkVertices(this);
328
+ if (xgmmlLen === this.m_xgmml.length) {
329
+ // Add at least one child otherwise subgraphs will render as a vertex ---
330
+ var vertex = subgraph.__hpcc_vertices[0];
331
+ if (vertex) {
332
+ this.m_xgmml += this.buildVertexString(vertex, true);
333
+ }
334
+ }
335
+ var props = subgraph.getProperties();
336
+ for (var key in props) {
337
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
338
+ }
339
+ this.m_xgmml += root ? "" : "</graph></att>" + propsStr + "</node>";
340
+ }
341
+ return false;
342
+ };
343
+ LocalisedXGMMLWriter.prototype.vertexVisited = function (vertex) {
344
+ if (this.m_visibleVertices[vertex.__hpcc_id]) {
345
+ this.m_xgmml += this.buildVertexString(vertex, false);
346
+ }
347
+ else if (this.m_semiVisibleVertices[vertex.__hpcc_id]) {
348
+ this.m_xgmml += this.buildVertexString(vertex, true);
349
+ }
350
+ };
351
+ LocalisedXGMMLWriter.prototype.edgeVisited = function (edge) {
352
+ if (this.m_visibleEdges[edge.__hpcc_id]) {
353
+ this.m_xgmml += this.buildEdgeString(edge);
354
+ }
355
+ };
356
+ return LocalisedXGMMLWriter;
357
+ }());
358
+ var GraphItem = /** @class */ (function () {
359
+ function GraphItem(graph, id) {
360
+ this.__hpcc_graph = graph;
361
+ this.__hpcc_id = id;
362
+ this._globalID = id;
363
+ }
364
+ GraphItem.prototype.getProperties = function () {
365
+ var retVal = {};
366
+ for (var key in this) {
367
+ if (key.indexOf("__") !== 0 && this.hasOwnProperty(key)) {
368
+ retVal[key] = this[key];
369
+ }
370
+ }
371
+ return retVal;
372
+ };
373
+ return GraphItem;
374
+ }());
375
+ var Subgraph = /** @class */ (function (_super) {
376
+ __extends(Subgraph, _super);
377
+ function Subgraph(graph, id) {
378
+ var _this = _super.call(this, graph, id) || this;
379
+ _this._globalType = id === "0" ? "Graph" : "Cluster";
380
+ _this.__hpcc_subgraphs = [];
381
+ _this.__hpcc_vertices = [];
382
+ _this.__hpcc_edges = [];
383
+ _this.id = id;
384
+ return _this;
385
+ }
386
+ Subgraph.prototype.addSubgraph = function (subgraph) {
387
+ subgraph.__hpcc_parent = this;
388
+ if (!this.__hpcc_subgraphs.some(function (subgraph2) { return subgraph === subgraph2; })) {
389
+ this.__hpcc_subgraphs.push(subgraph);
390
+ }
391
+ };
392
+ Subgraph.prototype.addVertex = function (vertex) {
393
+ vertex.__hpcc_parent = this;
394
+ if (!this.__hpcc_vertices.some(function (vertex2) { return vertex === vertex2; })) {
395
+ this.__hpcc_vertices.push(vertex);
396
+ }
397
+ };
398
+ Subgraph.prototype.removeVertex = function (vertex) {
399
+ this.__hpcc_vertices = this.__hpcc_vertices.filter(function (vertex2) { return vertex !== vertex2; });
400
+ };
401
+ Subgraph.prototype.addEdge = function (edge) {
402
+ edge.__hpcc_parent = this;
403
+ if (!this.__hpcc_edges.some(function (edge2) { return edge === edge2; })) {
404
+ this.__hpcc_edges.push(edge);
405
+ }
406
+ };
407
+ Subgraph.prototype.removeEdge = function (edge) {
408
+ this.__hpcc_edges = this.__hpcc_edges.filter(function (edge2) { return edge !== edge2; });
409
+ };
410
+ Subgraph.prototype.remove = function () {
411
+ var _this = this;
412
+ this.__hpcc_subgraphs.forEach(function (subgraph) { return subgraph.__hpcc_parent = _this.__hpcc_parent; });
413
+ this.__hpcc_vertices.forEach(function (vertex) { return vertex.__hpcc_parent = _this.__hpcc_parent; });
414
+ this.__hpcc_edges.forEach(function (edge) { return edge.__hpcc_parent = _this.__hpcc_parent; });
415
+ delete this.__hpcc_parent;
416
+ this.__hpcc_graph.removeItem(this);
417
+ };
418
+ Subgraph.prototype.walkSubgraphs = function (visitor) {
419
+ this.__hpcc_subgraphs.forEach(function (subgraph, idx) {
420
+ if (visitor.subgraphVisited(subgraph)) {
421
+ subgraph.walkSubgraphs(visitor);
422
+ }
423
+ });
424
+ };
425
+ Subgraph.prototype.walkVertices = function (visitor) {
426
+ this.__hpcc_vertices.forEach(function (vertex, idx) {
427
+ visitor.vertexVisited(vertex);
428
+ });
429
+ };
430
+ return Subgraph;
431
+ }(GraphItem));
432
+ var Vertex = /** @class */ (function (_super) {
433
+ __extends(Vertex, _super);
434
+ function Vertex(graph, id) {
435
+ var _this = _super.call(this, graph, id) || this;
436
+ _this._globalType = "Vertex";
437
+ return _this;
438
+ }
439
+ Vertex.prototype.isSpill = function () {
440
+ return this._isSpill;
441
+ };
442
+ Vertex.prototype.remove = function () {
443
+ var _a;
444
+ var inVertices = this.getInVertices();
445
+ if (inVertices.length <= 1) {
446
+ console.warn(this.__hpcc_id + ": remove only supports single or zero inputs activities...");
447
+ }
448
+ this.getInEdges().forEach(function (edge) {
449
+ edge.remove();
450
+ });
451
+ this.getOutEdges().forEach(function (edge) {
452
+ edge.setSource(inVertices[0]);
453
+ });
454
+ (_a = this.__hpcc_parent) === null || _a === void 0 ? void 0 : _a.removeVertex(this);
455
+ this.__hpcc_graph.removeItem(this);
456
+ };
457
+ Vertex.prototype.getInVertices = function () {
458
+ return this.getInEdges().map(function (edge) {
459
+ return edge.getSource();
460
+ });
461
+ };
462
+ Vertex.prototype.getInEdges = function () {
463
+ var _this = this;
464
+ return this.__hpcc_graph.edges.filter(function (edge) {
465
+ return edge.getTarget() === _this;
466
+ });
467
+ };
468
+ Vertex.prototype.getOutVertices = function () {
469
+ return this.getOutEdges().map(function (edge) {
470
+ return edge.getTarget();
471
+ });
472
+ };
473
+ Vertex.prototype.getOutEdges = function () {
474
+ var _this = this;
475
+ return this.__hpcc_graph.edges.filter(function (edge) {
476
+ return edge.getSource() === _this;
477
+ });
478
+ };
479
+ return Vertex;
480
+ }(GraphItem));
481
+ var Edge = /** @class */ (function (_super) {
482
+ __extends(Edge, _super);
483
+ function Edge(graph, id) {
484
+ var _this = _super.call(this, graph, id) || this;
485
+ _this._globalType = "Edge";
486
+ _this._globalType = "Edge";
487
+ return _this;
488
+ }
489
+ Edge.prototype.remove = function () {
490
+ var _this = this;
491
+ this.__hpcc_graph.subgraphs.forEach(function (subgraph) {
492
+ subgraph.removeEdge(_this);
493
+ });
494
+ this.__hpcc_graph.removeItem(this);
495
+ };
496
+ Edge.prototype.getSource = function () {
497
+ return this.__hpcc_graph.idx[this._sourceActivity || this.source];
498
+ };
499
+ Edge.prototype.setSource = function (source) {
500
+ if (this._sourceActivity) {
501
+ this._sourceActivity = source.__hpcc_id;
502
+ }
503
+ else if (this.source) {
504
+ this.source = source.__hpcc_id;
505
+ }
506
+ if (this.__widget) {
507
+ this.__widget.setSource(this.getSource().__widget);
508
+ }
509
+ };
510
+ Edge.prototype.getTarget = function () {
511
+ return this.__hpcc_graph.idx[this._targetActivity || this.target];
512
+ };
513
+ return Edge;
514
+ }(GraphItem));
515
+ var QueryGraph = /** @class */ (function () {
516
+ function QueryGraph() {
517
+ this.idx = {};
518
+ this.subgraphs = [];
519
+ this.vertices = [];
520
+ this.edges = [];
521
+ this.xgmml = "";
522
+ this.clear();
523
+ }
524
+ QueryGraph.prototype.clear = function () {
525
+ this.xgmml = "";
526
+ this.idx = {};
527
+ this.subgraphs = [];
528
+ this.vertices = [];
529
+ this.edges = [];
530
+ };
531
+ QueryGraph.prototype.load = function (xgmml) {
532
+ this.clear();
533
+ this.merge(xgmml);
534
+ };
535
+ QueryGraph.prototype.merge = function (xgmml) {
536
+ this.xgmml = xgmml;
537
+ var parser = new DOMParser();
538
+ var dom = parser.parseFromString(xgmml, "text/xml");
539
+ this.walkDocument(dom.documentElement, "0");
540
+ };
541
+ QueryGraph.prototype.isSubgraph = function (item) {
542
+ return item instanceof Subgraph;
543
+ };
544
+ QueryGraph.prototype.isVertex = function (item) {
545
+ return item instanceof Vertex;
546
+ };
547
+ QueryGraph.prototype.isEdge = function (item) {
548
+ return item instanceof Edge;
549
+ };
550
+ QueryGraph.prototype.getGlobalType = function (item) {
551
+ if (item instanceof Vertex) {
552
+ return GRAPH_TYPE.VERTEX;
553
+ }
554
+ else if (item instanceof Edge) {
555
+ return GRAPH_TYPE.EDGE;
556
+ }
557
+ else if (item instanceof Subgraph) {
558
+ return GRAPH_TYPE.SUBGRAPH;
559
+ }
560
+ else if (item instanceof QueryGraph) {
561
+ return GRAPH_TYPE.GRAPH;
562
+ }
563
+ return GRAPH_TYPE.UNKNOWN;
564
+ };
565
+ QueryGraph.prototype.getGlobalTypeString = function (item) {
566
+ if (item instanceof Vertex) {
567
+ return GRAPH_TYPE_STRING.VERTEX;
568
+ }
569
+ else if (item instanceof Edge) {
570
+ return GRAPH_TYPE_STRING.EDGE;
571
+ }
572
+ else if (item instanceof Subgraph) {
573
+ return GRAPH_TYPE_STRING.SUBGRAPH;
574
+ }
575
+ else if (item instanceof QueryGraph) {
576
+ return GRAPH_TYPE_STRING.GRAPH;
577
+ }
578
+ return GRAPH_TYPE_STRING.UNKNOWN;
579
+ };
580
+ QueryGraph.prototype.getItem = function (docNode, id) {
581
+ if (!this.idx[id]) {
582
+ switch (docNode.tagName) {
583
+ case "graph":
584
+ var subgraph = new Subgraph(this, id);
585
+ this.subgraphs.push(subgraph);
586
+ this.idx[id] = subgraph;
587
+ break;
588
+ case "node":
589
+ var vertex = new Vertex(this, id);
590
+ this.vertices.push(vertex);
591
+ this.idx[id] = vertex;
592
+ break;
593
+ case "edge":
594
+ var edge = new Edge(this, id);
595
+ this.edges.push(edge);
596
+ this.idx[id] = edge;
597
+ break;
598
+ default:
599
+ console.warn("Graph.getItem - Unknown Node Type!");
600
+ break;
601
+ }
602
+ }
603
+ var retVal = this.idx[id];
604
+ Array.from(docNode.attributes).forEach(function (attr) {
605
+ safeAssign(retVal, attr.name, attr.value);
606
+ });
607
+ return retVal;
608
+ };
609
+ QueryGraph.prototype.removeItem = function (item) {
610
+ delete this.idx[item.__hpcc_id];
611
+ if (item instanceof Subgraph) {
612
+ this.subgraphs = this.subgraphs.filter(function (subgraph) {
613
+ return item !== subgraph;
614
+ });
615
+ }
616
+ else if (item instanceof Vertex) {
617
+ this.vertices = this.vertices.filter(function (vertex) {
618
+ return item !== vertex;
619
+ });
620
+ }
621
+ else if (item instanceof Edge) {
622
+ this.edges = this.edges.filter(function (edge) {
623
+ return item !== edge;
624
+ });
625
+ }
626
+ };
627
+ QueryGraph.prototype.getChildByTagName = function (docNode, tagName) {
628
+ var retVal = null;
629
+ Array.from(docNode.childNodes).some(function (childNode, idx) {
630
+ if (childNode.tagName === tagName) {
631
+ retVal = childNode;
632
+ return true;
633
+ }
634
+ });
635
+ return retVal;
636
+ };
637
+ QueryGraph.prototype.walkDocument = function (docNode, id) {
638
+ var _this = this;
639
+ var retVal = this.getItem(docNode, id);
640
+ docNode.childNodes.forEach(function (childNode, idx) {
641
+ switch (childNode.nodeType) {
642
+ case 1: // ELEMENT_NODE
643
+ switch (childNode.tagName) {
644
+ case "graph":
645
+ break;
646
+ case "node":
647
+ var isSubgraph = false;
648
+ var attNode = _this.getChildByTagName(childNode, "att");
649
+ if (attNode) {
650
+ var graphNode = _this.getChildByTagName(attNode, "graph");
651
+ if (graphNode) {
652
+ isSubgraph = true;
653
+ var subgraph = _this.walkDocument(graphNode, childNode.getAttribute("id"));
654
+ retVal.addSubgraph(subgraph);
655
+ }
656
+ }
657
+ if (!isSubgraph) {
658
+ var vertex = _this.walkDocument(childNode, childNode.getAttribute("id"));
659
+ retVal.addVertex(vertex);
660
+ }
661
+ break;
662
+ case "att":
663
+ var name_1 = childNode.getAttribute("name");
664
+ var uname = "_" + name_1;
665
+ var value = childNode.getAttribute("value");
666
+ if (name_1.indexOf("Time") === 0) {
667
+ safeAssign(retVal, uname, value);
668
+ safeAssign(retVal, name_1, "" + espTime2Seconds(value));
669
+ }
670
+ else if (name_1.indexOf("Size") === 0) {
671
+ safeAssign(retVal, uname, value);
672
+ safeAssign(retVal, name_1, "" + espSize2Bytes(value));
673
+ }
674
+ else if (name_1.indexOf("Skew") === 0) {
675
+ safeAssign(retVal, uname, value);
676
+ safeAssign(retVal, name_1, "" + espSkew2Number(value));
677
+ }
678
+ else {
679
+ safeAssign(retVal, name_1, value);
680
+ }
681
+ break;
682
+ case "edge":
683
+ var edge = _this.walkDocument(childNode, childNode.getAttribute("id"));
684
+ if (edge.NumRowsProcessed !== undefined) {
685
+ edge._eclwatchCount = edge.NumRowsProcessed.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
686
+ }
687
+ else if (edge.Count !== undefined) {
688
+ edge._eclwatchCount = edge.Count.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
689
+ }
690
+ else if (edge.count !== undefined) {
691
+ edge._eclwatchCount = edge.count.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
692
+ }
693
+ if (edge.inputProgress) {
694
+ edge._eclwatchInputProgress = "[" + edge.inputProgress.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "]";
695
+ }
696
+ if (edge.SkewMaxRowsProcessed && edge.SkewMinRowsProcessed) {
697
+ edge._eclwatchSkew = "+" + edge.SkewMaxRowsProcessed + ", " + edge.SkewMinRowsProcessed;
698
+ }
699
+ if (edge._dependsOn) {
700
+ }
701
+ else if (edge._childGraph) {
702
+ }
703
+ else if (edge._sourceActivity || edge._targetActivity) {
704
+ edge._isSpill = true;
705
+ var source = edge.getSource();
706
+ source._isSpill = true;
707
+ var target = edge.getTarget();
708
+ target._isSpill = true;
709
+ }
710
+ retVal.addEdge(edge);
711
+ break;
712
+ default:
713
+ break;
714
+ }
715
+ break;
716
+ case 2: // ATTRIBUTE_NODE
717
+ case 3: // TEXT_NODE
718
+ case 4: // CDATA_SECTION_NODE
719
+ case 5: // ENTITY_REFERENCE_NODE
720
+ case 6: // ENTITY_NODE
721
+ case 7: // PROCESSING_INSTRUCTION_NODE
722
+ case 8: // COMMENT_NODE
723
+ case 9: // DOCUMENT_NODE
724
+ case 10: // DOCUMENT_TYPE_NODE
725
+ case 11: // DOCUMENT_FRAGMENT_NODE
726
+ case 12: // NOTATION_NODE
727
+ break;
728
+ default:
729
+ break;
730
+ }
731
+ });
732
+ return retVal;
733
+ };
734
+ QueryGraph.prototype.removeSubgraphs = function () {
735
+ var subgraphs = __spreadArray([], this.subgraphs, true);
736
+ subgraphs.forEach(function (subgraph) {
737
+ if (subgraph.__hpcc_parent instanceof Subgraph) {
738
+ subgraph.remove();
739
+ }
740
+ });
741
+ };
742
+ QueryGraph.prototype.removeSpillVertices = function () {
743
+ var vertices = __spreadArray([], this.vertices, true);
744
+ vertices.forEach(function (vertex) {
745
+ if (vertex.isSpill()) {
746
+ vertex.remove();
747
+ }
748
+ });
749
+ };
750
+ QueryGraph.prototype.getLocalisedXGMML = function (items, localisationDepth, localisationDistance, noSpills) {
751
+ var xgmmlWriter = new LocalisedXGMMLWriter(this);
752
+ xgmmlWriter.calcVisibility(items, localisationDepth, localisationDistance, noSpills);
753
+ xgmmlWriter.writeXgmml();
754
+ return "<graph>" + xgmmlWriter.m_xgmml + "</graph>";
755
+ };
756
+ return QueryGraph;
757
+ }());
758
+ export { QueryGraph };
759
+ //# sourceMappingURL=queryGraph.js.map