@supernova-studio/client 0.47.43 → 0.47.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.47.43",
3
+ "version": "0.47.45",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -5,7 +5,7 @@ import {
5
5
  ElementGroup,
6
6
  groupBy,
7
7
  } from "@supernova-studio/model";
8
- import { DTODocumentationGroupStructureV2, DTODocumentationGroupV2 } from "../../dto";
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
- ): DTODocumentationGroupStructureV2 {
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 { DTODocumentationPageStructureV2, DTODocumentationPageV2 } from "../../dto";
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 { buildDocPagePublishPaths, applyPrivacyConfigurationToNestedItems } from "./documentation-page-to-dto-utils";
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 documentationPagesToStructureDTOV2(
16
- pages: DocumentationPageV2[],
15
+ export function documentationPageToDTOV2(
16
+ page: DocumentationPageV2,
17
17
  groups: ElementGroup[],
18
18
  routingVersion: string
19
- ): DTODocumentationPageStructureV2[] {
20
- const pathsMap = buildDocPagePublishPaths(groups, pages, routingVersion);
21
- return pages.map(page => documentationPageToStructureDTOV2(page, pathsMap));
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 => documentationPageToStructureDTOV2(page, pathsMap));
46
+ return fixedPages.map(page => _documentationPageToDTOV2(page, pathsMap));
48
47
  }
49
48
 
50
- function documentationPageToStructureDTOV2(
49
+ function _documentationPageToDTOV2(
51
50
  page: DocumentationPageV2,
52
51
  pagePathMap: Map<string, string>
53
- ): DTODocumentationPageStructureV2 {
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
 
@@ -1,4 +1,3 @@
1
- export * from "./documentation-elements-to-hierarchy-v2-dto";
2
1
  export * from "./documentation-group-v1-to-dto";
3
2
  export * from "./documentation-group-v2-to-dto";
4
3
  export * from "./documentation-item-configuration-v1-to-dto";
@@ -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>;
@@ -1,2 +1,3 @@
1
1
  export * from "./anchor";
2
+ export * from "./documentation-page-snapshot";
2
3
  export * from "./link-preview";
@@ -3,8 +3,12 @@ import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
3
3
 
4
4
  export const DTODocumentationDraftChangeType = z.enum(["Created", "Updated", "Deleted"]);
5
5
 
6
- export const DTODocumentationDraftState = z.object({
7
- changeType: DTODocumentationDraftChangeType,
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),
8
12
  changes: z.object({
9
13
  previousTitle: z.string().optional(),
10
14
  previousConfiguration: DTODocumentationItemConfigurationV2.optional(),
@@ -12,5 +16,20 @@ export const DTODocumentationDraftState = z.object({
12
16
  }),
13
17
  });
14
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
+
15
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
+
16
35
  export type DTODocumentationDraftState = z.infer<typeof DTODocumentationDraftState>;
@@ -7,10 +7,6 @@ import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
7
7
  // Read
8
8
  //
9
9
 
10
- /**
11
- * Structure DTO is element properties minus element data (in other words data required
12
- * to display the element in the left panel)
13
- */
14
10
  export const DTODocumentationGroupV2 = ElementGroup.omit({
15
11
  sortOrder: true,
16
12
  parentPersistentId: true,
@@ -32,10 +28,7 @@ export const DTODocumentationGroupV2 = ElementGroup.omit({
32
28
  draftState: DTODocumentationDraftState.optional(),
33
29
  });
34
30
 
35
- export const DTODocumentationGroupStructureV2 = DTODocumentationGroupV2;
36
-
37
31
  export type DTODocumentationGroupV2 = z.infer<typeof DTODocumentationGroupV2>;
38
- export type DTODocumentationGroupStructureV2 = DTODocumentationGroupV2;
39
32
 
40
33
  //
41
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>;
@@ -2,6 +2,7 @@ export * from "./draft-state";
2
2
  export * from "./group-action";
3
3
  export * from "./group-v1";
4
4
  export * from "./group-v2";
5
+ export * from "./hierarchy";
5
6
  export * from "./item-configuration-v1";
6
7
  export * from "./item-configuration-v2";
7
8
  export * from "./page-actions-v2";
@@ -1,44 +1,38 @@
1
- import { DocumentationPageV2 } from "@supernova-studio/model";
2
1
  import { z } from "zod";
3
- import { DTODocumentationGroupStructureV2 } from "./group-v2";
4
- import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
5
2
  import { DTODocumentationDraftState } from "./draft-state";
3
+ import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
4
+
6
5
  //
7
6
  // Read
8
7
  //
9
8
 
10
- /**
11
- * Structure DTO is element properties minus element data (in other words data required
12
- * to display the element in the left panel)
13
- */
14
- export const DTODocumentationPageV2 = DocumentationPageV2.omit({
15
- data: true,
16
- meta: true,
17
- parentPersistentId: true,
18
- sortOrder: true,
19
- }).extend({
9
+ export const DTODocumentationPageV2 = z.object({
10
+ id: z.string(),
11
+ persistentId: z.string(),
12
+
13
+ designSystemVersionId: z.string(),
14
+
20
15
  title: z.string(),
21
- path: z.string(),
22
- type: z.literal("Page"),
23
16
  configuration: DTODocumentationItemConfigurationV2,
24
17
 
25
- /** Defined when a page has changed since last publish and can be included into a partial publish */
26
- draftState: DTODocumentationDraftState.optional(),
27
- });
18
+ shortPersistentId: z.string(),
19
+
20
+ slug: z.string().optional(),
21
+ userSlug: z.string().optional(),
22
+
23
+ createdAt: z.coerce.date(),
24
+ updatedAt: z.coerce.date(),
28
25
 
29
- export const DTODocumentationPageStructureV2 = DTODocumentationPageV2;
26
+ path: z.string(),
30
27
 
31
- export const DTODocumentationHierarchyV2 = z.object({
32
- pages: z.array(DTODocumentationPageStructureV2),
33
- groups: z.array(DTODocumentationGroupStructureV2),
28
+ /** Defined when a page has changed since last publish and can be included into a partial publish */
29
+ draftState: DTODocumentationDraftState.optional(),
34
30
 
35
- deletedPages: z.array(DTODocumentationPageStructureV2),
36
- deletedGroups: z.array(DTODocumentationGroupStructureV2),
31
+ // Backward compatibility
32
+ type: z.literal("Page"),
37
33
  });
38
34
 
39
35
  export type DTODocumentationPageV2 = z.infer<typeof DTODocumentationPageV2>;
40
- export type DTODocumentationPageStructureV2 = DTODocumentationPageV2;
41
- export type DTODocumentationHierarchyV2 = z.infer<typeof DTODocumentationHierarchyV2>;
42
36
 
43
37
  //
44
38
  // Write
@@ -1,16 +1,33 @@
1
- import { DesignElementSnapshot, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
1
+ import {
2
+ DocumentationPageSnapshot,
3
+ DocumentationPageV2,
4
+ ElementGroup,
5
+ ElementGroupSnapshot,
6
+ } from "@supernova-studio/model";
2
7
  import * as Y from "yjs";
3
8
  import { DocumentationHierarchySettings } from "../design-system-content";
4
9
  import { VersionRoomBaseYDoc } from "./base";
5
10
 
6
11
  type DocumentationHierarchyTransaction = {
7
- pages: DocumentationPageV2[];
8
- groups: ElementGroup[];
9
- pageIdsToDelete: string[];
10
- groupIdsToDelete: string[];
11
- publishedPageSnapshots: DesignElementSnapshot[];
12
+ pages?: DocumentationPageV2[];
13
+ pageIdsToDelete?: string[];
12
14
 
13
- internalSettings: DocumentationHierarchySettings | undefined;
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;
14
31
  };
15
32
 
16
33
  export class BackendVersionRoomYDoc {
@@ -25,15 +42,32 @@ export class BackendVersionRoomYDoc {
25
42
  const yDoc = new VersionRoomBaseYDoc(trx.doc);
26
43
 
27
44
  // Pages
28
- transaction.pageIdsToDelete.length && yDoc.deleteDocumentationPages(transaction.pageIdsToDelete);
29
- transaction.pages.length && yDoc.updateDocumentationPages(transaction.pages);
45
+ transaction.pageIdsToDelete && yDoc.deletePages(transaction.pageIdsToDelete);
46
+ transaction.pages && yDoc.updatePages(transaction.pages);
30
47
 
31
48
  // Groups
32
- transaction.groupIdsToDelete.length && yDoc.deleteDocumentationGroups(transaction.groupIdsToDelete);
33
- transaction.groups.length && yDoc.updateDocumentationGroups(transaction.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);
34
66
 
35
- // Snapshots
36
- // TODO Artem
67
+ // Snapshots - deleted groups
68
+ transaction.deletedGroupSnapshotIdsToDelete &&
69
+ yDoc.deleteGroupDeletedSnapshots(transaction.deletedGroupSnapshotIdsToDelete);
70
+ transaction.deletedGroupSnapshots && yDoc.updateGroupDeletedSnapshots(transaction.deletedGroupSnapshots);
37
71
 
38
72
  // Settings
39
73
  transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
@@ -1,19 +1,14 @@
1
- import { DesignElementSnapshot, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
1
+ import {
2
+ DocumentationPageSnapshot,
3
+ DocumentationPageV2,
4
+ ElementGroup,
5
+ ElementGroupSnapshot,
6
+ } from "@supernova-studio/model";
2
7
  import * as Y from "yjs";
8
+ import { ZodSchema, ZodTypeDef } from "zod";
3
9
  import { DocumentationHierarchySettings } from "../design-system-content";
4
10
 
5
- //
6
- // Types
7
- //
8
-
9
- type DocumentationHierarchyTransaction = {
10
- pages: DocumentationPageV2[];
11
- groups: ElementGroup[];
12
- pageIdsToDelete: string[];
13
- groupIdsToDelete: string[];
14
-
15
- internalSettings: DocumentationHierarchySettings | undefined;
16
- };
11
+ type YJSSerializable = { id: string };
17
12
 
18
13
  export class VersionRoomBaseYDoc {
19
14
  private readonly yDoc: Y.Doc;
@@ -26,74 +21,50 @@ export class VersionRoomBaseYDoc {
26
21
  // Pages
27
22
  //
28
23
 
29
- getDocumentationPages(): DocumentationPageV2[] {
30
- const pagesMap = this.pagesYMap;
31
-
32
- // Read pages
33
- const pages: DocumentationPageV2[] = [];
34
- pagesMap.forEach(page => {
35
- pages.push(DocumentationPageV2.parse(page));
36
- });
37
-
38
- return pages;
24
+ getPages(): DocumentationPageV2[] {
25
+ return this.getObjects(this.pagesYMap, DocumentationPageV2);
39
26
  }
40
27
 
41
- updateDocumentationPages(pages: DocumentationPageV2[]) {
42
- const pagesMap = this.pagesYMap;
43
-
44
- pages.forEach(page => {
28
+ updatePages(pages: DocumentationPageV2[]) {
29
+ pages = pages.map(page => {
45
30
  // We remove blocks from the payload here because it will not get parsed anyway
46
- const sanitizedPage: DocumentationPageV2 = {
31
+ return {
47
32
  ...page,
48
33
  data: {
49
34
  configuration: page.data.configuration,
50
35
  },
51
36
  };
52
-
53
- pagesMap.set(page.id, JSON.parse(JSON.stringify(sanitizedPage)));
54
37
  });
38
+
39
+ this.setObjects(this.pagesYMap, pages);
55
40
  }
56
41
 
57
- deleteDocumentationPages(ids: string[]) {
58
- const pagesMap = this.pagesYMap;
59
- ids.forEach(id => pagesMap.delete(id));
42
+ deletePages(ids: string[]) {
43
+ this.deleteObjects(this.pagesYMap, ids);
60
44
  }
61
45
 
62
46
  private get pagesYMap() {
63
- return this.yDoc.getMap<DocumentationPageV2>("documentationPages");
47
+ return this.yDoc.getMap<object>("documentationPages");
64
48
  }
65
49
 
66
50
  //
67
51
  // Groups
68
52
  //
69
53
 
70
- getDocumentationGroups(): ElementGroup[] {
71
- const groupsMap = this.groupsYMap;
72
-
73
- // Read groups
74
- const groups: ElementGroup[] = [];
75
- groupsMap.forEach(group => {
76
- groups.push(ElementGroup.parse(group));
77
- });
78
-
79
- return groups;
54
+ getGroups(): ElementGroup[] {
55
+ return this.getObjects(this.groupsYMap, ElementGroup);
80
56
  }
81
57
 
82
- updateDocumentationGroups(groups: ElementGroup[]) {
83
- const groupsMap = this.groupsYMap;
84
-
85
- groups.forEach(group => {
86
- groupsMap.set(group.id, JSON.parse(JSON.stringify(group)));
87
- });
58
+ updateGroups(groups: ElementGroup[]) {
59
+ this.setObjects(this.groupsYMap, groups);
88
60
  }
89
61
 
90
- deleteDocumentationGroups(ids: string[]) {
91
- const groupsMap = this.groupsYMap;
92
- ids.forEach(id => groupsMap.delete(id));
62
+ deleteGroups(ids: string[]) {
63
+ this.deleteObjects(this.groupsYMap, ids);
93
64
  }
94
65
 
95
66
  private get groupsYMap() {
96
- return this.yDoc.getMap<ElementGroup>("documentationGroups");
67
+ return this.yDoc.getMap<object>("documentationGroups");
97
68
  }
98
69
 
99
70
  //
@@ -133,12 +104,16 @@ export class VersionRoomBaseYDoc {
133
104
  // Documentation page published snapshot
134
105
  //
135
106
 
136
- getDocumentationPagePublishedSnapshots(): DesignElementSnapshot[] {
137
- return this.getSnapshots(this.documentationPagePublishedStatesYMap);
107
+ getPagePublishedSnapshots(): DocumentationPageSnapshot[] {
108
+ return this.getObjects(this.documentationPagePublishedStatesYMap, DocumentationPageSnapshot);
109
+ }
110
+
111
+ updatePagePublishedSnapshots(snapshots: DocumentationPageSnapshot[]) {
112
+ this.setObjects(this.documentationPagePublishedStatesYMap, snapshots);
138
113
  }
139
114
 
140
- updateDocumentationPagePublishedSnapshots(snapshots: DesignElementSnapshot[]) {
141
- this.setSnapshots(this.documentationPagePublishedStatesYMap, snapshots);
115
+ deletePagePublishedSnapshots(ids: string[]) {
116
+ this.deleteObjects(this.documentationPagePublishedStatesYMap, ids);
142
117
  }
143
118
 
144
119
  private get documentationPagePublishedStatesYMap() {
@@ -149,12 +124,16 @@ export class VersionRoomBaseYDoc {
149
124
  // Documentation page deleted snapshot
150
125
  //
151
126
 
152
- getDocumentationPageDeletedSnapshots(): DesignElementSnapshot[] {
153
- return this.getSnapshots(this.documentationPageDeletedStatesYMap);
127
+ getPageDeletedSnapshots(): DocumentationPageSnapshot[] {
128
+ return this.getObjects(this.documentationPageDeletedStatesYMap, DocumentationPageSnapshot);
154
129
  }
155
130
 
156
- updateDocumentationPageDeletedSnapshots(snapshots: DesignElementSnapshot[]) {
157
- this.setSnapshots(this.documentationPageDeletedStatesYMap, snapshots);
131
+ updatePageDeletedSnapshots(snapshots: DocumentationPageSnapshot[]) {
132
+ this.setObjects(this.documentationPageDeletedStatesYMap, snapshots);
133
+ }
134
+
135
+ deletePageDeletedSnapshots(ids: string[]) {
136
+ this.deleteObjects(this.documentationPageDeletedStatesYMap, ids);
158
137
  }
159
138
 
160
139
  private get documentationPageDeletedStatesYMap() {
@@ -165,12 +144,16 @@ export class VersionRoomBaseYDoc {
165
144
  // Documentation group published snapshots
166
145
  //
167
146
 
168
- getDocumentationGroupPublishedSnapshots(): DesignElementSnapshot[] {
169
- return this.getSnapshots(this.documentationGroupPublishedStatesYMap);
147
+ getGroupPublishedSnapshots(): ElementGroupSnapshot[] {
148
+ return this.getObjects(this.documentationGroupPublishedStatesYMap, ElementGroupSnapshot);
149
+ }
150
+
151
+ updateGroupPublishedSnapshots(snapshots: ElementGroupSnapshot[]) {
152
+ this.setObjects(this.documentationGroupPublishedStatesYMap, snapshots);
170
153
  }
171
154
 
172
- updateDocumentationGroupPublishedSnapshots(snapshots: DesignElementSnapshot[]) {
173
- this.setSnapshots(this.documentationGroupPublishedStatesYMap, snapshots);
155
+ deleteGroupPublishedSnapshots(ids: string[]) {
156
+ this.deleteObjects(this.documentationGroupPublishedStatesYMap, ids);
174
157
  }
175
158
 
176
159
  private get documentationGroupPublishedStatesYMap() {
@@ -181,12 +164,16 @@ export class VersionRoomBaseYDoc {
181
164
  // Documentation group deleted snapshots
182
165
  //
183
166
 
184
- getDocumentationGroupDeletedSnapshots(): DesignElementSnapshot[] {
185
- return this.getSnapshots(this.documentationGroupDeletedStatesYMap);
167
+ getGroupDeletedSnapshots(): ElementGroupSnapshot[] {
168
+ return this.getObjects(this.documentationGroupDeletedStatesYMap, ElementGroupSnapshot);
169
+ }
170
+
171
+ updateGroupDeletedSnapshots(snapshots: ElementGroupSnapshot[]) {
172
+ this.setObjects(this.documentationGroupDeletedStatesYMap, snapshots);
186
173
  }
187
174
 
188
- updateDocumentationGroupDeletedSnapshots(snapshots: DesignElementSnapshot[]) {
189
- this.setSnapshots(this.documentationGroupDeletedStatesYMap, snapshots);
175
+ deleteGroupDeletedSnapshots(ids: string[]) {
176
+ this.deleteObjects(this.documentationGroupDeletedStatesYMap, ids);
190
177
  }
191
178
 
192
179
  private get documentationGroupDeletedStatesYMap() {
@@ -194,22 +181,21 @@ export class VersionRoomBaseYDoc {
194
181
  }
195
182
 
196
183
  //
197
- // Snapshot utils
184
+ // Utils
198
185
  //
199
186
 
200
- private getSnapshots(map: Y.Map<object>): DesignElementSnapshot[] {
201
- const snapshots: DesignElementSnapshot[] = [];
202
- map.forEach(snapshot => {
203
- snapshots.push(DesignElementSnapshot.parse(snapshot));
204
- });
187
+ private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
188
+ const results: T[] = [];
189
+ map.forEach(object => results.push(schema.parse(object)));
190
+ return results;
191
+ }
205
192
 
206
- return snapshots;
193
+ private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
194
+ objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
207
195
  }
208
196
 
209
- private setSnapshots(map: Y.Map<object>, snapshots: DesignElementSnapshot[]) {
210
- snapshots.forEach(snapshot => {
211
- map.set(snapshot.id, JSON.parse(JSON.stringify(snapshot)));
212
- });
197
+ private deleteObjects(map: Y.Map<object>, ids: string[]) {
198
+ ids.forEach(id => map.delete(id));
213
199
  }
214
200
 
215
201
  //