@qrunio/qqq-frontend-core 1.0.128-SNAPSHOT

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/LICENSE +619 -0
  2. package/README.md +35 -0
  3. package/lib/controllers/QController.d.ts +217 -0
  4. package/lib/controllers/QController.js +1026 -0
  5. package/lib/controllers/QController.js.map +1 -0
  6. package/lib/controllers/QControllerV1.d.ts +213 -0
  7. package/lib/controllers/QControllerV1.js +992 -0
  8. package/lib/controllers/QControllerV1.js.map +1 -0
  9. package/lib/exceptions/QException.d.ts +12 -0
  10. package/lib/exceptions/QException.js +54 -0
  11. package/lib/exceptions/QException.js.map +1 -0
  12. package/lib/model/QPossibleValue.d.ts +9 -0
  13. package/lib/model/QPossibleValue.js +33 -0
  14. package/lib/model/QPossibleValue.js.map +1 -0
  15. package/lib/model/QRecord.d.ts +14 -0
  16. package/lib/model/QRecord.js +64 -0
  17. package/lib/model/QRecord.js.map +1 -0
  18. package/lib/model/metaData/AdornmentType.d.ts +16 -0
  19. package/lib/model/metaData/AdornmentType.js +41 -0
  20. package/lib/model/metaData/AdornmentType.js.map +1 -0
  21. package/lib/model/metaData/Banner.d.ts +15 -0
  22. package/lib/model/metaData/Banner.js +37 -0
  23. package/lib/model/metaData/Banner.js.map +1 -0
  24. package/lib/model/metaData/Capability.d.ts +12 -0
  25. package/lib/model/metaData/Capability.js +37 -0
  26. package/lib/model/metaData/Capability.js.map +1 -0
  27. package/lib/model/metaData/FieldAdornment.d.ts +11 -0
  28. package/lib/model/metaData/FieldAdornment.js +44 -0
  29. package/lib/model/metaData/FieldAdornment.js.map +1 -0
  30. package/lib/model/metaData/ProcessMetaDataAdjustment.d.ts +11 -0
  31. package/lib/model/metaData/ProcessMetaDataAdjustment.js +45 -0
  32. package/lib/model/metaData/ProcessMetaDataAdjustment.js.map +1 -0
  33. package/lib/model/metaData/QAppMetaData.d.ts +17 -0
  34. package/lib/model/metaData/QAppMetaData.js +57 -0
  35. package/lib/model/metaData/QAppMetaData.js.map +1 -0
  36. package/lib/model/metaData/QAppNodeType.d.ts +10 -0
  37. package/lib/model/metaData/QAppNodeType.js +32 -0
  38. package/lib/model/metaData/QAppNodeType.js.map +1 -0
  39. package/lib/model/metaData/QAppSection.d.ts +14 -0
  40. package/lib/model/metaData/QAppSection.js +46 -0
  41. package/lib/model/metaData/QAppSection.js.map +1 -0
  42. package/lib/model/metaData/QAppTreeNode.d.ts +16 -0
  43. package/lib/model/metaData/QAppTreeNode.js +46 -0
  44. package/lib/model/metaData/QAppTreeNode.js.map +1 -0
  45. package/lib/model/metaData/QAuthenticationMetaData.d.ts +10 -0
  46. package/lib/model/metaData/QAuthenticationMetaData.js +44 -0
  47. package/lib/model/metaData/QAuthenticationMetaData.js.map +1 -0
  48. package/lib/model/metaData/QBrandingMetaData.d.ts +17 -0
  49. package/lib/model/metaData/QBrandingMetaData.js +46 -0
  50. package/lib/model/metaData/QBrandingMetaData.js.map +1 -0
  51. package/lib/model/metaData/QComponentType.d.ts +20 -0
  52. package/lib/model/metaData/QComponentType.js +45 -0
  53. package/lib/model/metaData/QComponentType.js.map +1 -0
  54. package/lib/model/metaData/QExposedJoin.d.ts +14 -0
  55. package/lib/model/metaData/QExposedJoin.js +41 -0
  56. package/lib/model/metaData/QExposedJoin.js.map +1 -0
  57. package/lib/model/metaData/QFieldMetaData.d.ts +42 -0
  58. package/lib/model/metaData/QFieldMetaData.js +98 -0
  59. package/lib/model/metaData/QFieldMetaData.js.map +1 -0
  60. package/lib/model/metaData/QFieldType.d.ts +18 -0
  61. package/lib/model/metaData/QFieldType.js +43 -0
  62. package/lib/model/metaData/QFieldType.js.map +1 -0
  63. package/lib/model/metaData/QFrontendComponent.d.ts +10 -0
  64. package/lib/model/metaData/QFrontendComponent.js +35 -0
  65. package/lib/model/metaData/QFrontendComponent.js.map +1 -0
  66. package/lib/model/metaData/QFrontendStepMetaData.d.ts +18 -0
  67. package/lib/model/metaData/QFrontendStepMetaData.js +62 -0
  68. package/lib/model/metaData/QFrontendStepMetaData.js.map +1 -0
  69. package/lib/model/metaData/QHelpContent.d.ts +23 -0
  70. package/lib/model/metaData/QHelpContent.js +82 -0
  71. package/lib/model/metaData/QHelpContent.js.map +1 -0
  72. package/lib/model/metaData/QIcon.d.ts +10 -0
  73. package/lib/model/metaData/QIcon.js +34 -0
  74. package/lib/model/metaData/QIcon.js.map +1 -0
  75. package/lib/model/metaData/QInstance.d.ts +41 -0
  76. package/lib/model/metaData/QInstance.js +145 -0
  77. package/lib/model/metaData/QInstance.js.map +1 -0
  78. package/lib/model/metaData/QJoinMetaData.d.ts +11 -0
  79. package/lib/model/metaData/QJoinMetaData.js +35 -0
  80. package/lib/model/metaData/QJoinMetaData.js.map +1 -0
  81. package/lib/model/metaData/QProcessMetaData.d.ts +18 -0
  82. package/lib/model/metaData/QProcessMetaData.js +52 -0
  83. package/lib/model/metaData/QProcessMetaData.js.map +1 -0
  84. package/lib/model/metaData/QReportMetaData.d.ts +13 -0
  85. package/lib/model/metaData/QReportMetaData.js +38 -0
  86. package/lib/model/metaData/QReportMetaData.js.map +1 -0
  87. package/lib/model/metaData/QTableMetaData.d.ts +29 -0
  88. package/lib/model/metaData/QTableMetaData.js +85 -0
  89. package/lib/model/metaData/QTableMetaData.js.map +1 -0
  90. package/lib/model/metaData/QTableSection.d.ts +20 -0
  91. package/lib/model/metaData/QTableSection.js +46 -0
  92. package/lib/model/metaData/QTableSection.js.map +1 -0
  93. package/lib/model/metaData/QTableVariant.d.ts +10 -0
  94. package/lib/model/metaData/QTableVariant.js +34 -0
  95. package/lib/model/metaData/QTableVariant.js.map +1 -0
  96. package/lib/model/metaData/QWidgetMetaData.d.ts +32 -0
  97. package/lib/model/metaData/QWidgetMetaData.js +63 -0
  98. package/lib/model/metaData/QWidgetMetaData.js.map +1 -0
  99. package/lib/model/processes/QJobComplete.d.ts +15 -0
  100. package/lib/model/processes/QJobComplete.js +39 -0
  101. package/lib/model/processes/QJobComplete.js.map +1 -0
  102. package/lib/model/processes/QJobError.d.ts +10 -0
  103. package/lib/model/processes/QJobError.js +34 -0
  104. package/lib/model/processes/QJobError.js.map +1 -0
  105. package/lib/model/processes/QJobRunning.d.ts +11 -0
  106. package/lib/model/processes/QJobRunning.js +35 -0
  107. package/lib/model/processes/QJobRunning.js.map +1 -0
  108. package/lib/model/processes/QJobStarted.d.ts +9 -0
  109. package/lib/model/processes/QJobStarted.js +33 -0
  110. package/lib/model/processes/QJobStarted.js.map +1 -0
  111. package/lib/model/query/FilterVariableExpression.d.ts +11 -0
  112. package/lib/model/query/FilterVariableExpression.js +37 -0
  113. package/lib/model/query/FilterVariableExpression.js.map +1 -0
  114. package/lib/model/query/NowExpression.d.ts +9 -0
  115. package/lib/model/query/NowExpression.js +35 -0
  116. package/lib/model/query/NowExpression.js.map +1 -0
  117. package/lib/model/query/NowWithOffsetExpression.d.ts +14 -0
  118. package/lib/model/query/NowWithOffsetExpression.js +43 -0
  119. package/lib/model/query/NowWithOffsetExpression.js.map +1 -0
  120. package/lib/model/query/QCriteriaOperator.d.ts +25 -0
  121. package/lib/model/query/QCriteriaOperator.js +47 -0
  122. package/lib/model/query/QCriteriaOperator.js.map +1 -0
  123. package/lib/model/query/QFilterCriteria.d.ts +12 -0
  124. package/lib/model/query/QFilterCriteria.js +34 -0
  125. package/lib/model/query/QFilterCriteria.js.map +1 -0
  126. package/lib/model/query/QFilterOrderBy.d.ts +9 -0
  127. package/lib/model/query/QFilterOrderBy.js +33 -0
  128. package/lib/model/query/QFilterOrderBy.js.map +1 -0
  129. package/lib/model/query/QQueryFilter.d.ts +26 -0
  130. package/lib/model/query/QQueryFilter.js +86 -0
  131. package/lib/model/query/QQueryFilter.js.map +1 -0
  132. package/lib/model/query/QueryJoin.d.ts +13 -0
  133. package/lib/model/query/QueryJoin.js +42 -0
  134. package/lib/model/query/QueryJoin.js.map +1 -0
  135. package/lib/model/query/ThisOrLastPeriodExpression.d.ts +13 -0
  136. package/lib/model/query/ThisOrLastPeriodExpression.js +43 -0
  137. package/lib/model/query/ThisOrLastPeriodExpression.js.map +1 -0
  138. package/lib/qqq-frontend-core.d.ts +1 -0
  139. package/lib/qqq-frontend-core.js +31 -0
  140. package/lib/qqq-frontend-core.js.map +1 -0
  141. package/package.json +51 -0
