igniteui-webcomponents-datasources 1.4.1 → 3.2.1

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 (84) hide show
  1. package/bundles/igniteui-webcomponents-datasources.umd.js +2279 -1
  2. package/bundles/igniteui-webcomponents-datasources.umd.min.js +7 -2
  3. package/esm2015/igniteui-webcomponents-datasources.js +0 -1
  4. package/esm2015/lib/Entity.js +0 -1
  5. package/esm2015/lib/EntityProperty.js +0 -1
  6. package/esm2015/lib/EntitySet.js +0 -1
  7. package/esm2015/lib/ODataDataSourcePage.js +0 -1
  8. package/esm2015/lib/ODataSchemaProvider.js +0 -1
  9. package/esm2015/lib/ODataVirtualDataSource.js +0 -1
  10. package/esm2015/lib/ODataVirtualDataSourceDataProvider.js +0 -1
  11. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -1
  12. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -1
  13. package/esm2015/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -1
  14. package/esm2015/lib/RestVirtualDataSource.js +272 -0
  15. package/esm2015/lib/RestVirtualDataSourceDataProvider.js +528 -0
  16. package/esm2015/lib/RestVirtualDataSourceDataProviderWorker.js +744 -0
  17. package/esm2015/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +154 -0
  18. package/esm2015/lib/RestVirtualDataSourcePage.js +67 -0
  19. package/esm2015/lib/RestVirtualDataSourceProviderTaskDataHolder.js +8 -0
  20. package/esm2015/lib/Schema.js +0 -1
  21. package/esm2015/lib/util.js +0 -1
  22. package/esm2015/public_api.js +6 -1
  23. package/esm5/igniteui-webcomponents-datasources.js +0 -1
  24. package/esm5/lib/Entity.js +0 -1
  25. package/esm5/lib/EntityProperty.js +0 -1
  26. package/esm5/lib/EntitySet.js +0 -1
  27. package/esm5/lib/ODataDataSourcePage.js +0 -1
  28. package/esm5/lib/ODataSchemaProvider.js +0 -1
  29. package/esm5/lib/ODataVirtualDataSource.js +0 -1
  30. package/esm5/lib/ODataVirtualDataSourceDataProvider.js +0 -1
  31. package/esm5/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -1
  32. package/esm5/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -1
  33. package/esm5/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -1
  34. package/esm5/lib/RestVirtualDataSource.js +357 -0
  35. package/esm5/lib/RestVirtualDataSourceDataProvider.js +675 -0
  36. package/esm5/lib/RestVirtualDataSourceDataProviderWorker.js +948 -0
  37. package/esm5/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +240 -0
  38. package/esm5/lib/RestVirtualDataSourcePage.js +73 -0
  39. package/esm5/lib/RestVirtualDataSourceProviderTaskDataHolder.js +12 -0
  40. package/esm5/lib/Schema.js +0 -1
  41. package/esm5/lib/util.js +0 -1
  42. package/esm5/public_api.js +6 -1
  43. package/fesm2015/igniteui-webcomponents-datasources.js +1754 -3
  44. package/fesm5/igniteui-webcomponents-datasources.js +2275 -3
  45. package/lib/RestVirtualDataSource.d.ts +60 -0
  46. package/lib/RestVirtualDataSourceDataProvider.d.ts +135 -0
  47. package/lib/RestVirtualDataSourceDataProviderWorker.d.ts +69 -0
  48. package/lib/RestVirtualDataSourceDataProviderWorkerSettings.d.ts +60 -0
  49. package/lib/RestVirtualDataSourcePage.d.ts +19 -0
  50. package/lib/RestVirtualDataSourceProviderTaskDataHolder.d.ts +5 -0
  51. package/package.json +3 -3
  52. package/public_api.d.ts +6 -0
  53. package/bundles/igniteui-webcomponents-datasources.umd.js.map +0 -1
  54. package/bundles/igniteui-webcomponents-datasources.umd.min.js.map +0 -1
  55. package/esm2015/igniteui-webcomponents-datasources.js.map +0 -1
  56. package/esm2015/lib/Entity.js.map +0 -1
  57. package/esm2015/lib/EntityProperty.js.map +0 -1
  58. package/esm2015/lib/EntitySet.js.map +0 -1
  59. package/esm2015/lib/ODataDataSourcePage.js.map +0 -1
  60. package/esm2015/lib/ODataSchemaProvider.js.map +0 -1
  61. package/esm2015/lib/ODataVirtualDataSource.js.map +0 -1
  62. package/esm2015/lib/ODataVirtualDataSourceDataProvider.js.map +0 -1
  63. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorker.js.map +0 -1
  64. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js.map +0 -1
  65. package/esm2015/lib/ODataVirtualDataSourceProviderTaskDataHolder.js.map +0 -1
  66. package/esm2015/lib/Schema.js.map +0 -1
  67. package/esm2015/lib/util.js.map +0 -1
  68. package/esm2015/public_api.js.map +0 -1
  69. package/esm5/igniteui-webcomponents-datasources.js.map +0 -1
  70. package/esm5/lib/Entity.js.map +0 -1
  71. package/esm5/lib/EntityProperty.js.map +0 -1
  72. package/esm5/lib/EntitySet.js.map +0 -1
  73. package/esm5/lib/ODataDataSourcePage.js.map +0 -1
  74. package/esm5/lib/ODataSchemaProvider.js.map +0 -1
  75. package/esm5/lib/ODataVirtualDataSource.js.map +0 -1
  76. package/esm5/lib/ODataVirtualDataSourceDataProvider.js.map +0 -1
  77. package/esm5/lib/ODataVirtualDataSourceDataProviderWorker.js.map +0 -1
  78. package/esm5/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js.map +0 -1
  79. package/esm5/lib/ODataVirtualDataSourceProviderTaskDataHolder.js.map +0 -1
  80. package/esm5/lib/Schema.js.map +0 -1
  81. package/esm5/lib/util.js.map +0 -1
  82. package/esm5/public_api.js.map +0 -1
  83. package/fesm2015/igniteui-webcomponents-datasources.js.map +0 -1
  84. package/fesm5/igniteui-webcomponents-datasources.js.map +0 -1
