@hpcc-js/comms
Version:
hpcc-js - Communications
257 lines • 9.74 kB
JavaScript
import * as tslib_1 from "tslib";
import { Cache, exists, StateObject } from "@hpcc-js/util";
import { WorkunitsService } from "../services/wsWorkunits";
import { parseXSD } from "./xsdParser";
var GlobalResultCache = /** @class */ (function (_super) {
tslib_1.__extends(GlobalResultCache, _super);
function GlobalResultCache() {
return _super.call(this, function (obj) {
return obj.Wuid + "/" + obj.ResultName;
}) || this;
}
return GlobalResultCache;
}(Cache));
export { GlobalResultCache };
var _results = new GlobalResultCache();
var Result = /** @class */ (function (_super) {
tslib_1.__extends(Result, _super);
function Result(optsConnection, wuidOrLogicalFile, eclResultOrResultName, resultViews) {
if (resultViews === void 0) { resultViews = []; }
var _this = _super.call(this) || this;
if (optsConnection instanceof WorkunitsService) {
_this.connection = optsConnection;
}
else {
_this.connection = new WorkunitsService(optsConnection);
}
if (typeof eclResultOrResultName === "undefined") {
_this.set({
LogicalFileName: wuidOrLogicalFile
});
}
else if (typeof eclResultOrResultName === "string") {
_this.set({
Wuid: wuidOrLogicalFile,
ResultName: eclResultOrResultName,
ResultViews: resultViews
});
}
else if (typeof eclResultOrResultName === "number") {
_this.set({
Wuid: wuidOrLogicalFile,
ResultSequence: eclResultOrResultName,
ResultViews: resultViews
});
}
else {
_this.set(tslib_1.__assign({ Wuid: wuidOrLogicalFile, ResultName: eclResultOrResultName.Name, ResultViews: resultViews }, eclResultOrResultName));
}
return _this;
}
Object.defineProperty(Result.prototype, "properties", {
get: function () { return this.get(); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Wuid", {
get: function () { return this.get("Wuid"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultName", {
get: function () { return this.get("ResultName"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultSequence", {
get: function () { return this.get("ResultSequence"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "LogicalFileName", {
get: function () { return this.get("LogicalFileName"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Name", {
get: function () { return this.get("Name"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Sequence", {
get: function () { return this.get("Sequence"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Value", {
get: function () { return this.get("Value"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Link", {
get: function () { return this.get("Link"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "FileName", {
get: function () { return this.get("FileName"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "IsSupplied", {
get: function () { return this.get("IsSupplied"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "ShowFileContent", {
get: function () { return this.get("ShowFileContent"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "Total", {
get: function () { return this.get("Total"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "ECLSchemas", {
get: function () { return this.get("ECLSchemas"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "NodeGroup", {
get: function () { return this.get("NodeGroup"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "ResultViews", {
get: function () { return this.get("ResultViews"); },
enumerable: true,
configurable: true
});
Object.defineProperty(Result.prototype, "XmlSchema", {
get: function () { return this.get("XmlSchema"); },
enumerable: true,
configurable: true
});
Result.attach = function (optsConnection, wuid, resultName, state) {
var retVal = _results.get({ Wuid: wuid, ResultName: resultName }, function () {
return new Result(optsConnection, wuid, resultName);
});
if (state) {
retVal.set(state);
}
return retVal;
};
Result.prototype.isComplete = function () {
return this.Total !== -1;
};
Result.prototype.fetchXMLSchema = function () {
var _this = this;
if (this.xsdSchema) {
return Promise.resolve(this.xsdSchema);
}
return this.WUResult().then(function (response) {
if (exists("Result.XmlSchema.xml", response)) {
_this.xsdSchema = parseXSD(response.Result.XmlSchema.xml);
return _this.xsdSchema;
}
return null;
});
};
Result.prototype.refresh = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__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) {
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).then(function (response) {
var result = response.Result;
delete response.Result; // Do not want it in "set"
_this.set(tslib_1.__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) {
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).then(function (response) {
return response;
});
};
return Result;
}(StateObject));
export { Result };
var ResultCache = /** @class */ (function (_super) {
tslib_1.__extends(ResultCache, _super);
function ResultCache() {
return _super.call(this, function (obj) {
return Cache.hash([obj.Sequence, obj.Name, obj.FileName]);
}) || this;
}
return ResultCache;
}(Cache));
export { ResultCache };
//# sourceMappingURL=result.js.map