mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-02 16:09:13 +01:00
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
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";
|
|
|
|
export async function deleteUserDefinedFunction(databaseId: string, collectionId: string, id: string): Promise<void> {
|
|
const clearMessage = logConsoleProgress(`Deleting user defined function ${id}`);
|
|
try {
|
|
if (
|
|
userContext.authType === AuthType.AAD &&
|
|
!userContext.useSDKOperations &&
|
|
userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB
|
|
) {
|
|
await deleteSqlUserDefinedFunction(
|
|
userContext.subscriptionId,
|
|
userContext.resourceGroup,
|
|
userContext.databaseAccount.name,
|
|
databaseId,
|
|
collectionId,
|
|
id
|
|
);
|
|
} else {
|
|
await client().database(databaseId).container(collectionId).scripts.userDefinedFunction(id).delete();
|
|
}
|
|
} catch (error) {
|
|
handleError(error, "DeleteUserDefinedFunction", `Error while deleting user defined function ${id}`);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
}
|