UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

110 lines 3.74 kB
import { __decorate } from "tslib"; import { body } from "@pnp/queryable"; import { _SPCollection, _SPInstance, spInvokableFactory, SPCollection, deleteable, spPost, spPostMerge, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; let _ContentTypes = class _ContentTypes extends _SPCollection { /** * Adds an existing contenttype to a content type collection * * @param contentTypeId in the following format, for example: 0x010102 */ async addAvailableContentType(contentTypeId) { const data = await spPost(ContentTypes(this, "addAvailableContentType"), body({ "contentTypeId": contentTypeId })); return { contentType: this.getById(data.id), data: data, }; } /** * Gets a ContentType by content type id * @param id The id of the content type to get, in the following format, for example: 0x010102 */ getById(id) { return ContentType(this).concat(`('${id}')`); } /** * Adds a new content type to the collection * * @param id The desired content type id for the new content type (also determines the parent * content type) * @param name The name of the content type * @param description The description of the content type * @param group The group in which to add the content type * @param additionalSettings Any additional settings to provide when creating the content type * */ async add(id, name, description = "", group = "Custom Content Types", additionalSettings = {}) { const postBody = body({ Description: description, Group: group, Id: { StringValue: id }, Name: name, ...additionalSettings, }); const data = await spPost(this, postBody); return { contentType: this.getById(data.id), data }; } }; _ContentTypes = __decorate([ defaultPath("contenttypes") ], _ContentTypes); export { _ContentTypes }; export const ContentTypes = spInvokableFactory(_ContentTypes); export class _ContentType extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Updates this list instance with the supplied properties * * @param properties A plain object hash of values to update for the web */ async update(properties) { return spPostMerge(this, body(properties)); } /** * Gets the column (also known as field) references in the content type. */ get fieldLinks() { return FieldLinks(this); } /** * Gets a value that specifies the collection of fields for the content type. */ get fields() { return SPCollection(this, "fields"); } /** * Gets the parent content type of the content type. */ get parent() { return ContentType(this, "parent"); } /** * Gets a value that specifies the collection of workflow associations for the content type. */ get workflowAssociations() { return SPCollection(this, "workflowAssociations"); } } export const ContentType = spInvokableFactory(_ContentType); let _FieldLinks = class _FieldLinks extends _SPCollection { /** * Gets a FieldLink by GUID id * * @param id The GUID id of the field link */ getById(id) { return FieldLink(this).concat(`(guid'${id}')`); } }; _FieldLinks = __decorate([ defaultPath("fieldlinks") ], _FieldLinks); export { _FieldLinks }; export const FieldLinks = spInvokableFactory(_FieldLinks); export class _FieldLink extends _SPInstance { } export const FieldLink = spInvokableFactory(_FieldLink); //# sourceMappingURL=types.js.map