UNPKG

15.3 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { hOP, isArray, objectDefinedNotNull } from "@pnp/core";
3import { body, headers, TextParse } from "@pnp/queryable";
4import { _SPCollection, spInvokableFactory, _SPInstance, deleteableWithETag, SPQueryable, SPCollection, } from "../spqueryable.js";
5import { odataUrlFrom } from "../utils/odata-url-from.js";
6import { defaultPath } from "../decorators.js";
7import { spPost, spPostMerge } from "../operations.js";
8import { toResourcePath } from "../utils/to-resource-path.js";
9import { encodePath } from "../utils/encode-path-str.js";
10let _Lists = class _Lists extends _SPCollection {
11 /**
12 * Gets a list from the collection by guid id
13 *
14 * @param id The Id of the list (GUID)
15 */
16 getById(id) {
17 return List(this).concat(`('${id}')`);
18 }
19 /**
20 * Gets a list from the collection by title
21 *
22 * @param title The title of the list
23 */
24 getByTitle(title) {
25 return List(this, `getByTitle('${encodePath(title)}')`);
26 }
27 /**
28 * Adds a new list to the collection
29 *
30 * @param title The new list's title
31 * @param description The new list's description
32 * @param template The list template value
33 * @param enableContentTypes If true content types will be allowed and enabled, otherwise they will be disallowed and not enabled
34 * @param additionalSettings Will be passed as part of the list creation body
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 * Ensures that the specified list exists in the collection (note: this method not supported for batching)
50 *
51 * @param title The new list's title
52 * @param desc The new list's description
53 * @param template The list template value
54 * @param enableContentTypes If true content types will be allowed and enabled, otherwise they will be disallowed and not enabled
55 * @param additionalSettings Will be passed as part of the list creation body or used to update an existing list
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 * Gets a list that is the default asset location for images or other files, which the users upload to their wiki pages.
72 */
73 async ensureSiteAssetsLibrary() {
74 const json = await spPost(Lists(this, "ensuresiteassetslibrary"));
75 return List([this, odataUrlFrom(json)]);
76 }
77 /**
78 * Gets a list that is the default location for wiki pages.
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);
88export { _Lists };
89export const Lists = spInvokableFactory(_Lists);
90export class _List extends _SPInstance {
91 constructor() {
92 super(...arguments);
93 this.delete = deleteableWithETag();
94 }
95 /**
96 * Gets the effective base permissions of this list
97 *
98 */
99 get effectiveBasePermissions() {
100 return SPQueryable(this, "EffectiveBasePermissions");
101 }
102 /**
103 * Gets the event receivers attached to this list
104 *
105 */
106 get eventReceivers() {
107 return SPCollection(this, "EventReceivers");
108 }
109 /**
110 * Gets the related fields of this list
111 *
112 */
113 get relatedFields() {
114 return SPQueryable(this, "getRelatedFields");
115 }
116 /**
117 * Gets the IRM settings for this list
118 *
119 */
120 get informationRightsManagementSettings() {
121 return SPQueryable(this, "InformationRightsManagementSettings");
122 }
123 /**
124 * Updates this list intance with the supplied properties
125 *
126 * @param properties A plain object hash of values to update for the list
127 * @param eTag Value used in the IF-Match header, by default "*"
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 * Returns the collection of changes from the change log that have occurred within the list, based on the specified query.
139 * @param query A query that is performed against the change log.
140 */
141 getChanges(query) {
142 return spPost(List(this, "getchanges"), body({ query }));
143 }
144 /**
145 * Returns the collection of items in the list based on the provided CamlQuery
146 * @param query A query that is performed against the list
147 * @param expands An expanded array of n items that contains fields to expand in the CamlQuery
148 */
149 getItemsByCAMLQuery(query, ...expands) {
150 return spPost(List(this, "getitems").expand(...expands), body({ query }));
151 }
152 /**
153 * See: https://msdn.microsoft.com/en-us/library/office/dn292554.aspx
154 * @param query An object that defines the change log item query
155 */
156 getListItemChangesSinceToken(query) {
157 return spPost(List(this, "getlistitemchangessincetoken").using(TextParse()), body({ query }));
158 }
159 /**
160 * Moves the list to the Recycle Bin and returns the identifier of the new Recycle Bin item.
161 */
162 async recycle() {
163 return spPost(List(this, "recycle"));
164 }
165 /**
166 * Renders list data based on the view xml provided
167 * @param viewXml A string object representing a view xml
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 * Returns the data for the specified query view
177 *
178 * @param parameters The parameters to be used to render list data as JSON string.
179 * @param overrideParams The parameters that are used to override and extend the regular SPRenderListDataParameters.
180 * @param query Allows setting of query parameters
181 */
182 // eslint-disable-next-line max-len
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 * Gets the field values and field schema attributes for a list item.
196 * @param itemId Item id of the item to render form data for
197 * @param formId The id of the form
198 * @param mode Enum representing the control mode of the form (Display, Edit, New)
199 */
200 async renderListFormData(itemId, formId, mode) {
201 const data = await spPost(List(this, `renderlistformdata(itemid=${itemId}, formid='${formId}', mode='${mode}')`));
202 // data will be a string, so we parse it again
203 return JSON.parse(data);
204 }
205 /**
206 * Reserves a list item ID for idempotent list item creation.
207 */
208 async reserveListItemId() {
209 return spPost(List(this, "reservelistitemid"));
210 }
211 /**
212 * Creates an item using path (in a folder), validates and sets its field values.
213 *
214 * @param formValues The fields to change and their new values.
215 * @param decodedUrl Path decoded url; folder's server relative path.
216 * @param bNewDocumentUpdate true if the list item is a document being updated after upload; otherwise false.
217 * @param checkInComment Optional check in comment.
218 * @param additionalProps Optional set of additional properties LeafName new document file name,
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 * Gets the parent information for this item's list and web
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}
260export const List = spInvokableFactory(_List);
261/**
262 * Enum representing the options of the RenderOptions property on IRenderListDataParameters interface
263 */
264export 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 * The returned list will have a FileSystemItemId field on each item if possible.
274 */
275 RenderListDataOptions[RenderListDataOptions["FileSystemItemId"] = 32] = "FileSystemItemId";
276 /**
277 * Returns the client form schema to add and edit items.
278 */
279 RenderListDataOptions[RenderListDataOptions["ClientFormSchema"] = 64] = "ClientFormSchema";
280 /**
281 * Returns QuickLaunch navigation nodes.
282 */
283 RenderListDataOptions[RenderListDataOptions["QuickLaunch"] = 128] = "QuickLaunch";
284 /**
285 * Returns Spotlight rendering information.
286 */
287 RenderListDataOptions[RenderListDataOptions["Spotlight"] = 256] = "Spotlight";
288 /**
289 * Returns Visualization rendering information.
290 */
291 RenderListDataOptions[RenderListDataOptions["Visualization"] = 512] = "Visualization";
292 /**
293 * Returns view XML and other information about the current view.
294 */
295 RenderListDataOptions[RenderListDataOptions["ViewMetadata"] = 1024] = "ViewMetadata";
296 /**
297 * Prevents AutoHyperlink from being run on text fields in this query.
298 */
299 RenderListDataOptions[RenderListDataOptions["DisableAutoHyperlink"] = 2048] = "DisableAutoHyperlink";
300 /**
301 * Enables urls pointing to Media TA service, such as .thumbnailUrl, .videoManifestUrl, .pdfConversionUrls.
302 */
303 RenderListDataOptions[RenderListDataOptions["EnableMediaTAUrls"] = 4096] = "EnableMediaTAUrls";
304 /**
305 * Return Parant folder information.
306 */
307 RenderListDataOptions[RenderListDataOptions["ParentInfo"] = 8192] = "ParentInfo";
308 /**
309 * Return Page context info for the current list being rendered.
310 */
311 RenderListDataOptions[RenderListDataOptions["PageContextInfo"] = 16384] = "PageContextInfo";
312 /**
313 * Return client-side component manifest information associated with the list.
314 */
315 RenderListDataOptions[RenderListDataOptions["ClientSideComponentManifest"] = 32768] = "ClientSideComponentManifest";
316 /**
317 * Return all content-types available on the list.
318 */
319 RenderListDataOptions[RenderListDataOptions["ListAvailableContentTypes"] = 65536] = "ListAvailableContentTypes";
320 /**
321 * Return the order of items in the new-item menu.
322 */
323 RenderListDataOptions[RenderListDataOptions["FolderContentTypeOrder"] = 131072] = "FolderContentTypeOrder";
324 /**
325 * Return information to initialize Grid for quick edit.
326 */
327 RenderListDataOptions[RenderListDataOptions["GridInitInfo"] = 262144] = "GridInitInfo";
328 /**
329 * Indicator if the vroom API of the SPItemUrl returned in MediaTAUrlGenerator should use site url as host.
330 */
331 RenderListDataOptions[RenderListDataOptions["SiteUrlAsMediaTASPItemHost"] = 524288] = "SiteUrlAsMediaTASPItemHost";
332 /**
333 * Return the files representing mount points in the list.
334 */
335 RenderListDataOptions[RenderListDataOptions["AddToOneDrive"] = 1048576] = "AddToOneDrive";
336 /**
337 * Return SPFX CustomAction.
338 */
339 RenderListDataOptions[RenderListDataOptions["SPFXCustomActions"] = 2097152] = "SPFXCustomActions";
340 /**
341 * Do not return non-SPFX CustomAction.
342 */
343 RenderListDataOptions[RenderListDataOptions["CustomActions"] = 4194304] = "CustomActions";
344})(RenderListDataOptions || (RenderListDataOptions = {}));
345/**
346 * Determines the display mode of the given control or view
347 */
348export 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//# sourceMappingURL=types.js.map
\No newline at end of file