-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add mongodb-ts-autocomplete package MONGOSH-2034 #520
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
base: main
Are you sure you want to change the base?
Conversation
24c2ad2
to
8b624a4
Compare
185e497
to
6d9a9d7
Compare
import path from 'path'; | ||
|
||
function replaceImports(code: string) { | ||
// This just makes it possible to work on mql.ts because then the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually my stubbed mql.ts file doesn't even use the bson library at the moment, but this will become relevant again once we have the real mql.ts or otherwise use something that depends on loading in the bson library.
([collectionName, schema]) => { | ||
const def: string = schema ? toTypescriptTypeDefinition(schema) : `{}`; | ||
const lines = def.split(/\n/g).map((line) => ` ${line}`); | ||
return ` '${collectionName}': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that collection names can contain quotes, newlines, etc.
Should probably be
return ` '${collectionName}': { | |
return ` ${JSON.stringify(collectionName)}: { |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll change it throughout.
const databaseProperties = Object.entries(this.databaseSchemas).map( | ||
([databaseName, schema]) => { | ||
const def = schema.toTypescriptTypeDefinition(); | ||
return `'${databaseName}': ${def}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
return `'${databaseName}': ${def}`; | |
return `${JSON.stringify(databaseName)}: ${def}`; |
I mean, very generally you always want to JSON.stringify()
when inserting JS values into JS source code, and then if you need to properly handle __proto__
you might even want to do JSON.parse(${JSON.stringify(JSON.stringify())})
Requires:
Currently still works with fake mql types, but the shell-api ones are at least the real ones.
TODO: separate tickets
Until the shell-api PR lands: