Skip to content

Commit 6f302d8

Browse files
committed
feat: create structure for deployment
1 parent 138d9d8 commit 6f302d8

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.changeset/pink-rabbits-guess.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+
New structure for deployments. It's used at `deploys.list()` method.

src/assertions/deploy.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { DeploymentState } from "@squarecloud/api-types/v2";
2+
import { z } from "zod";
3+
4+
import { assertAPIObject } from "./common";
5+
6+
const DeploymentSchema = z.object({
7+
id: z.string(),
8+
state: z.nativeEnum(DeploymentState),
9+
date: z.coerce.date(),
10+
});
11+
12+
export function assertDeployment(
13+
value: unknown,
14+
): asserts value is z.infer<typeof DeploymentSchema> {
15+
assertAPIObject({
16+
schema: DeploymentSchema,
17+
value,
18+
code: "DEPLOYMENT",
19+
route: "/apps/{app_id}/deployments",
20+
});
21+
}

src/modules/deploys.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assertString } from "@/assertions/literal";
22
import { Routes } from "@/lib/routes";
33
import type { BaseApplication } from "@/structures";
4+
import { Deployment } from "@/structures/deploy";
45

56
export class DeploysModule {
67
constructor(public readonly application: BaseApplication) {}
@@ -29,7 +30,9 @@ export class DeploysModule {
2930
Routes.apps.deployments.list(this.application.id),
3031
);
3132

32-
return data.response;
33+
return data.response.map(
34+
(deployment) => new Deployment(this.application, deployment),
35+
);
3336
}
3437

3538
/**

src/structures/deploy.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { APIDeployment, DeploymentState } from "@squarecloud/api-types/v2";
2+
3+
import { assertDeployment } from "@/assertions/deploy";
4+
import type { BaseApplication } from "./application/base";
5+
6+
export class Deployment {
7+
/** The ID of the deploy. */
8+
id: `git-${string}`;
9+
10+
/** The current state of the deploy. */
11+
state: DeploymentState;
12+
13+
/** The date the deploy was created. */
14+
createdAt: Date;
15+
16+
/** The date the deploy was created in millisseconds. */
17+
createdTimestamp: number;
18+
19+
constructor(
20+
public readonly application: BaseApplication,
21+
data: APIDeployment,
22+
) {
23+
assertDeployment(data);
24+
const { id, state, date } = data;
25+
26+
this.id = id;
27+
this.state = state;
28+
this.createdAt = new Date(date);
29+
this.createdTimestamp = this.createdAt.getTime();
30+
}
31+
}

0 commit comments

Comments
 (0)