Enable scripting for triggers and other objects (#16885)

* WIP 1

* Add parentName to azdata

* Add some additional types for scripting

* Add parent type name to support view subobjects

* bump dependencies and address review comments
This commit is contained in:
Karl Burtram
2021-08-26 14:43:36 -07:00
committed by GitHub
parent dc1e460f71
commit a0f3d0873b
11 changed files with 99 additions and 200 deletions

View File

@@ -27,7 +27,7 @@ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.Obje
constructor(nodeName: string, nodeSchema: string, nodeType: string, parent: azdata.objectexplorer.ObjectExplorerNode) { constructor(nodeName: string, nodeSchema: string, nodeType: string, parent: azdata.objectexplorer.ObjectExplorerNode) {
this.parent = parent; this.parent = parent;
this.nodeType = nodeType; this.nodeType = nodeType;
this.metadata = { metadataType: undefined, metadataTypeName: undefined, name: nodeName, schema: nodeSchema, urn: undefined }; this.metadata = { metadataType: undefined, metadataTypeName: undefined, name: nodeName, schema: nodeSchema, urn: undefined, parentName: undefined, parentTypeName: undefined };
} }
isExpanded(): Thenable<boolean> { isExpanded(): Thenable<boolean> {

View File

@@ -1,6 +1,6 @@
{ {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "3.0.0-release.121", "version": "3.0.0-release.126",
"downloadFileNames": { "downloadFileNames": {
"Windows_86": "win-x86-net5.0.zip", "Windows_86": "win-x86-net5.0.zip",
"Windows_64": "win-x64-net5.0.zip", "Windows_64": "win-x64-net5.0.zip",

View File

@@ -1259,7 +1259,7 @@
"@microsoft/ads-kerberos": "^1.1.3", "@microsoft/ads-kerberos": "^1.1.3",
"buffer-stream-reader": "^0.1.1", "buffer-stream-reader": "^0.1.1",
"bytes": "^3.1.0", "bytes": "^3.1.0",
"dataprotocol-client": "github:Microsoft/sqlops-dataprotocolclient#1.2.2", "dataprotocol-client": "github:Microsoft/sqlops-dataprotocolclient#1.2.3",
"error-ex": "^1.3.2", "error-ex": "^1.3.2",
"figures": "^2.0.0", "figures": "^2.0.0",
"find-remove": "1.2.1", "find-remove": "1.2.1",

View File

@@ -551,9 +551,9 @@ dashdash@^1.12.0:
dependencies: dependencies:
assert-plus "^1.0.0" assert-plus "^1.0.0"
"dataprotocol-client@github:Microsoft/sqlops-dataprotocolclient#1.2.2": "dataprotocol-client@github:Microsoft/sqlops-dataprotocolclient#1.2.3":
version "1.2.2" version "1.2.3"
resolved "https://codeload.github.com/Microsoft/sqlops-dataprotocolclient/tar.gz/3ffb03ba8b892cffe6ad363a2269c1f9439cf350" resolved "https://codeload.github.com/Microsoft/sqlops-dataprotocolclient/tar.gz/c2282e6230e596eb647be8d50239b0486707f962"
dependencies: dependencies:
vscode-languageclient "5.2.1" vscode-languageclient "5.2.1"

View File

@@ -928,4 +928,16 @@ declare module 'azdata' {
*/ */
icon?: IconPath | SqlThemeIcon; icon?: IconPath | SqlThemeIcon;
} }
export interface ObjectMetadata {
/*
* Parent object name for subobjects such as triggers, indexes, etc.
*/
parentName?: string;
/*
* Parent object type name, such as Table, View, etc.
*/
parentTypeName?: string;
}
} }

View File

@@ -12,6 +12,8 @@ export class ObjectMetadataWrapper implements ObjectMetadata {
public urn: string; public urn: string;
public name: string; public name: string;
public schema: string; public schema: string;
public parentName: string;
public parentTypeName: string;
public get fullName(): string { public get fullName(): string {
return `${this.schema}.${this.name}`; return `${this.schema}.${this.name}`;
@@ -23,6 +25,8 @@ export class ObjectMetadataWrapper implements ObjectMetadata {
this.urn = from.urn; this.urn = from.urn;
this.name = from.name; this.name = from.name;
this.schema = from.schema; this.schema = from.schema;
this.parentName = from.parentName;
this.parentTypeName = from.parentTypeName;
} }
public matches(other: ObjectMetadataWrapper): boolean { public matches(other: ObjectMetadataWrapper): boolean {
@@ -32,7 +36,8 @@ export class ObjectMetadataWrapper implements ObjectMetadata {
return this.metadataType === other.metadataType return this.metadataType === other.metadataType
&& this.schema === other.schema && this.schema === other.schema
&& this.name === other.name; && this.name === other.name
&& this.parentName === other.parentName;
} }
// custom sort : Table > View > Stored Procedures > Function // custom sort : Table > View > Stored Procedures > Function

View File

@@ -19,35 +19,45 @@ suite('Explorer Widget Tests', () => {
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testView', name: 'testView',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.Table, metadataType: MetadataType.Table,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testTable', name: 'testTable',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.SProc, metadataType: MetadataType.SProc,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testSProc', name: 'testSProc',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.Function, metadataType: MetadataType.Function,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testFunction', name: 'testFunction',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.View, metadataType: MetadataType.View,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'firstView', name: 'firstView',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
} }
].map(m => new ObjectMetadataWrapper(m)); ].map(m => new ObjectMetadataWrapper(m));
@@ -84,35 +94,45 @@ suite('Explorer Widget Tests', () => {
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testView', name: 'testView',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.Table, metadataType: MetadataType.Table,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testTable', name: 'testTable',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.SProc, metadataType: MetadataType.SProc,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testSProc', name: 'testSProc',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.Function, metadataType: MetadataType.Function,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'testFunction', name: 'testFunction',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}, },
{ {
metadataType: MetadataType.View, metadataType: MetadataType.View,
metadataTypeName: undefined, metadataTypeName: undefined,
urn: undefined, urn: undefined,
name: 'firstView', name: 'firstView',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
} }
].map(o => new ObjectMetadataWrapper(o)); ].map(o => new ObjectMetadataWrapper(o));
const filter = new ExplorerFilter('database', ['name']); const filter = new ExplorerFilter('database', ['name']);

View File

@@ -1,158 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
import { isWindows } from 'vs/base/common/platform';
import { INodeContextValue } from 'sql/workbench/services/objectExplorer/browser/mssqlNodeContext';
export class NodeContextUtils extends Disposable {
static readonly canSelect = new Set([NodeType.Table, NodeType.View]);
static readonly canEditData = new Set([NodeType.Table]);
static readonly canCreateOrDelete = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
NodeType.Schema, NodeType.StoredProcedure, NodeType.Table, NodeType.TableValuedFunction,
NodeType.User, NodeType.UserDefinedTableType, NodeType.View]);
static readonly canExecute = new Set([NodeType.StoredProcedure]);
static readonly canAlter = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
NodeType.StoredProcedure, NodeType.TableValuedFunction, NodeType.View, NodeType.Function]);
// General node context keys
static NodeProvider = new RawContextKey<string>('nodeProvider', undefined);
static IsDatabaseOrServer = new RawContextKey<boolean>('isDatabaseOrServer', false);
static IsWindows = new RawContextKey<boolean>('isWindows', isWindows);
static IsCloud = new RawContextKey<boolean>('isCloud', false);
static NodeType = new RawContextKey<string>('nodeType', undefined);
static NodeLabel = new RawContextKey<string>('nodeLabel', undefined);
// Scripting context keys
static CanScriptAsSelect = new RawContextKey<boolean>('canScriptAsSelect', false);
static CanEditData = new RawContextKey<boolean>('canEditData', false);
static CanScriptAsCreateOrDelete = new RawContextKey<boolean>('canScriptAsCreateOeDelete', false);
static CanScriptAsExecute = new RawContextKey<boolean>('canScriptAsExecute', false);
static CanScriptAsAlter = new RawContextKey<boolean>('canScriptAsAlter', false);
private nodeProviderKey: IContextKey<string>;
private isCloudKey: IContextKey<boolean>;
private nodeTypeKey: IContextKey<string>;
private nodeLabelKey: IContextKey<string>;
private isDatabaseOrServerKey: IContextKey<boolean>;
private canScriptAsSelectKey: IContextKey<boolean>;
private canEditDataKey: IContextKey<boolean>;
private canScriptAsCreateOrDeleteKey: IContextKey<boolean>;
private canScriptAsExecuteKey: IContextKey<boolean>;
private canScriptAsAlterKey: IContextKey<boolean>;
constructor(
private nodeContextValue: INodeContextValue,
@IContextKeyService private contextKeyService: IContextKeyService,
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
@ICapabilitiesService private capabilitiesService: ICapabilitiesService
) {
super();
this.bindContextKeys();
// Set additional node context keys
if (this.nodeContextValue.node) {
const node = this.nodeContextValue.node;
if (node.payload) {
this.setNodeProvider();
this.setIsCloud();
if (node.type) {
this.setIsDatabaseOrServer();
this.nodeTypeKey.set(node.type);
} else if (node.contextValue && node.providerHandle === mssqlProviderName) {
this.setIsDatabaseOrServer();
this.setScriptingContextKeys();
this.nodeTypeKey.set(node.contextValue);
}
}
if (node.label) {
this.nodeLabelKey.set(node.label.label);
}
}
}
private bindContextKeys(): void {
this.isCloudKey = NodeContextUtils.IsCloud.bindTo(this.contextKeyService);
this.nodeTypeKey = NodeContextUtils.NodeType.bindTo(this.contextKeyService);
this.nodeLabelKey = NodeContextUtils.NodeLabel.bindTo(this.contextKeyService);
this.isDatabaseOrServerKey = NodeContextUtils.IsDatabaseOrServer.bindTo(this.contextKeyService);
this.canScriptAsSelectKey = NodeContextUtils.CanScriptAsSelect.bindTo(this.contextKeyService);
this.canEditDataKey = NodeContextUtils.CanEditData.bindTo(this.contextKeyService);
this.canScriptAsCreateOrDeleteKey = NodeContextUtils.CanScriptAsCreateOrDelete.bindTo(this.contextKeyService);
this.canScriptAsExecuteKey = NodeContextUtils.CanScriptAsExecute.bindTo(this.contextKeyService);
this.canScriptAsAlterKey = NodeContextUtils.CanScriptAsAlter.bindTo(this.contextKeyService);
this.nodeProviderKey = NodeContextUtils.NodeProvider.bindTo(this.contextKeyService);
}
/**
* Helper function to get the node provider
*/
private setNodeProvider(): void {
if (this.nodeContextValue.node.payload.providerName) {
this.nodeProviderKey.set(this.nodeContextValue.node.payload.providerName);
} else if (this.nodeContextValue.node.childProvider) {
this.nodeProviderKey.set(this.nodeContextValue.node.childProvider);
}
}
/**
* Helper function to tell whether a connected node is cloud or not
*/
private setIsCloud(): void {
const profile = new ConnectionProfile(this.capabilitiesService,
this.nodeContextValue.node.payload);
const connection = this.connectionManagementService.findExistingConnection(profile);
if (connection) {
const serverInfo = this.connectionManagementService.getServerInfo(connection.id);
if (serverInfo.isCloud) {
this.isCloudKey.set(true);
}
}
}
/**
* Helper function to tell whether a connected node is a database or a
* server or not. Added this key because this is easier to write than
* writing an OR statement in ContextKeyExpr
*/
private setIsDatabaseOrServer(): void {
const isDatabaseOrServer = (this.nodeContextValue.node.contextValue === NodeType.Server ||
this.nodeContextValue.node.contextValue === NodeType.Database ||
this.nodeContextValue.node.type === NodeType.Server ||
this.nodeContextValue.node.type === NodeType.Database);
this.isDatabaseOrServerKey.set(isDatabaseOrServer);
}
/**
* Helper function to get the correct context from node for showing
* scripting context menu actions
*/
private setScriptingContextKeys(): void {
const nodeType = this.nodeContextValue.node.contextValue;
if (NodeContextUtils.canCreateOrDelete.has(nodeType)) {
this.canScriptAsCreateOrDeleteKey.set(true);
}
if (NodeContextUtils.canEditData.has(nodeType)) {
this.canEditDataKey.set(true);
}
if (NodeContextUtils.canAlter.has(nodeType)) {
this.canScriptAsAlterKey.set(true);
}
if (NodeContextUtils.canExecute.has(nodeType)) {
this.canScriptAsExecuteKey.set(true);
}
if (NodeContextUtils.canSelect.has(nodeType)) {
this.canScriptAsSelectKey.set(true);
}
}
}

View File

@@ -103,8 +103,8 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
ConnectionContextKey.Provider.notEqualsTo('KUSTO'), ConnectionContextKey.Provider.notEqualsTo('KUSTO'),
ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'), ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'),
ContextKeyExpr.or( ContextKeyExpr.or(
TreeNodeContextKey.NodeType.isEqualTo('Table'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
TreeNodeContextKey.NodeType.isEqualTo('View') TreeNodeContextKey.NodeType.isEqualTo(NodeType.View)
) )
) )
}); });
@@ -117,8 +117,8 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
title: localize('scriptKustoSelect', "Take 10") title: localize('scriptKustoSelect', "Take 10")
}, },
when: ContextKeyExpr.or( when: ContextKeyExpr.or(
ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('KUSTO'), TreeNodeContextKey.NodeType.isEqualTo('Table')), ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('KUSTO'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table)),
ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('LOGANALYTICS'), TreeNodeContextKey.NodeType.isEqualTo('Table'))) ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('LOGANALYTICS'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table)))
}); });
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
@@ -130,7 +130,7 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
}, },
when: when:
ContextKeyExpr.and( ContextKeyExpr.and(
TreeNodeContextKey.NodeType.isEqualTo('Table'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
ConnectionContextKey.Provider.notEqualsTo('KUSTO'), ConnectionContextKey.Provider.notEqualsTo('KUSTO'),
ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'), ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'),
MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()),
@@ -150,16 +150,24 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
ConnectionContextKey.Provider.notEqualsTo('KUSTO'), ConnectionContextKey.Provider.notEqualsTo('KUSTO'),
ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'), ConnectionContextKey.Provider.notEqualsTo('LOGANALYTICS'),
ContextKeyExpr.or( ContextKeyExpr.or(
TreeNodeContextKey.NodeType.isEqualTo('Table'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
TreeNodeContextKey.NodeType.isEqualTo('View'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.View),
TreeNodeContextKey.NodeType.isEqualTo('Schema'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Schema),
ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('User'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())), ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo(NodeType.User), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
TreeNodeContextKey.NodeType.isEqualTo('UserDefinedTableType'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.UserDefinedTableType),
TreeNodeContextKey.NodeType.isEqualTo('AggregateFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure),
TreeNodeContextKey.NodeType.isEqualTo('PartitionFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction),
TreeNodeContextKey.NodeType.isEqualTo('ScalarValuedFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction),
TreeNodeContextKey.NodeType.isEqualTo('TableValuedFunction') TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Trigger),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.DatabaseTrigger),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Index),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Key),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.DatabaseRole),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ApplicationRole)
) )
) )
}); });
@@ -172,8 +180,8 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
title: localize('scriptExecute', "Script as Execute") title: localize('scriptExecute', "Script as Execute")
}, },
when: ContextKeyExpr.or( when: ContextKeyExpr.or(
ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('MSSQL'), TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure')), ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('MSSQL'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure)),
ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('KUSTO'), TreeNodeContextKey.NodeType.isEqualTo('Function'))) ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('KUSTO'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Function)))
}); });
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
@@ -231,7 +239,14 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction), TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction), TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction), TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction) TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Trigger),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.DatabaseTrigger),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Index),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Key),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.DatabaseRole),
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ApplicationRole)
) )
) )
}); });

