@supernova-studio/client 0.13.0 → 0.14.0

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.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+
3
+ import { DocumentationItemConfiguration } from "@supernova-studio/model";
4
+
5
+ //
6
+ // Documentation Pages
7
+ //
8
+
9
+ export const DTOCreateDocumentationPageInput = z.object({
10
+ parentPersistentId: z.string().uuid(),
11
+ persistentId: z.string().uuid(),
12
+ title: z.string(),
13
+ configuration: DocumentationItemConfiguration.optional(),
14
+ afterPersistentId: z.string().uuid().optional(),
15
+ });
16
+
17
+ export const DTOUpdateDocumentationPageInput = z.object({
18
+ id: z.string(),
19
+ title: z.string().optional(),
20
+ configuration: DocumentationItemConfiguration.optional(),
21
+ parentPersistentId: z.string().optional(),
22
+ afterPersistentId: z.string().optional(),
23
+ });
24
+
25
+ export const DTODuplicateDocumentationPageInput = z.object({
26
+ id: z.string(),
27
+ persistentId: z.string().uuid(),
28
+ parentPersistentId: z.string().uuid(),
29
+ afterPersistentId: z.string().uuid().optional(),
30
+ });
31
+
32
+ export const DTODocumentationTransactionInput = z.object({
33
+ create: z.array(DTOCreateDocumentationPageInput).optional(),
34
+ update: z.array(DTOUpdateDocumentationPageInput).optional(),
35
+ duplicate: z.array(DTODuplicateDocumentationPageInput).optional(),
36
+ delete: z.array(z.string()).optional(),
37
+ });
38
+
39
+ export type DTOCreateDocumentationPageInput = z.infer<typeof DTOCreateDocumentationPageInput>;
40
+ export type DTOUpdateDocumentationPageInput = z.infer<typeof DTOUpdateDocumentationPageInput>;
41
+ export type DTODuplicateDocumentationPageInput = z.infer<typeof DTODuplicateDocumentationPageInput>;
42
+
43
+ export type DTODocumentationTransactionInput = z.infer<typeof DTODocumentationTransactionInput>;
44
+
45
+ //
46
+ // Transaction
47
+ //
48
+
49
+ export const DTOElementsTransactionInput = z.object({
50
+ documentationPages: DTODocumentationTransactionInput,
51
+ });
52
+
53
+ export type DTOElementsTransactionInput = z.infer<typeof DTOElementsTransactionInput>;
@@ -0,0 +1 @@
1
+ export * from "./elements-transaction-v2";
@@ -1,2 +1,2 @@
1
- export * from "./post-bulk-doc-page-elements";
1
+ export * from "./elements";
2
2
  export * from "./post-liveblocks-auth";
@@ -0,0 +1,11 @@
1
+ import { DocumentationPageV2DTO } from "../../dto";
2
+
3
+ export type DTODocumentationElementsTransactionOutput = {
4
+ created: DocumentationPageV2DTO[];
5
+ updated: DocumentationPageV2DTO[];
6
+ deleted: string[];
7
+ };
8
+
9
+ export type DTOElementsTransactionOutput = {
10
+ documentationPages: DTODocumentationElementsTransactionOutput;
11
+ };
@@ -0,0 +1 @@
1
+ export * from "./elements-transaction-v2";
@@ -1 +1,2 @@
1
+ export * from "./elements";
1
2
  export * from "./get-block-definitions";
@@ -2,14 +2,37 @@ import * as Y from "yjs";
2
2
  import { DocumentationHierarchyV2DTO, DocumentationPageStructureV2DTO } from "../api/dto/documentation-v2";
3
3
  import { DocumentationGroupStructureDTO } from "../api";
4
4
 
5
- export function documentationHierarchyToYjs(documentationHierarchy: DocumentationHierarchyV2DTO, doc: Y.Doc) {
5
+ //
6
+ // Types
7
+ //
8
+
9
+ type ItemsToDelete = {
10
+ pagePersistentIdsToDelete: string[];
11
+ groupPersistentIdsToDelete: string[];
12
+ };
13
+
14
+ //
15
+ // Init
16
+ //
17
+
18
+ export function documentationHierarchyToYjs(
19
+ doc: Y.Doc,
20
+ documentationHierarchy: DocumentationHierarchyV2DTO,
21
+ itemsToDelete: ItemsToDelete
22
+ ) {
6
23
  doc.transact(trx => {
7
- const pagesMap = trx.doc.getMap("documentationPages");
24
+ const pagesMap = getPagesYMap(trx.doc);
25
+ itemsToDelete.pagePersistentIdsToDelete.forEach(persistentId => {
26
+ pagesMap.delete(persistentId);
27
+ });
8
28
  documentationHierarchy.pages.forEach(page => {
9
29
  pagesMap.set(page.persistentId, page);
10
30
  });
11
31
 
12
- const groupsMap = trx.doc.getMap("documentationGroups");
32
+ const groupsMap = getGroupsYMap(trx.doc);
33
+ itemsToDelete.groupPersistentIdsToDelete.forEach(persistentId => {
34
+ groupsMap.delete(persistentId);
35
+ });
13
36
  documentationHierarchy.groups.forEach(group => {
14
37
  groupsMap.set(group.persistentId, group);
15
38
  });
@@ -19,8 +42,8 @@ export function documentationHierarchyToYjs(documentationHierarchy: Documentatio
19
42
  }
20
43
 
21
44
  export function yjsToDocumentationHierarchy(doc: Y.Doc): DocumentationHierarchyV2DTO {
22
- const pagesMap = doc.getMap("documentationPages");
23
- const groupsMap = doc.getMap("documentationGroups");
45
+ const pagesMap = getPagesYMap(doc);
46
+ const groupsMap = getGroupsYMap(doc);
24
47
 
25
48
  const pages: DocumentationPageStructureV2DTO[] = [];
26
49
  pagesMap.forEach(page => {
@@ -38,4 +61,14 @@ export function yjsToDocumentationHierarchy(doc: Y.Doc): DocumentationHierarchyV
38
61
  };
39
62
  }
40
63
 
41
- // TODO Update page and update group
64
+ //
65
+ // Internals
66
+ //
67
+
68
+ function getPagesYMap(doc: Y.Doc) {
69
+ return doc.getMap<DocumentationPageStructureV2DTO>("documentationPages");
70
+ }
71
+
72
+ function getGroupsYMap(doc: Y.Doc) {
73
+ return doc.getMap<DocumentationGroupStructureDTO>("documentationGroups");
74
+ }
@@ -5,7 +5,7 @@ type UpdateDocumentationItemConfiguration = Partial<DocumentationItemConfigurati
5
5
  header?: Partial<DocumentationItemHeader>;
6
6
  };
7
7
 
8
- export function itemConfigurationToYjs(item: UpdateDocumentationItemConfiguration, yDoc: Y.Doc) {
8
+ export function itemConfigurationToYjs(yDoc: Y.Doc, item: UpdateDocumentationItemConfiguration) {
9
9
  yDoc.transact(trx => {
10
10
  const header = item.header;
11
11
 
@@ -1,47 +0,0 @@
1
- import { z } from "zod";
2
-
3
- import { DocumentationItemConfiguration } from "@supernova-studio/model";
4
-
5
- export const CreateBulkElementsInput = z.object({
6
- parentPersistentId: z.string().uuid(),
7
- persistentId: z.string().uuid(),
8
- title: z.string(),
9
- configuration: DocumentationItemConfiguration.optional(),
10
- afterPersistentId: z.string().uuid().optional(),
11
- });
12
-
13
- export type CreateBulkElementsInput = z.infer<typeof CreateBulkElementsInput>;
14
-
15
- export const UpdateBulkElementsInput = z.object({
16
- id: z.string(),
17
- title: z.string().optional(),
18
- configuration: DocumentationItemConfiguration.optional(),
19
- parentPersistentId: z.string().optional(),
20
- afterPersistentId: z.string().optional(),
21
- });
22
-
23
- export type UpdateBulkElementsInput = z.infer<typeof UpdateBulkElementsInput>;
24
-
25
- export const DeleteBulkElementsInput = z.array(z.string());
26
-
27
- export type DeleteBulkElementsInput = z.infer<typeof DeleteBulkElementsInput>;
28
-
29
- export const DuplicateBulkElementsInput = z.object({
30
- id: z.string(),
31
- persistentId: z.string().uuid(),
32
- parentPersistentId: z.string().uuid(),
33
- afterPersistentId: z.string().uuid().optional(),
34
- });
35
-
36
- export type DuplicateBulkElementsInput = z.infer<typeof DuplicateBulkElementsInput>;
37
-
38
- export const BulkEditDocPageElementsInput = z.object({
39
- documentationPages: z.object({
40
- create: z.array(CreateBulkElementsInput).optional(),
41
- update: z.array(UpdateBulkElementsInput).optional(),
42
- delete: DeleteBulkElementsInput.optional(),
43
- duplicate: z.array(DuplicateBulkElementsInput).optional(),
44
- }),
45
- });
46
-
47
- export type BulkEditDocPageElementsInput = z.infer<typeof BulkEditDocPageElementsInput>;