@supernova-studio/client 0.59.11 → 1.0.0-alpha.10

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.
Files changed (203) hide show
  1. package/dist/index.d.mts +1590 -1909
  2. package/dist/index.d.ts +1590 -1909
  3. package/dist/index.js +866 -349
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +2570 -2053
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +4 -3
  8. package/src/api/client.ts +0 -31
  9. package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +0 -114
  10. package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +0 -92
  11. package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +0 -52
  12. package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +0 -34
  13. package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +0 -131
  14. package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +0 -69
  15. package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +0 -78
  16. package/src/api/conversion/documentation/index.ts +0 -7
  17. package/src/api/conversion/export/index.ts +0 -1
  18. package/src/api/conversion/export/pipeline.ts +0 -26
  19. package/src/api/conversion/index.ts +0 -3
  20. package/src/api/conversion/integrations/git.ts +0 -37
  21. package/src/api/conversion/integrations/index.ts +0 -2
  22. package/src/api/conversion/integrations/integration.ts +0 -37
  23. package/src/api/dto/aux/color.ts +0 -7
  24. package/src/api/dto/aux/index.ts +0 -3
  25. package/src/api/dto/aux/meta.ts +0 -8
  26. package/src/api/dto/aux/pagination.ts +0 -8
  27. package/src/api/dto/bff/app-bootstrap-data.ts +0 -20
  28. package/src/api/dto/bff/index.ts +0 -1
  29. package/src/api/dto/collections/index.ts +0 -1
  30. package/src/api/dto/collections/token-collection.ts +0 -24
  31. package/src/api/dto/design-systems/brand.ts +0 -44
  32. package/src/api/dto/design-systems/component.ts +0 -40
  33. package/src/api/dto/design-systems/contact.ts +0 -11
  34. package/src/api/dto/design-systems/data-source.ts +0 -141
  35. package/src/api/dto/design-systems/design-system.ts +0 -68
  36. package/src/api/dto/design-systems/elements-diff.ts +0 -14
  37. package/src/api/dto/design-systems/figma-variables.ts +0 -108
  38. package/src/api/dto/design-systems/import-job.ts +0 -61
  39. package/src/api/dto/design-systems/index.ts +0 -14
  40. package/src/api/dto/design-systems/members.ts +0 -50
  41. package/src/api/dto/design-systems/redirects.ts +0 -33
  42. package/src/api/dto/design-systems/role.ts +0 -11
  43. package/src/api/dto/design-systems/stats.ts +0 -19
  44. package/src/api/dto/design-systems/version.ts +0 -56
  45. package/src/api/dto/design-systems/view.ts +0 -45
  46. package/src/api/dto/design-tokens/design-token.ts +0 -78
  47. package/src/api/dto/design-tokens/index.ts +0 -1
  48. package/src/api/dto/documentation/anchor.ts +0 -15
  49. package/src/api/dto/documentation/approvals.ts +0 -15
  50. package/src/api/dto/documentation/block-definition.ts +0 -28
  51. package/src/api/dto/documentation/block.ts +0 -6
  52. package/src/api/dto/documentation/documentation-page-snapshot.ts +0 -18
  53. package/src/api/dto/documentation/index.ts +0 -8
  54. package/src/api/dto/documentation/link-preview.ts +0 -23
  55. package/src/api/dto/documentation/publish.ts +0 -23
  56. package/src/api/dto/documentation/room.ts +0 -12
  57. package/src/api/dto/elements/components/figma-component-group.ts +0 -19
  58. package/src/api/dto/elements/components/figma-component.ts +0 -56
  59. package/src/api/dto/elements/components/index.ts +0 -2
  60. package/src/api/dto/elements/documentation/draft-state.ts +0 -37
  61. package/src/api/dto/elements/documentation/group-action.ts +0 -108
  62. package/src/api/dto/elements/documentation/group-v1.ts +0 -35
  63. package/src/api/dto/elements/documentation/group-v2.ts +0 -117
  64. package/src/api/dto/elements/documentation/hierarchy.ts +0 -22
  65. package/src/api/dto/elements/documentation/index.ts +0 -13
  66. package/src/api/dto/elements/documentation/item-configuration-v1.ts +0 -24
  67. package/src/api/dto/elements/documentation/item-configuration-v2.ts +0 -14
  68. package/src/api/dto/elements/documentation/metadata.ts +0 -8
  69. package/src/api/dto/elements/documentation/page-actions-v2.ts +0 -121
  70. package/src/api/dto/elements/documentation/page-content.ts +0 -15
  71. package/src/api/dto/elements/documentation/page-v1.ts +0 -21
  72. package/src/api/dto/elements/documentation/page-v2.ts +0 -123
  73. package/src/api/dto/elements/documentation/structure.ts +0 -37
  74. package/src/api/dto/elements/elements-action-v2.ts +0 -111
  75. package/src/api/dto/elements/figma-nodes/figma-node-v1.ts +0 -32
  76. package/src/api/dto/elements/figma-nodes/figma-node-v2.ts +0 -32
  77. package/src/api/dto/elements/figma-nodes/figma-node.ts +0 -103
  78. package/src/api/dto/elements/figma-nodes/index.ts +0 -4
  79. package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +0 -44
  80. package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +0 -17
  81. package/src/api/dto/elements/frame-node-structures/index.ts +0 -1
  82. package/src/api/dto/elements/get-elements-v2.ts +0 -27
  83. package/src/api/dto/elements/index.ts +0 -7
  84. package/src/api/dto/elements/properties/index.ts +0 -2
  85. package/src/api/dto/elements/properties/property-definitions.ts +0 -75
  86. package/src/api/dto/elements/properties/property-values.ts +0 -38
  87. package/src/api/dto/export/exporter-property.ts +0 -105
  88. package/src/api/dto/export/exporter.ts +0 -87
  89. package/src/api/dto/export/filter.ts +0 -6
  90. package/src/api/dto/export/index.ts +0 -5
  91. package/src/api/dto/export/job.ts +0 -96
  92. package/src/api/dto/export/pipeline.ts +0 -43
  93. package/src/api/dto/figma-components/assets/download.ts +0 -30
  94. package/src/api/dto/figma-components/assets/index.ts +0 -1
  95. package/src/api/dto/figma-components/index.ts +0 -1
  96. package/src/api/dto/index.ts +0 -13
  97. package/src/api/dto/liveblocks/auth-response.ts +0 -7
  98. package/src/api/dto/liveblocks/index.ts +0 -1
  99. package/src/api/dto/themes/index.ts +0 -2
  100. package/src/api/dto/themes/override.ts +0 -27
  101. package/src/api/dto/themes/theme.ts +0 -45
  102. package/src/api/dto/users/authenticated-user.ts +0 -46
  103. package/src/api/dto/users/index.ts +0 -3
  104. package/src/api/dto/users/update.ts +0 -8
  105. package/src/api/dto/users/user.ts +0 -31
  106. package/src/api/dto/workspaces/git.ts +0 -32
  107. package/src/api/dto/workspaces/index.ts +0 -6
  108. package/src/api/dto/workspaces/integrations.ts +0 -34
  109. package/src/api/dto/workspaces/invitations.ts +0 -30
  110. package/src/api/dto/workspaces/membership.ts +0 -41
  111. package/src/api/dto/workspaces/npm-registry.ts +0 -35
  112. package/src/api/dto/workspaces/workspace.ts +0 -34
  113. package/src/api/endpoints/codegen/codegen.ts +0 -16
  114. package/src/api/endpoints/codegen/exporters.ts +0 -25
  115. package/src/api/endpoints/codegen/index.ts +0 -4
  116. package/src/api/endpoints/codegen/jobs.ts +0 -15
  117. package/src/api/endpoints/codegen/pipelines.ts +0 -44
  118. package/src/api/endpoints/design-system/bff.ts +0 -13
  119. package/src/api/endpoints/design-system/contact.ts +0 -12
  120. package/src/api/endpoints/design-system/design-systems.ts +0 -55
  121. package/src/api/endpoints/design-system/index.ts +0 -6
  122. package/src/api/endpoints/design-system/members.ts +0 -24
  123. package/src/api/endpoints/design-system/sources.ts +0 -35
  124. package/src/api/endpoints/design-system/versions/brands.ts +0 -45
  125. package/src/api/endpoints/design-system/versions/documentation.ts +0 -27
  126. package/src/api/endpoints/design-system/versions/ds-components.ts +0 -28
  127. package/src/api/endpoints/design-system/versions/elements-action.ts +0 -60
  128. package/src/api/endpoints/design-system/versions/elements.ts +0 -27
  129. package/src/api/endpoints/design-system/versions/figma-component-groups.ts +0 -13
  130. package/src/api/endpoints/design-system/versions/figma-components.ts +0 -13
  131. package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +0 -13
  132. package/src/api/endpoints/design-system/versions/import-jobs.ts +0 -13
  133. package/src/api/endpoints/design-system/versions/index.ts +0 -18
  134. package/src/api/endpoints/design-system/versions/overrides.ts +0 -17
  135. package/src/api/endpoints/design-system/versions/property-definitions.ts +0 -43
  136. package/src/api/endpoints/design-system/versions/property-values.ts +0 -25
  137. package/src/api/endpoints/design-system/versions/stats.ts +0 -12
  138. package/src/api/endpoints/design-system/versions/themes.ts +0 -35
  139. package/src/api/endpoints/design-system/versions/token-collections.ts +0 -13
  140. package/src/api/endpoints/design-system/versions/token-groups.ts +0 -28
  141. package/src/api/endpoints/design-system/versions/tokens.ts +0 -27
  142. package/src/api/endpoints/design-system/versions/versions.ts +0 -79
  143. package/src/api/endpoints/index.ts +0 -5
  144. package/src/api/endpoints/liveblocks.ts +0 -14
  145. package/src/api/endpoints/users.ts +0 -26
  146. package/src/api/endpoints/workspaces/index.ts +0 -3
  147. package/src/api/endpoints/workspaces/workspace-invites.ts +0 -34
  148. package/src/api/endpoints/workspaces/workspace-members.ts +0 -31
  149. package/src/api/endpoints/workspaces/workspaces.ts +0 -47
  150. package/src/api/index.ts +0 -6
  151. package/src/api/payloads/design-systems/index.ts +0 -2
  152. package/src/api/payloads/design-systems/update-design-system.ts +0 -29
  153. package/src/api/payloads/design-systems/version.ts +0 -29
  154. package/src/api/payloads/documentation/block-definitions.ts +0 -12
  155. package/src/api/payloads/documentation/design-data-doc-diff.ts +0 -7
  156. package/src/api/payloads/documentation/index.ts +0 -2
  157. package/src/api/payloads/export/index.ts +0 -1
  158. package/src/api/payloads/export/pipeline.ts +0 -74
  159. package/src/api/payloads/index.ts +0 -6
  160. package/src/api/payloads/liveblocks/auth.ts +0 -7
  161. package/src/api/payloads/liveblocks/index.ts +0 -1
  162. package/src/api/payloads/users/index.ts +0 -2
  163. package/src/api/payloads/users/notifications/index.ts +0 -1
  164. package/src/api/payloads/users/notifications/notification-settings.ts +0 -17
  165. package/src/api/payloads/users/profile/index.ts +0 -1
  166. package/src/api/payloads/users/profile/update.ts +0 -4
  167. package/src/api/payloads/workspaces/index.ts +0 -3
  168. package/src/api/payloads/workspaces/transfer-ownership.ts +0 -7
  169. package/src/api/payloads/workspaces/workspace-configuration.ts +0 -50
  170. package/src/api/payloads/workspaces/workspace-integrations.ts +0 -26
  171. package/src/api/transport/index.ts +0 -2
  172. package/src/api/transport/request-executor-error.ts +0 -66
  173. package/src/api/transport/request-executor.ts +0 -87
  174. package/src/events/design-system.ts +0 -21
  175. package/src/events/event.ts +0 -6
  176. package/src/events/index.ts +0 -2
  177. package/src/index.ts +0 -4
  178. package/src/utils/figma.ts +0 -72
  179. package/src/utils/hash.ts +0 -62
  180. package/src/utils/index.ts +0 -3
  181. package/src/utils/query.ts +0 -18
  182. package/src/yjs/design-system-content/documentation-hierarchy.ts +0 -35
  183. package/src/yjs/design-system-content/index.ts +0 -2
  184. package/src/yjs/design-system-content/item-configuration.ts +0 -93
  185. package/src/yjs/docs-editor/blocks-to-prosemirror.ts +0 -764
  186. package/src/yjs/docs-editor/index.ts +0 -7
  187. package/src/yjs/docs-editor/list-tree-builder.ts +0 -127
  188. package/src/yjs/docs-editor/mock.ts +0 -2142
  189. package/src/yjs/docs-editor/model/block.ts +0 -8
  190. package/src/yjs/docs-editor/model/index.ts +0 -2
  191. package/src/yjs/docs-editor/model/page.ts +0 -8
  192. package/src/yjs/docs-editor/prosemirror/index.ts +0 -3
  193. package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +0 -145
  194. package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +0 -577
  195. package/src/yjs/docs-editor/prosemirror/types.ts +0 -19
  196. package/src/yjs/docs-editor/prosemirror-to-blocks.ts +0 -975
  197. package/src/yjs/docs-editor/utils.ts +0 -115
  198. package/src/yjs/index.ts +0 -3
  199. package/src/yjs/version-room/backend.ts +0 -78
  200. package/src/yjs/version-room/base.ts +0 -226
  201. package/src/yjs/version-room/frontend.ts +0 -463
  202. package/src/yjs/version-room/index.ts +0 -4
  203. package/src/yjs/version-room/utils.ts +0 -109
