Skip to content

Commit 6d9a9d7

Browse files
committed
at least structure the files as they will end up
1 parent dcc6cc0 commit 6d9a9d7

File tree

10 files changed

+97
-60
lines changed

10 files changed

+97
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
// TODO: this file would be generated and include the typescript code as strings
5+
// rather than reading them from disk
6+
function loadFiles() {
7+
return {
8+
'bson.d.ts': fs.readFileSync(
9+
path.join(__dirname, 'fixtures', 'bson.d.ts'),
10+
'utf8'
11+
),
12+
'bson-expressions.d.ts': fs.readFileSync(
13+
path.join(__dirname, 'fixtures', 'bson-expressions.d.ts'),
14+
'utf8'
15+
),
16+
'mql.d.ts': fs.readFileSync(
17+
path.join(__dirname, 'fixtures', 'mql.d.ts'),
18+
'utf8'
19+
),
20+
'shell-api.d.ts': fs.readFileSync(
21+
path.join(__dirname, 'fixtures', 'shell-api.d.ts'),
22+
'utf8'
23+
),
24+
};
25+
}
26+
27+
export default loadFiles;

packages/mongodb-ts-autocomplete/src/bson-expressions.ts

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// TODO: everything in here is just a very minimal stub until we can generate
2+
// this file from the real bson expression types we'll get in MONGOSH-2032
3+
4+
/* eslint-disable @typescript-eslint/triple-slash-reference */
5+
/// <reference path="bson.d.ts" />
6+
7+
export {}; // turns this into an "external module"
8+
9+
declare global {
10+
export function ObjectId(id: string): BSON.ObjectId;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// TODO: everything in here is just a very minimal stub until we can generate
2+
// this file from the real bson types
3+
4+
export {}; // turns this into an "external module"
5+
6+
// this has to be global otherwise the other files won't be able to use the
7+
// namespace
8+
declare global {
9+
export namespace BSON {
10+
export type ObjectId = {
11+
toString: () => string;
12+
};
13+
}
14+
}

packages/mongodb-ts-autocomplete/src/mock-shell-api.d.ts renamed to packages/mongodb-ts-autocomplete/src/fixtures/mql.d.ts

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// TODO: everything in here is just a very minimal stub until we can generate
2+
// this file from the work in MONGOSH-2030
3+
14
export {}; // turns this into an "external module"
25

6+
// this has to be global otherwise the other files won't be able to use the
7+
// namespace
38
declare global {
4-
namespace ShellAPI {
9+
export namespace MQL {
510
// TODO: most of these are actually MQL
611
export interface Document {
712
[key: string]: any;
@@ -37,23 +42,5 @@ declare global {
3742
};
3843

3944
export type Pipeline<T> = Array<Match<T> | Project<T> | Lookup<T, any>>;
40-
41-
export interface Collection<T> {
42-
find(query: Filter<T>): Cursor<T>;
43-
findOne(query: Filter<T>): T;
44-
aggregate(pipeline: Pipeline<T>): Cursor<T>;
45-
insertOne(value: T): void;
46-
insertMany(value: Array<T>): void;
47-
updateOne(query: Filter<T>, modifier: Partial<T> | Pipeline<T>): void;
48-
updateMany(query: Filter<T>, modifier: Partial<T> | Pipeline<T>): void;
49-
}
50-
51-
export interface Database {
52-
runCommand(cmd: string | Document, options: Document): Document;
53-
}
5445
}
55-
}
56-
57-
// NOTE: there are no globals declared yet. db and others will be generated
58-
// separately based on the the current database/collection/aggregation/whatever
59-
// that's being accessed. Those just use these types.
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// TODO: everything in here is just a very minimal stub until we can generate
2+
// this file from the work in MONGOSH-2031
3+
4+
/* eslint-disable @typescript-eslint/triple-slash-reference */
5+
/// <reference path="mql.d.ts" />
6+
7+
export {}; // turns this into an "external module"
8+
9+
declare global {
10+
namespace ShellAPI {
11+
export interface Collection<T> {
12+
find(query: MQL.Filter<T>): MQL.Cursor<T>;
13+
findOne(query: MQL.Filter<T>): T;
14+
aggregate(pipeline: MQL.Pipeline<T>): MQL.Cursor<T>;
15+
insertOne(value: T): void;
16+
insertMany(value: MQL.Array<T>): void;
17+
updateOne(
18+
query: MQL.Filter<T>,
19+
modifier: Partial<T> | MQL.Pipeline<T>
20+
): void;
21+
updateMany(
22+
query: MQL.Filter<T>,
23+
modifier: Partial<T> | MQL.Pipeline<T>
24+
): void;
25+
}
26+
27+
export interface Database {
28+
runCommand(
29+
cmd: string | MQL.Document,
30+
options: MQL.Document
31+
): MQL.Document;
32+
}
33+
}
34+
}

packages/mongodb-ts-autocomplete/src/index.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('MongoDBAutocompleter', function () {
5757
{
5858
kind: 'function',
5959
name: 'ObjectId',
60-
type: 'ObjectId',
60+
type: 'BSON.ObjectId',
6161
},
6262
]);
6363
});
@@ -88,7 +88,7 @@ describe('MongoDBAutocompleter', function () {
8888
{
8989
kind: 'method',
9090
name: 'runCommand',
91-
type: 'Document',
91+
type: 'MQL.Document',
9292
},
9393
]);
9494
});

packages/mongodb-ts-autocomplete/src/index.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import type {
33
AutocompleterOptions,
44
AutoCompletion,
55
} from '@mongodb-js/ts-autocomplete';
6-
import { loadShellAPI } from './shell-api';
7-
import { loadBSONExpressions } from './bson-expressions';
6+
import loadFiles from './autocompleter-types';
87

98
import type { JSONSchema } from './type-export';
109
import { toTypescriptTypeDefinition } from './type-export';
@@ -136,15 +135,7 @@ export default class MongoDBAutocompleter {
136135
this.connectionSchemas = Object.create(null);
137136
this.connectionSchemas;
138137

139-
// TODO: set the @mongodb-js/mql-typescript definitions (will this be separate or part of shell-api?)
140-
// these aren't globals because they are types, so probably only make sense
141-
// in combination with either the shell-api or something like a document or
142-
// aggregation editor
143-
144-
this.autocompleter.updateCode({
145-
'bson-expressions.d.ts': loadBSONExpressions(),
146-
});
147-
this.autocompleter.updateCode({ 'shell-api.d.ts': loadShellAPI() });
138+
this.autocompleter.updateCode(loadFiles());
148139
}
149140

150141
addConnection(connectionId: string): ConnectionSchema {

packages/mongodb-ts-autocomplete/src/mock-bson-expressions.d.ts

-9
This file was deleted.

packages/mongodb-ts-autocomplete/src/shell-api.ts

-8
This file was deleted.

0 commit comments

Comments
 (0)