@supernova-studio/model 0.35.0 → 0.37.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/model",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Supernova Data Models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
2
 
3
- export const ProductCodeSchema = z.enum(["free", "team", "team_test", "company", "enterprise"]);
3
+ export const ProductCodeSchema = z.enum(["free", "team", "company", "enterprise"]);
4
4
  export type ProductCode = z.infer<typeof ProductCodeSchema>;
5
5
  export const ProductCode = ProductCodeSchema.enum;
package/src/dsm/brand.ts CHANGED
@@ -1,7 +1,11 @@
1
- export type Brand = {
2
- id: string;
3
- designSystemVersionId: string;
4
- persistentId: string;
5
- name: string;
6
- description: string;
7
- };
1
+ import { z } from "zod";
2
+
3
+ export const Brand = z.object({
4
+ id: z.string(),
5
+ designSystemVersionId: z.string(),
6
+ persistentId: z.string(),
7
+ name: z.string(),
8
+ description: z.string(),
9
+ });
10
+
11
+ export type Brand = z.infer<typeof Brand>;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { PageBlockCalloutType, PageBlockCodeLanguage, PageBlockText } from "./documentation-block-v1";
3
2
  import { DesignTokenType } from "../raw-element";
3
+ import { PageBlockCalloutType, PageBlockCodeLanguage, PageBlockText } from "./documentation-block-v1";
4
4
 
5
5
  //
6
6
  // Enums
@@ -112,17 +112,19 @@ export const PageBlockItemAssetValue = z.object({
112
112
  showSearch: z.boolean().optional(),
113
113
  previewContainerSize: PageBlockPreviewContainerSize.optional(),
114
114
  backgroundColor: PageBlockColorV2.optional(),
115
- value: z.array(
116
- z.object({
117
- entityId: z.string(),
118
- entityType: z.enum(["Asset", "AssetGroup"]),
119
- entityMeta: PageBlockAssetEntityMeta.optional(),
120
- })
121
- ),
115
+ value: z
116
+ .array(
117
+ z.object({
118
+ entityId: z.string(),
119
+ entityType: z.enum(["Asset", "AssetGroup"]),
120
+ entityMeta: PageBlockAssetEntityMeta.optional(),
121
+ })
122
+ )
123
+ .default([]),
122
124
  });
123
125
 
124
126
  export const PageBlockItemAssetPropertyValue = z.object({
125
- value: z.array(z.string()),
127
+ value: z.array(z.string()).default([]),
126
128
  });
127
129
 