@@ -0,0 +1,948 @@
1
+ import * as tslib_1 from "tslib";
2
+ import { AsyncVirtualDataSourceProviderWorker } from "igniteui-webcomponents-core";
3
+ import { SortDescriptionCollection } from "igniteui-webcomponents-core";
4
+ import { RestVirtualDataSourceProviderTaskDataHolder } from "./RestVirtualDataSourceProviderTaskDataHolder";
5
+ import { AsyncDataSourcePageTaskHolder } from "igniteui-webcomponents-core";
6
+ import { AsyncVirtualDataTask } from "igniteui-webcomponents-core";
7
+ import { RestVirtualDataSourcePage } from "./RestVirtualDataSourcePage";
8
+ import { DefaultSectionInformation } from "igniteui-webcomponents-core";
9
+ import { Convert } from "igniteui-webcomponents-core";
10
+ import { ODataDataSourceFilterExpressionVisitor } from "igniteui-webcomponents-core";
11
+ import { ListSortDirection } from "igniteui-webcomponents-core";
12
+ import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
13
+ import { SummaryOperand } from "igniteui-webcomponents-core";
14
+ import { DataSourceSummaryScope } from "igniteui-webcomponents-core";
15
+ import { DefaultSummaryResult } from "igniteui-webcomponents-core";
16
+ import { LocalDataSource } from "igniteui-webcomponents-core";
17
+ var RestVirtualDataSourceDataProviderWorker = /** @class */ /*@__PURE__*/ (function (_super) {
18
+ tslib_1.__extends(RestVirtualDataSourceDataProviderWorker, _super);
19
+ function RestVirtualDataSourceDataProviderWorker(settings) {
20
+ var e_1, _a;
21
+ var _this = _super.call(this, settings) || this;
22
+ _this._baseUri = null;
23
+ _this._entitySet = null;
24
+ _this._sortDescriptions = null;
25
+ _this._groupDescriptions = null;
26
+ _this._filterExpressions = null;
27
+ _this._summaryDescriptions = null;
28
+ _this._desiredPropeties = null;
29
+ _this._enableJsonp = true;
30
+ _this._isAggregationSupported = false;
31
+ _this._provideFullCount = null;
32
+ _this._provideOrderByParameter = null;
33
+ _this._provideFilterParameter = null;
34
+ _this._provideAggregationParameter = null;
35
+ _this._provideAggregatedCount = null;
36
+ _this._providePagingParameter = null;
37
+ _this._provideDesiredPropertiesParameter = null;
38
+ _this._provideUri = null;
39
+ _this._performFetch = null;
40
+ _this._fixedFullCount = -1;
41
+ _this._groupInformation = null;
42
+ _this._summaryInformation = null;
43
+ _this._filterString = null;
44
+ _this._selectedString = null;
45
+ _this.doWork = _this.doWork.bind(_this);
46
+ _this._baseUri = settings.baseUri;
47
+ _this._entitySet = settings.entitySet;
48
+ _this._sortDescriptions = settings.sortDescriptions;
49
+ _this._groupDescriptions = settings.groupDescriptions;
50
+ if (_this._groupDescriptions != null && _this._groupDescriptions.size() > 0) {
51
+ _this._sortDescriptions = new SortDescriptionCollection();
52
+ try {
53
+ for (var _b = tslib_1.__values(_this.iter(settings.sortDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
54
+ var sd = _c.value;
55
+ _this._sortDescriptions.add(sd);
56
+ }
57
+ }
58
+ catch (e_1_1) {
59
+ e_1 = { error: e_1_1 };
60
+ }
61
+ finally {
62
+ try {
63
+ if (_c && !_c.done && (_a = _b.return))
64
+ _a.call(_b);
65
+ }
66
+ finally {
67
+ if (e_1)
68
+ throw e_1.error;
69
+ }
70
+ }
71
+ for (var i = 0; i < _this._groupDescriptions.size(); i++) {
72
+ _this._sortDescriptions.insert(i, _this._groupDescriptions.get(i));
73
+ }
74
+ }
75
+ _this._filterExpressions = settings.filterExpressions;
76
+ _this._desiredPropeties = settings.propertiesRequested;
77
+ _this._summaryDescriptions = settings.summaryDescriptions;
78
+ _this._fixedFullCount = settings.fixedFullCount;
79
+ _this._summaryScope = settings.summaryScope;
80
+ _this._enableJsonp = settings.enableJsonp;
81
+ _this._provideFullCount = settings.provideFullCount;
82
+ _this._performFetch = settings.performFetch;
83
+ _this._provideAggregationParameter = settings.provideAggregationParameter;
84
+ _this._provideFilterParameter = settings.provideFilterParameter;
85
+ _this._provideOrderByParameter = settings.provideOrderByParameter;
86
+ _this._provideUri = settings.provideUri;
87
+ _this._providePagingParameter = settings.providePagingParameter;
88
+ _this._provideDesiredPropertiesParameter = settings.provideDesiredPropertiesParameter;
89
+ _this._provideItems = settings.provideItems;
90
+ _this._provideAggregatedCount = settings.provideAggregatedCount;
91
+ if (!_this._provideItems) {
92
+ _this._provideItems = function (res) {
93
+ return res ? res.items : null;
94
+ };
95
+ }
96
+ if (!_this._provideFullCount) {
97
+ _this._provideFullCount = function (p) {
98
+ if (p.fullCount) {
99
+ return p.fullCount;
100
+ }
101
+ else {
102
+ return _this._fixedFullCount >= 0 ? _this._fixedFullCount : 0;
103
+ }
104
+ };
105
+ }
106
+ if (!_this._provideOrderByParameter) {
107
+ _this._provideOrderByParameter = function (args, orderByString, orderBy) {
108
+ args.push({ name: "orderBy", value: encodeURIComponent(orderByString) });
109
+ };
110
+ }
111
+ if (!_this._providePagingParameter) {
112
+ _this._providePagingParameter = function (args, skip, take) {
113
+ args.push({ name: "skip", value: skip });
114
+ args.push({ name: "take", value: take });
115
+ };
116
+ }
117
+ if (!_this._provideAggregationParameter) {
118
+ _this._provideAggregationParameter = function (args, fetchCountOnly, groupByString, groupBy, summaryString, summary) {
119
+ args.push({ name: "groupBy", value: groupByString });
120
+ args.push({ name: "aggregate", value: "count" });
121
+ };
122
+ }
123
+ if (!_this._provideUri) {
124
+ _this._provideUri = function (baseUri, entitySet, args) {
125
+ var requestUri = baseUri;
126
+ requestUri += "/" + entitySet;
127
+ if (args.length > 0) {
128
+ requestUri += "?";
129
+ }
130
+ var argsString = "";
131
+ for (var i = 0; i < args.length; i++) {
132
+ if (i > 0) {
133
+ argsString += "&";
134
+ }
135
+ argsString += args[i].name + "=" + args[i].value;
136
+ }
137
+ return requestUri + argsString;
138
+ };
139
+ }
140
+ _this._isAggregationSupported = settings.isAggregationSupported;
141
+ window.setTimeout(_this.doWork, 100);
142
+ return _this;
143
+ }
144
+ Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "sortDescriptions", {
145
+ get: function () {
146
+ return this._sortDescriptions;
147
+ },
148
+ enumerable: true,
149
+ configurable: true
150
+ });
151
+ Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "filterExpressions", {
152
+ get: function () {
153
+ return this._filterExpressions;
154
+ },
155
+ enumerable: true,
156
+ configurable: true
157
+ });
158
+ Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "desiredProperties", {
159
+ get: function () {
160
+ return this._desiredPropeties;
161
+ },
162
+ enumerable: true,
163
+ configurable: true
164
+ });
165
+ RestVirtualDataSourceDataProviderWorker.prototype.initialize = function () {
166
+ _super.prototype.initialize.call(this);
167
+ };
168
+ RestVirtualDataSourceDataProviderWorker.prototype.getTaskDataHolder = function () {
169
+ var holder = new RestVirtualDataSourceProviderTaskDataHolder();
170
+ return holder;
171
+ };
172
+ RestVirtualDataSourceDataProviderWorker.prototype.getCompletedTaskData = function (holder, completed) {
173
+ _super.prototype.getCompletedTaskData.call(this, holder, completed);
174
+ };
175
+ RestVirtualDataSourceDataProviderWorker.prototype.removeCompletedTaskData = function (holder, completed) {
176
+ _super.prototype.removeCompletedTaskData.call(this, holder, completed);
177
+ };
178
+ RestVirtualDataSourceDataProviderWorker.prototype.getTasksData = function (holder) {
179
+ _super.prototype.getTasksData.call(this, holder);
180
+ };
181
+ RestVirtualDataSourceDataProviderWorker.prototype.iter = function (coll) {
182
+ var i;
183
+ return tslib_1.__generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0:
186
+ i = 0;
187
+ _a.label = 1;
188
+ case 1:
189
+ if (!(i < coll.size()))
190
+ return [3 /*break*/, 4];
191
+ return [4 /*yield*/, coll.get(i)];
192
+ case 2:
193
+ _a.sent();
194
+ _a.label = 3;
195
+ case 3:
196
+ i++;
197
+ return [3 /*break*/, 1];
198
+ case 4: return [2 /*return*/];
199
+ }
200
+ });
201
+ };
202
+ RestVirtualDataSourceDataProviderWorker.prototype.iterFilter = function (coll) {
203
+ var i;
204
+ return tslib_1.__generator(this, function (_a) {
205
+ switch (_a.label) {
206
+ case 0:
207
+ i = 0;
208
+ _a.label = 1;
209
+ case 1:
210
+ if (!(i < coll.size()))
211
+ return [3 /*break*/, 4];
212
+ return [4 /*yield*/, coll.get(i)];
213
+ case 2:
214
+ _a.sent();
215
+ _a.label = 3;
216
+ case 3:
217
+ i++;
218
+ return [3 /*break*/, 1];
219
+ case 4: return [2 /*return*/];
220
+ }
221
+ });
222
+ };
223
+ RestVirtualDataSourceDataProviderWorker.prototype.iterSummaries = function (summaries) {
224
+ var i;
225
+ return tslib_1.__generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0:
228
+ i = 0;
229
+ _a.label = 1;
230
+ case 1:
231
+ if (!(i < summaries.size()))
232
+ return [3 /*break*/, 4];
233
+ return [4 /*yield*/, summaries.get(i)];
234
+ case 2:
235
+ _a.sent();
236
+ _a.label = 3;
237
+ case 3:
238
+ i++;
239
+ return [3 /*break*/, 1];
240
+ case 4: return [2 /*return*/];
241
+ }
242
+ });
243
+ };
244
+ RestVirtualDataSourceDataProviderWorker.prototype.processCompletedTask = function (completedTask, currentDelay, pageIndex, taskDataHolder) {
245
+ var _this = this;
246
+ var h = taskDataHolder;
247
+ var schema = null;
248
+ var result = null;
249
+ var schemaFetchCount = -1;
250
+ var task = completedTask.task;
251
+ try {
252
+ if (task.hasErrors) {
253
+ this.retryIndex(pageIndex, currentDelay);
254
+ return;
255
+ }
256
+ if (pageIndex == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
257
+ result = task.result;
258
+ schemaFetchCount = (this._provideFullCount(result));
259
+ }
260
+ else {
261
+ result = task.result;
262
+ }
263
+ }
264
+ catch (e) {
265
+ this.retryIndex(pageIndex, currentDelay);
266
+ return;
267
+ }
268
+ if (schemaFetchCount >= 0) {
269
+ this.actualCount = schemaFetchCount;
270
+ }
271
+ else {
272
+ this.actualCount = (this._provideFullCount(result));
273
+ }
274
+ schema = this.actualSchema;
275
+ if (schema == null) {
276
+ var requests_1 = 0;
277
+ this.resolveSchema(function (s) {
278
+ // resolveSchema success callback
279
+ _this.actualSchema = s;
280
+ if (_this._isAggregationSupported && (_this._groupDescriptions.size() !== 0 || _this._summaryDescriptions.size() !== 0)) {
281
+ if (_this._groupDescriptions.size() > 0) {
282
+ requests_1++;
283
+ _this.resolveGroupInformation(function (g) {
284
+ // group info success
285
+ requests_1--;
286
+ if (requests_1 === 0) {
287
+ _this.finishProcessingCompletedTask(task, pageIndex, s, result);
288
+ }
289
+ }, function () {
290
+ // group info failure
291
+ _this.retryIndex(pageIndex, currentDelay);
292
+ return;
293
+ });
294
+ }
295
+ if (_this._summaryDescriptions.size() > 0) {
296
+ requests_1++;
297
+ _this.resolveSummaryInformation(function (g) {
298
+ // summary info success
299
+ requests_1--;
300
+ if (requests_1 === 0) {
301
+ _this.finishProcessingCompletedTask(task, pageIndex, s, result);
302
+ }
303
+ }, function () {
304
+ // summary info failure
305
+ _this.retryIndex(pageIndex, currentDelay);
306
+ return;
307
+ });
308
+ }
309
+ }
310
+ else {
311
+ _this.finishProcessingCompletedTask(task, pageIndex, s, result);
312
+ }
313
+ }, function () {
314
+ // resolveSchema failure callback
315
+ _this.retryIndex(pageIndex, currentDelay);
316
+ return;
317
+ });
318
+ return;
319
+ }
320
+ this.finishProcessingCompletedTask(task, pageIndex, schema, result);
321
+ };
322
+ RestVirtualDataSourceDataProviderWorker.prototype.finishProcessingCompletedTask = function (task, pageIndex, schema, result) {
323
+ var _this = this;
324
+ var executionContext;
325
+ var pageLoaded;
326
+ var groupInformation;
327
+ var summaryInformation;
328
+ this.actualSchema = schema;
329
+ executionContext = this.executionContext;
330
+ groupInformation = this._groupInformation;
331
+ summaryInformation = this._summaryInformation;
332
+ pageLoaded = this.pageLoaded;
333
+ var page = null;
334
+ if (result != null) {
335
+ page = new RestVirtualDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex);
336
+ if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) {
337
+ this.populatedActualPageSize = true;
338
+ this.actualPageSize = page.count();
339
+ }
340
+ }
341
+ else {
342
+ page = new RestVirtualDataSourcePage(null, schema, groupInformation, summaryInformation, pageIndex);
343
+ }
344
+ if (this.pageLoaded != null) {
345
+ if (this.executionContext != null) {
346
+ if (executionContext == null || pageLoaded == null) {
347
+ this.shutdown();
348
+ return;
349
+ }
350
+ executionContext.execute(function () { return pageLoaded(page, _this.actualCount, _this.actualPageSize); });
351
+ }
352
+ else {
353
+ if (pageLoaded == null) {
354
+ this.shutdown();
355
+ return;
356
+ }
357
+ pageLoaded(page, this.actualCount, this.actualPageSize);
358
+ }
359
+ }
360
+ };
361
+ RestVirtualDataSourceDataProviderWorker.prototype.resolveGroupInformation = function (finishAction, failureAction) {
362
+ var e_2, _a;
363
+ var _this = this;
364
+ if (this._groupInformation != null) {
365
+ finishAction(this._groupInformation);
366
+ return;
367
+ }
368
+ var orderBy = "";
369
+ var groupBy = "";
370
+ var filter = null;
371
+ var summary = "";
372
+ if (this._groupDescriptions == null || this._groupDescriptions.size() == 0) {
373
+ finishAction(null);
374
+ return;
375
+ }
376
+ if (this._provideAggregationParameter == null) {
377
+ finishAction(null);
378
+ return;
379
+ }
380
+ filter = this._filterString;
381
+ this.updateFilterString();
382
+ if (this._groupDescriptions != null) {
383
+ var first1 = true;
384
+ try {
385
+ for (var _b = tslib_1.__values(this.iter(this._groupDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
386
+ var group = _c.value;
387
+ if (first1) {
388
+ first1 = false;
389
+ }
390
+ else {
391
+ orderBy += ", ";
392
+ groupBy += ", ";
393
+ }
394
+ groupBy += group.propertyName;
395
+ if (group.direction === ListSortDirection.Descending) {
396
+ orderBy += group.propertyName + " desc";
397
+ }
398
+ else {
399
+ orderBy += group.propertyName + " asc";
400
+ }
401
+ }
402
+ }
403
+ catch (e_2_1) {
404
+ e_2 = { error: e_2_1 };
405
+ }
406
+ finally {
407
+ try {
408
+ if (_c && !_c.done && (_a = _b.return))
409
+ _a.call(_b);
410
+ }
411
+ finally {
412
+ if (e_2)
413
+ throw e_2.error;
414
+ }
415
+ }
416
+ }
417
+ if (this._summaryScope === DataSourceSummaryScope.Both || this._summaryScope === DataSourceSummaryScope.Groups) {
418
+ var summaryParameters = this.getSummaryQueryParameters(true);
419
+ if (!stringIsNullOrEmpty(summaryParameters)) {
420
+ summary = ", " + summaryParameters;
421
+ }
422
+ }
423
+ var args = [];
424
+ if (this._provideOrderByParameter) {
425
+ this._provideOrderByParameter(args, orderBy, this._groupDescriptions);
426
+ }
427
+ if (this._provideFilterParameter && filter != null) {
428
+ this._provideFilterParameter(args, filter, this._filterExpressions);
429
+ }
430
+ if (this._provideAggregationParameter) {
431
+ this._provideAggregationParameter(args, true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions);
432
+ }
433
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
434
+ try {
435
+ var groupInformation_1 = [];
436
+ var success_1 = function (data, response) { return _this.groupSuccess(data, response, finishAction, failureAction, groupInformation_1); };
437
+ var failure_1 = function (err) { return _this.groupError(err, finishAction, failureAction, groupInformation_1); };
438
+ var run_ = null;
439
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
440
+ var request = {
441
+ requestUri: uri,
442
+ enableJsonpCallback: this._enableJsonp,
443
+ method: 'GET',
444
+ headers: headers,
445
+ data: null
446
+ };
447
+ run_ = function () {
448
+ _this.fetchUri(request, success_1, failure_1);
449
+ };
450
+ run_();
451
+ }
452
+ catch (e) {
453
+ failureAction();
454
+ }
455
+ };
456
+ RestVirtualDataSourceDataProviderWorker.prototype.fetchUri = function (request, success, failure) {
457
+ if (this._performFetch) {
458
+ this._performFetch(request, success, failure);
459
+ }
460
+ else {
461
+ fetch(request.requestUri, {
462
+ method: request.method,
463
+ headers: request.headers,
464
+ }).then(function (res) {
465
+ res.json().then(function (j) {
466
+ success(j, res);
467
+ });
468
+ }).catch(function (e) {
469
+ failure(e);
470
+ });
471
+ }
472
+ };
473
+ RestVirtualDataSourceDataProviderWorker.prototype.groupError = function (err, finishAction, failureAction, groupInformation) {
474
+ this._groupInformation = null;
475
+ };
476
+ RestVirtualDataSourceDataProviderWorker.prototype.groupSuccess = function (data, response, finishAction, failureAction, groupInformation) {
477
+ var e_3, _a;
478
+ var groupNames = [];
479
+ try {
480
+ for (var _b = tslib_1.__values(this.iter(this._groupDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
481
+ var group = _c.value;
482
+ groupNames.push(group.propertyName);
483
+ }
484
+ }
485
+ catch (e_3_1) {
486
+ e_3 = { error: e_3_1 };
487
+ }
488
+ finally {
489
+ try {
490
+ if (_c && !_c.done && (_a = _b.return))
491
+ _a.call(_b);
492
+ }
493
+ finally {
494
+ if (e_3)
495
+ throw e_3.error;
496
+ }
497
+ }
498
+ var groupNamesArray = groupNames;
499
+ var items = this._provideItems(data);
500
+ if (items && items.length > 0) {
501
+ var currentIndex = 0;
502
+ for (var i = 0; i < items.length; i++) {
503
+ this.addGroup(groupInformation, groupNames, groupNames, currentIndex, items[i]);
504
+ }
505
+ }
506
+ this._groupInformation = groupInformation;
507
+ finishAction(this._groupInformation);
508
+ };
509
+ RestVirtualDataSourceDataProviderWorker.prototype.addGroup = function (groupInformation, groupNames, groupNamesArray, currentIndex, group) {
510
+ var e_4, _a;
511
+ var groupValues = [];
512
+ try {
513
+ for (var groupNames_1 = tslib_1.__values(groupNames), groupNames_1_1 = groupNames_1.next(); !groupNames_1_1.done; groupNames_1_1 = groupNames_1.next()) {
514
+ var name_1 = groupNames_1_1.value;
515
+ if (group[name_1]) {
516
+ groupValues.push(group[name_1]);
517
+ }
518
+ }
519
+ }
520
+ catch (e_4_1) {
521
+ e_4 = { error: e_4_1 };
522
+ }
523
+ finally {
524
+ try {
525
+ if (groupNames_1_1 && !groupNames_1_1.done && (_a = groupNames_1.return))
526
+ _a.call(groupNames_1);
527
+ }
528
+ finally {
529
+ if (e_4)
530
+ throw e_4.error;
531
+ }
532
+ }
533
+ var groupCount = 0;
534
+ //todo: make this customizable
535
+ if (this._provideAggregatedCount) {
536
+ var ct = this._provideAggregatedCount(group);
537
+ }
538
+ else {
539
+ if (group["aggregatedCount"]) {
540
+ groupCount = Convert.toInt321(group["aggregatedCount"]);
541
+ }
542
+ }
543
+ var summaryResults = null;
544
+ if (this._summaryScope == DataSourceSummaryScope.Both || this._summaryScope == DataSourceSummaryScope.Groups) {
545
+ summaryResults = this.createSummaryResults(group);
546
+ }
547
+ var groupInfo = new DefaultSectionInformation(currentIndex, currentIndex + (groupCount - 1), groupNamesArray, groupValues, summaryResults);
548
+ groupInformation.push(groupInfo);
549
+ };
550
+ RestVirtualDataSourceDataProviderWorker.prototype.resolveSummaryInformation = function (finishAction, failureAction) {
551
+ var _this = this;
552
+ if (this._summaryInformation != null) {
553
+ finishAction(this._summaryInformation);
554
+ return;
555
+ }
556
+ var filter = null;
557
+ var summary = null;
558
+ if (this._summaryDescriptions == null ||
559
+ this._summaryDescriptions.size() == 0 ||
560
+ this._summaryScope == DataSourceSummaryScope.Groups ||
561
+ this._summaryScope == DataSourceSummaryScope.None) {
562
+ finishAction(null);
563
+ return;
564
+ }
565
+ filter = this._filterString;
566
+ this.updateFilterString();
567
+ summary = this.getSummaryQueryParameters(false);
568
+ var args = [];
569
+ // if (this._provideOrderByParameter) {
570
+ // args.push({ name: "orderBy", value: this._provideOrderByParameter(orderBy, this._sortDescriptions) });
571
+ // }
572
+ if (this._provideFilterParameter && filter != null) {
573
+ this._provideFilterParameter(args, filter, this._filterExpressions);
574
+ }
575
+ if (this._provideAggregationParameter) {
576
+ this._provideAggregationParameter(args, true, null, null, summary, this._summaryDescriptions);
577
+ }
578
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
579
+ // let commandText = this._entitySet + "?$apply=";
580
+ // if (!stringIsNullOrEmpty(filter)) {
581
+ // commandText += "filter(" + filter + ")/";
582
+ // }
583
+ // commandText += "aggregate(" + summary + ")";
584
+ try {
585
+ var summaryInformation_1 = [];
586
+ var success_2 = function (data, response) { return _this.summarySuccess(data, response, finishAction, failureAction, summaryInformation_1); };
587
+ var failure_2 = function (err) { return _this.summaryError(err, finishAction, failureAction, summaryInformation_1); };
588
+ var run_ = null;
589
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
590
+ var request = {
591
+ requestUri: uri,
592
+ enableJsonpCallback: this._enableJsonp,
593
+ method: 'GET',
594
+ headers: headers,
595
+ data: null
596
+ };
597
+ run_ = function () {
598
+ _this.fetchUri(request, success_2, failure_2);
599
+ };
600
+ run_();
601
+ }
602
+ catch (e) {
603
+ failureAction();
604
+ }
605
+ };
606
+ RestVirtualDataSourceDataProviderWorker.prototype.summarySuccess = function (data, response, finishAction, failureAction, summaryInformation) {
607
+ if (data && data.value && data.value.length > 0) {
608
+ summaryInformation = this.createSummaryResults(data.value[0]);
609
+ }
610
+ this._summaryInformation = summaryInformation;
611
+ finishAction(this._summaryInformation);
612
+ };
613
+ RestVirtualDataSourceDataProviderWorker.prototype.summaryError = function (err, finishAction, failureAction, summaryInformation) {
614
+ this._summaryInformation = null;
615
+ };
616
+ RestVirtualDataSourceDataProviderWorker.prototype.getSummaryQueryParameters = function (ignoreCount) {
617
+ var e_5, _a;
618
+ var result = "";
619
+ if (this._summaryDescriptions != null) {
620
+ var first = true;
621
+ var countExists = false;
622
+ try {
623
+ for (var _b = tslib_1.__values(this.iterSummaries(this._summaryDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
624
+ var summary = _c.value;
625
+ if (summary.operand == SummaryOperand.Count && (ignoreCount || countExists)) {
626
+ continue;
627
+ }
628
+ if (!first) {
629
+ result += ", ";
630
+ }
631
+ switch (summary.operand) {
632
+ case SummaryOperand.Average:
633
+ result += summary.propertyName + " with average as " + summary.propertyName + "Average";
634
+ break;
635
+ case SummaryOperand.Min:
636
+ result += summary.propertyName + " with min as " + summary.propertyName + "Min";
637
+ break;
638
+ case SummaryOperand.Max:
639
+ result += summary.propertyName + " with max as " + summary.propertyName + "Max";
640
+ break;
641
+ case SummaryOperand.Sum:
642
+ result += summary.propertyName + " with sum as " + summary.propertyName + "Sum";
643
+ break;
644
+ case SummaryOperand.Count:
645
+ result += "$count as $__count";
646
+ countExists = true;
647
+ break;
648
+ }
649
+ first = false;
650
+ }
651
+ }
652
+ catch (e_5_1) {
653
+ e_5 = { error: e_5_1 };
654
+ }
655
+ finally {
656
+ try {
657
+ if (_c && !_c.done && (_a = _b.return))
658
+ _a.call(_b);
659
+ }
660
+ finally {
661
+ if (e_5)
662
+ throw e_5.error;
663
+ }
664
+ }
665
+ }
666
+ return result;
667
+ };
668
+ RestVirtualDataSourceDataProviderWorker.prototype.createSummaryResults = function (data) {
669
+ var e_6, _a;
670
+ var summaryResults = [];
671
+ try {
672
+ for (var _b = tslib_1.__values(this.iterSummaries(this._summaryDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
673
+ var summary = _c.value;
674
+ var summaryName = summary.propertyName;
675
+ switch (summary.operand) {
676
+ case SummaryOperand.Average:
677
+ summaryName += "Average";
678
+ break;
679
+ case SummaryOperand.Min:
680
+ summaryName += "Min";
681
+ break;
682
+ case SummaryOperand.Max:
683
+ summaryName += "Max";
684
+ break;
685
+ case SummaryOperand.Sum:
686
+ summaryName += "Sum";
687
+ break;
688
+ case SummaryOperand.Count:
689
+ summaryName = "$__count";
690
+ break;
691
+ }
692
+ var summaryValue = null;
693
+ if (data && data[summaryName]) {
694
+ summaryValue = data[summaryName];
695
+ }
696
+ var summaryResult = new DefaultSummaryResult(summary.propertyName, summary.operand, summaryValue);
697
+ summaryResults.push(summaryResult);
698
+ }
699
+ }
700
+ catch (e_6_1) {
701
+ e_6 = { error: e_6_1 };
702
+ }
703
+ finally {
704
+ try {
705
+ if (_c && !_c.done && (_a = _b.return))
706
+ _a.call(_b);
707
+ }
708
+ finally {
709
+ if (e_6)
710
+ throw e_6.error;
711
+ }
712
+ }
713
+ return summaryResults;
714
+ };
715
+ RestVirtualDataSourceDataProviderWorker.prototype.resolveSchemaFromItems = function (items) {
716
+ var lds = new LocalDataSource();
717
+ lds.dataSource = items;
718
+ lds.flushAutoRefresh();
719
+ return lds.actualSchema;
720
+ };
721
+ RestVirtualDataSourceDataProviderWorker.prototype.resolveSchema = function (finishAction, failureAction) {
722
+ var _this = this;
723
+ if (!this._provideItems || !this._providePagingParameter) {
724
+ failureAction("required providers for items and paging are not specified");
725
+ return;
726
+ }
727
+ var success_ = function (res) {
728
+ var items = _this._provideItems(res);
729
+ if (items && items.length > 0) {
730
+ var schema = _this.resolveSchemaFromItems(items);
731
+ finishAction(schema);
732
+ }
733
+ else {
734
+ failureAction("could not find items to resolve schema");
735
+ }
736
+ };
737
+ var failure_ = function (e) { return failureAction(e); };
738
+ var args = [];
739
+ if (this._providePagingParameter) {
740
+ this._providePagingParameter(args, 0, this.actualPageSize);
741
+ }
742
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
743
+ try {
744
+ var run_ = null;
745
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
746
+ var request = {
747
+ requestUri: uri,
748
+ enableJsonpCallback: this._enableJsonp,
749
+ method: 'GET',
750
+ headers: headers,
751
+ data: null
752
+ };
753
+ run_ = function () {
754
+ _this.fetchUri(request, success_, failure_);
755
+ };
756
+ run_();
757
+ }
758
+ catch (e) {
759
+ failureAction(e);
760
+ }
761
+ };
762
+ RestVirtualDataSourceDataProviderWorker.prototype.makeTaskForRequest = function (request, retryDelay) {
763
+ var e_7, _a;
764
+ var args = [];
765
+ // if (this._provideAggregationParameter) {
766
+ // args.push({ name: "apply", value: this._provideAggregationParameter(true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions) });
767
+ // }
768
+ var actualPageSize = 0;
769
+ var sortDescriptions = null;
770
+ actualPageSize = this.actualPageSize;
771
+ sortDescriptions = this.sortDescriptions;
772
+ //let requestUrl: string = this._baseUri;
773
+ //requestUrl += "/" + this._entitySet;
774
+ var queryStarted = false;
775
+ this.updateFilterString();
776
+ if (this._filterString != null) {
777
+ if (this._provideFilterParameter) {
778
+ this._provideFilterParameter(args, this._filterString, this._filterExpressions);
779
+ }
780
+ }
781
+ if (this.sortDescriptions != null) {
782
+ var sortString = null;
783
+ try {
784
+ for (var _b = tslib_1.__values(this.iter(this.sortDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
785
+ var sort = _c.value;
786
+ if (sortString == null) {
787
+ sortString = "";
788
+ }
789
+ else {
790
+ sortString += ", ";
791
+ }
792
+ if (sort.direction == ListSortDirection.Descending) {
793
+ sortString += sort.propertyName + " desc";
794
+ }
795
+ else {
796
+ sortString += sort.propertyName;
797
+ }
798
+ }
799
+ }
800
+ catch (e_7_1) {
801
+ e_7 = { error: e_7_1 };
802
+ }
803
+ finally {
804
+ try {
805
+ if (_c && !_c.done && (_a = _b.return))
806
+ _a.call(_b);
807
+ }
808
+ finally {
809
+ if (e_7)
810
+ throw e_7.error;
811
+ }
812
+ }
813
+ if (sortString != null) {
814
+ if (this._provideOrderByParameter) {
815
+ this._provideOrderByParameter(args, sortString, this._sortDescriptions);
816
+ }
817
+ }
818
+ }
819
+ if (this.desiredProperties != null && this.desiredProperties.length > 0) {
820
+ var selectString = "";
821
+ var first = true;
822
+ var $t = this.desiredProperties;
823
+ for (var i = 0; i < $t.length; i++) {
824
+ var select = $t[i];
825
+ if (first) {
826
+ first = false;
827
+ }
828
+ else {
829
+ selectString += ", ";
830
+ }
831
+ selectString += select;
832
+ }
833
+ if (this._provideDesiredPropertiesParameter) {
834
+ this._provideDesiredPropertiesParameter(args, selectString, this._desiredPropeties);
835
+ }
836
+ }
837
+ if (this._providePagingParameter) {
838
+ if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
839
+ this._providePagingParameter(args, 0, actualPageSize);
840
+ }
841
+ else {
842
+ this._providePagingParameter(args, request.index * actualPageSize, actualPageSize);
843
+ }
844
+ }
845
+ var task = new AsyncVirtualDataTask();
846
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
847
+ if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
848
+ this.executeRequest(uri, queryStarted, 0, actualPageSize, task);
849
+ }
850
+ else {
851
+ this.executeRequest(uri, queryStarted, request.index * actualPageSize, actualPageSize, task);
852
+ }
853
+ request.taskHolder = new AsyncDataSourcePageTaskHolder();
854
+ request.taskHolder.task = task;
855
+ this.tasks.add(request);
856
+ };
857
+ RestVirtualDataSourceDataProviderWorker.prototype.updateFilterString = function () {
858
+ var e_8, _a;
859
+ if (this.filterExpressions != null && this.filterExpressions.size() > 0 && this._filterString == null) {
860
+ var sb = "";
861
+ var first = true;
862
+ try {
863
+ for (var _b = tslib_1.__values(this.iterFilter(this.filterExpressions)), _c = _b.next(); !_c.done; _c = _b.next()) {
864
+ var expr = _c.value;
865
+ if (first) {
866
+ first = false;
867
+ }
868
+ else {
869
+ sb += " AND ";
870
+ }
871
+ var visitor = new ODataDataSourceFilterExpressionVisitor(0);
872
+ visitor.visit(expr);
873
+ var txt = visitor.toString();
874
+ if (this.filterExpressions.size() > 1) {
875
+ txt = "(" + txt + ")";
876
+ }
877
+ sb += (txt);
878
+ }
879
+ }
880
+ catch (e_8_1) {
881
+ e_8 = { error: e_8_1 };
882
+ }
883
+ finally {
884
+ try {
885
+ if (_c && !_c.done && (_a = _b.return))
886
+ _a.call(_b);
887
+ }
888
+ finally {
889
+ if (e_8)
890
+ throw e_8.error;
891
+ }
892
+ }
893
+ this._filterString = sb;
894
+ }
895
+ };
896
+ RestVirtualDataSourceDataProviderWorker.prototype.executeRequest = function (requestUrl, queryStarted, skip, top, task) {
897
+ var _this = this;
898
+ // if (!queryStarted) {
899
+ // queryStarted = true;
900
+ // requestUrl += "?";
901
+ // } else {
902
+ // requestUrl += "&";
903
+ // }
904
+ // requestUrl += "$skip=" + skip + "&$top=" + top + "&$count=true";
905
+ var requestUrl_ = requestUrl;
906
+ var self_ = this;
907
+ var success_ = function (data, response) { return _this.success(task, data, response); };
908
+ var failure_ = function (err) { return _this.error(task, err); };
909
+ var run_ = null;
910
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
911
+ var request = {
912
+ requestUri: requestUrl_,
913
+ enableJsonpCallback: this._enableJsonp,
914
+ method: 'GET',
915
+ headers: headers,
916
+ data: null
917
+ };
918
+ run_ = function () {
919
+ _this.fetchUri(request, success_, failure_);
920
+ };
921
+ task.run = run_;
922
+ };
923
+ RestVirtualDataSourceDataProviderWorker.prototype.success = function (t, data, response) {
924
+ t.result = data;
925
+ t.isCompleted = true;
926
+ };
927
+ RestVirtualDataSourceDataProviderWorker.prototype.error = function (t, result) {
928
+ t.isCompleted = true;
929
+ t.hasErrors = true;
930
+ };
931
+ RestVirtualDataSourceDataProviderWorker.prototype.createBatchRequest = function (changes) {
932
+ //TODO: updates
933
+ };
934
+ RestVirtualDataSourceDataProviderWorker.prototype.getRequestUriWithKey = function (key) {
935
+ var result = "";
936
+ var keys = Object.keys(key);
937
+ for (var i = 0; i < keys.length; i++) {
938
+ if (i > 0) {
939
+ result += ",";
940
+ }
941
+ result += keys[i] + "=" + key[keys[i]];
942
+ }
943
+ return this._entitySet + "(" + result + ")";
944
+ };
945
+ RestVirtualDataSourceDataProviderWorker.schemaRequestIndex = -1;
946
+ return RestVirtualDataSourceDataProviderWorker;
947
+ }(AsyncVirtualDataSourceProviderWorker));
948
+ export { RestVirtualDataSourceDataProviderWorker };