Skip to content

Pikachu #30

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

Merged
merged 3 commits into from
Nov 11, 2023
Merged
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
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