UNPKG

231 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@hpcc-js/util')) :
3 typeof define === 'function' && define.amd ? define(['exports', '@hpcc-js/util'], factory) :
4 (global = global || self, factory(global['@hpcc-js/comms'] = {}, global['@hpcc-js/util']));
5}(this, (function (exports, util) { 'use strict';
6
7 (function(self) {
8
9 if (self.fetch) {
10 return
11 }
12
13 var support = {
14 searchParams: 'URLSearchParams' in self,
15 iterable: 'Symbol' in self && 'iterator' in Symbol,
16 blob: 'FileReader' in self && 'Blob' in self && (function() {
17 try {
18 new Blob();
19 return true
20 } catch(e) {
21 return false
22 }
23 })(),
24 formData: 'FormData' in self,
25 arrayBuffer: 'ArrayBuffer' in self
26 };
27
28 if (support.arrayBuffer) {
29 var viewClasses = [
30 '[object Int8Array]',
31 '[object Uint8Array]',
32 '[object Uint8ClampedArray]',
33 '[object Int16Array]',
34 '[object Uint16Array]',
35 '[object Int32Array]',
36 '[object Uint32Array]',
37 '[object Float32Array]',
38 '[object Float64Array]'
39 ];
40
41 var isDataView = function(obj) {
42 return obj && DataView.prototype.isPrototypeOf(obj)
43 };
44
45 var isArrayBufferView = ArrayBuffer.isView || function(obj) {
46 return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
47 };
48 }
49
50 function normalizeName(name) {
51 if (typeof name !== 'string') {
52 name = String(name);
53 }
54 if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
55 throw new TypeError('Invalid character in header field name')
56 }
57 return name.toLowerCase()
58 }
59
60 function normalizeValue(value) {
61 if (typeof value !== 'string') {
62 value = String(value);
63 }
64 return value
65 }
66
67 // Build a destructive iterator for the value list
68 function iteratorFor(items) {
69 var iterator = {
70 next: function() {
71 var value = items.shift();
72 return {done: value === undefined, value: value}
73 }
74 };
75
76 if (support.iterable) {
77 iterator[Symbol.iterator] = function() {
78 return iterator
79 };
80 }
81
82 return iterator
83 }
84
85 function Headers(headers) {
86 this.map = {};
87
88 if (headers instanceof Headers) {
89 headers.forEach(function(value, name) {
90 this.append(name, value);
91 }, this);
92 } else if (Array.isArray(headers)) {
93 headers.forEach(function(header) {
94 this.append(header[0], header[1]);
95 }, this);
96 } else if (headers) {
97 Object.getOwnPropertyNames(headers).forEach(function(name) {
98 this.append(name, headers[name]);
99 }, this);
100 }
101 }
102
103 Headers.prototype.append = function(name, value) {
104 name = normalizeName(name);
105 value = normalizeValue(value);
106 var oldValue = this.map[name];
107 this.map[name] = oldValue ? oldValue+','+value : value;
108 };
109
110 Headers.prototype['delete'] = function(name) {
111 delete this.map[normalizeName(name)];
112 };
113
114 Headers.prototype.get = function(name) {
115 name = normalizeName(name);
116 return this.has(name) ? this.map[name] : null
117 };
118
119 Headers.prototype.has = function(name) {
120 return this.map.hasOwnProperty(normalizeName(name))
121 };
122
123 Headers.prototype.set = function(name, value) {
124 this.map[normalizeName(name)] = normalizeValue(value);
125 };
126
127 Headers.prototype.forEach = function(callback, thisArg) {
128 for (var name in this.map) {
129 if (this.map.hasOwnProperty(name)) {
130 callback.call(thisArg, this.map[name], name, this);
131 }
132 }
133 };
134
135 Headers.prototype.keys = function() {
136 var items = [];
137 this.forEach(function(value, name) { items.push(name); });
138 return iteratorFor(items)
139 };
140
141 Headers.prototype.values = function() {
142 var items = [];
143 this.forEach(function(value) { items.push(value); });
144 return iteratorFor(items)
145 };
146
147 Headers.prototype.entries = function() {
148 var items = [];
149 this.forEach(function(value, name) { items.push([name, value]); });
150 return iteratorFor(items)
151 };
152
153 if (support.iterable) {
154 Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
155 }
156
157 function consumed(body) {
158 if (body.bodyUsed) {
159 return Promise.reject(new TypeError('Already read'))
160 }
161 body.bodyUsed = true;
162 }
163
164 function fileReaderReady(reader) {
165 return new Promise(function(resolve, reject) {
166 reader.onload = function() {
167 resolve(reader.result);
168 };
169 reader.onerror = function() {
170 reject(reader.error);
171 };
172 })
173 }
174
175 function readBlobAsArrayBuffer(blob) {
176 var reader = new FileReader();
177 var promise = fileReaderReady(reader);
178 reader.readAsArrayBuffer(blob);
179 return promise
180 }
181
182 function readBlobAsText(blob) {
183 var reader = new FileReader();
184 var promise = fileReaderReady(reader);
185 reader.readAsText(blob);
186 return promise
187 }
188
189 function readArrayBufferAsText(buf) {
190 var view = new Uint8Array(buf);
191 var chars = new Array(view.length);
192
193 for (var i = 0; i < view.length; i++) {
194 chars[i] = String.fromCharCode(view[i]);
195 }
196 return chars.join('')
197 }
198
199 function bufferClone(buf) {
200 if (buf.slice) {
201 return buf.slice(0)
202 } else {
203 var view = new Uint8Array(buf.byteLength);
204 view.set(new Uint8Array(buf));
205 return view.buffer
206 }
207 }
208
209 function Body() {
210 this.bodyUsed = false;
211
212 this._initBody = function(body) {
213 this._bodyInit = body;
214 if (!body) {
215 this._bodyText = '';
216 } else if (typeof body === 'string') {
217 this._bodyText = body;
218 } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
219 this._bodyBlob = body;
220 } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
221 this._bodyFormData = body;
222 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
223 this._bodyText = body.toString();
224 } else if (support.arrayBuffer && support.blob && isDataView(body)) {
225 this._bodyArrayBuffer = bufferClone(body.buffer);
226 // IE 10-11 can't handle a DataView body.
227 this._bodyInit = new Blob([this._bodyArrayBuffer]);
228 } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
229 this._bodyArrayBuffer = bufferClone(body);
230 } else {
231 throw new Error('unsupported BodyInit type')
232 }
233
234 if (!this.headers.get('content-type')) {
235 if (typeof body === 'string') {
236 this.headers.set('content-type', 'text/plain;charset=UTF-8');
237 } else if (this._bodyBlob && this._bodyBlob.type) {
238 this.headers.set('content-type', this._bodyBlob.type);
239 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
240 this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
241 }
242 }
243 };
244
245 if (support.blob) {
246 this.blob = function() {
247 var rejected = consumed(this);
248 if (rejected) {
249 return rejected
250 }
251
252 if (this._bodyBlob) {
253 return Promise.resolve(this._bodyBlob)
254 } else if (this._bodyArrayBuffer) {
255 return Promise.resolve(new Blob([this._bodyArrayBuffer]))
256 } else if (this._bodyFormData) {
257 throw new Error('could not read FormData body as blob')
258 } else {
259 return Promise.resolve(new Blob([this._bodyText]))
260 }
261 };
262
263 this.arrayBuffer = function() {
264 if (this._bodyArrayBuffer) {
265 return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
266 } else {
267 return this.blob().then(readBlobAsArrayBuffer)
268 }
269 };
270 }
271
272 this.text = function() {
273 var rejected = consumed(this);
274 if (rejected) {
275 return rejected
276 }
277
278 if (this._bodyBlob) {
279 return readBlobAsText(this._bodyBlob)
280 } else if (this._bodyArrayBuffer) {
281 return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
282 } else if (this._bodyFormData) {
283 throw new Error('could not read FormData body as text')
284 } else {
285 return Promise.resolve(this._bodyText)
286 }
287 };
288
289 if (support.formData) {
290 this.formData = function() {
291 return this.text().then(decode)
292 };
293 }
294
295 this.json = function() {
296 return this.text().then(JSON.parse)
297 };
298
299 return this
300 }
301
302 // HTTP methods whose capitalization should be normalized
303 var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
304
305 function normalizeMethod(method) {
306 var upcased = method.toUpperCase();
307 return (methods.indexOf(upcased) > -1) ? upcased : method
308 }
309
310 function Request(input, options) {
311 options = options || {};
312 var body = options.body;
313
314 if (input instanceof Request) {
315 if (input.bodyUsed) {
316 throw new TypeError('Already read')
317 }
318 this.url = input.url;
319 this.credentials = input.credentials;
320 if (!options.headers) {
321 this.headers = new Headers(input.headers);
322 }
323 this.method = input.method;
324 this.mode = input.mode;
325 if (!body && input._bodyInit != null) {
326 body = input._bodyInit;
327 input.bodyUsed = true;
328 }
329 } else {
330 this.url = String(input);
331 }
332
333 this.credentials = options.credentials || this.credentials || 'omit';
334 if (options.headers || !this.headers) {
335 this.headers = new Headers(options.headers);
336 }
337 this.method = normalizeMethod(options.method || this.method || 'GET');
338 this.mode = options.mode || this.mode || null;
339 this.referrer = null;
340
341 if ((this.method === 'GET' || this.method === 'HEAD') && body) {
342 throw new TypeError('Body not allowed for GET or HEAD requests')
343 }
344 this._initBody(body);
345 }
346
347 Request.prototype.clone = function() {
348 return new Request(this, { body: this._bodyInit })
349 };
350
351 function decode(body) {
352 var form = new FormData();
353 body.trim().split('&').forEach(function(bytes) {
354 if (bytes) {
355 var split = bytes.split('=');
356 var name = split.shift().replace(/\+/g, ' ');
357 var value = split.join('=').replace(/\+/g, ' ');
358 form.append(decodeURIComponent(name), decodeURIComponent(value));
359 }
360 });
361 return form
362 }
363
364 function parseHeaders(rawHeaders) {
365 var headers = new Headers();
366 rawHeaders.split(/\r?\n/).forEach(function(line) {
367 var parts = line.split(':');
368 var key = parts.shift().trim();
369 if (key) {
370 var value = parts.join(':').trim();
371 headers.append(key, value);
372 }
373 });
374 return headers
375 }
376
377 Body.call(Request.prototype);
378
379 function Response(bodyInit, options) {
380 if (!options) {
381 options = {};
382 }
383
384 this.type = 'default';
385 this.status = 'status' in options ? options.status : 200;
386 this.ok = this.status >= 200 && this.status < 300;
387 this.statusText = 'statusText' in options ? options.statusText : 'OK';
388 this.headers = new Headers(options.headers);
389 this.url = options.url || '';
390 this._initBody(bodyInit);
391 }
392
393 Body.call(Response.prototype);
394
395 Response.prototype.clone = function() {
396 return new Response(this._bodyInit, {
397 status: this.status,
398 statusText: this.statusText,
399 headers: new Headers(this.headers),
400 url: this.url
401 })
402 };
403
404 Response.error = function() {
405 var response = new Response(null, {status: 0, statusText: ''});
406 response.type = 'error';
407 return response
408 };
409
410 var redirectStatuses = [301, 302, 303, 307, 308];
411
412 Response.redirect = function(url, status) {
413 if (redirectStatuses.indexOf(status) === -1) {
414 throw new RangeError('Invalid status code')
415 }
416
417 return new Response(null, {status: status, headers: {location: url}})
418 };
419
420 self.Headers = Headers;
421 self.Request = Request;
422 self.Response = Response;
423
424 self.fetch = function(input, init) {
425 return new Promise(function(resolve, reject) {
426 var request = new Request(input, init);
427 var xhr = new XMLHttpRequest();
428
429 xhr.onload = function() {
430 var options = {
431 status: xhr.status,
432 statusText: xhr.statusText,
433 headers: parseHeaders(xhr.getAllResponseHeaders() || '')
434 };
435 options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
436 var body = 'response' in xhr ? xhr.response : xhr.responseText;
437 resolve(new Response(body, options));
438 };
439
440 xhr.onerror = function() {
441 reject(new TypeError('Network request failed'));
442 };
443
444 xhr.ontimeout = function() {
445 reject(new TypeError('Network request failed'));
446 };
447
448 xhr.open(request.method, request.url, true);
449
450 if (request.credentials === 'include') {
451 xhr.withCredentials = true;
452 }
453
454 if ('responseType' in xhr && support.blob) {
455 xhr.responseType = 'blob';
456 }
457
458 request.headers.forEach(function(value, name) {
459 xhr.setRequestHeader(name, value);
460 });
461
462 xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
463 })
464 };
465 self.fetch.polyfill = true;
466 })(typeof self !== 'undefined' ? self : undefined);
467
468 var PKG_NAME = "@hpcc-js/comms";
469 var PKG_VERSION = "2.17.0";
470 var BUILD_VERSION = "2.20.0";
471
472 /*! *****************************************************************************
473 Copyright (c) Microsoft Corporation. All rights reserved.
474 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
475 this file except in compliance with the License. You may obtain a copy of the
476 License at http://www.apache.org/licenses/LICENSE-2.0
477
478 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
479 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
480 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
481 MERCHANTABLITY OR NON-INFRINGEMENT.
482
483 See the Apache Version 2.0 License for specific language governing permissions
484 and limitations under the License.
485 ***************************************************************************** */
486 /* global Reflect, Promise */
487
488 var extendStatics = function(d, b) {
489 extendStatics = Object.setPrototypeOf ||
490 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
491 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
492 return extendStatics(d, b);
493 };
494
495 function __extends(d, b) {
496 extendStatics(d, b);
497 function __() { this.constructor = d; }
498 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
499 }
500
501 var __assign = function() {
502 __assign = Object.assign || function __assign(t) {
503 for (var s, i = 1, n = arguments.length; i < n; i++) {
504 s = arguments[i];
505 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
506 }
507 return t;
508 };
509 return __assign.apply(this, arguments);
510 };
511
512 function __awaiter(thisArg, _arguments, P, generator) {
513 return new (P || (P = Promise))(function (resolve, reject) {
514 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
515 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
516 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
517 step((generator = generator.apply(thisArg, _arguments || [])).next());
518 });
519 }
520
521 function __generator(thisArg, body) {
522 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
523 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
524 function verb(n) { return function (v) { return step([n, v]); }; }
525 function step(op) {
526 if (f) throw new TypeError("Generator is already executing.");
527 while (_) try {
528 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
529 if (y = 0, t) op = [op[0] & 2, t.value];
530 switch (op[0]) {
531 case 0: case 1: t = op; break;
532 case 4: _.label++; return { value: op[1], done: false };
533 case 5: _.label++; y = op[1]; op = [0]; continue;
534 case 7: op = _.ops.pop(); _.trys.pop(); continue;
535 default:
536 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
537 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
538 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
539 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
540 if (t[2]) _.ops.pop();
541 _.trys.pop(); continue;
542 }
543 op = body.call(thisArg, _);
544 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
545 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
546 }
547 }
548
549 var logger = util.scopedLogger("comms/connection.ts");
550 function instanceOfIOptions(object) {
551 return "baseUrl" in object;
552 }
553 var DefaultOptions = {
554 type: "post",
555 baseUrl: "",
556 userID: "",
557 password: "",
558 rejectUnauthorized: true,
559 timeoutSecs: 60
560 };
561 function instanceOfIConnection(object) {
562 return typeof object.opts === "function" &&
563 typeof object.send === "function" &&
564 typeof object.clone === "function";
565 }
566 // comms ---
567 function encode(uriComponent, encodeRequest) {
568 return (encodeRequest === undefined || encodeRequest === true) ? encodeURIComponent(uriComponent) : "" + uriComponent;
569 }
570 function serializeRequest(obj, encodeRequest, prefix) {
571 if (encodeRequest === void 0) { encodeRequest = true; }
572 if (prefix === void 0) { prefix = ""; }
573 if (prefix) {
574 prefix += ".";
575 }
576 if (typeof obj !== "object") {
577 return encode(obj, encodeRequest);
578 }
579 var str = [];
580 var _loop_1 = function (key) {
581 if (obj.hasOwnProperty(key)) {
582 if (obj[key] instanceof Array) {
583 // Specific to ESP - but no REST standard exists...
584 var includeItemCount_1 = false;
585 obj[key].forEach(function (row, i) {
586 if (typeof row === "object") {
587 includeItemCount_1 = true;
588 str.push(serializeRequest(row, encodeRequest, prefix + encode(key + "." + i, encodeRequest)));
589 }
590 else {
591 str.push(prefix + encode(key + "_i" + i, encodeRequest) + "=" + serializeRequest(row, encodeRequest));
592 }
593 });
594 if (includeItemCount_1) {
595 str.push(prefix + encode(key + ".itemcount", encodeRequest) + "=" + obj[key].length);
596 }
597 }
598 else if (typeof obj[key] === "object") {
599 if (obj[key] && obj[key]["Item"] instanceof Array) { // Specific to ws_machine.GetTargetClusterInfo?
600 str.push(serializeRequest(obj[key]["Item"], encodeRequest, prefix + encode(key, encodeRequest)));
601 str.push(prefix + encode(key + ".itemcount", encodeRequest) + "=" + obj[key]["Item"].length);
602 }
603 else {
604 str.push(serializeRequest(obj[key], encodeRequest, prefix + encode(key, encodeRequest)));
605 }
606 }
607 else if (obj[key] !== undefined) {
608 str.push(prefix + encode(key, encodeRequest) + "=" + encode(obj[key], encodeRequest));
609 }
610 else {
611 str.push(prefix + encode(key, encodeRequest));
612 }
613 }
614 };
615 for (var key in obj) {
616 _loop_1(key);
617 }
618 return str.join("&");
619 }
620 function deserializeResponse(body) {
621 return JSON.parse(body);
622 }
623 function jsonp(opts, action, request, responseType, header) {
624 if (request === void 0) { request = {}; }
625 if (responseType === void 0) { responseType = "json"; }
626 if (header) {
627 console.warn("Header attributes ignored for JSONP connections");
628 }
629 return new Promise(function (resolve, reject) {
630 var respondedTimeout = opts.timeoutSecs * 1000;
631 var respondedTick = 5000;
632 var callbackName = "jsonp_callback_" + Math.round(Math.random() * 999999);
633 window[callbackName] = function (response) {
634 respondedTimeout = 0;
635 doCallback();
636 resolve(responseType === "json" && typeof response === "string" ? deserializeResponse(response) : response);
637 };
638 var script = document.createElement("script");
639 var url = util.join(opts.baseUrl, action);
640 url += url.indexOf("?") >= 0 ? "&" : "?";
641 script.src = url + "jsonp=" + callbackName + "&" + serializeRequest(request, opts.encodeRequest);
642 document.body.appendChild(script);
643 var progress = setInterval(function () {
644 if (respondedTimeout <= 0) {
645 clearInterval(progress);
646 }
647 else {
648 respondedTimeout -= respondedTick;
649 if (respondedTimeout <= 0) {
650 clearInterval(progress);
651 logger.error("Request timeout: " + script.src);
652 doCallback();
653 reject(Error("Request timeout: " + script.src));
654 }
655 else {
656 logger.debug("Request pending (" + respondedTimeout / 1000 + " sec): " + script.src);
657 }
658 }
659 }, respondedTick);
660 function doCallback() {
661 delete window[callbackName];
662 document.body.removeChild(script);
663 }
664 });
665 }
666 function authHeader(opts) {
667 return opts.userID ? { Authorization: "Basic " + btoa(opts.userID + ":" + opts.password) } : {};
668 }
669 // _omitMap is a workaround for older HPCC-Platform instances without credentials ---
670 var _omitMap = {};
671 function doFetch(opts, action, requestInit, headersInit, responseType) {
672 headersInit = __assign(__assign({}, authHeader(opts)), headersInit);
673 requestInit = __assign(__assign({ credentials: _omitMap[opts.baseUrl] ? "omit" : "include" }, requestInit), { headers: headersInit });
674 if (opts.rejectUnauthorized === false && fetch["__agent"] && opts.baseUrl.indexOf("https:") === 0) {
675 // NodeJS / node-fetch only ---
676 requestInit["agent"] = fetch["__agent"];
677 }
678 function handleResponse(response) {
679 if (response.ok) {
680 return responseType === "json" ? response.json() : response.text();
681 }
682 throw new Error(response.statusText);
683 }
684 return util.promiseTimeout(opts.timeoutSecs * 1000, fetch(util.join(opts.baseUrl, action), requestInit)
685 .then(handleResponse)
686 .catch(function (e) {
687 // Try again with the opposite credentials mode ---
688 requestInit.credentials = !_omitMap[opts.baseUrl] ? "omit" : "include";
689 return fetch(util.join(opts.baseUrl, action), requestInit)
690 .then(handleResponse)
691 .then(function (responseBody) {
692 _omitMap[opts.baseUrl] = !_omitMap[opts.baseUrl]; // The "opposite" credentials mode is known to work ---
693 return responseBody;
694 });
695 }));
696 }
697 function post(opts, action, request, responseType, header) {
698 if (responseType === void 0) { responseType = "json"; }
699 return doFetch(opts, action, {
700 method: "post",
701 body: serializeRequest(request, opts.encodeRequest)
702 }, __assign({ "Content-Type": "application/x-www-form-urlencoded" }, header), responseType);
703 }
704 function get(opts, action, request, responseType, header) {
705 if (responseType === void 0) { responseType = "json"; }
706 return doFetch(opts, action + "?" + serializeRequest(request, opts.encodeRequest), {
707 method: "get"
708 }, __assign({}, header), responseType);
709 }
710 function send(opts, action, request, responseType, header) {
711 if (responseType === void 0) { responseType = "json"; }
712 var retVal;
713 switch (opts.type) {
714 case "jsonp":
715 retVal = jsonp(opts, action, request, responseType, header);
716 break;
717 case "get":
718 retVal = get(opts, action, request, responseType, header);
719 break;
720 case "post":
721 default:
722 retVal = post(opts, action, request, responseType, header);
723 break;
724 }
725 return retVal;
726 }
727 var hookedSend = send;
728 function hookSend(newSend) {
729 var retVal = hookedSend;
730 if (newSend) {
731 hookedSend = newSend;
732 }
733 return retVal;
734 }
735 var Connection = /** @class */ (function () {
736 function Connection(opts) {
737 this.opts(opts);
738 }
739 Object.defineProperty(Connection.prototype, "baseUrl", {
740 get: function () { return this._opts.baseUrl; },
741 enumerable: false,
742 configurable: true
743 });
744 Connection.prototype.opts = function (_) {
745 if (arguments.length === 0)
746 return this._opts;
747 this._opts = __assign(__assign({}, DefaultOptions), _);
748 return this;
749 };
750 Connection.prototype.send = function (action, request, responseType, header) {
751 if (responseType === void 0) { responseType = "json"; }
752 if (this._opts.hookSend) {
753 return this._opts.hookSend(this._opts, action, request, responseType, hookedSend, header);
754 }
755 return hookedSend(this._opts, action, request, responseType, header);
756 };
757 Connection.prototype.clone = function () {
758 return new Connection(this.opts());
759 };
760 return Connection;
761 }());
762 exports.createConnection = function (opts) {
763 return new Connection(opts);
764 };
765 function setTransportFactory(newFunc) {
766 var retVal = exports.createConnection;
767 exports.createConnection = newFunc;
768 return retVal;
769 }
770
771 function isArray(arg) {
772 return Object.prototype.toString.call(arg) === "[object Array]";
773 }
774 var ESPExceptions = /** @class */ (function (_super) {
775 __extends(ESPExceptions, _super);
776 function ESPExceptions(action, request, exceptions) {
777 var _this = _super.call(this, "ESPException: " + exceptions.Source) || this;
778 _this.isESPExceptions = true;
779 _this.action = action;
780 _this.request = request;
781 _this.Source = exceptions.Source;
782 _this.Exception = exceptions.Exception;
783 if (exceptions.Exception.length) {
784 _this.message = exceptions.Exception[0].Code + ": " + exceptions.Exception[0].Message;
785 }
786 return _this;
787 }
788 return ESPExceptions;
789 }(Error));
790 function isConnection(optsConnection) {
791 return optsConnection.send !== undefined;
792 }
793 var ESPConnection = /** @class */ (function () {
794 function ESPConnection(optsConnection, service, version) {
795 this._connection = isConnection(optsConnection) ? optsConnection : exports.createConnection(optsConnection);
796 this._service = service;
797 this._version = version;
798 }
799 Object.defineProperty(ESPConnection.prototype, "baseUrl", {
800 get: function () { return this._connection.opts().baseUrl; },
801 enumerable: false,
802 configurable: true
803 });
804 ESPConnection.prototype.service = function (_) {
805 if (_ === void 0)
806 return this._service;
807 this._service = _;
808 return this;
809 };
810 ESPConnection.prototype.version = function (_) {
811 if (_ === void 0)
812 return this._version;
813 this._version = _;
814 return this;
815 };
816 ESPConnection.prototype.toESPStringArray = function (target, arrayName) {
817 if (isArray(target[arrayName])) {
818 for (var i = 0; i < target[arrayName].length; ++i) {
819 target[arrayName + "_i" + i] = target[arrayName][i];
820 }
821 delete target[arrayName];
822 }
823 return target;
824 };
825 ESPConnection.prototype.opts = function (_) {
826 if (_ === void 0)
827 return this._connection.opts();
828 this._connection.opts(_);
829 return this;
830 };
831 ESPConnection.prototype.send = function (action, _request, espResponseType, largeUpload) {
832 if (_request === void 0) { _request = {}; }
833 if (espResponseType === void 0) { espResponseType = "json"; }
834 if (largeUpload === void 0) { largeUpload = false; }
835 var request = __assign(__assign({}, _request), { ver_: this._version });
836 if (largeUpload) {
837 request["upload_"] = true;
838 }
839 var serviceAction;
840 var responseType = "json";
841 switch (espResponseType) {
842 case "text":
843 serviceAction = util.join(this._service, action);
844 responseType = "text";
845 break;
846 case "xsd":
847 serviceAction = util.join(this._service, action + ".xsd");
848 responseType = "text";
849 break;
850 case "json2":
851 serviceAction = util.join(this._service, action + "/json");
852 espResponseType = "json";
853 var actionParts = action.split("/");
854 action = actionParts.pop();
855 break;
856 default:
857 serviceAction = util.join(this._service, action + ".json");
858 }
859 return this._connection.send(serviceAction, request, responseType).then(function (response) {
860 if (espResponseType === "json") {
861 var retVal = void 0;
862 if (response && response.Exceptions) {
863 throw new ESPExceptions(action, request, response.Exceptions);
864 }
865 else if (response) {
866 retVal = response[(action === "WUCDebug" ? "WUDebug" : action) + "Response"];
867 }
868 if (!retVal) {
869 throw new ESPExceptions(action, request, {
870 Source: "ESPConnection.send",
871 Exception: [{ Code: 0, Message: "Missing Response" }]
872 });
873 }
874 return retVal;
875 }
876 return response;
877 }).catch(function (e) {
878 if (e.isESPExceptions) {
879 throw e;
880 }
881 throw new ESPExceptions(action, request, {
882 Source: "ESPConnection.send",
883 Exception: [{ Code: 0, Message: e.message }]
884 });
885 });
886 };
887 ESPConnection.prototype.clone = function () {
888 return new ESPConnection(this._connection.clone(), this._service, this._version);
889 };
890 return ESPConnection;
891 }());
892 var Service = /** @class */ (function () {
893 function Service(optsConnection, service, version) {
894 this._connection = new ESPConnection(optsConnection, service, version);
895 }
896 Object.defineProperty(Service.prototype, "baseUrl", {
897 get: function () { return this._connection.opts().baseUrl; },
898 enumerable: false,
899 configurable: true
900 });
901 return Service;
902 }());
903
904 var AccountService = /** @class */ (function () {
905 function AccountService(optsConnection) {
906 this._connection = new ESPConnection(optsConnection, "Ws_Account", "1.03");
907 }
908 AccountService.prototype.connectionOptions = function () {
909 return this._connection.opts();
910 };
911 AccountService.prototype.VerifyUser = function (request) {
912 return this._connection.send("VerifyUser", request);
913 };
914 return AccountService;
915 }());
916
917 var DFUService = /** @class */ (function (_super) {
918 __extends(DFUService, _super);
919 function DFUService(optsConnection) {
920 return _super.call(this, optsConnection, "WsDfu", "1.5") || this;
921 }
922 DFUService.prototype.DFUQuery = function (request) {
923 return this._connection.send("DFUQuery", request);
924 };
925 DFUService.prototype.DFUInfo = function (request) {
926 return this._connection.send("DFUInfo", request);
927 };
928 return DFUService;
929 }(Service));
930
931 function jsonToIField(id, item) {
932 var type = typeof item;
933 switch (type) {
934 case "boolean":
935 case "number":
936 case "string":
937 return { id: id, type: type };
938 case "object":
939 if (item.Row instanceof Array) {
940 item = item.Row;
941 }
942 if (item instanceof Array) {
943 return {
944 id: id,
945 type: "dataset",
946 children: jsonToIFieldArr(item[0])
947 };
948 }
949 else if (item instanceof Object) {
950 if (item.Item && item.Item instanceof Array && item.Item.length === 1) {
951 var fieldType = typeof item.Item[0];
952 if (fieldType === "string" || fieldType === "number") {
953 return {
954 id: id,
955 type: "set",
956 fieldType: fieldType
957 };
958 }
959 throw new Error("Unknown field type");
960 }
961 return {
962 id: id,
963 type: "object",
964 fields: jsonToIFieldObj(item)
965 };
966 }
967 // Fall through ---
968 default:
969 throw new Error("Unknown field type");
970 }
971 }
972 function jsonToIFieldArr(json) {
973 if (json.Row && json.Row instanceof Array) {
974 json = json.Row[0];
975 }
976 var retVal = [];
977 for (var key in json) {
978 retVal.push(jsonToIField(key, json[key]));
979 }
980 return retVal;
981 }
982 function jsonToIFieldObj(json) {
983 var fields = {};
984 for (var key in json) {
985 fields[key] = jsonToIField(key, json[key]);
986 }
987 return fields;
988 }
989 var EclService = /** @class */ (function (_super) {
990 __extends(EclService, _super);
991 function EclService(optsConnection) {
992 return _super.call(this, optsConnection, "WsEcl", "0") || this;
993 }
994 EclService.prototype.opts = function () {
995 return this._connection.opts();
996 };
997 EclService.prototype.requestJson = function (querySet, queryId) {
998 // http://192.168.3.22:8002/WsEcl/example/request/query/roxie/peopleaccounts/json?display
999 return this._connection.send("example/request/query/" + querySet + "/" + queryId + "/json", {}, "text").then(function (response) {
1000 var requestSchema = JSON.parse(response);
1001 for (var key in requestSchema) {
1002 return requestSchema[key];
1003 }
1004 return {};
1005 }).then(jsonToIFieldArr);
1006 };
1007 EclService.prototype.responseJson = function (querySet, queryId) {
1008 // http://192.168.3.22:8002/WsEcl/example/response/query/roxie/peopleaccounts/json?display
1009 return this._connection.send("example/response/query/" + querySet + "/" + queryId + "/json", {}, "text").then(function (response) {
1010 var responseSchema = JSON.parse(response);
1011 for (var key in responseSchema) {
1012 return responseSchema[key].Results;
1013 }
1014 return {};
1015 }).then(function (resultsJson) {
1016 var retVal = {};
1017 for (var key in resultsJson) {
1018 retVal[key] = jsonToIFieldArr(resultsJson[key]);
1019 }
1020 return retVal;
1021 });
1022 };
1023 EclService.prototype.submit = function (querySet, queryId, request) {
1024 // http://192.168.3.22:8002/WsEcl/submit/query/roxie/peopleaccounts.1/json
1025 var action = "submit/query/" + querySet + "/" + queryId;
1026 return this._connection.send(action, request, "json2").then(function (response) {
1027 if (response.Results && response.Results.Exception) {
1028 throw new ESPExceptions(action, request, {
1029 Source: "wsEcl.submit",
1030 Exception: response.Results.Exception
1031 });
1032 }
1033 return response.Results;
1034 });
1035 };
1036 return EclService;
1037 }(Service));
1038
1039 function ascending(a, b) {
1040 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1041 }
1042
1043 function bisector(compare) {
1044 if (compare.length === 1) compare = ascendingComparator(compare);
1045 return {
1046 left: function(a, x, lo, hi) {
1047 if (lo == null) lo = 0;
1048 if (hi == null) hi = a.length;
1049 while (lo < hi) {
1050 var mid = lo + hi >>> 1;
1051 if (compare(a[mid], x) < 0) lo = mid + 1;
1052 else hi = mid;
1053 }
1054 return lo;
1055 },
1056 right: function(a, x, lo, hi) {
1057 if (lo == null) lo = 0;
1058 if (hi == null) hi = a.length;
1059 while (lo < hi) {
1060 var mid = lo + hi >>> 1;
1061 if (compare(a[mid], x) > 0) hi = mid;
1062 else lo = mid + 1;
1063 }
1064 return lo;
1065 }
1066 };
1067 }
1068
1069 function ascendingComparator(f) {
1070 return function(d, x) {
1071 return ascending(f(d), x);
1072 };
1073 }
1074
1075 var ascendingBisect = bisector(ascending);
1076
1077 function number(x) {
1078 return x === null ? NaN : +x;
1079 }
1080
1081 function d3Max(values, valueof) {
1082 var n = values.length,
1083 i = -1,
1084 value,
1085 max;
1086
1087 if (valueof == null) {
1088 while (++i < n) { // Find the first comparable value.
1089 if ((value = values[i]) != null && value >= value) {
1090 max = value;
1091 while (++i < n) { // Compare the remaining values.
1092 if ((value = values[i]) != null && value > max) {
1093 max = value;
1094 }
1095 }
1096 }
1097 }
1098 }
1099
1100 else {
1101 while (++i < n) { // Find the first comparable value.
1102 if ((value = valueof(values[i], i, values)) != null && value >= value) {
1103 max = value;
1104 while (++i < n) { // Compare the remaining values.
1105 if ((value = valueof(values[i], i, values)) != null && value > max) {
1106 max = value;
1107 }
1108 }
1109 }
1110 }
1111 }
1112
1113 return max;
1114 }
1115
1116 function d3Mean(values, valueof) {
1117 var n = values.length,
1118 m = n,
1119 i = -1,
1120 value,
1121 sum = 0;
1122
1123 if (valueof == null) {
1124 while (++i < n) {
1125 if (!isNaN(value = number(values[i]))) sum += value;
1126 else --m;
1127 }
1128 }
1129
1130 else {
1131 while (++i < n) {
1132 if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
1133 else --m;
1134 }
1135 }
1136
1137 if (m) return sum / m;
1138 }
1139
1140 var MachineService = /** @class */ (function () {
1141 function MachineService(optsConnection) {
1142 this._connection = new ESPConnection(optsConnection, "ws_machine", "1.13");
1143 }
1144 MachineService.prototype.GetTargetClusterInfo = function (request) {
1145 if (request === void 0) { request = {}; }
1146 return this._connection.send("GetTargetClusterInfo", request);
1147 };
1148 MachineService.prototype.GetTargetClusterUsage = function (targetClusters, bypassCachedResult) {
1149 if (bypassCachedResult === void 0) { bypassCachedResult = false; }
1150 return this._connection.send("GetTargetClusterUsage", {
1151 TargetClusters: targetClusters ? { Item: targetClusters } : {},
1152 BypassCachedResult: bypassCachedResult
1153 }).then(function (response) {
1154 return util.exists("TargetClusterUsages.TargetClusterUsage", response) ? response.TargetClusterUsages.TargetClusterUsage : [];
1155 });
1156 };
1157 MachineService.prototype.GetTargetClusterUsageEx = function (targetClusters, bypassCachedResult) {
1158 if (bypassCachedResult === void 0) { bypassCachedResult = false; }
1159 return this.GetTargetClusterUsage(targetClusters, bypassCachedResult).then(function (response) {
1160 return response.filter(function (tcu) { return !!tcu.ComponentUsages; }).map(function (tcu) {
1161 var ComponentUsages = tcu.ComponentUsages.ComponentUsage.map(function (cu) {
1162 var MachineUsages = (cu.MachineUsages && cu.MachineUsages.MachineUsage ? cu.MachineUsages.MachineUsage : []).map(function (mu) {
1163 var DiskUsages = mu.DiskUsages && mu.DiskUsages.DiskUsage ? mu.DiskUsages.DiskUsage.map(function (du) {
1164 return __assign(__assign({}, du), { Total: du.InUse + du.Available, PercentUsed: 100 - du.PercentAvailable });
1165 }) : [];
1166 return {
1167 Name: mu.Name,
1168 NetAddress: mu.NetAddress,
1169 Description: mu.Description,
1170 DiskUsages: DiskUsages,
1171 mean: d3Mean(DiskUsages.filter(function (du) { return !isNaN(du.PercentUsed); }), function (du) { return du.PercentUsed; }),
1172 max: d3Max(DiskUsages.filter(function (du) { return !isNaN(du.PercentUsed); }), function (du) { return du.PercentUsed; })
1173 };
1174 });
1175 return {
1176 Type: cu.Type,
1177 Name: cu.Name,
1178 Description: cu.Description,
1179 MachineUsages: MachineUsages,
1180 MachineUsagesDescription: MachineUsages.reduce(function (prev, mu) { return prev + (mu.Description || ""); }, ""),
1181 mean: d3Mean(MachineUsages.filter(function (mu) { return !isNaN(mu.mean); }), function (mu) { return mu.mean; }),
1182 max: d3Max(MachineUsages.filter(function (mu) { return !isNaN(mu.max); }), function (mu) { return mu.max; })
1183 };
1184 });
1185 return {
1186 Name: tcu.Name,
1187 Description: tcu.Description,
1188 ComponentUsages: ComponentUsages,
1189 ComponentUsagesDescription: ComponentUsages.reduce(function (prev, cu) { return prev + (cu.MachineUsagesDescription || ""); }, ""),
1190 mean: d3Mean(ComponentUsages.filter(function (cu) { return !isNaN(cu.mean); }), function (cu) { return cu.mean; }),
1191 max: d3Max(ComponentUsages.filter(function (cu) { return !isNaN(cu.max); }), function (cu) { return cu.max; })
1192 };
1193 });
1194 });
1195 };
1196 return MachineService;
1197 }());
1198
1199 var SMCService = /** @class */ (function () {
1200 function SMCService(optsConnection) {
1201 this._connection = new ESPConnection(optsConnection, "WsSMC", "1.19");
1202 }
1203 SMCService.prototype.connectionOptions = function () {
1204 return this._connection.opts();
1205 };
1206 SMCService.prototype.Activity = function (request) {
1207 return this._connection.send("Activity", request).then(function (response) {
1208 return __assign({ Running: {
1209 ActiveWorkunit: []
1210 } }, response);
1211 });
1212 };
1213 return SMCService;
1214 }());
1215
1216 var StoreService = /** @class */ (function (_super) {
1217 __extends(StoreService, _super);
1218 function StoreService(optsConnection) {
1219 return _super.call(this, optsConnection, "WsStore", "1") || this;
1220 }
1221 StoreService.prototype.CreateStore = function (request) {
1222 return this._connection.send("Fetch", request);
1223 };
1224 StoreService.prototype.Delete = function (request) {
1225 return this._connection.send("Delete", request).catch(function (e) {
1226 if (e.isESPExceptions && e.Exception.some(function (e) { return e.Code === -1; })) {
1227 // "Delete" item does not exist ---
1228 return {
1229 Exceptions: undefined,
1230 Success: true
1231 };
1232 }
1233 throw e;
1234 });
1235 };
1236 StoreService.prototype.DeleteNamespace = function (request) {
1237 return this._connection.send("DeleteNamespace", request);
1238 };
1239 StoreService.prototype.Fetch = function (request) {
1240 return this._connection.send("Fetch", request).catch(function (e) {
1241 if (e.isESPExceptions && e.Exception.some(function (e) { return e.Code === -1; })) {
1242 // "Fetch" item does not exist ---
1243 return {
1244 Exceptions: undefined,
1245 Value: undefined
1246 };
1247 }
1248 throw e;
1249 });
1250 };
1251 StoreService.prototype.FetchAll = function (request) {
1252 return this._connection.send("FetchAll", request);
1253 };
1254 StoreService.prototype.FetchKeyMD = function (request) {
1255 return this._connection.send("FetchKeyMD", request);
1256 };
1257 StoreService.prototype.ListKeys = function (request) {
1258 return this._connection.send("ListKeys", request);
1259 };
1260 StoreService.prototype.ListNamespaces = function (request) {
1261 return this._connection.send("ListNamespaces", request);
1262 };
1263 StoreService.prototype.Set = function (request) {
1264 return this._connection.send("Set", request);
1265 };
1266 return StoreService;
1267 }(Service));
1268
1269 var TopologyService = /** @class */ (function (_super) {
1270 __extends(TopologyService, _super);
1271 function TopologyService(optsConnection) {
1272 return _super.call(this, optsConnection, "WsTopology", "1.25") || this;
1273 }
1274 TopologyService.prototype.connectionOptions = function () {
1275 return this._connection.opts();
1276 };
1277 TopologyService.prototype.protocol = function () {
1278 var parts = this._connection.opts().baseUrl.split("//");
1279 return parts[0];
1280 };
1281 TopologyService.prototype.ip = function () {
1282 var parts = this._connection.opts().baseUrl.split("//");
1283 var parts2 = parts[1].split(":");
1284 return parts2[0];
1285 };
1286 TopologyService.prototype.TpLogicalClusterQuery = function (request) {
1287 if (request === void 0) { request = {}; }
1288 return this._connection.send("TpLogicalClusterQuery", request);
1289 };
1290 TopologyService.prototype.DefaultTpLogicalClusterQuery = function (request) {
1291 if (request === void 0) { request = {}; }
1292 return this.TpLogicalClusterQuery(request).then(function (response) {
1293 if (response.default) {
1294 return response.default;
1295 }
1296 var firstHThor;
1297 var first;
1298 response.TpLogicalClusters.TpLogicalCluster.some(function (item, idx) {
1299 if (idx === 0) {
1300 first = item;
1301 }
1302 if (item.Type === "hthor") {
1303 firstHThor = item;
1304 return true;
1305 }
1306 return false;
1307 });
1308 return firstHThor || first;
1309 });
1310 };
1311 TopologyService.prototype.TpServiceQuery = function (request) {
1312 return this._connection.send("TpServiceQuery", request);
1313 };
1314 TopologyService.prototype.TpTargetClusterQuery = function (request) {
1315 return this._connection.send("TpTargetClusterQuery", request);
1316 };
1317 TopologyService.prototype.TpListTargetClusters = function (request) {
1318 return this._connection.send("TpListTargetClusters", request);
1319 };
1320 return TopologyService;
1321 }(Service));
1322
1323 (function (WUStateID) {
1324 WUStateID[WUStateID["Unknown"] = 0] = "Unknown";
1325 WUStateID[WUStateID["Compiled"] = 1] = "Compiled";
1326 WUStateID[WUStateID["Running"] = 2] = "Running";
1327 WUStateID[WUStateID["Completed"] = 3] = "Completed";
1328 WUStateID[WUStateID["Failed"] = 4] = "Failed";
1329 WUStateID[WUStateID["Archived"] = 5] = "Archived";
1330 WUStateID[WUStateID["Aborting"] = 6] = "Aborting";
1331 WUStateID[WUStateID["Aborted"] = 7] = "Aborted";
1332 WUStateID[WUStateID["Blocked"] = 8] = "Blocked";
1333 WUStateID[WUStateID["Submitted"] = 9] = "Submitted";
1334 WUStateID[WUStateID["Scheduled"] = 10] = "Scheduled";
1335 WUStateID[WUStateID["Compiling"] = 11] = "Compiling";
1336 WUStateID[WUStateID["Wait"] = 12] = "Wait";
1337 WUStateID[WUStateID["UploadingFiled"] = 13] = "UploadingFiled";
1338 WUStateID[WUStateID["DebugPaused"] = 14] = "DebugPaused";
1339 WUStateID[WUStateID["DebugRunning"] = 15] = "DebugRunning";
1340 WUStateID[WUStateID["Paused"] = 16] = "Paused";
1341 WUStateID[WUStateID["LAST"] = 17] = "LAST";
1342 WUStateID[WUStateID["NotFound"] = 999] = "NotFound";
1343 })(exports.WUStateID || (exports.WUStateID = {}));
1344 (function (WUUpdate) {
1345 var Action;
1346 (function (Action) {
1347 Action[Action["Unknown"] = 0] = "Unknown";
1348 Action[Action["Compile"] = 1] = "Compile";
1349 Action[Action["Check"] = 2] = "Check";
1350 Action[Action["Run"] = 3] = "Run";
1351 Action[Action["ExecuteExisting"] = 4] = "ExecuteExisting";
1352 Action[Action["Pause"] = 5] = "Pause";
1353 Action[Action["PauseNow"] = 6] = "PauseNow";
1354 Action[Action["Resume"] = 7] = "Resume";
1355 Action[Action["Debug"] = 8] = "Debug";
1356 Action[Action["__size"] = 9] = "__size";
1357 })(Action = WUUpdate.Action || (WUUpdate.Action = {}));
1358 })(exports.WUUpdate || (exports.WUUpdate = {}));
1359 function isWUQueryECLWorkunit(_) {
1360 return _.TotalClusterTime !== undefined;
1361 }
1362 function isWUInfoWorkunit(_) {
1363 return _.StateEx !== undefined;
1364 }
1365 var WorkunitsService = /** @class */ (function (_super) {
1366 __extends(WorkunitsService, _super);
1367 function WorkunitsService(optsConnection) {
1368 return _super.call(this, optsConnection, "WsWorkunits", "1.68") || this;
1369 }
1370 WorkunitsService.prototype.opts = function () {
1371 return this._connection.opts();
1372 };
1373 WorkunitsService.prototype.connection = function () {
1374 return this._connection;
1375 };
1376 WorkunitsService.prototype.WUQuery = function (request) {
1377 if (request === void 0) { request = {}; }
1378 return this._connection.send("WUQuery", request).then(function (response) {
1379 return util.deepMixin({ Workunits: { ECLWorkunit: [] } }, response);
1380 });
1381 };
1382 WorkunitsService.prototype.WUInfo = function (_request) {
1383 var request = __assign({ Wuid: "", TruncateEclTo64k: true, IncludeExceptions: false, IncludeGraphs: false, IncludeSourceFiles: false, IncludeResults: false, IncludeResultsViewNames: false, IncludeVariables: false, IncludeTimers: false, IncludeDebugValues: false, IncludeApplicationValues: false, IncludeWorkflows: false, IncludeXmlSchemas: false, IncludeResourceURLs: false, SuppressResultSchemas: true }, _request);
1384 return this._connection.send("WUInfo", request);
1385 };
1386 WorkunitsService.prototype.WUCreate = function () {
1387 return this._connection.send("WUCreate");
1388 };
1389 WorkunitsService.prototype.WUUpdate = function (request) {
1390 return this._connection.send("WUUpdate", request, "json", true);
1391 };
1392 WorkunitsService.prototype.WUSubmit = function (request) {
1393 return this._connection.send("WUSubmit", request);
1394 };
1395 WorkunitsService.prototype.WUResubmit = function (request) {
1396 this._connection.toESPStringArray(request, "Wuids");
1397 return this._connection.send("WUResubmit", request);
1398 };
1399 WorkunitsService.prototype.WUQueryDetails = function (request) {
1400 return this._connection.send("WUQueryDetails", request);
1401 };
1402 WorkunitsService.prototype.WUListQueries = function (request) {
1403 return this._connection.send("WUListQueries", request);
1404 };
1405 WorkunitsService.prototype.WUPushEvent = function (request) {
1406 return this._connection.send("WUPushEvent", request);
1407 };
1408 WorkunitsService.prototype.WUAction = function (request) {
1409 request.ActionType = request.WUActionType; // v5.x compatibility
1410 return this._connection.send("WUAction", request);
1411 };
1412 WorkunitsService.prototype.WUGetZAPInfo = function (request) {
1413 return this._connection.send("WUGetZAPInfo", request);
1414 };
1415 WorkunitsService.prototype.WUShowScheduled = function (request) {
1416 return this._connection.send("WUShowScheduled", request);
1417 };
1418 WorkunitsService.prototype.WUQuerySetAliasAction = function (request) {
1419 return this._connection.send("WUQuerySetAliasAction", request);
1420 };
1421 WorkunitsService.prototype.WUQuerySetQueryAction = function (request) {
1422 return this._connection.send("WUQuerySetQueryAction", request);
1423 };
1424 WorkunitsService.prototype.WUPublishWorkunit = function (request) {
1425 return this._connection.send("WUPublishWorkunit", request);
1426 };
1427 WorkunitsService.prototype.WUGetGraph = function (request) {
1428 return this._connection.send("WUGetGraph", request);
1429 };
1430 WorkunitsService.prototype.WUResult = function (request) {
1431 return this._connection.send("WUResult", request);
1432 };
1433 WorkunitsService.prototype.WUQueryGetGraph = function (request) {
1434 return this._connection.send("WUQueryGetGraph", request);
1435 };
1436 WorkunitsService.prototype.WUFile = function (request) {
1437 return this._connection.send("WUFile", request, "text");
1438 };
1439 WorkunitsService.prototype.WUGetStats = function (request) {
1440 return this._connection.send("WUGetStats", request);
1441 };
1442 WorkunitsService.prototype.WUDetailsMeta = function (request) {
1443 if (!this._WUDetailsMetaPromise) {
1444 this._WUDetailsMetaPromise = this._connection.send("WUDetailsMeta", request);
1445 }
1446 return this._WUDetailsMetaPromise;
1447 };
1448 WorkunitsService.prototype.WUDetails = function (request) {
1449 return this._connection.send("WUDetails", request);
1450 };
1451 WorkunitsService.prototype.WUCDebug = function (request) {
1452 return this._connection.send("WUCDebug", request).then(function (response) {
1453 var retVal = util.xml2json(response.Result);
1454 var children = retVal.children();
1455 if (children.length) {
1456 return children[0];
1457 }
1458 return null;
1459 });
1460 };
1461 return WorkunitsService;
1462 }(Service));
1463
1464 var t0 = new Date,
1465 t1 = new Date;
1466
1467 function newInterval(floori, offseti, count, field) {
1468
1469 function interval(date) {
1470 return floori(date = new Date(+date)), date;
1471 }
1472
1473 interval.floor = interval;
1474
1475 interval.ceil = function(date) {
1476 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
1477 };
1478
1479 interval.round = function(date) {
1480 var d0 = interval(date),
1481 d1 = interval.ceil(date);
1482 return date - d0 < d1 - date ? d0 : d1;
1483 };
1484
1485 interval.offset = function(date, step) {
1486 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
1487 };
1488
1489 interval.range = function(start, stop, step) {
1490 var range = [];
1491 start = interval.ceil(start);
1492 step = step == null ? 1 : Math.floor(step);
1493 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
1494 do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
1495 return range;
1496 };
1497
1498 interval.filter = function(test) {
1499 return newInterval(function(date) {
1500 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
1501 }, function(date, step) {
1502 if (date >= date) while (--step >= 0) while (offseti(date, 1), !test(date)) {} // eslint-disable-line no-empty
1503 });
1504 };
1505
1506 if (count) {
1507 interval.count = function(start, end) {
1508 t0.setTime(+start), t1.setTime(+end);
1509 floori(t0), floori(t1);
1510 return Math.floor(count(t0, t1));
1511 };
1512
1513 interval.every = function(step) {
1514 step = Math.floor(step);
1515 return !isFinite(step) || !(step > 0) ? null
1516 : !(step > 1) ? interval
1517 : interval.filter(field
1518 ? function(d) { return field(d) % step === 0; }
1519 : function(d) { return interval.count(0, d) % step === 0; });
1520 };
1521 }
1522
1523 return interval;
1524 }
1525
1526 var millisecond = newInterval(function() {
1527 // noop
1528 }, function(date, step) {
1529 date.setTime(+date + step);
1530 }, function(start, end) {
1531 return end - start;
1532 });
1533
1534 // An optimized implementation for this simple case.
1535 millisecond.every = function(k) {
1536 k = Math.floor(k);
1537 if (!isFinite(k) || !(k > 0)) return null;
1538 if (!(k > 1)) return millisecond;
1539 return newInterval(function(date) {
1540 date.setTime(Math.floor(date / k) * k);
1541 }, function(date, step) {
1542 date.setTime(+date + step * k);
1543 }, function(start, end) {
1544 return (end - start) / k;
1545 });
1546 };
1547
1548 var durationSecond = 1e3;
1549 var durationMinute = 6e4;
1550 var durationHour = 36e5;
1551 var durationDay = 864e5;
1552 var durationWeek = 6048e5;
1553
1554 var second = newInterval(function(date) {
1555 date.setTime(Math.floor(date / durationSecond) * durationSecond);
1556 }, function(date, step) {
1557 date.setTime(+date + step * durationSecond);
1558 }, function(start, end) {
1559 return (end - start) / durationSecond;
1560 }, function(date) {
1561 return date.getUTCSeconds();
1562 });
1563
1564 var minute = newInterval(function(date) {
1565 date.setTime(Math.floor(date / durationMinute) * durationMinute);
1566 }, function(date, step) {
1567 date.setTime(+date + step * durationMinute);
1568 }, function(start, end) {
1569 return (end - start) / durationMinute;
1570 }, function(date) {
1571 return date.getMinutes();
1572 });
1573
1574 var hour = newInterval(function(date) {
1575 var offset = date.getTimezoneOffset() * durationMinute % durationHour;
1576 if (offset < 0) offset += durationHour;
1577 date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
1578 }, function(date, step) {
1579 date.setTime(+date + step * durationHour);
1580 }, function(start, end) {
1581 return (end - start) / durationHour;
1582 }, function(date) {
1583 return date.getHours();
1584 });
1585
1586 var day = newInterval(function(date) {
1587 date.setHours(0, 0, 0, 0);
1588 }, function(date, step) {
1589 date.setDate(date.getDate() + step);
1590 }, function(start, end) {
1591 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
1592 }, function(date) {
1593 return date.getDate() - 1;
1594 });
1595
1596 function weekday(i) {
1597 return newInterval(function(date) {
1598 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
1599 date.setHours(0, 0, 0, 0);
1600 }, function(date, step) {
1601 date.setDate(date.getDate() + step * 7);
1602 }, function(start, end) {
1603 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
1604 });
1605 }
1606
1607 var sunday = weekday(0);
1608 var monday = weekday(1);
1609 var tuesday = weekday(2);
1610 var wednesday = weekday(3);
1611 var thursday = weekday(4);
1612 var friday = weekday(5);
1613 var saturday = weekday(6);
1614
1615 var month = newInterval(function(date) {
1616 date.setDate(1);
1617 date.setHours(0, 0, 0, 0);
1618 }, function(date, step) {
1619 date.setMonth(date.getMonth() + step);
1620 }, function(start, end) {
1621 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
1622 }, function(date) {
1623 return date.getMonth();
1624 });
1625
1626 var year = newInterval(function(date) {
1627 date.setMonth(0, 1);
1628 date.setHours(0, 0, 0, 0);
1629 }, function(date, step) {
1630 date.setFullYear(date.getFullYear() + step);
1631 }, function(start, end) {
1632 return end.getFullYear() - start.getFullYear();
1633 }, function(date) {
1634 return date.getFullYear();
1635 });
1636
1637 // An optimized implementation for this simple case.
1638 year.every = function(k) {
1639 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
1640 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
1641 date.setMonth(0, 1);
1642 date.setHours(0, 0, 0, 0);
1643 }, function(date, step) {
1644 date.setFullYear(date.getFullYear() + step * k);
1645 });
1646 };
1647
1648 var utcMinute = newInterval(function(date) {
1649 date.setUTCSeconds(0, 0);
1650 }, function(date, step) {
1651 date.setTime(+date + step * durationMinute);
1652 }, function(start, end) {
1653 return (end - start) / durationMinute;
1654 }, function(date) {
1655 return date.getUTCMinutes();
1656 });
1657
1658 var utcHour = newInterval(function(date) {
1659 date.setUTCMinutes(0, 0, 0);
1660 }, function(date, step) {
1661 date.setTime(+date + step * durationHour);
1662 }, function(start, end) {
1663 return (end - start) / durationHour;
1664 }, function(date) {
1665 return date.getUTCHours();
1666 });
1667
1668 var utcDay = newInterval(function(date) {
1669 date.setUTCHours(0, 0, 0, 0);
1670 }, function(date, step) {
1671 date.setUTCDate(date.getUTCDate() + step);
1672 }, function(start, end) {
1673 return (end - start) / durationDay;
1674 }, function(date) {
1675 return date.getUTCDate() - 1;
1676 });
1677
1678 function utcWeekday(i) {
1679 return newInterval(function(date) {
1680 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
1681 date.setUTCHours(0, 0, 0, 0);
1682 }, function(date, step) {
1683 date.setUTCDate(date.getUTCDate() + step * 7);
1684 }, function(start, end) {
1685 return (end - start) / durationWeek;
1686 });
1687 }
1688
1689 var utcSunday = utcWeekday(0);
1690 var utcMonday = utcWeekday(1);
1691 var utcTuesday = utcWeekday(2);
1692 var utcWednesday = utcWeekday(3);
1693 var utcThursday = utcWeekday(4);
1694 var utcFriday = utcWeekday(5);
1695 var utcSaturday = utcWeekday(6);
1696
1697 var utcMonth = newInterval(function(date) {
1698 date.setUTCDate(1);
1699 date.setUTCHours(0, 0, 0, 0);
1700 }, function(date, step) {
1701 date.setUTCMonth(date.getUTCMonth() + step);
1702 }, function(start, end) {
1703 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
1704 }, function(date) {
1705 return date.getUTCMonth();
1706 });
1707
1708 var utcYear = newInterval(function(date) {
1709 date.setUTCMonth(0, 1);
1710 date.setUTCHours(0, 0, 0, 0);
1711 }, function(date, step) {
1712 date.setUTCFullYear(date.getUTCFullYear() + step);
1713 }, function(start, end) {
1714 return end.getUTCFullYear() - start.getUTCFullYear();
1715 }, function(date) {
1716 return date.getUTCFullYear();
1717 });
1718
1719 // An optimized implementation for this simple case.
1720 utcYear.every = function(k) {
1721 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
1722 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
1723 date.setUTCMonth(0, 1);
1724 date.setUTCHours(0, 0, 0, 0);
1725 }, function(date, step) {
1726 date.setUTCFullYear(date.getUTCFullYear() + step * k);
1727 });
1728 };
1729
1730 function localDate(d) {
1731 if (0 <= d.y && d.y < 100) {
1732 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
1733 date.setFullYear(d.y);
1734 return date;
1735 }
1736 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
1737 }
1738
1739 function utcDate(d) {
1740 if (0 <= d.y && d.y < 100) {
1741 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
1742 date.setUTCFullYear(d.y);
1743 return date;
1744 }
1745 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
1746 }
1747
1748 function newYear(y) {
1749 return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
1750 }
1751
1752 function formatLocale(locale) {
1753 var locale_dateTime = locale.dateTime,
1754 locale_date = locale.date,
1755 locale_time = locale.time,
1756 locale_periods = locale.periods,
1757 locale_weekdays = locale.days,
1758 locale_shortWeekdays = locale.shortDays,
1759 locale_months = locale.months,
1760 locale_shortMonths = locale.shortMonths;
1761
1762 var periodRe = formatRe(locale_periods),
1763 periodLookup = formatLookup(locale_periods),
1764 weekdayRe = formatRe(locale_weekdays),
1765 weekdayLookup = formatLookup(locale_weekdays),
1766 shortWeekdayRe = formatRe(locale_shortWeekdays),
1767 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
1768 monthRe = formatRe(locale_months),
1769 monthLookup = formatLookup(locale_months),
1770 shortMonthRe = formatRe(locale_shortMonths),
1771 shortMonthLookup = formatLookup(locale_shortMonths);
1772
1773 var formats = {
1774 "a": formatShortWeekday,
1775 "A": formatWeekday,
1776 "b": formatShortMonth,
1777 "B": formatMonth,
1778 "c": null,
1779 "d": formatDayOfMonth,
1780 "e": formatDayOfMonth,
1781 "f": formatMicroseconds,
1782 "H": formatHour24,
1783 "I": formatHour12,
1784 "j": formatDayOfYear,
1785 "L": formatMilliseconds,
1786 "m": formatMonthNumber,
1787 "M": formatMinutes,
1788 "p": formatPeriod,
1789 "Q": formatUnixTimestamp,
1790 "s": formatUnixTimestampSeconds,
1791 "S": formatSeconds,
1792 "u": formatWeekdayNumberMonday,
1793 "U": formatWeekNumberSunday,
1794 "V": formatWeekNumberISO,
1795 "w": formatWeekdayNumberSunday,
1796 "W": formatWeekNumberMonday,
1797 "x": null,
1798 "X": null,
1799 "y": formatYear,
1800 "Y": formatFullYear,
1801 "Z": formatZone,
1802 "%": formatLiteralPercent
1803 };
1804
1805 var utcFormats = {
1806 "a": formatUTCShortWeekday,
1807 "A": formatUTCWeekday,
1808 "b": formatUTCShortMonth,
1809 "B": formatUTCMonth,
1810 "c": null,
1811 "d": formatUTCDayOfMonth,
1812 "e": formatUTCDayOfMonth,
1813 "f": formatUTCMicroseconds,
1814 "H": formatUTCHour24,
1815 "I": formatUTCHour12,
1816 "j": formatUTCDayOfYear,
1817 "L": formatUTCMilliseconds,
1818 "m": formatUTCMonthNumber,
1819 "M": formatUTCMinutes,
1820 "p": formatUTCPeriod,
1821 "Q": formatUnixTimestamp,
1822 "s": formatUnixTimestampSeconds,
1823 "S": formatUTCSeconds,
1824 "u": formatUTCWeekdayNumberMonday,
1825 "U": formatUTCWeekNumberSunday,
1826 "V": formatUTCWeekNumberISO,
1827 "w": formatUTCWeekdayNumberSunday,
1828 "W": formatUTCWeekNumberMonday,
1829 "x": null,
1830 "X": null,
1831 "y": formatUTCYear,
1832 "Y": formatUTCFullYear,
1833 "Z": formatUTCZone,
1834 "%": formatLiteralPercent
1835 };
1836
1837 var parses = {
1838 "a": parseShortWeekday,
1839 "A": parseWeekday,
1840 "b": parseShortMonth,
1841 "B": parseMonth,
1842 "c": parseLocaleDateTime,
1843 "d": parseDayOfMonth,
1844 "e": parseDayOfMonth,
1845 "f": parseMicroseconds,
1846 "H": parseHour24,
1847 "I": parseHour24,
1848 "j": parseDayOfYear,
1849 "L": parseMilliseconds,
1850 "m": parseMonthNumber,
1851 "M": parseMinutes,
1852 "p": parsePeriod,
1853 "Q": parseUnixTimestamp,
1854 "s": parseUnixTimestampSeconds,
1855 "S": parseSeconds,
1856 "u": parseWeekdayNumberMonday,
1857 "U": parseWeekNumberSunday,
1858 "V": parseWeekNumberISO,
1859 "w": parseWeekdayNumberSunday,
1860 "W": parseWeekNumberMonday,
1861 "x": parseLocaleDate,
1862 "X": parseLocaleTime,
1863 "y": parseYear,
1864 "Y": parseFullYear,
1865 "Z": parseZone,
1866 "%": parseLiteralPercent
1867 };
1868
1869 // These recursive directive definitions must be deferred.
1870 formats.x = newFormat(locale_date, formats);
1871 formats.X = newFormat(locale_time, formats);
1872 formats.c = newFormat(locale_dateTime, formats);
1873 utcFormats.x = newFormat(locale_date, utcFormats);
1874 utcFormats.X = newFormat(locale_time, utcFormats);
1875 utcFormats.c = newFormat(locale_dateTime, utcFormats);
1876
1877 function newFormat(specifier, formats) {
1878 return function(date) {
1879 var string = [],
1880 i = -1,
1881 j = 0,
1882 n = specifier.length,
1883 c,
1884 pad,
1885 format;
1886
1887 if (!(date instanceof Date)) date = new Date(+date);
1888
1889 while (++i < n) {
1890 if (specifier.charCodeAt(i) === 37) {
1891 string.push(specifier.slice(j, i));
1892 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
1893 else pad = c === "e" ? " " : "0";
1894 if (format = formats[c]) c = format(date, pad);
1895 string.push(c);
1896 j = i + 1;
1897 }
1898 }
1899
1900 string.push(specifier.slice(j, i));
1901 return string.join("");
1902 };
1903 }
1904
1905 function newParse(specifier, newDate) {
1906 return function(string) {
1907 var d = newYear(1900),
1908 i = parseSpecifier(d, specifier, string += "", 0),
1909 week, day$1;
1910 if (i != string.length) return null;
1911
1912 // If a UNIX timestamp is specified, return it.
1913 if ("Q" in d) return new Date(d.Q);
1914
1915 // The am-pm flag is 0 for AM, and 1 for PM.
1916 if ("p" in d) d.H = d.H % 12 + d.p * 12;
1917
1918 // Convert day-of-week and week-of-year to day-of-year.
1919 if ("V" in d) {
1920 if (d.V < 1 || d.V > 53) return null;
1921 if (!("w" in d)) d.w = 1;
1922 if ("Z" in d) {
1923 week = utcDate(newYear(d.y)), day$1 = week.getUTCDay();
1924 week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
1925 week = utcDay.offset(week, (d.V - 1) * 7);
1926 d.y = week.getUTCFullYear();
1927 d.m = week.getUTCMonth();
1928 d.d = week.getUTCDate() + (d.w + 6) % 7;
1929 } else {
1930 week = newDate(newYear(d.y)), day$1 = week.getDay();
1931 week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
1932 week = day.offset(week, (d.V - 1) * 7);
1933 d.y = week.getFullYear();
1934 d.m = week.getMonth();
1935 d.d = week.getDate() + (d.w + 6) % 7;
1936 }
1937 } else if ("W" in d || "U" in d) {
1938 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
1939 day$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
1940 d.m = 0;
1941 d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
1942 }
1943
1944 // If a time zone is specified, all fields are interpreted as UTC and then
1945 // offset according to the specified time zone.
1946 if ("Z" in d) {
1947 d.H += d.Z / 100 | 0;
1948 d.M += d.Z % 100;
1949 return utcDate(d);
1950 }
1951
1952 // Otherwise, all fields are in local time.
1953 return newDate(d);
1954 };
1955 }
1956
1957 function parseSpecifier(d, specifier, string, j) {
1958 var i = 0,
1959 n = specifier.length,
1960 m = string.length,
1961 c,
1962 parse;
1963
1964 while (i < n) {
1965 if (j >= m) return -1;
1966 c = specifier.charCodeAt(i++);
1967 if (c === 37) {
1968 c = specifier.charAt(i++);
1969 parse = parses[c in pads ? specifier.charAt(i++) : c];
1970 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
1971 } else if (c != string.charCodeAt(j++)) {
1972 return -1;
1973 }
1974 }
1975
1976 return j;
1977 }
1978
1979 function parsePeriod(d, string, i) {
1980 var n = periodRe.exec(string.slice(i));
1981 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
1982 }
1983
1984 function parseShortWeekday(d, string, i) {
1985 var n = shortWeekdayRe.exec(string.slice(i));
1986 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
1987 }
1988
1989 function parseWeekday(d, string, i) {
1990 var n = weekdayRe.exec(string.slice(i));
1991 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
1992 }
1993
1994 function parseShortMonth(d, string, i) {
1995 var n = shortMonthRe.exec(string.slice(i));
1996 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
1997 }
1998
1999 function parseMonth(d, string, i) {
2000 var n = monthRe.exec(string.slice(i));
2001 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
2002 }
2003
2004 function parseLocaleDateTime(d, string, i) {
2005 return parseSpecifier(d, locale_dateTime, string, i);
2006 }
2007
2008 function parseLocaleDate(d, string, i) {
2009 return parseSpecifier(d, locale_date, string, i);
2010 }
2011
2012 function parseLocaleTime(d, string, i) {
2013 return parseSpecifier(d, locale_time, string, i);
2014 }
2015
2016 function formatShortWeekday(d) {
2017 return locale_shortWeekdays[d.getDay()];
2018 }
2019
2020 function formatWeekday(d) {
2021 return locale_weekdays[d.getDay()];
2022 }
2023
2024 function formatShortMonth(d) {
2025 return locale_shortMonths[d.getMonth()];
2026 }
2027
2028 function formatMonth(d) {
2029 return locale_months[d.getMonth()];
2030 }
2031
2032 function formatPeriod(d) {
2033 return locale_periods[+(d.getHours() >= 12)];
2034 }
2035
2036 function formatUTCShortWeekday(d) {
2037 return locale_shortWeekdays[d.getUTCDay()];
2038 }
2039
2040 function formatUTCWeekday(d) {
2041 return locale_weekdays[d.getUTCDay()];
2042 }
2043
2044 function formatUTCShortMonth(d) {
2045 return locale_shortMonths[d.getUTCMonth()];
2046 }
2047
2048 function formatUTCMonth(d) {
2049 return locale_months[d.getUTCMonth()];
2050 }
2051
2052 function formatUTCPeriod(d) {
2053 return locale_periods[+(d.getUTCHours() >= 12)];
2054 }
2055
2056 return {
2057 format: function(specifier) {
2058 var f = newFormat(specifier += "", formats);
2059 f.toString = function() { return specifier; };
2060 return f;
2061 },
2062 parse: function(specifier) {
2063 var p = newParse(specifier += "", localDate);
2064 p.toString = function() { return specifier; };
2065 return p;
2066 },
2067 utcFormat: function(specifier) {
2068 var f = newFormat(specifier += "", utcFormats);
2069 f.toString = function() { return specifier; };
2070 return f;
2071 },
2072 utcParse: function(specifier) {
2073 var p = newParse(specifier, utcDate);
2074 p.toString = function() { return specifier; };
2075 return p;
2076 }
2077 };
2078 }
2079
2080 var pads = {"-": "", "_": " ", "0": "0"},
2081 numberRe = /^\s*\d+/, // note: ignores next directive
2082 percentRe = /^%/,
2083 requoteRe = /[\\^$*+?|[\]().{}]/g;
2084
2085 function pad(value, fill, width) {
2086 var sign = value < 0 ? "-" : "",
2087 string = (sign ? -value : value) + "",
2088 length = string.length;
2089 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2090 }
2091
2092 function requote(s) {
2093 return s.replace(requoteRe, "\\$&");
2094 }
2095
2096 function formatRe(names) {
2097 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
2098 }
2099
2100 function formatLookup(names) {
2101 var map = {}, i = -1, n = names.length;
2102 while (++i < n) map[names[i].toLowerCase()] = i;
2103 return map;
2104 }
2105
2106 function parseWeekdayNumberSunday(d, string, i) {
2107 var n = numberRe.exec(string.slice(i, i + 1));
2108 return n ? (d.w = +n[0], i + n[0].length) : -1;
2109 }
2110
2111 function parseWeekdayNumberMonday(d, string, i) {
2112 var n = numberRe.exec(string.slice(i, i + 1));
2113 return n ? (d.u = +n[0], i + n[0].length) : -1;
2114 }
2115
2116 function parseWeekNumberSunday(d, string, i) {
2117 var n = numberRe.exec(string.slice(i, i + 2));
2118 return n ? (d.U = +n[0], i + n[0].length) : -1;
2119 }
2120
2121 function parseWeekNumberISO(d, string, i) {
2122 var n = numberRe.exec(string.slice(i, i + 2));
2123 return n ? (d.V = +n[0], i + n[0].length) : -1;
2124 }
2125
2126 function parseWeekNumberMonday(d, string, i) {
2127 var n = numberRe.exec(string.slice(i, i + 2));
2128 return n ? (d.W = +n[0], i + n[0].length) : -1;
2129 }
2130
2131 function parseFullYear(d, string, i) {
2132 var n = numberRe.exec(string.slice(i, i + 4));
2133 return n ? (d.y = +n[0], i + n[0].length) : -1;
2134 }
2135
2136 function parseYear(d, string, i) {
2137 var n = numberRe.exec(string.slice(i, i + 2));
2138 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
2139 }
2140
2141 function parseZone(d, string, i) {
2142 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
2143 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
2144 }
2145
2146 function parseMonthNumber(d, string, i) {
2147 var n = numberRe.exec(string.slice(i, i + 2));
2148 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
2149 }
2150
2151 function parseDayOfMonth(d, string, i) {
2152 var n = numberRe.exec(string.slice(i, i + 2));
2153 return n ? (d.d = +n[0], i + n[0].length) : -1;
2154 }
2155
2156 function parseDayOfYear(d, string, i) {
2157 var n = numberRe.exec(string.slice(i, i + 3));
2158 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
2159 }
2160
2161 function parseHour24(d, string, i) {
2162 var n = numberRe.exec(string.slice(i, i + 2));
2163 return n ? (d.H = +n[0], i + n[0].length) : -1;
2164 }
2165
2166 function parseMinutes(d, string, i) {
2167 var n = numberRe.exec(string.slice(i, i + 2));
2168 return n ? (d.M = +n[0], i + n[0].length) : -1;
2169 }
2170
2171 function parseSeconds(d, string, i) {
2172 var n = numberRe.exec(string.slice(i, i + 2));
2173 return n ? (d.S = +n[0], i + n[0].length) : -1;
2174 }
2175
2176 function parseMilliseconds(d, string, i) {
2177 var n = numberRe.exec(string.slice(i, i + 3));
2178 return n ? (d.L = +n[0], i + n[0].length) : -1;
2179 }
2180
2181 function parseMicroseconds(d, string, i) {
2182 var n = numberRe.exec(string.slice(i, i + 6));
2183 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
2184 }
2185
2186 function parseLiteralPercent(d, string, i) {
2187 var n = percentRe.exec(string.slice(i, i + 1));
2188 return n ? i + n[0].length : -1;
2189 }
2190
2191 function parseUnixTimestamp(d, string, i) {
2192 var n = numberRe.exec(string.slice(i));
2193 return n ? (d.Q = +n[0], i + n[0].length) : -1;
2194 }
2195
2196 function parseUnixTimestampSeconds(d, string, i) {
2197 var n = numberRe.exec(string.slice(i));
2198 return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
2199 }
2200
2201 function formatDayOfMonth(d, p) {
2202 return pad(d.getDate(), p, 2);
2203 }
2204
2205 function formatHour24(d, p) {
2206 return pad(d.getHours(), p, 2);
2207 }
2208
2209 function formatHour12(d, p) {
2210 return pad(d.getHours() % 12 || 12, p, 2);
2211 }
2212
2213 function formatDayOfYear(d, p) {
2214 return pad(1 + day.count(year(d), d), p, 3);
2215 }
2216
2217 function formatMilliseconds(d, p) {
2218 return pad(d.getMilliseconds(), p, 3);
2219 }
2220
2221 function formatMicroseconds(d, p) {
2222 return formatMilliseconds(d, p) + "000";
2223 }
2224
2225 function formatMonthNumber(d, p) {
2226 return pad(d.getMonth() + 1, p, 2);
2227 }
2228
2229 function formatMinutes(d, p) {
2230 return pad(d.getMinutes(), p, 2);
2231 }
2232
2233 function formatSeconds(d, p) {
2234 return pad(d.getSeconds(), p, 2);
2235 }
2236
2237 function formatWeekdayNumberMonday(d) {
2238 var day = d.getDay();
2239 return day === 0 ? 7 : day;
2240 }
2241
2242 function formatWeekNumberSunday(d, p) {
2243 return pad(sunday.count(year(d), d), p, 2);
2244 }
2245
2246 function formatWeekNumberISO(d, p) {
2247 var day = d.getDay();
2248 d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
2249 return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
2250 }
2251
2252 function formatWeekdayNumberSunday(d) {
2253 return d.getDay();
2254 }
2255
2256 function formatWeekNumberMonday(d, p) {
2257 return pad(monday.count(year(d), d), p, 2);
2258 }
2259
2260 function formatYear(d, p) {
2261 return pad(d.getFullYear() % 100, p, 2);
2262 }
2263
2264 function formatFullYear(d, p) {
2265 return pad(d.getFullYear() % 10000, p, 4);
2266 }
2267
2268 function formatZone(d) {
2269 var z = d.getTimezoneOffset();
2270 return (z > 0 ? "-" : (z *= -1, "+"))
2271 + pad(z / 60 | 0, "0", 2)
2272 + pad(z % 60, "0", 2);
2273 }
2274
2275 function formatUTCDayOfMonth(d, p) {
2276 return pad(d.getUTCDate(), p, 2);
2277 }
2278
2279 function formatUTCHour24(d, p) {
2280 return pad(d.getUTCHours(), p, 2);
2281 }
2282
2283 function formatUTCHour12(d, p) {
2284 return pad(d.getUTCHours() % 12 || 12, p, 2);
2285 }
2286
2287 function formatUTCDayOfYear(d, p) {
2288 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
2289 }
2290
2291 function formatUTCMilliseconds(d, p) {
2292 return pad(d.getUTCMilliseconds(), p, 3);
2293 }
2294
2295 function formatUTCMicroseconds(d, p) {
2296 return formatUTCMilliseconds(d, p) + "000";
2297 }
2298
2299 function formatUTCMonthNumber(d, p) {
2300 return pad(d.getUTCMonth() + 1, p, 2);
2301 }
2302
2303 function formatUTCMinutes(d, p) {
2304 return pad(d.getUTCMinutes(), p, 2);
2305 }
2306
2307 function formatUTCSeconds(d, p) {
2308 return pad(d.getUTCSeconds(), p, 2);
2309 }
2310
2311 function formatUTCWeekdayNumberMonday(d) {
2312 var dow = d.getUTCDay();
2313 return dow === 0 ? 7 : dow;
2314 }
2315
2316 function formatUTCWeekNumberSunday(d, p) {
2317 return pad(utcSunday.count(utcYear(d), d), p, 2);
2318 }
2319
2320 function formatUTCWeekNumberISO(d, p) {
2321 var day = d.getUTCDay();
2322 d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
2323 return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
2324 }
2325
2326 function formatUTCWeekdayNumberSunday(d) {
2327 return d.getUTCDay();
2328 }
2329
2330 function formatUTCWeekNumberMonday(d, p) {
2331 return pad(utcMonday.count(utcYear(d), d), p, 2);
2332 }
2333
2334 function formatUTCYear(d, p) {
2335 return pad(d.getUTCFullYear() % 100, p, 2);
2336 }
2337
2338 function formatUTCFullYear(d, p) {
2339 return pad(d.getUTCFullYear() % 10000, p, 4);
2340 }
2341
2342 function formatUTCZone() {
2343 return "+0000";
2344 }
2345
2346 function formatLiteralPercent() {
2347 return "%";
2348 }
2349
2350 function formatUnixTimestamp(d) {
2351 return +d;
2352 }
2353
2354 function formatUnixTimestampSeconds(d) {
2355 return Math.floor(+d / 1000);
2356 }
2357
2358 var locale;
2359 var timeFormat;
2360 var timeParse;
2361 var utcFormat;
2362 var utcParse;
2363
2364 defaultLocale({
2365 dateTime: "%x, %X",
2366 date: "%-m/%-d/%Y",
2367 time: "%-I:%M:%S %p",
2368 periods: ["AM", "PM"],
2369 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
2370 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
2371 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
2372 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
2373 });
2374
2375 function defaultLocale(definition) {
2376 locale = formatLocale(definition);
2377 timeFormat = locale.format;
2378 timeParse = locale.parse;
2379 utcFormat = locale.utcFormat;
2380 utcParse = locale.utcParse;
2381 return locale;
2382 }
2383
2384 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
2385
2386 function formatIsoNative(date) {
2387 return date.toISOString();
2388 }
2389
2390 var formatIso = Date.prototype.toISOString
2391 ? formatIsoNative
2392 : utcFormat(isoSpecifier);
2393
2394 function parseIsoNative(string) {
2395 var date = new Date(string);
2396 return isNaN(date) ? null : date;
2397 }
2398
2399 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
2400 ? parseIsoNative
2401 : utcParse(isoSpecifier);
2402
2403 var ECLGraph = /** @class */ (function (_super) {
2404 __extends(ECLGraph, _super);
2405 function ECLGraph(wu, eclGraph, eclTimers) {
2406 var _this = _super.call(this) || this;
2407 _this.wu = wu;
2408 var duration = 0;
2409 for (var _i = 0, eclTimers_1 = eclTimers; _i < eclTimers_1.length; _i++) {
2410 var eclTimer = eclTimers_1[_i];
2411 if (eclTimer.GraphName === eclGraph.Name && !eclTimer.HasSubGraphId) {
2412 duration = Math.round(eclTimer.Seconds * 1000) / 1000;
2413 break;
2414 }
2415 }
2416 _this.set(__assign({ Time: duration }, eclGraph));
2417 return _this;
2418 }
2419 Object.defineProperty(ECLGraph.prototype, "properties", {
2420 get: function () { return this.get(); },
2421 enumerable: false,
2422 configurable: true
2423 });
2424 Object.defineProperty(ECLGraph.prototype, "Name", {
2425 get: function () { return this.get("Name"); },
2426 enumerable: false,
2427 configurable: true
2428 });
2429 Object.defineProperty(ECLGraph.prototype, "Label", {
2430 get: function () { return this.get("Label"); },
2431 enumerable: false,
2432 configurable: true
2433 });
2434 Object.defineProperty(ECLGraph.prototype, "Type", {
2435 get: function () { return this.get("Type"); },
2436 enumerable: false,
2437 configurable: true
2438 });
2439 Object.defineProperty(ECLGraph.prototype, "Complete", {
2440 get: function () { return this.get("Complete"); },
2441 enumerable: false,
2442 configurable: true
2443 });
2444 Object.defineProperty(ECLGraph.prototype, "WhenStarted", {
2445 get: function () { return this.get("WhenStarted"); },
2446 enumerable: false,
2447 configurable: true
2448 });
2449 Object.defineProperty(ECLGraph.prototype, "WhenFinished", {
2450 get: function () { return this.get("WhenFinished"); },
2451 enumerable: false,
2452 configurable: true
2453 });
2454 Object.defineProperty(ECLGraph.prototype, "Time", {
2455 get: function () { return this.get("Time"); },
2456 enumerable: false,
2457 configurable: true
2458 });
2459 Object.defineProperty(ECLGraph.prototype, "Running", {
2460 get: function () { return this.get("Running"); },
2461 enumerable: false,
2462 configurable: true
2463 });
2464 Object.defineProperty(ECLGraph.prototype, "RunningId", {
2465 get: function () { return this.get("RunningId"); },
2466 enumerable: false,
2467 configurable: true
2468 });
2469 Object.defineProperty(ECLGraph.prototype, "Failed", {
2470 get: function () { return this.get("Failed"); },
2471 enumerable: false,
2472 configurable: true
2473 });
2474 ECLGraph.prototype.fetchScopeGraph = function (subgraphID) {
2475 if (subgraphID) {
2476 return this.wu.fetchGraphDetails([subgraphID], ["subgraph"]).then(function (scopes) {
2477 return createGraph(scopes);
2478 });
2479 }
2480 return this.wu.fetchGraphDetails([this.Name], ["graph"]).then(function (scopes) {
2481 return createGraph(scopes);
2482 });
2483 };
2484 return ECLGraph;
2485 }(util.StateObject));
2486 var GraphCache = /** @class */ (function (_super) {
2487 __extends(GraphCache, _super);
2488 function GraphCache() {
2489 return _super.call(this, function (obj) {
2490 return util.Cache.hash([obj.Name]);
2491 }) || this;
2492 }
2493 return GraphCache;
2494 }(util.Cache));
2495 function walkXmlJson(node, callback, stack) {
2496 stack = stack || [];
2497 stack.push(node);
2498 callback(node.name, node.$, node.children(), stack);
2499 node.children().forEach(function (childNode) {
2500 walkXmlJson(childNode, callback, stack);
2501 });
2502 stack.pop();
2503 }
2504 function flattenAtt(nodes) {
2505 var retVal = {};
2506 nodes.forEach(function (node) {
2507 if (node.name === "att") {
2508 retVal[node.$["name"]] = node.$["value"];
2509 }
2510 });
2511 return retVal;
2512 }
2513 var XGMMLGraph = /** @class */ (function (_super) {
2514 __extends(XGMMLGraph, _super);
2515 function XGMMLGraph() {
2516 return _super !== null && _super.apply(this, arguments) || this;
2517 }
2518 return XGMMLGraph;
2519 }(util.Graph));
2520 var XGMMLSubgraph = /** @class */ (function (_super) {
2521 __extends(XGMMLSubgraph, _super);
2522 function XGMMLSubgraph() {
2523 return _super !== null && _super.apply(this, arguments) || this;
2524 }
2525 return XGMMLSubgraph;
2526 }(util.Subgraph));
2527 var XGMMLVertex = /** @class */ (function (_super) {
2528 __extends(XGMMLVertex, _super);
2529 function XGMMLVertex() {
2530 return _super !== null && _super.apply(this, arguments) || this;
2531 }
2532 return XGMMLVertex;
2533 }(util.Vertex));
2534 var XGMMLEdge = /** @class */ (function (_super) {
2535 __extends(XGMMLEdge, _super);
2536 function XGMMLEdge() {
2537 return _super !== null && _super.apply(this, arguments) || this;
2538 }
2539 return XGMMLEdge;
2540 }(util.Edge));
2541 function createXGMMLGraph(id, graphs) {
2542 var subgraphs = {};
2543 var vertices = {};
2544 var edges = {};
2545 var graph = new XGMMLGraph(function (item) {
2546 return item._["id"];
2547 });
2548 var stack = [graph.root];
2549 walkXmlJson(graphs, function (tag, attributes, childNodes, _stack) {
2550 var top = stack[stack.length - 1];
2551 switch (tag) {
2552 case "graph":
2553 break;
2554 case "node":
2555 if (childNodes.length && childNodes[0].children().length && childNodes[0].children()[0].name === "graph") {
2556 var subgraph = top.createSubgraph(flattenAtt(childNodes));
2557 stack.push(subgraph);
2558 subgraphs[attributes["id"]] = subgraph;
2559 }
2560 // TODO: Is this really a node when its also a subgraph?
2561 var vertex = top.createVertex(flattenAtt(childNodes));
2562 vertices[attributes["id"]] = vertex;
2563 break;
2564 case "edge":
2565 var edge = top.createEdge(vertices[attributes["source"]], vertices[attributes["target"]], flattenAtt(childNodes));
2566 edges[attributes["id"]] = edge;
2567 break;
2568 }
2569 });
2570 return graph;
2571 }
2572 var ScopeGraph = /** @class */ (function (_super) {
2573 __extends(ScopeGraph, _super);
2574 function ScopeGraph() {
2575 return _super !== null && _super.apply(this, arguments) || this;
2576 }
2577 return ScopeGraph;
2578 }(util.Graph));
2579 var ScopeSubgraph = /** @class */ (function (_super) {
2580 __extends(ScopeSubgraph, _super);
2581 function ScopeSubgraph() {
2582 return _super !== null && _super.apply(this, arguments) || this;
2583 }
2584 return ScopeSubgraph;
2585 }(util.Subgraph));
2586 var ScopeVertex = /** @class */ (function (_super) {
2587 __extends(ScopeVertex, _super);
2588 function ScopeVertex() {
2589 return _super !== null && _super.apply(this, arguments) || this;
2590 }
2591 return ScopeVertex;
2592 }(util.Vertex));
2593 var ScopeEdge = /** @class */ (function (_super) {
2594 __extends(ScopeEdge, _super);
2595 function ScopeEdge() {
2596 return _super !== null && _super.apply(this, arguments) || this;
2597 }
2598 return ScopeEdge;
2599 }(util.Edge));
2600 function createGraph(scopes) {
2601 var subgraphs = {};
2602 var edges = {};
2603 var graph;
2604 for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
2605 var scope = scopes_1[_i];
2606 switch (scope.ScopeType) {
2607 case "graph":
2608 graph = new ScopeGraph(function (item) { return item._.Id; }, scope);
2609 subgraphs[scope.ScopeName] = graph.root;
2610 break;
2611 case "subgraph":
2612 if (!graph) {
2613 graph = new ScopeGraph(function (item) { return item._.Id; }, scope);
2614 subgraphs[scope.ScopeName] = graph.root;
2615 }
2616 var scopeStack = scope.parentScope().split(":");
2617 var scopeParent1 = subgraphs[scope.parentScope()];
2618 while (scopeStack.length && !scopeParent1) {
2619 scopeParent1 = subgraphs[scopeStack.join(":")];
2620 scopeStack.pop();
2621 }
2622 if (!scopeParent1) {
2623 console.log("Missing SG:Parent (" + scope.Id + "): " + scope.parentScope());
2624 }
2625 else {
2626 var parent1 = scopeParent1;
2627 subgraphs[scope.ScopeName] = parent1.createSubgraph(scope);
2628 }
2629 break;
2630 case "activity":
2631 var scopeParent2 = subgraphs[scope.parentScope()];
2632 if (!scopeParent2) {
2633 console.log("Missing A:Parent (" + scope.Id + "): " + scope.parentScope());
2634 }
2635 else {
2636 scopeParent2.createVertex(scope);
2637 }
2638 break;
2639 case "edge":
2640 edges[scope.ScopeName] = scope;
2641 break;
2642 }
2643 }
2644 for (var id in edges) {
2645 var scope = edges[id];
2646 var scopeParent3 = subgraphs[scope.parentScope()];
2647 if (!scopeParent3) {
2648 console.log("Missing E:Parent (" + scope.Id + "): " + scope.parentScope());
2649 }
2650 else {
2651 var parent3 = scopeParent3;
2652 try {
2653 var source = graph.vertex(scope.attr("IdSource").RawValue);
2654 var target = graph.vertex(scope.attr("IdTarget").RawValue);
2655 parent3.createEdge(source, target, scope);
2656 }
2657 catch (e) {
2658 // const sourceIndex = scope.attr("SourceIndex").RawValue;
2659 // const targetIndex = scope.attr("TargetIndex").RawValue;
2660 console.log("Invalid Edge: " + id);
2661 }
2662 }
2663 }
2664 return graph;
2665 }
2666
2667 var Resource = /** @class */ (function (_super) {
2668 __extends(Resource, _super);
2669 function Resource(wu, url) {
2670 var _this = _super.call(this) || this;
2671 _this.wu = wu;
2672 var cleanedURL = url.split("\\").join("/");
2673 var urlParts = cleanedURL.split("/");
2674 var matchStr = "res/" + _this.wu.Wuid + "/";
2675 var displayPath = "";
2676 var displayName = "";
2677 if (cleanedURL.indexOf(matchStr) === 0) {
2678 displayPath = cleanedURL.substr(matchStr.length);
2679 displayName = urlParts[urlParts.length - 1];
2680 }
2681 _this.set({
2682 URL: url,
2683 DisplayName: displayName,
2684 DisplayPath: displayPath
2685 });
2686 return _this;
2687 }
2688 Object.defineProperty(Resource.prototype, "properties", {
2689 get: function () { return this.get(); },
2690 enumerable: false,
2691 configurable: true
2692 });
2693 Object.defineProperty(Resource.prototype, "URL", {
2694 get: function () { return this.get("URL"); },
2695 enumerable: false,
2696 configurable: true
2697 });
2698 Object.defineProperty(Resource.prototype, "DisplayName", {
2699 get: function () { return this.get("DisplayName"); },
2700 enumerable: false,
2701 configurable: true
2702 });
2703 Object.defineProperty(Resource.prototype, "DisplayPath", {
2704 get: function () { return this.get("DisplayPath"); },
2705 enumerable: false,
2706 configurable: true
2707 });
2708 return Resource;
2709 }(util.StateObject));
2710
2711 var XSDNode = /** @class */ (function () {
2712 function XSDNode(e) {
2713 this.e = e;
2714 }
2715 XSDNode.prototype.fix = function () {
2716 delete this.e;
2717 };
2718 return XSDNode;
2719 }());
2720 var XSDXMLNode = /** @class */ (function (_super) {
2721 __extends(XSDXMLNode, _super);
2722 function XSDXMLNode(e) {
2723 var _this = _super.call(this, e) || this;
2724 _this.attrs = {};
2725 _this._children = [];
2726 return _this;
2727 }
2728 XSDXMLNode.prototype.append = function (child) {
2729 this._children.push(child);
2730 if (!this.type) {
2731 this.type = "hpcc:childDataset";
2732 }
2733 };
2734 XSDXMLNode.prototype.fix = function () {
2735 var _a;
2736 this.name = this.e.$["name"];
2737 this.type = this.e.$["type"];
2738 for (var i = this._children.length - 1; i >= 0; --i) {
2739 var row = this._children[i];
2740 if (row.name === "Row" && row.type === undefined) {
2741 (_a = this._children).push.apply(_a, row._children);
2742 this._children.splice(i, 1);
2743 }
2744 }
2745 _super.prototype.fix.call(this);
2746 };
2747 XSDXMLNode.prototype.children = function () {
2748 return this._children;
2749 };
2750 XSDXMLNode.prototype.charWidth = function () {
2751 var retVal = -1;
2752 switch (this.type) {
2753 case "xs:boolean":
2754 retVal = 5;
2755 break;
2756 case "xs:integer":
2757 retVal = 8;
2758 break;
2759 case "xs:nonNegativeInteger":
2760 retVal = 8;
2761 break;
2762 case "xs:double":
2763 retVal = 8;
2764 break;
2765 case "xs:string":
2766 retVal = 32;
2767 break;
2768 default:
2769 var numStr = "0123456789";
2770 var underbarPos = this.type.lastIndexOf("_");
2771 var length_1 = underbarPos > 0 ? underbarPos : this.type.length;
2772 var i = length_1 - 1;
2773 for (; i >= 0; --i) {
2774 if (numStr.indexOf(this.type.charAt(i)) === -1)
2775 break;
2776 }
2777 if (i + 1 < length_1) {
2778 retVal = parseInt(this.type.substring(i + 1, length_1), 10);
2779 }
2780 if (this.type.indexOf("data") === 0) {
2781 retVal *= 2;
2782 }
2783 break;
2784 }
2785 if (retVal < this.name.length)
2786 retVal = this.name.length;
2787 return retVal;
2788 };
2789 return XSDXMLNode;
2790 }(XSDNode));
2791 var XSDSimpleType = /** @class */ (function (_super) {
2792 __extends(XSDSimpleType, _super);
2793 function XSDSimpleType(e) {
2794 return _super.call(this, e) || this;
2795 }
2796 XSDSimpleType.prototype.append = function (e) {
2797 switch (e.name) {
2798 case "xs:restriction":
2799 this._restricition = e;
2800 break;
2801 case "xs:maxLength":
2802 this._maxLength = e;
2803 break;
2804 }
2805 };
2806 XSDSimpleType.prototype.fix = function () {
2807 this.name = this.e.$["name"];
2808 this.type = this._restricition.$["base"];
2809 this.maxLength = this._maxLength ? +this._maxLength.$["value"] : undefined;
2810 delete this._restricition;
2811 delete this._maxLength;
2812 _super.prototype.fix.call(this);
2813 };
2814 return XSDSimpleType;
2815 }(XSDNode));
2816 var XSDSchema = /** @class */ (function () {
2817 function XSDSchema() {
2818 this.simpleTypes = {};
2819 }
2820 XSDSchema.prototype.fields = function () {
2821 return this.root.children();
2822 };
2823 return XSDSchema;
2824 }());
2825 var XSDParser = /** @class */ (function (_super) {
2826 __extends(XSDParser, _super);
2827 function XSDParser() {
2828 var _this = _super !== null && _super.apply(this, arguments) || this;
2829 _this.schema = new XSDSchema();
2830 _this.simpleTypes = {};
2831 _this.xsdStack = new util.Stack();
2832 return _this;
2833 }
2834 XSDParser.prototype.startXMLNode = function (e) {
2835 _super.prototype.startXMLNode.call(this, e);
2836 switch (e.name) {
2837 case "xs:element":
2838 var xsdXMLNode = new XSDXMLNode(e);
2839 if (!this.schema.root) {
2840 this.schema.root = xsdXMLNode;
2841 }
2842 else if (this.xsdStack.depth()) {
2843 this.xsdStack.top().append(xsdXMLNode);
2844 }
2845 this.xsdStack.push(xsdXMLNode);
2846 break;
2847 case "xs:simpleType":
2848 this.simpleType = new XSDSimpleType(e);
2849 break;
2850 }
2851 };
2852 XSDParser.prototype.endXMLNode = function (e) {
2853 switch (e.name) {
2854 case "xs:element":
2855 var xsdXMLNode = this.xsdStack.pop();
2856 xsdXMLNode.fix();
2857 break;
2858 case "xs:simpleType":
2859 this.simpleType.fix();
2860 this.simpleTypes[this.simpleType.name] = this.simpleType;
2861 delete this.simpleType;
2862 break;
2863 case "xs:appinfo":
2864 var xsdXMLNode2 = this.xsdStack.top();
2865 for (var key in e.$) {
2866 xsdXMLNode2.attrs[key] = e.$[key];
2867 }
2868 break;
2869 default:
2870 if (this.simpleType) {
2871 this.simpleType.append(e);
2872 }
2873 }
2874 _super.prototype.endXMLNode.call(this, e);
2875 };
2876 return XSDParser;
2877 }(util.SAXStackParser));
2878 function parseXSD(xml) {
2879 var saxParser = new XSDParser();
2880 saxParser.parse(xml);
2881 return saxParser.schema;
2882 }
2883 var XSDParser2 = /** @class */ (function (_super) {
2884 __extends(XSDParser2, _super);
2885 function XSDParser2(rootName) {
2886 var _this = _super.call(this) || this;
2887 _this.schema = new XSDSchema();
2888 _this.simpleTypes = {};
2889 _this.xsdStack = new util.Stack();
2890 _this._rootName = rootName;
2891 return _this;
2892 }
2893 XSDParser2.prototype.startXMLNode = function (e) {
2894 _super.prototype.startXMLNode.call(this, e);
2895 switch (e.name) {
2896 case "xsd:element":
2897 var xsdXMLNode = new XSDXMLNode(e);
2898 if (!this.schema.root && this._rootName === e.$.name) {
2899 this.schema.root = xsdXMLNode;
2900 }
2901 if (this.xsdStack.depth()) {
2902 this.xsdStack.top().append(xsdXMLNode);
2903 }
2904 this.xsdStack.push(xsdXMLNode);
2905 break;
2906 case "xsd:simpleType":
2907 this.simpleType = new XSDSimpleType(e);
2908 break;
2909 }
2910 };
2911 XSDParser2.prototype.endXMLNode = function (e) {
2912 switch (e.name) {
2913 case "xsd:element":
2914 var xsdXMLNode = this.xsdStack.pop();
2915 xsdXMLNode.fix();
2916 break;
2917 }
2918 _super.prototype.endXMLNode.call(this, e);
2919 };
2920 return XSDParser2;
2921 }(XSDParser));
2922 function parseXSD2(xml, rootName) {
2923 var saxParser = new XSDParser2(rootName);
2924 saxParser.parse(xml);
2925 return saxParser.schema;
2926 }
2927
2928 var GlobalResultCache = /** @class */ (function (_super) {
2929 __extends(GlobalResultCache, _super);
2930 function GlobalResultCache() {
2931 return _super.call(this, function (obj) {
2932 return obj.BaseUrl + "-" + obj.Wuid + "-" + obj.ResultName;
2933 }) || this;
2934 }
2935 return GlobalResultCache;
2936 }(util.Cache));
2937 var _results = new GlobalResultCache();
2938 var Result = /** @class */ (function (_super) {
2939 __extends(Result, _super);
2940 function Result(optsConnection, wuidOrLogicalFile, eclResultOrResultName, resultViews) {
2941 if (resultViews === void 0) { resultViews = []; }
2942 var _this = _super.call(this) || this;
2943 if (optsConnection instanceof WorkunitsService) {
2944 _this.connection = optsConnection;
2945 }
2946 else {
2947 _this.connection = new WorkunitsService(optsConnection);
2948 }
2949 if (typeof eclResultOrResultName === "undefined") {
2950 _this.set({
2951 LogicalFileName: wuidOrLogicalFile
2952 });
2953 }
2954 else if (typeof eclResultOrResultName === "string") {
2955 _this.set({
2956 Wuid: wuidOrLogicalFile,
2957 ResultName: eclResultOrResultName,
2958 ResultViews: resultViews
2959 });
2960 }
2961 else if (typeof eclResultOrResultName === "number") {
2962 _this.set({
2963 Wuid: wuidOrLogicalFile,
2964 ResultSequence: eclResultOrResultName,
2965 ResultViews: resultViews
2966 });
2967 }
2968 else {
2969 _this.set(__assign({ Wuid: wuidOrLogicalFile, ResultName: eclResultOrResultName.Name, ResultViews: resultViews }, eclResultOrResultName));
2970 }
2971 return _this;
2972 }
2973 Object.defineProperty(Result.prototype, "BaseUrl", {
2974 get: function () { return this.connection.baseUrl; },
2975 enumerable: false,
2976 configurable: true
2977 });
2978 Object.defineProperty(Result.prototype, "properties", {
2979 get: function () { return this.get(); },
2980 enumerable: false,
2981 configurable: true
2982 });
2983 Object.defineProperty(Result.prototype, "Wuid", {
2984 get: function () { return this.get("Wuid"); },
2985 enumerable: false,
2986 configurable: true
2987 });
2988 Object.defineProperty(Result.prototype, "ResultName", {
2989 get: function () { return this.get("ResultName"); },
2990 enumerable: false,
2991 configurable: true
2992 });
2993 Object.defineProperty(Result.prototype, "ResultSequence", {
2994 get: function () { return this.get("ResultSequence"); },
2995 enumerable: false,
2996 configurable: true
2997 });
2998 Object.defineProperty(Result.prototype, "LogicalFileName", {
2999 get: function () { return this.get("LogicalFileName"); },
3000 enumerable: false,
3001 configurable: true
3002 });
3003 Object.defineProperty(Result.prototype, "Name", {
3004 get: function () { return this.get("Name"); },
3005 enumerable: false,
3006 configurable: true
3007 });
3008 Object.defineProperty(Result.prototype, "Sequence", {
3009 get: function () { return this.get("Sequence"); },
3010 enumerable: false,
3011 configurable: true
3012 });
3013 Object.defineProperty(Result.prototype, "Value", {
3014 get: function () { return this.get("Value"); },
3015 enumerable: false,
3016 configurable: true
3017 });
3018 Object.defineProperty(Result.prototype, "Link", {
3019 get: function () { return this.get("Link"); },
3020 enumerable: false,
3021 configurable: true
3022 });
3023 Object.defineProperty(Result.prototype, "FileName", {
3024 get: function () { return this.get("FileName"); },
3025 enumerable: false,
3026 configurable: true
3027 });
3028 Object.defineProperty(Result.prototype, "IsSupplied", {
3029 get: function () { return this.get("IsSupplied"); },
3030 enumerable: false,
3031 configurable: true
3032 });
3033 Object.defineProperty(Result.prototype, "ShowFileContent", {
3034 get: function () { return this.get("ShowFileContent"); },
3035 enumerable: false,
3036 configurable: true
3037 });
3038 Object.defineProperty(Result.prototype, "Total", {
3039 get: function () { return this.get("Total"); },
3040 enumerable: false,
3041 configurable: true
3042 });
3043 Object.defineProperty(Result.prototype, "ECLSchemas", {
3044 get: function () { return this.get("ECLSchemas"); },
3045 enumerable: false,
3046 configurable: true
3047 });
3048 Object.defineProperty(Result.prototype, "NodeGroup", {
3049 get: function () { return this.get("NodeGroup"); },
3050 enumerable: false,
3051 configurable: true
3052 });
3053 Object.defineProperty(Result.prototype, "ResultViews", {
3054 get: function () { return this.get("ResultViews"); },
3055 enumerable: false,
3056 configurable: true
3057 });
3058 Object.defineProperty(Result.prototype, "XmlSchema", {
3059 get: function () { return this.get("XmlSchema"); },
3060 enumerable: false,
3061 configurable: true
3062 });
3063 Result.attach = function (optsConnection, wuid, resultName, state) {
3064 var retVal = _results.get({ BaseUrl: optsConnection.baseUrl, Wuid: wuid, ResultName: resultName }, function () {
3065 return new Result(optsConnection, wuid, resultName);
3066 });
3067 if (state) {
3068 retVal.set(state);
3069 }
3070 return retVal;
3071 };
3072 Result.prototype.isComplete = function () {
3073 return this.Total !== -1;
3074 };
3075 Result.prototype.fetchXMLSchema = function () {
3076 var _this = this;
3077 if (this.xsdSchema) {
3078 return Promise.resolve(this.xsdSchema);
3079 }
3080 return this.WUResult().then(function (response) {
3081 if (util.exists("Result.XmlSchema.xml", response)) {
3082 _this.xsdSchema = parseXSD(response.Result.XmlSchema.xml);
3083 return _this.xsdSchema;
3084 }
3085 return null;
3086 });
3087 };
3088 Result.prototype.refresh = function () {
3089 return __awaiter(this, void 0, void 0, function () {
3090 return __generator(this, function (_a) {
3091 switch (_a.label) {
3092 case 0: return [4 /*yield*/, this.fetchRows(0, 1, true)];
3093 case 1:
3094 _a.sent();
3095 return [2 /*return*/, this];
3096 }
3097 });
3098 });
3099 };
3100 Result.prototype.fetchRows = function (from, count, includeSchema, filter) {
3101 var _this = this;
3102 if (from === void 0) { from = 0; }
3103 if (count === void 0) { count = -1; }
3104 if (includeSchema === void 0) { includeSchema = false; }
3105 if (filter === void 0) { filter = {}; }
3106 return this.WUResult(from, count, !includeSchema, filter).then(function (response) {
3107 var result = response.Result;
3108 delete response.Result; // Do not want it in "set"
3109 _this.set(__assign({}, response));
3110 if (util.exists("XmlSchema.xml", result)) {
3111 _this.xsdSchema = parseXSD(result.XmlSchema.xml);
3112 }
3113 if (util.exists("Row", result)) {
3114 return result.Row;
3115 }
3116 else if (_this.ResultName && util.exists(_this.ResultName, result)) {
3117 return result[_this.ResultName].Row;
3118 }
3119 return [];
3120 });
3121 };
3122 Result.prototype.rootField = function () {
3123 if (!this.xsdSchema)
3124 return null;
3125 return this.xsdSchema.root;
3126 };
3127 Result.prototype.fields = function () {
3128 if (!this.xsdSchema)
3129 return [];
3130 return this.xsdSchema.root.children();
3131 };
3132 Result.prototype.WUResult = function (start, count, suppressXmlSchema, filter) {
3133 if (start === void 0) { start = 0; }
3134 if (count === void 0) { count = 1; }
3135 if (suppressXmlSchema === void 0) { suppressXmlSchema = false; }
3136 if (filter === void 0) { filter = {}; }
3137 var FilterBy = {
3138 NamedValue: {
3139 itemcount: 0
3140 }
3141 };
3142 for (var key in filter) {
3143 FilterBy.NamedValue[FilterBy.NamedValue.itemcount++] = {
3144 Name: key,
3145 Value: filter[key]
3146 };
3147 }
3148 var request = { FilterBy: FilterBy };
3149 if (this.Wuid && this.ResultName !== undefined) {
3150 request.Wuid = this.Wuid;
3151 request.ResultName = this.ResultName;
3152 }
3153 else if (this.Wuid && this.ResultSequence !== undefined) {
3154 request.Wuid = this.Wuid;
3155 request.Sequence = this.ResultSequence;
3156 }
3157 else if (this.LogicalFileName && this.NodeGroup) {
3158 request.LogicalName = this.LogicalFileName;
3159 request.Cluster = this.NodeGroup;
3160 }
3161 else if (this.LogicalFileName) {
3162 request.LogicalName = this.LogicalFileName;
3163 }
3164 request.Start = start;
3165 request.Count = count;
3166 request.SuppressXmlSchema = suppressXmlSchema;
3167 return this.connection.WUResult(request).then(function (response) {
3168 return response;
3169 });
3170 };
3171 return Result;
3172 }(util.StateObject));
3173 var ResultCache = /** @class */ (function (_super) {
3174 __extends(ResultCache, _super);
3175 function ResultCache() {
3176 return _super.call(this, function (obj) {
3177 return util.Cache.hash([obj.Sequence, obj.Name, obj.FileName]);
3178 }) || this;
3179 }
3180 return ResultCache;
3181 }(util.Cache));
3182
3183 var Attribute = /** @class */ (function (_super) {
3184 __extends(Attribute, _super);
3185 function Attribute(scope, attribute) {
3186 var _this = _super.call(this) || this;
3187 _this.scope = scope;
3188 _this.set(attribute);
3189 return _this;
3190 }
3191 Object.defineProperty(Attribute.prototype, "properties", {
3192 get: function () { return this.get(); },
3193 enumerable: false,
3194 configurable: true
3195 });
3196 Object.defineProperty(Attribute.prototype, "Name", {
3197 get: function () { return this.get("Name"); },
3198 enumerable: false,
3199 configurable: true
3200 });
3201 Object.defineProperty(Attribute.prototype, "RawValue", {
3202 get: function () { return this.get("RawValue"); },
3203 enumerable: false,
3204 configurable: true
3205 });
3206 Object.defineProperty(Attribute.prototype, "Formatted", {
3207 get: function () { return this.get("Formatted"); },
3208 enumerable: false,
3209 configurable: true
3210 });
3211 Object.defineProperty(Attribute.prototype, "FormattedEnd", {
3212 get: function () { return this.get("FormattedEnd"); },
3213 enumerable: false,
3214 configurable: true
3215 });
3216 Object.defineProperty(Attribute.prototype, "Measure", {
3217 get: function () { return this.get("Measure"); },
3218 enumerable: false,
3219 configurable: true
3220 });
3221 Object.defineProperty(Attribute.prototype, "Creator", {
3222 get: function () { return this.get("Creator"); },
3223 enumerable: false,
3224 configurable: true
3225 });
3226 Object.defineProperty(Attribute.prototype, "CreatorType", {
3227 get: function () { return this.get("CreatorType"); },
3228 enumerable: false,
3229 configurable: true
3230 });
3231 return Attribute;
3232 }(util.StateObject));
3233 var BaseScope = /** @class */ (function (_super) {
3234 __extends(BaseScope, _super);
3235 function BaseScope(scope) {
3236 var _this = _super.call(this) || this;
3237 _this._attributeMap = {};
3238 _this._children = [];
3239 _this.update(scope);
3240 return _this;
3241 }
3242 Object.defineProperty(BaseScope.prototype, "properties", {
3243 get: function () { return this.get(); },
3244 enumerable: false,
3245 configurable: true
3246 });
3247 Object.defineProperty(BaseScope.prototype, "ScopeName", {
3248 get: function () { return this.get("ScopeName"); },
3249 enumerable: false,
3250 configurable: true
3251 });
3252 Object.defineProperty(BaseScope.prototype, "Id", {
3253 get: function () { return this.get("Id"); },
3254 enumerable: false,
3255 configurable: true
3256 });
3257 Object.defineProperty(BaseScope.prototype, "ScopeType", {
3258 get: function () { return this.get("ScopeType"); },
3259 enumerable: false,
3260 configurable: true
3261 });
3262 Object.defineProperty(BaseScope.prototype, "Properties", {
3263 get: function () { return this.get("Properties", { Property: [] }); },
3264 enumerable: false,
3265 configurable: true
3266 });
3267 Object.defineProperty(BaseScope.prototype, "CAttributes", {
3268 get: function () {
3269 var _this = this;
3270 // Match "started" and time elapsed
3271 var retVal = [];
3272 var timeElapsed = {
3273 start: null,
3274 end: null
3275 };
3276 this.Properties.Property.forEach(function (scopeAttr) {
3277 if (scopeAttr.Measure === "ts" && scopeAttr.Name.indexOf("Started") >= 0) {
3278 timeElapsed.start = scopeAttr;
3279 }
3280 else if (_this.ScopeName && scopeAttr.Measure === "ts" && scopeAttr.Name.indexOf("Finished") >= 0) {
3281 timeElapsed.end = scopeAttr;
3282 }
3283 else {
3284 retVal.push(new Attribute(_this, scopeAttr));
3285 }
3286 });
3287 if (timeElapsed.start && timeElapsed.end) {
3288 // const endTime = parser(timeElapsed.start.Formatted);
3289 // endTime!.setMilliseconds(endTime!.getMilliseconds() + (+timeElapsed.elapsed.RawValue) / 1000000);
3290 // timeElapsed.start.FormattedEnd = formatter(endTime!);
3291 timeElapsed.start.FormattedEnd = timeElapsed.end.Formatted;
3292 retVal.push(new Attribute(this, timeElapsed.start));
3293 }
3294 else if (timeElapsed.start) {
3295 retVal.push(new Attribute(this, timeElapsed.start));
3296 }
3297 else if (timeElapsed.end) {
3298 retVal.push(new Attribute(this, timeElapsed.end)); // Should not happen?
3299 }
3300 return retVal;
3301 },
3302 enumerable: false,
3303 configurable: true
3304 });
3305 BaseScope.prototype.update = function (scope) {
3306 var _this = this;
3307 this.set(scope);
3308 this.CAttributes.forEach(function (attr) {
3309 _this._attributeMap[attr.Name] = attr;
3310 });
3311 this.Properties.Property = [];
3312 for (var key in this._attributeMap) {
3313 if (this._attributeMap.hasOwnProperty(key)) {
3314 this.Properties.Property.push(this._attributeMap[key].properties);
3315 }
3316 }
3317 };
3318 BaseScope.prototype.parentScope = function () {
3319 var scopeParts = this.ScopeName.split(":");
3320 scopeParts.pop();
3321 return scopeParts.join(":");
3322 };
3323 BaseScope.prototype.children = function (_) {
3324 if (!arguments.length)
3325 return this._children;
3326 this._children = _;
3327 return this;
3328 };
3329 BaseScope.prototype.walk = function (visitor) {
3330 if (visitor.start(this))
3331 return true;
3332 for (var _i = 0, _a = this.children(); _i < _a.length; _i++) {
3333 var scope = _a[_i];
3334 if (scope.walk(visitor)) {
3335 return true;
3336 }
3337 }
3338 return visitor.end(this);
3339 };
3340 BaseScope.prototype.formattedAttrs = function () {
3341 var retVal = {};
3342 for (var attr in this._attributeMap) {
3343 retVal[attr] = this._attributeMap[attr].Formatted || this._attributeMap[attr].RawValue;
3344 }
3345 return retVal;
3346 };
3347 BaseScope.prototype.rawAttrs = function () {
3348 var retVal = {};
3349 for (var attr in this._attributeMap) {
3350 retVal[attr] = this._attributeMap[attr].RawValue;
3351 }
3352 return retVal;
3353 };
3354 BaseScope.prototype.hasAttr = function (name) {
3355 return this._attributeMap[name] !== undefined;
3356 };
3357 BaseScope.prototype.attr = function (name) {
3358 return this._attributeMap[name] || new Attribute(this, {
3359 Creator: "",
3360 CreatorType: "",
3361 Formatted: "",
3362 Measure: "",
3363 Name: "",
3364 RawValue: ""
3365 });
3366 };
3367 BaseScope.prototype.attrMeasure = function (name) {
3368 return this._attributeMap[name].Measure;
3369 };
3370 BaseScope.prototype.calcTooltip = function (parentScope) {
3371 var label = "";
3372 var rows = [];
3373 label = this.Id;
3374 rows.push("<tr><td class=\"key\">ID:</td><td class=\"value\">" + this.Id + "</td></tr>");
3375 if (parentScope) {
3376 rows.push("<tr><td class=\"key\">Parent ID:</td><td class=\"value\">" + parentScope.Id + "</td></tr>");
3377 }
3378 rows.push("<tr><td class=\"key\">Scope:</td><td class=\"value\">" + this.ScopeName + "</td></tr>");
3379 var attrs = this.formattedAttrs();
3380 for (var key in attrs) {
3381 if (key === "Label") {
3382 label = attrs[key];
3383 }
3384 else {
3385 rows.push("<tr><td class=\"key\">" + key + "</td><td class=\"value\">" + attrs[key] + "</td></tr>");
3386 }
3387 }
3388 return "<div class=\"eclwatch_WUGraph_Tooltip\" style=\"max-width:480px\">\n <h4 align=\"center\">" + label + "</h4>\n <table>\n " + rows.join("") + "\n </table>\n </div>";
3389 };
3390 return BaseScope;
3391 }(util.StateObject));
3392 var Scope = /** @class */ (function (_super) {
3393 __extends(Scope, _super);
3394 function Scope(wu, scope) {
3395 var _this = _super.call(this, scope) || this;
3396 _this.wu = wu;
3397 return _this;
3398 }
3399 return Scope;
3400 }(BaseScope));
3401
3402 var SourceFile = /** @class */ (function (_super) {
3403 __extends(SourceFile, _super);
3404 function SourceFile(optsConnection, wuid, eclSourceFile) {
3405 var _this = _super.call(this) || this;
3406 if (optsConnection instanceof WorkunitsService) {
3407 _this.connection = optsConnection;
3408 }
3409 else {
3410 _this.connection = new WorkunitsService(optsConnection);
3411 }
3412 _this.set(__assign({ Wuid: wuid }, eclSourceFile));
3413 return _this;
3414 }
3415 Object.defineProperty(SourceFile.prototype, "properties", {
3416 get: function () { return this.get(); },
3417 enumerable: false,
3418 configurable: true
3419 });
3420 Object.defineProperty(SourceFile.prototype, "Wuid", {
3421 get: function () { return this.get("Wuid"); },
3422 enumerable: false,
3423 configurable: true
3424 });
3425 Object.defineProperty(SourceFile.prototype, "FileCluster", {
3426 get: function () { return this.get("FileCluster"); },
3427 enumerable: false,
3428 configurable: true
3429 });
3430 Object.defineProperty(SourceFile.prototype, "Name", {
3431 get: function () { return this.get("Name"); },
3432 enumerable: false,
3433 configurable: true
3434 });
3435 Object.defineProperty(SourceFile.prototype, "IsSuperFile", {
3436 get: function () { return this.get("IsSuperFile"); },
3437 enumerable: false,
3438 configurable: true
3439 });
3440 Object.defineProperty(SourceFile.prototype, "Subs", {
3441 get: function () { return this.get("Subs"); },
3442 enumerable: false,
3443 configurable: true
3444 });
3445 Object.defineProperty(SourceFile.prototype, "Count", {
3446 get: function () { return this.get("Count"); },
3447 enumerable: false,
3448 configurable: true
3449 });
3450 Object.defineProperty(SourceFile.prototype, "ECLSourceFiles", {
3451 get: function () { return this.get("ECLSourceFiles"); },
3452 enumerable: false,
3453 configurable: true
3454 });
3455 return SourceFile;
3456 }(util.StateObject));
3457
3458 var Timer = /** @class */ (function (_super) {
3459 __extends(Timer, _super);
3460 function Timer(optsConnection, wuid, eclTimer) {
3461 var _this = _super.call(this) || this;
3462 if (optsConnection instanceof WorkunitsService) {
3463 _this.connection = optsConnection;
3464 }
3465 else {
3466 _this.connection = new WorkunitsService(optsConnection);
3467 }
3468 var secs = util.espTime2Seconds(eclTimer.Value);
3469 _this.set(__assign({ Wuid: wuid, Seconds: Math.round(secs * 1000) / 1000, HasSubGraphId: eclTimer.SubGraphId !== undefined }, eclTimer));
3470 return _this;
3471 }
3472 Object.defineProperty(Timer.prototype, "properties", {
3473 get: function () { return this.get(); },
3474 enumerable: false,
3475 configurable: true
3476 });
3477 Object.defineProperty(Timer.prototype, "Wuid", {
3478 get: function () { return this.get("Wuid"); },
3479 enumerable: false,
3480 configurable: true
3481 });
3482 Object.defineProperty(Timer.prototype, "Name", {
3483 get: function () { return this.get("Name"); },
3484 enumerable: false,
3485 configurable: true
3486 });
3487 Object.defineProperty(Timer.prototype, "Value", {
3488 get: function () { return this.get("Value"); },
3489 enumerable: false,
3490 configurable: true
3491 });
3492 Object.defineProperty(Timer.prototype, "Seconds", {
3493 get: function () { return this.get("Seconds"); },
3494 enumerable: false,
3495 configurable: true
3496 });
3497 Object.defineProperty(Timer.prototype, "GraphName", {
3498 get: function () { return this.get("GraphName"); },
3499 enumerable: false,
3500 configurable: true
3501 });
3502 Object.defineProperty(Timer.prototype, "SubGraphId", {
3503 get: function () { return this.get("SubGraphId"); },
3504 enumerable: false,
3505 configurable: true
3506 });
3507 Object.defineProperty(Timer.prototype, "HasSubGraphId", {
3508 get: function () { return this.get("HasSubGraphId"); },
3509 enumerable: false,
3510 configurable: true
3511 });
3512 Object.defineProperty(Timer.prototype, "count", {
3513 get: function () { return this.get("count"); },
3514 enumerable: false,
3515 configurable: true
3516 });
3517 return Timer;
3518 }(util.StateObject));
3519
3520 var formatter = utcFormat("%Y-%m-%dT%H:%M:%S.%LZ");
3521 var parser = utcParse("%Y-%m-%dT%H:%M:%S.%LZ");
3522 var logger$1 = util.scopedLogger("workunit.ts");
3523 var WUStateID = exports.WUStateID;
3524 var WorkunitCache = /** @class */ (function (_super) {
3525 __extends(WorkunitCache, _super);
3526 function WorkunitCache() {
3527 return _super.call(this, function (obj) {
3528 return obj.BaseUrl + "-" + obj.Wuid;
3529 }) || this;
3530 }
3531 return WorkunitCache;
3532 }(util.Cache));
3533 var _workunits = new WorkunitCache();
3534 var Workunit = /** @class */ (function (_super) {
3535 __extends(Workunit, _super);
3536 // --- --- ---
3537 function Workunit(optsConnection, wuid) {
3538 var _this = _super.call(this) || this;
3539 _this._debugMode = false;
3540 _this._resultCache = new ResultCache();
3541 _this._graphCache = new GraphCache();
3542 _this.connection = new WorkunitsService(optsConnection);
3543 _this.topologyConnection = new TopologyService(optsConnection);
3544 _this.clearState(wuid);
3545 return _this;
3546 }
3547 Object.defineProperty(Workunit.prototype, "BaseUrl", {
3548 get: function () { return this.connection.baseUrl; },
3549 enumerable: false,
3550 configurable: true
3551 });
3552 Object.defineProperty(Workunit.prototype, "properties", {
3553 // Accessors ---
3554 get: function () { return this.get(); },
3555 enumerable: false,
3556 configurable: true
3557 });
3558 Object.defineProperty(Workunit.prototype, "Wuid", {
3559 get: function () { return this.get("Wuid"); },
3560 enumerable: false,
3561 configurable: true
3562 });
3563 Object.defineProperty(Workunit.prototype, "Owner", {
3564 get: function () { return this.get("Owner", ""); },
3565 enumerable: false,
3566 configurable: true
3567 });
3568 Object.defineProperty(Workunit.prototype, "Cluster", {
3569 get: function () { return this.get("Cluster", ""); },
3570 enumerable: false,
3571 configurable: true
3572 });
3573 Object.defineProperty(Workunit.prototype, "Jobname", {
3574 get: function () { return this.get("Jobname", ""); },
3575 enumerable: false,
3576 configurable: true
3577 });
3578 Object.defineProperty(Workunit.prototype, "Description", {
3579 get: function () { return this.get("Description", ""); },
3580 enumerable: false,
3581 configurable: true
3582 });
3583 Object.defineProperty(Workunit.prototype, "ActionEx", {
3584 get: function () { return this.get("ActionEx", ""); },
3585 enumerable: false,
3586 configurable: true
3587 });
3588 Object.defineProperty(Workunit.prototype, "StateID", {
3589 get: function () { return this.get("StateID", exports.WUStateID.Unknown); },
3590 enumerable: false,
3591 configurable: true
3592 });
3593 Object.defineProperty(Workunit.prototype, "State", {
3594 get: function () { return this.get("State") || exports.WUStateID[this.StateID]; },
3595 enumerable: false,
3596 configurable: true
3597 });
3598 Object.defineProperty(Workunit.prototype, "Protected", {
3599 get: function () { return this.get("Protected", false); },
3600 enumerable: false,
3601 configurable: true
3602 });
3603 Object.defineProperty(Workunit.prototype, "Exceptions", {
3604 get: function () { return this.get("Exceptions", { ECLException: [] }); },
3605 enumerable: false,
3606 configurable: true
3607 });
3608 Object.defineProperty(Workunit.prototype, "ResultViews", {
3609 get: function () { return this.get("ResultViews", []); },
3610 enumerable: false,
3611 configurable: true
3612 });
3613 Object.defineProperty(Workunit.prototype, "ResultCount", {
3614 get: function () { return this.get("ResultCount", 0); },
3615 enumerable: false,
3616 configurable: true
3617 });
3618 Object.defineProperty(Workunit.prototype, "Results", {
3619 get: function () { return this.get("Results", { ECLResult: [] }); },
3620 enumerable: false,
3621 configurable: true
3622 });
3623 Object.defineProperty(Workunit.prototype, "CResults", {
3624 get: function () {
3625 var _this = this;
3626 return this.Results.ECLResult.map(function (eclResult) {
3627 return _this._resultCache.get(eclResult, function () {
3628 return new Result(_this.connection, _this.Wuid, eclResult, _this.ResultViews);
3629 });
3630 });
3631 },
3632 enumerable: false,
3633 configurable: true
3634 });
3635 Object.defineProperty(Workunit.prototype, "SequenceResults", {
3636 get: function () {
3637 var retVal = {};
3638 this.CResults.forEach(function (result) {
3639 retVal[result.Sequence] = result;
3640 });
3641 return retVal;
3642 },
3643 enumerable: false,
3644 configurable: true
3645 });
3646 Object.defineProperty(Workunit.prototype, "Timers", {
3647 get: function () { return this.get("Timers", { ECLTimer: [] }); },
3648 enumerable: false,
3649 configurable: true
3650 });
3651 Object.defineProperty(Workunit.prototype, "CTimers", {
3652 get: function () {
3653 var _this = this;
3654 return this.Timers.ECLTimer.map(function (eclTimer) {
3655 return new Timer(_this.connection, _this.Wuid, eclTimer);
3656 });
3657 },
3658 enumerable: false,
3659 configurable: true
3660 });
3661 Object.defineProperty(Workunit.prototype, "GraphCount", {
3662 get: function () { return this.get("GraphCount", 0); },
3663 enumerable: false,
3664 configurable: true
3665 });
3666 Object.defineProperty(Workunit.prototype, "Graphs", {
3667 get: function () { return this.get("Graphs", { ECLGraph: [] }); },
3668 enumerable: false,
3669 configurable: true
3670 });
3671 Object.defineProperty(Workunit.prototype, "CGraphs", {
3672 get: function () {
3673 var _this = this;
3674 return this.Graphs.ECLGraph.map(function (eclGraph) {
3675 return _this._graphCache.get(eclGraph, function () {
3676 return new ECLGraph(_this, eclGraph, _this.CTimers);
3677 });
3678 });
3679 },
3680 enumerable: false,
3681 configurable: true
3682 });
3683 Object.defineProperty(Workunit.prototype, "ThorLogList", {
3684 get: function () { return this.get("ThorLogList"); },
3685 enumerable: false,
3686 configurable: true
3687 });
3688 Object.defineProperty(Workunit.prototype, "ResourceURLCount", {
3689 get: function () { return this.get("ResourceURLCount", 0); },
3690 enumerable: false,
3691 configurable: true
3692 });
3693 Object.defineProperty(Workunit.prototype, "ResourceURLs", {
3694 get: function () { return this.get("ResourceURLs", { URL: [] }); },
3695 enumerable: false,
3696 configurable: true
3697 });
3698 Object.defineProperty(Workunit.prototype, "CResourceURLs", {
3699 get: function () {
3700 var _this = this;
3701 return this.ResourceURLs.URL.map(function (url) {
3702 return new Resource(_this, url);
3703 });
3704 },
3705 enumerable: false,
3706 configurable: true
3707 });
3708 Object.defineProperty(Workunit.prototype, "TotalClusterTime", {
3709 get: function () { return this.get("TotalClusterTime", ""); },
3710 enumerable: false,
3711 configurable: true
3712 });
3713 Object.defineProperty(Workunit.prototype, "DateTimeScheduled", {
3714 get: function () { return this.get("DateTimeScheduled"); },
3715 enumerable: false,
3716 configurable: true
3717 });
3718 Object.defineProperty(Workunit.prototype, "IsPausing", {
3719 get: function () { return this.get("IsPausing"); },
3720 enumerable: false,
3721 configurable: true
3722 });
3723 Object.defineProperty(Workunit.prototype, "ThorLCR", {
3724 get: function () { return this.get("ThorLCR"); },
3725 enumerable: false,
3726 configurable: true
3727 });
3728 Object.defineProperty(Workunit.prototype, "ApplicationValues", {
3729 get: function () { return this.get("ApplicationValues", { ApplicationValue: [] }); },
3730 enumerable: false,
3731 configurable: true
3732 });
3733 Object.defineProperty(Workunit.prototype, "HasArchiveQuery", {
3734 get: function () { return this.get("HasArchiveQuery"); },
3735 enumerable: false,
3736 configurable: true
3737 });
3738 Object.defineProperty(Workunit.prototype, "StateEx", {
3739 get: function () { return this.get("StateEx"); },
3740 enumerable: false,
3741 configurable: true
3742 });
3743 Object.defineProperty(Workunit.prototype, "PriorityClass", {
3744 get: function () { return this.get("PriorityClass"); },
3745 enumerable: false,
3746 configurable: true
3747 });
3748 Object.defineProperty(Workunit.prototype, "PriorityLevel", {
3749 get: function () { return this.get("PriorityLevel"); },
3750 enumerable: false,
3751 configurable: true
3752 });
3753 Object.defineProperty(Workunit.prototype, "Snapshot", {
3754 get: function () { return this.get("Snapshot"); },
3755 enumerable: false,
3756 configurable: true
3757 });
3758 Object.defineProperty(Workunit.prototype, "ResultLimit", {
3759 get: function () { return this.get("ResultLimit"); },
3760 enumerable: false,
3761 configurable: true
3762 });
3763 Object.defineProperty(Workunit.prototype, "EventSchedule", {
3764 get: function () { return this.get("EventSchedule"); },
3765 enumerable: false,
3766 configurable: true
3767 });
3768 Object.defineProperty(Workunit.prototype, "HaveSubGraphTimings", {
3769 get: function () { return this.get("HaveSubGraphTimings"); },
3770 enumerable: false,
3771 configurable: true
3772 });
3773 Object.defineProperty(Workunit.prototype, "Query", {
3774 get: function () { return this.get("Query"); },
3775 enumerable: false,
3776 configurable: true
3777 });
3778 Object.defineProperty(Workunit.prototype, "HelpersCount", {
3779 get: function () { return this.get("HelpersCount", 0); },
3780 enumerable: false,
3781 configurable: true
3782 });
3783 Object.defineProperty(Workunit.prototype, "Helpers", {
3784 get: function () { return this.get("Helpers", { ECLHelpFile: [] }); },
3785 enumerable: false,
3786 configurable: true
3787 });
3788 Object.defineProperty(Workunit.prototype, "DebugValues", {
3789 get: function () { return this.get("DebugValues"); },
3790 enumerable: false,
3791 configurable: true
3792 });
3793 Object.defineProperty(Workunit.prototype, "AllowedClusters", {
3794 get: function () { return this.get("AllowedClusters"); },
3795 enumerable: false,
3796 configurable: true
3797 });
3798 Object.defineProperty(Workunit.prototype, "ErrorCount", {
3799 get: function () { return this.get("ErrorCount", 0); },
3800 enumerable: false,
3801 configurable: true
3802 });
3803 Object.defineProperty(Workunit.prototype, "WarningCount", {
3804 get: function () { return this.get("WarningCount", 0); },
3805 enumerable: false,
3806 configurable: true
3807 });
3808 Object.defineProperty(Workunit.prototype, "InfoCount", {
3809 get: function () { return this.get("InfoCount", 0); },
3810 enumerable: false,
3811 configurable: true
3812 });
3813 Object.defineProperty(Workunit.prototype, "AlertCount", {
3814 get: function () { return this.get("AlertCount", 0); },
3815 enumerable: false,
3816 configurable: true
3817 });
3818 Object.defineProperty(Workunit.prototype, "SourceFileCount", {
3819 get: function () { return this.get("SourceFileCount", 0); },
3820 enumerable: false,
3821 configurable: true
3822 });
3823 Object.defineProperty(Workunit.prototype, "SourceFiles", {
3824 get: function () { return this.get("SourceFiles", { ECLSourceFile: [] }); },
3825 enumerable: false,
3826 configurable: true
3827 });
3828 Object.defineProperty(Workunit.prototype, "CSourceFiles", {
3829 get: function () {
3830 var _this = this;
3831 return this.SourceFiles.ECLSourceFile.map(function (eclSourceFile) { return new SourceFile(_this.connection, _this.Wuid, eclSourceFile); });
3832 },
3833 enumerable: false,
3834 configurable: true
3835 });
3836 Object.defineProperty(Workunit.prototype, "VariableCount", {
3837 get: function () { return this.get("VariableCount", 0); },
3838 enumerable: false,
3839 configurable: true
3840 });
3841 Object.defineProperty(Workunit.prototype, "Variables", {
3842 get: function () { return this.get("Variables", { ECLResult: [] }); },
3843 enumerable: false,
3844 configurable: true
3845 });
3846 Object.defineProperty(Workunit.prototype, "TimerCount", {
3847 get: function () { return this.get("TimerCount", 0); },
3848 enumerable: false,
3849 configurable: true
3850 });
3851 Object.defineProperty(Workunit.prototype, "HasDebugValue", {
3852 get: function () { return this.get("HasDebugValue"); },
3853 enumerable: false,
3854 configurable: true
3855 });
3856 Object.defineProperty(Workunit.prototype, "ApplicationValueCount", {
3857 get: function () { return this.get("ApplicationValueCount", 0); },
3858 enumerable: false,
3859 configurable: true
3860 });
3861 Object.defineProperty(Workunit.prototype, "XmlParams", {
3862 get: function () { return this.get("XmlParams"); },
3863 enumerable: false,
3864 configurable: true
3865 });
3866 Object.defineProperty(Workunit.prototype, "AccessFlag", {
3867 get: function () { return this.get("AccessFlag"); },
3868 enumerable: false,
3869 configurable: true
3870 });
3871 Object.defineProperty(Workunit.prototype, "ClusterFlag", {
3872 get: function () { return this.get("ClusterFlag"); },
3873 enumerable: false,
3874 configurable: true
3875 });
3876 Object.defineProperty(Workunit.prototype, "ResultViewCount", {
3877 get: function () { return this.get("ResultViewCount", 0); },
3878 enumerable: false,
3879 configurable: true
3880 });
3881 Object.defineProperty(Workunit.prototype, "DebugValueCount", {
3882 get: function () { return this.get("DebugValueCount", 0); },
3883 enumerable: false,
3884 configurable: true
3885 });
3886 Object.defineProperty(Workunit.prototype, "WorkflowCount", {
3887 get: function () { return this.get("WorkflowCount", 0); },
3888 enumerable: false,
3889 configurable: true
3890 });
3891 Object.defineProperty(Workunit.prototype, "Archived", {
3892 get: function () { return this.get("Archived"); },
3893 enumerable: false,
3894 configurable: true
3895 });
3896 Object.defineProperty(Workunit.prototype, "RoxieCluster", {
3897 get: function () { return this.get("RoxieCluster"); },
3898 enumerable: false,
3899 configurable: true
3900 });
3901 Object.defineProperty(Workunit.prototype, "DebugState", {
3902 get: function () { return this.get("DebugState", {}); },
3903 enumerable: false,
3904 configurable: true
3905 });
3906 Object.defineProperty(Workunit.prototype, "Queue", {
3907 get: function () { return this.get("Queue"); },
3908 enumerable: false,
3909 configurable: true
3910 });
3911 Object.defineProperty(Workunit.prototype, "Active", {
3912 get: function () { return this.get("Active"); },
3913 enumerable: false,
3914 configurable: true
3915 });
3916 Object.defineProperty(Workunit.prototype, "Action", {
3917 get: function () { return this.get("Action"); },
3918 enumerable: false,
3919 configurable: true
3920 });
3921 Object.defineProperty(Workunit.prototype, "Scope", {
3922 get: function () { return this.get("Scope"); },
3923 enumerable: false,
3924 configurable: true
3925 });
3926 Object.defineProperty(Workunit.prototype, "AbortBy", {
3927 get: function () { return this.get("AbortBy"); },
3928 enumerable: false,
3929 configurable: true
3930 });
3931 Object.defineProperty(Workunit.prototype, "AbortTime", {
3932 get: function () { return this.get("AbortTime"); },
3933 enumerable: false,
3934 configurable: true
3935 });
3936 Object.defineProperty(Workunit.prototype, "Workflows", {
3937 get: function () { return this.get("Workflows"); },
3938 enumerable: false,
3939 configurable: true
3940 });
3941 Object.defineProperty(Workunit.prototype, "TimingData", {
3942 get: function () { return this.get("TimingData"); },
3943 enumerable: false,
3944 configurable: true
3945 });
3946 Object.defineProperty(Workunit.prototype, "HelpersDesc", {
3947 get: function () { return this.get("HelpersDesc"); },
3948 enumerable: false,
3949 configurable: true
3950 });
3951 Object.defineProperty(Workunit.prototype, "GraphsDesc", {
3952 get: function () { return this.get("GraphsDesc"); },
3953 enumerable: false,
3954 configurable: true
3955 });
3956 Object.defineProperty(Workunit.prototype, "SourceFilesDesc", {
3957 get: function () { return this.get("GraphsDesc"); },
3958 enumerable: false,
3959 configurable: true
3960 });
3961 Object.defineProperty(Workunit.prototype, "ResultsDesc", {
3962 get: function () { return this.get("GraphsDesc"); },
3963 enumerable: false,
3964 configurable: true
3965 });
3966 Object.defineProperty(Workunit.prototype, "VariablesDesc", {
3967 get: function () { return this.get("GraphsDesc"); },
3968 enumerable: false,
3969 configurable: true
3970 });
3971 Object.defineProperty(Workunit.prototype, "TimersDesc", {
3972 get: function () { return this.get("GraphsDesc"); },
3973 enumerable: false,
3974 configurable: true
3975 });
3976 Object.defineProperty(Workunit.prototype, "DebugValuesDesc", {
3977 get: function () { return this.get("GraphsDesc"); },
3978 enumerable: false,
3979 configurable: true
3980 });
3981 Object.defineProperty(Workunit.prototype, "ApplicationValuesDesc", {
3982 get: function () { return this.get("GraphsDesc"); },
3983 enumerable: false,
3984 configurable: true
3985 });
3986 Object.defineProperty(Workunit.prototype, "WorkflowsDesc", {
3987 get: function () { return this.get("GraphsDesc"); },
3988 enumerable: false,
3989 configurable: true
3990 });
3991 // Factories ---
3992 Workunit.create = function (optsConnection) {
3993 var retVal = new Workunit(optsConnection);
3994 return retVal.connection.WUCreate().then(function (response) {
3995 _workunits.set(retVal);
3996 retVal.set(response.Workunit);
3997 return retVal;
3998 });
3999 };
4000 Workunit.attach = function (optsConnection, wuid, state) {
4001 var retVal = _workunits.get({ BaseUrl: optsConnection.baseUrl, Wuid: wuid }, function () {
4002 return new Workunit(optsConnection, wuid);
4003 });
4004 if (state) {
4005 retVal.set(state);
4006 }
4007 return retVal;
4008 };
4009 Workunit.existsLocal = function (baseUrl, wuid) {
4010 return _workunits.has({ BaseUrl: baseUrl, Wuid: wuid });
4011 };
4012 Workunit.submit = function (server, target, ecl) {
4013 return Workunit.create(server).then(function (wu) {
4014 return wu.update({ QueryText: ecl });
4015 }).then(function (wu) {
4016 return wu.submit(target);
4017 });
4018 };
4019 Workunit.query = function (server, opts) {
4020 var wsWorkunits = new WorkunitsService(server);
4021 return wsWorkunits.WUQuery(opts).then(function (response) {
4022 return response.Workunits.ECLWorkunit.map(function (wu) {
4023 return Workunit.attach(server, wu.Wuid, wu);
4024 });
4025 });
4026 };
4027 Workunit.prototype.clearState = function (wuid) {
4028 this.clear({
4029 Wuid: wuid,
4030 StateID: WUStateID.Unknown
4031 });
4032 };
4033 Workunit.prototype.update = function (request) {
4034 var _this = this;
4035 return this.connection.WUUpdate(__assign(__assign({}, request), {
4036 Wuid: this.Wuid,
4037 StateOrig: this.State,
4038 JobnameOrig: this.Jobname,
4039 DescriptionOrig: this.Description,
4040 ProtectedOrig: this.Protected,
4041 ClusterOrig: this.Cluster
4042 })).then(function (response) {
4043 _this.set(response.Workunit);
4044 return _this;
4045 });
4046 };
4047 Workunit.prototype.submit = function (_cluster, action, resultLimit) {
4048 var _this = this;
4049 if (action === void 0) { action = exports.WUUpdate.Action.Run; }
4050 var clusterPromise;
4051 if (_cluster !== void 0) {
4052 clusterPromise = Promise.resolve(_cluster);
4053 }
4054 else {
4055 clusterPromise = this.topologyConnection.DefaultTpLogicalClusterQuery().then(function (response) {
4056 return response.Name;
4057 });
4058 }
4059 this._debugMode = false;
4060 if (action === exports.WUUpdate.Action.Debug) {
4061 action = exports.WUUpdate.Action.Run;
4062 this._debugMode = true;
4063 }
4064 return clusterPromise.then(function (cluster) {
4065 return _this.connection.WUUpdate({
4066 Wuid: _this.Wuid,
4067 Action: action,
4068 ResultLimit: resultLimit,
4069 DebugValues: {
4070 DebugValue: [
4071 {
4072 Name: "Debug",
4073 Value: _this._debugMode ? "1" : ""
4074 }
4075 ]
4076 }
4077 }).then(function (response) {
4078 _this.set(response.Workunit);
4079 _this._submitAction = action;
4080 return _this.connection.WUSubmit({ Wuid: _this.Wuid, Cluster: cluster });
4081 });
4082 }).then(function () {
4083 return _this;
4084 });
4085 };
4086 Workunit.prototype.isComplete = function () {
4087 switch (this.StateID) {
4088 case WUStateID.Compiled:
4089 return this.ActionEx === "compile" || this._submitAction === exports.WUUpdate.Action.Compile;
4090 case WUStateID.Completed:
4091 case WUStateID.Failed:
4092 case WUStateID.Aborted:
4093 case WUStateID.NotFound:
4094 return true;
4095 }
4096 return false;
4097 };
4098 Workunit.prototype.isFailed = function () {
4099 switch (this.StateID) {
4100 case WUStateID.Aborted:
4101 case WUStateID.Failed:
4102 return true;
4103 }
4104 return false;
4105 };
4106 Workunit.prototype.isDeleted = function () {
4107 switch (this.StateID) {
4108 case WUStateID.NotFound:
4109 return true;
4110 }
4111 return false;
4112 };
4113 Workunit.prototype.isDebugging = function () {
4114 switch (this.StateID) {
4115 case WUStateID.DebugPaused:
4116 case WUStateID.DebugRunning:
4117 return true;
4118 }
4119 return this._debugMode;
4120 };
4121 Workunit.prototype.isRunning = function () {
4122 switch (this.StateID) {
4123 case WUStateID.Compiled:
4124 case WUStateID.Running:
4125 case WUStateID.Aborting:
4126 case WUStateID.Blocked:
4127 case WUStateID.DebugPaused:
4128 case WUStateID.DebugRunning:
4129 return true;
4130 }
4131 return false;
4132 };
4133 Workunit.prototype.setToFailed = function () {
4134 return this.WUAction("SetToFailed");
4135 };
4136 Workunit.prototype.pause = function () {
4137 return this.WUAction("Pause");
4138 };
4139 Workunit.prototype.pauseNow = function () {
4140 return this.WUAction("PauseNow");
4141 };
4142 Workunit.prototype.resume = function () {
4143 return this.WUAction("Resume");
4144 };
4145 Workunit.prototype.abort = function () {
4146 return this.WUAction("Abort");
4147 };
4148 Workunit.prototype.delete = function () {
4149 return this.WUAction("Delete");
4150 };
4151 Workunit.prototype.restore = function () {
4152 return this.WUAction("Restore");
4153 };
4154 Workunit.prototype.deschedule = function () {
4155 return this.WUAction("Deschedule");
4156 };
4157 Workunit.prototype.reschedule = function () {
4158 return this.WUAction("Reschedule");
4159 };
4160 Workunit.prototype.resubmit = function () {
4161 var _this = this;
4162 return this.WUResubmit({
4163 CloneWorkunit: false,
4164 ResetWorkflow: false
4165 }).then(function () {
4166 _this.clearState(_this.Wuid);
4167 return _this.refresh().then(function () {
4168 _this._monitor();
4169 return _this;
4170 });
4171 });
4172 };
4173 Workunit.prototype.clone = function () {
4174 var _this = this;
4175 return this.WUResubmit({
4176 CloneWorkunit: true,
4177 ResetWorkflow: false
4178 }).then(function (response) {
4179 return Workunit.attach(_this.connection.connection(), response.WUs.WU[0].WUID)
4180 .refresh();
4181 });
4182 };
4183 Workunit.prototype.refreshState = function () {
4184 return __awaiter(this, void 0, void 0, function () {
4185 return __generator(this, function (_a) {
4186 switch (_a.label) {
4187 case 0: return [4 /*yield*/, this.WUQuery()];
4188 case 1:
4189 _a.sent();
4190 return [2 /*return*/, this];
4191 }
4192 });
4193 });
4194 };
4195 Workunit.prototype.refreshInfo = function () {
4196 return __awaiter(this, void 0, void 0, function () {
4197 return __generator(this, function (_a) {
4198 switch (_a.label) {
4199 case 0: return [4 /*yield*/, this.WUInfo()];
4200 case 1:
4201 _a.sent();
4202 return [2 /*return*/, this];
4203 }
4204 });
4205 });
4206 };
4207 Workunit.prototype.refreshDebug = function () {
4208 return __awaiter(this, void 0, void 0, function () {
4209 return __generator(this, function (_a) {
4210 switch (_a.label) {
4211 case 0: return [4 /*yield*/, this.debugStatus()];
4212 case 1:
4213 _a.sent();
4214 return [2 /*return*/, this];
4215 }
4216 });
4217 });
4218 };
4219 Workunit.prototype.refresh = function (full) {
4220 if (full === void 0) { full = false; }
4221 return __awaiter(this, void 0, void 0, function () {
4222 return __generator(this, function (_a) {
4223 switch (_a.label) {
4224 case 0:
4225 if (!full) return [3 /*break*/, 2];
4226 return [4 /*yield*/, Promise.all([this.refreshInfo(), this.refreshDebug()])];
4227 case 1:
4228 _a.sent();
4229 return [3 /*break*/, 4];
4230 case 2: return [4 /*yield*/, this.refreshState()];
4231 case 3:
4232 _a.sent();
4233 _a.label = 4;
4234 case 4: return [2 /*return*/, this];
4235 }
4236 });
4237 });
4238 };
4239 Workunit.prototype.eclExceptions = function () {
4240 return this.Exceptions.ECLException;
4241 };
4242 Workunit.prototype.fetchArchive = function () {
4243 return this.connection.WUFile({
4244 Wuid: this.Wuid,
4245 Type: "ArchiveQuery"
4246 });
4247 };
4248 Workunit.prototype.fetchECLExceptions = function () {
4249 var _this = this;
4250 return this.WUInfo({ IncludeExceptions: true }).then(function () {
4251 return _this.eclExceptions();
4252 });
4253 };
4254 Workunit.prototype.fetchResults = function () {
4255 var _this = this;
4256 return this.WUInfo({ IncludeResults: true }).then(function () {
4257 return _this.CResults;
4258 });
4259 };
4260 Workunit.prototype.fetchGraphs = function () {
4261 var _this = this;
4262 return this.WUInfo({ IncludeGraphs: true }).then(function () {
4263 return _this.CGraphs;
4264 });
4265 };
4266 Workunit.prototype.fetchDetailsMeta = function (request) {
4267 if (request === void 0) { request = {}; }
4268 return this.WUDetailsMeta(request);
4269 };
4270 Workunit.prototype.fetchDetailsRaw = function (request) {
4271 if (request === void 0) { request = {}; }
4272 return this.WUDetails(request).then(function (response) { return response.Scopes.Scope; });
4273 };
4274 Workunit.prototype.fetchDetailsNormalized = function (request) {
4275 if (request === void 0) { request = {}; }
4276 return Promise.all([this.fetchDetailsMeta(), this.fetchDetailsRaw(request)]).then(function (promises) {
4277 var meta = promises[0];
4278 var scopes = promises[1];
4279 var columns = {
4280 id: {
4281 Measure: "label"
4282 },
4283 name: {
4284 Measure: "label"
4285 },
4286 type: {
4287 Measure: "label"
4288 }
4289 };
4290 var data = [];
4291 for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
4292 var scope = scopes_1[_i];
4293 var props = {};
4294 if (scope && scope.Id && scope.Properties && scope.Properties.Property) {
4295 for (var key in scope.Properties.Property) {
4296 var scopeProperty = scope.Properties.Property[key];
4297 if (scopeProperty.Measure === "ns") {
4298 scopeProperty.Measure = "s";
4299 }
4300 columns[scopeProperty.Name] = __assign({}, scopeProperty);
4301 delete columns[scopeProperty.Name].RawValue;
4302 delete columns[scopeProperty.Name].Formatted;
4303 switch (scopeProperty.Measure) {
4304 case "bool":
4305 props[scopeProperty.Name] = !!+scopeProperty.RawValue;
4306 break;
4307 case "sz":
4308 props[scopeProperty.Name] = +scopeProperty.RawValue;
4309 break;
4310 case "s":
4311 props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000000;
4312 break;
4313 case "ns":
4314 props[scopeProperty.Name] = +scopeProperty.RawValue;
4315 break;
4316 case "ts":
4317 props[scopeProperty.Name] = new Date(+scopeProperty.RawValue / 1000).toISOString();
4318 break;
4319 case "cnt":
4320 props[scopeProperty.Name] = +scopeProperty.RawValue;
4321 break;
4322 case "cpu":
4323 case "skw":
4324 case "node":
4325 case "ppm":
4326 case "ip":
4327 case "cy":
4328 case "en":
4329 case "txt":
4330 case "id":
4331 case "fname":
4332 default:
4333 props[scopeProperty.Name] = scopeProperty.RawValue;
4334 }
4335 }
4336 data.push(__assign({ id: scope.Id, name: scope.ScopeName, type: scope.ScopeType }, props));
4337 }
4338 }
4339 return {
4340 meta: meta,
4341 columns: columns,
4342 data: data
4343 };
4344 });
4345 };
4346 Workunit.prototype.fetchDetails = function (request) {
4347 var _this = this;
4348 if (request === void 0) { request = {}; }
4349 return this.WUDetails(request).then(function (response) {
4350 return response.Scopes.Scope.map(function (rawScope) {
4351 return new Scope(_this, rawScope);
4352 });
4353 });
4354 };
4355 Workunit.prototype.fetchDetailsHierarchy = function (request) {
4356 var _this = this;
4357 if (request === void 0) { request = {}; }
4358 return this.WUDetails(request).then(function (response) {
4359 var retVal = [];
4360 // Recreate Scope Hierarchy and dedup ---
4361 var scopeMap = {};
4362 response.Scopes.Scope.forEach(function (rawScope) {
4363 if (scopeMap[rawScope.ScopeName]) {
4364 scopeMap[rawScope.ScopeName].update(rawScope);
4365 return null;
4366 }
4367 else {
4368 var scope = new Scope(_this, rawScope);
4369 scopeMap[scope.ScopeName] = scope;
4370 return scope;
4371 }
4372 });
4373 for (var key in scopeMap) {
4374 if (scopeMap.hasOwnProperty(key)) {
4375 var scope = scopeMap[key];
4376 var parentScopeID = scope.parentScope();
4377 if (parentScopeID && scopeMap[parentScopeID]) {
4378 scopeMap[parentScopeID].children().push(scope);
4379 }
4380 else {
4381 retVal.push(scope);
4382 }
4383 }
4384 }
4385 return retVal;
4386 });
4387 };
4388 Workunit.prototype.fetchGraphDetails = function (graphIDs, rootTypes) {
4389 if (graphIDs === void 0) { graphIDs = []; }
4390 return this.fetchDetails({
4391 ScopeFilter: {
4392 MaxDepth: 999999,
4393 Ids: graphIDs,
4394 ScopeTypes: rootTypes
4395 },
4396 NestedFilter: {
4397 Depth: 999999,
4398 ScopeTypes: ["graph", "subgraph", "activity", "edge"]
4399 },
4400 PropertiesToReturn: {
4401 AllStatistics: true,
4402 AllAttributes: true,
4403 AllHints: true,
4404 AllProperties: true,
4405 AllScopes: true
4406 },
4407 ScopeOptions: {
4408 IncludeId: true,
4409 IncludeScope: true,
4410 IncludeScopeType: true
4411 },
4412 PropertyOptions: {
4413 IncludeName: true,
4414 IncludeRawValue: true,
4415 IncludeFormatted: true,
4416 IncludeMeasure: true,
4417 IncludeCreator: false,
4418 IncludeCreatorType: false
4419 }
4420 });
4421 };
4422 Workunit.prototype.fetchScopeGraphs = function (graphIDs) {
4423 if (graphIDs === void 0) { graphIDs = []; }
4424 return this.fetchGraphDetails(graphIDs, ["graph"]).then(function (scopes) {
4425 return createGraph(scopes);
4426 });
4427 };
4428 Workunit.prototype.fetchTimeElapsed = function () {
4429 return this.fetchDetails({
4430 ScopeFilter: {
4431 PropertyFilters: {
4432 PropertyFilter: [{ Name: "TimeElapsed" }]
4433 }
4434 }
4435 }).then(function (scopes) {
4436 var scopeInfo = {};
4437 scopes.forEach(function (scope) {
4438 scopeInfo[scope.ScopeName] = scopeInfo[scope.ScopeName] || {
4439 scope: scope.ScopeName,
4440 start: null,
4441 elapsed: null,
4442 finish: null
4443 };
4444 scope.CAttributes.forEach(function (attr) {
4445 if (attr.Name === "TimeElapsed") {
4446 scopeInfo[scope.ScopeName].elapsed = +attr.RawValue;
4447 }
4448 else if (attr.Measure === "ts" && attr.Name.indexOf("Started") >= 0) {
4449 scopeInfo[scope.ScopeName].start = attr.Formatted;
4450 }
4451 });
4452 });
4453 // Workaround duplicate scope responses
4454 var retVal = [];
4455 for (var key in scopeInfo) {
4456 var scope = scopeInfo[key];
4457 if (scope.start && scope.elapsed) {
4458 var endTime = parser(scope.start);
4459 endTime.setMilliseconds(endTime.getMilliseconds() + scope.elapsed / 1000000);
4460 scope.finish = formatter(endTime);
4461 retVal.push(scope);
4462 }
4463 }
4464 retVal.sort(function (l, r) {
4465 if (l.start < r.start)
4466 return -1;
4467 if (l.start > r.start)
4468 return 1;
4469 return 0;
4470 });
4471 return retVal;
4472 });
4473 };
4474 // Monitoring ---
4475 Workunit.prototype._monitor = function () {
4476 if (this.isComplete()) {
4477 this._monitorTickCount = 0;
4478 return;
4479 }
4480 _super.prototype._monitor.call(this);
4481 };
4482 Workunit.prototype._monitorTimeoutDuraction = function () {
4483 var retVal = _super.prototype._monitorTimeoutDuraction.call(this);
4484 if (this._monitorTickCount <= 1) { // Once
4485 return 1000;
4486 }
4487 else if (this._monitorTickCount <= 3) { // Twice
4488 return 3000;
4489 }
4490 else if (this._monitorTickCount <= 5) { // Twice
4491 return 5000;
4492 }
4493 else if (this._monitorTickCount <= 7) { // Twice
4494 return 10000;
4495 }
4496 return retVal;
4497 };
4498 // Events ---
4499 Workunit.prototype.on = function (eventID, propIDorCallback, callback) {
4500 var _this = this;
4501 if (this.isCallback(propIDorCallback)) {
4502 switch (eventID) {
4503 case "completed":
4504 _super.prototype.on.call(this, "propChanged", "StateID", function (changeInfo) {
4505 if (_this.isComplete()) {
4506 propIDorCallback([changeInfo]);
4507 }
4508 });
4509 break;
4510 case "changed":
4511 _super.prototype.on.call(this, eventID, propIDorCallback);
4512 break;
4513 }
4514 }
4515 else {
4516 switch (eventID) {
4517 case "changed":
4518 _super.prototype.on.call(this, eventID, propIDorCallback, callback);
4519 break;
4520 }
4521 }
4522 this._monitor();
4523 return this;
4524 };
4525 Workunit.prototype.watchUntilComplete = function (callback) {
4526 var _this = this;
4527 return new Promise(function (resolve, _) {
4528 var watchHandle = _this.watch(function (changes) {
4529 if (callback) {
4530 callback(changes);
4531 }
4532 if (_this.isComplete()) {
4533 watchHandle.release();
4534 resolve(_this);
4535 }
4536 });
4537 });
4538 };
4539 Workunit.prototype.watchUntilRunning = function (callback) {
4540 var _this = this;
4541 return new Promise(function (resolve, _) {
4542 var watchHandle = _this.watch(function (changes) {
4543 if (callback) {
4544 callback(changes);
4545 }
4546 if (_this.isComplete() || _this.isRunning()) {
4547 watchHandle.release();
4548 resolve(_this);
4549 }
4550 });
4551 });
4552 };
4553 // WsWorkunits passthroughs ---
4554 Workunit.prototype.WUQuery = function (_request) {
4555 var _this = this;
4556 if (_request === void 0) { _request = {}; }
4557 return this.connection.WUQuery(__assign(__assign({}, _request), { Wuid: this.Wuid })).then(function (response) {
4558 _this.set(response.Workunits.ECLWorkunit[0]);
4559 return response;
4560 }).catch(function (e) {
4561 // deleted ---
4562 var wuMissing = e.Exception.some(function (exception) {
4563 if (exception.Code === 20081) {
4564 _this.clearState(_this.Wuid);
4565 _this.set("StateID", WUStateID.NotFound);
4566 return true;
4567 }
4568 return false;
4569 });
4570 if (!wuMissing) {
4571 logger$1.warning("Unexpected exception: ");
4572 throw e;
4573 }
4574 return {};
4575 });
4576 };
4577 Workunit.prototype.WUCreate = function () {
4578 var _this = this;
4579 return this.connection.WUCreate().then(function (response) {
4580 _this.set(response.Workunit);
4581 _workunits.set(_this);
4582 return response;
4583 });
4584 };
4585 Workunit.prototype.WUInfo = function (_request) {
4586 var _this = this;
4587 if (_request === void 0) { _request = {}; }
4588 var includeResults = _request.IncludeResults || _request.IncludeResultsViewNames;
4589 return this.connection.WUInfo(__assign(__assign({}, _request), { Wuid: this.Wuid, IncludeResults: includeResults, IncludeResultsViewNames: includeResults, SuppressResultSchemas: false })).then(function (response) {
4590 _this.set(response.Workunit);
4591 if (includeResults) {
4592 _this.set({
4593 ResultViews: response.ResultViews
4594 });
4595 }
4596 return response;
4597 }).catch(function (e) {
4598 // deleted ---
4599 var wuMissing = e.Exception.some(function (exception) {
4600 if (exception.Code === 20080) {
4601 _this.clearState(_this.Wuid);
4602 _this.set("StateID", WUStateID.NotFound);
4603 return true;
4604 }
4605 return false;
4606 });
4607 if (!wuMissing) {
4608 logger$1.warning("Unexpected exception: ");
4609 throw e;
4610 }
4611 return {};
4612 });
4613 };
4614 Workunit.prototype.WUResubmit = function (request) {
4615 return this.connection.WUResubmit(util.deepMixinT({}, request, {
4616 Wuids: [this.Wuid]
4617 }));
4618 };
4619 Workunit.prototype.WUDetailsMeta = function (request) {
4620 return this.connection.WUDetailsMeta(request);
4621 };
4622 Workunit.prototype.WUDetails = function (request) {
4623 return this.connection.WUDetails(util.deepMixinT({
4624 ScopeFilter: {
4625 MaxDepth: 9999
4626 },
4627 ScopeOptions: {
4628 IncludeMatchedScopesInResults: true,
4629 IncludeScope: true,
4630 IncludeId: false,
4631 IncludeScopeType: false
4632 },
4633 PropertyOptions: {
4634 IncludeName: true,
4635 IncludeRawValue: false,
4636 IncludeFormatted: true,
4637 IncludeMeasure: true,
4638 IncludeCreator: false,
4639 IncludeCreatorType: false
4640 }
4641 }, request, { WUID: this.Wuid })).then(function (response) {
4642 return util.deepMixinT({
4643 Scopes: {
4644 Scope: []
4645 }
4646 }, response);
4647 });
4648 };
4649 Workunit.prototype.WUAction = function (actionType) {
4650 var _this = this;
4651 return this.connection.WUAction({
4652 Wuids: [this.Wuid],
4653 WUActionType: actionType
4654 }).then(function (response) {
4655 return _this.refresh().then(function () {
4656 _this._monitor();
4657 return response;
4658 });
4659 });
4660 };
4661 Workunit.prototype.publish = function (name) {
4662 return this.connection.WUPublishWorkunit({
4663 Wuid: this.Wuid,
4664 Cluster: this.Cluster,
4665 JobName: name || this.Jobname,
4666 AllowForeignFiles: true,
4667 Activate: true,
4668 Wait: 5000
4669 });
4670 };
4671 Workunit.prototype.WUCDebug = function (command, opts) {
4672 if (opts === void 0) { opts = {}; }
4673 var optsStr = "";
4674 for (var key in opts) {
4675 if (opts.hasOwnProperty(key)) {
4676 optsStr += " " + key + "='" + opts[key] + "'";
4677 }
4678 }
4679 return this.connection.WUCDebug({
4680 Wuid: this.Wuid,
4681 Command: "<debug:" + command + " uid='" + this.Wuid + "'" + optsStr + "/>"
4682 }).then(function (response) {
4683 return response;
4684 });
4685 };
4686 Workunit.prototype.debug = function (command, opts) {
4687 if (!this.isDebugging()) {
4688 return Promise.resolve(new util.XMLNode(command));
4689 }
4690 return this.WUCDebug(command, opts).then(function (response) {
4691 var retVal = response.children(command);
4692 if (retVal.length) {
4693 return retVal[0];
4694 }
4695 return new util.XMLNode(command);
4696 }).catch(function (_) {
4697 logger$1.error(_);
4698 return Promise.resolve(new util.XMLNode(command));
4699 });
4700 };
4701 Workunit.prototype.debugStatus = function () {
4702 var _this = this;
4703 if (!this.isDebugging()) {
4704 return Promise.resolve({
4705 DebugState: { state: "unknown" }
4706 });
4707 }
4708 return this.debug("status").then(function (response) {
4709 var debugState = __assign(__assign({}, _this.DebugState), response.$);
4710 _this.set({
4711 DebugState: debugState
4712 });
4713 return response;
4714 });
4715 };
4716 Workunit.prototype.debugContinue = function (mode) {
4717 if (mode === void 0) { mode = ""; }
4718 return this.debug("continue", {
4719 mode: mode
4720 });
4721 };
4722 Workunit.prototype.debugStep = function (mode) {
4723 return this.debug("step", {
4724 mode: mode
4725 });
4726 };
4727 Workunit.prototype.debugPause = function () {
4728 return this.debug("interrupt");
4729 };
4730 Workunit.prototype.debugQuit = function () {
4731 return this.debug("quit");
4732 };
4733 Workunit.prototype.debugDeleteAllBreakpoints = function () {
4734 return this.debug("delete", {
4735 idx: 0
4736 });
4737 };
4738 Workunit.prototype.debugBreakpointResponseParser = function (rootNode) {
4739 return rootNode.children().map(function (childNode) {
4740 if (childNode.name === "break") {
4741 return childNode.$;
4742 }
4743 });
4744 };
4745 Workunit.prototype.debugBreakpointAdd = function (id, mode, action) {
4746 var _this = this;
4747 return this.debug("breakpoint", {
4748 id: id,
4749 mode: mode,
4750 action: action
4751 }).then(function (rootNode) {
4752 return _this.debugBreakpointResponseParser(rootNode);
4753 });
4754 };
4755 Workunit.prototype.debugBreakpointList = function () {
4756 var _this = this;
4757 return this.debug("list").then(function (rootNode) {
4758 return _this.debugBreakpointResponseParser(rootNode);
4759 });
4760 };
4761 Workunit.prototype.debugGraph = function () {
4762 var _this = this;
4763 if (this._debugAllGraph && this.DebugState["_prevGraphSequenceNum"] === this.DebugState["graphSequenceNum"]) {
4764 return Promise.resolve(this._debugAllGraph);
4765 }
4766 return this.debug("graph", { name: "all" }).then(function (response) {
4767 _this.DebugState["_prevGraphSequenceNum"] = _this.DebugState["graphSequenceNum"];
4768 _this._debugAllGraph = createXGMMLGraph(_this.Wuid, response);
4769 return _this._debugAllGraph;
4770 });
4771 };
4772 Workunit.prototype.debugBreakpointValid = function (path) {
4773 return this.debugGraph().then(function (graph) {
4774 return breakpointLocations(graph, path);
4775 });
4776 };
4777 Workunit.prototype.debugPrint = function (edgeID, startRow, numRows) {
4778 if (startRow === void 0) { startRow = 0; }
4779 if (numRows === void 0) { numRows = 10; }
4780 return this.debug("print", {
4781 edgeID: edgeID,
4782 startRow: startRow,
4783 numRows: numRows
4784 }).then(function (response) {
4785 return response.children().map(function (rowNode) {
4786 var retVal = {};
4787 rowNode.children().forEach(function (cellNode) {
4788 retVal[cellNode.name] = cellNode.content;
4789 });
4790 return retVal;
4791 });
4792 });
4793 };
4794 return Workunit;
4795 }(util.StateObject));
4796 var ATTR_DEFINITION = "definition";
4797 function hasECLDefinition(vertex) {
4798 return vertex._[ATTR_DEFINITION] !== undefined;
4799 }
4800 function getECLDefinition(vertex) {
4801 var match = /([a-z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(vertex._[ATTR_DEFINITION]);
4802 if (match) {
4803 var _file = match[1], _row = match[2], _col = match[3];
4804 _file.replace("/./", "/");
4805 return {
4806 id: vertex._["id"],
4807 file: _file,
4808 line: +_row,
4809 column: +_col
4810 };
4811 }
4812 throw new Error("Bad definition: " + vertex._[ATTR_DEFINITION]);
4813 }
4814 function breakpointLocations(graph, path) {
4815 var retVal = [];
4816 for (var _i = 0, _a = graph.vertices; _i < _a.length; _i++) {
4817 var vertex = _a[_i];
4818 if (hasECLDefinition(vertex)) {
4819 var definition = getECLDefinition(vertex);
4820 if (definition && !path || path === definition.file) {
4821 retVal.push(definition);
4822 }
4823 }
4824 }
4825 return retVal.sort(function (l, r) {
4826 return l.line - r.line;
4827 });
4828 }
4829
4830 var _activity;
4831 var Activity = /** @class */ (function (_super) {
4832 __extends(Activity, _super);
4833 function Activity(optsConnection) {
4834 var _this = _super.call(this) || this;
4835 _this.lazyRefresh = util.debounce(function () { return __awaiter(_this, void 0, void 0, function () {
4836 var response;
4837 return __generator(this, function (_a) {
4838 switch (_a.label) {
4839 case 0: return [4 /*yield*/, this.connection.Activity({})];
4840 case 1:
4841 response = _a.sent();
4842 this.set(response);
4843 return [2 /*return*/, this];
4844 }
4845 });
4846 }); });
4847 if (optsConnection instanceof SMCService) {
4848 _this.connection = optsConnection;
4849 }
4850 else {
4851 _this.connection = new SMCService(optsConnection);
4852 }
4853 _this.clear({});
4854 return _this;
4855 }
4856 Object.defineProperty(Activity.prototype, "properties", {
4857 get: function () { return this.get(); },
4858 enumerable: false,
4859 configurable: true
4860 });
4861 Object.defineProperty(Activity.prototype, "Exceptions", {
4862 get: function () { return this.get("Exceptions"); },
4863 enumerable: false,
4864 configurable: true
4865 });
4866 Object.defineProperty(Activity.prototype, "Build", {
4867 get: function () { return this.get("Build"); },
4868 enumerable: false,
4869 configurable: true
4870 });
4871 Object.defineProperty(Activity.prototype, "ThorClusterList", {
4872 get: function () { return this.get("ThorClusterList"); },
4873 enumerable: false,
4874 configurable: true
4875 });
4876 Object.defineProperty(Activity.prototype, "RoxieClusterList", {
4877 get: function () { return this.get("RoxieClusterList"); },
4878 enumerable: false,
4879 configurable: true
4880 });
4881 Object.defineProperty(Activity.prototype, "HThorClusterList", {
4882 get: function () { return this.get("HThorClusterList"); },
4883 enumerable: false,
4884 configurable: true
4885 });
4886 Object.defineProperty(Activity.prototype, "DFUJobs", {
4887 get: function () { return this.get("DFUJobs"); },
4888 enumerable: false,
4889 configurable: true
4890 });
4891 Object.defineProperty(Activity.prototype, "Running", {
4892 get: function () { return this.get("Running", { ActiveWorkunit: [] }); },
4893 enumerable: false,
4894 configurable: true
4895 });
4896 Object.defineProperty(Activity.prototype, "BannerContent", {
4897 get: function () { return this.get("BannerContent"); },
4898 enumerable: false,
4899 configurable: true
4900 });
4901 Object.defineProperty(Activity.prototype, "BannerColor", {
4902 get: function () { return this.get("BannerColor"); },
4903 enumerable: false,
4904 configurable: true
4905 });
4906 Object.defineProperty(Activity.prototype, "BannerSize", {
4907 get: function () { return this.get("BannerSize"); },
4908 enumerable: false,
4909 configurable: true
4910 });
4911 Object.defineProperty(Activity.prototype, "BannerScroll", {
4912 get: function () { return this.get("BannerScroll"); },
4913 enumerable: false,
4914 configurable: true
4915 });
4916 Object.defineProperty(Activity.prototype, "ChatURL", {
4917 get: function () { return this.get("ChatURL"); },
4918 enumerable: false,
4919 configurable: true
4920 });
4921 Object.defineProperty(Activity.prototype, "ShowBanner", {
4922 get: function () { return this.get("ShowBanner"); },
4923 enumerable: false,
4924 configurable: true
4925 });
4926 Object.defineProperty(Activity.prototype, "ShowChatURL", {
4927 get: function () { return this.get("ShowChatURL"); },
4928 enumerable: false,
4929 configurable: true
4930 });
4931 Object.defineProperty(Activity.prototype, "SortBy", {
4932 get: function () { return this.get("SortBy"); },
4933 enumerable: false,
4934 configurable: true
4935 });
4936 Object.defineProperty(Activity.prototype, "Descending", {
4937 get: function () { return this.get("Descending"); },
4938 enumerable: false,
4939 configurable: true
4940 });
4941 Object.defineProperty(Activity.prototype, "SuperUser", {
4942 get: function () { return this.get("SuperUser"); },
4943 enumerable: false,
4944 configurable: true
4945 });
4946 Object.defineProperty(Activity.prototype, "AccessRight", {
4947 get: function () { return this.get("AccessRight"); },
4948 enumerable: false,
4949 configurable: true
4950 });
4951 Object.defineProperty(Activity.prototype, "ServerJobQueues", {
4952 get: function () { return this.get("ServerJobQueues"); },
4953 enumerable: false,
4954 configurable: true
4955 });
4956 Activity.attach = function (optsConnection, state) {
4957 if (!_activity) {
4958 _activity = new Activity(optsConnection);
4959 }
4960 if (state) {
4961 _activity.set(__assign({}, state));
4962 }
4963 return _activity;
4964 };
4965 Activity.prototype.runningWorkunits = function (clusterName) {
4966 var _this = this;
4967 if (clusterName === void 0) { clusterName = ""; }
4968 return this.Running.ActiveWorkunit.filter(function (awu) { return clusterName === "" || awu.ClusterName === clusterName; }).map(function (awu) { return Workunit.attach(_this.connection.connectionOptions(), awu.Wuid, awu); });
4969 };
4970 Activity.prototype.refresh = function () {
4971 return __awaiter(this, void 0, void 0, function () {
4972 return __generator(this, function (_a) {
4973 return [2 /*return*/, this.lazyRefresh()];
4974 });
4975 });
4976 };
4977 return Activity;
4978 }(util.StateObject));
4979
4980 var LogicalFileCache = /** @class */ (function (_super) {
4981 __extends(LogicalFileCache, _super);
4982 function LogicalFileCache() {
4983 return _super.call(this, function (obj) {
4984 return obj.BaseUrl + "-" + obj.Cluster + "-" + obj.Name;
4985 }) || this;
4986 }
4987 return LogicalFileCache;
4988 }(util.Cache));
4989 var _store = new LogicalFileCache();
4990 var LogicalFile = /** @class */ (function (_super) {
4991 __extends(LogicalFile, _super);
4992 function LogicalFile(optsConnection, Cluster, Name) {
4993 var _this = _super.call(this) || this;
4994 if (optsConnection instanceof DFUService) {
4995 _this.connection = optsConnection;
4996 }
4997 else {
4998 _this.connection = new DFUService(optsConnection);
4999 }
5000 _this.clear({
5001 Cluster: Cluster,
5002 Name: Name
5003 });
5004 return _this;
5005 }
5006 Object.defineProperty(LogicalFile.prototype, "BaseUrl", {
5007 get: function () { return this.connection.baseUrl; },
5008 enumerable: false,
5009 configurable: true
5010 });
5011 Object.defineProperty(LogicalFile.prototype, "Cluster", {
5012 get: function () { return this.get("Cluster"); },
5013 enumerable: false,
5014 configurable: true
5015 });
5016 Object.defineProperty(LogicalFile.prototype, "Name", {
5017 get: function () { return this.get("Name"); },
5018 enumerable: false,
5019 configurable: true
5020 });
5021 Object.defineProperty(LogicalFile.prototype, "Filename", {
5022 get: function () { return this.get("Filename"); },
5023 enumerable: false,
5024 configurable: true
5025 });
5026 Object.defineProperty(LogicalFile.prototype, "Prefix", {
5027 get: function () { return this.get("Prefix"); },
5028 enumerable: false,
5029 configurable: true
5030 });
5031 Object.defineProperty(LogicalFile.prototype, "NodeGroup", {
5032 get: function () { return this.get("NodeGroup"); },
5033 enumerable: false,
5034 configurable: true
5035 });
5036 Object.defineProperty(LogicalFile.prototype, "NumParts", {
5037 get: function () { return this.get("NumParts"); },
5038 enumerable: false,
5039 configurable: true
5040 });
5041 Object.defineProperty(LogicalFile.prototype, "Description", {
5042 get: function () { return this.get("Description"); },
5043 enumerable: false,
5044 configurable: true
5045 });
5046 Object.defineProperty(LogicalFile.prototype, "Dir", {
5047 get: function () { return this.get("Dir"); },
5048 enumerable: false,
5049 configurable: true
5050 });
5051 Object.defineProperty(LogicalFile.prototype, "PathMask", {
5052 get: function () { return this.get("PathMask"); },
5053 enumerable: false,
5054 configurable: true
5055 });
5056 Object.defineProperty(LogicalFile.prototype, "Filesize", {
5057 get: function () { return this.get("Filesize"); },
5058 enumerable: false,
5059 configurable: true
5060 });
5061 Object.defineProperty(LogicalFile.prototype, "FileSizeInt64", {
5062 get: function () { return this.get("FileSizeInt64"); },
5063 enumerable: false,
5064 configurable: true
5065 });
5066 Object.defineProperty(LogicalFile.prototype, "RecordSize", {
5067 get: function () { return this.get("RecordSize"); },
5068 enumerable: false,
5069 configurable: true
5070 });
5071 Object.defineProperty(LogicalFile.prototype, "RecordCount", {
5072 get: function () { return this.get("RecordCount"); },
5073 enumerable: false,
5074 configurable: true
5075 });
5076 Object.defineProperty(LogicalFile.prototype, "RecordSizeInt64", {
5077 get: function () { return this.get("RecordSizeInt64"); },
5078 enumerable: false,
5079 configurable: true
5080 });
5081 Object.defineProperty(LogicalFile.prototype, "RecordCountInt64", {
5082 get: function () { return this.get("RecordCountInt64"); },
5083 enumerable: false,
5084 configurable: true
5085 });
5086 Object.defineProperty(LogicalFile.prototype, "Wuid", {
5087 get: function () { return this.get("Wuid"); },
5088 enumerable: false,
5089 configurable: true
5090 });
5091 Object.defineProperty(LogicalFile.prototype, "Owner", {
5092 get: function () { return this.get("Owner"); },
5093 enumerable: false,
5094 configurable: true
5095 });
5096 Object.defineProperty(LogicalFile.prototype, "JobName", {
5097 get: function () { return this.get("JobName"); },
5098 enumerable: false,
5099 configurable: true
5100 });
5101 Object.defineProperty(LogicalFile.prototype, "Persistent", {
5102 get: function () { return this.get("Persistent"); },
5103 enumerable: false,
5104 configurable: true
5105 });
5106 Object.defineProperty(LogicalFile.prototype, "Format", {
5107 get: function () { return this.get("Format"); },
5108 enumerable: false,
5109 configurable: true
5110 });
5111 Object.defineProperty(LogicalFile.prototype, "MaxRecordSize", {
5112 get: function () { return this.get("MaxRecordSize"); },
5113 enumerable: false,
5114 configurable: true
5115 });
5116 Object.defineProperty(LogicalFile.prototype, "CsvSeparate", {
5117 get: function () { return this.get("CsvSeparate"); },
5118 enumerable: false,
5119 configurable: true
5120 });
5121 Object.defineProperty(LogicalFile.prototype, "CsvQuote", {
5122 get: function () { return this.get("CsvQuote"); },
5123 enumerable: false,
5124 configurable: true
5125 });
5126 Object.defineProperty(LogicalFile.prototype, "CsvTerminate", {
5127 get: function () { return this.get("CsvTerminate"); },
5128 enumerable: false,
5129 configurable: true
5130 });
5131 Object.defineProperty(LogicalFile.prototype, "CsvEscape", {
5132 get: function () { return this.get("CsvEscape"); },
5133 enumerable: false,
5134 configurable: true
5135 });
5136 Object.defineProperty(LogicalFile.prototype, "Modified", {
5137 get: function () { return this.get("Modified"); },
5138 enumerable: false,
5139 configurable: true
5140 });
5141 Object.defineProperty(LogicalFile.prototype, "Ecl", {
5142 get: function () { return this.get("Ecl"); },
5143 enumerable: false,
5144 configurable: true
5145 });
5146 Object.defineProperty(LogicalFile.prototype, "Stat", {
5147 get: function () { return this.get("Stat"); },
5148 enumerable: false,
5149 configurable: true
5150 });
5151 Object.defineProperty(LogicalFile.prototype, "DFUFilePartsOnClusters", {
5152 get: function () { return this.get("DFUFilePartsOnClusters"); },
5153 enumerable: false,
5154 configurable: true
5155 });
5156 Object.defineProperty(LogicalFile.prototype, "isSuperfile", {
5157 get: function () { return this.get("isSuperfile"); },
5158 enumerable: false,
5159 configurable: true
5160 });
5161 Object.defineProperty(LogicalFile.prototype, "ShowFileContent", {
5162 get: function () { return this.get("ShowFileContent"); },
5163 enumerable: false,
5164 configurable: true
5165 });
5166 Object.defineProperty(LogicalFile.prototype, "subfiles", {
5167 get: function () { return this.get("subfiles"); },
5168 enumerable: false,
5169 configurable: true
5170 });
5171 Object.defineProperty(LogicalFile.prototype, "Superfiles", {
5172 get: function () { return this.get("Superfiles"); },
5173 enumerable: false,
5174 configurable: true
5175 });
5176 Object.defineProperty(LogicalFile.prototype, "ProtectList", {
5177 get: function () { return this.get("ProtectList"); },
5178 enumerable: false,
5179 configurable: true
5180 });
5181 Object.defineProperty(LogicalFile.prototype, "FromRoxieCluster", {
5182 get: function () { return this.get("FromRoxieCluster"); },
5183 enumerable: false,
5184 configurable: true
5185 });
5186 Object.defineProperty(LogicalFile.prototype, "Graphs", {
5187 get: function () { return this.get("Graphs"); },
5188 enumerable: false,
5189 configurable: true
5190 });
5191 Object.defineProperty(LogicalFile.prototype, "UserPermission", {
5192 get: function () { return this.get("UserPermission"); },
5193 enumerable: false,
5194 configurable: true
5195 });
5196 Object.defineProperty(LogicalFile.prototype, "ContentType", {
5197 get: function () { return this.get("ContentType"); },
5198 enumerable: false,
5199 configurable: true
5200 });
5201 Object.defineProperty(LogicalFile.prototype, "CompressedFileSize", {
5202 get: function () { return this.get("CompressedFileSize"); },
5203 enumerable: false,
5204 configurable: true
5205 });
5206 Object.defineProperty(LogicalFile.prototype, "PercentCompressed", {
5207 get: function () { return this.get("PercentCompressed"); },
5208 enumerable: false,
5209 configurable: true
5210 });
5211 Object.defineProperty(LogicalFile.prototype, "IsCompressed", {
5212 get: function () { return this.get("IsCompressed"); },
5213 enumerable: false,
5214 configurable: true
5215 });
5216 Object.defineProperty(LogicalFile.prototype, "BrowseData", {
5217 get: function () { return this.get("BrowseData"); },
5218 enumerable: false,
5219 configurable: true
5220 });
5221 Object.defineProperty(LogicalFile.prototype, "jsonInfo", {
5222 get: function () { return this.get("jsonInfo"); },
5223 enumerable: false,
5224 configurable: true
5225 });
5226 Object.defineProperty(LogicalFile.prototype, "binInfo", {
5227 get: function () { return this.get("binInfo"); },
5228 enumerable: false,
5229 configurable: true
5230 });
5231 Object.defineProperty(LogicalFile.prototype, "PackageID", {
5232 get: function () { return this.get("PackageID"); },
5233 enumerable: false,
5234 configurable: true
5235 });
5236 Object.defineProperty(LogicalFile.prototype, "Partition", {
5237 get: function () { return this.get("Partition"); },
5238 enumerable: false,
5239 configurable: true
5240 });
5241 Object.defineProperty(LogicalFile.prototype, "Blooms", {
5242 get: function () { return this.get("Blooms"); },
5243 enumerable: false,
5244 configurable: true
5245 });
5246 Object.defineProperty(LogicalFile.prototype, "ExpireDays", {
5247 get: function () { return this.get("ExpireDays"); },
5248 enumerable: false,
5249 configurable: true
5250 });
5251 Object.defineProperty(LogicalFile.prototype, "KeyType", {
5252 get: function () { return this.get("KeyType"); },
5253 enumerable: false,
5254 configurable: true
5255 });
5256 Object.defineProperty(LogicalFile.prototype, "properties", {
5257 get: function () { return this.get(); },
5258 enumerable: false,
5259 configurable: true
5260 });
5261 LogicalFile.attach = function (optsConnection, Cluster, Name) {
5262 var retVal = _store.get({ BaseUrl: optsConnection.baseUrl, Cluster: Cluster, Name: Name }, function () {
5263 return new LogicalFile(optsConnection, Cluster, Name);
5264 });
5265 return retVal;
5266 };
5267 LogicalFile.prototype.fetchInfo = function () {
5268 var _this = this;
5269 return this.connection.DFUInfo({ Cluster: this.Cluster, Name: this.Name }).then(function (response) {
5270 _this.set(__assign({ Cluster: _this.Cluster }, response.FileDetail));
5271 return response.FileDetail;
5272 });
5273 };
5274 return LogicalFile;
5275 }(util.StateObject));
5276
5277 var MachineCache = /** @class */ (function (_super) {
5278 __extends(MachineCache, _super);
5279 function MachineCache() {
5280 return _super.call(this, function (obj) {
5281 return obj.Address;
5282 }) || this;
5283 }
5284 return MachineCache;
5285 }(util.Cache));
5286 var _machines = new MachineCache();
5287 var Machine = /** @class */ (function (_super) {
5288 __extends(Machine, _super);
5289 function Machine(optsConnection) {
5290 var _this = _super.call(this) || this;
5291 if (optsConnection instanceof MachineService) {
5292 _this.connection = optsConnection;
5293 }
5294 else {
5295 _this.connection = new MachineService(optsConnection);
5296 }
5297 return _this;
5298 }
5299 Object.defineProperty(Machine.prototype, "Address", {
5300 get: function () { return this.get("Address"); },
5301 enumerable: false,
5302 configurable: true
5303 });
5304 Object.defineProperty(Machine.prototype, "ConfigAddress", {
5305 get: function () { return this.get("ConfigAddress"); },
5306 enumerable: false,
5307 configurable: true
5308 });
5309 Object.defineProperty(Machine.prototype, "Name", {
5310 get: function () { return this.get("Name"); },
5311 enumerable: false,
5312 configurable: true
5313 });
5314 Object.defineProperty(Machine.prototype, "ProcessType", {
5315 get: function () { return this.get("ProcessType"); },
5316 enumerable: false,
5317 configurable: true
5318 });
5319 Object.defineProperty(Machine.prototype, "DisplayType", {
5320 get: function () { return this.get("DisplayType"); },
5321 enumerable: false,
5322 configurable: true
5323 });
5324 Object.defineProperty(Machine.prototype, "Description", {
5325 get: function () { return this.get("Description"); },
5326 enumerable: false,
5327 configurable: true
5328 });
5329 Object.defineProperty(Machine.prototype, "AgentVersion", {
5330 get: function () { return this.get("AgentVersion"); },
5331 enumerable: false,
5332 configurable: true
5333 });
5334 Object.defineProperty(Machine.prototype, "Contact", {
5335 get: function () { return this.get("Contact"); },
5336 enumerable: false,
5337 configurable: true
5338 });
5339 Object.defineProperty(Machine.prototype, "Location", {
5340 get: function () { return this.get("Location"); },
5341 enumerable: false,
5342 configurable: true
5343 });
5344 Object.defineProperty(Machine.prototype, "UpTime", {
5345 get: function () { return this.get("UpTime"); },
5346 enumerable: false,
5347 configurable: true
5348 });
5349 Object.defineProperty(Machine.prototype, "ComponentName", {
5350 get: function () { return this.get("ComponentName"); },
5351 enumerable: false,
5352 configurable: true
5353 });
5354 Object.defineProperty(Machine.prototype, "ComponentPath", {
5355 get: function () { return this.get("ComponentPath"); },
5356 enumerable: false,
5357 configurable: true
5358 });
5359 Object.defineProperty(Machine.prototype, "RoxieState", {
5360 get: function () { return this.get("RoxieState"); },
5361 enumerable: false,
5362 configurable: true
5363 });
5364 Object.defineProperty(Machine.prototype, "RoxieStateDetails", {
5365 get: function () { return this.get("RoxieStateDetails"); },
5366 enumerable: false,
5367 configurable: true
5368 });
5369 Object.defineProperty(Machine.prototype, "OS", {
5370 get: function () { return this.get("OS"); },
5371 enumerable: false,
5372 configurable: true
5373 });
5374 Object.defineProperty(Machine.prototype, "ProcessNumber", {
5375 get: function () { return this.get("ProcessNumber"); },
5376 enumerable: false,
5377 configurable: true
5378 });
5379 Object.defineProperty(Machine.prototype, "Processors", {
5380 get: function () { return this.get("Processors"); },
5381 enumerable: false,
5382 configurable: true
5383 });
5384 Object.defineProperty(Machine.prototype, "Storage", {
5385 get: function () { return this.get("Storage"); },
5386 enumerable: false,
5387 configurable: true
5388 });
5389 Object.defineProperty(Machine.prototype, "Running", {
5390 get: function () { return this.get("Running"); },
5391 enumerable: false,
5392 configurable: true
5393 });
5394 Object.defineProperty(Machine.prototype, "PhysicalMemory", {
5395 get: function () { return this.get("PhysicalMemory"); },
5396 enumerable: false,
5397 configurable: true
5398 });
5399 Object.defineProperty(Machine.prototype, "VirtualMemory", {
5400 get: function () { return this.get("VirtualMemory"); },
5401 enumerable: false,
5402 configurable: true
5403 });
5404 Object.defineProperty(Machine.prototype, "ComponentInfo", {
5405 get: function () { return this.get("ComponentInfo"); },
5406 enumerable: false,
5407 configurable: true
5408 });
5409 Machine.attach = function (optsConnection, address, state) {
5410 var retVal = _machines.get({ Address: address }, function () {
5411 return new Machine(optsConnection);
5412 });
5413 if (state) {
5414 retVal.set(state);
5415 }
5416 return retVal;
5417 };
5418 return Machine;
5419 }(util.StateObject));
5420
5421 var QueryCache = /** @class */ (function (_super) {
5422 __extends(QueryCache, _super);
5423 function QueryCache() {
5424 return _super.call(this, function (obj) {
5425 return util.Cache.hash([obj.QueryId, obj.QuerySet]);
5426 }) || this;
5427 }
5428 return QueryCache;
5429 }(util.Cache));
5430 var _queries = new QueryCache();
5431 var Query = /** @class */ (function (_super) {
5432 __extends(Query, _super);
5433 function Query(optsConnection, querySet, queryID, queryDetails) {
5434 var _this = _super.call(this) || this;
5435 if (optsConnection instanceof EclService) {
5436 _this.connection = optsConnection;
5437 // this._topology = new Topology(this.connection.opts());
5438 }
5439 else {
5440 _this.connection = new EclService(optsConnection);
5441 // this._topology = new Topology(optsConnection);
5442 }
5443 _this.set(__assign({ QuerySet: querySet, QueryId: queryID }, queryDetails));
5444 return _this;
5445 }
5446 Object.defineProperty(Query.prototype, "BaseUrl", {
5447 get: function () { return this.connection.baseUrl; },
5448 enumerable: false,
5449 configurable: true
5450 });
5451 Object.defineProperty(Query.prototype, "properties", {
5452 get: function () { return this.get(); },
5453 enumerable: false,
5454 configurable: true
5455 });
5456 Object.defineProperty(Query.prototype, "Exceptions", {
5457 get: function () { return this.get("Exceptions"); },
5458 enumerable: false,
5459 configurable: true
5460 });
5461 Object.defineProperty(Query.prototype, "QueryId", {
5462 get: function () { return this.get("QueryId"); },
5463 enumerable: false,
5464 configurable: true
5465 });
5466 Object.defineProperty(Query.prototype, "QuerySet", {
5467 get: function () { return this.get("QuerySet"); },
5468 enumerable: false,
5469 configurable: true
5470 });
5471 Object.defineProperty(Query.prototype, "QueryName", {
5472 get: function () { return this.get("QueryName"); },
5473 enumerable: false,
5474 configurable: true
5475 });
5476 Object.defineProperty(Query.prototype, "Wuid", {
5477 get: function () { return this.get("Wuid"); },
5478 enumerable: false,
5479 configurable: true
5480 });
5481 Object.defineProperty(Query.prototype, "Dll", {
5482 get: function () { return this.get("Dll"); },
5483 enumerable: false,
5484 configurable: true
5485 });
5486 Object.defineProperty(Query.prototype, "Suspended", {
5487 get: function () { return this.get("Suspended"); },
5488 enumerable: false,
5489 configurable: true
5490 });
5491 Object.defineProperty(Query.prototype, "Activated", {
5492 get: function () { return this.get("Activated"); },
5493 enumerable: false,
5494 configurable: true
5495 });
5496 Object.defineProperty(Query.prototype, "SuspendedBy", {
5497 get: function () { return this.get("SuspendedBy"); },
5498 enumerable: false,
5499 configurable: true
5500 });
5501 Object.defineProperty(Query.prototype, "Clusters", {
5502 get: function () { return this.get("Clusters"); },
5503 enumerable: false,
5504 configurable: true
5505 });
5506 Object.defineProperty(Query.prototype, "PublishedBy", {
5507 get: function () { return this.get("PublishedBy"); },
5508 enumerable: false,
5509 configurable: true
5510 });
5511 Object.defineProperty(Query.prototype, "Comment", {
5512 get: function () { return this.get("Comment"); },
5513 enumerable: false,
5514 configurable: true
5515 });
5516 Object.defineProperty(Query.prototype, "LogicalFiles", {
5517 get: function () { return this.get("LogicalFiles"); },
5518 enumerable: false,
5519 configurable: true
5520 });
5521 Object.defineProperty(Query.prototype, "SuperFiles", {
5522 get: function () { return this.get("SuperFiles"); },
5523 enumerable: false,
5524 configurable: true
5525 });
5526 Object.defineProperty(Query.prototype, "IsLibrary", {
5527 get: function () { return this.get("IsLibrary"); },
5528 enumerable: false,
5529 configurable: true
5530 });
5531 Object.defineProperty(Query.prototype, "Priority", {
5532 get: function () { return this.get("Priority"); },
5533 enumerable: false,
5534 configurable: true
5535 });
5536 Object.defineProperty(Query.prototype, "WUSnapShot", {
5537 get: function () { return this.get("WUSnapShot"); },
5538 enumerable: false,
5539 configurable: true
5540 });
5541 Object.defineProperty(Query.prototype, "CompileTime", {
5542 get: function () { return this.get("CompileTime"); },
5543 enumerable: false,
5544 configurable: true
5545 });
5546 Object.defineProperty(Query.prototype, "LibrariesUsed", {
5547 get: function () { return this.get("LibrariesUsed"); },
5548 enumerable: false,
5549 configurable: true
5550 });
5551 Object.defineProperty(Query.prototype, "CountGraphs", {
5552 get: function () { return this.get("CountGraphs"); },
5553 enumerable: false,
5554 configurable: true
5555 });
5556 Object.defineProperty(Query.prototype, "ResourceURLCount", {
5557 get: function () { return this.get("ResourceURLCount"); },
5558 enumerable: false,
5559 configurable: true
5560 });
5561 Object.defineProperty(Query.prototype, "WsEclAddresses", {
5562 get: function () { return this.get("WsEclAddresses"); },
5563 enumerable: false,
5564 configurable: true
5565 });
5566 Object.defineProperty(Query.prototype, "WUGraphs", {
5567 get: function () { return this.get("WUGraphs"); },
5568 enumerable: false,
5569 configurable: true
5570 });
5571 Object.defineProperty(Query.prototype, "WUTimers", {
5572 get: function () { return this.get("WUTimers"); },
5573 enumerable: false,
5574 configurable: true
5575 });
5576 Query.attach = function (optsConnection, querySet, queryId) {
5577 var retVal = _queries.get({ BaseUrl: optsConnection.baseUrl, QuerySet: querySet, QueryId: queryId }, function () {
5578 return new Query(optsConnection, querySet, queryId);
5579 });
5580 return retVal;
5581 };
5582 Query.prototype.fetchRequestSchema = function () {
5583 return __awaiter(this, void 0, void 0, function () {
5584 var _a;
5585 return __generator(this, function (_b) {
5586 switch (_b.label) {
5587 case 0:
5588 _a = this;
5589 return [4 /*yield*/, this.connection.requestJson(this.QuerySet, this.QueryId)];
5590 case 1:
5591 _a._requestSchema = _b.sent();
5592 return [2 /*return*/];
5593 }
5594 });
5595 });
5596 };
5597 Query.prototype.fetchResponseSchema = function () {
5598 return __awaiter(this, void 0, void 0, function () {
5599 var _a;
5600 return __generator(this, function (_b) {
5601 switch (_b.label) {
5602 case 0:
5603 _a = this;
5604 return [4 /*yield*/, this.connection.responseJson(this.QuerySet, this.QueryId)];
5605 case 1:
5606 _a._responseSchema = _b.sent();
5607 return [2 /*return*/];
5608 }
5609 });
5610 });
5611 };
5612 Query.prototype.fetchSchema = function () {
5613 return __awaiter(this, void 0, void 0, function () {
5614 return __generator(this, function (_a) {
5615 switch (_a.label) {
5616 case 0: return [4 /*yield*/, Promise.all([this.fetchRequestSchema(), this.fetchResponseSchema()])];
5617 case 1:
5618 _a.sent();
5619 return [2 /*return*/];
5620 }
5621 });
5622 });
5623 };
5624 Query.prototype.submit = function (request) {
5625 return this.connection.submit(this.QuerySet, this.QueryId, request).then(function (results) {
5626 for (var key in results) {
5627 results[key] = results[key].Row;
5628 }
5629 return results;
5630 });
5631 };
5632 Query.prototype.refresh = function () {
5633 return __awaiter(this, void 0, void 0, function () {
5634 var _this = this;
5635 return __generator(this, function (_a) {
5636 return [2 /*return*/, this.fetchSchema().then(function (schema) { return _this; })];
5637 });
5638 });
5639 };
5640 Query.prototype.requestFields = function () {
5641 if (!this._requestSchema)
5642 return [];
5643 return this._requestSchema;
5644 };
5645 Query.prototype.responseFields = function () {
5646 if (!this._responseSchema)
5647 return {};
5648 return this._responseSchema;
5649 };
5650 Query.prototype.resultNames = function () {
5651 var retVal = [];
5652 for (var key in this.responseFields()) {
5653 retVal.push(key);
5654 }
5655 return retVal;
5656 };
5657 Query.prototype.resultFields = function (resultName) {
5658 if (!this._responseSchema[resultName])
5659 return [];
5660 return this._responseSchema[resultName];
5661 };
5662 return Query;
5663 }(util.StateObject));
5664
5665 var StoreCache = /** @class */ (function (_super) {
5666 __extends(StoreCache, _super);
5667 function StoreCache() {
5668 return _super.call(this, function (obj) {
5669 return obj.BaseUrl + "-" + obj.Name + ":" + obj.UserSpecific + "-" + obj.Namespace;
5670 }) || this;
5671 }
5672 return StoreCache;
5673 }(util.Cache));
5674 var _store$1 = new StoreCache();
5675 var ValueChangedMessage = /** @class */ (function (_super) {
5676 __extends(ValueChangedMessage, _super);
5677 function ValueChangedMessage(key, value, oldValue) {
5678 var _this = _super.call(this) || this;
5679 _this.key = key;
5680 _this.value = value;
5681 _this.oldValue = oldValue;
5682 return _this;
5683 }
5684 Object.defineProperty(ValueChangedMessage.prototype, "canConflate", {
5685 get: function () { return true; },
5686 enumerable: false,
5687 configurable: true
5688 });
5689 ValueChangedMessage.prototype.conflate = function (other) {
5690 if (this.key === other.key) {
5691 this.value = other.value;
5692 return true;
5693 }
5694 return false;
5695 };
5696 ValueChangedMessage.prototype.void = function () {
5697 return this.value === this.oldValue;
5698 };
5699 return ValueChangedMessage;
5700 }(util.Message));
5701 var Store = /** @class */ (function () {
5702 function Store(optsConnection, Name, Namespace, UserSpecific) {
5703 this._dispatch = new util.Dispatch();
5704 this._knownValues = {};
5705 if (optsConnection instanceof StoreService) {
5706 this.connection = optsConnection;
5707 }
5708 else {
5709 this.connection = new StoreService(optsConnection);
5710 }
5711 this.Name = Name;
5712 this.UserSpecific = UserSpecific;
5713 this.Namespace = Namespace;
5714 }
5715 Object.defineProperty(Store.prototype, "BaseUrl", {
5716 get: function () { return this.connection.baseUrl; },
5717 enumerable: false,
5718 configurable: true
5719 });
5720 Store.attach = function (optsConnection, Name, Namespace, UserSpecific) {
5721 if (Name === void 0) { Name = "HPCCApps"; }
5722 if (UserSpecific === void 0) { UserSpecific = true; }
5723 var retVal = _store$1.get({ BaseUrl: optsConnection.baseUrl, Name: Name, UserSpecific: UserSpecific, Namespace: Namespace }, function () {
5724 return new Store(optsConnection, Name, Namespace, UserSpecific);
5725 });
5726 return retVal;
5727 };
5728 Store.prototype.create = function () {
5729 this.connection.CreateStore({ Name: this.Name, UserSpecific: this.UserSpecific, Type: "", Description: "" });
5730 };
5731 Store.prototype.set = function (key, value, broadcast) {
5732 var _this = this;
5733 if (broadcast === void 0) { broadcast = true; }
5734 return this.connection.Set({
5735 StoreName: this.Name,
5736 UserSpecific: this.UserSpecific,
5737 Namespace: this.Namespace,
5738 Key: key,
5739 Value: value
5740 }).then(function (response) {
5741 var oldValue = _this._knownValues[key];
5742 _this._knownValues[key] = value;
5743 if (broadcast) {
5744 _this._dispatch.post(new ValueChangedMessage(key, value, oldValue));
5745 }
5746 }).catch(function (e) {
5747 console.error("Store.set(\"" + key + "\", \"" + value + "\") failed:", e);
5748 });
5749 };
5750 Store.prototype.get = function (key, broadcast) {
5751 var _this = this;
5752 if (broadcast === void 0) { broadcast = true; }
5753 return this.connection.Fetch({
5754 StoreName: this.Name,
5755 UserSpecific: this.UserSpecific,
5756 Namespace: this.Namespace,
5757 Key: key
5758 }).then(function (response) {
5759 var oldValue = _this._knownValues[key];
5760 _this._knownValues[key] = response.Value;
5761 if (broadcast) {
5762 _this._dispatch.post(new ValueChangedMessage(key, response.Value, oldValue));
5763 }
5764 return response.Value;
5765 }).catch(function (e) {
5766 console.error("Store.get(" + key + ") failed:", e);
5767 return undefined;
5768 });
5769 };
5770 Store.prototype.getAll = function (broadcast) {
5771 var _this = this;
5772 if (broadcast === void 0) { broadcast = true; }
5773 return this.connection.FetchAll({
5774 StoreName: this.Name,
5775 UserSpecific: this.UserSpecific,
5776 Namespace: this.Namespace
5777 }).then(function (response) {
5778 var retVal = {};
5779 var deletedValues = _this._knownValues;
5780 _this._knownValues = {};
5781 response.Pairs.Pair.forEach(function (pair) {
5782 var oldValue = _this._knownValues[pair.Key];
5783 _this._knownValues[pair.Key] = pair.Value;
5784 delete deletedValues[pair.Key];
5785 retVal[pair.Key] = pair.Value;
5786 if (broadcast) {
5787 _this._dispatch.post(new ValueChangedMessage(pair.Key, pair.Value, oldValue));
5788 }
5789 });
5790 if (broadcast) {
5791 for (var key in deletedValues) {
5792 _this._dispatch.post(new ValueChangedMessage(key, undefined, deletedValues[key]));
5793 }
5794 }
5795 return retVal;
5796 }).catch(function (e) {
5797 console.error("Store.getAll failed:", e);
5798 return {};
5799 });
5800 };
5801 Store.prototype.delete = function (key, broadcast) {
5802 var _this = this;
5803 if (broadcast === void 0) { broadcast = true; }
5804 return this.connection.Delete({
5805 StoreName: this.Name,
5806 UserSpecific: this.UserSpecific,
5807 Namespace: this.Namespace,
5808 Key: key
5809 }).then(function (response) {
5810 var oldValue = _this._knownValues[key];
5811 delete _this._knownValues[key];
5812 if (broadcast) {
5813 _this._dispatch.post(new ValueChangedMessage(key, undefined, oldValue));
5814 }
5815 }).catch(function (e) {
5816 console.error("Store.delete(" + key + ") failed:", e);
5817 });
5818 };
5819 Store.prototype.monitor = function (callback) {
5820 return this._dispatch.attach(callback);
5821 };
5822 return Store;
5823 }());
5824
5825 var TargetClusterCache = /** @class */ (function (_super) {
5826 __extends(TargetClusterCache, _super);
5827 function TargetClusterCache() {
5828 return _super.call(this, function (obj) {
5829 return obj.BaseUrl + "-" + obj.Name;
5830 }) || this;
5831 }
5832 return TargetClusterCache;
5833 }(util.Cache));
5834 var _targetCluster = new TargetClusterCache();
5835 var TargetCluster = /** @class */ (function (_super) {
5836 __extends(TargetCluster, _super);
5837 function TargetCluster(optsConnection, name) {
5838 var _this = _super.call(this) || this;
5839 if (optsConnection instanceof TopologyService) {
5840 _this.connection = optsConnection;
5841 _this.machineConnection = new MachineService(optsConnection.connectionOptions());
5842 }
5843 else {
5844 _this.connection = new TopologyService(optsConnection);
5845 _this.machineConnection = new MachineService(optsConnection);
5846 }
5847 _this.clear({
5848 Name: name
5849 });
5850 return _this;
5851 }
5852 Object.defineProperty(TargetCluster.prototype, "BaseUrl", {
5853 get: function () { return this.connection.baseUrl; },
5854 enumerable: false,
5855 configurable: true
5856 });
5857 Object.defineProperty(TargetCluster.prototype, "Name", {
5858 get: function () { return this.get("Name"); },
5859 enumerable: false,
5860 configurable: true
5861 });
5862 Object.defineProperty(TargetCluster.prototype, "Prefix", {
5863 get: function () { return this.get("Prefix"); },
5864 enumerable: false,
5865 configurable: true
5866 });
5867 Object.defineProperty(TargetCluster.prototype, "Type", {
5868 get: function () { return this.get("Type"); },
5869 enumerable: false,
5870 configurable: true
5871 });
5872 Object.defineProperty(TargetCluster.prototype, "IsDefault", {
5873 get: function () { return this.get("IsDefault"); },
5874 enumerable: false,
5875 configurable: true
5876 });
5877 Object.defineProperty(TargetCluster.prototype, "TpClusters", {
5878 get: function () { return this.get("TpClusters"); },
5879 enumerable: false,
5880 configurable: true
5881 });
5882 Object.defineProperty(TargetCluster.prototype, "TpEclCCServers", {
5883 get: function () { return this.get("TpEclCCServers"); },
5884 enumerable: false,
5885 configurable: true
5886 });
5887 Object.defineProperty(TargetCluster.prototype, "TpEclServers", {
5888 get: function () { return this.get("TpEclServers"); },
5889 enumerable: false,
5890 configurable: true
5891 });
5892 Object.defineProperty(TargetCluster.prototype, "TpEclAgents", {
5893 get: function () { return this.get("TpEclAgents"); },
5894 enumerable: false,
5895 configurable: true
5896 });
5897 Object.defineProperty(TargetCluster.prototype, "TpEclSchedulers", {
5898 get: function () { return this.get("TpEclSchedulers"); },
5899 enumerable: false,
5900 configurable: true
5901 });
5902 Object.defineProperty(TargetCluster.prototype, "MachineInfoEx", {
5903 get: function () { return this.get("MachineInfoEx", []); },
5904 enumerable: false,
5905 configurable: true
5906 });
5907 Object.defineProperty(TargetCluster.prototype, "CMachineInfoEx", {
5908 get: function () {
5909 var _this = this;
5910 return this.MachineInfoEx.map(function (machineInfoEx) { return Machine.attach(_this.machineConnection, machineInfoEx.Address, machineInfoEx); });
5911 },
5912 enumerable: false,
5913 configurable: true
5914 });
5915 TargetCluster.attach = function (optsConnection, name, state) {
5916 var retVal = _targetCluster.get({ BaseUrl: optsConnection.baseUrl, Name: name }, function () {
5917 return new TargetCluster(optsConnection, name);
5918 });
5919 if (state) {
5920 retVal.set(__assign({}, state));
5921 }
5922 return retVal;
5923 };
5924 TargetCluster.prototype.fetchMachines = function (request) {
5925 var _this = this;
5926 if (request === void 0) { request = {}; }
5927 return this.machineConnection.GetTargetClusterInfo(__assign({ TargetClusters: {
5928 Item: [this.Type + ":" + this.Name]
5929 } }, request)).then(function (response) {
5930 var retVal = [];
5931 for (var _i = 0, _a = response.TargetClusterInfoList.TargetClusterInfo; _i < _a.length; _i++) {
5932 var machineInfo = _a[_i];
5933 for (var _b = 0, _c = machineInfo.Processes.MachineInfoEx; _b < _c.length; _b++) {
5934 var machineInfoEx = _c[_b];
5935 retVal.push(machineInfoEx);
5936 }
5937 }
5938 _this.set("MachineInfoEx", retVal);
5939 return _this.CMachineInfoEx;
5940 });
5941 };
5942 TargetCluster.prototype.machineStats = function () {
5943 var maxDisk = 0;
5944 var totalFree = 0;
5945 var total = 0;
5946 for (var _i = 0, _a = this.CMachineInfoEx; _i < _a.length; _i++) {
5947 var machine = _a[_i];
5948 for (var _b = 0, _c = machine.Storage.StorageInfo; _b < _c.length; _b++) {
5949 var storageInfo = _c[_b];
5950 totalFree += storageInfo.Available;
5951 total += storageInfo.Total;
5952 var usage = 1 - storageInfo.Available / storageInfo.Total;
5953 if (usage > maxDisk) {
5954 maxDisk = usage;
5955 }
5956 }
5957 }
5958 return {
5959 maxDisk: maxDisk,
5960 meanDisk: 1 - (total ? totalFree / total : 1)
5961 };
5962 };
5963 TargetCluster.prototype.fetchUsage = function () {
5964 return this.machineConnection.GetTargetClusterUsageEx([this.Name]);
5965 };
5966 return TargetCluster;
5967 }(util.StateObject));
5968 function targetClusters(optsConnection) {
5969 var connection;
5970 if (optsConnection instanceof TopologyService) {
5971 connection = optsConnection;
5972 }
5973 else {
5974 connection = new TopologyService(optsConnection);
5975 }
5976 return connection.TpListTargetClusters({}).then(function (response) {
5977 return response.TargetClusters.TpClusterNameType.map(function (item) { return TargetCluster.attach(optsConnection, item.Name, item); });
5978 });
5979 }
5980 var _defaultTargetCluster = {};
5981 function defaultTargetCluster(optsConnection) {
5982 if (!_defaultTargetCluster[optsConnection.baseUrl]) {
5983 var connection = void 0;
5984 if (optsConnection instanceof TopologyService) {
5985 connection = optsConnection;
5986 }
5987 else {
5988 connection = new TopologyService(optsConnection);
5989 }
5990 _defaultTargetCluster[optsConnection.baseUrl] = connection.TpListTargetClusters({}).then(function (response) {
5991 var firstItem;
5992 var defaultItem;
5993 var hthorItem;
5994 response.TargetClusters.TpClusterNameType.forEach(function (item) {
5995 if (!firstItem) {
5996 firstItem = item;
5997 }
5998 if (!defaultItem && item.IsDefault === true) {
5999 defaultItem = item;
6000 }
6001 if (!hthorItem && item.Type === "hthor") {
6002 hthorItem = item;
6003 }
6004 });
6005 var defItem = defaultItem || hthorItem || firstItem;
6006 return TargetCluster.attach(optsConnection, defItem.Name, defItem);
6007 });
6008 }
6009 return _defaultTargetCluster[optsConnection.baseUrl];
6010 }
6011
6012 var Topology = /** @class */ (function (_super) {
6013 __extends(Topology, _super);
6014 function Topology(optsConnection) {
6015 var _this = _super.call(this) || this;
6016 if (optsConnection instanceof TopologyService) {
6017 _this.connection = optsConnection;
6018 }
6019 else {
6020 _this.connection = new TopologyService(optsConnection);
6021 }
6022 return _this;
6023 }
6024 Object.defineProperty(Topology.prototype, "properties", {
6025 // Accessors ---
6026 get: function () { return this.get(); },
6027 enumerable: false,
6028 configurable: true
6029 });
6030 Object.defineProperty(Topology.prototype, "TargetClusters", {
6031 get: function () { return this.get("TargetClusters"); },
6032 enumerable: false,
6033 configurable: true
6034 });
6035 Object.defineProperty(Topology.prototype, "CTargetClusters", {
6036 get: function () {
6037 var _this = this;
6038 return this.TargetClusters.map(function (tc) { return TargetCluster.attach(_this.connection, tc.Name, tc); });
6039 },
6040 enumerable: false,
6041 configurable: true
6042 });
6043 Topology.prototype.GetESPServiceBaseURL = function (type) {
6044 var _this = this;
6045 if (type === void 0) { type = ""; }
6046 return this.connection.TpServiceQuery({}).then(function (response) {
6047 var rootProtocol = _this.connection.protocol();
6048 var ip = _this.connection.ip();
6049 var port = rootProtocol === "https:" ? "18002" : "8002";
6050 if (util.exists("ServiceList.TpEspServers.TpEspServer", response)) {
6051 for (var _i = 0, _a = response.ServiceList.TpEspServers.TpEspServer; _i < _a.length; _i++) {
6052 var item = _a[_i];
6053 if (util.exists("TpBindings.TpBinding", item)) {
6054 for (var _b = 0, _c = item.TpBindings.TpBinding; _b < _c.length; _b++) {
6055 var binding = _c[_b];
6056 if (binding.Service === type && binding.Protocol + ":" === rootProtocol) {
6057 port = binding.Port;
6058 }
6059 }
6060 }
6061 }
6062 }
6063 return rootProtocol + "//" + ip + ":" + port + "/";
6064 });
6065 };
6066 Topology.prototype.fetchTargetClusters = function () {
6067 var _this = this;
6068 return this.connection.TpTargetClusterQuery({ Type: "ROOT" }).then(function (response) {
6069 _this.set({
6070 TargetClusters: response.TpTargetClusters.TpTargetCluster
6071 });
6072 return _this.CTargetClusters;
6073 });
6074 };
6075 Topology.prototype.refresh = function () {
6076 return __awaiter(this, void 0, void 0, function () {
6077 return __generator(this, function (_a) {
6078 switch (_a.label) {
6079 case 0: return [4 /*yield*/, this.fetchTargetClusters()];
6080 case 1:
6081 _a.sent();
6082 return [2 /*return*/, this];
6083 }
6084 });
6085 });
6086 };
6087 // Monitoring ---
6088 // Events ---
6089 Topology.prototype.on = function (eventID, propIDorCallback, callback) {
6090 if (this.isCallback(propIDorCallback)) {
6091 switch (eventID) {
6092 case "changed":
6093 _super.prototype.on.call(this, eventID, propIDorCallback);
6094 break;
6095 }
6096 }
6097 else {
6098 switch (eventID) {
6099 case "changed":
6100 _super.prototype.on.call(this, eventID, propIDorCallback, callback);
6101 break;
6102 }
6103 }
6104 this._monitor();
6105 return this;
6106 };
6107 return Topology;
6108 }(util.StateObject));
6109
6110 exports.AccountService = AccountService;
6111 exports.Activity = Activity;
6112 exports.Attribute = Attribute;
6113 exports.BUILD_VERSION = BUILD_VERSION;
6114 exports.BaseScope = BaseScope;
6115 exports.Connection = Connection;
6116 exports.DFUService = DFUService;
6117 exports.ECLGraph = ECLGraph;
6118 exports.ESPConnection = ESPConnection;
6119 exports.ESPExceptions = ESPExceptions;
6120 exports.EclService = EclService;
6121 exports.GlobalResultCache = GlobalResultCache;
6122 exports.GraphCache = GraphCache;
6123 exports.LogicalFile = LogicalFile;
6124 exports.LogicalFileCache = LogicalFileCache;
6125 exports.Machine = Machine;
6126 exports.MachineCache = MachineCache;
6127 exports.MachineService = MachineService;
6128 exports.PKG_NAME = PKG_NAME;
6129 exports.PKG_VERSION = PKG_VERSION;
6130 exports.Query = Query;
6131 exports.Resource = Resource;
6132 exports.Result = Result;
6133 exports.ResultCache = ResultCache;
6134 exports.SMCService = SMCService;
6135 exports.Scope = Scope;
6136 exports.ScopeEdge = ScopeEdge;
6137 exports.ScopeGraph = ScopeGraph;
6138 exports.ScopeSubgraph = ScopeSubgraph;
6139 exports.ScopeVertex = ScopeVertex;
6140 exports.Service = Service;
6141 exports.SourceFile = SourceFile;
6142 exports.Store = Store;
6143 exports.StoreCache = StoreCache;
6144 exports.StoreService = StoreService;
6145 exports.TargetCluster = TargetCluster;
6146 exports.TargetClusterCache = TargetClusterCache;
6147 exports.Timer = Timer;
6148 exports.Topology = Topology;
6149 exports.TopologyService = TopologyService;
6150 exports.ValueChangedMessage = ValueChangedMessage;
6151 exports.Workunit = Workunit;
6152 exports.WorkunitCache = WorkunitCache;
6153 exports.WorkunitsService = WorkunitsService;
6154 exports.XGMMLEdge = XGMMLEdge;
6155 exports.XGMMLGraph = XGMMLGraph;
6156 exports.XGMMLSubgraph = XGMMLSubgraph;
6157 exports.XGMMLVertex = XGMMLVertex;
6158 exports.XSDNode = XSDNode;
6159 exports.XSDSchema = XSDSchema;
6160 exports.XSDSimpleType = XSDSimpleType;
6161 exports.XSDXMLNode = XSDXMLNode;
6162 exports.createGraph = createGraph;
6163 exports.createXGMMLGraph = createXGMMLGraph;
6164 exports.defaultTargetCluster = defaultTargetCluster;
6165 exports.deserializeResponse = deserializeResponse;
6166 exports.get = get;
6167 exports.hookSend = hookSend;
6168 exports.instanceOfIConnection = instanceOfIConnection;
6169 exports.instanceOfIOptions = instanceOfIOptions;
6170 exports.isArray = isArray;
6171 exports.isWUInfoWorkunit = isWUInfoWorkunit;
6172 exports.isWUQueryECLWorkunit = isWUQueryECLWorkunit;
6173 exports.jsonp = jsonp;
6174 exports.parseXSD = parseXSD;
6175 exports.parseXSD2 = parseXSD2;
6176 exports.post = post;
6177 exports.send = send;
6178 exports.serializeRequest = serializeRequest;
6179 exports.setTransportFactory = setTransportFactory;
6180 exports.targetClusters = targetClusters;
6181
6182 Object.defineProperty(exports, '__esModule', { value: true });
6183
6184})));
6185//# sourceMappingURL=index.js.map