Skip to content

Commit dd583f8

Browse files
committed
refactor: rename backups to snapshots
1 parent 05e9f51 commit dd583f8

File tree

12 files changed

+150
-131
lines changed

12 files changed

+150
-131
lines changed

.changeset/smooth-places-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/api": minor
3+
---
4+
5+
Rename `backups` to `snapshots`. The old `backups` property will be removed in the next major release.

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
"version": "3.7.9",
44
"description": "A NodeJS wrapper for Square Cloud API",
55
"exports": {
6-
".": {
7-
"import": {
8-
"types": "./lib/index.d.ts",
9-
"default": "./lib/index.js"
10-
},
11-
"require": {
12-
"types": "./lib/index.d.cts",
13-
"default": "./lib/index.cjs"
14-
},
6+
"import": {
157
"types": "./lib/index.d.ts",
168
"default": "./lib/index.js"
17-
}
9+
},
10+
"require": {
11+
"types": "./lib/index.d.cts",
12+
"default": "./lib/index.cjs"
13+
},
14+
"types": "./lib/index.d.ts",
15+
"default": "./lib/index.js"
1816
},
1917
"packageManager": "pnpm@10.11.1",
2018
"type": "module",

src/modules/applications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class ApplicationsModule {
102102
}
103103

104104
export * from "../services/cache/application";
105-
export * from "./backups";
106105
export * from "./deploys";
107106
export * from "./files";
108107
export * from "./network";
108+
export * from "./snapshots";

src/modules/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * from "./applications";
2-
export * from "./backups";
32
export * from "./deploys";
43
export * from "./files";
54
export * from "./network";
5+
export * from "./snapshots";
66
export * from "./user";
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ import type { RESTPostAPISnapshotResult } from "@squarecloud/api-types/v2";
22

33
import { Routes } from "@/lib/routes";
44
import { type BaseApplication, SquareCloudAPIError } from "@/structures";
5-
import { Backup } from "@/structures/backup";
5+
import { Snapshot } from "@/structures/snapshot";
66

