import { InputParamValueByType } from "./params_input"; import { ParamValues } from "../api"; export type ParamType = "shorttext" | "longtext" | "sql" | "boolean" | "upload" | "integer" | "float" | "date" | "datetime" | "configvar" | "json"; export type Param = { type: ParamType; } & (ShortTextParam | LongTextParam | SQLParam | BooleanParam | FileParam | IntegerParam | FloatParam | DateParam | DatetimeParam | ConfigVarParam | JSONParam); export type PromptParamType = "shorttext" | "longtext" | "sql" | "boolean" | "integer" | "float" | "date" | "datetime" | "upload" | "json"; export type PromptParam = { type: PromptParamType; } & (ShortTextParam | LongTextParam | SQLParam | BooleanParam | IntegerParam | FloatParam | DateParam | DatetimeParam | FileParam | JSONParam); type ShortTextParam = { /** * This is your commonly used "string" input. * @see https://docs.airplane.dev/platform/parameters#short-text */ type: "shorttext"; } & ParamBase & ParamRegex & ParamOptions; type LongTextParam = { /** * This is a string, but with a larger input box for users. * @see https://docs.airplane.dev/platform/parameters#long-text */ type: "longtext"; } & ParamBase & ParamRegex & ParamOptions; type SQLParam = { /** * SQL inputs are similar to long text parameters, but offer SQL syntax highlighting. * @see https://docs.airplane.dev/platform/parameters#sql */ type: "sql"; } & ParamBase & ParamOptions; type BooleanParam = { /** * Booleans are presented as on/off toggles. * @see https://docs.airplane.dev/platform/parameters#boolean */ type: "boolean"; } & ParamBase; type FileParam = { /** * The file type allows users to upload files from the web interface. * @see https://docs.airplane.dev/platform/parameters#file */ type: "upload"; } & ParamBase; type IntegerParam = { /** * Integers accept whole numbers. * @see https://docs.airplane.dev/platform/parameters#integer */ type: "integer"; } & ParamBase & ParamOptions; type FloatParam = { /** * Floats are floating-point numbers, allowing both whole numbers and decimals. * @see https://docs.airplane.dev/platform/parameters#float */ type: "float"; } & ParamBase & ParamOptions; type DateParam = { /** * Dates allow users to pick a value from a datepicker. Similar to datetimes, but without * the time component. * @see https://docs.airplane.dev/platform/parameters#date */ type: "date"; } & ParamBase & ParamOptions; type DatetimeParam = { /** * Datetimes allow users to pick a value from a date and time picker. Similar to dates, but with * a time component. * @see https://docs.airplane.dev/platform/parameters#date--time */ type: "datetime"; } & ParamBase & ParamOptions; type ConfigVarParam = { /** * Config variable parameters allow users to pass in config variables as parameter values into a task. * * This is especially useful if your task needs to use different configs between runs. * * Config variable parameters must have either a `regex` or `options` set. This determines which config * variables a user can select when executing this task. To explicitly allow a user to choose any config * variable, set regex to `^.*$`. * @see https://docs.airplane.dev/platform/parameters#config-variable */ type: "configvar"; } & ParamBase & ParamRegex & ParamOptions & (Required | Required>); type JSONParam = { /** * JSON parameters allow users to pass any valid JSON as parameter values into a task. */ type: "json"; } & ParamBase & ParamOptions; type ParamRegex = { /** * An optional regular expressions that restricts what values are permitted. * * All regular expressions must start with the `^` character and end with the `$` character. * * For config variable parameters, the regular expression will be matched against the name of the config variable (not the value). * * For help writing a regular expression, see [regex101.com](https://regex101.com). * * Airplane supports Go-style regular expressions, so certain advanced features are not supported * (e.g. negative lookaheads). To learn more about the supported syntax, see * [the RE2 documentation](https://github.com/google/re2/wiki/Syntax). * @example Matches a standard 10-digit phone number. * "^\d{3}-\d{3}-\d{4}$" */ regex?: string; }; type ParamOptions = { /** * An optional list of values that a user can pick from for this parameter. * * If set, the parameter will only accept values from the list. The task will * not execute if provided with any other value. * * Each option can optionally include a label that will be used when rendering this * option in the Airplane UI. * * Alternatively, you can specify a task slug and optional params for the options to be backed by teh output of a task. */ options?: (TParamValue | SelectOption)[] | TaskOption; }; export type SelectOption = { /** * An optional user-facing label for this value. This is purely used for visual * purposes. */ label?: string; /** * The value that will be used if this option is selected. */ value: TParamValue; }; type TaskOption = { slug: string; params?: ParamValues; }; type ParamBase = { /** * An optional user-facing name for this parameter. * * Defaults to the parameter's slug. */ name?: string; /** * An optional user-facing description for this parameter. * * Supports markdown. See the [CommonMark docs](https://commonmark.org/help/) for * an introduction to markdown formatting. */ description?: string; /** * Determines whether this parameter requires a value. This task will not exceute * unless a non-null value is provided for this parameter. * @default true */ required?: boolean; /** * Determines whether this parameter is hidden. * Hidden is evaluated as a [JS template](https://docs.airplane.dev/platform/js-templates) and can refer to other parameters by using the `params` * keyword. If hidden evaluates to a truthy value, the parameter will be hidden from the user. * @example * "params.some_other_param === 'foo'" */ hidden?: string; /** * Determines whether this parameter is secret. * Secret parameters will not show up in run log outputs and will not be stored permanently. */ secret?: boolean; /** * An expression that returns a string, representing the error, if the value is invalid, or `null` * if the value is valid. * The expression is evaluated as a [JS template](/platform/js-templates) and can * refer to other parameters by using the `params` keyword. * @example * "params.some_other_param === 'foo' ? 'some_other_param cannot be foo' : null" */ validate?: string; } & ({ /** * If a value is not provided for this parameter, the default value will be used instead. * * If a parameter is optional, but has a default value, then a non-null value will always * be provided to your task's function. */ default?: TParamValue[]; /** * Determines whether this parameter is a list of values. The task will be passed a list * of values that match the parameter type. If the parameter has multi=true and specified * options, then the user will be able to select multiple values from a dropdown. * @default false */ multi: true; } | { /** * If a value is not provided for this parameter, the default value will be used instead. * * If a parameter is optional, but has a default value, then a non-null value will always * be provided to your task's function. */ default?: TParamValue; /** * Determines whether this parameter is a list of values. The task will be passed a list * of values that match the parameter type. If the parameter has multi=true and specified * options, then the user will be able to select multiple values from a dropdown. * @default false */ multi?: false; }); /** * Utility that returns a list of all of the optional params (required=false). */ export type OptionalParamSlugs> = string extends keyof TParams ? keyof TParams : { [TSlug in keyof TParams]: TParams[TSlug]["required"] extends false ? TSlug : never; }[keyof TParams]; /** * Utility that returns a list of all of the optional params (required=false) that do not have defaults. */ export type OptionalParamSlugsWithoutDefaults> = string extends keyof TParams ? keyof TParams : { [TSlug in keyof TParams]: TParams[TSlug]["required"] extends false ? undefined extends TParams[TSlug]["default"] ? TSlug : never : never; }[keyof TParams]; export {};