@kwiz/common 1.0.4 → 1.0.6
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.
- package/dist/helpers/base64.js +10 -21
- package/dist/helpers/base64.js.map +1 -1
- package/dist/helpers/browser.d.ts +13 -5
- package/dist/helpers/browser.js +61 -39
- package/dist/helpers/browser.js.map +1 -1
- package/dist/helpers/collections.base.js +46 -65
- package/dist/helpers/collections.base.js.map +1 -1
- package/dist/helpers/collections.js +4 -1
- package/dist/helpers/collections.js.map +1 -1
- package/dist/helpers/date.d.ts +2 -1
- package/dist/helpers/date.js +22 -3
- package/dist/helpers/date.js.map +1 -1
- package/dist/helpers/debug.js +9 -20
- package/dist/helpers/debug.js.map +1 -1
- package/dist/helpers/objects.js +2 -11
- package/dist/helpers/objects.js.map +1 -1
- package/dist/helpers/promises.js +28 -41
- package/dist/helpers/promises.js.map +1 -1
- package/dist/helpers/strings.js +2 -1
- package/dist/helpers/strings.js.map +1 -1
- package/dist/utils/base64.js +18 -29
- package/dist/utils/base64.js.map +1 -1
- package/dist/utils/consolelogger.js +16 -27
- package/dist/utils/consolelogger.js.map +1 -1
- package/dist/utils/emails.js +5 -2
- package/dist/utils/emails.js.map +1 -1
- package/dist/utils/knownscript.js +4 -15
- package/dist/utils/knownscript.js.map +1 -1
- package/dist/utils/localstoragecache.js +3 -3
- package/dist/utils/localstoragecache.js.map +1 -1
- package/dist/utils/rest.d.ts +2 -0
- package/dist/utils/rest.js +18 -5
- package/dist/utils/rest.js.map +1 -1
- package/dist/utils/script.js +25 -40
- package/dist/utils/script.js.map +1 -1
- package/dist/utils/sharepoint.rest/file.folder.d.ts +2 -0
- package/dist/utils/sharepoint.rest/file.folder.js +123 -123
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -1
- package/dist/utils/sharepoint.rest/item.d.ts +10 -0
- package/dist/utils/sharepoint.rest/item.js +233 -237
- package/dist/utils/sharepoint.rest/item.js.map +1 -1
- package/dist/utils/sharepoint.rest/list.d.ts +30 -1
- package/dist/utils/sharepoint.rest/list.js +296 -289
- package/dist/utils/sharepoint.rest/list.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +352 -360
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +47 -58
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -1
- package/dist/utils/sharepoint.rest/user-search.d.ts +5 -10
- package/dist/utils/sharepoint.rest/user-search.js +129 -148
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -1
- package/dist/utils/sharepoint.rest/user.d.ts +1 -0
- package/dist/utils/sharepoint.rest/user.js +200 -169
- package/dist/utils/sharepoint.rest/user.js.map +1 -1
- package/dist/utils/sharepoint.rest/web.d.ts +10 -1
- package/dist/utils/sharepoint.rest/web.js +381 -401
- package/dist/utils/sharepoint.rest/web.js.map +1 -1
- package/dist/utils/sod.js +8 -19
- package/dist/utils/sod.js.map +1 -1
- package/package.json +5 -4
- package/src/helpers/browser.ts +56 -13
- package/src/helpers/date.ts +23 -1
- package/src/helpers/strings.test.js +14 -2
- package/src/helpers/strings.ts +2 -1
- package/src/utils/rest.ts +7 -0
- package/src/utils/sharepoint.rest/file.folder.ts +18 -1
- package/src/utils/sharepoint.rest/item.ts +54 -1
- package/src/utils/sharepoint.rest/list.ts +144 -0
- package/src/utils/sharepoint.rest/user-search.ts +10 -14
- package/src/utils/sharepoint.rest/user.ts +49 -3
- package/src/utils/sharepoint.rest/web.ts +23 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.GetListItemsByCaml = void 0;
|
|
13
4
|
const _dependencies_1 = require("../../_dependencies");
|
|
@@ -27,138 +18,136 @@ const lookupOrUserFieldLimit = 11;
|
|
|
27
18
|
* - view.ViewQuery
|
|
28
19
|
* - wrapped view.ViewQuery in a <View>: "<View Scope='RecursiveAll'><Query></Query><RowLimit>1000</RowLimit></View>" or send rowLimit in options.
|
|
29
20
|
*/
|
|
30
|
-
function GetListItemsByCaml(siteUrl, listIdOrTitle, camlQuery, options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
async function GetListItemsByCaml(siteUrl, listIdOrTitle, camlQuery, options) {
|
|
22
|
+
siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
|
|
23
|
+
if (!camlQuery.toLowerCase().startsWith("<view")) {
|
|
24
|
+
camlQuery = `<View Scope='RecursiveAll'><Query>${camlQuery}</Query></View>`;
|
|
25
|
+
}
|
|
26
|
+
let xmlParser = new DOMParser();
|
|
27
|
+
let xmlDoc = xmlParser.parseFromString(camlQuery, "text/xml");
|
|
28
|
+
let viewNode = xmlDoc.querySelector("View, view");
|
|
29
|
+
let queryNode = viewNode && viewNode.querySelector("Query, query");
|
|
30
|
+
let rowLimitNode = viewNode && viewNode.querySelector("RowLimit, rowlimit");
|
|
31
|
+
let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
|
|
32
|
+
let parseRowLimitNodeResult = _parseRowLimitNode(rowLimitNode, viewNode, options.rowLimit);
|
|
33
|
+
if (!(0, _dependencies_1.isNullOrUndefined)(parseRowLimitNodeResult)) {
|
|
34
|
+
options.rowLimit = parseRowLimitNodeResult.rowLimit;
|
|
35
|
+
camlQuery = parseRowLimitNodeResult.camlQuery;
|
|
36
|
+
}
|
|
37
|
+
let removeSingleAndConditionsResult = _removeSingleAndConditions(viewNode, queryNode);
|
|
38
|
+
if (!(0, _dependencies_1.isNullOrUndefined)(removeSingleAndConditionsResult)) {
|
|
39
|
+
camlQuery = removeSingleAndConditionsResult.camlQuery;
|
|
40
|
+
}
|
|
41
|
+
let getAllItems = (0, _dependencies_1.isNullOrEmptyString)(options.rowLimit) || options.rowLimit < 1;
|
|
42
|
+
let totalItemsInList = 99999;
|
|
43
|
+
let maxBatchSize = 5000;
|
|
44
|
+
let batchSize = options.rowLimit > 0 && options.rowLimit < maxBatchSize ? options.rowLimit : maxBatchSize;
|
|
45
|
+
let totalNumberOfItemsToGet = getAllItems ? totalItemsInList : options.rowLimit > maxBatchSize ? options.rowLimit : batchSize;
|
|
46
|
+
let requestUrl = `${(0, list_1.GetListRestUrl)(siteUrl, listIdOrTitle)}/GetItems?$expand=FieldValuesAsText`;
|
|
47
|
+
let allListFieldsHash = (0, _dependencies_1.toHash)(await (0, list_1.GetListFields)(siteUrl, listIdOrTitle), f => f.InternalName);
|
|
48
|
+
let expandFields = [];
|
|
49
|
+
let orderByStatement = (0, _dependencies_1.GetOrderByFromCaml)(camlQuery);
|
|
50
|
+
if ((0, _dependencies_1.isNullOrUndefined)(options.columns)) {
|
|
51
|
+
options.columns = [];
|
|
52
|
+
}
|
|
53
|
+
let columns = options.columns;
|
|
54
|
+
columns = _ensureOrderByColumns(orderByStatement, columns);
|
|
55
|
+
columns = _ensureViewFields(viewFieldsNode, columns, allListFieldsHash);
|
|
56
|
+
columns = _normalizeColumns(columns, allListFieldsHash);
|
|
57
|
+
if (columns.length > options.columns.length) {
|
|
58
|
+
logger.warn(`added ${columns.length - options.columns.length} to query`);
|
|
59
|
+
}
|
|
60
|
+
options.columns = columns;
|
|
61
|
+
// Store the result of processing the request
|
|
62
|
+
let rtrnProcessRequestResult;
|
|
63
|
+
let lookupOrUserFieldsInColumns = options.columns.filter((columnName) => {
|
|
64
|
+
let field = allListFieldsHash[columnName];
|
|
65
|
+
return _isLookupOrUserField(field);
|
|
66
|
+
});
|
|
67
|
+
let isThrottled = lookupOrUserFieldsInColumns.length >= lookupOrUserFieldLimit;
|
|
68
|
+
try {
|
|
69
|
+
if (isThrottled) {
|
|
70
|
+
//ISSUE: 1565
|
|
71
|
+
rtrnProcessRequestResult = await _processLookupThresholdCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize);
|
|
46
72
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
camlQuery = removeSingleAndConditionsResult.camlQuery;
|
|
73
|
+
else {
|
|
74
|
+
rtrnProcessRequestResult = await _processNormalCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize);
|
|
50
75
|
}
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
const { items, needContentTypes, postProcessOrderBy } = rtrnProcessRequestResult;
|
|
77
|
+
let itemsResult = (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour);
|
|
78
|
+
let itemsWithOutContentType = [];
|
|
79
|
+
if (needContentTypes) {
|
|
80
|
+
itemsResult.forEach((item) => {
|
|
81
|
+
if ((0, _dependencies_1.isNullOrUndefined)(item["ContentType"])) {
|
|
82
|
+
itemsWithOutContentType.push(item.Id);
|
|
83
|
+
}
|
|
84
|
+
else if (!(0, _dependencies_1.isNullOrUndefined)(item["ContentType"].Name)) {
|
|
85
|
+
item["ContentType"] = item["ContentType"].Name;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
62
88
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
if (itemsWithOutContentType.length > 0) {
|
|
90
|
+
logger.time("Getting content types");
|
|
91
|
+
//Issue 1465 content types no longer come back from get items request...
|
|
92
|
+
//Make a separate request to get this info
|
|
93
|
+
let ctypes = (await (0, GetListItemsById_1.GetItemsById)(siteUrl, listIdOrTitle, itemsWithOutContentType, {
|
|
94
|
+
expand: ['ContentType/Name'],
|
|
95
|
+
select: ['ContentType/Name', 'Id'],
|
|
96
|
+
jsonMetadata: _dependencies_1.jsonTypes.nometadata
|
|
97
|
+
}));
|
|
98
|
+
itemsResult.forEach(item => {
|
|
99
|
+
if (!(0, _dependencies_1.isNullOrUndefined)(ctypes[item.Id])) {
|
|
100
|
+
item["ContentType"] = ctypes[item.Id].ContentType.Name;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
logger.timeEnd("Getting content types");
|
|
69
104
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rtrnProcessRequestResult = yield _processLookupThresholdCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
rtrnProcessRequestResult = yield _processNormalCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize);
|
|
85
|
-
}
|
|
86
|
-
const { items, needContentTypes, postProcessOrderBy } = rtrnProcessRequestResult;
|
|
87
|
-
let itemsResult = (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour);
|
|
88
|
-
let itemsWithOutContentType = [];
|
|
89
|
-
if (needContentTypes) {
|
|
90
|
-
itemsResult.forEach((item) => {
|
|
91
|
-
if ((0, _dependencies_1.isNullOrUndefined)(item["ContentType"])) {
|
|
92
|
-
itemsWithOutContentType.push(item.Id);
|
|
93
|
-
}
|
|
94
|
-
else if (!(0, _dependencies_1.isNullOrUndefined)(item["ContentType"].Name)) {
|
|
95
|
-
item["ContentType"] = item["ContentType"].Name;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
105
|
+
if (postProcessOrderBy) {
|
|
106
|
+
//re-apply sort
|
|
107
|
+
if (_dependencies_1.IsLocalDev) {
|
|
108
|
+
logger.table(itemsResult.map(i => {
|
|
109
|
+
let row = {
|
|
110
|
+
Id: i.Id,
|
|
111
|
+
Title: i.Title
|
|
112
|
+
};
|
|
113
|
+
orderByStatement.forEach(s => { row[`${s.Name} ${s.IsAscending ? 'asc' : 'desc'}`] = i[s.Name]; });
|
|
114
|
+
return row;
|
|
115
|
+
}), "before sort", true);
|
|
98
116
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
jsonMetadata: _dependencies_1.jsonTypes.nometadata
|
|
107
|
-
}));
|
|
108
|
-
itemsResult.forEach(item => {
|
|
109
|
-
if (!(0, _dependencies_1.isNullOrUndefined)(ctypes[item.Id])) {
|
|
110
|
-
item["ContentType"] = ctypes[item.Id].ContentType.Name;
|
|
117
|
+
itemsResult.sort((a, b) => {
|
|
118
|
+
for (let i = 0; i < orderByStatement.length; i++) {
|
|
119
|
+
let ob = orderByStatement[i];
|
|
120
|
+
let v1 = a[ob.Name];
|
|
121
|
+
let v2 = b[ob.Name];
|
|
122
|
+
if (v1 === v2) {
|
|
123
|
+
//these are equal - continue to second sort statement
|
|
111
124
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (_dependencies_1.IsLocalDev) {
|
|
118
|
-
logger.table(itemsResult.map(i => {
|
|
119
|
-
let row = {
|
|
120
|
-
Id: i.Id,
|
|
121
|
-
Title: i.Title
|
|
122
|
-
};
|
|
123
|
-
orderByStatement.forEach(s => { row[`${s.Name} ${s.IsAscending ? 'asc' : 'desc'}`] = i[s.Name]; });
|
|
124
|
-
return row;
|
|
125
|
-
}), "before sort", true);
|
|
126
|
-
}
|
|
127
|
-
itemsResult.sort((a, b) => {
|
|
128
|
-
for (let i = 0; i < orderByStatement.length; i++) {
|
|
129
|
-
let ob = orderByStatement[i];
|
|
130
|
-
let v1 = a[ob.Name];
|
|
131
|
-
let v2 = b[ob.Name];
|
|
132
|
-
if (v1 === v2) {
|
|
133
|
-
//these are equal - continue to second sort statement
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
if (ob.IsAscending)
|
|
137
|
-
return (v1 > v2) ? 1 : -1;
|
|
138
|
-
else
|
|
139
|
-
return (v2 > v1) ? 1 : -1;
|
|
140
|
-
}
|
|
125
|
+
else {
|
|
126
|
+
if (ob.IsAscending)
|
|
127
|
+
return (v1 > v2) ? 1 : -1;
|
|
128
|
+
else
|
|
129
|
+
return (v2 > v1) ? 1 : -1;
|
|
141
130
|
}
|
|
142
|
-
return 0;
|
|
143
|
-
});
|
|
144
|
-
if (_dependencies_1.IsLocalDev) {
|
|
145
|
-
logger.table(itemsResult.map(i => {
|
|
146
|
-
let row = {
|
|
147
|
-
Id: i.Id,
|
|
148
|
-
Title: i.Title
|
|
149
|
-
};
|
|
150
|
-
orderByStatement.forEach(s => { row[`${s.Name} ${s.IsAscending ? 'asc' : 'desc'}`] = i[s.Name]; });
|
|
151
|
-
return row;
|
|
152
|
-
}), "after sort", true);
|
|
153
131
|
}
|
|
132
|
+
return 0;
|
|
133
|
+
});
|
|
134
|
+
if (_dependencies_1.IsLocalDev) {
|
|
135
|
+
logger.table(itemsResult.map(i => {
|
|
136
|
+
let row = {
|
|
137
|
+
Id: i.Id,
|
|
138
|
+
Title: i.Title
|
|
139
|
+
};
|
|
140
|
+
orderByStatement.forEach(s => { row[`${s.Name} ${s.IsAscending ? 'asc' : 'desc'}`] = i[s.Name]; });
|
|
141
|
+
return row;
|
|
142
|
+
}), "after sort", true);
|
|
154
143
|
}
|
|
155
|
-
return itemsResult;
|
|
156
|
-
}
|
|
157
|
-
catch (ex) {
|
|
158
|
-
console.log(`isThrottled: ${isThrottled}`);
|
|
159
144
|
}
|
|
160
|
-
return
|
|
161
|
-
}
|
|
145
|
+
return itemsResult;
|
|
146
|
+
}
|
|
147
|
+
catch (ex) {
|
|
148
|
+
console.log(`isThrottled: ${isThrottled}`);
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
162
151
|
}
|
|
163
152
|
exports.GetListItemsByCaml = GetListItemsByCaml;
|
|
164
153
|
// (window as any).runtTest = true;
|
|
@@ -172,161 +161,94 @@ exports.GetListItemsByCaml = GetListItemsByCaml;
|
|
|
172
161
|
// });
|
|
173
162
|
// }, 500);
|
|
174
163
|
//ISSUE: 1565
|
|
175
|
-
function _processLookupThresholdCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
let
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return col === null;
|
|
196
|
-
}
|
|
197
|
-
return false;
|
|
198
|
-
});
|
|
199
|
-
let otherFieldNames = options.columns.filter((columnName) => {
|
|
200
|
-
let field = allListFieldsHash[columnName];
|
|
201
|
-
let exists = !(0, _dependencies_1.isNullOrUndefined)(field);
|
|
202
|
-
let isLookupField = exists && _isLookupOrUserField(field);
|
|
203
|
-
let isInOrderBy = exists && (0, _dependencies_1.firstOrNull)(orderByFields, (orderByField) => orderByField.InternalName === field.InternalName) !== null;
|
|
204
|
-
return exists && !isLookupField && !isInOrderBy;
|
|
205
|
-
});
|
|
206
|
-
//Split the requests into equally chunked arrays based on the lookup field count
|
|
207
|
-
//add lookup fields in chunk but leave room to add lookup fields from the order by statement
|
|
208
|
-
//since they are mandatory
|
|
209
|
-
let requestChunks = (0, _dependencies_1.chunkArray)(lookupOrUserFieldsToChunk, lookupOrUserFieldLimit - lookupOrUserFieldsInOrderBy.length);
|
|
210
|
-
let otherFieldsChunkSize = Math.ceil(otherFieldNames.length / requestChunks.length);
|
|
211
|
-
let otherFieldsChunks = (0, _dependencies_1.chunkArray)(otherFieldNames, otherFieldsChunkSize);
|
|
212
|
-
requestChunks.forEach((chunk, index) => {
|
|
213
|
-
//Add all order by fields to each request, this will include the lookup
|
|
214
|
-
//fields from the order by statement that we left room for previously
|
|
215
|
-
requestChunks[index] = chunk.concat(orderByFields.map((orderByField) => {
|
|
216
|
-
return orderByField.InternalName;
|
|
217
|
-
}));
|
|
218
|
-
//Add the other fields but split them across the requests so we don't request duplicate data
|
|
219
|
-
if (otherFieldsChunks[index]) {
|
|
220
|
-
requestChunks[index] = chunk.concat(otherFieldsChunks[index]);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
//requestChunks should now have about the same number of fields in each chunk and each
|
|
224
|
-
//chunk will have all the order by fields.
|
|
225
|
-
let queries = requestChunks.map((requestChunk) => {
|
|
226
|
-
let camlQueryClone = camlQuery;
|
|
227
|
-
let processColumnsResult = _processColumns(requestChunk, expandFields, allListFieldsHash);
|
|
228
|
-
//Id field must be included in oder to merge the items correctly
|
|
229
|
-
let viewFields = processColumnsResult.viewFields;
|
|
230
|
-
if (viewFields.length && !viewFields.includes("Id")) {
|
|
231
|
-
viewFields.push("Id");
|
|
232
|
-
}
|
|
233
|
-
let selectFields = processColumnsResult.selectFields;
|
|
234
|
-
if (selectFields.length && !selectFields.includes("Id")) {
|
|
235
|
-
selectFields.push("Id");
|
|
236
|
-
}
|
|
237
|
-
rtrnProcessRequestResult.needContentTypes = rtrnProcessRequestResult.needContentTypes || processColumnsResult.needContentTypes;
|
|
238
|
-
expandFields = processColumnsResult.expandFields;
|
|
239
|
-
if ((0, _dependencies_1.isNotEmptyArray)(viewFields)) {
|
|
240
|
-
camlQueryClone = (0, _dependencies_1.EnsureViewFields)(camlQueryClone, viewFields, true);
|
|
241
|
-
}
|
|
242
|
-
// if (isDebug()) {
|
|
243
|
-
// let lfields = viewFields.filter((fieldName) => {
|
|
244
|
-
// let field = allListFieldsHash[fieldName];
|
|
245
|
-
// return _isLookupOrUserField(field);
|
|
246
|
-
// });
|
|
247
|
-
// let xmlDoc = new DOMParser().parseFromString(camlQueryClone, "text/xml");
|
|
248
|
-
// let viewNode = xmlDoc.querySelector("View, view");
|
|
249
|
-
// let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
|
|
250
|
-
// let viewFields2 = Array.from(viewFieldsNode.children).map((viewFieldNode) => {
|
|
251
|
-
// let name = viewFieldNode.getAttribute("Name") || viewFieldNode.getAttribute("name");
|
|
252
|
-
// return name;
|
|
253
|
-
// });
|
|
254
|
-
// let lfields2 = viewFields2.filter((fieldName) => {
|
|
255
|
-
// let field = allListFieldsHash[fieldName];
|
|
256
|
-
// return _isLookupOrUserField(field);
|
|
257
|
-
// });
|
|
258
|
-
// if (lfields2.length !== lfields.length) {
|
|
259
|
-
// logger.warn("Lookup fields in caml query do not match look up fields in view fields.");
|
|
260
|
-
// logger.warn(`Lookup fields in caml query: ${lfields2}`)
|
|
261
|
-
// logger.warn(`Lookup fields in in view fields: ${lfields}`)
|
|
262
|
-
// }
|
|
263
|
-
// }
|
|
264
|
-
// Prepare the REST URL with select fields
|
|
265
|
-
let restUrlWithSelect = requestUrl;
|
|
266
|
-
if (expandFields.length > 0) {
|
|
267
|
-
restUrlWithSelect += ',' + expandFields.join(',');
|
|
268
|
-
}
|
|
269
|
-
// Include the lookup user select fields with the other select fields
|
|
270
|
-
restUrlWithSelect += '&$select=' + selectFields.join(',');
|
|
271
|
-
return { camlQueryClone, restUrlWithSelect, viewFields };
|
|
272
|
-
});
|
|
273
|
-
let mergedItems = null;
|
|
274
|
-
for (let i = 0; i < queries.length; i++) {
|
|
275
|
-
const { camlQueryClone, restUrlWithSelect, viewFields } = queries[i];
|
|
276
|
-
let loopResult = yield processRequestResult(requestUrl, restUrlWithSelect, camlQueryClone, Object.assign(Object.assign({}, options), { columns: viewFields }), siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement);
|
|
277
|
-
if ((0, _dependencies_1.isNullOrUndefined)(mergedItems)) {
|
|
278
|
-
mergedItems = loopResult.items;
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
for (let restItemIndex = 0; restItemIndex < loopResult.items.length; restItemIndex++) {
|
|
282
|
-
//The item chunks (loopResult) should be in the same order as mergedItems because each request should have the
|
|
283
|
-
//same number of items returned in the same order. The only difference between requests is which fields are present.
|
|
284
|
-
//So request 1 will have the 1st set of fields, request 2 will have the 2nd set. etc.
|
|
285
|
-
//This means that the restItemIndex should be the same as existingItemIndex for each iteration. But, we do these extra
|
|
286
|
-
//checks just in case.
|
|
287
|
-
let restItem = loopResult.items[restItemIndex];
|
|
288
|
-
let existingItem = mergedItems[restItemIndex];
|
|
289
|
-
let existingItemIndex = restItemIndex;
|
|
290
|
-
if ((0, _dependencies_1.isNullOrUndefined)(existingItem) || existingItem.Id !== restItem.Id) {
|
|
291
|
-
existingItemIndex = (0, _dependencies_1.firstIndexOf)(mergedItems, (mergedItem) => {
|
|
292
|
-
return mergedItem.Id === restItem.Id;
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
if (existingItemIndex === -1) {
|
|
296
|
-
//We shouldn't get here. Each chunk should have the same items in the same order.
|
|
297
|
-
logger.warn("_processLookupThresholdCamlRequest results are out of sync");
|
|
298
|
-
mergedItems.push(restItem);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
let existingItem = mergedItems[existingItemIndex];
|
|
302
|
-
let FieldValuesAsText = Object.assign(Object.assign({}, (existingItem.FieldValuesAsText || {})), (restItem.FieldValuesAsText || {}));
|
|
303
|
-
let FieldValuesForEdit = Object.assign(Object.assign({}, (existingItem.FieldValuesForEdit || {})), (restItem.FieldValuesForEdit || {}));
|
|
304
|
-
existingItem = Object.assign(Object.assign({}, existingItem), restItem);
|
|
305
|
-
existingItem.FieldValuesAsText = FieldValuesAsText;
|
|
306
|
-
existingItem.FieldValuesForEdit = FieldValuesForEdit;
|
|
307
|
-
mergedItems[existingItemIndex] = existingItem;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// only need to put this true if it happens once
|
|
312
|
-
if (loopResult.postProcessOrderBy) {
|
|
313
|
-
rtrnProcessRequestResult.postProcessOrderBy = true;
|
|
314
|
-
}
|
|
164
|
+
async function _processLookupThresholdCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize) {
|
|
165
|
+
let rtrnProcessRequestResult = {
|
|
166
|
+
items: [],
|
|
167
|
+
postProcessOrderBy: false,
|
|
168
|
+
needContentTypes: false
|
|
169
|
+
};
|
|
170
|
+
let orderByFields = orderByStatement.map((orderByField) => {
|
|
171
|
+
let field = allListFieldsHash[orderByField.Name];
|
|
172
|
+
return field;
|
|
173
|
+
});
|
|
174
|
+
let lookupOrUserFieldsInOrderBy = orderByFields.filter((orderByField) => {
|
|
175
|
+
return _isLookupOrUserField(orderByField);
|
|
176
|
+
});
|
|
177
|
+
let lookupOrUserFieldsToChunk = options.columns.filter((columnName) => {
|
|
178
|
+
let field = allListFieldsHash[columnName];
|
|
179
|
+
if (_isLookupOrUserField(field)) {
|
|
180
|
+
let col = (0, _dependencies_1.firstOrNull)(lookupOrUserFieldsInOrderBy, (orderByField) => {
|
|
181
|
+
return field.InternalName !== orderByField.InternalName;
|
|
182
|
+
});
|
|
183
|
+
return col === null;
|
|
315
184
|
}
|
|
316
|
-
|
|
317
|
-
return rtrnProcessRequestResult;
|
|
185
|
+
return false;
|
|
318
186
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
let
|
|
187
|
+
let otherFieldNames = options.columns.filter((columnName) => {
|
|
188
|
+
let field = allListFieldsHash[columnName];
|
|
189
|
+
let exists = !(0, _dependencies_1.isNullOrUndefined)(field);
|
|
190
|
+
let isLookupField = exists && _isLookupOrUserField(field);
|
|
191
|
+
let isInOrderBy = exists && (0, _dependencies_1.firstOrNull)(orderByFields, (orderByField) => orderByField.InternalName === field.InternalName) !== null;
|
|
192
|
+
return exists && !isLookupField && !isInOrderBy;
|
|
193
|
+
});
|
|
194
|
+
//Split the requests into equally chunked arrays based on the lookup field count
|
|
195
|
+
//add lookup fields in chunk but leave room to add lookup fields from the order by statement
|
|
196
|
+
//since they are mandatory
|
|
197
|
+
let requestChunks = (0, _dependencies_1.chunkArray)(lookupOrUserFieldsToChunk, lookupOrUserFieldLimit - lookupOrUserFieldsInOrderBy.length);
|
|
198
|
+
let otherFieldsChunkSize = Math.ceil(otherFieldNames.length / requestChunks.length);
|
|
199
|
+
let otherFieldsChunks = (0, _dependencies_1.chunkArray)(otherFieldNames, otherFieldsChunkSize);
|
|
200
|
+
requestChunks.forEach((chunk, index) => {
|
|
201
|
+
//Add all order by fields to each request, this will include the lookup
|
|
202
|
+
//fields from the order by statement that we left room for previously
|
|
203
|
+
requestChunks[index] = chunk.concat(orderByFields.map((orderByField) => {
|
|
204
|
+
return orderByField.InternalName;
|
|
205
|
+
}));
|
|
206
|
+
//Add the other fields but split them across the requests so we don't request duplicate data
|
|
207
|
+
if (otherFieldsChunks[index]) {
|
|
208
|
+
requestChunks[index] = chunk.concat(otherFieldsChunks[index]);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
//requestChunks should now have about the same number of fields in each chunk and each
|
|
212
|
+
//chunk will have all the order by fields.
|
|
213
|
+
let queries = requestChunks.map((requestChunk) => {
|
|
214
|
+
let camlQueryClone = camlQuery;
|
|
215
|
+
let processColumnsResult = _processColumns(requestChunk, expandFields, allListFieldsHash);
|
|
216
|
+
//Id field must be included in oder to merge the items correctly
|
|
323
217
|
let viewFields = processColumnsResult.viewFields;
|
|
218
|
+
if (viewFields.length && !viewFields.includes("Id")) {
|
|
219
|
+
viewFields.push("Id");
|
|
220
|
+
}
|
|
324
221
|
let selectFields = processColumnsResult.selectFields;
|
|
222
|
+
if (selectFields.length && !selectFields.includes("Id")) {
|
|
223
|
+
selectFields.push("Id");
|
|
224
|
+
}
|
|
225
|
+
rtrnProcessRequestResult.needContentTypes = rtrnProcessRequestResult.needContentTypes || processColumnsResult.needContentTypes;
|
|
325
226
|
expandFields = processColumnsResult.expandFields;
|
|
326
|
-
let needContentTypes = processColumnsResult.needContentTypes;
|
|
327
227
|
if ((0, _dependencies_1.isNotEmptyArray)(viewFields)) {
|
|
328
|
-
|
|
228
|
+
camlQueryClone = (0, _dependencies_1.EnsureViewFields)(camlQueryClone, viewFields, true);
|
|
329
229
|
}
|
|
230
|
+
// if (isDebug()) {
|
|
231
|
+
// let lfields = viewFields.filter((fieldName) => {
|
|
232
|
+
// let field = allListFieldsHash[fieldName];
|
|
233
|
+
// return _isLookupOrUserField(field);
|
|
234
|
+
// });
|
|
235
|
+
// let xmlDoc = new DOMParser().parseFromString(camlQueryClone, "text/xml");
|
|
236
|
+
// let viewNode = xmlDoc.querySelector("View, view");
|
|
237
|
+
// let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
|
|
238
|
+
// let viewFields2 = Array.from(viewFieldsNode.children).map((viewFieldNode) => {
|
|
239
|
+
// let name = viewFieldNode.getAttribute("Name") || viewFieldNode.getAttribute("name");
|
|
240
|
+
// return name;
|
|
241
|
+
// });
|
|
242
|
+
// let lfields2 = viewFields2.filter((fieldName) => {
|
|
243
|
+
// let field = allListFieldsHash[fieldName];
|
|
244
|
+
// return _isLookupOrUserField(field);
|
|
245
|
+
// });
|
|
246
|
+
// if (lfields2.length !== lfields.length) {
|
|
247
|
+
// logger.warn("Lookup fields in caml query do not match look up fields in view fields.");
|
|
248
|
+
// logger.warn(`Lookup fields in caml query: ${lfields2}`)
|
|
249
|
+
// logger.warn(`Lookup fields in in view fields: ${lfields}`)
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
330
252
|
// Prepare the REST URL with select fields
|
|
331
253
|
let restUrlWithSelect = requestUrl;
|
|
332
254
|
if (expandFields.length > 0) {
|
|
@@ -334,10 +256,82 @@ function _processNormalCamlRequest(orderByStatement, allListFieldsHash, options,
|
|
|
334
256
|
}
|
|
335
257
|
// Include the lookup user select fields with the other select fields
|
|
336
258
|
restUrlWithSelect += '&$select=' + selectFields.join(',');
|
|
337
|
-
|
|
338
|
-
let result = yield processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement);
|
|
339
|
-
return Object.assign(Object.assign({}, result), { needContentTypes });
|
|
259
|
+
return { camlQueryClone, restUrlWithSelect, viewFields };
|
|
340
260
|
});
|
|
261
|
+
let mergedItems = null;
|
|
262
|
+
for (let i = 0; i < queries.length; i++) {
|
|
263
|
+
const { camlQueryClone, restUrlWithSelect, viewFields } = queries[i];
|
|
264
|
+
let loopResult = await processRequestResult(requestUrl, restUrlWithSelect, camlQueryClone, { ...options, columns: viewFields }, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement);
|
|
265
|
+
if ((0, _dependencies_1.isNullOrUndefined)(mergedItems)) {
|
|
266
|
+
mergedItems = loopResult.items;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
for (let restItemIndex = 0; restItemIndex < loopResult.items.length; restItemIndex++) {
|
|
270
|
+
//The item chunks (loopResult) should be in the same order as mergedItems because each request should have the
|
|
271
|
+
//same number of items returned in the same order. The only difference between requests is which fields are present.
|
|
272
|
+
//So request 1 will have the 1st set of fields, request 2 will have the 2nd set. etc.
|
|
273
|
+
//This means that the restItemIndex should be the same as existingItemIndex for each iteration. But, we do these extra
|
|
274
|
+
//checks just in case.
|
|
275
|
+
let restItem = loopResult.items[restItemIndex];
|
|
276
|
+
let existingItem = mergedItems[restItemIndex];
|
|
277
|
+
let existingItemIndex = restItemIndex;
|
|
278
|
+
if ((0, _dependencies_1.isNullOrUndefined)(existingItem) || existingItem.Id !== restItem.Id) {
|
|
279
|
+
existingItemIndex = (0, _dependencies_1.firstIndexOf)(mergedItems, (mergedItem) => {
|
|
280
|
+
return mergedItem.Id === restItem.Id;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (existingItemIndex === -1) {
|
|
284
|
+
//We shouldn't get here. Each chunk should have the same items in the same order.
|
|
285
|
+
logger.warn("_processLookupThresholdCamlRequest results are out of sync");
|
|
286
|
+
mergedItems.push(restItem);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
let existingItem = mergedItems[existingItemIndex];
|
|
290
|
+
let FieldValuesAsText = {
|
|
291
|
+
...(existingItem.FieldValuesAsText || {}),
|
|
292
|
+
...(restItem.FieldValuesAsText || {})
|
|
293
|
+
};
|
|
294
|
+
let FieldValuesForEdit = {
|
|
295
|
+
...(existingItem.FieldValuesForEdit || {}),
|
|
296
|
+
...(restItem.FieldValuesForEdit || {})
|
|
297
|
+
};
|
|
298
|
+
existingItem = { ...existingItem, ...restItem };
|
|
299
|
+
existingItem.FieldValuesAsText = FieldValuesAsText;
|
|
300
|
+
existingItem.FieldValuesForEdit = FieldValuesForEdit;
|
|
301
|
+
mergedItems[existingItemIndex] = existingItem;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// only need to put this true if it happens once
|
|
306
|
+
if (loopResult.postProcessOrderBy) {
|
|
307
|
+
rtrnProcessRequestResult.postProcessOrderBy = true;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
rtrnProcessRequestResult.items = mergedItems;
|
|
311
|
+
return rtrnProcessRequestResult;
|
|
312
|
+
}
|
|
313
|
+
async function _processNormalCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize) {
|
|
314
|
+
let processColumnsResult = _processColumns(options.columns, expandFields, allListFieldsHash);
|
|
315
|
+
let viewFields = processColumnsResult.viewFields;
|
|
316
|
+
let selectFields = processColumnsResult.selectFields;
|
|
317
|
+
expandFields = processColumnsResult.expandFields;
|
|
318
|
+
let needContentTypes = processColumnsResult.needContentTypes;
|
|
319
|
+
if ((0, _dependencies_1.isNotEmptyArray)(viewFields)) {
|
|
320
|
+
camlQuery = (0, _dependencies_1.EnsureViewFields)(camlQuery, viewFields, true);
|
|
321
|
+
}
|
|
322
|
+
// Prepare the REST URL with select fields
|
|
323
|
+
let restUrlWithSelect = requestUrl;
|
|
324
|
+
if (expandFields.length > 0) {
|
|
325
|
+
restUrlWithSelect += ',' + expandFields.join(',');
|
|
326
|
+
}
|
|
327
|
+
// Include the lookup user select fields with the other select fields
|
|
328
|
+
restUrlWithSelect += '&$select=' + selectFields.join(',');
|
|
329
|
+
// Process the request and get the result
|
|
330
|
+
let result = await processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement);
|
|
331
|
+
return {
|
|
332
|
+
...result,
|
|
333
|
+
needContentTypes
|
|
334
|
+
};
|
|
341
335
|
}
|
|
342
336
|
function _ensureViewFields(viewFieldsNode, columns, allListFieldsHash) {
|
|
343
337
|
//ISSUE: 1565
|
|
@@ -538,92 +532,90 @@ function _isLookupOrUserField(field) {
|
|
|
538
532
|
return false;
|
|
539
533
|
}
|
|
540
534
|
}
|
|
541
|
-
function processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
orderFieldValue = (0, web_1.SPServerLocalTimeToUTCSync)(siteUrl, orderFieldValueAsDate).replace(/T/i, " ").replace(/Z/i, " ");
|
|
584
|
-
}
|
|
585
|
-
catch (e) { }
|
|
535
|
+
async function processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement) {
|
|
536
|
+
//issue 6150: if there are too many fields, url will be too long. just get all columns without adding a $select
|
|
537
|
+
if (restUrlWithSelect.length < 2000)
|
|
538
|
+
requestUrl = restUrlWithSelect;
|
|
539
|
+
let query = { ViewXml: camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`) };
|
|
540
|
+
if (!(0, _dependencies_1.isNullOrEmptyString)(options.FolderServerRelativeUrl))
|
|
541
|
+
query.FolderServerRelativeUrl = options.FolderServerRelativeUrl;
|
|
542
|
+
let data = { query: query };
|
|
543
|
+
let items = [];
|
|
544
|
+
//let triedWithoutViewFields = false;
|
|
545
|
+
let postProcessOrderBy = false;
|
|
546
|
+
do {
|
|
547
|
+
try {
|
|
548
|
+
let requestResult = await (0, rest_1.GetJson)(requestUrl, JSON.stringify(data), {
|
|
549
|
+
allowCache: options.refreshCache !== true,
|
|
550
|
+
postCacheKey: JSON.stringify(data.query),
|
|
551
|
+
jsonMetadata: _dependencies_1.jsonTypes.nometadata,
|
|
552
|
+
spWebUrl: siteUrl
|
|
553
|
+
});
|
|
554
|
+
if (requestResult && requestResult.value)
|
|
555
|
+
items.push(...requestResult.value);
|
|
556
|
+
let itemsLeftToGet = totalNumberOfItemsToGet - items.length;
|
|
557
|
+
if (itemsLeftToGet > 0 && //we need more items
|
|
558
|
+
requestResult.value.length === batchSize //we might have more on server since we got the full batch size we asked for
|
|
559
|
+
) {
|
|
560
|
+
let lastItem = items[items.length - 1];
|
|
561
|
+
let lastItemId = lastItem.Id;
|
|
562
|
+
let pagingInfoSort = "";
|
|
563
|
+
//Issue 7542 need to add order by value to the paging info if it is in the query
|
|
564
|
+
if (!postProcessOrderBy && orderByStatement && orderByStatement.length) {
|
|
565
|
+
let orderFieldName = orderByStatement[0].Name;
|
|
566
|
+
let orderFieldValue = lastItem[orderFieldName];
|
|
567
|
+
//if field is ID - do not do it.
|
|
568
|
+
if (orderFieldName.toLowerCase() !== "id" && !(0, _dependencies_1.isNullOrUndefined)(orderFieldValue)) {
|
|
569
|
+
//if value is date - we need it in ISO and in this format: yyyyMMdd HH:mm:ss
|
|
570
|
+
try {
|
|
571
|
+
//Numbers cast to date properly but they are not dates. ignore number values.
|
|
572
|
+
let orderFieldValueAsDate = (0, _dependencies_1.isNumeric)(orderFieldValue) ? null : new Date(orderFieldValue);
|
|
573
|
+
if ((0, _dependencies_1.isDate)(orderFieldValueAsDate)) {
|
|
574
|
+
try {
|
|
575
|
+
//issue 7599 date only field on different time zone...
|
|
576
|
+
orderFieldValue = (0, web_1.SPServerLocalTimeToUTCSync)(siteUrl, orderFieldValueAsDate).replace(/T/i, " ").replace(/Z/i, " ");
|
|
586
577
|
}
|
|
578
|
+
catch (e) { }
|
|
587
579
|
}
|
|
588
|
-
catch (e) { }
|
|
589
|
-
pagingInfoSort = `&p_${orderFieldName}=${(0, _dependencies_1.encodeURIComponentEX)(orderFieldValue)}`;
|
|
590
580
|
}
|
|
581
|
+
catch (e) { }
|
|
582
|
+
pagingInfoSort = `&p_${orderFieldName}=${(0, _dependencies_1.encodeURIComponentEX)(orderFieldValue)}`;
|
|
591
583
|
}
|
|
592
|
-
data.query.ListItemCollectionPosition = {
|
|
593
|
-
"PagingInfo": `Paged=TRUE${pagingInfoSort}&p_ID=${lastItemId}`
|
|
594
|
-
};
|
|
595
|
-
if (itemsLeftToGet < batchSize) //the last batch should be smaller, update the row limit
|
|
596
|
-
data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${itemsLeftToGet}</RowLimit></View>`);
|
|
597
584
|
}
|
|
598
|
-
|
|
599
|
-
|
|
585
|
+
data.query.ListItemCollectionPosition = {
|
|
586
|
+
"PagingInfo": `Paged=TRUE${pagingInfoSort}&p_ID=${lastItemId}`
|
|
587
|
+
};
|
|
588
|
+
if (itemsLeftToGet < batchSize) //the last batch should be smaller, update the row limit
|
|
589
|
+
data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${itemsLeftToGet}</RowLimit></View>`);
|
|
600
590
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
591
|
+
else
|
|
592
|
+
data = null;
|
|
593
|
+
}
|
|
594
|
+
catch (e) {
|
|
595
|
+
if ((0, common_1.__getSPRestErrorData)(e).code.indexOf('SPQueryThrottledException')) {
|
|
596
|
+
//test again - on awaiting score view, this will work but will ONLY return the order by fields...
|
|
597
|
+
// if (!triedWithoutViewFields) {
|
|
598
|
+
// //Our own issues list had too many lookup fields.
|
|
599
|
+
// logger.info("Query throttled, trying again without view fields... some fields might be missing from results.");
|
|
600
|
+
// triedWithoutViewFields = true;
|
|
601
|
+
// camlQuery = EnsureViewFields(camlQuery, orderByStatement.map(o => o.Name), false, true);
|
|
602
|
+
// data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`);
|
|
603
|
+
// }
|
|
604
|
+
// else
|
|
605
|
+
if (!postProcessOrderBy && orderByStatement.length > 0) {
|
|
606
|
+
logger.warn("Query throttled, trying again without order by...");
|
|
607
|
+
postProcessOrderBy = true;
|
|
608
|
+
camlQuery = (0, _dependencies_1.RemoveOrderByFromCaml)(camlQuery);
|
|
609
|
+
camlQuery = (0, _dependencies_1.EnsureViewFields)(camlQuery, [], false, true);
|
|
610
|
+
data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`);
|
|
621
611
|
}
|
|
622
612
|
else
|
|
623
|
-
throw e; //
|
|
613
|
+
throw e; //still throttled? might be due to filter query
|
|
624
614
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
615
|
+
else
|
|
616
|
+
throw e; //different error
|
|
617
|
+
}
|
|
618
|
+
} while (!(0, _dependencies_1.isNullOrEmptyString)(data));
|
|
619
|
+
return { items: items, postProcessOrderBy: postProcessOrderBy };
|
|
628
620
|
}
|
|
629
621
|
//# sourceMappingURL=GetListItemsByCaml.js.map
|