128
130
  export const PageBlockItemBooleanValue = z.object({
@@ -148,12 +150,14 @@ export const PageBlockItemColorValue = z.record(z.any());
148
150
 
149
151
  export const PageBlockItemComponentValue = z.object({
150
152
  selectedPropertyIds: z.array(z.string()).optional(),
151
- value: z.array(
152
- z.object({
153
- entityId: z.string(),
154
- entityType: z.enum(["Component", "ComponentGroup"]),
155
- })
156
- ),
153
+ value: z
154
+ .array(
155
+ z.object({
156
+ entityId: z.string(),
157
+ entityType: z.enum(["Component", "ComponentGroup"]),
158
+ })
159
+ )
160
+ .default([]),
157
161
  });
158
162
 
159
163
  export const PageBlockItemComponentPropertyValue = z.object({
@@ -180,12 +184,14 @@ export const PageBlockItemFigmaNodeValue = z.object({
180
184
  previewContainerSize: PageBlockPreviewContainerSize.optional(),
181
185
  backgroundColor: PageBlockColorV2.optional(),
182
186
  showFrameDetails: z.boolean().optional(),
183
- value: z.array(
184
- z.object({
185
- entityId: z.string(),
186
- entityMeta: PageBlockFigmaNodeEntityMeta.optional(),
187
- })
188
- ),
187
+ value: z
188
+ .array(
189
+ z.object({
190
+ entityId: z.string(),
191
+ entityMeta: PageBlockFigmaNodeEntityMeta.optional(),
192
+ })
193
+ )
194
+ .default([]),
189
195
  });
190
196
 
191
197
  export const PageBlockItemImageValue = z.object({
@@ -204,7 +210,7 @@ export const PageBlockItemMultiRichTextValue = z.object({
204
210
  });
205
211
 
206
212
  export const PageBlockItemMultiSelectValue = z.object({
207
- value: z.array(z.string()),
213
+ value: z.array(z.string()).default([]),
208
214
  });
209
215
 
210
216
  export const PageBlockItemNumberValue = z.object({
@@ -223,8 +229,8 @@ export const PageBlockItemSingleSelectValue = z.object({
223
229
  export const PageBlockItemStorybookValue = z.object({
224
230
  caption: z.string().optional(),
225
231
  height: z.number().optional(),
226
- showAddons: z.boolean().optional(),
227
- value: z.string(),
232
+ embedUrl: z.string().optional(),
233
+ value: z.string().optional(),
228
234
  });
229
235
 
230
236
  export const PageBlockItemTextValue = z.object({
@@ -235,27 +241,29 @@ export const PageBlockItemTokenValue = z.object({
235
241
  selectedPropertyIds: z.array(z.string()).optional(),
236
242
  selectedThemeIds: z.array(z.string()).optional(),
237
243
  themeDisplayMode: PageBlockThemeDisplayMode.optional(),
238
- value: z.array(
239
- z.object({
240
- entityId: z.string(),
241
- entityType: z.enum(["Token", "TokenGroup"]),
242
- entityMeta: z
243
- .object({
244
- showNestedGroups: z.boolean().optional(),
245
- })
246
- .optional(),
247
- })
248
- ),
244
+ value: z
245
+ .array(
246
+ z.object({
247
+ entityId: z.string(),
248
+ entityType: z.enum(["Token", "TokenGroup"]),
249
+ entityMeta: z
250
+ .object({
251
+ showNestedGroups: z.boolean().optional(),
252
+ })
253
+ .optional(),
254
+ })
255
+ )
256
+ .default([]),
249
257
  });
250
258
 
251
259
  export const PageBlockItemTokenPropertyValue = z.object({
252
260
  selectedPropertyIds: z.array(z.string()).optional(),
253
261
  selectedThemeIds: z.array(z.string()).optional(),
254
- value: z.array(z.string()),
262
+ value: z.array(z.string()).default([]),
255
263
  });
256
264
 
257
265
  export const PageBlockItemTokenTypeValue = z.object({
258
- value: z.array(DesignTokenType),
266
+ value: z.array(DesignTokenType).default([]),
259
267
  });
260
268
 
261
269
  export const PageBlockItemUrlValue = z.object({
@@ -330,7 +338,7 @@ export const PageBlockItemTableValue = z.object({
330
338
  highlightHeaderColumn: z.boolean().optional(),
331
339
  highlightHeaderRow: z.boolean().optional(),
332
340
  showBorder: z.boolean().optional(),
333
- value: z.array(PageBlockItemTableRow),
341
+ value: z.array(PageBlockItemTableRow).default([]),
334
342
  });
335
343
 
336
344
  export type PageBlockItemTableRichTextNode = z.infer<typeof PageBlockItemTableRichTextNode>;
@@ -11,3 +11,4 @@ export * from "./page-block-v2";
11
11
  export * from "./raw-element";
12
12
  export * from "./theme";
13
13
  export * from "./tokens";
14
+ export * from "./utils";
@@ -0,0 +1,114 @@
1
+ import { DocumentationPageContentItem, PageBlockDefinition, PageBlockDefinitionProperty } from "../documentation";
2
+ import { PageBlockItemUntypedValue, PageBlockItemV2 } from "./data";
3
+ import { PageBlockEditorModelV2 } from "./page-block-v2";
4
+
5
+ //
6
+ // Traverse
7
+ //
8
+
9
+ /**
10
+ * Pay attention to correct types!
11
+ */
12
+ export function mapPageBlockItemValuesV2(
13
+ pageItems: DocumentationPageContentItem[],
14
+ definitionsMap: PageBlockDefinitionsMap,
15
+ fn: (
16
+ block: PageBlockEditorModelV2,
17
+ item: PageBlockItemV2,
18
+ property: PageBlockDefinitionProperty,
19
+ value: PageBlockItemUntypedValue
20
+ ) => PageBlockItemUntypedValue
21
+ ) {
22
+ traversePageBlockItemsV2(pageItems, (block, item) => {
23
+ Object.entries(item.props).forEach(([propKey, value]) => {
24
+ const property = definitionsMap.getDefinitionProperty(block.data.packageId, propKey);
25
+ if (!property) return;
26
+
27
+ item.props[propKey] = fn(block, item, property, value);
28
+ });
29
+ });
30
+ }
31
+
32
+ export function traversePageBlockItemValuesV2(
33
+ pageItems: DocumentationPageContentItem[],
34
+ definitionsMap: PageBlockDefinitionsMap,
35
+ fn: (
36
+ block: PageBlockEditorModelV2,
37
+ item: PageBlockItemV2,
38
+ property: PageBlockDefinitionProperty,
39
+ value: PageBlockItemUntypedValue
40
+ ) => void
41
+ ) {
42
+ traversePageBlockItemsV2(pageItems, (block, item) => {
43
+ Object.entries(item.props).forEach(([propKey, value]) => {
44
+ const property = definitionsMap.getDefinitionProperty(block.data.packageId, propKey);
45
+ if (!property) return;
46
+
47
+ fn(block, item, property, value);
48
+ });
49
+ });
50
+ }
51
+
52
+ export function traversePageBlockItemsV2(
53
+ pageItems: DocumentationPageContentItem[],
54
+ fn: (block: PageBlockEditorModelV2, item: PageBlockItemV2) => void
55
+ ) {
56
+ traversePageItemsV2(pageItems, block => {
57
+ block.data.items.forEach(item => {
58
+ fn(block, item);
59
+ });
60
+ });
61
+ }
62
+
63
+ export function traversePageItemsV2(
64
+ pageItems: DocumentationPageContentItem[],
65
+ fn: (item: PageBlockEditorModelV2) => void
66
+ ): void {
67
+ for (const item of pageItems) {
68
+ switch (item.type) {
69
+ case "Block":
70
+ fn(item);
71
+
72
+ break;
73
+
74
+ case "Section":
75
+ item.items.forEach(i => {
76
+ i.columns.forEach(c => {
77
+ traversePageItemsV2(c.blocks, fn);
78
+ });
79
+ });
80
+
81
+ break;
82
+ }
83
+ }
84
+ }
85
+
86
+ //
87
+ // Definitions map
88
+ //
89
+
90
+ export class PageBlockDefinitionsMap {
91
+ private definitionsMap = new Map<string, PageBlockDefinition>();
92
+ private propertiesMap = new Map<string, PageBlockDefinitionProperty>();
93
+
94
+ constructor(definitions: PageBlockDefinition[]) {
95
+ definitions.forEach(d => {
96
+ this.definitionsMap.set(d.id, d);
97
+ d.item.properties.forEach(p => {
98
+ this.propertiesMap.set(this.propertyKey(d.id, p.id), p);
99
+ });
100
+ });
101
+ }
102
+
103
+ getDefinition(id: string): PageBlockDefinition | undefined {
104
+ return this.definitionsMap.get(id);
105
+ }
106
+
107
+ getDefinitionProperty(defId: string, propId: string): PageBlockDefinitionProperty | undefined {
108
+ return this.propertiesMap.get(this.propertyKey(defId, propId));
109
+ }
110
+
111
+ private propertyKey(defId: string, propId: string): string {
112
+ return `${defId}.${propId}`;
113
+ }
114
+ }
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { DbCreateInputOmit, DbUpdate } from "../../helpers";
3
3
 
4
- export const ElementPropertyType = z.enum(["Text", "Number", "Boolean", "Select", "Generic", "Link", "URL"]);
4
+ export const ElementPropertyTypeSchema = z.enum(["Text", "Number", "Boolean", "Select", "Generic", "Link", "URL"]);
5
5
  export const ElementPropertyTargetType = z.enum(["Token", "Component", "DocumentationPage"]);
6
6
  export const ElementPropertyLinkType = z.enum(["FigmaComponent", "DocumentationPage"]);
7
7
 
@@ -22,13 +22,15 @@ export const ElementPropertyDefinition = z.object({
22
22
  name: z.string(),
23
23
  codeName: z.string(),
24
24
  description: z.string(),
25
- type: ElementPropertyType,
25
+ type: ElementPropertyTypeSchema,
26
26
  targetElementType: ElementPropertyTargetType,
27
- options: z.array(ElementPropertyDefinitionOption).nullish(),
28
- linkElementType: ElementPropertyLinkType.nullish(),
27
+ options: z.array(ElementPropertyDefinitionOption).optional(),
28
+ linkElementType: ElementPropertyLinkType.optional(),
29
29
  });
30
30
 
31
- export type ElementPropertyType = z.infer<typeof ElementPropertyType>;
31
+ export type ElementPropertyType = z.infer<typeof ElementPropertyTypeSchema>;
32
+ export const ElementPropertyType = ElementPropertyTypeSchema.enum;
33
+
32
34
  export type ElementPropertyTargetType = z.infer<typeof ElementPropertyTargetType>;
33
35
  export type ElementPropertyLinkType = z.infer<typeof ElementPropertyLinkType>;
34
36
  export type ColorTokenInlineData = z.infer<typeof ColorTokenInlineData>;
@@ -11,7 +11,7 @@ export const ElementPropertyValue = z.object({
11
11
  numberValue: z.number().nullish(),
12
12
  booleanValue: z.boolean().nullish(),
13
13
  referenceValue: z.string().nullish(),
14
- referenceValuePreview: z.string().nullish(),
14
+ referenceValuePreview: z.string().optional(),
15
15
  });
16
16
 
17
17
  export type ElementPropertyValue = z.infer<typeof ElementPropertyValue>;
@@ -1,14 +1,24 @@
1
- export type DesignSystemVersion = {
2
- id: string;
3
- version: string;
4
- createdAt: Date;
5
- designSystemId: string;
6
- name: string;
7
- comment: string;
8
- isReadonly: boolean;
9
- parentId: string | null;
10
- changeLog: string;
11
-
12
- // TODO Artem
13
- // customProperties: Prisma.JsonValue | null;
14
- };
1
+ import { z } from "zod";
2
+ import { OmitStrict } from "../utils";
3
+ import { DbCreateInputOmit, DbUpdate } from "../helpers";
4
+
5
+ export const DesignSystemVersion = z.object({
6
+ id: z.string(),
7
+ version: z.string(),
8
+ createdAt: z.date(),
9
+ designSystemId: z.string(),
10
+ name: z.string(),
11
+ comment: z.string(),
12
+ isReadonly: z.boolean(),
13
+ changeLog: z.string(),
14
+ parentId: z.string().optional(),
15
+ });
16
+
17
+ export type DesignSystemVersion = z.infer<typeof DesignSystemVersion>;
18
+
19
+ export type CreateDesignSystemVersion = DbCreateInputOmit<DesignSystemVersion>;
20
+
21
+ export type UpdateDesignSystemVersion = OmitStrict<
22
+ DbUpdate<DesignSystemVersion>,
23
+ "designSystemId" | "isReadonly" | "version" | "parentId"
24
+ >;
@@ -1,37 +1,51 @@
1
1
  import { DbCreateInputOmit, DbUpdate } from "../../helpers";
2
2
  import { OmitStrict } from "../../utils";
3
-
4
- export type ElementViewBaseColumnType = "Name" | "Description" | "Value" | "UpdatedAt";
5
-
6
- export type ElementViewColumn =
7
- | ElementViewBasePropertyColumn
8
- | ElementViewPropertyDefinitionColumn
9
- | ElementViewThemeColumn;
10
-
11
- export type ElementViewBasePropertyColumn = ElementViewColumnSharedAttributes & {
12
- type: "BaseProperty";
13
- basePropertyType: ElementViewBaseColumnType;
14
- };
15
-
16
- export type ElementViewPropertyDefinitionColumn = ElementViewColumnSharedAttributes & {
17
- type: "PropertyDefinition";
18
- propertyDefinitionId: string;
19
- };
20
-
21
- export type ElementViewThemeColumn = ElementViewColumnSharedAttributes & {
22
- type: "Theme";
23
- themeId: string;
24
- };
25
-
26
- export type ElementViewColumnSharedAttributes = {
27
- id: string;
28
- persistentId: string;
29
- elementDataViewId: string;
30
- sortPosition: number;
31
- width: number;
32
- };
33
-
34
- export type ElementViewColumnType = ElementViewColumn["type"];
3
+ import { z } from "zod";
4
+
5
+ export const ElementViewBaseColumnType = z.enum(["Name", "Description", "Value", "UpdatedAt"]);
6
+
7
+ export const ElementViewColumnType = z.union([
8
+ z.literal("BaseProperty"),
9
+ z.literal("PropertyDefinition"),
10
+ z.literal("Theme"),
11
+ ]);
12
+
13
+ export const ElementViewColumnSharedAttributes = z.object({
14
+ id: z.string(),
15
+ persistentId: z.string(),
16
+ elementDataViewId: z.string(),
17
+ sortPosition: z.number(),
18
+ width: z.number(),
19
+ });
20
+
21
+ export const ElementViewBasePropertyColumn = ElementViewColumnSharedAttributes.extend({
22
+ type: z.literal("BaseProperty"),
23
+ basePropertyType: ElementViewBaseColumnType,
24
+ });
25
+
26
+ export const ElementViewPropertyDefinitionColumn = ElementViewColumnSharedAttributes.extend({
27
+ type: z.literal("PropertyDefinition"),
28
+ propertyDefinitionId: z.string(),
29
+ });
30
+
31
+ export const ElementViewThemeColumn = ElementViewColumnSharedAttributes.extend({
32
+ type: z.literal("Theme"),
33
+ themeId: z.string(),
34
+ });
35
+
36
+ export const ElementViewColumn = z.discriminatedUnion("type", [
37
+ ElementViewBasePropertyColumn,
38
+ ElementViewPropertyDefinitionColumn,
39
+ ElementViewThemeColumn,
40
+ ]);
41
+
42
+ export type ElementViewBaseColumnType = z.infer<typeof ElementViewBaseColumnType>;
43
+ export type ElementViewBasePropertyColumn = z.infer<typeof ElementViewBasePropertyColumn>;
44
+ export type ElementViewPropertyDefinitionColumn = z.infer<typeof ElementViewPropertyDefinitionColumn>;
45
+ export type ElementViewThemeColumn = z.infer<typeof ElementViewThemeColumn>;
46
+ export type ElementViewColumn = z.infer<typeof ElementViewColumn>;
47
+ export type ElementViewColumnSharedAttributes = z.infer<typeof ElementViewColumnSharedAttributes>;
48
+ export type ElementViewColumnType = z.infer<typeof ElementViewColumn>["type"];
35
49
 
36
50
  export type CreateElementViewColumn =
37
51
  | DbCreateInputOmit<ElementViewBasePropertyColumn>
@@ -1,11 +1,14 @@
1
1
  import { ElementPropertyTargetType } from "../properties";
2
+ import { z } from "zod";
2
3
 
3
- export type ElementView = {
4
- id: string;
5
- persistentId: string;
6
- designSystemVersionId: string;
7
- name: string;
8
- description: string;
9
- targetElementType: ElementPropertyTargetType;
10
- isDefault: boolean;
11
- };
4
+ export const ElementView = z.object({
5
+ id: z.string(),
6
+ persistentId: z.string(),
7
+ designSystemVersionId: z.string(),
8
+ name: z.string(),
9
+ description: z.string(),
10
+ targetElementType: ElementPropertyTargetType,
11
+ isDefault: z.boolean(),
12
+ });
13
+
14
+ export type ElementView = z.infer<typeof ElementView>;