@@ -0,0 +1,992 @@
1
+ /*
2
+ * QQQ - Low-code Application Framework for Engineers.
3
+ * Copyright (C) 2021-2022. Kingsrook, LLC
4
+ * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
5
+ * contact@kingsrook.com
6
+ * https://github.com/Kingsrook/
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ var __assign = (this && this.__assign) || function () {
22
+ __assign = Object.assign || function(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
26
+ t[p] = s[p];
27
+ }
28
+ return t;
29
+ };
30
+ return __assign.apply(this, arguments);
31
+ };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
48
+ 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;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ import { AxiosError } from "axios";
69
+ import FormData from "form-data";
70
+ import { QException } from "../exceptions/QException";
71
+ import { QAuthenticationMetaData } from "../model/metaData/QAuthenticationMetaData";
72
+ import { QInstance } from "../model/metaData/QInstance";
73
+ import { QProcessMetaData } from "../model/metaData/QProcessMetaData";
74
+ import { QTableMetaData } from "../model/metaData/QTableMetaData";
75
+ import { QTableVariant } from "../model/metaData/QTableVariant";
76
+ import { QJobComplete } from "../model/processes/QJobComplete";
77
+ import { QJobError } from "../model/processes/QJobError";
78
+ import { QJobRunning } from "../model/processes/QJobRunning";
79
+ import { QJobStarted } from "../model/processes/QJobStarted";
80
+ import { QPossibleValue } from "../model/QPossibleValue";
81
+ import { QRecord } from "../model/QRecord";
82
+ var axios = require("axios").default;
83
+ /*******************************************************************************
84
+ ** Controller for interacting with a QQQ backend going through Middleware V1.
85
+ *******************************************************************************/
86
+ var QControllerV1 = /** @class */ (function () {
87
+ /*******************************************************************************
88
+ **
89
+ *******************************************************************************/
90
+ function QControllerV1(baseUrl, exceptionHandler) {
91
+ this.axiosInstance = axios.create({
92
+ baseURL: baseUrl,
93
+ timeout: 60000, // todo - evaluate this!
94
+ });
95
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
96
+ // create a promise which will run a busy-loop until setAuthorizationHeaderValue is called. //
97
+ // the idea being, to not fire off any other requests until we know that the user is authenticated, //
98
+ // and we know how to send that authentication to the backend. //
99
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
100
+ QControllerV1.awaitAuthenticationPromise = new Promise(function (resolve) {
101
+ var interval = setInterval(function () {
102
+ if (QControllerV1.gotAuthentication) {
103
+ resolve(true);
104
+ clearInterval(interval);
105
+ }
106
+ }, 50);
107
+ });
108
+ try {
109
+ this.axiosInstance.defaults.headers.common["X-QQQ-UserTimezone"] = Intl.DateTimeFormat().resolvedOptions().timeZone;
110
+ }
111
+ catch (e) {
112
+ ////////////
113
+ // ignore //
114
+ ////////////
115
+ }
116
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
117
+ // javascript timezone offset is positive for locations west of GMT (e.g., 300 for US/Central) - which seems //
118
+ // opposite of the convention (e.g., CST=-6, CDT=-5). So, we'll use a negative version of this value. //
119
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
120
+ this.axiosInstance.defaults.headers.common["X-QQQ-UserTimezoneOffsetMinutes"] = -new Date().getTimezoneOffset();
121
+ if (exceptionHandler != null) {
122
+ this.exceptionHandler = exceptionHandler;
123
+ }
124
+ else {
125
+ this.exceptionHandler = function (error) {
126
+ throw error;
127
+ };
128
+ }
129
+ }
130
+ /*******************************************************************************
131
+ ** Useful for development (e.g., to be able to use the axios instance, to test
132
+ ** things we probably want to keep in this class, without having to re-install
133
+ ** this module for the testing cycle), but probably not meant for main-line usage.
134
+ *******************************************************************************/
135
+ QControllerV1.prototype.getAxiosInstance = function () {
136
+ return (this.axiosInstance);
137
+ };
138
+ /*******************************************************************************
139
+ ** clear memoized promises
140
+ *******************************************************************************/
141
+ QControllerV1.clearMemoization = function () {
142
+ QControllerV1.metaDataPromise = undefined;
143
+ QControllerV1.tableMetaDataPromises.clear();
144
+ QControllerV1.processMetaDataPromises.clear();
145
+ };
146
+ /*******************************************************************************
147
+ ** Function to be called by an app after it's authenticated the user. This will
148
+ ** allow the awaitAuthenticationPromise to resolve, so that other requests can continue.
149
+ *******************************************************************************/
150
+ QControllerV1.prototype.setGotAuthentication = function () {
151
+ QControllerV1.gotAuthentication = true;
152
+ };
153
+ /*******************************************************************************
154
+ ** Clear the authentication meta data from local storage
155
+ *******************************************************************************/
156
+ QControllerV1.prototype.clearAuthenticationMetaDataLocalStorage = function () {
157
+ localStorage.removeItem(QControllerV1.authenticationMetaDataLocalStorageKey);
158
+ };
159
+ /*******************************************************************************
160
+ ** Fetch the authentication meta data from local storage or the server.
161
+ *******************************************************************************/
162
+ QControllerV1.prototype.getAuthenticationMetaData = function () {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var authenticationMetaDataJson, authenticationMetaData, age;
165
+ var _this = this;
166
+ return __generator(this, function (_a) {
167
+ try {
168
+ authenticationMetaDataJson = localStorage.getItem(QControllerV1.authenticationMetaDataLocalStorageKey);
169
+ authenticationMetaData = JSON.parse(authenticationMetaDataJson);
170
+ if (authenticationMetaData && authenticationMetaData.timestamp) {
171
+ age = ((new Date().getTime()) - authenticationMetaData.timestamp) / 1000;
172
+ if (age < 60 * 60) {
173
+ console.log("Found authentication meta data in local storage (and it's ".concat(age, " seconds old) - using it."));
174
+ return [2 /*return*/, (new QAuthenticationMetaData(authenticationMetaData))];
175
+ }
176
+ }
177
+ }
178
+ catch (e) {
179
+ console.log("Caught [".concat(e, "] reading authentication meta data from local storage - proceeding to get from backend."));
180
+ }
181
+ //////////////////////////////////////////
182
+ // resume with a fetch from the backend //
183
+ //////////////////////////////////////////
184
+ return [2 /*return*/, this.axiosInstance
185
+ .get("/metaData/authentication")
186
+ .then(function (response) {
187
+ response.data.timestamp = new Date().getTime();
188
+ localStorage.setItem(QControllerV1.authenticationMetaDataLocalStorageKey, JSON.stringify(response.data));
189
+ console.log("Fetched authentication meta data from backend.");
190
+ return new QAuthenticationMetaData(response.data);
191
+ })
192
+ .catch(function (error) {
193
+ _this.handleException(error);
194
+ })];
195
+ });
196
+ });
197
+ };
198
+ /*******************************************************************************
199
+ ** create or update a user session
200
+ *******************************************************************************/
201
+ QControllerV1.prototype.manageSession = function (accessToken, uuid, more) {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ var data;
204
+ var _this = this;
205
+ return __generator(this, function (_a) {
206
+ data = __assign({ accessToken: accessToken, uuid: uuid }, (more !== null && more !== void 0 ? more : {}));
207
+ return [2 /*return*/, this.axiosInstance
208
+ .post("/manageSession", data)
209
+ .then(function (response) {
210
+ return response.data;
211
+ })
212
+ .catch(function (error) {
213
+ _this.handleException(error);
214
+ })];
215
+ });
216
+ });
217
+ };
218
+ /*******************************************************************************
219
+ ** Fetch the top-level meta data for a qqq instance.
220
+ *******************************************************************************/
221
+ QControllerV1.prototype.loadMetaData = function () {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var _this = this;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0: return [4 /*yield*/, QControllerV1.awaitAuthenticationPromise];
227
+ case 1:
228
+ _a.sent();
229
+ if (QControllerV1.metaDataPromise) {
230
+ return [2 /*return*/, (QControllerV1.metaDataPromise)];
231
+ }
232
+ QControllerV1.metaDataPromise = this.axiosInstance
233
+ .get("/metaData/")
234
+ .then(function (response) {
235
+ return new QInstance(response.data);
236
+ })
237
+ .catch(function (error) {
238
+ _this.handleException(error);
239
+ });
240
+ return [2 /*return*/, QControllerV1.metaDataPromise];
241
+ }
242
+ });
243
+ });
244
+ };
245
+ /*******************************************************************************
246
+ ** Fetch the full meta data for a specific table.
247
+ *******************************************************************************/
248
+ QControllerV1.prototype.loadTableMetaData = function (tableName, version) {
249
+ return __awaiter(this, void 0, void 0, function () {
250
+ var key, promise;
251
+ var _this = this;
252
+ return __generator(this, function (_a) {
253
+ switch (_a.label) {
254
+ case 0: return [4 /*yield*/, QControllerV1.awaitAuthenticationPromise];
255
+ case 1:
256
+ _a.sent();
257
+ key = { tableName: tableName, version: version };
258
+ if (QControllerV1.tableMetaDataPromises.has(key)) {
259
+ return [2 /*return*/, (QControllerV1.tableMetaDataPromises.get(key))];
260
+ }
261
+ promise = this.axiosInstance
262
+ .get("".concat(this.getVersionPrefix(version), "/metaData/table/").concat(encodeURIComponent(tableName)))
263
+ .then(function (response) {
264
+ return new QTableMetaData(response.data);
265
+ })
266
+ .catch(function (error) {
267
+ _this.handleException(error);
268
+ });
269
+ QControllerV1.tableMetaDataPromises.set(key, promise);
270
+ return [2 /*return*/, (promise)];
271
+ }
272
+ });
273
+ });
274
+ };
275
+ /*******************************************************************************
276
+ ** Fetch the full meta data for a specific process.
277
+ *******************************************************************************/
278
+ QControllerV1.prototype.loadProcessMetaData = function (processName) {
279
+ return __awaiter(this, void 0, void 0, function () {
280
+ var promise;
281
+ var _this = this;
282
+ return __generator(this, function (_a) {
283
+ switch (_a.label) {
284
+ case 0: return [4 /*yield*/, QControllerV1.awaitAuthenticationPromise];
285
+ case 1:
286
+ _a.sent();
287
+ if (QControllerV1.processMetaDataPromises.has(processName)) {
288
+ return [2 /*return*/, (QControllerV1.processMetaDataPromises.get(processName))];
289
+ }
290
+ promise = this.axiosInstance
291
+ .get("/metaData/process/".concat(encodeURIComponent(processName)))
292
+ .then(function (response) {
293
+ return new QProcessMetaData(response.data);
294
+ })
295
+ .catch(function (error) {
296
+ _this.handleException(error);
297
+ });
298
+ QControllerV1.processMetaDataPromises.set(processName, promise);
299
+ return [2 /*return*/, (promise)];
300
+ }
301
+ });
302
+ });
303
+ };
304
+ /*******************************************************************************
305
+ ** Make a count request to the backend
306
+ *******************************************************************************/
307
+ QControllerV1.prototype.count = function (tableName, version, queryFilter, queryJoins, includeDistinct, tableVariant) {
308
+ if (queryJoins === void 0) { queryJoins = null; }
309
+ if (includeDistinct === void 0) { includeDistinct = false; }
310
+ if (tableVariant === void 0) { tableVariant = null; }
311
+ return __awaiter(this, void 0, void 0, function () {
312
+ var countURL, body;
313
+ var _this = this;
314
+ return __generator(this, function (_a) {
315
+ countURL = "".concat(this.getVersionPrefix(version), "/table/").concat(encodeURIComponent(tableName), "/count");
316
+ body = {};
317
+ if (queryFilter) {
318
+ body.filter = queryFilter;
319
+ }
320
+ if (queryJoins) {
321
+ body.joins = queryJoins;
322
+ }
323
+ if (tableVariant) {
324
+ body.tableVariant = tableVariant;
325
+ }
326
+ if (includeDistinct) {
327
+ countURL += "?includeDistinct=true";
328
+ }
329
+ return [2 /*return*/, this.axiosInstance
330
+ .post(countURL, body, { "content-type": "application/json" })
331
+ .then(function (response) {
332
+ return [response.data.count, response.data.distinctCount];
333
+ })
334
+ .catch(function (error) {
335
+ _this.handleException(error);
336
+ })];
337
+ });
338
+ });
339
+ };
340
+ /*******************************************************************************
341
+ ** Make a query request to the backend
342
+ *******************************************************************************/
343
+ QControllerV1.prototype.query = function (tableName, version, queryFilter, queryJoins, tableVariant) {
344
+ if (queryJoins === void 0) { queryJoins = null; }
345
+ if (tableVariant === void 0) { tableVariant = null; }
346
+ return __awaiter(this, void 0, void 0, function () {
347
+ var queryURL, body;
348
+ var _this = this;
349
+ return __generator(this, function (_a) {
350
+ queryURL = "".concat(this.getVersionPrefix(version), "/table/").concat(encodeURIComponent(tableName), "/query");
351
+ body = {};
352
+ if (queryFilter) {
353
+ body.filter = queryFilter;
354
+ }
355
+ if (queryJoins) {
356
+ body.joins = queryJoins;
357
+ }
358
+ if (tableVariant) {
359
+ body.tableVariant = tableVariant;
360
+ }
361
+ return [2 /*return*/, this.axiosInstance
362
+ .post(queryURL, body, { "content-type": "application/json" })
363
+ .then(function (response) {
364
+ var records = [];
365
+ if (response.data.records) {
366
+ for (var i = 0; i < response.data.records.length; i++) {
367
+ records.push(new QRecord(response.data.records[i]));
368
+ }
369
+ }
370
+ return records;
371
+ })
372
+ .catch(function (error) {
373
+ _this.handleException(error);
374
+ })];
375
+ });
376
+ });
377
+ };
378
+ /*******************************************************************************
379
+ ** Make a request to the backend for a single record
380
+ *******************************************************************************/
381
+ QControllerV1.prototype.get = function (tableName, primaryKey, tableVariant, includeAssociations, queryJoins) {
382
+ if (tableVariant === void 0) { tableVariant = null; }
383
+ if (includeAssociations === void 0) { includeAssociations = false; }
384
+ if (queryJoins === void 0) { queryJoins = null; }
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var getURL, queryString;
387
+ var _this = this;
388
+ return __generator(this, function (_a) {
389
+ getURL = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey));
390
+ queryString = [];
391
+ if (tableVariant) {
392
+ queryString.push("tableVariant=".concat(encodeURIComponent(JSON.stringify(tableVariant))));
393
+ }
394
+ if (includeAssociations) {
395
+ queryString.push("includeAssociations=true");
396
+ }
397
+ if (queryJoins) {
398
+ queryString.push("queryJoins=".concat(encodeURIComponent(JSON.stringify(queryJoins))));
399
+ }
400
+ if (queryString.length > 0) {
401
+ getURL += "?" + queryString.join("&");
402
+ }
403
+ return [2 /*return*/, this.axiosInstance
404
+ .get(getURL)
405
+ .then(function (response) {
406
+ return new QRecord(response.data);
407
+ })
408
+ .catch(function (error) {
409
+ _this.handleException(error);
410
+ })];
411
+ });
412
+ });
413
+ };
414
+ /*******************************************************************************
415
+ ** Make a request to the backend for a single record's developer mode data
416
+ *******************************************************************************/
417
+ QControllerV1.prototype.getRecordDeveloperMode = function (tableName, primaryKey) {
418
+ return __awaiter(this, void 0, void 0, function () {
419
+ var getURL;
420
+ var _this = this;
421
+ return __generator(this, function (_a) {
422
+ getURL = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer");
423
+ return [2 /*return*/, this.axiosInstance
424
+ .get(getURL)
425
+ .then(function (response) {
426
+ return response.data;
427
+ })
428
+ .catch(function (error) {
429
+ _this.handleException(error);
430
+ })];
431
+ });
432
+ });
433
+ };
434
+ /*******************************************************************************
435
+ ** Make a request to the backend to save a new version of a record's associated script
436
+ *******************************************************************************/
437
+ QControllerV1.prototype.storeRecordAssociatedScript = function (tableName, primaryKey, fieldName, code, commitMessage) {
438
+ return __awaiter(this, void 0, void 0, function () {
439
+ var url, formData;
440
+ var _this = this;
441
+ return __generator(this, function (_a) {
442
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName));
443
+ formData = new FormData();
444
+ formData.append("contents", code);
445
+ formData.append("commitMessage", commitMessage);
446
+ return [2 /*return*/, this.axiosInstance
447
+ .post(url, formData)
448
+ .then(function (response) {
449
+ return response.data;
450
+ })
451
+ .catch(function (error) {
452
+ _this.handleException(error);
453
+ })];
454
+ });
455
+ });
456
+ };
457
+ /*******************************************************************************
458
+ ** Make a request to the backend to get script logs for an associated script
459
+ *******************************************************************************/
460
+ QControllerV1.prototype.getRecordAssociatedScriptLogs = function (tableName, primaryKey, fieldName, scriptRevisionId) {
461
+ return __awaiter(this, void 0, void 0, function () {
462
+ var url;
463
+ var _this = this;
464
+ return __generator(this, function (_a) {
465
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName), "/").concat(encodeURIComponent(scriptRevisionId), "/logs");
466
+ return [2 /*return*/, this.axiosInstance
467
+ .get(url)
468
+ .then(function (response) {
469
+ return response.data;
470
+ })
471
+ .catch(function (error) {
472
+ _this.handleException(error);
473
+ })];
474
+ });
475
+ });
476
+ };
477
+ /*******************************************************************************
478
+ ** Make a request to the backend to test a script
479
+ *******************************************************************************/
480
+ QControllerV1.prototype.testScript = function (tableName, primaryKey, fieldName, code, inputValues) {
481
+ return __awaiter(this, void 0, void 0, function () {
482
+ var url, formData, _i, _a, key;
483
+ var _this = this;
484
+ return __generator(this, function (_b) {
485
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName), "/test");
486
+ formData = new FormData();
487
+ formData.append("code", code);
488
+ for (_i = 0, _a = Array.from(inputValues.keys()); _i < _a.length; _i++) {
489
+ key = _a[_i];
490
+ formData.append(key, inputValues.get(key));
491
+ }
492
+ return [2 /*return*/, this.axiosInstance
493
+ .post(url, formData)
494
+ .then(function (response) {
495
+ return response.data;
496
+ })
497
+ .catch(function (error) {
498
+ _this.handleException(error);
499
+ })];
500
+ });
501
+ });
502
+ };
503
+ /*******************************************************************************
504
+ ** Make a backend call to create a single record
505
+ **
506
+ *******************************************************************************/
507
+ QControllerV1.prototype.create = function (tableName, data) {
508
+ return __awaiter(this, void 0, void 0, function () {
509
+ var formData;
510
+ var _this = this;
511
+ return __generator(this, function (_a) {
512
+ formData = this.dataObjectToFormData(data);
513
+ return [2 /*return*/, this.axiosInstance
514
+ .post("/data/".concat(encodeURIComponent(tableName)), formData, this.defaultMultipartFormDataHeaders())
515
+ .then(function (response) {
516
+ return new QRecord(response.data.records[0]);
517
+ })
518
+ .catch(function (error) {
519
+ _this.handleException(error);
520
+ })];
521
+ });
522
+ });
523
+ };
524
+ /*******************************************************************************
525
+ ** Convert a javascript object of form data to a "FormData" object for multipart posting.
526
+ *******************************************************************************/
527
+ QControllerV1.prototype.dataObjectToFormData = function (data) {
528
+ var formData = new FormData();
529
+ Object.keys(data).forEach(function (key) {
530
+ if (data[key] == null) {
531
+ formData.append(key, "");
532
+ }
533
+ else {
534
+ formData.append(key, data[key]);
535
+ }
536
+ });
537
+ return formData;
538
+ };
539
+ /*******************************************************************************
540
+ ** Make a backend call to update a single record
541
+ **
542
+ *******************************************************************************/
543
+ QControllerV1.prototype.update = function (tableName, id, data) {
544
+ return __awaiter(this, void 0, void 0, function () {
545
+ var formData;
546
+ var _this = this;
547
+ return __generator(this, function (_a) {
548
+ formData = this.dataObjectToFormData(data);
549
+ return [2 /*return*/, this.axiosInstance
550
+ .put("/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(id)), formData, this.defaultMultipartFormDataHeaders())
551
+ .then(function (response) {
552
+ return new QRecord(response.data.records[0]);
553
+ })
554
+ .catch(function (error) {
555
+ _this.handleException(error);
556
+ })];
557
+ });
558
+ });
559
+ };
560
+ /*******************************************************************************
561
+ ** Make a backend call to delete a single record
562
+ **
563
+ *******************************************************************************/
564
+ QControllerV1.prototype.delete = function (tableName, id) {
565
+ return __awaiter(this, void 0, void 0, function () {
566
+ var _this = this;
567
+ return __generator(this, function (_a) {
568
+ return [2 /*return*/, this.axiosInstance
569
+ .delete("/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(id)))
570
+ .then(function (response) {
571
+ var _a, _b, _c;
572
+ if (response.data.deletedRecordCount === 1) {
573
+ if (response.data.recordsWithWarnings && response.data.recordsWithWarnings.length > 0) {
574
+ var recordWithWarnings = response.data.recordsWithWarnings[0];
575
+ if (recordWithWarnings && recordWithWarnings.warnings && recordWithWarnings.warnings.length > 0) {
576
+ var warning = recordWithWarnings.warnings[0];
577
+ if (warning) {
578
+ _this.exceptionHandler(new QException(new AxiosError("Warning: ".concat((_a = warning.message) !== null && _a !== void 0 ? _a : warning))));
579
+ return (0);
580
+ }
581
+ }
582
+ }
583
+ return (1);
584
+ }
585
+ else {
586
+ var qException = new QException(new AxiosError("Unknown error deleting record"));
587
+ var error = (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.recordsWithErrors[0]) === null || _c === void 0 ? void 0 : _c.errors[0];
588
+ if (error) {
589
+ qException = new QException(error);
590
+ }
591
+ _this.exceptionHandler(qException);
592
+ return (0);
593
+ }
594
+ })
595
+ .catch(function (error) {
596
+ _this.handleException(error);
597
+ })];
598
+ });
599
+ });
600
+ };
601
+ /*******************************************************************************
602
+ ** Common logic to parse a process-related server response into an appropriate object.
603
+ *******************************************************************************/
604
+ QControllerV1.prototype.parseProcessResponse = function (response) {
605
+ //////////////////////////////////////////////////////////////////////////////////////
606
+ // so, the order of these checks is critical (mostly because, complete & error have //
607
+ // a jobStatus with them too, so, you can't check that one too soon //
608
+ //////////////////////////////////////////////////////////////////////////////////////
609
+ if (response.data.jobUUID) {
610
+ return new QJobStarted(response.data);
611
+ }
612
+ else if (response.data.values || response.data.nextStep) {
613
+ return new QJobComplete(response.data);
614
+ }
615
+ else if (response.data.error) {
616
+ return new QJobError(response.data);
617
+ }
618
+ else if (response.data.jobStatus) {
619
+ return new QJobRunning(response.data.jobStatus);
620
+ }
621
+ else {
622
+ return new QJobError({ error: "Unexpected server response." });
623
+ }
624
+ };
625
+ /*******************************************************************************
626
+ ** Initialize a process
627
+ *******************************************************************************/
628
+ QControllerV1.prototype.processInit = function (processName, formDataOrQueryString, formDataHeaders) {
629
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var url;
632
+ return __generator(this, function (_a) {
633
+ url = "/processes/".concat(encodeURIComponent(processName), "/init");
634
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders)];
635
+ });
636
+ });
637
+ };
638
+ /*******************************************************************************
639
+ ** Fully run a process (i.e., not stopping for frontend steps)
640
+ *******************************************************************************/
641
+ QControllerV1.prototype.processRun = function (processName, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend) {
642
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
643
+ if (dontGoAsyncOnBackend === void 0) { dontGoAsyncOnBackend = false; }
644
+ return __awaiter(this, void 0, void 0, function () {
645
+ var url;
646
+ return __generator(this, function (_a) {
647
+ url = "/processes/".concat(encodeURIComponent(processName), "/run");
648
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend)];
649
+ });
650
+ });
651
+ };
652
+ /*******************************************************************************
653
+ ** Helper function for the process init & step functions, as well as bulk functions
654
+ ** which may run async.
655
+ *******************************************************************************/
656
+ QControllerV1.prototype.postWithQueryStringToPossibleAsyncBackendJob = function (queryString, url) {
657
+ var _this = this;
658
+ if (queryString && queryString !== "") {
659
+ url += "?".concat(queryString);
660
+ }
661
+ return this.axiosInstance
662
+ .post(url)
663
+ .then(function (response) {
664
+ var responseObject = _this.parseProcessResponse(response);
665
+ if (responseObject instanceof QJobRunning) {
666
+ ////////////////////////////////////////////////////////////////////
667
+ // we aren't allowed to return "Running" here, so just in case... //
668
+ ////////////////////////////////////////////////////////////////////
669
+ return new QJobError({ error: "Unexpected server response." });
670
+ }
671
+ return responseObject;
672
+ })
673
+ .catch(function (error) {
674
+ _this.handleException(error);
675
+ });
676
+ };
677
+ /*******************************************************************************
678
+ ** Proceed to the next step in a process
679
+ *******************************************************************************/
680
+ QControllerV1.prototype.processStep = function (processName, processUUID, step, formDataOrQueryString, formDataHeaders) {
681
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
682
+ return __awaiter(this, void 0, void 0, function () {
683
+ var url;
684
+ return __generator(this, function (_a) {
685
+ url = "/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/step/").concat(encodeURIComponent(step));
686
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders)];
687
+ });
688
+ });
689
+ };
690
+ /*******************************************************************************
691
+ ** Proceed to the next step in a process
692
+ *******************************************************************************/
693
+ QControllerV1.prototype.processStepOrInit = function (url, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend) {
694
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
695
+ if (dontGoAsyncOnBackend === void 0) { dontGoAsyncOnBackend = false; }
696
+ return __awaiter(this, void 0, void 0, function () {
697
+ var _this = this;
698
+ return __generator(this, function (_a) {
699
+ if (formDataOrQueryString instanceof FormData) {
700
+ if (!formDataHeaders) {
701
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////
702
+ // so, it looks like FormData is supplied by the browser, when running the browser, but by a form-data //
703
+ // lib when running not in the browser. The browser version doesn't have a getHeaders method... //
704
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////
705
+ if (formDataOrQueryString.getHeaders) {
706
+ formDataHeaders = formDataOrQueryString.getHeaders();
707
+ }
708
+ else {
709
+ formDataHeaders = { "content-type": "multipart/form-data; boundary=--------------------------320289315924586491558366" };
710
+ }
711
+ }
712
+ if (dontGoAsyncOnBackend) {
713
+ formDataOrQueryString.append("_qStepTimeoutMillis", 300 * 1000);
714
+ }
715
+ return [2 /*return*/, this.axiosInstance
716
+ .post(url, formDataOrQueryString, { headers: formDataHeaders })
717
+ .then(function (response) {
718
+ var responseObject = _this.parseProcessResponse(response);
719
+ if (responseObject instanceof QJobRunning) {
720
+ ////////////////////////////////////////////////////////////////////
721
+ // we aren't allowed to return "Running" here, so just in case... //
722
+ ////////////////////////////////////////////////////////////////////
723
+ return new QJobError({ error: "Unexpected server response." });
724
+ }
725
+ return responseObject;
726
+ })
727
+ .catch(function (error) {
728
+ _this.handleException(error);
729
+ })];
730
+ }
731
+ else {
732
+ if (dontGoAsyncOnBackend) {
733
+ formDataOrQueryString += "&_qStepTimeoutMillis=".concat(300 * 1000);
734
+ }
735
+ return [2 /*return*/, this.postWithQueryStringToPossibleAsyncBackendJob(formDataOrQueryString, url)];
736
+ }
737
+ return [2 /*return*/];
738
+ });
739
+ });
740
+ };
741
+ /*******************************************************************************
742
+ ** Get the status for a currently executing job within a process (init or step)
743
+ *******************************************************************************/
744
+ QControllerV1.prototype.processJobStatus = function (processName, processUUID, jobUUID) {
745
+ return __awaiter(this, void 0, void 0, function () {
746
+ var _this = this;
747
+ return __generator(this, function (_a) {
748
+ return [2 /*return*/, this.axiosInstance
749
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/status/").concat(encodeURIComponent(jobUUID)))
750
+ .then(function (response) {
751
+ var responseObject = _this.parseProcessResponse(response);
752
+ if (responseObject instanceof QJobStarted) {
753
+ ////////////////////////////////////////////////////////////////////
754
+ // we aren't allowed to return "Started" here, so just in case... //
755
+ ////////////////////////////////////////////////////////////////////
756
+ return new QJobError({ error: "Unexpected server response." });
757
+ }
758
+ return responseObject;
759
+ })
760
+ .catch(function (error) {
761
+ _this.handleException(error);
762
+ })];
763
+ });
764
+ });
765
+ };
766
+ /*******************************************************************************
767
+ ** Get records from a process's state
768
+ *******************************************************************************/
769
+ QControllerV1.prototype.processRecords = function (processName, processUUID, skip, limit) {
770
+ if (skip === void 0) { skip = 0; }
771
+ if (limit === void 0) { limit = 20; }
772
+ return __awaiter(this, void 0, void 0, function () {
773
+ var _this = this;
774
+ return __generator(this, function (_a) {
775
+ return [2 /*return*/, this.axiosInstance
776
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/records?skip=").concat(encodeURIComponent(skip), "&limit=").concat(encodeURIComponent(limit)))
777
+ .then(function (response) {
778
+ var records = [];
779
+ if (response.data && response.data.records && response.data.records.length) {
780
+ for (var i = 0; i < response.data.records.length; i++) {
781
+ records.push(new QRecord(response.data.records[i]));
782
+ }
783
+ }
784
+ return { totalRecords: response.data.totalRecords, records: records };
785
+ })
786
+ .catch(function (error) {
787
+ _this.handleException(error);
788
+ })];
789
+ });
790
+ });
791
+ };
792
+ /*******************************************************************************
793
+ ** Handle a user clicking cancel on a process
794
+ *******************************************************************************/
795
+ QControllerV1.prototype.processCancel = function (processName, processUUID) {
796
+ return __awaiter(this, void 0, void 0, function () {
797
+ var _this = this;
798
+ return __generator(this, function (_a) {
799
+ return [2 /*return*/, this.axiosInstance
800
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/cancel"))
801
+ .then(function () {
802
+ return true;
803
+ })
804
+ .catch(function (error) {
805
+ _this.handleException(error);
806
+ })];
807
+ });
808
+ });
809
+ };
810
+ /*******************************************************************************
811
+ ** Fetch the data for a specific widget.
812
+ *******************************************************************************/
813
+ QControllerV1.prototype.tableVariants = function (tableName) {
814
+ return __awaiter(this, void 0, void 0, function () {
815
+ var url;
816
+ var _this = this;
817
+ return __generator(this, function (_a) {
818
+ url = "/data/".concat(encodeURIComponent(tableName), "/variants");
819
+ console.log("Looking for variants for table [" + tableName + "]");
820
+ return [2 /*return*/, this.axiosInstance
821
+ .get(url)
822
+ .then(function (response) {
823
+ var variants = [];
824
+ if (response.data && response.data.length) {
825
+ for (var i = 0; i < response.data.length; i++) {
826
+ variants.push(new QTableVariant(response.data[i]));
827
+ }
828
+ }
829
+ return variants;
830
+ })
831
+ .catch(function (e) {
832
+ if (e.code && e.code === "ERR_CANCELED") {
833
+ console.log("Controller request cancellation successful!");
834
+ return;
835
+ }
836
+ _this.handleException(e);
837
+ })];
838
+ });
839
+ });
840
+ };
841
+ /*******************************************************************************
842
+ ** Fetch the data for a specific widget.
843
+ *******************************************************************************/
844
+ QControllerV1.prototype.widget = function (widgetName, urlParams) {
845
+ return __awaiter(this, void 0, void 0, function () {
846
+ var url, controller, signal;
847
+ var _this = this;
848
+ return __generator(this, function (_a) {
849
+ url = "/widget/".concat(encodeURIComponent(widgetName));
850
+ if (urlParams) {
851
+ url += "?".concat(urlParams);
852
+ }
853
+ /////////////////////////////////////////////////////////////////
854
+ // see if an abort controller was created for this widget name //
855
+ /////////////////////////////////////////////////////////////////
856
+ console.log("Looking for controller for widget [" + widgetName + "]");
857
+ controller = QControllerV1.widgetAbortControllerMap.get(widgetName);
858
+ if (controller) {
859
+ console.log("Found existing abort controller for widget '".concat(widgetName, "', aborting..."));
860
+ controller.abort();
861
+ }
862
+ /////////////////////////////////////////
863
+ // keep track of this widget's request //
864
+ /////////////////////////////////////////
865
+ controller = new AbortController();
866
+ signal = controller.signal;
867
+ QControllerV1.widgetAbortControllerMap.set(widgetName, controller);
868
+ return [2 /*return*/, this.axiosInstance
869
+ .get(url, { signal: signal })
870
+ .then(function (response) {
871
+ ///////////////////////////////////////////////////
872
+ // make sure to clear out the request controller //
873
+ ///////////////////////////////////////////////////
874
+ QControllerV1.widgetAbortControllerMap.set(widgetName, null);
875
+ return response.data;
876
+ })
877
+ .catch(function (e) {
878
+ if (e.code && e.code === "ERR_CANCELED") {
879
+ console.log("Controller request cancellation successful!");
880
+ return;
881
+ }
882
+ _this.handleException(e);
883
+ })];
884
+ });
885
+ });
886
+ };
887
+ /*******************************************************************************
888
+ ** Fetch options for a possible-value drop down.
889
+ **
890
+ ** This method operates in 3 modes:
891
+ ** - for a PVS field on a table (pass (tableName, null, fieldName, ...)
892
+ ** - for a PVS field on a process (pass (null, processName, fieldName, ...)
893
+ ** - for a standalone PVS (pass (null, null, process, ...)
894
+ *******************************************************************************/
895
+ QControllerV1.prototype.possibleValues = function (tableName, processName, fieldNameOrPossibleValueSourceName, searchTerm, ids, values, useCase) {
896
+ if (searchTerm === void 0) { searchTerm = ""; }
897
+ if (ids === void 0) { ids = []; }
898
+ if (values === void 0) { values = new Map(); }
899
+ if (useCase === void 0) { useCase = ""; }
900
+ return __awaiter(this, void 0, void 0, function () {
901
+ var url, queryComponents, postBody;
902
+ return __generator(this, function (_a) {
903
+ if (tableName) {
904
+ url = "/data/".concat(encodeURIComponent(tableName), "/possibleValues/").concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
905
+ }
906
+ else if (processName) {
907
+ url = "/processes/".concat(encodeURIComponent(processName), "/possibleValues/").concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
908
+ }
909
+ else {
910
+ url = "/possibleValues/".concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
911
+ }
912
+ queryComponents = [];
913
+ if (searchTerm !== "") {
914
+ queryComponents.push("searchTerm=".concat(encodeURIComponent(searchTerm)));
915
+ }
916
+ if (useCase !== "") {
917
+ queryComponents.push("useCase=".concat(encodeURIComponent(useCase)));
918
+ }
919
+ if (ids && ids.length) {
920
+ queryComponents.push("ids=".concat(encodeURIComponent(ids.join(","))));
921
+ }
922
+ if (queryComponents.length > 0) {
923
+ url += "?".concat(queryComponents.join("&"));
924
+ }
925
+ postBody = new FormData();
926
+ postBody.append("values", JSON.stringify(Object.fromEntries(values)));
927
+ return [2 /*return*/, this.axiosInstance
928
+ .post(url, postBody)
929
+ .then(function (response) {
930
+ var results = [];
931
+ if (response.data && response.data.options) {
932
+ for (var i = 0; i < response.data.options.length; i++) {
933
+ results.push(new QPossibleValue(response.data.options[i]));
934
+ }
935
+ }
936
+ return results;
937
+ })
938
+ .catch(this.handleException)];
939
+ });
940
+ });
941
+ };
942
+ /***************************************************************************
943
+ ** Let an app piggyback on our axiosInstance and handleException methods
944
+ ** to issue ad-hock requests.
945
+ ***************************************************************************/
946
+ QControllerV1.prototype.axiosRequest = function (config) {
947
+ return __awaiter(this, void 0, void 0, function () {
948
+ return __generator(this, function (_a) {
949
+ return [2 /*return*/, this.axiosInstance
950
+ .request(config)
951
+ .then(function (response) {
952
+ return (response.data);
953
+ })
954
+ .catch(this.handleException)];
955
+ });
956
+ });
957
+ };
958
+ /*******************************************************************************
959
+ **
960
+ *******************************************************************************/
961
+ QControllerV1.prototype.defaultMultipartFormDataHeaders = function () {
962
+ return {
963
+ "content-type": "multipart/form-data; boundary=--------------------------320289315924586491558366",
964
+ };
965
+ };
966
+ /*******************************************************************************
967
+ ** exception handler which will marshal axios error into a QException and
968
+ * send that the exception handler provided to this class
969
+ *******************************************************************************/
970
+ QControllerV1.prototype.handleException = function (error) {
971
+ var qException = new QException(error);
972
+ this.exceptionHandler(qException);
973
+ };
974
+ /***************************************************************************
975
+ ** function get map a Version to the string we put into urls
976
+ ***************************************************************************/
977
+ QControllerV1.prototype.getVersionPrefix = function (version) {
978
+ if (version) {
979
+ return "/".concat(version.path, "/").concat(version.version);
980
+ }
981
+ return "";
982
+ };
983
+ QControllerV1.STEP_TIMEOUT_MILLIS_PARAM_NAME = "_qStepTimeoutMillis";
984
+ QControllerV1.tableMetaDataPromises = new Map();
985
+ QControllerV1.processMetaDataPromises = new Map();
986
+ QControllerV1.authenticationMetaDataLocalStorageKey = "qqq.authenticationMetaData.json";
987
+ QControllerV1.gotAuthentication = false;
988
+ QControllerV1.widgetAbortControllerMap = new Map();
989
+ return QControllerV1;
990
+ }());
991
+ export { QControllerV1 };
992
+ //# sourceMappingURL=QControllerV1.js.map