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,710 @@
1
+ import { AsyncVirtualDataSourceProviderWorker } from "igniteui-webcomponents-core";
2
+ import { SortDescriptionCollection } from "igniteui-webcomponents-core";
3
+ import { ODataVirtualDataSourceProviderTaskDataHolder } from "./ODataVirtualDataSourceProviderTaskDataHolder";
4
+ import { AsyncDataSourcePageTaskHolder } from "igniteui-webcomponents-core";
5
+ import { AsyncVirtualDataTask } from "igniteui-webcomponents-core";
6
+ import { ODataDataSourcePage } from "./ODataDataSourcePage";
7
+ import { DefaultSectionInformation } from "igniteui-webcomponents-core";
8
+ import { Convert } from "igniteui-webcomponents-core";
9
+ import { ODataSchemaProvider } from "./ODataSchemaProvider";
10
+ import { ODataDataSourceFilterExpressionVisitor } from "igniteui-webcomponents-core";
11
+ import { ListSortDirection } from "igniteui-webcomponents-core";
12
+ import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
13
+ import { DataSourceSummaryOperand } from "igniteui-webcomponents-core";
14
+ import { DataSourceSummaryScope } from "igniteui-webcomponents-core";
15
+ import { DefaultSummaryResult } from "igniteui-webcomponents-core";
16
+ import { TransactionType } from "igniteui-webcomponents-core";
17
+ import { ODataDataSourceSchema } from "igniteui-webcomponents-core";
18
+ class ODataVirtualDataSourceDataProviderWorker 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 ODataVirtualDataSourceProviderTaskDataHolder();
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._groupInformation = null;
72
+ this._summaryInformation = null;
73
+ this._filterString = null;
74
+ this._selectedString = null;
75
+ this.doWork = this.doWork.bind(this);
76
+ this._baseUri = settings.baseUri;
77
+ this._entitySet = settings.entitySet;
78
+ this._sortDescriptions = settings.sortDescriptions;
79
+ this._groupDescriptions = settings.groupDescriptions;
80
+ if (this._groupDescriptions != null && this._groupDescriptions.size() > 0) {
81
+ this._sortDescriptions = new SortDescriptionCollection();
82
+ for (let sd of this.iter(settings.sortDescriptions)) {
83
+ this._sortDescriptions.add(sd);
84
+ }
85
+ for (let i = 0; i < this._groupDescriptions.size(); i++) {
86
+ this._sortDescriptions.insert(i, this._groupDescriptions.get(i));
87
+ }
88
+ }
89
+ this._filterExpressions = settings.filterExpressions;
90
+ this._desiredPropeties = settings.propertiesRequested;
91
+ if (settings.schemaIncludedProperties != null) {
92
+ this._schemaIncludedProperties = new Set();
93
+ for (let i = 0; i < settings.schemaIncludedProperties.length; i++) {
94
+ this._schemaIncludedProperties.add(settings.schemaIncludedProperties[i]);
95
+ }
96
+ }
97
+ this._summaryDescriptions = settings.summaryDescriptions;
98
+ this._summaryScope = settings.summaryScope;
99
+ this._enableJsonp = settings.enableJsonp;
100
+ this._isAggregationSupported = settings.isAggregationSupported;
101
+ window.setTimeout(this.doWork, 100);
102
+ }
103
+ processCompletedTask(completedTask, currentDelay, pageIndex, taskDataHolder) {
104
+ let h = taskDataHolder;
105
+ let schema = null;
106
+ let result = null;
107
+ let schemaFetchCount = -1;
108
+ let task = completedTask.task;
109
+ try {
110
+ if (task.hasErrors) {
111
+ this.retryIndex(pageIndex, currentDelay);
112
+ return;
113
+ }
114
+ if (pageIndex == ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
115
+ result = task.result;
116
+ schemaFetchCount = (result['@odata.count']);
117
+ }
118
+ else {
119
+ result = task.result;
120
+ }
121
+ }
122
+ catch (e) {
123
+ this.retryIndex(pageIndex, currentDelay);
124
+ return;
125
+ }
126
+ if (schemaFetchCount >= 0) {
127
+ this.actualCount = schemaFetchCount;
128
+ }
129
+ else {
130
+ this.actualCount = (result['@odata.count']);
131
+ }
132
+ schema = this.actualSchema;
133
+ if (schema == null) {
134
+ let requests = 0;
135
+ this.resolveSchema((s) => {
136
+ // resolveSchema success callback
137
+ this.actualSchema = s;
138
+ if (this._isAggregationSupported && (this._groupDescriptions.size() !== 0 || this._summaryDescriptions.size() !== 0)) {
139
+ if (this._groupDescriptions.size() > 0) {
140
+ requests++;
141
+ this.resolveGroupInformation((g) => {
142
+ // group info success
143
+ requests--;
144
+ if (requests === 0) {
145
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
146
+ }
147
+ }, () => {
148
+ // group info failure
149
+ this.retryIndex(pageIndex, currentDelay);
150
+ return;
151
+ });
152
+ }
153
+ if (this._summaryDescriptions.size() > 0) {
154
+ requests++;
155
+ this.resolveSummaryInformation((g) => {
156
+ // summary info success
157
+ requests--;
158
+ if (requests === 0) {
159
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
160
+ }
161
+ }, () => {
162
+ // summary info failure
163
+ this.retryIndex(pageIndex, currentDelay);
164
+ return;
165
+ });
166
+ }
167
+ }
168
+ else {
169
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
170
+ }
171
+ }, () => {
172
+ // resolveSchema failure callback
173
+ this.retryIndex(pageIndex, currentDelay);
174
+ return;
175
+ });
176
+ return;
177
+ }
178
+ this.finishProcessingCompletedTask(task, pageIndex, schema, result);
179
+ }
180
+ finishProcessingCompletedTask(task, pageIndex, schema, result) {
181
+ let executionContext;
182
+ let pageLoaded;
183
+ let groupInformation;
184
+ let summaryInformation;
185
+ this.actualSchema = schema;
186
+ executionContext = this.executionContext;
187
+ groupInformation = this._groupInformation;
188
+ summaryInformation = this._summaryInformation;
189
+ pageLoaded = this.pageLoaded;
190
+ let page = null;
191
+ if (result != null) {
192
+ page = new ODataDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex);
193
+ if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) {
194
+ this.populatedActualPageSize = true;
195
+ this.actualPageSize = page.count();
196
+ }
197
+ }
198
+ else {
199
+ page = new ODataDataSourcePage(null, schema, groupInformation, summaryInformation, pageIndex);
200
+ }
201
+ if (this.pageLoaded != null) {
202
+ if (this.executionContext != null) {
203
+ if (executionContext == null || pageLoaded == null) {
204
+ this.shutdown();
205
+ return;
206
+ }
207
+ executionContext.execute(() => pageLoaded(page, this.actualCount, this.actualPageSize));
208
+ }
209
+ else {
210
+ if (pageLoaded == null) {
211
+ this.shutdown();
212
+ return;
213
+ }
214
+ pageLoaded(page, this.actualCount, this.actualPageSize);
215
+ }
216
+ }
217
+ }
218
+ resolveGroupInformation(finishAction, failureAction) {
219
+ if (this._groupInformation != null) {
220
+ finishAction(this._groupInformation);
221
+ return;
222
+ }
223
+ let orderBy = "";
224
+ let groupBy = "";
225
+ let filter = null;
226
+ let summary = "";
227
+ if (this._groupDescriptions == null || this._groupDescriptions.size() == 0) {
228
+ finishAction(null);
229
+ return;
230
+ }
231
+ filter = this._filterString;
232
+ this.updateFilterString();
233
+ if (this._groupDescriptions != null) {
234
+ let first1 = true;
235
+ for (let group of this.iter(this._groupDescriptions)) {
236
+ if (first1) {
237
+ first1 = false;
238
+ }
239
+ else {
240
+ orderBy += ", ";
241
+ groupBy += ", ";
242
+ }
243
+ groupBy += group.propertyName;
244
+ if (group.direction === ListSortDirection.Descending) {
245
+ orderBy += group.propertyName + " desc";
246
+ }
247
+ else {
248
+ orderBy += group.propertyName + " asc";
249
+ }
250
+ }
251
+ }
252
+ if (this._summaryScope === DataSourceSummaryScope.Both || this._summaryScope === DataSourceSummaryScope.Groups) {
253
+ let summaryParameters = this.getSummaryQueryParameters(true);
254
+ if (!stringIsNullOrEmpty(summaryParameters)) {
255
+ summary = ", " + summaryParameters;
256
+ }
257
+ }
258
+ let commandText = this._entitySet + "?$orderby=" + orderBy + "&$apply=";
259
+ if (!stringIsNullOrEmpty(filter)) {
260
+ commandText += "filter(" + filter + ")/";
261
+ }
262
+ commandText += "groupby((" + groupBy + "), aggregate($count as $__count" + summary + "))";
263
+ try {
264
+ let groupInformation = [];
265
+ let success_ = (data, response) => this.groupSuccess(data, response, finishAction, failureAction, groupInformation);
266
+ let failure_ = (err) => this.groupError(err, finishAction, failureAction, groupInformation);
267
+ let run_ = null;
268
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
269
+ var request = {
270
+ requestUri: this._baseUri + "/" + commandText,
271
+ enableJsonpCallback: this._enableJsonp,
272
+ method: 'GET',
273
+ headers: headers,
274
+ data: null
275
+ };
276
+ run_ = function () {
277
+ odatajs.oData.request(request, success_, failure_);
278
+ };
279
+ run_();
280
+ }
281
+ catch (e) {
282
+ failureAction();
283
+ }
284
+ }
285
+ groupError(err, finishAction, failureAction, groupInformation) {
286
+ this._groupInformation = null;
287
+ }
288
+ groupSuccess(data, response, finishAction, failureAction, groupInformation) {
289
+ let groupNames = [];
290
+ for (let group of this.iter(this._groupDescriptions)) {
291
+ groupNames.push(group.propertyName);
292
+ }
293
+ let groupNamesArray = groupNames;
294
+ if (data && data.value && data.value.length > 0) {
295
+ let currentIndex = 0;
296
+ for (let i = 0; i < data.value.length; i++) {
297
+ this.addGroup(groupInformation, groupNames, groupNames, currentIndex, data.value[i]);
298
+ }
299
+ }
300
+ this._groupInformation = groupInformation;
301
+ finishAction(this._groupInformation);
302
+ }
303
+ addGroup(groupInformation, groupNames, groupNamesArray, currentIndex, group) {
304
+ let groupValues = [];
305
+ for (let name of groupNames) {
306
+ if (group[name]) {
307
+ groupValues.push(group[name]);
308
+ }
309
+ }
310
+ let groupCount = 0;
311
+ if (group["$__count"]) {
312
+ groupCount = Convert.toInt321(group["$__count"]);
313
+ }
314
+ let summaryResults = null;
315
+ if (this._summaryScope == DataSourceSummaryScope.Both || this._summaryScope == DataSourceSummaryScope.Groups) {
316
+ summaryResults = this.createSummaryResults(group);
317
+ }
318
+ let groupInfo = new DefaultSectionInformation(currentIndex, currentIndex + (groupCount - 1), groupNamesArray, groupValues, summaryResults);
319
+ groupInformation.push(groupInfo);
320
+ }
321
+ resolveSummaryInformation(finishAction, failureAction) {
322
+ if (this._summaryInformation != null) {
323
+ finishAction(this._summaryInformation);
324
+ return;
325
+ }
326
+ let filter = null;
327
+ let summary = null;
328
+ if (this._summaryDescriptions == null ||
329
+ this._summaryDescriptions.size() == 0 ||
330
+ this._summaryScope == DataSourceSummaryScope.Groups ||
331
+ this._summaryScope == DataSourceSummaryScope.None) {
332
+ finishAction(null);
333
+ return;
334
+ }
335
+ filter = this._filterString;
336
+ this.updateFilterString();
337
+ summary = this.getSummaryQueryParameters(false);
338
+ let commandText = this._entitySet + "?$apply=";
339
+ if (!stringIsNullOrEmpty(filter)) {
340
+ commandText += "filter(" + filter + ")/";
341
+ }
342
+ commandText += "aggregate(" + summary + ")";
343
+ try {
344
+ let summaryInformation = [];
345
+ let success_ = (data, response) => this.summarySuccess(data, response, finishAction, failureAction, summaryInformation);
346
+ let failure_ = (err) => this.summaryError(err, finishAction, failureAction, summaryInformation);
347
+ let run_ = null;
348
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
349
+ var request = {
350
+ requestUri: this._baseUri + "/" + commandText,
351
+ enableJsonpCallback: this._enableJsonp,
352
+ method: 'GET',
353
+ headers: headers,
354
+ data: null
355
+ };
356
+ run_ = function () {
357
+ odatajs.oData.request(request, success_, failure_);
358
+ };
359
+ run_();
360
+ }
361
+ catch (e) {
362
+ failureAction();
363
+ }
364
+ }
365
+ summarySuccess(data, response, finishAction, failureAction, summaryInformation) {
366
+ if (data && data.value && data.value.length > 0) {
367
+ summaryInformation = this.createSummaryResults(data.value[0]);
368
+ }
369
+ this._summaryInformation = summaryInformation;
370
+ finishAction(this._summaryInformation);
371
+ }
372
+ summaryError(err, finishAction, failureAction, summaryInformation) {
373
+ this._summaryInformation = null;
374
+ }
375
+ getSummaryQueryParameters(ignoreCount) {
376
+ let result = "";
377
+ if (this._summaryDescriptions != null) {
378
+ let first = true;
379
+ let countExists = false;
380
+ for (let summary of this.iterSummaries(this._summaryDescriptions)) {
381
+ if (summary.operand == DataSourceSummaryOperand.Count && (ignoreCount || countExists)) {
382
+ continue;
383
+ }
384
+ if (!first) {
385
+ result += ", ";
386
+ }
387
+ switch (summary.operand) {
388
+ case DataSourceSummaryOperand.Average:
389
+ result += summary.propertyName + " with average as " + summary.propertyName + "Average";
390
+ break;
391
+ case DataSourceSummaryOperand.Min:
392
+ result += summary.propertyName + " with min as " + summary.propertyName + "Min";
393
+ break;
394
+ case DataSourceSummaryOperand.Max:
395
+ result += summary.propertyName + " with max as " + summary.propertyName + "Max";
396
+ break;
397
+ case DataSourceSummaryOperand.Sum:
398
+ result += summary.propertyName + " with sum as " + summary.propertyName + "Sum";
399
+ break;
400
+ case DataSourceSummaryOperand.Count:
401
+ result += "$count as $__count";
402
+ countExists = true;
403
+ break;
404
+ }
405
+ first = false;
406
+ }
407
+ }
408
+ return result;
409
+ }
410
+ createSummaryResults(data) {
411
+ let summaryResults = [];
412
+ for (let summary of this.iterSummaries(this._summaryDescriptions)) {
413
+ let summaryName = summary.propertyName;
414
+ switch (summary.operand) {
415
+ case DataSourceSummaryOperand.Average:
416
+ summaryName += "Average";
417
+ break;
418
+ case DataSourceSummaryOperand.Min:
419
+ summaryName += "Min";
420
+ break;
421
+ case DataSourceSummaryOperand.Max:
422
+ summaryName += "Max";
423
+ break;
424
+ case DataSourceSummaryOperand.Sum:
425
+ summaryName += "Sum";
426
+ break;
427
+ case DataSourceSummaryOperand.Count:
428
+ summaryName = "$__count";
429
+ break;
430
+ }
431
+ let summaryValue = null;
432
+ if (data && data[summaryName]) {
433
+ summaryValue = data[summaryName];
434
+ }
435
+ let summaryResult = new DefaultSummaryResult(summary.propertyName, summary.operand, summaryValue);
436
+ summaryResults.push(summaryResult);
437
+ }
438
+ return summaryResults;
439
+ }
440
+ resolveSchema(finishAction, failureAction) {
441
+ let success_ = (res) => {
442
+ let sp = new ODataSchemaProvider(res);
443
+ let schema = sp.getODataDataSourceSchema(this._entitySet);
444
+ if (this._schemaIncludedProperties != null) {
445
+ let propertyNames = [];
446
+ let propertyTypes = [];
447
+ for (let i = 0; i < schema.propertyNames.length; i++) {
448
+ if (!this._schemaIncludedProperties.has(schema.propertyNames[i])) {
449
+ continue;
450
+ }
451
+ propertyNames.push(schema.propertyNames[i]);
452
+ propertyTypes.push(schema.propertyTypes[i]);
453
+ }
454
+ schema = new ODataDataSourceSchema(propertyNames, propertyTypes, schema.primaryKey);
455
+ }
456
+ finishAction(schema);
457
+ };
458
+ let failure_ = () => failureAction();
459
+ let baseUri_ = this._baseUri;
460
+ var request = new XMLHttpRequest();
461
+ request.onreadystatechange = function () {
462
+ if (request.readyState === 4) {
463
+ if (request.status === 200) {
464
+ success_(request.responseText);
465
+ }
466
+ else {
467
+ failure_();
468
+ }
469
+ }
470
+ };
471
+ request.open('Get', baseUri_ + '/$metadata');
472
+ request.send();
473
+ ;
474
+ }
475
+ static { this.schemaRequestIndex = -1; }
476
+ makeTaskForRequest(request, retryDelay) {
477
+ let actualPageSize = 0;
478
+ let sortDescriptions = null;
479
+ actualPageSize = this.actualPageSize;
480
+ sortDescriptions = this.sortDescriptions;
481
+ let requestUrl = this._baseUri;
482
+ requestUrl += "/" + this._entitySet;
483
+ let queryStarted = false;
484
+ this.updateFilterString();
485
+ if (this._filterString != null) {
486
+ if (!queryStarted) {
487
+ queryStarted = true;
488
+ requestUrl += "?";
489
+ }
490
+ else {
491
+ requestUrl += "&";
492
+ }
493
+ requestUrl += "$filter=" + this._filterString;
494
+ }
495
+ if (this.sortDescriptions != null) {
496
+ let sortString = null;
497
+ for (let sort of this.iter(this.sortDescriptions)) {
498
+ if (sortString == null) {
499
+ sortString = "";
500
+ }
501
+ else {
502
+ sortString += ", ";
503
+ }
504
+ if (sort.direction == ListSortDirection.Descending) {
505
+ sortString += sort.propertyName + " desc";
506
+ }
507
+ else {
508
+ sortString += sort.propertyName;
509
+ }
510
+ }
511
+ if (sortString != null) {
512
+ if (!queryStarted) {
513
+ queryStarted = true;
514
+ requestUrl += "?";
515
+ }
516
+ else {
517
+ requestUrl += "&";
518
+ }
519
+ requestUrl += "$orderby=" + sortString;
520
+ }
521
+ }
522
+ if (this.desiredProperties != null && this.desiredProperties.length > 0) {
523
+ let selectString = "";
524
+ let first = true;
525
+ let $t = this.desiredProperties;
526
+ for (let i = 0; i < $t.length; i++) {
527
+ let select = $t[i];
528
+ if (first) {
529
+ first = false;
530
+ }
531
+ else {
532
+ selectString += ", ";
533
+ }
534
+ selectString += select;
535
+ }
536
+ if (!queryStarted) {
537
+ queryStarted = true;
538
+ requestUrl += "?";
539
+ }
540
+ else {
541
+ requestUrl += "&";
542
+ }
543
+ requestUrl += "$select=" + selectString;
544
+ }
545
+ let task = new AsyncVirtualDataTask();
546
+ if (request.index == ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
547
+ this.executeRequest(requestUrl, queryStarted, 0, actualPageSize, task);
548
+ }
549
+ else {
550
+ this.executeRequest(requestUrl, queryStarted, request.index * actualPageSize, actualPageSize, task);
551
+ }
552
+ request.taskHolder = new AsyncDataSourcePageTaskHolder();
553
+ request.taskHolder.task = task;
554
+ this.tasks.add(request);
555
+ }
556
+ updateFilterString() {
557
+ if (this.filterExpressions != null && this.filterExpressions.size() > 0 && this._filterString == null) {
558
+ let sb = "";
559
+ let first = true;
560
+ for (let expr of this.iterFilter(this.filterExpressions)) {
561
+ if (first) {
562
+ first = false;
563
+ }
564
+ else {
565
+ sb += " AND ";
566
+ }
567
+ let visitor = new ODataDataSourceFilterExpressionVisitor(0);
568
+ visitor.visit(expr);
569
+ let txt = visitor.toString();
570
+ if (this.filterExpressions.size() > 1) {
571
+ txt = "(" + txt + ")";
572
+ }
573
+ sb += (txt);
574
+ }
575
+ this._filterString = sb;
576
+ }
577
+ }
578
+ executeRequest(requestUrl, queryStarted, skip, top, task) {
579
+ if (!queryStarted) {
580
+ queryStarted = true;
581
+ requestUrl += "?";
582
+ }
583
+ else {
584
+ requestUrl += "&";
585
+ }
586
+ requestUrl += "$skip=" + skip + "&$top=" + top + "&$count=true";
587
+ let requestUrl_ = requestUrl;
588
+ let self_ = this;
589
+ let success_ = (data, response) => this.success(task, data, response);
590
+ let failure_ = (err) => this.error(task, err);
591
+ let run_ = null;
592
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
593
+ var request = {
594
+ requestUri: requestUrl_,
595
+ enableJsonpCallback: this._enableJsonp,
596
+ method: 'GET',
597
+ headers: headers,
598
+ data: null
599
+ };
600
+ run_ = function () {
601
+ odatajs.oData.request(request, success_, failure_);
602
+ };
603
+ task.run = run_;
604
+ }
605
+ success(t, data, response) {
606
+ t.result = data;
607
+ t.isCompleted = true;
608
+ }
609
+ error(t, result) {
610
+ t.isCompleted = true;
611
+ t.hasErrors = true;
612
+ }
613
+ createBatchRequest(changes) {
614
+ const requests = [];
615
+ for (let i = 0; i < changes.length; i++) {
616
+ let c = changes[i];
617
+ const headers = { "Content-Type": "application/json", "odata-version": "4.0" };
618
+ if (c.transactionType === TransactionType.Add) {
619
+ requests.push({
620
+ method: "POST",
621
+ id: `r${i}`,
622
+ atomicityGroup: "g1",
623
+ url: `${this._baseUri}/${this._entitySet}`,
624
+ headers: headers,
625
+ body: c.value,
626
+ });
627
+ }
628
+ else if (c.transactionType === TransactionType.Update) {
629
+ if (c.version) {
630
+ headers["If-Match"] = c.version;
631
+ }
632
+ requests.push({
633
+ method: "PATCH",
634
+ id: `r${i}`,
635
+ atomicityGroup: "g1",
636
+ url: `${this._baseUri}/${this.getRequestUriWithKey(c.id)}`,
637
+ headers: headers,
638
+ body: c.value,
639
+ });
640
+ }
641
+ else if (c.transactionType === TransactionType.Delete) {
642
+ if (c.version) {
643
+ headers["If-Match"] = c.version;
644
+ }
645
+ requests.push({
646
+ method: "DELETE",
647
+ id: `r${i}`,
648
+ atomicityGroup: "g1",
649
+ url: `${this._baseUri}/${this.getRequestUriWithKey(c.id)}`,
650
+ headers: headers,
651
+ });
652
+ }
653
+ }
654
+ let request = {
655
+ requestUri: `${this._baseUri}/$batch`,
656
+ method: "POST",
657
+ headers: { "Content-Type": "application/json" },
658
+ body: JSON.stringify({ requests: requests })
659
+ };
660
+ let self = this;
661
+ odatajs.oData.request(request, function (data) {
662
+ if (data && data.responses) {
663
+ if (data.responses.length > 0) {
664
+ let success = true;
665
+ let messages = [];
666
+ for (let i = 0; i < data.responses.length; i++) {
667
+ if (data.responses[i].status !== 200 &&
668
+ data.responses[i].status !== 204) {
669
+ success = false;
670
+ let failedRequest = requests.filter(r => r.id == data.responses[i].id)[0];
671
+ if (failedRequest) {
672
+ let msg = `${failedRequest.method} request failed with code ${data.responses[i].status}`;
673
+ messages.push(msg);
674
+ console.error(msg);
675
+ }
676
+ break;
677
+ }
678
+ }
679
+ if (success) {
680
+ self.batchCompleted(true, true, null);
681
+ }
682
+ else {
683
+ self.batchCompleted(false, true, messages);
684
+ }
685
+ }
686
+ else {
687
+ self.batchCompleted(false, true, null);
688
+ }
689
+ }
690
+ }, function (error) {
691
+ const messages = [];
692
+ if (error && error.message) {
693
+ messages.push(error.message);
694
+ }
695
+ self.batchCompleted(false, true, messages);
696
+ });
697
+ }
698
+ getRequestUriWithKey(key) {
699
+ let result = "";
700
+ const keys = Object.keys(key);
701
+ for (let i = 0; i < keys.length; i++) {
702
+ if (i > 0) {
703
+ result += ",";
704
+ }
705
+ result += `${keys[i]}=${key[keys[i]]}`;
706
+ }
707
+ return `${this._entitySet}(${result})`;
708
+ }
709
+ }
710
+ export { ODataVirtualDataSourceDataProviderWorker };