@supernova-studio/client 0.59.12 → 1.0.0-alpha.11

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 (204) hide show
  1. package/dist/index.d.mts +1592 -1952
  2. package/dist/index.d.ts +1592 -1952
  3. package/dist/index.js +865 -392
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +2569 -2096
  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 -15
  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-room.ts +0 -12
  45. package/src/api/dto/design-systems/version.ts +0 -56
  46. package/src/api/dto/design-systems/view.ts +0 -45
  47. package/src/api/dto/design-tokens/design-token.ts +0 -78
  48. package/src/api/dto/design-tokens/index.ts +0 -1
  49. package/src/api/dto/documentation/anchor.ts +0 -15
  50. package/src/api/dto/documentation/approvals.ts +0 -15
  51. package/src/api/dto/documentation/block-definition.ts +0 -28
  52. package/src/api/dto/documentation/block.ts +0 -6
  53. package/src/api/dto/documentation/documentation-page-snapshot.ts +0 -18
  54. package/src/api/dto/documentation/index.ts +0 -8
  55. package/src/api/dto/documentation/link-preview.ts +0 -23
  56. package/src/api/dto/documentation/publish.ts +0 -23
  57. package/src/api/dto/documentation/room.ts +0 -12
  58. package/src/api/dto/elements/components/figma-component-group.ts +0 -19
  59. package/src/api/dto/elements/components/figma-component.ts +0 -56
  60. package/src/api/dto/elements/components/index.ts +0 -2
  61. package/src/api/dto/elements/documentation/draft-state.ts +0 -37
  62. package/src/api/dto/elements/documentation/group-action.ts +0 -108
  63. package/src/api/dto/elements/documentation/group-v1.ts +0 -35
  64. package/src/api/dto/elements/documentation/group-v2.ts +0 -117
  65. package/src/api/dto/elements/documentation/hierarchy.ts +0 -22
  66. package/src/api/dto/elements/documentation/index.ts +0 -13
  67. package/src/api/dto/elements/documentation/item-configuration-v1.ts +0 -24
  68. package/src/api/dto/elements/documentation/item-configuration-v2.ts +0 -14
  69. package/src/api/dto/elements/documentation/metadata.ts +0 -8
  70. package/src/api/dto/elements/documentation/page-actions-v2.ts +0 -121
  71. package/src/api/dto/elements/documentation/page-content.ts +0 -15
  72. package/src/api/dto/elements/documentation/page-v1.ts +0 -21
  73. package/src/api/dto/elements/documentation/page-v2.ts +0 -123
  74. package/src/api/dto/elements/documentation/structure.ts +0 -37
  75. package/src/api/dto/elements/elements-action-v2.ts +0 -117
  76. package/src/api/dto/elements/figma-nodes/figma-node-v1.ts +0 -32
  77. package/src/api/dto/elements/figma-nodes/figma-node-v2.ts +0 -32
  78. package/src/api/dto/elements/figma-nodes/figma-node.ts +0 -103
  79. package/src/api/dto/elements/figma-nodes/index.ts +0 -4
  80. package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +0 -44
  81. package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +0 -17
  82. package/src/api/dto/elements/frame-node-structures/index.ts +0 -1
  83. package/src/api/dto/elements/get-elements-v2.ts +0 -27
  84. package/src/api/dto/elements/index.ts +0 -7
  85. package/src/api/dto/elements/properties/index.ts +0 -2
  86. package/src/api/dto/elements/properties/property-definitions.ts +0 -75
  87. package/src/api/dto/elements/properties/property-values.ts +0 -38
  88. package/src/api/dto/export/exporter-property.ts +0 -105
  89. package/src/api/dto/export/exporter.ts +0 -87
  90. package/src/api/dto/export/filter.ts +0 -6
  91. package/src/api/dto/export/index.ts +0 -5
  92. package/src/api/dto/export/job.ts +0 -96
  93. package/src/api/dto/export/pipeline.ts +0 -43
  94. package/src/api/dto/figma-components/assets/download.ts +0 -30
  95. package/src/api/dto/figma-components/assets/index.ts +0 -1
  96. package/src/api/dto/figma-components/index.ts +0 -1
  97. package/src/api/dto/index.ts +0 -13
  98. package/src/api/dto/liveblocks/auth-response.ts +0 -7
  99. package/src/api/dto/liveblocks/index.ts +0 -1
  100. package/src/api/dto/themes/index.ts +0 -2
  101. package/src/api/dto/themes/override.ts +0 -27
  102. package/src/api/dto/themes/theme.ts +0 -45
  103. package/src/api/dto/users/authenticated-user.ts +0 -46
  104. package/src/api/dto/users/index.ts +0 -3
  105. package/src/api/dto/users/update.ts +0 -8
  106. package/src/api/dto/users/user.ts +0 -31
  107. package/src/api/dto/workspaces/git.ts +0 -32
  108. package/src/api/dto/workspaces/index.ts +0 -6
  109. package/src/api/dto/workspaces/integrations.ts +0 -34
  110. package/src/api/dto/workspaces/invitations.ts +0 -30
  111. package/src/api/dto/workspaces/membership.ts +0 -41
  112. package/src/api/dto/workspaces/npm-registry.ts +0 -35
  113. package/src/api/dto/workspaces/workspace.ts +0 -34
  114. package/src/api/endpoints/codegen/codegen.ts +0 -16
  115. package/src/api/endpoints/codegen/exporters.ts +0 -25
  116. package/src/api/endpoints/codegen/index.ts +0 -4
  117. package/src/api/endpoints/codegen/jobs.ts +0 -15
  118. package/src/api/endpoints/codegen/pipelines.ts +0 -44
  119. package/src/api/endpoints/design-system/bff.ts +0 -13
  120. package/src/api/endpoints/design-system/contact.ts +0 -12
  121. package/src/api/endpoints/design-system/design-systems.ts +0 -55
  122. package/src/api/endpoints/design-system/index.ts +0 -6
  123. package/src/api/endpoints/design-system/members.ts +0 -24
  124. package/src/api/endpoints/design-system/sources.ts +0 -35
  125. package/src/api/endpoints/design-system/versions/brands.ts +0 -45
  126. package/src/api/endpoints/design-system/versions/documentation.ts +0 -27
  127. package/src/api/endpoints/design-system/versions/ds-components.ts +0 -28
  128. package/src/api/endpoints/design-system/versions/elements-action.ts +0 -63
  129. package/src/api/endpoints/design-system/versions/elements.ts +0 -27
  130. package/src/api/endpoints/design-system/versions/figma-component-groups.ts +0 -13
  131. package/src/api/endpoints/design-system/versions/figma-components.ts +0 -13
  132. package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +0 -13
  133. package/src/api/endpoints/design-system/versions/import-jobs.ts +0 -13
  134. package/src/api/endpoints/design-system/versions/index.ts +0 -18
  135. package/src/api/endpoints/design-system/versions/overrides.ts +0 -17
  136. package/src/api/endpoints/design-system/versions/property-definitions.ts +0 -43
  137. package/src/api/endpoints/design-system/versions/property-values.ts +0 -25
  138. package/src/api/endpoints/design-system/versions/stats.ts +0 -12
  139. package/src/api/endpoints/design-system/versions/themes.ts +0 -35
  140. package/src/api/endpoints/design-system/versions/token-collections.ts +0 -13
  141. package/src/api/endpoints/design-system/versions/token-groups.ts +0 -28
  142. package/src/api/endpoints/design-system/versions/tokens.ts +0 -27
  143. package/src/api/endpoints/design-system/versions/versions.ts +0 -87
  144. package/src/api/endpoints/index.ts +0 -5
  145. package/src/api/endpoints/liveblocks.ts +0 -14
  146. package/src/api/endpoints/users.ts +0 -26
  147. package/src/api/endpoints/workspaces/index.ts +0 -3
  148. package/src/api/endpoints/workspaces/workspace-invites.ts +0 -34
  149. package/src/api/endpoints/workspaces/workspace-members.ts +0 -31
  150. package/src/api/endpoints/workspaces/workspaces.ts +0 -47
  151. package/src/api/index.ts +0 -6
  152. package/src/api/payloads/design-systems/index.ts +0 -2
  153. package/src/api/payloads/design-systems/update-design-system.ts +0 -29
  154. package/src/api/payloads/design-systems/version.ts +0 -29
  155. package/src/api/payloads/documentation/block-definitions.ts +0 -12
  156. package/src/api/payloads/documentation/design-data-doc-diff.ts +0 -7
  157. package/src/api/payloads/documentation/index.ts +0 -2
  158. package/src/api/payloads/export/index.ts +0 -1
  159. package/src/api/payloads/export/pipeline.ts +0 -74
  160. package/src/api/payloads/index.ts +0 -6
  161. package/src/api/payloads/liveblocks/auth.ts +0 -7
  162. package/src/api/payloads/liveblocks/index.ts +0 -1
  163. package/src/api/payloads/users/index.ts +0 -2
  164. package/src/api/payloads/users/notifications/index.ts +0 -1
  165. package/src/api/payloads/users/notifications/notification-settings.ts +0 -17
  166. package/src/api/payloads/users/profile/index.ts +0 -1
  167. package/src/api/payloads/users/profile/update.ts +0 -4
  168. package/src/api/payloads/workspaces/index.ts +0 -3
  169. package/src/api/payloads/workspaces/transfer-ownership.ts +0 -7
  170. package/src/api/payloads/workspaces/workspace-configuration.ts +0 -50
  171. package/src/api/payloads/workspaces/workspace-integrations.ts +0 -26
  172. package/src/api/transport/index.ts +0 -2
  173. package/src/api/transport/request-executor-error.ts +0 -66
  174. package/src/api/transport/request-executor.ts +0 -87
  175. package/src/events/design-system.ts +0 -21
  176. package/src/events/event.ts +0 -6
  177. package/src/events/index.ts +0 -2
  178. package/src/index.ts +0 -4
  179. package/src/utils/figma.ts +0 -72
  180. package/src/utils/hash.ts +0 -62
  181. package/src/utils/index.ts +0 -3
  182. package/src/utils/query.ts +0 -18
  183. package/src/yjs/design-system-content/documentation-hierarchy.ts +0 -35
  184. package/src/yjs/design-system-content/index.ts +0 -2
  185. package/src/yjs/design-system-content/item-configuration.ts +0 -93
  186. package/src/yjs/docs-editor/blocks-to-prosemirror.ts +0 -764
  187. package/src/yjs/docs-editor/index.ts +0 -7
  188. package/src/yjs/docs-editor/list-tree-builder.ts +0 -127
  189. package/src/yjs/docs-editor/mock.ts +0 -2142
  190. package/src/yjs/docs-editor/model/block.ts +0 -8
  191. package/src/yjs/docs-editor/model/index.ts +0 -2
  192. package/src/yjs/docs-editor/model/page.ts +0 -8
  193. package/src/yjs/docs-editor/prosemirror/index.ts +0 -3
  194. package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +0 -145
  195. package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +0 -577
  196. package/src/yjs/docs-editor/prosemirror/types.ts +0 -19
  197. package/src/yjs/docs-editor/prosemirror-to-blocks.ts +0 -975
  198. package/src/yjs/docs-editor/utils.ts +0 -115
  199. package/src/yjs/index.ts +0 -3
  200. package/src/yjs/version-room/backend.ts +0 -83
  201. package/src/yjs/version-room/base.ts +0 -252
  202. package/src/yjs/version-room/frontend.ts +0 -463
  203. package/src/yjs/version-room/index.ts +0 -4
  204. 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,83 +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
