@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
130 lines (129 loc) • 6.38 kB
TypeScript
import { Run } from "airplane/api";
import { DefaultOutput, DefaultParams, ParamValues } from "../client";
import { MutationHookOptions } from "../state";
import { RunbookMutationHookOptions } from "../state/tasks/useRunbookMutation";
import { UseTaskQueryOptions } from "../state/tasks/useTaskQuery";
export type AirplaneFunc<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = (paramValues: TParams) => Promise<Run<any, TOutput>>;
/**
* FullQuery is a query that uses an airplane function or a slug. It is always
* an object and does not include the shorthands of just slug or just function.
*/
export type FullQuery<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = FunctionQuery<TParams, TOutput> | SlugQuery<TParams, TOutput>;
/** FunctionQuery is a query that takes an airplane function and params. */
export type FunctionQuery<TParams extends ParamValues | undefined, TOutput = DefaultOutput> = (Record<string, never> extends TParams ? {
/**
* A function returned by airplane.task to execute.
* @example
* // myTask can be used as fn.
* const myTask = airplane.task(async (params) => {...
*/
fn: AirplaneFunc<TParams, TOutput>;
params?: TParams;
slug?: never;
} : {
/**
* A function returned by airplane.task to execute.
* @example
* // myTask can be used as fn.
* const myTask = airplane.task(async (params) => {...
*/
fn: AirplaneFunc<TParams, TOutput>;
params: TParams;
slug?: never;
}) & UseTaskQueryOptions<TParams, TOutput>;
/** SlugQuery is a query that takes a slug and params. */
export type SlugQuery<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = {
/** The slug of the task to execute. */
slug: string;
fn?: never;
} & UseTaskQueryOptions<TParams, TOutput>;
/**
* TaskQuery is a query that uses an airplane function or a slug. If the task's
* parameters are optional then it can take a shorthand of a string slug or a function.
*/
export type TaskQuery<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = SlugQuery<TParams, TOutput> | string | FunctionQuery<TParams, TOutput> | (Record<string, never> extends TParams ? AirplaneFunc<TParams, TOutput> : never);
/**
* getFullQuery gets a FullQuery given a TaskQuery. It converts shorthands (just string or function)
* to their full form.
*/
export declare function getFullQuery<TParams extends ParamValues | undefined = DefaultParams>(q: TaskQuery<TParams>): FullQuery<TParams>;
/**
* FullMutation is a mutation that uses an airplane function or a slug. It is always
* an object and does not include the shorthands of just slug or just function.
*/
export type FullMutation<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = FunctionMutation<TParams, TOutput> | SlugMutation<TParams, TOutput>;
/** FunctionMutation is a mutation that takes an airplane function and params. */
export type FunctionMutation<TParams extends ParamValues | undefined, TOutput = DefaultOutput> = (Record<string, never> extends TParams ? {
/**
* A function returned by airplane.task to execute.
* @example
* // myTask can be used as fn.
* const myTask = airplane.task(async (params) => {...
*/
fn: AirplaneFunc<TParams, TOutput>;
params?: TParams;
slug?: never;
} : {
/**
* A function returned by airplane.task to execute.
* @example
* // myTask can be used as fn.
* const myTask = airplane.task(async (params) => {...
*/
fn: AirplaneFunc<TParams, TOutput>;
params: TParams;
slug?: never;
}) & MutationHookOptions<TParams, TOutput>;
/** SlugMutation is a mutation that takes a slug and params. */
export type SlugMutation<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = {
/** The slug of the task to execute. */
slug: string;
} & MutationHookOptions<TParams, TOutput>;
/**
* TaskMutation is a mutation that uses an airplane function or a slug. If the task's
* parameters are optional then it can take a shorthand of a string slug or a function.
*/
export type TaskMutation<TParams extends ParamValues | undefined = DefaultParams, TOutput = DefaultOutput> = SlugMutation<TParams, TOutput> | string | FunctionMutation<TParams, TOutput> | (Record<string, never> extends TParams ? AirplaneFunc<TParams, TOutput> : never);
/**
* getFullMutation gets a FullMutation given a TaskMutation.
* It converts shorthands (just string or function) to their full form.
*/
export declare function getFullMutation<TParams extends ParamValues | undefined = DefaultParams>(m: TaskMutation<TParams>): FullMutation<TParams>;
/**
* getSlug takes a full query or mutation and returns the task slug.
*/
export declare function getSlug<TParams extends ParamValues | undefined = DefaultParams>(fullQuery: FullQuery<TParams> | FullMutation<TParams>): string;
/**
* getRunbookFullMutation gets a RunbookFullMutation given a RunbookMutation.
* It converts a shorthand string slug into the full runbook form.
*/
export declare function getRunbookFullMutation<TParams extends ParamValues | undefined = DefaultParams>(m: RunbookMutation<TParams>): RunbookFullMutation<TParams>;
/** 4XX errors from executing task or runbook (except for 403 missing execute permissions) */
type ClientExecuteError = {
message: string;
type: "CLIENT_ERROR";
};
/** All other API errors (403 and 5XX errors) */
type InternalExecuteError = {
message: string;
type: "AIRPLANE_INTERNAL";
};
/** Run/session failure errors */
type FailedExecuteError = {
message: string;
type: "FAILED";
};
export type ExecuteError = ClientExecuteError | InternalExecuteError | FailedExecuteError;
export type RunbookSlugMutation<TParams extends ParamValues | undefined = DefaultParams> = {
slug: string;
} & RunbookMutationHookOptions<TParams>;
export type RunbookFullMutation<TParams extends ParamValues | undefined = DefaultParams> = RunbookSlugMutation<TParams>;
export type RunbookMutation<TParams extends ParamValues | undefined = DefaultParams> = RunbookSlugMutation<TParams> | string;
export type RefetchQuery = {
slug: string;
params?: ParamValues;
} | string | {
fn: AirplaneFunc<any>;
params?: ParamValues;
} | AirplaneFunc<any>;
export {};