From 21f271671d75794feb82478a06773c1f3c179842 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Tue, 21 Mar 2023 10:51:55 -0700 Subject: [PATCH] new drop object request (#22387) * simplify drop object requests * update sts * pr comments --- extensions/mssql/config.json | 2 +- extensions/mssql/src/contracts.ts | 27 +++----- extensions/mssql/src/mssql.d.ts | 23 +++---- .../mssql/src/objectManagement/commands.ts | 11 +--- .../objectManagementService.ts | 63 +++++++------------ 5 files changed, 40 insertions(+), 86 deletions(-) diff --git a/extensions/mssql/config.json b/extensions/mssql/config.json index 0012378051..39958906e0 100644 --- a/extensions/mssql/config.json +++ b/extensions/mssql/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "4.6.0.13", + "version": "4.6.0.14", "downloadFileNames": { "Windows_86": "win-x86-net7.0.zip", "Windows_64": "win-x64-net7.0.zip", diff --git a/extensions/mssql/src/contracts.ts b/extensions/mssql/src/contracts.ts index 86a4103f28..cf78e955de 100644 --- a/extensions/mssql/src/contracts.ts +++ b/extensions/mssql/src/contracts.ts @@ -1539,15 +1539,6 @@ export namespace UpdateLoginRequest { export const type = new RequestType('objectManagement/updateLogin'); } -export interface DeleteLoginRequestParams { - connectionUri: string; - name: string; -} - -export namespace DeleteLoginRequest { - export const type = new RequestType('objectManagement/deleteLogin'); -} - export interface DisposeLoginViewRequestParams { contextId: string; } @@ -1586,16 +1577,6 @@ export namespace UpdateUserRequest { export const type = new RequestType('objectManagement/updateUser'); } -export interface DeleteUserRequestParams { - connectionUri: string; - database: string; - name: string; -} - -export namespace DeleteUserRequest { - export const type = new RequestType('objectManagement/deleteUser'); -} - export interface DisposeUserViewRequestParams { contextId: string; } @@ -1614,4 +1595,12 @@ export namespace RenameObjectRequest { export const type = new RequestType('objectManagement/rename'); } +export interface DropObjectRequestParams { + connectionUri: string; + objectUrn: string; +} + +export namespace DropObjectRequest { + export const type = new RequestType('objectManagement/drop'); +} // ------------------------------- < Object Management > ------------------------------------ diff --git a/extensions/mssql/src/mssql.d.ts b/extensions/mssql/src/mssql.d.ts index 6817ec5bfb..de7f86e7be 100644 --- a/extensions/mssql/src/mssql.d.ts +++ b/extensions/mssql/src/mssql.d.ts @@ -1191,12 +1191,6 @@ declare module 'mssql' { * @param login The login information. */ updateLogin(contextId: string, login: ObjectManagement.Login): Thenable; - /** - * Delete a login. - * @param connectionUri The URI of the server connection. - * @param name Name of the login. - */ - deleteLogin(connectionUri: string, name: string): Thenable; /** * Dispose the login view. * @param contextId The id of the view. @@ -1218,18 +1212,11 @@ declare module 'mssql' { */ createUser(contextId: string, user: ObjectManagement.User): Thenable; /** - * Create a login. + * Update a user. * @param contextId Id of the view. * @param user The user information. */ updateUser(contextId: string, user: ObjectManagement.User): Thenable; - /** - * Create a login. - * @param connectionUri The URI of the server connection. - * @param database Name of the database. - * @param name Name of the user. - */ - deleteUser(connectionUri: string, database: string, name: string): Thenable; /** * Dispose the user view. * @param contextId The id of the view. @@ -1238,10 +1225,16 @@ declare module 'mssql' { /** * Rename an object. * @param connectionUri The URI of the server connection. - * @param objectUrn Urn of the object to be renamed. More information: https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/overview-smo. + * @param objectUrn SMO Urn of the object to be renamed. More information: https://learn.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo * @param newName The new name of the object. */ rename(connectionUri: string, objectUrn: string, newName: string): Thenable; + /** + * Drop an object. + * @param connectionUri The URI of the server connection. + * @param objectUrn SMO Urn of the object to be dropped. More information: https://learn.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo + */ + drop(connectionUri: string, objectUrn: string): Thenable; } // Object Management - End. } diff --git a/extensions/mssql/src/objectManagement/commands.ts b/extensions/mssql/src/objectManagement/commands.ts index 8ce76bb7e4..0e64ad99bf 100644 --- a/extensions/mssql/src/objectManagement/commands.ts +++ b/extensions/mssql/src/objectManagement/commands.ts @@ -139,16 +139,7 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext, operation: async (operation) => { try { const startTime = Date.now(); - switch (context.nodeInfo.nodeType) { - case NodeType.Login: - await service.deleteLogin(connectionUri, context.nodeInfo.label); - break; - case NodeType.User: - await service.deleteUser(connectionUri, context.connectionProfile.databaseName, context.nodeInfo.label); - break; - default: - return; - } + await service.drop(connectionUri, context.nodeInfo.metadata.urn); TelemetryReporter.sendTelemetryEvent(TelemetryActions.DeleteObject, { objectType: context.nodeInfo.nodeType }, { diff --git a/extensions/mssql/src/objectManagement/objectManagementService.ts b/extensions/mssql/src/objectManagement/objectManagementService.ts index 9a7c776515..25027fd581 100644 --- a/extensions/mssql/src/objectManagement/objectManagementService.ts +++ b/extensions/mssql/src/objectManagement/objectManagementService.ts @@ -39,7 +39,7 @@ export class ObjectManagementService implements IObjectManagementService { }, e => { this.client.logFailedRequest(contracts.InitializeLoginViewRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -49,7 +49,7 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.CreateLoginRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -59,17 +59,7 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.UpdateLoginRequest.type, e); - return Promise.reject(new Error(e.message)); - } - ); - } - deleteLogin(connectionUri: string, name: string): Thenable { - const params: contracts.DeleteLoginRequestParams = { connectionUri, name }; - return this.client.sendRequest(contracts.DeleteLoginRequest.type, params).then( - r => { }, - e => { - this.client.logFailedRequest(contracts.DeleteLoginRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -79,11 +69,10 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.DisposeLoginViewRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } - initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string | undefined): Thenable { const params: contracts.InitializeUserViewRequestParams = { connectionUri, database, contextId, isNewObject, name }; return this.client.sendRequest(contracts.InitializeUserViewRequest.type, params).then( @@ -92,7 +81,7 @@ export class ObjectManagementService implements IObjectManagementService { }, e => { this.client.logFailedRequest(contracts.InitializeUserViewRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -102,7 +91,7 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.CreateUserRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -112,17 +101,7 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.UpdateUserRequest.type, e); - return Promise.reject(new Error(e.message)); - } - ); - } - deleteUser(connectionUri: string, database: string, name: string): Thenable { - const params: contracts.DeleteUserRequestParams = { connectionUri, database, name }; - return this.client.sendRequest(contracts.DeleteUserRequest.type, params).then( - r => { }, - e => { - this.client.logFailedRequest(contracts.DeleteUserRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -132,7 +111,7 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.DisposeUserViewRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); } ); } @@ -142,7 +121,17 @@ export class ObjectManagementService implements IObjectManagementService { r => { }, e => { this.client.logFailedRequest(contracts.RenameObjectRequest.type, e); - return Promise.reject(new Error(e.message)); + return Promise.reject(e); + } + ); + } + drop(connectionUri: string, objectUrn: string): Thenable { + const params: contracts.DropObjectRequestParams = { connectionUri, objectUrn }; + return this.client.sendRequest(contracts.DropObjectRequest.type, params).then( + r => { }, + e => { + this.client.logFailedRequest(contracts.DropObjectRequest.type, e); + return Promise.reject(e); } ); } @@ -226,13 +215,6 @@ export class TestObjectManagementService implements IObjectManagementService { }, 3000); }); } - async deleteLogin(connectionUri: string, name: string): Promise { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve(); - }, 3000); - }); - } async disposeLoginView(contextId: string): Promise { } async initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string): Promise { @@ -297,15 +279,14 @@ export class TestObjectManagementService implements IObjectManagementService { async updateUser(contextId: string, login: ObjectManagement.User): Promise { return this.delayAndResolve(); } - async deleteUser(connectionUri: string, database: string, name: string): Promise { - return this.delayAndResolve(); - } async disposeUserView(contextId: string): Promise { } async rename(connectionUri: string, objectUrn: string, newName: string): Promise { return this.delayAndResolve(); } - + async drop(connectionUri: string, objectUrn: string): Promise { + return this.delayAndResolve(); + } private delayAndResolve(): Promise { return new Promise((resolve, reject) => { setTimeout(() => {