Move collection description rendering to JSON (#6944)

* First pass, moving collection description rendering to JSON

* tsc

* docs

* refactor

* test
This commit is contained in:
Tom Moor
2024-05-25 18:17:19 -04:00
committed by GitHub
parent d51267b8bc
commit f103d73b48
15 changed files with 225 additions and 81 deletions

View File

@@ -32,7 +32,7 @@ import {
BeforeDestroy,
} from "sequelize-typescript";
import isUUID from "validator/lib/isUUID";
import type { CollectionSort } from "@shared/types";
import type { CollectionSort, ProsemirrorData } from "@shared/types";
import { CollectionPermission, NavigationNode } from "@shared/types";
import { UrlHelper } from "@shared/utils/UrlHelper";
import { sortNavigationNodes } from "@shared/utils/collections";
@@ -49,6 +49,7 @@ import User from "./User";
import UserMembership from "./UserMembership";
import ParanoidModel from "./base/ParanoidModel";
import Fix from "./decorators/Fix";
import { DocumentHelper } from "./helpers/DocumentHelper";
import IsHexColor from "./validators/IsHexColor";
import Length from "./validators/Length";
import NotContainsUrl from "./validators/NotContainsUrl";
@@ -163,6 +164,12 @@ class Collection extends ParanoidModel<
@Column
name: string;
/**
* The content of the collection as Markdown.
*
* @deprecated Use `content` instead, or `DocumentHelper.toMarkdown` if exporting lossy markdown.
* This column will be removed in a future migration.
*/
@Length({
max: CollectionValidation.maxDescriptionLength,
msg: `description must be ${CollectionValidation.maxDescriptionLength} characters or less`,
@@ -170,6 +177,12 @@ class Collection extends ParanoidModel<
@Column
description: string | null;
/**
* The content of the collection as JSON, this is a snapshot at the last time the state was saved.
*/
@Column(DataType.JSONB)
content: ProsemirrorData | null;
@Length({
max: 50,
msg: `icon must be 50 characters or less`,
@@ -260,6 +273,10 @@ class Collection extends ParanoidModel<
if (model.icon === "collection") {
model.icon = null;
}
if (!model.content) {
model.content = await DocumentHelper.toJSON(model);
}
}
@BeforeDestroy