Skip to content

Commit 198fb06

Browse files
committed
add rs, sh, sp generics
1 parent d81ff54 commit 198fb06

File tree

7 files changed

+173
-38
lines changed

7 files changed

+173
-38
lines changed

packages/shell-api/api-extractor.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3-
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
3+
"mainEntryPointFilePath": "<projectFolder>/lib/api.d.ts",
44
"apiReport": {
55
"enabled": false
66
},
@@ -9,6 +9,7 @@
99
},
1010
"bundledPackages": [
1111
"@mongodb-js/devtools-connect",
12+
"@mongodb-js/devtools-proxy-support",
1213
"@mongodb-js/oidc-plugin",
1314
"@mongosh/arg-parser",
1415
"@mongosh/service-provider-core",
@@ -40,8 +41,11 @@
4041
"addToApiReportFile": false
4142
},
4243
"ae-forgotten-export": {
43-
"logLevel": "error",
44+
"logLevel": "warning",
4445
"addToApiReportFile": false
46+
},
47+
"ae-missing-release-tag": {
48+
"logLevel": "none"
4549
}
4650
},
4751
"tsdocMessageReporting": {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { signatures } from '../';
66

77
function applyAsyncRewriterChanges() {
88
return ({
9+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
910
types: t,
1011
}: {
1112
types: typeof BabelTypes;
@@ -30,6 +31,7 @@ function applyAsyncRewriterChanges() {
3031
([cls, method]) => cls === className && method === methodName
3132
)
3233
) {
34+
// eslint-disable-next-line no-console
3335
console.error(
3436
`Expected to find and transpile type for @returnsPromise-annotated method ${className}.${methodName}`
3537
);
@@ -131,6 +133,11 @@ type MongodbServerSchema = {
131133
declare global {
132134
// second argument optional
133135
var db: Database<MongodbServerSchema, MongodbServerSchema['test']>;
136+
var rs: ReplicaSet<MongodbServerSchema, MongodbServerSchema['test']>;
137+
var sh: Shard<MongodbServerSchema, MongodbServerSchema['test']>;
138+
// not sure this is correct because sp is usually made using static method
139+
// Streams.newInstance(), but here Streams is only a type
140+
var sp: Streams<MongodbServerSchema, MongodbServerSchema['test']>;
134141
135142
var use: (collection: StringKey<MongodbServerSchema>) => void;
136143
}

packages/shell-api/src/api.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// TODO: does it make sense to have all this stuff? Don't we just need enough for the top-level API, ie. the globals?
2+
import AggregationCursor from './aggregation-cursor';
3+
import RunCommandCursor from './run-command-cursor';
4+
export { Collection } from './collection';
5+
import Cursor from './cursor';
6+
import Database, { CollectionNamesWithTypes } from './database';
7+
import Explainable from './explainable';
8+
import ExplainableCursor from './explainable-cursor';
9+
import Help, { HelpProperties } from './help';
10+
export {
11+
ShellInstanceState,
12+
EvaluationListener,
13+
ShellCliOptions,
14+
OnLoadResult,
15+
ShellPlugin,
16+
AutocompleteParameters,
17+
} from './shell-instance-state';
18+
export type { ShellBson } from './shell-bson';
19+
import Shard from './shard';
20+
import ReplicaSet from './replica-set';
21+
import ShellApi from './shell-api';
22+
export {
23+
BulkWriteResult,
24+
CommandResult,
25+
CursorIterationResult,
26+
DeleteResult,
27+
InsertManyResult,
28+
InsertOneResult,
29+
UpdateResult,
30+
} from './result';
31+
import Mongo from './mongo';
32+
export {
33+
signatures,
34+
ShellResult,
35+
toShellResult,
36+
getShellApiType,
37+
TypeSignature,
38+
Namespace,
39+
} from './decorators';
40+
import { Topologies, ServerVersions } from './enums';
41+
import { InterruptFlag } from './interruptor';
42+
export type {
43+
GenericCollectionSchema,
44+
GenericDatabaseSchema,
45+
GenericServerSideSchema,
46+
StringKey,
47+
FindAndModifyMethodShellOptions,
48+
FindAndModifyShellOptions,
49+
RemoveShellOptions,
50+
} from './helpers';
51+
export type { Streams } from './streams';
52+
export type { StreamProcessor } from './stream-processor';
53+
54+
export {
55+
AggregationCursor,
56+
RunCommandCursor,
57+
CollectionNamesWithTypes,
58+
Cursor,
59+
Database,
60+
Explainable,
61+
ExplainableCursor,
62+
Help,
63+
HelpProperties,
64+
Mongo,
65+
Shard,
66+
ReplicaSet,
67+
ShellApi,
68+
ServerVersions,
69+
Topologies,
70+
InterruptFlag,
71+
};
72+
73+
// TODO: do we really want all these?
74+
75+
/*
76+
export { AggregateOrFindCursor } from './aggregate-or-find-cursor';
77+
export {
78+
ServiceProviderFindCursor,
79+
ServiceProviderAggregationCursor,
80+
ReadPreferenceLike,
81+
ReadConcernLevel,
82+
TagSet,
83+
CollationOptions,
84+
HedgeOptions,
85+
ExplainVerbosityLike,
86+
FindOptions,
87+
CountOptions,
88+
DistinctOptions,
89+
FindOneAndDeleteOptions,
90+
FindOneAndReplaceOptions,
91+
FindOneAndUpdateOptions,
92+
UpdateOptions,
93+
CommandOperationOptions,
94+
AggregateOptions
95+
} from '@mongosh/service-provider-core';
96+
export { DatabaseImpl } from './database';
97+
export { CollectionImpl } from './collection';
98+
export { ShellResultSourceInformation, ShellCommandCompleter, Signatures, ShellApiWithMongoClass } from './decorators';
99+
export { MapReduceShellOptions } from './helpers';
100+
101+
// and many more
102+
*/

packages/shell-api/src/index.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import AggregationCursor from './aggregation-cursor';
22
import RunCommandCursor from './run-command-cursor';
3-
export { Collection } from './collection';
3+
import Collection from './collection';
44
import Cursor from './cursor';
55
import Database, { CollectionNamesWithTypes } from './database';
66
import Explainable from './explainable';
77
import ExplainableCursor from './explainable-cursor';
88
import Help, { HelpProperties } from './help';
9-
export {
10-
ShellInstanceState,
9+
import ShellInstanceState, {
1110
EvaluationListener,
1211
ShellCliOptions,
1312
OnLoadResult,
1413
ShellPlugin,
15-
AutocompleteParameters,
1614
} from './shell-instance-state';
17-
export type { ShellBson } from './shell-bson';
1815
import Shard from './shard';
1916
import ReplicaSet from './replica-set';
2017
import ShellApi from './shell-api';
21-
export {
18+
import {
2219
BulkWriteResult,
2320
CommandResult,
2421
CursorIterationResult,
@@ -28,43 +25,49 @@ export {
2825
UpdateResult,
2926
} from './result';
3027
import Mongo from './mongo';
31-
export {
28+
import {
3229
signatures,
3330
ShellResult,
3431
toShellResult,
3532
getShellApiType,
3633
TypeSignature,
37-
Namespace,
3834
} from './decorators';
3935
import { Topologies, ServerVersions } from './enums';
4036
import { InterruptFlag } from './interruptor';
41-
export type {
42-
GenericCollectionSchema,
43-
GenericDatabaseSchema,
44-
GenericServerSideSchema,
45-
StringKey,
46-
FindAndModifyMethodShellOptions,
47-
FindAndModifyShellOptions,
48-
RemoveShellOptions,
49-
} from './helpers';
50-
export type { Streams } from './streams';
51-
export type { StreamProcessor } from './stream-processor';
5237

5338
export {
5439
AggregationCursor,
5540
RunCommandCursor,
5641
CollectionNamesWithTypes,
5742
Cursor,
43+
CursorIterationResult,
5844
Database,
45+
Collection,
5946
Explainable,
6047
ExplainableCursor,
6148
Help,
6249
HelpProperties,
50+
ShellInstanceState,
51+
EvaluationListener,
52+
BulkWriteResult,
53+
CommandResult,
54+
DeleteResult,
55+
InsertManyResult,
56+
InsertOneResult,
6357
Mongo,
6458
Shard,
6559
ReplicaSet,
60+
UpdateResult,
61+
signatures,
6662
ShellApi,
6763
ServerVersions,
6864
Topologies,
65+
toShellResult,
66+
getShellApiType,
67+
ShellResult,
68+
ShellCliOptions,
69+
TypeSignature,
70+
OnLoadResult,
71+
ShellPlugin,
6972
InterruptFlag,
7073
};

packages/shell-api/src/replica-set.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { asPrintable } from './enums';
1919
import { assertArgsDefinedType } from './helpers';
2020
import type { CommandResult } from './result';
21+
import type { GenericDatabaseSchema, GenericServerSideSchema } from './helpers';
2122

2223
export type ReplSetMemberConfig = {
2324
_id: number;
@@ -35,15 +36,18 @@ export type ReplSetConfig = {
3536
};
3637

3738
@shellApiClassDefault
38-
export default class ReplicaSet extends ShellApiWithMongoClass {
39-
_database: Database;
39+
export default class ReplicaSet<
40+
M extends GenericServerSideSchema = GenericServerSideSchema,
41+
D extends GenericDatabaseSchema = GenericDatabaseSchema
42+
> extends ShellApiWithMongoClass {
43+
_database: Database<M, D>;
4044

41-
constructor(database: Database) {
45+
constructor(database: Database<M, D>) {
4246
super();
4347
this._database = database;
4448
}
4549

46-
get _mongo(): Mongo {
50+
get _mongo(): Mongo<M> {
4751
return this._database._mongo;
4852
}
4953

packages/shell-api/src/shard.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import type {
1212
Document,
1313
CheckMetadataConsistencyOptions,
1414
} from '@mongosh/service-provider-core';
15-
import type { ShardInfo, ShardingStatusResult } from './helpers';
15+
import type {
16+
ShardInfo,
17+
ShardingStatusResult,
18+
GenericDatabaseSchema,
19+
GenericServerSideSchema,
20+
} from './helpers';
1621
import {
1722
assertArgsDefinedType,
1823
getConfigDB,
@@ -28,15 +33,18 @@ import type RunCommandCursor from './run-command-cursor';
2833
import semver from 'semver';
2934

3035
@shellApiClassDefault
31-
export default class Shard extends ShellApiWithMongoClass {
32-
_database: Database;
36+
export default class Shard<
37+
M extends GenericServerSideSchema = GenericServerSideSchema,
38+
D extends GenericDatabaseSchema = GenericDatabaseSchema
39+
> extends ShellApiWithMongoClass {
40+
_database: Database<M, D>;
3341

34-
constructor(database: Database) {
42+
constructor(database: Database<M, D>) {
3543
super();
3644
this._database = database;
3745
}
3846

39-
get _mongo(): Mongo {
47+
get _mongo(): Mongo<M> {
4048
return this._database._mongo;
4149
}
4250

@@ -205,7 +213,7 @@ export default class Shard extends ShellApiWithMongoClass {
205213
@apiVersions([1])
206214
async status(
207215
verbose = false,
208-
configDB?: Database
216+
configDB?: Database<M, D>
209217
): Promise<CommandResult<ShardingStatusResult>> {
210218
const result = await getPrintableShardStatus(
211219
configDB ?? (await getConfigDB(this._database)),

packages/shell-api/src/streams.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ import StreamProcessor from './stream-processor';
1010
import { ADMIN_DB, asPrintable, shellApiType } from './enums';
1111
import type Database from './database';
1212
import type Mongo from './mongo';
13+
import type { GenericDatabaseSchema, GenericServerSideSchema } from './helpers';
1314

1415
@shellApiClassDefault
15-
export class Streams extends ShellApiWithMongoClass {
16-
public static newInstance(database: Database) {
17-
return new Proxy(new Streams(database), {
16+
export class Streams<
17+
M extends GenericServerSideSchema = GenericServerSideSchema,
18+
D extends GenericDatabaseSchema = GenericDatabaseSchema
19+
> extends ShellApiWithMongoClass {
20+
public static newInstance<
21+
M extends GenericServerSideSchema = GenericServerSideSchema,
22+
D extends GenericDatabaseSchema = GenericDatabaseSchema
23+
>(database: Database<M, D>) {
24+
return new Proxy(new Streams<M, D>(database), {
1825
get(target, prop) {
1926
const v = (target as any)[prop];
2027
if (v !== undefined) {
@@ -27,22 +34,22 @@ export class Streams extends ShellApiWithMongoClass {
2734
});
2835
}
2936

30-
private _database: Database;
37+
private _database: Database<M, D>;
3138

32-
constructor(database: Database) {
39+
constructor(database: Database<M, D>) {
3340
super();
3441
this._database = database;
3542
}
3643

37-
get _mongo(): Mongo {
44+
get _mongo(): Mongo<M> {
3845
return this._database._mongo;
3946
}
4047

4148
[asPrintable](): string {
4249
return 'Atlas Stream Processing';
4350
}
4451

45-
getProcessor(name: string) {
52+
getProcessor(name: string): StreamProcessor {
4653
return new StreamProcessor(this, name);
4754
}
4855

0 commit comments

Comments
 (0)