@hpcc-js/comms 2.89.0 → 2.91.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 (45) hide show
  1. package/dist/index.es6.js +956 -128
  2. package/dist/index.es6.js.map +1 -1
  3. package/dist/index.js +948 -119
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/index.node.js +948 -119
  8. package/dist/index.node.js.map +1 -1
  9. package/dist/index.node.min.js +1 -1
  10. package/dist/index.node.min.js.map +1 -1
  11. package/lib-es6/__package__.js +2 -2
  12. package/lib-es6/ecl/query.js +68 -0
  13. package/lib-es6/ecl/query.js.map +1 -1
  14. package/lib-es6/ecl/queryGraph.js +759 -0
  15. package/lib-es6/ecl/queryGraph.js.map +1 -0
  16. package/lib-es6/ecl/workunit.js +116 -102
  17. package/lib-es6/ecl/workunit.js.map +1 -1
  18. package/lib-es6/services/wsWorkunits.js +5 -1
  19. package/lib-es6/services/wsWorkunits.js.map +1 -1
  20. package/lib-es6/services/wsdl/WsWorkunits/v1.98/WsWorkunits.js +370 -0
  21. package/lib-es6/services/wsdl/WsWorkunits/v1.98/WsWorkunits.js.map +1 -0
  22. package/package.json +3 -3
  23. package/src/__package__.ts +2 -2
  24. package/src/ecl/query.ts +66 -1
  25. package/src/ecl/queryGraph.ts +809 -0
  26. package/src/ecl/workunit.ts +126 -103
  27. package/src/services/wsWorkunits.ts +8 -1
  28. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -0
  29. package/types/__package__.d.ts +2 -2
  30. package/types/ecl/query.d.ts +12 -1
  31. package/types/ecl/query.d.ts.map +1 -1
  32. package/types/ecl/queryGraph.d.ts +101 -0
  33. package/types/ecl/queryGraph.d.ts.map +1 -0
  34. package/types/ecl/workunit.d.ts +8 -0
  35. package/types/ecl/workunit.d.ts.map +1 -1
  36. package/types/services/wsWorkunits.d.ts +3 -1
  37. package/types/services/wsWorkunits.d.ts.map +1 -1
  38. package/types/services/wsdl/WsWorkunits/v1.98/WsWorkunits.d.ts +2623 -0
  39. package/types/services/wsdl/WsWorkunits/v1.98/WsWorkunits.d.ts.map +1 -0
  40. package/types-3.4/__package__.d.ts +2 -2
  41. package/types-3.4/ecl/query.d.ts +12 -1
  42. package/types-3.4/ecl/queryGraph.d.ts +101 -0
  43. package/types-3.4/ecl/workunit.d.ts +8 -0
  44. package/types-3.4/services/wsWorkunits.d.ts +3 -1
  45. package/types-3.4/services/wsdl/WsWorkunits/v1.98/WsWorkunits.d.ts +2623 -0
package/dist/index.js CHANGED
@@ -648,8 +648,8 @@
648
648
  }
649
649
 
650
650
  var PKG_NAME = "@hpcc-js/comms";
651
- var PKG_VERSION = "2.89.0";
652
- var BUILD_VERSION = "2.104.39";
651
+ var PKG_VERSION = "2.91.0";
652
+ var BUILD_VERSION = "2.104.42";
653
653
 
654
654
  /******************************************************************************
655
655
  Copyright (c) Microsoft Corporation.
@@ -2800,7 +2800,7 @@
2800
2800
  return TopologyService;
2801
2801
  }(TopologyServiceBase));
2802
2802
 
2803
- var WsWorkunits;
2803
+ exports.WsWorkunits = void 0;
2804
2804
  (function (WsWorkunits) {
2805
2805
  (function (ECLWUActions) {
2806
2806
  ECLWUActions["Abort"] = "Abort";
@@ -2816,6 +2816,26 @@
2816
2816
  ECLWUActions["SetToFailed"] = "SetToFailed";
2817
2817
  ECLWUActions["Archive"] = "Archive";
2818
2818
  })(WsWorkunits.ECLWUActions || (WsWorkunits.ECLWUActions = {}));
2819
+ (function (LogSelectColumnMode) {
2820
+ LogSelectColumnMode[LogSelectColumnMode["MIN"] = 0] = "MIN";
2821
+ LogSelectColumnMode[LogSelectColumnMode["DEFAULT"] = 1] = "DEFAULT";
2822
+ LogSelectColumnMode[LogSelectColumnMode["ALL"] = 2] = "ALL";
2823
+ LogSelectColumnMode[LogSelectColumnMode["CUSTOM"] = 3] = "CUSTOM";
2824
+ })(WsWorkunits.LogSelectColumnMode || (WsWorkunits.LogSelectColumnMode = {}));
2825
+ (function (SortDirection) {
2826
+ SortDirection[SortDirection["ASC"] = 0] = "ASC";
2827
+ SortDirection[SortDirection["DSC"] = 1] = "DSC";
2828
+ })(WsWorkunits.SortDirection || (WsWorkunits.SortDirection = {}));
2829
+ (function (LogEventClass) {
2830
+ LogEventClass["ALL"] = "ALL";
2831
+ LogEventClass["DIS"] = "DIS";
2832
+ LogEventClass["ERR"] = "ERR";
2833
+ LogEventClass["WRN"] = "WRN";
2834
+ LogEventClass["INF"] = "INF";
2835
+ LogEventClass["PRO"] = "PRO";
2836
+ LogEventClass["MET"] = "MET";
2837
+ LogEventClass["EVT"] = "EVT";
2838
+ })(WsWorkunits.LogEventClass || (WsWorkunits.LogEventClass = {}));
2819
2839
  (function (EclDefinitionActions) {
2820
2840
  EclDefinitionActions["SyntaxCheck"] = "SyntaxCheck";
2821
2841
  EclDefinitionActions["Deploy"] = "Deploy";
@@ -2826,12 +2846,6 @@
2826
2846
  ErrorMessageFormat["json"] = "json";
2827
2847
  ErrorMessageFormat["text"] = "text";
2828
2848
  })(WsWorkunits.ErrorMessageFormat || (WsWorkunits.ErrorMessageFormat = {}));
2829
- (function (LogSelectColumnMode) {
2830
- LogSelectColumnMode[LogSelectColumnMode["MIN"] = 0] = "MIN";
2831
- LogSelectColumnMode[LogSelectColumnMode["DEFAULT"] = 1] = "DEFAULT";
2832
- LogSelectColumnMode[LogSelectColumnMode["ALL"] = 2] = "ALL";
2833
- LogSelectColumnMode[LogSelectColumnMode["CUSTOM"] = 3] = "CUSTOM";
2834
- })(WsWorkunits.LogSelectColumnMode || (WsWorkunits.LogSelectColumnMode = {}));
2835
2849
  (function (LogAccessLogFormat) {
2836
2850
  LogAccessLogFormat[LogAccessLogFormat["XML"] = 0] = "XML";
2837
2851
  LogAccessLogFormat[LogAccessLogFormat["JSON"] = 1] = "JSON";
@@ -2886,11 +2900,11 @@
2886
2900
  WUQueryActivationMode[WUQueryActivationMode["ActivateQuerySuspendPrevious"] = 2] = "ActivateQuerySuspendPrevious";
2887
2901
  WUQueryActivationMode[WUQueryActivationMode["ActivateQueryDeletePrevious"] = 3] = "ActivateQueryDeletePrevious";
2888
2902
  })(WsWorkunits.WUQueryActivationMode || (WsWorkunits.WUQueryActivationMode = {}));
2889
- })(WsWorkunits || (WsWorkunits = {}));
2903
+ })(exports.WsWorkunits || (exports.WsWorkunits = {}));
2890
2904
  var WorkunitsServiceBase = /** @class */ (function (_super) {
2891
2905
  __extends(WorkunitsServiceBase, _super);
2892
2906
  function WorkunitsServiceBase(optsConnection) {
2893
- return _super.call(this, optsConnection, "WsWorkunits", "1.95") || this;
2907
+ return _super.call(this, optsConnection, "WsWorkunits", "1.98") || this;
2894
2908
  }
2895
2909
  WorkunitsServiceBase.prototype.GVCAjaxGraph = function (request) {
2896
2910
  return this._connection.send("GVCAjaxGraph", request, "json", false, undefined, "GVCAjaxGraphResponse");
@@ -3138,12 +3152,6 @@
3138
3152
  return WorkunitsServiceBase;
3139
3153
  }(Service));
3140
3154
 
3141
- /*
3142
- Response structures generated via:
3143
- * http://localhost:8010/WsWorkunits/WUInfo?reqjson_
3144
- * http://localhost:8010/WsWorkunits/WUInfo?respjson_
3145
- * http://json2ts.com/
3146
- */
3147
3155
  exports.WUStateID = void 0;
3148
3156
  (function (WUStateID) {
3149
3157
  WUStateID[WUStateID["Unknown"] = 0] = "Unknown";
@@ -3306,6 +3314,9 @@
3306
3314
  function WorkunitsServiceEx() {
3307
3315
  return _super !== null && _super.apply(this, arguments) || this;
3308
3316
  }
3317
+ WorkunitsServiceEx.prototype.WUPublishWorkunitEx = function (request) {
3318
+ return this._connection.send("WUPublishWorkunit", request);
3319
+ };
3309
3320
  return WorkunitsServiceEx;
3310
3321
  }(WorkunitsServiceBase));
3311
3322
 
@@ -5727,6 +5738,13 @@
5727
5738
  }
