@supernova-studio/client 0.58.18 → 1.0.0-alpha.2
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 +1349 -1323
- package/dist/index.d.ts +1349 -1323
- package/dist/index.js +462 -329
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +764 -631
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/api/client.ts +0 -31
- package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +0 -114
- package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +0 -92
- package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +0 -52
- package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +0 -34
- package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +0 -131
- package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +0 -69
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +0 -72
- package/src/api/conversion/documentation/index.ts +0 -7
- package/src/api/conversion/export/index.ts +0 -1
- package/src/api/conversion/export/pipeline.ts +0 -25
- package/src/api/conversion/index.ts +0 -3
- package/src/api/conversion/integrations/git.ts +0 -37
- package/src/api/conversion/integrations/index.ts +0 -2
- package/src/api/conversion/integrations/integration.ts +0 -37
- package/src/api/dto/aux/color.ts +0 -7
- package/src/api/dto/aux/index.ts +0 -3
- package/src/api/dto/aux/meta.ts +0 -8
- package/src/api/dto/aux/pagination.ts +0 -8
- package/src/api/dto/bff/app-bootstrap-data.ts +0 -20
- package/src/api/dto/bff/index.ts +0 -1
- package/src/api/dto/collections/index.ts +0 -1
- package/src/api/dto/collections/token-collection.ts +0 -24
- package/src/api/dto/design-systems/brand.ts +0 -44
- package/src/api/dto/design-systems/component.ts +0 -40
- package/src/api/dto/design-systems/contact.ts +0 -11
- package/src/api/dto/design-systems/data-source.ts +0 -141
- package/src/api/dto/design-systems/design-system.ts +0 -68
- package/src/api/dto/design-systems/elements-diff.ts +0 -14
- package/src/api/dto/design-systems/figma-variables.ts +0 -108
- package/src/api/dto/design-systems/import-job.ts +0 -61
- package/src/api/dto/design-systems/index.ts +0 -13
- package/src/api/dto/design-systems/members.ts +0 -50
- package/src/api/dto/design-systems/role.ts +0 -11
- package/src/api/dto/design-systems/stats.ts +0 -19
- package/src/api/dto/design-systems/version.ts +0 -56
- package/src/api/dto/design-systems/view.ts +0 -45
- package/src/api/dto/design-tokens/design-token.ts +0 -78
- package/src/api/dto/design-tokens/index.ts +0 -1
- package/src/api/dto/documentation/anchor.ts +0 -15
- package/src/api/dto/documentation/approvals.ts +0 -15
- package/src/api/dto/documentation/block-definition.ts +0 -28
- package/src/api/dto/documentation/block.ts +0 -6
- package/src/api/dto/documentation/documentation-page-snapshot.ts +0 -18
- package/src/api/dto/documentation/index.ts +0 -8
- package/src/api/dto/documentation/link-preview.ts +0 -23
- package/src/api/dto/documentation/publish.ts +0 -23
- package/src/api/dto/documentation/room.ts +0 -12
- package/src/api/dto/elements/components/figma-component-group.ts +0 -19
- package/src/api/dto/elements/components/figma-component.ts +0 -56
- package/src/api/dto/elements/components/index.ts +0 -2
- package/src/api/dto/elements/documentation/draft-state.ts +0 -37
- package/src/api/dto/elements/documentation/group-action.ts +0 -108
- package/src/api/dto/elements/documentation/group-v1.ts +0 -35
- package/src/api/dto/elements/documentation/group-v2.ts +0 -117
- package/src/api/dto/elements/documentation/hierarchy.ts +0 -22
- package/src/api/dto/elements/documentation/index.ts +0 -13
- package/src/api/dto/elements/documentation/item-configuration-v1.ts +0 -24
- package/src/api/dto/elements/documentation/item-configuration-v2.ts +0 -14
- package/src/api/dto/elements/documentation/metadata.ts +0 -8
- package/src/api/dto/elements/documentation/page-actions-v2.ts +0 -121
- package/src/api/dto/elements/documentation/page-content.ts +0 -15
- package/src/api/dto/elements/documentation/page-v1.ts +0 -21
- package/src/api/dto/elements/documentation/page-v2.ts +0 -120
- package/src/api/dto/elements/documentation/structure.ts +0 -37
- package/src/api/dto/elements/elements-action-v2.ts +0 -104
- package/src/api/dto/elements/figma-nodes/figma-node.ts +0 -106
- package/src/api/dto/elements/figma-nodes/index.ts +0 -2
- package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +0 -24
- package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +0 -17
- package/src/api/dto/elements/frame-node-structures/index.ts +0 -1
- package/src/api/dto/elements/get-elements-v2.ts +0 -21
- package/src/api/dto/elements/index.ts +0 -7
- package/src/api/dto/elements/properties/index.ts +0 -2
- package/src/api/dto/elements/properties/property-definitions.ts +0 -75
- package/src/api/dto/elements/properties/property-values.ts +0 -38
- package/src/api/dto/export/exporter-property.ts +0 -95
- package/src/api/dto/export/exporter.ts +0 -87
- package/src/api/dto/export/filter.ts +0 -6
- package/src/api/dto/export/index.ts +0 -5
- package/src/api/dto/export/job.ts +0 -87
- package/src/api/dto/export/pipeline.ts +0 -43
- package/src/api/dto/figma-components/assets/download.ts +0 -30
- package/src/api/dto/figma-components/assets/index.ts +0 -1
- package/src/api/dto/figma-components/index.ts +0 -1
- package/src/api/dto/index.ts +0 -13
- package/src/api/dto/liveblocks/auth-response.ts +0 -7
- package/src/api/dto/liveblocks/index.ts +0 -1
- package/src/api/dto/themes/index.ts +0 -2
- package/src/api/dto/themes/override.ts +0 -27
- package/src/api/dto/themes/theme.ts +0 -45
- package/src/api/dto/users/authenticated-user.ts +0 -43
- package/src/api/dto/users/index.ts +0 -3
- package/src/api/dto/users/update.ts +0 -8
- package/src/api/dto/users/user.ts +0 -31
- package/src/api/dto/workspaces/git.ts +0 -32
- package/src/api/dto/workspaces/index.ts +0 -6
- package/src/api/dto/workspaces/integrations.ts +0 -34
- package/src/api/dto/workspaces/invitations.ts +0 -30
- package/src/api/dto/workspaces/membership.ts +0 -41
- package/src/api/dto/workspaces/npm-registry.ts +0 -35
- package/src/api/dto/workspaces/workspace.ts +0 -34
- package/src/api/endpoints/codegen/codegen.ts +0 -13
- package/src/api/endpoints/codegen/exporters.ts +0 -13
- package/src/api/endpoints/codegen/index.ts +0 -3
- package/src/api/endpoints/codegen/pipelines.ts +0 -37
- package/src/api/endpoints/design-system/bff.ts +0 -13
- package/src/api/endpoints/design-system/contact.ts +0 -12
- package/src/api/endpoints/design-system/design-systems.ts +0 -55
- package/src/api/endpoints/design-system/index.ts +0 -6
- package/src/api/endpoints/design-system/members.ts +0 -24
- package/src/api/endpoints/design-system/sources.ts +0 -35
- package/src/api/endpoints/design-system/versions/brands.ts +0 -45
- package/src/api/endpoints/design-system/versions/documentation.ts +0 -27
- package/src/api/endpoints/design-system/versions/ds-components.ts +0 -28
- package/src/api/endpoints/design-system/versions/elements-action.ts +0 -55
- package/src/api/endpoints/design-system/versions/elements.ts +0 -13
- package/src/api/endpoints/design-system/versions/figma-component-groups.ts +0 -13
- package/src/api/endpoints/design-system/versions/figma-components.ts +0 -13
- package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +0 -13
- package/src/api/endpoints/design-system/versions/import-jobs.ts +0 -13
- package/src/api/endpoints/design-system/versions/index.ts +0 -18
- package/src/api/endpoints/design-system/versions/overrides.ts +0 -17
- package/src/api/endpoints/design-system/versions/property-definitions.ts +0 -43
- package/src/api/endpoints/design-system/versions/property-values.ts +0 -25
- package/src/api/endpoints/design-system/versions/stats.ts +0 -12
- package/src/api/endpoints/design-system/versions/themes.ts +0 -35
- package/src/api/endpoints/design-system/versions/token-collections.ts +0 -13
- package/src/api/endpoints/design-system/versions/token-groups.ts +0 -28
- package/src/api/endpoints/design-system/versions/tokens.ts +0 -27
- package/src/api/endpoints/design-system/versions/versions.ts +0 -79
- package/src/api/endpoints/index.ts +0 -5
- package/src/api/endpoints/liveblocks.ts +0 -14
- package/src/api/endpoints/users.ts +0 -26
- package/src/api/endpoints/workspaces/index.ts +0 -3
- package/src/api/endpoints/workspaces/workspace-invites.ts +0 -34
- package/src/api/endpoints/workspaces/workspace-members.ts +0 -31
- package/src/api/endpoints/workspaces/workspaces.ts +0 -47
- package/src/api/index.ts +0 -6
- package/src/api/payloads/design-systems/index.ts +0 -2
- package/src/api/payloads/design-systems/update-design-system.ts +0 -29
- package/src/api/payloads/design-systems/version.ts +0 -29
- package/src/api/payloads/documentation/block-definitions.ts +0 -12
- package/src/api/payloads/documentation/design-data-doc-diff.ts +0 -7
- package/src/api/payloads/documentation/index.ts +0 -2
- package/src/api/payloads/export/index.ts +0 -1
- package/src/api/payloads/export/pipeline.ts +0 -50
- package/src/api/payloads/index.ts +0 -6
- package/src/api/payloads/liveblocks/auth.ts +0 -7
- package/src/api/payloads/liveblocks/index.ts +0 -1
- package/src/api/payloads/users/index.ts +0 -2
- package/src/api/payloads/users/notifications/index.ts +0 -1
- package/src/api/payloads/users/notifications/notification-settings.ts +0 -17
- package/src/api/payloads/users/profile/index.ts +0 -1
- package/src/api/payloads/users/profile/update.ts +0 -4
- package/src/api/payloads/workspaces/index.ts +0 -3
- package/src/api/payloads/workspaces/transfer-ownership.ts +0 -7
- package/src/api/payloads/workspaces/workspace-configuration.ts +0 -50
- package/src/api/payloads/workspaces/workspace-integrations.ts +0 -26
- package/src/api/transport/index.ts +0 -2
- package/src/api/transport/request-executor-error.ts +0 -66
- package/src/api/transport/request-executor.ts +0 -87
- package/src/index.ts +0 -3
- package/src/utils/figma.ts +0 -53
- package/src/utils/hash.ts +0 -62
- package/src/utils/index.ts +0 -3
- package/src/utils/query.ts +0 -18
- package/src/yjs/design-system-content/documentation-hierarchy.ts +0 -35
- package/src/yjs/design-system-content/index.ts +0 -2
- package/src/yjs/design-system-content/item-configuration.ts +0 -93
- package/src/yjs/docs-editor/blocks-to-prosemirror.ts +0 -764
- package/src/yjs/docs-editor/index.ts +0 -7
- package/src/yjs/docs-editor/list-tree-builder.ts +0 -127
- package/src/yjs/docs-editor/mock.ts +0 -2104
- package/src/yjs/docs-editor/model/block.ts +0 -8
- package/src/yjs/docs-editor/model/index.ts +0 -2
- package/src/yjs/docs-editor/model/page.ts +0 -8
- package/src/yjs/docs-editor/prosemirror/index.ts +0 -3
- package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +0 -145
- package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +0 -577
- package/src/yjs/docs-editor/prosemirror/types.ts +0 -19
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +0 -975
- package/src/yjs/docs-editor/utils.ts +0 -115
- package/src/yjs/index.ts +0 -3
- package/src/yjs/version-room/backend.ts +0 -78
- package/src/yjs/version-room/base.ts +0 -211
- package/src/yjs/version-room/frontend.ts +0 -461
- package/src/yjs/version-room/index.ts +0 -4
- 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,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,211 +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
|
-
updateDocumentationPageContentHashes(hashes: Record<string, string>) {
|
|
187
|
-
const map = this.documentationPageContentHashesYMap;
|
|
188
|
-
Object.entries(hashes).forEach(([key, hash]) => map.set(key, hash));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private get documentationPageContentHashesYMap() {
|
|
192
|
-
return this.yDoc.getMap<string>("documentationPageHashes");
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Approval states
|
|
196
|
-
updateApprovalStates(updates: DocumentationPageApproval[]) {
|
|
197
|
-
this.setObjects(this.documentationPageApprovalsMap, updates);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
removeApprovalStates(ids: string[]) {
|
|
201
|
-
this.deleteObjects(this.documentationPageApprovalsMap, ids);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
getApprovals() {
|
|
205
|
-
return this.getObjects(this.documentationPageApprovalsMap, DocumentationPageApproval);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private get documentationPageApprovalsMap() {
|
|
209
|
-
return this.yDoc.getMap<object>("documentationPageApprovals");
|
|
210
|
-
}
|
|
211
|
-
}
|