From ad115a2cce503150a556edc7d4ad72ece8ccbfc0 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Thu, 23 Jul 2020 19:02:09 -0500 Subject: [PATCH] Functional version --- src/Utils/arm/CassandraResources.ts | 252 +++++---- src/Utils/arm/Collection.ts | 63 +-- src/Utils/arm/CollectionPartition.ts | 45 +- src/Utils/arm/CollectionPartitionRegion.ts | 29 +- src/Utils/arm/CollectionRegion.ts | 29 +- src/Utils/arm/Database.ts | 59 ++- src/Utils/arm/DatabaseAccountRegion.ts | 25 +- src/Utils/arm/DatabaseAccounts.ts | 375 +++++++------- src/Utils/arm/GremlinResources.ts | 252 +++++---- src/Utils/arm/MongoDBResources.ts | 252 +++++---- src/Utils/arm/Operations.ts | 13 +- src/Utils/arm/PartitionKeyRangeId.ts | 29 +- src/Utils/arm/PartitionKeyRangeIdRegion.ts | 31 +- src/Utils/arm/Percentile.ts | 23 +- src/Utils/arm/PercentileSourceTarget.ts | 27 +- src/Utils/arm/PercentileTarget.ts | 25 +- src/Utils/arm/RestorableDatabaseAccounts.ts | 53 +- src/Utils/arm/SqlResources.ts | 533 +++++++++++--------- src/Utils/arm/TableResources.ts | 124 +++-- utils/armClientGenerator/generator.ts | 45 +- 20 files changed, 1204 insertions(+), 1080 deletions(-) diff --git a/src/Utils/arm/CassandraResources.ts b/src/Utils/arm/CassandraResources.ts index 3c7d3953d..c8ee9b82d 100644 --- a/src/Utils/arm/CassandraResources.ts +++ b/src/Utils/arm/CassandraResources.ts @@ -6,110 +6,150 @@ import * as Types from "./types"; -export class CassandraResourcesClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/cassandraKeyspaces`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Lists the Cassandra keyspaces under an existing Azure Cosmos DB database account. */ - async listCassandraKeyspaces(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the Cassandra keyspaces under an existing Azure Cosmos DB database account with the provided name. */ - async getCassandraKeyspace(keyspaceName: string): Promise { - const path = `/${keyspaceName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB Cassandra keyspace */ - async createUpdateCassandraKeyspace( - keyspaceName: string, - body: Types.CassandraKeyspaceCreateUpdateParameters - ): Promise { - const path = `/${keyspaceName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB Cassandra keyspace. */ - async deleteCassandraKeyspace(keyspaceName: string): Promise { - const path = `/${keyspaceName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the Cassandra table under an existing Azure Cosmos DB database account. */ - async listCassandraTables(keyspaceName: string): Promise { - const path = `/${keyspaceName}/tables`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the Cassandra table under an existing Azure Cosmos DB database account. */ - async getCassandraTable(keyspaceName: string, tableName: string): Promise { - const path = `/${keyspaceName}/tables/${tableName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB Cassandra Table */ - async createUpdateCassandraTable( - keyspaceName: string, - tableName: string, - body: Types.CassandraTableCreateUpdateParameters - ): Promise { - const path = `/${keyspaceName}/tables/${tableName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB Cassandra table. */ - async deleteCassandraTable(keyspaceName: string, tableName: string): Promise { - const path = `/${keyspaceName}/tables/${tableName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the RUs per second of the Cassandra table under an existing Azure Cosmos DB database account with the provided name. */ - async getCassandraTableThroughput( - keyspaceName: string, - tableName: string - ): Promise { - const path = `/${keyspaceName}/tables/${tableName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB Cassandra table */ - async updateCassandraTableThroughput( - keyspaceName: string, - tableName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${keyspaceName}/tables/${tableName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Gets the RUs per second of the Cassandra Keyspace under an existing Azure Cosmos DB database account with the provided name. */ - async getCassandraKeyspaceThroughput(keyspaceName: string): Promise { - const path = `/${keyspaceName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB Cassandra Keyspace */ - async updateCassandraKeyspaceThroughput( - keyspaceName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${keyspaceName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } +/* Lists the Cassandra keyspaces under an existing Azure Cosmos DB database account. */ +export async function listCassandraKeyspaces( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the Cassandra keyspaces under an existing Azure Cosmos DB database account with the provided name. */ +export async function getCassandraKeyspace( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB Cassandra keyspace */ +export async function createUpdateCassandraKeyspace( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + body: Types.CassandraKeyspaceCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB Cassandra keyspace. */ +export async function deleteCassandraKeyspace( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the Cassandra Keyspace under an existing Azure Cosmos DB database account with the provided name. */ +export async function getCassandraKeyspaceThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB Cassandra Keyspace */ +export async function updateCassandraKeyspaceThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the Cassandra table under an existing Azure Cosmos DB database account. */ +export async function listCassandraTables( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the Cassandra table under an existing Azure Cosmos DB database account. */ +export async function getCassandraTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables/${tableName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB Cassandra Table */ +export async function createUpdateCassandraTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + tableName: string, + body: Types.CassandraTableCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables/${tableName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB Cassandra table. */ +export async function deleteCassandraTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables/${tableName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the Cassandra table under an existing Azure Cosmos DB database account with the provided name. */ +export async function getCassandraTableThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables/${tableName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB Cassandra table */ +export async function updateCassandraTableThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + keyspaceName: string, + tableName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/cassandraKeyspaces/${keyspaceName}/tables/${tableName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); } diff --git a/src/Utils/arm/Collection.ts b/src/Utils/arm/Collection.ts index fd577d48d..66010931e 100644 --- a/src/Utils/arm/Collection.ts +++ b/src/Utils/arm/Collection.ts @@ -6,33 +6,38 @@ import * as Types from "./types"; -export class CollectionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/databases/${this.databaseRid}/collections/${this.collectionRid}/`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly databaseRid: string, - private readonly collectionRid: string - ) {} - - /* Retrieves metric definitions for the given collection. */ - async listMetricDefinitions(): Promise { - const path = `metricDefinitions`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the metrics determined by the given filter for the given database account and collection. */ - async listMetrics(): Promise { - const path = `metrics`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the usages (most recent storage data) for the given collection. */ - async listUsages(): Promise { - const path = `usages`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given database account and collection. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves the usages (most recent storage data) for the given collection. */ +export async function listUsages( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/usages`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves metric definitions for the given collection. */ +export async function listMetricDefinitions( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/metricDefinitions`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/CollectionPartition.ts b/src/Utils/arm/CollectionPartition.ts index 50c3bed35..e0890b91a 100644 --- a/src/Utils/arm/CollectionPartition.ts +++ b/src/Utils/arm/CollectionPartition.ts @@ -6,27 +6,26 @@ import * as Types from "./types"; -export class CollectionPartitionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/databases/${this.databaseRid}/collections/${this.collectionRid}/partitions/`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly databaseRid: string, - private readonly collectionRid: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given collection, split by partition. */ - async listMetrics(): Promise { - const path = `metrics`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the usages (most recent storage data) for the given collection, split by partition. */ - async listUsages(): Promise { - const path = `usages`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given collection, split by partition. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/partitions/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves the usages (most recent storage data) for the given collection, split by partition. */ +export async function listUsages( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/partitions/usages`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/CollectionPartitionRegion.ts b/src/Utils/arm/CollectionPartitionRegion.ts index 4eb9ddd9c..de1dc9947 100644 --- a/src/Utils/arm/CollectionPartitionRegion.ts +++ b/src/Utils/arm/CollectionPartitionRegion.ts @@ -6,22 +6,15 @@ import * as Types from "./types"; -export class CollectionPartitionRegionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/region/${this.region}/databases/${this.databaseRid}/collections/${this.collectionRid}/partitions/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly region: string, - private readonly databaseRid: string, - private readonly collectionRid: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given collection and region, split by partition. */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given collection and region, split by partition. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + region: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/region/${region}/databases/${databaseRid}/collections/${collectionRid}/partitions/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/CollectionRegion.ts b/src/Utils/arm/CollectionRegion.ts index 4fb24a242..d7e38be33 100644 --- a/src/Utils/arm/CollectionRegion.ts +++ b/src/Utils/arm/CollectionRegion.ts @@ -6,22 +6,15 @@ import * as Types from "./types"; -export class CollectionRegionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/region/${this.region}/databases/${this.databaseRid}/collections/${this.collectionRid}/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly region: string, - private readonly databaseRid: string, - private readonly collectionRid: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given database account, collection and region. */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given database account, collection and region. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + region: string, + databaseRid: string, + collectionRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/region/${region}/databases/${databaseRid}/collections/${collectionRid}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/Database.ts b/src/Utils/arm/Database.ts index afe0a74c9..0f072e56b 100644 --- a/src/Utils/arm/Database.ts +++ b/src/Utils/arm/Database.ts @@ -6,32 +6,35 @@ import * as Types from "./types"; -export class DatabaseClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/databases/${this.databaseRid}/`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly databaseRid: string - ) {} - - /* Retrieves metric definitions for the given database. */ - async listMetricDefinitions(): Promise { - const path = `metricDefinitions`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the metrics determined by the given filter for the given database account and database. */ - async listMetrics(): Promise { - const path = `metrics`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the usages (most recent data) for the given database. */ - async listUsages(): Promise { - const path = `usages`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given database account and database. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves the usages (most recent data) for the given database. */ +export async function listUsages( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/usages`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves metric definitions for the given database. */ +export async function listMetricDefinitions( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/metricDefinitions`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/DatabaseAccountRegion.ts b/src/Utils/arm/DatabaseAccountRegion.ts index ae9a86cc7..a4eb72ad6 100644 --- a/src/Utils/arm/DatabaseAccountRegion.ts +++ b/src/Utils/arm/DatabaseAccountRegion.ts @@ -6,20 +6,13 @@ import * as Types from "./types"; -export class DatabaseAccountRegionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/region/${this.region}/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly region: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given database account and region. */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given database account and region. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + region: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/region/${region}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/DatabaseAccounts.ts b/src/Utils/arm/DatabaseAccounts.ts index 7c39a376b..d3d5eb2e9 100644 --- a/src/Utils/arm/DatabaseAccounts.ts +++ b/src/Utils/arm/DatabaseAccounts.ts @@ -6,192 +6,191 @@ import * as Types from "./types"; -export class DatabaseAccountsClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/`; - - /* Checks that the Azure Cosmos DB account name already exists. A valid account name may contain only lowercase letters, numbers, and the '-' character, and must be between 3 and 50 characters. */ - async checkNameExists(accountName: string): Promise { - const path = `providers/Microsoft.DocumentDB/databaseAccountNames/${accountName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "head" }).then(response => response.json()); - } - - /* Lists all the Azure Cosmos DB database accounts available under the subscription. */ - async list(subscriptionId: string): Promise { - const path = `subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/databaseAccounts`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Lists all the Azure Cosmos DB database accounts available under the given resource group. */ - async listByResourceGroup( - subscriptionId: string, - resourceGroupName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the properties of an existing Azure Cosmos DB database account. */ - async get( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Updates the properties of an existing Azure Cosmos DB database account. */ - async update( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.DatabaseAccountUpdateParameters - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "patch", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Creates or updates an Azure Cosmos DB database account. The "Update" method is preferred when performing updates on an account. */ - async createOrUpdate( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.DatabaseAccountCreateUpdateParameters - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB database account. */ - async destroy(subscriptionId: string, resourceGroupName: string, accountName: string): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Changes the failover priority for the Azure Cosmos DB database account. A failover priority of 0 indicates a write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values must be unique for each of the regions in which the database account exists. */ - async failoverPriorityChange( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.FailoverPolicies - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/failoverPriorityChange`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Lists the connection strings for the specified Azure Cosmos DB database account. */ - async listConnectionStrings( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/listConnectionStrings`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); - } - - /* Lists the access keys for the specified Azure Cosmos DB database account. */ - async listKeys( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/listKeys`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); - } - - /* Retrieves metric definitions for the given database account. */ - async listMetricDefinitions( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/metricDefinitions`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the metrics determined by the given filter for the given database account. */ - async listMetrics( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/metrics`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Offline the specified region for the specified Azure Cosmos DB database account. */ - async offlineRegion( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.RegionForOnlineOffline - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/offlineRegion`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Online the specified region for the specified Azure Cosmos DB database account. */ - async onlineRegion( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.RegionForOnlineOffline - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/onlineRegion`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Lists the read-only access keys for the specified Azure Cosmos DB database account. */ - async getReadOnlyKeys( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/readonlykeys`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Lists the read-only access keys for the specified Azure Cosmos DB database account. */ - async listReadOnlyKeys( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/readonlykeys`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); - } - - /* Regenerates an access key for the specified Azure Cosmos DB database account. */ - async regenerateKey( - subscriptionId: string, - resourceGroupName: string, - accountName: string, - body: Types.DatabaseAccountRegenerateKeyParameters - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/regenerateKey`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Retrieves the usages (most recent data) for the given database account. */ - async listUsages( - subscriptionId: string, - resourceGroupName: string, - accountName: string - ): Promise { - const path = `subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/usages`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the properties of an existing Azure Cosmos DB database account. */ +export async function get( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Updates the properties of an existing Azure Cosmos DB database account. */ +export async function update( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.DatabaseAccountUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "patch", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Creates or updates an Azure Cosmos DB database account. The "Update" method is preferred when performing updates on an account. */ +export async function createOrUpdate( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.DatabaseAccountCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB database account. */ +export async function destroy( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Changes the failover priority for the Azure Cosmos DB database account. A failover priority of 0 indicates a write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values must be unique for each of the regions in which the database account exists. */ +export async function failoverPriorityChange( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.FailoverPolicies +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/failoverPriorityChange`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists all the Azure Cosmos DB database accounts available under the subscription. */ +export async function list(subscriptionId: string): Promise { + const path = `/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/databaseAccounts`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Lists all the Azure Cosmos DB database accounts available under the given resource group. */ +export async function listByResourceGroup( + subscriptionId: string, + resourceGroupName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Lists the access keys for the specified Azure Cosmos DB database account. */ +export async function listKeys( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/listKeys`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); +} + +/* Lists the connection strings for the specified Azure Cosmos DB database account. */ +export async function listConnectionStrings( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/listConnectionStrings`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); +} + +/* Offline the specified region for the specified Azure Cosmos DB database account. */ +export async function offlineRegion( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.RegionForOnlineOffline +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/offlineRegion`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Online the specified region for the specified Azure Cosmos DB database account. */ +export async function onlineRegion( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.RegionForOnlineOffline +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/onlineRegion`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the read-only access keys for the specified Azure Cosmos DB database account. */ +export async function getReadOnlyKeys( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/readonlykeys`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Lists the read-only access keys for the specified Azure Cosmos DB database account. */ +export async function listReadOnlyKeys( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/readonlykeys`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "post" }).then(response => response.json()); +} + +/* Regenerates an access key for the specified Azure Cosmos DB database account. */ +export async function regenerateKey( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + body: Types.DatabaseAccountRegenerateKeyParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/regenerateKey`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "post", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Checks that the Azure Cosmos DB account name already exists. A valid account name may contain only lowercase letters, numbers, and the '-' character, and must be between 3 and 50 characters. */ +export async function checkNameExists(accountName: string): Promise { + const path = `/providers/Microsoft.DocumentDB/databaseAccountNames/${accountName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "head" }).then(response => response.json()); +} + +/* Retrieves the metrics determined by the given filter for the given database account. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves the usages (most recent data) for the given database account. */ +export async function listUsages( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/usages`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves metric definitions for the given database account. */ +export async function listMetricDefinitions( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/metricDefinitions`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/GremlinResources.ts b/src/Utils/arm/GremlinResources.ts index 4def1a9c2..d4c6a1435 100644 --- a/src/Utils/arm/GremlinResources.ts +++ b/src/Utils/arm/GremlinResources.ts @@ -6,110 +6,150 @@ import * as Types from "./types"; -export class GremlinResourcesClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/gremlinDatabases`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Lists the Gremlin databases under an existing Azure Cosmos DB database account. */ - async listGremlinDatabases(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the Gremlin databases under an existing Azure Cosmos DB database account with the provided name. */ - async getGremlinDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB Gremlin database */ - async createUpdateGremlinDatabase( - databaseName: string, - body: Types.GremlinDatabaseCreateUpdateParameters - ): Promise { - const path = `/${databaseName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB Gremlin database. */ - async deleteGremlinDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the Gremlin graph under an existing Azure Cosmos DB database account. */ - async listGremlinGraphs(databaseName: string): Promise { - const path = `/${databaseName}/graphs`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the Gremlin graph under an existing Azure Cosmos DB database account. */ - async getGremlinGraph(databaseName: string, graphName: string): Promise { - const path = `/${databaseName}/graphs/${graphName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB Gremlin graph */ - async createUpdateGremlinGraph( - databaseName: string, - graphName: string, - body: Types.GremlinGraphCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/graphs/${graphName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB Gremlin graph. */ - async deleteGremlinGraph(databaseName: string, graphName: string): Promise { - const path = `/${databaseName}/graphs/${graphName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the Gremlin graph throughput under an existing Azure Cosmos DB database account with the provided name. */ - async getGremlinGraphThroughput( - databaseName: string, - graphName: string - ): Promise { - const path = `/${databaseName}/graphs/${graphName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB Gremlin graph */ - async updateGremlinGraphThroughput( - databaseName: string, - graphName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/graphs/${graphName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Gets the RUs per second of the Gremlin database under an existing Azure Cosmos DB database account with the provided name. */ - async getGremlinDatabaseThroughput(databaseName: string): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB Gremlin database */ - async updateGremlinDatabaseThroughput( - databaseName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } +/* Lists the Gremlin databases under an existing Azure Cosmos DB database account. */ +export async function listGremlinDatabases( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the Gremlin databases under an existing Azure Cosmos DB database account with the provided name. */ +export async function getGremlinDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB Gremlin database */ +export async function createUpdateGremlinDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.GremlinDatabaseCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB Gremlin database. */ +export async function deleteGremlinDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the Gremlin database under an existing Azure Cosmos DB database account with the provided name. */ +export async function getGremlinDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB Gremlin database */ +export async function updateGremlinDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the Gremlin graph under an existing Azure Cosmos DB database account. */ +export async function listGremlinGraphs( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the Gremlin graph under an existing Azure Cosmos DB database account. */ +export async function getGremlinGraph( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + graphName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs/${graphName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB Gremlin graph */ +export async function createUpdateGremlinGraph( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + graphName: string, + body: Types.GremlinGraphCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs/${graphName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB Gremlin graph. */ +export async function deleteGremlinGraph( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + graphName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs/${graphName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the Gremlin graph throughput under an existing Azure Cosmos DB database account with the provided name. */ +export async function getGremlinGraphThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + graphName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs/${graphName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB Gremlin graph */ +export async function updateGremlinGraphThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + graphName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/gremlinDatabases/${databaseName}/graphs/${graphName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); } diff --git a/src/Utils/arm/MongoDBResources.ts b/src/Utils/arm/MongoDBResources.ts index 08817412c..bcbd7e2e1 100644 --- a/src/Utils/arm/MongoDBResources.ts +++ b/src/Utils/arm/MongoDBResources.ts @@ -6,110 +6,150 @@ import * as Types from "./types"; -export class MongoDBResourcesClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/mongodbDatabases`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Lists the MongoDB databases under an existing Azure Cosmos DB database account. */ - async listMongoDBDatabases(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the MongoDB databases under an existing Azure Cosmos DB database account with the provided name. */ - async getMongoDBDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or updates Azure Cosmos DB MongoDB database */ - async createUpdateMongoDBDatabase( - databaseName: string, - body: Types.MongoDBDatabaseCreateUpdateParameters - ): Promise { - const path = `/${databaseName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB MongoDB database. */ - async deleteMongoDBDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the MongoDB collection under an existing Azure Cosmos DB database account. */ - async listMongoDBCollections(databaseName: string): Promise { - const path = `/${databaseName}/collections`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the MongoDB collection under an existing Azure Cosmos DB database account. */ - async getMongoDBCollection(databaseName: string, collectionName: string): Promise { - const path = `/${databaseName}/collections/${collectionName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB MongoDB Collection */ - async createUpdateMongoDBCollection( - databaseName: string, - collectionName: string, - body: Types.MongoDBCollectionCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/collections/${collectionName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB MongoDB Collection. */ - async deleteMongoDBCollection(databaseName: string, collectionName: string): Promise { - const path = `/${databaseName}/collections/${collectionName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the RUs per second of the MongoDB collection under an existing Azure Cosmos DB database account with the provided name. */ - async getMongoDBCollectionThroughput( - databaseName: string, - collectionName: string - ): Promise { - const path = `/${databaseName}/collections/${collectionName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update the RUs per second of an Azure Cosmos DB MongoDB collection */ - async updateMongoDBCollectionThroughput( - databaseName: string, - collectionName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/collections/${collectionName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Gets the RUs per second of the MongoDB database under an existing Azure Cosmos DB database account with the provided name. */ - async getMongoDBDatabaseThroughput(databaseName: string): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of the an Azure Cosmos DB MongoDB database */ - async updateMongoDBDatabaseThroughput( - databaseName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } +/* Lists the MongoDB databases under an existing Azure Cosmos DB database account. */ +export async function listMongoDBDatabases( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the MongoDB databases under an existing Azure Cosmos DB database account with the provided name. */ +export async function getMongoDBDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or updates Azure Cosmos DB MongoDB database */ +export async function createUpdateMongoDBDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.MongoDBDatabaseCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB MongoDB database. */ +export async function deleteMongoDBDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the MongoDB database under an existing Azure Cosmos DB database account with the provided name. */ +export async function getMongoDBDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of the an Azure Cosmos DB MongoDB database */ +export async function updateMongoDBDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the MongoDB collection under an existing Azure Cosmos DB database account. */ +export async function listMongoDBCollections( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the MongoDB collection under an existing Azure Cosmos DB database account. */ +export async function getMongoDBCollection( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + collectionName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections/${collectionName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB MongoDB Collection */ +export async function createUpdateMongoDBCollection( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + collectionName: string, + body: Types.MongoDBCollectionCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections/${collectionName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB MongoDB Collection. */ +export async function deleteMongoDBCollection( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + collectionName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections/${collectionName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the MongoDB collection under an existing Azure Cosmos DB database account with the provided name. */ +export async function getMongoDBCollectionThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + collectionName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections/${collectionName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update the RUs per second of an Azure Cosmos DB MongoDB collection */ +export async function updateMongoDBCollectionThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + collectionName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/mongodbDatabases/${databaseName}/collections/${collectionName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); } diff --git a/src/Utils/arm/Operations.ts b/src/Utils/arm/Operations.ts index 5b0316680..469c69778 100644 --- a/src/Utils/arm/Operations.ts +++ b/src/Utils/arm/Operations.ts @@ -6,13 +6,8 @@ import * as Types from "./types"; -export class OperationsClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/providers/Microsoft.DocumentDB/operations`; - - /* Lists all of the available Cosmos DB Resource Provider operations. */ - async list(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Lists all of the available Cosmos DB Resource Provider operations. */ +export async function list(): Promise { + const path = `/providers/Microsoft.DocumentDB/operations`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/PartitionKeyRangeId.ts b/src/Utils/arm/PartitionKeyRangeId.ts index 9278f0f72..796979f77 100644 --- a/src/Utils/arm/PartitionKeyRangeId.ts +++ b/src/Utils/arm/PartitionKeyRangeId.ts @@ -6,22 +6,15 @@ import * as Types from "./types"; -export class PartitionKeyRangeIdClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/databases/${this.databaseRid}/collections/${this.collectionRid}/partitionKeyRangeId/${this.partitionKeyRangeId}/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly databaseRid: string, - private readonly collectionRid: string, - private readonly partitionKeyRangeId: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given partition key range id. */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given partition key range id. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseRid: string, + collectionRid: string, + partitionKeyRangeId: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/databases/${databaseRid}/collections/${collectionRid}/partitionKeyRangeId/${partitionKeyRangeId}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/PartitionKeyRangeIdRegion.ts b/src/Utils/arm/PartitionKeyRangeIdRegion.ts index f5c59bba1..e4562137d 100644 --- a/src/Utils/arm/PartitionKeyRangeIdRegion.ts +++ b/src/Utils/arm/PartitionKeyRangeIdRegion.ts @@ -6,23 +6,16 @@ import * as Types from "./types"; -export class PartitionKeyRangeIdRegionClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/region/${this.region}/databases/${this.databaseRid}/collections/${this.collectionRid}/partitionKeyRangeId/${this.partitionKeyRangeId}/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly region: string, - private readonly databaseRid: string, - private readonly collectionRid: string, - private readonly partitionKeyRangeId: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given partition key range id and region. */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given partition key range id and region. */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + region: string, + databaseRid: string, + collectionRid: string, + partitionKeyRangeId: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/region/${region}/databases/${databaseRid}/collections/${collectionRid}/partitionKeyRangeId/${partitionKeyRangeId}/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/Percentile.ts b/src/Utils/arm/Percentile.ts index 739a1bbd5..c674c34f8 100644 --- a/src/Utils/arm/Percentile.ts +++ b/src/Utils/arm/Percentile.ts @@ -6,19 +6,12 @@ import * as Types from "./types"; -export class PercentileClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/percentile/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given database account. This url is only for PBS and Replication Latency data */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given database account. This url is only for PBS and Replication Latency data */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/percentile/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/PercentileSourceTarget.ts b/src/Utils/arm/PercentileSourceTarget.ts index fe2240b76..d45110ad1 100644 --- a/src/Utils/arm/PercentileSourceTarget.ts +++ b/src/Utils/arm/PercentileSourceTarget.ts @@ -6,21 +6,14 @@ import * as Types from "./types"; -export class PercentileSourceTargetClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/sourceRegion/${this.sourceRegion}/targetRegion/${this.targetRegion}/percentile/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly sourceRegion: string, - private readonly targetRegion: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given account, source and target region. This url is only for PBS and Replication Latency data */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given account, source and target region. This url is only for PBS and Replication Latency data */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + sourceRegion: string, + targetRegion: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sourceRegion/${sourceRegion}/targetRegion/${targetRegion}/percentile/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/PercentileTarget.ts b/src/Utils/arm/PercentileTarget.ts index b7fffaeb7..1e0cb8430 100644 --- a/src/Utils/arm/PercentileTarget.ts +++ b/src/Utils/arm/PercentileTarget.ts @@ -6,20 +6,13 @@ import * as Types from "./types"; -export class PercentileTargetClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/targetRegion/${this.targetRegion}/percentile/metrics`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string, - private readonly targetRegion: string - ) {} - - /* Retrieves the metrics determined by the given filter for the given account target region. This url is only for PBS and Replication Latency data */ - async listMetrics(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Retrieves the metrics determined by the given filter for the given account target region. This url is only for PBS and Replication Latency data */ +export async function listMetrics( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + targetRegion: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/targetRegion/${targetRegion}/percentile/metrics`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/RestorableDatabaseAccounts.ts b/src/Utils/arm/RestorableDatabaseAccounts.ts index 17ad0d702..0166736d1 100644 --- a/src/Utils/arm/RestorableDatabaseAccounts.ts +++ b/src/Utils/arm/RestorableDatabaseAccounts.ts @@ -6,32 +6,29 @@ import * as Types from "./types"; -export class RestorableDatabaseAccountsClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/providers/Microsoft.DocumentDB/`; - - constructor(private readonly subscriptionId: string) {} - - /* Lists all the restorable Azure Cosmos DB database accounts available under the subscription and in a region. */ - async listByLocation( - location: string - ): Promise { - const path = `locations/${location}/restorableDatabaseAccounts`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Retrieves the properties of an existing Azure Cosmos DB restorable database account. */ - async getByLocation( - location: string, - instanceId: string - ): Promise { - const path = `locations/${location}/restorableDatabaseAccounts/${instanceId}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Lists all the restorable Azure Cosmos DB database accounts available under the subscription. */ - async list(): Promise { - const path = `restorableDatabaseAccounts`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } +/* Lists all the restorable Azure Cosmos DB database accounts available under the subscription and in a region. */ +export async function listByLocation( + subscriptionId: string, + location: string +): Promise { + const path = `/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/locations/${location}/restorableDatabaseAccounts`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Lists all the restorable Azure Cosmos DB database accounts available under the subscription. */ +export async function list( + subscriptionId: string +): Promise { + const path = `/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/restorableDatabaseAccounts`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Retrieves the properties of an existing Azure Cosmos DB restorable database account. */ +export async function getByLocation( + subscriptionId: string, + location: string, + instanceId: string +): Promise { + const path = `/subscriptions/${subscriptionId}/providers/Microsoft.DocumentDB/locations/${location}/restorableDatabaseAccounts/${instanceId}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); } diff --git a/src/Utils/arm/SqlResources.ts b/src/Utils/arm/SqlResources.ts index a75442672..6cd944314 100644 --- a/src/Utils/arm/SqlResources.ts +++ b/src/Utils/arm/SqlResources.ts @@ -6,229 +6,312 @@ import * as Types from "./types"; -export class SqlResourcesClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/sqlDatabases`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Lists the SQL databases under an existing Azure Cosmos DB database account. */ - async listSqlDatabases(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the SQL database under an existing Azure Cosmos DB database account with the provided name. */ - async getSqlDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB SQL database */ - async createUpdateSqlDatabase( - databaseName: string, - body: Types.SqlDatabaseCreateUpdateParameters - ): Promise { - const path = `/${databaseName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB SQL database. */ - async deleteSqlDatabase(databaseName: string): Promise { - const path = `/${databaseName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the SQL container under an existing Azure Cosmos DB database account. */ - async listSqlContainers(databaseName: string): Promise { - const path = `/${databaseName}/containers`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the SQL container under an existing Azure Cosmos DB database account. */ - async getSqlContainer(databaseName: string, containerName: string): Promise { - const path = `/${databaseName}/containers/${containerName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB SQL container */ - async createUpdateSqlContainer( - databaseName: string, - containerName: string, - body: Types.SqlContainerCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/containers/${containerName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB SQL container. */ - async deleteSqlContainer(databaseName: string, containerName: string): Promise { - const path = `/${databaseName}/containers/${containerName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the SQL storedProcedure under an existing Azure Cosmos DB database account. */ - async listSqlStoredProcedures( - databaseName: string, - containerName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/storedProcedures`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the SQL storedProcedure under an existing Azure Cosmos DB database account. */ - async getSqlStoredProcedure( - databaseName: string, - containerName: string, - storedProcedureName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB SQL storedProcedure */ - async createUpdateSqlStoredProcedure( - databaseName: string, - containerName: string, - storedProcedureName: string, - body: Types.SqlStoredProcedureCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB SQL storedProcedure. */ - async deleteSqlStoredProcedure( - databaseName: string, - containerName: string, - storedProcedureName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the RUs per second of the SQL container under an existing Azure Cosmos DB database account. */ - async getSqlContainerThroughput( - databaseName: string, - containerName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB SQL container */ - async updateSqlContainerThroughput( - databaseName: string, - containerName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/containers/${containerName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Lists the SQL trigger under an existing Azure Cosmos DB database account. */ - async listSqlTriggers(databaseName: string, containerName: string): Promise { - const path = `/${databaseName}/containers/${containerName}/triggers`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the SQL trigger under an existing Azure Cosmos DB database account. */ - async getSqlTrigger( - databaseName: string, - containerName: string, - triggerName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/triggers/${triggerName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB SQL trigger */ - async createUpdateSqlTrigger( - databaseName: string, - containerName: string, - triggerName: string, - body: Types.SqlTriggerCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/containers/${containerName}/triggers/${triggerName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB SQL trigger. */ - async deleteSqlTrigger(databaseName: string, containerName: string, triggerName: string): Promise { - const path = `/${databaseName}/containers/${containerName}/triggers/${triggerName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Lists the SQL userDefinedFunction under an existing Azure Cosmos DB database account. */ - async listSqlUserDefinedFunctions( - databaseName: string, - containerName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/userDefinedFunctions`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the SQL userDefinedFunction under an existing Azure Cosmos DB database account. */ - async getSqlUserDefinedFunction( - databaseName: string, - containerName: string, - userDefinedFunctionName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB SQL userDefinedFunction */ - async createUpdateSqlUserDefinedFunction( - databaseName: string, - containerName: string, - userDefinedFunctionName: string, - body: Types.SqlUserDefinedFunctionCreateUpdateParameters - ): Promise { - const path = `/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB SQL userDefinedFunction. */ - async deleteSqlUserDefinedFunction( - databaseName: string, - containerName: string, - userDefinedFunctionName: string - ): Promise { - const path = `/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the RUs per second of the SQL database under an existing Azure Cosmos DB database account with the provided name. */ - async getSqlDatabaseThroughput(databaseName: string): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB SQL database */ - async updateSqlDatabaseThroughput( - databaseName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${databaseName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } +/* Lists the SQL databases under an existing Azure Cosmos DB database account. */ +export async function listSqlDatabases( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the SQL database under an existing Azure Cosmos DB database account with the provided name. */ +export async function getSqlDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB SQL database */ +export async function createUpdateSqlDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.SqlDatabaseCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB SQL database. */ +export async function deleteSqlDatabase( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the SQL database under an existing Azure Cosmos DB database account with the provided name. */ +export async function getSqlDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB SQL database */ +export async function updateSqlDatabaseThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the SQL container under an existing Azure Cosmos DB database account. */ +export async function listSqlContainers( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the SQL container under an existing Azure Cosmos DB database account. */ +export async function getSqlContainer( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB SQL container */ +export async function createUpdateSqlContainer( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + body: Types.SqlContainerCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB SQL container. */ +export async function deleteSqlContainer( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the SQL container under an existing Azure Cosmos DB database account. */ +export async function getSqlContainerThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB SQL container */ +export async function updateSqlContainerThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Lists the SQL storedProcedure under an existing Azure Cosmos DB database account. */ +export async function listSqlStoredProcedures( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/storedProcedures`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the SQL storedProcedure under an existing Azure Cosmos DB database account. */ +export async function getSqlStoredProcedure( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + storedProcedureName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB SQL storedProcedure */ +export async function createUpdateSqlStoredProcedure( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + storedProcedureName: string, + body: Types.SqlStoredProcedureCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB SQL storedProcedure. */ +export async function deleteSqlStoredProcedure( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + storedProcedureName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/storedProcedures/${storedProcedureName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Lists the SQL userDefinedFunction under an existing Azure Cosmos DB database account. */ +export async function listSqlUserDefinedFunctions( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/userDefinedFunctions`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the SQL userDefinedFunction under an existing Azure Cosmos DB database account. */ +export async function getSqlUserDefinedFunction( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + userDefinedFunctionName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB SQL userDefinedFunction */ +export async function createUpdateSqlUserDefinedFunction( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + userDefinedFunctionName: string, + body: Types.SqlUserDefinedFunctionCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB SQL userDefinedFunction. */ +export async function deleteSqlUserDefinedFunction( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + userDefinedFunctionName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/userDefinedFunctions/${userDefinedFunctionName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Lists the SQL trigger under an existing Azure Cosmos DB database account. */ +export async function listSqlTriggers( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/triggers`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the SQL trigger under an existing Azure Cosmos DB database account. */ +export async function getSqlTrigger( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + triggerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/triggers/${triggerName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB SQL trigger */ +export async function createUpdateSqlTrigger( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + triggerName: string, + body: Types.SqlTriggerCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/triggers/${triggerName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB SQL trigger. */ +export async function deleteSqlTrigger( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + databaseName: string, + containerName: string, + triggerName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/sqlDatabases/${databaseName}/containers/${containerName}/triggers/${triggerName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); } diff --git a/src/Utils/arm/TableResources.ts b/src/Utils/arm/TableResources.ts index e44a316ee..6cbfc0a1c 100644 --- a/src/Utils/arm/TableResources.ts +++ b/src/Utils/arm/TableResources.ts @@ -6,59 +6,73 @@ import * as Types from "./types"; -export class TableResourcesClient { - private readonly baseUrl = "https://management.azure.com"; - private readonly basePath = `/subscriptions/${this.subscriptionId}/resourceGroups/${this.resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${this.accountName}/tables`; - - constructor( - private readonly subscriptionId: string, - private readonly resourceGroupName: string, - private readonly accountName: string - ) {} - - /* Lists the Tables under an existing Azure Cosmos DB database account. */ - async listTables(): Promise { - const path = ``; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Gets the Tables under an existing Azure Cosmos DB database account with the provided name. */ - async getTable(tableName: string): Promise { - const path = `/${tableName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Create or update an Azure Cosmos DB Table */ - async createUpdateTable( - tableName: string, - body: Types.TableCreateUpdateParameters - ): Promise { - const path = `/${tableName}`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } - - /* Deletes an existing Azure Cosmos DB Table. */ - async deleteTable(tableName: string): Promise { - const path = `/${tableName}`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); - } - - /* Gets the RUs per second of the Table under an existing Azure Cosmos DB database account with the provided name. */ - async getTableThroughput(tableName: string): Promise { - const path = `/${tableName}/throughputSettings/default`; - return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); - } - - /* Update RUs per second of an Azure Cosmos DB Table */ - async updateTableThroughput( - tableName: string, - body: Types.ThroughputSettingsUpdateParameters - ): Promise { - const path = `/${tableName}/throughputSettings/default`; - return window - .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) - .then(response => response.json()); - } +/* Lists the Tables under an existing Azure Cosmos DB database account. */ +export async function listTables( + subscriptionId: string, + resourceGroupName: string, + accountName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Gets the Tables under an existing Azure Cosmos DB database account with the provided name. */ +export async function getTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables/${tableName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Create or update an Azure Cosmos DB Table */ +export async function createUpdateTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + tableName: string, + body: Types.TableCreateUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables/${tableName}`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); +} + +/* Deletes an existing Azure Cosmos DB Table. */ +export async function deleteTable( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables/${tableName}`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "delete" }).then(response => response.json()); +} + +/* Gets the RUs per second of the Table under an existing Azure Cosmos DB database account with the provided name. */ +export async function getTableThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + tableName: string +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables/${tableName}/throughputSettings/default`; + return window.fetch(this.baseUrl + this.basePath + path, { method: "get" }).then(response => response.json()); +} + +/* Update RUs per second of an Azure Cosmos DB Table */ +export async function updateTableThroughput( + subscriptionId: string, + resourceGroupName: string, + accountName: string, + tableName: string, + body: Types.ThroughputSettingsUpdateParameters +): Promise { + const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${accountName}/tables/${tableName}/throughputSettings/default`; + return window + .fetch(this.baseUrl + this.basePath + path, { method: "put", body: JSON.stringify(body) }) + .then(response => response.json()); } diff --git a/utils/armClientGenerator/generator.ts b/utils/armClientGenerator/generator.ts index af0895460..1a6135644 100644 --- a/utils/armClientGenerator/generator.ts +++ b/utils/armClientGenerator/generator.ts @@ -191,11 +191,6 @@ async function main() { for (const clientName in clients) { const outputClient: string[] = [""]; outputClient.push(`import * as Types from "./types"\n\n`); - outputClient.push(`export class ${clientName}Client {\n\n`); - outputClient.push(`private readonly baseUrl = "https://management.azure.com"\n`); - const basePath = buildBasePath(clients[clientName].paths); - outputClient.push(`private readonly basePath = \`${basePath.replace(/{/g, "${this.")}\`\n\n`); - outputClient.push(buildConstructor(clients[clientName])); for (const path of clients[clientName].paths) { for (const method in schema.paths[path]) { const operation = schema.paths[path][method]; @@ -203,15 +198,15 @@ async function main() { const bodyParameter = operation.parameters.find( (parameter: { in: string; required: boolean }) => parameter.in === "body" && parameter.required === true ); - const constructorParameters = constructorParams(clients[clientName]); - const methodParameters = parametersFromPath(path).filter(p => !constructorParameters.includes(p)); outputClient.push(` /* ${operation.description} */ - async ${sanitize(camelize(methodName))} ( - ${methodParameters.map(p => `${p}: string`).join(",\n")} + export async function ${sanitize(camelize(methodName))} ( + ${parametersFromPath(path) + .map(p => `${p}: string`) + .join(",\n")} ${bodyParam(bodyParameter, "Types")} ) : Promise<${responseType(operation, "Types")}> { - const path = \`${path.replace(basePath, "").replace(/{/g, "${")}\` + const path = \`${path.replace(/{/g, "${")}\` return window.fetch(this.baseUrl + this.basePath + path, { method: "${method}", ${ bodyParameter ? "body: JSON.stringify(body)" : "" } }).then((response) => response.json()) @@ -219,25 +214,12 @@ async function main() { `); } } - outputClient.push(`}`); writeOutputFile(`./${clientName}.ts`, outputClient); } writeOutputFile("./types.ts", outputTypes); } -function buildBasePath(strings: string[]) { - const sortArr = strings.sort(); - const arrFirstElem = strings[0]; - const arrLastElem = sortArr[sortArr.length - 1]; - const arrFirstElemLength = arrFirstElem.length; - let i = 0; - while (i < arrFirstElemLength && arrFirstElem.charAt(i) === arrLastElem.charAt(i)) { - i++; - } - return arrFirstElem.substring(0, i); -} - function sanitize(name: string) { if (name === "delete") { return "destroy"; @@ -245,23 +227,6 @@ function sanitize(name: string) { return name; } -function buildConstructor(client: Client) { - const params = constructorParams(client); - if (params.length === 0) { - return ""; - } - return `\nconstructor(${params.map(p => `private readonly ${p}: string`).join(",")}){}\n`; -} - -function constructorParams(client: Client) { - let commonParams = parametersFromPath(client.paths[0]); - for (const path of client.paths) { - const params = parametersFromPath(path); - commonParams = commonParams.filter(p => params.includes(p)); - } - return commonParams; -} - function writeOutputFile(outputPath: string, components: string[]) { components.unshift(`/* AUTOGENERATED FILE