Skip to content
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

feat: add analyzeDocuments + SchemaAccessor COMPASS-8799 #216

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

paula-stacho
Copy link

@paula-stacho paula-stacho commented Jan 16, 2025

Adding analyzeDocuments() -> SchemaAccessor as prep for having multiple formats. The interface has been chosen so that:

  • the conversion to different formats happens only when requested, and only once
  • if we switch to analysis which uses $jsonSchema as the base format, the interface can stay the same

see the tech design for more details.

@paula-stacho paula-stacho marked this pull request as ready for review January 16, 2025 12:16
@paula-stacho paula-stacho changed the title feat: add SchemaAccessor COMPASS-8799 feat: add analyzeDocuments + SchemaAccessor COMPASS-8799 Jan 16, 2025
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

Looking good, left a couple comments/suggestions

options: {
signal?: AbortSignal
}): ExtendedJSONSchema {
// TODO: COMPASS-8702
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit apprehensive about merging this to main - if we find out we want to do a release of some other fix in the meantime before this TODO is completed then we'd effectively be releasing something that doesn't work.
I don't think we chatted about this in the technical design. How would you feel about having a separate branch that we merge this branch and all of these various accessors to before we merge them into main to avoid that?
Again it's mostly only us using this package, but it can be a good practice to follow. We did a similar thing with the copilot agent in VSCode: mongodb-js/vscode#839


export type StandardJSONSchema = JSONSchema4;

export type MongodbJSONSchema = Pick<StandardJSONSchema, 'title' | 'required' | 'description'> & {
Copy link
Member

Choose a reason for hiding this comment

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

A total nit question, how do you feel about MongoDBJSONSchema? I suppose it is a lot of uppercase letters in a row though lol. I think we typically write MongoDB with the uppercase DB in our code in Compass, and it looks like the driver does too at least with MongoDBNamespace. Same question with the related functions.

private signal?: AbortSignal;

constructor(internalSchema: InternalSchema, signal?: AbortSignal) {
this.signal = signal;
Copy link
Member

@Anemy Anemy Jan 17, 2025

Choose a reason for hiding this comment

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

Is there a benefit for us saving the signal here and using it in the accessors verses having the accessors receive the signal as one of their arguments?
I'm thinking it may be more flexible to have the various accessors receive a signal in their function arguments in case the consumer of this wants to say start a schema retrieval, then abort it because the user clicked cancel or something, and then start a different one.

return source;
}

export async function getCompletedSchemaAnalyzer(
Copy link
Member

@Anemy Anemy Jan 17, 2025

Choose a reason for hiding this comment

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

nit: I like to avoid adding functions to util files when possible as I feel they can sometimes absorb a lot of the code and overtime that can make discovery more difficult. Would it make sense to move these functions to the schema-analyzer.ts file? No changes needed, mostly a thought/suggestion. Also I should mention I like not having much code in index.ts files so I'm happy these are at least not there anymore!

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