From 222f69e689463357dda926bfff9f9d31555a48ad Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 28 Jan 2021 16:56:33 +0100 Subject: [PATCH] feat(shell-api,autocomplete): skip deprecated methods MONGOSH-509 Mark methods as deprecated and skip them for autocompletion. --- packages/autocomplete/index.spec.ts | 9 ++-- packages/autocomplete/index.ts | 42 ++++++++++++------- .../shell-api/src/aggregation-cursor.spec.ts | 1 + packages/shell-api/src/bulk.spec.ts | 2 + .../src/change-stream-cursor.spec.ts | 1 + .../shell-api/src/change-stream-cursor.ts | 4 +- packages/shell-api/src/collection.spec.ts | 1 + packages/shell-api/src/collection.ts | 9 +++- packages/shell-api/src/cursor.spec.ts | 1 + packages/shell-api/src/cursor.ts | 5 ++- packages/shell-api/src/database.spec.ts | 1 + packages/shell-api/src/database.ts | 7 +++- packages/shell-api/src/decorators.ts | 21 ++++++++-- packages/shell-api/src/deprecated.ts | 4 +- .../shell-api/src/explainable-cursor.spec.ts | 1 + packages/shell-api/src/explainable.spec.ts | 1 + .../src/field-level-encryption.spec.ts | 2 + packages/shell-api/src/index.ts | 6 ++- packages/shell-api/src/mongo.spec.ts | 1 + packages/shell-api/src/mongo.ts | 5 ++- packages/shell-api/src/plan-cache.spec.ts | 1 + packages/shell-api/src/plan-cache.ts | 5 ++- packages/shell-api/src/replica-set.spec.ts | 1 + packages/shell-api/src/replica-set.ts | 4 +- packages/shell-api/src/session.spec.ts | 1 + packages/shell-api/src/shard.spec.ts | 1 + packages/shell-api/src/shell-api.spec.ts | 10 +++++ packages/shell-api/src/shell-bson.ts | 1 + 28 files changed, 117 insertions(+), 31 deletions(-) diff --git a/packages/autocomplete/index.spec.ts b/packages/autocomplete/index.spec.ts index 083b3af250..e1d470ab40 100644 --- a/packages/autocomplete/index.spec.ts +++ b/packages/autocomplete/index.spec.ts @@ -179,8 +179,11 @@ describe('completer.completer', () => { it('returns all suggestions', async() => { const i = 'db.'; - const dbComplete = Object.keys(shellSignatures.Database.attributes as any); - const adjusted = dbComplete.map(c => `${i}${c}`); + const attr = shellSignatures.Database.attributes as any; + const dbComplete = Object.keys(attr); + const adjusted = dbComplete + .filter(c => !attr[c].deprecated) + .map(c => `${i}${c}`); expect(await completer(noParams, i)).to.deep.equal([adjusted, i]); }); @@ -221,7 +224,7 @@ describe('completer.completer', () => { it('returns all suggestions', async() => { const i = 'db.shipwrecks.'; const collComplete = Object.keys(shellSignatures.Collection.attributes as any); - const adjusted = collComplete.filter(c => !['count', 'update', 'remove'].includes(c)).map(c => `${i}${c}`); + const adjusted = collComplete.filter(c => !['count', 'update', 'remove', 'insert', 'save'].includes(c)).map(c => `${i}${c}`); expect(await completer(sharded440, i)).to.deep.equal([adjusted, i]); }); diff --git a/packages/autocomplete/index.ts b/packages/autocomplete/index.ts index ddbbce9191..074c85e7d8 100644 --- a/packages/autocomplete/index.ts +++ b/packages/autocomplete/index.ts @@ -1,6 +1,6 @@ /* eslint complexity: 0, camelcase: 0, no-nested-ternary: 0 */ -import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api'; +import { signatures as shellSignatures, Topologies, TypeSignature } from '@mongosh/shell-api'; import semver from 'semver'; import { CONVERSION_OPERATORS, @@ -14,6 +14,8 @@ import { ON_PREM } from 'mongodb-ace-autocompleter'; +type TypeSignatureAttributes = { [key: string]: TypeSignature }; + export interface AutocompleteParameters { topology: () => Topologies; connectionInfo: () => undefined | { @@ -49,13 +51,13 @@ const GROUP = '$group'; * @returns {array} Matching Completions, Current User Input. */ async function completer(params: AutocompleteParameters, line: string): Promise<[string[], string]> { - const SHELL_COMPLETIONS = shellSignatures.ShellApi.attributes; - const COLL_COMPLETIONS = shellSignatures.Collection.attributes; - const DB_COMPLETIONS = shellSignatures.Database.attributes; - const AGG_CURSOR_COMPLETIONS = shellSignatures.AggregationCursor.attributes; - const COLL_CURSOR_COMPLETIONS = shellSignatures.Cursor.attributes; - const RS_COMPLETIONS = shellSignatures.ReplicaSet.attributes; - const SHARD_COMPLETE = shellSignatures.Shard.attributes; + const SHELL_COMPLETIONS = shellSignatures.ShellApi.attributes as TypeSignatureAttributes; + const COLL_COMPLETIONS = shellSignatures.Collection.attributes as TypeSignatureAttributes; + const DB_COMPLETIONS = shellSignatures.Database.attributes as TypeSignatureAttributes; + const AGG_CURSOR_COMPLETIONS = shellSignatures.AggregationCursor.attributes as TypeSignatureAttributes; + const COLL_CURSOR_COMPLETIONS = shellSignatures.Cursor.attributes as TypeSignatureAttributes; + const RS_COMPLETIONS = shellSignatures.ReplicaSet.attributes as TypeSignatureAttributes; + const SHARD_COMPLETE = shellSignatures.Shard.attributes as TypeSignatureAttributes; // keep initial line param intact to always return in return statement // check for contents of line with: @@ -174,17 +176,29 @@ function filterQueries(params: AutocompleteParameters, completions: any, prefix: return hits.map(h => `${split}${h.name}`); } -function filterShellAPI(params: AutocompleteParameters, completions: any, prefix: string, split?: string[]): string[] { - const hits: string[] = Object.keys(completions).filter((c: any) => { +function filterShellAPI( + params: AutocompleteParameters, + completions: { [key: string]: TypeSignature }, + prefix: string, + split?: string[]): string[] { + const hits: string[] = Object.keys(completions).filter((c: string) => { if (!c.startsWith(prefix)) return false; + if (completions[c].deprecated) return false; + const serverVersion = params.connectionInfo()?.server_version; if (!serverVersion) return true; + + const acceptableVersions = completions[c].serverVersions; const isAcceptableVersion = - (semver.gte(serverVersion, completions[c].serverVersions[0]) && - semver.lte(serverVersion, completions[c].serverVersions[1])); + !acceptableVersions || + (semver.gte(serverVersion, acceptableVersions[0]) && + semver.lte(serverVersion, acceptableVersions[1])); + + const acceptableTopologies = completions[c].topologies; const isAcceptableTopology = - !completions[c].topologies || - completions[c].topologies.includes(params.topology()); + !acceptableTopologies || + acceptableTopologies.includes(params.topology()); + return isAcceptableVersion && isAcceptableTopology; }); diff --git a/packages/shell-api/src/aggregation-cursor.spec.ts b/packages/shell-api/src/aggregation-cursor.spec.ts index ba0a917e7d..be1f2ffe03 100644 --- a/packages/shell-api/src/aggregation-cursor.spec.ts +++ b/packages/shell-api/src/aggregation-cursor.spec.ts @@ -24,6 +24,7 @@ describe('AggregationCursor', () => { expect(signatures.AggregationCursor.attributes.map).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'AggregationCursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/bulk.spec.ts b/packages/shell-api/src/bulk.spec.ts index 6dd53ce0e8..739e0bf6ce 100644 --- a/packages/shell-api/src/bulk.spec.ts +++ b/packages/shell-api/src/bulk.spec.ts @@ -35,6 +35,7 @@ describe('Bulk API', () => { expect(signatures.Bulk.attributes.find).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'BulkFindOp', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -236,6 +237,7 @@ describe('Bulk API', () => { expect(signatures.BulkFindOp.attributes.hint).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'BulkFindOp', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/change-stream-cursor.spec.ts b/packages/shell-api/src/change-stream-cursor.spec.ts index adefb81ba4..f627d5acf4 100644 --- a/packages/shell-api/src/change-stream-cursor.spec.ts +++ b/packages/shell-api/src/change-stream-cursor.spec.ts @@ -30,6 +30,7 @@ describe('ChangeStreamCursor', () => { expect(signatures.ChangeStreamCursor.attributes.next).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/change-stream-cursor.ts b/packages/shell-api/src/change-stream-cursor.ts index 19c84c3ae7..58183aaaed 100644 --- a/packages/shell-api/src/change-stream-cursor.ts +++ b/packages/shell-api/src/change-stream-cursor.ts @@ -3,7 +3,8 @@ import { returnsPromise, returnType, hasAsyncChild, - ShellApiClass + ShellApiClass, + deprecated } from './decorators'; import { ChangeStream, @@ -58,6 +59,7 @@ export default class ChangeStreamCursor extends ShellApiClass { } @returnsPromise + @deprecated async hasNext(): Promise { printWarning( 'If there are no documents in the batch, hasNext will block. Use tryNext if you want to check if there ' + diff --git a/packages/shell-api/src/collection.spec.ts b/packages/shell-api/src/collection.spec.ts index 286c7f328a..01f85abf55 100644 --- a/packages/shell-api/src/collection.spec.ts +++ b/packages/shell-api/src/collection.spec.ts @@ -40,6 +40,7 @@ describe('Collection', () => { expect(signatures.Collection.attributes.aggregate).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: 'AggregationCursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/collection.ts b/packages/shell-api/src/collection.ts index 3de7ec76e1..4845973d5c 100644 --- a/packages/shell-api/src/collection.ts +++ b/packages/shell-api/src/collection.ts @@ -9,7 +9,8 @@ import { serverVersions, ShellApiClass, shellApiClassDefault, - topologies + topologies, + deprecated } from './decorators'; import { ADMIN_DB, asPrintable, namespaceInfo, ServerVersions, Topologies } from './enums'; import { @@ -233,6 +234,7 @@ export default class Collection extends ShellApiClass { * @returns {Integer} The promise of the count. */ @returnsPromise + @deprecated @serverVersions([ServerVersions.earliest, '4.0.0']) async count(query = {}, options: CountOptions = {}): Promise { this._emitCollectionApiCall( @@ -592,6 +594,8 @@ export default class Collection extends ShellApiClass { * @return {InsertManyResult} */ @returnsPromise + @deprecated + @serverVersions([ServerVersions.earliest, '3.6.0']) async insert(docs: Document | Document[], options: BulkWriteOptions = {}): Promise { printDeprecationWarning( 'Collection.insert() is deprecated. Use insertOne, insertMany or bulkWrite.', @@ -702,6 +706,7 @@ export default class Collection extends ShellApiClass { * @return {Promise} */ @returnsPromise + @deprecated @serverVersions([ServerVersions.earliest, '3.2.0']) async remove(query: Document, options: boolean | RemoveShellOptions = {}): Promise { printDeprecationWarning( @@ -730,6 +735,7 @@ export default class Collection extends ShellApiClass { } @returnsPromise + @deprecated save(): Promise { throw new MongoshInvalidInputError('Collection.save() is deprecated. Use insertOne, insertMany, updateOne or updateMany.'); } @@ -772,6 +778,7 @@ export default class Collection extends ShellApiClass { } @returnsPromise + @deprecated @serverVersions([ServerVersions.earliest, '3.2.0']) async update(filter: Document, update: Document, options: UpdateOptions & { multi?: boolean } = {}): Promise { printDeprecationWarning( diff --git a/packages/shell-api/src/cursor.spec.ts b/packages/shell-api/src/cursor.spec.ts index fe83e643ed..f3a45ff5b9 100644 --- a/packages/shell-api/src/cursor.spec.ts +++ b/packages/shell-api/src/cursor.spec.ts @@ -28,6 +28,7 @@ describe('Cursor', () => { expect(signatures.Cursor.attributes.map).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'Cursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/cursor.ts b/packages/shell-api/src/cursor.ts index cc22b00ef0..817abb5d67 100644 --- a/packages/shell-api/src/cursor.ts +++ b/packages/shell-api/src/cursor.ts @@ -6,7 +6,8 @@ import { serverVersions, ShellApiClass, shellApiClassDefault, - toShellResult + toShellResult, + deprecated } from './decorators'; import { ServerVersions, @@ -75,7 +76,6 @@ export default class Cursor extends ShellApiClass { if (optionFlagNumber === 4) { throw new MongoshUnimplementedError('the slaveOk option is not supported.', CommonErrors.NotImplemented); } - const optionFlag: CursorFlag | undefined = (CURSOR_FLAGS as any)[optionFlagNumber]; if (!optionFlag) { @@ -340,6 +340,7 @@ export default class Cursor extends ShellApiClass { return this; } + @deprecated @serverVersions([ServerVersions.earliest, '4.0.0']) maxScan(): void { throw new MongoshDeprecatedError( diff --git a/packages/shell-api/src/database.spec.ts b/packages/shell-api/src/database.spec.ts index 433d918f7f..2621397103 100644 --- a/packages/shell-api/src/database.spec.ts +++ b/packages/shell-api/src/database.spec.ts @@ -81,6 +81,7 @@ describe('Database', () => { expect(signatures.Database.attributes.aggregate).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: 'AggregationCursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/database.ts b/packages/shell-api/src/database.ts index cc54806d72..db04bef7dd 100644 --- a/packages/shell-api/src/database.ts +++ b/packages/shell-api/src/database.ts @@ -8,7 +8,8 @@ import { serverVersions, ShellApiClass, shellApiClassDefault, - topologies + topologies, + deprecated } from './decorators'; import { ADMIN_DB, asPrintable, ServerVersions, Topologies } from './enums'; import { @@ -1024,14 +1025,17 @@ export default class Database extends ShellApiClass { return result.logComponentVerbosity; } + @deprecated cloneDatabase(): void { throw new MongoshDeprecatedError('`cloneDatabase()` was removed because it was deprecated in MongoDB 4.0'); } + @deprecated cloneCollection(): void { throw new MongoshDeprecatedError('`cloneCollection()` was removed because it was deprecated in MongoDB 4.0'); } + @deprecated copyDatabase(): void { throw new MongoshDeprecatedError('`copyDatabase()` was removed because it was deprecated in MongoDB 4.0'); } @@ -1248,6 +1252,7 @@ export default class Database extends ShellApiClass { return new CommandResult('StatsResult', result); } + @deprecated @returnsPromise async printSlaveReplicationInfo(): Promise { throw new MongoshDeprecatedError('Method deprecated, use db.printSecondaryReplicationInfo instead'); diff --git a/packages/shell-api/src/decorators.ts b/packages/shell-api/src/decorators.ts index f02d6f9a11..ba9761601a 100644 --- a/packages/shell-api/src/decorators.ts +++ b/packages/shell-api/src/decorators.ts @@ -133,10 +133,13 @@ function wrapWithAddSourceToResult(fn: Function): Function { return wrapper; } -interface TypeSignature { +export interface TypeSignature { type: string; hasAsyncChild?: boolean; + serverVersions?: [ string, string ]; + topologies?: Topologies[]; returnsPromise?: boolean; + deprecated?: boolean; returnType?: string | TypeSignature; attributes?: { [key: string]: TypeSignature }; } @@ -156,6 +159,7 @@ type ClassSignature = { type: string; hasAsyncChild: boolean; returnsPromise: boolean; + deprecated: boolean; attributes: { [methodName: string]: { type: 'function'; @@ -163,6 +167,7 @@ type ClassSignature = { topologies: Topologies[]; returnType: ClassSignature; returnsPromise: boolean; + deprecated: boolean; platforms: ReplPlatform[]; } }; @@ -187,6 +192,7 @@ export function shellApiClassDefault(constructor: Function): void { type: className, hasAsyncChild: constructor.prototype.hasAsyncChild || false, returnsPromise: constructor.prototype.returnsPromise || false, + deprecated: constructor.prototype.deprecated || false, attributes: {} }; @@ -209,6 +215,7 @@ export function shellApiClassDefault(constructor: Function): void { method.topologies = method.topologies || ALL_TOPOLOGIES; method.returnType = method.returnType || { type: 'unknown', attributes: {} }; method.returnsPromise = method.returnsPromise || false; + method.deprecated = method.deprecated || false; method.platforms = method.platforms || ALL_PLATFORMS; classSignature.attributes[propertyName] = { @@ -217,6 +224,7 @@ export function shellApiClassDefault(constructor: Function): void { topologies: method.topologies, returnType: method.returnType, returnsPromise: method.returnsPromise, + deprecated: method.deprecated, platforms: method.platforms }; @@ -262,6 +270,7 @@ export function shellApiClassDefault(constructor: Function): void { topologies: method.topologies, returnType: method.returnType, returnsPromise: method.returnsPromise, + deprecated: method.deprecated, platforms: method.platforms }; @@ -284,7 +293,7 @@ export function shellApiClassDefault(constructor: Function): void { } export { signatures }; -export function serverVersions(versionArray: any[]): Function { +export function serverVersions(versionArray: [ string, string ]): Function { return function( _target: any, _propertyKey: string, @@ -293,7 +302,10 @@ export function serverVersions(versionArray: any[]): Function { descriptor.value.serverVersions = versionArray; }; } -export function topologies(topologiesArray: any[]): Function { +export function deprecated(_target: any, _propertyKey: string, descriptor: PropertyDescriptor): void { + descriptor.value.deprecated = true; +} +export function topologies(topologiesArray: Topologies[]): Function { return function( _target: any, _propertyKey: string, @@ -323,6 +335,9 @@ export function hasAsyncChild(constructor: Function): void { export function classReturnsPromise(constructor: Function): void { constructor.prototype.returnsPromise = true; } +export function classDeprecated(constructor: Function): void { + constructor.prototype.deprecated = true; +} export function platforms(platformsArray: any[]): Function { return function( _target: any, diff --git a/packages/shell-api/src/deprecated.ts b/packages/shell-api/src/deprecated.ts index b23fa939c4..c377964551 100644 --- a/packages/shell-api/src/deprecated.ts +++ b/packages/shell-api/src/deprecated.ts @@ -1,12 +1,14 @@ import { ShellApiClass, - shellApiClassDefault + shellApiClassDefault, + classDeprecated } from './decorators'; import { asPrintable } from './enums'; import { MongoshDeprecatedError } from '@mongosh/errors'; @shellApiClassDefault +@classDeprecated class DeprecatedClass extends ShellApiClass { public name: string; constructor(name: string, alternatives: Record = {}) { diff --git a/packages/shell-api/src/explainable-cursor.spec.ts b/packages/shell-api/src/explainable-cursor.spec.ts index 10a191cc2d..6896d7a059 100644 --- a/packages/shell-api/src/explainable-cursor.spec.ts +++ b/packages/shell-api/src/explainable-cursor.spec.ts @@ -21,6 +21,7 @@ describe('ExplainableCursor', () => { expect(signatures.ExplainableCursor.attributes.map).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'ExplainableCursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/explainable.spec.ts b/packages/shell-api/src/explainable.spec.ts index ffa4ce4e8c..25bfe5ce36 100644 --- a/packages/shell-api/src/explainable.spec.ts +++ b/packages/shell-api/src/explainable.spec.ts @@ -28,6 +28,7 @@ describe('Explainable', () => { expect(signatures.Explainable.attributes.find).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: 'ExplainableCursor', platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/field-level-encryption.spec.ts b/packages/shell-api/src/field-level-encryption.spec.ts index df4a9be321..fd52d889de 100644 --- a/packages/shell-api/src/field-level-encryption.spec.ts +++ b/packages/shell-api/src/field-level-encryption.spec.ts @@ -95,6 +95,7 @@ describe('Field Level Encryption', () => { expect(signatures.KeyVault.attributes.createKey).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { attributes: {}, type: 'unknown' }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -103,6 +104,7 @@ describe('Field Level Encryption', () => { expect(signatures.ClientEncryption.attributes.encrypt).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { attributes: {}, type: 'unknown' }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/index.ts b/packages/shell-api/src/index.ts index edbf450268..c123793761 100644 --- a/packages/shell-api/src/index.ts +++ b/packages/shell-api/src/index.ts @@ -24,7 +24,8 @@ import { signatures, ShellResult, toShellResult, - getShellApiType + getShellApiType, + TypeSignature } from './decorators'; import { Topologies, @@ -60,5 +61,6 @@ export { toShellResult, getShellApiType, ShellResult, - ShellCliOptions + ShellCliOptions, + TypeSignature }; diff --git a/packages/shell-api/src/mongo.spec.ts b/packages/shell-api/src/mongo.spec.ts index b4d12d2e7a..8688d8e2e9 100644 --- a/packages/shell-api/src/mongo.spec.ts +++ b/packages/shell-api/src/mongo.spec.ts @@ -41,6 +41,7 @@ describe('Mongo', () => { expect(signatures.Mongo.attributes.show).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { attributes: {}, type: 'unknown' }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index 674eb2aae2..de8a0a459a 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -16,7 +16,8 @@ import { serverVersions, ShellApiClass, shellApiClassDefault, - topologies + topologies, + deprecated } from './decorators'; import { ChangeStreamOptions, @@ -260,10 +261,12 @@ export default class Mongo extends ShellApiClass { ); } + @deprecated setSlaveOk(): void { throw new MongoshDeprecatedError('setSlaveOk is deprecated.'); } + @deprecated setSecondaryOk(): void { throw new MongoshDeprecatedError('Setting secondaryOk is deprecated, use setReadPref instead'); } diff --git a/packages/shell-api/src/plan-cache.spec.ts b/packages/shell-api/src/plan-cache.spec.ts index 81e1ce800f..32a9f3be9c 100644 --- a/packages/shell-api/src/plan-cache.spec.ts +++ b/packages/shell-api/src/plan-cache.spec.ts @@ -22,6 +22,7 @@ describe('PlanCache', () => { expect(signatures.PlanCache.attributes.list).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { attributes: {}, type: 'unknown' }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/plan-cache.ts b/packages/shell-api/src/plan-cache.ts index e5a61e1205..40d02658e3 100644 --- a/packages/shell-api/src/plan-cache.ts +++ b/packages/shell-api/src/plan-cache.ts @@ -3,7 +3,8 @@ import { returnsPromise, serverVersions, ShellApiClass, - shellApiClassDefault + shellApiClassDefault, + deprecated } from './decorators'; import { Document } from '@mongosh/service-provider-core'; import Collection from './collection'; @@ -52,10 +53,12 @@ export default class PlanCache extends ShellApiClass { return await agg.toArray(); } + @deprecated planCacheQueryShapes(): void { throw new MongoshDeprecatedError('PlanCache.listQueryShapes was deprecated, please use PlanCache.list instead'); } + @deprecated getPlansByQuery(): void { throw new MongoshDeprecatedError('PlanCache.getPlansByQuery was deprecated, please use PlanCache.list instead'); } diff --git a/packages/shell-api/src/replica-set.spec.ts b/packages/shell-api/src/replica-set.spec.ts index a4979f3468..1de5d07611 100644 --- a/packages/shell-api/src/replica-set.spec.ts +++ b/packages/shell-api/src/replica-set.spec.ts @@ -44,6 +44,7 @@ describe('ReplicaSet', () => { expect(signatures.ReplicaSet.attributes.initiate).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/replica-set.ts b/packages/shell-api/src/replica-set.ts index 832020fdfc..c7f00925f0 100644 --- a/packages/shell-api/src/replica-set.ts +++ b/packages/shell-api/src/replica-set.ts @@ -3,7 +3,8 @@ import { shellApiClassDefault, hasAsyncChild, ShellApiClass, - returnsPromise + returnsPromise, + deprecated } from './decorators'; import { Document @@ -118,6 +119,7 @@ export default class ReplicaSet extends ShellApiClass { return this._database.printSecondaryReplicationInfo(); } + @deprecated @returnsPromise async printSlaveReplicationInfo(): Promise { throw new MongoshDeprecatedError('printSlaveReplicationInfo has been deprecated. Use printSecondaryReplicationInfo instead'); diff --git a/packages/shell-api/src/session.spec.ts b/packages/shell-api/src/session.spec.ts index 4428cf6870..26d7bf5a9f 100644 --- a/packages/shell-api/src/session.spec.ts +++ b/packages/shell-api/src/session.spec.ts @@ -35,6 +35,7 @@ describe('Session', () => { expect(signatures.Session.attributes.endSession).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/shard.spec.ts b/packages/shell-api/src/shard.spec.ts index 6c0ae1f199..b0808da71e 100644 --- a/packages/shell-api/src/shard.spec.ts +++ b/packages/shell-api/src/shard.spec.ts @@ -33,6 +33,7 @@ describe('Shard', () => { expect(signatures.Shard.attributes.enableSharding).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/shell-api.spec.ts b/packages/shell-api/src/shell-api.spec.ts index da4628dec7..e364bca980 100644 --- a/packages/shell-api/src/shell-api.spec.ts +++ b/packages/shell-api/src/shell-api.spec.ts @@ -37,6 +37,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.use).to.deep.equal({ type: 'function', returnsPromise: false, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -45,6 +46,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.show).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -53,6 +55,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.exit).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -61,6 +64,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.it).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -69,6 +73,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.print).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -77,6 +82,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.printjson).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -85,6 +91,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.sleep).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -93,6 +100,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.cls).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: { type: 'unknown', attributes: {} }, platforms: ALL_PLATFORMS, topologies: ALL_TOPOLOGIES, @@ -101,6 +109,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.Mongo).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: 'Mongo', platforms: [ ReplPlatform.CLI ], topologies: ALL_TOPOLOGIES, @@ -109,6 +118,7 @@ describe('ShellApi', () => { expect(signatures.ShellApi.attributes.connect).to.deep.equal({ type: 'function', returnsPromise: true, + deprecated: false, returnType: 'Database', platforms: [ ReplPlatform.CLI ], topologies: ALL_TOPOLOGIES, diff --git a/packages/shell-api/src/shell-bson.ts b/packages/shell-api/src/shell-bson.ts index ac1f2d9dca..0d23b2d877 100644 --- a/packages/shell-api/src/shell-bson.ts +++ b/packages/shell-api/src/shell-bson.ts @@ -58,6 +58,7 @@ export default function constructShellBson(bson: typeof BSON): any { }); // Symbol is deprecated (bson.BSONSymbol as any).prototype.serverVersions = [ ServerVersions.earliest, '1.6.0' ]; + (bson.BSONSymbol as any).prototype.deprecated = true; const bsonPkg = { DBRef: function(namespace: string, oid: any, db?: string): any {