@qrunio/qqq-frontend-core 1.0.0

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,1026 @@
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.
85
+ *******************************************************************************/
86
+ var QController = /** @class */ (function () {
87
+ /*******************************************************************************
88
+ **
89
+ *******************************************************************************/
90
+ function QController(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
+ QController.awaitAuthenticationPromise = new Promise(function (resolve) {
101
+ var interval = setInterval(function () {
102
+ if (QController.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
+ QController.prototype.getAxiosInstance = function () {
136
+ return (this.axiosInstance);
137
+ };
138
+ /*******************************************************************************
139
+ ** clear memoized promises
140
+ *******************************************************************************/
141
+ QController.clearMemoization = function () {
142
+ QController.metaDataPromise = undefined;
143
+ QController.tableMetaDataPromises.clear();
144
+ QController.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
+ QController.prototype.setGotAuthentication = function () {
151
+ QController.gotAuthentication = true;
152
+ };
153
+ /*******************************************************************************
154
+ ** Clear the authentication meta data from local storage
155
+ *******************************************************************************/
156
+ QController.prototype.clearAuthenticationMetaDataLocalStorage = function () {
157
+ localStorage.removeItem(QController.authenticationMetaDataLocalStorageKey);
158
+ };
159
+ /*******************************************************************************
160
+ ** Fetch the authentication meta data from local storage or the server.
161
+ *******************************************************************************/
162
+ QController.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(QController.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(QController.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
+ QController.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
+ QController.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*/, QController.awaitAuthenticationPromise];
227
+ case 1:
228
+ _a.sent();
229
+ if (QController.metaDataPromise) {
230
+ return [2 /*return*/, (QController.metaDataPromise)];
231
+ }
232
+ QController.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*/, QController.metaDataPromise];
241
+ }
242
+ });
243
+ });
244
+ };
245
+ /*******************************************************************************
246
+ ** Fetch the full meta data for a specific table.
247
+ *******************************************************************************/
248
+ QController.prototype.loadTableMetaData = function (tableName) {
249
+ return __awaiter(this, void 0, void 0, function () {
250
+ var promise;
251
+ var _this = this;
252
+ return __generator(this, function (_a) {
253
+ switch (_a.label) {
254
+ case 0: return [4 /*yield*/, QController.awaitAuthenticationPromise];
255
+ case 1:
256
+ _a.sent();
257
+ if (QController.tableMetaDataPromises.has(tableName)) {
258
+ return [2 /*return*/, (QController.tableMetaDataPromises.get(tableName))];
259
+ }
260
+ promise = this.axiosInstance
261
+ .get("/metaData/table/".concat(encodeURIComponent(tableName)))
262
+ .then(function (response) {
263
+ return new QTableMetaData(response.data.table);
264
+ })
265
+ .catch(function (error) {
266
+ _this.handleException(error);
267
+ });
268
+ QController.tableMetaDataPromises.set(tableName, promise);
269
+ return [2 /*return*/, (promise)];
270
+ }
271
+ });
272
+ });
273
+ };
274
+ /*******************************************************************************
275
+ ** Fetch the full meta data for a specific process.
276
+ *******************************************************************************/
277
+ QController.prototype.loadProcessMetaData = function (processName) {
278
+ return __awaiter(this, void 0, void 0, function () {
279
+ var promise;
280
+ var _this = this;
281
+ return __generator(this, function (_a) {
282
+ switch (_a.label) {
283
+ case 0: return [4 /*yield*/, QController.awaitAuthenticationPromise];
284
+ case 1:
285
+ _a.sent();
286
+ if (QController.processMetaDataPromises.has(processName)) {
287
+ return [2 /*return*/, (QController.processMetaDataPromises.get(processName))];
288
+ }
289
+ promise = this.axiosInstance
290
+ .get("/metaData/process/".concat(encodeURIComponent(processName)))
291
+ .then(function (response) {
292
+ return new QProcessMetaData(response.data.process);
293
+ })
294
+ .catch(function (error) {
295
+ _this.handleException(error);
296
+ });
297
+ QController.processMetaDataPromises.set(processName, promise);
298
+ return [2 /*return*/, (promise)];
299
+ }
300
+ });
301
+ });
302
+ };
303
+ /*******************************************************************************
304
+ ** Make a count request to the backend
305
+ *******************************************************************************/
306
+ QController.prototype.count = function (tableName, queryFilter, queryJoins, includeDistinct, tableVariant) {
307
+ if (queryJoins === void 0) { queryJoins = null; }
308
+ if (includeDistinct === void 0) { includeDistinct = false; }
309
+ if (tableVariant === void 0) { tableVariant = null; }
310
+ return __awaiter(this, void 0, void 0, function () {
311
+ var countURL, queryStringParts, formData;
312
+ var _this = this;
313
+ return __generator(this, function (_a) {
314
+ countURL = "/data/".concat(encodeURIComponent(tableName), "/count");
315
+ queryStringParts = [];
316
+ if (queryJoins) {
317
+ queryStringParts.push("queryJoins=".concat(encodeURIComponent(JSON.stringify(queryJoins))));
318
+ }
319
+ if (includeDistinct) {
320
+ queryStringParts.push("includeDistinct=true");
321
+ }
322
+ if (queryStringParts.length > 0) {
323
+ countURL += "?".concat(queryStringParts.join("&"));
324
+ }
325
+ formData = new FormData();
326
+ if (queryFilter) {
327
+ formData.append("filter", JSON.stringify(queryFilter));
328
+ }
329
+ if (tableVariant) {
330
+ formData.append("tableVariant", JSON.stringify(tableVariant));
331
+ }
332
+ return [2 /*return*/, this.axiosInstance
333
+ .post(countURL, formData)
334
+ .then(function (response) {
335
+ return [response.data.count, response.data.distinctCount];
336
+ })
337
+ .catch(function (error) {
338
+ _this.handleException(error);
339
+ })];
340
+ });
341
+ });
342
+ };
343
+ /*******************************************************************************
344
+ ** Make a query request to the backend
345
+ *******************************************************************************/
346
+ QController.prototype.query = function (tableName, queryFilter, queryJoins, tableVariant) {
347
+ if (queryJoins === void 0) { queryJoins = null; }
348
+ if (tableVariant === void 0) { tableVariant = null; }
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var queryURL, queryStringParts, formData;
351
+ var _this = this;
352
+ return __generator(this, function (_a) {
353
+ queryURL = "/data/".concat(encodeURIComponent(tableName), "/query");
354
+ queryStringParts = [];
355
+ if (queryJoins) {
356
+ queryStringParts.push("queryJoins=".concat(encodeURIComponent(JSON.stringify(queryJoins))));
357
+ }
358
+ if (queryStringParts.length > 0) {
359
+ queryURL += "?".concat(queryStringParts.join("&"));
360
+ }
361
+ formData = new FormData();
362
+ if (queryFilter) {
363
+ formData.append("filter", JSON.stringify(queryFilter));
364
+ }
365
+ if (tableVariant) {
366
+ formData.append("tableVariant", JSON.stringify(tableVariant));
367
+ }
368
+ return [2 /*return*/, this.axiosInstance
369
+ .post(queryURL, formData)
370
+ .then(function (response) {
371
+ var records = [];
372
+ if (response.data.records) {
373
+ for (var i = 0; i < response.data.records.length; i++) {
374
+ records.push(new QRecord(response.data.records[i]));
375
+ }
376
+ }
377
+ return records;
378
+ })
379
+ .catch(function (error) {
380
+ _this.handleException(error);
381
+ })];
382
+ });
383
+ });
384
+ };
385
+ /*******************************************************************************
386
+ ** Make a request to the backend for a single record
387
+ *******************************************************************************/
388
+ QController.prototype.get = function (tableName, primaryKey, tableVariant, includeAssociations, queryJoins) {
389
+ if (tableVariant === void 0) { tableVariant = null; }
390
+ if (includeAssociations === void 0) { includeAssociations = false; }
391
+ if (queryJoins === void 0) { queryJoins = null; }
392
+ return __awaiter(this, void 0, void 0, function () {
393
+ var getURL, queryString;
394
+ var _this = this;
395
+ return __generator(this, function (_a) {
396
+ getURL = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey));
397
+ queryString = [];
398
+ if (tableVariant) {
399
+ queryString.push("tableVariant=".concat(encodeURIComponent(JSON.stringify(tableVariant))));
400
+ }
401
+ if (includeAssociations) {
402
+ queryString.push("includeAssociations=true");
403
+ }
404
+ if (queryJoins) {
405
+ queryString.push("queryJoins=".concat(encodeURIComponent(JSON.stringify(queryJoins))));
406
+ }
407
+ if (queryString.length > 0) {
408
+ getURL += "?" + queryString.join("&");
409
+ }
410
+ return [2 /*return*/, this.axiosInstance
411
+ .get(getURL)
412
+ .then(function (response) {
413
+ return new QRecord(response.data);
414
+ })
415
+ .catch(function (error) {
416
+ _this.handleException(error);
417
+ })];
418
+ });
419
+ });
420
+ };
421
+ /*******************************************************************************
422
+ ** Make a request to the backend for a single record's developer mode data
423
+ *******************************************************************************/
424
+ QController.prototype.getRecordDeveloperMode = function (tableName, primaryKey) {
425
+ return __awaiter(this, void 0, void 0, function () {
426
+ var getURL;
427
+ var _this = this;
428
+ return __generator(this, function (_a) {
429
+ getURL = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer");
430
+ return [2 /*return*/, this.axiosInstance
431
+ .get(getURL)
432
+ .then(function (response) {
433
+ return response.data;
434
+ })
435
+ .catch(function (error) {
436
+ _this.handleException(error);
437
+ })];
438
+ });
439
+ });
440
+ };
441
+ /*******************************************************************************
442
+ ** Make a request to the backend to save a new version of a record's associated script
443
+ *******************************************************************************/
444
+ QController.prototype.storeRecordAssociatedScript = function (tableName, primaryKey, fieldName, code, commitMessage) {
445
+ return __awaiter(this, void 0, void 0, function () {
446
+ var url, formData;
447
+ var _this = this;
448
+ return __generator(this, function (_a) {
449
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName));
450
+ formData = new FormData();
451
+ formData.append("contents", code);
452
+ formData.append("commitMessage", commitMessage);
453
+ return [2 /*return*/, this.axiosInstance
454
+ .post(url, formData)
455
+ .then(function (response) {
456
+ return response.data;
457
+ })
458
+ .catch(function (error) {
459
+ _this.handleException(error);
460
+ })];
461
+ });
462
+ });
463
+ };
464
+ /*******************************************************************************
465
+ ** Make a request to the backend to get script logs for an associated script
466
+ *******************************************************************************/
467
+ QController.prototype.getRecordAssociatedScriptLogs = function (tableName, primaryKey, fieldName, scriptRevisionId) {
468
+ return __awaiter(this, void 0, void 0, function () {
469
+ var url;
470
+ var _this = this;
471
+ return __generator(this, function (_a) {
472
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName), "/").concat(encodeURIComponent(scriptRevisionId), "/logs");
473
+ return [2 /*return*/, this.axiosInstance
474
+ .get(url)
475
+ .then(function (response) {
476
+ return response.data;
477
+ })
478
+ .catch(function (error) {
479
+ _this.handleException(error);
480
+ })];
481
+ });
482
+ });
483
+ };
484
+ /*******************************************************************************
485
+ ** Make a request to the backend to test a script
486
+ *******************************************************************************/
487
+ QController.prototype.testScript = function (tableName, primaryKey, fieldName, code, inputValues) {
488
+ return __awaiter(this, void 0, void 0, function () {
489
+ var url, formData, _i, _a, key;
490
+ var _this = this;
491
+ return __generator(this, function (_b) {
492
+ url = "/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(primaryKey), "/developer/associatedScript/").concat(encodeURIComponent(fieldName), "/test");
493
+ formData = new FormData();
494
+ formData.append("code", code);
495
+ for (_i = 0, _a = Array.from(inputValues.keys()); _i < _a.length; _i++) {
496
+ key = _a[_i];
497
+ formData.append(key, inputValues.get(key));
498
+ }
499
+ return [2 /*return*/, this.axiosInstance
500
+ .post(url, formData)
501
+ .then(function (response) {
502
+ return response.data;
503
+ })
504
+ .catch(function (error) {
505
+ _this.handleException(error);
506
+ })];
507
+ });
508
+ });
509
+ };
510
+ /*******************************************************************************
511
+ ** Make a backend call to create a single record
512
+ **
513
+ *******************************************************************************/
514
+ QController.prototype.create = function (tableName, data) {
515
+ return __awaiter(this, void 0, void 0, function () {
516
+ var formData;
517
+ var _this = this;
518
+ return __generator(this, function (_a) {
519
+ formData = this.dataObjectToFormData(data);
520
+ return [2 /*return*/, this.axiosInstance
521
+ .post("/data/".concat(encodeURIComponent(tableName)), formData, this.defaultMultipartFormDataHeaders())
522
+ .then(function (response) {
523
+ return new QRecord(response.data.records[0]);
524
+ })
525
+ .catch(function (error) {
526
+ _this.handleException(error);
527
+ })];
528
+ });
529
+ });
530
+ };
531
+ /*******************************************************************************
532
+ ** Convert a javascript object of form data to a "FormData" object for multipart posting.
533
+ *******************************************************************************/
534
+ QController.prototype.dataObjectToFormData = function (data) {
535
+ var formData = new FormData();
536
+ Object.keys(data).forEach(function (key) {
537
+ if (data[key] == null) {
538
+ formData.append(key, "");
539
+ }
540
+ else {
541
+ formData.append(key, data[key]);
542
+ }
543
+ });
544
+ return formData;
545
+ };
546
+ /*******************************************************************************
547
+ ** Make a backend call to update a single record
548
+ **
549
+ *******************************************************************************/
550
+ QController.prototype.update = function (tableName, id, data) {
551
+ return __awaiter(this, void 0, void 0, function () {
552
+ var formData;
553
+ var _this = this;
554
+ return __generator(this, function (_a) {
555
+ formData = this.dataObjectToFormData(data);
556
+ return [2 /*return*/, this.axiosInstance
557
+ .put("/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(id)), formData, this.defaultMultipartFormDataHeaders())
558
+ .then(function (response) {
559
+ return new QRecord(response.data.records[0]);
560
+ })
561
+ .catch(function (error) {
562
+ _this.handleException(error);
563
+ })];
564
+ });
565
+ });
566
+ };
567
+ /*******************************************************************************
568
+ ** Make a backend call to delete a single record
569
+ **
570
+ *******************************************************************************/
571
+ QController.prototype.delete = function (tableName, id) {
572
+ return __awaiter(this, void 0, void 0, function () {
573
+ var _this = this;
574
+ return __generator(this, function (_a) {
575
+ return [2 /*return*/, this.axiosInstance
576
+ .delete("/data/".concat(encodeURIComponent(tableName), "/").concat(encodeURIComponent(id)))
577
+ .then(function (response) {
578
+ var _a, _b, _c;
579
+ if (response.data.deletedRecordCount === 1) {
580
+ if (response.data.recordsWithWarnings && response.data.recordsWithWarnings.length > 0) {
581
+ var recordWithWarnings = response.data.recordsWithWarnings[0];
582
+ if (recordWithWarnings && recordWithWarnings.warnings && recordWithWarnings.warnings.length > 0) {
583
+ var warning = recordWithWarnings.warnings[0];
584
+ if (warning) {
585
+ _this.exceptionHandler(new QException(new AxiosError("Warning: ".concat((_a = warning.message) !== null && _a !== void 0 ? _a : warning))));
586
+ return (0);
587
+ }
588
+ }
589
+ }
590
+ return (1);
591
+ }
592
+ else {
593
+ var qException = new QException(new AxiosError("Unknown error deleting record"));
594
+ var error = (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.recordsWithErrors[0]) === null || _c === void 0 ? void 0 : _c.errors[0];
595
+ if (error) {
596
+ qException = new QException(error);
597
+ }
598
+ _this.exceptionHandler(qException);
599
+ return (0);
600
+ }
601
+ })
602
+ .catch(function (error) {
603
+ _this.handleException(error);
604
+ })];
605
+ });
606
+ });
607
+ };
608
+ /*******************************************************************************
609
+ ** Common logic to parse a process-related server response into an appropriate object.
610
+ *******************************************************************************/
611
+ QController.prototype.parseProcessResponse = function (response) {
612
+ //////////////////////////////////////////////////////////////////////////////////////
613
+ // so, the order of these checks is critical (mostly because, complete & error have //
614
+ // a jobStatus with them too, so, you can't check that one too soon //
615
+ //////////////////////////////////////////////////////////////////////////////////////
616
+ if (response.data.jobUUID) {
617
+ return new QJobStarted(response.data);
618
+ }
619
+ else if (response.data.values || response.data.nextStep) {
620
+ return new QJobComplete(response.data);
621
+ }
622
+ else if (response.data.error) {
623
+ return new QJobError(response.data);
624
+ }
625
+ else if (response.data.jobStatus) {
626
+ return new QJobRunning(response.data.jobStatus);
627
+ }
628
+ else {
629
+ return new QJobError({ error: "Unexpected server response." });
630
+ }
631
+ };
632
+ /*******************************************************************************
633
+ ** Initialize a process
634
+ *******************************************************************************/
635
+ QController.prototype.processInit = function (processName, formDataOrQueryString, formDataHeaders) {
636
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
637
+ return __awaiter(this, void 0, void 0, function () {
638
+ var url;
639
+ return __generator(this, function (_a) {
640
+ url = "/processes/".concat(encodeURIComponent(processName), "/init");
641
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders)];
642
+ });
643
+ });
644
+ };
645
+ /*******************************************************************************
646
+ ** Fully run a process (i.e., not stopping for frontend steps)
647
+ *******************************************************************************/
648
+ QController.prototype.processRun = function (processName, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend) {
649
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
650
+ if (dontGoAsyncOnBackend === void 0) { dontGoAsyncOnBackend = false; }
651
+ return __awaiter(this, void 0, void 0, function () {
652
+ var url;
653
+ return __generator(this, function (_a) {
654
+ url = "/processes/".concat(encodeURIComponent(processName), "/run");
655
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend)];
656
+ });
657
+ });
658
+ };
659
+ /*******************************************************************************
660
+ ** Helper function for the process init & step functions, as well as bulk functions
661
+ ** which may run async.
662
+ *******************************************************************************/
663
+ QController.prototype.postWithQueryStringToPossibleAsyncBackendJob = function (queryString, url) {
664
+ var _this = this;
665
+ if (queryString && queryString !== "") {
666
+ url += "?".concat(queryString);
667
+ }
668
+ return this.axiosInstance
669
+ .post(url)
670
+ .then(function (response) {
671
+ var responseObject = _this.parseProcessResponse(response);
672
+ if (responseObject instanceof QJobRunning) {
673
+ ////////////////////////////////////////////////////////////////////
674
+ // we aren't allowed to return "Running" here, so just in case... //
675
+ ////////////////////////////////////////////////////////////////////
676
+ return new QJobError({ error: "Unexpected server response." });
677
+ }
678
+ return responseObject;
679
+ })
680
+ .catch(function (error) {
681
+ _this.handleException(error);
682
+ });
683
+ };
684
+ /*******************************************************************************
685
+ ** Proceed to the next step in a process
686
+ *******************************************************************************/
687
+ QController.prototype.processStep = function (processName, processUUID, step, formDataOrQueryString, formDataHeaders) {
688
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
689
+ return __awaiter(this, void 0, void 0, function () {
690
+ var url;
691
+ return __generator(this, function (_a) {
692
+ url = "/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/step/").concat(encodeURIComponent(step));
693
+ return [2 /*return*/, this.processStepOrInit(url, formDataOrQueryString, formDataHeaders)];
694
+ });
695
+ });
696
+ };
697
+ /*******************************************************************************
698
+ ** Proceed to the next step in a process
699
+ *******************************************************************************/
700
+ QController.prototype.processStepOrInit = function (url, formDataOrQueryString, formDataHeaders, dontGoAsyncOnBackend) {
701
+ if (formDataOrQueryString === void 0) { formDataOrQueryString = ""; }
702
+ if (dontGoAsyncOnBackend === void 0) { dontGoAsyncOnBackend = false; }
703
+ return __awaiter(this, void 0, void 0, function () {
704
+ var _this = this;
705
+ return __generator(this, function (_a) {
706
+ if (formDataOrQueryString instanceof FormData) {
707
+ if (!formDataHeaders) {
708
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////
709
+ // so, it looks like FormData is supplied by the browser, when running the browser, but by a form-data //
710
+ // lib when running not in the browser. The browser version doesn't have a getHeaders method... //
711
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////
712
+ if (formDataOrQueryString.getHeaders) {
713
+ formDataHeaders = formDataOrQueryString.getHeaders();
714
+ }
715
+ else {
716
+ formDataHeaders = { "content-type": "multipart/form-data; boundary=--------------------------320289315924586491558366" };
717
+ }
718
+ }
719
+ if (dontGoAsyncOnBackend) {
720
+ formDataOrQueryString.append("_qStepTimeoutMillis", 300 * 1000);
721
+ }
722
+ return [2 /*return*/, this.axiosInstance
723
+ .post(url, formDataOrQueryString, { headers: formDataHeaders })
724
+ .then(function (response) {
725
+ var responseObject = _this.parseProcessResponse(response);
726
+ if (responseObject instanceof QJobRunning) {
727
+ ////////////////////////////////////////////////////////////////////
728
+ // we aren't allowed to return "Running" here, so just in case... //
729
+ ////////////////////////////////////////////////////////////////////
730
+ return new QJobError({ error: "Unexpected server response." });
731
+ }
732
+ return responseObject;
733
+ })
734
+ .catch(function (error) {
735
+ _this.handleException(error);
736
+ })];
737
+ }
738
+ else {
739
+ if (dontGoAsyncOnBackend) {
740
+ formDataOrQueryString += "&_qStepTimeoutMillis=".concat(300 * 1000);
741
+ }
742
+ return [2 /*return*/, this.postWithQueryStringToPossibleAsyncBackendJob(formDataOrQueryString, url)];
743
+ }
744
+ return [2 /*return*/];
745
+ });
746
+ });
747
+ };
748
+ /*******************************************************************************
749
+ ** Get the status for a currently executing job within a process (init or step)
750
+ *******************************************************************************/
751
+ QController.prototype.processJobStatus = function (processName, processUUID, jobUUID) {
752
+ return __awaiter(this, void 0, void 0, function () {
753
+ var _this = this;
754
+ return __generator(this, function (_a) {
755
+ return [2 /*return*/, this.axiosInstance
756
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/status/").concat(encodeURIComponent(jobUUID)))
757
+ .then(function (response) {
758
+ var responseObject = _this.parseProcessResponse(response);
759
+ if (responseObject instanceof QJobStarted) {
760
+ ////////////////////////////////////////////////////////////////////
761
+ // we aren't allowed to return "Started" here, so just in case... //
762
+ ////////////////////////////////////////////////////////////////////
763
+ return new QJobError({ error: "Unexpected server response." });
764
+ }
765
+ return responseObject;
766
+ })
767
+ .catch(function (error) {
768
+ _this.handleException(error);
769
+ })];
770
+ });
771
+ });
772
+ };
773
+ /*******************************************************************************
774
+ ** Get records from a process's state
775
+ *******************************************************************************/
776
+ QController.prototype.processRecords = function (processName, processUUID, skip, limit) {
777
+ if (skip === void 0) { skip = 0; }
778
+ if (limit === void 0) { limit = 20; }
779
+ return __awaiter(this, void 0, void 0, function () {
780
+ var _this = this;
781
+ return __generator(this, function (_a) {
782
+ return [2 /*return*/, this.axiosInstance
783
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/records?skip=").concat(encodeURIComponent(skip), "&limit=").concat(encodeURIComponent(limit)))
784
+ .then(function (response) {
785
+ var records = [];
786
+ if (response.data && response.data.records && response.data.records.length) {
787
+ for (var i = 0; i < response.data.records.length; i++) {
788
+ records.push(new QRecord(response.data.records[i]));
789
+ }
790
+ }
791
+ return { totalRecords: response.data.totalRecords, records: records };
792
+ })
793
+ .catch(function (error) {
794
+ _this.handleException(error);
795
+ })];
796
+ });
797
+ });
798
+ };
799
+ /*******************************************************************************
800
+ ** Handle a user clicking cancel on a process
801
+ *******************************************************************************/
802
+ QController.prototype.processCancel = function (processName, processUUID) {
803
+ return __awaiter(this, void 0, void 0, function () {
804
+ var _this = this;
805
+ return __generator(this, function (_a) {
806
+ return [2 /*return*/, this.axiosInstance
807
+ .get("/processes/".concat(encodeURIComponent(processName), "/").concat(encodeURIComponent(processUUID), "/cancel"))
808
+ .then(function () {
809
+ return true;
810
+ })
811
+ .catch(function (error) {
812
+ _this.handleException(error);
813
+ })];
814
+ });
815
+ });
816
+ };
817
+ /*******************************************************************************
818
+ ** Fetch the data for a specific widget.
819
+ *******************************************************************************/
820
+ QController.prototype.tableVariants = function (tableName) {
821
+ return __awaiter(this, void 0, void 0, function () {
822
+ var url;
823
+ var _this = this;
824
+ return __generator(this, function (_a) {
825
+ url = "/data/".concat(encodeURIComponent(tableName), "/variants");
826
+ console.log("Looking for variants for table [" + tableName + "]");
827
+ return [2 /*return*/, this.axiosInstance
828
+ .get(url)
829
+ .then(function (response) {
830
+ var variants = [];
831
+ if (response.data && response.data.length) {
832
+ for (var i = 0; i < response.data.length; i++) {
833
+ variants.push(new QTableVariant(response.data[i]));
834
+ }
835
+ }
836
+ return variants;
837
+ })
838
+ .catch(function (e) {
839
+ if (e.code && e.code === "ERR_CANCELED") {
840
+ console.log("Controller request cancellation successful!");
841
+ return;
842
+ }
843
+ _this.handleException(e);
844
+ })];
845
+ });
846
+ });
847
+ };
848
+ /*******************************************************************************
849
+ ** Fetch the data for a specific widget.
850
+ *******************************************************************************/
851
+ QController.prototype.widget = function (widgetName, urlParams) {
852
+ return __awaiter(this, void 0, void 0, function () {
853
+ var url, controller, signal;
854
+ var _this = this;
855
+ return __generator(this, function (_a) {
856
+ url = "/widget/".concat(encodeURIComponent(widgetName));
857
+ if (urlParams) {
858
+ url += "?".concat(urlParams);
859
+ }
860
+ /////////////////////////////////////////////////////////////////
861
+ // see if an abort controller was created for this widget name //
862
+ /////////////////////////////////////////////////////////////////
863
+ console.log("Looking for controller for widget [" + widgetName + "]");
864
+ controller = QController.widgetAbortControllerMap.get(widgetName);
865
+ if (controller) {
866
+ console.log("Found existing abort controller for widget '".concat(widgetName, "', aborting..."));
867
+ controller.abort();
868
+ }
869
+ /////////////////////////////////////////
870
+ // keep track of this widget's request //
871
+ /////////////////////////////////////////
872
+ controller = new AbortController();
873
+ signal = controller.signal;
874
+ QController.widgetAbortControllerMap.set(widgetName, controller);
875
+ return [2 /*return*/, this.axiosInstance
876
+ .get(url, { signal: signal })
877
+ .then(function (response) {
878
+ ///////////////////////////////////////////////////
879
+ // make sure to clear out the request controller //
880
+ ///////////////////////////////////////////////////
881
+ QController.widgetAbortControllerMap.set(widgetName, null);
882
+ return response.data;
883
+ })
884
+ .catch(function (e) {
885
+ if (e.code && e.code === "ERR_CANCELED") {
886
+ console.log("Controller request cancellation successful!");
887
+ return;
888
+ }
889
+ _this.handleException(e);
890
+ })];
891
+ });
892
+ });
893
+ };
894
+ /*******************************************************************************
895
+ ** Fetch options for a possible-value drop down.
896
+ **
897
+ ** This method operates in 3 modes:
898
+ ** - for a PVS field on a table (pass (tableName, null, fieldName, ...)
899
+ ** - for a PVS field on a process (pass (null, processName, fieldName, ...)
900
+ ** - for a standalone PVS (pass (null, null, process, ...)
901
+ **
902
+ ** For the standalone use-case, the backend doesn't know what QFieldMetaData
903
+ ** is being used (e.g,. it can't find it on a table or process), so, for that
904
+ ** case, a possibleValueSourceFilter can be passed along to provide that function.
905
+ *******************************************************************************/
906
+ QController.prototype.possibleValues = function () {
907
+ var args = [];
908
+ for (var _i = 0; _i < arguments.length; _i++) {
909
+ args[_i] = arguments[_i];
910
+ }
911
+ return __awaiter(this, void 0, void 0, function () {
912
+ var tableName, processName, fieldNameOrPossibleValueSourceName, searchTerm, ids, labels, values, useCase, possibleValueSourceFilter, url, queryComponents, postBody;
913
+ var _a, _b;
914
+ return __generator(this, function (_c) {
915
+ possibleValueSourceFilter = null;
916
+ if (args[0] != null && typeof args[0] === "object") {
917
+ (_a = args[0], tableName = _a.tableName, processName = _a.processName, fieldNameOrPossibleValueSourceName = _a.fieldNameOrPossibleValueSourceName, searchTerm = _a.searchTerm, ids = _a.ids, labels = _a.labels, values = _a.values, useCase = _a.useCase, possibleValueSourceFilter = _a.possibleValueSourceFilter);
918
+ }
919
+ else {
920
+ _b = args, tableName = _b[0], processName = _b[1], fieldNameOrPossibleValueSourceName = _b[2], searchTerm = _b[3], ids = _b[4], labels = _b[5], values = _b[6], useCase = _b[7];
921
+ }
922
+ if (searchTerm == null) {
923
+ searchTerm = "";
924
+ }
925
+ if (ids == null) {
926
+ ids = [];
927
+ }
928
+ if (labels == null) {
929
+ labels = [];
930
+ }
931
+ if (values == null) {
932
+ values = new Map();
933
+ }
934
+ if (useCase == null) {
935
+ useCase = "";
936
+ }
937
+ if (tableName) {
938
+ url = "/data/".concat(encodeURIComponent(tableName), "/possibleValues/").concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
939
+ }
940
+ else if (processName) {
941
+ url = "/processes/".concat(encodeURIComponent(processName), "/possibleValues/").concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
942
+ }
943
+ else {
944
+ url = "/possibleValues/".concat(encodeURIComponent(fieldNameOrPossibleValueSourceName));
945
+ }
946
+ queryComponents = [];
947
+ if (searchTerm !== "") {
948
+ queryComponents.push("searchTerm=".concat(encodeURIComponent(searchTerm)));
949
+ }
950
+ if (useCase !== "") {
951
+ queryComponents.push("useCase=".concat(encodeURIComponent(useCase)));
952
+ }
953
+ if (ids && ids.length) {
954
+ queryComponents.push("ids=".concat(encodeURIComponent(ids.join(","))));
955
+ }
956
+ if (labels && labels.length) {
957
+ queryComponents.push("labels=".concat(encodeURIComponent(labels.join(","))));
958
+ }
959
+ if (queryComponents.length > 0) {
960
+ url += "?".concat(queryComponents.join("&"));
961
+ }
962
+ postBody = new FormData();
963
+ postBody.append("values", JSON.stringify(Object.fromEntries(values)));
964
+ if (possibleValueSourceFilter) {
965
+ postBody.append("filter", JSON.stringify(possibleValueSourceFilter));
966
+ }
967
+ return [2 /*return*/, this.axiosInstance
968
+ .post(url, postBody)
969
+ .then(function (response) {
970
+ var results = [];
971
+ if (response.data && response.data.options) {
972
+ for (var i = 0; i < response.data.options.length; i++) {
973
+ results.push(new QPossibleValue(response.data.options[i]));
974
+ }
975
+ }
976
+ return results;
977
+ })
978
+ .catch(this.handleException)];
979
+ });
980
+ });
981
+ };
982
+ /***************************************************************************
983
+ ** Let an app piggyback on our axiosInstance and handleException methods
984
+ ** to issue ad-hock requests.
985
+ ***************************************************************************/
986
+ QController.prototype.axiosRequest = function (config) {
987
+ return __awaiter(this, void 0, void 0, function () {
988
+ var _this = this;
989
+ return __generator(this, function (_a) {
990
+ return [2 /*return*/, this.axiosInstance
991
+ .request(config)
992
+ .then(function (response) {
993
+ return (response.data);
994
+ })
995
+ .catch(function (error) {
996
+ _this.handleException(error);
997
+ })];
998
+ });
999
+ });
1000
+ };
1001
+ /*******************************************************************************
1002
+ **
1003
+ *******************************************************************************/
1004
+ QController.prototype.defaultMultipartFormDataHeaders = function () {
1005
+ return {
1006
+ "content-type": "multipart/form-data; boundary=--------------------------320289315924586491558366",
1007
+ };
1008
+ };
1009
+ /*******************************************************************************
1010
+ ** exception handler which will marshal axios error into a QException and
1011
+ * send that the exception handler provided to this class
1012
+ *******************************************************************************/
1013
+ QController.prototype.handleException = function (error) {
1014
+ var qException = new QException(error);
1015
+ this.exceptionHandler(qException);
1016
+ };
1017
+ QController.STEP_TIMEOUT_MILLIS_PARAM_NAME = "_qStepTimeoutMillis";
1018
+ QController.tableMetaDataPromises = new Map();
1019
+ QController.processMetaDataPromises = new Map();
1020
+ QController.authenticationMetaDataLocalStorageKey = "qqq.authenticationMetaData.json";
1021
+ QController.gotAuthentication = false;
1022
+ QController.widgetAbortControllerMap = new Map();
1023
+ return QController;
1024
+ }());
1025
+ export { QController };
1026
+ //# sourceMappingURL=QController.js.map