[WIP] feat: generate TypeScript from MongoDBJSONSchema or JSON Schemas MONGOSH-2058#236
Closed
[WIP] feat: generate TypeScript from MongoDBJSONSchema or JSON Schemas MONGOSH-2058#236
Conversation
lerouxb
commented
Mar 13, 2025
| export type StandardJSONSchema = JSONSchema4; | ||
|
|
||
| export type MongoDBJSONSchema = Pick<StandardJSONSchema, 'title' | 'required' | 'description'> & { | ||
| export type MongoDBJSONSchema = Partial<StandardJSONSchema> & Pick<StandardJSONSchema, 'title' | 'required' | 'description'> & { |
Contributor
Author
There was a problem hiding this comment.
Still allowing all JSON Schema fields so that things like JSON Schema's type can be used.
|
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. |
Contributor
Author
|
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. |
Contributor
Author
|
ok I'll close this and move the code to the mongodb-ts-autocomplete package I'm adding to devtools-shared. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.