mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Update SDK
This commit is contained in:
@@ -51,7 +51,7 @@ export type UsageDatabases = {
|
||||
/**
|
||||
* Aggregated total statistics of database storage.
|
||||
*/
|
||||
databasesStorageTotal: number;
|
||||
storageTotal: number;
|
||||
/**
|
||||
* Aggregated total statistics of documents per period.
|
||||
*/
|
||||
@@ -67,7 +67,7 @@ export type UsageDatabases = {
|
||||
/**
|
||||
* Aggregated total statistics of database storage per period.
|
||||
*/
|
||||
databasesStorage: Metric[];
|
||||
storage: Metric[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -150,7 +150,41 @@ type UsageProject = {
|
||||
databasesStorageBreakdown: MetricBreakdown[];
|
||||
};
|
||||
|
||||
export class ProjectDBStorage {
|
||||
/**
|
||||
* UsageDatabase
|
||||
*/
|
||||
export type UsageDatabase = {
|
||||
/**
|
||||
* Time range of the usage stats.
|
||||
*/
|
||||
range: string;
|
||||
/**
|
||||
* Total aggregated number of collections.
|
||||
*/
|
||||
collectionsTotal: number;
|
||||
/**
|
||||
* Total aggregated number of documents.
|
||||
*/
|
||||
documentsTotal: number;
|
||||
/**
|
||||
* Total aggregated sum of storage size (in bytes).
|
||||
*/
|
||||
storageTotal: number;
|
||||
/**
|
||||
* Aggregated number of collections per period.
|
||||
*/
|
||||
collections: Metric[];
|
||||
/**
|
||||
* Aggregated number of documents per period.
|
||||
*/
|
||||
documents: Metric[];
|
||||
/**
|
||||
* Aggregated sum of storage size (in bytes) per period.
|
||||
*/
|
||||
storage: Metric[];
|
||||
}
|
||||
|
||||
export class DBStorage {
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
@@ -167,7 +201,7 @@ export class ProjectDBStorage {
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getUsage(startDate: string, endDate: string, period?: ProjectUsageRange): Promise<UsageProject> {
|
||||
async getProjectUsage(startDate: string, endDate: string, period?: ProjectUsageRange): Promise<UsageProject> {
|
||||
if (typeof startDate === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "startDate"');
|
||||
}
|
||||
@@ -205,7 +239,7 @@ export class ProjectDBStorage {
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getDBUsage(range?: DatabaseUsageRange): Promise<UsageDatabases> {
|
||||
async getUsage(range?: DatabaseUsageRange): Promise<UsageDatabases> {
|
||||
const apiPath = '/databases/usage';
|
||||
const payload: Payload = {};
|
||||
|
||||
@@ -218,4 +252,31 @@ export class ProjectDBStorage {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get database usage stats
|
||||
*
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {DatabaseUsageRange} range
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getDatabaseUsage(databaseId: string, range?: DatabaseUsageRange): Promise<UsageDatabase> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/usage'.replace('{databaseId}', databaseId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof range !== 'undefined') {
|
||||
payload['range'] = range;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
import { Billing } from '../sdk/billing';
|
||||
import { Sources } from '$lib/sdk/sources';
|
||||
import { SpecsFunctions } from '$lib/sdk/functionsSpec';
|
||||
import { ProjectDBStorage } from '$lib/sdk/usageDatabaseStorage';
|
||||
import { DBStorage } from '$lib/sdk/DBStorage';
|
||||
|
||||
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
|
||||
|
||||
@@ -46,7 +46,7 @@ const sdkForProject = {
|
||||
messaging: new Messaging(clientProject),
|
||||
project: new Project(clientProject),
|
||||
projectApi: new ProjectApi(clientProject),
|
||||
projectDatabaseStorage: new ProjectDBStorage(clientProject),
|
||||
DBStorage: new DBStorage(clientProject),
|
||||
storage: new Storage(clientProject),
|
||||
teams: new Teams(clientProject),
|
||||
users: new Users(clientProject),
|
||||
|
||||
+12
@@ -7,6 +7,8 @@
|
||||
|
||||
$: total = data.collectionsTotal;
|
||||
$: count = data.collections;
|
||||
$: totalStorage = data.storageTotal;
|
||||
$: countStorage = data.storage;
|
||||
</script>
|
||||
|
||||
<Usage
|
||||
@@ -18,3 +20,13 @@
|
||||
legend: 'Collections',
|
||||
title: 'Total collections'
|
||||
}} />
|
||||
|
||||
<Usage
|
||||
title="Storage"
|
||||
path={`/console/project-${$page.params.project}/databases/database-${$page.params.database}/usage`}
|
||||
total={totalStorage}
|
||||
count={countStorage}
|
||||
countMetadata={{
|
||||
legend: 'Collection Storage',
|
||||
title: 'Total storage used'
|
||||
}} />
|
||||
+1
-1
@@ -7,5 +7,5 @@ export const load: PageLoad = async ({ params }) => {
|
||||
const period = isValueOfStringEnum(DatabaseUsageRange, params.period)
|
||||
? params.period
|
||||
: DatabaseUsageRange.ThirtyDays;
|
||||
return sdk.forProject.databases.getDatabaseUsage(params.database, period);
|
||||
return sdk.forProject.DBStorage.getDatabaseUsage(params.database, period);
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
export let data: PageData;
|
||||
$: total = data.databasesTotal;
|
||||
$: count = data.databases;
|
||||
$: totalStorage = data.databasesStorageTotal;
|
||||
$: countStorage = data.databasesStorage;
|
||||
$: totalStorage = data.storageTotal;
|
||||
$: countStorage = data.storage;
|
||||
</script>
|
||||
|
||||
<Usage
|
||||
@@ -21,11 +21,11 @@
|
||||
}} />
|
||||
|
||||
<Usage
|
||||
title="Database storage"
|
||||
title="Storage"
|
||||
path={`/console/project-${$page.params.project}/databases/usage`}
|
||||
total={totalStorage}
|
||||
count={countStorage}
|
||||
countMetadata={{
|
||||
legend: 'Databases',
|
||||
title: 'Total database storage'
|
||||
title: 'Total storage'
|
||||
}} />
|
||||
|
||||
@@ -9,7 +9,7 @@ export const load: PageLoad = async ({ params }) => {
|
||||
? params.period
|
||||
: DatabaseUsageRange.ThirtyDays;
|
||||
try {
|
||||
return sdk.forProject.projectDatabaseStorage.getDBUsage(period);
|
||||
return sdk.forProject.DBStorage.getUsage(period);
|
||||
} catch (e) {
|
||||
error(e.code, e.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user