mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
improve sql bindings extension (#18757)
This commit is contained in:
@@ -63,7 +63,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@microsoft/ads-extension-telemetry": "^1.1.5",
|
"@microsoft/ads-extension-telemetry": "^1.1.5",
|
||||||
"fast-glob": "^3.2.7",
|
"fast-glob": "^3.2.7",
|
||||||
"jsonc-parser": "^2.3.1",
|
|
||||||
"promisify-child-process": "^3.1.1",
|
"promisify-child-process": "^3.1.1",
|
||||||
"vscode-nls": "^4.1.2",
|
"vscode-nls": "^4.1.2",
|
||||||
"vscode-languageclient": "5.2.1"
|
"vscode-languageclient": "5.2.1"
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import * as path from 'path';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import * as constants from './constants';
|
import * as constants from './constants';
|
||||||
import { BindingType } from 'sql-bindings';
|
import { BindingType } from 'sql-bindings';
|
||||||
import * as path from 'path';
|
|
||||||
import { ConnectionDetails, IConnectionInfo } from 'vscode-mssql';
|
import { ConnectionDetails, IConnectionInfo } from 'vscode-mssql';
|
||||||
// https://github.com/microsoft/vscode-azurefunctions/blob/main/src/vscode-azurefunctions.api.d.ts
|
// https://github.com/microsoft/vscode-azurefunctions/blob/main/src/vscode-azurefunctions.api.d.ts
|
||||||
import { AzureFunctionsExtensionApi } from '../typings/vscode-azurefunctions.api';
|
import { AzureFunctionsExtensionApi } from '../typings/vscode-azurefunctions.api';
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
||||||
*--------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// copied from vscode-azurefunctions extension
|
|
||||||
|
|
||||||
import * as jsonc from 'jsonc-parser';
|
|
||||||
import * as constants from './constants';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses and returns JSON
|
|
||||||
* Has extra logic to remove a BOM character if it exists and handle comments
|
|
||||||
*/
|
|
||||||
export function parseJson<T extends object>(data: string): T {
|
|
||||||
if (data.charCodeAt(0) === 0xFEFF) {
|
|
||||||
data = data.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const errors: jsonc.ParseError[] = [];
|
|
||||||
const result: T = <T>jsonc.parse(data, errors, { allowTrailingComma: true });
|
|
||||||
if (errors.length > 0) {
|
|
||||||
const [line, column]: [number, number] = getLineAndColumnFromOffset(data, errors[0].offset);
|
|
||||||
throw new Error(constants.jsonParseError(jsonc.printParseErrorCode(errors[0].error), line, column));
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLineAndColumnFromOffset(data: string, offset: number): [number, number] {
|
|
||||||
const lines: string[] = data.split('\n');
|
|
||||||
let charCount: number = 0;
|
|
||||||
let lineCount: number = 0;
|
|
||||||
let column: number = 0;
|
|
||||||
for (const line of lines) {
|
|
||||||
lineCount += 1;
|
|
||||||
const lineLength: number = line.length + 1;
|
|
||||||
charCount += lineLength;
|
|
||||||
if (charCount >= offset) {
|
|
||||||
column = offset - (charCount - lineLength);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [lineCount, column];
|
|
||||||
}
|
|
||||||
@@ -32,16 +32,6 @@ export function getErrorMessage(error: any): string {
|
|||||||
: typeof error === 'string' ? error : `${JSON.stringify(error, undefined, '\t')}`;
|
: typeof error === 'string' ? error : `${JSON.stringify(error, undefined, '\t')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAzureFunctionService(): Promise<vscodeMssql.IAzureFunctionsService> {
|
|
||||||
if (getAzdataApi()) {
|
|
||||||
// this isn't supported in ADS
|
|
||||||
throw new Error('Azure Functions service is not supported in Azure Data Studio');
|
|
||||||
} else {
|
|
||||||
const api = await getVscodeMssqlApi();
|
|
||||||
return api.azureFunctions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getVscodeMssqlApi(): Promise<vscodeMssql.IExtension> {
|
export async function getVscodeMssqlApi(): Promise<vscodeMssql.IExtension> {
|
||||||
const ext = vscode.extensions.getExtension(vscodeMssql.extension.name) as vscode.Extension<vscodeMssql.IExtension>;
|
const ext = vscode.extensions.getExtension(vscodeMssql.extension.name) as vscode.Extension<vscodeMssql.IExtension>;
|
||||||
return ext.activate();
|
return ext.activate();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import * as constants from '../common/constants';
|
|||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||||
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
|
import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/telemetry';
|
||||||
|
import { addSqlBinding, getAzureFunctions } from '../services/azureFunctionsService';
|
||||||
|
|
||||||
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined): Promise<void> {
|
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined): Promise<void> {
|
||||||
TelemetryReporter.sendActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.startAddSqlBinding);
|
TelemetryReporter.sendActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.startAddSqlBinding);
|
||||||
@@ -27,16 +28,16 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all the Azure functions in the file
|
// get azure functions from STS request
|
||||||
const azureFunctionsService = await utils.getAzureFunctionService();
|
|
||||||
let getAzureFunctionsResult;
|
let getAzureFunctionsResult;
|
||||||
try {
|
try {
|
||||||
getAzureFunctionsResult = await azureFunctionsService.getAzureFunctions(uri.fsPath);
|
getAzureFunctionsResult = await getAzureFunctions(uri.fsPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
void vscode.window.showErrorMessage(utils.getErrorMessage(e));
|
void vscode.window.showErrorMessage(utils.getErrorMessage(e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get all the Azure functions in the file
|
||||||
const azureFunctions = getAzureFunctionsResult.azureFunctions;
|
const azureFunctions = getAzureFunctionsResult.azureFunctions;
|
||||||
|
|
||||||
if (azureFunctions.length === 0) {
|
if (azureFunctions.length === 0) {
|
||||||
@@ -84,7 +85,7 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
|
|||||||
|
|
||||||
// 5. insert binding
|
// 5. insert binding
|
||||||
try {
|
try {
|
||||||
const result = await azureFunctionsService.addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
|
const result = await addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
void vscode.window.showErrorMessage(result.errorMessage);
|
void vscode.window.showErrorMessage(result.errorMessage);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
import * as azureFunctionUtils from '../common/azureFunctionsUtils';
|
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||||
import * as constants from '../common/constants';
|
import * as constants from '../common/constants';
|
||||||
import * as azureFunctionsContracts from '../contracts/azureFunctions/azureFunctionsContracts';
|
import * as azureFunctionsContracts from '../contracts/azureFunctions/azureFunctionsContracts';
|
||||||
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, ResultStatus } from 'sql-bindings';
|
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, ResultStatus } from 'sql-bindings';
|
||||||
@@ -15,12 +15,12 @@ export const hostFileName: string = 'host.json';
|
|||||||
|
|
||||||
|
|
||||||
export async function createAzureFunction(connectionString: string, schema: string, table: string): Promise<void> {
|
export async function createAzureFunction(connectionString: string, schema: string, table: string): Promise<void> {
|
||||||
const azureFunctionApi = await azureFunctionUtils.getAzureFunctionsExtensionApi();
|
const azureFunctionApi = await azureFunctionsUtils.getAzureFunctionsExtensionApi();
|
||||||
if (!azureFunctionApi) {
|
if (!azureFunctionApi) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let projectFile = await azureFunctionUtils.getAzureFunctionProject();
|
let projectFile = await azureFunctionsUtils.getAzureFunctionProject();
|
||||||
let newHostProjectFile!: azureFunctionUtils.IFileFunctionObject;
|
let newHostProjectFile!: azureFunctionsUtils.IFileFunctionObject;
|
||||||
let hostFile: string;
|
let hostFile: string;
|
||||||
|
|
||||||
if (!projectFile) {
|
if (!projectFile) {
|
||||||
@@ -34,13 +34,13 @@ export async function createAzureFunction(connectionString: string, schema: stri
|
|||||||
try {
|
try {
|
||||||
// because of an AF extension API issue, we have to get the newly created file by adding a watcher
|
// because of an AF extension API issue, we have to get the newly created file by adding a watcher
|
||||||
// issue: https://github.com/microsoft/vscode-azurefunctions/issues/3052
|
// issue: https://github.com/microsoft/vscode-azurefunctions/issues/3052
|
||||||
newHostProjectFile = await azureFunctionUtils.waitForNewHostFile();
|
newHostProjectFile = await azureFunctionsUtils.waitForNewHostFile();
|
||||||
await azureFunctionApi.createFunction({});
|
await azureFunctionApi.createFunction({});
|
||||||
const timeoutForHostFile = utils.timeoutPromise(constants.timeoutProjectError);
|
const timeoutForHostFile = utils.timeoutPromise(constants.timeoutProjectError);
|
||||||
hostFile = await Promise.race([newHostProjectFile.filePromise, timeoutForHostFile]);
|
hostFile = await Promise.race([newHostProjectFile.filePromise, timeoutForHostFile]);
|
||||||
if (hostFile) {
|
if (hostFile) {
|
||||||
// start the add sql binding flow
|
// start the add sql binding flow
|
||||||
projectFile = await azureFunctionUtils.getAzureFunctionProject();
|
projectFile = await azureFunctionsUtils.getAzureFunctionProject();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
void vscode.window.showErrorMessage(utils.formatString(constants.errorNewAzureFunction, error.message ?? error));
|
void vscode.window.showErrorMessage(utils.formatString(constants.errorNewAzureFunction, error.message ?? error));
|
||||||
@@ -54,7 +54,7 @@ export async function createAzureFunction(connectionString: string, schema: stri
|
|||||||
if (projectFile) {
|
if (projectFile) {
|
||||||
// because of an AF extension API issue, we have to get the newly created file by adding a watcher
|
// because of an AF extension API issue, we have to get the newly created file by adding a watcher
|
||||||
// issue: https://github.com/microsoft/vscode-azurefunctions/issues/2908
|
// issue: https://github.com/microsoft/vscode-azurefunctions/issues/2908
|
||||||
const newFunctionFileObject = azureFunctionUtils.waitForNewFunctionFile(projectFile);
|
const newFunctionFileObject = azureFunctionsUtils.waitForNewFunctionFile(projectFile);
|
||||||
let functionFile: string;
|
let functionFile: string;
|
||||||
let functionName: string;
|
let functionName: string;
|
||||||
|
|
||||||
@@ -87,33 +87,17 @@ export async function createAzureFunction(connectionString: string, schema: stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// select input or output binding
|
// select input or output binding
|
||||||
const inputOutputItems: (vscode.QuickPickItem & { type: BindingType })[] = [
|
const selectedBinding = await azureFunctionsUtils.promptForBindingType();
|
||||||
{
|
|
||||||
label: constants.input,
|
|
||||||
type: BindingType.input
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: constants.output,
|
|
||||||
type: BindingType.output
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const selectedBinding = await vscode.window.showQuickPick(inputOutputItems, {
|
|
||||||
canPickMany: false,
|
|
||||||
title: constants.selectBindingType,
|
|
||||||
ignoreFocusOut: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!selectedBinding) {
|
if (!selectedBinding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await azureFunctionUtils.addNugetReferenceToProjectFile(projectFile);
|
await azureFunctionsUtils.addNugetReferenceToProjectFile(projectFile);
|
||||||
await azureFunctionUtils.addConnectionStringToConfig(connectionString, projectFile);
|
await azureFunctionsUtils.addConnectionStringToConfig(connectionString, projectFile);
|
||||||
|
|
||||||
let objectName = utils.generateQuotedFullName(schema, table);
|
let objectName = utils.generateQuotedFullName(schema, table);
|
||||||
const azureFunctionsService = await utils.getAzureFunctionService();
|
await addSqlBinding(
|
||||||
await azureFunctionsService.addSqlBinding(
|
|
||||||
selectedBinding.type,
|
selectedBinding.type,
|
||||||
functionFile,
|
functionFile,
|
||||||
functionName,
|
functionName,
|
||||||
@@ -121,7 +105,7 @@ export async function createAzureFunction(connectionString: string, schema: stri
|
|||||||
constants.sqlConnectionString
|
constants.sqlConnectionString
|
||||||
);
|
);
|
||||||
|
|
||||||
azureFunctionUtils.overwriteAzureFunctionMethodBody(functionFile);
|
azureFunctionsUtils.overwriteAzureFunctionMethodBody(functionFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +138,6 @@ export async function addSqlBinding(
|
|||||||
return vscodeMssqlApi.sendRequest(azureFunctionsContracts.AddSqlBindingRequest.type, params);
|
return vscodeMssqlApi.sendRequest(azureFunctionsContracts.AddSqlBindingRequest.type, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the names of the Azure functions in the file
|
* Gets the names of the Azure functions in the file
|
||||||
* @param filePath Path of the file to get the Azure functions
|
* @param filePath Path of the file to get the Azure functions
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import * as TypeMoq from 'typemoq';
|
|||||||
import * as utils from '../../common/utils';
|
import * as utils from '../../common/utils';
|
||||||
import * as constants from '../../common/constants';
|
import * as constants from '../../common/constants';
|
||||||
import * as azureFunctionUtils from '../../common/azureFunctionsUtils';
|
import * as azureFunctionUtils from '../../common/azureFunctionsUtils';
|
||||||
|
import * as azureFunctionService from '../../services/azureFunctionsService';
|
||||||
|
|
||||||
import { createTestUtils, TestUtils, createTestCredentials } from '../testUtils';
|
import { createTestUtils, TestUtils, createTestCredentials } from '../testUtils';
|
||||||
import { launchAddSqlBindingQuickpick } from '../../dialogs/addSqlBindingQuickpick';
|
import { launchAddSqlBindingQuickpick } from '../../dialogs/addSqlBindingQuickpick';
|
||||||
|
|
||||||
let testUtils: TestUtils;
|
let testUtils: TestUtils;
|
||||||
|
const fileUri = vscode.Uri.file('testUri');
|
||||||
describe('Add SQL Binding quick pick', () => {
|
describe('Add SQL Binding quick pick', () => {
|
||||||
beforeEach(function (): void {
|
beforeEach(function (): void {
|
||||||
testUtils = createTestUtils();
|
testUtils = createTestUtils();
|
||||||
@@ -25,17 +27,16 @@ describe('Add SQL Binding quick pick', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should show error if the file contains no Azure Functions', async function (): Promise<void> {
|
it('Should show error if the file contains no Azure Functions', async function (): Promise<void> {
|
||||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
|
||||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
Promise.resolve({
|
||||||
return Promise.resolve({
|
|
||||||
success: true,
|
success: true,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
azureFunctions: []
|
azureFunctions: []
|
||||||
});
|
}));
|
||||||
});
|
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||||
await launchAddSqlBindingQuickpick(vscode.Uri.file('testUri'));
|
|
||||||
|
await launchAddSqlBindingQuickpick(fileUri);
|
||||||
|
|
||||||
const msg = constants.noAzureFunctionsInFile;
|
const msg = constants.noAzureFunctionsInFile;
|
||||||
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
||||||
@@ -43,25 +44,24 @@ describe('Add SQL Binding quick pick', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should show error if adding SQL binding was not successful', async function (): Promise<void> {
|
it('Should show error if adding SQL binding was not successful', async function (): Promise<void> {
|
||||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
|
||||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
Promise.resolve({
|
||||||
return Promise.resolve({
|
|
||||||
success: true,
|
success: true,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
azureFunctions: ['af1', 'af2']
|
azureFunctions: ['af1', 'af2']
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
//failure since no AFs are found in the project
|
//failure since no AFs are found in the project
|
||||||
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(undefined);
|
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(undefined);
|
||||||
const errormsg = 'Error inserting binding';
|
const errormsg = 'Error inserting binding';
|
||||||
testUtils.azureFunctionService.setup(x => x.addSqlBinding(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(async () => {
|
sinon.stub(azureFunctionService, 'addSqlBinding').withArgs(
|
||||||
return Promise.resolve({
|
sinon.match.any, sinon.match.any, sinon.match.any,
|
||||||
|
sinon.match.any, sinon.match.any).returns(
|
||||||
|
Promise.resolve({
|
||||||
success: false,
|
success: false,
|
||||||
errorMessage: errormsg
|
errorMessage: errormsg
|
||||||
});
|
}));
|
||||||
});
|
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||||
|
|
||||||
// select Azure function
|
// select Azure function
|
||||||
let quickpickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves({ label: 'af1' });
|
let quickpickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves({ label: 'af1' });
|
||||||
@@ -79,18 +79,16 @@ describe('Add SQL Binding quick pick', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should show error connection profile does not connect', async function (): Promise<void> {
|
it('Should show error connection profile does not connect', async function (): Promise<void> {
|
||||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
|
||||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||||
let connectionCreds = createTestCredentials();
|
let connectionCreds = createTestCredentials();
|
||||||
|
|
||||||
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(vscode.Uri.file('testUri'));
|
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(vscode.Uri.file('testUri'));
|
||||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||||
return Promise.resolve({
|
Promise.resolve({
|
||||||
success: true,
|
success: true,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
azureFunctions: ['af1']
|
azureFunctions: ['af1']
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
// Mocks connect call to mssql
|
// Mocks connect call to mssql
|
||||||
let error = new Error('Connection Request Failed');
|
let error = new Error('Connection Request Failed');
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ import * as TypeMoq from 'typemoq';
|
|||||||
import * as mssql from '../../../mssql/src/mssql';
|
import * as mssql from '../../../mssql/src/mssql';
|
||||||
import * as vscodeMssql from 'vscode-mssql';
|
import * as vscodeMssql from 'vscode-mssql';
|
||||||
import { RequestType } from 'vscode-languageclient';
|
import { RequestType } from 'vscode-languageclient';
|
||||||
import { BindingType, GetAzureFunctionsResult } from 'sql-bindings';
|
|
||||||
|
|
||||||
export interface TestUtils {
|
export interface TestUtils {
|
||||||
context: vscode.ExtensionContext;
|
context: vscode.ExtensionContext;
|
||||||
dacFxService: TypeMoq.IMock<mssql.IDacFxService>;
|
dacFxService: TypeMoq.IMock<mssql.IDacFxService>;
|
||||||
azureFunctionService: TypeMoq.IMock<vscodeMssql.IAzureFunctionsService>;
|
|
||||||
outputChannel: vscode.OutputChannel;
|
outputChannel: vscode.OutputChannel;
|
||||||
vscodeMssqlIExtension: TypeMoq.IMock<vscodeMssql.IExtension>
|
vscodeMssqlIExtension: TypeMoq.IMock<vscodeMssql.IExtension>
|
||||||
dacFxMssqlService: TypeMoq.IMock<vscodeMssql.IDacFxService>;
|
dacFxMssqlService: TypeMoq.IMock<vscodeMssql.IDacFxService>;
|
||||||
@@ -131,17 +129,6 @@ export const mockResultStatus = {
|
|||||||
errorMessage: ''
|
errorMessage: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mockGetAzureFunctionsResult = {
|
|
||||||
success: true,
|
|
||||||
errorMessage: '',
|
|
||||||
azureFunctions: []
|
|
||||||
};
|
|
||||||
|
|
||||||
export class MockAzureFunctionService implements vscodeMssql.IAzureFunctionsService {
|
|
||||||
addSqlBinding(_: BindingType, __: string, ___: string, ____: string, _____: string): Thenable<vscodeMssql.ResultStatus> { return Promise.resolve(mockResultStatus); }
|
|
||||||
getAzureFunctions(_: string): Thenable<GetAzureFunctionsResult> { return Promise.resolve(mockGetAzureFunctionsResult); }
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mockDacFxMssqlOptionResult: vscodeMssql.DacFxOptionsResult = {
|
export const mockDacFxMssqlOptionResult: vscodeMssql.DacFxOptionsResult = {
|
||||||
success: true,
|
success: true,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
@@ -249,12 +236,10 @@ export class MockVscodeMssqlIExtension implements vscodeMssql.IExtension {
|
|||||||
sqlToolsServicePath: string = '';
|
sqlToolsServicePath: string = '';
|
||||||
dacFx: vscodeMssql.IDacFxService;
|
dacFx: vscodeMssql.IDacFxService;
|
||||||
schemaCompare: vscodeMssql.ISchemaCompareService;
|
schemaCompare: vscodeMssql.ISchemaCompareService;
|
||||||
azureFunctions: vscodeMssql.IAzureFunctionsService;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.dacFx = new MockDacFxMssqlService;
|
this.dacFx = new MockDacFxMssqlService;
|
||||||
this.schemaCompare = new MockSchemaCompareService;
|
this.schemaCompare = new MockSchemaCompareService;
|
||||||
this.azureFunctions = new MockAzureFunctionService;
|
|
||||||
}
|
}
|
||||||
sendRequest<P, R, E, R0>(_: RequestType<P, R, E, R0>, __?: P): Promise<R> {
|
sendRequest<P, R, E, R0>(_: RequestType<P, R, E, R0>, __?: P): Promise<R> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
@@ -311,7 +296,6 @@ export function createTestUtils(): TestUtils {
|
|||||||
extension: undefined as any
|
extension: undefined as any
|
||||||
},
|
},
|
||||||
dacFxService: TypeMoq.Mock.ofType(MockDacFxService),
|
dacFxService: TypeMoq.Mock.ofType(MockDacFxService),
|
||||||
azureFunctionService: TypeMoq.Mock.ofType(MockAzureFunctionService),
|
|
||||||
vscodeMssqlIExtension: TypeMoq.Mock.ofType(MockVscodeMssqlIExtension),
|
vscodeMssqlIExtension: TypeMoq.Mock.ofType(MockVscodeMssqlIExtension),
|
||||||
dacFxMssqlService: TypeMoq.Mock.ofType(MockDacFxMssqlService),
|
dacFxMssqlService: TypeMoq.Mock.ofType(MockDacFxMssqlService),
|
||||||
schemaCompareService: TypeMoq.Mock.ofType(MockSchemaCompareService),
|
schemaCompareService: TypeMoq.Mock.ofType(MockSchemaCompareService),
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ declare module 'vscode-mssql' {
|
|||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { RequestType } from 'vscode-languageclient';
|
import { RequestType } from 'vscode-languageclient';
|
||||||
import { BindingType, GetAzureFunctionsResult } from 'sql-bindings';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Covers defining what the vscode-mssql extension exports to other extensions
|
* Covers defining what the vscode-mssql extension exports to other extensions
|
||||||
@@ -41,11 +40,6 @@ declare module 'vscode-mssql' {
|
|||||||
*/
|
*/
|
||||||
readonly schemaCompare: ISchemaCompareService;
|
readonly schemaCompare: ISchemaCompareService;
|
||||||
|
|
||||||
/**
|
|
||||||
* Service for accessing AzureFunctions functionality
|
|
||||||
*/
|
|
||||||
readonly azureFunctions: IAzureFunctionsService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts the user to select an existing connection or create a new one, and then returns the result
|
* Prompts the user to select an existing connection or create a new one, and then returns the result
|
||||||
* @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false)
|
* @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false)
|
||||||
@@ -302,24 +296,6 @@ declare module 'vscode-mssql' {
|
|||||||
validateStreamingJob(packageFilePath: string, createStreamingJobTsql: string): Thenable<ValidateStreamingJobResult>;
|
validateStreamingJob(packageFilePath: string, createStreamingJobTsql: string): Thenable<ValidateStreamingJobResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAzureFunctionsService {
|
|
||||||
/**
|
|
||||||
* Adds a SQL Binding to a specified Azure function in a file
|
|
||||||
* @param bindingType Type of SQL Binding
|
|
||||||
* @param filePath Path of the file where the Azure Functions are
|
|
||||||
* @param functionName Name of the function where the SQL Binding is to be added
|
|
||||||
* @param objectName Name of Object for the SQL Query
|
|
||||||
* @param connectionStringSetting Setting for the connection string
|
|
||||||
*/
|
|
||||||
addSqlBinding(bindingType: BindingType, filePath: string, functionName: string, objectName: string, connectionStringSetting: string): Thenable<ResultStatus>;
|
|
||||||
/**
|
|
||||||
* Gets the names of the Azure functions in the file
|
|
||||||
* @param filePath Path of the file to get the Azure functions
|
|
||||||
* @returns array of names of Azure functions in the file
|
|
||||||
*/
|
|
||||||
getAzureFunctions(filePath: string): Thenable<GetAzureFunctionsResult>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const enum TaskExecutionMode {
|
export const enum TaskExecutionMode {
|
||||||
execute = 0,
|
execute = 0,
|
||||||
script = 1,
|
script = 1,
|
||||||
|
|||||||
@@ -794,11 +794,6 @@ json5@^2.1.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
minimist "^1.2.5"
|
minimist "^1.2.5"
|
||||||
|
|
||||||
jsonc-parser@^2.3.1:
|
|
||||||
version "2.3.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-2.3.1.tgz#59549150b133f2efacca48fe9ce1ec0659af2342"
|
|
||||||
integrity sha512-H8jvkz1O50L3dMZCsLqiuB2tA7muqbSg1AtGEkN0leAqGjsUzDJir3Zwr02BhqdcITPg3ei3mZ+HjMocAknhhg==
|
|
||||||
|
|
||||||
just-extend@^4.0.2:
|
just-extend@^4.0.2:
|
||||||
version "4.2.1"
|
version "4.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.2.1.tgz#ef5e589afb61e5d66b24eca749409a8939a8c744"
|
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.2.1.tgz#ef5e589afb61e5d66b24eca749409a8939a8c744"
|
||||||
|
|||||||
Reference in New Issue
Block a user