5728
5739
  return num;
5729
5740
  }
5741
+ function safeDelete(obj, key, prop) {
5742
+ if (obj[key] === undefined || obj[key][prop] === undefined)
5743
+ return;
5744
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
5745
+ return;
5746
+ delete obj[key][prop];
5747
+ }
5730
5748
  var DEFINITION_LIST = "DefinitionList";
5731
5749
  var definitionRegex = /([a-zA-Z]:)?(.*[\\\/])(.*)(\((\d+),(\d+)\))/;
5732
5750
  var PropertyType = ["Avg", "Min", "Max", "Delta", "StdDev"];
@@ -6617,115 +6635,117 @@
6617
6635
  if (request === void 0) { request = {}; }
6618
6636
  return this.WUDetails(request).then(function (response) { return response.Scopes.Scope; });
6619
6637
  };
6620
- Workunit.prototype.fetchDetailsNormalized = function (request) {
6621
- if (request === void 0) { request = {}; }
6622
- return Promise.all([this.fetchDetailsMeta(), this.fetchDetailsRaw(request)]).then(function (promises) {
6623
- var _a;
6624
- var meta = promises[0];
6625
- var scopes = promises[1];
6626
- var columns = {
6627
- id: {
6628
- Measure: "label"
6629
- },
6630
- name: {
6631
- Measure: "label"
6632
- },
6633
- type: {
6634
- Measure: "label"
6635
- }
6636
- };
6637
- var data = [];
6638
- var _loop_1 = function (scope) {
6639
- var props = {};
6640
- var formattedProps = {};
6641
- if (scope && scope.Id && scope.Properties && scope.Properties.Property) {
6642
- for (var key in scope.Properties.Property) {
6643
- var scopeProperty = scope.Properties.Property[key];
6644
- if (scopeProperty.Measure === "ns") {
6645
- scopeProperty.Measure = "s";
6646
- }
6647
- columns[scopeProperty.Name] = __assign({}, scopeProperty);
6648
- delete columns[scopeProperty.Name].RawValue;
6649
- delete columns[scopeProperty.Name].Formatted;
6650
- switch (scopeProperty.Measure) {
6651
- case "bool":
6652
- props[scopeProperty.Name] = !!+scopeProperty.RawValue;
6653
- break;
6654
- case "sz":
6655
- props[scopeProperty.Name] = +scopeProperty.RawValue;
6656
- break;
6657
- case "s":
6658
- props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000000;
6659
- break;
6660
- case "ns":
6661
- props[scopeProperty.Name] = +scopeProperty.RawValue;
6662
- break;
6663
- case "ts":
6664
- props[scopeProperty.Name] = new Date(+scopeProperty.RawValue / 1000).toISOString();
6665
- break;
6666
- case "cnt":
6667
- props[scopeProperty.Name] = +scopeProperty.RawValue;
6668
- break;
6669
- case "cost":
6670
- props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000;
6671
- break;
6672
- case "cpu":
6673
- case "skw":
6674
- case "node":
6675
- case "ppm":
6676
- case "ip":
6677
- case "cy":
6678
- case "en":
6679
- case "txt":
6680
- case "id":
6681
- case "fname":
6682
- default:
6683
- props[scopeProperty.Name] = scopeProperty.RawValue;
6684
- }
6685
- formattedProps[scopeProperty.Name] = formatNum((_a = scopeProperty.Formatted) !== null && _a !== void 0 ? _a : props[scopeProperty.Name]);
6686
- }
6687
- // Other properties ---
6688
- }
6689
- var normalizedScope = __assign({ id: scope.Id, name: scope.ScopeName, type: scope.ScopeType, Kind: scope["Kind"], Label: scope["Label"], __formattedProps: formattedProps, __groupedProps: {} }, props);
6690
- if (normalizedScope[DEFINITION_LIST]) {
6691
- try {
6692
- var definitionList = JSON.parse(normalizedScope[DEFINITION_LIST].split("\\").join("\\\\"));
6693
- normalizedScope[DEFINITION_LIST] = [];
6694
- definitionList.forEach(function (definition, idx) {
6695
- var _a;
6696
- var matches = definition.match(definitionRegex);
6697
- if (matches) {
6698
- var filePath = ((_a = matches[1]) !== null && _a !== void 0 ? _a : "") + matches[2] + matches[3];
6699
- var line = parseInt(matches[5]);
6700
- var col = parseInt(matches[6]);
6701
- normalizedScope[DEFINITION_LIST].push({ filePath: filePath, line: line, col: col });
6702
- }
6703
- });
6638
+ Workunit.prototype.normalizeDetails = function (meta, scopes) {
6639
+ var _a;
6640
+ var columns = {
6641
+ id: {
6642
+ Measure: "label"
6643
+ },
6644
+ name: {
6645
+ Measure: "label"
6646
+ },
6647
+ type: {
6648
+ Measure: "label"
6649
+ }
6650
+ };
6651
+ var data = [];
6652
+ var _loop_1 = function (scope) {
6653
+ var props = {};
6654
+ var formattedProps = {};
6655
+ if (scope && scope.Id && scope.Properties && scope.Properties.Property) {
6656
+ for (var key in scope.Properties.Property) {
6657
+ var scopeProperty = scope.Properties.Property[key];
6658
+ if (scopeProperty.Measure === "ns") {
6659
+ scopeProperty.Measure = "s";
6704
6660
  }
6705
- catch (e) {
6706
- logger$2.error("Unexpected \"DefinitionList\": ".concat(normalizedScope[DEFINITION_LIST]));
6661
+ columns[scopeProperty.Name] = __assign({}, scopeProperty);
6662
+ safeDelete(columns, scopeProperty.Name, "RawValue");
6663
+ safeDelete(columns, scopeProperty.Name, "Formatted");
6664
+ switch (scopeProperty.Measure) {
6665
+ case "bool":
6666
+ props[scopeProperty.Name] = !!+scopeProperty.RawValue;
6667
+ break;
6668
+ case "sz":
6669
+ props[scopeProperty.Name] = +scopeProperty.RawValue;
6670
+ break;
6671
+ case "s":
6672
+ props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000000;
6673
+ break;
6674
+ case "ns":
6675
+ props[scopeProperty.Name] = +scopeProperty.RawValue;
6676
+ break;
6677
+ case "ts":
6678
+ props[scopeProperty.Name] = new Date(+scopeProperty.RawValue / 1000).toISOString();
6679
+ break;
6680
+ case "cnt":
6681
+ props[scopeProperty.Name] = +scopeProperty.RawValue;
6682
+ break;
6683
+ case "cost":
6684
+ props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000;
6685
+ break;
6686
+ case "cpu":
6687
+ case "skw":
6688
+ case "node":
6689
+ case "ppm":
6690
+ case "ip":
6691
+ case "cy":
6692
+ case "en":
6693
+ case "txt":
6694
+ case "id":
6695
+ case "fname":
6696
+ default:
6697
+ props[scopeProperty.Name] = scopeProperty.RawValue;
6707
6698
  }
6699
+ formattedProps[scopeProperty.Name] = formatNum((_a = scopeProperty.Formatted) !== null && _a !== void 0 ? _a : props[scopeProperty.Name]);
6708
6700
  }
6709
- var dedup = {};
6710
- for (var key in normalizedScope) {
6711
- if (key.indexOf("__") !== 0) {
6712
- var row = formatValues(normalizedScope, key, dedup);
6713
- if (row) {
6714
- normalizedScope.__groupedProps[row.Key] = row;
6701
+ // Other properties ---
6702
+ }
6703
+ var normalizedScope = __assign({ id: scope.Id, name: scope.ScopeName, type: scope.ScopeType, Kind: scope["Kind"], Label: scope["Label"], __formattedProps: formattedProps, __groupedProps: {} }, props);
6704
+ if (normalizedScope[DEFINITION_LIST]) {
6705
+ try {
6706
+ var definitionList = JSON.parse(normalizedScope[DEFINITION_LIST].split("\\").join("\\\\"));
6707
+ normalizedScope[DEFINITION_LIST] = [];
6708
+ definitionList.forEach(function (definition, idx) {
6709
+ var _a;
6710
+ var matches = definition.match(definitionRegex);
6711
+ if (matches) {
6712
+ var filePath = ((_a = matches[1]) !== null && _a !== void 0 ? _a : "") + matches[2] + matches[3];
6713
+ var line = parseInt(matches[5]);
6714
+ var col = parseInt(matches[6]);
6715
+ normalizedScope[DEFINITION_LIST].push({ filePath: filePath, line: line, col: col });
6715
6716
  }
6717
+ });
6718
+ }
6719
+ catch (e) {
6720
+ logger$2.error("Unexpected \"DefinitionList\": ".concat(normalizedScope[DEFINITION_LIST]));
6721
+ }
6722
+ }
6723
+ var dedup = {};
6724
+ for (var key in normalizedScope) {
6725
+ if (key.indexOf("__") !== 0) {
6726
+ var row = formatValues(normalizedScope, key, dedup);
6727
+ if (row) {
6728
+ normalizedScope.__groupedProps[row.Key] = row;
6716
6729
  }
6717
6730
  }
6718
- data.push(normalizedScope);
6719
- };
6720
- for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
6721
- var scope = scopes_1[_i];
6722
- _loop_1(scope);
6723
6731
  }
6724
- return {
6725
- meta: meta,
6726
- columns: columns,
6727
- data: data
6728
- };
6732
+ data.push(normalizedScope);
6733
+ };
6734
+ for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
6735
+ var scope = scopes_1[_i];
6736
+ _loop_1(scope);
6737
+ }
6738
+ return {
6739
+ meta: meta,
6740
+ columns: columns,
6741
+ data: data
6742
+ };
6743
+ };
6744
+ Workunit.prototype.fetchDetailsNormalized = function (request) {
6745
+ var _this = this;
6746
+ if (request === void 0) { request = {}; }
6747
+ return Promise.all([this.fetchDetailsMeta(), this.fetchDetailsRaw(request)]).then(function (promises) {
6748
+ return _this.normalizeDetails(promises[0], promises[1]);
6729
6749
  });
6730
6750
  };
6731
6751
  Workunit.prototype.fetchInfo = function (request) {
@@ -7057,6 +7077,11 @@
7057
7077
  Wait: 5000
7058
7078
  });
7059
7079
  };
7080
+ Workunit.prototype.publishEx = function (request) {
7081
+ var service = new WorkunitsServiceEx({ baseUrl: "" });
7082
+ var publishRequest = __assign({ Wuid: this.Wuid, Cluster: this.Cluster, JobName: this.Jobname, AllowForeignFiles: true, Activate: 1, Wait: 5000 }, request);
7083
+ return service.WUPublishWorkunitEx(publishRequest);
7084
+ };
7060
7085
  Workunit.prototype.WUCDebug = function (command, opts) {
7061
7086
  if (opts === void 0) { opts = {}; }
7062
7087
  var optsStr = "";
@@ -8237,7 +8262,750 @@
8237
8262
  return Topology;
8238
8263
  }(util.StateObject));
8239
8264
 
8265
+ // Ported from: https://github.com/hpcc-systems/HPCC-Platform/blob/f0ed9dbeca49c39fb55aa28fec295c89407ac663/esp/src/src/ESPGraph.ts
8266
+ function safeAssign(obj, key, value) {
8267
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
8268
+ return;
8269
+ obj[key] = value;
8270
+ }
8271
+ function xmlEncode(str) {
8272
+ str = "" + str;
8273
+ return str.replace(/&/g, "&amp;")
8274
+ .replace(/"/g, "&quot;")
8275
+ .replace(/'/g, "&apos;")
8276
+ .replace(/</g, "&lt;")
8277
+ .replace(/>/g, "&gt;")
8278
+ .replace(/\n/g, "&#10;")
8279
+ .replace(/\r/g, "&#13;");
8280
+ }
8281
+ function espTime2Seconds(duration) {
8282
+ if (!duration) {
8283
+ return 0;
8284
+ }
8285
+ else if (!isNaN(+duration)) {
8286
+ return parseFloat(duration);
8287
+ }
8288
+ var re = /(?:(?:(\d+).days.)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+\.\d+|\d+)s))|(?:(\d+\.\d+|\d+)ms|(\d+\.\d+|\d+)us|(\d+\.\d+|\d+)ns)/;
8289
+ var match = re.exec(duration);
8290
+ if (!match)
8291
+ return 0;
8292
+ var days = +match[1] || 0;
8293
+ var hours = +match[2] || 0;
8294
+ var mins = +match[3] || 0;
8295
+ var secs = +match[4] || 0;
8296
+ var ms = +match[5] || 0;
8297
+ var us = +match[6] || 0;
8298
+ var ns = +match[7] || 0;
8299
+ return (days * 24 * 60 * 60) + (hours * 60 * 60) + (mins * 60) + secs + ms / 1000 + us / 1000000 + ns / 1000000000;
8300
+ }
8301
+ function unitTest(size, unit) {
8302
+ var nsIndex = size.indexOf(unit);
8303
+ if (nsIndex !== -1) {
8304
+ return parseFloat(size.substring(0, nsIndex));
8305
+ }
8306
+ return -1;
8307
+ }
8308
+ function espSize2Bytes(size) {
8309
+ if (!size) {
8310
+ return 0;
8311
+ }
8312
+ else if (!isNaN(+size)) {
8313
+ return parseFloat(size);
8314
+ }
8315
+ var retVal = unitTest(size, "Kb");
8316
+ if (retVal >= 0) {
8317
+ return retVal * 1024;
8318
+ }
8319
+ retVal = unitTest(size, "Mb");
8320
+ if (retVal >= 0) {
8321
+ return retVal * Math.pow(1024, 2);
8322
+ }
8323
+ retVal = unitTest(size, "Gb");
8324
+ if (retVal >= 0) {
8325
+ return retVal * Math.pow(1024, 3);
8326
+ }
8327
+ retVal = unitTest(size, "Tb");
8328
+ if (retVal >= 0) {
8329
+ return retVal * Math.pow(1024, 4);
8330
+ }
8331
+ retVal = unitTest(size, "Pb");
8332
+ if (retVal >= 0) {
8333
+ return retVal * Math.pow(1024, 5);
8334
+ }
8335
+ retVal = unitTest(size, "Eb");
8336
+ if (retVal >= 0) {
8337
+ return retVal * Math.pow(1024, 6);
8338
+ }
8339
+ retVal = unitTest(size, "Zb");
8340
+ if (retVal >= 0) {
8341
+ return retVal * Math.pow(1024, 7);
8342
+ }
8343
+ retVal = unitTest(size, "b");
8344
+ if (retVal >= 0) {
8345
+ return retVal;
8346
+ }
8347
+ return 0;
8348
+ }
8349
+ function espSkew2Number(skew) {
8350
+ if (!skew) {
8351
+ return 0;
8352
+ }
8353
+ return parseFloat(skew);
8354
+ }
8355
+ var GRAPH_TYPE;
8356
+ (function (GRAPH_TYPE) {
8357
+ GRAPH_TYPE[GRAPH_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
8358
+ GRAPH_TYPE[GRAPH_TYPE["GRAPH"] = 1] = "GRAPH";
8359
+ GRAPH_TYPE[GRAPH_TYPE["SUBGRAPH"] = 2] = "SUBGRAPH";
8360
+ GRAPH_TYPE[GRAPH_TYPE["VERTEX"] = 3] = "VERTEX";
8361
+ GRAPH_TYPE[GRAPH_TYPE["EDGE"] = 4] = "EDGE";
8362
+ GRAPH_TYPE[GRAPH_TYPE["LAST"] = 5] = "LAST";
8363
+ })(GRAPH_TYPE || (GRAPH_TYPE = {}));
8364
+ var GRAPH_TYPE_STRING;
8365
+ (function (GRAPH_TYPE_STRING) {
8366
+ GRAPH_TYPE_STRING["UNKNOWN"] = "Unknown";
8367
+ GRAPH_TYPE_STRING["GRAPH"] = "Graph";
8368
+ GRAPH_TYPE_STRING["SUBGRAPH"] = "Cluster";
8369
+ GRAPH_TYPE_STRING["VERTEX"] = "Vertex";
8370
+ GRAPH_TYPE_STRING["EDGE"] = "Edge";
8371
+ GRAPH_TYPE_STRING["LAST"] = "Last";
8372
+ })(GRAPH_TYPE_STRING || (GRAPH_TYPE_STRING = {}));
8373
+ var LocalisedXGMMLWriter = /** @class */ (function () {
8374
+ function LocalisedXGMMLWriter(graph) {
8375
+ this.graph = graph;
8376
+ this.m_xgmml = "";
8377
+ this.m_visibleSubgraphs = {};
8378
+ this.m_visibleVertices = {};
8379
+ this.m_semiVisibleVertices = {};
8380
+ this.m_visibleEdges = {};
8381
+ }
8382
+ LocalisedXGMMLWriter.prototype.calcVisibility = function (items, localisationDepth, localisationDistance, noSpills) {
8383
+ var _this = this;
8384
+ this.noSpills = noSpills;
8385
+ items.forEach(function (item) {
8386
+ if (_this.graph.isVertex(item)) {
8387
+ _this.calcInVertexVisibility(item, localisationDistance);
8388
+ _this.calcOutVertexVisibility(item, localisationDistance);
8389
+ }
8390
+ else if (_this.graph.isEdge(item)) {
8391
+ _this.calcInVertexVisibility(item.getSource(), localisationDistance - 1);
8392
+ _this.calcOutVertexVisibility(item.getTarget(), localisationDistance - 1);
8393
+ }
8394
+ else if (_this.graph.isSubgraph(item)) {
8395
+ _this.m_visibleSubgraphs[item.__hpcc_id] = item;
8396
+ _this.calcSubgraphVisibility(item, localisationDepth - 1);
8397
+ }
8398
+ });
8399
+ this.calcVisibility2();
8400
+ };
8401
+ LocalisedXGMMLWriter.prototype.calcInVertexVisibility = function (vertex, localisationDistance) {
8402
+ var _this = this;
8403
+ if (this.noSpills && vertex.isSpill()) {
8404
+ localisationDistance++;
8405
+ }
8406
+ this.m_visibleVertices[vertex.__hpcc_id] = vertex;
8407
+ if (localisationDistance > 0) {
8408
+ vertex.getInEdges().forEach(function (edge) {
8409
+ _this.calcInVertexVisibility(edge.getSource(), localisationDistance - 1);
8410
+ });
8411
+ }
8412
+ };
8413
+ LocalisedXGMMLWriter.prototype.calcOutVertexVisibility = function (vertex, localisationDistance) {
8414
+ var _this = this;
8415
+ if (this.noSpills && vertex.isSpill()) {
8416
+ localisationDistance++;
8417
+ }
8418
+ this.m_visibleVertices[vertex.__hpcc_id] = vertex;
8419
+ if (localisationDistance > 0) {
8420
+ vertex.getOutEdges().forEach(function (edge) {
8421
+ _this.calcOutVertexVisibility(edge.getTarget(), localisationDistance - 1);
8422
+ });
8423
+ }
8424
+ };
8425
+ LocalisedXGMMLWriter.prototype.calcSubgraphVisibility = function (subgraph, localisationDepth) {
8426
+ var _this = this;
8427
+ if (localisationDepth < 0) {
8428
+ return;
8429
+ }
8430
+ if (localisationDepth > 0) {
8431
+ subgraph.__hpcc_subgraphs.forEach(function (subgraph, idx) {
8432
+ _this.calcSubgraphVisibility(subgraph, localisationDepth - 1);
8433
+ });
8434
+ }
8435
+ subgraph.__hpcc_subgraphs.forEach(function (subgraph, idx) {
8436
+ _this.m_visibleSubgraphs[subgraph.__hpcc_id] = subgraph;
8437
+ });
8438
+ subgraph.__hpcc_vertices.forEach(function (vertex, idx) {
8439
+ _this.m_visibleVertices[vertex.__hpcc_id] = vertex;
8440
+ });
8441
+ // Calculate edges that pass through the subgraph ---
8442
+ var dedupEdges = {};
8443
+ this.graph.edges.forEach(function (edge, idx) {
8444
+ if (edge.getSource().__hpcc_parent !== edge.getTarget().__hpcc_parent && subgraph === _this.getCommonAncestor(edge)) {
8445
+ // Only include one unique edge between subgraphs ---
8446
+ if (!dedupEdges[edge.getSource().__hpcc_parent.__hpcc_id + "::" + edge.getTarget().__hpcc_parent.__hpcc_id]) {
8447
+ dedupEdges[edge.getSource().__hpcc_parent.__hpcc_id + "::" + edge.getTarget().__hpcc_parent.__hpcc_id] = true;
8448
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
8449
+ }
8450
+ }
8451
+ });
8452
+ };
8453
+ LocalisedXGMMLWriter.prototype.buildVertexString = function (vertex, isPoint) {
8454
+ var attrStr = "";
8455
+ var propsStr = "";
8456
+ var props = vertex.getProperties();
8457
+ for (var key in props) {
8458
+ if (isPoint && key.indexOf("_kind") >= 0) {
8459
+ propsStr += "<att name=\"_kind\" value=\"point\"/>";
8460
+ }
8461
+ else if (key === "id" || key === "label") {
8462
+ attrStr += " " + key + "=\"" + xmlEncode(props[key]) + "\"";
8463
+ }
8464
+ else {
8465
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
8466
+ }
8467
+ }
8468
+ return "<node" + attrStr + ">" + propsStr + "</node>";
8469
+ };
8470
+ LocalisedXGMMLWriter.prototype.buildEdgeString = function (edge) {
8471
+ var attrStr = "";
8472
+ var propsStr = "";
8473
+ var props = edge.getProperties();
8474
+ for (var key in props) {
8475
+ if (key.toLowerCase() === "id" ||
8476
+ key.toLowerCase() === "label" ||
8477
+ key.toLowerCase() === "source" ||
8478
+ key.toLowerCase() === "target") {
8479
+ attrStr += " " + key + "=\"" + xmlEncode(props[key]) + "\"";
8480
+ }
8481
+ else {
8482
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
8483
+ }
8484
+ }
8485
+ return "<edge" + attrStr + ">" + propsStr + "</edge>";
8486
+ };
8487
+ LocalisedXGMMLWriter.prototype.getAncestors = function (v, ancestors) {
8488
+ var parent = v.__hpcc_parent;
8489
+ while (parent) {
8490
+ ancestors.push(parent);
8491
+ parent = parent.__hpcc_parent;
8492
+ }
8493
+ };
8494
+ LocalisedXGMMLWriter.prototype.getCommonAncestorV = function (v1, v2) {
8495
+ var v1_ancestors = [];
8496
+ var v2_ancestors = [];
8497
+ this.getAncestors(v1, v1_ancestors);
8498
+ this.getAncestors(v2, v2_ancestors);
8499
+ var finger1 = v1_ancestors.length - 1;
8500
+ var finger2 = v2_ancestors.length - 1;
8501
+ var retVal = null;
8502
+ while (finger1 >= 0 && finger2 >= 0 && v1_ancestors[finger1] === v2_ancestors[finger2]) {
8503
+ retVal = v1_ancestors[finger1];
8504
+ --finger1;
8505
+ --finger2;
8506
+ }
8507
+ return retVal;
8508
+ };
8509
+ LocalisedXGMMLWriter.prototype.getCommonAncestor = function (e) {
8510
+ return this.getCommonAncestorV(e.getSource(), e.getTarget());
8511
+ };
8512
+ LocalisedXGMMLWriter.prototype.calcAncestorVisibility = function (vertex) {
8513
+ var _this = this;
8514
+ var ancestors = [];
8515
+ this.getAncestors(vertex, ancestors);
8516
+ ancestors.forEach(function (item, idx) {
8517
+ _this.m_visibleSubgraphs[item.__hpcc_id] = item;
8518
+ });
8519
+ };
8520
+ LocalisedXGMMLWriter.prototype.calcVisibility2 = function () {
8521
+ var _this = this;
8522
+ for (var key in this.m_visibleVertices) {
8523
+ var vertex = this.m_visibleVertices[key];
8524
+ vertex.getInEdges().forEach(function (edge, idx) {
8525
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
8526
+ });
8527
+ vertex.getOutEdges().forEach(function (edge, idx) {
8528
+ _this.m_visibleEdges[edge.__hpcc_id] = edge;
8529
+ });
8530
+ this.calcAncestorVisibility(vertex);
8531
+ }
8532
+ this.calcSemiVisibleVertices();
8533
+ };
8534
+ LocalisedXGMMLWriter.prototype.addSemiVisibleEdge = function (edge) {
8535
+ if (edge && !this.m_visibleEdges[edge.__hpcc_id]) {
8536
+ this.m_visibleEdges[edge.__hpcc_id] = edge;
8537
+ }
8538
+ };
8539
+ LocalisedXGMMLWriter.prototype.addSemiVisibleVertex = function (vertex) {
8540
+ if (!this.m_visibleVertices[vertex.__hpcc_id]) {
8541
+ this.m_semiVisibleVertices[vertex.__hpcc_id] = vertex;
8542
+ this.calcAncestorVisibility(vertex);
8543
+ }
8544
+ };
8545
+ LocalisedXGMMLWriter.prototype.calcSemiVisibleVertices = function () {
8546
+ for (var key in this.m_visibleEdges) {
8547
+ var edge = this.m_visibleEdges[key];
8548
+ var source = edge.getSource();
8549
+ this.addSemiVisibleVertex(source);
8550
+ while (this.noSpills && source.isSpill()) {
8551
+ var inEdges = source.getInEdges();
8552
+ if (inEdges.length) {
8553
+ this.addSemiVisibleEdge(inEdges[0]);
8554
+ source = inEdges[0].getSource();
8555
+ this.addSemiVisibleVertex(source);
8556
+ }
8557
+ else {
8558
+ break;
8559
+ }
8560
+ }
8561
+ var target = edge.getTarget();
8562
+ this.addSemiVisibleVertex(target);
8563
+ while (this.noSpills && target.isSpill()) {
8564
+ var outEdges = target.getOutEdges();
8565
+ if (outEdges.length) {
8566
+ this.addSemiVisibleEdge(outEdges[0]);
8567
+ target = outEdges[0].getTarget();
8568
+ this.addSemiVisibleVertex(target);
8569
+ }
8570
+ else {
8571
+ break;
8572
+ }
8573
+ }
8574
+ }
8575
+ };
8576
+ LocalisedXGMMLWriter.prototype.writeXgmml = function () {
8577
+ var _this = this;
8578
+ this.subgraphVisited(this.graph.subgraphs[0], true);
8579
+ this.graph.edges.forEach(function (edge, idx) {
8580
+ _this.edgeVisited(edge);
8581
+ });
8582
+ };
8583
+ LocalisedXGMMLWriter.prototype.subgraphVisited = function (subgraph, root) {
8584
+ if (root === void 0) { root = false; }
8585
+ if (this.m_visibleSubgraphs[subgraph.__hpcc_id]) {
8586
+ var propsStr = "";
8587
+ this.m_xgmml += root ? "" : "<node id=\"" + subgraph.__hpcc_id + "\"><att><graph>";
8588
+ var xgmmlLen = this.m_xgmml.length;
8589
+ subgraph.walkSubgraphs(this);
8590
+ subgraph.walkVertices(this);
8591
+ if (xgmmlLen === this.m_xgmml.length) {
8592
+ // Add at least one child otherwise subgraphs will render as a vertex ---
8593
+ var vertex = subgraph.__hpcc_vertices[0];
8594
+ if (vertex) {
8595
+ this.m_xgmml += this.buildVertexString(vertex, true);
8596
+ }
8597
+ }
8598
+ var props = subgraph.getProperties();
8599
+ for (var key in props) {
8600
+ propsStr += "<att name=\"" + key + "\" value=\"" + xmlEncode(props[key]) + "\"/>";
8601
+ }
8602
+ this.m_xgmml += root ? "" : "</graph></att>" + propsStr + "</node>";
8603
+ }
8604
+ return false;
8605
+ };
8606
+ LocalisedXGMMLWriter.prototype.vertexVisited = function (vertex) {
8607
+ if (this.m_visibleVertices[vertex.__hpcc_id]) {
8608
+ this.m_xgmml += this.buildVertexString(vertex, false);
8609
+ }
8610
+ else if (this.m_semiVisibleVertices[vertex.__hpcc_id]) {
8611
+ this.m_xgmml += this.buildVertexString(vertex, true);
8612
+ }
8613
+ };
8614
+ LocalisedXGMMLWriter.prototype.edgeVisited = function (edge) {
8615
+ if (this.m_visibleEdges[edge.__hpcc_id]) {
8616
+ this.m_xgmml += this.buildEdgeString(edge);
8617
+ }
8618
+ };
8619
+ return LocalisedXGMMLWriter;
8620
+ }());
8621
+ var GraphItem = /** @class */ (function () {
8622
+ function GraphItem(graph, id) {
8623
+ this.__hpcc_graph = graph;
8624
+ this.__hpcc_id = id;
8625
+ this._globalID = id;
8626
+ }
8627
+ GraphItem.prototype.getProperties = function () {
8628
+ var retVal = {};
8629
+ for (var key in this) {
8630
+ if (key.indexOf("__") !== 0 && this.hasOwnProperty(key)) {
8631
+ retVal[key] = this[key];
8632
+ }
8633
+ }
8634
+ return retVal;
8635
+ };
8636
+ return GraphItem;
8637
+ }());
8638
+ var Subgraph = /** @class */ (function (_super) {
8639
+ __extends(Subgraph, _super);
8640
+ function Subgraph(graph, id) {
8641
+ var _this = _super.call(this, graph, id) || this;
8642
+ _this._globalType = id === "0" ? "Graph" : "Cluster";
8643
+ _this.__hpcc_subgraphs = [];
8644
+ _this.__hpcc_vertices = [];
8645
+ _this.__hpcc_edges = [];
8646
+ _this.id = id;
8647
+ return _this;
8648
+ }
8649
+ Subgraph.prototype.addSubgraph = function (subgraph) {
8650
+ subgraph.__hpcc_parent = this;
8651
+ if (!this.__hpcc_subgraphs.some(function (subgraph2) { return subgraph === subgraph2; })) {
8652
+ this.__hpcc_subgraphs.push(subgraph);
8653
+ }
8654
+ };
8655
+ Subgraph.prototype.addVertex = function (vertex) {
8656
+ vertex.__hpcc_parent = this;
8657
+ if (!this.__hpcc_vertices.some(function (vertex2) { return vertex === vertex2; })) {
8658
+ this.__hpcc_vertices.push(vertex);
8659
+ }
8660
+ };
8661
+ Subgraph.prototype.removeVertex = function (vertex) {
8662
+ this.__hpcc_vertices = this.__hpcc_vertices.filter(function (vertex2) { return vertex !== vertex2; });
8663
+ };
8664
+ Subgraph.prototype.addEdge = function (edge) {
8665
+ edge.__hpcc_parent = this;
8666
+ if (!this.__hpcc_edges.some(function (edge2) { return edge === edge2; })) {
8667
+ this.__hpcc_edges.push(edge);
8668
+ }
8669
+ };
8670
+ Subgraph.prototype.removeEdge = function (edge) {
8671
+ this.__hpcc_edges = this.__hpcc_edges.filter(function (edge2) { return edge !== edge2; });
8672
+ };
8673
+ Subgraph.prototype.remove = function () {
8674
+ var _this = this;
8675
+ this.__hpcc_subgraphs.forEach(function (subgraph) { return subgraph.__hpcc_parent = _this.__hpcc_parent; });
8676
+ this.__hpcc_vertices.forEach(function (vertex) { return vertex.__hpcc_parent = _this.__hpcc_parent; });
8677
+ this.__hpcc_edges.forEach(function (edge) { return edge.__hpcc_parent = _this.__hpcc_parent; });
8678
+ delete this.__hpcc_parent;
8679
+ this.__hpcc_graph.removeItem(this);
8680
+ };
8681
+ Subgraph.prototype.walkSubgraphs = function (visitor) {
8682
+ this.__hpcc_subgraphs.forEach(function (subgraph, idx) {
8683
+ if (visitor.subgraphVisited(subgraph)) {
8684
+ subgraph.walkSubgraphs(visitor);
8685
+ }
8686
+ });
8687
+ };
8688
+ Subgraph.prototype.walkVertices = function (visitor) {
8689
+ this.__hpcc_vertices.forEach(function (vertex, idx) {
8690
+ visitor.vertexVisited(vertex);
8691
+ });
8692
+ };
8693
+ return Subgraph;
8694
+ }(GraphItem));
8695
+ var Vertex = /** @class */ (function (_super) {
8696
+ __extends(Vertex, _super);
8697
+ function Vertex(graph, id) {
8698
+ var _this = _super.call(this, graph, id) || this;
8699
+ _this._globalType = "Vertex";
8700
+ return _this;
8701
+ }
8702
+ Vertex.prototype.isSpill = function () {
8703
+ return this._isSpill;
8704
+ };
8705
+ Vertex.prototype.remove = function () {
8706
+ var _a;
8707
+ var inVertices = this.getInVertices();
8708
+ if (inVertices.length <= 1) {
8709
+ console.warn(this.__hpcc_id + ": remove only supports single or zero inputs activities...");
8710
+ }
8711
+ this.getInEdges().forEach(function (edge) {
8712
+ edge.remove();
8713
+ });
8714
+ this.getOutEdges().forEach(function (edge) {
8715
+ edge.setSource(inVertices[0]);
8716
+ });
8717
+ (_a = this.__hpcc_parent) === null || _a === void 0 ? void 0 : _a.removeVertex(this);
8718
+ this.__hpcc_graph.removeItem(this);
8719
+ };
8720
+ Vertex.prototype.getInVertices = function () {
8721
+ return this.getInEdges().map(function (edge) {
8722
+ return edge.getSource();
8723
+ });
8724
+ };
8725
+ Vertex.prototype.getInEdges = function () {
8726
+ var _this = this;
8727
+ return this.__hpcc_graph.edges.filter(function (edge) {
8728
+ return edge.getTarget() === _this;
8729
+ });
8730
+ };
8731
+ Vertex.prototype.getOutVertices = function () {
8732
+ return this.getOutEdges().map(function (edge) {
8733
+ return edge.getTarget();
8734
+ });
8735
+ };
8736
+ Vertex.prototype.getOutEdges = function () {
8737
+ var _this = this;
8738
+ return this.__hpcc_graph.edges.filter(function (edge) {
8739
+ return edge.getSource() === _this;
8740
+ });
8741
+ };
8742
+ return Vertex;
8743
+ }(GraphItem));
8744
+ var Edge = /** @class */ (function (_super) {
8745
+ __extends(Edge, _super);
8746
+ function Edge(graph, id) {
8747
+ var _this = _super.call(this, graph, id) || this;
8748
+ _this._globalType = "Edge";
8749
+ _this._globalType = "Edge";
8750
+ return _this;
8751
+ }
8752
+ Edge.prototype.remove = function () {
8753
+ var _this = this;
8754
+ this.__hpcc_graph.subgraphs.forEach(function (subgraph) {
8755
+ subgraph.removeEdge(_this);
8756
+ });
8757
+ this.__hpcc_graph.removeItem(this);
8758
+ };
8759
+ Edge.prototype.getSource = function () {
8760
+ return this.__hpcc_graph.idx[this._sourceActivity || this.source];
8761
+ };
8762
+ Edge.prototype.setSource = function (source) {
8763
+ if (this._sourceActivity) {
8764
+ this._sourceActivity = source.__hpcc_id;
8765
+ }
8766
+ else if (this.source) {
8767
+ this.source = source.__hpcc_id;
8768
+ }
8769
+ if (this.__widget) {
8770
+ this.__widget.setSource(this.getSource().__widget);
8771
+ }
8772
+ };
8773
+ Edge.prototype.getTarget = function () {
8774
+ return this.__hpcc_graph.idx[this._targetActivity || this.target];
8775
+ };
8776
+ return Edge;
8777
+ }(GraphItem));
8778
+ var QueryGraph = /** @class */ (function () {
8779
+ function QueryGraph() {
8780
+ this.idx = {};
8781
+ this.subgraphs = [];
8782
+ this.vertices = [];
8783
+ this.edges = [];
8784
+ this.xgmml = "";
8785
+ this.clear();
8786
+ }
8787
+ QueryGraph.prototype.clear = function () {
8788
+ this.xgmml = "";
8789
+ this.idx = {};
8790
+ this.subgraphs = [];
8791
+ this.vertices = [];
8792
+ this.edges = [];
8793
+ };
8794
+ QueryGraph.prototype.load = function (xgmml) {
8795
+ this.clear();
8796
+ this.merge(xgmml);
8797
+ };
8798
+ QueryGraph.prototype.merge = function (xgmml) {
8799
+ this.xgmml = xgmml;
8800
+ var parser = new DOMParser();
8801
+ var dom = parser.parseFromString(xgmml, "text/xml");
8802
+ this.walkDocument(dom.documentElement, "0");
8803
+ };
8804
+ QueryGraph.prototype.isSubgraph = function (item) {
8805
+ return item instanceof Subgraph;
8806
+ };
8807
+ QueryGraph.prototype.isVertex = function (item) {
8808
+ return item instanceof Vertex;
8809
+ };
8810
+ QueryGraph.prototype.isEdge = function (item) {
8811
+ return item instanceof Edge;
8812
+ };
8813
+ QueryGraph.prototype.getGlobalType = function (item) {
8814
+ if (item instanceof Vertex) {
8815
+ return GRAPH_TYPE.VERTEX;
8816
+ }
8817
+ else if (item instanceof Edge) {
8818
+ return GRAPH_TYPE.EDGE;
8819
+ }
8820
+ else if (item instanceof Subgraph) {
8821
+ return GRAPH_TYPE.SUBGRAPH;
8822
+ }
8823
+ else if (item instanceof QueryGraph) {
8824
+ return GRAPH_TYPE.GRAPH;
8825
+ }
8826
+ return GRAPH_TYPE.UNKNOWN;
8827
+ };
8828
+ QueryGraph.prototype.getGlobalTypeString = function (item) {
8829
+ if (item instanceof Vertex) {
8830
+ return GRAPH_TYPE_STRING.VERTEX;
8831
+ }
8832
+ else if (item instanceof Edge) {
8833
+ return GRAPH_TYPE_STRING.EDGE;
8834
+ }
8835
+ else if (item instanceof Subgraph) {
8836
+ return GRAPH_TYPE_STRING.SUBGRAPH;
8837
+ }
8838
+ else if (item instanceof QueryGraph) {
8839
+ return GRAPH_TYPE_STRING.GRAPH;
8840
+ }
8841
+ return GRAPH_TYPE_STRING.UNKNOWN;
8842
+ };
8843
+ QueryGraph.prototype.getItem = function (docNode, id) {
8844
+ if (!this.idx[id]) {
8845
+ switch (docNode.tagName) {
8846
+ case "graph":
8847
+ var subgraph = new Subgraph(this, id);
8848
+ this.subgraphs.push(subgraph);
8849
+ this.idx[id] = subgraph;
8850
+ break;
8851
+ case "node":
8852
+ var vertex = new Vertex(this, id);
8853
+ this.vertices.push(vertex);
8854
+ this.idx[id] = vertex;
8855
+ break;
8856
+ case "edge":
8857
+ var edge = new Edge(this, id);
8858
+ this.edges.push(edge);
8859
+ this.idx[id] = edge;
8860
+ break;
8861
+ default:
8862
+ console.warn("Graph.getItem - Unknown Node Type!");
8863
+ break;
8864
+ }
8865
+ }
8866
+ var retVal = this.idx[id];
8867
+ Array.from(docNode.attributes).forEach(function (attr) {
8868
+ safeAssign(retVal, attr.name, attr.value);
8869
+ });
8870
+ return retVal;
8871
+ };
8872
+ QueryGraph.prototype.removeItem = function (item) {
8873
+ delete this.idx[item.__hpcc_id];
8874
+ if (item instanceof Subgraph) {
8875
+ this.subgraphs = this.subgraphs.filter(function (subgraph) {
8876
+ return item !== subgraph;
8877
+ });
8878
+ }
8879
+ else if (item instanceof Vertex) {
8880
+ this.vertices = this.vertices.filter(function (vertex) {
8881
+ return item !== vertex;
8882
+ });
8883
+ }
8884
+ else if (item instanceof Edge) {
8885
+ this.edges = this.edges.filter(function (edge) {
8886
+ return item !== edge;
8887
+ });
8888
+ }
8889
+ };
8890
+ QueryGraph.prototype.getChildByTagName = function (docNode, tagName) {
8891
+ var retVal = null;
8892
+ Array.from(docNode.childNodes).some(function (childNode, idx) {
8893
+ if (childNode.tagName === tagName) {
8894
+ retVal = childNode;
8895
+ return true;
8896
+ }
8897
+ });
8898
+ return retVal;
8899
+ };
8900
+ QueryGraph.prototype.walkDocument = function (docNode, id) {
8901
+ var _this = this;
8902
+ var retVal = this.getItem(docNode, id);
8903
+ docNode.childNodes.forEach(function (childNode, idx) {
8904
+ switch (childNode.nodeType) {
8905
+ case 1: // ELEMENT_NODE
8906
+ switch (childNode.tagName) {
8907
+ case "graph":
8908
+ break;
8909
+ case "node":
8910
+ var isSubgraph = false;
8911
+ var attNode = _this.getChildByTagName(childNode, "att");
8912
+ if (attNode) {
8913
+ var graphNode = _this.getChildByTagName(attNode, "graph");
8914
+ if (graphNode) {
8915
+ isSubgraph = true;
8916
+ var subgraph = _this.walkDocument(graphNode, childNode.getAttribute("id"));
8917
+ retVal.addSubgraph(subgraph);
8918
+ }
8919
+ }
8920
+ if (!isSubgraph) {
8921
+ var vertex = _this.walkDocument(childNode, childNode.getAttribute("id"));
8922
+ retVal.addVertex(vertex);
8923
+ }
8924
+ break;
8925
+ case "att":
8926
+ var name_1 = childNode.getAttribute("name");
8927
+ var uname = "_" + name_1;
8928
+ var value = childNode.getAttribute("value");
8929
+ if (name_1.indexOf("Time") === 0) {
8930
+ safeAssign(retVal, uname, value);
8931
+ safeAssign(retVal, name_1, "" + espTime2Seconds(value));
8932
+ }
8933
+ else if (name_1.indexOf("Size") === 0) {
8934
+ safeAssign(retVal, uname, value);
8935
+ safeAssign(retVal, name_1, "" + espSize2Bytes(value));
8936
+ }
8937
+ else if (name_1.indexOf("Skew") === 0) {
8938
+ safeAssign(retVal, uname, value);
8939
+ safeAssign(retVal, name_1, "" + espSkew2Number(value));
8940
+ }
8941
+ else {
8942
+ safeAssign(retVal, name_1, value);
8943
+ }
8944
+ break;
8945
+ case "edge":
8946
+ var edge = _this.walkDocument(childNode, childNode.getAttribute("id"));
8947
+ if (edge.NumRowsProcessed !== undefined) {
8948
+ edge._eclwatchCount = edge.NumRowsProcessed.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
8949
+ }
8950
+ else if (edge.Count !== undefined) {
8951
+ edge._eclwatchCount = edge.Count.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
8952
+ }
8953
+ else if (edge.count !== undefined) {
8954
+ edge._eclwatchCount = edge.count.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
8955
+ }
8956
+ if (edge.inputProgress) {
8957
+ edge._eclwatchInputProgress = "[" + edge.inputProgress.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "]";
8958
+ }
8959
+ if (edge.SkewMaxRowsProcessed && edge.SkewMinRowsProcessed) {
8960
+ edge._eclwatchSkew = "+" + edge.SkewMaxRowsProcessed + ", " + edge.SkewMinRowsProcessed;
8961
+ }
8962
+ if (edge._dependsOn) ;
8963
+ else if (edge._childGraph) ;
8964
+ else if (edge._sourceActivity || edge._targetActivity) {
8965
+ edge._isSpill = true;
8966
+ var source = edge.getSource();
8967
+ source._isSpill = true;
8968
+ var target = edge.getTarget();
8969
+ target._isSpill = true;
8970
+ }
8971
+ retVal.addEdge(edge);
8972
+ break;
8973
+ }
8974
+ break;
8975
+ }
8976
+ });
8977
+ return retVal;
8978
+ };
8979
+ QueryGraph.prototype.removeSubgraphs = function () {
8980
+ var subgraphs = __spreadArray([], this.subgraphs, true);
8981
+ subgraphs.forEach(function (subgraph) {
8982
+ if (subgraph.__hpcc_parent instanceof Subgraph) {
8983
+ subgraph.remove();
8984
+ }
8985
+ });
8986
+ };
8987
+ QueryGraph.prototype.removeSpillVertices = function () {
8988
+ var vertices = __spreadArray([], this.vertices, true);
8989
+ vertices.forEach(function (vertex) {
8990
+ if (vertex.isSpill()) {
8991
+ vertex.remove();
8992
+ }
8993
+ });
8994
+ };
8995
+ QueryGraph.prototype.getLocalisedXGMML = function (items, localisationDepth, localisationDistance, noSpills) {
8996
+ var xgmmlWriter = new LocalisedXGMMLWriter(this);
8997
+ xgmmlWriter.calcVisibility(items, localisationDepth, localisationDistance, noSpills);
8998
+ xgmmlWriter.writeXgmml();
8999
+ return "<graph>" + xgmmlWriter.m_xgmml + "</graph>";
9000
+ };
9001
+ return QueryGraph;
9002
+ }());
9003
+
8240
9004
  var logger$1 = util.scopedLogger("@hpcc-js/comms/ecl/query.ts");
9005
+ var siFormatter = format("~s");
9006
+ function isNumber(n) {
9007
+ return !isNaN(parseFloat(n)) && !isNaN(n - 0);
9008
+ }
8241
9009
  var QueryCache = /** @class */ (function (_super) {
8242
9010
  __extends(QueryCache, _super);
8243
9011
  function QueryCache() {
@@ -8513,6 +9281,66 @@
8513
9281
  Query.prototype.fetchSummaryStats = function () {
8514
9282
  return this.wsWorkunitsService.WUQueryGetSummaryStats({ Target: this.QuerySet, QueryId: this.QueryId });
8515
9283
  };
9284
+ Query.prototype.fetchGraph = function (GraphName, SubGraphId) {
9285
+ if (GraphName === void 0) { GraphName = ""; }
9286
+ if (SubGraphId === void 0) { SubGraphId = ""; }
9287
+ return this.wsWorkunitsService.WUQueryGetGraph({ Target: this.QuerySet, QueryId: this.QueryId, GraphName: GraphName, SubGraphId: SubGraphId }).then(function (response) {
9288
+ var _a;
9289
+ var graph = new QueryGraph();
9290
+ var first = true;
9291
+ for (var _i = 0, _b = ((_a = response === null || response === void 0 ? void 0 : response.Graphs) === null || _a === void 0 ? void 0 : _a.ECLGraphEx) || []; _i < _b.length; _i++) {
9292
+ var graphItem = _b[_i];
9293
+ if (first) {
9294
+ graph.load(graphItem.Graph);
9295
+ first = false;
9296
+ }
9297
+ else {
9298
+ graph.merge(graphItem.Graph);
9299
+ }
9300
+ }
9301
+ return graph;
9302
+ });
9303
+ };
9304
+ Query.prototype.fetchDetailsNormalized = function (request) {
9305
+ if (request === void 0) { request = {}; }
9306
+ var wu = Workunit.attach(this.wsWorkunitsService, this.Wuid);
9307
+ if (wu) {
9308
+ return Promise.all([this.fetchGraph(), wu.fetchDetailsMeta(), wu.fetchDetailsRaw(request)]).then(function (promises) {
9309
+ var graph = promises[0];
9310
+ var meta = promises[1];
9311
+ var metrics = promises[2];
9312
+ var data = metrics.map(function (metric) {
9313
+ if (metric.Id[0] === "a" || metric.Id[0] === "e") {
9314
+ var item = graph.idx[metric.Id.substring(1)];
9315
+ var _loop_1 = function (key) {
9316
+ if (key.charAt(0) !== "_" && key.charAt(0) === key.charAt(0).toUpperCase() && (typeof item[key] === "string" || typeof item[key] === "number" || typeof item[key] === "boolean")) {
9317
+ if (!metric.Properties.Property.some(function (row) { return row.Name === key; })) {
9318
+ var isNum = isNumber(item[key]);
9319
+ var rawValue = isNum ? parseFloat(item[key]) : item[key];
9320
+ var formatted = item[key];
9321
+ if (key.indexOf("Time") >= 0) {
9322
+ rawValue = rawValue / 1000000000;
9323
+ formatted = siFormatter(rawValue) + "s";
9324
+ }
9325
+ metric.Properties.Property.push({
9326
+ Name: key,
9327
+ RawValue: rawValue,
9328
+ Formatted: formatted
9329
+ });
9330
+ }
9331
+ }
9332
+ };
9333
+ for (var key in item) {
9334
+ _loop_1(key);
9335
+ }
9336
+ }
9337
+ return metric;
9338
+ });
9339
+ return wu.normalizeDetails(meta, data);
9340
+ });
9341
+ }
9342
+ return Promise.resolve({ meta: undefined, columns: undefined, data: undefined });
9343
+ };
8516
9344
  Query.prototype.submit = function (request) {
8517
9345
  var _a;
8518
9346
  return __awaiter(this, void 0, void 0, function () {
@@ -9351,6 +10179,7 @@
9351
10179
  exports.PackageProcessService = PackageProcessService;
9352
10180
  exports.PropertyType = PropertyType;
9353
10181
  exports.Query = Query;
10182
+ exports.QueryGraph = QueryGraph;
9354
10183
  exports.RelatedProperty = RelatedProperty;
9355
10184
  exports.Resource = Resource;
9356
10185
  exports.ResourcesService = ResourcesService;