1 | import { __decorate } from "tslib";
|
2 | import { hOP, isArray, objectDefinedNotNull } from "@pnp/core";
|
3 | import { body, headers, TextParse } from "@pnp/queryable";
|
4 | import { _SPCollection, spInvokableFactory, _SPInstance, deleteableWithETag, SPQueryable, SPCollection, } from "../spqueryable.js";
|
5 | import { odataUrlFrom } from "../utils/odata-url-from.js";
|
6 | import { defaultPath } from "../decorators.js";
|
7 | import { spPost, spPostMerge } from "../operations.js";
|
8 | import { toResourcePath } from "../utils/to-resource-path.js";
|
9 | import { encodePath } from "../utils/encode-path-str.js";
|
10 | let _Lists = class _Lists extends _SPCollection {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 | getById(id) {
|
17 | return List(this).concat(`('${id}')`);
|
18 | }
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | getByTitle(title) {
|
25 | return List(this, `getByTitle('${encodePath(title)}')`);
|
26 | }
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | async add(title, desc = "", template = 100, enableContentTypes = false, additionalSettings = {}) {
|
37 | const addSettings = {
|
38 | "AllowContentTypes": enableContentTypes,
|
39 | "BaseTemplate": template,
|
40 | "ContentTypesEnabled": enableContentTypes,
|
41 | "Description": desc,
|
42 | "Title": title,
|
43 | ...additionalSettings,
|
44 | };
|
45 | const data = await spPost(this, body(addSettings));
|
46 | return { data, list: this.getByTitle(addSettings.Title) };
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | async ensure(title, desc = "", template = 100, enableContentTypes = false, additionalSettings = {}) {
|
58 | const addOrUpdateSettings = { Title: title, Description: desc, ContentTypesEnabled: enableContentTypes, ...additionalSettings };
|
59 | const list = this.getByTitle(addOrUpdateSettings.Title);
|
60 | try {
|
61 | await list.select("Title")();
|
62 | const data = await list.update(addOrUpdateSettings).then(r => r.data);
|
63 | return { created: false, data, list: this.getByTitle(addOrUpdateSettings.Title) };
|
64 | }
|
65 | catch (e) {
|
66 | const data = await this.add(title, desc, template, enableContentTypes, addOrUpdateSettings).then(r => r.data);
|
67 | return { created: true, data, list: this.getByTitle(addOrUpdateSettings.Title) };
|
68 | }
|
69 | }
|
70 | |
71 |
|
72 |
|
73 | async ensureSiteAssetsLibrary() {
|
74 | const json = await spPost(Lists(this, "ensuresiteassetslibrary"));
|
75 | return List([this, odataUrlFrom(json)]);
|
76 | }
|
77 | |
78 |
|
79 |
|
80 | async ensureSitePagesLibrary() {
|
81 | const json = await spPost(Lists(this, "ensuresitepageslibrary"));
|
82 | return List([this, odataUrlFrom(json)]);
|
83 | }
|
84 | };
|
85 | _Lists = __decorate([
|
86 | defaultPath("lists")
|
87 | ], _Lists);
|
88 | export { _Lists };
|
89 | export const Lists = spInvokableFactory(_Lists);
|
90 | export class _List extends _SPInstance {
|
91 | constructor() {
|
92 | super(...arguments);
|
93 | this.delete = deleteableWithETag();
|
94 | }
|
95 | |
96 |
|
97 |
|
98 |
|
99 | get effectiveBasePermissions() {
|
100 | return SPQueryable(this, "EffectiveBasePermissions");
|
101 | }
|
102 | |
103 |
|
104 |
|
105 |
|
106 | get eventReceivers() {
|
107 | return SPCollection(this, "EventReceivers");
|
108 | }
|
109 | |
110 |
|
111 |
|
112 |
|
113 | get relatedFields() {
|
114 | return SPQueryable(this, "getRelatedFields");
|
115 | }
|
116 | |
117 |
|
118 |
|
119 |
|
120 | get informationRightsManagementSettings() {
|
121 | return SPQueryable(this, "InformationRightsManagementSettings");
|
122 | }
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | async update(properties, eTag = "*") {
|
130 | const data = await spPostMerge(this, body(properties, headers({ "IF-Match": eTag })));
|
131 | const list = hOP(properties, "Title") ? this.getParent(List, `getByTitle('${properties.Title}')`) : List(this);
|
132 | return {
|
133 | data,
|
134 | list,
|
135 | };
|
136 | }
|
137 | |
138 |
|
139 |
|
140 |
|
141 | getChanges(query) {
|
142 | return spPost(List(this, "getchanges"), body({ query }));
|
143 | }
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 | getItemsByCAMLQuery(query, ...expands) {
|
150 | return spPost(List(this, "getitems").expand(...expands), body({ query }));
|
151 | }
|
152 | |
153 |
|
154 |
|
155 |
|
156 | getListItemChangesSinceToken(query) {
|
157 | return spPost(List(this, "getlistitemchangessincetoken").using(TextParse()), body({ query }));
|
158 | }
|
159 | |
160 |
|
161 |
|
162 | async recycle() {
|
163 | return spPost(List(this, "recycle"));
|
164 | }
|
165 | |
166 |
|
167 |
|
168 |
|
169 | async renderListData(viewXml) {
|
170 | const q = List(this, "renderlistdata(@viewXml)");
|
171 | q.query.set("@viewXml", `'${viewXml}'`);
|
172 | const data = await spPost(q);
|
173 | return JSON.parse(data);
|
174 | }
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 | renderListDataAsStream(parameters, overrideParameters = null, query = new Map()) {
|
184 | if (hOP(parameters, "RenderOptions") && isArray(parameters.RenderOptions)) {
|
185 | parameters.RenderOptions = parameters.RenderOptions.reduce((v, c) => v + c);
|
186 | }
|
187 | const clone = List(this, "RenderListDataAsStream");
|
188 | if (query && query.size > 0) {
|
189 | query.forEach((v, k) => clone.query.set(k, v));
|
190 | }
|
191 | const params = objectDefinedNotNull(overrideParameters) ? { parameters, overrideParameters } : { parameters };
|
192 | return spPost(clone, body(params));
|
193 | }
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | async renderListFormData(itemId, formId, mode) {
|
201 | const data = await spPost(List(this, `renderlistformdata(itemid=${itemId}, formid='${formId}', mode='${mode}')`));
|
202 |
|
203 | return JSON.parse(data);
|
204 | }
|
205 | |
206 |
|
207 |
|
208 | async reserveListItemId() {
|
209 | return spPost(List(this, "reservelistitemid"));
|
210 | }
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | async addValidateUpdateItemUsingPath(formValues, decodedUrl, bNewDocumentUpdate = false, checkInComment, additionalProps) {
|
221 | const addProps = {
|
222 | FolderPath: toResourcePath(decodedUrl),
|
223 | };
|
224 | if (objectDefinedNotNull(additionalProps)) {
|
225 | if (additionalProps.leafName) {
|
226 | addProps.LeafName = toResourcePath(additionalProps.leafName);
|
227 | }
|
228 | if (additionalProps.objectType) {
|
229 | addProps.UnderlyingObjectType = additionalProps.objectType;
|
230 | }
|
231 | }
|
232 | return spPost(List(this, "AddValidateUpdateItemUsingPath()"), body({
|
233 | bNewDocumentUpdate,
|
234 | checkInComment,
|
235 | formValues,
|
236 | listItemCreateInfo: addProps,
|
237 | }));
|
238 | }
|
239 | |
240 |
|
241 |
|
242 | async getParentInfos() {
|
243 | const urlInfo = await this.select("Id", "RootFolder/UniqueId", "RootFolder/ServerRelativeUrl", "RootFolder/ServerRelativePath", "ParentWeb/Id", "ParentWeb/Url", "ParentWeb/ServerRelativeUrl", "ParentWeb/ServerRelativePath").expand("RootFolder", "ParentWeb")();
|
244 | return {
|
245 | List: {
|
246 | Id: urlInfo.Id,
|
247 | RootFolderServerRelativePath: urlInfo.RootFolder.ServerRelativePath,
|
248 | RootFolderServerRelativeUrl: urlInfo.RootFolder.ServerRelativeUrl,
|
249 | RootFolderUniqueId: urlInfo.RootFolder.UniqueId,
|
250 | },
|
251 | ParentWeb: {
|
252 | Id: urlInfo.ParentWeb.Id,
|
253 | ServerRelativePath: urlInfo.ParentWeb.ServerRelativePath,
|
254 | ServerRelativeUrl: urlInfo.ParentWeb.ServerRelativeUrl,
|
255 | Url: urlInfo.ParentWeb.Url,
|
256 | },
|
257 | };
|
258 | }
|
259 | }
|
260 | export const List = spInvokableFactory(_List);
|
261 |
|
262 |
|
263 |
|
264 | export var RenderListDataOptions;
|
265 | (function (RenderListDataOptions) {
|
266 | RenderListDataOptions[RenderListDataOptions["None"] = 0] = "None";
|
267 | RenderListDataOptions[RenderListDataOptions["ContextInfo"] = 1] = "ContextInfo";
|
268 | RenderListDataOptions[RenderListDataOptions["ListData"] = 2] = "ListData";
|
269 | RenderListDataOptions[RenderListDataOptions["ListSchema"] = 4] = "ListSchema";
|
270 | RenderListDataOptions[RenderListDataOptions["MenuView"] = 8] = "MenuView";
|
271 | RenderListDataOptions[RenderListDataOptions["ListContentType"] = 16] = "ListContentType";
|
272 | |
273 |
|
274 |
|
275 | RenderListDataOptions[RenderListDataOptions["FileSystemItemId"] = 32] = "FileSystemItemId";
|
276 | |
277 |
|
278 |
|
279 | RenderListDataOptions[RenderListDataOptions["ClientFormSchema"] = 64] = "ClientFormSchema";
|
280 | |
281 |
|
282 |
|
283 | RenderListDataOptions[RenderListDataOptions["QuickLaunch"] = 128] = "QuickLaunch";
|
284 | |
285 |
|
286 |
|
287 | RenderListDataOptions[RenderListDataOptions["Spotlight"] = 256] = "Spotlight";
|
288 | |
289 |
|
290 |
|
291 | RenderListDataOptions[RenderListDataOptions["Visualization"] = 512] = "Visualization";
|
292 | |
293 |
|
294 |
|
295 | RenderListDataOptions[RenderListDataOptions["ViewMetadata"] = 1024] = "ViewMetadata";
|
296 | |
297 |
|
298 |
|
299 | RenderListDataOptions[RenderListDataOptions["DisableAutoHyperlink"] = 2048] = "DisableAutoHyperlink";
|
300 | |
301 |
|
302 |
|
303 | RenderListDataOptions[RenderListDataOptions["EnableMediaTAUrls"] = 4096] = "EnableMediaTAUrls";
|
304 | |
305 |
|
306 |
|
307 | RenderListDataOptions[RenderListDataOptions["ParentInfo"] = 8192] = "ParentInfo";
|
308 | |
309 |
|
310 |
|
311 | RenderListDataOptions[RenderListDataOptions["PageContextInfo"] = 16384] = "PageContextInfo";
|
312 | |
313 |
|
314 |
|
315 | RenderListDataOptions[RenderListDataOptions["ClientSideComponentManifest"] = 32768] = "ClientSideComponentManifest";
|
316 | |
317 |
|
318 |
|
319 | RenderListDataOptions[RenderListDataOptions["ListAvailableContentTypes"] = 65536] = "ListAvailableContentTypes";
|
320 | |
321 |
|
322 |
|
323 | RenderListDataOptions[RenderListDataOptions["FolderContentTypeOrder"] = 131072] = "FolderContentTypeOrder";
|
324 | |
325 |
|
326 |
|
327 | RenderListDataOptions[RenderListDataOptions["GridInitInfo"] = 262144] = "GridInitInfo";
|
328 | |
329 |
|
330 |
|
331 | RenderListDataOptions[RenderListDataOptions["SiteUrlAsMediaTASPItemHost"] = 524288] = "SiteUrlAsMediaTASPItemHost";
|
332 | |
333 |
|
334 |
|
335 | RenderListDataOptions[RenderListDataOptions["AddToOneDrive"] = 1048576] = "AddToOneDrive";
|
336 | |
337 |
|
338 |
|
339 | RenderListDataOptions[RenderListDataOptions["SPFXCustomActions"] = 2097152] = "SPFXCustomActions";
|
340 | |
341 |
|
342 |
|
343 | RenderListDataOptions[RenderListDataOptions["CustomActions"] = 4194304] = "CustomActions";
|
344 | })(RenderListDataOptions || (RenderListDataOptions = {}));
|
345 |
|
346 |
|
347 |
|
348 | export var ControlMode;
|
349 | (function (ControlMode) {
|
350 | ControlMode[ControlMode["Display"] = 1] = "Display";
|
351 | ControlMode[ControlMode["Edit"] = 2] = "Edit";
|
352 | ControlMode[ControlMode["New"] = 3] = "New";
|
353 | })(ControlMode || (ControlMode = {}));
|
354 |
|
\ | No newline at end of file |