Skip to content

Commit d59f57f

Browse files
committed
refactor: make some managers available at base application
1 parent a8d5bda commit d59f57f

File tree

8 files changed

+54
-28
lines changed

8 files changed

+54
-28
lines changed

.changeset/selfish-rockets-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/api": patch
3+
---
4+
5+
Now `backups`, `deploys`, `files` and `cache` are available in the BaseApplication.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { type Application, SquareCloudAPIError } from "@/index";
1+
import {
2+
Application,
3+
type BaseApplication,
4+
SquareCloudAPIError,
5+
} from "@/index";
26
import { Routes } from "@/lib/routes";
37
import type {
48
APIApplicationBackup,
59
RESTPostAPIApplicationBackupResult,
610
} from "@squarecloud/api-types/v2";
711

8-
export class ApplicationBackupManager {
9-
constructor(public readonly application: Application) {}
12+
export class ApplicationBackupsManager {
13+
constructor(public readonly application: BaseApplication) {}
1014

1115
async list(): Promise<APIApplicationBackup[]> {
1216
const data = await this.application.client.api.request(

src/managers/application/deploys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { assertString } from "@/assertions/literal";
2-
import type { Application } from "@/index";
2+
import type { BaseApplication } from "@/index";
33
import { Routes } from "@/lib/routes";
44

55
export class ApplicationDeploysManager {
6-
constructor(public readonly application: Application) {}
6+
constructor(public readonly application: BaseApplication) {}
77

88
/**
99
* Integrates Square Cloud with GitHub webhooks

src/managers/application/files.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { join } from "path";
22
import { assertPathLike, assertString } from "@/assertions/literal";
3-
import type { Application } from "@/index";
3+
import type { BaseApplication } from "@/index";
44
import { Routes } from "@/lib/routes";
55
import { readFile } from "fs/promises";
66

77
export class ApplicationFilesManager {
8-
constructor(public readonly application: Application) {}
8+
constructor(public readonly application: BaseApplication) {}
99

1010
/**
1111
* Lists the files inside a directory

src/managers/application/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class ApplicationManager {
9999
}
100100
}
101101

102-
export * from "./backup";
102+
export * from "./backups";
103103
export * from "./cache";
104104
export * from "./deploys";
105105
export * from "./files";

src/structures/application/application.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { assertApplication } from "@/assertions/application";
22
import { ApplicationStatus, type SquareCloudAPI } from "@/index";
33
import { Routes } from "@/lib/routes";
4-
import {
5-
ApplicationBackupManager,
6-
ApplicationCacheManager,
7-
ApplicationDeploysManager,
8-
ApplicationFilesManager,
9-
} from "@/managers";
104
import type {
115
APIApplication,
126
ApplicationLanguage,
@@ -45,16 +39,10 @@ export class Application extends BaseApplication {
4539
* - `rust`
4640
* - `go`
4741
* - `php`
42+
* - `dotnet`
43+
* - `static`
4844
*/
4945
language: ApplicationLanguage;
50-
/** Files manager for this application */
51-
files = new ApplicationFilesManager(this);
52-
/** Backup manager for this application */
53-
backup = new ApplicationBackupManager(this);
54-
/** Deploys manager for this application */
55-
deploys = new ApplicationDeploysManager(this);
56-
/** Cache manager for this application */
57-
cache = new ApplicationCacheManager();
5846

5947
constructor(
6048
public readonly client: SquareCloudAPI,

src/structures/application/base.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { assertPathLike, assertString } from "@/assertions/literal";
2-
import { ApplicationStatus, type SquareCloudAPI } from "@/index";
2+
import {
3+
ApplicationBackupsManager,
4+
ApplicationCacheManager,
5+
ApplicationDeploysManager,
6+
ApplicationFilesManager,
7+
ApplicationStatus,
8+
type SquareCloudAPI,
9+
} from "@/index";
310
import { Routes } from "@/lib/routes";
411
import type {
512
APIUserApplication,
@@ -17,11 +24,18 @@ import type { Application } from "./application";
1724
* @param data - The data from this application
1825
*/
1926
export class BaseApplication {
27+
/** The application ID */
2028
id: string;
29+
/** The application display name */
2130
name: string;
31+
/** The application description */
2232
description?: string;
33+
/** The url to manage the application via web */
2334
url: string;
35+
/** The application total ram */
2436
ram: number;
37+
/** The application current cluster */
38+
cluster: string;
2539
/**
2640
* The application programming language
2741
*
@@ -33,9 +47,18 @@ export class BaseApplication {
3347
* - `rust`
3448
* - `go`
3549
* - `php`
50+
* - `dotnet`
51+
* - `static`
3652
*/
3753
language: ApplicationLanguage;
38-
cluster: string;
54+
/** Cache manager for this application */
55+
cache = new ApplicationCacheManager();
56+
/** Files manager for this application */
57+
files = new ApplicationFilesManager(this);
58+
/** Backup manager for this application */
59+
backups = new ApplicationBackupsManager(this);
60+
/** Deploys manager for this application */
61+
deploys = new ApplicationDeploysManager(this);
3962

4063
constructor(
4164
public readonly client: SquareCloudAPI,

src/types/client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import EventEmitter from "events";
22
import type { APIApplicationBackup } from "@squarecloud/api-types/v2";
3-
import type { Application, ApplicationStatus, User } from "..";
3+
import type {
4+
Application,
5+
ApplicationStatus,
6+
BaseApplication,
7+
User,
8+
WebsiteApplication,
9+
} from "..";
410

511
export class TypedEventEmitter<TEvents extends Record<string, any>> {
612
private emitter = new EventEmitter();
@@ -29,17 +35,17 @@ export class TypedEventEmitter<TEvents extends Record<string, any>> {
2935

3036
export interface ClientEvents {
3137
logsUpdate: [
32-
application: Application,
38+
application: BaseApplication | Application | WebsiteApplication,
3339
before: string | undefined,
3440
after: string,
3541
];
3642
backupsUpdate: [
37-
application: Application,
43+
application: BaseApplication | Application | WebsiteApplication,
3844
before: APIApplicationBackup[] | undefined,
3945
after: APIApplicationBackup[],
4046
];
4147
statusUpdate: [
42-
application: Application,
48+
application: BaseApplication | Application | WebsiteApplication,
4349
before: ApplicationStatus | undefined,
4450
after: ApplicationStatus,
4551
];

0 commit comments

Comments
 (0)