UNPKG

contentful-management

Version:
66 lines (63 loc) 2.07 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils.js'; import enhanceWithMethods from '../enhance-with-methods.js'; // Remove and replace with BLOCKS as soon as rich-text-types supports mentions var CommentNode; (function (CommentNode) { CommentNode["Document"] = "document"; CommentNode["Paragraph"] = "paragraph"; CommentNode["Mention"] = "mention"; })(CommentNode || (CommentNode = {})); /** * @internal */ function createCommentApi(makeRequest) { const getParams = (comment) => { const parentEntity = comment.sys.parentEntity; return { spaceId: comment.sys.space.sys.id, environmentId: comment.sys.environment.sys.id, commentId: comment.sys.id, parentEntityType: parentEntity.sys.linkType, parentEntityId: parentEntity.sys.id, }; }; return { update: async function () { const raw = this.toPlainObject(); const data = await makeRequest({ entityType: 'Comment', action: 'update', params: getParams(raw), payload: raw, }); return wrapComment(makeRequest, data); }, delete: async function () { const raw = this.toPlainObject(); await makeRequest({ entityType: 'Comment', action: 'delete', params: { ...getParams(raw), version: raw.sys.version, }, }); }, }; } /** * @internal */ function wrapComment(makeRequest, data) { const comment = toPlainObject(copy(data)); const commentWithMethods = enhanceWithMethods(comment, createCommentApi(makeRequest)); return freezeSys(commentWithMethods); } /** * @internal */ const wrapCommentCollection = wrapCollection(wrapComment); export { CommentNode, wrapComment, wrapCommentCollection }; //# sourceMappingURL=comment.js.map