Skip to content

Commit af124da

Browse files
committed
add type
1 parent fe33cf3 commit af124da

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-data-modeling/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"react-redux": "^8.1.3",
7474
"redux": "^4.2.1",
7575
"redux-thunk": "^2.4.2",
76-
"zod": "^3.25.1"
76+
"zod": "^3.24.4"
7777
},
7878
"devDependencies": {
7979
"@mongodb-js/eslint-config-compass": "^1.3.8",

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const editorContainerApplyContainerStyles = css({
8888
gap: spacing[200],
8989
display: 'flex',
9090
width: '100%',
91-
height: spacing[1200],
91+
height: spacing[100],
9292
});
9393

9494
const editorContainerPlaceholderButtonStyles = css({

packages/compass-data-modeling/src/services/data-model-storage-electron.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DataModelStorageElectron implements DataModelStorage {
2424
async loadAll(): Promise<MongoDBDataModelDescription[]> {
2525
try {
2626
const res = await this.userData.readAll();
27-
return res.data;
27+
return res.data as MongoDBDataModelDescription[];
2828
} catch (err) {
2929
return [];
3030
}

packages/compass-data-modeling/src/services/data-model-storage.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from '@mongodb-js/compass-user-data';
2+
import type { MongoDBJSONSchema } from 'mongodb-schema';
23
import type { ZodError } from 'zod';
34

45
export const RelationshipSideSchema = z.object({
@@ -21,7 +22,7 @@ export const StaticModelSchema = z.object({
2122
collections: z.array(
2223
z.object({
2324
ns: z.string(),
24-
jsonSchema: z.unknown(), // MongoDBJSONSchema is not directly representable in zod
25+
jsonSchema: z.unknown(), // skipped for simplicity
2526
indexes: z.array(z.record(z.unknown())),
2627
shardKey: z.record(z.unknown()).optional(),
2728
displayPosition: z.tuple([z.number(), z.number()]),
@@ -30,7 +31,19 @@ export const StaticModelSchema = z.object({
3031
relationships: z.array(RelationshipSchema),
3132
});
3233

33-
export type StaticModel = z.output<typeof StaticModelSchema>;
34+
export type StaticModel = Omit<
35+
z.output<typeof StaticModelSchema>,
36+
'collections'
37+
> & {
38+
collections: Array<
39+
Omit<
40+
z.output<typeof StaticModelSchema>['collections'][number],
41+
'jsonSchema'
42+
> & {
43+
jsonSchema: MongoDBJSONSchema;
44+
}
45+
>;
46+
};
3447

3548
export const EditSchema = z.discriminatedUnion('type', [
3649
z.object({
@@ -53,6 +66,15 @@ export const EditSchema = z.discriminatedUnion('type', [
5366
}),
5467
]);
5568

69+
type BaseEdit = z.output<typeof EditSchema>;
70+
type SetModelEdit = Omit<Extract<BaseEdit, { type: 'SetModel' }>, 'model'> & {
71+
model: StaticModel;
72+
};
73+
74+
export type Edit =
75+
| SetModelEdit
76+
| Extract<BaseEdit, { type: 'AddRelationship' | 'RemoveRelationship' }>;
77+
5678
export const validateEdit = (
5779
edit: unknown
5880
): { result: true; errors?: never } | { result: false; errors: string[] } => {
@@ -71,8 +93,6 @@ export const validateEdit = (
7193
}
7294
};
7395

74-
export type Edit = z.output<typeof EditSchema>;
75-
7696
export const MongoDBDataModelDescriptionSchema = z.object({
7797
id: z.string(),
7898
name: z.string(),
@@ -87,9 +107,12 @@ export const MongoDBDataModelDescriptionSchema = z.object({
87107
edits: z.array(EditSchema).default([]),
88108
});
89109

90-
export type MongoDBDataModelDescription = z.output<
91-
typeof MongoDBDataModelDescriptionSchema
92-
>;
110+
export type MongoDBDataModelDescription = Omit<
111+
z.output<typeof MongoDBDataModelDescriptionSchema>,
112+
'edits'
113+
> & {
114+
edits: Array<Edit>;
115+
};
93116

94117
export interface DataModelStorage {
95118
save(description: MongoDBDataModelDescription): Promise<boolean>;

0 commit comments

Comments
 (0)