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

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