Skip to content

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

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

Conversation

lerouxb
Copy link
Collaborator

@lerouxb lerouxb commented Mar 19, 2025

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:

~/mongo/mongosh/packages/shell-api % npm link
~/mongo/devtools-shared % npm link @mongosh/shell-api -w @mongodb-js/mongodb-ts-autocomplete
npm run extract-types

@lerouxb lerouxb force-pushed the add-autocomplete-package branch from 24c2ad2 to 8b624a4 Compare March 19, 2025 12:32
@lerouxb lerouxb marked this pull request as draft March 19, 2025 12:33
@lerouxb lerouxb added the wip label Mar 19, 2025
@lerouxb lerouxb force-pushed the add-autocomplete-package branch from 185e497 to 6d9a9d7 Compare March 20, 2025 15:47
@lerouxb lerouxb marked this pull request as ready for review April 2, 2025 15:40
@lerouxb lerouxb changed the title feat: add autocomplete package MONGOSH-2034 feat: add mongodb-ts-autocomplete package MONGOSH-2034 Apr 2, 2025
import path from 'path';

function replaceImports(code: string) {
// This just makes it possible to work on mql.ts because then the
Copy link
Collaborator Author

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.

@lerouxb lerouxb mentioned this pull request May 2, 2025
3 tasks
([collectionName, schema]) => {
const def: string = schema ? toTypescriptTypeDefinition(schema) : `{}`;
const lines = def.split(/\n/g).map((line) => ` ${line}`);
return ` '${collectionName}': {
Copy link
Collaborator

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

Suggested change
return ` '${collectionName}': {
return ` ${JSON.stringify(collectionName)}: {

?

Copy link
Collaborator Author

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}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto?

Suggested change
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())})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants