@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.
- package/LICENSE +21 -0
- package/dist/_dependencies.d.ts +1 -0
- package/dist/_dependencies.js +8 -0
- package/dist/_dependencies.js.map +1 -0
- package/dist/helpers/Guid.d.ts +119 -0
- package/dist/helpers/Guid.js +183 -0
- package/dist/helpers/Guid.js.map +1 -0
- package/dist/helpers/_dependencies.d.ts +2 -0
- package/dist/helpers/_dependencies.js +21 -0
- package/dist/helpers/_dependencies.js.map +1 -0
- package/dist/helpers/base64.d.ts +8 -0
- package/dist/helpers/base64.js +178 -0
- package/dist/helpers/base64.js.map +1 -0
- package/dist/helpers/browser.d.ts +144 -0
- package/dist/helpers/browser.js +1200 -0
- package/dist/helpers/browser.js.map +1 -0
- package/dist/helpers/browserinfo.d.ts +23 -0
- package/dist/helpers/browserinfo.js +215 -0
- package/dist/helpers/browserinfo.js.map +1 -0
- package/dist/helpers/collections.base.d.ts +128 -0
- package/dist/helpers/collections.base.js +430 -0
- package/dist/helpers/collections.base.js.map +1 -0
- package/dist/helpers/collections.d.ts +18 -0
- package/dist/helpers/collections.js +99 -0
- package/dist/helpers/collections.js.map +1 -0
- package/dist/helpers/color.d.ts +11 -0
- package/dist/helpers/color.js +57 -0
- package/dist/helpers/color.js.map +1 -0
- package/dist/helpers/cookies.d.ts +6 -0
- package/dist/helpers/cookies.js +56 -0
- package/dist/helpers/cookies.js.map +1 -0
- package/dist/helpers/date.d.ts +43 -0
- package/dist/helpers/date.js +158 -0
- package/dist/helpers/date.js.map +1 -0
- package/dist/helpers/debug.d.ts +33 -0
- package/dist/helpers/debug.js +177 -0
- package/dist/helpers/debug.js.map +1 -0
- package/dist/helpers/emails.d.ts +2 -0
- package/dist/helpers/emails.js +10 -0
- package/dist/helpers/emails.js.map +1 -0
- package/dist/helpers/eval.d.ts +1 -0
- package/dist/helpers/eval.js +10 -0
- package/dist/helpers/eval.js.map +1 -0
- package/dist/helpers/file.d.ts +11 -0
- package/dist/helpers/file.js +55 -0
- package/dist/helpers/file.js.map +1 -0
- package/dist/helpers/flatted.d.ts +20 -0
- package/dist/helpers/flatted.js +135 -0
- package/dist/helpers/flatted.js.map +1 -0
- package/dist/helpers/functions.d.ts +4 -0
- package/dist/helpers/functions.js +17 -0
- package/dist/helpers/functions.js.map +1 -0
- package/dist/helpers/graph/calendar.types.d.ts +3 -0
- package/dist/helpers/graph/calendar.types.js +15 -0
- package/dist/helpers/graph/calendar.types.js.map +1 -0
- package/dist/helpers/http.d.ts +25 -0
- package/dist/helpers/http.js +70 -0
- package/dist/helpers/http.js.map +1 -0
- package/dist/helpers/images.d.ts +16 -0
- package/dist/helpers/images.js +21 -0
- package/dist/helpers/images.js.map +1 -0
- package/dist/helpers/index.d.ts +29 -0
- package/dist/helpers/index.js +46 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/json.d.ts +3 -0
- package/dist/helpers/json.js +44 -0
- package/dist/helpers/json.js.map +1 -0
- package/dist/helpers/md5.d.ts +5 -0
- package/dist/helpers/md5.js +172 -0
- package/dist/helpers/md5.js.map +1 -0
- package/dist/helpers/objects.d.ts +49 -0
- package/dist/helpers/objects.js +271 -0
- package/dist/helpers/objects.js.map +1 -0
- package/dist/helpers/promises.d.ts +14 -0
- package/dist/helpers/promises.js +112 -0
- package/dist/helpers/promises.js.map +1 -0
- package/dist/helpers/random.d.ts +2 -0
- package/dist/helpers/random.js +32 -0
- package/dist/helpers/random.js.map +1 -0
- package/dist/helpers/scheduler/scheduler.d.ts +39 -0
- package/dist/helpers/scheduler/scheduler.js +109 -0
- package/dist/helpers/scheduler/scheduler.js.map +1 -0
- package/dist/helpers/sharepoint.d.ts +112 -0
- package/dist/helpers/sharepoint.js +629 -0
- package/dist/helpers/sharepoint.js.map +1 -0
- package/dist/helpers/strings.d.ts +56 -0
- package/dist/helpers/strings.js +282 -0
- package/dist/helpers/strings.js.map +1 -0
- package/dist/helpers/typecheckers.d.ts +56 -0
- package/dist/helpers/typecheckers.js +274 -0
- package/dist/helpers/typecheckers.js.map +1 -0
- package/dist/helpers/url.d.ts +46 -0
- package/dist/helpers/url.js +199 -0
- package/dist/helpers/url.js.map +1 -0
- package/dist/helpers/urlhelper.d.ts +16 -0
- package/dist/helpers/urlhelper.js +96 -0
- package/dist/helpers/urlhelper.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/types/common.types.d.ts +19 -0
- package/dist/types/common.types.js +4 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/flatted.types.d.ts +49 -0
- package/dist/types/flatted.types.js +3 -0
- package/dist/types/flatted.types.js.map +1 -0
- package/dist/types/globals.types.d.ts +6 -0
- package/dist/types/globals.types.js +3 -0
- package/dist/types/globals.types.js.map +1 -0
- package/dist/types/graph/calendar.types.d.ts +79 -0
- package/dist/types/graph/calendar.types.js +3 -0
- package/dist/types/graph/calendar.types.js.map +1 -0
- package/dist/types/graph/index.d.ts +1 -0
- package/dist/types/graph/index.js +18 -0
- package/dist/types/graph/index.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +28 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/knownscript.types.d.ts +22 -0
- package/dist/types/knownscript.types.js +3 -0
- package/dist/types/knownscript.types.js.map +1 -0
- package/dist/types/libs/datajs.types.d.ts +29 -0
- package/dist/types/libs/datajs.types.js +3 -0
- package/dist/types/libs/datajs.types.js.map +1 -0
- package/dist/types/libs/ics.types.d.ts +29 -0
- package/dist/types/libs/ics.types.js +3 -0
- package/dist/types/libs/ics.types.js.map +1 -0
- package/dist/types/libs/index.d.ts +3 -0
- package/dist/types/libs/index.js +20 -0
- package/dist/types/libs/index.js.map +1 -0
- package/dist/types/libs/msal.types.d.ts +33 -0
- package/dist/types/libs/msal.types.js +63 -0
- package/dist/types/libs/msal.types.js.map +1 -0
- package/dist/types/locales.d.ts +122 -0
- package/dist/types/locales.js +1 -0
- package/dist/types/locales.js.map +1 -0
- package/dist/types/localstoragecache.types.d.ts +8 -0
- package/dist/types/localstoragecache.types.js +3 -0
- package/dist/types/localstoragecache.types.js.map +1 -0
- package/dist/types/moment.d.ts +6 -0
- package/dist/types/moment.js +1 -0
- package/dist/types/moment.js.map +1 -0
- package/dist/types/regex.types.d.ts +14 -0
- package/dist/types/regex.types.js +3 -0
- package/dist/types/regex.types.js.map +1 -0
- package/dist/types/rest.types.d.ts +81 -0
- package/dist/types/rest.types.js +24 -0
- package/dist/types/rest.types.js.map +1 -0
- package/dist/types/sharepoint.types.d.ts +1432 -0
- package/dist/types/sharepoint.types.js +629 -0
- package/dist/types/sharepoint.types.js.map +1 -0
- package/dist/types/sharepoint.utils.types.d.ts +246 -0
- package/dist/types/sharepoint.utils.types.js +26 -0
- package/dist/types/sharepoint.utils.types.js.map +1 -0
- package/dist/utils/_dependencies.d.ts +3 -0
- package/dist/utils/_dependencies.js +24 -0
- package/dist/utils/_dependencies.js.map +1 -0
- package/dist/utils/base64.d.ts +2 -0
- package/dist/utils/base64.js +41 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/consolelogger.d.ts +73 -0
- package/dist/utils/consolelogger.js +281 -0
- package/dist/utils/consolelogger.js.map +1 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.js +30 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/emails.d.ts +2 -0
- package/dist/utils/emails.js +24 -0
- package/dist/utils/emails.js.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/knownscript.d.ts +99 -0
- package/dist/utils/knownscript.js +261 -0
- package/dist/utils/knownscript.js.map +1 -0
- package/dist/utils/localstoragecache.d.ts +19 -0
- package/dist/utils/localstoragecache.js +372 -0
- package/dist/utils/localstoragecache.js.map +1 -0
- package/dist/utils/rest.d.ts +17 -0
- package/dist/utils/rest.js +402 -0
- package/dist/utils/rest.js.map +1 -0
- package/dist/utils/script.d.ts +33 -0
- package/dist/utils/script.js +169 -0
- package/dist/utils/script.js.map +1 -0
- package/dist/utils/sharepoint.rest/common.d.ts +32 -0
- package/dist/utils/sharepoint.rest/common.js +146 -0
- package/dist/utils/sharepoint.rest/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/date.d.ts +2 -0
- package/dist/utils/sharepoint.rest/date.js +57 -0
- package/dist/utils/sharepoint.rest/date.js.map +1 -0
- package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
- package/dist/utils/sharepoint.rest/file.folder.js +305 -0
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
- package/dist/utils/sharepoint.rest/index.d.ts +11 -0
- package/dist/utils/sharepoint.rest/index.js +28 -0
- package/dist/utils/sharepoint.rest/index.js.map +1 -0
- package/dist/utils/sharepoint.rest/item.d.ts +81 -0
- package/dist/utils/sharepoint.rest/item.js +444 -0
- package/dist/utils/sharepoint.rest/item.js.map +1 -0
- package/dist/utils/sharepoint.rest/list.d.ts +228 -0
- package/dist/utils/sharepoint.rest/list.js +868 -0
- package/dist/utils/sharepoint.rest/list.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
- package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
- package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
- package/dist/utils/sharepoint.rest/user-search.js +239 -0
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
- package/dist/utils/sharepoint.rest/user.d.ts +71 -0
- package/dist/utils/sharepoint.rest/user.js +404 -0
- package/dist/utils/sharepoint.rest/user.js.map +1 -0
- package/dist/utils/sharepoint.rest/web.d.ts +107 -0
- package/dist/utils/sharepoint.rest/web.js +929 -0
- package/dist/utils/sharepoint.rest/web.js.map +1 -0
- package/dist/utils/sod.d.ts +29 -0
- package/dist/utils/sod.js +177 -0
- package/dist/utils/sod.js.map +1 -0
- package/package.json +60 -0
- package/readme.md +13 -0
- package/src/_dependencies.ts +2 -0
- package/src/helpers/Guid.ts +182 -0
- package/src/helpers/_dependencies.ts +3 -0
- package/src/helpers/base64.ts +174 -0
- package/src/helpers/browser.test.js +9 -0
- package/src/helpers/browser.ts +1299 -0
- package/src/helpers/browserinfo.ts +293 -0
- package/src/helpers/collections.base.test.js +26 -0
- package/src/helpers/collections.base.ts +439 -0
- package/src/helpers/collections.ts +108 -0
- package/src/helpers/color.ts +55 -0
- package/src/helpers/cookies.ts +55 -0
- package/src/helpers/date.test.js +97 -0
- package/src/helpers/date.ts +163 -0
- package/src/helpers/debug.ts +187 -0
- package/src/helpers/emails.ts +7 -0
- package/src/helpers/eval.ts +5 -0
- package/src/helpers/file.test.js +51 -0
- package/src/helpers/file.ts +59 -0
- package/src/helpers/flatted.ts +150 -0
- package/src/helpers/functions.ts +17 -0
- package/src/helpers/graph/calendar.types.ts +11 -0
- package/src/helpers/http.ts +70 -0
- package/src/helpers/images.ts +23 -0
- package/src/helpers/index.ts +29 -0
- package/src/helpers/json.ts +39 -0
- package/src/helpers/md5.ts +190 -0
- package/src/helpers/objects.test.js +27 -0
- package/src/helpers/objects.ts +256 -0
- package/src/helpers/promises.test.js +18 -0
- package/src/helpers/promises.ts +102 -0
- package/src/helpers/random.ts +27 -0
- package/src/helpers/scheduler/scheduler.test.js +104 -0
- package/src/helpers/scheduler/scheduler.ts +132 -0
- package/src/helpers/sharepoint.ts +681 -0
- package/src/helpers/strings.test.js +43 -0
- package/src/helpers/strings.ts +288 -0
- package/src/helpers/typecheckers.test.js +35 -0
- package/src/helpers/typecheckers.ts +263 -0
- package/src/helpers/url.test.js +18 -0
- package/src/helpers/url.ts +202 -0
- package/src/helpers/urlhelper.ts +104 -0
- package/src/index.ts +24 -0
- package/src/types/common.types.ts +16 -0
- package/src/types/flatted.types.ts +60 -0
- package/src/types/globals.types.ts +7 -0
- package/src/types/graph/calendar.types.ts +81 -0
- package/src/types/graph/index.ts +1 -0
- package/src/types/index.ts +12 -0
- package/src/types/knownscript.types.ts +19 -0
- package/src/types/libs/datajs.types.ts +29 -0
- package/src/types/libs/ics.types.ts +31 -0
- package/src/types/libs/index.ts +4 -0
- package/src/types/libs/msal.types.ts +79 -0
- package/src/types/locales.ts +125 -0
- package/src/types/localstoragecache.types.ts +9 -0
- package/src/types/moment.ts +7 -0
- package/src/types/regex.types.ts +17 -0
- package/src/types/rest.types.ts +94 -0
- package/src/types/sharepoint.types.ts +1413 -0
- package/src/types/sharepoint.utils.types.ts +246 -0
- package/src/utils/_dependencies.ts +4 -0
- package/src/utils/base64.ts +27 -0
- package/src/utils/consolelogger.ts +315 -0
- package/src/utils/date.ts +36 -0
- package/src/utils/emails.ts +25 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/knownscript.ts +280 -0
- package/src/utils/localstoragecache.ts +419 -0
- package/src/utils/rest.ts +465 -0
- package/src/utils/script.ts +168 -0
- package/src/utils/sharepoint.rest/common.ts +149 -0
- package/src/utils/sharepoint.rest/date.ts +61 -0
- package/src/utils/sharepoint.rest/file.folder.ts +368 -0
- package/src/utils/sharepoint.rest/index.ts +11 -0
- package/src/utils/sharepoint.rest/item.ts +456 -0
- package/src/utils/sharepoint.rest/list.ts +1144 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
- package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
- package/src/utils/sharepoint.rest/user-search.ts +254 -0
- package/src/utils/sharepoint.rest/user.ts +447 -0
- package/src/utils/sharepoint.rest/web.ts +1031 -0
- package/src/utils/sod.ts +193 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { IRestItem, chunkArray, getGlobal, isBoolean, isNotEmptyArray, isNullOrEmptyArray, isNullOrUndefined, isNumber, jsonClone, jsonTypes } from "../../_dependencies";
|
|
2
|
+
import { GetJson, GetJsonSync } from "../../rest";
|
|
3
|
+
import { GetListRestUrl } from "../list";
|
|
4
|
+
|
|
5
|
+
let g_cache = getGlobal<{ getItemsByIdCache: { [cachekey: string]: IRestItem[]; }; }>("SharePoint_Rest_List_Cache", {
|
|
6
|
+
getItemsByIdCache: {}
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/** return array will use the item ID as indexer, not a real array */
|
|
10
|
+
export async function GetItemsById<T extends IRestItem>(siteUrl: string, listIdOrTitle: string, itemIds: number[], options?: {
|
|
11
|
+
expand?: string[];
|
|
12
|
+
select?: string[];
|
|
13
|
+
refreshCache?: boolean;
|
|
14
|
+
jsonMetadata?: jsonTypes;
|
|
15
|
+
}) {
|
|
16
|
+
try {
|
|
17
|
+
let baseParams = _parseItemsByIdParams<T>(siteUrl, listIdOrTitle, itemIds, { ...options, batchRequests: itemIds.length > 1 });
|
|
18
|
+
|
|
19
|
+
const { results, allowCache, queue } = baseParams;
|
|
20
|
+
let cacheKey = baseParams.cacheKey;
|
|
21
|
+
|
|
22
|
+
if (options && !isNullOrUndefined(options.jsonMetadata)) {
|
|
23
|
+
cacheKey += "|jsonMetadata=" + options.jsonMetadata
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (queue.length > 0) {
|
|
27
|
+
let promises = queue.map(batchRequestUrl => {
|
|
28
|
+
return GetJson<tGetItemsByIdResult<T>>(batchRequestUrl, null, {
|
|
29
|
+
//do not allow cache. modern forms have apply option which will need this to reload the item
|
|
30
|
+
//it is cached in _restListItems anyways so this is not needed.
|
|
31
|
+
allowCache: allowCache === true,
|
|
32
|
+
includeDigestInGet: true,
|
|
33
|
+
jsonMetadata: options && options.jsonMetadata
|
|
34
|
+
}).then(obj => {
|
|
35
|
+
if (!isNullOrUndefined(obj)) {
|
|
36
|
+
//no-metadata will return a value, as a single result or array
|
|
37
|
+
//otherwise, it'll go into "d"
|
|
38
|
+
let items: T[] = [];
|
|
39
|
+
|
|
40
|
+
if (isNoMetaDataResult(obj)) {
|
|
41
|
+
items = isNotEmptyArray(obj.value)
|
|
42
|
+
? obj.value
|
|
43
|
+
: [obj.value];
|
|
44
|
+
}
|
|
45
|
+
else if (isVerboseResult(obj)) {
|
|
46
|
+
items = Array.isArray(obj.d.results)
|
|
47
|
+
? obj.d.results
|
|
48
|
+
: [obj.d];
|
|
49
|
+
}
|
|
50
|
+
else if (isSingleResult(obj)) {
|
|
51
|
+
// Issue 1471: If only single item returns it not an array and just object
|
|
52
|
+
items.push(obj);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
items.forEach((restItem) => {
|
|
56
|
+
results[Number(restItem.Id)] = restItem;
|
|
57
|
+
_addCacheItem(cacheKey, restItem);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await Promise.all(promises);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return results;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw new Error("Could not retrieve rest item from list");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function GetItemsByIdSync<T extends IRestItem>(siteUrl: string, listIdOrTitle: string, itemIds: number[], options?: {
|
|
73
|
+
expand?: string[];
|
|
74
|
+
select?: string[];
|
|
75
|
+
refreshCache?: boolean;
|
|
76
|
+
jsonMetadata?: jsonTypes;
|
|
77
|
+
}) {
|
|
78
|
+
try {
|
|
79
|
+
let baseParams = _parseItemsByIdParams<T>(siteUrl, listIdOrTitle, itemIds, { ...options, batchRequests: itemIds.length > 1 });
|
|
80
|
+
|
|
81
|
+
const { results, allowCache, queue } = baseParams;
|
|
82
|
+
let cacheKey = baseParams.cacheKey;
|
|
83
|
+
|
|
84
|
+
if (options && !isNullOrUndefined(options.jsonMetadata)) {
|
|
85
|
+
cacheKey += "|jsonMetadata=" + options.jsonMetadata
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (queue.length > 0) {
|
|
89
|
+
queue.forEach((batchRequestUrl) => {
|
|
90
|
+
let response = GetJsonSync<tGetItemsByIdResult<T>>(batchRequestUrl, null, {
|
|
91
|
+
//do not allow cache. modern forms have apply option which will need this to reload the item
|
|
92
|
+
//it is cached in _restListItems anyways so this is not needed.
|
|
93
|
+
allowCache: allowCache === true,
|
|
94
|
+
includeDigestInGet: true,
|
|
95
|
+
jsonMetadata: options && options.jsonMetadata
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (response && response.success && response.result) {
|
|
99
|
+
//no-metadata will return a value, as a single result or array
|
|
100
|
+
//otherwise, it'll go into "d"
|
|
101
|
+
let items: T[] = [];
|
|
102
|
+
if (isNoMetaDataResult(response.result)) {
|
|
103
|
+
items = isNotEmptyArray(response.result.value)
|
|
104
|
+
? response.result.value
|
|
105
|
+
: [response.result.value];
|
|
106
|
+
}
|
|
107
|
+
else if (isVerboseResult(response.result)) {
|
|
108
|
+
items = Array.isArray(response.result.d.results)
|
|
109
|
+
? response.result.d.results
|
|
110
|
+
: [response.result.d];
|
|
111
|
+
}
|
|
112
|
+
else if (isSingleResult(response.result)) {
|
|
113
|
+
// Issue 1471: If only single item returns it not an array and just object
|
|
114
|
+
items.push(response.result);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
items.forEach((restItem) => {
|
|
118
|
+
results[Number(restItem.Id)] = restItem;
|
|
119
|
+
_addCacheItem(cacheKey, restItem);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return results;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
throw new Error("Could not retrieve rest item from list");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function _addCacheItem<T extends IRestItem>(cacheKey: string, item: T) {
|
|
132
|
+
if (isNullOrUndefined(g_cache.getItemsByIdCache[cacheKey])) {
|
|
133
|
+
g_cache.getItemsByIdCache[cacheKey] = [];
|
|
134
|
+
}
|
|
135
|
+
g_cache.getItemsByIdCache[cacheKey][item.Id] = jsonClone(item);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function _getCacheItem<T extends IRestItem>(cacheKey: string, itemId: number) {
|
|
139
|
+
if (isNullOrUndefined(g_cache.getItemsByIdCache[cacheKey])) {
|
|
140
|
+
g_cache.getItemsByIdCache[cacheKey] = [];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!isNullOrUndefined(g_cache.getItemsByIdCache[cacheKey][Number(itemId)])) {
|
|
144
|
+
return jsonClone(g_cache.getItemsByIdCache[cacheKey][Number(itemId)]) as T;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function _refreshCache(cacheKey: string) {
|
|
151
|
+
g_cache.getItemsByIdCache[cacheKey] = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function _getItemsByIdBaseUrl(siteUrl: string, listIdOrTitle: string) {
|
|
155
|
+
return `${GetListRestUrl(siteUrl, listIdOrTitle)}/items`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function _parseItemsByIdParams<T extends IRestItem>(siteUrl: string, listIdOrTitle: string, itemIds: number[], options?: {
|
|
159
|
+
expand?: string[];
|
|
160
|
+
select?: string[];
|
|
161
|
+
refreshCache?: boolean;
|
|
162
|
+
batchRequests?: boolean;
|
|
163
|
+
}) {
|
|
164
|
+
let baseUrl = _getItemsByIdBaseUrl(siteUrl, listIdOrTitle);
|
|
165
|
+
|
|
166
|
+
let expand: string[] = [];
|
|
167
|
+
let select: string[] = [];
|
|
168
|
+
let allowCache = true;
|
|
169
|
+
let results: T[] = [];
|
|
170
|
+
let queue: string[] = [];
|
|
171
|
+
|
|
172
|
+
if (!isNullOrUndefined(options)) {
|
|
173
|
+
if (!isNullOrEmptyArray(options.select)) {
|
|
174
|
+
select = options.select.sort();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!isNullOrEmptyArray(options.expand)) {
|
|
178
|
+
expand = options.expand.sort();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (isBoolean(options.refreshCache)) {
|
|
182
|
+
allowCache = options.refreshCache !== true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let cacheKey = [baseUrl, select.join(",").toLowerCase(), expand.join(",").toLowerCase()].join("|");
|
|
187
|
+
|
|
188
|
+
if (allowCache === true) {
|
|
189
|
+
itemIds.forEach((itemId) => {
|
|
190
|
+
let cachedItem = _getCacheItem<T>(cacheKey, itemId);
|
|
191
|
+
if (!isNullOrUndefined(cachedItem)) {
|
|
192
|
+
results[itemId] = cachedItem;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
_refreshCache(cacheKey);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//remove item ids that were retrieved from cache
|
|
200
|
+
itemIds = itemIds.filter((itemId) => {
|
|
201
|
+
return !results.some((result) => {
|
|
202
|
+
return Number(itemId) === Number(result.Id);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (itemIds.length !== 0) {
|
|
207
|
+
let selectExpand: string[] = [];
|
|
208
|
+
|
|
209
|
+
if (select.length) {
|
|
210
|
+
selectExpand.push(`$select=${select.join(",")}`);
|
|
211
|
+
}
|
|
212
|
+
if (expand.length) {
|
|
213
|
+
selectExpand.push(`$expand=${expand.join(",")}`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let selectExpandQS = selectExpand.join("&");
|
|
217
|
+
|
|
218
|
+
if (options.batchRequests === false) {
|
|
219
|
+
itemIds.forEach((itemId) => {
|
|
220
|
+
let getItemsRequestUrl = `${baseUrl}(${itemId})?${selectExpandQS}`;
|
|
221
|
+
queue.push(getItemsRequestUrl);
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
let chunks = chunkArray(itemIds, 60);
|
|
225
|
+
for (var chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
226
|
+
let chunk = chunks[chunkIndex];
|
|
227
|
+
|
|
228
|
+
let filter = chunk.map((id) => {
|
|
229
|
+
return `(ID eq ${id})`;
|
|
230
|
+
}).join("or");
|
|
231
|
+
|
|
232
|
+
let getItemsRequestUrl = `${baseUrl}?${[`$filter=${filter}`, selectExpandQS].join("&")}`;
|
|
233
|
+
queue.push(getItemsRequestUrl);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
results: results,
|
|
240
|
+
allowCache: allowCache,
|
|
241
|
+
queue: queue,
|
|
242
|
+
cacheKey: cacheKey
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
type tGetItemsByIdResult_Single<T> = T;
|
|
247
|
+
type tGetItemsByIdResult_Verbose<T> = {
|
|
248
|
+
d: T | {
|
|
249
|
+
results: T[];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
type tGetItemsByIdResult_NoMetadata<T> = {
|
|
253
|
+
value: T | T[]
|
|
254
|
+
}
|
|
255
|
+
type tGetItemsByIdResult<T> = tGetItemsByIdResult_Single<T> | tGetItemsByIdResult_Verbose<T> | tGetItemsByIdResult_NoMetadata<T>;
|
|
256
|
+
|
|
257
|
+
function isVerboseResult<T extends IRestItem>(result: tGetItemsByIdResult<T>): result is tGetItemsByIdResult_Verbose<T> {
|
|
258
|
+
return !isNullOrUndefined((result as tGetItemsByIdResult_Verbose<T>).d);
|
|
259
|
+
}
|
|
260
|
+
function isNoMetaDataResult<T extends IRestItem>(result: tGetItemsByIdResult<T>): result is tGetItemsByIdResult_NoMetadata<T> {
|
|
261
|
+
return !isNullOrUndefined((result as tGetItemsByIdResult_NoMetadata<T>).value);
|
|
262
|
+
}
|
|
263
|
+
function isSingleResult<T extends IRestItem>(result: tGetItemsByIdResult<T>): result is tGetItemsByIdResult_Single<T> {
|
|
264
|
+
return isNumber((result as tGetItemsByIdResult_Single<T>).Id);
|
|
265
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { FileSystemObjectTypes, GeListItemsFoldersBehaviour, IDictionary, IFieldInfoEX, IFieldLookupInfo, IRestItem, isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber, jsonTypes, lastIndexOf, toHash } from "../../_dependencies";
|
|
2
|
+
import { ConsoleLogger } from "../../consolelogger";
|
|
3
|
+
import { DecodeFieldValuesAsTextKey, GetFieldNameFromRawValues } from "../common";
|
|
4
|
+
import { GetItemsByIdSync } from "./GetListItemsById";
|
|
5
|
+
|
|
6
|
+
const logger = ConsoleLogger.get("sharepoint.rest/list/common");
|
|
7
|
+
|
|
8
|
+
export function __fixGetListItemsResults(siteUrl: string, listIdOrTitle: string, items: IRestItem[], foldersBehaviour?: GeListItemsFoldersBehaviour, expandedLookupFields?: IFieldInfoEX[]): IRestItem[] {
|
|
9
|
+
let folders: { [folderPath: string]: IRestItem; } = {};
|
|
10
|
+
|
|
11
|
+
let itemFileRefMap: IDictionary<{ FileRef: string; FileSystemObjectType: FileSystemObjectTypes }> = {};
|
|
12
|
+
if (isNotEmptyArray(items) && isNullOrUndefined(items[0].FileRef)) {
|
|
13
|
+
//customer support ticket - request was missing teh FileRef column!
|
|
14
|
+
let additionalItems = GetItemsByIdSync(siteUrl, listIdOrTitle, items.map(i => i.Id), {
|
|
15
|
+
select: ["Id", "FileRef", "FileSystemObjectType"],
|
|
16
|
+
jsonMetadata: jsonTypes.nometadata
|
|
17
|
+
});
|
|
18
|
+
itemFileRefMap = toHash(additionalItems, i => i.Id.toString(10));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
items.forEach(item => {
|
|
22
|
+
try {
|
|
23
|
+
if (itemFileRefMap[item.Id]) {
|
|
24
|
+
let mappedValue = itemFileRefMap[item.Id];
|
|
25
|
+
item.FileRef = mappedValue.FileRef;
|
|
26
|
+
item.FileSystemObjectType = mappedValue.FileSystemObjectType;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let fileRef = item.FileRef as string || "";
|
|
30
|
+
let parts = fileRef.split('/');
|
|
31
|
+
item.FileLeafRef = parts.pop() || "";
|
|
32
|
+
item.FileDirRef = parts.join('/');
|
|
33
|
+
item.FileOrFolderName = item.FileLeafRef.split('.')[0];
|
|
34
|
+
|
|
35
|
+
if (item.FileSystemObjectType === 1) {
|
|
36
|
+
item.FileType = "folder";
|
|
37
|
+
item.__Items = [];
|
|
38
|
+
folders[fileRef.toLowerCase()] = item;
|
|
39
|
+
item.__DisplayTitle = item.FileLeafRef;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
//issue 8094 file name might have multiple dots
|
|
43
|
+
let splitDot = item.FileLeafRef.split('.');
|
|
44
|
+
item.FileType = splitDot.length > 1 ? splitDot.pop().toLowerCase() : "folder";
|
|
45
|
+
item.__DisplayTitle = splitDot.join('.');
|
|
46
|
+
if (item.FileType === '000') {
|
|
47
|
+
item.FileType = 'listitem';
|
|
48
|
+
item.__DisplayTitle = item.Title;
|
|
49
|
+
if (isNullOrEmptyString(item.__DisplayTitle))
|
|
50
|
+
item.__DisplayTitle = `Item #${item.Id}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isNotEmptyArray(expandedLookupFields))
|
|
55
|
+
expandedLookupFields.forEach((f: IFieldLookupInfo) => {
|
|
56
|
+
//ISSUE: 1519
|
|
57
|
+
let lookupField = f.LookupField;
|
|
58
|
+
|
|
59
|
+
//ISSUE: 1250 - expanded lookup fields with names that start with '_'
|
|
60
|
+
//will be returned as OData__name. We have to use the field name returned
|
|
61
|
+
//from GetFieldNameFromRawValues without the 'Id' appended to the name because
|
|
62
|
+
//the value has been expanded.
|
|
63
|
+
let fieldInternalName = f.InternalName;
|
|
64
|
+
let rawValue = item[f.InternalName];
|
|
65
|
+
if (isNullOrUndefined(rawValue)) {
|
|
66
|
+
fieldInternalName = GetFieldNameFromRawValues(f, {
|
|
67
|
+
excludeIdFromName: true
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
rawValue = item[fieldInternalName];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (rawValue) {
|
|
74
|
+
item.FieldValuesAsText = item.FieldValuesAsText || {};
|
|
75
|
+
|
|
76
|
+
let value: { Id: number; Title: string;[InternalName: string]: any } | { Id: number; Title: string;[InternalName: string]: any }[] = rawValue;
|
|
77
|
+
if (Array.isArray(value))//multi value
|
|
78
|
+
{
|
|
79
|
+
let id: number[] = [];
|
|
80
|
+
let text: string[] = [];
|
|
81
|
+
value.forEach(v => {
|
|
82
|
+
id.push(v.Id);
|
|
83
|
+
if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(v[lookupField])) {
|
|
84
|
+
text.push(v[lookupField]);
|
|
85
|
+
} else {
|
|
86
|
+
text.push(v.Title);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
item[`${fieldInternalName}Id`] = id;
|
|
90
|
+
item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = text.join(", ");
|
|
91
|
+
}
|
|
92
|
+
else if (isNumber(value && value.Id)) {
|
|
93
|
+
item[`${fieldInternalName}Id`] = value.Id;
|
|
94
|
+
//ISSUE: 1519 - condition to check if lookup field exists and get the value from the rawValue object by string index of lookup field key
|
|
95
|
+
if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(value[lookupField])) {
|
|
96
|
+
item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value[lookupField];
|
|
97
|
+
} else {
|
|
98
|
+
item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value.Title;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
} catch (e) {
|
|
104
|
+
logger.error(`Failed to fix list item result ${item && item.Id || 'unknown id'}`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
//loop through items, put them inside folders
|
|
109
|
+
let itemsInRoot: IRestItem[] = [];
|
|
110
|
+
items.forEach(item => {
|
|
111
|
+
let parentFolder = folders[item.FileDirRef.toLowerCase()];
|
|
112
|
+
if (!isNullOrUndefined(parentFolder)) {
|
|
113
|
+
|
|
114
|
+
if (item.FileSystemObjectType === FileSystemObjectTypes.Folder) {
|
|
115
|
+
//add it before any items, so we have folders first (sorted) and items after
|
|
116
|
+
let indexOfLastFolder = lastIndexOf(parentFolder.__Items, i => i.FileSystemObjectType === FileSystemObjectTypes.Folder);
|
|
117
|
+
parentFolder.__Items.splice(indexOfLastFolder + 1, 0, item);
|
|
118
|
+
} else
|
|
119
|
+
parentFolder.__Items.push(item);
|
|
120
|
+
item.__ParentFolder = parentFolder;
|
|
121
|
+
}
|
|
122
|
+
else itemsInRoot.push(item);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
switch (foldersBehaviour) {
|
|
126
|
+
case GeListItemsFoldersBehaviour.AllItemsNoFolders:
|
|
127
|
+
return items.filter(r => r.FileSystemObjectType !== 1);
|
|
128
|
+
case GeListItemsFoldersBehaviour.ItemsInsideFolders:
|
|
129
|
+
return itemsInRoot;
|
|
130
|
+
case GeListItemsFoldersBehaviour.ItemsAndFoldersFlat:
|
|
131
|
+
default:
|
|
132
|
+
return items;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export var SkipFields: string[] = [
|
|
137
|
+
"appauthor",
|
|
138
|
+
"appeditor",
|
|
139
|
+
"linktitle",
|
|
140
|
+
"linktitlenomenu",
|
|
141
|
+
"linkfilename",
|
|
142
|
+
"linkfilenamenomenu",
|
|
143
|
+
"_copysource",
|
|
144
|
+
"_complianceflags",
|
|
145
|
+
"_compliancetag",
|
|
146
|
+
"_compliancetagwrittentime",
|
|
147
|
+
"_compliancetaguserid",
|
|
148
|
+
"_isrecord",
|
|
149
|
+
//issue 5576: allow user to see version column "_uiversionstring",
|
|
150
|
+
"itemchildcount",
|
|
151
|
+
"folderchildcount",
|
|
152
|
+
"complianceassetid",
|
|
153
|
+
"xd_progid",
|
|
154
|
+
"xd_signature",
|
|
155
|
+
"_shortcuturl",
|
|
156
|
+
"_shortcutsiteid",
|
|
157
|
+
"_shortcutwebid",
|
|
158
|
+
"_shortcutuniqueid",
|
|
159
|
+
"_hascopydestinations",
|
|
160
|
+
"sortbehavior",
|
|
161
|
+
"permmask",
|
|
162
|
+
"syncclientid",
|
|
163
|
+
"progid",
|
|
164
|
+
"scopeid",
|
|
165
|
+
"virusstatus",
|
|
166
|
+
"_editmenutablestart",
|
|
167
|
+
"_editmenutablestart2",
|
|
168
|
+
"_editmenutableend",
|
|
169
|
+
"linkfilename2",
|
|
170
|
+
"basename",
|
|
171
|
+
"metainfo",
|
|
172
|
+
"_level",
|
|
173
|
+
"_iscurrentversion",
|
|
174
|
+
"originatorid",
|
|
175
|
+
"noexecute",
|
|
176
|
+
"bsn",
|
|
177
|
+
"_listschemaversion",
|
|
178
|
+
"_dirty",
|
|
179
|
+
"_parsable",
|
|
180
|
+
"_stubfile",
|
|
181
|
+
"_virusstatus",
|
|
182
|
+
"_virusvendorid",
|
|
183
|
+
"_virusinfo",
|
|
184
|
+
"_rmstemplateid",
|
|
185
|
+
"_iplabelid",
|
|
186
|
+
"_displayname",
|
|
187
|
+
"smtotalsize",
|
|
188
|
+
"smlastmodifieddate",
|
|
189
|
+
"smtotalfilestreamsize",
|
|
190
|
+
"smtotalfilecount",
|
|
191
|
+
"selecttitle",
|
|
192
|
+
"selectfilename",
|
|
193
|
+
"edit",
|
|
194
|
+
"workflowversion",
|
|
195
|
+
"workflowinstanceid",
|
|
196
|
+
"parentversionstring",
|
|
197
|
+
"parentleafname",
|
|
198
|
+
"docconcurrencynumber",
|
|
199
|
+
"parentuniqueid",
|
|
200
|
+
"streamhash",
|
|
201
|
+
"combine",
|
|
202
|
+
"repairdocument"];
|