igniteui-webcomponents-datasources 7.1.1-beta.0 → 7.1.1-beta.2

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