Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
export * from "./question";
export * from "./ui";
export * from "./validation";
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/qm/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC"}
+9
View File
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./question"), exports);
tslib_1.__exportStar(require("./ui"), exports);
tslib_1.__exportStar(require("./validation"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/qm/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,YAAY,CAAC;;;AAEb,qDAA2B;AAC3B,+CAAqB;AACrB,uDAA6B"}
+435
View File
@@ -0,0 +1,435 @@
import { Inputs, OptionItem } from "../types";
import { ConditionFunc, FuncValidation, StringArrayValidation, StringValidation, ValidationSchema } from "./validation";
export interface FunctionRouter {
namespace: string;
method: string;
}
export interface Func extends FunctionRouter {
params?: any;
}
/**
* definition of a function that return some dynamic value
*/
export type LocalFunc<T> = (inputs: Inputs) => T | Promise<T>;
export type OnSelectionChangeFunc = (currentSelectedIds: Set<string>, previousSelectedIds: Set<string>) => Promise<Set<string>>;
/**
* static option is `string` array or `OptionItem` array.
* If the option is a string array, each element of which will be converted to an `OptionItem` object with `id` and `label` field equal to the string element.
* For example, option=['id1','id2'] => [{'id':'id1', label:'id1'},{'id':'id2', label:'id2'}].
*/
export type StaticOptions = string[] | OptionItem[];
/**
* dynamic option is defined by a function
*/
export type DynamicOptions = LocalFunc<StaticOptions>;
/**
* Basic question data
*/
export interface BaseQuestion {
/**
* name is the identifier of the question
*/
name: string;
/**
* human readable meaningful display name of the question
*/
title?: string | LocalFunc<string | undefined>;
/**
* the answer of the question
*/
value?: unknown;
valueType?: "skip" | "success";
/**
* default input value
*/
default?: unknown;
/**
* `step` and `totalSteps` are used to describe the progress in question flow
* `step` is the sequence number of current question
*/
step?: number;
/**
* `totalStep` is the number of questions totally
*/
totalSteps?: number;
/**
* `innerStep` and `innerTotalStep` are used to describe the inner step of a group of questions
* `innerStep` is the sequence number of the current question in the group.
* VSC will display the innerStep and innerTotalStep in the question title.
*/
innerStep?: number;
/**
* `innerTotalStep` is the number of questions in the group in total
*/
innerTotalStep?: number;
/**
* if true, the toolkit will not remember the value as default value
*/
forgetLastValue?: boolean;
/**
* Actions that can be made within the question.
* @param An array of actions
* @param `icon` is the icon id of the action item
* @param `tooltip` is the hint of the action item
* @param `command` is the command name that will be executed when current action triggered
*/
buttons?: {
icon: string;
tooltip: string;
command: string;
}[];
}
/**
* Definition of question that needs human input
*/
export interface UserInputQuestion extends BaseQuestion {
/**
* question type
*/
type: "singleSelect" | "multiSelect" | "singleFile" | "multiFile" | "folder" | "text" | "singleFileOrText" | "innerText" | "confirm";
/**
* title is required for human input question
*/
title: string | LocalFunc<string | undefined>;
/**
* placeholder in the input text box
* placeholder can have dynamic value defined by a function with type `LocalFunc<string | undefined>`
*/
placeholder?: string | LocalFunc<string | undefined>;
/**
* prompt text providing some ask or explanation to the user
* prompt can have dynamic value defined by a function with type `LocalFunc<string | undefined>`
*/
prompt?: string | LocalFunc<string | undefined>;
/**
* default value of the question
*/
default?: string | string[] | boolean | LocalFunc<string | string[] | boolean | undefined>;
/**
* validation schema for the answer value, which can be static validation schema or dynamic customized validation function
*/
validation?: ValidationSchema;
/**
* An optional validation message indicating or explaining the problem with the current input value.
*/
validationHelp?: string;
/**
* A flag to indicate whether the question is required for CLI non-interactive mode.
* Default value is false.
* If not explicitly defined, the framework will try to fillin this field.
*/
required?: boolean;
/**
* alternative names of the question that use to map the input properties into final Input object
*/
alternativeNames?: string[];
/**
* CLI option/argument name, if not specified, the question name will be used as the CLI option/argument name
*/
cliName?: string;
/**
* the question is only for CLI option abbrevation
*/
cliShortName?: string;
/**
* whether the value is a boolean string value, if true, it will support '--option', which is equivalant to '--option true'
*/
isBoolean?: boolean;
/**
* whether the question is mapped to CLI option or argument, default is option
*/
cliType?: "option" | "argument";
cliDescription?: string;
/**
* @description the question will converted to a hidden option in CLI
*/
cliHidden?: boolean;
}
/**
* Definition of single selection question
*/
export interface SingleSelectQuestion extends UserInputQuestion {
type: "singleSelect";
/**
* static options array
* CLI's help command focus only on this static option
*/
staticOptions: StaticOptions;
/**
* dynamic option, which has higher priority than static options
*/
dynamicOptions?: DynamicOptions;
/**
* answer value, which is the `id` string or `OptionItem` object
*/
value?: string | OptionItem;
/**
* The default selected `id` value of the option item
*/
default?: string | LocalFunc<string | undefined>;
/**
* This config only works for option items with `OptionItem[]` type. If `returnObject` is true, the answer value is an `OptionItem` object; otherwise, the answer value is the `id` string of the `OptionItem`.
* In case of option items with `string[]` type, whether `returnObject` is true or false, the returned answer value is always a string.
*/
returnObject?: boolean;
/**
* whether to skip the single option select question
* if true: single select question will be automatically answered with the single option;
* if false: use still need to do the selection manually even there is no other choice.
*/
skipSingleOption?: boolean | LocalFunc<boolean>;
/**
* the command is only for CLI option description
*/
cliChoiceListCommand?: string;
/**
* whether to skip validation against allowed list in non-interactive mode, default false
*/
skipValidation?: boolean;
}
/**
* Definition of single selection question
*/
export interface ConfirmQuestion extends UserInputQuestion {
type: "confirm";
/**
* display text for option true or false
*/
transformer?: (value: boolean) => string;
/**
* answer value: true or false
*/
value?: boolean;
/**
* The default selected `id` value of the option item
*/
default?: boolean | LocalFunc<boolean>;
}
/**
* Definition of multiple selection question
*/
export interface MultiSelectQuestion extends UserInputQuestion {
type: "multiSelect";
/**
* static options array
* CLI's help command focus only on this static option
*/
staticOptions: StaticOptions;
/**
* dynamic option, which has higher priority than static options
*/
dynamicOptions?: DynamicOptions;
/**
* answer value, which is `id` string array or `OptionItem` object array
*/
value?: string[] | OptionItem[];
/**
* The default selected `id` array of the option item
*/
default?: string[] | LocalFunc<string[] | undefined> | "none" | "all";
/**
* This config only works for option items with `OptionItem[]` type. If `returnObject` is true, the answer value is an array of `OptionItem` objects; otherwise, the answer value is an array of `id` strings.
* In case of option items with `string[]` type, whether `returnObject` is true or false, the returned answer value is always a string array.
*/
returnObject?: boolean;
/**
* whether to skip the single option select question
* if true: single select question will be automatically answered with the single option;
* if false: use still need to do the selection manually even there is no second choice
*/
skipSingleOption?: boolean;
/**
* a callback function which is triggered when the selected values change, which can change the final selected values.
* @param currentSelectedIds current selected option ids
* @param previousSelectedIds previous selected option ids
* @returns the final selected option ids
*/
onDidChangeSelection?: OnSelectionChangeFunc;
/**
* validation schema for the answer values
*/
validation?: StringArrayValidation | FuncValidation<string[]>;
/**
* the command is only for CLI option description
*/
cliChoiceListCommand?: string;
/**
* whether to skip validation against allowed list in non-interactive mode, default false
*/
skipValidation?: boolean;
}
/**
* Definition of text input question
*/
export interface TextInputQuestion extends UserInputQuestion {
type: "text";
/**
* If the input value should be hidden. Defaults to false.
*/
password?: boolean;
/**
* input value.
*/
value?: string;
/**
* default value
*
*/
default?: string | LocalFunc<string | undefined>;
/**
* validation schema, which can be a dynamic function closure
*/
validation?: StringValidation | FuncValidation<string>;
/**
* validation when user confirms the input.
*/
additionalValidationOnAccept?: StringValidation | FuncValidation<string>;
}
/**
* Definition of text input question of a sub-question of SingleFileOrInputQuestion
*/
export interface InnerTextInputQuestion extends UserInputQuestion {
type: "innerText";
/**
* If the input value should be hidden. Defaults to false.
*/
password?: boolean;
/**
* input value.
*/
value?: string;
/**
* default value
*
*/
default?: string | LocalFunc<string | undefined>;
/**
* validation schema, which can be a dynamic function closure
*/
validation?: StringValidation | FuncValidation<string>;
}
/**
* Definition of single file selection
*/
export interface SingleFileQuestion extends UserInputQuestion {
type: "singleFile";
/**
* the answer value is a file path string
*/
value?: string;
/**
* default selected file path
*/
default?: string | LocalFunc<string | undefined>;
/**
* validation function
*/
validation?: FuncValidation<string>;
/**
* This will only take effect in VSC.
* A set of file filters that are used by the dialog. Each entry is a human-readable label,
* like "TypeScript", and an array of extensions, e.g.
* ```ts
* {
* 'Images': ['png', 'jpg']
* 'TypeScript': ['ts', 'tsx']
* }
* ```
*/
filters?: {
[name: string]: string[];
};
/**
* Default Uri when open file selector window.
*/
defaultFolder?: string | LocalFunc<string | undefined>;
}
export interface MultiFileQuestion extends UserInputQuestion {
type: "multiFile";
/**
* the answer value is an array of file paths
*/
value?: string[];
/**
* default selected file path
*/
default?: string | LocalFunc<string | undefined>;
/**
* validation function
*/
validation?: FuncValidation<string[]>;
}
export interface FolderQuestion extends UserInputQuestion {
type: "folder";
/**
* the answer value is a folder path string
*/
value?: string;
/**
* default selected folder path
*/
default?: string | LocalFunc<string | undefined>;
/**
* validation function
*/
validation?: FuncValidation<string>;
}
export interface SingleFileOrInputQuestion extends UserInputQuestion {
type: "singleFileOrText";
/**
* An item shown in the list in VSC that user can click to input text.
*/
inputOptionItem: OptionItem;
/**
* Config for the input box.
*/
inputBoxConfig: InnerTextInputQuestion;
/**
* This will only take effect in VSC.
* A set of file filters that are used by the dialog. Each entry is a human-readable label,
* like "TypeScript", and an array of extensions, e.g.
* ```ts
* {
* 'Images': ['png', 'jpg']
* 'TypeScript': ['ts', 'tsx']
* }
* ```
*/
filters?: {
[name: string]: string[];
};
}
/**
* `Group` is a virtual node in the question tree that wraps a group of questions, which share the same activation condition in this group.
*/
export interface Group {
type: "group";
name?: string;
}
export type Question = SingleSelectQuestion | MultiSelectQuestion | TextInputQuestion | SingleFileQuestion | MultiFileQuestion | FolderQuestion | SingleFileQuestion | SingleFileOrInputQuestion | ConfirmQuestion;
/**
* IQTreeNode is the tree node data structure, which have three main properties:
* - data: data is either a group or question. Questions can be organized into a group, which has the same trigger condition.
* - condition: trigger condition for this node to be activated;
* - children: child questions that will be activated according their trigger condition.
*/
export interface IQTreeNode {
data: Question | Group;
condition?: StringValidation | StringArrayValidation | ConditionFunc;
children?: IQTreeNode[];
/**
* @description the question node will be ignored as CLI option in non-interactive mode
* "self" - only ignore the question itself
* "children" - ignore all nodes in sub-tree
* "all" - ignore self and all nodes in sub-tree
*/
cliOptionDisabled?: "self" | "children" | "all";
/**
* @description the question node will be ignored as an Inputs property
* "self" - only ignore the question itself
* "children" - ignore all nodes in sub-tree
* "all" - ignore self and all nodes in sub-tree
*/
inputsDisabled?: "self" | "children" | "all";
}
//# sourceMappingURL=question.d.ts.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=question.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../src/qm/question.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC"}
+465
View File
@@ -0,0 +1,465 @@
import { Result } from "neverthrow";
import { FxError } from "../error";
import { Inputs, OptionItem } from "../types";
import { Colors } from "./../utils/log";
import { LocalFunc, OnSelectionChangeFunc, StaticOptions } from "./question";
/**
* A base structure of user interaction (UI) configuration
*/
export interface UIConfig<T> {
/**
* name is the identifier of the UI
*/
name: string;
/**
* human readable meaningful display name of the UI
*/
title: string;
/**
* placeholder in the UI
*/
placeholder?: string;
/**
* prompt text providing some ask or explanation to the user
*/
prompt?: string;
/**
* `step` and `totalSteps` are used to describe the progress in question flow
* `step` is the sequence number of current question
*/
step?: number;
/**
* `totalStep` is the number of questions totally
*/
totalSteps?: number;
/**
* default input value
*/
default?: T | (() => Promise<T>) | string;
/**
* A function that will be called to validate input and to give a hint to the user.
*
* @param input The current value of the input to be validated.
* @return A human-readable string which is presented as diagnostic message.
* Return `undefined` when 'value' is valid.
*/
validation?: (input: T) => string | undefined | Promise<string | undefined>;
/**
* Actions that can be made within the question.
* @param An array of actions
* @param `icon` is the icon id of the action item
* @param `tooltip` is the hint of the action item
* @param `command` is the command name that will be executed when current action triggered
*/
buttons?: {
icon: string;
tooltip: string;
command: string;
}[];
/**
* `innerStep` and `innerTotalStep` are used to describe the inner step of a group of questions
* `innerStep` is the sequence number of the current question in the group.
* VSC will display the innerStep and innerTotalStep in the question title.
*/
innerStep?: number;
/**
* `innerTotalStep` is the number of questions in the group in total
*/
innerTotalStep?: number;
}
export interface ConfirmConfig extends UIConfig<boolean> {
/**
* display text for option true or false
*/
transformer?: (value: boolean) => string;
}
/**
* single selection UI config
*/
export interface SingleSelectConfig extends UIConfig<string> {
/**
* option array or a callback function which returns option array
*/
options: StaticOptions | (() => Promise<StaticOptions>);
default?: string | (() => Promise<string>);
/**
* This config only works for option items with `OptionItem[]` type. If `returnObject` is true, the answer value is an `OptionItem` object; otherwise, the answer value is the `id` string of the `OptionItem`.
* In case of option items with `string[]` type, whether `returnObject` is true or false, the returned answer value is always a string.
*/
returnObject?: boolean;
/**
* whether skip selection if there is only one option, default is false
*/
skipSingleOption?: boolean;
}
/**
* multiple selection UI config
*/
export interface MultiSelectConfig extends UIConfig<string[]> {
/**
* option array or a callback function which returns option array
*/
options: StaticOptions | (() => Promise<StaticOptions>);
default?: string[] | (() => Promise<string[]>) | "none" | "all";
/**
* This config only works for option items with `OptionItem[]` type. If `returnObject` is true, the answer value is an array of `OptionItem` objects; otherwise, the answer value is an array of `id` strings.
* In case of option items with `string[]` type, whether `returnObject` is true or false, the returned answer value is always a string array.
*/
returnObject?: boolean;
/**
* a callback function which is triggered when the selected values change, which can change the final selected values.
* @param currentSelectedIds current selected option ids
* @param previousSelectedIds previous selected option ids
* @returns the final selected option ids
*/
onDidChangeSelection?: OnSelectionChangeFunc;
/**
* whether skip selection if there is only one option, default is false
*/
skipSingleOption?: boolean;
}
/**
* text input UI config
*/
export interface InputTextConfig extends UIConfig<string> {
/**
* If the input value should be hidden. Defaults to false.
*/
password?: boolean;
default?: string | (() => Promise<string>);
/**
* A function that will be called to validate the input that user accepted.
*
* @param input The current value of the input to be validated.
* @return A human-readable string which is presented as diagnostic message.
* Return `undefined` when 'value' is valid.
*/
additionalValidationOnAccept?: (input: string) => string | undefined | Promise<string | undefined>;
}
/**
* single file selector config
*/
export type SelectFileConfig = UIConfig<string> & {
/**
* This will only take effect in VSC.
* A set of file filters that are used by the dialog. Each entry is a human-readable label,
* like "TypeScript", and an array of extensions, e.g.
* ```ts
* {
* 'Images': ['png', 'jpg']
* 'TypeScript': ['ts', 'tsx']
* }
* ```
*/
filters?: {
[name: string]: string[];
};
default?: string | (() => Promise<string>);
/**
* Possible files that will be listed for users to select.
* The id cannot be "default" or "browse" as they are reserved for default and browse options.
*/
possibleFiles?: {
id: string;
label: string;
description?: string;
}[];
/**
* Default Uri when open file selector window.
*/
defaultFolder?: string | (() => Promise<string>);
};
/**
* multiple files selector config
*/
export type SelectFilesConfig = UIConfig<string[]> & {
/**
* This will only take effect in VSC.
* A set of file filters that are used by the dialog. Each entry is a human-readable label,
* like "TypeScript", and an array of extensions, e.g.
* ```ts
* {
* 'Images': ['png', 'jpg']
* 'TypeScript': ['ts', 'tsx']
* }
* ```
*/
filters?: {
[name: string]: string[];
};
default?: string[] | (() => Promise<string[]>);
};
/**
* folder selector config
*/
export type SelectFolderConfig = UIConfig<string> & {
default?: string | (() => Promise<string>);
};
/**
* func execution config
*/
export interface ExecuteFuncConfig extends UIConfig<string> {
func: LocalFunc<any>;
inputs: Inputs;
}
export interface SingleFileOrInputConfig extends UIConfig<string> {
/**
* An item shown in the list in VSC that user can click to input text.
*/
inputOptionItem: OptionItem;
/**
* Config for the input box.
*/
inputBoxConfig: UIConfig<string>;
/**
* This will only take effect in VSC.
* A set of file filters that are used by the dialog. Each entry is a human-readable label,
* like "TypeScript", and an array of extensions, e.g.
* ```ts
* {
* 'Images': ['png', 'jpg']
* 'TypeScript': ['ts', 'tsx']
* }
* ```
*/
filters?: {
[name: string]: string[];
};
}
/**
* a wrapper of user input result
*/
export interface InputResult<T> {
/**
* `success`: the returned answer value is successfully collected when user click predefined confirm button/key, user will continue to answer the next question if available
* `skip`: the answer value is automatically selected when `skipSingleOption` is true for single/multiple selection list, user will continue to answer the next question if available
* `back`: the returned answer is undefined because user click the go-back button/key and will go back to re-answer the previous question in the question flow
*/
type: "success" | "skip" | "back";
/**
* answer value
*/
result?: T;
}
export type ConfirmResult = InputResult<boolean>;
export type SingleSelectResult = InputResult<string | OptionItem>;
export type MultiSelectResult = InputResult<StaticOptions>;
export type InputTextResult = InputResult<string>;
export type SelectFileResult = InputResult<string>;
export type SelectFilesResult = InputResult<string[]>;
export type SelectFolderResult = InputResult<string>;
/**
* Definition of user interaction, which is platform independent
*/
export interface UserInteraction {
/**
* Shows confirm dialog
* @param config confirm config
* @returns A promise that resolves to the confirm result wrapper or FxError
* @throws FxError
*/
confirm?: (config: ConfirmConfig) => Promise<Result<ConfirmResult, FxError>>;
/**
* Shows a single selection list
* @param config single selection config
* @returns A promise that resolves to the single select result wrapper or FxError
* @throws FxError
*/
selectOption: (config: SingleSelectConfig) => Promise<Result<SingleSelectResult, FxError>>;
/**
* Shows a multiple selection list
* @param config multiple selection config
* @returns A promise that resolves to the multiple select result wrapper or FxError
* @throws FxError
*/
selectOptions: (config: MultiSelectConfig) => Promise<Result<MultiSelectResult, FxError>>;
/**
* Opens an input box to ask the user for input.
* @param config text input config
* @returns A promise that resolves to the text input result wrapper or FxError
* @throws FxError
*/
inputText: (config: InputTextConfig) => Promise<Result<InputTextResult, FxError>>;
/**
* Shows a file open dialog to the user which allows to select a single file
* @param config file selector config
* @returns A promise that resolves to the file selector result wrapper or FxError
* @throws FxError
*/
selectFile: (config: SelectFileConfig) => Promise<Result<SelectFileResult, FxError>>;
/**
* Shows a file open dialog to the user which allows to select multiple files
* @param config multiple files selector config
* @returns A promise that resolves to the multiple files selector result wrapper or FxError
* @throws FxError
*/
selectFiles: (config: SelectFilesConfig) => Promise<Result<SelectFilesResult, FxError>>;
/**
* Shows a file open dialog to the user which allows to select a folder
* @param config folder selector config
* @returns A promise that resolves to the folder selector result wrapper or FxError
* @throws FxError
*/
selectFolder: (config: SelectFolderConfig) => Promise<Result<SelectFolderResult, FxError>>;
/**
* Opens a link externally in the browser.
* @param link The uri that should be opened.
* @returns A promise indicating if open was successful.
*/
openUrl(link: string): Promise<Result<boolean, FxError>>;
/**
* Show an information/warning/error message to users. Optionally provide an array of items which will be presented as clickable buttons.
* @param level message level
* @param message The message to show.
* @param items A set of items that will be rendered as actions in the message.
* @returns A promise that resolves to the selected item or `undefined` when being dismissed.
*/
showMessage(level: "info" | "warn" | "error", message: string, modal: boolean, ...items: string[]): Promise<Result<string | undefined, FxError>>;
/**
* Show an information/warning/error message with different colors to users, which only works for CLI.
* @param level message level
* @param message The message with color to show. The color only works for CLI.
* @param items A set of items that will be rendered as actions in the message.
* @returns A promise that resolves to the selected item or `undefined` when being dismissed.
*/
showMessage(level: "info" | "warn" | "error", message: Array<{
content: string;
color: Colors;
}>, modal: boolean, ...items: string[]): Promise<Result<string | undefined, FxError>>;
/**
* Create a new progress bar with the specified title and the number of steps. It will
* return a progress handler and you can use this handler to control the detail message
* of it.
* ${currentStep} will increase from 0 to ${totalSteps}.
* @param title the title of this progress bar.
* @param totalSteps the number of steps.
* @returns the handler of a progress bar
*/
createProgressBar: (title: string, totalSteps: number) => IProgressHandler;
/**
* Reload window to update user interface. (Only works for VS Code)
* @returns A promise indicating if reload is successful.
*/
reload?(): Promise<Result<boolean, FxError>>;
/**
* Execute a function. User interface can decide what the UX is.
* @param config execute function configurations
*/
executeFunction?(config: ExecuteFuncConfig): any | Promise<any>;
/**
* Opens a file.
* @param filePath The path of the file that should be opened.
* @returns A promise indicating if open was successful.
*/
openFile?(filePath: string): Promise<Result<boolean, FxError>>;
/**
* run a user defined command in terminals of UI
* @param args
*/
runCommand?(args: {
cmd: string;
workingDirectory?: string;
shell?: string;
timeout?: number;
env?: {
[k: string]: string;
};
shellName?: string;
iconPath?: string;
}): Promise<Result<string, FxError>>;
/**
* In VSC, it shows two options to user, one will open a dialog to the user which allows to select a single file, another one will show an input box asking to enter a value.
* If CLI, it will directly asks user to enter a value.
* @param config config to select local file or enter a value
* @returns A promise that resolves to the local file path or the value entered by user or FxError
* @throws FxError
*/
selectFileOrInput?(config: SingleFileOrInputConfig): Promise<Result<InputResult<string>, FxError>>;
/**
* Supports in VSC only for now. Show diagnostic message in editor.
*/
showDiagnosticInfo?(diagnostics: IDiagnosticInfo[]): void;
}
export interface IProgressHandler {
/**
* Start this progress bar. After calling it, the progress bar will be seen to users with
* ${currentStep} = 0 and ${detail} = detail.
* @param detail the detail message of the next work.
*/
start: (detail?: string) => Promise<void>;
/**
* Update the progress bar's message. After calling it, the progress bar will be seen to
* users with ${currentStep}++ and ${detail} = detail.
* This func must be called after calling start().
* @param detail the detail message of the next work.
*/
next: (detail?: string) => Promise<void>;
/**
* End the progress bar and tell if success. After calling it, the progress bar will disappear. This handler
* can be reused after calling end().
*/
end: (success: boolean, hideAfterFinish?: boolean) => Promise<void>;
}
export declare enum DiagnosticSeverity {
/**
* Something not allowed by the rules of a language or other means.
*/
Error = 0,
/**
* Something suspicious but allowed.
*/
Warning = 1,
/**
* Something to inform about but not a problem.
*/
Information = 2,
/**
* Something to hint to a better way of doing it, like proposing
* a refactoring.
*/
Hint = 3
}
export interface IDiagnosticInfo {
/**
* Path of file where diagnostic shows.
*/
filePath: string;
/**
* Line number where diagnostic info starts.
*/
startLine: number;
/**
* Index of the beginning character where diagnostic info shows
*/
startIndex: number;
/**
* Line number where diagnostic info ends.
*/
endLine: number;
/**
* Index of the end character where diagnostic info ends.
*/
endIndex: number;
/**
* Message.
*/
message: string;
/**
* Severity.
*/
severity: DiagnosticSeverity;
/**
* A code or identifier for this diagnostic.
*/
code?: {
/**
* Value.
*/
value: string;
/**
* Link to open with more information about the diagnostic error.
*/
link: string;
};
}
//# sourceMappingURL=ui.d.ts.map
File diff suppressed because one or more lines are too long
+26
View File
@@ -0,0 +1,26 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiagnosticSeverity = void 0;
var DiagnosticSeverity;
(function (DiagnosticSeverity) {
/**
* Something not allowed by the rules of a language or other means.
*/
DiagnosticSeverity[DiagnosticSeverity["Error"] = 0] = "Error";
/**
* Something suspicious but allowed.
*/
DiagnosticSeverity[DiagnosticSeverity["Warning"] = 1] = "Warning";
/**
* Something to inform about but not a problem.
*/
DiagnosticSeverity[DiagnosticSeverity["Information"] = 2] = "Information";
/**
* Something to hint to a better way of doing it, like proposing
* a refactoring.
*/
DiagnosticSeverity[DiagnosticSeverity["Hint"] = 3] = "Hint";
})(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
//# sourceMappingURL=ui.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../src/qm/ui.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAoclC,IAAY,kBAqBX;AArBD,WAAY,kBAAkB;IAC5B;;OAEG;IACH,6DAAS,CAAA;IAET;;OAEG;IACH,iEAAW,CAAA;IAEX;;OAEG;IACH,yEAAe,CAAA;IAEf;;;OAGG;IACH,2DAAQ,CAAA;AACV,CAAC,EArBW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAqB7B"}
+123
View File
@@ -0,0 +1,123 @@
import { Inputs, OptionItem } from "../types";
export type ValidateFunc<T> = (input: T, inputs?: Inputs) => string | undefined | Promise<string | undefined>;
/**
* Validation for Any Instance Type
* JSON Schema Validation reference: http://json-schema.org/draft/2019-09/json-schema-validation.html
*/
export interface StaticValidation {
/**
* whether the value is required or not, default value is true if it is undefined
*/
required?: boolean;
/**
* An instance validates successfully against this keyword if its value is equal to the value of the keyword.
*/
equals?: unknown;
}
/**
* Validation for Strings
*/
export interface StringValidation extends StaticValidation {
/**
* A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
*/
maxLength?: number;
/**
* A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
*/
minLength?: number;
/**
* A string instance is considered valid if the regular expression matches the instance successfully.
*/
pattern?: string;
/**
* A string instance validates successfully against this keyword if its value is equal to one of the elements in this keyword's array value.
*/
enum?: string[];
/**
* A string instance is valid against this keyword if the string starts with the value of this keyword.
*/
startsWith?: string;
/**
* A string instance is valid against this keyword if the string ends with the value of this keyword.
*/
endsWith?: string;
/**
* A string instance is valid against this keyword if the string contains the value of this keyword.
*/
includes?: string;
/**
* An instance validates successfully against this keyword if its value is equal to the value of the keyword.
*/
equals?: string;
/**
* An instance validates successfully against this keyword if its value is not equal to the value of the keyword.
*/
notEquals?: string;
/**
* A string instance validates successfully against this keyword if its value does not equal to any of the elements in this keyword's array value.
*/
excludesEnum?: string[];
}
/**
* Validation for String Arrays
*/
export interface StringArrayValidation extends StaticValidation {
/**
* The value of this keyword MUST be a non-negative integer.
* An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.
*/
maxItems?: number;
/**
* The value of this keyword MUST be a non-negative integer.
* An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.
*/
minItems?: number;
/**
* If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.
*/
uniqueItems?: boolean;
/**
* An instance validates successfully against this string array if they have the exactly the same elements.
*/
equals?: string[];
/**
* An array instance is valid against "enum" array if all of the elements of the array is contained in the `enum` array.
*/
enum?: string[];
/**
* An array instance is valid against "excludes" if it doesn't contains the value of `excludes`
*/
excludes?: string;
/**
* An array instance is valid against "contains" if it contains the value of `contains`
*/
contains?: string;
/**
* An array instance is valid against "containsAll" array if it contains all of the elements of `containsAll` array.
*/
containsAll?: string[];
/**
* An array instance is valid against "containsAny" array if it contains any one of the elements of `containsAny` array.
*/
containsAny?: string[];
}
/**
* The validation is checked by a validFunc provided by user
*/
export interface FuncValidation<T extends string | string[] | OptionItem | OptionItem[] | undefined> {
/**
* A function that will be called to validate input and to give a hint to the user.
*
* @param input The current value of the input to be validated.
* @return A human-readable string which is presented as diagnostic message.
* Return `undefined` when 'value' is valid.
*/
validFunc: ValidateFunc<T>;
}
export type ConditionFunc = (inputs: Inputs) => boolean | Promise<boolean>;
/**
* Definition of validation schema, which is a union of `StringValidation`, `StringArrayValidation` and `FuncValidation<any>`
*/
export type ValidationSchema = StringValidation | StringArrayValidation | FuncValidation<any>;
//# sourceMappingURL=validation.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/qm/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAC5B,KAAK,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,MAAM,KACZ,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,UAAU,EAAE,GAAG,SAAS;IAEnE;;;;;;OAMG;IACH,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC5B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,qBAAqB,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=validation.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/qm/validation.ts"],"names":[],"mappings":""}