UNPKG

@hpcc-js/comms

Version:
243 lines 9.19 kB
import * as tslib_1 from "tslib"; import { Cache, StateObject } from "@hpcc-js/util"; import { EclService } from "../services/wsEcl"; var QueryCache = /** @class */ (function (_super) { tslib_1.__extends(QueryCache, _super); function QueryCache() { return _super.call(this, function (obj) { return Cache.hash([obj.QueryId, obj.QuerySet]); }) || this; } return QueryCache; }(Cache)); var _queries = new QueryCache(); var Query = /** @class */ (function (_super) { tslib_1.__extends(Query, _super); function Query(optsConnection, querySet, queryID, queryDetails) { var _this = _super.call(this) || this; if (optsConnection instanceof EclService) { _this.connection = optsConnection; // this._topology = new Topology(this.connection.opts()); } else { _this.connection = new EclService(optsConnection); // this._topology = new Topology(optsConnection); } _this.set(tslib_1.__assign({ QuerySet: querySet, QueryId: queryID }, queryDetails)); return _this; } Object.defineProperty(Query.prototype, "properties", { get: function () { return this.get(); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Exceptions", { get: function () { return this.get("Exceptions"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "QueryId", { get: function () { return this.get("QueryId"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "QuerySet", { get: function () { return this.get("QuerySet"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "QueryName", { get: function () { return this.get("QueryName"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Wuid", { get: function () { return this.get("Wuid"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Dll", { get: function () { return this.get("Dll"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Suspended", { get: function () { return this.get("Suspended"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Activated", { get: function () { return this.get("Activated"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "SuspendedBy", { get: function () { return this.get("SuspendedBy"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Clusters", { get: function () { return this.get("Clusters"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "PublishedBy", { get: function () { return this.get("PublishedBy"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Comment", { get: function () { return this.get("Comment"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "LogicalFiles", { get: function () { return this.get("LogicalFiles"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "SuperFiles", { get: function () { return this.get("SuperFiles"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "IsLibrary", { get: function () { return this.get("IsLibrary"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "Priority", { get: function () { return this.get("Priority"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "WUSnapShot", { get: function () { return this.get("WUSnapShot"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "CompileTime", { get: function () { return this.get("CompileTime"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "LibrariesUsed", { get: function () { return this.get("LibrariesUsed"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "CountGraphs", { get: function () { return this.get("CountGraphs"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "ResourceURLCount", { get: function () { return this.get("ResourceURLCount"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "WsEclAddresses", { get: function () { return this.get("WsEclAddresses"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "WUGraphs", { get: function () { return this.get("WUGraphs"); }, enumerable: true, configurable: true }); Object.defineProperty(Query.prototype, "WUTimers", { get: function () { return this.get("WUTimers"); }, enumerable: true, configurable: true }); Query.attach = function (optsConnection, querySet, queryId) { var retVal = _queries.get({ QuerySet: querySet, QueryId: queryId }, function () { return new Query(optsConnection, querySet, queryId); }); return retVal; }; Query.prototype.fetchRequestSchema = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var _a; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: _a = this; return [4 /*yield*/, this.connection.requestJson(this.QuerySet, this.QueryId)]; case 1: _a._requestSchema = _b.sent(); return [2 /*return*/]; } }); }); }; Query.prototype.fetchResponseSchema = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var _a; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: _a = this; return [4 /*yield*/, this.connection.responseJson(this.QuerySet, this.QueryId)]; case 1: _a._responseSchema = _b.sent(); return [2 /*return*/]; } }); }); }; Query.prototype.fetchSchema = 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*/, Promise.all([this.fetchRequestSchema(), this.fetchResponseSchema()])]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; Query.prototype.submit = function (request) { return this.connection.submit(this.QuerySet, this.QueryId, request).then(function (results) { for (var key in results) { results[key] = results[key].Row; } return results; }); }; Query.prototype.refresh = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var _this = this; return tslib_1.__generator(this, function (_a) { return [2 /*return*/, this.fetchSchema().then(function (schema) { return _this; })]; }); }); }; Query.prototype.requestFields = function () { if (!this._requestSchema) return []; return this._requestSchema; }; Query.prototype.responseFields = function () { if (!this._responseSchema) return {}; return this._responseSchema; }; Query.prototype.resultNames = function () { var retVal = []; for (var key in this.responseFields()) { retVal.push(key); } return retVal; }; Query.prototype.resultFields = function (resultName) { if (!this._responseSchema[resultName]) return []; return this._responseSchema[resultName]; }; return Query; }(StateObject)); export { Query }; //# sourceMappingURL=query.js.map