diff --git a/src/Common/DocumentUtility.ts b/src/Common/DocumentUtility.ts index b552ba495..99cdefc5a 100644 --- a/src/Common/DocumentUtility.ts +++ b/src/Common/DocumentUtility.ts @@ -1,8 +1,7 @@ -import { DefaultAccountExperienceType } from "../DefaultAccountExperienceType"; import { userContext } from "../UserContext"; export const getEntityName = (): string => { - if (userContext.defaultExperience === DefaultAccountExperienceType.MongoDB) { + if (userContext.apiType === "Mongo") { return "document"; } diff --git a/src/Common/dataAccess/createCollection.test.ts b/src/Common/dataAccess/createCollection.test.ts index fc5b9a911..ce04404a6 100644 --- a/src/Common/dataAccess/createCollection.test.ts +++ b/src/Common/dataAccess/createCollection.test.ts @@ -2,11 +2,10 @@ jest.mock("../../Utils/arm/request"); jest.mock("../CosmosClient"); import { AuthType } from "../../AuthType"; import { CreateCollectionParams, DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; import { armRequest } from "../../Utils/arm/request"; import { client } from "../CosmosClient"; -import { createCollection, constructRpOptions } from "./createCollection"; -import { updateUserContext } from "../../UserContext"; +import { constructRpOptions, createCollection } from "./createCollection"; describe("createCollection", () => { const createCollectionParams: CreateCollectionParams = { @@ -22,7 +21,7 @@ describe("createCollection", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/createCollection.ts b/src/Common/dataAccess/createCollection.ts index 00cfeb4b5..52b529006 100644 --- a/src/Common/dataAccess/createCollection.ts +++ b/src/Common/dataAccess/createCollection.ts @@ -1,33 +1,32 @@ -import * as DataModels from "../../Contracts/DataModels"; -import { AuthType } from "../../AuthType"; import { ContainerResponse, DatabaseResponse } from "@azure/cosmos"; +import { RequestOptions } from "@azure/cosmos/dist-esm"; import { ContainerRequest } from "@azure/cosmos/dist-esm/client/Container/ContainerRequest"; import { DatabaseRequest } from "@azure/cosmos/dist-esm/client/Database/DatabaseRequest"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { RequestOptions } from "@azure/cosmos/dist-esm"; -import * as ARMTypes from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; -import { createMongoCollectionWithProxy } from "../MongoProxyClient"; -import { createUpdateSqlContainer, getSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { AuthType } from "../../AuthType"; +import * as DataModels from "../../Contracts/DataModels"; +import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; +import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; +import { userContext } from "../../UserContext"; import { createUpdateCassandraTable, getCassandraTable, } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { - createUpdateMongoDBCollection, - getMongoDBCollection, -} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { createUpdateGremlinGraph, getGremlinGraph, } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { + createUpdateMongoDBCollection, + getMongoDBCollection, +} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { createUpdateSqlContainer, getSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { createUpdateTable, getTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { logConsoleProgress, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; -import { createDatabase } from "./createDatabase"; -import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; -import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; +import * as ARMTypes from "../../Utils/arm/generatedClients/2020-04-01/types"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; +import { createMongoCollectionWithProxy } from "../MongoProxyClient"; +import { createDatabase } from "./createDatabase"; export const createCollection = async (params: DataModels.CreateCollectionParams): Promise => { const clearMessage = logConsoleProgress( @@ -46,7 +45,7 @@ export const createCollection = async (params: DataModels.CreateCollectionParams await createDatabase(createDatabaseParams); } collection = await createCollectionWithARM(params); - } else if (userContext.defaultExperience === DefaultAccountExperienceType.MongoDB) { + } else if (userContext.apiType === "Mongo") { collection = await createMongoCollectionWithProxy(params); } else { collection = await createCollectionWithSDK(params); @@ -63,17 +62,17 @@ export const createCollection = async (params: DataModels.CreateCollectionParams }; const createCollectionWithARM = async (params: DataModels.CreateCollectionParams): Promise => { - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": return createSqlContainer(params); - case DefaultAccountExperienceType.MongoDB: + case "Mongo": return createMongoCollection(params); - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": return createCassandraTable(params); - case DefaultAccountExperienceType.Graph: + case "Gremlin": return createGraph(params); - case DefaultAccountExperienceType.Table: + case "Tables": return createTable(params); default: throw new Error(`Unsupported default experience type: ${defaultExperience}`); diff --git a/src/Common/dataAccess/createDatabase.ts b/src/Common/dataAccess/createDatabase.ts index 11dadae67..d6ea3b834 100644 --- a/src/Common/dataAccess/createDatabase.ts +++ b/src/Common/dataAccess/createDatabase.ts @@ -1,37 +1,36 @@ -import * as DataModels from "../../Contracts/DataModels"; -import { AuthType } from "../../AuthType"; import { DatabaseResponse } from "@azure/cosmos"; import { DatabaseRequest } from "@azure/cosmos/dist-esm/client/Database/DatabaseRequest"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { - CassandraKeyspaceCreateUpdateParameters, - GremlinDatabaseCreateUpdateParameters, - MongoDBDatabaseCreateUpdateParameters, - SqlDatabaseCreateUpdateParameters, - CreateUpdateOptions, -} from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; -import { createUpdateSqlDatabase, getSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { AuthType } from "../../AuthType"; +import * as DataModels from "../../Contracts/DataModels"; +import { userContext } from "../../UserContext"; import { createUpdateCassandraKeyspace, getCassandraKeyspace, } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { - createUpdateMongoDBDatabase, - getMongoDBDatabase, -} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { createUpdateGremlinDatabase, getGremlinDatabase, } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { + createUpdateMongoDBDatabase, + getMongoDBDatabase, +} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { createUpdateSqlDatabase, getSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { + CassandraKeyspaceCreateUpdateParameters, + CreateUpdateOptions, + GremlinDatabaseCreateUpdateParameters, + MongoDBDatabaseCreateUpdateParameters, + SqlDatabaseCreateUpdateParameters, +} from "../../Utils/arm/generatedClients/2020-04-01/types"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleProgress, logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; export async function createDatabase(params: DataModels.CreateDatabaseParams): Promise { const clearMessage = logConsoleProgress(`Creating a new database ${params.databaseId}`); try { - if (userContext.defaultExperience === DefaultAccountExperienceType.Table) { + if (userContext.apiType === "Tables") { throw new Error("Creating database resources is not allowed for tables accounts"); } const database: DataModels.Database = await (userContext.authType === AuthType.AAD && !userContext.useSDKOperations @@ -49,15 +48,15 @@ export async function createDatabase(params: DataModels.CreateDatabaseParams): P } async function createDatabaseWithARM(params: DataModels.CreateDatabaseParams): Promise { - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": return createSqlDatabase(params); - case DefaultAccountExperienceType.MongoDB: + case "Mongo": return createMongoDatabase(params); - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": return createCassandraKeyspace(params); - case DefaultAccountExperienceType.Graph: + case "Gremlin": return createGremlineDatabase(params); default: throw new Error(`Unsupported default experience type: ${defaultExperience}`); diff --git a/src/Common/dataAccess/createStoredProcedure.ts b/src/Common/dataAccess/createStoredProcedure.ts index e3a448dec..471ea0f97 100644 --- a/src/Common/dataAccess/createStoredProcedure.ts +++ b/src/Common/dataAccess/createStoredProcedure.ts @@ -1,18 +1,17 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; -import { - SqlStoredProcedureCreateUpdateParameters, - SqlStoredProcedureResource, -} from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { createUpdateSqlStoredProcedure, getSqlStoredProcedure, } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; +import { + SqlStoredProcedureCreateUpdateParameters, + SqlStoredProcedureResource, +} from "../../Utils/arm/generatedClients/2020-04-01/types"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function createStoredProcedure( databaseId: string, @@ -21,11 +20,7 @@ export async function createStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Creating stored procedure ${storedProcedure.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { try { const getResponse = await getSqlStoredProcedure( userContext.subscriptionId, diff --git a/src/Common/dataAccess/createTrigger.ts b/src/Common/dataAccess/createTrigger.ts index 8a750402f..d9771b095 100644 --- a/src/Common/dataAccess/createTrigger.ts +++ b/src/Common/dataAccess/createTrigger.ts @@ -1,15 +1,14 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, TriggerDefinition } from "@azure/cosmos"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; +import { createUpdateSqlTrigger, getSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { SqlTriggerCreateUpdateParameters, SqlTriggerResource, } from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; -import { createUpdateSqlTrigger, getSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function createTrigger( databaseId: string, @@ -18,11 +17,7 @@ export async function createTrigger( ): Promise { const clearMessage = logConsoleProgress(`Creating trigger ${trigger.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { try { const getResponse = await getSqlTrigger( userContext.subscriptionId, diff --git a/src/Common/dataAccess/createUserDefinedFunction.ts b/src/Common/dataAccess/createUserDefinedFunction.ts index c90b4b6f0..8608c25da 100644 --- a/src/Common/dataAccess/createUserDefinedFunction.ts +++ b/src/Common/dataAccess/createUserDefinedFunction.ts @@ -1,18 +1,17 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; -import { - SqlUserDefinedFunctionCreateUpdateParameters, - SqlUserDefinedFunctionResource, -} from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { createUpdateSqlUserDefinedFunction, getSqlUserDefinedFunction, } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; +import { + SqlUserDefinedFunctionCreateUpdateParameters, + SqlUserDefinedFunctionResource, +} from "../../Utils/arm/generatedClients/2020-04-01/types"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function createUserDefinedFunction( databaseId: string, @@ -21,11 +20,7 @@ export async function createUserDefinedFunction( ): Promise { const clearMessage = logConsoleProgress(`Creating user defined function ${userDefinedFunction.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { try { const getResponse = await getSqlUserDefinedFunction( userContext.subscriptionId, diff --git a/src/Common/dataAccess/deleteCollection.test.ts b/src/Common/dataAccess/deleteCollection.test.ts index 17886b6c3..f7ddc723d 100644 --- a/src/Common/dataAccess/deleteCollection.test.ts +++ b/src/Common/dataAccess/deleteCollection.test.ts @@ -1,13 +1,12 @@ jest.mock("../../Utils/arm/request"); jest.mock("../MessageHandler"); jest.mock("../CosmosClient"); -import { deleteCollection } from "./deleteCollection"; -import { armRequest } from "../../Utils/arm/request"; import { AuthType } from "../../AuthType"; -import { client } from "../CosmosClient"; -import { updateUserContext } from "../../UserContext"; import { DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; +import { armRequest } from "../../Utils/arm/request"; +import { client } from "../CosmosClient"; +import { deleteCollection } from "./deleteCollection"; describe("deleteCollection", () => { beforeAll(() => { @@ -15,7 +14,7 @@ describe("deleteCollection", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/deleteCollection.ts b/src/Common/dataAccess/deleteCollection.ts index 7bb08c5d7..b1d15ee4b 100644 --- a/src/Common/dataAccess/deleteCollection.ts +++ b/src/Common/dataAccess/deleteCollection.ts @@ -1,14 +1,13 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { deleteSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { deleteCassandraTable } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { deleteMongoDBCollection } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; -import { deleteGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { deleteTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { deleteCassandraTable } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; +import { deleteGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { deleteMongoDBCollection } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { deleteSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { deleteTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function deleteCollection(databaseId: string, collectionId: string): Promise { const clearMessage = logConsoleProgress(`Deleting container ${collectionId}`); @@ -31,18 +30,18 @@ function deleteCollectionWithARM(databaseId: string, collectionId: string): Prom const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": return deleteSqlContainer(subscriptionId, resourceGroup, accountName, databaseId, collectionId); - case DefaultAccountExperienceType.MongoDB: + case "Mongo": return deleteMongoDBCollection(subscriptionId, resourceGroup, accountName, databaseId, collectionId); - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": return deleteCassandraTable(subscriptionId, resourceGroup, accountName, databaseId, collectionId); - case DefaultAccountExperienceType.Graph: + case "Gremlin": return deleteGremlinGraph(subscriptionId, resourceGroup, accountName, databaseId, collectionId); - case DefaultAccountExperienceType.Table: + case "Tables": return deleteTable(subscriptionId, resourceGroup, accountName, collectionId); default: throw new Error(`Unsupported default experience type: ${defaultExperience}`); diff --git a/src/Common/dataAccess/deleteDatabase.test.ts b/src/Common/dataAccess/deleteDatabase.test.ts index dc78998bd..05d1ce5f3 100644 --- a/src/Common/dataAccess/deleteDatabase.test.ts +++ b/src/Common/dataAccess/deleteDatabase.test.ts @@ -1,13 +1,12 @@ jest.mock("../../Utils/arm/request"); jest.mock("../MessageHandler"); jest.mock("../CosmosClient"); -import { deleteDatabase } from "./deleteDatabase"; -import { armRequest } from "../../Utils/arm/request"; import { AuthType } from "../../AuthType"; -import { client } from "../CosmosClient"; -import { updateUserContext } from "../../UserContext"; import { DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; +import { armRequest } from "../../Utils/arm/request"; +import { client } from "../CosmosClient"; +import { deleteDatabase } from "./deleteDatabase"; describe("deleteDatabase", () => { beforeAll(() => { @@ -15,7 +14,7 @@ describe("deleteDatabase", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/deleteDatabase.ts b/src/Common/dataAccess/deleteDatabase.ts index 20a1119f3..f30084fc3 100644 --- a/src/Common/dataAccess/deleteDatabase.ts +++ b/src/Common/dataAccess/deleteDatabase.ts @@ -1,19 +1,18 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { deleteCassandraKeyspace } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { deleteMongoDBDatabase } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; -import { deleteGremlinDatabase } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { deleteCassandraKeyspace } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; +import { deleteGremlinDatabase } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { deleteMongoDBDatabase } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function deleteDatabase(databaseId: string): Promise { const clearMessage = logConsoleProgress(`Deleting database ${databaseId}`); try { - if (userContext.defaultExperience === DefaultAccountExperienceType.Table) { + if (userContext.apiType === "Tables") { throw new Error("Deleting database resources is not allowed for tables accounts"); } if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations) { @@ -34,16 +33,16 @@ function deleteDatabaseWithARM(databaseId: string): Promise { const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": return deleteSqlDatabase(subscriptionId, resourceGroup, accountName, databaseId); - case DefaultAccountExperienceType.MongoDB: + case "Mongo": return deleteMongoDBDatabase(subscriptionId, resourceGroup, accountName, databaseId); - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": return deleteCassandraKeyspace(subscriptionId, resourceGroup, accountName, databaseId); - case DefaultAccountExperienceType.Graph: + case "Gremlin": return deleteGremlinDatabase(subscriptionId, resourceGroup, accountName, databaseId); default: throw new Error(`Unsupported default experience type: ${defaultExperience}`); diff --git a/src/Common/dataAccess/deleteStoredProcedure.ts b/src/Common/dataAccess/deleteStoredProcedure.ts index acc6dfc4a..d1cd534ac 100644 --- a/src/Common/dataAccess/deleteStoredProcedure.ts +++ b/src/Common/dataAccess/deleteStoredProcedure.ts @@ -1,10 +1,9 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { client } from "../CosmosClient"; -import { deleteSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { deleteSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function deleteStoredProcedure( databaseId: string, @@ -13,11 +12,7 @@ export async function deleteStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Deleting stored procedure ${storedProcedureId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { await deleteSqlStoredProcedure( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/deleteTrigger.ts b/src/Common/dataAccess/deleteTrigger.ts index f36d44e23..3309bc2a9 100644 --- a/src/Common/dataAccess/deleteTrigger.ts +++ b/src/Common/dataAccess/deleteTrigger.ts @@ -1,19 +1,14 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { client } from "../CosmosClient"; -import { deleteSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { deleteSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function deleteTrigger(databaseId: string, collectionId: string, triggerId: string): Promise { const clearMessage = logConsoleProgress(`Deleting trigger ${triggerId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { await deleteSqlTrigger( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/deleteUserDefinedFunction.ts b/src/Common/dataAccess/deleteUserDefinedFunction.ts index b1e622a5a..b502c1a98 100644 --- a/src/Common/dataAccess/deleteUserDefinedFunction.ts +++ b/src/Common/dataAccess/deleteUserDefinedFunction.ts @@ -1,19 +1,14 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { client } from "../CosmosClient"; -import { deleteSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { userContext } from "../../UserContext"; +import { deleteSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function deleteUserDefinedFunction(databaseId: string, collectionId: string, id: string): Promise { const clearMessage = logConsoleProgress(`Deleting user defined function ${id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { await deleteSqlUserDefinedFunction( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readCollection.test.ts b/src/Common/dataAccess/readCollection.test.ts index 8b5060948..b6d6b1752 100644 --- a/src/Common/dataAccess/readCollection.test.ts +++ b/src/Common/dataAccess/readCollection.test.ts @@ -1,10 +1,9 @@ jest.mock("../CosmosClient"); import { AuthType } from "../../AuthType"; import { DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; import { client } from "../CosmosClient"; import { readCollection } from "./readCollection"; -import { updateUserContext } from "../../UserContext"; describe("readCollection", () => { beforeAll(() => { @@ -13,7 +12,7 @@ describe("readCollection", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/readCollectionOffer.ts b/src/Common/dataAccess/readCollectionOffer.ts index c56183622..b83d37cb7 100644 --- a/src/Common/dataAccess/readCollectionOffer.ts +++ b/src/Common/dataAccess/readCollectionOffer.ts @@ -1,25 +1,20 @@ import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Offer, ReadCollectionOfferParams } from "../../Contracts/DataModels"; -import { handleError } from "../ErrorHandlingUtils"; -import { getSqlContainerThroughput } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { getMongoDBCollectionThroughput } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { userContext } from "../../UserContext"; import { getCassandraTableThroughput } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { getGremlinGraphThroughput } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { getMongoDBCollectionThroughput } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { getSqlContainerThroughput } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { getTableThroughput } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { handleError } from "../ErrorHandlingUtils"; import { readOfferWithSDK } from "./readOfferWithSDK"; -import { userContext } from "../../UserContext"; export const readCollectionOffer = async (params: ReadCollectionOfferParams): Promise => { const clearMessage = logConsoleProgress(`Querying offer for collection ${params.collectionId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.Table - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType !== "Tables") { return await readCollectionOfferWithARM(params.databaseId, params.collectionId); } @@ -36,12 +31,12 @@ const readCollectionOfferWithARM = async (databaseId: string, collectionId: stri const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; let rpResponse; try { switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": rpResponse = await getSqlContainerThroughput( subscriptionId, resourceGroup, @@ -50,7 +45,7 @@ const readCollectionOfferWithARM = async (databaseId: string, collectionId: stri collectionId ); break; - case DefaultAccountExperienceType.MongoDB: + case "Mongo": rpResponse = await getMongoDBCollectionThroughput( subscriptionId, resourceGroup, @@ -59,7 +54,7 @@ const readCollectionOfferWithARM = async (databaseId: string, collectionId: stri collectionId ); break; - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": rpResponse = await getCassandraTableThroughput( subscriptionId, resourceGroup, @@ -68,7 +63,7 @@ const readCollectionOfferWithARM = async (databaseId: string, collectionId: stri collectionId ); break; - case DefaultAccountExperienceType.Graph: + case "Gremlin": rpResponse = await getGremlinGraphThroughput( subscriptionId, resourceGroup, @@ -77,7 +72,7 @@ const readCollectionOfferWithARM = async (databaseId: string, collectionId: stri collectionId ); break; - case DefaultAccountExperienceType.Table: + case "Tables": rpResponse = await getTableThroughput(subscriptionId, resourceGroup, accountName, collectionId); break; default: diff --git a/src/Common/dataAccess/readCollections.test.ts b/src/Common/dataAccess/readCollections.test.ts index 998591b48..50348b574 100644 --- a/src/Common/dataAccess/readCollections.test.ts +++ b/src/Common/dataAccess/readCollections.test.ts @@ -2,11 +2,10 @@ jest.mock("../../Utils/arm/request"); jest.mock("../CosmosClient"); import { AuthType } from "../../AuthType"; import { DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; import { armRequest } from "../../Utils/arm/request"; import { client } from "../CosmosClient"; import { readCollections } from "./readCollections"; -import { updateUserContext } from "../../UserContext"; describe("readCollections", () => { beforeAll(() => { @@ -14,7 +13,7 @@ describe("readCollections", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/readCollections.ts b/src/Common/dataAccess/readCollections.ts index 4d77a0597..f12b8074f 100644 --- a/src/Common/dataAccess/readCollections.ts +++ b/src/Common/dataAccess/readCollections.ts @@ -1,6 +1,5 @@ import { AuthType } from "../../AuthType"; import * as DataModels from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { userContext } from "../../UserContext"; import { listCassandraTables } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { listGremlinGraphs } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; @@ -14,11 +13,7 @@ import { handleError } from "../ErrorHandlingUtils"; export async function readCollections(databaseId: string): Promise { const clearMessage = logConsoleProgress(`Querying containers for database ${databaseId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.Table - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType !== "Tables") { return await readCollectionsWithARM(databaseId); } @@ -37,22 +32,22 @@ async function readCollectionsWithARM(databaseId: string): Promise => { const clearMessage = logConsoleProgress(`Querying offer for database ${params.databaseId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.Table - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType !== "Tables") { return await readDatabaseOfferWithARM(params.databaseId); } @@ -35,21 +30,21 @@ const readDatabaseOfferWithARM = async (databaseId: string): Promise => { const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; let rpResponse; try { switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": rpResponse = await getSqlDatabaseThroughput(subscriptionId, resourceGroup, accountName, databaseId); break; - case DefaultAccountExperienceType.MongoDB: + case "Mongo": rpResponse = await getMongoDBDatabaseThroughput(subscriptionId, resourceGroup, accountName, databaseId); break; - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": rpResponse = await getCassandraKeyspaceThroughput(subscriptionId, resourceGroup, accountName, databaseId); break; - case DefaultAccountExperienceType.Graph: + case "Gremlin": rpResponse = await getGremlinDatabaseThroughput(subscriptionId, resourceGroup, accountName, databaseId); break; default: diff --git a/src/Common/dataAccess/readDatabases.test.ts b/src/Common/dataAccess/readDatabases.test.ts index 4315d0a1c..8f6368f78 100644 --- a/src/Common/dataAccess/readDatabases.test.ts +++ b/src/Common/dataAccess/readDatabases.test.ts @@ -2,11 +2,10 @@ jest.mock("../../Utils/arm/request"); jest.mock("../CosmosClient"); import { AuthType } from "../../AuthType"; import { DatabaseAccount } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { updateUserContext } from "../../UserContext"; import { armRequest } from "../../Utils/arm/request"; import { client } from "../CosmosClient"; import { readDatabases } from "./readDatabases"; -import { updateUserContext } from "../../UserContext"; describe("readDatabases", () => { beforeAll(() => { @@ -14,7 +13,7 @@ describe("readDatabases", () => { databaseAccount: { name: "test", } as DatabaseAccount, - defaultExperience: DefaultAccountExperienceType.DocumentDB, + apiType: "SQL", }); }); diff --git a/src/Common/dataAccess/readDatabases.ts b/src/Common/dataAccess/readDatabases.ts index ddcc72c93..1026c0654 100644 --- a/src/Common/dataAccess/readDatabases.ts +++ b/src/Common/dataAccess/readDatabases.ts @@ -1,24 +1,19 @@ -import * as DataModels from "../../Contracts/DataModels"; import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import * as DataModels from "../../Contracts/DataModels"; +import { userContext } from "../../UserContext"; +import { listCassandraKeyspaces } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; +import { listGremlinDatabases } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { listMongoDBDatabases } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { listSqlDatabases } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; -import { listSqlDatabases } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { listCassandraKeyspaces } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { listMongoDBDatabases } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; -import { listGremlinDatabases } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; export async function readDatabases(): Promise { let databases: DataModels.Database[]; const clearMessage = logConsoleProgress(`Querying databases`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.Table - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType !== "Tables") { databases = await readDatabasesWithARM(); } else { const sdkResponse = await client().databases.readAll().fetchAll(); @@ -37,19 +32,19 @@ async function readDatabasesWithARM(): Promise { const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": rpResponse = await listSqlDatabases(subscriptionId, resourceGroup, accountName); break; - case DefaultAccountExperienceType.MongoDB: + case "Mongo": rpResponse = await listMongoDBDatabases(subscriptionId, resourceGroup, accountName); break; - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": rpResponse = await listCassandraKeyspaces(subscriptionId, resourceGroup, accountName); break; - case DefaultAccountExperienceType.Graph: + case "Gremlin": rpResponse = await listGremlinDatabases(subscriptionId, resourceGroup, accountName); break; default: diff --git a/src/Common/dataAccess/readStoredProcedures.ts b/src/Common/dataAccess/readStoredProcedures.ts index 78a5bcee6..b7955ffd7 100644 --- a/src/Common/dataAccess/readStoredProcedures.ts +++ b/src/Common/dataAccess/readStoredProcedures.ts @@ -1,11 +1,10 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; -import { client } from "../CosmosClient"; -import { handleError } from "../ErrorHandlingUtils"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { listSqlStoredProcedures } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function readStoredProcedures( databaseId: string, @@ -13,11 +12,7 @@ export async function readStoredProcedures( ): Promise<(StoredProcedureDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying stored procedures for container ${collectionId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const rpResponse = await listSqlStoredProcedures( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readTriggers.ts b/src/Common/dataAccess/readTriggers.ts index fa97f98d6..7f87d3ae9 100644 --- a/src/Common/dataAccess/readTriggers.ts +++ b/src/Common/dataAccess/readTriggers.ts @@ -1,10 +1,9 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, TriggerDefinition } from "@azure/cosmos"; -import { client } from "../CosmosClient"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { listSqlTriggers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; export async function readTriggers( @@ -13,11 +12,7 @@ export async function readTriggers( ): Promise<(TriggerDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying triggers for container ${collectionId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const rpResponse = await listSqlTriggers( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readUserDefinedFunctions.ts b/src/Common/dataAccess/readUserDefinedFunctions.ts index 7d59bec6f..f1a0f52c5 100644 --- a/src/Common/dataAccess/readUserDefinedFunctions.ts +++ b/src/Common/dataAccess/readUserDefinedFunctions.ts @@ -1,11 +1,10 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; -import { client } from "../CosmosClient"; -import { handleError } from "../ErrorHandlingUtils"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { listSqlUserDefinedFunctions } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function readUserDefinedFunctions( databaseId: string, @@ -13,11 +12,7 @@ export async function readUserDefinedFunctions( ): Promise<(UserDefinedFunctionDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying user defined functions for container ${collectionId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const rpResponse = await listSqlUserDefinedFunctions( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateCollection.ts b/src/Common/dataAccess/updateCollection.ts index 7deb06902..f3b9d5002 100644 --- a/src/Common/dataAccess/updateCollection.ts +++ b/src/Common/dataAccess/updateCollection.ts @@ -2,7 +2,6 @@ import { ContainerDefinition } from "@azure/cosmos"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import { AuthType } from "../../AuthType"; import { Collection } from "../../Contracts/DataModels"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { userContext } from "../../UserContext"; import { createUpdateCassandraTable, @@ -38,11 +37,7 @@ export async function updateCollection( const clearMessage = logConsoleProgress(`Updating container ${collectionId}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.Table - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType !== "Tables") { collection = await updateCollectionWithARM(databaseId, collectionId, newCollection); } else { const sdkResponse = await client() @@ -71,18 +66,18 @@ async function updateCollectionWithARM( const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; const accountName = userContext.databaseAccount.name; - const defaultExperience = userContext.defaultExperience; + const defaultExperience = userContext.apiType; switch (defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + case "SQL": return updateSqlContainer(databaseId, collectionId, subscriptionId, resourceGroup, accountName, newCollection); - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": return updateCassandraTable(databaseId, collectionId, subscriptionId, resourceGroup, accountName, newCollection); - case DefaultAccountExperienceType.Graph: + case "Gremlin": return updateGremlinGraph(databaseId, collectionId, subscriptionId, resourceGroup, accountName, newCollection); - case DefaultAccountExperienceType.Table: + case "Tables": return updateTable(collectionId, subscriptionId, resourceGroup, accountName, newCollection); - case DefaultAccountExperienceType.MongoDB: + case "Mongo": return updateMongoDBCollection( databaseId, collectionId, diff --git a/src/Common/dataAccess/updateOffer.ts b/src/Common/dataAccess/updateOffer.ts index 00a6864e9..0050f3648 100644 --- a/src/Common/dataAccess/updateOffer.ts +++ b/src/Common/dataAccess/updateOffer.ts @@ -1,54 +1,53 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { HttpHeaders } from "../Constants"; -import { Offer, SDKOfferDefinition, UpdateOfferParams } from "../../Contracts/DataModels"; import { OfferDefinition } from "@azure/cosmos"; import { RequestOptions } from "@azure/cosmos/dist-esm"; -import { ThroughputSettingsUpdateParameters } from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; -import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { parseSDKOfferResponse } from "../OfferUtility"; -import { readCollectionOffer } from "./readCollectionOffer"; -import { readDatabaseOffer } from "./readDatabaseOffer"; +import { AuthType } from "../../AuthType"; +import { Offer, SDKOfferDefinition, UpdateOfferParams } from "../../Contracts/DataModels"; +import { userContext } from "../../UserContext"; import { - updateSqlDatabaseThroughput, - migrateSqlDatabaseToAutoscale, - migrateSqlDatabaseToManualThroughput, - migrateSqlContainerToAutoscale, - migrateSqlContainerToManualThroughput, - updateSqlContainerThroughput, -} from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { - updateCassandraKeyspaceThroughput, migrateCassandraKeyspaceToAutoscale, migrateCassandraKeyspaceToManualThroughput, migrateCassandraTableToAutoscale, migrateCassandraTableToManualThroughput, + updateCassandraKeyspaceThroughput, updateCassandraTableThroughput, } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; import { - updateMongoDBDatabaseThroughput, - migrateMongoDBDatabaseToAutoscale, - migrateMongoDBDatabaseToManualThroughput, - migrateMongoDBCollectionToAutoscale, - migrateMongoDBCollectionToManualThroughput, - updateMongoDBCollectionThroughput, -} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; -import { - updateGremlinDatabaseThroughput, migrateGremlinDatabaseToAutoscale, migrateGremlinDatabaseToManualThroughput, migrateGremlinGraphToAutoscale, migrateGremlinGraphToManualThroughput, + updateGremlinDatabaseThroughput, updateGremlinGraphThroughput, } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; -import { userContext } from "../../UserContext"; +import { + migrateMongoDBCollectionToAutoscale, + migrateMongoDBCollectionToManualThroughput, + migrateMongoDBDatabaseToAutoscale, + migrateMongoDBDatabaseToManualThroughput, + updateMongoDBCollectionThroughput, + updateMongoDBDatabaseThroughput, +} from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { + migrateSqlContainerToAutoscale, + migrateSqlContainerToManualThroughput, + migrateSqlDatabaseToAutoscale, + migrateSqlDatabaseToManualThroughput, + updateSqlContainerThroughput, + updateSqlDatabaseThroughput, +} from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { migrateTableToAutoscale, migrateTableToManualThroughput, updateTableThroughput, } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; +import { ThroughputSettingsUpdateParameters } from "../../Utils/arm/generatedClients/2020-04-01/types"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; +import { HttpHeaders } from "../Constants"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; +import { parseSDKOfferResponse } from "../OfferUtility"; +import { readCollectionOffer } from "./readCollectionOffer"; +import { readDatabaseOffer } from "./readDatabaseOffer"; export const updateOffer = async (params: UpdateOfferParams): Promise => { let updatedOffer: Offer; @@ -61,7 +60,7 @@ export const updateOffer = async (params: UpdateOfferParams): Promise => if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations) { if (params.collectionId) { updatedOffer = await updateCollectionOfferWithARM(params); - } else if (userContext.defaultExperience === DefaultAccountExperienceType.Table) { + } else if (userContext.apiType === "Tables") { // update table's database offer with SDK since RP doesn't support it updatedOffer = await updateOfferWithSDK(params); } else { @@ -82,24 +81,24 @@ export const updateOffer = async (params: UpdateOfferParams): Promise => const updateCollectionOfferWithARM = async (params: UpdateOfferParams): Promise => { try { - switch (userContext.defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + switch (userContext.apiType) { + case "SQL": await updateSqlContainerOffer(params); break; - case DefaultAccountExperienceType.MongoDB: + case "Mongo": await updateMongoCollectionOffer(params); break; - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": await updateCassandraTableOffer(params); break; - case DefaultAccountExperienceType.Graph: + case "Gremlin": await updateGremlinGraphOffer(params); break; - case DefaultAccountExperienceType.Table: + case "Tables": await updateTableOffer(params); break; default: - throw new Error(`Unsupported default experience type: ${userContext.defaultExperience}`); + throw new Error(`Unsupported default experience type: ${userContext.apiType}`); } } catch (error) { if (error.code !== "MethodNotAllowed") { @@ -116,21 +115,21 @@ const updateCollectionOfferWithARM = async (params: UpdateOfferParams): Promise< const updateDatabaseOfferWithARM = async (params: UpdateOfferParams): Promise => { try { - switch (userContext.defaultExperience) { - case DefaultAccountExperienceType.DocumentDB: + switch (userContext.apiType) { + case "SQL": await updateSqlDatabaseOffer(params); break; - case DefaultAccountExperienceType.MongoDB: + case "Mongo": await updateMongoDatabaseOffer(params); break; - case DefaultAccountExperienceType.Cassandra: + case "Cassandra": await updateCassandraKeyspaceOffer(params); break; - case DefaultAccountExperienceType.Graph: + case "Gremlin": await updateGremlinDatabaseOffer(params); break; default: - throw new Error(`Unsupported default experience type: ${userContext.defaultExperience}`); + throw new Error(`Unsupported default experience type: ${userContext.apiType}`); } } catch (error) { if (error.code !== "MethodNotAllowed") { diff --git a/src/Common/dataAccess/updateStoredProcedure.ts b/src/Common/dataAccess/updateStoredProcedure.ts index de49ef82a..9889ac519 100644 --- a/src/Common/dataAccess/updateStoredProcedure.ts +++ b/src/Common/dataAccess/updateStoredProcedure.ts @@ -1,18 +1,17 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; -import { - SqlStoredProcedureCreateUpdateParameters, - SqlStoredProcedureResource, -} from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { createUpdateSqlStoredProcedure, getSqlStoredProcedure, } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; +import { + SqlStoredProcedureCreateUpdateParameters, + SqlStoredProcedureResource, +} from "../../Utils/arm/generatedClients/2020-04-01/types"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function updateStoredProcedure( databaseId: string, @@ -21,11 +20,7 @@ export async function updateStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Updating stored procedure ${storedProcedure.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const getResponse = await getSqlStoredProcedure( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateTrigger.ts b/src/Common/dataAccess/updateTrigger.ts index 3a3040695..f4898052b 100644 --- a/src/Common/dataAccess/updateTrigger.ts +++ b/src/Common/dataAccess/updateTrigger.ts @@ -1,15 +1,14 @@ +import { TriggerDefinition } from "@azure/cosmos"; import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; +import { userContext } from "../../UserContext"; +import { createUpdateSqlTrigger, getSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { SqlTriggerCreateUpdateParameters, SqlTriggerResource, } from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { TriggerDefinition } from "@azure/cosmos"; -import { client } from "../CosmosClient"; -import { createUpdateSqlTrigger, getSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function updateTrigger( databaseId: string, @@ -18,11 +17,7 @@ export async function updateTrigger( ): Promise { const clearMessage = logConsoleProgress(`Updating trigger ${trigger.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const getResponse = await getSqlTrigger( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateUserDefinedFunction.ts b/src/Common/dataAccess/updateUserDefinedFunction.ts index 59e01c970..1d50951d6 100644 --- a/src/Common/dataAccess/updateUserDefinedFunction.ts +++ b/src/Common/dataAccess/updateUserDefinedFunction.ts @@ -1,18 +1,17 @@ -import { AuthType } from "../../AuthType"; -import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; -import { - SqlUserDefinedFunctionCreateUpdateParameters, - SqlUserDefinedFunctionResource, -} from "../../Utils/arm/generatedClients/2020-04-01/types"; -import { client } from "../CosmosClient"; +import { AuthType } from "../../AuthType"; +import { userContext } from "../../UserContext"; import { createUpdateSqlUserDefinedFunction, getSqlUserDefinedFunction, } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; -import { handleError } from "../ErrorHandlingUtils"; +import { + SqlUserDefinedFunctionCreateUpdateParameters, + SqlUserDefinedFunctionResource, +} from "../../Utils/arm/generatedClients/2020-04-01/types"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function updateUserDefinedFunction( databaseId: string, @@ -21,11 +20,7 @@ export async function updateUserDefinedFunction( ): Promise { const clearMessage = logConsoleProgress(`Updating user defined function ${userDefinedFunction.id}`); try { - if ( - userContext.authType === AuthType.AAD && - !userContext.useSDKOperations && - userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB - ) { + if (userContext.authType === AuthType.AAD && !userContext.useSDKOperations && userContext.apiType === "SQL") { const getResponse = await getSqlUserDefinedFunction( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/DefaultAccountExperienceType.ts b/src/DefaultAccountExperienceType.ts deleted file mode 100644 index 19a5d0f13..000000000 --- a/src/DefaultAccountExperienceType.ts +++ /dev/null @@ -1,8 +0,0 @@ -export enum DefaultAccountExperienceType { - DocumentDB = "DocumentDB", - Graph = "Graph", - MongoDB = "MongoDB", - Table = "Table", - Cassandra = "Cassandra", - ApiForMongoDB = "Azure Cosmos DB for MongoDB API", -} diff --git a/src/Explorer/ContextMenuButtonFactory.ts b/src/Explorer/ContextMenuButtonFactory.ts index db950ad46..6973c5326 100644 --- a/src/Explorer/ContextMenuButtonFactory.ts +++ b/src/Explorer/ContextMenuButtonFactory.ts @@ -10,7 +10,6 @@ import DeleteTriggerIcon from "../../images/DeleteTrigger.svg"; import DeleteUDFIcon from "../../images/DeleteUDF.svg"; import HostedTerminalIcon from "../../images/Hosted-Terminal.svg"; import * as ViewModels from "../Contracts/ViewModels"; -import { DefaultAccountExperienceType } from "../DefaultAccountExperienceType"; import { userContext } from "../UserContext"; import { TreeNodeMenuItem } from "./Controls/TreeComponent/TreeComponent"; import Explorer from "./Explorer"; @@ -39,7 +38,7 @@ export class ResourceTreeContextMenuButtonFactory { }, ]; - if (userContext.defaultExperience !== DefaultAccountExperienceType.Table) { + if (userContext.apiType !== "Tables") { items.push({ iconSrc: DeleteDatabaseIcon, onClick: () => container.openDeleteDatabaseConfirmationPane(), diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 875c275db..3a090fd7e 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -25,12 +25,11 @@ import { ResourceProviderClientFactory } from "../ResourceProvider/ResourceProvi import { RouteHandler } from "../RouteHandlers/RouteHandler"; import { trackEvent } from "../Shared/appInsights"; import * as SharedConstants from "../Shared/Constants"; -import { DefaultExperienceUtility } from "../Shared/DefaultExperienceUtility"; import { ExplorerSettings } from "../Shared/ExplorerSettings"; import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor"; import { ArcadiaResourceManager } from "../SparkClusterManager/ArcadiaResourceManager"; -import { updateUserContext, userContext } from "../UserContext"; +import { userContext } from "../UserContext"; import { decryptJWTToken, getAuthorizationHeader } from "../Utils/AuthorizationUtils"; import { stringToBlob } from "../Utils/BlobUtils"; import { fromContentUri, toRawContentUri } from "../Utils/GitHubUtils"; @@ -373,16 +372,16 @@ export default class Explorer { direction: SplitterDirection.Vertical, }); this.defaultExperience = ko.observable(); - this.databaseAccount.subscribe((databaseAccount) => { - const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount( - databaseAccount - ); - this.defaultExperience(defaultExperience); - // TODO. Remove this entirely - updateUserContext({ - defaultExperience: DefaultExperienceUtility.mapDefaultExperienceStringToEnum(defaultExperience), - }); - }); + // this.databaseAccount.subscribe((databaseAccount) => { + // const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount( + // databaseAccount + // ); + // this.defaultExperience(defaultExperience); + // // TODO. Remove this entirely + // updateUserContext({ + // apiType: DefaultExperienceUtility.mapDefaultExperienceStringToEnum(defaultExperience), + // }); + // }); this.isFixedCollectionWithSharedThroughputSupported = ko.computed(() => { if (userContext.features.enableFixedCollectionWithSharedThroughput) { @@ -2062,7 +2061,7 @@ export default class Explorer { } public openDeleteCollectionConfirmationPane(): void { - let collectionName = PricingUtils.getCollectionName(userContext.defaultExperience); + let collectionName = PricingUtils.getCollectionName(userContext.apiType); this.openSidePanel( "Delete " + collectionName, -