Skip to content

[WIP] feat: generate TypeScript from MongoDBJSONSchema or JSON Schemas MONGOSH-2058 #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Mar 13, 2025

Still very WIP - at a minimum needs lots more tests and there are some open questions.

Loosely inspired by the type generation from @kmruiz PoC https://github.com/mongodb-js/poc-mongodb-autocomplete/blob/main/src/type-export/index.ts#L191-L197

This takes a MongoDBJSONShema which is our superset of JSON Schema or just a JSON Schema and it turns it into TypeScript code for a Collection described by the schema.

Not sure what we'd call the BSON types. I have them as bson.Blah, but they might just be globals? Or will that clash with the BSON expressions? Obviously this now also depends on those types existing which is still TODO in other tickets.

@@ -3,7 +3,7 @@ import { InternalSchema } from '.';

export type StandardJSONSchema = JSONSchema4;

export type MongoDBJSONSchema = Pick<StandardJSONSchema, 'title' | 'required' | 'description'> & {
export type MongoDBJSONSchema = Partial<StandardJSONSchema> & Pick<StandardJSONSchema, 'title' | 'required' | 'description'> & {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still allowing all JSON Schema fields so that things like JSON Schema's type can be used.

@kmruiz
Copy link

kmruiz commented Mar 13, 2025

I'm not sure about this approach: we are not generating a MongoDB schema, essentially we are generating the types can be used to query a collection, which requires the schema, but it's not the schema. I would implement this in the autocomplete package that we are building instead of here.

@lerouxb
Copy link
Contributor Author

lerouxb commented Mar 13, 2025

Yeah I wasn't sure where would be best to put it and I don't mind moving it. By putting it in the autocomplete package we can more easily make our own trade-offs like making things quite loose.

@lerouxb
Copy link
Contributor Author

lerouxb commented Mar 13, 2025

ok I'll close this and move the code to the mongodb-ts-autocomplete package I'm adding to devtools-shared.

@lerouxb lerouxb closed this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants