@supernova-studio/client 0.47.42 → 0.47.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +15387 -10902
- package/dist/index.d.ts +15387 -10902
- package/dist/index.js +622 -309
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2131 -1818
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +2 -11
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +11 -12
- package/src/api/conversion/documentation/index.ts +0 -1
- package/src/api/dto/documentation/documentation-page-snapshot.ts +18 -0
- package/src/api/dto/documentation/index.ts +1 -0
- package/src/api/dto/elements/documentation/draft-state.ts +35 -0
- package/src/api/dto/elements/documentation/group-v2.ts +4 -6
- package/src/api/dto/elements/documentation/hierarchy.ts +36 -0
- package/src/api/dto/elements/documentation/index.ts +2 -0
- package/src/api/dto/elements/documentation/page-v2.ts +23 -23
- package/src/yjs/design-system-content/documentation-hierarchy.ts +6 -144
- package/src/yjs/index.ts +1 -0
- package/src/yjs/version-room/backend.ts +76 -0
- package/src/yjs/version-room/base.ts +224 -0
- package/src/yjs/version-room/frontend.ts +236 -0
- package/src/yjs/version-room/index.ts +3 -0
- package/src/api/conversion/documentation/documentation-elements-to-hierarchy-v2-dto.ts +0 -23
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ElementGroup,
|
|
6
6
|
groupBy,
|
|
7
7
|
} from "@supernova-studio/model";
|
|
8
|
-
import {
|
|
8
|
+
import { DTODocumentationGroupV2 } from "../../dto";
|
|
9
9
|
import {
|
|
10
10
|
documentationItemConfigurationToDTOV2,
|
|
11
11
|
getDtoDefaultItemConfigurationV2,
|
|
@@ -18,15 +18,6 @@ import { applyPrivacyConfigurationToNestedItems } from "./documentation-page-to-
|
|
|
18
18
|
//
|
|
19
19
|
// Please do not put more DTO conversion here unless you know what you're doing.
|
|
20
20
|
|
|
21
|
-
export function elementGroupsToDocumentationGroupStructureDTOV2(
|
|
22
|
-
groups: ElementGroup[],
|
|
23
|
-
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
24
|
-
): DTODocumentationGroupStructureV2[] {
|
|
25
|
-
const childrenIdsMap = calculateChildrenIdsMapV2(pages, groups);
|
|
26
|
-
|
|
27
|
-
return groups.map(group => elementGroupToDocumentationGroupStructureDTOV2(group, childrenIdsMap));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
21
|
export function elementGroupsToDocumentationGroupDTOV2(
|
|
31
22
|
groups: ElementGroup[],
|
|
32
23
|
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
@@ -54,7 +45,7 @@ export function elementGroupsToDocumentationGroupFixedConfigurationDTOV2(
|
|
|
54
45
|
function elementGroupToDocumentationGroupStructureDTOV2(
|
|
55
46
|
group: ElementGroup,
|
|
56
47
|
childrenIdsMap: Map<string, string[]>
|
|
57
|
-
):
|
|
48
|
+
): DTODocumentationGroupV2 {
|
|
58
49
|
const childrenIds = childrenIdsMap.get(group.persistentId) ?? [];
|
|
59
50
|
|
|
60
51
|
if (!group.shortPersistentId) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DocumentationItemConfigurationV2, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
|
|
2
|
-
import {
|
|
2
|
+
import { DTODocumentationPageV2 } from "../../dto";
|
|
3
3
|
import {
|
|
4
4
|
documentationItemConfigurationToDTOV2,
|
|
5
5
|
getDtoDefaultItemConfigurationV2,
|
|
6
6
|
} from "./documentation-item-configuration-v2-to-dto";
|
|
7
|
-
import {
|
|
7
|
+
import { applyPrivacyConfigurationToNestedItems, buildDocPagePublishPaths } from "./documentation-page-to-dto-utils";
|
|
8
8
|
|
|
9
9
|
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
10
10
|
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
@@ -12,13 +12,13 @@ import { buildDocPagePublishPaths, applyPrivacyConfigurationToNestedItems } from
|
|
|
12
12
|
//
|
|
13
13
|
// Please do not put more DTO conversion here unless you know what you're doing.
|
|
14
14
|
|
|
15
|
-
export function
|
|
16
|
-
|
|
15
|
+
export function documentationPageToDTOV2(
|
|
16
|
+
page: DocumentationPageV2,
|
|
17
17
|
groups: ElementGroup[],
|
|
18
18
|
routingVersion: string
|
|
19
|
-
):
|
|
20
|
-
const pathsMap = buildDocPagePublishPaths(groups,
|
|
21
|
-
return
|
|
19
|
+
): DTODocumentationPageV2 {
|
|
20
|
+
const pathsMap = buildDocPagePublishPaths(groups, [page], routingVersion);
|
|
21
|
+
return _documentationPageToDTOV2(page, pathsMap);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function documentationPagesToDTOV2(
|
|
@@ -27,8 +27,7 @@ export function documentationPagesToDTOV2(
|
|
|
27
27
|
routingVersion: string
|
|
28
28
|
): DTODocumentationPageV2[] {
|
|
29
29
|
const pathsMap = buildDocPagePublishPaths(groups, pages, routingVersion);
|
|
30
|
-
|
|
31
|
-
return pages.map(page => documentationPageToStructureDTOV2(page, pathsMap));
|
|
30
|
+
return pages.map(page => _documentationPageToDTOV2(page, pathsMap));
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export function documentationPagesFixedConfigurationToDTOV2(
|
|
@@ -44,13 +43,13 @@ export function documentationPagesFixedConfigurationToDTOV2(
|
|
|
44
43
|
DocumentationItemConfigurationV2
|
|
45
44
|
>(pages, groups, getDtoDefaultItemConfigurationV2);
|
|
46
45
|
|
|
47
|
-
return fixedPages.map(page =>
|
|
46
|
+
return fixedPages.map(page => _documentationPageToDTOV2(page, pathsMap));
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
function
|
|
49
|
+
function _documentationPageToDTOV2(
|
|
51
50
|
page: DocumentationPageV2,
|
|
52
51
|
pagePathMap: Map<string, string>
|
|
53
|
-
):
|
|
52
|
+
): DTODocumentationPageV2 {
|
|
54
53
|
let path = pagePathMap.get(page.persistentId);
|
|
55
54
|
if (!path) throw new Error(`Path for page ${page.id} was not calculated`);
|
|
56
55
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DesignElementSnapshotReason } from "@supernova-studio/model";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { DTODocumentationPageV2 } from "../elements/documentation/page-v2";
|
|
4
|
+
|
|
5
|
+
export const DTODocumentationPageSnapshot = z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
designSystemVersionId: z.string(),
|
|
8
|
+
|
|
9
|
+
createdAt: z.string(),
|
|
10
|
+
updatedAt: z.string(),
|
|
11
|
+
|
|
12
|
+
documentationPage: DTODocumentationPageV2,
|
|
13
|
+
pageContentHash: z.string(),
|
|
14
|
+
|
|
15
|
+
reason: DesignElementSnapshotReason,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export type DTODocumentationPageSnapshot = z.infer<typeof DTODocumentationPageSnapshot>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
|
|
3
|
+
|
|
4
|
+
export const DTODocumentationDraftChangeType = z.enum(["Created", "Updated", "Deleted"]);
|
|
5
|
+
|
|
6
|
+
export const DTODocumentationDraftStateCreated = z.object({
|
|
7
|
+
changeType: z.literal(DTODocumentationDraftChangeType.enum.Created),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const DTODocumentationDraftStateUpdated = z.object({
|
|
11
|
+
changeType: z.literal(DTODocumentationDraftChangeType.enum.Updated),
|
|
12
|
+
changes: z.object({
|
|
13
|
+
previousTitle: z.string().optional(),
|
|
14
|
+
previousConfiguration: DTODocumentationItemConfigurationV2.optional(),
|
|
15
|
+
previousContentHash: z.string().optional(),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const DTODocumentationDraftStateDeleted = z.object({
|
|
20
|
+
changeType: z.literal(DTODocumentationDraftChangeType.enum.Deleted),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const DTODocumentationDraftState = z.discriminatedUnion("changeType", [
|
|
24
|
+
DTODocumentationDraftStateCreated,
|
|
25
|
+
DTODocumentationDraftStateUpdated,
|
|
26
|
+
DTODocumentationDraftStateDeleted,
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
export type DTODocumentationDraftChangeType = z.infer<typeof DTODocumentationDraftChangeType>;
|
|
30
|
+
|
|
31
|
+
export type DTODocumentationDraftStateCreated = z.infer<typeof DTODocumentationDraftStateCreated>;
|
|
32
|
+
export type DTODocumentationDraftStateUpdated = z.infer<typeof DTODocumentationDraftStateUpdated>;
|
|
33
|
+
export type DTODocumentationDraftStateDeleted = z.infer<typeof DTODocumentationDraftStateDeleted>;
|
|
34
|
+
|
|
35
|
+
export type DTODocumentationDraftState = z.infer<typeof DTODocumentationDraftState>;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { DocumentationGroupBehavior, ElementGroup } from "@supernova-studio/model";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { DTODocumentationDraftState } from "./draft-state";
|
|
3
4
|
import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
|
|
4
5
|
|
|
5
6
|
//
|
|
6
7
|
// Read
|
|
7
8
|
//
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
-
* Structure DTO is element properties minus element data (in other words data required
|
|
11
|
-
* to display the element in the left panel)
|
|
12
|
-
*/
|
|
13
10
|
export const DTODocumentationGroupV2 = ElementGroup.omit({
|
|
14
11
|
sortOrder: true,
|
|
15
12
|
parentPersistentId: true,
|
|
@@ -26,11 +23,12 @@ export const DTODocumentationGroupV2 = ElementGroup.omit({
|
|
|
26
23
|
shortPersistentId: z.string(),
|
|
27
24
|
configuration: DTODocumentationItemConfigurationV2,
|
|
28
25
|
type: z.literal("Group"),
|
|
26
|
+
|
|
27
|
+
/** Defined when a group has changed since last publish and can be included into a partial publish */
|
|
28
|
+
draftState: DTODocumentationDraftState.optional(),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
export type DTODocumentationGroupV2 = z.infer<typeof DTODocumentationGroupV2>;
|
|
32
|
-
export const DTODocumentationGroupStructureV2 = DTODocumentationGroupV2;
|
|
33
|
-
export type DTODocumentationGroupStructureV2 = DTODocumentationGroupV2;
|
|
34
32
|
|
|
35
33
|
//
|
|
36
34
|
// Write
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DTODocumentationDraftState } from "./draft-state";
|
|
3
|
+
import { DTODocumentationGroupV2 } from "./group-v2";
|
|
4
|
+
import { DTODocumentationPageV2 } from "./page-v2";
|
|
5
|
+
|
|
6
|
+
export const DTODocumentationHierarchyV2 = z.object({
|
|
7
|
+
pages: z.array(
|
|
8
|
+
DTODocumentationPageV2.extend({
|
|
9
|
+
/** Defined when a page has changed since last publish and can be included into a partial publish */
|
|
10
|
+
draftState: DTODocumentationDraftState.optional(),
|
|
11
|
+
})
|
|
12
|
+
),
|
|
13
|
+
|
|
14
|
+
groups: z.array(
|
|
15
|
+
DTODocumentationGroupV2.extend({
|
|
16
|
+
/** Defined when a page has changed since last publish and can be included into a partial publish */
|
|
17
|
+
draftState: DTODocumentationDraftState.optional(),
|
|
18
|
+
})
|
|
19
|
+
),
|
|
20
|
+
|
|
21
|
+
deletedPages: z.array(
|
|
22
|
+
DTODocumentationPageV2.extend({
|
|
23
|
+
/** Deleted page is always a draft change */
|
|
24
|
+
draftState: DTODocumentationDraftState,
|
|
25
|
+
})
|
|
26
|
+
),
|
|
27
|
+
|
|
28
|
+
deletedGroups: z.array(
|
|
29
|
+
DTODocumentationGroupV2.extend({
|
|
30
|
+
/** Deleted page is always a draft change */
|
|
31
|
+
draftState: DTODocumentationDraftState,
|
|
32
|
+
})
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export type DTODocumentationHierarchyV2 = z.infer<typeof DTODocumentationHierarchyV2>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from "./draft-state";
|
|
1
2
|
export * from "./group-action";
|
|
2
3
|
export * from "./group-v1";
|
|
3
4
|
export * from "./group-v2";
|
|
5
|
+
export * from "./hierarchy";
|
|
4
6
|
export * from "./item-configuration-v1";
|
|
5
7
|
export * from "./item-configuration-v2";
|
|
6
8
|
export * from "./page-actions-v2";
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { DesignElementSnapshot, DocumentationPageV2 } from "@supernova-studio/model";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
2
|
+
import { DTODocumentationDraftState } from "./draft-state";
|
|
4
3
|
import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
|
|
4
|
+
|
|
5
5
|
//
|
|
6
6
|
// Read
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
meta: true,
|
|
16
|
-
parentPersistentId: true,
|
|
17
|
-
sortOrder: true,
|
|
18
|
-
}).extend({
|
|
9
|
+
export const DTODocumentationPageV2 = z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
persistentId: z.string(),
|
|
12
|
+
|
|
13
|
+
designSystemVersionId: z.string(),
|
|
14
|
+
|
|
19
15
|
title: z.string(),
|
|
20
|
-
path: z.string(),
|
|
21
|
-
type: z.literal("Page"),
|
|
22
16
|
configuration: DTODocumentationItemConfigurationV2,
|
|
23
|
-
});
|
|
24
|
-
export type DTODocumentationPageV2 = z.infer<typeof DTODocumentationPageV2>;
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
export type DTODocumentationPageStructureV2 = DTODocumentationPageV2;
|
|
18
|
+
shortPersistentId: z.string(),
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
slug: z.string().optional(),
|
|
21
|
+
userSlug: z.string().optional(),
|
|
22
|
+
|
|
23
|
+
createdAt: z.coerce.date(),
|
|
24
|
+
updatedAt: z.coerce.date(),
|
|
25
|
+
|
|
26
|
+
path: z.string(),
|
|
27
|
+
|
|
28
|
+
/** Defined when a page has changed since last publish and can be included into a partial publish */
|
|
29
|
+
draftState: DTODocumentationDraftState.optional(),
|
|
30
|
+
|
|
31
|
+
// Backward compatibility
|
|
32
|
+
type: z.literal("Page"),
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
export type
|
|
35
|
+
export type DTODocumentationPageV2 = z.infer<typeof DTODocumentationPageV2>;
|
|
36
36
|
|
|
37
37
|
//
|
|
38
38
|
// Write
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DesignElementSnapshot, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
|
|
2
1
|
import * as Y from "yjs";
|
|
3
2
|
import { z } from "zod";
|
|
4
|
-
import { DTODocumentationHierarchyV2
|
|
3
|
+
import { DTODocumentationHierarchyV2 } from "../../api";
|
|
4
|
+
import { FrontendVersionRoomYDoc } from "../version-room/frontend";
|
|
5
5
|
|
|
6
6
|
// We store pages and groups in the same way they are stored in the database.
|
|
7
7
|
// This means that instead of groups having childrenIds array, all items have
|
|
@@ -18,16 +18,6 @@ import { DTODocumentationHierarchyV2, documentationElementsToHierarchyDto } from
|
|
|
18
18
|
// Types
|
|
19
19
|
//
|
|
20
20
|
|
|
21
|
-
type DocumentationHierarchyTransaction = {
|
|
22
|
-
pages: DocumentationPageV2[];
|
|
23
|
-
groups: ElementGroup[];
|
|
24
|
-
pageIdsToDelete: string[];
|
|
25
|
-
groupIdsToDelete: string[];
|
|
26
|
-
publishedPageSnapshots: DesignElementSnapshot[];
|
|
27
|
-
|
|
28
|
-
internalSettings: DocumentationHierarchySettings | undefined;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
21
|
export const DocumentationHierarchySettings = z.object({
|
|
32
22
|
routingVersion: z.string(),
|
|
33
23
|
isDraftFeatureAdopted: z.boolean(),
|
|
@@ -35,137 +25,9 @@ export const DocumentationHierarchySettings = z.object({
|
|
|
35
25
|
|
|
36
26
|
export type DocumentationHierarchySettings = z.infer<typeof DocumentationHierarchySettings>;
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export function documentationHierarchyToYjs(doc: Y.Doc, transaction: DocumentationHierarchyTransaction) {
|
|
43
|
-
doc.transact(trx => {
|
|
44
|
-
// Pages
|
|
45
|
-
const pagesMap = getPagesYMap(trx.doc);
|
|
46
|
-
|
|
47
|
-
transaction.pageIdsToDelete.forEach(pageId => {
|
|
48
|
-
pagesMap.delete(pageId);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
transaction.pages.forEach(page => {
|
|
52
|
-
// We remove blocks from the payload here because it will not get parsed anyway
|
|
53
|
-
const sanitizedPage: DocumentationPageV2 = {
|
|
54
|
-
...page,
|
|
55
|
-
data: {
|
|
56
|
-
configuration: page.data.configuration,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
pagesMap.set(page.id, JSON.parse(JSON.stringify(sanitizedPage)));
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Groups
|
|
64
|
-
const groupsMap = getGroupsYMap(trx.doc);
|
|
65
|
-
|
|
66
|
-
transaction.groupIdsToDelete.forEach(id => {
|
|
67
|
-
groupsMap.delete(id);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
transaction.groups.forEach(group => {
|
|
71
|
-
groupsMap.set(group.id, JSON.parse(JSON.stringify(group)));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Published state
|
|
75
|
-
const publishedSnapshotsMap = getPublishedSnapshotsYMap(trx.doc);
|
|
76
|
-
|
|
77
|
-
transaction.publishedPageSnapshots.forEach(state => {
|
|
78
|
-
publishedSnapshotsMap.set(state.id, JSON.parse(JSON.stringify(state)));
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Internal settings
|
|
82
|
-
if (transaction.internalSettings) {
|
|
83
|
-
serializeDocumentationInternalSettings(trx.doc, transaction.internalSettings);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return doc;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function serializeDocumentationInternalSettings(doc: Y.Doc, settings: DocumentationHierarchySettings) {
|
|
91
|
-
const map = getInternalSettingsYMap(doc);
|
|
92
|
-
|
|
93
|
-
map.set("routingVersion", settings.routingVersion);
|
|
94
|
-
settings.isDraftFeatureAdopted !== undefined && map.set("isDraftFeatureAdapted", settings.isDraftFeatureAdopted);
|
|
95
|
-
}
|
|
96
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated - Use FrontendVersionRoomYDoc.getDocumentationHierarchy
|
|
30
|
+
*/
|
|
97
31
|
export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarchyV2 {
|
|
98
|
-
|
|
99
|
-
const groupsMap = getGroupsYMap(doc);
|
|
100
|
-
const publishedSnapshotsMap = getPublishedSnapshotsYMap(doc);
|
|
101
|
-
|
|
102
|
-
// Read pages
|
|
103
|
-
const pages: DocumentationPageV2[] = [];
|
|
104
|
-
pagesMap.forEach(page => {
|
|
105
|
-
pages.push(DocumentationPageV2.parse(page));
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Read groups
|
|
109
|
-
const groups: ElementGroup[] = [];
|
|
110
|
-
groupsMap.forEach(group => {
|
|
111
|
-
groups.push(ElementGroup.parse(group));
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Read states
|
|
115
|
-
const publishedSnapshots: DesignElementSnapshot[] = [];
|
|
116
|
-
publishedSnapshotsMap.forEach(state => {
|
|
117
|
-
publishedSnapshots.push(DesignElementSnapshot.parse(state));
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Parse internalSettings
|
|
121
|
-
const internalSettings = parseDocumentationInternalSettings(doc);
|
|
122
|
-
|
|
123
|
-
// Map model onto client DTO
|
|
124
|
-
const hierarchy = documentationElementsToHierarchyDto(
|
|
125
|
-
pages,
|
|
126
|
-
groups,
|
|
127
|
-
publishedSnapshots,
|
|
128
|
-
internalSettings.routingVersion ?? "2"
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
return hierarchy;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function parseDocumentationInternalSettings(doc: Y.Doc): DocumentationHierarchySettings {
|
|
135
|
-
const map = getInternalSettingsYMap(doc);
|
|
136
|
-
|
|
137
|
-
const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
|
|
138
|
-
routingVersion: map.get("routingVersion"),
|
|
139
|
-
isDraftFeatureAdopted: map.get("isDraftFeatureAdapted") ?? false,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
|
|
143
|
-
if (!settingsParseResult.success) {
|
|
144
|
-
return {
|
|
145
|
-
routingVersion: "2",
|
|
146
|
-
isDraftFeatureAdopted: false,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return settingsParseResult.data;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
// Internals
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
function getPagesYMap(doc: Y.Doc) {
|
|
158
|
-
return doc.getMap<DocumentationPageV2>("documentationPages");
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getGroupsYMap(doc: Y.Doc) {
|
|
162
|
-
return doc.getMap<ElementGroup>("documentationGroups");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getInternalSettingsYMap(doc: Y.Doc) {
|
|
166
|
-
return doc.getMap<unknown>("documentationInternalSettings");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function getPublishedSnapshotsYMap(doc: Y.Doc) {
|
|
170
|
-
return doc.getMap<DesignElementSnapshot>("documentationPagePublishedSnapshots");
|
|
32
|
+
return new FrontendVersionRoomYDoc(doc).getDocumentationHierarchy();
|
|
171
33
|
}
|
package/src/yjs/index.ts
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DocumentationPageSnapshot,
|
|
3
|
+
DocumentationPageV2,
|
|
4
|
+
ElementGroup,
|
|
5
|
+
ElementGroupSnapshot,
|
|
6
|
+
} from "@supernova-studio/model";
|
|
7
|
+
import * as Y from "yjs";
|
|
8
|
+
import { DocumentationHierarchySettings } from "../design-system-content";
|
|
9
|
+
import { VersionRoomBaseYDoc } from "./base";
|
|
10
|
+
|
|
11
|
+
type DocumentationHierarchyTransaction = {
|
|
12
|
+
pages?: DocumentationPageV2[];
|
|
13
|
+
pageIdsToDelete?: string[];
|
|
14
|
+
|
|
15
|
+
groups?: ElementGroup[];
|
|
16
|
+
groupIdsToDelete?: string[];
|
|
17
|
+
|
|
18
|
+
publishedPageSnapshots?: DocumentationPageSnapshot[];
|
|
19
|
+
publishedPageSnapshotIdsToDelete?: string[];
|
|
20
|
+
|
|
21
|
+
publishedGroupSnapshots?: ElementGroupSnapshot[];
|
|
22
|
+
publishedGroupSnapshotIdsToDelete?: string[];
|
|
23
|
+
|
|
24
|
+
deletedPageSnapshots?: DocumentationPageSnapshot[];
|
|
25
|
+
deletedPageSnapshotIdsToDelete?: string[];
|
|
26
|
+
|
|
27
|
+
deletedGroupSnapshots?: ElementGroupSnapshot[];
|
|
28
|
+
deletedGroupSnapshotIdsToDelete?: string[];
|
|
29
|
+
|
|
30
|
+
internalSettings?: DocumentationHierarchySettings;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export class BackendVersionRoomYDoc {
|
|
34
|
+
private readonly yDoc: Y.Doc;
|
|
35
|
+
|
|
36
|
+
constructor(yDoc: Y.Doc) {
|
|
37
|
+
this.yDoc = yDoc;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
updateDocumentationHierarchy(transaction: DocumentationHierarchyTransaction) {
|
|
41
|
+
this.yDoc.transact(trx => {
|
|
42
|
+
const yDoc = new VersionRoomBaseYDoc(trx.doc);
|
|
43
|
+
|
|
44
|
+
// Pages
|
|
45
|
+
transaction.pageIdsToDelete && yDoc.deletePages(transaction.pageIdsToDelete);
|
|
46
|
+
transaction.pages && yDoc.updatePages(transaction.pages);
|
|
47
|
+
|
|
48
|
+
// Groups
|
|
49
|
+
transaction.groupIdsToDelete && yDoc.deleteGroups(transaction.groupIdsToDelete);
|
|
50
|
+
transaction.groups && yDoc.updateGroups(transaction.groups);
|
|
51
|
+
|
|
52
|
+
// Snapshots - published pages
|
|
53
|
+
transaction.publishedPageSnapshotIdsToDelete &&
|
|
54
|
+
yDoc.deletePagePublishedSnapshots(transaction.publishedPageSnapshotIdsToDelete);
|
|
55
|
+
transaction.publishedPageSnapshots && yDoc.updatePagePublishedSnapshots(transaction.publishedPageSnapshots);
|
|
56
|
+
|
|
57
|
+
// Snapshots - published groups
|
|
58
|
+
transaction.publishedGroupSnapshotIdsToDelete &&
|
|
59
|
+
yDoc.deleteGroupPublishedSnapshots(transaction.publishedGroupSnapshotIdsToDelete);
|
|
60
|
+
transaction.publishedGroupSnapshots && yDoc.updateGroupPublishedSnapshots(transaction.publishedGroupSnapshots);
|
|
61
|
+
|
|
62
|
+
// Snapshots - deleted pages
|
|
63
|
+
transaction.deletedPageSnapshotIdsToDelete &&
|
|
64
|
+
yDoc.deletePageDeletedSnapshots(transaction.deletedPageSnapshotIdsToDelete);
|
|
65
|
+
transaction.deletedPageSnapshots && yDoc.updatePageDeletedSnapshots(transaction.deletedPageSnapshots);
|
|
66
|
+
|
|
67
|
+
// Snapshots - deleted groups
|
|
68
|
+
transaction.deletedGroupSnapshotIdsToDelete &&
|
|
69
|
+
yDoc.deleteGroupDeletedSnapshots(transaction.deletedGroupSnapshotIdsToDelete);
|
|
70
|
+
transaction.deletedGroupSnapshots && yDoc.updateGroupDeletedSnapshots(transaction.deletedGroupSnapshots);
|
|
71
|
+
|
|
72
|
+
// Settings
|
|
73
|
+
transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|