igniteui-webcomponents-datasources 7.1.1-beta.1 → 7.1.1-beta.3

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 (74) hide show
  1. package/esm2022/lib/ODataSchemaProvider.js +120 -0
  2. package/esm2022/lib/ODataVirtualDataSourceDataProvider.js +450 -0
  3. package/esm2022/lib/ODataVirtualDataSourceDataProviderWorker.js +710 -0
  4. package/esm2022/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +83 -0
  5. package/esm2022/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +6 -0
  6. package/esm2022/lib/RestVirtualDataSourceDataProvider.js +535 -0
  7. package/esm2022/lib/RestVirtualDataSourceDataProviderWorker.js +762 -0
  8. package/esm2022/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +159 -0
  9. package/esm2022/lib/RestVirtualDataSourceProviderTaskDataHolder.js +6 -0
  10. package/package.json +14 -10
  11. package/bundles/igniteui-webcomponents-datasources.umd.js +0 -4725
  12. package/bundles/igniteui-webcomponents-datasources.umd.min.js +0 -7
  13. package/esm2015/igniteui-webcomponents-datasources.js +0 -1
  14. package/esm2015/lib/ODataSchemaProvider.js +0 -123
  15. package/esm2015/lib/ODataVirtualDataSourceDataProvider.js +0 -453
  16. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -713
  17. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -86
  18. package/esm2015/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -9
  19. package/esm2015/lib/RestVirtualDataSourceDataProvider.js +0 -538
  20. package/esm2015/lib/RestVirtualDataSourceDataProviderWorker.js +0 -765
  21. package/esm2015/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +0 -162
  22. package/esm2015/lib/RestVirtualDataSourceProviderTaskDataHolder.js +0 -9
  23. package/esm5/igniteui-webcomponents-datasources.js +0 -1
  24. package/esm5/lib/Entity.js +0 -79
  25. package/esm5/lib/EntityProperty.js +0 -41
  26. package/esm5/lib/EntitySet.js +0 -68
  27. package/esm5/lib/ODataDataSourcePage.js +0 -73
  28. package/esm5/lib/ODataSchemaProvider.js +0 -158
  29. package/esm5/lib/ODataVirtualDataSource.js +0 -169
  30. package/esm5/lib/ODataVirtualDataSourceDataProvider.js +0 -558
  31. package/esm5/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -920
  32. package/esm5/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -130
  33. package/esm5/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -11
  34. package/esm5/lib/RestVirtualDataSource.js +0 -357
  35. package/esm5/lib/RestVirtualDataSourceDataProvider.js +0 -687
  36. package/esm5/lib/RestVirtualDataSourceDataProviderWorker.js +0 -967
  37. package/esm5/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +0 -250
  38. package/esm5/lib/RestVirtualDataSourcePage.js +0 -73
  39. package/esm5/lib/RestVirtualDataSourceProviderTaskDataHolder.js +0 -11
  40. package/esm5/lib/Schema.js +0 -68
  41. package/esm5/lib/util.js +0 -160
  42. package/esm5/public_api.js +0 -18
  43. package/fesm2015/igniteui-webcomponents-datasources.js +0 -3638
  44. package/fesm5/igniteui-webcomponents-datasources.js +0 -4698
  45. package/igniteui-webcomponents-datasources.d.ts +0 -1
  46. /package/{lib → esm2022/lib}/Entity.d.ts +0 -0
  47. /package/{esm2015 → esm2022}/lib/Entity.js +0 -0
  48. /package/{lib → esm2022/lib}/EntityProperty.d.ts +0 -0
  49. /package/{esm2015 → esm2022}/lib/EntityProperty.js +0 -0
  50. /package/{lib → esm2022/lib}/EntitySet.d.ts +0 -0
  51. /package/{esm2015 → esm2022}/lib/EntitySet.js +0 -0
  52. /package/{lib → esm2022/lib}/ODataDataSourcePage.d.ts +0 -0
  53. /package/{esm2015 → esm2022}/lib/ODataDataSourcePage.js +0 -0
  54. /package/{lib → esm2022/lib}/ODataSchemaProvider.d.ts +0 -0
  55. /package/{lib → esm2022/lib}/ODataVirtualDataSource.d.ts +0 -0
  56. /package/{esm2015 → esm2022}/lib/ODataVirtualDataSource.js +0 -0
  57. /package/{lib → esm2022/lib}/ODataVirtualDataSourceDataProvider.d.ts +0 -0
  58. /package/{lib → esm2022/lib}/ODataVirtualDataSourceDataProviderWorker.d.ts +0 -0
  59. /package/{lib → esm2022/lib}/ODataVirtualDataSourceDataProviderWorkerSettings.d.ts +0 -0
  60. /package/{lib → esm2022/lib}/ODataVirtualDataSourceProviderTaskDataHolder.d.ts +0 -0
  61. /package/{lib → esm2022/lib}/RestVirtualDataSource.d.ts +0 -0
  62. /package/{esm2015 → esm2022}/lib/RestVirtualDataSource.js +0 -0
  63. /package/{lib → esm2022/lib}/RestVirtualDataSourceDataProvider.d.ts +0 -0
  64. /package/{lib → esm2022/lib}/RestVirtualDataSourceDataProviderWorker.d.ts +0 -0
  65. /package/{lib → esm2022/lib}/RestVirtualDataSourceDataProviderWorkerSettings.d.ts +0 -0
  66. /package/{lib → esm2022/lib}/RestVirtualDataSourcePage.d.ts +0 -0
  67. /package/{esm2015 → esm2022}/lib/RestVirtualDataSourcePage.js +0 -0
  68. /package/{lib → esm2022/lib}/RestVirtualDataSourceProviderTaskDataHolder.d.ts +0 -0
  69. /package/{lib → esm2022/lib}/Schema.d.ts +0 -0
  70. /package/{esm2015 → esm2022}/lib/Schema.js +0 -0
  71. /package/{lib → esm2022/lib}/util.d.ts +0 -0
  72. /package/{esm2015 → esm2022}/lib/util.js +0 -0
  73. /package/{public_api.d.ts → esm2022/public_api.d.ts} +0 -0
  74. /package/{esm2015 → esm2022}/public_api.js +0 -0
