mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 10:51:30 +00:00
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos";
|
|
import { AuthType } from "../../AuthType";
|
|
import { userContext } from "../../UserContext";
|
|
import { listSqlUserDefinedFunctions } from "../../Utils/arm/generatedClients/cosmos/sqlResources";
|
|
import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
|
import { client } from "../CosmosClient";
|
|
import { handleError } from "../ErrorHandlingUtils";
|
|
|
|
export async function readUserDefinedFunctions(
|
|
databaseId: string,
|
|
collectionId: string
|
|
): Promise<(UserDefinedFunctionDefinition & Resource)[]> {
|
|
const clearMessage = logConsoleProgress(`Querying user defined functions for container ${collectionId}`);
|
|
const { authType, useSDKOperations, apiType, subscriptionId, resourceGroup, databaseAccount } = userContext;
|
|
try {
|
|
if (authType === AuthType.AAD && !useSDKOperations && apiType === "SQL") {
|
|
const rpResponse = await listSqlUserDefinedFunctions(
|
|
subscriptionId,
|
|
resourceGroup,
|
|
databaseAccount.name,
|
|
databaseId,
|
|
collectionId
|
|
);
|
|
return rpResponse?.value?.map((udf) => udf.properties?.resource as UserDefinedFunctionDefinition & Resource);
|
|
}
|
|
|
|
const response = await client()
|
|
.database(databaseId)
|
|
.container(collectionId)
|
|
.scripts.userDefinedFunctions.readAll()
|
|
.fetchAll();
|
|
return response?.resources;
|
|
} catch (error) {
|
|
handleError(
|
|
error,
|
|
"ReadUserDefinedFunctions",
|
|
`Failed to query user defined functions for container ${collectionId}`
|
|
);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
}
|