@@ -1,115 +0,0 @@
1
- import { PageBlockEditorModel } from "./model/block";
2
- import {
3
- PageBlockDefinition,
4
- PageBlockDefinitionPropertyType,
5
- PageBlockItemEmbedValue,
6
- PageBlockItemMultiRichTextValue,
7
- PageBlockItemRichTextValue,
8
- PageBlockItemTableValue,
9
- PageBlockItemUntypedValue,
10
- PageBlockItemV2,
11
- PageBlockText,
12
- } from "@supernova-studio/model";
13
-
14
- export const BlockParsingUtils = {
15
- singleBlockItem(block: PageBlockEditorModel) {
16
- if (!block.data.items.length) throw new Error(`Block ${block.id} has no items`);
17
- if (block.data.items.length > 1) throw new Error(`Block ${block.id} has more than 1 item`);
18
-
19
- return block.data.items[0]!;
20
- },
21
-
22
- richTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemRichTextValue {
23
- const objectValue = this.objectPropertyValue(item, propertyKey);
24
- const richText = PageBlockItemRichTextValue.parse(objectValue);
25
-
26
- return richText;
27
- },
28
-
29
- multiRichTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemMultiRichTextValue {
30
- const objectValue = this.objectPropertyValue(item, propertyKey);
31
- const richText = PageBlockItemMultiRichTextValue.parse(objectValue);
32
-
33
- return richText;
34
- },
35
-
36
- tablePropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemTableValue {
37
- const objectValue = this.objectPropertyValue(item, propertyKey);
38
- const table = PageBlockItemTableValue.parse(objectValue);
39
-
40
- return table;
41
- },
42
-
43
- embedPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemEmbedValue {
44
- const objectValue = this.objectPropertyValue(item, propertyKey);
45
- const embed = PageBlockItemEmbedValue.parse(objectValue);
46
-
47
- return embed;
48
- },
49
-
50
- objectPropertyValue(item: PageBlockItemV2, propertyKey: string) {
51
- const value = this.propertyValueOrThrow(item, propertyKey);
52
-
53
- if (typeof value !== "object") {
54
- throw new Error(`Value for property ${propertyKey} is expected to be an object, but instead is ${typeof value}`);
55
- }
56
-
57
- return value;
58
- },
59
-
60
- propertyValueOrThrow(item: PageBlockItemV2, propertyKey: string): PageBlockItemUntypedValue {
61
- const value = item.props[propertyKey];
62
- if (!value) throw new Error(`Property ${propertyKey} is not defined on block item`);
63
-
64
- return value;
65
- },
66
- };
67
-
68
- export const BlockDefinitionUtils = {
69
- firstRichTextProperty(definition: PageBlockDefinition) {
70
- const property = definition.item.properties.find(p => p.type === "RichText");
71
- if (property) return property;
72
- return undefined;
73
- },
74
-
75
- firstMultiRichTextProperty(definition: PageBlockDefinition) {
76
- const property = definition.item.properties.find(p => p.type === "MultiRichText");
77
- if (property) return property;
78
- return undefined;
79
- },
80
-
81
- firstTableProperty(definition: PageBlockDefinition) {
82
- const property = definition.item.properties.find(p => p.type === "Table");
83
- if (property) return property;
84
- return undefined;
85
- },
86
-
87
- firstEmbedProperty(definition: PageBlockDefinition) {
88
- const property = definition.item.properties.find(p => p.type === "EmbedURL");
89
- if (property) return property;
90
- return undefined;
91
- },
92
-
93
- richTextProperty(definition: PageBlockDefinition, propertyKey: string) {
94
- return this.property(definition, propertyKey, "RichText");
95
- },
96
-
97
- property(
98
- definition: PageBlockDefinition,
99
- propertyKey: string,
100
- expectedPropertyType?: PageBlockDefinitionPropertyType
101
- ) {
102
- const property = definition.item.properties.find(p => p.id === propertyKey);
103
- if (!property) {
104
- throw new Error(`Definition ${definition.id} doesn't contain property ${propertyKey}`);
105
- }
106
-
107
- if (expectedPropertyType && property.type !== expectedPropertyType) {
108
- throw new Error(
109
- `Property ${propertyKey} of definition ${definition.id} expected to be ${expectedPropertyType} but was ${property.type}`
110
- );
111
- }
112
-
113
- return property;
114
- },
115
- };
package/src/yjs/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./design-system-content";
2
- export * from "./docs-editor";
3
- export * from "./version-room";
@@ -1,78 +0,0 @@
1
- import {
2
- DocumentationPageApproval,
3
- DocumentationPageSnapshot,
4
- DocumentationPageV2,
5
- ElementGroup,
6
- ElementGroupSnapshot,
7
- } from "@supernova-studio/model";
8
- import * as Y from "yjs";
9
- import { DocumentationHierarchySettings } from "../design-system-content";
10
- import { VersionRoomBaseYDoc } from "./base";
11
-
12
- type DocumentationHierarchyTransaction = {
13
- pages?: DocumentationPageV2[];
14
- pageIdsToDelete?: string[];
15
-
16
- groups?: ElementGroup[];
17
- groupIdsToDelete?: string[];
18
-
19
- pageSnapshots?: DocumentationPageSnapshot[];
20
- pageSnapshotIdsToDelete?: string[];
21
-
22
- groupSnapshots?: ElementGroupSnapshot[];
23
- groupSnapshotIdsToDelete?: string[];
24
-
25
- internalSettings?: Partial<DocumentationHierarchySettings>;
26
-
27
- pageHashesToUpdate?: Record<string, string>;
28
-
29
- pageApprovals?: DocumentationPageApproval[];
30
- pageApprovalIdsToDelete?: string[];
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
- // Page snapshots
53
- transaction.pageSnapshotIdsToDelete && yDoc.deletePageSnapshots(transaction.pageSnapshotIdsToDelete);
54
- transaction.pageSnapshots && yDoc.updatePageSnapshots(transaction.pageSnapshots);
55
-
56
- // Snapshots - published groups
57
- transaction.groupSnapshotIdsToDelete && yDoc.deleteGroupSnapshots(transaction.groupSnapshotIdsToDelete);
58
- transaction.groupSnapshots && yDoc.updateGroupSnapshots(transaction.groupSnapshots);
59
-
60
- // Settings
61
- transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
62
- transaction.pageHashesToUpdate && yDoc.updateDocumentationPageContentHashes(transaction.pageHashesToUpdate);
63
- transaction.pageApprovals && yDoc.updateApprovalStates(transaction.pageApprovals);
64
- transaction.pageApprovalIdsToDelete && yDoc.removeApprovalStates(transaction.pageApprovalIdsToDelete);
65
- });
66
- }
67
-
68
- getDocumentationPageContentHashes() {
69
- const versionDoc = new VersionRoomBaseYDoc(this.yDoc);
70
-
71
- // Limit each hash string by 100 characters
72
- const validHashes = Object.entries(versionDoc.getDocumentationPageContentHashes()).filter(e => {
73
- return e[1].length < 100;
74
- });
75
-
76
- return Object.fromEntries(validHashes);
77
- }
78
- }
@@ -1,226 +0,0 @@
1
- import {
2
- DocumentationPageApproval,
3
- DocumentationPageSnapshot,
4
- DocumentationPageV2,
5
- ElementGroup,
6
- ElementGroupSnapshot,
7
- } from "@supernova-studio/model";
8
- import * as Y from "yjs";
9
- import { ZodSchema, ZodTypeDef } from "zod";
10
- import { DocumentationHierarchySettings } from "../design-system-content";
11
-
12
- type YJSSerializable = { id: string };
13
-
14
- export class VersionRoomBaseYDoc {
15
- private readonly yDoc: Y.Doc;
16
-
17
- constructor(yDoc: Y.Doc) {
18
- this.yDoc = yDoc;
19
- }
20
-
21
- //
22
- // Pages
23
- //
24
-
25
- getPages(): DocumentationPageV2[] {
26
- return this.getObjects(this.pagesYMap, DocumentationPageV2);
27
- }
28
-
29
- updatePages(pages: DocumentationPageV2[]) {
30
- pages = pages.map(page => {
31
- // We remove blocks from the payload here because it will not get parsed anyway
32
- return {
33
- ...page,
34
- data: {
35
- configuration: page.data.configuration,
36
- },
37
- };
38
- });
39
-
40
- this.setObjects(this.pagesYMap, pages);
41
- }
42
-
43
- deletePages(ids: string[]) {
44
- this.deleteObjects(this.pagesYMap, ids);
45
- }
46
-
47
- private get pagesYMap() {
48
- return this.yDoc.getMap<object>("documentationPages");
49
- }
50
-
51
- //
52
- // Groups
53
- //
54
-
55
- getGroups(): ElementGroup[] {
56
- return this.getObjects(this.groupsYMap, ElementGroup);
57
- }
58
-
59
- updateGroups(groups: ElementGroup[]) {
60
- this.setObjects(this.groupsYMap, groups);
61
- }
62
-
63
- deleteGroups(ids: string[]) {
64
- this.deleteObjects(this.groupsYMap, ids);
65
- }
66
-
67
- private get groupsYMap() {
68
- return this.yDoc.getMap<object>("documentationGroups");
69
- }
70
-
71
- //
72
- // Documentation internal settings
73
- //
74
-
75
- getDocumentationInternalSettings(): DocumentationHierarchySettings {
76
- const map = this.internalSettingsYMap;
77
-
78
- const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
79
- routingVersion: map.get("routingVersion"),
80
- isDraftFeatureAdopted: map.get("isDraftFeatureAdopted") ?? false,
81
- isApprovalFeatureEnabled: map.get("isApprovalFeatureEnabled") ?? false,
82
- approvalRequiredForPublishing: map.get("approvalRequiredForPublishing") ?? false,
83
- };
84
-
85
- const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
86
- if (!settingsParseResult.success) {
87
- return {
88
- routingVersion: "2",
89
- isDraftFeatureAdopted: false,
90
- isApprovalFeatureEnabled: false,
91
- approvalRequiredForPublishing: false,
92
- };
93
- }
94
-
95
- return settingsParseResult.data;
96
- }
97
-
98
- updateDocumentationInternalSettings(settings: Partial<DocumentationHierarchySettings>) {
99
- const map = this.internalSettingsYMap;
100
- map.set("routingVersion", settings.routingVersion ?? map.get("routingVersion"));
101
- map.set("isDraftFeatureAdopted", settings.isDraftFeatureAdopted ?? map.get("isDraftFeatureAdopted"));
102
- map.set("isApprovalFeatureEnabled", settings.isApprovalFeatureEnabled ?? map.get("isApprovalFeatureEnabled"));
103
- map.set(
104
- "approvalRequiredForPublishing",
105
- settings.approvalRequiredForPublishing ?? map.get("approvalRequiredForPublishing")
106
- );
107
- }
108
-
109
- private get internalSettingsYMap() {
110
- return this.yDoc.getMap<unknown>("documentationInternalSettings");
111
- }
112
-
113
- //
114
- // Documentation page snapshot
115
- //
116
-
117
- getPageSnapshots(): DocumentationPageSnapshot[] {
118
- return this.getObjects(this.documentationPagePublishedStatesYMap, DocumentationPageSnapshot);
119
- }
120
-
121
- updatePageSnapshots(snapshots: DocumentationPageSnapshot[]) {
122
- this.setObjects(this.documentationPagePublishedStatesYMap, snapshots);
123
- }
124
-
125
- deletePageSnapshots(ids: string[]) {
126
- this.deleteObjects(this.documentationPagePublishedStatesYMap, ids);
127
- }
128
-
129
- private get documentationPagePublishedStatesYMap() {
130
- return this.yDoc.getMap<object>("documentationPageSnapshots");
131
- }
132
-
133
- //
134
- // Documentation group snapshots
135
- //
136
-
137
- getGroupSnapshots(): ElementGroupSnapshot[] {
138
- return this.getObjects(this.documentationGroupPublishedStatesYMap, ElementGroupSnapshot);
139
- }
140
-
141
- updateGroupSnapshots(snapshots: ElementGroupSnapshot[]) {
142
- this.setObjects(this.documentationGroupPublishedStatesYMap, snapshots);
143
- }
144
-
145
- deleteGroupSnapshots(ids: string[]) {
146
- this.deleteObjects(this.documentationGroupPublishedStatesYMap, ids);
147
- }
148
-
149
- private get documentationGroupPublishedStatesYMap() {
150
- return this.yDoc.getMap<object>("documentationGroupSnapshots");
151
- }
152
-
153
- //
154
- // Utils
155
- //
156
-
157
- private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
158
- const results: T[] = [];
159
- map.forEach(object => results.push(schema.parse(object)));
160
- return results;
161
- }
162
-
163
- private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
164
- objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
165
- }
166
-
167
- private deleteObjects(map: Y.Map<object>, ids: string[]) {
168
- ids.forEach(id => map.delete(id));
169
- }
170
-
171
- //
172
- // Documentation page content hashes
173
- //
174
-
175
- getDocumentationPageContentHashes(): Record<string, string> {
176
- const map = this.documentationPageContentHashesYMap;
177
-
178
- const result: Record<string, string> = {};
179
- map.forEach((hash, key) => {
180
- if (typeof hash === "string") result[key] = hash;
181
- });
182
-
183
- return result;
184
- }
185
-
186
- getDocumentationPageLiveblocksRoomIds(): Record<string, string> {
187
- const map = this.documentationPageLiveblocksRoomIdsYMap;
188
-
189
- const result: Record<string, string> = {};
190
- map.forEach((hash, key) => {
191
- if (typeof hash === "string") result[key] = hash;
192
- });
193
-
194
- return result;
195
- }
196
-
197
- private get documentationPageLiveblocksRoomIdsYMap() {
198
- return this.yDoc.getMap<string>("documentationPageLiveblocksRoomIds");
199
- }
200
-
201
- updateDocumentationPageContentHashes(hashes: Record<string, string>) {
202
- const map = this.documentationPageContentHashesYMap;
203
- Object.entries(hashes).forEach(([key, hash]) => map.set(key, hash));
204
- }
205
-
206
- private get documentationPageContentHashesYMap() {
207
- return this.yDoc.getMap<string>("documentationPageHashes");
208
- }
209
-
210
- // Approval states
211
- updateApprovalStates(updates: DocumentationPageApproval[]) {
212
- this.setObjects(this.documentationPageApprovalsMap, updates);
213
- }
214
-
215
- removeApprovalStates(ids: string[]) {
216
- this.deleteObjects(this.documentationPageApprovalsMap, ids);
217
- }
218
-
219
- getApprovals() {
220
- return this.getObjects(this.documentationPageApprovalsMap, DocumentationPageApproval);
221
- }
222
-
223
- private get documentationPageApprovalsMap() {
224
- return this.yDoc.getMap<object>("documentationPageApprovals");
225
- }
226
- }