Start of plugin types refactor

This commit is contained in:
Gregory Schier
2024-07-31 14:56:55 -07:00
parent 1cb86bc1b7
commit a643713139
18 changed files with 331 additions and 154 deletions

View File

@@ -0,0 +1,2 @@
export type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
export type SingleOrArray<T> = T[] | T;

View File

@@ -0,0 +1,3 @@
export type * from './models';
export type * from './plugins';
export type * from './themes';

View File

@@ -0,0 +1 @@
export * from './types';

View File

@@ -0,0 +1,135 @@
export interface BaseModel {
readonly model: string;
readonly id: string;
readonly createdAt: string;
readonly updatedAt: string;
}
export interface Workspace extends BaseModel {
readonly model: 'workspace';
name: string;
description: string;
variables: EnvironmentVariable[];
settingValidateCertificates: boolean;
settingFollowRedirects: boolean;
settingRequestTimeout: number;
}
export interface EnvironmentVariable {
name: string;
value: string;
enabled?: boolean;
}
export interface Folder extends BaseModel {
readonly workspaceId: string;
readonly model: 'folder';
folderId: string | null;
sortPriority: number;
name: string;
}
export interface Environment extends BaseModel {
readonly workspaceId: string;
readonly model: 'environment';
name: string;
variables: EnvironmentVariable[];
}
export interface HttpHeader {
name: string;
value: string;
enabled?: boolean;
}
export interface HttpUrlParameter {
name: string;
value: string;
enabled?: boolean;
}
export interface GrpcMetadataEntry {
name: string;
value: string;
enabled?: boolean;
}
export interface GrpcRequest extends BaseModel {
readonly workspaceId: string;
readonly model: 'grpc_request';
folderId: string | null;
sortPriority: number;
name: string;
url: string;
service: string | null;
method: string | null;
message: string;
authentication: Record<string, string | number | boolean | null | undefined>;
authenticationType: string | null;
metadata: GrpcMetadataEntry[];
}
export interface GrpcEvent extends BaseModel {
readonly workspaceId: string;
readonly requestId: string;
readonly connectionId: string;
readonly model: 'grpc_event';
content: string;
status: number | null;
error: string | null;
eventType:
| 'info'
| 'error'
| 'client_message'
| 'server_message'
| 'connection_start'
| 'connection_end';
metadata: Record<string, string>;
}
export interface GrpcConnection extends BaseModel {
readonly workspaceId: string;
readonly requestId: string;
readonly model: 'grpc_connection';
service: string;
method: string;
elapsed: number;
elapsedConnection: number;
status: number;
url: string;
error: string | null;
trailers: Record<string, string>;
}
export interface HttpRequest extends BaseModel {
readonly workspaceId: string;
readonly model: 'http_request';
folderId: string | null;
sortPriority: number;
name: string;
url: string;
urlParameters: HttpUrlParameter[];
body: Record<string, unknown>;
bodyType: string | null;
authentication: Record<string, string | number | boolean | null | undefined>;
authenticationType: string | null;
method: string;
headers: HttpHeader[];
}
export interface HttpResponse extends BaseModel {
readonly workspaceId: string;
readonly model: 'http_response';
readonly requestId: string;
readonly bodyPath: string | null;
readonly contentLength: number | null;
readonly error: string;
readonly status: number;
readonly elapsed: number;
readonly elapsedHeaders: number;
readonly statusReason: string;
readonly version: string;
readonly remoteAddr: string;
readonly url: string;
readonly headers: HttpHeader[];
}

View File

@@ -0,0 +1,11 @@
import { HttpRequest, HttpResponse } from '../models';
export type YaakContext = {
metadata: {
getVersion(): Promise<string>;
};
httpRequest: {
send(id: string): Promise<HttpResponse>;
getById(id: string): Promise<HttpRequest | null>;
};
};

View File

@@ -0,0 +1,16 @@
import { AtLeast } from '../helpers';
import { Environment, Folder, HttpRequest, Workspace } from '../models';
import { YaakContext } from './context';
export type ImportPluginResponse = null | {
resources: Partial<{
workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[];
environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[];
httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[];
folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
}>;
};
export type ImporterPlugin = {
onImport(ctx: YaakContext, fileContents: string): Promise<ImportPluginResponse>;
};

View File

@@ -0,0 +1,13 @@
import { SingleOrArray } from '../helpers';
import { ImporterPlugin } from './import';
import { ThemePlugin } from './theme';
/**
* The global structure of a Yaak plugin
*/
export type YaakPlugin = {
/** One or many plugins to import data into Yaak */
importers?: SingleOrArray<ImporterPlugin>;
/** One or many themes to customize the Yaak UI */
themes?: SingleOrArray<ThemePlugin>;
};

View File

@@ -0,0 +1,5 @@
import { Theme } from '../themes';
export type ThemePlugin = {
theme: Theme;
};

View File

@@ -0,0 +1,44 @@
export type Colors = {
surface: string;
surfaceHighlight?: string;
surfaceActive?: string;
text: string;
textSubtle?: string;
textSubtlest?: string;
border?: string;
borderSubtle?: string;
borderFocus?: string;
shadow?: string;
backdrop?: string;
selection?: string;
primary?: string;
secondary?: string;
info?: string;
success?: string;
notice?: string;
warning?: string;
danger?: string;
};
export type Theme = Colors & {
id: string;
name: string;
components?: Partial<{
dialog: Partial<Colors>;
menu: Partial<Colors>;
toast: Partial<Colors>;
sidebar: Partial<Colors>;
responsePane: Partial<Colors>;
appHeader: Partial<Colors>;
button: Partial<Colors>;
banner: Partial<Colors>;
placeholder: Partial<Colors>;
urlBar: Partial<Colors>;
editor: Partial<Colors>;
input: Partial<Colors>;
}>;
};