Skip to content

Commit 0f448e3

Browse files
committed
wip
1 parent 02c5921 commit 0f448e3

File tree

5 files changed

+98
-14
lines changed

5 files changed

+98
-14
lines changed

package-lock.json

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

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
import { z } from '@mongodb-js/compass-user-data';
22

3+
export const RelationshipSideSchema = z.object({
4+
ns: z.string(),
5+
cardinality: z.number(),
6+
fields: z.array(z.string()),
7+
});
8+
9+
export type RelationshipSide = z.output<typeof RelationshipSideSchema>;
10+
11+
export const RelationshipSchema = z.object({
12+
id: z.string(),
13+
relationship: z.tuple([RelationshipSideSchema, RelationshipSideSchema]),
14+
isInferred: z.boolean(),
15+
});
16+
17+
export type Relationship = z.output<typeof RelationshipSchema>;
18+
19+
export const StaticModelSchema = z.object({
20+
collections: z.array(
21+
z.object({
22+
ns: z.string(),
23+
jsonSchema: z.unknown(), // MongoDBJSONSchema is not directly representable in zod
24+
indexes: z.array(z.record(z.unknown())),
25+
shardKey: z.record(z.unknown()).optional(),
26+
displayPosition: z.tuple([z.number(), z.number()]),
27+
})
28+
),
29+
relationships: z.array(RelationshipSchema),
30+
});
31+
32+
export type StaticModel = z.output<typeof StaticModelSchema>;
33+
34+
export const EditSchema = z.discriminatedUnion('type', [
35+
z.object({
36+
type: z.literal('SetModel'),
37+
id: z.string(),
38+
timestamp: z.string(),
39+
model: StaticModelSchema,
40+
}),
41+
z.object({
42+
type: z.literal('AddRelationship'),
43+
id: z.string(),
44+
timestamp: z.string(),
45+
relationship: RelationshipSchema,
46+
}),
47+
z.object({
48+
type: z.literal('RemoveRelationship'),
49+
id: z.string(),
50+
timestamp: z.string(),
51+
}),
52+
]);
53+
54+
export type Edit = z.output<typeof EditSchema>;
55+
356
export const MongoDBDataModelDescriptionSchema = z.object({
457
id: z.string(),
558
name: z.string(),
@@ -11,8 +64,7 @@ export const MongoDBDataModelDescriptionSchema = z.object({
1164
*/
1265
connectionId: z.string().nullable(),
1366

14-
// TODO: define rest of the schema based on arch doc / tech design
15-
edits: z.array(z.unknown()).default([]),
67+
edits: z.array(EditSchema).default([]),
1668
});
1769

1870
export type MongoDBDataModelDescription = z.output<

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Reducer } from 'redux';
22
import { UUID } from 'bson';
33
import { isAction } from './util';
4-
import type { MongoDBDataModelDescription } from '../services/data-model-storage';
4+
import type {
5+
Edit,
6+
MongoDBDataModelDescription,
7+
} from '../services/data-model-storage';
58
import { AnalysisProcessActionTypes } from './analysis-process';
69
import { memoize } from 'lodash';
710
import type { DataModelingState, DataModelingThunkAction } from './reducer';
@@ -10,9 +13,9 @@ import { showConfirmation, showPrompt } from '@mongodb-js/compass-components';
1013
export type DiagramState =
1114
| (Omit<MongoDBDataModelDescription, 'edits'> & {
1215
edits: {
13-
prev: MongoDBDataModelDescription['edits'][];
14-
current: MongoDBDataModelDescription['edits'];
15-
next: MongoDBDataModelDescription['edits'][];
16+
prev: Edit[];
17+
current: Edit[];
18+
next: Edit[];
1619
};
1720
})
1821
| null; // null when no diagram is currently open
@@ -44,7 +47,6 @@ export type RenameDiagramAction = {
4447

4548
export type ApplyEditAction = {
4649
type: DiagramActionTypes.APPLY_EDIT;
47-
// TODO
4850
edit: unknown;
4951
};
5052

packages/compass-preferences-model/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"lodash": "^4.17.21",
6161
"react": "^17.0.2",
6262
"yargs-parser": "^21.1.1",
63-
"zod": "^3.22.3"
63+
"zod": "^3.24.4"
6464
},
6565
"devDependencies": {
6666
"@mongodb-js/eslint-config-compass": "^1.3.8",

packages/compass-user-data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@mongodb-js/compass-logging": "^1.6.9",
5353
"@mongodb-js/compass-utils": "^0.8.8",
5454
"write-file-atomic": "^5.0.1",
55-
"zod": "^3.22.3"
55+
"zod": "^3.24.4"
5656
},
5757
"devDependencies": {
5858
"@mongodb-js/eslint-config-compass": "^1.3.8",

0 commit comments

Comments
 (0)