7-
export class BackupsModule {
7+
export class SnapshotsModule {
88
constructor(public readonly application: BaseApplication) {}
99

1010
/**
11-
* Gets the list of generated backups (snapshots) for this application
11+
* Gets the list of generated snapshots for this application
1212
*/
13-
async list(): Promise<Backup[]> {
13+
async list(): Promise<Snapshot[]> {
1414
const data = await this.application.client.api.request(
1515
Routes.apps.snapshots(this.application.id),
1616
);
1717

18-
const backups = data.response.map(
19-
(backup) => new Backup(this.application, backup),
18+
const snapshots = data.response.map(
19+
(snapshot) => new Snapshot(this.application, snapshot),
2020
);
2121

2222
this.application.client.emit(
23-
"backupsUpdate",
23+
"snapshotsUpdate",
2424
this.application,
25-
this.application.cache.backups,
26-
backups,
25+
this.application.cache.snapshots,
26+
snapshots,
2727
);
28-
this.application.cache.set("backups", backups);
28+
this.application.cache.set("snapshots", snapshots);
2929

30-
return backups;
30+
return snapshots;
3131
}
3232

3333
/**
34-
* Generates a new backup
35-
* @returns The generated backup URL and key
34+
* Generates a new snapshot
35+
* @returns The generated snapshot URL and key
3636
*/
3737
async create(): Promise<RESTPostAPISnapshotResult> {
3838
const data = await this.application.client.api.request(
@@ -44,18 +44,18 @@ export class BackupsModule {
4444
}
4545

4646
/**
47-
* Generates a new backup and downloads it
48-
* @returns The downloaded backup bufer
47+
* Generates a new snapshot and downloads it
48+
* @returns The downloaded snapshot buffer
4949
*/
5050
async download(): Promise<Buffer> {
51-
const backup = await this.create();
51+
const snapshot = await this.create();
5252

53-
const res = await fetch(backup.url)
53+
const res = await fetch(snapshot.url)
5454
.then((res) => res.arrayBuffer())
5555
.catch(() => undefined);
5656

5757
if (!res) {
58-
throw new SquareCloudAPIError("BACKUP_DOWNLOAD_FAILED");
58+
throw new SquareCloudAPIError("SNAPSHOT_DOWNLOAD_FAILED");
5959
}
6060

6161
return Buffer.from(res);

src/services/cache/application.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import type { ApplicationStatus } from "@/structures";
2-
import type { Backup } from "@/structures/backup";
2+
import type { Snapshot } from "@/structures/snapshot";
33

44
import { BaseCacheService } from "./base";
55

66
export interface ApplicationCache {
77
readonly status?: ApplicationStatus;
8-
readonly backups?: Backup[];
8+
readonly snapshots?: Snapshot[];
99
readonly logs?: string;
1010
}
1111

1212
export class ApplicationCacheService extends BaseCacheService<ApplicationCache> {
1313
protected cache: ApplicationCache = {
1414
status: undefined,
15-
backups: undefined,
15+
snapshots: undefined,
1616
logs: undefined,
1717
};
1818

1919
get status() {
2020
return this.cache.status;
2121
}
2222

23-
get backups() {
24-
return this.cache.backups;
23+
get snapshots() {
24+
return this.cache.snapshots;
2525
}
2626

2727
get logs() {

src/structures/application/base.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { readFile } from "fs/promises";
77
import type { SquareCloudAPI } from "@/index";
88
import { assertPathLike, assertString } from "@/assertions/literal";
99
import { Routes } from "@/lib/routes";
10-
import { BackupsModule, DeploysModule, FilesModule } from "@/modules";
10+
import { DeploysModule, FilesModule, SnapshotsModule } from "@/modules";
1111
import { ApplicationCacheService } from "@/services";
1212
import { ApplicationStatus } from "@/structures";
1313

@@ -49,8 +49,8 @@ export class BaseApplication {
4949
public readonly cache = new ApplicationCacheService();
5050
/** Files module for this application */
5151
public readonly files = new FilesModule(this);
52-
/** Backup module for this application */
53-
public readonly backups = new BackupsModule(this);
52+
/** Snapshots module for this application */
53+
public readonly snapshots = new SnapshotsModule(this);
5454
/** Deploys module for this application */
5555
public readonly deploys = new DeploysModule(this);
5656

@@ -76,12 +76,20 @@ export class BaseApplication {
7676
this.url = `https://squarecloud.app/dashboard/app/${id}`;
7777
}
7878

79-
/** @deprecated Use `Application#backups` instead */
79+
/** @deprecated Use `Application#snapshots` instead */
8080
get backup() {
8181
console.warn(
82-
"[SquareCloudAPI] The 'backup' property is deprecated and will be removed in the the next major version. Use Application#backups instead.",
82+
"[SquareCloudAPI] The 'backup' property is deprecated and will be removed in the next major version. Use Application#snapshots instead.",
8383
);
84-
return this.backups;
84+
return this.snapshots;
85+
}
86+
87+
/** @deprecated Use `Application#snapshots` instead */
88+
get backups() {
89+
console.warn(
90+
"[SquareCloudAPI] The 'backups' property is deprecated and will be removed in the next major version. Use Application#snapshots instead.",
91+
);
92+
return this.snapshots;
8593
}
8694

8795
/**

src/structures/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export * from "./application/application";
22
export * from "./application/base";
33
export * from "./application/website";
4-
export * from "./backup";
54
export * from "./collection";
65
export * from "./deploy";
76
export * from "./error";
7+
export * from "./snapshot";
88
export * from "./status";
99
export * from "./user";
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import type { APISnapshot } from "@squarecloud/api-types/v2";
33
import type { BaseApplication } from "./application/base";
44

55
/**
6-
* Represents an application backup (snapshot)
6+
* Represents an application snapshot
77
*/
8-
export class Backup {
9-
/** Size of the backup in bytes. */
8+
export class Snapshot {
9+
/** Size of the snapshot in bytes. */
1010
public size: number;
1111

12-
/** Date of the last modification of the backup. */
12+
/** Date of the last modification of the snapshot. */
1313
public modifiedAt: Date;
1414

15-
/** Date of the last modification of the backup in millisseconds. */
15+
/** Date of the last modification of the snapshot in millisseconds. */
1616
public modifiedTimestamp: number;
1717

18-
/** AWS access key for the backup. */
18+
/** AWS access key for the snapshot. */
1919
public readonly key: string;
2020

21-
/** The URL for downloading this backup */
21+
/** The URL for downloading this snapshot */
2222
public readonly url: string;
2323

2424
/**
25-
* Represents an application backup (snapshot)
25+
* Represents an application snapshot
2626
*
2727
* @constructor
28-
* @param application - The application from which you fetched the backups
29-
* @param data - The data from this backup
28+
* @param application - The application from which you fetched the snapshots
29+
* @param data - The data from this snapshot
3030
*/
3131
constructor(
3232
public readonly application: BaseApplication,
@@ -43,18 +43,23 @@ export class Backup {
4343
}
4444

4545
/**
46-
* Downloads this backup
47-
* @returns The downloaded backup bufer
46+
* Downloads this snapshot
47+
* @returns The downloaded snapshot bufer
4848
*/
4949
async download(): Promise<Buffer> {
5050
const res = await fetch(this.url)
5151
.then((res) => res.arrayBuffer())
5252
.catch(() => undefined);
5353

5454
if (!res) {
55-
throw new Error("BACKUP_DOWNLOAD_FAILED");
55+
throw new Error("SNAPSHOT_DOWNLOAD_FAILED");
5656
}
5757

5858
return Buffer.from(res);
5959
}
6060
}
61+
62+
/**
63+
* @deprecated Use Snapshot instead.
64+
*/
65+
export class Backup extends Snapshot {}

src/types/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
User,
88
WebsiteApplication,
99
} from "@/structures";
10-
import type { Backup } from "@/structures/backup";
10+
import type { Snapshot } from "@/structures/snapshot";
1111

1212
export class TypedEventEmitter<TEvents extends Record<string, any>> {
1313
private emitter = new EventEmitter();
@@ -40,10 +40,10 @@ export interface ClientEvents {
4040
before: string | undefined,
4141
after: string,
4242
];
43-
backupsUpdate: [
43+
snapshotsUpdate: [
4444
application: BaseApplication | Application | WebsiteApplication,
45-
before: Backup[] | undefined,
46-
after: Backup[],
45+
before: Snapshot[] | undefined,
46+
after: Snapshot[],
4747
];
4848
statusUpdate: [
4949
application: BaseApplication | Application | WebsiteApplication,

0 commit comments

Comments
 (0)