@supernova-studio/model 0.59.0 → 0.59.2
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/dist/index.d.mts +7784 -7654
- package/dist/index.d.ts +7784 -7654
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +745 -706
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dsm/data-sources/data-source.ts +10 -0
- package/src/dsm/elements/data/figma-node-reference.ts +46 -18
- package/src/dsm/figma-node-renderer/index.ts +1 -0
- package/src/dsm/figma-node-renderer/renderer-payload.ts +9 -0
- package/src/dsm/index.ts +1 -0
- package/src/helpers/db.ts +2 -59
- package/src/utils/common.ts +40 -0
package/package.json
CHANGED
|
@@ -155,6 +155,16 @@ export type DataSourceVersion = z.infer<typeof DataSourceVersion>;
|
|
|
155
155
|
|
|
156
156
|
export type DataSourceRemote = z.infer<typeof DataSourceRemote>;
|
|
157
157
|
export type DataSource = z.infer<typeof DataSource>;
|
|
158
|
+
export type DataSourceOfType<T extends DataSourceRemoteType> = DataSource & {
|
|
159
|
+
remote: Extract<DataSourceRemote, { type: T }>;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export function isDataSourceOfType<T extends DataSourceRemoteType>(
|
|
163
|
+
dataSource: DataSource,
|
|
164
|
+
type: T
|
|
165
|
+
): dataSource is DataSourceOfType<T> {
|
|
166
|
+
return dataSource.remote.type === type;
|
|
167
|
+
}
|
|
158
168
|
|
|
159
169
|
export type CreateDataSource = OmitStrict<DbCreateInputOmit<DataSource>, "sortOrder">;
|
|
160
170
|
export type UpdateDataSource = OmitStrict<DbUpdate<DataSource>, "brandPersistentId" | "designSystemId">;
|
|
@@ -1,27 +1,55 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { nullishToOptional } from "../../../helpers/nullish-to-optional";
|
|
2
3
|
|
|
4
|
+
//
|
|
5
|
+
// Enums
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export const FigmaNodeRenderState = z.enum(["InProgress", "Success", "Failed"]);
|
|
3
9
|
export const FigmaNodeRenderFormat = z.enum(["Png", "Svg"]);
|
|
10
|
+
export const FigmaNodeRenderErrorType = z.enum(["MissingIntegration", "NodeNotFound", "RenderError"]);
|
|
4
11
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
assetWidth: z.number().optional(),
|
|
16
|
-
assetHeight: z.number().optional(),
|
|
17
|
-
assetUrl: z.string().optional(),
|
|
18
|
-
assetOriginKey: z.string().optional(),
|
|
12
|
+
export type FigmaNodeRenderState = z.infer<typeof FigmaNodeRenderState>;
|
|
13
|
+
export type FigmaNodeRenderFormat = z.infer<typeof FigmaNodeRenderFormat>;
|
|
14
|
+
export type FigmaNodeRenderErrorType = z.infer<typeof FigmaNodeRenderErrorType>;
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
// Definition
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
export const FigmaNodeRelinkData = z.object({
|
|
21
|
+
fileId: z.string(),
|
|
19
22
|
});
|
|
20
23
|
|
|
21
|
-
export const
|
|
22
|
-
|
|
24
|
+
export const FigmaNodeRenderedImage = z.object({
|
|
25
|
+
resourceId: z.string(),
|
|
26
|
+
format: FigmaNodeRenderFormat,
|
|
27
|
+
scale: nullishToOptional(z.number()),
|
|
28
|
+
|
|
29
|
+
width: nullishToOptional(z.number()),
|
|
30
|
+
height: nullishToOptional(z.number()),
|
|
31
|
+
url: nullishToOptional(z.string()),
|
|
32
|
+
originKey: nullishToOptional(z.string()),
|
|
23
33
|
});
|
|
24
34
|
|
|
25
|
-
export
|
|
35
|
+
export const FigmaNodeRenderError = z.object({
|
|
36
|
+
type: FigmaNodeRenderErrorType,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const FigmaNodeReferenceData = z.object({
|
|
40
|
+
sceneNodeId: z.string(),
|
|
41
|
+
format: FigmaNodeRenderFormat,
|
|
42
|
+
scale: nullishToOptional(z.number()),
|
|
43
|
+
|
|
44
|
+
renderState: FigmaNodeRenderState,
|
|
45
|
+
renderedImage: FigmaNodeRenderedImage.optional(),
|
|
46
|
+
renderError: FigmaNodeRenderError.optional(),
|
|
47
|
+
|
|
48
|
+
hasSource: z.boolean(),
|
|
49
|
+
relinkData: FigmaNodeRelinkData.optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export type FigmaNodeRelinkData = z.infer<typeof FigmaNodeRelinkData>;
|
|
53
|
+
export type FigmaNodeRenderedImage = z.infer<typeof FigmaNodeRenderedImage>;
|
|
54
|
+
export type FigmaNodeRenderError = z.infer<typeof FigmaNodeRenderError>;
|
|
26
55
|
export type FigmaNodeReferenceData = z.infer<typeof FigmaNodeReferenceData>;
|
|
27
|
-
export type FigmaNodeReferenceElementData = z.infer<typeof FigmaNodeReferenceElementData>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./renderer-payload";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const FigmaNodeRendererPayload = z.object({
|
|
4
|
+
designSystemId: z.string(),
|
|
5
|
+
versionId: z.string(),
|
|
6
|
+
figmaNodePersistentIds: z.string().array(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type FigmaNodeRendererPayload = z.infer<typeof FigmaNodeRendererPayload>;
|
package/src/dsm/index.ts
CHANGED
package/src/helpers/db.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { OptionalToNullable } from "../utils";
|
|
2
|
+
|
|
1
3
|
export type DbCreateInputOmit<T> = Omit<T, "id" | "createdAt" | "updatedAt">;
|
|
2
4
|
|
|
3
5
|
export type DbUpdateInputOmit<T> = Omit<T, "createdAt" | "updatedAt" | "persistentId">;
|
|
@@ -5,20 +7,6 @@ export type DbUpdateInputOmit<T> = Omit<T, "createdAt" | "updatedAt" | "persiste
|
|
|
5
7
|
export type DbUpdate<T extends { id: string }> = Partial<OptionalToNullable<DbUpdateInputOmit<Omit<T, "id">>>> &
|
|
6
8
|
Pick<T, "id">;
|
|
7
9
|
|
|
8
|
-
type PickOptional<T> = {
|
|
9
|
-
[P in keyof T as undefined extends T[P] ? P : never]: T[P];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type PickNotOptional<T> = {
|
|
13
|
-
[P in keyof T as undefined extends T[P] ? never : P]: T[P];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type OptionalToNullable<T> = {
|
|
17
|
-
[K in keyof PickOptional<T>]-?: Exclude<T[K], undefined> | null;
|
|
18
|
-
} & {
|
|
19
|
-
[K in keyof PickNotOptional<T>]: T[K];
|
|
20
|
-
};
|
|
21
|
-
|
|
22
10
|
export function zodCreateInputOmit() {
|
|
23
11
|
return {
|
|
24
12
|
id: true,
|
|
@@ -35,48 +23,3 @@ export function zodUpdateInputOmit() {
|
|
|
35
23
|
persistentId: true,
|
|
36
24
|
} as const;
|
|
37
25
|
}
|
|
38
|
-
|
|
39
|
-
// function zodCreate<
|
|
40
|
-
// T extends ZodRawShape,
|
|
41
|
-
// UnknownKeys extends UnknownKeysParam = UnknownKeysParam,
|
|
42
|
-
// Catchall extends ZodTypeAny = ZodTypeAny,
|
|
43
|
-
// O = objectOutputType<T, Catchall, UnknownKeys>,
|
|
44
|
-
// I = objectInputType<T, Catchall, UnknownKeys>
|
|
45
|
-
// >(schema: ZodObject<T, UnknownKeysParam, ZodTypeAny, I, O>) {
|
|
46
|
-
// return schema.omit(zodCreateInputOmit());
|
|
47
|
-
// }
|
|
48
|
-
|
|
49
|
-
// /**
|
|
50
|
-
// * Don't use it yet, produces too complex type
|
|
51
|
-
// */
|
|
52
|
-
// function zodUpdate<
|
|
53
|
-
// T extends ZodRawShape,
|
|
54
|
-
// UnknownKeys extends UnknownKeysParam = UnknownKeysParam,
|
|
55
|
-
// Catchall extends ZodTypeAny = ZodTypeAny,
|
|
56
|
-
// O = objectOutputType<T, Catchall, UnknownKeys>,
|
|
57
|
-
// I = objectInputType<T, Catchall, UnknownKeys>
|
|
58
|
-
// >(schema: ZodObject<T, UnknownKeysParam, ZodTypeAny, I, O>) {
|
|
59
|
-
// const hue = schema.omit(zodUpdateInputOmit());
|
|
60
|
-
// return makeOptionalPropsNullable(hue).partial();
|
|
61
|
-
// }
|
|
62
|
-
|
|
63
|
-
// function makeOptionalPropsNullable<Schema extends z.AnyZodObject>(schema: Schema) {
|
|
64
|
-
// type SchemaType = typeof schema;
|
|
65
|
-
|
|
66
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
67
|
-
// const entries = Object.entries(schema.shape) as [keyof SchemaType["shape"], z.ZodTypeAny][];
|
|
68
|
-
// const newProps = entries.reduce(
|
|
69
|
-
// (acc, [key, value]) => {
|
|
70
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
71
|
-
// acc[key] = value instanceof z.ZodOptional ? value.unwrap().nullable() : value;
|
|
72
|
-
// return acc;
|
|
73
|
-
// },
|
|
74
|
-
// {} as {
|
|
75
|
-
// [key in keyof SchemaType["shape"]]: SchemaType["shape"][key] extends z.ZodOptional<infer T>
|
|
76
|
-
// ? z.ZodNullable<T>
|
|
77
|
-
// : SchemaType["shape"][key];
|
|
78
|
-
// }
|
|
79
|
-
// );
|
|
80
|
-
|
|
81
|
-
// return z.object(newProps);
|
|
82
|
-
// }
|
package/src/utils/common.ts
CHANGED
|
@@ -30,6 +30,20 @@ export type Defined<T> = T extends null | undefined ? never : T;
|
|
|
30
30
|
// Makes specific properties in the type required
|
|
31
31
|
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
|
32
32
|
|
|
33
|
+
type PickOptional<T> = {
|
|
34
|
+
[P in keyof T as undefined extends T[P] ? P : never]: T[P];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type PickNotOptional<T> = {
|
|
38
|
+
[P in keyof T as undefined extends T[P] ? never : P]: T[P];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type OptionalToNullable<T> = {
|
|
42
|
+
[K in keyof PickOptional<T>]-?: Exclude<T[K], undefined> | null;
|
|
43
|
+
} & {
|
|
44
|
+
[K in keyof PickNotOptional<T>]: T[K];
|
|
45
|
+
};
|
|
46
|
+
|
|
33
47
|
export function forceUnwrapNullish<T>(value: Nullish<T>): T {
|
|
34
48
|
if (value === null) throw new Error("Illegal null");
|
|
35
49
|
if (value === undefined) throw new Error("Illegal undefined");
|
|
@@ -172,6 +186,32 @@ export function recordToMap<V>(record: Record<string, V>): Map<string, V> {
|
|
|
172
186
|
return map;
|
|
173
187
|
}
|
|
174
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Applies direct properties from `update` to `object`.
|
|
191
|
+
*
|
|
192
|
+
* - In case a property is not defined in `update`, it `object` will retain the current one
|
|
193
|
+
* - In case a property is null in `update`, it will be removed from `object`
|
|
194
|
+
*
|
|
195
|
+
* @param object base object to perform updates on
|
|
196
|
+
* @param update source of property updates
|
|
197
|
+
* @returns object by merging updates from `update` into `object`
|
|
198
|
+
*/
|
|
199
|
+
export function applyShallowObjectUpdate<T>(object: T, update: Partial<OptionalToNullable<T>>): T {
|
|
200
|
+
const objectShallowCopy = { ...object };
|
|
201
|
+
|
|
202
|
+
for (const [key, value] of Object.entries(update)) {
|
|
203
|
+
if (value === null) {
|
|
204
|
+
// @ts-expect-error it's very hard to get typescript to believe that the types will match
|
|
205
|
+
objectShallowCopy[key] = undefined;
|
|
206
|
+
} else if (value !== undefined) {
|
|
207
|
+
// @ts-expect-error it's very hard to get typescript to believe that the types will match
|
|
208
|
+
objectShallowCopy[key] = value;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return objectShallowCopy;
|
|
213
|
+
}
|
|
214
|
+
|
|
175
215
|
export type Pagination = {
|
|
176
216
|
skip?: number;
|
|
177
217
|
take?: number;
|