@supernova-studio/model 0.58.26 → 0.59.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.58.26",
3
+ "version": "0.59.0",
4
4
  "description": "Supernova Data Models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -93,14 +93,32 @@ const stringTokenTypes: Set<DesignTokenType> = new Set([
93
93
  "FontWeight",
94
94
  ] satisfies DesignTokenType[]);
95
95
 
96
- export function areTokenTypesCompatible(lhs: DesignTokenType, rhs: DesignTokenType): boolean {
96
+ const fallbackNumberValue = 14;
97
+
98
+ export function areTokenTypesCompatible(
99
+ lhs: DesignTokenType,
100
+ rhs: DesignTokenType,
101
+ isNonCompatibleTypeChangesEnabled = false
102
+ ): boolean {
97
103
  if (lhs === rhs) return true;
98
104
  if (numberTokenTypes.has(lhs) && numberTokenTypes.has(rhs)) return true;
99
105
  if (stringTokenTypes.has(lhs) && stringTokenTypes.has(rhs)) return true;
100
106
 
107
+ if (isNonCompatibleTypeChangesEnabled && stringTokenTypes.has(lhs) && numberTokenTypes.has(rhs)) return true;
108
+
101
109
  return false;
102
110
  }
103
111
 
112
+ export function castStringToDimensionValue(lhs: DesignTokenType, rhs: DesignTokenType, value?: unknown) {
113
+ if (stringTokenTypes.has(lhs) && numberTokenTypes.has(rhs) && value) {
114
+ const newValue = Number.parseFloat(value?.toString() ?? "");
115
+ const measure = Number.isNaN(newValue) ? fallbackNumberValue : newValue;
116
+ return { unit: "Pixels", measure };
117
+ }
118
+
119
+ return value;
120
+ }
121
+
104
122
  //
105
123
  // Element category
106
124
  //
@@ -35,7 +35,7 @@ import {
35
35
  VisibilityTokenData,
36
36
  ZIndexTokenData,
37
37
  } from "./data";
38
- import { areTokenTypesCompatible, DesignTokenType } from "./raw-element";
38
+ import { areTokenTypesCompatible, castStringToDimensionValue, DesignTokenType } from "./raw-element";
39
39
 
40
40
  //
41
41
  // Base
@@ -279,15 +279,21 @@ export function extractTokenTypedData<T extends DesignTokenType, I extends Desig
279
279
 
280
280
  export function convertTokenTypedData<I extends DesignTokenType, O extends DesignTokenType>(
281
281
  source: DesignTokenTypedDataOfType<I>,
282
- type: O
282
+ type: O,
283
+ isNonCompatibleTypeChangesEnabled: boolean
283
284
  ): DesignTokenTypedDataOfType<O> {
284
- if (!areTokenTypesCompatible(source.type, type)) {
285
+ if (!areTokenTypesCompatible(source.type, type, isNonCompatibleTypeChangesEnabled)) {
285
286
  throw SupernovaException.invalidOperation(`Cannot convert token from ${source.type} to ${type}`);
286
287
  }
287
288
 
289
+ const data = source.data;
290
+ if (isNonCompatibleTypeChangesEnabled) {
291
+ data.value = castStringToDimensionValue(source.type, type, source.data.value);
292
+ }
293
+
288
294
  return {
289
- type: type,
290
- data: source.data,
295
+ type,
296
+ data,
291
297
  } as DesignTokenTypedDataOfType<O>;
292
298
  }
293
299
 
@@ -60,6 +60,7 @@ export const FeatureFlagsKeepAliases = z.object({
60
60
  isTypographyPropsKeepAliasesEnabled: z.boolean().default(false),
61
61
  isGradientPropsKeepAliasesEnabled: z.boolean().default(false),
62
62
  isShadowPropsKeepAliasesEnabled: z.boolean().default(false),
63
+ isNonCompatibleTypeChangesEnabled: z.boolean().default(false),
63
64
  });
64
65
  export type FeatureFlagsKeepAliases = z.infer<typeof FeatureFlagsKeepAliases>;
65
66
 
@@ -0,0 +1,90 @@
1
+ import { z } from "zod";
2
+
3
+ //
4
+ // Primitives
5
+ //
6
+
7
+ const PrimitiveValue = z.number().or(z.boolean()).or(z.string());
8
+ const ArrayValue = z.array(z.string());
9
+ const ObjectValue = z.record(z.string());
10
+
11
+ export const ExporterPropertyDefinitionValue = PrimitiveValue.or(ArrayValue).or(ObjectValue);
12
+ export const ExporterPropertyType = z.enum(["Enum", "Boolean", "String", "Number", "Array", "Object"]);
13
+
14
+ export type ExporterPropertyDefinitionValue = z.infer<typeof ExporterPropertyDefinitionValue>;
15
+ export type ExporterPropertyType = z.infer<typeof ExporterPropertyType>;
16
+
17
+ //
18
+ // Property
19
+ //
20
+
21
+ const PropertyDefinitionBase = z.object({
22
+ key: z.string(),
23
+ title: z.string(),
24
+ description: z.string(),
25
+ });
26
+
27
+ export const ExporterPropertyDefinitionEnum = PropertyDefinitionBase.extend({
28
+ type: z.literal(ExporterPropertyType.Enum.Enum),
29
+ options: z.string().array(),
30
+ default: z.string(),
31
+ });
32
+
33
+ export const ExporterPropertyDefinitionBoolean = PropertyDefinitionBase.extend({
34
+ type: z.literal(ExporterPropertyType.Enum.Boolean),
35
+ default: z.boolean(),
36
+ });
37
+
38
+ export const ExporterPropertyDefinitionString = PropertyDefinitionBase.extend({
39
+ type: z.literal(ExporterPropertyType.Enum.String),
40
+ default: z.string(),
41
+ });
42
+
43
+ export const ExporterPropertyDefinitionNumber = PropertyDefinitionBase.extend({
44
+ type: z.literal(ExporterPropertyType.Enum.Number),
45
+ default: z.number(),
46
+ });
47
+
48
+ export const ExporterPropertyDefinitionArray = PropertyDefinitionBase.extend({
49
+ type: z.literal(ExporterPropertyType.Enum.Array),
50
+ default: ArrayValue,
51
+ });
52
+
53
+ export const ExporterPropertyDefinitionObject = PropertyDefinitionBase.extend({
54
+ type: z.literal(ExporterPropertyType.Enum.Object),
55
+ default: ObjectValue,
56
+ allowedKeys: z
57
+ .object({
58
+ options: z.string().array(),
59
+ type: z.string(),
60
+ })
61
+ .optional(),
62
+ allowedValues: z
63
+ .object({
64
+ type: z.string(),
65
+ })
66
+ .optional(),
67
+ });
68
+
69
+ export const ExporterPropertyDefinition = z.discriminatedUnion("type", [
70
+ ExporterPropertyDefinitionEnum,
71
+ ExporterPropertyDefinitionBoolean,
72
+ ExporterPropertyDefinitionString,
73
+ ExporterPropertyDefinitionNumber,
74
+ ExporterPropertyDefinitionArray,
75
+ ExporterPropertyDefinitionObject,
76
+ ]);
77
+
78
+ export type ExporterPropertyDefinitionEnum = z.infer<typeof ExporterPropertyDefinitionEnum>;
79
+ export type ExporterPropertyDefinitionBoolean = z.infer<typeof ExporterPropertyDefinitionBoolean>;
80
+ export type ExporterPropertyDefinitionString = z.infer<typeof ExporterPropertyDefinitionString>;
81
+ export type ExporterPropertyDefinitionNumber = z.infer<typeof ExporterPropertyDefinitionNumber>;
82
+ export type ExporterPropertyDefinitionArray = z.infer<typeof ExporterPropertyDefinitionArray>;
83
+ export type ExporterPropertyDefinitionObject = z.infer<typeof ExporterPropertyDefinitionObject>;
84
+ export type ExporterPropertyDefinition = z.infer<typeof ExporterPropertyDefinition>;
85
+ //
86
+ // Value
87
+ //
88
+
89
+ export const ExporterPropertyDefinitionValueMap = z.record(ExporterPropertyDefinitionValue);
90
+ export type ExporterPropertyDefinitionValueMap = z.infer<typeof ExporterPropertyDefinitionValueMap>;
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { PublishedDocEnvironment } from "../dsm";
3
3
  import { DbCreateInputOmit, DbUpdate, nullishToOptional } from "../helpers";
4
4
  import { ExportDestinationsMap } from "./export-destinations";
5
+ import { ExporterPropertyDefinitionValueMap } from "./export-configuration";
5
6
 
6
7
  //
7
8
  // Enums
@@ -89,6 +90,7 @@ export const ExportJob = z.object({
89
90
  status: ExportJobStatus,
90
91
  result: ExportJobResult.optional(),
91
92
  createdByUserId: z.string().optional(),
93
+ exporterConfigurationProperties: ExporterPropertyDefinitionValueMap.optional(),
92
94
 
93
95
  // Destinations
94
96
  ...ExportDestinationsMap.shape,
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { ExporterPropertyValue, PublishedDocEnvironment } from "../../dsm";
3
+ import { ExporterPropertyDefinitionValueMap } from "../export-configuration";
3
4
 
4
5
  export const ExportJobDocumentationContext = z.object({
5
6
  isSingleVersionDocs: z.boolean(),
@@ -27,6 +28,7 @@ export const ExportJobContext = z.object({
27
28
  export const ExportJobExporterConfiguration = z.object({
28
29
  exporterPackageUrl: z.string(),
29
30
  exporterPropertyValues: ExporterPropertyValue.array(),
31
+ exporterConfigurationProperties: ExporterPropertyDefinitionValueMap.optional(),
30
32
  });
31
33
 
32
34
  export type ExportJobDocumentationContext = z.infer<typeof ExportJobDocumentationContext>;
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { nullishToOptional } from "../helpers";
3
3
  import { GitProvider } from "./git-providers";
4
4
  import { PulsarContributionConfigurationProperty, PulsarContributionVariant, PulsarCustomBlock } from "./pulsar";
5
+ import { ExporterPropertyDefinition } from "./export-configuration";
5
6
 
6
7
  export const ExporterType = z.enum(["code", "documentation"]);
7
8
  export const ExporterSource = z.enum(["git", "upload"]);
@@ -22,6 +23,7 @@ export const ExporterPulsarDetails = z.object({
22
23
  configurationProperties: nullishToOptional(z.array(PulsarContributionConfigurationProperty)).default([]),
23
24
  customBlocks: nullishToOptional(z.array(PulsarCustomBlock)).default([]),
24
25
  blockVariants: nullishToOptional(z.record(z.string(), z.array(PulsarContributionVariant))).default({}),
26
+ properties: nullishToOptional(ExporterPropertyDefinition.array()),
25
27
 
26
28
  usesBrands: nullishToOptional(z.boolean()).default(false),
27
29
  usesThemes: nullishToOptional(z.boolean()).default(false),
@@ -45,6 +47,7 @@ export const Exporter = z.object({
45
47
  details: ExporterDetails,
46
48
  exporterType: nullishToOptional(ExporterType).default("code"),
47
49
  storagePath: nullishToOptional(z.string()).default(""),
50
+ properties: nullishToOptional(ExporterPropertyDefinition.array()),
48
51
  });
49
52
 
50
53
  export type ExporterType = z.infer<typeof ExporterType>;
@@ -1,4 +1,5 @@
1
1
  export * from "./export-runner";
2
+ export * from "./export-configuration";
2
3
  export * from "./export-destinations";
3
4
  export * from "./export-jobs";
4
5
  export * from "./exporter-workspace-membership-role";
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { ExportDestinationsMap } from "./export-destinations";
3
+ import { ExporterPropertyDefinitionValueMap } from "./export-configuration";
3
4
 
4
5
  export const PipelineEventType = z.enum(["OnVersionReleased", "OnHeadChanged", "OnSourceUpdated", "None"]);
5
6
 
@@ -21,6 +22,7 @@ export const Pipeline = z.object({
21
22
  brandPersistentId: z.string().optional(),
22
23
  themePersistentId: z.string().optional(),
23
24
  themePersistentIds: z.string().array().optional(),
25
+ exporterConfigurationProperties: ExporterPropertyDefinitionValueMap.optional(),
24
26
 
25
27
  // Destinations
26
28
  ...ExportDestinationsMap.shape,
@@ -8,6 +8,7 @@ export const FlaggedFeature = z.enum([
8
8
  "TypographyPropsKeepAliases",
9
9
  "GradientPropsKeepAliases",
10
10
  "ShadowPropsKeepAliases",
11
+ "NonCompatibleTypeChanges",
11
12
  ]);
12
13
  export const FeatureFlagMap = z.record(FlaggedFeature, z.boolean());
13
14
  export const FeatureFlag = z.object({