Skip to content

Commit 1edc212

Browse files
committed
move it back
1 parent b7bba92 commit 1edc212

File tree

5 files changed

+78
-75
lines changed

5 files changed

+78
-75
lines changed

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-repl/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"js-yaml": "^4.1.0",
8888
"mongodb-connection-string-url": "^3.0.1",
8989
"mongodb-log-writer": "^2.3.1",
90-
"mongodb-schema": "^12.6.2",
9190
"numeral": "^2.0.6",
9291
"pretty-repl": "^4.0.1",
9392
"semver": "^7.5.4",

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ import { installPasteSupport } from './repl-paste-support';
5050
import util from 'util';
5151

5252
import { MongoDBAutocompleter } from '@mongodb-js/mongodb-ts-autocomplete';
53-
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
54-
import type { JSONSchema } from 'mongodb-schema';
55-
import { analyzeDocuments } from 'mongodb-schema';
5653

5754
declare const __non_webpack_require__: any;
5855

@@ -436,73 +433,6 @@ class MongoshNodeRepl implements EvaluationListener {
436433
this.runtimeState().context.history = history;
437434
}
438435

439-
public getAutocompletionContext(
440-
instanceState: ShellInstanceState
441-
): AutocompletionContext {
442-
return {
443-
currentDatabaseAndConnection: () => {
444-
return {
445-
connectionId: instanceState.currentDb.getMongo()._getConnectionId(),
446-
databaseName: instanceState.currentDb.getName(),
447-
};
448-
},
449-
databasesForConnection: async (
450-
connectionId: string
451-
): Promise<string[]> => {
452-
const mongo = instanceState.getMongoByConnectionId(connectionId);
453-
try {
454-
const dbNames = await mongo._getDatabaseNamesForCompletion();
455-
return dbNames.filter(
456-
(name: string) => !CONTROL_CHAR_REGEXP.test(name)
457-
);
458-
} catch (err: any) {
459-
// TODO: move this code to a method in the shell instance so we don't
460-
// have to hardcode the error code or export it.
461-
if (err?.code === 'SHAPI-10004' || err?.codeName === 'Unauthorized') {
462-
return [];
463-
}
464-
throw err;
465-
}
466-
},
467-
collectionsForDatabase: async (
468-
connectionId: string,
469-
databaseName: string
470-
): Promise<string[]> => {
471-
const mongo = instanceState.getMongoByConnectionId(connectionId);
472-
try {
473-
const collectionNames = await mongo
474-
._getDb(databaseName)
475-
._getCollectionNamesForCompletion();
476-
return collectionNames.filter(
477-
(name: string) => !CONTROL_CHAR_REGEXP.test(name)
478-
);
479-
} catch (err: any) {
480-
// TODO: move this code to a method in the shell instance so we don't
481-
// have to hardcode the error code or export it.
482-
if (err?.code === 'SHAPI-10004' || err?.codeName === 'Unauthorized') {
483-
return [];
484-
}
485-
throw err;
486-
}
487-
},
488-
schemaInformationForCollection: async (
489-
connectionId: string,
490-
databaseName: string,
491-
collectionName: string
492-
): Promise<JSONSchema> => {
493-
const mongo = instanceState.getMongoByConnectionId(connectionId);
494-
const docs = await mongo
495-
._getDb(databaseName)
496-
.getCollection(collectionName)
497-
._getSampleDocsForCompletion();
498-
const schemaAccessor = await analyzeDocuments(docs);
499-
500-
const schema = await schemaAccessor.getMongoDBJsonSchema();
501-
return schema;
502-
},
503-
};
504-
}
505-
506436
private async finishInitializingNodeRepl(): Promise<void> {
507437
const { repl, instanceState } = this.runtimeState();
508438
if (!repl) return;
@@ -516,7 +446,7 @@ class MongoshNodeRepl implements EvaluationListener {
516446
) => Promise<[string[], string, 'exclusive'] | [string[], string]>;
517447
if (process.env.USE_NEW_AUTOCOMPLETE) {
518448
const autocompletionContext =
519-
this.getAutocompletionContext(instanceState);
449+
instanceState.getAutocompletionContext(instanceState);
520450
newMongoshCompleter = new MongoDBAutocompleter({
521451
context: autocompletionContext,
522452
});

packages/shell-api/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@
5858
"@mongosh/history": "2.4.6",
5959
"@mongosh/i18n": "^2.13.1",
6060
"@mongosh/service-provider-core": "3.3.3",
61-
"mongodb-redact": "^1.1.5"
61+
"mongodb-redact": "^1.1.5",
62+
"mongodb-schema": "^12.6.2"
6263
},
6364
"devDependencies": {
6465
"@microsoft/api-extractor": "^7.39.3",
6566
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
67+
"@mongodb-js/mongodb-ts-autocomplete": "^0.2.2",
6668
"@mongodb-js/prettier-config-devtools": "^1.0.1",
6769
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
6870
"@mongosh/types": "3.6.2",

packages/shell-api/src/shell-instance-state.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import constructShellBson from './shell-bson';
3737
import { Streams } from './streams';
3838
import { ShellLog } from './shell-log';
3939

40+
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
41+
import type { JSONSchema } from 'mongodb-schema';
42+
import { analyzeDocuments } from 'mongodb-schema';
43+
4044
/**
4145
* The subset of CLI options that is relevant for the shell API's behavior itself.
4246
*/
@@ -411,6 +415,73 @@ export class ShellInstanceState {
411415
throw new Error(`mongo with connection id ${connectionId} not found`);
412416
}
413417

418+
public getAutocompletionContext(
419+
instanceState: ShellInstanceState
420+
): AutocompletionContext {
421+
return {
422+
currentDatabaseAndConnection: () => {
423+
return {
424+
connectionId: instanceState.currentDb.getMongo()._getConnectionId(),
425+
databaseName: instanceState.currentDb.getName(),
426+
};
427+
},
428+
databasesForConnection: async (
429+
connectionId: string
430+
): Promise<string[]> => {
431+
const mongo = instanceState.getMongoByConnectionId(connectionId);
432+
try {
433+
const dbNames = await mongo._getDatabaseNamesForCompletion();
434+
return dbNames.filter(
435+
(name: string) => !CONTROL_CHAR_REGEXP.test(name)
436+
);
437+
} catch (err: any) {
438+
// TODO: move this code to a method in the shell instance so we don't
439+
// have to hardcode the error code or export it.
440+
if (err?.code === 'SHAPI-10004' || err?.codeName === 'Unauthorized') {
441+
return [];
442+
}
443+
throw err;
444+
}
445+
},
446+
collectionsForDatabase: async (
447+
connectionId: string,
448+
databaseName: string
449+
): Promise<string[]> => {
450+
const mongo = instanceState.getMongoByConnectionId(connectionId);
451+
try {
452+
const collectionNames = await mongo
453+
._getDb(databaseName)
454+
._getCollectionNamesForCompletion();
455+
return collectionNames.filter(
456+
(name: string) => !CONTROL_CHAR_REGEXP.test(name)
457+
);
458+
} catch (err: any) {
459+
// TODO: move this code to a method in the shell instance so we don't
460+
// have to hardcode the error code or export it.
461+
if (err?.code === 'SHAPI-10004' || err?.codeName === 'Unauthorized') {
462+
return [];
463+
}
464+
throw err;
465+
}
466+
},
467+
schemaInformationForCollection: async (
468+
connectionId: string,
469+
databaseName: string,
470+
collectionName: string
471+
): Promise<JSONSchema> => {
472+
const mongo = instanceState.getMongoByConnectionId(connectionId);
473+
const docs = await mongo
474+
._getDb(databaseName)
475+
.getCollection(collectionName)
476+
._getSampleDocsForCompletion();
477+
const schemaAccessor = await analyzeDocuments(docs);
478+
479+
const schema = await schemaAccessor.getMongoDBJsonSchema();
480+
return schema;
481+
},
482+
};
483+
}
484+
414485
public getAutocompleteParameters(): AutocompleteParameters {
415486
return {
416487
topology: () => {

0 commit comments

Comments
 (0)