feat: add support foor db pools

This commit is contained in:
Christy Jacob committed 2022-11-17 22:50:26 +05:30
1 parent de73c020a7
commit 2f6ba45084
4 files changed
+75 -6

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import type { Client, Models } from "@aw-labs/appwrite-console";
type Payload = {
[key: string]: any;
}
class Service {
static CHUNK_SIZE = 5*1024*1024; // 5MB
client: Client;
constructor(client: Client) {
this.client = client;
}
static flatten(data: Payload, prefix = ''): Payload {
let output: Payload = {};
for (const key in data) {
let value = data[key];
let finalKey = prefix ? `${prefix}[${key}]` : key;
if (Array.isArray(value)) {
output = Object.assign(output, this.flatten(value, finalKey));
}
else {
output[finalKey] = value;
}
}
return output;
}
}
export class Project extends Service {
constructor(client: Client)
{
super(client);
}
/**
* Get usage stats for a project
*
*
* @param {string} range
* @throws {AppwriteException}
* @returns {Promise}
*/
async getUsage(range?: string): Promise<Models.UsageProject> {
let path = '/project/usage';
let payload: Payload = {};
console.log("Getting usage")
console.log(range)
if (typeof range !== 'undefined') {
payload['range'] = range;
}
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('get', uri, {
'content-type': 'application/json',
}, payload);
}
}
+3
View File
@@ -12,6 +12,8 @@ import {
Users
} from '@aw-labs/appwrite-console';
import { Project } from './project';
const endpoint =
import.meta.env.VITE_APPWRITE_ENDPOINT?.toString() ?? `${window?.location?.origin}/v1`;
const clientConsole = new Client();
@@ -42,6 +44,7 @@ const sdkForProject = {
functions: new Functions(clientProject),
health: new Health(clientProject),
locale: new Locale(clientProject),
project: new Project(clientProject),
projects: new Projects(clientProject),
storage: new Storage(clientProject),
teams: new Teams(clientProject),
@@ -42,7 +42,7 @@
afterNavigate(handle);
async function handle() {
const promise = usage.load(projectId, period);
const promise = usage.load(period);
if ($usage) {
await promise;
@@ -51,7 +51,7 @@
function changePeriod(newPeriod: UsagePeriods) {
period = newPeriod;
usage.load(projectId, period);
usage.load(period);
}
</script>
@@ -1,16 +1,17 @@
import { sdkForConsole } from '$lib/stores/sdk';
import { sdkForProject } from '$lib/stores/sdk';
import { cachedStore } from '$lib/helpers/cache';
import type { Models } from '@aw-labs/appwrite-console';
export const usage = cachedStore<
Models.UsageProject,
{
load: (projectId: string, range: string) => Promise<void>;
load: (range: string) => Promise<void>;
}
>('projectUsage', function ({ set }) {
return {
load: async (projectId, range) => {
const usages = await sdkForConsole.projects.getUsage(projectId, range);
load: async (range) => {
const usages = await sdkForProject.project.getUsage(range);
console.log(usages)
set(usages);
}
};