Skip to content

Commit 0c11fc6

Browse files
committed
refactor: allow only history()
1 parent c6fe835 commit 0c11fc6

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -572,22 +572,6 @@ describe('MongoshNodeRepl', function () {
572572
)
573573
);
574574
});
575-
576-
it('works without ()', async function () {
577-
output = '';
578-
input.write('history\n');
579-
await waitEval(bus);
580-
expect(output).includes(
581-
formatOutput(
582-
{
583-
value: getAllHistoryItems()
584-
.slice(1, getAllHistoryItems().length)
585-
.reverse(),
586-
},
587-
{ colors: true, maxArrayLength: Infinity }
588-
)
589-
);
590-
});
591575
});
592576

593577
it('looks up existing entries, if there are any', async function () {

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class MongoshNodeRepl implements EvaluationListener {
397397
}
398398

399399
setupHistoryCommand(): void {
400-
const getHistory = () => {
400+
const history = () => {
401401
// eslint-disable-next-line @typescript-eslint/no-explicit-any
402402
const replHistory: string[] = (this.runtimeState().repl as any).history;
403403
const formattedHistory =
@@ -408,7 +408,7 @@ class MongoshNodeRepl implements EvaluationListener {
408408
formattedHistory[util.inspect.custom as any] = (() => {
409409
return formatOutput(
410410
{
411-
// The value of the format has to be a copy of the history to avoid circular references.
411+
// Providing a copy of the history avoids a circular reference.
412412
value: formattedHistory.concat(),
413413
},
414414
{ colors: true, maxArrayLength: Infinity }
@@ -418,20 +418,7 @@ class MongoshNodeRepl implements EvaluationListener {
418418
return formattedHistory;
419419
};
420420

421-
getHistory.isDirectShellCommand = true;
422-
getHistory.returnsPromise = false;
423-
getHistory.acceptsRawInput = true;
424-
425-
this.runtimeState().context.history =
426-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
427-
(this.runtimeState().instanceState.shellApi as any).history = getHistory;
428-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
429-
(signatures.ShellApi.attributes as any).history = {
430-
type: 'function',
431-
returnsPromise: true,
432-
isDirectShellCommand: true,
433-
acceptsRawInput: true,
434-
} as TypeSignature;
421+
this.runtimeState().context.history = history;
435422
}
436423

437424
private async finishInitializingNodeRepl(): Promise<void> {

0 commit comments

Comments
 (0)