@kwiz/common 1.0.1

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 (310) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_dependencies.d.ts +1 -0
  3. package/dist/_dependencies.js +8 -0
  4. package/dist/_dependencies.js.map +1 -0
  5. package/dist/helpers/Guid.d.ts +119 -0
  6. package/dist/helpers/Guid.js +183 -0
  7. package/dist/helpers/Guid.js.map +1 -0
  8. package/dist/helpers/_dependencies.d.ts +2 -0
  9. package/dist/helpers/_dependencies.js +21 -0
  10. package/dist/helpers/_dependencies.js.map +1 -0
  11. package/dist/helpers/base64.d.ts +8 -0
  12. package/dist/helpers/base64.js +178 -0
  13. package/dist/helpers/base64.js.map +1 -0
  14. package/dist/helpers/browser.d.ts +144 -0
  15. package/dist/helpers/browser.js +1200 -0
  16. package/dist/helpers/browser.js.map +1 -0
  17. package/dist/helpers/browserinfo.d.ts +23 -0
  18. package/dist/helpers/browserinfo.js +215 -0
  19. package/dist/helpers/browserinfo.js.map +1 -0
  20. package/dist/helpers/collections.base.d.ts +128 -0
  21. package/dist/helpers/collections.base.js +430 -0
  22. package/dist/helpers/collections.base.js.map +1 -0
  23. package/dist/helpers/collections.d.ts +18 -0
  24. package/dist/helpers/collections.js +99 -0
  25. package/dist/helpers/collections.js.map +1 -0
  26. package/dist/helpers/color.d.ts +11 -0
  27. package/dist/helpers/color.js +57 -0
  28. package/dist/helpers/color.js.map +1 -0
  29. package/dist/helpers/cookies.d.ts +6 -0
  30. package/dist/helpers/cookies.js +56 -0
  31. package/dist/helpers/cookies.js.map +1 -0
  32. package/dist/helpers/date.d.ts +43 -0
  33. package/dist/helpers/date.js +158 -0
  34. package/dist/helpers/date.js.map +1 -0
  35. package/dist/helpers/debug.d.ts +33 -0
  36. package/dist/helpers/debug.js +177 -0
  37. package/dist/helpers/debug.js.map +1 -0
  38. package/dist/helpers/emails.d.ts +2 -0
  39. package/dist/helpers/emails.js +10 -0
  40. package/dist/helpers/emails.js.map +1 -0
  41. package/dist/helpers/eval.d.ts +1 -0
  42. package/dist/helpers/eval.js +10 -0
  43. package/dist/helpers/eval.js.map +1 -0
  44. package/dist/helpers/file.d.ts +11 -0
  45. package/dist/helpers/file.js +55 -0
  46. package/dist/helpers/file.js.map +1 -0
  47. package/dist/helpers/flatted.d.ts +20 -0
  48. package/dist/helpers/flatted.js +135 -0
  49. package/dist/helpers/flatted.js.map +1 -0
  50. package/dist/helpers/functions.d.ts +4 -0
  51. package/dist/helpers/functions.js +17 -0
  52. package/dist/helpers/functions.js.map +1 -0
  53. package/dist/helpers/graph/calendar.types.d.ts +3 -0
  54. package/dist/helpers/graph/calendar.types.js +15 -0
  55. package/dist/helpers/graph/calendar.types.js.map +1 -0
  56. package/dist/helpers/http.d.ts +25 -0
  57. package/dist/helpers/http.js +70 -0
  58. package/dist/helpers/http.js.map +1 -0
  59. package/dist/helpers/images.d.ts +16 -0
  60. package/dist/helpers/images.js +21 -0
  61. package/dist/helpers/images.js.map +1 -0
  62. package/dist/helpers/index.d.ts +29 -0
  63. package/dist/helpers/index.js +46 -0
  64. package/dist/helpers/index.js.map +1 -0
  65. package/dist/helpers/json.d.ts +3 -0
  66. package/dist/helpers/json.js +44 -0
  67. package/dist/helpers/json.js.map +1 -0
  68. package/dist/helpers/md5.d.ts +5 -0
  69. package/dist/helpers/md5.js +172 -0
  70. package/dist/helpers/md5.js.map +1 -0
  71. package/dist/helpers/objects.d.ts +49 -0
  72. package/dist/helpers/objects.js +271 -0
  73. package/dist/helpers/objects.js.map +1 -0
  74. package/dist/helpers/promises.d.ts +14 -0
  75. package/dist/helpers/promises.js +112 -0
  76. package/dist/helpers/promises.js.map +1 -0
  77. package/dist/helpers/random.d.ts +2 -0
  78. package/dist/helpers/random.js +32 -0
  79. package/dist/helpers/random.js.map +1 -0
  80. package/dist/helpers/scheduler/scheduler.d.ts +39 -0
  81. package/dist/helpers/scheduler/scheduler.js +109 -0
  82. package/dist/helpers/scheduler/scheduler.js.map +1 -0
  83. package/dist/helpers/sharepoint.d.ts +112 -0
  84. package/dist/helpers/sharepoint.js +629 -0
  85. package/dist/helpers/sharepoint.js.map +1 -0
  86. package/dist/helpers/strings.d.ts +56 -0
  87. package/dist/helpers/strings.js +282 -0
  88. package/dist/helpers/strings.js.map +1 -0
  89. package/dist/helpers/typecheckers.d.ts +56 -0
  90. package/dist/helpers/typecheckers.js +274 -0
  91. package/dist/helpers/typecheckers.js.map +1 -0
  92. package/dist/helpers/url.d.ts +46 -0
  93. package/dist/helpers/url.js +199 -0
  94. package/dist/helpers/url.js.map +1 -0
  95. package/dist/helpers/urlhelper.d.ts +16 -0
  96. package/dist/helpers/urlhelper.js +96 -0
  97. package/dist/helpers/urlhelper.js.map +1 -0
  98. package/dist/index.d.ts +15 -0
  99. package/dist/index.js +37 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/types/common.types.d.ts +19 -0
  102. package/dist/types/common.types.js +4 -0
  103. package/dist/types/common.types.js.map +1 -0
  104. package/dist/types/flatted.types.d.ts +49 -0
  105. package/dist/types/flatted.types.js +3 -0
  106. package/dist/types/flatted.types.js.map +1 -0
  107. package/dist/types/globals.types.d.ts +6 -0
  108. package/dist/types/globals.types.js +3 -0
  109. package/dist/types/globals.types.js.map +1 -0
  110. package/dist/types/graph/calendar.types.d.ts +79 -0
  111. package/dist/types/graph/calendar.types.js +3 -0
  112. package/dist/types/graph/calendar.types.js.map +1 -0
  113. package/dist/types/graph/index.d.ts +1 -0
  114. package/dist/types/graph/index.js +18 -0
  115. package/dist/types/graph/index.js.map +1 -0
  116. package/dist/types/index.d.ts +11 -0
  117. package/dist/types/index.js +28 -0
  118. package/dist/types/index.js.map +1 -0
  119. package/dist/types/knownscript.types.d.ts +22 -0
  120. package/dist/types/knownscript.types.js +3 -0
  121. package/dist/types/knownscript.types.js.map +1 -0
  122. package/dist/types/libs/datajs.types.d.ts +29 -0
  123. package/dist/types/libs/datajs.types.js +3 -0
  124. package/dist/types/libs/datajs.types.js.map +1 -0
  125. package/dist/types/libs/ics.types.d.ts +29 -0
  126. package/dist/types/libs/ics.types.js +3 -0
  127. package/dist/types/libs/ics.types.js.map +1 -0
  128. package/dist/types/libs/index.d.ts +3 -0
  129. package/dist/types/libs/index.js +20 -0
  130. package/dist/types/libs/index.js.map +1 -0
  131. package/dist/types/libs/msal.types.d.ts +33 -0
  132. package/dist/types/libs/msal.types.js +63 -0
  133. package/dist/types/libs/msal.types.js.map +1 -0
  134. package/dist/types/locales.d.ts +122 -0
  135. package/dist/types/locales.js +1 -0
  136. package/dist/types/locales.js.map +1 -0
  137. package/dist/types/localstoragecache.types.d.ts +8 -0
  138. package/dist/types/localstoragecache.types.js +3 -0
  139. package/dist/types/localstoragecache.types.js.map +1 -0
  140. package/dist/types/moment.d.ts +6 -0
  141. package/dist/types/moment.js +1 -0
  142. package/dist/types/moment.js.map +1 -0
  143. package/dist/types/regex.types.d.ts +14 -0
  144. package/dist/types/regex.types.js +3 -0
  145. package/dist/types/regex.types.js.map +1 -0
  146. package/dist/types/rest.types.d.ts +81 -0
  147. package/dist/types/rest.types.js +24 -0
  148. package/dist/types/rest.types.js.map +1 -0
  149. package/dist/types/sharepoint.types.d.ts +1432 -0
  150. package/dist/types/sharepoint.types.js +629 -0
  151. package/dist/types/sharepoint.types.js.map +1 -0
  152. package/dist/types/sharepoint.utils.types.d.ts +246 -0
  153. package/dist/types/sharepoint.utils.types.js +26 -0
  154. package/dist/types/sharepoint.utils.types.js.map +1 -0
  155. package/dist/utils/_dependencies.d.ts +3 -0
  156. package/dist/utils/_dependencies.js +24 -0
  157. package/dist/utils/_dependencies.js.map +1 -0
  158. package/dist/utils/base64.d.ts +2 -0
  159. package/dist/utils/base64.js +41 -0
  160. package/dist/utils/base64.js.map +1 -0
  161. package/dist/utils/consolelogger.d.ts +73 -0
  162. package/dist/utils/consolelogger.js +281 -0
  163. package/dist/utils/consolelogger.js.map +1 -0
  164. package/dist/utils/date.d.ts +10 -0
  165. package/dist/utils/date.js +30 -0
  166. package/dist/utils/date.js.map +1 -0
  167. package/dist/utils/emails.d.ts +2 -0
  168. package/dist/utils/emails.js +24 -0
  169. package/dist/utils/emails.js.map +1 -0
  170. package/dist/utils/index.d.ts +13 -0
  171. package/dist/utils/index.js +31 -0
  172. package/dist/utils/index.js.map +1 -0
  173. package/dist/utils/knownscript.d.ts +99 -0
  174. package/dist/utils/knownscript.js +261 -0
  175. package/dist/utils/knownscript.js.map +1 -0
  176. package/dist/utils/localstoragecache.d.ts +19 -0
  177. package/dist/utils/localstoragecache.js +372 -0
  178. package/dist/utils/localstoragecache.js.map +1 -0
  179. package/dist/utils/rest.d.ts +17 -0
  180. package/dist/utils/rest.js +402 -0
  181. package/dist/utils/rest.js.map +1 -0
  182. package/dist/utils/script.d.ts +33 -0
  183. package/dist/utils/script.js +169 -0
  184. package/dist/utils/script.js.map +1 -0
  185. package/dist/utils/sharepoint.rest/common.d.ts +32 -0
  186. package/dist/utils/sharepoint.rest/common.js +146 -0
  187. package/dist/utils/sharepoint.rest/common.js.map +1 -0
  188. package/dist/utils/sharepoint.rest/date.d.ts +2 -0
  189. package/dist/utils/sharepoint.rest/date.js +57 -0
  190. package/dist/utils/sharepoint.rest/date.js.map +1 -0
  191. package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
  192. package/dist/utils/sharepoint.rest/file.folder.js +305 -0
  193. package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
  194. package/dist/utils/sharepoint.rest/index.d.ts +11 -0
  195. package/dist/utils/sharepoint.rest/index.js +28 -0
  196. package/dist/utils/sharepoint.rest/index.js.map +1 -0
  197. package/dist/utils/sharepoint.rest/item.d.ts +81 -0
  198. package/dist/utils/sharepoint.rest/item.js +444 -0
  199. package/dist/utils/sharepoint.rest/item.js.map +1 -0
  200. package/dist/utils/sharepoint.rest/list.d.ts +228 -0
  201. package/dist/utils/sharepoint.rest/list.js +868 -0
  202. package/dist/utils/sharepoint.rest/list.js.map +1 -0
  203. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
  204. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
  205. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
  206. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
  207. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
  208. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
  209. package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
  210. package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
  211. package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
  212. package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
  213. package/dist/utils/sharepoint.rest/user-search.js +239 -0
  214. package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
  215. package/dist/utils/sharepoint.rest/user.d.ts +71 -0
  216. package/dist/utils/sharepoint.rest/user.js +404 -0
  217. package/dist/utils/sharepoint.rest/user.js.map +1 -0
  218. package/dist/utils/sharepoint.rest/web.d.ts +107 -0
  219. package/dist/utils/sharepoint.rest/web.js +929 -0
  220. package/dist/utils/sharepoint.rest/web.js.map +1 -0
  221. package/dist/utils/sod.d.ts +29 -0
  222. package/dist/utils/sod.js +177 -0
  223. package/dist/utils/sod.js.map +1 -0
  224. package/package.json +60 -0
  225. package/readme.md +13 -0
  226. package/src/_dependencies.ts +2 -0
  227. package/src/helpers/Guid.ts +182 -0
  228. package/src/helpers/_dependencies.ts +3 -0
  229. package/src/helpers/base64.ts +174 -0
  230. package/src/helpers/browser.test.js +9 -0
  231. package/src/helpers/browser.ts +1299 -0
  232. package/src/helpers/browserinfo.ts +293 -0
  233. package/src/helpers/collections.base.test.js +26 -0
  234. package/src/helpers/collections.base.ts +439 -0
  235. package/src/helpers/collections.ts +108 -0
  236. package/src/helpers/color.ts +55 -0
  237. package/src/helpers/cookies.ts +55 -0
  238. package/src/helpers/date.test.js +97 -0
  239. package/src/helpers/date.ts +163 -0
  240. package/src/helpers/debug.ts +187 -0
  241. package/src/helpers/emails.ts +7 -0
  242. package/src/helpers/eval.ts +5 -0
  243. package/src/helpers/file.test.js +51 -0
  244. package/src/helpers/file.ts +59 -0
  245. package/src/helpers/flatted.ts +150 -0
  246. package/src/helpers/functions.ts +17 -0
  247. package/src/helpers/graph/calendar.types.ts +11 -0
  248. package/src/helpers/http.ts +70 -0
  249. package/src/helpers/images.ts +23 -0
  250. package/src/helpers/index.ts +29 -0
  251. package/src/helpers/json.ts +39 -0
  252. package/src/helpers/md5.ts +190 -0
  253. package/src/helpers/objects.test.js +27 -0
  254. package/src/helpers/objects.ts +256 -0
  255. package/src/helpers/promises.test.js +18 -0
  256. package/src/helpers/promises.ts +102 -0
  257. package/src/helpers/random.ts +27 -0
  258. package/src/helpers/scheduler/scheduler.test.js +104 -0
  259. package/src/helpers/scheduler/scheduler.ts +132 -0
  260. package/src/helpers/sharepoint.ts +681 -0
  261. package/src/helpers/strings.test.js +43 -0
  262. package/src/helpers/strings.ts +288 -0
  263. package/src/helpers/typecheckers.test.js +35 -0
  264. package/src/helpers/typecheckers.ts +263 -0
  265. package/src/helpers/url.test.js +18 -0
  266. package/src/helpers/url.ts +202 -0
  267. package/src/helpers/urlhelper.ts +104 -0
  268. package/src/index.ts +24 -0
  269. package/src/types/common.types.ts +16 -0
  270. package/src/types/flatted.types.ts +60 -0
  271. package/src/types/globals.types.ts +7 -0
  272. package/src/types/graph/calendar.types.ts +81 -0
  273. package/src/types/graph/index.ts +1 -0
  274. package/src/types/index.ts +12 -0
  275. package/src/types/knownscript.types.ts +19 -0
  276. package/src/types/libs/datajs.types.ts +29 -0
  277. package/src/types/libs/ics.types.ts +31 -0
  278. package/src/types/libs/index.ts +4 -0
  279. package/src/types/libs/msal.types.ts +79 -0
  280. package/src/types/locales.ts +125 -0
  281. package/src/types/localstoragecache.types.ts +9 -0
  282. package/src/types/moment.ts +7 -0
  283. package/src/types/regex.types.ts +17 -0
  284. package/src/types/rest.types.ts +94 -0
  285. package/src/types/sharepoint.types.ts +1413 -0
  286. package/src/types/sharepoint.utils.types.ts +246 -0
  287. package/src/utils/_dependencies.ts +4 -0
  288. package/src/utils/base64.ts +27 -0
  289. package/src/utils/consolelogger.ts +315 -0
  290. package/src/utils/date.ts +36 -0
  291. package/src/utils/emails.ts +25 -0
  292. package/src/utils/index.ts +13 -0
  293. package/src/utils/knownscript.ts +280 -0
  294. package/src/utils/localstoragecache.ts +419 -0
  295. package/src/utils/rest.ts +465 -0
  296. package/src/utils/script.ts +168 -0
  297. package/src/utils/sharepoint.rest/common.ts +149 -0
  298. package/src/utils/sharepoint.rest/date.ts +61 -0
  299. package/src/utils/sharepoint.rest/file.folder.ts +368 -0
  300. package/src/utils/sharepoint.rest/index.ts +11 -0
  301. package/src/utils/sharepoint.rest/item.ts +456 -0
  302. package/src/utils/sharepoint.rest/list.ts +1144 -0
  303. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
  304. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
  305. package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
  306. package/src/utils/sharepoint.rest/user-search.ts +254 -0
  307. package/src/utils/sharepoint.rest/user.ts +447 -0
  308. package/src/utils/sharepoint.rest/web.ts +1031 -0
  309. package/src/utils/sod.ts +193 -0
  310. package/tsconfig.json +21 -0
@@ -0,0 +1,629 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GetListItemsByCaml = void 0;
13
+ const _dependencies_1 = require("../../_dependencies");
14
+ const consolelogger_1 = require("../../consolelogger");
15
+ const rest_1 = require("../../rest");
16
+ const common_1 = require("../common");
17
+ const list_1 = require("../list");
18
+ const web_1 = require("../web");
19
+ const GetListItemsById_1 = require("./GetListItemsById");
20
+ const common_2 = require("./common");
21
+ const logger = consolelogger_1.ConsoleLogger.get("sharepoint.rest/list/GetListItemsByCaml");
22
+ //Lookup threshold limit is 12 but we use a smaller number here to ensure there are no issues
23
+ const lookupOrUserFieldLimit = 11;
24
+ /** returns the items or NULL, never errors out since it is used in aggregator.
25
+ * set throwErrors = true if you want errors to be thrown instead of returning null.
26
+ * camlQuery: one of:
27
+ * - view.ViewQuery
28
+ * - wrapped view.ViewQuery in a <View>: "&lt;View Scope='RecursiveAll'>&lt;Query>&lt;/Query>&lt;RowLimit>1000&lt;/RowLimit>&lt;/View>" or send rowLimit in options.
29
+ */
30
+ function GetListItemsByCaml(siteUrl, listIdOrTitle, camlQuery, options) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
33
+ if (!camlQuery.toLowerCase().startsWith("<view")) {
34
+ camlQuery = `<View Scope='RecursiveAll'><Query>${camlQuery}</Query></View>`;
35
+ }
36
+ let xmlParser = new DOMParser();
37
+ let xmlDoc = xmlParser.parseFromString(camlQuery, "text/xml");
38
+ let viewNode = xmlDoc.querySelector("View, view");
39
+ let queryNode = viewNode && viewNode.querySelector("Query, query");
40
+ let rowLimitNode = viewNode && viewNode.querySelector("RowLimit, rowlimit");
41
+ let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
42
+ let parseRowLimitNodeResult = _parseRowLimitNode(rowLimitNode, viewNode, options.rowLimit);
43
+ if (!(0, _dependencies_1.isNullOrUndefined)(parseRowLimitNodeResult)) {
44
+ options.rowLimit = parseRowLimitNodeResult.rowLimit;
45
+ camlQuery = parseRowLimitNodeResult.camlQuery;
46
+ }
47
+ let removeSingleAndConditionsResult = _removeSingleAndConditions(viewNode, queryNode);
48
+ if (!(0, _dependencies_1.isNullOrUndefined)(removeSingleAndConditionsResult)) {
49
+ camlQuery = removeSingleAndConditionsResult.camlQuery;
50
+ }
51
+ let getAllItems = (0, _dependencies_1.isNullOrEmptyString)(options.rowLimit) || options.rowLimit < 1;
52
+ let totalItemsInList = 99999;
53
+ let maxBatchSize = 5000;
54
+ let batchSize = options.rowLimit > 0 && options.rowLimit < maxBatchSize ? options.rowLimit : maxBatchSize;
55
+ let totalNumberOfItemsToGet = getAllItems ? totalItemsInList : options.rowLimit > maxBatchSize ? options.rowLimit : batchSize;
56
+ let requestUrl = `${(0, list_1.GetListRestUrl)(siteUrl, listIdOrTitle)}/GetItems?$expand=FieldValuesAsText`;
57
+ let allListFieldsHash = (0, _dependencies_1.toHash)(yield (0, list_1.GetListFields)(siteUrl, listIdOrTitle), f => f.InternalName);
58
+ let expandFields = [];
59
+ let orderByStatement = (0, _dependencies_1.GetOrderByFromCaml)(camlQuery);
60
+ if ((0, _dependencies_1.isNullOrUndefined)(options.columns)) {
61
+ options.columns = [];
62
+ }
63
+ let columns = options.columns;
64
+ columns = _ensureOrderByColumns(orderByStatement, columns);
65
+ columns = _ensureViewFields(viewFieldsNode, columns, allListFieldsHash);
66
+ columns = _normalizeColumns(columns, allListFieldsHash);
67
+ if (columns.length > options.columns.length) {
68
+ logger.warn(`added ${columns.length - options.columns.length} to query`);
69
+ }
70
+ options.columns = columns;
71
+ // Store the result of processing the request
72
+ let rtrnProcessRequestResult;
73
+ let lookupOrUserFieldsInColumns = options.columns.filter((columnName) => {
74
+ let field = allListFieldsHash[columnName];
75
+ return _isLookupOrUserField(field);
76
+ });
77
+ let isThrottled = lookupOrUserFieldsInColumns.length >= lookupOrUserFieldLimit;
78
+ try {
79
+ if (isThrottled) {
80
+ //ISSUE: 1565
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
+ });
98
+ }
99
+ if (itemsWithOutContentType.length > 0) {
100
+ logger.time("Getting content types");
101
+ //Issue 1465 content types no longer come back from get items request...
102
+ //Make a separate request to get this info
103
+ let ctypes = (yield (0, GetListItemsById_1.GetItemsById)(siteUrl, listIdOrTitle, itemsWithOutContentType, {
104
+ expand: ['ContentType/Name'],
105
+ select: ['ContentType/Name', 'Id'],
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;
111
+ }
112
+ });
113
+ logger.timeEnd("Getting content types");
114
+ }
115
+ if (postProcessOrderBy) {
116
+ //re-apply sort
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
+ }
141
+ }
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
+ }
154
+ }
155
+ return itemsResult;
156
+ }
157
+ catch (ex) {
158
+ console.log(`isThrottled: ${isThrottled}`);
159
+ }
160
+ return null;
161
+ });
162
+ }
163
+ exports.GetListItemsByCaml = GetListItemsByCaml;
164
+ // (window as any).runtTest = true;
165
+ // window.setTimeout(() => {
166
+ // if ((window as any).runtTest == false) return;
167
+ // (window as any).runtTest = false;
168
+ // GetListItemsByCaml(null, "aec7756b-daa0-4da1-88ba-c66cb572e816", "", {
169
+ // columns: [],
170
+ // refreshCache: true
171
+ // }).then((r) => {
172
+ // });
173
+ // }, 500);
174
+ //ISSUE: 1565
175
+ function _processLookupThresholdCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ let rtrnProcessRequestResult = {
178
+ items: [],
179
+ postProcessOrderBy: false,
180
+ needContentTypes: false
181
+ };
182
+ let orderByFields = orderByStatement.map((orderByField) => {
183
+ let field = allListFieldsHash[orderByField.Name];
184
+ return field;
185
+ });
186
+ let lookupOrUserFieldsInOrderBy = orderByFields.filter((orderByField) => {
187
+ return _isLookupOrUserField(orderByField);
188
+ });
189
+ let lookupOrUserFieldsToChunk = options.columns.filter((columnName) => {
190
+ let field = allListFieldsHash[columnName];
191
+ if (_isLookupOrUserField(field)) {
192
+ let col = (0, _dependencies_1.firstOrNull)(lookupOrUserFieldsInOrderBy, (orderByField) => {
193
+ return field.InternalName !== orderByField.InternalName;
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
+ }
315
+ }
316
+ rtrnProcessRequestResult.items = mergedItems;
317
+ return rtrnProcessRequestResult;
318
+ });
319
+ }
320
+ function _processNormalCamlRequest(orderByStatement, allListFieldsHash, options, camlQuery, requestUrl, expandFields, siteUrl, totalNumberOfItemsToGet, batchSize) {
321
+ return __awaiter(this, void 0, void 0, function* () {
322
+ let processColumnsResult = _processColumns(options.columns, expandFields, allListFieldsHash);
323
+ let viewFields = processColumnsResult.viewFields;
324
+ let selectFields = processColumnsResult.selectFields;
325
+ expandFields = processColumnsResult.expandFields;
326
+ let needContentTypes = processColumnsResult.needContentTypes;
327
+ if ((0, _dependencies_1.isNotEmptyArray)(viewFields)) {
328
+ camlQuery = (0, _dependencies_1.EnsureViewFields)(camlQuery, viewFields, true);
329
+ }
330
+ // Prepare the REST URL with select fields
331
+ let restUrlWithSelect = requestUrl;
332
+ if (expandFields.length > 0) {
333
+ restUrlWithSelect += ',' + expandFields.join(',');
334
+ }
335
+ // Include the lookup user select fields with the other select fields
336
+ restUrlWithSelect += '&$select=' + selectFields.join(',');
337
+ // Process the request and get the result
338
+ let result = yield processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement);
339
+ return Object.assign(Object.assign({}, result), { needContentTypes });
340
+ });
341
+ }
342
+ function _ensureViewFields(viewFieldsNode, columns, allListFieldsHash) {
343
+ //ISSUE: 1565
344
+ //Cases
345
+ //1. Empty view fields element so ALL columns will be requested. We must include all list fields in
346
+ //columns parsing so that we get an accurate count of how many lookup/user fields there are
347
+ //2. View fields element with a some field names that must also be included in the column parsing so we add them here.
348
+ if ((0, _dependencies_1.isNullOrUndefined)(viewFieldsNode) && (0, _dependencies_1.isNullOrEmptyArray)(columns)) {
349
+ Object.keys(allListFieldsHash).forEach((fieldName) => {
350
+ let field = allListFieldsHash[fieldName];
351
+ if (!(0, _dependencies_1.isNullOrUndefined)(field)
352
+ && !field.Hidden
353
+ && !common_2.SkipFields.includes(fieldName.toLowerCase())) {
354
+ columns.push(field.InternalName);
355
+ }
356
+ });
357
+ }
358
+ else if (!(0, _dependencies_1.isNullOrUndefined)(viewFieldsNode)) {
359
+ let fieldRefNodes = Array.from(viewFieldsNode.querySelectorAll("FieldRef"));
360
+ if ((0, _dependencies_1.isNotEmptyArray)(fieldRefNodes)) {
361
+ fieldRefNodes.forEach((fieldRefNode) => {
362
+ let name = fieldRefNode.getAttribute("Name") || fieldRefNode.getAttribute("name");
363
+ if (!(0, _dependencies_1.isNullOrEmptyString)(name)) {
364
+ columns.push(name);
365
+ }
366
+ });
367
+ }
368
+ }
369
+ return columns;
370
+ }
371
+ function _ensureOrderByColumns(orderByStatement, columns) {
372
+ //Issue 548: Ensure that the order by field is in the view fields and columns collection so
373
+ //that paging works correctly when there is an order by clause
374
+ if (orderByStatement.length > 0 && !(0, _dependencies_1.isNullOrEmptyString)(orderByStatement[0].Name)) {
375
+ // just add them to columns, and we will add them to view fields below.
376
+ // camlQuery = EnsureViewFields(camlQuery, orderByStatement.orderBy.map(o => o.Name), false);
377
+ orderByStatement.forEach(o => {
378
+ if (columns.indexOf(o.Name) === -1) {
379
+ columns.push(o.Name);
380
+ }
381
+ });
382
+ }
383
+ return columns;
384
+ }
385
+ function _normalizeColumns(columns, allListFieldsHash) {
386
+ return (0, _dependencies_1.makeUniqueArray)(columns.map((column) => {
387
+ //some columns will come in lower case (from dvp), normalize them so that we can remove duplicates
388
+ let name = Object.keys(allListFieldsHash).filter((fieldName) => {
389
+ return fieldName.toLowerCase() === column.toLowerCase();
390
+ })[0];
391
+ if (!(0, _dependencies_1.isNullOrEmptyString)(name)) {
392
+ let field = allListFieldsHash[name];
393
+ return field;
394
+ }
395
+ return null;
396
+ }).filter((field) => {
397
+ return !(0, _dependencies_1.isNullOrUndefined)(field);
398
+ }).map((field) => {
399
+ return field.InternalName;
400
+ }).concat(['Title', 'Id', 'FileLeafRef', 'FileDirRef', 'FileRef', 'FileSystemObjectType']));
401
+ }
402
+ function _removeSingleAndConditions(viewNode, queryNode) {
403
+ if (!(0, _dependencies_1.isNullOrUndefined)(viewNode.querySelector("And, and"))) {
404
+ try {
405
+ //Issue 8063: calendar list, will wrongly add a wrapping <and> statement for a single condition
406
+ //will result in error 500
407
+ //ie: <View Scope='RecursiveAll'><Query><Where><And><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">Holiday</Value></Eq></And></Where>
408
+ //</Query><RowLimit>5000</RowLimit></View>
409
+ let whereNode = queryNode && queryNode.querySelector("Where, where");
410
+ if (!(0, _dependencies_1.isNullOrUndefined)(whereNode)) {
411
+ let firstCondition = whereNode.firstElementChild;
412
+ if (firstCondition.tagName.toLowerCase() === "and" && firstCondition.children.length < 2) {
413
+ //this is the bug, <and> tag must have 2 conditions - get rid of it!
414
+ whereNode.innerHTML = firstCondition.innerHTML;
415
+ return {
416
+ camlQuery: viewNode.outerHTML
417
+ };
418
+ }
419
+ }
420
+ }
421
+ catch (e) { }
422
+ }
423
+ return null;
424
+ }
425
+ function _parseRowLimitNode(rowLimitNode, viewNode, rowLimit) {
426
+ if (!(0, _dependencies_1.isNullOrUndefined)(rowLimitNode)) {
427
+ let value = rowLimitNode.textContent;
428
+ //if not provided by options - use it
429
+ if ((0, _dependencies_1.isNullOrNaN)(rowLimit) && (0, _dependencies_1.isNumeric)(value) && Number(value) > 0) {
430
+ rowLimit = Number(value);
431
+ }
432
+ //remove it
433
+ viewNode.removeChild(rowLimitNode);
434
+ return {
435
+ camlQuery: viewNode.outerHTML,
436
+ rowLimit: rowLimit
437
+ };
438
+ }
439
+ return null;
440
+ }
441
+ function _processColumns(columns, expandFields, allListFieldsHash) {
442
+ let thresholdLimitLookupCount = 0;
443
+ let thresholdLimitLookupHit = false;
444
+ let selectFields = [];
445
+ let viewFields = [];
446
+ let needContentTypes = false;
447
+ //column parsing
448
+ columns.forEach(viewField => {
449
+ if (viewField.toLowerCase() === 'contenttype' || viewField.toLowerCase() === 'contenttypeid') {
450
+ needContentTypes = true;
451
+ }
452
+ else if (viewField.toLowerCase() === '_moderationstatus') {
453
+ selectFields.push(`FieldValuesAsText/${viewField}`);
454
+ viewFields.push('_moderationstatus');
455
+ }
456
+ else if (viewField.toLowerCase() === '_moderationcomments') {
457
+ selectFields.push('OData_' + viewField);
458
+ viewFields.push('_moderationcomments');
459
+ }
460
+ else if (viewField.toLowerCase() === "filesystemobjecttype") {
461
+ selectFields.push("FileSystemObjectType");
462
+ }
463
+ else if (viewField.toLowerCase() === "fileref" || viewField.toLowerCase() === "filedirref") {
464
+ //treat them similar to lookup fields
465
+ selectFields.push(viewField);
466
+ selectFields.push(`FieldValuesAsText/${viewField}`);
467
+ viewFields.push(`${viewField}`);
468
+ viewFields.push(`${viewField}Id`);
469
+ }
470
+ else {
471
+ //prefer to get columns not from FieldValuesAsText, unless special data type requires it (date, lookup, boolean, etc...)
472
+ //make the select url shorter
473
+ let foundField = allListFieldsHash[viewField];
474
+ if (foundField) {
475
+ let foundFieldInternalName = foundField.InternalName;
476
+ viewFields.push(foundFieldInternalName);
477
+ //Issue 828, 336
478
+ if (foundFieldInternalName.startsWith("_")) {
479
+ foundFieldInternalName = `OData_${foundFieldInternalName}`;
480
+ }
481
+ let outputType = (0, _dependencies_1.getFieldOutputType)(foundField);
482
+ switch (outputType) {
483
+ case "Lookup":
484
+ case "LookupMulti":
485
+ case "User":
486
+ case "UserMulti":
487
+ thresholdLimitLookupCount += 1;
488
+ if (thresholdLimitLookupCount >= lookupOrUserFieldLimit) {
489
+ thresholdLimitLookupHit = true;
490
+ }
491
+ //lookup raw values comes with Id appended
492
+ selectFields.push(`FieldValuesAsText/${foundFieldInternalName}`);
493
+ selectFields.push(`${foundFieldInternalName}Id`);
494
+ break;
495
+ case "Boolean":
496
+ case "Attachments":
497
+ case "AllDayEvent":
498
+ case "Recurrence":
499
+ selectFields.push(`FieldValuesAsText/${foundFieldInternalName}`);
500
+ selectFields.push(foundFieldInternalName);
501
+ break;
502
+ default:
503
+ selectFields.push(foundFieldInternalName);
504
+ break;
505
+ }
506
+ }
507
+ else {
508
+ selectFields.push(viewField);
509
+ }
510
+ }
511
+ });
512
+ if (needContentTypes) {
513
+ expandFields.push("ContentType");
514
+ selectFields.push("ContentType/Name");
515
+ selectFields.push("ContentTypeId");
516
+ viewFields.push("ContentTypeId");
517
+ }
518
+ return {
519
+ thresholdLimitLookupHit,
520
+ viewFields: (0, _dependencies_1.makeUniqueArray)(viewFields),
521
+ selectFields: (0, _dependencies_1.makeUniqueArray)(selectFields),
522
+ expandFields: (0, _dependencies_1.makeUniqueArray)(expandFields),
523
+ needContentTypes
524
+ };
525
+ }
526
+ function _isLookupOrUserField(field) {
527
+ if ((0, _dependencies_1.isNullOrUndefined)(field)) {
528
+ return false;
529
+ }
530
+ let outputType = (0, _dependencies_1.getFieldOutputType)(field);
531
+ switch (outputType) {
532
+ case "Lookup":
533
+ case "LookupMulti":
534
+ case "User":
535
+ case "UserMulti":
536
+ return true;
537
+ default:
538
+ return false;
539
+ }
540
+ }
541
+ function processRequestResult(requestUrl, restUrlWithSelect, camlQuery, options, siteUrl, totalNumberOfItemsToGet, batchSize, orderByStatement) {
542
+ return __awaiter(this, void 0, void 0, function* () {
543
+ //issue 6150: if there are too many fields, url will be too long. just get all columns without adding a $select
544
+ if (restUrlWithSelect.length < 2000)
545
+ requestUrl = restUrlWithSelect;
546
+ let query = { ViewXml: camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`) };
547
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.FolderServerRelativeUrl))
548
+ query.FolderServerRelativeUrl = options.FolderServerRelativeUrl;
549
+ let data = { query: query };
550
+ let items = [];
551
+ //let triedWithoutViewFields = false;
552
+ let postProcessOrderBy = false;
553
+ do {
554
+ try {
555
+ let requestResult = yield (0, rest_1.GetJson)(requestUrl, JSON.stringify(data), {
556
+ allowCache: options.refreshCache !== true,
557
+ postCacheKey: JSON.stringify(data.query),
558
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata,
559
+ spWebUrl: siteUrl
560
+ });
561
+ if (requestResult && requestResult.value)
562
+ items.push(...requestResult.value);
563
+ let itemsLeftToGet = totalNumberOfItemsToGet - items.length;
564
+ if (itemsLeftToGet > 0 && //we need more items
565
+ requestResult.value.length === batchSize //we might have more on server since we got the full batch size we asked for
566
+ ) {
567
+ let lastItem = items[items.length - 1];
568
+ let lastItemId = lastItem.Id;
569
+ let pagingInfoSort = "";
570
+ //Issue 7542 need to add order by value to the paging info if it is in the query
571
+ if (!postProcessOrderBy && orderByStatement && orderByStatement.length) {
572
+ let orderFieldName = orderByStatement[0].Name;
573
+ let orderFieldValue = lastItem[orderFieldName];
574
+ //if field is ID - do not do it.
575
+ if (orderFieldName.toLowerCase() !== "id" && !(0, _dependencies_1.isNullOrUndefined)(orderFieldValue)) {
576
+ //if value is date - we need it in ISO and in this format: yyyyMMdd HH:mm:ss
577
+ try {
578
+ //Numbers cast to date properly but they are not dates. ignore number values.
579
+ let orderFieldValueAsDate = (0, _dependencies_1.isNumeric)(orderFieldValue) ? null : new Date(orderFieldValue);
580
+ if ((0, _dependencies_1.isDate)(orderFieldValueAsDate)) {
581
+ try {
582
+ //issue 7599 date only field on different time zone...
583
+ orderFieldValue = (0, web_1.SPServerLocalTimeToUTCSync)(siteUrl, orderFieldValueAsDate).replace(/T/i, " ").replace(/Z/i, " ");
584
+ }
585
+ catch (e) { }
586
+ }
587
+ }
588
+ catch (e) { }
589
+ pagingInfoSort = `&p_${orderFieldName}=${(0, _dependencies_1.encodeURIComponentEX)(orderFieldValue)}`;
590
+ }
591
+ }
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
+ }
598
+ else
599
+ data = null;
600
+ }
601
+ catch (e) {
602
+ if ((0, common_1.__getSPRestErrorData)(e).code.indexOf('SPQueryThrottledException')) {
603
+ //test again - on awaiting score view, this will work but will ONLY return the order by fields...
604
+ // if (!triedWithoutViewFields) {
605
+ // //Our own issues list had too many lookup fields.
606
+ // logger.info("Query throttled, trying again without view fields... some fields might be missing from results.");
607
+ // triedWithoutViewFields = true;
608
+ // camlQuery = EnsureViewFields(camlQuery, orderByStatement.map(o => o.Name), false, true);
609
+ // data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`);
610
+ // }
611
+ // else
612
+ if (!postProcessOrderBy && orderByStatement.length > 0) {
613
+ logger.warn("Query throttled, trying again without order by...");
614
+ postProcessOrderBy = true;
615
+ camlQuery = (0, _dependencies_1.RemoveOrderByFromCaml)(camlQuery);
616
+ camlQuery = (0, _dependencies_1.EnsureViewFields)(camlQuery, [], false, true);
617
+ data.query.ViewXml = camlQuery.replace("</View>", `<RowLimit>${batchSize}</RowLimit></View>`);
618
+ }
619
+ else
620
+ throw e; //still throttled? might be due to filter query
621
+ }
622
+ else
623
+ throw e; //different error
624
+ }
625
+ } while (!(0, _dependencies_1.isNullOrEmptyString)(data));
626
+ return { items: items, postProcessOrderBy: postProcessOrderBy };
627
+ });
628
+ }
629
+ //# sourceMappingURL=GetListItemsByCaml.js.map