View File

@@ -26,7 +26,8 @@ export class MssqlNodeContext extends Disposable {
static readonly canEditData = new Set([NodeType.Table]); static readonly canEditData = new Set([NodeType.Table]);
static readonly canCreateOrDelete = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction, static readonly canCreateOrDelete = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
NodeType.Schema, NodeType.StoredProcedure, NodeType.Table, NodeType.TableValuedFunction, NodeType.Schema, NodeType.StoredProcedure, NodeType.Table, NodeType.TableValuedFunction,
NodeType.User, NodeType.UserDefinedTableType, NodeType.View]); NodeType.User, NodeType.UserDefinedTableType, NodeType.View, NodeType.Trigger, NodeType.DatabaseTrigger,
NodeType.Index, NodeType.User, NodeType.DatabaseRole, NodeType.ApplicationRole, NodeType.Key]);
static readonly canExecute = new Set([NodeType.StoredProcedure, NodeType.Function]); static readonly canExecute = new Set([NodeType.StoredProcedure, NodeType.Function]);
static readonly canAlter = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction, static readonly canAlter = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
NodeType.StoredProcedure, NodeType.TableValuedFunction, NodeType.View, NodeType.Function]); NodeType.StoredProcedure, NodeType.TableValuedFunction, NodeType.View, NodeType.Function]);

