UNPKG

contentful-management

Version:
62 lines (59 loc) 1.92 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) => ({ spaceId: comment.sys.space.sys.id, environmentId: comment.sys.environment.sys.id, entryId: comment.sys.parentEntity.sys.id, commentId: comment.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