@supernova-studio/model 0.0.4

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 (165) hide show
  1. package/index.ts +1 -0
  2. package/package.json +23 -0
  3. package/src/auth/index.ts +1 -0
  4. package/src/auth/plugin-oauth-request.ts +14 -0
  5. package/src/billing/card.ts +12 -0
  6. package/src/billing/checkoutSession.ts +16 -0
  7. package/src/billing/customer.ts +28 -0
  8. package/src/billing/features.ts +43 -0
  9. package/src/billing/index.ts +9 -0
  10. package/src/billing/invoice.ts +34 -0
  11. package/src/billing/portalSession.ts +19 -0
  12. package/src/billing/price.ts +24 -0
  13. package/src/billing/product.ts +5 -0
  14. package/src/billing/subscription.ts +65 -0
  15. package/src/codegen/export-jobs.ts +26 -0
  16. package/src/codegen/exporter-workspace-membership-role.ts +4 -0
  17. package/src/codegen/exporter-workspace-membership.ts +14 -0
  18. package/src/codegen/exporter.ts +52 -0
  19. package/src/codegen/git-providers.ts +11 -0
  20. package/src/codegen/index.ts +6 -0
  21. package/src/codegen/pulsar.ts +59 -0
  22. package/src/common/entity.ts +9 -0
  23. package/src/common/index.ts +2 -0
  24. package/src/common/object-meta.ts +8 -0
  25. package/src/custom-domains/custom-domains.ts +24 -0
  26. package/src/custom-domains/index.ts +1 -0
  27. package/src/docs-server/index.ts +1 -0
  28. package/src/docs-server/session.ts +39 -0
  29. package/src/dsm/assets/asset-reference.ts +18 -0
  30. package/src/dsm/assets/asset-value.ts +3 -0
  31. package/src/dsm/assets/asset.ts +48 -0
  32. package/src/dsm/assets/index.ts +3 -0
  33. package/src/dsm/brand.ts +7 -0
  34. package/src/dsm/data-sources/data-source.ts +158 -0
  35. package/src/dsm/data-sources/import-job.ts +28 -0
  36. package/src/dsm/data-sources/import-summary.ts +70 -0
  37. package/src/dsm/data-sources/index.ts +3 -0
  38. package/src/dsm/design-system.ts +33 -0
  39. package/src/dsm/desing-system-create.ts +22 -0
  40. package/src/dsm/desing-system-update.ts +25 -0
  41. package/src/dsm/documentation/block-definitions/aux.ts +8 -0
  42. package/src/dsm/documentation/block-definitions/definition.ts +104 -0
  43. package/src/dsm/documentation/block-definitions/index.ts +4 -0
  44. package/src/dsm/documentation/block-definitions/item.ts +113 -0
  45. package/src/dsm/documentation/block-definitions/variant.ts +78 -0
  46. package/src/dsm/documentation/group.ts +19 -0
  47. package/src/dsm/documentation/index.ts +3 -0
  48. package/src/dsm/documentation/page.ts +18 -0
  49. package/src/dsm/elements/base.ts +49 -0
  50. package/src/dsm/elements/component.ts +48 -0
  51. package/src/dsm/elements/data/base.ts +18 -0
  52. package/src/dsm/elements/data/blur.ts +16 -0
  53. package/src/dsm/elements/data/border-radius.ts +15 -0
  54. package/src/dsm/elements/data/border-width.ts +15 -0
  55. package/src/dsm/elements/data/border.ts +21 -0
  56. package/src/dsm/elements/data/color.ts +13 -0
  57. package/src/dsm/elements/data/component.ts +23 -0
  58. package/src/dsm/elements/data/dimension.ts +15 -0
  59. package/src/dsm/elements/data/documentation-block-v1.ts +325 -0
  60. package/src/dsm/elements/data/documentation-block-v2.ts +57 -0
  61. package/src/dsm/elements/data/documentation-page-v1.ts +13 -0
  62. package/src/dsm/elements/data/documentation-page-v2.ts +11 -0
  63. package/src/dsm/elements/data/documentation.ts +8 -0
  64. package/src/dsm/elements/data/duration.ts +15 -0
  65. package/src/dsm/elements/data/figma-file-structure.ts +65 -0
  66. package/src/dsm/elements/data/figma-node-reference.ts +20 -0
  67. package/src/dsm/elements/data/font-family.ts +8 -0
  68. package/src/dsm/elements/data/font-size.ts +15 -0
  69. package/src/dsm/elements/data/font-weight.ts +8 -0
  70. package/src/dsm/elements/data/gradient.ts +32 -0
  71. package/src/dsm/elements/data/group.ts +17 -0
  72. package/src/dsm/elements/data/index.ts +36 -0
  73. package/src/dsm/elements/data/letter-spacing.ts +15 -0
  74. package/src/dsm/elements/data/line-height.ts +15 -0
  75. package/src/dsm/elements/data/opacity.ts +12 -0
  76. package/src/dsm/elements/data/paragraph-indent.ts +15 -0
  77. package/src/dsm/elements/data/paragraph-spacing.ts +15 -0
  78. package/src/dsm/elements/data/product-copy.ts +8 -0
  79. package/src/dsm/elements/data/shadow.ts +23 -0
  80. package/src/dsm/elements/data/size.ts +15 -0
  81. package/src/dsm/elements/data/space.ts +15 -0
  82. package/src/dsm/elements/data/string.ts +8 -0
  83. package/src/dsm/elements/data/text-case.ts +10 -0
  84. package/src/dsm/elements/data/text-decoration.ts +10 -0
  85. package/src/dsm/elements/data/typography.ts +28 -0
  86. package/src/dsm/elements/data/visibility.ts +10 -0
  87. package/src/dsm/elements/data/z-index.ts +15 -0
  88. package/src/dsm/elements/documentation-page-v1.ts +30 -0
  89. package/src/dsm/elements/documentation-page-v2.ts +16 -0
  90. package/src/dsm/elements/figma-file-structures.ts +39 -0
  91. package/src/dsm/elements/figma-node-reference.ts +17 -0
  92. package/src/dsm/elements/group.ts +59 -0
  93. package/src/dsm/elements/index.ts +13 -0
  94. package/src/dsm/elements/page-block-v2.ts +24 -0
  95. package/src/dsm/elements/primitives/index.ts +2 -0
  96. package/src/dsm/elements/primitives/point.ts +8 -0
  97. package/src/dsm/elements/primitives/size.ts +28 -0
  98. package/src/dsm/elements/raw-element.ts +126 -0
  99. package/src/dsm/elements/theme.ts +74 -0
  100. package/src/dsm/elements/tokens.ts +288 -0
  101. package/src/dsm/import/asset.ts +6 -0
  102. package/src/dsm/import/base.ts +24 -0
  103. package/src/dsm/import/component.ts +36 -0
  104. package/src/dsm/import/data-source.ts +9 -0
  105. package/src/dsm/import/figma-frames.ts +74 -0
  106. package/src/dsm/import/image.ts +72 -0
  107. package/src/dsm/import/index.ts +11 -0
  108. package/src/dsm/import/origin.ts +5 -0
  109. package/src/dsm/import/support/figma-files.ts +16 -0
  110. package/src/dsm/import/support/import-context.ts +75 -0
  111. package/src/dsm/import/support/import-model-collections.ts +46 -0
  112. package/src/dsm/import/support/index.ts +3 -0
  113. package/src/dsm/import/theme.ts +76 -0
  114. package/src/dsm/import/tokens.ts +49 -0
  115. package/src/dsm/import/warning.ts +28 -0
  116. package/src/dsm/index.ts +15 -0
  117. package/src/dsm/properties/index.ts +3 -0
  118. package/src/dsm/properties/property-definition.ts +44 -0
  119. package/src/dsm/properties/property-reference.ts +5 -0
  120. package/src/dsm/properties/property-value.ts +27 -0
  121. package/src/dsm/published-doc-page.ts +25 -0
  122. package/src/dsm/published-doc.ts +30 -0
  123. package/src/dsm/reference.ts +9 -0
  124. package/src/dsm/version.ts +14 -0
  125. package/src/dsm/views/column.ts +43 -0
  126. package/src/dsm/views/index.ts +2 -0
  127. package/src/dsm/views/view.ts +11 -0
  128. package/src/feature-flags/feature-flags.ts +14 -0
  129. package/src/feature-flags/index.ts +1 -0
  130. package/src/helpers/common.ts +1 -0
  131. package/src/helpers/db.ts +37 -0
  132. package/src/helpers/index.ts +4 -0
  133. package/src/helpers/nullish-to-optional.ts +9 -0
  134. package/src/helpers/slug-helper.ts +641 -0
  135. package/src/index.ts +16 -0
  136. package/src/integrations/external-oauth-request.ts +12 -0
  137. package/src/integrations/index.ts +3 -0
  138. package/src/integrations/oauth-providers.ts +13 -0
  139. package/src/integrations/oauth-token.ts +15 -0
  140. package/src/multiplayer/design-system-version-room.ts +13 -0
  141. package/src/multiplayer/documentation-page-room.ts +14 -0
  142. package/src/multiplayer/index.ts +2 -0
  143. package/src/npm/index.ts +2 -0
  144. package/src/npm/npm-package.ts +30 -0
  145. package/src/npm/npm-proxy-token-payload.ts +7 -0
  146. package/src/tokens/index.ts +1 -0
  147. package/src/tokens/personal-access-token.ts +17 -0
  148. package/src/users/index.ts +5 -0
  149. package/src/users/linked-integrations.ts +36 -0
  150. package/src/users/user-identity.ts +8 -0
  151. package/src/users/user-profile.ts +26 -0
  152. package/src/users/user-with-pat.ts +7 -0
  153. package/src/users/user.ts +17 -0
  154. package/src/utils/content-loader-instruction.ts +31 -0
  155. package/src/utils/index.ts +1 -0
  156. package/src/workspace/index.ts +9 -0
  157. package/src/workspace/npm-registry-settings.ts +45 -0
  158. package/src/workspace/sso-provider.ts +13 -0
  159. package/src/workspace/user-invite.ts +18 -0
  160. package/src/workspace/workspace-context.ts +10 -0
  161. package/src/workspace/workspace-create.ts +27 -0
  162. package/src/workspace/workspace-invitations.ts +14 -0
  163. package/src/workspace/workspace-membership.ts +11 -0
  164. package/src/workspace/workspace-role.ts +6 -0
  165. package/src/workspace/workspace.ts +48 -0
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { DesignElementBase, DesignElementGroupableRequiredPart } from "./base";
3
+ import { PageBlockDataV2 } from "./data";
4
+
5
+ //
6
+ // Element
7
+ //
8
+
9
+ export const PageBlockV2 = DesignElementBase.extend(DesignElementGroupableRequiredPart.shape).extend({
10
+ data: PageBlockDataV2,
11
+ });
12
+
13
+ export type PageBlockV2 = z.infer<typeof PageBlockV2>;
14
+
15
+ //
16
+ // Editor Model
17
+ //
18
+
19
+ export const PageBlockEditorModelV2 = z.object({
20
+ id: z.string(),
21
+ data: PageBlockDataV2,
22
+ });
23
+
24
+ export type PageBlockEditorModelV2 = z.infer<typeof PageBlockEditorModelV2>;
@@ -0,0 +1,2 @@
1
+ export * from "./point";
2
+ export * from "./size";
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+
3
+ export const Point2D = z.object({
4
+ x: z.number(),
5
+ y: z.number(),
6
+ });
7
+
8
+ export type Point2D = z.infer<typeof Point2D>;
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+
3
+ const nullSize = { height: -1, width: -1 };
4
+
5
+ function isNullSize(size: Size): boolean {
6
+ return size.height === nullSize.height && size.width === nullSize.width;
7
+ }
8
+
9
+ export const Size = z.object({
10
+ width: z
11
+ .number()
12
+ .nullish()
13
+ .transform(v => v ?? nullSize.width),
14
+
15
+ height: z
16
+ .number()
17
+ .nullish()
18
+ .transform(v => v ?? nullSize.height),
19
+ });
20
+
21
+ export const SizeOrUndefined = Size.optional().transform(v => {
22
+ if (!v) return undefined;
23
+ if (isNullSize(v)) return undefined;
24
+
25
+ return v;
26
+ });
27
+
28
+ export type Size = z.infer<typeof Size>;
@@ -0,0 +1,126 @@
1
+ import { z } from "zod";
2
+ import { DbCreateInputOmit, DbUpdate, OmitStrict } from "../../helpers";
3
+ import { ObjectMeta } from "../../common";
4
+
5
+ export type CreateDesignElement = DbCreateInputOmit<DesignElement>;
6
+ export type UpdateDesignElement = OmitStrict<
7
+ DbUpdate<DesignElement>,
8
+ "brandPersistentId" | "childType" | "designSystemVersionId" | "shortPersistentId" | "type"
9
+ >;
10
+
11
+ //
12
+ // Token types
13
+ //
14
+
15
+ export const DesignTokenType = z.enum([
16
+ "Color",
17
+ "Border",
18
+ "Gradient",
19
+ "Shadow",
20
+ "Dimension",
21
+ "Duration",
22
+ "Size",
23
+ "Space",
24
+ "Opacity",
25
+ "FontSize",
26
+ "LineHeight",
27
+ "LetterSpacing",
28
+ "ParagraphSpacing",
29
+ "BorderWidth",
30
+ "BorderRadius",
31
+ "Duration",
32
+ "ZIndex",
33
+ "Image",
34
+ "String",
35
+ "ProductCopy",
36
+ "FontFamily",
37
+ "FontWeight",
38
+ "TextDecoration",
39
+ "TextCase",
40
+ "Visibility",
41
+ "Typography",
42
+ "Blur",
43
+ "Font",
44
+ ]);
45
+
46
+ export const tokenElementTypes: ReadonlyArray<DesignTokenType> = [...DesignTokenType.options.filter(v => v !== "Font")];
47
+
48
+ export type DesignTokenType = z.infer<typeof DesignTokenType>;
49
+
50
+ //
51
+ // Non-token types
52
+ //
53
+
54
+ export const DesignElementType = DesignTokenType.or(
55
+ z.enum([
56
+ "Component",
57
+ "Theme",
58
+ "Documentation",
59
+ "DocumentationPage",
60
+ "DesignSystemComponent",
61
+ "ElementGroup",
62
+ "FigmaNodeStructure",
63
+ "FigmaNodeReference",
64
+ "PageBlock",
65
+ ])
66
+ );
67
+
68
+ export type DesignElementType = z.infer<typeof DesignElementType>;
69
+
70
+ export function isTokenType(type: DesignElementType): type is DesignTokenType {
71
+ return DesignTokenType.safeParse(type).success;
72
+ }
73
+
74
+ //
75
+ // Element category
76
+ //
77
+
78
+ export const DesignElementCategory = z.enum([
79
+ "Token",
80
+ "Component",
81
+ "DesignSystemComponent",
82
+ "DocumentationPage",
83
+ "Theme",
84
+ "PageBlock",
85
+ ]);
86
+
87
+ export type DesignElementCategory = z.infer<typeof DesignElementCategory>;
88
+
89
+ // Elements
90
+
91
+ export const DesignSystemElementExportProps = z.object({
92
+ isAsset: z
93
+ .boolean()
94
+ .nullish()
95
+ .transform(v => v ?? false),
96
+
97
+ codeName: z.string().nullish(),
98
+ });
99
+
100
+ export type DesignSystemElementExportProps = z.infer<typeof DesignSystemElementExportProps>;
101
+
102
+ export const ShallowDesignElement = z.object({
103
+ id: z.string(),
104
+ persistentId: z.string(),
105
+ designSystemVersionId: z.string(),
106
+ type: DesignElementType,
107
+ brandPersistentId: z.string().optional(),
108
+ parentPersistentId: z.string().optional(),
109
+ shortPersistentId: z.string().optional(),
110
+ sortOrder: z.number(),
111
+ });
112
+
113
+ export const DesignElement = ShallowDesignElement.extend({
114
+ meta: ObjectMeta,
115
+ childType: DesignElementType.optional(),
116
+ slug: z.string().optional(),
117
+ userSlug: z.string().optional(),
118
+ createdAt: z.date(),
119
+ updatedAt: z.date(),
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.
123
+ });
124
+
125
+ export type ShallowDesignElement = z.infer<typeof ShallowDesignElement>;
126
+ export type DesignElement = z.infer<typeof DesignElement>;
@@ -0,0 +1,74 @@
1
+ import { z } from "zod";
2
+ import { DesignTokenOrigin, DesignTokenOriginPart, DesignTokenTypedData } from "./tokens";
3
+ import { DesignTokenType } from "./raw-element";
4
+ import { DesignElementBase, DesignElementBrandedPart } from "./base";
5
+ import { DbCreateInputOmit, DbUpdate, OmitStrict } from "../../helpers";
6
+
7
+ //
8
+ // Overrides
9
+ //
10
+
11
+ export const ThemeOverrideOriginPart = DesignTokenOriginPart;
12
+ export const ThemeOverrideOrigin = DesignTokenOrigin;
13
+
14
+ export const ThemeOverride = DesignTokenTypedData.and(
15
+ z.object({
16
+ tokenPersistentId: z.string(),
17
+ origin: ThemeOverrideOrigin.optional()
18
+ .nullable()
19
+ .transform(v => v ?? undefined),
20
+ })
21
+ );
22
+
23
+ export type ThemeOverride = z.infer<typeof ThemeOverride>;
24
+ export type ThemeOverrideOfType<T extends DesignTokenType> = Extract<ThemeOverride, { type: T }>;
25
+
26
+ //
27
+ // Theme data
28
+ //
29
+
30
+ export const ThemeElementData = z.object({
31
+ value: z.object({
32
+ overrides: z.array(ThemeOverride),
33
+ }),
34
+ });
35
+
36
+ export type ThemeElementData = z.infer<typeof ThemeElementData>;
37
+
38
+ //
39
+ // Theme
40
+ //
41
+
42
+ export const ThemeOriginPart = z.object({});
43
+
44
+ export const ThemeOriginObject = z.object({
45
+ id: z.string(),
46
+ name: z.string(),
47
+ });
48
+
49
+ export const ThemeOriginSource = z.object({
50
+ sourceId: z.string(),
51
+ sourceObjects: z.array(ThemeOriginObject),
52
+ });
53
+
54
+ export const ThemeOrigin = z.object({
55
+ sources: z.array(ThemeOriginSource),
56
+ });
57
+
58
+ export const Theme = DesignElementBase.extend(DesignElementBrandedPart.shape).extend({
59
+ origin: ThemeOrigin.optional(),
60
+ overrides: z.array(ThemeOverride),
61
+ });
62
+
63
+ export type Theme = z.infer<typeof Theme>;
64
+ export type ThemeOrigin = z.infer<typeof ThemeOrigin>;
65
+ export type ThemeOriginSource = z.infer<typeof ThemeOriginSource>;
66
+ export type ThemeOriginObject = z.infer<typeof ThemeOriginObject>;
67
+
68
+ export type CreateTheme = DbCreateInputOmit<Theme>;
69
+ export type UpdateTheme = OmitStrict<DbUpdate<Theme>, "brandPersistentId" | "designSystemVersionId">;
70
+
71
+ export type ThemeDiff = {
72
+ toCreate: CreateTheme[];
73
+ toUpdate: UpdateTheme[];
74
+ };
@@ -0,0 +1,288 @@
1
+ import { z } from "zod";
2
+ import {
3
+ DesignElementBase,
4
+ DesignElementBrandedPart,
5
+ DesignElementGroupableRequiredPart,
6
+ DesignElementOrigin,
7
+ } from "./base";
8
+ import { DbUpdate, OmitStrict, zodCreateInputOmit, zodUpdateInputOmit } from "../../helpers";
9
+ import { DesignTokenType } from "./raw-element";
10
+ import {
11
+ TextCaseTokenData,
12
+ FontWeightTokenData,
13
+ LetterSpacingTokenData,
14
+ LineHeightTokenData,
15
+ ParagraphSpacingTokenData,
16
+ StringTokenData,
17
+ TextDecorationTokenData,
18
+ BorderRadiusTokenData,
19
+ BorderWidthTokenData,
20
+ BorderTokenData,
21
+ ProductCopyTokenData,
22
+ FontFamilyTokenData,
23
+ FontSizeTokenData,
24
+ DimensionTokenData,
25
+ TypographyTokenData,
26
+ ShadowTokenData,
27
+ OpacityTokenData,
28
+ GradientTokenData,
29
+ ColorTokenData,
30
+ BlurTokenData,
31
+ DurationTokenData,
32
+ ZIndexTokenData,
33
+ VisibilityTokenData,
34
+ SpaceTokenData,
35
+ SizeTokenData,
36
+ } from "./data";
37
+
38
+ //
39
+ // Base
40
+ //
41
+
42
+ export const DesignTokenOriginPart = z.object({
43
+ referenceOriginId: z.string().optional(),
44
+ referencePersistentId: z.string().optional(),
45
+ });
46
+
47
+ export const DesignTokenOrigin = DesignElementOrigin.extend(DesignTokenOriginPart.shape);
48
+
49
+ const DesignTokenBase = DesignElementBase.extend(DesignElementGroupableRequiredPart.shape)
50
+ .extend(DesignElementBrandedPart.shape)
51
+ .extend({
52
+ origin: DesignTokenOrigin.optional(),
53
+ });
54
+
55
+ const CreateDesignTokenBase = DesignTokenBase.omit(zodCreateInputOmit());
56
+ const UpdateDesignTokenBase = DesignTokenBase.omit({
57
+ ...zodUpdateInputOmit(),
58
+ brandPersistentId: true,
59
+ designSystemVersionId: true,
60
+ });
61
+
62
+ //
63
+ // Per type
64
+ //
65
+
66
+ const BlurTokenTypedData = z.object({
67
+ type: z.literal("Blur"),
68
+ data: BlurTokenData,
69
+ });
70
+
71
+ const ColorTokenTypedData = z.object({
72
+ type: z.literal("Color"),
73
+ data: ColorTokenData,
74
+ });
75
+
76
+ const GradientTokenTypedData = z.object({
77
+ type: z.literal("Gradient"),
78
+ data: GradientTokenData,
79
+ });
80
+
81
+ const OpacityTokenTypedData = z.object({
82
+ type: z.literal("Opacity"),
83
+ data: OpacityTokenData,
84
+ });
85
+
86
+ const ShadowTokenTypedData = z.object({
87
+ type: z.literal("Shadow"),
88
+ data: ShadowTokenData,
89
+ });
90
+
91
+ const TypographyTokenTypedData = z.object({
92
+ type: z.literal("Typography"),
93
+ data: TypographyTokenData,
94
+ });
95
+
96
+ const StringTokenTypedData = z.object({
97
+ type: z.literal("String"),
98
+ data: StringTokenData,
99
+ });
100
+
101
+ const DimensionTokenTypedData = z.object({
102
+ type: z.literal("Dimension"),
103
+ data: DimensionTokenData,
104
+ });
105
+
106
+ const FontSizeTokenTypedData = z.object({
107
+ type: z.literal("FontSize"),
108
+ data: FontSizeTokenData,
109
+ });
110
+
111
+ const FontFamilyTokenTypedData = z.object({
112
+ type: z.literal("FontFamily"),
113
+ data: FontFamilyTokenData,
114
+ });
115
+
116
+ const FontWeightTokenTypedData = z.object({
117
+ type: z.literal("FontWeight"),
118
+ data: FontWeightTokenData,
119
+ });
120
+
121
+ const LetterSpacingTokenTypedData = z.object({
122
+ type: z.literal("LetterSpacing"),
123
+ data: LetterSpacingTokenData,
124
+ });
125
+
126
+ const LineHeightTokenTypedData = z.object({
127
+ type: z.literal("LineHeight"),
128
+ data: LineHeightTokenData,
129
+ });
130
+
131
+ const ParagraphSpacingTokenTypedData = z.object({
132
+ type: z.literal("ParagraphSpacing"),
133
+ data: ParagraphSpacingTokenData,
134
+ });
135
+
136
+ const TextCaseTokenTypedData = z.object({
137
+ type: z.literal("TextCase"),
138
+ data: TextCaseTokenData,
139
+ });
140
+
141
+ const TextDecorationTokenTypedData = z.object({
142
+ type: z.literal("TextDecoration"),
143
+ data: TextDecorationTokenData,
144
+ });
145
+
146
+ const BorderRadiusTokenTypedData = z.object({
147
+ type: z.literal("BorderRadius"),
148
+ data: BorderRadiusTokenData,
149
+ });
150
+
151
+ const BorderWidthTokenTypedData = z.object({
152
+ type: z.literal("BorderWidth"),
153
+ data: BorderWidthTokenData,
154
+ });
155
+
156
+ const BorderTypedData = z.object({
157
+ type: z.literal("Border"),
158
+ data: BorderTokenData,
159
+ });
160
+
161
+ const ProductCopyTypedData = z.object({
162
+ type: z.literal("ProductCopy"),
163
+ data: ProductCopyTokenData,
164
+ });
165
+
166
+ const SizeTypedData = z.object({
167
+ type: z.literal("Size"),
168
+ data: SizeTokenData,
169
+ });
170
+
171
+ const SpaceTypedData = z.object({
172
+ type: z.literal("Space"),
173
+ data: SpaceTokenData,
174
+ });
175
+
176
+ const VisibilityTypedData = z.object({
177
+ type: z.literal("Visibility"),
178
+ data: VisibilityTokenData,
179
+ });
180
+
181
+ const ZIndexTypedData = z.object({
182
+ type: z.literal("ZIndex"),
183
+ data: ZIndexTokenData,
184
+ });
185
+
186
+ const DurationTypedData = z.object({
187
+ type: z.literal("Duration"),
188
+ data: DurationTokenData,
189
+ });
190
+
191
+ const FontTypedData = z.object({
192
+ type: z.literal("Font"),
193
+ data: z.record(z.any()),
194
+ });
195
+
196
+ //
197
+ // Global types
198
+ //
199
+
200
+ export const DesignTokenTypedData = z.discriminatedUnion("type", [
201
+ BlurTokenTypedData,
202
+ BorderRadiusTokenTypedData,
203
+ BorderWidthTokenTypedData,
204
+ BorderTypedData,
205
+ ColorTokenTypedData,
206
+
207
+ DimensionTokenTypedData,
208
+ DurationTypedData,
209
+ FontSizeTokenTypedData,
210
+ FontFamilyTokenTypedData,
211
+ FontWeightTokenTypedData,
212
+
213
+ GradientTokenTypedData,
214
+ LetterSpacingTokenTypedData,
215
+ LineHeightTokenTypedData,
216
+ OpacityTokenTypedData,
217
+ ParagraphSpacingTokenTypedData,
218
+
219
+ ProductCopyTypedData,
220
+ ShadowTokenTypedData,
221
+ SizeTypedData,
222
+ SpaceTypedData,
223
+ StringTokenTypedData,
224
+
225
+ TextCaseTokenTypedData,
226
+ TextDecorationTokenTypedData,
227
+ TypographyTokenTypedData,
228
+ VisibilityTypedData,
229
+ ZIndexTypedData,
230
+ FontTypedData,
231
+ ]);
232
+
233
+ export type DesignTokenOriginPart = z.infer<typeof DesignTokenOriginPart>;
234
+ export type DesignTokenOrigin = z.infer<typeof DesignTokenOrigin>;
235
+
236
+ export type DesignTokenBase = z.infer<typeof DesignTokenBase>;
237
+
238
+ export const DesignToken = DesignTokenTypedData.and(DesignTokenBase);
239
+ export const CreateDesignToken = DesignTokenTypedData.and(CreateDesignTokenBase);
240
+
241
+ export type DesignTokenTypedData = z.infer<typeof DesignTokenTypedData>;
242
+ export type DesignTokenTypedDataOfType<T extends DesignTokenType> = Extract<DesignTokenTypedData, { type: T }>;
243
+
244
+ export type DesignToken = z.infer<typeof DesignToken>;
245
+ export type ImportedDesignToken = OmitStrict<DesignToken, "origin"> & { origin: DesignTokenOrigin };
246
+
247
+ export type DesignTokenOfType<T extends DesignTokenType> = Extract<DesignToken, { type: T }>;
248
+ export type ImportedDesignTokenOfType<T extends DesignTokenType> = Extract<ImportedDesignToken, { type: T }>;
249
+
250
+ export type CreateDesignToken = z.infer<typeof CreateDesignToken>;
251
+ export type UpdateDesignToken = OmitStrict<DbUpdate<DesignToken>, "brandPersistentId" | "designSystemVersionId">;
252
+
253
+ export type DesignTokensDiff = {
254
+ toCreate: CreateDesignToken[];
255
+ toUpdate: UpdateDesignToken[];
256
+ };
257
+
258
+ //
259
+ // Utilities
260
+ //
261
+
262
+ export function extractTokenTypedData<T extends DesignTokenType, I extends DesignTokenTypedDataOfType<T>>(
263
+ source: I
264
+ ): DesignTokenTypedDataOfType<T> {
265
+ return {
266
+ type: source.type,
267
+ data: source.data,
268
+ } as DesignTokenTypedDataOfType<T>;
269
+ }
270
+
271
+ export function isImportedDesignToken<T extends DesignTokenType>(
272
+ designToken: DesignTokenOfType<T>
273
+ ): designToken is ImportedDesignTokenOfType<T> {
274
+ return !!designToken.origin;
275
+ }
276
+
277
+ export function isDesignTokenOfType<T extends DesignTokenType>(
278
+ designToken: DesignToken,
279
+ type: T
280
+ ): designToken is DesignTokenOfType<T> {
281
+ return designToken.type === type;
282
+ }
283
+
284
+ export function designTokenTypeFilter<T extends DesignTokenType>(
285
+ type: T
286
+ ): (designToken: DesignToken) => designToken is DesignTokenOfType<T> {
287
+ return (designToken): designToken is DesignTokenOfType<T> => isDesignTokenOfType(designToken, type);
288
+ }
@@ -0,0 +1,6 @@
1
+ import { ComponentImportModelInput } from "./component";
2
+ import { FigmaSvgRenderImportModel } from "./image";
3
+
4
+ export type AssetImportModel = ComponentImportModelInput & {
5
+ svg: FigmaSvgRenderImportModel;
6
+ };
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { DesignElementOrigin } from "../elements";
3
+ import { ObjectMeta } from "../../common";
4
+
5
+ export const ImportModelBase = z.object({
6
+ id: z.string(),
7
+ meta: ObjectMeta,
8
+ origin: DesignElementOrigin,
9
+ brandPersistentId: z.string(),
10
+ sortOrder: z.number(),
11
+ });
12
+
13
+ export type ImportModelBase = z.infer<typeof ImportModelBase>;
14
+
15
+ export const ImportModelInputBase = ImportModelBase.omit({
16
+ brandPersistentId: true,
17
+ origin: true,
18
+ sortOrder: true,
19
+ }).extend({
20
+ originId: z.string(),
21
+ originMetadata: z.record(z.any()),
22
+ });
23
+
24
+ export type ImportModelInputBase = z.infer<typeof ImportModelInputBase>;
@@ -0,0 +1,36 @@
1
+ import { FigmaSvgRenderImportModel, ImageImportModel } from "./image";
2
+ import { ComponentOrigin, ComponentOriginPart } from "../elements";
3
+ import { z } from "zod";
4
+ import { ImportModelBase, ImportModelInputBase } from "./base";
5
+
6
+ //
7
+ // Import model
8
+ //
9
+
10
+ const ComponentImportModelPart = z.object({
11
+ thumbnail: ImageImportModel,
12
+ });
13
+
14
+ export const ComponentImportModel = ImportModelBase.extend(ComponentImportModelPart.shape).extend({
15
+ isAsset: z.boolean(),
16
+ svg: FigmaSvgRenderImportModel.optional(),
17
+ origin: ComponentOrigin,
18
+ });
19
+
20
+ export type ComponentImportModel = z.infer<typeof ComponentImportModel>;
21
+
22
+ //
23
+ // Import model input
24
+ //
25
+
26
+ export const ComponentImportModelInput = ImportModelInputBase.extend(ComponentImportModelPart.shape).extend({
27
+ originMetadata: ComponentOriginPart,
28
+ });
29
+
30
+ export const AssetImportModelInput = ImportModelInputBase.extend(ComponentImportModelPart.shape).extend({
31
+ svg: FigmaSvgRenderImportModel,
32
+ originMetadata: ComponentOriginPart,
33
+ });
34
+
35
+ export type ComponentImportModelInput = z.infer<typeof ComponentImportModelInput>;
36
+ export type AssetImportModelInput = z.infer<typeof AssetImportModelInput>;
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+
3
+ export const DataSourceImportModel = z.object({
4
+ id: z.string(),
5
+ fileName: z.string().optional(),
6
+ thumbnailUrl: z.string().optional(),
7
+ });
8
+
9
+ export type DataSourceImportModel = z.infer<typeof DataSourceImportModel>;