View File

@@ -407,15 +407,17 @@ suite('SQL Object Explorer Service tests', () => {
metadataTypeName: 'Database', metadataTypeName: 'Database',
urn: '//server/db1/', urn: '//server/db1/',
name: 'Db1', name: 'Db1',
schema: null schema: undefined,
parentName: undefined,
parentTypeName: undefined
}; };
const databaseNode = new TreeNode(NodeType.Database, 'Db1', false, 'testServerName\\Db1', '', '', null, databaseMetaData, undefined, undefined); const databaseNode = new TreeNode(NodeType.Database, 'Db1', false, 'testServerName\\Db1', '', '', undefined, databaseMetaData, undefined, undefined);
databaseNode.connection = connection; databaseNode.connection = connection;
databaseNode.session = objectExplorerSession; databaseNode.session = objectExplorerSession;
const tablesNode = new TreeNode(NodeType.Folder, 'Tables', false, 'testServerName\\Db1\\tables', '', '', databaseNode, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, 'Tables', false, 'testServerName\\Db1\\tables', '', '', databaseNode, undefined, undefined, undefined);
databaseNode.children = [tablesNode]; databaseNode.children = [tablesNode];
const table1Node = new TreeNode(NodeType.Table, 'dbo.Table1', false, 'testServerName\\Db1\\tables\\dbo.Table1', '', '', tablesNode, null, undefined, undefined); const table1Node = new TreeNode(NodeType.Table, 'dbo.Table1', false, 'testServerName\\Db1\\tables\\dbo.Table1', '', '', tablesNode, undefined, undefined, undefined);
const table2Node = new TreeNode(NodeType.Table, 'dbo.Table2', false, 'testServerName\\Db1\\tables\\dbo.Table2', '', '', tablesNode, null, undefined, undefined); const table2Node = new TreeNode(NodeType.Table, 'dbo.Table2', false, 'testServerName\\Db1\\tables\\dbo.Table2', '', '', tablesNode, undefined, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
assert.equal(table1Node.getSession(), objectExplorerSession); assert.equal(table1Node.getSession(), objectExplorerSession);
assert.equal(table1Node.getConnectionProfile(), connection); assert.equal(table1Node.getConnectionProfile(), connection);
@@ -451,7 +453,9 @@ suite('SQL Object Explorer Service tests', () => {
metadataTypeName: 'Database', metadataTypeName: 'Database',
urn: '//server/db1/', urn: '//server/db1/',
name: 'Db1', name: 'Db1',
schema: undefined schema: undefined,
parentName: undefined,
parentTypeName: undefined
}; };
const databaseName = 'Db1'; const databaseName = 'Db1';
const databaseNode = new TreeNode(NodeType.Database, databaseName, false, 'testServerName\\Db1', '', '', undefined, databaseMetadata, undefined, undefined); const databaseNode = new TreeNode(NodeType.Database, databaseName, false, 'testServerName\\Db1', '', '', undefined, databaseMetadata, undefined, undefined);