@hpcc-js/comms
Version:
hpcc-js - Communications
288 lines • 11.7 kB
JavaScript
import { __assign, __awaiter, __extends, __generator } from "tslib";
import { Cache, exists, StateObject } from "@hpcc-js/util";
import { isECLResult, WorkunitsService } from "../services/wsWorkunits";
import { parseXSD } from "./xsdParser";
var GlobalResultCache = /** @class */ (function (_super) {
__extends(GlobalResultCache, _super);
function GlobalResultCache() {
return _super.call(this, function (obj) {
return "".concat(obj.BaseUrl, "-").concat(obj.Wuid, "-").concat(obj.ResultName);
}) || this;
}
return GlobalResultCache;
}(Cache));
export { GlobalResultCache };
var _results = new GlobalResultCache();
var Result = /** @class */ (function (_super) {
__extends(Result, _super);
function Result(optsConnection, wuid_NodeGroup, name_sequence_eclResult_logicalFile, resultViews_isLogicalFile) {
var _this = _super.call(this) || this;
if (optsConnection instanceof WorkunitsService) {
_this.connection = optsConnection;
}
else {
_this.connection = new WorkunitsService(optsConnection);
}
if (typeof resultViews_isLogicalFile === "boolean" && resultViews_isLogicalFile === true) {
_this.set({
NodeGroup: wuid_NodeGroup,
LogicalFileName: name_sequence_eclResult_logicalFile
});
}
else if (isECLResult(name_sequence_eclResult_logicalFile) && Array.isArray(resultViews_isLogicalFile)) {
_this.set(__assign(__assign({}, name_sequence_eclResult_logicalFile), { Wuid: wuid_NodeGroup, ResultName: name_sequence_eclResult_logicalFile.Name, ResultViews: resultViews_isLogicalFile }));
}
else if (typeof resultViews_isLogicalFile === "undefined") {
if (typeof name_sequence_eclResult_logicalFile === "number") {
_this.set({
Wuid: wuid_NodeGroup,
ResultSequence: name_sequence_eclResult_logicalFile
});
}
else if (typeof name_sequence_eclResult_logicalFile === "string") {
_this.set({
Wuid: wuid_NodeGroup,
ResultName: name_sequence_eclResult_logicalFile
});
}
else {
console.warn("Unknown Result.attach (1)");
}
}
else {
console.warn("Unknown Result.attach (2)");
}
return _this;
}
Object.defineProperty(Result.prototype, "BaseUrl", {
get: function () { return this.connection.baseUrl; },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "properties", {
get: function () { return this.get(); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Wuid", {
get: function () { return this.get("Wuid"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultName", {
get: function () { return this.get("ResultName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultSequence", {
get: function () { return this.get("ResultSequence"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "LogicalFileName", {
get: function () { return this.get("LogicalFileName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Name", {
get: function () { return this.get("Name"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Sequence", {
get: function () { return this.get("Sequence"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Value", {
get: function () { return this.get("Value"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Link", {
get: function () { return this.get("Link"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "FileName", {
get: function () { return this.get("FileName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "IsSupplied", {
get: function () { return this.get("IsSupplied"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "ShowFileContent", {
get: function () { return this.get("ShowFileContent"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "Total", {
get: function () { return this.get("Total"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "ECLSchemas", {
get: function () { return this.get("ECLSchemas"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "NodeGroup", {
get: function () { return this.get("NodeGroup"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultViews", {
get: function () { return this.get("ResultViews"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Result.prototype, "XmlSchema", {
get: function () { return this.get("XmlSchema"); },
enumerable: false,
configurable: true
});
Result.attach = function (optsConnection, wuid, name_sequence_eclResult, resultViews) {
var retVal;
if (Array.isArray(resultViews)) {
retVal = _results.get({ BaseUrl: optsConnection.baseUrl, Wuid: wuid, ResultName: name_sequence_eclResult.Name }, function () {
return new Result(optsConnection, wuid, name_sequence_eclResult, resultViews);
});
retVal.set(name_sequence_eclResult);
}
else if (typeof resultViews === "undefined") {
if (typeof name_sequence_eclResult === "number") {
retVal = _results.get({ BaseUrl: optsConnection.baseUrl, Wuid: wuid, ResultName: "Sequence_" + name_sequence_eclResult }, function () {
return new Result(optsConnection, wuid, name_sequence_eclResult);
});
}
else if (typeof name_sequence_eclResult === "string") {
retVal = _results.get({ BaseUrl: optsConnection.baseUrl, Wuid: wuid, ResultName: name_sequence_eclResult }, function () {
return new Result(optsConnection, wuid, name_sequence_eclResult);
});
}
}
return retVal;
};
Result.attachLogicalFile = function (optsConnection, nodeGroup, logicalFile) {
return _results.get({ BaseUrl: optsConnection.baseUrl, Wuid: nodeGroup, ResultName: logicalFile }, function () {
return new Result(optsConnection, nodeGroup, logicalFile, true);
});
};
Result.prototype.isComplete = function () {
return this.Total !== -1;
};
Result.prototype.fetchXMLSchema = function (refresh) {
var _this = this;
if (refresh === void 0) { refresh = false; }
if (!this._fetchXMLSchemaPromise || refresh) {
this._fetchXMLSchemaPromise = this.WUResult().then(function (response) {
var _a, _b;
if ((_b = (_a = response.Result) === null || _a === void 0 ? void 0 : _a.XmlSchema) === null || _b === void 0 ? void 0 : _b.xml) {
_this.xsdSchema = parseXSD(response.Result.XmlSchema.xml);
return _this.xsdSchema;
}
return null;
});
}
return this._fetchXMLSchemaPromise;
};
Result.prototype.refresh = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchRows(0, 1, true)];
case 1:
_a.sent();
return [2 /*return*/, this];
}
});
});
};
Result.prototype.fetchRows = function (from, count, includeSchema, filter, abortSignal) {
var _this = this;
if (from === void 0) { from = 0; }
if (count === void 0) { count = -1; }
if (includeSchema === void 0) { includeSchema = false; }
if (filter === void 0) { filter = {}; }
return this.WUResult(from, count, !includeSchema, filter, abortSignal).then(function (response) {
var result = response.Result;
delete response.Result; // Do not want it in "set"
_this.set(__assign({}, response));
if (exists("XmlSchema.xml", result)) {
_this.xsdSchema = parseXSD(result.XmlSchema.xml);
}
if (exists("Row", result)) {
return result.Row;
}
else if (_this.ResultName && exists(_this.ResultName, result)) {
return result[_this.ResultName].Row;
}
return [];
});
};
Result.prototype.rootField = function () {
if (!this.xsdSchema)
return null;
return this.xsdSchema.root;
};
Result.prototype.fields = function () {
if (!this.xsdSchema)
return [];
return this.xsdSchema.root.children();
};
Result.prototype.WUResult = function (start, count, suppressXmlSchema, filter, abortSignal) {
if (start === void 0) { start = 0; }
if (count === void 0) { count = 1; }
if (suppressXmlSchema === void 0) { suppressXmlSchema = false; }
if (filter === void 0) { filter = {}; }
var FilterBy = {
NamedValue: {
itemcount: 0
}
};
for (var key in filter) {
FilterBy.NamedValue[FilterBy.NamedValue.itemcount++] = {
Name: key,
Value: filter[key]
};
}
var request = { FilterBy: FilterBy };
if (this.Wuid && this.ResultName !== undefined) {
request.Wuid = this.Wuid;
request.ResultName = this.ResultName;
}
else if (this.Wuid && this.ResultSequence !== undefined) {
request.Wuid = this.Wuid;
request.Sequence = this.ResultSequence;
}
else if (this.LogicalFileName && this.NodeGroup) {
request.LogicalName = this.LogicalFileName;
request.Cluster = this.NodeGroup;
}
else if (this.LogicalFileName) {
request.LogicalName = this.LogicalFileName;
}
request.Start = start;
request.Count = count;
request.SuppressXmlSchema = suppressXmlSchema;
return this.connection.WUResult(request, abortSignal).then(function (response) {
return response;
});
};
return Result;
}(StateObject));
export { Result };
var ResultCache = /** @class */ (function (_super) {
__extends(ResultCache, _super);
function ResultCache() {
return _super.call(this, function (obj) {
return Cache.hash([obj.Sequence, obj.Name, obj.Value, obj.FileName]);
}) || this;
}
return ResultCache;
}(Cache));
export { ResultCache };
//# sourceMappingURL=result.js.map