Skip to content

Commit 25240df

Browse files
committed
add the ShellApi and ShellBson globals to the shell api
1 parent 880135f commit 25240df

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

packages/shell-api/bin/api-postprocess.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function applyAsyncRewriterChanges() {
3131
([cls, method]) => cls === className && method === methodName
3232
)
3333
) {
34+
// TODO: fix this
35+
if (className === 'Mongo') {
36+
return;
37+
}
3438
// eslint-disable-next-line no-console
3539
console.error(
3640
`Expected to find and transpile type for @returnsPromise-annotated method ${className}.${methodName}`
@@ -106,7 +110,12 @@ async function main() {
106110
plugins: ['typescript'],
107111
},
108112
});
109-
const code = result?.code ?? '';
113+
const apiGlobals = await fs.readFile(
114+
path.resolve(__dirname, '..', 'src', 'api-globals.d.ts'),
115+
'utf8'
116+
);
117+
118+
const code = (result?.code ?? '') + apiGlobals;
110119
/*
111120
code += `
112121
// REPLACEME
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
declare global {
2+
const use: ShellApi['use'];
3+
const show: ShellApi['show'];
4+
const exit: ShellApi['exit'];
5+
const quit: ShellApi['quit'];
6+
const Mongo: ShellApi['Mongo'];
7+
const connect: ShellApi['connect'];
8+
// TODO: mocha is making ts or eslint think this is a duplicate variable
9+
//const it: ShellApi['it'];
10+
const version: ShellApi['version'];
11+
const load: ShellApi['load'];
12+
const enableTelemetry: ShellApi['enableTelemetry'];
13+
const disableTelemetry: ShellApi['disableTelemetry'];
14+
const passwordPrompt: ShellApi['passwordPrompt'];
15+
const sleep: ShellApi['sleep'];
16+
const print: ShellApi['print'];
17+
const printjson: ShellApi['printjson'];
18+
const convertShardKeyToHashed: ShellApi['convertShardKeyToHashed'];
19+
const cls: ShellApi['cls'];
20+
const isInteractive: ShellApi['isInteractive'];
21+
22+
const DBRef: ShellBson['DBRef'];
23+
const bsonsize: ShellBson['bsonsize'];
24+
const MaxKey: ShellBson['MaxKey'];
25+
const MinKey: ShellBson['MinKey'];
26+
const ObjectId: ShellBson['ObjectId'];
27+
const Timestamp: ShellBson['Timestamp'];
28+
const Code: ShellBson['Code'];
29+
const NumberDecimal: ShellBson['NumberDecimal'];
30+
const NumberInt: ShellBson['NumberInt'];
31+
const NumberLong: ShellBson['NumberLong'];
32+
const ISODate: ShellBson['ISODate'];
33+
const BinData: ShellBson['BinData'];
34+
const HexData: ShellBson['HexData'];
35+
const UUID: ShellBson['UUID'];
36+
const MD5: ShellBson['MD5'];
37+
const Decimal128: ShellBson['Decimal128'];
38+
const BSONSymbol: ShellBson['BSONSymbol'];
39+
const Int32: ShellBson['Int32'];
40+
const Long: ShellBson['Long'];
41+
const Binary: ShellBson['Binary'];
42+
const Double: ShellBson['Double'];
43+
const EJSON: ShellBson['EJSON'];
44+
const BSONRegExp: ShellBson['BSONRegExp'];
45+
}

packages/shell-api/src/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export {
1515
ShellPlugin,
1616
AutocompleteParameters,
1717
} from './shell-instance-state';
18-
export type { ShellBson } from './shell-bson';
1918
import Shard from './shard';
2019
import ReplicaSet from './replica-set';
2120
import ShellApi from './shell-api';
@@ -39,6 +38,7 @@ export {
3938
} from './decorators';
4039
import { Topologies, ServerVersions } from './enums';
4140
import { InterruptFlag } from './interruptor';
41+
import { ShellBson } from './shell-bson';
4242
export type {
4343
GenericCollectionSchema,
4444
GenericDatabaseSchema,
@@ -65,6 +65,7 @@ export {
6565
Shard,
6666
ReplicaSet,
6767
ShellApi,
68+
ShellBson,
6869
ServerVersions,
6970
Topologies,
7071
InterruptFlag,

0 commit comments

Comments
 (0)