@supernova-studio/model 0.4.1 → 0.5.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.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Supernova Data Models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,8 @@
25
25
  "build": "tsup",
26
26
  "typecheck": "tsc --noEmit",
27
27
  "publish": "npm run build && npm publish",
28
- "test:unit": "vitest run"
28
+ "test:unit": "vitest run",
29
+ "index": "node ./create-indexes.js"
29
30
  },
30
31
  "author": "",
31
32
  "license": "ISC",
@@ -1,4 +1,4 @@
1
- import { ZodSchema, z } from "zod";
1
+ import { ZodSchema, ZodTypeDef, z } from "zod";
2
2
 
3
3
  export const TokenDataAliasSchema = z.object({
4
4
  aliasTo: z
@@ -8,11 +8,11 @@ export const TokenDataAliasSchema = z.object({
8
8
  .transform(v => v ?? undefined),
9
9
  });
10
10
 
11
- export function tokenAliasOrValue<T extends ZodSchema>(value: T) {
11
+ export function tokenAliasOrValue<I, O>(value: ZodSchema<I, ZodTypeDef, O>) {
12
12
  return TokenDataAliasSchema.extend({
13
13
  value: value
14
14
  .optional()
15
15
  .nullable()
16
- .transform(v => (v ?? undefined) as z.output<T> | undefined),
16
+ .transform(v => (v ?? undefined) as z.output<typeof value> | undefined),
17
17
  });
18
18
  }
@@ -181,6 +181,7 @@ export const PageBlockItemTextValue = z.object({
181
181
  export const PageBlockItemTokenValue = z.object({
182
182
  selectedPropertyIds: z.array(z.string()).optional(),
183
183
  selectedThemeIds: z.array(z.string()).optional(),
184
+ themeDisplayMode: z.enum(["Split", "Override"]).optional(),
184
185
  value: z.array(
185
186
  z.object({
186
187
  entityId: z.string(),
@@ -1,8 +1,9 @@
1
1
  import { z } from "zod";
2
+ import { DocumentationItemHeader } from "./item-header";
2
3
 
3
4
  export const DocumentationItemConfiguration = z.object({
4
5
  showSidebar: z.boolean(),
5
- header: z.any(),
6
+ header: DocumentationItemHeader,
6
7
  });
7
8
 
8
9
  export type DocumentationItemConfiguration = z.infer<typeof DocumentationItemConfiguration>;
@@ -19,12 +19,15 @@ export * from "./font-size";
19
19
  export * from "./font-weight";
20
20
  export * from "./gradient";
21
21
  export * from "./group";
22
+ export * from "./item-header";
22
23
  export * from "./letter-spacing";
23
24
  export * from "./line-height";
24
25
  export * from "./opacity";
26
+ export * from "./page-asset";
25
27
  export * from "./paragraph-indent";
26
28
  export * from "./paragraph-spacing";
27
29
  export * from "./product-copy";
30
+ export * from "./safe-id";
28
31
  export * from "./shadow";
29
32
  export * from "./size";
30
33
  export * from "./space";
@@ -0,0 +1,49 @@
1
+ import { z } from "zod";
2
+ import { DocumentationPageAsset } from "./page-asset";
3
+ import { ColorTokenData } from "./color";
4
+
5
+ //
6
+ // Consts
7
+ //
8
+
9
+ export const colorValueRegex = /^#[a-f0-9]{8}$/;
10
+ export const colorValueFormatDescription = "Must match /^#[a-f0-9]{8}$/";
11
+
12
+ //
13
+ // Enums
14
+ //
15
+
16
+ export const DocumentationItemHeaderAlignmentSchema = z.enum(["Left", "Center"]);
17
+ export const DocumentationItemHeaderImageScaleTypeSchema = z.enum(["AspectFill", "AspectFit"]);
18
+
19
+ export const DocumentationItemHeaderAlignment = DocumentationItemHeaderAlignmentSchema.enum;
20
+ export const DocumentationItemHeaderImageScaleType = DocumentationItemHeaderImageScaleTypeSchema.enum;
21
+
22
+ export type DocumentationItemHeaderImageScaleType = z.infer<typeof DocumentationItemHeaderImageScaleTypeSchema>;
23
+ export type DocumentationItemHeaderAlignment = z.infer<typeof DocumentationItemHeaderAlignmentSchema>;
24
+
25
+ //
26
+ // Definitions
27
+ //
28
+
29
+ export const DocumentationItemHeader = z.object({
30
+ description: z.string(),
31
+ alignment: DocumentationItemHeaderAlignmentSchema,
32
+ foregroundColor: ColorTokenData.nullish(),
33
+ backgroundColor: ColorTokenData.nullish(),
34
+ backgroundImageAsset: DocumentationPageAsset.nullish(),
35
+ backgroundImageScaleType: DocumentationItemHeaderImageScaleTypeSchema,
36
+ showBackgroundOverlay: z.boolean(),
37
+ showCoverText: z.boolean(),
38
+ minHeight: z.number().nullish(),
39
+ });
40
+
41
+ export type DocumentationItemHeader = z.infer<typeof DocumentationItemHeader>;
42
+
43
+ export const defaultDocumentationItemHeader: DocumentationItemHeader = {
44
+ alignment: DocumentationItemHeaderAlignment.Left,
45
+ backgroundImageScaleType: DocumentationItemHeaderImageScaleType.AspectFill,
46
+ description: "",
47
+ showBackgroundOverlay: false,
48
+ showCoverText: true,
49
+ };
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ import { SafeIdSchema } from "./safe-id";
3
+ import { PageBlockFrame } from "./documentation-block-v1";
4
+
5
+ export const DocumentationPageAssetType = z.enum(["image", "figmaFrame"]);
6
+ export type DocumentationPageAssetType = z.infer<typeof DocumentationPageAssetType>;
7
+
8
+ export const DocumentationPageImageAsset = z.object({
9
+ type: z.literal(DocumentationPageAssetType.Enum.image),
10
+ url: z.string().url().optional(),
11
+ id: SafeIdSchema,
12
+ });
13
+
14
+ export const DocumentationPageFrameAsset = z.object({
15
+ type: z.literal(DocumentationPageAssetType.Enum.figmaFrame),
16
+ url: z.string().url().optional(),
17
+ figmaFrame: PageBlockFrame,
18
+ });
19
+
20
+ export const DocumentationPageAsset = z.discriminatedUnion("type", [
21
+ DocumentationPageImageAsset,
22
+ DocumentationPageFrameAsset,
23
+ ]);
24
+
25
+ export type DocumentationPageImageAsset = z.infer<typeof DocumentationPageImageAsset>;
26
+ export type DocumentationPageFrameAsset = z.infer<typeof DocumentationPageFrameAsset>;
27
+ export type DocumentationPageAsset = z.infer<typeof DocumentationPageAsset>;
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ const RESERVED_OBJECT_ID_PREFIX = "x-sn-reserved-";
4
+
5
+ // Really only checks if the schema does not have the reserved prefix
6
+ export const SafeIdSchema = z.string().refine(
7
+ value => {
8
+ return !value.startsWith(RESERVED_OBJECT_ID_PREFIX);
9
+ },
10
+ {
11
+ message: `ID value can't start with ${RESERVED_OBJECT_ID_PREFIX}`,
12
+ }
13
+ );
@@ -14,17 +14,3 @@ export type DocumentationPageV1 = z.infer<typeof DocumentationPageV1>;
14
14
 
15
15
  export type CreateDocumentationPageV1 = DbCreateInputOmit<DocumentationPageV1>;
16
16
  export type UpdateDocumentationPageV1 = OmitStrict<DbUpdate<DocumentationPageV1>, "designSystemVersionId">;
17
-
18
- export const DocumentationPageDTOV1 = DocumentationPageV1.omit({
19
- data: true,
20
- meta: true,
21
- parentPersistentId: true,
22
- sortOrder: true,
23
- })
24
- .extend(DocumentationPageV1.shape.data.shape)
25
- .extend({
26
- title: z.string(),
27
- path: z.string(),
28
- });
29
-
30
- export type DocumentationPageDTOV1 = z.infer<typeof DocumentationPageDTOV1>;
@@ -5,6 +5,7 @@ import { DbCreateInputOmit, DbUpdate } from "../../helpers";
5
5
  import { OmitStrict } from "../../helpers";
6
6
  import { DocumentationGroupBehavior, ElementGroupData } from "./data";
7
7
  import { DocumentationItemConfiguration } from "./data";
8
+
8
9
  export const ElementGroup = DesignElementBase.extend(DesignElementGroupablePart.shape)
9
10
  .extend(DesignElementSlugPart.shape)
10
11
  .extend(DesignElementBrandedPart.partial().shape)
@@ -34,26 +35,3 @@ export type ElementGroupsDiff = {
34
35
  toUpdate: UpdateElementGroup[];
35
36
  toDelete: ElementGroup["id"][];
36
37
  };
37
-
38
- //
39
- // DTO
40
- //
41
-
42
- export const DocumentationGroupDTO = ElementGroup.omit({
43
- sortOrder: true,
44
- parentPersistentId: true,
45
- brandPersistentId: true,
46
- meta: true,
47
- childType: true,
48
- data: true,
49
- shortPersistentId: true,
50
- }).extend({
51
- title: z.string(),
52
- isRoot: z.boolean(),
53
- childrenIds: z.array(z.string()),
54
- groupBehavior: DocumentationGroupBehavior,
55
- configuration: DocumentationItemConfiguration,
56
- shortPersistentId: z.string(),
57
- });
58
-
59
- export type DocumentationGroupDTO = z.infer<typeof DocumentationGroupDTO>;
@@ -43,7 +43,7 @@ export const DesignTokenType = z.enum([
43
43
  "Font",
44
44
  ]);
45
45
 
46
- export const tokenElementTypes: ReadonlyArray<DesignTokenType> = [...DesignTokenType.options.filter(v => v !== "Font")];
46
+ export const tokenElementTypes: DesignTokenType[] = [...DesignTokenType.options.filter(v => v !== "Font")];
47
47
 
48
48
  export type DesignTokenType = z.infer<typeof DesignTokenType>;
49
49
 
@@ -118,8 +118,8 @@ export const DesignElement = ShallowDesignElement.extend({
118
118
  createdAt: z.date(),
119
119
  updatedAt: z.date(),
120
120
  exportProperties: DesignSystemElementExportProps.optional(),
121
- data: z.any(), // TODO this should be an object, not any.
122
- origin: z.any().optional(), // TODO object, not any.
121
+ data: z.record(z.any()),
122
+ origin: z.record(z.any()).optional(),
123
123
  });
124
124
 
125
125
  export type ShallowDesignElement = z.infer<typeof ShallowDesignElement>;
@@ -1,9 +1,9 @@
1
- import { ZodType, z } from "zod";
1
+ import { ZodType, ZodTypeDef, z } from "zod";
2
2
 
3
3
  /**
4
4
  * Allows both null and undefined as input values in addition to the actual value,
5
5
  * but coerces them both to undefined.
6
6
  */
7
- export function nullishToOptional<T>(type: ZodType<T>) {
7
+ export function nullishToOptional<I, O>(type: ZodType<I, ZodTypeDef, O>) {
8
8
  return type.nullish().transform(t => t ?? undefined);
9
9
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./design-system-version-room";
2
2
  export * from "./documentation-page-room";
3
+ export * from "./room-type";
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+
3
+ export enum RoomTypeEnum {
4
+ DocumentationPage = "documentation-page",
5
+ DesignSystemVersion = "design-system-version",
6
+ }
7
+ export const RoomTypeSchema = z.nativeEnum(RoomTypeEnum);
8
+
9
+ export type RoomType = z.infer<typeof RoomTypeSchema>;
10
+ export const RoomType = RoomTypeSchema.enum;
@@ -1 +1,2 @@
1
1
  export * from "./content-loader-instruction";
2
+ export * from "./validation";