Skip to content

Commit

Permalink
Merge pull request #29 from AtomiCloud/pichu
Browse files Browse the repository at this point in the history
upgrade from pichu
  • Loading branch information
kirinnee authored Nov 11, 2023
2 parents 78012a8 + 0a3e39a commit 995f405
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 19 deletions.
157 changes: 153 additions & 4 deletions src/lib/api/core/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import type {
PluginPrincipalResp,
PluginResp,
PluginVersionPrincipalResp,
PluginVersionResp,
ProcessorPrincipalResp,
ProcessorResp,
ProcessorVersionPrincipalResp,
ProcessorVersionResp,
PushPluginReq,
PushProcessorReq,
PushTemplateReq,
TemplatePrincipalResp,
TemplateResp,
TemplateVersionPrincipalResp,
Expand Down Expand Up @@ -336,14 +341,39 @@ export class Api<
},
params: RequestParams = {},
) =>
this.request<PluginVersionPrincipalResp, any>({
this.request<PluginVersionResp, any>({
path: `/api/v${version}/Plugin/slug/${username}/${pluginName}/versions/${ver}`,
method: "GET",
query: query,
secure: true,
format: "json",
...params,
});
/**
* No description
*
* @tags Plugin
* @name VPluginSlugVersionsLatestDetail
* @request GET:/api/v{version}/Plugin/slug/{username}/{pluginName}/versions/latest
* @secure
*/
vPluginSlugVersionsLatestDetail = (
username: string,
pluginName: string,
version: string,
query?: {
bumpDownload?: boolean;
},
params: RequestParams = {},
) =>
this.request<PluginVersionResp, any>({
path: `/api/v${version}/Plugin/slug/${username}/${pluginName}/versions/latest`,
method: "GET",
query: query,
secure: true,
format: "json",
...params,
});
/**
* No description
*
Expand All @@ -361,7 +391,7 @@ export class Api<
version: string,
params: RequestParams = {},
) =>
this.request<PluginVersionPrincipalResp, any>({
this.request<PluginVersionResp, any>({
path: `/api/v${version}/Plugin/id/${userId}/${pluginId}/versions/${ver}`,
method: "GET",
secure: true,
Expand Down Expand Up @@ -393,6 +423,29 @@ export class Api<
format: "json",
...params,
});
/**
* No description
*
* @tags Plugin
* @name VPluginPushCreate
* @request POST:/api/v{version}/Plugin/push/{username}
* @secure
*/
vPluginPushCreate = (
username: string,
version: string,
data: PushPluginReq,
params: RequestParams = {},
) =>
this.request<PluginVersionPrincipalResp, any>({
path: `/api/v${version}/Plugin/push/${username}`,
method: "POST",
body: data,
secure: true,
type: ContentType.Json,
format: "json",
...params,
});
/**
* No description
*
Expand Down Expand Up @@ -680,14 +733,39 @@ export class Api<
},
params: RequestParams = {},
) =>
this.request<ProcessorVersionPrincipalResp, any>({
this.request<ProcessorVersionResp, any>({
path: `/api/v${version}/Processor/slug/${username}/${processorName}/versions/${ver}`,
method: "GET",
query: query,
secure: true,
format: "json",
...params,
});
/**
* No description
*
* @tags Processor
* @name VProcessorSlugVersionsLatestDetail
* @request GET:/api/v{version}/Processor/slug/{username}/{processorName}/versions/latest
* @secure
*/
vProcessorSlugVersionsLatestDetail = (
username: string,
processorName: string,
version: string,
query?: {
bumpDownload?: boolean;
},
params: RequestParams = {},
) =>
this.request<ProcessorVersionResp, any>({
path: `/api/v${version}/Processor/slug/${username}/${processorName}/versions/latest`,
method: "GET",
query: query,
secure: true,
format: "json",
...params,
});
/**
* No description
*
Expand All @@ -705,7 +783,7 @@ export class Api<
version: string,
params: RequestParams = {},
) =>
this.request<ProcessorVersionPrincipalResp, any>({
this.request<ProcessorVersionResp, any>({
path: `/api/v${version}/Processor/id/${userId}/${processorId}/versions/${ver}`,
method: "GET",
secure: true,
Expand Down Expand Up @@ -737,6 +815,29 @@ export class Api<
format: "json",
...params,
});
/**
* No description
*
* @tags Processor
* @name VProcessorPushCreate
* @request POST:/api/v{version}/Processor/push/{username}
* @secure
*/
vProcessorPushCreate = (
username: string,
version: string,
data: PushProcessorReq,
params: RequestParams = {},
) =>
this.request<ProcessorVersionPrincipalResp, any>({
path: `/api/v${version}/Processor/push/${username}`,
method: "POST",
body: data,
secure: true,
type: ContentType.Json,
format: "json",
...params,
});
/**
* No description
*
Expand Down Expand Up @@ -1032,6 +1133,31 @@ export class Api<
format: "json",
...params,
});
/**
* No description
*
* @tags Template
* @name VTemplateSlugVersionsLatestDetail
* @request GET:/api/v{version}/Template/slug/{username}/{templateName}/versions/latest
* @secure
*/
vTemplateSlugVersionsLatestDetail = (
username: string,
templateName: string,
version: string,
query?: {
bumpDownload?: boolean;
},
params: RequestParams = {},
) =>
this.request<TemplateVersionResp, any>({
path: `/api/v${version}/Template/slug/${username}/${templateName}/versions/latest`,
method: "GET",
query: query,
secure: true,
format: "json",
...params,
});
/**
* No description
*
Expand Down Expand Up @@ -1081,6 +1207,29 @@ export class Api<
format: "json",
...params,
});
/**
* No description
*
* @tags Template
* @name VTemplatePushCreate
* @request POST:/api/v{version}/Template/push/{username}
* @secure
*/
vTemplatePushCreate = (
username: string,
version: string,
data: PushTemplateReq,
params: RequestParams = {},
) =>
this.request<TemplateVersionPrincipalResp, any>({
path: `/api/v${version}/Template/push/${username}`,
method: "POST",
body: data,
secure: true,
type: ContentType.Json,
format: "json",
...params,
});
/**
* No description
*
Expand Down
65 changes: 61 additions & 4 deletions src/lib/api/core/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface CreatePluginReq {
export interface CreatePluginVersionReq {
description?: string | null;
dockerReference?: string | null;
dockerSha?: string | null;
dockerTag?: string | null;
}

export interface CreateProcessorReq {
Expand All @@ -38,7 +38,7 @@ export interface CreateProcessorReq {
export interface CreateProcessorVersionReq {
description?: string | null;
dockerReference?: string | null;
dockerSha?: string | null;
dockerTag?: string | null;
}

export interface CreateTemplateReq {
Expand All @@ -54,9 +54,9 @@ export interface CreateTemplateReq {
export interface CreateTemplateVersionReq {
description?: string | null;
blobDockerReference?: string | null;
blobDockerSha?: string | null;
blobDockerTag?: string | null;
templateDockerReference?: string | null;
templateDockerSha?: string | null;
templateDockerTag?: string | null;
plugins?: PluginReferenceReq[] | null;
processors?: ProcessorReferenceReq[] | null;
}
Expand Down Expand Up @@ -122,6 +122,12 @@ export interface PluginVersionPrincipalResp {
description?: string | null;
dockerReference?: string | null;
dockerSha?: string | null;
dockerTag?: string | null;
}

export interface PluginVersionResp {
principal?: PluginVersionPrincipalResp;
plugin?: PluginPrincipalResp;
}

export interface ProcessorInfoResp {
Expand Down Expand Up @@ -170,6 +176,55 @@ export interface ProcessorVersionPrincipalResp {
description?: string | null;
dockerReference?: string | null;
dockerSha?: string | null;
dockerTag?: string | null;
}

export interface ProcessorVersionResp {
principal?: ProcessorVersionPrincipalResp;
processor?: ProcessorPrincipalResp;
}

export interface PushPluginReq {
name?: string | null;
project?: string | null;
source?: string | null;
email?: string | null;
tags?: string[] | null;
description?: string | null;
readme?: string | null;
versionDescription?: string | null;
dockerReference?: string | null;
dockerTag?: string | null;
}

export interface PushProcessorReq {
name?: string | null;
project?: string | null;
source?: string | null;
email?: string | null;
tags?: string[] | null;
description?: string | null;
readme?: string | null;
versionDescription?: string | null;
dockerReference?: string | null;
dockerTag?: string | null;
}

export interface PushTemplateReq {
name?: string | null;
project?: string | null;
source?: string | null;
email?: string | null;
tags?: string[] | null;
description?: string | null;
readme?: string | null;
versionDescription?: string | null;
blobDockerReference?: string | null;
blobDockerTag?: string | null;
templateDockerReference?: string | null;
templateDockerTag?: string | null;
plugins?: PluginReferenceReq[] | null;
processors?: ProcessorReferenceReq[] | null;
}

export interface TemplateInfoResp {
Expand Down Expand Up @@ -211,6 +266,8 @@ export interface TemplateVersionPrincipalResp {
blobDockerSha?: string | null;
templateDockerReference?: string | null;
templateDockerSha?: string | null;
blobDockerTag?: string | null;
templateDockerTag?: string | null;
}

export interface TemplateVersionResp {
Expand Down
18 changes: 8 additions & 10 deletions src/lib/api/core/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* ---------------------------------------------------------------
*/

import { browser } from "$app/environment";

export type QueryParamsType = Record<string | number, any>;
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;

Expand Down Expand Up @@ -70,14 +68,12 @@ export class HttpClient<SecurityDataType = unknown> {
private customFetch = (...fetchParams: Parameters<typeof fetch>) =>
fetch(...fetchParams);

private baseApiParams: RequestParams = browser
? {
credentials: "same-origin",
headers: {},
redirect: "follow",
referrerPolicy: "no-referrer",
}
: { headers: {} };
private baseApiParams: RequestParams = {
credentials: "same-origin",
headers: {},
redirect: "follow",
referrerPolicy: "no-referrer",
};

constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
Object.assign(this, apiConfig);
Expand Down Expand Up @@ -208,6 +204,7 @@ export class HttpClient<SecurityDataType = unknown> {
const queryString = query && this.toQueryString(query);
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
const responseFormat = format || requestParams.format;

return this.customFetch(
`${baseUrl || this.baseUrl || ""}${path}${
queryString ? `?${queryString}` : ""
Expand All @@ -233,6 +230,7 @@ export class HttpClient<SecurityDataType = unknown> {
const r = response as HttpResponse<T, E>;
r.data = null as unknown as T;
r.error = null as unknown as E;

const data = !responseFormat
? r
: await response[responseFormat]()
Expand Down
Loading

0 comments on commit 995f405

Please sign in to comment.