@@ -1,713 +0,0 @@
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
- let ODataVirtualDataSourceDataProviderWorker = /*@__PURE__*/ (() => {
19
- class ODataVirtualDataSourceDataProviderWorker extends AsyncVirtualDataSourceProviderWorker {
20
- get sortDescriptions() {
21
- return this._sortDescriptions;
22
- }
23
- get filterExpressions() {
24
- return this._filterExpressions;
25
- }
26
- get desiredProperties() {
27
- return this._desiredPropeties;
28
- }
29
- initialize() {
30
- super.initialize();
31
- }
32
- getTaskDataHolder() {
33
- let holder = new ODataVirtualDataSourceProviderTaskDataHolder();
34
- return holder;
35
- }
36
- getCompletedTaskData(holder, completed) {
37
- super.getCompletedTaskData(holder, completed);
38
- }
39
- removeCompletedTaskData(holder, completed) {
40
- super.removeCompletedTaskData(holder, completed);
41
- }
42
- getTasksData(holder) {
43
- super.getTasksData(holder);
44
- }
45
- *iter(coll) {
46
- for (let i = 0; i < coll.size(); i++) {
47
- yield coll.get(i);
48
- }
49
- }
50
- *iterFilter(coll) {
51
- for (let i = 0; i < coll.size(); i++) {
52
- yield coll.get(i);
53
- }
54
- }
55
- *iterSummaries(summaries) {
56
- for (let i = 0; i < summaries.size(); i++) {
57
- yield summaries.get(i);
58
- }
59
- }
60
- constructor(settings) {
61
- super(settings);
62
- this._baseUri = null;
63
- this._entitySet = null;
64
- this._sortDescriptions = null;
65
- this._groupDescriptions = null;
66
- this._filterExpressions = null;
67
- this._summaryDescriptions = null;
68
- this._desiredPropeties = null;
69
- this._schemaIncludedProperties = null;
70
- this._enableJsonp = true;
71
- this._isAggregationSupported = false;
72
- this._groupInformation = null;
73
- this._summaryInformation = null;
74
- this._filterString = null;
75
- this._selectedString = null;
76
- this.doWork = this.doWork.bind(this);
77
- this._baseUri = settings.baseUri;
78
- this._entitySet = settings.entitySet;
79
- this._sortDescriptions = settings.sortDescriptions;
80
- this._groupDescriptions = settings.groupDescriptions;
81
- if (this._groupDescriptions != null && this._groupDescriptions.size() > 0) {
82
- this._sortDescriptions = new SortDescriptionCollection();
83
- for (let sd of this.iter(settings.sortDescriptions)) {
84
- this._sortDescriptions.add(sd);
85
- }
86
- for (let i = 0; i < this._groupDescriptions.size(); i++) {
87
- this._sortDescriptions.insert(i, this._groupDescriptions.get(i));
88
- }
89
- }
90
- this._filterExpressions = settings.filterExpressions;
91
- this._desiredPropeties = settings.propertiesRequested;
92
- if (settings.schemaIncludedProperties != null) {
93
- this._schemaIncludedProperties = new Set();
94
- for (let i = 0; i < settings.schemaIncludedProperties.length; i++) {
95
- this._schemaIncludedProperties.add(settings.schemaIncludedProperties[i]);
96
- }
97
- }
98
- this._summaryDescriptions = settings.summaryDescriptions;
99
- this._summaryScope = settings.summaryScope;
100
- this._enableJsonp = settings.enableJsonp;
101
- this._isAggregationSupported = settings.isAggregationSupported;
102
- window.setTimeout(this.doWork, 100);
103
- }
104
- processCompletedTask(completedTask, currentDelay, pageIndex, taskDataHolder) {
105
- let h = taskDataHolder;
106
- let schema = null;
107
- let result = null;
108
- let schemaFetchCount = -1;
109
- let task = completedTask.task;
110
- try {
111
- if (task.hasErrors) {
112
- this.retryIndex(pageIndex, currentDelay);
113
- return;
114
- }
115
- if (pageIndex == ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
116
- result = task.result;
117
- schemaFetchCount = (result['@odata.count']);
118
- }
119
- else {
120
- result = task.result;
121
- }
122
- }
123
- catch (e) {
124
- this.retryIndex(pageIndex, currentDelay);
125
- return;
126
- }
127
- if (schemaFetchCount >= 0) {
128
- this.actualCount = schemaFetchCount;
129
- }
130
- else {
131
- this.actualCount = (result['@odata.count']);
132
- }
133
- schema = this.actualSchema;
134
- if (schema == null) {
135
- let requests = 0;
136
- this.resolveSchema((s) => {
137
- // resolveSchema success callback
138
- this.actualSchema = s;
139
- if (this._isAggregationSupported && (this._groupDescriptions.size() !== 0 || this._summaryDescriptions.size() !== 0)) {
140
- if (this._groupDescriptions.size() > 0) {
141
- requests++;
142
- this.resolveGroupInformation((g) => {
143
- // group info success
144
- requests--;
145
- if (requests === 0) {
146
- this.finishProcessingCompletedTask(task, pageIndex, s, result);
147
- }
148
- }, () => {
149
- // group info failure
150
- this.retryIndex(pageIndex, currentDelay);
151
- return;
152
- });
153
- }
154
- if (this._summaryDescriptions.size() > 0) {
155
- requests++;
156
- this.resolveSummaryInformation((g) => {
157
- // summary info success
158
- requests--;
159
- if (requests === 0) {
160
- this.finishProcessingCompletedTask(task, pageIndex, s, result);
161
- }
162
- }, () => {
163
- // summary info failure
164
- this.retryIndex(pageIndex, currentDelay);
165
- return;
166
- });
167
- }
168
- }
169
- else {
170
- this.finishProcessingCompletedTask(task, pageIndex, s, result);
171
- }
172
- }, () => {
173
- // resolveSchema failure callback
174
- this.retryIndex(pageIndex, currentDelay);
175
- return;
176
- });
177
- return;
178
- }
179
- this.finishProcessingCompletedTask(task, pageIndex, schema, result);
180
- }
181
- finishProcessingCompletedTask(task, pageIndex, schema, result) {
182
- let executionContext;
183
- let pageLoaded;
184
- let groupInformation;
185
- let summaryInformation;
186
- this.actualSchema = schema;
187
- executionContext = this.executionContext;
188
- groupInformation = this._groupInformation;
189
- summaryInformation = this._summaryInformation;
190
- pageLoaded = this.pageLoaded;
191
- let page = null;
192
- if (result != null) {
193
- page = new ODataDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex);
194
- if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) {
195
- this.populatedActualPageSize = true;
196
- this.actualPageSize = page.count();
197
- }
198
- }
199
- else {
200
- page = new ODataDataSourcePage(null, schema, groupInformation, summaryInformation, pageIndex);
201
- }
202
- if (this.pageLoaded != null) {
203
- if (this.executionContext != null) {
204
- if (executionContext == null || pageLoaded == null) {
205
- this.shutdown();
206
- return;
207
- }
208
- executionContext.execute(() => pageLoaded(page, this.actualCount, this.actualPageSize));
209
- }
210
- else {
211
- if (pageLoaded == null) {
212
- this.shutdown();
213
- return;
214
- }
215
- pageLoaded(page, this.actualCount, this.actualPageSize);
216
- }
217
- }
218
- }
219
- resolveGroupInformation(finishAction, failureAction) {
220
- if (this._groupInformation != null) {
221
- finishAction(this._groupInformation);
222
- return;
223
- }
224
- let orderBy = "";
225
- let groupBy = "";
226
- let filter = null;
227
- let summary = "";
228
- if (this._groupDescriptions == null || this._groupDescriptions.size() == 0) {
229
- finishAction(null);
230
- return;
231
- }
232
- filter = this._filterString;
233
- this.updateFilterString();
234
- if (this._groupDescriptions != null) {
235
- let first1 = true;
236
- for (let group of this.iter(this._groupDescriptions)) {
237
- if (first1) {
238
- first1 = false;
239
- }
240
- else {
241
- orderBy += ", ";
242
- groupBy += ", ";
243
- }
244
- groupBy += group.propertyName;
245
- if (group.direction === ListSortDirection.Descending) {
246
- orderBy += group.propertyName + " desc";
247
- }
248
- else {
249
- orderBy += group.propertyName + " asc";
250
- }
251
- }
252
- }
253
- if (this._summaryScope === DataSourceSummaryScope.Both || this._summaryScope === DataSourceSummaryScope.Groups) {
254
- let summaryParameters = this.getSummaryQueryParameters(true);
255
- if (!stringIsNullOrEmpty(summaryParameters)) {
256
- summary = ", " + summaryParameters;
257
- }
258
- }
259
- let commandText = this._entitySet + "?$orderby=" + orderBy + "&$apply=";
260
- if (!stringIsNullOrEmpty(filter)) {
261
- commandText += "filter(" + filter + ")/";
262
- }
263
- commandText += "groupby((" + groupBy + "), aggregate($count as $__count" + summary + "))";
264
- try {
265
- let groupInformation = [];
266
- let success_ = (data, response) => this.groupSuccess(data, response, finishAction, failureAction, groupInformation);
267
- let failure_ = (err) => this.groupError(err, finishAction, failureAction, groupInformation);
268
- let run_ = null;
269
- var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
270
- var request = {
271
- requestUri: this._baseUri + "/" + commandText,
272
- enableJsonpCallback: this._enableJsonp,
273
- method: 'GET',
274
- headers: headers,
275
- data: null
276
- };
277
- run_ = function () {
278
- odatajs.oData.request(request, success_, failure_);
279
- };
280
- run_();
281
- }
282
- catch (e) {
283
- failureAction();
284
- }
285
- }
286
- groupError(err, finishAction, failureAction, groupInformation) {
287
- this._groupInformation = null;
288
- }
289
- groupSuccess(data, response, finishAction, failureAction, groupInformation) {
290
- let groupNames = [];
291
- for (let group of this.iter(this._groupDescriptions)) {
292
- groupNames.push(group.propertyName);
293
- }
294
- let groupNamesArray = groupNames;
295
- if (data && data.value && data.value.length > 0) {
296
- let currentIndex = 0;
297
- for (let i = 0; i < data.value.length; i++) {
298
- this.addGroup(groupInformation, groupNames, groupNames, currentIndex, data.value[i]);
299
- }
300
- }
301
- this._groupInformation = groupInformation;
302
- finishAction(this._groupInformation);
303
- }
304
- addGroup(groupInformation, groupNames, groupNamesArray, currentIndex, group) {
305
- let groupValues = [];
306
- for (let name of groupNames) {
307
- if (group[name]) {
308
- groupValues.push(group[name]);
309
- }
310
- }
311
- let groupCount = 0;
312
- if (group["$__count"]) {
313
- groupCount = Convert.toInt321(group["$__count"]);
314
- }
315
- let summaryResults = null;
316
- if (this._summaryScope == DataSourceSummaryScope.Both || this._summaryScope == DataSourceSummaryScope.Groups) {
317
- summaryResults = this.createSummaryResults(group);
318
- }
319
- let groupInfo = new DefaultSectionInformation(currentIndex, currentIndex + (groupCount - 1), groupNamesArray, groupValues, summaryResults);
320
- groupInformation.push(groupInfo);
321
- }
322
- resolveSummaryInformation(finishAction, failureAction) {
323
- if (this._summaryInformation != null) {
324
- finishAction(this._summaryInformation);
325
- return;
326
- }
327
- let filter = null;
328
- let summary = null;
329
- if (this._summaryDescriptions == null ||
330
- this._summaryDescriptions.size() == 0 ||
331
- this._summaryScope == DataSourceSummaryScope.Groups ||
332
- this._summaryScope == DataSourceSummaryScope.None) {
333
- finishAction(null);
334
- return;
335
- }
336
- filter = this._filterString;
337
- this.updateFilterString();
338
- summary = this.getSummaryQueryParameters(false);
339
- let commandText = this._entitySet + "?$apply=";
340
- if (!stringIsNullOrEmpty(filter)) {
341
- commandText += "filter(" + filter + ")/";
342
- }
343
- commandText += "aggregate(" + summary + ")";
344
- try {
345
- let summaryInformation = [];
346
- let success_ = (data, response) => this.summarySuccess(data, response, finishAction, failureAction, summaryInformation);
347
- let failure_ = (err) => this.summaryError(err, finishAction, failureAction, summaryInformation);
348
- let run_ = null;
349
- var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
350
- var request = {
351
- requestUri: this._baseUri + "/" + commandText,
352
- enableJsonpCallback: this._enableJsonp,
353
- method: 'GET',
354
- headers: headers,
355
- data: null
356
- };
357
- run_ = function () {
358
- odatajs.oData.request(request, success_, failure_);
359
- };
360
- run_();
361
- }
362
- catch (e) {
363
- failureAction();
364
- }
365
- }
366
- summarySuccess(data, response, finishAction, failureAction, summaryInformation) {
367
- if (data && data.value && data.value.length > 0) {
368
- summaryInformation = this.createSummaryResults(data.value[0]);
369
- }
370
- this._summaryInformation = summaryInformation;
371
- finishAction(this._summaryInformation);
372
- }
373
- summaryError(err, finishAction, failureAction, summaryInformation) {
374
- this._summaryInformation = null;
375
- }
376
- getSummaryQueryParameters(ignoreCount) {
377
- let result = "";
378
- if (this._summaryDescriptions != null) {
379
- let first = true;
380
- let countExists = false;
381
- for (let summary of this.iterSummaries(this._summaryDescriptions)) {
382
- if (summary.operand == DataSourceSummaryOperand.Count && (ignoreCount || countExists)) {
383
- continue;
384
- }
385
- if (!first) {
386
- result += ", ";
387
- }
388
- switch (summary.operand) {
389
- case DataSourceSummaryOperand.Average:
390
- result += summary.propertyName + " with average as " + summary.propertyName + "Average";
391
- break;
392
- case DataSourceSummaryOperand.Min:
393
- result += summary.propertyName + " with min as " + summary.propertyName + "Min";
394
- break;
395
- case DataSourceSummaryOperand.Max:
396
- result += summary.propertyName + " with max as " + summary.propertyName + "Max";
397
- break;
398
- case DataSourceSummaryOperand.Sum:
399
- result += summary.propertyName + " with sum as " + summary.propertyName + "Sum";
400
- break;
401
- case DataSourceSummaryOperand.Count:
402
- result += "$count as $__count";
403
- countExists = true;
404
- break;
405
- }
406
- first = false;
407
- }
408
- }
409
- return result;
410
- }
411
- createSummaryResults(data) {
412
- let summaryResults = [];
413
- for (let summary of this.iterSummaries(this._summaryDescriptions)) {
414
- let summaryName = summary.propertyName;
415
- switch (summary.operand) {
416
- case DataSourceSummaryOperand.Average:
417
- summaryName += "Average";
418
- break;
419
- case DataSourceSummaryOperand.Min:
420
- summaryName += "Min";
421
- break;
422
- case DataSourceSummaryOperand.Max:
423
- summaryName += "Max";
424
- break;
425
- case DataSourceSummaryOperand.Sum:
426
- summaryName += "Sum";
427
- break;
428
- case DataSourceSummaryOperand.Count:
429
- summaryName = "$__count";
430
- break;
431
- }
432
- let summaryValue = null;
433
- if (data && data[summaryName]) {
434
- summaryValue = data[summaryName];
435
- }
436
- let summaryResult = new DefaultSummaryResult(summary.propertyName, summary.operand, summaryValue);
437
- summaryResults.push(summaryResult);
438
- }
439
- return summaryResults;
440
- }
441
- resolveSchema(finishAction, failureAction) {
442
- let success_ = (res) => {
443
- let sp = new ODataSchemaProvider(res);
444
- let schema = sp.getODataDataSourceSchema(this._entitySet);
445
- if (this._schemaIncludedProperties != null) {
446
- let propertyNames = [];
447
- let propertyTypes = [];
448
- for (let i = 0; i < schema.propertyNames.length; i++) {
449
- if (!this._schemaIncludedProperties.has(schema.propertyNames[i])) {
450
- continue;
451
- }
452
- propertyNames.push(schema.propertyNames[i]);
453
- propertyTypes.push(schema.propertyTypes[i]);
454
- }
455
- schema = new ODataDataSourceSchema(propertyNames, propertyTypes, schema.primaryKey);
456
- }
457
- finishAction(schema);
458
- };
459
- let failure_ = () => failureAction();
460
- let baseUri_ = this._baseUri;
461
- var request = new XMLHttpRequest();
462
- request.onreadystatechange = function () {
463
- if (request.readyState === 4) {
464
- if (request.status === 200) {
465
- success_(request.responseText);
466
- }
467
- else {
468
- failure_();
469
- }
470
- }
471
- };
472
- request.open('Get', baseUri_ + '/$metadata');
473
- request.send();
474
- ;
475
- }
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
- ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex = -1;
711
- return ODataVirtualDataSourceDataProviderWorker;
712
- })();
713
- export { ODataVirtualDataSourceDataProviderWorker };