Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring & Adding Interfaces #36

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package-lock.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be commited, the version is not 1.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ export interface Deployment {
packages: Record<LanguageId, Handle[]>;
ports: number[];
}
export class IDeployment implements Deployment {
public status: DeployStatus;
public prefix: string;
public suffix: string;
public version: string;
public packages: Record<LanguageId, Handle[]>;
public ports: number[];

constructor(
status: DeployStatus,
prefix: string,
suffix: string,
version: string,
packages: Record<LanguageId, Handle[]>,
ports: number[]
) {
this.status = status;
this.prefix = prefix;
this.suffix = suffix;
this.version = version;
this.packages = packages;
this.ports = ports;
}
}

export interface Create {
suffix: string;
Expand Down
96 changes: 57 additions & 39 deletions src/protocol.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of the interfaces is correct, but the interface API should not be modified, this will imply we have to modify metacall-deploy too, and maybe other dependencies. I do not want to do that yet.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ export interface Branches {
branches: [string];
}

export interface DeployBody {
name: string;
env: { name: string; value: string }[];
plan: Plans;
resourceType: ResourceType;
release?: string;
version?: string;
}

export interface DeleteBody {
prefix: string;
suffix: string;
version: string;
}

export interface FetchFilesFromRepoBody {
branch: string;
url: string;
}

export interface FetchBranchListBody {
url: string;
}

export interface API {
refresh(): Promise<string>;
validate(): Promise<boolean>;
Expand All @@ -68,28 +92,17 @@ export interface API {
branch: string,
jsons: MetaCallJSON[]
): Promise<AddResponse>;
deploy(
name: string,
env: { name: string; value: string }[],
plan: Plans,
resourceType: ResourceType,
release?: string,
version?: string
): Promise<Create>;
deployDelete(
prefix: string,
suffix: string,
version: string
): Promise<string>;
deploy(options: DeployBody): Promise<Create>;
deployDelete(options: DeleteBody): Promise<string>;
logs(
container: string,
type: LogType,
suffix: string,
prefix: string,
version?: string
): Promise<string>;
branchList(url: string): Promise<Branches>;
fileList(url: string, branch: string): Promise<string[]>;
branchList(options: FetchBranchListBody): Promise<Branches>;
fileList(options: FetchFilesFromRepoBody): Promise<string[]>;
}

export default (token: string, baseURL: string): API => {
Expand Down Expand Up @@ -198,8 +211,9 @@ export default (token: string, baseURL: string): API => {
}
)
.then((res: AxiosResponse) => res.data as AddResponse),
branchList: (url: string): Promise<Branches> =>
axios
branchList: async (options: FetchBranchListBody): Promise<Branches> => {
const { url } = options;
return await axios
.post<string>(
baseURL + '/api/repository/branchlist',
{
Expand All @@ -209,17 +223,19 @@ export default (token: string, baseURL: string): API => {
headers: { Authorization: 'jwt ' + token }
}
)
.then((res: AxiosResponse) => res.data as Branches),
.then((res: AxiosResponse) => res.data as Branches);
},

deploy: (
name: string,
env: { name: string; value: string }[],
plan: Plans,
resourceType: ResourceType,
release: string = Date.now().toString(16),
version = 'v1'
): Promise<Create> =>
axios
deploy: async (options: DeployBody): Promise<Create> => {
const {
name,
env,
plan,
resourceType,
release = Date.now().toString(16),
version = 'v1'
} = options;
return await axios
.post<Create>(
baseURL + '/api/deploy/create',
{
Expand All @@ -234,14 +250,12 @@ export default (token: string, baseURL: string): API => {
headers: { Authorization: 'jwt ' + token }
}
)
.then(res => res.data),
.then(res => res.data);
},

deployDelete: (
prefix: string,
suffix: string,
version = 'v1'
): Promise<string> =>
axios
deployDelete: async (options: DeleteBody): Promise<string> => {
const { prefix, suffix, version = 'v1' } = options;
return await axios
.post<string>(
baseURL + '/api/deploy/delete',
{
Expand All @@ -253,8 +267,8 @@ export default (token: string, baseURL: string): API => {
headers: { Authorization: 'jwt ' + token }
}
)
.then(res => res.data),

.then(res => res.data);
},
logs: (
container: string,
type: LogType = LogType.Deploy,
Expand All @@ -278,8 +292,11 @@ export default (token: string, baseURL: string): API => {
)
.then(res => res.data),

fileList: (url: string, branch: string): Promise<string[]> =>
axios
fileList: async (
options: FetchFilesFromRepoBody
): Promise<string[]> => {
const { url, branch } = options;
return await axios
.post<{ [k: string]: string[] }>(
baseURL + '/api/repository/filelist',
{
Expand All @@ -290,7 +307,8 @@ export default (token: string, baseURL: string): API => {
headers: { Authorization: 'jwt ' + token }
}
)
.then(res => res.data['files'])
.then(res => res.data['files']);
}
};

return api;
Expand Down