- executedTransactionIds?: string[];
33
- };
34
-
35
- export class BackendVersionRoomYDoc {
36
- private readonly yDoc: Y.Doc;
37
-
38
- constructor(yDoc: Y.Doc) {
39
- this.yDoc = yDoc;
40
- }
41
-
42
- updateDocumentationHierarchy(transaction: DocumentationHierarchyTransaction) {
43
- this.yDoc.transact(trx => {
44
- const yDoc = new VersionRoomBaseYDoc(trx.doc);
45
-
46
- // Pages
47
- transaction.pageIdsToDelete && yDoc.deletePages(transaction.pageIdsToDelete);
48
- transaction.pages && yDoc.updatePages(transaction.pages);
49
-
50
- // Groups
51
- transaction.groupIdsToDelete && yDoc.deleteGroups(transaction.groupIdsToDelete);
52
- transaction.groups && yDoc.updateGroups(transaction.groups);
53
-
54
- // Page snapshots
55
- transaction.pageSnapshotIdsToDelete && yDoc.deletePageSnapshots(transaction.pageSnapshotIdsToDelete);
56
- transaction.pageSnapshots && yDoc.updatePageSnapshots(transaction.pageSnapshots);
57
-
58
- // Snapshots - published groups
59
- transaction.groupSnapshotIdsToDelete && yDoc.deleteGroupSnapshots(transaction.groupSnapshotIdsToDelete);
60
- transaction.groupSnapshots && yDoc.updateGroupSnapshots(transaction.groupSnapshots);
61
-
62
- // Settings
63
- transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
64
- transaction.pageHashesToUpdate && yDoc.updateDocumentationPageContentHashes(transaction.pageHashesToUpdate);
65
- transaction.pageApprovals && yDoc.updateApprovalStates(transaction.pageApprovals);
66
- transaction.pageApprovalIdsToDelete && yDoc.removeApprovalStates(transaction.pageApprovalIdsToDelete);
67
-
68
- // Executed transaction ids
69
- transaction.executedTransactionIds && yDoc.updateExecutedTransactionIds(transaction.executedTransactionIds);
70
- });
71
- }
72
-
73
- getDocumentationPageContentHashes() {
74
- const versionDoc = new VersionRoomBaseYDoc(this.yDoc);
75
-
76
- // Limit each hash string by 100 characters
77
- const validHashes = Object.entries(versionDoc.getDocumentationPageContentHashes()).filter(e => {
78
- return e[1].length < 100;
79
- });
80
-
81
- return Object.fromEntries(validHashes);
82
- }
83
- }
@@ -1,252 +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
- //
211
- // Approval states
212
- //
213
-
214
- updateApprovalStates(updates: DocumentationPageApproval[]) {
215
- this.setObjects(this.documentationPageApprovalsMap, updates);
216
- }
217
-
218
- removeApprovalStates(ids: string[]) {
219
- this.deleteObjects(this.documentationPageApprovalsMap, ids);
220
- }
221
-
222
- getApprovals() {
223
- return this.getObjects(this.documentationPageApprovalsMap, DocumentationPageApproval);
224
- }
225
-
226
- private get documentationPageApprovalsMap() {
227
- return this.yDoc.getMap<object>("documentationPageApprovals");
228
- }
229
-
230
- //
231
- // Executed transactions
232
- //
233
-
234
- updateExecutedTransactionIds(transactionIds: string[]) {
235
- transactionIds = Array.from(new Set(transactionIds));
236
- if (!transactionIds.length) return;
237
-
238
- const array = this.executedTransactionIdsArray;
239
-
240
- // Append transactions at the end
241
- array.push(transactionIds);
242
-
243
- // Trim from the beginning in case it contains more than 100
244
- if (array.length > 100) {
245
- array.delete(0, array.length - 100);
246
- }
247
- }
248
-
249
- private get executedTransactionIdsArray() {
250
- return this.yDoc.getArray<unknown>("executedTransactionIds");
251
- }
252
- }