Skip to content

Commit c78588f

Browse files
committed
refactor: pass cache management to base application
1 parent d59f57f commit c78588f

File tree

4 files changed

+10
-73
lines changed

4 files changed

+10
-73
lines changed

src/managers/application/backups.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Application,
3-
type BaseApplication,
4-
SquareCloudAPIError,
5-
} from "@/index";
1+
import { type BaseApplication, SquareCloudAPIError } from "@/index";
62
import { Routes } from "@/lib/routes";
73
import type {
84
APIApplicationBackup,

src/structures/application/application.ts

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { assertApplication } from "@/assertions/application";
2-
import { ApplicationStatus, type SquareCloudAPI } from "@/index";
3-
import { Routes } from "@/lib/routes";
4-
import type {
5-
APIApplication,
6-
ApplicationLanguage,
7-
} from "@squarecloud/api-types/v2";
2+
import type { SquareCloudAPI, WebsiteApplication } from "@/index";
3+
import type { APIApplication } from "@squarecloud/api-types/v2";
84
import { BaseApplication } from "./base";
9-
import type { WebsiteApplication } from "./website";
105

116
/**
127
* Represents a Square Cloud application
@@ -16,72 +11,12 @@ import type { WebsiteApplication } from "./website";
1611
* @param data - The data from this application
1712
*/
1813
export class Application extends BaseApplication {
19-
/** The application ID */
20-
id: string;
21-
/** The application display name */
22-
name: string;
23-
/** The application description */
24-
description?: string;
25-
/** The url to manage the application via web */
26-
url: string;
27-
/** The application current cluster */
28-
cluster: string;
29-
/** The application total ram */
30-
ram: number;
31-
/**
32-
* The application programming language
33-
*
34-
* - `javascript`
35-
* - `typescript`
36-
* - `python`
37-
* - `java`
38-
* - `elixir`
39-
* - `rust`
40-
* - `go`
41-
* - `php`
42-
* - `dotnet`
43-
* - `static`
44-
*/
45-
language: ApplicationLanguage;
46-
4714
constructor(
4815
public readonly client: SquareCloudAPI,
4916
data: APIApplication,
5017
) {
5118
assertApplication(data);
5219
super(client, { ...data, lang: data.language });
53-
54-
const { id, name, desc, cluster, ram, language } = data;
55-
56-
this.id = id;
57-
this.name = name;
58-
this.description = desc;
59-
this.cluster = cluster;
60-
this.ram = ram;
61-
this.language = language;
62-
this.url = `https://squarecloud.app/dashboard/app/${id}`;
63-
}
64-
65-
/** @returns The application current status information */
66-
async getStatus(): Promise<ApplicationStatus> {
67-
const data = await this.client.api.request(Routes.apps.status(this.id));
68-
const status = new ApplicationStatus(this.client, data.response, this.id);
69-
70-
this.client.emit("statusUpdate", this, this.cache.status, status);
71-
this.cache.set("status", status);
72-
73-
return status;
74-
}
75-
76-
/** @returns The application logs */
77-
async getLogs(): Promise<string> {
78-
const data = await this.client.api.request(Routes.apps.logs(this.id));
79-
const { logs } = data.response;
80-
81-
this.client.emit("logsUpdate", this, this.cache.logs, logs);
82-
this.cache.set("logs", logs);
83-
84-
return logs;
8520
}
8621

8722
isWebsite(): this is WebsiteApplication {

src/structures/application/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class BaseApplication {
8484
const data = await this.client.api.request(Routes.apps.status(this.id));
8585
const status = new ApplicationStatus(this.client, data.response, this.id);
8686

87+
this.client.emit("statusUpdate", this, this.cache.status, status);
88+
this.cache.set("status", status);
89+
8790
return status;
8891
}
8992

@@ -92,6 +95,9 @@ export class BaseApplication {
9295
const data = await this.client.api.request(Routes.apps.logs(this.id));
9396
const { logs } = data.response;
9497

98+
this.client.emit("logsUpdate", this, this.cache.logs, logs);
99+
this.cache.set("logs", logs);
100+
95101
return logs;
96102
}
97103

src/structures/application/website.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export class WebsiteApplication extends Application {
2323
public readonly client: SquareCloudAPI,
2424
data: APIWebsiteApplication,
2525
) {
26-
super(client, data);
2726
assertWebsiteApplication(data);
27+
super(client, data);
2828

2929
const { domain, custom } = data;
3030

0 commit comments

Comments
 (0)